devargs: rename legacy API
[dpdk.git] / lib / librte_ether / rte_ethdev.c
index a023b3e..f0f53d4 100644 (file)
@@ -534,6 +534,12 @@ rte_eth_dev_get_sec_ctx(uint16_t port_id)
 
 uint16_t
 rte_eth_dev_count(void)
+{
+       return rte_eth_dev_count_avail();
+}
+
+uint16_t
+rte_eth_dev_count_avail(void)
 {
        uint16_t p;
        uint16_t count;
@@ -546,6 +552,18 @@ rte_eth_dev_count(void)
        return count;
 }
 
+uint16_t
+rte_eth_dev_count_total(void)
+{
+       uint16_t port, count = 0;
+
+       for (port = 0; port < RTE_MAX_ETHPORTS; port++)
+               if (rte_eth_devices[port].state != RTE_ETH_DEV_UNUSED)
+                       count++;
+
+       return count;
+}
+
 int
 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
 {
@@ -600,35 +618,37 @@ eth_err(uint16_t port_id, int ret)
 int
 rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
 {
+       int current = rte_eth_dev_count_total();
+       struct rte_devargs da;
        int ret = -1;
-       int current = rte_eth_dev_count();
-       char *name = NULL;
-       char *args = NULL;
+
+       memset(&da, 0, sizeof(da));
 
        if ((devargs == NULL) || (port_id == NULL)) {
                ret = -EINVAL;
                goto err;
        }
 
-       /* parse devargs, then retrieve device name and args */
-       if (rte_eal_parse_devargs_str(devargs, &name, &args))
+       /* parse devargs */
+       if (rte_devargs_parse(&da, "%s", devargs))
                goto err;
 
-       ret = rte_eal_dev_attach(name, args);
+       ret = rte_eal_hotplug_add(da.bus->name, da.name, da.args);
        if (ret < 0)
                goto err;
 
        /* no point looking at the port count if no port exists */
-       if (!rte_eth_dev_count()) {
-               ethdev_log(ERR, "No port found for device (%s)", name);
+       if (!rte_eth_dev_count_total()) {
+               ethdev_log(ERR, "No port found for device (%s)", da.name);
                ret = -1;
                goto err;
        }
 
        /* if nothing happened, there is a bug here, since some driver told us
         * it did attach a device, but did not create a port.
+        * FIXME: race condition in case of plug-out of another device
         */
-       if (current == rte_eth_dev_count()) {
+       if (current == rte_eth_dev_count_total()) {
                ret = -1;
                goto err;
        }
@@ -637,45 +657,42 @@ rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
        ret = 0;
 
 err:
-       free(name);
-       free(args);
+       free(da.args);
        return ret;
 }
 
 /* detach the device, then store the name of the device */
 int
-rte_eth_dev_detach(uint16_t port_id, char *name)
+rte_eth_dev_detach(uint16_t port_id, char *name __rte_unused)
 {
+       struct rte_device *dev;
+       struct rte_bus *bus;
        uint32_t dev_flags;
        int ret = -1;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
 
-       if (name == NULL) {
-               ret = -EINVAL;
-               goto err;
-       }
-
        dev_flags = rte_eth_devices[port_id].data->dev_flags;
        if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
                ethdev_log(ERR,
                        "Port %" PRIu16 " is bonded, cannot detach", port_id);
-               ret = -ENOTSUP;
-               goto err;
+               return -ENOTSUP;
        }
 
-       snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
-                "%s", rte_eth_devices[port_id].data->name);
+       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_dev_detach(rte_eth_devices[port_id].device);
+       ret = rte_eal_hotplug_remove(bus->name, dev->name);
        if (ret < 0)
-               goto err;
+               return ret;
 
        rte_eth_dev_release_port(&rte_eth_devices[port_id]);
        return 0;
-
-err:
-       return ret;
 }
 
 static int
@@ -3034,6 +3051,7 @@ int
 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr)
 {
        struct rte_eth_dev *dev;
+       int ret;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 
@@ -3043,11 +3061,13 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr)
        dev = &rte_eth_devices[port_id];
        RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
 
+       ret = (*dev->dev_ops->mac_addr_set)(dev, addr);
+       if (ret < 0)
+               return ret;
+
        /* Update default address in NIC data structure */
        ether_addr_copy(addr, &dev->data->mac_addrs[0]);
 
-       (*dev->dev_ops->mac_addr_set)(dev, addr);
-
        return 0;
 }