2 * Copyright (c) 2013-2015, Mellanox Technologies. 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/interrupt.h>
34 #include <linux/module.h>
35 #include <linux/mlx5/driver.h>
36 #include <linux/mlx5/cmd.h>
37 #include "mlx5_core.h"
38 #include "fpga/core.h"
39 #ifdef CONFIG_MLX5_CORE_EN
44 MLX5_EQE_SIZE = sizeof(struct mlx5_eqe),
45 MLX5_EQE_OWNER_INIT_VAL = 0x1,
49 MLX5_EQ_STATE_ARMED = 0x9,
50 MLX5_EQ_STATE_FIRED = 0xa,
51 MLX5_EQ_STATE_ALWAYS_ARMED = 0xb,
55 MLX5_NUM_SPARE_EQE = 0x80,
56 MLX5_NUM_ASYNC_EQE = 0x100,
57 MLX5_NUM_CMD_EQE = 32,
58 MLX5_NUM_PF_DRAIN = 64,
62 MLX5_EQ_DOORBEL_OFFSET = 0x40,
65 #define MLX5_ASYNC_EVENT_MASK ((1ull << MLX5_EVENT_TYPE_PATH_MIG) | \
66 (1ull << MLX5_EVENT_TYPE_COMM_EST) | \
67 (1ull << MLX5_EVENT_TYPE_SQ_DRAINED) | \
68 (1ull << MLX5_EVENT_TYPE_CQ_ERROR) | \
69 (1ull << MLX5_EVENT_TYPE_WQ_CATAS_ERROR) | \
70 (1ull << MLX5_EVENT_TYPE_PATH_MIG_FAILED) | \
71 (1ull << MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR) | \
72 (1ull << MLX5_EVENT_TYPE_WQ_ACCESS_ERROR) | \
73 (1ull << MLX5_EVENT_TYPE_PORT_CHANGE) | \
74 (1ull << MLX5_EVENT_TYPE_SRQ_CATAS_ERROR) | \
75 (1ull << MLX5_EVENT_TYPE_SRQ_LAST_WQE) | \
76 (1ull << MLX5_EVENT_TYPE_SRQ_RQ_LIMIT))
89 static int mlx5_cmd_destroy_eq(struct mlx5_core_dev *dev, u8 eqn)
91 u32 out[MLX5_ST_SZ_DW(destroy_eq_out)] = {0};
92 u32 in[MLX5_ST_SZ_DW(destroy_eq_in)] = {0};
94 MLX5_SET(destroy_eq_in, in, opcode, MLX5_CMD_OP_DESTROY_EQ);
95 MLX5_SET(destroy_eq_in, in, eq_number, eqn);
96 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
99 static struct mlx5_eqe *get_eqe(struct mlx5_eq *eq, u32 entry)
101 return mlx5_buf_offset(&eq->buf, entry * MLX5_EQE_SIZE);
104 static struct mlx5_eqe *next_eqe_sw(struct mlx5_eq *eq)
106 struct mlx5_eqe *eqe = get_eqe(eq, eq->cons_index & (eq->nent - 1));
108 return ((eqe->owner & 1) ^ !!(eq->cons_index & eq->nent)) ? NULL : eqe;
111 static const char *eqe_type_str(u8 type)
114 case MLX5_EVENT_TYPE_COMP:
115 return "MLX5_EVENT_TYPE_COMP";
116 case MLX5_EVENT_TYPE_PATH_MIG:
117 return "MLX5_EVENT_TYPE_PATH_MIG";
118 case MLX5_EVENT_TYPE_COMM_EST:
119 return "MLX5_EVENT_TYPE_COMM_EST";
120 case MLX5_EVENT_TYPE_SQ_DRAINED:
121 return "MLX5_EVENT_TYPE_SQ_DRAINED";
122 case MLX5_EVENT_TYPE_SRQ_LAST_WQE:
123 return "MLX5_EVENT_TYPE_SRQ_LAST_WQE";
124 case MLX5_EVENT_TYPE_SRQ_RQ_LIMIT:
125 return "MLX5_EVENT_TYPE_SRQ_RQ_LIMIT";
126 case MLX5_EVENT_TYPE_CQ_ERROR:
127 return "MLX5_EVENT_TYPE_CQ_ERROR";
128 case MLX5_EVENT_TYPE_WQ_CATAS_ERROR:
129 return "MLX5_EVENT_TYPE_WQ_CATAS_ERROR";
130 case MLX5_EVENT_TYPE_PATH_MIG_FAILED:
131 return "MLX5_EVENT_TYPE_PATH_MIG_FAILED";
132 case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
133 return "MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR";
134 case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR:
135 return "MLX5_EVENT_TYPE_WQ_ACCESS_ERROR";
136 case MLX5_EVENT_TYPE_SRQ_CATAS_ERROR:
137 return "MLX5_EVENT_TYPE_SRQ_CATAS_ERROR";
138 case MLX5_EVENT_TYPE_INTERNAL_ERROR:
139 return "MLX5_EVENT_TYPE_INTERNAL_ERROR";
140 case MLX5_EVENT_TYPE_PORT_CHANGE:
141 return "MLX5_EVENT_TYPE_PORT_CHANGE";
142 case MLX5_EVENT_TYPE_GPIO_EVENT:
143 return "MLX5_EVENT_TYPE_GPIO_EVENT";
144 case MLX5_EVENT_TYPE_PORT_MODULE_EVENT:
145 return "MLX5_EVENT_TYPE_PORT_MODULE_EVENT";
146 case MLX5_EVENT_TYPE_REMOTE_CONFIG:
147 return "MLX5_EVENT_TYPE_REMOTE_CONFIG";
148 case MLX5_EVENT_TYPE_DB_BF_CONGESTION:
149 return "MLX5_EVENT_TYPE_DB_BF_CONGESTION";
150 case MLX5_EVENT_TYPE_STALL_EVENT:
151 return "MLX5_EVENT_TYPE_STALL_EVENT";
152 case MLX5_EVENT_TYPE_CMD:
153 return "MLX5_EVENT_TYPE_CMD";
154 case MLX5_EVENT_TYPE_PAGE_REQUEST:
155 return "MLX5_EVENT_TYPE_PAGE_REQUEST";
156 case MLX5_EVENT_TYPE_PAGE_FAULT:
157 return "MLX5_EVENT_TYPE_PAGE_FAULT";
158 case MLX5_EVENT_TYPE_PPS_EVENT:
159 return "MLX5_EVENT_TYPE_PPS_EVENT";
160 case MLX5_EVENT_TYPE_NIC_VPORT_CHANGE:
161 return "MLX5_EVENT_TYPE_NIC_VPORT_CHANGE";
162 case MLX5_EVENT_TYPE_FPGA_ERROR:
163 return "MLX5_EVENT_TYPE_FPGA_ERROR";
164 case MLX5_EVENT_TYPE_GENERAL_EVENT:
165 return "MLX5_EVENT_TYPE_GENERAL_EVENT";
167 return "Unrecognized event";
171 static enum mlx5_dev_event port_subtype_event(u8 subtype)
174 case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
175 return MLX5_DEV_EVENT_PORT_DOWN;
176 case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
177 return MLX5_DEV_EVENT_PORT_UP;
178 case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED:
179 return MLX5_DEV_EVENT_PORT_INITIALIZED;
180 case MLX5_PORT_CHANGE_SUBTYPE_LID:
181 return MLX5_DEV_EVENT_LID_CHANGE;
182 case MLX5_PORT_CHANGE_SUBTYPE_PKEY:
183 return MLX5_DEV_EVENT_PKEY_CHANGE;
184 case MLX5_PORT_CHANGE_SUBTYPE_GUID:
185 return MLX5_DEV_EVENT_GUID_CHANGE;
186 case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG:
187 return MLX5_DEV_EVENT_CLIENT_REREG;
192 static void eq_update_ci(struct mlx5_eq *eq, int arm)
194 __be32 __iomem *addr = eq->doorbell + (arm ? 0 : 2);
195 u32 val = (eq->cons_index & 0xffffff) | (eq->eqn << 24);
196 __raw_writel((__force u32)cpu_to_be32(val), addr);
197 /* We still want ordering, just not swabbing, so add a barrier */
201 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
202 static void eqe_pf_action(struct work_struct *work)
204 struct mlx5_pagefault *pfault = container_of(work,
205 struct mlx5_pagefault,
207 struct mlx5_eq *eq = pfault->eq;
209 mlx5_core_page_fault(eq->dev, pfault);
210 mempool_free(pfault, eq->pf_ctx.pool);
213 static void eq_pf_process(struct mlx5_eq *eq)
215 struct mlx5_core_dev *dev = eq->dev;
216 struct mlx5_eqe_page_fault *pf_eqe;
217 struct mlx5_pagefault *pfault;
218 struct mlx5_eqe *eqe;
221 while ((eqe = next_eqe_sw(eq))) {
222 pfault = mempool_alloc(eq->pf_ctx.pool, GFP_ATOMIC);
224 schedule_work(&eq->pf_ctx.work);
229 pf_eqe = &eqe->data.page_fault;
230 pfault->event_subtype = eqe->sub_type;
231 pfault->bytes_committed = be32_to_cpu(pf_eqe->bytes_committed);
234 "PAGE_FAULT: subtype: 0x%02x, bytes_committed: 0x%06x\n",
235 eqe->sub_type, pfault->bytes_committed);
237 switch (eqe->sub_type) {
238 case MLX5_PFAULT_SUBTYPE_RDMA:
239 /* RDMA based event */
241 be32_to_cpu(pf_eqe->rdma.pftype_token) >> 24;
243 be32_to_cpu(pf_eqe->rdma.pftype_token) &
246 be32_to_cpu(pf_eqe->rdma.r_key);
247 pfault->rdma.packet_size =
248 be16_to_cpu(pf_eqe->rdma.packet_length);
249 pfault->rdma.rdma_op_len =
250 be32_to_cpu(pf_eqe->rdma.rdma_op_len);
251 pfault->rdma.rdma_va =
252 be64_to_cpu(pf_eqe->rdma.rdma_va);
254 "PAGE_FAULT: type:0x%x, token: 0x%06x, r_key: 0x%08x\n",
255 pfault->type, pfault->token,
258 "PAGE_FAULT: rdma_op_len: 0x%08x, rdma_va: 0x%016llx\n",
259 pfault->rdma.rdma_op_len,
260 pfault->rdma.rdma_va);
263 case MLX5_PFAULT_SUBTYPE_WQE:
264 /* WQE based event */
266 be32_to_cpu(pf_eqe->wqe.pftype_wq) >> 24;
268 be32_to_cpu(pf_eqe->wqe.token);
270 be32_to_cpu(pf_eqe->wqe.pftype_wq) &
272 pfault->wqe.wqe_index =
273 be16_to_cpu(pf_eqe->wqe.wqe_index);
274 pfault->wqe.packet_size =
275 be16_to_cpu(pf_eqe->wqe.packet_length);
277 "PAGE_FAULT: type:0x%x, token: 0x%06x, wq_num: 0x%06x, wqe_index: 0x%04x\n",
278 pfault->type, pfault->token,
280 pfault->wqe.wqe_index);
285 "Unsupported page fault event sub-type: 0x%02hhx\n",
287 /* Unsupported page faults should still be
288 * resolved by the page fault handler
293 INIT_WORK(&pfault->work, eqe_pf_action);
294 queue_work(eq->pf_ctx.wq, &pfault->work);
299 if (unlikely(set_ci >= MLX5_NUM_SPARE_EQE)) {
308 static irqreturn_t mlx5_eq_pf_int(int irq, void *eq_ptr)
310 struct mlx5_eq *eq = eq_ptr;
313 if (spin_trylock_irqsave(&eq->pf_ctx.lock, flags)) {
315 spin_unlock_irqrestore(&eq->pf_ctx.lock, flags);
317 schedule_work(&eq->pf_ctx.work);
323 /* mempool_refill() was proposed but unfortunately wasn't accepted
324 * http://lkml.iu.edu/hypermail/linux/kernel/1512.1/05073.html
327 static void mempool_refill(mempool_t *pool)
329 while (pool->curr_nr < pool->min_nr)
330 mempool_free(mempool_alloc(pool, GFP_KERNEL), pool);
333 static void eq_pf_action(struct work_struct *work)
335 struct mlx5_eq *eq = container_of(work, struct mlx5_eq, pf_ctx.work);
337 mempool_refill(eq->pf_ctx.pool);
339 spin_lock_irq(&eq->pf_ctx.lock);
341 spin_unlock_irq(&eq->pf_ctx.lock);
344 static int init_pf_ctx(struct mlx5_eq_pagefault *pf_ctx, const char *name)
346 spin_lock_init(&pf_ctx->lock);
347 INIT_WORK(&pf_ctx->work, eq_pf_action);
349 pf_ctx->wq = alloc_ordered_workqueue(name,
354 pf_ctx->pool = mempool_create_kmalloc_pool
355 (MLX5_NUM_PF_DRAIN, sizeof(struct mlx5_pagefault));
361 destroy_workqueue(pf_ctx->wq);
365 int mlx5_core_page_fault_resume(struct mlx5_core_dev *dev, u32 token,
366 u32 wq_num, u8 type, int error)
368 u32 out[MLX5_ST_SZ_DW(page_fault_resume_out)] = {0};
369 u32 in[MLX5_ST_SZ_DW(page_fault_resume_in)] = {0};
371 MLX5_SET(page_fault_resume_in, in, opcode,
372 MLX5_CMD_OP_PAGE_FAULT_RESUME);
373 MLX5_SET(page_fault_resume_in, in, error, !!error);
374 MLX5_SET(page_fault_resume_in, in, page_fault_type, type);
375 MLX5_SET(page_fault_resume_in, in, wq_number, wq_num);
376 MLX5_SET(page_fault_resume_in, in, token, token);
378 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
380 EXPORT_SYMBOL_GPL(mlx5_core_page_fault_resume);
383 static void general_event_handler(struct mlx5_core_dev *dev,
384 struct mlx5_eqe *eqe)
386 switch (eqe->sub_type) {
387 case MLX5_GENERAL_SUBTYPE_DELAY_DROP_TIMEOUT:
389 dev->event(dev, MLX5_DEV_EVENT_DELAY_DROP_TIMEOUT, 0);
392 mlx5_core_dbg(dev, "General event with unrecognized subtype: sub_type %d\n",
397 static irqreturn_t mlx5_eq_int(int irq, void *eq_ptr)
399 struct mlx5_eq *eq = eq_ptr;
400 struct mlx5_core_dev *dev = eq->dev;
401 struct mlx5_eqe *eqe;
407 while ((eqe = next_eqe_sw(eq))) {
409 * Make sure we read EQ entry contents after we've
410 * checked the ownership bit.
414 mlx5_core_dbg(eq->dev, "eqn %d, eqe type %s\n",
415 eq->eqn, eqe_type_str(eqe->type));
417 case MLX5_EVENT_TYPE_COMP:
418 cqn = be32_to_cpu(eqe->data.comp.cqn) & 0xffffff;
419 mlx5_cq_completion(dev, cqn);
422 case MLX5_EVENT_TYPE_PATH_MIG:
423 case MLX5_EVENT_TYPE_COMM_EST:
424 case MLX5_EVENT_TYPE_SQ_DRAINED:
425 case MLX5_EVENT_TYPE_SRQ_LAST_WQE:
426 case MLX5_EVENT_TYPE_WQ_CATAS_ERROR:
427 case MLX5_EVENT_TYPE_PATH_MIG_FAILED:
428 case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
429 case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR:
430 rsn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff;
431 rsn |= (eqe->data.qp_srq.type << MLX5_USER_INDEX_LEN);
432 mlx5_core_dbg(dev, "event %s(%d) arrived on resource 0x%x\n",
433 eqe_type_str(eqe->type), eqe->type, rsn);
434 mlx5_rsc_event(dev, rsn, eqe->type);
437 case MLX5_EVENT_TYPE_SRQ_RQ_LIMIT:
438 case MLX5_EVENT_TYPE_SRQ_CATAS_ERROR:
439 rsn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff;
440 mlx5_core_dbg(dev, "SRQ event %s(%d): srqn 0x%x\n",
441 eqe_type_str(eqe->type), eqe->type, rsn);
442 mlx5_srq_event(dev, rsn, eqe->type);
445 case MLX5_EVENT_TYPE_CMD:
446 mlx5_cmd_comp_handler(dev, be32_to_cpu(eqe->data.cmd.vector), false);
449 case MLX5_EVENT_TYPE_PORT_CHANGE:
450 port = (eqe->data.port.port >> 4) & 0xf;
451 switch (eqe->sub_type) {
452 case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
453 case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
454 case MLX5_PORT_CHANGE_SUBTYPE_LID:
455 case MLX5_PORT_CHANGE_SUBTYPE_PKEY:
456 case MLX5_PORT_CHANGE_SUBTYPE_GUID:
457 case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG:
458 case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED:
460 dev->event(dev, port_subtype_event(eqe->sub_type),
461 (unsigned long)port);
464 mlx5_core_warn(dev, "Port event with unrecognized subtype: port %d, sub_type %d\n",
465 port, eqe->sub_type);
468 case MLX5_EVENT_TYPE_CQ_ERROR:
469 cqn = be32_to_cpu(eqe->data.cq_err.cqn) & 0xffffff;
470 mlx5_core_warn(dev, "CQ error on CQN 0x%x, syndrom 0x%x\n",
471 cqn, eqe->data.cq_err.syndrome);
472 mlx5_cq_event(dev, cqn, eqe->type);
475 case MLX5_EVENT_TYPE_PAGE_REQUEST:
477 u16 func_id = be16_to_cpu(eqe->data.req_pages.func_id);
478 s32 npages = be32_to_cpu(eqe->data.req_pages.num_pages);
480 mlx5_core_dbg(dev, "page request for func 0x%x, npages %d\n",
482 mlx5_core_req_pages_handler(dev, func_id, npages);
486 #ifdef CONFIG_MLX5_CORE_EN
487 case MLX5_EVENT_TYPE_NIC_VPORT_CHANGE:
488 mlx5_eswitch_vport_event(dev->priv.eswitch, eqe);
492 case MLX5_EVENT_TYPE_PORT_MODULE_EVENT:
493 mlx5_port_module_event(dev, eqe);
496 case MLX5_EVENT_TYPE_PPS_EVENT:
498 dev->event(dev, MLX5_DEV_EVENT_PPS, (unsigned long)eqe);
501 case MLX5_EVENT_TYPE_FPGA_ERROR:
502 mlx5_fpga_event(dev, eqe->type, &eqe->data.raw);
505 case MLX5_EVENT_TYPE_GENERAL_EVENT:
506 general_event_handler(dev, eqe);
509 mlx5_core_warn(dev, "Unhandled event 0x%x on EQ 0x%x\n",
517 /* The HCA will think the queue has overflowed if we
518 * don't tell it we've been processing events. We
519 * create our EQs with MLX5_NUM_SPARE_EQE extra
520 * entries, so we must update our consumer index at
523 if (unlikely(set_ci >= MLX5_NUM_SPARE_EQE)) {
532 tasklet_schedule(&eq->tasklet_ctx.task);
537 static void init_eq_buf(struct mlx5_eq *eq)
539 struct mlx5_eqe *eqe;
542 for (i = 0; i < eq->nent; i++) {
543 eqe = get_eqe(eq, i);
544 eqe->owner = MLX5_EQE_OWNER_INIT_VAL;
548 int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
549 int nent, u64 mask, const char *name,
550 enum mlx5_eq_type type)
552 u32 out[MLX5_ST_SZ_DW(create_eq_out)] = {0};
553 struct mlx5_priv *priv = &dev->priv;
554 irq_handler_t handler;
562 eq->nent = roundup_pow_of_two(nent + MLX5_NUM_SPARE_EQE);
564 err = mlx5_buf_alloc(dev, eq->nent * MLX5_EQE_SIZE, &eq->buf);
568 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
569 if (type == MLX5_EQ_TYPE_PF)
570 handler = mlx5_eq_pf_int;
573 handler = mlx5_eq_int;
577 inlen = MLX5_ST_SZ_BYTES(create_eq_in) +
578 MLX5_FLD_SZ_BYTES(create_eq_in, pas[0]) * eq->buf.npages;
580 in = kvzalloc(inlen, GFP_KERNEL);
586 pas = (__be64 *)MLX5_ADDR_OF(create_eq_in, in, pas);
587 mlx5_fill_page_array(&eq->buf, pas);
589 MLX5_SET(create_eq_in, in, opcode, MLX5_CMD_OP_CREATE_EQ);
590 MLX5_SET64(create_eq_in, in, event_bitmask, mask);
592 eqc = MLX5_ADDR_OF(create_eq_in, in, eq_context_entry);
593 MLX5_SET(eqc, eqc, log_eq_size, ilog2(eq->nent));
594 MLX5_SET(eqc, eqc, uar_page, priv->uar->index);
595 MLX5_SET(eqc, eqc, intr, vecidx);
596 MLX5_SET(eqc, eqc, log_page_size,
597 eq->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT);
599 err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
603 snprintf(priv->irq_info[vecidx].name, MLX5_MAX_IRQ_NAME, "%s@pci:%s",
604 name, pci_name(dev->pdev));
606 eq->eqn = MLX5_GET(create_eq_out, out, eq_number);
607 eq->irqn = priv->msix_arr[vecidx].vector;
609 eq->doorbell = priv->uar->map + MLX5_EQ_DOORBEL_OFFSET;
610 err = request_irq(eq->irqn, handler, 0,
611 priv->irq_info[vecidx].name, eq);
615 err = mlx5_debug_eq_add(dev, eq);
619 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
620 if (type == MLX5_EQ_TYPE_PF) {
621 err = init_pf_ctx(&eq->pf_ctx, name);
627 INIT_LIST_HEAD(&eq->tasklet_ctx.list);
628 INIT_LIST_HEAD(&eq->tasklet_ctx.process_list);
629 spin_lock_init(&eq->tasklet_ctx.lock);
630 tasklet_init(&eq->tasklet_ctx.task, mlx5_cq_tasklet_cb,
631 (unsigned long)&eq->tasklet_ctx);
634 /* EQs are created in ARMED state
642 free_irq(priv->msix_arr[vecidx].vector, eq);
645 mlx5_cmd_destroy_eq(dev, eq->eqn);
651 mlx5_buf_free(dev, &eq->buf);
654 EXPORT_SYMBOL_GPL(mlx5_create_map_eq);
656 int mlx5_destroy_unmap_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq)
660 mlx5_debug_eq_remove(dev, eq);
661 free_irq(eq->irqn, eq);
662 err = mlx5_cmd_destroy_eq(dev, eq->eqn);
664 mlx5_core_warn(dev, "failed to destroy a previously created eq: eqn %d\n",
666 synchronize_irq(eq->irqn);
668 if (eq->type == MLX5_EQ_TYPE_COMP) {
669 tasklet_disable(&eq->tasklet_ctx.task);
670 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
671 } else if (eq->type == MLX5_EQ_TYPE_PF) {
672 cancel_work_sync(&eq->pf_ctx.work);
673 destroy_workqueue(eq->pf_ctx.wq);
674 mempool_destroy(eq->pf_ctx.pool);
677 mlx5_buf_free(dev, &eq->buf);
681 EXPORT_SYMBOL_GPL(mlx5_destroy_unmap_eq);
683 u32 mlx5_get_msix_vec(struct mlx5_core_dev *dev, int vecidx)
685 return dev->priv.msix_arr[MLX5_EQ_VEC_ASYNC].vector;
688 int mlx5_eq_init(struct mlx5_core_dev *dev)
692 spin_lock_init(&dev->priv.eq_table.lock);
694 err = mlx5_eq_debugfs_init(dev);
699 void mlx5_eq_cleanup(struct mlx5_core_dev *dev)
701 mlx5_eq_debugfs_cleanup(dev);
704 int mlx5_start_eqs(struct mlx5_core_dev *dev)
706 struct mlx5_eq_table *table = &dev->priv.eq_table;
707 u64 async_event_mask = MLX5_ASYNC_EVENT_MASK;
710 if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_ETH &&
711 MLX5_CAP_GEN(dev, vport_group_manager) &&
712 mlx5_core_is_pf(dev))
713 async_event_mask |= (1ull << MLX5_EVENT_TYPE_NIC_VPORT_CHANGE);
715 if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_ETH &&
716 MLX5_CAP_GEN(dev, general_notification_event))
717 async_event_mask |= (1ull << MLX5_EVENT_TYPE_GENERAL_EVENT);
719 if (MLX5_CAP_GEN(dev, port_module_event))
720 async_event_mask |= (1ull << MLX5_EVENT_TYPE_PORT_MODULE_EVENT);
722 mlx5_core_dbg(dev, "port_module_event is not set\n");
724 if (MLX5_CAP_GEN(dev, pps))
725 async_event_mask |= (1ull << MLX5_EVENT_TYPE_PPS_EVENT);
727 if (MLX5_CAP_GEN(dev, fpga))
728 async_event_mask |= (1ull << MLX5_EVENT_TYPE_FPGA_ERROR);
730 err = mlx5_create_map_eq(dev, &table->cmd_eq, MLX5_EQ_VEC_CMD,
731 MLX5_NUM_CMD_EQE, 1ull << MLX5_EVENT_TYPE_CMD,
732 "mlx5_cmd_eq", MLX5_EQ_TYPE_ASYNC);
734 mlx5_core_warn(dev, "failed to create cmd EQ %d\n", err);
738 mlx5_cmd_use_events(dev);
740 err = mlx5_create_map_eq(dev, &table->async_eq, MLX5_EQ_VEC_ASYNC,
741 MLX5_NUM_ASYNC_EQE, async_event_mask,
742 "mlx5_async_eq", MLX5_EQ_TYPE_ASYNC);
744 mlx5_core_warn(dev, "failed to create async EQ %d\n", err);
748 err = mlx5_create_map_eq(dev, &table->pages_eq,
750 /* TODO: sriov max_vf + */ 1,
751 1 << MLX5_EVENT_TYPE_PAGE_REQUEST, "mlx5_pages_eq",
754 mlx5_core_warn(dev, "failed to create pages EQ %d\n", err);
758 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
759 if (MLX5_CAP_GEN(dev, pg)) {
760 err = mlx5_create_map_eq(dev, &table->pfault_eq,
763 1 << MLX5_EVENT_TYPE_PAGE_FAULT,
764 "mlx5_page_fault_eq",
767 mlx5_core_warn(dev, "failed to create page fault EQ %d\n",
775 mlx5_destroy_unmap_eq(dev, &table->pages_eq);
781 mlx5_destroy_unmap_eq(dev, &table->async_eq);
784 mlx5_cmd_use_polling(dev);
785 mlx5_destroy_unmap_eq(dev, &table->cmd_eq);
789 int mlx5_stop_eqs(struct mlx5_core_dev *dev)
791 struct mlx5_eq_table *table = &dev->priv.eq_table;
794 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
795 if (MLX5_CAP_GEN(dev, pg)) {
796 err = mlx5_destroy_unmap_eq(dev, &table->pfault_eq);
802 err = mlx5_destroy_unmap_eq(dev, &table->pages_eq);
806 mlx5_destroy_unmap_eq(dev, &table->async_eq);
807 mlx5_cmd_use_polling(dev);
809 err = mlx5_destroy_unmap_eq(dev, &table->cmd_eq);
811 mlx5_cmd_use_events(dev);
816 int mlx5_core_eq_query(struct mlx5_core_dev *dev, struct mlx5_eq *eq,
817 u32 *out, int outlen)
819 u32 in[MLX5_ST_SZ_DW(query_eq_in)] = {0};
821 MLX5_SET(query_eq_in, in, opcode, MLX5_CMD_OP_QUERY_EQ);
822 MLX5_SET(query_eq_in, in, eq_number, eq->eqn);
823 return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
825 EXPORT_SYMBOL_GPL(mlx5_core_eq_query);