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
80 /* page number for queue file region */
81 #define QM_DOORBELL_PAGE_NR 1
104 struct debugfs_file
{
105 enum qm_debug_file index
;
107 struct qm_debug
*debug
;
112 struct dentry
*debug_root
;
114 struct debugfs_file files
[DEBUG_FILE_NUM
];
123 struct hisi_qm_status
{
133 struct hisi_qm_err_info
{
140 struct hisi_qm_err_ini
{
141 void (*hw_err_enable
)(struct hisi_qm
*qm
);
142 void (*hw_err_disable
)(struct hisi_qm
*qm
);
143 u32 (*get_dev_hw_err_status
)(struct hisi_qm
*qm
);
144 void (*log_dev_hw_err
)(struct hisi_qm
*qm
, u32 err_sts
);
145 struct hisi_qm_err_info err_info
;
148 struct hisi_qm_list
{
150 struct list_head list
;
155 enum qm_fun_type fun_type
;
156 const char *dev_name
;
157 struct pci_dev
*pdev
;
158 void __iomem
*io_base
;
164 struct list_head list
;
170 struct qm_aeqe
*aeqe
;
176 struct hisi_qm_status status
;
177 const struct hisi_qm_err_ini
*err_ini
;
180 unsigned long *qp_bitmap
;
181 struct hisi_qp
**qp_array
;
183 struct mutex mailbox_lock
;
185 const struct hisi_qm_hw_ops
*ops
;
187 struct qm_debug debug
;
192 struct workqueue_struct
*wq
;
193 struct work_struct work
;
198 resource_size_t phys_base
;
199 resource_size_t phys_size
;
200 struct uacce_device
*uacce
;
203 struct hisi_qp_status
{
212 int (*fill_sqe
)(void *sqe
, void *q_parm
, void *d_parm
);
226 struct hisi_qp_status qp_status
;
227 struct hisi_qp_ops
*hw_ops
;
229 void (*req_cb
)(struct hisi_qp
*qp
, void *data
);
230 void (*event_cb
)(struct hisi_qp
*qp
);
234 struct uacce_queue
*uacce_q
;
237 static inline void hisi_qm_init_list(struct hisi_qm_list
*qm_list
)
239 INIT_LIST_HEAD(&qm_list
->list
);
240 mutex_init(&qm_list
->lock
);
243 static inline void hisi_qm_add_to_list(struct hisi_qm
*qm
,
244 struct hisi_qm_list
*qm_list
)
246 mutex_lock(&qm_list
->lock
);
247 list_add_tail(&qm
->list
, &qm_list
->list
);
248 mutex_unlock(&qm_list
->lock
);
251 static inline void hisi_qm_del_from_list(struct hisi_qm
*qm
,
252 struct hisi_qm_list
*qm_list
)
254 mutex_lock(&qm_list
->lock
);
256 mutex_unlock(&qm_list
->lock
);
259 int hisi_qm_init(struct hisi_qm
*qm
);
260 void hisi_qm_uninit(struct hisi_qm
*qm
);
261 int hisi_qm_start(struct hisi_qm
*qm
);
262 int hisi_qm_stop(struct hisi_qm
*qm
);
263 struct hisi_qp
*hisi_qm_create_qp(struct hisi_qm
*qm
, u8 alg_type
);
264 int hisi_qm_start_qp(struct hisi_qp
*qp
, unsigned long arg
);
265 int hisi_qm_stop_qp(struct hisi_qp
*qp
);
266 void hisi_qm_release_qp(struct hisi_qp
*qp
);
267 int hisi_qp_send(struct hisi_qp
*qp
, const void *msg
);
268 int hisi_qm_get_free_qp_num(struct hisi_qm
*qm
);
269 int hisi_qm_get_vft(struct hisi_qm
*qm
, u32
*base
, u32
*number
);
270 int hisi_qm_set_vft(struct hisi_qm
*qm
, u32 fun_num
, u32 base
, u32 number
);
271 int hisi_qm_debug_init(struct hisi_qm
*qm
);
272 enum qm_hw_ver
hisi_qm_get_hw_version(struct pci_dev
*pdev
);
273 void hisi_qm_debug_regs_clear(struct hisi_qm
*qm
);
274 void hisi_qm_dev_err_init(struct hisi_qm
*qm
);
275 void hisi_qm_dev_err_uninit(struct hisi_qm
*qm
);
276 pci_ers_result_t
hisi_qm_dev_err_detected(struct pci_dev
*pdev
,
277 pci_channel_state_t state
);
279 struct hisi_acc_sgl_pool
;
280 struct hisi_acc_hw_sgl
*hisi_acc_sg_buf_map_to_hw_sgl(struct device
*dev
,
281 struct scatterlist
*sgl
, struct hisi_acc_sgl_pool
*pool
,
282 u32 index
, dma_addr_t
*hw_sgl_dma
);
283 void hisi_acc_sg_buf_unmap(struct device
*dev
, struct scatterlist
*sgl
,
284 struct hisi_acc_hw_sgl
*hw_sgl
);
285 struct hisi_acc_sgl_pool
*hisi_acc_create_sgl_pool(struct device
*dev
,
286 u32 count
, u32 sge_nr
);
287 void hisi_acc_free_sgl_pool(struct device
*dev
,
288 struct hisi_acc_sgl_pool
*pool
);
289 int hisi_qm_alloc_qps_node(struct hisi_qm_list
*qm_list
, int qp_num
,
290 u8 alg_type
, int node
, struct hisi_qp
**qps
);
291 void hisi_qm_free_qps(struct hisi_qp
**qps
, int qp_num
);