falcon_gmac.c 7.7 KB

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