From: Gaetan Rivet Date: Tue, 18 Apr 2017 12:17:42 +0000 (+0200) Subject: app/testpmd: request device removal interrupt X-Git-Tag: spdx-start~3434 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=284c908cc588e6448e25199773aea998c7cccd78;p=dpdk.git app/testpmd: request device removal interrupt Enable device removal event for PMD supporting it. Add the --no-rmv-interrupt parameter to explicitly disable it. Signed-off-by: Gaetan Rivet Signed-off-by: Elad Persiko --- diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index e3499cd400..73da65a9a8 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -201,6 +201,7 @@ usage(char* progname) printf(" --disable-link-check: disable check on link status when " "starting/stopping ports.\n"); printf(" --no-lsc-interrupt: disable link status change interrupt.\n"); + printf(" --no-rmv-interrupt: disable device removal interrupt."); } #ifdef RTE_LIBRTE_CMDLINE @@ -570,6 +571,7 @@ launch_args_parse(int argc, char** argv) { "txpkts", 1, 0, 0 }, { "disable-link-check", 0, 0, 0 }, { "no-lsc-interrupt", 0, 0, 0 }, + { "no-rmv-interrupt", 0, 0, 0 }, { 0, 0, 0, 0 }, }; @@ -1002,6 +1004,8 @@ launch_args_parse(int argc, char** argv) no_link_check = 1; if (!strcmp(lgopts[opt_idx].name, "no-lsc-interrupt")) lsc_interrupt = 0; + if (!strcmp(lgopts[opt_idx].name, "no-rmv-interrupt")) + rmv_interrupt = 0; break; case 'h': diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index f1325ce9ae..a05a36391c 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -275,6 +276,11 @@ uint8_t no_link_check = 0; /* check by default */ */ uint8_t lsc_interrupt = 1; /* enabled by default */ +/* + * Enable device removal notification. + */ +uint8_t rmv_interrupt = 1; /* enabled by default */ + /* * NIC bypass mode configuration options. */ @@ -1757,6 +1763,29 @@ check_all_ports_link_status(uint32_t port_mask) } } +static void +rmv_event_callback(void *arg) +{ + struct rte_eth_dev *dev; + struct rte_devargs *da; + char name[32] = ""; + uint8_t port_id = (intptr_t)arg; + + RTE_ETH_VALID_PORTID_OR_RET(port_id); + dev = &rte_eth_devices[port_id]; + da = dev->device->devargs; + + stop_port(port_id); + close_port(port_id); + if (da->type == RTE_DEVTYPE_VIRTUAL) + snprintf(name, sizeof(name), "%s", da->virt.drv_name); + else if (da->type == RTE_DEVTYPE_WHITELISTED_PCI) + rte_eal_pci_device_name(&da->pci.addr, name, sizeof(name)); + printf("removing device %s\n", name); + rte_eal_dev_detach(name); + dev->state = RTE_ETH_DEV_UNUSED; +} + /* This function is used by the interrupt thread */ static void eth_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param) @@ -1783,6 +1812,16 @@ eth_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param) event_desc[type]); fflush(stdout); } + + switch (type) { + case RTE_ETH_EVENT_INTR_RMV: + if (rte_eal_alarm_set(100000, + rmv_event_callback, (void *)(intptr_t)port_id)) + fprintf(stderr, "Could not set up deferred device removal\n"); + break; + default: + break; + } } static int @@ -1942,6 +1981,10 @@ init_port_config(void) (rte_eth_devices[pid].data->dev_flags & RTE_ETH_DEV_INTR_LSC)) port->dev_conf.intr_conf.lsc = 1; + if (rmv_interrupt && + (rte_eth_devices[pid].data->dev_flags & + RTE_ETH_DEV_INTR_RMV)) + port->dev_conf.intr_conf.rmv = 1; } } diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 62f89e6bc3..a9ff07e5d5 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -306,6 +306,7 @@ extern uint8_t mp_anon; /**< set by "--mp-anon" parameter */ extern uint8_t no_link_check; /**