Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/19/19 10:17 PM, Dan Williams wrote: > On Mon, Aug 19, 2019 at 9:30 AM Stephen Douthit > wrote: >> >> On 8/14/19 1:17 PM, Dan Williams wrote: Can you get someone from the controller design team to give us a clear answer on a revision where this PCS change happened? It would be nice if we could just check PCI_REVISION_ID or something similar. >>> >>> I don't think such a reliable association with rev-id exists, the> intent >>> was that the OS need never consider PCS. >> >> Can you please ask to confirm? It would be a much simpler check if it >> is possible. > > No. Even if it were accidentally the case today the Linux driver can't > trust that rev-id across the different implementations will be > maintained for this purpose because the OS driver is not meant to > touch this register. Just look at a sampling of rev-id from a few > different systems, and note that rev-id applies to the chipset not > just the ahci controller. > > rev 08 > rev 11 > rev 31 > > ...which one of those is Denverton? > > The intent is that PCS is a platform-firmware concern and that any > software that cares about PCS is caring about it by explicit > identification. Understood. My hope was that there was a guaranteed relation, but no such luck. >>> The way Linux is using >>> it is already broken with the assumption that it is performed after >>> every HOST_CTL based reset which only resets mmio space. At most it >>> should only be required at initial PCI discovery iff platform firmware >>> failed to run. >> >> This is a separate issue. >> >> It's broken in the sense that the code is called more often that it >> needs to be, but reset isn't a hot path, and there are no side effects >> to doing this multiple times that I can see. > > The problem is that there is no known need to do it for Denverton, and > likely more platform implementations. > >> And as you point out, no >> bug reports, so pretty benign all things considered. >> >> We could move the PCS quirk code to ahci_init_one() to address this >> concern once there's agreement on what the criteria is to run/not-run >> this code. >> >>> There are no bug reports with the current >>> implementation that only attempts to enable bits based on PORTS_IMPL, >>> so I think we are firmer ground trying to draw a line where the driver >>> just stops worrying about PCS rather than try to detect the layout. >> >> Someone at Intel is going to need to decide where/how to draw this line. > > This is a case of Linux touching a "BIOS only" register and assuming > that the quirk is widely applicable. I think a reasonable fix is to > just whitelist all the known Intel ids, apply the PCS fixup assuming > the legacy configuration register location, and stop applying the > quirk by default. > > Here is a proposed patch along these lines. I can send a > non-whitespace damaged version if this approach looks acceptable: > > --- > > From f40a7f287c97cfba71393ccb592ba521e43d807b Mon Sep 17 00:00:00 2001 > From: Dan Williams > Date: Mon, 19 Aug 2019 11:30:37 -0700 > Subject: [PATCH] libata/ahci: Drop PCS quirk for Denverton and beyond > > The Linux ahci driver has historically implemented a configuration fixup > for platforms / platform-firmware that fails to enable the ports prior > to OS hand-off at boot. The fixup was originally implemented way back > before ahci moved from drivers/scsi/ to drivers/ata/, and was updated in > 2007 via commit 49f290903935 "ahci: update PCS programming". The quirk > sets a port-enable bitmap in the PCS register at offset 0x92. > > This quirk could be applied generically up until the arrival of the > Denverton (DNV) platform. The DNV AHCI controller architecture supports > more than 6 ports and along with that the PCS register location and > format were updated to allow for more possible ports in the bitmap. DNV > AHCI expands the register to 32-bits and moves it to offset 0x94. > > As it stands there are no known problem reports with existing Linux > trying to set bits at offset 0x92 which indicates that the quirk is not > applicable. Likely it is not applicable on a wider range of platforms, > but it is difficult to discern which platforms if any still depend on > the quirk. > > Rather than try to fix the PCS quirk to consider the DNV register layout > instead require explicit opt-in. The assumption is that the OS driver > need not touch this register, and platforms can be added to a whitelist > when / if problematic platforms are found in the future. The list in > ahci_intel_pcs_quirk() is populated with all the current explicit > device-ids with the expectation that class-code based detection need not > apply the quirk. > > Reported-by: Stephen Douthit > Cc: Christoph Hellwig > Signed-off-by: Dan Williams > --- > drivers/ata/ahci.c | 211 +++-- > 1 file changed, 184 insertions(+), 27 deletions(-) > > diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c >
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On Mon, Aug 19, 2019 at 9:30 AM Stephen Douthit wrote: > > On 8/14/19 1:17 PM, Dan Williams wrote: > >> Can you get someone from the controller design team to give us a clear > >> answer on a revision where this PCS change happened? > >> > >> It would be nice if we could just check PCI_REVISION_ID or something > >> similar. > > > > I don't think such a reliable association with rev-id exists, the> intent > > was that the OS need never consider PCS. > > Can you please ask to confirm? It would be a much simpler check if it > is possible. No. Even if it were accidentally the case today the Linux driver can't trust that rev-id across the different implementations will be maintained for this purpose because the OS driver is not meant to touch this register. Just look at a sampling of rev-id from a few different systems, and note that rev-id applies to the chipset not just the ahci controller. rev 08 rev 11 rev 31 ...which one of those is Denverton? The intent is that PCS is a platform-firmware concern and that any software that cares about PCS is caring about it by explicit identification. > > The way Linux is using > > it is already broken with the assumption that it is performed after > > every HOST_CTL based reset which only resets mmio space. At most it > > should only be required at initial PCI discovery iff platform firmware > > failed to run. > > This is a separate issue. > > It's broken in the sense that the code is called more often that it > needs to be, but reset isn't a hot path, and there are no side effects > to doing this multiple times that I can see. The problem is that there is no known need to do it for Denverton, and likely more platform implementations. > And as you point out, no > bug reports, so pretty benign all things considered. > > We could move the PCS quirk code to ahci_init_one() to address this > concern once there's agreement on what the criteria is to run/not-run > this code. > > > There are no bug reports with the current > > implementation that only attempts to enable bits based on PORTS_IMPL, > > so I think we are firmer ground trying to draw a line where the driver > > just stops worrying about PCS rather than try to detect the layout. > > Someone at Intel is going to need to decide where/how to draw this line. This is a case of Linux touching a "BIOS only" register and assuming that the quirk is widely applicable. I think a reasonable fix is to just whitelist all the known Intel ids, apply the PCS fixup assuming the legacy configuration register location, and stop applying the quirk by default. Here is a proposed patch along these lines. I can send a non-whitespace damaged version if this approach looks acceptable: --- >From f40a7f287c97cfba71393ccb592ba521e43d807b Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 19 Aug 2019 11:30:37 -0700 Subject: [PATCH] libata/ahci: Drop PCS quirk for Denverton and beyond The Linux ahci driver has historically implemented a configuration fixup for platforms / platform-firmware that fails to enable the ports prior to OS hand-off at boot. The fixup was originally implemented way back before ahci moved from drivers/scsi/ to drivers/ata/, and was updated in 2007 via commit 49f290903935 "ahci: update PCS programming". The quirk sets a port-enable bitmap in the PCS register at offset 0x92. This quirk could be applied generically up until the arrival of the Denverton (DNV) platform. The DNV AHCI controller architecture supports more than 6 ports and along with that the PCS register location and format were updated to allow for more possible ports in the bitmap. DNV AHCI expands the register to 32-bits and moves it to offset 0x94. As it stands there are no known problem reports with existing Linux trying to set bits at offset 0x92 which indicates that the quirk is not applicable. Likely it is not applicable on a wider range of platforms, but it is difficult to discern which platforms if any still depend on the quirk. Rather than try to fix the PCS quirk to consider the DNV register layout instead require explicit opt-in. The assumption is that the OS driver need not touch this register, and platforms can be added to a whitelist when / if problematic platforms are found in the future. The list in ahci_intel_pcs_quirk() is populated with all the current explicit device-ids with the expectation that class-code based detection need not apply the quirk. Reported-by: Stephen Douthit Cc: Christoph Hellwig Signed-off-by: Dan Williams --- drivers/ata/ahci.c | 211 +++-- 1 file changed, 184 insertions(+), 27 deletions(-) diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index f7652baa6337..ceb38d205e1b 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -623,30 +623,6 @@ static void ahci_pci_save_initial_config(struct pci_dev *pdev, ahci_save_initial_config(>dev, hpriv); } -static int ahci_pci_reset_controller(struct ata_host *host) -{ - struct
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/14/19 1:17 PM, Dan Williams wrote: >> Can you get someone from the controller design team to give us a clear >> answer on a revision where this PCS change happened? >> >> It would be nice if we could just check PCI_REVISION_ID or something >> similar. > > I don't think such a reliable association with rev-id exists, the> intent was > that the OS need never consider PCS. Can you please ask to confirm? It would be a much simpler check if it is possible. > The way Linux is using > it is already broken with the assumption that it is performed after > every HOST_CTL based reset which only resets mmio space. At most it > should only be required at initial PCI discovery iff platform firmware > failed to run. This is a separate issue. It's broken in the sense that the code is called more often that it needs to be, but reset isn't a hot path, and there are no side effects to doing this multiple times that I can see. And as you point out, no bug reports, so pretty benign all things considered. We could move the PCS quirk code to ahci_init_one() to address this concern once there's agreement on what the criteria is to run/not-run this code. > There are no bug reports with the current > implementation that only attempts to enable bits based on PORTS_IMPL, > so I think we are firmer ground trying to draw a line where the driver > just stops worrying about PCS rather than try to detect the layout. Someone at Intel is going to need to decide where/how to draw this line.
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On Wed, Aug 14, 2019 at 9:54 AM Stephen Douthit wrote: > > On 8/14/19 12:09 PM, Dan Williams wrote: > > On Wed, Aug 14, 2019 at 7:34 AM Stephen Douthit > > wrote: > >> > >> On 8/13/19 6:07 PM, Dan Williams wrote: > >>> On Tue, Aug 13, 2019 at 12:31 AM Christoph Hellwig > >>> wrote: > > On Mon, Aug 12, 2019 at 12:31:35PM -0700, Dan Williams wrote: > > It seems platforms / controllers that fail to run the option-rom > > should be quirked by device-id, but the PCS register twiddling be > > removed for everyone else. "Card BIOS" to me implies devices with an > > Option-ROM BAR which I don't think modern devices have, so that might > > be a simple way to try to phase out this quirk going forward without > > regressing working setups that might be relying on this. > > > > Then again the driver is already depending on the number of enabled > > ports to be reliable before PCS is written, and the current driver > > does not attempt to enable ports that were not enabled previously. > > That tells me that if the PCS quirk ever mattered it would have > > already regressed when the driver switched from blindly writing 0xf to > > only setting the bits that were already set in ->port_map. > > But how do we find that out? > >>> > >>> We can layer another assumption on top of Tejun's assumptions from > >>> commit 49f290903935 "ahci: update PCS programming". The kernel > >>> community has not received any regression reports from that change > >>> which says: > >>> > >>> " > >>> port_map is determined from PORTS_IMPL PCI register which is > >>> implemented as write or write-once register. If the register isn't > >>> programmed, ahci automatically generates it from number of ports, > >>> which is good enough for PCS programming. ICH6/7M are probably the > >>> only ones where non-contiguous enable bits are necessary && > >>> PORTS_IMPL > >>> isn't programmed properly but they're proven to work reliably with > >>> 0xf > >>> anyway. > >>> " > >>> > >>> So the potential options I see are: > >>> > >>> 1/ Keep the current scheme, but limit it to cases where PORTS_IMPL is > >>> less than 8 and assume this need to set the bits is unnecessary legacy > >>> to carry forward > >>> > >>> 2/ Option1 + additionally use PORTS_IMPL as a gate to guess when the > >>> PCS format might be different for values >= 8. > >>> > >>> I think the driver does not need to consider Option2 unless / until it > >>> encounters a platform where firmware does not "do the right thing", > >>> and given Denverton has been in the wild with the wrong PCS twiddling > >>> it seems to suggest nothing needs to be done there. > >>> > A compromise to me seems that we just do the PCS quirk for all Intel > devices explicitly listed in the PCI Ids based on new board_* values > as long as they have the old PCS location, and assume anything new > enough to have the new location won't need to quirk, given that it > never properly worked. This might miss some intel devices that were > supported with the class based catchall, though. > >>> > >>> I'd be more comfortable with PORT_IMPL as the deciding factor. > >> > >> Unfortunately we can't use CAP.NP or PORTS_IMPL for this heuristic. > >> > >> The problem is that BIOS should be setting the PORTS_IMPL bitmask to > >> match which lanes have actually been connected on the board. So > >> PORTS_IMPL can be < 8 even if the controller is new enough to > >> potentially support > 8 and has the new config space layout. > >> > >> As proof here's the relevant ahci_print_info() output booting on a > >> Denverton based box with 5 ports implemented: > >> > >> ahci :00:14.0: AHCI 0001.0301 32 slots 5 ports 6 Gbps 0x7a impl SATA > >> mode > >> | \-PORTS_IMPL > >> \-CAP.NP > > > > Ugh, ok, thanks for clarifying and my mistake for not realizing > > Denverton already violates that heuristic. > > > > So now I'm trying to grok Christoph's suggestion. Are you saying that > > all existing board-ids would assume old PCS format? That would mean > > that Denverton gets the wrong format via board_ahci via the class code > > matching? Maybe I'm not understanding the suggestion... > > My understanding of Christoph's suggestion was that we create a new > board_ahci_* entry (e.g. board_ahci_intel_legacy) to match in > ahci_pci_tbl against those devices using the original config space > layout where PCS is @ 0x92. > > Once we have that we can conditionally run the PCS poke code in > ahci_pci_reset_controller() only for devices with that new board_id. We > assume that all newer devices added to the table will not use the legacy > board_id and not need to do PCS pokes. > > Right now there are entries for devices with both the new and old config > space layout in ahci_pci_tbl. That means someone at Intel
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/14/19 12:09 PM, Dan Williams wrote: > On Wed, Aug 14, 2019 at 7:34 AM Stephen Douthit > wrote: >> >> On 8/13/19 6:07 PM, Dan Williams wrote: >>> On Tue, Aug 13, 2019 at 12:31 AM Christoph Hellwig >>> wrote: On Mon, Aug 12, 2019 at 12:31:35PM -0700, Dan Williams wrote: > It seems platforms / controllers that fail to run the option-rom > should be quirked by device-id, but the PCS register twiddling be > removed for everyone else. "Card BIOS" to me implies devices with an > Option-ROM BAR which I don't think modern devices have, so that might > be a simple way to try to phase out this quirk going forward without > regressing working setups that might be relying on this. > > Then again the driver is already depending on the number of enabled > ports to be reliable before PCS is written, and the current driver > does not attempt to enable ports that were not enabled previously. > That tells me that if the PCS quirk ever mattered it would have > already regressed when the driver switched from blindly writing 0xf to > only setting the bits that were already set in ->port_map. But how do we find that out? >>> >>> We can layer another assumption on top of Tejun's assumptions from >>> commit 49f290903935 "ahci: update PCS programming". The kernel >>> community has not received any regression reports from that change >>> which says: >>> >>> " >>> port_map is determined from PORTS_IMPL PCI register which is >>> implemented as write or write-once register. If the register isn't >>> programmed, ahci automatically generates it from number of ports, >>> which is good enough for PCS programming. ICH6/7M are probably the >>> only ones where non-contiguous enable bits are necessary && PORTS_IMPL >>> isn't programmed properly but they're proven to work reliably with 0xf >>> anyway. >>> " >>> >>> So the potential options I see are: >>> >>> 1/ Keep the current scheme, but limit it to cases where PORTS_IMPL is >>> less than 8 and assume this need to set the bits is unnecessary legacy >>> to carry forward >>> >>> 2/ Option1 + additionally use PORTS_IMPL as a gate to guess when the >>> PCS format might be different for values >= 8. >>> >>> I think the driver does not need to consider Option2 unless / until it >>> encounters a platform where firmware does not "do the right thing", >>> and given Denverton has been in the wild with the wrong PCS twiddling >>> it seems to suggest nothing needs to be done there. >>> A compromise to me seems that we just do the PCS quirk for all Intel devices explicitly listed in the PCI Ids based on new board_* values as long as they have the old PCS location, and assume anything new enough to have the new location won't need to quirk, given that it never properly worked. This might miss some intel devices that were supported with the class based catchall, though. >>> >>> I'd be more comfortable with PORT_IMPL as the deciding factor. >> >> Unfortunately we can't use CAP.NP or PORTS_IMPL for this heuristic. >> >> The problem is that BIOS should be setting the PORTS_IMPL bitmask to >> match which lanes have actually been connected on the board. So >> PORTS_IMPL can be < 8 even if the controller is new enough to >> potentially support > 8 and has the new config space layout. >> >> As proof here's the relevant ahci_print_info() output booting on a >> Denverton based box with 5 ports implemented: >> >> ahci :00:14.0: AHCI 0001.0301 32 slots 5 ports 6 Gbps 0x7a impl SATA mode >> | \-PORTS_IMPL >> \-CAP.NP > > Ugh, ok, thanks for clarifying and my mistake for not realizing > Denverton already violates that heuristic. > > So now I'm trying to grok Christoph's suggestion. Are you saying that > all existing board-ids would assume old PCS format? That would mean > that Denverton gets the wrong format via board_ahci via the class code > matching? Maybe I'm not understanding the suggestion... My understanding of Christoph's suggestion was that we create a new board_ahci_* entry (e.g. board_ahci_intel_legacy) to match in ahci_pci_tbl against those devices using the original config space layout where PCS is @ 0x92. Once we have that we can conditionally run the PCS poke code in ahci_pci_reset_controller() only for devices with that new board_id. We assume that all newer devices added to the table will not use the legacy board_id and not need to do PCS pokes. Right now there are entries for devices with both the new and old config space layout in ahci_pci_tbl. That means someone at Intel would need to go through each entry and mark it as new or old. Your point about devices matching solely on the class code still applies. > Another option might be that controllers >= 1.3.1 will stop using the > PCS twiddling, and then we go add a new board id where
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On Wed, Aug 14, 2019 at 7:34 AM Stephen Douthit wrote: > > On 8/13/19 6:07 PM, Dan Williams wrote: > > On Tue, Aug 13, 2019 at 12:31 AM Christoph Hellwig > > wrote: > >> > >> On Mon, Aug 12, 2019 at 12:31:35PM -0700, Dan Williams wrote: > >>> It seems platforms / controllers that fail to run the option-rom > >>> should be quirked by device-id, but the PCS register twiddling be > >>> removed for everyone else. "Card BIOS" to me implies devices with an > >>> Option-ROM BAR which I don't think modern devices have, so that might > >>> be a simple way to try to phase out this quirk going forward without > >>> regressing working setups that might be relying on this. > >>> > >>> Then again the driver is already depending on the number of enabled > >>> ports to be reliable before PCS is written, and the current driver > >>> does not attempt to enable ports that were not enabled previously. > >>> That tells me that if the PCS quirk ever mattered it would have > >>> already regressed when the driver switched from blindly writing 0xf to > >>> only setting the bits that were already set in ->port_map. > >> > >> But how do we find that out? > > > > We can layer another assumption on top of Tejun's assumptions from > > commit 49f290903935 "ahci: update PCS programming". The kernel > > community has not received any regression reports from that change > > which says: > > > > " > > port_map is determined from PORTS_IMPL PCI register which is > > implemented as write or write-once register. If the register isn't > > programmed, ahci automatically generates it from number of ports, > > which is good enough for PCS programming. ICH6/7M are probably the > > only ones where non-contiguous enable bits are necessary && PORTS_IMPL > > isn't programmed properly but they're proven to work reliably with 0xf > > anyway. > > " > > > > So the potential options I see are: > > > > 1/ Keep the current scheme, but limit it to cases where PORTS_IMPL is > > less than 8 and assume this need to set the bits is unnecessary legacy > > to carry forward > > > > 2/ Option1 + additionally use PORTS_IMPL as a gate to guess when the > > PCS format might be different for values >= 8. > > > > I think the driver does not need to consider Option2 unless / until it > > encounters a platform where firmware does not "do the right thing", > > and given Denverton has been in the wild with the wrong PCS twiddling > > it seems to suggest nothing needs to be done there. > > > >> A compromise to me seems that we just do the PCS quirk for all Intel > >> devices explicitly listed in the PCI Ids based on new board_* values > >> as long as they have the old PCS location, and assume anything new > >> enough to have the new location won't need to quirk, given that it > >> never properly worked. This might miss some intel devices that were > >> supported with the class based catchall, though. > > > > I'd be more comfortable with PORT_IMPL as the deciding factor. > > Unfortunately we can't use CAP.NP or PORTS_IMPL for this heuristic. > > The problem is that BIOS should be setting the PORTS_IMPL bitmask to > match which lanes have actually been connected on the board. So > PORTS_IMPL can be < 8 even if the controller is new enough to > potentially support > 8 and has the new config space layout. > > As proof here's the relevant ahci_print_info() output booting on a > Denverton based box with 5 ports implemented: > > ahci :00:14.0: AHCI 0001.0301 32 slots 5 ports 6 Gbps 0x7a impl SATA mode > | \-PORTS_IMPL > \-CAP.NP Ugh, ok, thanks for clarifying and my mistake for not realizing Denverton already violates that heuristic. So now I'm trying to grok Christoph's suggestion. Are you saying that all existing board-ids would assume old PCS format? That would mean that Denverton gets the wrong format via board_ahci via the class code matching? Maybe I'm not understanding the suggestion... Another option might be that controllers >= 1.3.1 will stop using the PCS twiddling, and then we go add a new board id where / if it happens to matter in practice.
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/13/19 6:07 PM, Dan Williams wrote: > On Tue, Aug 13, 2019 at 12:31 AM Christoph Hellwig wrote: >> >> On Mon, Aug 12, 2019 at 12:31:35PM -0700, Dan Williams wrote: >>> It seems platforms / controllers that fail to run the option-rom >>> should be quirked by device-id, but the PCS register twiddling be >>> removed for everyone else. "Card BIOS" to me implies devices with an >>> Option-ROM BAR which I don't think modern devices have, so that might >>> be a simple way to try to phase out this quirk going forward without >>> regressing working setups that might be relying on this. >>> >>> Then again the driver is already depending on the number of enabled >>> ports to be reliable before PCS is written, and the current driver >>> does not attempt to enable ports that were not enabled previously. >>> That tells me that if the PCS quirk ever mattered it would have >>> already regressed when the driver switched from blindly writing 0xf to >>> only setting the bits that were already set in ->port_map. >> >> But how do we find that out? > > We can layer another assumption on top of Tejun's assumptions from > commit 49f290903935 "ahci: update PCS programming". The kernel > community has not received any regression reports from that change > which says: > > " > port_map is determined from PORTS_IMPL PCI register which is > implemented as write or write-once register. If the register isn't > programmed, ahci automatically generates it from number of ports, > which is good enough for PCS programming. ICH6/7M are probably the > only ones where non-contiguous enable bits are necessary && PORTS_IMPL > isn't programmed properly but they're proven to work reliably with 0xf > anyway. > " > > So the potential options I see are: > > 1/ Keep the current scheme, but limit it to cases where PORTS_IMPL is > less than 8 and assume this need to set the bits is unnecessary legacy > to carry forward > > 2/ Option1 + additionally use PORTS_IMPL as a gate to guess when the > PCS format might be different for values >= 8. > > I think the driver does not need to consider Option2 unless / until it > encounters a platform where firmware does not "do the right thing", > and given Denverton has been in the wild with the wrong PCS twiddling > it seems to suggest nothing needs to be done there. > >> A compromise to me seems that we just do the PCS quirk for all Intel >> devices explicitly listed in the PCI Ids based on new board_* values >> as long as they have the old PCS location, and assume anything new >> enough to have the new location won't need to quirk, given that it >> never properly worked. This might miss some intel devices that were >> supported with the class based catchall, though. > > I'd be more comfortable with PORT_IMPL as the deciding factor. Unfortunately we can't use CAP.NP or PORTS_IMPL for this heuristic. The problem is that BIOS should be setting the PORTS_IMPL bitmask to match which lanes have actually been connected on the board. So PORTS_IMPL can be < 8 even if the controller is new enough to potentially support > 8 and has the new config space layout. As proof here's the relevant ahci_print_info() output booting on a Denverton based box with 5 ports implemented: ahci :00:14.0: AHCI 0001.0301 32 slots 5 ports 6 Gbps 0x7a impl SATA mode | \-PORTS_IMPL \-CAP.NP
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On Tue, Aug 13, 2019 at 12:31 AM Christoph Hellwig wrote: > > On Mon, Aug 12, 2019 at 12:31:35PM -0700, Dan Williams wrote: > > It seems platforms / controllers that fail to run the option-rom > > should be quirked by device-id, but the PCS register twiddling be > > removed for everyone else. "Card BIOS" to me implies devices with an > > Option-ROM BAR which I don't think modern devices have, so that might > > be a simple way to try to phase out this quirk going forward without > > regressing working setups that might be relying on this. > > > > Then again the driver is already depending on the number of enabled > > ports to be reliable before PCS is written, and the current driver > > does not attempt to enable ports that were not enabled previously. > > That tells me that if the PCS quirk ever mattered it would have > > already regressed when the driver switched from blindly writing 0xf to > > only setting the bits that were already set in ->port_map. > > But how do we find that out? We can layer another assumption on top of Tejun's assumptions from commit 49f290903935 "ahci: update PCS programming". The kernel community has not received any regression reports from that change which says: " port_map is determined from PORTS_IMPL PCI register which is implemented as write or write-once register. If the register isn't programmed, ahci automatically generates it from number of ports, which is good enough for PCS programming. ICH6/7M are probably the only ones where non-contiguous enable bits are necessary && PORTS_IMPL isn't programmed properly but they're proven to work reliably with 0xf anyway. " So the potential options I see are: 1/ Keep the current scheme, but limit it to cases where PORTS_IMPL is less than 8 and assume this need to set the bits is unnecessary legacy to carry forward 2/ Option1 + additionally use PORTS_IMPL as a gate to guess when the PCS format might be different for values >= 8. I think the driver does not need to consider Option2 unless / until it encounters a platform where firmware does not "do the right thing", and given Denverton has been in the wild with the wrong PCS twiddling it seems to suggest nothing needs to be done there. > A compromise to me seems that we just do the PCS quirk for all Intel > devices explicitly listed in the PCI Ids based on new board_* values > as long as they have the old PCS location, and assume anything new > enough to have the new location won't need to quirk, given that it > never properly worked. This might miss some intel devices that were > supported with the class based catchall, though. I'd be more comfortable with PORT_IMPL as the deciding factor.
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On Mon, Aug 12, 2019 at 12:31:35PM -0700, Dan Williams wrote: > It seems platforms / controllers that fail to run the option-rom > should be quirked by device-id, but the PCS register twiddling be > removed for everyone else. "Card BIOS" to me implies devices with an > Option-ROM BAR which I don't think modern devices have, so that might > be a simple way to try to phase out this quirk going forward without > regressing working setups that might be relying on this. > > Then again the driver is already depending on the number of enabled > ports to be reliable before PCS is written, and the current driver > does not attempt to enable ports that were not enabled previously. > That tells me that if the PCS quirk ever mattered it would have > already regressed when the driver switched from blindly writing 0xf to > only setting the bits that were already set in ->port_map. But how do we find that out? A compromise to me seems that we just do the PCS quirk for all Intel devices explicitly listed in the PCI Ids based on new board_* values as long as they have the old PCS location, and assume anything new enough to have the new location won't need to quirk, given that it never properly worked. This might miss some intel devices that were supported with the class based catchall, though.
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On Mon, Aug 12, 2019 at 11:08 AM Christoph Hellwig wrote: > > On Mon, Aug 12, 2019 at 05:49:29PM +, Stephen Douthit wrote: > > Does anyone know the background of the original PCS workaround? > > Based on a few git-blame iterations on history.git the original PCS > handling (just when initializing) goes back to this BK commit: > > -- > From c0835b838e76c9500facad05dc305170a1a577a8 Mon Sep 17 00:00:00 2001 > From: Jeff Garzik > Date: Thu, 14 Oct 2004 16:11:44 -0400 > Subject: [libata ahci] fix several bugs > > * PCI IDs from test version didn't make it into mainline... doh > * do all command setup in ->qc_prep > * phy_reset routine that does signature check > * check SATA phy for errors > * reset hardware from scratch, in case card BIOS didn't run Ok, that at least matches the expectation that platform firmware initially enables the ports. However, it still leaves open the question of whether the PCS bits were actually not configured, or whether just the controller reset was needed. Certainly there is no reason to touch that configuration register after every controller reset (via the HOST_CTL mmio register) It seems platforms / controllers that fail to run the option-rom should be quirked by device-id, but the PCS register twiddling be removed for everyone else. "Card BIOS" to me implies devices with an Option-ROM BAR which I don't think modern devices have, so that might be a simple way to try to phase out this quirk going forward without regressing working setups that might be relying on this. Then again the driver is already depending on the number of enabled ports to be reliable before PCS is written, and the current driver does not attempt to enable ports that were not enabled previously. That tells me that if the PCS quirk ever mattered it would have already regressed when the driver switched from blindly writing 0xf to only setting the bits that were already set in ->port_map.
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/12/19 2:06 PM, Christoph Hellwig wrote: > On Mon, Aug 12, 2019 at 05:49:29PM +, Stephen Douthit wrote: >> Does anyone know the background of the original PCS workaround? > > Based on a few git-blame iterations on history.git the original PCS > handling (just when initializing) goes back to this BK commit: > > -- > From c0835b838e76c9500facad05dc305170a1a577a8 Mon Sep 17 00:00:00 2001 > From: Jeff Garzik > Date: Thu, 14 Oct 2004 16:11:44 -0400 Thanks for digging, this is definitely further back than I looked. > Subject: [libata ahci] fix several bugs > > * PCI IDs from test version didn't make it into mainline... doh > * do all command setup in ->qc_prep > * phy_reset routine that does signature check > * check SATA phy for errors > * reset hardware from scratch, in case card BIOS didn't run > * implement staggered spinup by default > * adding additional debugging output [snip] > @@ -236,7 +238,9 @@ static struct ata_port_info ahci_port_info[] = { > }; > > static struct pci_device_id ahci_pci_tbl[] = { > - { PCI_VENDOR_ID_INTEL, 0x, PCI_ANY_ID, PCI_ANY_ID, 0, 0, > + { PCI_VENDOR_ID_INTEL, 0x2652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, > + board_ahci }, > + { PCI_VENDOR_ID_INTEL, 0x2653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, These look to be for the ICH6, and at these early days Intel looks to be the only vendor in the list. That would explain the lack of a vendor guard on the PCS poke below. > board_ahci }, > { } /* terminate list */ > }; [snip] > static int ahci_host_init(struct ata_probe_ent *probe_ent) > { > struct ahci_host_priv *hpriv = probe_ent->private_data; > struct pci_dev *pdev = probe_ent->pdev; > - void *mmio = probe_ent->mmio_base; > - u32 tmp; > - unsigned int i, using_dac; > + void __iomem *mmio = probe_ent->mmio_base; > + u32 tmp, cap_save; > + u16 tmp16; > + unsigned int i, j, using_dac; > int rc; > + void __iomem *port_mmio; > + > + cap_save = readl(mmio + HOST_CAP); > + cap_save &= ( (1<<28) | (1<<17) ); > + cap_save |= (1 << 27); > > /* global controller reset */ > tmp = readl(mmio + HOST_CTL); > @@ -698,23 +747,22 @@ static int ahci_host_init(struct ata_probe_ent > *probe_ent) > return -EIO; > } > > - /* make sure we're in AHCI mode, with irq disabled */ > - if ((tmp & (HOST_AHCI_EN | HOST_IRQ_EN)) != HOST_AHCI_EN) { > - tmp |= HOST_AHCI_EN; > - tmp &= ~HOST_IRQ_EN; > - writel(tmp, mmio + HOST_CTL); > - readl(mmio + HOST_CTL); /* flush */ > - } > - tmp = readl(mmio + HOST_CTL); > - if ((tmp & (HOST_AHCI_EN | HOST_IRQ_EN)) != HOST_AHCI_EN) { > - printk(KERN_ERR DRV_NAME "(%s): AHCI enable failed (0x%x)\n", > - pci_name(pdev), tmp); > - return -EIO; > - } > + writel(HOST_AHCI_EN, mmio + HOST_CTL); > + (void) readl(mmio + HOST_CTL); /* flush */ > + writel(cap_save, mmio + HOST_CAP); > + writel(0xf, mmio + HOST_PORTS_IMPL); > + (void) readl(mmio + HOST_PORTS_IMPL); /* flush */ > + > + pci_read_config_word(pdev, 0x92, ); > + tmp16 |= 0xf; > + pci_write_config_word(pdev, 0x92, tmp16); Not much to explain why this is here unfortunately... Maybe this isn't so much a workaround as an implementation specific quirk. If we can't rely on 100% of BIOS implementations to have set PCS to match Ports Implemented (probably a safe bet) then we still need the PCS poke code. In that case we're back to Christoph's question of if there's a better way of figuring out where PCS lives than checking device IDs. In the meantime on Denverton 0x92 contains the Port Disable bits of the MAP register. Since these are write-once BIOS should have locked them already so we probably won't break anything poking them until a solution is identified. I don't think we want to rely on that assumption in the long term though.
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On Mon, Aug 12, 2019 at 05:49:29PM +, Stephen Douthit wrote: > Does anyone know the background of the original PCS workaround? Based on a few git-blame iterations on history.git the original PCS handling (just when initializing) goes back to this BK commit: -- >From c0835b838e76c9500facad05dc305170a1a577a8 Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Thu, 14 Oct 2004 16:11:44 -0400 Subject: [libata ahci] fix several bugs * PCI IDs from test version didn't make it into mainline... doh * do all command setup in ->qc_prep * phy_reset routine that does signature check * check SATA phy for errors * reset hardware from scratch, in case card BIOS didn't run * implement staggered spinup by default * adding additional debugging output --- drivers/scsi/ahci.c | 150 1 file changed, 109 insertions(+), 41 deletions(-) diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c index e2fdeb8b857e..408ecc527b59 100644 --- a/drivers/scsi/ahci.c +++ b/drivers/scsi/ahci.c @@ -38,7 +38,7 @@ #include #define DRV_NAME "ahci" -#define DRV_VERSION"0.10" +#define DRV_VERSION"0.11" enum { @@ -52,6 +52,7 @@ enum { AHCI_PORT_PRIV_DMA_SZ = AHCI_CMD_SLOT_SZ + AHCI_CMD_TBL_SZ + AHCI_RX_FIS_SZ, AHCI_IRQ_ON_SG = (1 << 31), + AHCI_CMD_ATAPI = (1 << 5), AHCI_CMD_WRITE = (1 << 6), RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ @@ -82,8 +83,10 @@ enum { PORT_IRQ_MASK = 0x14, /* interrupt enable/disable mask */ PORT_CMD= 0x18, /* port command */ PORT_TFDATA = 0x20, /* taskfile data */ + PORT_SIG= 0x24, /* device TF signature */ PORT_CMD_ISSUE = 0x38, /* command issue */ PORT_SCR= 0x28, /* SATA phy register block */ + PORT_SCR_STAT = 0x28, /* SATA phy register: SStatus */ PORT_SCR_CTL= 0x2c, /* SATA phy register: SControl */ PORT_SCR_ERR= 0x30, /* SATA phy register: SError */ @@ -161,9 +164,9 @@ struct ahci_port_priv { static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); -static void ahci_dma_setup(struct ata_queued_cmd *qc); -static void ahci_dma_start(struct ata_queued_cmd *qc); +static int ahci_qc_issue(struct ata_queued_cmd *qc); static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs); +static void ahci_phy_reset(struct ata_port *ap); static void ahci_irq_clear(struct ata_port *ap); static void ahci_eng_timeout(struct ata_port *ap); static int ahci_port_start(struct ata_port *ap); @@ -202,13 +205,12 @@ static struct ata_port_operations ahci_ops = { .tf_read= ahci_tf_read, .check_status = ahci_check_status, .exec_command = ahci_exec_command, + .dev_select = ata_noop_dev_select, - .phy_reset = sata_phy_reset, + .phy_reset = ahci_phy_reset, - .bmdma_setup= ahci_dma_setup, - .bmdma_start= ahci_dma_start, .qc_prep= ahci_qc_prep, - .qc_issue = ata_qc_issue_prot, + .qc_issue = ahci_qc_issue, .eng_timeout= ahci_eng_timeout, @@ -236,7 +238,9 @@ static struct ata_port_info ahci_port_info[] = { }; static struct pci_device_id ahci_pci_tbl[] = { - { PCI_VENDOR_ID_INTEL, 0x, PCI_ANY_ID, PCI_ANY_ID, 0, 0, + { PCI_VENDOR_ID_INTEL, 0x2652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, + board_ahci }, + { PCI_VENDOR_ID_INTEL, 0x2653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, board_ahci }, { } /* terminate list */ }; @@ -292,6 +296,7 @@ static int ahci_port_start(struct ata_port *ap) rc = -ENOMEM; goto err_out_kfree; } + memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ); pp->rx_fis = mem; pp->rx_fis_dma = mem_dma; @@ -302,7 +307,7 @@ static int ahci_port_start(struct ata_port *ap) pp->cmd_tbl = mem; pp->cmd_tbl_dma = mem_dma; - mem2 = mem + 128; + mem2 = mem + 0x80; pp->cmd_tbl_sg = mem2; mem += AHCI_CMD_TBL_SZ; @@ -398,6 +403,29 @@ static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in, writel(val, (void *) ap->ioaddr.scr_addr + (sc_reg * 4)); } +static void ahci_phy_reset(struct ata_port *ap) +{ + void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; + struct ata_taskfile tf; + struct ata_device *dev = >device[0]; + u32 tmp; + + __sata_phy_reset(ap); + + if (ap->flags & ATA_FLAG_PORT_DISABLED) + return; + +
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/12/19 12:29 PM, Dan Williams wrote: > On Mon, Aug 12, 2019 at 6:03 AM Stephen Douthit > wrote: >> >> On 8/10/19 3:43 AM, Christoph Hellwig wrote: >>> On Thu, Aug 08, 2019 at 08:24:31PM +, Stephen Douthit wrote: Intel moved the PCS register from 0x92 to 0x94 on Denverton for some reason, so now we get to check the device ID before poking it on reset. >>> >>> And now you just match on the new IDs, which means we'll perpetually >>> catch up on any new device. Dan, can you reach out inside Intel to >>> figure out if there is a way to find out the PCS register location >>> without the PCI ID check? >>> >>> static int ahci_pci_reset_controller(struct ata_host *host) { struct pci_dev *pdev = to_pci_dev(host->dev); @@ -634,13 +669,14 @@ static int ahci_pci_reset_controller(struct ata_host *host) if (pdev->vendor == PCI_VENDOR_ID_INTEL) { struct ahci_host_priv *hpriv = host->private_data; +int pcs = ahci_pcs_offset(host); u16 tmp16; /* configure PCS */ -pci_read_config_word(pdev, 0x92, ); +pci_read_config_word(pdev, pcs, ); if ((tmp16 & hpriv->port_map) != hpriv->port_map) { -tmp16 |= hpriv->port_map; -pci_write_config_word(pdev, 0x92, tmp16); +tmp16 |= hpriv->port_map & 0xff; +pci_write_config_word(pdev, pcs, tmp16); } } >>> >>> And Stephen, while you are at it, can you split this Intel-specific >>> quirk into a separate helper? >> >> I can do that. I'll wait until we hear back from Dan if there's a >> better scheme than a device ID lookup. > > Do you see any behavior change in practice with this patch? It's > purportedly to re-enable the ports after a reset, but that would only > be needed if the entire pci device reset. In this path the reset is > being performed via the host control register. That is only meant to > touch mmio registers, not config registers. So, as far as I can see > this register bit twiddling after reset has never been necessary. Not on Denverton. I have seen AHCI reset issues on Avoton/Rangeley, but I'd have to go digging at this point to know for sure if they were fixed solely by the ahci_avn_hardreset() workaround, or that in combination with the existing PCS workaround. I found this not because of failure I saw in Linux, but because I was using the Linux driver as reference while debugging the u-boot AHCI driver. When I couldn't find config space offset 0x92 defined in the Denverton EDS I went digging, and that's where the patch comes from. I wasn't quickly able to find what chipset the PCS workaround was added for. If it's for an obsolete chipset then dropping this entirely would be cleaner. Does anyone know the background of the original PCS workaround?
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On Mon, Aug 12, 2019 at 6:03 AM Stephen Douthit wrote: > > On 8/10/19 3:43 AM, Christoph Hellwig wrote: > > On Thu, Aug 08, 2019 at 08:24:31PM +, Stephen Douthit wrote: > >> Intel moved the PCS register from 0x92 to 0x94 on Denverton for some > >> reason, so now we get to check the device ID before poking it on reset. > > > > And now you just match on the new IDs, which means we'll perpetually > > catch up on any new device. Dan, can you reach out inside Intel to > > figure out if there is a way to find out the PCS register location > > without the PCI ID check? > > > > > >> static int ahci_pci_reset_controller(struct ata_host *host) > >> { > >> struct pci_dev *pdev = to_pci_dev(host->dev); > >> @@ -634,13 +669,14 @@ static int ahci_pci_reset_controller(struct ata_host > >> *host) > >> > >> if (pdev->vendor == PCI_VENDOR_ID_INTEL) { > >> struct ahci_host_priv *hpriv = host->private_data; > >> +int pcs = ahci_pcs_offset(host); > >> u16 tmp16; > >> > >> /* configure PCS */ > >> -pci_read_config_word(pdev, 0x92, ); > >> +pci_read_config_word(pdev, pcs, ); > >> if ((tmp16 & hpriv->port_map) != hpriv->port_map) { > >> -tmp16 |= hpriv->port_map; > >> -pci_write_config_word(pdev, 0x92, tmp16); > >> +tmp16 |= hpriv->port_map & 0xff; > >> +pci_write_config_word(pdev, pcs, tmp16); > >> } > >> } > > > > And Stephen, while you are at it, can you split this Intel-specific > > quirk into a separate helper? > > I can do that. I'll wait until we hear back from Dan if there's a > better scheme than a device ID lookup. Do you see any behavior change in practice with this patch? It's purportedly to re-enable the ports after a reset, but that would only be needed if the entire pci device reset. In this path the reset is being performed via the host control register. That is only meant to touch mmio registers, not config registers. So, as far as I can see this register bit twiddling after reset has never been necessary.
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/12/19 6:02 AM, Stephen Douthit wrote: > On 8/10/19 3:43 AM, Christoph Hellwig wrote: >> On Thu, Aug 08, 2019 at 08:24:31PM +, Stephen Douthit wrote: >>> Intel moved the PCS register from 0x92 to 0x94 on Denverton for some >>> reason, so now we get to check the device ID before poking it on reset. >> >> And now you just match on the new IDs, which means we'll perpetually >> catch up on any new device. Dan, can you reach out inside Intel to >> figure out if there is a way to find out the PCS register location >> without the PCI ID check? >> >> >>>static int ahci_pci_reset_controller(struct ata_host *host) >>>{ >>> struct pci_dev *pdev = to_pci_dev(host->dev); >>> @@ -634,13 +669,14 @@ static int ahci_pci_reset_controller(struct ata_host >>> *host) >>> >>> if (pdev->vendor == PCI_VENDOR_ID_INTEL) { >>> struct ahci_host_priv *hpriv = host->private_data; >>> + int pcs = ahci_pcs_offset(host); >>> u16 tmp16; >>> >>> /* configure PCS */ >>> - pci_read_config_word(pdev, 0x92, ); >>> + pci_read_config_word(pdev, pcs, ); >>> if ((tmp16 & hpriv->port_map) != hpriv->port_map) { >>> - tmp16 |= hpriv->port_map; >>> - pci_write_config_word(pdev, 0x92, tmp16); >>> + tmp16 |= hpriv->port_map & 0xff; >>> + pci_write_config_word(pdev, pcs, tmp16); >>> } >>> } >> >> And Stephen, while you are at it, can you split this Intel-specific >> quirk into a separate helper? > > I can do that. I'll wait until we hear back from Dan if there's a > better scheme than a device ID lookup. I'll drop the previous series for now. -- Jens Axboe
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/10/19 3:43 AM, Christoph Hellwig wrote: > On Thu, Aug 08, 2019 at 08:24:31PM +, Stephen Douthit wrote: >> Intel moved the PCS register from 0x92 to 0x94 on Denverton for some >> reason, so now we get to check the device ID before poking it on reset. > > And now you just match on the new IDs, which means we'll perpetually > catch up on any new device. Dan, can you reach out inside Intel to > figure out if there is a way to find out the PCS register location > without the PCI ID check? > > >> static int ahci_pci_reset_controller(struct ata_host *host) >> { >> struct pci_dev *pdev = to_pci_dev(host->dev); >> @@ -634,13 +669,14 @@ static int ahci_pci_reset_controller(struct ata_host >> *host) >> >> if (pdev->vendor == PCI_VENDOR_ID_INTEL) { >> struct ahci_host_priv *hpriv = host->private_data; >> +int pcs = ahci_pcs_offset(host); >> u16 tmp16; >> >> /* configure PCS */ >> -pci_read_config_word(pdev, 0x92, ); >> +pci_read_config_word(pdev, pcs, ); >> if ((tmp16 & hpriv->port_map) != hpriv->port_map) { >> -tmp16 |= hpriv->port_map; >> -pci_write_config_word(pdev, 0x92, tmp16); >> +tmp16 |= hpriv->port_map & 0xff; >> +pci_write_config_word(pdev, pcs, tmp16); >> } >> } > > And Stephen, while you are at it, can you split this Intel-specific > quirk into a separate helper? I can do that. I'll wait until we hear back from Dan if there's a better scheme than a device ID lookup.
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On Sat, Aug 10, 2019 at 12:43 AM Christoph Hellwig wrote: > > On Thu, Aug 08, 2019 at 08:24:31PM +, Stephen Douthit wrote: > > Intel moved the PCS register from 0x92 to 0x94 on Denverton for some > > reason, so now we get to check the device ID before poking it on reset. > > And now you just match on the new IDs, which means we'll perpetually > catch up on any new device. Dan, can you reach out inside Intel to > figure out if there is a way to find out the PCS register location > without the PCI ID check? I'll ask. One guess for now is that num_ports >= 8 indicates the new layout since the old layout ran out of space, but that might fall over if the SOC uses the new layout, but implements fewer ports.
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On Thu, Aug 08, 2019 at 08:24:31PM +, Stephen Douthit wrote: > Intel moved the PCS register from 0x92 to 0x94 on Denverton for some > reason, so now we get to check the device ID before poking it on reset. And now you just match on the new IDs, which means we'll perpetually catch up on any new device. Dan, can you reach out inside Intel to figure out if there is a way to find out the PCS register location without the PCI ID check? > static int ahci_pci_reset_controller(struct ata_host *host) > { > struct pci_dev *pdev = to_pci_dev(host->dev); > @@ -634,13 +669,14 @@ static int ahci_pci_reset_controller(struct ata_host > *host) > > if (pdev->vendor == PCI_VENDOR_ID_INTEL) { > struct ahci_host_priv *hpriv = host->private_data; > + int pcs = ahci_pcs_offset(host); > u16 tmp16; > > /* configure PCS */ > - pci_read_config_word(pdev, 0x92, ); > + pci_read_config_word(pdev, pcs, ); > if ((tmp16 & hpriv->port_map) != hpriv->port_map) { > - tmp16 |= hpriv->port_map; > - pci_write_config_word(pdev, 0x92, tmp16); > + tmp16 |= hpriv->port_map & 0xff; > + pci_write_config_word(pdev, pcs, tmp16); > } > } And Stephen, while you are at it, can you split this Intel-specific quirk into a separate helper?
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/9/19 7:13 AM, Stephen Douthit wrote: > On 8/8/19 11:46 PM, Jens Axboe wrote: >> On 8/8/19 1:24 PM, Stephen Douthit wrote: >>> Intel moved the PCS register from 0x92 to 0x94 on Denverton for some >>> reason, so now we get to check the device ID before poking it on reset. >>> >>> Signed-off-by: Stephen Douthit >>> --- >>> drivers/ata/ahci.c | 42 +++--- >>> 1 file changed, 39 insertions(+), 3 deletions(-) >>> >>> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c >>> index f7652baa6337..7090c7754fc2 100644 >>> --- a/drivers/ata/ahci.c >>> +++ b/drivers/ata/ahci.c >>> @@ -623,6 +623,41 @@ static void ahci_pci_save_initial_config(struct >>> pci_dev *pdev, >>> ahci_save_initial_config(>dev, hpriv); >>> } >>> >>> +/* >>> + * Intel moved the PCS register on the Denverton AHCI controller, see which >>> + * offset this controller is using >>> + */ >>> +static int ahci_pcs_offset(struct ata_host *host) >>> +{ >>> + struct pci_dev *pdev = to_pci_dev(host->dev); >>> + >>> + switch (pdev->device) { >>> + case 0x19b0: >>> + case 0x19b1: >>> + case 0x19b2: >>> + case 0x19b3: >>> + case 0x19b4: >>> + case 0x19b5: >>> + case 0x19b6: >>> + case 0x19b7: >>> + case 0x19bE: >>> + case 0x19bF: >>> + case 0x19c0: >>> + case 0x19c1: >>> + case 0x19c2: >>> + case 0x19c3: >>> + case 0x19c4: >>> + case 0x19c5: >>> + case 0x19c6: >>> + case 0x19c7: >>> + case 0x19cE: >>> + case 0x19cF: >> >> Any particular reason why you made some of hex alphas upper case? > > No good reason. These were copied from the ahci_pci_tbl above and I > didn't notice the mixed case. Ah I see. > I'll resend. > > Would you like a separate cleanup patch for ahci_pci_tbl as well? Yes please, I have a hard time reading the weird mixed case. -- Jens Axboe
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/8/19 11:46 PM, Jens Axboe wrote: > On 8/8/19 1:24 PM, Stephen Douthit wrote: >> Intel moved the PCS register from 0x92 to 0x94 on Denverton for some >> reason, so now we get to check the device ID before poking it on reset. >> >> Signed-off-by: Stephen Douthit >> --- >>drivers/ata/ahci.c | 42 +++--- >>1 file changed, 39 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c >> index f7652baa6337..7090c7754fc2 100644 >> --- a/drivers/ata/ahci.c >> +++ b/drivers/ata/ahci.c >> @@ -623,6 +623,41 @@ static void ahci_pci_save_initial_config(struct pci_dev >> *pdev, >> ahci_save_initial_config(>dev, hpriv); >>} >> >> +/* >> + * Intel moved the PCS register on the Denverton AHCI controller, see which >> + * offset this controller is using >> + */ >> +static int ahci_pcs_offset(struct ata_host *host) >> +{ >> +struct pci_dev *pdev = to_pci_dev(host->dev); >> + >> +switch (pdev->device) { >> +case 0x19b0: >> +case 0x19b1: >> +case 0x19b2: >> +case 0x19b3: >> +case 0x19b4: >> +case 0x19b5: >> +case 0x19b6: >> +case 0x19b7: >> +case 0x19bE: >> +case 0x19bF: >> +case 0x19c0: >> +case 0x19c1: >> +case 0x19c2: >> +case 0x19c3: >> +case 0x19c4: >> +case 0x19c5: >> +case 0x19c6: >> +case 0x19c7: >> +case 0x19cE: >> +case 0x19cF: > > Any particular reason why you made some of hex alphas upper case? No good reason. These were copied from the ahci_pci_tbl above and I didn't notice the mixed case. I'll resend. Would you like a separate cleanup patch for ahci_pci_tbl as well?
Re: [PATCH] ata: ahci: Lookup PCS register offset based on PCI device ID
On 8/8/19 1:24 PM, Stephen Douthit wrote: > Intel moved the PCS register from 0x92 to 0x94 on Denverton for some > reason, so now we get to check the device ID before poking it on reset. > > Signed-off-by: Stephen Douthit > --- > drivers/ata/ahci.c | 42 +++--- > 1 file changed, 39 insertions(+), 3 deletions(-) > > diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c > index f7652baa6337..7090c7754fc2 100644 > --- a/drivers/ata/ahci.c > +++ b/drivers/ata/ahci.c > @@ -623,6 +623,41 @@ static void ahci_pci_save_initial_config(struct pci_dev > *pdev, > ahci_save_initial_config(>dev, hpriv); > } > > +/* > + * Intel moved the PCS register on the Denverton AHCI controller, see which > + * offset this controller is using > + */ > +static int ahci_pcs_offset(struct ata_host *host) > +{ > + struct pci_dev *pdev = to_pci_dev(host->dev); > + > + switch (pdev->device) { > + case 0x19b0: > + case 0x19b1: > + case 0x19b2: > + case 0x19b3: > + case 0x19b4: > + case 0x19b5: > + case 0x19b6: > + case 0x19b7: > + case 0x19bE: > + case 0x19bF: > + case 0x19c0: > + case 0x19c1: > + case 0x19c2: > + case 0x19c3: > + case 0x19c4: > + case 0x19c5: > + case 0x19c6: > + case 0x19c7: > + case 0x19cE: > + case 0x19cF: Any particular reason why you made some of hex alphas upper case? -- Jens Axboe