X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fkni%2Frte_eth_kni.c;h=42a45333d4b88b23d6ab60916eb5b1e390aac24b;hb=35b2d13fd6fdcbd191f2a30d74648faeb1186c65;hp=e3ce572d5b92728787aa2c1aee5ee816001f63cd;hpb=5d2aa461cbcae1b5ede5cee0b0b3a1228c4afc59;p=dpdk.git diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c index e3ce572d5b..42a45333d4 100644 --- a/drivers/net/kni/rte_eth_kni.c +++ b/drivers/net/kni/rte_eth_kni.c @@ -1,52 +1,27 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2017 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2017 Intel Corporation */ #include #include #include -#include +#include +#include +#include #include #include #include -#include +#include /* Only single queue supported */ #define KNI_MAX_QUEUE_PER_PORT 1 -#define MAX_PACKET_SZ 2048 #define MAX_KNI_PORTS 8 +#define KNI_ETHER_MTU(mbuf_size) \ + ((mbuf_size) - RTE_ETHER_HDR_LEN) /**< Ethernet MTU. */ + #define ETH_KNI_NO_REQUEST_THREAD_ARG "no_request_thread" static const char * const valid_arguments[] = { ETH_KNI_NO_REQUEST_THREAD_ARG, @@ -79,7 +54,7 @@ struct pmd_internals { int stop_thread; int no_request_thread; - struct ether_addr eth_addr; + struct rte_ether_addr eth_addr; struct pmd_queue rx_queues[KNI_MAX_QUEUE_PER_PORT]; struct pmd_queue tx_queues[KNI_MAX_QUEUE_PER_PORT]; @@ -89,10 +64,15 @@ static const struct rte_eth_link pmd_link = { .link_speed = ETH_SPEED_NUM_10G, .link_duplex = ETH_LINK_FULL_DUPLEX, .link_status = ETH_LINK_DOWN, - .link_autoneg = ETH_LINK_SPEED_AUTONEG, + .link_autoneg = ETH_LINK_FIXED, }; static int is_kni_initialized; +static int eth_kni_logtype; + +#define PMD_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, eth_kni_logtype, \ + "%s(): " fmt "\n", __func__, ##args) static uint16_t eth_kni_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { @@ -144,18 +124,20 @@ eth_kni_start(struct rte_eth_dev *dev) uint16_t port_id = dev->data->port_id; struct rte_mempool *mb_pool; struct rte_kni_conf conf; - const char *name = dev->data->name + 4; /* remove net_ */ + const char *name = dev->device->name + 4; /* remove net_ */ - snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", name); + mb_pool = internals->rx_queues[0].mb_pool; + strlcpy(conf.name, name, RTE_KNI_NAMESIZE); conf.force_bind = 0; conf.group_id = port_id; - conf.mbuf_size = MAX_PACKET_SZ; - mb_pool = internals->rx_queues[0].mb_pool; + conf.mbuf_size = + rte_pktmbuf_data_room_size(mb_pool) - RTE_PKTMBUF_HEADROOM; + conf.mtu = KNI_ETHER_MTU(conf.mbuf_size); internals->kni = rte_kni_alloc(mb_pool, &conf, NULL); if (internals->kni == NULL) { - RTE_LOG(ERR, PMD, - "Fail to create kni interface for port: %d\n", + PMD_LOG(ERR, + "Fail to create kni interface for port: %d", port_id); return -1; } @@ -177,11 +159,12 @@ eth_kni_dev_start(struct rte_eth_dev *dev) } if (internals->no_request_thread == 0) { - ret = pthread_create(&internals->thread, NULL, + ret = rte_ctrl_thread_create(&internals->thread, + "kni_handle_req", NULL, kni_handle_request, internals); if (ret) { - RTE_LOG(ERR, PMD, - "Fail to create kni request thread\n"); + PMD_LOG(ERR, + "Fail to create kni request thread"); return -1; } } @@ -202,11 +185,11 @@ eth_kni_dev_stop(struct rte_eth_dev *dev) ret = pthread_cancel(internals->thread); if (ret) - RTE_LOG(ERR, PMD, "Can't cancel the thread\n"); + PMD_LOG(ERR, "Can't cancel the thread"); ret = pthread_join(internals->thread, NULL); if (ret) - RTE_LOG(ERR, PMD, "Can't join the thread\n"); + PMD_LOG(ERR, "Can't join the thread"); internals->stop_thread = 0; } @@ -229,7 +212,6 @@ eth_kni_dev_info(struct rte_eth_dev *dev __rte_unused, dev_info->max_rx_queues = KNI_MAX_QUEUE_PER_PORT; dev_info->max_tx_queues = KNI_MAX_QUEUE_PER_PORT; dev_info->min_rx_bufsize = 0; - dev_info->pci_dev = NULL; } static int @@ -282,7 +264,7 @@ eth_kni_link_update(struct rte_eth_dev *dev __rte_unused, return 0; } -static void +static int eth_kni_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { unsigned long rx_packets_total = 0, rx_bytes_total = 0; @@ -319,6 +301,8 @@ eth_kni_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) stats->opackets = tx_packets_total; stats->obytes = tx_bytes_total; stats->oerrors = tx_packets_err_total; + + return 0; } static void @@ -355,60 +339,37 @@ static const struct eth_dev_ops eth_kni_ops = { .stats_reset = eth_kni_stats_reset, }; -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; - RTE_LOG(INFO, PMD, "Creating kni ethdev on numa socket %u\n", + PMD_LOG(INFO, "Creating kni ethdev on numa socket %u", numa_node); - 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; - /* 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) + 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; + data = eth_dev->data; data->nb_rx_queues = 1; data->nb_tx_queues = 1; data->dev_link = pmd_link; data->mac_addrs = &internals->eth_addr; - eth_random_addr(internals->eth_addr.addr_bytes); + rte_eth_random_addr(internals->eth_addr.addr_bytes); - 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 @@ -452,7 +413,20 @@ eth_kni_probe(struct rte_vdev_device *vdev) name = rte_vdev_device_name(vdev); params = rte_vdev_device_args(vdev); - RTE_LOG(INFO, PMD, "Initializing eth_kni for %s\n", name); + PMD_LOG(INFO, "Initializing eth_kni for %s", name); + + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + eth_dev = rte_eth_dev_attach_secondary(name); + if (!eth_dev) { + PMD_LOG(ERR, "Failed to probe %s", name); + return -1; + } + /* TODO: request info from primary to set up Rx and Tx */ + eth_dev->dev_ops = ð_kni_ops; + eth_dev->device = &vdev->device; + rte_eth_dev_probing_finish(eth_dev); + return 0; + } ret = eth_kni_kvargs_process(&args, params); if (ret < 0) @@ -462,13 +436,14 @@ 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; eth_dev->rx_pkt_burst = eth_kni_rx; eth_dev->tx_pkt_burst = eth_kni_tx; + rte_eth_dev_probing_finish(eth_dev); return 0; kni_uninit: @@ -484,24 +459,28 @@ eth_kni_remove(struct rte_vdev_device *vdev) struct rte_eth_dev *eth_dev; struct pmd_internals *internals; const char *name; + int ret; name = rte_vdev_device_name(vdev); - RTE_LOG(INFO, PMD, "Un-Initializing eth_kni for %s\n", name); + PMD_LOG(INFO, "Un-Initializing eth_kni for %s", name); /* find the ethdev entry */ eth_dev = rte_eth_dev_allocated(name); if (eth_dev == NULL) return -1; - eth_kni_dev_stop(eth_dev); + /* mac_addrs must not be freed alone because part of dev_private */ + eth_dev->data->mac_addrs = NULL; - if (eth_dev->data) { - internals = eth_dev->data->dev_private; - rte_kni_release(internals->kni); + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return rte_eth_dev_release_port(eth_dev); - rte_free(internals); - } - rte_free(eth_dev->data); + eth_kni_dev_stop(eth_dev); + + internals = eth_dev->data->dev_private; + ret = rte_kni_release(internals->kni); + if (ret) + PMD_LOG(WARNING, "Not able to release kni for %s", name); rte_eth_dev_release_port(eth_dev); @@ -519,3 +498,10 @@ static struct rte_vdev_driver eth_kni_drv = { RTE_PMD_REGISTER_VDEV(net_kni, eth_kni_drv); RTE_PMD_REGISTER_PARAM_STRING(net_kni, ETH_KNI_NO_REQUEST_THREAD_ARG "="); + +RTE_INIT(eth_kni_init_log) +{ + eth_kni_logtype = rte_log_register("pmd.net.kni"); + if (eth_kni_logtype >= 0) + rte_log_set_level(eth_kni_logtype, RTE_LOG_NOTICE); +}