summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorWisam Jaddo <wisamm@mellanox.com>2018-10-19 04:07:52 +0200
committerFerruh Yigit <ferruh.yigit@intel.com>2018-10-26 22:14:05 +0200
commitce6959bf793c9e333098f7620cd2427008de0d5f (patch)
treebfa4ae5b10030289146420bf0d6f696f616b214b /app
parent22aeda000ca97da76152a2652a530b5c8dd66395 (diff)
downloaddpdk-ce6959bf793c9e333098f7620cd2427008de0d5f.zip
dpdk-ce6959bf793c9e333098f7620cd2427008de0d5f.tar.gz
dpdk-ce6959bf793c9e333098f7620cd2427008de0d5f.tar.xz
app/testpmd: update port list for multiple removals
When detaching a port, the full rte_device is removed. If the rte_device was hosting several ports, the testpmd list of ports must be updated for multiple removals. Signed-off-by: Wisam Jaddo <wisamm@mellanox.com> Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
Diffstat (limited to 'app')
-rw-r--r--app/test-pmd/testpmd.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index b057365..89fc39c 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2198,6 +2198,31 @@ stop_port(portid_t pid)
printf("Done\n");
}
+static void
+remove_unused_fwd_ports(void)
+{
+ int i;
+ int last_port_idx = nb_ports - 1;
+
+ for (i = 0; i <= last_port_idx; i++) { /* iterate in ports_ids */
+ if (rte_eth_devices[ports_ids[i]].state != RTE_ETH_DEV_UNUSED)
+ continue;
+ /* skip unused ports at the end */
+ while (i <= last_port_idx &&
+ rte_eth_devices[ports_ids[last_port_idx]].state
+ == RTE_ETH_DEV_UNUSED)
+ last_port_idx--;
+ if (last_port_idx < i)
+ break;
+ /* overwrite unused port with last valid port */
+ ports_ids[i] = ports_ids[last_port_idx];
+ /* decrease ports count */
+ last_port_idx--;
+ }
+ nb_ports = rte_eth_dev_count_avail();
+ update_fwd_ports(RTE_MAX_ETHPORTS);
+}
+
void
close_port(portid_t pid)
{
@@ -2327,7 +2352,6 @@ void
detach_port(portid_t port_id)
{
char name[RTE_ETH_NAME_MAX_LEN];
- uint16_t i;
printf("Detaching a port...\n");
@@ -2344,16 +2368,7 @@ detach_port(portid_t port_id)
return;
}
- for (i = 0; i < nb_ports; i++) {
- if (ports_ids[i] == port_id) {
- ports_ids[i] = ports_ids[nb_ports-1];
- ports_ids[nb_ports-1] = 0;
- break;
- }
- }
- nb_ports = rte_eth_dev_count_avail();
-
- update_fwd_ports(RTE_MAX_ETHPORTS);
+ remove_unused_fwd_ports();
printf("Port %u is detached. Now total ports is %d\n",
port_id, nb_ports);