efx_devlink.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /****************************************************************************
  3. * Driver for AMD network controllers and boards
  4. * Copyright (C) 2023, Advanced Micro Devices, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #include "net_driver.h"
  11. #include "ef100_nic.h"
  12. #include "efx_devlink.h"
  13. #include <linux/rtc.h>
  14. #include "mcdi.h"
  15. #include "mcdi_functions.h"
  16. #include "mcdi_pcol.h"
  17. #ifdef CONFIG_SFC_SRIOV
  18. #include "mae.h"
  19. #include "ef100_rep.h"
  20. #endif
  21. struct efx_devlink {
  22. struct efx_nic *efx;
  23. };
  24. #ifdef CONFIG_SFC_SRIOV
  25. static int efx_devlink_port_addr_get(struct devlink_port *port, u8 *hw_addr,
  26. int *hw_addr_len,
  27. struct netlink_ext_ack *extack)
  28. {
  29. struct efx_devlink *devlink = devlink_priv(port->devlink);
  30. struct mae_mport_desc *mport_desc;
  31. efx_qword_t pciefn;
  32. u32 client_id;
  33. int rc = 0;
  34. mport_desc = container_of(port, struct mae_mport_desc, dl_port);
  35. if (!ef100_mport_on_local_intf(devlink->efx, mport_desc)) {
  36. rc = -EINVAL;
  37. NL_SET_ERR_MSG_FMT(extack,
  38. "Port not on local interface (mport: %u)",
  39. mport_desc->mport_id);
  40. goto out;
  41. }
  42. if (ef100_mport_is_vf(mport_desc))
  43. EFX_POPULATE_QWORD_3(pciefn,
  44. PCIE_FUNCTION_PF, PCIE_FUNCTION_PF_NULL,
  45. PCIE_FUNCTION_VF, mport_desc->vf_idx,
  46. PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER);
  47. else
  48. EFX_POPULATE_QWORD_3(pciefn,
  49. PCIE_FUNCTION_PF, mport_desc->pf_idx,
  50. PCIE_FUNCTION_VF, PCIE_FUNCTION_VF_NULL,
  51. PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER);
  52. rc = efx_ef100_lookup_client_id(devlink->efx, pciefn, &client_id);
  53. if (rc) {
  54. NL_SET_ERR_MSG_FMT(extack,
  55. "No internal client_ID for port (mport: %u)",
  56. mport_desc->mport_id);
  57. goto out;
  58. }
  59. rc = ef100_get_mac_address(devlink->efx, hw_addr, client_id, true);
  60. if (rc != 0)
  61. NL_SET_ERR_MSG_FMT(extack,
  62. "No available MAC for port (mport: %u)",
  63. mport_desc->mport_id);
  64. out:
  65. *hw_addr_len = ETH_ALEN;
  66. return rc;
  67. }
  68. static int efx_devlink_port_addr_set(struct devlink_port *port,
  69. const u8 *hw_addr, int hw_addr_len,
  70. struct netlink_ext_ack *extack)
  71. {
  72. MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_CLIENT_MAC_ADDRESSES_IN_LEN(1));
  73. struct efx_devlink *devlink = devlink_priv(port->devlink);
  74. struct mae_mport_desc *mport_desc;
  75. efx_qword_t pciefn;
  76. u32 client_id;
  77. int rc;
  78. mport_desc = container_of(port, struct mae_mport_desc, dl_port);
  79. if (!ef100_mport_is_vf(mport_desc)) {
  80. NL_SET_ERR_MSG_FMT(extack,
  81. "port mac change not allowed (mport: %u)",
  82. mport_desc->mport_id);
  83. return -EPERM;
  84. }
  85. EFX_POPULATE_QWORD_3(pciefn,
  86. PCIE_FUNCTION_PF, PCIE_FUNCTION_PF_NULL,
  87. PCIE_FUNCTION_VF, mport_desc->vf_idx,
  88. PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER);
  89. rc = efx_ef100_lookup_client_id(devlink->efx, pciefn, &client_id);
  90. if (rc) {
  91. NL_SET_ERR_MSG_FMT(extack,
  92. "No internal client_ID for port (mport: %u)",
  93. mport_desc->mport_id);
  94. return rc;
  95. }
  96. MCDI_SET_DWORD(inbuf, SET_CLIENT_MAC_ADDRESSES_IN_CLIENT_HANDLE,
  97. client_id);
  98. ether_addr_copy(MCDI_PTR(inbuf, SET_CLIENT_MAC_ADDRESSES_IN_MAC_ADDRS),
  99. hw_addr);
  100. rc = efx_mcdi_rpc(devlink->efx, MC_CMD_SET_CLIENT_MAC_ADDRESSES, inbuf,
  101. sizeof(inbuf), NULL, 0, NULL);
  102. if (rc)
  103. NL_SET_ERR_MSG_FMT(extack,
  104. "sfc MC_CMD_SET_CLIENT_MAC_ADDRESSES mcdi error (mport: %u)",
  105. mport_desc->mport_id);
  106. return rc;
  107. }
  108. static const struct devlink_port_ops sfc_devlink_port_ops = {
  109. .port_fn_hw_addr_get = efx_devlink_port_addr_get,
  110. .port_fn_hw_addr_set = efx_devlink_port_addr_set,
  111. };
  112. static void efx_devlink_del_port(struct devlink_port *dl_port)
  113. {
  114. if (!dl_port)
  115. return;
  116. devl_port_unregister(dl_port);
  117. }
  118. static int efx_devlink_add_port(struct efx_nic *efx,
  119. struct mae_mport_desc *mport)
  120. {
  121. bool external = false;
  122. if (!ef100_mport_on_local_intf(efx, mport))
  123. external = true;
  124. switch (mport->mport_type) {
  125. case MAE_MPORT_DESC_MPORT_TYPE_VNIC:
  126. if (mport->vf_idx != MAE_MPORT_DESC_VF_IDX_NULL)
  127. devlink_port_attrs_pci_vf_set(&mport->dl_port, 0, mport->pf_idx,
  128. mport->vf_idx,
  129. external);
  130. else
  131. devlink_port_attrs_pci_pf_set(&mport->dl_port, 0, mport->pf_idx,
  132. external);
  133. break;
  134. default:
  135. /* MAE_MPORT_DESC_MPORT_ALIAS and UNDEFINED */
  136. return 0;
  137. }
  138. mport->dl_port.index = mport->mport_id;
  139. return devl_port_register_with_ops(efx->devlink, &mport->dl_port,
  140. mport->mport_id,
  141. &sfc_devlink_port_ops);
  142. }
  143. #endif
  144. static int efx_devlink_info_nvram_partition(struct efx_nic *efx,
  145. struct devlink_info_req *req,
  146. unsigned int partition_type,
  147. const char *version_name)
  148. {
  149. char buf[EFX_MAX_VERSION_INFO_LEN];
  150. u16 version[4];
  151. int rc;
  152. rc = efx_mcdi_nvram_metadata(efx, partition_type, NULL, version, NULL,
  153. 0);
  154. /* If the partition does not exist, that is not an error. */
  155. if (rc == -ENOENT)
  156. return 0;
  157. if (rc) {
  158. netif_err(efx, drv, efx->net_dev, "mcdi nvram %s: failed (rc=%d)\n",
  159. version_name, rc);
  160. return rc;
  161. }
  162. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", version[0],
  163. version[1], version[2], version[3]);
  164. devlink_info_version_stored_put(req, version_name, buf);
  165. return 0;
  166. }
  167. static int efx_devlink_info_stored_versions(struct efx_nic *efx,
  168. struct devlink_info_req *req)
  169. {
  170. int err;
  171. /* We do not care here about the specific error but just if an error
  172. * happened. The specific error will be reported inside the call
  173. * through system messages, and if any error happened in any call
  174. * below, we report it through extack.
  175. */
  176. err = efx_devlink_info_nvram_partition(efx, req,
  177. NVRAM_PARTITION_TYPE_BUNDLE,
  178. DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID);
  179. err |= efx_devlink_info_nvram_partition(efx, req,
  180. NVRAM_PARTITION_TYPE_MC_FIRMWARE,
  181. DEVLINK_INFO_VERSION_GENERIC_FW_MGMT);
  182. err |= efx_devlink_info_nvram_partition(efx, req,
  183. NVRAM_PARTITION_TYPE_SUC_FIRMWARE,
  184. EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC);
  185. err |= efx_devlink_info_nvram_partition(efx, req,
  186. NVRAM_PARTITION_TYPE_EXPANSION_ROM,
  187. EFX_DEVLINK_INFO_VERSION_FW_EXPROM);
  188. err |= efx_devlink_info_nvram_partition(efx, req,
  189. NVRAM_PARTITION_TYPE_EXPANSION_UEFI,
  190. EFX_DEVLINK_INFO_VERSION_FW_UEFI);
  191. return err;
  192. }
  193. #define EFX_VER_FLAG(_f) \
  194. (MC_CMD_GET_VERSION_V5_OUT_ ## _f ## _PRESENT_LBN)
  195. static void efx_devlink_info_running_v2(struct efx_nic *efx,
  196. struct devlink_info_req *req,
  197. unsigned int flags, efx_dword_t *outbuf)
  198. {
  199. char buf[EFX_MAX_VERSION_INFO_LEN];
  200. union {
  201. const __le32 *dwords;
  202. const __le16 *words;
  203. const char *str;
  204. } ver;
  205. struct rtc_time build_date;
  206. unsigned int build_id;
  207. size_t offset;
  208. __maybe_unused u64 tstamp;
  209. if (flags & BIT(EFX_VER_FLAG(BOARD_EXT_INFO))) {
  210. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%s",
  211. MCDI_PTR(outbuf, GET_VERSION_V2_OUT_BOARD_NAME));
  212. devlink_info_version_fixed_put(req,
  213. DEVLINK_INFO_VERSION_GENERIC_BOARD_ID,
  214. buf);
  215. /* Favour full board version if present (in V5 or later) */
  216. if (~flags & BIT(EFX_VER_FLAG(BOARD_VERSION))) {
  217. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u",
  218. MCDI_DWORD(outbuf,
  219. GET_VERSION_V2_OUT_BOARD_REVISION));
  220. devlink_info_version_fixed_put(req,
  221. DEVLINK_INFO_VERSION_GENERIC_BOARD_REV,
  222. buf);
  223. }
  224. ver.str = MCDI_PTR(outbuf, GET_VERSION_V2_OUT_BOARD_SERIAL);
  225. if (ver.str[0])
  226. devlink_info_board_serial_number_put(req, ver.str);
  227. }
  228. if (flags & BIT(EFX_VER_FLAG(FPGA_EXT_INFO))) {
  229. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  230. GET_VERSION_V2_OUT_FPGA_VERSION);
  231. offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u_%c%u",
  232. le32_to_cpu(ver.dwords[0]),
  233. 'A' + le32_to_cpu(ver.dwords[1]),
  234. le32_to_cpu(ver.dwords[2]));
  235. ver.str = MCDI_PTR(outbuf, GET_VERSION_V2_OUT_FPGA_EXTRA);
  236. if (ver.str[0])
  237. snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset,
  238. " (%s)", ver.str);
  239. devlink_info_version_running_put(req,
  240. EFX_DEVLINK_INFO_VERSION_FPGA_REV,
  241. buf);
  242. }
  243. if (flags & BIT(EFX_VER_FLAG(CMC_EXT_INFO))) {
  244. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  245. GET_VERSION_V2_OUT_CMCFW_VERSION);
  246. offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
  247. le32_to_cpu(ver.dwords[0]),
  248. le32_to_cpu(ver.dwords[1]),
  249. le32_to_cpu(ver.dwords[2]),
  250. le32_to_cpu(ver.dwords[3]));
  251. #ifdef CONFIG_RTC_LIB
  252. tstamp = MCDI_QWORD(outbuf,
  253. GET_VERSION_V2_OUT_CMCFW_BUILD_DATE);
  254. if (tstamp) {
  255. rtc_time64_to_tm(tstamp, &build_date);
  256. snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset,
  257. " (%ptRd)", &build_date);
  258. }
  259. #endif
  260. devlink_info_version_running_put(req,
  261. EFX_DEVLINK_INFO_VERSION_FW_MGMT_CMC,
  262. buf);
  263. }
  264. ver.words = (__le16 *)MCDI_PTR(outbuf, GET_VERSION_V2_OUT_VERSION);
  265. offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
  266. le16_to_cpu(ver.words[0]), le16_to_cpu(ver.words[1]),
  267. le16_to_cpu(ver.words[2]), le16_to_cpu(ver.words[3]));
  268. if (flags & BIT(EFX_VER_FLAG(MCFW_EXT_INFO))) {
  269. build_id = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_MCFW_BUILD_ID);
  270. snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset,
  271. " (%x) %s", build_id,
  272. MCDI_PTR(outbuf, GET_VERSION_V2_OUT_MCFW_BUILD_NAME));
  273. }
  274. devlink_info_version_running_put(req,
  275. DEVLINK_INFO_VERSION_GENERIC_FW_MGMT,
  276. buf);
  277. if (flags & BIT(EFX_VER_FLAG(SUCFW_EXT_INFO))) {
  278. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  279. GET_VERSION_V2_OUT_SUCFW_VERSION);
  280. #ifdef CONFIG_RTC_LIB
  281. tstamp = MCDI_QWORD(outbuf,
  282. GET_VERSION_V2_OUT_SUCFW_BUILD_DATE);
  283. rtc_time64_to_tm(tstamp, &build_date);
  284. #else
  285. memset(&build_date, 0, sizeof(build_date));
  286. #endif
  287. build_id = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_SUCFW_CHIP_ID);
  288. snprintf(buf, EFX_MAX_VERSION_INFO_LEN,
  289. "%u.%u.%u.%u type %x (%ptRd)",
  290. le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
  291. le32_to_cpu(ver.dwords[2]), le32_to_cpu(ver.dwords[3]),
  292. build_id, &build_date);
  293. devlink_info_version_running_put(req,
  294. EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC,
  295. buf);
  296. }
  297. }
  298. static void efx_devlink_info_running_v3(struct efx_nic *efx,
  299. struct devlink_info_req *req,
  300. unsigned int flags, efx_dword_t *outbuf)
  301. {
  302. char buf[EFX_MAX_VERSION_INFO_LEN];
  303. union {
  304. const __le32 *dwords;
  305. const __le16 *words;
  306. const char *str;
  307. } ver;
  308. if (flags & BIT(EFX_VER_FLAG(DATAPATH_HW_VERSION))) {
  309. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  310. GET_VERSION_V3_OUT_DATAPATH_HW_VERSION);
  311. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u",
  312. le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
  313. le32_to_cpu(ver.dwords[2]));
  314. devlink_info_version_running_put(req,
  315. EFX_DEVLINK_INFO_VERSION_DATAPATH_HW,
  316. buf);
  317. }
  318. if (flags & BIT(EFX_VER_FLAG(DATAPATH_FW_VERSION))) {
  319. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  320. GET_VERSION_V3_OUT_DATAPATH_FW_VERSION);
  321. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u",
  322. le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
  323. le32_to_cpu(ver.dwords[2]));
  324. devlink_info_version_running_put(req,
  325. EFX_DEVLINK_INFO_VERSION_DATAPATH_FW,
  326. buf);
  327. }
  328. }
  329. static void efx_devlink_info_running_v4(struct efx_nic *efx,
  330. struct devlink_info_req *req,
  331. unsigned int flags, efx_dword_t *outbuf)
  332. {
  333. char buf[EFX_MAX_VERSION_INFO_LEN];
  334. union {
  335. const __le32 *dwords;
  336. const __le16 *words;
  337. const char *str;
  338. } ver;
  339. if (flags & BIT(EFX_VER_FLAG(SOC_BOOT_VERSION))) {
  340. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  341. GET_VERSION_V4_OUT_SOC_BOOT_VERSION);
  342. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
  343. le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
  344. le32_to_cpu(ver.dwords[2]),
  345. le32_to_cpu(ver.dwords[3]));
  346. devlink_info_version_running_put(req,
  347. EFX_DEVLINK_INFO_VERSION_SOC_BOOT,
  348. buf);
  349. }
  350. if (flags & BIT(EFX_VER_FLAG(SOC_UBOOT_VERSION))) {
  351. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  352. GET_VERSION_V4_OUT_SOC_UBOOT_VERSION);
  353. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
  354. le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
  355. le32_to_cpu(ver.dwords[2]),
  356. le32_to_cpu(ver.dwords[3]));
  357. devlink_info_version_running_put(req,
  358. EFX_DEVLINK_INFO_VERSION_SOC_UBOOT,
  359. buf);
  360. }
  361. if (flags & BIT(EFX_VER_FLAG(SOC_MAIN_ROOTFS_VERSION))) {
  362. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  363. GET_VERSION_V4_OUT_SOC_MAIN_ROOTFS_VERSION);
  364. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
  365. le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
  366. le32_to_cpu(ver.dwords[2]),
  367. le32_to_cpu(ver.dwords[3]));
  368. devlink_info_version_running_put(req,
  369. EFX_DEVLINK_INFO_VERSION_SOC_MAIN,
  370. buf);
  371. }
  372. if (flags & BIT(EFX_VER_FLAG(SOC_RECOVERY_BUILDROOT_VERSION))) {
  373. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  374. GET_VERSION_V4_OUT_SOC_RECOVERY_BUILDROOT_VERSION);
  375. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
  376. le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
  377. le32_to_cpu(ver.dwords[2]),
  378. le32_to_cpu(ver.dwords[3]));
  379. devlink_info_version_running_put(req,
  380. EFX_DEVLINK_INFO_VERSION_SOC_RECOVERY,
  381. buf);
  382. }
  383. if (flags & BIT(EFX_VER_FLAG(SUCFW_VERSION)) &&
  384. ~flags & BIT(EFX_VER_FLAG(SUCFW_EXT_INFO))) {
  385. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  386. GET_VERSION_V4_OUT_SUCFW_VERSION);
  387. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
  388. le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
  389. le32_to_cpu(ver.dwords[2]),
  390. le32_to_cpu(ver.dwords[3]));
  391. devlink_info_version_running_put(req,
  392. EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC,
  393. buf);
  394. }
  395. }
  396. static void efx_devlink_info_running_v5(struct efx_nic *efx,
  397. struct devlink_info_req *req,
  398. unsigned int flags, efx_dword_t *outbuf)
  399. {
  400. char buf[EFX_MAX_VERSION_INFO_LEN];
  401. union {
  402. const __le32 *dwords;
  403. const __le16 *words;
  404. const char *str;
  405. } ver;
  406. if (flags & BIT(EFX_VER_FLAG(BOARD_VERSION))) {
  407. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  408. GET_VERSION_V5_OUT_BOARD_VERSION);
  409. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
  410. le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
  411. le32_to_cpu(ver.dwords[2]),
  412. le32_to_cpu(ver.dwords[3]));
  413. devlink_info_version_running_put(req,
  414. DEVLINK_INFO_VERSION_GENERIC_BOARD_REV,
  415. buf);
  416. }
  417. if (flags & BIT(EFX_VER_FLAG(BUNDLE_VERSION))) {
  418. ver.dwords = (__le32 *)MCDI_PTR(outbuf,
  419. GET_VERSION_V5_OUT_BUNDLE_VERSION);
  420. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
  421. le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
  422. le32_to_cpu(ver.dwords[2]),
  423. le32_to_cpu(ver.dwords[3]));
  424. devlink_info_version_running_put(req,
  425. DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID,
  426. buf);
  427. }
  428. }
  429. static int efx_devlink_info_running_versions(struct efx_nic *efx,
  430. struct devlink_info_req *req)
  431. {
  432. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_VERSION_V5_OUT_LEN);
  433. MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_VERSION_EXT_IN_LEN);
  434. char buf[EFX_MAX_VERSION_INFO_LEN];
  435. union {
  436. const __le32 *dwords;
  437. const __le16 *words;
  438. const char *str;
  439. } ver;
  440. size_t outlength;
  441. unsigned int flags;
  442. int rc;
  443. rc = efx_mcdi_rpc(efx, MC_CMD_GET_VERSION, inbuf, sizeof(inbuf),
  444. outbuf, sizeof(outbuf), &outlength);
  445. if (rc || outlength < MC_CMD_GET_VERSION_OUT_LEN) {
  446. netif_err(efx, drv, efx->net_dev,
  447. "mcdi MC_CMD_GET_VERSION failed\n");
  448. return rc;
  449. }
  450. /* Handle previous output */
  451. if (outlength < MC_CMD_GET_VERSION_V2_OUT_LEN) {
  452. ver.words = (__le16 *)MCDI_PTR(outbuf,
  453. GET_VERSION_EXT_OUT_VERSION);
  454. snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
  455. le16_to_cpu(ver.words[0]),
  456. le16_to_cpu(ver.words[1]),
  457. le16_to_cpu(ver.words[2]),
  458. le16_to_cpu(ver.words[3]));
  459. devlink_info_version_running_put(req,
  460. DEVLINK_INFO_VERSION_GENERIC_FW_MGMT,
  461. buf);
  462. return 0;
  463. }
  464. /* Handle V2 additions */
  465. flags = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_FLAGS);
  466. efx_devlink_info_running_v2(efx, req, flags, outbuf);
  467. if (outlength < MC_CMD_GET_VERSION_V3_OUT_LEN)
  468. return 0;
  469. /* Handle V3 additions */
  470. efx_devlink_info_running_v3(efx, req, flags, outbuf);
  471. if (outlength < MC_CMD_GET_VERSION_V4_OUT_LEN)
  472. return 0;
  473. /* Handle V4 additions */
  474. efx_devlink_info_running_v4(efx, req, flags, outbuf);
  475. if (outlength < MC_CMD_GET_VERSION_V5_OUT_LEN)
  476. return 0;
  477. /* Handle V5 additions */
  478. efx_devlink_info_running_v5(efx, req, flags, outbuf);
  479. return 0;
  480. }
  481. #define EFX_MAX_SERIALNUM_LEN (ETH_ALEN * 2 + 1)
  482. static int efx_devlink_info_board_cfg(struct efx_nic *efx,
  483. struct devlink_info_req *req)
  484. {
  485. char sn[EFX_MAX_SERIALNUM_LEN];
  486. u8 mac_address[ETH_ALEN];
  487. int rc;
  488. rc = efx_mcdi_get_board_cfg(efx, (u8 *)mac_address, NULL, NULL);
  489. if (!rc) {
  490. snprintf(sn, EFX_MAX_SERIALNUM_LEN, "%pm", mac_address);
  491. devlink_info_serial_number_put(req, sn);
  492. }
  493. return rc;
  494. }
  495. static int efx_devlink_info_get(struct devlink *devlink,
  496. struct devlink_info_req *req,
  497. struct netlink_ext_ack *extack)
  498. {
  499. struct efx_devlink *devlink_private = devlink_priv(devlink);
  500. struct efx_nic *efx = devlink_private->efx;
  501. int err;
  502. /* Several different MCDI commands are used. We report if errors
  503. * happened through extack. Specific error information via system
  504. * messages inside the calls.
  505. */
  506. err = efx_devlink_info_board_cfg(efx, req);
  507. err |= efx_devlink_info_stored_versions(efx, req);
  508. err |= efx_devlink_info_running_versions(efx, req);
  509. if (err)
  510. NL_SET_ERR_MSG_MOD(extack, "Errors when getting device info. Check system messages");
  511. return 0;
  512. }
  513. static const struct devlink_ops sfc_devlink_ops = {
  514. .info_get = efx_devlink_info_get,
  515. };
  516. #ifdef CONFIG_SFC_SRIOV
  517. static struct devlink_port *ef100_set_devlink_port(struct efx_nic *efx, u32 idx)
  518. {
  519. struct mae_mport_desc *mport;
  520. u32 id;
  521. int rc;
  522. if (!efx->mae)
  523. return NULL;
  524. if (efx_mae_lookup_mport(efx, idx, &id)) {
  525. /* This should not happen. */
  526. if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
  527. pci_warn_once(efx->pci_dev, "No mport ID found for PF.\n");
  528. else
  529. pci_warn_once(efx->pci_dev, "No mport ID found for VF %u.\n",
  530. idx);
  531. return NULL;
  532. }
  533. mport = efx_mae_get_mport(efx, id);
  534. if (!mport) {
  535. /* This should not happen. */
  536. if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
  537. pci_warn_once(efx->pci_dev, "No mport found for PF.\n");
  538. else
  539. pci_warn_once(efx->pci_dev, "No mport found for VF %u.\n",
  540. idx);
  541. return NULL;
  542. }
  543. rc = efx_devlink_add_port(efx, mport);
  544. if (rc) {
  545. if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
  546. pci_warn(efx->pci_dev,
  547. "devlink port creation for PF failed.\n");
  548. else
  549. pci_warn(efx->pci_dev,
  550. "devlink_port creation for VF %u failed.\n",
  551. idx);
  552. return NULL;
  553. }
  554. return &mport->dl_port;
  555. }
  556. void ef100_rep_set_devlink_port(struct efx_rep *efv)
  557. {
  558. efv->dl_port = ef100_set_devlink_port(efv->parent, efv->idx);
  559. }
  560. void ef100_pf_set_devlink_port(struct efx_nic *efx)
  561. {
  562. efx->dl_port = ef100_set_devlink_port(efx, MAE_MPORT_DESC_VF_IDX_NULL);
  563. }
  564. void ef100_rep_unset_devlink_port(struct efx_rep *efv)
  565. {
  566. efx_devlink_del_port(efv->dl_port);
  567. }
  568. void ef100_pf_unset_devlink_port(struct efx_nic *efx)
  569. {
  570. efx_devlink_del_port(efx->dl_port);
  571. }
  572. #endif
  573. void efx_fini_devlink_lock(struct efx_nic *efx)
  574. {
  575. if (efx->devlink)
  576. devl_lock(efx->devlink);
  577. }
  578. void efx_fini_devlink_and_unlock(struct efx_nic *efx)
  579. {
  580. if (efx->devlink) {
  581. devl_unregister(efx->devlink);
  582. devl_unlock(efx->devlink);
  583. devlink_free(efx->devlink);
  584. efx->devlink = NULL;
  585. }
  586. }
  587. int efx_probe_devlink_and_lock(struct efx_nic *efx)
  588. {
  589. struct efx_devlink *devlink_private;
  590. if (efx->type->is_vf)
  591. return 0;
  592. efx->devlink = devlink_alloc(&sfc_devlink_ops,
  593. sizeof(struct efx_devlink),
  594. &efx->pci_dev->dev);
  595. if (!efx->devlink)
  596. return -ENOMEM;
  597. devl_lock(efx->devlink);
  598. devlink_private = devlink_priv(efx->devlink);
  599. devlink_private->efx = efx;
  600. devl_register(efx->devlink);
  601. return 0;
  602. }
  603. void efx_probe_devlink_unlock(struct efx_nic *efx)
  604. {
  605. if (!efx->devlink)
  606. return;
  607. devl_unlock(efx->devlink);
  608. }