1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
2 | /* |
3 | * linux/mdio.h: definitions for MDIO (clause 45) transceivers |
4 | * Copyright 2006-2009 Solarflare Communications Inc. |
5 | */ |
6 | #ifndef __LINUX_MDIO_H__ |
7 | #define __LINUX_MDIO_H__ |
8 | |
9 | #include <uapi/linux/mdio.h> |
10 | #include <linux/bitfield.h> |
11 | #include <linux/mod_devicetable.h> |
12 | |
13 | struct gpio_desc; |
14 | struct mii_bus; |
15 | struct reset_control; |
16 | |
17 | /* Multiple levels of nesting are possible. However typically this is |
18 | * limited to nested DSA like layer, a MUX layer, and the normal |
19 | * user. Instead of trying to handle the general case, just define |
20 | * these cases. |
21 | */ |
22 | enum mdio_mutex_lock_class { |
23 | MDIO_MUTEX_NORMAL, |
24 | MDIO_MUTEX_MUX, |
25 | MDIO_MUTEX_NESTED, |
26 | }; |
27 | |
28 | struct mdio_device { |
29 | struct device dev; |
30 | |
31 | struct mii_bus *bus; |
32 | char modalias[MDIO_NAME_SIZE]; |
33 | |
34 | int (*bus_match)(struct device *dev, struct device_driver *drv); |
35 | void (*device_free)(struct mdio_device *mdiodev); |
36 | void (*device_remove)(struct mdio_device *mdiodev); |
37 | |
38 | /* Bus address of the MDIO device (0-31) */ |
39 | int addr; |
40 | int flags; |
41 | int reset_state; |
42 | struct gpio_desc *reset_gpio; |
43 | struct reset_control *reset_ctrl; |
44 | unsigned int reset_assert_delay; |
45 | unsigned int reset_deassert_delay; |
46 | }; |
47 | |
48 | static inline struct mdio_device *to_mdio_device(const struct device *dev) |
49 | { |
50 | return container_of(dev, struct mdio_device, dev); |
51 | } |
52 | |
53 | /* struct mdio_driver_common: Common to all MDIO drivers */ |
54 | struct mdio_driver_common { |
55 | struct device_driver driver; |
56 | int flags; |
57 | }; |
58 | #define MDIO_DEVICE_FLAG_PHY 1 |
59 | |
60 | static inline struct mdio_driver_common * |
61 | to_mdio_common_driver(const struct device_driver *driver) |
62 | { |
63 | return container_of(driver, struct mdio_driver_common, driver); |
64 | } |
65 | |
66 | /* struct mdio_driver: Generic MDIO driver */ |
67 | struct mdio_driver { |
68 | struct mdio_driver_common mdiodrv; |
69 | |
70 | /* |
71 | * Called during discovery. Used to set |
72 | * up device-specific structures, if any |
73 | */ |
74 | int (*probe)(struct mdio_device *mdiodev); |
75 | |
76 | /* Clears up any memory if needed */ |
77 | void (*remove)(struct mdio_device *mdiodev); |
78 | |
79 | /* Quiesces the device on system shutdown, turns off interrupts etc */ |
80 | void (*shutdown)(struct mdio_device *mdiodev); |
81 | }; |
82 | |
83 | static inline struct mdio_driver * |
84 | to_mdio_driver(const struct device_driver *driver) |
85 | { |
86 | return container_of(to_mdio_common_driver(driver), struct mdio_driver, |
87 | mdiodrv); |
88 | } |
89 | |
90 | /* device driver data */ |
91 | static inline void mdiodev_set_drvdata(struct mdio_device *mdio, void *data) |
92 | { |
93 | dev_set_drvdata(dev: &mdio->dev, data); |
94 | } |
95 | |
96 | static inline void *mdiodev_get_drvdata(struct mdio_device *mdio) |
97 | { |
98 | return dev_get_drvdata(dev: &mdio->dev); |
99 | } |
100 | |
101 | void mdio_device_free(struct mdio_device *mdiodev); |
102 | struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr); |
103 | int mdio_device_register(struct mdio_device *mdiodev); |
104 | void mdio_device_remove(struct mdio_device *mdiodev); |
105 | void mdio_device_reset(struct mdio_device *mdiodev, int value); |
106 | int mdio_driver_register(struct mdio_driver *drv); |
107 | void mdio_driver_unregister(struct mdio_driver *drv); |
108 | int mdio_device_bus_match(struct device *dev, struct device_driver *drv); |
109 | |
110 | static inline void mdio_device_get(struct mdio_device *mdiodev) |
111 | { |
112 | get_device(dev: &mdiodev->dev); |
113 | } |
114 | |
115 | static inline void mdio_device_put(struct mdio_device *mdiodev) |
116 | { |
117 | mdio_device_free(mdiodev); |
118 | } |
119 | |
120 | static inline bool mdio_phy_id_is_c45(int phy_id) |
121 | { |
122 | return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK); |
123 | } |
124 | |
125 | static inline __u16 mdio_phy_id_prtad(int phy_id) |
126 | { |
127 | return (phy_id & MDIO_PHY_ID_PRTAD) >> 5; |
128 | } |
129 | |
130 | static inline __u16 mdio_phy_id_devad(int phy_id) |
131 | { |
132 | return phy_id & MDIO_PHY_ID_DEVAD; |
133 | } |
134 | |
135 | /** |
136 | * struct mdio_if_info - Ethernet controller MDIO interface |
137 | * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown) |
138 | * @mmds: Mask of MMDs expected to be present in the PHY. This must be |
139 | * non-zero unless @prtad = %MDIO_PRTAD_NONE. |
140 | * @mode_support: MDIO modes supported. If %MDIO_SUPPORTS_C22 is set then |
141 | * MII register access will be passed through with @devad = |
142 | * %MDIO_DEVAD_NONE. If %MDIO_EMULATE_C22 is set then access to |
143 | * commonly used clause 22 registers will be translated into |
144 | * clause 45 registers. |
145 | * @dev: Net device structure |
146 | * @mdio_read: Register read function; returns value or negative error code |
147 | * @mdio_write: Register write function; returns 0 or negative error code |
148 | */ |
149 | struct mdio_if_info { |
150 | int prtad; |
151 | u32 mmds; |
152 | unsigned mode_support; |
153 | |
154 | struct net_device *dev; |
155 | int (*mdio_read)(struct net_device *dev, int prtad, int devad, |
156 | u16 addr); |
157 | int (*mdio_write)(struct net_device *dev, int prtad, int devad, |
158 | u16 addr, u16 val); |
159 | }; |
160 | |
161 | #define MDIO_PRTAD_NONE (-1) |
162 | #define MDIO_DEVAD_NONE (-1) |
163 | #define MDIO_SUPPORTS_C22 1 |
164 | #define MDIO_SUPPORTS_C45 2 |
165 | #define MDIO_EMULATE_C22 4 |
166 | |
167 | struct ethtool_cmd; |
168 | struct ethtool_pauseparam; |
169 | extern int mdio45_probe(struct mdio_if_info *mdio, int prtad); |
170 | extern int mdio_set_flag(const struct mdio_if_info *mdio, |
171 | int prtad, int devad, u16 addr, int mask, |
172 | bool sense); |
173 | extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds); |
174 | extern int mdio45_nway_restart(const struct mdio_if_info *mdio); |
175 | extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio, |
176 | struct ethtool_cmd *ecmd, |
177 | u32 npage_adv, u32 npage_lpa); |
178 | extern void |
179 | mdio45_ethtool_ksettings_get_npage(const struct mdio_if_info *mdio, |
180 | struct ethtool_link_ksettings *cmd, |
181 | u32 npage_adv, u32 npage_lpa); |
182 | |
183 | /** |
184 | * mdio45_ethtool_gset - get settings for ETHTOOL_GSET |
185 | * @mdio: MDIO interface |
186 | * @ecmd: Ethtool request structure |
187 | * |
188 | * Since the CSRs for auto-negotiation using next pages are not fully |
189 | * standardised, this function does not attempt to decode them. Use |
190 | * mdio45_ethtool_gset_npage() to specify advertisement bits from next |
191 | * pages. |
192 | */ |
193 | static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio, |
194 | struct ethtool_cmd *ecmd) |
195 | { |
196 | mdio45_ethtool_gset_npage(mdio, ecmd, npage_adv: 0, npage_lpa: 0); |
197 | } |
198 | |
199 | /** |
200 | * mdio45_ethtool_ksettings_get - get settings for ETHTOOL_GLINKSETTINGS |
201 | * @mdio: MDIO interface |
202 | * @cmd: Ethtool request structure |
203 | * |
204 | * Since the CSRs for auto-negotiation using next pages are not fully |
205 | * standardised, this function does not attempt to decode them. Use |
206 | * mdio45_ethtool_ksettings_get_npage() to specify advertisement bits |
207 | * from next pages. |
208 | */ |
209 | static inline void |
210 | mdio45_ethtool_ksettings_get(const struct mdio_if_info *mdio, |
211 | struct ethtool_link_ksettings *cmd) |
212 | { |
213 | mdio45_ethtool_ksettings_get_npage(mdio, cmd, npage_adv: 0, npage_lpa: 0); |
214 | } |
215 | |
216 | extern int mdio_mii_ioctl(const struct mdio_if_info *mdio, |
217 | struct mii_ioctl_data *mii_data, int cmd); |
218 | |
219 | /** |
220 | * mmd_eee_cap_to_ethtool_sup_t |
221 | * @eee_cap: value of the MMD EEE Capability register |
222 | * |
223 | * A small helper function that translates MMD EEE Capability (3.20) bits |
224 | * to ethtool supported settings. |
225 | */ |
226 | static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap) |
227 | { |
228 | u32 supported = 0; |
229 | |
230 | if (eee_cap & MDIO_EEE_100TX) |
231 | supported |= SUPPORTED_100baseT_Full; |
232 | if (eee_cap & MDIO_EEE_1000T) |
233 | supported |= SUPPORTED_1000baseT_Full; |
234 | if (eee_cap & MDIO_EEE_10GT) |
235 | supported |= SUPPORTED_10000baseT_Full; |
236 | if (eee_cap & MDIO_EEE_1000KX) |
237 | supported |= SUPPORTED_1000baseKX_Full; |
238 | if (eee_cap & MDIO_EEE_10GKX4) |
239 | supported |= SUPPORTED_10000baseKX4_Full; |
240 | if (eee_cap & MDIO_EEE_10GKR) |
241 | supported |= SUPPORTED_10000baseKR_Full; |
242 | |
243 | return supported; |
244 | } |
245 | |
246 | /** |
247 | * mmd_eee_adv_to_ethtool_adv_t |
248 | * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers |
249 | * |
250 | * A small helper function that translates the MMD EEE Advertisment (7.60) |
251 | * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement |
252 | * settings. |
253 | */ |
254 | static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv) |
255 | { |
256 | u32 adv = 0; |
257 | |
258 | if (eee_adv & MDIO_EEE_100TX) |
259 | adv |= ADVERTISED_100baseT_Full; |
260 | if (eee_adv & MDIO_EEE_1000T) |
261 | adv |= ADVERTISED_1000baseT_Full; |
262 | if (eee_adv & MDIO_EEE_10GT) |
263 | adv |= ADVERTISED_10000baseT_Full; |
264 | if (eee_adv & MDIO_EEE_1000KX) |
265 | adv |= ADVERTISED_1000baseKX_Full; |
266 | if (eee_adv & MDIO_EEE_10GKX4) |
267 | adv |= ADVERTISED_10000baseKX4_Full; |
268 | if (eee_adv & MDIO_EEE_10GKR) |
269 | adv |= ADVERTISED_10000baseKR_Full; |
270 | |
271 | return adv; |
272 | } |
273 | |
274 | /** |
275 | * ethtool_adv_to_mmd_eee_adv_t |
276 | * @adv: the ethtool advertisement settings |
277 | * |
278 | * A small helper function that translates ethtool advertisement settings |
279 | * to EEE advertisements for the MMD EEE Advertisement (7.60) and |
280 | * MMD EEE Link Partner Ability (7.61) registers. |
281 | */ |
282 | static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv) |
283 | { |
284 | u16 reg = 0; |
285 | |
286 | if (adv & ADVERTISED_100baseT_Full) |
287 | reg |= MDIO_EEE_100TX; |
288 | if (adv & ADVERTISED_1000baseT_Full) |
289 | reg |= MDIO_EEE_1000T; |
290 | if (adv & ADVERTISED_10000baseT_Full) |
291 | reg |= MDIO_EEE_10GT; |
292 | if (adv & ADVERTISED_1000baseKX_Full) |
293 | reg |= MDIO_EEE_1000KX; |
294 | if (adv & ADVERTISED_10000baseKX4_Full) |
295 | reg |= MDIO_EEE_10GKX4; |
296 | if (adv & ADVERTISED_10000baseKR_Full) |
297 | reg |= MDIO_EEE_10GKR; |
298 | |
299 | return reg; |
300 | } |
301 | |
302 | /** |
303 | * linkmode_adv_to_mii_10gbt_adv_t |
304 | * @advertising: the linkmode advertisement settings |
305 | * |
306 | * A small helper function that translates linkmode advertisement |
307 | * settings to phy autonegotiation advertisements for the C45 |
308 | * 10GBASE-T AN CONTROL (7.32) register. |
309 | */ |
310 | static inline u32 linkmode_adv_to_mii_10gbt_adv_t(unsigned long *advertising) |
311 | { |
312 | u32 result = 0; |
313 | |
314 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_2500baseT_Full_BIT, |
315 | addr: advertising)) |
316 | result |= MDIO_AN_10GBT_CTRL_ADV2_5G; |
317 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_5000baseT_Full_BIT, |
318 | addr: advertising)) |
319 | result |= MDIO_AN_10GBT_CTRL_ADV5G; |
320 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_10000baseT_Full_BIT, |
321 | addr: advertising)) |
322 | result |= MDIO_AN_10GBT_CTRL_ADV10G; |
323 | |
324 | return result; |
325 | } |
326 | |
327 | /** |
328 | * mii_10gbt_stat_mod_linkmode_lpa_t |
329 | * @advertising: target the linkmode advertisement settings |
330 | * @lpa: value of the C45 10GBASE-T AN STATUS register |
331 | * |
332 | * A small helper function that translates C45 10GBASE-T AN STATUS register bits |
333 | * to linkmode advertisement settings. Other bits in advertising aren't changed. |
334 | */ |
335 | static inline void mii_10gbt_stat_mod_linkmode_lpa_t(unsigned long *advertising, |
336 | u32 lpa) |
337 | { |
338 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_2500baseT_Full_BIT, |
339 | addr: advertising, set: lpa & MDIO_AN_10GBT_STAT_LP2_5G); |
340 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_5000baseT_Full_BIT, |
341 | addr: advertising, set: lpa & MDIO_AN_10GBT_STAT_LP5G); |
342 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_10000baseT_Full_BIT, |
343 | addr: advertising, set: lpa & MDIO_AN_10GBT_STAT_LP10G); |
344 | } |
345 | |
346 | /** |
347 | * mii_t1_adv_l_mod_linkmode_t |
348 | * @advertising: target the linkmode advertisement settings |
349 | * @lpa: value of the BASE-T1 Autonegotiation Advertisement [15:0] Register |
350 | * |
351 | * A small helper function that translates BASE-T1 Autonegotiation |
352 | * Advertisement [15:0] Register bits to linkmode advertisement settings. |
353 | * Other bits in advertising aren't changed. |
354 | */ |
355 | static inline void mii_t1_adv_l_mod_linkmode_t(unsigned long *advertising, u32 lpa) |
356 | { |
357 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_Pause_BIT, addr: advertising, |
358 | set: lpa & MDIO_AN_T1_ADV_L_PAUSE_CAP); |
359 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_Asym_Pause_BIT, addr: advertising, |
360 | set: lpa & MDIO_AN_T1_ADV_L_PAUSE_ASYM); |
361 | } |
362 | |
363 | /** |
364 | * mii_t1_adv_m_mod_linkmode_t |
365 | * @advertising: target the linkmode advertisement settings |
366 | * @lpa: value of the BASE-T1 Autonegotiation Advertisement [31:16] Register |
367 | * |
368 | * A small helper function that translates BASE-T1 Autonegotiation |
369 | * Advertisement [31:16] Register bits to linkmode advertisement settings. |
370 | * Other bits in advertising aren't changed. |
371 | */ |
372 | static inline void mii_t1_adv_m_mod_linkmode_t(unsigned long *advertising, u32 lpa) |
373 | { |
374 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, |
375 | addr: advertising, set: lpa & MDIO_AN_T1_ADV_M_B10L); |
376 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_100baseT1_Full_BIT, |
377 | addr: advertising, set: lpa & MDIO_AN_T1_ADV_M_100BT1); |
378 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_1000baseT1_Full_BIT, |
379 | addr: advertising, set: lpa & MDIO_AN_T1_ADV_M_1000BT1); |
380 | } |
381 | |
382 | /** |
383 | * linkmode_adv_to_mii_t1_adv_l_t |
384 | * @advertising: the linkmode advertisement settings |
385 | * |
386 | * A small helper function that translates linkmode advertisement |
387 | * settings to phy autonegotiation advertisements for the |
388 | * BASE-T1 Autonegotiation Advertisement [15:0] Register. |
389 | */ |
390 | static inline u32 linkmode_adv_to_mii_t1_adv_l_t(unsigned long *advertising) |
391 | { |
392 | u32 result = 0; |
393 | |
394 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_Pause_BIT, addr: advertising)) |
395 | result |= MDIO_AN_T1_ADV_L_PAUSE_CAP; |
396 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_Asym_Pause_BIT, addr: advertising)) |
397 | result |= MDIO_AN_T1_ADV_L_PAUSE_ASYM; |
398 | |
399 | return result; |
400 | } |
401 | |
402 | /** |
403 | * linkmode_adv_to_mii_t1_adv_m_t |
404 | * @advertising: the linkmode advertisement settings |
405 | * |
406 | * A small helper function that translates linkmode advertisement |
407 | * settings to phy autonegotiation advertisements for the |
408 | * BASE-T1 Autonegotiation Advertisement [31:16] Register. |
409 | */ |
410 | static inline u32 linkmode_adv_to_mii_t1_adv_m_t(unsigned long *advertising) |
411 | { |
412 | u32 result = 0; |
413 | |
414 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, addr: advertising)) |
415 | result |= MDIO_AN_T1_ADV_M_B10L; |
416 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_100baseT1_Full_BIT, addr: advertising)) |
417 | result |= MDIO_AN_T1_ADV_M_100BT1; |
418 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_1000baseT1_Full_BIT, addr: advertising)) |
419 | result |= MDIO_AN_T1_ADV_M_1000BT1; |
420 | |
421 | return result; |
422 | } |
423 | |
424 | /** |
425 | * mii_eee_cap1_mod_linkmode_t() |
426 | * @adv: target the linkmode advertisement settings |
427 | * @val: register value |
428 | * |
429 | * A function that translates value of following registers to the linkmode: |
430 | * IEEE 802.3-2018 45.2.3.10 "EEE control and capability 1" register (3.20) |
431 | * IEEE 802.3-2018 45.2.7.13 "EEE advertisement 1" register (7.60) |
432 | * IEEE 802.3-2018 45.2.7.14 "EEE link partner ability 1" register (7.61) |
433 | */ |
434 | static inline void mii_eee_cap1_mod_linkmode_t(unsigned long *adv, u32 val) |
435 | { |
436 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_100baseT_Full_BIT, |
437 | addr: adv, set: val & MDIO_EEE_100TX); |
438 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_1000baseT_Full_BIT, |
439 | addr: adv, set: val & MDIO_EEE_1000T); |
440 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_10000baseT_Full_BIT, |
441 | addr: adv, set: val & MDIO_EEE_10GT); |
442 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, |
443 | addr: adv, set: val & MDIO_EEE_1000KX); |
444 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, |
445 | addr: adv, set: val & MDIO_EEE_10GKX4); |
446 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, |
447 | addr: adv, set: val & MDIO_EEE_10GKR); |
448 | } |
449 | |
450 | /** |
451 | * mii_eee_cap2_mod_linkmode_sup_t() |
452 | * @adv: target the linkmode settings |
453 | * @val: register value |
454 | * |
455 | * A function that translates value of following registers to the linkmode: |
456 | * IEEE 802.3-2022 45.2.3.11 "EEE control and capability 2" register (3.21) |
457 | */ |
458 | static inline void mii_eee_cap2_mod_linkmode_sup_t(unsigned long *adv, u32 val) |
459 | { |
460 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_2500baseT_Full_BIT, |
461 | addr: adv, set: val & MDIO_EEE_2_5GT); |
462 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_5000baseT_Full_BIT, |
463 | addr: adv, set: val & MDIO_EEE_5GT); |
464 | } |
465 | |
466 | /** |
467 | * mii_eee_cap2_mod_linkmode_adv_t() |
468 | * @adv: target the linkmode advertisement settings |
469 | * @val: register value |
470 | * |
471 | * A function that translates value of following registers to the linkmode: |
472 | * IEEE 802.3-2022 45.2.7.16 "EEE advertisement 2" register (7.62) |
473 | * IEEE 802.3-2022 45.2.7.17 "EEE link partner ability 2" register (7.63) |
474 | * Note: Currently this function is the same as mii_eee_cap2_mod_linkmode_sup_t. |
475 | * For certain, not yet supported, modes however the bits differ. |
476 | * Therefore create separate functions already. |
477 | */ |
478 | static inline void mii_eee_cap2_mod_linkmode_adv_t(unsigned long *adv, u32 val) |
479 | { |
480 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_2500baseT_Full_BIT, |
481 | addr: adv, set: val & MDIO_EEE_2_5GT); |
482 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_5000baseT_Full_BIT, |
483 | addr: adv, set: val & MDIO_EEE_5GT); |
484 | } |
485 | |
486 | /** |
487 | * linkmode_to_mii_eee_cap1_t() |
488 | * @adv: the linkmode advertisement settings |
489 | * |
490 | * A function that translates linkmode to value for IEEE 802.3-2018 45.2.7.13 |
491 | * "EEE advertisement 1" register (7.60) |
492 | */ |
493 | static inline u32 linkmode_to_mii_eee_cap1_t(unsigned long *adv) |
494 | { |
495 | u32 result = 0; |
496 | |
497 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_100baseT_Full_BIT, addr: adv)) |
498 | result |= MDIO_EEE_100TX; |
499 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_1000baseT_Full_BIT, addr: adv)) |
500 | result |= MDIO_EEE_1000T; |
501 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_10000baseT_Full_BIT, addr: adv)) |
502 | result |= MDIO_EEE_10GT; |
503 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, addr: adv)) |
504 | result |= MDIO_EEE_1000KX; |
505 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, addr: adv)) |
506 | result |= MDIO_EEE_10GKX4; |
507 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, addr: adv)) |
508 | result |= MDIO_EEE_10GKR; |
509 | |
510 | return result; |
511 | } |
512 | |
513 | /** |
514 | * linkmode_to_mii_eee_cap2_t() |
515 | * @adv: the linkmode advertisement settings |
516 | * |
517 | * A function that translates linkmode to value for IEEE 802.3-2022 45.2.7.16 |
518 | * "EEE advertisement 2" register (7.62) |
519 | */ |
520 | static inline u32 linkmode_to_mii_eee_cap2_t(unsigned long *adv) |
521 | { |
522 | u32 result = 0; |
523 | |
524 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_2500baseT_Full_BIT, addr: adv)) |
525 | result |= MDIO_EEE_2_5GT; |
526 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_5000baseT_Full_BIT, addr: adv)) |
527 | result |= MDIO_EEE_5GT; |
528 | |
529 | return result; |
530 | } |
531 | |
532 | /** |
533 | * mii_10base_t1_adv_mod_linkmode_t() |
534 | * @adv: linkmode advertisement settings |
535 | * @val: register value |
536 | * |
537 | * A function that translates IEEE 802.3cg-2019 45.2.7.26 "10BASE-T1 AN status" |
538 | * register (7.527) value to the linkmode. |
539 | */ |
540 | static inline void mii_10base_t1_adv_mod_linkmode_t(unsigned long *adv, u16 val) |
541 | { |
542 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, |
543 | addr: adv, set: val & MDIO_AN_10BT1_AN_CTRL_ADV_EEE_T1L); |
544 | } |
545 | |
546 | /** |
547 | * linkmode_adv_to_mii_10base_t1_t() |
548 | * @adv: linkmode advertisement settings |
549 | * |
550 | * A function that translates the linkmode to IEEE 802.3cg-2019 45.2.7.25 |
551 | * "10BASE-T1 AN control" register (7.526) value. |
552 | */ |
553 | static inline u32 linkmode_adv_to_mii_10base_t1_t(unsigned long *adv) |
554 | { |
555 | u32 result = 0; |
556 | |
557 | if (linkmode_test_bit(nr: ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, addr: adv)) |
558 | result |= MDIO_AN_10BT1_AN_CTRL_ADV_EEE_T1L; |
559 | |
560 | return result; |
561 | } |
562 | |
563 | /** |
564 | * mii_c73_mod_linkmode - convert a Clause 73 advertisement to linkmodes |
565 | * @adv: linkmode advertisement setting |
566 | * @lpa: array of three u16s containing the advertisement |
567 | * |
568 | * Convert an IEEE 802.3 Clause 73 advertisement to ethtool link modes. |
569 | */ |
570 | static inline void mii_c73_mod_linkmode(unsigned long *adv, u16 *lpa) |
571 | { |
572 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_Pause_BIT, |
573 | addr: adv, set: lpa[0] & MDIO_AN_C73_0_PAUSE); |
574 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_Asym_Pause_BIT, |
575 | addr: adv, set: lpa[0] & MDIO_AN_C73_0_ASM_DIR); |
576 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, |
577 | addr: adv, set: lpa[1] & MDIO_AN_C73_1_1000BASE_KX); |
578 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, |
579 | addr: adv, set: lpa[1] & MDIO_AN_C73_1_10GBASE_KX4); |
580 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT, |
581 | addr: adv, set: lpa[1] & MDIO_AN_C73_1_40GBASE_KR4); |
582 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT, |
583 | addr: adv, set: lpa[1] & MDIO_AN_C73_1_40GBASE_CR4); |
584 | /* 100GBASE_CR10 and 100GBASE_KP4 not implemented */ |
585 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT, |
586 | addr: adv, set: lpa[1] & MDIO_AN_C73_1_100GBASE_KR4); |
587 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT, |
588 | addr: adv, set: lpa[1] & MDIO_AN_C73_1_100GBASE_CR4); |
589 | /* 25GBASE_R_S not implemented */ |
590 | /* The 25GBASE_R bit can be used for 25Gbase KR or CR modes */ |
591 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_25000baseKR_Full_BIT, |
592 | addr: adv, set: lpa[1] & MDIO_AN_C73_1_25GBASE_R); |
593 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_25000baseCR_Full_BIT, |
594 | addr: adv, set: lpa[1] & MDIO_AN_C73_1_25GBASE_R); |
595 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, |
596 | addr: adv, set: lpa[1] & MDIO_AN_C73_1_10GBASE_KR); |
597 | linkmode_mod_bit(nr: ETHTOOL_LINK_MODE_2500baseX_Full_BIT, |
598 | addr: adv, set: lpa[2] & MDIO_AN_C73_2_2500BASE_KX); |
599 | /* 5GBASE_KR not implemented */ |
600 | } |
601 | |
602 | int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum); |
603 | int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val); |
604 | int __mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask, |
605 | u16 set); |
606 | int __mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, |
607 | u16 mask, u16 set); |
608 | |
609 | int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum); |
610 | int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum); |
611 | int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val); |
612 | int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val); |
613 | int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask, |
614 | u16 set); |
615 | int mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, |
616 | u16 mask, u16 set); |
617 | int __mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum); |
618 | int mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum); |
619 | int mdiobus_c45_read_nested(struct mii_bus *bus, int addr, int devad, |
620 | u32 regnum); |
621 | int __mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnum, |
622 | u16 val); |
623 | int mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnum, |
624 | u16 val); |
625 | int mdiobus_c45_write_nested(struct mii_bus *bus, int addr, int devad, |
626 | u32 regnum, u16 val); |
627 | int mdiobus_c45_modify(struct mii_bus *bus, int addr, int devad, u32 regnum, |
628 | u16 mask, u16 set); |
629 | |
630 | int mdiobus_c45_modify_changed(struct mii_bus *bus, int addr, int devad, |
631 | u32 regnum, u16 mask, u16 set); |
632 | |
633 | static inline int __mdiodev_read(struct mdio_device *mdiodev, u32 regnum) |
634 | { |
635 | return __mdiobus_read(bus: mdiodev->bus, addr: mdiodev->addr, regnum); |
636 | } |
637 | |
638 | static inline int __mdiodev_write(struct mdio_device *mdiodev, u32 regnum, |
639 | u16 val) |
640 | { |
641 | return __mdiobus_write(bus: mdiodev->bus, addr: mdiodev->addr, regnum, val); |
642 | } |
643 | |
644 | static inline int __mdiodev_modify(struct mdio_device *mdiodev, u32 regnum, |
645 | u16 mask, u16 set) |
646 | { |
647 | return __mdiobus_modify(bus: mdiodev->bus, addr: mdiodev->addr, regnum, mask, set); |
648 | } |
649 | |
650 | static inline int __mdiodev_modify_changed(struct mdio_device *mdiodev, |
651 | u32 regnum, u16 mask, u16 set) |
652 | { |
653 | return __mdiobus_modify_changed(bus: mdiodev->bus, addr: mdiodev->addr, regnum, |
654 | mask, set); |
655 | } |
656 | |
657 | static inline int mdiodev_read(struct mdio_device *mdiodev, u32 regnum) |
658 | { |
659 | return mdiobus_read(bus: mdiodev->bus, addr: mdiodev->addr, regnum); |
660 | } |
661 | |
662 | static inline int mdiodev_write(struct mdio_device *mdiodev, u32 regnum, |
663 | u16 val) |
664 | { |
665 | return mdiobus_write(bus: mdiodev->bus, addr: mdiodev->addr, regnum, val); |
666 | } |
667 | |
668 | static inline int mdiodev_modify(struct mdio_device *mdiodev, u32 regnum, |
669 | u16 mask, u16 set) |
670 | { |
671 | return mdiobus_modify(bus: mdiodev->bus, addr: mdiodev->addr, regnum, mask, set); |
672 | } |
673 | |
674 | static inline int mdiodev_modify_changed(struct mdio_device *mdiodev, |
675 | u32 regnum, u16 mask, u16 set) |
676 | { |
677 | return mdiobus_modify_changed(bus: mdiodev->bus, addr: mdiodev->addr, regnum, |
678 | mask, set); |
679 | } |
680 | |
681 | static inline int mdiodev_c45_modify(struct mdio_device *mdiodev, int devad, |
682 | u32 regnum, u16 mask, u16 set) |
683 | { |
684 | return mdiobus_c45_modify(bus: mdiodev->bus, addr: mdiodev->addr, devad, regnum, |
685 | mask, set); |
686 | } |
687 | |
688 | static inline int mdiodev_c45_modify_changed(struct mdio_device *mdiodev, |
689 | int devad, u32 regnum, u16 mask, |
690 | u16 set) |
691 | { |
692 | return mdiobus_c45_modify_changed(bus: mdiodev->bus, addr: mdiodev->addr, devad, |
693 | regnum, mask, set); |
694 | } |
695 | |
696 | static inline int mdiodev_c45_read(struct mdio_device *mdiodev, int devad, |
697 | u16 regnum) |
698 | { |
699 | return mdiobus_c45_read(bus: mdiodev->bus, addr: mdiodev->addr, devad, regnum); |
700 | } |
701 | |
702 | static inline int mdiodev_c45_write(struct mdio_device *mdiodev, u32 devad, |
703 | u16 regnum, u16 val) |
704 | { |
705 | return mdiobus_c45_write(bus: mdiodev->bus, addr: mdiodev->addr, devad, regnum, |
706 | val); |
707 | } |
708 | |
709 | int mdiobus_register_device(struct mdio_device *mdiodev); |
710 | int mdiobus_unregister_device(struct mdio_device *mdiodev); |
711 | bool mdiobus_is_registered_device(struct mii_bus *bus, int addr); |
712 | struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr); |
713 | |
714 | /** |
715 | * mdio_module_driver() - Helper macro for registering mdio drivers |
716 | * @_mdio_driver: driver to register |
717 | * |
718 | * Helper macro for MDIO drivers which do not do anything special in module |
719 | * init/exit. Each module may only use this macro once, and calling it |
720 | * replaces module_init() and module_exit(). |
721 | */ |
722 | #define mdio_module_driver(_mdio_driver) \ |
723 | static int __init mdio_module_init(void) \ |
724 | { \ |
725 | return mdio_driver_register(&_mdio_driver); \ |
726 | } \ |
727 | module_init(mdio_module_init); \ |
728 | static void __exit mdio_module_exit(void) \ |
729 | { \ |
730 | mdio_driver_unregister(&_mdio_driver); \ |
731 | } \ |
732 | module_exit(mdio_module_exit) |
733 | |
734 | #endif /* __LINUX_MDIO_H__ */ |
735 | |