Imported Upstream version 16.07.2
[deb_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 /* Verbs header. */
38 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
39 #ifdef PEDANTIC
40 #pragma GCC diagnostic ignored "-Wpedantic"
41 #endif
42 #include <infiniband/mlx5_hw.h>
43 #ifdef PEDANTIC
44 #pragma GCC diagnostic error "-Wpedantic"
45 #endif
46
47 #include "mlx5_autoconf.h"
48
49 /* Get CQE owner bit. */
50 #define MLX5_CQE_OWNER(op_own) ((op_own) & MLX5_CQE_OWNER_MASK)
51
52 /* Get CQE format. */
53 #define MLX5_CQE_FORMAT(op_own) (((op_own) & MLX5E_CQE_FORMAT_MASK) >> 2)
54
55 /* Get CQE opcode. */
56 #define MLX5_CQE_OPCODE(op_own) (((op_own) & 0xf0) >> 4)
57
58 /* Get CQE solicited event. */
59 #define MLX5_CQE_SE(op_own) (((op_own) >> 1) & 1)
60
61 /* Invalidate a CQE. */
62 #define MLX5_CQE_INVALIDATE (MLX5_CQE_INVALID << 4)
63
64 /* CQE value to inform that VLAN is stripped. */
65 #define MLX5_CQE_VLAN_STRIPPED 0x1
66
67 /* Maximum number of packets a multi-packet WQE can handle. */
68 #define MLX5_MPW_DSEG_MAX 5
69
70 /* Room for inline data in regular work queue element. */
71 #define MLX5_WQE64_INL_DATA 12
72
73 /* Room for inline data in multi-packet WQE. */
74 #define MLX5_MWQE64_INL_DATA 28
75
76 #ifndef HAVE_VERBS_MLX5_OPCODE_TSO
77 #define MLX5_OPCODE_TSO MLX5_OPCODE_LSO_MPW /* Compat with OFED 3.3. */
78 #endif
79
80 /* IPv4 packet. */
81 #define MLX5_CQE_RX_IPV4_PACKET (1u << 2)
82
83 /* IPv6 packet. */
84 #define MLX5_CQE_RX_IPV6_PACKET (1u << 3)
85
86 /* Outer IPv4 packet. */
87 #define MLX5_CQE_RX_OUTER_IPV4_PACKET (1u << 7)
88
89 /* Outer IPv6 packet. */
90 #define MLX5_CQE_RX_OUTER_IPV6_PACKET (1u << 8)
91
92 /* Tunnel packet bit in the CQE. */
93 #define MLX5_CQE_RX_TUNNEL_PACKET (1u << 4)
94
95 /* Outer IP checksum OK. */
96 #define MLX5_CQE_RX_OUTER_IP_CSUM_OK (1u << 5)
97
98 /* Outer UDP header and checksum OK. */
99 #define MLX5_CQE_RX_OUTER_TCP_UDP_CSUM_OK (1u << 6)
100
101 /* Subset of struct mlx5_wqe_eth_seg. */
102 struct mlx5_wqe_eth_seg_small {
103         uint32_t rsvd0;
104         uint8_t cs_flags;
105         uint8_t rsvd1;
106         uint16_t mss;
107         uint32_t rsvd2;
108         uint16_t inline_hdr_sz;
109 };
110
111 /* Regular WQE. */
112 struct mlx5_wqe_regular {
113         union {
114                 struct mlx5_wqe_ctrl_seg ctrl;
115                 uint32_t data[4];
116         } ctrl;
117         struct mlx5_wqe_eth_seg eseg;
118         struct mlx5_wqe_data_seg dseg;
119 } __rte_aligned(64);
120
121 /* Inline WQE. */
122 struct mlx5_wqe_inl {
123         union {
124                 struct mlx5_wqe_ctrl_seg ctrl;
125                 uint32_t data[4];
126         } ctrl;
127         struct mlx5_wqe_eth_seg eseg;
128         uint32_t byte_cnt;
129         uint8_t data[MLX5_WQE64_INL_DATA];
130 } __rte_aligned(64);
131
132 /* Multi-packet WQE. */
133 struct mlx5_wqe_mpw {
134         union {
135                 struct mlx5_wqe_ctrl_seg ctrl;
136                 uint32_t data[4];
137         } ctrl;
138         struct mlx5_wqe_eth_seg_small eseg;
139         struct mlx5_wqe_data_seg dseg[2];
140 } __rte_aligned(64);
141
142 /* Multi-packet WQE with inline. */
143 struct mlx5_wqe_mpw_inl {
144         union {
145                 struct mlx5_wqe_ctrl_seg ctrl;
146                 uint32_t data[4];
147         } ctrl;
148         struct mlx5_wqe_eth_seg_small eseg;
149         uint32_t byte_cnt;
150         uint8_t data[MLX5_MWQE64_INL_DATA];
151 } __rte_aligned(64);
152
153 /* Union of all WQE types. */
154 union mlx5_wqe {
155         struct mlx5_wqe_regular wqe;
156         struct mlx5_wqe_inl inl;
157         struct mlx5_wqe_mpw mpw;
158         struct mlx5_wqe_mpw_inl mpw_inl;
159         uint8_t data[64];
160 };
161
162 /* MPW session status. */
163 enum mlx5_mpw_state {
164         MLX5_MPW_STATE_OPENED,
165         MLX5_MPW_INL_STATE_OPENED,
166         MLX5_MPW_STATE_CLOSED,
167 };
168
169 /* MPW session descriptor. */
170 struct mlx5_mpw {
171         enum mlx5_mpw_state state;
172         unsigned int pkts_n;
173         unsigned int len;
174         unsigned int total_len;
175         volatile union mlx5_wqe *wqe;
176         union {
177                 volatile struct mlx5_wqe_data_seg *dseg[MLX5_MPW_DSEG_MAX];
178                 volatile uint8_t *raw;
179         } data;
180 };
181
182 /* CQ element structure - should be equal to the cache line size */
183 struct mlx5_cqe {
184 #if (RTE_CACHE_LINE_SIZE == 128)
185         uint8_t padding[64];
186 #endif
187         struct mlx5_cqe64 cqe64;
188 };
189
190 #endif /* RTE_PMD_MLX5_PRM_H_ */