aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/dpdk/device
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-01-09 13:13:13 +0100
committerFlorin Coras <florin.coras@gmail.com>2022-01-09 20:32:54 +0000
commit71635fda0dcbbb21ec3eb7af9618eb51513b8ab8 (patch)
tree3dd1d270896117200896ee856ed7813464119e2f /src/plugins/dpdk/device
parent9d33cfc0bc1928f0b4c8aa95c170cf91ee8011a0 (diff)
dpdk: port type code cleanup
Type: improvement Change-Id: I4ead18dee249a27b4dbb8bbf53b6238d91042890 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/plugins/dpdk/device')
-rw-r--r--src/plugins/dpdk/device/dpdk.h45
-rw-r--r--src/plugins/dpdk/device/format.c80
-rw-r--r--src/plugins/dpdk/device/init.c2
3 files changed, 34 insertions, 93 deletions
diff --git a/src/plugins/dpdk/device/dpdk.h b/src/plugins/dpdk/device/dpdk.h
index ff2bf6f9c50..4981d250ea6 100644
--- a/src/plugins/dpdk/device/dpdk.h
+++ b/src/plugins/dpdk/device/dpdk.h
@@ -90,26 +90,32 @@ typedef enum
VNET_DPDK_PMD_UNKNOWN, /* must be last */
} dpdk_pmd_t;
+#define forach_dpdk_port_type \
+ _ (ETH_1G, "GigabitEthernet") \
+ _ (ETH_2_5G, "Two_FiveGigabitEthernet") \
+ _ (ETH_5G, "FiveGigabitEthernet") \
+ _ (ETH_10G, "TenGigabitEthernet") \
+ _ (ETH_20G, "TwentyGigabitEthernet") \
+ _ (ETH_25G, "TwentyFiveGigabitEthernet") \
+ _ (ETH_40G, "FortyGigabitEthernet") \
+ _ (ETH_50G, "FiftyGigabitEthernet") \
+ _ (ETH_56G, "FiftySixGigabitEthernet") \
+ _ (ETH_100G, "HundredGigabitEthernet") \
+ _ (ETH_200G, "TwoHundredGigabitEthernet") \
+ _ (ETH_SWITCH, "EthernetSwitch") \
+ _ (ETH_VF, "VirtualFunctionEthernet") \
+ _ (AF_PACKET, "af_packet") \
+ _ (VIRTIO_USER, "VirtioUser") \
+ _ (VHOST_ETHER, "VhostEthernet") \
+ _ (FAILSAFE, "FailsafeEthernet") \
+ _ (NETVSC, "NetVSC")
+
typedef enum
{
- VNET_DPDK_PORT_TYPE_ETH_1G,
- VNET_DPDK_PORT_TYPE_ETH_2_5G,
- VNET_DPDK_PORT_TYPE_ETH_5G,
- VNET_DPDK_PORT_TYPE_ETH_10G,
- VNET_DPDK_PORT_TYPE_ETH_20G,
- VNET_DPDK_PORT_TYPE_ETH_25G,
- VNET_DPDK_PORT_TYPE_ETH_40G,
- VNET_DPDK_PORT_TYPE_ETH_50G,
- VNET_DPDK_PORT_TYPE_ETH_56G,
- VNET_DPDK_PORT_TYPE_ETH_100G,
- VNET_DPDK_PORT_TYPE_ETH_SWITCH,
- VNET_DPDK_PORT_TYPE_AF_PACKET,
- VNET_DPDK_PORT_TYPE_ETH_VF,
- VNET_DPDK_PORT_TYPE_VIRTIO_USER,
- VNET_DPDK_PORT_TYPE_VHOST_ETHER,
- VNET_DPDK_PORT_TYPE_FAILSAFE,
- VNET_DPDK_PORT_TYPE_NETVSC,
- VNET_DPDK_PORT_TYPE_UNKNOWN,
+ VNET_DPDK_PORT_TYPE_UNKNOWN = 0,
+#define _(n, s) VNET_DPDK_PORT_TYPE_##n,
+ forach_dpdk_port_type
+#undef _
} dpdk_port_type_t;
typedef uint16_t dpdk_portid_t;
@@ -225,9 +231,6 @@ typedef struct
u32 parked_loop_count;
struct rte_flow_error last_flow_error;
- /* af_packet instance number */
- u16 af_packet_instance_num;
-
struct rte_eth_link link;
f64 time_last_link_update;
diff --git a/src/plugins/dpdk/device/format.c b/src/plugins/dpdk/device/format.c
index 24ec7f0bfb4..efb2216f225 100644
--- a/src/plugins/dpdk/device/format.c
+++ b/src/plugins/dpdk/device/format.c
@@ -120,12 +120,18 @@
#define foreach_dpdk_pkt_dyn_rx_offload_flag \
_ (RX_TIMESTAMP, 0, "Timestamp field is valid")
+static char *device_name_by_port_type[] = {
+#define _(n, s) [VNET_DPDK_PORT_TYPE_##n] = (s),
+ forach_dpdk_port_type
+#undef _
+};
+
u8 *
format_dpdk_device_name (u8 * s, va_list * args)
{
dpdk_main_t *dm = &dpdk_main;
char *devname_format;
- char *device_name;
+ char *device_name = 0;
u32 i = va_arg (*args, u32);
dpdk_device_t *xd = vec_elt_at_index (dm->devices, i);
struct rte_eth_dev_info dev_info;
@@ -140,76 +146,10 @@ format_dpdk_device_name (u8 * s, va_list * args)
else
devname_format = "%s%x/%x/%x";
- switch (xd->port_type)
- {
- case VNET_DPDK_PORT_TYPE_ETH_1G:
- device_name = "GigabitEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_2_5G:
- device_name = "Two_FiveGigabitEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_5G:
- device_name = "FiveGigabitEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_10G:
- device_name = "TenGigabitEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_20G:
- device_name = "TwentyGigabitEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_25G:
- device_name = "TwentyFiveGigabitEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_40G:
- device_name = "FortyGigabitEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_50G:
- device_name = "FiftyGigabitEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_56G:
- device_name = "FiftySixGigabitEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_100G:
- device_name = "HundredGigabitEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_SWITCH:
- device_name = "EthernetSwitch";
- break;
-
- case VNET_DPDK_PORT_TYPE_ETH_VF:
- device_name = "VirtualFunctionEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_AF_PACKET:
- return format (s, "af_packet%d", xd->af_packet_instance_num);
+ if (xd->port_type < ARRAY_LEN (device_name_by_port_type))
+ device_name = device_name_by_port_type[xd->port_type];
- case VNET_DPDK_PORT_TYPE_VIRTIO_USER:
- device_name = "VirtioUser";
- break;
-
- case VNET_DPDK_PORT_TYPE_VHOST_ETHER:
- device_name = "VhostEthernet";
- break;
-
- case VNET_DPDK_PORT_TYPE_FAILSAFE:
- device_name = "FailsafeEthernet";
- break;
-
- default:
- case VNET_DPDK_PORT_TYPE_UNKNOWN:
- device_name = "UnknownEthernet";
- break;
- }
+ device_name = device_name ? device_name : "UnknownEthernet";
rte_eth_dev_info_get (xd->port_id, &dev_info);
pci_dev = dpdk_get_pci_device (&dev_info);
diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c
index 8a466a0169f..71c3bfac75e 100644
--- a/src/plugins/dpdk/device/init.c
+++ b/src/plugins/dpdk/device/init.c
@@ -184,7 +184,6 @@ dpdk_lib_init (dpdk_main_t * dm)
dpdk_device_t *xd;
vlib_pci_addr_t last_pci_addr;
u32 last_pci_addr_port = 0;
- u8 af_packet_instance_num = 0;
last_pci_addr.as_u32 = ~0;
nports = rte_eth_dev_count_avail ();
@@ -599,7 +598,6 @@ dpdk_lib_init (dpdk_main_t * dm)
case VNET_DPDK_PMD_AF_PACKET:
xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET;
- xd->af_packet_instance_num = af_packet_instance_num++;
break;
case VNET_DPDK_PMD_VIRTIO_USER: