* [PATCH v3 1/2] PCI: add helper function to find root port for device
@ 2015-01-13 19:57 Lucas Stach
2015-01-13 19:57 ` [PATCH v3 2/2] PCI: tegra: apply relaxed ordering fixup only on Tegra Lucas Stach
2015-01-23 22:34 ` [PATCH v3 1/2] PCI: add helper function to find root port for device Bjorn Helgaas
0 siblings, 2 replies; 5+ messages in thread
From: Lucas Stach @ 2015-01-13 19:57 UTC (permalink / raw)
To: Thierry Reding, Bjorn Helgaas; +Cc: linux-tegra, linux-pci
This adds a simple way to get the root port a given device
is connected to.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
v2: new patch in v2
v3: rename to pci_find_rootport to fit better with other API
---
drivers/pci/search.c | 20 ++++++++++++++++++++
include/linux/pci.h | 1 +
2 files changed, 21 insertions(+)
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index a20ce7d5e2a7..7254f126096d 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -384,3 +384,23 @@ int pci_dev_present(const struct pci_device_id *ids)
return 0;
}
EXPORT_SYMBOL(pci_dev_present);
+
+/**
+ * pci_find_root_port - Returns the root port the given device is connected to.
+ * @dev: PCI device for which the root port should be found.
+ */
+struct pci_dev *pci_find_root_port(struct pci_dev *dev)
+{
+ struct pci_bus *bus = dev->bus;
+
+ /* If there is no bridge on the bus the passed device is a root port. */
+ if (!bus->self)
+ return dev;
+
+ /* Walk up the PCI hierarchy to the first level below the root. */
+ while (bus->parent && bus->parent->self)
+ bus = bus->parent;
+
+ return bus->self;
+}
+EXPORT_SYMBOL(pci_find_root_port);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 360a966a97a5..f4321c5ba653 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -844,6 +844,7 @@ static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
}
struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from);
int pci_dev_present(const struct pci_device_id *ids);
+struct pci_dev *pci_find_root_port(struct pci_dev *dev);
int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn,
int where, u8 *val);
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] PCI: tegra: apply relaxed ordering fixup only on Tegra
2015-01-13 19:57 [PATCH v3 1/2] PCI: add helper function to find root port for device Lucas Stach
@ 2015-01-13 19:57 ` Lucas Stach
2015-01-23 22:40 ` Bjorn Helgaas
2015-01-23 22:34 ` [PATCH v3 1/2] PCI: add helper function to find root port for device Bjorn Helgaas
1 sibling, 1 reply; 5+ messages in thread
From: Lucas Stach @ 2015-01-13 19:57 UTC (permalink / raw)
To: Thierry Reding, Bjorn Helgaas; +Cc: linux-tegra, linux-pci
The fixup to enable relaxed ordering on all PCI devices was
executed unconditionally if the Tegra PCI host driver was
built into the kernel. This doesn't play nice with a
multiplatform kernel executed on other platforms which
may not need this fixup.
Make sure to only apply the fixup if the root port is
a Tegra.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Acked-by: Thierry Reding <treding@nvidia.com>
---
v2:
- split out PCI hierarchy walk
- separate code from data by moving PCI IDs into own structure
v3:
- fixup for helper rename
- applied Thierry's ACK
---
drivers/pci/host/pci-tegra.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c
index 6f9c29fa70e7..e87d79559723 100644
--- a/drivers/pci/host/pci-tegra.c
+++ b/drivers/pci/host/pci-tegra.c
@@ -635,10 +635,42 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0bf1, tegra_pcie_fixup_class);
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0e1c, tegra_pcie_fixup_class);
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0e1d, tegra_pcie_fixup_class);
+static const struct pci_device_id tegra_rootport_ids[] = {
+ {
+ /* Tegra20 4 lane root port */
+ .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0bf0,
+ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
+ }, {
+ /* Tegra20 2 lane root port */
+ .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0bf1,
+ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
+ }, {
+ /* Tegra30 4 lane root port */
+ .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0e1c,
+ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
+ }, {
+ /* Tegra30 2 lane root port */
+ .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0e1d,
+ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
+ }, {
+ /* Tegra124 4 lane root port */
+ .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0e12,
+ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
+ }, {
+ /* Tegra124 1 lane root port */
+ .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0e13,
+ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
+ }, {
+ /* sentinel */
+ }
+};
+
/* Tegra PCIE requires relaxed ordering */
static void tegra_pcie_relax_enable(struct pci_dev *dev)
{
- pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN);
+ if (pci_match_id(tegra_rootport_ids, pci_find_root_port(dev)))
+ pcie_capability_set_word(dev, PCI_EXP_DEVCTL,
+ PCI_EXP_DEVCTL_RELAX_EN);
}
DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, tegra_pcie_relax_enable);
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] PCI: add helper function to find root port for device
2015-01-13 19:57 [PATCH v3 1/2] PCI: add helper function to find root port for device Lucas Stach
2015-01-13 19:57 ` [PATCH v3 2/2] PCI: tegra: apply relaxed ordering fixup only on Tegra Lucas Stach
@ 2015-01-23 22:34 ` Bjorn Helgaas
2015-03-30 10:36 ` Lucas Stach
1 sibling, 1 reply; 5+ messages in thread
From: Bjorn Helgaas @ 2015-01-23 22:34 UTC (permalink / raw)
To: Lucas Stach; +Cc: Thierry Reding, linux-tegra, linux-pci
On Tue, Jan 13, 2015 at 08:57:27PM +0100, Lucas Stach wrote:
> This adds a simple way to get the root port a given device
> is connected to.
>
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> ---
> v2: new patch in v2
> v3: rename to pci_find_rootport to fit better with other API
> ---
> drivers/pci/search.c | 20 ++++++++++++++++++++
> include/linux/pci.h | 1 +
> 2 files changed, 21 insertions(+)
>
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index a20ce7d5e2a7..7254f126096d 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -384,3 +384,23 @@ int pci_dev_present(const struct pci_device_id *ids)
> return 0;
> }
> EXPORT_SYMBOL(pci_dev_present);
> +
> +/**
> + * pci_find_root_port - Returns the root port the given device is connected to.
> + * @dev: PCI device for which the root port should be found.
> + */
> +struct pci_dev *pci_find_root_port(struct pci_dev *dev)
This seems a little too generic. There are still PCI (non-PCIe) systems,
and on those this will return some non-Root Port device, the meaning of
which is unclear. I'm happy to put something like this in pci-tegra.c, but
until there are other potential users and we sort out the PCI/PCIe-ness of
the interface, I don't really want to make it global and exported.
> +{
> + struct pci_bus *bus = dev->bus;
> +
> + /* If there is no bridge on the bus the passed device is a root port. */
This assumption is false -- see the comment at pci_is_root_bus().
> + if (!bus->self)
> + return dev;
> +
> + /* Walk up the PCI hierarchy to the first level below the root. */
> + while (bus->parent && bus->parent->self)
> + bus = bus->parent;
> +
> + return bus->self;
> +}
> +EXPORT_SYMBOL(pci_find_root_port);
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 360a966a97a5..f4321c5ba653 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -844,6 +844,7 @@ static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
> }
> struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from);
> int pci_dev_present(const struct pci_device_id *ids);
> +struct pci_dev *pci_find_root_port(struct pci_dev *dev);
>
> int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn,
> int where, u8 *val);
> --
> 2.1.4
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] PCI: tegra: apply relaxed ordering fixup only on Tegra
2015-01-13 19:57 ` [PATCH v3 2/2] PCI: tegra: apply relaxed ordering fixup only on Tegra Lucas Stach
@ 2015-01-23 22:40 ` Bjorn Helgaas
0 siblings, 0 replies; 5+ messages in thread
From: Bjorn Helgaas @ 2015-01-23 22:40 UTC (permalink / raw)
To: Lucas Stach; +Cc: Thierry Reding, linux-tegra, linux-pci
On Tue, Jan 13, 2015 at 08:57:28PM +0100, Lucas Stach wrote:
> The fixup to enable relaxed ordering on all PCI devices was
> executed unconditionally if the Tegra PCI host driver was
> built into the kernel. This doesn't play nice with a
> multiplatform kernel executed on other platforms which
> may not need this fixup.
>
> Make sure to only apply the fixup if the root port is
> a Tegra.
>
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> Acked-by: Thierry Reding <treding@nvidia.com>
> ---
> v2:
> - split out PCI hierarchy walk
> - separate code from data by moving PCI IDs into own structure
> v3:
> - fixup for helper rename
> - applied Thierry's ACK
> ---
> drivers/pci/host/pci-tegra.c | 34 +++++++++++++++++++++++++++++++++-
> 1 file changed, 33 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c
> index 6f9c29fa70e7..e87d79559723 100644
> --- a/drivers/pci/host/pci-tegra.c
> +++ b/drivers/pci/host/pci-tegra.c
> @@ -635,10 +635,42 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0bf1, tegra_pcie_fixup_class);
> DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0e1c, tegra_pcie_fixup_class);
> DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0e1d, tegra_pcie_fixup_class);
>
> +static const struct pci_device_id tegra_rootport_ids[] = {
> + {
> + /* Tegra20 4 lane root port */
> + .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0bf0,
> + .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
> + }, {
> + /* Tegra20 2 lane root port */
> + .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0bf1,
> + .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
> + }, {
> + /* Tegra30 4 lane root port */
> + .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0e1c,
> + .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
> + }, {
> + /* Tegra30 2 lane root port */
> + .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0e1d,
> + .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
> + }, {
> + /* Tegra124 4 lane root port */
> + .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0e12,
> + .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
> + }, {
> + /* Tegra124 1 lane root port */
> + .vendor = PCI_VENDOR_ID_NVIDIA, .device = 0x0e13,
> + .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
> + }, {
> + /* sentinel */
> + }
The table is OK and I'll apply it after we resolve the pci_find_root_port()
thing, but it's unfortunate that we're signing up to the ongoing
maintenance a table like this requires. I'm sure you've already tried
other possibilities and resigned yourself to this one, though.
> +};
> +
> /* Tegra PCIE requires relaxed ordering */
> static void tegra_pcie_relax_enable(struct pci_dev *dev)
> {
> - pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN);
> + if (pci_match_id(tegra_rootport_ids, pci_find_root_port(dev)))
> + pcie_capability_set_word(dev, PCI_EXP_DEVCTL,
> + PCI_EXP_DEVCTL_RELAX_EN);
> }
> DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, tegra_pcie_relax_enable);
>
> --
> 2.1.4
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] PCI: add helper function to find root port for device
2015-01-23 22:34 ` [PATCH v3 1/2] PCI: add helper function to find root port for device Bjorn Helgaas
@ 2015-03-30 10:36 ` Lucas Stach
0 siblings, 0 replies; 5+ messages in thread
From: Lucas Stach @ 2015-03-30 10:36 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: Thierry Reding, linux-tegra, linux-pci
Am Freitag, den 23.01.2015, 16:34 -0600 schrieb Bjorn Helgaas:
> On Tue, Jan 13, 2015 at 08:57:27PM +0100, Lucas Stach wrote:
> > This adds a simple way to get the root port a given device
> > is connected to.
> >
> > Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> > ---
> > v2: new patch in v2
> > v3: rename to pci_find_rootport to fit better with other API
> > ---
> > drivers/pci/search.c | 20 ++++++++++++++++++++
> > include/linux/pci.h | 1 +
> > 2 files changed, 21 insertions(+)
> >
> > diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> > index a20ce7d5e2a7..7254f126096d 100644
> > --- a/drivers/pci/search.c
> > +++ b/drivers/pci/search.c
> > @@ -384,3 +384,23 @@ int pci_dev_present(const struct pci_device_id *ids)
> > return 0;
> > }
> > EXPORT_SYMBOL(pci_dev_present);
> > +
> > +/**
> > + * pci_find_root_port - Returns the root port the given device is connected to.
> > + * @dev: PCI device for which the root port should be found.
> > + */
> > +struct pci_dev *pci_find_root_port(struct pci_dev *dev)
>
> This seems a little too generic. There are still PCI (non-PCIe) systems,
> and on those this will return some non-Root Port device, the meaning of
> which is unclear. I'm happy to put something like this in pci-tegra.c, but
> until there are other potential users and we sort out the PCI/PCIe-ness of
> the interface, I don't really want to make it global and exported.
>
I moved it out of the Tegra PCIe driver on your request. Also I can
already see this being useful for the Keystone PCI host driver to
shorten the MTRS quirk function.
I will rename this to pcie_find_root_port() so it is clear that this is
PCIe specific, but keep it in the current location.
> > +{
> > + struct pci_bus *bus = dev->bus;
> > +
> > + /* If there is no bridge on the bus the passed device is a root port. */
>
> This assumption is false -- see the comment at pci_is_root_bus().
>
Right, will change this.
Regards,
Lucas
--
Pengutronix e.K. | Lucas Stach |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-03-30 10:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-13 19:57 [PATCH v3 1/2] PCI: add helper function to find root port for device Lucas Stach
2015-01-13 19:57 ` [PATCH v3 2/2] PCI: tegra: apply relaxed ordering fixup only on Tegra Lucas Stach
2015-01-23 22:40 ` Bjorn Helgaas
2015-01-23 22:34 ` [PATCH v3 1/2] PCI: add helper function to find root port for device Bjorn Helgaas
2015-03-30 10:36 ` Lucas Stach
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).