mcdi_phy.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2009 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. * Driver for PHY related operations via MCDI.
  11. */
  12. #include <linux/slab.h>
  13. #include "efx.h"
  14. #include "phy.h"
  15. #include "mcdi.h"
  16. #include "mcdi_pcol.h"
  17. #include "mdio_10g.h"
  18. struct efx_mcdi_phy_cfg {
  19. u32 flags;
  20. u32 type;
  21. u32 supported_cap;
  22. u32 channel;
  23. u32 port;
  24. u32 stats_mask;
  25. u8 name[20];
  26. u32 media;
  27. u32 mmd_mask;
  28. u8 revision[20];
  29. u32 forced_cap;
  30. };
  31. static int
  32. efx_mcdi_get_phy_cfg(struct efx_nic *efx, struct efx_mcdi_phy_cfg *cfg)
  33. {
  34. u8 outbuf[MC_CMD_GET_PHY_CFG_OUT_LEN];
  35. size_t outlen;
  36. int rc;
  37. BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_IN_LEN != 0);
  38. BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_OUT_NAME_LEN != sizeof(cfg->name));
  39. rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_CFG, NULL, 0,
  40. outbuf, sizeof(outbuf), &outlen);
  41. if (rc)
  42. goto fail;
  43. if (outlen < MC_CMD_GET_PHY_CFG_OUT_LEN) {
  44. rc = -EIO;
  45. goto fail;
  46. }
  47. cfg->flags = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_FLAGS);
  48. cfg->type = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_TYPE);
  49. cfg->supported_cap =
  50. MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_SUPPORTED_CAP);
  51. cfg->channel = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_CHANNEL);
  52. cfg->port = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_PRT);
  53. cfg->stats_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_STATS_MASK);
  54. memcpy(cfg->name, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_NAME),
  55. sizeof(cfg->name));
  56. cfg->media = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MEDIA_TYPE);
  57. cfg->mmd_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MMD_MASK);
  58. memcpy(cfg->revision, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_REVISION),
  59. sizeof(cfg->revision));
  60. return 0;
  61. fail:
  62. EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc);
  63. return rc;
  64. }
  65. static int efx_mcdi_set_link(struct efx_nic *efx, u32 capabilities,
  66. u32 flags, u32 loopback_mode,
  67. u32 loopback_speed)
  68. {
  69. u8 inbuf[MC_CMD_SET_LINK_IN_LEN];
  70. int rc;
  71. BUILD_BUG_ON(MC_CMD_SET_LINK_OUT_LEN != 0);
  72. MCDI_SET_DWORD(inbuf, SET_LINK_IN_CAP, capabilities);
  73. MCDI_SET_DWORD(inbuf, SET_LINK_IN_FLAGS, flags);
  74. MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_MODE, loopback_mode);
  75. MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_SPEED, loopback_speed);
  76. rc = efx_mcdi_rpc(efx, MC_CMD_SET_LINK, inbuf, sizeof(inbuf),
  77. NULL, 0, NULL);
  78. if (rc)
  79. goto fail;
  80. return 0;
  81. fail:
  82. EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc);
  83. return rc;
  84. }
  85. static int efx_mcdi_loopback_modes(struct efx_nic *efx, u64 *loopback_modes)
  86. {
  87. u8 outbuf[MC_CMD_GET_LOOPBACK_MODES_OUT_LEN];
  88. size_t outlen;
  89. int rc;
  90. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LOOPBACK_MODES, NULL, 0,
  91. outbuf, sizeof(outbuf), &outlen);
  92. if (rc)
  93. goto fail;
  94. if (outlen < MC_CMD_GET_LOOPBACK_MODES_OUT_LEN) {
  95. rc = -EIO;
  96. goto fail;
  97. }
  98. *loopback_modes = MCDI_QWORD(outbuf, GET_LOOPBACK_MODES_SUGGESTED);
  99. return 0;
  100. fail:
  101. EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc);
  102. return rc;
  103. }
  104. int efx_mcdi_mdio_read(struct efx_nic *efx, unsigned int bus,
  105. unsigned int prtad, unsigned int devad, u16 addr,
  106. u16 *value_out, u32 *status_out)
  107. {
  108. u8 inbuf[MC_CMD_MDIO_READ_IN_LEN];
  109. u8 outbuf[MC_CMD_MDIO_READ_OUT_LEN];
  110. size_t outlen;
  111. int rc;
  112. MCDI_SET_DWORD(inbuf, MDIO_READ_IN_BUS, bus);
  113. MCDI_SET_DWORD(inbuf, MDIO_READ_IN_PRTAD, prtad);
  114. MCDI_SET_DWORD(inbuf, MDIO_READ_IN_DEVAD, devad);
  115. MCDI_SET_DWORD(inbuf, MDIO_READ_IN_ADDR, addr);
  116. rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_READ, inbuf, sizeof(inbuf),
  117. outbuf, sizeof(outbuf), &outlen);
  118. if (rc)
  119. goto fail;
  120. *value_out = (u16)MCDI_DWORD(outbuf, MDIO_READ_OUT_VALUE);
  121. *status_out = MCDI_DWORD(outbuf, MDIO_READ_OUT_STATUS);
  122. return 0;
  123. fail:
  124. EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc);
  125. return rc;
  126. }
  127. int efx_mcdi_mdio_write(struct efx_nic *efx, unsigned int bus,
  128. unsigned int prtad, unsigned int devad, u16 addr,
  129. u16 value, u32 *status_out)
  130. {
  131. u8 inbuf[MC_CMD_MDIO_WRITE_IN_LEN];
  132. u8 outbuf[MC_CMD_MDIO_WRITE_OUT_LEN];
  133. size_t outlen;
  134. int rc;
  135. MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_BUS, bus);
  136. MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_PRTAD, prtad);
  137. MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_DEVAD, devad);
  138. MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_ADDR, addr);
  139. MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_VALUE, value);
  140. rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_WRITE, inbuf, sizeof(inbuf),
  141. outbuf, sizeof(outbuf), &outlen);
  142. if (rc)
  143. goto fail;
  144. *status_out = MCDI_DWORD(outbuf, MDIO_WRITE_OUT_STATUS);
  145. return 0;
  146. fail:
  147. EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc);
  148. return rc;
  149. }
  150. static u32 mcdi_to_ethtool_cap(u32 media, u32 cap)
  151. {
  152. u32 result = 0;
  153. switch (media) {
  154. case MC_CMD_MEDIA_KX4:
  155. result |= SUPPORTED_Backplane;
  156. if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
  157. result |= SUPPORTED_1000baseKX_Full;
  158. if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
  159. result |= SUPPORTED_10000baseKX4_Full;
  160. break;
  161. case MC_CMD_MEDIA_XFP:
  162. case MC_CMD_MEDIA_SFP_PLUS:
  163. result |= SUPPORTED_FIBRE;
  164. break;
  165. case MC_CMD_MEDIA_BASE_T:
  166. result |= SUPPORTED_TP;
  167. if (cap & (1 << MC_CMD_PHY_CAP_10HDX_LBN))
  168. result |= SUPPORTED_10baseT_Half;
  169. if (cap & (1 << MC_CMD_PHY_CAP_10FDX_LBN))
  170. result |= SUPPORTED_10baseT_Full;
  171. if (cap & (1 << MC_CMD_PHY_CAP_100HDX_LBN))
  172. result |= SUPPORTED_100baseT_Half;
  173. if (cap & (1 << MC_CMD_PHY_CAP_100FDX_LBN))
  174. result |= SUPPORTED_100baseT_Full;
  175. if (cap & (1 << MC_CMD_PHY_CAP_1000HDX_LBN))
  176. result |= SUPPORTED_1000baseT_Half;
  177. if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
  178. result |= SUPPORTED_1000baseT_Full;
  179. if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
  180. result |= SUPPORTED_10000baseT_Full;
  181. break;
  182. }
  183. if (cap & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
  184. result |= SUPPORTED_Pause;
  185. if (cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
  186. result |= SUPPORTED_Asym_Pause;
  187. if (cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
  188. result |= SUPPORTED_Autoneg;
  189. return result;
  190. }
  191. static u32 ethtool_to_mcdi_cap(u32 cap)
  192. {
  193. u32 result = 0;
  194. if (cap & SUPPORTED_10baseT_Half)
  195. result |= (1 << MC_CMD_PHY_CAP_10HDX_LBN);
  196. if (cap & SUPPORTED_10baseT_Full)
  197. result |= (1 << MC_CMD_PHY_CAP_10FDX_LBN);
  198. if (cap & SUPPORTED_100baseT_Half)
  199. result |= (1 << MC_CMD_PHY_CAP_100HDX_LBN);
  200. if (cap & SUPPORTED_100baseT_Full)
  201. result |= (1 << MC_CMD_PHY_CAP_100FDX_LBN);
  202. if (cap & SUPPORTED_1000baseT_Half)
  203. result |= (1 << MC_CMD_PHY_CAP_1000HDX_LBN);
  204. if (cap & (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseKX_Full))
  205. result |= (1 << MC_CMD_PHY_CAP_1000FDX_LBN);
  206. if (cap & (SUPPORTED_10000baseT_Full | SUPPORTED_10000baseKX4_Full))
  207. result |= (1 << MC_CMD_PHY_CAP_10000FDX_LBN);
  208. if (cap & SUPPORTED_Pause)
  209. result |= (1 << MC_CMD_PHY_CAP_PAUSE_LBN);
  210. if (cap & SUPPORTED_Asym_Pause)
  211. result |= (1 << MC_CMD_PHY_CAP_ASYM_LBN);
  212. if (cap & SUPPORTED_Autoneg)
  213. result |= (1 << MC_CMD_PHY_CAP_AN_LBN);
  214. return result;
  215. }
  216. static u32 efx_get_mcdi_phy_flags(struct efx_nic *efx)
  217. {
  218. struct efx_mcdi_phy_cfg *phy_cfg = efx->phy_data;
  219. enum efx_phy_mode mode, supported;
  220. u32 flags;
  221. /* TODO: Advertise the capabilities supported by this PHY */
  222. supported = 0;
  223. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_TXDIS_LBN))
  224. supported |= PHY_MODE_TX_DISABLED;
  225. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_LOWPOWER_LBN))
  226. supported |= PHY_MODE_LOW_POWER;
  227. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_POWEROFF_LBN))
  228. supported |= PHY_MODE_OFF;
  229. mode = efx->phy_mode & supported;
  230. flags = 0;
  231. if (mode & PHY_MODE_TX_DISABLED)
  232. flags |= (1 << MC_CMD_SET_LINK_TXDIS_LBN);
  233. if (mode & PHY_MODE_LOW_POWER)
  234. flags |= (1 << MC_CMD_SET_LINK_LOWPOWER_LBN);
  235. if (mode & PHY_MODE_OFF)
  236. flags |= (1 << MC_CMD_SET_LINK_POWEROFF_LBN);
  237. return flags;
  238. }
  239. static u32 mcdi_to_ethtool_media(u32 media)
  240. {
  241. switch (media) {
  242. case MC_CMD_MEDIA_XAUI:
  243. case MC_CMD_MEDIA_CX4:
  244. case MC_CMD_MEDIA_KX4:
  245. return PORT_OTHER;
  246. case MC_CMD_MEDIA_XFP:
  247. case MC_CMD_MEDIA_SFP_PLUS:
  248. return PORT_FIBRE;
  249. case MC_CMD_MEDIA_BASE_T:
  250. return PORT_TP;
  251. default:
  252. return PORT_OTHER;
  253. }
  254. }
  255. static int efx_mcdi_phy_probe(struct efx_nic *efx)
  256. {
  257. struct efx_mcdi_phy_cfg *phy_data;
  258. u8 outbuf[MC_CMD_GET_LINK_OUT_LEN];
  259. u32 caps;
  260. int rc;
  261. /* Initialise and populate phy_data */
  262. phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
  263. if (phy_data == NULL)
  264. return -ENOMEM;
  265. rc = efx_mcdi_get_phy_cfg(efx, phy_data);
  266. if (rc != 0)
  267. goto fail;
  268. /* Read initial link advertisement */
  269. BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
  270. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
  271. outbuf, sizeof(outbuf), NULL);
  272. if (rc)
  273. goto fail;
  274. /* Fill out nic state */
  275. efx->phy_data = phy_data;
  276. efx->phy_type = phy_data->type;
  277. efx->mdio_bus = phy_data->channel;
  278. efx->mdio.prtad = phy_data->port;
  279. efx->mdio.mmds = phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22);
  280. efx->mdio.mode_support = 0;
  281. if (phy_data->mmd_mask & (1 << MC_CMD_MMD_CLAUSE22))
  282. efx->mdio.mode_support |= MDIO_SUPPORTS_C22;
  283. if (phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22))
  284. efx->mdio.mode_support |= MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  285. caps = MCDI_DWORD(outbuf, GET_LINK_OUT_CAP);
  286. if (caps & (1 << MC_CMD_PHY_CAP_AN_LBN))
  287. efx->link_advertising =
  288. mcdi_to_ethtool_cap(phy_data->media, caps);
  289. else
  290. phy_data->forced_cap = caps;
  291. /* Assert that we can map efx -> mcdi loopback modes */
  292. BUILD_BUG_ON(LOOPBACK_NONE != MC_CMD_LOOPBACK_NONE);
  293. BUILD_BUG_ON(LOOPBACK_DATA != MC_CMD_LOOPBACK_DATA);
  294. BUILD_BUG_ON(LOOPBACK_GMAC != MC_CMD_LOOPBACK_GMAC);
  295. BUILD_BUG_ON(LOOPBACK_XGMII != MC_CMD_LOOPBACK_XGMII);
  296. BUILD_BUG_ON(LOOPBACK_XGXS != MC_CMD_LOOPBACK_XGXS);
  297. BUILD_BUG_ON(LOOPBACK_XAUI != MC_CMD_LOOPBACK_XAUI);
  298. BUILD_BUG_ON(LOOPBACK_GMII != MC_CMD_LOOPBACK_GMII);
  299. BUILD_BUG_ON(LOOPBACK_SGMII != MC_CMD_LOOPBACK_SGMII);
  300. BUILD_BUG_ON(LOOPBACK_XGBR != MC_CMD_LOOPBACK_XGBR);
  301. BUILD_BUG_ON(LOOPBACK_XFI != MC_CMD_LOOPBACK_XFI);
  302. BUILD_BUG_ON(LOOPBACK_XAUI_FAR != MC_CMD_LOOPBACK_XAUI_FAR);
  303. BUILD_BUG_ON(LOOPBACK_GMII_FAR != MC_CMD_LOOPBACK_GMII_FAR);
  304. BUILD_BUG_ON(LOOPBACK_SGMII_FAR != MC_CMD_LOOPBACK_SGMII_FAR);
  305. BUILD_BUG_ON(LOOPBACK_XFI_FAR != MC_CMD_LOOPBACK_XFI_FAR);
  306. BUILD_BUG_ON(LOOPBACK_GPHY != MC_CMD_LOOPBACK_GPHY);
  307. BUILD_BUG_ON(LOOPBACK_PHYXS != MC_CMD_LOOPBACK_PHYXS);
  308. BUILD_BUG_ON(LOOPBACK_PCS != MC_CMD_LOOPBACK_PCS);
  309. BUILD_BUG_ON(LOOPBACK_PMAPMD != MC_CMD_LOOPBACK_PMAPMD);
  310. BUILD_BUG_ON(LOOPBACK_XPORT != MC_CMD_LOOPBACK_XPORT);
  311. BUILD_BUG_ON(LOOPBACK_XGMII_WS != MC_CMD_LOOPBACK_XGMII_WS);
  312. BUILD_BUG_ON(LOOPBACK_XAUI_WS != MC_CMD_LOOPBACK_XAUI_WS);
  313. BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR != MC_CMD_LOOPBACK_XAUI_WS_FAR);
  314. BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR != MC_CMD_LOOPBACK_XAUI_WS_NEAR);
  315. BUILD_BUG_ON(LOOPBACK_GMII_WS != MC_CMD_LOOPBACK_GMII_WS);
  316. BUILD_BUG_ON(LOOPBACK_XFI_WS != MC_CMD_LOOPBACK_XFI_WS);
  317. BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR != MC_CMD_LOOPBACK_XFI_WS_FAR);
  318. BUILD_BUG_ON(LOOPBACK_PHYXS_WS != MC_CMD_LOOPBACK_PHYXS_WS);
  319. rc = efx_mcdi_loopback_modes(efx, &efx->loopback_modes);
  320. if (rc != 0)
  321. goto fail;
  322. /* The MC indicates that LOOPBACK_NONE is a valid loopback mode,
  323. * but by convention we don't */
  324. efx->loopback_modes &= ~(1 << LOOPBACK_NONE);
  325. /* Set the initial link mode */
  326. efx_mcdi_phy_decode_link(
  327. efx, &efx->link_state,
  328. MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED),
  329. MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS),
  330. MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL));
  331. /* Default to Autonegotiated flow control if the PHY supports it */
  332. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  333. if (phy_data->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
  334. efx->wanted_fc |= EFX_FC_AUTO;
  335. return 0;
  336. fail:
  337. kfree(phy_data);
  338. return rc;
  339. }
  340. int efx_mcdi_phy_reconfigure(struct efx_nic *efx)
  341. {
  342. struct efx_mcdi_phy_cfg *phy_cfg = efx->phy_data;
  343. u32 caps = (efx->link_advertising ?
  344. ethtool_to_mcdi_cap(efx->link_advertising) :
  345. phy_cfg->forced_cap);
  346. return efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
  347. efx->loopback_mode, 0);
  348. }
  349. void efx_mcdi_phy_decode_link(struct efx_nic *efx,
  350. struct efx_link_state *link_state,
  351. u32 speed, u32 flags, u32 fcntl)
  352. {
  353. switch (fcntl) {
  354. case MC_CMD_FCNTL_AUTO:
  355. WARN_ON(1); /* This is not a link mode */
  356. link_state->fc = EFX_FC_AUTO | EFX_FC_TX | EFX_FC_RX;
  357. break;
  358. case MC_CMD_FCNTL_BIDIR:
  359. link_state->fc = EFX_FC_TX | EFX_FC_RX;
  360. break;
  361. case MC_CMD_FCNTL_RESPOND:
  362. link_state->fc = EFX_FC_RX;
  363. break;
  364. default:
  365. WARN_ON(1);
  366. case MC_CMD_FCNTL_OFF:
  367. link_state->fc = 0;
  368. break;
  369. }
  370. link_state->up = !!(flags & (1 << MC_CMD_GET_LINK_LINK_UP_LBN));
  371. link_state->fd = !!(flags & (1 << MC_CMD_GET_LINK_FULL_DUPLEX_LBN));
  372. link_state->speed = speed;
  373. }
  374. /* Verify that the forced flow control settings (!EFX_FC_AUTO) are
  375. * supported by the link partner. Warn the user if this isn't the case
  376. */
  377. void efx_mcdi_phy_check_fcntl(struct efx_nic *efx, u32 lpa)
  378. {
  379. struct efx_mcdi_phy_cfg *phy_cfg = efx->phy_data;
  380. u32 rmtadv;
  381. /* The link partner capabilities are only relevent if the
  382. * link supports flow control autonegotiation */
  383. if (~phy_cfg->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
  384. return;
  385. /* If flow control autoneg is supported and enabled, then fine */
  386. if (efx->wanted_fc & EFX_FC_AUTO)
  387. return;
  388. rmtadv = 0;
  389. if (lpa & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
  390. rmtadv |= ADVERTISED_Pause;
  391. if (lpa & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
  392. rmtadv |= ADVERTISED_Asym_Pause;
  393. if ((efx->wanted_fc & EFX_FC_TX) && rmtadv == ADVERTISED_Asym_Pause)
  394. EFX_ERR(efx, "warning: link partner doesn't support "
  395. "pause frames");
  396. }
  397. static bool efx_mcdi_phy_poll(struct efx_nic *efx)
  398. {
  399. struct efx_link_state old_state = efx->link_state;
  400. u8 outbuf[MC_CMD_GET_LINK_OUT_LEN];
  401. int rc;
  402. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  403. BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
  404. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
  405. outbuf, sizeof(outbuf), NULL);
  406. if (rc) {
  407. EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc);
  408. efx->link_state.up = false;
  409. } else {
  410. efx_mcdi_phy_decode_link(
  411. efx, &efx->link_state,
  412. MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED),
  413. MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS),
  414. MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL));
  415. }
  416. return !efx_link_state_equal(&efx->link_state, &old_state);
  417. }
  418. static void efx_mcdi_phy_remove(struct efx_nic *efx)
  419. {
  420. struct efx_mcdi_phy_data *phy_data = efx->phy_data;
  421. efx->phy_data = NULL;
  422. kfree(phy_data);
  423. }
  424. static void efx_mcdi_phy_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  425. {
  426. struct efx_mcdi_phy_cfg *phy_cfg = efx->phy_data;
  427. u8 outbuf[MC_CMD_GET_LINK_OUT_LEN];
  428. int rc;
  429. ecmd->supported =
  430. mcdi_to_ethtool_cap(phy_cfg->media, phy_cfg->supported_cap);
  431. ecmd->advertising = efx->link_advertising;
  432. ecmd->speed = efx->link_state.speed;
  433. ecmd->duplex = efx->link_state.fd;
  434. ecmd->port = mcdi_to_ethtool_media(phy_cfg->media);
  435. ecmd->phy_address = phy_cfg->port;
  436. ecmd->transceiver = XCVR_INTERNAL;
  437. ecmd->autoneg = !!(efx->link_advertising & ADVERTISED_Autoneg);
  438. ecmd->mdio_support = (efx->mdio.mode_support &
  439. (MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22));
  440. BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
  441. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
  442. outbuf, sizeof(outbuf), NULL);
  443. if (rc) {
  444. EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc);
  445. return;
  446. }
  447. ecmd->lp_advertising =
  448. mcdi_to_ethtool_cap(phy_cfg->media,
  449. MCDI_DWORD(outbuf, GET_LINK_OUT_LP_CAP));
  450. }
  451. static int efx_mcdi_phy_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  452. {
  453. struct efx_mcdi_phy_cfg *phy_cfg = efx->phy_data;
  454. u32 caps;
  455. int rc;
  456. if (ecmd->autoneg) {
  457. caps = (ethtool_to_mcdi_cap(ecmd->advertising) |
  458. 1 << MC_CMD_PHY_CAP_AN_LBN);
  459. } else if (ecmd->duplex) {
  460. switch (ecmd->speed) {
  461. case 10: caps = 1 << MC_CMD_PHY_CAP_10FDX_LBN; break;
  462. case 100: caps = 1 << MC_CMD_PHY_CAP_100FDX_LBN; break;
  463. case 1000: caps = 1 << MC_CMD_PHY_CAP_1000FDX_LBN; break;
  464. case 10000: caps = 1 << MC_CMD_PHY_CAP_10000FDX_LBN; break;
  465. default: return -EINVAL;
  466. }
  467. } else {
  468. switch (ecmd->speed) {
  469. case 10: caps = 1 << MC_CMD_PHY_CAP_10HDX_LBN; break;
  470. case 100: caps = 1 << MC_CMD_PHY_CAP_100HDX_LBN; break;
  471. case 1000: caps = 1 << MC_CMD_PHY_CAP_1000HDX_LBN; break;
  472. default: return -EINVAL;
  473. }
  474. }
  475. rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
  476. efx->loopback_mode, 0);
  477. if (rc)
  478. return rc;
  479. if (ecmd->autoneg) {
  480. efx_link_set_advertising(
  481. efx, ecmd->advertising | ADVERTISED_Autoneg);
  482. phy_cfg->forced_cap = 0;
  483. } else {
  484. efx_link_set_advertising(efx, 0);
  485. phy_cfg->forced_cap = caps;
  486. }
  487. return 0;
  488. }
  489. static int efx_mcdi_phy_test_alive(struct efx_nic *efx)
  490. {
  491. u8 outbuf[MC_CMD_GET_PHY_STATE_OUT_LEN];
  492. size_t outlen;
  493. int rc;
  494. BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN != 0);
  495. rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_STATE, NULL, 0,
  496. outbuf, sizeof(outbuf), &outlen);
  497. if (rc)
  498. return rc;
  499. if (outlen < MC_CMD_GET_PHY_STATE_OUT_LEN)
  500. return -EIO;
  501. if (MCDI_DWORD(outbuf, GET_PHY_STATE_STATE) != MC_CMD_PHY_STATE_OK)
  502. return -EINVAL;
  503. return 0;
  504. }
  505. struct efx_phy_operations efx_mcdi_phy_ops = {
  506. .probe = efx_mcdi_phy_probe,
  507. .init = efx_port_dummy_op_int,
  508. .reconfigure = efx_mcdi_phy_reconfigure,
  509. .poll = efx_mcdi_phy_poll,
  510. .fini = efx_port_dummy_op_void,
  511. .remove = efx_mcdi_phy_remove,
  512. .get_settings = efx_mcdi_phy_get_settings,
  513. .set_settings = efx_mcdi_phy_set_settings,
  514. .test_alive = efx_mcdi_phy_test_alive,
  515. .run_tests = NULL,
  516. .test_name = NULL,
  517. };