net/bnxt: refactor init/uninit
[dpdk.git] / lib / librte_pdump / rte_pdump.c
index 8a01ac5..d20e944 100644 (file)
 
 #include "rte_pdump.h"
 
-#define DEVICE_ID_SIZE 64
+RTE_LOG_REGISTER(pdump_logtype, lib.pdump, NOTICE);
 
 /* Macro for printing using RTE_LOG */
-static int pdump_logtype;
 #define PDUMP_LOG(level, fmt, args...)                         \
        rte_log(RTE_LOG_ ## level, pdump_logtype, "%s(): " fmt, \
                __func__, ## args)
@@ -38,14 +37,14 @@ struct pdump_request {
        uint32_t flags;
        union pdump_data {
                struct enable_v1 {
-                       char device[DEVICE_ID_SIZE];
+                       char device[RTE_DEV_NAME_MAX_LEN];
                        uint16_t queue;
                        struct rte_ring *ring;
                        struct rte_mempool *mp;
                        void *filter;
                } en_v1;
                struct disable_v1 {
-                       char device[DEVICE_ID_SIZE];
+                       char device[RTE_DEV_NAME_MAX_LEN];
                        uint16_t queue;
                        struct rte_ring *ring;
                        struct rte_mempool *mp;
@@ -72,7 +71,7 @@ tx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT];
 static inline void
 pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
 {
-       unsigned i;
+       unsigned int i;
        int ring_enq;
        uint16_t d_pkts = 0;
        struct rte_mbuf *dup_bufs[nb_pkts];
@@ -92,11 +91,11 @@ pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params)
 
        ring_enq = rte_ring_enqueue_burst(ring, (void *)dup_bufs, d_pkts, NULL);
        if (unlikely(ring_enq < d_pkts)) {
+               unsigned int drops = d_pkts - ring_enq;
+
                PDUMP_LOG(DEBUG,
                        "only %d of packets enqueued to ring\n", ring_enq);
-               do {
-                       rte_pktmbuf_free(dup_bufs[ring_enq]);
-               } while (++ring_enq < d_pkts);
+               rte_pktmbuf_free_bulk(&dup_bufs[ring_enq], drops);
        }
 }
 
@@ -132,8 +131,7 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
                if (cbs && operation == ENABLE) {
                        if (cbs->cb) {
                                PDUMP_LOG(ERR,
-                                       "failed to add rx callback for port=%d "
-                                       "and queue=%d, callback already exists\n",
+                                       "rx callback for port=%d queue=%d, already exists\n",
                                        port, qid);
                                return -EEXIST;
                        }
@@ -153,8 +151,7 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 
                        if (cbs->cb == NULL) {
                                PDUMP_LOG(ERR,
-                                       "failed to delete non existing rx "
-                                       "callback for port=%d and queue=%d\n",
+                                       "no existing rx callback for port=%d queue=%d\n",
                                        port, qid);
                                return -EINVAL;
                        }
@@ -187,8 +184,7 @@ pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
                if (cbs && operation == ENABLE) {
                        if (cbs->cb) {
                                PDUMP_LOG(ERR,
-                                       "failed to add tx callback for port=%d "
-                                       "and queue=%d, callback already exists\n",
+                                       "tx callback for port=%d queue=%d, already exists\n",
                                        port, qid);
                                return -EEXIST;
                        }
@@ -208,8 +204,7 @@ pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
 
                        if (cbs->cb == NULL) {
                                PDUMP_LOG(ERR,
-                                       "failed to delete non existing tx "
-                                       "callback for port=%d and queue=%d\n",
+                                       "no existing tx callback for port=%d queue=%d\n",
                                        port, qid);
                                return -EINVAL;
                        }
@@ -352,7 +347,9 @@ pdump_server(const struct rte_mp_msg *mp_msg, const void *peer)
 int
 rte_pdump_init(void)
 {
-       int ret = rte_mp_action_register(PDUMP_MP, pdump_server);
+       int ret;
+
+       ret = rte_mp_action_register(PDUMP_MP, pdump_server);
        if (ret && rte_errno != ENOTSUP)
                return -1;
        return 0;
@@ -375,14 +372,16 @@ pdump_validate_ring_mp(struct rte_ring *ring, struct rte_mempool *mp)
                return -1;
        }
        if (mp->flags & MEMPOOL_F_SP_PUT || mp->flags & MEMPOOL_F_SC_GET) {
-               PDUMP_LOG(ERR, "mempool with either SP or SC settings"
-               " is not valid for pdump, should have MP and MC settings\n");
+               PDUMP_LOG(ERR,
+                         "mempool with SP or SC set not valid for pdump,"
+                         "must have MP and MC set\n");
                rte_errno = EINVAL;
                return -1;
        }
-       if (ring->prod.single || ring->cons.single) {
-               PDUMP_LOG(ERR, "ring with either SP or SC settings"
-               " is not valid for pdump, should have MP and MC settings\n");
+       if (rte_ring_is_prod_single(ring) || rte_ring_is_cons_single(ring)) {
+               PDUMP_LOG(ERR,
+                         "ring with SP or SC set is not valid for pdump,"
+                         "must have MP and MC set\n");
                rte_errno = EINVAL;
                return -1;
        }
@@ -484,9 +483,8 @@ rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags,
                        struct rte_mempool *mp,
                        void *filter)
 {
-
-       int ret = 0;
-       char name[DEVICE_ID_SIZE];
+       int ret;
+       char name[RTE_DEV_NAME_MAX_LEN];
 
        ret = pdump_validate_port(port, name);
        if (ret < 0)
@@ -530,7 +528,7 @@ int
 rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags)
 {
        int ret = 0;
-       char name[DEVICE_ID_SIZE];
+       char name[RTE_DEV_NAME_MAX_LEN];
 
        ret = pdump_validate_port(port, name);
        if (ret < 0)
@@ -560,10 +558,3 @@ rte_pdump_disable_by_deviceid(char *device_id, uint16_t queue,
 
        return ret;
 }
-
-RTE_INIT(pdump_log)
-{
-       pdump_logtype = rte_log_register("lib.pdump");
-       if (pdump_logtype >= 0)
-               rte_log_set_level(pdump_logtype, RTE_LOG_NOTICE);
-}