xref: /freebsd/sys/dev/mlx5/mlx5_core/mlx5_transobj.c (revision 98071573638a1f31e4007894ce20a4fdc8e33a1d)
1 /*-
2  * Copyright (c) 2013-2017, 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 
26 #include "opt_rss.h"
27 #include "opt_ratelimit.h"
28 
29 #include <dev/mlx5/driver.h>
30 #include <dev/mlx5/mlx5_core/mlx5_core.h>
31 #include <dev/mlx5/mlx5_core/transobj.h>
32 
mlx5_alloc_transport_domain(struct mlx5_core_dev * dev,u32 * tdn,u32 uid)33 int mlx5_alloc_transport_domain(struct mlx5_core_dev *dev, u32 *tdn, u32 uid)
34 {
35 	u32 in[MLX5_ST_SZ_DW(alloc_transport_domain_in)] = {0};
36 	u32 out[MLX5_ST_SZ_DW(alloc_transport_domain_out)] = {0};
37 	int err;
38 
39 	MLX5_SET(alloc_transport_domain_in, in, opcode,
40 		 MLX5_CMD_OP_ALLOC_TRANSPORT_DOMAIN);
41 	MLX5_SET(alloc_transport_domain_in, in, uid, uid);
42 
43 	err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
44 	if (!err)
45 		*tdn = MLX5_GET(alloc_transport_domain_out, out,
46 				transport_domain);
47 
48 	return err;
49 }
50 
mlx5_dealloc_transport_domain(struct mlx5_core_dev * dev,u32 tdn,u32 uid)51 void mlx5_dealloc_transport_domain(struct mlx5_core_dev *dev, u32 tdn, u32 uid)
52 {
53 	u32 in[MLX5_ST_SZ_DW(dealloc_transport_domain_in)] = {0};
54 	u32 out[MLX5_ST_SZ_DW(dealloc_transport_domain_out)] = {0};
55 
56 	MLX5_SET(dealloc_transport_domain_in, in, opcode,
57 		 MLX5_CMD_OP_DEALLOC_TRANSPORT_DOMAIN);
58 	MLX5_SET(dealloc_transport_domain_in, in, transport_domain, tdn);
59 	MLX5_SET(dealloc_transport_domain_in, in, uid, uid);
60 
61 	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
62 }
63 
mlx5_core_create_rq(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * rqn)64 int mlx5_core_create_rq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *rqn)
65 {
66 	u32 out[MLX5_ST_SZ_DW(create_rq_out)] = {0};
67 	int err;
68 
69 	MLX5_SET(create_rq_in, in, opcode, MLX5_CMD_OP_CREATE_RQ);
70 
71 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
72 	if (!err)
73 		*rqn = MLX5_GET(create_rq_out, out, rqn);
74 
75 	return err;
76 }
77 
mlx5_core_modify_rq(struct mlx5_core_dev * dev,u32 * in,int inlen)78 int mlx5_core_modify_rq(struct mlx5_core_dev *dev, u32 *in, int inlen)
79 {
80 	u32 out[MLX5_ST_SZ_DW(modify_rq_out)] = {0};
81 
82 	MLX5_SET(modify_rq_in, in, opcode, MLX5_CMD_OP_MODIFY_RQ);
83 
84 	return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
85 }
86 
mlx5_core_destroy_rq(struct mlx5_core_dev * dev,u32 rqn)87 void mlx5_core_destroy_rq(struct mlx5_core_dev *dev, u32 rqn)
88 {
89 	u32 in[MLX5_ST_SZ_DW(destroy_rq_in)] = {0};
90 	u32 out[MLX5_ST_SZ_DW(destroy_rq_out)] = {0};
91 
92 	MLX5_SET(destroy_rq_in, in, opcode, MLX5_CMD_OP_DESTROY_RQ);
93 	MLX5_SET(destroy_rq_in, in, rqn, rqn);
94 
95 	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
96 }
97 
mlx5_core_query_rq(struct mlx5_core_dev * dev,u32 rqn,u32 * out)98 int mlx5_core_query_rq(struct mlx5_core_dev *dev, u32 rqn, u32 *out)
99 {
100 	u32 in[MLX5_ST_SZ_DW(query_rq_in)] = {0};
101 	int outlen = MLX5_ST_SZ_BYTES(query_rq_out);
102 
103 	MLX5_SET(query_rq_in, in, opcode, MLX5_CMD_OP_QUERY_RQ);
104 	MLX5_SET(query_rq_in, in, rqn, rqn);
105 
106 	return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
107 }
108 
mlx5_core_create_sq(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * sqn)109 int mlx5_core_create_sq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *sqn)
110 {
111 	u32 out[MLX5_ST_SZ_DW(create_sq_out)] = {0};
112 	int err;
113 
114 	MLX5_SET(create_sq_in, in, opcode, MLX5_CMD_OP_CREATE_SQ);
115 
116 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
117 	if (!err)
118 		*sqn = MLX5_GET(create_sq_out, out, sqn);
119 
120 	return err;
121 }
122 
mlx5_core_modify_sq(struct mlx5_core_dev * dev,u32 * in,int inlen)123 int mlx5_core_modify_sq(struct mlx5_core_dev *dev, u32 *in, int inlen)
124 {
125 	u32 out[MLX5_ST_SZ_DW(modify_sq_out)] = {0};
126 
127 	MLX5_SET(modify_sq_in, in, opcode, MLX5_CMD_OP_MODIFY_SQ);
128 
129 	return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
130 }
131 
mlx5_core_destroy_sq(struct mlx5_core_dev * dev,u32 sqn)132 void mlx5_core_destroy_sq(struct mlx5_core_dev *dev, u32 sqn)
133 {
134 	u32 in[MLX5_ST_SZ_DW(destroy_sq_in)] = {0};
135 	u32 out[MLX5_ST_SZ_DW(destroy_sq_out)] = {0};
136 
137 	MLX5_SET(destroy_sq_in, in, opcode, MLX5_CMD_OP_DESTROY_SQ);
138 	MLX5_SET(destroy_sq_in, in, sqn, sqn);
139 
140 	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
141 }
142 
mlx5_core_query_sq(struct mlx5_core_dev * dev,u32 sqn,u32 * out)143 int mlx5_core_query_sq(struct mlx5_core_dev *dev, u32 sqn, u32 *out)
144 {
145 	u32 in[MLX5_ST_SZ_DW(query_sq_in)] = {0};
146 	int outlen = MLX5_ST_SZ_BYTES(query_sq_out);
147 
148 	MLX5_SET(query_sq_in, in, opcode, MLX5_CMD_OP_QUERY_SQ);
149 	MLX5_SET(query_sq_in, in, sqn, sqn);
150 
151 	return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
152 }
153 
mlx5_core_create_tir(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * tirn)154 int mlx5_core_create_tir(struct mlx5_core_dev *dev, u32 *in, int inlen,
155 			 u32 *tirn)
156 {
157 	u32 out[MLX5_ST_SZ_DW(create_tir_out)] = {0};
158 	int err;
159 
160 	MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR);
161 
162 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
163 	if (!err)
164 		*tirn = MLX5_GET(create_tir_out, out, tirn);
165 
166 	return err;
167 }
168 
169 
170 int
mlx5_core_modify_tir(struct mlx5_core_dev * dev,u32 * in,int inlen)171 mlx5_core_modify_tir(struct mlx5_core_dev *dev, u32 *in, int inlen)
172 {
173 	u32 out[MLX5_ST_SZ_DW(create_tir_out)] = {0};
174 	int err;
175 
176 	MLX5_SET(modify_tir_in, in, opcode, MLX5_CMD_OP_MODIFY_TIR);
177 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
178 	return (err);
179 }
180 
mlx5_core_destroy_tir(struct mlx5_core_dev * dev,u32 tirn,u32 uid)181 void mlx5_core_destroy_tir(struct mlx5_core_dev *dev, u32 tirn, u32 uid)
182 {
183 	u32 in[MLX5_ST_SZ_DW(destroy_tir_in)] = {0};
184 	u32 out[MLX5_ST_SZ_DW(destroy_tir_out)] = {0};
185 
186 	MLX5_SET(destroy_tir_in, in, opcode, MLX5_CMD_OP_DESTROY_TIR);
187 	MLX5_SET(destroy_tir_in, in, uid, uid);
188 	MLX5_SET(destroy_tir_in, in, tirn, tirn);
189 
190 	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
191 }
192 
mlx5_core_create_tis(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * tisn)193 int mlx5_core_create_tis(struct mlx5_core_dev *dev, u32 *in, int inlen,
194 			 u32 *tisn)
195 {
196 	u32 out[MLX5_ST_SZ_DW(create_tis_out)] = {0};
197 	int err;
198 
199 	MLX5_SET(create_tis_in, in, opcode, MLX5_CMD_OP_CREATE_TIS);
200 
201 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
202 	if (!err)
203 		*tisn = MLX5_GET(create_tis_out, out, tisn);
204 
205 	return err;
206 }
207 
mlx5_core_modify_tis(struct mlx5_core_dev * dev,u32 tisn,u32 * in,int inlen)208 int mlx5_core_modify_tis(struct mlx5_core_dev *dev, u32 tisn, u32 *in,
209 			 int inlen)
210 {
211 	u32 out[MLX5_ST_SZ_DW(modify_tis_out)] = {0};
212 
213 	MLX5_SET(modify_tis_in, in, tisn, tisn);
214 	MLX5_SET(modify_tis_in, in, opcode, MLX5_CMD_OP_MODIFY_TIS);
215 
216 	return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
217 }
218 
mlx5_core_destroy_tis(struct mlx5_core_dev * dev,u32 tisn,u32 uid)219 void mlx5_core_destroy_tis(struct mlx5_core_dev *dev, u32 tisn, u32 uid)
220 {
221 	u32 in[MLX5_ST_SZ_DW(destroy_tis_in)] = {0};
222 	u32 out[MLX5_ST_SZ_DW(destroy_tis_out)] = {0};
223 
224 	MLX5_SET(destroy_tis_in, in, opcode, MLX5_CMD_OP_DESTROY_TIS);
225 	MLX5_SET(destroy_tis_in, in, uid, uid);
226 	MLX5_SET(destroy_tis_in, in, tisn, tisn);
227 
228 	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
229 }
230 
mlx5_core_create_rmp(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * rmpn)231 int mlx5_core_create_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *rmpn)
232 {
233 	u32 out[MLX5_ST_SZ_DW(create_rmp_out)] = {0};
234 	int err;
235 
236 	MLX5_SET(create_rmp_in, in, opcode, MLX5_CMD_OP_CREATE_RMP);
237 
238 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
239 	if (!err)
240 		*rmpn = MLX5_GET(create_rmp_out, out, rmpn);
241 
242 	return err;
243 }
244 
mlx5_core_modify_rmp(struct mlx5_core_dev * dev,u32 * in,int inlen)245 int mlx5_core_modify_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen)
246 {
247 	u32 out[MLX5_ST_SZ_DW(modify_rmp_out)] = {0};
248 
249 	MLX5_SET(modify_rmp_in, in, opcode, MLX5_CMD_OP_MODIFY_RMP);
250 
251 	return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
252 }
253 
mlx5_core_destroy_rmp(struct mlx5_core_dev * dev,u32 rmpn)254 int mlx5_core_destroy_rmp(struct mlx5_core_dev *dev, u32 rmpn)
255 {
256 	u32 in[MLX5_ST_SZ_DW(destroy_rmp_in)] = {0};
257 	u32 out[MLX5_ST_SZ_DW(destroy_rmp_out)] = {0};
258 
259 	MLX5_SET(destroy_rmp_in, in, opcode, MLX5_CMD_OP_DESTROY_RMP);
260 	MLX5_SET(destroy_rmp_in, in, rmpn, rmpn);
261 
262 	return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
263 }
264 
mlx5_core_query_rmp(struct mlx5_core_dev * dev,u32 rmpn,u32 * out)265 int mlx5_core_query_rmp(struct mlx5_core_dev *dev, u32 rmpn, u32 *out)
266 {
267 	u32 in[MLX5_ST_SZ_DW(query_rmp_in)] = {0};
268 	int outlen = MLX5_ST_SZ_BYTES(query_rmp_out);
269 
270 	MLX5_SET(query_rmp_in, in, opcode, MLX5_CMD_OP_QUERY_RMP);
271 	MLX5_SET(query_rmp_in, in, rmpn,   rmpn);
272 
273 	return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
274 }
275 
mlx5_core_arm_rmp(struct mlx5_core_dev * dev,u32 rmpn,u16 lwm)276 int mlx5_core_arm_rmp(struct mlx5_core_dev *dev, u32 rmpn, u16 lwm)
277 {
278 	void *in;
279 	void *rmpc;
280 	void *wq;
281 	void *bitmask;
282 	int  err;
283 
284 	in = mlx5_vzalloc(MLX5_ST_SZ_BYTES(modify_rmp_in));
285 	if (!in)
286 		return -ENOMEM;
287 
288 	rmpc    = MLX5_ADDR_OF(modify_rmp_in,   in,   ctx);
289 	bitmask = MLX5_ADDR_OF(modify_rmp_in,   in,   bitmask);
290 	wq      = MLX5_ADDR_OF(rmpc,	        rmpc, wq);
291 
292 	MLX5_SET(modify_rmp_in, in,	 rmp_state, MLX5_RMPC_STATE_RDY);
293 	MLX5_SET(modify_rmp_in, in,	 rmpn,      rmpn);
294 	MLX5_SET(wq,		wq,	 lwm,	    lwm);
295 	MLX5_SET(rmp_bitmask,	bitmask, lwm,	    1);
296 	MLX5_SET(rmpc,		rmpc,	 state,	    MLX5_RMPC_STATE_RDY);
297 
298 	err =  mlx5_core_modify_rmp(dev, in, MLX5_ST_SZ_BYTES(modify_rmp_in));
299 
300 	kvfree(in);
301 
302 	return err;
303 }
304 
mlx5_core_create_xsrq(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * xsrqn)305 int mlx5_core_create_xsrq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *xsrqn)
306 {
307 	u32 out[MLX5_ST_SZ_DW(create_xrc_srq_out)] = {0};
308 	int err;
309 
310 	MLX5_SET(create_xrc_srq_in, in, opcode,     MLX5_CMD_OP_CREATE_XRC_SRQ);
311 
312 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
313 	if (!err)
314 		*xsrqn = MLX5_GET(create_xrc_srq_out, out, xrc_srqn);
315 
316 	return err;
317 }
318 
mlx5_core_destroy_xsrq(struct mlx5_core_dev * dev,u32 xsrqn)319 int mlx5_core_destroy_xsrq(struct mlx5_core_dev *dev, u32 xsrqn)
320 {
321 	u32 in[MLX5_ST_SZ_DW(destroy_xrc_srq_in)] = {0};
322 	u32 out[MLX5_ST_SZ_DW(destroy_xrc_srq_out)] = {0};
323 
324 	MLX5_SET(destroy_xrc_srq_in, in, opcode,   MLX5_CMD_OP_DESTROY_XRC_SRQ);
325 	MLX5_SET(destroy_xrc_srq_in, in, xrc_srqn, xsrqn);
326 
327 	return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
328 }
329 
mlx5_core_query_xsrq(struct mlx5_core_dev * dev,u32 xsrqn,u32 * out)330 int mlx5_core_query_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u32 *out)
331 {
332 	int outlen = MLX5_ST_SZ_BYTES(query_xrc_srq_out);
333 	u32 in[MLX5_ST_SZ_DW(query_xrc_srq_in)] = {0};
334 	void *xrc_srqc;
335 	void *srqc;
336 	int err;
337 
338 	MLX5_SET(query_xrc_srq_in, in, opcode,   MLX5_CMD_OP_QUERY_XRC_SRQ);
339 	MLX5_SET(query_xrc_srq_in, in, xrc_srqn, xsrqn);
340 
341 	err =  mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
342 	if (!err) {
343 		xrc_srqc = MLX5_ADDR_OF(query_xrc_srq_out, out,
344 					xrc_srq_context_entry);
345 		srqc = MLX5_ADDR_OF(query_srq_out, out, srq_context_entry);
346 		memcpy(srqc, xrc_srqc, MLX5_ST_SZ_BYTES(srqc));
347 	}
348 
349 	return err;
350 }
351 
mlx5_core_arm_xsrq(struct mlx5_core_dev * dev,u32 xsrqn,u16 lwm)352 int mlx5_core_arm_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u16 lwm)
353 {
354 	u32 in[MLX5_ST_SZ_DW(arm_xrc_srq_in)] = {0};
355 	u32 out[MLX5_ST_SZ_DW(arm_xrc_srq_out)] = {0};
356 
357 	MLX5_SET(arm_xrc_srq_in, in, opcode,   MLX5_CMD_OP_ARM_XRC_SRQ);
358 	MLX5_SET(arm_xrc_srq_in, in, xrc_srqn, xsrqn);
359 	MLX5_SET(arm_xrc_srq_in, in, lwm,      lwm);
360 	MLX5_SET(arm_xrc_srq_in, in, op_mod,
361 		 MLX5_ARM_XRC_SRQ_IN_OP_MOD_XRC_SRQ);
362 
363 	return	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
364 
365 }
366 
mlx5_core_create_rqt(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * rqtn)367 int mlx5_core_create_rqt(struct mlx5_core_dev *dev, u32 *in, int inlen,
368 			 u32 *rqtn)
369 {
370 	u32 out[MLX5_ST_SZ_DW(create_rqt_out)] = {0};
371 	int err;
372 
373 	MLX5_SET(create_rqt_in, in, opcode, MLX5_CMD_OP_CREATE_RQT);
374 
375 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
376 	if (!err)
377 		*rqtn = MLX5_GET(create_rqt_out, out, rqtn);
378 
379 	return err;
380 }
381 
mlx5_core_modify_rqt(struct mlx5_core_dev * dev,u32 rqtn,u32 * in,int inlen)382 int mlx5_core_modify_rqt(struct mlx5_core_dev *dev, u32 rqtn, u32 *in,
383 			 int inlen)
384 {
385 	u32 out[MLX5_ST_SZ_DW(modify_rqt_out)] = {0};
386 
387 	MLX5_SET(modify_rqt_in, in, rqtn, rqtn);
388 	MLX5_SET(modify_rqt_in, in, opcode, MLX5_CMD_OP_MODIFY_RQT);
389 
390 	return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
391 }
392 
mlx5_core_destroy_rqt(struct mlx5_core_dev * dev,u32 rqtn,u32 uid)393 void mlx5_core_destroy_rqt(struct mlx5_core_dev *dev, u32 rqtn, u32 uid)
394 {
395 	u32 in[MLX5_ST_SZ_DW(destroy_rqt_in)] = {0};
396 	u32 out[MLX5_ST_SZ_DW(destroy_rqt_out)] = {0};
397 
398 	MLX5_SET(destroy_rqt_in, in, opcode, MLX5_CMD_OP_DESTROY_RQT);
399 	MLX5_SET(destroy_rqt_in, in, uid, uid);
400 	MLX5_SET(destroy_rqt_in, in, rqtn, rqtn);
401 
402 	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
403 }
404