mdio_10g.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2006-2008 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 EFX_MDIO_10G_H
  10. #define EFX_MDIO_10G_H
  11. /*
  12. * Definitions needed for doing 10G MDIO as specified in clause 45
  13. * MDIO, which do not appear in Linux yet. Also some helper functions.
  14. */
  15. #include "efx.h"
  16. #include "boards.h"
  17. /* Numbering of the MDIO Manageable Devices (MMDs) */
  18. /* Physical Medium Attachment/ Physical Medium Dependent sublayer */
  19. #define MDIO_MMD_PMAPMD (1)
  20. /* WAN Interface Sublayer */
  21. #define MDIO_MMD_WIS (2)
  22. /* Physical Coding Sublayer */
  23. #define MDIO_MMD_PCS (3)
  24. /* PHY Extender Sublayer */
  25. #define MDIO_MMD_PHYXS (4)
  26. /* Extender Sublayer */
  27. #define MDIO_MMD_DTEXS (5)
  28. /* Transmission convergence */
  29. #define MDIO_MMD_TC (6)
  30. /* Auto negotiation */
  31. #define MDIO_MMD_AN (7)
  32. /* Clause 22 extension */
  33. #define MDIO_MMD_C22EXT 29
  34. /* Generic register locations */
  35. #define MDIO_MMDREG_CTRL1 (0)
  36. #define MDIO_MMDREG_STAT1 (1)
  37. #define MDIO_MMDREG_IDHI (2)
  38. #define MDIO_MMDREG_IDLOW (3)
  39. #define MDIO_MMDREG_SPEED (4)
  40. #define MDIO_MMDREG_DEVS0 (5)
  41. #define MDIO_MMDREG_DEVS1 (6)
  42. #define MDIO_MMDREG_CTRL2 (7)
  43. #define MDIO_MMDREG_STAT2 (8)
  44. #define MDIO_MMDREG_TXDIS (9)
  45. /* Bits in MMDREG_CTRL1 */
  46. /* Reset */
  47. #define MDIO_MMDREG_CTRL1_RESET_LBN (15)
  48. #define MDIO_MMDREG_CTRL1_RESET_WIDTH (1)
  49. /* Loopback */
  50. /* Loopback bit for WIS, PCS, PHYSX and DTEXS */
  51. #define MDIO_MMDREG_CTRL1_LBACK_LBN (14)
  52. #define MDIO_MMDREG_CTRL1_LBACK_WIDTH (1)
  53. /* Low power */
  54. #define MDIO_MMDREG_CTRL1_LPOWER_LBN (11)
  55. #define MDIO_MMDREG_CTRL1_LPOWER_WIDTH (1)
  56. /* Bits in MMDREG_STAT1 */
  57. #define MDIO_MMDREG_STAT1_FAULT_LBN (7)
  58. #define MDIO_MMDREG_STAT1_FAULT_WIDTH (1)
  59. /* Link state */
  60. #define MDIO_MMDREG_STAT1_LINK_LBN (2)
  61. #define MDIO_MMDREG_STAT1_LINK_WIDTH (1)
  62. /* Low power ability */
  63. #define MDIO_MMDREG_STAT1_LPABLE_LBN (1)
  64. #define MDIO_MMDREG_STAT1_LPABLE_WIDTH (1)
  65. /* Bits in combined ID regs */
  66. static inline unsigned mdio_id_rev(u32 id) { return id & 0xf; }
  67. static inline unsigned mdio_id_model(u32 id) { return (id >> 4) & 0x3f; }
  68. extern unsigned mdio_id_oui(u32 id);
  69. /* Bits in MMDREG_DEVS0/1. Someone thoughtfully layed things out
  70. * so the 'bit present' bit number of an MMD is the number of
  71. * that MMD */
  72. #define DEV_PRESENT_BIT(_b) (1 << _b)
  73. #define MDIO_MMDREG_DEVS_PHYXS DEV_PRESENT_BIT(MDIO_MMD_PHYXS)
  74. #define MDIO_MMDREG_DEVS_PCS DEV_PRESENT_BIT(MDIO_MMD_PCS)
  75. #define MDIO_MMDREG_DEVS_PMAPMD DEV_PRESENT_BIT(MDIO_MMD_PMAPMD)
  76. #define MDIO_MMDREG_DEVS_AN DEV_PRESENT_BIT(MDIO_MMD_AN)
  77. #define MDIO_MMDREG_DEVS_C22EXT DEV_PRESENT_BIT(MDIO_MMD_C22EXT)
  78. /* Bits in MMDREG_SPEED */
  79. #define MDIO_MMDREG_SPEED_10G_LBN 0
  80. #define MDIO_MMDREG_SPEED_10G_WIDTH 1
  81. #define MDIO_MMDREG_SPEED_1000M_LBN 4
  82. #define MDIO_MMDREG_SPEED_1000M_WIDTH 1
  83. #define MDIO_MMDREG_SPEED_100M_LBN 5
  84. #define MDIO_MMDREG_SPEED_100M_WIDTH 1
  85. #define MDIO_MMDREG_SPEED_10M_LBN 6
  86. #define MDIO_MMDREG_SPEED_10M_WIDTH 1
  87. /* Bits in MMDREG_STAT2 */
  88. #define MDIO_MMDREG_STAT2_PRESENT_VAL (2)
  89. #define MDIO_MMDREG_STAT2_PRESENT_LBN (14)
  90. #define MDIO_MMDREG_STAT2_PRESENT_WIDTH (2)
  91. /* Bits in MMDREG_TXDIS */
  92. #define MDIO_MMDREG_TXDIS_GLOBAL_LBN (0)
  93. #define MDIO_MMDREG_TXDIS_GLOBAL_WIDTH (1)
  94. /* MMD-specific bits, ordered by MMD, then register */
  95. #define MDIO_PMAPMD_CTRL1_LBACK_LBN (0)
  96. #define MDIO_PMAPMD_CTRL1_LBACK_WIDTH (1)
  97. /* PMA type (4 bits) */
  98. #define MDIO_PMAPMD_CTRL2_10G_CX4 (0x0)
  99. #define MDIO_PMAPMD_CTRL2_10G_EW (0x1)
  100. #define MDIO_PMAPMD_CTRL2_10G_LW (0x2)
  101. #define MDIO_PMAPMD_CTRL2_10G_SW (0x3)
  102. #define MDIO_PMAPMD_CTRL2_10G_LX4 (0x4)
  103. #define MDIO_PMAPMD_CTRL2_10G_ER (0x5)
  104. #define MDIO_PMAPMD_CTRL2_10G_LR (0x6)
  105. #define MDIO_PMAPMD_CTRL2_10G_SR (0x7)
  106. /* Reserved */
  107. #define MDIO_PMAPMD_CTRL2_10G_BT (0x9)
  108. /* Reserved */
  109. /* Reserved */
  110. #define MDIO_PMAPMD_CTRL2_1G_BT (0xc)
  111. /* Reserved */
  112. #define MDIO_PMAPMD_CTRL2_100_BT (0xe)
  113. #define MDIO_PMAPMD_CTRL2_10_BT (0xf)
  114. #define MDIO_PMAPMD_CTRL2_TYPE_MASK (0xf)
  115. /* PMA 10GBT registers */
  116. #define MDIO_PMAPMD_10GBT_TXPWR (131)
  117. #define MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN (0)
  118. #define MDIO_PMAPMD_10GBT_TXPWR_SHORT_WIDTH (1)
  119. /* PHY XGXS Status 2 */
  120. #define MDIO_PHYXS_STATUS2 (8)
  121. #define MDIO_PHYXS_STATUS2_RX_FAULT_LBN 10
  122. /* PHY XGXS lane state */
  123. #define MDIO_PHYXS_LANE_STATE (0x18)
  124. #define MDIO_PHYXS_LANE_ALIGNED_LBN (12)
  125. /* AN registers */
  126. #define MDIO_AN_CTRL_XNP_LBN 13
  127. #define MDIO_AN_STATUS (1)
  128. #define MDIO_AN_STATUS_XNP_LBN (7)
  129. #define MDIO_AN_STATUS_PAGE_LBN (6)
  130. #define MDIO_AN_STATUS_AN_DONE_LBN (5)
  131. #define MDIO_AN_STATUS_LP_AN_CAP_LBN (0)
  132. #define MDIO_AN_ADVERTISE 16
  133. #define MDIO_AN_ADVERTISE_XNP_LBN 12
  134. #define MDIO_AN_LPA 19
  135. #define MDIO_AN_XNP 22
  136. #define MDIO_AN_LPA_XNP 25
  137. #define MDIO_AN_10GBT_CTRL 32
  138. #define MDIO_AN_10GBT_CTRL_ADV_10G_LBN 12
  139. #define MDIO_AN_10GBT_STATUS (33)
  140. #define MDIO_AN_10GBT_STATUS_MS_FLT_LBN (15) /* MASTER/SLAVE config fault */
  141. #define MDIO_AN_10GBT_STATUS_MS_LBN (14) /* MASTER/SLAVE config */
  142. #define MDIO_AN_10GBT_STATUS_LOC_OK_LBN (13) /* Local OK */
  143. #define MDIO_AN_10GBT_STATUS_REM_OK_LBN (12) /* Remote OK */
  144. #define MDIO_AN_10GBT_STATUS_LP_10G_LBN (11) /* Link partner is 10GBT capable */
  145. #define MDIO_AN_10GBT_STATUS_LP_LTA_LBN (10) /* LP loop timing ability */
  146. #define MDIO_AN_10GBT_STATUS_LP_TRR_LBN (9) /* LP Training Reset Request */
  147. /* Packing of the prt and dev arguments of clause 45 style MDIO into a
  148. * single int so they can be passed into the mdio_read/write functions
  149. * that currently exist. Note that as Falcon is the only current user,
  150. * the packed form is chosen to match what Falcon needs to write into
  151. * a register. This is checked at compile-time so do not change it. If
  152. * your target chip needs things layed out differently you will need
  153. * to unpack the arguments in your chip-specific mdio functions.
  154. */
  155. /* These are defined by the standard. */
  156. #define MDIO45_PRT_ID_WIDTH (5)
  157. #define MDIO45_DEV_ID_WIDTH (5)
  158. /* The prt ID is just packed in immediately to the left of the dev ID */
  159. #define MDIO45_PRT_DEV_WIDTH (MDIO45_PRT_ID_WIDTH + MDIO45_DEV_ID_WIDTH)
  160. #define MDIO45_PRT_ID_MASK ((1 << MDIO45_PRT_DEV_WIDTH) - 1)
  161. /* This is the prt + dev extended by 1 bit to hold the 'is clause 45' flag. */
  162. #define MDIO45_XPRT_ID_WIDTH (MDIO45_PRT_DEV_WIDTH + 1)
  163. #define MDIO45_XPRT_ID_MASK ((1 << MDIO45_XPRT_ID_WIDTH) - 1)
  164. #define MDIO45_XPRT_ID_IS10G (1 << (MDIO45_XPRT_ID_WIDTH - 1))
  165. #define MDIO45_PRT_ID_COMP_LBN MDIO45_DEV_ID_WIDTH
  166. #define MDIO45_PRT_ID_COMP_WIDTH MDIO45_PRT_ID_WIDTH
  167. #define MDIO45_DEV_ID_COMP_LBN 0
  168. #define MDIO45_DEV_ID_COMP_WIDTH MDIO45_DEV_ID_WIDTH
  169. /* Compose port and device into a phy_id */
  170. static inline int mdio_clause45_pack(u8 prt, u8 dev)
  171. {
  172. efx_dword_t phy_id;
  173. EFX_POPULATE_DWORD_2(phy_id, MDIO45_PRT_ID_COMP, prt,
  174. MDIO45_DEV_ID_COMP, dev);
  175. return MDIO45_XPRT_ID_IS10G | EFX_DWORD_VAL(phy_id);
  176. }
  177. static inline void mdio_clause45_unpack(u32 val, u8 *prt, u8 *dev)
  178. {
  179. efx_dword_t phy_id;
  180. EFX_POPULATE_DWORD_1(phy_id, EFX_DWORD_0, val);
  181. *prt = EFX_DWORD_FIELD(phy_id, MDIO45_PRT_ID_COMP);
  182. *dev = EFX_DWORD_FIELD(phy_id, MDIO45_DEV_ID_COMP);
  183. }
  184. static inline int mdio_clause45_read(struct efx_nic *efx,
  185. u8 prt, u8 dev, u16 addr)
  186. {
  187. return efx->mii.mdio_read(efx->net_dev,
  188. mdio_clause45_pack(prt, dev), addr);
  189. }
  190. static inline void mdio_clause45_write(struct efx_nic *efx,
  191. u8 prt, u8 dev, u16 addr, int value)
  192. {
  193. efx->mii.mdio_write(efx->net_dev,
  194. mdio_clause45_pack(prt, dev), addr, value);
  195. }
  196. static inline u32 mdio_clause45_read_id(struct efx_nic *efx, int mmd)
  197. {
  198. int phy_id = efx->mii.phy_id;
  199. u16 id_low = mdio_clause45_read(efx, phy_id, mmd, MDIO_MMDREG_IDLOW);
  200. u16 id_hi = mdio_clause45_read(efx, phy_id, mmd, MDIO_MMDREG_IDHI);
  201. return (id_hi << 16) | (id_low);
  202. }
  203. static inline bool mdio_clause45_phyxgxs_lane_sync(struct efx_nic *efx)
  204. {
  205. int i, lane_status;
  206. bool sync;
  207. for (i = 0; i < 2; ++i)
  208. lane_status = mdio_clause45_read(efx, efx->mii.phy_id,
  209. MDIO_MMD_PHYXS,
  210. MDIO_PHYXS_LANE_STATE);
  211. sync = !!(lane_status & (1 << MDIO_PHYXS_LANE_ALIGNED_LBN));
  212. if (!sync)
  213. EFX_LOG(efx, "XGXS lane status: %x\n", lane_status);
  214. return sync;
  215. }
  216. extern const char *mdio_clause45_mmd_name(int mmd);
  217. /*
  218. * Reset a specific MMD and wait for reset to clear.
  219. * Return number of spins left (>0) on success, -%ETIMEDOUT on failure.
  220. *
  221. * This function will sleep
  222. */
  223. extern int mdio_clause45_reset_mmd(struct efx_nic *efx, int mmd,
  224. int spins, int spintime);
  225. /* As mdio_clause45_check_mmd but for multiple MMDs */
  226. int mdio_clause45_check_mmds(struct efx_nic *efx,
  227. unsigned int mmd_mask, unsigned int fatal_mask);
  228. /* Check the link status of specified mmds in bit mask */
  229. extern bool mdio_clause45_links_ok(struct efx_nic *efx,
  230. unsigned int mmd_mask);
  231. /* Generic transmit disable support though PMAPMD */
  232. extern void mdio_clause45_transmit_disable(struct efx_nic *efx);
  233. /* Generic part of reconfigure: set/clear loopback bits */
  234. extern void mdio_clause45_phy_reconfigure(struct efx_nic *efx);
  235. /* Set the power state of the specified MMDs */
  236. extern void mdio_clause45_set_mmds_lpower(struct efx_nic *efx,
  237. int low_power, unsigned int mmd_mask);
  238. /* Read (some of) the PHY settings over MDIO */
  239. extern void mdio_clause45_get_settings(struct efx_nic *efx,
  240. struct ethtool_cmd *ecmd);
  241. /* Read (some of) the PHY settings over MDIO */
  242. extern void
  243. mdio_clause45_get_settings_ext(struct efx_nic *efx, struct ethtool_cmd *ecmd,
  244. u32 xnp, u32 xnp_lpa);
  245. /* Set (some of) the PHY settings over MDIO */
  246. extern int mdio_clause45_set_settings(struct efx_nic *efx,
  247. struct ethtool_cmd *ecmd);
  248. /* Set pause parameters to be advertised through AN (if available) */
  249. extern void mdio_clause45_set_pause(struct efx_nic *efx);
  250. /* Get pause parameters from AN if available (otherwise return
  251. * requested pause parameters)
  252. */
  253. enum efx_fc_type mdio_clause45_get_pause(struct efx_nic *efx);
  254. /* Wait for specified MMDs to exit reset within a timeout */
  255. extern int mdio_clause45_wait_reset_mmds(struct efx_nic *efx,
  256. unsigned int mmd_mask);
  257. /* Set or clear flag, debouncing */
  258. extern void mdio_clause45_set_flag(struct efx_nic *efx, u8 prt, u8 dev,
  259. u16 addr, int bit, bool sense);
  260. #endif /* EFX_MDIO_10G_H */