All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
To: linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v7 01/10] PCI: host: rcar: Add Renesas R-Car PCIe driver
Date: Thu, 01 May 2014 16:50:03 +0000	[thread overview]
Message-ID: <20140501165003.GC3296@obsidianresearch.com> (raw)
In-Reply-To: <b9160c7a49304270b5070dcf49482723@HKXPR06MB168.apcprd06.prod.outlook.com>

On Thu, May 01, 2014 at 09:50:56AM +0000, Phil Edworthy wrote:

> > The logic should be:
> >  if (bus = primary)
> >     do io access to host bridge
> >  else if (bus = secondary)
> >     issue type 0 TLP on the wire
> >  else if (bus > secondary && bus <= subordinate)
> >     issue type 1 TLP on the wire
> >  else
> >     fail, invalid bus number
> > Where the three values come from the register in the PCI host bridge's
> > configuration space, and are kept in sync with the programming from
> > the Linux PCI core.
> > 
> > It is just a happy hapenstance that root_bus_nr equals the value the
> > PCI core programmed into secondary - that is not guarenteed, you must
> > use the primary value directly.

> For type0 TLPs, we are not checking that root_bus_nr equals the
> value the PCI core programmed into secondary, we are checking that
> the (root_bus_nr = bus->parent->number). The only way this wouldn't
> work is if root_bus_nr was not the root bus number.

Okay, that isn't as sketchy, but that process still ignores the
subordinate bus number and the failure case as required by PCI.

The goal here is to have the stuff below the drivers implement the PCI
spec so that the core code can assume everything below is
conformant. Drivers should not introduce gratuitous differences 'just
because'

There is no reason drivers should be using PCI core structures to make
decisions when the spec says those decisions are driven by config
space fields.

This way the PCI core code doesn't have to be aware of any weird
non-standard edge cases.. Such as not failing bus numbers beyond the
subordinate bus number.

> Since the Synopsys DW driver also saves off sys->busnr and later
> uses this to determine if accesses are for the host bridge, I guess
> that means it won't always work either, right? Or is it ok because
> the DW driver saves sys->busnr in its .scan function?

Sounds like it is making the same mistake, and nobody noticed. This is
another reason why it is important to implement correctly so people
copying copy the right stuff :)

> When would the PCI core change the root bus number to something
> other than set in sys->busnr?

I think the more likely scenario is that 'sys' in general is
architecture specific and its use is being discouraged so that host
drivers are not arch specific.

A domain driver like rcar should always place the root complex
integrated bus as bus 0 in the domain.

Jason

WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
To: Phil Edworthy <phil.edworthy@renesas.com>
Cc: "linux-sh@vger.kernel.org" <linux-sh@vger.kernel.org>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	Magnus Damm <magnus.damm@gmail.com>,
	Valentine Barshak <valentine.barshak@cogentembedded.com>,
	Simon Horman <horms@verge.net.au>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Ben Dooks <ben.dooks@codethink.co.uk>,
	LAKML <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v7 01/10] PCI: host: rcar: Add Renesas R-Car PCIe driver
Date: Thu, 1 May 2014 10:50:03 -0600	[thread overview]
Message-ID: <20140501165003.GC3296@obsidianresearch.com> (raw)
In-Reply-To: <b9160c7a49304270b5070dcf49482723@HKXPR06MB168.apcprd06.prod.outlook.com>

On Thu, May 01, 2014 at 09:50:56AM +0000, Phil Edworthy wrote:

> > The logic should be:
> >  if (bus == primary)
> >     do io access to host bridge
> >  else if (bus == secondary)
> >     issue type 0 TLP on the wire
> >  else if (bus > secondary && bus <= subordinate)
> >     issue type 1 TLP on the wire
> >  else
> >     fail, invalid bus number
> > Where the three values come from the register in the PCI host bridge's
> > configuration space, and are kept in sync with the programming from
> > the Linux PCI core.
> > 
> > It is just a happy hapenstance that root_bus_nr equals the value the
> > PCI core programmed into secondary - that is not guarenteed, you must
> > use the primary value directly.

