1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019 HiSilicon Limited. */
6 #include <linux/bitfield.h>
7 #include <linux/iopoll.h>
8 #include <linux/module.h>
12 #define QM_ARUSER_M_CFG_1 0x100088
13 #define AXUSER_SNOOP_ENABLE BIT(30)
14 #define AXUSER_CMD_TYPE GENMASK(14, 12)
15 #define AXUSER_CMD_SMMU_NORMAL 1
16 #define AXUSER_NS BIT(6)
17 #define AXUSER_NO BIT(5)
18 #define AXUSER_FP BIT(4)
19 #define AXUSER_SSV BIT(0)
20 #define AXUSER_BASE (AXUSER_SNOOP_ENABLE | \
21 FIELD_PREP(AXUSER_CMD_TYPE, \
22 AXUSER_CMD_SMMU_NORMAL) | \
23 AXUSER_NS | AXUSER_NO | AXUSER_FP)
24 #define QM_ARUSER_M_CFG_ENABLE 0x100090
25 #define ARUSER_M_CFG_ENABLE 0xfffffffe
26 #define QM_AWUSER_M_CFG_1 0x100098
27 #define QM_AWUSER_M_CFG_ENABLE 0x1000a0
28 #define AWUSER_M_CFG_ENABLE 0xfffffffe
29 #define QM_WUSER_M_CFG_ENABLE 0x1000a8
30 #define WUSER_M_CFG_ENABLE 0xffffffff
33 #define QM_CACHE_CTL 0x100050
34 #define SQC_CACHE_ENABLE BIT(0)
35 #define CQC_CACHE_ENABLE BIT(1)
36 #define SQC_CACHE_WB_ENABLE BIT(4)
37 #define SQC_CACHE_WB_THRD GENMASK(10, 5)
38 #define CQC_CACHE_WB_ENABLE BIT(11)
39 #define CQC_CACHE_WB_THRD GENMASK(17, 12)
40 #define QM_AXI_M_CFG 0x1000ac
41 #define AXI_M_CFG 0xffff
42 #define QM_AXI_M_CFG_ENABLE 0x1000b0
43 #define AXI_M_CFG_ENABLE 0xffffffff
44 #define QM_PEH_AXUSER_CFG 0x1000cc
45 #define QM_PEH_AXUSER_CFG_ENABLE 0x1000d0
46 #define PEH_AXUSER_CFG 0x401001
47 #define PEH_AXUSER_CFG_ENABLE 0xffffffff
49 #define QM_DFX_MB_CNT_VF 0x104010
50 #define QM_DFX_DB_CNT_VF 0x104020
51 #define QM_DFX_SQE_CNT_VF_SQN 0x104030
52 #define QM_DFX_CQE_CNT_VF_CQN 0x104040
53 #define QM_DFX_QN_SHIFT 16
54 #define CURRENT_FUN_MASK GENMASK(5, 0)
55 #define CURRENT_Q_MASK GENMASK(31, 16)
57 #define QM_AXI_RRESP BIT(0)
58 #define QM_AXI_BRESP BIT(1)
59 #define QM_ECC_MBIT BIT(2)
60 #define QM_ECC_1BIT BIT(3)
61 #define QM_ACC_GET_TASK_TIMEOUT BIT(4)
62 #define QM_ACC_DO_TASK_TIMEOUT BIT(5)
63 #define QM_ACC_WB_NOT_READY_TIMEOUT BIT(6)
64 #define QM_SQ_CQ_VF_INVALID BIT(7)
65 #define QM_CQ_VF_INVALID BIT(8)
66 #define QM_SQ_VF_INVALID BIT(9)
67 #define QM_DB_TIMEOUT BIT(10)
68 #define QM_OF_FIFO_OF BIT(11)
69 #define QM_DB_RANDOM_INVALID BIT(12)
71 #define QM_BASE_NFE (QM_AXI_RRESP | QM_AXI_BRESP | QM_ECC_MBIT | \
72 QM_ACC_GET_TASK_TIMEOUT | QM_DB_TIMEOUT | \
74 #define QM_BASE_CE QM_ECC_1BIT
76 #define QM_Q_DEPTH 1024
78 #define HISI_ACC_SGL_SGE_NR_MAX 255
101 struct debugfs_file
{
102 enum qm_debug_file index
;
104 struct qm_debug
*debug
;
109 struct dentry
*debug_root
;
111 struct debugfs_file files
[DEBUG_FILE_NUM
];
120 struct hisi_qm_status
{
130 enum qm_fun_type fun_type
;
131 const char *dev_name
;
132 struct pci_dev
*pdev
;
133 void __iomem
*io_base
;
144 struct qm_aeqe
*aeqe
;
150 struct hisi_qm_status status
;
153 unsigned long *qp_bitmap
;
154 struct hisi_qp
**qp_array
;
156 struct mutex mailbox_lock
;
158 const struct hisi_qm_hw_ops
*ops
;
160 struct qm_debug debug
;
168 struct hisi_qp_status
{
177 int (*fill_sqe
)(void *sqe
, void *q_parm
, void *d_parm
);
191 struct hisi_qp_status qp_status
;
192 struct hisi_qp_ops
*hw_ops
;
194 void (*req_cb
)(struct hisi_qp
*qp
, void *data
);
195 struct work_struct work
;
196 struct workqueue_struct
*wq
;
201 int hisi_qm_init(struct hisi_qm
*qm
);
202 void hisi_qm_uninit(struct hisi_qm
*qm
);
203 int hisi_qm_start(struct hisi_qm
*qm
);
204 int hisi_qm_stop(struct hisi_qm
*qm
);
205 struct hisi_qp
*hisi_qm_create_qp(struct hisi_qm
*qm
, u8 alg_type
);
206 int hisi_qm_start_qp(struct hisi_qp
*qp
, unsigned long arg
);
207 int hisi_qm_stop_qp(struct hisi_qp
*qp
);
208 void hisi_qm_release_qp(struct hisi_qp
*qp
);
209 int hisi_qp_send(struct hisi_qp
*qp
, const void *msg
);
210 int hisi_qm_get_free_qp_num(struct hisi_qm
*qm
);
211 int hisi_qm_get_vft(struct hisi_qm
*qm
, u32
*base
, u32
*number
);
212 int hisi_qm_set_vft(struct hisi_qm
*qm
, u32 fun_num
, u32 base
, u32 number
);
213 int hisi_qm_debug_init(struct hisi_qm
*qm
);
214 void hisi_qm_hw_error_init(struct hisi_qm
*qm
, u32 ce
, u32 nfe
, u32 fe
,
216 pci_ers_result_t
hisi_qm_hw_error_handle(struct hisi_qm
*qm
);
217 enum qm_hw_ver
hisi_qm_get_hw_version(struct pci_dev
*pdev
);
218 void hisi_qm_debug_regs_clear(struct hisi_qm
*qm
);
220 struct hisi_acc_sgl_pool
;
221 struct hisi_acc_hw_sgl
*hisi_acc_sg_buf_map_to_hw_sgl(struct device
*dev
,
222 struct scatterlist
*sgl
, struct hisi_acc_sgl_pool
*pool
,
223 u32 index
, dma_addr_t
*hw_sgl_dma
);
224 void hisi_acc_sg_buf_unmap(struct device
*dev
, struct scatterlist
*sgl
,
225 struct hisi_acc_hw_sgl
*hw_sgl
);
226 struct hisi_acc_sgl_pool
*hisi_acc_create_sgl_pool(struct device
*dev
,
227 u32 count
, u32 sge_nr
);
228 void hisi_acc_free_sgl_pool(struct device
*dev
,
229 struct hisi_acc_sgl_pool
*pool
);