falcon_xmac.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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 "falcon_hwdefs.h"
  15. #include "falcon_io.h"
  16. #include "mac.h"
  17. #include "gmii.h"
  18. #include "mdio_10g.h"
  19. #include "phy.h"
  20. #include "boards.h"
  21. #include "workarounds.h"
  22. /**************************************************************************
  23. *
  24. * MAC register access
  25. *
  26. **************************************************************************/
  27. /* Offset of an XMAC register within Falcon */
  28. #define FALCON_XMAC_REG(mac_reg) \
  29. (FALCON_XMAC_REGBANK + ((mac_reg) * FALCON_XMAC_REG_SIZE))
  30. void falcon_xmac_writel(struct efx_nic *efx,
  31. efx_dword_t *value, unsigned int mac_reg)
  32. {
  33. efx_oword_t temp;
  34. EFX_POPULATE_OWORD_1(temp, MAC_DATA, EFX_DWORD_FIELD(*value, MAC_DATA));
  35. falcon_write(efx, &temp, FALCON_XMAC_REG(mac_reg));
  36. }
  37. void falcon_xmac_readl(struct efx_nic *efx,
  38. efx_dword_t *value, unsigned int mac_reg)
  39. {
  40. efx_oword_t temp;
  41. falcon_read(efx, &temp, FALCON_XMAC_REG(mac_reg));
  42. EFX_POPULATE_DWORD_1(*value, MAC_DATA, EFX_OWORD_FIELD(temp, MAC_DATA));
  43. }
  44. /**************************************************************************
  45. *
  46. * MAC operations
  47. *
  48. *************************************************************************/
  49. static int falcon_reset_xmac(struct efx_nic *efx)
  50. {
  51. efx_dword_t reg;
  52. int count;
  53. EFX_POPULATE_DWORD_1(reg, XM_CORE_RST, 1);
  54. falcon_xmac_writel(efx, &reg, XM_GLB_CFG_REG_MAC);
  55. for (count = 0; count < 10000; count++) { /* wait upto 100ms */
  56. falcon_xmac_readl(efx, &reg, XM_GLB_CFG_REG_MAC);
  57. if (EFX_DWORD_FIELD(reg, XM_CORE_RST) == 0)
  58. return 0;
  59. udelay(10);
  60. }
  61. EFX_ERR(efx, "timed out waiting for XMAC core reset\n");
  62. return -ETIMEDOUT;
  63. }
  64. /* Configure the XAUI driver that is an output from Falcon */
  65. static void falcon_setup_xaui(struct efx_nic *efx)
  66. {
  67. efx_dword_t sdctl, txdrv;
  68. /* Move the XAUI into low power, unless there is no PHY, in
  69. * which case the XAUI will have to drive a cable. */
  70. if (efx->phy_type == PHY_TYPE_NONE)
  71. return;
  72. falcon_xmac_readl(efx, &sdctl, XX_SD_CTL_REG_MAC);
  73. EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVD, XX_SD_CTL_DRV_DEFAULT);
  74. EFX_SET_DWORD_FIELD(sdctl, XX_LODRVD, XX_SD_CTL_DRV_DEFAULT);
  75. EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVC, XX_SD_CTL_DRV_DEFAULT);
  76. EFX_SET_DWORD_FIELD(sdctl, XX_LODRVC, XX_SD_CTL_DRV_DEFAULT);
  77. EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVB, XX_SD_CTL_DRV_DEFAULT);
  78. EFX_SET_DWORD_FIELD(sdctl, XX_LODRVB, XX_SD_CTL_DRV_DEFAULT);
  79. EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVA, XX_SD_CTL_DRV_DEFAULT);
  80. EFX_SET_DWORD_FIELD(sdctl, XX_LODRVA, XX_SD_CTL_DRV_DEFAULT);
  81. falcon_xmac_writel(efx, &sdctl, XX_SD_CTL_REG_MAC);
  82. EFX_POPULATE_DWORD_8(txdrv,
  83. XX_DEQD, XX_TXDRV_DEQ_DEFAULT,
  84. XX_DEQC, XX_TXDRV_DEQ_DEFAULT,
  85. XX_DEQB, XX_TXDRV_DEQ_DEFAULT,
  86. XX_DEQA, XX_TXDRV_DEQ_DEFAULT,
  87. XX_DTXD, XX_TXDRV_DTX_DEFAULT,
  88. XX_DTXC, XX_TXDRV_DTX_DEFAULT,
  89. XX_DTXB, XX_TXDRV_DTX_DEFAULT,
  90. XX_DTXA, XX_TXDRV_DTX_DEFAULT);
  91. falcon_xmac_writel(efx, &txdrv, XX_TXDRV_CTL_REG_MAC);
  92. }
  93. static void falcon_hold_xaui_in_rst(struct efx_nic *efx)
  94. {
  95. efx_dword_t reg;
  96. EFX_ZERO_DWORD(reg);
  97. EFX_SET_DWORD_FIELD(reg, XX_PWRDNA_EN, 1);
  98. EFX_SET_DWORD_FIELD(reg, XX_PWRDNB_EN, 1);
  99. EFX_SET_DWORD_FIELD(reg, XX_PWRDNC_EN, 1);
  100. EFX_SET_DWORD_FIELD(reg, XX_PWRDND_EN, 1);
  101. EFX_SET_DWORD_FIELD(reg, XX_RSTPLLAB_EN, 1);
  102. EFX_SET_DWORD_FIELD(reg, XX_RSTPLLCD_EN, 1);
  103. EFX_SET_DWORD_FIELD(reg, XX_RESETA_EN, 1);
  104. EFX_SET_DWORD_FIELD(reg, XX_RESETB_EN, 1);
  105. EFX_SET_DWORD_FIELD(reg, XX_RESETC_EN, 1);
  106. EFX_SET_DWORD_FIELD(reg, XX_RESETD_EN, 1);
  107. EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSRX_EN, 1);
  108. EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSTX_EN, 1);
  109. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  110. udelay(10);
  111. }
  112. static int _falcon_reset_xaui_a(struct efx_nic *efx)
  113. {
  114. efx_dword_t reg;
  115. falcon_hold_xaui_in_rst(efx);
  116. falcon_xmac_readl(efx, &reg, XX_PWR_RST_REG_MAC);
  117. /* Follow the RAMBUS XAUI data reset sequencing
  118. * Channels A and B first: power down, reset PLL, reset, clear
  119. */
  120. EFX_SET_DWORD_FIELD(reg, XX_PWRDNA_EN, 0);
  121. EFX_SET_DWORD_FIELD(reg, XX_PWRDNB_EN, 0);
  122. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  123. udelay(10);
  124. EFX_SET_DWORD_FIELD(reg, XX_RSTPLLAB_EN, 0);
  125. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  126. udelay(10);
  127. EFX_SET_DWORD_FIELD(reg, XX_RESETA_EN, 0);
  128. EFX_SET_DWORD_FIELD(reg, XX_RESETB_EN, 0);
  129. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  130. udelay(10);
  131. /* Channels C and D: power down, reset PLL, reset, clear */
  132. EFX_SET_DWORD_FIELD(reg, XX_PWRDNC_EN, 0);
  133. EFX_SET_DWORD_FIELD(reg, XX_PWRDND_EN, 0);
  134. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  135. udelay(10);
  136. EFX_SET_DWORD_FIELD(reg, XX_RSTPLLCD_EN, 0);
  137. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  138. udelay(10);
  139. EFX_SET_DWORD_FIELD(reg, XX_RESETC_EN, 0);
  140. EFX_SET_DWORD_FIELD(reg, XX_RESETD_EN, 0);
  141. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  142. udelay(10);
  143. /* Setup XAUI */
  144. falcon_setup_xaui(efx);
  145. udelay(10);
  146. /* Take XGXS out of reset */
  147. EFX_ZERO_DWORD(reg);
  148. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  149. udelay(10);
  150. return 0;
  151. }
  152. static int _falcon_reset_xaui_b(struct efx_nic *efx)
  153. {
  154. efx_dword_t reg;
  155. int count;
  156. EFX_POPULATE_DWORD_1(reg, XX_RST_XX_EN, 1);
  157. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  158. /* Give some time for the link to establish */
  159. for (count = 0; count < 1000; count++) { /* wait upto 10ms */
  160. falcon_xmac_readl(efx, &reg, XX_PWR_RST_REG_MAC);
  161. if (EFX_DWORD_FIELD(reg, XX_RST_XX_EN) == 0) {
  162. falcon_setup_xaui(efx);
  163. return 0;
  164. }
  165. udelay(10);
  166. }
  167. EFX_ERR(efx, "timed out waiting for XAUI/XGXS reset\n");
  168. return -ETIMEDOUT;
  169. }
  170. int falcon_reset_xaui(struct efx_nic *efx)
  171. {
  172. int rc;
  173. if (EFX_WORKAROUND_9388(efx)) {
  174. falcon_hold_xaui_in_rst(efx);
  175. efx->phy_op->reset_xaui(efx);
  176. rc = _falcon_reset_xaui_a(efx);
  177. } else {
  178. rc = _falcon_reset_xaui_b(efx);
  179. }
  180. return rc;
  181. }
  182. static int falcon_xgmii_status(struct efx_nic *efx)
  183. {
  184. efx_dword_t reg;
  185. if (FALCON_REV(efx) < FALCON_REV_B0)
  186. return 1;
  187. /* The ISR latches, so clear it and re-read */
  188. falcon_xmac_readl(efx, &reg, XM_MGT_INT_REG_MAC_B0);
  189. falcon_xmac_readl(efx, &reg, XM_MGT_INT_REG_MAC_B0);
  190. if (EFX_DWORD_FIELD(reg, XM_LCLFLT) ||
  191. EFX_DWORD_FIELD(reg, XM_RMTFLT)) {
  192. EFX_INFO(efx, "MGT_INT: "EFX_DWORD_FMT"\n", EFX_DWORD_VAL(reg));
  193. return 0;
  194. }
  195. return 1;
  196. }
  197. static void falcon_mask_status_intr(struct efx_nic *efx, int enable)
  198. {
  199. efx_dword_t reg;
  200. if (FALCON_REV(efx) < FALCON_REV_B0)
  201. return;
  202. /* Flush the ISR */
  203. if (enable)
  204. falcon_xmac_readl(efx, &reg, XM_MGT_INT_REG_MAC_B0);
  205. EFX_POPULATE_DWORD_2(reg,
  206. XM_MSK_RMTFLT, !enable,
  207. XM_MSK_LCLFLT, !enable);
  208. falcon_xmac_writel(efx, &reg, XM_MGT_INT_MSK_REG_MAC_B0);
  209. }
  210. int falcon_init_xmac(struct efx_nic *efx)
  211. {
  212. int rc;
  213. /* Initialize the PHY first so the clock is around */
  214. rc = efx->phy_op->init(efx);
  215. if (rc)
  216. goto fail1;
  217. rc = falcon_reset_xaui(efx);
  218. if (rc)
  219. goto fail2;
  220. /* Wait again. Give the PHY and MAC time to come back */
  221. schedule_timeout_uninterruptible(HZ / 10);
  222. rc = falcon_reset_xmac(efx);
  223. if (rc)
  224. goto fail2;
  225. falcon_mask_status_intr(efx, 1);
  226. return 0;
  227. fail2:
  228. efx->phy_op->fini(efx);
  229. fail1:
  230. return rc;
  231. }
  232. int falcon_xaui_link_ok(struct efx_nic *efx)
  233. {
  234. efx_dword_t reg;
  235. int align_done, sync_status, link_ok = 0;
  236. /* Read link status */
  237. falcon_xmac_readl(efx, &reg, XX_CORE_STAT_REG_MAC);
  238. align_done = EFX_DWORD_FIELD(reg, XX_ALIGN_DONE);
  239. sync_status = EFX_DWORD_FIELD(reg, XX_SYNC_STAT);
  240. if (align_done && (sync_status == XX_SYNC_STAT_DECODE_SYNCED))
  241. link_ok = 1;
  242. /* Clear link status ready for next read */
  243. EFX_SET_DWORD_FIELD(reg, XX_COMMA_DET, XX_COMMA_DET_RESET);
  244. EFX_SET_DWORD_FIELD(reg, XX_CHARERR, XX_CHARERR_RESET);
  245. EFX_SET_DWORD_FIELD(reg, XX_DISPERR, XX_DISPERR_RESET);
  246. falcon_xmac_writel(efx, &reg, XX_CORE_STAT_REG_MAC);
  247. /* If the link is up, then check the phy side of the xaui link
  248. * (error conditions from the wire side propoagate back through
  249. * the phy to the xaui side). */
  250. if (efx->link_up && link_ok) {
  251. int has_phyxs = efx->phy_op->mmds & (1 << MDIO_MMD_PHYXS);
  252. if (has_phyxs)
  253. link_ok = mdio_clause45_phyxgxs_lane_sync(efx);
  254. }
  255. /* If the PHY and XAUI links are up, then check the mac's xgmii
  256. * fault state */
  257. if (efx->link_up && link_ok)
  258. link_ok = falcon_xgmii_status(efx);
  259. return link_ok;
  260. }
  261. static void falcon_reconfigure_xmac_core(struct efx_nic *efx)
  262. {
  263. unsigned int max_frame_len;
  264. efx_dword_t reg;
  265. int rx_fc = (efx->flow_control & EFX_FC_RX) ? 1 : 0;
  266. /* Configure MAC - cut-thru mode is hard wired on */
  267. EFX_POPULATE_DWORD_3(reg,
  268. XM_RX_JUMBO_MODE, 1,
  269. XM_TX_STAT_EN, 1,
  270. XM_RX_STAT_EN, 1);
  271. falcon_xmac_writel(efx, &reg, XM_GLB_CFG_REG_MAC);
  272. /* Configure TX */
  273. EFX_POPULATE_DWORD_6(reg,
  274. XM_TXEN, 1,
  275. XM_TX_PRMBL, 1,
  276. XM_AUTO_PAD, 1,
  277. XM_TXCRC, 1,
  278. XM_FCNTL, 1,
  279. XM_IPG, 0x3);
  280. falcon_xmac_writel(efx, &reg, XM_TX_CFG_REG_MAC);
  281. /* Configure RX */
  282. EFX_POPULATE_DWORD_5(reg,
  283. XM_RXEN, 1,
  284. XM_AUTO_DEPAD, 0,
  285. XM_ACPT_ALL_MCAST, 1,
  286. XM_ACPT_ALL_UCAST, efx->promiscuous,
  287. XM_PASS_CRC_ERR, 1);
  288. falcon_xmac_writel(efx, &reg, XM_RX_CFG_REG_MAC);
  289. /* Set frame length */
  290. max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
  291. EFX_POPULATE_DWORD_1(reg, XM_MAX_RX_FRM_SIZE, max_frame_len);
  292. falcon_xmac_writel(efx, &reg, XM_RX_PARAM_REG_MAC);
  293. EFX_POPULATE_DWORD_2(reg,
  294. XM_MAX_TX_FRM_SIZE, max_frame_len,
  295. XM_TX_JUMBO_MODE, 1);
  296. falcon_xmac_writel(efx, &reg, XM_TX_PARAM_REG_MAC);
  297. EFX_POPULATE_DWORD_2(reg,
  298. XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */
  299. XM_DIS_FCNTL, rx_fc ? 0 : 1);
  300. falcon_xmac_writel(efx, &reg, XM_FC_REG_MAC);
  301. /* Set MAC address */
  302. EFX_POPULATE_DWORD_4(reg,
  303. XM_ADR_0, efx->net_dev->dev_addr[0],
  304. XM_ADR_1, efx->net_dev->dev_addr[1],
  305. XM_ADR_2, efx->net_dev->dev_addr[2],
  306. XM_ADR_3, efx->net_dev->dev_addr[3]);
  307. falcon_xmac_writel(efx, &reg, XM_ADR_LO_REG_MAC);
  308. EFX_POPULATE_DWORD_2(reg,
  309. XM_ADR_4, efx->net_dev->dev_addr[4],
  310. XM_ADR_5, efx->net_dev->dev_addr[5]);
  311. falcon_xmac_writel(efx, &reg, XM_ADR_HI_REG_MAC);
  312. }
  313. /* Try and bring the Falcon side of the Falcon-Phy XAUI link fails
  314. * to come back up. Bash it until it comes back up */
  315. static int falcon_check_xaui_link_up(struct efx_nic *efx)
  316. {
  317. int max_tries, tries;
  318. tries = EFX_WORKAROUND_5147(efx) ? 5 : 1;
  319. max_tries = tries;
  320. if (efx->phy_type == PHY_TYPE_NONE)
  321. return 0;
  322. while (tries) {
  323. if (falcon_xaui_link_ok(efx))
  324. return 1;
  325. EFX_LOG(efx, "%s Clobbering XAUI (%d tries left).\n",
  326. __func__, tries);
  327. (void) falcon_reset_xaui(efx);
  328. udelay(200);
  329. tries--;
  330. }
  331. EFX_ERR(efx, "Failed to bring XAUI link back up in %d tries!\n",
  332. max_tries);
  333. return 0;
  334. }
  335. void falcon_reconfigure_xmac(struct efx_nic *efx)
  336. {
  337. int xaui_link_ok;
  338. falcon_mask_status_intr(efx, 0);
  339. falcon_deconfigure_mac_wrapper(efx);
  340. efx->phy_op->reconfigure(efx);
  341. falcon_reconfigure_xmac_core(efx);
  342. falcon_reconfigure_mac_wrapper(efx);
  343. /* Ensure XAUI link is up */
  344. xaui_link_ok = falcon_check_xaui_link_up(efx);
  345. if (xaui_link_ok && efx->link_up)
  346. falcon_mask_status_intr(efx, 1);
  347. }
  348. void falcon_fini_xmac(struct efx_nic *efx)
  349. {
  350. /* Isolate the MAC - PHY */
  351. falcon_deconfigure_mac_wrapper(efx);
  352. /* Potentially power down the PHY */
  353. efx->phy_op->fini(efx);
  354. }
  355. void falcon_update_stats_xmac(struct efx_nic *efx)
  356. {
  357. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  358. int rc;
  359. rc = falcon_dma_stats(efx, XgDmaDone_offset);
  360. if (rc)
  361. return;
  362. /* Update MAC stats from DMAed values */
  363. FALCON_STAT(efx, XgRxOctets, rx_bytes);
  364. FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes);
  365. FALCON_STAT(efx, XgRxPkts, rx_packets);
  366. FALCON_STAT(efx, XgRxPktsOK, rx_good);
  367. FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast);
  368. FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast);
  369. FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast);
  370. FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64);
  371. FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo);
  372. FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo);
  373. FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64);
  374. FALCON_STAT(efx, XgRxDropEvents, rx_overflow);
  375. FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad);
  376. FALCON_STAT(efx, XgRxAlignError, rx_align_error);
  377. FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error);
  378. FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error);
  379. FALCON_STAT(efx, XgRxControlPkts, rx_control);
  380. FALCON_STAT(efx, XgRxPausePkts, rx_pause);
  381. FALCON_STAT(efx, XgRxPkts64Octets, rx_64);
  382. FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127);
  383. FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255);
  384. FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511);
  385. FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023);
  386. FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx);
  387. FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo);
  388. FALCON_STAT(efx, XgRxLengthError, rx_length_error);
  389. FALCON_STAT(efx, XgTxPkts, tx_packets);
  390. FALCON_STAT(efx, XgTxOctets, tx_bytes);
  391. FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast);
  392. FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast);
  393. FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast);
  394. FALCON_STAT(efx, XgTxControlPkts, tx_control);
  395. FALCON_STAT(efx, XgTxPausePkts, tx_pause);
  396. FALCON_STAT(efx, XgTxPkts64Octets, tx_64);
  397. FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127);
  398. FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255);
  399. FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511);
  400. FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023);
  401. FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx);
  402. FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo);
  403. FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64);
  404. FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo);
  405. FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp);
  406. FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error);
  407. FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error);
  408. /* Update derived statistics */
  409. mac_stats->tx_good_bytes =
  410. (mac_stats->tx_bytes - mac_stats->tx_bad_bytes);
  411. mac_stats->rx_bad_bytes =
  412. (mac_stats->rx_bytes - mac_stats->rx_good_bytes);
  413. }
  414. #define EFX_XAUI_RETRAIN_MAX 8
  415. int falcon_check_xmac(struct efx_nic *efx)
  416. {
  417. unsigned xaui_link_ok;
  418. int rc;
  419. falcon_mask_status_intr(efx, 0);
  420. xaui_link_ok = falcon_xaui_link_ok(efx);
  421. if (EFX_WORKAROUND_5147(efx) && !xaui_link_ok)
  422. (void) falcon_reset_xaui(efx);
  423. /* Call the PHY check_hw routine */
  424. rc = efx->phy_op->check_hw(efx);
  425. /* Unmask interrupt if everything was (and still is) ok */
  426. if (xaui_link_ok && efx->link_up)
  427. falcon_mask_status_intr(efx, 1);
  428. return rc;
  429. }
  430. /* Simulate a PHY event */
  431. void falcon_xmac_sim_phy_event(struct efx_nic *efx)
  432. {
  433. efx_qword_t phy_event;
  434. EFX_POPULATE_QWORD_2(phy_event,
  435. EV_CODE, GLOBAL_EV_DECODE,
  436. XG_PHY_INTR, 1);
  437. falcon_generate_event(&efx->channel[0], &phy_event);
  438. }
  439. int falcon_xmac_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  440. {
  441. mdio_clause45_get_settings(efx, ecmd);
  442. ecmd->transceiver = XCVR_INTERNAL;
  443. ecmd->phy_address = efx->mii.phy_id;
  444. ecmd->autoneg = AUTONEG_DISABLE;
  445. ecmd->duplex = DUPLEX_FULL;
  446. return 0;
  447. }
  448. int falcon_xmac_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  449. {
  450. if (ecmd->transceiver != XCVR_INTERNAL)
  451. return -EINVAL;
  452. if (ecmd->autoneg != AUTONEG_DISABLE)
  453. return -EINVAL;
  454. if (ecmd->duplex != DUPLEX_FULL)
  455. return -EINVAL;
  456. return mdio_clause45_set_settings(efx, ecmd);
  457. }
  458. int falcon_xmac_set_pause(struct efx_nic *efx, enum efx_fc_type flow_control)
  459. {
  460. int reset;
  461. if (flow_control & EFX_FC_AUTO) {
  462. EFX_LOG(efx, "10G does not support flow control "
  463. "autonegotiation\n");
  464. return -EINVAL;
  465. }
  466. if ((flow_control & EFX_FC_TX) && !(flow_control & EFX_FC_RX))
  467. return -EINVAL;
  468. /* TX flow control may automatically turn itself off if the
  469. * link partner (intermittently) stops responding to pause
  470. * frames. There isn't any indication that this has happened,
  471. * so the best we do is leave it up to the user to spot this
  472. * and fix it be cycling transmit flow control on this end. */
  473. reset = ((flow_control & EFX_FC_TX) &&
  474. !(efx->flow_control & EFX_FC_TX));
  475. if (EFX_WORKAROUND_11482(efx) && reset) {
  476. if (FALCON_REV(efx) >= FALCON_REV_B0) {
  477. /* Recover by resetting the EM block */
  478. if (efx->link_up)
  479. falcon_drain_tx_fifo(efx);
  480. } else {
  481. /* Schedule a reset to recover */
  482. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  483. }
  484. }
  485. efx->flow_control = flow_control;
  486. return 0;
  487. }