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