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