falcon_gmac.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2008 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 "falcon.h"
  14. #include "mac.h"
  15. #include "falcon_hwdefs.h"
  16. #include "falcon_io.h"
  17. #include "gmii.h"
  18. /**************************************************************************
  19. *
  20. * MAC operations
  21. *
  22. *************************************************************************/
  23. static void falcon_reconfigure_gmac(struct efx_nic *efx)
  24. {
  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 = (efx->link_fc & EFX_FC_TX) || !efx->link_fd;
  31. rx_fc = !!(efx->link_fc & EFX_FC_RX);
  32. loopback = (efx->loopback_mode == LOOPBACK_GMAC);
  33. bytemode = (efx->link_speed == 1000);
  34. EFX_POPULATE_OWORD_5(reg,
  35. GM_LOOP, loopback,
  36. GM_TX_EN, 1,
  37. GM_TX_FC_EN, tx_fc,
  38. GM_RX_EN, 1,
  39. GM_RX_FC_EN, rx_fc);
  40. falcon_write(efx, &reg, GM_CFG1_REG);
  41. udelay(10);
  42. /* Configuration register 2 */
  43. if_mode = (bytemode) ? 2 : 1;
  44. EFX_POPULATE_OWORD_5(reg,
  45. GM_IF_MODE, if_mode,
  46. GM_PAD_CRC_EN, 1,
  47. GM_LEN_CHK, 1,
  48. GM_FD, efx->link_fd,
  49. GM_PAMBL_LEN, 0x7/*datasheet recommended */);
  50. falcon_write(efx, &reg, GM_CFG2_REG);
  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, GM_MAX_FLEN, max_frame_len);
  55. falcon_write(efx, &reg, GM_MAX_FLEN_REG);
  56. udelay(10);
  57. /* FIFO configuration register 0 */
  58. EFX_POPULATE_OWORD_5(reg,
  59. GMF_FTFENREQ, 1,
  60. GMF_STFENREQ, 1,
  61. GMF_FRFENREQ, 1,
  62. GMF_SRFENREQ, 1,
  63. GMF_WTMENREQ, 1);
  64. falcon_write(efx, &reg, GMF_CFG0_REG);
  65. udelay(10);
  66. /* FIFO configuration register 1 */
  67. EFX_POPULATE_OWORD_2(reg,
  68. GMF_CFGFRTH, 0x12,
  69. GMF_CFGXOFFRTX, 0xffff);
  70. falcon_write(efx, &reg, GMF_CFG1_REG);
  71. udelay(10);
  72. /* FIFO configuration register 2 */
  73. EFX_POPULATE_OWORD_2(reg,
  74. GMF_CFGHWM, 0x3f,
  75. GMF_CFGLWM, 0xa);
  76. falcon_write(efx, &reg, GMF_CFG2_REG);
  77. udelay(10);
  78. /* FIFO configuration register 3 */
  79. EFX_POPULATE_OWORD_2(reg,
  80. GMF_CFGHWMFT, 0x1c,
  81. GMF_CFGFTTH, 0x08);
  82. falcon_write(efx, &reg, GMF_CFG3_REG);
  83. udelay(10);
  84. /* FIFO configuration register 4 */
  85. EFX_POPULATE_OWORD_1(reg, GMF_HSTFLTRFRM_PAUSE, 1);
  86. falcon_write(efx, &reg, GMF_CFG4_REG);
  87. udelay(10);
  88. /* FIFO configuration register 5 */
  89. falcon_read(efx, &reg, GMF_CFG5_REG);
  90. EFX_SET_OWORD_FIELD(reg, GMF_CFGBYTMODE, bytemode);
  91. EFX_SET_OWORD_FIELD(reg, GMF_CFGHDPLX, !efx->link_fd);
  92. EFX_SET_OWORD_FIELD(reg, GMF_HSTDRPLT64, !efx->link_fd);
  93. EFX_SET_OWORD_FIELD(reg, GMF_HSTFLTRFRMDC_PAUSE, 0);
  94. falcon_write(efx, &reg, GMF_CFG5_REG);
  95. udelay(10);
  96. /* MAC address */
  97. EFX_POPULATE_OWORD_4(reg,
  98. GM_HWADDR_5, efx->net_dev->dev_addr[5],
  99. GM_HWADDR_4, efx->net_dev->dev_addr[4],
  100. GM_HWADDR_3, efx->net_dev->dev_addr[3],
  101. GM_HWADDR_2, efx->net_dev->dev_addr[2]);
  102. falcon_write(efx, &reg, GM_ADR1_REG);
  103. udelay(10);
  104. EFX_POPULATE_OWORD_2(reg,
  105. GM_HWADDR_1, efx->net_dev->dev_addr[1],
  106. GM_HWADDR_0, efx->net_dev->dev_addr[0]);
  107. falcon_write(efx, &reg, GM_ADR2_REG);
  108. udelay(10);
  109. falcon_reconfigure_mac_wrapper(efx);
  110. }
  111. static void falcon_update_stats_gmac(struct efx_nic *efx)
  112. {
  113. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  114. unsigned long old_rx_pause, old_tx_pause;
  115. unsigned long new_rx_pause, new_tx_pause;
  116. int rc;
  117. rc = falcon_dma_stats(efx, GDmaDone_offset);
  118. if (rc)
  119. return;
  120. /* Pause frames are erroneously counted as errors (SFC bug 3269) */
  121. old_rx_pause = mac_stats->rx_pause;
  122. old_tx_pause = mac_stats->tx_pause;
  123. /* Update MAC stats from DMAed values */
  124. FALCON_STAT(efx, GRxGoodOct, rx_good_bytes);
  125. FALCON_STAT(efx, GRxBadOct, rx_bad_bytes);
  126. FALCON_STAT(efx, GRxMissPkt, rx_missed);
  127. FALCON_STAT(efx, GRxFalseCRS, rx_false_carrier);
  128. FALCON_STAT(efx, GRxPausePkt, rx_pause);
  129. FALCON_STAT(efx, GRxBadPkt, rx_bad);
  130. FALCON_STAT(efx, GRxUcastPkt, rx_unicast);
  131. FALCON_STAT(efx, GRxMcastPkt, rx_multicast);
  132. FALCON_STAT(efx, GRxBcastPkt, rx_broadcast);
  133. FALCON_STAT(efx, GRxGoodLt64Pkt, rx_good_lt64);
  134. FALCON_STAT(efx, GRxBadLt64Pkt, rx_bad_lt64);
  135. FALCON_STAT(efx, GRx64Pkt, rx_64);
  136. FALCON_STAT(efx, GRx65to127Pkt, rx_65_to_127);
  137. FALCON_STAT(efx, GRx128to255Pkt, rx_128_to_255);
  138. FALCON_STAT(efx, GRx256to511Pkt, rx_256_to_511);
  139. FALCON_STAT(efx, GRx512to1023Pkt, rx_512_to_1023);
  140. FALCON_STAT(efx, GRx1024to15xxPkt, rx_1024_to_15xx);
  141. FALCON_STAT(efx, GRx15xxtoJumboPkt, rx_15xx_to_jumbo);
  142. FALCON_STAT(efx, GRxGtJumboPkt, rx_gtjumbo);
  143. FALCON_STAT(efx, GRxFcsErr64to15xxPkt, rx_bad_64_to_15xx);
  144. FALCON_STAT(efx, GRxFcsErr15xxtoJumboPkt, rx_bad_15xx_to_jumbo);
  145. FALCON_STAT(efx, GRxFcsErrGtJumboPkt, rx_bad_gtjumbo);
  146. FALCON_STAT(efx, GTxGoodBadOct, tx_bytes);
  147. FALCON_STAT(efx, GTxGoodOct, tx_good_bytes);
  148. FALCON_STAT(efx, GTxSglColPkt, tx_single_collision);
  149. FALCON_STAT(efx, GTxMultColPkt, tx_multiple_collision);
  150. FALCON_STAT(efx, GTxExColPkt, tx_excessive_collision);
  151. FALCON_STAT(efx, GTxDefPkt, tx_deferred);
  152. FALCON_STAT(efx, GTxLateCol, tx_late_collision);
  153. FALCON_STAT(efx, GTxExDefPkt, tx_excessive_deferred);
  154. FALCON_STAT(efx, GTxPausePkt, tx_pause);
  155. FALCON_STAT(efx, GTxBadPkt, tx_bad);
  156. FALCON_STAT(efx, GTxUcastPkt, tx_unicast);
  157. FALCON_STAT(efx, GTxMcastPkt, tx_multicast);
  158. FALCON_STAT(efx, GTxBcastPkt, tx_broadcast);
  159. FALCON_STAT(efx, GTxLt64Pkt, tx_lt64);
  160. FALCON_STAT(efx, GTx64Pkt, tx_64);
  161. FALCON_STAT(efx, GTx65to127Pkt, tx_65_to_127);
  162. FALCON_STAT(efx, GTx128to255Pkt, tx_128_to_255);
  163. FALCON_STAT(efx, GTx256to511Pkt, tx_256_to_511);
  164. FALCON_STAT(efx, GTx512to1023Pkt, tx_512_to_1023);
  165. FALCON_STAT(efx, GTx1024to15xxPkt, tx_1024_to_15xx);
  166. FALCON_STAT(efx, GTx15xxtoJumboPkt, tx_15xx_to_jumbo);
  167. FALCON_STAT(efx, GTxGtJumboPkt, tx_gtjumbo);
  168. FALCON_STAT(efx, GTxNonTcpUdpPkt, tx_non_tcpudp);
  169. FALCON_STAT(efx, GTxMacSrcErrPkt, tx_mac_src_error);
  170. FALCON_STAT(efx, GTxIpSrcErrPkt, tx_ip_src_error);
  171. /* Pause frames are erroneously counted as errors (SFC bug 3269) */
  172. new_rx_pause = mac_stats->rx_pause;
  173. new_tx_pause = mac_stats->tx_pause;
  174. mac_stats->rx_bad -= (new_rx_pause - old_rx_pause);
  175. mac_stats->tx_bad -= (new_tx_pause - old_tx_pause);
  176. /* Derive stats that the MAC doesn't provide directly */
  177. mac_stats->tx_bad_bytes =
  178. mac_stats->tx_bytes - mac_stats->tx_good_bytes;
  179. mac_stats->tx_packets =
  180. mac_stats->tx_lt64 + mac_stats->tx_64 +
  181. mac_stats->tx_65_to_127 + mac_stats->tx_128_to_255 +
  182. mac_stats->tx_256_to_511 + mac_stats->tx_512_to_1023 +
  183. mac_stats->tx_1024_to_15xx + mac_stats->tx_15xx_to_jumbo +
  184. mac_stats->tx_gtjumbo;
  185. mac_stats->tx_collision =
  186. mac_stats->tx_single_collision +
  187. mac_stats->tx_multiple_collision +
  188. mac_stats->tx_excessive_collision +
  189. mac_stats->tx_late_collision;
  190. mac_stats->rx_bytes =
  191. mac_stats->rx_good_bytes + mac_stats->rx_bad_bytes;
  192. mac_stats->rx_packets =
  193. mac_stats->rx_good_lt64 + mac_stats->rx_bad_lt64 +
  194. mac_stats->rx_64 + mac_stats->rx_65_to_127 +
  195. mac_stats->rx_128_to_255 + mac_stats->rx_256_to_511 +
  196. mac_stats->rx_512_to_1023 + mac_stats->rx_1024_to_15xx +
  197. mac_stats->rx_15xx_to_jumbo + mac_stats->rx_gtjumbo;
  198. mac_stats->rx_good = mac_stats->rx_packets - mac_stats->rx_bad;
  199. mac_stats->rx_lt64 = mac_stats->rx_good_lt64 + mac_stats->rx_bad_lt64;
  200. }
  201. struct efx_mac_operations falcon_gmac_operations = {
  202. .reconfigure = falcon_reconfigure_gmac,
  203. .update_stats = falcon_update_stats_gmac,
  204. .irq = efx_port_dummy_op_void,
  205. .poll = efx_port_dummy_op_void,
  206. };