falcon_xmac.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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) || LOOPBACK_INTERNAL(efx))
  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. if (LOOPBACK_INTERNAL(efx))
  240. return 1;
  241. /* Read link status */
  242. falcon_xmac_readl(efx, &reg, XX_CORE_STAT_REG_MAC);
  243. align_done = EFX_DWORD_FIELD(reg, XX_ALIGN_DONE);
  244. sync_status = EFX_DWORD_FIELD(reg, XX_SYNC_STAT);
  245. if (align_done && (sync_status == XX_SYNC_STAT_DECODE_SYNCED))
  246. link_ok = 1;
  247. /* Clear link status ready for next read */
  248. EFX_SET_DWORD_FIELD(reg, XX_COMMA_DET, XX_COMMA_DET_RESET);
  249. EFX_SET_DWORD_FIELD(reg, XX_CHARERR, XX_CHARERR_RESET);
  250. EFX_SET_DWORD_FIELD(reg, XX_DISPERR, XX_DISPERR_RESET);
  251. falcon_xmac_writel(efx, &reg, XX_CORE_STAT_REG_MAC);
  252. /* If the link is up, then check the phy side of the xaui link
  253. * (error conditions from the wire side propoagate back through
  254. * the phy to the xaui side). */
  255. if (efx->link_up && link_ok) {
  256. int has_phyxs = efx->phy_op->mmds & (1 << MDIO_MMD_PHYXS);
  257. if (has_phyxs)
  258. link_ok = mdio_clause45_phyxgxs_lane_sync(efx);
  259. }
  260. /* If the PHY and XAUI links are up, then check the mac's xgmii
  261. * fault state */
  262. if (efx->link_up && link_ok)
  263. link_ok = falcon_xgmii_status(efx);
  264. return link_ok;
  265. }
  266. static void falcon_reconfigure_xmac_core(struct efx_nic *efx)
  267. {
  268. unsigned int max_frame_len;
  269. efx_dword_t reg;
  270. int rx_fc = (efx->flow_control & EFX_FC_RX) ? 1 : 0;
  271. /* Configure MAC - cut-thru mode is hard wired on */
  272. EFX_POPULATE_DWORD_3(reg,
  273. XM_RX_JUMBO_MODE, 1,
  274. XM_TX_STAT_EN, 1,
  275. XM_RX_STAT_EN, 1);
  276. falcon_xmac_writel(efx, &reg, XM_GLB_CFG_REG_MAC);
  277. /* Configure TX */
  278. EFX_POPULATE_DWORD_6(reg,
  279. XM_TXEN, 1,
  280. XM_TX_PRMBL, 1,
  281. XM_AUTO_PAD, 1,
  282. XM_TXCRC, 1,
  283. XM_FCNTL, 1,
  284. XM_IPG, 0x3);
  285. falcon_xmac_writel(efx, &reg, XM_TX_CFG_REG_MAC);
  286. /* Configure RX */
  287. EFX_POPULATE_DWORD_5(reg,
  288. XM_RXEN, 1,
  289. XM_AUTO_DEPAD, 0,
  290. XM_ACPT_ALL_MCAST, 1,
  291. XM_ACPT_ALL_UCAST, efx->promiscuous,
  292. XM_PASS_CRC_ERR, 1);
  293. falcon_xmac_writel(efx, &reg, XM_RX_CFG_REG_MAC);
  294. /* Set frame length */
  295. max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
  296. EFX_POPULATE_DWORD_1(reg, XM_MAX_RX_FRM_SIZE, max_frame_len);
  297. falcon_xmac_writel(efx, &reg, XM_RX_PARAM_REG_MAC);
  298. EFX_POPULATE_DWORD_2(reg,
  299. XM_MAX_TX_FRM_SIZE, max_frame_len,
  300. XM_TX_JUMBO_MODE, 1);
  301. falcon_xmac_writel(efx, &reg, XM_TX_PARAM_REG_MAC);
  302. EFX_POPULATE_DWORD_2(reg,
  303. XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */
  304. XM_DIS_FCNTL, rx_fc ? 0 : 1);
  305. falcon_xmac_writel(efx, &reg, XM_FC_REG_MAC);
  306. /* Set MAC address */
  307. EFX_POPULATE_DWORD_4(reg,
  308. XM_ADR_0, efx->net_dev->dev_addr[0],
  309. XM_ADR_1, efx->net_dev->dev_addr[1],
  310. XM_ADR_2, efx->net_dev->dev_addr[2],
  311. XM_ADR_3, efx->net_dev->dev_addr[3]);
  312. falcon_xmac_writel(efx, &reg, XM_ADR_LO_REG_MAC);
  313. EFX_POPULATE_DWORD_2(reg,
  314. XM_ADR_4, efx->net_dev->dev_addr[4],
  315. XM_ADR_5, efx->net_dev->dev_addr[5]);
  316. falcon_xmac_writel(efx, &reg, XM_ADR_HI_REG_MAC);
  317. }
  318. static void falcon_reconfigure_xgxs_core(struct efx_nic *efx)
  319. {
  320. efx_dword_t reg;
  321. int xgxs_loopback = (efx->loopback_mode == LOOPBACK_XGXS) ? 1 : 0;
  322. int xaui_loopback = (efx->loopback_mode == LOOPBACK_XAUI) ? 1 : 0;
  323. int xgmii_loopback =
  324. (efx->loopback_mode == LOOPBACK_XGMII) ? 1 : 0;
  325. /* XGXS block is flaky and will need to be reset if moving
  326. * into our out of XGMII, XGXS or XAUI loopbacks. */
  327. if (EFX_WORKAROUND_5147(efx)) {
  328. int old_xgmii_loopback, old_xgxs_loopback, old_xaui_loopback;
  329. int reset_xgxs;
  330. falcon_xmac_readl(efx, &reg, XX_CORE_STAT_REG_MAC);
  331. old_xgxs_loopback = EFX_DWORD_FIELD(reg, XX_XGXS_LB_EN);
  332. old_xgmii_loopback = EFX_DWORD_FIELD(reg, XX_XGMII_LB_EN);
  333. falcon_xmac_readl(efx, &reg, XX_SD_CTL_REG_MAC);
  334. old_xaui_loopback = EFX_DWORD_FIELD(reg, XX_LPBKA);
  335. /* The PHY driver may have turned XAUI off */
  336. reset_xgxs = ((xgxs_loopback != old_xgxs_loopback) ||
  337. (xaui_loopback != old_xaui_loopback) ||
  338. (xgmii_loopback != old_xgmii_loopback));
  339. if (reset_xgxs) {
  340. falcon_xmac_readl(efx, &reg, XX_PWR_RST_REG_MAC);
  341. EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSTX_EN, 1);
  342. EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSRX_EN, 1);
  343. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  344. udelay(1);
  345. EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSTX_EN, 0);
  346. EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSRX_EN, 0);
  347. falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
  348. udelay(1);
  349. }
  350. }
  351. falcon_xmac_readl(efx, &reg, XX_CORE_STAT_REG_MAC);
  352. EFX_SET_DWORD_FIELD(reg, XX_FORCE_SIG,
  353. (xgxs_loopback || xaui_loopback) ?
  354. XX_FORCE_SIG_DECODE_FORCED : 0);
  355. EFX_SET_DWORD_FIELD(reg, XX_XGXS_LB_EN, xgxs_loopback);
  356. EFX_SET_DWORD_FIELD(reg, XX_XGMII_LB_EN, xgmii_loopback);
  357. falcon_xmac_writel(efx, &reg, XX_CORE_STAT_REG_MAC);
  358. falcon_xmac_readl(efx, &reg, XX_SD_CTL_REG_MAC);
  359. EFX_SET_DWORD_FIELD(reg, XX_LPBKD, xaui_loopback);
  360. EFX_SET_DWORD_FIELD(reg, XX_LPBKC, xaui_loopback);
  361. EFX_SET_DWORD_FIELD(reg, XX_LPBKB, xaui_loopback);
  362. EFX_SET_DWORD_FIELD(reg, XX_LPBKA, xaui_loopback);
  363. falcon_xmac_writel(efx, &reg, XX_SD_CTL_REG_MAC);
  364. }
  365. /* Try and bring the Falcon side of the Falcon-Phy XAUI link fails
  366. * to come back up. Bash it until it comes back up */
  367. static int falcon_check_xaui_link_up(struct efx_nic *efx)
  368. {
  369. int max_tries, tries;
  370. tries = EFX_WORKAROUND_5147(efx) ? 5 : 1;
  371. max_tries = tries;
  372. if ((efx->loopback_mode == LOOPBACK_NETWORK) ||
  373. (efx->phy_type == PHY_TYPE_NONE))
  374. return 0;
  375. while (tries) {
  376. if (falcon_xaui_link_ok(efx))
  377. return 1;
  378. EFX_LOG(efx, "%s Clobbering XAUI (%d tries left).\n",
  379. __func__, tries);
  380. (void) falcon_reset_xaui(efx);
  381. udelay(200);
  382. tries--;
  383. }
  384. EFX_ERR(efx, "Failed to bring XAUI link back up in %d tries!\n",
  385. max_tries);
  386. return 0;
  387. }
  388. void falcon_reconfigure_xmac(struct efx_nic *efx)
  389. {
  390. int xaui_link_ok;
  391. falcon_mask_status_intr(efx, 0);
  392. falcon_deconfigure_mac_wrapper(efx);
  393. efx->tx_disabled = LOOPBACK_INTERNAL(efx);
  394. efx->phy_op->reconfigure(efx);
  395. falcon_reconfigure_xgxs_core(efx);
  396. falcon_reconfigure_xmac_core(efx);
  397. falcon_reconfigure_mac_wrapper(efx);
  398. /* Ensure XAUI link is up */
  399. xaui_link_ok = falcon_check_xaui_link_up(efx);
  400. if (xaui_link_ok && efx->link_up)
  401. falcon_mask_status_intr(efx, 1);
  402. }
  403. void falcon_fini_xmac(struct efx_nic *efx)
  404. {
  405. /* Isolate the MAC - PHY */
  406. falcon_deconfigure_mac_wrapper(efx);
  407. /* Potentially power down the PHY */
  408. efx->phy_op->fini(efx);
  409. }
  410. void falcon_update_stats_xmac(struct efx_nic *efx)
  411. {
  412. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  413. int rc;
  414. rc = falcon_dma_stats(efx, XgDmaDone_offset);
  415. if (rc)
  416. return;
  417. /* Update MAC stats from DMAed values */
  418. FALCON_STAT(efx, XgRxOctets, rx_bytes);
  419. FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes);
  420. FALCON_STAT(efx, XgRxPkts, rx_packets);
  421. FALCON_STAT(efx, XgRxPktsOK, rx_good);
  422. FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast);
  423. FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast);
  424. FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast);
  425. FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64);
  426. FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo);
  427. FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo);
  428. FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64);
  429. FALCON_STAT(efx, XgRxDropEvents, rx_overflow);
  430. FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad);
  431. FALCON_STAT(efx, XgRxAlignError, rx_align_error);
  432. FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error);
  433. FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error);
  434. FALCON_STAT(efx, XgRxControlPkts, rx_control);
  435. FALCON_STAT(efx, XgRxPausePkts, rx_pause);
  436. FALCON_STAT(efx, XgRxPkts64Octets, rx_64);
  437. FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127);
  438. FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255);
  439. FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511);
  440. FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023);
  441. FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx);
  442. FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo);
  443. FALCON_STAT(efx, XgRxLengthError, rx_length_error);
  444. FALCON_STAT(efx, XgTxPkts, tx_packets);
  445. FALCON_STAT(efx, XgTxOctets, tx_bytes);
  446. FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast);
  447. FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast);
  448. FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast);
  449. FALCON_STAT(efx, XgTxControlPkts, tx_control);
  450. FALCON_STAT(efx, XgTxPausePkts, tx_pause);
  451. FALCON_STAT(efx, XgTxPkts64Octets, tx_64);
  452. FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127);
  453. FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255);
  454. FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511);
  455. FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023);
  456. FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx);
  457. FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo);
  458. FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64);
  459. FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo);
  460. FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp);
  461. FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error);
  462. FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error);
  463. /* Update derived statistics */
  464. mac_stats->tx_good_bytes =
  465. (mac_stats->tx_bytes - mac_stats->tx_bad_bytes);
  466. mac_stats->rx_bad_bytes =
  467. (mac_stats->rx_bytes - mac_stats->rx_good_bytes);
  468. }
  469. int falcon_check_xmac(struct efx_nic *efx)
  470. {
  471. unsigned xaui_link_ok;
  472. int rc;
  473. if ((efx->loopback_mode == LOOPBACK_NETWORK) ||
  474. (efx->phy_type == PHY_TYPE_NONE))
  475. return 0;
  476. falcon_mask_status_intr(efx, 0);
  477. xaui_link_ok = falcon_xaui_link_ok(efx);
  478. if (EFX_WORKAROUND_5147(efx) && !xaui_link_ok)
  479. (void) falcon_reset_xaui(efx);
  480. /* Call the PHY check_hw routine */
  481. rc = efx->phy_op->check_hw(efx);
  482. /* Unmask interrupt if everything was (and still is) ok */
  483. if (xaui_link_ok && efx->link_up)
  484. falcon_mask_status_intr(efx, 1);
  485. return rc;
  486. }
  487. /* Simulate a PHY event */
  488. void falcon_xmac_sim_phy_event(struct efx_nic *efx)
  489. {
  490. efx_qword_t phy_event;
  491. EFX_POPULATE_QWORD_2(phy_event,
  492. EV_CODE, GLOBAL_EV_DECODE,
  493. XG_PHY_INTR, 1);
  494. falcon_generate_event(&efx->channel[0], &phy_event);
  495. }
  496. int falcon_xmac_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  497. {
  498. mdio_clause45_get_settings(efx, ecmd);
  499. ecmd->transceiver = XCVR_INTERNAL;
  500. ecmd->phy_address = efx->mii.phy_id;
  501. ecmd->autoneg = AUTONEG_DISABLE;
  502. ecmd->duplex = DUPLEX_FULL;
  503. return 0;
  504. }
  505. int falcon_xmac_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  506. {
  507. if (ecmd->transceiver != XCVR_INTERNAL)
  508. return -EINVAL;
  509. if (ecmd->autoneg != AUTONEG_DISABLE)
  510. return -EINVAL;
  511. if (ecmd->duplex != DUPLEX_FULL)
  512. return -EINVAL;
  513. return mdio_clause45_set_settings(efx, ecmd);
  514. }
  515. int falcon_xmac_set_pause(struct efx_nic *efx, enum efx_fc_type flow_control)
  516. {
  517. int reset;
  518. if (flow_control & EFX_FC_AUTO) {
  519. EFX_LOG(efx, "10G does not support flow control "
  520. "autonegotiation\n");
  521. return -EINVAL;
  522. }
  523. if ((flow_control & EFX_FC_TX) && !(flow_control & EFX_FC_RX))
  524. return -EINVAL;
  525. /* TX flow control may automatically turn itself off if the
  526. * link partner (intermittently) stops responding to pause
  527. * frames. There isn't any indication that this has happened,
  528. * so the best we do is leave it up to the user to spot this
  529. * and fix it be cycling transmit flow control on this end. */
  530. reset = ((flow_control & EFX_FC_TX) &&
  531. !(efx->flow_control & EFX_FC_TX));
  532. if (EFX_WORKAROUND_11482(efx) && reset) {
  533. if (FALCON_REV(efx) >= FALCON_REV_B0) {
  534. /* Recover by resetting the EM block */
  535. if (efx->link_up)
  536. falcon_drain_tx_fifo(efx);
  537. } else {
  538. /* Schedule a reset to recover */
  539. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  540. }
  541. }
  542. efx->flow_control = flow_control;
  543. return 0;
  544. }