|
1 | 1 | // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) |
2 | 2 | /* Copyright(c) 2015 - 2021 Intel Corporation */ |
| 3 | +#include <linux/delay.h> |
3 | 4 | #include <linux/pci.h> |
4 | 5 | #include "adf_accel_devices.h" |
5 | 6 | #include "adf_pfvf_msg.h" |
6 | 7 | #include "adf_pfvf_pf_msg.h" |
7 | 8 | #include "adf_pfvf_pf_proto.h" |
8 | 9 |
|
| 10 | +#define ADF_PF_WAIT_RESTARTING_COMPLETE_DELAY 100 |
| 11 | +#define ADF_VF_SHUTDOWN_RETRY 100 |
| 12 | + |
9 | 13 | void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev) |
10 | 14 | { |
11 | 15 | struct adf_accel_vf_info *vf; |
12 | 16 | struct pfvf_message msg = { .type = ADF_PF2VF_MSGTYPE_RESTARTING }; |
13 | 17 | int i, num_vfs = pci_num_vf(accel_to_pci_dev(accel_dev)); |
14 | 18 |
|
| 19 | + dev_dbg(&GET_DEV(accel_dev), "pf2vf notify restarting\n"); |
15 | 20 | 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)) |
17 | 25 | dev_err(&GET_DEV(accel_dev), |
18 | 26 | "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); |
19 | 81 | } |
20 | 82 | } |
21 | 83 |
|
|
0 commit comments