crypto: qat - protect interrupt mask CSRs with a spinlock
[linux-2.6-microblaze.git] / drivers / crypto / qat / qat_c62x / adf_c62x_hw_data.c
1 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
2 /* Copyright(c) 2014 - 2020 Intel Corporation */
3 #include <adf_accel_devices.h>
4 #include <adf_common_drv.h>
5 #include <adf_pf2vf_msg.h>
6 #include <adf_gen2_hw_data.h>
7 #include "adf_c62x_hw_data.h"
8 #include "icp_qat_hw.h"
9
10 /* Worker thread to service arbiter mappings */
11 static const u32 thrd_to_arb_map[ADF_C62X_MAX_ACCELENGINES] = {
12         0x12222AAA, 0x11222AAA, 0x12222AAA, 0x11222AAA, 0x12222AAA,
13         0x11222AAA, 0x12222AAA, 0x11222AAA, 0x12222AAA, 0x11222AAA
14 };
15
16 static struct adf_hw_device_class c62x_class = {
17         .name = ADF_C62X_DEVICE_NAME,
18         .type = DEV_C62X,
19         .instances = 0
20 };
21
22 static u32 get_accel_mask(struct adf_hw_device_data *self)
23 {
24         u32 straps = self->straps;
25         u32 fuses = self->fuses;
26         u32 accel;
27
28         accel = ~(fuses | straps) >> ADF_C62X_ACCELERATORS_REG_OFFSET;
29         accel &= ADF_C62X_ACCELERATORS_MASK;
30
31         return accel;
32 }
33
34 static u32 get_ae_mask(struct adf_hw_device_data *self)
35 {
36         u32 straps = self->straps;
37         u32 fuses = self->fuses;
38         unsigned long disabled;
39         u32 ae_disable;
40         int accel;
41
42         /* If an accel is disabled, then disable the corresponding two AEs */
43         disabled = ~get_accel_mask(self) & ADF_C62X_ACCELERATORS_MASK;
44         ae_disable = BIT(1) | BIT(0);
45         for_each_set_bit(accel, &disabled, ADF_C62X_MAX_ACCELERATORS)
46                 straps |= ae_disable << (accel << 1);
47
48         return ~(fuses | straps) & ADF_C62X_ACCELENGINES_MASK;
49 }
50
51 static u32 get_num_accels(struct adf_hw_device_data *self)
52 {
53         u32 i, ctr = 0;
54
55         if (!self || !self->accel_mask)
56                 return 0;
57
58         for (i = 0; i < ADF_C62X_MAX_ACCELERATORS; i++) {
59                 if (self->accel_mask & (1 << i))
60                         ctr++;
61         }
62         return ctr;
63 }
64
65 static u32 get_num_aes(struct adf_hw_device_data *self)
66 {
67         u32 i, ctr = 0;
68
69         if (!self || !self->ae_mask)
70                 return 0;
71
72         for (i = 0; i < ADF_C62X_MAX_ACCELENGINES; i++) {
73                 if (self->ae_mask & (1 << i))
74                         ctr++;
75         }
76         return ctr;
77 }
78
79 static u32 get_misc_bar_id(struct adf_hw_device_data *self)
80 {
81         return ADF_C62X_PMISC_BAR;
82 }
83
84 static u32 get_etr_bar_id(struct adf_hw_device_data *self)
85 {
86         return ADF_C62X_ETR_BAR;
87 }
88
89 static u32 get_sram_bar_id(struct adf_hw_device_data *self)
90 {
91         return ADF_C62X_SRAM_BAR;
92 }
93
94 static enum dev_sku_info get_sku(struct adf_hw_device_data *self)
95 {
96         int aes = get_num_aes(self);
97
98         if (aes == 8)
99                 return DEV_SKU_2;
100         else if (aes == 10)
101                 return DEV_SKU_4;
102
103         return DEV_SKU_UNKNOWN;
104 }
105
106 static const u32 *adf_get_arbiter_mapping(void)
107 {
108         return thrd_to_arb_map;
109 }
110
111 static u32 get_pf2vf_offset(u32 i)
112 {
113         return ADF_C62X_PF2VF_OFFSET(i);
114 }
115
116 static u32 get_vintmsk_offset(u32 i)
117 {
118         return ADF_C62X_VINTMSK_OFFSET(i);
119 }
120
121 static void adf_enable_error_correction(struct adf_accel_dev *accel_dev)
122 {
123         struct adf_hw_device_data *hw_device = accel_dev->hw_device;
124         struct adf_bar *misc_bar = &GET_BARS(accel_dev)[ADF_C62X_PMISC_BAR];
125         unsigned long accel_mask = hw_device->accel_mask;
126         unsigned long ae_mask = hw_device->ae_mask;
127         void __iomem *csr = misc_bar->virt_addr;
128         unsigned int val, i;
129
130         /* Enable Accel Engine error detection & correction */
131         for_each_set_bit(i, &ae_mask, GET_MAX_ACCELENGINES(accel_dev)) {
132                 val = ADF_CSR_RD(csr, ADF_C62X_AE_CTX_ENABLES(i));
133                 val |= ADF_C62X_ENABLE_AE_ECC_ERR;
134                 ADF_CSR_WR(csr, ADF_C62X_AE_CTX_ENABLES(i), val);
135                 val = ADF_CSR_RD(csr, ADF_C62X_AE_MISC_CONTROL(i));
136                 val |= ADF_C62X_ENABLE_AE_ECC_PARITY_CORR;
137                 ADF_CSR_WR(csr, ADF_C62X_AE_MISC_CONTROL(i), val);
138         }
139
140         /* Enable shared memory error detection & correction */
141         for_each_set_bit(i, &accel_mask, ADF_C62X_MAX_ACCELERATORS) {
142                 val = ADF_CSR_RD(csr, ADF_C62X_UERRSSMSH(i));
143                 val |= ADF_C62X_ERRSSMSH_EN;
144                 ADF_CSR_WR(csr, ADF_C62X_UERRSSMSH(i), val);
145                 val = ADF_CSR_RD(csr, ADF_C62X_CERRSSMSH(i));
146                 val |= ADF_C62X_ERRSSMSH_EN;
147                 ADF_CSR_WR(csr, ADF_C62X_CERRSSMSH(i), val);
148         }
149 }
150
151 static void adf_enable_ints(struct adf_accel_dev *accel_dev)
152 {
153         void __iomem *addr;
154
155         addr = (&GET_BARS(accel_dev)[ADF_C62X_PMISC_BAR])->virt_addr;
156
157         /* Enable bundle and misc interrupts */
158         ADF_CSR_WR(addr, ADF_C62X_SMIAPF0_MASK_OFFSET,
159                    ADF_C62X_SMIA0_MASK);
160         ADF_CSR_WR(addr, ADF_C62X_SMIAPF1_MASK_OFFSET,
161                    ADF_C62X_SMIA1_MASK);
162 }
163
164 static int adf_pf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev)
165 {
166         spin_lock_init(&accel_dev->pf.vf2pf_ints_lock);
167
168         return 0;
169 }
170
171 static void configure_iov_threads(struct adf_accel_dev *accel_dev, bool enable)
172 {
173         adf_gen2_cfg_iov_thds(accel_dev, enable,
174                               ADF_C62X_AE2FUNC_MAP_GRP_A_NUM_REGS,
175                               ADF_C62X_AE2FUNC_MAP_GRP_B_NUM_REGS);
176 }
177
178 void adf_init_hw_data_c62x(struct adf_hw_device_data *hw_data)
179 {
180         hw_data->dev_class = &c62x_class;
181         hw_data->instance_id = c62x_class.instances++;
182         hw_data->num_banks = ADF_C62X_ETR_MAX_BANKS;
183         hw_data->num_rings_per_bank = ADF_ETR_MAX_RINGS_PER_BANK;
184         hw_data->num_accel = ADF_C62X_MAX_ACCELERATORS;
185         hw_data->num_logical_accel = 1;
186         hw_data->num_engines = ADF_C62X_MAX_ACCELENGINES;
187         hw_data->tx_rx_gap = ADF_C62X_RX_RINGS_OFFSET;
188         hw_data->tx_rings_mask = ADF_C62X_TX_RINGS_MASK;
189         hw_data->alloc_irq = adf_isr_resource_alloc;
190         hw_data->free_irq = adf_isr_resource_free;
191         hw_data->enable_error_correction = adf_enable_error_correction;
192         hw_data->get_accel_mask = get_accel_mask;
193         hw_data->get_ae_mask = get_ae_mask;
194         hw_data->get_accel_cap = adf_gen2_get_accel_cap;
195         hw_data->get_num_accels = get_num_accels;
196         hw_data->get_num_aes = get_num_aes;
197         hw_data->get_sram_bar_id = get_sram_bar_id;
198         hw_data->get_etr_bar_id = get_etr_bar_id;
199         hw_data->get_misc_bar_id = get_misc_bar_id;
200         hw_data->get_pf2vf_offset = get_pf2vf_offset;
201         hw_data->get_vintmsk_offset = get_vintmsk_offset;
202         hw_data->get_admin_info = adf_gen2_get_admin_info;
203         hw_data->get_arb_info = adf_gen2_get_arb_info;
204         hw_data->get_sku = get_sku;
205         hw_data->fw_name = ADF_C62X_FW;
206         hw_data->fw_mmp_name = ADF_C62X_MMP;
207         hw_data->init_admin_comms = adf_init_admin_comms;
208         hw_data->exit_admin_comms = adf_exit_admin_comms;
209         hw_data->configure_iov_threads = configure_iov_threads;
210         hw_data->disable_iov = adf_disable_sriov;
211         hw_data->send_admin_init = adf_send_admin_init;
212         hw_data->init_arb = adf_init_arb;
213         hw_data->exit_arb = adf_exit_arb;
214         hw_data->get_arb_mapping = adf_get_arbiter_mapping;
215         hw_data->enable_ints = adf_enable_ints;
216         hw_data->enable_vf2pf_comms = adf_pf_enable_vf2pf_comms;
217         hw_data->reset_device = adf_reset_flr;
218         hw_data->min_iov_compat_ver = ADF_PFVF_COMPAT_THIS_VERSION;
219         hw_data->set_ssm_wdtimer = adf_gen2_set_ssm_wdtimer;
220         adf_gen2_init_hw_csr_ops(&hw_data->csr_ops);
221 }
222
223 void adf_clean_hw_data_c62x(struct adf_hw_device_data *hw_data)
224 {
225         hw_data->dev_class->instances--;
226 }