From: Lambert Wang <lambert.q.wang@gmail.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Lambert Wang <lambert.q.wang@gmail.com>
Subject: [PATCH] pci: add pci_dev_is_alive API
Date: Tue, 25 May 2021 20:59:25 +0800 [thread overview]
Message-ID: <20210525125925.112306-1-lambert.q.wang@gmail.com> (raw)
Device drivers use this API to proactively check if the device
is alive or not. It is helpful for some PCI devices to detect
surprise removal and do recovery when Hotplug function is disabled.
Note: Device in power states larger than D0 is also treated not alive
by this function.
Signed-off-by: Lambert Wang <lambert.q.wang@gmail.com>
---
drivers/pci/pci.c | 23 +++++++++++++++++++++++
include/linux/pci.h | 1 +
2 files changed, 24 insertions(+)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b717680377a9..8a7c039b1cd5 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4659,6 +4659,29 @@ int pcie_flr(struct pci_dev *dev)
}
EXPORT_SYMBOL_GPL(pcie_flr);
+/**
+ * pci_dev_is_alive - check the pci device is alive or not
+ * @pdev: the PCI device
+ *
+ * Device drivers use this API to proactively check if the device
+ * is alive or not. It is helpful for some PCI devices to detect
+ * surprise removal and do recovery when Hotplug function is disabled.
+ *
+ * Note: Device in power state larger than D0 is also treated not alive
+ * by this function.
+ *
+ * Returns true if the device is alive.
+ */
+bool pci_dev_is_alive(struct pci_dev *pdev)
+{
+ u16 vendor;
+
+ pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor);
+
+ return vendor == pdev->vendor;
+}
+EXPORT_SYMBOL(pci_dev_is_alive);
+
static int pci_af_flr(struct pci_dev *dev, int probe)
{
int pos;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c20211e59a57..2a3ba06a7347 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1227,6 +1227,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
void pcie_print_link_status(struct pci_dev *dev);
bool pcie_has_flr(struct pci_dev *dev);
int pcie_flr(struct pci_dev *dev);
+bool pci_dev_is_alive(struct pci_dev *pdev);
int __pci_reset_function_locked(struct pci_dev *dev);
int pci_reset_function(struct pci_dev *dev);
int pci_reset_function_locked(struct pci_dev *dev);
--
2.30.2
next reply other threads:[~2021-05-25 13:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-25 12:59 Lambert Wang [this message]
2021-05-25 13:20 ` [PATCH] pci: add pci_dev_is_alive API Krzysztof Wilczyński
2021-05-26 6:12 ` Lambert Wang
2021-05-26 16:23 ` Bjorn Helgaas
2021-05-27 3:43 ` Lambert Wang
2021-05-26 18:18 ` Lukas Wunner
2021-05-27 3:52 ` Lambert Wang
2021-05-25 14:08 ` 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=20210525125925.112306-1-lambert.q.wang@gmail.com \
--to=lambert.q.wang@gmail.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).