common/cnxk: check BPHY IRQ availability
[dpdk.git] / drivers / common / sfc_efx / base / efx_mae.c
index 834e8f9..c178421 100644 (file)
@@ -46,17 +46,20 @@ efx_mae_get_capabilities(
 
        maep->em_encap_types_supported = 0;
 
-       if (MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_ENCAP_TYPE_VXLAN) == 1) {
+       if (MCDI_OUT_DWORD_FIELD(req, MAE_GET_CAPS_OUT_ENCAP_TYPES_SUPPORTED,
+           MAE_GET_CAPS_OUT_ENCAP_TYPE_VXLAN) != 0) {
                maep->em_encap_types_supported |=
                    (1U << EFX_TUNNEL_PROTOCOL_VXLAN);
        }
 
-       if (MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_ENCAP_TYPE_GENEVE) == 1) {
+       if (MCDI_OUT_DWORD_FIELD(req, MAE_GET_CAPS_OUT_ENCAP_TYPES_SUPPORTED,
+           MAE_GET_CAPS_OUT_ENCAP_TYPE_GENEVE) != 0) {
                maep->em_encap_types_supported |=
                    (1U << EFX_TUNNEL_PROTOCOL_GENEVE);
        }
 
-       if (MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_ENCAP_TYPE_NVGRE) == 1) {
+       if (MCDI_OUT_DWORD_FIELD(req, MAE_GET_CAPS_OUT_ENCAP_TYPES_SUPPORTED,
+           MAE_GET_CAPS_OUT_ENCAP_TYPE_NVGRE) != 0) {
                maep->em_encap_types_supported |=
                    (1U << EFX_TUNNEL_PROTOCOL_NVGRE);
        }
@@ -106,17 +109,22 @@ efx_mae_get_outer_rule_caps(
                goto fail2;
        }
 
+       if (req.emr_out_length_used < MC_CMD_MAE_GET_OR_CAPS_OUT_LENMIN) {
+               rc = EMSGSIZE;
+               goto fail3;
+       }
+
        mcdi_field_ncaps = MCDI_OUT_DWORD(req, MAE_GET_OR_CAPS_OUT_COUNT);
 
        if (req.emr_out_length_used <
            MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(mcdi_field_ncaps)) {
                rc = EMSGSIZE;
-               goto fail3;
+               goto fail4;
        }
 
        if (mcdi_field_ncaps > field_ncaps) {
                rc = EMSGSIZE;
-               goto fail4;
+               goto fail5;
        }
 
        for (i = 0; i < mcdi_field_ncaps; ++i) {
@@ -144,6 +152,8 @@ efx_mae_get_outer_rule_caps(
 
        return (0);
 
+fail5:
+       EFSYS_PROBE(fail5);
 fail4:
        EFSYS_PROBE(fail4);
 fail3:
@@ -188,17 +198,22 @@ efx_mae_get_action_rule_caps(
                goto fail2;
        }
 
-       mcdi_field_ncaps = MCDI_OUT_DWORD(req, MAE_GET_OR_CAPS_OUT_COUNT);
+       if (req.emr_out_length_used < MC_CMD_MAE_GET_AR_CAPS_OUT_LENMIN) {
+               rc = EMSGSIZE;
+               goto fail3;
+       }
+
+       mcdi_field_ncaps = MCDI_OUT_DWORD(req, MAE_GET_AR_CAPS_OUT_COUNT);
 
        if (req.emr_out_length_used <
            MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(mcdi_field_ncaps)) {
                rc = EMSGSIZE;
-               goto fail3;
+               goto fail4;
        }
 
        if (mcdi_field_ncaps > field_ncaps) {
                rc = EMSGSIZE;
-               goto fail4;
+               goto fail5;
        }
 
        for (i = 0; i < mcdi_field_ncaps; ++i) {
@@ -226,6 +241,8 @@ efx_mae_get_action_rule_caps(
 
        return (0);
 
+fail5:
+       EFSYS_PROBE(fail5);
 fail4:
        EFSYS_PROBE(fail4);
 fail3:
@@ -993,6 +1010,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);
@@ -1010,6 +1029,37 @@ efx_mae_action_set_spec_fini(
        EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
 }
 
+static __checkReturn                   efx_rc_t
+efx_mae_action_set_add_decap(
+       __in                            efx_mae_actions_t *spec,
+       __in                            size_t arg_size,
+       __in_bcount(arg_size)           const uint8_t *arg)
+{
+       efx_rc_t rc;
+
+       _NOTE(ARGUNUSED(spec))
+
+       if (arg_size != 0) {
+               rc = EINVAL;
+               goto fail1;
+       }
+
+       if (arg != NULL) {
+               rc = EINVAL;
+               goto fail2;
+       }
+
+       /* This action does not have any arguments, so do nothing here. */
+
+       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_vlan_pop(
        __in                            efx_mae_actions_t *spec,
@@ -1084,6 +1134,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,
@@ -1180,12 +1274,18 @@ typedef struct efx_mae_action_desc_s {
 } efx_mae_action_desc_t;
 
 static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
+       [EFX_MAE_ACTION_DECAP] = {
+               .emad_add = efx_mae_action_set_add_decap
+       },
        [EFX_MAE_ACTION_VLAN_POP] = {
                .emad_add = efx_mae_action_set_add_vlan_pop
        },
        [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
        },
@@ -1198,8 +1298,10 @@ 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_DECAP) |
        (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);
@@ -1292,6 +1394,14 @@ fail1:
        return (rc);
 }
 
+       __checkReturn                   efx_rc_t
+efx_mae_action_set_populate_decap(
+       __in                            efx_mae_actions_t *spec)
+{
+       return (efx_mae_action_set_spec_populate(spec,
+           EFX_MAE_ACTION_DECAP, 0, NULL));
+}
+
        __checkReturn                   efx_rc_t
 efx_mae_action_set_populate_vlan_pop(
        __in                            efx_mae_actions_t *spec)
@@ -1316,6 +1426,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 +1512,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
@@ -1648,15 +1787,22 @@ efx_mae_outer_rule_remove(
                goto fail2;
        }
 
+       if (req.emr_out_length_used < MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LENMIN) {
+               rc = EMSGSIZE;
+               goto fail3;
+       }
+
        if (MCDI_OUT_DWORD(req, MAE_OUTER_RULE_REMOVE_OUT_REMOVED_OR_ID) !=
            or_idp->id) {
                /* Firmware failed to remove the outer rule. */
                rc = EAGAIN;
-               goto fail3;
+               goto fail4;
        }
 
        return (0);
 
+fail4:
+       EFSYS_PROBE(fail4);
 fail3:
        EFSYS_PROBE(fail3);
 fail2:
@@ -1845,6 +1991,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 +2074,11 @@ 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);
+
+       if ((spec->ema_actions & (1U << EFX_MAE_ACTION_DECAP)) != 0) {
+               MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
+                   MAE_ACTION_SET_ALLOC_IN_DECAP, 1);
+       }
 
        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 +2108,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);
@@ -2005,15 +2197,22 @@ efx_mae_action_set_free(
                goto fail2;
        }
 
+       if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_FREE_OUT_LENMIN) {
+               rc = EMSGSIZE;
+               goto fail3;
+       }
+
        if (MCDI_OUT_DWORD(req, MAE_ACTION_SET_FREE_OUT_FREED_AS_ID) !=
            aset_idp->id) {
                /* Firmware failed to free the action set. */
                rc = EAGAIN;
-               goto fail3;
+               goto fail4;
        }
 
        return (0);
 
+fail4:
+       EFSYS_PROBE(fail4);
 fail3:
        EFSYS_PROBE(fail3);
 fail2:
@@ -2155,15 +2354,23 @@ efx_mae_action_rule_remove(
                goto fail2;
        }
 
+       if (req.emr_out_length_used <
+           MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LENMIN) {
+               rc = EMSGSIZE;
+               goto fail3;
+       }
+
        if (MCDI_OUT_DWORD(req, MAE_ACTION_RULE_DELETE_OUT_DELETED_AR_ID) !=
            ar_idp->id) {
                /* Firmware failed to delete the action rule. */
                rc = EAGAIN;
-               goto fail3;
+               goto fail4;
        }
 
        return (0);
 
+fail4:
+       EFSYS_PROBE(fail4);
 fail3:
        EFSYS_PROBE(fail3);
 fail2: