From: Mario Limonciello <superm1@kernel.org>
To: Bjorn Helgaas <bhelgaas@google.com>,
Mathias Nyman <mathias.nyman@intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: "open list : PCI SUBSYSTEM" <linux-pci@vger.kernel.org>,
"open list" <linux-kernel@vger.kernel.org>,
"open list : USB XHCI DRIVER" <linux-usb@vger.kernel.org>,
"Daniel Drake" <drake@endlessos.org>, "Gary Li" <Gary.Li@amd.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Mario Limonciello" <mario.limonciello@amd.com>
Subject: [PATCH v5 1/5] PCI: Use an enum for reset type in pci_dev_wait()
Date: Fri, 23 Aug 2024 10:40:19 -0500 [thread overview]
Message-ID: <20240823154023.360234-2-superm1@kernel.org> (raw)
In-Reply-To: <20240823154023.360234-1-superm1@kernel.org>
From: Mario Limonciello <mario.limonciello@amd.com>
A string is passed to all callers of pci_dev_wait() which is utilized
to demonstrate what kind of reset happened when there was a problem.
This doesn't allow making the behavior for different reset types
conditional though. Lay some plumbing to allow making comparisons of
reset types with integers instead. No functional changes.
Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v4->v5:
* Add static assert and PCI_DEV_WAIT_MAX
v3->v4:
* Use index-based array initialization format for pci_reset_types
* Fix LKP reported sparse issue
---
drivers/pci/pci-driver.c | 2 +-
drivers/pci/pci.c | 30 ++++++++++++++++++++----------
drivers/pci/pci.h | 12 +++++++++++-
drivers/pci/pcie/dpc.c | 2 +-
4 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index f412ef73a6e4b..ac3cfbfa137d9 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -572,7 +572,7 @@ static void pci_pm_bridge_power_up_actions(struct pci_dev *pci_dev)
{
int ret;
- ret = pci_bridge_wait_for_secondary_bus(pci_dev, "resume");
+ ret = pci_bridge_wait_for_secondary_bus(pci_dev, PCI_DEV_WAIT_RESUME);
if (ret) {
/*
* The downstream link failed to come up, so mark the
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index ffaaca0978cbc..1e219057a5069 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -181,6 +181,16 @@ static int __init pcie_port_pm_setup(char *str)
}
__setup("pcie_port_pm=", pcie_port_pm_setup);
+static const char * const pci_reset_types[] = {
+ [PCI_DEV_WAIT_FLR] = "FLR",
+ [PCI_DEV_WAIT_AF_FLR] = "AF_FLR",
+ [PCI_DEV_WAIT_D3HOT_D0] = "PM D3HOT->D0",
+ [PCI_DEV_WAIT_BUS_RESET] = "bus reset",
+ [PCI_DEV_WAIT_RESUME] = "resume",
+ [PCI_DEV_WAIT_DPC] = "DPC",
+};
+static_assert(ARRAY_SIZE(pci_reset_types) == PCI_DEV_WAIT_MAX);
+
/**
* pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
* @bus: pointer to PCI bus structure to search
@@ -1279,7 +1289,7 @@ void pci_resume_bus(struct pci_bus *bus)
pci_walk_bus(bus, pci_resume_one, NULL);
}
-static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
+static int pci_dev_wait(struct pci_dev *dev, enum pci_reset_type reset_type, int timeout)
{
int delay = 1;
bool retrain = false;
@@ -1317,7 +1327,7 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
if (delay > timeout) {
pci_warn(dev, "not ready %dms after %s; giving up\n",
- delay - 1, reset_type);
+ delay - 1, pci_reset_types[reset_type]);
return -ENOTTY;
}
@@ -1330,7 +1340,7 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
}
}
pci_info(dev, "not ready %dms after %s; waiting\n",
- delay - 1, reset_type);
+ delay - 1, pci_reset_types[reset_type]);
}
msleep(delay);
@@ -1339,10 +1349,10 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
if (delay > PCI_RESET_WAIT)
pci_info(dev, "ready %dms after %s\n", delay - 1,
- reset_type);
+ pci_reset_types[reset_type]);
else
pci_dbg(dev, "ready %dms after %s\n", delay - 1,
- reset_type);
+ pci_reset_types[reset_type]);
return 0;
}
@@ -4536,7 +4546,7 @@ int pcie_flr(struct pci_dev *dev)
*/
msleep(100);
- return pci_dev_wait(dev, "FLR", PCIE_RESET_READY_POLL_MS);
+ return pci_dev_wait(dev, PCI_DEV_WAIT_FLR, PCIE_RESET_READY_POLL_MS);
}
EXPORT_SYMBOL_GPL(pcie_flr);
@@ -4603,7 +4613,7 @@ static int pci_af_flr(struct pci_dev *dev, bool probe)
*/
msleep(100);
- return pci_dev_wait(dev, "AF_FLR", PCIE_RESET_READY_POLL_MS);
+ return pci_dev_wait(dev, PCI_DEV_WAIT_AF_FLR, PCIE_RESET_READY_POLL_MS);
}
/**
@@ -4648,7 +4658,7 @@ static int pci_pm_reset(struct pci_dev *dev, bool probe)
pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr);
pci_dev_d3_sleep(dev);
- return pci_dev_wait(dev, "PM D3hot->D0", PCIE_RESET_READY_POLL_MS);
+ return pci_dev_wait(dev, PCI_DEV_WAIT_D3HOT_D0, PCIE_RESET_READY_POLL_MS);
}
/**
@@ -4822,7 +4832,7 @@ static int pci_bus_max_d3cold_delay(const struct pci_bus *bus)
* Return 0 on success or -ENOTTY if the first device on the secondary bus
* failed to become accessible.
*/
-int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type)
+int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, enum pci_reset_type reset_type)
{
struct pci_dev *child __free(pci_dev_put) = NULL;
int delay;
@@ -4959,7 +4969,7 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev)
__builtin_return_address(0));
pcibios_reset_secondary_bus(dev);
- return pci_bridge_wait_for_secondary_bus(dev, "bus reset");
+ return pci_bridge_wait_for_secondary_bus(dev, PCI_DEV_WAIT_BUS_RESET);
}
EXPORT_SYMBOL_GPL(pci_bridge_secondary_bus_reset);
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 79c8398f39384..be06c38342c76 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -4,6 +4,16 @@
#include <linux/pci.h>
+enum pci_reset_type {
+ PCI_DEV_WAIT_FLR,
+ PCI_DEV_WAIT_AF_FLR,
+ PCI_DEV_WAIT_D3HOT_D0,
+ PCI_DEV_WAIT_BUS_RESET,
+ PCI_DEV_WAIT_RESUME,
+ PCI_DEV_WAIT_DPC,
+ PCI_DEV_WAIT_MAX,
+};
+
/* Number of possible devfns: 0.0 to 1f.7 inclusive */
#define MAX_NR_DEVFNS 256
@@ -137,7 +147,7 @@ void pci_msi_init(struct pci_dev *dev);
void pci_msix_init(struct pci_dev *dev);
bool pci_bridge_d3_possible(struct pci_dev *dev);
void pci_bridge_d3_update(struct pci_dev *dev);
-int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type);
+int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, enum pci_reset_type reset_type);
static inline void pci_wakeup_event(struct pci_dev *dev)
{
diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c
index 2b6ef7efa3c11..95cd985244729 100644
--- a/drivers/pci/pcie/dpc.c
+++ b/drivers/pci/pcie/dpc.c
@@ -174,7 +174,7 @@ pci_ers_result_t dpc_reset_link(struct pci_dev *pdev)
pci_write_config_word(pdev, cap + PCI_EXP_DPC_STATUS,
PCI_EXP_DPC_STATUS_TRIGGER);
- if (pci_bridge_wait_for_secondary_bus(pdev, "DPC")) {
+ if (pci_bridge_wait_for_secondary_bus(pdev, PCI_DEV_WAIT_DPC)) {
clear_bit(PCI_DPC_RECOVERED, &pdev->priv_flags);
ret = PCI_ERS_RESULT_DISCONNECT;
} else {
--
2.43.0
next prev parent reply other threads:[~2024-08-23 15:40 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-23 15:40 [PATCH v5 0/5] Verify devices transition from D3cold to D0 Mario Limonciello
2024-08-23 15:40 ` Mario Limonciello [this message]
2024-08-23 15:40 ` [PATCH v5 2/5] PCI: Check PCI_PM_CTRL instead of PCI_COMMAND in pci_dev_wait() Mario Limonciello
2024-08-23 19:54 ` Bjorn Helgaas
2024-08-26 19:16 ` Mario Limonciello
2024-08-27 17:43 ` Mario Limonciello
2024-08-27 19:44 ` Bjorn Helgaas
2024-08-30 0:01 ` Bjorn Helgaas
2024-09-03 16:29 ` Mario Limonciello
2024-09-03 17:11 ` Bjorn Helgaas
2024-09-03 17:31 ` Mario Limonciello
2024-09-03 18:25 ` Bjorn Helgaas
2024-09-03 18:32 ` Mario Limonciello
2024-09-03 21:32 ` Bjorn Helgaas
2024-09-04 12:05 ` Mika Westerberg
2024-09-04 15:24 ` Mario Limonciello
2024-09-05 9:33 ` Mika Westerberg
2024-09-09 20:40 ` Mario Limonciello
2024-09-10 9:13 ` Mika Westerberg
2024-09-13 4:12 ` Mario Limonciello
2024-09-13 4:58 ` Mika Westerberg
2024-09-13 7:23 ` Mika Westerberg
2024-09-13 20:56 ` Mario Limonciello
2024-09-15 7:07 ` Mika Westerberg
2024-08-23 15:40 ` [PATCH v5 3/5] PCI: Verify functions currently in D3cold have entered D0 Mario Limonciello
2024-08-23 15:40 ` [PATCH v5 4/5] PCI: Allow Ryzen XHCI controllers into D3cold and drop delays Mario Limonciello
2024-08-23 15:40 ` [PATCH v5 5/5] PCI: Drop Radeon quirk for Macbook Pro 8.2 Mario Limonciello
2024-12-04 17:30 ` [PATCH v5 0/5] Verify devices transition from D3cold to D0 Mario Limonciello
2024-12-04 23:45 ` Bjorn Helgaas
2024-12-05 3:44 ` Mario Limonciello
2024-12-05 18:12 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240823154023.360234-2-superm1@kernel.org \
--to=superm1@kernel.org \
--cc=Gary.Li@amd.com \
--cc=bhelgaas@google.com \
--cc=drake@endlessos.org \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=mathias.nyman@intel.com \
--cc=mika.westerberg@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.