From: Jan Blunck Date: Tue, 11 Apr 2017 15:44:12 +0000 (+0200) Subject: drivers/net: use ethdev allocation helper for vdev X-Git-Tag: spdx-start~3649 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=050fe6e9ff970ff92d842912136be8f9f52e171f;p=dpdk.git drivers/net: use ethdev allocation helper for vdev Signed-off-by: Jan Blunck Signed-off-by: Gaetan Rivet Acked-by: Stephen Hemminger --- diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 77536e82bb..6f6ba0ca60 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -539,18 +540,19 @@ open_packet_iface(const char *key __rte_unused, static struct rte_vdev_driver pmd_af_packet_drv; static int -rte_pmd_init_internals(const char *name, +rte_pmd_init_internals(struct rte_vdev_device *dev, const int sockfd, const unsigned nb_queues, unsigned int blocksize, unsigned int blockcnt, unsigned int framesize, unsigned int framecnt, - const unsigned numa_node, struct pmd_internals **internals, struct rte_eth_dev **eth_dev, struct rte_kvargs *kvlist) { + const char *name = rte_vdev_device_name(dev); + const unsigned int numa_node = dev->device.numa_node; struct rte_eth_dev_data *data = NULL; struct rte_kvargs_pair *pair = NULL; struct ifreq ifr; @@ -768,7 +770,7 @@ rte_pmd_init_internals(const char *name, } /* reserve an ethdev entry */ - *eth_dev = rte_eth_dev_allocate(name); + *eth_dev = rte_eth_vdev_allocate(dev, 0); if (*eth_dev == NULL) goto error; @@ -782,22 +784,16 @@ rte_pmd_init_internals(const char *name, (*internals)->nb_queues = nb_queues; + rte_memcpy(data, (*eth_dev)->data, sizeof(*data)); data->dev_private = *internals; - data->port_id = (*eth_dev)->data->port_id; data->nb_rx_queues = (uint16_t)nb_queues; data->nb_tx_queues = (uint16_t)nb_queues; data->dev_link = pmd_link; data->mac_addrs = &(*internals)->eth_addr; - strncpy(data->name, - (*eth_dev)->data->name, strlen((*eth_dev)->data->name)); (*eth_dev)->data = data; (*eth_dev)->dev_ops = &ops; - (*eth_dev)->driver = NULL; (*eth_dev)->data->dev_flags = RTE_ETH_DEV_DETACHABLE; - (*eth_dev)->data->drv_name = pmd_af_packet_drv.driver.name; - (*eth_dev)->data->kdrv = RTE_KDRV_NONE; - (*eth_dev)->data->numa_node = numa_node; return 0; @@ -822,11 +818,11 @@ error_early: } static int -rte_eth_from_packet(const char *name, +rte_eth_from_packet(struct rte_vdev_device *dev, int const *sockfd, - const unsigned numa_node, struct rte_kvargs *kvlist) { + const char *name = rte_vdev_device_name(dev); struct pmd_internals *internals = NULL; struct rte_eth_dev *eth_dev = NULL; struct rte_kvargs_pair *pair = NULL; @@ -909,11 +905,11 @@ rte_eth_from_packet(const char *name, RTE_LOG(INFO, PMD, "%s:\tframe size %d\n", name, framesize); RTE_LOG(INFO, PMD, "%s:\tframe count %d\n", name, framecount); - if (rte_pmd_init_internals(name, *sockfd, qpairs, - blocksize, blockcount, - framesize, framecount, - numa_node, &internals, ð_dev, - kvlist) < 0) + if (rte_pmd_init_internals(dev, *sockfd, qpairs, + blocksize, blockcount, + framesize, framecount, + &internals, ð_dev, + kvlist) < 0) return -1; eth_dev->rx_pkt_burst = eth_af_packet_rx; @@ -925,15 +921,12 @@ rte_eth_from_packet(const char *name, static int rte_pmd_af_packet_probe(struct rte_vdev_device *dev) { - const char *name = rte_vdev_device_name(dev); - unsigned numa_node; int ret = 0; struct rte_kvargs *kvlist; int sockfd = -1; - RTE_LOG(INFO, PMD, "Initializing pmd_af_packet for %s\n", name); - - numa_node = rte_socket_id(); + RTE_LOG(INFO, PMD, "Initializing pmd_af_packet for %s\n", + rte_vdev_device_name(dev)); kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments); if (kvlist == NULL) { @@ -953,7 +946,10 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev) goto exit; } - ret = rte_eth_from_packet(name, &sockfd, numa_node, kvlist); + if (dev->device.numa_node == SOCKET_ID_ANY) + dev->device.numa_node = rte_socket_id(); + + ret = rte_eth_from_packet(dev, &sockfd, kvlist); close(sockfd); /* no longer needed */ exit: diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c index 2b1db0b2de..2ddcd0791a 100644 --- a/drivers/net/bonding/rte_eth_bond_pmd.c +++ b/drivers/net/bonding/rte_eth_bond_pmd.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -2253,31 +2254,20 @@ bond_alloc(struct rte_vdev_device *dev, uint8_t mode) * and internal (private) data */ - if (name == NULL) { - RTE_BOND_LOG(ERR, "Invalid name specified"); - goto err; - } - if (socket_id >= number_of_sockets()) { RTE_BOND_LOG(ERR, "Invalid socket id specified to create bonded device on."); goto err; } - internals = rte_zmalloc_socket(name, sizeof(*internals), 0, socket_id); - if (internals == NULL) { - RTE_BOND_LOG(ERR, "Unable to malloc internals on socket"); - goto err; - } - /* reserve an ethdev entry */ - eth_dev = rte_eth_dev_allocate(name); + eth_dev = rte_eth_vdev_allocate(dev, sizeof(*internals)); if (eth_dev == NULL) { RTE_BOND_LOG(ERR, "Unable to allocate rte_eth_dev"); goto err; } - eth_dev->data->dev_private = internals; + internals = eth_dev->data->dev_private; eth_dev->data->nb_rx_queues = (uint16_t)1; eth_dev->data->nb_tx_queues = (uint16_t)1; @@ -2291,10 +2281,6 @@ bond_alloc(struct rte_vdev_device *dev, uint8_t mode) eth_dev->dev_ops = &default_dev_ops; eth_dev->data->dev_flags = RTE_ETH_DEV_INTR_LSC | RTE_ETH_DEV_DETACHABLE; - eth_dev->driver = NULL; - eth_dev->data->kdrv = RTE_KDRV_NONE; - eth_dev->data->drv_name = pmd_bond_drv.driver.name; - eth_dev->data->numa_node = socket_id; rte_spinlock_init(&internals->lock); diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c index e3ce572d5b..8f900342cf 100644 --- a/drivers/net/kni/rte_eth_kni.c +++ b/drivers/net/kni/rte_eth_kni.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -358,32 +359,32 @@ static const struct eth_dev_ops eth_kni_ops = { static struct rte_vdev_driver eth_kni_drv; static struct rte_eth_dev * -eth_kni_create(const char *name, struct eth_kni_args *args, +eth_kni_create(struct rte_vdev_device *vdev, + struct eth_kni_args *args, unsigned int numa_node) { - struct pmd_internals *internals = NULL; + struct pmd_internals *internals; struct rte_eth_dev_data *data; struct rte_eth_dev *eth_dev; + const char *name; RTE_LOG(INFO, PMD, "Creating kni ethdev on numa socket %u\n", numa_node); + name = rte_vdev_device_name(vdev); data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node); if (data == NULL) - goto error; - - internals = rte_zmalloc_socket(name, sizeof(*internals), 0, numa_node); - if (internals == NULL) - goto error; + return NULL; /* reserve an ethdev entry */ - eth_dev = rte_eth_dev_allocate(name); - if (eth_dev == NULL) - goto error; + eth_dev = rte_eth_vdev_allocate(vdev, sizeof(*internals)); + if (eth_dev == NULL) { + rte_free(data); + return NULL; + } - data->dev_private = internals; - data->port_id = eth_dev->data->port_id; - memmove(data->name, eth_dev->data->name, sizeof(data->name)); + internals = eth_dev->data->dev_private; + rte_memcpy(data, eth_dev->data, sizeof(*data)); data->nb_rx_queues = 1; data->nb_tx_queues = 1; data->dev_link = pmd_link; @@ -393,22 +394,12 @@ eth_kni_create(const char *name, struct eth_kni_args *args, eth_dev->data = data; eth_dev->dev_ops = ð_kni_ops; - eth_dev->device->driver = NULL; data->dev_flags = RTE_ETH_DEV_DETACHABLE; - data->kdrv = RTE_KDRV_NONE; - data->drv_name = eth_kni_drv.driver.name; - data->numa_node = numa_node; internals->no_request_thread = args->no_request_thread; return eth_dev; - -error: - rte_free(data); - rte_free(internals); - - return NULL; } static int @@ -462,7 +453,7 @@ eth_kni_probe(struct rte_vdev_device *vdev) if (ret < 0) return ret; - eth_dev = eth_kni_create(name, &args, rte_socket_id()); + eth_dev = eth_kni_create(vdev, &args, rte_socket_id()); if (eth_dev == NULL) goto kni_uninit; diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c index 863fcc78fc..abf3ec7536 100644 --- a/drivers/net/null/rte_eth_null.c +++ b/drivers/net/null/rte_eth_null.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -477,8 +478,7 @@ static const struct eth_dev_ops ops = { static struct rte_vdev_driver pmd_null_drv; static int -eth_dev_null_create(const char *name, - const unsigned numa_node, +eth_dev_null_create(struct rte_vdev_device *dev, unsigned packet_size, unsigned packet_copy) { @@ -495,27 +495,25 @@ eth_dev_null_create(const char *name, 0xBE, 0xAC, 0x01, 0xFA }; - if (name == NULL) - return -EINVAL; + if (dev->device.numa_node == SOCKET_ID_ANY) + dev->device.numa_node = rte_socket_id(); RTE_LOG(INFO, PMD, "Creating null ethdev on numa socket %u\n", - numa_node); + dev->device.numa_node); /* now do all data allocation - for eth_dev structure, dummy pci driver * and internal (private) data */ - data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node); - if (data == NULL) - goto error; - - internals = rte_zmalloc_socket(name, sizeof(*internals), 0, numa_node); - if (internals == NULL) - goto error; + data = rte_zmalloc_socket(rte_vdev_device_name(dev), sizeof(*data), 0, + dev->device.numa_node); + if (!data) + return -ENOMEM; - /* reserve an ethdev entry */ - eth_dev = rte_eth_dev_allocate(name); - if (eth_dev == NULL) - goto error; + eth_dev = rte_eth_vdev_allocate(dev, sizeof(*internals)); + if (!eth_dev) { + rte_free(data); + return -ENOMEM; + } /* now put it all together * - store queue data in internals, @@ -526,6 +524,7 @@ eth_dev_null_create(const char *name, /* NOTE: we'll replace the data element, of originally allocated eth_dev * so the nulls are local per-process */ + internals = eth_dev->data->dev_private; internals->packet_size = packet_size; internals->packet_copy = packet_copy; internals->port_id = eth_dev->data->port_id; @@ -535,22 +534,16 @@ eth_dev_null_create(const char *name, rte_memcpy(internals->rss_key, default_rss_key, 40); - data->dev_private = internals; - data->port_id = eth_dev->data->port_id; + rte_memcpy(data, eth_dev->data, sizeof(*data)); data->nb_rx_queues = (uint16_t)nb_rx_queues; data->nb_tx_queues = (uint16_t)nb_tx_queues; data->dev_link = pmd_link; data->mac_addrs = ð_addr; - strncpy(data->name, eth_dev->data->name, strlen(eth_dev->data->name)); eth_dev->data = data; eth_dev->dev_ops = &ops; - eth_dev->driver = NULL; data->dev_flags = RTE_ETH_DEV_DETACHABLE; - data->kdrv = RTE_KDRV_NONE; - data->drv_name = pmd_null_drv.driver.name; - data->numa_node = numa_node; /* finally assign rx and tx ops */ if (packet_copy) { @@ -562,12 +555,6 @@ eth_dev_null_create(const char *name, } return 0; - -error: - rte_free(data); - rte_free(internals); - - return -1; } static inline int @@ -608,7 +595,6 @@ static int rte_pmd_null_probe(struct rte_vdev_device *dev) { const char *name, *params; - unsigned numa_node; unsigned packet_size = default_packet_size; unsigned packet_copy = default_packet_copy; struct rte_kvargs *kvlist = NULL; @@ -621,8 +607,6 @@ rte_pmd_null_probe(struct rte_vdev_device *dev) params = rte_vdev_device_args(dev); RTE_LOG(INFO, PMD, "Initializing pmd_null for %s\n", name); - numa_node = rte_socket_id(); - if (params != NULL) { kvlist = rte_kvargs_parse(params, valid_arguments); if (kvlist == NULL) @@ -651,7 +635,7 @@ rte_pmd_null_probe(struct rte_vdev_device *dev) "packet copy is %s\n", packet_size, packet_copy ? "enabled" : "disabled"); - ret = eth_dev_null_create(name, numa_node, packet_size, packet_copy); + ret = eth_dev_null_create(dev, packet_size, packet_copy); free_kvlist: if (kvlist) diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index 05cbd47b3c..defb3b4194 100644 --- a/drivers/net/pcap/rte_eth_pcap.c +++ b/drivers/net/pcap/rte_eth_pcap.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -790,14 +791,17 @@ open_tx_iface(const char *key, const char *value, void *extra_args) static struct rte_vdev_driver pmd_pcap_drv; static int -pmd_init_internals(const char *name, const unsigned int nb_rx_queues, +pmd_init_internals(struct rte_vdev_device *vdev, + const unsigned int nb_rx_queues, const unsigned int nb_tx_queues, struct pmd_internals **internals, struct rte_eth_dev **eth_dev) { struct rte_eth_dev_data *data = NULL; - unsigned int numa_node = rte_socket_id(); + unsigned int numa_node = vdev->device.numa_node; + const char *name; + name = rte_vdev_device_name(vdev); RTE_LOG(INFO, PMD, "Creating pcap-backed ethdev on numa socket %u\n", numa_node); @@ -806,17 +810,14 @@ pmd_init_internals(const char *name, const unsigned int nb_rx_queues, */ data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node); if (data == NULL) - goto error; - - *internals = rte_zmalloc_socket(name, sizeof(**internals), 0, - numa_node); - if (*internals == NULL) - goto error; + return -1; /* reserve an ethdev entry */ - *eth_dev = rte_eth_dev_allocate(name); - if (*eth_dev == NULL) - goto error; + *eth_dev = rte_eth_vdev_allocate(vdev, sizeof(**internals)); + if (*eth_dev == NULL) { + rte_free(data); + return -1; + } /* now put it all together * - store queue data in internals, @@ -824,9 +825,8 @@ pmd_init_internals(const char *name, const unsigned int nb_rx_queues, * - point eth_dev_data to internals * - and point eth_dev structure to new eth_dev_data structure */ - data->dev_private = *internals; - data->port_id = (*eth_dev)->data->port_id; - snprintf(data->name, sizeof(data->name), "%s", (*eth_dev)->data->name); + *internals = (*eth_dev)->data->dev_private; + rte_memcpy(data, (*eth_dev)->data, sizeof(*data)); data->nb_rx_queues = (uint16_t)nb_rx_queues; data->nb_tx_queues = (uint16_t)nb_tx_queues; data->dev_link = pmd_link; @@ -838,26 +838,17 @@ pmd_init_internals(const char *name, const unsigned int nb_rx_queues, */ (*eth_dev)->data = data; (*eth_dev)->dev_ops = &ops; - (*eth_dev)->driver = NULL; data->dev_flags = RTE_ETH_DEV_DETACHABLE; - data->kdrv = RTE_KDRV_NONE; - data->drv_name = pmd_pcap_drv.driver.name; - data->numa_node = numa_node; return 0; - -error: - rte_free(data); - rte_free(*internals); - - return -1; } static int -eth_from_pcaps_common(const char *name, struct pmd_devargs *rx_queues, - const unsigned int nb_rx_queues, struct pmd_devargs *tx_queues, - const unsigned int nb_tx_queues, struct rte_kvargs *kvlist, - struct pmd_internals **internals, struct rte_eth_dev **eth_dev) +eth_from_pcaps_common(struct rte_vdev_device *vdev, + struct pmd_devargs *rx_queues, const unsigned int nb_rx_queues, + struct pmd_devargs *tx_queues, const unsigned int nb_tx_queues, + struct rte_kvargs *kvlist, struct pmd_internals **internals, + struct rte_eth_dev **eth_dev) { struct rte_kvargs_pair *pair = NULL; unsigned int k_idx; @@ -869,7 +860,7 @@ eth_from_pcaps_common(const char *name, struct pmd_devargs *rx_queues, if (tx_queues == NULL && nb_tx_queues > 0) return -1; - if (pmd_init_internals(name, nb_rx_queues, nb_tx_queues, internals, + if (pmd_init_internals(vdev, nb_rx_queues, nb_tx_queues, internals, eth_dev) < 0) return -1; @@ -907,16 +898,17 @@ eth_from_pcaps_common(const char *name, struct pmd_devargs *rx_queues, } static int -eth_from_pcaps(const char *name, struct pmd_devargs *rx_queues, - const unsigned int nb_rx_queues, struct pmd_devargs *tx_queues, - const unsigned int nb_tx_queues, struct rte_kvargs *kvlist, - int single_iface, unsigned int using_dumpers) +eth_from_pcaps(struct rte_vdev_device *vdev, + struct pmd_devargs *rx_queues, const unsigned int nb_rx_queues, + struct pmd_devargs *tx_queues, const unsigned int nb_tx_queues, + struct rte_kvargs *kvlist, int single_iface, + unsigned int using_dumpers) { struct pmd_internals *internals = NULL; struct rte_eth_dev *eth_dev = NULL; int ret; - ret = eth_from_pcaps_common(name, rx_queues, nb_rx_queues, + ret = eth_from_pcaps_common(vdev, rx_queues, nb_rx_queues, tx_queues, nb_tx_queues, kvlist, &internals, ð_dev); if (ret < 0) @@ -1027,7 +1019,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev) goto free_kvlist; create_eth: - ret = eth_from_pcaps(name, &pcaps, pcaps.num_of_queue, &dumpers, + ret = eth_from_pcaps(dev, &pcaps, pcaps.num_of_queue, &dumpers, dumpers.num_of_queue, kvlist, single_iface, is_tx_pcap); free_kvlist: diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 698e14baae..206a0d6946 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1131,12 +1132,13 @@ tap_kernel_support(struct pmd_internals *pmd) } static int -eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) +eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, + char *remote_iface) { int numa_node = rte_socket_id(); - struct rte_eth_dev *dev = NULL; - struct pmd_internals *pmd = NULL; - struct rte_eth_dev_data *data = NULL; + struct rte_eth_dev *dev; + struct pmd_internals *pmd; + struct rte_eth_dev_data *data; int i; RTE_LOG(DEBUG, PMD, " TAP device on numa %u\n", rte_socket_id()); @@ -1147,22 +1149,14 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) goto error_exit; } - pmd = rte_zmalloc_socket(tap_name, sizeof(*pmd), 0, numa_node); - if (!pmd) { - RTE_LOG(ERR, PMD, "TAP Unable to allocate internal struct\n"); - goto error_exit; - } - - /* name in allocation and data->name must be consistent */ - snprintf(data->name, sizeof(data->name), "%s", name); - dev = rte_eth_dev_allocate(name); + dev = rte_eth_vdev_allocate(vdev, sizeof(*pmd)); if (!dev) { RTE_LOG(ERR, PMD, "TAP Unable to allocate device struct\n"); goto error_exit; } + pmd = dev->data->dev_private; snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name); - pmd->nb_queues = RTE_PMD_TAP_MAX_QUEUES; pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0); @@ -1174,13 +1168,11 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) } /* Setup some default values */ + rte_memcpy(data, dev->data, sizeof(*data)); data->dev_private = pmd; - data->port_id = dev->data->port_id; - data->mtu = dev->data->mtu; data->dev_flags = RTE_ETH_DEV_DETACHABLE | RTE_ETH_DEV_INTR_LSC; - data->kdrv = RTE_KDRV_NONE; - data->drv_name = pmd_tap_drv.driver.name; data->numa_node = numa_node; + data->drv_name = pmd_tap_drv.driver.name; data->dev_link = pmd_link; data->mac_addrs = &pmd->eth_addr; @@ -1189,7 +1181,6 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) dev->data = data; dev->dev_ops = &ops; - dev->driver = NULL; dev->rx_pkt_burst = pmd_rx_burst; dev->tx_pkt_burst = pmd_tx_burst; @@ -1236,13 +1227,10 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface) return 0; error_exit: - RTE_LOG(DEBUG, PMD, "TAP Unable to initialize %s\n", name); + RTE_LOG(DEBUG, PMD, "TAP Unable to initialize %s\n", + rte_vdev_device_name(vdev)); rte_free(data); - rte_free(pmd); - - rte_eth_dev_release_port(dev); - return -EINVAL; } @@ -1343,7 +1331,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n", name, tap_name); - ret = eth_dev_tap_create(name, tap_name, remote_iface); + ret = eth_dev_tap_create(dev, tap_name, remote_iface); leave: if (ret == -1) { diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index cdd8c315e3..9663e55f0e 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -983,9 +984,10 @@ static const struct eth_dev_ops ops = { static struct rte_vdev_driver pmd_vhost_drv; static int -eth_dev_vhost_create(const char *name, char *iface_name, int16_t queues, - const unsigned numa_node, uint64_t flags) +eth_dev_vhost_create(struct rte_vdev_device *dev, char *iface_name, + int16_t queues, const unsigned int numa_node, uint64_t flags) { + const char *name = rte_vdev_device_name(dev); struct rte_eth_dev_data *data = NULL; struct pmd_internal *internal = NULL; struct rte_eth_dev *eth_dev = NULL; @@ -996,23 +998,19 @@ eth_dev_vhost_create(const char *name, char *iface_name, int16_t queues, RTE_LOG(INFO, PMD, "Creating VHOST-USER backend on numa socket %u\n", numa_node); - /* now do all data allocation - for eth_dev structure, dummy pci driver - * and internal (private) data + /* now do all data allocation - for eth_dev structure and internal + * (private) data */ data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node); if (data == NULL) goto error; - internal = rte_zmalloc_socket(name, sizeof(*internal), 0, numa_node); - if (internal == NULL) - goto error; - list = rte_zmalloc_socket(name, sizeof(*list), 0, numa_node); if (list == NULL) goto error; /* reserve an ethdev entry */ - eth_dev = rte_eth_dev_allocate(name); + eth_dev = rte_eth_vdev_allocate(dev, sizeof(*internal)); if (eth_dev == NULL) goto error; @@ -1029,10 +1027,10 @@ eth_dev_vhost_create(const char *name, char *iface_name, int16_t queues, /* now put it all together * - store queue data in internal, - * - store numa_node info in ethdev data * - point eth_dev_data to internals * - and point eth_dev structure to new eth_dev_data structure */ + internal = eth_dev->data->dev_private; internal->dev_name = strdup(name); if (internal->dev_name == NULL) goto error; @@ -1048,26 +1046,21 @@ eth_dev_vhost_create(const char *name, char *iface_name, int16_t queues, rte_spinlock_init(&vring_state->lock); vring_states[eth_dev->data->port_id] = vring_state; - data->dev_private = internal; - data->port_id = eth_dev->data->port_id; - memmove(data->name, eth_dev->data->name, sizeof(data->name)); + /* We'll replace the 'data' originally allocated by eth_dev. So the + * vhost PMD resources won't be shared between multi processes. + */ + rte_memcpy(data, eth_dev->data, sizeof(*data)); + eth_dev->data = data; + data->nb_rx_queues = queues; data->nb_tx_queues = queues; internal->max_queues = queues; data->dev_link = pmd_link; data->mac_addrs = eth_addr; - - /* We'll replace the 'data' originally allocated by eth_dev. So the - * vhost PMD resources won't be shared between multi processes. - */ - eth_dev->data = data; - eth_dev->dev_ops = &ops; - eth_dev->driver = NULL; data->dev_flags = RTE_ETH_DEV_DETACHABLE | RTE_ETH_DEV_INTR_LSC; - data->kdrv = RTE_KDRV_NONE; - data->drv_name = pmd_vhost_drv.driver.name; - data->numa_node = numa_node; + + eth_dev->dev_ops = &ops; /* finally assign rx and tx ops */ eth_dev->rx_pkt_burst = eth_vhost_rx; @@ -1090,8 +1083,10 @@ eth_dev_vhost_create(const char *name, char *iface_name, int16_t queues, return data->port_id; error: - if (internal) + if (internal) { + free(internal->iface_name); free(internal->dev_name); + } rte_free(vring_state); rte_free(eth_addr); if (eth_dev) @@ -1134,7 +1129,6 @@ open_int(const char *key __rte_unused, const char *value, void *extra_args) static int rte_pmd_vhost_probe(struct rte_vdev_device *dev) { - const char *name; struct rte_kvargs *kvlist = NULL; int ret = 0; char *iface_name; @@ -1143,8 +1137,8 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev) int client_mode = 0; int dequeue_zero_copy = 0; - name = rte_vdev_device_name(dev); - RTE_LOG(INFO, PMD, "Initializing pmd_vhost for %s\n", name); + RTE_LOG(INFO, PMD, "Initializing pmd_vhost for %s\n", + rte_vdev_device_name(dev)); kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments); if (kvlist == NULL) @@ -1189,7 +1183,11 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev) flags |= RTE_VHOST_USER_DEQUEUE_ZERO_COPY; } - eth_dev_vhost_create(name, iface_name, queues, rte_socket_id(), flags); + if (dev->device.numa_node == SOCKET_ID_ANY) + dev->device.numa_node = rte_socket_id(); + + eth_dev_vhost_create(dev, iface_name, queues, dev->device.numa_node, + flags); out_free: rte_kvargs_free(kvlist); diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 7979c1f00c..1894310cf8 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -336,27 +337,21 @@ get_integer_arg(const char *key __rte_unused, static struct rte_vdev_driver virtio_user_driver; static struct rte_eth_dev * -virtio_user_eth_dev_alloc(const char *name) +virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev) { struct rte_eth_dev *eth_dev; struct rte_eth_dev_data *data; struct virtio_hw *hw; struct virtio_user_dev *dev; - eth_dev = rte_eth_dev_allocate(name); + eth_dev = rte_eth_vdev_allocate(vdev, sizeof(*hw)); if (!eth_dev) { PMD_INIT_LOG(ERR, "cannot alloc rte_eth_dev"); return NULL; } data = eth_dev->data; - - hw = rte_zmalloc(NULL, sizeof(*hw), 0); - if (!hw) { - PMD_INIT_LOG(ERR, "malloc virtio_hw failed"); - rte_eth_dev_release_port(eth_dev); - return NULL; - } + hw = eth_dev->data->dev_private; dev = rte_zmalloc(NULL, sizeof(*dev), 0); if (!dev) { @@ -377,12 +372,7 @@ virtio_user_eth_dev_alloc(const char *name) hw->modern = 0; hw->use_simple_rxtx = 0; hw->virtio_user_dev = dev; - data->dev_private = hw; - data->drv_name = virtio_user_driver.driver.name; - data->numa_node = SOCKET_ID_ANY; - data->kdrv = RTE_KDRV_NONE; data->dev_flags = RTE_ETH_DEV_DETACHABLE; - eth_dev->driver = NULL; return eth_dev; } @@ -501,7 +491,7 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) } if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - eth_dev = virtio_user_eth_dev_alloc(rte_vdev_device_name(dev)); + eth_dev = virtio_user_eth_dev_alloc(dev); if (!eth_dev) { PMD_INIT_LOG(ERR, "virtio_user fails to alloc device"); goto end;