falcon_xmac.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2010 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 "regs.h"
  15. #include "io.h"
  16. #include "mdio_10g.h"
  17. #include "workarounds.h"
  18. /**************************************************************************
  19. *
  20. * MAC operations
  21. *
  22. *************************************************************************/
  23. /* Configure the XAUI driver that is an output from Falcon */
  24. void falcon_setup_xaui(struct efx_nic *efx)
  25. {
  26. efx_oword_t sdctl, txdrv;
  27. /* Move the XAUI into low power, unless there is no PHY, in
  28. * which case the XAUI will have to drive a cable. */
  29. if (efx->phy_type == PHY_TYPE_NONE)
  30. return;
  31. efx_reado(efx, &sdctl, FR_AB_XX_SD_CTL);
  32. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVD, FFE_AB_XX_SD_CTL_DRV_DEF);
  33. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVD, FFE_AB_XX_SD_CTL_DRV_DEF);
  34. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVC, FFE_AB_XX_SD_CTL_DRV_DEF);
  35. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVC, FFE_AB_XX_SD_CTL_DRV_DEF);
  36. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVB, FFE_AB_XX_SD_CTL_DRV_DEF);
  37. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVB, FFE_AB_XX_SD_CTL_DRV_DEF);
  38. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVA, FFE_AB_XX_SD_CTL_DRV_DEF);
  39. EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVA, FFE_AB_XX_SD_CTL_DRV_DEF);
  40. efx_writeo(efx, &sdctl, FR_AB_XX_SD_CTL);
  41. EFX_POPULATE_OWORD_8(txdrv,
  42. FRF_AB_XX_DEQD, FFE_AB_XX_TXDRV_DEQ_DEF,
  43. FRF_AB_XX_DEQC, FFE_AB_XX_TXDRV_DEQ_DEF,
  44. FRF_AB_XX_DEQB, FFE_AB_XX_TXDRV_DEQ_DEF,
  45. FRF_AB_XX_DEQA, FFE_AB_XX_TXDRV_DEQ_DEF,
  46. FRF_AB_XX_DTXD, FFE_AB_XX_TXDRV_DTX_DEF,
  47. FRF_AB_XX_DTXC, FFE_AB_XX_TXDRV_DTX_DEF,
  48. FRF_AB_XX_DTXB, FFE_AB_XX_TXDRV_DTX_DEF,
  49. FRF_AB_XX_DTXA, FFE_AB_XX_TXDRV_DTX_DEF);
  50. efx_writeo(efx, &txdrv, FR_AB_XX_TXDRV_CTL);
  51. }
  52. int falcon_reset_xaui(struct efx_nic *efx)
  53. {
  54. struct falcon_nic_data *nic_data = efx->nic_data;
  55. efx_oword_t reg;
  56. int count;
  57. /* Don't fetch MAC statistics over an XMAC reset */
  58. WARN_ON(nic_data->stats_disable_count == 0);
  59. /* Start reset sequence */
  60. EFX_POPULATE_OWORD_1(reg, FRF_AB_XX_RST_XX_EN, 1);
  61. efx_writeo(efx, &reg, FR_AB_XX_PWR_RST);
  62. /* Wait up to 10 ms for completion, then reinitialise */
  63. for (count = 0; count < 1000; count++) {
  64. efx_reado(efx, &reg, FR_AB_XX_PWR_RST);
  65. if (EFX_OWORD_FIELD(reg, FRF_AB_XX_RST_XX_EN) == 0 &&
  66. EFX_OWORD_FIELD(reg, FRF_AB_XX_SD_RST_ACT) == 0) {
  67. falcon_setup_xaui(efx);
  68. return 0;
  69. }
  70. udelay(10);
  71. }
  72. netif_err(efx, hw, efx->net_dev,
  73. "timed out waiting for XAUI/XGXS reset\n");
  74. return -ETIMEDOUT;
  75. }
  76. static void falcon_ack_status_intr(struct efx_nic *efx)
  77. {
  78. struct falcon_nic_data *nic_data = efx->nic_data;
  79. efx_oword_t reg;
  80. if ((efx_nic_rev(efx) != EFX_REV_FALCON_B0) || LOOPBACK_INTERNAL(efx))
  81. return;
  82. /* We expect xgmii faults if the wireside link is down */
  83. if (!EFX_WORKAROUND_5147(efx) || !efx->link_state.up)
  84. return;
  85. /* We can only use this interrupt to signal the negative edge of
  86. * xaui_align [we have to poll the positive edge]. */
  87. if (nic_data->xmac_poll_required)
  88. return;
  89. efx_reado(efx, &reg, FR_AB_XM_MGT_INT_MSK);
  90. }
  91. static bool falcon_xgxs_link_ok(struct efx_nic *efx)
  92. {
  93. efx_oword_t reg;
  94. bool align_done, link_ok = false;
  95. int sync_status;
  96. /* Read link status */
  97. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  98. align_done = EFX_OWORD_FIELD(reg, FRF_AB_XX_ALIGN_DONE);
  99. sync_status = EFX_OWORD_FIELD(reg, FRF_AB_XX_SYNC_STAT);
  100. if (align_done && (sync_status == FFE_AB_XX_STAT_ALL_LANES))
  101. link_ok = true;
  102. /* Clear link status ready for next read */
  103. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_COMMA_DET, FFE_AB_XX_STAT_ALL_LANES);
  104. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_CHAR_ERR, FFE_AB_XX_STAT_ALL_LANES);
  105. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_DISPERR, FFE_AB_XX_STAT_ALL_LANES);
  106. efx_writeo(efx, &reg, FR_AB_XX_CORE_STAT);
  107. return link_ok;
  108. }
  109. static bool falcon_xmac_link_ok(struct efx_nic *efx)
  110. {
  111. /*
  112. * Check MAC's XGXS link status except when using XGMII loopback
  113. * which bypasses the XGXS block.
  114. * If possible, check PHY's XGXS link status except when using
  115. * MAC loopback.
  116. */
  117. return (efx->loopback_mode == LOOPBACK_XGMII ||
  118. falcon_xgxs_link_ok(efx)) &&
  119. (!(efx->mdio.mmds & (1 << MDIO_MMD_PHYXS)) ||
  120. LOOPBACK_INTERNAL(efx) ||
  121. efx_mdio_phyxgxs_lane_sync(efx));
  122. }
  123. static void falcon_reconfigure_xmac_core(struct efx_nic *efx)
  124. {
  125. unsigned int max_frame_len;
  126. efx_oword_t reg;
  127. bool rx_fc = !!(efx->link_state.fc & EFX_FC_RX);
  128. bool tx_fc = !!(efx->link_state.fc & EFX_FC_TX);
  129. /* Configure MAC - cut-thru mode is hard wired on */
  130. EFX_POPULATE_OWORD_3(reg,
  131. FRF_AB_XM_RX_JUMBO_MODE, 1,
  132. FRF_AB_XM_TX_STAT_EN, 1,
  133. FRF_AB_XM_RX_STAT_EN, 1);
  134. efx_writeo(efx, &reg, FR_AB_XM_GLB_CFG);
  135. /* Configure TX */
  136. EFX_POPULATE_OWORD_6(reg,
  137. FRF_AB_XM_TXEN, 1,
  138. FRF_AB_XM_TX_PRMBL, 1,
  139. FRF_AB_XM_AUTO_PAD, 1,
  140. FRF_AB_XM_TXCRC, 1,
  141. FRF_AB_XM_FCNTL, tx_fc,
  142. FRF_AB_XM_IPG, 0x3);
  143. efx_writeo(efx, &reg, FR_AB_XM_TX_CFG);
  144. /* Configure RX */
  145. EFX_POPULATE_OWORD_5(reg,
  146. FRF_AB_XM_RXEN, 1,
  147. FRF_AB_XM_AUTO_DEPAD, 0,
  148. FRF_AB_XM_ACPT_ALL_MCAST, 1,
  149. FRF_AB_XM_ACPT_ALL_UCAST, efx->promiscuous,
  150. FRF_AB_XM_PASS_CRC_ERR, 1);
  151. efx_writeo(efx, &reg, FR_AB_XM_RX_CFG);
  152. /* Set frame length */
  153. max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
  154. EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_MAX_RX_FRM_SIZE, max_frame_len);
  155. efx_writeo(efx, &reg, FR_AB_XM_RX_PARAM);
  156. EFX_POPULATE_OWORD_2(reg,
  157. FRF_AB_XM_MAX_TX_FRM_SIZE, max_frame_len,
  158. FRF_AB_XM_TX_JUMBO_MODE, 1);
  159. efx_writeo(efx, &reg, FR_AB_XM_TX_PARAM);
  160. EFX_POPULATE_OWORD_2(reg,
  161. FRF_AB_XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */
  162. FRF_AB_XM_DIS_FCNTL, !rx_fc);
  163. efx_writeo(efx, &reg, FR_AB_XM_FC);
  164. /* Set MAC address */
  165. memcpy(&reg, &efx->net_dev->dev_addr[0], 4);
  166. efx_writeo(efx, &reg, FR_AB_XM_ADR_LO);
  167. memcpy(&reg, &efx->net_dev->dev_addr[4], 2);
  168. efx_writeo(efx, &reg, FR_AB_XM_ADR_HI);
  169. }
  170. static void falcon_reconfigure_xgxs_core(struct efx_nic *efx)
  171. {
  172. efx_oword_t reg;
  173. bool xgxs_loopback = (efx->loopback_mode == LOOPBACK_XGXS);
  174. bool xaui_loopback = (efx->loopback_mode == LOOPBACK_XAUI);
  175. bool xgmii_loopback = (efx->loopback_mode == LOOPBACK_XGMII);
  176. /* XGXS block is flaky and will need to be reset if moving
  177. * into our out of XGMII, XGXS or XAUI loopbacks. */
  178. if (EFX_WORKAROUND_5147(efx)) {
  179. bool old_xgmii_loopback, old_xgxs_loopback, old_xaui_loopback;
  180. bool reset_xgxs;
  181. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  182. old_xgxs_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_XGXS_LB_EN);
  183. old_xgmii_loopback =
  184. EFX_OWORD_FIELD(reg, FRF_AB_XX_XGMII_LB_EN);
  185. efx_reado(efx, &reg, FR_AB_XX_SD_CTL);
  186. old_xaui_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_LPBKA);
  187. /* The PHY driver may have turned XAUI off */
  188. reset_xgxs = ((xgxs_loopback != old_xgxs_loopback) ||
  189. (xaui_loopback != old_xaui_loopback) ||
  190. (xgmii_loopback != old_xgmii_loopback));
  191. if (reset_xgxs)
  192. falcon_reset_xaui(efx);
  193. }
  194. efx_reado(efx, &reg, FR_AB_XX_CORE_STAT);
  195. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_FORCE_SIG,
  196. (xgxs_loopback || xaui_loopback) ?
  197. FFE_AB_XX_FORCE_SIG_ALL_LANES : 0);
  198. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_XGXS_LB_EN, xgxs_loopback);
  199. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_XGMII_LB_EN, xgmii_loopback);
  200. efx_writeo(efx, &reg, FR_AB_XX_CORE_STAT);
  201. efx_reado(efx, &reg, FR_AB_XX_SD_CTL);
  202. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKD, xaui_loopback);
  203. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKC, xaui_loopback);
  204. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKB, xaui_loopback);
  205. EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKA, xaui_loopback);
  206. efx_writeo(efx, &reg, FR_AB_XX_SD_CTL);
  207. }
  208. /* Try to bring up the Falcon side of the Falcon-Phy XAUI link */
  209. static bool falcon_xmac_link_ok_retry(struct efx_nic *efx, int tries)
  210. {
  211. bool mac_up = falcon_xmac_link_ok(efx);
  212. if (LOOPBACK_MASK(efx) & LOOPBACKS_EXTERNAL(efx) & LOOPBACKS_WS ||
  213. efx_phy_mode_disabled(efx->phy_mode))
  214. /* XAUI link is expected to be down */
  215. return mac_up;
  216. falcon_stop_nic_stats(efx);
  217. while (!mac_up && tries) {
  218. netif_dbg(efx, hw, efx->net_dev, "bashing xaui\n");
  219. falcon_reset_xaui(efx);
  220. udelay(200);
  221. mac_up = falcon_xmac_link_ok(efx);
  222. --tries;
  223. }
  224. falcon_start_nic_stats(efx);
  225. return mac_up;
  226. }
  227. bool falcon_xmac_check_fault(struct efx_nic *efx)
  228. {
  229. return !falcon_xmac_link_ok_retry(efx, 5);
  230. }
  231. int falcon_reconfigure_xmac(struct efx_nic *efx)
  232. {
  233. struct falcon_nic_data *nic_data = efx->nic_data;
  234. falcon_reconfigure_xgxs_core(efx);
  235. falcon_reconfigure_xmac_core(efx);
  236. falcon_reconfigure_mac_wrapper(efx);
  237. nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 5);
  238. falcon_ack_status_intr(efx);
  239. return 0;
  240. }
  241. void falcon_update_stats_xmac(struct efx_nic *efx)
  242. {
  243. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  244. /* Update MAC stats from DMAed values */
  245. FALCON_STAT(efx, XgRxOctets, rx_bytes);
  246. FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes);
  247. FALCON_STAT(efx, XgRxPkts, rx_packets);
  248. FALCON_STAT(efx, XgRxPktsOK, rx_good);
  249. FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast);
  250. FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast);
  251. FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast);
  252. FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64);
  253. FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo);
  254. FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo);
  255. FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64);
  256. FALCON_STAT(efx, XgRxDropEvents, rx_overflow);
  257. FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad);
  258. FALCON_STAT(efx, XgRxAlignError, rx_align_error);
  259. FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error);
  260. FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error);
  261. FALCON_STAT(efx, XgRxControlPkts, rx_control);
  262. FALCON_STAT(efx, XgRxPausePkts, rx_pause);
  263. FALCON_STAT(efx, XgRxPkts64Octets, rx_64);
  264. FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127);
  265. FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255);
  266. FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511);
  267. FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023);
  268. FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx);
  269. FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo);
  270. FALCON_STAT(efx, XgRxLengthError, rx_length_error);
  271. FALCON_STAT(efx, XgTxPkts, tx_packets);
  272. FALCON_STAT(efx, XgTxOctets, tx_bytes);
  273. FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast);
  274. FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast);
  275. FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast);
  276. FALCON_STAT(efx, XgTxControlPkts, tx_control);
  277. FALCON_STAT(efx, XgTxPausePkts, tx_pause);
  278. FALCON_STAT(efx, XgTxPkts64Octets, tx_64);
  279. FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127);
  280. FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255);
  281. FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511);
  282. FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023);
  283. FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx);
  284. FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo);
  285. FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64);
  286. FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo);
  287. FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp);
  288. FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error);
  289. FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error);
  290. /* Update derived statistics */
  291. mac_stats->tx_good_bytes =
  292. (mac_stats->tx_bytes - mac_stats->tx_bad_bytes -
  293. mac_stats->tx_control * 64);
  294. mac_stats->rx_bad_bytes =
  295. (mac_stats->rx_bytes - mac_stats->rx_good_bytes -
  296. mac_stats->rx_control * 64);
  297. }
  298. void falcon_poll_xmac(struct efx_nic *efx)
  299. {
  300. struct falcon_nic_data *nic_data = efx->nic_data;
  301. if (!EFX_WORKAROUND_5147(efx) || !efx->link_state.up ||
  302. !nic_data->xmac_poll_required)
  303. return;
  304. nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 1);
  305. falcon_ack_status_intr(efx);
  306. }