phy.h 36 KB

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