net/sfc: support MARK and FLAG actions in flow API
[dpdk.git] / drivers / net / sfc / sfc_flow.c
index b7e54d7..e6b2ecf 100644 (file)
@@ -23,6 +23,7 @@
 #include "sfc_filter.h"
 #include "sfc_flow.h"
 #include "sfc_log.h"
+#include "sfc_dp_rx.h"
 
 /*
  * At now flow API is implemented in such a manner that each
@@ -1500,6 +1501,22 @@ sfc_flow_filter_remove(struct sfc_adapter *sa,
        return rc;
 }
 
+static int
+sfc_flow_parse_mark(struct sfc_adapter *sa,
+                   const struct rte_flow_action_mark *mark,
+                   struct rte_flow *flow)
+{
+       const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
+
+       if (mark == NULL || mark->id > encp->enc_filter_action_mark_max)
+               return EINVAL;
+
+       flow->spec.template.efs_flags |= EFX_FILTER_FLAG_ACTION_MARK;
+       flow->spec.template.efs_mark = mark->id;
+
+       return 0;
+}
+
 static int
 sfc_flow_parse_actions(struct sfc_adapter *sa,
                       const struct rte_flow_action actions[],
@@ -1507,7 +1524,13 @@ sfc_flow_parse_actions(struct sfc_adapter *sa,
                       struct rte_flow_error *error)
 {
        int rc;
-       boolean_t is_specified = B_FALSE;
+       const unsigned int dp_rx_features = sa->dp_rx->features;
+       uint32_t actions_set = 0;
+       const uint32_t fate_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_QUEUE) |
+                                          (1UL << RTE_FLOW_ACTION_TYPE_RSS) |
+                                          (1UL << RTE_FLOW_ACTION_TYPE_DROP);
+       const uint32_t mark_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_MARK) |
+                                          (1UL << RTE_FLOW_ACTION_TYPE_FLAG);
 
        if (actions == NULL) {
                rte_flow_error_set(error, EINVAL,
@@ -1516,21 +1539,22 @@ sfc_flow_parse_actions(struct sfc_adapter *sa,
                return -rte_errno;
        }
 
+#define SFC_BUILD_SET_OVERFLOW(_action, _set) \
+       RTE_BUILD_BUG_ON(_action >= sizeof(_set) * CHAR_BIT)
+
        for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
-               /* This one may appear anywhere multiple times. */
-               if (actions->type == RTE_FLOW_ACTION_TYPE_VOID)
-                       continue;
-               /* Fate-deciding actions may appear exactly once. */
-               if (is_specified) {
-                       rte_flow_error_set
-                               (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
-                                actions,
-                                "Cannot combine several fate-deciding actions,"
-                                "choose between QUEUE, RSS or DROP");
-                       return -rte_errno;
-               }
                switch (actions->type) {
+               case RTE_FLOW_ACTION_TYPE_VOID:
+                       SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VOID,
+                                              actions_set);
+                       break;
+
                case RTE_FLOW_ACTION_TYPE_QUEUE:
+                       SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_QUEUE,
+                                              actions_set);
+                       if ((actions_set & fate_actions_mask) != 0)
+                               goto fail_fate_actions;
+
                        rc = sfc_flow_parse_queue(sa, actions->conf, flow);
                        if (rc != 0) {
                                rte_flow_error_set(error, EINVAL,
@@ -1538,11 +1562,14 @@ sfc_flow_parse_actions(struct sfc_adapter *sa,
                                        "Bad QUEUE action");
                                return -rte_errno;
                        }
-
-                       is_specified = B_TRUE;
                        break;
 
                case RTE_FLOW_ACTION_TYPE_RSS:
+                       SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_RSS,
+                                              actions_set);
+                       if ((actions_set & fate_actions_mask) != 0)
+                               goto fail_fate_actions;
+
                        rc = sfc_flow_parse_rss(sa, actions->conf, flow);
                        if (rc != 0) {
                                rte_flow_error_set(error, rc,
@@ -1550,15 +1577,55 @@ sfc_flow_parse_actions(struct sfc_adapter *sa,
                                        "Bad RSS action");
                                return -rte_errno;
                        }
-
-                       is_specified = B_TRUE;
                        break;
 
                case RTE_FLOW_ACTION_TYPE_DROP:
+                       SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
+                                              actions_set);
+                       if ((actions_set & fate_actions_mask) != 0)
+                               goto fail_fate_actions;
+
                        flow->spec.template.efs_dmaq_id =
                                EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
+                       break;
+
+               case RTE_FLOW_ACTION_TYPE_FLAG:
+                       SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
+                                              actions_set);
+                       if ((actions_set & mark_actions_mask) != 0)
+                               goto fail_actions_overlap;
 
-                       is_specified = B_TRUE;
+                       if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_FLAG) == 0) {
+                               rte_flow_error_set(error, ENOTSUP,
+                                       RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+                                       "FLAG action is not supported on the current Rx datapath");
+                               return -rte_errno;
+                       }
+
+                       flow->spec.template.efs_flags |=
+                               EFX_FILTER_FLAG_ACTION_FLAG;
+                       break;
+
+               case RTE_FLOW_ACTION_TYPE_MARK:
+                       SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
+                                              actions_set);
+                       if ((actions_set & mark_actions_mask) != 0)
+                               goto fail_actions_overlap;
+
+                       if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_MARK) == 0) {
+                               rte_flow_error_set(error, ENOTSUP,
+                                       RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+                                       "MARK action is not supported on the current Rx datapath");
+                               return -rte_errno;
+                       }
+
+                       rc = sfc_flow_parse_mark(sa, actions->conf, flow);
+                       if (rc != 0) {
+                               rte_flow_error_set(error, rc,
+                                       RTE_FLOW_ERROR_TYPE_ACTION, actions,
+                                       "Bad MARK action");
+                               return -rte_errno;
+                       }
                        break;
 
                default:
@@ -1567,15 +1634,29 @@ sfc_flow_parse_actions(struct sfc_adapter *sa,
                                           "Action is not supported");
                        return -rte_errno;
                }
+
+               actions_set |= (1UL << actions->type);
        }
+#undef SFC_BUILD_SET_OVERFLOW
 
        /* When fate is unknown, drop traffic. */
-       if (!is_specified) {
+       if ((actions_set & fate_actions_mask) == 0) {
                flow->spec.template.efs_dmaq_id =
                        EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
        }
 
        return 0;
+
+fail_fate_actions:
+       rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
+                          "Cannot combine several fate-deciding actions, "
+                          "choose between QUEUE, RSS or DROP");
+       return -rte_errno;
+
+fail_actions_overlap:
+       rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
+                          "Overlapping actions are not supported");
+       return -rte_errno;
 }
 
 /**