net/enic: support VXLAN decap action combined with VLAN pop
[dpdk.git] / drivers / net / enic / enic_fm_flow.c
index 94e39a9..34c9005 100644 (file)
@@ -923,6 +923,20 @@ enic_fm_append_action_op(struct enic_flowman *fm,
        return 0;
 }
 
+static struct fm_action_op *
+find_prev_action_op(struct enic_flowman *fm, uint32_t opcode)
+{
+       struct fm_action_op *op;
+       int i;
+
+       for (i = 0; i < fm->action_op_count; i++) {
+               op = &fm->action.fma_action_ops[i];
+               if (op->fa_op == opcode)
+                       return op;
+       }
+       return NULL;
+}
+
 /* NIC requires that 1st steer appear before decap.
  * Correct example: steer, decap, steer, steer, ...
  */
@@ -938,7 +952,8 @@ enic_fm_reorder_action_op(struct enic_flowman *fm)
        steer = NULL;
        decap = NULL;
        while (op->fa_op != FMOP_END) {
-               if (!decap && op->fa_op == FMOP_DECAP_NOSTRIP)
+               if (!decap && (op->fa_op == FMOP_DECAP_NOSTRIP ||
+                              op->fa_op == FMOP_DECAP_STRIP))
                        decap = op;
                else if (!steer && op->fa_op == FMOP_RQ_STEER)
                        steer = op;
@@ -978,6 +993,17 @@ enic_fm_copy_vxlan_decap(struct enic_flowman *fm,
        return enic_fm_append_action_op(fm, &fm_op, error);
 }
 
+/* Generate a reasonable source port number */
+static uint16_t
+gen_src_port(void)
+{
+       /* Min/max below are the default values in OVS-DPDK and Linux */
+       uint16_t p = rte_rand();
+       p = RTE_MAX(p, 32768);
+       p = RTE_MIN(p, 61000);
+       return rte_cpu_to_be_16(p);
+}
+
 /* VXLAN encap is done via flowman compound action */
 static int
 enic_fm_copy_vxlan_encap(struct enic_flowman *fm,
@@ -986,6 +1012,7 @@ enic_fm_copy_vxlan_encap(struct enic_flowman *fm,
 {
        struct fm_action_op fm_op;
        struct rte_ether_hdr *eth;
+       struct rte_udp_hdr *udp;
        uint16_t *ethertype;
        void *template;
        uint8_t off;
@@ -1084,8 +1111,17 @@ enic_fm_copy_vxlan_encap(struct enic_flowman *fm,
                off + offsetof(struct rte_udp_hdr, dgram_len);
        fm_op.encap.len2_delta =
                sizeof(struct rte_udp_hdr) + sizeof(struct rte_vxlan_hdr);
+       udp = (struct rte_udp_hdr *)template;
        append_template(&template, &off, item->spec,
                        sizeof(struct rte_udp_hdr));
+       /*
+        * Firmware does not hash/fill source port yet. Generate a
+        * random port, as there is *usually* one rte_flow for the
+        * given inner packet stream (i.e. a single stream has one
+        * random port).
+        */
+       if (udp->src_port == 0)
+               udp->src_port = gen_src_port();
        item++;
        flow_item_skip_void(&item);
 
@@ -1451,6 +1487,19 @@ enic_fm_copy_action(struct enic_flowman *fm,
                        break;
                }
                case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN: {
+                       struct fm_action_op *decap;
+
+                       /*
+                        * If decap-nostrip appears before pop vlan, this pop
+                        * applies to the inner packet vlan. Turn it into
+                        * decap-strip.
+                        */
+                       decap = find_prev_action_op(fm, FMOP_DECAP_NOSTRIP);
+                       if (decap) {
+                               ENICPMD_LOG(DEBUG, "pop-vlan inner: decap-nostrip => decap-strip");
+                               decap->fa_op = FMOP_DECAP_STRIP;
+                               break;
+                       }
                        memset(&fm_op, 0, sizeof(fm_op));
                        fm_op.fa_op = FMOP_POP_VLAN;
                        ret = enic_fm_append_action_op(fm, &fm_op, error);