| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733 |
- // SPDX-License-Identifier: GPL-2.0-only
- /****************************************************************************
- * Driver for AMD network controllers and boards
- * Copyright (C) 2023, Advanced Micro Devices, Inc.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published
- * by the Free Software Foundation, incorporated herein by reference.
- */
- #include "net_driver.h"
- #include "ef100_nic.h"
- #include "efx_devlink.h"
- #include <linux/rtc.h>
- #include "mcdi.h"
- #include "mcdi_functions.h"
- #include "mcdi_pcol.h"
- #ifdef CONFIG_SFC_SRIOV
- #include "mae.h"
- #include "ef100_rep.h"
- #endif
- struct efx_devlink {
- struct efx_nic *efx;
- };
- #ifdef CONFIG_SFC_SRIOV
- static int efx_devlink_port_addr_get(struct devlink_port *port, u8 *hw_addr,
- int *hw_addr_len,
- struct netlink_ext_ack *extack)
- {
- struct efx_devlink *devlink = devlink_priv(port->devlink);
- struct mae_mport_desc *mport_desc;
- efx_qword_t pciefn;
- u32 client_id;
- int rc = 0;
- mport_desc = container_of(port, struct mae_mport_desc, dl_port);
- if (!ef100_mport_on_local_intf(devlink->efx, mport_desc)) {
- rc = -EINVAL;
- NL_SET_ERR_MSG_FMT(extack,
- "Port not on local interface (mport: %u)",
- mport_desc->mport_id);
- goto out;
- }
- if (ef100_mport_is_vf(mport_desc))
- EFX_POPULATE_QWORD_3(pciefn,
- PCIE_FUNCTION_PF, PCIE_FUNCTION_PF_NULL,
- PCIE_FUNCTION_VF, mport_desc->vf_idx,
- PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER);
- else
- EFX_POPULATE_QWORD_3(pciefn,
- PCIE_FUNCTION_PF, mport_desc->pf_idx,
- PCIE_FUNCTION_VF, PCIE_FUNCTION_VF_NULL,
- PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER);
- rc = efx_ef100_lookup_client_id(devlink->efx, pciefn, &client_id);
- if (rc) {
- NL_SET_ERR_MSG_FMT(extack,
- "No internal client_ID for port (mport: %u)",
- mport_desc->mport_id);
- goto out;
- }
- rc = ef100_get_mac_address(devlink->efx, hw_addr, client_id, true);
- if (rc != 0)
- NL_SET_ERR_MSG_FMT(extack,
- "No available MAC for port (mport: %u)",
- mport_desc->mport_id);
- out:
- *hw_addr_len = ETH_ALEN;
- return rc;
- }
- static int efx_devlink_port_addr_set(struct devlink_port *port,
- const u8 *hw_addr, int hw_addr_len,
- struct netlink_ext_ack *extack)
- {
- MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_CLIENT_MAC_ADDRESSES_IN_LEN(1));
- struct efx_devlink *devlink = devlink_priv(port->devlink);
- struct mae_mport_desc *mport_desc;
- efx_qword_t pciefn;
- u32 client_id;
- int rc;
- mport_desc = container_of(port, struct mae_mport_desc, dl_port);
- if (!ef100_mport_is_vf(mport_desc)) {
- NL_SET_ERR_MSG_FMT(extack,
- "port mac change not allowed (mport: %u)",
- mport_desc->mport_id);
- return -EPERM;
- }
- EFX_POPULATE_QWORD_3(pciefn,
- PCIE_FUNCTION_PF, PCIE_FUNCTION_PF_NULL,
- PCIE_FUNCTION_VF, mport_desc->vf_idx,
- PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER);
- rc = efx_ef100_lookup_client_id(devlink->efx, pciefn, &client_id);
- if (rc) {
- NL_SET_ERR_MSG_FMT(extack,
- "No internal client_ID for port (mport: %u)",
- mport_desc->mport_id);
- return rc;
- }
- MCDI_SET_DWORD(inbuf, SET_CLIENT_MAC_ADDRESSES_IN_CLIENT_HANDLE,
- client_id);
- ether_addr_copy(MCDI_PTR(inbuf, SET_CLIENT_MAC_ADDRESSES_IN_MAC_ADDRS),
- hw_addr);
- rc = efx_mcdi_rpc(devlink->efx, MC_CMD_SET_CLIENT_MAC_ADDRESSES, inbuf,
- sizeof(inbuf), NULL, 0, NULL);
- if (rc)
- NL_SET_ERR_MSG_FMT(extack,
- "sfc MC_CMD_SET_CLIENT_MAC_ADDRESSES mcdi error (mport: %u)",
- mport_desc->mport_id);
- return rc;
- }
- static const struct devlink_port_ops sfc_devlink_port_ops = {
- .port_fn_hw_addr_get = efx_devlink_port_addr_get,
- .port_fn_hw_addr_set = efx_devlink_port_addr_set,
- };
- static void efx_devlink_del_port(struct devlink_port *dl_port)
- {
- if (!dl_port)
- return;
- devl_port_unregister(dl_port);
- }
- static int efx_devlink_add_port(struct efx_nic *efx,
- struct mae_mport_desc *mport)
- {
- bool external = false;
- if (!ef100_mport_on_local_intf(efx, mport))
- external = true;
- switch (mport->mport_type) {
- case MAE_MPORT_DESC_MPORT_TYPE_VNIC:
- if (mport->vf_idx != MAE_MPORT_DESC_VF_IDX_NULL)
- devlink_port_attrs_pci_vf_set(&mport->dl_port, 0, mport->pf_idx,
- mport->vf_idx,
- external);
- else
- devlink_port_attrs_pci_pf_set(&mport->dl_port, 0, mport->pf_idx,
- external);
- break;
- default:
- /* MAE_MPORT_DESC_MPORT_ALIAS and UNDEFINED */
- return 0;
- }
- mport->dl_port.index = mport->mport_id;
- return devl_port_register_with_ops(efx->devlink, &mport->dl_port,
- mport->mport_id,
- &sfc_devlink_port_ops);
- }
- #endif
- static int efx_devlink_info_nvram_partition(struct efx_nic *efx,
- struct devlink_info_req *req,
- unsigned int partition_type,
- const char *version_name)
- {
- char buf[EFX_MAX_VERSION_INFO_LEN];
- u16 version[4];
- int rc;
- rc = efx_mcdi_nvram_metadata(efx, partition_type, NULL, version, NULL,
- 0);
- /* If the partition does not exist, that is not an error. */
- if (rc == -ENOENT)
- return 0;
- if (rc) {
- netif_err(efx, drv, efx->net_dev, "mcdi nvram %s: failed (rc=%d)\n",
- version_name, rc);
- return rc;
- }
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", version[0],
- version[1], version[2], version[3]);
- devlink_info_version_stored_put(req, version_name, buf);
- return 0;
- }
- static int efx_devlink_info_stored_versions(struct efx_nic *efx,
- struct devlink_info_req *req)
- {
- int err;
- /* We do not care here about the specific error but just if an error
- * happened. The specific error will be reported inside the call
- * through system messages, and if any error happened in any call
- * below, we report it through extack.
- */
- err = efx_devlink_info_nvram_partition(efx, req,
- NVRAM_PARTITION_TYPE_BUNDLE,
- DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID);
- err |= efx_devlink_info_nvram_partition(efx, req,
- NVRAM_PARTITION_TYPE_MC_FIRMWARE,
- DEVLINK_INFO_VERSION_GENERIC_FW_MGMT);
- err |= efx_devlink_info_nvram_partition(efx, req,
- NVRAM_PARTITION_TYPE_SUC_FIRMWARE,
- EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC);
- err |= efx_devlink_info_nvram_partition(efx, req,
- NVRAM_PARTITION_TYPE_EXPANSION_ROM,
- EFX_DEVLINK_INFO_VERSION_FW_EXPROM);
- err |= efx_devlink_info_nvram_partition(efx, req,
- NVRAM_PARTITION_TYPE_EXPANSION_UEFI,
- EFX_DEVLINK_INFO_VERSION_FW_UEFI);
- return err;
- }
- #define EFX_VER_FLAG(_f) \
- (MC_CMD_GET_VERSION_V5_OUT_ ## _f ## _PRESENT_LBN)
- static void efx_devlink_info_running_v2(struct efx_nic *efx,
- struct devlink_info_req *req,
- unsigned int flags, efx_dword_t *outbuf)
- {
- char buf[EFX_MAX_VERSION_INFO_LEN];
- union {
- const __le32 *dwords;
- const __le16 *words;
- const char *str;
- } ver;
- struct rtc_time build_date;
- unsigned int build_id;
- size_t offset;
- __maybe_unused u64 tstamp;
- if (flags & BIT(EFX_VER_FLAG(BOARD_EXT_INFO))) {
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%s",
- MCDI_PTR(outbuf, GET_VERSION_V2_OUT_BOARD_NAME));
- devlink_info_version_fixed_put(req,
- DEVLINK_INFO_VERSION_GENERIC_BOARD_ID,
- buf);
- /* Favour full board version if present (in V5 or later) */
- if (~flags & BIT(EFX_VER_FLAG(BOARD_VERSION))) {
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u",
- MCDI_DWORD(outbuf,
- GET_VERSION_V2_OUT_BOARD_REVISION));
- devlink_info_version_fixed_put(req,
- DEVLINK_INFO_VERSION_GENERIC_BOARD_REV,
- buf);
- }
- ver.str = MCDI_PTR(outbuf, GET_VERSION_V2_OUT_BOARD_SERIAL);
- if (ver.str[0])
- devlink_info_board_serial_number_put(req, ver.str);
- }
- if (flags & BIT(EFX_VER_FLAG(FPGA_EXT_INFO))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V2_OUT_FPGA_VERSION);
- offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u_%c%u",
- le32_to_cpu(ver.dwords[0]),
- 'A' + le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]));
- ver.str = MCDI_PTR(outbuf, GET_VERSION_V2_OUT_FPGA_EXTRA);
- if (ver.str[0])
- snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset,
- " (%s)", ver.str);
- devlink_info_version_running_put(req,
- EFX_DEVLINK_INFO_VERSION_FPGA_REV,
- buf);
- }
- if (flags & BIT(EFX_VER_FLAG(CMC_EXT_INFO))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V2_OUT_CMCFW_VERSION);
- offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
- le32_to_cpu(ver.dwords[0]),
- le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]),
- le32_to_cpu(ver.dwords[3]));
- #ifdef CONFIG_RTC_LIB
- tstamp = MCDI_QWORD(outbuf,
- GET_VERSION_V2_OUT_CMCFW_BUILD_DATE);
- if (tstamp) {
- rtc_time64_to_tm(tstamp, &build_date);
- snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset,
- " (%ptRd)", &build_date);
- }
- #endif
- devlink_info_version_running_put(req,
- EFX_DEVLINK_INFO_VERSION_FW_MGMT_CMC,
- buf);
- }
- ver.words = (__le16 *)MCDI_PTR(outbuf, GET_VERSION_V2_OUT_VERSION);
- offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
- le16_to_cpu(ver.words[0]), le16_to_cpu(ver.words[1]),
- le16_to_cpu(ver.words[2]), le16_to_cpu(ver.words[3]));
- if (flags & BIT(EFX_VER_FLAG(MCFW_EXT_INFO))) {
- build_id = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_MCFW_BUILD_ID);
- snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset,
- " (%x) %s", build_id,
- MCDI_PTR(outbuf, GET_VERSION_V2_OUT_MCFW_BUILD_NAME));
- }
- devlink_info_version_running_put(req,
- DEVLINK_INFO_VERSION_GENERIC_FW_MGMT,
- buf);
- if (flags & BIT(EFX_VER_FLAG(SUCFW_EXT_INFO))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V2_OUT_SUCFW_VERSION);
- #ifdef CONFIG_RTC_LIB
- tstamp = MCDI_QWORD(outbuf,
- GET_VERSION_V2_OUT_SUCFW_BUILD_DATE);
- rtc_time64_to_tm(tstamp, &build_date);
- #else
- memset(&build_date, 0, sizeof(build_date));
- #endif
- build_id = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_SUCFW_CHIP_ID);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN,
- "%u.%u.%u.%u type %x (%ptRd)",
- le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]), le32_to_cpu(ver.dwords[3]),
- build_id, &build_date);
- devlink_info_version_running_put(req,
- EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC,
- buf);
- }
- }
- static void efx_devlink_info_running_v3(struct efx_nic *efx,
- struct devlink_info_req *req,
- unsigned int flags, efx_dword_t *outbuf)
- {
- char buf[EFX_MAX_VERSION_INFO_LEN];
- union {
- const __le32 *dwords;
- const __le16 *words;
- const char *str;
- } ver;
- if (flags & BIT(EFX_VER_FLAG(DATAPATH_HW_VERSION))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V3_OUT_DATAPATH_HW_VERSION);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u",
- le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]));
- devlink_info_version_running_put(req,
- EFX_DEVLINK_INFO_VERSION_DATAPATH_HW,
- buf);
- }
- if (flags & BIT(EFX_VER_FLAG(DATAPATH_FW_VERSION))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V3_OUT_DATAPATH_FW_VERSION);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u",
- le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]));
- devlink_info_version_running_put(req,
- EFX_DEVLINK_INFO_VERSION_DATAPATH_FW,
- buf);
- }
- }
- static void efx_devlink_info_running_v4(struct efx_nic *efx,
- struct devlink_info_req *req,
- unsigned int flags, efx_dword_t *outbuf)
- {
- char buf[EFX_MAX_VERSION_INFO_LEN];
- union {
- const __le32 *dwords;
- const __le16 *words;
- const char *str;
- } ver;
- if (flags & BIT(EFX_VER_FLAG(SOC_BOOT_VERSION))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V4_OUT_SOC_BOOT_VERSION);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
- le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]),
- le32_to_cpu(ver.dwords[3]));
- devlink_info_version_running_put(req,
- EFX_DEVLINK_INFO_VERSION_SOC_BOOT,
- buf);
- }
- if (flags & BIT(EFX_VER_FLAG(SOC_UBOOT_VERSION))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V4_OUT_SOC_UBOOT_VERSION);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
- le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]),
- le32_to_cpu(ver.dwords[3]));
- devlink_info_version_running_put(req,
- EFX_DEVLINK_INFO_VERSION_SOC_UBOOT,
- buf);
- }
- if (flags & BIT(EFX_VER_FLAG(SOC_MAIN_ROOTFS_VERSION))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V4_OUT_SOC_MAIN_ROOTFS_VERSION);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
- le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]),
- le32_to_cpu(ver.dwords[3]));
- devlink_info_version_running_put(req,
- EFX_DEVLINK_INFO_VERSION_SOC_MAIN,
- buf);
- }
- if (flags & BIT(EFX_VER_FLAG(SOC_RECOVERY_BUILDROOT_VERSION))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V4_OUT_SOC_RECOVERY_BUILDROOT_VERSION);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
- le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]),
- le32_to_cpu(ver.dwords[3]));
- devlink_info_version_running_put(req,
- EFX_DEVLINK_INFO_VERSION_SOC_RECOVERY,
- buf);
- }
- if (flags & BIT(EFX_VER_FLAG(SUCFW_VERSION)) &&
- ~flags & BIT(EFX_VER_FLAG(SUCFW_EXT_INFO))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V4_OUT_SUCFW_VERSION);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
- le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]),
- le32_to_cpu(ver.dwords[3]));
- devlink_info_version_running_put(req,
- EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC,
- buf);
- }
- }
- static void efx_devlink_info_running_v5(struct efx_nic *efx,
- struct devlink_info_req *req,
- unsigned int flags, efx_dword_t *outbuf)
- {
- char buf[EFX_MAX_VERSION_INFO_LEN];
- union {
- const __le32 *dwords;
- const __le16 *words;
- const char *str;
- } ver;
- if (flags & BIT(EFX_VER_FLAG(BOARD_VERSION))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V5_OUT_BOARD_VERSION);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
- le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]),
- le32_to_cpu(ver.dwords[3]));
- devlink_info_version_running_put(req,
- DEVLINK_INFO_VERSION_GENERIC_BOARD_REV,
- buf);
- }
- if (flags & BIT(EFX_VER_FLAG(BUNDLE_VERSION))) {
- ver.dwords = (__le32 *)MCDI_PTR(outbuf,
- GET_VERSION_V5_OUT_BUNDLE_VERSION);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
- le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]),
- le32_to_cpu(ver.dwords[2]),
- le32_to_cpu(ver.dwords[3]));
- devlink_info_version_running_put(req,
- DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID,
- buf);
- }
- }
- static int efx_devlink_info_running_versions(struct efx_nic *efx,
- struct devlink_info_req *req)
- {
- MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_VERSION_V5_OUT_LEN);
- MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_VERSION_EXT_IN_LEN);
- char buf[EFX_MAX_VERSION_INFO_LEN];
- union {
- const __le32 *dwords;
- const __le16 *words;
- const char *str;
- } ver;
- size_t outlength;
- unsigned int flags;
- int rc;
- rc = efx_mcdi_rpc(efx, MC_CMD_GET_VERSION, inbuf, sizeof(inbuf),
- outbuf, sizeof(outbuf), &outlength);
- if (rc || outlength < MC_CMD_GET_VERSION_OUT_LEN) {
- netif_err(efx, drv, efx->net_dev,
- "mcdi MC_CMD_GET_VERSION failed\n");
- return rc;
- }
- /* Handle previous output */
- if (outlength < MC_CMD_GET_VERSION_V2_OUT_LEN) {
- ver.words = (__le16 *)MCDI_PTR(outbuf,
- GET_VERSION_EXT_OUT_VERSION);
- snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u",
- le16_to_cpu(ver.words[0]),
- le16_to_cpu(ver.words[1]),
- le16_to_cpu(ver.words[2]),
- le16_to_cpu(ver.words[3]));
- devlink_info_version_running_put(req,
- DEVLINK_INFO_VERSION_GENERIC_FW_MGMT,
- buf);
- return 0;
- }
- /* Handle V2 additions */
- flags = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_FLAGS);
- efx_devlink_info_running_v2(efx, req, flags, outbuf);
- if (outlength < MC_CMD_GET_VERSION_V3_OUT_LEN)
- return 0;
- /* Handle V3 additions */
- efx_devlink_info_running_v3(efx, req, flags, outbuf);
- if (outlength < MC_CMD_GET_VERSION_V4_OUT_LEN)
- return 0;
- /* Handle V4 additions */
- efx_devlink_info_running_v4(efx, req, flags, outbuf);
- if (outlength < MC_CMD_GET_VERSION_V5_OUT_LEN)
- return 0;
- /* Handle V5 additions */
- efx_devlink_info_running_v5(efx, req, flags, outbuf);
- return 0;
- }
- #define EFX_MAX_SERIALNUM_LEN (ETH_ALEN * 2 + 1)
- static int efx_devlink_info_board_cfg(struct efx_nic *efx,
- struct devlink_info_req *req)
- {
- char sn[EFX_MAX_SERIALNUM_LEN];
- u8 mac_address[ETH_ALEN];
- int rc;
- rc = efx_mcdi_get_board_cfg(efx, (u8 *)mac_address, NULL, NULL);
- if (!rc) {
- snprintf(sn, EFX_MAX_SERIALNUM_LEN, "%pm", mac_address);
- devlink_info_serial_number_put(req, sn);
- }
- return rc;
- }
- static int efx_devlink_info_get(struct devlink *devlink,
- struct devlink_info_req *req,
- struct netlink_ext_ack *extack)
- {
- struct efx_devlink *devlink_private = devlink_priv(devlink);
- struct efx_nic *efx = devlink_private->efx;
- int err;
- /* Several different MCDI commands are used. We report if errors
- * happened through extack. Specific error information via system
- * messages inside the calls.
- */
- err = efx_devlink_info_board_cfg(efx, req);
- err |= efx_devlink_info_stored_versions(efx, req);
- err |= efx_devlink_info_running_versions(efx, req);
- if (err)
- NL_SET_ERR_MSG_MOD(extack, "Errors when getting device info. Check system messages");
- return 0;
- }
- static const struct devlink_ops sfc_devlink_ops = {
- .info_get = efx_devlink_info_get,
- };
- #ifdef CONFIG_SFC_SRIOV
- static struct devlink_port *ef100_set_devlink_port(struct efx_nic *efx, u32 idx)
- {
- struct mae_mport_desc *mport;
- u32 id;
- int rc;
- if (!efx->mae)
- return NULL;
- if (efx_mae_lookup_mport(efx, idx, &id)) {
- /* This should not happen. */
- if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
- pci_warn_once(efx->pci_dev, "No mport ID found for PF.\n");
- else
- pci_warn_once(efx->pci_dev, "No mport ID found for VF %u.\n",
- idx);
- return NULL;
- }
- mport = efx_mae_get_mport(efx, id);
- if (!mport) {
- /* This should not happen. */
- if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
- pci_warn_once(efx->pci_dev, "No mport found for PF.\n");
- else
- pci_warn_once(efx->pci_dev, "No mport found for VF %u.\n",
- idx);
- return NULL;
- }
- rc = efx_devlink_add_port(efx, mport);
- if (rc) {
- if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
- pci_warn(efx->pci_dev,
- "devlink port creation for PF failed.\n");
- else
- pci_warn(efx->pci_dev,
- "devlink_port creation for VF %u failed.\n",
- idx);
- return NULL;
- }
- return &mport->dl_port;
- }
- void ef100_rep_set_devlink_port(struct efx_rep *efv)
- {
- efv->dl_port = ef100_set_devlink_port(efv->parent, efv->idx);
- }
- void ef100_pf_set_devlink_port(struct efx_nic *efx)
- {
- efx->dl_port = ef100_set_devlink_port(efx, MAE_MPORT_DESC_VF_IDX_NULL);
- }
- void ef100_rep_unset_devlink_port(struct efx_rep *efv)
- {
- efx_devlink_del_port(efv->dl_port);
- }
- void ef100_pf_unset_devlink_port(struct efx_nic *efx)
- {
- efx_devlink_del_port(efx->dl_port);
- }
- #endif
- void efx_fini_devlink_lock(struct efx_nic *efx)
- {
- if (efx->devlink)
- devl_lock(efx->devlink);
- }
- void efx_fini_devlink_and_unlock(struct efx_nic *efx)
- {
- if (efx->devlink) {
- devl_unregister(efx->devlink);
- devl_unlock(efx->devlink);
- devlink_free(efx->devlink);
- efx->devlink = NULL;
- }
- }
- int efx_probe_devlink_and_lock(struct efx_nic *efx)
- {
- struct efx_devlink *devlink_private;
- if (efx->type->is_vf)
- return 0;
- efx->devlink = devlink_alloc(&sfc_devlink_ops,
- sizeof(struct efx_devlink),
- &efx->pci_dev->dev);
- if (!efx->devlink)
- return -ENOMEM;
- devl_lock(efx->devlink);
- devlink_private = devlink_priv(efx->devlink);
- devlink_private->efx = efx;
- devl_register(efx->devlink);
- return 0;
- }
- void efx_probe_devlink_unlock(struct efx_nic *efx)
- {
- if (!efx->devlink)
- return;
- devl_unlock(efx->devlink);
- }
|