1 // SPDX-License-Identifier: GPL-2.0-only
2
3 #include <linux/ethtool_netlink.h>
4 #include <linux/net_tstamp.h>
5 #include <linux/phy.h>
6 #include <linux/rtnetlink.h>
7 #include <linux/ptp_clock_kernel.h>
8
9 #include "netlink.h"
10 #include "common.h"
11
12 const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
13 [NETIF_F_SG_BIT] = "tx-scatter-gather",
14 [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4",
15 [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
16 [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
17 [NETIF_F_HIGHDMA_BIT] = "highdma",
18 [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
19 [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert",
20
21 [NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse",
22 [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter",
23 [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert",
24 [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse",
25 [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter",
26 [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
27 [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
28 [NETIF_F_GRO_BIT] = "rx-gro",
29 [NETIF_F_GRO_HW_BIT] = "rx-gro-hw",
30 [NETIF_F_LRO_BIT] = "rx-lro",
31
32 [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
33 [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
34 [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
35 [NETIF_F_TSO_MANGLEID_BIT] = "tx-tcp-mangleid-segmentation",
36 [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
37 [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
38 [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation",
39 [NETIF_F_GSO_GRE_CSUM_BIT] = "tx-gre-csum-segmentation",
40 [NETIF_F_GSO_IPXIP4_BIT] = "tx-ipxip4-segmentation",
41 [NETIF_F_GSO_IPXIP6_BIT] = "tx-ipxip6-segmentation",
42 [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation",
43 [NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT] = "tx-udp_tnl-csum-segmentation",
44 [NETIF_F_GSO_PARTIAL_BIT] = "tx-gso-partial",
45 [NETIF_F_GSO_TUNNEL_REMCSUM_BIT] = "tx-tunnel-remcsum-segmentation",
46 [NETIF_F_GSO_SCTP_BIT] = "tx-sctp-segmentation",
47 [NETIF_F_GSO_ESP_BIT] = "tx-esp-segmentation",
48 [NETIF_F_GSO_UDP_L4_BIT] = "tx-udp-segmentation",
49 [NETIF_F_GSO_FRAGLIST_BIT] = "tx-gso-list",
50
51 [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
52 [NETIF_F_SCTP_CRC_BIT] = "tx-checksum-sctp",
53 [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter",
54 [NETIF_F_RXHASH_BIT] = "rx-hashing",
55 [NETIF_F_RXCSUM_BIT] = "rx-checksum",
56 [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy",
57 [NETIF_F_LOOPBACK_BIT] = "loopback",
58 [NETIF_F_RXFCS_BIT] = "rx-fcs",
59 [NETIF_F_RXALL_BIT] = "rx-all",
60 [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload",
61 [NETIF_F_HW_TC_BIT] = "hw-tc-offload",
62 [NETIF_F_HW_ESP_BIT] = "esp-hw-offload",
63 [NETIF_F_HW_ESP_TX_CSUM_BIT] = "esp-tx-csum-hw-offload",
64 [NETIF_F_RX_UDP_TUNNEL_PORT_BIT] = "rx-udp_tunnel-port-offload",
65 [NETIF_F_HW_TLS_RECORD_BIT] = "tls-hw-record",
66 [NETIF_F_HW_TLS_TX_BIT] = "tls-hw-tx-offload",
67 [NETIF_F_HW_TLS_RX_BIT] = "tls-hw-rx-offload",
68 [NETIF_F_GRO_FRAGLIST_BIT] = "rx-gro-list",
69 [NETIF_F_HW_MACSEC_BIT] = "macsec-hw-offload",
70 [NETIF_F_GRO_UDP_FWD_BIT] = "rx-udp-gro-forwarding",
71 [NETIF_F_HW_HSR_TAG_INS_BIT] = "hsr-tag-ins-offload",
72 [NETIF_F_HW_HSR_TAG_RM_BIT] = "hsr-tag-rm-offload",
73 [NETIF_F_HW_HSR_FWD_BIT] = "hsr-fwd-offload",
74 [NETIF_F_HW_HSR_DUP_BIT] = "hsr-dup-offload",
75 };
76
77 const char
78 rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN] = {
79 [ETH_RSS_HASH_TOP_BIT] = "toeplitz",
80 [ETH_RSS_HASH_XOR_BIT] = "xor",
81 [ETH_RSS_HASH_CRC32_BIT] = "crc32",
82 };
83
84 const char
85 tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN] = {
86 [ETHTOOL_ID_UNSPEC] = "Unspec",
87 [ETHTOOL_RX_COPYBREAK] = "rx-copybreak",
88 [ETHTOOL_TX_COPYBREAK] = "tx-copybreak",
89 [ETHTOOL_PFC_PREVENTION_TOUT] = "pfc-prevention-tout",
90 [ETHTOOL_TX_COPYBREAK_BUF_SIZE] = "tx-copybreak-buf-size",
91 };
92
93 const char
94 phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN] = {
95 [ETHTOOL_ID_UNSPEC] = "Unspec",
96 [ETHTOOL_PHY_DOWNSHIFT] = "phy-downshift",
97 [ETHTOOL_PHY_FAST_LINK_DOWN] = "phy-fast-link-down",
98 [ETHTOOL_PHY_EDPD] = "phy-energy-detect-power-down",
99 };
100
101 #define __LINK_MODE_NAME(speed, type, duplex) \
102 #speed "base" #type "/" #duplex
103 #define __DEFINE_LINK_MODE_NAME(speed, type, duplex) \
104 [ETHTOOL_LINK_MODE(speed, type, duplex)] = \
105 __LINK_MODE_NAME(speed, type, duplex)
106 #define __DEFINE_SPECIAL_MODE_NAME(_mode, _name) \
107 [ETHTOOL_LINK_MODE_ ## _mode ## _BIT] = _name
108
109 const char link_mode_names[][ETH_GSTRING_LEN] = {
110 __DEFINE_LINK_MODE_NAME(10, T, Half),
111 __DEFINE_LINK_MODE_NAME(10, T, Full),
112 __DEFINE_LINK_MODE_NAME(100, T, Half),
113 __DEFINE_LINK_MODE_NAME(100, T, Full),
114 __DEFINE_LINK_MODE_NAME(1000, T, Half),
115 __DEFINE_LINK_MODE_NAME(1000, T, Full),
116 __DEFINE_SPECIAL_MODE_NAME(Autoneg, "Autoneg"),
117 __DEFINE_SPECIAL_MODE_NAME(TP, "TP"),
118 __DEFINE_SPECIAL_MODE_NAME(AUI, "AUI"),
119 __DEFINE_SPECIAL_MODE_NAME(MII, "MII"),
120 __DEFINE_SPECIAL_MODE_NAME(FIBRE, "FIBRE"),
121 __DEFINE_SPECIAL_MODE_NAME(BNC, "BNC"),
122 __DEFINE_LINK_MODE_NAME(10000, T, Full),
123 __DEFINE_SPECIAL_MODE_NAME(Pause, "Pause"),
124 __DEFINE_SPECIAL_MODE_NAME(Asym_Pause, "Asym_Pause"),
125 __DEFINE_LINK_MODE_NAME(2500, X, Full),
126 __DEFINE_SPECIAL_MODE_NAME(Backplane, "Backplane"),
127 __DEFINE_LINK_MODE_NAME(1000, KX, Full),
128 __DEFINE_LINK_MODE_NAME(10000, KX4, Full),
129 __DEFINE_LINK_MODE_NAME(10000, KR, Full),
130 __DEFINE_SPECIAL_MODE_NAME(10000baseR_FEC, "10000baseR_FEC"),
131 __DEFINE_LINK_MODE_NAME(20000, MLD2, Full),
132 __DEFINE_LINK_MODE_NAME(20000, KR2, Full),
133 __DEFINE_LINK_MODE_NAME(40000, KR4, Full),
134 __DEFINE_LINK_MODE_NAME(40000, CR4, Full),
135 __DEFINE_LINK_MODE_NAME(40000, SR4, Full),
136 __DEFINE_LINK_MODE_NAME(40000, LR4, Full),
137 __DEFINE_LINK_MODE_NAME(56000, KR4, Full),
138 __DEFINE_LINK_MODE_NAME(56000, CR4, Full),
139 __DEFINE_LINK_MODE_NAME(56000, SR4, Full),
140 __DEFINE_LINK_MODE_NAME(56000, LR4, Full),
141 __DEFINE_LINK_MODE_NAME(25000, CR, Full),
142 __DEFINE_LINK_MODE_NAME(25000, KR, Full),
143 __DEFINE_LINK_MODE_NAME(25000, SR, Full),
144 __DEFINE_LINK_MODE_NAME(50000, CR2, Full),
145 __DEFINE_LINK_MODE_NAME(50000, KR2, Full),
146 __DEFINE_LINK_MODE_NAME(100000, KR4, Full),
147 __DEFINE_LINK_MODE_NAME(100000, SR4, Full),
148 __DEFINE_LINK_MODE_NAME(100000, CR4, Full),
149 __DEFINE_LINK_MODE_NAME(100000, LR4_ER4, Full),
150 __DEFINE_LINK_MODE_NAME(50000, SR2, Full),
151 __DEFINE_LINK_MODE_NAME(1000, X, Full),
152 __DEFINE_LINK_MODE_NAME(10000, CR, Full),
153 __DEFINE_LINK_MODE_NAME(10000, SR, Full),
154 __DEFINE_LINK_MODE_NAME(10000, LR, Full),
155 __DEFINE_LINK_MODE_NAME(10000, LRM, Full),
156 __DEFINE_LINK_MODE_NAME(10000, ER, Full),
157 __DEFINE_LINK_MODE_NAME(2500, T, Full),
158 __DEFINE_LINK_MODE_NAME(5000, T, Full),
159 __DEFINE_SPECIAL_MODE_NAME(FEC_NONE, "None"),
160 __DEFINE_SPECIAL_MODE_NAME(FEC_RS, "RS"),
161 __DEFINE_SPECIAL_MODE_NAME(FEC_BASER, "BASER"),
162 __DEFINE_LINK_MODE_NAME(50000, KR, Full),
163 __DEFINE_LINK_MODE_NAME(50000, SR, Full),
164 __DEFINE_LINK_MODE_NAME(50000, CR, Full),
165 __DEFINE_LINK_MODE_NAME(50000, LR_ER_FR, Full),
166 __DEFINE_LINK_MODE_NAME(50000, DR, Full),
167 __DEFINE_LINK_MODE_NAME(100000, KR2, Full),
168 __DEFINE_LINK_MODE_NAME(100000, SR2, Full),
169 __DEFINE_LINK_MODE_NAME(100000, CR2, Full),
170 __DEFINE_LINK_MODE_NAME(100000, LR2_ER2_FR2, Full),
171 __DEFINE_LINK_MODE_NAME(100000, DR2, Full),
172 __DEFINE_LINK_MODE_NAME(200000, KR4, Full),
173 __DEFINE_LINK_MODE_NAME(200000, SR4, Full),
174 __DEFINE_LINK_MODE_NAME(200000, LR4_ER4_FR4, Full),
175 __DEFINE_LINK_MODE_NAME(200000, DR4, Full),
176 __DEFINE_LINK_MODE_NAME(200000, CR4, Full),
177 __DEFINE_LINK_MODE_NAME(100, T1, Full),
178 __DEFINE_LINK_MODE_NAME(1000, T1, Full),
179 __DEFINE_LINK_MODE_NAME(400000, KR8, Full),
180 __DEFINE_LINK_MODE_NAME(400000, SR8, Full),
181 __DEFINE_LINK_MODE_NAME(400000, LR8_ER8_FR8, Full),
182 __DEFINE_LINK_MODE_NAME(400000, DR8, Full),
183 __DEFINE_LINK_MODE_NAME(400000, CR8, Full),
184 __DEFINE_SPECIAL_MODE_NAME(FEC_LLRS, "LLRS"),
185 __DEFINE_LINK_MODE_NAME(100000, KR, Full),
186 __DEFINE_LINK_MODE_NAME(100000, SR, Full),
187 __DEFINE_LINK_MODE_NAME(100000, LR_ER_FR, Full),
188 __DEFINE_LINK_MODE_NAME(100000, DR, Full),
189 __DEFINE_LINK_MODE_NAME(100000, CR, Full),
190 __DEFINE_LINK_MODE_NAME(200000, KR2, Full),
191 __DEFINE_LINK_MODE_NAME(200000, SR2, Full),
192 __DEFINE_LINK_MODE_NAME(200000, LR2_ER2_FR2, Full),
193 __DEFINE_LINK_MODE_NAME(200000, DR2, Full),
194 __DEFINE_LINK_MODE_NAME(200000, CR2, Full),
195 __DEFINE_LINK_MODE_NAME(400000, KR4, Full),
196 __DEFINE_LINK_MODE_NAME(400000, SR4, Full),
197 __DEFINE_LINK_MODE_NAME(400000, LR4_ER4_FR4, Full),
198 __DEFINE_LINK_MODE_NAME(400000, DR4, Full),
199 __DEFINE_LINK_MODE_NAME(400000, CR4, Full),
200 __DEFINE_LINK_MODE_NAME(100, FX, Half),
201 __DEFINE_LINK_MODE_NAME(100, FX, Full),
202 __DEFINE_LINK_MODE_NAME(10, T1L, Full),
203 __DEFINE_LINK_MODE_NAME(800000, CR8, Full),
204 __DEFINE_LINK_MODE_NAME(800000, KR8, Full),
205 __DEFINE_LINK_MODE_NAME(800000, DR8, Full),
206 __DEFINE_LINK_MODE_NAME(800000, DR8_2, Full),
207 __DEFINE_LINK_MODE_NAME(800000, SR8, Full),
208 __DEFINE_LINK_MODE_NAME(800000, VR8, Full),
209 __DEFINE_LINK_MODE_NAME(10, T1S, Full),
210 __DEFINE_LINK_MODE_NAME(10, T1S, Half),
211 __DEFINE_LINK_MODE_NAME(10, T1S_P2MP, Half),
212 __DEFINE_LINK_MODE_NAME(10, T1BRR, Full),
213 };
214 static_assert(ARRAY_SIZE(link_mode_names) == __ETHTOOL_LINK_MODE_MASK_NBITS);
215
216 #define __LINK_MODE_LANES_CR 1
217 #define __LINK_MODE_LANES_CR2 2
218 #define __LINK_MODE_LANES_CR4 4
219 #define __LINK_MODE_LANES_CR8 8
220 #define __LINK_MODE_LANES_DR 1
221 #define __LINK_MODE_LANES_DR2 2
222 #define __LINK_MODE_LANES_DR4 4
223 #define __LINK_MODE_LANES_DR8 8
224 #define __LINK_MODE_LANES_KR 1
225 #define __LINK_MODE_LANES_KR2 2
226 #define __LINK_MODE_LANES_KR4 4
227 #define __LINK_MODE_LANES_KR8 8
228 #define __LINK_MODE_LANES_SR 1
229 #define __LINK_MODE_LANES_SR2 2
230 #define __LINK_MODE_LANES_SR4 4
231 #define __LINK_MODE_LANES_SR8 8
232 #define __LINK_MODE_LANES_ER 1
233 #define __LINK_MODE_LANES_KX 1
234 #define __LINK_MODE_LANES_KX4 4
235 #define __LINK_MODE_LANES_LR 1
236 #define __LINK_MODE_LANES_LR4 4
237 #define __LINK_MODE_LANES_LR4_ER4 4
238 #define __LINK_MODE_LANES_LR_ER_FR 1
239 #define __LINK_MODE_LANES_LR2_ER2_FR2 2
240 #define __LINK_MODE_LANES_LR4_ER4_FR4 4
241 #define __LINK_MODE_LANES_LR8_ER8_FR8 8
242 #define __LINK_MODE_LANES_LRM 1
243 #define __LINK_MODE_LANES_MLD2 2
244 #define __LINK_MODE_LANES_T 1
245 #define __LINK_MODE_LANES_T1 1
246 #define __LINK_MODE_LANES_X 1
247 #define __LINK_MODE_LANES_FX 1
248 #define __LINK_MODE_LANES_T1L 1
249 #define __LINK_MODE_LANES_T1S 1
250 #define __LINK_MODE_LANES_T1S_P2MP 1
251 #define __LINK_MODE_LANES_VR8 8
252 #define __LINK_MODE_LANES_DR8_2 8
253 #define __LINK_MODE_LANES_T1BRR 1
254
255 #define __DEFINE_LINK_MODE_PARAMS(_speed, _type, _duplex) \
256 [ETHTOOL_LINK_MODE(_speed, _type, _duplex)] = { \
257 .speed = SPEED_ ## _speed, \
258 .lanes = __LINK_MODE_LANES_ ## _type, \
259 .duplex = __DUPLEX_ ## _duplex \
260 }
261 #define __DUPLEX_Half DUPLEX_HALF
262 #define __DUPLEX_Full DUPLEX_FULL
263 #define __DEFINE_SPECIAL_MODE_PARAMS(_mode) \
264 [ETHTOOL_LINK_MODE_ ## _mode ## _BIT] = { \
265 .speed = SPEED_UNKNOWN, \
266 .lanes = 0, \
267 .duplex = DUPLEX_UNKNOWN, \
268 }
269
270 const struct link_mode_info link_mode_params[] = {
271 __DEFINE_LINK_MODE_PARAMS(10, T, Half),
272 __DEFINE_LINK_MODE_PARAMS(10, T, Full),
273 __DEFINE_LINK_MODE_PARAMS(100, T, Half),
274 __DEFINE_LINK_MODE_PARAMS(100, T, Full),
275 __DEFINE_LINK_MODE_PARAMS(1000, T, Half),
276 __DEFINE_LINK_MODE_PARAMS(1000, T, Full),
277 __DEFINE_SPECIAL_MODE_PARAMS(Autoneg),
278 __DEFINE_SPECIAL_MODE_PARAMS(TP),
279 __DEFINE_SPECIAL_MODE_PARAMS(AUI),
280 __DEFINE_SPECIAL_MODE_PARAMS(MII),
281 __DEFINE_SPECIAL_MODE_PARAMS(FIBRE),
282 __DEFINE_SPECIAL_MODE_PARAMS(BNC),
283 __DEFINE_LINK_MODE_PARAMS(10000, T, Full),
284 __DEFINE_SPECIAL_MODE_PARAMS(Pause),
285 __DEFINE_SPECIAL_MODE_PARAMS(Asym_Pause),
286 __DEFINE_LINK_MODE_PARAMS(2500, X, Full),
287 __DEFINE_SPECIAL_MODE_PARAMS(Backplane),
288 __DEFINE_LINK_MODE_PARAMS(1000, KX, Full),
289 __DEFINE_LINK_MODE_PARAMS(10000, KX4, Full),
290 __DEFINE_LINK_MODE_PARAMS(10000, KR, Full),
291 [ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] = {
292 .speed = SPEED_10000,
293 .lanes = 1,
294 .duplex = DUPLEX_FULL,
295 },
296 __DEFINE_LINK_MODE_PARAMS(20000, MLD2, Full),
297 __DEFINE_LINK_MODE_PARAMS(20000, KR2, Full),
298 __DEFINE_LINK_MODE_PARAMS(40000, KR4, Full),
299 __DEFINE_LINK_MODE_PARAMS(40000, CR4, Full),
300 __DEFINE_LINK_MODE_PARAMS(40000, SR4, Full),
301 __DEFINE_LINK_MODE_PARAMS(40000, LR4, Full),
302 __DEFINE_LINK_MODE_PARAMS(56000, KR4, Full),
303 __DEFINE_LINK_MODE_PARAMS(56000, CR4, Full),
304 __DEFINE_LINK_MODE_PARAMS(56000, SR4, Full),
305 __DEFINE_LINK_MODE_PARAMS(56000, LR4, Full),
306 __DEFINE_LINK_MODE_PARAMS(25000, CR, Full),
307 __DEFINE_LINK_MODE_PARAMS(25000, KR, Full),
308 __DEFINE_LINK_MODE_PARAMS(25000, SR, Full),
309 __DEFINE_LINK_MODE_PARAMS(50000, CR2, Full),
310 __DEFINE_LINK_MODE_PARAMS(50000, KR2, Full),
311 __DEFINE_LINK_MODE_PARAMS(100000, KR4, Full),
312 __DEFINE_LINK_MODE_PARAMS(100000, SR4, Full),
313 __DEFINE_LINK_MODE_PARAMS(100000, CR4, Full),
314 __DEFINE_LINK_MODE_PARAMS(100000, LR4_ER4, Full),
315 __DEFINE_LINK_MODE_PARAMS(50000, SR2, Full),
316 __DEFINE_LINK_MODE_PARAMS(1000, X, Full),
317 __DEFINE_LINK_MODE_PARAMS(10000, CR, Full),
318 __DEFINE_LINK_MODE_PARAMS(10000, SR, Full),
319 __DEFINE_LINK_MODE_PARAMS(10000, LR, Full),
320 __DEFINE_LINK_MODE_PARAMS(10000, LRM, Full),
321 __DEFINE_LINK_MODE_PARAMS(10000, ER, Full),
322 __DEFINE_LINK_MODE_PARAMS(2500, T, Full),
323 __DEFINE_LINK_MODE_PARAMS(5000, T, Full),
324 __DEFINE_SPECIAL_MODE_PARAMS(FEC_NONE),
325 __DEFINE_SPECIAL_MODE_PARAMS(FEC_RS),
326 __DEFINE_SPECIAL_MODE_PARAMS(FEC_BASER),
327 __DEFINE_LINK_MODE_PARAMS(50000, KR, Full),
328 __DEFINE_LINK_MODE_PARAMS(50000, SR, Full),
329 __DEFINE_LINK_MODE_PARAMS(50000, CR, Full),
330 __DEFINE_LINK_MODE_PARAMS(50000, LR_ER_FR, Full),
331 __DEFINE_LINK_MODE_PARAMS(50000, DR, Full),
332 __DEFINE_LINK_MODE_PARAMS(100000, KR2, Full),
333 __DEFINE_LINK_MODE_PARAMS(100000, SR2, Full),
334 __DEFINE_LINK_MODE_PARAMS(100000, CR2, Full),
335 __DEFINE_LINK_MODE_PARAMS(100000, LR2_ER2_FR2, Full),
336 __DEFINE_LINK_MODE_PARAMS(100000, DR2, Full),
337 __DEFINE_LINK_MODE_PARAMS(200000, KR4, Full),
338 __DEFINE_LINK_MODE_PARAMS(200000, SR4, Full),
339 __DEFINE_LINK_MODE_PARAMS(200000, LR4_ER4_FR4, Full),
340 __DEFINE_LINK_MODE_PARAMS(200000, DR4, Full),
341 __DEFINE_LINK_MODE_PARAMS(200000, CR4, Full),
342 __DEFINE_LINK_MODE_PARAMS(100, T1, Full),
343 __DEFINE_LINK_MODE_PARAMS(1000, T1, Full),
344 __DEFINE_LINK_MODE_PARAMS(400000, KR8, Full),
345 __DEFINE_LINK_MODE_PARAMS(400000, SR8, Full),
346 __DEFINE_LINK_MODE_PARAMS(400000, LR8_ER8_FR8, Full),
347 __DEFINE_LINK_MODE_PARAMS(400000, DR8, Full),
348 __DEFINE_LINK_MODE_PARAMS(400000, CR8, Full),
349 __DEFINE_SPECIAL_MODE_PARAMS(FEC_LLRS),
350 __DEFINE_LINK_MODE_PARAMS(100000, KR, Full),
351 __DEFINE_LINK_MODE_PARAMS(100000, SR, Full),
352 __DEFINE_LINK_MODE_PARAMS(100000, LR_ER_FR, Full),
353 __DEFINE_LINK_MODE_PARAMS(100000, DR, Full),
354 __DEFINE_LINK_MODE_PARAMS(100000, CR, Full),
355 __DEFINE_LINK_MODE_PARAMS(200000, KR2, Full),
356 __DEFINE_LINK_MODE_PARAMS(200000, SR2, Full),
357 __DEFINE_LINK_MODE_PARAMS(200000, LR2_ER2_FR2, Full),
358 __DEFINE_LINK_MODE_PARAMS(200000, DR2, Full),
359 __DEFINE_LINK_MODE_PARAMS(200000, CR2, Full),
360 __DEFINE_LINK_MODE_PARAMS(400000, KR4, Full),
361 __DEFINE_LINK_MODE_PARAMS(400000, SR4, Full),
362 __DEFINE_LINK_MODE_PARAMS(400000, LR4_ER4_FR4, Full),
363 __DEFINE_LINK_MODE_PARAMS(400000, DR4, Full),
364 __DEFINE_LINK_MODE_PARAMS(400000, CR4, Full),
365 __DEFINE_LINK_MODE_PARAMS(100, FX, Half),
366 __DEFINE_LINK_MODE_PARAMS(100, FX, Full),
367 __DEFINE_LINK_MODE_PARAMS(10, T1L, Full),
368 __DEFINE_LINK_MODE_PARAMS(800000, CR8, Full),
369 __DEFINE_LINK_MODE_PARAMS(800000, KR8, Full),
370 __DEFINE_LINK_MODE_PARAMS(800000, DR8, Full),
371 __DEFINE_LINK_MODE_PARAMS(800000, DR8_2, Full),
372 __DEFINE_LINK_MODE_PARAMS(800000, SR8, Full),
373 __DEFINE_LINK_MODE_PARAMS(800000, VR8, Full),
374 __DEFINE_LINK_MODE_PARAMS(10, T1S, Full),
375 __DEFINE_LINK_MODE_PARAMS(10, T1S, Half),
376 __DEFINE_LINK_MODE_PARAMS(10, T1S_P2MP, Half),
377 __DEFINE_LINK_MODE_PARAMS(10, T1BRR, Full),
378 };
379 static_assert(ARRAY_SIZE(link_mode_params) == __ETHTOOL_LINK_MODE_MASK_NBITS);
380
381 const char netif_msg_class_names[][ETH_GSTRING_LEN] = {
382 [NETIF_MSG_DRV_BIT] = "drv",
383 [NETIF_MSG_PROBE_BIT] = "probe",
384 [NETIF_MSG_LINK_BIT] = "link",
385 [NETIF_MSG_TIMER_BIT] = "timer",
386 [NETIF_MSG_IFDOWN_BIT] = "ifdown",
387 [NETIF_MSG_IFUP_BIT] = "ifup",
388 [NETIF_MSG_RX_ERR_BIT] = "rx_err",
389 [NETIF_MSG_TX_ERR_BIT] = "tx_err",
390 [NETIF_MSG_TX_QUEUED_BIT] = "tx_queued",
391 [NETIF_MSG_INTR_BIT] = "intr",
392 [NETIF_MSG_TX_DONE_BIT] = "tx_done",
393 [NETIF_MSG_RX_STATUS_BIT] = "rx_status",
394 [NETIF_MSG_PKTDATA_BIT] = "pktdata",
395 [NETIF_MSG_HW_BIT] = "hw",
396 [NETIF_MSG_WOL_BIT] = "wol",
397 };
398 static_assert(ARRAY_SIZE(netif_msg_class_names) == NETIF_MSG_CLASS_COUNT);
399
400 const char wol_mode_names[][ETH_GSTRING_LEN] = {
401 [const_ilog2(WAKE_PHY)] = "phy",
402 [const_ilog2(WAKE_UCAST)] = "ucast",
403 [const_ilog2(WAKE_MCAST)] = "mcast",
404 [const_ilog2(WAKE_BCAST)] = "bcast",
405 [const_ilog2(WAKE_ARP)] = "arp",
406 [const_ilog2(WAKE_MAGIC)] = "magic",
407 [const_ilog2(WAKE_MAGICSECURE)] = "magicsecure",
408 [const_ilog2(WAKE_FILTER)] = "filter",
409 };
410 static_assert(ARRAY_SIZE(wol_mode_names) == WOL_MODE_COUNT);
411
412 const char sof_timestamping_names[][ETH_GSTRING_LEN] = {
413 [const_ilog2(SOF_TIMESTAMPING_TX_HARDWARE)] = "hardware-transmit",
414 [const_ilog2(SOF_TIMESTAMPING_TX_SOFTWARE)] = "software-transmit",
415 [const_ilog2(SOF_TIMESTAMPING_RX_HARDWARE)] = "hardware-receive",
416 [const_ilog2(SOF_TIMESTAMPING_RX_SOFTWARE)] = "software-receive",
417 [const_ilog2(SOF_TIMESTAMPING_SOFTWARE)] = "software-system-clock",
418 [const_ilog2(SOF_TIMESTAMPING_SYS_HARDWARE)] = "hardware-legacy-clock",
419 [const_ilog2(SOF_TIMESTAMPING_RAW_HARDWARE)] = "hardware-raw-clock",
420 [const_ilog2(SOF_TIMESTAMPING_OPT_ID)] = "option-id",
421 [const_ilog2(SOF_TIMESTAMPING_TX_SCHED)] = "sched-transmit",
422 [const_ilog2(SOF_TIMESTAMPING_TX_ACK)] = "ack-transmit",
423 [const_ilog2(SOF_TIMESTAMPING_OPT_CMSG)] = "option-cmsg",
424 [const_ilog2(SOF_TIMESTAMPING_OPT_TSONLY)] = "option-tsonly",
425 [const_ilog2(SOF_TIMESTAMPING_OPT_STATS)] = "option-stats",
426 [const_ilog2(SOF_TIMESTAMPING_OPT_PKTINFO)] = "option-pktinfo",
427 [const_ilog2(SOF_TIMESTAMPING_OPT_TX_SWHW)] = "option-tx-swhw",
428 [const_ilog2(SOF_TIMESTAMPING_BIND_PHC)] = "bind-phc",
429 [const_ilog2(SOF_TIMESTAMPING_OPT_ID_TCP)] = "option-id-tcp",
430 [const_ilog2(SOF_TIMESTAMPING_OPT_RX_FILTER)] = "option-rx-filter",
431 };
432 static_assert(ARRAY_SIZE(sof_timestamping_names) == __SOF_TIMESTAMPING_CNT);
433
434 const char ts_tx_type_names[][ETH_GSTRING_LEN] = {
435 [HWTSTAMP_TX_OFF] = "off",
436 [HWTSTAMP_TX_ON] = "on",
437 [HWTSTAMP_TX_ONESTEP_SYNC] = "onestep-sync",
438 [HWTSTAMP_TX_ONESTEP_P2P] = "onestep-p2p",
439 };
440 static_assert(ARRAY_SIZE(ts_tx_type_names) == __HWTSTAMP_TX_CNT);
441
442 const char ts_rx_filter_names[][ETH_GSTRING_LEN] = {
443 [HWTSTAMP_FILTER_NONE] = "none",
444 [HWTSTAMP_FILTER_ALL] = "all",
445 [HWTSTAMP_FILTER_SOME] = "some",
446 [HWTSTAMP_FILTER_PTP_V1_L4_EVENT] = "ptpv1-l4-event",
447 [HWTSTAMP_FILTER_PTP_V1_L4_SYNC] = "ptpv1-l4-sync",
448 [HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ] = "ptpv1-l4-delay-req",
449 [HWTSTAMP_FILTER_PTP_V2_L4_EVENT] = "ptpv2-l4-event",
450 [HWTSTAMP_FILTER_PTP_V2_L4_SYNC] = "ptpv2-l4-sync",
451 [HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ] = "ptpv2-l4-delay-req",
452 [HWTSTAMP_FILTER_PTP_V2_L2_EVENT] = "ptpv2-l2-event",
453 [HWTSTAMP_FILTER_PTP_V2_L2_SYNC] = "ptpv2-l2-sync",
454 [HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ] = "ptpv2-l2-delay-req",
455 [HWTSTAMP_FILTER_PTP_V2_EVENT] = "ptpv2-event",
456 [HWTSTAMP_FILTER_PTP_V2_SYNC] = "ptpv2-sync",
457 [HWTSTAMP_FILTER_PTP_V2_DELAY_REQ] = "ptpv2-delay-req",
458 [HWTSTAMP_FILTER_NTP_ALL] = "ntp-all",
459 };
460 static_assert(ARRAY_SIZE(ts_rx_filter_names) == __HWTSTAMP_FILTER_CNT);
461
462 const char udp_tunnel_type_names[][ETH_GSTRING_LEN] = {
463 [ETHTOOL_UDP_TUNNEL_TYPE_VXLAN] = "vxlan",
464 [ETHTOOL_UDP_TUNNEL_TYPE_GENEVE] = "geneve",
465 [ETHTOOL_UDP_TUNNEL_TYPE_VXLAN_GPE] = "vxlan-gpe",
466 };
467 static_assert(ARRAY_SIZE(udp_tunnel_type_names) ==
468 __ETHTOOL_UDP_TUNNEL_TYPE_CNT);
469
470 /* return false if legacy contained non-0 deprecated fields
471 * maxtxpkt/maxrxpkt. rest of ksettings always updated
472 */
473 bool
convert_legacy_settings_to_link_ksettings(struct ethtool_link_ksettings * link_ksettings,const struct ethtool_cmd * legacy_settings)474 convert_legacy_settings_to_link_ksettings(
475 struct ethtool_link_ksettings *link_ksettings,
476 const struct ethtool_cmd *legacy_settings)
477 {
478 bool retval = true;
479
480 memset(link_ksettings, 0, sizeof(*link_ksettings));
481
482 /* This is used to tell users that driver is still using these
483 * deprecated legacy fields, and they should not use
484 * %ETHTOOL_GLINKSETTINGS/%ETHTOOL_SLINKSETTINGS
485 */
486 if (legacy_settings->maxtxpkt ||
487 legacy_settings->maxrxpkt)
488 retval = false;
489
490 ethtool_convert_legacy_u32_to_link_mode(
491 link_ksettings->link_modes.supported,
492 legacy_settings->supported);
493 ethtool_convert_legacy_u32_to_link_mode(
494 link_ksettings->link_modes.advertising,
495 legacy_settings->advertising);
496 ethtool_convert_legacy_u32_to_link_mode(
497 link_ksettings->link_modes.lp_advertising,
498 legacy_settings->lp_advertising);
499 link_ksettings->base.speed
500 = ethtool_cmd_speed(legacy_settings);
501 link_ksettings->base.duplex
502 = legacy_settings->duplex;
503 link_ksettings->base.port
504 = legacy_settings->port;
505 link_ksettings->base.phy_address
506 = legacy_settings->phy_address;
507 link_ksettings->base.autoneg
508 = legacy_settings->autoneg;
509 link_ksettings->base.mdio_support
510 = legacy_settings->mdio_support;
511 link_ksettings->base.eth_tp_mdix
512 = legacy_settings->eth_tp_mdix;
513 link_ksettings->base.eth_tp_mdix_ctrl
514 = legacy_settings->eth_tp_mdix_ctrl;
515 return retval;
516 }
517
__ethtool_get_link(struct net_device * dev)518 int __ethtool_get_link(struct net_device *dev)
519 {
520 if (!dev->ethtool_ops->get_link)
521 return -EOPNOTSUPP;
522
523 return netif_running(dev) && dev->ethtool_ops->get_link(dev);
524 }
525
ethtool_get_rxnfc_rule_count(struct net_device * dev)526 static int ethtool_get_rxnfc_rule_count(struct net_device *dev)
527 {
528 const struct ethtool_ops *ops = dev->ethtool_ops;
529 struct ethtool_rxnfc info = {
530 .cmd = ETHTOOL_GRXCLSRLCNT,
531 };
532 int err;
533
534 err = ops->get_rxnfc(dev, &info, NULL);
535 if (err)
536 return err;
537
538 return info.rule_cnt;
539 }
540
541 /* Max offset for one RSS context */
ethtool_get_rss_ctx_max_channel(struct ethtool_rxfh_context * ctx)542 static u32 ethtool_get_rss_ctx_max_channel(struct ethtool_rxfh_context *ctx)
543 {
544 u32 max_ring = 0;
545 u32 i, *tbl;
546
547 if (WARN_ON_ONCE(!ctx))
548 return 0;
549 tbl = ethtool_rxfh_context_indir(ctx);
550 for (i = 0; i < ctx->indir_size; i++)
551 max_ring = max(max_ring, tbl[i]);
552 return max_ring;
553 }
554
ethtool_get_max_rxnfc_channel(struct net_device * dev,u64 * max)555 static int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max)
556 {
557 const struct ethtool_ops *ops = dev->ethtool_ops;
558 struct ethtool_rxnfc *info;
559 int err, i, rule_cnt;
560 u64 max_ring = 0;
561
562 if (!ops->get_rxnfc)
563 return -EOPNOTSUPP;
564
565 rule_cnt = ethtool_get_rxnfc_rule_count(dev);
566 if (rule_cnt <= 0)
567 return -EINVAL;
568
569 info = kvzalloc(struct_size(info, rule_locs, rule_cnt), GFP_KERNEL);
570 if (!info)
571 return -ENOMEM;
572
573 info->cmd = ETHTOOL_GRXCLSRLALL;
574 info->rule_cnt = rule_cnt;
575 err = ops->get_rxnfc(dev, info, info->rule_locs);
576 if (err)
577 goto err_free_info;
578
579 for (i = 0; i < rule_cnt; i++) {
580 struct ethtool_rxnfc rule_info = {
581 .cmd = ETHTOOL_GRXCLSRULE,
582 .fs.location = info->rule_locs[i],
583 };
584
585 err = ops->get_rxnfc(dev, &rule_info, NULL);
586 if (err)
587 goto err_free_info;
588
589 if (rule_info.fs.ring_cookie != RX_CLS_FLOW_DISC &&
590 rule_info.fs.ring_cookie != RX_CLS_FLOW_WAKE &&
591 !ethtool_get_flow_spec_ring_vf(rule_info.fs.ring_cookie)) {
592 u64 ring = rule_info.fs.ring_cookie;
593
594 if (rule_info.flow_type & FLOW_RSS) {
595 struct ethtool_rxfh_context *ctx;
596
597 ctx = xa_load(&dev->ethtool->rss_ctx,
598 rule_info.rss_context);
599 ring += ethtool_get_rss_ctx_max_channel(ctx);
600 }
601 max_ring = max_t(u64, max_ring, ring);
602 }
603 }
604
605 kvfree(info);
606 *max = max_ring;
607 return 0;
608
609 err_free_info:
610 kvfree(info);
611 return err;
612 }
613
614 /* Max offset across all of a device's RSS contexts */
ethtool_get_max_rss_ctx_channel(struct net_device * dev)615 static u32 ethtool_get_max_rss_ctx_channel(struct net_device *dev)
616 {
617 struct ethtool_rxfh_context *ctx;
618 unsigned long context;
619 u32 max_ring = 0;
620
621 mutex_lock(&dev->ethtool->rss_lock);
622 xa_for_each(&dev->ethtool->rss_ctx, context, ctx)
623 max_ring = max(max_ring, ethtool_get_rss_ctx_max_channel(ctx));
624 mutex_unlock(&dev->ethtool->rss_lock);
625
626 return max_ring;
627 }
628
ethtool_get_max_rxfh_channel(struct net_device * dev)629 static u32 ethtool_get_max_rxfh_channel(struct net_device *dev)
630 {
631 struct ethtool_rxfh_param rxfh = {};
632 u32 dev_size, current_max = 0;
633 int ret;
634
635 /* While we do track whether RSS context has an indirection
636 * table explicitly set by the user, no driver looks at that bit.
637 * Assume drivers won't auto-regenerate the additional tables,
638 * to be safe.
639 */
640 current_max = ethtool_get_max_rss_ctx_channel(dev);
641
642 if (!netif_is_rxfh_configured(dev))
643 return current_max;
644
645 if (!dev->ethtool_ops->get_rxfh_indir_size ||
646 !dev->ethtool_ops->get_rxfh)
647 return current_max;
648 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
649 if (dev_size == 0)
650 return current_max;
651
652 rxfh.indir = kcalloc(dev_size, sizeof(rxfh.indir[0]), GFP_USER);
653 if (!rxfh.indir)
654 return U32_MAX;
655
656 ret = dev->ethtool_ops->get_rxfh(dev, &rxfh);
657 if (ret) {
658 current_max = U32_MAX;
659 goto out_free;
660 }
661
662 while (dev_size--)
663 current_max = max(current_max, rxfh.indir[dev_size]);
664
665 out_free:
666 kfree(rxfh.indir);
667 return current_max;
668 }
669
ethtool_check_max_channel(struct net_device * dev,struct ethtool_channels channels,struct genl_info * info)670 int ethtool_check_max_channel(struct net_device *dev,
671 struct ethtool_channels channels,
672 struct genl_info *info)
673 {
674 u64 max_rxnfc_in_use;
675 u32 max_rxfh_in_use;
676 int max_mp_in_use;
677
678 /* ensure the new Rx count fits within the configured Rx flow
679 * indirection table/rxnfc settings
680 */
681 if (ethtool_get_max_rxnfc_channel(dev, &max_rxnfc_in_use))
682 max_rxnfc_in_use = 0;
683 max_rxfh_in_use = ethtool_get_max_rxfh_channel(dev);
684 if (channels.combined_count + channels.rx_count <= max_rxfh_in_use) {
685 if (info)
686 GENL_SET_ERR_MSG_FMT(info, "requested channel counts are too low for existing indirection table (%d)", max_rxfh_in_use);
687 return -EINVAL;
688 }
689 if (channels.combined_count + channels.rx_count <= max_rxnfc_in_use) {
690 if (info)
691 GENL_SET_ERR_MSG(info, "requested channel counts are too low for existing ntuple filter settings");
692 return -EINVAL;
693 }
694
695 max_mp_in_use = dev_get_min_mp_channel_count(dev);
696 if (channels.combined_count + channels.rx_count <= max_mp_in_use) {
697 if (info)
698 GENL_SET_ERR_MSG_FMT(info, "requested channel counts are too low for existing memory provider setting (%d)", max_mp_in_use);
699 return -EINVAL;
700 }
701
702 return 0;
703 }
704
ethtool_check_rss_ctx_busy(struct net_device * dev,u32 rss_context)705 int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context)
706 {
707 const struct ethtool_ops *ops = dev->ethtool_ops;
708 struct ethtool_rxnfc *info;
709 int rc, i, rule_cnt;
710
711 if (!ops->get_rxnfc)
712 return 0;
713
714 rule_cnt = ethtool_get_rxnfc_rule_count(dev);
715 if (!rule_cnt)
716 return 0;
717
718 if (rule_cnt < 0)
719 return -EINVAL;
720
721 info = kvzalloc(struct_size(info, rule_locs, rule_cnt), GFP_KERNEL);
722 if (!info)
723 return -ENOMEM;
724
725 info->cmd = ETHTOOL_GRXCLSRLALL;
726 info->rule_cnt = rule_cnt;
727 rc = ops->get_rxnfc(dev, info, info->rule_locs);
728 if (rc)
729 goto out_free;
730
731 for (i = 0; i < rule_cnt; i++) {
732 struct ethtool_rxnfc rule_info = {
733 .cmd = ETHTOOL_GRXCLSRULE,
734 .fs.location = info->rule_locs[i],
735 };
736
737 rc = ops->get_rxnfc(dev, &rule_info, NULL);
738 if (rc)
739 goto out_free;
740
741 if (rule_info.fs.flow_type & FLOW_RSS &&
742 rule_info.rss_context == rss_context) {
743 rc = -EBUSY;
744 goto out_free;
745 }
746 }
747
748 out_free:
749 kvfree(info);
750 return rc;
751 }
752
ethtool_check_ops(const struct ethtool_ops * ops)753 int ethtool_check_ops(const struct ethtool_ops *ops)
754 {
755 if (WARN_ON(ops->set_coalesce && !ops->supported_coalesce_params))
756 return -EINVAL;
757 if (WARN_ON(ops->rxfh_max_num_contexts == 1))
758 return -EINVAL;
759 /* NOTE: sufficiently insane drivers may swap ethtool_ops at runtime,
760 * the fact that ops are checked at registration time does not
761 * mean the ops attached to a netdev later on are sane.
762 */
763 return 0;
764 }
765
__ethtool_get_ts_info(struct net_device * dev,struct kernel_ethtool_ts_info * info)766 int __ethtool_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info)
767 {
768 const struct ethtool_ops *ops = dev->ethtool_ops;
769 struct phy_device *phydev = dev->phydev;
770 int err = 0;
771
772 memset(info, 0, sizeof(*info));
773 info->cmd = ETHTOOL_GET_TS_INFO;
774 info->phc_index = -1;
775
776 if (phy_is_default_hwtstamp(phydev) && phy_has_tsinfo(phydev))
777 err = phy_ts_info(phydev, info);
778 else if (ops->get_ts_info)
779 err = ops->get_ts_info(dev, info);
780
781 info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
782 SOF_TIMESTAMPING_SOFTWARE;
783
784 return err;
785 }
786
ethtool_get_phc_vclocks(struct net_device * dev,int ** vclock_index)787 int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index)
788 {
789 struct kernel_ethtool_ts_info info = { };
790 int num = 0;
791
792 if (!__ethtool_get_ts_info(dev, &info))
793 num = ptp_get_vclocks_index(info.phc_index, vclock_index);
794
795 return num;
796 }
797 EXPORT_SYMBOL(ethtool_get_phc_vclocks);
798
ethtool_get_ts_info_by_layer(struct net_device * dev,struct kernel_ethtool_ts_info * info)799 int ethtool_get_ts_info_by_layer(struct net_device *dev, struct kernel_ethtool_ts_info *info)
800 {
801 return __ethtool_get_ts_info(dev, info);
802 }
803 EXPORT_SYMBOL(ethtool_get_ts_info_by_layer);
804
805 const struct ethtool_phy_ops *ethtool_phy_ops;
806
ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops * ops)807 void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops)
808 {
809 ASSERT_RTNL();
810 ethtool_phy_ops = ops;
811 }
812 EXPORT_SYMBOL_GPL(ethtool_set_ethtool_phy_ops);
813
814 void
ethtool_params_from_link_mode(struct ethtool_link_ksettings * link_ksettings,enum ethtool_link_mode_bit_indices link_mode)815 ethtool_params_from_link_mode(struct ethtool_link_ksettings *link_ksettings,
816 enum ethtool_link_mode_bit_indices link_mode)
817 {
818 const struct link_mode_info *link_info;
819
820 if (WARN_ON_ONCE(link_mode >= __ETHTOOL_LINK_MODE_MASK_NBITS))
821 return;
822
823 link_info = &link_mode_params[link_mode];
824 link_ksettings->base.speed = link_info->speed;
825 link_ksettings->lanes = link_info->lanes;
826 link_ksettings->base.duplex = link_info->duplex;
827 }
828 EXPORT_SYMBOL_GPL(ethtool_params_from_link_mode);
829
830 /**
831 * ethtool_forced_speed_maps_init
832 * @maps: Pointer to an array of Ethtool forced speed map
833 * @size: Array size
834 *
835 * Initialize an array of Ethtool forced speed map to Ethtool link modes. This
836 * should be called during driver module init.
837 */
838 void
ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map * maps,u32 size)839 ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, u32 size)
840 {
841 for (u32 i = 0; i < size; i++) {
842 struct ethtool_forced_speed_map *map = &maps[i];
843
844 linkmode_set_bit_array(map->cap_arr, map->arr_size, map->caps);
845 map->cap_arr = NULL;
846 map->arr_size = 0;
847 }
848 }
849 EXPORT_SYMBOL_GPL(ethtool_forced_speed_maps_init);
850
ethtool_rxfh_context_lost(struct net_device * dev,u32 context_id)851 void ethtool_rxfh_context_lost(struct net_device *dev, u32 context_id)
852 {
853 struct ethtool_rxfh_context *ctx;
854
855 WARN_ONCE(!rtnl_is_locked() &&
856 !lockdep_is_held_type(&dev->ethtool->rss_lock, -1),
857 "RSS context lock assertion failed\n");
858
859 netdev_err(dev, "device error, RSS context %d lost\n", context_id);
860 ctx = xa_erase(&dev->ethtool->rss_ctx, context_id);
861 kfree(ctx);
862 }
863 EXPORT_SYMBOL(ethtool_rxfh_context_lost);
864