falcon_xmac.c 18 KB

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