Skip to content

Commit ec26f8e

Browse files
yepmunchunherbertx
authored andcommitted
crypto: qat - update PFVF protocol for recovery
Update the PFVF logic to handle restart and recovery. This adds the following functions: * adf_pf2vf_notify_fatal_error(): allows the PF to notify VFs that the device detected a fatal error and requires a reset. This sends to VF the event `ADF_PF2VF_MSGTYPE_FATAL_ERROR`. * adf_pf2vf_wait_for_restarting_complete(): allows the PF to wait for `ADF_VF2PF_MSGTYPE_RESTARTING_COMPLETE` events from active VFs before proceeding with a reset. * adf_pf2vf_notify_restarted(): enables the PF to notify VFs with an `ADF_PF2VF_MSGTYPE_RESTARTED` event after recovery, indicating that the device is back to normal. This prompts VF drivers switch back to use the accelerator for workload processing. These changes improve the communication and synchronization between PF and VF drivers during system restart and recovery processes. 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 758a008 commit ec26f8e

File tree

8 files changed

+109
-2
lines changed

8 files changed

+109
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ struct adf_accel_vf_info {
332332
struct ratelimit_state vf2pf_ratelimit;
333333
u32 vf_nr;
334334
bool init;
335+
bool restarting;
335336
u8 vf_compat_ver;
336337
};
337338

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/delay.h>
88
#include "adf_accel_devices.h"
99
#include "adf_common_drv.h"
10+
#include "adf_pfvf_pf_msg.h"
1011

1112
struct adf_fatal_error_data {
1213
struct adf_accel_dev *accel_dev;
@@ -189,6 +190,8 @@ static void adf_notify_fatal_error_worker(struct work_struct *work)
189190
/* Disable arbitration to stop processing of new requests */
190191
if (hw_device->exit_arb)
191192
hw_device->exit_arb(accel_dev);
193+
if (accel_dev->pf.vf_info)
194+
adf_pf2vf_notify_fatal_error(accel_dev);
192195
}
193196

194197
kfree(wq_data);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ enum pf2vf_msgtype {
9999
ADF_PF2VF_MSGTYPE_RESTARTING = 0x01,
100100
ADF_PF2VF_MSGTYPE_VERSION_RESP = 0x02,
101101
ADF_PF2VF_MSGTYPE_BLKMSG_RESP = 0x03,
102+
ADF_PF2VF_MSGTYPE_FATAL_ERROR = 0x04,
103+
ADF_PF2VF_MSGTYPE_RESTARTED = 0x05,
102104
/* Values from 0x10 are Gen4 specific, message type is only 4 bits in Gen2 devices. */
103105
ADF_PF2VF_MSGTYPE_RP_RESET_RESP = 0x10,
104106
};
@@ -112,6 +114,7 @@ enum vf2pf_msgtype {
112114
ADF_VF2PF_MSGTYPE_LARGE_BLOCK_REQ = 0x07,
113115
ADF_VF2PF_MSGTYPE_MEDIUM_BLOCK_REQ = 0x08,
114116
ADF_VF2PF_MSGTYPE_SMALL_BLOCK_REQ = 0x09,
117+
ADF_VF2PF_MSGTYPE_RESTARTING_COMPLETE = 0x0a,
115118
/* Values from 0x10 are Gen4 specific, message type is only 4 bits in Gen2 devices. */
116119
ADF_VF2PF_MSGTYPE_RP_RESET = 0x10,
117120
};
@@ -124,8 +127,10 @@ enum pfvf_compatibility_version {
124127
ADF_PFVF_COMPAT_FAST_ACK = 0x03,
125128
/* Ring to service mapping support for non-standard mappings */
126129
ADF_PFVF_COMPAT_RING_TO_SVC_MAP = 0x04,
130+
/* Fallback compat */
131+
ADF_PFVF_COMPAT_FALLBACK = 0x05,
127132
/* Reference to the latest version */
128-
ADF_PFVF_COMPAT_THIS_VERSION = 0x04,
133+
ADF_PFVF_COMPAT_THIS_VERSION = 0x05,
129134
};
130135

