linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libata: Keep shadow last_ctl up to date during resets
@ 2009-03-10 11:38 Stuart MENEFY
  2009-03-11  7:42 ` Tejun Heo
  2009-03-13 18:58 ` Jeff Garzik
  0 siblings, 2 replies; 5+ messages in thread
From: Stuart MENEFY @ 2009-03-10 11:38 UTC (permalink / raw)
  To: linux-ide

libata keeps a shadow copy of the ATA CTL register (which is write only),
and only writes to the hardware when the required value doesn't match
the shadow. However this copy wasn't being maintained when performing
reset functions. This could cause problems for the first operation after
a reset when the correct value might not be written to the CTL register.

This problem was observed when hotplugging a drive: the identify command
was being issued with interrupts enabled, when they should have been
disabled.

Signed-off-by: Stuart Menefy <stuart.menefy@st.com>
---
 linux-2.6/drivers/ata/libata-sff.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Index: linux-2.6/drivers/ide/ide-dma-sff.c
===================================================================
--- linux-2.6.orig/drivers/ata/libata-sff.c
+++ linux-2.6/drivers/ata/libata-sff.c
@@ -2066,6 +2066,7 @@ static int ata_bus_softreset(struct ata_
 	iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr);
 	udelay(20);	/* FIXME: flush */
 	iowrite8(ap->ctl, ioaddr->ctl_addr);
+	ap->last_ctl = ap->ctl;

 	/* wait the port to become ready */
 	return ata_sff_wait_after_reset(&ap->link, devmask, deadline);
@@ -2190,8 +2191,10 @@ void ata_sff_postreset(struct ata_link *
 	}

 	/* set up device control */
-	if (ap->ioaddr.ctl_addr)
+	if (ap->ioaddr.ctl_addr) {
 		iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
+		ap->last_ctl = ap->ctl;
+	}
 }
 EXPORT_SYMBOL_GPL(ata_sff_postreset);

@@ -2534,6 +2537,7 @@ void ata_bus_reset(struct ata_port *ap)
 	if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) {
 		/* set up device control for ATA_FLAG_SATA_RESET */
 		iowrite8(ap->ctl, ioaddr->ctl_addr);
+		ap->last_ctl = ap->ctl;
 	}

 	DPRINTK("EXIT\n");

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libata: Keep shadow last_ctl up to date during resets
  2009-03-10 11:38 [PATCH] libata: Keep shadow last_ctl up to date during resets Stuart MENEFY
@ 2009-03-11  7:42 ` Tejun Heo
  2009-03-11 12:28   ` Mark Lord
  2009-03-13 18:58 ` Jeff Garzik
  1 sibling, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2009-03-11  7:42 UTC (permalink / raw)
  To: Stuart MENEFY; +Cc: linux-ide

Hello,

Stuart MENEFY wrote:
> libata keeps a shadow copy of the ATA CTL register (which is write only),
> and only writes to the hardware when the required value doesn't match
> the shadow. However this copy wasn't being maintained when performing
> reset functions. This could cause problems for the first operation after
> a reset when the correct value might not be written to the CTL register.
> 
> This problem was observed when hotplugging a drive: the identify command
> was being issued with interrupts enabled, when they should have been
> disabled.
> 
> Signed-off-by: Stuart Menefy <stuart.menefy@st.com>

Nice catch.  Maybe a nice addition would be a ata_sff_write_to_ctl()
or something which always does the right thing.

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libata: Keep shadow last_ctl up to date during resets
  2009-03-11  7:42 ` Tejun Heo
@ 2009-03-11 12:28   ` Mark Lord
  2009-03-11 13:11     ` Tejun Heo
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Lord @ 2009-03-11 12:28 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Stuart MENEFY, linux-ide

Tejun Heo wrote:
> Hello,
> 
> Stuart MENEFY wrote:
>> libata keeps a shadow copy of the ATA CTL register (which is write only),
>> and only writes to the hardware when the required value doesn't match
>> the shadow. However this copy wasn't being maintained when performing
>> reset functions. This could cause problems for the first operation after
>> a reset when the correct value might not be written to the CTL register.
>>
>> This problem was observed when hotplugging a drive: the identify command
>> was being issued with interrupts enabled, when they should have been
>> disabled.
>>
>> Signed-off-by: Stuart Menefy <stuart.menefy@st.com>
> 
> Nice catch.  Maybe a nice addition would be a ata_sff_write_to_ctl()
> or something which always does the right thing.
> 
> Acked-by: Tejun Heo <tj@kernel.org>
..

