net/cxgbe: fix jumbo frame flag condition
[dpdk.git] / lib / librte_pdump / rte_pdump.c
index 7816c72..d20e944 100644 (file)
 
 #include "rte_pdump.h"
 
-#define DEVICE_ID_SIZE 64
-/* Macros for printing using RTE_LOG */
-#define RTE_LOGTYPE_PDUMP RTE_LOGTYPE_USER1
+RTE_LOG_REGISTER(pdump_logtype, lib.pdump, NOTICE);
+
+/* Macro for printing using RTE_LOG */
+#define PDUMP_LOG(level, fmt, args...)                         \
+       rte_log(RTE_LOG_ ## level, pdump_logtype, "%s(): " fmt, \
+               __func__, ## args)
 
 /* Used for the multi-process communication */
 #define PDUMP_MP       "mp_pdump"
@@ -34,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;
@@ -68,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];
@@ -88,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)) {
-               RTE_LOG(DEBUG, PDUMP,
+               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);
        }
 }
 
@@ -127,9 +130,8 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
                cbs = &rx_cbs[port][qid];
                if (cbs && operation == ENABLE) {
                        if (cbs->cb) {
-                               RTE_LOG(ERR, PDUMP,
-                                       "failed to add rx callback for port=%d "
-                                       "and queue=%d, callback already exists\n",
+                               PDUMP_LOG(ERR,
+                                       "rx callback for port=%d queue=%d, already exists\n",
                                        port, qid);
                                return -EEXIST;
                        }
@@ -138,7 +140,7 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
                        cbs->cb = rte_eth_add_first_rx_callback(port, qid,
                                                                pdump_rx, cbs);
                        if (cbs->cb == NULL) {
-                               RTE_LOG(ERR, PDUMP,
+                               PDUMP_LOG(ERR,
                                        "failed to add rx callback, errno=%d\n",
                                        rte_errno);
                                return rte_errno;
@@ -148,15 +150,14 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
                        int ret;
 
                        if (cbs->cb == NULL) {
-                               RTE_LOG(ERR, PDUMP,
-                                       "failed to delete non existing rx "
-                                       "callback for port=%d and queue=%d\n",
+                               PDUMP_LOG(ERR,
+                                       "no existing rx callback for port=%d queue=%d\n",
                                        port, qid);
                                return -EINVAL;
                        }
                        ret = rte_eth_remove_rx_callback(port, qid, cbs->cb);
                        if (ret < 0) {
-                               RTE_LOG(ERR, PDUMP,
+                               PDUMP_LOG(ERR,
                                        "failed to remove rx callback, errno=%d\n",
                                        -ret);
                                return ret;
@@ -182,9 +183,8 @@ pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
                cbs = &tx_cbs[port][qid];
                if (cbs && operation == ENABLE) {
                        if (cbs->cb) {
-                               RTE_LOG(ERR, PDUMP,
-                                       "failed to add tx callback for port=%d "
-                                       "and queue=%d, callback already exists\n",
+                               PDUMP_LOG(ERR,
+                                       "tx callback for port=%d queue=%d, already exists\n",
                                        port, qid);
                                return -EEXIST;
                        }
@@ -193,7 +193,7 @@ pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
                        cbs->cb = rte_eth_add_tx_callback(port, qid, pdump_tx,
                                                                cbs);
                        if (cbs->cb == NULL) {
-                               RTE_LOG(ERR, PDUMP,
+                               PDUMP_LOG(ERR,
                                        "failed to add tx callback, errno=%d\n",
                                        rte_errno);
                                return rte_errno;
@@ -203,15 +203,14 @@ pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue,
                        int ret;
 
                        if (cbs->cb == NULL) {
-                               RTE_LOG(ERR, PDUMP,
-                                       "failed to delete non existing tx "
-                                       "callback for port=%d and queue=%d\n",
+                               PDUMP_LOG(ERR,
+                                       "no existing tx callback for port=%d queue=%d\n",
                                        port, qid);
                                return -EINVAL;
                        }
                        ret = rte_eth_remove_tx_callback(port, qid, cbs->cb);
                        if (ret < 0) {
-                               RTE_LOG(ERR, PDUMP,
+                               PDUMP_LOG(ERR,
                                        "failed to remove tx callback, errno=%d\n",
                                        -ret);
                                return ret;
@@ -240,7 +239,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)
                ret = rte_eth_dev_get_port_by_name(p->data.en_v1.device,
                                &port);
                if (ret < 0) {
-                       RTE_LOG(ERR, PDUMP,
+                       PDUMP_LOG(ERR,
                                "failed to get port id for device id=%s\n",
                                p->data.en_v1.device);
                        return -EINVAL;
@@ -252,7 +251,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)
                ret = rte_eth_dev_get_port_by_name(p->data.dis_v1.device,
                                &port);
                if (ret < 0) {
-                       RTE_LOG(ERR, PDUMP,
+                       PDUMP_LOG(ERR,
                                "failed to get port id for device id=%s\n",
                                p->data.dis_v1.device);
                        return -EINVAL;
@@ -268,7 +267,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)
 
                ret = rte_eth_dev_info_get(port, &dev_info);
                if (ret != 0) {
-                       RTE_LOG(ERR, PDUMP,
+                       PDUMP_LOG(ERR,
                                "Error during getting device (port %u) info: %s\n",
                                port, strerror(-ret));
                        return ret;
@@ -277,18 +276,18 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)
                nb_rx_q = dev_info.nb_rx_queues;
                nb_tx_q = dev_info.nb_tx_queues;
                if (nb_rx_q == 0 && flags & RTE_PDUMP_FLAG_RX) {
-                       RTE_LOG(ERR, PDUMP,
+                       PDUMP_LOG(ERR,
                                "number of rx queues cannot be 0\n");
                        return -EINVAL;
                }
                if (nb_tx_q == 0 && flags & RTE_PDUMP_FLAG_TX) {
-                       RTE_LOG(ERR, PDUMP,
+                       PDUMP_LOG(ERR,
                                "number of tx queues cannot be 0\n");
                        return -EINVAL;
                }
                if ((nb_tx_q == 0 || nb_rx_q == 0) &&
                        flags == RTE_PDUMP_FLAG_RXTX) {
-                       RTE_LOG(ERR, PDUMP,
+                       PDUMP_LOG(ERR,
                                "both tx&rx queues must be non zero\n");
                        return -EINVAL;
                }
@@ -324,7 +323,7 @@ pdump_server(const struct rte_mp_msg *mp_msg, const void *peer)
 
        /* recv client requests */
        if (mp_msg->len_param != sizeof(*cli_req)) {
-               RTE_LOG(ERR, PDUMP, "failed to recv from client\n");
+               PDUMP_LOG(ERR, "failed to recv from client\n");
                resp->err_value = -EINVAL;
        } else {
                cli_req = (const struct pdump_request *)mp_msg->param;
@@ -337,8 +336,8 @@ pdump_server(const struct rte_mp_msg *mp_msg, const void *peer)
        mp_resp.len_param = sizeof(*resp);
        mp_resp.num_fds = 0;
        if (rte_mp_reply(&mp_resp, peer) < 0) {
-               RTE_LOG(ERR, PDUMP, "failed to send to client:%s, %s:%d\n",
-                       strerror(rte_errno), __func__, __LINE__);
+               PDUMP_LOG(ERR, "failed to send to client:%s\n",
+                         strerror(rte_errno));
                return -1;
        }
 
@@ -348,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;
@@ -366,20 +367,21 @@ static int
 pdump_validate_ring_mp(struct rte_ring *ring, struct rte_mempool *mp)
 {
        if (ring == NULL || mp == NULL) {
-               RTE_LOG(ERR, PDUMP, "NULL ring or mempool are passed %s:%d\n",
-                       __func__, __LINE__);
+               PDUMP_LOG(ERR, "NULL ring or mempool\n");
                rte_errno = EINVAL;
                return -1;
        }
        if (mp->flags & MEMPOOL_F_SP_PUT || mp->flags & MEMPOOL_F_SC_GET) {
-               RTE_LOG(ERR, PDUMP, "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) {
-               RTE_LOG(ERR, PDUMP, "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;
        }
@@ -392,7 +394,7 @@ pdump_validate_flags(uint32_t flags)
 {
        if (flags != RTE_PDUMP_FLAG_RX && flags != RTE_PDUMP_FLAG_TX &&
                flags != RTE_PDUMP_FLAG_RXTX) {
-               RTE_LOG(ERR, PDUMP,
+               PDUMP_LOG(ERR,
                        "invalid flags, should be either rx/tx/rxtx\n");
                rte_errno = EINVAL;
                return -1;
@@ -407,17 +409,15 @@ pdump_validate_port(uint16_t port, char *name)
        int ret = 0;
 
        if (port >= RTE_MAX_ETHPORTS) {
-               RTE_LOG(ERR, PDUMP, "Invalid port id %u, %s:%d\n", port,
-                       __func__, __LINE__);
+               PDUMP_LOG(ERR, "Invalid port id %u\n", port);
                rte_errno = EINVAL;
                return -1;
        }
 
        ret = rte_eth_dev_get_name_by_port(port, name);
        if (ret < 0) {
-               RTE_LOG(ERR, PDUMP,
-                       "port id to name mapping failed for port id=%u, %s:%d\n",
-                       port, __func__, __LINE__);
+               PDUMP_LOG(ERR, "port %u to name mapping failed\n",
+                         port);
                rte_errno = EINVAL;
                return -1;
        }
@@ -472,7 +472,7 @@ pdump_prepare_client_request(char *device, uint16_t queue,
        }
 
        if (ret < 0)
-               RTE_LOG(ERR, PDUMP,
+               PDUMP_LOG(ERR,
                        "client request for pdump enable/disable failed\n");
        return ret;
 }
@@ -483,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)
@@ -529,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)