falcon_gmac.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  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. #include <linux/delay.h>
  11. #include "net_driver.h"
  12. #include "efx.h"
  13. #include "nic.h"
  14. #include "mac.h"
  15. #include "regs.h"
  16. #include "io.h"
  17. /**************************************************************************
  18. *
  19. * MAC operations
  20. *
  21. *************************************************************************/
  22. static int falcon_reconfigure_gmac(struct efx_nic *efx)
  23. {
  24. struct efx_link_state *link_state = &efx->link_state;
  25. bool loopback, tx_fc, rx_fc, bytemode;
  26. int if_mode;
  27. unsigned int max_frame_len;
  28. efx_oword_t reg;
  29. /* Configuration register 1 */
  30. tx_fc = (link_state->fc & EFX_FC_TX) || !link_state->fd;
  31. rx_fc = !!(link_state->fc & EFX_FC_RX);
  32. loopback = (efx->loopback_mode == LOOPBACK_GMAC);
  33. bytemode = (link_state->speed == 1000);
  34. EFX_POPULATE_OWORD_5(reg,
  35. FRF_AB_GM_LOOP, loopback,
  36. FRF_AB_GM_TX_EN, 1,
  37. FRF_AB_GM_TX_FC_EN, tx_fc,
  38. FRF_AB_GM_RX_EN, 1,
  39. FRF_AB_GM_RX_FC_EN, rx_fc);
  40. efx_writeo(efx, &reg, FR_AB_GM_CFG1);
  41. udelay(10);
  42. /* Configuration register 2 */
  43. if_mode = (bytemode) ? 2 : 1;
  44. EFX_POPULATE_OWORD_5(reg,
  45. FRF_AB_GM_IF_MODE, if_mode,
  46. FRF_AB_GM_PAD_CRC_EN, 1,
  47. FRF_AB_GM_LEN_CHK, 1,
  48. FRF_AB_GM_FD, link_state->fd,
  49. FRF_AB_GM_PAMBL_LEN, 0x7/*datasheet recommended */);
  50. efx_writeo(efx, &reg, FR_AB_GM_CFG2);
  51. udelay(10);
  52. /* Max frame len register */
  53. max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
  54. EFX_POPULATE_OWORD_1(reg, FRF_AB_GM_MAX_FLEN, max_frame_len);
  55. efx_writeo(efx, &reg, FR_AB_GM_MAX_FLEN);
  56. udelay(10);
  57. /* FIFO configuration register 0 */
  58. EFX_POPULATE_OWORD_5(reg,
  59. FRF_AB_GMF_FTFENREQ, 1,
  60. FRF_AB_GMF_STFENREQ, 1,
  61. FRF_AB_GMF_FRFENREQ, 1,
  62. FRF_AB_GMF_SRFENREQ, 1,
  63. FRF_AB_GMF_WTMENREQ, 1);
  64. efx_writeo(efx, &reg, FR_AB_GMF_CFG0);
  65. udelay(10);
  66. /* FIFO configuration register 1 */
  67. EFX_POPULATE_OWORD_2(reg,
  68. FRF_AB_GMF_CFGFRTH, 0x12,
  69. FRF_AB_GMF_CFGXOFFRTX, 0xffff);
  70. efx_writeo(efx, &reg, FR_AB_GMF_CFG1);
  71. udelay(10);
  72. /* FIFO configuration register 2 */
  73. EFX_POPULATE_OWORD_2(reg,
  74. FRF_AB_GMF_CFGHWM, 0x3f,
  75. FRF_AB_GMF_CFGLWM, 0xa);
  76. efx_writeo(efx, &reg, FR_AB_GMF_CFG2);
  77. udelay(10);
  78. /* FIFO configuration register 3 */
  79. EFX_POPULATE_OWORD_2(reg,
  80. FRF_AB_GMF_CFGHWMFT, 0x1c,
  81. FRF_AB_GMF_CFGFTTH, 0x08);
  82. efx_writeo(efx, &reg, FR_AB_GMF_CFG3);
  83. udelay(10);
  84. /* FIFO configuration register 4 */
  85. EFX_POPULATE_OWORD_1(reg, FRF_AB_GMF_HSTFLTRFRM_PAUSE, 1);
  86. efx_writeo(efx, &reg, FR_AB_GMF_CFG4);
  87. udelay(10);
  88. /* FIFO configuration register 5 */
  89. efx_reado(efx, &reg, FR_AB_GMF_CFG5);
  90. EFX_SET_OWORD_FIELD(reg, FRF_AB_GMF_CFGBYTMODE, bytemode);
  91. EFX_SET_OWORD_FIELD(reg, FRF_AB_GMF_CFGHDPLX, !link_state->fd);
  92. EFX_SET_OWORD_FIELD(reg, FRF_AB_GMF_HSTDRPLT64, !link_state->fd);
  93. EFX_SET_OWORD_FIELD(reg, FRF_AB_GMF_HSTFLTRFRMDC_PAUSE, 0);
  94. efx_writeo(efx, &reg, FR_AB_GMF_CFG5);
  95. udelay(10);
  96. /* MAC address */
  97. EFX_POPULATE_OWORD_4(reg,
  98. FRF_AB_GM_ADR_B0, efx->net_dev->dev_addr[5],
  99. FRF_AB_GM_ADR_B1, efx->net_dev->dev_addr[4],
  100. FRF_AB_GM_ADR_B2, efx->net_dev->dev_addr[3],
  101. FRF_AB_GM_ADR_B3, efx->net_dev->dev_addr[2]);
  102. efx_writeo(efx, &reg, FR_AB_GM_ADR1);
  103. udelay(10);
  104. EFX_POPULATE_OWORD_2(reg,
  105. FRF_AB_GM_ADR_B4, efx->net_dev->dev_addr[1],
  106. FRF_AB_GM_ADR_B5, efx->net_dev->dev_addr[0]);
  107. efx_writeo(efx, &reg, FR_AB_GM_ADR2);
  108. udelay(10);
  109. falcon_reconfigure_mac_wrapper(efx);
  110. return 0;
  111. }
  112. static void falcon_update_stats_gmac(struct efx_nic *efx)
  113. {
  114. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  115. unsigned long old_rx_pause, old_tx_pause;
  116. unsigned long new_rx_pause, new_tx_pause;
  117. /* Pause frames are erroneously counted as errors (SFC bug 3269) */
  118. old_rx_pause = mac_stats->rx_pause;
  119. old_tx_pause = mac_stats->tx_pause;
  120. /* Update MAC stats from DMAed values */
  121. FALCON_STAT(efx, GRxGoodOct, rx_good_bytes);
  122. FALCON_STAT(efx, GRxBadOct, rx_bad_bytes);
  123. FALCON_STAT(efx, GRxMissPkt, rx_missed);
  124. FALCON_STAT(efx, GRxFalseCRS, rx_false_carrier);
  125. FALCON_STAT(efx, GRxPausePkt, rx_pause);
  126. FALCON_STAT(efx, GRxBadPkt, rx_bad);
  127. FALCON_STAT(efx, GRxUcastPkt, rx_unicast);
  128. FALCON_STAT(efx, GRxMcastPkt, rx_multicast);
  129. FALCON_STAT(efx, GRxBcastPkt, rx_broadcast);
  130. FALCON_STAT(efx, GRxGoodLt64Pkt, rx_good_lt64);
  131. FALCON_STAT(efx, GRxBadLt64Pkt, rx_bad_lt64);
  132. FALCON_STAT(efx, GRx64Pkt, rx_64);
  133. FALCON_STAT(efx, GRx65to127Pkt, rx_65_to_127);
  134. FALCON_STAT(efx, GRx128to255Pkt, rx_128_to_255);
  135. FALCON_STAT(efx, GRx256to511Pkt, rx_256_to_511);
  136. FALCON_STAT(efx, GRx512to1023Pkt, rx_512_to_1023);
  137. FALCON_STAT(efx, GRx1024to15xxPkt, rx_1024_to_15xx);
  138. FALCON_STAT(efx, GRx15xxtoJumboPkt, rx_15xx_to_jumbo);
  139. FALCON_STAT(efx, GRxGtJumboPkt, rx_gtjumbo);
  140. FALCON_STAT(efx, GRxFcsErr64to15xxPkt, rx_bad_64_to_15xx);
  141. FALCON_STAT(efx, GRxFcsErr15xxtoJumboPkt, rx_bad_15xx_to_jumbo);
  142. FALCON_STAT(efx, GRxFcsErrGtJumboPkt, rx_bad_gtjumbo);
  143. FALCON_STAT(efx, GTxGoodBadOct, tx_bytes);
  144. FALCON_STAT(efx, GTxGoodOct, tx_good_bytes);
  145. FALCON_STAT(efx, GTxSglColPkt, tx_single_collision);
  146. FALCON_STAT(efx, GTxMultColPkt, tx_multiple_collision);
  147. FALCON_STAT(efx, GTxExColPkt, tx_excessive_collision);
  148. FALCON_STAT(efx, GTxDefPkt, tx_deferred);
  149. FALCON_STAT(efx, GTxLateCol, tx_late_collision);
  150. FALCON_STAT(efx, GTxExDefPkt, tx_excessive_deferred);
  151. FALCON_STAT(efx, GTxPausePkt, tx_pause);
  152. FALCON_STAT(efx, GTxBadPkt, tx_bad);
  153. FALCON_STAT(efx, GTxUcastPkt, tx_unicast);
  154. FALCON_STAT(efx, GTxMcastPkt, tx_multicast);
  155. FALCON_STAT(efx, GTxBcastPkt, tx_broadcast);
  156. FALCON_STAT(efx, GTxLt64Pkt, tx_lt64);
  157. FALCON_STAT(efx, GTx64Pkt, tx_64);
  158. FALCON_STAT(efx, GTx65to127Pkt, tx_65_to_127);
  159. FALCON_STAT(efx, GTx128to255Pkt, tx_128_to_255);
  160. FALCON_STAT(efx, GTx256to511Pkt, tx_256_to_511);
  161. FALCON_STAT(efx, GTx512to1023Pkt, tx_512_to_1023);
  162. FALCON_STAT(efx, GTx1024to15xxPkt, tx_1024_to_15xx);
  163. FALCON_STAT(efx, GTx15xxtoJumboPkt, tx_15xx_to_jumbo);
  164. FALCON_STAT(efx, GTxGtJumboPkt, tx_gtjumbo);
  165. FALCON_STAT(efx, GTxNonTcpUdpPkt, tx_non_tcpudp);
  166. FALCON_STAT(efx, GTxMacSrcErrPkt, tx_mac_src_error);
  167. FALCON_STAT(efx, GTxIpSrcErrPkt, tx_ip_src_error);
  168. /* Pause frames are erroneously counted as errors (SFC bug 3269) */
  169. new_rx_pause = mac_stats->rx_pause;
  170. new_tx_pause = mac_stats->tx_pause;
  171. mac_stats->rx_bad -= (new_rx_pause - old_rx_pause);
  172. mac_stats->tx_bad -= (new_tx_pause - old_tx_pause);
  173. /* Derive stats that the MAC doesn't provide directly */
  174. mac_stats->tx_bad_bytes =
  175. mac_stats->tx_bytes - mac_stats->tx_good_bytes;
  176. mac_stats->tx_packets =
  177. mac_stats->tx_lt64 + mac_stats->tx_64 +
  178. mac_stats->tx_65_to_127 + mac_stats->tx_128_to_255 +
  179. mac_stats->tx_256_to_511 + mac_stats->tx_512_to_1023 +
  180. mac_stats->tx_1024_to_15xx + mac_stats->tx_15xx_to_jumbo +
  181. mac_stats->tx_gtjumbo;
  182. mac_stats->tx_collision =
  183. mac_stats->tx_single_collision +
  184. mac_stats->tx_multiple_collision +
  185. mac_stats->tx_excessive_collision +
  186. mac_stats->tx_late_collision;
  187. mac_stats->rx_bytes =
  188. mac_stats->rx_good_bytes + mac_stats->rx_bad_bytes;
  189. mac_stats->rx_packets =
  190. mac_stats->rx_good_lt64 + mac_stats->rx_bad_lt64 +
  191. mac_stats->rx_64 + mac_stats->rx_65_to_127 +
  192. mac_stats->rx_128_to_255 + mac_stats->rx_256_to_511 +
  193. mac_stats->rx_512_to_1023 + mac_stats->rx_1024_to_15xx +
  194. mac_stats->rx_15xx_to_jumbo + mac_stats->rx_gtjumbo;
  195. mac_stats->rx_good = mac_stats->rx_packets - mac_stats->rx_bad;
  196. mac_stats->rx_lt64 = mac_stats->rx_good_lt64 + mac_stats->rx_bad_lt64;
  197. }
  198. static bool falcon_gmac_check_fault(struct efx_nic *efx)
  199. {
  200. return false;
  201. }
  202. struct efx_mac_operations falcon_gmac_operations = {
  203. .reconfigure = falcon_reconfigure_gmac,
  204. .update_stats = falcon_update_stats_gmac,
  205. .check_fault = falcon_gmac_check_fault,
  206. };