tenxpress.c 25 KB

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