Merge branch 'akpm' (patches from Andrew)
[linux/fpc-iii.git] / drivers / crypto / hisilicon / qm.c
blobb57da5ef8b5ba6bd1359a3248bd7cf50b6330c9d
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 HiSilicon Limited. */
3 #include <asm/page.h>
4 #include <linux/bitmap.h>
5 #include <linux/debugfs.h>
6 #include <linux/dma-mapping.h>
7 #include <linux/io.h>
8 #include <linux/irqreturn.h>
9 #include <linux/log2.h>
10 #include <linux/seq_file.h>
11 #include <linux/slab.h>
12 #include "qm.h"
14 /* eq/aeq irq enable */
15 #define QM_VF_AEQ_INT_SOURCE 0x0
16 #define QM_VF_AEQ_INT_MASK 0x4
17 #define QM_VF_EQ_INT_SOURCE 0x8
18 #define QM_VF_EQ_INT_MASK 0xc
19 #define QM_IRQ_NUM_V1 1
20 #define QM_IRQ_NUM_PF_V2 4
21 #define QM_IRQ_NUM_VF_V2 2
23 #define QM_EQ_EVENT_IRQ_VECTOR 0
24 #define QM_AEQ_EVENT_IRQ_VECTOR 1
25 #define QM_ABNORMAL_EVENT_IRQ_VECTOR 3
27 /* mailbox */
28 #define QM_MB_CMD_SQC 0x0
29 #define QM_MB_CMD_CQC 0x1
30 #define QM_MB_CMD_EQC 0x2
31 #define QM_MB_CMD_AEQC 0x3
32 #define QM_MB_CMD_SQC_BT 0x4
33 #define QM_MB_CMD_CQC_BT 0x5
34 #define QM_MB_CMD_SQC_VFT_V2 0x6
36 #define QM_MB_CMD_SEND_BASE 0x300
37 #define QM_MB_EVENT_SHIFT 8
38 #define QM_MB_BUSY_SHIFT 13
39 #define QM_MB_OP_SHIFT 14
40 #define QM_MB_CMD_DATA_ADDR_L 0x304
41 #define QM_MB_CMD_DATA_ADDR_H 0x308
43 /* sqc shift */
44 #define QM_SQ_HOP_NUM_SHIFT 0
45 #define QM_SQ_PAGE_SIZE_SHIFT 4
46 #define QM_SQ_BUF_SIZE_SHIFT 8
47 #define QM_SQ_SQE_SIZE_SHIFT 12
48 #define QM_SQ_PRIORITY_SHIFT 0
49 #define QM_SQ_ORDERS_SHIFT 4
50 #define QM_SQ_TYPE_SHIFT 8
52 #define QM_SQ_TYPE_MASK GENMASK(3, 0)
54 /* cqc shift */
55 #define QM_CQ_HOP_NUM_SHIFT 0
56 #define QM_CQ_PAGE_SIZE_SHIFT 4
57 #define QM_CQ_BUF_SIZE_SHIFT 8
58 #define QM_CQ_CQE_SIZE_SHIFT 12
59 #define QM_CQ_PHASE_SHIFT 0
60 #define QM_CQ_FLAG_SHIFT 1
62 #define QM_CQE_PHASE(cqe) (le16_to_cpu((cqe)->w7) & 0x1)
63 #define QM_QC_CQE_SIZE 4
65 /* eqc shift */
66 #define QM_EQE_AEQE_SIZE (2UL << 12)
67 #define QM_EQC_PHASE_SHIFT 16
69 #define QM_EQE_PHASE(eqe) ((le32_to_cpu((eqe)->dw0) >> 16) & 0x1)
70 #define QM_EQE_CQN_MASK GENMASK(15, 0)
72 #define QM_AEQE_PHASE(aeqe) ((le32_to_cpu((aeqe)->dw0) >> 16) & 0x1)
73 #define QM_AEQE_TYPE_SHIFT 17
75 #define QM_DOORBELL_CMD_SQ 0
76 #define QM_DOORBELL_CMD_CQ 1
77 #define QM_DOORBELL_CMD_EQ 2
78 #define QM_DOORBELL_CMD_AEQ 3
80 #define QM_DOORBELL_BASE_V1 0x340
81 #define QM_DB_CMD_SHIFT_V1 16
82 #define QM_DB_INDEX_SHIFT_V1 32
83 #define QM_DB_PRIORITY_SHIFT_V1 48
84 #define QM_DOORBELL_SQ_CQ_BASE_V2 0x1000
85 #define QM_DOORBELL_EQ_AEQ_BASE_V2 0x2000
86 #define QM_DB_CMD_SHIFT_V2 12
87 #define QM_DB_RAND_SHIFT_V2 16
88 #define QM_DB_INDEX_SHIFT_V2 32
89 #define QM_DB_PRIORITY_SHIFT_V2 48
91 #define QM_MEM_START_INIT 0x100040
92 #define QM_MEM_INIT_DONE 0x100044
93 #define QM_VFT_CFG_RDY 0x10006c
94 #define QM_VFT_CFG_OP_WR 0x100058
95 #define QM_VFT_CFG_TYPE 0x10005c
96 #define QM_SQC_VFT 0x0
97 #define QM_CQC_VFT 0x1
98 #define QM_VFT_CFG 0x100060
99 #define QM_VFT_CFG_OP_ENABLE 0x100054
101 #define QM_VFT_CFG_DATA_L 0x100064
102 #define QM_VFT_CFG_DATA_H 0x100068
103 #define QM_SQC_VFT_BUF_SIZE (7ULL << 8)
104 #define QM_SQC_VFT_SQC_SIZE (5ULL << 12)
105 #define QM_SQC_VFT_INDEX_NUMBER (1ULL << 16)
106 #define QM_SQC_VFT_START_SQN_SHIFT 28
107 #define QM_SQC_VFT_VALID (1ULL << 44)
108 #define QM_SQC_VFT_SQN_SHIFT 45
109 #define QM_CQC_VFT_BUF_SIZE (7ULL << 8)
110 #define QM_CQC_VFT_SQC_SIZE (5ULL << 12)
111 #define QM_CQC_VFT_INDEX_NUMBER (1ULL << 16)
112 #define QM_CQC_VFT_VALID (1ULL << 28)
114 #define QM_SQC_VFT_BASE_SHIFT_V2 28
115 #define QM_SQC_VFT_BASE_MASK_V2 GENMASK(5, 0)
116 #define QM_SQC_VFT_NUM_SHIFT_V2 45
117 #define QM_SQC_VFT_NUM_MASK_v2 GENMASK(9, 0)
119 #define QM_DFX_CNT_CLR_CE 0x100118
121 #define QM_ABNORMAL_INT_SOURCE 0x100000
122 #define QM_ABNORMAL_INT_MASK 0x100004
123 #define QM_ABNORMAL_INT_MASK_VALUE 0x1fff
124 #define QM_ABNORMAL_INT_STATUS 0x100008
125 #define QM_ABNORMAL_INF00 0x100010
126 #define QM_FIFO_OVERFLOW_TYPE 0xc0
127 #define QM_FIFO_OVERFLOW_TYPE_SHIFT 6
128 #define QM_FIFO_OVERFLOW_VF 0x3f
129 #define QM_ABNORMAL_INF01 0x100014
130 #define QM_DB_TIMEOUT_TYPE 0xc0
131 #define QM_DB_TIMEOUT_TYPE_SHIFT 6
132 #define QM_DB_TIMEOUT_VF 0x3f
133 #define QM_RAS_CE_ENABLE 0x1000ec
134 #define QM_RAS_FE_ENABLE 0x1000f0
135 #define QM_RAS_NFE_ENABLE 0x1000f4
136 #define QM_RAS_CE_THRESHOLD 0x1000f8
137 #define QM_RAS_CE_TIMES_PER_IRQ 1
138 #define QM_RAS_MSI_INT_SEL 0x1040f4
140 #define QM_CACHE_WB_START 0x204
141 #define QM_CACHE_WB_DONE 0x208
143 #define PCI_BAR_2 2
144 #define QM_SQE_DATA_ALIGN_MASK GENMASK(6, 0)
145 #define QMC_ALIGN(sz) ALIGN(sz, 32)
147 #define QM_DBG_TMP_BUF_LEN 22
149 #define QM_MK_CQC_DW3_V1(hop_num, pg_sz, buf_sz, cqe_sz) \
150 (((hop_num) << QM_CQ_HOP_NUM_SHIFT) | \
151 ((pg_sz) << QM_CQ_PAGE_SIZE_SHIFT) | \
152 ((buf_sz) << QM_CQ_BUF_SIZE_SHIFT) | \
153 ((cqe_sz) << QM_CQ_CQE_SIZE_SHIFT))
155 #define QM_MK_CQC_DW3_V2(cqe_sz) \
156 ((QM_Q_DEPTH - 1) | ((cqe_sz) << QM_CQ_CQE_SIZE_SHIFT))
158 #define QM_MK_SQC_W13(priority, orders, alg_type) \
159 (((priority) << QM_SQ_PRIORITY_SHIFT) | \
160 ((orders) << QM_SQ_ORDERS_SHIFT) | \
161 (((alg_type) & QM_SQ_TYPE_MASK) << QM_SQ_TYPE_SHIFT))
163 #define QM_MK_SQC_DW3_V1(hop_num, pg_sz, buf_sz, sqe_sz) \
164 (((hop_num) << QM_SQ_HOP_NUM_SHIFT) | \
165 ((pg_sz) << QM_SQ_PAGE_SIZE_SHIFT) | \
166 ((buf_sz) << QM_SQ_BUF_SIZE_SHIFT) | \
167 ((u32)ilog2(sqe_sz) << QM_SQ_SQE_SIZE_SHIFT))
169 #define QM_MK_SQC_DW3_V2(sqe_sz) \
170 ((QM_Q_DEPTH - 1) | ((u32)ilog2(sqe_sz) << QM_SQ_SQE_SIZE_SHIFT))
172 #define INIT_QC_COMMON(qc, base, pasid) do { \
173 (qc)->head = 0; \
174 (qc)->tail = 0; \
175 (qc)->base_l = cpu_to_le32(lower_32_bits(base)); \
176 (qc)->base_h = cpu_to_le32(upper_32_bits(base)); \
177 (qc)->dw3 = 0; \
178 (qc)->w8 = 0; \
179 (qc)->rsvd0 = 0; \
180 (qc)->pasid = cpu_to_le16(pasid); \
181 (qc)->w11 = 0; \
182 (qc)->rsvd1 = 0; \
183 } while (0)
185 enum vft_type {
186 SQC_VFT = 0,
187 CQC_VFT,
190 struct qm_cqe {
191 __le32 rsvd0;
192 __le16 cmd_id;
193 __le16 rsvd1;
194 __le16 sq_head;
195 __le16 sq_num;
196 __le16 rsvd2;
197 __le16 w7;
200 struct qm_eqe {
201 __le32 dw0;
204 struct qm_aeqe {
205 __le32 dw0;
208 struct qm_sqc {
209 __le16 head;
210 __le16 tail;
211 __le32 base_l;
212 __le32 base_h;
213 __le32 dw3;
214 __le16 w8;
215 __le16 rsvd0;
216 __le16 pasid;
217 __le16 w11;
218 __le16 cq_num;
219 __le16 w13;
220 __le32 rsvd1;
223 struct qm_cqc {
224 __le16 head;
225 __le16 tail;
226 __le32 base_l;
227 __le32 base_h;
228 __le32 dw3;
229 __le16 w8;
230 __le16 rsvd0;
231 __le16 pasid;
232 __le16 w11;
233 __le32 dw6;
234 __le32 rsvd1;
237 struct qm_eqc {
238 __le16 head;
239 __le16 tail;
240 __le32 base_l;
241 __le32 base_h;
242 __le32 dw3;
243 __le32 rsvd[2];
244 __le32 dw6;
247 struct qm_aeqc {
248 __le16 head;
249 __le16 tail;
250 __le32 base_l;
251 __le32 base_h;
252 __le32 dw3;
253 __le32 rsvd[2];
254 __le32 dw6;
257 struct qm_mailbox {
258 __le16 w0;
259 __le16 queue_num;
260 __le32 base_l;
261 __le32 base_h;
262 __le32 rsvd;
265 struct qm_doorbell {
266 __le16 queue_num;
267 __le16 cmd;
268 __le16 index;
269 __le16 priority;
272 struct hisi_qm_hw_ops {
273 int (*get_vft)(struct hisi_qm *qm, u32 *base, u32 *number);
274 void (*qm_db)(struct hisi_qm *qm, u16 qn,
275 u8 cmd, u16 index, u8 priority);
276 u32 (*get_irq_num)(struct hisi_qm *qm);
277 int (*debug_init)(struct hisi_qm *qm);
278 void (*hw_error_init)(struct hisi_qm *qm, u32 ce, u32 nfe, u32 fe,
279 u32 msi);
280 pci_ers_result_t (*hw_error_handle)(struct hisi_qm *qm);
283 static const char * const qm_debug_file_name[] = {
284 [CURRENT_Q] = "current_q",
285 [CLEAR_ENABLE] = "clear_enable",
288 struct hisi_qm_hw_error {
289 u32 int_msk;
290 const char *msg;
293 static const struct hisi_qm_hw_error qm_hw_error[] = {
294 { .int_msk = BIT(0), .msg = "qm_axi_rresp" },
295 { .int_msk = BIT(1), .msg = "qm_axi_bresp" },
296 { .int_msk = BIT(2), .msg = "qm_ecc_mbit" },
297 { .int_msk = BIT(3), .msg = "qm_ecc_1bit" },
298 { .int_msk = BIT(4), .msg = "qm_acc_get_task_timeout" },
299 { .int_msk = BIT(5), .msg = "qm_acc_do_task_timeout" },
300 { .int_msk = BIT(6), .msg = "qm_acc_wb_not_ready_timeout" },
301 { .int_msk = BIT(7), .msg = "qm_sq_cq_vf_invalid" },
302 { .int_msk = BIT(8), .msg = "qm_cq_vf_invalid" },
303 { .int_msk = BIT(9), .msg = "qm_sq_vf_invalid" },
304 { .int_msk = BIT(10), .msg = "qm_db_timeout" },
305 { .int_msk = BIT(11), .msg = "qm_of_fifo_of" },
306 { .int_msk = BIT(12), .msg = "qm_db_random_invalid" },
307 { /* sentinel */ }
310 static const char * const qm_db_timeout[] = {
311 "sq", "cq", "eq", "aeq",
314 static const char * const qm_fifo_overflow[] = {
315 "cq", "eq", "aeq",
318 /* return 0 mailbox ready, -ETIMEDOUT hardware timeout */
319 static int qm_wait_mb_ready(struct hisi_qm *qm)
321 u32 val;
323 return readl_relaxed_poll_timeout(qm->io_base + QM_MB_CMD_SEND_BASE,
324 val, !((val >> QM_MB_BUSY_SHIFT) &
325 0x1), 10, 1000);
328 /* 128 bit should be written to hardware at one time to trigger a mailbox */
329 static void qm_mb_write(struct hisi_qm *qm, const void *src)
331 void __iomem *fun_base = qm->io_base + QM_MB_CMD_SEND_BASE;
332 unsigned long tmp0 = 0, tmp1 = 0;
334 if (!IS_ENABLED(CONFIG_ARM64)) {
335 memcpy_toio(fun_base, src, 16);
336 wmb();
337 return;
340 asm volatile("ldp %0, %1, %3\n"
341 "stp %0, %1, %2\n"
342 "dsb sy\n"
343 : "=&r" (tmp0),
344 "=&r" (tmp1),
345 "+Q" (*((char __iomem *)fun_base))
346 : "Q" (*((char *)src))
347 : "memory");
350 static int qm_mb(struct hisi_qm *qm, u8 cmd, dma_addr_t dma_addr, u16 queue,
351 bool op)
353 struct qm_mailbox mailbox;
354 int ret = 0;
356 dev_dbg(&qm->pdev->dev, "QM mailbox request to q%u: %u-%llx\n",
357 queue, cmd, (unsigned long long)dma_addr);
359 mailbox.w0 = cpu_to_le16(cmd |
360 (op ? 0x1 << QM_MB_OP_SHIFT : 0) |
361 (0x1 << QM_MB_BUSY_SHIFT));
362 mailbox.queue_num = cpu_to_le16(queue);
363 mailbox.base_l = cpu_to_le32(lower_32_bits(dma_addr));
364 mailbox.base_h = cpu_to_le32(upper_32_bits(dma_addr));
365 mailbox.rsvd = 0;
367 mutex_lock(&qm->mailbox_lock);
369 if (unlikely(qm_wait_mb_ready(qm))) {
370 ret = -EBUSY;
371 dev_err(&qm->pdev->dev, "QM mailbox is busy to start!\n");
372 goto busy_unlock;
375 qm_mb_write(qm, &mailbox);
377 if (unlikely(qm_wait_mb_ready(qm))) {
378 ret = -EBUSY;
379 dev_err(&qm->pdev->dev, "QM mailbox operation timeout!\n");
380 goto busy_unlock;
383 busy_unlock:
384 mutex_unlock(&qm->mailbox_lock);
386 return ret;
389 static void qm_db_v1(struct hisi_qm *qm, u16 qn, u8 cmd, u16 index, u8 priority)
391 u64 doorbell;
393 doorbell = qn | ((u64)cmd << QM_DB_CMD_SHIFT_V1) |
394 ((u64)index << QM_DB_INDEX_SHIFT_V1) |
395 ((u64)priority << QM_DB_PRIORITY_SHIFT_V1);
397 writeq(doorbell, qm->io_base + QM_DOORBELL_BASE_V1);
400 static void qm_db_v2(struct hisi_qm *qm, u16 qn, u8 cmd, u16 index, u8 priority)
402 u64 doorbell;
403 u64 dbase;
404 u16 randata = 0;
406 if (cmd == QM_DOORBELL_CMD_SQ || cmd == QM_DOORBELL_CMD_CQ)
407 dbase = QM_DOORBELL_SQ_CQ_BASE_V2;
408 else
409 dbase = QM_DOORBELL_EQ_AEQ_BASE_V2;
411 doorbell = qn | ((u64)cmd << QM_DB_CMD_SHIFT_V2) |
412 ((u64)randata << QM_DB_RAND_SHIFT_V2) |
413 ((u64)index << QM_DB_INDEX_SHIFT_V2) |
414 ((u64)priority << QM_DB_PRIORITY_SHIFT_V2);
416 writeq(doorbell, qm->io_base + dbase);
419 static void qm_db(struct hisi_qm *qm, u16 qn, u8 cmd, u16 index, u8 priority)
421 dev_dbg(&qm->pdev->dev, "QM doorbell request: qn=%u, cmd=%u, index=%u\n",
422 qn, cmd, index);
424 qm->ops->qm_db(qm, qn, cmd, index, priority);
427 static int qm_dev_mem_reset(struct hisi_qm *qm)
429 u32 val;
431 writel(0x1, qm->io_base + QM_MEM_START_INIT);
432 return readl_relaxed_poll_timeout(qm->io_base + QM_MEM_INIT_DONE, val,
433 val & BIT(0), 10, 1000);
436 static u32 qm_get_irq_num_v1(struct hisi_qm *qm)
438 return QM_IRQ_NUM_V1;
441 static u32 qm_get_irq_num_v2(struct hisi_qm *qm)
443 if (qm->fun_type == QM_HW_PF)
444 return QM_IRQ_NUM_PF_V2;
445 else
446 return QM_IRQ_NUM_VF_V2;
449 static struct hisi_qp *qm_to_hisi_qp(struct hisi_qm *qm, struct qm_eqe *eqe)
451 u16 cqn = le32_to_cpu(eqe->dw0) & QM_EQE_CQN_MASK;
453 return qm->qp_array[cqn];
456 static void qm_cq_head_update(struct hisi_qp *qp)
458 if (qp->qp_status.cq_head == QM_Q_DEPTH - 1) {
459 qp->qp_status.cqc_phase = !qp->qp_status.cqc_phase;
460 qp->qp_status.cq_head = 0;
461 } else {
462 qp->qp_status.cq_head++;
466 static void qm_poll_qp(struct hisi_qp *qp, struct hisi_qm *qm)
468 struct qm_cqe *cqe = qp->cqe + qp->qp_status.cq_head;
470 if (qp->req_cb) {
471 while (QM_CQE_PHASE(cqe) == qp->qp_status.cqc_phase) {
472 dma_rmb();
473 qp->req_cb(qp, qp->sqe + qm->sqe_size *
474 le16_to_cpu(cqe->sq_head));
475 qm_cq_head_update(qp);
476 cqe = qp->cqe + qp->qp_status.cq_head;
477 qm_db(qm, qp->qp_id, QM_DOORBELL_CMD_CQ,
478 qp->qp_status.cq_head, 0);
479 atomic_dec(&qp->qp_status.used);
482 /* set c_flag */
483 qm_db(qm, qp->qp_id, QM_DOORBELL_CMD_CQ,
484 qp->qp_status.cq_head, 1);
488 static void qm_qp_work_func(struct work_struct *work)
490 struct hisi_qp *qp;
492 qp = container_of(work, struct hisi_qp, work);
493 qm_poll_qp(qp, qp->qm);
496 static irqreturn_t qm_irq_handler(int irq, void *data)
498 struct hisi_qm *qm = data;
499 struct qm_eqe *eqe = qm->eqe + qm->status.eq_head;
500 struct hisi_qp *qp;
501 int eqe_num = 0;
503 while (QM_EQE_PHASE(eqe) == qm->status.eqc_phase) {
504 eqe_num++;
505 qp = qm_to_hisi_qp(qm, eqe);
506 if (qp)
507 queue_work(qp->wq, &qp->work);
509 if (qm->status.eq_head == QM_Q_DEPTH - 1) {
510 qm->status.eqc_phase = !qm->status.eqc_phase;
511 eqe = qm->eqe;
512 qm->status.eq_head = 0;
513 } else {
514 eqe++;
515 qm->status.eq_head++;
518 if (eqe_num == QM_Q_DEPTH / 2 - 1) {
519 eqe_num = 0;
520 qm_db(qm, 0, QM_DOORBELL_CMD_EQ, qm->status.eq_head, 0);
524 qm_db(qm, 0, QM_DOORBELL_CMD_EQ, qm->status.eq_head, 0);
526 return IRQ_HANDLED;
529 static irqreturn_t qm_irq(int irq, void *data)
531 struct hisi_qm *qm = data;
533 if (readl(qm->io_base + QM_VF_EQ_INT_SOURCE))
534 return qm_irq_handler(irq, data);
536 dev_err(&qm->pdev->dev, "invalid int source\n");
537 qm_db(qm, 0, QM_DOORBELL_CMD_EQ, qm->status.eq_head, 0);
539 return IRQ_NONE;
542 static irqreturn_t qm_aeq_irq(int irq, void *data)
544 struct hisi_qm *qm = data;
545 struct qm_aeqe *aeqe = qm->aeqe + qm->status.aeq_head;
546 u32 type;
548 if (!readl(qm->io_base + QM_VF_AEQ_INT_SOURCE))
549 return IRQ_NONE;
551 while (QM_AEQE_PHASE(aeqe) == qm->status.aeqc_phase) {
552 type = le32_to_cpu(aeqe->dw0) >> QM_AEQE_TYPE_SHIFT;
553 if (type < ARRAY_SIZE(qm_fifo_overflow))
554 dev_err(&qm->pdev->dev, "%s overflow\n",
555 qm_fifo_overflow[type]);
556 else
557 dev_err(&qm->pdev->dev, "unknown error type %d\n",
558 type);
560 if (qm->status.aeq_head == QM_Q_DEPTH - 1) {
561 qm->status.aeqc_phase = !qm->status.aeqc_phase;
562 aeqe = qm->aeqe;
563 qm->status.aeq_head = 0;
564 } else {
565 aeqe++;
566 qm->status.aeq_head++;
569 qm_db(qm, 0, QM_DOORBELL_CMD_AEQ, qm->status.aeq_head, 0);
572 return IRQ_HANDLED;
575 static irqreturn_t qm_abnormal_irq(int irq, void *data)
577 const struct hisi_qm_hw_error *err = qm_hw_error;
578 struct hisi_qm *qm = data;
579 struct device *dev = &qm->pdev->dev;
580 u32 error_status, tmp;
582 /* read err sts */
583 tmp = readl(qm->io_base + QM_ABNORMAL_INT_STATUS);
584 error_status = qm->msi_mask & tmp;
586 while (err->msg) {
587 if (err->int_msk & error_status)
588 dev_err(dev, "%s [error status=0x%x] found\n",
589 err->msg, err->int_msk);
591 err++;
594 /* clear err sts */
595 writel(error_status, qm->io_base + QM_ABNORMAL_INT_SOURCE);
597 return IRQ_HANDLED;
600 static int qm_irq_register(struct hisi_qm *qm)
602 struct pci_dev *pdev = qm->pdev;
603 int ret;
605 ret = request_irq(pci_irq_vector(pdev, QM_EQ_EVENT_IRQ_VECTOR),
606 qm_irq, IRQF_SHARED, qm->dev_name, qm);
607 if (ret)
608 return ret;
610 if (qm->ver == QM_HW_V2) {
611 ret = request_irq(pci_irq_vector(pdev, QM_AEQ_EVENT_IRQ_VECTOR),
612 qm_aeq_irq, IRQF_SHARED, qm->dev_name, qm);
613 if (ret)
614 goto err_aeq_irq;
616 if (qm->fun_type == QM_HW_PF) {
617 ret = request_irq(pci_irq_vector(pdev,
618 QM_ABNORMAL_EVENT_IRQ_VECTOR),
619 qm_abnormal_irq, IRQF_SHARED,
620 qm->dev_name, qm);
621 if (ret)
622 goto err_abonormal_irq;
626 return 0;
628 err_abonormal_irq:
629 free_irq(pci_irq_vector(pdev, QM_AEQ_EVENT_IRQ_VECTOR), qm);
630 err_aeq_irq:
631 free_irq(pci_irq_vector(pdev, QM_EQ_EVENT_IRQ_VECTOR), qm);
632 return ret;
635 static void qm_irq_unregister(struct hisi_qm *qm)
637 struct pci_dev *pdev = qm->pdev;
639 free_irq(pci_irq_vector(pdev, QM_EQ_EVENT_IRQ_VECTOR), qm);
641 if (qm->ver == QM_HW_V2) {
642 free_irq(pci_irq_vector(pdev, QM_AEQ_EVENT_IRQ_VECTOR), qm);
644 if (qm->fun_type == QM_HW_PF)
645 free_irq(pci_irq_vector(pdev,
646 QM_ABNORMAL_EVENT_IRQ_VECTOR), qm);
650 static void qm_init_qp_status(struct hisi_qp *qp)
652 struct hisi_qp_status *qp_status = &qp->qp_status;
654 qp_status->sq_tail = 0;
655 qp_status->cq_head = 0;
656 qp_status->cqc_phase = true;
657 qp_status->flags = 0;
660 static void qm_vft_data_cfg(struct hisi_qm *qm, enum vft_type type, u32 base,
661 u32 number)
663 u64 tmp = 0;
665 if (number > 0) {
666 switch (type) {
667 case SQC_VFT:
668 switch (qm->ver) {
669 case QM_HW_V1:
670 tmp = QM_SQC_VFT_BUF_SIZE |
671 QM_SQC_VFT_SQC_SIZE |
672 QM_SQC_VFT_INDEX_NUMBER |
673 QM_SQC_VFT_VALID |
674 (u64)base << QM_SQC_VFT_START_SQN_SHIFT;
675 break;
676 case QM_HW_V2:
677 tmp = (u64)base << QM_SQC_VFT_START_SQN_SHIFT |
678 QM_SQC_VFT_VALID |
679 (u64)(number - 1) << QM_SQC_VFT_SQN_SHIFT;
680 break;
681 case QM_HW_UNKNOWN:
682 break;
684 break;
685 case CQC_VFT:
686 switch (qm->ver) {
687 case QM_HW_V1:
688 tmp = QM_CQC_VFT_BUF_SIZE |
689 QM_CQC_VFT_SQC_SIZE |
690 QM_CQC_VFT_INDEX_NUMBER |
691 QM_CQC_VFT_VALID;
692 break;
693 case QM_HW_V2:
694 tmp = QM_CQC_VFT_VALID;
695 break;
696 case QM_HW_UNKNOWN:
697 break;
699 break;
703 writel(lower_32_bits(tmp), qm->io_base + QM_VFT_CFG_DATA_L);
704 writel(upper_32_bits(tmp), qm->io_base + QM_VFT_CFG_DATA_H);
707 static int qm_set_vft_common(struct hisi_qm *qm, enum vft_type type,
708 u32 fun_num, u32 base, u32 number)
710 unsigned int val;
711 int ret;
713 ret = readl_relaxed_poll_timeout(qm->io_base + QM_VFT_CFG_RDY, val,
714 val & BIT(0), 10, 1000);
715 if (ret)
716 return ret;
718 writel(0x0, qm->io_base + QM_VFT_CFG_OP_WR);
719 writel(type, qm->io_base + QM_VFT_CFG_TYPE);
720 writel(fun_num, qm->io_base + QM_VFT_CFG);
722 qm_vft_data_cfg(qm, type, base, number);
724 writel(0x0, qm->io_base + QM_VFT_CFG_RDY);
725 writel(0x1, qm->io_base + QM_VFT_CFG_OP_ENABLE);
727 return readl_relaxed_poll_timeout(qm->io_base + QM_VFT_CFG_RDY, val,
728 val & BIT(0), 10, 1000);
731 /* The config should be conducted after qm_dev_mem_reset() */
732 static int qm_set_sqc_cqc_vft(struct hisi_qm *qm, u32 fun_num, u32 base,
733 u32 number)
735 int ret, i;
737 for (i = SQC_VFT; i <= CQC_VFT; i++) {
738 ret = qm_set_vft_common(qm, i, fun_num, base, number);
739 if (ret)
740 return ret;
743 return 0;
746 static int qm_get_vft_v2(struct hisi_qm *qm, u32 *base, u32 *number)
748 u64 sqc_vft;
749 int ret;
751 ret = qm_mb(qm, QM_MB_CMD_SQC_VFT_V2, 0, 0, 1);
752 if (ret)
753 return ret;
755 sqc_vft = readl(qm->io_base + QM_MB_CMD_DATA_ADDR_L) |
756 ((u64)readl(qm->io_base + QM_MB_CMD_DATA_ADDR_H) << 32);
757 *base = QM_SQC_VFT_BASE_MASK_V2 & (sqc_vft >> QM_SQC_VFT_BASE_SHIFT_V2);
758 *number = (QM_SQC_VFT_NUM_MASK_v2 &
759 (sqc_vft >> QM_SQC_VFT_NUM_SHIFT_V2)) + 1;
761 return 0;
764 static struct hisi_qm *file_to_qm(struct debugfs_file *file)
766 struct qm_debug *debug = file->debug;
768 return container_of(debug, struct hisi_qm, debug);
771 static u32 current_q_read(struct debugfs_file *file)
773 struct hisi_qm *qm = file_to_qm(file);
775 return readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) >> QM_DFX_QN_SHIFT;
778 static int current_q_write(struct debugfs_file *file, u32 val)
780 struct hisi_qm *qm = file_to_qm(file);
781 u32 tmp;
783 if (val >= qm->debug.curr_qm_qp_num)
784 return -EINVAL;
786 tmp = val << QM_DFX_QN_SHIFT |
787 (readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) & CURRENT_FUN_MASK);
788 writel(tmp, qm->io_base + QM_DFX_SQE_CNT_VF_SQN);
790 tmp = val << QM_DFX_QN_SHIFT |
791 (readl(qm->io_base + QM_DFX_CQE_CNT_VF_CQN) & CURRENT_FUN_MASK);
792 writel(tmp, qm->io_base + QM_DFX_CQE_CNT_VF_CQN);
794 return 0;
797 static u32 clear_enable_read(struct debugfs_file *file)
799 struct hisi_qm *qm = file_to_qm(file);
801 return readl(qm->io_base + QM_DFX_CNT_CLR_CE);
804 /* rd_clr_ctrl 1 enable read clear, otherwise 0 disable it */
805 static int clear_enable_write(struct debugfs_file *file, u32 rd_clr_ctrl)
807 struct hisi_qm *qm = file_to_qm(file);
809 if (rd_clr_ctrl > 1)
810 return -EINVAL;
812 writel(rd_clr_ctrl, qm->io_base + QM_DFX_CNT_CLR_CE);
814 return 0;
817 static ssize_t qm_debug_read(struct file *filp, char __user *buf,
818 size_t count, loff_t *pos)
820 struct debugfs_file *file = filp->private_data;
821 enum qm_debug_file index = file->index;
822 char tbuf[QM_DBG_TMP_BUF_LEN];
823 u32 val;
824 int ret;
826 mutex_lock(&file->lock);
827 switch (index) {
828 case CURRENT_Q:
829 val = current_q_read(file);
830 break;
831 case CLEAR_ENABLE:
832 val = clear_enable_read(file);
833 break;
834 default:
835 mutex_unlock(&file->lock);
836 return -EINVAL;
838 mutex_unlock(&file->lock);
839 ret = sprintf(tbuf, "%u\n", val);
840 return simple_read_from_buffer(buf, count, pos, tbuf, ret);
843 static ssize_t qm_debug_write(struct file *filp, const char __user *buf,
844 size_t count, loff_t *pos)
846 struct debugfs_file *file = filp->private_data;
847 enum qm_debug_file index = file->index;
848 unsigned long val;
849 char tbuf[QM_DBG_TMP_BUF_LEN];
850 int len, ret;
852 if (*pos != 0)
853 return 0;
855 if (count >= QM_DBG_TMP_BUF_LEN)
856 return -ENOSPC;
858 len = simple_write_to_buffer(tbuf, QM_DBG_TMP_BUF_LEN - 1, pos, buf,
859 count);
860 if (len < 0)
861 return len;
863 tbuf[len] = '\0';
864 if (kstrtoul(tbuf, 0, &val))
865 return -EFAULT;
867 mutex_lock(&file->lock);
868 switch (index) {
869 case CURRENT_Q:
870 ret = current_q_write(file, val);
871 if (ret)
872 goto err_input;
873 break;
874 case CLEAR_ENABLE:
875 ret = clear_enable_write(file, val);
876 if (ret)
877 goto err_input;
878 break;
879 default:
880 ret = -EINVAL;
881 goto err_input;
883 mutex_unlock(&file->lock);
885 return count;
887 err_input:
888 mutex_unlock(&file->lock);
889 return ret;
892 static const struct file_operations qm_debug_fops = {
893 .owner = THIS_MODULE,
894 .open = simple_open,
895 .read = qm_debug_read,
896 .write = qm_debug_write,
899 struct qm_dfx_registers {
900 char *reg_name;
901 u64 reg_offset;
904 #define CNT_CYC_REGS_NUM 10
905 static struct qm_dfx_registers qm_dfx_regs[] = {
906 /* XXX_CNT are reading clear register */
907 {"QM_ECC_1BIT_CNT ", 0x104000ull},
908 {"QM_ECC_MBIT_CNT ", 0x104008ull},
909 {"QM_DFX_MB_CNT ", 0x104018ull},
910 {"QM_DFX_DB_CNT ", 0x104028ull},
911 {"QM_DFX_SQE_CNT ", 0x104038ull},
912 {"QM_DFX_CQE_CNT ", 0x104048ull},
913 {"QM_DFX_SEND_SQE_TO_ACC_CNT ", 0x104050ull},
914 {"QM_DFX_WB_SQE_FROM_ACC_CNT ", 0x104058ull},
915 {"QM_DFX_ACC_FINISH_CNT ", 0x104060ull},
916 {"QM_DFX_CQE_ERR_CNT ", 0x1040b4ull},
917 {"QM_DFX_FUNS_ACTIVE_ST ", 0x200ull},
918 {"QM_ECC_1BIT_INF ", 0x104004ull},
919 {"QM_ECC_MBIT_INF ", 0x10400cull},
920 {"QM_DFX_ACC_RDY_VLD0 ", 0x1040a0ull},
921 {"QM_DFX_ACC_RDY_VLD1 ", 0x1040a4ull},
922 {"QM_DFX_AXI_RDY_VLD ", 0x1040a8ull},
923 {"QM_DFX_FF_ST0 ", 0x1040c8ull},
924 {"QM_DFX_FF_ST1 ", 0x1040ccull},
925 {"QM_DFX_FF_ST2 ", 0x1040d0ull},
926 {"QM_DFX_FF_ST3 ", 0x1040d4ull},
927 {"QM_DFX_FF_ST4 ", 0x1040d8ull},
928 {"QM_DFX_FF_ST5 ", 0x1040dcull},
929 {"QM_DFX_FF_ST6 ", 0x1040e0ull},
930 {"QM_IN_IDLE_ST ", 0x1040e4ull},
931 { NULL, 0}
934 static struct qm_dfx_registers qm_vf_dfx_regs[] = {
935 {"QM_DFX_FUNS_ACTIVE_ST ", 0x200ull},
936 { NULL, 0}
939 static int qm_regs_show(struct seq_file *s, void *unused)
941 struct hisi_qm *qm = s->private;
942 struct qm_dfx_registers *regs;
943 u32 val;
945 if (qm->fun_type == QM_HW_PF)
946 regs = qm_dfx_regs;
947 else
948 regs = qm_vf_dfx_regs;
950 while (regs->reg_name) {
951 val = readl(qm->io_base + regs->reg_offset);
952 seq_printf(s, "%s= 0x%08x\n", regs->reg_name, val);
953 regs++;
956 return 0;
959 static int qm_regs_open(struct inode *inode, struct file *file)
961 return single_open(file, qm_regs_show, inode->i_private);
964 static const struct file_operations qm_regs_fops = {
965 .owner = THIS_MODULE,
966 .open = qm_regs_open,
967 .read = seq_read,
968 .release = single_release,
971 static int qm_create_debugfs_file(struct hisi_qm *qm, enum qm_debug_file index)
973 struct dentry *qm_d = qm->debug.qm_d;
974 struct debugfs_file *file = qm->debug.files + index;
976 debugfs_create_file(qm_debug_file_name[index], 0600, qm_d, file,
977 &qm_debug_fops);
979 file->index = index;
980 mutex_init(&file->lock);
981 file->debug = &qm->debug;
983 return 0;
986 static void qm_hw_error_init_v1(struct hisi_qm *qm, u32 ce, u32 nfe, u32 fe,
987 u32 msi)
989 writel(QM_ABNORMAL_INT_MASK_VALUE, qm->io_base + QM_ABNORMAL_INT_MASK);
992 static void qm_hw_error_init_v2(struct hisi_qm *qm, u32 ce, u32 nfe, u32 fe,
993 u32 msi)
995 u32 irq_enable = ce | nfe | fe | msi;
996 u32 irq_unmask = ~irq_enable;
998 qm->error_mask = ce | nfe | fe;
999 qm->msi_mask = msi;
1001 /* configure error type */
1002 writel(ce, qm->io_base + QM_RAS_CE_ENABLE);
1003 writel(QM_RAS_CE_TIMES_PER_IRQ, qm->io_base + QM_RAS_CE_THRESHOLD);
1004 writel(nfe, qm->io_base + QM_RAS_NFE_ENABLE);
1005 writel(fe, qm->io_base + QM_RAS_FE_ENABLE);
1007 /* use RAS irq default, so only set QM_RAS_MSI_INT_SEL for MSI */
1008 writel(msi, qm->io_base + QM_RAS_MSI_INT_SEL);
1010 irq_unmask &= readl(qm->io_base + QM_ABNORMAL_INT_MASK);
1011 writel(irq_unmask, qm->io_base + QM_ABNORMAL_INT_MASK);
1014 static void qm_log_hw_error(struct hisi_qm *qm, u32 error_status)
1016 const struct hisi_qm_hw_error *err = qm_hw_error;
1017 struct device *dev = &qm->pdev->dev;
1018 u32 reg_val, type, vf_num;
1020 while (err->msg) {
1021 if (err->int_msk & error_status) {
1022 dev_err(dev, "%s [error status=0x%x] found\n",
1023 err->msg, err->int_msk);
1025 if (error_status & QM_DB_TIMEOUT) {
1026 reg_val = readl(qm->io_base +
1027 QM_ABNORMAL_INF01);
1028 type = (reg_val & QM_DB_TIMEOUT_TYPE) >>
1029 QM_DB_TIMEOUT_TYPE_SHIFT;
1030 vf_num = reg_val & QM_DB_TIMEOUT_VF;
1031 dev_err(dev, "qm %s doorbell timeout in function %u\n",
1032 qm_db_timeout[type], vf_num);
1035 if (error_status & QM_OF_FIFO_OF) {
1036 reg_val = readl(qm->io_base +
1037 QM_ABNORMAL_INF00);
1038 type = (reg_val & QM_FIFO_OVERFLOW_TYPE) >>
1039 QM_FIFO_OVERFLOW_TYPE_SHIFT;
1040 vf_num = reg_val & QM_FIFO_OVERFLOW_VF;
1042 if (type < ARRAY_SIZE(qm_fifo_overflow))
1043 dev_err(dev, "qm %s fifo overflow in function %u\n",
1044 qm_fifo_overflow[type],
1045 vf_num);
1046 else
1047 dev_err(dev, "unknown error type\n");
1050 err++;
1054 static pci_ers_result_t qm_hw_error_handle_v2(struct hisi_qm *qm)
1056 u32 error_status, tmp;
1058 /* read err sts */
1059 tmp = readl(qm->io_base + QM_ABNORMAL_INT_STATUS);
1060 error_status = qm->error_mask & tmp;
1062 if (error_status) {
1063 qm_log_hw_error(qm, error_status);
1065 /* clear err sts */
1066 writel(error_status, qm->io_base + QM_ABNORMAL_INT_SOURCE);
1068 return PCI_ERS_RESULT_NEED_RESET;
1071 return PCI_ERS_RESULT_RECOVERED;
1074 static const struct hisi_qm_hw_ops qm_hw_ops_v1 = {
1075 .qm_db = qm_db_v1,
1076 .get_irq_num = qm_get_irq_num_v1,
1077 .hw_error_init = qm_hw_error_init_v1,
1080 static const struct hisi_qm_hw_ops qm_hw_ops_v2 = {
1081 .get_vft = qm_get_vft_v2,
1082 .qm_db = qm_db_v2,
1083 .get_irq_num = qm_get_irq_num_v2,
1084 .hw_error_init = qm_hw_error_init_v2,
1085 .hw_error_handle = qm_hw_error_handle_v2,
1088 static void *qm_get_avail_sqe(struct hisi_qp *qp)
1090 struct hisi_qp_status *qp_status = &qp->qp_status;
1091 u16 sq_tail = qp_status->sq_tail;
1093 if (unlikely(atomic_read(&qp->qp_status.used) == QM_Q_DEPTH))
1094 return NULL;
1096 return qp->sqe + sq_tail * qp->qm->sqe_size;
1100 * hisi_qm_create_qp() - Create a queue pair from qm.
1101 * @qm: The qm we create a qp from.
1102 * @alg_type: Accelerator specific algorithm type in sqc.
1104 * return created qp, -EBUSY if all qps in qm allocated, -ENOMEM if allocating
1105 * qp memory fails.
1107 struct hisi_qp *hisi_qm_create_qp(struct hisi_qm *qm, u8 alg_type)
1109 struct device *dev = &qm->pdev->dev;
1110 struct hisi_qp *qp;
1111 int qp_id, ret;
1113 qp = kzalloc(sizeof(*qp), GFP_KERNEL);
1114 if (!qp)
1115 return ERR_PTR(-ENOMEM);
1117 write_lock(&qm->qps_lock);
1119 qp_id = find_first_zero_bit(qm->qp_bitmap, qm->qp_num);
1120 if (qp_id >= qm->qp_num) {
1121 write_unlock(&qm->qps_lock);
1122 dev_info(&qm->pdev->dev, "QM all queues are busy!\n");
1123 ret = -EBUSY;
1124 goto err_free_qp;
1126 set_bit(qp_id, qm->qp_bitmap);
1127 qm->qp_array[qp_id] = qp;
1128 qm->qp_in_used++;
1130 write_unlock(&qm->qps_lock);
1132 qp->qm = qm;
1134 if (qm->use_dma_api) {
1135 qp->qdma.size = qm->sqe_size * QM_Q_DEPTH +
1136 sizeof(struct qm_cqe) * QM_Q_DEPTH;
1137 qp->qdma.va = dma_alloc_coherent(dev, qp->qdma.size,
1138 &qp->qdma.dma, GFP_KERNEL);
1139 if (!qp->qdma.va) {
1140 ret = -ENOMEM;
1141 goto err_clear_bit;
1144 dev_dbg(dev, "allocate qp dma buf(va=%pK, dma=%pad, size=%zx)\n",
1145 qp->qdma.va, &qp->qdma.dma, qp->qdma.size);
1148 qp->qp_id = qp_id;
1149 qp->alg_type = alg_type;
1150 INIT_WORK(&qp->work, qm_qp_work_func);
1151 qp->wq = alloc_workqueue("hisi_qm", WQ_UNBOUND | WQ_HIGHPRI |
1152 WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM, 0);
1153 if (!qp->wq) {
1154 ret = -EFAULT;
1155 goto err_free_qp_mem;
1158 return qp;
1160 err_free_qp_mem:
1161 if (qm->use_dma_api)
1162 dma_free_coherent(dev, qp->qdma.size, qp->qdma.va,
1163 qp->qdma.dma);
1164 err_clear_bit:
1165 write_lock(&qm->qps_lock);
1166 qm->qp_array[qp_id] = NULL;
1167 clear_bit(qp_id, qm->qp_bitmap);
1168 write_unlock(&qm->qps_lock);
1169 err_free_qp:
1170 kfree(qp);
1171 return ERR_PTR(ret);
1173 EXPORT_SYMBOL_GPL(hisi_qm_create_qp);
1176 * hisi_qm_release_qp() - Release a qp back to its qm.
1177 * @qp: The qp we want to release.
1179 * This function releases the resource of a qp.
1181 void hisi_qm_release_qp(struct hisi_qp *qp)
1183 struct hisi_qm *qm = qp->qm;
1184 struct qm_dma *qdma = &qp->qdma;
1185 struct device *dev = &qm->pdev->dev;
1187 if (qm->use_dma_api && qdma->va)
1188 dma_free_coherent(dev, qdma->size, qdma->va, qdma->dma);
1190 write_lock(&qm->qps_lock);
1191 qm->qp_array[qp->qp_id] = NULL;
1192 clear_bit(qp->qp_id, qm->qp_bitmap);
1193 qm->qp_in_used--;
1194 write_unlock(&qm->qps_lock);
1196 kfree(qp);
1198 EXPORT_SYMBOL_GPL(hisi_qm_release_qp);
1200 static int qm_qp_ctx_cfg(struct hisi_qp *qp, int qp_id, int pasid)
1202 struct hisi_qm *qm = qp->qm;
1203 struct device *dev = &qm->pdev->dev;
1204 enum qm_hw_ver ver = qm->ver;
1205 struct qm_sqc *sqc;
1206 struct qm_cqc *cqc;
1207 dma_addr_t sqc_dma;
1208 dma_addr_t cqc_dma;
1209 int ret;
1211 qm_init_qp_status(qp);
1213 sqc = kzalloc(sizeof(struct qm_sqc), GFP_KERNEL);
1214 if (!sqc)
1215 return -ENOMEM;
1216 sqc_dma = dma_map_single(dev, sqc, sizeof(struct qm_sqc),
1217 DMA_TO_DEVICE);
1218 if (dma_mapping_error(dev, sqc_dma)) {
1219 kfree(sqc);
1220 return -ENOMEM;
1223 INIT_QC_COMMON(sqc, qp->sqe_dma, pasid);
1224 if (ver == QM_HW_V1) {
1225 sqc->dw3 = cpu_to_le32(QM_MK_SQC_DW3_V1(0, 0, 0, qm->sqe_size));
1226 sqc->w8 = cpu_to_le16(QM_Q_DEPTH - 1);
1227 } else if (ver == QM_HW_V2) {
1228 sqc->dw3 = cpu_to_le32(QM_MK_SQC_DW3_V2(qm->sqe_size));
1229 sqc->w8 = 0; /* rand_qc */
1231 sqc->cq_num = cpu_to_le16(qp_id);
1232 sqc->w13 = cpu_to_le16(QM_MK_SQC_W13(0, 1, qp->alg_type));
1234 ret = qm_mb(qm, QM_MB_CMD_SQC, sqc_dma, qp_id, 0);
1235 dma_unmap_single(dev, sqc_dma, sizeof(struct qm_sqc), DMA_TO_DEVICE);
1236 kfree(sqc);
1237 if (ret)
1238 return ret;
1240 cqc = kzalloc(sizeof(struct qm_cqc), GFP_KERNEL);
1241 if (!cqc)
1242 return -ENOMEM;
1243 cqc_dma = dma_map_single(dev, cqc, sizeof(struct qm_cqc),
1244 DMA_TO_DEVICE);
1245 if (dma_mapping_error(dev, cqc_dma)) {
1246 kfree(cqc);
1247 return -ENOMEM;
1250 INIT_QC_COMMON(cqc, qp->cqe_dma, pasid);
1251 if (ver == QM_HW_V1) {
1252 cqc->dw3 = cpu_to_le32(QM_MK_CQC_DW3_V1(0, 0, 0, 4));
1253 cqc->w8 = cpu_to_le16(QM_Q_DEPTH - 1);
1254 } else if (ver == QM_HW_V2) {
1255 cqc->dw3 = cpu_to_le32(QM_MK_CQC_DW3_V2(4));
1256 cqc->w8 = 0;
1258 cqc->dw6 = cpu_to_le32(1 << QM_CQ_PHASE_SHIFT | 1 << QM_CQ_FLAG_SHIFT);
1260 ret = qm_mb(qm, QM_MB_CMD_CQC, cqc_dma, qp_id, 0);
1261 dma_unmap_single(dev, cqc_dma, sizeof(struct qm_cqc), DMA_TO_DEVICE);
1262 kfree(cqc);
1264 return ret;
1268 * hisi_qm_start_qp() - Start a qp into running.
1269 * @qp: The qp we want to start to run.
1270 * @arg: Accelerator specific argument.
1272 * After this function, qp can receive request from user. Return qp_id if
1273 * successful, Return -EBUSY if failed.
1275 int hisi_qm_start_qp(struct hisi_qp *qp, unsigned long arg)
1277 struct hisi_qm *qm = qp->qm;
1278 struct device *dev = &qm->pdev->dev;
1279 enum qm_hw_ver ver = qm->ver;
1280 int qp_id = qp->qp_id;
1281 int pasid = arg;
1282 size_t off = 0;
1283 int ret;
1285 #define QP_INIT_BUF(qp, type, size) do { \
1286 (qp)->type = ((qp)->qdma.va + (off)); \
1287 (qp)->type##_dma = (qp)->qdma.dma + (off); \
1288 off += (size); \
1289 } while (0)
1291 if (!qp->qdma.dma) {
1292 dev_err(dev, "cannot get qm dma buffer\n");
1293 return -EINVAL;
1296 /* sq need 128 bytes alignment */
1297 if (qp->qdma.dma & QM_SQE_DATA_ALIGN_MASK) {
1298 dev_err(dev, "qm sq is not aligned to 128 byte\n");
1299 return -EINVAL;
1302 QP_INIT_BUF(qp, sqe, qm->sqe_size * QM_Q_DEPTH);
1303 QP_INIT_BUF(qp, cqe, sizeof(struct qm_cqe) * QM_Q_DEPTH);
1305 dev_dbg(dev, "init qp buffer(v%d):\n"
1306 " sqe (%pK, %lx)\n"
1307 " cqe (%pK, %lx)\n",
1308 ver, qp->sqe, (unsigned long)qp->sqe_dma,
1309 qp->cqe, (unsigned long)qp->cqe_dma);
1311 ret = qm_qp_ctx_cfg(qp, qp_id, pasid);
1312 if (ret)
1313 return ret;
1315 dev_dbg(dev, "queue %d started\n", qp_id);
1317 return qp_id;
1319 EXPORT_SYMBOL_GPL(hisi_qm_start_qp);
1322 * hisi_qm_stop_qp() - Stop a qp in qm.
1323 * @qp: The qp we want to stop.
1325 * This function is reverse of hisi_qm_start_qp. Return 0 if successful.
1327 int hisi_qm_stop_qp(struct hisi_qp *qp)
1329 struct device *dev = &qp->qm->pdev->dev;
1330 int i = 0;
1332 /* it is stopped */
1333 if (test_bit(QP_STOP, &qp->qp_status.flags))
1334 return 0;
1336 while (atomic_read(&qp->qp_status.used)) {
1337 i++;
1338 msleep(20);
1339 if (i == 10) {
1340 dev_err(dev, "Cannot drain out data for stopping, Force to stop!\n");
1341 return 0;
1345 set_bit(QP_STOP, &qp->qp_status.flags);
1347 dev_dbg(dev, "stop queue %u!", qp->qp_id);
1349 return 0;
1351 EXPORT_SYMBOL_GPL(hisi_qm_stop_qp);
1354 * hisi_qp_send() - Queue up a task in the hardware queue.
1355 * @qp: The qp in which to put the message.
1356 * @msg: The message.
1358 * This function will return -EBUSY if qp is currently full, and -EAGAIN
1359 * if qp related qm is resetting.
1361 int hisi_qp_send(struct hisi_qp *qp, const void *msg)
1363 struct hisi_qp_status *qp_status = &qp->qp_status;
1364 u16 sq_tail = qp_status->sq_tail;
1365 u16 sq_tail_next = (sq_tail + 1) % QM_Q_DEPTH;
1366 void *sqe = qm_get_avail_sqe(qp);
1368 if (unlikely(test_bit(QP_STOP, &qp->qp_status.flags))) {
1369 dev_info(&qp->qm->pdev->dev, "QP is stopped or resetting\n");
1370 return -EAGAIN;
1373 if (!sqe)
1374 return -EBUSY;
1376 memcpy(sqe, msg, qp->qm->sqe_size);
1378 qm_db(qp->qm, qp->qp_id, QM_DOORBELL_CMD_SQ, sq_tail_next, 0);
1379 atomic_inc(&qp->qp_status.used);
1380 qp_status->sq_tail = sq_tail_next;
1382 return 0;
1384 EXPORT_SYMBOL_GPL(hisi_qp_send);
1386 static void hisi_qm_cache_wb(struct hisi_qm *qm)
1388 unsigned int val;
1390 if (qm->ver == QM_HW_V2) {
1391 writel(0x1, qm->io_base + QM_CACHE_WB_START);
1392 if (readl_relaxed_poll_timeout(qm->io_base + QM_CACHE_WB_DONE,
1393 val, val & BIT(0), 10, 1000))
1394 dev_err(&qm->pdev->dev, "QM writeback sqc cache fail!\n");
1399 * hisi_qm_get_free_qp_num() - Get free number of qp in qm.
1400 * @qm: The qm which want to get free qp.
1402 * This function return free number of qp in qm.
1404 int hisi_qm_get_free_qp_num(struct hisi_qm *qm)
1406 int ret;
1408 read_lock(&qm->qps_lock);
1409 ret = qm->qp_num - qm->qp_in_used;
1410 read_unlock(&qm->qps_lock);
1412 return ret;
1414 EXPORT_SYMBOL_GPL(hisi_qm_get_free_qp_num);
1417 * hisi_qm_init() - Initialize configures about qm.
1418 * @qm: The qm needing init.
1420 * This function init qm, then we can call hisi_qm_start to put qm into work.
1422 int hisi_qm_init(struct hisi_qm *qm)
1424 struct pci_dev *pdev = qm->pdev;
1425 struct device *dev = &pdev->dev;
1426 unsigned int num_vec;
1427 int ret;
1429 switch (qm->ver) {
1430 case QM_HW_V1:
1431 qm->ops = &qm_hw_ops_v1;
1432 break;
1433 case QM_HW_V2:
1434 qm->ops = &qm_hw_ops_v2;
1435 break;
1436 default:
1437 return -EINVAL;
1440 ret = pci_enable_device_mem(pdev);
1441 if (ret < 0) {
1442 dev_err(&pdev->dev, "Failed to enable device mem!\n");
1443 return ret;
1446 ret = pci_request_mem_regions(pdev, qm->dev_name);
1447 if (ret < 0) {
1448 dev_err(&pdev->dev, "Failed to request mem regions!\n");
1449 goto err_disable_pcidev;
1452 qm->io_base = ioremap(pci_resource_start(pdev, PCI_BAR_2),
1453 pci_resource_len(qm->pdev, PCI_BAR_2));
1454 if (!qm->io_base) {
1455 ret = -EIO;
1456 goto err_release_mem_regions;
1459 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
1460 if (ret < 0)
1461 goto err_iounmap;
1462 pci_set_master(pdev);
1464 if (!qm->ops->get_irq_num) {
1465 ret = -EOPNOTSUPP;
1466 goto err_iounmap;
1468 num_vec = qm->ops->get_irq_num(qm);
1469 ret = pci_alloc_irq_vectors(pdev, num_vec, num_vec, PCI_IRQ_MSI);
1470 if (ret < 0) {
1471 dev_err(dev, "Failed to enable MSI vectors!\n");
1472 goto err_iounmap;
1475 ret = qm_irq_register(qm);
1476 if (ret)
1477 goto err_free_irq_vectors;
1479 qm->qp_in_used = 0;
1480 mutex_init(&qm->mailbox_lock);
1481 rwlock_init(&qm->qps_lock);
1483 dev_dbg(dev, "init qm %s with %s\n", pdev->is_physfn ? "pf" : "vf",
1484 qm->use_dma_api ? "dma api" : "iommu api");
1486 return 0;
1488 err_free_irq_vectors:
1489 pci_free_irq_vectors(pdev);
1490 err_iounmap:
1491 iounmap(qm->io_base);
1492 err_release_mem_regions:
1493 pci_release_mem_regions(pdev);
1494 err_disable_pcidev:
1495 pci_disable_device(pdev);
1497 return ret;
1499 EXPORT_SYMBOL_GPL(hisi_qm_init);
1502 * hisi_qm_uninit() - Uninitialize qm.
1503 * @qm: The qm needed uninit.
1505 * This function uninits qm related device resources.
1507 void hisi_qm_uninit(struct hisi_qm *qm)
1509 struct pci_dev *pdev = qm->pdev;
1510 struct device *dev = &pdev->dev;
1512 if (qm->use_dma_api && qm->qdma.va) {
1513 hisi_qm_cache_wb(qm);
1514 dma_free_coherent(dev, qm->qdma.size,
1515 qm->qdma.va, qm->qdma.dma);
1516 memset(&qm->qdma, 0, sizeof(qm->qdma));
1519 qm_irq_unregister(qm);
1520 pci_free_irq_vectors(pdev);
1521 iounmap(qm->io_base);
1522 pci_release_mem_regions(pdev);
1523 pci_disable_device(pdev);
1525 EXPORT_SYMBOL_GPL(hisi_qm_uninit);
1528 * hisi_qm_get_vft() - Get vft from a qm.
1529 * @qm: The qm we want to get its vft.
1530 * @base: The base number of queue in vft.
1531 * @number: The number of queues in vft.
1533 * We can allocate multiple queues to a qm by configuring virtual function
1534 * table. We get related configures by this function. Normally, we call this
1535 * function in VF driver to get the queue information.
1537 * qm hw v1 does not support this interface.
1539 int hisi_qm_get_vft(struct hisi_qm *qm, u32 *base, u32 *number)
1541 if (!base || !number)
1542 return -EINVAL;
1544 if (!qm->ops->get_vft) {
1545 dev_err(&qm->pdev->dev, "Don't support vft read!\n");
1546 return -EINVAL;
1549 return qm->ops->get_vft(qm, base, number);
1551 EXPORT_SYMBOL_GPL(hisi_qm_get_vft);
1554 * hisi_qm_set_vft() - Set "virtual function table" for a qm.
1555 * @fun_num: Number of operated function.
1556 * @qm: The qm in which to set vft, alway in a PF.
1557 * @base: The base number of queue in vft.
1558 * @number: The number of queues in vft. 0 means invalid vft.
1560 * This function is alway called in PF driver, it is used to assign queues
1561 * among PF and VFs.
1563 * Assign queues A~B to PF: hisi_qm_set_vft(qm, 0, A, B - A + 1)
1564 * Assign queues A~B to VF: hisi_qm_set_vft(qm, 2, A, B - A + 1)
1565 * (VF function number 0x2)
1567 int hisi_qm_set_vft(struct hisi_qm *qm, u32 fun_num, u32 base,
1568 u32 number)
1570 u32 max_q_num = qm->ctrl_qp_num;
1572 if (base >= max_q_num || number > max_q_num ||
1573 (base + number) > max_q_num)
1574 return -EINVAL;
1576 return qm_set_sqc_cqc_vft(qm, fun_num, base, number);
1578 EXPORT_SYMBOL_GPL(hisi_qm_set_vft);
1580 static void qm_init_eq_aeq_status(struct hisi_qm *qm)
1582 struct hisi_qm_status *status = &qm->status;
1584 status->eq_head = 0;
1585 status->aeq_head = 0;
1586 status->eqc_phase = true;
1587 status->aeqc_phase = true;
1590 static int qm_eq_ctx_cfg(struct hisi_qm *qm)
1592 struct device *dev = &qm->pdev->dev;
1593 struct qm_eqc *eqc;
1594 struct qm_aeqc *aeqc;
1595 dma_addr_t eqc_dma;
1596 dma_addr_t aeqc_dma;
1597 int ret;
1599 qm_init_eq_aeq_status(qm);
1601 eqc = kzalloc(sizeof(struct qm_eqc), GFP_KERNEL);
1602 if (!eqc)
1603 return -ENOMEM;
1604 eqc_dma = dma_map_single(dev, eqc, sizeof(struct qm_eqc),
1605 DMA_TO_DEVICE);
1606 if (dma_mapping_error(dev, eqc_dma)) {
1607 kfree(eqc);
1608 return -ENOMEM;
1611 eqc->base_l = cpu_to_le32(lower_32_bits(qm->eqe_dma));
1612 eqc->base_h = cpu_to_le32(upper_32_bits(qm->eqe_dma));
1613 if (qm->ver == QM_HW_V1)
1614 eqc->dw3 = cpu_to_le32(QM_EQE_AEQE_SIZE);
1615 eqc->dw6 = cpu_to_le32((QM_Q_DEPTH - 1) | (1 << QM_EQC_PHASE_SHIFT));
1616 ret = qm_mb(qm, QM_MB_CMD_EQC, eqc_dma, 0, 0);
1617 dma_unmap_single(dev, eqc_dma, sizeof(struct qm_eqc), DMA_TO_DEVICE);
1618 kfree(eqc);
1619 if (ret)
1620 return ret;
1622 aeqc = kzalloc(sizeof(struct qm_aeqc), GFP_KERNEL);
1623 if (!aeqc)
1624 return -ENOMEM;
1625 aeqc_dma = dma_map_single(dev, aeqc, sizeof(struct qm_aeqc),
1626 DMA_TO_DEVICE);
1627 if (dma_mapping_error(dev, aeqc_dma)) {
1628 kfree(aeqc);
1629 return -ENOMEM;
1632 aeqc->base_l = cpu_to_le32(lower_32_bits(qm->aeqe_dma));
1633 aeqc->base_h = cpu_to_le32(upper_32_bits(qm->aeqe_dma));
1634 aeqc->dw6 = cpu_to_le32((QM_Q_DEPTH - 1) | (1 << QM_EQC_PHASE_SHIFT));
1636 ret = qm_mb(qm, QM_MB_CMD_AEQC, aeqc_dma, 0, 0);
1637 dma_unmap_single(dev, aeqc_dma, sizeof(struct qm_aeqc), DMA_TO_DEVICE);
1638 kfree(aeqc);
1640 return ret;
1643 static int __hisi_qm_start(struct hisi_qm *qm)
1645 struct pci_dev *pdev = qm->pdev;
1646 struct device *dev = &pdev->dev;
1647 size_t off = 0;
1648 int ret;
1650 #define QM_INIT_BUF(qm, type, num) do { \
1651 (qm)->type = ((qm)->qdma.va + (off)); \
1652 (qm)->type##_dma = (qm)->qdma.dma + (off); \
1653 off += QMC_ALIGN(sizeof(struct qm_##type) * (num)); \
1654 } while (0)
1656 WARN_ON(!qm->qdma.dma);
1658 if (qm->qp_num == 0)
1659 return -EINVAL;
1661 if (qm->fun_type == QM_HW_PF) {
1662 ret = qm_dev_mem_reset(qm);
1663 if (ret)
1664 return ret;
1666 ret = hisi_qm_set_vft(qm, 0, qm->qp_base, qm->qp_num);
1667 if (ret)
1668 return ret;
1671 QM_INIT_BUF(qm, eqe, QM_Q_DEPTH);
1672 QM_INIT_BUF(qm, aeqe, QM_Q_DEPTH);
1673 QM_INIT_BUF(qm, sqc, qm->qp_num);
1674 QM_INIT_BUF(qm, cqc, qm->qp_num);
1676 dev_dbg(dev, "init qm buffer:\n"
1677 " eqe (%pK, %lx)\n"
1678 " aeqe (%pK, %lx)\n"
1679 " sqc (%pK, %lx)\n"
1680 " cqc (%pK, %lx)\n",
1681 qm->eqe, (unsigned long)qm->eqe_dma,
1682 qm->aeqe, (unsigned long)qm->aeqe_dma,
1683 qm->sqc, (unsigned long)qm->sqc_dma,
1684 qm->cqc, (unsigned long)qm->cqc_dma);
1686 ret = qm_eq_ctx_cfg(qm);
1687 if (ret)
1688 return ret;
1690 ret = qm_mb(qm, QM_MB_CMD_SQC_BT, qm->sqc_dma, 0, 0);
1691 if (ret)
1692 return ret;
1694 ret = qm_mb(qm, QM_MB_CMD_CQC_BT, qm->cqc_dma, 0, 0);
1695 if (ret)
1696 return ret;
1698 writel(0x0, qm->io_base + QM_VF_EQ_INT_MASK);
1699 writel(0x0, qm->io_base + QM_VF_AEQ_INT_MASK);
1701 return 0;
1705 * hisi_qm_start() - start qm
1706 * @qm: The qm to be started.
1708 * This function starts a qm, then we can allocate qp from this qm.
1710 int hisi_qm_start(struct hisi_qm *qm)
1712 struct device *dev = &qm->pdev->dev;
1714 dev_dbg(dev, "qm start with %d queue pairs\n", qm->qp_num);
1716 if (!qm->qp_num) {
1717 dev_err(dev, "qp_num should not be 0\n");
1718 return -EINVAL;
1721 if (!qm->qp_bitmap) {
1722 qm->qp_bitmap = devm_kcalloc(dev, BITS_TO_LONGS(qm->qp_num),
1723 sizeof(long), GFP_KERNEL);
1724 qm->qp_array = devm_kcalloc(dev, qm->qp_num,
1725 sizeof(struct hisi_qp *),
1726 GFP_KERNEL);
1727 if (!qm->qp_bitmap || !qm->qp_array)
1728 return -ENOMEM;
1731 if (!qm->use_dma_api) {
1732 dev_dbg(&qm->pdev->dev, "qm delay start\n");
1733 return 0;
1734 } else if (!qm->qdma.va) {
1735 qm->qdma.size = QMC_ALIGN(sizeof(struct qm_eqe) * QM_Q_DEPTH) +
1736 QMC_ALIGN(sizeof(struct qm_aeqe) * QM_Q_DEPTH) +
1737 QMC_ALIGN(sizeof(struct qm_sqc) * qm->qp_num) +
1738 QMC_ALIGN(sizeof(struct qm_cqc) * qm->qp_num);
1739 qm->qdma.va = dma_alloc_coherent(dev, qm->qdma.size,
1740 &qm->qdma.dma, GFP_KERNEL);
1741 dev_dbg(dev, "allocate qm dma buf(va=%pK, dma=%pad, size=%zx)\n",
1742 qm->qdma.va, &qm->qdma.dma, qm->qdma.size);
1743 if (!qm->qdma.va)
1744 return -ENOMEM;
1747 return __hisi_qm_start(qm);
1749 EXPORT_SYMBOL_GPL(hisi_qm_start);
1752 * hisi_qm_stop() - Stop a qm.
1753 * @qm: The qm which will be stopped.
1755 * This function stops qm and its qps, then qm can not accept request.
1756 * Related resources are not released at this state, we can use hisi_qm_start
1757 * to let qm start again.
1759 int hisi_qm_stop(struct hisi_qm *qm)
1761 struct device *dev;
1762 struct hisi_qp *qp;
1763 int ret = 0, i;
1765 if (!qm || !qm->pdev) {
1766 WARN_ON(1);
1767 return -EINVAL;
1770 dev = &qm->pdev->dev;
1772 /* Mask eq and aeq irq */
1773 writel(0x1, qm->io_base + QM_VF_EQ_INT_MASK);
1774 writel(0x1, qm->io_base + QM_VF_AEQ_INT_MASK);
1776 /* Stop all qps belong to this qm */
1777 for (i = 0; i < qm->qp_num; i++) {
1778 qp = qm->qp_array[i];
1779 if (qp) {
1780 ret = hisi_qm_stop_qp(qp);
1781 if (ret < 0) {
1782 dev_err(dev, "Failed to stop qp%d!\n", i);
1783 return -EBUSY;
1788 if (qm->fun_type == QM_HW_PF) {
1789 ret = hisi_qm_set_vft(qm, 0, 0, 0);
1790 if (ret < 0)
1791 dev_err(dev, "Failed to set vft!\n");
1794 return ret;
1796 EXPORT_SYMBOL_GPL(hisi_qm_stop);
1799 * hisi_qm_debug_init() - Initialize qm related debugfs files.
1800 * @qm: The qm for which we want to add debugfs files.
1802 * Create qm related debugfs files.
1804 int hisi_qm_debug_init(struct hisi_qm *qm)
1806 struct dentry *qm_d;
1807 int i, ret;
1809 qm_d = debugfs_create_dir("qm", qm->debug.debug_root);
1810 qm->debug.qm_d = qm_d;
1812 /* only show this in PF */
1813 if (qm->fun_type == QM_HW_PF)
1814 for (i = CURRENT_Q; i < DEBUG_FILE_NUM; i++)
1815 if (qm_create_debugfs_file(qm, i)) {
1816 ret = -ENOENT;
1817 goto failed_to_create;
1820 debugfs_create_file("qm_regs", 0444, qm->debug.qm_d, qm, &qm_regs_fops);
1822 return 0;
1824 failed_to_create:
1825 debugfs_remove_recursive(qm_d);
1826 return ret;
1828 EXPORT_SYMBOL_GPL(hisi_qm_debug_init);
1831 * hisi_qm_debug_regs_clear() - clear qm debug related registers.
1832 * @qm: The qm for which we want to clear its debug registers.
1834 void hisi_qm_debug_regs_clear(struct hisi_qm *qm)
1836 struct qm_dfx_registers *regs;
1837 int i;
1839 /* clear current_q */
1840 writel(0x0, qm->io_base + QM_DFX_SQE_CNT_VF_SQN);
1841 writel(0x0, qm->io_base + QM_DFX_CQE_CNT_VF_CQN);
1844 * these registers are reading and clearing, so clear them after
1845 * reading them.
1847 writel(0x1, qm->io_base + QM_DFX_CNT_CLR_CE);
1849 regs = qm_dfx_regs;
1850 for (i = 0; i < CNT_CYC_REGS_NUM; i++) {
1851 readl(qm->io_base + regs->reg_offset);
1852 regs++;
1855 writel(0x0, qm->io_base + QM_DFX_CNT_CLR_CE);
1857 EXPORT_SYMBOL_GPL(hisi_qm_debug_regs_clear);
1860 * hisi_qm_hw_error_init() - Configure qm hardware error report method.
1861 * @qm: The qm which we want to configure.
1862 * @ce: Bit mask of correctable error configure.
1863 * @nfe: Bit mask of non-fatal error configure.
1864 * @fe: Bit mask of fatal error configure.
1865 * @msi: Bit mask of error reported by message signal interrupt.
1867 * Hardware errors of qm can be reported either by RAS interrupts which will
1868 * be handled by UEFI and then PCIe AER or by device MSI. User can configure
1869 * each error to use either of above two methods. For RAS interrupts, we can
1870 * configure an error as one of correctable error, non-fatal error or
1871 * fatal error.
1873 * Bits indicating errors can be configured to ce, nfe, fe and msi to enable
1874 * related report methods. Error report will be masked if related error bit
1875 * does not configure.
1877 void hisi_qm_hw_error_init(struct hisi_qm *qm, u32 ce, u32 nfe, u32 fe,
1878 u32 msi)
1880 if (!qm->ops->hw_error_init) {
1881 dev_err(&qm->pdev->dev, "QM doesn't support hw error handling!\n");
1882 return;
1885 qm->ops->hw_error_init(qm, ce, nfe, fe, msi);
1887 EXPORT_SYMBOL_GPL(hisi_qm_hw_error_init);
1890 * hisi_qm_hw_error_handle() - Handle qm non-fatal hardware errors.
1891 * @qm: The qm which has non-fatal hardware errors.
1893 * Accelerators use this function to handle qm non-fatal hardware errors.
1895 pci_ers_result_t hisi_qm_hw_error_handle(struct hisi_qm *qm)
1897 if (!qm->ops->hw_error_handle) {
1898 dev_err(&qm->pdev->dev, "QM doesn't support hw error report!\n");
1899 return PCI_ERS_RESULT_NONE;
1902 return qm->ops->hw_error_handle(qm);
1904 EXPORT_SYMBOL_GPL(hisi_qm_hw_error_handle);
1907 * hisi_qm_get_hw_version() - Get hardware version of a qm.
1908 * @pdev: The device which hardware version we want to get.
1910 * This function gets the hardware version of a qm. Return QM_HW_UNKNOWN
1911 * if the hardware version is not supported.
1913 enum qm_hw_ver hisi_qm_get_hw_version(struct pci_dev *pdev)
1915 switch (pdev->revision) {
1916 case QM_HW_V1:
1917 case QM_HW_V2:
1918 return pdev->revision;
1919 default:
1920 return QM_HW_UNKNOWN;
1923 EXPORT_SYMBOL_GPL(hisi_qm_get_hw_version);
1925 MODULE_LICENSE("GPL v2");
1926 MODULE_AUTHOR("Zhou Wang <wangzhou1@hisilicon.com>");
1927 MODULE_DESCRIPTION("HiSilicon Accelerator queue manager driver");