net/mlx5: use work queue buffer as a raw buffer
[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 "mlx5_autoconf.h"
50
51 /* Get CQE owner bit. */
52 #define MLX5_CQE_OWNER(op_own) ((op_own) & MLX5_CQE_OWNER_MASK)
53
54 /* Get CQE format. */
55 #define MLX5_CQE_FORMAT(op_own) (((op_own) & MLX5E_CQE_FORMAT_MASK) >> 2)
56
57 /* Get CQE opcode. */
58 #define MLX5_CQE_OPCODE(op_own) (((op_own) & 0xf0) >> 4)
59
60 /* Get CQE solicited event. */
61 #define MLX5_CQE_SE(op_own) (((op_own) >> 1) & 1)
62
63 /* Invalidate a CQE. */
64 #define MLX5_CQE_INVALIDATE (MLX5_CQE_INVALID << 4)
65
66 /* CQE value to inform that VLAN is stripped. */
67 #define MLX5_CQE_VLAN_STRIPPED 0x1
68
69 /* Maximum number of packets a multi-packet WQE can handle. */
70 #define MLX5_MPW_DSEG_MAX 5
71
72 /* WQE DWORD size */
73 #define MLX5_WQE_DWORD_SIZE 16
74
75 /* WQE size */
76 #define MLX5_WQE_SIZE (4 * MLX5_WQE_DWORD_SIZE)
77
78 /* Compute the number of DS. */
79 #define MLX5_WQE_DS(n) \
80         (((n) + MLX5_WQE_DWORD_SIZE - 1) / MLX5_WQE_DWORD_SIZE)
81
82 /* Room for inline data in multi-packet WQE. */
83 #define MLX5_MWQE64_INL_DATA 28
84
85 #ifndef HAVE_VERBS_MLX5_OPCODE_TSO
86 #define MLX5_OPCODE_TSO MLX5_OPCODE_LSO_MPW /* Compat with OFED 3.3. */
87 #endif
88
89 /* IPv4 packet. */
90 #define MLX5_CQE_RX_IPV4_PACKET (1u << 2)
91
92 /* IPv6 packet. */
93 #define MLX5_CQE_RX_IPV6_PACKET (1u << 3)
94
95 /* Outer IPv4 packet. */
96 #define MLX5_CQE_RX_OUTER_IPV4_PACKET (1u << 7)
97
98 /* Outer IPv6 packet. */
99 #define MLX5_CQE_RX_OUTER_IPV6_PACKET (1u << 8)
100
101 /* Tunnel packet bit in the CQE. */
102 #define MLX5_CQE_RX_TUNNEL_PACKET (1u << 4)
103
104 /* Outer IP checksum OK. */
105 #define MLX5_CQE_RX_OUTER_IP_CSUM_OK (1u << 5)
106
107 /* Outer UDP header and checksum OK. */
108 #define MLX5_CQE_RX_OUTER_TCP_UDP_CSUM_OK (1u << 6)
109
110 /* INVALID is used by packets matching no flow rules. */
111 #define MLX5_FLOW_MARK_INVALID 0
112
113 /* Maximum allowed value to mark a packet. */
114 #define MLX5_FLOW_MARK_MAX 0xfffff0
115
116 /* Default mark value used when none is provided. */
117 #define MLX5_FLOW_MARK_DEFAULT 0xffffff
118
119 /* Subset of struct mlx5_wqe_eth_seg. */
120 struct mlx5_wqe_eth_seg_small {
121         uint32_t rsvd0;
122         uint8_t cs_flags;
123         uint8_t rsvd1;
124         uint16_t mss;
125         uint32_t rsvd2;
126         uint16_t inline_hdr_sz;
127         uint8_t inline_hdr[2];
128 } __rte_aligned(MLX5_WQE_DWORD_SIZE);
129
130 struct mlx5_wqe_inl_small {
131         uint32_t byte_cnt;
132         uint8_t raw;
133 } __rte_aligned(MLX5_WQE_DWORD_SIZE);
134
135 struct mlx5_wqe_ctrl {
136         uint32_t ctrl0;
137         uint32_t ctrl1;
138         uint32_t ctrl2;
139         uint32_t ctrl3;
140 } __rte_aligned(MLX5_WQE_DWORD_SIZE);
141
142 /* Small common part of the WQE. */
143 struct mlx5_wqe {
144         uint32_t ctrl[4];
145         struct mlx5_wqe_eth_seg_small eseg;
146 };
147
148 /* WQE. */
149 struct mlx5_wqe64 {
150         struct mlx5_wqe hdr;
151         uint8_t raw[32];
152 } __rte_aligned(MLX5_WQE_SIZE);
153
154 /* MPW session status. */
155 enum mlx5_mpw_state {
156         MLX5_MPW_STATE_OPENED,
157         MLX5_MPW_INL_STATE_OPENED,
158         MLX5_MPW_STATE_CLOSED,
159 };
160
161 /* MPW session descriptor. */
162 struct mlx5_mpw {
163         enum mlx5_mpw_state state;
164         unsigned int pkts_n;
165         unsigned int len;
166         unsigned int total_len;
167         volatile struct mlx5_wqe *wqe;
168         union {
169                 volatile struct mlx5_wqe_data_seg *dseg[MLX5_MPW_DSEG_MAX];
170                 volatile uint8_t *raw;
171         } data;
172 };
173
174 /* CQ element structure - should be equal to the cache line size */
175 struct mlx5_cqe {
176 #if (RTE_CACHE_LINE_SIZE == 128)
177         uint8_t padding[64];
178 #endif
179         uint8_t pkt_info;
180         uint8_t rsvd0[11];
181         uint32_t rx_hash_res;
182         uint8_t rx_hash_type;
183         uint8_t rsvd1[11];
184         uint8_t hds_ip_ext;
185         uint8_t l4_hdr_type_etc;
186         uint16_t vlan_info;
187         uint8_t rsvd2[12];
188         uint32_t byte_cnt;
189         uint64_t timestamp;
190         uint32_t sop_drop_qpn;
191         uint16_t wqe_counter;
192         uint8_t rsvd4;
193         uint8_t op_own;
194 };
195
196 /**
197  * Convert a user mark to flow mark.
198  *
199  * @param val
200  *   Mark value to convert.
201  *
202  * @return
203  *   Converted mark value.
204  */
205 static inline uint32_t
206 mlx5_flow_mark_set(uint32_t val)
207 {
208         uint32_t ret;
209
210         /*
211          * Add one to the user value to differentiate un-marked flows from
212          * marked flows.
213          */
214         ++val;
215 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
216         /*
217          * Mark is 24 bits (minus reserved values) but is stored on a 32 bit
218          * word, byte-swapped by the kernel on little-endian systems. In this
219          * case, left-shifting the resulting big-endian value ensures the
220          * least significant 24 bits are retained when converting it back.
221          */
222         ret = rte_cpu_to_be_32(val) >> 8;
223 #else
224         ret = val;
225 #endif
226         assert(ret <= MLX5_FLOW_MARK_MAX);
227         return ret;
228 }
229
230 /**
231  * Convert a mark to user mark.
232  *
233  * @param val
234  *   Mark value to convert.
235  *
236  * @return
237  *   Converted mark value.
238  */
239 static inline uint32_t
240 mlx5_flow_mark_get(uint32_t val)
241 {
242         /*
243          * Subtract one from the retrieved value. It was added by
244          * mlx5_flow_mark_set() to distinguish unmarked flows.
245          */
246 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
247         return (val >> 8) - 1;
248 #else
249         return val - 1;
250 #endif
251 }
252
253 #endif /* RTE_PMD_MLX5_PRM_H_ */