28c28
< * $FreeBSD: head/sys/dev/ata/ata-all.c 50842 1999-09-03 10:57:17Z phk $
---
> * $FreeBSD: head/sys/dev/ata/ata-all.c 51520 1999-09-21 19:50:40Z sos $
31a32,33
> #include "apm.h"
>
32a35
>
35a39,41
> #include "atapicd.h"
> #include "atapifd.h"
> #include "atapist.h"
41a48
> #include <sys/disk.h>
52,56d58
< #include <machine/clock.h>
< #ifdef __i386__
< #include <machine/smp.h>
< #include <i386/isa/intr_machdep.h>
< #endif
62a65,72
> #include <machine/clock.h>
> #ifdef __i386__
> #include <machine/smp.h>
> #include <i386/isa/intr_machdep.h>
> #endif
> #if NAPM > 0
> #include <machine/apm_bios.h>
> #endif
63a74
> #include <dev/ata/ata-disk.h>
67,68d77
< #define UNIT(dev) (dev>>3 & 0x1f) /* assume 8 minor # per unit */
< #define MIN(a,b) ((a)>(b)?(b):(a))
70c79
< #define isa_apic_irq(x) x
---
> #define isa_apic_irq(x) x
132d140
<
174d181
<
178d184
<
202,204c208,210
< #if 0
< case 0x05711106:
< return "VIA Apollo IDE controller";
---
> case 0x05711106: /* 82c586 */
> case 0x05961106: /* 82c596 */
> return "VIA Apollo IDE controller (generic mode)";
206c212
< return "CMD 640 IDE controller";
---
> return "CMD 640 IDE controller (generic mode)";
208c214
< return "CMD 646 IDE controller";
---
> return "CMD 646 IDE controller (generic mode)";
210c216
< return "Cypress 82C693 IDE controller";
---
> return "Cypress 82C693 IDE controller (generic mode)";
212,213c218
< return "Cyrix 5530 IDE controller";
< #endif
---
> return "Cyrix 5530 IDE controller (generic mode)";
215c220
< return "Unknown PCI IDE controller (using generic mode)";
---
> return "Unknown PCI IDE controller (generic mode)";
263c268
< bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc;
---
> bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc;
293,294c298,299
< /* is this controller busmaster capable ? */
< if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
---
> /* is this controller busmaster capable ? */
> if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
297,298c302,303
< /* is there a valid port range to connect to ? */
< if ((bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc)) {
---
> /* is there a valid port range to connect to ? */
> if ((bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc)) {
301,302c306,307
< }
< else
---
> }
> else
306,308c311,313
< printf("ata-pci%d: Busmastering DMA not enabled\n", unit);
< }
< else
---
> printf("ata-pci%d: Busmastering DMA not enabled\n", unit);
> }
> else
319c324
< &bio_imask, INTR_EXCL);
---
> &bio_imask, INTR_EXCL);
334c339
< if (type == 0x4d33105a || type == 0x4d38105a)
---
> if (type == 0x4d33105a || type == 0x4d38105a)
348c353
< &bio_imask, INTR_EXCL);
---
> &bio_imask, INTR_EXCL);
358,359c363,364
< if (type != 0x4d33105a && type != 0x4d38105a) {
< irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
---
> if (type != 0x4d33105a && type != 0x4d38105a) {
> irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
361c366
< if (!irq)
---
> if (!irq)
408d412
< int32_t timeout;
436,439c440,442
< #ifdef ATA_DEBUG
< printf("ata%d: iobase=0x%04x altiobase=0x%04x\n",
< scp->lun, scp->ioaddr, scp->altioaddr);
< #endif
---
> if (bootverbose)
> printf("ata%d: iobase=0x%04x altiobase=0x%04x\n",
> scp->lun, scp->ioaddr, scp->altioaddr);
440a444
>
446c450
< DELAY(1);
---
> DELAY(1);
449c453
< mask |= 0x01;
---
> mask |= 0x01;
451,455c455,458
< mask |= 0x02;
< #ifdef ATA_DEBUG
< printf("ata%d: mask=%02x status0=%02x status1=%02x\n",
< scp->lun, mask, status0, status1);
< #endif
---
> mask |= 0x02;
> if (bootverbose)
> printf("ata%d: mask=%02x status0=%02x status1=%02x\n",
> scp->lun, mask, status0, status1);
458c461
< return 0;
---
> return 0;
460,498c463
< /* assert reset for devices and wait for completition */
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
< DELAY(1);
< outb(scp->altioaddr, ATA_A_IDS | ATA_A_RESET);
< DELAY(1000);
< outb(scp->altioaddr, ATA_A_IDS);
< DELAY(1000);
< inb(scp->ioaddr + ATA_ERROR);
< DELAY(1);
< outb(scp->altioaddr, ATA_A_4BIT);
< DELAY(1);
<
< /* wait for BUSY to go inactive */
< for (timeout = 0; timeout < 30000*10; timeout++) {
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
< DELAY(1);
< status0 = inb(scp->ioaddr + ATA_STATUS);
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
< DELAY(1);
< status1 = inb(scp->ioaddr + ATA_STATUS);
< if (mask == 0x01) /* wait for master only */
< if (!(status0 & ATA_S_BSY))
< break;
< if (mask == 0x02) /* wait for slave only */
< if (!(status1 & ATA_S_BSY))
< break;
< if (mask == 0x03) /* wait for both master & slave */
< if (!(status0 & ATA_S_BSY) && !(status1 & ATA_S_BSY))
< break;
< DELAY(100);
< }
< if (status0 & ATA_S_BSY)
< mask &= ~0x01;
< if (status1 & ATA_S_BSY)
< mask &= ~0x02;
< #ifdef ATA_DEBUG
< printf("ata%d: mask=%02x status0=%02x status1=%02x\n",
< scp->lun, mask, status0, status1);
< #endif
---
> ata_reset(scp, &mask);
501c466
< return 0;
---
> return 0;
508d472
<
522,526c486,490
< outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_MASTER));
< DELAY(1);
< outb(scp->ioaddr + ATA_ERROR, 0x58);
< outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
< if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
---
> outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_MASTER));
> DELAY(1);
> outb(scp->ioaddr + ATA_ERROR, 0x58);
> outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
> if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
529c493
< }
---
> }
532,537c496,501
< outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_SLAVE));
< DELAY(1);
< outb(scp->ioaddr + ATA_ERROR, 0x58);
< outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
< if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
< inb(scp->ioaddr + ATA_CYL_LSB) == 0xa5) {
---
> outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_SLAVE));
> DELAY(1);
> outb(scp->ioaddr + ATA_ERROR, 0x58);
> outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
> if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
> inb(scp->ioaddr + ATA_CYL_LSB) == 0xa5) {
539c503
< }
---
> }
541,543c505,506
< #ifdef ATA_DEBUG
< printf("ata%d: devices = 0x%x\n", scp->lun, scp->devices);
< #endif
---
> if (bootverbose)
> printf("ata%d: devices = 0x%x\n", scp->lun, scp->devices);
553c516
< scp->bmaddr = bmaddr;
---
> scp->bmaddr = bmaddr;
557a521,527
> #if NAPM > 0
> scp->resume_hook.ah_fun = (void *)ata_reinit;
> scp->resume_hook.ah_arg = scp;
> scp->resume_hook.ah_name = "ATA driver";
> scp->resume_hook.ah_order = APM_MID_ORDER;
> apm_hook_establish(APM_HOOK_RESUME, &scp->resume_hook);
> #endif
564,568c534
< struct ata_softc *scp;
< struct atapi_request *atapi_request;
< struct ad_request *ad_request;
< u_int8_t status;
< static int32_t intr_count = 0;
---
> struct ata_softc *scp =(struct ata_softc *)data;
570c536
< scp = (struct ata_softc *)data;
---
> scp->status = inb(scp->ioaddr + ATA_STATUS);
576,577c542
< if ((ad_request = TAILQ_FIRST(&scp->ata_queue)))
< if (ad_interrupt(ad_request) == ATA_OP_CONTINUES)
---
> if (ad_interrupt(scp->running) == ATA_OP_CONTINUES)
580a546
> #if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0
582,583c548
< if ((atapi_request = TAILQ_FIRST(&scp->atapi_queue)))
< if (atapi_interrupt(atapi_request) == ATA_OP_CONTINUES)
---
> if (atapi_interrupt(scp->running) == ATA_OP_CONTINUES)
586c551
<
---
> #endif
596,599c561,568
< status = inb(scp->ioaddr + ATA_STATUS);
< if (intr_count++ < 10)
< printf("ata%d: unwanted interrupt %d status = %02x\n",
< scp->lun, intr_count, status);
---
> #ifdef ATA_DEBUG
> {
> static int32_t intr_count = 0;
> if (intr_count++ < 10)
> printf("ata%d: unwanted interrupt %d status = %02x\n",
> scp->lun, intr_count, scp->status);
> }
> #endif
602a572
> scp->running = NULL;
615,616c585
< if (scp->active != ATA_IDLE) {
< printf("ata: unwanted ata_start\n");
---
> if (scp->active != ATA_IDLE)
618d586
< }
622a591
> TAILQ_REMOVE(&scp->ata_queue, ad_request, chain);
624c593,594
< ad_transfer(ad_request);
---
> scp->running = ad_request;
> ad_transfer(ad_request);
626c596
< printf("ata_start: started ata, leaving\n");
---
> printf("ata_start: started ata, leaving\n");
631,632c601,609
<
< /* find & call the responsible driver if anything on ATAPI queue */
---
> #if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0
> /*
> * find & call the responsible driver if anything on ATAPI queue.
> * check for device busy by polling the DSC bit, if busy, check
> * for requests to the other device on the channel (if any).
> * 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.
> */
634c611,635
< scp->active = ATA_ACTIVE_ATAPI;
---
> struct atapi_softc *atp = atapi_request->device;
>
> 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;
>
> 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;
> }
> }
> }
> if (!atapi_request) {
> timeout((timeout_t*)ata_start, scp, 1);
> return;
> }
> TAILQ_REMOVE(&scp->atapi_queue, atapi_request, chain);
> scp->active = ATA_ACTIVE_ATAPI;
> scp->running = atapi_request;
637c638
< printf("ata_start: started atapi, leaving\n");
---
> printf("ata_start: started atapi, leaving\n");
640a642
> #endif
642a645,691
> void
> ata_reset(struct ata_softc *scp, int32_t *mask)
> {
> int32_t timeout;
> int8_t status0, status1;
>
> /* reset channel */
> outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
> DELAY(1);
> inb(scp->ioaddr + ATA_STATUS);
> outb(scp->altioaddr, ATA_A_IDS | ATA_A_RESET);
> DELAY(10000);
> outb(scp->altioaddr, ATA_A_IDS);
> DELAY(10000);
> inb(scp->ioaddr + ATA_ERROR);
> DELAY(1);
> outb(scp->altioaddr, ATA_A_4BIT);
> DELAY(1);
>
> /* wait for BUSY to go inactive */
> for (timeout = 0; timeout < 300000; timeout++) {
> outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
> DELAY(1);
> status0 = inb(scp->ioaddr + ATA_STATUS);
> outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
> DELAY(1);
> status1 = inb(scp->ioaddr + ATA_STATUS);
> if (*mask == 0x01) /* wait for master only */
> if (!(status0 & ATA_S_BSY))
> break;
> if (*mask == 0x02) /* wait for slave only */
> if (!(status1 & ATA_S_BSY))
> break;
> if (*mask == 0x03) /* wait for both master & slave */
> if (!(status0 & ATA_S_BSY) && !(status1 & ATA_S_BSY))
> break;
> DELAY(100);
> }
> if (status0 & ATA_S_BSY)
> *mask &= ~0x01;
> if (status1 & ATA_S_BSY)
> *mask &= ~0x02;
> if (bootverbose)
> printf("ata%d: mask=%02x status0=%02x status1=%02x\n",
> scp->lun, *mask, status0, status1);
> }
>
643a693,722
> ata_reinit(struct ata_softc *scp)
> {
> int32_t mask = 0;
>
> printf("ata%d: resetting devices .. ", scp->lun);
> scp->active = ATA_IDLE;
> if (scp->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER))
> mask |= 0x01;
> if (scp->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE))
> mask |= 0x02;
> ata_reset(scp, &mask);
>
> #if NATADISK > 0
> if (scp->devices & (ATA_ATA_MASTER))
> ad_reinit((struct ad_softc *)scp->dev_softc[0]);
> if (scp->devices & (ATA_ATA_SLAVE))
> ad_reinit((struct ad_softc *)scp->dev_softc[1]);
> #endif
> #if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0
> if (scp->devices & (ATA_ATAPI_MASTER))
> atapi_reinit((struct atapi_softc *)scp->dev_softc[0]);
> if (scp->devices & (ATA_ATAPI_SLAVE))
> atapi_reinit((struct atapi_softc *)scp->dev_softc[1]);
> #endif
> printf("done\n");
> ata_start(scp);
> return 0;
> }
>
> int32_t
649c728
< while (timeout++ <= 500000) { /* timeout 5 secs */
---
> while (timeout <= 5000000) { /* timeout 5 secs */
654c733
< printf("ata%d: %s: no status, reselecting device\n",
---
> printf("ata%d: %s: no status, reselecting device\n",
656c735
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
---
> outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
668,669c747,749
< }
< if (timeout > 1000)
---
> }
> if (timeout > 1000) {
> timeout += 1000;
671c751,753
< else
---
> }
> else {
> timeout += 10;
672a755
> }
683c766,769
< printf("ata%d: ata_command: addr=%04x, device=%02x, cmd=%02x, c=%d, h=%d, s=%d, count=%d, flags=%02x\n", scp->lun, scp->ioaddr, device, command, cylinder, head, sector, count, flags);
---
> printf("ata%d: ata_command: addr=%04x, device=%02x, cmd=%02x, "
> "c=%d, h=%d, s=%d, count=%d, flags=%02x\n",
> scp->lun, scp->ioaddr, device, command,
> cylinder, head, sector, count, flags);
688c774
< printf("ata%d: %s: timeout waiting to give command s=%02x e=%02x\n",
---
> printf("ata%d-%s: timeout waiting to give command s=%02x e=%02x\n",
703,704c789,790
< scp->active = ATA_WAIT_INTR;
< outb(scp->ioaddr + ATA_CMD, command);
---
> scp->active = ATA_WAIT_INTR;
> outb(scp->ioaddr + ATA_CMD, command);
713,714c799,800
< scp->active = ATA_IGNORE_INTR;
< outb(scp->ioaddr + ATA_CMD, command);
---
> scp->active = ATA_IGNORE_INTR;
> outb(scp->ioaddr + ATA_CMD, command);
719c805
< outb(scp->ioaddr + ATA_CMD, command);
---
> outb(scp->ioaddr + ATA_CMD, command);
723c809
< printf("ata_command: leaving\n");
---
> printf("ata_command: leaving\n");
727a814,830
> int8_t *
> ata_mode2str(int32_t mode)
> {
> switch (mode) {
> case ATA_MODE_PIO:
> return "PIO";
> case ATA_MODE_DMA:
> return "DMA";
> case ATA_MODE_UDMA33:
> return "UDMA33";
> case ATA_MODE_UDMA66:
> return "UDMA66";
> default:
> return "???";
> }
> }
>
734c837
< *p = ntohs(*p);
---
> *p = ntohs(*p);
743,744c846,847
< if (!*p)
< *p = ' ';
---
> if (!*p)
> *p = ' ';
746c849
< *p = 0;
---
> *p = 0;
761c864
< if (src[i] == ' ')
---
> if (src[i] == ' ') {
762a866,868
> if (i == 0)
> continue;
> }
< * $FreeBSD: head/sys/dev/ata/ata-all.c 50842 1999-09-03 10:57:17Z phk $
---
> * $FreeBSD: head/sys/dev/ata/ata-all.c 51520 1999-09-21 19:50:40Z sos $
31a32,33
> #include "apm.h"
>
32a35
>
35a39,41
> #include "atapicd.h"
> #include "atapifd.h"
> #include "atapist.h"
41a48
> #include <sys/disk.h>
52,56d58
< #include <machine/clock.h>
< #ifdef __i386__
< #include <machine/smp.h>
< #include <i386/isa/intr_machdep.h>
< #endif
62a65,72
> #include <machine/clock.h>
> #ifdef __i386__
> #include <machine/smp.h>
> #include <i386/isa/intr_machdep.h>
> #endif
> #if NAPM > 0
> #include <machine/apm_bios.h>
> #endif
63a74
> #include <dev/ata/ata-disk.h>
67,68d77
< #define UNIT(dev) (dev>>3 & 0x1f) /* assume 8 minor # per unit */
< #define MIN(a,b) ((a)>(b)?(b):(a))
70c79
< #define isa_apic_irq(x) x
---
> #define isa_apic_irq(x) x
132d140
<
174d181
<
178d184
<
202,204c208,210
< #if 0
< case 0x05711106:
< return "VIA Apollo IDE controller";
---
> case 0x05711106: /* 82c586 */
> case 0x05961106: /* 82c596 */
> return "VIA Apollo IDE controller (generic mode)";
206c212
< return "CMD 640 IDE controller";
---
> return "CMD 640 IDE controller (generic mode)";
208c214
< return "CMD 646 IDE controller";
---
> return "CMD 646 IDE controller (generic mode)";
210c216
< return "Cypress 82C693 IDE controller";
---
> return "Cypress 82C693 IDE controller (generic mode)";
212,213c218
< return "Cyrix 5530 IDE controller";
< #endif
---
> return "Cyrix 5530 IDE controller (generic mode)";
215c220
< return "Unknown PCI IDE controller (using generic mode)";
---
> return "Unknown PCI IDE controller (generic mode)";
263c268
< bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc;
---
> bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc;
293,294c298,299
< /* is this controller busmaster capable ? */
< if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
---
> /* is this controller busmaster capable ? */
> if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
297,298c302,303
< /* is there a valid port range to connect to ? */
< if ((bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc)) {
---
> /* is there a valid port range to connect to ? */
> if ((bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc)) {
301,302c306,307
< }
< else
---
> }
> else
306,308c311,313
< printf("ata-pci%d: Busmastering DMA not enabled\n", unit);
< }
< else
---
> printf("ata-pci%d: Busmastering DMA not enabled\n", unit);
> }
> else
319c324
< &bio_imask, INTR_EXCL);
---
> &bio_imask, INTR_EXCL);
334c339
< if (type == 0x4d33105a || type == 0x4d38105a)
---
> if (type == 0x4d33105a || type == 0x4d38105a)
348c353
< &bio_imask, INTR_EXCL);
---
> &bio_imask, INTR_EXCL);
358,359c363,364
< if (type != 0x4d33105a && type != 0x4d38105a) {
< irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
---
> if (type != 0x4d33105a && type != 0x4d38105a) {
> irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
361c366
< if (!irq)
---
> if (!irq)
408d412
< int32_t timeout;
436,439c440,442
< #ifdef ATA_DEBUG
< printf("ata%d: iobase=0x%04x altiobase=0x%04x\n",
< scp->lun, scp->ioaddr, scp->altioaddr);
< #endif
---
> if (bootverbose)
> printf("ata%d: iobase=0x%04x altiobase=0x%04x\n",
> scp->lun, scp->ioaddr, scp->altioaddr);
440a444
>
446c450
< DELAY(1);
---
> DELAY(1);
449c453
< mask |= 0x01;
---
> mask |= 0x01;
451,455c455,458
< mask |= 0x02;
< #ifdef ATA_DEBUG
< printf("ata%d: mask=%02x status0=%02x status1=%02x\n",
< scp->lun, mask, status0, status1);
< #endif
---
> mask |= 0x02;
> if (bootverbose)
> printf("ata%d: mask=%02x status0=%02x status1=%02x\n",
> scp->lun, mask, status0, status1);
458c461
< return 0;
---
> return 0;
460,498c463
< /* assert reset for devices and wait for completition */
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
< DELAY(1);
< outb(scp->altioaddr, ATA_A_IDS | ATA_A_RESET);
< DELAY(1000);
< outb(scp->altioaddr, ATA_A_IDS);
< DELAY(1000);
< inb(scp->ioaddr + ATA_ERROR);
< DELAY(1);
< outb(scp->altioaddr, ATA_A_4BIT);
< DELAY(1);
<
< /* wait for BUSY to go inactive */
< for (timeout = 0; timeout < 30000*10; timeout++) {
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
< DELAY(1);
< status0 = inb(scp->ioaddr + ATA_STATUS);
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
< DELAY(1);
< status1 = inb(scp->ioaddr + ATA_STATUS);
< if (mask == 0x01) /* wait for master only */
< if (!(status0 & ATA_S_BSY))
< break;
< if (mask == 0x02) /* wait for slave only */
< if (!(status1 & ATA_S_BSY))
< break;
< if (mask == 0x03) /* wait for both master & slave */
< if (!(status0 & ATA_S_BSY) && !(status1 & ATA_S_BSY))
< break;
< DELAY(100);
< }
< if (status0 & ATA_S_BSY)
< mask &= ~0x01;
< if (status1 & ATA_S_BSY)
< mask &= ~0x02;
< #ifdef ATA_DEBUG
< printf("ata%d: mask=%02x status0=%02x status1=%02x\n",
< scp->lun, mask, status0, status1);
< #endif
---
> ata_reset(scp, &mask);
501c466
< return 0;
---
> return 0;
508d472
<
522,526c486,490
< outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_MASTER));
< DELAY(1);
< outb(scp->ioaddr + ATA_ERROR, 0x58);
< outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
< if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
---
> outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_MASTER));
> DELAY(1);
> outb(scp->ioaddr + ATA_ERROR, 0x58);
> outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
> if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
529c493
< }
---
> }
532,537c496,501
< outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_SLAVE));
< DELAY(1);
< outb(scp->ioaddr + ATA_ERROR, 0x58);
< outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
< if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
< inb(scp->ioaddr + ATA_CYL_LSB) == 0xa5) {
---
> outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_SLAVE));
> DELAY(1);
> outb(scp->ioaddr + ATA_ERROR, 0x58);
> outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
> if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
> inb(scp->ioaddr + ATA_CYL_LSB) == 0xa5) {
539c503
< }
---
> }
541,543c505,506
< #ifdef ATA_DEBUG
< printf("ata%d: devices = 0x%x\n", scp->lun, scp->devices);
< #endif
---
> if (bootverbose)
> printf("ata%d: devices = 0x%x\n", scp->lun, scp->devices);
553c516
< scp->bmaddr = bmaddr;
---
> scp->bmaddr = bmaddr;
557a521,527
> #if NAPM > 0
> scp->resume_hook.ah_fun = (void *)ata_reinit;
> scp->resume_hook.ah_arg = scp;
> scp->resume_hook.ah_name = "ATA driver";
> scp->resume_hook.ah_order = APM_MID_ORDER;
> apm_hook_establish(APM_HOOK_RESUME, &scp->resume_hook);
> #endif
564,568c534
< struct ata_softc *scp;
< struct atapi_request *atapi_request;
< struct ad_request *ad_request;
< u_int8_t status;
< static int32_t intr_count = 0;
---
> struct ata_softc *scp =(struct ata_softc *)data;
570c536
< scp = (struct ata_softc *)data;
---
> scp->status = inb(scp->ioaddr + ATA_STATUS);
576,577c542
< if ((ad_request = TAILQ_FIRST(&scp->ata_queue)))
< if (ad_interrupt(ad_request) == ATA_OP_CONTINUES)
---
> if (ad_interrupt(scp->running) == ATA_OP_CONTINUES)
580a546
> #if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0
582,583c548
< if ((atapi_request = TAILQ_FIRST(&scp->atapi_queue)))
< if (atapi_interrupt(atapi_request) == ATA_OP_CONTINUES)
---
> if (atapi_interrupt(scp->running) == ATA_OP_CONTINUES)
586c551
<
---
> #endif
596,599c561,568
< status = inb(scp->ioaddr + ATA_STATUS);
< if (intr_count++ < 10)
< printf("ata%d: unwanted interrupt %d status = %02x\n",
< scp->lun, intr_count, status);
---
> #ifdef ATA_DEBUG
> {
> static int32_t intr_count = 0;
> if (intr_count++ < 10)
> printf("ata%d: unwanted interrupt %d status = %02x\n",
> scp->lun, intr_count, scp->status);
> }
> #endif
602a572
> scp->running = NULL;
615,616c585
< if (scp->active != ATA_IDLE) {
< printf("ata: unwanted ata_start\n");
---
> if (scp->active != ATA_IDLE)
618d586
< }
622a591
> TAILQ_REMOVE(&scp->ata_queue, ad_request, chain);
624c593,594
< ad_transfer(ad_request);
---
> scp->running = ad_request;
> ad_transfer(ad_request);
626c596
< printf("ata_start: started ata, leaving\n");
---
> printf("ata_start: started ata, leaving\n");
631,632c601,609
<
< /* find & call the responsible driver if anything on ATAPI queue */
---
> #if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0
> /*
> * find & call the responsible driver if anything on ATAPI queue.
> * check for device busy by polling the DSC bit, if busy, check
> * for requests to the other device on the channel (if any).
> * 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.
> */
634c611,635
< scp->active = ATA_ACTIVE_ATAPI;
---
> struct atapi_softc *atp = atapi_request->device;
>
> 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;
>
> 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;
> }
> }
> }
> if (!atapi_request) {
> timeout((timeout_t*)ata_start, scp, 1);
> return;
> }
> TAILQ_REMOVE(&scp->atapi_queue, atapi_request, chain);
> scp->active = ATA_ACTIVE_ATAPI;
> scp->running = atapi_request;
637c638
< printf("ata_start: started atapi, leaving\n");
---
> printf("ata_start: started atapi, leaving\n");
640a642
> #endif
642a645,691
> void
> ata_reset(struct ata_softc *scp, int32_t *mask)
> {
> int32_t timeout;
> int8_t status0, status1;
>
> /* reset channel */
> outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
> DELAY(1);
> inb(scp->ioaddr + ATA_STATUS);
> outb(scp->altioaddr, ATA_A_IDS | ATA_A_RESET);
> DELAY(10000);
> outb(scp->altioaddr, ATA_A_IDS);
> DELAY(10000);
> inb(scp->ioaddr + ATA_ERROR);
> DELAY(1);
> outb(scp->altioaddr, ATA_A_4BIT);
> DELAY(1);
>
> /* wait for BUSY to go inactive */
> for (timeout = 0; timeout < 300000; timeout++) {
> outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
> DELAY(1);
> status0 = inb(scp->ioaddr + ATA_STATUS);
> outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
> DELAY(1);
> status1 = inb(scp->ioaddr + ATA_STATUS);
> if (*mask == 0x01) /* wait for master only */
> if (!(status0 & ATA_S_BSY))
> break;
> if (*mask == 0x02) /* wait for slave only */
> if (!(status1 & ATA_S_BSY))
> break;
> if (*mask == 0x03) /* wait for both master & slave */
> if (!(status0 & ATA_S_BSY) && !(status1 & ATA_S_BSY))
> break;
> DELAY(100);
> }
> if (status0 & ATA_S_BSY)
> *mask &= ~0x01;
> if (status1 & ATA_S_BSY)
> *mask &= ~0x02;
> if (bootverbose)
> printf("ata%d: mask=%02x status0=%02x status1=%02x\n",
> scp->lun, *mask, status0, status1);
> }
>
643a693,722
> ata_reinit(struct ata_softc *scp)
> {
> int32_t mask = 0;
>
> printf("ata%d: resetting devices .. ", scp->lun);
> scp->active = ATA_IDLE;
> if (scp->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER))
> mask |= 0x01;
> if (scp->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE))
> mask |= 0x02;
> ata_reset(scp, &mask);
>
> #if NATADISK > 0
> if (scp->devices & (ATA_ATA_MASTER))
> ad_reinit((struct ad_softc *)scp->dev_softc[0]);
> if (scp->devices & (ATA_ATA_SLAVE))
> ad_reinit((struct ad_softc *)scp->dev_softc[1]);
> #endif
> #if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0
> if (scp->devices & (ATA_ATAPI_MASTER))
> atapi_reinit((struct atapi_softc *)scp->dev_softc[0]);
> if (scp->devices & (ATA_ATAPI_SLAVE))
> atapi_reinit((struct atapi_softc *)scp->dev_softc[1]);
> #endif
> printf("done\n");
> ata_start(scp);
> return 0;
> }
>
> int32_t
649c728
< while (timeout++ <= 500000) { /* timeout 5 secs */
---
> while (timeout <= 5000000) { /* timeout 5 secs */
654c733
< printf("ata%d: %s: no status, reselecting device\n",
---
> printf("ata%d: %s: no status, reselecting device\n",
656c735
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
---
> outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
668,669c747,749
< }
< if (timeout > 1000)
---
> }
> if (timeout > 1000) {
> timeout += 1000;
671c751,753
< else
---
> }
> else {
> timeout += 10;
672a755
> }
683c766,769
< printf("ata%d: ata_command: addr=%04x, device=%02x, cmd=%02x, c=%d, h=%d, s=%d, count=%d, flags=%02x\n", scp->lun, scp->ioaddr, device, command, cylinder, head, sector, count, flags);
---
> printf("ata%d: ata_command: addr=%04x, device=%02x, cmd=%02x, "
> "c=%d, h=%d, s=%d, count=%d, flags=%02x\n",
> scp->lun, scp->ioaddr, device, command,
> cylinder, head, sector, count, flags);
688c774
< printf("ata%d: %s: timeout waiting to give command s=%02x e=%02x\n",
---
> printf("ata%d-%s: timeout waiting to give command s=%02x e=%02x\n",
703,704c789,790
< scp->active = ATA_WAIT_INTR;
< outb(scp->ioaddr + ATA_CMD, command);
---
> scp->active = ATA_WAIT_INTR;
> outb(scp->ioaddr + ATA_CMD, command);
713,714c799,800
< scp->active = ATA_IGNORE_INTR;
< outb(scp->ioaddr + ATA_CMD, command);
---
> scp->active = ATA_IGNORE_INTR;
> outb(scp->ioaddr + ATA_CMD, command);
719c805
< outb(scp->ioaddr + ATA_CMD, command);
---
> outb(scp->ioaddr + ATA_CMD, command);
723c809
< printf("ata_command: leaving\n");
---
> printf("ata_command: leaving\n");
727a814,830
> int8_t *
> ata_mode2str(int32_t mode)
> {
> switch (mode) {
> case ATA_MODE_PIO:
> return "PIO";
> case ATA_MODE_DMA:
> return "DMA";
> case ATA_MODE_UDMA33:
> return "UDMA33";
> case ATA_MODE_UDMA66:
> return "UDMA66";
> default:
> return "???";
> }
> }
>
734c837
< *p = ntohs(*p);
---
> *p = ntohs(*p);
743,744c846,847
< if (!*p)
< *p = ' ';
---
> if (!*p)
> *p = ' ';
746c849
< *p = 0;
---
> *p = 0;
761c864
< if (src[i] == ' ')
---
> if (src[i] == ' ') {
762a866,868
> if (i == 0)
> continue;
> }