Merge branches 'cxgb4' and 'mlx5' into k.o/for-4.8
[cascardo/linux.git] / drivers / infiniband / hw / mlx5 / user.h
1 /*
2  * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32
33 #ifndef MLX5_IB_USER_H
34 #define MLX5_IB_USER_H
35
36 #include <linux/types.h>
37
38 #include "mlx5_ib.h"
39
40 enum {
41         MLX5_QP_FLAG_SIGNATURE          = 1 << 0,
42         MLX5_QP_FLAG_SCATTER_CQE        = 1 << 1,
43 };
44
45 enum {
46         MLX5_SRQ_FLAG_SIGNATURE         = 1 << 0,
47 };
48
49 enum {
50         MLX5_WQ_FLAG_SIGNATURE          = 1 << 0,
51 };
52
53
54 /* Increment this value if any changes that break userspace ABI
55  * compatibility are made.
56  */
57 #define MLX5_IB_UVERBS_ABI_VERSION      1
58
59 /* Make sure that all structs defined in this file remain laid out so
60  * that they pack the same way on 32-bit and 64-bit architectures (to
61  * avoid incompatibility between 32-bit userspace and 64-bit kernels).
62  * In particular do not use pointer types -- pass pointers in __u64
63  * instead.
64  */
65
66 struct mlx5_ib_alloc_ucontext_req {
67         __u32   total_num_uuars;
68         __u32   num_low_latency_uuars;
69 };
70
71 struct mlx5_ib_alloc_ucontext_req_v2 {
72         __u32   total_num_uuars;
73         __u32   num_low_latency_uuars;
74         __u32   flags;
75         __u32   comp_mask;
76         __u8    max_cqe_version;
77         __u8    reserved0;
78         __u16   reserved1;
79         __u32   reserved2;
80 };
81
82 enum mlx5_ib_alloc_ucontext_resp_mask {
83         MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_CORE_CLOCK_OFFSET = 1UL << 0,
84 };
85
86 enum mlx5_user_cmds_supp_uhw {
87         MLX5_USER_CMDS_SUPP_UHW_QUERY_DEVICE = 1 << 0,
88 };
89
90 struct mlx5_ib_alloc_ucontext_resp {
91         __u32   qp_tab_size;
92         __u32   bf_reg_size;
93         __u32   tot_uuars;
94         __u32   cache_line_size;
95         __u16   max_sq_desc_sz;
96         __u16   max_rq_desc_sz;
97         __u32   max_send_wqebb;
98         __u32   max_recv_wr;
99         __u32   max_srq_recv_wr;
100         __u16   num_ports;
101         __u16   reserved1;
102         __u32   comp_mask;
103         __u32   response_length;
104         __u8    cqe_version;
105         __u8    cmds_supp_uhw;
106         __u16   reserved2;
107         __u64   hca_core_clock_offset;
108 };
109
110 struct mlx5_ib_alloc_pd_resp {
111         __u32   pdn;
112 };
113
114 struct mlx5_ib_tso_caps {
115         __u32 max_tso; /* Maximum tso payload size in bytes */
116
117         /* Corresponding bit will be set if qp type from
118          * 'enum ib_qp_type' is supported, e.g.
119          * supported_qpts |= 1 << IB_QPT_UD
120          */
121         __u32 supported_qpts;
122 };
123
124 struct mlx5_ib_query_device_resp {
125         __u32   comp_mask;
126         __u32   response_length;
127         struct  mlx5_ib_tso_caps tso_caps;
128 };
129
130 struct mlx5_ib_create_cq {
131         __u64   buf_addr;
132         __u64   db_addr;
133         __u32   cqe_size;
134         __u32   reserved; /* explicit padding (optional on i386) */
135 };
136
137 struct mlx5_ib_create_cq_resp {
138         __u32   cqn;
139         __u32   reserved;
140 };
141
142 struct mlx5_ib_resize_cq {
143         __u64   buf_addr;
144         __u16   cqe_size;
145         __u16   reserved0;
146         __u32   reserved1;
147 };
148
149 struct mlx5_ib_create_srq {
150         __u64   buf_addr;
151         __u64   db_addr;
152         __u32   flags;
153         __u32   reserved0; /* explicit padding (optional on i386) */
154         __u32   uidx;
155         __u32   reserved1;
156 };
157
158 struct mlx5_ib_create_srq_resp {
159         __u32   srqn;
160         __u32   reserved;
161 };
162
163 struct mlx5_ib_create_qp {
164         __u64   buf_addr;
165         __u64   db_addr;
166         __u32   sq_wqe_count;
167         __u32   rq_wqe_count;
168         __u32   rq_wqe_shift;
169         __u32   flags;
170         __u32   uidx;
171         __u32   reserved0;
172         __u64   sq_buf_addr;
173 };
174
175 /* RX Hash function flags */
176 enum mlx5_rx_hash_function_flags {
177         MLX5_RX_HASH_FUNC_TOEPLITZ      = 1 << 0,
178 };
179
180 /*
181  * RX Hash flags, these flags allows to set which incoming packet's field should
182  * participates in RX Hash. Each flag represent certain packet's field,
183  * when the flag is set the field that is represented by the flag will
184  * participate in RX Hash calculation.
185  * Note: *IPV4 and *IPV6 flags can't be enabled together on the same QP
186  * and *TCP and *UDP flags can't be enabled together on the same QP.
187 */
188 enum mlx5_rx_hash_fields {
189         MLX5_RX_HASH_SRC_IPV4   = 1 << 0,
190         MLX5_RX_HASH_DST_IPV4   = 1 << 1,
191         MLX5_RX_HASH_SRC_IPV6   = 1 << 2,
192         MLX5_RX_HASH_DST_IPV6   = 1 << 3,
193         MLX5_RX_HASH_SRC_PORT_TCP       = 1 << 4,
194         MLX5_RX_HASH_DST_PORT_TCP       = 1 << 5,
195         MLX5_RX_HASH_SRC_PORT_UDP       = 1 << 6,
196         MLX5_RX_HASH_DST_PORT_UDP       = 1 << 7
197 };
198
199 struct mlx5_ib_create_qp_rss {
200         __u64 rx_hash_fields_mask; /* enum mlx5_rx_hash_fields */
201         __u8 rx_hash_function; /* enum mlx5_rx_hash_function_flags */
202         __u8 rx_key_len; /* valid only for Toeplitz */
203         __u8 reserved[6];
204         __u8 rx_hash_key[128]; /* valid only for Toeplitz */
205         __u32   comp_mask;
206         __u32   reserved1;
207 };
208
209 struct mlx5_ib_create_qp_resp {
210         __u32   uuar_index;
211 };
212
213 struct mlx5_ib_alloc_mw {
214         __u32   comp_mask;
215         __u8    num_klms;
216         __u8    reserved1;
217         __u16   reserved2;
218 };
219
220 struct mlx5_ib_create_wq {
221         __u64   buf_addr;
222         __u64   db_addr;
223         __u32   rq_wqe_count;
224         __u32   rq_wqe_shift;
225         __u32   user_index;
226         __u32   flags;
227         __u32   comp_mask;
228         __u32   reserved;
229 };
230
231 struct mlx5_ib_create_wq_resp {
232         __u32   response_length;
233         __u32   reserved;
234 };
235
236 struct mlx5_ib_create_rwq_ind_tbl_resp {
237         __u32   response_length;
238         __u32   reserved;
239 };
240
241 struct mlx5_ib_modify_wq {
242         __u32   comp_mask;
243         __u32   reserved;
244 };
245
246 static inline int get_qp_user_index(struct mlx5_ib_ucontext *ucontext,
247                                     struct mlx5_ib_create_qp *ucmd,
248                                     int inlen,
249                                     u32 *user_index)
250 {
251         u8 cqe_version = ucontext->cqe_version;
252
253         if (field_avail(struct mlx5_ib_create_qp, uidx, inlen) &&
254             !cqe_version && (ucmd->uidx == MLX5_IB_DEFAULT_UIDX))
255                 return 0;
256
257         if (!!(field_avail(struct mlx5_ib_create_qp, uidx, inlen) !=
258                !!cqe_version))
259                 return -EINVAL;
260
261         return verify_assign_uidx(cqe_version, ucmd->uidx, user_index);
262 }
263
264 static inline int get_srq_user_index(struct mlx5_ib_ucontext *ucontext,
265                                      struct mlx5_ib_create_srq *ucmd,
266                                      int inlen,
267                                      u32 *user_index)
268 {
269         u8 cqe_version = ucontext->cqe_version;
270
271         if (field_avail(struct mlx5_ib_create_srq, uidx, inlen) &&
272             !cqe_version && (ucmd->uidx == MLX5_IB_DEFAULT_UIDX))
273                 return 0;
274
275         if (!!(field_avail(struct mlx5_ib_create_srq, uidx, inlen) !=
276                !!cqe_version))
277                 return -EINVAL;
278
279         return verify_assign_uidx(cqe_version, ucmd->uidx, user_index);
280 }
281 #endif /* MLX5_IB_USER_H */