tenxpress.c 25 KB

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