From 3907defa5bf06a3e4bc87081b0633d925523a781 Mon Sep 17 00:00:00 2001 From: Ivan Malov Date: Fri, 12 Mar 2021 14:07:41 +0300 Subject: [PATCH] common/sfc_efx/base: support adding encap action to a set For convenience, there are two separate APIs provided, one for adding the action and one for setting the encap. header ID. This design allows the client driver to first build the action set specification (which validates the order of the actions) and, if everything is correct, proceed with allocation of the resource utilised by the action set (encap. header). This facilitates clarity of the client code and its efficiency. Signed-off-by: Ivan Malov Reviewed-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- drivers/common/sfc_efx/base/efx.h | 16 ++++ drivers/common/sfc_efx/base/efx_impl.h | 12 +++ drivers/common/sfc_efx/base/efx_mae.c | 126 ++++++++++++++++++++++++- drivers/common/sfc_efx/version.map | 2 + 4 files changed, 153 insertions(+), 3 deletions(-) diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h index 76d87994c3..f98c616278 100644 --- a/drivers/common/sfc_efx/base/efx.h +++ b/drivers/common/sfc_efx/base/efx.h @@ -4252,6 +4252,15 @@ efx_mae_action_set_populate_vlan_push( __in uint16_t tpid_be, __in uint16_t tci_be); +/* + * Use efx_mae_action_set_fill_in_eh_id() to set ID of the allocated + * encap. header in the specification prior to action set allocation. + */ +LIBEFX_API +extern __checkReturn efx_rc_t +efx_mae_action_set_populate_encap( + __in efx_mae_actions_t *spec); + LIBEFX_API extern __checkReturn efx_rc_t efx_mae_action_set_populate_flag( @@ -4345,6 +4354,13 @@ efx_mae_encap_header_free( __in efx_nic_t *enp, __in const efx_mae_eh_id_t *eh_idp); +/* See description before efx_mae_action_set_populate_encap(). */ +LIBEFX_API +extern __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); + /* Action set ID */ typedef struct efx_mae_aset_id_s { uint32_t id; diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h index aa878014c1..c76ed9bbe6 100644 --- a/drivers/common/sfc_efx/base/efx_impl.h +++ b/drivers/common/sfc_efx/base/efx_impl.h @@ -1729,6 +1729,7 @@ typedef enum efx_mae_action_e { /* These actions are strictly ordered. */ EFX_MAE_ACTION_VLAN_POP, EFX_MAE_ACTION_VLAN_PUSH, + EFX_MAE_ACTION_ENCAP, /* * These actions are not strictly ordered and can @@ -1756,6 +1757,10 @@ typedef struct efx_mae_action_vlan_push_s { uint16_t emavp_tci_be; } efx_mae_action_vlan_push_t; +typedef struct efx_mae_actions_rsrc_s { + efx_mae_eh_id_t emar_eh_id; +} efx_mae_actions_rsrc_t; + struct efx_mae_actions_s { /* Bitmap of actions in spec, indexed by action type */ uint32_t ema_actions; @@ -1766,6 +1771,13 @@ struct efx_mae_actions_s { EFX_MAE_VLAN_PUSH_MAX_NTAGS]; uint32_t ema_mark_value; efx_mport_sel_t ema_deliver_mport; + + /* + * Always keep this at the end of the struct since + * efx_mae_action_set_specs_equal() relies on that + * to make sure that resource IDs are not compared. + */ + efx_mae_actions_rsrc_t ema_rsrc; }; #endif /* EFSYS_OPT_MAE */ diff --git a/drivers/common/sfc_efx/base/efx_mae.c b/drivers/common/sfc_efx/base/efx_mae.c index 834e8f9afe..fc112f8323 100644 --- a/drivers/common/sfc_efx/base/efx_mae.c +++ b/drivers/common/sfc_efx/base/efx_mae.c @@ -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); diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map index 49a380c7ba..7e88674ead 100644 --- a/drivers/common/sfc_efx/version.map +++ b/drivers/common/sfc_efx/version.map @@ -88,9 +88,11 @@ INTERNAL { efx_mae_action_rule_insert; efx_mae_action_rule_remove; efx_mae_action_set_alloc; + efx_mae_action_set_fill_in_eh_id; efx_mae_action_set_free; efx_mae_action_set_populate_deliver; efx_mae_action_set_populate_drop; + efx_mae_action_set_populate_encap; efx_mae_action_set_populate_flag; efx_mae_action_set_populate_mark; efx_mae_action_set_populate_vlan_pop; -- 2.20.1