131136
/* PF->VF Version Response */

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

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,83 @@
11
// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
22
/* Copyright(c) 2015 - 2021 Intel Corporation */
3+
#include <linux/delay.h>
34
#include <linux/pci.h>
45
#include "adf_accel_devices.h"
56
#include "adf_pfvf_msg.h"
67
#include "adf_pfvf_pf_msg.h"
78
#include "adf_pfvf_pf_proto.h"
89

10+
#define ADF_PF_WAIT_RESTARTING_COMPLETE_DELAY 100
11+
#define ADF_VF_SHUTDOWN_RETRY 100
12+
913
void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev)
1014
{
1115
struct adf_accel_vf_info *vf;
1216
struct pfvf_message msg = { .type = ADF_PF2VF_MSGTYPE_RESTARTING };
1317
int i, num_vfs = pci_num_vf(accel_to_pci_dev(accel_dev));
1418

19+
dev_dbg(&GET_DEV(accel_dev), "pf2vf notify restarting\n");
1520
for (i = 0, vf = accel_dev->pf.vf_info; i < num_vfs; i++, vf++) {
16-
if (vf->init && adf_send_pf2vf_msg(accel_dev, i, msg))
21+
vf->restarting = false;
22+
if (!vf->init)
23+
continue;
24+
if (adf_send_pf2vf_msg(accel_dev, i, msg))
1725
dev_err(&GET_DEV(accel_dev),
1826
"Failed to send restarting msg to VF%d\n", i);
27+
else if (vf->vf_compat_ver >= ADF_PFVF_COMPAT_FALLBACK)
28+
vf->restarting = true;
29+
}
30+
}
31+
32+
void adf_pf2vf_wait_for_restarting_complete(struct adf_accel_dev *accel_dev)
33+
{
34+
int num_vfs = pci_num_vf(accel_to_pci_dev(accel_dev));
35+
int i, retries = ADF_VF_SHUTDOWN_RETRY;
36+
struct adf_accel_vf_info *vf;
37+
bool vf_running;
38+
39+
dev_dbg(&GET_DEV(accel_dev), "pf2vf wait for restarting complete\n");
40+
do {
41+
vf_running = false;
42+
for (i = 0, vf = accel_dev->pf.vf_info; i < num_vfs; i++, vf++)
43+
if (vf->restarting)
44+
vf_running = true;
45+
if (!vf_running)
46+
break;
47+
msleep(ADF_PF_WAIT_RESTARTING_COMPLETE_DELAY);
48+
} while (--retries);
49+
50+
if (vf_running)
51+
dev_warn(&GET_DEV(accel_dev), "Some VFs are still running\n");
52+
}
53+
54+
void adf_pf2vf_notify_restarted(struct adf_accel_dev *accel_dev)
55+
{
56+
struct pfvf_message msg = { .type = ADF_PF2VF_MSGTYPE_RESTARTED };
57+
int i, num_vfs = pci_num_vf(accel_to_pci_dev(accel_dev));
58+
struct adf_accel_vf_info *vf;
59+
60+
dev_dbg(&GET_DEV(accel_dev), "pf2vf notify restarted\n");
61+
for (i = 0, vf = accel_dev->pf.vf_info; i < num_vfs; i++, vf++) {
62+
if (vf->init && vf->vf_compat_ver >= ADF_PFVF_COMPAT_FALLBACK &&
63+
adf_send_pf2vf_msg(accel_dev, i, msg))
64+
dev_err(&GET_DEV(accel_dev),
65+
"Failed to send restarted msg to VF%d\n", i);
66+
}
67+
}
68+
69+
void adf_pf2vf_notify_fatal_error(struct adf_accel_dev *accel_dev)
70+
{
71+
struct pfvf_message msg = { .type = ADF_PF2VF_MSGTYPE_FATAL_ERROR };
72+
int i, num_vfs = pci_num_vf(accel_to_pci_dev(accel_dev));
73+
struct adf_accel_vf_info *vf;
74+
75+
dev_dbg(&GET_DEV(accel_dev), "pf2vf notify fatal error\n");
76+
for (i = 0, vf = accel_dev->pf.vf_info; i < num_vfs; i++, vf++) {
77+
if (vf->init && vf->vf_compat_ver >= ADF_PFVF_COMPAT_FALLBACK &&
78+
adf_send_pf2vf_msg(accel_dev, i, msg))
79+
dev_err(&GET_DEV(accel_dev),
80+
"Failed to send fatal error msg to VF%d\n", i);
1981
}
2082
}
2183

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,28 @@
55

