xref: /freebsd/sys/dev/ice/ice_rss.h (revision 9978553d0199e7ec0bdd1c44fc7f6c7b0c11e43b)
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 #include <net/rss_config.h>
46 
47 /* Make sure our key size buffer has enough space to store the kernel RSS key */
48 CTASSERT(ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE >= RSS_KEYSIZE);
49 
50 #ifdef RSS
51 /* RSS CPU/bucket mapping functions - only available with options RSS */
52 #else
53 /* Stub CPU/bucket functions when RSS not configured */
54 #define rss_getnumbuckets() (mp_ncpus)
55 #define rss_get_indirection_to_bucket(index) (index)
56 
57 /**
58  * rss_hash2bucket - Determine the bucket for a given hash value
59  * @hash_val: the hash value to use
60  * @hash_type: the type of the hash
61  * @bucket_id: on success, updated with the bucket
62  *
63  * This function simply verifies that the hash type is known. If it is, then
64  * we forward the hash value directly as the bucket id. If the hash type is
65  * unknown, we return -1.
66  *
67  * This is the simplest mechanism for converting a hash value into a bucket,
68  * and does not support any form of indirection table.
69  */
70 static inline int
71 rss_hash2bucket(uint32_t hash_val, uint32_t hash_type, uint32_t *bucket_id)
72 {
73 	switch (hash_type) {
74 	case M_HASHTYPE_RSS_IPV4:
75 	case M_HASHTYPE_RSS_TCP_IPV4:
76 	case M_HASHTYPE_RSS_UDP_IPV4:
77 	case M_HASHTYPE_RSS_IPV6:
78 	case M_HASHTYPE_RSS_TCP_IPV6:
79 	case M_HASHTYPE_RSS_UDP_IPV6:
80 		*bucket_id = hash_val;
81 		return (0);
82 	default:
83 		return (-1);
84 	}
85 }
86 #endif /* !RSS */
87 
88 #define ICE_DEFAULT_RSS_HASH_CONFIG \
89 	((u_int)(RSS_HASHTYPE_RSS_IPV4 | \
90 		 RSS_HASHTYPE_RSS_TCP_IPV4 | \
91 		 RSS_HASHTYPE_RSS_UDP_IPV4 | \
92 		 RSS_HASHTYPE_RSS_IPV6 | \
93 		 RSS_HASHTYPE_RSS_TCP_IPV6 | \
94 		 RSS_HASHTYPE_RSS_UDP_IPV6))
95 
96 #endif /* _ICE_COMMON_COMPAT_H_ */
97