eq.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /*
  2. * Copyright (c) 2013-2015, Mellanox Technologies. 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/interrupt.h>
  33. #include <linux/module.h>
  34. #include <linux/mlx5/driver.h>
  35. #include <linux/mlx5/cmd.h>
  36. #include "mlx5_core.h"
  37. #ifdef CONFIG_MLX5_CORE_EN
  38. #include "eswitch.h"
  39. #endif
  40. enum {
  41. MLX5_EQE_SIZE = sizeof(struct mlx5_eqe),
  42. MLX5_EQE_OWNER_INIT_VAL = 0x1,
  43. };
  44. enum {
  45. MLX5_EQ_STATE_ARMED = 0x9,
  46. MLX5_EQ_STATE_FIRED = 0xa,
  47. MLX5_EQ_STATE_ALWAYS_ARMED = 0xb,
  48. };
  49. enum {
  50. MLX5_NUM_SPARE_EQE = 0x80,
  51. MLX5_NUM_ASYNC_EQE = 0x100,
  52. MLX5_NUM_CMD_EQE = 32,
  53. };
  54. enum {
  55. MLX5_EQ_DOORBEL_OFFSET = 0x40,
  56. };
  57. #define MLX5_ASYNC_EVENT_MASK ((1ull << MLX5_EVENT_TYPE_PATH_MIG) | \
  58. (1ull << MLX5_EVENT_TYPE_COMM_EST) | \
  59. (1ull << MLX5_EVENT_TYPE_SQ_DRAINED) | \
  60. (1ull << MLX5_EVENT_TYPE_CQ_ERROR) | \
  61. (1ull << MLX5_EVENT_TYPE_WQ_CATAS_ERROR) | \
  62. (1ull << MLX5_EVENT_TYPE_PATH_MIG_FAILED) | \
  63. (1ull << MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR) | \
  64. (1ull << MLX5_EVENT_TYPE_WQ_ACCESS_ERROR) | \
  65. (1ull << MLX5_EVENT_TYPE_PORT_CHANGE) | \
  66. (1ull << MLX5_EVENT_TYPE_SRQ_CATAS_ERROR) | \
  67. (1ull << MLX5_EVENT_TYPE_SRQ_LAST_WQE) | \
  68. (1ull << MLX5_EVENT_TYPE_SRQ_RQ_LIMIT))
  69. struct map_eq_in {
  70. u64 mask;
  71. u32 reserved;
  72. u32 unmap_eqn;
  73. };
  74. struct cre_des_eq {
  75. u8 reserved[15];
  76. u8 eqn;
  77. };
  78. static int mlx5_cmd_destroy_eq(struct mlx5_core_dev *dev, u8 eqn)
  79. {
  80. u32 out[MLX5_ST_SZ_DW(destroy_eq_out)] = {0};
  81. u32 in[MLX5_ST_SZ_DW(destroy_eq_in)] = {0};
  82. MLX5_SET(destroy_eq_in, in, opcode, MLX5_CMD_OP_DESTROY_EQ);
  83. MLX5_SET(destroy_eq_in, in, eq_number, eqn);
  84. return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
  85. }
  86. static struct mlx5_eqe *get_eqe(struct mlx5_eq *eq, u32 entry)
  87. {
  88. return mlx5_buf_offset(&eq->buf, entry * MLX5_EQE_SIZE);
  89. }
  90. static struct mlx5_eqe *next_eqe_sw(struct mlx5_eq *eq)
  91. {
  92. struct mlx5_eqe *eqe = get_eqe(eq, eq->cons_index & (eq->nent - 1));
  93. return ((eqe->owner & 1) ^ !!(eq->cons_index & eq->nent)) ? NULL : eqe;
  94. }
  95. static const char *eqe_type_str(u8 type)
  96. {
  97. switch (type) {
  98. case MLX5_EVENT_TYPE_COMP:
  99. return "MLX5_EVENT_TYPE_COMP";
  100. case MLX5_EVENT_TYPE_PATH_MIG:
  101. return "MLX5_EVENT_TYPE_PATH_MIG";
  102. case MLX5_EVENT_TYPE_COMM_EST:
  103. return "MLX5_EVENT_TYPE_COMM_EST";
  104. case MLX5_EVENT_TYPE_SQ_DRAINED:
  105. return "MLX5_EVENT_TYPE_SQ_DRAINED";
  106. case MLX5_EVENT_TYPE_SRQ_LAST_WQE:
  107. return "MLX5_EVENT_TYPE_SRQ_LAST_WQE";
  108. case MLX5_EVENT_TYPE_SRQ_RQ_LIMIT:
  109. return "MLX5_EVENT_TYPE_SRQ_RQ_LIMIT";
  110. case MLX5_EVENT_TYPE_CQ_ERROR:
  111. return "MLX5_EVENT_TYPE_CQ_ERROR";
  112. case MLX5_EVENT_TYPE_WQ_CATAS_ERROR:
  113. return "MLX5_EVENT_TYPE_WQ_CATAS_ERROR";
  114. case MLX5_EVENT_TYPE_PATH_MIG_FAILED:
  115. return "MLX5_EVENT_TYPE_PATH_MIG_FAILED";
  116. case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
  117. return "MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR";
  118. case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR:
  119. return "MLX5_EVENT_TYPE_WQ_ACCESS_ERROR";
  120. case MLX5_EVENT_TYPE_SRQ_CATAS_ERROR:
  121. return "MLX5_EVENT_TYPE_SRQ_CATAS_ERROR";
  122. case MLX5_EVENT_TYPE_INTERNAL_ERROR:
  123. return "MLX5_EVENT_TYPE_INTERNAL_ERROR";
  124. case MLX5_EVENT_TYPE_PORT_CHANGE:
  125. return "MLX5_EVENT_TYPE_PORT_CHANGE";
  126. case MLX5_EVENT_TYPE_GPIO_EVENT:
  127. return "MLX5_EVENT_TYPE_GPIO_EVENT";
  128. case MLX5_EVENT_TYPE_REMOTE_CONFIG:
  129. return "MLX5_EVENT_TYPE_REMOTE_CONFIG";
  130. case MLX5_EVENT_TYPE_DB_BF_CONGESTION:
  131. return "MLX5_EVENT_TYPE_DB_BF_CONGESTION";
  132. case MLX5_EVENT_TYPE_STALL_EVENT:
  133. return "MLX5_EVENT_TYPE_STALL_EVENT";
  134. case MLX5_EVENT_TYPE_CMD:
  135. return "MLX5_EVENT_TYPE_CMD";
  136. case MLX5_EVENT_TYPE_PAGE_REQUEST:
  137. return "MLX5_EVENT_TYPE_PAGE_REQUEST";
  138. case MLX5_EVENT_TYPE_PAGE_FAULT:
  139. return "MLX5_EVENT_TYPE_PAGE_FAULT";
  140. default:
  141. return "Unrecognized event";
  142. }
  143. }
  144. static enum mlx5_dev_event port_subtype_event(u8 subtype)
  145. {
  146. switch (subtype) {
  147. case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
  148. return MLX5_DEV_EVENT_PORT_DOWN;
  149. case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
  150. return MLX5_DEV_EVENT_PORT_UP;
  151. case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED:
  152. return MLX5_DEV_EVENT_PORT_INITIALIZED;
  153. case MLX5_PORT_CHANGE_SUBTYPE_LID:
  154. return MLX5_DEV_EVENT_LID_CHANGE;
  155. case MLX5_PORT_CHANGE_SUBTYPE_PKEY:
  156. return MLX5_DEV_EVENT_PKEY_CHANGE;
  157. case MLX5_PORT_CHANGE_SUBTYPE_GUID:
  158. return MLX5_DEV_EVENT_GUID_CHANGE;
  159. case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG:
  160. return MLX5_DEV_EVENT_CLIENT_REREG;
  161. }
  162. return -1;
  163. }
  164. static void eq_update_ci(struct mlx5_eq *eq, int arm)
  165. {
  166. __be32 __iomem *addr = eq->doorbell + (arm ? 0 : 2);
  167. u32 val = (eq->cons_index & 0xffffff) | (eq->eqn << 24);
  168. __raw_writel((__force u32) cpu_to_be32(val), addr);
  169. /* We still want ordering, just not swabbing, so add a barrier */
  170. mb();
  171. }
  172. static int mlx5_eq_int(struct mlx5_core_dev *dev, struct mlx5_eq *eq)
  173. {
  174. struct mlx5_eqe *eqe;
  175. int eqes_found = 0;
  176. int set_ci = 0;
  177. u32 cqn = -1;
  178. u32 rsn;
  179. u8 port;
  180. while ((eqe = next_eqe_sw(eq))) {
  181. /*
  182. * Make sure we read EQ entry contents after we've
  183. * checked the ownership bit.
  184. */
  185. dma_rmb();
  186. mlx5_core_dbg(eq->dev, "eqn %d, eqe type %s\n",
  187. eq->eqn, eqe_type_str(eqe->type));
  188. switch (eqe->type) {
  189. case MLX5_EVENT_TYPE_COMP:
  190. cqn = be32_to_cpu(eqe->data.comp.cqn) & 0xffffff;
  191. mlx5_cq_completion(dev, cqn);
  192. break;
  193. case MLX5_EVENT_TYPE_PATH_MIG:
  194. case MLX5_EVENT_TYPE_COMM_EST:
  195. case MLX5_EVENT_TYPE_SQ_DRAINED:
  196. case MLX5_EVENT_TYPE_SRQ_LAST_WQE:
  197. case MLX5_EVENT_TYPE_WQ_CATAS_ERROR:
  198. case MLX5_EVENT_TYPE_PATH_MIG_FAILED:
  199. case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
  200. case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR:
  201. rsn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff;
  202. rsn |= (eqe->data.qp_srq.type << MLX5_USER_INDEX_LEN);
  203. mlx5_core_dbg(dev, "event %s(%d) arrived on resource 0x%x\n",
  204. eqe_type_str(eqe->type), eqe->type, rsn);
  205. mlx5_rsc_event(dev, rsn, eqe->type);
  206. break;
  207. case MLX5_EVENT_TYPE_SRQ_RQ_LIMIT:
  208. case MLX5_EVENT_TYPE_SRQ_CATAS_ERROR:
  209. rsn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff;
  210. mlx5_core_dbg(dev, "SRQ event %s(%d): srqn 0x%x\n",
  211. eqe_type_str(eqe->type), eqe->type, rsn);
  212. mlx5_srq_event(dev, rsn, eqe->type);
  213. break;
  214. case MLX5_EVENT_TYPE_CMD:
  215. mlx5_cmd_comp_handler(dev, be32_to_cpu(eqe->data.cmd.vector), false);
  216. break;
  217. case MLX5_EVENT_TYPE_PORT_CHANGE:
  218. port = (eqe->data.port.port >> 4) & 0xf;
  219. switch (eqe->sub_type) {
  220. case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
  221. case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
  222. case MLX5_PORT_CHANGE_SUBTYPE_LID:
  223. case MLX5_PORT_CHANGE_SUBTYPE_PKEY:
  224. case MLX5_PORT_CHANGE_SUBTYPE_GUID:
  225. case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG:
  226. case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED:
  227. if (dev->event)
  228. dev->event(dev, port_subtype_event(eqe->sub_type),
  229. (unsigned long)port);
  230. break;
  231. default:
  232. mlx5_core_warn(dev, "Port event with unrecognized subtype: port %d, sub_type %d\n",
  233. port, eqe->sub_type);
  234. }
  235. break;
  236. case MLX5_EVENT_TYPE_CQ_ERROR:
  237. cqn = be32_to_cpu(eqe->data.cq_err.cqn) & 0xffffff;
  238. mlx5_core_warn(dev, "CQ error on CQN 0x%x, syndrom 0x%x\n",
  239. cqn, eqe->data.cq_err.syndrome);
  240. mlx5_cq_event(dev, cqn, eqe->type);
  241. break;
  242. case MLX5_EVENT_TYPE_PAGE_REQUEST:
  243. {
  244. u16 func_id = be16_to_cpu(eqe->data.req_pages.func_id);
  245. s32 npages = be32_to_cpu(eqe->data.req_pages.num_pages);
  246. mlx5_core_dbg(dev, "page request for func 0x%x, npages %d\n",
  247. func_id, npages);
  248. mlx5_core_req_pages_handler(dev, func_id, npages);
  249. }
  250. break;
  251. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  252. case MLX5_EVENT_TYPE_PAGE_FAULT:
  253. mlx5_eq_pagefault(dev, eqe);
  254. break;
  255. #endif
  256. #ifdef CONFIG_MLX5_CORE_EN
  257. case MLX5_EVENT_TYPE_NIC_VPORT_CHANGE:
  258. mlx5_eswitch_vport_event(dev->priv.eswitch, eqe);
  259. break;
  260. #endif
  261. default:
  262. mlx5_core_warn(dev, "Unhandled event 0x%x on EQ 0x%x\n",
  263. eqe->type, eq->eqn);
  264. break;
  265. }
  266. ++eq->cons_index;
  267. eqes_found = 1;
  268. ++set_ci;
  269. /* The HCA will think the queue has overflowed if we
  270. * don't tell it we've been processing events. We
  271. * create our EQs with MLX5_NUM_SPARE_EQE extra
  272. * entries, so we must update our consumer index at
  273. * least that often.
  274. */
  275. if (unlikely(set_ci >= MLX5_NUM_SPARE_EQE)) {
  276. eq_update_ci(eq, 0);
  277. set_ci = 0;
  278. }
  279. }
  280. eq_update_ci(eq, 1);
  281. if (cqn != -1)
  282. tasklet_schedule(&eq->tasklet_ctx.task);
  283. return eqes_found;
  284. }
  285. static irqreturn_t mlx5_msix_handler(int irq, void *eq_ptr)
  286. {
  287. struct mlx5_eq *eq = eq_ptr;
  288. struct mlx5_core_dev *dev = eq->dev;
  289. mlx5_eq_int(dev, eq);
  290. /* MSI-X vectors always belong to us */
  291. return IRQ_HANDLED;
  292. }
  293. static void init_eq_buf(struct mlx5_eq *eq)
  294. {
  295. struct mlx5_eqe *eqe;
  296. int i;
  297. for (i = 0; i < eq->nent; i++) {
  298. eqe = get_eqe(eq, i);
  299. eqe->owner = MLX5_EQE_OWNER_INIT_VAL;
  300. }
  301. }
  302. int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
  303. int nent, u64 mask, const char *name, struct mlx5_uar *uar)
  304. {
  305. u32 out[MLX5_ST_SZ_DW(create_eq_out)] = {0};
  306. struct mlx5_priv *priv = &dev->priv;
  307. __be64 *pas;
  308. void *eqc;
  309. int inlen;
  310. u32 *in;
  311. int err;
  312. eq->nent = roundup_pow_of_two(nent + MLX5_NUM_SPARE_EQE);
  313. eq->cons_index = 0;
  314. err = mlx5_buf_alloc(dev, eq->nent * MLX5_EQE_SIZE, &eq->buf);
  315. if (err)
  316. return err;
  317. init_eq_buf(eq);
  318. inlen = MLX5_ST_SZ_BYTES(create_eq_in) +
  319. MLX5_FLD_SZ_BYTES(create_eq_in, pas[0]) * eq->buf.npages;
  320. in = mlx5_vzalloc(inlen);
  321. if (!in) {
  322. err = -ENOMEM;
  323. goto err_buf;
  324. }
  325. pas = (__be64 *)MLX5_ADDR_OF(create_eq_in, in, pas);
  326. mlx5_fill_page_array(&eq->buf, pas);
  327. MLX5_SET(create_eq_in, in, opcode, MLX5_CMD_OP_CREATE_EQ);
  328. MLX5_SET64(create_eq_in, in, event_bitmask, mask);
  329. eqc = MLX5_ADDR_OF(create_eq_in, in, eq_context_entry);
  330. MLX5_SET(eqc, eqc, log_eq_size, ilog2(eq->nent));
  331. MLX5_SET(eqc, eqc, uar_page, uar->index);
  332. MLX5_SET(eqc, eqc, intr, vecidx);
  333. MLX5_SET(eqc, eqc, log_page_size,
  334. eq->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT);
  335. err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
  336. if (err)
  337. goto err_in;
  338. snprintf(priv->irq_info[vecidx].name, MLX5_MAX_IRQ_NAME, "%s@pci:%s",
  339. name, pci_name(dev->pdev));
  340. eq->eqn = MLX5_GET(create_eq_out, out, eq_number);
  341. eq->irqn = priv->msix_arr[vecidx].vector;
  342. eq->dev = dev;
  343. eq->doorbell = uar->map + MLX5_EQ_DOORBEL_OFFSET;
  344. err = request_irq(eq->irqn, mlx5_msix_handler, 0,
  345. priv->irq_info[vecidx].name, eq);
  346. if (err)
  347. goto err_eq;
  348. err = mlx5_debug_eq_add(dev, eq);
  349. if (err)
  350. goto err_irq;
  351. INIT_LIST_HEAD(&eq->tasklet_ctx.list);
  352. INIT_LIST_HEAD(&eq->tasklet_ctx.process_list);
  353. spin_lock_init(&eq->tasklet_ctx.lock);
  354. tasklet_init(&eq->tasklet_ctx.task, mlx5_cq_tasklet_cb,
  355. (unsigned long)&eq->tasklet_ctx);
  356. /* EQs are created in ARMED state
  357. */
  358. eq_update_ci(eq, 1);
  359. kvfree(in);
  360. return 0;
  361. err_irq:
  362. free_irq(priv->msix_arr[vecidx].vector, eq);
  363. err_eq:
  364. mlx5_cmd_destroy_eq(dev, eq->eqn);
  365. err_in:
  366. kvfree(in);
  367. err_buf:
  368. mlx5_buf_free(dev, &eq->buf);
  369. return err;
  370. }
  371. EXPORT_SYMBOL_GPL(mlx5_create_map_eq);
  372. int mlx5_destroy_unmap_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq)
  373. {
  374. int err;
  375. mlx5_debug_eq_remove(dev, eq);
  376. free_irq(eq->irqn, eq);
  377. err = mlx5_cmd_destroy_eq(dev, eq->eqn);
  378. if (err)
  379. mlx5_core_warn(dev, "failed to destroy a previously created eq: eqn %d\n",
  380. eq->eqn);
  381. synchronize_irq(eq->irqn);
  382. tasklet_disable(&eq->tasklet_ctx.task);
  383. mlx5_buf_free(dev, &eq->buf);
  384. return err;
  385. }
  386. EXPORT_SYMBOL_GPL(mlx5_destroy_unmap_eq);
  387. u32 mlx5_get_msix_vec(struct mlx5_core_dev *dev, int vecidx)
  388. {
  389. return dev->priv.msix_arr[MLX5_EQ_VEC_ASYNC].vector;
  390. }
  391. int mlx5_eq_init(struct mlx5_core_dev *dev)
  392. {
  393. int err;
  394. spin_lock_init(&dev->priv.eq_table.lock);
  395. err = mlx5_eq_debugfs_init(dev);
  396. return err;
  397. }
  398. void mlx5_eq_cleanup(struct mlx5_core_dev *dev)
  399. {
  400. mlx5_eq_debugfs_cleanup(dev);
  401. }
  402. int mlx5_start_eqs(struct mlx5_core_dev *dev)
  403. {
  404. struct mlx5_eq_table *table = &dev->priv.eq_table;
  405. u32 async_event_mask = MLX5_ASYNC_EVENT_MASK;
  406. int err;
  407. if (MLX5_CAP_GEN(dev, pg))
  408. async_event_mask |= (1ull << MLX5_EVENT_TYPE_PAGE_FAULT);
  409. if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_ETH &&
  410. MLX5_CAP_GEN(dev, vport_group_manager) &&
  411. mlx5_core_is_pf(dev))
  412. async_event_mask |= (1ull << MLX5_EVENT_TYPE_NIC_VPORT_CHANGE);
  413. err = mlx5_create_map_eq(dev, &table->cmd_eq, MLX5_EQ_VEC_CMD,
  414. MLX5_NUM_CMD_EQE, 1ull << MLX5_EVENT_TYPE_CMD,
  415. "mlx5_cmd_eq", &dev->priv.uuari.uars[0]);
  416. if (err) {
  417. mlx5_core_warn(dev, "failed to create cmd EQ %d\n", err);
  418. return err;
  419. }
  420. mlx5_cmd_use_events(dev);
  421. err = mlx5_create_map_eq(dev, &table->async_eq, MLX5_EQ_VEC_ASYNC,
  422. MLX5_NUM_ASYNC_EQE, async_event_mask,
  423. "mlx5_async_eq", &dev->priv.uuari.uars[0]);
  424. if (err) {
  425. mlx5_core_warn(dev, "failed to create async EQ %d\n", err);
  426. goto err1;
  427. }
  428. err = mlx5_create_map_eq(dev, &table->pages_eq,
  429. MLX5_EQ_VEC_PAGES,
  430. /* TODO: sriov max_vf + */ 1,
  431. 1 << MLX5_EVENT_TYPE_PAGE_REQUEST, "mlx5_pages_eq",
  432. &dev->priv.uuari.uars[0]);
  433. if (err) {
  434. mlx5_core_warn(dev, "failed to create pages EQ %d\n", err);
  435. goto err2;
  436. }
  437. return err;
  438. err2:
  439. mlx5_destroy_unmap_eq(dev, &table->async_eq);
  440. err1:
  441. mlx5_cmd_use_polling(dev);
  442. mlx5_destroy_unmap_eq(dev, &table->cmd_eq);
  443. return err;
  444. }
  445. int mlx5_stop_eqs(struct mlx5_core_dev *dev)
  446. {
  447. struct mlx5_eq_table *table = &dev->priv.eq_table;
  448. int err;
  449. err = mlx5_destroy_unmap_eq(dev, &table->pages_eq);
  450. if (err)
  451. return err;
  452. mlx5_destroy_unmap_eq(dev, &table->async_eq);
  453. mlx5_cmd_use_polling(dev);
  454. err = mlx5_destroy_unmap_eq(dev, &table->cmd_eq);
  455. if (err)
  456. mlx5_cmd_use_events(dev);
  457. return err;
  458. }
  459. int mlx5_core_eq_query(struct mlx5_core_dev *dev, struct mlx5_eq *eq,
  460. u32 *out, int outlen)
  461. {
  462. u32 in[MLX5_ST_SZ_DW(query_eq_in)] = {0};
  463. MLX5_SET(query_eq_in, in, opcode, MLX5_CMD_OP_QUERY_EQ);
  464. MLX5_SET(query_eq_in, in, eq_number, eq->eqn);
  465. return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
  466. }
  467. EXPORT_SYMBOL_GPL(mlx5_core_eq_query);