Skip to content

Commit 4469f9b

Browse files
yepmunchunherbertx
authored andcommitted
crypto: qat - re-enable sriov after pf reset
When a Physical Function (PF) is reset, SR-IOV gets disabled, making the associated Virtual Functions (VFs) unavailable. Even after reset and using pci_restore_state, VFs remain uncreated because the numvfs still at 0. Therefore, it's necessary to reconfigure SR-IOV to re-enable VFs. This commit introduces the ADF_SRIOV_ENABLED configuration flag to cache the SR-IOV enablement state. SR-IOV is only re-enabled if it was previously configured. This commit also introduces a dedicated workqueue without `WQ_MEM_RECLAIM` flag for enabling SR-IOV during Heartbeat and CPM error resets, preventing workqueue flushing warning. This patch is based on earlier work done by Shashank Gupta. Signed-off-by: Mun Chun Yep <mun.chun.yep@intel.com> Reviewed-by: Ahsan Atta <ahsan.atta@intel.com> Reviewed-by: Markas Rapoportas <markas.rapoportas@intel.com> Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent ec26f8e commit 4469f9b

File tree

4 files changed

+79
-4
lines changed

4 files changed

+79
-4
lines changed

drivers/crypto/intel/qat/qat_common/adf_aer.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct adf_fatal_error_data {
1515
};
1616

1717
static struct workqueue_struct *device_reset_wq;
18+
static struct workqueue_struct *device_sriov_wq;
1819

1920
static pci_ers_result_t adf_error_detected(struct pci_dev *pdev,
2021
pci_channel_state_t state)
@@ -43,6 +44,13 @@ struct adf_reset_dev_data {
4344
struct work_struct reset_work;
4445
};
4546

47+
/* sriov dev data */
48+
struct adf_sriov_dev_data {
49+
struct adf_accel_dev *accel_dev;
50+
struct completion compl;
51+
struct work_struct sriov_work;
52+
};
53+
4654
void adf_reset_sbr(struct adf_accel_dev *accel_dev)
4755
{
4856
struct pci_dev *pdev = accel_to_pci_dev(accel_dev);
@@ -88,11 +96,22 @@ void adf_dev_restore(struct adf_accel_dev *accel_dev)
8896
}
8997
}
9098

