net/mlx5: use vector types to speed up processing
[dpdk.git] / drivers / net / mlx5 / mlx5_prm.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2016 6WIND S.A.
5  *   Copyright 2016 Mellanox.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of 6WIND S.A. nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef RTE_PMD_MLX5_PRM_H_
35 #define RTE_PMD_MLX5_PRM_H_
36
37 #include <assert.h>
38
39 /* Verbs header. */
40 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
41 #ifdef PEDANTIC
42 #pragma GCC diagnostic ignored "-Wpedantic"
43 #endif
44 #include <infiniband/mlx5_hw.h>
45 #ifdef PEDANTIC
46 #pragma GCC diagnostic error "-Wpedantic"
47 #endif
48
49 #include <rte_vect.h>
50 #include "mlx5_autoconf.h"
51
52 /* Get CQE owner bit. */
53 #define MLX5_CQE_OWNER(op_own) ((op_own) & MLX5_CQE_OWNER_MASK)
54
55 /* Get CQE format. */
56 #define MLX5_CQE_FORMAT(op_own) (((op_own) & MLX5E_CQE_FORMAT_MASK) >> 2)
57
58 /* Get CQE opcode. */
59 #define MLX5_CQE_OPCODE(op_own) (((op_own) & 0xf0) >> 4)
60
61 /* Get CQE solicited event. */
62 #define MLX5_CQE_SE(op_own) (((op_own) >> 1) & 1)
63
64 /* Invalidate a CQE. */
65 #define MLX5_CQE_INVALIDATE (MLX5_CQE_INVALID << 4)
66
67 /* CQE value to inform that VLAN is stripped. */
68 #define MLX5_CQE_VLAN_STRIPPED 0x1
69
70 /* Maximum number of packets a multi-packet WQE can handle. */
71 #define MLX5_MPW_DSEG_MAX 5
72
73 /* WQE DWORD size */
74 #define MLX5_WQE_DWORD_SIZE 16
75
76 /* WQE size */
77 #define MLX5_WQE_SIZE (4 * MLX5_WQE_DWORD_SIZE)
78
79 /* Compute the number of DS. */
80 #define MLX5_WQE_DS(n) \
81         (((n) + MLX5_WQE_DWORD_SIZE - 1) / MLX5_WQE_DWORD_SIZE)
82
83 /* Room for inline data in multi-packet WQE. */
84 #define MLX5_MWQE64_INL_DATA 28
85
86 #ifndef HAVE_VERBS_MLX5_OPCODE_TSO
87 #define MLX5_OPCODE_TSO MLX5_OPCODE_LSO_MPW /* Compat with OFED 3.3. */
88 #endif
89
90 /* IPv4 packet. */
91 #define MLX5_CQE_RX_IPV4_PACKET (1u << 2)
92
93 /* IPv6 packet. */
94 #define MLX5_CQE_RX_IPV6_PACKET (1u << 3)
95
96 /* Outer IPv4 packet. */
97 #define MLX5_CQE_RX_OUTER_IPV4_PACKET (1u << 7)
98
99 /* Outer IPv6 packet. */
100 #define MLX5_CQE_RX_OUTER_IPV6_PACKET (1u << 8)
101
102 /* Tunnel packet bit in the CQE. */
103 #define MLX5_CQE_RX_TUNNEL_PACKET (1u << 4)
104
105 /* Outer IP checksum OK. */
106 #define MLX5_CQE_RX_OUTER_IP_CSUM_OK (1u << 5)
107
108 /* Outer UDP header and checksum OK. */
109 #define MLX5_CQE_RX_OUTER_TCP_UDP_CSUM_OK (1u << 6)
110
111 /* INVALID is used by packets matching no flow rules. */
112 #define MLX5_FLOW_MARK_INVALID 0
113
114 /* Maximum allowed value to mark a packet. */
115 #define MLX5_FLOW_MARK_MAX 0xfffff0
116
117 /* Default mark value used when none is provided. */
118 #define MLX5_FLOW_MARK_DEFAULT 0xffffff
119
120 /* Subset of struct mlx5_wqe_eth_seg. */
121 struct mlx5_wqe_eth_seg_small {
122         uint32_t rsvd0;
123         uint8_t cs_flags;
124         uint8_t rsvd1;
125         uint16_t mss;
126         uint32_t rsvd2;
127         uint16_t inline_hdr_sz;
128         uint8_t inline_hdr[2];
129 } __rte_aligned(MLX5_WQE_DWORD_SIZE);
130
131 struct mlx5_wqe_inl_small {
132         uint32_t byte_cnt;
133         uint8_t raw;
134 } __rte_aligned(MLX5_WQE_DWORD_SIZE);
135
136 struct mlx5_wqe_ctrl {
137         uint32_t ctrl0;
138         uint32_t ctrl1;
139         uint32_t ctrl2;
140         uint32_t ctrl3;
141 } __rte_aligned(MLX5_WQE_DWORD_SIZE);
142
143 /* Small common part of the WQE. */
144 struct mlx5_wqe {
145         uint32_t ctrl[4];
146         struct mlx5_wqe_eth_seg_small eseg;
147 };
148
149 /* Vectorize WQE header. */
150 struct mlx5_wqe_v {
151         rte_v128u32_t ctrl;
152         rte_v128u32_t eseg;
153 };
154
155 /* WQE. */
156 struct mlx5_wqe64 {
157         struct mlx5_wqe hdr;
158         uint8_t raw[32];
159 } __rte_aligned(MLX5_WQE_SIZE);
160
161 /* MPW session status. */
162 enum mlx5_mpw_state {
163         MLX5_MPW_STATE_OPENED,
164         MLX5_MPW_INL_STATE_OPENED,
165         MLX5_MPW_STATE_CLOSED,
166 };
167
168 /* MPW session descriptor. */
169 struct mlx5_mpw {
170         enum mlx5_mpw_state state;
171         unsigned int pkts_n;
172         unsigned int len;
173         unsigned int total_len;
174         volatile struct mlx5_wqe *wqe;
175         union {
176                 volatile struct mlx5_wqe_data_seg *dseg[MLX5_MPW_DSEG_MAX];
177                 volatile uint8_t *raw;
178         } data;
179 };
180
181 /* CQ element structure - should be equal to the cache line size */
182 struct mlx5_cqe {
183 #if (RTE_CACHE_LINE_SIZE == 128)
184         uint8_t padding[64];
185 #endif
186         uint8_t pkt_info;
187         uint8_t rsvd0[11];
188         uint32_t rx_hash_res;
189         uint8_t rx_hash_type;
190         uint8_t rsvd1[11];
191         uint8_t hds_ip_ext;
192         uint8_t l4_hdr_type_etc;
193         uint16_t vlan_info;
194         uint8_t rsvd2[12];
195         uint32_t byte_cnt;
196         uint64_t timestamp;
197         uint32_t sop_drop_qpn;
198         uint16_t wqe_counter;
199         uint8_t rsvd4;
200         uint8_t op_own;
201 };
202
203 /**
204  * Convert a user mark to flow mark.
205  *
206  * @param val
207  *   Mark value to convert.
208  *
209  * @return
210  *   Converted mark value.
211  */
212 static inline uint32_t
213 mlx5_flow_mark_set(uint32_t val)
214 {
215         uint32_t ret;
216
217         /*
218          * Add one to the user value to differentiate un-marked flows from
219          * marked flows.
220          */
221         ++val;
222 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
223         /*
224          * Mark is 24 bits (minus reserved values) but is stored on a 32 bit
225          * word, byte-swapped by the kernel on little-endian systems. In this
226          * case, left-shifting the resulting big-endian value ensures the
227          * least significant 24 bits are retained when converting it back.
228          */
229         ret = rte_cpu_to_be_32(val) >> 8;
230 #else
231         ret = val;
232 #endif
233         assert(ret <= MLX5_FLOW_MARK_MAX);
234         return ret;
235 }
236
237 /**
238  * Convert a mark to user mark.
239  *
240  * @param val
241  *   Mark value to convert.
242  *
243  * @return
244  *   Converted mark value.
245  */
246 static inline uint32_t
247 mlx5_flow_mark_get(uint32_t val)
248 {
249         /*
250          * Subtract one from the retrieved value. It was added by
251          * mlx5_flow_mark_set() to distinguish unmarked flows.
252          */
253 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
254         return (val >> 8) - 1;
255 #else
256         return val - 1;
257 #endif
258 }
259
260 #endif /* RTE_PMD_MLX5_PRM_H_ */