2 * Copyright (c) 2013-2017, Mellanox Technologies, Ltd. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
28 #include <dev/mlx5/driver.h>
30 #include "mlx5_core.h"
33 int mlx5_alloc_transport_domain(struct mlx5_core_dev *dev, u32 *tdn)
35 u32 in[MLX5_ST_SZ_DW(alloc_transport_domain_in)] = {0};
36 u32 out[MLX5_ST_SZ_DW(alloc_transport_domain_out)] = {0};
39 MLX5_SET(alloc_transport_domain_in, in, opcode,
40 MLX5_CMD_OP_ALLOC_TRANSPORT_DOMAIN);
42 err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
44 *tdn = MLX5_GET(alloc_transport_domain_out, out,
50 void mlx5_dealloc_transport_domain(struct mlx5_core_dev *dev, u32 tdn)
52 u32 in[MLX5_ST_SZ_DW(dealloc_transport_domain_in)] = {0};
53 u32 out[MLX5_ST_SZ_DW(dealloc_transport_domain_out)] = {0};
55 MLX5_SET(dealloc_transport_domain_in, in, opcode,
56 MLX5_CMD_OP_DEALLOC_TRANSPORT_DOMAIN);
57 MLX5_SET(dealloc_transport_domain_in, in, transport_domain, tdn);
59 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
62 int mlx5_core_create_rq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *rqn)
64 u32 out[MLX5_ST_SZ_DW(create_rq_out)] = {0};
67 MLX5_SET(create_rq_in, in, opcode, MLX5_CMD_OP_CREATE_RQ);
69 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
71 *rqn = MLX5_GET(create_rq_out, out, rqn);
76 int mlx5_core_modify_rq(struct mlx5_core_dev *dev, u32 *in, int inlen)
78 u32 out[MLX5_ST_SZ_DW(modify_rq_out)] = {0};
80 MLX5_SET(modify_rq_in, in, opcode, MLX5_CMD_OP_MODIFY_RQ);
82 return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
85 void mlx5_core_destroy_rq(struct mlx5_core_dev *dev, u32 rqn)
87 u32 in[MLX5_ST_SZ_DW(destroy_rq_in)] = {0};
88 u32 out[MLX5_ST_SZ_DW(destroy_rq_out)] = {0};
90 MLX5_SET(destroy_rq_in, in, opcode, MLX5_CMD_OP_DESTROY_RQ);
91 MLX5_SET(destroy_rq_in, in, rqn, rqn);
93 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
96 int mlx5_core_query_rq(struct mlx5_core_dev *dev, u32 rqn, u32 *out)
98 u32 in[MLX5_ST_SZ_DW(query_rq_in)] = {0};
99 int outlen = MLX5_ST_SZ_BYTES(query_rq_out);
101 MLX5_SET(query_rq_in, in, opcode, MLX5_CMD_OP_QUERY_RQ);
102 MLX5_SET(query_rq_in, in, rqn, rqn);
104 return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
107 int mlx5_core_create_sq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *sqn)
109 u32 out[MLX5_ST_SZ_DW(create_sq_out)] = {0};
112 MLX5_SET(create_sq_in, in, opcode, MLX5_CMD_OP_CREATE_SQ);
114 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
116 *sqn = MLX5_GET(create_sq_out, out, sqn);
121 int mlx5_core_modify_sq(struct mlx5_core_dev *dev, u32 *in, int inlen)
123 u32 out[MLX5_ST_SZ_DW(modify_sq_out)] = {0};
125 MLX5_SET(modify_sq_in, in, opcode, MLX5_CMD_OP_MODIFY_SQ);
127 return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
130 void mlx5_core_destroy_sq(struct mlx5_core_dev *dev, u32 sqn)
132 u32 in[MLX5_ST_SZ_DW(destroy_sq_in)] = {0};
133 u32 out[MLX5_ST_SZ_DW(destroy_sq_out)] = {0};
135 MLX5_SET(destroy_sq_in, in, opcode, MLX5_CMD_OP_DESTROY_SQ);
136 MLX5_SET(destroy_sq_in, in, sqn, sqn);
138 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
141 int mlx5_core_query_sq(struct mlx5_core_dev *dev, u32 sqn, u32 *out)
143 u32 in[MLX5_ST_SZ_DW(query_sq_in)] = {0};
144 int outlen = MLX5_ST_SZ_BYTES(query_sq_out);
146 MLX5_SET(query_sq_in, in, opcode, MLX5_CMD_OP_QUERY_SQ);
147 MLX5_SET(query_sq_in, in, sqn, sqn);
149 return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
152 int mlx5_core_create_tir(struct mlx5_core_dev *dev, u32 *in, int inlen,
155 u32 out[MLX5_ST_SZ_DW(create_tir_out)] = {0};
158 MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR);
160 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
162 *tirn = MLX5_GET(create_tir_out, out, tirn);
167 void mlx5_core_destroy_tir(struct mlx5_core_dev *dev, u32 tirn)
169 u32 in[MLX5_ST_SZ_DW(destroy_tir_in)] = {0};
170 u32 out[MLX5_ST_SZ_DW(destroy_tir_out)] = {0};
172 MLX5_SET(destroy_tir_in, in, opcode, MLX5_CMD_OP_DESTROY_TIR);
173 MLX5_SET(destroy_tir_in, in, tirn, tirn);
175 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
178 int mlx5_core_create_tis(struct mlx5_core_dev *dev, u32 *in, int inlen,
181 u32 out[MLX5_ST_SZ_DW(create_tis_out)] = {0};
184 MLX5_SET(create_tis_in, in, opcode, MLX5_CMD_OP_CREATE_TIS);
186 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
188 *tisn = MLX5_GET(create_tis_out, out, tisn);
193 int mlx5_core_modify_tis(struct mlx5_core_dev *dev, u32 tisn, u32 *in,
196 u32 out[MLX5_ST_SZ_DW(modify_tis_out)] = {0};
198 MLX5_SET(modify_tis_in, in, tisn, tisn);
199 MLX5_SET(modify_tis_in, in, opcode, MLX5_CMD_OP_MODIFY_TIS);
201 return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
204 void mlx5_core_destroy_tis(struct mlx5_core_dev *dev, u32 tisn)
206 u32 in[MLX5_ST_SZ_DW(destroy_tis_in)] = {0};
207 u32 out[MLX5_ST_SZ_DW(destroy_tis_out)] = {0};
209 MLX5_SET(destroy_tis_in, in, opcode, MLX5_CMD_OP_DESTROY_TIS);
210 MLX5_SET(destroy_tis_in, in, tisn, tisn);
212 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
215 int mlx5_core_create_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *rmpn)
217 u32 out[MLX5_ST_SZ_DW(create_rmp_out)] = {0};
220 MLX5_SET(create_rmp_in, in, opcode, MLX5_CMD_OP_CREATE_RMP);
222 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
224 *rmpn = MLX5_GET(create_rmp_out, out, rmpn);
229 int mlx5_core_modify_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen)
231 u32 out[MLX5_ST_SZ_DW(modify_rmp_out)] = {0};
233 MLX5_SET(modify_rmp_in, in, opcode, MLX5_CMD_OP_MODIFY_RMP);
235 return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
238 int mlx5_core_destroy_rmp(struct mlx5_core_dev *dev, u32 rmpn)
240 u32 in[MLX5_ST_SZ_DW(destroy_rmp_in)] = {0};
241 u32 out[MLX5_ST_SZ_DW(destroy_rmp_out)] = {0};
243 MLX5_SET(destroy_rmp_in, in, opcode, MLX5_CMD_OP_DESTROY_RMP);
244 MLX5_SET(destroy_rmp_in, in, rmpn, rmpn);
246 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
249 int mlx5_core_query_rmp(struct mlx5_core_dev *dev, u32 rmpn, u32 *out)
251 u32 in[MLX5_ST_SZ_DW(query_rmp_in)] = {0};
252 int outlen = MLX5_ST_SZ_BYTES(query_rmp_out);
254 MLX5_SET(query_rmp_in, in, opcode, MLX5_CMD_OP_QUERY_RMP);
255 MLX5_SET(query_rmp_in, in, rmpn, rmpn);
257 return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
260 int mlx5_core_arm_rmp(struct mlx5_core_dev *dev, u32 rmpn, u16 lwm)
268 in = mlx5_vzalloc(MLX5_ST_SZ_BYTES(modify_rmp_in));
272 rmpc = MLX5_ADDR_OF(modify_rmp_in, in, ctx);
273 bitmask = MLX5_ADDR_OF(modify_rmp_in, in, bitmask);
274 wq = MLX5_ADDR_OF(rmpc, rmpc, wq);
276 MLX5_SET(modify_rmp_in, in, rmp_state, MLX5_RMPC_STATE_RDY);
277 MLX5_SET(modify_rmp_in, in, rmpn, rmpn);
278 MLX5_SET(wq, wq, lwm, lwm);
279 MLX5_SET(rmp_bitmask, bitmask, lwm, 1);
280 MLX5_SET(rmpc, rmpc, state, MLX5_RMPC_STATE_RDY);
282 err = mlx5_core_modify_rmp(dev, in, MLX5_ST_SZ_BYTES(modify_rmp_in));
289 int mlx5_core_create_xsrq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *xsrqn)
291 u32 out[MLX5_ST_SZ_DW(create_xrc_srq_out)] = {0};
294 MLX5_SET(create_xrc_srq_in, in, opcode, MLX5_CMD_OP_CREATE_XRC_SRQ);
296 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
298 *xsrqn = MLX5_GET(create_xrc_srq_out, out, xrc_srqn);
303 int mlx5_core_destroy_xsrq(struct mlx5_core_dev *dev, u32 xsrqn)
305 u32 in[MLX5_ST_SZ_DW(destroy_xrc_srq_in)] = {0};
306 u32 out[MLX5_ST_SZ_DW(destroy_xrc_srq_out)] = {0};
308 MLX5_SET(destroy_xrc_srq_in, in, opcode, MLX5_CMD_OP_DESTROY_XRC_SRQ);
309 MLX5_SET(destroy_xrc_srq_in, in, xrc_srqn, xsrqn);
311 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
314 int mlx5_core_query_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u32 *out)
316 int outlen = MLX5_ST_SZ_BYTES(query_xrc_srq_out);
317 u32 in[MLX5_ST_SZ_DW(query_xrc_srq_in)] = {0};
322 MLX5_SET(query_xrc_srq_in, in, opcode, MLX5_CMD_OP_QUERY_XRC_SRQ);
323 MLX5_SET(query_xrc_srq_in, in, xrc_srqn, xsrqn);
325 err = mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
327 xrc_srqc = MLX5_ADDR_OF(query_xrc_srq_out, out,
328 xrc_srq_context_entry);
329 srqc = MLX5_ADDR_OF(query_srq_out, out, srq_context_entry);
330 memcpy(srqc, xrc_srqc, MLX5_ST_SZ_BYTES(srqc));
336 int mlx5_core_arm_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u16 lwm)
338 u32 in[MLX5_ST_SZ_DW(arm_xrc_srq_in)] = {0};
339 u32 out[MLX5_ST_SZ_DW(arm_xrc_srq_out)] = {0};
341 MLX5_SET(arm_xrc_srq_in, in, opcode, MLX5_CMD_OP_ARM_XRC_SRQ);
342 MLX5_SET(arm_xrc_srq_in, in, xrc_srqn, xsrqn);
343 MLX5_SET(arm_xrc_srq_in, in, lwm, lwm);
344 MLX5_SET(arm_xrc_srq_in, in, op_mod,
345 MLX5_ARM_XRC_SRQ_IN_OP_MOD_XRC_SRQ);
347 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
351 int mlx5_core_create_rqt(struct mlx5_core_dev *dev, u32 *in, int inlen,
354 u32 out[MLX5_ST_SZ_DW(create_rqt_out)] = {0};
357 MLX5_SET(create_rqt_in, in, opcode, MLX5_CMD_OP_CREATE_RQT);
359 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
361 *rqtn = MLX5_GET(create_rqt_out, out, rqtn);
366 int mlx5_core_modify_rqt(struct mlx5_core_dev *dev, u32 rqtn, u32 *in,
369 u32 out[MLX5_ST_SZ_DW(modify_rqt_out)] = {0};
371 MLX5_SET(modify_rqt_in, in, rqtn, rqtn);
372 MLX5_SET(modify_rqt_in, in, opcode, MLX5_CMD_OP_MODIFY_RQT);
374 return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
377 void mlx5_core_destroy_rqt(struct mlx5_core_dev *dev, u32 rqtn)
379 u32 in[MLX5_ST_SZ_DW(destroy_rqt_in)] = {0};
380 u32 out[MLX5_ST_SZ_DW(destroy_rqt_out)] = {0};
382 MLX5_SET(destroy_rqt_in, in, opcode, MLX5_CMD_OP_DESTROY_RQT);
383 MLX5_SET(destroy_rqt_in, in, rqtn, rqtn);
385 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));