[PATCH 22/46] common/sfc_efx/base: obtain assigned netport handle from NIC

Ivan Malov ivan.malov at arknetworks.am
Wed Apr 16 15:59:52 CEST 2025


Get an 'assigned' netport handle for the current MCDI entity.
This handle will be used when sending other netport commands.

Signed-off-by: Ivan Malov <ivan.malov at arknetworks.am>
Reviewed-by: Andy Moreton <andy.moreton at amd.com>
Reviewed-by: Pieter Jansen Van Vuuren <pieter.jansen-van-vuuren at amd.com>
---
 drivers/common/sfc_efx/base/efx_impl.h |  4 +++
 drivers/common/sfc_efx/base/efx_np.c   | 50 ++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h
index 9ad973ded7..4952f45121 100644
--- a/drivers/common/sfc_efx/base/efx_impl.h
+++ b/drivers/common/sfc_efx/base/efx_impl.h
@@ -335,6 +335,8 @@ typedef struct efx_virtio_ops_s {
 } efx_virtio_ops_t;
 #endif /* EFSYS_OPT_VIRTIO */
 
+typedef uint32_t efx_np_handle_t;
+
 typedef struct efx_port_s {
 	efx_mac_type_t		ep_mac_type;
 	uint32_t		ep_phy_type;
@@ -378,6 +380,8 @@ typedef struct efx_port_s {
 #endif
 	const efx_mac_ops_t	*ep_emop;
 	const efx_phy_ops_t	*ep_epop;
+
+	efx_np_handle_t		ep_np_handle;
 } efx_port_t;
 
 typedef struct efx_mon_ops_s {
diff --git a/drivers/common/sfc_efx/base/efx_np.c b/drivers/common/sfc_efx/base/efx_np.c
index 3200bc0a90..ec6a432623 100644
--- a/drivers/common/sfc_efx/base/efx_np.c
+++ b/drivers/common/sfc_efx/base/efx_np.c
@@ -41,12 +41,53 @@ efx_np_assign_legacy_props(
 	encp->enc_port = 0;
 }
 
+static	__checkReturn		efx_rc_t
+efx_np_get_assigned_handle(
+	__in			efx_nic_t *enp,
+	__out			efx_np_handle_t *nphp)
+{
+	EFX_MCDI_DECLARE_BUF(payload,
+	    MC_CMD_GET_ASSIGNED_PORT_HANDLE_IN_LEN,
+	    MC_CMD_GET_ASSIGNED_PORT_HANDLE_OUT_LEN);
+	efx_mcdi_req_t req;
+	efx_rc_t rc;
+
+	req.emr_out_length = MC_CMD_GET_ASSIGNED_PORT_HANDLE_OUT_LEN;
+	req.emr_in_length = MC_CMD_GET_ASSIGNED_PORT_HANDLE_IN_LEN;
+	req.emr_cmd = MC_CMD_GET_ASSIGNED_PORT_HANDLE;
+	req.emr_out_buf = payload;
+	req.emr_in_buf = payload;
+
+	efx_mcdi_execute(enp, &req);
+
+	if (req.emr_rc != 0) {
+		rc = req.emr_rc;
+		goto fail1;
+	}
+
+	if (req.emr_out_length_used < MC_CMD_GET_ASSIGNED_PORT_HANDLE_OUT_LEN) {
+		rc = EMSGSIZE;
+		goto fail2;
+	}
+
+	*nphp = MCDI_OUT_DWORD(req, GET_ASSIGNED_PORT_HANDLE_OUT_PORT_HANDLE);
+	return (0);
+
+fail2:
+	EFSYS_PROBE(fail2);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+	return (rc);
+}
+
 	__checkReturn	efx_rc_t
 efx_np_attach(
 	__in		efx_nic_t *enp)
 {
 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
 	efx_port_t *epp = &(enp->en_port);
+	efx_rc_t rc;
 
 	if (efx_np_supported(enp) == B_FALSE)
 		return (0);
@@ -63,7 +104,16 @@ efx_np_attach(
 
 	epp->ep_fixed_port_type = EFX_PHY_MEDIA_INVALID;
 	epp->ep_module_type = EFX_PHY_MEDIA_INVALID;
+
+	rc = efx_np_get_assigned_handle(enp, &epp->ep_np_handle);
+	if (rc != 0)
+		goto fail1;
+
 	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+	return (rc);
 }
 
 		void
-- 
2.39.5



More information about the dev mailing list