phy.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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/spinlock.h>
  18. #include <linux/ethtool.h>
  19. #include <linux/mii.h>
  20. #include <linux/timer.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/mod_devicetable.h>
  23. #include <linux/atomic.h>
  24. #define PHY_DEFAULT_FEATURES (SUPPORTED_Autoneg | \
  25. SUPPORTED_TP | \
  26. SUPPORTED_MII)
  27. #define PHY_10BT_FEATURES (SUPPORTED_10baseT_Half | \
  28. SUPPORTED_10baseT_Full)
  29. #define PHY_100BT_FEATURES (SUPPORTED_100baseT_Half | \
  30. SUPPORTED_100baseT_Full)
  31. #define PHY_1000BT_FEATURES (SUPPORTED_1000baseT_Half | \
  32. SUPPORTED_1000baseT_Full)
  33. #define PHY_BASIC_FEATURES (PHY_10BT_FEATURES | \
  34. PHY_100BT_FEATURES | \
  35. PHY_DEFAULT_FEATURES)
  36. #define PHY_GBIT_FEATURES (PHY_BASIC_FEATURES | \
  37. PHY_1000BT_FEATURES)
  38. /*
  39. * Set phydev->irq to PHY_POLL if interrupts are not supported,
  40. * or not desired for this PHY. Set to PHY_IGNORE_INTERRUPT if
  41. * the attached driver handles the interrupt
  42. */
  43. #define PHY_POLL -1
  44. #define PHY_IGNORE_INTERRUPT -2
  45. #define PHY_HAS_INTERRUPT 0x00000001
  46. #define PHY_HAS_MAGICANEG 0x00000002
  47. #define PHY_IS_INTERNAL 0x00000004
  48. /* Interface Mode definitions */
  49. typedef enum {
  50. PHY_INTERFACE_MODE_NA,
  51. PHY_INTERFACE_MODE_MII,
  52. PHY_INTERFACE_MODE_GMII,
  53. PHY_INTERFACE_MODE_SGMII,
  54. PHY_INTERFACE_MODE_TBI,
  55. PHY_INTERFACE_MODE_REVMII,
  56. PHY_INTERFACE_MODE_RMII,
  57. PHY_INTERFACE_MODE_RGMII,
  58. PHY_INTERFACE_MODE_RGMII_ID,
  59. PHY_INTERFACE_MODE_RGMII_RXID,
  60. PHY_INTERFACE_MODE_RGMII_TXID,
  61. PHY_INTERFACE_MODE_RTBI,
  62. PHY_INTERFACE_MODE_SMII,
  63. PHY_INTERFACE_MODE_XGMII,
  64. PHY_INTERFACE_MODE_MAX,
  65. } phy_interface_t;
  66. /**
  67. * It maps 'enum phy_interface_t' found in include/linux/phy.h
  68. * into the device tree binding of 'phy-mode', so that Ethernet
  69. * device driver can get phy interface from device tree.
  70. */
  71. static inline const char *phy_modes(phy_interface_t interface)
  72. {
  73. switch (interface) {
  74. case PHY_INTERFACE_MODE_NA:
  75. return "";
  76. case PHY_INTERFACE_MODE_MII:
  77. return "mii";
  78. case PHY_INTERFACE_MODE_GMII:
  79. return "gmii";
  80. case PHY_INTERFACE_MODE_SGMII:
  81. return "sgmii";
  82. case PHY_INTERFACE_MODE_TBI:
  83. return "tbi";
  84. case PHY_INTERFACE_MODE_REVMII:
  85. return "rev-mii";
  86. case PHY_INTERFACE_MODE_RMII:
  87. return "rmii";
  88. case PHY_INTERFACE_MODE_RGMII:
  89. return "rgmii";
  90. case PHY_INTERFACE_MODE_RGMII_ID:
  91. return "rgmii-id";
  92. case PHY_INTERFACE_MODE_RGMII_RXID:
  93. return "rgmii-rxid";
  94. case PHY_INTERFACE_MODE_RGMII_TXID:
  95. return "rgmii-txid";
  96. case PHY_INTERFACE_MODE_RTBI:
  97. return "rtbi";
  98. case PHY_INTERFACE_MODE_SMII:
  99. return "smii";
  100. case PHY_INTERFACE_MODE_XGMII:
  101. return "xgmii";
  102. default:
  103. return "unknown";
  104. }
  105. }
  106. #define PHY_INIT_TIMEOUT 100000
  107. #define PHY_STATE_TIME 1
  108. #define PHY_FORCE_TIMEOUT 10
  109. #define PHY_AN_TIMEOUT 10
  110. #define PHY_MAX_ADDR 32
  111. /* Used when trying to connect to a specific phy (mii bus id:phy device id) */
  112. #define PHY_ID_FMT "%s:%02x"
  113. /*
  114. * Need to be a little smaller than phydev->dev.bus_id to leave room
  115. * for the ":%02x"
  116. */
  117. #define MII_BUS_ID_SIZE (20 - 3)
  118. /* Or MII_ADDR_C45 into regnum for read/write on mii_bus to enable the 21 bit
  119. IEEE 802.3ae clause 45 addressing mode used by 10GIGE phy chips. */
  120. #define MII_ADDR_C45 (1<<30)
  121. struct device;
  122. struct sk_buff;
  123. /*
  124. * The Bus class for PHYs. Devices which provide access to
  125. * PHYs should register using this structure
  126. */
  127. struct mii_bus {
  128. const char *name;
  129. char id[MII_BUS_ID_SIZE];
  130. void *priv;
  131. int (*read)(struct mii_bus *bus, int phy_id, int regnum);
  132. int (*write)(struct mii_bus *bus, int phy_id, int regnum, u16 val);
  133. int (*reset)(struct mii_bus *bus);
  134. /*
  135. * A lock to ensure that only one thing can read/write
  136. * the MDIO bus at a time
  137. */
  138. struct mutex mdio_lock;
  139. struct device *parent;
  140. enum {
  141. MDIOBUS_ALLOCATED = 1,
  142. MDIOBUS_REGISTERED,
  143. MDIOBUS_UNREGISTERED,
  144. MDIOBUS_RELEASED,
  145. } state;
  146. struct device dev;
  147. /* list of all PHYs on bus */
  148. struct phy_device *phy_map[PHY_MAX_ADDR];
  149. /* PHY addresses to be ignored when probing */
  150. u32 phy_mask;
  151. /*
  152. * Pointer to an array of interrupts, each PHY's
  153. * interrupt at the index matching its address
  154. */
  155. int *irq;
  156. };
  157. #define to_mii_bus(d) container_of(d, struct mii_bus, dev)
  158. struct mii_bus *mdiobus_alloc_size(size_t);
  159. static inline struct mii_bus *mdiobus_alloc(void)
  160. {
  161. return mdiobus_alloc_size(0);
  162. }
  163. int mdiobus_register(struct mii_bus *bus);
  164. void mdiobus_unregister(struct mii_bus *bus);
  165. void mdiobus_free(struct mii_bus *bus);
  166. struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
  167. int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
  168. int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
  169. #define PHY_INTERRUPT_DISABLED 0x0
  170. #define PHY_INTERRUPT_ENABLED 0x80000000
  171. /* PHY state machine states:
  172. *
  173. * DOWN: PHY device and driver are not ready for anything. probe
  174. * should be called if and only if the PHY is in this state,
  175. * given that the PHY device exists.
  176. * - PHY driver probe function will, depending on the PHY, set
  177. * the state to STARTING or READY
  178. *
  179. * STARTING: PHY device is coming up, and the ethernet driver is
  180. * not ready. PHY drivers may set this in the probe function.
  181. * If they do, they are responsible for making sure the state is
  182. * eventually set to indicate whether the PHY is UP or READY,
  183. * depending on the state when the PHY is done starting up.
  184. * - PHY driver will set the state to READY
  185. * - start will set the state to PENDING
  186. *
  187. * READY: PHY is ready to send and receive packets, but the
  188. * controller is not. By default, PHYs which do not implement
  189. * probe will be set to this state by phy_probe(). If the PHY
  190. * driver knows the PHY is ready, and the PHY state is STARTING,
  191. * then it sets this STATE.
  192. * - start will set the state to UP
  193. *
  194. * PENDING: PHY device is coming up, but the ethernet driver is
  195. * ready. phy_start will set this state if the PHY state is
  196. * STARTING.
  197. * - PHY driver will set the state to UP when the PHY is ready
  198. *
  199. * UP: The PHY and attached device are ready to do work.
  200. * Interrupts should be started here.
  201. * - timer moves to AN
  202. *
  203. * AN: The PHY is currently negotiating the link state. Link is
  204. * therefore down for now. phy_timer will set this state when it
  205. * detects the state is UP. config_aneg will set this state
  206. * whenever called with phydev->autoneg set to AUTONEG_ENABLE.
  207. * - If autonegotiation finishes, but there's no link, it sets
  208. * the state to NOLINK.
  209. * - If aneg finishes with link, it sets the state to RUNNING,
  210. * and calls adjust_link
  211. * - If autonegotiation did not finish after an arbitrary amount
  212. * of time, autonegotiation should be tried again if the PHY
  213. * supports "magic" autonegotiation (back to AN)
  214. * - If it didn't finish, and no magic_aneg, move to FORCING.
  215. *
  216. * NOLINK: PHY is up, but not currently plugged in.
  217. * - If the timer notes that the link comes back, we move to RUNNING
  218. * - config_aneg moves to AN
  219. * - phy_stop moves to HALTED
  220. *
  221. * FORCING: PHY is being configured with forced settings
  222. * - if link is up, move to RUNNING
  223. * - If link is down, we drop to the next highest setting, and
  224. * retry (FORCING) after a timeout
  225. * - phy_stop moves to HALTED
  226. *
  227. * RUNNING: PHY is currently up, running, and possibly sending
  228. * and/or receiving packets
  229. * - timer will set CHANGELINK if we're polling (this ensures the
  230. * link state is polled every other cycle of this state machine,
  231. * which makes it every other second)
  232. * - irq will set CHANGELINK
  233. * - config_aneg will set AN
  234. * - phy_stop moves to HALTED
  235. *
  236. * CHANGELINK: PHY experienced a change in link state
  237. * - timer moves to RUNNING if link
  238. * - timer moves to NOLINK if the link is down
  239. * - phy_stop moves to HALTED
  240. *
  241. * HALTED: PHY is up, but no polling or interrupts are done. Or
  242. * PHY is in an error state.
  243. *
  244. * - phy_start moves to RESUMING
  245. *
  246. * RESUMING: PHY was halted, but now wants to run again.
  247. * - If we are forcing, or aneg is done, timer moves to RUNNING
  248. * - If aneg is not done, timer moves to AN
  249. * - phy_stop moves to HALTED
  250. */
  251. enum phy_state {
  252. PHY_DOWN = 0,
  253. PHY_STARTING,
  254. PHY_READY,
  255. PHY_PENDING,
  256. PHY_UP,
  257. PHY_AN,
  258. PHY_RUNNING,
  259. PHY_NOLINK,
  260. PHY_FORCING,
  261. PHY_CHANGELINK,
  262. PHY_HALTED,
  263. PHY_RESUMING
  264. };
  265. /**
  266. * struct phy_c45_device_ids - 802.3-c45 Device Identifiers
  267. * @devices_in_package: Bit vector of devices present.
  268. * @device_ids: The device identifer for each present device.
  269. */
  270. struct phy_c45_device_ids {
  271. u32 devices_in_package;
  272. u32 device_ids[8];
  273. };
  274. /* phy_device: An instance of a PHY
  275. *
  276. * drv: Pointer to the driver for this PHY instance
  277. * bus: Pointer to the bus this PHY is on
  278. * dev: driver model device structure for this PHY
  279. * phy_id: UID for this device found during discovery
  280. * c45_ids: 802.3-c45 Device Identifers if is_c45.
  281. * is_c45: Set to true if this phy uses clause 45 addressing.
  282. * is_internal: Set to true if this phy is internal to a MAC.
  283. * state: state of the PHY for management purposes
  284. * dev_flags: Device-specific flags used by the PHY driver.
  285. * addr: Bus address of PHY
  286. * link_timeout: The number of timer firings to wait before the
  287. * giving up on the current attempt at acquiring a link
  288. * irq: IRQ number of the PHY's interrupt (-1 if none)
  289. * phy_timer: The timer for handling the state machine
  290. * phy_queue: A work_queue for the interrupt
  291. * attached_dev: The attached enet driver's device instance ptr
  292. * adjust_link: Callback for the enet controller to respond to
  293. * changes in the link state.
  294. *
  295. * speed, duplex, pause, supported, advertising, lp_advertising,
  296. * and autoneg are used like in mii_if_info
  297. *
  298. * interrupts currently only supports enabled or disabled,
  299. * but could be changed in the future to support enabling
  300. * and disabling specific interrupts
  301. *
  302. * Contains some infrastructure for polling and interrupt
  303. * handling, as well as handling shifts in PHY hardware state
  304. */
  305. struct phy_device {
  306. /* Information about the PHY type */
  307. /* And management functions */
  308. struct phy_driver *drv;
  309. struct mii_bus *bus;
  310. struct device dev;
  311. u32 phy_id;
  312. struct phy_c45_device_ids c45_ids;
  313. bool is_c45;
  314. bool is_internal;
  315. bool has_fixups;
  316. enum phy_state state;
  317. u32 dev_flags;
  318. phy_interface_t interface;
  319. /* Bus address of the PHY (0-31) */
  320. int addr;
  321. /*
  322. * forced speed & duplex (no autoneg)
  323. * partner speed & duplex & pause (autoneg)
  324. */
  325. int speed;
  326. int duplex;
  327. int pause;
  328. int asym_pause;
  329. /* The most recently read link state */
  330. int link;
  331. /* Enabled Interrupts */
  332. u32 interrupts;
  333. /* Union of PHY and Attached devices' supported modes */
  334. /* See mii.h for more info */
  335. u32 supported;
  336. u32 advertising;
  337. u32 lp_advertising;
  338. int autoneg;
  339. int link_timeout;
  340. /*
  341. * Interrupt number for this PHY
  342. * -1 means no interrupt
  343. */
  344. int irq;
  345. /* private data pointer */
  346. /* For use by PHYs to maintain extra state */
  347. void *priv;
  348. /* Interrupt and Polling infrastructure */
  349. struct work_struct phy_queue;
  350. struct delayed_work state_queue;
  351. atomic_t irq_disable;
  352. struct mutex lock;
  353. struct net_device *attached_dev;
  354. void (*adjust_link)(struct net_device *dev);
  355. };
  356. #define to_phy_device(d) container_of(d, struct phy_device, dev)
  357. /* struct phy_driver: Driver structure for a particular PHY type
  358. *
  359. * phy_id: The result of reading the UID registers of this PHY
  360. * type, and ANDing them with the phy_id_mask. This driver
  361. * only works for PHYs with IDs which match this field
  362. * name: The friendly name of this PHY type
  363. * phy_id_mask: Defines the important bits of the phy_id
  364. * features: A list of features (speed, duplex, etc) supported
  365. * by this PHY
  366. * flags: A bitfield defining certain other features this PHY
  367. * supports (like interrupts)
  368. *
  369. * The drivers must implement config_aneg and read_status. All
  370. * other functions are optional. Note that none of these
  371. * functions should be called from interrupt time. The goal is
  372. * for the bus read/write functions to be able to block when the
  373. * bus transaction is happening, and be freed up by an interrupt
  374. * (The MPC85xx has this ability, though it is not currently
  375. * supported in the driver).
  376. */
  377. struct phy_driver {
  378. u32 phy_id;
  379. char *name;
  380. unsigned int phy_id_mask;
  381. u32 features;
  382. u32 flags;
  383. /*
  384. * Called to initialize the PHY,
  385. * including after a reset
  386. */
  387. int (*config_init)(struct phy_device *phydev);
  388. /*
  389. * Called during discovery. Used to set
  390. * up device-specific structures, if any
  391. */
  392. int (*probe)(struct phy_device *phydev);
  393. /* PHY Power Management */
  394. int (*suspend)(struct phy_device *phydev);
  395. int (*resume)(struct phy_device *phydev);
  396. /*
  397. * Configures the advertisement and resets
  398. * autonegotiation if phydev->autoneg is on,
  399. * forces the speed to the current settings in phydev
  400. * if phydev->autoneg is off
  401. */
  402. int (*config_aneg)(struct phy_device *phydev);
  403. /* Determines the auto negotiation result */
  404. int (*aneg_done)(struct phy_device *phydev);
  405. /* Determines the negotiated speed and duplex */
  406. int (*read_status)(struct phy_device *phydev);
  407. /* Clears any pending interrupts */
  408. int (*ack_interrupt)(struct phy_device *phydev);
  409. /* Enables or disables interrupts */
  410. int (*config_intr)(struct phy_device *phydev);
  411. /*
  412. * Checks if the PHY generated an interrupt.
  413. * For multi-PHY devices with shared PHY interrupt pin
  414. */
  415. int (*did_interrupt)(struct phy_device *phydev);
  416. /* Clears up any memory if needed */
  417. void (*remove)(struct phy_device *phydev);
  418. /* Returns true if this is a suitable driver for the given
  419. * phydev. If NULL, matching is based on phy_id and
  420. * phy_id_mask.
  421. */
  422. int (*match_phy_device)(struct phy_device *phydev);
  423. /* Handles ethtool queries for hardware time stamping. */
  424. int (*ts_info)(struct phy_device *phydev, struct ethtool_ts_info *ti);
  425. /* Handles SIOCSHWTSTAMP ioctl for hardware time stamping. */
  426. int (*hwtstamp)(struct phy_device *phydev, struct ifreq *ifr);
  427. /*
  428. * Requests a Rx timestamp for 'skb'. If the skb is accepted,
  429. * the phy driver promises to deliver it using netif_rx() as
  430. * soon as a timestamp becomes available. One of the
  431. * PTP_CLASS_ values is passed in 'type'. The function must
  432. * return true if the skb is accepted for delivery.
  433. */
  434. bool (*rxtstamp)(struct phy_device *dev, struct sk_buff *skb, int type);
  435. /*
  436. * Requests a Tx timestamp for 'skb'. The phy driver promises
  437. * to deliver it using skb_complete_tx_timestamp() as soon as a
  438. * timestamp becomes available. One of the PTP_CLASS_ values
  439. * is passed in 'type'.
  440. */
  441. void (*txtstamp)(struct phy_device *dev, struct sk_buff *skb, int type);
  442. /* Some devices (e.g. qnap TS-119P II) require PHY register changes to
  443. * enable Wake on LAN, so set_wol is provided to be called in the
  444. * ethernet driver's set_wol function. */
  445. int (*set_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
  446. /* See set_wol, but for checking whether Wake on LAN is enabled. */
  447. void (*get_wol)(struct phy_device *dev, struct ethtool_wolinfo *wol);
  448. struct device_driver driver;
  449. };
  450. #define to_phy_driver(d) container_of(d, struct phy_driver, driver)
  451. #define PHY_ANY_ID "MATCH ANY PHY"
  452. #define PHY_ANY_UID 0xffffffff
  453. /* A Structure for boards to register fixups with the PHY Lib */
  454. struct phy_fixup {
  455. struct list_head list;
  456. char bus_id[20];
  457. u32 phy_uid;
  458. u32 phy_uid_mask;
  459. int (*run)(struct phy_device *phydev);
  460. };
  461. /**
  462. * phy_read_mmd - Convenience function for reading a register
  463. * from an MMD on a given PHY.
  464. * @phydev: The phy_device struct
  465. * @devad: The MMD to read from
  466. * @regnum: The register on the MMD to read
  467. *
  468. * Same rules as for phy_read();
  469. */
  470. static inline int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
  471. {
  472. if (!phydev->is_c45)
  473. return -EOPNOTSUPP;
  474. return mdiobus_read(phydev->bus, phydev->addr,
  475. MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff));
  476. }
  477. /**
  478. * phy_read - Convenience function for reading a given PHY register
  479. * @phydev: the phy_device struct
  480. * @regnum: register number to read
  481. *
  482. * NOTE: MUST NOT be called from interrupt context,
  483. * because the bus read/write functions may wait for an interrupt
  484. * to conclude the operation.
  485. */
  486. static inline int phy_read(struct phy_device *phydev, u32 regnum)
  487. {
  488. return mdiobus_read(phydev->bus, phydev->addr, regnum);
  489. }
  490. /**
  491. * phy_write - Convenience function for writing a given PHY register
  492. * @phydev: the phy_device struct
  493. * @regnum: register number to write
  494. * @val: value to write to @regnum
  495. *
  496. * NOTE: MUST NOT be called from interrupt context,
  497. * because the bus read/write functions may wait for an interrupt
  498. * to conclude the operation.
  499. */
  500. static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
  501. {
  502. return mdiobus_write(phydev->bus, phydev->addr, regnum, val);
  503. }
  504. /**
  505. * phy_interrupt_is_valid - Convenience function for testing a given PHY irq
  506. * @phydev: the phy_device struct
  507. *
  508. * NOTE: must be kept in sync with addition/removal of PHY_POLL and
  509. * PHY_IGNORE_INTERRUPT
  510. */
  511. static inline bool phy_interrupt_is_valid(struct phy_device *phydev)
  512. {
  513. return phydev->irq != PHY_POLL && phydev->irq != PHY_IGNORE_INTERRUPT;
  514. }
  515. /**
  516. * phy_is_internal - Convenience function for testing if a PHY is internal
  517. * @phydev: the phy_device struct
  518. */
  519. static inline bool phy_is_internal(struct phy_device *phydev)
  520. {
  521. return phydev->is_internal;
  522. }
  523. /**
  524. * phy_write_mmd - Convenience function for writing a register
  525. * on an MMD on a given PHY.
  526. * @phydev: The phy_device struct
  527. * @devad: The MMD to read from
  528. * @regnum: The register on the MMD to read
  529. * @val: value to write to @regnum
  530. *
  531. * Same rules as for phy_write();
  532. */
  533. static inline int phy_write_mmd(struct phy_device *phydev, int devad,
  534. u32 regnum, u16 val)
  535. {
  536. if (!phydev->is_c45)
  537. return -EOPNOTSUPP;
  538. regnum = MII_ADDR_C45 | ((devad & 0x1f) << 16) | (regnum & 0xffff);
  539. return mdiobus_write(phydev->bus, phydev->addr, regnum, val);
  540. }
  541. struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
  542. bool is_c45,
  543. struct phy_c45_device_ids *c45_ids);
  544. struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
  545. int phy_device_register(struct phy_device *phy);
  546. int phy_init_hw(struct phy_device *phydev);
  547. int phy_suspend(struct phy_device *phydev);
  548. int phy_resume(struct phy_device *phydev);
  549. struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
  550. phy_interface_t interface);
  551. struct phy_device *phy_find_first(struct mii_bus *bus);
  552. int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
  553. u32 flags, phy_interface_t interface);
  554. int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
  555. void (*handler)(struct net_device *),
  556. phy_interface_t interface);
  557. struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
  558. void (*handler)(struct net_device *),
  559. phy_interface_t interface);
  560. void phy_disconnect(struct phy_device *phydev);
  561. void phy_detach(struct phy_device *phydev);
  562. void phy_start(struct phy_device *phydev);
  563. void phy_stop(struct phy_device *phydev);
  564. int phy_start_aneg(struct phy_device *phydev);
  565. int phy_stop_interrupts(struct phy_device *phydev);
  566. static inline int phy_read_status(struct phy_device *phydev)
  567. {
  568. return phydev->drv->read_status(phydev);
  569. }
  570. int genphy_setup_forced(struct phy_device *phydev);
  571. int genphy_restart_aneg(struct phy_device *phydev);
  572. int genphy_config_aneg(struct phy_device *phydev);
  573. int genphy_aneg_done(struct phy_device *phydev);
  574. int genphy_update_link(struct phy_device *phydev);
  575. int genphy_read_status(struct phy_device *phydev);
  576. int genphy_suspend(struct phy_device *phydev);
  577. int genphy_resume(struct phy_device *phydev);
  578. void phy_driver_unregister(struct phy_driver *drv);
  579. void phy_drivers_unregister(struct phy_driver *drv, int n);
  580. int phy_driver_register(struct phy_driver *new_driver);
  581. int phy_drivers_register(struct phy_driver *new_driver, int n);
  582. void phy_state_machine(struct work_struct *work);
  583. void phy_change(struct work_struct *work);
  584. void phy_mac_interrupt(struct phy_device *phydev, int new_link);
  585. void phy_start_machine(struct phy_device *phydev);
  586. void phy_stop_machine(struct phy_device *phydev);
  587. int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
  588. int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd);
  589. int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
  590. int phy_start_interrupts(struct phy_device *phydev);
  591. void phy_print_status(struct phy_device *phydev);
  592. void phy_device_free(struct phy_device *phydev);
  593. int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
  594. int (*run)(struct phy_device *));
  595. int phy_register_fixup_for_id(const char *bus_id,
  596. int (*run)(struct phy_device *));
  597. int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
  598. int (*run)(struct phy_device *));
  599. int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
  600. int phy_get_eee_err(struct phy_device *phydev);
  601. int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data);
  602. int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
  603. int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
  604. void phy_ethtool_get_wol(struct phy_device *phydev,
  605. struct ethtool_wolinfo *wol);
  606. int __init mdio_bus_init(void);
  607. void mdio_bus_exit(void);
  608. extern struct bus_type mdio_bus_type;
  609. #endif /* __PHY_H */