1*b61a5730SWarner Losh /* SPDX-License-Identifier: BSD-2-Clause AND BSD-3-Clause */
2f4f56ff4SMark Johnston /* $NetBSD: qat_hw15.c,v 1.1 2019/11/20 09:37:46 hikaru 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-2013 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 #include <sys/cdefs.h>
61f4f56ff4SMark Johnston #if 0
62f4f56ff4SMark Johnston __KERNEL_RCSID(0, "$NetBSD: qat_hw15.c,v 1.1 2019/11/20 09:37:46 hikaru Exp $");
63f4f56ff4SMark Johnston #endif
64f4f56ff4SMark Johnston
65f4f56ff4SMark Johnston #include <sys/param.h>
66f4f56ff4SMark Johnston #include <sys/bus.h>
67f4f56ff4SMark Johnston #include <sys/kernel.h>
68f4f56ff4SMark Johnston #include <sys/proc.h>
69f4f56ff4SMark Johnston #include <sys/systm.h>
70f4f56ff4SMark Johnston
71f4f56ff4SMark Johnston #include <machine/bus.h>
72f4f56ff4SMark Johnston
73f4f56ff4SMark Johnston #include <opencrypto/xform.h>
74f4f56ff4SMark Johnston
75f4f56ff4SMark Johnston #include <dev/pci/pcireg.h>
76f4f56ff4SMark Johnston #include <dev/pci/pcivar.h>
77f4f56ff4SMark Johnston
78f4f56ff4SMark Johnston #include "qatreg.h"
79f4f56ff4SMark Johnston #include "qat_hw15reg.h"
80f4f56ff4SMark Johnston #include "qatvar.h"
81f4f56ff4SMark Johnston #include "qat_hw15var.h"
82f4f56ff4SMark Johnston
83f4f56ff4SMark Johnston static int qat_adm_ring_init_ring_table(struct qat_softc *);
84f4f56ff4SMark Johnston static void qat_adm_ring_build_slice_mask(uint16_t *, uint32_t, uint32_t);
85f4f56ff4SMark Johnston static void qat_adm_ring_build_shram_mask(uint64_t *, uint32_t, uint32_t);
86f4f56ff4SMark Johnston static int qat_adm_ring_build_ring_table(struct qat_softc *, uint32_t);
87f4f56ff4SMark Johnston static int qat_adm_ring_build_init_msg(struct qat_softc *,
88f4f56ff4SMark Johnston struct fw_init_req *, enum fw_init_cmd_id, uint32_t,
89f4f56ff4SMark Johnston struct qat_accel_init_cb *);
90f4f56ff4SMark Johnston static int qat_adm_ring_send_init_msg_sync(struct qat_softc *,
91f4f56ff4SMark Johnston enum fw_init_cmd_id, uint32_t);
92f4f56ff4SMark Johnston static int qat_adm_ring_send_init_msg(struct qat_softc *,
93f4f56ff4SMark Johnston enum fw_init_cmd_id);
94f4f56ff4SMark Johnston static int qat_adm_ring_intr(struct qat_softc *, void *, void *);
95f4f56ff4SMark Johnston
96f4f56ff4SMark Johnston void
qat_msg_req_type_populate(struct arch_if_req_hdr * msg,enum arch_if_req type,uint32_t rxring)97f4f56ff4SMark Johnston qat_msg_req_type_populate(struct arch_if_req_hdr *msg, enum arch_if_req type,
98f4f56ff4SMark Johnston uint32_t rxring)
99f4f56ff4SMark Johnston {
100f4f56ff4SMark Johnston
101f4f56ff4SMark Johnston memset(msg, 0, sizeof(struct arch_if_req_hdr));
102f4f56ff4SMark Johnston msg->flags = ARCH_IF_FLAGS_VALID_FLAG |
103f4f56ff4SMark Johnston ARCH_IF_FLAGS_RESP_RING_TYPE_ET | ARCH_IF_FLAGS_RESP_TYPE_S;
104f4f56ff4SMark Johnston msg->req_type = type;
105f4f56ff4SMark Johnston msg->resp_pipe_id = rxring;
106f4f56ff4SMark Johnston }
107f4f56ff4SMark Johnston
108f4f56ff4SMark Johnston void
qat_msg_cmn_hdr_populate(struct fw_la_bulk_req * msg,bus_addr_t desc_paddr,uint8_t hdrsz,uint8_t hwblksz,uint16_t comn_req_flags,uint32_t flow_id)109f4f56ff4SMark Johnston qat_msg_cmn_hdr_populate(struct fw_la_bulk_req *msg, bus_addr_t desc_paddr,
110f4f56ff4SMark Johnston uint8_t hdrsz, uint8_t hwblksz, uint16_t comn_req_flags, uint32_t flow_id)
111f4f56ff4SMark Johnston {
112f4f56ff4SMark Johnston struct fw_comn_req_hdr *hdr = &msg->comn_hdr;
113f4f56ff4SMark Johnston
114f4f56ff4SMark Johnston hdr->comn_req_flags = comn_req_flags;
115f4f56ff4SMark Johnston hdr->content_desc_params_sz = hwblksz;
116f4f56ff4SMark Johnston hdr->content_desc_hdr_sz = hdrsz;
117f4f56ff4SMark Johnston hdr->content_desc_addr = desc_paddr;
118f4f56ff4SMark Johnston msg->flow_id = flow_id;
119f4f56ff4SMark Johnston }
120f4f56ff4SMark Johnston
121f4f56ff4SMark Johnston void
qat_msg_service_cmd_populate(struct fw_la_bulk_req * msg,enum fw_la_cmd_id cmdid,uint16_t cmd_flags)122f4f56ff4SMark Johnston qat_msg_service_cmd_populate(struct fw_la_bulk_req *msg, enum fw_la_cmd_id cmdid,
123f4f56ff4SMark Johnston uint16_t cmd_flags)
124f4f56ff4SMark Johnston {
125f4f56ff4SMark Johnston msg->comn_la_req.la_cmd_id = cmdid;
126f4f56ff4SMark Johnston msg->comn_la_req.u.la_flags = cmd_flags;
127f4f56ff4SMark Johnston }
128f4f56ff4SMark Johnston
129f4f56ff4SMark Johnston void
qat_msg_cmn_mid_populate(struct fw_comn_req_mid * msg,void * cookie,uint64_t src,uint64_t dst)130f4f56ff4SMark Johnston qat_msg_cmn_mid_populate(struct fw_comn_req_mid *msg, void *cookie,
131f4f56ff4SMark Johnston uint64_t src, uint64_t dst)
132f4f56ff4SMark Johnston {
133f4f56ff4SMark Johnston
134f4f56ff4SMark Johnston msg->opaque_data = (uint64_t)(uintptr_t)cookie;
135f4f56ff4SMark Johnston msg->src_data_addr = src;
136f4f56ff4SMark Johnston if (dst == 0)
137f4f56ff4SMark Johnston msg->dest_data_addr = src;
138f4f56ff4SMark Johnston else
139f4f56ff4SMark Johnston msg->dest_data_addr = dst;
140f4f56ff4SMark Johnston }
141f4f56ff4SMark Johnston
142f4f56ff4SMark Johnston void
qat_msg_req_params_populate(struct fw_la_bulk_req * msg,bus_addr_t req_params_paddr,uint8_t req_params_sz)143f4f56ff4SMark Johnston qat_msg_req_params_populate(struct fw_la_bulk_req *msg,
144f4f56ff4SMark Johnston bus_addr_t req_params_paddr, uint8_t req_params_sz)
145f4f56ff4SMark Johnston {
146f4f56ff4SMark Johnston msg->req_params_addr = req_params_paddr;
147f4f56ff4SMark Johnston msg->comn_la_req.u1.req_params_blk_sz = req_params_sz / 8;
148f4f56ff4SMark Johnston }
149f4f56ff4SMark Johnston
150f4f56ff4SMark Johnston void
qat_msg_cmn_footer_populate(union fw_comn_req_ftr * msg,uint64_t next_addr)151f4f56ff4SMark Johnston qat_msg_cmn_footer_populate(union fw_comn_req_ftr *msg, uint64_t next_addr)
152f4f56ff4SMark Johnston {
153f4f56ff4SMark Johnston msg->next_request_addr = next_addr;
154f4f56ff4SMark Johnston }
155f4f56ff4SMark Johnston
156f4f56ff4SMark Johnston void
qat_msg_params_populate(struct fw_la_bulk_req * msg,struct qat_crypto_desc * desc,uint8_t req_params_sz,uint16_t service_cmd_flags,uint16_t comn_req_flags)157f4f56ff4SMark Johnston qat_msg_params_populate(struct fw_la_bulk_req *msg,
158f4f56ff4SMark Johnston struct qat_crypto_desc *desc, uint8_t req_params_sz,
159f4f56ff4SMark Johnston uint16_t service_cmd_flags, uint16_t comn_req_flags)
160f4f56ff4SMark Johnston {
161f4f56ff4SMark Johnston qat_msg_cmn_hdr_populate(msg, desc->qcd_desc_paddr,
162f4f56ff4SMark Johnston desc->qcd_hdr_sz, desc->qcd_hw_blk_sz, comn_req_flags, 0);
163f4f56ff4SMark Johnston qat_msg_service_cmd_populate(msg, desc->qcd_cmd_id, service_cmd_flags);
164f4f56ff4SMark Johnston qat_msg_cmn_mid_populate(&msg->comn_mid, NULL, 0, 0);
165f4f56ff4SMark Johnston qat_msg_req_params_populate(msg, 0, req_params_sz);
166f4f56ff4SMark Johnston qat_msg_cmn_footer_populate(&msg->comn_ftr, 0);
167f4f56ff4SMark Johnston }
168f4f56ff4SMark Johnston
169f4f56ff4SMark Johnston static int
qat_adm_ring_init_ring_table(struct qat_softc * sc)170f4f56ff4SMark Johnston qat_adm_ring_init_ring_table(struct qat_softc *sc)
171f4f56ff4SMark Johnston {
172f4f56ff4SMark Johnston struct qat_admin_rings *qadr = &sc->sc_admin_rings;
173f4f56ff4SMark Johnston
174f4f56ff4SMark Johnston if (sc->sc_ae_num == 1) {
175f4f56ff4SMark Johnston qadr->qadr_cya_ring_tbl =
176f4f56ff4SMark Johnston &qadr->qadr_master_ring_tbl[0];
177f4f56ff4SMark Johnston qadr->qadr_srv_mask[0] = QAT_SERVICE_CRYPTO_A;
178f4f56ff4SMark Johnston } else if (sc->sc_ae_num == 2 || sc->sc_ae_num == 4) {
179f4f56ff4SMark Johnston qadr->qadr_cya_ring_tbl =
180f4f56ff4SMark Johnston &qadr->qadr_master_ring_tbl[0];
181f4f56ff4SMark Johnston qadr->qadr_srv_mask[0] = QAT_SERVICE_CRYPTO_A;
182f4f56ff4SMark Johnston qadr->qadr_cyb_ring_tbl =
183f4f56ff4SMark Johnston &qadr->qadr_master_ring_tbl[1];
184f4f56ff4SMark Johnston qadr->qadr_srv_mask[1] = QAT_SERVICE_CRYPTO_B;
185f4f56ff4SMark Johnston }
186f4f56ff4SMark Johnston
187f4f56ff4SMark Johnston return 0;
188f4f56ff4SMark Johnston }
189f4f56ff4SMark Johnston
190f4f56ff4SMark Johnston int
qat_adm_ring_init(struct qat_softc * sc)191f4f56ff4SMark Johnston qat_adm_ring_init(struct qat_softc *sc)
192f4f56ff4SMark Johnston {
193f4f56ff4SMark Johnston struct qat_admin_rings *qadr = &sc->sc_admin_rings;
194f4f56ff4SMark Johnston int error, i, j;
195f4f56ff4SMark Johnston
196f4f56ff4SMark Johnston error = qat_alloc_dmamem(sc, &qadr->qadr_dma, 1, PAGE_SIZE, PAGE_SIZE);
197f4f56ff4SMark Johnston if (error)
198f4f56ff4SMark Johnston return error;
199f4f56ff4SMark Johnston
200f4f56ff4SMark Johnston qadr->qadr_master_ring_tbl = qadr->qadr_dma.qdm_dma_vaddr;
201f4f56ff4SMark Johnston
202f4f56ff4SMark Johnston MPASS(sc->sc_ae_num *
203f4f56ff4SMark Johnston sizeof(struct fw_init_ring_table) <= PAGE_SIZE);
204f4f56ff4SMark Johnston
205f4f56ff4SMark Johnston /* Initialize the Master Ring Table */
206f4f56ff4SMark Johnston for (i = 0; i < sc->sc_ae_num; i++) {
207f4f56ff4SMark Johnston struct fw_init_ring_table *firt =
208f4f56ff4SMark Johnston &qadr->qadr_master_ring_tbl[i];
209f4f56ff4SMark Johnston
210f4f56ff4SMark Johnston for (j = 0; j < INIT_RING_TABLE_SZ; j++) {
211f4f56ff4SMark Johnston struct fw_init_ring_params *firp =
212f4f56ff4SMark Johnston &firt->firt_bulk_rings[j];
213f4f56ff4SMark Johnston
214f4f56ff4SMark Johnston firp->firp_reserved = 0;
215f4f56ff4SMark Johnston firp->firp_curr_weight = QAT_DEFAULT_RING_WEIGHT;
216f4f56ff4SMark Johnston firp->firp_init_weight = QAT_DEFAULT_RING_WEIGHT;
217f4f56ff4SMark Johnston firp->firp_ring_pvl = QAT_DEFAULT_PVL;
218f4f56ff4SMark Johnston }
219f4f56ff4SMark Johnston memset(firt->firt_ring_mask, 0, sizeof(firt->firt_ring_mask));
220f4f56ff4SMark Johnston }
221f4f56ff4SMark Johnston
222f4f56ff4SMark Johnston error = qat_etr_setup_ring(sc, 0, RING_NUM_ADMIN_TX,
223f4f56ff4SMark Johnston ADMIN_RING_SIZE, sc->sc_hw.qhw_fw_req_size,
224f4f56ff4SMark Johnston NULL, NULL, "admin_tx", &qadr->qadr_admin_tx);
225f4f56ff4SMark Johnston if (error)
226f4f56ff4SMark Johnston return error;
227f4f56ff4SMark Johnston
228f4f56ff4SMark Johnston error = qat_etr_setup_ring(sc, 0, RING_NUM_ADMIN_RX,
229f4f56ff4SMark Johnston ADMIN_RING_SIZE, sc->sc_hw.qhw_fw_resp_size,
230f4f56ff4SMark Johnston qat_adm_ring_intr, qadr, "admin_rx", &qadr->qadr_admin_rx);
231f4f56ff4SMark Johnston if (error)
232f4f56ff4SMark Johnston return error;
233f4f56ff4SMark Johnston
234f4f56ff4SMark Johnston /*
235f4f56ff4SMark Johnston * Finally set up the service indices into the Master Ring Table
236f4f56ff4SMark Johnston * and convenient ring table pointers for each service enabled.
237f4f56ff4SMark Johnston * Only the Admin rings are initialized.
238f4f56ff4SMark Johnston */
239f4f56ff4SMark Johnston error = qat_adm_ring_init_ring_table(sc);
240f4f56ff4SMark Johnston if (error)
241f4f56ff4SMark Johnston return error;
242f4f56ff4SMark Johnston
243f4f56ff4SMark Johnston /*
244f4f56ff4SMark Johnston * Calculate the number of active AEs per QAT
245f4f56ff4SMark Johnston * needed for Shram partitioning.
246f4f56ff4SMark Johnston */
247f4f56ff4SMark Johnston for (i = 0; i < sc->sc_ae_num; i++) {
248f4f56ff4SMark Johnston if (qadr->qadr_srv_mask[i])
249f4f56ff4SMark Johnston qadr->qadr_active_aes_per_accel++;
250f4f56ff4SMark Johnston }
251f4f56ff4SMark Johnston
252f4f56ff4SMark Johnston return 0;
253f4f56ff4SMark Johnston }
254f4f56ff4SMark Johnston
255f4f56ff4SMark Johnston static void
qat_adm_ring_build_slice_mask(uint16_t * slice_mask,uint32_t srv_mask,uint32_t init_shram)256f4f56ff4SMark Johnston qat_adm_ring_build_slice_mask(uint16_t *slice_mask, uint32_t srv_mask,
257f4f56ff4SMark Johnston uint32_t init_shram)
258f4f56ff4SMark Johnston {
259f4f56ff4SMark Johnston uint16_t shram = 0, comn_req = 0;
260f4f56ff4SMark Johnston
261f4f56ff4SMark Johnston if (init_shram)
262f4f56ff4SMark Johnston shram = COMN_REQ_SHRAM_INIT_REQUIRED;
263f4f56ff4SMark Johnston
264f4f56ff4SMark Johnston if (srv_mask & QAT_SERVICE_CRYPTO_A)
265f4f56ff4SMark Johnston comn_req |= COMN_REQ_CY0_ONLY(shram);
266f4f56ff4SMark Johnston if (srv_mask & QAT_SERVICE_CRYPTO_B)
267f4f56ff4SMark Johnston comn_req |= COMN_REQ_CY1_ONLY(shram);
268f4f56ff4SMark Johnston
269f4f56ff4SMark Johnston *slice_mask = comn_req;
270f4f56ff4SMark Johnston }
271f4f56ff4SMark Johnston
272f4f56ff4SMark Johnston static void
qat_adm_ring_build_shram_mask(uint64_t * shram_mask,uint32_t active_aes,uint32_t ae)273f4f56ff4SMark Johnston qat_adm_ring_build_shram_mask(uint64_t *shram_mask, uint32_t active_aes,
274f4f56ff4SMark Johnston uint32_t ae)
275f4f56ff4SMark Johnston {
276f4f56ff4SMark Johnston *shram_mask = 0;
277f4f56ff4SMark Johnston
278f4f56ff4SMark Johnston if (active_aes == 1) {
279f4f56ff4SMark Johnston *shram_mask = ~(*shram_mask);
280f4f56ff4SMark Johnston } else if (active_aes == 2) {
281f4f56ff4SMark Johnston if (ae == 1)
282f4f56ff4SMark Johnston *shram_mask = ((~(*shram_mask)) & 0xffffffff);
283f4f56ff4SMark Johnston else
284f4f56ff4SMark Johnston *shram_mask = ((~(*shram_mask)) & 0xffffffff00000000ull);
285f4f56ff4SMark Johnston } else if (active_aes == 3) {
286f4f56ff4SMark Johnston if (ae == 0)
287f4f56ff4SMark Johnston *shram_mask = ((~(*shram_mask)) & 0x7fffff);
288f4f56ff4SMark Johnston else if (ae == 1)
289f4f56ff4SMark Johnston *shram_mask = ((~(*shram_mask)) & 0x3fffff800000ull);
290f4f56ff4SMark Johnston else
291f4f56ff4SMark Johnston *shram_mask = ((~(*shram_mask)) & 0xffffc00000000000ull);
292f4f56ff4SMark Johnston } else {
293f4f56ff4SMark Johnston panic("Only three services are supported in current version");
294f4f56ff4SMark Johnston }
295f4f56ff4SMark Johnston }
296f4f56ff4SMark Johnston
297f4f56ff4SMark Johnston static int
qat_adm_ring_build_ring_table(struct qat_softc * sc,uint32_t ae)298f4f56ff4SMark Johnston qat_adm_ring_build_ring_table(struct qat_softc *sc, uint32_t ae)
299f4f56ff4SMark Johnston {
300f4f56ff4SMark Johnston struct qat_admin_rings *qadr = &sc->sc_admin_rings;
301f4f56ff4SMark Johnston struct fw_init_ring_table *tbl;
302f4f56ff4SMark Johnston struct fw_init_ring_params *param;
303f4f56ff4SMark Johnston uint8_t srv_mask = sc->sc_admin_rings.qadr_srv_mask[ae];
304f4f56ff4SMark Johnston
305f4f56ff4SMark Johnston if ((srv_mask & QAT_SERVICE_CRYPTO_A)) {
306f4f56ff4SMark Johnston tbl = qadr->qadr_cya_ring_tbl;
307f4f56ff4SMark Johnston } else if ((srv_mask & QAT_SERVICE_CRYPTO_B)) {
308f4f56ff4SMark Johnston tbl = qadr->qadr_cyb_ring_tbl;
309f4f56ff4SMark Johnston } else {
310f4f56ff4SMark Johnston device_printf(sc->sc_dev,
311f4f56ff4SMark Johnston "Invalid execution engine %d\n", ae);
312f4f56ff4SMark Johnston return EINVAL;
313f4f56ff4SMark Johnston }
314f4f56ff4SMark Johnston
315f4f56ff4SMark Johnston param = &tbl->firt_bulk_rings[sc->sc_hw.qhw_ring_sym_tx];
316f4f56ff4SMark Johnston param->firp_curr_weight = QAT_HI_PRIO_RING_WEIGHT;
317f4f56ff4SMark Johnston param->firp_init_weight = QAT_HI_PRIO_RING_WEIGHT;
318f4f56ff4SMark Johnston FW_INIT_RING_MASK_SET(tbl, sc->sc_hw.qhw_ring_sym_tx);
319f4f56ff4SMark Johnston
320f4f56ff4SMark Johnston return 0;
321f4f56ff4SMark Johnston }
322f4f56ff4SMark Johnston
323f4f56ff4SMark Johnston static int
qat_adm_ring_build_init_msg(struct qat_softc * sc,struct fw_init_req * initmsg,enum fw_init_cmd_id cmd,uint32_t ae,struct qat_accel_init_cb * cb)324f4f56ff4SMark Johnston qat_adm_ring_build_init_msg(struct qat_softc *sc,
325f4f56ff4SMark Johnston struct fw_init_req *initmsg, enum fw_init_cmd_id cmd, uint32_t ae,
326f4f56ff4SMark Johnston struct qat_accel_init_cb *cb)
327f4f56ff4SMark Johnston {
328f4f56ff4SMark Johnston struct fw_init_set_ae_info_hdr *aehdr;
329f4f56ff4SMark Johnston struct fw_init_set_ae_info *aeinfo;
330f4f56ff4SMark Johnston struct fw_init_set_ring_info_hdr *ringhdr;
331f4f56ff4SMark Johnston struct fw_init_set_ring_info *ringinfo;
332f4f56ff4SMark Johnston int init_shram = 0, tgt_id, cluster_id;
333f4f56ff4SMark Johnston uint32_t srv_mask;
334f4f56ff4SMark Johnston
335f4f56ff4SMark Johnston srv_mask = sc->sc_admin_rings.qadr_srv_mask[
336f4f56ff4SMark Johnston ae % sc->sc_ae_num];
337f4f56ff4SMark Johnston
338f4f56ff4SMark Johnston memset(initmsg, 0, sizeof(struct fw_init_req));
339f4f56ff4SMark Johnston
340f4f56ff4SMark Johnston qat_msg_req_type_populate(&initmsg->comn_hdr.arch_if,
341f4f56ff4SMark Johnston ARCH_IF_REQ_QAT_FW_INIT,
342f4f56ff4SMark Johnston sc->sc_admin_rings.qadr_admin_rx->qr_ring_id);
343f4f56ff4SMark Johnston
344f4f56ff4SMark Johnston qat_msg_cmn_mid_populate(&initmsg->comn_mid, cb, 0, 0);
345f4f56ff4SMark Johnston
346f4f56ff4SMark Johnston switch (cmd) {
347f4f56ff4SMark Johnston case FW_INIT_CMD_SET_AE_INFO:
348f4f56ff4SMark Johnston if (ae % sc->sc_ae_num == 0)
349f4f56ff4SMark Johnston init_shram = 1;
350f4f56ff4SMark Johnston if (ae >= sc->sc_ae_num) {
351f4f56ff4SMark Johnston tgt_id = 1;
352f4f56ff4SMark Johnston cluster_id = 1;
353f4f56ff4SMark Johnston } else {
354f4f56ff4SMark Johnston cluster_id = 0;
355f4f56ff4SMark Johnston if (sc->sc_ae_mask)
356f4f56ff4SMark Johnston tgt_id = 0;
357f4f56ff4SMark Johnston else
358f4f56ff4SMark Johnston tgt_id = 1;
359f4f56ff4SMark Johnston }
360f4f56ff4SMark Johnston aehdr = &initmsg->u.set_ae_info;
361f4f56ff4SMark Johnston aeinfo = &initmsg->u1.set_ae_info;
362f4f56ff4SMark Johnston
363f4f56ff4SMark Johnston aehdr->init_cmd_id = cmd;
364f4f56ff4SMark Johnston /* XXX that does not support sparse ae_mask */
365f4f56ff4SMark Johnston aehdr->init_trgt_id = ae;
366f4f56ff4SMark Johnston aehdr->init_ring_cluster_id = cluster_id;
367f4f56ff4SMark Johnston aehdr->init_qat_id = tgt_id;
368f4f56ff4SMark Johnston
369f4f56ff4SMark Johnston qat_adm_ring_build_slice_mask(&aehdr->init_slice_mask, srv_mask,
370f4f56ff4SMark Johnston init_shram);
371f4f56ff4SMark Johnston
372f4f56ff4SMark Johnston qat_adm_ring_build_shram_mask(&aeinfo->init_shram_mask,
373f4f56ff4SMark Johnston sc->sc_admin_rings.qadr_active_aes_per_accel,
374f4f56ff4SMark Johnston ae % sc->sc_ae_num);
375f4f56ff4SMark Johnston
376f4f56ff4SMark Johnston break;
377f4f56ff4SMark Johnston case FW_INIT_CMD_SET_RING_INFO:
378f4f56ff4SMark Johnston ringhdr = &initmsg->u.set_ring_info;
379f4f56ff4SMark Johnston ringinfo = &initmsg->u1.set_ring_info;
380f4f56ff4SMark Johnston
381f4f56ff4SMark Johnston ringhdr->init_cmd_id = cmd;
382f4f56ff4SMark Johnston /* XXX that does not support sparse ae_mask */
383f4f56ff4SMark Johnston ringhdr->init_trgt_id = ae;
384f4f56ff4SMark Johnston
385f4f56ff4SMark Johnston /* XXX */
386f4f56ff4SMark Johnston qat_adm_ring_build_ring_table(sc,
387f4f56ff4SMark Johnston ae % sc->sc_ae_num);
388f4f56ff4SMark Johnston
389f4f56ff4SMark Johnston ringhdr->init_ring_tbl_sz = sizeof(struct fw_init_ring_table);
390f4f56ff4SMark Johnston
391f4f56ff4SMark Johnston ringinfo->init_ring_table_ptr =
392f4f56ff4SMark Johnston sc->sc_admin_rings.qadr_dma.qdm_dma_seg.ds_addr +
393f4f56ff4SMark Johnston ((ae % sc->sc_ae_num) *
394f4f56ff4SMark Johnston sizeof(struct fw_init_ring_table));
395f4f56ff4SMark Johnston
396f4f56ff4SMark Johnston break;
397f4f56ff4SMark Johnston default:
398f4f56ff4SMark Johnston return ENOTSUP;
399f4f56ff4SMark Johnston }
400f4f56ff4SMark Johnston
401f4f56ff4SMark Johnston return 0;
402f4f56ff4SMark Johnston }
403f4f56ff4SMark Johnston
404f4f56ff4SMark Johnston static int
qat_adm_ring_send_init_msg_sync(struct qat_softc * sc,enum fw_init_cmd_id cmd,uint32_t ae)405f4f56ff4SMark Johnston qat_adm_ring_send_init_msg_sync(struct qat_softc *sc,
406f4f56ff4SMark Johnston enum fw_init_cmd_id cmd, uint32_t ae)
407f4f56ff4SMark Johnston {
408f4f56ff4SMark Johnston struct fw_init_req initmsg;
409f4f56ff4SMark Johnston struct qat_accel_init_cb cb;
410f4f56ff4SMark Johnston int error;
411f4f56ff4SMark Johnston
412f4f56ff4SMark Johnston error = qat_adm_ring_build_init_msg(sc, &initmsg, cmd, ae, &cb);
413f4f56ff4SMark Johnston if (error)
414f4f56ff4SMark Johnston return error;
415f4f56ff4SMark Johnston
416f4f56ff4SMark Johnston error = qat_etr_put_msg(sc, sc->sc_admin_rings.qadr_admin_tx,
417f4f56ff4SMark Johnston (uint32_t *)&initmsg);
418f4f56ff4SMark Johnston if (error)
419f4f56ff4SMark Johnston return error;
420f4f56ff4SMark Johnston
421f4f56ff4SMark Johnston error = tsleep(&cb, PZERO, "qat_init", hz * 3 / 2);
422f4f56ff4SMark Johnston if (error) {
423f4f56ff4SMark Johnston device_printf(sc->sc_dev,
424f4f56ff4SMark Johnston "Timed out initialization firmware: %d\n", error);
425f4f56ff4SMark Johnston return error;
426f4f56ff4SMark Johnston }
427f4f56ff4SMark Johnston if (cb.qaic_status) {
428f4f56ff4SMark Johnston device_printf(sc->sc_dev, "Failed to initialize firmware\n");
429f4f56ff4SMark Johnston return EIO;
430f4f56ff4SMark Johnston }
431f4f56ff4SMark Johnston
432f4f56ff4SMark Johnston return error;
433f4f56ff4SMark Johnston }
434f4f56ff4SMark Johnston
435f4f56ff4SMark Johnston static int
qat_adm_ring_send_init_msg(struct qat_softc * sc,enum fw_init_cmd_id cmd)436f4f56ff4SMark Johnston qat_adm_ring_send_init_msg(struct qat_softc *sc,
437f4f56ff4SMark Johnston enum fw_init_cmd_id cmd)
438f4f56ff4SMark Johnston {
439f4f56ff4SMark Johnston struct qat_admin_rings *qadr = &sc->sc_admin_rings;
440f4f56ff4SMark Johnston uint32_t error, ae;
441f4f56ff4SMark Johnston
442f4f56ff4SMark Johnston for (ae = 0; ae < sc->sc_ae_num; ae++) {
443f4f56ff4SMark Johnston uint8_t srv_mask = qadr->qadr_srv_mask[ae];
444f4f56ff4SMark Johnston switch (cmd) {
445f4f56ff4SMark Johnston case FW_INIT_CMD_SET_AE_INFO:
446f4f56ff4SMark Johnston case FW_INIT_CMD_SET_RING_INFO:
447f4f56ff4SMark Johnston if (!srv_mask)
448f4f56ff4SMark Johnston continue;
449f4f56ff4SMark Johnston break;
450f4f56ff4SMark Johnston case FW_INIT_CMD_TRNG_ENABLE:
451f4f56ff4SMark Johnston case FW_INIT_CMD_TRNG_DISABLE:
452f4f56ff4SMark Johnston if (!(srv_mask & QAT_SERVICE_CRYPTO_A))
453f4f56ff4SMark Johnston continue;
454f4f56ff4SMark Johnston break;
455f4f56ff4SMark Johnston default:
456f4f56ff4SMark Johnston return ENOTSUP;
457f4f56ff4SMark Johnston }
458f4f56ff4SMark Johnston
459f4f56ff4SMark Johnston error = qat_adm_ring_send_init_msg_sync(sc, cmd, ae);
460f4f56ff4SMark Johnston if (error)
461f4f56ff4SMark Johnston return error;
462f4f56ff4SMark Johnston }
463f4f56ff4SMark Johnston
464f4f56ff4SMark Johnston return 0;
465f4f56ff4SMark Johnston }
466f4f56ff4SMark Johnston
467f4f56ff4SMark Johnston int
qat_adm_ring_send_init(struct qat_softc * sc)468f4f56ff4SMark Johnston qat_adm_ring_send_init(struct qat_softc *sc)
469f4f56ff4SMark Johnston {
470f4f56ff4SMark Johnston int error;
471f4f56ff4SMark Johnston
472f4f56ff4SMark Johnston error = qat_adm_ring_send_init_msg(sc, FW_INIT_CMD_SET_AE_INFO);
473f4f56ff4SMark Johnston if (error)
474f4f56ff4SMark Johnston return error;
475f4f56ff4SMark Johnston
476f4f56ff4SMark Johnston error = qat_adm_ring_send_init_msg(sc, FW_INIT_CMD_SET_RING_INFO);
477f4f56ff4SMark Johnston if (error)
478f4f56ff4SMark Johnston return error;
479f4f56ff4SMark Johnston
480f4f56ff4SMark Johnston return 0;
481f4f56ff4SMark Johnston }
482f4f56ff4SMark Johnston
483f4f56ff4SMark Johnston static int
qat_adm_ring_intr(struct qat_softc * sc,void * arg,void * msg)484f4f56ff4SMark Johnston qat_adm_ring_intr(struct qat_softc *sc, void *arg, void *msg)
485f4f56ff4SMark Johnston {
486f4f56ff4SMark Johnston struct arch_if_resp_hdr *resp;
487f4f56ff4SMark Johnston struct fw_init_resp *init_resp;
488f4f56ff4SMark Johnston struct qat_accel_init_cb *init_cb;
489f4f56ff4SMark Johnston int handled = 0;
490f4f56ff4SMark Johnston
491f4f56ff4SMark Johnston resp = (struct arch_if_resp_hdr *)msg;
492f4f56ff4SMark Johnston
493f4f56ff4SMark Johnston switch (resp->resp_type) {
494f4f56ff4SMark Johnston case ARCH_IF_REQ_QAT_FW_INIT:
495f4f56ff4SMark Johnston init_resp = (struct fw_init_resp *)msg;
496f4f56ff4SMark Johnston init_cb = (struct qat_accel_init_cb *)
497f4f56ff4SMark Johnston (uintptr_t)init_resp->comn_resp.opaque_data;
498f4f56ff4SMark Johnston init_cb->qaic_status =
499f4f56ff4SMark Johnston __SHIFTOUT(init_resp->comn_resp.comn_status,
500f4f56ff4SMark Johnston COMN_RESP_INIT_ADMIN_STATUS);
501f4f56ff4SMark Johnston wakeup(init_cb);
502f4f56ff4SMark Johnston break;
503f4f56ff4SMark Johnston default:
504f4f56ff4SMark Johnston device_printf(sc->sc_dev,
505f4f56ff4SMark Johnston "unknown resp type %d\n", resp->resp_type);
506f4f56ff4SMark Johnston break;
507f4f56ff4SMark Johnston }
508f4f56ff4SMark Johnston
509f4f56ff4SMark Johnston return handled;
510f4f56ff4SMark Johnston }
511f4f56ff4SMark Johnston
512f4f56ff4SMark Johnston static inline uint16_t
qat_hw15_get_comn_req_flags(uint8_t ae)513f4f56ff4SMark Johnston qat_hw15_get_comn_req_flags(uint8_t ae)
514f4f56ff4SMark Johnston {
515f4f56ff4SMark Johnston if (ae == 0) {
516f4f56ff4SMark Johnston return COMN_REQ_ORD_STRICT | COMN_REQ_PTR_TYPE_SGL |
517f4f56ff4SMark Johnston COMN_REQ_AUTH0_SLICE_REQUIRED |
518f4f56ff4SMark Johnston COMN_REQ_CIPHER0_SLICE_REQUIRED;
519f4f56ff4SMark Johnston } else {
520f4f56ff4SMark Johnston return COMN_REQ_ORD_STRICT | COMN_REQ_PTR_TYPE_SGL |
521f4f56ff4SMark Johnston COMN_REQ_AUTH1_SLICE_REQUIRED |
522f4f56ff4SMark Johnston COMN_REQ_CIPHER1_SLICE_REQUIRED;
523f4f56ff4SMark Johnston }
524f4f56ff4SMark Johnston }
525f4f56ff4SMark Johnston
526f4f56ff4SMark Johnston static uint32_t
qat_hw15_crypto_setup_cipher_desc(struct qat_crypto_desc * desc,struct qat_session * qs,struct fw_cipher_hdr * cipher_hdr,uint32_t hw_blk_offset,enum fw_slice next_slice)527f4f56ff4SMark Johnston qat_hw15_crypto_setup_cipher_desc(struct qat_crypto_desc *desc,
528f4f56ff4SMark Johnston struct qat_session *qs, struct fw_cipher_hdr *cipher_hdr,
529f4f56ff4SMark Johnston uint32_t hw_blk_offset, enum fw_slice next_slice)
530f4f56ff4SMark Johnston {
531f4f56ff4SMark Johnston desc->qcd_cipher_blk_sz = HW_AES_BLK_SZ;
532f4f56ff4SMark Johnston
533f4f56ff4SMark Johnston cipher_hdr->state_padding_sz = 0;
534f4f56ff4SMark Johnston cipher_hdr->key_sz = qs->qs_cipher_klen / 8;
535f4f56ff4SMark Johnston
536f4f56ff4SMark Johnston cipher_hdr->state_sz = desc->qcd_cipher_blk_sz / 8;
537f4f56ff4SMark Johnston
538f4f56ff4SMark Johnston cipher_hdr->next_id = next_slice;
539f4f56ff4SMark Johnston cipher_hdr->curr_id = FW_SLICE_CIPHER;
540f4f56ff4SMark Johnston cipher_hdr->offset = hw_blk_offset / 8;
541f4f56ff4SMark Johnston cipher_hdr->resrvd = 0;
542f4f56ff4SMark Johnston
543f4f56ff4SMark Johnston return sizeof(struct hw_cipher_config) + qs->qs_cipher_klen;
544f4f56ff4SMark Johnston }
545f4f56ff4SMark Johnston
546f4f56ff4SMark Johnston static void
qat_hw15_crypto_setup_cipher_config(const struct qat_crypto_desc * desc,const struct qat_session * qs,const struct cryptop * crp,struct hw_cipher_config * cipher_config)547f4f56ff4SMark Johnston qat_hw15_crypto_setup_cipher_config(const struct qat_crypto_desc *desc,
548f4f56ff4SMark Johnston const struct qat_session *qs, const struct cryptop *crp,
549f4f56ff4SMark Johnston struct hw_cipher_config *cipher_config)
550f4f56ff4SMark Johnston {
551f4f56ff4SMark Johnston const uint8_t *key;
552f4f56ff4SMark Johnston uint8_t *cipher_key;
553f4f56ff4SMark Johnston
554f4f56ff4SMark Johnston cipher_config->val = qat_crypto_load_cipher_session(desc, qs);
555f4f56ff4SMark Johnston cipher_config->reserved = 0;
556f4f56ff4SMark Johnston
557f4f56ff4SMark Johnston cipher_key = (uint8_t *)(cipher_config + 1);
558f4f56ff4SMark Johnston if (crp != NULL && crp->crp_cipher_key != NULL)
559f4f56ff4SMark Johnston key = crp->crp_cipher_key;
560f4f56ff4SMark Johnston else
561f4f56ff4SMark Johnston key = qs->qs_cipher_key;
562f4f56ff4SMark Johnston memcpy(cipher_key, key, qs->qs_cipher_klen);
563f4f56ff4SMark Johnston }
564f4f56ff4SMark Johnston
565f4f56ff4SMark Johnston static uint32_t
qat_hw15_crypto_setup_auth_desc(struct qat_crypto_desc * desc,struct qat_session * qs,struct fw_auth_hdr * auth_hdr,uint32_t ctrl_blk_offset,uint32_t hw_blk_offset,enum fw_slice next_slice)566f4f56ff4SMark Johnston qat_hw15_crypto_setup_auth_desc(struct qat_crypto_desc *desc,
567f4f56ff4SMark Johnston struct qat_session *qs, struct fw_auth_hdr *auth_hdr,
568f4f56ff4SMark Johnston uint32_t ctrl_blk_offset, uint32_t hw_blk_offset,
569f4f56ff4SMark Johnston enum fw_slice next_slice)
570f4f56ff4SMark Johnston {
571f4f56ff4SMark Johnston const struct qat_sym_hash_def *hash_def;
572f4f56ff4SMark Johnston
573f4f56ff4SMark Johnston (void)qat_crypto_load_auth_session(desc, qs, &hash_def);
574f4f56ff4SMark Johnston
575f4f56ff4SMark Johnston auth_hdr->next_id = next_slice;
576f4f56ff4SMark Johnston auth_hdr->curr_id = FW_SLICE_AUTH;
577f4f56ff4SMark Johnston auth_hdr->offset = hw_blk_offset / 8;
578f4f56ff4SMark Johnston auth_hdr->resrvd = 0;
579f4f56ff4SMark Johnston
580f4f56ff4SMark Johnston auth_hdr->hash_flags = FW_AUTH_HDR_FLAG_NO_NESTED;
581f4f56ff4SMark Johnston auth_hdr->u.inner_prefix_sz = 0;
582f4f56ff4SMark Johnston auth_hdr->outer_prefix_sz = 0;
583f4f56ff4SMark Johnston auth_hdr->final_sz = hash_def->qshd_alg->qshai_digest_len;
584f4f56ff4SMark Johnston auth_hdr->inner_state1_sz =
585f4f56ff4SMark Johnston roundup(hash_def->qshd_qat->qshqi_state1_len, 8);
586f4f56ff4SMark Johnston auth_hdr->inner_res_sz = hash_def->qshd_alg->qshai_digest_len;
587f4f56ff4SMark Johnston auth_hdr->inner_state2_sz =
588f4f56ff4SMark Johnston roundup(hash_def->qshd_qat->qshqi_state2_len, 8);
589f4f56ff4SMark Johnston auth_hdr->inner_state2_off = auth_hdr->offset +
590f4f56ff4SMark Johnston ((sizeof(struct hw_auth_setup) + auth_hdr->inner_state1_sz) / 8);
591f4f56ff4SMark Johnston
592f4f56ff4SMark Johnston auth_hdr->outer_config_off = 0;
593f4f56ff4SMark Johnston auth_hdr->outer_state1_sz = 0;
594f4f56ff4SMark Johnston auth_hdr->outer_res_sz = 0;
595f4f56ff4SMark Johnston auth_hdr->outer_prefix_off = 0;
596f4f56ff4SMark Johnston
597f4f56ff4SMark Johnston desc->qcd_auth_sz = hash_def->qshd_alg->qshai_sah->hashsize;
598f4f56ff4SMark Johnston desc->qcd_state_storage_sz = (sizeof(struct hw_auth_counter) +
599f4f56ff4SMark Johnston roundup(hash_def->qshd_alg->qshai_state_size, 8)) / 8;
600f4f56ff4SMark Johnston desc->qcd_gcm_aad_sz_offset1 = desc->qcd_auth_offset +
601f4f56ff4SMark Johnston sizeof(struct hw_auth_setup) + auth_hdr->inner_state1_sz +
602f4f56ff4SMark Johnston AES_BLOCK_LEN;
603f4f56ff4SMark Johnston desc->qcd_gcm_aad_sz_offset2 = ctrl_blk_offset +
604f4f56ff4SMark Johnston offsetof(struct fw_auth_hdr, u.aad_sz);
605f4f56ff4SMark Johnston
606f4f56ff4SMark Johnston return sizeof(struct hw_auth_setup) + auth_hdr->inner_state1_sz +
607f4f56ff4SMark Johnston auth_hdr->inner_state2_sz;
608f4f56ff4SMark Johnston }
609f4f56ff4SMark Johnston
610f4f56ff4SMark Johnston static void
qat_hw15_crypto_setup_auth_setup(const struct qat_crypto_desc * desc,const struct qat_session * qs,const struct cryptop * crp,struct hw_auth_setup * auth_setup)611f4f56ff4SMark Johnston qat_hw15_crypto_setup_auth_setup(const struct qat_crypto_desc *desc,
612f4f56ff4SMark Johnston const struct qat_session *qs, const struct cryptop *crp,
613f4f56ff4SMark Johnston struct hw_auth_setup *auth_setup)
614f4f56ff4SMark Johnston {
615f4f56ff4SMark Johnston const struct qat_sym_hash_def *hash_def;
616f4f56ff4SMark Johnston const uint8_t *key;
617f4f56ff4SMark Johnston uint8_t *state1, *state2;
618f4f56ff4SMark Johnston uint32_t state_sz, state1_sz, state2_sz, state1_pad_len, state2_pad_len;
619f4f56ff4SMark Johnston
620f4f56ff4SMark Johnston auth_setup->auth_config.config = qat_crypto_load_auth_session(desc, qs,
621f4f56ff4SMark Johnston &hash_def);
622f4f56ff4SMark Johnston auth_setup->auth_config.reserved = 0;
623f4f56ff4SMark Johnston
624f4f56ff4SMark Johnston auth_setup->auth_counter.counter =
625f4f56ff4SMark Johnston htobe32(hash_def->qshd_qat->qshqi_auth_counter);
626f4f56ff4SMark Johnston auth_setup->auth_counter.reserved = 0;
627f4f56ff4SMark Johnston
628f4f56ff4SMark Johnston state1 = (uint8_t *)(auth_setup + 1);
629f4f56ff4SMark Johnston state2 = state1 + roundup(hash_def->qshd_qat->qshqi_state1_len, 8);
630f4f56ff4SMark Johnston switch (qs->qs_auth_algo) {
631f4f56ff4SMark Johnston case HW_AUTH_ALGO_GALOIS_128:
632f4f56ff4SMark Johnston qat_crypto_gmac_precompute(desc, qs->qs_cipher_key,
633f4f56ff4SMark Johnston qs->qs_cipher_klen, hash_def, state2);
634f4f56ff4SMark Johnston break;
635f4f56ff4SMark Johnston case HW_AUTH_ALGO_SHA1:
636f4f56ff4SMark Johnston state_sz = hash_def->qshd_alg->qshai_state_size;
637f4f56ff4SMark Johnston state1_sz = roundup(hash_def->qshd_qat->qshqi_state1_len, 8);
638f4f56ff4SMark Johnston state2_sz = roundup(hash_def->qshd_qat->qshqi_state2_len, 8);
639f4f56ff4SMark Johnston if (qs->qs_auth_mode == HW_AUTH_MODE1) {
640f4f56ff4SMark Johnston state1_pad_len = state1_sz - state_sz;
641f4f56ff4SMark Johnston state2_pad_len = state2_sz - state_sz;
642f4f56ff4SMark Johnston if (state1_pad_len > 0)
643f4f56ff4SMark Johnston memset(state1 + state_sz, 0, state1_pad_len);
644f4f56ff4SMark Johnston if (state2_pad_len > 0)
645f4f56ff4SMark Johnston memset(state2 + state_sz, 0, state2_pad_len);
646f4f56ff4SMark Johnston }
647f4f56ff4SMark Johnston /* FALLTHROUGH */
648f4f56ff4SMark Johnston case HW_AUTH_ALGO_SHA256:
649f4f56ff4SMark Johnston case HW_AUTH_ALGO_SHA384:
650f4f56ff4SMark Johnston case HW_AUTH_ALGO_SHA512:
651f4f56ff4SMark Johnston switch (qs->qs_auth_mode) {
652f4f56ff4SMark Johnston case HW_AUTH_MODE0:
653f4f56ff4SMark Johnston memcpy(state1, hash_def->qshd_alg->qshai_init_state,
654f4f56ff4SMark Johnston state1_sz);
655f4f56ff4SMark Johnston /* Override for mode 0 hashes. */
656f4f56ff4SMark Johnston auth_setup->auth_counter.counter = 0;
657f4f56ff4SMark Johnston break;
658f4f56ff4SMark Johnston case HW_AUTH_MODE1:
659f4f56ff4SMark Johnston if (crp != NULL && crp->crp_auth_key != NULL)
660f4f56ff4SMark Johnston key = crp->crp_auth_key;
661f4f56ff4SMark Johnston else
662f4f56ff4SMark Johnston key = qs->qs_auth_key;
663f4f56ff4SMark Johnston if (key != NULL) {
664f4f56ff4SMark Johnston qat_crypto_hmac_precompute(desc, key,
665f4f56ff4SMark Johnston qs->qs_auth_klen, hash_def, state1, state2);
666f4f56ff4SMark Johnston }
667f4f56ff4SMark Johnston break;
668f4f56ff4SMark Johnston default:
669f4f56ff4SMark Johnston panic("%s: unhandled auth mode %d", __func__,
670f4f56ff4SMark Johnston qs->qs_auth_mode);
671f4f56ff4SMark Johnston }
672f4f56ff4SMark Johnston break;
673f4f56ff4SMark Johnston default:
674f4f56ff4SMark Johnston panic("%s: unhandled auth algorithm %d", __func__,
675f4f56ff4SMark Johnston qs->qs_auth_algo);
676f4f56ff4SMark Johnston }
677f4f56ff4SMark Johnston }
678f4f56ff4SMark Johnston
679f4f56ff4SMark Johnston void
qat_hw15_crypto_setup_desc(struct qat_crypto * qcy,struct qat_session * qs,struct qat_crypto_desc * desc)680f4f56ff4SMark Johnston qat_hw15_crypto_setup_desc(struct qat_crypto *qcy, struct qat_session *qs,
681f4f56ff4SMark Johnston struct qat_crypto_desc *desc)
682f4f56ff4SMark Johnston {
683f4f56ff4SMark Johnston struct fw_cipher_hdr *cipher_hdr;
684f4f56ff4SMark Johnston struct fw_auth_hdr *auth_hdr;
685f4f56ff4SMark Johnston struct fw_la_bulk_req *req_cache;
686f4f56ff4SMark Johnston struct hw_auth_setup *auth_setup;
687f4f56ff4SMark Johnston struct hw_cipher_config *cipher_config;
688f4f56ff4SMark Johnston uint32_t ctrl_blk_sz, ctrl_blk_offset, hw_blk_offset;
689f4f56ff4SMark Johnston int i;
690f4f56ff4SMark Johnston uint16_t la_cmd_flags;
691f4f56ff4SMark Johnston uint8_t req_params_sz;
692f4f56ff4SMark Johnston uint8_t *ctrl_blk_ptr, *hw_blk_ptr;
693f4f56ff4SMark Johnston
694f4f56ff4SMark Johnston ctrl_blk_sz = 0;
695f4f56ff4SMark Johnston if (qs->qs_cipher_algo != HW_CIPHER_ALGO_NULL)
696f4f56ff4SMark Johnston ctrl_blk_sz += sizeof(struct fw_cipher_hdr);
697f4f56ff4SMark Johnston if (qs->qs_auth_algo != HW_AUTH_ALGO_NULL)
698f4f56ff4SMark Johnston ctrl_blk_sz += sizeof(struct fw_auth_hdr);
699f4f56ff4SMark Johnston
700f4f56ff4SMark Johnston ctrl_blk_ptr = desc->qcd_content_desc;
701f4f56ff4SMark Johnston ctrl_blk_offset = 0;
702f4f56ff4SMark Johnston hw_blk_ptr = ctrl_blk_ptr + ctrl_blk_sz;
703f4f56ff4SMark Johnston hw_blk_offset = 0;
704f4f56ff4SMark Johnston
705f4f56ff4SMark Johnston la_cmd_flags = 0;
706f4f56ff4SMark Johnston req_params_sz = 0;
707f4f56ff4SMark Johnston for (i = 0; i < MAX_FW_SLICE; i++) {
708f4f56ff4SMark Johnston switch (desc->qcd_slices[i]) {
709f4f56ff4SMark Johnston case FW_SLICE_CIPHER:
710f4f56ff4SMark Johnston cipher_hdr = (struct fw_cipher_hdr *)(ctrl_blk_ptr +
711f4f56ff4SMark Johnston ctrl_blk_offset);
712f4f56ff4SMark Johnston cipher_config = (struct hw_cipher_config *)(hw_blk_ptr +
713f4f56ff4SMark Johnston hw_blk_offset);
714f4f56ff4SMark Johnston desc->qcd_cipher_offset = ctrl_blk_sz + hw_blk_offset;
715f4f56ff4SMark Johnston hw_blk_offset += qat_hw15_crypto_setup_cipher_desc(desc,
716f4f56ff4SMark Johnston qs, cipher_hdr, hw_blk_offset,
717f4f56ff4SMark Johnston desc->qcd_slices[i + 1]);
718f4f56ff4SMark Johnston qat_hw15_crypto_setup_cipher_config(desc, qs, NULL,
719f4f56ff4SMark Johnston cipher_config);
720f4f56ff4SMark Johnston ctrl_blk_offset += sizeof(struct fw_cipher_hdr);
721f4f56ff4SMark Johnston req_params_sz += sizeof(struct fw_la_cipher_req_params);
722f4f56ff4SMark Johnston break;
723f4f56ff4SMark Johnston case FW_SLICE_AUTH:
724f4f56ff4SMark Johnston auth_hdr = (struct fw_auth_hdr *)(ctrl_blk_ptr +
725f4f56ff4SMark Johnston ctrl_blk_offset);
726f4f56ff4SMark Johnston auth_setup = (struct hw_auth_setup *)(hw_blk_ptr +
727f4f56ff4SMark Johnston hw_blk_offset);
728f4f56ff4SMark Johnston desc->qcd_auth_offset = ctrl_blk_sz + hw_blk_offset;
729f4f56ff4SMark Johnston hw_blk_offset += qat_hw15_crypto_setup_auth_desc(desc,
730f4f56ff4SMark Johnston qs, auth_hdr, ctrl_blk_offset, hw_blk_offset,
731f4f56ff4SMark Johnston desc->qcd_slices[i + 1]);
732f4f56ff4SMark Johnston qat_hw15_crypto_setup_auth_setup(desc, qs, NULL,
733f4f56ff4SMark Johnston auth_setup);
734f4f56ff4SMark Johnston ctrl_blk_offset += sizeof(struct fw_auth_hdr);
735f4f56ff4SMark Johnston req_params_sz += sizeof(struct fw_la_auth_req_params);
736f4f56ff4SMark Johnston la_cmd_flags |= LA_FLAGS_RET_AUTH_RES;
737f4f56ff4SMark Johnston /* no digest verify */
738f4f56ff4SMark Johnston break;
739f4f56ff4SMark Johnston case FW_SLICE_DRAM_WR:
740f4f56ff4SMark Johnston i = MAX_FW_SLICE; /* end of chain */
741f4f56ff4SMark Johnston break;
742f4f56ff4SMark Johnston default:
743f4f56ff4SMark Johnston MPASS(0);
744f4f56ff4SMark Johnston break;
745f4f56ff4SMark Johnston }
746f4f56ff4SMark Johnston }
747f4f56ff4SMark Johnston
748f4f56ff4SMark Johnston desc->qcd_hdr_sz = ctrl_blk_offset / 8;
749f4f56ff4SMark Johnston desc->qcd_hw_blk_sz = hw_blk_offset / 8;
750f4f56ff4SMark Johnston
751f4f56ff4SMark Johnston req_cache = (struct fw_la_bulk_req *)desc->qcd_req_cache;
752f4f56ff4SMark Johnston qat_msg_req_type_populate(
753f4f56ff4SMark Johnston &req_cache->comn_hdr.arch_if,
754f4f56ff4SMark Johnston ARCH_IF_REQ_QAT_FW_LA, 0);
755f4f56ff4SMark Johnston
756f4f56ff4SMark Johnston if (qs->qs_auth_algo == HW_AUTH_ALGO_GALOIS_128)
757f4f56ff4SMark Johnston la_cmd_flags |= LA_FLAGS_PROTO_GCM | LA_FLAGS_GCM_IV_LEN_FLAG;
758f4f56ff4SMark Johnston else
759f4f56ff4SMark Johnston la_cmd_flags |= LA_FLAGS_PROTO_NO;
760f4f56ff4SMark Johnston
761f4f56ff4SMark Johnston qat_msg_params_populate(req_cache, desc, req_params_sz,
762f4f56ff4SMark Johnston la_cmd_flags, 0);
763f4f56ff4SMark Johnston
764f4f56ff4SMark Johnston bus_dmamap_sync(qs->qs_desc_mem.qdm_dma_tag,
765f4f56ff4SMark Johnston qs->qs_desc_mem.qdm_dma_map, BUS_DMASYNC_PREWRITE);
766f4f56ff4SMark Johnston }
767f4f56ff4SMark Johnston
768f4f56ff4SMark Johnston static void
qat_hw15_crypto_req_setkey(const struct qat_crypto_desc * desc,const struct qat_session * qs,struct qat_sym_cookie * qsc,struct fw_la_bulk_req * bulk_req,struct cryptop * crp)769f4f56ff4SMark Johnston qat_hw15_crypto_req_setkey(const struct qat_crypto_desc *desc,
770f4f56ff4SMark Johnston const struct qat_session *qs, struct qat_sym_cookie *qsc,
771f4f56ff4SMark Johnston struct fw_la_bulk_req *bulk_req, struct cryptop *crp)
772f4f56ff4SMark Johnston {
773f4f56ff4SMark Johnston struct hw_auth_setup *auth_setup;
774f4f56ff4SMark Johnston struct hw_cipher_config *cipher_config;
775f4f56ff4SMark Johnston uint8_t *cdesc;
776f4f56ff4SMark Johnston int i;
777f4f56ff4SMark Johnston
778f4f56ff4SMark Johnston cdesc = qsc->qsc_content_desc;
779f4f56ff4SMark Johnston memcpy(cdesc, desc->qcd_content_desc, CONTENT_DESC_MAX_SIZE);
780f4f56ff4SMark Johnston for (i = 0; i < MAX_FW_SLICE; i++) {
781f4f56ff4SMark Johnston switch (desc->qcd_slices[i]) {
782f4f56ff4SMark Johnston case FW_SLICE_CIPHER:
783f4f56ff4SMark Johnston cipher_config = (struct hw_cipher_config *)
784f4f56ff4SMark Johnston (cdesc + desc->qcd_cipher_offset);
785f4f56ff4SMark Johnston qat_hw15_crypto_setup_cipher_config(desc, qs, crp,
786f4f56ff4SMark Johnston cipher_config);
787f4f56ff4SMark Johnston break;
788f4f56ff4SMark Johnston case FW_SLICE_AUTH:
789f4f56ff4SMark Johnston auth_setup = (struct hw_auth_setup *)
790f4f56ff4SMark Johnston (cdesc + desc->qcd_auth_offset);
791f4f56ff4SMark Johnston qat_hw15_crypto_setup_auth_setup(desc, qs, crp,
792f4f56ff4SMark Johnston auth_setup);
793f4f56ff4SMark Johnston break;
794f4f56ff4SMark Johnston case FW_SLICE_DRAM_WR:
795f4f56ff4SMark Johnston i = MAX_FW_SLICE; /* end of chain */
796f4f56ff4SMark Johnston break;
797f4f56ff4SMark Johnston default:
798f4f56ff4SMark Johnston MPASS(0);
799f4f56ff4SMark Johnston }
800f4f56ff4SMark Johnston }
801f4f56ff4SMark Johnston
802f4f56ff4SMark Johnston bulk_req->comn_hdr.content_desc_addr = qsc->qsc_content_desc_paddr;
803f4f56ff4SMark Johnston }
804f4f56ff4SMark Johnston
805f4f56ff4SMark Johnston void
qat_hw15_crypto_setup_req_params(struct qat_crypto_bank * qcb,struct qat_session * qs,struct qat_crypto_desc const * desc,struct qat_sym_cookie * qsc,struct cryptop * crp)806f4f56ff4SMark Johnston qat_hw15_crypto_setup_req_params(struct qat_crypto_bank *qcb,
807f4f56ff4SMark Johnston struct qat_session *qs, struct qat_crypto_desc const *desc,
808f4f56ff4SMark Johnston struct qat_sym_cookie *qsc, struct cryptop *crp)
809f4f56ff4SMark Johnston {
810f4f56ff4SMark Johnston struct qat_sym_bulk_cookie *qsbc;
811f4f56ff4SMark Johnston struct fw_la_bulk_req *bulk_req;
812f4f56ff4SMark Johnston struct fw_la_cipher_req_params *cipher_req;
813f4f56ff4SMark Johnston struct fw_la_auth_req_params *auth_req;
814f4f56ff4SMark Johnston bus_addr_t digest_paddr;
815f4f56ff4SMark Johnston uint8_t *aad_szp2, *req_params_ptr;
816f4f56ff4SMark Johnston uint32_t aad_sz, *aad_szp1;
817f4f56ff4SMark Johnston enum fw_la_cmd_id cmd_id = desc->qcd_cmd_id;
818f4f56ff4SMark Johnston enum fw_slice next_slice;
819f4f56ff4SMark Johnston
820f4f56ff4SMark Johnston qsbc = &qsc->qsc_bulk_cookie;
821f4f56ff4SMark Johnston
822f4f56ff4SMark Johnston bulk_req = (struct fw_la_bulk_req *)qsbc->qsbc_msg;
823f4f56ff4SMark Johnston memcpy(bulk_req, &desc->qcd_req_cache, QAT_HW15_SESSION_REQ_CACHE_SIZE);
824f4f56ff4SMark Johnston bulk_req->comn_hdr.arch_if.resp_pipe_id = qcb->qcb_sym_rx->qr_ring_id;
825f4f56ff4SMark Johnston bulk_req->comn_hdr.comn_req_flags =
826f4f56ff4SMark Johnston qat_hw15_get_comn_req_flags(qcb->qcb_bank % 2);
827f4f56ff4SMark Johnston bulk_req->comn_mid.src_data_addr = qsc->qsc_buffer_list_desc_paddr;
828f4f56ff4SMark Johnston if (CRYPTO_HAS_OUTPUT_BUFFER(crp)) {
829f4f56ff4SMark Johnston bulk_req->comn_mid.dest_data_addr =
830f4f56ff4SMark Johnston qsc->qsc_obuffer_list_desc_paddr;
831f4f56ff4SMark Johnston } else {
832f4f56ff4SMark Johnston bulk_req->comn_mid.dest_data_addr =
833f4f56ff4SMark Johnston qsc->qsc_buffer_list_desc_paddr;
834f4f56ff4SMark Johnston }
835f4f56ff4SMark Johnston bulk_req->req_params_addr = qsc->qsc_bulk_req_params_buf_paddr;
836f4f56ff4SMark Johnston bulk_req->comn_ftr.next_request_addr = 0;
837f4f56ff4SMark Johnston bulk_req->comn_mid.opaque_data = (uint64_t)(uintptr_t)qsc;
838f4f56ff4SMark Johnston if (__predict_false(crp->crp_cipher_key != NULL ||
839f4f56ff4SMark Johnston crp->crp_auth_key != NULL)) {
840f4f56ff4SMark Johnston qat_hw15_crypto_req_setkey(desc, qs, qsc, bulk_req, crp);
841f4f56ff4SMark Johnston }
842f4f56ff4SMark Johnston
843f4f56ff4SMark Johnston digest_paddr = 0;
844f4f56ff4SMark Johnston if (desc->qcd_auth_sz != 0)
845f4f56ff4SMark Johnston digest_paddr = qsc->qsc_auth_res_paddr;
846f4f56ff4SMark Johnston
847f4f56ff4SMark Johnston req_params_ptr = qsbc->qsbc_req_params_buf;
848f4f56ff4SMark Johnston memset(req_params_ptr, 0, sizeof(qsbc->qsbc_req_params_buf));
849f4f56ff4SMark Johnston
850f4f56ff4SMark Johnston /*
851f4f56ff4SMark Johnston * The SG list layout is a bit different for GCM and GMAC, it's simpler
852f4f56ff4SMark Johnston * to handle those cases separately.
853f4f56ff4SMark Johnston */
854f4f56ff4SMark Johnston if (qs->qs_auth_algo == HW_AUTH_ALGO_GALOIS_128) {
855f4f56ff4SMark Johnston cipher_req = (struct fw_la_cipher_req_params *)req_params_ptr;
856f4f56ff4SMark Johnston auth_req = (struct fw_la_auth_req_params *)
857f4f56ff4SMark Johnston (req_params_ptr + sizeof(struct fw_la_cipher_req_params));
858f4f56ff4SMark Johnston
859f4f56ff4SMark Johnston cipher_req->cipher_state_sz = desc->qcd_cipher_blk_sz / 8;
860f4f56ff4SMark Johnston cipher_req->curr_id = FW_SLICE_CIPHER;
861f4f56ff4SMark Johnston if (cmd_id == FW_LA_CMD_HASH_CIPHER || cmd_id == FW_LA_CMD_AUTH)
862f4f56ff4SMark Johnston cipher_req->next_id = FW_SLICE_DRAM_WR;
863f4f56ff4SMark Johnston else
864f4f56ff4SMark Johnston cipher_req->next_id = FW_SLICE_AUTH;
865f4f56ff4SMark Johnston cipher_req->state_address = qsc->qsc_iv_buf_paddr;
866f4f56ff4SMark Johnston
867f4f56ff4SMark Johnston if (cmd_id != FW_LA_CMD_AUTH) {
868f4f56ff4SMark Johnston /*
869f4f56ff4SMark Johnston * Don't fill out the cipher block if we're doing GMAC
870f4f56ff4SMark Johnston * only.
871f4f56ff4SMark Johnston */
872f4f56ff4SMark Johnston cipher_req->cipher_off = 0;
873f4f56ff4SMark Johnston cipher_req->cipher_len = crp->crp_payload_length;
874f4f56ff4SMark Johnston }
875f4f56ff4SMark Johnston auth_req->curr_id = FW_SLICE_AUTH;
876f4f56ff4SMark Johnston if (cmd_id == FW_LA_CMD_HASH_CIPHER || cmd_id == FW_LA_CMD_AUTH)
877f4f56ff4SMark Johnston auth_req->next_id = FW_SLICE_CIPHER;
878f4f56ff4SMark Johnston else
879f4f56ff4SMark Johnston auth_req->next_id = FW_SLICE_DRAM_WR;
880f4f56ff4SMark Johnston
881f4f56ff4SMark Johnston auth_req->auth_res_address = digest_paddr;
882f4f56ff4SMark Johnston auth_req->auth_res_sz = desc->qcd_auth_sz;
883f4f56ff4SMark Johnston
884f4f56ff4SMark Johnston auth_req->auth_off = 0;
885f4f56ff4SMark Johnston auth_req->auth_len = crp->crp_payload_length;
886f4f56ff4SMark Johnston
887f4f56ff4SMark Johnston auth_req->hash_state_sz =
888f4f56ff4SMark Johnston roundup2(crp->crp_aad_length, QAT_AES_GCM_AAD_ALIGN) >> 3;
889f4f56ff4SMark Johnston auth_req->u1.aad_addr = crp->crp_aad_length > 0 ?
890f4f56ff4SMark Johnston qsc->qsc_gcm_aad_paddr : 0;
891f4f56ff4SMark Johnston
892f4f56ff4SMark Johnston /*
893f4f56ff4SMark Johnston * Update the hash state block if necessary. This only occurs
894f4f56ff4SMark Johnston * when the AAD length changes between requests in a session and
895f4f56ff4SMark Johnston * is synchronized by qat_process().
896f4f56ff4SMark Johnston */
897f4f56ff4SMark Johnston aad_sz = htobe32(crp->crp_aad_length);
898f4f56ff4SMark Johnston aad_szp1 = (uint32_t *)(
899f4f56ff4SMark Johnston __DECONST(uint8_t *, desc->qcd_content_desc) +
900f4f56ff4SMark Johnston desc->qcd_gcm_aad_sz_offset1);
901f4f56ff4SMark Johnston aad_szp2 = __DECONST(uint8_t *, desc->qcd_content_desc) +
902f4f56ff4SMark Johnston desc->qcd_gcm_aad_sz_offset2;
903f4f56ff4SMark Johnston if (__predict_false(*aad_szp1 != aad_sz)) {
904f4f56ff4SMark Johnston *aad_szp1 = aad_sz;
905f4f56ff4SMark Johnston *aad_szp2 = (uint8_t)roundup2(crp->crp_aad_length,
906f4f56ff4SMark Johnston QAT_AES_GCM_AAD_ALIGN);
907f4f56ff4SMark Johnston bus_dmamap_sync(qs->qs_desc_mem.qdm_dma_tag,
908f4f56ff4SMark Johnston qs->qs_desc_mem.qdm_dma_map,
909f4f56ff4SMark Johnston BUS_DMASYNC_PREWRITE);
910f4f56ff4SMark Johnston }
911f4f56ff4SMark Johnston } else {
912f4f56ff4SMark Johnston cipher_req = (struct fw_la_cipher_req_params *)req_params_ptr;
913f4f56ff4SMark Johnston if (cmd_id != FW_LA_CMD_AUTH) {
914f4f56ff4SMark Johnston if (cmd_id == FW_LA_CMD_CIPHER ||
915f4f56ff4SMark Johnston cmd_id == FW_LA_CMD_HASH_CIPHER)
916f4f56ff4SMark Johnston next_slice = FW_SLICE_DRAM_WR;
917f4f56ff4SMark Johnston else
918f4f56ff4SMark Johnston next_slice = FW_SLICE_AUTH;
919f4f56ff4SMark Johnston
920f4f56ff4SMark Johnston cipher_req->cipher_state_sz =
921f4f56ff4SMark Johnston desc->qcd_cipher_blk_sz / 8;
922f4f56ff4SMark Johnston
923f4f56ff4SMark Johnston cipher_req->curr_id = FW_SLICE_CIPHER;
924f4f56ff4SMark Johnston cipher_req->next_id = next_slice;
925f4f56ff4SMark Johnston
926f4f56ff4SMark Johnston if (crp->crp_aad_length == 0) {
927f4f56ff4SMark Johnston cipher_req->cipher_off = 0;
928f4f56ff4SMark Johnston } else if (crp->crp_aad == NULL) {
929f4f56ff4SMark Johnston cipher_req->cipher_off =
930f4f56ff4SMark Johnston crp->crp_payload_start - crp->crp_aad_start;
931f4f56ff4SMark Johnston } else {
932f4f56ff4SMark Johnston cipher_req->cipher_off = crp->crp_aad_length;
933f4f56ff4SMark Johnston }
934f4f56ff4SMark Johnston cipher_req->cipher_len = crp->crp_payload_length;
935f4f56ff4SMark Johnston cipher_req->state_address = qsc->qsc_iv_buf_paddr;
936f4f56ff4SMark Johnston }
937f4f56ff4SMark Johnston if (cmd_id != FW_LA_CMD_CIPHER) {
938f4f56ff4SMark Johnston if (cmd_id == FW_LA_CMD_AUTH)
939f4f56ff4SMark Johnston auth_req = (struct fw_la_auth_req_params *)
940f4f56ff4SMark Johnston req_params_ptr;
941f4f56ff4SMark Johnston else
942f4f56ff4SMark Johnston auth_req = (struct fw_la_auth_req_params *)
943f4f56ff4SMark Johnston (cipher_req + 1);
944f4f56ff4SMark Johnston if (cmd_id == FW_LA_CMD_HASH_CIPHER)
945f4f56ff4SMark Johnston next_slice = FW_SLICE_CIPHER;
946f4f56ff4SMark Johnston else
947f4f56ff4SMark Johnston next_slice = FW_SLICE_DRAM_WR;
948f4f56ff4SMark Johnston
949f4f56ff4SMark Johnston auth_req->curr_id = FW_SLICE_AUTH;
950f4f56ff4SMark Johnston auth_req->next_id = next_slice;
951f4f56ff4SMark Johnston
952f4f56ff4SMark Johnston auth_req->auth_res_address = digest_paddr;
953f4f56ff4SMark Johnston auth_req->auth_res_sz = desc->qcd_auth_sz;
954f4f56ff4SMark Johnston
955f4f56ff4SMark Johnston auth_req->auth_len =
956f4f56ff4SMark Johnston crp->crp_payload_length + crp->crp_aad_length;
957f4f56ff4SMark Johnston auth_req->auth_off = 0;
958f4f56ff4SMark Johnston
959f4f56ff4SMark Johnston auth_req->hash_state_sz = 0;
960f4f56ff4SMark Johnston auth_req->u1.prefix_addr = desc->qcd_hash_state_paddr +
961f4f56ff4SMark Johnston desc->qcd_state_storage_sz;
962f4f56ff4SMark Johnston }
963f4f56ff4SMark Johnston }
964f4f56ff4SMark Johnston }
965