drivers/net: do not use private ethdev data
[dpdk.git] / drivers / net / pcap / rte_eth_pcap.c
index defb3b4..8740d52 100644 (file)
@@ -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 <time.h>
 #include <pcap.h>
 
 #include <rte_cycles.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
 #include <rte_ethdev_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
-#include <rte_vdev.h>
+#include <rte_bus_vdev.h>
 
 #define RTE_ETH_PCAP_SNAPSHOT_LEN 65535
 #define RTE_ETH_PCAP_SNAPLEN ETHER_MAX_JUMBO_FRAME_LEN
@@ -75,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];
@@ -124,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
@@ -411,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;
 }
 
@@ -560,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;
@@ -592,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
@@ -797,27 +773,16 @@ pmd_init_internals(struct rte_vdev_device *vdev,
                struct pmd_internals **internals,
                struct rte_eth_dev **eth_dev)
 {
-       struct rte_eth_dev_data *data = NULL;
+       struct rte_eth_dev_data *data;
        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",
+       RTE_LOG(INFO, PMD, "Creating pcap-backed ethdev on numa socket %d\n",
                numa_node);
 
-       /* 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)
-               return -1;
-
        /* reserve an ethdev entry */
        *eth_dev = rte_eth_vdev_allocate(vdev, sizeof(**internals));
-       if (*eth_dev == NULL) {
-               rte_free(data);
+       if (!(*eth_dev))
                return -1;
-       }
 
        /* now put it all together
         * - store queue data in internals,
@@ -826,7 +791,7 @@ pmd_init_internals(struct rte_vdev_device *vdev,
         * - and point eth_dev structure to new eth_dev_data structure
         */
        *internals = (*eth_dev)->data->dev_private;
-       rte_memcpy(data, (*eth_dev)->data, sizeof(*data));
+       data = (*eth_dev)->data;
        data->nb_rx_queues = (uint16_t)nb_rx_queues;
        data->nb_tx_queues = (uint16_t)nb_tx_queues;
        data->dev_link = pmd_link;
@@ -836,9 +801,7 @@ pmd_init_internals(struct rte_vdev_device *vdev,
         * NOTE: we'll replace the data element, of originally allocated
         * eth_dev so the rings are local per-process
         */
-       (*eth_dev)->data = data;
        (*eth_dev)->dev_ops = &ops;
-       data->dev_flags = RTE_ETH_DEV_DETACHABLE;
 
        return 0;
 }
@@ -1033,7 +996,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)
@@ -1045,7 +1008,6 @@ pmd_pcap_remove(struct rte_vdev_device *dev)
                return -1;
 
        rte_free(eth_dev->data->dev_private);
-       rte_free(eth_dev->data);
 
        rte_eth_dev_release_port(eth_dev);