transobj.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. #include <linux/mlx5/driver.h>
  33. #include "mlx5_core.h"
  34. #include <linux/mlx5/transobj.h>
  35. int mlx5_core_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. MLX5_SET(alloc_transport_domain_in, in, opcode,
  41. MLX5_CMD_OP_ALLOC_TRANSPORT_DOMAIN);
  42. err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
  43. if (!err)
  44. *tdn = MLX5_GET(alloc_transport_domain_out, out,
  45. transport_domain);
  46. return err;
  47. }
  48. EXPORT_SYMBOL(mlx5_core_alloc_transport_domain);
  49. void mlx5_core_dealloc_transport_domain(struct mlx5_core_dev *dev, u32 tdn)
  50. {
  51. u32 in[MLX5_ST_SZ_DW(dealloc_transport_domain_in)] = {0};
  52. u32 out[MLX5_ST_SZ_DW(dealloc_transport_domain_out)] = {0};
  53. MLX5_SET(dealloc_transport_domain_in, in, opcode,
  54. MLX5_CMD_OP_DEALLOC_TRANSPORT_DOMAIN);
  55. MLX5_SET(dealloc_transport_domain_in, in, transport_domain, tdn);
  56. mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
  57. }
  58. EXPORT_SYMBOL(mlx5_core_dealloc_transport_domain);
  59. int mlx5_core_create_rq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *rqn)
  60. {
  61. u32 out[MLX5_ST_SZ_DW(create_rq_out)] = {0};
  62. int err;
  63. MLX5_SET(create_rq_in, in, opcode, MLX5_CMD_OP_CREATE_RQ);
  64. err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  65. if (!err)
  66. *rqn = MLX5_GET(create_rq_out, out, rqn);
  67. return err;
  68. }
  69. EXPORT_SYMBOL(mlx5_core_create_rq);
  70. int mlx5_core_modify_rq(struct mlx5_core_dev *dev, u32 rqn, u32 *in, int inlen)
  71. {
  72. u32 out[MLX5_ST_SZ_DW(modify_rq_out)];
  73. MLX5_SET(modify_rq_in, in, rqn, rqn);
  74. MLX5_SET(modify_rq_in, in, opcode, MLX5_CMD_OP_MODIFY_RQ);
  75. memset(out, 0, sizeof(out));
  76. return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  77. }
  78. EXPORT_SYMBOL(mlx5_core_modify_rq);
  79. void mlx5_core_destroy_rq(struct mlx5_core_dev *dev, u32 rqn)
  80. {
  81. u32 in[MLX5_ST_SZ_DW(destroy_rq_in)] = {0};
  82. u32 out[MLX5_ST_SZ_DW(destroy_rq_out)] = {0};
  83. MLX5_SET(destroy_rq_in, in, opcode, MLX5_CMD_OP_DESTROY_RQ);
  84. MLX5_SET(destroy_rq_in, in, rqn, rqn);
  85. mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
  86. }
  87. EXPORT_SYMBOL(mlx5_core_destroy_rq);
  88. int mlx5_core_query_rq(struct mlx5_core_dev *dev, u32 rqn, u32 *out)
  89. {
  90. u32 in[MLX5_ST_SZ_DW(query_rq_in)] = {0};
  91. int outlen = MLX5_ST_SZ_BYTES(query_rq_out);
  92. MLX5_SET(query_rq_in, in, opcode, MLX5_CMD_OP_QUERY_RQ);
  93. MLX5_SET(query_rq_in, in, rqn, rqn);
  94. return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
  95. }
  96. EXPORT_SYMBOL(mlx5_core_query_rq);
  97. int mlx5_core_create_sq(struct mlx5_core_dev *dev, u32 *in, int inlen, u32 *sqn)
  98. {
  99. u32 out[MLX5_ST_SZ_DW(create_sq_out)] = {0};
  100. int err;
  101. MLX5_SET(create_sq_in, in, opcode, MLX5_CMD_OP_CREATE_SQ);
  102. err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  103. if (!err)
  104. *sqn = MLX5_GET(create_sq_out, out, sqn);
  105. return err;
  106. }
  107. int mlx5_core_modify_sq(struct mlx5_core_dev *dev, u32 sqn, u32 *in, int inlen)
  108. {
  109. u32 out[MLX5_ST_SZ_DW(modify_sq_out)] = {0};
  110. MLX5_SET(modify_sq_in, in, sqn, sqn);
  111. MLX5_SET(modify_sq_in, in, opcode, MLX5_CMD_OP_MODIFY_SQ);
  112. return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  113. }
  114. EXPORT_SYMBOL(mlx5_core_modify_sq);
  115. void mlx5_core_destroy_sq(struct mlx5_core_dev *dev, u32 sqn)
  116. {
  117. u32 in[MLX5_ST_SZ_DW(destroy_sq_in)] = {0};
  118. u32 out[MLX5_ST_SZ_DW(destroy_sq_out)] = {0};
  119. MLX5_SET(destroy_sq_in, in, opcode, MLX5_CMD_OP_DESTROY_SQ);
  120. MLX5_SET(destroy_sq_in, in, sqn, sqn);
  121. mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
  122. }
  123. int mlx5_core_query_sq(struct mlx5_core_dev *dev, u32 sqn, u32 *out)
  124. {
  125. u32 in[MLX5_ST_SZ_DW(query_sq_in)] = {0};
  126. int outlen = MLX5_ST_SZ_BYTES(query_sq_out);
  127. MLX5_SET(query_sq_in, in, opcode, MLX5_CMD_OP_QUERY_SQ);
  128. MLX5_SET(query_sq_in, in, sqn, sqn);
  129. return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
  130. }
  131. EXPORT_SYMBOL(mlx5_core_query_sq);
  132. int mlx5_core_create_tir(struct mlx5_core_dev *dev, u32 *in, int inlen,
  133. u32 *tirn)
  134. {
  135. u32 out[MLX5_ST_SZ_DW(create_tir_out)] = {0};
  136. int err;
  137. MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR);
  138. memset(out, 0, sizeof(out));
  139. err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  140. if (!err)
  141. *tirn = MLX5_GET(create_tir_out, out, tirn);
  142. return err;
  143. }
  144. EXPORT_SYMBOL(mlx5_core_create_tir);
  145. int mlx5_core_modify_tir(struct mlx5_core_dev *dev, u32 tirn, u32 *in,
  146. int inlen)
  147. {
  148. u32 out[MLX5_ST_SZ_DW(modify_tir_out)] = {0};
  149. MLX5_SET(modify_tir_in, in, tirn, tirn);
  150. MLX5_SET(modify_tir_in, in, opcode, MLX5_CMD_OP_MODIFY_TIR);
  151. return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  152. }
  153. void mlx5_core_destroy_tir(struct mlx5_core_dev *dev, u32 tirn)
  154. {
  155. u32 in[MLX5_ST_SZ_DW(destroy_tir_in)] = {0};
  156. u32 out[MLX5_ST_SZ_DW(destroy_tir_out)] = {0};
  157. MLX5_SET(destroy_tir_in, in, opcode, MLX5_CMD_OP_DESTROY_TIR);
  158. MLX5_SET(destroy_tir_in, in, tirn, tirn);
  159. mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
  160. }
  161. EXPORT_SYMBOL(mlx5_core_destroy_tir);
  162. int mlx5_core_create_tis(struct mlx5_core_dev *dev, u32 *in, int inlen,
  163. u32 *tisn)
  164. {
  165. u32 out[MLX5_ST_SZ_DW(create_tis_out)] = {0};
  166. int err;
  167. MLX5_SET(create_tis_in, in, opcode, MLX5_CMD_OP_CREATE_TIS);
  168. err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  169. if (!err)
  170. *tisn = MLX5_GET(create_tis_out, out, tisn);
  171. return err;
  172. }
  173. EXPORT_SYMBOL(mlx5_core_create_tis);
  174. int mlx5_core_modify_tis(struct mlx5_core_dev *dev, u32 tisn, u32 *in,
  175. int inlen)
  176. {
  177. u32 out[MLX5_ST_SZ_DW(modify_tis_out)] = {0};
  178. MLX5_SET(modify_tis_in, in, tisn, tisn);
  179. MLX5_SET(modify_tis_in, in, opcode, MLX5_CMD_OP_MODIFY_TIS);
  180. return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  181. }
  182. EXPORT_SYMBOL(mlx5_core_modify_tis);
  183. void mlx5_core_destroy_tis(struct mlx5_core_dev *dev, u32 tisn)
  184. {
  185. u32 in[MLX5_ST_SZ_DW(destroy_tis_in)] = {0};
  186. u32 out[MLX5_ST_SZ_DW(destroy_tis_out)] = {0};
  187. MLX5_SET(destroy_tis_in, in, opcode, MLX5_CMD_OP_DESTROY_TIS);
  188. MLX5_SET(destroy_tis_in, in, tisn, tisn);
  189. mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
  190. }
  191. EXPORT_SYMBOL(mlx5_core_destroy_tis);
  192. int mlx5_core_create_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen,
  193. u32 *rmpn)
  194. {
  195. u32 out[MLX5_ST_SZ_DW(create_rmp_out)] = {0};
  196. int err;
  197. MLX5_SET(create_rmp_in, in, opcode, MLX5_CMD_OP_CREATE_RMP);
  198. err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  199. if (!err)
  200. *rmpn = MLX5_GET(create_rmp_out, out, rmpn);
  201. return err;
  202. }
  203. int mlx5_core_modify_rmp(struct mlx5_core_dev *dev, u32 *in, int inlen)
  204. {
  205. u32 out[MLX5_ST_SZ_DW(modify_rmp_out)] = {0};
  206. MLX5_SET(modify_rmp_in, in, opcode, MLX5_CMD_OP_MODIFY_RMP);
  207. return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  208. }
  209. int mlx5_core_destroy_rmp(struct mlx5_core_dev *dev, u32 rmpn)
  210. {
  211. u32 in[MLX5_ST_SZ_DW(destroy_rmp_in)] = {0};
  212. u32 out[MLX5_ST_SZ_DW(destroy_rmp_out)] = {0};
  213. MLX5_SET(destroy_rmp_in, in, opcode, MLX5_CMD_OP_DESTROY_RMP);
  214. MLX5_SET(destroy_rmp_in, in, rmpn, rmpn);
  215. return mlx5_cmd_exec(dev, in, sizeof(in), out,
  216. sizeof(out));
  217. }
  218. int mlx5_core_query_rmp(struct mlx5_core_dev *dev, u32 rmpn, u32 *out)
  219. {
  220. u32 in[MLX5_ST_SZ_DW(query_rmp_in)] = {0};
  221. int outlen = MLX5_ST_SZ_BYTES(query_rmp_out);
  222. MLX5_SET(query_rmp_in, in, opcode, MLX5_CMD_OP_QUERY_RMP);
  223. MLX5_SET(query_rmp_in, in, rmpn, rmpn);
  224. return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
  225. }
  226. int mlx5_core_arm_rmp(struct mlx5_core_dev *dev, u32 rmpn, u16 lwm)
  227. {
  228. void *in;
  229. void *rmpc;
  230. void *wq;
  231. void *bitmask;
  232. int err;
  233. in = mlx5_vzalloc(MLX5_ST_SZ_BYTES(modify_rmp_in));
  234. if (!in)
  235. return -ENOMEM;
  236. rmpc = MLX5_ADDR_OF(modify_rmp_in, in, ctx);
  237. bitmask = MLX5_ADDR_OF(modify_rmp_in, in, bitmask);
  238. wq = MLX5_ADDR_OF(rmpc, rmpc, wq);
  239. MLX5_SET(modify_rmp_in, in, rmp_state, MLX5_RMPC_STATE_RDY);
  240. MLX5_SET(modify_rmp_in, in, rmpn, rmpn);
  241. MLX5_SET(wq, wq, lwm, lwm);
  242. MLX5_SET(rmp_bitmask, bitmask, lwm, 1);
  243. MLX5_SET(rmpc, rmpc, state, MLX5_RMPC_STATE_RDY);
  244. err = mlx5_core_modify_rmp(dev, in, MLX5_ST_SZ_BYTES(modify_rmp_in));
  245. kvfree(in);
  246. return err;
  247. }
  248. int mlx5_core_create_xsrq(struct mlx5_core_dev *dev, u32 *in, int inlen,
  249. u32 *xsrqn)
  250. {
  251. u32 out[MLX5_ST_SZ_DW(create_xrc_srq_out)] = {0};
  252. int err;
  253. MLX5_SET(create_xrc_srq_in, in, opcode, MLX5_CMD_OP_CREATE_XRC_SRQ);
  254. err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  255. if (!err)
  256. *xsrqn = MLX5_GET(create_xrc_srq_out, out, xrc_srqn);
  257. return err;
  258. }
  259. int mlx5_core_destroy_xsrq(struct mlx5_core_dev *dev, u32 xsrqn)
  260. {
  261. u32 in[MLX5_ST_SZ_DW(destroy_xrc_srq_in)] = {0};
  262. u32 out[MLX5_ST_SZ_DW(destroy_xrc_srq_out)] = {0};
  263. MLX5_SET(destroy_xrc_srq_in, in, opcode, MLX5_CMD_OP_DESTROY_XRC_SRQ);
  264. MLX5_SET(destroy_xrc_srq_in, in, xrc_srqn, xsrqn);
  265. return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
  266. }
  267. int mlx5_core_query_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u32 *out)
  268. {
  269. u32 in[MLX5_ST_SZ_DW(query_xrc_srq_in)] = {0};
  270. void *srqc;
  271. void *xrc_srqc;
  272. int err;
  273. MLX5_SET(query_xrc_srq_in, in, opcode, MLX5_CMD_OP_QUERY_XRC_SRQ);
  274. MLX5_SET(query_xrc_srq_in, in, xrc_srqn, xsrqn);
  275. err = mlx5_cmd_exec(dev, in, sizeof(in), out,
  276. MLX5_ST_SZ_BYTES(query_xrc_srq_out));
  277. if (!err) {
  278. xrc_srqc = MLX5_ADDR_OF(query_xrc_srq_out, out,
  279. xrc_srq_context_entry);
  280. srqc = MLX5_ADDR_OF(query_srq_out, out, srq_context_entry);
  281. memcpy(srqc, xrc_srqc, MLX5_ST_SZ_BYTES(srqc));
  282. }
  283. return err;
  284. }
  285. int mlx5_core_arm_xsrq(struct mlx5_core_dev *dev, u32 xsrqn, u16 lwm)
  286. {
  287. u32 in[MLX5_ST_SZ_DW(arm_xrc_srq_in)] = {0};
  288. u32 out[MLX5_ST_SZ_DW(arm_xrc_srq_out)] = {0};
  289. MLX5_SET(arm_xrc_srq_in, in, opcode, MLX5_CMD_OP_ARM_XRC_SRQ);
  290. MLX5_SET(arm_xrc_srq_in, in, xrc_srqn, xsrqn);
  291. MLX5_SET(arm_xrc_srq_in, in, lwm, lwm);
  292. MLX5_SET(arm_xrc_srq_in, in, op_mod,
  293. MLX5_ARM_XRC_SRQ_IN_OP_MOD_XRC_SRQ);
  294. return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
  295. }
  296. int mlx5_core_create_rqt(struct mlx5_core_dev *dev, u32 *in, int inlen,
  297. u32 *rqtn)
  298. {
  299. u32 out[MLX5_ST_SZ_DW(create_rqt_out)] = {0};
  300. int err;
  301. MLX5_SET(create_rqt_in, in, opcode, MLX5_CMD_OP_CREATE_RQT);
  302. err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  303. if (!err)
  304. *rqtn = MLX5_GET(create_rqt_out, out, rqtn);
  305. return err;
  306. }
  307. EXPORT_SYMBOL(mlx5_core_create_rqt);
  308. int mlx5_core_modify_rqt(struct mlx5_core_dev *dev, u32 rqtn, u32 *in,
  309. int inlen)
  310. {
  311. u32 out[MLX5_ST_SZ_DW(modify_rqt_out)] = {0};
  312. MLX5_SET(modify_rqt_in, in, rqtn, rqtn);
  313. MLX5_SET(modify_rqt_in, in, opcode, MLX5_CMD_OP_MODIFY_RQT);
  314. return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  315. }
  316. void mlx5_core_destroy_rqt(struct mlx5_core_dev *dev, u32 rqtn)
  317. {
  318. u32 in[MLX5_ST_SZ_DW(destroy_rqt_in)] = {0};
  319. u32 out[MLX5_ST_SZ_DW(destroy_rqt_out)] = {0};
  320. MLX5_SET(destroy_rqt_in, in, opcode, MLX5_CMD_OP_DESTROY_RQT);
  321. MLX5_SET(destroy_rqt_in, in, rqtn, rqtn);
  322. mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
  323. }
  324. EXPORT_SYMBOL(mlx5_core_destroy_rqt);