mdio.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * linux/mdio.h: definitions for MDIO (clause 45) transceivers
  3. * Copyright 2006-2009 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. #ifndef __LINUX_MDIO_H__
  10. #define __LINUX_MDIO_H__
  11. #include <uapi/linux/mdio.h>
  12. struct mii_bus;
  13. struct mdio_device {
  14. struct device dev;
  15. const struct dev_pm_ops *pm_ops;
  16. struct mii_bus *bus;
  17. /* Bus address of the MDIO device (0-31) */
  18. int addr;
  19. int flags;
  20. };
  21. #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
  22. #define MDIO_DEVICE_FLAG_PHY 1
  23. static inline bool mdio_phy_id_is_c45(int phy_id)
  24. {
  25. return (phy_id & MDIO_PHY_ID_C45) && !(phy_id & ~MDIO_PHY_ID_C45_MASK);
  26. }
  27. static inline __u16 mdio_phy_id_prtad(int phy_id)
  28. {
  29. return (phy_id & MDIO_PHY_ID_PRTAD) >> 5;
  30. }
  31. static inline __u16 mdio_phy_id_devad(int phy_id)
  32. {
  33. return phy_id & MDIO_PHY_ID_DEVAD;
  34. }
  35. /**
  36. * struct mdio_if_info - Ethernet controller MDIO interface
  37. * @prtad: PRTAD of the PHY (%MDIO_PRTAD_NONE if not present/unknown)
  38. * @mmds: Mask of MMDs expected to be present in the PHY. This must be
  39. * non-zero unless @prtad = %MDIO_PRTAD_NONE.
  40. * @mode_support: MDIO modes supported. If %MDIO_SUPPORTS_C22 is set then
  41. * MII register access will be passed through with @devad =
  42. * %MDIO_DEVAD_NONE. If %MDIO_EMULATE_C22 is set then access to
  43. * commonly used clause 22 registers will be translated into
  44. * clause 45 registers.
  45. * @dev: Net device structure
  46. * @mdio_read: Register read function; returns value or negative error code
  47. * @mdio_write: Register write function; returns 0 or negative error code
  48. */
  49. struct mdio_if_info {
  50. int prtad;
  51. u32 mmds;
  52. unsigned mode_support;
  53. struct net_device *dev;
  54. int (*mdio_read)(struct net_device *dev, int prtad, int devad,
  55. u16 addr);
  56. int (*mdio_write)(struct net_device *dev, int prtad, int devad,
  57. u16 addr, u16 val);
  58. };
  59. #define MDIO_PRTAD_NONE (-1)
  60. #define MDIO_DEVAD_NONE (-1)
  61. #define MDIO_SUPPORTS_C22 1
  62. #define MDIO_SUPPORTS_C45 2
  63. #define MDIO_EMULATE_C22 4
  64. struct ethtool_cmd;
  65. struct ethtool_pauseparam;
  66. extern int mdio45_probe(struct mdio_if_info *mdio, int prtad);
  67. extern int mdio_set_flag(const struct mdio_if_info *mdio,
  68. int prtad, int devad, u16 addr, int mask,
  69. bool sense);
  70. extern int mdio45_links_ok(const struct mdio_if_info *mdio, u32 mmds);
  71. extern int mdio45_nway_restart(const struct mdio_if_info *mdio);
  72. extern void mdio45_ethtool_gset_npage(const struct mdio_if_info *mdio,
  73. struct ethtool_cmd *ecmd,
  74. u32 npage_adv, u32 npage_lpa);
  75. /**
  76. * mdio45_ethtool_gset - get settings for ETHTOOL_GSET
  77. * @mdio: MDIO interface
  78. * @ecmd: Ethtool request structure
  79. *
  80. * Since the CSRs for auto-negotiation using next pages are not fully
  81. * standardised, this function does not attempt to decode them. Use
  82. * mdio45_ethtool_gset_npage() to specify advertisement bits from next
  83. * pages.
  84. */
  85. static inline void mdio45_ethtool_gset(const struct mdio_if_info *mdio,
  86. struct ethtool_cmd *ecmd)
  87. {
  88. mdio45_ethtool_gset_npage(mdio, ecmd, 0, 0);
  89. }
  90. extern int mdio_mii_ioctl(const struct mdio_if_info *mdio,
  91. struct mii_ioctl_data *mii_data, int cmd);
  92. /**
  93. * mmd_eee_cap_to_ethtool_sup_t
  94. * @eee_cap: value of the MMD EEE Capability register
  95. *
  96. * A small helper function that translates MMD EEE Capability (3.20) bits
  97. * to ethtool supported settings.
  98. */
  99. static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
  100. {
  101. u32 supported = 0;
  102. if (eee_cap & MDIO_EEE_100TX)
  103. supported |= SUPPORTED_100baseT_Full;
  104. if (eee_cap & MDIO_EEE_1000T)
  105. supported |= SUPPORTED_1000baseT_Full;
  106. if (eee_cap & MDIO_EEE_10GT)
  107. supported |= SUPPORTED_10000baseT_Full;
  108. if (eee_cap & MDIO_EEE_1000KX)
  109. supported |= SUPPORTED_1000baseKX_Full;
  110. if (eee_cap & MDIO_EEE_10GKX4)
  111. supported |= SUPPORTED_10000baseKX4_Full;
  112. if (eee_cap & MDIO_EEE_10GKR)
  113. supported |= SUPPORTED_10000baseKR_Full;
  114. return supported;
  115. }
  116. /**
  117. * mmd_eee_adv_to_ethtool_adv_t
  118. * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
  119. *
  120. * A small helper function that translates the MMD EEE Advertisment (7.60)
  121. * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
  122. * settings.
  123. */
  124. static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
  125. {
  126. u32 adv = 0;
  127. if (eee_adv & MDIO_EEE_100TX)
  128. adv |= ADVERTISED_100baseT_Full;
  129. if (eee_adv & MDIO_EEE_1000T)
  130. adv |= ADVERTISED_1000baseT_Full;
  131. if (eee_adv & MDIO_EEE_10GT)
  132. adv |= ADVERTISED_10000baseT_Full;
  133. if (eee_adv & MDIO_EEE_1000KX)
  134. adv |= ADVERTISED_1000baseKX_Full;
  135. if (eee_adv & MDIO_EEE_10GKX4)
  136. adv |= ADVERTISED_10000baseKX4_Full;
  137. if (eee_adv & MDIO_EEE_10GKR)
  138. adv |= ADVERTISED_10000baseKR_Full;
  139. return adv;
  140. }
  141. /**
  142. * ethtool_adv_to_mmd_eee_adv_t
  143. * @adv: the ethtool advertisement settings
  144. *
  145. * A small helper function that translates ethtool advertisement settings
  146. * to EEE advertisements for the MMD EEE Advertisement (7.60) and
  147. * MMD EEE Link Partner Ability (7.61) registers.
  148. */
  149. static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
  150. {
  151. u16 reg = 0;
  152. if (adv & ADVERTISED_100baseT_Full)
  153. reg |= MDIO_EEE_100TX;
  154. if (adv & ADVERTISED_1000baseT_Full)
  155. reg |= MDIO_EEE_1000T;
  156. if (adv & ADVERTISED_10000baseT_Full)
  157. reg |= MDIO_EEE_10GT;
  158. if (adv & ADVERTISED_1000baseKX_Full)
  159. reg |= MDIO_EEE_1000KX;
  160. if (adv & ADVERTISED_10000baseKX4_Full)
  161. reg |= MDIO_EEE_10GKX4;
  162. if (adv & ADVERTISED_10000baseKR_Full)
  163. reg |= MDIO_EEE_10GKR;
  164. return reg;
  165. }
  166. int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
  167. int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
  168. int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
  169. int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
  170. int mdiobus_register_device(struct mdio_device *mdiodev);
  171. int mdiobus_unregister_device(struct mdio_device *mdiodev);
  172. bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
  173. struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr);
  174. #endif /* __LINUX_MDIO_H__ */