All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Subject: [PATCH 12/12] net/failsafe: support device removal
Date: Fri,  3 Mar 2017 16:40:34 +0100	[thread overview]
Message-ID: <e41723daf81b2c369e5aa4cbf400aad878c71f03.1488550982.git.gaetan.rivet@6wind.com> (raw)
In-Reply-To: <cover.1488550982.git.gaetan.rivet@6wind.com>

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Acked-by: Olga Shern <olgas@mellanox.com>
---
 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 <unistd.h>
 
+#include <rte_alarm.h>
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
 
@@ -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

  parent reply	other threads:[~2017-03-03 15:40 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-03 15:40 [PATCH 00/12] introduce fail-safe PMD Gaetan Rivet
2017-03-03 15:40 ` [PATCH 01/12] ethdev: save VLAN filter setting Gaetan Rivet
2017-03-03 17:33   ` Stephen Hemminger
2017-03-03 15:40 ` [PATCH 02/12] ethdev: add flow API rule copy function Gaetan Rivet
2017-03-03 15:40 ` [PATCH 03/12] ethdev: add deferred intermediate device state Gaetan Rivet
2017-03-03 17:34   ` Stephen Hemminger
2017-03-03 15:40 ` [PATCH 04/12] pci: expose device detach routine Gaetan Rivet
2017-03-03 15:40 ` [PATCH 05/12] pci: expose parse and probe routines Gaetan Rivet
2017-03-03 15:40 ` [PATCH 06/12] net/failsafe: add fail-safe PMD Gaetan Rivet
2017-03-03 17:38   ` Stephen Hemminger
2017-03-06 14:19     ` Gaëtan Rivet
2017-03-03 15:40 ` [PATCH 07/12] net/failsafe: add plug-in support Gaetan Rivet
2017-03-03 15:40 ` [PATCH 08/12] net/failsafe: add flexible device definition Gaetan Rivet
2017-03-03 15:40 ` [PATCH 09/12] net/failsafe: support flow API Gaetan Rivet
2017-03-03 15:40 ` [PATCH 10/12] net/failsafe: support offload capabilities Gaetan Rivet
2017-03-03 15:40 ` [PATCH 11/12] net/failsafe: add fast burst functions Gaetan Rivet
2017-03-03 15:40 ` Gaetan Rivet [this message]
2017-03-03 16:14 ` [PATCH 00/12] introduce fail-safe PMD Bruce Richardson
2017-03-06 13:53   ` Gaëtan Rivet
2017-03-03 17:27 ` Stephen Hemminger
2017-03-08 15:15 ` [PATCH v2 00/13] " Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 01/13] ethdev: save VLAN filter setting Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 02/13] ethdev: add flow API rule copy function Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 03/13] ethdev: add deferred intermediate device state Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 04/13] pci: expose device detach routine Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 05/13] pci: expose parse and probe routines Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 06/13] net/failsafe: add fail-safe PMD Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 07/13] net/failsafe: add plug-in support Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 08/13] net/failsafe: add flexible device definition Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 09/13] net/failsafe: support flow API Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 10/13] net/failsafe: support offload capabilities Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 11/13] net/failsafe: add fast burst functions Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 12/13] net/failsafe: support device removal Gaetan Rivet
2017-03-08 15:15   ` [PATCH v2 13/13] net/failsafe: support link status change event Gaetan Rivet
2017-03-08 16:54   ` [PATCH v2 00/13] introduce fail-safe PMD Neil Horman
2017-03-09  9:15     ` Bruce Richardson
2017-03-10  9:13       ` Gaëtan Rivet
2017-03-10 22:43         ` Neil Horman
2017-03-14 14:49           ` Gaëtan Rivet
2017-03-15  3:28             ` Bruce Richardson
2017-03-15 11:15               ` Thomas Monjalon
2017-03-15 14:25                 ` Gaëtan Rivet
2017-03-16 20:50                   ` Neil Horman
2017-03-17 10:56                     ` Gaëtan Rivet
2017-03-18 19:51                       ` Neil Horman
2017-03-20 15:00   ` Thomas Monjalon
2017-05-17 12:50     ` Ferruh Yigit
2017-05-17 16:59       ` Gaëtan Rivet
2017-03-23 13:01   ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e41723daf81b2c369e5aa4cbf400aad878c71f03.1488550982.git.gaetan.rivet@6wind.com \
    --to=gaetan.rivet@6wind.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.