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