Skip to content

Commit ed8ccae

Browse files
tstrukherbertx
authored andcommitted
crypto: qat - Add support for SRIOV
Add code that enables SRIOV on dh895xcc devices. Signed-off-by: Tadeusz Struk <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent a573313 commit ed8ccae

File tree

17 files changed

+1426
-94
lines changed

17 files changed

+1426
-94
lines changed

drivers/crypto/qat/qat_common/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ intel_qat-objs := adf_cfg.o \
1919
qat_hal.o
2020

2121
intel_qat-$(CONFIG_DEBUG_FS) += adf_transport_debug.o
22+
intel_qat-$(CONFIG_PCI_IOV) += adf_sriov.o adf_pf2vf_msg.o

drivers/crypto/qat/qat_common/adf_accel_devices.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@
4646
*/
4747
#ifndef ADF_ACCEL_DEVICES_H_
4848
#define ADF_ACCEL_DEVICES_H_
49+
#include <linux/interrupt.h>
4950
#include <linux/module.h>
5051
#include <linux/list.h>
5152
#include <linux/io.h>
53+
#include <linux/ratelimit.h>
5254
#include "adf_cfg_common.h"
5355

5456
#define ADF_DH895XCC_DEVICE_NAME "dh895xcc"
57+
#define ADF_DH895XCCVF_DEVICE_NAME "dh895xccvf"
5558
#define ADF_DH895XCC_PCI_DEVICE_ID 0x435
59+
#define ADF_DH895XCCIOV_PCI_DEVICE_ID 0x443
5660
#define ADF_PCI_MAX_BARS 3
5761
#define ADF_DEVICE_NAME_LENGTH 32
5862
#define ADF_ETR_MAX_RINGS_PER_BANK 16
@@ -79,6 +83,7 @@ struct adf_bar {
7983
struct adf_accel_msix {
8084
struct msix_entry *entries;
8185
char **names;
86+
u32 num_entries;
8287
} __packed;
8388

8489
struct adf_accel_pci {
@@ -99,6 +104,7 @@ enum dev_sku_info {
99104
DEV_SKU_2,
100105
DEV_SKU_3,
101106
DEV_SKU_4,
107+
DEV_SKU_VF,
102108
DEV_SKU_UNKNOWN,
103109
};
104110

@@ -113,6 +119,8 @@ static inline const char *get_sku_info(enum dev_sku_info info)
113119
return "SKU3";
114120
case DEV_SKU_4:
115121
return "SKU4";
122+
case DEV_SKU_VF:
123+
return "SKUVF";
116124
case DEV_SKU_UNKNOWN:
117125
default:
118126
break;
@@ -140,6 +148,8 @@ struct adf_hw_device_data {
140148
uint32_t (*get_etr_bar_id)(struct adf_hw_device_data *self);
141149
uint32_t (*get_num_aes)(struct adf_hw_device_data *self);
142150
uint32_t (*get_num_accels)(struct adf_hw_device_data *self);
151+
uint32_t (*get_pf2vf_offset)(uint32_t i);
152+
uint32_t (*get_vintmsk_offset)(uint32_t i);
143153
enum dev_sku_info (*get_sku)(struct adf_hw_device_data *self);
144154
int (*alloc_irq)(struct adf_accel_dev *accel_dev);
145155
void (*free_irq)(struct adf_accel_dev *accel_dev);
@@ -151,7 +161,9 @@ struct adf_hw_device_data {
151161
void (*exit_arb)(struct adf_accel_dev *accel_dev);
152162
void (*get_arb_mapping)(struct adf_accel_dev *accel_dev,
153163
const uint32_t **cfg);
164+
void (*disable_iov)(struct adf_accel_dev *accel_dev);
154165
void (*enable_ints)(struct adf_accel_dev *accel_dev);
166+
int (*enable_vf2pf_comms)(struct adf_accel_dev *accel_dev);
155167
const char *fw_name;
156168
const char *fw_mmp_name;
157169
uint32_t fuses;
@@ -165,6 +177,7 @@ struct adf_hw_device_data {
165177
uint8_t num_accel;
166178
uint8_t num_logical_accel;
167179
uint8_t num_engines;
180+
uint8_t min_iov_compat_ver;
168181
} __packed;
169182

170183
/* CSR write macro */
@@ -189,6 +202,15 @@ struct adf_fw_loader_data {
189202
const struct firmware *mmp_fw;
190203
};
191204

205+
struct adf_accel_vf_info {
206+
struct adf_accel_dev *accel_dev;
207+
struct tasklet_struct vf2pf_bh_tasklet;
208+
struct mutex pf2vf_lock; /* protect CSR access for PF2VF messages */
209+
struct ratelimit_state vf2pf_ratelimit;
210+
u32 vf_nr;
211+
bool init;
212+
};
213+
192214
struct adf_accel_dev {
193215
struct adf_etr_data *transport;
194216
struct adf_hw_device_data *hw_device;
@@ -202,6 +224,21 @@ struct adf_accel_dev {
202224
struct list_head list;
203225
struct module *owner;
204226
struct adf_accel_pci accel_pci_dev;
227+
union {
228+
struct {
229+
/* vf_info is non-zero when SR-IOV is init'ed */
230+
struct adf_accel_vf_info *vf_info;
231+
} pf;
232+
struct {
233+
char *irq_name;
234+
struct tasklet_struct pf2vf_bh_tasklet;
235+
struct mutex vf2pf_lock; /* protect CSR access */
236+
struct completion iov_msg_completion;
237+
uint8_t compatible;
238+
uint8_t pf_version;
239+
} vf;
240+
};
241+
bool is_vf;
205242
uint8_t accel_id;
206243
} __packed;
207244
#endif

drivers/crypto/qat/qat_common/adf_aer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ static void adf_dev_restore(struct adf_accel_dev *accel_dev)
9191
dev_info(&GET_DEV(accel_dev), "Resetting device qat_dev%d\n",
9292
accel_dev->accel_id);
9393

94+
if (!parent)
95+
parent = pdev;
96+
9497
if (!pci_wait_for_pending_transaction(pdev))
9598
dev_info(&GET_DEV(accel_dev),
9699
"Transaction still in progress. Proceeding\n");

drivers/crypto/qat/qat_common/adf_cfg.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ void adf_cfg_dev_remove(struct adf_accel_dev *accel_dev)
178178
{
179179
struct adf_cfg_device_data *dev_cfg_data = accel_dev->cfg;
180180

181+
if (!dev_cfg_data)
182+
return;
183+
181184
down_write(&dev_cfg_data->lock);
182185
adf_cfg_section_del_all(&dev_cfg_data->sec_list);
183186
up_write(&dev_cfg_data->lock);

drivers/crypto/qat/qat_common/adf_cfg_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#define ADF_CFG_NO_DEVICE 0xFF
6161
#define ADF_CFG_AFFINITY_WHATEVER 0xFF
6262
#define MAX_DEVICE_NAME_SIZE 32
63-
#define ADF_MAX_DEVICES 32
63+
#define ADF_MAX_DEVICES (32 * 32)
6464

6565
enum adf_cfg_val_type {
6666
ADF_DEC,
@@ -71,6 +71,7 @@ enum adf_cfg_val_type {
7171
enum adf_device_type {
7272
DEV_UNKNOWN = 0,
7373
DEV_DH895XCC,
74+
DEV_DH895XCCVF,
7475
};
7576

7677
struct adf_dev_status_info {

drivers/crypto/qat/qat_common/adf_common_drv.h

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
#include "icp_qat_hal.h"
5555

5656
#define ADF_MAJOR_VERSION 0
57-
#define ADF_MINOR_VERSION 1
58-
#define ADF_BUILD_VERSION 4
57+
#define ADF_MINOR_VERSION 2
58+
#define ADF_BUILD_VERSION 0
5959
#define ADF_DRV_VERSION __stringify(ADF_MAJOR_VERSION) "." \
6060
__stringify(ADF_MINOR_VERSION) "." \
6161
__stringify(ADF_BUILD_VERSION)
@@ -95,7 +95,7 @@ struct service_hndl {
9595

9696
static inline int get_current_node(void)
9797
{
98-
return cpu_data(current_thread_info()->cpu).phys_proc_id;
98+
return topology_physical_package_id(smp_processor_id());
9999
}
100100

101101
int adf_service_register(struct service_hndl *service);
@@ -106,13 +106,23 @@ int adf_dev_start(struct adf_accel_dev *accel_dev);
106106
int adf_dev_stop(struct adf_accel_dev *accel_dev);
107107
void adf_dev_shutdown(struct adf_accel_dev *accel_dev);
108108

109+
void adf_enable_pf2vf_interrupts(struct adf_accel_dev *accel_dev);
110+
void adf_disable_pf2vf_interrupts(struct adf_accel_dev *accel_dev);
111+
int adf_iov_putmsg(struct adf_accel_dev *accel_dev, u32 msg, u8 vf_nr);
112+
void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev);
113+
int adf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev);
114+
void adf_devmgr_update_class_index(struct adf_hw_device_data *hw_data);
115+
void adf_clean_vf_map(bool);
116+
109117
int adf_ctl_dev_register(void);
110118
void adf_ctl_dev_unregister(void);
111119
int adf_processes_dev_register(void);
112120
void adf_processes_dev_unregister(void);
113121

114-
int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev);
115-
void adf_devmgr_rm_dev(struct adf_accel_dev *accel_dev);
122+
int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev,
123+
struct adf_accel_dev *pf);
124+
void adf_devmgr_rm_dev(struct adf_accel_dev *accel_dev,
125+
struct adf_accel_dev *pf);
116126
struct list_head *adf_devmgr_get_head(void);
117127
struct adf_accel_dev *adf_devmgr_get_dev_by_id(uint32_t id);
118128
struct adf_accel_dev *adf_devmgr_get_first(void);
@@ -211,4 +221,21 @@ int qat_uclo_map_uof_obj(struct icp_qat_fw_loader_handle *handle,
211221
void *addr_ptr, int mem_size);
212222
void qat_uclo_wr_mimage(struct icp_qat_fw_loader_handle *handle,
213223
void *addr_ptr, int mem_size);
224+
#if defined(CONFIG_PCI_IOV)
225+
int adf_sriov_configure(struct pci_dev *pdev, int numvfs);
226+
void adf_disable_sriov(struct adf_accel_dev *accel_dev);
227+
void adf_disable_vf2pf_interrupts(struct adf_accel_dev *accel_dev,
228+
uint32_t vf_mask);
229+
void adf_enable_vf2pf_interrupts(struct adf_accel_dev *accel_dev,
230+
uint32_t vf_mask);
231+
#else
232+
static inline int adf_sriov_configure(struct pci_dev *pdev, int numvfs)
233+
{
234+
return 0;
235+
}
236+
237+
static inline void adf_disable_sriov(struct adf_accel_dev *accel_dev)
238+
{
239+
}
240+
#endif
214241
#endif

drivers/crypto/qat/qat_common/adf_ctl_drv.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,9 @@ static int adf_ctl_ioctl_get_status(struct file *fp, unsigned int cmd,
398398
}
399399

400400
accel_dev = adf_devmgr_get_dev_by_id(dev_info.accel_id);
401-
if (!accel_dev) {
402-
pr_err("QAT: Device %d not found\n", dev_info.accel_id);
401+
if (!accel_dev)
403402
return -ENODEV;
404-
}
403+
405404
hw_data = accel_dev->hw_device;
406405
dev_info.state = adf_dev_started(accel_dev) ? DEV_UP : DEV_DOWN;
407406
dev_info.num_ae = hw_data->get_num_aes(hw_data);
@@ -495,6 +494,7 @@ static void __exit adf_unregister_ctl_device_driver(void)
495494
adf_exit_aer();
496495
qat_crypto_unregister();
497496
qat_algs_exit();
497+
adf_clean_vf_map(false);
498498
mutex_destroy(&adf_ctl_lock);
499499
}
500500

0 commit comments

Comments
 (0)