net/virtio: rationalize queue flushing
[dpdk.git] / examples / ipsec-secgw / ipsec.c
index 4337e66..5fb5bc1 100644 (file)
@@ -166,7 +166,7 @@ create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa)
                        sa->pattern[2].type = RTE_FLOW_ITEM_TYPE_ESP;
                        sa->pattern[2].spec = &sa->esp_spec;
                        sa->pattern[2].mask = &rte_flow_item_esp_mask;
-                       sa->esp_spec.hdr.spi = sa->spi;
+                       sa->esp_spec.hdr.spi = rte_cpu_to_be_32(sa->spi);
 
                        sa->pattern[3].type = RTE_FLOW_ITEM_TYPE_END;
 
@@ -221,11 +221,24 @@ create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa)
                                        &(struct rte_flow_action_queue){
                                        .index = 0,
                                };
+                               ret = rte_flow_validate(sa->portid, &sa->attr,
+                                                       sa->pattern, sa->action,
+                                                       &err);
+                               /* Try End. */
+                               sa->action[1].type = RTE_FLOW_ACTION_TYPE_END;
+                               sa->action[1].conf = NULL;
                                ret = rte_flow_validate(sa->portid, &sa->attr,
                                                        sa->pattern, sa->action,
                                                        &err);
                                if (ret)
                                        goto flow_create_failure;
+                       } else if (sa->attr.egress &&
+                                  (sa->ol_flags &
+                                   RTE_SECURITY_TX_HW_TRAILER_OFFLOAD)) {
+                               sa->action[1].type =
+                                       RTE_FLOW_ACTION_TYPE_PASSTHRU;
+                               sa->action[2].type =
+                                       RTE_FLOW_ACTION_TYPE_END;
                        }
 flow_create:
                        sa->flow = rte_flow_create(sa->portid,
@@ -361,7 +374,6 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
        struct ipsec_mbuf_metadata *priv;
        struct rte_crypto_sym_op *sym_cop;
        struct ipsec_sa *sa;
-       struct cdev_qp *cqp;
 
        for (i = 0; i < nb_pkts; i++) {
                if (unlikely(sas[i] == NULL)) {
@@ -424,8 +436,7 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
                                continue;
                        }
 
-                       cqp = &ipsec_ctx->tbl[sa->cdev_id_qp];
-                       cqp->ol_pkts[cqp->ol_pkts_cnt++] = pkts[i];
+                       ipsec_ctx->ol_pkts[ipsec_ctx->ol_pkts_cnt++] = pkts[i];
                        if (sa->ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
                                rte_security_set_pkt_metadata(
                                                sa->security_ctx,
@@ -452,8 +463,7 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
                                continue;
                        }
 
-                       cqp = &ipsec_ctx->tbl[sa->cdev_id_qp];
-                       cqp->ol_pkts[cqp->ol_pkts_cnt++] = pkts[i];
+                       ipsec_ctx->ol_pkts[ipsec_ctx->ol_pkts_cnt++] = pkts[i];
                        if (sa->ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
                                rte_security_set_pkt_metadata(
                                                sa->security_ctx,
@@ -478,11 +488,10 @@ ipsec_dequeue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx,
 
        for (i = 0; i < ipsec_ctx->nb_qps && nb_pkts < max_pkts;) {
                struct cdev_qp *cqp;
-
                cqp = &ipsec_ctx->tbl[ipsec_ctx->last_qp];
 
-               while (cqp->ol_pkts_cnt > 0 && nb_pkts < max_pkts) {
-                       pkt = cqp->ol_pkts[--cqp->ol_pkts_cnt];
+               while (ipsec_ctx->ol_pkts_cnt > 0 && nb_pkts < max_pkts) {
+                       pkt = ipsec_ctx->ol_pkts[--ipsec_ctx->ol_pkts_cnt];
                        rte_prefetch0(pkt);
                        priv = get_priv(pkt);
                        sa = priv->sa;