mdio_10g.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2006-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. /*
  10. * Useful functions for working with MDIO clause 45 PHYs
  11. */
  12. #include <linux/types.h>
  13. #include <linux/ethtool.h>
  14. #include <linux/delay.h>
  15. #include "net_driver.h"
  16. #include "mdio_10g.h"
  17. #include "boards.h"
  18. #include "workarounds.h"
  19. int mdio_clause45_reset_mmd(struct efx_nic *port, int mmd,
  20. int spins, int spintime)
  21. {
  22. u32 ctrl;
  23. int phy_id = port->mii.phy_id;
  24. /* Catch callers passing values in the wrong units (or just silly) */
  25. EFX_BUG_ON_PARANOID(spins * spintime >= 5000);
  26. mdio_clause45_write(port, phy_id, mmd, MDIO_MMDREG_CTRL1,
  27. (1 << MDIO_MMDREG_CTRL1_RESET_LBN));
  28. /* Wait for the reset bit to clear. */
  29. do {
  30. msleep(spintime);
  31. ctrl = mdio_clause45_read(port, phy_id, mmd, MDIO_MMDREG_CTRL1);
  32. spins--;
  33. } while (spins && (ctrl & (1 << MDIO_MMDREG_CTRL1_RESET_LBN)));
  34. return spins ? spins : -ETIMEDOUT;
  35. }
  36. static int mdio_clause45_check_mmd(struct efx_nic *efx, int mmd,
  37. int fault_fatal)
  38. {
  39. int status;
  40. int phy_id = efx->mii.phy_id;
  41. if (LOOPBACK_INTERNAL(efx))
  42. return 0;
  43. if (mmd != MDIO_MMD_AN) {
  44. /* Read MMD STATUS2 to check it is responding. */
  45. status = mdio_clause45_read(efx, phy_id, mmd,
  46. MDIO_MMDREG_STAT2);
  47. if (((status >> MDIO_MMDREG_STAT2_PRESENT_LBN) &
  48. ((1 << MDIO_MMDREG_STAT2_PRESENT_WIDTH) - 1)) !=
  49. MDIO_MMDREG_STAT2_PRESENT_VAL) {
  50. EFX_ERR(efx, "PHY MMD %d not responding.\n", mmd);
  51. return -EIO;
  52. }
  53. }
  54. /* Read MMD STATUS 1 to check for fault. */
  55. status = mdio_clause45_read(efx, phy_id, mmd, MDIO_MMDREG_STAT1);
  56. if ((status & (1 << MDIO_MMDREG_STAT1_FAULT_LBN)) != 0) {
  57. if (fault_fatal) {
  58. EFX_ERR(efx, "PHY MMD %d reporting fatal"
  59. " fault: status %x\n", mmd, status);
  60. return -EIO;
  61. } else {
  62. EFX_LOG(efx, "PHY MMD %d reporting status"
  63. " %x (expected)\n", mmd, status);
  64. }
  65. }
  66. return 0;
  67. }
  68. /* This ought to be ridiculous overkill. We expect it to fail rarely */
  69. #define MDIO45_RESET_TIME 1000 /* ms */
  70. #define MDIO45_RESET_ITERS 100
  71. int mdio_clause45_wait_reset_mmds(struct efx_nic *efx,
  72. unsigned int mmd_mask)
  73. {
  74. const int spintime = MDIO45_RESET_TIME / MDIO45_RESET_ITERS;
  75. int tries = MDIO45_RESET_ITERS;
  76. int rc = 0;
  77. int in_reset;
  78. while (tries) {
  79. int mask = mmd_mask;
  80. int mmd = 0;
  81. int stat;
  82. in_reset = 0;
  83. while (mask) {
  84. if (mask & 1) {
  85. stat = mdio_clause45_read(efx,
  86. efx->mii.phy_id,
  87. mmd,
  88. MDIO_MMDREG_CTRL1);
  89. if (stat < 0) {
  90. EFX_ERR(efx, "failed to read status of"
  91. " MMD %d\n", mmd);
  92. return -EIO;
  93. }
  94. if (stat & (1 << MDIO_MMDREG_CTRL1_RESET_LBN))
  95. in_reset |= (1 << mmd);
  96. }
  97. mask = mask >> 1;
  98. mmd++;
  99. }
  100. if (!in_reset)
  101. break;
  102. tries--;
  103. msleep(spintime);
  104. }
  105. if (in_reset != 0) {
  106. EFX_ERR(efx, "not all MMDs came out of reset in time."
  107. " MMDs still in reset: %x\n", in_reset);
  108. rc = -ETIMEDOUT;
  109. }
  110. return rc;
  111. }
  112. int mdio_clause45_check_mmds(struct efx_nic *efx,
  113. unsigned int mmd_mask, unsigned int fatal_mask)
  114. {
  115. u32 devices;
  116. int mmd = 0, probe_mmd;
  117. /* Historically we have probed the PHYXS to find out what devices are
  118. * present,but that doesn't work so well if the PHYXS isn't expected
  119. * to exist, if so just find the first item in the list supplied. */
  120. probe_mmd = (mmd_mask & MDIO_MMDREG_DEVS_PHYXS) ? MDIO_MMD_PHYXS :
  121. __ffs(mmd_mask);
  122. devices = (mdio_clause45_read(efx, efx->mii.phy_id,
  123. probe_mmd, MDIO_MMDREG_DEVS0) |
  124. mdio_clause45_read(efx, efx->mii.phy_id,
  125. probe_mmd, MDIO_MMDREG_DEVS1) << 16);
  126. /* Check all the expected MMDs are present */
  127. if (devices < 0) {
  128. EFX_ERR(efx, "failed to read devices present\n");
  129. return -EIO;
  130. }
  131. if ((devices & mmd_mask) != mmd_mask) {
  132. EFX_ERR(efx, "required MMDs not present: got %x, "
  133. "wanted %x\n", devices, mmd_mask);
  134. return -ENODEV;
  135. }
  136. EFX_TRACE(efx, "Devices present: %x\n", devices);
  137. /* Check all required MMDs are responding and happy. */
  138. while (mmd_mask) {
  139. if (mmd_mask & 1) {
  140. int fault_fatal = fatal_mask & 1;
  141. if (mdio_clause45_check_mmd(efx, mmd, fault_fatal))
  142. return -EIO;
  143. }
  144. mmd_mask = mmd_mask >> 1;
  145. fatal_mask = fatal_mask >> 1;
  146. mmd++;
  147. }
  148. return 0;
  149. }
  150. bool mdio_clause45_links_ok(struct efx_nic *efx, unsigned int mmd_mask)
  151. {
  152. int phy_id = efx->mii.phy_id;
  153. u32 reg;
  154. bool ok = true;
  155. int mmd = 0;
  156. /* If the port is in loopback, then we should only consider a subset
  157. * of mmd's */
  158. if (LOOPBACK_INTERNAL(efx))
  159. return true;
  160. else if (efx->loopback_mode == LOOPBACK_NETWORK)
  161. return false;
  162. else if (efx_phy_mode_disabled(efx->phy_mode))
  163. return false;
  164. else if (efx->loopback_mode == LOOPBACK_PHYXS)
  165. mmd_mask &= ~(MDIO_MMDREG_DEVS_PHYXS |
  166. MDIO_MMDREG_DEVS_PCS |
  167. MDIO_MMDREG_DEVS_PMAPMD |
  168. MDIO_MMDREG_DEVS_AN);
  169. else if (efx->loopback_mode == LOOPBACK_PCS)
  170. mmd_mask &= ~(MDIO_MMDREG_DEVS_PCS |
  171. MDIO_MMDREG_DEVS_PMAPMD |
  172. MDIO_MMDREG_DEVS_AN);
  173. else if (efx->loopback_mode == LOOPBACK_PMAPMD)
  174. mmd_mask &= ~(MDIO_MMDREG_DEVS_PMAPMD |
  175. MDIO_MMDREG_DEVS_AN);
  176. if (!mmd_mask) {
  177. /* Use presence of XGMII faults in leui of link state */
  178. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PHYXS,
  179. MDIO_PHYXS_STATUS2);
  180. return !(reg & (1 << MDIO_PHYXS_STATUS2_RX_FAULT_LBN));
  181. }
  182. while (mmd_mask) {
  183. if (mmd_mask & 1) {
  184. /* Double reads because link state is latched, and a
  185. * read moves the current state into the register */
  186. reg = mdio_clause45_read(efx, phy_id,
  187. mmd, MDIO_MMDREG_STAT1);
  188. reg = mdio_clause45_read(efx, phy_id,
  189. mmd, MDIO_MMDREG_STAT1);
  190. ok = ok && (reg & (1 << MDIO_MMDREG_STAT1_LINK_LBN));
  191. }
  192. mmd_mask = (mmd_mask >> 1);
  193. mmd++;
  194. }
  195. return ok;
  196. }
  197. void mdio_clause45_transmit_disable(struct efx_nic *efx)
  198. {
  199. mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  200. MDIO_MMDREG_TXDIS, MDIO_MMDREG_TXDIS_GLOBAL_LBN,
  201. efx->phy_mode & PHY_MODE_TX_DISABLED);
  202. }
  203. void mdio_clause45_phy_reconfigure(struct efx_nic *efx)
  204. {
  205. int phy_id = efx->mii.phy_id;
  206. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PMAPMD,
  207. MDIO_MMDREG_CTRL1, MDIO_PMAPMD_CTRL1_LBACK_LBN,
  208. efx->loopback_mode == LOOPBACK_PMAPMD);
  209. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PCS,
  210. MDIO_MMDREG_CTRL1, MDIO_MMDREG_CTRL1_LBACK_LBN,
  211. efx->loopback_mode == LOOPBACK_PCS);
  212. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PHYXS,
  213. MDIO_MMDREG_CTRL1, MDIO_MMDREG_CTRL1_LBACK_LBN,
  214. efx->loopback_mode == LOOPBACK_NETWORK);
  215. }
  216. static void mdio_clause45_set_mmd_lpower(struct efx_nic *efx,
  217. int lpower, int mmd)
  218. {
  219. int phy = efx->mii.phy_id;
  220. int stat = mdio_clause45_read(efx, phy, mmd, MDIO_MMDREG_STAT1);
  221. EFX_TRACE(efx, "Setting low power mode for MMD %d to %d\n",
  222. mmd, lpower);
  223. if (stat & (1 << MDIO_MMDREG_STAT1_LPABLE_LBN)) {
  224. mdio_clause45_set_flag(efx, phy, mmd, MDIO_MMDREG_CTRL1,
  225. MDIO_MMDREG_CTRL1_LPOWER_LBN, lpower);
  226. }
  227. }
  228. void mdio_clause45_set_mmds_lpower(struct efx_nic *efx,
  229. int low_power, unsigned int mmd_mask)
  230. {
  231. int mmd = 0;
  232. mmd_mask &= ~MDIO_MMDREG_DEVS_AN;
  233. while (mmd_mask) {
  234. if (mmd_mask & 1)
  235. mdio_clause45_set_mmd_lpower(efx, low_power, mmd);
  236. mmd_mask = (mmd_mask >> 1);
  237. mmd++;
  238. }
  239. }
  240. static u32 mdio_clause45_get_an(struct efx_nic *efx, u16 addr, u32 xnp)
  241. {
  242. int phy_id = efx->mii.phy_id;
  243. u32 result = 0;
  244. int reg;
  245. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN, addr);
  246. if (reg & ADVERTISE_10HALF)
  247. result |= ADVERTISED_10baseT_Half;
  248. if (reg & ADVERTISE_10FULL)
  249. result |= ADVERTISED_10baseT_Full;
  250. if (reg & ADVERTISE_100HALF)
  251. result |= ADVERTISED_100baseT_Half;
  252. if (reg & ADVERTISE_100FULL)
  253. result |= ADVERTISED_100baseT_Full;
  254. if (reg & LPA_RESV)
  255. result |= xnp;
  256. return result;
  257. }
  258. /**
  259. * mdio_clause45_get_settings - Read (some of) the PHY settings over MDIO.
  260. * @efx: Efx NIC
  261. * @ecmd: Buffer for settings
  262. *
  263. * On return the 'port', 'speed', 'supported' and 'advertising' fields of
  264. * ecmd have been filled out.
  265. */
  266. void mdio_clause45_get_settings(struct efx_nic *efx,
  267. struct ethtool_cmd *ecmd)
  268. {
  269. mdio_clause45_get_settings_ext(efx, ecmd, 0, 0);
  270. }
  271. /**
  272. * mdio_clause45_get_settings_ext - Read (some of) the PHY settings over MDIO.
  273. * @efx: Efx NIC
  274. * @ecmd: Buffer for settings
  275. * @xnp: Advertised Extended Next Page state
  276. * @xnp_lpa: Link Partner's advertised XNP state
  277. *
  278. * On return the 'port', 'speed', 'supported' and 'advertising' fields of
  279. * ecmd have been filled out.
  280. */
  281. void mdio_clause45_get_settings_ext(struct efx_nic *efx,
  282. struct ethtool_cmd *ecmd,
  283. u32 xnp, u32 xnp_lpa)
  284. {
  285. int phy_id = efx->mii.phy_id;
  286. int reg;
  287. ecmd->transceiver = XCVR_INTERNAL;
  288. ecmd->phy_address = phy_id;
  289. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  290. MDIO_MMDREG_CTRL2);
  291. switch (reg & MDIO_PMAPMD_CTRL2_TYPE_MASK) {
  292. case MDIO_PMAPMD_CTRL2_10G_BT:
  293. case MDIO_PMAPMD_CTRL2_1G_BT:
  294. case MDIO_PMAPMD_CTRL2_100_BT:
  295. case MDIO_PMAPMD_CTRL2_10_BT:
  296. ecmd->port = PORT_TP;
  297. ecmd->supported = SUPPORTED_TP;
  298. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  299. MDIO_MMDREG_SPEED);
  300. if (reg & (1 << MDIO_MMDREG_SPEED_10G_LBN))
  301. ecmd->supported |= SUPPORTED_10000baseT_Full;
  302. if (reg & (1 << MDIO_MMDREG_SPEED_1000M_LBN))
  303. ecmd->supported |= (SUPPORTED_1000baseT_Full |
  304. SUPPORTED_1000baseT_Half);
  305. if (reg & (1 << MDIO_MMDREG_SPEED_100M_LBN))
  306. ecmd->supported |= (SUPPORTED_100baseT_Full |
  307. SUPPORTED_100baseT_Half);
  308. if (reg & (1 << MDIO_MMDREG_SPEED_10M_LBN))
  309. ecmd->supported |= (SUPPORTED_10baseT_Full |
  310. SUPPORTED_10baseT_Half);
  311. ecmd->advertising = ADVERTISED_TP;
  312. break;
  313. /* We represent CX4 as fibre in the absence of anything better */
  314. case MDIO_PMAPMD_CTRL2_10G_CX4:
  315. /* All the other defined modes are flavours of optical */
  316. default:
  317. ecmd->port = PORT_FIBRE;
  318. ecmd->supported = SUPPORTED_FIBRE;
  319. ecmd->advertising = ADVERTISED_FIBRE;
  320. break;
  321. }
  322. if (efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_AN)) {
  323. ecmd->supported |= SUPPORTED_Autoneg;
  324. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  325. MDIO_MMDREG_CTRL1);
  326. if (reg & BMCR_ANENABLE) {
  327. ecmd->autoneg = AUTONEG_ENABLE;
  328. ecmd->advertising |=
  329. ADVERTISED_Autoneg |
  330. mdio_clause45_get_an(efx,
  331. MDIO_AN_ADVERTISE, xnp);
  332. } else
  333. ecmd->autoneg = AUTONEG_DISABLE;
  334. } else
  335. ecmd->autoneg = AUTONEG_DISABLE;
  336. if (ecmd->autoneg) {
  337. /* If AN is complete, report best common mode,
  338. * otherwise report best advertised mode. */
  339. u32 common = ecmd->advertising;
  340. if (mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  341. MDIO_MMDREG_STAT1) &
  342. (1 << MDIO_AN_STATUS_AN_DONE_LBN)) {
  343. common &= mdio_clause45_get_an(efx, MDIO_AN_LPA,
  344. xnp_lpa);
  345. }
  346. if (common & ADVERTISED_10000baseT_Full) {
  347. ecmd->speed = SPEED_10000;
  348. ecmd->duplex = DUPLEX_FULL;
  349. } else if (common & (ADVERTISED_1000baseT_Full |
  350. ADVERTISED_1000baseT_Half)) {
  351. ecmd->speed = SPEED_1000;
  352. ecmd->duplex = !!(common & ADVERTISED_1000baseT_Full);
  353. } else if (common & (ADVERTISED_100baseT_Full |
  354. ADVERTISED_100baseT_Half)) {
  355. ecmd->speed = SPEED_100;
  356. ecmd->duplex = !!(common & ADVERTISED_100baseT_Full);
  357. } else {
  358. ecmd->speed = SPEED_10;
  359. ecmd->duplex = !!(common & ADVERTISED_10baseT_Full);
  360. }
  361. } else {
  362. /* Report forced settings */
  363. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  364. MDIO_MMDREG_CTRL1);
  365. ecmd->speed = (((reg & BMCR_SPEED1000) ? 100 : 1) *
  366. ((reg & BMCR_SPEED100) ? 100 : 10));
  367. ecmd->duplex = (reg & BMCR_FULLDPLX ||
  368. ecmd->speed == SPEED_10000);
  369. }
  370. }
  371. /**
  372. * mdio_clause45_set_settings - Set (some of) the PHY settings over MDIO.
  373. * @efx: Efx NIC
  374. * @ecmd: New settings
  375. */
  376. int mdio_clause45_set_settings(struct efx_nic *efx,
  377. struct ethtool_cmd *ecmd)
  378. {
  379. int phy_id = efx->mii.phy_id;
  380. struct ethtool_cmd prev;
  381. u32 required;
  382. int ctrl1_bits, reg;
  383. efx->phy_op->get_settings(efx, &prev);
  384. if (ecmd->advertising == prev.advertising &&
  385. ecmd->speed == prev.speed &&
  386. ecmd->duplex == prev.duplex &&
  387. ecmd->port == prev.port &&
  388. ecmd->autoneg == prev.autoneg)
  389. return 0;
  390. /* We can only change these settings for -T PHYs */
  391. if (prev.port != PORT_TP || ecmd->port != PORT_TP)
  392. return -EINVAL;
  393. /* Check that PHY supports these settings and work out the
  394. * basic control bits */
  395. if (ecmd->duplex) {
  396. switch (ecmd->speed) {
  397. case SPEED_10:
  398. ctrl1_bits = BMCR_FULLDPLX;
  399. required = SUPPORTED_10baseT_Full;
  400. break;
  401. case SPEED_100:
  402. ctrl1_bits = BMCR_SPEED100 | BMCR_FULLDPLX;
  403. required = SUPPORTED_100baseT_Full;
  404. break;
  405. case SPEED_1000:
  406. ctrl1_bits = BMCR_SPEED1000 | BMCR_FULLDPLX;
  407. required = SUPPORTED_1000baseT_Full;
  408. break;
  409. case SPEED_10000:
  410. ctrl1_bits = (BMCR_SPEED1000 | BMCR_SPEED100 |
  411. BMCR_FULLDPLX);
  412. required = SUPPORTED_10000baseT_Full;
  413. break;
  414. default:
  415. return -EINVAL;
  416. }
  417. } else {
  418. switch (ecmd->speed) {
  419. case SPEED_10:
  420. ctrl1_bits = 0;
  421. required = SUPPORTED_10baseT_Half;
  422. break;
  423. case SPEED_100:
  424. ctrl1_bits = BMCR_SPEED100;
  425. required = SUPPORTED_100baseT_Half;
  426. break;
  427. case SPEED_1000:
  428. ctrl1_bits = BMCR_SPEED1000;
  429. required = SUPPORTED_1000baseT_Half;
  430. break;
  431. default:
  432. return -EINVAL;
  433. }
  434. }
  435. if (ecmd->autoneg)
  436. required |= SUPPORTED_Autoneg;
  437. required |= ecmd->advertising;
  438. if (required & ~prev.supported)
  439. return -EINVAL;
  440. /* Set the basic control bits */
  441. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  442. MDIO_MMDREG_CTRL1);
  443. reg &= ~(BMCR_SPEED1000 | BMCR_SPEED100 | BMCR_FULLDPLX | 0x003c);
  444. reg |= ctrl1_bits;
  445. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD, MDIO_MMDREG_CTRL1,
  446. reg);
  447. /* Set the AN registers */
  448. if (ecmd->autoneg != prev.autoneg ||
  449. ecmd->advertising != prev.advertising) {
  450. bool xnp = false;
  451. if (efx->phy_op->set_xnp_advertise)
  452. xnp = efx->phy_op->set_xnp_advertise(efx,
  453. ecmd->advertising);
  454. if (ecmd->autoneg) {
  455. reg = 0;
  456. if (ecmd->advertising & ADVERTISED_10baseT_Half)
  457. reg |= ADVERTISE_10HALF;
  458. if (ecmd->advertising & ADVERTISED_10baseT_Full)
  459. reg |= ADVERTISE_10FULL;
  460. if (ecmd->advertising & ADVERTISED_100baseT_Half)
  461. reg |= ADVERTISE_100HALF;
  462. if (ecmd->advertising & ADVERTISED_100baseT_Full)
  463. reg |= ADVERTISE_100FULL;
  464. if (xnp)
  465. reg |= ADVERTISE_RESV;
  466. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  467. MDIO_AN_ADVERTISE, reg);
  468. }
  469. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  470. MDIO_MMDREG_CTRL1);
  471. if (ecmd->autoneg)
  472. reg |= BMCR_ANENABLE | BMCR_ANRESTART;
  473. else
  474. reg &= ~BMCR_ANENABLE;
  475. if (EFX_WORKAROUND_15195(efx)
  476. && LOOPBACK_MASK(efx) & efx->phy_op->loopbacks)
  477. reg &= ~BMCR_ANRESTART;
  478. if (xnp)
  479. reg |= 1 << MDIO_AN_CTRL_XNP_LBN;
  480. else
  481. reg &= ~(1 << MDIO_AN_CTRL_XNP_LBN);
  482. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  483. MDIO_MMDREG_CTRL1, reg);
  484. }
  485. return 0;
  486. }
  487. void mdio_clause45_set_pause(struct efx_nic *efx)
  488. {
  489. int phy_id = efx->mii.phy_id;
  490. int reg;
  491. if (efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_AN)) {
  492. /* Set pause capability advertising */
  493. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  494. MDIO_AN_ADVERTISE);
  495. reg &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  496. reg |= efx_fc_advertise(efx->wanted_fc);
  497. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  498. MDIO_AN_ADVERTISE, reg);
  499. /* Restart auto-negotiation */
  500. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  501. MDIO_MMDREG_CTRL1);
  502. if (reg & BMCR_ANENABLE) {
  503. reg |= BMCR_ANRESTART;
  504. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  505. MDIO_MMDREG_CTRL1, reg);
  506. }
  507. }
  508. }
  509. enum efx_fc_type mdio_clause45_get_pause(struct efx_nic *efx)
  510. {
  511. int phy_id = efx->mii.phy_id;
  512. int lpa;
  513. if (!(efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_AN)))
  514. return efx->wanted_fc;
  515. lpa = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN, MDIO_AN_LPA);
  516. return efx_fc_resolve(efx->wanted_fc, lpa);
  517. }
  518. void mdio_clause45_set_flag(struct efx_nic *efx, u8 prt, u8 dev,
  519. u16 addr, int bit, bool sense)
  520. {
  521. int old_val = mdio_clause45_read(efx, prt, dev, addr);
  522. int new_val;
  523. if (sense)
  524. new_val = old_val | (1 << bit);
  525. else
  526. new_val = old_val & ~(1 << bit);
  527. if (old_val != new_val)
  528. mdio_clause45_write(efx, prt, dev, addr, new_val);
  529. }