Skip to content

Commit

Permalink
common/sfc_efx/base: convert EFX PCIe INTF to MCDI value
Browse files Browse the repository at this point in the history
[ upstream commit b85f504 ]

When the driver queries its PCIe interface type via MCDI,
the value from the response is translated to an EFX enum.

When the driver passes this enum value back to any other
MCDI helper, the inverse translation has to be conducted.

Fixes: 1bf9ff5 ("common/sfc_efx/base: allow getting VNIC MCDI client handles")

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
  • Loading branch information
ol-ivanmal authored and kevintraynor committed Jun 8, 2022
1 parent a3f86b4 commit 2400300
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
6 changes: 6 additions & 0 deletions drivers/common/sfc_efx/base/efx_impl.h
Expand Up @@ -1555,6 +1555,12 @@ efx_mcdi_intf_from_pcie(
__in uint32_t pcie_intf,
__out efx_pcie_interface_t *efx_intf);

LIBEFX_INTERNAL
extern __checkReturn efx_rc_t
efx_mcdi_intf_to_pcie(
__in efx_pcie_interface_t efx_intf,
__out uint32_t *pcie_intf);

LIBEFX_INTERNAL
extern __checkReturn efx_rc_t
efx_mcdi_init_evq(
Expand Down
44 changes: 40 additions & 4 deletions drivers/common/sfc_efx/base/efx_mcdi.c
Expand Up @@ -659,13 +659,18 @@ efx_mcdi_get_client_handle(
EFX_MCDI_DECLARE_BUF(payload,
MC_CMD_GET_CLIENT_HANDLE_IN_LEN,
MC_CMD_GET_CLIENT_HANDLE_OUT_LEN);
uint32_t pcie_intf;
efx_rc_t rc;

if (handle == NULL) {
rc = EINVAL;
goto fail1;
}

rc = efx_mcdi_intf_to_pcie(intf, &pcie_intf);
if (rc != 0)
goto fail2;

req.emr_cmd = MC_CMD_GET_CLIENT_HANDLE;
req.emr_in_buf = payload;
req.emr_in_length = MC_CMD_GET_CLIENT_HANDLE_IN_LEN;
Expand All @@ -676,23 +681,25 @@ efx_mcdi_get_client_handle(
MC_CMD_GET_CLIENT_HANDLE_IN_TYPE_FUNC);
MCDI_IN_SET_WORD(req, GET_CLIENT_HANDLE_IN_FUNC_PF, pf);
MCDI_IN_SET_WORD(req, GET_CLIENT_HANDLE_IN_FUNC_VF, vf);
MCDI_IN_SET_DWORD(req, GET_CLIENT_HANDLE_IN_FUNC_INTF, intf);
MCDI_IN_SET_DWORD(req, GET_CLIENT_HANDLE_IN_FUNC_INTF, pcie_intf);

efx_mcdi_execute(enp, &req);

if (req.emr_rc != 0) {
rc = req.emr_rc;
goto fail2;
goto fail3;
}

if (req.emr_out_length_used < MC_CMD_GET_CLIENT_HANDLE_OUT_LEN) {
rc = EMSGSIZE;
goto fail3;
goto fail4;
}

*handle = MCDI_OUT_DWORD(req, GET_CLIENT_HANDLE_OUT_HANDLE);

return 0;
fail4:
EFSYS_PROBE(fail4);
fail3:
EFSYS_PROBE(fail3);
fail2:
Expand All @@ -709,7 +716,7 @@ efx_mcdi_get_own_client_handle(
{
efx_rc_t rc;

rc = efx_mcdi_get_client_handle(enp, PCIE_INTERFACE_CALLER,
rc = efx_mcdi_get_client_handle(enp, EFX_PCIE_INTERFACE_CALLER,
PCIE_FUNCTION_PF_NULL, PCIE_FUNCTION_VF_NULL, handle);
if (rc != 0)
goto fail1;
Expand Down Expand Up @@ -2233,6 +2240,35 @@ efx_mcdi_intf_from_pcie(
return (rc);
}

__checkReturn efx_rc_t
efx_mcdi_intf_to_pcie(
__in efx_pcie_interface_t efx_intf,
__out uint32_t *pcie_intf)
{
efx_rc_t rc;

switch (efx_intf) {
case EFX_PCIE_INTERFACE_CALLER:
*pcie_intf = PCIE_INTERFACE_CALLER;
break;
case EFX_PCIE_INTERFACE_HOST_PRIMARY:
*pcie_intf = PCIE_INTERFACE_HOST_PRIMARY;
break;
case EFX_PCIE_INTERFACE_NIC_EMBEDDED:
*pcie_intf = PCIE_INTERFACE_NIC_EMBEDDED;
break;
default:
rc = EINVAL;
goto fail1;
}

return (0);

fail1:
EFSYS_PROBE1(fail1, efx_rc_t, rc);
return (rc);
}

/*
* This function returns the pf and vf number of a function. If it is a pf the
* vf number is 0xffff. The vf number is the index of the vf on that
Expand Down

0 comments on commit 2400300

Please sign in to comment.