tenxpress.c 23 KB

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