sunxi_hal_mii.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Copyright (c) 2019-2025 Allwinner Technology Co., Ltd. ALL rights reserved.
  3. *
  4. * Allwinner is a trademark of Allwinner Technology Co.,Ltd., registered in
  5. * the the People's Republic of China and other countries.
  6. * All Allwinner Technology Co.,Ltd. trademarks are used with permission.
  7. *
  8. * DISCLAIMER
  9. * THIRD PARTY LICENCES MAY BE REQUIRED TO IMPLEMENT THE SOLUTION/PRODUCT.
  10. * IF YOU NEED TO INTEGRATE THIRD PARTY’S TECHNOLOGY (SONY, DTS, DOLBY, AVS OR MPEGLA, ETC.)
  11. * IN ALLWINNERS’SDK OR PRODUCTS, YOU SHALL BE SOLELY RESPONSIBLE TO OBTAIN
  12. * ALL APPROPRIATELY REQUIRED THIRD PARTY LICENCES.
  13. * ALLWINNER SHALL HAVE NO WARRANTY, INDEMNITY OR OTHER OBLIGATIONS WITH RESPECT TO MATTERS
  14. * COVERED UNDER ANY REQUIRED THIRD PARTY LICENSE.
  15. * YOU ARE SOLELY RESPONSIBLE FOR YOUR USAGE OF THIRD PARTY’S TECHNOLOGY.
  16. *
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY ALLWINNER"AS IS" AND TO THE MAXIMUM EXTENT
  19. * PERMITTED BY LAW, ALLWINNER EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND,
  20. * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION REGARDING
  21. * THE TITLE, NON-INFRINGEMENT, ACCURACY, CONDITION, COMPLETENESS, PERFORMANCE
  22. * OR MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  23. * IN NO EVENT SHALL ALLWINNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS, OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  28. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  30. * OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef __SUNXI_HAL_MII_H__
  33. #define __SUNXI_HAL_MII_H__
  34. /* Generic MII registers. */
  35. #define MII_BMCR 0x00 /* Basic mode control register */
  36. #define MII_BMSR 0x01 /* Basic mode status register */
  37. #define MII_PHYSID1 0x02 /* PHYS ID 1 */
  38. #define MII_PHYSID2 0x03 /* PHYS ID 2 */
  39. #define MII_ADVERTISE 0x04 /* Advertisement control reg */
  40. #define MII_LPA 0x05 /* Link partner ability reg */
  41. #define MII_EXPANSION 0x06 /* Expansion register */
  42. #define MII_CTRL1000 0x09 /* 1000BASE-T control */
  43. #define MII_STAT1000 0x0a /* 1000BASE-T status */
  44. #define MII_ESTATUS 0x0f /* Extended Status */
  45. #define MII_DCOUNTER 0x12 /* Disconnect counter */
  46. #define MII_FCSCOUNTER 0x13 /* False carrier counter */
  47. #define MII_NWAYTEST 0x14 /* N-way auto-neg test reg */
  48. #define MII_RERRCOUNTER 0x15 /* Receive error counter */
  49. #define MII_SREVISION 0x16 /* Silicon revision */
  50. #define MII_RESV1 0x17 /* Reserved... */
  51. #define MII_LBRERROR 0x18 /* Lpback, rx, bypass error */
  52. #define MII_PHYADDR 0x19 /* PHY address */
  53. #define MII_RESV2 0x1a /* Reserved... */
  54. #define MII_TPISTATUS 0x1b /* TPI status for 10mbps */
  55. #define MII_NCONFIG 0x1c /* Network interface config */
  56. /* Basic mode control register. */
  57. #define BMCR_RESV 0x003f /* Unused... */
  58. #define BMCR_SPEED1000 0x0040 /* MSB of Speed (1000) */
  59. #define BMCR_CTST 0x0080 /* Collision test */
  60. #define BMCR_FULLDPLX 0x0100 /* Full duplex */
  61. #define BMCR_ANRESTART 0x0200 /* Auto negotiation restart */
  62. #define BMCR_ISOLATE 0x0400 /* Disconnect DP83840 from MII */
  63. #define BMCR_PDOWN 0x0800 /* Powerdown the DP83840 */
  64. #define BMCR_ANENABLE 0x1000 /* Enable auto negotiation */
  65. #define BMCR_SPEED100 0x2000 /* Select 100Mbps */
  66. #define BMCR_LOOPBACK 0x4000 /* TXD loopback bits */
  67. #define BMCR_RESET 0x8000 /* Reset the DP83840 */
  68. /* Basic mode status register. */
  69. #define BMSR_ERCAP 0x0001 /* Ext-reg capability */
  70. #define BMSR_JCD 0x0002 /* Jabber detected */
  71. #define BMSR_LSTATUS 0x0004 /* Link status */
  72. #define BMSR_ANEGCAPABLE 0x0008 /* Able to do auto-negotiation */
  73. #define BMSR_RFAULT 0x0010 /* Remote fault detected */
  74. #define BMSR_ANEGCOMPLETE 0x0020 /* Auto-negotiation complete */
  75. #define BMSR_RESV 0x00c0 /* Unused... */
  76. #define BMSR_ESTATEN 0x0100 /* Extended Status in R15 */
  77. #define BMSR_100HALF2 0x0200 /* Can do 100BASE-T2 HDX */
  78. #define BMSR_100FULL2 0x0400 /* Can do 100BASE-T2 FDX */
  79. #define BMSR_10HALF 0x0800 /* Can do 10mbps, half-duplex */
  80. #define BMSR_10FULL 0x1000 /* Can do 10mbps, full-duplex */
  81. #define BMSR_100HALF 0x2000 /* Can do 100mbps, half-duplex */
  82. #define BMSR_100FULL 0x4000 /* Can do 100mbps, full-duplex */
  83. #define BMSR_100BASE4 0x8000 /* Can do 100mbps, 4k packets */
  84. /* Advertisement control register. */
  85. #define ADVERTISE_SLCT 0x001f /* Selector bits */
  86. #define ADVERTISE_CSMA 0x0001 /* Only selector supported */
  87. #define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
  88. #define ADVERTISE_1000XFULL 0x0020 /* Try for 1000BASE-X full-duplex */
  89. #define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
  90. #define ADVERTISE_1000XHALF 0x0040 /* Try for 1000BASE-X half-duplex */
  91. #define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
  92. #define ADVERTISE_1000XPAUSE 0x0080 /* Try for 1000BASE-X pause */
  93. #define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
  94. #define ADVERTISE_1000XPSE_ASYM 0x0100 /* Try for 1000BASE-X asym pause */
  95. #define ADVERTISE_100BASE4 0x0200 /* Try for 100mbps 4k packets */
  96. #define ADVERTISE_PAUSE_CAP 0x0400 /* Try for pause */
  97. #define ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymetric pause */
  98. #define ADVERTISE_RESV 0x1000 /* Unused... */
  99. #define ADVERTISE_RFAULT 0x2000 /* Say we can detect faults */
  100. #define ADVERTISE_LPACK 0x4000 /* Ack link partners response */
  101. #define ADVERTISE_NPAGE 0x8000 /* Next page bit */
  102. #define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
  103. ADVERTISE_CSMA)
  104. #define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  105. ADVERTISE_100HALF | ADVERTISE_100FULL)
  106. /* Link partner ability register. */
  107. #define LPA_SLCT 0x001f /* Same as advertise selector */
  108. #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
  109. #define LPA_1000XFULL 0x0020 /* Can do 1000BASE-X full-duplex */
  110. #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
  111. #define LPA_1000XHALF 0x0040 /* Can do 1000BASE-X half-duplex */
  112. #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
  113. #define LPA_1000XPAUSE 0x0080 /* Can do 1000BASE-X pause */
  114. #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
  115. #define LPA_1000XPAUSE_ASYM 0x0100 /* Can do 1000BASE-X pause asym*/
  116. #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
  117. #define LPA_PAUSE_CAP 0x0400 /* Can pause */
  118. #define LPA_PAUSE_ASYM 0x0800 /* Can pause asymetrically */
  119. #define LPA_RESV 0x1000 /* Unused... */
  120. #define LPA_RFAULT 0x2000 /* Link partner faulted */
  121. #define LPA_LPACK 0x4000 /* Link partner acked us */
  122. #define LPA_NPAGE 0x8000 /* Next page bit */
  123. #define LPA_DUPLEX (LPA_10FULL | LPA_100FULL)
  124. #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
  125. /* Expansion register for auto-negotiation. */
  126. #define EXPANSION_NWAY 0x0001 /* Can do N-way auto-nego */
  127. #define EXPANSION_LCWP 0x0002 /* Got new RX page code word */
  128. #define EXPANSION_ENABLENPAGE 0x0004 /* This enables npage words */
  129. #define EXPANSION_NPCAPABLE 0x0008 /* Link partner supports npage */
  130. #define EXPANSION_MFAULTS 0x0010 /* Multiple faults detected */
  131. #define EXPANSION_RESV 0xffe0 /* Unused... */
  132. #define ESTATUS_1000_XFULL 0x8000 /* Can do 1000BX Full */
  133. #define ESTATUS_1000_XHALF 0x4000 /* Can do 1000BX Half */
  134. #define ESTATUS_1000_TFULL 0x2000 /* Can do 1000BT Full */
  135. #define ESTATUS_1000_THALF 0x1000 /* Can do 1000BT Half */
  136. /* N-way test register. */
  137. #define NWAYTEST_RESV1 0x00ff /* Unused... */
  138. #define NWAYTEST_LOOPBACK 0x0100 /* Enable loopback for N-way */
  139. #define NWAYTEST_RESV2 0xfe00 /* Unused... */
  140. /* 1000BASE-T Control register */
  141. #define ADVERTISE_1000FULL 0x0200 /* Advertise 1000BASE-T full duplex */
  142. #define ADVERTISE_1000HALF 0x0100 /* Advertise 1000BASE-T half duplex */
  143. /* 1000BASE-T Status register */
  144. #define LPA_1000LOCALRXOK 0x2000 /* Link partner local receiver status */
  145. #define LPA_1000REMRXOK 0x1000 /* Link partner remote receiver status */
  146. #define LPA_1000FULL 0x0800 /* Link partner 1000BASE-T full duplex */
  147. #define LPA_1000HALF 0x0400 /* Link partner 1000BASE-T half duplex */
  148. /* Flow control flags */
  149. #define FLOW_CTRL_TX 0x01
  150. #define FLOW_CTRL_RX 0x02
  151. /**
  152. * mii_nway_result
  153. * @negotiated: value of MII ANAR and'd with ANLPAR
  154. *
  155. * Given a set of MII abilities, check each bit and returns the
  156. * currently supported media, in the priority order defined by
  157. * IEEE 802.3u. We use LPA_xxx constants but note this is not the
  158. * value of LPA solely, as described above.
  159. *
  160. * The one exception to IEEE 802.3u is that 100baseT4 is placed
  161. * between 100T-full and 100T-half. If your phy does not support
  162. * 100T4 this is fine. If your phy places 100T4 elsewhere in the
  163. * priority order, you will need to roll your own function.
  164. */
  165. static inline unsigned int mii_nway_result (unsigned int negotiated)
  166. {
  167. unsigned int ret;
  168. if (negotiated & LPA_100FULL)
  169. ret = LPA_100FULL;
  170. else if (negotiated & LPA_100BASE4)
  171. ret = LPA_100BASE4;
  172. else if (negotiated & LPA_100HALF)
  173. ret = LPA_100HALF;
  174. else if (negotiated & LPA_10FULL)
  175. ret = LPA_10FULL;
  176. else
  177. ret = LPA_10HALF;
  178. return ret;
  179. }
  180. /**
  181. * mii_duplex
  182. * @duplex_lock: Non-zero if duplex is locked at full
  183. * @negotiated: value of MII ANAR and'd with ANLPAR
  184. *
  185. * A small helper function for a common case. Returns one
  186. * if the media is operating or locked at full duplex, and
  187. * returns zero otherwise.
  188. */
  189. static inline unsigned int mii_duplex (unsigned int duplex_lock,
  190. unsigned int negotiated)
  191. {
  192. if (duplex_lock)
  193. return 1;
  194. if (mii_nway_result(negotiated) & LPA_DUPLEX)
  195. return 1;
  196. return 0;
  197. }
  198. #endif /* __SUNXI_HAL_MII_H__ */