In test-pmd (rxonly.c), the code is able to dump the list of ol_flags.
The issue is that the list of flags in the application has to be
synchronized with the flags defined in rte_mbuf.h.

This patch introduces 2 new functions rte_get_rx_ol_flag_name()
and rte_get_tx_ol_flag_name() that returns the name of a flag from
its mask. It also fixes rxonly.c to use this new functions and to
display the proper flags.

Signed-off-by: Olivier Matz <olivier.matz at 6wind.com>
---
 app/test-pmd/rxonly.c      | 36 ++++++++++--------------------------
 lib/librte_mbuf/rte_mbuf.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf.h | 22 ++++++++++++++++++++++
 3 files changed, 77 insertions(+), 26 deletions(-)

diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c
index 9ad1df6..51a530a 100644
--- a/app/test-pmd/rxonly.c
+++ b/app/test-pmd/rxonly.c
@@ -71,26 +71,6 @@

 #include "testpmd.h"

-#define MAX_PKT_RX_FLAGS 13
-static const char *pkt_rx_flag_names[MAX_PKT_RX_FLAGS] = {
-       "VLAN_PKT",
-       "RSS_HASH",
-       "PKT_RX_FDIR",
-       "IP_CKSUM",
-       "IP_CKSUM_BAD",
-
-       "IPV4_HDR",
-       "IPV4_HDR_EXT",
-       "IPV6_HDR",
-       "IPV6_HDR_EXT",
-
-       "IEEE1588_PTP",
-       "IEEE1588_TMST",
-
-       "TUNNEL_IPV4_HDR",
-       "TUNNEL_IPV6_HDR",
-};
-
 static inline void
 print_ether_addr(const char *what, struct ether_addr *eth_addr)
 {
@@ -214,12 +194,16 @@ pkt_burst_receive(struct fwd_stream *fs)
                printf(" - Receive queue=0x%x", (unsigned) fs->rx_queue);
                printf("\n");
                if (ol_flags != 0) {
-                       int rxf;
-
-                       for (rxf = 0; rxf < MAX_PKT_RX_FLAGS; rxf++) {
-                               if (ol_flags & (1 << rxf))
-                                       printf("  PKT_RX_%s\n",
-                                              pkt_rx_flag_names[rxf]);
+                       unsigned rxf;
+                       const char *name;
+
+                       for (rxf = 0; rxf < sizeof(mb->ol_flags) * 8; rxf++) {
+                               if ((ol_flags & (1ULL << rxf)) == 0)
+                                       continue;
+                               name = rte_get_rx_ol_flag_name(1ULL << rxf);
+                               if (name == NULL)
+                                       continue;
+                               printf("  %s\n", name);
                        }
                }
                rte_pktmbuf_free(mb);
diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
index 52e7574..5cd9137 100644
--- a/lib/librte_mbuf/rte_mbuf.c
+++ b/lib/librte_mbuf/rte_mbuf.c
@@ -196,3 +196,48 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, 
unsigned dump_len)
                nb_segs --;
        }
 }
+
+/*
+ * Get the name of a RX offload flag
+ */
+const char *rte_get_rx_ol_flag_name(uint64_t mask)
+{
+       switch (mask) {
+       case PKT_RX_VLAN_PKT: return "PKT_RX_VLAN_PKT";
+       case PKT_RX_RSS_HASH: return "PKT_RX_RSS_HASH";
+       case PKT_RX_FDIR: return "PKT_RX_FDIR";
+       case PKT_RX_L4_CKSUM_BAD: return "PKT_RX_L4_CKSUM_BAD";
+       case PKT_RX_IP_CKSUM_BAD: return "PKT_RX_IP_CKSUM_BAD";
+       /* case PKT_RX_EIP_CKSUM_BAD: return "PKT_RX_EIP_CKSUM_BAD"; */
+       /* case PKT_RX_OVERSIZE: return "PKT_RX_OVERSIZE"; */
+       /* case PKT_RX_HBUF_OVERFLOW: return "PKT_RX_HBUF_OVERFLOW"; */
+       /* case PKT_RX_RECIP_ERR: return "PKT_RX_RECIP_ERR"; */
+       /* case PKT_RX_MAC_ERR: return "PKT_RX_MAC_ERR"; */
+       case PKT_RX_IPV4_HDR: return "PKT_RX_IPV4_HDR";
+       case PKT_RX_IPV4_HDR_EXT: return "PKT_RX_IPV4_HDR_EXT";
+       case PKT_RX_IPV6_HDR: return "PKT_RX_IPV6_HDR";
+       case PKT_RX_IPV6_HDR_EXT: return "PKT_RX_IPV6_HDR_EXT";
+       case PKT_RX_IEEE1588_PTP: return "PKT_RX_IEEE1588_PTP";
+       case PKT_RX_IEEE1588_TMST: return "PKT_RX_IEEE1588_TMST";
+       case PKT_RX_TUNNEL_IPV4_HDR: return "PKT_RX_TUNNEL_IPV4_HDR";
+       case PKT_RX_TUNNEL_IPV6_HDR: return "PKT_RX_TUNNEL_IPV6_HDR";
+       default: return NULL;
+       }
+}
+
+/*
+ * Get the name of a TX offload flag
+ */
+const char *rte_get_tx_ol_flag_name(uint64_t mask)
+{
+       switch (mask) {
+       case PKT_TX_VLAN_PKT: return "PKT_TX_VLAN_PKT";
+       case PKT_TX_IP_CKSUM: return "PKT_TX_IP_CKSUM";
+       case PKT_TX_TCP_CKSUM: return "PKT_TX_TCP_CKSUM";
+       case PKT_TX_SCTP_CKSUM: return "PKT_TX_SCTP_CKSUM";
+       case PKT_TX_UDP_CKSUM: return "PKT_TX_UDP_CKSUM";
+       case PKT_TX_IEEE1588_TMST: return "PKT_TX_IEEE1588_TMST";
+       case PKT_TX_VXLAN_CKSUM: return "PKT_TX_VXLAN_CKSUM";
+       default: return NULL;
+       }
+}
diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index 68fb988..e76617f 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -129,6 +129,28 @@ extern "C" {
 /* Use final bit of flags to indicate a control mbuf */
 #define CTRL_MBUF_FLAG       (1ULL << 63) /**< Mbuf contains control data */

+/**
+ * Get the name of a RX offload flag
+ *
+ * @param mask
+ *   The mask describing the flag.
+ * @return
+ *   The name of this flag, or NULL if it's not a valid RX flag.
+ */
+const char *rte_get_rx_ol_flag_name(uint64_t mask);
+
+/**
+ * Get the name of a TX offload flag
+ *
+ * @param mask
+ *   The mask describing the flag. Usually only one bit must be set.
+ *   Several bits can be given if they belong to the same mask.
+ *   Ex: PKT_TX_L4_MASK.
+ * @return
+ *   The name of this flag, or NULL if it's not a valid TX flag.
+ */
+const char *rte_get_tx_ol_flag_name(uint64_t mask);
+
 /* define a set of marker types that can be used to refer to set points in the
  * mbuf */
 typedef void    *MARKER[0];   /**< generic marker for a point in a structure */
-- 
2.1.0

Reply via email to