From 840478c2f8d03060e0ab4ab2ba64339b49fb2cc6 Mon Sep 17 00:00:00 2001 From: Andrew Rybchenko Date: Tue, 13 Oct 2020 14:45:46 +0100 Subject: [PATCH] common/sfc_efx/base: provide helper to check Rx prefix A new function allows to check if used Rx prefix layout matches available Rx prefix layout. Length check is out-of-scope of the function and caller should ensure length is either checked or different length with everything required in place is handled properly. Signed-off-by: Andrew Rybchenko --- drivers/common/sfc_efx/base/efx.h | 12 ++++++ drivers/common/sfc_efx/base/efx_rx.c | 40 +++++++++++++++++++ .../sfc_efx/rte_common_sfc_efx_version.map | 1 + 3 files changed, 53 insertions(+) diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h index 406e96caf8..bd1ac303b1 100644 --- a/drivers/common/sfc_efx/base/efx.h +++ b/drivers/common/sfc_efx/base/efx.h @@ -2920,6 +2920,18 @@ typedef struct efx_rx_prefix_layout_s { efx_rx_prefix_field_info_t erpl_fields[EFX_RX_PREFIX_NFIELDS]; } efx_rx_prefix_layout_t; +/* + * Helper function to find out a bit mask of wanted but not available + * Rx prefix fields. + * + * A field is considered as not available if any parameter mismatch. + */ +LIBEFX_API +extern __checkReturn uint32_t +efx_rx_prefix_layout_check( + __in const efx_rx_prefix_layout_t *available, + __in const efx_rx_prefix_layout_t *wanted); + LIBEFX_API extern __checkReturn efx_rc_t efx_rx_prefix_get_layout( diff --git a/drivers/common/sfc_efx/base/efx_rx.c b/drivers/common/sfc_efx/base/efx_rx.c index d6b56fec48..93a73703ed 100644 --- a/drivers/common/sfc_efx/base/efx_rx.c +++ b/drivers/common/sfc_efx/base/efx_rx.c @@ -1803,3 +1803,43 @@ siena_rx_fini( } #endif /* EFSYS_OPT_SIENA */ + +static __checkReturn boolean_t +efx_rx_prefix_layout_fields_match( + __in const efx_rx_prefix_field_info_t *erpfip1, + __in const efx_rx_prefix_field_info_t *erpfip2) +{ + if (erpfip1->erpfi_offset_bits != erpfip2->erpfi_offset_bits) + return (B_FALSE); + + if (erpfip1->erpfi_width_bits != erpfip2->erpfi_width_bits) + return (B_FALSE); + + if (erpfip1->erpfi_big_endian != erpfip2->erpfi_big_endian) + return (B_FALSE); + + return (B_TRUE); +} + + __checkReturn uint32_t +efx_rx_prefix_layout_check( + __in const efx_rx_prefix_layout_t *available, + __in const efx_rx_prefix_layout_t *wanted) +{ + uint32_t result = 0; + unsigned int i; + + EFX_STATIC_ASSERT(EFX_RX_PREFIX_NFIELDS < sizeof (result) * 8); + for (i = 0; i < EFX_RX_PREFIX_NFIELDS; ++i) { + /* Skip the field if driver does not want to use it */ + if (wanted->erpl_fields[i].erpfi_width_bits == 0) + continue; + + if (efx_rx_prefix_layout_fields_match( + &available->erpl_fields[i], + &wanted->erpl_fields[i]) == B_FALSE) + result |= (1U << i); + } + + return (result); +} diff --git a/drivers/common/sfc_efx/rte_common_sfc_efx_version.map b/drivers/common/sfc_efx/rte_common_sfc_efx_version.map index fd95fd09e5..f656d5b644 100644 --- a/drivers/common/sfc_efx/rte_common_sfc_efx_version.map +++ b/drivers/common/sfc_efx/rte_common_sfc_efx_version.map @@ -141,6 +141,7 @@ INTERNAL { efx_rx_hash_default_support_get; efx_rx_init; efx_rx_prefix_get_layout; + efx_rx_prefix_layout_check; efx_rx_qcreate; efx_rx_qcreate_es_super_buffer; efx_rx_qdestroy; -- 2.20.1