18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/* Copyright (c) 2019 HiSilicon Limited. */
38c2ecf20Sopenharmony_ci#include <linux/acpi.h>
48c2ecf20Sopenharmony_ci#include <linux/aer.h>
58c2ecf20Sopenharmony_ci#include <linux/bitops.h>
68c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
78c2ecf20Sopenharmony_ci#include <linux/init.h>
88c2ecf20Sopenharmony_ci#include <linux/io.h>
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <linux/module.h>
118c2ecf20Sopenharmony_ci#include <linux/pci.h>
128c2ecf20Sopenharmony_ci#include <linux/seq_file.h>
138c2ecf20Sopenharmony_ci#include <linux/topology.h>
148c2ecf20Sopenharmony_ci#include <linux/uacce.h>
158c2ecf20Sopenharmony_ci#include "zip.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_ZIP_PF		0xa250
188c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_ZIP_VF		0xa251
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define HZIP_QUEUE_NUM_V1		4096
218c2ecf20Sopenharmony_ci#define HZIP_QUEUE_NUM_V2		1024
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define HZIP_CLOCK_GATE_CTRL		0x301004
248c2ecf20Sopenharmony_ci#define COMP0_ENABLE			BIT(0)
258c2ecf20Sopenharmony_ci#define COMP1_ENABLE			BIT(1)
268c2ecf20Sopenharmony_ci#define DECOMP0_ENABLE			BIT(2)
278c2ecf20Sopenharmony_ci#define DECOMP1_ENABLE			BIT(3)
288c2ecf20Sopenharmony_ci#define DECOMP2_ENABLE			BIT(4)
298c2ecf20Sopenharmony_ci#define DECOMP3_ENABLE			BIT(5)
308c2ecf20Sopenharmony_ci#define DECOMP4_ENABLE			BIT(6)
318c2ecf20Sopenharmony_ci#define DECOMP5_ENABLE			BIT(7)
328c2ecf20Sopenharmony_ci#define HZIP_ALL_COMP_DECOMP_EN		(COMP0_ENABLE | COMP1_ENABLE | \
338c2ecf20Sopenharmony_ci					 DECOMP0_ENABLE | DECOMP1_ENABLE | \
348c2ecf20Sopenharmony_ci					 DECOMP2_ENABLE | DECOMP3_ENABLE | \
358c2ecf20Sopenharmony_ci					 DECOMP4_ENABLE | DECOMP5_ENABLE)
368c2ecf20Sopenharmony_ci#define HZIP_DECOMP_CHECK_ENABLE	BIT(16)
378c2ecf20Sopenharmony_ci#define HZIP_FSM_MAX_CNT		0x301008
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define HZIP_PORT_ARCA_CHE_0		0x301040
408c2ecf20Sopenharmony_ci#define HZIP_PORT_ARCA_CHE_1		0x301044
418c2ecf20Sopenharmony_ci#define HZIP_PORT_AWCA_CHE_0		0x301060
428c2ecf20Sopenharmony_ci#define HZIP_PORT_AWCA_CHE_1		0x301064
438c2ecf20Sopenharmony_ci#define HZIP_CACHE_ALL_EN		0xffffffff
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define HZIP_BD_RUSER_32_63		0x301110
468c2ecf20Sopenharmony_ci#define HZIP_SGL_RUSER_32_63		0x30111c
478c2ecf20Sopenharmony_ci#define HZIP_DATA_RUSER_32_63		0x301128
488c2ecf20Sopenharmony_ci#define HZIP_DATA_WUSER_32_63		0x301134
498c2ecf20Sopenharmony_ci#define HZIP_BD_WUSER_32_63		0x301140
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define HZIP_QM_IDEL_STATUS		0x3040e4
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define HZIP_CORE_DEBUG_COMP_0		0x302000
548c2ecf20Sopenharmony_ci#define HZIP_CORE_DEBUG_COMP_1		0x303000
558c2ecf20Sopenharmony_ci#define HZIP_CORE_DEBUG_DECOMP_0	0x304000
568c2ecf20Sopenharmony_ci#define HZIP_CORE_DEBUG_DECOMP_1	0x305000
578c2ecf20Sopenharmony_ci#define HZIP_CORE_DEBUG_DECOMP_2	0x306000
588c2ecf20Sopenharmony_ci#define HZIP_CORE_DEBUG_DECOMP_3	0x307000
598c2ecf20Sopenharmony_ci#define HZIP_CORE_DEBUG_DECOMP_4	0x308000
608c2ecf20Sopenharmony_ci#define HZIP_CORE_DEBUG_DECOMP_5	0x309000
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define HZIP_CORE_INT_SOURCE		0x3010A0
638c2ecf20Sopenharmony_ci#define HZIP_CORE_INT_MASK_REG		0x3010A4
648c2ecf20Sopenharmony_ci#define HZIP_CORE_INT_SET		0x3010A8
658c2ecf20Sopenharmony_ci#define HZIP_CORE_INT_STATUS		0x3010AC
668c2ecf20Sopenharmony_ci#define HZIP_CORE_INT_STATUS_M_ECC	BIT(1)
678c2ecf20Sopenharmony_ci#define HZIP_CORE_SRAM_ECC_ERR_INFO	0x301148
688c2ecf20Sopenharmony_ci#define HZIP_CORE_INT_RAS_CE_ENB	0x301160
698c2ecf20Sopenharmony_ci#define HZIP_CORE_INT_RAS_NFE_ENB	0x301164
708c2ecf20Sopenharmony_ci#define HZIP_CORE_INT_RAS_FE_ENB        0x301168
718c2ecf20Sopenharmony_ci#define HZIP_CORE_INT_RAS_NFE_ENABLE	0x7FE
728c2ecf20Sopenharmony_ci#define HZIP_SRAM_ECC_ERR_NUM_SHIFT	16
738c2ecf20Sopenharmony_ci#define HZIP_SRAM_ECC_ERR_ADDR_SHIFT	24
748c2ecf20Sopenharmony_ci#define HZIP_CORE_INT_MASK_ALL		GENMASK(10, 0)
758c2ecf20Sopenharmony_ci#define HZIP_COMP_CORE_NUM		2
768c2ecf20Sopenharmony_ci#define HZIP_DECOMP_CORE_NUM		6
778c2ecf20Sopenharmony_ci#define HZIP_CORE_NUM			(HZIP_COMP_CORE_NUM + \
788c2ecf20Sopenharmony_ci					 HZIP_DECOMP_CORE_NUM)
798c2ecf20Sopenharmony_ci#define HZIP_SQE_SIZE			128
808c2ecf20Sopenharmony_ci#define HZIP_SQ_SIZE			(HZIP_SQE_SIZE * QM_Q_DEPTH)
818c2ecf20Sopenharmony_ci#define HZIP_PF_DEF_Q_NUM		64
828c2ecf20Sopenharmony_ci#define HZIP_PF_DEF_Q_BASE		0
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define HZIP_SOFT_CTRL_CNT_CLR_CE	0x301000
858c2ecf20Sopenharmony_ci#define HZIP_SOFT_CTRL_CNT_CLR_CE_BIT	BIT(0)
868c2ecf20Sopenharmony_ci#define HZIP_SOFT_CTRL_ZIP_CONTROL	0x30100C
878c2ecf20Sopenharmony_ci#define HZIP_AXI_SHUTDOWN_ENABLE	BIT(14)
888c2ecf20Sopenharmony_ci#define HZIP_WR_PORT			BIT(11)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define HZIP_BUF_SIZE			22
918c2ecf20Sopenharmony_ci#define HZIP_SQE_MASK_OFFSET		64
928c2ecf20Sopenharmony_ci#define HZIP_SQE_MASK_LEN		48
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define HZIP_CNT_CLR_CE_EN		BIT(0)
958c2ecf20Sopenharmony_ci#define HZIP_RO_CNT_CLR_CE_EN		BIT(2)
968c2ecf20Sopenharmony_ci#define HZIP_RD_CNT_CLR_CE_EN		(HZIP_CNT_CLR_CE_EN | \
978c2ecf20Sopenharmony_ci					 HZIP_RO_CNT_CLR_CE_EN)
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistatic const char hisi_zip_name[] = "hisi_zip";
1008c2ecf20Sopenharmony_cistatic struct dentry *hzip_debugfs_root;
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistruct hisi_zip_hw_error {
1038c2ecf20Sopenharmony_ci	u32 int_msk;
1048c2ecf20Sopenharmony_ci	const char *msg;
1058c2ecf20Sopenharmony_ci};
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_cistruct zip_dfx_item {
1088c2ecf20Sopenharmony_ci	const char *name;
1098c2ecf20Sopenharmony_ci	u32 offset;
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistatic struct hisi_qm_list zip_devices = {
1138c2ecf20Sopenharmony_ci	.register_to_crypto	= hisi_zip_register_to_crypto,
1148c2ecf20Sopenharmony_ci	.unregister_from_crypto	= hisi_zip_unregister_from_crypto,
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic struct zip_dfx_item zip_dfx_files[] = {
1188c2ecf20Sopenharmony_ci	{"send_cnt", offsetof(struct hisi_zip_dfx, send_cnt)},
1198c2ecf20Sopenharmony_ci	{"recv_cnt", offsetof(struct hisi_zip_dfx, recv_cnt)},
1208c2ecf20Sopenharmony_ci	{"send_busy_cnt", offsetof(struct hisi_zip_dfx, send_busy_cnt)},
1218c2ecf20Sopenharmony_ci	{"err_bd_cnt", offsetof(struct hisi_zip_dfx, err_bd_cnt)},
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic const struct hisi_zip_hw_error zip_hw_error[] = {
1258c2ecf20Sopenharmony_ci	{ .int_msk = BIT(0), .msg = "zip_ecc_1bitt_err" },
1268c2ecf20Sopenharmony_ci	{ .int_msk = BIT(1), .msg = "zip_ecc_2bit_err" },
1278c2ecf20Sopenharmony_ci	{ .int_msk = BIT(2), .msg = "zip_axi_rresp_err" },
1288c2ecf20Sopenharmony_ci	{ .int_msk = BIT(3), .msg = "zip_axi_bresp_err" },
1298c2ecf20Sopenharmony_ci	{ .int_msk = BIT(4), .msg = "zip_src_addr_parse_err" },
1308c2ecf20Sopenharmony_ci	{ .int_msk = BIT(5), .msg = "zip_dst_addr_parse_err" },
1318c2ecf20Sopenharmony_ci	{ .int_msk = BIT(6), .msg = "zip_pre_in_addr_err" },
1328c2ecf20Sopenharmony_ci	{ .int_msk = BIT(7), .msg = "zip_pre_in_data_err" },
1338c2ecf20Sopenharmony_ci	{ .int_msk = BIT(8), .msg = "zip_com_inf_err" },
1348c2ecf20Sopenharmony_ci	{ .int_msk = BIT(9), .msg = "zip_enc_inf_err" },
1358c2ecf20Sopenharmony_ci	{ .int_msk = BIT(10), .msg = "zip_pre_out_err" },
1368c2ecf20Sopenharmony_ci	{ /* sentinel */ }
1378c2ecf20Sopenharmony_ci};
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_cienum ctrl_debug_file_index {
1408c2ecf20Sopenharmony_ci	HZIP_CURRENT_QM,
1418c2ecf20Sopenharmony_ci	HZIP_CLEAR_ENABLE,
1428c2ecf20Sopenharmony_ci	HZIP_DEBUG_FILE_NUM,
1438c2ecf20Sopenharmony_ci};
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic const char * const ctrl_debug_file_name[] = {
1468c2ecf20Sopenharmony_ci	[HZIP_CURRENT_QM]   = "current_qm",
1478c2ecf20Sopenharmony_ci	[HZIP_CLEAR_ENABLE] = "clear_enable",
1488c2ecf20Sopenharmony_ci};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistruct ctrl_debug_file {
1518c2ecf20Sopenharmony_ci	enum ctrl_debug_file_index index;
1528c2ecf20Sopenharmony_ci	spinlock_t lock;
1538c2ecf20Sopenharmony_ci	struct hisi_zip_ctrl *ctrl;
1548c2ecf20Sopenharmony_ci};
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/*
1578c2ecf20Sopenharmony_ci * One ZIP controller has one PF and multiple VFs, some global configurations
1588c2ecf20Sopenharmony_ci * which PF has need this structure.
1598c2ecf20Sopenharmony_ci *
1608c2ecf20Sopenharmony_ci * Just relevant for PF.
1618c2ecf20Sopenharmony_ci */
1628c2ecf20Sopenharmony_cistruct hisi_zip_ctrl {
1638c2ecf20Sopenharmony_ci	struct hisi_zip *hisi_zip;
1648c2ecf20Sopenharmony_ci	struct ctrl_debug_file files[HZIP_DEBUG_FILE_NUM];
1658c2ecf20Sopenharmony_ci};
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cienum {
1688c2ecf20Sopenharmony_ci	HZIP_COMP_CORE0,
1698c2ecf20Sopenharmony_ci	HZIP_COMP_CORE1,
1708c2ecf20Sopenharmony_ci	HZIP_DECOMP_CORE0,
1718c2ecf20Sopenharmony_ci	HZIP_DECOMP_CORE1,
1728c2ecf20Sopenharmony_ci	HZIP_DECOMP_CORE2,
1738c2ecf20Sopenharmony_ci	HZIP_DECOMP_CORE3,
1748c2ecf20Sopenharmony_ci	HZIP_DECOMP_CORE4,
1758c2ecf20Sopenharmony_ci	HZIP_DECOMP_CORE5,
1768c2ecf20Sopenharmony_ci};
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cistatic const u64 core_offsets[] = {
1798c2ecf20Sopenharmony_ci	[HZIP_COMP_CORE0]   = 0x302000,
1808c2ecf20Sopenharmony_ci	[HZIP_COMP_CORE1]   = 0x303000,
1818c2ecf20Sopenharmony_ci	[HZIP_DECOMP_CORE0] = 0x304000,
1828c2ecf20Sopenharmony_ci	[HZIP_DECOMP_CORE1] = 0x305000,
1838c2ecf20Sopenharmony_ci	[HZIP_DECOMP_CORE2] = 0x306000,
1848c2ecf20Sopenharmony_ci	[HZIP_DECOMP_CORE3] = 0x307000,
1858c2ecf20Sopenharmony_ci	[HZIP_DECOMP_CORE4] = 0x308000,
1868c2ecf20Sopenharmony_ci	[HZIP_DECOMP_CORE5] = 0x309000,
1878c2ecf20Sopenharmony_ci};
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistatic const struct debugfs_reg32 hzip_dfx_regs[] = {
1908c2ecf20Sopenharmony_ci	{"HZIP_GET_BD_NUM                ",  0x00ull},
1918c2ecf20Sopenharmony_ci	{"HZIP_GET_RIGHT_BD              ",  0x04ull},
1928c2ecf20Sopenharmony_ci	{"HZIP_GET_ERROR_BD              ",  0x08ull},
1938c2ecf20Sopenharmony_ci	{"HZIP_DONE_BD_NUM               ",  0x0cull},
1948c2ecf20Sopenharmony_ci	{"HZIP_WORK_CYCLE                ",  0x10ull},
1958c2ecf20Sopenharmony_ci	{"HZIP_IDLE_CYCLE                ",  0x18ull},
1968c2ecf20Sopenharmony_ci	{"HZIP_MAX_DELAY                 ",  0x20ull},
1978c2ecf20Sopenharmony_ci	{"HZIP_MIN_DELAY                 ",  0x24ull},
1988c2ecf20Sopenharmony_ci	{"HZIP_AVG_DELAY                 ",  0x28ull},
1998c2ecf20Sopenharmony_ci	{"HZIP_MEM_VISIBLE_DATA          ",  0x30ull},
2008c2ecf20Sopenharmony_ci	{"HZIP_MEM_VISIBLE_ADDR          ",  0x34ull},
2018c2ecf20Sopenharmony_ci	{"HZIP_COMSUMED_BYTE             ",  0x38ull},
2028c2ecf20Sopenharmony_ci	{"HZIP_PRODUCED_BYTE             ",  0x40ull},
2038c2ecf20Sopenharmony_ci	{"HZIP_COMP_INF                  ",  0x70ull},
2048c2ecf20Sopenharmony_ci	{"HZIP_PRE_OUT                   ",  0x78ull},
2058c2ecf20Sopenharmony_ci	{"HZIP_BD_RD                     ",  0x7cull},
2068c2ecf20Sopenharmony_ci	{"HZIP_BD_WR                     ",  0x80ull},
2078c2ecf20Sopenharmony_ci	{"HZIP_GET_BD_AXI_ERR_NUM        ",  0x84ull},
2088c2ecf20Sopenharmony_ci	{"HZIP_GET_BD_PARSE_ERR_NUM      ",  0x88ull},
2098c2ecf20Sopenharmony_ci	{"HZIP_ADD_BD_AXI_ERR_NUM        ",  0x8cull},
2108c2ecf20Sopenharmony_ci	{"HZIP_DECOMP_STF_RELOAD_CURR_ST ",  0x94ull},
2118c2ecf20Sopenharmony_ci	{"HZIP_DECOMP_LZ77_CURR_ST       ",  0x9cull},
2128c2ecf20Sopenharmony_ci};
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic int pf_q_num_set(const char *val, const struct kernel_param *kp)
2158c2ecf20Sopenharmony_ci{
2168c2ecf20Sopenharmony_ci	return q_num_set(val, kp, PCI_DEVICE_ID_ZIP_PF);
2178c2ecf20Sopenharmony_ci}
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistatic const struct kernel_param_ops pf_q_num_ops = {
2208c2ecf20Sopenharmony_ci	.set = pf_q_num_set,
2218c2ecf20Sopenharmony_ci	.get = param_get_int,
2228c2ecf20Sopenharmony_ci};
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_cistatic u32 pf_q_num = HZIP_PF_DEF_Q_NUM;
2258c2ecf20Sopenharmony_cimodule_param_cb(pf_q_num, &pf_q_num_ops, &pf_q_num, 0444);
2268c2ecf20Sopenharmony_ciMODULE_PARM_DESC(pf_q_num, "Number of queues in PF(v1 2-4096, v2 2-1024)");
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistatic const struct kernel_param_ops vfs_num_ops = {
2298c2ecf20Sopenharmony_ci	.set = vfs_num_set,
2308c2ecf20Sopenharmony_ci	.get = param_get_int,
2318c2ecf20Sopenharmony_ci};
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_cistatic u32 vfs_num;
2348c2ecf20Sopenharmony_cimodule_param_cb(vfs_num, &vfs_num_ops, &vfs_num, 0444);
2358c2ecf20Sopenharmony_ciMODULE_PARM_DESC(vfs_num, "Number of VFs to enable(1-63), 0(default)");
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_cistatic const struct pci_device_id hisi_zip_dev_ids[] = {
2388c2ecf20Sopenharmony_ci	{ PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, PCI_DEVICE_ID_ZIP_PF) },
2398c2ecf20Sopenharmony_ci	{ PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, PCI_DEVICE_ID_ZIP_VF) },
2408c2ecf20Sopenharmony_ci	{ 0, }
2418c2ecf20Sopenharmony_ci};
2428c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, hisi_zip_dev_ids);
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ciint zip_create_qps(struct hisi_qp **qps, int qp_num, int node)
2458c2ecf20Sopenharmony_ci{
2468c2ecf20Sopenharmony_ci	if (node == NUMA_NO_NODE)
2478c2ecf20Sopenharmony_ci		node = cpu_to_node(smp_processor_id());
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	return hisi_qm_alloc_qps_node(&zip_devices, qp_num, 0, node, qps);
2508c2ecf20Sopenharmony_ci}
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_cistatic int hisi_zip_set_user_domain_and_cache(struct hisi_qm *qm)
2538c2ecf20Sopenharmony_ci{
2548c2ecf20Sopenharmony_ci	void __iomem *base = qm->io_base;
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	/* qm user domain */
2578c2ecf20Sopenharmony_ci	writel(AXUSER_BASE, base + QM_ARUSER_M_CFG_1);
2588c2ecf20Sopenharmony_ci	writel(ARUSER_M_CFG_ENABLE, base + QM_ARUSER_M_CFG_ENABLE);
2598c2ecf20Sopenharmony_ci	writel(AXUSER_BASE, base + QM_AWUSER_M_CFG_1);
2608c2ecf20Sopenharmony_ci	writel(AWUSER_M_CFG_ENABLE, base + QM_AWUSER_M_CFG_ENABLE);
2618c2ecf20Sopenharmony_ci	writel(WUSER_M_CFG_ENABLE, base + QM_WUSER_M_CFG_ENABLE);
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	/* qm cache */
2648c2ecf20Sopenharmony_ci	writel(AXI_M_CFG, base + QM_AXI_M_CFG);
2658c2ecf20Sopenharmony_ci	writel(AXI_M_CFG_ENABLE, base + QM_AXI_M_CFG_ENABLE);
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	/* disable FLR triggered by BME(bus master enable) */
2688c2ecf20Sopenharmony_ci	writel(PEH_AXUSER_CFG, base + QM_PEH_AXUSER_CFG);
2698c2ecf20Sopenharmony_ci	writel(PEH_AXUSER_CFG_ENABLE, base + QM_PEH_AXUSER_CFG_ENABLE);
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	/* cache */
2728c2ecf20Sopenharmony_ci	writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_0);
2738c2ecf20Sopenharmony_ci	writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_ARCA_CHE_1);
2748c2ecf20Sopenharmony_ci	writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_0);
2758c2ecf20Sopenharmony_ci	writel(HZIP_CACHE_ALL_EN, base + HZIP_PORT_AWCA_CHE_1);
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	/* user domain configurations */
2788c2ecf20Sopenharmony_ci	writel(AXUSER_BASE, base + HZIP_BD_RUSER_32_63);
2798c2ecf20Sopenharmony_ci	writel(AXUSER_BASE, base + HZIP_SGL_RUSER_32_63);
2808c2ecf20Sopenharmony_ci	writel(AXUSER_BASE, base + HZIP_BD_WUSER_32_63);
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	if (qm->use_sva) {
2838c2ecf20Sopenharmony_ci		writel(AXUSER_BASE | AXUSER_SSV, base + HZIP_DATA_RUSER_32_63);
2848c2ecf20Sopenharmony_ci		writel(AXUSER_BASE | AXUSER_SSV, base + HZIP_DATA_WUSER_32_63);
2858c2ecf20Sopenharmony_ci	} else {
2868c2ecf20Sopenharmony_ci		writel(AXUSER_BASE, base + HZIP_DATA_RUSER_32_63);
2878c2ecf20Sopenharmony_ci		writel(AXUSER_BASE, base + HZIP_DATA_WUSER_32_63);
2888c2ecf20Sopenharmony_ci	}
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	/* let's open all compression/decompression cores */
2918c2ecf20Sopenharmony_ci	writel(HZIP_DECOMP_CHECK_ENABLE | HZIP_ALL_COMP_DECOMP_EN,
2928c2ecf20Sopenharmony_ci	       base + HZIP_CLOCK_GATE_CTRL);
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	/* enable sqc,cqc writeback */
2958c2ecf20Sopenharmony_ci	writel(SQC_CACHE_ENABLE | CQC_CACHE_ENABLE | SQC_CACHE_WB_ENABLE |
2968c2ecf20Sopenharmony_ci	       CQC_CACHE_WB_ENABLE | FIELD_PREP(SQC_CACHE_WB_THRD, 1) |
2978c2ecf20Sopenharmony_ci	       FIELD_PREP(CQC_CACHE_WB_THRD, 1), base + QM_CACHE_CTL);
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	return 0;
3008c2ecf20Sopenharmony_ci}
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_cistatic void hisi_zip_hw_error_enable(struct hisi_qm *qm)
3038c2ecf20Sopenharmony_ci{
3048c2ecf20Sopenharmony_ci	u32 val;
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	if (qm->ver == QM_HW_V1) {
3078c2ecf20Sopenharmony_ci		writel(HZIP_CORE_INT_MASK_ALL,
3088c2ecf20Sopenharmony_ci		       qm->io_base + HZIP_CORE_INT_MASK_REG);
3098c2ecf20Sopenharmony_ci		dev_info(&qm->pdev->dev, "Does not support hw error handle\n");
3108c2ecf20Sopenharmony_ci		return;
3118c2ecf20Sopenharmony_ci	}
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	/* clear ZIP hw error source if having */
3148c2ecf20Sopenharmony_ci	writel(HZIP_CORE_INT_MASK_ALL, qm->io_base + HZIP_CORE_INT_SOURCE);
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	/* configure error type */
3178c2ecf20Sopenharmony_ci	writel(0x1, qm->io_base + HZIP_CORE_INT_RAS_CE_ENB);
3188c2ecf20Sopenharmony_ci	writel(0x0, qm->io_base + HZIP_CORE_INT_RAS_FE_ENB);
3198c2ecf20Sopenharmony_ci	writel(HZIP_CORE_INT_RAS_NFE_ENABLE,
3208c2ecf20Sopenharmony_ci	       qm->io_base + HZIP_CORE_INT_RAS_NFE_ENB);
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	/* enable ZIP hw error interrupts */
3238c2ecf20Sopenharmony_ci	writel(0, qm->io_base + HZIP_CORE_INT_MASK_REG);
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	/* enable ZIP block master OOO when m-bit error occur */
3268c2ecf20Sopenharmony_ci	val = readl(qm->io_base + HZIP_SOFT_CTRL_ZIP_CONTROL);
3278c2ecf20Sopenharmony_ci	val = val | HZIP_AXI_SHUTDOWN_ENABLE;
3288c2ecf20Sopenharmony_ci	writel(val, qm->io_base + HZIP_SOFT_CTRL_ZIP_CONTROL);
3298c2ecf20Sopenharmony_ci}
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_cistatic void hisi_zip_hw_error_disable(struct hisi_qm *qm)
3328c2ecf20Sopenharmony_ci{
3338c2ecf20Sopenharmony_ci	u32 val;
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	/* disable ZIP hw error interrupts */
3368c2ecf20Sopenharmony_ci	writel(HZIP_CORE_INT_MASK_ALL, qm->io_base + HZIP_CORE_INT_MASK_REG);
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	/* disable ZIP block master OOO when m-bit error occur */
3398c2ecf20Sopenharmony_ci	val = readl(qm->io_base + HZIP_SOFT_CTRL_ZIP_CONTROL);
3408c2ecf20Sopenharmony_ci	val = val & ~HZIP_AXI_SHUTDOWN_ENABLE;
3418c2ecf20Sopenharmony_ci	writel(val, qm->io_base + HZIP_SOFT_CTRL_ZIP_CONTROL);
3428c2ecf20Sopenharmony_ci}
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_cistatic inline struct hisi_qm *file_to_qm(struct ctrl_debug_file *file)
3458c2ecf20Sopenharmony_ci{
3468c2ecf20Sopenharmony_ci	struct hisi_zip *hisi_zip = file->ctrl->hisi_zip;
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci	return &hisi_zip->qm;
3498c2ecf20Sopenharmony_ci}
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_cistatic u32 current_qm_read(struct ctrl_debug_file *file)
3528c2ecf20Sopenharmony_ci{
3538c2ecf20Sopenharmony_ci	struct hisi_qm *qm = file_to_qm(file);
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	return readl(qm->io_base + QM_DFX_MB_CNT_VF);
3568c2ecf20Sopenharmony_ci}
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_cistatic int current_qm_write(struct ctrl_debug_file *file, u32 val)
3598c2ecf20Sopenharmony_ci{
3608c2ecf20Sopenharmony_ci	struct hisi_qm *qm = file_to_qm(file);
3618c2ecf20Sopenharmony_ci	u32 vfq_num;
3628c2ecf20Sopenharmony_ci	u32 tmp;
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	if (val > qm->vfs_num)
3658c2ecf20Sopenharmony_ci		return -EINVAL;
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	/* According PF or VF Dev ID to calculation curr_qm_qp_num and store */
3688c2ecf20Sopenharmony_ci	if (val == 0) {
3698c2ecf20Sopenharmony_ci		qm->debug.curr_qm_qp_num = qm->qp_num;
3708c2ecf20Sopenharmony_ci	} else {
3718c2ecf20Sopenharmony_ci		vfq_num = (qm->ctrl_qp_num - qm->qp_num) / qm->vfs_num;
3728c2ecf20Sopenharmony_ci		if (val == qm->vfs_num)
3738c2ecf20Sopenharmony_ci			qm->debug.curr_qm_qp_num = qm->ctrl_qp_num -
3748c2ecf20Sopenharmony_ci				qm->qp_num - (qm->vfs_num - 1) * vfq_num;
3758c2ecf20Sopenharmony_ci		else
3768c2ecf20Sopenharmony_ci			qm->debug.curr_qm_qp_num = vfq_num;
3778c2ecf20Sopenharmony_ci	}
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	writel(val, qm->io_base + QM_DFX_MB_CNT_VF);
3808c2ecf20Sopenharmony_ci	writel(val, qm->io_base + QM_DFX_DB_CNT_VF);
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci	tmp = val |
3838c2ecf20Sopenharmony_ci	      (readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) & CURRENT_Q_MASK);
3848c2ecf20Sopenharmony_ci	writel(tmp, qm->io_base + QM_DFX_SQE_CNT_VF_SQN);
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	tmp = val |
3878c2ecf20Sopenharmony_ci	      (readl(qm->io_base + QM_DFX_CQE_CNT_VF_CQN) & CURRENT_Q_MASK);
3888c2ecf20Sopenharmony_ci	writel(tmp, qm->io_base + QM_DFX_CQE_CNT_VF_CQN);
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	return  0;
3918c2ecf20Sopenharmony_ci}
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_cistatic u32 clear_enable_read(struct ctrl_debug_file *file)
3948c2ecf20Sopenharmony_ci{
3958c2ecf20Sopenharmony_ci	struct hisi_qm *qm = file_to_qm(file);
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	return readl(qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE) &
3988c2ecf20Sopenharmony_ci		     HZIP_SOFT_CTRL_CNT_CLR_CE_BIT;
3998c2ecf20Sopenharmony_ci}
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_cistatic int clear_enable_write(struct ctrl_debug_file *file, u32 val)
4028c2ecf20Sopenharmony_ci{
4038c2ecf20Sopenharmony_ci	struct hisi_qm *qm = file_to_qm(file);
4048c2ecf20Sopenharmony_ci	u32 tmp;
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	if (val != 1 && val != 0)
4078c2ecf20Sopenharmony_ci		return -EINVAL;
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci	tmp = (readl(qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE) &
4108c2ecf20Sopenharmony_ci	       ~HZIP_SOFT_CTRL_CNT_CLR_CE_BIT) | val;
4118c2ecf20Sopenharmony_ci	writel(tmp, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci	return  0;
4148c2ecf20Sopenharmony_ci}
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_cistatic ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf,
4178c2ecf20Sopenharmony_ci					size_t count, loff_t *pos)
4188c2ecf20Sopenharmony_ci{
4198c2ecf20Sopenharmony_ci	struct ctrl_debug_file *file = filp->private_data;
4208c2ecf20Sopenharmony_ci	char tbuf[HZIP_BUF_SIZE];
4218c2ecf20Sopenharmony_ci	u32 val;
4228c2ecf20Sopenharmony_ci	int ret;
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	spin_lock_irq(&file->lock);
4258c2ecf20Sopenharmony_ci	switch (file->index) {
4268c2ecf20Sopenharmony_ci	case HZIP_CURRENT_QM:
4278c2ecf20Sopenharmony_ci		val = current_qm_read(file);
4288c2ecf20Sopenharmony_ci		break;
4298c2ecf20Sopenharmony_ci	case HZIP_CLEAR_ENABLE:
4308c2ecf20Sopenharmony_ci		val = clear_enable_read(file);
4318c2ecf20Sopenharmony_ci		break;
4328c2ecf20Sopenharmony_ci	default:
4338c2ecf20Sopenharmony_ci		spin_unlock_irq(&file->lock);
4348c2ecf20Sopenharmony_ci		return -EINVAL;
4358c2ecf20Sopenharmony_ci	}
4368c2ecf20Sopenharmony_ci	spin_unlock_irq(&file->lock);
4378c2ecf20Sopenharmony_ci	ret = scnprintf(tbuf, sizeof(tbuf), "%u\n", val);
4388c2ecf20Sopenharmony_ci	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
4398c2ecf20Sopenharmony_ci}
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_cistatic ssize_t hisi_zip_ctrl_debug_write(struct file *filp,
4428c2ecf20Sopenharmony_ci					 const char __user *buf,
4438c2ecf20Sopenharmony_ci					 size_t count, loff_t *pos)
4448c2ecf20Sopenharmony_ci{
4458c2ecf20Sopenharmony_ci	struct ctrl_debug_file *file = filp->private_data;
4468c2ecf20Sopenharmony_ci	char tbuf[HZIP_BUF_SIZE];
4478c2ecf20Sopenharmony_ci	unsigned long val;
4488c2ecf20Sopenharmony_ci	int len, ret;
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci	if (*pos != 0)
4518c2ecf20Sopenharmony_ci		return 0;
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	if (count >= HZIP_BUF_SIZE)
4548c2ecf20Sopenharmony_ci		return -ENOSPC;
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	len = simple_write_to_buffer(tbuf, HZIP_BUF_SIZE - 1, pos, buf, count);
4578c2ecf20Sopenharmony_ci	if (len < 0)
4588c2ecf20Sopenharmony_ci		return len;
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	tbuf[len] = '\0';
4618c2ecf20Sopenharmony_ci	if (kstrtoul(tbuf, 0, &val))
4628c2ecf20Sopenharmony_ci		return -EFAULT;
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci	spin_lock_irq(&file->lock);
4658c2ecf20Sopenharmony_ci	switch (file->index) {
4668c2ecf20Sopenharmony_ci	case HZIP_CURRENT_QM:
4678c2ecf20Sopenharmony_ci		ret = current_qm_write(file, val);
4688c2ecf20Sopenharmony_ci		if (ret)
4698c2ecf20Sopenharmony_ci			goto err_input;
4708c2ecf20Sopenharmony_ci		break;
4718c2ecf20Sopenharmony_ci	case HZIP_CLEAR_ENABLE:
4728c2ecf20Sopenharmony_ci		ret = clear_enable_write(file, val);
4738c2ecf20Sopenharmony_ci		if (ret)
4748c2ecf20Sopenharmony_ci			goto err_input;
4758c2ecf20Sopenharmony_ci		break;
4768c2ecf20Sopenharmony_ci	default:
4778c2ecf20Sopenharmony_ci		ret = -EINVAL;
4788c2ecf20Sopenharmony_ci		goto err_input;
4798c2ecf20Sopenharmony_ci	}
4808c2ecf20Sopenharmony_ci	spin_unlock_irq(&file->lock);
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci	return count;
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_cierr_input:
4858c2ecf20Sopenharmony_ci	spin_unlock_irq(&file->lock);
4868c2ecf20Sopenharmony_ci	return ret;
4878c2ecf20Sopenharmony_ci}
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_cistatic const struct file_operations ctrl_debug_fops = {
4908c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
4918c2ecf20Sopenharmony_ci	.open = simple_open,
4928c2ecf20Sopenharmony_ci	.read = hisi_zip_ctrl_debug_read,
4938c2ecf20Sopenharmony_ci	.write = hisi_zip_ctrl_debug_write,
4948c2ecf20Sopenharmony_ci};
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_cistatic int zip_debugfs_atomic64_set(void *data, u64 val)
4978c2ecf20Sopenharmony_ci{
4988c2ecf20Sopenharmony_ci	if (val)
4998c2ecf20Sopenharmony_ci		return -EINVAL;
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci	atomic64_set((atomic64_t *)data, 0);
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci	return 0;
5048c2ecf20Sopenharmony_ci}
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_cistatic int zip_debugfs_atomic64_get(void *data, u64 *val)
5078c2ecf20Sopenharmony_ci{
5088c2ecf20Sopenharmony_ci	*val = atomic64_read((atomic64_t *)data);
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci	return 0;
5118c2ecf20Sopenharmony_ci}
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ciDEFINE_DEBUGFS_ATTRIBUTE(zip_atomic64_ops, zip_debugfs_atomic64_get,
5148c2ecf20Sopenharmony_ci			 zip_debugfs_atomic64_set, "%llu\n");
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_cistatic int hisi_zip_core_debug_init(struct hisi_qm *qm)
5178c2ecf20Sopenharmony_ci{
5188c2ecf20Sopenharmony_ci	struct device *dev = &qm->pdev->dev;
5198c2ecf20Sopenharmony_ci	struct debugfs_regset32 *regset;
5208c2ecf20Sopenharmony_ci	struct dentry *tmp_d;
5218c2ecf20Sopenharmony_ci	char buf[HZIP_BUF_SIZE];
5228c2ecf20Sopenharmony_ci	int i;
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci	for (i = 0; i < HZIP_CORE_NUM; i++) {
5258c2ecf20Sopenharmony_ci		if (i < HZIP_COMP_CORE_NUM)
5268c2ecf20Sopenharmony_ci			scnprintf(buf, sizeof(buf), "comp_core%d", i);
5278c2ecf20Sopenharmony_ci		else
5288c2ecf20Sopenharmony_ci			scnprintf(buf, sizeof(buf), "decomp_core%d",
5298c2ecf20Sopenharmony_ci				  i - HZIP_COMP_CORE_NUM);
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci		regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL);
5328c2ecf20Sopenharmony_ci		if (!regset)
5338c2ecf20Sopenharmony_ci			return -ENOENT;
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci		regset->regs = hzip_dfx_regs;
5368c2ecf20Sopenharmony_ci		regset->nregs = ARRAY_SIZE(hzip_dfx_regs);
5378c2ecf20Sopenharmony_ci		regset->base = qm->io_base + core_offsets[i];
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci		tmp_d = debugfs_create_dir(buf, qm->debug.debug_root);
5408c2ecf20Sopenharmony_ci		debugfs_create_regset32("regs", 0444, tmp_d, regset);
5418c2ecf20Sopenharmony_ci	}
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ci	return 0;
5448c2ecf20Sopenharmony_ci}
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_cistatic void hisi_zip_dfx_debug_init(struct hisi_qm *qm)
5478c2ecf20Sopenharmony_ci{
5488c2ecf20Sopenharmony_ci	struct hisi_zip *zip = container_of(qm, struct hisi_zip, qm);
5498c2ecf20Sopenharmony_ci	struct hisi_zip_dfx *dfx = &zip->dfx;
5508c2ecf20Sopenharmony_ci	struct dentry *tmp_dir;
5518c2ecf20Sopenharmony_ci	void *data;
5528c2ecf20Sopenharmony_ci	int i;
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci	tmp_dir = debugfs_create_dir("zip_dfx", qm->debug.debug_root);
5558c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(zip_dfx_files); i++) {
5568c2ecf20Sopenharmony_ci		data = (atomic64_t *)((uintptr_t)dfx + zip_dfx_files[i].offset);
5578c2ecf20Sopenharmony_ci		debugfs_create_file(zip_dfx_files[i].name,
5588c2ecf20Sopenharmony_ci				    0644, tmp_dir, data,
5598c2ecf20Sopenharmony_ci				    &zip_atomic64_ops);
5608c2ecf20Sopenharmony_ci	}
5618c2ecf20Sopenharmony_ci}
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_cistatic int hisi_zip_ctrl_debug_init(struct hisi_qm *qm)
5648c2ecf20Sopenharmony_ci{
5658c2ecf20Sopenharmony_ci	struct hisi_zip *zip = container_of(qm, struct hisi_zip, qm);
5668c2ecf20Sopenharmony_ci	int i;
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci	for (i = HZIP_CURRENT_QM; i < HZIP_DEBUG_FILE_NUM; i++) {
5698c2ecf20Sopenharmony_ci		spin_lock_init(&zip->ctrl->files[i].lock);
5708c2ecf20Sopenharmony_ci		zip->ctrl->files[i].ctrl = zip->ctrl;
5718c2ecf20Sopenharmony_ci		zip->ctrl->files[i].index = i;
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci		debugfs_create_file(ctrl_debug_file_name[i], 0600,
5748c2ecf20Sopenharmony_ci				    qm->debug.debug_root,
5758c2ecf20Sopenharmony_ci				    zip->ctrl->files + i,
5768c2ecf20Sopenharmony_ci				    &ctrl_debug_fops);
5778c2ecf20Sopenharmony_ci	}
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci	return hisi_zip_core_debug_init(qm);
5808c2ecf20Sopenharmony_ci}
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_cistatic int hisi_zip_debugfs_init(struct hisi_qm *qm)
5838c2ecf20Sopenharmony_ci{
5848c2ecf20Sopenharmony_ci	struct device *dev = &qm->pdev->dev;
5858c2ecf20Sopenharmony_ci	struct dentry *dev_d;
5868c2ecf20Sopenharmony_ci	int ret;
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_ci	dev_d = debugfs_create_dir(dev_name(dev), hzip_debugfs_root);
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci	qm->debug.sqe_mask_offset = HZIP_SQE_MASK_OFFSET;
5918c2ecf20Sopenharmony_ci	qm->debug.sqe_mask_len = HZIP_SQE_MASK_LEN;
5928c2ecf20Sopenharmony_ci	qm->debug.debug_root = dev_d;
5938c2ecf20Sopenharmony_ci	ret = hisi_qm_debug_init(qm);
5948c2ecf20Sopenharmony_ci	if (ret)
5958c2ecf20Sopenharmony_ci		goto failed_to_create;
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_ci	if (qm->fun_type == QM_HW_PF) {
5988c2ecf20Sopenharmony_ci		ret = hisi_zip_ctrl_debug_init(qm);
5998c2ecf20Sopenharmony_ci		if (ret)
6008c2ecf20Sopenharmony_ci			goto failed_to_create;
6018c2ecf20Sopenharmony_ci	}
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci	hisi_zip_dfx_debug_init(qm);
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ci	return 0;
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_cifailed_to_create:
6088c2ecf20Sopenharmony_ci	debugfs_remove_recursive(hzip_debugfs_root);
6098c2ecf20Sopenharmony_ci	return ret;
6108c2ecf20Sopenharmony_ci}
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ci/* hisi_zip_debug_regs_clear() - clear the zip debug regs */
6138c2ecf20Sopenharmony_cistatic void hisi_zip_debug_regs_clear(struct hisi_qm *qm)
6148c2ecf20Sopenharmony_ci{
6158c2ecf20Sopenharmony_ci	int i, j;
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci	/* clear current_qm */
6188c2ecf20Sopenharmony_ci	writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF);
6198c2ecf20Sopenharmony_ci	writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF);
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	/* enable register read_clear bit */
6228c2ecf20Sopenharmony_ci	writel(HZIP_RD_CNT_CLR_CE_EN, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);
6238c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(core_offsets); i++)
6248c2ecf20Sopenharmony_ci		for (j = 0; j < ARRAY_SIZE(hzip_dfx_regs); j++)
6258c2ecf20Sopenharmony_ci			readl(qm->io_base + core_offsets[i] +
6268c2ecf20Sopenharmony_ci			      hzip_dfx_regs[j].offset);
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ci	/* disable register read_clear bit */
6298c2ecf20Sopenharmony_ci	writel(0x0, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci	hisi_qm_debug_regs_clear(qm);
6328c2ecf20Sopenharmony_ci}
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_cistatic void hisi_zip_debugfs_exit(struct hisi_qm *qm)
6358c2ecf20Sopenharmony_ci{
6368c2ecf20Sopenharmony_ci	debugfs_remove_recursive(qm->debug.debug_root);
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci	if (qm->fun_type == QM_HW_PF) {
6398c2ecf20Sopenharmony_ci		hisi_zip_debug_regs_clear(qm);
6408c2ecf20Sopenharmony_ci		qm->debug.curr_qm_qp_num = 0;
6418c2ecf20Sopenharmony_ci	}
6428c2ecf20Sopenharmony_ci}
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_cistatic void hisi_zip_log_hw_error(struct hisi_qm *qm, u32 err_sts)
6458c2ecf20Sopenharmony_ci{
6468c2ecf20Sopenharmony_ci	const struct hisi_zip_hw_error *err = zip_hw_error;
6478c2ecf20Sopenharmony_ci	struct device *dev = &qm->pdev->dev;
6488c2ecf20Sopenharmony_ci	u32 err_val;
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci	while (err->msg) {
6518c2ecf20Sopenharmony_ci		if (err->int_msk & err_sts) {
6528c2ecf20Sopenharmony_ci			dev_err(dev, "%s [error status=0x%x] found\n",
6538c2ecf20Sopenharmony_ci				err->msg, err->int_msk);
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci			if (err->int_msk & HZIP_CORE_INT_STATUS_M_ECC) {
6568c2ecf20Sopenharmony_ci				err_val = readl(qm->io_base +
6578c2ecf20Sopenharmony_ci						HZIP_CORE_SRAM_ECC_ERR_INFO);
6588c2ecf20Sopenharmony_ci				dev_err(dev, "hisi-zip multi ecc sram num=0x%x\n",
6598c2ecf20Sopenharmony_ci					((err_val >>
6608c2ecf20Sopenharmony_ci					HZIP_SRAM_ECC_ERR_NUM_SHIFT) & 0xFF));
6618c2ecf20Sopenharmony_ci			}
6628c2ecf20Sopenharmony_ci		}
6638c2ecf20Sopenharmony_ci		err++;
6648c2ecf20Sopenharmony_ci	}
6658c2ecf20Sopenharmony_ci}
6668c2ecf20Sopenharmony_ci
6678c2ecf20Sopenharmony_cistatic u32 hisi_zip_get_hw_err_status(struct hisi_qm *qm)
6688c2ecf20Sopenharmony_ci{
6698c2ecf20Sopenharmony_ci	return readl(qm->io_base + HZIP_CORE_INT_STATUS);
6708c2ecf20Sopenharmony_ci}
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_cistatic void hisi_zip_clear_hw_err_status(struct hisi_qm *qm, u32 err_sts)
6738c2ecf20Sopenharmony_ci{
6748c2ecf20Sopenharmony_ci	writel(err_sts, qm->io_base + HZIP_CORE_INT_SOURCE);
6758c2ecf20Sopenharmony_ci}
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_cistatic void hisi_zip_open_axi_master_ooo(struct hisi_qm *qm)
6788c2ecf20Sopenharmony_ci{
6798c2ecf20Sopenharmony_ci	u32 val;
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_ci	val = readl(qm->io_base + HZIP_SOFT_CTRL_ZIP_CONTROL);
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci	writel(val & ~HZIP_AXI_SHUTDOWN_ENABLE,
6848c2ecf20Sopenharmony_ci	       qm->io_base + HZIP_SOFT_CTRL_ZIP_CONTROL);
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_ci	writel(val | HZIP_AXI_SHUTDOWN_ENABLE,
6878c2ecf20Sopenharmony_ci	       qm->io_base + HZIP_SOFT_CTRL_ZIP_CONTROL);
6888c2ecf20Sopenharmony_ci}
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_cistatic void hisi_zip_close_axi_master_ooo(struct hisi_qm *qm)
6918c2ecf20Sopenharmony_ci{
6928c2ecf20Sopenharmony_ci	u32 nfe_enb;
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	/* Disable ECC Mbit error report. */
6958c2ecf20Sopenharmony_ci	nfe_enb = readl(qm->io_base + HZIP_CORE_INT_RAS_NFE_ENB);
6968c2ecf20Sopenharmony_ci	writel(nfe_enb & ~HZIP_CORE_INT_STATUS_M_ECC,
6978c2ecf20Sopenharmony_ci	       qm->io_base + HZIP_CORE_INT_RAS_NFE_ENB);
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_ci	/* Inject zip ECC Mbit error to block master ooo. */
7008c2ecf20Sopenharmony_ci	writel(HZIP_CORE_INT_STATUS_M_ECC,
7018c2ecf20Sopenharmony_ci	       qm->io_base + HZIP_CORE_INT_SET);
7028c2ecf20Sopenharmony_ci}
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_cistatic const struct hisi_qm_err_ini hisi_zip_err_ini = {
7058c2ecf20Sopenharmony_ci	.hw_init		= hisi_zip_set_user_domain_and_cache,
7068c2ecf20Sopenharmony_ci	.hw_err_enable		= hisi_zip_hw_error_enable,
7078c2ecf20Sopenharmony_ci	.hw_err_disable		= hisi_zip_hw_error_disable,
7088c2ecf20Sopenharmony_ci	.get_dev_hw_err_status	= hisi_zip_get_hw_err_status,
7098c2ecf20Sopenharmony_ci	.clear_dev_hw_err_status = hisi_zip_clear_hw_err_status,
7108c2ecf20Sopenharmony_ci	.log_dev_hw_err		= hisi_zip_log_hw_error,
7118c2ecf20Sopenharmony_ci	.open_axi_master_ooo	= hisi_zip_open_axi_master_ooo,
7128c2ecf20Sopenharmony_ci	.close_axi_master_ooo	= hisi_zip_close_axi_master_ooo,
7138c2ecf20Sopenharmony_ci	.err_info		= {
7148c2ecf20Sopenharmony_ci		.ce			= QM_BASE_CE,
7158c2ecf20Sopenharmony_ci		.nfe			= QM_BASE_NFE |
7168c2ecf20Sopenharmony_ci					  QM_ACC_WB_NOT_READY_TIMEOUT,
7178c2ecf20Sopenharmony_ci		.fe			= 0,
7188c2ecf20Sopenharmony_ci		.ecc_2bits_mask		= HZIP_CORE_INT_STATUS_M_ECC,
7198c2ecf20Sopenharmony_ci		.msi_wr_port		= HZIP_WR_PORT,
7208c2ecf20Sopenharmony_ci		.acpi_rst		= "ZRST",
7218c2ecf20Sopenharmony_ci	}
7228c2ecf20Sopenharmony_ci};
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_cistatic int hisi_zip_pf_probe_init(struct hisi_zip *hisi_zip)
7258c2ecf20Sopenharmony_ci{
7268c2ecf20Sopenharmony_ci	struct hisi_qm *qm = &hisi_zip->qm;
7278c2ecf20Sopenharmony_ci	struct hisi_zip_ctrl *ctrl;
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci	ctrl = devm_kzalloc(&qm->pdev->dev, sizeof(*ctrl), GFP_KERNEL);
7308c2ecf20Sopenharmony_ci	if (!ctrl)
7318c2ecf20Sopenharmony_ci		return -ENOMEM;
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ci	hisi_zip->ctrl = ctrl;
7348c2ecf20Sopenharmony_ci	ctrl->hisi_zip = hisi_zip;
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci	if (qm->ver == QM_HW_V1)
7378c2ecf20Sopenharmony_ci		qm->ctrl_qp_num = HZIP_QUEUE_NUM_V1;
7388c2ecf20Sopenharmony_ci	else
7398c2ecf20Sopenharmony_ci		qm->ctrl_qp_num = HZIP_QUEUE_NUM_V2;
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_ci	qm->err_ini = &hisi_zip_err_ini;
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci	hisi_zip_set_user_domain_and_cache(qm);
7448c2ecf20Sopenharmony_ci	hisi_qm_dev_err_init(qm);
7458c2ecf20Sopenharmony_ci	hisi_zip_debug_regs_clear(qm);
7468c2ecf20Sopenharmony_ci
7478c2ecf20Sopenharmony_ci	return 0;
7488c2ecf20Sopenharmony_ci}
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_cistatic int hisi_zip_qm_init(struct hisi_qm *qm, struct pci_dev *pdev)
7518c2ecf20Sopenharmony_ci{
7528c2ecf20Sopenharmony_ci	qm->pdev = pdev;
7538c2ecf20Sopenharmony_ci	qm->ver = pdev->revision;
7548c2ecf20Sopenharmony_ci	qm->algs = "zlib\ngzip";
7558c2ecf20Sopenharmony_ci	qm->sqe_size = HZIP_SQE_SIZE;
7568c2ecf20Sopenharmony_ci	qm->dev_name = hisi_zip_name;
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_ci	qm->fun_type = (pdev->device == PCI_DEVICE_ID_ZIP_PF) ?
7598c2ecf20Sopenharmony_ci			QM_HW_PF : QM_HW_VF;
7608c2ecf20Sopenharmony_ci	if (qm->fun_type == QM_HW_PF) {
7618c2ecf20Sopenharmony_ci		qm->qp_base = HZIP_PF_DEF_Q_BASE;
7628c2ecf20Sopenharmony_ci		qm->qp_num = pf_q_num;
7638c2ecf20Sopenharmony_ci		qm->debug.curr_qm_qp_num = pf_q_num;
7648c2ecf20Sopenharmony_ci		qm->qm_list = &zip_devices;
7658c2ecf20Sopenharmony_ci	} else if (qm->fun_type == QM_HW_VF && qm->ver == QM_HW_V1) {
7668c2ecf20Sopenharmony_ci		/*
7678c2ecf20Sopenharmony_ci		 * have no way to get qm configure in VM in v1 hardware,
7688c2ecf20Sopenharmony_ci		 * so currently force PF to uses HZIP_PF_DEF_Q_NUM, and force
7698c2ecf20Sopenharmony_ci		 * to trigger only one VF in v1 hardware.
7708c2ecf20Sopenharmony_ci		 *
7718c2ecf20Sopenharmony_ci		 * v2 hardware has no such problem.
7728c2ecf20Sopenharmony_ci		 */
7738c2ecf20Sopenharmony_ci		qm->qp_base = HZIP_PF_DEF_Q_NUM;
7748c2ecf20Sopenharmony_ci		qm->qp_num = HZIP_QUEUE_NUM_V1 - HZIP_PF_DEF_Q_NUM;
7758c2ecf20Sopenharmony_ci	}
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci	return hisi_qm_init(qm);
7788c2ecf20Sopenharmony_ci}
7798c2ecf20Sopenharmony_ci
7808c2ecf20Sopenharmony_cistatic int hisi_zip_probe_init(struct hisi_zip *hisi_zip)
7818c2ecf20Sopenharmony_ci{
7828c2ecf20Sopenharmony_ci	struct hisi_qm *qm = &hisi_zip->qm;
7838c2ecf20Sopenharmony_ci	int ret;
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci	if (qm->fun_type == QM_HW_PF) {
7868c2ecf20Sopenharmony_ci		ret = hisi_zip_pf_probe_init(hisi_zip);
7878c2ecf20Sopenharmony_ci		if (ret)
7888c2ecf20Sopenharmony_ci			return ret;
7898c2ecf20Sopenharmony_ci	}
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci	return 0;
7928c2ecf20Sopenharmony_ci}
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_cistatic int hisi_zip_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7958c2ecf20Sopenharmony_ci{
7968c2ecf20Sopenharmony_ci	struct hisi_zip *hisi_zip;
7978c2ecf20Sopenharmony_ci	struct hisi_qm *qm;
7988c2ecf20Sopenharmony_ci	int ret;
7998c2ecf20Sopenharmony_ci
8008c2ecf20Sopenharmony_ci	hisi_zip = devm_kzalloc(&pdev->dev, sizeof(*hisi_zip), GFP_KERNEL);
8018c2ecf20Sopenharmony_ci	if (!hisi_zip)
8028c2ecf20Sopenharmony_ci		return -ENOMEM;
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci	qm = &hisi_zip->qm;
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_ci	ret = hisi_zip_qm_init(qm, pdev);
8078c2ecf20Sopenharmony_ci	if (ret) {
8088c2ecf20Sopenharmony_ci		pci_err(pdev, "Failed to init ZIP QM (%d)!\n", ret);
8098c2ecf20Sopenharmony_ci		return ret;
8108c2ecf20Sopenharmony_ci	}
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_ci	ret = hisi_zip_probe_init(hisi_zip);
8138c2ecf20Sopenharmony_ci	if (ret) {
8148c2ecf20Sopenharmony_ci		pci_err(pdev, "Failed to probe (%d)!\n", ret);
8158c2ecf20Sopenharmony_ci		goto err_qm_uninit;
8168c2ecf20Sopenharmony_ci	}
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ci	ret = hisi_qm_start(qm);
8198c2ecf20Sopenharmony_ci	if (ret)
8208c2ecf20Sopenharmony_ci		goto err_dev_err_uninit;
8218c2ecf20Sopenharmony_ci
8228c2ecf20Sopenharmony_ci	ret = hisi_zip_debugfs_init(qm);
8238c2ecf20Sopenharmony_ci	if (ret)
8248c2ecf20Sopenharmony_ci		pci_err(pdev, "failed to init debugfs (%d)!\n", ret);
8258c2ecf20Sopenharmony_ci
8268c2ecf20Sopenharmony_ci	ret = hisi_qm_alg_register(qm, &zip_devices);
8278c2ecf20Sopenharmony_ci	if (ret < 0) {
8288c2ecf20Sopenharmony_ci		pci_err(pdev, "failed to register driver to crypto!\n");
8298c2ecf20Sopenharmony_ci		goto err_qm_stop;
8308c2ecf20Sopenharmony_ci	}
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci	if (qm->uacce) {
8338c2ecf20Sopenharmony_ci		ret = uacce_register(qm->uacce);
8348c2ecf20Sopenharmony_ci		if (ret) {
8358c2ecf20Sopenharmony_ci			pci_err(pdev, "failed to register uacce (%d)!\n", ret);
8368c2ecf20Sopenharmony_ci			goto err_qm_alg_unregister;
8378c2ecf20Sopenharmony_ci		}
8388c2ecf20Sopenharmony_ci	}
8398c2ecf20Sopenharmony_ci
8408c2ecf20Sopenharmony_ci	if (qm->fun_type == QM_HW_PF && vfs_num > 0) {
8418c2ecf20Sopenharmony_ci		ret = hisi_qm_sriov_enable(pdev, vfs_num);
8428c2ecf20Sopenharmony_ci		if (ret < 0)
8438c2ecf20Sopenharmony_ci			goto err_qm_alg_unregister;
8448c2ecf20Sopenharmony_ci	}
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci	return 0;
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_cierr_qm_alg_unregister:
8498c2ecf20Sopenharmony_ci	hisi_qm_alg_unregister(qm, &zip_devices);
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_cierr_qm_stop:
8528c2ecf20Sopenharmony_ci	hisi_zip_debugfs_exit(qm);
8538c2ecf20Sopenharmony_ci	hisi_qm_stop(qm, QM_NORMAL);
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_cierr_dev_err_uninit:
8568c2ecf20Sopenharmony_ci	hisi_qm_dev_err_uninit(qm);
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_cierr_qm_uninit:
8598c2ecf20Sopenharmony_ci	hisi_qm_uninit(qm);
8608c2ecf20Sopenharmony_ci
8618c2ecf20Sopenharmony_ci	return ret;
8628c2ecf20Sopenharmony_ci}
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_cistatic void hisi_zip_remove(struct pci_dev *pdev)
8658c2ecf20Sopenharmony_ci{
8668c2ecf20Sopenharmony_ci	struct hisi_qm *qm = pci_get_drvdata(pdev);
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_ci	hisi_qm_wait_task_finish(qm, &zip_devices);
8698c2ecf20Sopenharmony_ci	hisi_qm_alg_unregister(qm, &zip_devices);
8708c2ecf20Sopenharmony_ci
8718c2ecf20Sopenharmony_ci	if (qm->fun_type == QM_HW_PF && qm->vfs_num)
8728c2ecf20Sopenharmony_ci		hisi_qm_sriov_disable(pdev, qm->is_frozen);
8738c2ecf20Sopenharmony_ci
8748c2ecf20Sopenharmony_ci	hisi_zip_debugfs_exit(qm);
8758c2ecf20Sopenharmony_ci	hisi_qm_stop(qm, QM_NORMAL);
8768c2ecf20Sopenharmony_ci	hisi_qm_dev_err_uninit(qm);
8778c2ecf20Sopenharmony_ci	hisi_qm_uninit(qm);
8788c2ecf20Sopenharmony_ci}
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_cistatic const struct pci_error_handlers hisi_zip_err_handler = {
8818c2ecf20Sopenharmony_ci	.error_detected	= hisi_qm_dev_err_detected,
8828c2ecf20Sopenharmony_ci	.slot_reset	= hisi_qm_dev_slot_reset,
8838c2ecf20Sopenharmony_ci	.reset_prepare	= hisi_qm_reset_prepare,
8848c2ecf20Sopenharmony_ci	.reset_done	= hisi_qm_reset_done,
8858c2ecf20Sopenharmony_ci};
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_cistatic struct pci_driver hisi_zip_pci_driver = {
8888c2ecf20Sopenharmony_ci	.name			= "hisi_zip",
8898c2ecf20Sopenharmony_ci	.id_table		= hisi_zip_dev_ids,
8908c2ecf20Sopenharmony_ci	.probe			= hisi_zip_probe,
8918c2ecf20Sopenharmony_ci	.remove			= hisi_zip_remove,
8928c2ecf20Sopenharmony_ci	.sriov_configure	= IS_ENABLED(CONFIG_PCI_IOV) ?
8938c2ecf20Sopenharmony_ci					hisi_qm_sriov_configure : NULL,
8948c2ecf20Sopenharmony_ci	.err_handler		= &hisi_zip_err_handler,
8958c2ecf20Sopenharmony_ci	.shutdown		= hisi_qm_dev_shutdown,
8968c2ecf20Sopenharmony_ci};
8978c2ecf20Sopenharmony_ci
8988c2ecf20Sopenharmony_cistatic void hisi_zip_register_debugfs(void)
8998c2ecf20Sopenharmony_ci{
9008c2ecf20Sopenharmony_ci	if (!debugfs_initialized())
9018c2ecf20Sopenharmony_ci		return;
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci	hzip_debugfs_root = debugfs_create_dir("hisi_zip", NULL);
9048c2ecf20Sopenharmony_ci}
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_cistatic void hisi_zip_unregister_debugfs(void)
9078c2ecf20Sopenharmony_ci{
9088c2ecf20Sopenharmony_ci	debugfs_remove_recursive(hzip_debugfs_root);
9098c2ecf20Sopenharmony_ci}
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_cistatic int __init hisi_zip_init(void)
9128c2ecf20Sopenharmony_ci{
9138c2ecf20Sopenharmony_ci	int ret;
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_ci	hisi_qm_init_list(&zip_devices);
9168c2ecf20Sopenharmony_ci	hisi_zip_register_debugfs();
9178c2ecf20Sopenharmony_ci
9188c2ecf20Sopenharmony_ci	ret = pci_register_driver(&hisi_zip_pci_driver);
9198c2ecf20Sopenharmony_ci	if (ret < 0) {
9208c2ecf20Sopenharmony_ci		hisi_zip_unregister_debugfs();
9218c2ecf20Sopenharmony_ci		pr_err("Failed to register pci driver.\n");
9228c2ecf20Sopenharmony_ci	}
9238c2ecf20Sopenharmony_ci
9248c2ecf20Sopenharmony_ci	return ret;
9258c2ecf20Sopenharmony_ci}
9268c2ecf20Sopenharmony_ci
9278c2ecf20Sopenharmony_cistatic void __exit hisi_zip_exit(void)
9288c2ecf20Sopenharmony_ci{
9298c2ecf20Sopenharmony_ci	pci_unregister_driver(&hisi_zip_pci_driver);
9308c2ecf20Sopenharmony_ci	hisi_zip_unregister_debugfs();
9318c2ecf20Sopenharmony_ci}
9328c2ecf20Sopenharmony_ci
9338c2ecf20Sopenharmony_cimodule_init(hisi_zip_init);
9348c2ecf20Sopenharmony_cimodule_exit(hisi_zip_exit);
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
9378c2ecf20Sopenharmony_ciMODULE_AUTHOR("Zhou Wang <wangzhou1@hisilicon.com>");
9388c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Driver for HiSilicon ZIP accelerator");
939