phy.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. * Andy Fleming <afleming@freescale.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. struct list_head list;
  106. };
  107. struct phy_device {
  108. /* Information about the PHY type */
  109. /* And management functions */
  110. struct mii_dev *bus;
  111. struct phy_driver *drv;
  112. void *priv;
  113. struct eth_device *dev;
  114. /* forced speed & duplex (no autoneg)
  115. * partner speed & duplex & pause (autoneg)
  116. */
  117. int speed;
  118. int duplex;
  119. /* The most recently read link state */
  120. int link;
  121. int port;
  122. phy_interface_t interface;
  123. u32 advertising;
  124. u32 supported;
  125. u32 mmds;
  126. int autoneg;
  127. int addr;
  128. int pause;
  129. int asym_pause;
  130. u32 phy_id;
  131. u32 flags;
  132. };
  133. static inline int phy_read(struct phy_device *phydev, int devad, int regnum)
  134. {
  135. struct mii_dev *bus = phydev->bus;
  136. return bus->read(bus, phydev->addr, devad, regnum);
  137. }
  138. static inline int phy_write(struct phy_device *phydev, int devad, int regnum,
  139. u16 val)
  140. {
  141. struct mii_dev *bus = phydev->bus;
  142. return bus->write(bus, phydev->addr, devad, regnum, val);
  143. }
  144. #ifdef CONFIG_PHYLIB_10G
  145. extern struct phy_driver gen10g_driver;
  146. /* For now, XGMII is the only 10G interface */
  147. static inline int is_10g_interface(phy_interface_t interface)
  148. {
  149. return interface == PHY_INTERFACE_MODE_XGMII;
  150. }
  151. #endif
  152. int phy_init(void);
  153. int phy_reset(struct phy_device *phydev);
  154. struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask,
  155. phy_interface_t interface);
  156. void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev);
  157. struct phy_device *phy_connect(struct mii_dev *bus, int addr,
  158. struct eth_device *dev,
  159. phy_interface_t interface);
  160. int phy_startup(struct phy_device *phydev);
  161. int phy_config(struct phy_device *phydev);
  162. int phy_shutdown(struct phy_device *phydev);
  163. int phy_register(struct phy_driver *drv);
  164. int genphy_config_aneg(struct phy_device *phydev);
  165. int genphy_restart_aneg(struct phy_device *phydev);
  166. int genphy_update_link(struct phy_device *phydev);
  167. int genphy_parse_link(struct phy_device *phydev);
  168. int genphy_config(struct phy_device *phydev);
  169. int genphy_startup(struct phy_device *phydev);
  170. int genphy_shutdown(struct phy_device *phydev);
  171. int gen10g_config(struct phy_device *phydev);
  172. int gen10g_startup(struct phy_device *phydev);
  173. int gen10g_shutdown(struct phy_device *phydev);
  174. int gen10g_discover_mmds(struct phy_device *phydev);
  175. int phy_atheros_init(void);
  176. int phy_broadcom_init(void);
  177. int phy_davicom_init(void);
  178. int phy_et1011c_init(void);
  179. int phy_lxt_init(void);
  180. int phy_marvell_init(void);
  181. int phy_micrel_init(void);
  182. int phy_natsemi_init(void);
  183. int phy_realtek_init(void);
  184. int phy_smsc_init(void);
  185. int phy_teranetics_init(void);
  186. int phy_vitesse_init(void);
  187. /* PHY UIDs for various PHYs that are referenced in external code */
  188. #define PHY_UID_TN2020 0x00a19410
  189. #endif