X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fpcap%2Frte_eth_pcap.c;h=c1571e1fe9d5915e5aa76fc7c94a297071e16b5c;hb=1e4a3cf6fa4c7a53b152c1221891c94c2da6d467;hp=05cbd47b3c9bc7c0e95474cc90b358be058a2d35;hpb=5d2aa461cbcae1b5ede5cee0b0b3a1228c4afc59;p=dpdk.git diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index 05cbd47b3c..c1571e1fe9 100644 --- a/drivers/net/pcap/rte_eth_pcap.c +++ b/drivers/net/pcap/rte_eth_pcap.c @@ -1,35 +1,7 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. - * Copyright(c) 2014 6WIND S.A. - * 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) 2010-2016 Intel Corporation. + * Copyright(c) 2014 6WIND S.A. + * All rights reserved. */ #include @@ -39,11 +11,12 @@ #include #include -#include +#include +#include #include #include #include -#include +#include #define RTE_ETH_PCAP_SNAPSHOT_LEN 65535 #define RTE_ETH_PCAP_SNAPLEN ETHER_MAX_JUMBO_FRAME_LEN @@ -74,7 +47,7 @@ struct queue_stat { struct pcap_rx_queue { pcap_t *pcap; - uint8_t in_port; + uint16_t in_port; struct rte_mempool *mb_pool; struct queue_stat rx_stat; char name[PATH_MAX]; @@ -123,7 +96,7 @@ static 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_FIXED, + .link_autoneg = ETH_LINK_AUTONEG, }; static int @@ -410,11 +383,13 @@ open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper) /* The dumper is created using the previous pcap_t reference */ *dumper = pcap_dump_open(tx_pcap, pcap_filename); if (*dumper == NULL) { + pcap_close(tx_pcap); RTE_LOG(ERR, PMD, "Couldn't open %s for writing.\n", pcap_filename); return -1; } + pcap_close(tx_pcap); return 0; } @@ -559,7 +534,7 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->min_rx_bufsize = 0; } -static void +static int eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { unsigned int i; @@ -591,6 +566,8 @@ eth_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 @@ -790,15 +767,18 @@ 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; - RTE_LOG(INFO, PMD, "Creating pcap-backed ethdev on numa socket %u\n", + name = rte_vdev_device_name(vdev); + RTE_LOG(INFO, PMD, "Creating pcap-backed ethdev on numa socket %d\n", numa_node); /* now do all data allocation - for eth_dev structure @@ -806,17 +786,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 +801,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 +814,16 @@ 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 +835,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 +873,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 +994,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: @@ -1041,7 +1008,7 @@ pmd_pcap_remove(struct rte_vdev_device *dev) { struct rte_eth_dev *eth_dev = NULL; - RTE_LOG(INFO, PMD, "Closing pcap ethdev on numa socket %u\n", + RTE_LOG(INFO, PMD, "Closing pcap ethdev on numa socket %d\n", rte_socket_id()); if (!dev)