2 * Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
33 #include <linux/mlx5/driver.h>
34 #include "mlx5_core.h"
35 #include <linux/mlx5/transobj.h>
37 int mlx5_core_alloc_transport_domain(struct mlx5_core_dev *dev, u32 *tdn)
39 u32 in[MLX5_ST_SZ_DW(alloc_transport_domain_in)];
40 u32 out[MLX5_ST_SZ_DW(alloc_transport_domain_out)];
43 memset(in, 0, sizeof(in));
44 memset(out, 0, sizeof(out));
46 MLX5_SET(alloc_transport_domain_in, in, opcode,
47 MLX5_CMD_OP_ALLOC_TRANSPORT_DOMAIN);
49 err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
51 *tdn = MLX5_GET(alloc_transport_domain_out, out,
56 EXPORT_SYMBOL(mlx5_core_alloc_transport_domain);
58 void mlx5_core_dealloc_transport_domain(struct mlx5_core_dev *dev, u32 tdn)
60 u32 in[MLX5_ST_SZ_DW(dealloc_transport_domain_in)];
61 u32 out[MLX5_ST_SZ_DW(dealloc_transport_domain_out)];
63 memset(in, 0, sizeof(in));
64 memset(out, 0, sizeof(out));
66 MLX5_SET(dealloc_transport_domain_in, in, opcode,
67 MLX5_CMD_OP_DEALLOC_TRANSPORT_DOMAIN);
68 MLX5_SET(dealloc_transport_domain_in, in, transport_domain, tdn);
70 mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
72 EXPORT_SYMBOL(mlx5_core_dealloc_transport_domain);
74 int mlx5_core_create_rq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *rqn)
76 u32 out[MLX5_ST_SZ_DW(create_rq_out)];
79 MLX5_SET(create_rq_in, in, opcode, MLX5_CMD_OP_CREATE_RQ);
81 memset(out, 0, sizeof(out));
82 err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
84 *rqn = MLX5_GET(create_rq_out, out, rqn);
89 int mlx5_core_modify_rq(struct mlx5_core_dev *dev, u32 rqn, u32 *in, int inlen)
91 u32 out[MLX5_ST_SZ_DW(modify_rq_out)];
93 MLX5_SET(modify_rq_in, in, rqn, rqn);
94 MLX5_SET(modify_rq_in, in, opcode, MLX5_CMD_OP_MODIFY_RQ);
96 memset(out, 0, sizeof(out));
97 return mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
99 EXPORT_SYMBOL(mlx5_core_modify_rq);
101 void mlx5_core_destroy_rq(struct mlx5_core_dev *dev, u32 rqn)
103 u32 in[MLX5_ST_SZ_DW(destroy_rq_in)];
104 u32 out[MLX5_ST_SZ_DW(destroy_rq_out)];
106 memset(in, 0, sizeof(in));
108 MLX5_SET(destroy_rq_in, in, opcode, MLX5_CMD_OP_DESTROY_RQ);
109 MLX5_SET(destroy_rq_in, in, rqn, rqn);
111 mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
114 int mlx5_core_create_sq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *sqn)
116 u32 out[MLX5_ST_SZ_DW(create_sq_out)];
119 MLX5_SET(create_sq_in, in, opcode, MLX5_CMD_OP_CREATE_SQ);
121 memset(out, 0, sizeof(out));
122 err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
124 *sqn = MLX5_GET(create_sq_out, out, sqn);
129 int mlx5_core_modify_sq(struct mlx5_core_dev *dev, u32 sqn, u32 *in, int inlen)
131 u32 out[MLX5_ST_SZ_DW(modify_sq_out)];
133 MLX5_SET(modify_sq_in, in, sqn, sqn);
134 MLX5_SET(modify_sq_in, in, opcode, MLX5_CMD_OP_MODIFY_SQ);
136 memset(out, 0, sizeof(out));
137 return mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
139 EXPORT_SYMBOL(mlx5_core_modify_sq);
141 void mlx5_core_destroy_sq(struct mlx5_core_dev *dev, u32 sqn)
143 u32 in[MLX5_ST_SZ_DW(destroy_sq_in)];
144 u32 out[MLX5_ST_SZ_DW(destroy_sq_out)];
146 memset(in, 0, sizeof(in));
148 MLX5_SET(destroy_sq_in, in, opcode, MLX5_CMD_OP_DESTROY_SQ);
149 MLX5_SET(destroy_sq_in, in, sqn, sqn);
151 mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
154 int mlx5_core_create_tir(struct mlx5_core_dev *dev, u32 *in, int inlen,
157 u32 out[MLX5_ST_SZ_DW(create_tir_out)];
160 MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR);
162 memset(out, 0, sizeof(out));
163 err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
165 *tirn = MLX5_GET(create_tir_out, out, tirn);
169 EXPORT_SYMBOL(mlx5_core_create_tir);
171 int mlx5_core_modify_tir(struct mlx5_core_dev *dev, u32 tirn, u32 *in,
174 u32 out[MLX5_ST_SZ_DW(modify_tir_out)];
176 MLX5_SET(modify_tir_in, in, tirn, tirn);
177 MLX5_SET(modify_tir_in, in, opcode, MLX5_CMD_OP_MODIFY_TIR);
179 memset(out, 0, sizeof(out));
180 return mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
183 void mlx5_core_destroy_tir(struct mlx5_core_dev *dev, u32 tirn)
185 u32 in[MLX5_ST_SZ_DW(destroy_tir_in)];
186 u32 out[MLX5_ST_SZ_DW(destroy_tir_out)];
188 memset(in, 0, sizeof(in));
190 MLX5_SET(destroy_tir_in, in, opcode, MLX5_CMD_OP_DESTROY_TIR);
191 MLX5_SET(destroy_tir_in, in, tirn, tirn);
193 mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
195 EXPORT_SYMBOL(mlx5_core_destroy_tir);
197 int mlx5_core_create_tis(struct mlx5_core_dev *dev, u32 *in, int inlen,
200 u32 out[MLX5_ST_SZ_DW(create_tis_out)];
203 MLX5_SET(create_tis_in, in, opcode, MLX5_CMD_OP_CREATE_TIS);
205 memset(out, 0, sizeof(out));
206 err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
208 *tisn = MLX5_GET(create_tis_out, out, tisn);
212 EXPORT_SYMBOL(mlx5_core_create_tis);
214 void mlx5_core_destroy_tis(struct mlx5_core_dev *dev, u32 tisn)
216 u32 in[MLX5_ST_SZ_DW(destroy_tis_in)];
217 u32 out[MLX5_ST_SZ_DW(destroy_tis_out)];
219 memset(in, 0, sizeof(in));
221 MLX5_SET(destroy_tis_in, in, opcode, MLX5_CMD_OP_DESTROY_TIS);
222 MLX5_SET(destroy_tis_in, in, tisn, tisn);
224 mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
226 EXPORT_SYMBOL(mlx5_core_destroy_tis);
228 int mlx5_core_create_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen,
231 u32 out[MLX5_ST_SZ_DW(create_rmp_out)];
234 MLX5_SET(create_rmp_in, in, opcode, MLX5_CMD_OP_CREATE_RMP);
236 memset(out, 0, sizeof(out));
237 err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
239 *rmpn = MLX5_GET(create_rmp_out, out, rmpn);
244 int mlx5_core_modify_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen)
246 u32 out[MLX5_ST_SZ_DW(modify_rmp_out)];
248 MLX5_SET(modify_rmp_in, in, opcode, MLX5_CMD_OP_MODIFY_RMP);
250 memset(out, 0, sizeof(out));
251 return mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
254 int mlx5_core_destroy_rmp(struct mlx5_core_dev *dev, u32 rmpn)
256 u32 in[MLX5_ST_SZ_DW(destroy_rmp_in)];
257 u32 out[MLX5_ST_SZ_DW(destroy_rmp_out)];
259 memset(in, 0, sizeof(in));
261 MLX5_SET(destroy_rmp_in, in, opcode, MLX5_CMD_OP_DESTROY_RMP);
262 MLX5_SET(destroy_rmp_in, in, rmpn, rmpn);
264 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
268 int mlx5_core_query_rmp(struct mlx5_core_dev *dev, u32 rmpn, u32 *out)
270 u32 in[MLX5_ST_SZ_DW(query_rmp_in)];
271 int outlen = MLX5_ST_SZ_BYTES(query_rmp_out);
273 memset(in, 0, sizeof(in));
274 MLX5_SET(query_rmp_in, in, opcode, MLX5_CMD_OP_QUERY_RMP);
275 MLX5_SET(query_rmp_in, in, rmpn, rmpn);
277 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, outlen);
280 int mlx5_core_arm_rmp(struct mlx5_core_dev *dev, u32 rmpn, u16 lwm)
288 in = mlx5_vzalloc(MLX5_ST_SZ_BYTES(modify_rmp_in));
292 rmpc = MLX5_ADDR_OF(modify_rmp_in, in, ctx);
293 bitmask = MLX5_ADDR_OF(modify_rmp_in, in, bitmask);
294 wq = MLX5_ADDR_OF(rmpc, rmpc, wq);
296 MLX5_SET(modify_rmp_in, in, rmp_state, MLX5_RMPC_STATE_RDY);
297 MLX5_SET(modify_rmp_in, in, rmpn, rmpn);
298 MLX5_SET(wq, wq, lwm, lwm);
299 MLX5_SET(rmp_bitmask, bitmask, lwm, 1);
300 MLX5_SET(rmpc, rmpc, state, MLX5_RMPC_STATE_RDY);
302 err = mlx5_core_modify_rmp(dev, in, MLX5_ST_SZ_BYTES(modify_rmp_in));
309 int mlx5_core_create_xsrq(struct mlx5_core_dev *dev, u32 *in, int inlen,
312 u32 out[MLX5_ST_SZ_DW(create_xrc_srq_out)];
315 MLX5_SET(create_xrc_srq_in, in, opcode, MLX5_CMD_OP_CREATE_XRC_SRQ);
317 memset(out, 0, sizeof(out));
318 err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
320 *xsrqn = MLX5_GET(create_xrc_srq_out, out, xrc_srqn);
325 int mlx5_core_destroy_xsrq(struct mlx5_core_dev *dev, u32 xsrqn)
327 u32 in[MLX5_ST_SZ_DW(destroy_xrc_srq_in)];
328 u32 out[MLX5_ST_SZ_DW(destroy_xrc_srq_out)];
330 memset(in, 0, sizeof(in));
331 memset(out, 0, sizeof(out));
333 MLX5_SET(destroy_xrc_srq_in, in, opcode, MLX5_CMD_OP_DESTROY_XRC_SRQ);
334 MLX5_SET(destroy_xrc_srq_in, in, xrc_srqn, xsrqn);
336 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
340 int mlx5_core_query_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u32 *out)
342 u32 in[MLX5_ST_SZ_DW(query_xrc_srq_in)];
347 memset(in, 0, sizeof(in));
348 MLX5_SET(query_xrc_srq_in, in, opcode, MLX5_CMD_OP_QUERY_XRC_SRQ);
349 MLX5_SET(query_xrc_srq_in, in, xrc_srqn, xsrqn);
351 err = mlx5_cmd_exec_check_status(dev, in, sizeof(in),
353 MLX5_ST_SZ_BYTES(query_xrc_srq_out));
355 xrc_srqc = MLX5_ADDR_OF(query_xrc_srq_out, out,
356 xrc_srq_context_entry);
357 srqc = MLX5_ADDR_OF(query_srq_out, out, srq_context_entry);
358 memcpy(srqc, xrc_srqc, MLX5_ST_SZ_BYTES(srqc));
364 int mlx5_core_arm_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u16 lwm)
366 u32 in[MLX5_ST_SZ_DW(arm_xrc_srq_in)];
367 u32 out[MLX5_ST_SZ_DW(arm_xrc_srq_out)];
369 memset(in, 0, sizeof(in));
370 memset(out, 0, sizeof(out));
372 MLX5_SET(arm_xrc_srq_in, in, opcode, MLX5_CMD_OP_ARM_XRC_SRQ);
373 MLX5_SET(arm_xrc_srq_in, in, xrc_srqn, xsrqn);
374 MLX5_SET(arm_xrc_srq_in, in, lwm, lwm);
375 MLX5_SET(arm_xrc_srq_in, in, op_mod,
376 MLX5_ARM_XRC_SRQ_IN_OP_MOD_XRC_SRQ);
378 return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
382 int mlx5_core_create_rqt(struct mlx5_core_dev *dev, u32 *in, int inlen,
385 u32 out[MLX5_ST_SZ_DW(create_rqt_out)];
388 MLX5_SET(create_rqt_in, in, opcode, MLX5_CMD_OP_CREATE_RQT);
390 memset(out, 0, sizeof(out));
391 err = mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
393 *rqtn = MLX5_GET(create_rqt_out, out, rqtn);
398 int mlx5_core_modify_rqt(struct mlx5_core_dev *dev, u32 rqtn, u32 *in,
401 u32 out[MLX5_ST_SZ_DW(modify_rqt_out)];
403 MLX5_SET(modify_rqt_in, in, rqtn, rqtn);
404 MLX5_SET(modify_rqt_in, in, opcode, MLX5_CMD_OP_MODIFY_RQT);
406 memset(out, 0, sizeof(out));
407 return mlx5_cmd_exec_check_status(dev, in, inlen, out, sizeof(out));
410 void mlx5_core_destroy_rqt(struct mlx5_core_dev *dev, u32 rqtn)
412 u32 in[MLX5_ST_SZ_DW(destroy_rqt_in)];
413 u32 out[MLX5_ST_SZ_DW(destroy_rqt_out)];
415 memset(in, 0, sizeof(in));
417 MLX5_SET(destroy_rqt_in, in, opcode, MLX5_CMD_OP_DESTROY_RQT);
418 MLX5_SET(destroy_rqt_in, in, rqtn, rqtn);
420 mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));