Mmm.. I wonder if this is severe enough to warrant backporting
to -stable for the past couple of releases? 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libata: Keep shadow last_ctl up to date during resets
  2009-03-11 12:28   ` Mark Lord
@ 2009-03-11 13:11     ` Tejun Heo
  0 siblings, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2009-03-11 13:11 UTC (permalink / raw)
  To: Mark Lord; +Cc: Stuart MENEFY, linux-ide

Mark Lord wrote:
> Tejun Heo wrote:
>> Hello,
>>
>> Stuart MENEFY wrote:
>>> libata keeps a shadow copy of the ATA CTL register (which is write
>>> only),
>>> and only writes to the hardware when the required value doesn't match
>>> the shadow. However this copy wasn't being maintained when performing
>>> reset functions. This could cause problems for the first operation after
>>> a reset when the correct value might not be written to the CTL register.
>>>
>>> This problem was observed when hotplugging a drive: the identify command
>>> was being issued with interrupts enabled, when they should have been
>>> disabled.
>>>
>>> Signed-off-by: Stuart Menefy <stuart.menefy@st.com>
>>
>> Nice catch.  Maybe a nice addition would be a ata_sff_write_to_ctl()
>> or something which always does the right thing.
>>
>> Acked-by: Tejun Heo <tj@kernel.org>
> ..
> 
> Mmm.. I wonder if this is severe enough to warrant backporting
> to -stable for the past couple of releases?

Yeah, I think it can be responsible for at least some of runaway IRQs
during detection on ata_piix and is likely to be a good candidate for
-stable but I think it would be better to see how it does on -rc first
for a while before pushing this -stable.  sata_nv breakages very well
showed how messed up things can get with obvious fixes.  :-)

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libata: Keep shadow last_ctl up to date during resets
  2009-03-10 11:38 [PATCH] libata: Keep shadow last_ctl up to date during resets Stuart MENEFY
  2009-03-11  7:42 ` Tejun Heo
@ 2009-03-13 18:58 ` Jeff Garzik
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff Garzik @ 2009-03-13 18:58 UTC (permalink / raw)
  To: Stuart MENEFY; +Cc: linux-ide

Stuart MENEFY wrote:
> libata keeps a shadow copy of the ATA CTL register (which is write only),
> and only writes to the hardware when the required value doesn't match
> the shadow. However this copy wasn't being maintained when performing
> reset functions. This could cause problems for the first operation after
> a reset when the correct value might not be written to the CTL register.
> 
> This problem was observed when hotplugging a drive: the identify command
> was being issued with interrupts enabled, when they should have been
> disabled.
> 
> Signed-off-by: Stuart Menefy <stuart.menefy@st.com>
> ---
>  linux-2.6/drivers/ata/libata-sff.c |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> Index: linux-2.6/drivers/ide/ide-dma-sff.c
> ===================================================================
> --- linux-2.6.orig/drivers/ata/libata-sff.c
> +++ linux-2.6/drivers/ata/libata-sff.c
> @@ -2066,6 +2066,7 @@ static int ata_bus_softreset(struct ata_
>  	iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr);
>  	udelay(20);	/* FIXME: flush */
>  	iowrite8(ap->ctl, ioaddr->ctl_addr);
> +	ap->last_ctl = ap->ctl;
> 
>  	/* wait the port to become ready */
>  	return ata_sff_wait_after_reset(&ap->link, devmask, deadline);
> @@ -2190,8 +2191,10 @@ void ata_sff_postreset(struct ata_link *
>  	}
> 
>  	/* set up device control */
> -	if (ap->ioaddr.ctl_addr)
> +	if (ap->ioaddr.ctl_addr) {
>  		iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
> +		ap->last_ctl = ap->ctl;
> +	}
>  }
>  EXPORT_SYMBOL_GPL(ata_sff_postreset);
> 
> @@ -2534,6 +2537,7 @@ void ata_bus_reset(struct ata_port *ap)
>  	if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) {
>  		/* set up device control for ATA_FLAG_SATA_RESET */
>  		iowrite8(ap->ctl, ioaddr->ctl_addr);
> +		ap->last_ctl = ap->ctl;
>  	}

applied, good catch!



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-03-13 18:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-10 11:38 [PATCH] libata: Keep shadow last_ctl up to date during resets Stuart MENEFY
2009-03-11  7:42 ` Tejun Heo
2009-03-11 12:28   ` Mark Lord
2009-03-11 13:11     ` Tejun Heo
2009-03-13 18:58 ` Jeff Garzik

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).