NAT goes after IP TTL decrement. It can operate on the outermost frame only. In the case of prior decapsulation, that maps to the frame which was (originally) the inner one. Input data for the action comes from the response of the HW conntrack assistance table hit.
Signed-off-by: Ivan Malov <ivan.ma...@arknetworks.am> Reviewed-by: Andy Moreton <amore...@xilinx.com> --- drivers/common/sfc_efx/base/efx.h | 13 +++++++++++++ drivers/common/sfc_efx/base/efx_impl.h | 1 + drivers/common/sfc_efx/base/efx_mae.c | 17 +++++++++++++++++ drivers/common/sfc_efx/version.map | 1 + 4 files changed, 32 insertions(+) diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h index 141481372c..abde5fea2e 100644 --- a/drivers/common/sfc_efx/base/efx.h +++ b/drivers/common/sfc_efx/base/efx.h @@ -4560,6 +4560,19 @@ extern __checkReturn efx_rc_t efx_mae_action_set_populate_decr_ip_ttl( __in efx_mae_actions_t *spec); +/* + * This only requests NAT action. The replacement IP address and + * L4 port number, as well as the edit direction (DST/SRC), come + * from the response to a hit in the conntrack assistance table. + * + * The action amends the outermost frame. In the case of prior + * decapsulation, that maps to the (originally) inner frame. + */ +LIBEFX_API +extern __checkReturn efx_rc_t +efx_mae_action_set_populate_nat( + __in efx_mae_actions_t *spec); + LIBEFX_API extern __checkReturn efx_rc_t efx_mae_action_set_populate_vlan_push( diff --git a/drivers/common/sfc_efx/base/efx_impl.h b/drivers/common/sfc_efx/base/efx_impl.h index 34e25ef990..f9d60b9eb9 100644 --- a/drivers/common/sfc_efx/base/efx_impl.h +++ b/drivers/common/sfc_efx/base/efx_impl.h @@ -1771,6 +1771,7 @@ typedef enum efx_mae_action_e { EFX_MAE_ACTION_SET_DST_MAC, EFX_MAE_ACTION_SET_SRC_MAC, EFX_MAE_ACTION_DECR_IP_TTL, + EFX_MAE_ACTION_NAT, EFX_MAE_ACTION_VLAN_PUSH, EFX_MAE_ACTION_COUNT, EFX_MAE_ACTION_ENCAP, diff --git a/drivers/common/sfc_efx/base/efx_mae.c b/drivers/common/sfc_efx/base/efx_mae.c index b3127b6db8..154d2f1942 100644 --- a/drivers/common/sfc_efx/base/efx_mae.c +++ b/drivers/common/sfc_efx/base/efx_mae.c @@ -1834,6 +1834,9 @@ static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = { [EFX_MAE_ACTION_DECR_IP_TTL] = { .emad_add = efx_mae_action_set_no_op }, + [EFX_MAE_ACTION_NAT] = { + .emad_add = efx_mae_action_set_no_op + }, [EFX_MAE_ACTION_VLAN_PUSH] = { .emad_add = efx_mae_action_set_add_vlan_push }, @@ -1860,6 +1863,7 @@ static const uint32_t efx_mae_action_ordered_map = (1U << EFX_MAE_ACTION_SET_DST_MAC) | (1U << EFX_MAE_ACTION_SET_SRC_MAC) | (1U << EFX_MAE_ACTION_DECR_IP_TTL) | + (1U << EFX_MAE_ACTION_NAT) | (1U << EFX_MAE_ACTION_VLAN_PUSH) | /* * HW will conduct action COUNT after @@ -2035,6 +2039,14 @@ efx_mae_action_set_populate_decr_ip_ttl( return (rc); } + __checkReturn efx_rc_t +efx_mae_action_set_populate_nat( + __in efx_mae_actions_t *spec) +{ + return (efx_mae_action_set_spec_populate(spec, + EFX_MAE_ACTION_NAT, 0, NULL)); +} + __checkReturn efx_rc_t efx_mae_action_set_populate_vlan_push( __in efx_mae_actions_t *spec, @@ -3090,6 +3102,11 @@ efx_mae_action_set_alloc( MAE_ACTION_SET_ALLOC_IN_DO_DECR_IP_TTL, 1); } + if ((spec->ema_actions & (1U << EFX_MAE_ACTION_NAT)) != 0) { + MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS, + MAE_ACTION_SET_ALLOC_IN_DO_NAT, 1); + } + if (spec->ema_n_vlan_tags_to_push > 0) { unsigned int outer_tag_idx; diff --git a/drivers/common/sfc_efx/version.map b/drivers/common/sfc_efx/version.map index f567f667b5..f601110f84 100644 --- a/drivers/common/sfc_efx/version.map +++ b/drivers/common/sfc_efx/version.map @@ -105,6 +105,7 @@ INTERNAL { efx_mae_action_set_populate_flag; efx_mae_action_set_populate_mark; efx_mae_action_set_populate_mark_reset; + efx_mae_action_set_populate_nat; efx_mae_action_set_populate_set_dst_mac; efx_mae_action_set_populate_set_src_mac; efx_mae_action_set_populate_vlan_pop; -- 2.30.2