66
#include "adf_accel_devices.h"
77

8+
#if defined(CONFIG_PCI_IOV)
89
void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev);
10+
void adf_pf2vf_wait_for_restarting_complete(struct adf_accel_dev *accel_dev);
11+
void adf_pf2vf_notify_restarted(struct adf_accel_dev *accel_dev);
12+
void adf_pf2vf_notify_fatal_error(struct adf_accel_dev *accel_dev);
13+
#else
14+
static inline void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev)
15+
{
16+
}
17+
18+
static inline void adf_pf2vf_wait_for_restarting_complete(struct adf_accel_dev *accel_dev)
19+
{
20+
}
21+
22+
static inline void adf_pf2vf_notify_restarted(struct adf_accel_dev *accel_dev)
23+
{
24+
}
25+
26+
static inline void adf_pf2vf_notify_fatal_error(struct adf_accel_dev *accel_dev)
27+
{
28+
}
29+
#endif
930

1031
typedef int (*adf_pf2vf_blkmsg_provider)(struct adf_accel_dev *accel_dev,
1132
u8 *buffer, u8 compat);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ static int adf_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u8 vf_nr,
291291
vf_info->init = false;
292292
}
293293
break;
294+
case ADF_VF2PF_MSGTYPE_RESTARTING_COMPLETE:
295+
{
296+
dev_dbg(&GET_DEV(accel_dev),
297+
"Restarting Complete received from VF%d\n", vf_nr);
298+
vf_info->restarting = false;
299+
vf_info->init = false;
300+
}
301+
break;
294302
case ADF_VF2PF_MSGTYPE_LARGE_BLOCK_REQ:
295303
case ADF_VF2PF_MSGTYPE_MEDIUM_BLOCK_REQ:
296304
case ADF_VF2PF_MSGTYPE_SMALL_BLOCK_REQ:

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ static bool adf_handle_pf2vf_msg(struct adf_accel_dev *accel_dev,
308308

309309
adf_pf2vf_handle_pf_restarting(accel_dev);
310310
return false;
311+
case ADF_PF2VF_MSGTYPE_RESTARTED:
312+
dev_dbg(&GET_DEV(accel_dev), "Restarted message received from PF\n");
313+
return true;
314+
case ADF_PF2VF_MSGTYPE_FATAL_ERROR:
315+
dev_err(&GET_DEV(accel_dev), "Fatal error received from PF\n");
316+
return true;
311317
case ADF_PF2VF_MSGTYPE_VERSION_RESP:
312318
case ADF_PF2VF_MSGTYPE_BLKMSG_RESP:
313319
case ADF_PF2VF_MSGTYPE_RP_RESET_RESP:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void adf_disable_sriov(struct adf_accel_dev *accel_dev)
103103
return;
104104

105105
adf_pf2vf_notify_restarting(accel_dev);
106+
adf_pf2vf_wait_for_restarting_complete(accel_dev);
106107
pci_disable_sriov(accel_to_pci_dev(accel_dev));
107108

108109
/* Disable VF to PF interrupts */

0 commit comments

Comments
 (0)