summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorThomas Monjalon <thomas@monjalon.net>2018-10-25 17:11:13 +0200
committerFerruh Yigit <ferruh.yigit@intel.com>2018-10-26 22:14:06 +0200
commitf8e5baa2662d2cc89af25e8b077e4a6ae073754a (patch)
treef5fb70e2109bfa9f7d7e37a774eed0e2720d4c2e /app
parentaa1e69aebb12a57038f7ed5664605b7bcccbbe20 (diff)
downloaddpdk-f8e5baa2662d2cc89af25e8b077e4a6ae073754a.zip
dpdk-f8e5baa2662d2cc89af25e8b077e4a6ae073754a.tar.gz
dpdk-f8e5baa2662d2cc89af25e8b077e4a6ae073754a.tar.xz
app/testpmd: check not detaching device twice
The command "port detach" is removing the EAL rte_device of the ethdev port specified as parameter. The function name and some comments are updated to make clear that we are detaching the whole device. After detaching, the pointer, which maps a port to its device, is reset. This way, it is possible to check whether a port is still associated to a (not removed) device. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
Diffstat (limited to 'app')
-rw-r--r--app/test-pmd/cmdline.c2
-rw-r--r--app/test-pmd/testpmd.c35
-rw-r--r--app/test-pmd/testpmd.h2
3 files changed, 30 insertions, 9 deletions
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 4856d23..e350c38 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -1305,7 +1305,7 @@ static void cmd_operate_detach_port_parsed(void *parsed_result,
struct cmd_operate_detach_port_result *res = parsed_result;
if (!strcmp(res->keyword, "detach"))
- detach_port(res->port_id);
+ detach_port_device(res->port_id);
else
printf("Unknown parameter\n");
}
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 70c0822..70d08d7 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2356,10 +2356,19 @@ setup_attached_port(portid_t pi)
}
void
-detach_port(portid_t port_id)
+detach_port_device(portid_t port_id)
{
+ struct rte_device *dev;
+ portid_t sibling;
+
printf("Removing a device...\n");
+ dev = rte_eth_devices[port_id].device;
+ if (dev == NULL) {
+ printf("Device already removed\n");
+ return;
+ }
+
if (ports[port_id].port_status != RTE_PORT_CLOSED) {
if (ports[port_id].port_status != RTE_PORT_STOPPED) {
printf("Port not stopped\n");
@@ -2370,15 +2379,27 @@ detach_port(portid_t port_id)
port_flow_flush(port_id);
}
- if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) {
- TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
+ if (rte_dev_remove(dev) != 0) {
+ TESTPMD_LOG(ERR, "Failed to detach device %s\n", dev->name);
return;
}
+ for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++) {
+ if (rte_eth_devices[sibling].device != dev)
+ continue;
+ /* reset mapping between old ports and removed device */
+ rte_eth_devices[sibling].device = NULL;
+ if (ports[sibling].port_status != RTE_PORT_CLOSED) {
+ /* sibling ports are forced to be closed */
+ ports[sibling].port_status = RTE_PORT_CLOSED;
+ printf("Port %u is closed\n", sibling);
+ }
+ }
+
remove_unused_fwd_ports();
- printf("Port %u is detached. Now total ports is %d\n",
- port_id, nb_ports);
+ printf("Device of port %u is detached\n", port_id);
+ printf("Now total ports is %d\n", nb_ports);
printf("Done\n");
return;
}
@@ -2411,7 +2432,7 @@ pmd_test_exit(void)
*/
device = rte_eth_devices[pt_id].device;
if (device && !strcmp(device->driver->name, "net_virtio_user"))
- detach_port(pt_id);
+ detach_port_device(pt_id);
}
}
@@ -2523,7 +2544,7 @@ rmv_event_callback(void *arg)
stop_port(port_id);
no_link_check = org_no_link_check;
close_port(port_id);
- detach_port(port_id);
+ detach_port_device(port_id);
if (need_to_start)
start_packet_forwarding(0);
}
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index ca2320c..e0f86ee 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -777,7 +777,7 @@ void stop_port(portid_t pid);
void close_port(portid_t pid);
void reset_port(portid_t pid);
void attach_port(char *identifier);
-void detach_port(portid_t port_id);
+void detach_port_device(portid_t port_id);
int all_ports_stopped(void);
int port_is_stopped(portid_t port_id);
int port_is_started(portid_t port_id);