phy.h 6.5 KB

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