mdio_10g.c 16 KB

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