aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTadeusz Struk <tadeusz.struk@intel.com>2015-12-04 19:56:40 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2015-12-09 07:03:53 -0500
commita6dabee6c8ba770bab7a3ec63b6a5c1059331d5c (patch)
treecf2fa5c109dd31a63763aa0100101fa32140c4ec
parent890c55f4dc0e60a4ba71ab9b6877f69ff7053213 (diff)
crypto: qat - add support for c62x accel type
Add support for qat c62x accel type Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/qat/Kconfig11
-rw-r--r--drivers/crypto/qat/Makefile1
-rw-r--r--drivers/crypto/qat/qat_c62x/Makefile3
-rw-r--r--drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.c248
-rw-r--r--drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.h84
-rw-r--r--drivers/crypto/qat/qat_c62x/adf_drv.c335
-rw-r--r--drivers/crypto/qat/qat_common/adf_cfg_common.h1
7 files changed, 683 insertions, 0 deletions
diff --git a/drivers/crypto/qat/Kconfig b/drivers/crypto/qat/Kconfig
index 7b3e791ae2d6..33ae4828d92f 100644
--- a/drivers/crypto/qat/Kconfig
+++ b/drivers/crypto/qat/Kconfig
@@ -33,6 +33,17 @@ config CRYPTO_DEV_QAT_C3XXX
33 To compile this as a module, choose M here: the module 33 To compile this as a module, choose M here: the module
34 will be called qat_c3xxx. 34 will be called qat_c3xxx.
35 35
36config CRYPTO_DEV_QAT_C62X
37 tristate "Support for Intel(R) C62X"
38 depends on X86 && PCI
39 select CRYPTO_DEV_QAT
40 help
41 Support for Intel(R) C62x with Intel(R) QuickAssist Technology
42 for accelerating crypto and compression workloads.
43
44 To compile this as a module, choose M here: the module
45 will be called qat_c62x.
46
36config CRYPTO_DEV_QAT_DH895xCCVF 47config CRYPTO_DEV_QAT_DH895xCCVF
37 tristate "Support for Intel(R) DH895xCC Virtual Function" 48 tristate "Support for Intel(R) DH895xCC Virtual Function"
38 depends on X86 && PCI 49 depends on X86 && PCI
diff --git a/drivers/crypto/qat/Makefile b/drivers/crypto/qat/Makefile
index e08d66031bcc..6bc41941fb88 100644
--- a/drivers/crypto/qat/Makefile
+++ b/drivers/crypto/qat/Makefile
@@ -1,4 +1,5 @@
1obj-$(CONFIG_CRYPTO_DEV_QAT) += qat_common/ 1obj-$(CONFIG_CRYPTO_DEV_QAT) += qat_common/
2obj-$(CONFIG_CRYPTO_DEV_QAT_DH895xCC) += qat_dh895xcc/ 2obj-$(CONFIG_CRYPTO_DEV_QAT_DH895xCC) += qat_dh895xcc/
3obj-$(CONFIG_CRYPTO_DEV_QAT_C3XXX) += qat_c3xxx/ 3obj-$(CONFIG_CRYPTO_DEV_QAT_C3XXX) += qat_c3xxx/
4obj-$(CONFIG_CRYPTO_DEV_QAT_C62X) += qat_c62x/
4obj-$(CONFIG_CRYPTO_DEV_QAT_DH895xCCVF) += qat_dh895xccvf/ 5obj-$(CONFIG_CRYPTO_DEV_QAT_DH895xCCVF) += qat_dh895xccvf/
diff --git a/drivers/crypto/qat/qat_c62x/Makefile b/drivers/crypto/qat/qat_c62x/Makefile
new file mode 100644
index 000000000000..bd75ace59b76
--- /dev/null
+++ b/drivers/crypto/qat/qat_c62x/Makefile
@@ -0,0 +1,3 @@
1ccflags-y := -I$(src)/../qat_common
2obj-$(CONFIG_CRYPTO_DEV_QAT_C62X) += qat_c62x.o
3qat_c62x-objs := adf_drv.o adf_c62x_hw_data.o
diff --git a/drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.c b/drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.c
new file mode 100644
index 000000000000..879e04cae714
--- /dev/null
+++ b/drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.c
@@ -0,0 +1,248 @@
1/*
2 This file is provided under a dual BSD/GPLv2 license. When using or
3 redistributing this file, you may do so under either license.
4
5 GPL LICENSE SUMMARY
6 Copyright(c) 2014 Intel Corporation.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of version 2 of the GNU General Public License as
9 published by the Free Software Foundation.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 Contact Information:
17 qat-linux@intel.com
18
19 BSD LICENSE
20 Copyright(c) 2014 Intel Corporation.
21 Redistribution and use in source and binary forms, with or without
22 modification, are permitted provided that the following conditions
23 are met:
24
25 * Redistributions of source code must retain the above copyright
26 notice, this list of conditions and the following disclaimer.
27 * Redistributions in binary form must reproduce the above copyright
28 notice, this list of conditions and the following disclaimer in
29 the documentation and/or other materials provided with the
30 distribution.
31 * Neither the name of Intel Corporation nor the names of its
32 contributors may be used to endorse or promote products derived
33 from this software without specific prior written permission.
34
35 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46*/
47#include <adf_accel_devices.h>
48#include <adf_common_drv.h>
49#include <adf_pf2vf_msg.h>
50#include "adf_c62x_hw_data.h"
51
52/* Worker thread to service arbiter mappings based on dev SKUs */
53static const u32 thrd_to_arb_map_8_me_sku[] = {
54 0x12222AAA, 0x11222AAA, 0x12222AAA, 0x11222AAA, 0x12222AAA,
55 0x11222AAA, 0x12222AAA, 0x11222AAA, 0, 0
56};
57
58static const u32 thrd_to_arb_map_10_me_sku[] = {
59 0x12222AAA, 0x11222AAA, 0x12222AAA, 0x11222AAA, 0x12222AAA,
60 0x11222AAA, 0x12222AAA, 0x11222AAA, 0x12222AAA, 0x11222AAA
61};
62
63static struct adf_hw_device_class c62x_class = {
64 .name = ADF_C62X_DEVICE_NAME,
65 .type = DEV_C62X,
66 .instances = 0
67};
68
69static u32 get_accel_mask(u32 fuse)
70{
71 return (~fuse) >> ADF_C62X_ACCELERATORS_REG_OFFSET &
72 ADF_C62X_ACCELERATORS_MASK;
73}
74
75static u32 get_ae_mask(u32 fuse)
76{
77 return (~fuse) & ADF_C62X_ACCELENGINES_MASK;
78}
79
80static u32 get_num_accels(struct adf_hw_device_data *self)
81{
82 u32 i, ctr = 0;
83
84 if (!self || !self->accel_mask)
85 return 0;
86
87 for (i = 0; i < ADF_C62X_MAX_ACCELERATORS; i++) {
88 if (self->accel_mask & (1 << i))
89 ctr++;
90 }
91 return ctr;
92}
93
94static u32 get_num_aes(struct adf_hw_device_data *self)
95{
96 u32 i, ctr = 0;
97
98 if (!self || !self->ae_mask)
99 return 0;
100
101 for (i = 0; i < ADF_C62X_MAX_ACCELENGINES; i++) {
102 if (self->ae_mask & (1 << i))
103 ctr++;
104 }
105 return ctr;
106}
107
108static u32 get_misc_bar_id(struct adf_hw_device_data *self)
109{
110 return ADF_C62X_PMISC_BAR;
111}
112
113static u32 get_etr_bar_id(struct adf_hw_device_data *self)
114{
115 return ADF_C62X_ETR_BAR;
116}
117
118static u32 get_sram_bar_id(struct adf_hw_device_data *self)
119{
120 return ADF_C62X_SRAM_BAR;
121}
122
123static enum dev_sku_info get_sku(struct adf_hw_device_data *self)
124{
125 int aes = get_num_aes(self);
126
127 if (aes == 8)
128 return DEV_SKU_2;
129 else if (aes == 10)
130 return DEV_SKU_4;
131
132 return DEV_SKU_UNKNOWN;
133}
134
135static void adf_get_arbiter_mapping(struct adf_accel_dev *accel_dev,
136 u32 const **arb_map_config)
137{
138 switch (accel_dev->accel_pci_dev.sku) {
139 case DEV_SKU_2:
140 *arb_map_config = thrd_to_arb_map_8_me_sku;
141 break;
142 case DEV_SKU_4:
143 *arb_map_config = thrd_to_arb_map_10_me_sku;
144 break;
145 default:
146 dev_err(&GET_DEV(accel_dev),
147 "The configuration doesn't match any SKU");
148 *arb_map_config = NULL;
149 }
150}
151
152static u32 get_pf2vf_offset(u32 i)
153{
154 return ADF_C62X_PF2VF_OFFSET(i);
155}
156
157static u32 get_vintmsk_offset(u32 i)
158{
159 return ADF_C62X_VINTMSK_OFFSET(i);
160}
161
162static void adf_enable_error_correction(struct adf_accel_dev *accel_dev)
163{
164 struct adf_hw_device_data *hw_device = accel_dev->hw_device;
165 struct adf_bar *misc_bar = &GET_BARS(accel_dev)[ADF_C62X_PMISC_BAR];
166 void __iomem *csr = misc_bar->virt_addr;
167 unsigned int val, i;
168
169 /* Enable Accel Engine error detection & correction */
170 for (i = 0; i < hw_device->get_num_aes(hw_device); i++) {
171 val = ADF_CSR_RD(csr, ADF_C62X_AE_CTX_ENABLES(i));
172 val |= ADF_C62X_ENABLE_AE_ECC_ERR;
173 ADF_CSR_WR(csr, ADF_C62X_AE_CTX_ENABLES(i), val);
174 val = ADF_CSR_RD(csr, ADF_C62X_AE_MISC_CONTROL(i));
175 val |= ADF_C62X_ENABLE_AE_ECC_PARITY_CORR;
176 ADF_CSR_WR(csr, ADF_C62X_AE_MISC_CONTROL(i), val);
177 }
178
179 /* Enable shared memory error detection & correction */
180 for (i = 0; i < hw_device->get_num_accels(hw_device); i++) {
181 val = ADF_CSR_RD(csr, ADF_C62X_UERRSSMSH(i));
182 val |= ADF_C62X_ERRSSMSH_EN;
183 ADF_CSR_WR(csr, ADF_C62X_UERRSSMSH(i), val);
184 val = ADF_CSR_RD(csr, ADF_C62X_CERRSSMSH(i));
185 val |= ADF_C62X_ERRSSMSH_EN;
186 ADF_CSR_WR(csr, ADF_C62X_CERRSSMSH(i), val);
187 }
188}
189
190static void adf_enable_ints(struct adf_accel_dev *accel_dev)
191{
192 void __iomem *addr;
193
194 addr = (&GET_BARS(accel_dev)[ADF_C62X_PMISC_BAR])->virt_addr;
195
196 /* Enable bundle and misc interrupts */
197 ADF_CSR_WR(addr, ADF_C62X_SMIAPF0_MASK_OFFSET,
198 ADF_C62X_SMIA0_MASK);
199 ADF_CSR_WR(addr, ADF_C62X_SMIAPF1_MASK_OFFSET,
200 ADF_C62X_SMIA1_MASK);
201}
202
203static int adf_pf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev)
204{
205 return 0;
206}
207
208void adf_init_hw_data_c62x(struct adf_hw_device_data *hw_data)
209{
210 hw_data->dev_class = &c62x_class;
211 hw_data->instance_id = c62x_class.instances++;
212 hw_data->num_banks = ADF_C62X_ETR_MAX_BANKS;
213 hw_data->num_accel = ADF_C62X_MAX_ACCELERATORS;
214 hw_data->num_logical_accel = 1;
215 hw_data->num_engines = ADF_C62X_MAX_ACCELENGINES;
216 hw_data->tx_rx_gap = ADF_C62X_RX_RINGS_OFFSET;
217 hw_data->tx_rings_mask = ADF_C62X_TX_RINGS_MASK;
218 hw_data->alloc_irq = adf_isr_resource_alloc;
219 hw_data->free_irq = adf_isr_resource_free;
220 hw_data->enable_error_correction = adf_enable_error_correction;
221 hw_data->get_accel_mask = get_accel_mask;
222 hw_data->get_ae_mask = get_ae_mask;
223 hw_data->get_num_accels = get_num_accels;
224 hw_data->get_num_aes = get_num_aes;
225 hw_data->get_sram_bar_id = get_sram_bar_id;
226 hw_data->get_etr_bar_id = get_etr_bar_id;
227 hw_data->get_misc_bar_id = get_misc_bar_id;
228 hw_data->get_pf2vf_offset = get_pf2vf_offset;
229 hw_data->get_vintmsk_offset = get_vintmsk_offset;
230 hw_data->get_sku = get_sku;
231 hw_data->fw_name = ADF_C62X_FW;
232 hw_data->fw_mmp_name = ADF_C62X_MMP;
233 hw_data->init_admin_comms = adf_init_admin_comms;
234 hw_data->exit_admin_comms = adf_exit_admin_comms;
235 hw_data->disable_iov = adf_disable_sriov;
236 hw_data->send_admin_init = adf_send_admin_init;
237 hw_data->init_arb = adf_init_arb;
238 hw_data->exit_arb = adf_exit_arb;
239 hw_data->get_arb_mapping = adf_get_arbiter_mapping;
240 hw_data->enable_ints = adf_enable_ints;
241 hw_data->enable_vf2pf_comms = adf_pf_enable_vf2pf_comms;
242 hw_data->min_iov_compat_ver = ADF_PFVF_COMPATIBILITY_VERSION;
243}
244
245void adf_clean_hw_data_c62x(struct adf_hw_device_data *hw_data)
246{
247 hw_data->dev_class->instances--;
248}
diff --git a/drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.h b/drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.h
new file mode 100644
index 000000000000..17a8a32d5c63
--- /dev/null
+++ b/drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.h
@@ -0,0 +1,84 @@
1/*
2 This file is provided under a dual BSD/GPLv2 license. When using or
3 redistributing this file, you may do so under either license.
4
5 GPL LICENSE SUMMARY
6 Copyright(c) 2014 Intel Corporation.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of version 2 of the GNU General Public License as
9 published by the Free Software Foundation.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 Contact Information:
17 qat-linux@intel.com
18
19 BSD LICENSE
20 Copyright(c) 2014 Intel Corporation.
21 Redistribution and use in source and binary forms, with or without
22 modification, are permitted provided that the following conditions
23 are met:
24
25 * Redistributions of source code must retain the above copyright
26 notice, this list of conditions and the following disclaimer.
27 * Redistributions in binary form must reproduce the above copyright
28 notice, this list of conditions and the following disclaimer in
29 the documentation and/or other materials provided with the
30 distribution.
31 * Neither the name of Intel Corporation nor the names of its
32 contributors may be used to endorse or promote products derived
33 from this software without specific prior written permission.
34
35 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46*/
47#ifndef ADF_C62X_HW_DATA_H_
48#define ADF_C62X_HW_DATA_H_
49
50/* PCIe configuration space */
51#define ADF_C62X_SRAM_BAR 0
52#define ADF_C62X_PMISC_BAR 1
53#define ADF_C62X_ETR_BAR 2
54#define ADF_C62X_RX_RINGS_OFFSET 8
55#define ADF_C62X_TX_RINGS_MASK 0xFF
56#define ADF_C62X_MAX_ACCELERATORS 5
57#define ADF_C62X_MAX_ACCELENGINES 10
58#define ADF_C62X_ACCELERATORS_REG_OFFSET 16
59#define ADF_C62X_ACCELERATORS_MASK 0x1F
60#define ADF_C62X_ACCELENGINES_MASK 0x3FF
61#define ADF_C62X_ETR_MAX_BANKS 16
62#define ADF_C62X_SMIAPF0_MASK_OFFSET (0x3A000 + 0x28)
63#define ADF_C62X_SMIAPF1_MASK_OFFSET (0x3A000 + 0x30)
64#define ADF_C62X_SMIA0_MASK 0xFFFF
65#define ADF_C62X_SMIA1_MASK 0x1
66/* Error detection and correction */
67#define ADF_C62X_AE_CTX_ENABLES(i) (i * 0x1000 + 0x20818)
68#define ADF_C62X_AE_MISC_CONTROL(i) (i * 0x1000 + 0x20960)
69#define ADF_C62X_ENABLE_AE_ECC_ERR BIT(28)
70#define ADF_C62X_ENABLE_AE_ECC_PARITY_CORR (BIT(24) | BIT(12))
71#define ADF_C62X_UERRSSMSH(i) (i * 0x4000 + 0x18)
72#define ADF_C62X_CERRSSMSH(i) (i * 0x4000 + 0x10)
73#define ADF_C62X_ERRSSMSH_EN BIT(3)
74
75#define ADF_C62X_PF2VF_OFFSET(i) (0x3A000 + 0x280 + ((i) * 0x04))
76#define ADF_C62X_VINTMSK_OFFSET(i) (0x3A000 + 0x200 + ((i) * 0x04))
77
78/* Firmware Binary */
79#define ADF_C62X_FW "qat_c62x.bin"
80#define ADF_C62X_MMP "qat_c62x_mmp.bin"
81
82void adf_init_hw_data_c62x(struct adf_hw_device_data *hw_data);
83void adf_clean_hw_data_c62x(struct adf_hw_device_data *hw_data);
84#endif
diff --git a/drivers/crypto/qat/qat_c62x/adf_drv.c b/drivers/crypto/qat/qat_c62x/adf_drv.c
new file mode 100644
index 000000000000..512c56509718
--- /dev/null
+++ b/drivers/crypto/qat/qat_c62x/adf_drv.c
@@ -0,0 +1,335 @@
1/*
2 This file is provided under a dual BSD/GPLv2 license. When using or
3 redistributing this file, you may do so under either license.
4
5 GPL LICENSE SUMMARY
6 Copyright(c) 2014 Intel Corporation.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of version 2 of the GNU General Public License as
9 published by the Free Software Foundation.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 Contact Information:
17 qat-linux@intel.com
18
19 BSD LICENSE
20 Copyright(c) 2014 Intel Corporation.
21 Redistribution and use in source and binary forms, with or without
22 modification, are permitted provided that the following conditions
23 are met:
24
25 * Redistributions of source code must retain the above copyright
26 notice, this list of conditions and the following disclaimer.
27 * Redistributions in binary form must reproduce the above copyright
28 notice, this list of conditions and the following disclaimer in
29 the documentation and/or other materials provided with the
30 distribution.
31 * Neither the name of Intel Corporation nor the names of its
32 contributors may be used to endorse or promote products derived
33 from this software without specific prior written permission.
34
35 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46*/
47#include <linux/kernel.h>
48#include <linux/module.h>
49#include <linux/pci.h>
50#include <linux/init.h>
51#include <linux/types.h>
52#include <linux/fs.h>
53#include <linux/slab.h>
54#include <linux/errno.h>
55#include <linux/device.h>
56#include <linux/dma-mapping.h>
57#include <linux/platform_device.h>
58#include <linux/workqueue.h>
59#include <linux/io.h>
60#include <adf_accel_devices.h>
61#include <adf_common_drv.h>
62#include <adf_cfg.h>
63#include "adf_c62x_hw_data.h"
64
65#define ADF_SYSTEM_DEVICE(device_id) \
66 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
67
68static const struct pci_device_id adf_pci_tbl[] = {
69 ADF_SYSTEM_DEVICE(ADF_C62X_PCI_DEVICE_ID),
70 {0,}
71};
72MODULE_DEVICE_TABLE(pci, adf_pci_tbl);
73
74static int adf_probe(struct pci_dev *dev, const struct pci_device_id *ent);
75static void adf_remove(struct pci_dev *dev);
76
77static struct pci_driver adf_driver = {
78 .id_table = adf_pci_tbl,
79 .name = ADF_C62X_DEVICE_NAME,
80 .probe = adf_probe,
81 .remove = adf_remove,
82 .sriov_configure = adf_sriov_configure,
83};
84
85static void adf_cleanup_pci_dev(struct adf_accel_dev *accel_dev)
86{
87 pci_release_regions(accel_dev->accel_pci_dev.pci_dev);
88 pci_disable_device(accel_dev->accel_pci_dev.pci_dev);
89}
90
91static void adf_cleanup_accel(struct adf_accel_dev *accel_dev)
92{
93 struct adf_accel_pci *accel_pci_dev = &accel_dev->accel_pci_dev;
94 int i;
95
96 for (i = 0; i < ADF_PCI_MAX_BARS; i++) {
97 struct adf_bar *bar = &accel_pci_dev->pci_bars[i];
98
99 if (bar->virt_addr)
100 pci_iounmap(accel_pci_dev->pci_dev, bar->virt_addr);
101 }
102
103 if (accel_dev->hw_device) {
104 switch (accel_pci_dev->pci_dev->device) {
105 case ADF_C62X_PCI_DEVICE_ID:
106 adf_clean_hw_data_c62x(accel_dev->hw_device);
107 break;
108 default:
109 break;
110 }
111 kfree(accel_dev->hw_device);
112 accel_dev->hw_device = NULL;
113 }
114 adf_cfg_dev_remove(accel_dev);
115 debugfs_remove(accel_dev->debugfs_dir);
116 adf_devmgr_rm_dev(accel_dev, NULL);
117}
118
119static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
120{
121 struct adf_accel_dev *accel_dev;
122 struct adf_accel_pci *accel_pci_dev;
123 struct adf_hw_device_data *hw_data;
124 char name[ADF_DEVICE_NAME_LENGTH];
125 unsigned int i, bar_nr;
126 int ret, bar_mask;
127
128 switch (ent->device) {
129 case ADF_C62X_PCI_DEVICE_ID:
130 break;
131 default:
132 dev_err(&pdev->dev, "Invalid device 0x%x.\n", ent->device);
133 return -ENODEV;
134 }
135
136 if (num_possible_nodes() > 1 && dev_to_node(&pdev->dev) < 0) {
137 /* If the accelerator is connected to a node with no memory
138 * there is no point in using the accelerator since the remote
139 * memory transaction will be very slow. */
140 dev_err(&pdev->dev, "Invalid NUMA configuration.\n");
141 return -EINVAL;
142 }
143
144 accel_dev = kzalloc_node(sizeof(*accel_dev), GFP_KERNEL,
145 dev_to_node(&pdev->dev));
146 if (!accel_dev)
147 return -ENOMEM;
148
149 INIT_LIST_HEAD(&accel_dev->crypto_list);
150 accel_pci_dev = &accel_dev->accel_pci_dev;
151 accel_pci_dev->pci_dev = pdev;
152
153 /* Add accel device to accel table.
154 * This should be called before adf_cleanup_accel is called */
155 if (adf_devmgr_add_dev(accel_dev, NULL)) {
156 dev_err(&pdev->dev, "Failed to add new accelerator device.\n");
157 kfree(accel_dev);
158 return -EFAULT;
159 }
160
161 accel_dev->owner = THIS_MODULE;
162 /* Allocate and configure device configuration structure */
163 hw_data = kzalloc_node(sizeof(*hw_data), GFP_KERNEL,
164 dev_to_node(&pdev->dev));
165 if (!hw_data) {
166 ret = -ENOMEM;
167 goto out_err;
168 }
169
170 accel_dev->hw_device = hw_data;
171 adf_init_hw_data_c62x(accel_dev->hw_device);
172 pci_read_config_byte(pdev, PCI_REVISION_ID, &accel_pci_dev->revid);
173 pci_read_config_dword(pdev, ADF_DEVICE_FUSECTL_OFFSET,
174 &hw_data->fuses);
175
176 /* Get Accelerators and Accelerators Engines masks */
177 hw_data->accel_mask = hw_data->get_accel_mask(hw_data->fuses);
178 hw_data->ae_mask = hw_data->get_ae_mask(hw_data->fuses);
179 accel_pci_dev->sku = hw_data->get_sku(hw_data);
180 /* If the device has no acceleration engines then ignore it. */
181 if (!hw_data->accel_mask || !hw_data->ae_mask ||
182 ((~hw_data->ae_mask) & 0x01)) {
183 dev_err(&pdev->dev, "No acceleration units found");
184 ret = -EFAULT;
185 goto out_err;
186 }
187
188 /* Create dev top level debugfs entry */
189 snprintf(name, sizeof(name), "%s%s_%02x:%02d.%02d",
190 ADF_DEVICE_NAME_PREFIX, hw_data->dev_class->name,
191 pdev->bus->number, PCI_SLOT(pdev->devfn),
192 PCI_FUNC(pdev->devfn));
193
194 accel_dev->debugfs_dir = debugfs_create_dir(name, NULL);
195 if (!accel_dev->debugfs_dir) {
196 dev_err(&pdev->dev, "Could not create debugfs dir %s\n", name);
197 ret = -EINVAL;
198 goto out_err;
199 }
200
201 /* Create device configuration table */
202 ret = adf_cfg_dev_add(accel_dev);
203 if (ret)
204 goto out_err;
205
206 /* enable PCI device */
207 if (pci_enable_device(pdev)) {
208 ret = -EFAULT;
209 goto out_err;
210 }
211
212 /* set dma identifier */
213 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
214 if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) {
215 dev_err(&pdev->dev, "No usable DMA configuration\n");
216 ret = -EFAULT;
217 goto out_err_disable;
218 } else {
219 pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
220 }
221
222 } else {
223 pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
224 }
225
226 if (pci_request_regions(pdev, ADF_C62X_DEVICE_NAME)) {
227 ret = -EFAULT;
228 goto out_err_disable;
229 }
230
231 /* Read accelerator capabilities mask */
232 pci_read_config_dword(pdev, ADF_DEVICE_LEGFUSE_OFFSET,
233 &hw_data->accel_capabilities_mask);
234
235 /* Find and map all the device's BARS */
236 i = 0;
237 bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
238 for_each_set_bit(bar_nr, (const unsigned long *)&bar_mask,
239 ADF_PCI_MAX_BARS * 2) {
240 struct adf_bar *bar = &accel_pci_dev->pci_bars[i++];
241
242 bar->base_addr = pci_resource_start(pdev, bar_nr);
243 if (!bar->base_addr)
244 break;
245 bar->size = pci_resource_len(pdev, bar_nr);
246 bar->virt_addr = pci_iomap(accel_pci_dev->pci_dev, bar_nr, 0);
247 if (!bar->virt_addr) {
248 dev_err(&pdev->dev, "Failed to map BAR %d\n", bar_nr);
249 ret = -EFAULT;
250 goto out_err_free_reg;
251 }
252 }
253 pci_set_master(pdev);
254
255 if (adf_enable_aer(accel_dev, &adf_driver)) {
256 dev_err(&pdev->dev, "Failed to enable aer\n");
257 ret = -EFAULT;
258 goto out_err_free_reg;
259 }
260
261 if (pci_save_state(pdev)) {
262 dev_err(&pdev->dev, "Failed to save pci state\n");
263 ret = -ENOMEM;
264 goto out_err_free_reg;
265 }
266
267 ret = qat_crypto_dev_config(accel_dev);
268 if (ret)
269 goto out_err_free_reg;
270
271 ret = adf_dev_init(accel_dev);
272 if (ret)
273 goto out_err_dev_shutdown;
274
275 ret = adf_dev_start(accel_dev);
276 if (ret)
277 goto out_err_dev_stop;
278
279 return ret;
280
281out_err_dev_stop:
282 adf_dev_stop(accel_dev);
283out_err_dev_shutdown:
284 adf_dev_shutdown(accel_dev);
285out_err_free_reg:
286 pci_release_regions(accel_pci_dev->pci_dev);
287out_err_disable:
288 pci_disable_device(accel_pci_dev->pci_dev);
289out_err:
290 adf_cleanup_accel(accel_dev);
291 kfree(accel_dev);
292 return ret;
293}
294
295static void adf_remove(struct pci_dev *pdev)
296{
297 struct adf_accel_dev *accel_dev = adf_devmgr_pci_to_accel_dev(pdev);
298
299 if (!accel_dev) {
300 pr_err("QAT: Driver removal failed\n");
301 return;
302 }
303 if (adf_dev_stop(accel_dev))
304 dev_err(&GET_DEV(accel_dev), "Failed to stop QAT accel dev\n");
305
306 adf_dev_shutdown(accel_dev);
307 adf_disable_aer(accel_dev);
308 adf_cleanup_accel(accel_dev);
309 adf_cleanup_pci_dev(accel_dev);
310 kfree(accel_dev);
311}
312
313static int __init adfdrv_init(void)
314{
315 request_module("intel_qat");
316
317 if (pci_register_driver(&adf_driver)) {
318 pr_err("QAT: Driver initialization failed\n");
319 return -EFAULT;
320 }
321 return 0;
322}
323
324static void __exit adfdrv_release(void)
325{
326 pci_unregister_driver(&adf_driver);
327}
328
329module_init(adfdrv_init);
330module_exit(adfdrv_release);
331
332MODULE_LICENSE("Dual BSD/GPL");
333MODULE_AUTHOR("Intel");
334MODULE_DESCRIPTION("Intel(R) QuickAssist Technology");
335MODULE_VERSION(ADF_DRV_VERSION);
diff --git a/drivers/crypto/qat/qat_common/adf_cfg_common.h b/drivers/crypto/qat/qat_common/adf_cfg_common.h
index 39884c982c37..5aae6b954c0e 100644
--- a/drivers/crypto/qat/qat_common/adf_cfg_common.h
+++ b/drivers/crypto/qat/qat_common/adf_cfg_common.h
@@ -72,6 +72,7 @@ enum adf_device_type {
72 DEV_UNKNOWN = 0, 72 DEV_UNKNOWN = 0,
73 DEV_DH895XCC, 73 DEV_DH895XCC,
74 DEV_DH895XCCVF, 74 DEV_DH895XCCVF,
75 DEV_C62X,
75 DEV_C3XXX 76 DEV_C3XXX
76}; 77};
77 78