phy.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Framework and drivers for configuring and reading different PHYs
  4. * Based on code in sungem_phy.c and (long-removed) gianfar_phy.c
  5. *
  6. * Author: Andy Fleming
  7. *
  8. * Copyright (c) 2004 Freescale Semiconductor, Inc.
  9. */
  10. #ifndef __PHY_H
  11. #define __PHY_H
  12. #include <linux/compiler.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/ethtool.h>
  15. #include <linux/linkmode.h>
  16. #include <linux/mdio.h>
  17. #include <linux/mii.h>
  18. #include <linux/module.h>
  19. #include <linux/timer.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/mod_devicetable.h>
  22. #include <linux/atomic.h>
  23. #define PHY_DEFAULT_FEATURES (SUPPORTED_Autoneg | \
  24. SUPPORTED_TP | \
  25. SUPPORTED_MII)
  26. #define PHY_10BT_FEATURES (SUPPORTED_10baseT_Half | \
  27. SUPPORTED_10baseT_Full)
  28. #define PHY_100BT_FEATURES (SUPPORTED_100baseT_Half | \
  29. SUPPORTED_100baseT_Full)
  30. #define PHY_1000BT_FEATURES (SUPPORTED_1000baseT_Half | \
  31. SUPPORTED_1000baseT_Full)
  32. extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_features) __ro_after_init;
  33. extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_t1_features) __ro_after_init;
  34. extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_features) __ro_after_init;
  35. extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_fibre_features) __ro_after_init;
  36. extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_all_ports_features) __ro_after_init;
  37. extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_features) __ro_after_init;
  38. extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_fec_features) __ro_after_init;
  39. extern __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_full_features) __ro_after_init;
  40. #define PHY_BASIC_FEATURES ((unsigned long *)&phy_basic_features)
  41. #define PHY_BASIC_T1_FEATURES ((unsigned long *)&phy_basic_t1_features)
  42. #define PHY_GBIT_FEATURES ((unsigned long *)&phy_gbit_features)
  43. #define PHY_GBIT_FIBRE_FEATURES ((unsigned long *)&phy_gbit_fibre_features)
  44. #define PHY_GBIT_ALL_PORTS_FEATURES ((unsigned long *)&phy_gbit_all_ports_features)
  45. #define PHY_10GBIT_FEATURES ((unsigned long *)&phy_10gbit_features)
  46. #define PHY_10GBIT_FEC_FEATURES ((unsigned long *)&phy_10gbit_fec_features)
  47. #define PHY_10GBIT_FULL_FEATURES ((unsigned long *)&phy_10gbit_full_features)
  48. extern const int phy_basic_ports_array[3];
  49. extern const int phy_fibre_port_array[1];
  50. extern const int phy_all_ports_features_array[7];
  51. extern const int phy_10_100_features_array[4];
  52. extern const int phy_basic_t1_features_array[2];
  53. extern const int phy_gbit_features_array[2];
  54. extern const int phy_10gbit_features_array[1];
  55. /*
  56. * Set phydev->irq to PHY_POLL if interrupts are not supported,
  57. * or not desired for this PHY. Set to PHY_IGNORE_INTERRUPT if
  58. * the attached driver handles the interrupt
  59. */
  60. #define PHY_POLL -1
  61. #define PHY_IGNORE_INTERRUPT -2
  62. #define PHY_IS_INTERNAL 0x00000001
  63. #define PHY_RST_AFTER_CLK_EN 0x00000002
  64. #define MDIO_DEVICE_IS_PHY 0x80000000
  65. /* Interface Mode definitions */
  66. typedef enum {
  67. PHY_INTERFACE_MODE_NA,
  68. PHY_INTERFACE_MODE_INTERNAL,
  69. PHY_INTERFACE_MODE_MII,
  70. PHY_INTERFACE_MODE_GMII,
  71. PHY_INTERFACE_MODE_SGMII,
  72. PHY_INTERFACE_MODE_TBI,
  73. PHY_INTERFACE_MODE_REVMII,
  74. PHY_INTERFACE_MODE_RMII,
  75. PHY_INTERFACE_MODE_RGMII,
  76. PHY_INTERFACE_MODE_RGMII_ID,
  77. PHY_INTERFACE_MODE_RGMII_RXID,
  78. PHY_INTERFACE_MODE_RGMII_TXID,
  79. PHY_INTERFACE_MODE_RTBI,
  80. PHY_INTERFACE_MODE_SMII,
  81. PHY_INTERFACE_MODE_XGMII,
  82. PHY_INTERFACE_MODE_MOCA,
  83. PHY_INTERFACE_MODE_QSGMII,
  84. PHY_INTERFACE_MODE_TRGMII,
  85. PHY_INTERFACE_MODE_1000BASEX,
  86. PHY_INTERFACE_MODE_2500BASEX,
  87. PHY_INTERFACE_MODE_RXAUI,
  88. PHY_INTERFACE_MODE_XAUI,
  89. /* 10GBASE-KR, XFI, SFI - single lane 10G Serdes */
  90. PHY_INTERFACE_MODE_10GKR,
  91. PHY_INTERFACE_MODE_USXGMII,
  92. PHY_INTERFACE_MODE_MAX,
  93. } phy_interface_t;
  94. /**
  95. * phy_supported_speeds - return all speeds currently supported by a phy device
  96. * @phy: The phy device to return supported speeds of.
  97. * @speeds: buffer to store supported speeds in.
  98. * @size: size of speeds buffer.
  99. *
  100. * Description: Returns the number of supported speeds, and fills
  101. * the speeds buffer with the supported speeds. If speeds buffer is
  102. * too small to contain all currently supported speeds, will return as
  103. * many speeds as can fit.
  104. */
  105. unsigned int phy_supported_speeds(struct phy_device *phy,
  106. unsigned int *speeds,
  107. unsigned int size);
  108. /**
  109. * phy_modes - map phy_interface_t enum to device tree binding of phy-mode
  110. * @interface: enum phy_interface_t value
  111. *
  112. * Description: maps 'enum phy_interface_t' defined in this file
  113. * into the device tree binding of 'phy-mode', so that Ethernet
  114. * device driver can get phy interface from device tree.
  115. */
  116. static inline const char *phy_modes(phy_interface_t interface)
  117. {
  118. switch (interface) {
  119. case PHY_INTERFACE_MODE_NA:
  120. return "";
  121. case PHY_INTERFACE_MODE_INTERNAL:
  122. return "internal";
  123. case PHY_INTERFACE_MODE_MII:
  124. return "mii";
  125. case PHY_INTERFACE_MODE_GMII:
  126. return "gmii";
  127. case PHY_INTERFACE_MODE_SGMII:
  128. return "sgmii";
  129. case PHY_INTERFACE_MODE_TBI:
  130. return "tbi";
  131. case PHY_INTERFACE_MODE_REVMII:
  132. return "rev-mii";
  133. case PHY_INTERFACE_MODE_RMII:
  134. return "rmii";
  135. case PHY_INTERFACE_MODE_RGMII:
  136. return "rgmii";
  137. case PHY_INTERFACE_MODE_RGMII_ID:
  138. return "rgmii-id";
  139. case PHY_INTERFACE_MODE_RGMII_RXID:
  140. return "rgmii-rxid";
  141. case PHY_INTERFACE_MODE_RGMII_TXID:
  142. return "rgmii-txid";
  143. case PHY_INTERFACE_MODE_RTBI:
  144. return "rtbi";
  145. case PHY_INTERFACE_MODE_SMII:
  146. return "smii";
  147. case PHY_INTERFACE_MODE_XGMII:
  148. return "xgmii";
  149. case PHY_INTERFACE_MODE_MOCA:
  150. return "moca";
  151. case PHY_INTERFACE_MODE_QSGMII:
  152. return "qsgmii";
  153. case PHY_INTERFACE_MODE_TRGMII:
  154. return "trgmii";
  155. case PHY_INTERFACE_MODE_1000BASEX:
  156. return "1000base-x";
  157. case PHY_INTERFACE_MODE_2500BASEX:
  158. return "2500base-x";
  159. case PHY_INTERFACE_MODE_RXAUI:
  160. return "rxaui";
  161. case PHY_INTERFACE_MODE_XAUI:
  162. return "xaui";
  163. case PHY_INTERFACE_MODE_10GKR:
  164. return "10gbase-kr";
  165. case PHY_INTERFACE_MODE_USXGMII:
  166. return "usxgmii";
  167. default:
  168. return "unknown";
  169. }
  170. }
  171. #define PHY_INIT_TIMEOUT 100000
  172. #define PHY_FORCE_TIMEOUT 10
  173. #define PHY_MAX_ADDR 32
  174. /* Used when trying to connect to a specific phy (mii bus id:phy device id) */
  175. #define PHY_ID_FMT "%s:%02x"
  176. #define MII_BUS_ID_SIZE 61
  177. /* Or MII_ADDR_C45 into regnum for read/write on mii_bus to enable the 21 bit
  178. IEEE 802.3ae clause 45 addressing mode used by 10GIGE phy chips. */
  179. #define MII_ADDR_C45 (1<<30)
  180. #define MII_DEVADDR_C45_SHIFT 16
  181. #define MII_REGADDR_C45_MASK GENMASK(15, 0)
  182. struct device;
  183. struct phylink;
  184. struct sk_buff;
  185. /*
  186. * The Bus class for PHYs. Devices which provide access to
  187. * PHYs should register using this structure
  188. */
  189. struct mii_bus {
  190. struct module *owner;
  191. const char *name;
  192. char id[MII_BUS_ID_SIZE];
  193. void *priv;
  194. int (*read)(struct mii_bus *bus, int addr, int regnum);
  195. int (*write)(struct mii_bus *bus, int addr, int regnum, u16 val);
  196. int (*reset)(struct mii_bus *bus);
  197. /*
  198. * A lock to ensure that only one thing can read/write
  199. * the MDIO bus at a time
  200. */
  201. struct mutex mdio_lock;
  202. struct device *parent;
  203. enum {
  204. MDIOBUS_ALLOCATED = 1,
  205. MDIOBUS_REGISTERED,
  206. MDIOBUS_UNREGISTERED,
  207. MDIOBUS_RELEASED,
  208. } state;
  209. struct device dev;
  210. /* list of all PHYs on bus */
  211. struct mdio_device *mdio_map[PHY_MAX_ADDR];
  212. /* PHY addresses to be ignored when probing */
  213. u32 phy_mask;
  214. /* PHY addresses to ignore the TA/read failure */
  215. u32 phy_ignore_ta_mask;
  216. /*
  217. * An array of interrupts, each PHY's interrupt at the index
  218. * matching its address
  219. */
  220. int irq[PHY_MAX_ADDR];
  221. /* GPIO reset pulse width in microseconds */
  222. int reset_delay_us;
  223. /* RESET GPIO descriptor pointer */
  224. struct gpio_desc *reset_gpiod;
  225. };
  226. #define to_mii_bus(d) container_of(d, struct mii_bus, dev)
  227. struct mii_bus *mdiobus_alloc_size(size_t);
  228. static inline struct mii_bus *mdiobus_alloc(void)
  229. {
  230. return mdiobus_alloc_size(0);
  231. }
  232. int __mdiobus_register(struct mii_bus *bus, struct module *owner);
  233. #define mdiobus_register(bus) __mdiobus_register(bus, THIS_MODULE)
  234. void mdiobus_unregister(struct mii_bus *bus);
  235. void mdiobus_free(struct mii_bus *bus);
  236. struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv);
  237. static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
  238. {
  239. return devm_mdiobus_alloc_size(dev, 0);
  240. }
  241. void devm_mdiobus_free(struct device *dev, struct mii_bus *bus);
  242. struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
  243. #define PHY_INTERRUPT_DISABLED false
  244. #define PHY_INTERRUPT_ENABLED true
  245. /* PHY state machine states:
  246. *
  247. * DOWN: PHY device and driver are not ready for anything. probe
  248. * should be called if and only if the PHY is in this state,
  249. * given that the PHY device exists.
  250. * - PHY driver probe function will set the state to READY
  251. *
  252. * READY: PHY is ready to send and receive packets, but the
  253. * controller is not. By default, PHYs which do not implement
  254. * probe will be set to this state by phy_probe().
  255. * - start will set the state to UP
  256. *
  257. * UP: The PHY and attached device are ready to do work.
  258. * Interrupts should be started here.
  259. * - timer moves to NOLINK or RUNNING
  260. *
  261. * NOLINK: PHY is up, but not currently plugged in.
  262. * - irq or timer will set RUNNING if link comes back
  263. * - phy_stop moves to HALTED
  264. *
  265. * RUNNING: PHY is currently up, running, and possibly sending
  266. * and/or receiving packets
  267. * - irq or timer will set NOLINK if link goes down
  268. * - phy_stop moves to HALTED
  269. *
  270. * HALTED: PHY is up, but no polling or interrupts are done. Or
  271. * PHY is in an error state.
  272. * - phy_start moves to UP
  273. */
  274. enum phy_state {
  275. PHY_DOWN = 0,
  276. PHY_READY,
  277. PHY_HALTED,
  278. PHY_UP,
  279. PHY_RUNNING,
  280. PHY_NOLINK,
  281. };
  282. /**
  283. * struct phy_c45_device_ids - 802.3-c45 Device Identifiers
  284. * @devices_in_package: Bit vector of devices present.
  285. * @device_ids: The device identifer for each present device.
  286. */
  287. struct phy_c45_device_ids {
  288. u32 devices_in_package;
  289. u32 device_ids[8];
  290. };
  291. /* phy_device: An instance of a PHY
  292. *
  293. * drv: Pointer to the driver for this PHY instance
  294. * phy_id: UID for this device found during discovery
  295. * c45_ids: 802.3-c45 Device Identifers if is_c45.
  296. * is_c45: Set to true if this phy uses clause 45 addressing.
  297. * is_internal: Set to true if this phy is internal to a MAC.
  298. * is_pseudo_fixed_link: Set to true if this phy is an Ethernet switch, etc.
  299. * is_gigabit_capable: Set to true if PHY supports 1000Mbps
  300. * has_fixups: Set to true if this phy has fixups/quirks.
  301. * suspended: Set to true if this phy has been suspended successfully.
  302. * suspended_by_mdio_bus: Set to true if this phy was suspended by MDIO bus.
  303. * sysfs_links: Internal boolean tracking sysfs symbolic links setup/removal.
  304. * loopback_enabled: Set true if this phy has been loopbacked successfully.
  305. * state: state of the PHY for management purposes
  306. * dev_flags: Device-specific flags used by the PHY driver.
  307. * irq: IRQ number of the PHY's interrupt (-1 if none)
  308. * phy_timer: The timer for handling the state machine
  309. * attached_dev: The attached enet driver's device instance ptr
  310. * adjust_link: Callback for the enet controller to respond to
  311. * changes in the link state.
  312. *
  313. * speed, duplex, pause, supported, advertising, lp_advertising,
  314. * and autoneg are used like in mii_if_info
  315. *
  316. * interrupts currently only supports enabled or disabled,
  317. * but could be changed in the future to support enabling
  318. * and disabling specific interrupts
  319. *
  320. * Contains some infrastructure for polling and interrupt
  321. * handling, as well as handling shifts in PHY hardware state
  322. */
  323. struct phy_device {
  324. struct mdio_device mdio;
  325. /* Information about the PHY type */
  326. /* And management functions */
  327. struct phy_driver *drv;
  328. u32 phy_id;
  329. struct phy_c45_device_ids c45_ids;
  330. unsigned is_c45:1;
  331. unsigned is_internal:1;
  332. unsigned is_pseudo_fixed_link:1;
  333. unsigned is_gigabit_capable:1;
  334. unsigned has_fixups:1;
  335. unsigned suspended:1;
  336. unsigned suspended_by_mdio_bus:1;
  337. unsigned sysfs_links:1;
  338. unsigned loopback_enabled:1;
  339. unsigned autoneg:1;
  340. /* The most recently read link state */
  341. unsigned link:1;
  342. unsigned autoneg_complete:1;
  343. /* Interrupts are enabled */
  344. unsigned interrupts:1;
  345. enum phy_state state;
  346. u32 dev_flags;
  347. phy_interface_t interface;
  348. /*
  349. * forced speed & duplex (no autoneg)
  350. * partner speed & duplex & pause (autoneg)
  351. */
  352. int speed;
  353. int duplex;
  354. int pause;
  355. int asym_pause;
  356. /* Union of PHY and Attached devices' supported link modes */
  357. /* See ethtool.h for more info */
  358. __ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
  359. __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
  360. __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
  361. /* used with phy_speed_down */
  362. __ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old);
  363. /* Energy efficient ethernet modes which should be prohibited */
  364. u32 eee_broken_modes;
  365. #ifdef CONFIG_LED_TRIGGER_PHY
  366. struct phy_led_trigger *phy_led_triggers;
  367. unsigned int phy_num_led_triggers;
  368. struct phy_led_trigger *last_triggered;
  369. struct phy_led_trigger *led_link_trigger;
  370. #endif
  371. /*
  372. * Interrupt number for this PHY
  373. * -1 means no interrupt
  374. */
  375. int irq;
  376. /* private data pointer */
  377. /* For use by PHYs to maintain extra state */
  378. void *priv;
  379. /* Interrupt and Polling infrastructure */
  380. struct delayed_work state_queue;
  381. struct mutex lock;
  382. struct phylink *phylink;
  383. struct net_device *attached_dev;
  384. u8 mdix;
  385. u8 mdix_ctrl;
  386. void (*phy_link_change)(struct phy_device *, bool up, bool do_carrier);
  387. void (*adjust_link)(struct net_device *dev);
  388. };
  389. #define to_phy_device(d) container_of(to_mdio_device(d), \
  390. struct phy_device, mdio)
  391. /* struct phy_driver: Driver structure for a particular PHY type
  392. *
  393. * driver_data: static driver data
  394. * phy_id: The result of reading the UID registers of this PHY
  395. * type, and ANDing them with the phy_id_mask. This driver
  396. * only works for PHYs with IDs which match this field
  397. * name: The friendly name of this PHY type
  398. * phy_id_mask: Defines the important bits of the phy_id
  399. * features: A mandatory list of features (speed, duplex, etc)
  400. * supported by this PHY
  401. * flags: A bitfield defining certain other features this PHY
  402. * supports (like interrupts)
  403. *
  404. * All functions are optional. If config_aneg or read_status
  405. * are not implemented, the phy core uses the genphy versions.
  406. * Note that none of these functions should be called from
  407. * interrupt time. The goal is for the bus read/write functions
  408. * to be able to block when the bus transaction is happening,
  409. * and be freed up by an interrupt (The MPC85xx has this ability,
  410. * though it is not currently supported in the driver).
  411. */
  412. struct phy_driver {
  413. struct mdio_driver_common mdiodrv;
  414. u32 phy_id;
  415. char *name;
  416. u32 phy_id_mask;
  417. const unsigned long * const features;
  418. u32 flags;
  419. const void *driver_data;
  420. /*
  421. * Called to issue a PHY software reset
  422. */
  423. int (*soft_reset)(struct phy_device *phydev);
  424. /*
  425. * Called to initialize the PHY,
  426. * including after a reset
  427. */
  428. int (*config_init)(struct phy_device *phydev);
  429. /*
  430. * Called during discovery. Used to set
  431. * up device-specific structures, if any
  432. */
  433. int (*probe)(struct phy_device *phydev);
  434. /*
  435. * Probe the hardware to determine what abilities it has.
  436. * Should only set phydev->supported.
  437. */
  438. int (*get_features)(struct phy_device *phydev);
  439. /* PHY Power Management */
  440. int (*suspend)(struct phy_device *phydev);
  441. int (*resume)(struct phy_device *phydev);
  442. /*
  443. * Configures the advertisement and resets
  444. * autonegotiation if phydev->autoneg is on,
  445. * forces the speed to the current settings in phydev
  446. * if phydev->autoneg is off
  447. */
  448. int (*config_aneg)(struct phy_device *phydev);
  449. /* Determines the auto negotiation result */
  450. int (*aneg_done)(struct phy_device *phydev);
  451. /* Determines the negotiated speed and duplex */
  452. int (*read_status)(struct phy_device *phydev);
  453. /* Clears any pending interrupts */
  454. int (*ack_interrupt)(struct phy_device *phydev);
  455. /* Enables or disables interrupts */
  456. int (*config_intr)(struct phy_device *phydev);
  457. /*
  458. * Checks if the PHY generated an interrupt.
  459. * For multi-PHY devices with shared PHY interrupt pin
  460. * Set interrupt bits have to be cleared.
  461. */
  462. int (*did_interrupt)(struct phy_device *phydev);
  463. /* Override default interrupt handling */
  464. int (*handle_interrupt)(struct phy_device *phydev);
  465. /* Clears up any memory if needed */
  466. void (*remove)(struct phy_device *phydev);
  467. /* Returns true if this is a suitable driver for the given
  468. * phydev. If NULL, matching is based on phy_id and
  469. * phy_id_mask.
  470. */
  471. int (*match_phy_device)(struct phy_device *phydev);
  472. /* Handles ethtool queries for hardware time stamping. */
  473. int (*ts_info)(struct phy_device *phydev, struct ethtool_ts_info *ti);
  474. /* Handles SIOCSHWTSTAMP ioctl for hardware time stamping. */
  475. int (*hwtstamp)(struct phy_device *phydev, struct ifreq *ifr);
  476. /*
  477. * Requests a Rx timestamp for 'skb'. If the skb is accepted,
  478. * the phy driver promises to deliver it using netif_rx() as
  479. * soon as a timestamp becomes available. One of the
  480. * PTP_CLASS_ values is passed in 'type'. The function must
  481. * return true if the skb is accepted for delivery.
  482. */
  483. bool (*rxtstamp)(struct phy_device *dev, struct sk_buff *skb, int type);
  484. /*
  485. * Requests a Tx timestamp for 'skb'. The phy driver promises
  486. * to deliver it using skb_complete_tx_timestamp() as soon as a
  487. * timestamp becomes available. One of the PTP_CLASS_ values
  488. * is passed in 'type'.
  489. */
  490. void (*txtstamp)(struct phy_device *dev, struct sk_buff *skb, int type);
  491. /* Some devices (e.g. qnap TS-119P II) require PHY register changes to
  492. * enable Wake on LAN, so set_wol is provided to be called in the
  493. * ethernet driver's set_wol function. */
  494. int (*set_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
  495. /* See set_wol, but for checking whether Wake on LAN is enabled. */
  496. void (*get_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
  497. /*
  498. * Called to inform a PHY device driver when the core is about to
  499. * change the link state. This callback is supposed to be used as
  500. * fixup hook for drivers that need to take action when the link
  501. * state changes. Drivers are by no means allowed to mess with the
  502. * PHY device structure in their implementations.
  503. */
  504. void (*link_change_notify)(struct phy_device *dev);
  505. /*
  506. * Phy specific driver override for reading a MMD register.
  507. * This function is optional for PHY specific drivers. When
  508. * not provided, the default MMD read function will be used
  509. * by phy_read_mmd(), which will use either a direct read for
  510. * Clause 45 PHYs or an indirect read for Clause 22 PHYs.
  511. * devnum is the MMD device number within the PHY device,
  512. * regnum is the register within the selected MMD device.
  513. */
  514. int (*read_mmd)(struct phy_device *dev, int devnum, u16 regnum);
  515. /*
  516. * Phy specific driver override for writing a MMD register.
  517. * This function is optional for PHY specific drivers. When
  518. * not provided, the default MMD write function will be used
  519. * by phy_write_mmd(), which will use either a direct write for
  520. * Clause 45 PHYs, or an indirect write for Clause 22 PHYs.
  521. * devnum is the MMD device number within the PHY device,
  522. * regnum is the register within the selected MMD device.
  523. * val is the value to be written.
  524. */
  525. int (*write_mmd)(struct phy_device *dev, int devnum, u16 regnum,
  526. u16 val);
  527. int (*read_page)(struct phy_device *dev);
  528. int (*write_page)(struct phy_device *dev, int page);
  529. /* Get the size and type of the eeprom contained within a plug-in
  530. * module */
  531. int (*module_info)(struct phy_device *dev,
  532. struct ethtool_modinfo *modinfo);
  533. /* Get the eeprom information from the plug-in module */
  534. int (*module_eeprom)(struct phy_device *dev,
  535. struct ethtool_eeprom *ee, u8 *data);
  536. /* Get statistics from the phy using ethtool */
  537. int (*get_sset_count)(struct phy_device *dev);
  538. void (*get_strings)(struct phy_device *dev, u8 *data);
  539. void (*get_stats)(struct phy_device *dev,
  540. struct ethtool_stats *stats, u64 *data);
  541. /* Get and Set PHY tunables */
  542. int (*get_tunable)(struct phy_device *dev,
  543. struct ethtool_tunable *tuna, void *data);
  544. int (*set_tunable)(struct phy_device *dev,
  545. struct ethtool_tunable *tuna,
  546. const void *data);
  547. int (*set_loopback)(struct phy_device *dev, bool enable);
  548. };
  549. #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
  550. struct phy_driver, mdiodrv)
  551. #define PHY_ANY_ID "MATCH ANY PHY"
  552. #define PHY_ANY_UID 0xffffffff
  553. #define PHY_ID_MATCH_EXACT(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 0)
  554. #define PHY_ID_MATCH_MODEL(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 4)
  555. #define PHY_ID_MATCH_VENDOR(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 10)
  556. /* A Structure for boards to register fixups with the PHY Lib */
  557. struct phy_fixup {
  558. struct list_head list;
  559. char bus_id[MII_BUS_ID_SIZE + 3];
  560. u32 phy_uid;
  561. u32 phy_uid_mask;
  562. int (*run)(struct phy_device *phydev);
  563. };
  564. const char *phy_speed_to_str(int speed);
  565. const char *phy_duplex_to_str(unsigned int duplex);
  566. /* A structure for mapping a particular speed and duplex
  567. * combination to a particular SUPPORTED and ADVERTISED value
  568. */
  569. struct phy_setting {
  570. u32 speed;
  571. u8 duplex;
  572. u8 bit;
  573. };
  574. const struct phy_setting *
  575. phy_lookup_setting(int speed, int duplex, const unsigned long *mask,
  576. bool exact);
  577. size_t phy_speeds(unsigned int *speeds, size_t size,
  578. unsigned long *mask);
  579. void of_set_phy_supported(struct phy_device *phydev);
  580. void of_set_phy_eee_broken(struct phy_device *phydev);
  581. int phy_speed_down_core(struct phy_device *phydev);
  582. /**
  583. * phy_is_started - Convenience function to check whether PHY is started
  584. * @phydev: The phy_device struct
  585. */
  586. static inline bool phy_is_started(struct phy_device *phydev)
  587. {
  588. return phydev->state >= PHY_UP;
  589. }
  590. void phy_resolve_aneg_pause(struct phy_device *phydev);
  591. void phy_resolve_aneg_linkmode(struct phy_device *phydev);
  592. /**
  593. * phy_read - Convenience function for reading a given PHY register
  594. * @phydev: the phy_device struct
  595. * @regnum: register number to read
  596. *
  597. * NOTE: MUST NOT be called from interrupt context,
  598. * because the bus read/write functions may wait for an interrupt
  599. * to conclude the operation.
  600. */
  601. static inline int phy_read(struct phy_device *phydev, u32 regnum)
  602. {
  603. return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
  604. }
  605. /**
  606. * __phy_read - convenience function for reading a given PHY register
  607. * @phydev: the phy_device struct
  608. * @regnum: register number to read
  609. *
  610. * The caller must have taken the MDIO bus lock.
  611. */
  612. static inline int __phy_read(struct phy_device *phydev, u32 regnum)
  613. {
  614. return __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
  615. }
  616. /**
  617. * phy_write - Convenience function for writing a given PHY register
  618. * @phydev: the phy_device struct
  619. * @regnum: register number to write
  620. * @val: value to write to @regnum
  621. *
  622. * NOTE: MUST NOT be called from interrupt context,
  623. * because the bus read/write functions may wait for an interrupt
  624. * to conclude the operation.
  625. */
  626. static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
  627. {
  628. return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);
  629. }
  630. /**
  631. * __phy_write - Convenience function for writing a given PHY register
  632. * @phydev: the phy_device struct
  633. * @regnum: register number to write
  634. * @val: value to write to @regnum
  635. *
  636. * The caller must have taken the MDIO bus lock.
  637. */
  638. static inline int __phy_write(struct phy_device *phydev, u32 regnum, u16 val)
  639. {
  640. return __mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum,
  641. val);
  642. }
  643. /**
  644. * phy_read_mmd - Convenience function for reading a register
  645. * from an MMD on a given PHY.
  646. * @phydev: The phy_device struct
  647. * @devad: The MMD to read from
  648. * @regnum: The register on the MMD to read
  649. *
  650. * Same rules as for phy_read();
  651. */
  652. int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
  653. /**
  654. * __phy_read_mmd - Convenience function for reading a register
  655. * from an MMD on a given PHY.
  656. * @phydev: The phy_device struct
  657. * @devad: The MMD to read from
  658. * @regnum: The register on the MMD to read
  659. *
  660. * Same rules as for __phy_read();
  661. */
  662. int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
  663. /**
  664. * phy_write_mmd - Convenience function for writing a register
  665. * on an MMD on a given PHY.
  666. * @phydev: The phy_device struct
  667. * @devad: The MMD to write to
  668. * @regnum: The register on the MMD to read
  669. * @val: value to write to @regnum
  670. *
  671. * Same rules as for phy_write();
  672. */
  673. int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
  674. /**
  675. * __phy_write_mmd - Convenience function for writing a register
  676. * on an MMD on a given PHY.
  677. * @phydev: The phy_device struct
  678. * @devad: The MMD to write to
  679. * @regnum: The register on the MMD to read
  680. * @val: value to write to @regnum
  681. *
  682. * Same rules as for __phy_write();
  683. */
  684. int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val);
  685. int __phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask,
  686. u16 set);
  687. int phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask,
  688. u16 set);
  689. int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
  690. int phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set);
  691. int __phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
  692. u16 mask, u16 set);
  693. int phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
  694. u16 mask, u16 set);
  695. int __phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
  696. u16 mask, u16 set);
  697. int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
  698. u16 mask, u16 set);
  699. /**
  700. * __phy_set_bits - Convenience function for setting bits in a PHY register
  701. * @phydev: the phy_device struct
  702. * @regnum: register number to write
  703. * @val: bits to set
  704. *
  705. * The caller must have taken the MDIO bus lock.
  706. */
  707. static inline int __phy_set_bits(struct phy_device *phydev, u32 regnum, u16 val)
  708. {
  709. return __phy_modify(phydev, regnum, 0, val);
  710. }
  711. /**
  712. * __phy_clear_bits - Convenience function for clearing bits in a PHY register
  713. * @phydev: the phy_device struct
  714. * @regnum: register number to write
  715. * @val: bits to clear
  716. *
  717. * The caller must have taken the MDIO bus lock.
  718. */
  719. static inline int __phy_clear_bits(struct phy_device *phydev, u32 regnum,
  720. u16 val)
  721. {
  722. return __phy_modify(phydev, regnum, val, 0);
  723. }
  724. /**
  725. * phy_set_bits - Convenience function for setting bits in a PHY register
  726. * @phydev: the phy_device struct
  727. * @regnum: register number to write
  728. * @val: bits to set
  729. */
  730. static inline int phy_set_bits(struct phy_device *phydev, u32 regnum, u16 val)
  731. {
  732. return phy_modify(phydev, regnum, 0, val);
  733. }
  734. /**
  735. * phy_clear_bits - Convenience function for clearing bits in a PHY register
  736. * @phydev: the phy_device struct
  737. * @regnum: register number to write
  738. * @val: bits to clear
  739. */
  740. static inline int phy_clear_bits(struct phy_device *phydev, u32 regnum, u16 val)
  741. {
  742. return phy_modify(phydev, regnum, val, 0);
  743. }
  744. /**
  745. * __phy_set_bits_mmd - Convenience function for setting bits in a register
  746. * on MMD
  747. * @phydev: the phy_device struct
  748. * @devad: the MMD containing register to modify
  749. * @regnum: register number to modify
  750. * @val: bits to set
  751. *
  752. * The caller must have taken the MDIO bus lock.
  753. */
  754. static inline int __phy_set_bits_mmd(struct phy_device *phydev, int devad,
  755. u32 regnum, u16 val)
  756. {
  757. return __phy_modify_mmd(phydev, devad, regnum, 0, val);
  758. }
  759. /**
  760. * __phy_clear_bits_mmd - Convenience function for clearing bits in a register
  761. * on MMD
  762. * @phydev: the phy_device struct
  763. * @devad: the MMD containing register to modify
  764. * @regnum: register number to modify
  765. * @val: bits to clear
  766. *
  767. * The caller must have taken the MDIO bus lock.
  768. */
  769. static inline int __phy_clear_bits_mmd(struct phy_device *phydev, int devad,
  770. u32 regnum, u16 val)
  771. {
  772. return __phy_modify_mmd(phydev, devad, regnum, val, 0);
  773. }
  774. /**
  775. * phy_set_bits_mmd - Convenience function for setting bits in a register
  776. * on MMD
  777. * @phydev: the phy_device struct
  778. * @devad: the MMD containing register to modify
  779. * @regnum: register number to modify
  780. * @val: bits to set
  781. */
  782. static inline int phy_set_bits_mmd(struct phy_device *phydev, int devad,
  783. u32 regnum, u16 val)
  784. {
  785. return phy_modify_mmd(phydev, devad, regnum, 0, val);
  786. }
  787. /**
  788. * phy_clear_bits_mmd - Convenience function for clearing bits in a register
  789. * on MMD
  790. * @phydev: the phy_device struct
  791. * @devad: the MMD containing register to modify
  792. * @regnum: register number to modify
  793. * @val: bits to clear
  794. */
  795. static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad,
  796. u32 regnum, u16 val)
  797. {
  798. return phy_modify_mmd(phydev, devad, regnum, val, 0);
  799. }
  800. /**
  801. * phy_interrupt_is_valid - Convenience function for testing a given PHY irq
  802. * @phydev: the phy_device struct
  803. *
  804. * NOTE: must be kept in sync with addition/removal of PHY_POLL and
  805. * PHY_IGNORE_INTERRUPT
  806. */
  807. static inline bool phy_interrupt_is_valid(struct phy_device *phydev)
  808. {
  809. return phydev->irq != PHY_POLL && phydev->irq != PHY_IGNORE_INTERRUPT;
  810. }
  811. /**
  812. * phy_polling_mode - Convenience function for testing whether polling is
  813. * used to detect PHY status changes
  814. * @phydev: the phy_device struct
  815. */
  816. static inline bool phy_polling_mode(struct phy_device *phydev)
  817. {
  818. return phydev->irq == PHY_POLL;
  819. }
  820. /**
  821. * phy_is_internal - Convenience function for testing if a PHY is internal
  822. * @phydev: the phy_device struct
  823. */
  824. static inline bool phy_is_internal(struct phy_device *phydev)
  825. {
  826. return phydev->is_internal;
  827. }
  828. /**
  829. * phy_interface_mode_is_rgmii - Convenience function for testing if a
  830. * PHY interface mode is RGMII (all variants)
  831. * @mode: the phy_interface_t enum
  832. */
  833. static inline bool phy_interface_mode_is_rgmii(phy_interface_t mode)
  834. {
  835. return mode >= PHY_INTERFACE_MODE_RGMII &&
  836. mode <= PHY_INTERFACE_MODE_RGMII_TXID;
  837. };
  838. /**
  839. * phy_interface_mode_is_8023z() - does the phy interface mode use 802.3z
  840. * negotiation
  841. * @mode: one of &enum phy_interface_t
  842. *
  843. * Returns true if the phy interface mode uses the 16-bit negotiation
  844. * word as defined in 802.3z. (See 802.3-2015 37.2.1 Config_Reg encoding)
  845. */
  846. static inline bool phy_interface_mode_is_8023z(phy_interface_t mode)
  847. {
  848. return mode == PHY_INTERFACE_MODE_1000BASEX ||
  849. mode == PHY_INTERFACE_MODE_2500BASEX;
  850. }
  851. /**
  852. * phy_interface_is_rgmii - Convenience function for testing if a PHY interface
  853. * is RGMII (all variants)
  854. * @phydev: the phy_device struct
  855. */
  856. static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
  857. {
  858. return phy_interface_mode_is_rgmii(phydev->interface);
  859. };
  860. /*
  861. * phy_is_pseudo_fixed_link - Convenience function for testing if this
  862. * PHY is the CPU port facing side of an Ethernet switch, or similar.
  863. * @phydev: the phy_device struct
  864. */
  865. static inline bool phy_is_pseudo_fixed_link(struct phy_device *phydev)
  866. {
  867. return phydev->is_pseudo_fixed_link;
  868. }
  869. int phy_save_page(struct phy_device *phydev);
  870. int phy_select_page(struct phy_device *phydev, int page);
  871. int phy_restore_page(struct phy_device *phydev, int oldpage, int ret);
  872. int phy_read_paged(struct phy_device *phydev, int page, u32 regnum);
  873. int phy_write_paged(struct phy_device *phydev, int page, u32 regnum, u16 val);
  874. int phy_modify_paged_changed(struct phy_device *phydev, int page, u32 regnum,
  875. u16 mask, u16 set);
  876. int phy_modify_paged(struct phy_device *phydev, int page, u32 regnum,
  877. u16 mask, u16 set);
  878. struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
  879. bool is_c45,
  880. struct phy_c45_device_ids *c45_ids);
  881. #if IS_ENABLED(CONFIG_PHYLIB)
  882. struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
  883. int phy_device_register(struct phy_device *phy);
  884. void phy_device_free(struct phy_device *phydev);
  885. #else
  886. static inline
  887. struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
  888. {
  889. return NULL;
  890. }
  891. static inline int phy_device_register(struct phy_device *phy)
  892. {
  893. return 0;
  894. }
  895. static inline void phy_device_free(struct phy_device *phydev) { }
  896. #endif /* CONFIG_PHYLIB */
  897. void phy_device_remove(struct phy_device *phydev);
  898. int phy_init_hw(struct phy_device *phydev);
  899. int phy_suspend(struct phy_device *phydev);
  900. int phy_resume(struct phy_device *phydev);
  901. int __phy_resume(struct phy_device *phydev);
  902. int phy_loopback(struct phy_device *phydev, bool enable);
  903. struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
  904. phy_interface_t interface);
  905. struct phy_device *phy_find_first(struct mii_bus *bus);
  906. int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
  907. u32 flags, phy_interface_t interface);
  908. int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
  909. void (*handler)(struct net_device *),
  910. phy_interface_t interface);
  911. struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
  912. void (*handler)(struct net_device *),
  913. phy_interface_t interface);
  914. void phy_disconnect(struct phy_device *phydev);
  915. void phy_detach(struct phy_device *phydev);
  916. void phy_start(struct phy_device *phydev);
  917. void phy_stop(struct phy_device *phydev);
  918. int phy_start_aneg(struct phy_device *phydev);
  919. int phy_aneg_done(struct phy_device *phydev);
  920. int phy_speed_down(struct phy_device *phydev, bool sync);
  921. int phy_speed_up(struct phy_device *phydev);
  922. int phy_restart_aneg(struct phy_device *phydev);
  923. int phy_reset_after_clk_enable(struct phy_device *phydev);
  924. static inline void phy_device_reset(struct phy_device *phydev, int value)
  925. {
  926. mdio_device_reset(&phydev->mdio, value);
  927. }
  928. #define phydev_err(_phydev, format, args...) \
  929. dev_err(&_phydev->mdio.dev, format, ##args)
  930. #define phydev_info(_phydev, format, args...) \
  931. dev_info(&_phydev->mdio.dev, format, ##args)
  932. #define phydev_warn(_phydev, format, args...) \
  933. dev_warn(&_phydev->mdio.dev, format, ##args)
  934. #define phydev_dbg(_phydev, format, args...) \
  935. dev_dbg(&_phydev->mdio.dev, format, ##args)
  936. static inline const char *phydev_name(const struct phy_device *phydev)
  937. {
  938. return dev_name(&phydev->mdio.dev);
  939. }
  940. void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)
  941. __printf(2, 3);
  942. void phy_attached_info(struct phy_device *phydev);
  943. /* Clause 22 PHY */
  944. int genphy_read_abilities(struct phy_device *phydev);
  945. int genphy_setup_forced(struct phy_device *phydev);
  946. int genphy_restart_aneg(struct phy_device *phydev);
  947. int genphy_config_eee_advert(struct phy_device *phydev);
  948. int __genphy_config_aneg(struct phy_device *phydev, bool changed);
  949. int genphy_aneg_done(struct phy_device *phydev);
  950. int genphy_update_link(struct phy_device *phydev);
  951. int genphy_read_lpa(struct phy_device *phydev);
  952. int genphy_read_status(struct phy_device *phydev);
  953. int genphy_suspend(struct phy_device *phydev);
  954. int genphy_resume(struct phy_device *phydev);
  955. int genphy_loopback(struct phy_device *phydev, bool enable);
  956. int genphy_soft_reset(struct phy_device *phydev);
  957. static inline int genphy_config_aneg(struct phy_device *phydev)
  958. {
  959. return __genphy_config_aneg(phydev, false);
  960. }
  961. static inline int genphy_no_soft_reset(struct phy_device *phydev)
  962. {
  963. return 0;
  964. }
  965. static inline int genphy_no_ack_interrupt(struct phy_device *phydev)
  966. {
  967. return 0;
  968. }
  969. static inline int genphy_no_config_intr(struct phy_device *phydev)
  970. {
  971. return 0;
  972. }
  973. int genphy_read_mmd_unsupported(struct phy_device *phdev, int devad,
  974. u16 regnum);
  975. int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum,
  976. u16 regnum, u16 val);
  977. /* Clause 45 PHY */
  978. int genphy_c45_restart_aneg(struct phy_device *phydev);
  979. int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart);
  980. int genphy_c45_aneg_done(struct phy_device *phydev);
  981. int genphy_c45_read_link(struct phy_device *phydev);
  982. int genphy_c45_read_lpa(struct phy_device *phydev);
  983. int genphy_c45_read_pma(struct phy_device *phydev);
  984. int genphy_c45_pma_setup_forced(struct phy_device *phydev);
  985. int genphy_c45_an_config_aneg(struct phy_device *phydev);
  986. int genphy_c45_an_disable_aneg(struct phy_device *phydev);
  987. int genphy_c45_read_mdix(struct phy_device *phydev);
  988. int genphy_c45_pma_read_abilities(struct phy_device *phydev);
  989. int genphy_c45_read_status(struct phy_device *phydev);
  990. int genphy_c45_config_aneg(struct phy_device *phydev);
  991. /* The gen10g_* functions are the old Clause 45 stub */
  992. int gen10g_config_aneg(struct phy_device *phydev);
  993. static inline int phy_read_status(struct phy_device *phydev)
  994. {
  995. if (!phydev->drv)
  996. return -EIO;
  997. if (phydev->drv->read_status)
  998. return phydev->drv->read_status(phydev);
  999. else
  1000. return genphy_read_status(phydev);
  1001. }
  1002. void phy_driver_unregister(struct phy_driver *drv);
  1003. void phy_drivers_unregister(struct phy_driver *drv, int n);
  1004. int phy_driver_register(struct phy_driver *new_driver, struct module *owner);
  1005. int phy_drivers_register(struct phy_driver *new_driver, int n,
  1006. struct module *owner);
  1007. void phy_state_machine(struct work_struct *work);
  1008. void phy_queue_state_machine(struct phy_device *phydev, unsigned long jiffies);
  1009. void phy_mac_interrupt(struct phy_device *phydev);
  1010. void phy_start_machine(struct phy_device *phydev);
  1011. void phy_stop_machine(struct phy_device *phydev);
  1012. int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
  1013. void phy_ethtool_ksettings_get(struct phy_device *phydev,
  1014. struct ethtool_link_ksettings *cmd);
  1015. int phy_ethtool_ksettings_set(struct phy_device *phydev,
  1016. const struct ethtool_link_ksettings *cmd);
  1017. int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
  1018. void phy_request_interrupt(struct phy_device *phydev);
  1019. void phy_free_interrupt(struct phy_device *phydev);
  1020. void phy_print_status(struct phy_device *phydev);
  1021. int phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
  1022. void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode);
  1023. void phy_advertise_supported(struct phy_device *phydev);
  1024. void phy_support_sym_pause(struct phy_device *phydev);
  1025. void phy_support_asym_pause(struct phy_device *phydev);
  1026. void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx,
  1027. bool autoneg);
  1028. void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx);
  1029. bool phy_validate_pause(struct phy_device *phydev,
  1030. struct ethtool_pauseparam *pp);
  1031. int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
  1032. int (*run)(struct phy_device *));
  1033. int phy_register_fixup_for_id(const char *bus_id,
  1034. int (*run)(struct phy_device *));
  1035. int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
  1036. int (*run)(struct phy_device *));
  1037. int phy_unregister_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask);
  1038. int phy_unregister_fixup_for_id(const char *bus_id);
  1039. int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask);
  1040. int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
  1041. int phy_get_eee_err(struct phy_device *phydev);
  1042. int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data);
  1043. int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
  1044. int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
  1045. void phy_ethtool_get_wol(struct phy_device *phydev,
  1046. struct ethtool_wolinfo *wol);
  1047. int phy_ethtool_get_link_ksettings(struct net_device *ndev,
  1048. struct ethtool_link_ksettings *cmd);
  1049. int phy_ethtool_set_link_ksettings(struct net_device *ndev,
  1050. const struct ethtool_link_ksettings *cmd);
  1051. int phy_ethtool_nway_reset(struct net_device *ndev);
  1052. #if IS_ENABLED(CONFIG_PHYLIB)
  1053. int __init mdio_bus_init(void);
  1054. void mdio_bus_exit(void);
  1055. #endif
  1056. /* Inline function for use within net/core/ethtool.c (built-in) */
  1057. static inline int phy_ethtool_get_strings(struct phy_device *phydev, u8 *data)
  1058. {
  1059. if (!phydev->drv)
  1060. return -EIO;
  1061. mutex_lock(&phydev->lock);
  1062. phydev->drv->get_strings(phydev, data);
  1063. mutex_unlock(&phydev->lock);
  1064. return 0;
  1065. }
  1066. static inline int phy_ethtool_get_sset_count(struct phy_device *phydev)
  1067. {
  1068. int ret;
  1069. if (!phydev->drv)
  1070. return -EIO;
  1071. if (phydev->drv->get_sset_count &&
  1072. phydev->drv->get_strings &&
  1073. phydev->drv->get_stats) {
  1074. mutex_lock(&phydev->lock);
  1075. ret = phydev->drv->get_sset_count(phydev);
  1076. mutex_unlock(&phydev->lock);
  1077. return ret;
  1078. }
  1079. return -EOPNOTSUPP;
  1080. }
  1081. static inline int phy_ethtool_get_stats(struct phy_device *phydev,
  1082. struct ethtool_stats *stats, u64 *data)
  1083. {
  1084. if (!phydev->drv)
  1085. return -EIO;
  1086. mutex_lock(&phydev->lock);
  1087. phydev->drv->get_stats(phydev, stats, data);
  1088. mutex_unlock(&phydev->lock);
  1089. return 0;
  1090. }
  1091. extern struct bus_type mdio_bus_type;
  1092. struct mdio_board_info {
  1093. const char *bus_id;
  1094. char modalias[MDIO_NAME_SIZE];
  1095. int mdio_addr;
  1096. const void *platform_data;
  1097. };
  1098. #if IS_ENABLED(CONFIG_MDIO_DEVICE)
  1099. int mdiobus_register_board_info(const struct mdio_board_info *info,
  1100. unsigned int n);
  1101. #else
  1102. static inline int mdiobus_register_board_info(const struct mdio_board_info *i,
  1103. unsigned int n)
  1104. {
  1105. return 0;
  1106. }
  1107. #endif
  1108. /**
  1109. * module_phy_driver() - Helper macro for registering PHY drivers
  1110. * @__phy_drivers: array of PHY drivers to register
  1111. *
  1112. * Helper macro for PHY drivers which do not do anything special in module
  1113. * init/exit. Each module may only use this macro once, and calling it
  1114. * replaces module_init() and module_exit().
  1115. */
  1116. #define phy_module_driver(__phy_drivers, __count) \
  1117. static int __init phy_module_init(void) \
  1118. { \
  1119. return phy_drivers_register(__phy_drivers, __count, THIS_MODULE); \
  1120. } \
  1121. module_init(phy_module_init); \
  1122. static void __exit phy_module_exit(void) \
  1123. { \
  1124. phy_drivers_unregister(__phy_drivers, __count); \
  1125. } \
  1126. module_exit(phy_module_exit)
  1127. #define module_phy_driver(__phy_drivers) \
  1128. phy_module_driver(__phy_drivers, ARRAY_SIZE(__phy_drivers))
  1129. bool phy_driver_is_genphy(struct phy_device *phydev);
  1130. bool phy_driver_is_genphy_10g(struct phy_device *phydev);
  1131. #endif /* __PHY_H */