]> CyberLeo.Net >> Repos - FreeBSD/releng/10.3.git/blob - sys/dev/mlx5/mlx5_core/mlx5_transobj.c
- Copy stable/10@296371 to releng/10.3 in preparation for 10.3-RC1
[FreeBSD/releng/10.3.git] / sys / dev / mlx5 / mlx5_core / mlx5_transobj.c
1 /*-
2  * Copyright (c) 2013-2015, Mellanox Technologies, Ltd.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27
28 #include <dev/mlx5/driver.h>
29
30 #include "mlx5_core.h"
31 #include "transobj.h"
32
33 int mlx5_alloc_transport_domain(struct mlx5_core_dev *dev, u32 *tdn)
34 {
35         u32 in[MLX5_ST_SZ_DW(alloc_transport_domain_in)];
36         u32 out[MLX5_ST_SZ_DW(alloc_transport_domain_out)];
37         int err;
38
39         memset(in, 0, sizeof(in));
40         memset(out, 0, sizeof(out));
41
42         MLX5_SET(alloc_transport_domain_in, in, opcode,
43                  MLX5_CMD_OP_ALLOC_TRANSPORT_DOMAIN);
44
45         err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
46         if (!err)
47                 *tdn = MLX5_GET(alloc_transport_domain_out, out,
48                                 transport_domain);
49
50         return err;
51 }
52
53 void mlx5_dealloc_transport_domain(struct mlx5_core_dev *dev, u32 tdn)
54 {
55         u32 in[MLX5_ST_SZ_DW(dealloc_transport_domain_in)];
56         u32 out[MLX5_ST_SZ_DW(dealloc_transport_domain_out)];
57
58         memset(in, 0, sizeof(in));
59         memset(out, 0, sizeof(out));
60
61         MLX5_SET(dealloc_transport_domain_in, in, opcode,
62                  MLX5_CMD_OP_DEALLOC_TRANSPORT_DOMAIN);
63         MLX5_SET(dealloc_transport_domain_in, in, transport_domain, tdn);
64
65         mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
66 }
67
68 int mlx5_core_create_rq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *rqn)
69 {
70         u32 out[MLX5_ST_SZ_DW(create_rq_out)];
71         int err;
72
73         MLX5_SET(create_rq_in, in, opcode, MLX5_CMD_OP_CREATE_RQ);
74
75         memset(out, 0, sizeof(out));
76         err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
77         if (!err)
78                 *rqn = MLX5_GET(create_rq_out, out, rqn);
79
80         return err;
81 }
82
83 int mlx5_core_modify_rq(struct mlx5_core_dev *dev, u32 *in, int inlen)
84 {
85         u32 out[MLX5_ST_SZ_DW(modify_rq_out)];
86
87         MLX5_SET(modify_rq_in, in, opcode, MLX5_CMD_OP_MODIFY_RQ);
88
89         memset(out, 0, sizeof(out));
90         return mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
91 }
92
93 void mlx5_core_destroy_rq(struct mlx5_core_dev *dev, u32 rqn)
94 {
95         u32 in[MLX5_ST_SZ_DW(destroy_rq_in)];
96         u32 out[MLX5_ST_SZ_DW(destroy_rq_out)];
97
98         memset(in, 0, sizeof(in));
99
100         MLX5_SET(destroy_rq_in, in, opcode, MLX5_CMD_OP_DESTROY_RQ);
101         MLX5_SET(destroy_rq_in, in, rqn, rqn);
102
103         mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
104 }
105
106 int mlx5_core_create_sq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *sqn)
107 {
108         u32 out[MLX5_ST_SZ_DW(create_sq_out)];
109         int err;
110
111         MLX5_SET(create_sq_in, in, opcode, MLX5_CMD_OP_CREATE_SQ);
112
113         memset(out, 0, sizeof(out));
114         err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
115         if (!err)
116                 *sqn = MLX5_GET(create_sq_out, out, sqn);
117
118         return err;
119 }
120
121 int mlx5_core_modify_sq(struct mlx5_core_dev *dev, u32 *in, int inlen)
122 {
123         u32 out[MLX5_ST_SZ_DW(modify_sq_out)];
124
125         MLX5_SET(modify_sq_in, in, opcode, MLX5_CMD_OP_MODIFY_SQ);
126
127         memset(out, 0, sizeof(out));
128         return mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
129 }
130
131 void mlx5_core_destroy_sq(struct mlx5_core_dev *dev, u32 sqn)
132 {
133         u32 in[MLX5_ST_SZ_DW(destroy_sq_in)];
134         u32 out[MLX5_ST_SZ_DW(destroy_sq_out)];
135
136         memset(in, 0, sizeof(in));
137
138         MLX5_SET(destroy_sq_in, in, opcode, MLX5_CMD_OP_DESTROY_SQ);
139         MLX5_SET(destroy_sq_in, in, sqn, sqn);
140
141         mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
142 }
143
144 int mlx5_core_create_tir(struct mlx5_core_dev *dev, u32 *in, int inlen,
145                          u32 *tirn)
146 {
147         u32 out[MLX5_ST_SZ_DW(create_tir_out)];
148         int err;
149
150         MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR);
151
152         memset(out, 0, sizeof(out));
153         err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
154         if (!err)
155                 *tirn = MLX5_GET(create_tir_out, out, tirn);
156
157         return err;
158 }
159
160 void mlx5_core_destroy_tir(struct mlx5_core_dev *dev, u32 tirn)
161 {
162         u32 in[MLX5_ST_SZ_DW(destroy_tir_in)];
163         u32 out[MLX5_ST_SZ_DW(destroy_tir_out)];
164
165         memset(in, 0, sizeof(in));
166
167         MLX5_SET(destroy_tir_in, in, opcode, MLX5_CMD_OP_DESTROY_TIR);
168         MLX5_SET(destroy_tir_in, in, tirn, tirn);
169
170         mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
171 }
172
173 int mlx5_core_create_tis(struct mlx5_core_dev *dev, u32 *in, int inlen,
174                          u32 *tisn)
175 {
176         u32 out[MLX5_ST_SZ_DW(create_tis_out)];
177         int err;
178
179         MLX5_SET(create_tis_in, in, opcode, MLX5_CMD_OP_CREATE_TIS);
180
181         memset(out, 0, sizeof(out));
182         err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
183         if (!err)
184                 *tisn = MLX5_GET(create_tis_out, out, tisn);
185
186         return err;
187 }
188
189 void mlx5_core_destroy_tis(struct mlx5_core_dev *dev, u32 tisn)
190 {
191         u32 in[MLX5_ST_SZ_DW(destroy_tis_in)];
192         u32 out[MLX5_ST_SZ_DW(destroy_tis_out)];
193
194         memset(in, 0, sizeof(in));
195
196         MLX5_SET(destroy_tis_in, in, opcode, MLX5_CMD_OP_DESTROY_TIS);
197         MLX5_SET(destroy_tis_in, in, tisn, tisn);
198
199         mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
200 }
201
202 int mlx5_core_create_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *rmpn)
203 {
204         u32 out[MLX5_ST_SZ_DW(create_rmp_out)];
205         int err;
206
207         MLX5_SET(create_rmp_in, in, opcode, MLX5_CMD_OP_CREATE_RMP);
208
209         memset(out, 0, sizeof(out));
210         err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
211         if (!err)
212                 *rmpn = MLX5_GET(create_rmp_out, out, rmpn);
213
214         return err;
215 }
216
217 int mlx5_core_modify_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen)
218 {
219         u32 out[MLX5_ST_SZ_DW(modify_rmp_out)];
220
221         MLX5_SET(modify_rmp_in, in, opcode, MLX5_CMD_OP_MODIFY_RMP);
222
223         memset(out, 0, sizeof(out));
224         return mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
225 }
226
227 int mlx5_core_destroy_rmp(struct mlx5_core_dev *dev, u32 rmpn)
228 {
229         u32 in[MLX5_ST_SZ_DW(destroy_rmp_in)];
230         u32 out[MLX5_ST_SZ_DW(destroy_rmp_out)];
231
232         memset(in, 0, sizeof(in));
233
234         MLX5_SET(destroy_rmp_in, in, opcode, MLX5_CMD_OP_DESTROY_RMP);
235         MLX5_SET(destroy_rmp_in, in, rmpn, rmpn);
236
237         return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
238 }
239
240 int mlx5_core_query_rmp(struct mlx5_core_dev *dev, u32 rmpn, u32 *out)
241 {
242         u32 in[MLX5_ST_SZ_DW(query_rmp_in)];
243         int outlen = MLX5_ST_SZ_BYTES(query_rmp_out);
244
245         memset(in, 0, sizeof(in));
246         MLX5_SET(query_rmp_in, in, opcode, MLX5_CMD_OP_QUERY_RMP);
247         MLX5_SET(query_rmp_in, in, rmpn,   rmpn);
248
249         return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, outlen);
250 }
251
252 int mlx5_core_arm_rmp(struct mlx5_core_dev *dev, u32 rmpn, u16 lwm)
253 {
254         void *in;
255         void *rmpc;
256         void *wq;
257         void *bitmask;
258         int  err;
259
260         in = mlx5_vzalloc(MLX5_ST_SZ_BYTES(modify_rmp_in));
261         if (!in)
262                 return -ENOMEM;
263
264         rmpc    = MLX5_ADDR_OF(modify_rmp_in,   in,   ctx);
265         bitmask = MLX5_ADDR_OF(modify_rmp_in,   in,   bitmask);
266         wq      = MLX5_ADDR_OF(rmpc,            rmpc, wq);
267
268         MLX5_SET(modify_rmp_in, in,      rmp_state, MLX5_RMPC_STATE_RDY);
269         MLX5_SET(modify_rmp_in, in,      rmpn,      rmpn);
270         MLX5_SET(wq,            wq,      lwm,       lwm);
271         MLX5_SET(rmp_bitmask,   bitmask, lwm,       1);
272         MLX5_SET(rmpc,          rmpc,    state,     MLX5_RMPC_STATE_RDY);
273
274         err =  mlx5_core_modify_rmp(dev, in, MLX5_ST_SZ_BYTES(modify_rmp_in));
275
276         kvfree(in);
277
278         return err;
279 }
280
281 int mlx5_core_create_xsrq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *xsrqn)
282 {
283         u32 out[MLX5_ST_SZ_DW(create_xrc_srq_out)];
284         int err;
285
286         MLX5_SET(create_xrc_srq_in, in, opcode,     MLX5_CMD_OP_CREATE_XRC_SRQ);
287
288         memset(out, 0, sizeof(out));
289         err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
290         if (!err)
291                 *xsrqn = MLX5_GET(create_xrc_srq_out, out, xrc_srqn);
292
293         return err;
294 }
295
296 int mlx5_core_destroy_xsrq(struct mlx5_core_dev *dev, u32 xsrqn)
297 {
298         u32 in[MLX5_ST_SZ_DW(destroy_xrc_srq_in)];
299         u32 out[MLX5_ST_SZ_DW(destroy_xrc_srq_out)];
300
301         memset(in, 0, sizeof(in));
302         memset(out, 0, sizeof(out));
303
304         MLX5_SET(destroy_xrc_srq_in, in, opcode,   MLX5_CMD_OP_DESTROY_XRC_SRQ);
305         MLX5_SET(destroy_xrc_srq_in, in, xrc_srqn, xsrqn);
306
307         return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
308                                           sizeof(out));
309 }
310
311 int mlx5_core_query_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u32 *out)
312 {
313         u32 in[MLX5_ST_SZ_DW(query_xrc_srq_in)];
314         void *srqc;
315         void *xrc_srqc;
316         int err;
317
318         memset(in, 0, sizeof(in));
319         MLX5_SET(query_xrc_srq_in, in, opcode,   MLX5_CMD_OP_QUERY_XRC_SRQ);
320         MLX5_SET(query_xrc_srq_in, in, xrc_srqn, xsrqn);
321
322         err =  mlx5_cmd_exec_check_status(dev, in, sizeof(in),
323                                           out,
324                                           MLX5_ST_SZ_BYTES(query_xrc_srq_out));
325         if (!err) {
326                 xrc_srqc = MLX5_ADDR_OF(query_xrc_srq_out, out,
327                                         xrc_srq_context_entry);
328                 srqc = MLX5_ADDR_OF(query_srq_out, out, srq_context_entry);
329                 memcpy(srqc, xrc_srqc, MLX5_ST_SZ_BYTES(srqc));
330         }
331
332         return err;
333 }
334
335 int mlx5_core_arm_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u16 lwm)
336 {
337         u32 in[MLX5_ST_SZ_DW(arm_xrc_srq_in)];
338         u32 out[MLX5_ST_SZ_DW(arm_xrc_srq_out)];
339
340         memset(in, 0, sizeof(in));
341         memset(out, 0, sizeof(out));
342
343         MLX5_SET(arm_xrc_srq_in, in, opcode,   MLX5_CMD_OP_ARM_XRC_SRQ);
344         MLX5_SET(arm_xrc_srq_in, in, xrc_srqn, xsrqn);
345         MLX5_SET(arm_xrc_srq_in, in, lwm,      lwm);
346         MLX5_SET(arm_xrc_srq_in, in, op_mod,
347                  MLX5_ARM_XRC_SRQ_IN_OP_MOD_XRC_SRQ);
348
349         return  mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
350                                            sizeof(out));
351
352 }
353
354 int mlx5_core_create_rqt(struct mlx5_core_dev *dev, u32 *in, int inlen,
355                          u32 *rqtn)
356 {
357         u32 out[MLX5_ST_SZ_DW(create_rqt_out)];
358         int err;
359
360         MLX5_SET(create_rqt_in, in, opcode, MLX5_CMD_OP_CREATE_RQT);
361
362         memset(out, 0, sizeof(out));
363         err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
364         if (!err)
365                 *rqtn = MLX5_GET(create_rqt_out, out, rqtn);
366
367         return err;
368 }
369
370 int mlx5_core_modify_rqt(struct mlx5_core_dev *dev, u32 rqtn, u32 *in,
371                          int inlen)
372 {
373         u32 out[MLX5_ST_SZ_DW(modify_rqt_out)];
374
375         MLX5_SET(modify_rqt_in, in, rqtn, rqtn);
376         MLX5_SET(modify_rqt_in, in, opcode, MLX5_CMD_OP_MODIFY_RQT);
377
378         memset(out, 0, sizeof(out));
379         return mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
380 }
381
382 void mlx5_core_destroy_rqt(struct mlx5_core_dev *dev, u32 rqtn)
383 {
384         u32 in[MLX5_ST_SZ_DW(destroy_rqt_in)];
385         u32 out[MLX5_ST_SZ_DW(destroy_rqt_out)];
386
387         memset(in, 0, sizeof(in));
388
389         MLX5_SET(destroy_rqt_in, in, opcode, MLX5_CMD_OP_DESTROY_RQT);
390         MLX5_SET(destroy_rqt_in, in, rqtn, rqtn);
391
392         mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
393 }