xref: /freebsd/sys/dev/qat_c2xxx/qatvar.h (revision 71625ec9)
1b61a5730SWarner Losh /* SPDX-License-Identifier: BSD-2-Clause AND BSD-3-Clause */
2f4f56ff4SMark Johnston /*	$NetBSD: qatvar.h,v 1.2 2020/03/14 18:08:39 ad Exp $	*/
3f4f56ff4SMark Johnston 
4f4f56ff4SMark Johnston /*
5f4f56ff4SMark Johnston  * Copyright (c) 2019 Internet Initiative Japan, Inc.
6f4f56ff4SMark Johnston  * All rights reserved.
7f4f56ff4SMark Johnston  *
8f4f56ff4SMark Johnston  * Redistribution and use in source and binary forms, with or without
9f4f56ff4SMark Johnston  * modification, are permitted provided that the following conditions
10f4f56ff4SMark Johnston  * are met:
11f4f56ff4SMark Johnston  * 1. Redistributions of source code must retain the above copyright
12f4f56ff4SMark Johnston  *    notice, this list of conditions and the following disclaimer.
13f4f56ff4SMark Johnston  * 2. Redistributions in binary form must reproduce the above copyright
14f4f56ff4SMark Johnston  *    notice, this list of conditions and the following disclaimer in the
15f4f56ff4SMark Johnston  *    documentation and/or other materials provided with the distribution.
16f4f56ff4SMark Johnston  *
17f4f56ff4SMark Johnston  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18f4f56ff4SMark Johnston  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19f4f56ff4SMark Johnston  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20f4f56ff4SMark Johnston  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21f4f56ff4SMark Johnston  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22f4f56ff4SMark Johnston  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23f4f56ff4SMark Johnston  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24f4f56ff4SMark Johnston  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25f4f56ff4SMark Johnston  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26f4f56ff4SMark Johnston  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27f4f56ff4SMark Johnston  * POSSIBILITY OF SUCH DAMAGE.
28f4f56ff4SMark Johnston  */
29f4f56ff4SMark Johnston 
30f4f56ff4SMark Johnston /*
31f4f56ff4SMark Johnston  *   Copyright(c) 2007-2019 Intel Corporation. All rights reserved.
32f4f56ff4SMark Johnston  *
33f4f56ff4SMark Johnston  *   Redistribution and use in source and binary forms, with or without
34f4f56ff4SMark Johnston  *   modification, are permitted provided that the following conditions
35f4f56ff4SMark Johnston  *   are met:
36f4f56ff4SMark Johnston  *
37f4f56ff4SMark Johnston  *     * Redistributions of source code must retain the above copyright
38f4f56ff4SMark Johnston  *       notice, this list of conditions and the following disclaimer.
39f4f56ff4SMark Johnston  *     * Redistributions in binary form must reproduce the above copyright
40f4f56ff4SMark Johnston  *       notice, this list of conditions and the following disclaimer in
41f4f56ff4SMark Johnston  *       the documentation and/or other materials provided with the
42f4f56ff4SMark Johnston  *       distribution.
43f4f56ff4SMark Johnston  *     * Neither the name of Intel Corporation nor the names of its
44f4f56ff4SMark Johnston  *       contributors may be used to endorse or promote products derived
45f4f56ff4SMark Johnston  *       from this software without specific prior written permission.
46f4f56ff4SMark Johnston  *
47f4f56ff4SMark Johnston  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48f4f56ff4SMark Johnston  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49f4f56ff4SMark Johnston  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
50f4f56ff4SMark Johnston  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
51f4f56ff4SMark Johnston  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52f4f56ff4SMark Johnston  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53f4f56ff4SMark Johnston  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54f4f56ff4SMark Johnston  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55f4f56ff4SMark Johnston  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56f4f56ff4SMark Johnston  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57f4f56ff4SMark Johnston  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58f4f56ff4SMark Johnston  */
59f4f56ff4SMark Johnston 
60f4f56ff4SMark Johnston 
61f4f56ff4SMark Johnston #ifndef _DEV_PCI_QATVAR_H_
62f4f56ff4SMark Johnston #define _DEV_PCI_QATVAR_H_
63f4f56ff4SMark Johnston 
64f4f56ff4SMark Johnston #include <sys/counter.h>
65f4f56ff4SMark Johnston #include <sys/malloc.h>
66f4f56ff4SMark Johnston 
67f4f56ff4SMark Johnston #include <opencrypto/cryptodev.h>
68f4f56ff4SMark Johnston 
69f4f56ff4SMark Johnston #define QAT_NSYMREQ	256
70f4f56ff4SMark Johnston #define QAT_NSYMCOOKIE	((QAT_NSYMREQ * 2 + 1) * 2)
71f4f56ff4SMark Johnston 
72f4f56ff4SMark Johnston #define QAT_EV_NAME_SIZE		32
73f4f56ff4SMark Johnston #define QAT_RING_NAME_SIZE		32
74f4f56ff4SMark Johnston 
75f4f56ff4SMark Johnston #define QAT_MAXSEG			HW_MAXSEG /* max segments for sg dma */
76f4f56ff4SMark Johnston #define QAT_MAXLEN			65535	/* IP_MAXPACKET */
77f4f56ff4SMark Johnston 
78f4f56ff4SMark Johnston #define QAT_HB_INTERVAL			500	/* heartbeat msec */
79f4f56ff4SMark Johnston #define QAT_SSM_WDT			100
80f4f56ff4SMark Johnston 
81f4f56ff4SMark Johnston enum qat_chip_type {
82f4f56ff4SMark Johnston 	QAT_CHIP_C2XXX = 0,	/* NanoQAT: Atom C2000 */
83f4f56ff4SMark Johnston 	QAT_CHIP_C2XXX_IOV,
84f4f56ff4SMark Johnston 	QAT_CHIP_C3XXX,		/* Atom C3000 */
85f4f56ff4SMark Johnston 	QAT_CHIP_C3XXX_IOV,
86f4f56ff4SMark Johnston 	QAT_CHIP_C62X,
87f4f56ff4SMark Johnston 	QAT_CHIP_C62X_IOV,
88f4f56ff4SMark Johnston 	QAT_CHIP_D15XX,
89f4f56ff4SMark Johnston 	QAT_CHIP_D15XX_IOV,
90f4f56ff4SMark Johnston 	QAT_CHIP_DH895XCC,
91f4f56ff4SMark Johnston 	QAT_CHIP_DH895XCC_IOV,
92f4f56ff4SMark Johnston };
93f4f56ff4SMark Johnston 
94f4f56ff4SMark Johnston enum qat_sku {
95f4f56ff4SMark Johnston 	QAT_SKU_UNKNOWN = 0,
96f4f56ff4SMark Johnston 	QAT_SKU_1,
97f4f56ff4SMark Johnston 	QAT_SKU_2,
98f4f56ff4SMark Johnston 	QAT_SKU_3,
99f4f56ff4SMark Johnston 	QAT_SKU_4,
100f4f56ff4SMark Johnston 	QAT_SKU_VF,
101f4f56ff4SMark Johnston };
102f4f56ff4SMark Johnston 
103f4f56ff4SMark Johnston enum qat_ae_status {
104f4f56ff4SMark Johnston 	QAT_AE_ENABLED = 1,
105f4f56ff4SMark Johnston 	QAT_AE_ACTIVE,
106f4f56ff4SMark Johnston 	QAT_AE_DISABLED
107f4f56ff4SMark Johnston };
108f4f56ff4SMark Johnston 
109f4f56ff4SMark Johnston #define TIMEOUT_AE_RESET	100
110f4f56ff4SMark Johnston #define TIMEOUT_AE_CHECK	10000
111f4f56ff4SMark Johnston #define TIMEOUT_AE_CSR		500
112f4f56ff4SMark Johnston #define AE_EXEC_CYCLE		20
113f4f56ff4SMark Johnston 
114f4f56ff4SMark Johnston #define QAT_UOF_MAX_PAGE		1
115f4f56ff4SMark Johnston #define QAT_UOF_MAX_PAGE_REGION		1
116f4f56ff4SMark Johnston 
117f4f56ff4SMark Johnston struct qat_dmamem {
118f4f56ff4SMark Johnston 	bus_dma_tag_t qdm_dma_tag;
119f4f56ff4SMark Johnston 	bus_dmamap_t qdm_dma_map;
120f4f56ff4SMark Johnston 	bus_size_t qdm_dma_size;
121f4f56ff4SMark Johnston 	bus_dma_segment_t qdm_dma_seg;
122f4f56ff4SMark Johnston 	void *qdm_dma_vaddr;
123f4f56ff4SMark Johnston };
124f4f56ff4SMark Johnston 
125f4f56ff4SMark Johnston /* Valid internal ring size values */
126f4f56ff4SMark Johnston #define QAT_RING_SIZE_128 0x01
127f4f56ff4SMark Johnston #define QAT_RING_SIZE_256 0x02
128f4f56ff4SMark Johnston #define QAT_RING_SIZE_512 0x03
129f4f56ff4SMark Johnston #define QAT_RING_SIZE_4K 0x06
130f4f56ff4SMark Johnston #define QAT_RING_SIZE_16K 0x08
131f4f56ff4SMark Johnston #define QAT_RING_SIZE_4M 0x10
132f4f56ff4SMark Johnston #define QAT_MIN_RING_SIZE QAT_RING_SIZE_128
133f4f56ff4SMark Johnston #define QAT_MAX_RING_SIZE QAT_RING_SIZE_4M
134f4f56ff4SMark Johnston #define QAT_DEFAULT_RING_SIZE QAT_RING_SIZE_16K
135f4f56ff4SMark Johnston 
136f4f56ff4SMark Johnston /* Valid internal msg size values */
137f4f56ff4SMark Johnston #define QAT_MSG_SIZE_32 0x01
138f4f56ff4SMark Johnston #define QAT_MSG_SIZE_64 0x02
139f4f56ff4SMark Johnston #define QAT_MSG_SIZE_128 0x04
140f4f56ff4SMark Johnston #define QAT_MIN_MSG_SIZE QAT_MSG_SIZE_32
141f4f56ff4SMark Johnston #define QAT_MAX_MSG_SIZE QAT_MSG_SIZE_128
142f4f56ff4SMark Johnston 
143f4f56ff4SMark Johnston /* Size to bytes conversion macros for ring and msg size values */
144f4f56ff4SMark Johnston #define QAT_MSG_SIZE_TO_BYTES(SIZE) (SIZE << 5)
145f4f56ff4SMark Johnston #define QAT_BYTES_TO_MSG_SIZE(SIZE) (SIZE >> 5)
146f4f56ff4SMark Johnston #define QAT_SIZE_TO_RING_SIZE_IN_BYTES(SIZE) ((1 << (SIZE - 1)) << 7)
147f4f56ff4SMark Johnston #define QAT_RING_SIZE_IN_BYTES_TO_SIZE(SIZE) ((1 << (SIZE - 1)) >> 7)
148f4f56ff4SMark Johnston 
149f4f56ff4SMark Johnston /* Minimum ring buffer size for memory allocation */
150f4f56ff4SMark Johnston #define QAT_RING_SIZE_BYTES_MIN(SIZE) \
151f4f56ff4SMark Johnston 	((SIZE < QAT_SIZE_TO_RING_SIZE_IN_BYTES(QAT_RING_SIZE_4K)) ? \
152f4f56ff4SMark Johnston 		QAT_SIZE_TO_RING_SIZE_IN_BYTES(QAT_RING_SIZE_4K) : SIZE)
153f4f56ff4SMark Johnston #define QAT_RING_SIZE_MODULO(SIZE) (SIZE + 0x6)
154f4f56ff4SMark Johnston #define QAT_SIZE_TO_POW(SIZE) ((((SIZE & 0x4) >> 1) | ((SIZE & 0x4) >> 2) | \
155f4f56ff4SMark Johnston 				SIZE) & ~0x4)
156f4f56ff4SMark Johnston /* Max outstanding requests */
157f4f56ff4SMark Johnston #define QAT_MAX_INFLIGHTS(RING_SIZE, MSG_SIZE) \
158f4f56ff4SMark Johnston 	((((1 << (RING_SIZE - 1)) << 3) >> QAT_SIZE_TO_POW(MSG_SIZE)) - 1)
159f4f56ff4SMark Johnston 
160f4f56ff4SMark Johnston #define QAT_RING_PATTERN		0x7f
161f4f56ff4SMark Johnston 
162f4f56ff4SMark Johnston struct qat_softc;
163f4f56ff4SMark Johnston 
164f4f56ff4SMark Johnston typedef int (*qat_cb_t)(struct qat_softc *, void *, void *);
165f4f56ff4SMark Johnston 
166f4f56ff4SMark Johnston struct qat_ring {
167f4f56ff4SMark Johnston 	struct mtx qr_ring_mtx;   /* Lock per ring */
168f4f56ff4SMark Johnston 	bool qr_need_wakeup;
169f4f56ff4SMark Johnston 	void *qr_ring_vaddr;
170f4f56ff4SMark Johnston 	uint32_t * volatile qr_inflight;	/* tx/rx shared */
171f4f56ff4SMark Johnston 	uint32_t qr_head;
172f4f56ff4SMark Johnston 	uint32_t qr_tail;
173f4f56ff4SMark Johnston 	uint8_t qr_msg_size;
174f4f56ff4SMark Johnston 	uint8_t qr_ring_size;
175f4f56ff4SMark Johnston 	uint32_t qr_ring;	/* ring number in bank */
176f4f56ff4SMark Johnston 	uint32_t qr_bank;	/* bank number in device */
177f4f56ff4SMark Johnston 	uint32_t qr_ring_id;
178f4f56ff4SMark Johnston 	uint32_t qr_ring_mask;
179f4f56ff4SMark Johnston 	qat_cb_t qr_cb;
180f4f56ff4SMark Johnston 	void *qr_cb_arg;
181f4f56ff4SMark Johnston 	struct qat_dmamem qr_dma;
182f4f56ff4SMark Johnston 	bus_addr_t qr_ring_paddr;
183f4f56ff4SMark Johnston 
184f4f56ff4SMark Johnston 	const char *qr_name;
185f4f56ff4SMark Johnston };
186f4f56ff4SMark Johnston 
187f4f56ff4SMark Johnston struct qat_bank {
188f4f56ff4SMark Johnston 	struct qat_softc *qb_sc;	/* back pointer to softc */
189f4f56ff4SMark Johnston 	uint32_t qb_intr_mask;		/* current interrupt mask */
190f4f56ff4SMark Johnston 	uint32_t qb_allocated_rings;	/* current allocated ring bitfiled */
191f4f56ff4SMark Johnston 	uint32_t qb_coalescing_time;	/* timer in nano sec, 0: disabled */
192f4f56ff4SMark Johnston #define COALESCING_TIME_INTERVAL_DEFAULT	10000
193f4f56ff4SMark Johnston #define COALESCING_TIME_INTERVAL_MIN		500
194f4f56ff4SMark Johnston #define COALESCING_TIME_INTERVAL_MAX		0xfffff
195f4f56ff4SMark Johnston 	uint32_t qb_bank;		/* bank index */
196f4f56ff4SMark Johnston 	struct mtx qb_bank_mtx;
197f4f56ff4SMark Johnston 	struct resource *qb_ih;
198f4f56ff4SMark Johnston 	void *qb_ih_cookie;
199f4f56ff4SMark Johnston 
200f4f56ff4SMark Johnston 	struct qat_ring qb_et_rings[MAX_RING_PER_BANK];
201f4f56ff4SMark Johnston 
202f4f56ff4SMark Johnston };
203f4f56ff4SMark Johnston 
204f4f56ff4SMark Johnston struct qat_ap_bank {
205f4f56ff4SMark Johnston 	uint32_t qab_nf_mask;
206f4f56ff4SMark Johnston 	uint32_t qab_nf_dest;
207f4f56ff4SMark Johnston 	uint32_t qab_ne_mask;
208f4f56ff4SMark Johnston 	uint32_t qab_ne_dest;
209f4f56ff4SMark Johnston };
210f4f56ff4SMark Johnston 
211f4f56ff4SMark Johnston struct qat_ae_page {
212f4f56ff4SMark Johnston 	struct qat_ae_page *qap_next;
213f4f56ff4SMark Johnston 	struct qat_uof_page *qap_page;
214f4f56ff4SMark Johnston 	struct qat_ae_region *qap_region;
215f4f56ff4SMark Johnston 	u_int qap_flags;
216f4f56ff4SMark Johnston };
217f4f56ff4SMark Johnston 
218f4f56ff4SMark Johnston #define QAT_AE_PAGA_FLAG_WAITING	(1 << 0)
219f4f56ff4SMark Johnston 
220f4f56ff4SMark Johnston struct qat_ae_region {
221f4f56ff4SMark Johnston 	struct qat_ae_page *qar_loaded_page;
222f4f56ff4SMark Johnston 	STAILQ_HEAD(, qat_ae_page) qar_waiting_pages;
223f4f56ff4SMark Johnston };
224f4f56ff4SMark Johnston 
225f4f56ff4SMark Johnston struct qat_ae_slice {
226f4f56ff4SMark Johnston 	u_int qas_assigned_ctx_mask;
227f4f56ff4SMark Johnston 	struct qat_ae_region qas_regions[QAT_UOF_MAX_PAGE_REGION];
228f4f56ff4SMark Johnston 	struct qat_ae_page qas_pages[QAT_UOF_MAX_PAGE];
229f4f56ff4SMark Johnston 	struct qat_ae_page *qas_cur_pages[MAX_AE_CTX];
230f4f56ff4SMark Johnston 	struct qat_uof_image *qas_image;
231f4f56ff4SMark Johnston };
232f4f56ff4SMark Johnston 
233f4f56ff4SMark Johnston #define QAT_AE(sc, ae)			\
234f4f56ff4SMark Johnston 		((sc)->sc_ae[ae])
235f4f56ff4SMark Johnston 
236f4f56ff4SMark Johnston struct qat_ae {
237f4f56ff4SMark Johnston 	u_int qae_state;		/* AE state */
238f4f56ff4SMark Johnston 	u_int qae_ustore_size;		/* free micro-store address */
239f4f56ff4SMark Johnston 	u_int qae_free_addr;		/* free micro-store address */
240f4f56ff4SMark Johnston 	u_int qae_free_size;		/* free micro-store size */
241f4f56ff4SMark Johnston 	u_int qae_live_ctx_mask;	/* live context mask */
242f4f56ff4SMark Johnston 	u_int qae_ustore_dram_addr;	/* micro-store DRAM address */
243f4f56ff4SMark Johnston 	u_int qae_reload_size;		/* reloadable code size */
244f4f56ff4SMark Johnston 
245f4f56ff4SMark Johnston 	/* aefw */
246f4f56ff4SMark Johnston 	u_int qae_num_slices;
247f4f56ff4SMark Johnston 	struct qat_ae_slice qae_slices[MAX_AE_CTX];
248f4f56ff4SMark Johnston 	u_int qae_reloc_ustore_dram;	/* reloadable ustore-dram address */
249f4f56ff4SMark Johnston 	u_int qae_effect_ustore_size;	/* effective AE ustore size */
250f4f56ff4SMark Johnston 	u_int qae_shareable_ustore;
251f4f56ff4SMark Johnston };
252f4f56ff4SMark Johnston 
253f4f56ff4SMark Johnston struct qat_mof {
254f4f56ff4SMark Johnston 	void *qmf_sym;			/* SYM_OBJS in sc_fw_mof */
255f4f56ff4SMark Johnston 	size_t qmf_sym_size;
256f4f56ff4SMark Johnston 	void *qmf_uof_objs;		/* UOF_OBJS in sc_fw_mof */
257f4f56ff4SMark Johnston 	size_t qmf_uof_objs_size;
258f4f56ff4SMark Johnston 	void *qmf_suof_objs;		/* SUOF_OBJS in sc_fw_mof */
259f4f56ff4SMark Johnston 	size_t qmf_suof_objs_size;
260f4f56ff4SMark Johnston };
261f4f56ff4SMark Johnston 
262f4f56ff4SMark Johnston struct qat_ae_batch_init {
263f4f56ff4SMark Johnston 	u_int qabi_ae;
264f4f56ff4SMark Johnston 	u_int qabi_addr;
265f4f56ff4SMark Johnston 	u_int *qabi_value;
266f4f56ff4SMark Johnston 	u_int qabi_size;
267f4f56ff4SMark Johnston 	STAILQ_ENTRY(qat_ae_batch_init) qabi_next;
268f4f56ff4SMark Johnston };
269f4f56ff4SMark Johnston 
270f4f56ff4SMark Johnston STAILQ_HEAD(qat_ae_batch_init_list, qat_ae_batch_init);
271f4f56ff4SMark Johnston 
272f4f56ff4SMark Johnston /* overwritten struct uof_uword_block */
273f4f56ff4SMark Johnston struct qat_uof_uword_block {
274f4f56ff4SMark Johnston 	u_int quub_start_addr;		/* start address */
275f4f56ff4SMark Johnston 	u_int quub_num_words;		/* number of microwords */
276f4f56ff4SMark Johnston 	uint64_t quub_micro_words;	/* pointer to the uwords */
277f4f56ff4SMark Johnston };
278f4f56ff4SMark Johnston 
279f4f56ff4SMark Johnston struct qat_uof_page {
280f4f56ff4SMark Johnston 	u_int qup_page_num;		/* page number */
281f4f56ff4SMark Johnston 	u_int qup_def_page;		/* default page */
282f4f56ff4SMark Johnston 	u_int qup_page_region;		/* region of page */
283f4f56ff4SMark Johnston 	u_int qup_beg_vaddr;		/* begin virtual address */
284f4f56ff4SMark Johnston 	u_int qup_beg_paddr;		/* begin physical address */
285f4f56ff4SMark Johnston 
286f4f56ff4SMark Johnston 	u_int qup_num_uc_var;		/* num of uC var in array */
287f4f56ff4SMark Johnston 	struct uof_uword_fixup *qup_uc_var;
288f4f56ff4SMark Johnston 					/* array of import variables */
289f4f56ff4SMark Johnston 	u_int qup_num_imp_var;		/* num of import var in array */
290f4f56ff4SMark Johnston 	struct uof_import_var *qup_imp_var;
291f4f56ff4SMark Johnston 					/* array of import variables */
292f4f56ff4SMark Johnston 	u_int qup_num_imp_expr;		/* num of import expr in array */
293f4f56ff4SMark Johnston 	struct uof_uword_fixup *qup_imp_expr;
294f4f56ff4SMark Johnston 					/* array of import expressions */
295f4f56ff4SMark Johnston 	u_int qup_num_neigh_reg;	/* num of neigh-reg in array */
296f4f56ff4SMark Johnston 	struct uof_uword_fixup *qup_neigh_reg;
297f4f56ff4SMark Johnston 					/* array of neigh-reg assignments */
298f4f56ff4SMark Johnston 	u_int qup_num_micro_words;	/* number of microwords in the seg */
299f4f56ff4SMark Johnston 
300f4f56ff4SMark Johnston 	u_int qup_num_uw_blocks;	/* number of uword blocks */
301f4f56ff4SMark Johnston 	struct qat_uof_uword_block *qup_uw_blocks;
302f4f56ff4SMark Johnston 					/* array of uword blocks */
303f4f56ff4SMark Johnston };
304f4f56ff4SMark Johnston 
305f4f56ff4SMark Johnston struct qat_uof_image {
306f4f56ff4SMark Johnston 	struct uof_image *qui_image;		/* image pointer */
307f4f56ff4SMark Johnston 	struct qat_uof_page qui_pages[QAT_UOF_MAX_PAGE];
308f4f56ff4SMark Johnston 						/* array of pages */
309f4f56ff4SMark Johnston 
310f4f56ff4SMark Johnston 	u_int qui_num_ae_reg;			/* num of registers */
311f4f56ff4SMark Johnston 	struct uof_ae_reg *qui_ae_reg;		/* array of registers */
312f4f56ff4SMark Johnston 
313f4f56ff4SMark Johnston 	u_int qui_num_init_reg_sym;		/* num of reg/sym init values */
314f4f56ff4SMark Johnston 	struct uof_init_reg_sym *qui_init_reg_sym;
315f4f56ff4SMark Johnston 					/* array of reg/sym init values */
316f4f56ff4SMark Johnston 
317f4f56ff4SMark Johnston 	u_int qui_num_sbreak;			/* num of sbreak values */
318f4f56ff4SMark Johnston 	struct qui_sbreak *qui_sbreak;		/* array of sbreak values */
319f4f56ff4SMark Johnston 
320f4f56ff4SMark Johnston 	u_int qui_num_uwords_used;
321f4f56ff4SMark Johnston 				/* highest uword addressreferenced + 1 */
322f4f56ff4SMark Johnston };
323f4f56ff4SMark Johnston 
324f4f56ff4SMark Johnston struct qat_aefw_uof {
325f4f56ff4SMark Johnston 	size_t qafu_size;			/* uof size */
326f4f56ff4SMark Johnston 	struct uof_obj_hdr *qafu_obj_hdr;	/* UOF_OBJS */
327f4f56ff4SMark Johnston 
328f4f56ff4SMark Johnston 	void *qafu_str_tab;
329f4f56ff4SMark Johnston 	size_t qafu_str_tab_size;
330f4f56ff4SMark Johnston 
331f4f56ff4SMark Johnston 	u_int qafu_num_init_mem;
332f4f56ff4SMark Johnston 	struct uof_init_mem *qafu_init_mem;
333f4f56ff4SMark Johnston 	size_t qafu_init_mem_size;
334f4f56ff4SMark Johnston 
335f4f56ff4SMark Johnston 	struct uof_var_mem_seg *qafu_var_mem_seg;
336f4f56ff4SMark Johnston 
337f4f56ff4SMark Johnston 	struct qat_ae_batch_init_list qafu_lm_init[MAX_AE];
338f4f56ff4SMark Johnston 	size_t qafu_num_lm_init[MAX_AE];
339f4f56ff4SMark Johnston 	size_t qafu_num_lm_init_inst[MAX_AE];
340f4f56ff4SMark Johnston 
341f4f56ff4SMark Johnston 	u_int qafu_num_imgs;			/* number of uof image */
342f4f56ff4SMark Johnston 	struct qat_uof_image qafu_imgs[MAX_NUM_AE * MAX_AE_CTX];
343f4f56ff4SMark Johnston 						/* uof images */
344f4f56ff4SMark Johnston };
345f4f56ff4SMark Johnston 
346f4f56ff4SMark Johnston #define QAT_SERVICE_CRYPTO_A		(1 << 0)
347f4f56ff4SMark Johnston #define QAT_SERVICE_CRYPTO_B		(1 << 1)
348f4f56ff4SMark Johnston 
349f4f56ff4SMark Johnston struct qat_admin_rings {
350f4f56ff4SMark Johnston 	uint32_t qadr_active_aes_per_accel;
351f4f56ff4SMark Johnston 	uint8_t qadr_srv_mask[MAX_AE_PER_ACCEL];
352f4f56ff4SMark Johnston 
353f4f56ff4SMark Johnston 	struct qat_dmamem qadr_dma;
354f4f56ff4SMark Johnston 	struct fw_init_ring_table *qadr_master_ring_tbl;
355f4f56ff4SMark Johnston 	struct fw_init_ring_table *qadr_cya_ring_tbl;
356f4f56ff4SMark Johnston 	struct fw_init_ring_table *qadr_cyb_ring_tbl;
357f4f56ff4SMark Johnston 
358f4f56ff4SMark Johnston 	struct qat_ring *qadr_admin_tx;
359f4f56ff4SMark Johnston 	struct qat_ring *qadr_admin_rx;
360f4f56ff4SMark Johnston };
361f4f56ff4SMark Johnston 
362f4f56ff4SMark Johnston struct qat_accel_init_cb {
363f4f56ff4SMark Johnston 	int qaic_status;
364f4f56ff4SMark Johnston };
365f4f56ff4SMark Johnston 
366f4f56ff4SMark Johnston struct qat_admin_comms {
367f4f56ff4SMark Johnston 	struct qat_dmamem qadc_dma;
368f4f56ff4SMark Johnston 	struct qat_dmamem qadc_const_tbl_dma;
369f4f56ff4SMark Johnston 	struct qat_dmamem qadc_hb_dma;
370f4f56ff4SMark Johnston };
371f4f56ff4SMark Johnston 
372f4f56ff4SMark Johnston #define QAT_PID_MINOR_REV 0xf
373f4f56ff4SMark Johnston #define QAT_PID_MAJOR_REV (0xf << 4)
374f4f56ff4SMark Johnston 
375f4f56ff4SMark Johnston struct qat_suof_image {
376f4f56ff4SMark Johnston 	char *qsi_simg_buf;
377f4f56ff4SMark Johnston 	u_long qsi_simg_len;
378f4f56ff4SMark Johnston 	char *qsi_css_header;
379f4f56ff4SMark Johnston 	char *qsi_css_key;
380f4f56ff4SMark Johnston 	char *qsi_css_signature;
381f4f56ff4SMark Johnston 	char *qsi_css_simg;
382f4f56ff4SMark Johnston 	u_long qsi_simg_size;
383f4f56ff4SMark Johnston 	u_int qsi_ae_num;
384f4f56ff4SMark Johnston 	u_int qsi_ae_mask;
385f4f56ff4SMark Johnston 	u_int qsi_fw_type;
386f4f56ff4SMark Johnston 	u_long qsi_simg_name;
387f4f56ff4SMark Johnston 	u_long qsi_appmeta_data;
388f4f56ff4SMark Johnston 	struct qat_dmamem qsi_dma;
389f4f56ff4SMark Johnston };
390f4f56ff4SMark Johnston 
391f4f56ff4SMark Johnston struct qat_aefw_suof {
392f4f56ff4SMark Johnston 	u_int qafs_file_id;
393f4f56ff4SMark Johnston 	u_int qafs_check_sum;
394f4f56ff4SMark Johnston 	char qafs_min_ver;
395f4f56ff4SMark Johnston 	char qafs_maj_ver;
396f4f56ff4SMark Johnston 	char qafs_fw_type;
397f4f56ff4SMark Johnston 	char *qafs_suof_buf;
398f4f56ff4SMark Johnston 	u_int qafs_suof_size;
399f4f56ff4SMark Johnston 	char *qafs_sym_str;
400f4f56ff4SMark Johnston 	u_int qafs_sym_size;
401f4f56ff4SMark Johnston 	u_int qafs_num_simgs;
402f4f56ff4SMark Johnston 	struct qat_suof_image *qafs_simg;
403f4f56ff4SMark Johnston };
404f4f56ff4SMark Johnston 
405f4f56ff4SMark Johnston enum qat_sym_hash_algorithm {
406f4f56ff4SMark Johnston 	QAT_SYM_HASH_NONE = 0,
407f4f56ff4SMark Johnston 	QAT_SYM_HASH_MD5 = 1,
408f4f56ff4SMark Johnston 	QAT_SYM_HASH_SHA1 = 2,
409f4f56ff4SMark Johnston 	QAT_SYM_HASH_SHA224 = 3,
410f4f56ff4SMark Johnston 	QAT_SYM_HASH_SHA256 = 4,
411f4f56ff4SMark Johnston 	QAT_SYM_HASH_SHA384 = 5,
412f4f56ff4SMark Johnston 	QAT_SYM_HASH_SHA512 = 6,
413f4f56ff4SMark Johnston 	QAT_SYM_HASH_AES_XCBC = 7,
414f4f56ff4SMark Johnston 	QAT_SYM_HASH_AES_CCM = 8,
415f4f56ff4SMark Johnston 	QAT_SYM_HASH_AES_GCM = 9,
416f4f56ff4SMark Johnston 	QAT_SYM_HASH_KASUMI_F9 = 10,
417f4f56ff4SMark Johnston 	QAT_SYM_HASH_SNOW3G_UIA2 = 11,
418f4f56ff4SMark Johnston 	QAT_SYM_HASH_AES_CMAC = 12,
419f4f56ff4SMark Johnston 	QAT_SYM_HASH_AES_GMAC = 13,
420f4f56ff4SMark Johnston 	QAT_SYM_HASH_AES_CBC_MAC = 14,
421f4f56ff4SMark Johnston };
422f4f56ff4SMark Johnston 
423f4f56ff4SMark Johnston #define QAT_HASH_MD5_BLOCK_SIZE			64
424f4f56ff4SMark Johnston #define QAT_HASH_MD5_DIGEST_SIZE		16
425f4f56ff4SMark Johnston #define QAT_HASH_MD5_STATE_SIZE			16
426f4f56ff4SMark Johnston #define QAT_HASH_SHA1_BLOCK_SIZE		64
427f4f56ff4SMark Johnston #define QAT_HASH_SHA1_DIGEST_SIZE		20
428f4f56ff4SMark Johnston #define QAT_HASH_SHA1_STATE_SIZE		20
429f4f56ff4SMark Johnston #define QAT_HASH_SHA224_BLOCK_SIZE		64
430f4f56ff4SMark Johnston #define QAT_HASH_SHA224_DIGEST_SIZE		28
431f4f56ff4SMark Johnston #define QAT_HASH_SHA224_STATE_SIZE		32
432f4f56ff4SMark Johnston #define QAT_HASH_SHA256_BLOCK_SIZE		64
433f4f56ff4SMark Johnston #define QAT_HASH_SHA256_DIGEST_SIZE		32
434f4f56ff4SMark Johnston #define QAT_HASH_SHA256_STATE_SIZE		32
435f4f56ff4SMark Johnston #define QAT_HASH_SHA384_BLOCK_SIZE		128
436f4f56ff4SMark Johnston #define QAT_HASH_SHA384_DIGEST_SIZE		48
437f4f56ff4SMark Johnston #define QAT_HASH_SHA384_STATE_SIZE		64
438f4f56ff4SMark Johnston #define QAT_HASH_SHA512_BLOCK_SIZE		128
439f4f56ff4SMark Johnston #define QAT_HASH_SHA512_DIGEST_SIZE		64
440f4f56ff4SMark Johnston #define QAT_HASH_SHA512_STATE_SIZE		64
441f4f56ff4SMark Johnston #define QAT_HASH_XCBC_PRECOMP_KEY_NUM		3
442f4f56ff4SMark Johnston #define QAT_HASH_XCBC_MAC_BLOCK_SIZE		16
443f4f56ff4SMark Johnston #define QAT_HASH_XCBC_MAC_128_DIGEST_SIZE	16
444f4f56ff4SMark Johnston #define QAT_HASH_CMAC_BLOCK_SIZE		16
445f4f56ff4SMark Johnston #define QAT_HASH_CMAC_128_DIGEST_SIZE		16
446f4f56ff4SMark Johnston #define QAT_HASH_AES_CCM_BLOCK_SIZE		16
447f4f56ff4SMark Johnston #define QAT_HASH_AES_CCM_DIGEST_SIZE		16
448f4f56ff4SMark Johnston #define QAT_HASH_AES_GCM_BLOCK_SIZE		16
449f4f56ff4SMark Johnston #define QAT_HASH_AES_GCM_DIGEST_SIZE		16
450f4f56ff4SMark Johnston #define QAT_HASH_AES_GCM_STATE_SIZE		16
451f4f56ff4SMark Johnston #define QAT_HASH_KASUMI_F9_BLOCK_SIZE		8
452f4f56ff4SMark Johnston #define QAT_HASH_KASUMI_F9_DIGEST_SIZE		4
453f4f56ff4SMark Johnston #define QAT_HASH_SNOW3G_UIA2_BLOCK_SIZE		8
454f4f56ff4SMark Johnston #define QAT_HASH_SNOW3G_UIA2_DIGEST_SIZE	4
455f4f56ff4SMark Johnston #define QAT_HASH_AES_CBC_MAC_BLOCK_SIZE		16
456f4f56ff4SMark Johnston #define QAT_HASH_AES_CBC_MAC_DIGEST_SIZE	16
457f4f56ff4SMark Johnston #define QAT_HASH_AES_GCM_ICV_SIZE_8		8
458f4f56ff4SMark Johnston #define QAT_HASH_AES_GCM_ICV_SIZE_12		12
459f4f56ff4SMark Johnston #define QAT_HASH_AES_GCM_ICV_SIZE_16		16
460f4f56ff4SMark Johnston #define QAT_HASH_AES_CCM_ICV_SIZE_MIN		4
461f4f56ff4SMark Johnston #define QAT_HASH_AES_CCM_ICV_SIZE_MAX		16
462f4f56ff4SMark Johnston #define QAT_HASH_IPAD_BYTE			0x36
463f4f56ff4SMark Johnston #define QAT_HASH_OPAD_BYTE			0x5c
464f4f56ff4SMark Johnston #define QAT_HASH_IPAD_4_BYTES			0x36363636
465f4f56ff4SMark Johnston #define QAT_HASH_OPAD_4_BYTES			0x5c5c5c5c
466f4f56ff4SMark Johnston #define QAT_HASH_KASUMI_F9_KEY_MODIFIER_4_BYTES	0xAAAAAAAA
467f4f56ff4SMark Johnston 
468f4f56ff4SMark Johnston #define QAT_SYM_XCBC_STATE_SIZE		((QAT_HASH_XCBC_MAC_BLOCK_SIZE) * 3)
469f4f56ff4SMark Johnston #define QAT_SYM_CMAC_STATE_SIZE		((QAT_HASH_CMAC_BLOCK_SIZE) * 3)
470f4f56ff4SMark Johnston 
471f4f56ff4SMark Johnston struct qat_sym_hash_alg_info {
472f4f56ff4SMark Johnston 	uint32_t qshai_digest_len;		/* Digest length in bytes */
473f4f56ff4SMark Johnston 	uint32_t qshai_block_len;		/* Block length in bytes */
474f4f56ff4SMark Johnston 	uint32_t qshai_state_size;		/* size of above state in bytes */
475f4f56ff4SMark Johnston 	const uint8_t *qshai_init_state;	/* Initial state */
476f4f56ff4SMark Johnston 
477f4f56ff4SMark Johnston 	const struct auth_hash *qshai_sah;	/* software auth hash */
478f4f56ff4SMark Johnston 	uint32_t qshai_state_offset;		/* offset to state in *_CTX */
479f4f56ff4SMark Johnston 	uint32_t qshai_state_word;
480f4f56ff4SMark Johnston };
481f4f56ff4SMark Johnston 
482f4f56ff4SMark Johnston struct qat_sym_hash_qat_info {
483f4f56ff4SMark Johnston 	uint32_t qshqi_algo_enc;	/* QAT Algorithm encoding */
484f4f56ff4SMark Johnston 	uint32_t qshqi_auth_counter;	/* Counter value for Auth */
485f4f56ff4SMark Johnston 	uint32_t qshqi_state1_len;	/* QAT state1 length in bytes */
486f4f56ff4SMark Johnston 	uint32_t qshqi_state2_len;	/* QAT state2 length in bytes */
487f4f56ff4SMark Johnston };
488f4f56ff4SMark Johnston 
489f4f56ff4SMark Johnston struct qat_sym_hash_def {
490f4f56ff4SMark Johnston 	const struct qat_sym_hash_alg_info *qshd_alg;
491f4f56ff4SMark Johnston 	const struct qat_sym_hash_qat_info *qshd_qat;
492f4f56ff4SMark Johnston };
493f4f56ff4SMark Johnston 
494f4f56ff4SMark Johnston #define QAT_SYM_REQ_PARAMS_SIZE_MAX			(24 + 32)
495f4f56ff4SMark Johnston /* Reserve enough space for cipher and authentication request params */
496f4f56ff4SMark Johnston /* Basis of values are guaranteed in qat_hw*var.h with CTASSERT */
497f4f56ff4SMark Johnston 
498f4f56ff4SMark Johnston #define QAT_SYM_REQ_PARAMS_SIZE_PADDED			\
499f4f56ff4SMark Johnston 		roundup(QAT_SYM_REQ_PARAMS_SIZE_MAX, QAT_OPTIMAL_ALIGN)
500f4f56ff4SMark Johnston /* Pad out to 64-byte multiple to ensure optimal alignment of next field */
501f4f56ff4SMark Johnston 
502f4f56ff4SMark Johnston #define QAT_SYM_KEY_TLS_PREFIX_SIZE			(128)
503f4f56ff4SMark Johnston /* Hash Prefix size in bytes for TLS (128 = MAX = SHA2 (384, 512)*/
504f4f56ff4SMark Johnston 
505f4f56ff4SMark Johnston #define QAT_SYM_KEY_MAX_HASH_STATE_BUFFER		\
506f4f56ff4SMark Johnston 		(QAT_SYM_KEY_TLS_PREFIX_SIZE * 2)
507f4f56ff4SMark Johnston /* hash state prefix buffer structure that holds the maximum sized secret */
508f4f56ff4SMark Johnston 
509f4f56ff4SMark Johnston #define QAT_SYM_HASH_BUFFER_LEN			QAT_HASH_SHA512_STATE_SIZE
510f4f56ff4SMark Johnston /* Buffer length to hold 16 byte MD5 key and 20 byte SHA1 key */
511f4f56ff4SMark Johnston 
512f4f56ff4SMark Johnston #define QAT_GCM_AAD_SIZE_MAX		240
513f4f56ff4SMark Johnston /* Maximum AAD size */
514f4f56ff4SMark Johnston 
515f4f56ff4SMark Johnston #define	QAT_AES_GCM_AAD_ALIGN		16
516f4f56ff4SMark Johnston 
517f4f56ff4SMark Johnston struct qat_sym_bulk_cookie {
518f4f56ff4SMark Johnston 	uint8_t qsbc_req_params_buf[QAT_SYM_REQ_PARAMS_SIZE_PADDED];
519f4f56ff4SMark Johnston 	/* memory block reserved for request params, QAT 1.5 only
520f4f56ff4SMark Johnston 	 * NOTE: Field must be correctly aligned in memory for access by QAT
521f4f56ff4SMark Johnston 	 * engine */
522f4f56ff4SMark Johnston 	struct qat_crypto *qsbc_crypto;
523f4f56ff4SMark Johnston 	struct qat_session *qsbc_session;
524f4f56ff4SMark Johnston 	/* Session context */
525f4f56ff4SMark Johnston 	void *qsbc_cb_tag;
526f4f56ff4SMark Johnston 	/* correlator supplied by the client */
527f4f56ff4SMark Johnston 	uint8_t qsbc_msg[QAT_MSG_SIZE_TO_BYTES(QAT_MAX_MSG_SIZE)];
528f4f56ff4SMark Johnston 	/* QAT request message */
529f4f56ff4SMark Johnston } __aligned(QAT_OPTIMAL_ALIGN);
530f4f56ff4SMark Johnston 
531f4f56ff4SMark Johnston /* Basis of values are guaranteed in qat_hw*var.h with CTASSERT */
532f4f56ff4SMark Johnston #define HASH_CONTENT_DESC_SIZE		176
533f4f56ff4SMark Johnston #define CIPHER_CONTENT_DESC_SIZE	64
534f4f56ff4SMark Johnston 
535f4f56ff4SMark Johnston #define CONTENT_DESC_MAX_SIZE	roundup(				\
536f4f56ff4SMark Johnston 		HASH_CONTENT_DESC_SIZE + CIPHER_CONTENT_DESC_SIZE,	\
537f4f56ff4SMark Johnston 		QAT_OPTIMAL_ALIGN)
538f4f56ff4SMark Johnston 
539f4f56ff4SMark Johnston enum qat_sym_dma {
540f4f56ff4SMark Johnston 	QAT_SYM_DMA_AADBUF = 0,
541f4f56ff4SMark Johnston 	QAT_SYM_DMA_BUF,
542f4f56ff4SMark Johnston 	QAT_SYM_DMA_OBUF,
543f4f56ff4SMark Johnston 	QAT_SYM_DMA_COUNT,
544f4f56ff4SMark Johnston };
545f4f56ff4SMark Johnston 
546f4f56ff4SMark Johnston struct qat_sym_dmamap {
547f4f56ff4SMark Johnston 	bus_dmamap_t qsd_dmamap;
548f4f56ff4SMark Johnston 	bus_dma_tag_t qsd_dma_tag;
549f4f56ff4SMark Johnston };
550f4f56ff4SMark Johnston 
551f4f56ff4SMark Johnston struct qat_sym_cookie {
552f4f56ff4SMark Johnston 	struct qat_sym_bulk_cookie qsc_bulk_cookie;
553f4f56ff4SMark Johnston 
554f4f56ff4SMark Johnston 	/* should be 64-byte aligned */
555f4f56ff4SMark Johnston 	struct buffer_list_desc qsc_buf_list;
556f4f56ff4SMark Johnston 	struct buffer_list_desc qsc_obuf_list;
557f4f56ff4SMark Johnston 
558f4f56ff4SMark Johnston 	bus_dmamap_t qsc_self_dmamap;
559f4f56ff4SMark Johnston 	bus_dma_tag_t qsc_self_dma_tag;
560f4f56ff4SMark Johnston 
561f4f56ff4SMark Johnston 	uint8_t qsc_iv_buf[EALG_MAX_BLOCK_LEN];
562f4f56ff4SMark Johnston 	uint8_t qsc_auth_res[QAT_SYM_HASH_BUFFER_LEN];
563f4f56ff4SMark Johnston 	uint8_t qsc_gcm_aad[QAT_GCM_AAD_SIZE_MAX];
564f4f56ff4SMark Johnston 	uint8_t qsc_content_desc[CONTENT_DESC_MAX_SIZE];
565f4f56ff4SMark Johnston 
566f4f56ff4SMark Johnston 	struct qat_sym_dmamap qsc_dma[QAT_SYM_DMA_COUNT];
567f4f56ff4SMark Johnston 
568f4f56ff4SMark Johnston 	bus_addr_t qsc_bulk_req_params_buf_paddr;
569f4f56ff4SMark Johnston 	bus_addr_t qsc_buffer_list_desc_paddr;
570f4f56ff4SMark Johnston 	bus_addr_t qsc_obuffer_list_desc_paddr;
571f4f56ff4SMark Johnston 	bus_addr_t qsc_iv_buf_paddr;
572f4f56ff4SMark Johnston 	bus_addr_t qsc_auth_res_paddr;
573f4f56ff4SMark Johnston 	bus_addr_t qsc_gcm_aad_paddr;
574f4f56ff4SMark Johnston 	bus_addr_t qsc_content_desc_paddr;
575f4f56ff4SMark Johnston };
576f4f56ff4SMark Johnston 
577f4f56ff4SMark Johnston CTASSERT(offsetof(struct qat_sym_cookie,
578f4f56ff4SMark Johnston     qsc_bulk_cookie.qsbc_req_params_buf) % QAT_OPTIMAL_ALIGN == 0);
579f4f56ff4SMark Johnston CTASSERT(offsetof(struct qat_sym_cookie, qsc_buf_list) % QAT_OPTIMAL_ALIGN == 0);
580f4f56ff4SMark Johnston 
581f4f56ff4SMark Johnston #define MAX_CIPHER_SETUP_BLK_SZ						\
582f4f56ff4SMark Johnston 		(sizeof(struct hw_cipher_config) +			\
583f4f56ff4SMark Johnston 		2 * HW_KASUMI_KEY_SZ + 2 * HW_KASUMI_BLK_SZ)
584f4f56ff4SMark Johnston #define MAX_HASH_SETUP_BLK_SZ	sizeof(union hw_auth_algo_blk)
585f4f56ff4SMark Johnston 
586f4f56ff4SMark Johnston struct qat_crypto_desc {
587f4f56ff4SMark Johnston 	uint8_t qcd_content_desc[CONTENT_DESC_MAX_SIZE]; /* must be first */
588f4f56ff4SMark Johnston 	/* using only for qat 1.5 */
589f4f56ff4SMark Johnston 	uint8_t qcd_hash_state_prefix_buf[QAT_GCM_AAD_SIZE_MAX];
590f4f56ff4SMark Johnston 
591f4f56ff4SMark Johnston 	bus_addr_t qcd_desc_paddr;
592f4f56ff4SMark Johnston 	bus_addr_t qcd_hash_state_paddr;
593f4f56ff4SMark Johnston 
594f4f56ff4SMark Johnston 	enum fw_slice qcd_slices[MAX_FW_SLICE + 1];
595f4f56ff4SMark Johnston 	enum fw_la_cmd_id qcd_cmd_id;
596f4f56ff4SMark Johnston 	enum hw_cipher_dir qcd_cipher_dir;
597f4f56ff4SMark Johnston 
598f4f56ff4SMark Johnston 	/* content desc info */
599f4f56ff4SMark Johnston 	uint8_t qcd_hdr_sz;		/* in quad words */
600f4f56ff4SMark Johnston 	uint8_t qcd_hw_blk_sz;		/* in quad words */
601f4f56ff4SMark Johnston 	uint32_t qcd_cipher_offset;
602f4f56ff4SMark Johnston 	uint32_t qcd_auth_offset;
603f4f56ff4SMark Johnston 	/* hash info */
604f4f56ff4SMark Johnston 	uint8_t qcd_state_storage_sz;	/* in quad words */
605f4f56ff4SMark Johnston 	uint32_t qcd_gcm_aad_sz_offset1;
606f4f56ff4SMark Johnston 	uint32_t qcd_gcm_aad_sz_offset2;
607f4f56ff4SMark Johnston 	/* cipher info */
608f4f56ff4SMark Johnston 	uint16_t qcd_cipher_blk_sz;	/* in bytes */
609f4f56ff4SMark Johnston 	uint16_t qcd_auth_sz;		/* in bytes */
610f4f56ff4SMark Johnston 
611f4f56ff4SMark Johnston 	uint8_t qcd_req_cache[QAT_MSG_SIZE_TO_BYTES(QAT_MAX_MSG_SIZE)];
612f4f56ff4SMark Johnston } __aligned(QAT_OPTIMAL_ALIGN);
613f4f56ff4SMark Johnston 
614f4f56ff4SMark Johnston struct qat_session {
615f4f56ff4SMark Johnston 	struct qat_crypto_desc *qs_dec_desc;	/* should be at top of struct*/
616f4f56ff4SMark Johnston 	/* decrypt or auth then decrypt or auth */
617f4f56ff4SMark Johnston 
618f4f56ff4SMark Johnston 	struct qat_crypto_desc *qs_enc_desc;
619f4f56ff4SMark Johnston 	/* encrypt or encrypt then auth */
620f4f56ff4SMark Johnston 
621f4f56ff4SMark Johnston 	struct qat_dmamem qs_desc_mem;
622f4f56ff4SMark Johnston 
623f4f56ff4SMark Johnston 	enum hw_cipher_algo qs_cipher_algo;
624f4f56ff4SMark Johnston 	enum hw_cipher_mode qs_cipher_mode;
625f4f56ff4SMark Johnston 	enum hw_auth_algo qs_auth_algo;
626f4f56ff4SMark Johnston 	enum hw_auth_mode qs_auth_mode;
627f4f56ff4SMark Johnston 
628f4f56ff4SMark Johnston 	const uint8_t *qs_cipher_key;
629f4f56ff4SMark Johnston 	int qs_cipher_klen;
630f4f56ff4SMark Johnston 	const uint8_t *qs_auth_key;
631f4f56ff4SMark Johnston 	int qs_auth_klen;
632f4f56ff4SMark Johnston 	int qs_auth_mlen;
633f4f56ff4SMark Johnston 
634f4f56ff4SMark Johnston 	uint32_t qs_status;
635f4f56ff4SMark Johnston #define QAT_SESSION_STATUS_ACTIVE	(1 << 0)
636f4f56ff4SMark Johnston #define QAT_SESSION_STATUS_FREEING	(1 << 1)
637f4f56ff4SMark Johnston 	uint32_t qs_inflight;
638f4f56ff4SMark Johnston 	int qs_aad_length;
639f4f56ff4SMark Johnston 	bool qs_need_wakeup;
640f4f56ff4SMark Johnston 
641f4f56ff4SMark Johnston 	struct mtx qs_session_mtx;
642f4f56ff4SMark Johnston };
643f4f56ff4SMark Johnston 
644f4f56ff4SMark Johnston struct qat_crypto_bank {
645f4f56ff4SMark Johnston 	uint16_t qcb_bank;
646f4f56ff4SMark Johnston 
647f4f56ff4SMark Johnston 	struct qat_ring *qcb_sym_tx;
648f4f56ff4SMark Johnston 	struct qat_ring *qcb_sym_rx;
649f4f56ff4SMark Johnston 
650f4f56ff4SMark Johnston 	struct qat_dmamem qcb_symck_dmamems[QAT_NSYMCOOKIE];
651f4f56ff4SMark Johnston 	struct qat_sym_cookie *qcb_symck_free[QAT_NSYMCOOKIE];
652f4f56ff4SMark Johnston 	uint32_t qcb_symck_free_count;
653f4f56ff4SMark Johnston 
654f4f56ff4SMark Johnston 	struct mtx qcb_bank_mtx;
655f4f56ff4SMark Johnston 
656f4f56ff4SMark Johnston 	char qcb_ring_names[2][QAT_RING_NAME_SIZE];	/* sym tx,rx */
657f4f56ff4SMark Johnston };
658f4f56ff4SMark Johnston 
659f4f56ff4SMark Johnston struct qat_crypto {
660f4f56ff4SMark Johnston 	struct qat_softc *qcy_sc;
661f4f56ff4SMark Johnston 	uint32_t qcy_bank_mask;
662f4f56ff4SMark Johnston 	uint16_t qcy_num_banks;
663f4f56ff4SMark Johnston 
664f4f56ff4SMark Johnston 	int32_t qcy_cid;		/* OpenCrypto driver ID */
665f4f56ff4SMark Johnston 
666f4f56ff4SMark Johnston 	struct qat_crypto_bank *qcy_banks; /* array of qat_crypto_bank */
667f4f56ff4SMark Johnston 
668f4f56ff4SMark Johnston 	uint32_t qcy_session_free_count;
669f4f56ff4SMark Johnston 
670f4f56ff4SMark Johnston 	struct mtx qcy_crypto_mtx;
671f4f56ff4SMark Johnston };
672f4f56ff4SMark Johnston 
673f4f56ff4SMark Johnston struct qat_hw {
674f4f56ff4SMark Johnston 	int8_t qhw_sram_bar_id;
675f4f56ff4SMark Johnston 	int8_t qhw_misc_bar_id;
676f4f56ff4SMark Johnston 	int8_t qhw_etr_bar_id;
677f4f56ff4SMark Johnston 
678f4f56ff4SMark Johnston 	bus_size_t qhw_cap_global_offset;
679f4f56ff4SMark Johnston 	bus_size_t qhw_ae_offset;
680f4f56ff4SMark Johnston 	bus_size_t qhw_ae_local_offset;
681f4f56ff4SMark Johnston 	bus_size_t qhw_etr_bundle_size;
682f4f56ff4SMark Johnston 
683f4f56ff4SMark Johnston 	/* crypto processing callbacks */
684f4f56ff4SMark Johnston 	size_t qhw_crypto_opaque_offset;
685f4f56ff4SMark Johnston 	void (*qhw_crypto_setup_req_params)(struct qat_crypto_bank *,
686f4f56ff4SMark Johnston 	    struct qat_session *, struct qat_crypto_desc const *,
687f4f56ff4SMark Johnston 	    struct qat_sym_cookie *, struct cryptop *);
688f4f56ff4SMark Johnston 	void (*qhw_crypto_setup_desc)(struct qat_crypto *, struct qat_session *,
689f4f56ff4SMark Johnston 	    struct qat_crypto_desc *);
690f4f56ff4SMark Johnston 
691f4f56ff4SMark Johnston 	uint8_t qhw_num_banks;			/* max number of banks */
692f4f56ff4SMark Johnston 	uint8_t qhw_num_ap_banks;		/* max number of AutoPush banks */
693f4f56ff4SMark Johnston 	uint8_t qhw_num_rings_per_bank;		/* rings per bank */
694f4f56ff4SMark Johnston 	uint8_t qhw_num_accel;			/* max number of accelerators */
695f4f56ff4SMark Johnston 	uint8_t qhw_num_engines;		/* max number of accelerator engines */
696f4f56ff4SMark Johnston 	uint8_t qhw_tx_rx_gap;
697f4f56ff4SMark Johnston 	uint32_t qhw_tx_rings_mask;
698f4f56ff4SMark Johnston 	uint32_t qhw_clock_per_sec;
699f4f56ff4SMark Johnston 	bool qhw_fw_auth;
700f4f56ff4SMark Johnston 	uint32_t qhw_fw_req_size;
701f4f56ff4SMark Johnston 	uint32_t qhw_fw_resp_size;
702f4f56ff4SMark Johnston 
703f4f56ff4SMark Johnston 	uint8_t qhw_ring_sym_tx;
704f4f56ff4SMark Johnston 	uint8_t qhw_ring_sym_rx;
705f4f56ff4SMark Johnston 	uint8_t qhw_ring_asym_tx;
706f4f56ff4SMark Johnston 	uint8_t qhw_ring_asym_rx;
707f4f56ff4SMark Johnston 
708f4f56ff4SMark Johnston 	/* MSIx */
709f4f56ff4SMark Johnston 	uint32_t qhw_msix_ae_vec_gap;	/* gap to ae vec from bank */
710f4f56ff4SMark Johnston 
711f4f56ff4SMark Johnston 	const char *qhw_mof_fwname;
712f4f56ff4SMark Johnston 	const char *qhw_mmp_fwname;
713f4f56ff4SMark Johnston 
714f4f56ff4SMark Johnston 	uint32_t qhw_prod_type;		/* cpu type */
715f4f56ff4SMark Johnston 
716f4f56ff4SMark Johnston 	/* setup callbacks */
717f4f56ff4SMark Johnston 	uint32_t (*qhw_get_accel_mask)(struct qat_softc *);
718f4f56ff4SMark Johnston 	uint32_t (*qhw_get_ae_mask)(struct qat_softc *);
719f4f56ff4SMark Johnston 	enum qat_sku (*qhw_get_sku)(struct qat_softc *);
720f4f56ff4SMark Johnston 	uint32_t (*qhw_get_accel_cap)(struct qat_softc *);
721f4f56ff4SMark Johnston 	const char *(*qhw_get_fw_uof_name)(struct qat_softc *);
722f4f56ff4SMark Johnston 	void (*qhw_enable_intr)(struct qat_softc *);
723f4f56ff4SMark Johnston 	void (*qhw_init_etr_intr)(struct qat_softc *, int);
724f4f56ff4SMark Johnston 	int (*qhw_init_admin_comms)(struct qat_softc *);
725f4f56ff4SMark Johnston 	int (*qhw_send_admin_init)(struct qat_softc *);
726f4f56ff4SMark Johnston 	int (*qhw_init_arb)(struct qat_softc *);
727f4f56ff4SMark Johnston 	void (*qhw_get_arb_mapping)(struct qat_softc *, const uint32_t **);
728f4f56ff4SMark Johnston 	void (*qhw_enable_error_correction)(struct qat_softc *);
729f4f56ff4SMark Johnston 	int (*qhw_check_uncorrectable_error)(struct qat_softc *);
730f4f56ff4SMark Johnston 	void (*qhw_print_err_registers)(struct qat_softc *);
731f4f56ff4SMark Johnston 	void (*qhw_disable_error_interrupts)(struct qat_softc *);
732f4f56ff4SMark Johnston 	int (*qhw_check_slice_hang)(struct qat_softc *);
733f4f56ff4SMark Johnston 	int (*qhw_set_ssm_wdtimer)(struct qat_softc *);
734f4f56ff4SMark Johnston };
735f4f56ff4SMark Johnston 
736f4f56ff4SMark Johnston 
737f4f56ff4SMark Johnston /* sc_flags */
738f4f56ff4SMark Johnston #define QAT_FLAG_ESRAM_ENABLE_AUTO_INIT	(1 << 0)
739f4f56ff4SMark Johnston #define QAT_FLAG_SHRAM_WAIT_READY	(1 << 1)
740f4f56ff4SMark Johnston 
741f4f56ff4SMark Johnston /* sc_accel_cap */
742f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_CRYPTO_SYMMETRIC	(1 << 0)
743f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_CRYPTO_ASYMMETRIC	(1 << 1)
744f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_CIPHER		(1 << 2)
745f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_AUTHENTICATION	(1 << 3)
746f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_REGEX		(1 << 4)
747f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_COMPRESSION	(1 << 5)
748f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_LZS_COMPRESSION	(1 << 6)
749f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_RANDOM_NUMBER	(1 << 7)
750f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_ZUC		(1 << 8)
751f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_SHA3		(1 << 9)
752f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_KPT		(1 << 10)
753f4f56ff4SMark Johnston 
754f4f56ff4SMark Johnston #define QAT_ACCEL_CAP_BITS	\
755f4f56ff4SMark Johnston 	"\177\020"	\
756f4f56ff4SMark Johnston 	"b\x0a"		"KPT\0" \
757f4f56ff4SMark Johnston 	"b\x09"		"SHA3\0" \
758f4f56ff4SMark Johnston 	"b\x08"		"ZUC\0" \
759f4f56ff4SMark Johnston 	"b\x07"		"RANDOM_NUMBER\0" \
760f4f56ff4SMark Johnston 	"b\x06"		"LZS_COMPRESSION\0" \
761f4f56ff4SMark Johnston 	"b\x05"		"COMPRESSION\0" \
762f4f56ff4SMark Johnston 	"b\x04"		"REGEX\0" \
763f4f56ff4SMark Johnston 	"b\x03"		"AUTHENTICATION\0" \
764f4f56ff4SMark Johnston 	"b\x02"		"CIPHER\0" \
765f4f56ff4SMark Johnston 	"b\x01"		"CRYPTO_ASYMMETRIC\0" \
766f4f56ff4SMark Johnston 	"b\x00"		"CRYPTO_SYMMETRIC\0"
767f4f56ff4SMark Johnston 
768f4f56ff4SMark Johnston #define QAT_HI_PRIO_RING_WEIGHT		0xfc
769f4f56ff4SMark Johnston #define QAT_LO_PRIO_RING_WEIGHT		0xfe
770f4f56ff4SMark Johnston #define QAT_DEFAULT_RING_WEIGHT		0xff
771f4f56ff4SMark Johnston #define QAT_DEFAULT_PVL			0
772f4f56ff4SMark Johnston 
773f4f56ff4SMark Johnston struct firmware;
774f4f56ff4SMark Johnston struct resource;
775f4f56ff4SMark Johnston 
776f4f56ff4SMark Johnston struct qat_softc {
777f4f56ff4SMark Johnston 	device_t sc_dev;
778f4f56ff4SMark Johnston 
779f4f56ff4SMark Johnston 	struct resource *sc_res[MAX_BARS];
780f4f56ff4SMark Johnston 	int sc_rid[MAX_BARS];
781f4f56ff4SMark Johnston 	bus_space_tag_t sc_csrt[MAX_BARS];
782f4f56ff4SMark Johnston 	bus_space_handle_t sc_csrh[MAX_BARS];
783f4f56ff4SMark Johnston 
784f4f56ff4SMark Johnston 	uint32_t sc_ae_num;
785f4f56ff4SMark Johnston 	uint32_t sc_ae_mask;
786f4f56ff4SMark Johnston 
787f4f56ff4SMark Johnston 	struct qat_crypto sc_crypto;		/* crypto services */
788f4f56ff4SMark Johnston 
789f4f56ff4SMark Johnston 	struct qat_hw sc_hw;
790f4f56ff4SMark Johnston 
791f4f56ff4SMark Johnston 	uint8_t sc_rev;
792f4f56ff4SMark Johnston 	enum qat_sku sc_sku;
793f4f56ff4SMark Johnston 	uint32_t sc_flags;
794f4f56ff4SMark Johnston 
795f4f56ff4SMark Johnston 	uint32_t sc_accel_num;
796f4f56ff4SMark Johnston 	uint32_t sc_accel_mask;
797f4f56ff4SMark Johnston 	uint32_t sc_accel_cap;
798f4f56ff4SMark Johnston 
799f4f56ff4SMark Johnston 	struct qat_admin_rings sc_admin_rings;	/* use only for qat 1.5 */
800f4f56ff4SMark Johnston 	struct qat_admin_comms sc_admin_comms;	/* use only for qat 1.7 */
801f4f56ff4SMark Johnston 
802f4f56ff4SMark Johnston 	/* ETR */
803f4f56ff4SMark Johnston 	struct qat_bank *sc_etr_banks;		/* array of etr banks */
804f4f56ff4SMark Johnston 	struct qat_ap_bank *sc_etr_ap_banks;	/* array of etr auto push banks */
805f4f56ff4SMark Johnston 
806f4f56ff4SMark Johnston 	/* AE */
807f4f56ff4SMark Johnston 	struct qat_ae sc_ae[MAX_NUM_AE];
808f4f56ff4SMark Johnston 
809f4f56ff4SMark Johnston 	/* Interrupt */
810f4f56ff4SMark Johnston 	struct resource *sc_ih;			/* ae cluster ih */
811f4f56ff4SMark Johnston 	void *sc_ih_cookie;			/* ae cluster ih cookie */
812f4f56ff4SMark Johnston 
813f4f56ff4SMark Johnston 	/* Counters */
814f4f56ff4SMark Johnston 	counter_u64_t sc_gcm_aad_restarts;
815f4f56ff4SMark Johnston 	counter_u64_t sc_gcm_aad_updates;
816f4f56ff4SMark Johnston 	counter_u64_t sc_ring_full_restarts;
817f4f56ff4SMark Johnston 	counter_u64_t sc_sym_alloc_failures;
818f4f56ff4SMark Johnston 
819f4f56ff4SMark Johnston 	/* Firmware */
820f4f56ff4SMark Johnston 	void *sc_fw_mof;			/* mof data */
821f4f56ff4SMark Johnston 	size_t sc_fw_mof_size;			/* mof size */
822f4f56ff4SMark Johnston 	struct qat_mof sc_mof;			/* mof sections */
823f4f56ff4SMark Johnston 
824f4f56ff4SMark Johnston 	const char *sc_fw_uof_name;		/* uof/suof name in mof */
825f4f56ff4SMark Johnston 
826f4f56ff4SMark Johnston 	void *sc_fw_uof;			/* uof head */
827f4f56ff4SMark Johnston 	size_t sc_fw_uof_size;			/* uof size */
828f4f56ff4SMark Johnston 	struct qat_aefw_uof sc_aefw_uof;	/* UOF_OBJS in uof */
829f4f56ff4SMark Johnston 
830f4f56ff4SMark Johnston 	void *sc_fw_suof;			/* suof head */
831f4f56ff4SMark Johnston 	size_t sc_fw_suof_size;			/* suof size */
832f4f56ff4SMark Johnston 	struct qat_aefw_suof sc_aefw_suof;	/* suof context */
833f4f56ff4SMark Johnston 
834f4f56ff4SMark Johnston 	void *sc_fw_mmp;			/* mmp data */
835f4f56ff4SMark Johnston 	size_t sc_fw_mmp_size;			/* mmp size */
836f4f56ff4SMark Johnston };
837f4f56ff4SMark Johnston 
838f4f56ff4SMark Johnston static inline void
qat_bar_write_4(struct qat_softc * sc,int baroff,bus_size_t offset,uint32_t value)839f4f56ff4SMark Johnston qat_bar_write_4(struct qat_softc *sc, int baroff, bus_size_t offset,
840f4f56ff4SMark Johnston     uint32_t value)
841f4f56ff4SMark Johnston {
842f4f56ff4SMark Johnston 
843f4f56ff4SMark Johnston 	MPASS(baroff >= 0 && baroff < MAX_BARS);
844f4f56ff4SMark Johnston 
845f4f56ff4SMark Johnston 	bus_space_write_4(sc->sc_csrt[baroff],
846f4f56ff4SMark Johnston 	    sc->sc_csrh[baroff], offset, value);
847f4f56ff4SMark Johnston }
848f4f56ff4SMark Johnston 
849f4f56ff4SMark Johnston static inline uint32_t
qat_bar_read_4(struct qat_softc * sc,int baroff,bus_size_t offset)850f4f56ff4SMark Johnston qat_bar_read_4(struct qat_softc *sc, int baroff, bus_size_t offset)
851f4f56ff4SMark Johnston {
852f4f56ff4SMark Johnston 
853f4f56ff4SMark Johnston 	MPASS(baroff >= 0 && baroff < MAX_BARS);
854f4f56ff4SMark Johnston 
855f4f56ff4SMark Johnston 	return bus_space_read_4(sc->sc_csrt[baroff],
856f4f56ff4SMark Johnston 	    sc->sc_csrh[baroff], offset);
857f4f56ff4SMark Johnston }
858f4f56ff4SMark Johnston 
859f4f56ff4SMark Johnston static inline void
qat_misc_write_4(struct qat_softc * sc,bus_size_t offset,uint32_t value)860f4f56ff4SMark Johnston qat_misc_write_4(struct qat_softc *sc, bus_size_t offset, uint32_t value)
861f4f56ff4SMark Johnston {
862f4f56ff4SMark Johnston 
863f4f56ff4SMark Johnston 	qat_bar_write_4(sc, sc->sc_hw.qhw_misc_bar_id, offset, value);
864f4f56ff4SMark Johnston }
865f4f56ff4SMark Johnston 
866f4f56ff4SMark Johnston static inline uint32_t
qat_misc_read_4(struct qat_softc * sc,bus_size_t offset)867f4f56ff4SMark Johnston qat_misc_read_4(struct qat_softc *sc, bus_size_t offset)
868f4f56ff4SMark Johnston {
869f4f56ff4SMark Johnston 
870f4f56ff4SMark Johnston 	return qat_bar_read_4(sc, sc->sc_hw.qhw_misc_bar_id, offset);
871f4f56ff4SMark Johnston }
872f4f56ff4SMark Johnston 
873f4f56ff4SMark Johnston static inline void
qat_misc_read_write_or_4(struct qat_softc * sc,bus_size_t offset,uint32_t value)874f4f56ff4SMark Johnston qat_misc_read_write_or_4(struct qat_softc *sc, bus_size_t offset,
875f4f56ff4SMark Johnston     uint32_t value)
876f4f56ff4SMark Johnston {
877f4f56ff4SMark Johnston 	uint32_t reg;
878f4f56ff4SMark Johnston 
879f4f56ff4SMark Johnston 	reg = qat_misc_read_4(sc, offset);
880f4f56ff4SMark Johnston 	reg |= value;
881f4f56ff4SMark Johnston 	qat_misc_write_4(sc, offset, reg);
882f4f56ff4SMark Johnston }
883f4f56ff4SMark Johnston 
884f4f56ff4SMark Johnston static inline void
qat_misc_read_write_and_4(struct qat_softc * sc,bus_size_t offset,uint32_t mask)885f4f56ff4SMark Johnston qat_misc_read_write_and_4(struct qat_softc *sc, bus_size_t offset,
886f4f56ff4SMark Johnston     uint32_t mask)
887f4f56ff4SMark Johnston {
888f4f56ff4SMark Johnston 	uint32_t reg;
889f4f56ff4SMark Johnston 
890f4f56ff4SMark Johnston 	reg = qat_misc_read_4(sc, offset);
891f4f56ff4SMark Johnston 	reg &= mask;
892f4f56ff4SMark Johnston 	qat_misc_write_4(sc, offset, reg);
893f4f56ff4SMark Johnston }
894f4f56ff4SMark Johnston 
895f4f56ff4SMark Johnston static inline void
qat_etr_write_4(struct qat_softc * sc,bus_size_t offset,uint32_t value)896f4f56ff4SMark Johnston qat_etr_write_4(struct qat_softc *sc, bus_size_t offset, uint32_t value)
897f4f56ff4SMark Johnston {
898f4f56ff4SMark Johnston 
899f4f56ff4SMark Johnston 	qat_bar_write_4(sc, sc->sc_hw.qhw_etr_bar_id, offset, value);
900f4f56ff4SMark Johnston }
901f4f56ff4SMark Johnston 
902f4f56ff4SMark Johnston static inline uint32_t
qat_etr_read_4(struct qat_softc * sc,bus_size_t offset)903f4f56ff4SMark Johnston qat_etr_read_4(struct qat_softc *sc, bus_size_t offset)
904f4f56ff4SMark Johnston {
905f4f56ff4SMark Johnston 
906f4f56ff4SMark Johnston 	return qat_bar_read_4(sc, sc->sc_hw.qhw_etr_bar_id, offset);
907f4f56ff4SMark Johnston }
908f4f56ff4SMark Johnston 
909f4f56ff4SMark Johnston static inline void
qat_ae_local_write_4(struct qat_softc * sc,u_char ae,bus_size_t offset,uint32_t value)910f4f56ff4SMark Johnston qat_ae_local_write_4(struct qat_softc *sc, u_char ae, bus_size_t offset,
911f4f56ff4SMark Johnston 	uint32_t value)
912f4f56ff4SMark Johnston {
913f4f56ff4SMark Johnston 
914f4f56ff4SMark Johnston 	offset = __SHIFTIN(ae & sc->sc_ae_mask, AE_LOCAL_AE_MASK) |
915f4f56ff4SMark Johnston 	    (offset & AE_LOCAL_CSR_MASK);
916f4f56ff4SMark Johnston 
917f4f56ff4SMark Johnston 	qat_misc_write_4(sc, sc->sc_hw.qhw_ae_local_offset + offset,
918f4f56ff4SMark Johnston 	    value);
919f4f56ff4SMark Johnston }
920f4f56ff4SMark Johnston 
921f4f56ff4SMark Johnston static inline uint32_t
qat_ae_local_read_4(struct qat_softc * sc,u_char ae,bus_size_t offset)922f4f56ff4SMark Johnston qat_ae_local_read_4(struct qat_softc *sc, u_char ae, bus_size_t offset)
923f4f56ff4SMark Johnston {
924f4f56ff4SMark Johnston 
925f4f56ff4SMark Johnston 	offset = __SHIFTIN(ae & sc->sc_ae_mask, AE_LOCAL_AE_MASK) |
926f4f56ff4SMark Johnston 	    (offset & AE_LOCAL_CSR_MASK);
927f4f56ff4SMark Johnston 
928f4f56ff4SMark Johnston 	return qat_misc_read_4(sc, sc->sc_hw.qhw_ae_local_offset + offset);
929f4f56ff4SMark Johnston }
930f4f56ff4SMark Johnston 
931f4f56ff4SMark Johnston static inline void
qat_ae_xfer_write_4(struct qat_softc * sc,u_char ae,bus_size_t offset,uint32_t value)932f4f56ff4SMark Johnston qat_ae_xfer_write_4(struct qat_softc *sc, u_char ae, bus_size_t offset,
933f4f56ff4SMark Johnston 	uint32_t value)
934f4f56ff4SMark Johnston {
935f4f56ff4SMark Johnston 	offset = __SHIFTIN(ae & sc->sc_ae_mask, AE_XFER_AE_MASK) |
936f4f56ff4SMark Johnston 	    __SHIFTIN(offset, AE_XFER_CSR_MASK);
937f4f56ff4SMark Johnston 
938f4f56ff4SMark Johnston 	qat_misc_write_4(sc, sc->sc_hw.qhw_ae_offset + offset, value);
939f4f56ff4SMark Johnston }
940f4f56ff4SMark Johnston 
941f4f56ff4SMark Johnston static inline void
qat_cap_global_write_4(struct qat_softc * sc,bus_size_t offset,uint32_t value)942f4f56ff4SMark Johnston qat_cap_global_write_4(struct qat_softc *sc, bus_size_t offset, uint32_t value)
943f4f56ff4SMark Johnston {
944f4f56ff4SMark Johnston 
945f4f56ff4SMark Johnston 	qat_misc_write_4(sc, sc->sc_hw.qhw_cap_global_offset + offset, value);
946f4f56ff4SMark Johnston }
947f4f56ff4SMark Johnston 
948f4f56ff4SMark Johnston static inline uint32_t
qat_cap_global_read_4(struct qat_softc * sc,bus_size_t offset)949f4f56ff4SMark Johnston qat_cap_global_read_4(struct qat_softc *sc, bus_size_t offset)
950f4f56ff4SMark Johnston {
951f4f56ff4SMark Johnston 
952f4f56ff4SMark Johnston 	return qat_misc_read_4(sc, sc->sc_hw.qhw_cap_global_offset + offset);
953f4f56ff4SMark Johnston }
954f4f56ff4SMark Johnston 
955f4f56ff4SMark Johnston 
956f4f56ff4SMark Johnston static inline void
qat_etr_bank_write_4(struct qat_softc * sc,int bank,bus_size_t offset,uint32_t value)957f4f56ff4SMark Johnston qat_etr_bank_write_4(struct qat_softc *sc, int bank,
958f4f56ff4SMark Johnston 	bus_size_t offset, uint32_t value)
959f4f56ff4SMark Johnston {
960f4f56ff4SMark Johnston 
961f4f56ff4SMark Johnston 	qat_etr_write_4(sc, sc->sc_hw.qhw_etr_bundle_size * bank + offset,
962f4f56ff4SMark Johnston 	    value);
963f4f56ff4SMark Johnston }
964f4f56ff4SMark Johnston 
965f4f56ff4SMark Johnston static inline uint32_t
qat_etr_bank_read_4(struct qat_softc * sc,int bank,bus_size_t offset)966f4f56ff4SMark Johnston qat_etr_bank_read_4(struct qat_softc *sc, int bank,
967f4f56ff4SMark Johnston 	bus_size_t offset)
968f4f56ff4SMark Johnston {
969f4f56ff4SMark Johnston 
970f4f56ff4SMark Johnston 	return qat_etr_read_4(sc,
971f4f56ff4SMark Johnston 	    sc->sc_hw.qhw_etr_bundle_size * bank + offset);
972f4f56ff4SMark Johnston }
973f4f56ff4SMark Johnston 
974f4f56ff4SMark Johnston static inline void
qat_etr_ap_bank_write_4(struct qat_softc * sc,int ap_bank,bus_size_t offset,uint32_t value)975f4f56ff4SMark Johnston qat_etr_ap_bank_write_4(struct qat_softc *sc, int ap_bank,
976f4f56ff4SMark Johnston 	bus_size_t offset, uint32_t value)
977f4f56ff4SMark Johnston {
978f4f56ff4SMark Johnston 
979f4f56ff4SMark Johnston 	qat_etr_write_4(sc, ETR_AP_BANK_OFFSET * ap_bank + offset, value);
980f4f56ff4SMark Johnston }
981f4f56ff4SMark Johnston 
982f4f56ff4SMark Johnston static inline uint32_t
qat_etr_ap_bank_read_4(struct qat_softc * sc,int ap_bank,bus_size_t offset)983f4f56ff4SMark Johnston qat_etr_ap_bank_read_4(struct qat_softc *sc, int ap_bank,
984f4f56ff4SMark Johnston 	bus_size_t offset)
985f4f56ff4SMark Johnston {
986f4f56ff4SMark Johnston 
987f4f56ff4SMark Johnston 	return qat_etr_read_4(sc, ETR_AP_BANK_OFFSET * ap_bank + offset);
988f4f56ff4SMark Johnston }
989f4f56ff4SMark Johnston 
990f4f56ff4SMark Johnston 
991f4f56ff4SMark Johnston static inline void
qat_etr_bank_ring_write_4(struct qat_softc * sc,int bank,int ring,bus_size_t offset,uint32_t value)992f4f56ff4SMark Johnston qat_etr_bank_ring_write_4(struct qat_softc *sc, int bank, int ring,
993f4f56ff4SMark Johnston 	bus_size_t offset, uint32_t value)
994f4f56ff4SMark Johnston {
995f4f56ff4SMark Johnston 
996f4f56ff4SMark Johnston 	qat_etr_bank_write_4(sc, bank, (ring << 2) + offset, value);
997f4f56ff4SMark Johnston }
998f4f56ff4SMark Johnston 
999f4f56ff4SMark Johnston static inline uint32_t
qat_etr_bank_ring_read_4(struct qat_softc * sc,int bank,int ring,bus_size_t offset)1000f4f56ff4SMark Johnston qat_etr_bank_ring_read_4(struct qat_softc *sc, int bank, int ring,
1001f4f56ff4SMark Johnston 	bus_size_t offset)
1002f4f56ff4SMark Johnston {
1003f4f56ff4SMark Johnston 
1004f4f56ff4SMark Johnston 	return qat_etr_bank_read_4(sc, bank, (ring << 2) * offset);
1005f4f56ff4SMark Johnston }
1006f4f56ff4SMark Johnston 
1007f4f56ff4SMark Johnston static inline void
qat_etr_bank_ring_base_write_8(struct qat_softc * sc,int bank,int ring,uint64_t value)1008f4f56ff4SMark Johnston qat_etr_bank_ring_base_write_8(struct qat_softc *sc, int bank, int ring,
1009f4f56ff4SMark Johnston 	uint64_t value)
1010f4f56ff4SMark Johnston {
1011f4f56ff4SMark Johnston 	uint32_t lo, hi;
1012f4f56ff4SMark Johnston 
1013f4f56ff4SMark Johnston 	lo = (uint32_t)(value & 0xffffffff);
1014f4f56ff4SMark Johnston 	hi = (uint32_t)((value & 0xffffffff00000000ULL) >> 32);
1015f4f56ff4SMark Johnston 	qat_etr_bank_ring_write_4(sc, bank, ring, ETR_RING_LBASE, lo);
1016f4f56ff4SMark Johnston 	qat_etr_bank_ring_write_4(sc, bank, ring, ETR_RING_UBASE, hi);
1017f4f56ff4SMark Johnston }
1018f4f56ff4SMark Johnston 
1019f4f56ff4SMark Johnston static inline void
qat_arb_ringsrvarben_write_4(struct qat_softc * sc,int index,uint32_t value)1020f4f56ff4SMark Johnston qat_arb_ringsrvarben_write_4(struct qat_softc *sc, int index, uint32_t value)
1021f4f56ff4SMark Johnston {
1022f4f56ff4SMark Johnston 
1023f4f56ff4SMark Johnston 	qat_etr_write_4(sc, ARB_RINGSRVARBEN_OFFSET +
1024f4f56ff4SMark Johnston 	    (ARB_REG_SLOT * index), value);
1025f4f56ff4SMark Johnston }
1026f4f56ff4SMark Johnston 
1027f4f56ff4SMark Johnston static inline void
qat_arb_sarconfig_write_4(struct qat_softc * sc,int index,uint32_t value)1028f4f56ff4SMark Johnston qat_arb_sarconfig_write_4(struct qat_softc *sc, int index, uint32_t value)
1029f4f56ff4SMark Johnston {
1030f4f56ff4SMark Johnston 
1031f4f56ff4SMark Johnston 	qat_etr_write_4(sc, ARB_OFFSET +
1032f4f56ff4SMark Johnston 	    (ARB_REG_SIZE * index), value);
1033f4f56ff4SMark Johnston }
1034f4f56ff4SMark Johnston 
1035f4f56ff4SMark Johnston static inline void
qat_arb_wrk_2_ser_map_write_4(struct qat_softc * sc,int index,uint32_t value)1036f4f56ff4SMark Johnston qat_arb_wrk_2_ser_map_write_4(struct qat_softc *sc, int index, uint32_t value)
1037f4f56ff4SMark Johnston {
1038f4f56ff4SMark Johnston 
1039f4f56ff4SMark Johnston 	qat_etr_write_4(sc, ARB_OFFSET + ARB_WRK_2_SER_MAP_OFFSET +
1040f4f56ff4SMark Johnston 	    (ARB_REG_SIZE * index), value);
1041f4f56ff4SMark Johnston }
1042f4f56ff4SMark Johnston 
1043f4f56ff4SMark Johnston void *		qat_alloc_mem(size_t);
1044f4f56ff4SMark Johnston void		qat_free_mem(void *);
1045f4f56ff4SMark Johnston void		qat_free_dmamem(struct qat_softc *, struct qat_dmamem *);
1046f4f56ff4SMark Johnston int		qat_alloc_dmamem(struct qat_softc *, struct qat_dmamem *, int,
1047f4f56ff4SMark Johnston 		    bus_size_t, bus_size_t);
1048f4f56ff4SMark Johnston 
1049f4f56ff4SMark Johnston int		qat_etr_setup_ring(struct qat_softc *, int, uint32_t, uint32_t,
1050f4f56ff4SMark Johnston 		    uint32_t, qat_cb_t, void *, const char *,
1051f4f56ff4SMark Johnston 		    struct qat_ring **);
1052f4f56ff4SMark Johnston int		qat_etr_put_msg(struct qat_softc *, struct qat_ring *,
1053f4f56ff4SMark Johnston 		    uint32_t *);
1054f4f56ff4SMark Johnston 
1055f4f56ff4SMark Johnston void		qat_memcpy_htobe64(void *, const void *, size_t);
1056f4f56ff4SMark Johnston void		qat_memcpy_htobe32(void *, const void *, size_t);
1057f4f56ff4SMark Johnston void		qat_memcpy_htobe(void *, const void *, size_t, uint32_t);
1058f4f56ff4SMark Johnston void		qat_crypto_gmac_precompute(const struct qat_crypto_desc *,
1059f4f56ff4SMark Johnston 		    const uint8_t *key, int klen,
1060f4f56ff4SMark Johnston 		    const struct qat_sym_hash_def *, uint8_t *);
1061f4f56ff4SMark Johnston void		qat_crypto_hmac_precompute(const struct qat_crypto_desc *,
1062f4f56ff4SMark Johnston 		    const uint8_t *, int, const struct qat_sym_hash_def *,
1063f4f56ff4SMark Johnston 		    uint8_t *, uint8_t *);
1064f4f56ff4SMark Johnston uint16_t	qat_crypto_load_cipher_session(const struct qat_crypto_desc *,
1065f4f56ff4SMark Johnston 		    const struct qat_session *);
1066f4f56ff4SMark Johnston uint16_t	qat_crypto_load_auth_session(const struct qat_crypto_desc *,
1067f4f56ff4SMark Johnston 		    const struct qat_session *,
1068f4f56ff4SMark Johnston 		    struct qat_sym_hash_def const **);
1069f4f56ff4SMark Johnston 
1070f4f56ff4SMark Johnston #endif
1071