vhost: add APIs for datapath configuration
[dpdk.git] / lib / librte_pdump / rte_pdump.c
index a580a6a..ad6efc6 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2016 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) 2016 Intel Corporation
  */
 
 #include <sys/socket.h>
@@ -46,7 +17,7 @@
 #include <rte_lcore.h>
 #include <rte_log.h>
 #include <rte_errno.h>
-#include <rte_pci.h>
+#include <rte_string_fns.h>
 
 #include "rte_pdump.h"
 
@@ -105,7 +76,7 @@ struct pdump_response {
 static struct pdump_rxtx_cbs {
        struct rte_ring *ring;
        struct rte_mempool *mp;
-       struct rte_eth_rxtx_callback *cb;
+       const struct rte_eth_rxtx_callback *cb;
        void *filter;
 } rx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT],
 tx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT];
@@ -140,7 +111,7 @@ pdump_pktmbuf_copy(struct rte_mbuf *m, struct rte_mempool *mp)
 {
        struct rte_mbuf *m_dup, *seg, **prev;
        uint32_t pktlen;
-       uint8_t nseg;
+       uint16_t nseg;
 
        m_dup = rte_pktmbuf_alloc(mp);
        if (unlikely(m_dup == NULL))
@@ -154,6 +125,8 @@ pdump_pktmbuf_copy(struct rte_mbuf *m, struct rte_mempool *mp)
        do {
                nseg++;
                if (pdump_pktmbuf_copy_data(seg, m) < 0) {
+                       if (seg != m_dup)
+                               rte_pktmbuf_free_seg(seg);
                        rte_pktmbuf_free(m_dup);
                        return NULL;
                }
@@ -197,7 +170,7 @@ pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
                        dup_bufs[d_pkts++] = p;
        }
 
-       ring_enq = rte_ring_enqueue_burst(ring, (void *)dup_bufs, d_pkts);
+       ring_enq = rte_ring_enqueue_burst(ring, (void *)dup_bufs, d_pkts, NULL);
        if (unlikely(ring_enq < d_pkts)) {
                RTE_LOG(DEBUG, PDUMP,
                        "only %d of packets enqueued to ring\n", ring_enq);
@@ -208,7 +181,7 @@ pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
 }
 
 static uint16_t
-pdump_rx(uint8_t port __rte_unused, uint16_t qidx __rte_unused,
+pdump_rx(uint16_t port __rte_unused, uint16_t qidx __rte_unused,
        struct rte_mbuf **pkts, uint16_t nb_pkts,
        uint16_t max_pkts __rte_unused,
        void *user_params)
@@ -218,7 +191,7 @@ pdump_rx(uint8_t port __rte_unused, uint16_t qidx __rte_unused,
 }
 
 static uint16_t
-pdump_tx(uint8_t port __rte_unused, uint16_t qidx __rte_unused,
+pdump_tx(uint16_t port __rte_unused, uint16_t qidx __rte_unused,
                struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
 {
        pdump_copy(pkts, nb_pkts, user_params);
@@ -226,7 +199,7 @@ pdump_tx(uint8_t port __rte_unused, uint16_t qidx __rte_unused,
 }
 
 static int
-pdump_regitser_rx_callbacks(uint16_t end_q, uint8_t port, uint16_t queue,
+pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
                                struct rte_ring *ring, struct rte_mempool *mp,
                                uint16_t operation)
 {
@@ -280,7 +253,7 @@ pdump_regitser_rx_callbacks(uint16_t end_q, uint8_t port, uint16_t queue,
 }
 
 static int
-pdump_regitser_tx_callbacks(uint16_t end_q, uint8_t port, uint16_t queue,
+pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
                                struct rte_ring *ring, struct rte_mempool *mp,
                                uint16_t operation)
 {
@@ -338,7 +311,7 @@ static int
 set_pdump_rxtx_cbs(struct pdump_request *p)
 {
        uint16_t nb_rx_q = 0, nb_tx_q = 0, end_q, queue;
-       uint8_t port;
+       uint16_t port;
        int ret = 0;
        uint32_t flags;
        uint16_t operation;
@@ -352,7 +325,7 @@ set_pdump_rxtx_cbs(struct pdump_request *p)
                                &port);
                if (ret < 0) {
                        RTE_LOG(ERR, PDUMP,
-                               "failed to get potid for device id=%s\n",
+                               "failed to get port id for device id=%s\n",
                                p->data.en_v1.device);
                        return -EINVAL;
                }
@@ -364,7 +337,7 @@ set_pdump_rxtx_cbs(struct pdump_request *p)
                                &port);
                if (ret < 0) {
                        RTE_LOG(ERR, PDUMP,
-                               "failed to get potid for device id=%s\n",
+                               "failed to get port id for device id=%s\n",
                                p->data.dis_v1.device);
                        return -EINVAL;
                }
@@ -401,7 +374,7 @@ set_pdump_rxtx_cbs(struct pdump_request *p)
        /* register RX callback */
        if (flags & RTE_PDUMP_FLAG_RX) {
                end_q = (queue == RTE_PDUMP_ALL_QUEUES) ? nb_rx_q : queue + 1;
-               ret = pdump_regitser_rx_callbacks(end_q, port, queue, ring, mp,
+               ret = pdump_register_rx_callbacks(end_q, port, queue, ring, mp,
                                                        operation);
                if (ret < 0)
                        return ret;
@@ -410,7 +383,7 @@ set_pdump_rxtx_cbs(struct pdump_request *p)
        /* register TX callback */
        if (flags & RTE_PDUMP_FLAG_TX) {
                end_q = (queue == RTE_PDUMP_ALL_QUEUES) ? nb_tx_q : queue + 1;
-               ret = pdump_regitser_tx_callbacks(end_q, port, queue, ring, mp,
+               ret = pdump_register_tx_callbacks(end_q, port, queue, ring, mp,
                                                        operation);
                if (ret < 0)
                        return ret;
@@ -429,9 +402,9 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)
        int ret = 0;
 
        if (type == RTE_PDUMP_SOCKET_SERVER && server_socket_dir[0] != 0)
-               snprintf(dir, sizeof(dir), "%s", server_socket_dir);
+               strlcpy(dir, server_socket_dir, sizeof(dir));
        else if (type == RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0] != 0)
-               snprintf(dir, sizeof(dir), "%s", client_socket_dir);
+               strlcpy(dir, client_socket_dir, sizeof(dir));
        else {
                if (getuid() != 0) {
                        dir_home = getenv(SOCKET_PATH_HOME);
@@ -580,7 +553,7 @@ rte_pdump_init(const char *path)
        if (ret != 0) {
                RTE_LOG(ERR, PDUMP,
                        "Failed to create the pdump thread:%s, %s:%d\n",
-                       strerror(errno), __func__, __LINE__);
+                       strerror(ret), __func__, __LINE__);
                return -1;
        }
        /* Set thread_name for aid in debugging. */
@@ -603,7 +576,7 @@ rte_pdump_uninit(void)
        if (ret != 0) {
                RTE_LOG(ERR, PDUMP,
                        "Failed to cancel the pdump thread:%s, %s:%d\n",
-                       strerror(errno), __func__, __LINE__);
+                       strerror(ret), __func__, __LINE__);
                return -1;
        }
 
@@ -740,7 +713,7 @@ pdump_validate_ring_mp(struct rte_ring *ring, struct rte_mempool *mp)
                rte_errno = EINVAL;
                return -1;
        }
-       if (ring->prod.sp_enqueue || ring->cons.sc_dequeue) {
+       if (ring->prod.single || ring->cons.single) {
                RTE_LOG(ERR, PDUMP, "ring with either SP or SC settings"
                " is not valid for pdump, should have MP and MC settings\n");
                rte_errno = EINVAL;
@@ -765,7 +738,7 @@ pdump_validate_flags(uint32_t flags)
 }
 
 static int
-pdump_validate_port(uint8_t port, char *name)
+pdump_validate_port(uint16_t port, char *name)
 {
        int ret = 0;
 
@@ -829,7 +802,7 @@ pdump_prepare_client_request(char *device, uint16_t queue,
 }
 
 int
-rte_pdump_enable(uint8_t port, uint16_t queue, uint32_t flags,
+rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags,
                        struct rte_ring *ring,
                        struct rte_mempool *mp,
                        void *filter)
@@ -877,7 +850,7 @@ rte_pdump_enable_by_deviceid(char *device_id, uint16_t queue,
 }
 
 int
-rte_pdump_disable(uint8_t port, uint16_t queue, uint32_t flags)
+rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags)
 {
        int ret = 0;
        char name[DEVICE_ID_SIZE];
@@ -919,10 +892,10 @@ rte_pdump_set_socket_dir(const char *path, enum rte_pdump_socktype type)
        if (path != NULL) {
                if (type == RTE_PDUMP_SOCKET_SERVER) {
                        count = sizeof(server_socket_dir);
-                       ret = snprintf(server_socket_dir, count, "%s", path);
+                       ret = strlcpy(server_socket_dir, path, count);
                } else {
                        count = sizeof(client_socket_dir);
-                       ret = snprintf(client_socket_dir, count, "%s", path);
+                       ret = strlcpy(client_socket_dir, path, count);
                }
 
                if (ret < 0  || ret >= count) {