• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
2 /* Copyright(c) 2014 - 2020 Intel Corporation */
3 #ifndef ADF_ACCEL_DEVICES_H_
4 #define ADF_ACCEL_DEVICES_H_
5 #include <linux/interrupt.h>
6 #include <linux/module.h>
7 #include <linux/list.h>
8 #include <linux/io.h>
9 #include <linux/ratelimit.h>
10 #include "adf_cfg_common.h"
11 
12 #define ADF_DH895XCC_DEVICE_NAME "dh895xcc"
13 #define ADF_DH895XCCVF_DEVICE_NAME "dh895xccvf"
14 #define ADF_C62X_DEVICE_NAME "c6xx"
15 #define ADF_C62XVF_DEVICE_NAME "c6xxvf"
16 #define ADF_C3XXX_DEVICE_NAME "c3xxx"
17 #define ADF_C3XXXVF_DEVICE_NAME "c3xxxvf"
18 #define ADF_ERRSOU3 (0x3A000 + 0x0C)
19 #define ADF_ERRSOU5 (0x3A000 + 0xD8)
20 #define ADF_DEVICE_FUSECTL_OFFSET 0x40
21 #define ADF_DEVICE_LEGFUSE_OFFSET 0x4C
22 #define ADF_DEVICE_FUSECTL_MASK 0x80000000
23 #define ADF_PCI_MAX_BARS 3
24 #define ADF_DEVICE_NAME_LENGTH 32
25 #define ADF_ETR_MAX_RINGS_PER_BANK 16
26 #define ADF_MAX_MSIX_VECTOR_NAME 48
27 #define ADF_DEVICE_NAME_PREFIX "qat_"
28 
29 enum adf_accel_capabilities {
30 	ADF_ACCEL_CAPABILITIES_NULL = 0,
31 	ADF_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC = 1,
32 	ADF_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC = 2,
33 	ADF_ACCEL_CAPABILITIES_CIPHER = 4,
34 	ADF_ACCEL_CAPABILITIES_AUTHENTICATION = 8,
35 	ADF_ACCEL_CAPABILITIES_COMPRESSION = 32,
36 	ADF_ACCEL_CAPABILITIES_LZS_COMPRESSION = 64,
37 	ADF_ACCEL_CAPABILITIES_RANDOM_NUMBER = 128
38 };
39 
40 struct adf_bar {
41 	resource_size_t base_addr;
42 	void __iomem *virt_addr;
43 	resource_size_t size;
44 } __packed;
45 
46 struct adf_accel_msix {
47 	struct msix_entry *entries;
48 	char **names;
49 	u32 num_entries;
50 } __packed;
51 
52 struct adf_accel_pci {
53 	struct pci_dev *pci_dev;
54 	struct adf_accel_msix msix_entries;
55 	struct adf_bar pci_bars[ADF_PCI_MAX_BARS];
56 	u8 revid;
57 	u8 sku;
58 } __packed;
59 
60 enum dev_state {
61 	DEV_DOWN = 0,
62 	DEV_UP
63 };
64 
65 enum dev_sku_info {
66 	DEV_SKU_1 = 0,
67 	DEV_SKU_2,
68 	DEV_SKU_3,
69 	DEV_SKU_4,
70 	DEV_SKU_VF,
71 	DEV_SKU_UNKNOWN,
72 };
73 
get_sku_info(enum dev_sku_info info)74 static inline const char *get_sku_info(enum dev_sku_info info)
75 {
76 	switch (info) {
77 	case DEV_SKU_1:
78 		return "SKU1";
79 	case DEV_SKU_2:
80 		return "SKU2";
81 	case DEV_SKU_3:
82 		return "SKU3";
83 	case DEV_SKU_4:
84 		return "SKU4";
85 	case DEV_SKU_VF:
86 		return "SKUVF";
87 	case DEV_SKU_UNKNOWN:
88 	default:
89 		break;
90 	}
91 	return "Unknown SKU";
92 }
93 
94 struct adf_hw_device_class {
95 	const char *name;
96 	const enum adf_device_type type;
97 	u32 instances;
98 } __packed;
99 
100 struct adf_cfg_device_data;
101 struct adf_accel_dev;
102 struct adf_etr_data;
103 struct adf_etr_ring_data;
104 
105 struct adf_hw_device_data {
106 	struct adf_hw_device_class *dev_class;
107 	u32 (*get_accel_mask)(struct adf_hw_device_data *self);
108 	u32 (*get_ae_mask)(struct adf_hw_device_data *self);
109 	u32 (*get_sram_bar_id)(struct adf_hw_device_data *self);
110 	u32 (*get_misc_bar_id)(struct adf_hw_device_data *self);
111 	u32 (*get_etr_bar_id)(struct adf_hw_device_data *self);
112 	u32 (*get_num_aes)(struct adf_hw_device_data *self);
113 	u32 (*get_num_accels)(struct adf_hw_device_data *self);
114 	u32 (*get_pf2vf_offset)(u32 i);
115 	u32 (*get_vintmsk_offset)(u32 i);
116 	enum dev_sku_info (*get_sku)(struct adf_hw_device_data *self);
117 	int (*alloc_irq)(struct adf_accel_dev *accel_dev);
118 	void (*free_irq)(struct adf_accel_dev *accel_dev);
119 	void (*enable_error_correction)(struct adf_accel_dev *accel_dev);
120 	int (*init_admin_comms)(struct adf_accel_dev *accel_dev);
121 	void (*exit_admin_comms)(struct adf_accel_dev *accel_dev);
122 	int (*send_admin_init)(struct adf_accel_dev *accel_dev);
123 	int (*init_arb)(struct adf_accel_dev *accel_dev);
124 	void (*exit_arb)(struct adf_accel_dev *accel_dev);
125 	void (*get_arb_mapping)(struct adf_accel_dev *accel_dev,
126 				const u32 **cfg);
127 	void (*disable_iov)(struct adf_accel_dev *accel_dev);
128 	void (*enable_ints)(struct adf_accel_dev *accel_dev);
129 	int (*enable_vf2pf_comms)(struct adf_accel_dev *accel_dev);
130 	void (*reset_device)(struct adf_accel_dev *accel_dev);
131 	const char *fw_name;
132 	const char *fw_mmp_name;
133 	u32 fuses;
134 	u32 straps;
135 	u32 accel_capabilities_mask;
136 	u32 instance_id;
137 	u16 accel_mask;
138 	u16 ae_mask;
139 	u16 tx_rings_mask;
140 	u8 tx_rx_gap;
141 	u8 num_banks;
142 	u8 num_accel;
143 	u8 num_logical_accel;
144 	u8 num_engines;
145 	u8 min_iov_compat_ver;
146 } __packed;
147 
148 /* CSR write macro */
149 #define ADF_CSR_WR(csr_base, csr_offset, val) \
150 	__raw_writel(val, csr_base + csr_offset)
151 
152 /* CSR read macro */
153 #define ADF_CSR_RD(csr_base, csr_offset) __raw_readl(csr_base + csr_offset)
154 
155 #define GET_DEV(accel_dev) ((accel_dev)->accel_pci_dev.pci_dev->dev)
156 #define GET_BARS(accel_dev) ((accel_dev)->accel_pci_dev.pci_bars)
157 #define GET_HW_DATA(accel_dev) (accel_dev->hw_device)
158 #define GET_MAX_BANKS(accel_dev) (GET_HW_DATA(accel_dev)->num_banks)
159 #define GET_MAX_ACCELENGINES(accel_dev) (GET_HW_DATA(accel_dev)->num_engines)
160 #define accel_to_pci_dev(accel_ptr) accel_ptr->accel_pci_dev.pci_dev
161 
162 struct adf_admin_comms;
163 struct icp_qat_fw_loader_handle;
164 struct adf_fw_loader_data {
165 	struct icp_qat_fw_loader_handle *fw_loader;
166 	const struct firmware *uof_fw;
167 	const struct firmware *mmp_fw;
168 };
169 
170 struct adf_accel_vf_info {
171 	struct adf_accel_dev *accel_dev;
172 	struct tasklet_struct vf2pf_bh_tasklet;
173 	struct mutex pf2vf_lock; /* protect CSR access for PF2VF messages */
174 	struct ratelimit_state vf2pf_ratelimit;
175 	u32 vf_nr;
176 	bool init;
177 };
178 
179 struct adf_accel_dev {
180 	struct adf_etr_data *transport;
181 	struct adf_hw_device_data *hw_device;
182 	struct adf_cfg_device_data *cfg;
183 	struct adf_fw_loader_data *fw_loader;
184 	struct adf_admin_comms *admin;
185 	struct list_head crypto_list;
186 	unsigned long status;
187 	atomic_t ref_count;
188 	struct dentry *debugfs_dir;
189 	struct list_head list;
190 	struct module *owner;
191 	struct adf_accel_pci accel_pci_dev;
192 	union {
193 		struct {
194 			/* vf_info is non-zero when SR-IOV is init'ed */
195 			struct adf_accel_vf_info *vf_info;
196 		} pf;
197 		struct {
198 			char *irq_name;
199 			struct tasklet_struct pf2vf_bh_tasklet;
200 			struct mutex vf2pf_lock; /* protect CSR access */
201 			struct completion iov_msg_completion;
202 			u8 compatible;
203 			u8 pf_version;
204 		} vf;
205 	};
206 	bool is_vf;
207 	u32 accel_id;
208 } __packed;
209 #endif
210