[dpdk-users] How to replace rte_eth_dev_attach with rte_eal_hotplug_add

Hideyuki Yamashita yamashita.hideyuki at po.ntt-tx.co.jp
Thu Sep 13 05:00:14 CEST 2018


Hello,

From dpdk 18.08 release rte_eth_dev_attach and 
rte_eth_dev_detach becom deprecated API and 
it is recommended to replace with rte_eal_hotplug_add
and rte_eal_hotplug_remove.

My program uses  above mentioned deprecated APIs
and have to replace those.
Note that my program uses attach to attach vhost, pcap pmd.

My question is whether it is correct to replace those as following:
find rte_eth_dev_attach function in rte_ethdev.c and
migrate those content into my program.

[attach] refering lib/librte_ethdev/rte_ethdev.c
----------------------------------------------------------
   643  rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
   644  {
   645          int current = rte_eth_dev_count_total();
   646          struct rte_devargs da;
   647          int ret = -1;
   648
   649          memset(&da, 0, sizeof(da));
   650
   651          if ((devargs == NULL) || (port_id == NULL)) {
   652                  ret = -EINVAL;
   653                  goto err;
   654          }
   655
   656          /* parse devargs */
   657          if (rte_devargs_parse(&da, "%s", devargs))
   658                  goto err;
   659
   660          ret = rte_eal_hotplug_add(da.bus->name, da.name, da.args);
   661          if (ret < 0)
   662                  goto err;
   663
   664          /* no point looking at the port count if no port exists */
   665          if (!rte_eth_dev_count_total()) {
   666                  ethdev_log(ERR, "No port found for device (%s)", da.name);
   667                  ret = -1;
   668                  goto err;
   669          }
   670
   671          /* if nothing happened, there is a bug here, since some driver told us
   672           * it did attach a device, but did not create a port.
   673           * FIXME: race condition in case of plug-out of another device
   674           */
   675          if (current == rte_eth_dev_count_total()) {
   676                  ret = -1;
   677                  goto err;
   678          }
   679
   680          *port_id = eth_dev_last_created_port;
   681          ret = 0;
   682
   683  err:
   684          free(da.args);
   685          return ret;
   686  }
----------------------------------------------------------

[detach]refering lib/librte_ethdev/rte_ethdev.c
-----------------------------------------------------------
   690  rte_eth_dev_detach(uint16_t port_id, char *name __rte_unused)
   691  {
   692          struct rte_device *dev;
   693          struct rte_bus *bus;
   694          uint32_t dev_flags;
   695          int ret = -1;
   696
   697          RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
   698
   699          dev_flags = rte_eth_devices[port_id].data->dev_flags;
   700          if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
   701                  ethdev_log(ERR,
   702                          "Port %" PRIu16 " is bonded, cannot detach", port_id);
   703                  return -ENOTSUP;
   704          }
   705
   706          dev = rte_eth_devices[port_id].device;
   707          if (dev == NULL)
   708                  return -EINVAL;
   709
   710          bus = rte_bus_find_by_device(dev);
   711          if (bus == NULL)
   712                  return -ENOENT;
   713
   714          ret = rte_eal_hotplug_remove(bus->name, dev->name);
   715          if (ret < 0)
   716                  return ret;
   717
   718          rte_eth_dev_release_port(&rte_eth_devices[port_id]);
   719          return 0;
   720  }
------------------------------------------------------------

If my post should be better to dev mailing list instead of 
this mailing list, then please let me know.

Your advice/guidance are much appreciated.
Thanks!

BR,
Hideyuki Yamashita
-----------------------------------------
Hideyuki Yamashita
NTT TechnoCross
-----------------------------------------




More information about the users mailing list