diff mbox series

[v2] PCI: Factor functions of PCI function reset

Message ID 1616145918-31356-1-git-send-email-yangyicong@hisilicon.com (mailing list archive)
State Not Applicable
Delegated to: Bjorn Helgaas
Headers show
Series [v2] PCI: Factor functions of PCI function reset | expand

Commit Message

Yicong Yang March 19, 2021, 9:25 a.m. UTC
Previously we used pci_probe_reset_function() to probe whether a function
can be reset and use __pci_reset_function_locked() to perform a function
reset. These two functions have lots of common lines.

Factor the two functions and reduce the redundancy.

Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
Change since v1:
- reword the comments a bit(Krzysztof)
- fix typos in the commit(Bjorn)
Link: https://lore.kernel.org/linux-pci/1605090123-14243-1-git-send-email-yangyicong@hisilicon.com/

 drivers/pci/pci.c   | 62 ++++++++++++++++-------------------------------------
 drivers/pci/pci.h   |  2 +-
 drivers/pci/probe.c |  2 +-
 3 files changed, 21 insertions(+), 45 deletions(-)

Comments

Krzysztof Wilczyński March 19, 2021, 5:09 p.m. UTC | #1
[+cc Amey as he is workingo on a larger refactor of the reset functions]

Hi,

> Previously we used pci_probe_reset_function() to probe whether a function
> can be reset and use __pci_reset_function_locked() to perform a function
> reset. These two functions have lots of common lines.
> 
> Factor the two functions and reduce the redundancy.
[...]

I wanted to bring the following thread to your attention as you are
working on the same code that it's being talked about there in the
on-going conversation, see:

  https://lore.kernel.org/linux-pci/20210312173452.3855-1-ameynarkhede03@gmail.com/

I wonder if there would be some overlap, etc.

Krzysztof
Yicong Yang March 22, 2021, 11:56 a.m. UTC | #2
Hi Krzysztof,

On 2021/3/20 1:09, Krzysztof Wilczyński wrote:
> [+cc Amey as he is workingo on a larger refactor of the reset functions]
> 
> Hi,
> 
>> Previously we used pci_probe_reset_function() to probe whether a function
>> can be reset and use __pci_reset_function_locked() to perform a function
>> reset. These two functions have lots of common lines.
>>
>> Factor the two functions and reduce the redundancy.
> [...]
> 
> I wanted to bring the following thread to your attention as you are
> working on the same code that it's being talked about there in the
> on-going conversation, see:
> 
>   https://lore.kernel.org/linux-pci/20210312173452.3855-1-ameynarkhede03@gmail.com/
> 
> I wonder if there would be some overlap, etc.

thanks for the reminder. i roughly look through Amey's series and i think this little
refactor is unnecessary anymore. i'll follow on that series and i may need a further
understanding.

Thanks,
Yicong

> 
> Krzysztof
> 
> .
>
diff mbox series

Patch

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 16a1721..254bbe9 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5055,9 +5055,11 @@  static void pci_dev_restore(struct pci_dev *dev)
 }
 
 /**
- * __pci_reset_function_locked - reset a PCI device function while holding
- * the @dev mutex lock.
+ * pci_probe_reset_function - check whether the device can be safely reset
+ *                            or reset a PCI device function while holding
+ *                            the @dev mutex lock.
  * @dev: PCI device to reset
+ * @probe: Probe or not whether the device can be reset.
  *
  * Some devices allow an individual function to be reset without affecting
  * other functions in the same device.  The PCI device must be responsive
@@ -5071,10 +5073,11 @@  static void pci_dev_restore(struct pci_dev *dev)
  * device including MSI, bus mastering, BARs, decoding IO and memory spaces,
  * etc.
  *
- * Returns 0 if the device function was successfully reset or negative if the
- * device doesn't support resetting a single function.
+ * Returns 0 if the device function can be reset or was successfully
+ * reset, otherwise negative if the device doesn't support resetting
+ * a single function.
  */
-int __pci_reset_function_locked(struct pci_dev *dev)
+int pci_probe_reset_function(struct pci_dev *dev, int probe)
 {
 	int rc;
 
@@ -5088,61 +5091,34 @@  int __pci_reset_function_locked(struct pci_dev *dev)
 	 * other error, we're also finished: this indicates that further
 	 * reset mechanisms might be broken on the device.
 	 */
-	rc = pci_dev_specific_reset(dev, 0);
+	rc = pci_dev_specific_reset(dev, probe);
 	if (rc != -ENOTTY)
 		return rc;
 	if (pcie_has_flr(dev)) {
+		if (probe)
+			return 0;
 		rc = pcie_flr(dev);
 		if (rc != -ENOTTY)
 			return rc;
 	}
-	rc = pci_af_flr(dev, 0);
+	rc = pci_af_flr(dev, probe);
 	if (rc != -ENOTTY)
 		return rc;
-	rc = pci_pm_reset(dev, 0);
+	rc = pci_pm_reset(dev, probe);
 	if (rc != -ENOTTY)
 		return rc;
-	rc = pci_dev_reset_slot_function(dev, 0);
+	rc = pci_dev_reset_slot_function(dev, probe);
 	if (rc != -ENOTTY)
 		return rc;
-	return pci_parent_bus_reset(dev, 0);
+
+	return pci_parent_bus_reset(dev, probe);
 }
-EXPORT_SYMBOL_GPL(__pci_reset_function_locked);
 
-/**
- * pci_probe_reset_function - check whether the device can be safely reset
- * @dev: PCI device to reset
- *
- * Some devices allow an individual function to be reset without affecting
- * other functions in the same device.  The PCI device must be responsive
- * to PCI config space in order to use this function.
- *
- * Returns 0 if the device function can be reset or negative if the
- * device doesn't support resetting a single function.
- */
-int pci_probe_reset_function(struct pci_dev *dev)
+int __pci_reset_function_locked(struct pci_dev *dev)
 {
-	int rc;
-
-	might_sleep();
-
-	rc = pci_dev_specific_reset(dev, 1);
-	if (rc != -ENOTTY)
-		return rc;
-	if (pcie_has_flr(dev))
-		return 0;
-	rc = pci_af_flr(dev, 1);
-	if (rc != -ENOTTY)
-		return rc;
-	rc = pci_pm_reset(dev, 1);
-	if (rc != -ENOTTY)
-		return rc;
-	rc = pci_dev_reset_slot_function(dev, 1);
-	if (rc != -ENOTTY)
-		return rc;
-
-	return pci_parent_bus_reset(dev, 1);
+	return pci_probe_reset_function(dev, 0);
 }
+EXPORT_SYMBOL_GPL(__pci_reset_function_locked);
 
 /**
  * pci_reset_function - quiesce and reset a PCI device function
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index ef7c466..f349d48 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -39,7 +39,7 @@  enum pci_mmap_api {
 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai,
 		  enum pci_mmap_api mmap_api);
 
-int pci_probe_reset_function(struct pci_dev *dev);
+int pci_probe_reset_function(struct pci_dev *dev, int probe);
 int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
 int pci_bus_error_reset(struct pci_dev *dev);
 
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 953f15a..cc0c21d 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2404,7 +2404,7 @@  static void pci_init_capabilities(struct pci_dev *dev)
 
 	pcie_report_downtraining(dev);
 
-	if (pci_probe_reset_function(dev) == 0)
+	if (pci_probe_reset_function(dev, 1) == 0)
 		dev->reset_fn = 1;
 }