eal: introduce macro for always inline
[dpdk.git] / examples / ip_pipeline / pipeline / pipeline_passthrough_be.c
index 83a16c2..8cb2f0c 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,7 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include <string.h>
 
 #include <rte_common.h>
 
 #include "pipeline_passthrough_be.h"
 #include "pipeline_actions_common.h"
+#include "parser.h"
 #include "hash_func.h"
 
-enum flow_key_type {
-       FLOW_KEY_QINQ,
-       FLOW_KEY_IPV4_5TUPLE,
-       FLOW_KEY_IPV6_5TUPLE,
-};
+#define SWAP_DIM (PIPELINE_PASSTHROUGH_SWAP_N_FIELDS_MAX * \
+       (PIPELINE_PASSTHROUGH_SWAP_FIELD_SIZE_MAX / sizeof(uint64_t)))
 
 struct pipeline_passthrough {
        struct pipeline p;
-
-       uint32_t key_type_valid;
-       enum flow_key_type key_type;
-       uint32_t key_offset_rd;
-       uint32_t key_offset_wr;
-       uint32_t hash_offset;
-
+       struct pipeline_passthrough_params params;
        rte_table_hash_op_hash f_hash;
-       rte_pipeline_port_in_action_handler f_port_in_ah;
+       uint32_t swap_field0_offset[SWAP_DIM];
+       uint32_t swap_field1_offset[SWAP_DIM];
+       uint64_t swap_field_mask[SWAP_DIM];
+       uint32_t swap_n_fields;
 } __rte_cache_aligned;
 
 static pipeline_msg_req_handler handlers[] = {
@@ -80,434 +76,661 @@ static pipeline_msg_req_handler handlers[] = {
                pipeline_msg_req_invalid_handler,
 };
 
-static inline void
-pkt_work_key_qinq(
+static __rte_always_inline void
+pkt_work_dma(
        struct rte_mbuf *pkt,
-       void *arg)
+       void *arg,
+       uint32_t dma_size,
+       uint32_t hash_enabled,
+       uint32_t lb_hash,
+       uint32_t port_out_pow2)
 {
-       struct pipeline_passthrough *p_pt = arg;
-       uint32_t key_offset_rd = p_pt->key_offset_rd;
-       uint32_t key_offset_wr = p_pt->key_offset_wr;
-       uint32_t hash_offset = p_pt->hash_offset;
+       struct pipeline_passthrough *p = arg;
+
+       uint64_t *dma_dst = RTE_MBUF_METADATA_UINT64_PTR(pkt,
+               p->params.dma_dst_offset);
+       uint64_t *dma_src = RTE_MBUF_METADATA_UINT64_PTR(pkt,
+               p->params.dma_src_offset);
+       uint64_t *dma_mask = (uint64_t *) p->params.dma_src_mask;
+       uint32_t *dma_hash = RTE_MBUF_METADATA_UINT32_PTR(pkt,
+               p->params.dma_hash_offset);
+       uint32_t i;
+
+       /* Read (dma_src), compute (dma_dst), write (dma_dst) */
+       for (i = 0; i < (dma_size / 8); i++)
+               dma_dst[i] = dma_src[i] & dma_mask[i];
 
-       uint64_t *key_rd = RTE_MBUF_METADATA_UINT64_PTR(pkt, key_offset_rd);
-       uint64_t *key_wr = RTE_MBUF_METADATA_UINT64_PTR(pkt, key_offset_wr);
-       uint32_t *hash = RTE_MBUF_METADATA_UINT32_PTR(pkt, hash_offset);
+       /* Read (dma_dst), compute (hash), write (hash) */
+       if (hash_enabled) {
+               uint32_t hash = p->f_hash(dma_dst, dma_size, 0);
+               *dma_hash = hash;
 
-       /* Read */
-       uint64_t key_qinq = *key_rd & rte_bswap64(0x00000FFF00000FFFLLU);
+               if (lb_hash) {
+                       uint32_t port_out;
 
-       /* Compute */
-       uint32_t hash_qinq = p_pt->f_hash(&key_qinq, 8, 0);
+                       if (port_out_pow2)
+                               port_out
+                                       = hash & (p->p.n_ports_out - 1);
+                       else
+                               port_out
+                                       = hash % p->p.n_ports_out;
 
-       /* Write */
-       *key_wr = key_qinq;
-       *hash = hash_qinq;
+                       rte_pipeline_port_out_packet_insert(p->p.p,
+                               port_out, pkt);
+               }
+       }
 }
 
-static inline void
-pkt4_work_key_qinq(
-       struct rte_mbuf **pkt,
-       void *arg)
+static __rte_always_inline void
+pkt4_work_dma(
+       struct rte_mbuf **pkts,
+       void *arg,
+       uint32_t dma_size,
+       uint32_t hash_enabled,
+       uint32_t lb_hash,
+       uint32_t port_out_pow2)
 {
-       struct pipeline_passthrough *p_pt = arg;
-       uint32_t key_offset_rd = p_pt->key_offset_rd;
-       uint32_t key_offset_wr = p_pt->key_offset_wr;
-       uint32_t hash_offset = p_pt->hash_offset;
-
-       uint64_t *key_rd0 = RTE_MBUF_METADATA_UINT64_PTR(pkt[0], key_offset_rd);
-       uint64_t *key_wr0 = RTE_MBUF_METADATA_UINT64_PTR(pkt[0], key_offset_wr);
-       uint32_t *hash0 = RTE_MBUF_METADATA_UINT32_PTR(pkt[0], hash_offset);
-
-       uint64_t *key_rd1 = RTE_MBUF_METADATA_UINT64_PTR(pkt[1], key_offset_rd);
-       uint64_t *key_wr1 = RTE_MBUF_METADATA_UINT64_PTR(pkt[1], key_offset_wr);
-       uint32_t *hash1 = RTE_MBUF_METADATA_UINT32_PTR(pkt[1], hash_offset);
-
-       uint64_t *key_rd2 = RTE_MBUF_METADATA_UINT64_PTR(pkt[2], key_offset_rd);
-       uint64_t *key_wr2 = RTE_MBUF_METADATA_UINT64_PTR(pkt[2], key_offset_wr);
-       uint32_t *hash2 = RTE_MBUF_METADATA_UINT32_PTR(pkt[2], hash_offset);
-
-       uint64_t *key_rd3 = RTE_MBUF_METADATA_UINT64_PTR(pkt[3], key_offset_rd);
-       uint64_t *key_wr3 = RTE_MBUF_METADATA_UINT64_PTR(pkt[3], key_offset_wr);
-       uint32_t *hash3 = RTE_MBUF_METADATA_UINT32_PTR(pkt[3], hash_offset);
-
-       /* Read */
-       uint64_t key_qinq0 = *key_rd0 & rte_bswap64(0x00000FFF00000FFFLLU);
-       uint64_t key_qinq1 = *key_rd1 & rte_bswap64(0x00000FFF00000FFFLLU);
-       uint64_t key_qinq2 = *key_rd2 & rte_bswap64(0x00000FFF00000FFFLLU);
-       uint64_t key_qinq3 = *key_rd3 & rte_bswap64(0x00000FFF00000FFFLLU);
-
-       /* Compute */
-       uint32_t hash_qinq0 = p_pt->f_hash(&key_qinq0, 8, 0);
-       uint32_t hash_qinq1 = p_pt->f_hash(&key_qinq1, 8, 0);
-       uint32_t hash_qinq2 = p_pt->f_hash(&key_qinq2, 8, 0);
-       uint32_t hash_qinq3 = p_pt->f_hash(&key_qinq3, 8, 0);
-
-       /* Write */
-       *key_wr0 = key_qinq0;
-       *key_wr1 = key_qinq1;
-       *key_wr2 = key_qinq2;
-       *key_wr3 = key_qinq3;
-
-       *hash0 = hash_qinq0;
-       *hash1 = hash_qinq1;
-       *hash2 = hash_qinq2;
-       *hash3 = hash_qinq3;
-}
+       struct pipeline_passthrough *p = arg;
+
+       uint64_t *dma_dst0 = RTE_MBUF_METADATA_UINT64_PTR(pkts[0],
+               p->params.dma_dst_offset);
+       uint64_t *dma_dst1 = RTE_MBUF_METADATA_UINT64_PTR(pkts[1],
+               p->params.dma_dst_offset);
+       uint64_t *dma_dst2 = RTE_MBUF_METADATA_UINT64_PTR(pkts[2],
+               p->params.dma_dst_offset);
+       uint64_t *dma_dst3 = RTE_MBUF_METADATA_UINT64_PTR(pkts[3],
+               p->params.dma_dst_offset);
+
+       uint64_t *dma_src0 = RTE_MBUF_METADATA_UINT64_PTR(pkts[0],
+               p->params.dma_src_offset);
+       uint64_t *dma_src1 = RTE_MBUF_METADATA_UINT64_PTR(pkts[1],
+               p->params.dma_src_offset);
+       uint64_t *dma_src2 = RTE_MBUF_METADATA_UINT64_PTR(pkts[2],
+               p->params.dma_src_offset);
+       uint64_t *dma_src3 = RTE_MBUF_METADATA_UINT64_PTR(pkts[3],
+               p->params.dma_src_offset);
+
+       uint64_t *dma_mask = (uint64_t *) p->params.dma_src_mask;
+
+       uint32_t *dma_hash0 = RTE_MBUF_METADATA_UINT32_PTR(pkts[0],
+               p->params.dma_hash_offset);
+       uint32_t *dma_hash1 = RTE_MBUF_METADATA_UINT32_PTR(pkts[1],
+               p->params.dma_hash_offset);
+       uint32_t *dma_hash2 = RTE_MBUF_METADATA_UINT32_PTR(pkts[2],
+               p->params.dma_hash_offset);
+       uint32_t *dma_hash3 = RTE_MBUF_METADATA_UINT32_PTR(pkts[3],
+               p->params.dma_hash_offset);
+
+       uint32_t i;
+
+       /* Read (dma_src), compute (dma_dst), write (dma_dst) */
+       for (i = 0; i < (dma_size / 8); i++) {
+               dma_dst0[i] = dma_src0[i] & dma_mask[i];
+               dma_dst1[i] = dma_src1[i] & dma_mask[i];
+               dma_dst2[i] = dma_src2[i] & dma_mask[i];
+               dma_dst3[i] = dma_src3[i] & dma_mask[i];
+       }
 
-PIPELINE_PORT_IN_AH(port_in_ah_key_qinq, pkt_work_key_qinq, pkt4_work_key_qinq);
+       /* Read (dma_dst), compute (hash), write (hash) */
+       if (hash_enabled) {
+               uint32_t hash0 = p->f_hash(dma_dst0, dma_size, 0);
+               uint32_t hash1 = p->f_hash(dma_dst1, dma_size, 0);
+               uint32_t hash2 = p->f_hash(dma_dst2, dma_size, 0);
+               uint32_t hash3 = p->f_hash(dma_dst3, dma_size, 0);
+
+               *dma_hash0 = hash0;
+               *dma_hash1 = hash1;
+               *dma_hash2 = hash2;
+               *dma_hash3 = hash3;
+
+               if (lb_hash) {
+                       uint32_t port_out0, port_out1, port_out2, port_out3;
+
+                       if (port_out_pow2) {
+                               port_out0
+                                       = hash0 & (p->p.n_ports_out - 1);
+                               port_out1
+                                       = hash1 & (p->p.n_ports_out - 1);
+                               port_out2
+                                       = hash2 & (p->p.n_ports_out - 1);
+                               port_out3
+                                       = hash3 & (p->p.n_ports_out - 1);
+                       } else {
+                               port_out0
+                                       = hash0 % p->p.n_ports_out;
+                               port_out1
+                                       = hash1 % p->p.n_ports_out;
+                               port_out2
+                                       = hash2 % p->p.n_ports_out;
+                               port_out3
+                                       = hash3 % p->p.n_ports_out;
+                       }
+                       rte_pipeline_port_out_packet_insert(p->p.p,
+                               port_out0, pkts[0]);
+                       rte_pipeline_port_out_packet_insert(p->p.p,
+                               port_out1, pkts[1]);
+                       rte_pipeline_port_out_packet_insert(p->p.p,
+                               port_out2, pkts[2]);
+                       rte_pipeline_port_out_packet_insert(p->p.p,
+                               port_out3, pkts[3]);
+               }
+       }
+}
 
