tenxpress.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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_CTRL 49161
  159. #define C22EXT_MSTSLV_CTRL_ADV_1000_HD_LBN 8
  160. #define C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN 9
  161. #define C22EXT_MSTSLV_STATUS 49162
  162. #define C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN 10
  163. #define C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN 11
  164. /* Time to wait between powering down the LNPGA and turning off the power
  165. * rails */
  166. #define LNPGA_PDOWN_WAIT (HZ / 5)
  167. struct tenxpress_phy_data {
  168. enum efx_loopback_mode loopback_mode;
  169. enum efx_phy_mode phy_mode;
  170. int bad_lp_tries;
  171. };
  172. static ssize_t show_phy_short_reach(struct device *dev,
  173. struct device_attribute *attr, char *buf)
  174. {
  175. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  176. int reg;
  177. reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  178. MDIO_PMAPMD_10GBT_TXPWR);
  179. return sprintf(buf, "%d\n",
  180. !!(reg & (1 << MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN)));
  181. }
  182. static ssize_t set_phy_short_reach(struct device *dev,
  183. struct device_attribute *attr,
  184. const char *buf, size_t count)
  185. {
  186. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  187. rtnl_lock();
  188. mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  189. MDIO_PMAPMD_10GBT_TXPWR,
  190. MDIO_PMAPMD_10GBT_TXPWR_SHORT_LBN,
  191. count != 0 && *buf != '0');
  192. efx_reconfigure_port(efx);
  193. rtnl_unlock();
  194. return count;
  195. }
  196. static DEVICE_ATTR(phy_short_reach, 0644, show_phy_short_reach,
  197. set_phy_short_reach);
  198. /* Check that the C166 has booted successfully */
  199. static int tenxpress_phy_check(struct efx_nic *efx)
  200. {
  201. int phy_id = efx->mii.phy_id;
  202. int count = PCS_BOOT_MAX_DELAY / PCS_BOOT_POLL_DELAY;
  203. int boot_stat;
  204. /* Wait for the boot to complete (or not) */
  205. while (count) {
  206. boot_stat = mdio_clause45_read(efx, phy_id,
  207. MDIO_MMD_PCS,
  208. PCS_BOOT_STATUS_REG);
  209. if (boot_stat & (1 << PCS_BOOT_COMPLETE_LBN))
  210. break;
  211. count--;
  212. udelay(PCS_BOOT_POLL_DELAY);
  213. }
  214. if (!count) {
  215. EFX_ERR(efx, "%s: PHY boot timed out. Last status "
  216. "%x\n", __func__,
  217. (boot_stat >> PCS_BOOT_PROGRESS_LBN) &
  218. ((1 << PCS_BOOT_PROGRESS_WIDTH) - 1));
  219. return -ETIMEDOUT;
  220. }
  221. return 0;
  222. }
  223. static int tenxpress_init(struct efx_nic *efx)
  224. {
  225. int phy_id = efx->mii.phy_id;
  226. int reg;
  227. int rc;
  228. if (efx->phy_type == PHY_TYPE_SFX7101) {
  229. /* Enable 312.5 MHz clock */
  230. mdio_clause45_write(efx, phy_id,
  231. MDIO_MMD_PCS, PCS_TEST_SELECT_REG,
  232. 1 << CLK312_EN_LBN);
  233. } else {
  234. /* Enable 312.5 MHz clock and GMII */
  235. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  236. PMA_PMD_XCONTROL_REG);
  237. reg |= ((1 << PMA_PMD_EXT_GMII_EN_LBN) |
  238. (1 << PMA_PMD_EXT_CLK_OUT_LBN) |
  239. (1 << PMA_PMD_EXT_CLK312_LBN) |
  240. (1 << PMA_PMD_EXT_ROBUST_LBN));
  241. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
  242. PMA_PMD_XCONTROL_REG, reg);
  243. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
  244. GPHY_XCONTROL_REG, GPHY_ISOLATE_LBN,
  245. false);
  246. }
  247. rc = tenxpress_phy_check(efx);
  248. if (rc < 0)
  249. return rc;
  250. /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
  251. if (efx->phy_type == PHY_TYPE_SFX7101) {
  252. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PMAPMD,
  253. PMA_PMD_LED_CTRL_REG,
  254. PMA_PMA_LED_ACTIVITY_LBN,
  255. true);
  256. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
  257. PMA_PMD_LED_OVERR_REG, PMA_PMD_LED_DEFAULT);
  258. }
  259. return rc;
  260. }
  261. static int tenxpress_phy_init(struct efx_nic *efx)
  262. {
  263. struct tenxpress_phy_data *phy_data;
  264. int rc = 0;
  265. phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
  266. if (!phy_data)
  267. return -ENOMEM;
  268. efx->phy_data = phy_data;
  269. phy_data->phy_mode = efx->phy_mode;
  270. if (!(efx->phy_mode & PHY_MODE_SPECIAL)) {
  271. if (efx->phy_type == PHY_TYPE_SFT9001A) {
  272. int reg;
  273. reg = mdio_clause45_read(efx, efx->mii.phy_id,
  274. MDIO_MMD_PMAPMD,
  275. PMA_PMD_XCONTROL_REG);
  276. reg |= (1 << PMA_PMD_EXT_SSR_LBN);
  277. mdio_clause45_write(efx, efx->mii.phy_id,
  278. MDIO_MMD_PMAPMD,
  279. PMA_PMD_XCONTROL_REG, reg);
  280. mdelay(200);
  281. }
  282. rc = mdio_clause45_wait_reset_mmds(efx,
  283. TENXPRESS_REQUIRED_DEVS);
  284. if (rc < 0)
  285. goto fail;
  286. rc = mdio_clause45_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
  287. if (rc < 0)
  288. goto fail;
  289. }
  290. rc = tenxpress_init(efx);
  291. if (rc < 0)
  292. goto fail;
  293. mdio_clause45_set_pause(efx);
  294. if (efx->phy_type == PHY_TYPE_SFT9001B) {
  295. rc = device_create_file(&efx->pci_dev->dev,
  296. &dev_attr_phy_short_reach);
  297. if (rc)
  298. goto fail;
  299. }
  300. schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
  301. /* Let XGXS and SerDes out of reset */
  302. falcon_reset_xaui(efx);
  303. return 0;
  304. fail:
  305. kfree(efx->phy_data);
  306. efx->phy_data = NULL;
  307. return rc;
  308. }
  309. /* Perform a "special software reset" on the PHY. The caller is
  310. * responsible for saving and restoring the PHY hardware registers
  311. * properly, and masking/unmasking LASI */
  312. static int tenxpress_special_reset(struct efx_nic *efx)
  313. {
  314. int rc, reg;
  315. /* The XGMAC clock is driven from the SFC7101/SFT9001 312MHz clock, so
  316. * a special software reset can glitch the XGMAC sufficiently for stats
  317. * requests to fail. */
  318. efx_stats_disable(efx);
  319. /* Initiate reset */
  320. reg = mdio_clause45_read(efx, efx->mii.phy_id,
  321. MDIO_MMD_PMAPMD, PMA_PMD_XCONTROL_REG);
  322. reg |= (1 << PMA_PMD_EXT_SSR_LBN);
  323. mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  324. PMA_PMD_XCONTROL_REG, reg);
  325. mdelay(200);
  326. /* Wait for the blocks to come out of reset */
  327. rc = mdio_clause45_wait_reset_mmds(efx,
  328. TENXPRESS_REQUIRED_DEVS);
  329. if (rc < 0)
  330. goto out;
  331. /* Try and reconfigure the device */
  332. rc = tenxpress_init(efx);
  333. if (rc < 0)
  334. goto out;
  335. /* Wait for the XGXS state machine to churn */
  336. mdelay(10);
  337. out:
  338. efx_stats_enable(efx);
  339. return rc;
  340. }
  341. static void sfx7101_check_bad_lp(struct efx_nic *efx, bool link_ok)
  342. {
  343. struct tenxpress_phy_data *pd = efx->phy_data;
  344. int phy_id = efx->mii.phy_id;
  345. bool bad_lp;
  346. int reg;
  347. if (link_ok) {
  348. bad_lp = false;
  349. } else {
  350. /* Check that AN has started but not completed. */
  351. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  352. MDIO_AN_STATUS);
  353. if (!(reg & (1 << MDIO_AN_STATUS_LP_AN_CAP_LBN)))
  354. return; /* LP status is unknown */
  355. bad_lp = !(reg & (1 << MDIO_AN_STATUS_AN_DONE_LBN));
  356. if (bad_lp)
  357. pd->bad_lp_tries++;
  358. }
  359. /* Nothing to do if all is well and was previously so. */
  360. if (!pd->bad_lp_tries)
  361. return;
  362. /* Use the RX (red) LED as an error indicator once we've seen AN
  363. * failure several times in a row, and also log a message. */
  364. if (!bad_lp || pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
  365. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  366. PMA_PMD_LED_OVERR_REG);
  367. reg &= ~(PMA_PMD_LED_MASK << PMA_PMD_LED_RX_LBN);
  368. if (!bad_lp) {
  369. reg |= PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN;
  370. } else {
  371. reg |= PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN;
  372. EFX_ERR(efx, "appears to be plugged into a port"
  373. " that is not 10GBASE-T capable. The PHY"
  374. " supports 10GBASE-T ONLY, so no link can"
  375. " be established\n");
  376. }
  377. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
  378. PMA_PMD_LED_OVERR_REG, reg);
  379. pd->bad_lp_tries = bad_lp;
  380. }
  381. }
  382. static bool sfx7101_link_ok(struct efx_nic *efx)
  383. {
  384. return mdio_clause45_links_ok(efx,
  385. MDIO_MMDREG_DEVS_PMAPMD |
  386. MDIO_MMDREG_DEVS_PCS |
  387. MDIO_MMDREG_DEVS_PHYXS);
  388. }
  389. static bool sft9001_link_ok(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  390. {
  391. int phy_id = efx->mii.phy_id;
  392. u32 reg;
  393. if (efx_phy_mode_disabled(efx->phy_mode))
  394. return false;
  395. else if (efx->loopback_mode == LOOPBACK_GPHY)
  396. return true;
  397. else if (efx->loopback_mode)
  398. return mdio_clause45_links_ok(efx,
  399. MDIO_MMDREG_DEVS_PMAPMD |
  400. MDIO_MMDREG_DEVS_PHYXS);
  401. /* We must use the same definition of link state as LASI,
  402. * otherwise we can miss a link state transition
  403. */
  404. if (ecmd->speed == 10000) {
  405. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PCS,
  406. PCS_10GBASET_STAT1);
  407. return reg & (1 << PCS_10GBASET_BLKLK_LBN);
  408. } else {
  409. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
  410. C22EXT_STATUS_REG);
  411. return reg & (1 << C22EXT_STATUS_LINK_LBN);
  412. }
  413. }
  414. static void tenxpress_ext_loopback(struct efx_nic *efx)
  415. {
  416. int phy_id = efx->mii.phy_id;
  417. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PHYXS,
  418. PHYXS_TEST1, LOOPBACK_NEAR_LBN,
  419. efx->loopback_mode == LOOPBACK_PHYXS);
  420. if (efx->phy_type != PHY_TYPE_SFX7101)
  421. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
  422. GPHY_XCONTROL_REG,
  423. GPHY_LOOPBACK_NEAR_LBN,
  424. efx->loopback_mode == LOOPBACK_GPHY);
  425. }
  426. static void tenxpress_low_power(struct efx_nic *efx)
  427. {
  428. int phy_id = efx->mii.phy_id;
  429. if (efx->phy_type == PHY_TYPE_SFX7101)
  430. mdio_clause45_set_mmds_lpower(
  431. efx, !!(efx->phy_mode & PHY_MODE_LOW_POWER),
  432. TENXPRESS_REQUIRED_DEVS);
  433. else
  434. mdio_clause45_set_flag(
  435. efx, phy_id, MDIO_MMD_PMAPMD,
  436. PMA_PMD_XCONTROL_REG, PMA_PMD_EXT_LPOWER_LBN,
  437. !!(efx->phy_mode & PHY_MODE_LOW_POWER));
  438. }
  439. static void tenxpress_phy_reconfigure(struct efx_nic *efx)
  440. {
  441. struct tenxpress_phy_data *phy_data = efx->phy_data;
  442. struct ethtool_cmd ecmd;
  443. bool phy_mode_change, loop_reset;
  444. if (efx->phy_mode & (PHY_MODE_OFF | PHY_MODE_SPECIAL)) {
  445. phy_data->phy_mode = efx->phy_mode;
  446. return;
  447. }
  448. tenxpress_low_power(efx);
  449. phy_mode_change = (efx->phy_mode == PHY_MODE_NORMAL &&
  450. phy_data->phy_mode != PHY_MODE_NORMAL);
  451. loop_reset = (LOOPBACK_OUT_OF(phy_data, efx, efx->phy_op->loopbacks) ||
  452. LOOPBACK_CHANGED(phy_data, efx, 1 << LOOPBACK_GPHY));
  453. if (loop_reset || phy_mode_change) {
  454. int rc;
  455. efx->phy_op->get_settings(efx, &ecmd);
  456. if (loop_reset || phy_mode_change) {
  457. tenxpress_special_reset(efx);
  458. /* Reset XAUI if we were in 10G, and are staying
  459. * in 10G. If we're moving into and out of 10G
  460. * then xaui will be reset anyway */
  461. if (EFX_IS10G(efx))
  462. falcon_reset_xaui(efx);
  463. }
  464. rc = efx->phy_op->set_settings(efx, &ecmd);
  465. WARN_ON(rc);
  466. }
  467. mdio_clause45_transmit_disable(efx);
  468. mdio_clause45_phy_reconfigure(efx);
  469. tenxpress_ext_loopback(efx);
  470. phy_data->loopback_mode = efx->loopback_mode;
  471. phy_data->phy_mode = efx->phy_mode;
  472. if (efx->phy_type == PHY_TYPE_SFX7101) {
  473. efx->link_speed = 10000;
  474. efx->link_fd = true;
  475. efx->link_up = sfx7101_link_ok(efx);
  476. } else {
  477. efx->phy_op->get_settings(efx, &ecmd);
  478. efx->link_speed = ecmd.speed;
  479. efx->link_fd = ecmd.duplex == DUPLEX_FULL;
  480. efx->link_up = sft9001_link_ok(efx, &ecmd);
  481. }
  482. efx->link_fc = mdio_clause45_get_pause(efx);
  483. }
  484. /* Poll PHY for interrupt */
  485. static void tenxpress_phy_poll(struct efx_nic *efx)
  486. {
  487. struct tenxpress_phy_data *phy_data = efx->phy_data;
  488. bool change = false, link_ok;
  489. unsigned link_fc;
  490. if (efx->phy_type == PHY_TYPE_SFX7101) {
  491. link_ok = sfx7101_link_ok(efx);
  492. if (link_ok != efx->link_up) {
  493. change = true;
  494. } else {
  495. 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, res_reg;
  579. if (!(flags & ETH_TEST_FL_OFFLINE))
  580. return 0;
  581. efx->phy_op->get_settings(efx, &ecmd);
  582. /* Initialise cable diagnostic results to unknown failure */
  583. for (i = 1; i < 9; ++i)
  584. results[i] = -1;
  585. /* Run cable diagnostics; wait up to 5 seconds for them to complete.
  586. * A cable fault is not a self-test failure, but a timeout is. */
  587. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
  588. PMA_PMD_CDIAG_CTRL_REG,
  589. (1 << CDIAG_CTRL_IMMED_LBN) |
  590. (1 << CDIAG_CTRL_BRK_LINK_LBN) |
  591. (CDIAG_CTRL_LEN_METRES << CDIAG_CTRL_LEN_UNIT_LBN));
  592. i = 0;
  593. while (mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  594. PMA_PMD_CDIAG_CTRL_REG) &
  595. (1 << CDIAG_CTRL_IN_PROG_LBN)) {
  596. if (++i == 50) {
  597. rc = -ETIMEDOUT;
  598. goto reset;
  599. }
  600. msleep(100);
  601. }
  602. res_reg = mdio_clause45_read(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  603. PMA_PMD_CDIAG_RES_REG);
  604. for (i = 0; i < 4; i++) {
  605. int pair_res =
  606. (res_reg >> (CDIAG_RES_A_LBN - i * CDIAG_RES_WIDTH))
  607. & ((1 << CDIAG_RES_WIDTH) - 1);
  608. int len_reg = mdio_clause45_read(efx, efx->mii.phy_id,
  609. MDIO_MMD_PMAPMD,
  610. PMA_PMD_CDIAG_LEN_REG + i);
  611. if (pair_res == CDIAG_RES_OK)
  612. results[1 + i] = 1;
  613. else if (pair_res == CDIAG_RES_INVALID)
  614. results[1 + i] = -1;
  615. else
  616. results[1 + i] = -pair_res;
  617. if (pair_res != CDIAG_RES_INVALID &&
  618. pair_res != CDIAG_RES_OPEN &&
  619. len_reg != 0xffff)
  620. results[5 + i] = len_reg;
  621. }
  622. /* We must reset to exit cable diagnostic mode. The BIST will
  623. * also run when we do this. */
  624. reset:
  625. rc2 = tenxpress_special_reset(efx);
  626. results[0] = rc2 ? -1 : 1;
  627. if (!rc)
  628. rc = rc2;
  629. rc2 = efx->phy_op->set_settings(efx, &ecmd);
  630. if (!rc)
  631. rc = rc2;
  632. return rc;
  633. }
  634. static void
  635. tenxpress_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  636. {
  637. int phy_id = efx->mii.phy_id;
  638. u32 adv = 0, lpa = 0;
  639. int reg;
  640. if (efx->phy_type != PHY_TYPE_SFX7101) {
  641. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
  642. C22EXT_MSTSLV_CTRL);
  643. if (reg & (1 << C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN))
  644. adv |= ADVERTISED_1000baseT_Full;
  645. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_C22EXT,
  646. C22EXT_MSTSLV_STATUS);
  647. if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_HD_LBN))
  648. lpa |= ADVERTISED_1000baseT_Half;
  649. if (reg & (1 << C22EXT_MSTSLV_STATUS_LP_1000_FD_LBN))
  650. lpa |= ADVERTISED_1000baseT_Full;
  651. }
  652. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  653. MDIO_AN_10GBT_CTRL);
  654. if (reg & (1 << MDIO_AN_10GBT_CTRL_ADV_10G_LBN))
  655. adv |= ADVERTISED_10000baseT_Full;
  656. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  657. MDIO_AN_10GBT_STATUS);
  658. if (reg & (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN))
  659. lpa |= ADVERTISED_10000baseT_Full;
  660. mdio_clause45_get_settings_ext(efx, ecmd, adv, lpa);
  661. if (efx->phy_type != PHY_TYPE_SFX7101)
  662. ecmd->supported |= (SUPPORTED_100baseT_Full |
  663. SUPPORTED_1000baseT_Full);
  664. /* In loopback, the PHY automatically brings up the correct interface,
  665. * but doesn't advertise the correct speed. So override it */
  666. if (efx->loopback_mode == LOOPBACK_GPHY)
  667. ecmd->speed = SPEED_1000;
  668. else if (LOOPBACK_MASK(efx) & efx->phy_op->loopbacks)
  669. ecmd->speed = SPEED_10000;
  670. }
  671. static int tenxpress_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  672. {
  673. if (!ecmd->autoneg)
  674. return -EINVAL;
  675. return mdio_clause45_set_settings(efx, ecmd);
  676. }
  677. static void sfx7101_set_npage_adv(struct efx_nic *efx, u32 advertising)
  678. {
  679. mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_AN,
  680. MDIO_AN_10GBT_CTRL,
  681. MDIO_AN_10GBT_CTRL_ADV_10G_LBN,
  682. advertising & ADVERTISED_10000baseT_Full);
  683. }
  684. static void sft9001_set_npage_adv(struct efx_nic *efx, u32 advertising)
  685. {
  686. int phy_id = efx->mii.phy_id;
  687. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_C22EXT,
  688. C22EXT_MSTSLV_CTRL,
  689. C22EXT_MSTSLV_CTRL_ADV_1000_FD_LBN,
  690. advertising & ADVERTISED_1000baseT_Full);
  691. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_AN,
  692. MDIO_AN_10GBT_CTRL,
  693. MDIO_AN_10GBT_CTRL_ADV_10G_LBN,
  694. advertising & ADVERTISED_10000baseT_Full);
  695. }
  696. struct efx_phy_operations falcon_sfx7101_phy_ops = {
  697. .macs = EFX_XMAC,
  698. .init = tenxpress_phy_init,
  699. .reconfigure = tenxpress_phy_reconfigure,
  700. .poll = tenxpress_phy_poll,
  701. .fini = tenxpress_phy_fini,
  702. .clear_interrupt = efx_port_dummy_op_void,
  703. .get_settings = tenxpress_get_settings,
  704. .set_settings = tenxpress_set_settings,
  705. .set_npage_adv = sfx7101_set_npage_adv,
  706. .num_tests = ARRAY_SIZE(sfx7101_test_names),
  707. .test_names = sfx7101_test_names,
  708. .run_tests = sfx7101_run_tests,
  709. .mmds = TENXPRESS_REQUIRED_DEVS,
  710. .loopbacks = SFX7101_LOOPBACKS,
  711. };
  712. struct efx_phy_operations falcon_sft9001_phy_ops = {
  713. .macs = EFX_GMAC | EFX_XMAC,
  714. .init = tenxpress_phy_init,
  715. .reconfigure = tenxpress_phy_reconfigure,
  716. .poll = tenxpress_phy_poll,
  717. .fini = tenxpress_phy_fini,
  718. .clear_interrupt = efx_port_dummy_op_void,
  719. .get_settings = tenxpress_get_settings,
  720. .set_settings = tenxpress_set_settings,
  721. .set_npage_adv = sft9001_set_npage_adv,
  722. .num_tests = ARRAY_SIZE(sft9001_test_names),
  723. .test_names = sft9001_test_names,
  724. .run_tests = sft9001_run_tests,
  725. .mmds = TENXPRESS_REQUIRED_DEVS,
  726. .loopbacks = SFT9001_LOOPBACKS,
  727. };