phy.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. * Andy Fleming <afleming@gmail.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. *
  7. * This file pretty much stolen from Linux's mii.h/ethtool.h/phy.h
  8. */
  9. #ifndef _PHY_H
  10. #define _PHY_H
  11. #include <linux/list.h>
  12. #include <linux/mii.h>
  13. #include <linux/ethtool.h>
  14. #include <linux/mdio.h>
  15. #define PHY_MAX_ADDR 32
  16. #define PHY_BASIC_FEATURES (SUPPORTED_10baseT_Half | \
  17. SUPPORTED_10baseT_Full | \
  18. SUPPORTED_100baseT_Half | \
  19. SUPPORTED_100baseT_Full | \
  20. SUPPORTED_Autoneg | \
  21. SUPPORTED_TP | \
  22. SUPPORTED_MII)
  23. #define PHY_GBIT_FEATURES (PHY_BASIC_FEATURES | \
  24. SUPPORTED_1000baseT_Half | \
  25. SUPPORTED_1000baseT_Full)
  26. #define PHY_10G_FEATURES (PHY_GBIT_FEATURES | \
  27. SUPPORTED_10000baseT_Full)
  28. #define PHY_ANEG_TIMEOUT 4000
  29. typedef enum {
  30. PHY_INTERFACE_MODE_MII,
  31. PHY_INTERFACE_MODE_GMII,
  32. PHY_INTERFACE_MODE_SGMII,
  33. PHY_INTERFACE_MODE_QSGMII,
  34. PHY_INTERFACE_MODE_TBI,
  35. PHY_INTERFACE_MODE_RMII,
  36. PHY_INTERFACE_MODE_RGMII,
  37. PHY_INTERFACE_MODE_RGMII_ID,
  38. PHY_INTERFACE_MODE_RGMII_RXID,
  39. PHY_INTERFACE_MODE_RGMII_TXID,
  40. PHY_INTERFACE_MODE_RTBI,
  41. PHY_INTERFACE_MODE_XGMII,
  42. PHY_INTERFACE_MODE_NONE /* Must be last */
  43. } phy_interface_t;
  44. static const char *phy_interface_strings[] = {
  45. [PHY_INTERFACE_MODE_MII] = "mii",
  46. [PHY_INTERFACE_MODE_GMII] = "gmii",
  47. [PHY_INTERFACE_MODE_SGMII] = "sgmii",
  48. [PHY_INTERFACE_MODE_QSGMII] = "qsgmii",
  49. [PHY_INTERFACE_MODE_TBI] = "tbi",
  50. [PHY_INTERFACE_MODE_RMII] = "rmii",
  51. [PHY_INTERFACE_MODE_RGMII] = "rgmii",
  52. [PHY_INTERFACE_MODE_RGMII_ID] = "rgmii-id",
  53. [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid",
  54. [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
  55. [PHY_INTERFACE_MODE_RTBI] = "rtbi",
  56. [PHY_INTERFACE_MODE_XGMII] = "xgmii",
  57. [PHY_INTERFACE_MODE_NONE] = "",
  58. };
  59. static inline const char *phy_string_for_interface(phy_interface_t i)
  60. {
  61. /* Default to unknown */
  62. if (i > PHY_INTERFACE_MODE_NONE)
  63. i = PHY_INTERFACE_MODE_NONE;
  64. return phy_interface_strings[i];
  65. }
  66. struct phy_device;
  67. #define MDIO_NAME_LEN 32
  68. struct mii_dev {
  69. struct list_head link;
  70. char name[MDIO_NAME_LEN];
  71. void *priv;
  72. int (*read)(struct mii_dev *bus, int addr, int devad, int reg);
  73. int (*write)(struct mii_dev *bus, int addr, int devad, int reg,
  74. u16 val);
  75. int (*reset)(struct mii_dev *bus);
  76. struct phy_device *phymap[PHY_MAX_ADDR];
  77. u32 phy_mask;
  78. };
  79. /* struct phy_driver: a structure which defines PHY behavior
  80. *
  81. * uid will contain a number which represents the PHY. During
  82. * startup, the driver will poll the PHY to find out what its
  83. * UID--as defined by registers 2 and 3--is. The 32-bit result
  84. * gotten from the PHY will be masked to
  85. * discard any bits which may change based on revision numbers
  86. * unimportant to functionality
  87. *
  88. */
  89. struct phy_driver {
  90. char *name;
  91. unsigned int uid;
  92. unsigned int mask;
  93. unsigned int mmds;
  94. u32 features;
  95. /* Called to do any driver startup necessities */
  96. /* Will be called during phy_connect */
  97. int (*probe)(struct phy_device *phydev);
  98. /* Called to configure the PHY, and modify the controller
  99. * based on the results. Should be called after phy_connect */
  100. int (*config)(struct phy_device *phydev);
  101. /* Called when starting up the controller */
  102. int (*startup)(struct phy_device *phydev);
  103. /* Called when bringing down the controller */
  104. int (*shutdown)(struct phy_device *phydev);
  105. int (*readext)(struct phy_device *phydev, int addr, int devad, int reg);
  106. int (*writeext)(struct phy_device *phydev, int addr, int devad, int reg,
  107. u16 val);
  108. struct list_head list;
  109. };
  110. struct phy_device {
  111. /* Information about the PHY type */
  112. /* And management functions */
  113. struct mii_dev *bus;
  114. struct phy_driver *drv;
  115. void *priv;
  116. struct eth_device *dev;
  117. /* forced speed & duplex (no autoneg)
  118. * partner speed & duplex & pause (autoneg)
  119. */
  120. int speed;
  121. int duplex;
  122. /* The most recently read link state */
  123. int link;
  124. int port;
  125. phy_interface_t interface;
  126. u32 advertising;
  127. u32 supported;
  128. u32 mmds;
  129. int autoneg;
  130. int addr;
  131. int pause;
  132. int asym_pause;
  133. u32 phy_id;
  134. u32 flags;
  135. };
  136. struct fixed_link {
  137. int phy_id;
  138. int duplex;
  139. int link_speed;
  140. int pause;
  141. int asym_pause;
  142. };
  143. static inline int phy_read(struct phy_device *phydev, int devad, int regnum)
  144. {
  145. struct mii_dev *bus = phydev->bus;
  146. return bus->read(bus, phydev->addr, devad, regnum);
  147. }
  148. static inline int phy_write(struct phy_device *phydev, int devad, int regnum,
  149. u16 val)
  150. {
  151. struct mii_dev *bus = phydev->bus;
  152. return bus->write(bus, phydev->addr, devad, regnum, val);
  153. }
  154. #ifdef CONFIG_PHYLIB_10G
  155. extern struct phy_driver gen10g_driver;
  156. /* For now, XGMII is the only 10G interface */
  157. static inline int is_10g_interface(phy_interface_t interface)
  158. {
  159. return interface == PHY_INTERFACE_MODE_XGMII;
  160. }
  161. #endif
  162. int phy_init(void);
  163. int phy_reset(struct phy_device *phydev);
  164. struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask,
  165. phy_interface_t interface);
  166. void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev);
  167. struct phy_device *phy_connect(struct mii_dev *bus, int addr,
  168. struct eth_device *dev,
  169. phy_interface_t interface);
  170. int phy_startup(struct phy_device *phydev);
  171. int phy_config(struct phy_device *phydev);
  172. int phy_shutdown(struct phy_device *phydev);
  173. int phy_register(struct phy_driver *drv);
  174. int genphy_config_aneg(struct phy_device *phydev);
  175. int genphy_restart_aneg(struct phy_device *phydev);
  176. int genphy_update_link(struct phy_device *phydev);
  177. int genphy_parse_link(struct phy_device *phydev);
  178. int genphy_config(struct phy_device *phydev);
  179. int genphy_startup(struct phy_device *phydev);
  180. int genphy_shutdown(struct phy_device *phydev);
  181. int gen10g_config(struct phy_device *phydev);
  182. int gen10g_startup(struct phy_device *phydev);
  183. int gen10g_shutdown(struct phy_device *phydev);
  184. int gen10g_discover_mmds(struct phy_device *phydev);
  185. int phy_atheros_init(void);
  186. int phy_broadcom_init(void);
  187. int phy_davicom_init(void);
  188. int phy_et1011c_init(void);
  189. int phy_lxt_init(void);
  190. int phy_marvell_init(void);
  191. int phy_micrel_init(void);
  192. int phy_natsemi_init(void);
  193. int phy_realtek_init(void);
  194. int phy_smsc_init(void);
  195. int phy_teranetics_init(void);
  196. int phy_vitesse_init(void);
  197. int board_phy_config(struct phy_device *phydev);
  198. /* PHY UIDs for various PHYs that are referenced in external code */
  199. #define PHY_UID_TN2020 0x00a19410
  200. #endif