From: Jie Liu <[email protected]>
sxe2_switchdev_repr_match() encodes the kernel representor ID and
compares it against each requested port, which is fragile. Match the
PF number and VF ID directly against the switchdev representor info
instead, and drop the sxe2_switchdev_repr_id_encode_get() helper.
Fixes: 635084db5d ("net/sxe2: support VF representors")
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Jie Liu <[email protected]>
---
drivers/net/sxe2/sxe2_ethdev.c | 68 +++++++++++++++++-----------------
drivers/net/sxe2/sxe2_ethdev.h | 3 --
2 files changed, 33 insertions(+), 38 deletions(-)
diff --git a/drivers/net/sxe2/sxe2_ethdev.c b/drivers/net/sxe2/sxe2_ethdev.c
index 7787f5435e..1dd10cd515 100644
--- a/drivers/net/sxe2/sxe2_ethdev.c
+++ b/drivers/net/sxe2/sxe2_ethdev.c
@@ -2153,42 +2153,25 @@ static int32_t sxe2_fw_version_string_get(struct
rte_eth_dev *dev, char *fw_vers
return ret;
}
-static uint16_t sxe2_switchdev_repr_id_encode_get(struct sxe2_switchdev_info
*switchdev_info)
-{
- enum rte_eth_representor_type type;
- uint16_t repr = switchdev_info->vf_num;
- uint32_t pf = switchdev_info->pf_num;
-
- switch (switchdev_info->port_name_type) {
- case SXE2_PHYS_PORT_NAME_TYPE_UPLINK:
- if (!switchdev_info->representor)
- return UINT16_MAX;
- type = RTE_ETH_REPRESENTOR_PF;
- pf = switchdev_info->mpesw_owner;
- break;
- case SXE2_PHYS_PORT_NAME_TYPE_PFVF:
- default:
- type = RTE_ETH_REPRESENTOR_VF;
- break;
- }
-
- return SXE2_REPRESENTOR_ID(pf, type, repr);
-}
-
static bool sxe2_switchdev_repr_match(struct sxe2_adapter *adapter,
struct rte_eth_devargs *req_eth_da)
{
- uint32_t port_idx = 0;
- uint32_t repr_idx;
- uint16_t kernel_repr_id =
sxe2_switchdev_repr_id_encode_get(&adapter->switchdev_info);
- uint16_t repr_id;
+ uint16_t port_idx = UINT16_MAX;
+ uint16_t repr_idx;
+ uint16_t vf_id;
+ uint16_t i;
switch (req_eth_da->type) {
case RTE_ETH_REPRESENTOR_PF:
+ if (adapter->switchdev_info.port_name_type !=
+ SXE2_PHYS_PORT_NAME_TYPE_UPLINK) {
+ rte_errno = EBUSY;
+ return false;
+ }
break;
case RTE_ETH_REPRESENTOR_VF:
if (adapter->switchdev_info.port_name_type !=
- SXE2_PHYS_PORT_NAME_TYPE_PFVF) {
+ SXE2_PHYS_PORT_NAME_TYPE_PFVF) {
rte_errno = EBUSY;
return false;
}
@@ -2201,15 +2184,30 @@ static bool sxe2_switchdev_repr_match(struct
sxe2_adapter *adapter,
return false;
}
+ for (port_idx = 0; port_idx < req_eth_da->nb_ports; ++port_idx) {
+ if (adapter->switchdev_info.pf_num !=
req_eth_da->ports[port_idx]) {
+ PMD_DEV_LOG_DEBUG(adapter, DRV, "switchdev pf %u not
match req pf %u",
+ adapter->switchdev_info.pf_num,
req_eth_da->ports[port_idx]);
+ rte_errno = EBUSY;
+ return false;
+ }
+ }
+
for (repr_idx = 0; repr_idx < req_eth_da->nb_representor_ports;
++repr_idx) {
- repr_id = SXE2_REPRESENTOR_ID(req_eth_da->ports[port_idx],
- req_eth_da->type,
-
req_eth_da->representor_ports[repr_idx]);
- if (repr_id == kernel_repr_id)
- return true;
- }
- rte_errno = EBUSY;
- return false;
+ for (i = 0; i < adapter->repr_ctxt.nb_vf; ++i) {
+ vf_id =
rte_le_to_cpu_16(adapter->repr_ctxt.repr_vf_id[i].func_id);
+ if (vf_id == req_eth_da->representor_ports[repr_idx])
+ break;
+ }
+ if (i == adapter->repr_ctxt.nb_vf) {
+ PMD_DEV_LOG_DEBUG(adapter, DRV, "switchdev vf %u not
match req vf(cnt:%u)",
+ req_eth_da->representor_ports[repr_idx],
adapter->repr_ctxt.nb_vf);
+ rte_errno = EBUSY;
+ return false;
+ }
+ }
+
+ return true;
}
static int32_t sxe2_eth_pmd_probe_pf(struct sxe2_common_device *cdev,
diff --git a/drivers/net/sxe2/sxe2_ethdev.h b/drivers/net/sxe2/sxe2_ethdev.h
index f2557b28c3..e818578319 100644
--- a/drivers/net/sxe2/sxe2_ethdev.h
+++ b/drivers/net/sxe2/sxe2_ethdev.h
@@ -65,9 +65,6 @@ enum sxe2_fnav_tunnel_flag_type {
#define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16))
#define lower_32_bits(n) ((uint32_t)((n) & 0xffffffff))
-#define SXE2_REPRESENTOR_ID(pf, type, repr) \
- (((pf) << 14) + ((type) << 12) + ((repr) & 0xfff))
-
#define SXE2_I2C_EEPROM_DEV_ADDR 0xA0
#define SXE2_I2C_EEPROM_DEV_ADDR2 0xA2
#define SXE2_MODULE_TYPE_SFP 0x03
--
2.52.0