mdio.h 6.1 KB

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