2004-03-22 13:23:56

by Miquel van Smoorenburg

[permalink] [raw]
Subject: ata_piix doesn't work in combined mode if master is missing.

Hello,

I have a supermicro 1U server with 2 SATA swappable drives.
The chipset is Intel ICH5, and I'm using the ata_piix.c libata
driver. Works fine!

Except that if I remove the first drive, the second drive isn't
detected anymore. Now I have those drives set up with partitioned
RAID5, and if the first drive is missing or dead the system is
supposed to boot from the second disk - the BIOS does that, but
libata doesn't see the second drive.

A normal boot looks like this (dmesg output):

libata version 1.01 loaded.
ata_piix version 1.01
ata_piix: combined mode detected
PCI: Setting latency timer of device 0000:00:1f.2 to 64
ata1: SATA max UDMA/133 cmd 0x1F0 ctl 0x3F6 bmdma 0xF000 irq 14
ata1: dev 0 cfg 49:2f00 82:7c6b 83:7b09 84:4003 85:7c69 86:3a01 87:4003 88:407f
ata1: dev 0 ATA, max UDMA/133, 160086528 sectors
ata1: dev 1 cfg 49:2f00 82:7c6b 83:7b09 84:4003 85:7c69 86:3a01 87:4003 88:407f
ata1: dev 1 ATA, max UDMA/133, 160086528 sectors
ata1: dev 0 configured for UDMA/133
ata1: dev 1 configured for UDMA/133
scsi0 : ata_piix

A boot with the first disk removed looks like this:

ata_piix: combined mode detected
ata1: SATA max UDMA/133 cmd 0x1F0 ctl 0x3F6 bmdma 0xF000 irq 14
ata1: SATA port has no device. disabling.
scsi0 : ata_piix

(Note that this is serial console output, it apparently doesn't show
the "cfg" line on the serial console).

If I patch ata_piix.c to just ifdef out the "disabled" code, then I
can actually boot and run from the second disk, dmesg output:

ata_piix version 1.01
ata_piix: combined mode detected
PCI: Setting latency timer of device 0000:00:1f.2 to 64
ata1: SATA max UDMA/133 cmd 0x1F0 ctl 0x3F6 bmdma 0xF000 irq 14
ata1: dev 1 cfg 49:2f00 82:7c6b 83:7b09 84:4003 85:7c69 86:3a01 87:4003 88:407f
ata1: dev 1 ATA, max UDMA/133, 160086528 sectors
ata1: dev 1 configured for UDMA/133
scsi0 : ata_piix

If I enable "enhanced mode" instead of "combined mode" in the BIOS,
there is no problem - but as the system normally works in both modes,
and only fails in combined mode with the first disk missing, this
is risky - if you forget to put the BIOS in enhanced mode, you'll
only find out when it's too late.

The hack I used to reckognize the second disk is below. Is it
possible to fix this properly (i.e. check for slave in combined mode) ?

Thanks,

Mike.

--- linux-2.6.5-rc1.orig/drivers/scsi/ata_piix.c 2004-03-11 03:55:27.000000000 +0100
+++ linux-2.6.5-rc1/drivers/scsi/ata_piix.c 2004-03-22 13:14:59.000000000 +0100
@@ -342,6 +342,7 @@
return;
}

+#if 0 /* XXX miquels */
/* if port enabled but no device, disable port and exit */
if (!have_dev) {
piix_sata_port_disable(ap);
@@ -349,6 +350,7 @@
ap->id);
return;
}
+#endif

ap->cbl = ATA_CBL_SATA;


Mike.
--
Netu, v qba'g yvxr gur cynvagrkg :)


2004-03-22 18:07:00

by Jeff Garzik

[permalink] [raw]
Subject: ata_piix and combined mode

Yeah, combined mode is not recommended. The device presences for
slave-only is a bit off, and also because it often massively impacts
PATA speed and/or stability.

There are a few simple things you can do though, which would fix your
problem. Here is a summary, interested in working on it? :) (or
anyone else listening)

struct ata_port::port_no is only accurate in native mode, where all PCI
BAR resources and PCI irq are active. combined mode is a subset of
legacy mode, where
a) port 0 and port 1 IO ports are standard IDE ISA register blks
b) irqs are standard legacy 14 and 15, and not shared
c) hardware pretends that SATA0/1 are master/slave.
This last introduces nastiness into most drivers, since sata
is _really_ point-to-point. Faking non-PTP this way leads
to a disconnect, because you must now map master to
port 0 or 1, and slave to the other port (yes ordering
is dynamic too).

1) short term, probably want to create a "hard_port_no" field in
ata_port, and make that reflect the true SATA hardware port number.
Then use that in the disable/enable stuff in ata_piix.c.

2) module unload disables the SATA port, but module load does not
attempt to enable the SATA port. so modprobe+rmmod+modprobe will
results in sata ports being disabled. instead, enable each sata port
(which causes the right SATA phy stuff to happen silently), wait a bit,
check for device presences, then disable the port if no device.

3) long term, since combined mode combines PATA and SATA into the same
PCI device, under the SATA PCI id, libata can drive the PATA port as
well. libata must do this anyway, for Promise, where the PATA port is
even more tightly integrated with the SATA ports.

The blocker on #3 is debugging the existing ATAPI code. Once that's
working, PATA support can be turned on -- for the cases that need it. I
still want 99% of PATA handled in drivers/ide...

Even longer term, we just need to beat hardware vendors over the head
about combining PATA and SATA into the same PCI device.

Jeff



2004-03-22 18:15:56

by Jeff Garzik

[permalink] [raw]
Subject: Re: ata_piix and combined mode

Jeff Garzik wrote:
> c) hardware pretends that SATA0/1 are master/slave.
> This last introduces nastiness into most drivers, since sata
> is _really_ point-to-point. Faking non-PTP this way leads
> to a disconnect, because you must now map master to
> port 0 or 1, and slave to the other port (yes ordering
> is dynamic too).

Just to be more clear, the assignment (routing) of PATA and SATA ports
on the ICH5 too dynamic for its own good. You must deal with

* PATA and SATA on separate PCI devices (as it should be)
* PATA and SATA on the same PCI device, where
c0 == pata0 master (master), pata1 master (slave)
c1 == sata0 (master), sata1 (master)
or
c0 == pata0 master (master), pata1 master (slave)
c1 == sata1 (master), sata0 (master)

the ICH6 follows the horror of combined mode, where c0 or c1 might be
sata ports 0/2 or 1/3 (it has 4 sata ports rather than ICH5's 2). and
PATA might be c0 or c1.

(c0 == ata channel zero, c1 == ata channel one)

Sigh.

Although not with libata, with other drivers I belive that combined mode
is fundamentally flawed. Pretending a SATA device is a PATA device
eliminates SATA-specific knowledge, such as avoiding soft-reset (SRST)
on certain SATA devices, since they will lock up on probe.

I always recommend that users avoid combined mode when their
configuration permits.

Jeff