commit e67e5df45eba40e730081af812cc0d27f08a28fe Author: Laurent Vivier Date: Mon Feb 8 03:29:47 2021 -0500 Revert 80696f991424d05a784c0cf9c314ac09ac280406 Signed-off-by: Laurent Vivier diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h index 4fd200d8b0a9..0c1d000fd28a 100644 --- a/drivers/pci/hotplug/pciehp.h +++ b/drivers/pci/hotplug/pciehp.h @@ -172,9 +172,8 @@ void pciehp_get_power_status(struct controller *ctrl, u8 *status); void pciehp_set_indicators(struct controller *ctrl, int pwr, int attn); void pciehp_get_latch_status(struct controller *ctrl, u8 *status); +void pciehp_get_adapter_status(struct controller *ctrl, u8 *status); int pciehp_query_power_fault(struct controller *ctrl); -int pciehp_card_present(struct controller *ctrl); -int pciehp_card_present_or_link_active(struct controller *ctrl); int pciehp_check_link_status(struct controller *ctrl); int pciehp_check_link_active(struct controller *ctrl); void pciehp_release_ctrl(struct controller *ctrl); diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c index ad3393930ecb..00042735ceeb 100644 --- a/drivers/pci/hotplug/pciehp_core.c +++ b/drivers/pci/hotplug/pciehp_core.c @@ -139,15 +139,10 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value) { struct controller *ctrl = to_ctrl(hotplug_slot); struct pci_dev *pdev = ctrl->pcie->port; - int ret; pci_config_pm_runtime_get(pdev); - ret = pciehp_card_present_or_link_active(ctrl); + pciehp_get_adapter_status(ctrl, value); pci_config_pm_runtime_put(pdev); - if (ret < 0) - return ret; - - *value = ret; return 0; } @@ -164,12 +159,12 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value) */ static void pciehp_check_presence(struct controller *ctrl) { - int occupied; + u8 occupied; down_read(&ctrl->reset_lock); mutex_lock(&ctrl->state_lock); - occupied = pciehp_card_present_or_link_active(ctrl); + pciehp_get_adapter_status(ctrl, &occupied); if ((occupied > 0 && (ctrl->state == OFF_STATE || ctrl->state == BLINKINGON_STATE)) || (!occupied && (ctrl->state == ON_STATE || diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c index 529c34808440..03d5054b6035 100644 --- a/drivers/pci/hotplug/pciehp_ctrl.c +++ b/drivers/pci/hotplug/pciehp_ctrl.c @@ -224,7 +224,8 @@ void pciehp_handle_disable_request(struct controller *ctrl) void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) { - int present, link_active; + u8 present; + int link_active; /* * If the slot is on and presence or link has changed, turn it off. @@ -253,9 +254,9 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) /* Turn the slot on if it's occupied or link is up */ mutex_lock(&ctrl->state_lock); - present = pciehp_card_present(ctrl); + pciehp_get_adapter_status(ctrl, &present); link_active = pciehp_check_link_active(ctrl); - if (present <= 0 && link_active <= 0) { + if (!present && link_active <= 0) { mutex_unlock(&ctrl->state_lock); return; } diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index fb3840e222ad..8e76a028fa30 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -424,31 +424,6 @@ void pciehp_get_latch_status(struct controller *ctrl, u8 *status) *status = !!(slot_status & PCI_EXP_SLTSTA_MRLSS); } -/** - * pciehp_card_present() - Is the card present - * @ctrl: PCIe hotplug controller - * - * Function checks whether the card is currently present in the slot and - * in that case returns true. Note it is possible that the card is - * removed immediately after the check so the caller may need to take - * this into account. - * - * It the hotplug controller itself is not available anymore returns - * %-ENODEV. - */ -int pciehp_card_present(struct controller *ctrl) -{ - struct pci_dev *pdev = ctrl_dev(ctrl); - u16 slot_status; - int ret; - - ret = pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); - if (ret == PCIBIOS_DEVICE_NOT_FOUND || slot_status == (u16)~0) - return -ENODEV; - - return !!(slot_status & PCI_EXP_SLTSTA_PDS); -} - /** * pciehp_card_present_or_link_active() - whether given slot is occupied * @ctrl: PCIe hotplug controller @@ -461,15 +436,13 @@ int pciehp_card_present(struct controller *ctrl) * Returns: %1 if the slot is occupied and %0 if it is not. If the hotplug * port is not present anymore returns %-ENODEV. */ -int pciehp_card_present_or_link_active(struct controller *ctrl) +void pciehp_get_adapter_status(struct controller *ctrl, u8 *status) { - int ret; - - ret = pciehp_card_present(ctrl); - if (ret) - return ret; + struct pci_dev *pdev = ctrl_dev(ctrl); + u16 slot_status; - return pciehp_check_link_active(ctrl); + pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); + *status = !!(slot_status & PCI_EXP_SLTSTA_PDS); } int pciehp_query_power_fault(struct controller *ctrl) @@ -904,7 +877,7 @@ struct controller *pcie_init(struct pcie_device *dev) { struct controller *ctrl; u32 slot_cap, slot_cap2, link_cap; - u8 poweron; + u8 occupied, poweron; struct pci_dev *pdev = dev->port; struct pci_bus *subordinate = pdev->subordinate; @@ -977,8 +950,9 @@ struct controller *pcie_init(struct pcie_device *dev) * requested yet, so avoid triggering a notification with this command. */ if (POWER_CTRL(ctrl)) { + pciehp_get_adapter_status(ctrl, &occupied); pciehp_get_power_status(ctrl, &poweron); - if (!pciehp_card_present_or_link_active(ctrl) && poweron) { + if (!occupied && poweron) { pcie_disable_notification(ctrl); pciehp_power_off_slot(ctrl); }