> For type0 TLPs, we are not checking that root_bus_nr equals the
> value the PCI core programmed into secondary, we are checking that
> the (root_bus_nr == bus->parent->number). The only way this wouldn't
> work is if root_bus_nr was not the root bus number.

Okay, that isn't as sketchy, but that process still ignores the
subordinate bus number and the failure case as required by PCI.

The goal here is to have the stuff below the drivers implement the PCI
spec so that the core code can assume everything below is
conformant. Drivers should not introduce gratuitous differences 'just
because'

There is no reason drivers should be using PCI core structures to make
decisions when the spec says those decisions are driven by config
space fields.

This way the PCI core code doesn't have to be aware of any weird
non-standard edge cases.. Such as not failing bus numbers beyond the
subordinate bus number.

> Since the Synopsys DW driver also saves off sys->busnr and later
> uses this to determine if accesses are for the host bridge, I guess
> that means it won't always work either, right? Or is it ok because
> the DW driver saves sys->busnr in its .scan function?

Sounds like it is making the same mistake, and nobody noticed. This is
another reason why it is important to implement correctly so people
copying copy the right stuff :)

> When would the PCI core change the root bus number to something
> other than set in sys->busnr?

I think the more likely scenario is that 'sys' in general is
architecture specific and its use is being discouraged so that host
drivers are not arch specific.

A domain driver like rcar should always place the root complex
integrated bus as bus 0 in the domain.

Jason

WARNING: multiple messages have this Message-ID (diff)
From: jgunthorpe@obsidianresearch.com (Jason Gunthorpe)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v7 01/10] PCI: host: rcar: Add Renesas R-Car PCIe driver
Date: Thu, 1 May 2014 10:50:03 -0600	[thread overview]
Message-ID: <20140501165003.GC3296@obsidianresearch.com> (raw)
In-Reply-To: <b9160c7a49304270b5070dcf49482723@HKXPR06MB168.apcprd06.prod.outlook.com>

On Thu, May 01, 2014 at 09:50:56AM +0000, Phil Edworthy wrote:

> > The logic should be:
> >  if (bus == primary)
> >     do io access to host bridge
> >  else if (bus == secondary)
> >     issue type 0 TLP on the wire
> >  else if (bus > secondary && bus <= subordinate)
> >     issue type 1 TLP on the wire
> >  else
> >     fail, invalid bus number
> > Where the three values come from the register in the PCI host bridge's
> > configuration space, and are kept in sync with the programming from
> > the Linux PCI core.
> > 
> > It is just a happy hapenstance that root_bus_nr equals the value the
> > PCI core programmed into secondary - that is not guarenteed, you must
> > use the primary value directly.

> For type0 TLPs, we are not checking that root_bus_nr equals the
> value the PCI core programmed into secondary, we are checking that
> the (root_bus_nr == bus->parent->number). The only way this wouldn't
> work is if root_bus_nr was not the root bus number.

Okay, that isn't as sketchy, but that process still ignores the
subordinate bus number and the failure case as required by PCI.

The goal here is to have the stuff below the drivers implement the PCI
spec so that the core code can assume everything below is
conformant. Drivers should not introduce gratuitous differences 'just
because'

There is no reason drivers should be using PCI core structures to make
decisions when the spec says those decisions are driven by config
space fields.

This way the PCI core code doesn't have to be aware of any weird
non-standard edge cases.. Such as not failing bus numbers beyond the
subordinate bus number.

> Since the Synopsys DW driver also saves off sys->busnr and later
> uses this to determine if accesses are for the host bridge, I guess
> that means it won't always work either, right? Or is it ok because
> the DW driver saves sys->busnr in its .scan function?

Sounds like it is making the same mistake, and nobody noticed. This is
another reason why it is important to implement correctly so people
copying copy the right stuff :)

> When would the PCI core change the root bus number to something
> other than set in sys->busnr?

I think the more likely scenario is that 'sys' in general is
architecture specific and its use is being discouraged so that host
drivers are not arch specific.

A domain driver like rcar should always place the root complex
integrated bus as bus 0 in the domain.

