falcon_xmac.c 17 KB

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