* [PATCH 1/3] PCI: Use header type defines in pci_setup_device()
@ 2025-06-10 10:58 Ilpo Järvinen
2025-06-10 10:58 ` [PATCH 2/3] PCI: Cleanup early_dump_pci_device() Ilpo Järvinen
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Ilpo Järvinen @ 2025-06-10 10:58 UTC (permalink / raw)
To: Krzysztof Wilczyński, Bjorn Helgaas, linux-pci, linux-kernel
Cc: Ilpo Järvinen
Replace literals with PCI_HEADER_TYPE_* defines in pci_setup_device().
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/probe.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 4b8693ec9e4c..c00634e5a2ed 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1985,8 +1985,8 @@ int pci_setup_device(struct pci_dev *dev)
dev->sysdata = dev->bus->sysdata;
dev->dev.parent = dev->bus->bridge;
dev->dev.bus = &pci_bus_type;
- dev->hdr_type = hdr_type & 0x7f;
- dev->multifunction = !!(hdr_type & 0x80);
+ dev->hdr_type = FIELD_GET(PCI_HEADER_TYPE_MASK, hdr_type);
+ dev->multifunction = FIELD_GET(PCI_HEADER_TYPE_MFD, hdr_type);
dev->error_state = pci_channel_io_normal;
set_pcie_port_type(dev);
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] PCI: Cleanup early_dump_pci_device()
2025-06-10 10:58 [PATCH 1/3] PCI: Use header type defines in pci_setup_device() Ilpo Järvinen
@ 2025-06-10 10:58 ` Ilpo Järvinen
2025-06-10 14:26 ` Sathyanarayanan Kuppuswamy
2025-06-10 10:58 ` [PATCH 3/3] PCI: Cleanup pci_scan_child_bus_extend() loop Ilpo Järvinen
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Ilpo Järvinen @ 2025-06-10 10:58 UTC (permalink / raw)
To: Krzysztof Wilczyński, Bjorn Helgaas, linux-pci, linux-kernel
Cc: Ilpo Järvinen
Convert 256 to PCI_CFG_SPACE_SIZE and 4 to sizeof(u32) and
avoid i / 4 construct by changing the iteration.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/probe.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c00634e5a2ed..f08e754c404b 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -3,6 +3,7 @@
* PCI detection and setup code
*/
+#include <linux/array_size.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/init.h>
@@ -1912,16 +1913,16 @@ static int pci_intx_mask_broken(struct pci_dev *dev)
static void early_dump_pci_device(struct pci_dev *pdev)
{
- u32 value[256 / 4];
+ u32 value[PCI_CFG_SPACE_SIZE / sizeof(u32)];
int i;
pci_info(pdev, "config space:\n");
- for (i = 0; i < 256; i += 4)
- pci_read_config_dword(pdev, i, &value[i / 4]);
+ for (i = 0; i < ARRAY_SIZE(value); i++)
+ pci_read_config_dword(pdev, i * sizeof(u32), &value[i]);
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1,
- value, 256, false);
+ value, ARRAY_SIZE(value) * sizeof(u32), false);
}
static const char *pci_type_str(struct pci_dev *dev)
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] PCI: Cleanup pci_scan_child_bus_extend() loop
2025-06-10 10:58 [PATCH 1/3] PCI: Use header type defines in pci_setup_device() Ilpo Järvinen
2025-06-10 10:58 ` [PATCH 2/3] PCI: Cleanup early_dump_pci_device() Ilpo Järvinen
@ 2025-06-10 10:58 ` Ilpo Järvinen
2025-06-10 14:28 ` Sathyanarayanan Kuppuswamy
2025-06-10 14:26 ` [PATCH 1/3] PCI: Use header type defines in pci_setup_device() Sathyanarayanan Kuppuswamy
2025-08-06 22:56 ` Bjorn Helgaas
3 siblings, 1 reply; 7+ messages in thread
From: Ilpo Järvinen @ 2025-06-10 10:58 UTC (permalink / raw)
To: Krzysztof Wilczyński, Bjorn Helgaas, linux-pci, linux-kernel
Cc: Ilpo Järvinen
pci_scan_child_bus_extend() open-codes device number iteration in the
for loop. Convert to use PCI_DEVFN() and add PCI_MAX_NR_DEVS (there
seems to be no pre-existing defines for this purpose).
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/pci.h | 1 +
drivers/pci/probe.c | 6 +++---
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 12215ee72afb..caa6e02a9aea 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -8,6 +8,7 @@ struct pcie_tlp_log;
/* Number of possible devfns: 0.0 to 1f.7 inclusive */
#define MAX_NR_DEVFNS 256
+#define PCI_MAX_NR_DEVS 32
#define MAX_NR_LANES 16
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index f08e754c404b..963cab481327 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -3029,14 +3029,14 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
{
unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0;
unsigned int start = bus->busn_res.start;
- unsigned int devfn, cmax, max = start;
+ unsigned int devnr, cmax, max = start;
struct pci_dev *dev;
dev_dbg(&bus->dev, "scanning bus\n");
/* Go find them, Rover! */
- for (devfn = 0; devfn < 256; devfn += 8)
- pci_scan_slot(bus, devfn);
+ for (devnr = 0; devnr < PCI_MAX_NR_DEVS; devnr++)
+ pci_scan_slot(bus, PCI_DEVFN(devnr, 0));
/* Reserve buses for SR-IOV capability */
used_buses = pci_iov_bus_range(bus);
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] PCI: Use header type defines in pci_setup_device()
2025-06-10 10:58 [PATCH 1/3] PCI: Use header type defines in pci_setup_device() Ilpo Järvinen
2025-06-10 10:58 ` [PATCH 2/3] PCI: Cleanup early_dump_pci_device() Ilpo Järvinen
2025-06-10 10:58 ` [PATCH 3/3] PCI: Cleanup pci_scan_child_bus_extend() loop Ilpo Järvinen
@ 2025-06-10 14:26 ` Sathyanarayanan Kuppuswamy
2025-08-06 22:56 ` Bjorn Helgaas
3 siblings, 0 replies; 7+ messages in thread
From: Sathyanarayanan Kuppuswamy @ 2025-06-10 14:26 UTC (permalink / raw)
To: Ilpo Järvinen, Krzysztof Wilczyński, Bjorn Helgaas,
linux-pci, linux-kernel
On 6/10/25 3:58 AM, Ilpo Järvinen wrote:
> Replace literals with PCI_HEADER_TYPE_* defines in pci_setup_device().
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> drivers/pci/probe.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 4b8693ec9e4c..c00634e5a2ed 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -1985,8 +1985,8 @@ int pci_setup_device(struct pci_dev *dev)
> dev->sysdata = dev->bus->sysdata;
> dev->dev.parent = dev->bus->bridge;
> dev->dev.bus = &pci_bus_type;
> - dev->hdr_type = hdr_type & 0x7f;
> - dev->multifunction = !!(hdr_type & 0x80);
> + dev->hdr_type = FIELD_GET(PCI_HEADER_TYPE_MASK, hdr_type);
> + dev->multifunction = FIELD_GET(PCI_HEADER_TYPE_MFD, hdr_type);
> dev->error_state = pci_channel_io_normal;
> set_pcie_port_type(dev);
>
>
> base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] PCI: Cleanup early_dump_pci_device()
2025-06-10 10:58 ` [PATCH 2/3] PCI: Cleanup early_dump_pci_device() Ilpo Järvinen
@ 2025-06-10 14:26 ` Sathyanarayanan Kuppuswamy
0 siblings, 0 replies; 7+ messages in thread
From: Sathyanarayanan Kuppuswamy @ 2025-06-10 14:26 UTC (permalink / raw)
To: Ilpo Järvinen, Krzysztof Wilczyński, Bjorn Helgaas,
linux-pci, linux-kernel
On 6/10/25 3:58 AM, Ilpo Järvinen wrote:
> Convert 256 to PCI_CFG_SPACE_SIZE and 4 to sizeof(u32) and
> avoid i / 4 construct by changing the iteration.
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> drivers/pci/probe.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index c00634e5a2ed..f08e754c404b 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -3,6 +3,7 @@
> * PCI detection and setup code
> */
>
> +#include <linux/array_size.h>
> #include <linux/kernel.h>
> #include <linux/delay.h>
> #include <linux/init.h>
> @@ -1912,16 +1913,16 @@ static int pci_intx_mask_broken(struct pci_dev *dev)
>
> static void early_dump_pci_device(struct pci_dev *pdev)
> {
> - u32 value[256 / 4];
> + u32 value[PCI_CFG_SPACE_SIZE / sizeof(u32)];
> int i;
>
> pci_info(pdev, "config space:\n");
>
> - for (i = 0; i < 256; i += 4)
> - pci_read_config_dword(pdev, i, &value[i / 4]);
> + for (i = 0; i < ARRAY_SIZE(value); i++)
> + pci_read_config_dword(pdev, i * sizeof(u32), &value[i]);
>
> print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1,
> - value, 256, false);
> + value, ARRAY_SIZE(value) * sizeof(u32), false);
> }
>
> static const char *pci_type_str(struct pci_dev *dev)
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] PCI: Cleanup pci_scan_child_bus_extend() loop
2025-06-10 10:58 ` [PATCH 3/3] PCI: Cleanup pci_scan_child_bus_extend() loop Ilpo Järvinen
@ 2025-06-10 14:28 ` Sathyanarayanan Kuppuswamy
0 siblings, 0 replies; 7+ messages in thread
From: Sathyanarayanan Kuppuswamy @ 2025-06-10 14:28 UTC (permalink / raw)
To: Ilpo Järvinen, Krzysztof Wilczyński, Bjorn Helgaas,
linux-pci, linux-kernel
On 6/10/25 3:58 AM, Ilpo Järvinen wrote:
> pci_scan_child_bus_extend() open-codes device number iteration in the
> for loop. Convert to use PCI_DEVFN() and add PCI_MAX_NR_DEVS (there
> seems to be no pre-existing defines for this purpose).
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> drivers/pci/pci.h | 1 +
> drivers/pci/probe.c | 6 +++---
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 12215ee72afb..caa6e02a9aea 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -8,6 +8,7 @@ struct pcie_tlp_log;
>
> /* Number of possible devfns: 0.0 to 1f.7 inclusive */
> #define MAX_NR_DEVFNS 256
> +#define PCI_MAX_NR_DEVS 32
>
> #define MAX_NR_LANES 16
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index f08e754c404b..963cab481327 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -3029,14 +3029,14 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
> {
> unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0;
> unsigned int start = bus->busn_res.start;
> - unsigned int devfn, cmax, max = start;
> + unsigned int devnr, cmax, max = start;
> struct pci_dev *dev;
>
> dev_dbg(&bus->dev, "scanning bus\n");
>
> /* Go find them, Rover! */
> - for (devfn = 0; devfn < 256; devfn += 8)
> - pci_scan_slot(bus, devfn);
> + for (devnr = 0; devnr < PCI_MAX_NR_DEVS; devnr++)
> + pci_scan_slot(bus, PCI_DEVFN(devnr, 0));
>
> /* Reserve buses for SR-IOV capability */
> used_buses = pci_iov_bus_range(bus);
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] PCI: Use header type defines in pci_setup_device()
2025-06-10 10:58 [PATCH 1/3] PCI: Use header type defines in pci_setup_device() Ilpo Järvinen
` (2 preceding siblings ...)
2025-06-10 14:26 ` [PATCH 1/3] PCI: Use header type defines in pci_setup_device() Sathyanarayanan Kuppuswamy
@ 2025-08-06 22:56 ` Bjorn Helgaas
3 siblings, 0 replies; 7+ messages in thread
From: Bjorn Helgaas @ 2025-08-06 22:56 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Krzysztof Wilczyński, Bjorn Helgaas, linux-pci, linux-kernel
On Tue, Jun 10, 2025 at 01:58:18PM +0300, Ilpo Järvinen wrote:
> Replace literals with PCI_HEADER_TYPE_* defines in pci_setup_device().
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
All three applied to pci/enumeration for v6.18, thanks!
> ---
> drivers/pci/probe.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 4b8693ec9e4c..c00634e5a2ed 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -1985,8 +1985,8 @@ int pci_setup_device(struct pci_dev *dev)
> dev->sysdata = dev->bus->sysdata;
> dev->dev.parent = dev->bus->bridge;
> dev->dev.bus = &pci_bus_type;
> - dev->hdr_type = hdr_type & 0x7f;
> - dev->multifunction = !!(hdr_type & 0x80);
> + dev->hdr_type = FIELD_GET(PCI_HEADER_TYPE_MASK, hdr_type);
> + dev->multifunction = FIELD_GET(PCI_HEADER_TYPE_MFD, hdr_type);
> dev->error_state = pci_channel_io_normal;
> set_pcie_port_type(dev);
>
>
> base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
> --
> 2.39.5
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-08-06 22:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-10 10:58 [PATCH 1/3] PCI: Use header type defines in pci_setup_device() Ilpo Järvinen
2025-06-10 10:58 ` [PATCH 2/3] PCI: Cleanup early_dump_pci_device() Ilpo Järvinen
2025-06-10 14:26 ` Sathyanarayanan Kuppuswamy
2025-06-10 10:58 ` [PATCH 3/3] PCI: Cleanup pci_scan_child_bus_extend() loop Ilpo Järvinen
2025-06-10 14:28 ` Sathyanarayanan Kuppuswamy
2025-06-10 14:26 ` [PATCH 1/3] PCI: Use header type defines in pci_setup_device() Sathyanarayanan Kuppuswamy
2025-08-06 22:56 ` Bjorn Helgaas
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).