mdio_10g.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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)
  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. return result;
  255. }
  256. /**
  257. * mdio_clause45_get_settings - Read (some of) the PHY settings over MDIO.
  258. * @efx: Efx NIC
  259. * @ecmd: Buffer for settings
  260. *
  261. * On return the 'port', 'speed', 'supported' and 'advertising' fields of
  262. * ecmd have been filled out.
  263. */
  264. void mdio_clause45_get_settings(struct efx_nic *efx,
  265. struct ethtool_cmd *ecmd)
  266. {
  267. mdio_clause45_get_settings_ext(efx, ecmd, 0, 0);
  268. }
  269. /**
  270. * mdio_clause45_get_settings_ext - Read (some of) the PHY settings over MDIO.
  271. * @efx: Efx NIC
  272. * @ecmd: Buffer for settings
  273. * @xnp: Advertised Extended Next Page state
  274. * @xnp_lpa: Link Partner's advertised XNP state
  275. *
  276. * On return the 'port', 'speed', 'supported' and 'advertising' fields of
  277. * ecmd have been filled out.
  278. */
  279. void mdio_clause45_get_settings_ext(struct efx_nic *efx,
  280. struct ethtool_cmd *ecmd,
  281. u32 npage_adv, u32 npage_lpa)
  282. {
  283. int phy_id = efx->mii.phy_id;
  284. int reg;
  285. ecmd->transceiver = XCVR_INTERNAL;
  286. ecmd->phy_address = phy_id;
  287. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  288. MDIO_MMDREG_CTRL2);
  289. switch (reg & MDIO_PMAPMD_CTRL2_TYPE_MASK) {
  290. case MDIO_PMAPMD_CTRL2_10G_BT:
  291. case MDIO_PMAPMD_CTRL2_1G_BT:
  292. case MDIO_PMAPMD_CTRL2_100_BT:
  293. case MDIO_PMAPMD_CTRL2_10_BT:
  294. ecmd->port = PORT_TP;
  295. ecmd->supported = SUPPORTED_TP;
  296. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  297. MDIO_MMDREG_SPEED);
  298. if (reg & (1 << MDIO_MMDREG_SPEED_10G_LBN))
  299. ecmd->supported |= SUPPORTED_10000baseT_Full;
  300. if (reg & (1 << MDIO_MMDREG_SPEED_1000M_LBN))
  301. ecmd->supported |= (SUPPORTED_1000baseT_Full |
  302. SUPPORTED_1000baseT_Half);
  303. if (reg & (1 << MDIO_MMDREG_SPEED_100M_LBN))
  304. ecmd->supported |= (SUPPORTED_100baseT_Full |
  305. SUPPORTED_100baseT_Half);
  306. if (reg & (1 << MDIO_MMDREG_SPEED_10M_LBN))
  307. ecmd->supported |= (SUPPORTED_10baseT_Full |
  308. SUPPORTED_10baseT_Half);
  309. ecmd->advertising = ADVERTISED_TP;
  310. break;
  311. /* We represent CX4 as fibre in the absence of anything better */
  312. case MDIO_PMAPMD_CTRL2_10G_CX4:
  313. /* All the other defined modes are flavours of optical */
  314. default:
  315. ecmd->port = PORT_FIBRE;
  316. ecmd->supported = SUPPORTED_FIBRE;
  317. ecmd->advertising = ADVERTISED_FIBRE;
  318. break;
  319. }
  320. if (efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_AN)) {
  321. ecmd->supported |= SUPPORTED_Autoneg;
  322. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  323. MDIO_MMDREG_CTRL1);
  324. if (reg & BMCR_ANENABLE) {
  325. ecmd->autoneg = AUTONEG_ENABLE;
  326. ecmd->advertising |=
  327. ADVERTISED_Autoneg |
  328. mdio_clause45_get_an(efx, MDIO_AN_ADVERTISE) |
  329. npage_adv;
  330. } else
  331. ecmd->autoneg = AUTONEG_DISABLE;
  332. } else
  333. ecmd->autoneg = AUTONEG_DISABLE;
  334. if (ecmd->autoneg) {
  335. /* If AN is complete, report best common mode,
  336. * otherwise report best advertised mode. */
  337. u32 modes = 0;
  338. if (mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  339. MDIO_MMDREG_STAT1) &
  340. (1 << MDIO_AN_STATUS_AN_DONE_LBN))
  341. modes = (ecmd->advertising &
  342. (mdio_clause45_get_an(efx, MDIO_AN_LPA) |
  343. npage_lpa));
  344. if (modes == 0)
  345. modes = ecmd->advertising;
  346. if (modes & ADVERTISED_10000baseT_Full) {
  347. ecmd->speed = SPEED_10000;
  348. ecmd->duplex = DUPLEX_FULL;
  349. } else if (modes & (ADVERTISED_1000baseT_Full |
  350. ADVERTISED_1000baseT_Half)) {
  351. ecmd->speed = SPEED_1000;
  352. ecmd->duplex = !!(modes & ADVERTISED_1000baseT_Full);
  353. } else if (modes & (ADVERTISED_100baseT_Full |
  354. ADVERTISED_100baseT_Half)) {
  355. ecmd->speed = SPEED_100;
  356. ecmd->duplex = !!(modes & ADVERTISED_100baseT_Full);
  357. } else {
  358. ecmd->speed = SPEED_10;
  359. ecmd->duplex = !!(modes & 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 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 */
  394. if (ecmd->autoneg) {
  395. required = SUPPORTED_Autoneg;
  396. } else if (ecmd->duplex) {
  397. switch (ecmd->speed) {
  398. case SPEED_10: required = SUPPORTED_10baseT_Full; break;
  399. case SPEED_100: required = SUPPORTED_100baseT_Full; break;
  400. default: return -EINVAL;
  401. }
  402. } else {
  403. switch (ecmd->speed) {
  404. case SPEED_10: required = SUPPORTED_10baseT_Half; break;
  405. case SPEED_100: required = SUPPORTED_100baseT_Half; break;
  406. default: return -EINVAL;
  407. }
  408. }
  409. required |= ecmd->advertising;
  410. if (required & ~prev.supported)
  411. return -EINVAL;
  412. if (ecmd->autoneg) {
  413. bool xnp = (ecmd->advertising & ADVERTISED_10000baseT_Full
  414. || EFX_WORKAROUND_13204(efx));
  415. /* Set up the base page */
  416. reg = ADVERTISE_CSMA;
  417. if (ecmd->advertising & ADVERTISED_10baseT_Half)
  418. reg |= ADVERTISE_10HALF;
  419. if (ecmd->advertising & ADVERTISED_10baseT_Full)
  420. reg |= ADVERTISE_10FULL;
  421. if (ecmd->advertising & ADVERTISED_100baseT_Half)
  422. reg |= ADVERTISE_100HALF;
  423. if (ecmd->advertising & ADVERTISED_100baseT_Full)
  424. reg |= ADVERTISE_100FULL;
  425. if (xnp)
  426. reg |= ADVERTISE_RESV;
  427. else if (ecmd->advertising & (ADVERTISED_1000baseT_Half |
  428. ADVERTISED_1000baseT_Full))
  429. reg |= ADVERTISE_NPAGE;
  430. reg |= efx_fc_advertise(efx->wanted_fc);
  431. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  432. MDIO_AN_ADVERTISE, reg);
  433. /* Set up the (extended) next page if necessary */
  434. if (efx->phy_op->set_npage_adv)
  435. efx->phy_op->set_npage_adv(efx, ecmd->advertising);
  436. /* Enable and restart AN */
  437. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  438. MDIO_MMDREG_CTRL1);
  439. reg |= BMCR_ANENABLE;
  440. if (!(EFX_WORKAROUND_15195(efx) &&
  441. LOOPBACK_MASK(efx) & efx->phy_op->loopbacks))
  442. reg |= BMCR_ANRESTART;
  443. if (xnp)
  444. reg |= 1 << MDIO_AN_CTRL_XNP_LBN;
  445. else
  446. reg &= ~(1 << MDIO_AN_CTRL_XNP_LBN);
  447. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  448. MDIO_MMDREG_CTRL1, reg);
  449. } else {
  450. /* Disable AN */
  451. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_AN,
  452. MDIO_MMDREG_CTRL1,
  453. __ffs(BMCR_ANENABLE), false);
  454. /* Set the basic control bits */
  455. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  456. MDIO_MMDREG_CTRL1);
  457. reg &= ~(BMCR_SPEED1000 | BMCR_SPEED100 | BMCR_FULLDPLX |
  458. 0x003c);
  459. if (ecmd->speed == SPEED_100)
  460. reg |= BMCR_SPEED100;
  461. if (ecmd->duplex)
  462. reg |= BMCR_FULLDPLX;
  463. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
  464. MDIO_MMDREG_CTRL1, reg);
  465. }
  466. return 0;
  467. }
  468. void mdio_clause45_set_pause(struct efx_nic *efx)
  469. {
  470. int phy_id = efx->mii.phy_id;
  471. int reg;
  472. if (efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_AN)) {
  473. /* Set pause capability advertising */
  474. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  475. MDIO_AN_ADVERTISE);
  476. reg &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  477. reg |= efx_fc_advertise(efx->wanted_fc);
  478. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  479. MDIO_AN_ADVERTISE, reg);
  480. /* Restart auto-negotiation */
  481. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  482. MDIO_MMDREG_CTRL1);
  483. if (reg & BMCR_ANENABLE) {
  484. reg |= BMCR_ANRESTART;
  485. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  486. MDIO_MMDREG_CTRL1, reg);
  487. }
  488. }
  489. }
  490. enum efx_fc_type mdio_clause45_get_pause(struct efx_nic *efx)
  491. {
  492. int phy_id = efx->mii.phy_id;
  493. int lpa;
  494. if (!(efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_AN)))
  495. return efx->wanted_fc;
  496. lpa = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN, MDIO_AN_LPA);
  497. return efx_fc_resolve(efx->wanted_fc, lpa);
  498. }
  499. void mdio_clause45_set_flag(struct efx_nic *efx, u8 prt, u8 dev,
  500. u16 addr, int bit, bool sense)
  501. {
  502. int old_val = mdio_clause45_read(efx, prt, dev, addr);
  503. int new_val;
  504. if (sense)
  505. new_val = old_val | (1 << bit);
  506. else
  507. new_val = old_val & ~(1 << bit);
  508. if (old_val != new_val)
  509. mdio_clause45_write(efx, prt, dev, addr, new_val);
  510. }