From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by dpdk.org (Postfix) with ESMTP id 9FC8AF972 for ; Fri, 3 Mar 2017 16:40:56 +0100 (CET) Received: by mail-wm0-f54.google.com with SMTP id v186so18308877wmd.0 for ; Fri, 03 Mar 2017 07:40:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=anMcFyNYQnsuPSQBVhNhUVIgSpPxYkJ5vdJQtIgxURo=; b=0M+rfJ6LjkK68mUpp+Gl9I2u7EnkS+GMTteYKHCZVOpTnvS9vrGskDRuU+jyvmEQwB 7QV/s5quLfL+zpin2KYDfVXnhnZEbyUXH+QbojtDJcrAjQR0RG7AB70JKDTIWjlj87pc keNC1pGOYJzMr6cg0CeN7or07RH7pOV7hb6K1xJKmN1KQWtpqwSRE8H62loQYCzrJYnX Jb8Lgl55xxLhViFJnF9Uc/ArezJ0LA7IT8MMTMsTmAzMdcXfRzWQ6mdv/MPRlWEMIHgo ieRt+J24+jkYERsEVthH8wyALHWXTNkbDBVo/trB8tYAE/WTb91kZ0Uof8r155qfDm1u jEbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=anMcFyNYQnsuPSQBVhNhUVIgSpPxYkJ5vdJQtIgxURo=; b=drjc0676tnLdDUpJHjRtBYgBvhxAYvX82C6aDnMiMpcFqapjNViOvdXX2sVTRhff+d tOMkVmTg6M10VfOVLmv9zY0QTSN4n0Gv9BOafxWqmnZAq3TasLjxhMpeEkyuqucGtCuR 3ZlP+traqgTmFHK8BJN6JbrzFEvKq48aT+aJWM78E+l/+aa6We+LMVggtid0PWQFryPW 7JZn++jSs63r0SLBrNSb8j63pCwxug+na7txoGtQpJbDhDQn3VLJZ8yDtl588O88g1Yu /fwXr6qolxtuGF/nqasttUrx0MMGpxOVG2dvcSyBoPe0gc8rRyWhqVW5fR3D45k/FEMo /7zw== X-Gm-Message-State: AMke39kkIv9b8hdB4h4kySZLKhB0WJzcW6mdH0tupdEFwGzwQWr4l95wvIxtRw1mSWDiBAz7 X-Received: by 10.28.147.147 with SMTP id v141mr3922774wmd.110.1488555656194; Fri, 03 Mar 2017 07:40:56 -0800 (PST) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id 63sm3486280wmp.9.2017.03.03.07.40.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Mar 2017 07:40:55 -0800 (PST) From: Gaetan Rivet To: dev@dpdk.org Date: Fri, 3 Mar 2017 16:40:34 +0100 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 12/12] net/failsafe: support device removal X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Mar 2017 15:40:57 -0000 Signed-off-by: Gaetan Rivet Acked-by: Olga Shern --- drivers/net/failsafe/failsafe_args.c | 22 ++++++++++++ drivers/net/failsafe/failsafe_eal.c | 2 ++ drivers/net/failsafe/failsafe_ether.c | 62 +++++++++++++++++++++++++++++++-- drivers/net/failsafe/failsafe_ops.c | 17 +++++++++ drivers/net/failsafe/failsafe_private.h | 7 ++++ 5 files changed, 108 insertions(+), 2 deletions(-) diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c index 839831f..62033c4 100644 --- a/drivers/net/failsafe/failsafe_args.c +++ b/drivers/net/failsafe/failsafe_args.c @@ -462,6 +462,26 @@ failsafe_args_count_subdevice(struct rte_eth_dev *dev, dev, params); } +static int +parse_sub_device(struct sub_device *sdev) +{ + struct rte_devargs *da; + char params[DEVARGS_MAXLEN] = ""; + + da = &sdev->devargs; + if (da->type == RTE_DEVTYPE_VIRTUAL) + snprintf(params, sizeof(params) - 1, + "%s,%s", da->virt.drv_name, da->args); + else + snprintf(params, sizeof(params) - 1, + PCI_PRI_FMT ",%s", + da->pci.addr.domain, da->pci.addr.bus, + da->pci.addr.devid, da->pci.addr.function, + da->args); + + return parse_device(sdev, params); +} + int failsafe_args_parse_subs(struct rte_eth_dev *dev) { @@ -474,6 +494,8 @@ failsafe_args_parse_subs(struct rte_eth_dev *dev) continue; if (sdev->cmdline) ret = execute_cmd(sdev, sdev->cmdline); + else + ret = parse_sub_device(sdev); if (ret == 0) sdev->state = DEV_PARSED; } diff --git a/drivers/net/failsafe/failsafe_eal.c b/drivers/net/failsafe/failsafe_eal.c index 9817fc9..8bb8d45 100644 --- a/drivers/net/failsafe/failsafe_eal.c +++ b/drivers/net/failsafe/failsafe_eal.c @@ -140,6 +140,7 @@ dev_init(struct rte_eth_dev *dev) } ETH(sdev)->state = RTE_ETH_DEV_DEFERRED; SUB_ID(sdev) = i; + sdev->fs_dev = dev; sdev->state = DEV_PROBED; } } @@ -191,6 +192,7 @@ pci_probe(struct rte_eth_dev *dev) } ETH(sdev)->state = RTE_ETH_DEV_DEFERRED; SUB_ID(sdev) = i; + sdev->fs_dev = dev; sdev->state = DEV_PROBED; } } diff --git a/drivers/net/failsafe/failsafe_ether.c b/drivers/net/failsafe/failsafe_ether.c index 439e02c..2f05de5 100644 --- a/drivers/net/failsafe/failsafe_ether.c +++ b/drivers/net/failsafe/failsafe_ether.c @@ -33,6 +33,7 @@ #include +#include #include #include @@ -256,6 +257,43 @@ eth_dev_conf_apply(struct rte_eth_dev *dev, return 0; } +static void +fs_dev_remove(void *arg) +{ + struct sub_device *sdev = arg; + struct rte_devargs *da; + struct rte_pci_device *pdev; + enum dev_state state; + + state = sdev->state; + sdev->state = DEV_UNDEFINED; + fs_switch_dev(sdev->fs_dev); + switch (state) { + case DEV_STARTED: + rte_eth_dev_stop(PORT_ID(sdev)); + /* fallthrough */ + case DEV_ACTIVE: + rte_eth_dev_close(PORT_ID(sdev)); + /* fallthrough */ + case DEV_PROBED: + da = &sdev->devargs; + if (da->type == RTE_DEVTYPE_WHITELISTED_PCI) { + pdev = &sdev->pci_device; + rte_eal_pci_detach_all_drivers(pdev); + } else if (da->type == RTE_DEVTYPE_VIRTUAL) { + rte_eal_vdev_uninit(da->virt.drv_name); + } + sdev->eth_dev->state = RTE_ETH_DEV_UNUSED; + /* fallthrough */ + case DEV_SCANNED: + case DEV_PARSED: + case DEV_UNDEFINED: + /* the end */ + break; + } + failsafe_plugin_alarm_install(sdev->fs_dev); +} + int failsafe_eth_dev_state_sync(struct rte_eth_dev *dev) { @@ -291,12 +329,13 @@ failsafe_eth_dev_state_sync(struct rte_eth_dev *dev) if (ret) { ERROR("Could not apply configuration to sub_device %d", i); - /* TODO: disable device */ + fs_dev_remove(sdev); return ret; } } } - /* If new devices have been configured, check if + /* + * If new devices have been configured, check if * the link state has changed. */ if (inactive) @@ -308,3 +347,22 @@ failsafe_eth_dev_state_sync(struct rte_eth_dev *dev) return ret; return 0; } + +void +failsafe_eth_rmv_event_callback(uint8_t port_id __rte_unused, + enum rte_eth_event_type type, + void *arg) +{ + if (type != RTE_ETH_EVENT_INTR_RMV) { + ERROR("Incorrect event"); + return; + } + /* + * Async removal, the sub-PMD will try to unregister + * the callback at the source of the current thread context. + */ + if (rte_eal_alarm_set(FAILSAFE_PLUGOUT_ASYNC_RESCHED_US, + fs_dev_remove, + arg)) + ERROR("Could not set up deferred sub_device removal"); +} diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c index 0ed49b2..c2524c7 100644 --- a/drivers/net/failsafe/failsafe_ops.c +++ b/drivers/net/failsafe/failsafe_ops.c @@ -198,8 +198,19 @@ fs_dev_configure(struct rte_eth_dev *dev) } } FOREACH_SUBDEV(sdev, i, dev) { + int rmv_interrupt = 0; + if (sdev->state != DEV_PROBED) continue; + + rmv_interrupt = ETH(sdev)->data->dev_flags & + RTE_ETH_DEV_INTR_RMV; + if (rmv_interrupt) { + DEBUG("Enabling RMV interrupts for sub_device %d", i); + dev->data->dev_conf.intr_conf.rmv = 1; + } else { + DEBUG("sub_device %d does not support RMV event", i); + } DEBUG("Configuring sub-device %d", i); ret = rte_eth_dev_configure(PORT_ID(sdev), dev->data->nb_rx_queues, @@ -209,6 +220,12 @@ fs_dev_configure(struct rte_eth_dev *dev) ERROR("Could not configure sub_device %d", i); return ret; } + if (rmv_interrupt) + rte_eth_dev_callback_register(PORT_ID(sdev), + RTE_ETH_EVENT_INTR_RMV, + failsafe_eth_rmv_event_callback, + sdev); + dev->data->dev_conf.intr_conf.rmv = 0; sdev->state = DEV_ACTIVE; } if (PRIV(dev)->state < DEV_ACTIVE) diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h index db7ce93..fcaccc3 100644 --- a/drivers/net/failsafe/failsafe_private.h +++ b/drivers/net/failsafe/failsafe_private.h @@ -53,6 +53,7 @@ "" #define FAILSAFE_PLUGIN_DEFAULT_TIMEOUT_MS 2000 +#define FAILSAFE_PLUGOUT_ASYNC_RESCHED_US 100000 #define FAILSAFE_MAX_ETHPORTS (RTE_MAX_ETHPORTS - 1) #define FAILSAFE_MAX_ETHADDR 128 @@ -110,6 +111,9 @@ struct sub_device { /* Some device are defined as a command line */ char *cmdline; + + /* fail-safe device backreference */ + struct rte_eth_dev *fs_dev; }; struct fs_priv { @@ -175,6 +179,9 @@ int failsafe_eal_uninit(struct rte_eth_dev *dev); /* ETH_DEV */ int failsafe_eth_dev_state_sync(struct rte_eth_dev *dev); +void failsafe_eth_rmv_event_callback(uint8_t port_id, + enum rte_eth_event_type type, + void *arg); /* GLOBALS */ -- 2.1.4