xref: /freebsd/sys/dev/ice/ice_rss.h (revision 8c784bb8cf36911b828652f0bf7e88f443abec50)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2021, 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 /*$FreeBSD$*/
32 
33 /**
34  * @file ice_rss.h
35  * @brief default RSS values if kernel RSS is not enabled
36  *
37  * This header includes default definitions for RSS functionality if the
38  * kernel RSS interface is not enabled. This allows main driver code to avoid
39  * having to check the RSS ifdef throughout, but instead just use the RSS
40  * definitions, as they will fall back to these defaults when the kernel
41  * interface is disabled.
42  */
43 #ifndef _ICE_RSS_H_
44 #define _ICE_RSS_H_
45 
46 #ifdef RSS
47 // We have the kernel RSS interface available
48 #include <net/rss_config.h>
49 
50 /* Make sure our key size buffer has enough space to store the kernel RSS key */
51 CTASSERT(ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE >= RSS_KEYSIZE);
52 #else
53 /* The kernel RSS interface is not enabled. Use suitable defaults for the RSS
54  * configuration functions.
55  *
56  * The RSS hash key will be a pre-generated random key.
57  * The number of buckets will just match the number of CPUs.
58  * The lookup table will be assigned using round-robin with no indirection.
59  * The RSS hash configuration will be set to suitable defaults.
60  */
61 
62 #define	RSS_HASHTYPE_RSS_IPV4		(1 << 1)	/* IPv4 2-tuple */
63 #define	RSS_HASHTYPE_RSS_TCP_IPV4	(1 << 2)	/* TCPv4 4-tuple */
64 #define	RSS_HASHTYPE_RSS_IPV6		(1 << 3)	/* IPv6 2-tuple */
65 #define	RSS_HASHTYPE_RSS_TCP_IPV6	(1 << 4)	/* TCPv6 4-tuple */
66 #define	RSS_HASHTYPE_RSS_IPV6_EX	(1 << 5)	/* IPv6 2-tuple + ext hdrs */
67 #define	RSS_HASHTYPE_RSS_TCP_IPV6_EX	(1 << 6)	/* TCPv6 4-tiple + ext hdrs */
68 #define	RSS_HASHTYPE_RSS_UDP_IPV4	(1 << 7)	/* IPv4 UDP 4-tuple */
69 #define	RSS_HASHTYPE_RSS_UDP_IPV6	(1 << 9)	/* IPv6 UDP 4-tuple */
70 #define	RSS_HASHTYPE_RSS_UDP_IPV6_EX	(1 << 10)	/* IPv6 UDP 4-tuple + ext hdrs */
71 
72 #define ICE_DEFAULT_RSS_HASH_CONFIG \
73 	((u_int)(RSS_HASHTYPE_RSS_IPV4 | \
74 		 RSS_HASHTYPE_RSS_TCP_IPV4 | \
75 		 RSS_HASHTYPE_RSS_UDP_IPV4 | \
76 		 RSS_HASHTYPE_RSS_IPV6 | \
77 		 RSS_HASHTYPE_RSS_TCP_IPV6 | \
78 		 RSS_HASHTYPE_RSS_UDP_IPV6))
79 
80 #define rss_getkey(key) ice_get_default_rss_key(key)
81 #define rss_getnumbuckets() (mp_ncpus)
82 #define rss_get_indirection_to_bucket(index) (index)
83 #define rss_gethashconfig() (ICE_DEFAULT_RSS_HASH_CONFIG)
84 
85 /**
86  * rss_hash2bucket - Determine the bucket for a given hash value
87  * @hash_val: the hash value to use
88  * @hash_type: the type of the hash
89  * @bucket_id: on success, updated with the bucket
90  *
91  * This function simply verifies that the hash type is known. If it is, then
92  * we forward the hash value directly as the bucket id. If the hash type is
93  * unknown, we return -1.
94  *
95  * This is the simplest mechanism for converting a hash value into a bucket,
96  * and does not support any form of indirection table.
97  */
98 static inline int
99 rss_hash2bucket(uint32_t hash_val, uint32_t hash_type, uint32_t *bucket_id)
100 {
101 	switch (hash_type) {
102 	case M_HASHTYPE_RSS_IPV4:
103 	case M_HASHTYPE_RSS_TCP_IPV4:
104 	case M_HASHTYPE_RSS_UDP_IPV4:
105 	case M_HASHTYPE_RSS_IPV6:
106 	case M_HASHTYPE_RSS_TCP_IPV6:
107 	case M_HASHTYPE_RSS_UDP_IPV6:
108 		*bucket_id = hash_val;
109 		return (0);
110 	default:
111 		return (-1);
112 	}
113 }
114 
115 #endif /* !RSS */
116 
117 #endif /* _ICE_COMMON_COMPAT_H_ */
118