mcdi_port.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  1. /****************************************************************************
  2. * Driver for Solarflare network controllers and boards
  3. * Copyright 2009-2013 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. case 40000: caps = 1 << MC_CMD_PHY_CAP_40000FDX_LBN; break;
  474. default: return -EINVAL;
  475. }
  476. } else {
  477. switch (ethtool_cmd_speed(ecmd)) {
  478. case 10: caps = 1 << MC_CMD_PHY_CAP_10HDX_LBN; break;
  479. case 100: caps = 1 << MC_CMD_PHY_CAP_100HDX_LBN; break;
  480. case 1000: caps = 1 << MC_CMD_PHY_CAP_1000HDX_LBN; break;
  481. default: return -EINVAL;
  482. }
  483. }
  484. rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
  485. efx->loopback_mode, 0);
  486. if (rc)
  487. return rc;
  488. if (ecmd->autoneg) {
  489. efx_link_set_advertising(
  490. efx, ecmd->advertising | ADVERTISED_Autoneg);
  491. phy_cfg->forced_cap = 0;
  492. } else {
  493. efx_link_set_advertising(efx, 0);
  494. phy_cfg->forced_cap = caps;
  495. }
  496. return 0;
  497. }
  498. static int efx_mcdi_phy_test_alive(struct efx_nic *efx)
  499. {
  500. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_STATE_OUT_LEN);
  501. size_t outlen;
  502. int rc;
  503. BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN != 0);
  504. rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_STATE, NULL, 0,
  505. outbuf, sizeof(outbuf), &outlen);
  506. if (rc)
  507. return rc;
  508. if (outlen < MC_CMD_GET_PHY_STATE_OUT_LEN)
  509. return -EIO;
  510. if (MCDI_DWORD(outbuf, GET_PHY_STATE_OUT_STATE) != MC_CMD_PHY_STATE_OK)
  511. return -EINVAL;
  512. return 0;
  513. }
  514. static const char *const mcdi_sft9001_cable_diag_names[] = {
  515. "cable.pairA.length",
  516. "cable.pairB.length",
  517. "cable.pairC.length",
  518. "cable.pairD.length",
  519. "cable.pairA.status",
  520. "cable.pairB.status",
  521. "cable.pairC.status",
  522. "cable.pairD.status",
  523. };
  524. static int efx_mcdi_bist(struct efx_nic *efx, unsigned int bist_mode,
  525. int *results)
  526. {
  527. unsigned int retry, i, count = 0;
  528. size_t outlen;
  529. u32 status;
  530. MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
  531. MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_SFT9001_LEN);
  532. u8 *ptr;
  533. int rc;
  534. BUILD_BUG_ON(MC_CMD_START_BIST_OUT_LEN != 0);
  535. MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_mode);
  536. rc = efx_mcdi_rpc(efx, MC_CMD_START_BIST,
  537. inbuf, MC_CMD_START_BIST_IN_LEN, NULL, 0, NULL);
  538. if (rc)
  539. goto out;
  540. /* Wait up to 10s for BIST to finish */
  541. for (retry = 0; retry < 100; ++retry) {
  542. BUILD_BUG_ON(MC_CMD_POLL_BIST_IN_LEN != 0);
  543. rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
  544. outbuf, sizeof(outbuf), &outlen);
  545. if (rc)
  546. goto out;
  547. status = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
  548. if (status != MC_CMD_POLL_BIST_RUNNING)
  549. goto finished;
  550. msleep(100);
  551. }
  552. rc = -ETIMEDOUT;
  553. goto out;
  554. finished:
  555. results[count++] = (status == MC_CMD_POLL_BIST_PASSED) ? 1 : -1;
  556. /* SFT9001 specific cable diagnostics output */
  557. if (efx->phy_type == PHY_TYPE_SFT9001B &&
  558. (bist_mode == MC_CMD_PHY_BIST_CABLE_SHORT ||
  559. bist_mode == MC_CMD_PHY_BIST_CABLE_LONG)) {
  560. ptr = MCDI_PTR(outbuf, POLL_BIST_OUT_SFT9001_CABLE_LENGTH_A);
  561. if (status == MC_CMD_POLL_BIST_PASSED &&
  562. outlen >= MC_CMD_POLL_BIST_OUT_SFT9001_LEN) {
  563. for (i = 0; i < 8; i++) {
  564. results[count + i] =
  565. EFX_DWORD_FIELD(((efx_dword_t *)ptr)[i],
  566. EFX_DWORD_0);
  567. }
  568. }
  569. count += 8;
  570. }
  571. rc = count;
  572. out:
  573. return rc;
  574. }
  575. static int efx_mcdi_phy_run_tests(struct efx_nic *efx, int *results,
  576. unsigned flags)
  577. {
  578. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  579. u32 mode;
  580. int rc;
  581. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN)) {
  582. rc = efx_mcdi_bist(efx, MC_CMD_PHY_BIST, results);
  583. if (rc < 0)
  584. return rc;
  585. results += rc;
  586. }
  587. /* If we support both LONG and SHORT, then run each in response to
  588. * break or not. Otherwise, run the one we support */
  589. mode = 0;
  590. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN)) {
  591. if ((flags & ETH_TEST_FL_OFFLINE) &&
  592. (phy_cfg->flags &
  593. (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN)))
  594. mode = MC_CMD_PHY_BIST_CABLE_LONG;
  595. else
  596. mode = MC_CMD_PHY_BIST_CABLE_SHORT;
  597. } else if (phy_cfg->flags &
  598. (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))
  599. mode = MC_CMD_PHY_BIST_CABLE_LONG;
  600. if (mode != 0) {
  601. rc = efx_mcdi_bist(efx, mode, results);
  602. if (rc < 0)
  603. return rc;
  604. results += rc;
  605. }
  606. return 0;
  607. }
  608. static const char *efx_mcdi_phy_test_name(struct efx_nic *efx,
  609. unsigned int index)
  610. {
  611. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  612. if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN)) {
  613. if (index == 0)
  614. return "bist";
  615. --index;
  616. }
  617. if (phy_cfg->flags & ((1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN) |
  618. (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))) {
  619. if (index == 0)
  620. return "cable";
  621. --index;
  622. if (efx->phy_type == PHY_TYPE_SFT9001B) {
  623. if (index < ARRAY_SIZE(mcdi_sft9001_cable_diag_names))
  624. return mcdi_sft9001_cable_diag_names[index];
  625. index -= ARRAY_SIZE(mcdi_sft9001_cable_diag_names);
  626. }
  627. }
  628. return NULL;
  629. }
  630. #define SFP_PAGE_SIZE 128
  631. #define SFP_NUM_PAGES 2
  632. static int efx_mcdi_phy_get_module_eeprom(struct efx_nic *efx,
  633. struct ethtool_eeprom *ee, u8 *data)
  634. {
  635. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMAX);
  636. MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN);
  637. size_t outlen;
  638. int rc;
  639. unsigned int payload_len;
  640. unsigned int space_remaining = ee->len;
  641. unsigned int page;
  642. unsigned int page_off;
  643. unsigned int to_copy;
  644. u8 *user_data = data;
  645. BUILD_BUG_ON(SFP_PAGE_SIZE * SFP_NUM_PAGES != ETH_MODULE_SFF_8079_LEN);
  646. page_off = ee->offset % SFP_PAGE_SIZE;
  647. page = ee->offset / SFP_PAGE_SIZE;
  648. while (space_remaining && (page < SFP_NUM_PAGES)) {
  649. MCDI_SET_DWORD(inbuf, GET_PHY_MEDIA_INFO_IN_PAGE, page);
  650. rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_MEDIA_INFO,
  651. inbuf, sizeof(inbuf),
  652. outbuf, sizeof(outbuf),
  653. &outlen);
  654. if (rc)
  655. return rc;
  656. if (outlen < (MC_CMD_GET_PHY_MEDIA_INFO_OUT_DATA_OFST +
  657. SFP_PAGE_SIZE))
  658. return -EIO;
  659. payload_len = MCDI_DWORD(outbuf,
  660. GET_PHY_MEDIA_INFO_OUT_DATALEN);
  661. if (payload_len != SFP_PAGE_SIZE)
  662. return -EIO;
  663. /* Copy as much as we can into data */
  664. payload_len -= page_off;
  665. to_copy = (space_remaining < payload_len) ?
  666. space_remaining : payload_len;
  667. memcpy(user_data,
  668. MCDI_PTR(outbuf, GET_PHY_MEDIA_INFO_OUT_DATA) + page_off,
  669. to_copy);
  670. space_remaining -= to_copy;
  671. user_data += to_copy;
  672. page_off = 0;
  673. page++;
  674. }
  675. return 0;
  676. }
  677. static int efx_mcdi_phy_get_module_info(struct efx_nic *efx,
  678. struct ethtool_modinfo *modinfo)
  679. {
  680. struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
  681. switch (phy_cfg->media) {
  682. case MC_CMD_MEDIA_SFP_PLUS:
  683. modinfo->type = ETH_MODULE_SFF_8079;
  684. modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
  685. return 0;
  686. default:
  687. return -EOPNOTSUPP;
  688. }
  689. }
  690. static const struct efx_phy_operations efx_mcdi_phy_ops = {
  691. .probe = efx_mcdi_phy_probe,
  692. .init = efx_port_dummy_op_int,
  693. .reconfigure = efx_mcdi_port_reconfigure,
  694. .poll = efx_mcdi_phy_poll,
  695. .fini = efx_port_dummy_op_void,
  696. .remove = efx_mcdi_phy_remove,
  697. .get_settings = efx_mcdi_phy_get_settings,
  698. .set_settings = efx_mcdi_phy_set_settings,
  699. .test_alive = efx_mcdi_phy_test_alive,
  700. .run_tests = efx_mcdi_phy_run_tests,
  701. .test_name = efx_mcdi_phy_test_name,
  702. .get_module_eeprom = efx_mcdi_phy_get_module_eeprom,
  703. .get_module_info = efx_mcdi_phy_get_module_info,
  704. };
  705. u32 efx_mcdi_phy_get_caps(struct efx_nic *efx)
  706. {
  707. struct efx_mcdi_phy_data *phy_data = efx->phy_data;
  708. return phy_data->supported_cap;
  709. }
  710. static unsigned int efx_mcdi_event_link_speed[] = {
  711. [MCDI_EVENT_LINKCHANGE_SPEED_100M] = 100,
  712. [MCDI_EVENT_LINKCHANGE_SPEED_1G] = 1000,
  713. [MCDI_EVENT_LINKCHANGE_SPEED_10G] = 10000,
  714. [MCDI_EVENT_LINKCHANGE_SPEED_40G] = 40000,
  715. };
  716. void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev)
  717. {
  718. u32 flags, fcntl, speed, lpa;
  719. speed = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_SPEED);
  720. EFX_BUG_ON_PARANOID(speed >= ARRAY_SIZE(efx_mcdi_event_link_speed));
  721. speed = efx_mcdi_event_link_speed[speed];
  722. flags = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LINK_FLAGS);
  723. fcntl = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_FCNTL);
  724. lpa = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LP_CAP);
  725. /* efx->link_state is only modified by efx_mcdi_phy_get_link(),
  726. * which is only run after flushing the event queues. Therefore, it
  727. * is safe to modify the link state outside of the mac_lock here.
  728. */
  729. efx_mcdi_phy_decode_link(efx, &efx->link_state, speed, flags, fcntl);
  730. efx_mcdi_phy_check_fcntl(efx, lpa);
  731. efx_link_status_changed(efx);
  732. }
  733. int efx_mcdi_set_mac(struct efx_nic *efx)
  734. {
  735. u32 fcntl;
  736. MCDI_DECLARE_BUF(cmdbytes, MC_CMD_SET_MAC_IN_LEN);
  737. BUILD_BUG_ON(MC_CMD_SET_MAC_OUT_LEN != 0);
  738. memcpy(MCDI_PTR(cmdbytes, SET_MAC_IN_ADDR),
  739. efx->net_dev->dev_addr, ETH_ALEN);
  740. MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_MTU,
  741. EFX_MAX_FRAME_LEN(efx->net_dev->mtu));
  742. MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_DRAIN, 0);
  743. /* Set simple MAC filter for Siena */
  744. MCDI_POPULATE_DWORD_1(cmdbytes, SET_MAC_IN_REJECT,
  745. SET_MAC_IN_REJECT_UNCST, efx->unicast_filter);
  746. switch (efx->wanted_fc) {
  747. case EFX_FC_RX | EFX_FC_TX:
  748. fcntl = MC_CMD_FCNTL_BIDIR;
  749. break;
  750. case EFX_FC_RX:
  751. fcntl = MC_CMD_FCNTL_RESPOND;
  752. break;
  753. default:
  754. fcntl = MC_CMD_FCNTL_OFF;
  755. break;
  756. }
  757. if (efx->wanted_fc & EFX_FC_AUTO)
  758. fcntl = MC_CMD_FCNTL_AUTO;
  759. if (efx->fc_disable)
  760. fcntl = MC_CMD_FCNTL_OFF;
  761. MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_FCNTL, fcntl);
  762. return efx_mcdi_rpc(efx, MC_CMD_SET_MAC, cmdbytes, sizeof(cmdbytes),
  763. NULL, 0, NULL);
  764. }
  765. bool efx_mcdi_mac_check_fault(struct efx_nic *efx)
  766. {
  767. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
  768. size_t outlength;
  769. int rc;
  770. BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
  771. rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
  772. outbuf, sizeof(outbuf), &outlength);
  773. if (rc) {
  774. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  775. __func__, rc);
  776. return true;
  777. }
  778. return MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT) != 0;
  779. }
  780. static int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr,
  781. u32 dma_len, int enable, int clear)
  782. {
  783. MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
  784. int rc;
  785. int period = enable ? 1000 : 0;
  786. BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0);
  787. MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, dma_addr);
  788. MCDI_POPULATE_DWORD_7(inbuf, MAC_STATS_IN_CMD,
  789. MAC_STATS_IN_DMA, !!enable,
  790. MAC_STATS_IN_CLEAR, clear,
  791. MAC_STATS_IN_PERIODIC_CHANGE, 1,
  792. MAC_STATS_IN_PERIODIC_ENABLE, !!enable,
  793. MAC_STATS_IN_PERIODIC_CLEAR, 0,
  794. MAC_STATS_IN_PERIODIC_NOEVENT, 1,
  795. MAC_STATS_IN_PERIOD_MS, period);
  796. MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
  797. rc = efx_mcdi_rpc(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
  798. NULL, 0, NULL);
  799. if (rc)
  800. goto fail;
  801. return 0;
  802. fail:
  803. netif_err(efx, hw, efx->net_dev, "%s: %s failed rc=%d\n",
  804. __func__, enable ? "enable" : "disable", rc);
  805. return rc;
  806. }
  807. void efx_mcdi_mac_start_stats(struct efx_nic *efx)
  808. {
  809. __le64 *dma_stats = efx->stats_buffer.addr;
  810. dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
  811. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr,
  812. MC_CMD_MAC_NSTATS * sizeof(u64), 1, 0);
  813. }
  814. void efx_mcdi_mac_stop_stats(struct efx_nic *efx)
  815. {
  816. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, 0, 0, 0);
  817. }
  818. int efx_mcdi_port_probe(struct efx_nic *efx)
  819. {
  820. int rc;
  821. /* Hook in PHY operations table */
  822. efx->phy_op = &efx_mcdi_phy_ops;
  823. /* Set up MDIO structure for PHY */
  824. efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  825. efx->mdio.mdio_read = efx_mcdi_mdio_read;
  826. efx->mdio.mdio_write = efx_mcdi_mdio_write;
  827. /* Fill out MDIO structure, loopback modes, and initial link state */
  828. rc = efx->phy_op->probe(efx);
  829. if (rc != 0)
  830. return rc;
  831. /* Allocate buffer for stats */
  832. rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
  833. MC_CMD_MAC_NSTATS * sizeof(u64), GFP_KERNEL);
  834. if (rc)
  835. return rc;
  836. netif_dbg(efx, probe, efx->net_dev,
  837. "stats buffer at %llx (virt %p phys %llx)\n",
  838. (u64)efx->stats_buffer.dma_addr,
  839. efx->stats_buffer.addr,
  840. (u64)virt_to_phys(efx->stats_buffer.addr));
  841. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, 0, 0, 1);
  842. return 0;
  843. }
  844. void efx_mcdi_port_remove(struct efx_nic *efx)
  845. {
  846. efx->phy_op->remove(efx);
  847. efx_nic_free_buffer(efx, &efx->stats_buffer);
  848. }
  849. /* Get physical port number (EF10 only; on Siena it is same as PF number) */
  850. int efx_mcdi_port_get_number(struct efx_nic *efx)
  851. {
  852. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN);
  853. int rc;
  854. rc = efx_mcdi_rpc(efx, MC_CMD_GET_PORT_ASSIGNMENT, NULL, 0,
  855. outbuf, sizeof(outbuf), NULL);
  856. if (rc)
  857. return rc;
  858. return MCDI_DWORD(outbuf, GET_PORT_ASSIGNMENT_OUT_PORT);
  859. }