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(&mdio->dev, data); 94 } 95 96 static inline void *mdiodev_get_drvdata(struct mdio_device *mdio) 97 { 98 return dev_get_drvdata(&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(&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, 0, 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, 0, 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(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, 315 advertising)) 316 result |= MDIO_AN_10GBT_CTRL_ADV2_5G; 317 if (linkmode_test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT, 318 advertising)) 319 result |= MDIO_AN_10GBT_CTRL_ADV5G; 320 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, 321 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(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, 339 advertising, lpa & MDIO_AN_10GBT_STAT_LP2_5G); 340 linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT, 341 advertising, lpa & MDIO_AN_10GBT_STAT_LP5G); 342 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, 343 advertising, 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(ETHTOOL_LINK_MODE_Pause_BIT, advertising, 358 lpa & MDIO_AN_T1_ADV_L_PAUSE_CAP); 359 linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising, 360 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(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, 375 advertising, lpa & MDIO_AN_T1_ADV_M_B10L); 376 } 377 378 /** 379 * linkmode_adv_to_mii_t1_adv_l_t 380 * @advertising: the linkmode advertisement settings 381 * 382 * A small helper function that translates linkmode advertisement 383 * settings to phy autonegotiation advertisements for the 384 * BASE-T1 Autonegotiation Advertisement [15:0] Register. 385 */ 386 static inline u32 linkmode_adv_to_mii_t1_adv_l_t(unsigned long *advertising) 387 { 388 u32 result = 0; 389 390 if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising)) 391 result |= MDIO_AN_T1_ADV_L_PAUSE_CAP; 392 if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising)) 393 result |= MDIO_AN_T1_ADV_L_PAUSE_ASYM; 394 395 return result; 396 } 397 398 /** 399 * linkmode_adv_to_mii_t1_adv_m_t 400 * @advertising: the linkmode advertisement settings 401 * 402 * A small helper function that translates linkmode advertisement 403 * settings to phy autonegotiation advertisements for the 404 * BASE-T1 Autonegotiation Advertisement [31:16] Register. 405 */ 406 static inline u32 linkmode_adv_to_mii_t1_adv_m_t(unsigned long *advertising) 407 { 408 u32 result = 0; 409 410 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, advertising)) 411 result |= MDIO_AN_T1_ADV_M_B10L; 412 413 return result; 414 } 415 416 /** 417 * mii_eee_cap1_mod_linkmode_t() 418 * @adv: target the linkmode advertisement settings 419 * @val: register value 420 * 421 * A function that translates value of following registers to the linkmode: 422 * IEEE 802.3-2018 45.2.3.10 "EEE control and capability 1" register (3.20) 423 * IEEE 802.3-2018 45.2.7.13 "EEE advertisement 1" register (7.60) 424 * IEEE 802.3-2018 45.2.7.14 "EEE link partner ability 1" register (7.61) 425 */ 426 static inline void mii_eee_cap1_mod_linkmode_t(unsigned long *adv, u32 val) 427 { 428 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, 429 adv, val & MDIO_EEE_100TX); 430 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, 431 adv, val & MDIO_EEE_1000T); 432 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, 433 adv, val & MDIO_EEE_10GT); 434 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, 435 adv, val & MDIO_EEE_1000KX); 436 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, 437 adv, val & MDIO_EEE_10GKX4); 438 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, 439 adv, val & MDIO_EEE_10GKR); 440 } 441 442 /** 443 * mii_eee_cap2_mod_linkmode_sup_t() 444 * @adv: target the linkmode settings 445 * @val: register value 446 * 447 * A function that translates value of following registers to the linkmode: 448 * IEEE 802.3-2022 45.2.3.11 "EEE control and capability 2" register (3.21) 449 */ 450 static inline void mii_eee_cap2_mod_linkmode_sup_t(unsigned long *adv, u32 val) 451 { 452 linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, 453 adv, val & MDIO_EEE_2_5GT); 454 linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT, 455 adv, val & MDIO_EEE_5GT); 456 } 457 458 /** 459 * mii_eee_cap2_mod_linkmode_adv_t() 460 * @adv: target the linkmode advertisement settings 461 * @val: register value 462 * 463 * A function that translates value of following registers to the linkmode: 464 * IEEE 802.3-2022 45.2.7.16 "EEE advertisement 2" register (7.62) 465 * IEEE 802.3-2022 45.2.7.17 "EEE link partner ability 2" register (7.63) 466 * Note: Currently this function is the same as mii_eee_cap2_mod_linkmode_sup_t. 467 * For certain, not yet supported, modes however the bits differ. 468 * Therefore create separate functions already. 469 */ 470 static inline void mii_eee_cap2_mod_linkmode_adv_t(unsigned long *adv, u32 val) 471 { 472 linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, 473 adv, val & MDIO_EEE_2_5GT); 474 linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT, 475 adv, val & MDIO_EEE_5GT); 476 } 477 478 /** 479 * linkmode_to_mii_eee_cap1_t() 480 * @adv: the linkmode advertisement settings 481 * 482 * A function that translates linkmode to value for IEEE 802.3-2018 45.2.7.13 483 * "EEE advertisement 1" register (7.60) 484 */ 485 static inline u32 linkmode_to_mii_eee_cap1_t(unsigned long *adv) 486 { 487 u32 result = 0; 488 489 if (linkmode_test_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, adv)) 490 result |= MDIO_EEE_100TX; 491 if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, adv)) 492 result |= MDIO_EEE_1000T; 493 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, adv)) 494 result |= MDIO_EEE_10GT; 495 if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, adv)) 496 result |= MDIO_EEE_1000KX; 497 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, adv)) 498 result |= MDIO_EEE_10GKX4; 499 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, adv)) 500 result |= MDIO_EEE_10GKR; 501 502 return result; 503 } 504 505 /** 506 * linkmode_to_mii_eee_cap2_t() 507 * @adv: the linkmode advertisement settings 508 * 509 * A function that translates linkmode to value for IEEE 802.3-2022 45.2.7.16 510 * "EEE advertisement 2" register (7.62) 511 */ 512 static inline u32 linkmode_to_mii_eee_cap2_t(unsigned long *adv) 513 { 514 u32 result = 0; 515 516 if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, adv)) 517 result |= MDIO_EEE_2_5GT; 518 if (linkmode_test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT, adv)) 519 result |= MDIO_EEE_5GT; 520 521 return result; 522 } 523 524 /** 525 * mii_10base_t1_adv_mod_linkmode_t() 526 * @adv: linkmode advertisement settings 527 * @val: register value 528 * 529 * A function that translates IEEE 802.3cg-2019 45.2.7.26 "10BASE-T1 AN status" 530 * register (7.527) value to the linkmode. 531 */ 532 static inline void mii_10base_t1_adv_mod_linkmode_t(unsigned long *adv, u16 val) 533 { 534 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, 535 adv, val & MDIO_AN_10BT1_AN_CTRL_ADV_EEE_T1L); 536 } 537 538 /** 539 * linkmode_adv_to_mii_10base_t1_t() 540 * @adv: linkmode advertisement settings 541 * 542 * A function that translates the linkmode to IEEE 802.3cg-2019 45.2.7.25 543 * "10BASE-T1 AN control" register (7.526) value. 544 */ 545 static inline u32 linkmode_adv_to_mii_10base_t1_t(unsigned long *adv) 546 { 547 u32 result = 0; 548 549 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT, adv)) 550 result |= MDIO_AN_10BT1_AN_CTRL_ADV_EEE_T1L; 551 552 return result; 553 } 554 555 /** 556 * mii_c73_mod_linkmode - convert a Clause 73 advertisement to linkmodes 557 * @adv: linkmode advertisement setting 558 * @lpa: array of three u16s containing the advertisement 559 * 560 * Convert an IEEE 802.3 Clause 73 advertisement to ethtool link modes. 561 */ 562 static inline void mii_c73_mod_linkmode(unsigned long *adv, u16 *lpa) 563 { 564 linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT, 565 adv, lpa[0] & MDIO_AN_C73_0_PAUSE); 566 linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, 567 adv, lpa[0] & MDIO_AN_C73_0_ASM_DIR); 568 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, 569 adv, lpa[1] & MDIO_AN_C73_1_1000BASE_KX); 570 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT, 571 adv, lpa[1] & MDIO_AN_C73_1_10GBASE_KX4); 572 linkmode_mod_bit(ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT, 573 adv, lpa[1] & MDIO_AN_C73_1_40GBASE_KR4); 574 linkmode_mod_bit(ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT, 575 adv, lpa[1] & MDIO_AN_C73_1_40GBASE_CR4); 576 /* 100GBASE_CR10 and 100GBASE_KP4 not implemented */ 577 linkmode_mod_bit(ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT, 578 adv, lpa[1] & MDIO_AN_C73_1_100GBASE_KR4); 579 linkmode_mod_bit(ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT, 580 adv, lpa[1] & MDIO_AN_C73_1_100GBASE_CR4); 581 /* 25GBASE_R_S not implemented */ 582 /* The 25GBASE_R bit can be used for 25Gbase KR or CR modes */ 583 linkmode_mod_bit(ETHTOOL_LINK_MODE_25000baseKR_Full_BIT, 584 adv, lpa[1] & MDIO_AN_C73_1_25GBASE_R); 585 linkmode_mod_bit(ETHTOOL_LINK_MODE_25000baseCR_Full_BIT, 586 adv, lpa[1] & MDIO_AN_C73_1_25GBASE_R); 587 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKR_Full_BIT, 588 adv, lpa[1] & MDIO_AN_C73_1_10GBASE_KR); 589 linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseX_Full_BIT, 590 adv, lpa[2] & MDIO_AN_C73_2_2500BASE_KX); 591 /* 5GBASE_KR not implemented */ 592 } 593 594 int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum); 595 int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val); 596 int __mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask, 597 u16 set); 598 int __mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, 599 u16 mask, u16 set); 600 601 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum); 602 int mdiobus_read_nested(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_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val); 605 int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask, 606 u16 set); 607 int mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, 608 u16 mask, u16 set); 609 int __mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum); 610 int mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum); 611 int mdiobus_c45_read_nested(struct mii_bus *bus, int addr, int devad, 612 u32 regnum); 613 int __mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnum, 614 u16 val); 615 int mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnum, 616 u16 val); 617 int mdiobus_c45_write_nested(struct mii_bus *bus, int addr, int devad, 618 u32 regnum, u16 val); 619 int mdiobus_c45_modify(struct mii_bus *bus, int addr, int devad, u32 regnum, 620 u16 mask, u16 set); 621 622 int mdiobus_c45_modify_changed(struct mii_bus *bus, int addr, int devad, 623 u32 regnum, u16 mask, u16 set); 624 625 static inline int __mdiodev_read(struct mdio_device *mdiodev, u32 regnum) 626 { 627 return __mdiobus_read(mdiodev->bus, mdiodev->addr, regnum); 628 } 629 630 static inline int __mdiodev_write(struct mdio_device *mdiodev, u32 regnum, 631 u16 val) 632 { 633 return __mdiobus_write(mdiodev->bus, mdiodev->addr, regnum, val); 634 } 635 636 static inline int __mdiodev_modify(struct mdio_device *mdiodev, u32 regnum, 637 u16 mask, u16 set) 638 { 639 return __mdiobus_modify(mdiodev->bus, mdiodev->addr, regnum, mask, set); 640 } 641 642 static inline int __mdiodev_modify_changed(struct mdio_device *mdiodev, 643 u32 regnum, u16 mask, u16 set) 644 { 645 return __mdiobus_modify_changed(mdiodev->bus, mdiodev->addr, regnum, 646 mask, set); 647 } 648 649 static inline int mdiodev_read(struct mdio_device *mdiodev, u32 regnum) 650 { 651 return mdiobus_read(mdiodev->bus, mdiodev->addr, regnum); 652 } 653 654 static inline int mdiodev_write(struct mdio_device *mdiodev, u32 regnum, 655 u16 val) 656 { 657 return mdiobus_write(mdiodev->bus, mdiodev->addr, regnum, val); 658 } 659 660 static inline int mdiodev_modify(struct mdio_device *mdiodev, u32 regnum, 661 u16 mask, u16 set) 662 { 663 return mdiobus_modify(mdiodev->bus, mdiodev->addr, regnum, mask, set); 664 } 665 666 static inline int mdiodev_modify_changed(struct mdio_device *mdiodev, 667 u32 regnum, u16 mask, u16 set) 668 { 669 return mdiobus_modify_changed(mdiodev->bus, mdiodev->addr, regnum, 670 mask, set); 671 } 672 673 static inline int mdiodev_c45_modify(struct mdio_device *mdiodev, int devad, 674 u32 regnum, u16 mask, u16 set) 675 { 676 return mdiobus_c45_modify(mdiodev->bus, mdiodev->addr, devad, regnum, 677 mask, set); 678 } 679 680 static inline int mdiodev_c45_modify_changed(struct mdio_device *mdiodev, 681 int devad, u32 regnum, u16 mask, 682 u16 set) 683 { 684 return mdiobus_c45_modify_changed(mdiodev->bus, mdiodev->addr, devad, 685 regnum, mask, set); 686 } 687 688 static inline int mdiodev_c45_read(struct mdio_device *mdiodev, int devad, 689 u16 regnum) 690 { 691 return mdiobus_c45_read(mdiodev->bus, mdiodev->addr, devad, regnum); 692 } 693 694 static inline int mdiodev_c45_write(struct mdio_device *mdiodev, u32 devad, 695 u16 regnum, u16 val) 696 { 697 return mdiobus_c45_write(mdiodev->bus, mdiodev->addr, devad, regnum, 698 val); 699 } 700 701 int mdiobus_register_device(struct mdio_device *mdiodev); 702 int mdiobus_unregister_device(struct mdio_device *mdiodev); 703 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr); 704 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr); 705 706 /** 707 * mdio_module_driver() - Helper macro for registering mdio drivers 708 * @_mdio_driver: driver to register 709 * 710 * Helper macro for MDIO drivers which do not do anything special in module 711 * init/exit. Each module may only use this macro once, and calling it 712 * replaces module_init() and module_exit(). 713 */ 714 #define mdio_module_driver(_mdio_driver) \ 715 static int __init mdio_module_init(void) \ 716 { \ 717 return mdio_driver_register(&_mdio_driver); \ 718 } \ 719 module_init(mdio_module_init); \ 720 static void __exit mdio_module_exit(void) \ 721 { \ 722 mdio_driver_unregister(&_mdio_driver); \ 723 } \ 724 module_exit(mdio_module_exit) 725 726 #endif /* __LINUX_MDIO_H__ */ 727