common/sfc_efx/base: support adding encap action to a set
[dpdk.git] / drivers / common / sfc_efx / base / efx_mae.c
index 834e8f9..fc112f8 100644 (file)
@@ -993,6 +993,8 @@ efx_mae_action_set_spec_init(
                goto fail1;
        }
 
+       spec->ema_rsrc.emar_eh_id.id = EFX_MAE_RSRC_ID_INVALID;
+
        *specp = spec;
 
        return (0);
@@ -1084,6 +1086,50 @@ fail1:
        return (rc);
 }
 
+static __checkReturn                   efx_rc_t
+efx_mae_action_set_add_encap(
+       __in                            efx_mae_actions_t *spec,
+       __in                            size_t arg_size,
+       __in_bcount(arg_size)           const uint8_t *arg)
+{
+       efx_rc_t rc;
+
+       /*
+        * Adding this specific action to an action set spec and setting encap.
+        * header ID in the spec are two individual steps. This design allows
+        * the client driver to avoid encap. header allocation when it simply
+        * needs to check the order of actions submitted by user ("validate"),
+        * without actually allocating an action set and inserting a rule.
+        *
+        * For now, mark encap. header ID as invalid; the caller will invoke
+        * efx_mae_action_set_fill_in_eh_id() to override the field prior
+        * to action set allocation; otherwise, the allocation will fail.
+        */
+       spec->ema_rsrc.emar_eh_id.id = EFX_MAE_RSRC_ID_INVALID;
+
+       /*
+        * As explained above, there are no arguments to handle here.
+        * efx_mae_action_set_fill_in_eh_id() will take care of them.
+        */
+       if (arg_size != 0) {
+               rc = EINVAL;
+               goto fail1;
+       }
+
+       if (arg != NULL) {
+               rc = EINVAL;
+               goto fail2;
+       }
+
+       return (0);
+
+fail2:
+       EFSYS_PROBE(fail2);
+fail1:
+       EFSYS_PROBE1(fail1, efx_rc_t, rc);
+       return (rc);
+}
+
 static __checkReturn                   efx_rc_t
 efx_mae_action_set_add_flag(
        __in                            efx_mae_actions_t *spec,
@@ -1186,6 +1232,9 @@ static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
        [EFX_MAE_ACTION_VLAN_PUSH] = {
                .emad_add = efx_mae_action_set_add_vlan_push
        },
+       [EFX_MAE_ACTION_ENCAP] = {
+               .emad_add = efx_mae_action_set_add_encap
+       },
        [EFX_MAE_ACTION_FLAG] = {
                .emad_add = efx_mae_action_set_add_flag
        },
@@ -1200,6 +1249,7 @@ static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
 static const uint32_t efx_mae_action_ordered_map =
        (1U << EFX_MAE_ACTION_VLAN_POP) |
        (1U << EFX_MAE_ACTION_VLAN_PUSH) |
+       (1U << EFX_MAE_ACTION_ENCAP) |
        (1U << EFX_MAE_ACTION_FLAG) |
        (1U << EFX_MAE_ACTION_MARK) |
        (1U << EFX_MAE_ACTION_DELIVER);
@@ -1316,6 +1366,20 @@ efx_mae_action_set_populate_vlan_push(
            EFX_MAE_ACTION_VLAN_PUSH, sizeof (action), arg));
 }
 
+       __checkReturn                   efx_rc_t
+efx_mae_action_set_populate_encap(
+       __in                            efx_mae_actions_t *spec)
+{
+       /*
+        * There is no argument to pass encap. header ID, thus, one does not
+        * need to allocate an encap. header while parsing application input.
+        * This is useful since building an action set may be done simply to
+        * validate a rule, whilst resource allocation usually consumes time.
+        */
+       return (efx_mae_action_set_spec_populate(spec,
+           EFX_MAE_ACTION_ENCAP, 0, NULL));
+}
+
        __checkReturn                   efx_rc_t
 efx_mae_action_set_populate_flag(
        __in                            efx_mae_actions_t *spec)
@@ -1388,7 +1452,22 @@ efx_mae_action_set_specs_equal(
        __in                            const efx_mae_actions_t *left,
        __in                            const efx_mae_actions_t *right)
 {
-       return ((memcmp(left, right, sizeof (*left)) == 0) ? B_TRUE : B_FALSE);
+       size_t cmp_size = EFX_FIELD_OFFSET(efx_mae_actions_t, ema_rsrc);
+
+       /*
+        * An action set specification consists of two parts. The first part
+        * indicates what actions are included in the action set, as well as
+        * extra quantitative values (in example, the number of VLAN tags to
+        * push). The second part comprises resource IDs used by the actions.
+        *
+        * A resource, in example, a counter, is allocated from the hardware
+        * by the client, and it's the client who is responsible for keeping
+        * track of allocated resources and comparing resource IDs if needed.
+        *
+        * In this API, don't compare resource IDs in the two specifications.
+        */
+
+       return ((memcmp(left, right, cmp_size) == 0) ? B_TRUE : B_FALSE);
 }
 
        __checkReturn                   efx_rc_t
@@ -1845,6 +1924,46 @@ efx_mae_encap_header_free(
 
        return (0);
 
+fail3:
+       EFSYS_PROBE(fail3);
+fail2:
+       EFSYS_PROBE(fail2);
+fail1:
+       EFSYS_PROBE1(fail1, efx_rc_t, rc);
+       return (rc);
+}
+
+       __checkReturn                   efx_rc_t
+efx_mae_action_set_fill_in_eh_id(
+       __in                            efx_mae_actions_t *spec,
+       __in                            const efx_mae_eh_id_t *eh_idp)
+{
+       efx_rc_t rc;
+
+       if ((spec->ema_actions & (1U << EFX_MAE_ACTION_ENCAP)) == 0) {
+               /*
+                * The caller has not intended to have action ENCAP originally,
+                * hence, this attempt to indicate encap. header ID is invalid.
+                */
+               rc = EINVAL;
+               goto fail1;
+       }
+
+       if (spec->ema_rsrc.emar_eh_id.id != EFX_MAE_RSRC_ID_INVALID) {
+               /* The caller attempts to indicate encap. header ID twice. */
+               rc = EINVAL;
+               goto fail2;
+       }
+
+       if (eh_idp->id == EFX_MAE_RSRC_ID_INVALID) {
+               rc = EINVAL;
+               goto fail3;
+       }
+
+       spec->ema_rsrc.emar_eh_id.id = eh_idp->id;
+
+       return (0);
+
 fail3:
        EFSYS_PROBE(fail3);
 fail2:
@@ -1888,8 +2007,6 @@ efx_mae_action_set_alloc(
            MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID, EFX_MAE_RSRC_ID_INVALID);
        MCDI_IN_SET_DWORD(req,
            MAE_ACTION_SET_ALLOC_IN_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
-       MCDI_IN_SET_DWORD(req,
-           MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID, EFX_MAE_RSRC_ID_INVALID);
 
        MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
            MAE_ACTION_SET_ALLOC_IN_VLAN_POP, spec->ema_n_vlan_tags_to_pop);
@@ -1919,6 +2036,9 @@ efx_mae_action_set_alloc(
                    spec->ema_vlan_push_descs[outer_tag_idx].emavp_tci_be);
        }
 
+       MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID,
+           spec->ema_rsrc.emar_eh_id.id);
+
        if ((spec->ema_actions & (1U << EFX_MAE_ACTION_FLAG)) != 0) {
                MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
                    MAE_ACTION_SET_ALLOC_IN_FLAG, 1);