Skip to contentSkip to conversation

PCI: Introduce pci_bus_*() printing macros when device is not available

PATCH Superseded Andy Shevchenko 3 participants 6 messages Dec 9, 2021 PCI

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 PCI: Introduce pci_bus_*() printing macros when device is not available

In some cases PCI device structure is not available and we want to print information based on the bus and devfn parameters. For this cases introduce pci_bus_*() printing macros and replace in existing users.

---
v2: split out as a separate patch, added tag (Jean)

Jean, for now it seems overkill to add pci_bus_dbg() since it's not as simple as the rest, it needs a separate full macro with pr_debug() called explicitly
underneath. Hence, I tried and decided not to go until we have enough users.

 drivers/pci/probe.c | 12 +++---------
 include/linux/pci.h |  8 ++++++++
 2 files changed, 11 insertions(+), 9 deletions(-)
drivers/pci/probe.c +3 -9
index 2c91d3509d17..7208901fba70 100644
@@ -2334,16 +2334,12 @@ static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l,
 	 */
 	while (pci_bus_crs_vendor_id(*l)) {
 		if (delay > timeout) {
-			pr_warn("pci %04x:%02x:%02x.%d: not ready after %dms; giving up\n",
-				pci_domain_nr(bus), bus->number,
-				PCI_SLOT(devfn), PCI_FUNC(devfn), delay - 1);
+			pci_bus_warn(bus, devfn, "not ready after %dms; giving up\n", delay - 1);
 
 			return false;
 		}
 		if (delay >= 1000)
-			pr_info("pci %04x:%02x:%02x.%d: not ready after %dms; waiting\n",
-				pci_domain_nr(bus), bus->number,
-				PCI_SLOT(devfn), PCI_FUNC(devfn), delay - 1);
+			pci_bus_info(bus, devfn, "not ready after %dms; waiting\n", delay - 1);
 
 		msleep(delay);
 		delay *= 2;
@@ -2353,9 +2349,7 @@ static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l,
 	}
 
 	if (delay >= 1000)
-		pr_info("pci %04x:%02x:%02x.%d: ready after %dms\n",
-			pci_domain_nr(bus), bus->number,
-			PCI_SLOT(devfn), PCI_FUNC(devfn), delay - 1);
+		pci_bus_info(bus, devfn, "ready after %dms\n", delay - 1);
 
 	return true;
 }
