net/sfc/base: support more RSS hash configurations
[dpdk.git] / drivers / net / sfc / base / efx_rx.c
index d0dd605..b02c7f6 100644 (file)
@@ -1,31 +1,7 @@
-/*
- * Copyright (c) 2007-2016 Solarflare Communications Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
+/* SPDX-License-Identifier: BSD-3-Clause
  *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are
- * those of the authors and should not be interpreted as representing official
- * policies, either expressed or implied, of the FreeBSD Project.
+ * Copyright (c) 2007-2018 Solarflare Communications Inc.
+ * All rights reserved.
  */
 
 #include "efx.h"
@@ -175,7 +151,7 @@ static const efx_rx_ops_t __efx_rx_siena_ops = {
 };
 #endif /* EFSYS_OPT_SIENA */
 
-#if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
+#if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
 static const efx_rx_ops_t __efx_rx_ef10_ops = {
        ef10_rx_init,                           /* erxo_init */
        ef10_rx_fini,                           /* erxo_fini */
@@ -202,7 +178,7 @@ static const efx_rx_ops_t __efx_rx_ef10_ops = {
        ef10_rx_qcreate,                        /* erxo_qcreate */
        ef10_rx_qdestroy,                       /* erxo_qdestroy */
 };
-#endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
+#endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */
 
 
        __checkReturn   efx_rc_t
@@ -244,6 +220,12 @@ efx_rx_init(
                break;
 #endif /* EFSYS_OPT_MEDFORD */
 
+#if EFSYS_OPT_MEDFORD2
+       case EFX_FAMILY_MEDFORD2:
+               erxop = &__efx_rx_ef10_ops;
+               break;
+#endif /* EFSYS_OPT_MEDFORD2 */
+
        default:
                EFSYS_ASSERT(0);
                rc = ENOTSUP;
@@ -312,6 +294,85 @@ fail1:
 #endif /* EFSYS_OPT_RX_SCATTER */
 
 #if EFSYS_OPT_RX_SCALE
+       __checkReturn                           efx_rc_t
+efx_rx_scale_hash_flags_get(
+       __in                                    efx_nic_t *enp,
+       __in                                    efx_rx_hash_alg_t hash_alg,
+       __inout_ecount(EFX_RX_HASH_NFLAGS)      unsigned int *flags,
+       __out                                   unsigned int *nflagsp)
+{
+       efx_nic_cfg_t *encp = &enp->en_nic_cfg;
+       boolean_t additional_modes;
+       unsigned int *entryp = flags;
+       efx_rc_t rc;
+
+       if (flags == NULL || nflagsp == NULL) {
+               rc = EINVAL;
+               goto fail1;
+       }
+
+       additional_modes = encp->enc_rx_scale_additional_modes_supported;
+
+#define        LIST_FLAGS(_entryp, _class, _l4_hashing, _additional_modes)     \
+       do {                                                            \
+               if (_l4_hashing) {                                      \
+                       *(_entryp++) = EFX_RX_HASH(_class, 4TUPLE);     \
+                                                                       \
+                       if (_additional_modes) {                        \
+                               *(_entryp++) =                          \
+                                   EFX_RX_HASH(_class, 2TUPLE_DST);    \
+                               *(_entryp++) =                          \
+                                   EFX_RX_HASH(_class, 2TUPLE_SRC);    \
+                       }                                               \
+               }                                                       \
+                                                                       \
+               *(_entryp++) = EFX_RX_HASH(_class, 2TUPLE);             \
+                                                                       \
+               if (_additional_modes) {                                \
+                       *(_entryp++) = EFX_RX_HASH(_class, 1TUPLE_DST); \
+                       *(_entryp++) = EFX_RX_HASH(_class, 1TUPLE_SRC); \
+               }                                                       \
+                                                                       \
+               *(_entryp++) = EFX_RX_HASH(_class, DISABLE);            \
+                                                                       \
+               _NOTE(CONSTANTCONDITION)                                \
+       } while (B_FALSE)
+
+       switch (hash_alg) {
+       case EFX_RX_HASHALG_TOEPLITZ:
+               LIST_FLAGS(entryp, IPV4_TCP, B_TRUE, additional_modes);
+               LIST_FLAGS(entryp, IPV6_TCP, B_TRUE, additional_modes);
+
+               if (additional_modes) {
+                       LIST_FLAGS(entryp, IPV4_UDP, B_TRUE, additional_modes);
+                       LIST_FLAGS(entryp, IPV6_UDP, B_TRUE, additional_modes);
+               }
+
+               LIST_FLAGS(entryp, IPV4, B_FALSE, additional_modes);
+               LIST_FLAGS(entryp, IPV6, B_FALSE, additional_modes);
+               break;
+
+       default:
+               rc = EINVAL;
+               goto fail2;
+       }
+
+#undef LIST_FLAGS
+
+       *nflagsp = (unsigned int)(entryp - flags);
+       EFSYS_ASSERT3U(*nflagsp, <=, EFX_RX_HASH_NFLAGS);
+
+       return (0);
+
+fail2:
+       EFSYS_PROBE(fail2);
+
+fail1:
+       EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+       return (rc);
+}
+
        __checkReturn   efx_rc_t
 efx_rx_hash_default_support_get(
        __in            efx_nic_t *enp,
@@ -443,19 +504,82 @@ efx_rx_scale_mode_set(
        __in            boolean_t insert)
 {
        const efx_rx_ops_t *erxop = enp->en_erxop;
+       unsigned int type_flags[EFX_RX_HASH_NFLAGS];
+       unsigned int type_nflags;
+       efx_rx_hash_type_t type_check;
+       unsigned int i;
        efx_rc_t rc;
 
        EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
        EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_RX);
 
+       /*
+        * Legacy flags and modern bits cannot be
+        * used at the same time in the hash type.
+        */
+       if ((type & EFX_RX_HASH_LEGACY_MASK) &&
+           (type & ~EFX_RX_HASH_LEGACY_MASK)) {
+               rc = EINVAL;
+               goto fail1;
+       }
+
+       /*
+        * Translate legacy flags to the new representation
+        * so that chip-specific handlers will consider the
+        * new flags only.
+        */
+       if (type & EFX_RX_HASH_IPV4) {
+               type |= EFX_RX_HASH(IPV4, 2TUPLE);
+               type |= EFX_RX_HASH(IPV4_TCP, 2TUPLE);
+               type |= EFX_RX_HASH(IPV4_UDP, 2TUPLE);
+       }
+
+       if (type & EFX_RX_HASH_TCPIPV4)
+               type |= EFX_RX_HASH(IPV4_TCP, 4TUPLE);
+
+       if (type & EFX_RX_HASH_IPV6) {
+               type |= EFX_RX_HASH(IPV6, 2TUPLE);
+               type |= EFX_RX_HASH(IPV6_TCP, 2TUPLE);
+               type |= EFX_RX_HASH(IPV6_UDP, 2TUPLE);
+       }
+
+       if (type & EFX_RX_HASH_TCPIPV6)
+               type |= EFX_RX_HASH(IPV6_TCP, 4TUPLE);
+
+       type &= ~EFX_RX_HASH_LEGACY_MASK;
+       type_check = type;
+
+       /*
+        * Get the list of supported hash flags and sanitise the input.
+        */
+       rc = efx_rx_scale_hash_flags_get(enp, alg, type_flags, &type_nflags);
+       if (rc != 0)
+               goto fail2;
+
+       for (i = 0; i < type_nflags; ++i) {
+               if ((type_check & type_flags[i]) == type_flags[i])
+                       type_check &= ~(type_flags[i]);
+       }
+
+       if (type_check != 0) {
+               rc = EINVAL;
+               goto fail3;
+       }
+
        if (erxop->erxo_scale_mode_set != NULL) {
                if ((rc = erxop->erxo_scale_mode_set(enp, rss_context, alg,
                            type, insert)) != 0)
-                       goto fail1;
+                       goto fail4;
        }
 
        return (0);
 
+fail4:
+       EFSYS_PROBE(fail4);
+fail3:
+       EFSYS_PROBE(fail3);
+fail2:
+       EFSYS_PROBE(fail2);
 fail1:
        EFSYS_PROBE1(fail1, efx_rc_t, rc);
        return (rc);
@@ -899,6 +1023,10 @@ siena_rx_scale_mode_set(
        __in            efx_rx_hash_type_t type,
        __in            boolean_t insert)
 {
+       efx_rx_hash_type_t type_ipv4 = EFX_RX_HASH(IPV4, 2TUPLE);
+       efx_rx_hash_type_t type_ipv4_tcp = EFX_RX_HASH(IPV4_TCP, 4TUPLE);
+       efx_rx_hash_type_t type_ipv6 = EFX_RX_HASH(IPV6, 2TUPLE);
+       efx_rx_hash_type_t type_ipv6_tcp = EFX_RX_HASH(IPV6_TCP, 4TUPLE);
        efx_rc_t rc;
 
        if (rss_context != EFX_RSS_CONTEXT_DEFAULT) {
@@ -913,12 +1041,12 @@ siena_rx_scale_mode_set(
 
        case EFX_RX_HASHALG_TOEPLITZ:
                EFX_RX_TOEPLITZ_IPV4_HASH(enp, insert,
-                   type & EFX_RX_HASH_IPV4,
-                   type & EFX_RX_HASH_TCPIPV4);
+                   (type & type_ipv4) == type_ipv4,
+                   (type & type_ipv4_tcp) == type_ipv4_tcp);
 
                EFX_RX_TOEPLITZ_IPV6_HASH(enp,
-                   type & EFX_RX_HASH_IPV6,
-                   type & EFX_RX_HASH_TCPIPV6,
+                   (type & type_ipv6) == type_ipv6,
+                   (type & type_ipv6_tcp) == type_ipv6_tcp,
                    rc);
                if (rc != 0)
                        goto fail2;