mdio_10g.c 16 KB

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