mcdi_port.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2009-2010 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 "nic.h"
  18. #include "selftest.h"
  19. struct efx_mcdi_phy_data {
  20. u32 flags;
  21. u32 type;
  22. u32 supported_cap;
  23. u32 channel;
  24. u32 port;
  25. u32 stats_mask;
  26. u8 name[20];
  27. u32 media;
  28. u32 mmd_mask;
  29. u8 revision[20];
  30. u32 forced_cap;
  31. };
  32. static int
  33. efx_mcdi_get_phy_cfg(struct efx_nic *efx, struct efx_mcdi_phy_data *cfg)
  34. {
  35. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_CFG_OUT_LEN);
  36. size_t outlen;
  37. int rc;
  38. BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_IN_LEN != 0);
  39. BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_OUT_NAME_LEN != sizeof(cfg->name));
  40. rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_CFG, NULL, 0,
  41. outbuf, sizeof(outbuf), &outlen);
  42. if (rc)
  43. goto fail;
  44. if (outlen < MC_CMD_GET_PHY_CFG_OUT_LEN) {
  45. rc = -EIO;
  46. goto fail;
  47. }
  48. cfg->flags = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_FLAGS);
  49. cfg->type = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_TYPE);
  50. cfg->supported_cap =
  51. MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_SUPPORTED_CAP);
  52. cfg->channel = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_CHANNEL);
  53. cfg->port = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_PRT);
  54. cfg->stats_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_STATS_MASK);
  55. memcpy(cfg->name, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_NAME),
  56. sizeof(cfg->name));
  57. cfg->media = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MEDIA_TYPE);
  58. cfg->mmd_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MMD_MASK);
  59. memcpy(cfg->revision, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_REVISION),
  60. sizeof(cfg->revision));
  61. return 0;
  62. fail:
  63. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  64. return rc;
  65. }
  66. static int efx_mcdi_set_link(struct efx_nic *efx, u32 capabilities,
  67. u32 flags, u32 loopback_mode,
  68. u32 loopback_speed)
  69. {
  70. MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_LINK_IN_LEN);
  71. int rc;
  72. BUILD_BUG_ON(MC_CMD_SET_LINK_OUT_LEN != 0);
  73. MCDI_SET_DWORD(inbuf, SET_LINK_IN_CAP, capabilities);
  74. MCDI_SET_DWORD(inbuf, SET_LINK_IN_FLAGS, flags);
  75. MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_MODE, loopback_mode);
  76. MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_SPEED, loopback_speed);
  77. rc = efx_mcdi_rpc(efx, MC_CMD_SET_LINK, inbuf, sizeof(inbuf),
  78. NULL, 0, NULL);
  79. if (rc)
  80. goto fail;
  81. return 0;
  82. fail:
  83. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  84. return rc;
  85. }
  86. static int efx_mcdi_loopback_modes(struct efx_nic *efx, u64 *loopback_modes)
  87. {
  88. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LOOPBACK_MODES_OUT_LEN);
  89. size_t outlen;
  90. int rc;
  91. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LOOPBACK_MODES, NULL, 0,
  92. outbuf, sizeof(outbuf), &outlen);
  93. if (rc)
  94. goto fail;
  95. if (outlen < (MC_CMD_GET_LOOPBACK_MODES_OUT_SUGGESTED_OFST +
  96. MC_CMD_GET_LOOPBACK_MODES_OUT_SUGGESTED_LEN)) {
  97. rc = -EIO;
  98. goto fail;
  99. }
  100. *loopback_modes = MCDI_QWORD(outbuf, GET_LOOPBACK_MODES_OUT_SUGGESTED);
  101. return 0;
  102. fail:
  103. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  104. return rc;
  105. }
  106. static int efx_mcdi_mdio_read(struct net_device *net_dev,
  107. int prtad, int devad, u16 addr)
  108. {
  109. struct efx_nic *efx = netdev_priv(net_dev);
  110. MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_READ_IN_LEN);
  111. MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_READ_OUT_LEN);
  112. size_t outlen;
  113. int rc;
  114. MCDI_SET_DWORD(inbuf, MDIO_READ_IN_BUS, efx->mdio_bus);
  115. MCDI_SET_DWORD(inbuf, MDIO_READ_IN_PRTAD, prtad);
  116. MCDI_SET_DWORD(inbuf, MDIO_READ_IN_DEVAD, devad);
  117. MCDI_SET_DWORD(inbuf, MDIO_READ_IN_ADDR, addr);
  118. rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_READ, inbuf, sizeof(inbuf),
  119. outbuf, sizeof(outbuf), &outlen);
  120. if (rc)
  121. goto fail;
  122. if (MCDI_DWORD(outbuf, MDIO_READ_OUT_STATUS) !=
  123. MC_CMD_MDIO_STATUS_GOOD)
  124. return -EIO;
  125. return (u16)MCDI_DWORD(outbuf, MDIO_READ_OUT_VALUE);
  126. fail:
  127. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  128. return rc;
  129. }
  130. static int efx_mcdi_mdio_write(struct net_device *net_dev,
  131. int prtad, int devad, u16 addr, u16 value)
  132. {
  133. struct efx_nic *efx = netdev_priv(net_dev);
  134. MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_WRITE_IN_LEN);
  135. MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_WRITE_OUT_LEN);
  136. size_t outlen;
  137. int rc;
  138. MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_BUS, efx->mdio_bus);
  139. MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_PRTAD, prtad);
  140. MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_DEVAD, devad);
  141. MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_ADDR, addr);
  142. MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_VALUE, value);
  143. rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_WRITE, inbuf, sizeof(inbuf),
  144. outbuf, sizeof(outbuf), &outlen);
  145. if (rc)
  146. goto fail;
  147. if (MCDI_DWORD(outbuf, MDIO_WRITE_OUT_STATUS) !=
  148. MC_CMD_MDIO_STATUS_GOOD)
  149. return -EIO;
  150. return 0;
  151. fail:
  152. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  153. return rc;
  154. }
  155. static u32 mcdi_to_ethtool_cap(u32 media, u32 cap)
  156. {
  157. u32 result = 0;
  158. switch (media) {
  159. case MC_CMD_MEDIA_KX4:
  160. result |= SUPPORTED_Backplane;
  161. if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
  162. result |= SUPPORTED_1000baseKX_Full;
  163. if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
  164. result |= SUPPORTED_10000baseKX4_Full;
  165. break;
  166. case MC_CMD_MEDIA_XFP:
  167. case MC_CMD_MEDIA_SFP_PLUS:
  168. result |= SUPPORTED_FIBRE;
  169. break;
  170. case MC_CMD_MEDIA_BASE_T:
  171. result |= SUPPORTED_TP;
  172. if (cap & (1 << MC_CMD_PHY_CAP_10HDX_LBN))
  173. result |= SUPPORTED_10baseT_Half;
  174. if (cap & (1 << MC_CMD_PHY_CAP_10FDX_LBN))
  175. result |= SUPPORTED_10baseT_Full;
  176. if (cap & (1 << MC_CMD_PHY_CAP_100HDX_LBN))
  177. result |= SUPPORTED_100baseT_Half;
  178. if (cap & (1 << MC_CMD_PHY_CAP_100FDX_LBN))
  179. result |= SUPPORTED_100baseT_Full;
  180. if (cap & (1 << MC_CMD_PHY_CAP_1000HDX_LBN))
  181. result |= SUPPORTED_1000baseT_Half;
  182. if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
  183. result |= SUPPORTED_1000baseT_Full;
  184. if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
  185. result |= SUPPORTED_10000baseT_Full;
  186. break;
  187. }
  188. if (cap & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
  189. result |= SUPPORTED_Pause;
  190. if (cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
  191. result |= SUPPORTED_Asym_Pause;
  192. if (cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
  193. result |= SUPPORTED_Autoneg;
  194. return result;
  195. }
  196. static u32 ethtool_to_mcdi_cap(u32 cap)
  197. {
  198. u32 result = 0;
  199. if (cap & SUPPORTED_10baseT_Half)
  200. result |= (1 << MC_CMD_PHY_CAP_10HDX_LBN);
  201. if (cap & SUPPORTED_10baseT_Full)
  202. result |= (1 << MC_CMD_PHY_CAP_10FDX_LBN);
  203. if (cap & SUPPORTED_100baseT_Half)
  204. result |= (1 << MC_CMD_PHY_CAP_100HDX_LBN);
  205. if (cap & SUPPORTED_100baseT_Full)
  206. result |= (1 << MC_CMD_PHY_CAP_100FDX_LBN);
  207. if (cap & SUPPORTED_1000baseT_Half)
  208. result |= (1 << MC_CMD_PHY_CAP_1000HDX_LBN);
  209. if (cap & (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseKX_Full))
  210. result |= (1 << MC_CMD_PHY_CAP_1000FDX_LBN);
  211. if (cap & (SUPPORTED_10000baseT_Full | SUPPORTED_10000baseKX4_Full))
  212. result |= (1 << MC_CMD_PHY_CAP_10000FDX_LBN);
  213. if (cap & SUPPORTED_Pause)
  214. result |= (1 << MC_CMD_PHY_CAP_PAUSE_LBN);
  215. if (cap & SUPPORTED_Asym_Pause)
  216. result |= (1 << MC_CMD_PHY_CAP_ASYM_LBN);
  217. if (cap & SUPPORTED_Autoneg)
  218. result |= (1 << MC_CMD_PHY_CAP_AN_LBN);
  219. return result;
  220. }
  221. static u32 efx_get_mcdi_phy_flags(struct efx_nic *efx)
  222. {
  223. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  224. enum efx_phy_mode mode, supported;
  225. u32 flags;
  226. /* TODO: Advertise the capabilities supported by this PHY */
  227. supported = 0;
  228. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_TXDIS_LBN))
  229. supported |= PHY_MODE_TX_DISABLED;
  230. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_LOWPOWER_LBN))
  231. supported |= PHY_MODE_LOW_POWER;
  232. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_POWEROFF_LBN))
  233. supported |= PHY_MODE_OFF;
  234. mode = efx->phy_mode & supported;
  235. flags = 0;
  236. if (mode & PHY_MODE_TX_DISABLED)
  237. flags |= (1 << MC_CMD_SET_LINK_IN_TXDIS_LBN);
  238. if (mode & PHY_MODE_LOW_POWER)
  239. flags |= (1 << MC_CMD_SET_LINK_IN_LOWPOWER_LBN);
  240. if (mode & PHY_MODE_OFF)
  241. flags |= (1 << MC_CMD_SET_LINK_IN_POWEROFF_LBN);
  242. return flags;
  243. }
  244. static u32 mcdi_to_ethtool_media(u32 media)
  245. {
  246. switch (media) {
  247. case MC_CMD_MEDIA_XAUI:
  248. case MC_CMD_MEDIA_CX4:
  249. case MC_CMD_MEDIA_KX4:
  250. return PORT_OTHER;
  251. case MC_CMD_MEDIA_XFP:
  252. case MC_CMD_MEDIA_SFP_PLUS:
  253. return PORT_FIBRE;
  254. case MC_CMD_MEDIA_BASE_T:
  255. return PORT_TP;
  256. default:
  257. return PORT_OTHER;
  258. }
  259. }
  260. static void efx_mcdi_phy_decode_link(struct efx_nic *efx,
  261. struct efx_link_state *link_state,
  262. u32 speed, u32 flags, u32 fcntl)
  263. {
  264. switch (fcntl) {
  265. case MC_CMD_FCNTL_AUTO:
  266. WARN_ON(1); /* This is not a link mode */
  267. link_state->fc = EFX_FC_AUTO | EFX_FC_TX | EFX_FC_RX;
  268. break;
  269. case MC_CMD_FCNTL_BIDIR:
  270. link_state->fc = EFX_FC_TX | EFX_FC_RX;
  271. break;
  272. case MC_CMD_FCNTL_RESPOND:
  273. link_state->fc = EFX_FC_RX;
  274. break;
  275. default:
  276. WARN_ON(1);
  277. case MC_CMD_FCNTL_OFF:
  278. link_state->fc = 0;
  279. break;
  280. }
  281. link_state->up = !!(flags & (1 << MC_CMD_GET_LINK_OUT_LINK_UP_LBN));
  282. link_state->fd = !!(flags & (1 << MC_CMD_GET_LINK_OUT_FULL_DUPLEX_LBN));
  283. link_state->speed = speed;
  284. }
  285. static int efx_mcdi_phy_probe(struct efx_nic *efx)
  286. {
  287. struct efx_mcdi_phy_data *phy_data;
  288. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
  289. u32 caps;
  290. int rc;
  291. /* Initialise and populate phy_data */
  292. phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
  293. if (phy_data == NULL)
  294. return -ENOMEM;
  295. rc = efx_mcdi_get_phy_cfg(efx, phy_data);
  296. if (rc != 0)
  297. goto fail;
  298. /* Read initial link advertisement */
  299. BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
  300. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
  301. outbuf, sizeof(outbuf), NULL);
  302. if (rc)
  303. goto fail;
  304. /* Fill out nic state */
  305. efx->phy_data = phy_data;
  306. efx->phy_type = phy_data->type;
  307. efx->mdio_bus = phy_data->channel;
  308. efx->mdio.prtad = phy_data->port;
  309. efx->mdio.mmds = phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22);
  310. efx->mdio.mode_support = 0;
  311. if (phy_data->mmd_mask & (1 << MC_CMD_MMD_CLAUSE22))
  312. efx->mdio.mode_support |= MDIO_SUPPORTS_C22;
  313. if (phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22))
  314. efx->mdio.mode_support |= MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  315. caps = MCDI_DWORD(outbuf, GET_LINK_OUT_CAP);
  316. if (caps & (1 << MC_CMD_PHY_CAP_AN_LBN))
  317. efx->link_advertising =
  318. mcdi_to_ethtool_cap(phy_data->media, caps);
  319. else
  320. phy_data->forced_cap = caps;
  321. /* Assert that we can map efx -> mcdi loopback modes */
  322. BUILD_BUG_ON(LOOPBACK_NONE != MC_CMD_LOOPBACK_NONE);
  323. BUILD_BUG_ON(LOOPBACK_DATA != MC_CMD_LOOPBACK_DATA);
  324. BUILD_BUG_ON(LOOPBACK_GMAC != MC_CMD_LOOPBACK_GMAC);
  325. BUILD_BUG_ON(LOOPBACK_XGMII != MC_CMD_LOOPBACK_XGMII);
  326. BUILD_BUG_ON(LOOPBACK_XGXS != MC_CMD_LOOPBACK_XGXS);
  327. BUILD_BUG_ON(LOOPBACK_XAUI != MC_CMD_LOOPBACK_XAUI);
  328. BUILD_BUG_ON(LOOPBACK_GMII != MC_CMD_LOOPBACK_GMII);
  329. BUILD_BUG_ON(LOOPBACK_SGMII != MC_CMD_LOOPBACK_SGMII);
  330. BUILD_BUG_ON(LOOPBACK_XGBR != MC_CMD_LOOPBACK_XGBR);
  331. BUILD_BUG_ON(LOOPBACK_XFI != MC_CMD_LOOPBACK_XFI);
  332. BUILD_BUG_ON(LOOPBACK_XAUI_FAR != MC_CMD_LOOPBACK_XAUI_FAR);
  333. BUILD_BUG_ON(LOOPBACK_GMII_FAR != MC_CMD_LOOPBACK_GMII_FAR);
  334. BUILD_BUG_ON(LOOPBACK_SGMII_FAR != MC_CMD_LOOPBACK_SGMII_FAR);
  335. BUILD_BUG_ON(LOOPBACK_XFI_FAR != MC_CMD_LOOPBACK_XFI_FAR);
  336. BUILD_BUG_ON(LOOPBACK_GPHY != MC_CMD_LOOPBACK_GPHY);
  337. BUILD_BUG_ON(LOOPBACK_PHYXS != MC_CMD_LOOPBACK_PHYXS);
  338. BUILD_BUG_ON(LOOPBACK_PCS != MC_CMD_LOOPBACK_PCS);
  339. BUILD_BUG_ON(LOOPBACK_PMAPMD != MC_CMD_LOOPBACK_PMAPMD);
  340. BUILD_BUG_ON(LOOPBACK_XPORT != MC_CMD_LOOPBACK_XPORT);
  341. BUILD_BUG_ON(LOOPBACK_XGMII_WS != MC_CMD_LOOPBACK_XGMII_WS);
  342. BUILD_BUG_ON(LOOPBACK_XAUI_WS != MC_CMD_LOOPBACK_XAUI_WS);
  343. BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR != MC_CMD_LOOPBACK_XAUI_WS_FAR);
  344. BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR != MC_CMD_LOOPBACK_XAUI_WS_NEAR);
  345. BUILD_BUG_ON(LOOPBACK_GMII_WS != MC_CMD_LOOPBACK_GMII_WS);
  346. BUILD_BUG_ON(LOOPBACK_XFI_WS != MC_CMD_LOOPBACK_XFI_WS);
  347. BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR != MC_CMD_LOOPBACK_XFI_WS_FAR);
  348. BUILD_BUG_ON(LOOPBACK_PHYXS_WS != MC_CMD_LOOPBACK_PHYXS_WS);
  349. rc = efx_mcdi_loopback_modes(efx, &efx->loopback_modes);
  350. if (rc != 0)
  351. goto fail;
  352. /* The MC indicates that LOOPBACK_NONE is a valid loopback mode,
  353. * but by convention we don't */
  354. efx->loopback_modes &= ~(1 << LOOPBACK_NONE);
  355. /* Set the initial link mode */
  356. efx_mcdi_phy_decode_link(
  357. efx, &efx->link_state,
  358. MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED),
  359. MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS),
  360. MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL));
  361. /* Default to Autonegotiated flow control if the PHY supports it */
  362. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  363. if (phy_data->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
  364. efx->wanted_fc |= EFX_FC_AUTO;
  365. efx_link_set_wanted_fc(efx, efx->wanted_fc);
  366. return 0;
  367. fail:
  368. kfree(phy_data);
  369. return rc;
  370. }
  371. int efx_mcdi_port_reconfigure(struct efx_nic *efx)
  372. {
  373. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  374. u32 caps = (efx->link_advertising ?
  375. ethtool_to_mcdi_cap(efx->link_advertising) :
  376. phy_cfg->forced_cap);
  377. return efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
  378. efx->loopback_mode, 0);
  379. }
  380. /* Verify that the forced flow control settings (!EFX_FC_AUTO) are
  381. * supported by the link partner. Warn the user if this isn't the case
  382. */
  383. static void efx_mcdi_phy_check_fcntl(struct efx_nic *efx, u32 lpa)
  384. {
  385. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  386. u32 rmtadv;
  387. /* The link partner capabilities are only relevant if the
  388. * link supports flow control autonegotiation */
  389. if (~phy_cfg->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
  390. return;
  391. /* If flow control autoneg is supported and enabled, then fine */
  392. if (efx->wanted_fc & EFX_FC_AUTO)
  393. return;
  394. rmtadv = 0;
  395. if (lpa & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
  396. rmtadv |= ADVERTISED_Pause;
  397. if (lpa & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
  398. rmtadv |= ADVERTISED_Asym_Pause;
  399. if ((efx->wanted_fc & EFX_FC_TX) && rmtadv == ADVERTISED_Asym_Pause)
  400. netif_err(efx, link, efx->net_dev,
  401. "warning: link partner doesn't support pause frames");
  402. }
  403. static bool efx_mcdi_phy_poll(struct efx_nic *efx)
  404. {
  405. struct efx_link_state old_state = efx->link_state;
  406. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
  407. int rc;
  408. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  409. BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
  410. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
  411. outbuf, sizeof(outbuf), NULL);
  412. if (rc) {
  413. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  414. __func__, rc);
  415. efx->link_state.up = false;
  416. } else {
  417. efx_mcdi_phy_decode_link(
  418. efx, &efx->link_state,
  419. MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED),
  420. MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS),
  421. MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL));
  422. }
  423. return !efx_link_state_equal(&efx->link_state, &old_state);
  424. }
  425. static void efx_mcdi_phy_remove(struct efx_nic *efx)
  426. {
  427. struct efx_mcdi_phy_data *phy_data = efx->phy_data;
  428. efx->phy_data = NULL;
  429. kfree(phy_data);
  430. }
  431. static void efx_mcdi_phy_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  432. {
  433. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  434. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
  435. int rc;
  436. ecmd->supported =
  437. mcdi_to_ethtool_cap(phy_cfg->media, phy_cfg->supported_cap);
  438. ecmd->advertising = efx->link_advertising;
  439. ethtool_cmd_speed_set(ecmd, efx->link_state.speed);
  440. ecmd->duplex = efx->link_state.fd;
  441. ecmd->port = mcdi_to_ethtool_media(phy_cfg->media);
  442. ecmd->phy_address = phy_cfg->port;
  443. ecmd->transceiver = XCVR_INTERNAL;
  444. ecmd->autoneg = !!(efx->link_advertising & ADVERTISED_Autoneg);
  445. ecmd->mdio_support = (efx->mdio.mode_support &
  446. (MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22));
  447. BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
  448. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
  449. outbuf, sizeof(outbuf), NULL);
  450. if (rc) {
  451. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  452. __func__, rc);
  453. return;
  454. }
  455. ecmd->lp_advertising =
  456. mcdi_to_ethtool_cap(phy_cfg->media,
  457. MCDI_DWORD(outbuf, GET_LINK_OUT_LP_CAP));
  458. }
  459. static int efx_mcdi_phy_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
  460. {
  461. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  462. u32 caps;
  463. int rc;
  464. if (ecmd->autoneg) {
  465. caps = (ethtool_to_mcdi_cap(ecmd->advertising) |
  466. 1 << MC_CMD_PHY_CAP_AN_LBN);
  467. } else if (ecmd->duplex) {
  468. switch (ethtool_cmd_speed(ecmd)) {
  469. case 10: caps = 1 << MC_CMD_PHY_CAP_10FDX_LBN; break;
  470. case 100: caps = 1 << MC_CMD_PHY_CAP_100FDX_LBN; break;
  471. case 1000: caps = 1 << MC_CMD_PHY_CAP_1000FDX_LBN; break;
  472. case 10000: caps = 1 << MC_CMD_PHY_CAP_10000FDX_LBN; break;
  473. default: return -EINVAL;
  474. }
  475. } else {
  476. switch (ethtool_cmd_speed(ecmd)) {
  477. case 10: caps = 1 << MC_CMD_PHY_CAP_10HDX_LBN; break;
  478. case 100: caps = 1 << MC_CMD_PHY_CAP_100HDX_LBN; break;
  479. case 1000: caps = 1 << MC_CMD_PHY_CAP_1000HDX_LBN; break;
  480. default: return -EINVAL;
  481. }
  482. }
  483. rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
  484. efx->loopback_mode, 0);
  485. if (rc)
  486. return rc;
  487. if (ecmd->autoneg) {
  488. efx_link_set_advertising(
  489. efx, ecmd->advertising | ADVERTISED_Autoneg);
  490. phy_cfg->forced_cap = 0;
  491. } else {
  492. efx_link_set_advertising(efx, 0);
  493. phy_cfg->forced_cap = caps;
  494. }
  495. return 0;
  496. }
  497. static int efx_mcdi_phy_test_alive(struct efx_nic *efx)
  498. {
  499. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_STATE_OUT_LEN);
  500. size_t outlen;
  501. int rc;
  502. BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN != 0);
  503. rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_STATE, NULL, 0,
  504. outbuf, sizeof(outbuf), &outlen);
  505. if (rc)
  506. return rc;
  507. if (outlen < MC_CMD_GET_PHY_STATE_OUT_LEN)
  508. return -EIO;
  509. if (MCDI_DWORD(outbuf, GET_PHY_STATE_OUT_STATE) != MC_CMD_PHY_STATE_OK)
  510. return -EINVAL;
  511. return 0;
  512. }
  513. static const char *const mcdi_sft9001_cable_diag_names[] = {
  514. "cable.pairA.length",
  515. "cable.pairB.length",
  516. "cable.pairC.length",
  517. "cable.pairD.length",
  518. "cable.pairA.status",
  519. "cable.pairB.status",
  520. "cable.pairC.status",
  521. "cable.pairD.status",
  522. };
  523. static int efx_mcdi_bist(struct efx_nic *efx, unsigned int bist_mode,
  524. int *results)
  525. {
  526. unsigned int retry, i, count = 0;
  527. size_t outlen;
  528. u32 status;
  529. MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
  530. MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_SFT9001_LEN);
  531. u8 *ptr;
  532. int rc;
  533. BUILD_BUG_ON(MC_CMD_START_BIST_OUT_LEN != 0);
  534. MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_mode);
  535. rc = efx_mcdi_rpc(efx, MC_CMD_START_BIST,
  536. inbuf, MC_CMD_START_BIST_IN_LEN, NULL, 0, NULL);
  537. if (rc)
  538. goto out;
  539. /* Wait up to 10s for BIST to finish */
  540. for (retry = 0; retry < 100; ++retry) {
  541. BUILD_BUG_ON(MC_CMD_POLL_BIST_IN_LEN != 0);
  542. rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
  543. outbuf, sizeof(outbuf), &outlen);
  544. if (rc)
  545. goto out;
  546. status = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
  547. if (status != MC_CMD_POLL_BIST_RUNNING)
  548. goto finished;
  549. msleep(100);
  550. }
  551. rc = -ETIMEDOUT;
  552. goto out;
  553. finished:
  554. results[count++] = (status == MC_CMD_POLL_BIST_PASSED) ? 1 : -1;
  555. /* SFT9001 specific cable diagnostics output */
  556. if (efx->phy_type == PHY_TYPE_SFT9001B &&
  557. (bist_mode == MC_CMD_PHY_BIST_CABLE_SHORT ||
  558. bist_mode == MC_CMD_PHY_BIST_CABLE_LONG)) {
  559. ptr = MCDI_PTR(outbuf, POLL_BIST_OUT_SFT9001_CABLE_LENGTH_A);
  560. if (status == MC_CMD_POLL_BIST_PASSED &&
  561. outlen >= MC_CMD_POLL_BIST_OUT_SFT9001_LEN) {
  562. for (i = 0; i < 8; i++) {
  563. results[count + i] =
  564. EFX_DWORD_FIELD(((efx_dword_t *)ptr)[i],
  565. EFX_DWORD_0);
  566. }
  567. }
  568. count += 8;
  569. }
  570. rc = count;
  571. out:
  572. return rc;
  573. }
  574. static int efx_mcdi_phy_run_tests(struct efx_nic *efx, int *results,
  575. unsigned flags)
  576. {
  577. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  578. u32 mode;
  579. int rc;
  580. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN)) {
  581. rc = efx_mcdi_bist(efx, MC_CMD_PHY_BIST, results);
  582. if (rc < 0)
  583. return rc;
  584. results += rc;
  585. }
  586. /* If we support both LONG and SHORT, then run each in response to
  587. * break or not. Otherwise, run the one we support */
  588. mode = 0;
  589. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN)) {
  590. if ((flags & ETH_TEST_FL_OFFLINE) &&
  591. (phy_cfg->flags &
  592. (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN)))
  593. mode = MC_CMD_PHY_BIST_CABLE_LONG;
  594. else
  595. mode = MC_CMD_PHY_BIST_CABLE_SHORT;
  596. } else if (phy_cfg->flags &
  597. (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))
  598. mode = MC_CMD_PHY_BIST_CABLE_LONG;
  599. if (mode != 0) {
  600. rc = efx_mcdi_bist(efx, mode, results);
  601. if (rc < 0)
  602. return rc;
  603. results += rc;
  604. }
  605. return 0;
  606. }
  607. static const char *efx_mcdi_phy_test_name(struct efx_nic *efx,
  608. unsigned int index)
  609. {
  610. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  611. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN)) {
  612. if (index == 0)
  613. return "bist";
  614. --index;
  615. }
  616. if (phy_cfg->flags & ((1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN) |
  617. (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))) {
  618. if (index == 0)
  619. return "cable";
  620. --index;
  621. if (efx->phy_type == PHY_TYPE_SFT9001B) {
  622. if (index < ARRAY_SIZE(mcdi_sft9001_cable_diag_names))
  623. return mcdi_sft9001_cable_diag_names[index];
  624. index -= ARRAY_SIZE(mcdi_sft9001_cable_diag_names);
  625. }
  626. }
  627. return NULL;
  628. }
  629. #define SFP_PAGE_SIZE 128
  630. #define SFP_NUM_PAGES 2
  631. static int efx_mcdi_phy_get_module_eeprom(struct efx_nic *efx,
  632. struct ethtool_eeprom *ee, u8 *data)
  633. {
  634. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMAX);
  635. MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN);
  636. size_t outlen;
  637. int rc;
  638. unsigned int payload_len;
  639. unsigned int space_remaining = ee->len;
  640. unsigned int page;
  641. unsigned int page_off;
  642. unsigned int to_copy;
  643. u8 *user_data = data;
  644. BUILD_BUG_ON(SFP_PAGE_SIZE * SFP_NUM_PAGES != ETH_MODULE_SFF_8079_LEN);
  645. page_off = ee->offset % SFP_PAGE_SIZE;
  646. page = ee->offset / SFP_PAGE_SIZE;
  647. while (space_remaining && (page < SFP_NUM_PAGES)) {
  648. MCDI_SET_DWORD(inbuf, GET_PHY_MEDIA_INFO_IN_PAGE, page);
  649. rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_MEDIA_INFO,
  650. inbuf, sizeof(inbuf),
  651. outbuf, sizeof(outbuf),
  652. &outlen);
  653. if (rc)
  654. return rc;
  655. if (outlen < (MC_CMD_GET_PHY_MEDIA_INFO_OUT_DATA_OFST +
  656. SFP_PAGE_SIZE))
  657. return -EIO;
  658. payload_len = MCDI_DWORD(outbuf,
  659. GET_PHY_MEDIA_INFO_OUT_DATALEN);
  660. if (payload_len != SFP_PAGE_SIZE)
  661. return -EIO;
  662. /* Copy as much as we can into data */
  663. payload_len -= page_off;
  664. to_copy = (space_remaining < payload_len) ?
  665. space_remaining : payload_len;
  666. memcpy(user_data,
  667. MCDI_PTR(outbuf, GET_PHY_MEDIA_INFO_OUT_DATA) + page_off,
  668. to_copy);
  669. space_remaining -= to_copy;
  670. user_data += to_copy;
  671. page_off = 0;
  672. page++;
  673. }
  674. return 0;
  675. }
  676. static int efx_mcdi_phy_get_module_info(struct efx_nic *efx,
  677. struct ethtool_modinfo *modinfo)
  678. {
  679. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  680. switch (phy_cfg->media) {
  681. case MC_CMD_MEDIA_SFP_PLUS:
  682. modinfo->type = ETH_MODULE_SFF_8079;
  683. modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
  684. return 0;
  685. default:
  686. return -EOPNOTSUPP;
  687. }
  688. }
  689. static const struct efx_phy_operations efx_mcdi_phy_ops = {
  690. .probe = efx_mcdi_phy_probe,
  691. .init = efx_port_dummy_op_int,
  692. .reconfigure = efx_mcdi_port_reconfigure,
  693. .poll = efx_mcdi_phy_poll,
  694. .fini = efx_port_dummy_op_void,
  695. .remove = efx_mcdi_phy_remove,
  696. .get_settings = efx_mcdi_phy_get_settings,
  697. .set_settings = efx_mcdi_phy_set_settings,
  698. .test_alive = efx_mcdi_phy_test_alive,
  699. .run_tests = efx_mcdi_phy_run_tests,
  700. .test_name = efx_mcdi_phy_test_name,
  701. .get_module_eeprom = efx_mcdi_phy_get_module_eeprom,
  702. .get_module_info = efx_mcdi_phy_get_module_info,
  703. };
  704. static unsigned int efx_mcdi_event_link_speed[] = {
  705. [MCDI_EVENT_LINKCHANGE_SPEED_100M] = 100,
  706. [MCDI_EVENT_LINKCHANGE_SPEED_1G] = 1000,
  707. [MCDI_EVENT_LINKCHANGE_SPEED_10G] = 10000,
  708. };
  709. void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev)
  710. {
  711. u32 flags, fcntl, speed, lpa;
  712. speed = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_SPEED);
  713. EFX_BUG_ON_PARANOID(speed >= ARRAY_SIZE(efx_mcdi_event_link_speed));
  714. speed = efx_mcdi_event_link_speed[speed];
  715. flags = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LINK_FLAGS);
  716. fcntl = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_FCNTL);
  717. lpa = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LP_CAP);
  718. /* efx->link_state is only modified by efx_mcdi_phy_get_link(),
  719. * which is only run after flushing the event queues. Therefore, it
  720. * is safe to modify the link state outside of the mac_lock here.
  721. */
  722. efx_mcdi_phy_decode_link(efx, &efx->link_state, speed, flags, fcntl);
  723. efx_mcdi_phy_check_fcntl(efx, lpa);
  724. efx_link_status_changed(efx);
  725. }
  726. int efx_mcdi_set_mac(struct efx_nic *efx)
  727. {
  728. u32 fcntl;
  729. MCDI_DECLARE_BUF(cmdbytes, MC_CMD_SET_MAC_IN_LEN);
  730. BUILD_BUG_ON(MC_CMD_SET_MAC_OUT_LEN != 0);
  731. memcpy(MCDI_PTR(cmdbytes, SET_MAC_IN_ADDR),
  732. efx->net_dev->dev_addr, ETH_ALEN);
  733. MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_MTU,
  734. EFX_MAX_FRAME_LEN(efx->net_dev->mtu));
  735. MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_DRAIN, 0);
  736. /* Set simple MAC filter for Siena */
  737. MCDI_POPULATE_DWORD_1(cmdbytes, SET_MAC_IN_REJECT,
  738. SET_MAC_IN_REJECT_UNCST, efx->unicast_filter);
  739. switch (efx->wanted_fc) {
  740. case EFX_FC_RX | EFX_FC_TX:
  741. fcntl = MC_CMD_FCNTL_BIDIR;
  742. break;
  743. case EFX_FC_RX:
  744. fcntl = MC_CMD_FCNTL_RESPOND;
  745. break;
  746. default:
  747. fcntl = MC_CMD_FCNTL_OFF;
  748. break;
  749. }
  750. if (efx->wanted_fc & EFX_FC_AUTO)
  751. fcntl = MC_CMD_FCNTL_AUTO;
  752. if (efx->fc_disable)
  753. fcntl = MC_CMD_FCNTL_OFF;
  754. MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_FCNTL, fcntl);
  755. return efx_mcdi_rpc(efx, MC_CMD_SET_MAC, cmdbytes, sizeof(cmdbytes),
  756. NULL, 0, NULL);
  757. }
  758. bool efx_mcdi_mac_check_fault(struct efx_nic *efx)
  759. {
  760. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
  761. size_t outlength;
  762. int rc;
  763. BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
  764. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
  765. outbuf, sizeof(outbuf), &outlength);
  766. if (rc) {
  767. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  768. __func__, rc);
  769. return true;
  770. }
  771. return MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT) != 0;
  772. }
  773. static int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr,
  774. u32 dma_len, int enable, int clear)
  775. {
  776. MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
  777. int rc;
  778. int period = enable ? 1000 : 0;
  779. BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0);
  780. MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, dma_addr);
  781. MCDI_POPULATE_DWORD_7(inbuf, MAC_STATS_IN_CMD,
  782. MAC_STATS_IN_DMA, !!enable,
  783. MAC_STATS_IN_CLEAR, clear,
  784. MAC_STATS_IN_PERIODIC_CHANGE, 1,
  785. MAC_STATS_IN_PERIODIC_ENABLE, !!enable,
  786. MAC_STATS_IN_PERIODIC_CLEAR, 0,
  787. MAC_STATS_IN_PERIODIC_NOEVENT, 1,
  788. MAC_STATS_IN_PERIOD_MS, period);
  789. MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
  790. rc = efx_mcdi_rpc(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
  791. NULL, 0, NULL);
  792. if (rc)
  793. goto fail;
  794. return 0;
  795. fail:
  796. netif_err(efx, hw, efx->net_dev, "%s: %s failed rc=%d\n",
  797. __func__, enable ? "enable" : "disable", rc);
  798. return rc;
  799. }
  800. void efx_mcdi_mac_start_stats(struct efx_nic *efx)
  801. {
  802. __le64 *dma_stats = efx->stats_buffer.addr;
  803. dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
  804. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr,
  805. MC_CMD_MAC_NSTATS * sizeof(u64), 1, 0);
  806. }
  807. void efx_mcdi_mac_stop_stats(struct efx_nic *efx)
  808. {
  809. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, 0, 0, 0);
  810. }
  811. int efx_mcdi_port_probe(struct efx_nic *efx)
  812. {
  813. int rc;
  814. /* Hook in PHY operations table */
  815. efx->phy_op = &efx_mcdi_phy_ops;
  816. /* Set up MDIO structure for PHY */
  817. efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  818. efx->mdio.mdio_read = efx_mcdi_mdio_read;
  819. efx->mdio.mdio_write = efx_mcdi_mdio_write;
  820. /* Fill out MDIO structure, loopback modes, and initial link state */
  821. rc = efx->phy_op->probe(efx);
  822. if (rc != 0)
  823. return rc;
  824. /* Allocate buffer for stats */
  825. rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
  826. MC_CMD_MAC_NSTATS * sizeof(u64), GFP_KERNEL);
  827. if (rc)
  828. return rc;
  829. netif_dbg(efx, probe, efx->net_dev,
  830. "stats buffer at %llx (virt %p phys %llx)\n",
  831. (u64)efx->stats_buffer.dma_addr,
  832. efx->stats_buffer.addr,
  833. (u64)virt_to_phys(efx->stats_buffer.addr));
  834. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, 0, 0, 1);
  835. return 0;
  836. }
  837. void efx_mcdi_port_remove(struct efx_nic *efx)
  838. {
  839. efx->phy_op->remove(efx);
  840. efx_nic_free_buffer(efx, &efx->stats_buffer);
  841. }