mdio_10g.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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. u32 reg;
  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. if (!mmd_mask) {
  169. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PHYXS,
  170. MDIO_PHYXS_STATUS2);
  171. return !(reg & (1 << MDIO_PHYXS_STATUS2_RX_FAULT_LBN));
  172. }
  173. } else if (efx->loopback_mode == LOOPBACK_PCS)
  174. mmd_mask &= ~(MDIO_MMDREG_DEVS_PCS |
  175. MDIO_MMDREG_DEVS_PMAPMD |
  176. MDIO_MMDREG_DEVS_AN);
  177. else if (efx->loopback_mode == LOOPBACK_PMAPMD)
  178. mmd_mask &= ~(MDIO_MMDREG_DEVS_PMAPMD |
  179. MDIO_MMDREG_DEVS_AN);
  180. while (mmd_mask) {
  181. if (mmd_mask & 1) {
  182. /* Double reads because link state is latched, and a
  183. * read moves the current state into the register */
  184. reg = mdio_clause45_read(efx, phy_id,
  185. mmd, MDIO_MMDREG_STAT1);
  186. reg = mdio_clause45_read(efx, phy_id,
  187. mmd, MDIO_MMDREG_STAT1);
  188. ok = ok && (reg & (1 << MDIO_MMDREG_STAT1_LINK_LBN));
  189. }
  190. mmd_mask = (mmd_mask >> 1);
  191. mmd++;
  192. }
  193. return ok;
  194. }
  195. void mdio_clause45_transmit_disable(struct efx_nic *efx)
  196. {
  197. mdio_clause45_set_flag(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
  198. MDIO_MMDREG_TXDIS, MDIO_MMDREG_TXDIS_GLOBAL_LBN,
  199. efx->phy_mode & PHY_MODE_TX_DISABLED);
  200. }
  201. void mdio_clause45_phy_reconfigure(struct efx_nic *efx)
  202. {
  203. int phy_id = efx->mii.phy_id;
  204. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PMAPMD,
  205. MDIO_MMDREG_CTRL1, MDIO_PMAPMD_CTRL1_LBACK_LBN,
  206. efx->loopback_mode == LOOPBACK_PMAPMD);
  207. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PCS,
  208. MDIO_MMDREG_CTRL1, MDIO_MMDREG_CTRL1_LBACK_LBN,
  209. efx->loopback_mode == LOOPBACK_PCS);
  210. mdio_clause45_set_flag(efx, phy_id, MDIO_MMD_PHYXS,
  211. MDIO_MMDREG_CTRL1, MDIO_MMDREG_CTRL1_LBACK_LBN,
  212. efx->loopback_mode == LOOPBACK_NETWORK);
  213. }
  214. static void mdio_clause45_set_mmd_lpower(struct efx_nic *efx,
  215. int lpower, int mmd)
  216. {
  217. int phy = efx->mii.phy_id;
  218. int stat = mdio_clause45_read(efx, phy, mmd, MDIO_MMDREG_STAT1);
  219. EFX_TRACE(efx, "Setting low power mode for MMD %d to %d\n",
  220. mmd, lpower);
  221. if (stat & (1 << MDIO_MMDREG_STAT1_LPABLE_LBN)) {
  222. mdio_clause45_set_flag(efx, phy, mmd, MDIO_MMDREG_CTRL1,
  223. MDIO_MMDREG_CTRL1_LPOWER_LBN, lpower);
  224. }
  225. }
  226. void mdio_clause45_set_mmds_lpower(struct efx_nic *efx,
  227. int low_power, unsigned int mmd_mask)
  228. {
  229. int mmd = 0;
  230. mmd_mask &= ~MDIO_MMDREG_DEVS_AN;
  231. while (mmd_mask) {
  232. if (mmd_mask & 1)
  233. mdio_clause45_set_mmd_lpower(efx, low_power, mmd);
  234. mmd_mask = (mmd_mask >> 1);
  235. mmd++;
  236. }
  237. }
  238. static u32 mdio_clause45_get_an(struct efx_nic *efx, u16 addr, u32 xnp)
  239. {
  240. int phy_id = efx->mii.phy_id;
  241. u32 result = 0;
  242. int reg;
  243. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN, addr);
  244. if (reg & ADVERTISE_10HALF)
  245. result |= ADVERTISED_10baseT_Half;
  246. if (reg & ADVERTISE_10FULL)
  247. result |= ADVERTISED_10baseT_Full;
  248. if (reg & ADVERTISE_100HALF)
  249. result |= ADVERTISED_100baseT_Half;
  250. if (reg & ADVERTISE_100FULL)
  251. result |= ADVERTISED_100baseT_Full;
  252. if (reg & LPA_RESV)
  253. result |= xnp;
  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 xnp, u32 xnp_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,
  329. MDIO_AN_ADVERTISE, xnp);
  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 common = ecmd->advertising;
  338. if (mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  339. MDIO_MMDREG_STAT1) &
  340. (1 << MDIO_AN_STATUS_AN_DONE_LBN)) {
  341. common &= mdio_clause45_get_an(efx, MDIO_AN_LPA,
  342. xnp_lpa);
  343. }
  344. if (common & ADVERTISED_10000baseT_Full) {
  345. ecmd->speed = SPEED_10000;
  346. ecmd->duplex = DUPLEX_FULL;
  347. } else if (common & (ADVERTISED_1000baseT_Full |
  348. ADVERTISED_1000baseT_Half)) {
  349. ecmd->speed = SPEED_1000;
  350. ecmd->duplex = !!(common & ADVERTISED_1000baseT_Full);
  351. } else if (common & (ADVERTISED_100baseT_Full |
  352. ADVERTISED_100baseT_Half)) {
  353. ecmd->speed = SPEED_100;
  354. ecmd->duplex = !!(common & ADVERTISED_100baseT_Full);
  355. } else {
  356. ecmd->speed = SPEED_10;
  357. ecmd->duplex = !!(common & ADVERTISED_10baseT_Full);
  358. }
  359. } else {
  360. /* Report forced settings */
  361. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  362. MDIO_MMDREG_CTRL1);
  363. ecmd->speed = (((reg & BMCR_SPEED1000) ? 100 : 1) *
  364. ((reg & BMCR_SPEED100) ? 100 : 10));
  365. ecmd->duplex = (reg & BMCR_FULLDPLX ||
  366. ecmd->speed == SPEED_10000);
  367. }
  368. }
  369. /**
  370. * mdio_clause45_set_settings - Set (some of) the PHY settings over MDIO.
  371. * @efx: Efx NIC
  372. * @ecmd: New settings
  373. */
  374. int mdio_clause45_set_settings(struct efx_nic *efx,
  375. struct ethtool_cmd *ecmd)
  376. {
  377. int phy_id = efx->mii.phy_id;
  378. struct ethtool_cmd prev;
  379. u32 required;
  380. int ctrl1_bits, reg;
  381. efx->phy_op->get_settings(efx, &prev);
  382. if (ecmd->advertising == prev.advertising &&
  383. ecmd->speed == prev.speed &&
  384. ecmd->duplex == prev.duplex &&
  385. ecmd->port == prev.port &&
  386. ecmd->autoneg == prev.autoneg)
  387. return 0;
  388. /* We can only change these settings for -T PHYs */
  389. if (prev.port != PORT_TP || ecmd->port != PORT_TP)
  390. return -EINVAL;
  391. /* Check that PHY supports these settings and work out the
  392. * basic control bits */
  393. if (ecmd->duplex) {
  394. switch (ecmd->speed) {
  395. case SPEED_10:
  396. ctrl1_bits = BMCR_FULLDPLX;
  397. required = SUPPORTED_10baseT_Full;
  398. break;
  399. case SPEED_100:
  400. ctrl1_bits = BMCR_SPEED100 | BMCR_FULLDPLX;
  401. required = SUPPORTED_100baseT_Full;
  402. break;
  403. case SPEED_1000:
  404. ctrl1_bits = BMCR_SPEED1000 | BMCR_FULLDPLX;
  405. required = SUPPORTED_1000baseT_Full;
  406. break;
  407. case SPEED_10000:
  408. ctrl1_bits = (BMCR_SPEED1000 | BMCR_SPEED100 |
  409. BMCR_FULLDPLX);
  410. required = SUPPORTED_10000baseT_Full;
  411. break;
  412. default:
  413. return -EINVAL;
  414. }
  415. } else {
  416. switch (ecmd->speed) {
  417. case SPEED_10:
  418. ctrl1_bits = 0;
  419. required = SUPPORTED_10baseT_Half;
  420. break;
  421. case SPEED_100:
  422. ctrl1_bits = BMCR_SPEED100;
  423. required = SUPPORTED_100baseT_Half;
  424. break;
  425. case SPEED_1000:
  426. ctrl1_bits = BMCR_SPEED1000;
  427. required = SUPPORTED_1000baseT_Half;
  428. break;
  429. default:
  430. return -EINVAL;
  431. }
  432. }
  433. if (ecmd->autoneg)
  434. required |= SUPPORTED_Autoneg;
  435. required |= ecmd->advertising;
  436. if (required & ~prev.supported)
  437. return -EINVAL;
  438. /* Set the basic control bits */
  439. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
  440. MDIO_MMDREG_CTRL1);
  441. reg &= ~(BMCR_SPEED1000 | BMCR_SPEED100 | BMCR_FULLDPLX | 0x003c);
  442. reg |= ctrl1_bits;
  443. mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD, MDIO_MMDREG_CTRL1,
  444. reg);
  445. /* Set the AN registers */
  446. if (ecmd->autoneg != prev.autoneg ||
  447. ecmd->advertising != prev.advertising) {
  448. bool xnp = false;
  449. if (efx->phy_op->set_xnp_advertise)
  450. xnp = efx->phy_op->set_xnp_advertise(efx,
  451. ecmd->advertising);
  452. if (ecmd->autoneg) {
  453. reg = 0;
  454. if (ecmd->advertising & ADVERTISED_10baseT_Half)
  455. reg |= ADVERTISE_10HALF;
  456. if (ecmd->advertising & ADVERTISED_10baseT_Full)
  457. reg |= ADVERTISE_10FULL;
  458. if (ecmd->advertising & ADVERTISED_100baseT_Half)
  459. reg |= ADVERTISE_100HALF;
  460. if (ecmd->advertising & ADVERTISED_100baseT_Full)
  461. reg |= ADVERTISE_100FULL;
  462. if (xnp)
  463. reg |= ADVERTISE_RESV;
  464. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  465. MDIO_AN_ADVERTISE, reg);
  466. }
  467. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  468. MDIO_MMDREG_CTRL1);
  469. if (ecmd->autoneg)
  470. reg |= BMCR_ANENABLE | BMCR_ANRESTART;
  471. else
  472. reg &= ~BMCR_ANENABLE;
  473. if (xnp)
  474. reg |= 1 << MDIO_AN_CTRL_XNP_LBN;
  475. else
  476. reg &= ~(1 << MDIO_AN_CTRL_XNP_LBN);
  477. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  478. MDIO_MMDREG_CTRL1, reg);
  479. }
  480. return 0;
  481. }
  482. void mdio_clause45_set_pause(struct efx_nic *efx)
  483. {
  484. int phy_id = efx->mii.phy_id;
  485. int reg;
  486. if (efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_AN)) {
  487. /* Set pause capability advertising */
  488. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  489. MDIO_AN_ADVERTISE);
  490. reg &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  491. reg |= efx_fc_advertise(efx->wanted_fc);
  492. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  493. MDIO_AN_ADVERTISE, reg);
  494. /* Restart auto-negotiation */
  495. reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
  496. MDIO_MMDREG_CTRL1);
  497. if (reg & BMCR_ANENABLE) {
  498. reg |= BMCR_ANRESTART;
  499. mdio_clause45_write(efx, phy_id, MDIO_MMD_AN,
  500. MDIO_MMDREG_CTRL1, reg);
  501. }
  502. }
  503. }
  504. enum efx_fc_type mdio_clause45_get_pause(struct efx_nic *efx)
  505. {
  506. int phy_id = efx->mii.phy_id;
  507. int lpa;
  508. if (!(efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_AN)))
  509. return efx->wanted_fc;
  510. lpa = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN, MDIO_AN_LPA);
  511. return efx_fc_resolve(efx->wanted_fc, lpa);
  512. }
  513. void mdio_clause45_set_flag(struct efx_nic *efx, u8 prt, u8 dev,
  514. u16 addr, int bit, bool sense)
  515. {
  516. int old_val = mdio_clause45_read(efx, prt, dev, addr);
  517. int new_val;
  518. if (sense)
  519. new_val = old_val | (1 << bit);
  520. else
  521. new_val = old_val & ~(1 << bit);
  522. if (old_val != new_val)
  523. mdio_clause45_write(efx, prt, dev, addr, new_val);
  524. }