@@ -359,39 +359,31 @@ struct pci_sriov {
static inline bool pci_dev_set_io_state(struct pci_dev *dev,
pci_channel_state_t new)
{
- bool changed = false;
-
device_lock_assert(&dev->dev);
- switch (new) {
- case pci_channel_io_perm_failure:
- switch (dev->error_state) {
- case pci_channel_io_frozen:
- case pci_channel_io_normal:
- case pci_channel_io_perm_failure:
- changed = true;
- break;
- }
- break;
- case pci_channel_io_frozen:
- switch (dev->error_state) {
- case pci_channel_io_frozen:
- case pci_channel_io_normal:
- changed = true;
- break;
- }
- break;
- case pci_channel_io_normal:
- switch (dev->error_state) {
- case pci_channel_io_frozen:
- case pci_channel_io_normal:
- changed = true;
- break;
- }
- break;
+/*
+ * Truth table:
+ * requested new state
+ * current ------------------------------------------
+ * state normal frozen perm_failure
+ * ------------ + ------------- ------------- ------------
+ * normal | normal frozen perm_failure
+ * frozen | normal frozen perm_failure
+ * perm_failure | perm_failure* perm_failure* perm_failure
+ */
+
+ /* Can always put a device in perm_failure state */
+ if (new == pci_channel_io_perm_failure) {
+ dev->error_state = pci_channel_io_perm_failure;
+ return true;
}
- if (changed)
- dev->error_state = new;
- return changed;
+
+ /* If already in perm_failure, can't set to normal or frozen */
+ if (dev->error_state == pci_channel_io_perm_failure)
+ return false;
+
+ /* Can always change normal to frozen or vice versa */
+ dev->error_state = new;
+ return true;
}
static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
No function change. Signed-off-by: Ethan Zhao <haifeng.zhao@intel.com> --- Changes: v8: based on Bjorn's code and truth table, simplify the logic of function pci_dev_set_io_state(), no function change. drivers/pci/pci.h | 54 ++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 31 deletions(-)