[PATCH v5 04/19] net/tap: replace runtime speed capability with constant

Stephen Hemminger
2026-02-22T17:33:03Z

The TAP/TUN virtual device always operates at 10G. The link speed is
set in the static initializer for pmd_link, so the runtime assignments
in rte_pmd_tap_probe() and rte_pmd_tun_probe() are redundant.

Replace tap_dev_speed_capa(), which dynamically computed speed
capabilities against pmd_link.link_speed, with a compile-time
constant TAP_SPEED_CAPA. Remove the unused 'speed' variable and
redundant assignments.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/tap/rte_eth_tap.c | 48 ++++++-----------------------------
1 file changed, 8 insertions(+), 40 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 08d51c3a45..9dac0eced9 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -891,39 +891,13 @@ tap_dev_configure(struct rte_eth_dev *dev)
return 0;
}

-static uint32_t
-tap_dev_speed_capa(void)
-{
- uint32_t speed = pmd_link.link_speed;
- uint32_t capa = 0;
-
- if (speed >= RTE_ETH_SPEED_NUM_10M)
- capa |= RTE_ETH_LINK_SPEED_10M;
- if (speed >= RTE_ETH_SPEED_NUM_100M)
- capa |= RTE_ETH_LINK_SPEED_100M;
- if (speed >= RTE_ETH_SPEED_NUM_1G)
- capa |= RTE_ETH_LINK_SPEED_1G;
- if (speed >= RTE_ETH_SPEED_NUM_5G)
- capa |= RTE_ETH_LINK_SPEED_2_5G;
- if (speed >= RTE_ETH_SPEED_NUM_5G)
- capa |= RTE_ETH_LINK_SPEED_5G;
- if (speed >= RTE_ETH_SPEED_NUM_10G)
- capa |= RTE_ETH_LINK_SPEED_10G;
- if (speed >= RTE_ETH_SPEED_NUM_20G)
- capa |= RTE_ETH_LINK_SPEED_20G;
- if (speed >= RTE_ETH_SPEED_NUM_25G)
- capa |= RTE_ETH_LINK_SPEED_25G;
- if (speed >= RTE_ETH_SPEED_NUM_40G)
- capa |= RTE_ETH_LINK_SPEED_40G;
- if (speed >= RTE_ETH_SPEED_NUM_50G)
- capa |= RTE_ETH_LINK_SPEED_50G;
- if (speed >= RTE_ETH_SPEED_NUM_56G)
- capa |= RTE_ETH_LINK_SPEED_56G;
- if (speed >= RTE_ETH_SPEED_NUM_100G)
- capa |= RTE_ETH_LINK_SPEED_100G;
-
- return capa;
-}
+/* Speed capabilities for virtual TAP/TUN device (always 10G) */
+#define TAP_SPEED_CAPA (RTE_ETH_LINK_SPEED_10M | \
+ RTE_ETH_LINK_SPEED_100M | \
+ RTE_ETH_LINK_SPEED_1G | \
+ RTE_ETH_LINK_SPEED_2_5G | \
+ RTE_ETH_LINK_SPEED_5G | \
+ RTE_ETH_LINK_SPEED_10G)

static int
tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
@@ -936,7 +910,7 @@ tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
dev_info->max_rx_queues = RTE_PMD_TAP_MAX_QUEUES;
dev_info->max_tx_queues = RTE_PMD_TAP_MAX_QUEUES;
dev_info->min_rx_bufsize = 0;
- dev_info->speed_capa = tap_dev_speed_capa();
+ dev_info->speed_capa = TAP_SPEED_CAPA;
dev_info->rx_queue_offload_capa = TAP_RX_OFFLOAD;
dev_info->rx_offload_capa = dev_info->rx_queue_offload_capa;
dev_info->tx_queue_offload_capa = TAP_TX_OFFLOAD;
@@ -2314,7 +2288,6 @@ set_mac_type(const char *key __rte_unused,
* Open a TUN interface device. TUN PMD
* 1) sets tap_type as false
* 2) intakes iface as argument.
- * 3) as interface is virtual set speed to 10G
*/
static int
rte_pmd_tun_probe(struct rte_vdev_device *dev)
@@ -2362,7 +2335,6 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
}
}
}
- pmd_link.link_speed = RTE_ETH_SPEED_NUM_10G;

TAP_LOG(DEBUG, "Initializing pmd_tun for %s", name);

@@ -2484,7 +2456,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
const char *name, *params;
int ret;
struct rte_kvargs *kvlist = NULL;
- int speed;
char tap_name[IFNAMSIZ];
char remote_iface[IFNAMSIZ];
struct rte_ether_addr user_mac = { .addr_bytes = {0} };
@@ -2534,8 +2505,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
return 0;
}

- speed = RTE_ETH_SPEED_NUM_10G;
-
/* use tap%d which causes kernel to choose next available */
strlcpy(tap_name, DEFAULT_TAP_NAME "%d", IFNAMSIZ);
memset(remote_iface, 0, IFNAMSIZ);
@@ -2576,7 +2545,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
persist = 1;
}
}
- pmd_link.link_speed = speed;

TAP_LOG(DEBUG, "Initializing pmd_tap for %s", name);

--
2.51.0