1*b61a5730SWarner Losh /* SPDX-License-Identifier: BSD-2-Clause AND BSD-3-Clause */
2f4f56ff4SMark Johnston /* $NetBSD: qat_c2xxx.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_c2xxx.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/systm.h>
68f4f56ff4SMark Johnston
69f4f56ff4SMark Johnston #include <machine/bus.h>
70f4f56ff4SMark Johnston
71f4f56ff4SMark Johnston #include <dev/pci/pcireg.h>
72f4f56ff4SMark Johnston #include <dev/pci/pcivar.h>
73f4f56ff4SMark Johnston
74f4f56ff4SMark Johnston #include "qatreg.h"
75f4f56ff4SMark Johnston #include "qat_hw15reg.h"
76f4f56ff4SMark Johnston #include "qat_c2xxxreg.h"
77f4f56ff4SMark Johnston #include "qatvar.h"
78f4f56ff4SMark Johnston #include "qat_hw15var.h"
79f4f56ff4SMark Johnston
80f4f56ff4SMark Johnston static uint32_t
qat_c2xxx_get_accel_mask(struct qat_softc * sc)81f4f56ff4SMark Johnston qat_c2xxx_get_accel_mask(struct qat_softc *sc)
82f4f56ff4SMark Johnston {
83f4f56ff4SMark Johnston uint32_t fusectl;
84f4f56ff4SMark Johnston
85f4f56ff4SMark Johnston fusectl = pci_read_config(sc->sc_dev, FUSECTL_REG, 4);
86f4f56ff4SMark Johnston
87f4f56ff4SMark Johnston return ((~fusectl) & ACCEL_MASK_C2XXX);
88f4f56ff4SMark Johnston }
89f4f56ff4SMark Johnston
90f4f56ff4SMark Johnston static uint32_t
qat_c2xxx_get_ae_mask(struct qat_softc * sc)91f4f56ff4SMark Johnston qat_c2xxx_get_ae_mask(struct qat_softc *sc)
92f4f56ff4SMark Johnston {
93f4f56ff4SMark Johnston uint32_t fusectl;
94f4f56ff4SMark Johnston
95f4f56ff4SMark Johnston fusectl = pci_read_config(sc->sc_dev, FUSECTL_REG, 4);
96f4f56ff4SMark Johnston if (fusectl & (
97f4f56ff4SMark Johnston FUSECTL_C2XXX_PKE_DISABLE |
98f4f56ff4SMark Johnston FUSECTL_C2XXX_ATH_DISABLE |
99f4f56ff4SMark Johnston FUSECTL_C2XXX_CPH_DISABLE)) {
100f4f56ff4SMark Johnston return 0;
101f4f56ff4SMark Johnston } else {
102f4f56ff4SMark Johnston if ((~fusectl & AE_MASK_C2XXX) == 0x3) {
103f4f56ff4SMark Johnston /*
104f4f56ff4SMark Johnston * With both AEs enabled we get spurious completions on
105f4f56ff4SMark Johnston * ETR rings. Work around that for now by simply
106f4f56ff4SMark Johnston * disabling the second AE.
107f4f56ff4SMark Johnston */
108f4f56ff4SMark Johnston device_printf(sc->sc_dev, "disabling second AE\n");
109f4f56ff4SMark Johnston fusectl |= 0x2;
110f4f56ff4SMark Johnston }
111f4f56ff4SMark Johnston return ((~fusectl) & AE_MASK_C2XXX);
112f4f56ff4SMark Johnston }
113f4f56ff4SMark Johnston }
114f4f56ff4SMark Johnston
115f4f56ff4SMark Johnston static enum qat_sku
qat_c2xxx_get_sku(struct qat_softc * sc)116f4f56ff4SMark Johnston qat_c2xxx_get_sku(struct qat_softc *sc)
117f4f56ff4SMark Johnston {
118f4f56ff4SMark Johnston uint32_t fusectl;
119f4f56ff4SMark Johnston
120f4f56ff4SMark Johnston fusectl = pci_read_config(sc->sc_dev, FUSECTL_REG, 4);
121f4f56ff4SMark Johnston
122f4f56ff4SMark Johnston switch (sc->sc_ae_num) {
123f4f56ff4SMark Johnston case 1:
124f4f56ff4SMark Johnston if (fusectl & FUSECTL_C2XXX_LOW_SKU)
125f4f56ff4SMark Johnston return QAT_SKU_3;
126f4f56ff4SMark Johnston else if (fusectl & FUSECTL_C2XXX_MID_SKU)
127f4f56ff4SMark Johnston return QAT_SKU_2;
128f4f56ff4SMark Johnston break;
129f4f56ff4SMark Johnston case MAX_AE_C2XXX:
130f4f56ff4SMark Johnston return QAT_SKU_1;
131f4f56ff4SMark Johnston }
132f4f56ff4SMark Johnston
133f4f56ff4SMark Johnston return QAT_SKU_UNKNOWN;
134f4f56ff4SMark Johnston }
135f4f56ff4SMark Johnston
136f4f56ff4SMark Johnston static uint32_t
qat_c2xxx_get_accel_cap(struct qat_softc * sc)137f4f56ff4SMark Johnston qat_c2xxx_get_accel_cap(struct qat_softc *sc)
138f4f56ff4SMark Johnston {
139f4f56ff4SMark Johnston return QAT_ACCEL_CAP_CRYPTO_SYMMETRIC |
140f4f56ff4SMark Johnston QAT_ACCEL_CAP_CRYPTO_ASYMMETRIC |
141f4f56ff4SMark Johnston QAT_ACCEL_CAP_CIPHER |
142f4f56ff4SMark Johnston QAT_ACCEL_CAP_AUTHENTICATION;
143f4f56ff4SMark Johnston }
144f4f56ff4SMark Johnston
145f4f56ff4SMark Johnston static const char *
qat_c2xxx_get_fw_uof_name(struct qat_softc * sc)146f4f56ff4SMark Johnston qat_c2xxx_get_fw_uof_name(struct qat_softc *sc)
147f4f56ff4SMark Johnston {
148f4f56ff4SMark Johnston if (sc->sc_rev < QAT_REVID_C2XXX_B0)
149f4f56ff4SMark Johnston return AE_FW_UOF_NAME_C2XXX_A0;
150f4f56ff4SMark Johnston
151f4f56ff4SMark Johnston /* QAT_REVID_C2XXX_B0 and QAT_REVID_C2XXX_C0 */
152f4f56ff4SMark Johnston return AE_FW_UOF_NAME_C2XXX_B0;
153f4f56ff4SMark Johnston }
154f4f56ff4SMark Johnston
155f4f56ff4SMark Johnston static void
qat_c2xxx_enable_intr(struct qat_softc * sc)156f4f56ff4SMark Johnston qat_c2xxx_enable_intr(struct qat_softc *sc)
157f4f56ff4SMark Johnston {
158f4f56ff4SMark Johnston
159f4f56ff4SMark Johnston qat_misc_write_4(sc, EP_SMIA_C2XXX, EP_SMIA_MASK_C2XXX);
160f4f56ff4SMark Johnston }
161f4f56ff4SMark Johnston
162f4f56ff4SMark Johnston static void
qat_c2xxx_init_etr_intr(struct qat_softc * sc,int bank)163f4f56ff4SMark Johnston qat_c2xxx_init_etr_intr(struct qat_softc *sc, int bank)
164f4f56ff4SMark Johnston {
165f4f56ff4SMark Johnston /*
166f4f56ff4SMark Johnston * For now, all rings within the bank are setup such that the generation
167f4f56ff4SMark Johnston * of flag interrupts will be triggered when ring leaves the empty
168f4f56ff4SMark Johnston * state. Note that in order for the ring interrupt to generate an IRQ
169f4f56ff4SMark Johnston * the interrupt must also be enabled for the ring.
170f4f56ff4SMark Johnston */
171f4f56ff4SMark Johnston qat_etr_bank_write_4(sc, bank, ETR_INT_SRCSEL,
172f4f56ff4SMark Johnston ETR_INT_SRCSEL_MASK_0_C2XXX);
173f4f56ff4SMark Johnston qat_etr_bank_write_4(sc, bank, ETR_INT_SRCSEL_2,
174f4f56ff4SMark Johnston ETR_INT_SRCSEL_MASK_X_C2XXX);
175f4f56ff4SMark Johnston }
176f4f56ff4SMark Johnston
177f4f56ff4SMark Johnston const struct qat_hw qat_hw_c2xxx = {
178f4f56ff4SMark Johnston .qhw_sram_bar_id = BAR_SRAM_ID_C2XXX,
179f4f56ff4SMark Johnston .qhw_misc_bar_id = BAR_PMISC_ID_C2XXX,
180f4f56ff4SMark Johnston .qhw_etr_bar_id = BAR_ETR_ID_C2XXX,
181f4f56ff4SMark Johnston .qhw_cap_global_offset = CAP_GLOBAL_OFFSET_C2XXX,
182f4f56ff4SMark Johnston .qhw_ae_offset = AE_OFFSET_C2XXX,
183f4f56ff4SMark Johnston .qhw_ae_local_offset = AE_LOCAL_OFFSET_C2XXX,
184f4f56ff4SMark Johnston .qhw_etr_bundle_size = ETR_BUNDLE_SIZE_C2XXX,
185f4f56ff4SMark Johnston .qhw_num_banks = ETR_MAX_BANKS_C2XXX,
186f4f56ff4SMark Johnston .qhw_num_ap_banks = ETR_MAX_AP_BANKS_C2XXX,
187f4f56ff4SMark Johnston .qhw_num_rings_per_bank = ETR_MAX_RINGS_PER_BANK,
188f4f56ff4SMark Johnston .qhw_num_accel = MAX_ACCEL_C2XXX,
189f4f56ff4SMark Johnston .qhw_num_engines = MAX_AE_C2XXX,
190f4f56ff4SMark Johnston .qhw_tx_rx_gap = ETR_TX_RX_GAP_C2XXX,
191f4f56ff4SMark Johnston .qhw_tx_rings_mask = ETR_TX_RINGS_MASK_C2XXX,
192f4f56ff4SMark Johnston .qhw_msix_ae_vec_gap = MSIX_AE_VEC_GAP_C2XXX,
193f4f56ff4SMark Johnston .qhw_fw_auth = false,
194f4f56ff4SMark Johnston .qhw_fw_req_size = FW_REQ_DEFAULT_SZ_HW15,
195f4f56ff4SMark Johnston .qhw_fw_resp_size = FW_REQ_DEFAULT_SZ_HW15,
196f4f56ff4SMark Johnston .qhw_ring_asym_tx = 2,
197f4f56ff4SMark Johnston .qhw_ring_asym_rx = 3,
198f4f56ff4SMark Johnston .qhw_ring_sym_tx = 4,
199f4f56ff4SMark Johnston .qhw_ring_sym_rx = 5,
200f4f56ff4SMark Johnston .qhw_mof_fwname = AE_FW_MOF_NAME_C2XXX,
201f4f56ff4SMark Johnston .qhw_mmp_fwname = AE_FW_MMP_NAME_C2XXX,
202f4f56ff4SMark Johnston .qhw_prod_type = AE_FW_PROD_TYPE_C2XXX,
203f4f56ff4SMark Johnston .qhw_get_accel_mask = qat_c2xxx_get_accel_mask,
204f4f56ff4SMark Johnston .qhw_get_ae_mask = qat_c2xxx_get_ae_mask,
205f4f56ff4SMark Johnston .qhw_get_sku = qat_c2xxx_get_sku,
206f4f56ff4SMark Johnston .qhw_get_accel_cap = qat_c2xxx_get_accel_cap,
207f4f56ff4SMark Johnston .qhw_get_fw_uof_name = qat_c2xxx_get_fw_uof_name,
208f4f56ff4SMark Johnston .qhw_enable_intr = qat_c2xxx_enable_intr,
209f4f56ff4SMark Johnston .qhw_init_etr_intr = qat_c2xxx_init_etr_intr,
210f4f56ff4SMark Johnston .qhw_init_admin_comms = qat_adm_ring_init,
211f4f56ff4SMark Johnston .qhw_send_admin_init = qat_adm_ring_send_init,
212f4f56ff4SMark Johnston .qhw_crypto_setup_desc = qat_hw15_crypto_setup_desc,
213f4f56ff4SMark Johnston .qhw_crypto_setup_req_params = qat_hw15_crypto_setup_req_params,
214f4f56ff4SMark Johnston .qhw_crypto_opaque_offset =
215f4f56ff4SMark Johnston offsetof(struct fw_la_resp, comn_resp.opaque_data),
216f4f56ff4SMark Johnston };
217