include/linux/pci.h +8 -0
index 0ce26850470e..ea8736077d83 100644
@@ -2482,4 +2482,12 @@ void pci_uevent_ers(struct pci_dev *pdev, enum  pci_ers_result err_type);
 	WARN_ONCE(condition, "%s %s: " fmt, \
 		  dev_driver_string(&(pdev)->dev), pci_name(pdev), ##arg)
 
+#define pci_bus_printk(level, bus, devfn, fmt, arg...) \
+	printk(level "pci %04x:%02x:%02x.%d: " fmt, \
+	       pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##arg)
+
+#define pci_bus_err(bus, devfn, fmt, arg...)	pci_bus_printk(KERN_ERR, bus, devfn, fmt, ##arg)
+#define pci_bus_warn(bus, devfn, fmt, arg...)	pci_bus_printk(KERN_WARNING, bus, devfn, fmt, ##arg)
+#define pci_bus_info(bus, devfn, fmt, arg...)	pci_bus_printk(KERN_INFO, bus, devfn, fmt, ##arg)
+
 #endif /* LINUX_PCI_H */
Signature · 1 line
2.33.0
#1 lore raw
Quoted 3 lines · Andy Shevchenko

In some cases PCI device structure is not available and we want to print information based on the bus and devfn parameters. For this cases introduce pci_bus_*() printing macros and replace in existing users.

[]

include/linux/pci.h

Quoted 1 line
include/linux/pci.h +0 -0

[]

include/linux/pci.h void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type); · line 2487

Quoted 7 lines
include/linux/pci.h +3 -0
@@ -2482,4 +2482,12 @@ void pci_uevent_ers(struct pci_dev *pdev, enum  pci_ers_result err_type);
 	WARN_ONCE(condition, "%s %s: " fmt, \
 		  dev_driver_string(&(pdev)->dev), pci_name(pdev), ##arg)
 
+#define pci_bus_printk(level, bus, devfn, fmt, arg...) \
+	printk(level "pci %04x:%02x:%02x.%d: " fmt, \
+	       pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##arg)

I have a small preference for using ... and __VA_ARGS___

#define pci_bus_printk(level, bus, devfn, fmt, ...) \
	printk(level "pci %04x:%02x:%02x.%d: " fmt, \
	       pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##__VA_ARGS__)

and likely this should have parentheses around bus

	printk(level "pci %04x:%02x:%02x.%d: " fmt, \
	       pci_domain_nr(bus), (bus)->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##__VA_ARGS__)

include/linux/pci.h void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type); · line 2491

Quoted 3 lines
include/linux/pci.h +3 -0
+#define pci_bus_err(bus, devfn, fmt, arg...)	pci_bus_printk(KERN_ERR, bus, devfn, fmt, ##arg)
+#define pci_bus_warn(bus, devfn, fmt, arg...)	pci_bus_printk(KERN_WARNING, bus, devfn, fmt, ##arg)
+#define pci_bus_info(bus, devfn, fmt, arg...)	pci_bus_printk(KERN_INFO, bus, devfn, fmt, ##arg)

__VA_ARGS__ etc...

#2 lore raw
Quoted 1 line · Joe Perches

On Thu, 2021-12-09 at 20:27 +0200, Andy Shevchenko wrote:

...

Quoted 5 lines

include/linux/pci.h void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type); · line 2487

Quoted 3 lines
include/linux/pci.h +3 -0
+#define pci_bus_printk(level, bus, devfn, fmt, arg...) \
+	printk(level "pci %04x:%02x:%02x.%d: " fmt, \
+	       pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##arg)

I have a small preference for using ... and __VA_ARGS___

It contradicts what other macros in the pci.h do.
So I will stick with current solution for the sake of consistency.

...

Quoted 4 lines

and likely this should have parentheses around bus

	printk(level "pci %04x:%02x:%02x.%d: " fmt, \
	       pci_domain_nr(bus), (bus)->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##__VA_ARGS__)

This makes sense, thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 1 line · Joe Perches

On Thu, 2021-12-09 at 20:27 +0200, Andy Shevchenko wrote:

...

Quoted 8 lines
Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+#define pci_bus_printk(level, bus, devfn, fmt, arg...) \
+	printk(level "pci %04x:%02x:%02x.%d: " fmt, \
+	       pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##arg)

I have a small preference for using ... and __VA_ARGS___

It contradicts what other macros in the pci.h do.
So I will stick with current solution for the sake of consistency.

There's always this possibility.

And this: (cheers)

---
 include/linux/pci.h | 58 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 25 deletions(-)
include/linux/pci.h +33 -25
index 0ce26850470ef..1dc34f6eaeda7 100644
@@ -2456,30 +2456,38 @@ void pci_uevent_ers(struct pci_dev *pdev, enum  pci_ers_result err_type);
 /* Provide the legacy pci_dma_* API */
 #include <linux/pci-dma-compat.h>
 
-#define pci_printk(level, pdev, fmt, arg...) \
-	dev_printk(level, &(pdev)->dev, fmt, ##arg)
-
-#define pci_emerg(pdev, fmt, arg...)	dev_emerg(&(pdev)->dev, fmt, ##arg)
-#define pci_alert(pdev, fmt, arg...)	dev_alert(&(pdev)->dev, fmt, ##arg)
-#define pci_crit(pdev, fmt, arg...)	dev_crit(&(pdev)->dev, fmt, ##arg)
-#define pci_err(pdev, fmt, arg...)	dev_err(&(pdev)->dev, fmt, ##arg)
-#define pci_warn(pdev, fmt, arg...)	dev_warn(&(pdev)->dev, fmt, ##arg)
-#define pci_notice(pdev, fmt, arg...)	dev_notice(&(pdev)->dev, fmt, ##arg)
-#define pci_info(pdev, fmt, arg...)	dev_info(&(pdev)->dev, fmt, ##arg)
-#define pci_dbg(pdev, fmt, arg...)	dev_dbg(&(pdev)->dev, fmt, ##arg)
-
-#define pci_notice_ratelimited(pdev, fmt, arg...) \
-	dev_notice_ratelimited(&(pdev)->dev, fmt, ##arg)
-
-#define pci_info_ratelimited(pdev, fmt, arg...) \
-	dev_info_ratelimited(&(pdev)->dev, fmt, ##arg)
-
-#define pci_WARN(pdev, condition, fmt, arg...) \
-	WARN(condition, "%s %s: " fmt, \
-	     dev_driver_string(&(pdev)->dev), pci_name(pdev), ##arg)
-
-#define pci_WARN_ONCE(pdev, condition, fmt, arg...) \
-	WARN_ONCE(condition, "%s %s: " fmt, \
-		  dev_driver_string(&(pdev)->dev), pci_name(pdev), ##arg)
+#define pci_printk(level, pdev, fmt, ...)				\
+	dev_printk(level, &(pdev)->dev, fmt, ##__VA_ARGS__)
+
+#define pci_emerg(pdev, fmt, ...)					\
+	dev_emerg(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_alert(pdev, fmt, ...)					\
+	dev_alert(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_crit(pdev, fmt, ...)					\
+	dev_crit(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_err(pdev, fmt, ...)						\
+	dev_err(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_warn(pdev, fmt, ...)					\
+	dev_warn(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_notice(pdev, fmt, ...)					\
+	dev_notice(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_info(pdev, fmt, ...)					\
+	dev_info(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_dbg(pdev, fmt, ...)						\
+	dev_dbg(&(pdev)->dev, fmt, ##__VA_ARGS__)
+
+#define pci_notice_ratelimited(pdev, fmt, ...)				\
+	dev_notice_ratelimited(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_info_ratelimited(pdev, fmt, ...)				\
+	dev_info_ratelimited(&(pdev)->dev, fmt, ##__VA_ARGS__)
+
+#define pci_WARN(pdev, condition, fmt, ...)				\
+	WARN(condition, "%s %s: " fmt,					\
+	     dev_driver_string(&(pdev)->dev), pci_name(pdev),		\
+	     ##__VA_ARGS__)
+#define pci_WARN_ONCE(pdev, condition, fmt, ...)			\
+	WARN_ONCE(condition, "%s %s: " fmt,				\
+		  dev_driver_string(&(pdev)->dev), pci_name(pdev),	\
+		  ##__VA_ARGS__)
 
 #endif /* LINUX_PCI_H */
#4 lore raw

Hi Andy and Joe,

[...]

Quoted 74 lines
Quoted 8 lines
Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+#define pci_bus_printk(level, bus, devfn, fmt, arg...) \
+	printk(level "pci %04x:%02x:%02x.%d: " fmt, \
+	       pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), ##arg)

I have a small preference for using ... and __VA_ARGS___

It contradicts what other macros in the pci.h do.
So I will stick with current solution for the sake of consistency.

There's always this possibility.

And this: (cheers)

---
 include/linux/pci.h | 58 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 25 deletions(-)
include/linux/pci.h +25 -25
index 0ce26850470ef..1dc34f6eaeda7 100644
@@ -2456,30 +2456,38 @@ void pci_uevent_ers(struct pci_dev *pdev, enum  pci_ers_result err_type);
 /* Provide the legacy pci_dma_* API */
 #include <linux/pci-dma-compat.h>
 
-#define pci_printk(level, pdev, fmt, arg...) \
-	dev_printk(level, &(pdev)->dev, fmt, ##arg)
-
-#define pci_emerg(pdev, fmt, arg...)	dev_emerg(&(pdev)->dev, fmt, ##arg)
-#define pci_alert(pdev, fmt, arg...)	dev_alert(&(pdev)->dev, fmt, ##arg)
-#define pci_crit(pdev, fmt, arg...)	dev_crit(&(pdev)->dev, fmt, ##arg)
-#define pci_err(pdev, fmt, arg...)	dev_err(&(pdev)->dev, fmt, ##arg)
-#define pci_warn(pdev, fmt, arg...)	dev_warn(&(pdev)->dev, fmt, ##arg)
-#define pci_notice(pdev, fmt, arg...)	dev_notice(&(pdev)->dev, fmt, ##arg)
-#define pci_info(pdev, fmt, arg...)	dev_info(&(pdev)->dev, fmt, ##arg)
-#define pci_dbg(pdev, fmt, arg...)	dev_dbg(&(pdev)->dev, fmt, ##arg)
-
-#define pci_notice_ratelimited(pdev, fmt, arg...) \
-	dev_notice_ratelimited(&(pdev)->dev, fmt, ##arg)
-
-#define pci_info_ratelimited(pdev, fmt, arg...) \
-	dev_info_ratelimited(&(pdev)->dev, fmt, ##arg)
-
-#define pci_WARN(pdev, condition, fmt, arg...) \
-	WARN(condition, "%s %s: " fmt, \
-	     dev_driver_string(&(pdev)->dev), pci_name(pdev), ##arg)
-
-#define pci_WARN_ONCE(pdev, condition, fmt, arg...) \
-	WARN_ONCE(condition, "%s %s: " fmt, \
-		  dev_driver_string(&(pdev)->dev), pci_name(pdev), ##arg)
+#define pci_printk(level, pdev, fmt, ...)				\
+	dev_printk(level, &(pdev)->dev, fmt, ##__VA_ARGS__)
+
+#define pci_emerg(pdev, fmt, ...)					\
+	dev_emerg(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_alert(pdev, fmt, ...)					\
+	dev_alert(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_crit(pdev, fmt, ...)					\
+	dev_crit(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_err(pdev, fmt, ...)						\
+	dev_err(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_warn(pdev, fmt, ...)					\
+	dev_warn(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_notice(pdev, fmt, ...)					\
+	dev_notice(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_info(pdev, fmt, ...)					\
+	dev_info(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_dbg(pdev, fmt, ...)						\
+	dev_dbg(&(pdev)->dev, fmt, ##__VA_ARGS__)
+
+#define pci_notice_ratelimited(pdev, fmt, ...)				\
+	dev_notice_ratelimited(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_info_ratelimited(pdev, fmt, ...)				\
+	dev_info_ratelimited(&(pdev)->dev, fmt, ##__VA_ARGS__)
+

include/linux/pci.h void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type); · line 2493

Quoted 10 lines
include/linux/pci.h +8 -0
+#define pci_WARN(pdev, condition, fmt, ...)				\
+	WARN(condition, "%s %s: " fmt,					\
+	     dev_driver_string(&(pdev)->dev), pci_name(pdev),		\
+	     ##__VA_ARGS__)
+#define pci_WARN_ONCE(pdev, condition, fmt, ...)			\
+	WARN_ONCE(condition, "%s %s: " fmt,				\
+		  dev_driver_string(&(pdev)->dev), pci_name(pdev),	\
+		  ##__VA_ARGS__)
 
 #endif /* LINUX_PCI_H */

I think both things look nice!

So perhaps meet in-between here? Two patches in a small series: one adds new useful macros from Andy, and the other updates current macros as per Joe's feedback/preference? I am sure Bjorn wouldn't mind (hopefully).

Krzysztof

#5 lore raw
Quoted 1 line · Krzysztof Wilczyński

Hi Andy and Joe,

...

Quoted 5 lines

I think both things look nice!

So perhaps meet in-between here? Two patches in a small series: one adds new useful macros from Andy, and the other updates current macros as per Joe's feedback/preference? I am sure Bjorn wouldn't mind (hopefully).

Thanks, I agree that these changes should be separated, otherwise I'm fine if pci.h switches to __VA_ARGS__.

Signature · 2 lines
With Best Regards,
Andy Shevchenko