Skip to content

Commit

Permalink
sfc: add support for devlink port_function_hw_addr_get in ef100
Browse files Browse the repository at this point in the history
Using the builtin client handle id infrastructure, add support for
obtaining the mac address linked to mports in ef100. This implies
to execute an MCDI command for getting the data from the firmware
for each devlink port.

Signed-off-by: Alejandro Lucero <alejandro.lucero-palau@amd.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Acked-by: Martin Habets <habetsm.xilinx@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Alejandro Lucero authored and Paolo Abeni committed Feb 16, 2023
1 parent 7e056e2 commit fa78b01
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
27 changes: 27 additions & 0 deletions drivers/net/ethernet/sfc/ef100_nic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,33 @@ static int ef100_probe_main(struct efx_nic *efx)
return rc;
}

/* MCDI commands are related to the same device issuing them. This function
* allows to do an MCDI command on behalf of another device, mainly PFs setting
* things for VFs.
*/
int efx_ef100_lookup_client_id(struct efx_nic *efx, efx_qword_t pciefn, u32 *id)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLIENT_HANDLE_OUT_LEN);
MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_CLIENT_HANDLE_IN_LEN);
u64 pciefn_flat = le64_to_cpu(pciefn.u64[0]);
size_t outlen;
int rc;

MCDI_SET_DWORD(inbuf, GET_CLIENT_HANDLE_IN_TYPE,
MC_CMD_GET_CLIENT_HANDLE_IN_TYPE_FUNC);
MCDI_SET_QWORD(inbuf, GET_CLIENT_HANDLE_IN_FUNC,
pciefn_flat);

rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLIENT_HANDLE, inbuf, sizeof(inbuf),
outbuf, sizeof(outbuf), &outlen);
if (rc)
return rc;
if (outlen < sizeof(outbuf))
return -EIO;
*id = MCDI_DWORD(outbuf, GET_CLIENT_HANDLE_OUT_HANDLE);
return 0;
}

int ef100_probe_netdev_pf(struct efx_nic *efx)
{
struct ef100_nic_data *nic_data = efx->nic_data;
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/sfc/ef100_nic.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ int ef100_filter_table_probe(struct efx_nic *efx);

int ef100_get_mac_address(struct efx_nic *efx, u8 *mac_address,
int client_handle, bool empty_ok);
int efx_ef100_lookup_client_id(struct efx_nic *efx, efx_qword_t pciefn, u32 *id);
#endif /* EFX_EF100_NIC_H */
8 changes: 8 additions & 0 deletions drivers/net/ethernet/sfc/ef100_rep.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ bool ef100_mport_on_local_intf(struct efx_nic *efx,
mport_desc->interface_idx == nic_data->local_mae_intf;
}

bool ef100_mport_is_vf(struct mae_mport_desc *mport_desc)
{
bool pcie_func;

pcie_func = ef100_mport_is_pcie_vnic(mport_desc);
return pcie_func && (mport_desc->vf_idx != MAE_MPORT_DESC_VF_IDX_NULL);
}

void efx_ef100_init_reps(struct efx_nic *efx)
{
struct ef100_nic_data *nic_data = efx->nic_data;
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/sfc/ef100_rep.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ void efx_ef100_fini_reps(struct efx_nic *efx);
struct mae_mport_desc;
bool ef100_mport_on_local_intf(struct efx_nic *efx,
struct mae_mport_desc *mport_desc);
bool ef100_mport_is_vf(struct mae_mport_desc *mport_desc);
#endif /* EF100_REP_H */
54 changes: 54 additions & 0 deletions drivers/net/ethernet/sfc/efx_devlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include "net_driver.h"
#include "ef100_nic.h"
#include "efx_devlink.h"
#include <linux/rtc.h>
#include "mcdi.h"
Expand Down Expand Up @@ -58,6 +59,56 @@ static int efx_devlink_add_port(struct efx_nic *efx,

return devl_port_register(efx->devlink, &mport->dl_port, mport->mport_id);
}

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;
}

#endif

static int efx_devlink_info_nvram_partition(struct efx_nic *efx,
Expand Down Expand Up @@ -514,6 +565,9 @@ static int efx_devlink_info_get(struct devlink *devlink,

static const struct devlink_ops sfc_devlink_ops = {
.info_get = efx_devlink_info_get,
#ifdef CONFIG_SFC_SRIOV
.port_function_hw_addr_get = efx_devlink_port_addr_get,
#endif
};

#ifdef CONFIG_SFC_SRIOV
Expand Down

0 comments on commit fa78b01

Please sign in to comment.