1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017 6WIND S.A.
3 * Copyright 2017 Mellanox Technologies, Ltd
6 #include <rte_malloc.h>
8 #include "failsafe_private.h"
11 fs_ethdev_portid_get(const char *name, uint16_t *port_id)
17 DEBUG("Null pointer is specified\n");
21 RTE_ETH_FOREACH_DEV(pid) {
22 if (!strncmp(name, rte_eth_devices[pid].device->name, len)) {
31 fs_bus_init(struct rte_eth_dev *dev)
33 struct sub_device *sdev;
34 struct rte_devargs *da;
39 FOREACH_SUBDEV(sdev, i, dev) {
40 if (sdev->state != DEV_PARSED)
43 if (fs_ethdev_portid_get(da->name, &pid) != 0) {
44 ret = rte_eal_hotplug_add(da->bus->name,
48 ERROR("sub_device %d probe failed %s%s%s", i,
50 rte_errno ? strerror(rte_errno) : "",
51 rte_errno ? ")" : "");
54 if (fs_ethdev_portid_get(da->name, &pid) != 0) {
55 ERROR("sub_device %d init went wrong", i);
59 char devstr[DEVARGS_MAXLEN] = "";
60 struct rte_devargs *probed_da =
61 rte_eth_devices[pid].device->devargs;
63 /* Take control of device probed by EAL options. */
65 memset(da, 0, sizeof(*da));
66 if (probed_da != NULL)
67 snprintf(devstr, sizeof(devstr), "%s,%s",
68 probed_da->name, probed_da->args);
70 snprintf(devstr, sizeof(devstr), "%s",
71 rte_eth_devices[pid].device->name);
72 ret = rte_eal_devargs_parse(da, "%s", devstr);
74 ERROR("Probed devargs parsing failed with code"
78 INFO("Taking control of a probed sub device"
79 " %d named %s", i, da->name);
81 ret = rte_eth_dev_owner_set(pid, &PRIV(dev)->my_owner);
83 INFO("sub_device %d owner set failed (%s),"
84 " will try again later", i, strerror(-ret));
86 } else if (strncmp(rte_eth_devices[pid].device->name, da->name,
87 strlen(da->name)) != 0) {
89 * The device probably was removed and its port id was
90 * reallocated before ownership set.
92 rte_eth_dev_owner_unset(pid, PRIV(dev)->my_owner.id);
93 INFO("sub_device %d was probably removed before taking"
94 " ownership, will try again later", i);
97 ETH(sdev) = &rte_eth_devices[pid];
100 sdev->dev = ETH(sdev)->device;
101 ETH(sdev)->state = RTE_ETH_DEV_DEFERRED;
102 sdev->state = DEV_PROBED;
108 failsafe_eal_init(struct rte_eth_dev *dev)
112 ret = fs_bus_init(dev);
115 if (PRIV(dev)->state < DEV_PROBED)
116 PRIV(dev)->state = DEV_PROBED;
117 fs_switch_dev(dev, NULL);
122 fs_bus_uninit(struct rte_eth_dev *dev)
124 struct sub_device *sdev = NULL;
129 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
130 sdev_ret = rte_eal_hotplug_remove(sdev->bus->name,
133 ERROR("Failed to remove requested device %s (err: %d)",
134 sdev->dev->name, sdev_ret);
137 sdev->state = DEV_PROBED - 1;
143 failsafe_eal_uninit(struct rte_eth_dev *dev)
147 ret = fs_bus_uninit(dev);
148 PRIV(dev)->state = DEV_PROBED - 1;