xref: /freebsd/sys/dev/iavf/iavf_txrx_common.h (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
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 
32 /**
33  * @file iavf_txrx_common.h
34  * @brief Tx/Rx hotpath functions common to legacy and iflib
35  *
36  * Contains implementations for functions used in the hotpath for both the
37  * legacy and iflib driver implementations.
38  */
39 #ifndef _IAVF_TXRX_COMMON_H_
40 #define _IAVF_TXRX_COMMON_H_
41 
42 #include "iavf_iflib.h"
43 
44 static inline int iavf_ptype_to_hash(u8 ptype);
45 
46 /**
47  * iavf_ptype_to_hash - parse the packet type
48  * @ptype: packet type
49  *
50  * Determine the appropriate hash for a given packet type
51  *
52  * @returns the M_HASHTYPE_* value for the given packet type.
53  */
54 static inline int
55 iavf_ptype_to_hash(u8 ptype)
56 {
57         struct iavf_rx_ptype_decoded decoded;
58 
59 	decoded = decode_rx_desc_ptype(ptype);
60 
61 	if (!decoded.known)
62 		return M_HASHTYPE_OPAQUE;
63 
64 	if (decoded.outer_ip == IAVF_RX_PTYPE_OUTER_L2)
65 		return M_HASHTYPE_OPAQUE;
66 
67 	/* Note: anything that gets to this point is IP */
68         if (decoded.outer_ip_ver == IAVF_RX_PTYPE_OUTER_IPV6) {
69 		switch (decoded.inner_prot) {
70 		case IAVF_RX_PTYPE_INNER_PROT_TCP:
71 			return M_HASHTYPE_RSS_TCP_IPV6;
72 		case IAVF_RX_PTYPE_INNER_PROT_UDP:
73 			return M_HASHTYPE_RSS_UDP_IPV6;
74 		default:
75 			return M_HASHTYPE_RSS_IPV6;
76 		}
77 	}
78         if (decoded.outer_ip_ver == IAVF_RX_PTYPE_OUTER_IPV4) {
79 		switch (decoded.inner_prot) {
80 		case IAVF_RX_PTYPE_INNER_PROT_TCP:
81 			return M_HASHTYPE_RSS_TCP_IPV4;
82 		case IAVF_RX_PTYPE_INNER_PROT_UDP:
83 			return M_HASHTYPE_RSS_UDP_IPV4;
84 		default:
85 			return M_HASHTYPE_RSS_IPV4;
86 		}
87 	}
88 	/* We should never get here! */
89 	return M_HASHTYPE_OPAQUE;
90 }
91 
92 #endif /* _IAVF_TXRX_COMMON_H_ */
93