aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/dev/ata/ata-all.c178
-rw-r--r--sys/dev/ata/ata-all.h17
-rw-r--r--sys/dev/ata/ata-disk.c120
-rw-r--r--sys/dev/ata/ata-dma.c231
-rw-r--r--sys/dev/ata/atapi-all.c108
-rw-r--r--sys/dev/ata/atapi-cd.c344
-rw-r--r--sys/dev/ata/atapi-cd.h1
-rw-r--r--sys/dev/ata/atapi-fd.c57
-rw-r--r--sys/dev/ata/atapi-tape.c122
9 files changed, 610 insertions, 568 deletions
diff --git a/sys/dev/ata/ata-all.c b/sys/dev/ata/ata-all.c
index 6dea2251b3e5..669b53054110 100644
--- a/sys/dev/ata/ata-all.c
+++ b/sys/dev/ata/ata-all.c
@@ -47,6 +47,7 @@
#include <sys/buf.h>
#include <sys/malloc.h>
#include <sys/devicestat.h>
+#include <machine/stdarg.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/resource.h>
@@ -112,13 +113,13 @@ ata_isaprobe(device_t dev)
/* Check isapnp ids */
if (ISA_PNP_PROBE(device_get_parent(dev), dev, ata_ids) == ENXIO)
- return (ENXIO);
+ return ENXIO;
/* Allocate the port range */
rid = 0;
port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
if (!port)
- return (ENOMEM);
+ return ENOMEM;
/* check if allready in use by a PCI device */
for (ctlr = 0; ctlr < atanlun; ctlr++) {
@@ -322,10 +323,8 @@ ata_pciattach(device_t dev)
/* 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) & IOMASK)) {
+ if ((bmaddr_1 = pci_read_config(dev, 0x20, 4) & IOMASK))
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);
}
@@ -336,13 +335,11 @@ ata_pciattach(device_t dev)
if (type == 0x4d33105a || type == 0x4d38105a || type == 0x00041103) {
/* Promise and HPT366 controllers support busmastering DMA */
bmaddr_1 = pci_read_config(dev, 0x20, 4) & IOMASK;
- bmaddr_2 = (pci_read_config(dev, 0x20, 4) & IOMASK)+ATA_BM_OFFSET1;
- printf("ata-pci%d: Busmastering DMA supported\n", unit);
+ bmaddr_2 = bmaddr_1 + ATA_BM_OFFSET1;
}
- else {
+ else
/* we dont know this controller, no busmastering DMA */
printf("ata-pci%d: Busmastering DMA not supported\n", unit);
- }
}
/* do extra chipset specific setups */
@@ -382,12 +379,6 @@ ata_pciattach(device_t dev)
pci_write_config(dev, 0x50,
pci_read_config(dev, 0x50, 4) | 0x070f070f, 4);
break;
-
- case 0x00041103: /* HighPoint HPT366 controller */
- printf("hpt366: cache_line_size=0x%02x latency_timer=0x%02x min_grant=0x%02x max_latency=0x%02x\n",
- pci_read_config(dev, 0x0c, 1), pci_read_config(dev, 0x0d, 1),
- pci_read_config(dev, 0x3e, 1), pci_read_config(dev, 0x3f, 1));
-
}
/* now probe the addresse found for "real" ATA/ATAPI hardware */
@@ -506,12 +497,12 @@ ata_probe(int32_t ioaddr, int32_t altioaddr, int32_t bmaddr,
lun = atanlun++;
if ((scp = atadevices[lun])) {
- printf("ata%d: unit already attached\n", lun);
+ ata_printf(scp, -1, "unit already attached\n");
return 0;
}
scp = malloc(sizeof(struct ata_softc), M_ATA, M_NOWAIT);
if (scp == NULL) {
- printf("ata%d: failed to allocate driver storage\n", lun);
+ ata_printf(scp, -1, "failed to allocate driver storage\n");
return 0;
}
bzero(scp, sizeof(struct ata_softc));
@@ -524,8 +515,8 @@ ata_probe(int32_t ioaddr, int32_t altioaddr, int32_t bmaddr,
scp->active = ATA_IDLE;
if (bootverbose)
- printf("ata%d: iobase=0x%04x altiobase=0x%04x bmaddr=0x%04x\n",
- scp->lun, scp->ioaddr, scp->altioaddr, scp->bmaddr);
+ ata_printf(scp, -1, "iobase=0x%04x altiobase=0x%04x bmaddr=0x%04x\n",
+ scp->ioaddr, scp->altioaddr, scp->bmaddr);
/* do we have any signs of ATA/ATAPI HW being present ? */
outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
@@ -539,8 +530,8 @@ ata_probe(int32_t ioaddr, int32_t altioaddr, int32_t bmaddr,
if ((status1 & 0xf8) != 0xf8)
mask |= 0x02;
if (bootverbose)
- printf("ata%d: mask=%02x status0=%02x status1=%02x\n",
- scp->lun, mask, status0, status1);
+ ata_printf(scp, -1, "mask=%02x status0=%02x status1=%02x\n",
+ mask, status0, status1);
if (!mask) {
free(scp, M_DEVBUF);
return 0;
@@ -588,7 +579,7 @@ ata_probe(int32_t ioaddr, int32_t altioaddr, int32_t bmaddr,
}
}
if (bootverbose)
- printf("ata%d: devices = 0x%x\n", scp->lun, scp->devices);
+ ata_printf(scp, -1, "devices = 0x%x\n", scp->devices);
if (!scp->devices) {
free(scp, M_DEVBUF);
return 0;
@@ -604,14 +595,14 @@ ata_probe(int32_t ioaddr, int32_t altioaddr, int32_t bmaddr,
if (!(ata_attach_hook = (struct intr_config_hook *)
malloc(sizeof(struct intr_config_hook),
M_TEMP, M_NOWAIT))) {
- printf("ata: ERROR malloc attach_hook failed\n");
+ ata_printf(scp, -1, "ERROR malloc attach_hook failed\n");
return 0;
}
bzero(ata_attach_hook, sizeof(struct intr_config_hook));
ata_attach_hook->ich_func = ata_attach;
if (config_intrhook_establish(ata_attach_hook) != 0) {
- printf("ata: config_intrhook_establish failed\n");
+ ata_printf(scp, -1, "config_intrhook_establish failed\n");
free(ata_attach_hook, M_TEMP);
}
}
@@ -637,7 +628,6 @@ ata_attach(void *dummy)
*/
for (ctlr=0; ctlr<MAXATA; ctlr++) {
if (!atadevices[ctlr]) continue;
-
if (atadevices[ctlr]->devices & ATA_ATA_SLAVE)
if (ata_getparam(atadevices[ctlr], ATA_SLAVE, ATA_C_ATA_IDENTIFY))
atadevices[ctlr]->devices &= ~ATA_ATA_SLAVE;
@@ -684,25 +674,28 @@ ata_getparam(struct ata_softc *scp, int32_t device, u_int8_t command)
{
struct ata_params *ata_parm;
int8_t buffer[DEV_BSIZE];
+ int retry = 0;
/* select drive */
outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
DELAY(1);
- if (ata_command(scp, device, command, 0, 0, 0, 0, 0, ATA_WAIT_INTR)) {
- printf("ata%d-%s: identify failed\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave ");
- return -1;
- }
- if (ata_wait(scp, device, ATA_S_READY|ATA_S_DSC|ATA_S_DRQ)) {
- printf("ata%d-%s: drive wont come ready after identify\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave ");
- return -1;
- }
+
+ /* apparently some devices needs this repeated */
+ do {
+ if (ata_command(scp, device, command, 0, 0, 0, 0, 0, ATA_WAIT_INTR)) {
+ ata_printf(scp, device, "identify failed\n");
+ return -1;
+ }
+ if (retry++) {
+ ata_printf(scp, device, "drive wont come ready after identify\n");
+ return -1;
+ }
+ } while (ata_wait(scp, device, ATA_S_READY|ATA_S_DSC|ATA_S_DRQ));
+
insw(scp->ioaddr + ATA_DATA, buffer, sizeof(buffer)/sizeof(int16_t));
ata_parm = malloc(sizeof(struct ata_params), M_ATA, M_NOWAIT);
if (!ata_parm) {
- printf("ata%d-%s: malloc for ata_param failed\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave ");
+ ata_printf(scp, device, "malloc for ata_param failed\n");
return -1;
}
bcopy(buffer, ata_parm, sizeof(struct ata_params));
@@ -715,7 +708,7 @@ ata_getparam(struct ata_softc *scp, int32_t device, u_int8_t command)
bswap(ata_parm->revision, sizeof(ata_parm->revision));
btrim(ata_parm->revision, sizeof(ata_parm->revision));
bpack(ata_parm->revision, ata_parm->revision, sizeof(ata_parm->revision));
- scp->dev_param[(device == ATA_MASTER) ? 0 : 1] = ata_parm;
+ scp->dev_param[ATA_DEV(device)] = ata_parm;
return 0;
}
@@ -724,29 +717,13 @@ ataintr(void *data)
{
struct ata_softc *scp = (struct ata_softc *)data;
-#if NPCI > 0
/* check if this interrupt is for us (shared PCI interrupts) */
- switch (scp->chiptype) {
- case 0x00041103: /* HighPoint HPT366 controller */
- if (scp->active == ATA_IDLE)
+ /* if DMA active look at the dmastatus */
+ if ((scp->flags & ATA_DMA_ACTIVE) &&
+ !(ata_dmastatus(scp) & ATA_BMSTAT_INTERRUPT))
return;
- if (!(ata_dmastatus(scp) & ATA_BMSTAT_INTERRUPT))
- return;
- break;
-
- case 0x4d33105a: /* Promise 33's */
- case 0x4d38105a: /* Promise 66's */
- if (!(inl((pci_read_config(scp->dev, 0x20, 4) & IOMASK) + 0x1c) &
- ((scp->unit) ? 0x00004000 : 0x00000400)))
- return;
- break;
- default:
- if ((scp->flags & ATA_DMA_ACTIVE) &&
- !(ata_dmastatus(scp) & ATA_BMSTAT_INTERRUPT))
- return;
- }
-#endif
+ /* if drive is busy it didn't interrupt */
if (((scp->status = inb(scp->ioaddr + ATA_STATUS))&ATA_S_BUSY)==ATA_S_BUSY)
return;
@@ -784,8 +761,8 @@ ataintr(void *data)
{
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);
+ ata_printf(scp, -1, "unwanted interrupt %d status = %02x\n",
+ intr_count, scp->status);
}
#endif
/* return; SOS XXX */
@@ -902,8 +879,8 @@ ata_reset(struct ata_softc *scp, int32_t *mask)
if (status1 & ATA_S_BUSY)
*mask &= ~0x02;
if (bootverbose)
- printf("ata%d: mask=%02x status0=%02x status1=%02x\n",
- scp->lun, *mask, status0, status1);
+ ata_printf(scp, -1, "mask=%02x status0=%02x status1=%02x\n",
+ *mask, status0, status1);
}
int32_t
@@ -913,7 +890,7 @@ ata_reinit(struct ata_softc *scp)
scp->active = ATA_REINITING;
scp->running = NULL;
- printf("ata%d: resetting devices .. ", scp->lun);
+ ata_printf(scp, -1, "resetting devices .. ");
if (scp->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER))
mask |= 0x01;
if (scp->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE))
@@ -952,8 +929,7 @@ ata_wait(struct ata_softc *scp, int32_t device, u_int8_t mask)
/* if drive fails status, reselect the drive just to be sure */
if (scp->status == 0xff) {
- printf("ata%d-%s: no status, reselecting device\n",
- scp->lun, device?"slave":"master");
+ ata_printf(scp, device, "no status, reselecting device\n");
outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
DELAY(1);
scp->status = inb(scp->ioaddr + ATA_STATUS);
@@ -999,17 +975,16 @@ ata_command(struct ata_softc *scp, int32_t device, u_int32_t command,
u_int32_t count, u_int32_t feature, int32_t flags)
{
#ifdef ATA_DEBUG
- 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);
+ ata_printf(scp, device, "ata_command: addr=%04x, cmd=%02x, "
+ "c=%d, h=%d, s=%d, count=%d, flags=%02x\n",
+ scp->ioaddr, command, cylinder, head, sector, count, flags);
#endif
/* ready to issue command ? */
if (ata_wait(scp, device, 0) < 0) {
- 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);
+ ata_printf(scp, device,
+ "timeout waiting to give command=%02x s=%02x e=%02x\n",
+ command, scp->status, scp->error);
return -1;
}
outb(scp->ioaddr + ATA_FEATURE, feature);
@@ -1022,12 +997,13 @@ ata_command(struct ata_softc *scp, int32_t device, u_int32_t command,
switch (flags) {
case ATA_WAIT_INTR:
if (scp->active != ATA_IDLE)
- printf("WARNING: WAIT_INTR active=%s\n", active2str(scp->active));
+ ata_printf(scp, device, "WARNING: WAIT_INTR active=%s\n",
+ active2str(scp->active));
scp->active = ATA_WAIT_INTR;
asleep((caddr_t)scp, PRIBIO, "atacmd", 500);
outb(scp->ioaddr + ATA_CMD, command);
if (await(PRIBIO, 500)) {
- printf("ata_command: timeout waiting for interrupt\n");
+ ata_printf(scp, device, "ata_command: timeout waiting for intr\n");
scp->active = ATA_IDLE;
return -1;
}
@@ -1035,17 +1011,21 @@ ata_command(struct ata_softc *scp, int32_t device, u_int32_t command,
case ATA_WAIT_READY:
if (scp->active != ATA_IDLE && scp->active != ATA_REINITING)
- printf("WARNING: WAIT_READY active=%s\n", active2str(scp->active));
- scp->active = ATA_WAIT_READY;
+ ata_printf(scp, device, "WARNING: WAIT_READY active=%s\n",
+ active2str(scp->active));
+ if (scp->active != ATA_REINITING)
+ scp->active = ATA_WAIT_READY;
outb(scp->ioaddr + ATA_CMD, command);
if (ata_wait(scp, device, ATA_S_READY) < 0) {
- printf("ata%d-%s: timeout waiting for command=%02x s=%02x e=%02x\n",
- scp->lun, device ? "slave" : "master", command,
- scp->status, scp->error);
- scp->active = ATA_IDLE;
+ ata_printf(scp, device,
+ "timeout waiting for command=%02x s=%02x e=%02x\n",
+ command, scp->status, scp->error);
+ if (scp->active != ATA_REINITING)
+ scp->active = ATA_IDLE;
return -1;
}
- scp->active = ATA_IDLE;
+ if (scp->active != ATA_REINITING)
+ scp->active = ATA_IDLE;
break;
case ATA_IMMEDIATE:
@@ -1053,7 +1033,8 @@ ata_command(struct ata_softc *scp, int32_t device, u_int32_t command,
break;
default:
- printf("DANGER: illegal interrupt flag=%s\n", active2str(flags));
+ ata_printf(scp, device, "DANGER: illegal interrupt flag=%s\n",
+ active2str(flags));
}
return 0;
}
@@ -1116,17 +1097,18 @@ ata_pmode(struct ata_params *ap)
if (ap->apiomodes & 2) return 4;
if (ap->apiomodes & 1) return 3;
}
+ if (ap->opiomode == 2) return 2;
+ if (ap->opiomode == 1) return 1;
+ if (ap->opiomode == 0) return 0;
return -1;
}
int32_t
ata_wmode(struct ata_params *ap)
{
- if (ap->atavalid & ATA_FLAG_64_70) {
- if (ap->wdmamodes & 4) return 2;
- if (ap->wdmamodes & 2) return 1;
- if (ap->wdmamodes & 1) return 0;
- }
+ if (ap->wdmamodes & 4) return 2;
+ if (ap->wdmamodes & 2) return 1;
+ if (ap->wdmamodes & 1) return 0;
return -1;
}
@@ -1169,7 +1151,7 @@ bpack(int8_t *src, int8_t *dst, int32_t len)
{
int32_t i, j, blank;
- for (i = j = blank = 0 ; i < len-1; i++) {
+ for (i = j = blank = 0 ; i < len; i++) {
if (blank && src[i] == ' ') continue;
if (blank && src[i] != ' ') {
dst[j++] = src[i];
@@ -1183,5 +1165,23 @@ bpack(int8_t *src, int8_t *dst, int32_t len)
}
dst[j++] = src[i];
}
- dst[j] = 0x00;
+ if (j < len)
+ dst[j] = 0x00;
+}
+
+int32_t
+ata_printf(struct ata_softc *scp, int32_t device, const char * fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ if (device == -1)
+ ret = printf("ata%d: ", scp->lun);
+ else
+ ret = printf("ata%d-%s: ", scp->lun,
+ (device == ATA_MASTER) ? "master" : "slave");
+ va_start(ap, fmt);
+ ret += vprintf(fmt, ap);
+ va_end(ap);
+ return ret;
}
diff --git a/sys/dev/ata/ata-all.h b/sys/dev/ata/ata-all.h
index 3a0e870bc90b..2b6e720622ff 100644
--- a/sys/dev/ata/ata-all.h
+++ b/sys/dev/ata/ata-all.h
@@ -176,9 +176,9 @@ struct ata_params {
u_int8_t lbaflag :1; /* LBA supported - always 1 */
u_int8_t iordydis :1; /* IORDY may be disabled */
u_int8_t iordyflag :1; /* IORDY supported */
- u_int8_t :1;
+ u_int8_t softreset :1; /* needs softreset when busy */
u_int8_t stdby_ovlap :1; /* standby/overlap supported */
- u_int8_t :1;
+ u_int8_t queuing :1; /* supports queuing overlap */
u_int8_t idmaflag :1; /* interleaved DMA supported */
int16_t capvalidate; /* validation for above */
@@ -284,12 +284,12 @@ struct ata_softc {
u_int8_t error; /* last controller error */
int32_t active; /* active processing request */
#define ATA_IDLE 0x0
-#define ATA_IMMEDIATE 0x0
-#define ATA_WAIT_INTR 0x1
-#define ATA_WAIT_READY 0x2
-#define ATA_ACTIVE_ATA 0x3
-#define ATA_ACTIVE_ATAPI 0x4
-#define ATA_REINITING 0x5
+#define ATA_IMMEDIATE 0x1
+#define ATA_WAIT_INTR 0x2
+#define ATA_WAIT_READY 0x3
+#define ATA_ACTIVE_ATA 0x4
+#define ATA_ACTIVE_ATAPI 0x5
+#define ATA_REINITING 0x6
TAILQ_HEAD(, ad_request) ata_queue; /* head of ATA queue */
TAILQ_HEAD(, atapi_request) atapi_queue; /* head of ATAPI queue */
@@ -321,3 +321,4 @@ int32_t ata_umode(struct ata_params *);
int8_t *ata_mode2str(int32_t);
int8_t ata_pio2mode(int32_t);
int32_t ata_find_dev(device_t, int32_t);
+int32_t ata_printf(struct ata_softc *, int32_t, const char *, ...) __printflike(3, 4);
diff --git a/sys/dev/ata/ata-disk.c b/sys/dev/ata/ata-disk.c
index b52fcafecc1d..fc57baf3f624 100644
--- a/sys/dev/ata/ata-disk.c
+++ b/sys/dev/ata/ata-disk.c
@@ -160,26 +160,33 @@ ad_attach(struct ata_softc *scp, int32_t device)
if ((adp->num_tags = (AD_PARAM->queuelen & 0x1f) + 1))
adp->flags |= AD_F_TAG_ENABLED;
+ if (bootverbose) {
+ printf("ad%d: <%.40s/%.8s> ATA-%d disk at ata%d as %s\n",
+ adp->lun, AD_PARAM->model, AD_PARAM->revision,
+ ad_version(AD_PARAM->versmajor), scp->lun,
+ (adp->unit == ATA_MASTER) ? "master" : "slave ");
+
+ printf("ad%d: %luMB (%u sectors), %u cyls, %u heads, %u S/T, %u B/S\n",
+ adp->lun, adp->total_secs / ((1024L * 1024L)/DEV_BSIZE),
+ adp->total_secs,
+ adp->total_secs / (adp->heads * adp->sectors),
+ adp->heads, adp->sectors, DEV_BSIZE);
+
+ printf("ad%d: %d secs/int, %d depth queue, %s\n",
+ adp->lun, adp->transfersize / DEV_BSIZE, adp->num_tags,
+ ata_mode2str(adp->controller->mode[ATA_DEV(adp->unit)]));
- if (bootverbose)
printf("ad%d: piomode=%d dmamode=%d udmamode=%d cblid=%d\n",
adp->lun, ata_pmode(AD_PARAM), ata_wmode(AD_PARAM),
ata_umode(AD_PARAM), AD_PARAM->cblid);
- printf("ad%d: <%s/%s> ATA-%d disk at ata%d as %s\n",
- adp->lun, AD_PARAM->model, AD_PARAM->revision,
- ad_version(AD_PARAM->versmajor), scp->lun,
- (adp->unit == ATA_MASTER) ? "master" : "slave ");
-
- printf("ad%d: %luMB (%u sectors), %u cyls, %u heads, %u S/T, %u B/S\n",
- adp->lun, adp->total_secs / ((1024L * 1024L)/DEV_BSIZE),
- adp->total_secs,
- adp->total_secs / (adp->heads * adp->sectors),
- adp->heads, adp->sectors, DEV_BSIZE);
-
- printf("ad%d: %d secs/int, %d depth queue, %s\n",
- adp->lun, adp->transfersize / DEV_BSIZE, adp->num_tags,
- ata_mode2str(adp->controller->mode[ATA_DEV(adp->unit)]));
+ }
+ else
+ printf("ad%d: %luMB disk <%.40s> at ata%d as %s mode %s\n",
+ adp->lun, adp->total_secs / ((1024L * 1024L) / DEV_BSIZE),
+ AD_PARAM->model, scp->lun,
+ (adp->unit == ATA_MASTER) ? "master" : "slave ",
+ ata_mode2str(adp->controller->mode[ATA_DEV(adp->unit)]));
devstat_add_entry(&adp->stats, "ad", adp->lun, DEV_BSIZE,
DEVSTAT_NO_ORDERED_TAGS,
@@ -356,7 +363,7 @@ ad_transfer(struct ad_request *request)
count = howmany(request->bytecount, DEV_BSIZE);
if (count > 256) {
count = 256;
- printf("ad_transfer: count=%d not supported\n", count);
+ printf("ad%d: count=%d not supported\n", adp->lun, count);
}
if (adp->flags & AD_F_LBA_ENABLED) {
@@ -396,26 +403,26 @@ ad_transfer(struct ad_request *request)
if (ata_command(adp->controller, adp->unit, cmd,
cylinder, head, sector, count, 0, ATA_IMMEDIATE))
printf("ad%d: wouldn't take transfer command\n", adp->lun);
+
+ /* if this is a DMA transfer, start it, return and wait for interrupt */
+ if (request->flags & AR_F_DMA_USED) {
+ ata_dmastart(adp->controller);
+ return;
+ }
+
}
- /* if this is a DMA transaction start it, return and wait for interrupt */
- if (request->flags & AR_F_DMA_USED) {
- ata_dmastart(adp->controller);
- return;
- }
-
/* calculate this transfer length */
request->currentsize = min(request->bytecount, adp->transfersize);
/* if this is a PIO read operation, return and wait for interrupt */
- if (request->flags & AR_F_READ) {
+ if (request->flags & AR_F_READ)
return;
- }
/* ready to write PIO data ? */
if (ata_wait(adp->controller, adp->unit,
(ATA_S_READY | ATA_S_DSC | ATA_S_DRQ)) < 0)
- printf("ad_transfer: timeout waiting for DRQ");
+ printf("ad%d: timeout waiting for DRQ", adp->lun);
/* output the data */
if (adp->controller->flags & ATA_USE_16BIT)
@@ -426,8 +433,6 @@ ad_transfer(struct ad_request *request)
outsl(adp->controller->ioaddr + ATA_DATA,
(void *)((uintptr_t)request->data + request->donecount),
request->currentsize / sizeof(int32_t));
-
- request->bytecount -= request->currentsize;
}
int32_t
@@ -444,9 +449,11 @@ ad_interrupt(struct ad_request *request)
if (ata_wait(adp->controller, adp->unit, 0) < 0)
printf("ad_interrupt: timeout waiting for status");
+ /* do we have a corrected soft error ? */
if (adp->controller->status & ATA_S_CORR)
printf("ad%d: soft error ECC corrected\n", adp->lun);
+ /* did any real errors happen ? */
if ((adp->controller->status & ATA_S_ERROR) ||
(request->flags & AR_F_DMA_USED && dma_stat != ATA_BMSTAT_INTERRUPT)) {
oops:
@@ -456,7 +463,8 @@ oops:
request->blockaddr + (request->donecount / DEV_BSIZE));
/* if this is a UDMA CRC error, reinject request */
- if (adp->controller->error & ATA_E_ICRC) {
+ if (request->flags & AR_F_DMA_USED &&
+ adp->controller->error & ATA_E_ICRC) {
untimeout((timeout_t *)ad_timeout, request,request->timeout_handle);
if (request->retries++ < AD_MAX_RETRIES)
@@ -474,8 +482,7 @@ oops:
/* if using DMA, try once again in PIO mode */
if (request->flags & AR_F_DMA_USED) {
untimeout((timeout_t *)ad_timeout, request,request->timeout_handle);
- ata_dmainit(adp->controller, adp->unit,
- ata_pmode(AD_PARAM), -1, -1);
+ ata_dmainit(adp->controller, adp->unit, ata_pmode(AD_PARAM), -1,-1);
request->flags |= AR_F_FORCE_PIO;
adp->flags &= ~AD_F_DMA_ENABLED;
TAILQ_INSERT_HEAD(&adp->controller->ata_queue, request, chain);
@@ -488,10 +495,8 @@ oops:
}
/* if we arrived here with forced PIO mode, DMA doesn't work right */
- if (request->flags & AR_F_FORCE_PIO) {
- printf("ad%d: DMA problem encountered, fallback to PIO mode\n",
- adp->lun);
- }
+ if (request->flags & AR_F_FORCE_PIO)
+ printf("ad%d: DMA problem, fallback to PIO mode\n", adp->lun);
/* if this was a PIO read operation, get the data */
if (!(request->flags & AR_F_DMA_USED) &&
@@ -518,31 +523,26 @@ oops:
(void *)((uintptr_t)request->data + request->donecount),
request->currentsize / sizeof(int32_t));
- request->bytecount -= request->currentsize;
}
- /* if this was a DMA operation finish up */
- if ((request->flags & AR_F_DMA_USED) && !(request->flags & AR_F_ERROR))
+ /* finish up transfer */
+ if (request->flags & AR_F_ERROR) {
+ request->bp->b_error = EIO;
+ request->bp->b_flags |= B_ERROR;
+ }
+ else {
request->bytecount -= request->currentsize;
-
- /* finish up this tranfer, check for more work on this buffer */
- if (adp->controller->active == ATA_ACTIVE_ATA) {
- if (request->flags & AR_F_ERROR) {
- request->bp->b_error = EIO;
- request->bp->b_flags |= B_ERROR;
- }
- else {
- request->donecount += request->currentsize;
- if (request->bytecount > 0) {
- ad_transfer(request);
- return ATA_OP_CONTINUES;
- }
+ request->donecount += request->currentsize;
+ if (request->bytecount > 0) {
+ ad_transfer(request);
+ return ATA_OP_CONTINUES;
}
-
- request->bp->b_resid = request->bytecount;
- devstat_end_transaction_buf(&adp->stats, request->bp);
- biodone(request->bp);
}
+
+ request->bp->b_resid = request->bytecount;
+ devstat_end_transaction_buf(&adp->stats, request->bp);
+ biodone(request->bp);
+
/* disarm timeout for this transfer */
untimeout((timeout_t *)ad_timeout, request, request->timeout_handle);
@@ -556,16 +556,19 @@ ad_reinit(struct ad_softc *adp)
{
/* reinit disk parameters */
ata_command(adp->controller, adp->unit, ATA_C_SET_MULTI, 0, 0, 0,
- adp->transfersize / DEV_BSIZE, 0, ATA_IMMEDIATE);
- ata_wait(adp->controller, adp->unit, ATA_S_READY);
- ata_dmainit(adp->controller, adp->unit, ata_pmode(AD_PARAM),
- ata_wmode(AD_PARAM), ata_umode(AD_PARAM));
+ adp->transfersize / DEV_BSIZE, 0, ATA_WAIT_READY);
+ if (adp->flags & AD_F_DMA_ENABLED)
+ ata_dmainit(adp->controller, adp->unit, ata_pmode(AD_PARAM),
+ ata_wmode(AD_PARAM), ata_umode(AD_PARAM));
+ else
+ ata_dmainit(adp->controller, adp->unit, ata_pmode(AD_PARAM), -1, -1);
}
static void
ad_timeout(struct ad_request *request)
{
struct ad_softc *adp = request->device;
+ int32_t s = splbio();
adp->controller->running = NULL;
printf("ad%d: ad_timeout: lost disk contact - resetting\n", adp->lun);
@@ -592,6 +595,7 @@ ad_timeout(struct ad_request *request)
free(request, M_AD);
}
ata_reinit(adp->controller);
+ splx(s);
}
static int32_t
diff --git a/sys/dev/ata/ata-dma.c b/sys/dev/ata/ata-dma.c
index fe5288ba2485..82a1afbe366c 100644
--- a/sys/dev/ata/ata-dma.c
+++ b/sys/dev/ata/ata-dma.c
@@ -53,7 +53,6 @@ static void promise_timing(struct ata_softc *, int32_t, int32_t);
static void hpt366_timing(struct ata_softc *, int32_t, int32_t);
/* misc defines */
-#define MIN(a,b) ((a)>(b)?(b):(a))
#ifdef __alpha__
#undef vtophys
#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)va)
@@ -65,9 +64,8 @@ int32_t
ata_dmainit(struct ata_softc *scp, int32_t device,
int32_t apiomode, int32_t wdmamode, int32_t udmamode)
{
- int32_t devno = (scp->unit << 1) + ((device == ATA_MASTER) ? 0 : 1);
+ int32_t devno = (scp->unit << 1) + ATA_DEV(device);
int32_t error;
- void *dmatab;
if (!scp->bmaddr)
return -1;
@@ -77,23 +75,24 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
outb(scp->bmaddr + ATA_BMSTAT_PORT, inb(scp->bmaddr + ATA_BMSTAT_PORT) &
(ATA_BMSTAT_DMA_MASTER | ATA_BMSTAT_DMA_SLAVE));
if (inb(scp->bmaddr + ATA_BMSTAT_PORT) & ATA_BMSTAT_DMA_SIMPLEX) {
- printf("ata%d: simplex device, DMA on primary channel only\n",
- scp->lun);
+ ata_printf(scp, device, "simplex device, DMA on primary only\n");
return -1;
}
}
- if (!(dmatab = malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT)))
- return -1;
+ if (!scp->dmatab[ATA_DEV(device)]) {
+ void *dmatab;
- if (((uintptr_t)dmatab >> PAGE_SHIFT) ^
- (((uintptr_t)dmatab + PAGE_SIZE - 1) >> PAGE_SHIFT)) {
- printf("ata%d-%s: dmatab crosses page boundary, no DMA\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave");
- free(dmatab, M_DEVBUF);
- return -1;
+ if (!(dmatab = malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT)))
+ return -1;
+ if (((uintptr_t)dmatab >> PAGE_SHIFT) ^
+ (((uintptr_t)dmatab + PAGE_SIZE - 1) >> PAGE_SHIFT)) {
+ ata_printf(scp, device, "dmatab crosses page boundary, no DMA\n");
+ free(dmatab, M_DEVBUF);
+ return -1;
+ }
+ scp->dmatab[ATA_DEV(device)] = dmatab;
}
- scp->dmatab[(device == ATA_MASTER) ? 0 : 1] = dmatab;
switch (scp->chiptype) {
@@ -107,18 +106,17 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA2 mode on %s chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success",
- (scp->chiptype == 0x24118086) ? "ICH" :
- (scp->chiptype == 0x24218086) ? "ICH0" :"PIIX4");
+ ata_printf(scp, device, "%s setting up UDMA2 mode on %s chip\n",
+ (error) ? "failed" : "success",
+ (scp->chiptype == 0x24118086) ? "ICH" :
+ (scp->chiptype == 0x24218086) ? "ICH0" :"PIIX4");
if (!error) {
mask48 = (1 << devno) + (3 << (16 + (devno << 2)));
new48 = (1 << devno) + (2 << (16 + (devno << 2)));
pci_write_config(scp->dev, 0x48,
(pci_read_config(scp->dev, 0x48, 4) &
~mask48) | new48, 4);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA2;
return 0;
}
}
@@ -147,12 +145,11 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up WDMA2 mode on %s chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success",
- (scp->chiptype == 0x70108086) ? "PIIX3" :
- (scp->chiptype == 0x24118086) ? "ICH" :
- (scp->chiptype == 0x24218086) ? "ICH0" :"PIIX4");
+ ata_printf(scp, device, "%s setting up WDMA2 mode on %s chip\n",
+ (error) ? "failed" : "success",
+ (scp->chiptype == 0x70108086) ? "PIIX3" :
+ (scp->chiptype == 0x24118086) ? "ICH" :
+ (scp->chiptype == 0x24218086) ? "ICH0" :"PIIX4");
if (!error) {
if (device == ATA_MASTER) {
mask40 = 0x0000330f;
@@ -178,7 +175,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
pci_write_config(scp->dev, 0x44,
(pci_read_config(scp->dev, 0x44, 4) & ~mask44)|
new44, 4);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_WDMA2;
return 0;
}
}
@@ -200,11 +197,11 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up WDMA2 mode on PIIX chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up WDMA2 mode on PIIX chip\n",
+ (error) ? "failed" : "success");
if (!error) {
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_WDMA2;
return 0;
}
}
@@ -213,8 +210,8 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
case 0x522910b9: /* AcerLabs Aladdin IV/V */
/* the Aladdin doesn't support ATAPI DMA on both master & slave */
if (scp->devices & ATA_ATAPI_MASTER && scp->devices & ATA_ATAPI_SLAVE) {
- printf("ata%d: Aladdin: two atapi devices on this channel, "
- "DMA disabled\n", scp->lun);
+ ata_printf(scp, device,
+ "Aladdin: two atapi devices on this channel, no DMA\n");
break;
}
if (udmamode >= 2) {
@@ -223,9 +220,9 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA2 mode on Aladdin chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up UDMA2 mode on Aladdin chip\n",
+ (error) ? "failed" : "success");
if (!error) {
word54 |= 0x5555;
word54 |= (0x0a << (16 + (scp->unit << 3) + (device << 2)));
@@ -233,7 +230,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
pci_write_config(scp->dev, 0x53,
pci_read_config(scp->dev, 0x53, 1) | 0x03, 1);
scp->flags |= ATA_ATAPI_DMA_RO;
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA2;
return 0;
}
}
@@ -241,14 +238,14 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up WDMA2 mode on Aladdin chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up WDMA2 mode on Aladdin chip\n",
+ (error) ? "failed" : "success");
if (!error) {
pci_write_config(scp->dev, 0x53,
pci_read_config(scp->dev, 0x53, 1) | 0x03, 1);
scp->flags |= ATA_ATAPI_DMA_RO;
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_WDMA2;
return 0;
}
}
@@ -263,12 +260,11 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA4 mode on VIA chip\n",
- scp->lun, (device == ATA_MASTER) ? "master":"slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device, "%s setting up UDMA4 mode on VIA chip\n",
+ (error) ? "failed" : "success");
if (!error) {
pci_write_config(scp->dev, 0x53 - devno, 0xe8, 1);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA4;
return 0;
}
}
@@ -276,12 +272,12 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA2 mode on VIA chip\n",
- scp->lun, (device == ATA_MASTER) ? "master":"slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up UDMA2 mode on VIA chip\n",
+ (error) ? "failed" : "success");
if (!error) {
pci_write_config(scp->dev, 0x53 - devno, 0xea, 1);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA2;
return 0;
}
}
@@ -292,12 +288,12 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA4 mode on AMD chip\n",
- scp->lun, (device == ATA_MASTER) ? "master":"slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up UDMA4 mode on AMD chip\n",
+ (error) ? "failed" : "success");
if (!error) {
pci_write_config(scp->dev, 0x53 - devno, 0xc3, 1);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA4;
return 0;
}
}
@@ -310,13 +306,12 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA2 mode on %s chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success",
- (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
+ ata_printf(scp, device, "%s setting up UDMA2 mode on %s chip\n",
+ (error) ? "failed" : "success",
+ (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
if (!error) {
pci_write_config(scp->dev, 0x53 - devno, 0xc0, 1);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA2;
return 0;
}
}
@@ -324,14 +319,13 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up WDMA2 mode on %s chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success",
- (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
+ ata_printf(scp, device, "%s setting up WDMA2 mode on %s chip\n",
+ (error) ? "failed" : "success",
+ (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
if (!error) {
pci_write_config(scp->dev, 0x53 - devno, 0x82, 1);
pci_write_config(scp->dev, 0x4b - devno, 0x31, 1);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_WDMA2;
return 0;
}
}
@@ -343,12 +337,12 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA2 mode on SiS chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up UDMA2 mode on SiS chip\n",
+ (error) ? "failed" : "success");
if (!error) {
pci_write_config(scp->dev, 0x40 + (devno << 1), 0xa301, 2);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA2;
return 0;
}
}
@@ -356,12 +350,12 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up WDMA2 mode on SiS chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up WDMA2 mode on SiS chip\n",
+ (error) ? "failed" : "success");
if (!error) {
pci_write_config(scp->dev, 0x40 + (devno << 1), 0x0301, 2);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_WDMA2;
return 0;
}
}
@@ -380,13 +374,13 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA4 mode on Promise chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up UDMA4 mode on Promise chip\n",
+ (error) ? "failed" : "success");
if (!error) {
outb(scp->bmaddr+0x11, inl(scp->bmaddr+0x11) | scp->unit ? 8:2);
promise_timing(scp, devno, ATA_UDMA4);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA4;
return 0;
}
}
@@ -394,12 +388,12 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA2 mode on Promise chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up UDMA2 mode on Promise chip\n",
+ (error) ? "failed" : "success");
if (!error) {
promise_timing(scp, devno, ATA_UDMA2);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA2;
return 0;
}
}
@@ -407,12 +401,12 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up WDMA2 mode on Promise chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up WDMA2 mode on Promise chip\n",
+ (error) ? "failed" : "success");
if (!error) {
promise_timing(scp, devno, ATA_WDMA2);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_WDMA2;
return 0;
}
}
@@ -420,10 +414,10 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
ata_pio2mode(apiomode),
ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up PIO%d mode on Promise chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success",
- (apiomode >= 0) ? apiomode : 0);
+ ata_printf(scp, device,
+ "%s setting up PIO%d mode on Promise chip\n",
+ (error) ? "failed" : "success",
+ (apiomode >= 0) ? apiomode : 0);
if (!error) {
promise_timing(scp, devno, ata_pio2mode(apiomode));
return 0;
@@ -440,12 +434,12 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA4 mode on HPT366 chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up UDMA4 mode on HPT366 chip\n",
+ (error) ? "failed" : "success");
if (!error) {
hpt366_timing(scp, devno, ATA_UDMA4);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA4;
return 0;
}
}
@@ -453,12 +447,12 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up UDMA2 mode on HPT366 chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up UDMA2 mode on HPT366 chip\n",
+ (error) ? "failed" : "success");
if (!error) {
hpt366_timing(scp, devno, ATA_UDMA2);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_UDMA2;
return 0;
}
}
@@ -466,12 +460,12 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up WDMA2 mode on HPT366 chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up WDMA2 mode on HPT366 chip\n",
+ (error) ? "failed" : "success");
if (!error) {
hpt366_timing(scp, devno, ATA_WDMA2);
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_WDMA2;
return 0;
}
}
@@ -479,10 +473,9 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
ata_pio2mode(apiomode),
ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up PIO%d mode on HPT366 chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success",
- (apiomode >= 0) ? apiomode : 0);
+ ata_printf(scp, device, "%s setting up PIO%d mode on HPT366 chip\n",
+ (error) ? "failed" : "success",
+ (apiomode >= 0) ? apiomode : 0);
if (!error) {
hpt366_timing(scp, devno, ata_pio2mode(apiomode));
return 0;
@@ -505,24 +498,22 @@ ata_dmainit(struct ata_softc *scp, int32_t device,
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up WDMA2 mode on generic chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success");
+ ata_printf(scp, device,
+ "%s setting up WDMA2 mode on generic chip\n",
+ (error) ? "failed" : "success");
if (!error) {
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2;
+ scp->mode[ATA_DEV(device)] = ATA_WDMA2;
return 0;
}
}
}
- free(dmatab, M_DEVBUF);
error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
ata_pio2mode(apiomode), ATA_C_F_SETXFER,ATA_WAIT_READY);
if (bootverbose)
- printf("ata%d-%s: %s setting up PIO%d mode on generic chip\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- (error) ? "failed" : "success", (apiomode >= 0) ? apiomode : 0);
+ ata_printf(scp, device, "%s setting up PIO%d mode on generic chip\n",
+ (error) ? "failed" : "success",(apiomode>=0) ? apiomode : 0);
if (!error)
- scp->mode[(device == ATA_MASTER) ? 0 : 1] = ata_pio2mode(apiomode);
+ scp->mode[ATA_DEV(device)] = ata_pio2mode(apiomode);
return -1;
}
@@ -538,14 +529,13 @@ ata_dmasetup(struct ata_softc *scp, int32_t device,
return -1;
if (!count) {
- printf("ata%d-%s: zero length DMA transfer attempted\n",
- scp->lun, ((device == ATA_MASTER) ? "master" : "slave"));
+ ata_printf(scp, device, "zero length DMA transfer attempted\n");
return -1;
}
- dmatab = scp->dmatab[(device == ATA_MASTER) ? 0 : 1];
+ dmatab = scp->dmatab[ATA_DEV(device)];
dma_base = vtophys(data);
- dma_count = MIN(count, (PAGE_SIZE - ((uintptr_t)data & PAGE_MASK)));
+ dma_count = min(count, (PAGE_SIZE - ((uintptr_t)data & PAGE_MASK)));
data += dma_count;
count -= dma_count;
@@ -554,14 +544,13 @@ ata_dmasetup(struct ata_softc *scp, int32_t device,
dmatab[i].count = (dma_count & 0xffff);
i++;
if (i >= ATA_DMA_ENTRIES) {
- printf("ata%d-%s: too many segments in DMA table\n",
- scp->lun, (device ? "slave" : "master"));
+ ata_printf(scp, device, "too many segments in DMA table\n");
return -1;
}
dma_base = vtophys(data);
- dma_count = MIN(count, PAGE_SIZE);
- data += MIN(count, PAGE_SIZE);
- count -= MIN(count, PAGE_SIZE);
+ dma_count = min(count, PAGE_SIZE);
+ data += min(count, PAGE_SIZE);
+ count -= min(count, PAGE_SIZE);
}
dmatab[i].base = dma_base;
dmatab[i].count = (dma_count & 0xffff) | ATA_DMA_EOT;
diff --git a/sys/dev/ata/atapi-all.c b/sys/dev/ata/atapi-all.c
index d15c61a6c886..fecbe3ae209c 100644
--- a/sys/dev/ata/atapi-all.c
+++ b/sys/dev/ata/atapi-all.c
@@ -80,10 +80,10 @@ atapi_attach(struct ata_softc *scp, int32_t device)
atp->controller = scp;
atp->unit = device;
if (bootverbose)
- printf("ata%d-%s: piomode=%d dmamode=%d udmamode=%d dmaflag=%d\n",
- scp->lun, (device == ATA_MASTER) ? "master" : "slave",
- ata_pmode(ATP_PARAM), ata_wmode(ATP_PARAM),
- ata_umode(ATP_PARAM), ATP_PARAM->dmaflag);
+ ata_printf(scp, device,
+ "piomode=%d dmamode=%d udmamode=%d dmaflag=%d\n",
+ ata_pmode(ATP_PARAM), ata_wmode(ATP_PARAM),
+ ata_umode(ATP_PARAM), ATP_PARAM->dmaflag);
#ifdef ATA_ENABLE_ATAPI_DMA
if (!(ATP_PARAM->drqtype == ATAPI_DRQT_INTR)) {
@@ -105,26 +105,26 @@ atapi_attach(struct ata_softc *scp, int32_t device)
#if NATAPICD > 0
case ATAPI_TYPE_CDROM:
if (acdattach(atp))
- goto notfound;
+ goto notfound;
break;
#endif
#if NATAPIFD > 0
case ATAPI_TYPE_DIRECT:
if (afdattach(atp))
- goto notfound;
+ goto notfound;
break;
#endif
#if NATAPIST > 0
case ATAPI_TYPE_TAPE:
if (astattach(atp))
- goto notfound;
+ goto notfound;
break;
#endif
notfound:
default:
- printf("ata%d-%s: <%.40s/%.8s> %s device - NO DRIVER!\n", scp->lun,
- (device == ATA_MASTER) ? "master" : "slave", ATP_PARAM->model,
- ATP_PARAM->revision, atapi_type(ATP_PARAM->device_type));
+ ata_printf(scp, device, "<%.40s/%.8s> %s device - NO DRIVER!\n",
+ ATP_PARAM->model, ATP_PARAM->revision,
+ atapi_type(ATP_PARAM->device_type));
free(atp, M_ATAPI);
atp = NULL;
}
@@ -157,12 +157,13 @@ atapi_queue_cmd(struct atapi_softc *atp, int8_t *ccb, void *data,
request->driver = driver;
}
- /* append onto controller queue and try to start controller */
s = splbio();
/* if not using callbacks, prepare to sleep for this request */
if (!callback)
asleep((caddr_t)request, PRIBIO, "atprq", 0);
+
+ /* append onto controller queue and try to start controller */
TAILQ_INSERT_TAIL(&atp->controller->atapi_queue, request, chain);
if (atp->controller->active == ATA_IDLE)
ata_start(atp->controller);
@@ -262,7 +263,7 @@ atapi_interrupt(struct atapi_request *request)
{
struct atapi_softc *atp = request->device;
int8_t **buffer = (int8_t **)&request->data;
- int32_t length, reason, dma_stat = 0;
+ int32_t reason, dma_stat = 0;
if (request->ccb[0] == ATAPI_REQUEST_SENSE)
*buffer = (int8_t *)&request->sense;
@@ -305,51 +306,52 @@ atapi_interrupt(struct atapi_request *request)
request->result = 0;
request->bytecount = 0;
}
- goto op_finished;
}
+ else {
+ int32_t length = inb(atp->controller->ioaddr + ATA_CYL_LSB) |
+ inb(atp->controller->ioaddr + ATA_CYL_MSB) << 8;
- length = inb(atp->controller->ioaddr + ATA_CYL_LSB);
- length |= inb(atp->controller->ioaddr + ATA_CYL_MSB) << 8;
-
- switch (reason) {
- case ATAPI_P_WRITE:
- if (request->flags & A_READ) {
- request->result = inb(atp->controller->ioaddr + ATA_ERROR);
- printf("%s: %s trying to write on read buffer\n",
- atp->devname, atapi_cmd2str(atp->cmd));
- goto op_finished;
- }
- atapi_write(request, length);
- return ATA_OP_CONTINUES;
+ switch (reason) {
+ case ATAPI_P_WRITE:
+ if (request->flags & A_READ) {
+ request->result = inb(atp->controller->ioaddr + ATA_ERROR);
+ printf("%s: %s trying to write on read buffer\n",
+ atp->devname, atapi_cmd2str(atp->cmd));
+ break;
+ }
+ atapi_write(request, length);
+ return ATA_OP_CONTINUES;
- case ATAPI_P_READ:
- if (!(request->flags & A_READ)) {
- request->result = inb(atp->controller->ioaddr + ATA_ERROR);
- printf("%s: %s trying to read on write buffer\n",
- atp->devname, atapi_cmd2str(atp->cmd));
- goto op_finished;
- }
- atapi_read(request, length);
- return ATA_OP_CONTINUES;
-
- case ATAPI_P_DONEDRQ:
- printf("%s: %s DONEDRQ\n", atp->devname, atapi_cmd2str(atp->cmd));
- if (request->flags & A_READ)
+ case ATAPI_P_READ:
+ if (!(request->flags & A_READ)) {
+ request->result = inb(atp->controller->ioaddr + ATA_ERROR);
+ printf("%s: %s trying to read on write buffer\n",
+ atp->devname, atapi_cmd2str(atp->cmd));
+ break;
+ }
atapi_read(request, length);
- else
- atapi_write(request, length);
- /* FALLTHROUGH */
+ return ATA_OP_CONTINUES;
- case ATAPI_P_ABORT:
- case ATAPI_P_DONE:
- if (atp->controller->status & (ATA_S_ERROR | ATA_S_DWF))
- request->result = inb(atp->controller->ioaddr + ATA_ERROR);
- else
- if (request->ccb[0] != ATAPI_REQUEST_SENSE)
- request->result = 0;
- goto op_finished;
- default:
- printf("%s: unknown transfer phase %d\n", atp->devname, reason);
+ case ATAPI_P_DONEDRQ:
+ printf("%s: %s DONEDRQ\n", atp->devname, atapi_cmd2str(atp->cmd));
+ if (request->flags & A_READ)
+ atapi_read(request, length);
+ else
+ atapi_write(request, length);
+ /* FALLTHROUGH */
+
+ case ATAPI_P_ABORT:
+ case ATAPI_P_DONE:
+ if (atp->controller->status & (ATA_S_ERROR | ATA_S_DWF))
+ request->result = inb(atp->controller->ioaddr + ATA_ERROR);
+ else
+ if (request->ccb[0] != ATAPI_REQUEST_SENSE)
+ request->result = 0;
+ break;
+
+ default:
+ printf("%s: unknown transfer phase %d\n", atp->devname, reason);
+ }
}
op_finished:
@@ -522,6 +524,7 @@ static void
atapi_timeout(struct atapi_request *request)
{
struct atapi_softc *atp = request->device;
+ int32_t s = splbio();
atp->controller->running = NULL;
printf("%s: atapi_timeout: cmd=%s - resetting\n",
@@ -539,6 +542,7 @@ atapi_timeout(struct atapi_request *request)
wakeup((caddr_t)request);
}
ata_reinit(atp->controller);
+ splx(s);
}
static int8_t *
diff --git a/sys/dev/ata/atapi-cd.c b/sys/dev/ata/atapi-cd.c
index e799b5f9113d..d6e550b1b592 100644
--- a/sys/dev/ata/atapi-cd.c
+++ b/sys/dev/ata/atapi-cd.c
@@ -137,7 +137,6 @@ acdattach(struct atapi_softc *atp)
cdp->cap.cur_write_speed = ntohs(cdp->cap.cur_write_speed);
cdp->cap.max_vol_levels = ntohs(cdp->cap.max_vol_levels);
cdp->cap.buf_size = ntohs(cdp->cap.buf_size);
- acd_describe(cdp);
/* if this is a changer device, allocate the neeeded lun's */
if (cdp->cap.mech == MST_MECH_CHANGER) {
@@ -171,8 +170,9 @@ acdattach(struct atapi_softc *atp)
}
tmpcdp->slot = count;
tmpcdp->changer_info = chp;
- printf("acd%d: changer slot %d %s\n", acdnlun, count,
- (chp->slot[count].present ? "CD present" : "empty"));
+ if (bootverbose)
+ printf("acd%d: changer slot %d %s\n", acdnlun, count,
+ (chp->slot[count].present ? "CD present" : "empty"));
acdnlun++;
}
sprintf(string, "acd%d-", cdp->lun);
@@ -186,9 +186,10 @@ acdattach(struct atapi_softc *atp)
devstat_add_entry(cdp->stats, "acd", cdp->lun, DEV_BSIZE,
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_IDE,
- 0x178);
+ DEVSTAT_PRIORITY_CD);
acdnlun++;
}
+ acd_describe(cdp);
return 0;
}
@@ -220,21 +221,15 @@ acd_init_lun(struct atapi_softc *atp, int32_t lun, struct devstat *stats)
else
acd->stats = stats;
dev = make_dev(&acd_cdevsw, dkmakeminor(lun, 0, 0),
- UID_ROOT, GID_OPERATOR, 0644, "racd%da", lun);
- dev->si_drv1 = acd;
- dev->si_iosize_max = 252 * DEV_BSIZE;
- dev = make_dev(&acd_cdevsw, dkmakeminor(lun, 0, RAW_PART),
- UID_ROOT, GID_OPERATOR, 0644, "racd%dc", lun);
- dev->si_drv1 = acd;
- dev->si_iosize_max = 252 * DEV_BSIZE;
- dev = make_dev(&acd_cdevsw, dkmakeminor(lun, 0, 0),
UID_ROOT, GID_OPERATOR, 0644, "acd%da", lun);
dev->si_drv1 = acd;
dev->si_iosize_max = 252 * DEV_BSIZE;
+ dev->si_bsize_phys = 2048; /* XXX SOS */
dev = make_dev(&acd_cdevsw, dkmakeminor(lun, 0, RAW_PART),
UID_ROOT, GID_OPERATOR, 0644, "acd%dc", lun);
dev->si_drv1 = acd;
dev->si_iosize_max = 252 * DEV_BSIZE;
+ dev->si_bsize_phys = 2048; /* XXX SOS */
if ((acd->atp->devname = malloc(8, M_ACD, M_NOWAIT)))
sprintf(acd->atp->devname, "acd%d", acd->lun);
return acd;
@@ -246,165 +241,186 @@ acd_describe(struct acd_softc *cdp)
int32_t comma = 0;
int8_t *mechanism;
- printf("acd%d: <%.40s/%.8s> %s drive at ata%d as %s\n",
- cdp->lun, ATA_PARAM(cdp->atp->controller, cdp->atp->unit)->model,
- ATA_PARAM(cdp->atp->controller, cdp->atp->unit)->revision,
- (cdp->cap.write_dvdr) ? "DVD-R" :
+ if (bootverbose) {
+ printf("acd%d: <%.40s/%.8s> %s drive at ata%d as %s\n",
+ cdp->lun, ATA_PARAM(cdp->atp->controller, cdp->atp->unit)->model,
+ ATA_PARAM(cdp->atp->controller, cdp->atp->unit)->revision,
+ (cdp->cap.write_dvdr) ? "DVD-R" :
(cdp->cap.write_dvdram) ? "DVD-RAM" :
- (cdp->cap.write_cdrw) ? "CD-RW" :
- (cdp->cap.write_cdr) ? "CD-R" :
- (cdp->cap.read_dvdrom) ? "DVD-ROM" : "CDROM",
- cdp->atp->controller->lun,
- (cdp->atp->unit == ATA_MASTER) ? "master" : "slave ");
+ (cdp->cap.write_cdrw) ? "CD-RW" :
+ (cdp->cap.write_cdr) ? "CD-R" :
+ (cdp->cap.read_dvdrom) ? "DVD-ROM" : "CDROM",
+ cdp->atp->controller->lun,
+ (cdp->atp->unit == ATA_MASTER) ? "master" : "slave");
- printf("acd%d:", cdp->lun);
- if (cdp->cap.cur_read_speed) {
- printf(" read %dKB/s", cdp->cap.cur_read_speed * 1000 / 1024);
- if (cdp->cap.max_read_speed)
- printf(" (%dKB/s)", cdp->cap.max_read_speed * 1000 / 1024);
- if ((cdp->cap.cur_write_speed) &&
- (cdp->cap.write_cdr || cdp->cap.write_cdrw ||
- cdp->cap.write_dvdr || cdp->cap.write_dvdram)) {
- printf(" write %dKB/s", cdp->cap.cur_write_speed * 1000 / 1024);
- if (cdp->cap.max_write_speed)
- printf(" (%dKB/s)", cdp->cap.max_write_speed * 1000 / 1024);
+ printf("acd%d:", cdp->lun);
+ if (cdp->cap.cur_read_speed) {
+ printf(" read %dKB/s", cdp->cap.cur_read_speed * 1000 / 1024);
+ if (cdp->cap.max_read_speed)
+ printf(" (%dKB/s)", cdp->cap.max_read_speed * 1000 / 1024);
+ if ((cdp->cap.cur_write_speed) &&
+ (cdp->cap.write_cdr || cdp->cap.write_cdrw ||
+ cdp->cap.write_dvdr || cdp->cap.write_dvdram)) {
+ printf(" write %dKB/s", cdp->cap.cur_write_speed * 1000 / 1024);
+ if (cdp->cap.max_write_speed)
+ printf(" (%dKB/s)", cdp->cap.max_write_speed * 1000 / 1024);
+ }
+ comma = 1;
}
- comma = 1;
- }
- if (cdp->cap.buf_size) {
- printf("%s %dKB buffer", comma ? "," : "", cdp->cap.buf_size);
- comma = 1;
- }
- printf("%s %s\n",
- comma ? "," : "", ata_mode2str(cdp->atp->controller->mode[
- ATA_DEV(cdp->atp->unit)]));
-
- printf("acd%d: Reads:", cdp->lun);
- comma = 0;
- if (cdp->cap.read_cdr) {
- printf(" CD-R"); comma = 1;
- }
- if (cdp->cap.read_cdrw) {
- printf("%s CD-RW", comma ? "," : ""); comma = 1;
- }
- if (cdp->cap.cd_da) {
- if (cdp->cap.cd_da_stream)
- printf("%s CD-DA stream", comma ? "," : "");
- else
- printf("%s CD-DA", comma ? "," : "");
- comma = 1;
- }
- if (cdp->cap.read_dvdrom) {
- printf("%s DVD-ROM", comma ? "," : ""); comma = 1;
- }
- if (cdp->cap.read_dvdr) {
- printf("%s DVD-R", comma ? "," : ""); comma = 1;
- }
- if (cdp->cap.read_dvdram) {
- printf("%s DVD-RAM", comma ? "," : ""); comma = 1;
- }
- if (cdp->cap.read_packet)
- printf("%s packet", comma ? "," : "");
+ if (cdp->cap.buf_size) {
+ printf("%s %dKB buffer", comma ? "," : "", cdp->cap.buf_size);
+ comma = 1;
+ }
+ printf("%s %s\n",
+ comma ? "," : "", ata_mode2str(
+ cdp->atp->controller->mode[ATA_DEV(cdp->atp->unit)]));
- if (cdp->cap.write_cdr || cdp->cap.write_cdrw ||
- cdp->cap.write_dvdr || cdp->cap.write_dvdram) {
- printf("\nacd%d: Writes:", cdp->lun);
+ printf("acd%d: Reads:", cdp->lun);
comma = 0;
- if (cdp->cap.write_cdr) {
- printf(" CD-R" ); comma = 1;
+ if (cdp->cap.read_cdr) {
+ printf(" CD-R"); comma = 1;
}
- if (cdp->cap.write_cdrw) {
+ if (cdp->cap.read_cdrw) {
printf("%s CD-RW", comma ? "," : ""); comma = 1;
}
- if (cdp->cap.write_dvdr) {
+ if (cdp->cap.cd_da) {
+ if (cdp->cap.cd_da_stream)
+ printf("%s CD-DA stream", comma ? "," : "");
+ else
+ printf("%s CD-DA", comma ? "," : "");
+ comma = 1;
+ }
+ if (cdp->cap.read_dvdrom) {
+ printf("%s DVD-ROM", comma ? "," : ""); comma = 1;
+ }
+ if (cdp->cap.read_dvdr) {
printf("%s DVD-R", comma ? "," : ""); comma = 1;
}
- if (cdp->cap.write_dvdram) {
- printf("%s DVD-RAM", comma ? "," : ""); comma = 1;
+ if (cdp->cap.read_dvdram) {
+ printf("%s DVD-RAM", comma ? "," : ""); comma = 1;
}
- if (cdp->cap.test_write)
- printf("%s test write", comma ? "," : "");
- }
- if (cdp->cap.audio_play) {
- printf("\nacd%d: Audio: ", cdp->lun);
- if (cdp->cap.audio_play)
- printf("play");
- if (cdp->cap.max_vol_levels)
- printf(", %d volume levels", cdp->cap.max_vol_levels);
- }
- printf("\nacd%d: Mechanism: ", cdp->lun);
- switch (cdp->cap.mech) {
- case MST_MECH_CADDY:
- mechanism = "caddy"; break;
- case MST_MECH_TRAY:
- mechanism = "tray"; break;
- case MST_MECH_POPUP:
- mechanism = "popup"; break;
- case MST_MECH_CHANGER:
- mechanism = "changer"; break;
- case MST_MECH_CARTRIDGE:
- mechanism = "cartridge"; break;
- default:
- mechanism = 0; break;
- }
- if (mechanism)
- printf("%s%s", cdp->cap.eject ? "ejectable " : "", mechanism);
- else if (cdp->cap.eject)
- printf("ejectable");
+ if (cdp->cap.read_packet)
+ printf("%s packet", comma ? "," : "");
- if (cdp->cap.mech != MST_MECH_CHANGER) {
- printf("\nacd%d: Medium: ", cdp->lun);
- switch (cdp->cap.medium_type & MST_TYPE_MASK_HIGH) {
- case MST_CDROM:
- printf("CD-ROM "); break;
- case MST_CDR:
- printf("CD-R "); break;
- case MST_CDRW:
- printf("CD-RW "); break;
- case MST_DOOR_OPEN:
- printf("door open"); break;
- case MST_NO_DISC:
- printf("no/blank disc inside"); break;
- case MST_FMT_ERROR:
- printf("medium format error"); break;
+ if (cdp->cap.write_cdr || cdp->cap.write_cdrw ||
+ cdp->cap.write_dvdr || cdp->cap.write_dvdram) {
+ printf("\nacd%d: Writes:", cdp->lun);
+ comma = 0;
+ if (cdp->cap.write_cdr) {
+ printf(" CD-R" ); comma = 1;
+ }
+ if (cdp->cap.write_cdrw) {
+ printf("%s CD-RW", comma ? "," : ""); comma = 1;
+ }
+ if (cdp->cap.write_dvdr) {
+ printf("%s DVD-R", comma ? "," : ""); comma = 1;
+ }
+ if (cdp->cap.write_dvdram) {
+ printf("%s DVD-RAM", comma ? "," : ""); comma = 1;
+ }
+ if (cdp->cap.test_write)
+ printf("%s test write", comma ? "," : "");
}
- if ((cdp->cap.medium_type & MST_TYPE_MASK_HIGH) < MST_TYPE_MASK_HIGH) {
- switch (cdp->cap.medium_type & MST_TYPE_MASK_LOW) {
- case MST_DATA_120:
- printf("120mm data disc loaded"); break;
- case MST_AUDIO_120:
- printf("120mm audio disc loaded"); break;
- case MST_COMB_120:
- printf("120mm data/audio disc loaded"); break;
- case MST_PHOTO_120:
- printf("120mm photo disc loaded"); break;
- case MST_DATA_80:
- printf("80mm data disc loaded"); break;
- case MST_AUDIO_80:
- printf("80mm audio disc loaded"); break;
- case MST_COMB_80:
- printf("80mm data/audio disc loaded"); break;
- case MST_PHOTO_80:
- printf("80mm photo disc loaded"); break;
- case MST_FMT_NONE:
- switch (cdp->cap.medium_type & MST_TYPE_MASK_HIGH) {
- case MST_CDROM:
- printf("unknown medium"); break;
- case MST_CDR:
- case MST_CDRW:
- printf("blank medium"); break;
+ if (cdp->cap.audio_play) {
+ printf("\nacd%d: Audio: ", cdp->lun);
+ if (cdp->cap.audio_play)
+ printf("play");
+ if (cdp->cap.max_vol_levels)
+ printf(", %d volume levels", cdp->cap.max_vol_levels);
+ }
+ printf("\nacd%d: Mechanism: ", cdp->lun);
+ switch (cdp->cap.mech) {
+ case MST_MECH_CADDY:
+ mechanism = "caddy"; break;
+ case MST_MECH_TRAY:
+ mechanism = "tray"; break;
+ case MST_MECH_POPUP:
+ mechanism = "popup"; break;
+ case MST_MECH_CHANGER:
+ mechanism = "changer"; break;
+ case MST_MECH_CARTRIDGE:
+ mechanism = "cartridge"; break;
+ default:
+ mechanism = 0; break;
+ }
+ if (mechanism)
+ printf("%s%s", cdp->cap.eject ? "ejectable " : "", mechanism);
+ else if (cdp->cap.eject)
+ printf("ejectable");
+
+ if (cdp->cap.mech != MST_MECH_CHANGER) {
+ printf("\nacd%d: Medium: ", cdp->lun);
+ switch (cdp->cap.medium_type & MST_TYPE_MASK_HIGH) {
+ case MST_CDROM:
+ printf("CD-ROM "); break;
+ case MST_CDR:
+ printf("CD-R "); break;
+ case MST_CDRW:
+ printf("CD-RW "); break;
+ case MST_DOOR_OPEN:
+ printf("door open"); break;
+ case MST_NO_DISC:
+ printf("no/blank disc inside"); break;
+ case MST_FMT_ERROR:
+ printf("medium format error"); break;
+ }
+ if ((cdp->cap.medium_type & MST_TYPE_MASK_HIGH)<MST_TYPE_MASK_HIGH){
+ switch (cdp->cap.medium_type & MST_TYPE_MASK_LOW) {
+ case MST_DATA_120:
+ printf("120mm data disc loaded"); break;
+ case MST_AUDIO_120:
+ printf("120mm audio disc loaded"); break;
+ case MST_COMB_120:
+ printf("120mm data/audio disc loaded"); break;
+ case MST_PHOTO_120:
+ printf("120mm photo disc loaded"); break;
+ case MST_DATA_80:
+ printf("80mm data disc loaded"); break;
+ case MST_AUDIO_80:
+ printf("80mm audio disc loaded"); break;
+ case MST_COMB_80:
+ printf("80mm data/audio disc loaded"); break;
+ case MST_PHOTO_80:
+ printf("80mm photo disc loaded"); break;
+ case MST_FMT_NONE:
+ switch (cdp->cap.medium_type & MST_TYPE_MASK_HIGH) {
+ case MST_CDROM:
+ printf("unknown medium"); break;
+ case MST_CDR:
+ case MST_CDRW:
+ printf("blank medium"); break;
+ }
+ break;
+ default:
+ printf("unknown type=0x%x", cdp->cap.medium_type); break;
}
- break;
- default:
- printf("unknown type=0x%x", cdp->cap.medium_type); break;
}
}
+ if (cdp->cap.lock)
+ printf(cdp->cap.locked ? ", locked" : ", unlocked");
+ if (cdp->cap.prevent)
+ printf(", lock protected");
+ printf("\n");
+ }
+ else {
+ char changer[32];
+
+ bzero(changer, sizeof(changer));
+ if (cdp->changer_info)
+ sprintf(changer, " with %d CD changer", cdp->changer_info->slots);
+
+ printf("acd%d: %s%s <%.40s> at ata%d as %s mode %s\n",
+ cdp->lun, (cdp->cap.write_dvdr) ? "DVD-R" :
+ (cdp->cap.write_dvdram) ? "DVD-RAM" :
+ (cdp->cap.write_cdrw) ? "CD-RW" :
+ (cdp->cap.write_cdr) ? "CD-R" :
+ (cdp->cap.read_dvdrom) ? "DVD-ROM" : "CDROM",
+ changer, ATA_PARAM(cdp->atp->controller, cdp->atp->unit)->model,
+ cdp->atp->controller->lun,
+ (cdp->atp->unit == ATA_MASTER) ? "master" : "slave",
+ ata_mode2str(cdp->atp->controller->mode[ATA_DEV(cdp->atp->unit)])
+ );
}
- if (cdp->cap.lock)
- printf(cdp->cap.locked ? ", locked" : ", unlocked");
- if (cdp->cap.prevent)
- printf(", lock protected");
- printf("\n");
}
static __inline void
@@ -442,7 +458,6 @@ acdopen(dev_t dev, int32_t flags, int32_t fmt, struct proc *p)
cdp->flags |= F_WRITING;
}
- dev->si_bsize_phys = 2048; /* XXX SOS */
if (!cdp->refcnt) {
acd_prevent_allow(cdp, 1);
cdp->flags |= F_LOCKED;
@@ -916,7 +931,6 @@ acdioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p)
error = EINVAL;
break;
}
- cdp->next_writeable_addr = track_info.next_writeable_addr;
*(int*)addr = track_info.next_writeable_addr;
}
break;
@@ -926,7 +940,6 @@ acdioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p)
error = EINVAL;
printf("acd%d: sequence error (disk already open)\n", cdp->lun);
}
- cdp->next_writeable_addr = 0;
cdp->flags &= ~(F_WRITTEN | F_TRACK_OPEN);
cdp->flags |= F_DISK_OPEN;
break;
@@ -1074,21 +1087,24 @@ acd_start(struct acd_softc *cdp)
}
bzero(ccb, sizeof(ccb));
- if (bp->b_flags & B_READ) {
+ count = (bp->b_bcount + (cdp->block_size - 1)) / cdp->block_size;
+ if (bp->b_flags & B_PHYS)
+ lba = bp->b_offset / cdp->block_size;
+ else
lba = bp->b_blkno / (cdp->block_size / DEV_BSIZE);
- ccb[0] = ATAPI_READ_BIG;
+
+ if (bp->b_flags & B_READ) {
+ ccb[0] = ATAPI_READ_CD;
+ ccb[9] = 0x10; /* read user data only */
}
- else {
- lba = cdp->next_writeable_addr + (bp->b_offset / cdp->block_size);
+ else
ccb[0] = ATAPI_WRITE_BIG;
- }
- count = (bp->b_bcount + (cdp->block_size - 1)) / cdp->block_size;
-
ccb[1] = 0;
ccb[2] = lba>>24;
ccb[3] = lba>>16;
ccb[4] = lba>>8;
ccb[5] = lba;
+ ccb[6] = count>>16;
ccb[7] = count>>8;
ccb[8] = count;
diff --git a/sys/dev/ata/atapi-cd.h b/sys/dev/ata/atapi-cd.h
index 56e2c99bfcd0..90e284ff2562 100644
--- a/sys/dev/ata/atapi-cd.h
+++ b/sys/dev/ata/atapi-cd.h
@@ -341,6 +341,5 @@ struct acd_softc {
struct changer *changer_info; /* changer info */
int32_t slot; /* this lun's slot number */
u_int32_t block_size; /* blocksize currently used */
- u_int32_t next_writeable_addr; /* next writable address */
struct devstat *stats; /* devstat entry */
};
diff --git a/sys/dev/ata/atapi-fd.c b/sys/dev/ata/atapi-fd.c
index c2b2d52f6b81..949cd75b63b8 100644
--- a/sys/dev/ata/atapi-fd.c
+++ b/sys/dev/ata/atapi-fd.c
@@ -111,7 +111,6 @@ afdattach(struct atapi_softc *atp)
"IOMEGA ZIP", 11))
fdp->transfersize = 64;
- afd_describe(fdp);
devstat_add_entry(&fdp->stats, "afd", fdp->lun, DEV_BSIZE,
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_IDE,
@@ -121,6 +120,7 @@ afdattach(struct atapi_softc *atp)
dev->si_iosize_max = 252 * DEV_BSIZE;
if ((fdp->atp->devname = malloc(8, M_AFD, M_NOWAIT)))
sprintf(fdp->atp->devname, "afd%d", fdp->lun);
+ afd_describe(fdp);
return 0;
}
@@ -156,25 +156,26 @@ afd_sense(struct afd_softc *fdp)
static void
afd_describe(struct afd_softc *fdp)
{
- printf("afd%d: <%.40s/%.8s> rewriteable drive at ata%d as %s\n",
- fdp->lun, ATA_PARAM(fdp->atp->controller, fdp->atp->unit)->model,
- ATA_PARAM(fdp->atp->controller, fdp->atp->unit)->revision,
- fdp->atp->controller->lun,
- (fdp->atp->unit == ATA_MASTER) ? "master" : "slave ");
- printf("afd%d: %luMB (%u sectors), %u cyls, %u heads, %u S/T, %u B/S\n",
- fdp->lun,
- (fdp->cap.cylinders * fdp->cap.heads * fdp->cap.sectors) /
- ((1024L * 1024L) / fdp->cap.sector_size),
- fdp->cap.cylinders * fdp->cap.heads * fdp->cap.sectors,
- fdp->cap.cylinders, fdp->cap.heads, fdp->cap.sectors,
- fdp->cap.sector_size);
- printf("afd%d: %dKB/s,", fdp->lun, fdp->cap.transfer_rate/8);
- if (fdp->transfersize)
- printf(" transfer limit %d blks,", fdp->transfersize);
- printf(" %s\n", ata_mode2str(fdp->atp->controller->mode[
+ if (bootverbose) {
+ printf("afd%d: <%.40s/%.8s> rewriteable drive at ata%d as %s\n",
+ fdp->lun, ATA_PARAM(fdp->atp->controller, fdp->atp->unit)->model,
+ ATA_PARAM(fdp->atp->controller, fdp->atp->unit)->revision,
+ fdp->atp->controller->lun,
+ (fdp->atp->unit == ATA_MASTER) ? "master" : "slave");
+ printf("afd%d: %luMB (%u sectors), %u cyls, %u heads, %u S/T, %u B/S\n",
+ fdp->lun,
+ (fdp->cap.cylinders * fdp->cap.heads * fdp->cap.sectors) /
+ ((1024L * 1024L) / fdp->cap.sector_size),
+ fdp->cap.cylinders * fdp->cap.heads * fdp->cap.sectors,
+ fdp->cap.cylinders, fdp->cap.heads, fdp->cap.sectors,
+ fdp->cap.sector_size);
+ printf("afd%d: %dKB/s,", fdp->lun, fdp->cap.transfer_rate/8);
+ if (fdp->transfersize)
+ printf(" transfer limit %d blks,", fdp->transfersize);
+ printf(" %s\n", ata_mode2str(fdp->atp->controller->mode[
ATA_DEV(fdp->atp->unit)]));
- printf("afd%d: Medium: ", fdp->lun);
- switch (fdp->header.medium_type) {
+ printf("afd%d: Medium: ", fdp->lun);
+ switch (fdp->header.medium_type) {
case MFD_2DD:
printf("720KB DD disk"); break;
@@ -187,10 +188,22 @@ afd_describe(struct afd_softc *fdp)
case MFD_UHD:
printf("120MB UHD disk"); break;
- default: printf("Unknown media (0x%x)", fdp->header.medium_type);
+ default:
+ printf("Unknown media (0x%x)", fdp->header.medium_type);
+ }
+ if (fdp->header.wp) printf(", writeprotected");
+ printf("\n");
+ }
+ else {
+ printf("afd%d: %luMB floppy <%.40s> at ata%d as %s mode %s\n",
+ fdp->lun, (fdp->cap.cylinders*fdp->cap.heads*fdp->cap.sectors) /
+ ((1024L * 1024L) / fdp->cap.sector_size),
+ ATA_PARAM(fdp->atp->controller, fdp->atp->unit)->model,
+ fdp->atp->controller->lun,
+ (fdp->atp->unit == ATA_MASTER) ? "master" : "slave",
+ ata_mode2str(fdp->atp->controller->mode[ATA_DEV(fdp->atp->unit)])
+ );
}
- if (fdp->header.wp) printf(", writeprotected");
- printf("\n");
}
static int
diff --git a/sys/dev/ata/atapi-tape.c b/sys/dev/ata/atapi-tape.c
index f8c5b9fe6217..7f9e57062bf2 100644
--- a/sys/dev/ata/atapi-tape.c
+++ b/sys/dev/ata/atapi-tape.c
@@ -115,7 +115,6 @@ astattach(struct atapi_softc *atp)
free(stp, M_AST);
return -1;
}
- ast_describe(stp);
if (!strcmp(ATA_PARAM(stp->atp->controller, stp->atp->unit)->model,
"OnStream DI-30")) {
struct ast_transferpage transfer;
@@ -137,15 +136,16 @@ astattach(struct atapi_softc *atp)
DEVSTAT_TYPE_SEQUENTIAL | DEVSTAT_TYPE_IF_IDE,
DEVSTAT_PRIORITY_TAPE);
dev = make_dev(&ast_cdevsw, dkmakeminor(stp->lun, 0, 0),
- UID_ROOT, GID_OPERATOR, 0640, "rast%d", stp->lun);
+ UID_ROOT, GID_OPERATOR, 0640, "ast%d", stp->lun);
dev->si_drv1 = stp;
dev->si_iosize_max = 252 * DEV_BSIZE;
dev = make_dev(&ast_cdevsw, dkmakeminor(stp->lun, 0, 1),
- UID_ROOT, GID_OPERATOR, 0640, "nrast%d", stp->lun);
+ UID_ROOT, GID_OPERATOR, 0640, "nast%d", stp->lun);
dev->si_drv1 = stp;
dev->si_iosize_max = 252 * DEV_BSIZE;
if ((stp->atp->devname = malloc(8, M_AST, M_NOWAIT)))
sprintf(stp->atp->devname, "ast%d", stp->lun);
+ ast_describe(stp);
return 0;
}
@@ -157,63 +157,79 @@ ast_sense(struct ast_softc *stp)
/* get drive capabilities, some drives needs this repeated */
for (count = 0 ; count < 5 ; count++) {
if (!(error = ast_mode_sense(stp, ATAPI_TAPE_CAP_PAGE,
- &stp->cap, sizeof(stp->cap))))
- break;
+ &stp->cap, sizeof(stp->cap)))) {
+ if (stp->cap.blk32k)
+ stp->blksize = 32768;
+ if (stp->cap.blk1024)
+ stp->blksize = 1024;
+ if (stp->cap.blk512)
+ stp->blksize = 512;
+ if (!stp->blksize)
+ continue;
+ stp->cap.max_speed = ntohs(stp->cap.max_speed);
+ stp->cap.max_defects = ntohs(stp->cap.max_defects);
+ stp->cap.ctl = ntohs(stp->cap.ctl);
+ stp->cap.speed = ntohs(stp->cap.speed);
+ stp->cap.buffer_size = ntohs(stp->cap.buffer_size);
+ return 0;
+ }
}
- if (error)
- return 1;
-
- stp->cap.max_speed = ntohs(stp->cap.max_speed);
- stp->cap.max_defects = ntohs(stp->cap.max_defects);
- stp->cap.ctl = ntohs(stp->cap.ctl);
- stp->cap.speed = ntohs(stp->cap.speed);
- stp->cap.buffer_size = ntohs(stp->cap.buffer_size);
- if (stp->cap.blk32k)
- stp->blksize = 32768;
- if (stp->cap.blk1024)
- stp->blksize = 1024;
- if (stp->cap.blk512)
- stp->blksize = 512;
- return 0;
+ return 1;
}
static void
ast_describe(struct ast_softc *stp)
{
- printf("ast%d: <%.40s/%.8s> tape drive at ata%d as %s\n",
- stp->lun, ATA_PARAM(stp->atp->controller, stp->atp->unit)->model,
- ATA_PARAM(stp->atp->controller, stp->atp->unit)->revision,
- stp->atp->controller->lun,
- (stp->atp->unit == ATA_MASTER) ? "master" : "slave ");
- printf("ast%d: ", stp->lun);
- printf("%dKB/s, ", stp->cap.max_speed);
- printf("transfer limit %d blk%s, ", stp->cap.ctl, (stp->cap.ctl>1)?"s":"");
- printf("%dKB buffer, ", (stp->cap.buffer_size * DEV_BSIZE) / 1024);
- printf("%s\n", ata_mode2str(stp->atp->controller->mode[
- ATA_DEV(stp->atp->unit)]));
- printf("ast%d: ", stp->lun);
- switch (stp->cap.medium_type) {
- case 0x00: printf("Drive empty"); break;
- case 0x17: printf("Travan 1 (400 Mbyte) media"); break;
- case 0xb6: printf("Travan 4 (4 Gbyte) media"); break;
- case 0xda: printf("OnStream ADR (15Gyte) media"); break;
- default: printf("Unknown media (0x%x)", stp->cap.medium_type);
+ if (bootverbose) {
+ printf("ast%d: <%.40s/%.8s> tape drive at ata%d as %s\n",
+ stp->lun, ATA_PARAM(stp->atp->controller, stp->atp->unit)->model,
+ ATA_PARAM(stp->atp->controller, stp->atp->unit)->revision,
+ stp->atp->controller->lun,
+ (stp->atp->unit == ATA_MASTER) ? "master" : "slave ");
+ printf("ast%d: ", stp->lun);
+ printf("%dKB/s, ", stp->cap.max_speed);
+ printf("transfer limit %d blk%s, ",
+ stp->cap.ctl, (stp->cap.ctl > 1) ? "s" : "");
+ printf("%dKB buffer, ", (stp->cap.buffer_size * DEV_BSIZE) / 1024);
+ printf("%s\n", ata_mode2str(stp->atp->controller->mode[
+ ATA_DEV(stp->atp->unit)]));
+ printf("ast%d: ", stp->lun);
+ switch (stp->cap.medium_type) {
+ case 0x00:
+ printf("Drive empty"); break;
+ case 0x17:
+ printf("Travan 1 (400 Mbyte) media"); break;
+ case 0xb6:
+ printf("Travan 4 (4 Gbyte) media"); break;
+ case 0xda:
+ printf("OnStream ADR (15Gyte) media"); break;
+ default:
+ printf("Unknown media (0x%x)", stp->cap.medium_type);
+ }
+ if (stp->cap.readonly) printf(", readonly");
+ if (stp->cap.reverse) printf(", reverse");
+ if (stp->cap.eformat) printf(", eformat");
+ if (stp->cap.qfa) printf(", qfa");
+ if (stp->cap.lock) printf(", lock");
+ if (stp->cap.locked) printf(", locked");
+ if (stp->cap.prevent) printf(", prevent");
+ if (stp->cap.eject) printf(", eject");
+ if (stp->cap.disconnect) printf(", disconnect");
+ if (stp->cap.ecc) printf(", ecc");
+ if (stp->cap.compress) printf(", compress");
+ if (stp->cap.blk512) printf(", 512b");
+ if (stp->cap.blk1024) printf(", 1024b");
+ if (stp->cap.blk32k) printf(", 32kb");
+ printf("\n");
+ }
+ else {
+ printf("ast%d: TAPE <%.40s> at ata%d as %s mode %s\n",
+ stp->lun, ATA_PARAM(stp->atp->controller, stp->atp->unit)->model,
+ stp->atp->controller->lun,
+ (stp->atp->unit == ATA_MASTER) ? "master" : "slave",
+ ata_mode2str(stp->atp->controller->mode[ATA_DEV(stp->atp->unit)])
+ );
}
- if (stp->cap.readonly) printf(", readonly");
- if (stp->cap.reverse) printf(", reverse");
- if (stp->cap.eformat) printf(", eformat");
- if (stp->cap.qfa) printf(", qfa");
- if (stp->cap.lock) printf(", lock");
- if (stp->cap.locked) printf(", locked");
- if (stp->cap.prevent) printf(", prevent");
- if (stp->cap.eject) printf(", eject");
- if (stp->cap.disconnect) printf(", disconnect");
- if (stp->cap.ecc) printf(", ecc");
- if (stp->cap.compress) printf(", compress");
- if (stp->cap.blk512) printf(", 512b");
- if (stp->cap.blk1024) printf(", 1024b");
- if (stp->cap.blk32k) printf(", 32kb");
- printf("\n");
}
static int