]> git.droids-corp.org - dpdk.git/commitdiff
app/testpmd: fix metadata API and Tx insertion
authorDekel Peled <dekelp@mellanox.com>
Wed, 24 Oct 2018 06:21:59 +0000 (09:21 +0300)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 26 Oct 2018 20:14:06 +0000 (22:14 +0200)
Previous patch introduces the Tx metadata feature, with unnecessary
restrictions on data entry.
It also used the metadata in txonly fwd engine only.

This fix removes the data entry restrictions on metadata item.
It also implements callback function to add the metadata in every
Tx packet, sent by any fwd engine.

Fixes: c18feafa193c ("app/testpmd: support metadata as flow rule item")
Signed-off-by: Dekel Peled <dekelp@mellanox.com>
Acked-by: Ori Kam <orika@mellanox.com>
app/test-pmd/cmdline.c
app/test-pmd/cmdline_flow.c
app/test-pmd/testpmd.h
app/test-pmd/txonly.c
app/test-pmd/util.c

index 86088fd534fba311ccc85f19adc04800e8f418c4..4856d23657e6fa875b3559d1352d12bdb25e0e22 100644 (file)
@@ -18343,6 +18343,11 @@ cmd_config_tx_metadata_specific_parsed(void *parsed_result,
        if (port_id_is_invalid(res->port_id, ENABLED_WARN))
                return;
        ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
+       /* Add/remove callback to insert valid metadata in every Tx packet. */
+       if (ports[res->port_id].tx_metadata)
+               add_tx_md_callback(res->port_id);
+       else
+               remove_tx_md_callback(res->port_id);
 }
 
 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
index d1c370e36587553e8d006826af3b2988b750af36..23ea7cc8294988710c426e49858a6fe1f739e1ec 100644 (file)
@@ -570,11 +570,6 @@ static const enum index item_param[] = {
        ZERO,
 };
 
-static const enum index item_param_is[] = {
-       ITEM_PARAM_IS,
-       ZERO,
-};
-
 static const enum index next_item[] = {
        ITEM_END,
        ITEM_VOID,
@@ -2140,7 +2135,7 @@ static const struct token token_list[] = {
        [ITEM_META_DATA] = {
                .name = "data",
                .help = "metadata value",
-               .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param_is),
+               .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param),
                .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_meta,
                                                  data, "\xff\xff\xff\xff")),
        },
index 0ac886944c3c2685073321dbf5e49e4a3ea39a34..ca2320c4641f9d8a9a268fae712fb364962f8bc8 100644 (file)
@@ -198,6 +198,7 @@ struct rte_port {
 #endif
        /**< metadata value to insert in Tx packets. */
        rte_be32_t              tx_metadata;
+       const struct rte_eth_rxtx_callback *tx_set_md_cb[MAX_QUEUE_ID+1];
 };
 
 /**
@@ -843,6 +844,12 @@ void add_tx_dump_callbacks(portid_t portid);
 void remove_tx_dump_callbacks(portid_t portid);
 void configure_rxtx_dump_callbacks(uint16_t verbose);
 
+uint16_t tx_pkt_set_md(uint16_t port_id, __rte_unused uint16_t queue,
+                      struct rte_mbuf *pkts[], uint16_t nb_pkts,
+                      __rte_unused void *user_param);
+void add_tx_md_callback(portid_t portid);
+void remove_tx_md_callback(portid_t portid);
+
 /*
  * Work-around of a compilation error with ICC on invocations of the
  * rte_be_to_cpu_16() function.
index fae84cac2bcb6cdb5b688018463aab1c1844f823..1f08b6ed37a25025bf8514eba5306f312d9a45cf 100644 (file)
@@ -253,15 +253,6 @@ pkt_burst_transmit(struct fwd_stream *fs)
                pkt->l2_len = sizeof(struct ether_hdr);
                pkt->l3_len = sizeof(struct ipv4_hdr);
                pkts_burst[nb_pkt] = pkt;
-
-               /*
-                * If user configured metadata value add it to packet
-                * and set ol_flags accordingly
-                */
-               if (ports[fs->tx_port].tx_metadata) {
-                       pkt->tx_metadata = ports[fs->tx_port].tx_metadata;
-                       pkt->ol_flags |= PKT_TX_METADATA;
-               }
        }
        nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt);
        /*
index f4125df7a3f9d9cfe7e5fef655ecbc50119f8d3e..687bfa49656e4f5817dfea8186f78ada755e2ff9 100644 (file)
@@ -166,3 +166,54 @@ dump_tx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
        dump_pkt_burst(port_id, queue, pkts, nb_pkts, 0);
        return nb_pkts;
 }
+
+uint16_t
+tx_pkt_set_md(uint16_t port_id, __rte_unused uint16_t queue,
+             struct rte_mbuf *pkts[], uint16_t nb_pkts,
+             __rte_unused void *user_param)
+{
+       uint16_t i = 0;
+
+       /*
+        * Add metadata value to every Tx packet,
+        * and set ol_flags accordingly.
+        */
+       for (i = 0; i < nb_pkts; i++) {
+               pkts[i]->tx_metadata = ports[port_id].tx_metadata;
+               pkts[i]->ol_flags |= PKT_TX_METADATA;
+       }
+       return nb_pkts;
+}
+
+void
+add_tx_md_callback(portid_t portid)
+{
+       struct rte_eth_dev_info dev_info;
+       uint16_t queue;
+
+       if (port_id_is_invalid(portid, ENABLED_WARN))
+               return;
+       rte_eth_dev_info_get(portid, &dev_info);
+       for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
+               if (!ports[portid].tx_set_md_cb[queue])
+                       ports[portid].tx_set_md_cb[queue] =
+                               rte_eth_add_tx_callback(portid, queue,
+                                                       tx_pkt_set_md, NULL);
+}
+
+void
+remove_tx_md_callback(portid_t portid)
+{
+       struct rte_eth_dev_info dev_info;
+       uint16_t queue;
+
+       if (port_id_is_invalid(portid, ENABLED_WARN))
+               return;
+       rte_eth_dev_info_get(portid, &dev_info);
+       for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
+               if (ports[portid].tx_set_md_cb[queue]) {
+                       rte_eth_remove_tx_callback(portid, queue,
+                               ports[portid].tx_set_md_cb[queue]);
+                       ports[portid].tx_set_md_cb[queue] = NULL;
+               }
+}