xref: /freebsd/sys/dev/mlx5/mlx5_core/mlx5_transobj.c (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
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 
mlx5_core_destroy_tir(struct mlx5_core_dev * dev,u32 tirn,u32 uid)169 void mlx5_core_destroy_tir(struct mlx5_core_dev *dev, u32 tirn, u32 uid)
170 {
171 	u32 in[MLX5_ST_SZ_DW(destroy_tir_in)] = {0};
172 	u32 out[MLX5_ST_SZ_DW(destroy_tir_out)] = {0};
173 
174 	MLX5_SET(destroy_tir_in, in, opcode, MLX5_CMD_OP_DESTROY_TIR);
175 	MLX5_SET(destroy_tir_in, in, uid, uid);
176 	MLX5_SET(destroy_tir_in, in, tirn, tirn);
177 
178 	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
179 }
180 
mlx5_core_create_tis(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * tisn)181 int mlx5_core_create_tis(struct mlx5_core_dev *dev, u32 *in, int inlen,
182 			 u32 *tisn)
183 {
184 	u32 out[MLX5_ST_SZ_DW(create_tis_out)] = {0};
185 	int err;
186 
187 	MLX5_SET(create_tis_in, in, opcode, MLX5_CMD_OP_CREATE_TIS);
188 
189 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
190 	if (!err)
191 		*tisn = MLX5_GET(create_tis_out, out, tisn);
192 
193 	return err;
194 }
195 
mlx5_core_modify_tis(struct mlx5_core_dev * dev,u32 tisn,u32 * in,int inlen)196 int mlx5_core_modify_tis(struct mlx5_core_dev *dev, u32 tisn, u32 *in,
197 			 int inlen)
198 {
199 	u32 out[MLX5_ST_SZ_DW(modify_tis_out)] = {0};
200 
201 	MLX5_SET(modify_tis_in, in, tisn, tisn);
202 	MLX5_SET(modify_tis_in, in, opcode, MLX5_CMD_OP_MODIFY_TIS);
203 
204 	return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
205 }
206 
mlx5_core_destroy_tis(struct mlx5_core_dev * dev,u32 tisn,u32 uid)207 void mlx5_core_destroy_tis(struct mlx5_core_dev *dev, u32 tisn, u32 uid)
208 {
209 	u32 in[MLX5_ST_SZ_DW(destroy_tis_in)] = {0};
210 	u32 out[MLX5_ST_SZ_DW(destroy_tis_out)] = {0};
211 
212 	MLX5_SET(destroy_tis_in, in, opcode, MLX5_CMD_OP_DESTROY_TIS);
213 	MLX5_SET(destroy_tis_in, in, uid, uid);
214 	MLX5_SET(destroy_tis_in, in, tisn, tisn);
215 
216 	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
217 }
218 
mlx5_core_create_rmp(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * rmpn)219 int mlx5_core_create_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *rmpn)
220 {
221 	u32 out[MLX5_ST_SZ_DW(create_rmp_out)] = {0};
222 	int err;
223 
224 	MLX5_SET(create_rmp_in, in, opcode, MLX5_CMD_OP_CREATE_RMP);
225 
226 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
227 	if (!err)
228 		*rmpn = MLX5_GET(create_rmp_out, out, rmpn);
229 
230 	return err;
231 }
232 
mlx5_core_modify_rmp(struct mlx5_core_dev * dev,u32 * in,int inlen)233 int mlx5_core_modify_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen)
234 {
235 	u32 out[MLX5_ST_SZ_DW(modify_rmp_out)] = {0};
236 
237 	MLX5_SET(modify_rmp_in, in, opcode, MLX5_CMD_OP_MODIFY_RMP);
238 
239 	return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
240 }
241 
mlx5_core_destroy_rmp(struct mlx5_core_dev * dev,u32 rmpn)242 int mlx5_core_destroy_rmp(struct mlx5_core_dev *dev, u32 rmpn)
243 {
244 	u32 in[MLX5_ST_SZ_DW(destroy_rmp_in)] = {0};
245 	u32 out[MLX5_ST_SZ_DW(destroy_rmp_out)] = {0};
246 
247 	MLX5_SET(destroy_rmp_in, in, opcode, MLX5_CMD_OP_DESTROY_RMP);
248 	MLX5_SET(destroy_rmp_in, in, rmpn, rmpn);
249 
250 	return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
251 }
252 
mlx5_core_query_rmp(struct mlx5_core_dev * dev,u32 rmpn,u32 * out)253 int mlx5_core_query_rmp(struct mlx5_core_dev *dev, u32 rmpn, u32 *out)
254 {
255 	u32 in[MLX5_ST_SZ_DW(query_rmp_in)] = {0};
256 	int outlen = MLX5_ST_SZ_BYTES(query_rmp_out);
257 
258 	MLX5_SET(query_rmp_in, in, opcode, MLX5_CMD_OP_QUERY_RMP);
259 	MLX5_SET(query_rmp_in, in, rmpn,   rmpn);
260 
261 	return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
262 }
263 
mlx5_core_arm_rmp(struct mlx5_core_dev * dev,u32 rmpn,u16 lwm)264 int mlx5_core_arm_rmp(struct mlx5_core_dev *dev, u32 rmpn, u16 lwm)
265 {
266 	void *in;
267 	void *rmpc;
268 	void *wq;
269 	void *bitmask;
270 	int  err;
271 
272 	in = mlx5_vzalloc(MLX5_ST_SZ_BYTES(modify_rmp_in));
273 	if (!in)
274 		return -ENOMEM;
275 
276 	rmpc    = MLX5_ADDR_OF(modify_rmp_in,   in,   ctx);
277 	bitmask = MLX5_ADDR_OF(modify_rmp_in,   in,   bitmask);
278 	wq      = MLX5_ADDR_OF(rmpc,	        rmpc, wq);
279 
280 	MLX5_SET(modify_rmp_in, in,	 rmp_state, MLX5_RMPC_STATE_RDY);
281 	MLX5_SET(modify_rmp_in, in,	 rmpn,      rmpn);
282 	MLX5_SET(wq,		wq,	 lwm,	    lwm);
283 	MLX5_SET(rmp_bitmask,	bitmask, lwm,	    1);
284 	MLX5_SET(rmpc,		rmpc,	 state,	    MLX5_RMPC_STATE_RDY);
285 
286 	err =  mlx5_core_modify_rmp(dev, in, MLX5_ST_SZ_BYTES(modify_rmp_in));
287 
288 	kvfree(in);
289 
290 	return err;
291 }
292 
mlx5_core_create_xsrq(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * xsrqn)293 int mlx5_core_create_xsrq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *xsrqn)
294 {
295 	u32 out[MLX5_ST_SZ_DW(create_xrc_srq_out)] = {0};
296 	int err;
297 
298 	MLX5_SET(create_xrc_srq_in, in, opcode,     MLX5_CMD_OP_CREATE_XRC_SRQ);
299 
300 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
301 	if (!err)
302 		*xsrqn = MLX5_GET(create_xrc_srq_out, out, xrc_srqn);
303 
304 	return err;
305 }
306 
mlx5_core_destroy_xsrq(struct mlx5_core_dev * dev,u32 xsrqn)307 int mlx5_core_destroy_xsrq(struct mlx5_core_dev *dev, u32 xsrqn)
308 {
309 	u32 in[MLX5_ST_SZ_DW(destroy_xrc_srq_in)] = {0};
310 	u32 out[MLX5_ST_SZ_DW(destroy_xrc_srq_out)] = {0};
311 
312 	MLX5_SET(destroy_xrc_srq_in, in, opcode,   MLX5_CMD_OP_DESTROY_XRC_SRQ);
313 	MLX5_SET(destroy_xrc_srq_in, in, xrc_srqn, xsrqn);
314 
315 	return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
316 }
317 
mlx5_core_query_xsrq(struct mlx5_core_dev * dev,u32 xsrqn,u32 * out)318 int mlx5_core_query_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u32 *out)
319 {
320 	int outlen = MLX5_ST_SZ_BYTES(query_xrc_srq_out);
321 	u32 in[MLX5_ST_SZ_DW(query_xrc_srq_in)] = {0};
322 	void *xrc_srqc;
323 	void *srqc;
324 	int err;
325 
326 	MLX5_SET(query_xrc_srq_in, in, opcode,   MLX5_CMD_OP_QUERY_XRC_SRQ);
327 	MLX5_SET(query_xrc_srq_in, in, xrc_srqn, xsrqn);
328 
329 	err =  mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
330 	if (!err) {
331 		xrc_srqc = MLX5_ADDR_OF(query_xrc_srq_out, out,
332 					xrc_srq_context_entry);
333 		srqc = MLX5_ADDR_OF(query_srq_out, out, srq_context_entry);
334 		memcpy(srqc, xrc_srqc, MLX5_ST_SZ_BYTES(srqc));
335 	}
336 
337 	return err;
338 }
339 
mlx5_core_arm_xsrq(struct mlx5_core_dev * dev,u32 xsrqn,u16 lwm)340 int mlx5_core_arm_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u16 lwm)
341 {
342 	u32 in[MLX5_ST_SZ_DW(arm_xrc_srq_in)] = {0};
343 	u32 out[MLX5_ST_SZ_DW(arm_xrc_srq_out)] = {0};
344 
345 	MLX5_SET(arm_xrc_srq_in, in, opcode,   MLX5_CMD_OP_ARM_XRC_SRQ);
346 	MLX5_SET(arm_xrc_srq_in, in, xrc_srqn, xsrqn);
347 	MLX5_SET(arm_xrc_srq_in, in, lwm,      lwm);
348 	MLX5_SET(arm_xrc_srq_in, in, op_mod,
349 		 MLX5_ARM_XRC_SRQ_IN_OP_MOD_XRC_SRQ);
350 
351 	return	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
352 
353 }
354 
mlx5_core_create_rqt(struct mlx5_core_dev * dev,u32 * in,int inlen,u32 * rqtn)355 int mlx5_core_create_rqt(struct mlx5_core_dev *dev, u32 *in, int inlen,
356 			 u32 *rqtn)
357 {
358 	u32 out[MLX5_ST_SZ_DW(create_rqt_out)] = {0};
359 	int err;
360 
361 	MLX5_SET(create_rqt_in, in, opcode, MLX5_CMD_OP_CREATE_RQT);
362 
363 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
364 	if (!err)
365 		*rqtn = MLX5_GET(create_rqt_out, out, rqtn);
366 
367 	return err;
368 }
369 
mlx5_core_modify_rqt(struct mlx5_core_dev * dev,u32 rqtn,u32 * in,int inlen)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)] = {0};
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 	return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
379 }
380 
mlx5_core_destroy_rqt(struct mlx5_core_dev * dev,u32 rqtn,u32 uid)381 void mlx5_core_destroy_rqt(struct mlx5_core_dev *dev, u32 rqtn, u32 uid)
382 {
383 	u32 in[MLX5_ST_SZ_DW(destroy_rqt_in)] = {0};
384 	u32 out[MLX5_ST_SZ_DW(destroy_rqt_out)] = {0};
385 
386 	MLX5_SET(destroy_rqt_in, in, opcode, MLX5_CMD_OP_DESTROY_RQT);
387 	MLX5_SET(destroy_rqt_in, in, uid, uid);
388 	MLX5_SET(destroy_rqt_in, in, rqtn, rqtn);
389 
390 	mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
391 }
392