mdio.h 5.2 KB

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