common/sfc_efx/base: provide helper to check Rx prefix
authorAndrew Rybchenko <arybchenko@solarflare.com>
Tue, 13 Oct 2020 13:45:46 +0000 (14:45 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 16 Oct 2020 17:48:18 +0000 (19:48 +0200)
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 <arybchenko@solarflare.com>
drivers/common/sfc_efx/base/efx.h
drivers/common/sfc_efx/base/efx_rx.c
drivers/common/sfc_efx/rte_common_sfc_efx_version.map

index 406e96c..bd1ac30 100644 (file)
@@ -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(
index d6b56fe..93a7370 100644 (file)
@@ -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);
+}
index fd95fd0..f656d5b 100644 (file)
@@ -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;