summaryrefslogtreecommitdiff
path: root/sys/dev/ice/ice_rss.h
blob: 4efebb3620257fa1f1816bf142f3c876f672883a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* SPDX-License-Identifier: BSD-3-Clause */
/*  Copyright (c) 2024, Intel Corporation
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 *   3. Neither the name of the Intel Corporation nor the names of its
 *      contributors may be used to endorse or promote products derived from
 *      this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * @file ice_rss.h
 * @brief default RSS values if kernel RSS is not enabled
 *
 * This header includes default definitions for RSS functionality if the
 * kernel RSS interface is not enabled. This allows main driver code to avoid
 * having to check the RSS ifdef throughout, but instead just use the RSS
 * definitions, as they will fall back to these defaults when the kernel
 * interface is disabled.
 */
#ifndef _ICE_RSS_H_
#define _ICE_RSS_H_

#include <net/rss_config.h>

/* Make sure our key size buffer has enough space to store the kernel RSS key */
CTASSERT(ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE >= RSS_KEYSIZE);

#ifdef RSS
/* RSS CPU/bucket mapping functions - only available with options RSS */
#else
/* Stub CPU/bucket functions when RSS not configured */
#define rss_getnumbuckets() (mp_ncpus)
#define rss_get_indirection_to_bucket(index) (index)

/**
 * rss_hash2bucket - Determine the bucket for a given hash value
 * @hash_val: the hash value to use
 * @hash_type: the type of the hash
 * @bucket_id: on success, updated with the bucket
 *
 * This function simply verifies that the hash type is known. If it is, then
 * we forward the hash value directly as the bucket id. If the hash type is
 * unknown, we return -1.
 *
 * This is the simplest mechanism for converting a hash value into a bucket,
 * and does not support any form of indirection table.
 */
static inline int
rss_hash2bucket(uint32_t hash_val, uint32_t hash_type, uint32_t *bucket_id)
{
	switch (hash_type) {
	case M_HASHTYPE_RSS_IPV4:
	case M_HASHTYPE_RSS_TCP_IPV4:
	case M_HASHTYPE_RSS_UDP_IPV4:
	case M_HASHTYPE_RSS_IPV6:
	case M_HASHTYPE_RSS_TCP_IPV6:
	case M_HASHTYPE_RSS_UDP_IPV6:
		*bucket_id = hash_val;
		return (0);
	default:
		return (-1);
	}
}
#endif /* !RSS */

#define ICE_DEFAULT_RSS_HASH_CONFIG \
	((u_int)(RSS_HASHTYPE_RSS_IPV4 | \
		 RSS_HASHTYPE_RSS_TCP_IPV4 | \
		 RSS_HASHTYPE_RSS_UDP_IPV4 | \
		 RSS_HASHTYPE_RSS_IPV6 | \
		 RSS_HASHTYPE_RSS_TCP_IPV6 | \
		 RSS_HASHTYPE_RSS_UDP_IPV6))

#endif /* _ICE_COMMON_COMPAT_H_ */