xref: /linux/drivers/crypto/intel/qat/qat_common/adf_accel_devices.h (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
1a4b16dadSTom Zanussi /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
2a4b16dadSTom Zanussi /* Copyright(c) 2014 - 2020 Intel Corporation */
3a4b16dadSTom Zanussi #ifndef ADF_ACCEL_DEVICES_H_
4a4b16dadSTom Zanussi #define ADF_ACCEL_DEVICES_H_
5a4b16dadSTom Zanussi #include <linux/interrupt.h>
6a4b16dadSTom Zanussi #include <linux/module.h>
7a4b16dadSTom Zanussi #include <linux/list.h>
8a4b16dadSTom Zanussi #include <linux/io.h>
9b6e4b6ebSLucas Segarra Fernandez #include <linux/pci.h>
10a4b16dadSTom Zanussi #include <linux/ratelimit.h>
11532d7f6bSShashank Gupta #include <linux/types.h>
120fce55e5SXin Zeng #include <linux/qat/qat_mig_dev.h>
13a4b16dadSTom Zanussi #include "adf_cfg_common.h"
14d9fb8408SDamian Muszynski #include "adf_rl.h"
1569e7649fSLucas Segarra Fernandez #include "adf_telemetry.h"
16a4b16dadSTom Zanussi #include "adf_pfvf_msg.h"
175da6a2d5SDamian Muszynski #include "icp_qat_hw.h"
18a4b16dadSTom Zanussi 
19a4b16dadSTom Zanussi #define ADF_DH895XCC_DEVICE_NAME "dh895xcc"
20a4b16dadSTom Zanussi #define ADF_DH895XCCVF_DEVICE_NAME "dh895xccvf"
21a4b16dadSTom Zanussi #define ADF_C62X_DEVICE_NAME "c6xx"
22a4b16dadSTom Zanussi #define ADF_C62XVF_DEVICE_NAME "c6xxvf"
23a4b16dadSTom Zanussi #define ADF_C3XXX_DEVICE_NAME "c3xxx"
24a4b16dadSTom Zanussi #define ADF_C3XXXVF_DEVICE_NAME "c3xxxvf"
25a4b16dadSTom Zanussi #define ADF_4XXX_DEVICE_NAME "4xxx"
26fcf60f4bSJie Wang #define ADF_420XX_DEVICE_NAME "420xx"
27a4b16dadSTom Zanussi #define ADF_4XXX_PCI_DEVICE_ID 0x4940
28a4b16dadSTom Zanussi #define ADF_4XXXIOV_PCI_DEVICE_ID 0x4941
29a4b16dadSTom Zanussi #define ADF_401XX_PCI_DEVICE_ID 0x4942
30a4b16dadSTom Zanussi #define ADF_401XXIOV_PCI_DEVICE_ID 0x4943
31a4b16dadSTom Zanussi #define ADF_402XX_PCI_DEVICE_ID 0x4944
32a4b16dadSTom Zanussi #define ADF_402XXIOV_PCI_DEVICE_ID 0x4945
33fcf60f4bSJie Wang #define ADF_420XX_PCI_DEVICE_ID 0x4946
34fcf60f4bSJie Wang #define ADF_420XXIOV_PCI_DEVICE_ID 0x4947
35a4b16dadSTom Zanussi #define ADF_DEVICE_FUSECTL_OFFSET 0x40
36a4b16dadSTom Zanussi #define ADF_DEVICE_LEGFUSE_OFFSET 0x4C
37a4b16dadSTom Zanussi #define ADF_DEVICE_FUSECTL_MASK 0x80000000
38a4b16dadSTom Zanussi #define ADF_PCI_MAX_BARS 3
39a4b16dadSTom Zanussi #define ADF_DEVICE_NAME_LENGTH 32
40a4b16dadSTom Zanussi #define ADF_ETR_MAX_RINGS_PER_BANK 16
414e4e2ed2SGiovanni Cabiddu #define ADF_MAX_MSIX_VECTOR_NAME 48
42a4b16dadSTom Zanussi #define ADF_DEVICE_NAME_PREFIX "qat_"
43a4b16dadSTom Zanussi 
44a4b16dadSTom Zanussi enum adf_accel_capabilities {
45a4b16dadSTom Zanussi 	ADF_ACCEL_CAPABILITIES_NULL = 0,
46a4b16dadSTom Zanussi 	ADF_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC = 1,
47a4b16dadSTom Zanussi 	ADF_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC = 2,
48a4b16dadSTom Zanussi 	ADF_ACCEL_CAPABILITIES_CIPHER = 4,
49a4b16dadSTom Zanussi 	ADF_ACCEL_CAPABILITIES_AUTHENTICATION = 8,
50a4b16dadSTom Zanussi 	ADF_ACCEL_CAPABILITIES_COMPRESSION = 32,
51a4b16dadSTom Zanussi 	ADF_ACCEL_CAPABILITIES_LZS_COMPRESSION = 64,
52a4b16dadSTom Zanussi 	ADF_ACCEL_CAPABILITIES_RANDOM_NUMBER = 128
53a4b16dadSTom Zanussi };
54a4b16dadSTom Zanussi 
55a4b16dadSTom Zanussi struct adf_bar {
56a4b16dadSTom Zanussi 	resource_size_t base_addr;
57a4b16dadSTom Zanussi 	void __iomem *virt_addr;
58a4b16dadSTom Zanussi 	resource_size_t size;
59a4b16dadSTom Zanussi };
60a4b16dadSTom Zanussi 
61a4b16dadSTom Zanussi struct adf_irq {
62a4b16dadSTom Zanussi 	bool enabled;
63a4b16dadSTom Zanussi 	char name[ADF_MAX_MSIX_VECTOR_NAME];
64a4b16dadSTom Zanussi };
65a4b16dadSTom Zanussi 
66a4b16dadSTom Zanussi struct adf_accel_msix {
67a4b16dadSTom Zanussi 	struct adf_irq *irqs;
68a4b16dadSTom Zanussi 	u32 num_entries;
69a4b16dadSTom Zanussi };
70a4b16dadSTom Zanussi 
71a4b16dadSTom Zanussi struct adf_accel_pci {
72a4b16dadSTom Zanussi 	struct pci_dev *pci_dev;
73a4b16dadSTom Zanussi 	struct adf_accel_msix msix_entries;
74a4b16dadSTom Zanussi 	struct adf_bar pci_bars[ADF_PCI_MAX_BARS];
75a4b16dadSTom Zanussi 	u8 revid;
76a4b16dadSTom Zanussi 	u8 sku;
77a4b16dadSTom Zanussi };
78a4b16dadSTom Zanussi 
79a4b16dadSTom Zanussi enum dev_state {
80a4b16dadSTom Zanussi 	DEV_DOWN = 0,
81a4b16dadSTom Zanussi 	DEV_UP
82a4b16dadSTom Zanussi };
83a4b16dadSTom Zanussi 
84a4b16dadSTom Zanussi enum dev_sku_info {
85a4b16dadSTom Zanussi 	DEV_SKU_1 = 0,
86a4b16dadSTom Zanussi 	DEV_SKU_2,
87a4b16dadSTom Zanussi 	DEV_SKU_3,
88a4b16dadSTom Zanussi 	DEV_SKU_4,
89a4b16dadSTom Zanussi 	DEV_SKU_VF,
90a4b16dadSTom Zanussi 	DEV_SKU_UNKNOWN,
91a4b16dadSTom Zanussi };
92a4b16dadSTom Zanussi 
93532d7f6bSShashank Gupta enum ras_errors {
94532d7f6bSShashank Gupta 	ADF_RAS_CORR,
95532d7f6bSShashank Gupta 	ADF_RAS_UNCORR,
96532d7f6bSShashank Gupta 	ADF_RAS_FATAL,
97532d7f6bSShashank Gupta 	ADF_RAS_ERRORS,
98532d7f6bSShashank Gupta };
99532d7f6bSShashank Gupta 
100532d7f6bSShashank Gupta struct adf_error_counters {
101532d7f6bSShashank Gupta 	atomic_t counter[ADF_RAS_ERRORS];
10265089000SDamian Muszynski 	bool sysfs_added;
103532d7f6bSShashank Gupta 	bool enabled;
104532d7f6bSShashank Gupta };
105532d7f6bSShashank Gupta 
get_sku_info(enum dev_sku_info info)106a4b16dadSTom Zanussi static inline const char *get_sku_info(enum dev_sku_info info)
107a4b16dadSTom Zanussi {
108a4b16dadSTom Zanussi 	switch (info) {
109a4b16dadSTom Zanussi 	case DEV_SKU_1:
110a4b16dadSTom Zanussi 		return "SKU1";
111a4b16dadSTom Zanussi 	case DEV_SKU_2:
112a4b16dadSTom Zanussi 		return "SKU2";
113a4b16dadSTom Zanussi 	case DEV_SKU_3:
114a4b16dadSTom Zanussi 		return "SKU3";
115a4b16dadSTom Zanussi 	case DEV_SKU_4:
116a4b16dadSTom Zanussi 		return "SKU4";
117a4b16dadSTom Zanussi 	case DEV_SKU_VF:
118a4b16dadSTom Zanussi 		return "SKUVF";
119a4b16dadSTom Zanussi 	case DEV_SKU_UNKNOWN:
120a4b16dadSTom Zanussi 	default:
121a4b16dadSTom Zanussi 		break;
122a4b16dadSTom Zanussi 	}
123a4b16dadSTom Zanussi 	return "Unknown SKU";
124a4b16dadSTom Zanussi }
125a4b16dadSTom Zanussi 
126a4b16dadSTom Zanussi struct adf_hw_device_class {
127a4b16dadSTom Zanussi 	const char *name;
128a4b16dadSTom Zanussi 	const enum adf_device_type type;
129a4b16dadSTom Zanussi 	u32 instances;
130a4b16dadSTom Zanussi };
131a4b16dadSTom Zanussi 
132a4b16dadSTom Zanussi struct arb_info {
133a4b16dadSTom Zanussi 	u32 arb_cfg;
134a4b16dadSTom Zanussi 	u32 arb_offset;
135a4b16dadSTom Zanussi 	u32 wt2sam_offset;
136a4b16dadSTom Zanussi };
137a4b16dadSTom Zanussi 
138a4b16dadSTom Zanussi struct admin_info {
139a4b16dadSTom Zanussi 	u32 admin_msg_ur;
140a4b16dadSTom Zanussi 	u32 admin_msg_lr;
141a4b16dadSTom Zanussi 	u32 mailbox_offset;
142a4b16dadSTom Zanussi };
143a4b16dadSTom Zanussi 
144bbfdde7dSSiming Wan struct ring_config {
145bbfdde7dSSiming Wan 	u64 base;
146bbfdde7dSSiming Wan 	u32 config;
147bbfdde7dSSiming Wan 	u32 head;
148bbfdde7dSSiming Wan 	u32 tail;
149bbfdde7dSSiming Wan 	u32 reserved0;
150bbfdde7dSSiming Wan };
151bbfdde7dSSiming Wan 
152bbfdde7dSSiming Wan struct bank_state {
153bbfdde7dSSiming Wan 	u32 ringstat0;
154bbfdde7dSSiming Wan 	u32 ringstat1;
155bbfdde7dSSiming Wan 	u32 ringuostat;
156bbfdde7dSSiming Wan 	u32 ringestat;
157bbfdde7dSSiming Wan 	u32 ringnestat;
158bbfdde7dSSiming Wan 	u32 ringnfstat;
159bbfdde7dSSiming Wan 	u32 ringfstat;
160bbfdde7dSSiming Wan 	u32 ringcstat0;
161bbfdde7dSSiming Wan 	u32 ringcstat1;
162bbfdde7dSSiming Wan 	u32 ringcstat2;
163bbfdde7dSSiming Wan 	u32 ringcstat3;
164bbfdde7dSSiming Wan 	u32 iaintflagen;
165bbfdde7dSSiming Wan 	u32 iaintflagreg;
166bbfdde7dSSiming Wan 	u32 iaintflagsrcsel0;
167bbfdde7dSSiming Wan 	u32 iaintflagsrcsel1;
168bbfdde7dSSiming Wan 	u32 iaintcolen;
169bbfdde7dSSiming Wan 	u32 iaintcolctl;
170bbfdde7dSSiming Wan 	u32 iaintflagandcolen;
171bbfdde7dSSiming Wan 	u32 ringexpstat;
172bbfdde7dSSiming Wan 	u32 ringexpintenable;
173bbfdde7dSSiming Wan 	u32 ringsrvarben;
174bbfdde7dSSiming Wan 	u32 reserved0;
175bbfdde7dSSiming Wan 	struct ring_config rings[ADF_ETR_MAX_RINGS_PER_BANK];
176bbfdde7dSSiming Wan };
177bbfdde7dSSiming Wan 
178a4b16dadSTom Zanussi struct adf_hw_csr_ops {
179a4b16dadSTom Zanussi 	u64 (*build_csr_ring_base_addr)(dma_addr_t addr, u32 size);
180a4b16dadSTom Zanussi 	u32 (*read_csr_ring_head)(void __iomem *csr_base_addr, u32 bank,
181a4b16dadSTom Zanussi 				  u32 ring);
182a4b16dadSTom Zanussi 	void (*write_csr_ring_head)(void __iomem *csr_base_addr, u32 bank,
183a4b16dadSTom Zanussi 				    u32 ring, u32 value);
184a4b16dadSTom Zanussi 	u32 (*read_csr_ring_tail)(void __iomem *csr_base_addr, u32 bank,
185a4b16dadSTom Zanussi 				  u32 ring);
186a4b16dadSTom Zanussi 	void (*write_csr_ring_tail)(void __iomem *csr_base_addr, u32 bank,
187a4b16dadSTom Zanussi 				    u32 ring, u32 value);
1883fa1057eSSiming Wan 	u32 (*read_csr_stat)(void __iomem *csr_base_addr, u32 bank);
1893fa1057eSSiming Wan 	u32 (*read_csr_uo_stat)(void __iomem *csr_base_addr, u32 bank);
190a4b16dadSTom Zanussi 	u32 (*read_csr_e_stat)(void __iomem *csr_base_addr, u32 bank);
1913fa1057eSSiming Wan 	u32 (*read_csr_ne_stat)(void __iomem *csr_base_addr, u32 bank);
1923fa1057eSSiming Wan 	u32 (*read_csr_nf_stat)(void __iomem *csr_base_addr, u32 bank);
1933fa1057eSSiming Wan 	u32 (*read_csr_f_stat)(void __iomem *csr_base_addr, u32 bank);
1943fa1057eSSiming Wan 	u32 (*read_csr_c_stat)(void __iomem *csr_base_addr, u32 bank);
1953fa1057eSSiming Wan 	u32 (*read_csr_exp_stat)(void __iomem *csr_base_addr, u32 bank);
1963fa1057eSSiming Wan 	u32 (*read_csr_exp_int_en)(void __iomem *csr_base_addr, u32 bank);
1973fa1057eSSiming Wan 	void (*write_csr_exp_int_en)(void __iomem *csr_base_addr, u32 bank,
1983fa1057eSSiming Wan 				     u32 value);
1993fa1057eSSiming Wan 	u32 (*read_csr_ring_config)(void __iomem *csr_base_addr, u32 bank,
2003fa1057eSSiming Wan 				    u32 ring);
201a4b16dadSTom Zanussi 	void (*write_csr_ring_config)(void __iomem *csr_base_addr, u32 bank,
202a4b16dadSTom Zanussi 				      u32 ring, u32 value);
2033fa1057eSSiming Wan 	dma_addr_t (*read_csr_ring_base)(void __iomem *csr_base_addr, u32 bank,
2043fa1057eSSiming Wan 					 u32 ring);
205a4b16dadSTom Zanussi 	void (*write_csr_ring_base)(void __iomem *csr_base_addr, u32 bank,
206a4b16dadSTom Zanussi 				    u32 ring, dma_addr_t addr);
2073fa1057eSSiming Wan 	u32 (*read_csr_int_en)(void __iomem *csr_base_addr, u32 bank);
2083fa1057eSSiming Wan 	void (*write_csr_int_en)(void __iomem *csr_base_addr, u32 bank,
2093fa1057eSSiming Wan 				 u32 value);
2103fa1057eSSiming Wan 	u32 (*read_csr_int_flag)(void __iomem *csr_base_addr, u32 bank);
211a4b16dadSTom Zanussi 	void (*write_csr_int_flag)(void __iomem *csr_base_addr, u32 bank,
212a4b16dadSTom Zanussi 				   u32 value);
2133fa1057eSSiming Wan 	u32 (*read_csr_int_srcsel)(void __iomem *csr_base_addr, u32 bank);
214a4b16dadSTom Zanussi 	void (*write_csr_int_srcsel)(void __iomem *csr_base_addr, u32 bank);
2153fa1057eSSiming Wan 	void (*write_csr_int_srcsel_w_val)(void __iomem *csr_base_addr,
2163fa1057eSSiming Wan 					   u32 bank, u32 value);
2173fa1057eSSiming Wan 	u32 (*read_csr_int_col_en)(void __iomem *csr_base_addr, u32 bank);
218a4b16dadSTom Zanussi 	void (*write_csr_int_col_en)(void __iomem *csr_base_addr, u32 bank,
219a4b16dadSTom Zanussi 				     u32 value);
2203fa1057eSSiming Wan 	u32 (*read_csr_int_col_ctl)(void __iomem *csr_base_addr, u32 bank);
221a4b16dadSTom Zanussi 	void (*write_csr_int_col_ctl)(void __iomem *csr_base_addr, u32 bank,
222a4b16dadSTom Zanussi 				      u32 value);
2233fa1057eSSiming Wan 	u32 (*read_csr_int_flag_and_col)(void __iomem *csr_base_addr,
2243fa1057eSSiming Wan 					 u32 bank);
225a4b16dadSTom Zanussi 	void (*write_csr_int_flag_and_col)(void __iomem *csr_base_addr,
226a4b16dadSTom Zanussi 					   u32 bank, u32 value);
2273fa1057eSSiming Wan 	u32 (*read_csr_ring_srv_arb_en)(void __iomem *csr_base_addr, u32 bank);
228a4b16dadSTom Zanussi 	void (*write_csr_ring_srv_arb_en)(void __iomem *csr_base_addr, u32 bank,
229a4b16dadSTom Zanussi 					  u32 value);
2303fa1057eSSiming Wan 	u32 (*get_int_col_ctl_enable_mask)(void);
231a4b16dadSTom Zanussi };
232a4b16dadSTom Zanussi 
233a4b16dadSTom Zanussi struct adf_cfg_device_data;
234a4b16dadSTom Zanussi struct adf_accel_dev;
235a4b16dadSTom Zanussi struct adf_etr_data;
236a4b16dadSTom Zanussi struct adf_etr_ring_data;
237a4b16dadSTom Zanussi 
23893b2f7deSShashank Gupta struct adf_ras_ops {
23993b2f7deSShashank Gupta 	void (*enable_ras_errors)(struct adf_accel_dev *accel_dev);
24093b2f7deSShashank Gupta 	void (*disable_ras_errors)(struct adf_accel_dev *accel_dev);
24193b2f7deSShashank Gupta 	bool (*handle_interrupt)(struct adf_accel_dev *accel_dev,
24293b2f7deSShashank Gupta 				 bool *reset_required);
24393b2f7deSShashank Gupta };
24493b2f7deSShashank Gupta 
245a4b16dadSTom Zanussi struct adf_pfvf_ops {
246a4b16dadSTom Zanussi 	int (*enable_comms)(struct adf_accel_dev *accel_dev);
247a4b16dadSTom Zanussi 	u32 (*get_pf2vf_offset)(u32 i);
248a4b16dadSTom Zanussi 	u32 (*get_vf2pf_offset)(u32 i);
249a4b16dadSTom Zanussi 	void (*enable_vf2pf_interrupts)(void __iomem *pmisc_addr, u32 vf_mask);
250a4b16dadSTom Zanussi 	void (*disable_all_vf2pf_interrupts)(void __iomem *pmisc_addr);
251a4b16dadSTom Zanussi 	u32 (*disable_pending_vf2pf_interrupts)(void __iomem *pmisc_addr);
252a4b16dadSTom Zanussi 	int (*send_msg)(struct adf_accel_dev *accel_dev, struct pfvf_message msg,
253a4b16dadSTom Zanussi 			u32 pfvf_offset, struct mutex *csr_lock);
254a4b16dadSTom Zanussi 	struct pfvf_message (*recv_msg)(struct adf_accel_dev *accel_dev,
255a4b16dadSTom Zanussi 					u32 pfvf_offset, u8 compat_ver);
256a4b16dadSTom Zanussi };
257a4b16dadSTom Zanussi 
258a4b16dadSTom Zanussi struct adf_dc_ops {
259a4b16dadSTom Zanussi 	void (*build_deflate_ctx)(void *ctx);
260a4b16dadSTom Zanussi };
261a4b16dadSTom Zanussi 
2620fce55e5SXin Zeng struct qat_migdev_ops {
2630fce55e5SXin Zeng 	int (*init)(struct qat_mig_dev *mdev);
2640fce55e5SXin Zeng 	void (*cleanup)(struct qat_mig_dev *mdev);
2650fce55e5SXin Zeng 	void (*reset)(struct qat_mig_dev *mdev);
2660fce55e5SXin Zeng 	int (*open)(struct qat_mig_dev *mdev);
2670fce55e5SXin Zeng 	void (*close)(struct qat_mig_dev *mdev);
2680fce55e5SXin Zeng 	int (*suspend)(struct qat_mig_dev *mdev);
2690fce55e5SXin Zeng 	int (*resume)(struct qat_mig_dev *mdev);
2700fce55e5SXin Zeng 	int (*save_state)(struct qat_mig_dev *mdev);
2710fce55e5SXin Zeng 	int (*save_setup)(struct qat_mig_dev *mdev);
2720fce55e5SXin Zeng 	int (*load_state)(struct qat_mig_dev *mdev);
2730fce55e5SXin Zeng 	int (*load_setup)(struct qat_mig_dev *mdev, int size);
2740fce55e5SXin Zeng };
2750fce55e5SXin Zeng 
2764926e89dSShashank Gupta struct adf_dev_err_mask {
2774926e89dSShashank Gupta 	u32 cppagentcmdpar_mask;
278895f7d53SShashank Gupta 	u32 parerr_ath_cph_mask;
279895f7d53SShashank Gupta 	u32 parerr_cpr_xlt_mask;
280895f7d53SShashank Gupta 	u32 parerr_dcpr_ucs_mask;
281895f7d53SShashank Gupta 	u32 parerr_pke_mask;
282895f7d53SShashank Gupta 	u32 parerr_wat_wcp_mask;
283895f7d53SShashank Gupta 	u32 ssmfeatren_mask;
2844926e89dSShashank Gupta };
2854926e89dSShashank Gupta 
286a4b16dadSTom Zanussi struct adf_hw_device_data {
287a4b16dadSTom Zanussi 	struct adf_hw_device_class *dev_class;
288a4b16dadSTom Zanussi 	u32 (*get_accel_mask)(struct adf_hw_device_data *self);
289a4b16dadSTom Zanussi 	u32 (*get_ae_mask)(struct adf_hw_device_data *self);
290a4b16dadSTom Zanussi 	u32 (*get_accel_cap)(struct adf_accel_dev *accel_dev);
291a4b16dadSTom Zanussi 	u32 (*get_sram_bar_id)(struct adf_hw_device_data *self);
292a4b16dadSTom Zanussi 	u32 (*get_misc_bar_id)(struct adf_hw_device_data *self);
293a4b16dadSTom Zanussi 	u32 (*get_etr_bar_id)(struct adf_hw_device_data *self);
294a4b16dadSTom Zanussi 	u32 (*get_num_aes)(struct adf_hw_device_data *self);
295a4b16dadSTom Zanussi 	u32 (*get_num_accels)(struct adf_hw_device_data *self);
296a4b16dadSTom Zanussi 	void (*get_arb_info)(struct arb_info *arb_csrs_info);
297a4b16dadSTom Zanussi 	void (*get_admin_info)(struct admin_info *admin_csrs_info);
298a4b16dadSTom Zanussi 	enum dev_sku_info (*get_sku)(struct adf_hw_device_data *self);
299a238487fSGiovanni Cabiddu 	u16 (*get_ring_to_svc_map)(struct adf_accel_dev *accel_dev);
300a4b16dadSTom Zanussi 	int (*alloc_irq)(struct adf_accel_dev *accel_dev);
301a4b16dadSTom Zanussi 	void (*free_irq)(struct adf_accel_dev *accel_dev);
302a4b16dadSTom Zanussi 	void (*enable_error_correction)(struct adf_accel_dev *accel_dev);
303a4b16dadSTom Zanussi 	int (*init_admin_comms)(struct adf_accel_dev *accel_dev);
304a4b16dadSTom Zanussi 	void (*exit_admin_comms)(struct adf_accel_dev *accel_dev);
305a4b16dadSTom Zanussi 	int (*send_admin_init)(struct adf_accel_dev *accel_dev);
306fd77d8daSDamian Muszynski 	int (*start_timer)(struct adf_accel_dev *accel_dev);
307fd77d8daSDamian Muszynski 	void (*stop_timer)(struct adf_accel_dev *accel_dev);
308bec61a29SDamian Muszynski 	void (*check_hb_ctrs)(struct adf_accel_dev *accel_dev);
309e2980ba5SDamian Muszynski 	uint32_t (*get_hb_clock)(struct adf_hw_device_data *self);
310e2980ba5SDamian Muszynski 	int (*measure_clock)(struct adf_accel_dev *accel_dev);
311a4b16dadSTom Zanussi 	int (*init_arb)(struct adf_accel_dev *accel_dev);
312a4b16dadSTom Zanussi 	void (*exit_arb)(struct adf_accel_dev *accel_dev);
313a4b16dadSTom Zanussi 	const u32 *(*get_arb_mapping)(struct adf_accel_dev *accel_dev);
314a4b16dadSTom Zanussi 	int (*init_device)(struct adf_accel_dev *accel_dev);
315a4b16dadSTom Zanussi 	int (*enable_pm)(struct adf_accel_dev *accel_dev);
316a4b16dadSTom Zanussi 	bool (*handle_pm_interrupt)(struct adf_accel_dev *accel_dev);
317a4b16dadSTom Zanussi 	void (*disable_iov)(struct adf_accel_dev *accel_dev);
318a4b16dadSTom Zanussi 	void (*configure_iov_threads)(struct adf_accel_dev *accel_dev,
319a4b16dadSTom Zanussi 				      bool enable);
320a4b16dadSTom Zanussi 	void (*enable_ints)(struct adf_accel_dev *accel_dev);
321a4b16dadSTom Zanussi 	void (*set_ssm_wdtimer)(struct adf_accel_dev *accel_dev);
322a4b16dadSTom Zanussi 	int (*ring_pair_reset)(struct adf_accel_dev *accel_dev, u32 bank_nr);
323bbfdde7dSSiming Wan 	int (*bank_state_save)(struct adf_accel_dev *accel_dev, u32 bank_number,
324bbfdde7dSSiming Wan 			       struct bank_state *state);
325bbfdde7dSSiming Wan 	int (*bank_state_restore)(struct adf_accel_dev *accel_dev,
326bbfdde7dSSiming Wan 				  u32 bank_number, struct bank_state *state);
327a4b16dadSTom Zanussi 	void (*reset_device)(struct adf_accel_dev *accel_dev);
328a4b16dadSTom Zanussi 	void (*set_msix_rttable)(struct adf_accel_dev *accel_dev);
32952f9a284SGiovanni Cabiddu 	const char *(*uof_get_name)(struct adf_accel_dev *accel_dev, u32 obj_num);
330b34bd0fdSJie Wang 	u32 (*uof_get_num_objs)(struct adf_accel_dev *accel_dev);
331ed3d95feSDamian Muszynski 	int (*uof_get_obj_type)(struct adf_accel_dev *accel_dev, u32 obj_num);
332a4b16dadSTom Zanussi 	u32 (*uof_get_ae_mask)(struct adf_accel_dev *accel_dev, u32 obj_num);
3335da6a2d5SDamian Muszynski 	int (*get_rp_group)(struct adf_accel_dev *accel_dev, u32 ae_mask);
3345da6a2d5SDamian Muszynski 	u32 (*get_ena_thd_mask)(struct adf_accel_dev *accel_dev, u32 obj_num);
335a4b16dadSTom Zanussi 	int (*dev_config)(struct adf_accel_dev *accel_dev);
336a4b16dadSTom Zanussi 	struct adf_pfvf_ops pfvf_ops;
337a4b16dadSTom Zanussi 	struct adf_hw_csr_ops csr_ops;
338a4b16dadSTom Zanussi 	struct adf_dc_ops dc_ops;
33993b2f7deSShashank Gupta 	struct adf_ras_ops ras_ops;
3404926e89dSShashank Gupta 	struct adf_dev_err_mask dev_err_mask;
341d9fb8408SDamian Muszynski 	struct adf_rl_hw_data rl_data;
34269e7649fSLucas Segarra Fernandez 	struct adf_tl_hw_data tl_data;
3430fce55e5SXin Zeng 	struct qat_migdev_ops vfmig_ops;
344a4b16dadSTom Zanussi 	const char *fw_name;
345a4b16dadSTom Zanussi 	const char *fw_mmp_name;
346a4b16dadSTom Zanussi 	u32 fuses;
347a4b16dadSTom Zanussi 	u32 straps;
348a4b16dadSTom Zanussi 	u32 accel_capabilities_mask;
349a4b16dadSTom Zanussi 	u32 extended_dc_capabilities;
350c7fd5379SDamian Muszynski 	u16 fw_capabilities;
351a4b16dadSTom Zanussi 	u32 clock_frequency;
352a4b16dadSTom Zanussi 	u32 instance_id;
353a4b16dadSTom Zanussi 	u16 accel_mask;
354a4b16dadSTom Zanussi 	u32 ae_mask;
355a4b16dadSTom Zanussi 	u32 admin_ae_mask;
356a4b16dadSTom Zanussi 	u16 tx_rings_mask;
357a4b16dadSTom Zanussi 	u16 ring_to_svc_map;
3585da6a2d5SDamian Muszynski 	u32 thd_to_arb_map[ICP_QAT_HW_AE_DELIMITER];
359a4b16dadSTom Zanussi 	u8 tx_rx_gap;
360a4b16dadSTom Zanussi 	u8 num_banks;
361a4b16dadSTom Zanussi 	u16 num_banks_per_vf;
362a4b16dadSTom Zanussi 	u8 num_rings_per_bank;
363a4b16dadSTom Zanussi 	u8 num_accel;
364a4b16dadSTom Zanussi 	u8 num_logical_accel;
365a4b16dadSTom Zanussi 	u8 num_engines;
366359b84f8SDamian Muszynski 	u32 num_hb_ctrs;
367eb527077SLucas Segarra Fernandez 	u8 num_rps;
368a4b16dadSTom Zanussi };
369a4b16dadSTom Zanussi 
370a4b16dadSTom Zanussi /* CSR write macro */
371a4b16dadSTom Zanussi #define ADF_CSR_WR(csr_base, csr_offset, val) \
372a4b16dadSTom Zanussi 	__raw_writel(val, csr_base + csr_offset)
373a4b16dadSTom Zanussi 
374a4b16dadSTom Zanussi /* CSR read macro */
375a4b16dadSTom Zanussi #define ADF_CSR_RD(csr_base, csr_offset) __raw_readl(csr_base + csr_offset)
376a4b16dadSTom Zanussi 
377a4b16dadSTom Zanussi #define ADF_CFG_NUM_SERVICES	4
378a4b16dadSTom Zanussi #define ADF_SRV_TYPE_BIT_LEN	3
379a4b16dadSTom Zanussi #define ADF_SRV_TYPE_MASK	0x7
380359b84f8SDamian Muszynski #define ADF_AE_ADMIN_THREAD	7
381359b84f8SDamian Muszynski #define ADF_NUM_THREADS_PER_AE	8
382359b84f8SDamian Muszynski #define ADF_NUM_PKE_STRAND	2
383359b84f8SDamian Muszynski #define ADF_AE_STRAND0_THREAD	8
384359b84f8SDamian Muszynski #define ADF_AE_STRAND1_THREAD	9
385a4b16dadSTom Zanussi 
386a4b16dadSTom Zanussi #define GET_DEV(accel_dev) ((accel_dev)->accel_pci_dev.pci_dev->dev)
387a4b16dadSTom Zanussi #define GET_BARS(accel_dev) ((accel_dev)->accel_pci_dev.pci_bars)
388a4b16dadSTom Zanussi #define GET_HW_DATA(accel_dev) (accel_dev->hw_device)
389a4b16dadSTom Zanussi #define GET_MAX_BANKS(accel_dev) (GET_HW_DATA(accel_dev)->num_banks)
390a4b16dadSTom Zanussi #define GET_NUM_RINGS_PER_BANK(accel_dev) \
391a4b16dadSTom Zanussi 	GET_HW_DATA(accel_dev)->num_rings_per_bank
392a4b16dadSTom Zanussi #define GET_SRV_TYPE(accel_dev, idx) \
393a4b16dadSTom Zanussi 	(((GET_HW_DATA(accel_dev)->ring_to_svc_map) >> (ADF_SRV_TYPE_BIT_LEN * (idx))) \
394a4b16dadSTom Zanussi 	& ADF_SRV_TYPE_MASK)
3954926e89dSShashank Gupta #define GET_ERR_MASK(accel_dev) (&GET_HW_DATA(accel_dev)->dev_err_mask)
396a4b16dadSTom Zanussi #define GET_MAX_ACCELENGINES(accel_dev) (GET_HW_DATA(accel_dev)->num_engines)
397a4b16dadSTom Zanussi #define GET_CSR_OPS(accel_dev) (&(accel_dev)->hw_device->csr_ops)
398a4b16dadSTom Zanussi #define GET_PFVF_OPS(accel_dev) (&(accel_dev)->hw_device->pfvf_ops)
399a4b16dadSTom Zanussi #define GET_DC_OPS(accel_dev) (&(accel_dev)->hw_device->dc_ops)
4000fce55e5SXin Zeng #define GET_VFMIG_OPS(accel_dev) (&(accel_dev)->hw_device->vfmig_ops)
40169e7649fSLucas Segarra Fernandez #define GET_TL_DATA(accel_dev) GET_HW_DATA(accel_dev)->tl_data
402a4b16dadSTom Zanussi #define accel_to_pci_dev(accel_ptr) accel_ptr->accel_pci_dev.pci_dev
403a4b16dadSTom Zanussi 
404a4b16dadSTom Zanussi struct adf_admin_comms;
405a4b16dadSTom Zanussi struct icp_qat_fw_loader_handle;
406a4b16dadSTom Zanussi struct adf_fw_loader_data {
407a4b16dadSTom Zanussi 	struct icp_qat_fw_loader_handle *fw_loader;
408a4b16dadSTom Zanussi 	const struct firmware *uof_fw;
409a4b16dadSTom Zanussi 	const struct firmware *mmp_fw;
410a4b16dadSTom Zanussi };
411a4b16dadSTom Zanussi 
412a4b16dadSTom Zanussi struct adf_accel_vf_info {
413a4b16dadSTom Zanussi 	struct adf_accel_dev *accel_dev;
414a4b16dadSTom Zanussi 	struct mutex pf2vf_lock; /* protect CSR access for PF2VF messages */
415*f0bbfc39SXin Zeng 	struct mutex pfvf_mig_lock; /* protects PFVF state for migration */
416a4b16dadSTom Zanussi 	struct ratelimit_state vf2pf_ratelimit;
417a4b16dadSTom Zanussi 	u32 vf_nr;
418a4b16dadSTom Zanussi 	bool init;
419ec26f8e6SMun Chun Yep 	bool restarting;
420a4b16dadSTom Zanussi 	u8 vf_compat_ver;
421*f0bbfc39SXin Zeng 	/*
422*f0bbfc39SXin Zeng 	 * Private area used for device migration.
423*f0bbfc39SXin Zeng 	 * Memory allocation and free is managed by migration driver.
424*f0bbfc39SXin Zeng 	 */
425*f0bbfc39SXin Zeng 	void *mig_priv;
426a4b16dadSTom Zanussi };
427a4b16dadSTom Zanussi 
428a4b16dadSTom Zanussi struct adf_dc_data {
429a4b16dadSTom Zanussi 	u8 *ovf_buff;
430a4b16dadSTom Zanussi 	size_t ovf_buff_sz;
431a4b16dadSTom Zanussi 	dma_addr_t ovf_buff_p;
432a4b16dadSTom Zanussi };
433a4b16dadSTom Zanussi 
434e0792316SLucas Segarra Fernandez struct adf_pm {
435e0792316SLucas Segarra Fernandez 	struct dentry *debugfs_pm_status;
436e0792316SLucas Segarra Fernandez 	bool present;
437e0792316SLucas Segarra Fernandez 	int idle_irq_counters;
438e0792316SLucas Segarra Fernandez 	int throttle_irq_counters;
439e0792316SLucas Segarra Fernandez 	int fw_irq_counters;
440e0792316SLucas Segarra Fernandez 	int host_ack_counter;
441e0792316SLucas Segarra Fernandez 	int host_nack_counter;
442e0792316SLucas Segarra Fernandez 	ssize_t (*print_pm_status)(struct adf_accel_dev *accel_dev,
443e0792316SLucas Segarra Fernandez 				   char __user *buf, size_t count, loff_t *pos);
444e0792316SLucas Segarra Fernandez };
445e0792316SLucas Segarra Fernandez 
446dbc8876dSCiunas Bennett struct adf_sysfs {
447dbc8876dSCiunas Bennett 	int ring_num;
448dbc8876dSCiunas Bennett 	struct rw_semaphore lock; /* protects access to the fields in this struct */
449dbc8876dSCiunas Bennett };
450dbc8876dSCiunas Bennett 
451a4b16dadSTom Zanussi struct adf_accel_dev {
452a4b16dadSTom Zanussi 	struct adf_etr_data *transport;
453a4b16dadSTom Zanussi 	struct adf_hw_device_data *hw_device;
454a4b16dadSTom Zanussi 	struct adf_cfg_device_data *cfg;
455a4b16dadSTom Zanussi 	struct adf_fw_loader_data *fw_loader;
456a4b16dadSTom Zanussi 	struct adf_admin_comms *admin;
45769e7649fSLucas Segarra Fernandez 	struct adf_telemetry *telemetry;
458a4b16dadSTom Zanussi 	struct adf_dc_data *dc_data;
459e0792316SLucas Segarra Fernandez 	struct adf_pm power_management;
460a4b16dadSTom Zanussi 	struct list_head crypto_list;
461a4b16dadSTom Zanussi 	struct list_head compression_list;
462a4b16dadSTom Zanussi 	unsigned long status;
463a4b16dadSTom Zanussi 	atomic_t ref_count;
464a4b16dadSTom Zanussi 	struct dentry *debugfs_dir;
465865b50feSLucas Segarra Fernandez 	struct dentry *fw_cntr_dbgfile;
466d807f024SLucas Segarra Fernandez 	struct dentry *cnv_dbgfile;
467a4b16dadSTom Zanussi 	struct list_head list;
468a4b16dadSTom Zanussi 	struct module *owner;
469a4b16dadSTom Zanussi 	struct adf_accel_pci accel_pci_dev;
470fd77d8daSDamian Muszynski 	struct adf_timer *timer;
471359b84f8SDamian Muszynski 	struct adf_heartbeat *heartbeat;
472d9fb8408SDamian Muszynski 	struct adf_rl *rate_limiting;
473dbc8876dSCiunas Bennett 	struct adf_sysfs sysfs;
474a4b16dadSTom Zanussi 	union {
475a4b16dadSTom Zanussi 		struct {
476a4b16dadSTom Zanussi 			/* protects VF2PF interrupts access */
477a4b16dadSTom Zanussi 			spinlock_t vf2pf_ints_lock;
478a4b16dadSTom Zanussi 			/* vf_info is non-zero when SR-IOV is init'ed */
479a4b16dadSTom Zanussi 			struct adf_accel_vf_info *vf_info;
480a4b16dadSTom Zanussi 		} pf;
481a4b16dadSTom Zanussi 		struct {
482a4b16dadSTom Zanussi 			bool irq_enabled;
483a4b16dadSTom Zanussi 			char irq_name[ADF_MAX_MSIX_VECTOR_NAME];
484a4b16dadSTom Zanussi 			struct tasklet_struct pf2vf_bh_tasklet;
485a4b16dadSTom Zanussi 			struct mutex vf2pf_lock; /* protect CSR access */
486a4b16dadSTom Zanussi 			struct completion msg_received;
487a4b16dadSTom Zanussi 			struct pfvf_message response; /* temp field holding pf2vf response */
488a4b16dadSTom Zanussi 			u8 pf_compat_ver;
489a4b16dadSTom Zanussi 		} vf;
490a4b16dadSTom Zanussi 	};
491532d7f6bSShashank Gupta 	struct adf_error_counters ras_errors;
492a4b16dadSTom Zanussi 	struct mutex state_lock; /* protect state of the device */
493a4b16dadSTom Zanussi 	bool is_vf;
494f5419a42SDamian Muszynski 	bool autoreset_on_error;
495a4b16dadSTom Zanussi 	u32 accel_id;
496a4b16dadSTom Zanussi };
497a4b16dadSTom Zanussi #endif
498