tenxpress.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /****************************************************************************
  2. * Driver for Solarflare 802.3an compliant PHY
  3. * Copyright 2007 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/seq_file.h>
  11. #include "efx.h"
  12. #include "mdio_10g.h"
  13. #include "falcon.h"
  14. #include "phy.h"
  15. #include "falcon_hwdefs.h"
  16. #include "boards.h"
  17. #include "mac.h"
  18. /* We expect these MMDs to be in the package */
  19. /* AN not here as mdio_check_mmds() requires STAT2 support */
  20. #define TENXPRESS_REQUIRED_DEVS (MDIO_MMDREG_DEVS0_PMAPMD | \
  21. MDIO_MMDREG_DEVS0_PCS | \
  22. MDIO_MMDREG_DEVS0_PHYXS)
  23. #define TENXPRESS_LOOPBACKS ((1 << LOOPBACK_PHYXS) | \
  24. (1 << LOOPBACK_PCS) | \
  25. (1 << LOOPBACK_PMAPMD) | \
  26. (1 << LOOPBACK_NETWORK))
  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 0xc000
  33. #define PMA_PMD_LNPGA_POWERDOWN_LBN 8
  34. #define PMA_PMD_LNPGA_POWERDOWN_WIDTH 1
  35. /* extended status register */
  36. #define PMA_PMD_XSTATUS_REG 0xc001
  37. #define PMA_PMD_XSTAT_FLP_LBN (12)
  38. /* LED control register */
  39. #define PMA_PMD_LED_CTRL_REG (0xc007)
  40. #define PMA_PMA_LED_ACTIVITY_LBN (3)
  41. /* LED function override register */
  42. #define PMA_PMD_LED_OVERR_REG (0xc009)
  43. /* Bit positions for different LEDs (there are more but not wired on SFE4001)*/
  44. #define PMA_PMD_LED_LINK_LBN (0)
  45. #define PMA_PMD_LED_SPEED_LBN (2)
  46. #define PMA_PMD_LED_TX_LBN (4)
  47. #define PMA_PMD_LED_RX_LBN (6)
  48. /* Override settings */
  49. #define PMA_PMD_LED_AUTO (0) /* H/W control */
  50. #define PMA_PMD_LED_ON (1)
  51. #define PMA_PMD_LED_OFF (2)
  52. #define PMA_PMD_LED_FLASH (3)
  53. /* All LEDs under hardware control */
  54. #define PMA_PMD_LED_FULL_AUTO (0)
  55. /* Green and Amber under hardware control, Red off */
  56. #define PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
  57. /* Special Software reset register */
  58. #define PMA_PMD_EXT_CTRL_REG 49152
  59. #define PMA_PMD_EXT_SSR_LBN 15
  60. /* Misc register defines */
  61. #define PCS_CLOCK_CTRL_REG 0xd801
  62. #define PLL312_RST_N_LBN 2
  63. #define PCS_SOFT_RST2_REG 0xd806
  64. #define SERDES_RST_N_LBN 13
  65. #define XGXS_RST_N_LBN 12
  66. #define PCS_TEST_SELECT_REG 0xd807 /* PRM 10.5.8 */
  67. #define CLK312_EN_LBN 3
  68. /* PHYXS registers */
  69. #define PHYXS_TEST1 (49162)
  70. #define LOOPBACK_NEAR_LBN (8)
  71. #define LOOPBACK_NEAR_WIDTH (1)
  72. /* Boot status register */
  73. #define PCS_BOOT_STATUS_REG (0xd000)
  74. #define PCS_BOOT_FATAL_ERR_LBN (0)
  75. #define PCS_BOOT_PROGRESS_LBN (1)
  76. #define PCS_BOOT_PROGRESS_WIDTH (2)
  77. #define PCS_BOOT_COMPLETE_LBN (3)
  78. #define PCS_BOOT_MAX_DELAY (100)
  79. #define PCS_BOOT_POLL_DELAY (10)
  80. /* Time to wait between powering down the LNPGA and turning off the power
  81. * rails */
  82. #define LNPGA_PDOWN_WAIT (HZ / 5)
  83. static int crc_error_reset_threshold = 100;
  84. module_param(crc_error_reset_threshold, int, 0644);
  85. MODULE_PARM_DESC(crc_error_reset_threshold,
  86. "Max number of CRC errors before XAUI reset");
  87. struct tenxpress_phy_data {
  88. enum efx_loopback_mode loopback_mode;
  89. atomic_t bad_crc_count;
  90. enum efx_phy_mode phy_mode;
  91. int bad_lp_tries;
  92. };
  93. void tenxpress_crc_err(struct efx_nic *efx)
  94. {
  95. struct tenxpress_phy_data *phy_data = efx->phy_data;
  96. if (phy_data != NULL)
  97. atomic_inc(&phy_data->bad_crc_count);
  98. }
  99. /* Check that the C166 has booted successfully */
  100. static int tenxpress_phy_check(struct efx_nic *efx)
  101. {
  102. int phy_id = efx->mii.phy_id;
  103. int count = PCS_BOOT_MAX_DELAY / PCS_BOOT_POLL_DELAY;
  104. int boot_stat;
  105. /* Wait for the boot to complete (or not) */
  106. while (count) {
  107. boot_stat = mdio_clause45_read(efx, phy_id,
  108. MDIO_MMD_PCS,
  109. PCS_BOOT_STATUS_REG);
  110. if (boot_stat & (1 << PCS_BOOT_COMPLETE_LBN))
  111. break;
  112. count--;
  113. udelay(PCS_BOOT_POLL_DELAY);
  114. }
  115. if (!count) {
  116. EFX_ERR(efx, "%s: PHY boot timed out. Last status "
  117. "%x\n", __func__,
  118. (boot_stat >> PCS_BOOT_PROGRESS_LBN) &
  119. ((1 << PCS_BOOT_PROGRESS_WIDTH) - 1));
  120. return -ETIMEDOUT;
  121. }
  122. return 0;
  123. }
  124. static int tenxpress_init(struct efx_nic *efx)
  125. {
  126. int rc, reg;
  127. /* Turn on the clock */
  128. reg = (1 << CLK312_EN_LBN);
  129. mdio_clause45_write(efx, efx->mii.phy_id,
  130. MDIO_MMD_PCS, PCS_TEST_SELECT_REG, reg);
  131. rc = tenxpress_phy_check(efx);
  132. if (rc < 0)
  133. return rc;
  134. /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
  135. reg = mdio_clause45_read(efx, efx->mii.phy_id,
  136. MDIO_MMD_PMAPMD, PMA_PMD_LED_CTRL_REG);
  137. reg |= (1 << PMA_PMA_LED_ACTIVITY_LBN);
  138. mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  139. PMA_PMD_LED_CTRL_REG, reg);
  140. reg = PMA_PMD_LED_DEFAULT;
  141. mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  142. PMA_PMD_LED_OVERR_REG, reg);
  143. return rc;
  144. }
  145. static int tenxpress_phy_init(struct efx_nic *efx)
  146. {
  147. struct tenxpress_phy_data *phy_data;
  148. int rc = 0;
  149. phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
  150. if (!phy_data)
  151. return -ENOMEM;
  152. efx->phy_data = phy_data;
  153. phy_data->phy_mode = efx->phy_mode;
  154. rc = mdio_clause45_wait_reset_mmds(efx,
  155. TENXPRESS_REQUIRED_DEVS);
  156. if (rc < 0)
  157. goto fail;
  158. rc = mdio_clause45_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
  159. if (rc < 0)
  160. goto fail;
  161. rc = tenxpress_init(efx);
  162. if (rc < 0)
  163. goto fail;
  164. schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
  165. /* Let XGXS and SerDes out of reset and resets 10XPress */
  166. falcon_reset_xaui(efx);
  167. return 0;
  168. fail:
  169. kfree(efx->phy_data);
  170. efx->phy_data = NULL;
  171. return rc;
  172. }
  173. static int tenxpress_special_reset(struct efx_nic *efx)
  174. {
  175. int rc, reg;
  176. /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so
  177. * a special software reset can glitch the XGMAC sufficiently for stats
  178. * requests to fail. Since we don't ofen special_reset, just lock. */
  179. spin_lock(&efx->stats_lock);
  180. /* Initiate reset */
  181. reg = mdio_clause45_read(efx, efx->mii.phy_id,
  182. MDIO_MMD_PMAPMD, PMA_PMD_EXT_CTRL_REG);
  183. reg |= (1 << PMA_PMD_EXT_SSR_LBN);
  184. mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  185. PMA_PMD_EXT_CTRL_REG, reg);
  186. mdelay(200);
  187. /* Wait for the blocks to come out of reset */
  188. rc = mdio_clause45_wait_reset_mmds(efx,
  189. TENXPRESS_REQUIRED_DEVS);
  190. if (rc < 0)
  191. goto unlock;
  192. /* Try and reconfigure the device */
  193. rc = tenxpress_init(efx);
  194. if (rc < 0)
  195. goto unlock;
  196. unlock:
  197. spin_unlock(&efx->stats_lock);
  198. return rc;
  199. }
  200. static void tenxpress_set_bad_lp(struct efx_nic *efx, bool bad_lp)
  201. {
  202. struct tenxpress_phy_data *pd = efx->phy_data;
  203. int reg;
  204. /* Nothing to do if all is well and was previously so. */
  205. if (!(bad_lp || pd->bad_lp_tries))
  206. return;
  207. reg = mdio_clause45_read(efx, efx->mii.phy_id,
  208. MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG);
  209. if (bad_lp)
  210. pd->bad_lp_tries++;
  211. else
  212. pd->bad_lp_tries = 0;
  213. if (pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
  214. pd->bad_lp_tries = 0; /* Restart count */
  215. reg &= ~(PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN);
  216. reg |= (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN);
  217. EFX_ERR(efx, "This NIC appears to be plugged into"
  218. " a port that is not 10GBASE-T capable.\n"
  219. " This PHY is 10GBASE-T ONLY, so no link can"
  220. " be established.\n");
  221. } else {
  222. reg |= (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN);
  223. }
  224. mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  225. PMA_PMD_LED_OVERR_REG, reg);
  226. }
  227. /* Check link status and return a boolean OK value. If the link is NOT
  228. * OK we have a quick rummage round to see if we appear to be plugged
  229. * into a non-10GBT port and if so warn the user that they won't get
  230. * link any time soon as we are 10GBT only, unless caller specified
  231. * not to do this check (it isn't useful in loopback) */
  232. static bool tenxpress_link_ok(struct efx_nic *efx, bool check_lp)
  233. {
  234. bool ok = mdio_clause45_links_ok(efx, TENXPRESS_REQUIRED_DEVS);
  235. if (ok) {
  236. tenxpress_set_bad_lp(efx, false);
  237. } else if (check_lp) {
  238. /* Are we plugged into the wrong sort of link? */
  239. bool bad_lp = false;
  240. int phy_id = efx->mii.phy_id;
  241. int an_stat = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  242. MDIO_AN_STATUS);
  243. int xphy_stat = mdio_clause45_read(efx, phy_id,
  244. MDIO_MMD_PMAPMD,
  245. PMA_PMD_XSTATUS_REG);
  246. /* Are we plugged into anything that sends FLPs? If
  247. * not we can't distinguish between not being plugged
  248. * in and being plugged into a non-AN antique. The FLP
  249. * bit has the advantage of not clearing when autoneg
  250. * restarts. */
  251. if (!(xphy_stat & (1 << PMA_PMD_XSTAT_FLP_LBN))) {
  252. tenxpress_set_bad_lp(efx, false);
  253. return ok;
  254. }
  255. /* If it can do 10GBT it must be XNP capable */
  256. bad_lp = !(an_stat & (1 << MDIO_AN_STATUS_XNP_LBN));
  257. if (!bad_lp && (an_stat & (1 << MDIO_AN_STATUS_PAGE_LBN))) {
  258. bad_lp = !(mdio_clause45_read(efx, phy_id,
  259. MDIO_MMD_AN, MDIO_AN_10GBT_STATUS) &
  260. (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN));
  261. }
  262. tenxpress_set_bad_lp(efx, bad_lp);
  263. }
  264. return ok;
  265. }
  266. static void tenxpress_phyxs_loopback(struct efx_nic *efx)
  267. {
  268. int phy_id = efx->mii.phy_id;
  269. int ctrl1, ctrl2;
  270. ctrl1 = ctrl2 = mdio_clause45_read(efx, phy_id, MDIO_MMD_PHYXS,
  271. PHYXS_TEST1);
  272. if (efx->loopback_mode == LOOPBACK_PHYXS)
  273. ctrl2 |= (1 << LOOPBACK_NEAR_LBN);
  274. else
  275. ctrl2 &= ~(1 << LOOPBACK_NEAR_LBN);
  276. if (ctrl1 != ctrl2)
  277. mdio_clause45_write(efx, phy_id, MDIO_MMD_PHYXS,
  278. PHYXS_TEST1, ctrl2);
  279. }
  280. static void tenxpress_phy_reconfigure(struct efx_nic *efx)
  281. {
  282. struct tenxpress_phy_data *phy_data = efx->phy_data;
  283. bool loop_change = LOOPBACK_OUT_OF(phy_data, efx,
  284. TENXPRESS_LOOPBACKS);
  285. if (efx->phy_mode & PHY_MODE_SPECIAL) {
  286. phy_data->phy_mode = efx->phy_mode;
  287. return;
  288. }
  289. /* When coming out of transmit disable, coming out of low power
  290. * mode, or moving out of any PHY internal loopback mode,
  291. * perform a special software reset */
  292. if ((efx->phy_mode == PHY_MODE_NORMAL &&
  293. phy_data->phy_mode != PHY_MODE_NORMAL) ||
  294. loop_change) {
  295. tenxpress_special_reset(efx);
  296. falcon_reset_xaui(efx);
  297. }
  298. mdio_clause45_transmit_disable(efx);
  299. mdio_clause45_phy_reconfigure(efx);
  300. tenxpress_phyxs_loopback(efx);
  301. phy_data->loopback_mode = efx->loopback_mode;
  302. phy_data->phy_mode = efx->phy_mode;
  303. efx->link_up = tenxpress_link_ok(efx, false);
  304. efx->link_speed = 10000;
  305. efx->link_fd = true;
  306. }
  307. static void tenxpress_phy_clear_interrupt(struct efx_nic *efx)
  308. {
  309. /* Nothing done here - LASI interrupts aren't reliable so poll */
  310. }
  311. /* Poll PHY for interrupt */
  312. static int tenxpress_phy_check_hw(struct efx_nic *efx)
  313. {
  314. struct tenxpress_phy_data *phy_data = efx->phy_data;
  315. bool link_ok;
  316. int rc = 0;
  317. link_ok = tenxpress_link_ok(efx, true);
  318. if (link_ok != efx->link_up)
  319. falcon_xmac_sim_phy_event(efx);
  320. if (phy_data->phy_mode != PHY_MODE_NORMAL)
  321. return 0;
  322. if (atomic_read(&phy_data->bad_crc_count) > crc_error_reset_threshold) {
  323. EFX_ERR(efx, "Resetting XAUI due to too many CRC errors\n");
  324. falcon_reset_xaui(efx);
  325. atomic_set(&phy_data->bad_crc_count, 0);
  326. }
  327. rc = efx->board_info.monitor(efx);
  328. if (rc) {
  329. EFX_ERR(efx, "Board sensor %s; shutting down PHY\n",
  330. (rc == -ERANGE) ? "reported fault" : "failed");
  331. if (efx->phy_mode & PHY_MODE_OFF) {
  332. /* Assume that board has shut PHY off */
  333. phy_data->phy_mode = PHY_MODE_OFF;
  334. } else {
  335. efx->phy_mode |= PHY_MODE_LOW_POWER;
  336. mdio_clause45_set_mmds_lpower(efx, true,
  337. efx->phy_op->mmds);
  338. phy_data->phy_mode |= PHY_MODE_LOW_POWER;
  339. }
  340. }
  341. return rc;
  342. }
  343. static void tenxpress_phy_fini(struct efx_nic *efx)
  344. {
  345. int reg;
  346. /* Power down the LNPGA */
  347. reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
  348. mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  349. PMA_PMD_XCONTROL_REG, reg);
  350. /* Waiting here ensures that the board fini, which can turn off the
  351. * power to the PHY, won't get run until the LNPGA powerdown has been
  352. * given long enough to complete. */
  353. schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
  354. kfree(efx->phy_data);
  355. efx->phy_data = NULL;
  356. }
  357. /* Set the RX and TX LEDs and Link LED flashing. The other LEDs
  358. * (which probably aren't wired anyway) are left in AUTO mode */
  359. void tenxpress_phy_blink(struct efx_nic *efx, bool blink)
  360. {
  361. int reg;
  362. if (blink)
  363. reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) |
  364. (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) |
  365. (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN);
  366. else
  367. reg = PMA_PMD_LED_DEFAULT;
  368. mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  369. PMA_PMD_LED_OVERR_REG, reg);
  370. }
  371. static int tenxpress_phy_test(struct efx_nic *efx)
  372. {
  373. /* BIST is automatically run after a special software reset */
  374. return tenxpress_special_reset(efx);
  375. }
  376. struct efx_phy_operations falcon_tenxpress_phy_ops = {
  377. .init = tenxpress_phy_init,
  378. .reconfigure = tenxpress_phy_reconfigure,
  379. .check_hw = tenxpress_phy_check_hw,
  380. .fini = tenxpress_phy_fini,
  381. .clear_interrupt = tenxpress_phy_clear_interrupt,
  382. .test = tenxpress_phy_test,
  383. .mmds = TENXPRESS_REQUIRED_DEVS,
  384. .loopbacks = TENXPRESS_LOOPBACKS,
  385. };