common/sfc_efx/base: add mport alias MCDI wrappers
[dpdk.git] / drivers / common / sfc_efx / base / efx_nic.c
index dcf0987..9fe0933 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  *
- * Copyright(c) 2019-2020 Xilinx, Inc.
+ * Copyright(c) 2019-2021 Xilinx, Inc.
  * Copyright(c) 2007-2019 Solarflare Communications Inc.
  */
 
@@ -110,6 +110,7 @@ efx_family_probe_bar(
        __in            uint16_t venid,
        __in            uint16_t devid,
        __in            efsys_pci_config_t *espcp,
+       __in            const efx_pci_ops_t *epop,
        __out           efx_family_t *efp,
        __out           efx_bar_region_t *ebrp)
 {
@@ -121,7 +122,7 @@ efx_family_probe_bar(
 #if EFSYS_OPT_RIVERHEAD
                case EFX_PCI_DEVID_RIVERHEAD:
                case EFX_PCI_DEVID_RIVERHEAD_VF:
-                       rc = rhead_pci_nic_membar_lookup(espcp, ebrp);
+                       rc = rhead_pci_nic_membar_lookup(espcp, epop, ebrp);
                        if (rc == 0)
                                *efp = EFX_FAMILY_RIVERHEAD;
 
@@ -790,6 +791,52 @@ efx_nic_get_fw_version(
 
        return (0);
 
+fail3:
+       EFSYS_PROBE(fail3);
+fail2:
+       EFSYS_PROBE(fail2);
+fail1:
+       EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+       return (rc);
+}
+
+       __checkReturn   efx_rc_t
+efx_nic_get_board_info(
+       __in            efx_nic_t *enp,
+       __out           efx_nic_board_info_t *board_infop)
+{
+       efx_mcdi_version_t ver;
+       efx_rc_t rc;
+
+       EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
+       EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
+
+       rc = efx_mcdi_get_version(enp, EFX_MCDI_VERSION_BOARD_INFO, &ver);
+       if (rc == EMSGSIZE) {
+               /*
+                * Typically, EMSGSIZE is returned by above call in the
+                * case when the NIC does not provide extra information.
+                */
+               rc = ENOTSUP;
+               goto fail1;
+       } else if (rc != 0) {
+               goto fail2;
+       }
+
+       if ((ver.emv_flags & EFX_MCDI_VERSION_BOARD_INFO) == 0) {
+               rc = ENOTSUP;
+               goto fail3;
+       }
+
+       memcpy(board_infop, &ver.emv_board_info, sizeof (*board_infop));
+
+       /* MCDI should provide NUL-terminated strings, but stay vigilant. */
+       board_infop->enbi_serial[sizeof (board_infop->enbi_serial) - 1] = '\0';
+       board_infop->enbi_name[sizeof (board_infop->enbi_name) - 1] = '\0';
+
+       return (0);
+
 fail3:
        EFSYS_PROBE(fail3);
 fail2: