1*71d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */ 2*71d10453SEric Joyner /* Copyright (c) 2020, Intel Corporation 3*71d10453SEric Joyner * All rights reserved. 4*71d10453SEric Joyner * 5*71d10453SEric Joyner * Redistribution and use in source and binary forms, with or without 6*71d10453SEric Joyner * modification, are permitted provided that the following conditions are met: 7*71d10453SEric Joyner * 8*71d10453SEric Joyner * 1. Redistributions of source code must retain the above copyright notice, 9*71d10453SEric Joyner * this list of conditions and the following disclaimer. 10*71d10453SEric Joyner * 11*71d10453SEric Joyner * 2. Redistributions in binary form must reproduce the above copyright 12*71d10453SEric Joyner * notice, this list of conditions and the following disclaimer in the 13*71d10453SEric Joyner * documentation and/or other materials provided with the distribution. 14*71d10453SEric Joyner * 15*71d10453SEric Joyner * 3. Neither the name of the Intel Corporation nor the names of its 16*71d10453SEric Joyner * contributors may be used to endorse or promote products derived from 17*71d10453SEric Joyner * this software without specific prior written permission. 18*71d10453SEric Joyner * 19*71d10453SEric Joyner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20*71d10453SEric Joyner * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21*71d10453SEric Joyner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22*71d10453SEric Joyner * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23*71d10453SEric Joyner * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24*71d10453SEric Joyner * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25*71d10453SEric Joyner * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26*71d10453SEric Joyner * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27*71d10453SEric Joyner * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28*71d10453SEric Joyner * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29*71d10453SEric Joyner * POSSIBILITY OF SUCH DAMAGE. 30*71d10453SEric Joyner */ 31*71d10453SEric Joyner /*$FreeBSD$*/ 32*71d10453SEric Joyner 33*71d10453SEric Joyner /** 34*71d10453SEric Joyner * @file ice_rss.h 35*71d10453SEric Joyner * @brief default RSS values if kernel RSS is not enabled 36*71d10453SEric Joyner * 37*71d10453SEric Joyner * This header includes default definitions for RSS functionality if the 38*71d10453SEric Joyner * kernel RSS interface is not enabled. This allows main driver code to avoid 39*71d10453SEric Joyner * having to check the RSS ifdef throughout, but instead just use the RSS 40*71d10453SEric Joyner * definitions, as they will fall back to these defaults when the kernel 41*71d10453SEric Joyner * interface is disabled. 42*71d10453SEric Joyner */ 43*71d10453SEric Joyner #ifndef _ICE_RSS_H_ 44*71d10453SEric Joyner #define _ICE_RSS_H_ 45*71d10453SEric Joyner 46*71d10453SEric Joyner #ifdef RSS 47*71d10453SEric Joyner // We have the kernel RSS interface available 48*71d10453SEric Joyner #include <net/rss_config.h> 49*71d10453SEric Joyner 50*71d10453SEric Joyner /* Make sure our key size buffer has enough space to store the kernel RSS key */ 51*71d10453SEric Joyner CTASSERT(ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE >= RSS_KEYSIZE); 52*71d10453SEric Joyner #else 53*71d10453SEric Joyner /* The kernel RSS interface is not enabled. Use suitable defaults for the RSS 54*71d10453SEric Joyner * configuration functions. 55*71d10453SEric Joyner * 56*71d10453SEric Joyner * The RSS hash key will be a pre-generated random key. 57*71d10453SEric Joyner * The number of buckets will just match the number of CPUs. 58*71d10453SEric Joyner * The lookup table will be assigned using round-robin with no indirection. 59*71d10453SEric Joyner * The RSS hash configuration will be set to suitable defaults. 60*71d10453SEric Joyner */ 61*71d10453SEric Joyner 62*71d10453SEric Joyner #define RSS_HASHTYPE_RSS_IPV4 (1 << 1) /* IPv4 2-tuple */ 63*71d10453SEric Joyner #define RSS_HASHTYPE_RSS_TCP_IPV4 (1 << 2) /* TCPv4 4-tuple */ 64*71d10453SEric Joyner #define RSS_HASHTYPE_RSS_IPV6 (1 << 3) /* IPv6 2-tuple */ 65*71d10453SEric Joyner #define RSS_HASHTYPE_RSS_TCP_IPV6 (1 << 4) /* TCPv6 4-tuple */ 66*71d10453SEric Joyner #define RSS_HASHTYPE_RSS_IPV6_EX (1 << 5) /* IPv6 2-tuple + ext hdrs */ 67*71d10453SEric Joyner #define RSS_HASHTYPE_RSS_TCP_IPV6_EX (1 << 6) /* TCPv6 4-tiple + ext hdrs */ 68*71d10453SEric Joyner #define RSS_HASHTYPE_RSS_UDP_IPV4 (1 << 7) /* IPv4 UDP 4-tuple */ 69*71d10453SEric Joyner #define RSS_HASHTYPE_RSS_UDP_IPV6 (1 << 9) /* IPv6 UDP 4-tuple */ 70*71d10453SEric Joyner #define RSS_HASHTYPE_RSS_UDP_IPV6_EX (1 << 10) /* IPv6 UDP 4-tuple + ext hdrs */ 71*71d10453SEric Joyner 72*71d10453SEric Joyner #define ICE_DEFAULT_RSS_HASH_CONFIG \ 73*71d10453SEric Joyner ((u_int)(RSS_HASHTYPE_RSS_IPV4 | \ 74*71d10453SEric Joyner RSS_HASHTYPE_RSS_TCP_IPV4 | \ 75*71d10453SEric Joyner RSS_HASHTYPE_RSS_UDP_IPV4 | \ 76*71d10453SEric Joyner RSS_HASHTYPE_RSS_IPV6 | \ 77*71d10453SEric Joyner RSS_HASHTYPE_RSS_TCP_IPV6 | \ 78*71d10453SEric Joyner RSS_HASHTYPE_RSS_UDP_IPV6)) 79*71d10453SEric Joyner 80*71d10453SEric Joyner #define rss_getkey(key) ice_get_default_rss_key(key) 81*71d10453SEric Joyner #define rss_getnumbuckets() (mp_ncpus) 82*71d10453SEric Joyner #define rss_get_indirection_to_bucket(index) (index) 83*71d10453SEric Joyner #define rss_gethashconfig() (ICE_DEFAULT_RSS_HASH_CONFIG) 84*71d10453SEric Joyner 85*71d10453SEric Joyner /** 86*71d10453SEric Joyner * rss_hash2bucket - Determine the bucket for a given hash value 87*71d10453SEric Joyner * @hash_val: the hash value to use 88*71d10453SEric Joyner * @hash_type: the type of the hash 89*71d10453SEric Joyner * @bucket_id: on success, updated with the bucket 90*71d10453SEric Joyner * 91*71d10453SEric Joyner * This function simply verifies that the hash type is known. If it is, then 92*71d10453SEric Joyner * we forward the hash value directly as the bucket id. If the hash type is 93*71d10453SEric Joyner * unknown, we return -1. 94*71d10453SEric Joyner * 95*71d10453SEric Joyner * This is the simplest mechanism for converting a hash value into a bucket, 96*71d10453SEric Joyner * and does not support any form of indirection table. 97*71d10453SEric Joyner */ 98*71d10453SEric Joyner static inline int 99*71d10453SEric Joyner rss_hash2bucket(uint32_t hash_val, uint32_t hash_type, uint32_t *bucket_id) 100*71d10453SEric Joyner { 101*71d10453SEric Joyner switch (hash_type) { 102*71d10453SEric Joyner case M_HASHTYPE_RSS_IPV4: 103*71d10453SEric Joyner case M_HASHTYPE_RSS_TCP_IPV4: 104*71d10453SEric Joyner case M_HASHTYPE_RSS_UDP_IPV4: 105*71d10453SEric Joyner case M_HASHTYPE_RSS_IPV6: 106*71d10453SEric Joyner case M_HASHTYPE_RSS_TCP_IPV6: 107*71d10453SEric Joyner case M_HASHTYPE_RSS_UDP_IPV6: 108*71d10453SEric Joyner *bucket_id = hash_val; 109*71d10453SEric Joyner return (0); 110*71d10453SEric Joyner default: 111*71d10453SEric Joyner return (-1); 112*71d10453SEric Joyner } 113*71d10453SEric Joyner } 114*71d10453SEric Joyner 115*71d10453SEric Joyner #endif /* !RSS */ 116*71d10453SEric Joyner 117*71d10453SEric Joyner #endif /* _ICE_COMMON_COMPAT_H_ */ 118