171d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */
2015f8cc5SEric Joyner /* Copyright (c) 2024, Intel Corporation
371d10453SEric Joyner * All rights reserved.
471d10453SEric Joyner *
571d10453SEric Joyner * Redistribution and use in source and binary forms, with or without
671d10453SEric Joyner * modification, are permitted provided that the following conditions are met:
771d10453SEric Joyner *
871d10453SEric Joyner * 1. Redistributions of source code must retain the above copyright notice,
971d10453SEric Joyner * this list of conditions and the following disclaimer.
1071d10453SEric Joyner *
1171d10453SEric Joyner * 2. Redistributions in binary form must reproduce the above copyright
1271d10453SEric Joyner * notice, this list of conditions and the following disclaimer in the
1371d10453SEric Joyner * documentation and/or other materials provided with the distribution.
1471d10453SEric Joyner *
1571d10453SEric Joyner * 3. Neither the name of the Intel Corporation nor the names of its
1671d10453SEric Joyner * contributors may be used to endorse or promote products derived from
1771d10453SEric Joyner * this software without specific prior written permission.
1871d10453SEric Joyner *
1971d10453SEric Joyner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2071d10453SEric Joyner * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2171d10453SEric Joyner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2271d10453SEric Joyner * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2371d10453SEric Joyner * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2471d10453SEric Joyner * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2571d10453SEric Joyner * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2671d10453SEric Joyner * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2771d10453SEric Joyner * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2871d10453SEric Joyner * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2971d10453SEric Joyner * POSSIBILITY OF SUCH DAMAGE.
3071d10453SEric Joyner */
3171d10453SEric Joyner
3271d10453SEric Joyner /**
3371d10453SEric Joyner * @file ice_rss.h
3471d10453SEric Joyner * @brief default RSS values if kernel RSS is not enabled
3571d10453SEric Joyner *
3671d10453SEric Joyner * This header includes default definitions for RSS functionality if the
3771d10453SEric Joyner * kernel RSS interface is not enabled. This allows main driver code to avoid
3871d10453SEric Joyner * having to check the RSS ifdef throughout, but instead just use the RSS
3971d10453SEric Joyner * definitions, as they will fall back to these defaults when the kernel
4071d10453SEric Joyner * interface is disabled.
4171d10453SEric Joyner */
4271d10453SEric Joyner #ifndef _ICE_RSS_H_
4371d10453SEric Joyner #define _ICE_RSS_H_
4471d10453SEric Joyner
4571d10453SEric Joyner #ifdef RSS
4671d10453SEric Joyner // We have the kernel RSS interface available
4771d10453SEric Joyner #include <net/rss_config.h>
4871d10453SEric Joyner
4971d10453SEric Joyner /* Make sure our key size buffer has enough space to store the kernel RSS key */
5071d10453SEric Joyner CTASSERT(ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE >= RSS_KEYSIZE);
5171d10453SEric Joyner #else
5271d10453SEric Joyner /* The kernel RSS interface is not enabled. Use suitable defaults for the RSS
5371d10453SEric Joyner * configuration functions.
5471d10453SEric Joyner *
5571d10453SEric Joyner * The RSS hash key will be a pre-generated random key.
5671d10453SEric Joyner * The number of buckets will just match the number of CPUs.
5771d10453SEric Joyner * The lookup table will be assigned using round-robin with no indirection.
5871d10453SEric Joyner * The RSS hash configuration will be set to suitable defaults.
5971d10453SEric Joyner */
6071d10453SEric Joyner
6171d10453SEric Joyner #define RSS_HASHTYPE_RSS_IPV4 (1 << 1) /* IPv4 2-tuple */
6271d10453SEric Joyner #define RSS_HASHTYPE_RSS_TCP_IPV4 (1 << 2) /* TCPv4 4-tuple */
6371d10453SEric Joyner #define RSS_HASHTYPE_RSS_IPV6 (1 << 3) /* IPv6 2-tuple */
6471d10453SEric Joyner #define RSS_HASHTYPE_RSS_TCP_IPV6 (1 << 4) /* TCPv6 4-tuple */
6571d10453SEric Joyner #define RSS_HASHTYPE_RSS_IPV6_EX (1 << 5) /* IPv6 2-tuple + ext hdrs */
6671d10453SEric Joyner #define RSS_HASHTYPE_RSS_TCP_IPV6_EX (1 << 6) /* TCPv6 4-tiple + ext hdrs */
6771d10453SEric Joyner #define RSS_HASHTYPE_RSS_UDP_IPV4 (1 << 7) /* IPv4 UDP 4-tuple */
6871d10453SEric Joyner #define RSS_HASHTYPE_RSS_UDP_IPV6 (1 << 9) /* IPv6 UDP 4-tuple */
6971d10453SEric Joyner #define RSS_HASHTYPE_RSS_UDP_IPV6_EX (1 << 10) /* IPv6 UDP 4-tuple + ext hdrs */
7071d10453SEric Joyner
7171d10453SEric Joyner #define rss_getkey(key) ice_get_default_rss_key(key)
7271d10453SEric Joyner #define rss_getnumbuckets() (mp_ncpus)
7371d10453SEric Joyner #define rss_get_indirection_to_bucket(index) (index)
7471d10453SEric Joyner #define rss_gethashconfig() (ICE_DEFAULT_RSS_HASH_CONFIG)
7571d10453SEric Joyner
7671d10453SEric Joyner /**
7771d10453SEric Joyner * rss_hash2bucket - Determine the bucket for a given hash value
7871d10453SEric Joyner * @hash_val: the hash value to use
7971d10453SEric Joyner * @hash_type: the type of the hash
8071d10453SEric Joyner * @bucket_id: on success, updated with the bucket
8171d10453SEric Joyner *
8271d10453SEric Joyner * This function simply verifies that the hash type is known. If it is, then
8371d10453SEric Joyner * we forward the hash value directly as the bucket id. If the hash type is
8471d10453SEric Joyner * unknown, we return -1.
8571d10453SEric Joyner *
8671d10453SEric Joyner * This is the simplest mechanism for converting a hash value into a bucket,
8771d10453SEric Joyner * and does not support any form of indirection table.
8871d10453SEric Joyner */
8971d10453SEric Joyner static inline int
rss_hash2bucket(uint32_t hash_val,uint32_t hash_type,uint32_t * bucket_id)9071d10453SEric Joyner rss_hash2bucket(uint32_t hash_val, uint32_t hash_type, uint32_t *bucket_id)
9171d10453SEric Joyner {
9271d10453SEric Joyner switch (hash_type) {
9371d10453SEric Joyner case M_HASHTYPE_RSS_IPV4:
9471d10453SEric Joyner case M_HASHTYPE_RSS_TCP_IPV4:
9571d10453SEric Joyner case M_HASHTYPE_RSS_UDP_IPV4:
9671d10453SEric Joyner case M_HASHTYPE_RSS_IPV6:
9771d10453SEric Joyner case M_HASHTYPE_RSS_TCP_IPV6:
9871d10453SEric Joyner case M_HASHTYPE_RSS_UDP_IPV6:
9971d10453SEric Joyner *bucket_id = hash_val;
10071d10453SEric Joyner return (0);
10171d10453SEric Joyner default:
10271d10453SEric Joyner return (-1);
10371d10453SEric Joyner }
10471d10453SEric Joyner }
10571d10453SEric Joyner
10671d10453SEric Joyner #endif /* !RSS */
10771d10453SEric Joyner
108*6e565089SBrian Poole #define ICE_DEFAULT_RSS_HASH_CONFIG \
109*6e565089SBrian Poole ((u_int)(RSS_HASHTYPE_RSS_IPV4 | \
110*6e565089SBrian Poole RSS_HASHTYPE_RSS_TCP_IPV4 | \
111*6e565089SBrian Poole RSS_HASHTYPE_RSS_UDP_IPV4 | \
112*6e565089SBrian Poole RSS_HASHTYPE_RSS_IPV6 | \
113*6e565089SBrian Poole RSS_HASHTYPE_RSS_TCP_IPV6 | \
114*6e565089SBrian Poole RSS_HASHTYPE_RSS_UDP_IPV6))
115*6e565089SBrian Poole
11671d10453SEric Joyner #endif /* _ICE_COMMON_COMPAT_H_ */
117