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