ethdev: add namespace
[dpdk.git] / drivers / net / txgbe / txgbe_flow.c
index 488949c..6d7fd18 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2015-2020
+ * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
+ * Copyright(c) 2010-2017 Intel Corporation
  */
 
 #include <sys/queue.h>
@@ -129,6 +130,9 @@ const struct rte_flow_action *next_no_void_action(
  * END
  * other members in mask and spec should set to 0x00.
  * item->last should be NULL.
+ *
+ * Special case for flow action type RTE_FLOW_ACTION_TYPE_SECURITY.
+ *
  */
 static int
 cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
@@ -177,6 +181,43 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
        memset(&eth_null, 0, sizeof(struct rte_flow_item_eth));
        memset(&vlan_null, 0, sizeof(struct rte_flow_item_vlan));
 
+#ifdef RTE_LIB_SECURITY
+       /**
+        *  Special case for flow action type RTE_FLOW_ACTION_TYPE_SECURITY
+        */
+       act = next_no_void_action(actions, NULL);
+       if (act->type == RTE_FLOW_ACTION_TYPE_SECURITY) {
+               const void *conf = act->conf;
+               /* check if the next not void item is END */
+               act = next_no_void_action(actions, act);
+               if (act->type != RTE_FLOW_ACTION_TYPE_END) {
+                       memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
+                       rte_flow_error_set(error, EINVAL,
+                               RTE_FLOW_ERROR_TYPE_ACTION,
+                               act, "Not supported action.");
+                       return -rte_errno;
+               }
+
+               /* get the IP pattern*/
+               item = next_no_void_pattern(pattern, NULL);
+               while (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
+                               item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
+                       if (item->last ||
+                                       item->type == RTE_FLOW_ITEM_TYPE_END) {
+                               rte_flow_error_set(error, EINVAL,
+                                       RTE_FLOW_ERROR_TYPE_ITEM,
+                                       item, "IP pattern missing.");
+                               return -rte_errno;
+                       }
+                       item = next_no_void_pattern(pattern, item);
+               }
+
+               filter->proto = IPPROTO_ESP;
+               return txgbe_crypto_add_ingress_sa_from_flow(conf, item->spec,
+                                       item->type == RTE_FLOW_ITEM_TYPE_IPV6);
+       }
+#endif
+
        /* the first not void item can be MAC or IPv4 */
        item = next_no_void_pattern(pattern, NULL);
 
@@ -200,11 +241,10 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
                        return -rte_errno;
                }
                /* if the first item is MAC, the content should be NULL */
-               if ((item->spec || item->mask) &&
-                       (memcmp(eth_spec, &eth_null,
-                               sizeof(struct rte_flow_item_eth)) ||
-                        memcmp(eth_mask, &eth_null,
-                               sizeof(struct rte_flow_item_eth)))) {
+               if ((item->spec && memcmp(eth_spec, &eth_null,
+                                         sizeof(struct rte_flow_item_eth))) ||
+                   (item->mask && memcmp(eth_mask, &eth_null,
+                                         sizeof(struct rte_flow_item_eth)))) {
                        rte_flow_error_set(error, EINVAL,
                                RTE_FLOW_ERROR_TYPE_ITEM,
                                item, "Not supported by ntuple filter");
@@ -232,11 +272,10 @@ cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
                        return -rte_errno;
                }
                /* the content should be NULL */
-               if ((item->spec || item->mask) &&
-                       (memcmp(vlan_spec, &vlan_null,
-                               sizeof(struct rte_flow_item_vlan)) ||
-                        memcmp(vlan_mask, &vlan_null,
-                               sizeof(struct rte_flow_item_vlan)))) {
+               if ((item->spec && memcmp(vlan_spec, &vlan_null,
+                                         sizeof(struct rte_flow_item_vlan))) ||
+                   (item->mask && memcmp(vlan_mask, &vlan_null,
+                                         sizeof(struct rte_flow_item_vlan)))) {
                        rte_flow_error_set(error, EINVAL,
                                RTE_FLOW_ERROR_TYPE_ITEM,
                                item, "Not supported by ntuple filter");
@@ -472,7 +511,7 @@ action:
                memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
                rte_flow_error_set(error, EINVAL,
                        RTE_FLOW_ERROR_TYPE_ACTION,
-                       item, "Not supported action.");
+                       act, "Not supported action.");
                return -rte_errno;
        }
        filter->queue =
@@ -547,6 +586,12 @@ txgbe_parse_ntuple_filter(struct rte_eth_dev *dev,
        if (ret)
                return ret;
 
+#ifdef RTE_LIB_SECURITY
+       /* ESP flow not really a flow */
+       if (filter->proto == IPPROTO_ESP)
+               return 0;
+#endif
+
        /* txgbe doesn't support tcp flags */
        if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG) {
                memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
@@ -1170,7 +1215,7 @@ cons_parse_l2_tn_filter(struct rte_eth_dev *dev,
                return -rte_errno;
        }
 
-       filter->l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
+       filter->l2_tunnel_type = RTE_ETH_L2_TUNNEL_TYPE_E_TAG;
        /**
         * grp and e_cid_base are bit fields and only use 14 bits.
         * e-tag id is taken as little endian by HW.
@@ -2491,7 +2536,7 @@ txgbe_parse_rss_filter(struct rte_eth_dev *dev,
        /* check if the next not void item is END */
        act = next_no_void_action(actions, act);
        if (act->type != RTE_FLOW_ACTION_TYPE_END) {
-               memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
+               memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
                rte_flow_error_set(error, EINVAL,
                        RTE_FLOW_ERROR_TYPE_ACTION,
                        act, "Not supported action.");
@@ -2672,6 +2717,12 @@ txgbe_flow_create(struct rte_eth_dev *dev,
        ret = txgbe_parse_ntuple_filter(dev, attr, pattern,
                        actions, &ntuple_filter, error);
 
+#ifdef RTE_LIB_SECURITY
+       /* ESP flow not really a flow*/
+       if (ntuple_filter.proto == IPPROTO_ESP)
+               return flow;
+#endif
+
        if (!ret) {
                ret = txgbe_add_del_ntuple_filter(dev, &ntuple_filter, TRUE);
                if (!ret) {