1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2024, 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 rss_getkey(key) ice_get_default_rss_key(key)
72 #define rss_getnumbuckets() (mp_ncpus)
73 #define rss_get_indirection_to_bucket(index) (index)
74 #define rss_gethashconfig() (ICE_DEFAULT_RSS_HASH_CONFIG)
75
76 /**
77 * rss_hash2bucket - Determine the bucket for a given hash value
78 * @hash_val: the hash value to use
79 * @hash_type: the type of the hash
80 * @bucket_id: on success, updated with the bucket
81 *
82 * This function simply verifies that the hash type is known. If it is, then
83 * we forward the hash value directly as the bucket id. If the hash type is
84 * unknown, we return -1.
85 *
86 * This is the simplest mechanism for converting a hash value into a bucket,
87 * and does not support any form of indirection table.
88 */
89 static inline int
rss_hash2bucket(uint32_t hash_val,uint32_t hash_type,uint32_t * bucket_id)90 rss_hash2bucket(uint32_t hash_val, uint32_t hash_type, uint32_t *bucket_id)
91 {
92 switch (hash_type) {
93 case M_HASHTYPE_RSS_IPV4:
94 case M_HASHTYPE_RSS_TCP_IPV4:
95 case M_HASHTYPE_RSS_UDP_IPV4:
96 case M_HASHTYPE_RSS_IPV6:
97 case M_HASHTYPE_RSS_TCP_IPV6:
98 case M_HASHTYPE_RSS_UDP_IPV6:
99 *bucket_id = hash_val;
100 return (0);
101 default:
102 return (-1);
103 }
104 }
105
106 #endif /* !RSS */
107
108 #define ICE_DEFAULT_RSS_HASH_CONFIG \
109 ((u_int)(RSS_HASHTYPE_RSS_IPV4 | \
110 RSS_HASHTYPE_RSS_TCP_IPV4 | \
111 RSS_HASHTYPE_RSS_UDP_IPV4 | \
112 RSS_HASHTYPE_RSS_IPV6 | \
113 RSS_HASHTYPE_RSS_TCP_IPV6 | \
114 RSS_HASHTYPE_RSS_UDP_IPV6))
115
116 #endif /* _ICE_COMMON_COMPAT_H_ */
117