gmii.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006 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 EFX_GMII_H
  11. #define EFX_GMII_H
  12. /*
  13. * GMII interface
  14. */
  15. #include <linux/mii.h>
  16. /* GMII registers, excluding registers already defined as MII
  17. * registers in mii.h
  18. */
  19. #define GMII_IER 0x12 /* Interrupt enable register */
  20. #define GMII_ISR 0x13 /* Interrupt status register */
  21. /* Interrupt enable register */
  22. #define IER_ANEG_ERR 0x8000 /* Bit 15 - autonegotiation error */
  23. #define IER_SPEED_CHG 0x4000 /* Bit 14 - speed changed */
  24. #define IER_DUPLEX_CHG 0x2000 /* Bit 13 - duplex changed */
  25. #define IER_PAGE_RCVD 0x1000 /* Bit 12 - page received */
  26. #define IER_ANEG_DONE 0x0800 /* Bit 11 - autonegotiation complete */
  27. #define IER_LINK_CHG 0x0400 /* Bit 10 - link status changed */
  28. #define IER_SYM_ERR 0x0200 /* Bit 9 - symbol error */
  29. #define IER_FALSE_CARRIER 0x0100 /* Bit 8 - false carrier */
  30. #define IER_FIFO_ERR 0x0080 /* Bit 7 - FIFO over/underflow */
  31. #define IER_MDIX_CHG 0x0040 /* Bit 6 - MDI crossover changed */
  32. #define IER_DOWNSHIFT 0x0020 /* Bit 5 - downshift */
  33. #define IER_ENERGY 0x0010 /* Bit 4 - energy detect */
  34. #define IER_DTE_POWER 0x0004 /* Bit 2 - DTE power detect */
  35. #define IER_POLARITY_CHG 0x0002 /* Bit 1 - polarity changed */
  36. #define IER_JABBER 0x0001 /* Bit 0 - jabber */
  37. /* Interrupt status register */
  38. #define ISR_ANEG_ERR 0x8000 /* Bit 15 - autonegotiation error */
  39. #define ISR_SPEED_CHG 0x4000 /* Bit 14 - speed changed */
  40. #define ISR_DUPLEX_CHG 0x2000 /* Bit 13 - duplex changed */
  41. #define ISR_PAGE_RCVD 0x1000 /* Bit 12 - page received */
  42. #define ISR_ANEG_DONE 0x0800 /* Bit 11 - autonegotiation complete */
  43. #define ISR_LINK_CHG 0x0400 /* Bit 10 - link status changed */
  44. #define ISR_SYM_ERR 0x0200 /* Bit 9 - symbol error */
  45. #define ISR_FALSE_CARRIER 0x0100 /* Bit 8 - false carrier */
  46. #define ISR_FIFO_ERR 0x0080 /* Bit 7 - FIFO over/underflow */
  47. #define ISR_MDIX_CHG 0x0040 /* Bit 6 - MDI crossover changed */
  48. #define ISR_DOWNSHIFT 0x0020 /* Bit 5 - downshift */
  49. #define ISR_ENERGY 0x0010 /* Bit 4 - energy detect */
  50. #define ISR_DTE_POWER 0x0004 /* Bit 2 - DTE power detect */
  51. #define ISR_POLARITY_CHG 0x0002 /* Bit 1 - polarity changed */
  52. #define ISR_JABBER 0x0001 /* Bit 0 - jabber */
  53. /* Logically extended advertisement register */
  54. #define GM_ADVERTISE_SLCT ADVERTISE_SLCT
  55. #define GM_ADVERTISE_CSMA ADVERTISE_CSMA
  56. #define GM_ADVERTISE_10HALF ADVERTISE_10HALF
  57. #define GM_ADVERTISE_1000XFULL ADVERTISE_1000XFULL
  58. #define GM_ADVERTISE_10FULL ADVERTISE_10FULL
  59. #define GM_ADVERTISE_1000XHALF ADVERTISE_1000XHALF
  60. #define GM_ADVERTISE_100HALF ADVERTISE_100HALF
  61. #define GM_ADVERTISE_1000XPAUSE ADVERTISE_1000XPAUSE
  62. #define GM_ADVERTISE_100FULL ADVERTISE_100FULL
  63. #define GM_ADVERTISE_1000XPSE_ASYM ADVERTISE_1000XPSE_ASYM
  64. #define GM_ADVERTISE_100BASE4 ADVERTISE_100BASE4
  65. #define GM_ADVERTISE_PAUSE_CAP ADVERTISE_PAUSE_CAP
  66. #define GM_ADVERTISE_PAUSE_ASYM ADVERTISE_PAUSE_ASYM
  67. #define GM_ADVERTISE_RESV ADVERTISE_RESV
  68. #define GM_ADVERTISE_RFAULT ADVERTISE_RFAULT
  69. #define GM_ADVERTISE_LPACK ADVERTISE_LPACK
  70. #define GM_ADVERTISE_NPAGE ADVERTISE_NPAGE
  71. #define GM_ADVERTISE_1000FULL (ADVERTISE_1000FULL << 8)
  72. #define GM_ADVERTISE_1000HALF (ADVERTISE_1000HALF << 8)
  73. #define GM_ADVERTISE_1000 (GM_ADVERTISE_1000FULL | \
  74. GM_ADVERTISE_1000HALF)
  75. #define GM_ADVERTISE_FULL (GM_ADVERTISE_1000FULL | \
  76. ADVERTISE_FULL)
  77. #define GM_ADVERTISE_ALL (GM_ADVERTISE_1000FULL | \
  78. GM_ADVERTISE_1000HALF | \
  79. ADVERTISE_ALL)
  80. /* Logically extended link partner ability register */
  81. #define GM_LPA_SLCT LPA_SLCT
  82. #define GM_LPA_10HALF LPA_10HALF
  83. #define GM_LPA_1000XFULL LPA_1000XFULL
  84. #define GM_LPA_10FULL LPA_10FULL
  85. #define GM_LPA_1000XHALF LPA_1000XHALF
  86. #define GM_LPA_100HALF LPA_100HALF
  87. #define GM_LPA_1000XPAUSE LPA_1000XPAUSE
  88. #define GM_LPA_100FULL LPA_100FULL
  89. #define GM_LPA_1000XPAUSE_ASYM LPA_1000XPAUSE_ASYM
  90. #define GM_LPA_100BASE4 LPA_100BASE4
  91. #define GM_LPA_PAUSE_CAP LPA_PAUSE_CAP
  92. #define GM_LPA_PAUSE_ASYM LPA_PAUSE_ASYM
  93. #define GM_LPA_RESV LPA_RESV
  94. #define GM_LPA_RFAULT LPA_RFAULT
  95. #define GM_LPA_LPACK LPA_LPACK
  96. #define GM_LPA_NPAGE LPA_NPAGE
  97. #define GM_LPA_1000FULL (LPA_1000FULL << 6)
  98. #define GM_LPA_1000HALF (LPA_1000HALF << 6)
  99. #define GM_LPA_10000FULL 0x00040000
  100. #define GM_LPA_10000HALF 0x00080000
  101. #define GM_LPA_DUPLEX (GM_LPA_1000FULL | GM_LPA_10000FULL \
  102. | LPA_DUPLEX)
  103. #define GM_LPA_10 (LPA_10FULL | LPA_10HALF)
  104. #define GM_LPA_100 LPA_100
  105. #define GM_LPA_1000 (GM_LPA_1000FULL | GM_LPA_1000HALF)
  106. #define GM_LPA_10000 (GM_LPA_10000FULL | GM_LPA_10000HALF)
  107. /* Retrieve GMII autonegotiation advertised abilities
  108. *
  109. * The MII advertisment register (MII_ADVERTISE) is logically extended
  110. * to include advertisement bits ADVERTISE_1000FULL and
  111. * ADVERTISE_1000HALF from MII_CTRL1000. The result can be tested
  112. * against the GM_ADVERTISE_xxx constants.
  113. */
  114. static inline unsigned int gmii_advertised(struct mii_if_info *gmii)
  115. {
  116. unsigned int advertise;
  117. unsigned int ctrl1000;
  118. advertise = gmii->mdio_read(gmii->dev, gmii->phy_id, MII_ADVERTISE);
  119. ctrl1000 = gmii->mdio_read(gmii->dev, gmii->phy_id, MII_CTRL1000);
  120. return (((ctrl1000 << 8) & GM_ADVERTISE_1000) | advertise);
  121. }
  122. /* Retrieve GMII autonegotiation link partner abilities
  123. *
  124. * The MII link partner ability register (MII_LPA) is logically
  125. * extended by adding bits LPA_1000HALF and LPA_1000FULL from
  126. * MII_STAT1000. The result can be tested against the GM_LPA_xxx
  127. * constants.
  128. */
  129. static inline unsigned int gmii_lpa(struct mii_if_info *gmii)
  130. {
  131. unsigned int lpa;
  132. unsigned int stat1000;
  133. lpa = gmii->mdio_read(gmii->dev, gmii->phy_id, MII_LPA);
  134. stat1000 = gmii->mdio_read(gmii->dev, gmii->phy_id, MII_STAT1000);
  135. return (((stat1000 << 6) & GM_LPA_1000) | lpa);
  136. }
  137. /* Calculate GMII autonegotiated link technology
  138. *
  139. * "negotiated" should be the result of gmii_advertised() logically
  140. * ANDed with the result of gmii_lpa().
  141. *
  142. * "tech" will be negotiated with the unused bits masked out. For
  143. * example, if both ends of the link are capable of both
  144. * GM_LPA_1000FULL and GM_LPA_100FULL, GM_LPA_100FULL will be masked
  145. * out.
  146. */
  147. static inline unsigned int gmii_nway_result(unsigned int negotiated)
  148. {
  149. unsigned int other_bits;
  150. /* Mask out the speed and duplexity bits */
  151. other_bits = negotiated & ~(GM_LPA_10 | GM_LPA_100 | GM_LPA_1000);
  152. if (negotiated & GM_LPA_1000FULL)
  153. return (other_bits | GM_LPA_1000FULL);
  154. else if (negotiated & GM_LPA_1000HALF)
  155. return (other_bits | GM_LPA_1000HALF);
  156. else
  157. return (other_bits | mii_nway_result(negotiated));
  158. }
  159. /* Calculate GMII non-autonegotiated link technology
  160. *
  161. * This provides an equivalent to gmii_nway_result for the case when
  162. * autonegotiation is disabled.
  163. */
  164. static inline unsigned int gmii_forced_result(unsigned int bmcr)
  165. {
  166. unsigned int result;
  167. int full_duplex;
  168. full_duplex = bmcr & BMCR_FULLDPLX;
  169. if (bmcr & BMCR_SPEED1000)
  170. result = full_duplex ? GM_LPA_1000FULL : GM_LPA_1000HALF;
  171. else if (bmcr & BMCR_SPEED100)
  172. result = full_duplex ? GM_LPA_100FULL : GM_LPA_100HALF;
  173. else
  174. result = full_duplex ? GM_LPA_10FULL : GM_LPA_10HALF;
  175. return result;
  176. }
  177. #endif /* EFX_GMII_H */