[spp] [PATCH v2 4/6] shared: add dev_detach_by_port_id
x-fn-spp at sl.ntt-tx.co.jp
x-fn-spp at sl.ntt-tx.co.jp
Wed Nov 21 07:52:17 CET 2018
From: Hideyuki Yamashita <yamashita.hideyuki at po.ntt-tx.co.jp>
SPP uses deprecated APIs removed in DPDK v18.11. Using rte_eth_hotplug_remove()
is recommended instead of rte_eth_dev_detach()[1]. This patch is to add
dev_detach_by_port_id() to shared directory so that spp_primary, spp_nfv,
spp_vm and spp_vf can refer this new function.
[1]https://mails.dpdk.org/archives/dev/2018-October/117115.html
Signed-off-by: Hideyuki Yamashita <yamashita.hideyuki at po.ntt-tx.co.jp>
Signed-off-by: Naoki Takada <takada.naoki at lab.ntt.co.jp>
---
src/shared/common.c | 38 ++++++++++++++++++++++++++++++++++++++
src/shared/common.h | 12 ++++++++++++
2 files changed, 50 insertions(+)
diff --git a/src/shared/common.c b/src/shared/common.c
index c88ce14..0e32fa6 100644
--- a/src/shared/common.c
+++ b/src/shared/common.c
@@ -526,3 +526,41 @@ dev_attach_by_devargs(const char *devargs, uint16_t *port_id)
return ret;
}
+
+/* detach the device, then store the name of the device */
+int
+dev_detach_by_port_id(uint16_t port_id)
+{
+ struct rte_device *dev;
+ struct rte_bus *bus;
+ uint32_t dev_flags;
+ int ret = -1;
+
+ if (rte_eth_devices[port_id].data == NULL) {
+ RTE_LOG(INFO, APP,
+ "rte_eth_devices[%d].data is NULL\n", port_id);
+ return 0;
+ }
+ dev_flags = rte_eth_devices[port_id].data->dev_flags;
+ if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
+ RTE_LOG(ERR, APP,
+ "Port %"PRIu16" is bonded, cannot detach\n", port_id);
+ return -ENOTSUP;
+ }
+
+ dev = rte_eth_devices[port_id].device;
+ if (dev == NULL)
+ return -EINVAL;
+
+ bus = rte_bus_find_by_device(dev);
+ if (bus == NULL)
+ return -ENOENT;
+
+ ret = rte_eal_hotplug_remove(bus->name, dev->name);
+ if (ret < 0)
+ return ret;
+
+ rte_eth_dev_release_port(&rte_eth_devices[port_id]);
+
+ return 0;
+}
diff --git a/src/shared/common.h b/src/shared/common.h
index 60514e5..09dbf8a 100644
--- a/src/shared/common.h
+++ b/src/shared/common.h
@@ -234,4 +234,16 @@ int spp_atoi(const char *str, int *val);
int
dev_attach_by_devargs(const char *devargs, uint16_t *port_id);
+/**
+ * Detach a Ethernet device specified by port identifier.
+ * This function must be called when the device is in the
+ * closed state.
+ *
+ * @param port_id
+ * The port identifier of the device to detach.
+ * @return
+ * 0 on success and devname is filled, negative on error
+ */
+int dev_detach_by_port_id(uint16_t port_id);
+
#endif
--
2.18.0
More information about the spp
mailing list