tenxpress.c 24 KB

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