Deleted Added
full compact
28c28
< * $FreeBSD: head/sys/dev/ata/ata-all.c 51972 1999-10-07 02:17:21Z msmith $
---
> * $FreeBSD: head/sys/dev/ata/ata-all.c 52067 1999-10-09 19:57:13Z sos $
39a40
> #include "opt_ata.h"
80,82d80
< #if NPCI > 0
< static void promise_intr(void *);
< #endif
84a83
> static int8_t *active2str(int32_t);
86c85,86
< static int32_t atanlun = 0;
---
> /* local vars */
> static int32_t atanlun = 2;
88a89
> MALLOC_DEFINE(M_ATA, "ATA generic", "ATA driver generic layer");
92,95c93,96
< {0x0006d041, "Generic ESDI/IDE/ATA controller"}, /* PNP0600 */
< {0x0106d041, "Plus Hardcard II"}, /* PNP0601 */
< {0x0206d041, "Plus Hardcard IIXL/EZ"}, /* PNP0602 */
< {0x0306d041, "Generic ATA"}, /* PNP0603 */
---
> {0x0006d041, "Generic ESDI/IDE/ATA controller"}, /* PNP0600 */
> {0x0106d041, "Plus Hardcard II"}, /* PNP0601 */
> {0x0206d041, "Plus Hardcard IIXL/EZ"}, /* PNP0602 */
> {0x0306d041, "Generic ATA"}, /* PNP0603 */
185a187
> /* supported chipsets */
191a194,195
> case 0x522910b9:
> return "AcerLabs Aladdin IDE controller";
196,197d199
< case 0x522910b9:
< return "AcerLabs Aladdin IDE controller";
199a202,203
>
> /* unsupported but known chipsets, generic DMA only */
202c206
< return "VIA Apollo IDE controller";
---
> return "VIA Apollo IDE controller (generic mode)";
204c208
< return "CMD 640 IDE controller";
---
> return "CMD 640 IDE controller (generic mode)";
206c210
< return "CMD 646 IDE controller";
---
> return "CMD 646 IDE controller (generic mode)";
208c212
< return "Cypress 82C693 IDE controller";
---
> return "Cypress 82C693 IDE controller (generic mode)";
210c214
< return "Cyrix 5530 IDE controller";
---
> return "Cyrix 5530 IDE controller (generic mode)";
213,214c217,218
< pci_get_subclass(dev) == PCIS_STORAGE_IDE)
< return "Unknown PCI IDE controller (using generic mode)";
---
> (pci_get_subclass(dev) == PCIS_STORAGE_IDE))
> return "Unknown PCI IDE controller (generic mode)";
250,251c254,255
< printf("ata-pci%d: type=%08x class=%02x subclass=%02x cmd=%08x\n",
< unit, type, class, subclass, cmd);
---
> printf("ata-pci%d: type=%08x class=%02x subclass=%02x cmd=%08x if=%02x\n",
> unit, type, class, subclass, cmd, pci_get_progif(dev));
254,255c258,263
< /* if this is a Promise controller handle it specially */
< if (type == 0x4d33105a || type == 0x4d38105a) {
---
> if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
> iobase_1 = IO_WD1;
> altiobase_1 = iobase_1 + ATA_ALTPORT;
> irq1 = 14;
> }
> else {
258,260d265
< iobase_2 = pci_read_config(dev, 0x18, 4) & 0xfffc;
< altiobase_2 = pci_read_config(dev, 0x1c, 4) & 0xfffc;
< irq1 = irq2 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
262,264c267
< bmaddr_2 = bmaddr_1 + ATA_BM_OFFSET1;
< outb(bmaddr_1 + 0x1f, inb(bmaddr_1 + 0x1f) | 0x01);
< printf("ata-pci%d: Busmastering DMA supported\n", unit);
---
> irq1 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
266c269,274
< /* everybody else seems to do it this way */
---
>
> if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
> iobase_2 = IO_WD2;
> altiobase_2 = iobase_2 + ATA_ALTPORT;
> irq2 = 15;
> }
268,289c276,280
< if ((unit == 0) &&
< (pci_get_progif(dev) & PCIP_STORAGE_IDE_MODEPRIM) == 0) {
< iobase_1 = IO_WD1;
< altiobase_1 = iobase_1 + ATA_ALTPORT;
< irq1 = 14;
< }
< else {
< iobase_1 = pci_read_config(dev, 0x10, 4) & 0xfffc;
< altiobase_1 = pci_read_config(dev, 0x14, 4) & 0xfffc;
< irq1 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
< }
< if ((unit == 0) &&
< (pci_get_progif(dev) & PCIP_STORAGE_IDE_MODESEC) == 0) {
< iobase_2 = IO_WD2;
< altiobase_2 = iobase_2 + ATA_ALTPORT;
< irq2 = 15;
< }
< else {
< iobase_2 = pci_read_config(dev, 0x18, 4) & 0xfffc;
< altiobase_2 = pci_read_config(dev, 0x1c, 4) & 0xfffc;
< irq2 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
< }
---
> iobase_2 = pci_read_config(dev, 0x18, 4) & 0xfffc;
> altiobase_2 = pci_read_config(dev, 0x1c, 4) & 0xfffc;
> bmaddr_2 = (pci_read_config(dev, 0x20, 4) & 0xfffc) + ATA_BM_OFFSET1;
> irq2 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
> }
291,301c282,289
< /* is this controller busmaster capable ? */
< if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
< /* is busmastering support turned on ? */
< if ((pci_read_config(dev, PCI_COMMAND_STATUS_REG, 4) & 5) == 5) {
< /* is there a valid port range to connect to ? */
< if ((bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc)) {
< bmaddr_2 = bmaddr_1 + ATA_BM_OFFSET1;
< printf("ata-pci%d: Busmastering DMA supported\n", unit);
< }
< else
< printf("ata-pci%d: Busmastering DMA not configured\n",unit);
---
> /* is this controller busmaster DMA capable ? */
> if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
> /* is busmastering support turned on ? */
> if ((pci_read_config(dev, PCI_COMMAND_STATUS_REG, 4) & 5) == 5) {
> /* is there a valid port range to connect to ? */
> if ((bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc)) {
> bmaddr_2 = bmaddr_1 + ATA_BM_OFFSET1;
> printf("ata-pci%d: Busmastering DMA supported\n", unit);
304c292
< printf("ata-pci%d: Busmastering DMA not enabled\n", unit);
---
> printf("ata-pci%d: Busmastering DMA not configured\n", unit);
306a295,308
> printf("ata-pci%d: Busmastering DMA not enabled\n", unit);
> }
> else {
> /* the Promise controllers need this to support burst mode */
> if (type == 0x4d33105a || type == 0x4d38105a)
> outb(bmaddr_1 + 0x1f, inb(bmaddr_1 + 0x1f) | 0x01);
>
> /* Promise and HPT366 controllers support busmastering DMA */
> if (type == 0x4d33105a || type == 0x4d38105a || type == 0x00041103)
> printf("ata-pci%d: Busmastering DMA supported\n", unit);
>
> /* we dont know this controller, disable busmastering DMA */
> else {
> bmaddr_1 = bmaddr_2 = 0;
307a310
> }
312c315
< if (ata_probe(iobase_1, altiobase_1, bmaddr_1, dev, &lun)) {
---
> if (iobase_1 && ata_probe(iobase_1, altiobase_1, bmaddr_1, dev, &lun)) {
327,329c330,331
< irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
< RF_SHAREABLE | RF_ACTIVE);
< if (!irq)
---
> if (!(irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
> RF_SHAREABLE | RF_ACTIVE)))
331,335c333
<
< if (type == 0x4d33105a || type == 0x4d38105a)
< bus_setup_intr(dev, irq, INTR_TYPE_BIO, promise_intr, scp, &ih);
< else
< bus_setup_intr(dev, irq, INTR_TYPE_BIO, ataintr, scp, &ih);
---
> bus_setup_intr(dev, irq, INTR_TYPE_BIO, ataintr, scp, &ih);
341c339
< if (ata_probe(iobase_2, altiobase_2, bmaddr_2, dev, &lun)) {
---
> if (iobase_2 && ata_probe(iobase_2, altiobase_2, bmaddr_2, dev, &lun)) {
356,363c354,357
< if (type != 0x4d33105a && type != 0x4d38105a) {
< irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
< RF_SHAREABLE | RF_ACTIVE);
< if (!irq)
< printf("ata_pciattach: Unable to alloc interrupt\n");
<
< bus_setup_intr(dev, irq, INTR_TYPE_BIO, ataintr, scp, &ih);
< }
---
> if (!(irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
> RF_SHAREABLE | RF_ACTIVE)))
> printf("ata_pciattach: Unable to alloc interrupt\n");
> bus_setup_intr(dev, irq, INTR_TYPE_BIO, ataintr, scp, &ih);
385,397d378
<
< static void
< promise_intr(void *data)
< {
< struct ata_softc *scp = (struct ata_softc *)data;
< int32_t channel = inl((pci_read_config(scp->dev, 0x20, 4) & 0xfffc) + 0x1c);
<
< if (channel & 0x00000400)
< ataintr(data);
<
< if (channel & 0x00004000)
< ataintr(atadevices[scp->lun + 1]);
< }
404,406c385,386
< struct ata_softc *scp = atadevices[atanlun];
< int32_t mask = 0;
< int32_t lun = atanlun;
---
> struct ata_softc *scp;
> int32_t lun, mask = 0;
409,413c389,390
< #ifdef ATA_STATIC_ID
< atanlun++;
< #endif
< if (lun > MAXATA) {
< printf("ata: unit out of range(%d)\n", lun);
---
> if (atanlun > MAXATA) {
> printf("ata: unit out of range(%d)\n", atanlun);
416c393,402
< if (scp) {
---
>
> /* check if this is located at one of the std addresses */
> if (ioaddr == IO_WD1)
> lun = 0;
> else if (ioaddr == IO_WD2)
> lun = 1;
> else
> lun = atanlun++;
>
> if ((scp = atadevices[lun])) {
420c406
< scp = malloc(sizeof(struct ata_softc), M_DEVBUF, M_NOWAIT);
---
> scp = malloc(sizeof(struct ata_softc), M_ATA, M_NOWAIT);
427,428d412
< scp->unit = *unit;
< scp->lun = lun;
430a415,416
> scp->lun = lun;
> scp->unit = *unit;
511,513d496
< #ifndef ATA_STATIC_ID
< atanlun++;
< #endif
529c512,517
< scp->status = inb(scp->ioaddr + ATA_STATUS);
---
> /* is this interrupt really for this channel */
> if (scp->flags & ATA_DMA_ACTIVE)
> if (!(ata_dmastatus(scp) & ATA_BMSTAT_INTERRUPT))
> return;
> if ((scp->status = inb(scp->ioaddr + ATA_STATUS)) == ATA_S_BUSY) /*XXX SOS*/
> return;
535c523
< if (ad_interrupt(scp->running) == ATA_OP_CONTINUES)
---
> if (scp->running && (ad_interrupt(scp->running) == ATA_OP_CONTINUES))
541c529
< if (atapi_interrupt(scp->running) == ATA_OP_CONTINUES)
---
> if (scp->running && (atapi_interrupt(scp->running) == ATA_OP_CONTINUES))
548a537,539
> case ATA_REINITING:
> return;
>
582c573
< /* find & call the responsible driver if anything on ATA queue */
---
> /* find & call the responsible driver if anything on the ATA queue */
596c587
< * find & call the responsible driver if anything on ATAPI queue.
---
> * find & call the responsible driver if anything on the ATAPI queue.
599,601c590,591
< * if no request can be served, timeout a call to ata_start to
< * try again in a moment. the timeout should probably scale
< * so we dont use too much time polling for slow devices.
---
> * if the other device is an ATA disk it already had its chance above.
> * if no request can be served, timeout a call to ata_start.
604a595
> static int32_t interval = 1;
606,611c597,603
< outb(atp->controller->ioaddr + ATA_DRIVE, ATA_D_IBM | atp->unit);
< DELAY(1);
< if (!(inb(atp->controller->ioaddr + ATA_STATUS) & ATA_S_DSC)) {
< while ((atapi_request = TAILQ_NEXT(atapi_request, chain))) {
< if (atapi_request->device->unit != atp->unit) {
< struct atapi_softc *tmpatp = atapi_request->device;
---
> if (atp->flags & ATAPI_F_DSC_USED) {
> outb(atp->controller->ioaddr + ATA_DRIVE, ATA_D_IBM | atp->unit);
> DELAY(1);
> if (!(inb(atp->controller->ioaddr + ATA_STATUS) & ATA_S_DSC)) {
> while ((atapi_request = TAILQ_NEXT(atapi_request, chain))) {
> if (atapi_request->device->unit != atp->unit) {
> struct atapi_softc *tmp = atapi_request->device;
613,619c605,612
< outb(tmpatp->controller->ioaddr + ATA_DRIVE,
< ATA_D_IBM | tmpatp->unit);
< DELAY(1);
< if (!(inb(tmpatp->controller->ioaddr+ATA_STATUS)&ATA_S_DSC))
< atapi_request = NULL;
< break;
< }
---
> outb(tmp->controller->ioaddr + ATA_DRIVE,
> ATA_D_IBM | tmp->unit);
> DELAY(1);
> if (!inb(tmp->controller->ioaddr+ATA_STATUS)&ATA_S_DSC)
> atapi_request = NULL;
> break;
> }
> }
620a614,619
> if (!atapi_request) {
> timeout((timeout_t *)ata_start, atp->controller, interval++);
> return;
> }
> else
> interval = 1;
622,623d620
< if (!atapi_request)
< atapi_request = TAILQ_FIRST(&scp->atapi_queue);
651,653c648
< DELAY(1);
< outb(scp->altioaddr, ATA_A_4BIT);
< DELAY(1);
---
> DELAY(3000);
656c651
< for (timeout = 0; timeout < 300000; timeout++) {
---
> for (timeout = 0; timeout < 310000; timeout++) {
664c659
< if (!(status0 & ATA_S_BSY))
---
> if (!(status0 & ATA_S_BUSY))
667c662
< if (!(status1 & ATA_S_BSY))
---
> if (!(status1 & ATA_S_BUSY))
670c665
< if (!(status0 & ATA_S_BSY) && !(status1 & ATA_S_BSY))
---
> if (!(status0 & ATA_S_BUSY) && !(status1 & ATA_S_BUSY))
674c669,671
< if (status0 & ATA_S_BSY)
---
> DELAY(1);
> outb(scp->altioaddr, ATA_A_4BIT);
> if (status0 & ATA_S_BUSY)
676c673
< if (status1 & ATA_S_BSY)
---
> if (status1 & ATA_S_BUSY)
686c683
< int32_t mask = 0;
---
> int32_t mask = 0, omask;
687a685,686
> scp->active = ATA_REINITING;
> scp->running = NULL;
689d687
< scp->active = ATA_IDLE;
693a692
> omask = mask;
694a694,695
> if (omask != mask)
> printf(" device dissapeared! %d ", omask & ~mask);
697c698
< if (scp->devices & (ATA_ATA_MASTER))
---
> if (scp->devices & (ATA_ATA_MASTER) && scp->dev_softc[0])
699c700
< if (scp->devices & (ATA_ATA_SLAVE))
---
> if (scp->devices & (ATA_ATA_SLAVE) && scp->dev_softc[1])
703c704
< if (scp->devices & (ATA_ATAPI_MASTER))
---
> if (scp->devices & (ATA_ATAPI_MASTER) && scp->dev_softc[0])
705c706
< if (scp->devices & (ATA_ATAPI_SLAVE))
---
> if (scp->devices & (ATA_ATAPI_SLAVE) && scp->dev_softc[1])
708a710
> scp->active = ATA_IDLE;
733c735
< if (!(status & ATA_S_BSY)) {
---
> if (!(status & ATA_S_BUSY)) {
765,766c767,770
< printf("ata%d-%s: timeout waiting to give command s=%02x e=%02x\n",
< scp->lun, device?"slave":"master", scp->status, scp->error);
---
> printf("ata%d-%s: timeout waiting to give command=%02x s=%02x e=%02x\n",
> scp->lun, device ? "slave" : "master", command,
> scp->status, scp->error);
> return -1;
775,777d778
< if (scp->active != ATA_IDLE && flags != ATA_IMMEDIATE)
< printf("DANGER active=%d\n", scp->active);
<
779a781,782
> if (scp->active != ATA_IDLE)
> printf("DANGER wait_intr active=%s\n", active2str(scp->active));
790c793,796
< scp->active = ATA_IGNORE_INTR;
---
> if (scp->active != ATA_IDLE && scp->active != ATA_REINITING)
> printf("DANGER ignore_intr active=%s\n", active2str(scp->active));
> if (scp->active != ATA_REINITING)
> scp->active = ATA_IGNORE_INTR;
795d800
< default:
797a803,805
>
> default:
> printf("DANGER illegal interrupt flag=%s\n", active2str(flags));
811c819
< case ATA_MODE_DMA:
---
> case ATA_MODE_WDMA2:
813c821
< case ATA_MODE_UDMA33:
---
> case ATA_MODE_UDMA2:
815c823,825
< case ATA_MODE_UDMA66:
---
> case ATA_MODE_UDMA3:
> return "UDMA3";
> case ATA_MODE_UDMA4:
821a832,852
> static int8_t *
> active2str(int32_t active)
> {
> switch (active) {
> case ATA_IDLE:
> return("ATA_IDLE");
> case ATA_WAIT_INTR:
> return("ATA_WAIT_INTR");
> case ATA_IGNORE_INTR:
> return("ATA_IGNORE_INTR");
> case ATA_ACTIVE_ATA:
> return("ATA_ACTIVE_ATA");
> case ATA_ACTIVE_ATAPI:
> return("ATA_ACTIVE_ATAPI");
> case ATA_REINITING:
> return("ATA_REINITING");
> default:
> return("UNKNOWN");
> }
> }
>