Jason

  reply	other threads:[~2014-05-01 16:50 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-31 10:30 [PATCH v7 00/10] R-Car Gen2 PCIe host driver Phil Edworthy
2014-03-31 10:30 ` Phil Edworthy
2014-03-31 10:30 ` Phil Edworthy
2014-03-31 10:30 ` [PATCH v7 01/10] PCI: host: rcar: Add Renesas R-Car PCIe driver Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-04-24 19:19   ` Bjorn Helgaas
2014-04-24 19:19     ` Bjorn Helgaas
2014-04-24 19:19     ` Bjorn Helgaas
2014-04-28 10:03     ` Phil Edworthy
2014-04-28 10:03       ` Phil Edworthy
2014-04-28 10:03       ` Phil Edworthy
2014-04-28 19:11       ` Bjorn Helgaas
2014-04-28 19:11         ` Bjorn Helgaas
2014-04-28 19:11         ` Bjorn Helgaas
2014-04-28 20:35         ` Jason Gunthorpe
2014-04-28 20:35           ` Jason Gunthorpe
2014-04-28 20:35           ` Jason Gunthorpe
2014-04-30 10:33           ` Phil Edworthy
2014-04-30 10:33             ` Phil Edworthy
2014-04-30 10:33             ` Phil Edworthy
2014-04-30 15:43             ` Jason Gunthorpe
2014-04-30 15:43               ` Jason Gunthorpe
2014-04-30 15:43               ` Jason Gunthorpe
2014-05-01  9:50               ` Phil Edworthy
2014-05-01  9:50                 ` Phil Edworthy
2014-05-01  9:50                 ` Phil Edworthy
2014-05-01 16:50                 ` Jason Gunthorpe [this message]
2014-05-01 16:50                   ` Jason Gunthorpe
2014-05-01 16:50                   ` Jason Gunthorpe
2014-05-06 10:46                   ` Phil Edworthy
2014-05-06 10:46                     ` Phil Edworthy
2014-05-06 10:46                     ` Phil Edworthy
2014-05-01 17:31                 ` Bjorn Helgaas
2014-05-01 17:31                   ` Bjorn Helgaas
2014-05-01 17:31                   ` Bjorn Helgaas
2014-05-06 12:49                   ` Phil Edworthy
2014-05-06 12:49                     ` Phil Edworthy
2014-05-06 12:49                     ` Phil Edworthy
2014-04-30 10:20         ` Phil Edworthy
2014-04-30 10:20           ` Phil Edworthy
2014-04-30 10:20           ` Phil Edworthy
2014-03-31 10:30 ` [PATCH v7 02/10] PCI: host: rcar: Add MSI support Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-04-04  8:53   ` Lucas Stach
2014-04-04  8:53     ` Lucas Stach
2014-04-04  8:53     ` Lucas Stach
2014-03-31 10:30 ` [PATCH v7 03/10] ARM: shmobile: r8a7790: Add PCIe clock device tree nodes Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30 ` [PATCH v7 04/10] ARM: shmobile: r8a7791: " Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30 ` [PATCH v7 05/10] dt-bindings: pci: rcar pcie device tree bindings Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-04-04  9:08   ` Lucas Stach
2014-04-04  9:08     ` Lucas Stach
2014-04-04  9:08     ` Lucas Stach
2014-03-31 10:30 ` [PATCH v7 06/10] ARM: shmobile: r8a7790: Add PCIe device nodes Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30 ` [PATCH v7 07/10] ARM: shmobile: lager: " Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30 ` [PATCH v7 08/10] ARM: shmobile: r8a7791: " Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30 ` [PATCH v7 09/10] ARM: shmobile: koelsch: " Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30 ` [PATCH v7 10/10] ARM: shmobile: koelsch: Add PCIe to defconfig Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-03-31 10:30   ` Phil Edworthy
2014-04-04  8:22 ` [PATCH v7 00/10] R-Car Gen2 PCIe host driver Phil Edworthy
2014-04-04  8:22   ` Phil Edworthy
2014-04-04  8:22   ` Phil Edworthy
2014-04-04  8:30 ` Phil Edworthy
2014-04-04  8:30   ` Phil Edworthy
2014-04-04  8:30   ` Phil Edworthy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140501165003.GC3296@obsidianresearch.com \
    --to=jgunthorpe@obsidianresearch.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.