mdio.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * linux/mdio.h: definitions for MDIO (clause 45) transceivers
  4. * Copyright 2006-2009 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #ifndef _UAPI__LINUX_MDIO_H__
  11. #define _UAPI__LINUX_MDIO_H__
  12. #include <linux/types.h>
  13. #include <linux/mii.h>
  14. /* MDIO Manageable Devices (MMDs). */
  15. #define MDIO_MMD_PMAPMD 1 /* Physical Medium Attachment/
  16. * Physical Medium Dependent */
  17. #define MDIO_MMD_WIS 2 /* WAN Interface Sublayer */
  18. #define MDIO_MMD_PCS 3 /* Physical Coding Sublayer */
  19. #define MDIO_MMD_PHYXS 4 /* PHY Extender Sublayer */
  20. #define MDIO_MMD_DTEXS 5 /* DTE Extender Sublayer */
  21. #define MDIO_MMD_TC 6 /* Transmission Convergence */
  22. #define MDIO_MMD_AN 7 /* Auto-Negotiation */
  23. #define MDIO_MMD_C22EXT 29 /* Clause 22 extension */
  24. #define MDIO_MMD_VEND1 30 /* Vendor specific 1 */
  25. #define MDIO_MMD_VEND2 31 /* Vendor specific 2 */
  26. /* Generic MDIO registers. */
  27. #define MDIO_CTRL1 MII_BMCR
  28. #define MDIO_STAT1 MII_BMSR
  29. #define MDIO_DEVID1 MII_PHYSID1
  30. #define MDIO_DEVID2 MII_PHYSID2
  31. #define MDIO_SPEED 4 /* Speed ability */
  32. #define MDIO_DEVS1 5 /* Devices in package */
  33. #define MDIO_DEVS2 6
  34. #define MDIO_CTRL2 7 /* 10G control 2 */
  35. #define MDIO_STAT2 8 /* 10G status 2 */
  36. #define MDIO_PMA_TXDIS 9 /* 10G PMA/PMD transmit disable */
  37. #define MDIO_PMA_RXDET 10 /* 10G PMA/PMD receive signal detect */
  38. #define MDIO_PMA_EXTABLE 11 /* 10G PMA/PMD extended ability */
  39. #define MDIO_PKGID1 14 /* Package identifier */
  40. #define MDIO_PKGID2 15
  41. #define MDIO_AN_ADVERTISE 16 /* AN advertising (base page) */
  42. #define MDIO_AN_LPA 19 /* AN LP abilities (base page) */
  43. #define MDIO_PCS_EEE_ABLE 20 /* EEE Capability register */
  44. #define MDIO_PCS_EEE_WK_ERR 22 /* EEE wake error counter */
  45. #define MDIO_PHYXS_LNSTAT 24 /* PHY XGXS lane state */
  46. #define MDIO_AN_EEE_ADV 60 /* EEE advertisement */
  47. #define MDIO_AN_EEE_LPABLE 61 /* EEE link partner ability */
  48. /* Media-dependent registers. */
  49. #define MDIO_PMA_10GBT_SWAPPOL 130 /* 10GBASE-T pair swap & polarity */
  50. #define MDIO_PMA_10GBT_TXPWR 131 /* 10GBASE-T TX power control */
  51. #define MDIO_PMA_10GBT_SNR 133 /* 10GBASE-T SNR margin, lane A.
  52. * Lanes B-D are numbered 134-136. */
  53. #define MDIO_PMA_10GBR_FECABLE 170 /* 10GBASE-R FEC ability */
  54. #define MDIO_PCS_10GBX_STAT1 24 /* 10GBASE-X PCS status 1 */
  55. #define MDIO_PCS_10GBRT_STAT1 32 /* 10GBASE-R/-T PCS status 1 */
  56. #define MDIO_PCS_10GBRT_STAT2 33 /* 10GBASE-R/-T PCS status 2 */
  57. #define MDIO_AN_10GBT_CTRL 32 /* 10GBASE-T auto-negotiation control */
  58. #define MDIO_AN_10GBT_STAT 33 /* 10GBASE-T auto-negotiation status */
  59. /* LASI (Link Alarm Status Interrupt) registers, defined by XENPAK MSA. */
  60. #define MDIO_PMA_LASI_RXCTRL 0x9000 /* RX_ALARM control */
  61. #define MDIO_PMA_LASI_TXCTRL 0x9001 /* TX_ALARM control */
  62. #define MDIO_PMA_LASI_CTRL 0x9002 /* LASI control */
  63. #define MDIO_PMA_LASI_RXSTAT 0x9003 /* RX_ALARM status */
  64. #define MDIO_PMA_LASI_TXSTAT 0x9004 /* TX_ALARM status */
  65. #define MDIO_PMA_LASI_STAT 0x9005 /* LASI status */
  66. /* Control register 1. */
  67. /* Enable extended speed selection */
  68. #define MDIO_CTRL1_SPEEDSELEXT (BMCR_SPEED1000 | BMCR_SPEED100)
  69. /* All speed selection bits */
  70. #define MDIO_CTRL1_SPEEDSEL (MDIO_CTRL1_SPEEDSELEXT | 0x003c)
  71. #define MDIO_CTRL1_FULLDPLX BMCR_FULLDPLX
  72. #define MDIO_CTRL1_LPOWER BMCR_PDOWN
  73. #define MDIO_CTRL1_RESET BMCR_RESET
  74. #define MDIO_PMA_CTRL1_LOOPBACK 0x0001
  75. #define MDIO_PMA_CTRL1_SPEED1000 BMCR_SPEED1000
  76. #define MDIO_PMA_CTRL1_SPEED100 BMCR_SPEED100
  77. #define MDIO_PCS_CTRL1_LOOPBACK BMCR_LOOPBACK
  78. #define MDIO_PHYXS_CTRL1_LOOPBACK BMCR_LOOPBACK
  79. #define MDIO_AN_CTRL1_RESTART BMCR_ANRESTART
  80. #define MDIO_AN_CTRL1_ENABLE BMCR_ANENABLE
  81. #define MDIO_AN_CTRL1_XNP 0x2000 /* Enable extended next page */
  82. #define MDIO_PCS_CTRL1_CLKSTOP_EN 0x400 /* Stop the clock during LPI */
  83. /* 10 Gb/s */
  84. #define MDIO_CTRL1_SPEED10G (MDIO_CTRL1_SPEEDSELEXT | 0x00)
  85. /* 10PASS-TS/2BASE-TL */
  86. #define MDIO_CTRL1_SPEED10P2B (MDIO_CTRL1_SPEEDSELEXT | 0x04)
  87. /* Status register 1. */
  88. #define MDIO_STAT1_LPOWERABLE 0x0002 /* Low-power ability */
  89. #define MDIO_STAT1_LSTATUS BMSR_LSTATUS
  90. #define MDIO_STAT1_FAULT 0x0080 /* Fault */
  91. #define MDIO_AN_STAT1_LPABLE 0x0001 /* Link partner AN ability */
  92. #define MDIO_AN_STAT1_ABLE BMSR_ANEGCAPABLE
  93. #define MDIO_AN_STAT1_RFAULT BMSR_RFAULT
  94. #define MDIO_AN_STAT1_COMPLETE BMSR_ANEGCOMPLETE
  95. #define MDIO_AN_STAT1_PAGE 0x0040 /* Page received */
  96. #define MDIO_AN_STAT1_XNP 0x0080 /* Extended next page status */
  97. /* Speed register. */
  98. #define MDIO_SPEED_10G 0x0001 /* 10G capable */
  99. #define MDIO_PMA_SPEED_2B 0x0002 /* 2BASE-TL capable */
  100. #define MDIO_PMA_SPEED_10P 0x0004 /* 10PASS-TS capable */
  101. #define MDIO_PMA_SPEED_1000 0x0010 /* 1000M capable */
  102. #define MDIO_PMA_SPEED_100 0x0020 /* 100M capable */
  103. #define MDIO_PMA_SPEED_10 0x0040 /* 10M capable */
  104. #define MDIO_PCS_SPEED_10P2B 0x0002 /* 10PASS-TS/2BASE-TL capable */
  105. /* Device present registers. */
  106. #define MDIO_DEVS_PRESENT(devad) (1 << (devad))
  107. #define MDIO_DEVS_PMAPMD MDIO_DEVS_PRESENT(MDIO_MMD_PMAPMD)
  108. #define MDIO_DEVS_WIS MDIO_DEVS_PRESENT(MDIO_MMD_WIS)
  109. #define MDIO_DEVS_PCS MDIO_DEVS_PRESENT(MDIO_MMD_PCS)
  110. #define MDIO_DEVS_PHYXS MDIO_DEVS_PRESENT(MDIO_MMD_PHYXS)
  111. #define MDIO_DEVS_DTEXS MDIO_DEVS_PRESENT(MDIO_MMD_DTEXS)
  112. #define MDIO_DEVS_TC MDIO_DEVS_PRESENT(MDIO_MMD_TC)
  113. #define MDIO_DEVS_AN MDIO_DEVS_PRESENT(MDIO_MMD_AN)
  114. #define MDIO_DEVS_C22EXT MDIO_DEVS_PRESENT(MDIO_MMD_C22EXT)
  115. /* Control register 2. */
  116. #define MDIO_PMA_CTRL2_TYPE 0x000f /* PMA/PMD type selection */
  117. #define MDIO_PMA_CTRL2_10GBCX4 0x0000 /* 10GBASE-CX4 type */
  118. #define MDIO_PMA_CTRL2_10GBEW 0x0001 /* 10GBASE-EW type */
  119. #define MDIO_PMA_CTRL2_10GBLW 0x0002 /* 10GBASE-LW type */
  120. #define MDIO_PMA_CTRL2_10GBSW 0x0003 /* 10GBASE-SW type */
  121. #define MDIO_PMA_CTRL2_10GBLX4 0x0004 /* 10GBASE-LX4 type */
  122. #define MDIO_PMA_CTRL2_10GBER 0x0005 /* 10GBASE-ER type */
  123. #define MDIO_PMA_CTRL2_10GBLR 0x0006 /* 10GBASE-LR type */
  124. #define MDIO_PMA_CTRL2_10GBSR 0x0007 /* 10GBASE-SR type */
  125. #define MDIO_PMA_CTRL2_10GBLRM 0x0008 /* 10GBASE-LRM type */
  126. #define MDIO_PMA_CTRL2_10GBT 0x0009 /* 10GBASE-T type */
  127. #define MDIO_PMA_CTRL2_10GBKX4 0x000a /* 10GBASE-KX4 type */
  128. #define MDIO_PMA_CTRL2_10GBKR 0x000b /* 10GBASE-KR type */
  129. #define MDIO_PMA_CTRL2_1000BT 0x000c /* 1000BASE-T type */
  130. #define MDIO_PMA_CTRL2_1000BKX 0x000d /* 1000BASE-KX type */
  131. #define MDIO_PMA_CTRL2_100BTX 0x000e /* 100BASE-TX type */
  132. #define MDIO_PMA_CTRL2_10BT 0x000f /* 10BASE-T type */
  133. #define MDIO_PCS_CTRL2_TYPE 0x0003 /* PCS type selection */
  134. #define MDIO_PCS_CTRL2_10GBR 0x0000 /* 10GBASE-R type */
  135. #define MDIO_PCS_CTRL2_10GBX 0x0001 /* 10GBASE-X type */
  136. #define MDIO_PCS_CTRL2_10GBW 0x0002 /* 10GBASE-W type */
  137. #define MDIO_PCS_CTRL2_10GBT 0x0003 /* 10GBASE-T type */
  138. /* Status register 2. */
  139. #define MDIO_STAT2_RXFAULT 0x0400 /* Receive fault */
  140. #define MDIO_STAT2_TXFAULT 0x0800 /* Transmit fault */
  141. #define MDIO_STAT2_DEVPRST 0xc000 /* Device present */
  142. #define MDIO_STAT2_DEVPRST_VAL 0x8000 /* Device present value */
  143. #define MDIO_PMA_STAT2_LBABLE 0x0001 /* PMA loopback ability */
  144. #define MDIO_PMA_STAT2_10GBEW 0x0002 /* 10GBASE-EW ability */
  145. #define MDIO_PMA_STAT2_10GBLW 0x0004 /* 10GBASE-LW ability */
  146. #define MDIO_PMA_STAT2_10GBSW 0x0008 /* 10GBASE-SW ability */
  147. #define MDIO_PMA_STAT2_10GBLX4 0x0010 /* 10GBASE-LX4 ability */
  148. #define MDIO_PMA_STAT2_10GBER 0x0020 /* 10GBASE-ER ability */
  149. #define MDIO_PMA_STAT2_10GBLR 0x0040 /* 10GBASE-LR ability */
  150. #define MDIO_PMA_STAT2_10GBSR 0x0080 /* 10GBASE-SR ability */
  151. #define MDIO_PMD_STAT2_TXDISAB 0x0100 /* PMD TX disable ability */
  152. #define MDIO_PMA_STAT2_EXTABLE 0x0200 /* Extended abilities */
  153. #define MDIO_PMA_STAT2_RXFLTABLE 0x1000 /* Receive fault ability */
  154. #define MDIO_PMA_STAT2_TXFLTABLE 0x2000 /* Transmit fault ability */
  155. #define MDIO_PCS_STAT2_10GBR 0x0001 /* 10GBASE-R capable */
  156. #define MDIO_PCS_STAT2_10GBX 0x0002 /* 10GBASE-X capable */
  157. #define MDIO_PCS_STAT2_10GBW 0x0004 /* 10GBASE-W capable */
  158. #define MDIO_PCS_STAT2_RXFLTABLE 0x1000 /* Receive fault ability */
  159. #define MDIO_PCS_STAT2_TXFLTABLE 0x2000 /* Transmit fault ability */
  160. /* Transmit disable register. */
  161. #define MDIO_PMD_TXDIS_GLOBAL 0x0001 /* Global PMD TX disable */
  162. #define MDIO_PMD_TXDIS_0 0x0002 /* PMD TX disable 0 */
  163. #define MDIO_PMD_TXDIS_1 0x0004 /* PMD TX disable 1 */
  164. #define MDIO_PMD_TXDIS_2 0x0008 /* PMD TX disable 2 */
  165. #define MDIO_PMD_TXDIS_3 0x0010 /* PMD TX disable 3 */
  166. /* Receive signal detect register. */
  167. #define MDIO_PMD_RXDET_GLOBAL 0x0001 /* Global PMD RX signal detect */
  168. #define MDIO_PMD_RXDET_0 0x0002 /* PMD RX signal detect 0 */
  169. #define MDIO_PMD_RXDET_1 0x0004 /* PMD RX signal detect 1 */
  170. #define MDIO_PMD_RXDET_2 0x0008 /* PMD RX signal detect 2 */
  171. #define MDIO_PMD_RXDET_3 0x0010 /* PMD RX signal detect 3 */
  172. /* Extended abilities register. */
  173. #define MDIO_PMA_EXTABLE_10GCX4 0x0001 /* 10GBASE-CX4 ability */
  174. #define MDIO_PMA_EXTABLE_10GBLRM 0x0002 /* 10GBASE-LRM ability */
  175. #define MDIO_PMA_EXTABLE_10GBT 0x0004 /* 10GBASE-T ability */
  176. #define MDIO_PMA_EXTABLE_10GBKX4 0x0008 /* 10GBASE-KX4 ability */
  177. #define MDIO_PMA_EXTABLE_10GBKR 0x0010 /* 10GBASE-KR ability */
  178. #define MDIO_PMA_EXTABLE_1000BT 0x0020 /* 1000BASE-T ability */
  179. #define MDIO_PMA_EXTABLE_1000BKX 0x0040 /* 1000BASE-KX ability */
  180. #define MDIO_PMA_EXTABLE_100BTX 0x0080 /* 100BASE-TX ability */
  181. #define MDIO_PMA_EXTABLE_10BT 0x0100 /* 10BASE-T ability */
  182. /* PHY XGXS lane state register. */
  183. #define MDIO_PHYXS_LNSTAT_SYNC0 0x0001
  184. #define MDIO_PHYXS_LNSTAT_SYNC1 0x0002
  185. #define MDIO_PHYXS_LNSTAT_SYNC2 0x0004
  186. #define MDIO_PHYXS_LNSTAT_SYNC3 0x0008
  187. #define MDIO_PHYXS_LNSTAT_ALIGN 0x1000
  188. /* PMA 10GBASE-T pair swap & polarity */
  189. #define MDIO_PMA_10GBT_SWAPPOL_ABNX 0x0001 /* Pair A/B uncrossed */
  190. #define MDIO_PMA_10GBT_SWAPPOL_CDNX 0x0002 /* Pair C/D uncrossed */
  191. #define MDIO_PMA_10GBT_SWAPPOL_AREV 0x0100 /* Pair A polarity reversed */
  192. #define MDIO_PMA_10GBT_SWAPPOL_BREV 0x0200 /* Pair B polarity reversed */
  193. #define MDIO_PMA_10GBT_SWAPPOL_CREV 0x0400 /* Pair C polarity reversed */
  194. #define MDIO_PMA_10GBT_SWAPPOL_DREV 0x0800 /* Pair D polarity reversed */
  195. /* PMA 10GBASE-T TX power register. */
  196. #define MDIO_PMA_10GBT_TXPWR_SHORT 0x0001 /* Short-reach mode */
  197. /* PMA 10GBASE-T SNR registers. */
  198. /* Value is SNR margin in dB, clamped to range [-127, 127], plus 0x8000. */
  199. #define MDIO_PMA_10GBT_SNR_BIAS 0x8000
  200. #define MDIO_PMA_10GBT_SNR_MAX 127
  201. /* PMA 10GBASE-R FEC ability register. */
  202. #define MDIO_PMA_10GBR_FECABLE_ABLE 0x0001 /* FEC ability */
  203. #define MDIO_PMA_10GBR_FECABLE_ERRABLE 0x0002 /* FEC error indic. ability */
  204. /* PCS 10GBASE-R/-T status register 1. */
  205. #define MDIO_PCS_10GBRT_STAT1_BLKLK 0x0001 /* Block lock attained */
  206. /* PCS 10GBASE-R/-T status register 2. */
  207. #define MDIO_PCS_10GBRT_STAT2_ERR 0x00ff
  208. #define MDIO_PCS_10GBRT_STAT2_BER 0x3f00
  209. /* AN 10GBASE-T control register. */
  210. #define MDIO_AN_10GBT_CTRL_ADV10G 0x1000 /* Advertise 10GBASE-T */
  211. /* AN 10GBASE-T status register. */
  212. #define MDIO_AN_10GBT_STAT_LPTRR 0x0200 /* LP training reset req. */
  213. #define MDIO_AN_10GBT_STAT_LPLTABLE 0x0400 /* LP loop timing ability */
  214. #define MDIO_AN_10GBT_STAT_LP10G 0x0800 /* LP is 10GBT capable */
  215. #define MDIO_AN_10GBT_STAT_REMOK 0x1000 /* Remote OK */
  216. #define MDIO_AN_10GBT_STAT_LOCOK 0x2000 /* Local OK */
  217. #define MDIO_AN_10GBT_STAT_MS 0x4000 /* Master/slave config */
  218. #define MDIO_AN_10GBT_STAT_MSFLT 0x8000 /* Master/slave config fault */
  219. /* EEE Supported/Advertisement/LP Advertisement registers.
  220. *
  221. * EEE capability Register (3.20), Advertisement (7.60) and
  222. * Link partner ability (7.61) registers have and can use the same identical
  223. * bit masks.
  224. */
  225. #define MDIO_AN_EEE_ADV_100TX 0x0002 /* Advertise 100TX EEE cap */
  226. #define MDIO_AN_EEE_ADV_1000T 0x0004 /* Advertise 1000T EEE cap */
  227. /* Note: the two defines above can be potentially used by the user-land
  228. * and cannot remove them now.
  229. * So, we define the new generic MDIO_EEE_100TX and MDIO_EEE_1000T macros
  230. * using the previous ones (that can be considered obsolete).
  231. */
  232. #define MDIO_EEE_100TX MDIO_AN_EEE_ADV_100TX /* 100TX EEE cap */
  233. #define MDIO_EEE_1000T MDIO_AN_EEE_ADV_1000T /* 1000T EEE cap */
  234. #define MDIO_EEE_10GT 0x0008 /* 10GT EEE cap */
  235. #define MDIO_EEE_1000KX 0x0010 /* 1000KX EEE cap */
  236. #define MDIO_EEE_10GKX4 0x0020 /* 10G KX4 EEE cap */
  237. #define MDIO_EEE_10GKR 0x0040 /* 10G KR EEE cap */
  238. /* LASI RX_ALARM control/status registers. */
  239. #define MDIO_PMA_LASI_RX_PHYXSLFLT 0x0001 /* PHY XS RX local fault */
  240. #define MDIO_PMA_LASI_RX_PCSLFLT 0x0008 /* PCS RX local fault */
  241. #define MDIO_PMA_LASI_RX_PMALFLT 0x0010 /* PMA/PMD RX local fault */
  242. #define MDIO_PMA_LASI_RX_OPTICPOWERFLT 0x0020 /* RX optical power fault */
  243. #define MDIO_PMA_LASI_RX_WISLFLT 0x0200 /* WIS local fault */
  244. /* LASI TX_ALARM control/status registers. */
  245. #define MDIO_PMA_LASI_TX_PHYXSLFLT 0x0001 /* PHY XS TX local fault */
  246. #define MDIO_PMA_LASI_TX_PCSLFLT 0x0008 /* PCS TX local fault */
  247. #define MDIO_PMA_LASI_TX_PMALFLT 0x0010 /* PMA/PMD TX local fault */
  248. #define MDIO_PMA_LASI_TX_LASERPOWERFLT 0x0080 /* Laser output power fault */
  249. #define MDIO_PMA_LASI_TX_LASERTEMPFLT 0x0100 /* Laser temperature fault */
  250. #define MDIO_PMA_LASI_TX_LASERBICURRFLT 0x0200 /* Laser bias current fault */
  251. /* LASI control/status registers. */
  252. #define MDIO_PMA_LASI_LSALARM 0x0001 /* LS_ALARM enable/status */
  253. #define MDIO_PMA_LASI_TXALARM 0x0002 /* TX_ALARM enable/status */
  254. #define MDIO_PMA_LASI_RXALARM 0x0004 /* RX_ALARM enable/status */
  255. /* Mapping between MDIO PRTAD/DEVAD and mii_ioctl_data::phy_id */
  256. #define MDIO_PHY_ID_C45 0x8000
  257. #define MDIO_PHY_ID_PRTAD 0x03e0
  258. #define MDIO_PHY_ID_DEVAD 0x001f
  259. #define MDIO_PHY_ID_C45_MASK \
  260. (MDIO_PHY_ID_C45 | MDIO_PHY_ID_PRTAD | MDIO_PHY_ID_DEVAD)
  261. static inline __u16 mdio_phy_id_c45(int prtad, int devad)
  262. {
  263. return MDIO_PHY_ID_C45 | (prtad << 5) | devad;
  264. }
  265. #endif /* _UAPI__LINUX_MDIO_H__ */