diff mbox series

[RFC,v1,2/3] PCI: Add options to pci_reset_function

Message ID 20181019032345.5791-2-okaya@kernel.org
State Changes Requested
Delegated to: Bjorn Helgaas
Headers show
Series [RFC,v1,1/3] PCI: Unify pci_reset_function_locked() and __pci_reset_function_locked() | expand

Commit Message

Sinan Kaya Oct. 19, 2018, 3:23 a.m. UTC
Getting ready to deprecate pci_reset_function_locked(). Add
saverestore and locked parameters to pci_reset_function() function
and add saverestore = true and locked = false to all existing
callers.

Signed-off-by: Sinan Kaya <okaya@kernel.org>
---
 drivers/pci/pci.c   | 14 ++++++++++----
 include/linux/pci.h |  4 ++++
 2 files changed, 14 insertions(+), 4 deletions(-)

Comments

Sinan Kaya Oct. 19, 2018, 3:28 a.m. UTC | #1
On 10/18/2018 11:23 PM, Sinan Kaya wrote:
> Getting ready to deprecate pci_reset_function_locked(). Add
> saverestore and locked parameters to pci_reset_function() function
> and add saverestore = true and locked = false to all existing
> callers.

I realized that I forgot to update the commit text but this is a follow up
to this conversation per Christoph's request.

https://patchwork.kernel.org/patch/10636071/

Since Alex didn't like the idea much, I also split the API reduction work
out of the original reset API refactoring work and sent as an RFC.
diff mbox series

Patch

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index ccd69f5d01f3..17b10c33cb53 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4819,13 +4819,19 @@  int pci_reset_function(struct pci_dev *dev, u32 reset_type)
 	if (!dev->reset_fn)
 		return -ENOTTY;
 
-	pci_dev_lock(dev);
-	pci_dev_save_and_disable(dev);
+	if (!(reset_type & PCI_RESET_ALREADYLOCKED))
+		pci_dev_lock(dev);
+
+	if (!(reset_type & PCI_RESET_NOSAVERESTORE))
+		pci_dev_save_and_disable(dev);
 
 	rc = __pci_reset_function_locked(dev, reset_type);
 
-	pci_dev_restore(dev);
-	pci_dev_unlock(dev);
+	if (!(reset_type & PCI_RESET_NOSAVERESTORE))
+		pci_dev_restore(dev);
+
+	if (!(reset_type & PCI_RESET_ALREADYLOCKED))
+		pci_dev_unlock(dev);
 
 	return rc;
 }
diff --git a/include/linux/pci.h b/include/linux/pci.h
index fedd34a5af77..ad5996d521eb 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -896,6 +896,9 @@  enum {
  *
  * PCI_RESET_NOSAVERESTORE tells the PCI core to not save the card context
  * before performing a reset and restore the values after reset.
+ *
+ * PCI_RESET_ALREADYLOCKED indicates that caller is holding the device lock and
+ * PCI core should not try to lock again.
  */
 #define PCI_RESET_DEV_SPECIFIC	(1 << 0)
 #define PCI_RESET_FLR		(1 << 1)
@@ -903,6 +906,7 @@  enum {
 #define PCI_RESET_SLOT		(1 << 3)
 #define PCI_RESET_BUS		(1 << 4)
 #define PCI_RESET_NOSAVERESTORE (1 << 5)
+#define PCI_RESET_ALREADYLOCKED (1 << 6)
 
 #define PCI_RESET_FUNC		(PCI_RESET_DEV_SPECIFIC | \
 				 PCI_RESET_FLR | PCI_RESET_PM)