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