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 * $FreeBSD$ 26 */ 27 28 #include "opt_rss.h" 29 #include "opt_ratelimit.h" 30 31 #include <dev/mlx5/driver.h> 32 #include <dev/mlx5/mlx5_core/mlx5_core.h> 33 #include <dev/mlx5/mlx5_core/transobj.h> 34 35 int mlx5_alloc_transport_domain(struct mlx5_core_dev *dev, u32 *tdn) 36 { 37 u32 in[MLX5_ST_SZ_DW(alloc_transport_domain_in)] = {0}; 38 u32 out[MLX5_ST_SZ_DW(alloc_transport_domain_out)] = {0}; 39 int err; 40 41 MLX5_SET(alloc_transport_domain_in, in, opcode, 42 MLX5_CMD_OP_ALLOC_TRANSPORT_DOMAIN); 43 44 err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); 45 if (!err) 46 *tdn = MLX5_GET(alloc_transport_domain_out, out, 47 transport_domain); 48 49 return err; 50 } 51 52 void mlx5_dealloc_transport_domain(struct mlx5_core_dev *dev, u32 tdn) 53 { 54 u32 in[MLX5_ST_SZ_DW(dealloc_transport_domain_in)] = {0}; 55 u32 out[MLX5_ST_SZ_DW(dealloc_transport_domain_out)] = {0}; 56 57 MLX5_SET(dealloc_transport_domain_in, in, opcode, 58 MLX5_CMD_OP_DEALLOC_TRANSPORT_DOMAIN); 59 MLX5_SET(dealloc_transport_domain_in, in, transport_domain, tdn); 60 61 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); 62 } 63 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 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 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 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 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 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 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 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 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 void mlx5_core_destroy_tir(struct mlx5_core_dev *dev, u32 tirn) 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, tirn, tirn); 176 177 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); 178 } 179 180 int mlx5_core_create_tis(struct mlx5_core_dev *dev, u32 *in, int inlen, 181 u32 *tisn) 182 { 183 u32 out[MLX5_ST_SZ_DW(create_tis_out)] = {0}; 184 int err; 185 186 MLX5_SET(create_tis_in, in, opcode, MLX5_CMD_OP_CREATE_TIS); 187 188 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); 189 if (!err) 190 *tisn = MLX5_GET(create_tis_out, out, tisn); 191 192 return err; 193 } 194 195 int mlx5_core_modify_tis(struct mlx5_core_dev *dev, u32 tisn, u32 *in, 196 int inlen) 197 { 198 u32 out[MLX5_ST_SZ_DW(modify_tis_out)] = {0}; 199 200 MLX5_SET(modify_tis_in, in, tisn, tisn); 201 MLX5_SET(modify_tis_in, in, opcode, MLX5_CMD_OP_MODIFY_TIS); 202 203 return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); 204 } 205 206 void mlx5_core_destroy_tis(struct mlx5_core_dev *dev, u32 tisn) 207 { 208 u32 in[MLX5_ST_SZ_DW(destroy_tis_in)] = {0}; 209 u32 out[MLX5_ST_SZ_DW(destroy_tis_out)] = {0}; 210 211 MLX5_SET(destroy_tis_in, in, opcode, MLX5_CMD_OP_DESTROY_TIS); 212 MLX5_SET(destroy_tis_in, in, tisn, tisn); 213 214 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); 215 } 216 217 int mlx5_core_create_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *rmpn) 218 { 219 u32 out[MLX5_ST_SZ_DW(create_rmp_out)] = {0}; 220 int err; 221 222 MLX5_SET(create_rmp_in, in, opcode, MLX5_CMD_OP_CREATE_RMP); 223 224 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); 225 if (!err) 226 *rmpn = MLX5_GET(create_rmp_out, out, rmpn); 227 228 return err; 229 } 230 231 int mlx5_core_modify_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen) 232 { 233 u32 out[MLX5_ST_SZ_DW(modify_rmp_out)] = {0}; 234 235 MLX5_SET(modify_rmp_in, in, opcode, MLX5_CMD_OP_MODIFY_RMP); 236 237 return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); 238 } 239 240 int mlx5_core_destroy_rmp(struct mlx5_core_dev *dev, u32 rmpn) 241 { 242 u32 in[MLX5_ST_SZ_DW(destroy_rmp_in)] = {0}; 243 u32 out[MLX5_ST_SZ_DW(destroy_rmp_out)] = {0}; 244 245 MLX5_SET(destroy_rmp_in, in, opcode, MLX5_CMD_OP_DESTROY_RMP); 246 MLX5_SET(destroy_rmp_in, in, rmpn, rmpn); 247 248 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); 249 } 250 251 int mlx5_core_query_rmp(struct mlx5_core_dev *dev, u32 rmpn, u32 *out) 252 { 253 u32 in[MLX5_ST_SZ_DW(query_rmp_in)] = {0}; 254 int outlen = MLX5_ST_SZ_BYTES(query_rmp_out); 255 256 MLX5_SET(query_rmp_in, in, opcode, MLX5_CMD_OP_QUERY_RMP); 257 MLX5_SET(query_rmp_in, in, rmpn, rmpn); 258 259 return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen); 260 } 261 262 int mlx5_core_arm_rmp(struct mlx5_core_dev *dev, u32 rmpn, u16 lwm) 263 { 264 void *in; 265 void *rmpc; 266 void *wq; 267 void *bitmask; 268 int err; 269 270 in = mlx5_vzalloc(MLX5_ST_SZ_BYTES(modify_rmp_in)); 271 if (!in) 272 return -ENOMEM; 273 274 rmpc = MLX5_ADDR_OF(modify_rmp_in, in, ctx); 275 bitmask = MLX5_ADDR_OF(modify_rmp_in, in, bitmask); 276 wq = MLX5_ADDR_OF(rmpc, rmpc, wq); 277 278 MLX5_SET(modify_rmp_in, in, rmp_state, MLX5_RMPC_STATE_RDY); 279 MLX5_SET(modify_rmp_in, in, rmpn, rmpn); 280 MLX5_SET(wq, wq, lwm, lwm); 281 MLX5_SET(rmp_bitmask, bitmask, lwm, 1); 282 MLX5_SET(rmpc, rmpc, state, MLX5_RMPC_STATE_RDY); 283 284 err = mlx5_core_modify_rmp(dev, in, MLX5_ST_SZ_BYTES(modify_rmp_in)); 285 286 kvfree(in); 287 288 return err; 289 } 290 291 int mlx5_core_create_xsrq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *xsrqn) 292 { 293 u32 out[MLX5_ST_SZ_DW(create_xrc_srq_out)] = {0}; 294 int err; 295 296 MLX5_SET(create_xrc_srq_in, in, opcode, MLX5_CMD_OP_CREATE_XRC_SRQ); 297 298 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); 299 if (!err) 300 *xsrqn = MLX5_GET(create_xrc_srq_out, out, xrc_srqn); 301 302 return err; 303 } 304 305 int mlx5_core_destroy_xsrq(struct mlx5_core_dev *dev, u32 xsrqn) 306 { 307 u32 in[MLX5_ST_SZ_DW(destroy_xrc_srq_in)] = {0}; 308 u32 out[MLX5_ST_SZ_DW(destroy_xrc_srq_out)] = {0}; 309 310 MLX5_SET(destroy_xrc_srq_in, in, opcode, MLX5_CMD_OP_DESTROY_XRC_SRQ); 311 MLX5_SET(destroy_xrc_srq_in, in, xrc_srqn, xsrqn); 312 313 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); 314 } 315 316 int mlx5_core_query_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u32 *out) 317 { 318 int outlen = MLX5_ST_SZ_BYTES(query_xrc_srq_out); 319 u32 in[MLX5_ST_SZ_DW(query_xrc_srq_in)] = {0}; 320 void *xrc_srqc; 321 void *srqc; 322 int err; 323 324 MLX5_SET(query_xrc_srq_in, in, opcode, MLX5_CMD_OP_QUERY_XRC_SRQ); 325 MLX5_SET(query_xrc_srq_in, in, xrc_srqn, xsrqn); 326 327 err = mlx5_cmd_exec(dev, in, sizeof(in), out, outlen); 328 if (!err) { 329 xrc_srqc = MLX5_ADDR_OF(query_xrc_srq_out, out, 330 xrc_srq_context_entry); 331 srqc = MLX5_ADDR_OF(query_srq_out, out, srq_context_entry); 332 memcpy(srqc, xrc_srqc, MLX5_ST_SZ_BYTES(srqc)); 333 } 334 335 return err; 336 } 337 338 int mlx5_core_arm_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u16 lwm) 339 { 340 u32 in[MLX5_ST_SZ_DW(arm_xrc_srq_in)] = {0}; 341 u32 out[MLX5_ST_SZ_DW(arm_xrc_srq_out)] = {0}; 342 343 MLX5_SET(arm_xrc_srq_in, in, opcode, MLX5_CMD_OP_ARM_XRC_SRQ); 344 MLX5_SET(arm_xrc_srq_in, in, xrc_srqn, xsrqn); 345 MLX5_SET(arm_xrc_srq_in, in, lwm, lwm); 346 MLX5_SET(arm_xrc_srq_in, in, op_mod, 347 MLX5_ARM_XRC_SRQ_IN_OP_MOD_XRC_SRQ); 348 349 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); 350 351 } 352 353 int mlx5_core_create_rqt(struct mlx5_core_dev *dev, u32 *in, int inlen, 354 u32 *rqtn) 355 { 356 u32 out[MLX5_ST_SZ_DW(create_rqt_out)] = {0}; 357 int err; 358 359 MLX5_SET(create_rqt_in, in, opcode, MLX5_CMD_OP_CREATE_RQT); 360 361 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); 362 if (!err) 363 *rqtn = MLX5_GET(create_rqt_out, out, rqtn); 364 365 return err; 366 } 367 368 int mlx5_core_modify_rqt(struct mlx5_core_dev *dev, u32 rqtn, u32 *in, 369 int inlen) 370 { 371 u32 out[MLX5_ST_SZ_DW(modify_rqt_out)] = {0}; 372 373 MLX5_SET(modify_rqt_in, in, rqtn, rqtn); 374 MLX5_SET(modify_rqt_in, in, opcode, MLX5_CMD_OP_MODIFY_RQT); 375 376 return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out)); 377 } 378 379 void mlx5_core_destroy_rqt(struct mlx5_core_dev *dev, u32 rqtn) 380 { 381 u32 in[MLX5_ST_SZ_DW(destroy_rqt_in)] = {0}; 382 u32 out[MLX5_ST_SZ_DW(destroy_rqt_out)] = {0}; 383 384 MLX5_SET(destroy_rqt_in, in, opcode, MLX5_CMD_OP_DESTROY_RQT); 385 MLX5_SET(destroy_rqt_in, in, rqtn, rqtn); 386 387 mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); 388 } 389