-static inline void
-pkt_work_key_ipv4(
+static __rte_always_inline void
+pkt_work_swap(
        struct rte_mbuf *pkt,
        void *arg)
 {
-       struct pipeline_passthrough *p_pt = arg;
-       uint32_t key_offset_rd = p_pt->key_offset_rd;
-       uint32_t key_offset_wr = p_pt->key_offset_wr;
-       uint32_t hash_offset = p_pt->hash_offset;
-
-       uint64_t *key_rd = RTE_MBUF_METADATA_UINT64_PTR(pkt, key_offset_rd);
-       uint64_t *key_wr = RTE_MBUF_METADATA_UINT64_PTR(pkt, key_offset_wr);
-       uint32_t *hash = RTE_MBUF_METADATA_UINT32_PTR(pkt, hash_offset);
-       uint64_t key_ipv4[2];
-       uint32_t hash_ipv4;
-
-       /* Read */
-       key_ipv4[0] = key_rd[0] & rte_bswap64(0x00FF0000FFFFFFFFLLU);
-       key_ipv4[1] = key_rd[1];
-
-       /* Compute */
-       hash_ipv4 = p_pt->f_hash(key_ipv4, 16, 0);
-
-       /* Write */
-       key_wr[0] = key_ipv4[0];
-       key_wr[1] = key_ipv4[1];
-       *hash = hash_ipv4;
+       struct pipeline_passthrough *p = arg;
+       uint32_t i;
+
+       /* Read(field0, field1), compute(field0, field1), write(field0, field1) */
+       for (i = 0; i < p->swap_n_fields; i++) {
+               uint64_t *field0_ptr = RTE_MBUF_METADATA_UINT64_PTR(pkt,
+                       p->swap_field0_offset[i]);
+               uint64_t *field1_ptr = RTE_MBUF_METADATA_UINT64_PTR(pkt,
+                       p->swap_field1_offset[i]);
+               uint64_t mask = p->swap_field_mask[i];
+
+               uint64_t field0 = *field0_ptr;
+               uint64_t field1 = *field1_ptr;
+
+               *field0_ptr = (field0 & (~mask)) + (field1 & mask);
+               *field1_ptr = (field0 & mask) + (field1 & (~mask));
+       }
 }
 
-static inline void
-pkt4_work_key_ipv4(
-       struct rte_mbuf **pkt,
+static __rte_always_inline void
+pkt4_work_swap(
+       struct rte_mbuf **pkts,
        void *arg)
 {
-       struct pipeline_passthrough *p_pt = arg;
-       uint32_t key_offset_rd = p_pt->key_offset_rd;
-       uint32_t key_offset_wr = p_pt->key_offset_wr;
-       uint32_t hash_offset = p_pt->hash_offset;
-
-       uint64_t *key_rd0 = RTE_MBUF_METADATA_UINT64_PTR(pkt[0], key_offset_rd);
-       uint64_t *key_wr0 = RTE_MBUF_METADATA_UINT64_PTR(pkt[0], key_offset_wr);
-       uint32_t *hash0 = RTE_MBUF_METADATA_UINT32_PTR(pkt[0], hash_offset);
-
-       uint64_t *key_rd1 = RTE_MBUF_METADATA_UINT64_PTR(pkt[1], key_offset_rd);
-       uint64_t *key_wr1 = RTE_MBUF_METADATA_UINT64_PTR(pkt[1], key_offset_wr);
-       uint32_t *hash1 = RTE_MBUF_METADATA_UINT32_PTR(pkt[1], hash_offset);
-
-       uint64_t *key_rd2 = RTE_MBUF_METADATA_UINT64_PTR(pkt[2], key_offset_rd);
-       uint64_t *key_wr2 = RTE_MBUF_METADATA_UINT64_PTR(pkt[2], key_offset_wr);
-       uint32_t *hash2 = RTE_MBUF_METADATA_UINT32_PTR(pkt[2], hash_offset);
-
-       uint64_t *key_rd3 = RTE_MBUF_METADATA_UINT64_PTR(pkt[3], key_offset_rd);
-       uint64_t *key_wr3 = RTE_MBUF_METADATA_UINT64_PTR(pkt[3], key_offset_wr);
-       uint32_t *hash3 = RTE_MBUF_METADATA_UINT32_PTR(pkt[3], hash_offset);
-
-       uint64_t key_ipv4_0[2];
-       uint64_t key_ipv4_1[2];
-       uint64_t key_ipv4_2[2];
-       uint64_t key_ipv4_3[2];
-
-       uint32_t hash_ipv4_0;
-       uint32_t hash_ipv4_1;
-       uint32_t hash_ipv4_2;
-       uint32_t hash_ipv4_3;
-
-       /* Read */
-       key_ipv4_0[0] = key_rd0[0] & rte_bswap64(0x00FF0000FFFFFFFFLLU);
-       key_ipv4_1[0] = key_rd1[0] & rte_bswap64(0x00FF0000FFFFFFFFLLU);
-       key_ipv4_2[0] = key_rd2[0] & rte_bswap64(0x00FF0000FFFFFFFFLLU);
-       key_ipv4_3[0] = key_rd3[0] & rte_bswap64(0x00FF0000FFFFFFFFLLU);
-
-       key_ipv4_0[1] = key_rd0[1];
-       key_ipv4_1[1] = key_rd1[1];
-       key_ipv4_2[1] = key_rd2[1];
-       key_ipv4_3[1] = key_rd3[1];
-
-       /* Compute */
-       hash_ipv4_0 = p_pt->f_hash(key_ipv4_0, 16, 0);
-       hash_ipv4_1 = p_pt->f_hash(key_ipv4_1, 16, 0);
-       hash_ipv4_2 = p_pt->f_hash(key_ipv4_2, 16, 0);
-       hash_ipv4_3 = p_pt->f_hash(key_ipv4_3, 16, 0);
-
-       /* Write */
-       key_wr0[0] = key_ipv4_0[0];
-       key_wr1[0] = key_ipv4_1[0];
-       key_wr2[0] = key_ipv4_2[0];
-       key_wr3[0] = key_ipv4_3[0];
-
-       key_wr0[1] = key_ipv4_0[1];
-       key_wr1[1] = key_ipv4_1[1];
-       key_wr2[1] = key_ipv4_2[1];
-       key_wr3[1] = key_ipv4_3[1];
-
-       *hash0 = hash_ipv4_0;
-       *hash1 = hash_ipv4_1;
-       *hash2 = hash_ipv4_2;
-       *hash3 = hash_ipv4_3;
+       struct pipeline_passthrough *p = arg;
+       uint32_t i;
+
+       /* Read(field0, field1), compute(field0, field1), write(field0, field1) */
+       for (i = 0; i < p->swap_n_fields; i++) {
+               uint64_t *pkt0_field0_ptr = RTE_MBUF_METADATA_UINT64_PTR(pkts[0],
+                       p->swap_field0_offset[i]);
+               uint64_t *pkt1_field0_ptr = RTE_MBUF_METADATA_UINT64_PTR(pkts[1],
+                       p->swap_field0_offset[i]);
+               uint64_t *pkt2_field0_ptr = RTE_MBUF_METADATA_UINT64_PTR(pkts[2],
+                       p->swap_field0_offset[i]);
+               uint64_t *pkt3_field0_ptr = RTE_MBUF_METADATA_UINT64_PTR(pkts[3],
+                       p->swap_field0_offset[i]);
+
+               uint64_t *pkt0_field1_ptr = RTE_MBUF_METADATA_UINT64_PTR(pkts[0],
+                       p->swap_field1_offset[i]);
+               uint64_t *pkt1_field1_ptr = RTE_MBUF_METADATA_UINT64_PTR(pkts[1],
+                       p->swap_field1_offset[i]);
+               uint64_t *pkt2_field1_ptr = RTE_MBUF_METADATA_UINT64_PTR(pkts[2],
+                       p->swap_field1_offset[i]);
+               uint64_t *pkt3_field1_ptr = RTE_MBUF_METADATA_UINT64_PTR(pkts[3],
+                       p->swap_field1_offset[i]);
+
+               uint64_t mask = p->swap_field_mask[i];
+
+               uint64_t pkt0_field0 = *pkt0_field0_ptr;
+               uint64_t pkt1_field0 = *pkt1_field0_ptr;
+               uint64_t pkt2_field0 = *pkt2_field0_ptr;
+               uint64_t pkt3_field0 = *pkt3_field0_ptr;
+
+               uint64_t pkt0_field1 = *pkt0_field1_ptr;
+               uint64_t pkt1_field1 = *pkt1_field1_ptr;
+               uint64_t pkt2_field1 = *pkt2_field1_ptr;
+               uint64_t pkt3_field1 = *pkt3_field1_ptr;
+
+               *pkt0_field0_ptr = (pkt0_field0 & (~mask)) + (pkt0_field1 & mask);
+               *pkt1_field0_ptr = (pkt1_field0 & (~mask)) + (pkt1_field1 & mask);
+               *pkt2_field0_ptr = (pkt2_field0 & (~mask)) + (pkt2_field1 & mask);
+               *pkt3_field0_ptr = (pkt3_field0 & (~mask)) + (pkt3_field1 & mask);
+
+               *pkt0_field1_ptr = (pkt0_field0 & mask) + (pkt0_field1 & (~mask));
+               *pkt1_field1_ptr = (pkt1_field0 & mask) + (pkt1_field1 & (~mask));
+               *pkt2_field1_ptr = (pkt2_field0 & mask) + (pkt2_field1 & (~mask));
+               *pkt3_field1_ptr = (pkt3_field0 & mask) + (pkt3_field1 & (~mask));
+       }
 }
 
-PIPELINE_PORT_IN_AH(port_in_ah_key_ipv4, pkt_work_key_ipv4, pkt4_work_key_ipv4);
+#define PKT_WORK_DMA(dma_size, hash_enabled, lb_hash, port_pow2)       \
+static inline void                                             \
+pkt_work_dma_size##dma_size##_hash##hash_enabled               \
+       ##_lb##lb_hash##_pw##port_pow2(                 \
+       struct rte_mbuf *pkt,                                   \
+       void *arg)                                              \
+{                                                              \
+       pkt_work_dma(pkt, arg, dma_size, hash_enabled, lb_hash, port_pow2);     \
+}
 
-static inline void
-pkt_work_key_ipv6(
-       struct rte_mbuf *pkt,
-       void *arg)
-{
-       struct pipeline_passthrough *p_pt = arg;
-       uint32_t key_offset_rd = p_pt->key_offset_rd;
-       uint32_t key_offset_wr = p_pt->key_offset_wr;
-       uint32_t hash_offset = p_pt->hash_offset;
-
-       uint64_t *key_rd = RTE_MBUF_METADATA_UINT64_PTR(pkt, key_offset_rd);
-       uint64_t *key_wr = RTE_MBUF_METADATA_UINT64_PTR(pkt, key_offset_wr);
-       uint32_t *hash = RTE_MBUF_METADATA_UINT32_PTR(pkt, hash_offset);
-       uint64_t key_ipv6[8];
-       uint32_t hash_ipv6;
-
-       /* Read */
-       key_ipv6[0] = key_rd[0] & rte_bswap64(0x0000FF00FFFFFFFFLLU);
-       key_ipv6[1] = key_rd[1];
-       key_ipv6[2] = key_rd[2];
-       key_ipv6[3] = key_rd[3];
-       key_ipv6[4] = key_rd[4];
-       key_ipv6[5] = 0;
-       key_ipv6[6] = 0;
-       key_ipv6[7] = 0;
-
-       /* Compute */
-       hash_ipv6 = p_pt->f_hash(key_ipv6, 64, 0);
-
-       /* Write */
-       key_wr[0] = key_ipv6[0];
-       key_wr[1] = key_ipv6[1];
-       key_wr[2] = key_ipv6[2];
-       key_wr[3] = key_ipv6[3];
-       key_wr[4] = key_ipv6[4];
-       key_wr[5] = 0;
-       key_wr[6] = 0;
-       key_wr[7] = 0;
-       *hash = hash_ipv6;
+#define PKT4_WORK_DMA(dma_size, hash_enabled, lb_hash, port_pow2)      \
+static inline void                                             \
+pkt4_work_dma_size##dma_size##_hash##hash_enabled                      \
+       ##_lb##lb_hash##_pw##port_pow2(                 \
+       struct rte_mbuf **pkts,                                 \
+       void *arg)                                              \
+{                                                              \
+       pkt4_work_dma(pkts, arg, dma_size, hash_enabled, lb_hash, port_pow2); \
 }
 
-static inline void
-pkt4_work_key_ipv6(
-       struct rte_mbuf **pkt,
-       void *arg)
+#define port_in_ah_dma(dma_size, hash_enabled, lb_hash, port_pow2)     \
+PKT_WORK_DMA(dma_size, hash_enabled, lb_hash, port_pow2)                       \
+PKT4_WORK_DMA(dma_size, hash_enabled, lb_hash, port_pow2)                      \
+PIPELINE_PORT_IN_AH(port_in_ah_dma_size##dma_size##_hash       \
+       ##hash_enabled##_lb##lb_hash##_pw##port_pow2,           \
+       pkt_work_dma_size##dma_size##_hash##hash_enabled                \
+       ##_lb##lb_hash##_pw##port_pow2,                 \
+       pkt4_work_dma_size##dma_size##_hash##hash_enabled               \
+       ##_lb##lb_hash##_pw##port_pow2)
+
+
+#define port_in_ah_lb(dma_size, hash_enabled, lb_hash, port_pow2) \
+PKT_WORK_DMA(dma_size, hash_enabled, lb_hash, port_pow2)               \
+PKT4_WORK_DMA(dma_size, hash_enabled, lb_hash, port_pow2)      \
+PIPELINE_PORT_IN_AH_HIJACK_ALL(                                                \
+       port_in_ah_lb_size##dma_size##_hash##hash_enabled               \
+       ##_lb##lb_hash##_pw##port_pow2,                 \
+       pkt_work_dma_size##dma_size##_hash##hash_enabled                \
+       ##_lb##lb_hash##_pw##port_pow2, \
+       pkt4_work_dma_size##dma_size##_hash##hash_enabled               \
+       ##_lb##lb_hash##_pw##port_pow2)
+
+PIPELINE_PORT_IN_AH(port_in_ah_swap, pkt_work_swap,    pkt4_work_swap)
+
+
+/* Port in AH DMA(dma_size, hash_enabled, lb_hash, port_pow2) */
+
+port_in_ah_dma(8, 0, 0, 0)
+port_in_ah_dma(8, 1, 0, 0)
+port_in_ah_lb(8, 1, 1, 0)
+port_in_ah_lb(8, 1, 1, 1)
+
+port_in_ah_dma(16, 0, 0, 0)
+port_in_ah_dma(16, 1, 0, 0)
+port_in_ah_lb(16, 1, 1, 0)
+port_in_ah_lb(16, 1, 1, 1)
+
+port_in_ah_dma(24, 0, 0, 0)
+port_in_ah_dma(24, 1, 0, 0)
+port_in_ah_lb(24, 1, 1, 0)
+port_in_ah_lb(24, 1, 1, 1)
+
+port_in_ah_dma(32, 0, 0, 0)
+port_in_ah_dma(32, 1, 0, 0)
+port_in_ah_lb(32, 1, 1, 0)
+port_in_ah_lb(32, 1, 1, 1)
+
+port_in_ah_dma(40, 0, 0, 0)
+port_in_ah_dma(40, 1, 0, 0)
+port_in_ah_lb(40, 1, 1, 0)
+port_in_ah_lb(40, 1, 1, 1)
+
+port_in_ah_dma(48, 0, 0, 0)
+port_in_ah_dma(48, 1, 0, 0)
+port_in_ah_lb(48, 1, 1, 0)
+port_in_ah_lb(48, 1, 1, 1)
+
+port_in_ah_dma(56, 0, 0, 0)
+port_in_ah_dma(56, 1, 0, 0)
+port_in_ah_lb(56, 1, 1, 0)
+port_in_ah_lb(56, 1, 1, 1)
+
+port_in_ah_dma(64, 0, 0, 0)
+port_in_ah_dma(64, 1, 0, 0)
+port_in_ah_lb(64, 1, 1, 0)
+port_in_ah_lb(64, 1, 1, 1)
+
+static rte_pipeline_port_in_action_handler
+get_port_in_ah(struct pipeline_passthrough *p)
 {
-       struct pipeline_passthrough *p_pt = arg;
-       uint32_t key_offset_rd = p_pt->key_offset_rd;
-       uint32_t key_offset_wr = p_pt->key_offset_wr;
-       uint32_t hash_offset = p_pt->hash_offset;
-
-       uint64_t *key_rd0 = RTE_MBUF_METADATA_UINT64_PTR(pkt[0], key_offset_rd);
-       uint64_t *key_wr0 = RTE_MBUF_METADATA_UINT64_PTR(pkt[0], key_offset_wr);
-       uint32_t *hash0 = RTE_MBUF_METADATA_UINT32_PTR(pkt[0], hash_offset);
-
-       uint64_t *key_rd1 = RTE_MBUF_METADATA_UINT64_PTR(pkt[1], key_offset_rd);
-       uint64_t *key_wr1 = RTE_MBUF_METADATA_UINT64_PTR(pkt[1], key_offset_wr);
-       uint32_t *hash1 = RTE_MBUF_METADATA_UINT32_PTR(pkt[1], hash_offset);
-
-       uint64_t *key_rd2 = RTE_MBUF_METADATA_UINT64_PTR(pkt[2], key_offset_rd);
-       uint64_t *key_wr2 = RTE_MBUF_METADATA_UINT64_PTR(pkt[2], key_offset_wr);
-       uint32_t *hash2 = RTE_MBUF_METADATA_UINT32_PTR(pkt[2], hash_offset);
-
-       uint64_t *key_rd3 = RTE_MBUF_METADATA_UINT64_PTR(pkt[3], key_offset_rd);
-       uint64_t *key_wr3 = RTE_MBUF_METADATA_UINT64_PTR(pkt[3], key_offset_wr);
-       uint32_t *hash3 = RTE_MBUF_METADATA_UINT32_PTR(pkt[3], hash_offset);
-
-       uint64_t key_ipv6_0[8];
-       uint64_t key_ipv6_1[8];
-       uint64_t key_ipv6_2[8];
-       uint64_t key_ipv6_3[8];
-
-       uint32_t hash_ipv6_0;
-       uint32_t hash_ipv6_1;
-       uint32_t hash_ipv6_2;
-       uint32_t hash_ipv6_3;
-
-       /* Read */
-       key_ipv6_0[0] = key_rd0[0] & rte_bswap64(0x0000FF00FFFFFFFFLLU);
-       key_ipv6_1[0] = key_rd1[0] & rte_bswap64(0x0000FF00FFFFFFFFLLU);
-       key_ipv6_2[0] = key_rd2[0] & rte_bswap64(0x0000FF00FFFFFFFFLLU);
-       key_ipv6_3[0] = key_rd3[0] & rte_bswap64(0x0000FF00FFFFFFFFLLU);
-
-       key_ipv6_0[1] = key_rd0[1];
-       key_ipv6_1[1] = key_rd1[1];
-       key_ipv6_2[1] = key_rd2[1];
-       key_ipv6_3[1] = key_rd3[1];
-
-       key_ipv6_0[2] = key_rd0[2];
-       key_ipv6_1[2] = key_rd1[2];
-       key_ipv6_2[2] = key_rd2[2];
-       key_ipv6_3[2] = key_rd3[2];
-
-       key_ipv6_0[3] = key_rd0[3];
-       key_ipv6_1[3] = key_rd1[3];
-       key_ipv6_2[3] = key_rd2[3];
-       key_ipv6_3[3] = key_rd3[3];
-
-       key_ipv6_0[4] = key_rd0[4];
-       key_ipv6_1[4] = key_rd1[4];
-       key_ipv6_2[4] = key_rd2[4];
-       key_ipv6_3[4] = key_rd3[4];
-
-       key_ipv6_0[5] = 0;
-       key_ipv6_1[5] = 0;
-       key_ipv6_2[5] = 0;
-       key_ipv6_3[5] = 0;
-
-       key_ipv6_0[6] = 0;
-       key_ipv6_1[6] = 0;
-       key_ipv6_2[6] = 0;
-       key_ipv6_3[6] = 0;
-
-       key_ipv6_0[7] = 0;
-       key_ipv6_1[7] = 0;
-       key_ipv6_2[7] = 0;
-       key_ipv6_3[7] = 0;
-
-       /* Compute */
-       hash_ipv6_0 = p_pt->f_hash(key_ipv6_0, 64, 0);
-       hash_ipv6_1 = p_pt->f_hash(key_ipv6_1, 64, 0);
-       hash_ipv6_2 = p_pt->f_hash(key_ipv6_2, 64, 0);
-       hash_ipv6_3 = p_pt->f_hash(key_ipv6_3, 64, 0);
-
-       /* Write */
-       key_wr0[0] = key_ipv6_0[0];
-       key_wr1[0] = key_ipv6_1[0];
-       key_wr2[0] = key_ipv6_2[0];
-       key_wr3[0] = key_ipv6_3[0];
-
-       key_wr0[1] = key_ipv6_0[1];
-       key_wr1[1] = key_ipv6_1[1];
-       key_wr2[1] = key_ipv6_2[1];
-       key_wr3[1] = key_ipv6_3[1];
-
-       key_wr0[2] = key_ipv6_0[2];
-       key_wr1[2] = key_ipv6_1[2];
-       key_wr2[2] = key_ipv6_2[2];
-       key_wr3[2] = key_ipv6_3[2];
-
-       key_wr0[3] = key_ipv6_0[3];
-       key_wr1[3] = key_ipv6_1[3];
-       key_wr2[3] = key_ipv6_2[3];
-       key_wr3[3] = key_ipv6_3[3];
-
-       key_wr0[4] = key_ipv6_0[4];
-       key_wr1[4] = key_ipv6_1[4];
-       key_wr2[4] = key_ipv6_2[4];
-       key_wr3[4] = key_ipv6_3[4];
-
-       key_wr0[5] = 0;
-       key_wr0[5] = 0;
-       key_wr0[5] = 0;
-       key_wr0[5] = 0;
-
-       key_wr0[6] = 0;
-       key_wr0[6] = 0;
-       key_wr0[6] = 0;
-       key_wr0[6] = 0;
-
-       key_wr0[7] = 0;
-       key_wr0[7] = 0;
-       key_wr0[7] = 0;
-       key_wr0[7] = 0;
-
-       *hash0 = hash_ipv6_0;
-       *hash1 = hash_ipv6_1;
-       *hash2 = hash_ipv6_2;
-       *hash3 = hash_ipv6_3;
-}
+       if ((p->params.dma_enabled == 0) &&
+               (p->params.swap_enabled == 0))
+               return NULL;
 
-PIPELINE_PORT_IN_AH(port_in_ah_key_ipv6, pkt_work_key_ipv6, pkt4_work_key_ipv6);
+       if (p->params.swap_enabled)
+               return port_in_ah_swap;
+
+       if (p->params.dma_hash_enabled) {
+               if (p->params.dma_hash_lb_enabled) {
+                       if (rte_is_power_of_2(p->p.n_ports_out))
+                               switch (p->params.dma_size) {
+
+                               case 8: return port_in_ah_lb_size8_hash1_lb1_pw1;
+                               case 16: return port_in_ah_lb_size16_hash1_lb1_pw1;
+                               case 24: return port_in_ah_lb_size24_hash1_lb1_pw1;
+                               case 32: return port_in_ah_lb_size32_hash1_lb1_pw1;
+                               case 40: return port_in_ah_lb_size40_hash1_lb1_pw1;
+                               case 48: return port_in_ah_lb_size48_hash1_lb1_pw1;
+                               case 56: return port_in_ah_lb_size56_hash1_lb1_pw1;
+                               case 64: return port_in_ah_lb_size64_hash1_lb1_pw1;
+                               default: return NULL;
+                               }
+                       else
+                               switch (p->params.dma_size) {
+
+                               case 8: return port_in_ah_lb_size8_hash1_lb1_pw0;
+                               case 16: return port_in_ah_lb_size16_hash1_lb1_pw0;
+                               case 24: return port_in_ah_lb_size24_hash1_lb1_pw0;
+                               case 32: return port_in_ah_lb_size32_hash1_lb1_pw0;
+                               case 40: return port_in_ah_lb_size40_hash1_lb1_pw0;
+                               case 48: return port_in_ah_lb_size48_hash1_lb1_pw0;
+                               case 56: return port_in_ah_lb_size56_hash1_lb1_pw0;
+                               case 64: return port_in_ah_lb_size64_hash1_lb1_pw0;
+                               default: return NULL;
+                       }
+               } else
+                       switch (p->params.dma_size) {
+
+                       case 8: return port_in_ah_dma_size8_hash1_lb0_pw0;
+                       case 16: return port_in_ah_dma_size16_hash1_lb0_pw0;
+                       case 24: return port_in_ah_dma_size24_hash1_lb0_pw0;
+                       case 32: return port_in_ah_dma_size32_hash1_lb0_pw0;
+                       case 40: return port_in_ah_dma_size40_hash1_lb0_pw0;
+                       case 48: return port_in_ah_dma_size48_hash1_lb0_pw0;
+                       case 56: return port_in_ah_dma_size56_hash1_lb0_pw0;
+                       case 64: return port_in_ah_dma_size64_hash1_lb0_pw0;
+                       default: return NULL;
+               }
+       } else
+               switch (p->params.dma_size) {
+
+               case 8: return port_in_ah_dma_size8_hash0_lb0_pw0;
+               case 16: return port_in_ah_dma_size16_hash0_lb0_pw0;
+               case 24: return port_in_ah_dma_size24_hash0_lb0_pw0;
+               case 32: return port_in_ah_dma_size32_hash0_lb0_pw0;
+               case 40: return port_in_ah_dma_size40_hash0_lb0_pw0;
+               case 48: return port_in_ah_dma_size48_hash0_lb0_pw0;
+               case 56: return port_in_ah_dma_size56_hash0_lb0_pw0;
+               case 64: return port_in_ah_dma_size64_hash0_lb0_pw0;
+               default: return NULL;
+               }
+}
 
-static int
-pipeline_passthrough_parse_args(struct pipeline_passthrough *p,
+int
+pipeline_passthrough_parse_args(struct pipeline_passthrough_params *p,
        struct pipeline_params *params)
 {
-       uint32_t key_type_present = 0;
-       uint32_t key_offset_rd_present = 0;
-       uint32_t key_offset_wr_present = 0;
-       uint32_t hash_offset_present = 0;
+       uint32_t dma_dst_offset_present = 0;
+       uint32_t dma_src_offset_present = 0;
+       uint32_t dma_src_mask_present = 0;
+       char dma_mask_str[PIPELINE_PASSTHROUGH_DMA_SIZE_MAX * 2 + 1];
+       uint32_t dma_size_present = 0;
+       uint32_t dma_hash_offset_present = 0;
+       uint32_t dma_hash_lb_present = 0;
        uint32_t i;
 
+       /* default values */
+       p->dma_enabled = 0;
+       p->dma_hash_enabled = 0;
+       p->dma_hash_lb_enabled = 0;
+       memset(p->dma_src_mask, 0xFF, sizeof(p->dma_src_mask));
+       p->swap_enabled = 0;
+       p->swap_n_fields = 0;
+
        for (i = 0; i < params->n_args; i++) {
                char *arg_name = params->args_name[i];
                char *arg_value = params->args_value[i];
 
-               /* key_type */
-               if (strcmp(arg_name, "key_type") == 0) {
-                       if (key_type_present)
-                               return -1;
-                       key_type_present = 1;
-
-                       if ((strcmp(arg_value, "q-in-q") == 0) ||
-                               (strcmp(arg_value, "qinq") == 0))
-                               p->key_type = FLOW_KEY_QINQ;
-                       else if (strcmp(arg_value, "ipv4_5tuple") == 0)
-                               p->key_type = FLOW_KEY_IPV4_5TUPLE;
-                       else if (strcmp(arg_value, "ipv6_5tuple") == 0)
-                               p->key_type = FLOW_KEY_IPV6_5TUPLE;
-                       else
-                               return -1;
+               /* dma_dst_offset */
+               if (strcmp(arg_name, "dma_dst_offset") == 0) {
+                       int status;
+
+                       PIPELINE_PARSE_ERR_DUPLICATE(
+                               dma_dst_offset_present == 0, params->name,
+                               arg_name);
+                       dma_dst_offset_present = 1;
 
-                       p->key_type_valid = 1;
+                       status = parser_read_uint32(&p->dma_dst_offset,
+                               arg_value);
+                       PIPELINE_PARSE_ERR_INV_VAL((status != -EINVAL),
+                               params->name, arg_name, arg_value);
+                       PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
+                               params->name, arg_name, arg_value);
+
+                       p->dma_enabled = 1;
 
                        continue;
                }
 
-               /* key_offset_rd */
-               if (strcmp(arg_name, "key_offset_rd") == 0) {
-                       if (key_offset_rd_present)
-                               return -1;
-                       key_offset_rd_present = 1;
+               /* dma_src_offset */
+               if (strcmp(arg_name, "dma_src_offset") == 0) {
+                       int status;
+
+                       PIPELINE_PARSE_ERR_DUPLICATE(
+                               dma_src_offset_present == 0, params->name,
+                               arg_name);
+                       dma_src_offset_present = 1;
 
-                       p->key_offset_rd = atoi(arg_value);
+                       status = parser_read_uint32(&p->dma_src_offset,
+                               arg_value);
+                       PIPELINE_PARSE_ERR_INV_VAL((status != -EINVAL),
+                               params->name, arg_name, arg_value);
+                       PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
+                               params->name, arg_name, arg_value);
+
+                       p->dma_enabled = 1;
 
                        continue;
                }
 
-               /* key_offset_wr */
-               if (strcmp(arg_name, "key_offset_wr") == 0) {
-                       if (key_offset_wr_present)
-                               return -1;
-                       key_offset_wr_present = 1;
+               /* dma_size */
+               if (strcmp(arg_name, "dma_size") == 0) {
+                       int status;
+
+                       PIPELINE_PARSE_ERR_DUPLICATE(
+                               dma_size_present == 0, params->name,
+                               arg_name);
+                       dma_size_present = 1;
 
-                       p->key_offset_wr = atoi(arg_value);
+                       status = parser_read_uint32(&p->dma_size,
+                               arg_value);
+                       PIPELINE_PARSE_ERR_INV_VAL(((status != -EINVAL) &&
+                               (p->dma_size != 0) &&
+                               ((p->dma_size % 8) == 0)),
+                               params->name, arg_name, arg_value);
+                       PIPELINE_PARSE_ERR_OUT_RNG(((status != -ERANGE) &&
+                               (p->dma_size <=
+                               PIPELINE_PASSTHROUGH_DMA_SIZE_MAX)),
+                               params->name, arg_name, arg_value);
+
+                       p->dma_enabled = 1;
 
                        continue;
                }
 
-               /* hash_offset */
-               if (strcmp(arg_name, "hash_offset") == 0) {
-                       if (hash_offset_present)
-                               return -1;
-                       hash_offset_present = 1;
+               /* dma_src_mask */
+               if (strcmp(arg_name, "dma_src_mask") == 0) {
+                       int mask_str_len = strlen(arg_value);
+
+                       PIPELINE_PARSE_ERR_DUPLICATE(
+                               dma_src_mask_present == 0,
+                               params->name, arg_name);
+                       dma_src_mask_present = 1;
+
+                       PIPELINE_ARG_CHECK((mask_str_len <=
+                               (PIPELINE_PASSTHROUGH_DMA_SIZE_MAX * 2)),
+                               "Parse error in section \"%s\": entry "
+                               "\"%s\" too long", params->name,
+                               arg_name);
 
-                       p->hash_offset = atoi(arg_value);
+                       snprintf(dma_mask_str, mask_str_len + 1,
+                               "%s", arg_value);
+
+                       p->dma_enabled = 1;
+
+                       continue;
+               }
+
+               /* dma_hash_offset */
+               if (strcmp(arg_name, "dma_hash_offset") == 0) {
+                       int status;
+
+                       PIPELINE_PARSE_ERR_DUPLICATE(
+                               dma_hash_offset_present == 0,
+                               params->name, arg_name);
+                       dma_hash_offset_present = 1;
+
+                       status = parser_read_uint32(&p->dma_hash_offset,
+                               arg_value);
+                       PIPELINE_PARSE_ERR_INV_VAL((status != -EINVAL),
+                               params->name, arg_name, arg_value);
+                       PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
+                               params->name, arg_name, arg_value);
+
+                       p->dma_hash_enabled = 1;
+
+                       continue;
+               }
+
+               /* load_balance mode */
+               if (strcmp(arg_name, "lb") == 0) {
+                       PIPELINE_PARSE_ERR_DUPLICATE(
+                               dma_hash_lb_present == 0,
+                               params->name, arg_name);
+                       dma_hash_lb_present = 1;
+
+                       if (strcmp(arg_value, "hash") &&
+                               strcmp(arg_value, "HASH"))
+
+                               PIPELINE_PARSE_ERR_INV_VAL(0,
+                                       params->name,
+                                       arg_name,
+                                       arg_value);
+
+                       p->dma_hash_lb_enabled = 1;
+
+                       continue;
+               }
+
+               /* swap */
+               if (strcmp(arg_name, "swap") == 0) {
+                       uint32_t a, b, n_args;
+                       int len;
+
+                       n_args = sscanf(arg_value, "%" SCNu32 " %" SCNu32 "%n",
+                               &a, &b, &len);
+                       PIPELINE_PARSE_ERR_INV_VAL(((n_args == 2) &&
+                               ((size_t) len == strlen(arg_value))),
+                               params->name, arg_name, arg_value);
+
+                       p->swap_field0_offset[p->swap_n_fields] = a;
+                       p->swap_field1_offset[p->swap_n_fields] = b;
+                       p->swap_n_fields++;
+                       p->swap_enabled = 1;
 
                        continue;
                }
 
                /* any other */
-               return -1;
+               PIPELINE_PARSE_ERR_INV_ENT(0, params->name, arg_name);
        }
 
-       /* Check that mandatory arguments are present */
-       if ((key_offset_rd_present != key_type_present) ||
-               (key_offset_wr_present != key_type_present) ||
-               (hash_offset_present != key_type_present))
-               return -1;
+       /* Check correlations between arguments */
+       PIPELINE_ARG_CHECK((p->dma_enabled + p->swap_enabled < 2),
+               "Parse error in section \"%s\": DMA and SWAP actions are both enabled",
+               params->name);
+       PIPELINE_ARG_CHECK((dma_dst_offset_present == p->dma_enabled),
+               "Parse error in section \"%s\": missing entry "
+               "\"dma_dst_offset\"", params->name);
+       PIPELINE_ARG_CHECK((dma_src_offset_present == p->dma_enabled),
+               "Parse error in section \"%s\": missing entry "
+               "\"dma_src_offset\"", params->name);
+       PIPELINE_ARG_CHECK((dma_size_present == p->dma_enabled),
+               "Parse error in section \"%s\": missing entry "
+               "\"dma_size\"", params->name);
+       PIPELINE_ARG_CHECK((p->dma_hash_enabled <= p->dma_enabled),
+               "Parse error in section \"%s\": missing all DMA entries",
+               params->name);
+       PIPELINE_ARG_CHECK((p->dma_hash_lb_enabled <= p->dma_hash_enabled),
+               "Parse error in section \"%s\": missing all DMA hash entries ",
+               params->name);
+
+       if (dma_src_mask_present) {
+               uint32_t dma_size = p->dma_size;
+               int status;
+
+               PIPELINE_ARG_CHECK((strlen(dma_mask_str) ==
+                       (dma_size * 2)), "Parse error in section "
+                       "\"%s\": dma_src_mask should have exactly %u hex "
+                       "digits", params->name, (dma_size * 2));
+
+               status = parse_hex_string(dma_mask_str, p->dma_src_mask,
+                       &p->dma_size);
+
+               PIPELINE_PARSE_ERR_INV_VAL(((status == 0) &&
+                       (dma_size == p->dma_size)), params->name,
+                       "dma_src_mask", dma_mask_str);
+       }
+
+       if (p->dma_hash_lb_enabled)
+               PIPELINE_ARG_CHECK((params->n_ports_out > 1),
+                       "Parse error in section \"%s\": entry \"lb\" not "
+                       "allowed for single output port pipeline",
+                       params->name);
+       else
+               PIPELINE_ARG_CHECK(((params->n_ports_in >= params->n_ports_out)
+                       && ((params->n_ports_in % params->n_ports_out) == 0)),
+                       "Parse error in section \"%s\": n_ports_in needs to be "
+                       "a multiple of n_ports_out (lb mode disabled)",
+                       params->name);
+
+       return 0;
+}
+
+static rte_table_hash_op_hash
+get_hash_function(struct pipeline_passthrough *p)
+{
+       switch (p->params.dma_size) {
+
+       case 8: return hash_default_key8;
+       case 16: return hash_default_key16;
+       case 24: return hash_default_key24;
+       case 32: return hash_default_key32;
+       case 40: return hash_default_key40;
+       case 48: return hash_default_key48;
+       case 56: return hash_default_key56;
+       case 64: return hash_default_key64;
+       default: return NULL;
+       }
+}
+
+static int
+pipeline_passthrough_swap_convert(struct pipeline_passthrough *p)
+{
+       uint32_t i;
+
+       p->swap_n_fields = 0;
+
+       for (i = 0; i < p->params.swap_n_fields; i++) {
+               uint32_t offset0 = p->params.swap_field0_offset[i];
+               uint32_t offset1 = p->params.swap_field1_offset[i];
+               uint32_t size = offset1 - offset0;
+               uint32_t j;
+
+               /* Check */
+               if ((offset0 >= offset1) ||
+                       (size > PIPELINE_PASSTHROUGH_SWAP_FIELD_SIZE_MAX) ||
+                       (p->swap_n_fields >= SWAP_DIM))
+                       return -1;
+
+               for (j = 0; j < (size / sizeof(uint64_t)); j++) {
+                       p->swap_field0_offset[p->swap_n_fields] = offset0;
+                       p->swap_field1_offset[p->swap_n_fields] = offset1;
+                       p->swap_field_mask[p->swap_n_fields] = UINT64_MAX;
+                       p->swap_n_fields++;
+                       offset0 += sizeof(uint64_t);
+                       offset1 += sizeof(uint64_t);
+               }
+               if (size % sizeof(uint64_t)) {
+                       uint32_t n_bits = (size % sizeof(uint64_t)) * 8;
+
+                       p->swap_field0_offset[p->swap_n_fields] = offset0;
+                       p->swap_field1_offset[p->swap_n_fields] = offset1;
+                       p->swap_field_mask[p->swap_n_fields] =
+                               RTE_LEN2MASK(n_bits, uint64_t);
+                       p->swap_n_fields++;
+               }
+       }
 
        return 0;
 }
@@ -523,9 +746,7 @@ pipeline_passthrough_init(struct pipeline_params *params,
        /* Check input arguments */
        if ((params == NULL) ||
                (params->n_ports_in == 0) ||
-               (params->n_ports_out == 0) ||
-               (params->n_ports_in < params->n_ports_out) ||
-               (params->n_ports_in % params->n_ports_out))
+               (params->n_ports_out == 0))
                return NULL;
 
        /* Memory allocation */
@@ -541,33 +762,11 @@ pipeline_passthrough_init(struct pipeline_params *params,
        PLOG(p, HIGH, "Pass-through");
 
        /* Parse arguments */
-       if (pipeline_passthrough_parse_args(p_pt, params))
+       if (pipeline_passthrough_parse_args(&p_pt->params, params))
                return NULL;
-
-       if (p_pt->key_type_valid == 0) {
-               p_pt->f_hash = NULL;
-               p_pt->f_port_in_ah = NULL;
-       } else
-               switch (p_pt->key_type) {
-               case FLOW_KEY_QINQ:
-                       p_pt->f_hash = hash_default_key8;
-                       p_pt->f_port_in_ah = port_in_ah_key_qinq;
-                       break;
-
-               case FLOW_KEY_IPV4_5TUPLE:
-                       p_pt->f_hash = hash_default_key16;
-                       p_pt->f_port_in_ah = port_in_ah_key_ipv4;
-                       break;
-
-               case FLOW_KEY_IPV6_5TUPLE:
-                       p_pt->f_hash = hash_default_key64;
-                       p_pt->f_port_in_ah = port_in_ah_key_ipv6;
-                       break;
-
-               default:
-                       p_pt->f_hash = NULL;
-                       p_pt->f_port_in_ah = NULL;
-               }
+       if (pipeline_passthrough_swap_convert(p_pt))
+               return NULL;
+       p_pt->f_hash = get_hash_function(p_pt);
 
        /* Pipeline */
        {
@@ -584,15 +783,18 @@ pipeline_passthrough_init(struct pipeline_params *params,
                }
        }
 
-       /* Input ports */
        p->n_ports_in = params->n_ports_in;
+       p->n_ports_out = params->n_ports_out;
+       p->n_tables = p->n_ports_in;
+
+       /*Input ports*/
        for (i = 0; i < p->n_ports_in; i++) {
                struct rte_pipeline_port_in_params port_params = {
                        .ops = pipeline_port_in_params_get_ops(
                                &params->port_in[i]),
                        .arg_create = pipeline_port_in_params_convert(
                                &params->port_in[i]),
-                       .f_action = p_pt->f_port_in_ah,
+                       .f_action = get_port_in_ah(p_pt),
                        .arg_ah = p_pt,
                        .burst_size = params->port_in[i].burst_size,
                };
@@ -609,7 +811,6 @@ pipeline_passthrough_init(struct pipeline_params *params,
        }
 
        /* Output ports */
-       p->n_ports_out = params->n_ports_out;
        for (i = 0; i < p->n_ports_out; i++) {
                struct rte_pipeline_port_out_params port_params = {
                        .ops = pipeline_port_out_params_get_ops(
@@ -617,7 +818,6 @@ pipeline_passthrough_init(struct pipeline_params *params,
                        .arg_create = pipeline_port_out_params_convert(
                                &params->port_out[i]),
                        .f_action = NULL,
-                       .f_action_bulk = NULL,
                        .arg_ah = NULL,
                };
 
@@ -633,7 +833,6 @@ pipeline_passthrough_init(struct pipeline_params *params,
        }
 
        /* Tables */
-       p->n_tables = p->n_ports_in;
        for (i = 0; i < p->n_ports_in; i++) {
                struct rte_pipeline_table_params table_params = {
                        .ops = &rte_table_stub_ops,
@@ -670,10 +869,13 @@ pipeline_passthrough_init(struct pipeline_params *params,
 
        /* Add entries to tables */
        for (i = 0; i < p->n_ports_in; i++) {
+               uint32_t port_out_id = (p_pt->params.dma_hash_lb_enabled == 0) ?
+                       (i / (p->n_ports_in / p->n_ports_out)) :
+                       0;
+
                struct rte_pipeline_table_entry default_entry = {
                        .action = RTE_PIPELINE_ACTION_PORT,
-                       {.port_id = p->port_out_id[
-                               i / (p->n_ports_in / p->n_ports_out)]},
+                       {.port_id = p->port_out_id[port_out_id]},
                };
 
                struct rte_pipeline_table_entry *default_entry_ptr;
@@ -748,25 +950,9 @@ pipeline_passthrough_timer(void *pipeline)
        return 0;
 }
 
-static int
-pipeline_passthrough_track(void *pipeline, uint32_t port_in, uint32_t *port_out)
-{
-       struct pipeline *p = (struct pipeline *) pipeline;
-
-       /* Check input arguments */
-       if ((p == NULL) ||
-               (port_in >= p->n_ports_in) ||
-               (port_out == NULL))
-               return -1;
-
-       *port_out = port_in / p->n_ports_in;
-       return 0;
-}
-
 struct pipeline_be_ops pipeline_passthrough_be_ops = {
        .f_init = pipeline_passthrough_init,
        .f_free = pipeline_passthrough_free,
        .f_run = NULL,
        .f_timer = pipeline_passthrough_timer,
-       .f_track = pipeline_passthrough_track,
 };