tenxpress.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2007-2008 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 "workarounds.h"
  18. #include "selftest.h"
  19. /* We expect these MMDs to be in the package. SFT9001 also has a
  20. * clause 22 extension MMD, but since it doesn't have all the generic
  21. * MMD registers it is pointless to include it here.
  22. */
  23. #define TENXPRESS_REQUIRED_DEVS (MDIO_MMDREG_DEVS_PMAPMD | \
  24. MDIO_MMDREG_DEVS_PCS | \
  25. MDIO_MMDREG_DEVS_PHYXS | \
  26. MDIO_MMDREG_DEVS_AN)
  27. #define SFX7101_LOOPBACKS ((1 << LOOPBACK_PHYXS) | \
  28. (1 << LOOPBACK_PCS) | \
  29. (1 << LOOPBACK_PMAPMD) | \
  30. (1 << LOOPBACK_NETWORK))
  31. #define SFT9001_LOOPBACKS ((1 << LOOPBACK_GPHY) | \
  32. (1 << LOOPBACK_PHYXS) | \
  33. (1 << LOOPBACK_PCS) | \
  34. (1 << LOOPBACK_PMAPMD) | \
  35. (1 << LOOPBACK_NETWORK))
  36. /* We complain if we fail to see the link partner as 10G capable this many
  37. * times in a row (must be > 1 as sampling the autoneg. registers is racy)
  38. */
  39. #define MAX_BAD_LP_TRIES (5)
  40. /* LASI Control */
  41. #define PMA_PMD_LASI_CTRL 36866
  42. #define PMA_PMD_LASI_STATUS 36869
  43. #define PMA_PMD_LS_ALARM_LBN 0
  44. #define PMA_PMD_LS_ALARM_WIDTH 1
  45. #define PMA_PMD_TX_ALARM_LBN 1
  46. #define PMA_PMD_TX_ALARM_WIDTH 1
  47. #define PMA_PMD_RX_ALARM_LBN 2
  48. #define PMA_PMD_RX_ALARM_WIDTH 1
  49. #define PMA_PMD_AN_ALARM_LBN 3
  50. #define PMA_PMD_AN_ALARM_WIDTH 1
  51. /* Extended control register */
  52. #define PMA_PMD_XCONTROL_REG 49152
  53. #define PMA_PMD_EXT_GMII_EN_LBN 1
  54. #define PMA_PMD_EXT_GMII_EN_WIDTH 1
  55. #define PMA_PMD_EXT_CLK_OUT_LBN 2
  56. #define PMA_PMD_EXT_CLK_OUT_WIDTH 1
  57. #define PMA_PMD_LNPGA_POWERDOWN_LBN 8 /* SFX7101 only */
  58. #define PMA_PMD_LNPGA_POWERDOWN_WIDTH 1
  59. #define PMA_PMD_EXT_CLK312_LBN 8 /* SFT9001 only */
  60. #define PMA_PMD_EXT_CLK312_WIDTH 1
  61. #define PMA_PMD_EXT_LPOWER_LBN 12
  62. #define PMA_PMD_EXT_LPOWER_WIDTH 1
  63. #define PMA_PMD_EXT_ROBUST_LBN 14
  64. #define PMA_PMD_EXT_ROBUST_WIDTH 1
  65. #define PMA_PMD_EXT_SSR_LBN 15
  66. #define PMA_PMD_EXT_SSR_WIDTH 1
  67. /* extended status register */
  68. #define PMA_PMD_XSTATUS_REG 49153
  69. #define PMA_PMD_XSTAT_FLP_LBN (12)
  70. /* LED control register */
  71. #define PMA_PMD_LED_CTRL_REG 49159
  72. #define PMA_PMA_LED_ACTIVITY_LBN (3)
  73. /* LED function override register */
  74. #define PMA_PMD_LED_OVERR_REG 49161
  75. /* Bit positions for different LEDs (there are more but not wired on SFE4001)*/
  76. #define PMA_PMD_LED_LINK_LBN (0)
  77. #define PMA_PMD_LED_SPEED_LBN (2)
  78. #define PMA_PMD_LED_TX_LBN (4)
  79. #define PMA_PMD_LED_RX_LBN (6)
  80. /* Override settings */
  81. #define PMA_PMD_LED_AUTO (0) /* H/W control */
  82. #define PMA_PMD_LED_ON (1)
  83. #define PMA_PMD_LED_OFF (2)
  84. #define PMA_PMD_LED_FLASH (3)
  85. #define PMA_PMD_LED_MASK 3
  86. /* All LEDs under hardware control */
  87. #define PMA_PMD_LED_FULL_AUTO (0)
  88. /* Green and Amber under hardware control, Red off */
  89. #define PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
  90. #define PMA_PMD_SPEED_ENABLE_REG 49192
  91. #define PMA_PMD_100TX_ADV_LBN 1
  92. #define PMA_PMD_100TX_ADV_WIDTH 1
  93. #define PMA_PMD_1000T_ADV_LBN 2
  94. #define PMA_PMD_1000T_ADV_WIDTH 1
  95. #define PMA_PMD_10000T_ADV_LBN 3
  96. #define PMA_PMD_10000T_ADV_WIDTH 1
  97. #define PMA_PMD_SPEED_LBN 4
  98. #define PMA_PMD_SPEED_WIDTH 4
  99. /* Cable diagnostics - SFT9001 only */
  100. #define PMA_PMD_CDIAG_CTRL_REG 49213
  101. #define CDIAG_CTRL_IMMED_LBN 15
  102. #define CDIAG_CTRL_BRK_LINK_LBN 12
  103. #define CDIAG_CTRL_IN_PROG_LBN 11
  104. #define CDIAG_CTRL_LEN_UNIT_LBN 10
  105. #define CDIAG_CTRL_LEN_METRES 1
  106. #define PMA_PMD_CDIAG_RES_REG 49174
  107. #define CDIAG_RES_A_LBN 12
  108. #define CDIAG_RES_B_LBN 8
  109. #define CDIAG_RES_C_LBN 4
  110. #define CDIAG_RES_D_LBN 0
  111. #define CDIAG_RES_WIDTH 4
  112. #define CDIAG_RES_OPEN 2
  113. #define CDIAG_RES_OK 1
  114. #define CDIAG_RES_INVALID 0
  115. /* Set of 4 registers for pairs A-D */
  116. #define PMA_PMD_CDIAG_LEN_REG 49175
  117. /* Serdes control registers - SFT9001 only */
  118. #define PMA_PMD_CSERDES_CTRL_REG 64258
  119. /* Set the 156.25 MHz output to 312.5 MHz to drive Falcon's XMAC */
  120. #define PMA_PMD_CSERDES_DEFAULT 0x000f
  121. /* Misc register defines - SFX7101 only */
  122. #define PCS_CLOCK_CTRL_REG 55297
  123. #define PLL312_RST_N_LBN 2
  124. #define PCS_SOFT_RST2_REG 55302
  125. #define SERDES_RST_N_LBN 13
  126. #define XGXS_RST_N_LBN 12
  127. #define PCS_TEST_SELECT_REG 55303 /* PRM 10.5.8 */
  128. #define CLK312_EN_LBN 3
  129. /* PHYXS registers */
  130. #define PHYXS_XCONTROL_REG 49152
  131. #define PHYXS_RESET_LBN 15
  132. #define PHYXS_RESET_WIDTH 1
  133. #define PHYXS_TEST1 (49162)
  134. #define LOOPBACK_NEAR_LBN (8)
  135. #define LOOPBACK_NEAR_WIDTH (1)
  136. #define PCS_10GBASET_STAT1 32
  137. #define PCS_10GBASET_BLKLK_LBN 0
  138. #define PCS_10GBASET_BLKLK_WIDTH 1
  139. /* Boot status register */
  140. #define PCS_BOOT_STATUS_REG 53248
  141. #define PCS_BOOT_FATAL_ERR_LBN (0)
  142. #define PCS_BOOT_PROGRESS_LBN (1)
  143. #define PCS_BOOT_PROGRESS_WIDTH (2)
  144. #define PCS_BOOT_COMPLETE_LBN (3)
  145. #define PCS_BOOT_MAX_DELAY (100)
  146. #define PCS_BOOT_POLL_DELAY (10)
  147. /* 100M/1G PHY registers */
  148. #define GPHY_XCONTROL_REG 49152
  149. #define GPHY_ISOLATE_LBN 10
  150. #define GPHY_ISOLATE_WIDTH 1
  151. #define GPHY_DUPLEX_LBN 8
  152. #define GPHY_DUPLEX_WIDTH 1
  153. #define GPHY_LOOPBACK_NEAR_LBN 14
  154. #define GPHY_LOOPBACK_NEAR_WIDTH 1
  155. #define C22EXT_STATUS_REG 49153
  156. #define C22EXT_STATUS_LINK_LBN 2
  157. #define C22EXT_STATUS_LINK_WIDTH 1
  158. #define C22EXT_MSTSLV_REG 49162
  159. #define C22EXT_MSTSLV_1000_HD_LBN 10
  160. #define C22EXT_MSTSLV_1000_HD_WIDTH 1
  161. #define C22EXT_MSTSLV_1000_FD_LBN 11
  162. #define C22EXT_MSTSLV_1000_FD_WIDTH 1
  163. /* Time to wait between powering down the LNPGA and turning off the power
  164. * rails */
  165. #define LNPGA_PDOWN_WAIT (HZ / 5)
  166. static int crc_error_reset_threshold = 100;
  167. module_param(crc_error_reset_threshold, int, 0644);
  168. MODULE_PARM_DESC(crc_error_reset_threshold,
  169. "Max number of CRC errors before XAUI reset");
  170. struct tenxpress_phy_data {
  171. enum efx_loopback_mode loopback_mode;
  172. atomic_t bad_crc_count;
  173. enum efx_phy_mode phy_mode;
  174. int bad_lp_tries;
  175. };
  176. void tenxpress_crc_err(struct efx_nic *efx)
  177. {
  178. struct tenxpress_phy_data *phy_data = efx->phy_data;
  179. if (phy_data != NULL)
  180. atomic_inc(&phy_data->bad_crc_count);
  181. }
  182. static ssize_t show_phy_short_reach(struct device *dev,
  183. struct device_attribute *attr, char *buf)
  184. {
  185. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  186. int reg;
  187. reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  188. MDIO_PMAPMD_10GBT_TXPWR);
  189. return sprintf(buf, "%d\n",
  190. !!(reg & (1 << MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN)));
  191. }
  192. static ssize_t set_phy_short_reach(struct device *dev,
  193. struct device_attribute *attr,
  194. const char *buf, size_t count)
  195. {
  196. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  197. rtnl_lock();
  198. mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  199. MDIO_PMAPMD_10GBT_TXPWR,
  200. MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN,
  201. count != 0 && *buf != '0');
  202. efx_reconfigure_port(efx);
  203. rtnl_unlock();
  204. return count;
  205. }
  206. static DEVICE_ATTR(phy_short_reach, 0644, show_phy_short_reach,
  207. set_phy_short_reach);
  208. /* Check that the C166 has booted successfully */
  209. static int tenxpress_phy_check(struct efx_nic *efx)
  210. {
  211. int phy_id = efx->mii.phy_id;
  212. int count = PCS_BOOT_MAX_DELAY / PCS_BOOT_POLL_DELAY;
  213. int boot_stat;
  214. /* Wait for the boot to complete (or not) */
  215. while (count) {
  216. boot_stat = mdio_clause45_read(efx, phy_id,
  217. MDIO_MMD_PCS,
  218. PCS_BOOT_STATUS_REG);
  219. if (boot_stat & (1 << PCS_BOOT_COMPLETE_LBN))
  220. break;
  221. count--;
  222. udelay(PCS_BOOT_POLL_DELAY);
  223. }
  224. if (!count) {
  225. EFX_ERR(efx, "%s: PHY boot timed out. Last status "
  226. "%x\n", __func__,
  227. (boot_stat >> PCS_BOOT_PROGRESS_LBN) &
  228. ((1 << PCS_BOOT_PROGRESS_WIDTH) - 1));
  229. return -ETIMEDOUT;
  230. }
  231. return 0;
  232. }
  233. static int tenxpress_init(struct efx_nic *efx)
  234. {
  235. int phy_id = efx->mii.phy_id;
  236. int reg;
  237. int rc;
  238. if (efx->phy_type == PHY_TYPE_SFX7101) {
  239. /* Enable 312.5 MHz clock */
  240. mdio_clause45_write(efx, phy_id,
  241. MDIO_MMD_PCS, PCS_TEST_SELECT_REG,
  242. 1 << CLK312_EN_LBN);
  243. } else {
  244. /* Enable 312.5 MHz clock and GMII */
  245. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  246. PMA_PMD_XCONTROL_REG);
  247. reg |= ((1 << PMA_PMD_EXT_GMII_EN_LBN) |
  248. (1 << PMA_PMD_EXT_CLK_OUT_LBN) |
  249. (1 << PMA_PMD_EXT_CLK312_LBN) |
  250. (1 << PMA_PMD_EXT_ROBUST_LBN));
  251. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
  252. PMA_PMD_XCONTROL_REG, reg);
  253. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
  254. GPHY_XCONTROL_REG, GPHY_ISOLATE_LBN,
  255. false);
  256. }
  257. rc = tenxpress_phy_check(efx);
  258. if (rc < 0)
  259. return rc;
  260. /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
  261. if (efx->phy_type == PHY_TYPE_SFX7101) {
  262. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PMAPMD,
  263. PMA_PMD_LED_CTRL_REG,
  264. PMA_PMA_LED_ACTIVITY_LBN,
  265. true);
  266. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
  267. PMA_PMD_LED_OVERR_REG, PMA_PMD_LED_DEFAULT);
  268. }
  269. return rc;
  270. }
  271. static int tenxpress_phy_init(struct efx_nic *efx)
  272. {
  273. struct tenxpress_phy_data *phy_data;
  274. int rc = 0;
  275. phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
  276. if (!phy_data)
  277. return -ENOMEM;
  278. efx->phy_data = phy_data;
  279. phy_data->phy_mode = efx->phy_mode;
  280. if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
  281. if (efx->phy_type == PHY_TYPE_SFT9001A) {
  282. int reg;
  283. reg = mdio_clause45_read(efx, efx->mii.phy_id,
  284. MDIO_MMD_PMAPMD,
  285. PMA_PMD_XCONTROL_REG);
  286. reg |= (1 << PMA_PMD_EXT_SSR_LBN);
  287. mdio_clause45_write(efx, efx->mii.phy_id,
  288. MDIO_MMD_PMAPMD,
  289. PMA_PMD_XCONTROL_REG, reg);
  290. mdelay(200);
  291. }
  292. rc = mdio_clause45_wait_reset_mmds(efx,
  293. TENXPRESS_REQUIRED_DEVS);
  294. if (rc < 0)
  295. goto fail;
  296. rc = mdio_clause45_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
  297. if (rc < 0)
  298. goto fail;
  299. }
  300. rc = tenxpress_init(efx);
  301. if (rc < 0)
  302. goto fail;
  303. if (efx->phy_type == PHY_TYPE_SFT9001B) {
  304. rc = device_create_file(&efx->pci_dev->dev,
  305. &dev_attr_phy_short_reach);
  306. if (rc)
  307. goto fail;
  308. }
  309. schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
  310. /* Let XGXS and SerDes out of reset */
  311. falcon_reset_xaui(efx);
  312. return 0;
  313. fail:
  314. kfree(efx->phy_data);
  315. efx->phy_data = NULL;
  316. return rc;
  317. }
  318. /* Perform a "special software reset" on the PHY. The caller is
  319. * responsible for saving and restoring the PHY hardware registers
  320. * properly, and masking/unmasking LASI */
  321. static int tenxpress_special_reset(struct efx_nic *efx)
  322. {
  323. int rc, reg;
  324. /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so
  325. * a special software reset can glitch the XGMAC sufficiently for stats
  326. * requests to fail. Since we don't often special_reset, just lock. */
  327. spin_lock(&efx->stats_lock);
  328. /* Initiate reset */
  329. reg = mdio_clause45_read(efx, efx->mii.phy_id,
  330. MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
  331. reg |= (1 << PMA_PMD_EXT_SSR_LBN);
  332. mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  333. PMA_PMD_XCONTROL_REG, reg);
  334. mdelay(200);
  335. /* Wait for the blocks to come out of reset */
  336. rc = mdio_clause45_wait_reset_mmds(efx,
  337. TENXPRESS_REQUIRED_DEVS);
  338. if (rc < 0)
  339. goto unlock;
  340. /* Try and reconfigure the device */
  341. rc = tenxpress_init(efx);
  342. if (rc < 0)
  343. goto unlock;
  344. /* Wait for the XGXS state machine to churn */
  345. mdelay(10);
  346. unlock:
  347. spin_unlock(&efx->stats_lock);
  348. return rc;
  349. }
  350. static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
  351. {
  352. struct tenxpress_phy_data *pd = efx->phy_data;
  353. int phy_id = efx->mii.phy_id;
  354. bool bad_lp;
  355. int reg;
  356. if (link_ok) {
  357. bad_lp = false;
  358. } else {
  359. /* Check that AN has started but not completed. */
  360. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  361. MDIO_AN_STATUS);
  362. if (!(reg & (1 << MDIO_AN_STATUS_LP_AN_CAP_LBN)))
  363. return; /* LP status is unknown */
  364. bad_lp = !(reg & (1 << MDIO_AN_STATUS_AN_DONE_LBN));
  365. if (bad_lp)
  366. pd->bad_lp_tries++;
  367. }
  368. /* Nothing to do if all is well and was previously so. */
  369. if (!pd->bad_lp_tries)
  370. return;
  371. /* Use the RX (red) LED as an error indicator once we've seen AN
  372. * failure several times in a row, and also log a message. */
  373. if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
  374. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  375. PMA_PMD_LED_OVERR_REG);
  376. reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
  377. if (!bad_lp) {
  378. reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
  379. } else {
  380. reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
  381. EFX_ERR(efx, "appears to be plugged into a port"
  382. " that is not 10GBASE-T capable. The PHY"
  383. " supports 10GBASE-T ONLY, so no link can"
  384. " be established\n");
  385. }
  386. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
  387. PMA_PMD_LED_OVERR_REG, reg);
  388. pd->bad_lp_tries = bad_lp;
  389. }
  390. }
  391. static bool sfx7101_link_ok(struct efx_nic *efx)
  392. {
  393. return mdio_clause45_links_ok(efx,
  394. MDIO_MMDREG_DEVS_PMAPMD |
  395. MDIO_MMDREG_DEVS_PCS |
  396. MDIO_MMDREG_DEVS_PHYXS);
  397. }
  398. static bool sft9001_link_ok(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  399. {
  400. int phy_id = efx->mii.phy_id;
  401. u32 reg;
  402. if (efx_phy_mode_disabled(efx->phy_mode))
  403. return false;
  404. else if (efx->loopback_mode == LOOPBACK_GPHY)
  405. return true;
  406. else if (efx->loopback_mode)
  407. return mdio_clause45_links_ok(efx,
  408. MDIO_MMDREG_DEVS_PMAPMD |
  409. MDIO_MMDREG_DEVS_PHYXS);
  410. /* We must use the same definition of link state as LASI,
  411. * otherwise we can miss a link state transition
  412. */
  413. if (ecmd->speed == 10000) {
  414. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PCS,
  415. PCS_10GBASET_STAT1);
  416. return reg & (1 << PCS_10GBASET_BLKLK_LBN);
  417. } else {
  418. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
  419. C22EXT_STATUS_REG);
  420. return reg & (1 << C22EXT_STATUS_LINK_LBN);
  421. }
  422. }
  423. static void tenxpress_ext_loopback(struct efx_nic *efx)
  424. {
  425. int phy_id = efx->mii.phy_id;
  426. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PHYXS,
  427. PHYXS_TEST1, LOOPBACK_NEAR_LBN,
  428. efx->loopback_mode == LOOPBACK_PHYXS);
  429. if (efx->phy_type != PHY_TYPE_SFX7101)
  430. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
  431. GPHY_XCONTROL_REG,
  432. GPHY_LOOPBACK_NEAR_LBN,
  433. efx->loopback_mode == LOOPBACK_GPHY);
  434. }
  435. static void tenxpress_low_power(struct efx_nic *efx)
  436. {
  437. int phy_id = efx->mii.phy_id;
  438. if (efx->phy_type == PHY_TYPE_SFX7101)
  439. mdio_clause45_set_mmds_lpower(
  440. efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
  441. TENXPRESS_REQUIRED_DEVS);
  442. else
  443. mdio_clause45_set_flag(
  444. efx, phy_id, MDIO_MMD_PMAPMD,
  445. PMA_PMD_XCONTROL_REG, PMA_PMD_EXT_LPOWER_LBN,
  446. !!(efx->phy_mode & PHY_MODE_LOW_POWER));
  447. }
  448. static void tenxpress_phy_reconfigure(struct efx_nic *efx)
  449. {
  450. struct tenxpress_phy_data *phy_data = efx->phy_data;
  451. struct ethtool_cmd ecmd;
  452. bool phy_mode_change, loop_reset, loop_toggle, loopback;
  453. if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
  454. phy_data->phy_mode = efx->phy_mode;
  455. return;
  456. }
  457. tenxpress_low_power(efx);
  458. phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
  459. phy_data->phy_mode != PHY_MODE_NORMAL);
  460. loopback = LOOPBACK_MASK(efx) & efx->phy_op->loopbacks;
  461. loop_toggle = LOOPBACK_CHANGED(phy_data, efx, efx->phy_op->loopbacks);
  462. loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, efx->phy_op->loopbacks) ||
  463. LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
  464. if (loop_reset || loop_toggle || loopback || phy_mode_change) {
  465. int rc;
  466. efx->phy_op->get_settings(efx, &ecmd);
  467. if (loop_reset || phy_mode_change) {
  468. tenxpress_special_reset(efx);
  469. /* Reset XAUI if we were in 10G, and are staying
  470. * in 10G. If we're moving into and out of 10G
  471. * then xaui will be reset anyway */
  472. if (EFX_IS10G(efx))
  473. falcon_reset_xaui(efx);
  474. }
  475. if (efx->phy_type != PHY_TYPE_SFX7101) {
  476. /* Only change autoneg once, on coming out or
  477. * going into loopback */
  478. if (loop_toggle)
  479. ecmd.autoneg = !loopback;
  480. if (loopback) {
  481. ecmd.duplex = DUPLEX_FULL;
  482. if (efx->loopback_mode == LOOPBACK_GPHY)
  483. ecmd.speed = SPEED_1000;
  484. else
  485. ecmd.speed = SPEED_10000;
  486. }
  487. }
  488. rc = efx->phy_op->set_settings(efx, &ecmd);
  489. WARN_ON(rc);
  490. }
  491. mdio_clause45_transmit_disable(efx);
  492. mdio_clause45_phy_reconfigure(efx);
  493. tenxpress_ext_loopback(efx);
  494. phy_data->loopback_mode = efx->loopback_mode;
  495. phy_data->phy_mode = efx->phy_mode;
  496. if (efx->phy_type == PHY_TYPE_SFX7101) {
  497. efx->link_speed = 10000;
  498. efx->link_fd = true;
  499. efx->link_up = sfx7101_link_ok(efx);
  500. } else {
  501. efx->phy_op->get_settings(efx, &ecmd);
  502. efx->link_speed = ecmd.speed;
  503. efx->link_fd = ecmd.duplex == DUPLEX_FULL;
  504. efx->link_up = sft9001_link_ok(efx, &ecmd);
  505. }
  506. efx->link_fc = mdio_clause45_get_pause(efx);
  507. }
  508. /* Poll PHY for interrupt */
  509. static void tenxpress_phy_poll(struct efx_nic *efx)
  510. {
  511. struct tenxpress_phy_data *phy_data = efx->phy_data;
  512. bool change = false, link_ok;
  513. unsigned link_fc;
  514. if (efx->phy_type == PHY_TYPE_SFX7101) {
  515. link_ok = sfx7101_link_ok(efx);
  516. if (link_ok != efx->link_up) {
  517. change = true;
  518. } else {
  519. link_fc = mdio_clause45_get_pause(efx);
  520. if (link_fc != efx->link_fc)
  521. change = true;
  522. }
  523. sfx7101_check_bad_lp(efx, link_ok);
  524. } else if (efx->loopback_mode) {
  525. bool link_ok = sft9001_link_ok(efx, NULL);
  526. if (link_ok != efx->link_up)
  527. change = true;
  528. } else {
  529. u32 status = mdio_clause45_read(efx, efx->mii.phy_id,
  530. MDIO_MMD_PMAPMD,
  531. PMA_PMD_LASI_STATUS);
  532. if (status & (1 << PMA_PMD_LS_ALARM_LBN))
  533. change = true;
  534. }
  535. if (change)
  536. falcon_sim_phy_event(efx);
  537. if (phy_data->phy_mode != PHY_MODE_NORMAL)
  538. return;
  539. if (EFX_WORKAROUND_10750(efx) &&
  540. atomic_read(&phy_data->bad_crc_count) > crc_error_reset_threshold) {
  541. EFX_ERR(efx, "Resetting XAUI due to too many CRC errors\n");
  542. falcon_reset_xaui(efx);
  543. atomic_set(&phy_data->bad_crc_count, 0);
  544. }
  545. }
  546. static void tenxpress_phy_fini(struct efx_nic *efx)
  547. {
  548. int reg;
  549. if (efx->phy_type == PHY_TYPE_SFT9001B)
  550. device_remove_file(&efx->pci_dev->dev,
  551. &dev_attr_phy_short_reach);
  552. if (efx->phy_type == PHY_TYPE_SFX7101) {
  553. /* Power down the LNPGA */
  554. reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
  555. mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  556. PMA_PMD_XCONTROL_REG, reg);
  557. /* Waiting here ensures that the board fini, which can turn
  558. * off the power to the PHY, won't get run until the LNPGA
  559. * powerdown has been given long enough to complete. */
  560. schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
  561. }
  562. kfree(efx->phy_data);
  563. efx->phy_data = NULL;
  564. }
  565. /* Set the RX and TX LEDs and Link LED flashing. The other LEDs
  566. * (which probably aren't wired anyway) are left in AUTO mode */
  567. void tenxpress_phy_blink(struct efx_nic *efx, bool blink)
  568. {
  569. int reg;
  570. if (blink)
  571. reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) |
  572. (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) |
  573. (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN);
  574. else
  575. reg = PMA_PMD_LED_DEFAULT;
  576. mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  577. PMA_PMD_LED_OVERR_REG, reg);
  578. }
  579. static const char *const sfx7101_test_names[] = {
  580. "bist"
  581. };
  582. static int
  583. sfx7101_run_tests(struct efx_nic *efx, int *results, unsigned flags)
  584. {
  585. int rc;
  586. if (!(flags & ETH_TEST_FL_OFFLINE))
  587. return 0;
  588. /* BIST is automatically run after a special software reset */
  589. rc = tenxpress_special_reset(efx);
  590. results[0] = rc ? -1 : 1;
  591. return rc;
  592. }
  593. static const char *const sft9001_test_names[] = {
  594. "bist",
  595. "cable.pairA.status",
  596. "cable.pairB.status",
  597. "cable.pairC.status",
  598. "cable.pairD.status",
  599. "cable.pairA.length",
  600. "cable.pairB.length",
  601. "cable.pairC.length",
  602. "cable.pairD.length",
  603. };
  604. static int sft9001_run_tests(struct efx_nic *efx, int *results, unsigned flags)
  605. {
  606. struct ethtool_cmd ecmd;
  607. int phy_id = efx->mii.phy_id;
  608. int rc = 0, rc2, i, res_reg;
  609. if (!(flags & ETH_TEST_FL_OFFLINE))
  610. return 0;
  611. efx->phy_op->get_settings(efx, &ecmd);
  612. /* Initialise cable diagnostic results to unknown failure */
  613. for (i = 1; i < 9; ++i)
  614. results[i] = -1;
  615. /* Run cable diagnostics; wait up to 5 seconds for them to complete.
  616. * A cable fault is not a self-test failure, but a timeout is. */
  617. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
  618. PMA_PMD_CDIAG_CTRL_REG,
  619. (1 << CDIAG_CTRL_IMMED_LBN) |
  620. (1 << CDIAG_CTRL_BRK_LINK_LBN) |
  621. (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN));
  622. i = 0;
  623. while (mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  624. PMA_PMD_CDIAG_CTRL_REG) &
  625. (1 << CDIAG_CTRL_IN_PROG_LBN)) {
  626. if (++i == 50) {
  627. rc = -ETIMEDOUT;
  628. goto reset;
  629. }
  630. msleep(100);
  631. }
  632. res_reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  633. PMA_PMD_CDIAG_RES_REG);
  634. for (i = 0; i < 4; i++) {
  635. int pair_res =
  636. (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH))
  637. & ((1 << CDIAG_RES_WIDTH) - 1);
  638. int len_reg = mdio_clause45_read(efx, efx->mii.phy_id,
  639. MDIO_MMD_PMAPMD,
  640. PMA_PMD_CDIAG_LEN_REG + i);
  641. if (pair_res == CDIAG_RES_OK)
  642. results[1 + i] = 1;
  643. else if (pair_res == CDIAG_RES_INVALID)
  644. results[1 + i] = -1;
  645. else
  646. results[1 + i] = -pair_res;
  647. if (pair_res != CDIAG_RES_INVALID &&
  648. pair_res != CDIAG_RES_OPEN &&
  649. len_reg != 0xffff)
  650. results[5 + i] = len_reg;
  651. }
  652. /* We must reset to exit cable diagnostic mode. The BIST will
  653. * also run when we do this. */
  654. reset:
  655. rc2 = tenxpress_special_reset(efx);
  656. results[0] = rc2 ? -1 : 1;
  657. if (!rc)
  658. rc = rc2;
  659. rc2 = efx->phy_op->set_settings(efx, &ecmd);
  660. if (!rc)
  661. rc = rc2;
  662. return rc;
  663. }
  664. static u32 tenxpress_get_xnp_lpa(struct efx_nic *efx)
  665. {
  666. int phy = efx->mii.phy_id;
  667. u32 lpa = 0;
  668. int reg;
  669. if (efx->phy_type != PHY_TYPE_SFX7101) {
  670. reg = mdio_clause45_read(efx, phy, MDIO_MMD_C22EXT,
  671. C22EXT_MSTSLV_REG);
  672. if (reg & (1 << C22EXT_MSTSLV_1000_HD_LBN))
  673. lpa |= ADVERTISED_1000baseT_Half;
  674. if (reg & (1 << C22EXT_MSTSLV_1000_FD_LBN))
  675. lpa |= ADVERTISED_1000baseT_Full;
  676. }
  677. reg = mdio_clause45_read(efx, phy, MDIO_MMD_AN, MDIO_AN_10GBT_STATUS);
  678. if (reg & (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN))
  679. lpa |= ADVERTISED_10000baseT_Full;
  680. return lpa;
  681. }
  682. static void sfx7101_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  683. {
  684. mdio_clause45_get_settings_ext(efx, ecmd, ADVERTISED_10000baseT_Full,
  685. tenxpress_get_xnp_lpa(efx));
  686. ecmd->supported |= SUPPORTED_10000baseT_Full;
  687. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  688. }
  689. static void sft9001_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  690. {
  691. int phy_id = efx->mii.phy_id;
  692. u32 xnp_adv = 0;
  693. int reg;
  694. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  695. PMA_PMD_SPEED_ENABLE_REG);
  696. if (EFX_WORKAROUND_13204(efx) && (reg & (1 << PMA_PMD_100TX_ADV_LBN)))
  697. xnp_adv |= ADVERTISED_100baseT_Full;
  698. if (reg & (1 << PMA_PMD_1000T_ADV_LBN))
  699. xnp_adv |= ADVERTISED_1000baseT_Full;
  700. if (reg & (1 << PMA_PMD_10000T_ADV_LBN))
  701. xnp_adv |= ADVERTISED_10000baseT_Full;
  702. mdio_clause45_get_settings_ext(efx, ecmd, xnp_adv,
  703. tenxpress_get_xnp_lpa(efx));
  704. ecmd->supported |= (SUPPORTED_100baseT_Half |
  705. SUPPORTED_100baseT_Full |
  706. SUPPORTED_1000baseT_Full);
  707. /* Use the vendor defined C22ext register for duplex settings */
  708. if (ecmd->speed != SPEED_10000 && !ecmd->autoneg) {
  709. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
  710. GPHY_XCONTROL_REG);
  711. ecmd->duplex = (reg & (1 << GPHY_DUPLEX_LBN) ?
  712. DUPLEX_FULL : DUPLEX_HALF);
  713. }
  714. }
  715. static int sft9001_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  716. {
  717. int phy_id = efx->mii.phy_id;
  718. int rc;
  719. rc = mdio_clause45_set_settings(efx, ecmd);
  720. if (rc)
  721. return rc;
  722. if (ecmd->speed != SPEED_10000 && !ecmd->autoneg)
  723. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
  724. GPHY_XCONTROL_REG, GPHY_DUPLEX_LBN,
  725. ecmd->duplex == DUPLEX_FULL);
  726. return rc;
  727. }
  728. static bool sft9001_set_xnp_advertise(struct efx_nic *efx, u32 advertising)
  729. {
  730. int phy = efx->mii.phy_id;
  731. int reg = mdio_clause45_read(efx, phy, MDIO_MMD_PMAPMD,
  732. PMA_PMD_SPEED_ENABLE_REG);
  733. bool enabled;
  734. reg &= ~((1 << 2) | (1 << 3));
  735. if (EFX_WORKAROUND_13204(efx) &&
  736. (advertising & ADVERTISED_100baseT_Full))
  737. reg |= 1 << PMA_PMD_100TX_ADV_LBN;
  738. if (advertising & ADVERTISED_1000baseT_Full)
  739. reg |= 1 << PMA_PMD_1000T_ADV_LBN;
  740. if (advertising & ADVERTISED_10000baseT_Full)
  741. reg |= 1 << PMA_PMD_10000T_ADV_LBN;
  742. mdio_clause45_write(efx, phy, MDIO_MMD_PMAPMD,
  743. PMA_PMD_SPEED_ENABLE_REG, reg);
  744. enabled = (advertising &
  745. (ADVERTISED_1000baseT_Half |
  746. ADVERTISED_1000baseT_Full |
  747. ADVERTISED_10000baseT_Full));
  748. if (EFX_WORKAROUND_13204(efx))
  749. enabled |= (advertising & ADVERTISED_100baseT_Full);
  750. return enabled;
  751. }
  752. struct efx_phy_operations falcon_sfx7101_phy_ops = {
  753. .macs = EFX_XMAC,
  754. .init = tenxpress_phy_init,
  755. .reconfigure = tenxpress_phy_reconfigure,
  756. .poll = tenxpress_phy_poll,
  757. .fini = tenxpress_phy_fini,
  758. .clear_interrupt = efx_port_dummy_op_void,
  759. .get_settings = sfx7101_get_settings,
  760. .set_settings = mdio_clause45_set_settings,
  761. .num_tests = ARRAY_SIZE(sfx7101_test_names),
  762. .test_names = sfx7101_test_names,
  763. .run_tests = sfx7101_run_tests,
  764. .mmds = TENXPRESS_REQUIRED_DEVS,
  765. .loopbacks = SFX7101_LOOPBACKS,
  766. };
  767. struct efx_phy_operations falcon_sft9001_phy_ops = {
  768. .macs = EFX_GMAC | EFX_XMAC,
  769. .init = tenxpress_phy_init,
  770. .reconfigure = tenxpress_phy_reconfigure,
  771. .poll = tenxpress_phy_poll,
  772. .fini = tenxpress_phy_fini,
  773. .clear_interrupt = efx_port_dummy_op_void,
  774. .get_settings = sft9001_get_settings,
  775. .set_settings = sft9001_set_settings,
  776. .set_xnp_advertise = sft9001_set_xnp_advertise,
  777. .num_tests = ARRAY_SIZE(sft9001_test_names),
  778. .test_names = sft9001_test_names,
  779. .run_tests = sft9001_run_tests,
  780. .mmds = TENXPRESS_REQUIRED_DEVS,
  781. .loopbacks = SFT9001_LOOPBACKS,
  782. };