linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH #upstream-fixes 1/3] pata_hpt366: fix clock detection
@ 2008-12-08  9:48 Tejun Heo
  2008-12-08  9:52 ` [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection Tejun Heo
  2008-12-09  5:49 ` [PATCH #upstream-fixes 1/3] pata_hpt366: fix clock detection Jeff Garzik
  0 siblings, 2 replies; 9+ messages in thread
From: Tejun Heo @ 2008-12-08  9:48 UTC (permalink / raw)
  To: Jeff Garzik, IDE/ATA development list, Alan Cox, Mark Lord,
	rob.opensuse.linux

pata_hpt366 had its clock detection wrong and detected 25Mhz as 40Mhz
and vice-versa.  Fix it.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 drivers/ata/pata_hpt366.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: work/drivers/ata/pata_hpt366.c
===================================================================
--- work.orig/drivers/ata/pata_hpt366.c
+++ work/drivers/ata/pata_hpt366.c
@@ -382,10 +382,10 @@ static int hpt36x_init_one(struct pci_de
 	/* PCI clocking determines the ATA timing values to use */
 	/* info_hpt366 is safe against re-entry so we can scribble on it */
 	switch((reg1 & 0x700) >> 8) {
-		case 5:
+		case 9:
 			hpriv = &hpt366_40;
 			break;
-		case 9:
+		case 5:
 			hpriv = &hpt366_25;
 			break;
 		default:

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

* [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection
  2008-12-08  9:48 [PATCH #upstream-fixes 1/3] pata_hpt366: fix clock detection Tejun Heo
@ 2008-12-08  9:52 ` Tejun Heo
  2008-12-08 10:01   ` [PATCH #upstream-fixes 3/3] pata_hpt366: update mode programming Tejun Heo
  2008-12-08 11:23   ` [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection Sergei Shtylyov
  2008-12-09  5:49 ` [PATCH #upstream-fixes 1/3] pata_hpt366: fix clock detection Jeff Garzik
  1 sibling, 2 replies; 9+ messages in thread
From: Tejun Heo @ 2008-12-08  9:52 UTC (permalink / raw)
  To: Jeff Garzik, IDE/ATA development list, Alan Cox, Mark Lord,
	rob.opensuse.linux

hpt366 is strange in that its cable detection register uses the higher
bit for master, so the testing should be 2 >> port_no instead of 1 <<
port_no.  Fix it.

Info provided by Alan Cox.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
---
 drivers/ata/pata_hpt366.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: work/drivers/ata/pata_hpt366.c
===================================================================
--- work.orig/drivers/ata/pata_hpt366.c
+++ work/drivers/ata/pata_hpt366.c
@@ -215,7 +215,7 @@ static int hpt36x_cable_detect(struct at
 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 
 	pci_read_config_byte(pdev, 0x5A, &ata66);
-	if (ata66 & (1 << ap->port_no))
+	if (ata66 & (2 >> ap->port_no))
 		return ATA_CBL_PATA40;
 	return ATA_CBL_PATA80;
 }

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

* [PATCH #upstream-fixes 3/3] pata_hpt366: update mode programming
  2008-12-08  9:52 ` [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection Tejun Heo
@ 2008-12-08 10:01   ` Tejun Heo
  2008-12-08 11:23   ` [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection Sergei Shtylyov
  1 sibling, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2008-12-08 10:01 UTC (permalink / raw)
  To: Jeff Garzik, IDE/ATA development list, Alan Cox, Mark Lord,
	rob.opensuse.linux

Update mode programming logic of pata_hpt366 such that it's identical
to that of IDE hpt366 driver.  The differences were...

* pata_hpt366 used 0xCFFF8FFFF to mask pio modes and 0x3FFFFFFF dma
  modes.  IDE hpt366 uses 0xC1F8FFFF for PIO, 0x303800FF for MWDMA and
  0x30070000 for UDMA.

* pata_hpt366 doesn't set 0x08000000 for PIO unless it's already set
  and always turns it on for MWDMA/UDMA.  IDE hpt366 doesn't bother
  with the bit.  It always uses what was there.

* IDE hpt366 always clears 0xC0000000.  pata_hpt366 doesn't.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
---

Alan, can you please ack this if you think it's okay.  Jeff, please
don't commit till Alan acks.  Thanks.

 drivers/ata/pata_hpt366.c |   50 ++++++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

Index: work/drivers/ata/pata_hpt366.c
===================================================================
--- work.orig/drivers/ata/pata_hpt366.c
+++ work/drivers/ata/pata_hpt366.c
@@ -188,25 +188,41 @@ static unsigned long hpt366_filter(struc
 }
 
 /**
- *	hpt36x_find_mode	-	reset the hpt36x bus
+ *	hpt36x_calc_timing	-	calculate timing value for transfer mode
  *	@ap: ATA port
- *	@speed: transfer mode
+ *	@cur_timing: current timing value
+ *	@speed: target transfer mode
  *
  *	Return the 32bit register programming information for this channel
  *	that matches the speed provided.
  */
 
-static u32 hpt36x_find_mode(struct ata_port *ap, int speed)
+static u32 hpt36x_calc_timing(struct ata_port *ap, u32 cur_timing, int speed)
 {
 	struct hpt_clock *clocks = ap->host->private_data;
+	u32 mask;
 
-	while(clocks->xfer_speed) {
+	if (speed < XFER_MW_DMA_0)
+		mask = 0xc1f8ffff;
+	else if (speed < XFER_UDMA_0)
+		mask = 0x303800ff;
+	else
+		mask = 0x30070000;
+
+	while (clocks->xfer_speed) {
 		if (clocks->xfer_speed == speed)
-			return clocks->timing;
+			break;
 		clocks++;
 	}
-	BUG();
-	return 0xffffffffU;	/* silence compiler warning */
+	if (!clocks->xfer_speed)
+		BUG();
+
+	/*
+	 * Combine new mode bits with old config bits and disable
+	 * on-chip PIO FIFO/buffer (and PIO MST mode as well) to avoid
+	 * problems handling I/O errors later.
+	 */
+	return ((cur_timing & ~mask) | (clocks->timing & mask)) & ~0xc0000000;
 }
 
 static int hpt36x_cable_detect(struct ata_port *ap)
@@ -232,8 +248,7 @@ static void hpt366_set_piomode(struct at
 {
 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 	u32 addr1, addr2;
-	u32 reg;
-	u32 mode;
+	u32 reg, timing;
 	u8 fast;
 
 	addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
@@ -247,11 +262,8 @@ static void hpt366_set_piomode(struct at
 	}
 
 	pci_read_config_dword(pdev, addr1, &reg);
-	mode = hpt36x_find_mode(ap, adev->pio_mode);
-	mode &= ~0x8000000;	/* No FIFO in PIO */
-	mode &= ~0x30070000;	/* Leave config bits alone */
-	reg &= 0x30070000;	/* Strip timing bits */
-	pci_write_config_dword(pdev, addr1, reg | mode);
+	timing = hpt36x_calc_timing(ap, reg, adev->pio_mode);
+	pci_write_config_dword(pdev, addr1, timing);
 }
 
 /**
@@ -267,8 +279,7 @@ static void hpt366_set_dmamode(struct at
 {
 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 	u32 addr1, addr2;
-	u32 reg;
-	u32 mode;
+	u32 reg, timing;
 	u8 fast;
 
 	addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
@@ -282,11 +293,8 @@ static void hpt366_set_dmamode(struct at
 	}
 
 	pci_read_config_dword(pdev, addr1, &reg);
-	mode = hpt36x_find_mode(ap, adev->dma_mode);
-	mode |= 0x8000000;	/* FIFO in MWDMA or UDMA */
-	mode &= ~0xC0000000;	/* Leave config bits alone */
-	reg &= 0xC0000000;	/* Strip timing bits */
-	pci_write_config_dword(pdev, addr1, reg | mode);
+	timing = hpt36x_calc_timing(ap, reg, adev->dma_mode);
+	pci_write_config_dword(pdev, addr1, timing);
 }
 
 static struct scsi_host_template hpt36x_sht = {

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

* Re: [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection
  2008-12-08  9:52 ` [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection Tejun Heo
  2008-12-08 10:01   ` [PATCH #upstream-fixes 3/3] pata_hpt366: update mode programming Tejun Heo
@ 2008-12-08 11:23   ` Sergei Shtylyov
  2008-12-08 11:44     ` Alan Cox
  2008-12-08 14:04     ` Sergei Shtylyov
  1 sibling, 2 replies; 9+ messages in thread
From: Sergei Shtylyov @ 2008-12-08 11:23 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Jeff Garzik, IDE/ATA development list, Alan Cox, Mark Lord,
	rob.opensuse.linux

Hello.

Tejun Heo wrote:
> hpt366 is strange in that its cable detection register uses the higher
> bit for master, so the testing should be 2 >> port_no instead of 1 <<
>   

   For primary -- the cable bits are per-channel, not per-device.

> port_no.  Fix it.
>
> Info provided by Alan Cox.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>
>   

Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>

> Index: work/drivers/ata/pata_hpt366.c
> ===================================================================
> --- work.orig/drivers/ata/pata_hpt366.c
> +++ work/drivers/ata/pata_hpt366.c
> @@ -215,7 +215,7 @@ static int hpt36x_cable_detect(struct at
>  	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
>  
>  	pci_read_config_byte(pdev, 0x5A, &ata66);
> -	if (ata66 & (1 << ap->port_no))
> +	if (ata66 & (2 >> ap->port_no))
>   

   HPT36x are single channel per function, so the shift can be removed.

MBR, Sergei



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

* Re: [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection
  2008-12-08 11:23   ` [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection Sergei Shtylyov
@ 2008-12-08 11:44     ` Alan Cox
  2008-12-08 13:59       ` Sergei Shtylyov
  2008-12-08 14:04     ` Sergei Shtylyov
  1 sibling, 1 reply; 9+ messages in thread
From: Alan Cox @ 2008-12-08 11:44 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: Tejun Heo, Jeff Garzik, IDE/ATA development list, Mark Lord,
	rob.opensuse.linux

> >  	pci_read_config_byte(pdev, 0x5A, &ata66);
> > -	if (ata66 & (1 << ap->port_no))
> > +	if (ata66 & (2 >> ap->port_no))
> >   
> 
>    HPT36x are single channel per function, so the shift can be removed.

In the case of two channels are you sure the bits appear as bit 2 in both
cases ?

Alan

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

* Re: [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection
  2008-12-08 11:44     ` Alan Cox
@ 2008-12-08 13:59       ` Sergei Shtylyov
  0 siblings, 0 replies; 9+ messages in thread
From: Sergei Shtylyov @ 2008-12-08 13:59 UTC (permalink / raw)
  To: Alan Cox
  Cc: Tejun Heo, Jeff Garzik, IDE/ATA development list, Mark Lord,
	rob.opensuse.linux

Hello.

Alan Cox wrote:

>>> 	pci_read_config_byte(pdev, 0x5A, &ata66);
>>>-	if (ata66 & (1 << ap->port_no))
>>>+	if (ata66 & (2 >> ap->port_no))

>>   HPT36x are single channel per function, so the shift can be removed.

> In the case of two channels are you sure the bits appear as bit 2 in both
> cases ?

    Oops, they don't. The cable select register (0x5a) seems to be shared by 
both functions (with function 0 representing "primary" and the function 1 
"secondary" channel). But in this case, the logic remains broken -- I don't 
think that function #1 has its ap->port_no set to 1. The IDE driver appears 
broken as well then. Damn Highpoint for their brain damaged design...

> Alan

MBR, Sergei

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

* Re: [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection
  2008-12-08 11:23   ` [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection Sergei Shtylyov
  2008-12-08 11:44     ` Alan Cox
@ 2008-12-08 14:04     ` Sergei Shtylyov
  2008-12-09  1:17       ` Tejun Heo
  1 sibling, 1 reply; 9+ messages in thread
From: Sergei Shtylyov @ 2008-12-08 14:04 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: Tejun Heo, Jeff Garzik, IDE/ATA development list, Alan Cox,
	Mark Lord, rob.opensuse.linux

Hello, I wrote:

>> hpt366 is strange in that its cable detection register uses the higher
>> bit for master, so the testing should be 2 >> port_no instead of 1 <<

>   For primary -- the cable bits are per-channel, not per-device.

>> port_no.  Fix it.

>> Info provided by Alan Cox.

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

> Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>

    I have to NAK this. HPT366 design is just too brain damaged for both IDE 
and libata drivers to get it right so far.

>> Index: work/drivers/ata/pata_hpt366.c
>> ===================================================================
>> --- work.orig/drivers/ata/pata_hpt366.c
>> +++ work/drivers/ata/pata_hpt366.c
>> @@ -215,7 +215,7 @@ static int hpt36x_cable_detect(struct at
>>      struct pci_dev *pdev = to_pci_dev(ap->host->dev);
>>  
>>      pci_read_config_byte(pdev, 0x5A, &ata66);
>> -    if (ata66 & (1 << ap->port_no))
>> +    if (ata66 & (2 >> ap->port_no))
>>   

>   HPT36x are single channel per function, so the shift can be removed.

    It should be replaced by more sophisticated logic for function 1 in fact...

MBR, Sergei


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

* Re: [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection
  2008-12-08 14:04     ` Sergei Shtylyov
@ 2008-12-09  1:17       ` Tejun Heo
  0 siblings, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2008-12-09  1:17 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: Jeff Garzik, IDE/ATA development list, Alan Cox, Mark Lord,
	rob.opensuse.linux

Sergei Shtylyov wrote:
> Hello, I wrote:
> 
>>> hpt366 is strange in that its cable detection register uses the higher
>>> bit for master, so the testing should be 2 >> port_no instead of 1 <<
> 
>>   For primary -- the cable bits are per-channel, not per-device.
> 
>>> port_no.  Fix it.
> 
>>> Info provided by Alan Cox.
> 
>>> Signed-off-by: Tejun Heo <tj@kernel.org>
> 
>> Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
> 
>    I have to NAK this. HPT366 design is just too brain damaged for both
> IDE and libata drivers to get it right so far.
> 
>>> Index: work/drivers/ata/pata_hpt366.c
>>> ===================================================================
>>> --- work.orig/drivers/ata/pata_hpt366.c
>>> +++ work/drivers/ata/pata_hpt366.c
>>> @@ -215,7 +215,7 @@ static int hpt36x_cable_detect(struct at
>>>      struct pci_dev *pdev = to_pci_dev(ap->host->dev);
>>>  
>>>      pci_read_config_byte(pdev, 0x5A, &ata66);
>>> -    if (ata66 & (1 << ap->port_no))
>>> +    if (ata66 & (2 >> ap->port_no))
>>>   
> 
>>   HPT36x are single channel per function, so the shift can be removed.
> 
>    It should be replaced by more sophisticated logic for function 1 in
> fact...

Ah... crap.  I don't know anything about this controller.  Care to
post the correct patch?  I'll be happy to test.

Thanks.

-- 
tejun

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

* Re: [PATCH #upstream-fixes 1/3] pata_hpt366: fix clock detection
  2008-12-08  9:48 [PATCH #upstream-fixes 1/3] pata_hpt366: fix clock detection Tejun Heo
  2008-12-08  9:52 ` [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection Tejun Heo
@ 2008-12-09  5:49 ` Jeff Garzik
  1 sibling, 0 replies; 9+ messages in thread
From: Jeff Garzik @ 2008-12-09  5:49 UTC (permalink / raw)
  To: Tejun Heo
  Cc: IDE/ATA development list, Alan Cox, Mark Lord, rob.opensuse.linux

Tejun Heo wrote:
> pata_hpt366 had its clock detection wrong and detected 25Mhz as 40Mhz
> and vice-versa.  Fix it.
> 
> Signed-off-by: Tejun Heo <tj@kernel.org>
> ---
>  drivers/ata/pata_hpt366.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> Index: work/drivers/ata/pata_hpt366.c
> ===================================================================
> --- work.orig/drivers/ata/pata_hpt366.c
> +++ work/drivers/ata/pata_hpt366.c
> @@ -382,10 +382,10 @@ static int hpt36x_init_one(struct pci_de
>  	/* PCI clocking determines the ATA timing values to use */
>  	/* info_hpt366 is safe against re-entry so we can scribble on it */
>  	switch((reg1 & 0x700) >> 8) {
> -		case 5:
> +		case 9:
>  			hpriv = &hpt366_40;
>  			break;
> -		case 9:
> +		case 5:
>  			hpriv = &hpt366_25;

applied #upstream-fixes

Avoiding patch #2 in this series b/c the thread seemed to indicate it 
needed more work

Avoiding patch #3 in this series awaiting Alan's ack (did I miss it?)



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

end of thread, other threads:[~2008-12-09  5:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-08  9:48 [PATCH #upstream-fixes 1/3] pata_hpt366: fix clock detection Tejun Heo
2008-12-08  9:52 ` [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection Tejun Heo
2008-12-08 10:01   ` [PATCH #upstream-fixes 3/3] pata_hpt366: update mode programming Tejun Heo
2008-12-08 11:23   ` [PATCH #upstream-fixes 2/3] pata_hpt366: fix cable detection Sergei Shtylyov
2008-12-08 11:44     ` Alan Cox
2008-12-08 13:59       ` Sergei Shtylyov
2008-12-08 14:04     ` Sergei Shtylyov
2008-12-09  1:17       ` Tejun Heo
2008-12-09  5:49 ` [PATCH #upstream-fixes 1/3] pata_hpt366: fix clock detection 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).