tenxpress.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /****************************************************************************
  2. * Driver for Solarflare network controllers and boards
  3. * Copyright 2007-2011 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. #include <linux/delay.h>
  10. #include <linux/rtnetlink.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/slab.h>
  13. #include "efx.h"
  14. #include "mdio_10g.h"
  15. #include "nic.h"
  16. #include "phy.h"
  17. #include "workarounds.h"
  18. /* We expect these MMDs to be in the package. */
  19. #define TENXPRESS_REQUIRED_DEVS (MDIO_DEVS_PMAPMD | \
  20. MDIO_DEVS_PCS | \
  21. MDIO_DEVS_PHYXS | \
  22. MDIO_DEVS_AN)
  23. #define SFX7101_LOOPBACKS ((1 << LOOPBACK_PHYXS) | \
  24. (1 << LOOPBACK_PCS) | \
  25. (1 << LOOPBACK_PMAPMD) | \
  26. (1 << LOOPBACK_PHYXS_WS))
  27. /* We complain if we fail to see the link partner as 10G capable this many
  28. * times in a row (must be > 1 as sampling the autoneg. registers is racy)
  29. */
  30. #define MAX_BAD_LP_TRIES (5)
  31. /* Extended control register */
  32. #define PMA_PMD_XCONTROL_REG 49152
  33. #define PMA_PMD_EXT_GMII_EN_LBN 1
  34. #define PMA_PMD_EXT_GMII_EN_WIDTH 1
  35. #define PMA_PMD_EXT_CLK_OUT_LBN 2
  36. #define PMA_PMD_EXT_CLK_OUT_WIDTH 1
  37. #define PMA_PMD_LNPGA_POWERDOWN_LBN 8
  38. #define PMA_PMD_LNPGA_POWERDOWN_WIDTH 1
  39. #define PMA_PMD_EXT_CLK312_WIDTH 1
  40. #define PMA_PMD_EXT_LPOWER_LBN 12
  41. #define PMA_PMD_EXT_LPOWER_WIDTH 1
  42. #define PMA_PMD_EXT_ROBUST_LBN 14
  43. #define PMA_PMD_EXT_ROBUST_WIDTH 1
  44. #define PMA_PMD_EXT_SSR_LBN 15
  45. #define PMA_PMD_EXT_SSR_WIDTH 1
  46. /* extended status register */
  47. #define PMA_PMD_XSTATUS_REG 49153
  48. #define PMA_PMD_XSTAT_MDIX_LBN 14
  49. #define PMA_PMD_XSTAT_FLP_LBN (12)
  50. /* LED control register */
  51. #define PMA_PMD_LED_CTRL_REG 49159
  52. #define PMA_PMA_LED_ACTIVITY_LBN (3)
  53. /* LED function override register */
  54. #define PMA_PMD_LED_OVERR_REG 49161
  55. /* Bit positions for different LEDs (there are more but not wired on SFE4001)*/
  56. #define PMA_PMD_LED_LINK_LBN (0)
  57. #define PMA_PMD_LED_SPEED_LBN (2)
  58. #define PMA_PMD_LED_TX_LBN (4)
  59. #define PMA_PMD_LED_RX_LBN (6)
  60. /* Override settings */
  61. #define PMA_PMD_LED_AUTO (0) /* H/W control */
  62. #define PMA_PMD_LED_ON (1)
  63. #define PMA_PMD_LED_OFF (2)
  64. #define PMA_PMD_LED_FLASH (3)
  65. #define PMA_PMD_LED_MASK 3
  66. /* All LEDs under hardware control */
  67. /* Green and Amber under hardware control, Red off */
  68. #define SFX7101_PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
  69. #define PMA_PMD_SPEED_ENABLE_REG 49192
  70. #define PMA_PMD_100TX_ADV_LBN 1
  71. #define PMA_PMD_100TX_ADV_WIDTH 1
  72. #define PMA_PMD_1000T_ADV_LBN 2
  73. #define PMA_PMD_1000T_ADV_WIDTH 1
  74. #define PMA_PMD_10000T_ADV_LBN 3
  75. #define PMA_PMD_10000T_ADV_WIDTH 1
  76. #define PMA_PMD_SPEED_LBN 4
  77. #define PMA_PMD_SPEED_WIDTH 4
  78. /* Misc register defines */
  79. #define PCS_CLOCK_CTRL_REG 55297
  80. #define PLL312_RST_N_LBN 2
  81. #define PCS_SOFT_RST2_REG 55302
  82. #define SERDES_RST_N_LBN 13
  83. #define XGXS_RST_N_LBN 12
  84. #define PCS_TEST_SELECT_REG 55303 /* PRM 10.5.8 */
  85. #define CLK312_EN_LBN 3
  86. /* PHYXS registers */
  87. #define PHYXS_XCONTROL_REG 49152
  88. #define PHYXS_RESET_LBN 15
  89. #define PHYXS_RESET_WIDTH 1
  90. #define PHYXS_TEST1 (49162)
  91. #define LOOPBACK_NEAR_LBN (8)
  92. #define LOOPBACK_NEAR_WIDTH (1)
  93. /* Boot status register */
  94. #define PCS_BOOT_STATUS_REG 53248
  95. #define PCS_BOOT_FATAL_ERROR_LBN 0
  96. #define PCS_BOOT_PROGRESS_LBN 1
  97. #define PCS_BOOT_PROGRESS_WIDTH 2
  98. #define PCS_BOOT_PROGRESS_INIT 0
  99. #define PCS_BOOT_PROGRESS_WAIT_MDIO 1
  100. #define PCS_BOOT_PROGRESS_CHECKSUM 2
  101. #define PCS_BOOT_PROGRESS_JUMP 3
  102. #define PCS_BOOT_DOWNLOAD_WAIT_LBN 3
  103. #define PCS_BOOT_CODE_STARTED_LBN 4
  104. /* 100M/1G PHY registers */
  105. #define GPHY_XCONTROL_REG 49152
  106. #define GPHY_ISOLATE_LBN 10
  107. #define GPHY_ISOLATE_WIDTH 1
  108. #define GPHY_DUPLEX_LBN 8
  109. #define GPHY_DUPLEX_WIDTH 1
  110. #define GPHY_LOOPBACK_NEAR_LBN 14
  111. #define GPHY_LOOPBACK_NEAR_WIDTH 1
  112. #define C22EXT_STATUS_REG 49153
  113. #define C22EXT_STATUS_LINK_LBN 2
  114. #define C22EXT_STATUS_LINK_WIDTH 1
  115. #define C22EXT_MSTSLV_CTRL 49161
  116. #define C22EXT_MSTSLV_CTRL_ADV_1000_HD_LBN 8
  117. #define C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN 9
  118. #define C22EXT_MSTSLV_STATUS 49162
  119. #define C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN 10
  120. #define C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN 11
  121. /* Time to wait between powering down the LNPGA and turning off the power
  122. * rails */
  123. #define LNPGA_PDOWN_WAIT (HZ / 5)
  124. struct tenxpress_phy_data {
  125. enum efx_loopback_mode loopback_mode;
  126. enum efx_phy_mode phy_mode;
  127. int bad_lp_tries;
  128. };
  129. static int tenxpress_init(struct efx_nic *efx)
  130. {
  131. /* Enable 312.5 MHz clock */
  132. efx_mdio_write(efx, MDIO_MMD_PCS, PCS_TEST_SELECT_REG,
  133. 1 << CLK312_EN_LBN);
  134. /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
  135. efx_mdio_set_flag(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_CTRL_REG,
  136. 1 << PMA_PMA_LED_ACTIVITY_LBN, true);
  137. efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG,
  138. SFX7101_PMA_PMD_LED_DEFAULT);
  139. return 0;
  140. }
  141. static int tenxpress_phy_probe(struct efx_nic *efx)
  142. {
  143. struct tenxpress_phy_data *phy_data;
  144. /* Allocate phy private storage */
  145. phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
  146. if (!phy_data)
  147. return -ENOMEM;
  148. efx->phy_data = phy_data;
  149. phy_data->phy_mode = efx->phy_mode;
  150. efx->mdio.mmds = TENXPRESS_REQUIRED_DEVS;
  151. efx->mdio.mode_support = MDIO_SUPPORTS_C45;
  152. efx->loopback_modes = SFX7101_LOOPBACKS | FALCON_XMAC_LOOPBACKS;
  153. efx->link_advertising = (ADVERTISED_TP | ADVERTISED_Autoneg |
  154. ADVERTISED_10000baseT_Full);
  155. return 0;
  156. }
  157. static int tenxpress_phy_init(struct efx_nic *efx)
  158. {
  159. int rc;
  160. falcon_board(efx)->type->init_phy(efx);
  161. if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
  162. rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
  163. if (rc < 0)
  164. return rc;
  165. rc = efx_mdio_check_mmds(efx, TENXPRESS_REQUIRED_DEVS);
  166. if (rc < 0)
  167. return rc;
  168. }
  169. rc = tenxpress_init(efx);
  170. if (rc < 0)
  171. return rc;
  172. /* Reinitialise flow control settings */
  173. efx_link_set_wanted_fc(efx, efx->wanted_fc);
  174. efx_mdio_an_reconfigure(efx);
  175. schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
  176. /* Let XGXS and SerDes out of reset */
  177. falcon_reset_xaui(efx);
  178. return 0;
  179. }
  180. /* Perform a "special software reset" on the PHY. The caller is
  181. * responsible for saving and restoring the PHY hardware registers
  182. * properly, and masking/unmasking LASI */
  183. static int tenxpress_special_reset(struct efx_nic *efx)
  184. {
  185. int rc, reg;
  186. /* The XGMAC clock is driven from the SFX7101 312MHz clock, so
  187. * a special software reset can glitch the XGMAC sufficiently for stats
  188. * requests to fail. */
  189. falcon_stop_nic_stats(efx);
  190. /* Initiate reset */
  191. reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
  192. reg |= (1 << PMA_PMD_EXT_SSR_LBN);
  193. efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
  194. mdelay(200);
  195. /* Wait for the blocks to come out of reset */
  196. rc = efx_mdio_wait_reset_mmds(efx, TENXPRESS_REQUIRED_DEVS);
  197. if (rc < 0)
  198. goto out;
  199. /* Try and reconfigure the device */
  200. rc = tenxpress_init(efx);
  201. if (rc < 0)
  202. goto out;
  203. /* Wait for the XGXS state machine to churn */
  204. mdelay(10);
  205. out:
  206. falcon_start_nic_stats(efx);
  207. return rc;
  208. }
  209. static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
  210. {
  211. struct tenxpress_phy_data *pd = efx->phy_data;
  212. bool bad_lp;
  213. int reg;
  214. if (link_ok) {
  215. bad_lp = false;
  216. } else {
  217. /* Check that AN has started but not completed. */
  218. reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_STAT1);
  219. if (!(reg & MDIO_AN_STAT1_LPABLE))
  220. return; /* LP status is unknown */
  221. bad_lp = !(reg & MDIO_AN_STAT1_COMPLETE);
  222. if (bad_lp)
  223. pd->bad_lp_tries++;
  224. }
  225. /* Nothing to do if all is well and was previously so. */
  226. if (!pd->bad_lp_tries)
  227. return;
  228. /* Use the RX (red) LED as an error indicator once we've seen AN
  229. * failure several times in a row, and also log a message. */
  230. if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
  231. reg = efx_mdio_read(efx, MDIO_MMD_PMAPMD,
  232. PMA_PMD_LED_OVERR_REG);
  233. reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
  234. if (!bad_lp) {
  235. reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
  236. } else {
  237. reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
  238. netif_err(efx, link, efx->net_dev,
  239. "appears to be plugged into a port"
  240. " that is not 10GBASE-T capable. The PHY"
  241. " supports 10GBASE-T ONLY, so no link can"
  242. " be established\n");
  243. }
  244. efx_mdio_write(efx, MDIO_MMD_PMAPMD,
  245. PMA_PMD_LED_OVERR_REG, reg);
  246. pd->bad_lp_tries = bad_lp;
  247. }
  248. }
  249. static bool sfx7101_link_ok(struct efx_nic *efx)
  250. {
  251. return efx_mdio_links_ok(efx,
  252. MDIO_DEVS_PMAPMD |
  253. MDIO_DEVS_PCS |
  254. MDIO_DEVS_PHYXS);
  255. }
  256. static void tenxpress_ext_loopback(struct efx_nic *efx)
  257. {
  258. efx_mdio_set_flag(efx, MDIO_MMD_PHYXS, PHYXS_TEST1,
  259. 1 << LOOPBACK_NEAR_LBN,
  260. efx->loopback_mode == LOOPBACK_PHYXS);
  261. }
  262. static void tenxpress_low_power(struct efx_nic *efx)
  263. {
  264. efx_mdio_set_mmds_lpower(
  265. efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
  266. TENXPRESS_REQUIRED_DEVS);
  267. }
  268. static int tenxpress_phy_reconfigure(struct efx_nic *efx)
  269. {
  270. struct tenxpress_phy_data *phy_data = efx->phy_data;
  271. bool phy_mode_change, loop_reset;
  272. if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
  273. phy_data->phy_mode = efx->phy_mode;
  274. return 0;
  275. }
  276. phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
  277. phy_data->phy_mode != PHY_MODE_NORMAL);
  278. loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, LOOPBACKS_EXTERNAL(efx)) ||
  279. LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
  280. if (loop_reset || phy_mode_change) {
  281. tenxpress_special_reset(efx);
  282. falcon_reset_xaui(efx);
  283. }
  284. tenxpress_low_power(efx);
  285. efx_mdio_transmit_disable(efx);
  286. efx_mdio_phy_reconfigure(efx);
  287. tenxpress_ext_loopback(efx);
  288. efx_mdio_an_reconfigure(efx);
  289. phy_data->loopback_mode = efx->loopback_mode;
  290. phy_data->phy_mode = efx->phy_mode;
  291. return 0;
  292. }
  293. static void
  294. tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd);
  295. /* Poll for link state changes */
  296. static bool tenxpress_phy_poll(struct efx_nic *efx)
  297. {
  298. struct efx_link_state old_state = efx->link_state;
  299. efx->link_state.up = sfx7101_link_ok(efx);
  300. efx->link_state.speed = 10000;
  301. efx->link_state.fd = true;
  302. efx->link_state.fc = efx_mdio_get_pause(efx);
  303. sfx7101_check_bad_lp(efx, efx->link_state.up);
  304. return !efx_link_state_equal(&efx->link_state, &old_state);
  305. }
  306. static void sfx7101_phy_fini(struct efx_nic *efx)
  307. {
  308. int reg;
  309. /* Power down the LNPGA */
  310. reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
  311. efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG, reg);
  312. /* Waiting here ensures that the board fini, which can turn
  313. * off the power to the PHY, won't get run until the LNPGA
  314. * powerdown has been given long enough to complete. */
  315. schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
  316. }
  317. static void tenxpress_phy_remove(struct efx_nic *efx)
  318. {
  319. kfree(efx->phy_data);
  320. efx->phy_data = NULL;
  321. }
  322. /* Override the RX, TX and link LEDs */
  323. void tenxpress_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  324. {
  325. int reg;
  326. switch (mode) {
  327. case EFX_LED_OFF:
  328. reg = (PMA_PMD_LED_OFF << PMA_PMD_LED_TX_LBN) |
  329. (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN) |
  330. (PMA_PMD_LED_OFF << PMA_PMD_LED_LINK_LBN);
  331. break;
  332. case EFX_LED_ON:
  333. reg = (PMA_PMD_LED_ON << PMA_PMD_LED_TX_LBN) |
  334. (PMA_PMD_LED_ON << PMA_PMD_LED_RX_LBN) |
  335. (PMA_PMD_LED_ON << PMA_PMD_LED_LINK_LBN);
  336. break;
  337. default:
  338. reg = SFX7101_PMA_PMD_LED_DEFAULT;
  339. break;
  340. }
  341. efx_mdio_write(efx, MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG, reg);
  342. }
  343. static const char *const sfx7101_test_names[] = {
  344. "bist"
  345. };
  346. static const char *sfx7101_test_name(struct efx_nic *efx, unsigned int index)
  347. {
  348. if (index < ARRAY_SIZE(sfx7101_test_names))
  349. return sfx7101_test_names[index];
  350. return NULL;
  351. }
  352. static int
  353. sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
  354. {
  355. int rc;
  356. if (!(flags & ETH_TEST_FL_OFFLINE))
  357. return 0;
  358. /* BIST is automatically run after a special software reset */
  359. rc = tenxpress_special_reset(efx);
  360. results[0] = rc ? -1 : 1;
  361. efx_mdio_an_reconfigure(efx);
  362. return rc;
  363. }
  364. static void
  365. tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  366. {
  367. u32 adv = 0, lpa = 0;
  368. int reg;
  369. reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL);
  370. if (reg & MDIO_AN_10GBT_CTRL_ADV10G)
  371. adv |= ADVERTISED_10000baseT_Full;
  372. reg = efx_mdio_read(efx, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
  373. if (reg & MDIO_AN_10GBT_STAT_LP10G)
  374. lpa |= ADVERTISED_10000baseT_Full;
  375. mdio45_ethtool_gset_npage(&efx->mdio, ecmd, adv, lpa);
  376. /* In loopback, the PHY automatically brings up the correct interface,
  377. * but doesn't advertise the correct speed. So override it */
  378. if (LOOPBACK_EXTERNAL(efx))
  379. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  380. }
  381. static int tenxpress_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  382. {
  383. if (!ecmd->autoneg)
  384. return -EINVAL;
  385. return efx_mdio_set_settings(efx, ecmd);
  386. }
  387. static void sfx7101_set_npage_adv(struct efx_nic *efx, u32 advertising)
  388. {
  389. efx_mdio_set_flag(efx, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
  390. MDIO_AN_10GBT_CTRL_ADV10G,
  391. advertising & ADVERTISED_10000baseT_Full);
  392. }
  393. const struct efx_phy_operations falcon_sfx7101_phy_ops = {
  394. .probe = tenxpress_phy_probe,
  395. .init = tenxpress_phy_init,
  396. .reconfigure = tenxpress_phy_reconfigure,
  397. .poll = tenxpress_phy_poll,
  398. .fini = sfx7101_phy_fini,
  399. .remove = tenxpress_phy_remove,
  400. .get_settings = tenxpress_get_settings,
  401. .set_settings = tenxpress_set_settings,
  402. .set_npage_adv = sfx7101_set_npage_adv,
  403. .test_alive = efx_mdio_test_alive,
  404. .test_name = sfx7101_test_name,
  405. .run_tests = sfx7101_run_tests,
  406. };