falcon_xmac.c 19 KB

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