99+
static void adf_device_sriov_worker(struct work_struct *work)
100+
{
101+
struct adf_sriov_dev_data *sriov_data =
102+
container_of(work, struct adf_sriov_dev_data, sriov_work);
103+
104+
adf_reenable_sriov(sriov_data->accel_dev);
105+
complete(&sriov_data->compl);
106+
}
107+
91108
static void adf_device_reset_worker(struct work_struct *work)
92109
{
93110
struct adf_reset_dev_data *reset_data =
94111
container_of(work, struct adf_reset_dev_data, reset_work);
95112
struct adf_accel_dev *accel_dev = reset_data->accel_dev;
113+
unsigned long wait_jiffies = msecs_to_jiffies(10000);
114+
struct adf_sriov_dev_data sriov_data;
96115

97116
adf_dev_restarting_notify(accel_dev);
98117
if (adf_dev_restart(accel_dev)) {
@@ -103,6 +122,14 @@ static void adf_device_reset_worker(struct work_struct *work)
103122
WARN(1, "QAT: device restart failed. Device is unusable\n");
104123
return;
105124
}
125+
126+
sriov_data.accel_dev = accel_dev;
127+
init_completion(&sriov_data.compl);
128+
INIT_WORK(&sriov_data.sriov_work, adf_device_sriov_worker);
129+
queue_work(device_sriov_wq, &sriov_data.sriov_work);
130+
if (wait_for_completion_timeout(&sriov_data.compl, wait_jiffies))
131+
adf_pf2vf_notify_restarted(accel_dev);
132+
106133
adf_dev_restarted_notify(accel_dev);
107134
clear_bit(ADF_STATUS_RESTARTING, &accel_dev->status);
108135

@@ -216,12 +243,23 @@ int adf_init_aer(void)
216243
{
217244
device_reset_wq = alloc_workqueue("qat_device_reset_wq",
218245
WQ_MEM_RECLAIM, 0);
219-
return !device_reset_wq ? -EFAULT : 0;
246+
if (!device_reset_wq)
247+
return -EFAULT;
248+
249+
device_sriov_wq = alloc_workqueue("qat_device_sriov_wq", 0, 0);
250+
if (!device_sriov_wq)
251+
return -EFAULT;
252+
253+
return 0;
220254
}
221255

222256
void adf_exit_aer(void)
223257
{
224258
if (device_reset_wq)
225259
destroy_workqueue(device_reset_wq);
226260
device_reset_wq = NULL;
261+
262+
if (device_sriov_wq)
263+
destroy_workqueue(device_sriov_wq);
264+
device_sriov_wq = NULL;
227265
}

drivers/crypto/intel/qat/qat_common/adf_cfg_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@
4949
ADF_ETRMGR_BANK "%d" ADF_ETRMGR_CORE_AFFINITY
5050
#define ADF_ACCEL_STR "Accelerator%d"
5151
#define ADF_HEARTBEAT_TIMER "HeartbeatTimer"
52+
#define ADF_SRIOV_ENABLED "SriovEnabled"
5253

5354
#endif

drivers/crypto/intel/qat/qat_common/adf_common_drv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ bool adf_misc_wq_queue_delayed_work(struct delayed_work *work,
192192
#if defined(CONFIG_PCI_IOV)
193193
int adf_sriov_configure(struct pci_dev *pdev, int numvfs);
194194
void adf_disable_sriov(struct adf_accel_dev *accel_dev);
195+
void adf_reenable_sriov(struct adf_accel_dev *accel_dev);
195196
void adf_enable_vf2pf_interrupts(struct adf_accel_dev *accel_dev, u32 vf_mask);
196197
void adf_disable_all_vf2pf_interrupts(struct adf_accel_dev *accel_dev);
197198
bool adf_recv_and_handle_pf2vf_msg(struct adf_accel_dev *accel_dev);
@@ -212,6 +213,10 @@ static inline void adf_disable_sriov(struct adf_accel_dev *accel_dev)
212213
{
213214
}
214215

216+
static inline void adf_reenable_sriov(struct adf_accel_dev *accel_dev)
217+
{
218+
}
219+
215220
static inline int adf_init_pf_wq(void)
216221
{
217222
return 0;

drivers/crypto/intel/qat/qat_common/adf_sriov.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ static int adf_enable_sriov(struct adf_accel_dev *accel_dev)
6060
/* This ptr will be populated when VFs will be created */
6161
vf_info->accel_dev = accel_dev;
6262
vf_info->vf_nr = i;
63-
vf_info->vf_compat_ver = 0;
6463

6564
mutex_init(&vf_info->pf2vf_lock);
6665
ratelimit_state_init(&vf_info->vf2pf_ratelimit,
@@ -84,6 +83,32 @@ static int adf_enable_sriov(struct adf_accel_dev *accel_dev)
8483
return pci_enable_sriov(pdev, totalvfs);
8584
}
8685

86+
void adf_reenable_sriov(struct adf_accel_dev *accel_dev)
87+
{
88+
struct pci_dev *pdev = accel_to_pci_dev(accel_dev);
89+
char cfg[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0};
90+
unsigned long val = 0;
91+
92+
if (adf_cfg_get_param_value(accel_dev, ADF_GENERAL_SEC,
93+
ADF_SRIOV_ENABLED, cfg))
94+
return;
95+
96+
if (!accel_dev->pf.vf_info)
97+
return;
98+
99+
if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, ADF_NUM_CY,
100+
&val, ADF_DEC))
101+
return;
102+
103+
if (adf_cfg_add_key_value_param(accel_dev, ADF_KERNEL_SEC, ADF_NUM_DC,
104+
&val, ADF_DEC))
105+
return;
106+
107+
set_bit(ADF_STATUS_CONFIGURED, &accel_dev->status);
108+
dev_dbg(&pdev->dev, "Re-enabling SRIOV\n");
109+
adf_enable_sriov(accel_dev);
110+
}
111+
87112
/**
88113
* adf_disable_sriov() - Disable SRIOV for the device
89114
* @accel_dev: Pointer to accel device.
@@ -116,8 +141,10 @@ void adf_disable_sriov(struct adf_accel_dev *accel_dev)
116141
for (i = 0, vf = accel_dev->pf.vf_info; i < totalvfs; i++, vf++)
117142
mutex_destroy(&vf->pf2vf_lock);
118143

119-
kfree(accel_dev->pf.vf_info);
120-
accel_dev->pf.vf_info = NULL;
144+
if (!test_bit(ADF_STATUS_RESTARTING, &accel_dev->status)) {
145+
kfree(accel_dev->pf.vf_info);
146+
accel_dev->pf.vf_info = NULL;
147+
}
121148
}
122149
EXPORT_SYMBOL_GPL(adf_disable_sriov);
123150

@@ -195,6 +222,10 @@ int adf_sriov_configure(struct pci_dev *pdev, int numvfs)
195222
if (ret)
196223
return ret;
197224

225+
val = 1;
226+
adf_cfg_add_key_value_param(accel_dev, ADF_GENERAL_SEC, ADF_SRIOV_ENABLED,
227+
&val, ADF_DEC);
228+
198229
return numvfs;
199230
}
200231
EXPORT_SYMBOL_GPL(adf_sriov_configure);

0 commit comments

Comments
 (0)