summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/dev/ata/ata-all.c257
-rw-r--r--sys/dev/ata/ata-all.h146
-rw-r--r--sys/dev/ata/ata-disk.c175
-rw-r--r--sys/dev/ata/ata-dma.c1
-rw-r--r--sys/dev/ata/ata-raid.c1
-rw-r--r--sys/dev/ata/atapi-all.c125
-rw-r--r--sys/dev/ata/atapi-all.h1
-rw-r--r--sys/dev/ata/atapi-cd.c130
-rw-r--r--sys/dev/ata/atapi-fd.c62
-rw-r--r--sys/dev/ata/atapi-tape.c60
10 files changed, 503 insertions, 455 deletions
diff --git a/sys/dev/ata/ata-all.c b/sys/dev/ata/ata-all.c
index 75788e9..d0da258 100644
--- a/sys/dev/ata/ata-all.c
+++ b/sys/dev/ata/ata-all.c
@@ -32,7 +32,9 @@
#include "opt_ata.h"
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/ata.h>
#include <sys/kernel.h>
+#include <sys/conf.h>
#include <sys/disk.h>
#include <sys/module.h>
#include <sys/bus.h>
@@ -51,6 +53,25 @@
#include <dev/ata/ata-disk.h>
#include <dev/ata/atapi-all.h>
+/* device structures */
+static d_ioctl_t ataioctl;
+static struct cdevsw ata_cdevsw = {
+ /* open */ nullopen,
+ /* close */ nullclose,
+ /* read */ noread,
+ /* write */ nowrite,
+ /* ioctl */ ataioctl,
+ /* poll */ nopoll,
+ /* mmap */ nommap,
+ /* strategy */ nostrategy,
+ /* name */ "ata",
+ /* maj */ 159,
+ /* dump */ nodump,
+ /* psize */ nopsize,
+ /* flags */ 0,
+ /* bmaj */ -1
+};
+
/* prototypes */
static void ata_boot_attach(void);
static void ata_intr(void *);
@@ -60,13 +81,13 @@ static char *active2str(int);
static void bswap(int8_t *, int);
static void btrim(int8_t *, int);
static void bpack(int8_t *, int8_t *, int);
+static void ata_change_mode(struct ata_softc *, int, int);
/* global vars */
devclass_t ata_devclass;
/* local vars */
static struct intr_config_hook *ata_delayed_attach = NULL;
-static char ata_conf[256];
static MALLOC_DEFINE(M_ATA, "ATA generic", "ATA driver generic layer");
/* misc defines */
@@ -243,6 +264,10 @@ ata_detach(device_t dev)
bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, scp->r_bmio);
bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, scp->r_altio);
bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, scp->r_io);
+ scp->r_io = NULL;
+ scp->r_altio = NULL;
+ scp->r_bmio = NULL;
+ scp->r_irq = NULL;
scp->active = ATA_IDLE;
return 0;
}
@@ -257,6 +282,124 @@ ata_resume(device_t dev)
}
static int
+ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p)
+{
+ int error = 0;
+
+ switch (cmd) {
+ case ATAATTACH: {
+ device_t device = devclass_get_device(ata_devclass, *(int *)addr);
+ /* should enable channel HW on controller that can SOS XXX */
+ if (!device)
+ error = ENXIO;
+ if (!error)
+ error = ata_probe(device);
+ if (!error)
+ error = ata_attach(device);
+ break;
+ }
+
+ case ATADETACH: {
+ device_t device = devclass_get_device(ata_devclass, *(int *)addr);
+ if (!device)
+ error = ENXIO;
+ if (!error)
+ error = ata_detach(device);
+ /* should disable channel HW on controller that can SOS XXX */
+ break;
+ }
+
+ case ATAREINIT: {
+ device_t device = devclass_get_device(ata_devclass, *(int *)addr);
+ struct ata_softc *scp;
+ int s;
+
+ if (!device)
+ return ENXIO;
+ scp = device_get_softc(device);
+ if (!scp)
+ return ENXIO;
+
+ /* make sure channel is not busy SOS XXX */
+ s = splbio();
+ while (!atomic_cmpset_int(&scp->active, ATA_IDLE, ATA_ACTIVE))
+ tsleep((caddr_t)&s, PRIBIO, "atachm", hz/4);
+ splx(s);
+ error = ata_reinit(scp);
+ break;
+ }
+
+ case ATAGMODE: {
+ struct ata_modes *mode = (struct ata_modes *)addr;
+ device_t device = devclass_get_device(ata_devclass, mode->channel);
+ struct ata_softc *scp;
+
+ if (!device)
+ return ENXIO;
+ scp = device_get_softc(device);
+ if (!scp)
+ return ENXIO;
+ mode->mode[MASTER] = scp->mode[MASTER];
+ mode->mode[SLAVE] = scp->mode[SLAVE];
+ break;
+ }
+
+ case ATASMODE: {
+ struct ata_modes *mode = (struct ata_modes *)addr;
+ device_t device = devclass_get_device(ata_devclass, mode->channel);
+ struct ata_softc *scp;
+
+ if (!device)
+ return ENXIO;
+ scp = device_get_softc(device);
+ if (!scp)
+ return ENXIO;
+ if (mode->mode[MASTER] >= 0)
+ ata_change_mode(scp, ATA_MASTER, mode->mode[MASTER]);
+ if (mode->mode[SLAVE] >= 0)
+ ata_change_mode(scp, ATA_SLAVE, mode->mode[SLAVE]);
+ mode->mode[MASTER] = scp->mode[MASTER];
+ mode->mode[SLAVE] = scp->mode[SLAVE];
+ break;
+ }
+
+ case ATAGPARM: {
+ struct ata_param *parm = (struct ata_param *)addr;
+ device_t device = devclass_get_device(ata_devclass, parm->channel);
+ struct ata_softc *scp;
+
+ if (!device)
+ return ENXIO;
+ scp = device_get_softc(device);
+ if (!scp)
+ return ENXIO;
+
+ parm->type[MASTER] =
+ scp->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER);
+ parm->type[SLAVE] =
+ scp->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE);
+
+ if (scp->dev_name[MASTER])
+ strcpy(parm->name[MASTER], scp->dev_name[MASTER]);
+ if (scp->dev_name[SLAVE])
+ strcpy(parm->name[SLAVE], scp->dev_name[SLAVE]);
+
+ if (scp->dev_param[MASTER])
+ bcopy(scp->dev_param[MASTER], &parm->params[MASTER],
+ sizeof(struct ata_params));
+ if (scp->dev_param[SLAVE])
+ bcopy(scp->dev_param[SLAVE], &parm->params[SLAVE],
+ sizeof(struct ata_params));
+ break;
+ }
+
+ default:
+ error = ENOTTY;
+ }
+ return error;
+}
+
+static int
ata_getparam(struct ata_softc *scp, int device, u_int8_t command)
{
struct ata_params *ata_parm;
@@ -612,6 +755,8 @@ ata_reinit(struct ata_softc *scp)
{
int devices, misdev, newdev;
+ if (!scp->r_io || !scp->r_altio || !scp->r_irq)
+ return ENXIO;
scp->active = ATA_REINITING;
scp->running = NULL;
devices = scp->devices;
@@ -619,6 +764,8 @@ ata_reinit(struct ata_softc *scp)
ata_reset(scp);
if ((misdev = devices & ~scp->devices)) {
+ if (misdev)
+ printf("\n");
#ifdef DEV_ATADISK
if (misdev & ATA_ATA_MASTER && scp->dev_softc[MASTER])
ad_detach(scp->dev_softc[MASTER], 0);
@@ -653,10 +800,10 @@ ata_reinit(struct ata_softc *scp)
if (newdev & ATA_ATAPI_SLAVE)
if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATAPI_IDENTIFY))
newdev &= ~ATA_ATAPI_SLAVE;
- if (newdev)
- printf("\n");
}
scp->active = ATA_IDLE;
+ if (!misdev && newdev)
+ printf("\n");
#ifdef DEV_ATADISK
if (newdev & ATA_ATA_MASTER && !scp->dev_softc[MASTER])
ad_attach(scp, ATA_MASTER);
@@ -834,6 +981,21 @@ ata_command(struct ata_softc *scp, int device, u_int8_t command,
return error;
}
+void
+ata_set_name(struct ata_softc *scp, int device, char *name)
+{
+ scp->dev_name[ATA_DEV(device)] = malloc(strlen(name) + 1, M_ATA, M_NOWAIT);
+ if (scp->dev_name[ATA_DEV(device)])
+ strcpy(scp->dev_name[ATA_DEV(device)], name);
+}
+
+void
+ata_free_name(struct ata_softc *scp, int device)
+{
+ if (scp->dev_name[ATA_DEV(device)])
+ free(scp->dev_name[ATA_DEV(device)], M_ATA);
+}
+
int
ata_get_lun(u_int32_t *map)
{
@@ -863,9 +1025,13 @@ ata_printf(struct ata_softc *scp, int device, const char * fmt, ...)
if (device == -1)
ret = printf("ata%d: ", device_get_unit(scp->dev));
- else
- ret = printf("ata%d-%s: ", device_get_unit(scp->dev),
- (device == ATA_MASTER) ? "master" : "slave");
+ else {
+ if (scp->dev_name[ATA_DEV(device)])
+ ret = printf("%s: ", scp->dev_name[ATA_DEV(device)]);
+ else
+ ret = printf("ata%d-%s: ", device_get_unit(scp->dev),
+ (device == ATA_MASTER) ? "master" : "slave");
+ }
va_start(ap, fmt);
ret += vprintf(fmt, ap);
va_end(ap);
@@ -1029,72 +1195,45 @@ bpack(int8_t *src, int8_t *dst, int len)
static void
ata_change_mode(struct ata_softc *scp, int device, int mode)
{
+ int umode, wmode, pmode;
int s = splbio();
while (!atomic_cmpset_int(&scp->active, ATA_IDLE, ATA_ACTIVE))
tsleep((caddr_t)&s, PRIBIO, "atachm", hz/4);
- ata_dmainit(scp, device, ata_pmode(ATA_PARAM(scp, device)),
- mode < ATA_DMA ? -1 : ata_wmode(ATA_PARAM(scp, device)),
- mode < ATA_DMA ? -1 : ata_umode(ATA_PARAM(scp, device)));
+ umode = ata_umode(ATA_PARAM(scp, device));
+ wmode = ata_wmode(ATA_PARAM(scp, device));
+ pmode = ata_pmode(ATA_PARAM(scp, device));
+
+ switch (mode & ATA_DMA_MASK) {
+ case ATA_UDMA:
+ if ((mode & ATA_MODE_MASK) < umode)
+ umode = mode & ATA_MODE_MASK;
+ break;
+ case ATA_WDMA:
+ if ((mode & ATA_MODE_MASK) < wmode)
+ wmode = mode & ATA_MODE_MASK;
+ umode = -1;
+ break;
+ default:
+ if (((mode & ATA_MODE_MASK) - ATA_PIO0) < pmode)
+ pmode = (mode & ATA_MODE_MASK) - ATA_PIO0;
+ umode = -1;
+ wmode = -1;
+ }
+ ata_dmainit(scp, device, pmode, wmode, umode);
+
scp->active = ATA_IDLE;
ata_start(scp);
splx(s);
}
-static int
-sysctl_hw_ata(SYSCTL_HANDLER_ARGS)
-{
- struct ata_softc *scp;
- int ctlr, error, i;
-
- /* readout internal state */
- bzero(ata_conf, sizeof(ata_conf));
- for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) {
- if (!(scp = devclass_get_softc(ata_devclass, ctlr)))
- continue;
- for (i = 0; i < 2; i++) {
- if (!scp->dev_softc[i])
- strcat(ata_conf, "---,");
- else if (scp->mode[i] >= ATA_DMA)
- strcat(ata_conf, "dma,");
- else
- strcat(ata_conf, "pio,");
- }
- }
- error = sysctl_handle_string(oidp, ata_conf, sizeof(ata_conf), req);
- if (error == 0 && req->newptr != NULL) {
- char *ptr = ata_conf;
-
- /* update internal state */
- i = 0;
- while (*ptr) {
- if (!strncmp(ptr, "pio", 3) || !strncmp(ptr, "PIO", 3)) {
- if ((scp = devclass_get_softc(ata_devclass, i >> 1)) &&
- scp->dev_softc[i & 1] && scp->mode[i & 1] >= ATA_DMA)
- ata_change_mode(scp, (i & 1)?ATA_SLAVE:ATA_MASTER, ATA_PIO);
- }
- else if (!strncmp(ptr, "dma", 3) || !strncmp(ptr, "DMA", 3)) {
- if ((scp = devclass_get_softc(ata_devclass, i >> 1)) &&
- scp->dev_softc[i & 1] && scp->mode[i & 1] < ATA_DMA)
- ata_change_mode(scp, (i & 1)?ATA_SLAVE:ATA_MASTER, ATA_DMA);
- }
- else if (strncmp(ptr, "---", 3))
- break;
- ptr+=3;
- if (*ptr++ != ',' ||
- ++i > (devclass_get_maxunit(ata_devclass) << 1))
- break;
- }
- }
- return error;
-}
-SYSCTL_PROC(_hw, OID_AUTO, atamodes, CTLTYPE_STRING | CTLFLAG_RW,
- 0, sizeof(ata_conf), sysctl_hw_ata, "A", "");
-
static void
ata_init(void)
{
+ /* register controlling device */
+ make_dev(&ata_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0666, "ata");
+
/* register boot attach to be run when interrupts are enabled */
if (!(ata_delayed_attach = (struct intr_config_hook *)
malloc(sizeof(struct intr_config_hook),
diff --git a/sys/dev/ata/ata-all.h b/sys/dev/ata/ata-all.h
index b02fd3b..77e81ab 100644
--- a/sys/dev/ata/ata-all.h
+++ b/sys/dev/ata/ata-all.h
@@ -149,137 +149,6 @@ struct ata_dmaentry {
u_int32_t count;
};
-/* ATA/ATAPI device parameter information */
-struct ata_params {
- u_int8_t cmdsize :2; /* packet command size */
-#define ATAPI_PSIZE_12 0 /* 12 bytes */
-#define ATAPI_PSIZE_16 1 /* 16 bytes */
-
- u_int8_t :3;
- u_int8_t drqtype :2; /* DRQ type */
-#define ATAPI_DRQT_MPROC 0 /* cpu 3 ms delay */
-#define ATAPI_DRQT_INTR 1 /* intr 10 ms delay */
-#define ATAPI_DRQT_ACCEL 2 /* accel 50 us delay */
-
- u_int8_t removable :1; /* device is removable */
- u_int8_t device_type :5; /* device type */
-#define ATAPI_TYPE_DIRECT 0 /* disk/floppy */
-#define ATAPI_TYPE_TAPE 1 /* streaming tape */
-#define ATAPI_TYPE_CDROM 5 /* CD-ROM device */
-#define ATAPI_TYPE_OPTICAL 7 /* optical disk */
-
- u_int8_t :1;
- u_int8_t proto :2; /* command protocol */
-#define ATAPI_PROTO_ATAPI 2
-
- u_int16_t cylinders; /* number of cylinders */
- u_int16_t reserved2;
- u_int16_t heads; /* # heads */
- u_int16_t unfbytespertrk; /* # unformatted bytes/track */
- u_int16_t unfbytes; /* # unformatted bytes/sector */
- u_int16_t sectors; /* # sectors/track */
- u_int16_t vendorunique0[3];
- u_int8_t serial[20]; /* serial number */
- u_int16_t buffertype; /* buffer type */
-#define ATA_BT_SINGLEPORTSECTOR 1 /* 1 port, 1 sector buffer */
-#define ATA_BT_DUALPORTMULTI 2 /* 2 port, mult sector buffer */
-#define ATA_BT_DUALPORTMULTICACHE 3 /* above plus track cache */
-
- u_int16_t buffersize; /* buf size, 512-byte units */
- u_int16_t necc; /* ecc bytes appended */
- u_int8_t revision[8]; /* firmware revision */
- u_int8_t model[40]; /* model name */
- u_int8_t nsecperint; /* sectors per interrupt */
- u_int8_t vendorunique1;
- u_int16_t usedmovsd; /* double word read/write? */
-
- u_int8_t vendorcap; /* vendor capabilities */
- u_int8_t dmaflag :1; /* DMA supported - always 1 */
- 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 softreset :1; /* needs softreset when busy */
- u_int8_t stdby_ovlap :1; /* standby/overlap supported */
- u_int8_t queueing :1; /* supports queuing overlap */
- u_int8_t idmaflag :1; /* interleaved DMA supported */
- u_int16_t capvalidate; /* validation for above */
-
- u_int8_t vendorunique3;
- u_int8_t opiomode; /* PIO modes 0-2 */
- u_int8_t vendorunique4;
- u_int8_t odmamode; /* old DMA modes, not ATA-3 */
-
- u_int16_t atavalid; /* fields valid */
-#define ATA_FLAG_54_58 1 /* words 54-58 valid */
-#define ATA_FLAG_64_70 2 /* words 64-70 valid */
-#define ATA_FLAG_88 4 /* word 88 valid */
-
- u_int16_t currcyls;
- u_int16_t currheads;
- u_int16_t currsectors;
- u_int16_t currsize0;
- u_int16_t currsize1;
- u_int8_t currmultsect;
- u_int8_t multsectvalid;
- u_int32_t lbasize;
-
- u_int16_t sdmamodes; /* singleword DMA modes */
- u_int16_t wdmamodes; /* multiword DMA modes */
- u_int16_t apiomodes; /* advanced PIO modes */
-
- u_int16_t mwdmamin; /* min. M/W DMA time/word ns */
- u_int16_t mwdmarec; /* rec. M/W DMA time ns */
- u_int16_t pioblind; /* min. PIO cycle w/o flow */
- u_int16_t pioiordy; /* min. PIO cycle IORDY flow */
-
- u_int16_t reserved69;
- u_int16_t reserved70;
- u_int16_t rlsovlap; /* rel time (us) for overlap */
- u_int16_t rlsservice; /* rel time (us) for service */
- u_int16_t reserved73;
- u_int16_t reserved74;
- u_int16_t queuelen:5;
- u_int16_t :11;
- u_int16_t reserved76;
- u_int16_t reserved77;
- u_int16_t reserved78;
- u_int16_t reserved79;
- u_int16_t versmajor;
- u_int16_t versminor;
- u_int16_t featsupp1; /* 82 */
- u_int16_t supmicrocode:1;
- u_int16_t supqueued:1;
- u_int16_t supcfa:1;
- u_int16_t supapm:1;
- u_int16_t suprmsn:1;
- u_int16_t :11;
- u_int16_t featsupp3; /* 84 */
- u_int16_t featenab1; /* 85 */
- u_int16_t enabmicrocode:1;
- u_int16_t enabqueued:1;
- u_int16_t enabcfa:1;
- u_int16_t enabapm:1;
- u_int16_t enabrmsn:1;
- u_int16_t :11;
- u_int16_t featenab3; /* 87 */
- u_int16_t udmamodes; /* UltraDMA modes */
- u_int16_t erasetime;
- u_int16_t enherasetime;
- u_int16_t apmlevel;
- u_int16_t masterpasswdrev;
- u_int16_t masterhwres :8;
- u_int16_t slavehwres :5;
- u_int16_t cblid :1;
- u_int16_t reserved93_1415 :2;
- u_int16_t reserved94[32];
- u_int16_t rmvstat;
- u_int16_t securstat;
- u_int16_t reserved129[30];
- u_int16_t cfapwrmode;
- u_int16_t reserved161[84];
- u_int16_t integrity;
-};
-
/* structure describing an ATA device */
struct ata_softc {
struct device *dev; /* device handle */
@@ -292,21 +161,10 @@ struct ata_softc {
int (*intr_func)(struct ata_softc *); /* interrupt function */
u_int32_t chiptype; /* pciid of controller chip */
u_int32_t alignment; /* dma engine min alignment */
+ char *dev_name[2]; /* name of device */
struct ata_params *dev_param[2]; /* ptr to devices params */
void *dev_softc[2]; /* ptr to devices softc's */
int mode[2]; /* transfer mode for devices */
-#define ATA_PIO 0x00
-#define ATA_PIO0 0x08
-#define ATA_PIO1 0x09
-#define ATA_PIO2 0x0a
-#define ATA_PIO3 0x0b
-#define ATA_PIO4 0x0c
-#define ATA_DMA 0x10
-#define ATA_WDMA2 0x22
-#define ATA_UDMA2 0x42
-#define ATA_UDMA4 0x44
-#define ATA_UDMA5 0x45
-
int flags; /* controller flags */
#define ATA_DMA_ACTIVE 0x01
#define ATA_ATAPI_DMA_RO 0x02
@@ -352,6 +210,8 @@ int ata_reinit(struct ata_softc *);
int ata_wait(struct ata_softc *, int, u_int8_t);
int ata_command(struct ata_softc *, int, u_int8_t, u_int16_t, u_int8_t, u_int8_t, u_int8_t, u_int8_t, int);
int ata_printf(struct ata_softc *, int, const char *, ...) __printflike(3, 4);
+void ata_set_name(struct ata_softc *, int, char *);
+void ata_free_name(struct ata_softc *, int);
int ata_get_lun(u_int32_t *);
int ata_test_lun(u_int32_t *, int);
void ata_free_lun(u_int32_t *, int);
diff --git a/sys/dev/ata/ata-disk.c b/sys/dev/ata/ata-disk.c
index e7d15ed..7910e94 100644
--- a/sys/dev/ata/ata-disk.c
+++ b/sys/dev/ata/ata-disk.c
@@ -32,6 +32,7 @@
#include "opt_ata.h"
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/ata.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/bio.h>
@@ -81,6 +82,10 @@ static int ad_version(u_int16_t);
/* internal vars */
static u_int32_t adp_lun_map = 0;
static MALLOC_DEFINE(M_AD, "AD driver", "ATA disk driver");
+static int ata_dma, ata_wc, ata_tags;
+TUNABLE_INT_DECL("hw.ata.ata_dma", 1, ata_dma);
+TUNABLE_INT_DECL("hw.ata.wc", 0, ata_wc);
+TUNABLE_INT_DECL("hw.ata.tags", 0, ata_tags);
/* defines */
#define AD_MAX_RETRIES 3
@@ -95,6 +100,7 @@ ad_attach(struct ata_softc *scp, int device)
struct ad_softc *adp;
dev_t dev;
int secsperint;
+ char name[16];
if (!(adp = malloc(sizeof(struct ad_softc), M_AD, M_NOWAIT | M_ZERO))) {
ata_printf(scp, device, "failed to allocate driver storage\n");
@@ -107,6 +113,8 @@ ad_attach(struct ata_softc *scp, int device)
#else
adp->lun = ata_get_lun(&adp_lun_map);
#endif
+ sprintf(name, "ad%d", adp->lun);
+ ata_set_name(scp, device, name);
adp->heads = AD_PARAM->heads;
adp->sectors = AD_PARAM->sectors;
adp->total_secs = AD_PARAM->cylinders * adp->heads * adp->sectors;
@@ -127,35 +135,41 @@ ad_attach(struct ata_softc *scp, int device)
adp->transfersize *= secsperint;
}
- /* enable read/write cacheing if not default on device */
+ /* enable read cacheing if not default on device */
if (ata_command(adp->controller, adp->unit, ATA_C_SETFEATURES,
0, 0, 0, 0, ATA_C_F_ENAB_RCACHE, ATA_WAIT_INTR))
- printf("ad%d: enabling readahead cache failed\n", adp->lun);
+ ata_printf(scp, device, "enabling readahead cache failed\n");
-#if defined(ATA_ENABLE_WC) || defined(ATA_ENABLE_TAGS)
- if (ata_command(adp->controller, adp->unit, ATA_C_SETFEATURES,
- 0, 0, 0, 0, ATA_C_F_ENAB_WCACHE, ATA_WAIT_INTR))
- printf("ad%d: enabling write cache failed\n", adp->lun);
-#else
- if (ata_command(adp->controller, adp->unit, ATA_C_SETFEATURES,
- 0, 0, 0, 0, ATA_C_F_DIS_WCACHE, ATA_WAIT_INTR))
- printf("ad%d: disabling write cache failed\n", adp->lun);
-#endif
- /* use DMA if drive & controller supports it */
- ata_dmainit(adp->controller, adp->unit,
- ata_pmode(AD_PARAM), ata_wmode(AD_PARAM), ata_umode(AD_PARAM));
+ /* enable write cacheing if allowed and not default on device */
+ if (ata_wc || ata_tags) {
+ if (ata_command(adp->controller, adp->unit, ATA_C_SETFEATURES,
+ 0, 0, 0, 0, ATA_C_F_ENAB_WCACHE, ATA_WAIT_INTR))
+ ata_printf(scp, device, "enabling write cache failed\n");
+ }
+ else {
+ if (ata_command(adp->controller, adp->unit, ATA_C_SETFEATURES,
+ 0, 0, 0, 0, ATA_C_F_DIS_WCACHE, ATA_WAIT_INTR))
+ ata_printf(scp, device, "disabling write cache failed\n");
+ }
- /* use tagged queueing if supported */
- if (ad_tagsupported(adp)) {
+ /* use DMA if allowed and if drive/controller supports it */
+ if (ata_dma)
+ 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);
+
+ /* use tagged queueing if allowed and supported */
+ if (ata_tags && ad_tagsupported(adp)) {
adp->num_tags = AD_PARAM->queuelen;
adp->flags |= AD_F_TAG_ENABLED;
adp->controller->flags |= ATA_QUEUED;
if (ata_command(adp->controller, adp->unit, ATA_C_SETFEATURES,
0, 0, 0, 0, ATA_C_F_DIS_RELIRQ, ATA_WAIT_INTR))
- printf("ad%d: disabling release interrupt failed\n", adp->lun);
+ ata_printf(scp, device, "disabling release interrupt failed\n");
if (ata_command(adp->controller, adp->unit, ATA_C_SETFEATURES,
0, 0, 0, 0, ATA_C_F_DIS_SRVIRQ, ATA_WAIT_INTR))
- printf("ad%d: disabling service interrupt failed\n", adp->lun);
+ ata_printf(scp, device, "disabling service interrupt failed\n");
}
devstat_add_entry(&adp->stats, "ad", adp->lun, DEV_BSIZE,
@@ -170,32 +184,31 @@ ad_attach(struct ata_softc *scp, int device)
bioq_init(&adp->queue);
if (bootverbose) {
- printf("ad%d: <%.40s/%.8s> ATA-%d disk at ata%d-%s\n",
- adp->lun, AD_PARAM->model, AD_PARAM->revision,
- ad_version(AD_PARAM->versmajor), device_get_unit(scp->dev),
- (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%s\n",
- adp->lun, adp->transfersize / DEV_BSIZE, adp->num_tags + 1,
- (adp->flags & AD_F_TAG_ENABLED) ? "tagged " : "",
- ata_mode2str(adp->controller->mode[ATA_DEV(adp->unit)]));
+ ata_printf(scp, device, "<%.40s/%.8s> ATA-%d disk at ata%d-%s\n",
+ AD_PARAM->model, AD_PARAM->revision,
+ ad_version(AD_PARAM->versmajor), device_get_unit(scp->dev),
+ (adp->unit == ATA_MASTER) ? "master" : "slave");
- 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);
+ ata_printf(scp, device, "%luMB (%u sectors), %u C, %u H, %u S, %u B\n",
+ adp->total_secs / ((1024L*1024L)/DEV_BSIZE), adp->total_secs,
+ adp->total_secs / (adp->heads * adp->sectors),
+ adp->heads, adp->sectors, DEV_BSIZE);
+
+ ata_printf(scp, device, "%d secs/int, %d depth queue, %s%s\n",
+ adp->transfersize / DEV_BSIZE, adp->num_tags + 1,
+ (adp->flags & AD_F_TAG_ENABLED) ? "tagged " : "",
+ ata_mode2str(adp->controller->mode[ATA_DEV(adp->unit)]));
+
+ ata_printf(scp, device, "piomode=%d dmamode=%d udmamode=%d cblid=%d\n",
+ ata_pmode(AD_PARAM), ata_wmode(AD_PARAM),
+ ata_umode(AD_PARAM), AD_PARAM->cblid);
}
/* if this disk belongs to an ATA RAID dont print the probe */
if (ar_probe(adp))
- printf("ad%d: %luMB <%.40s> [%d/%d/%d] at ata%d-%s %s%s\n",
- adp->lun, adp->total_secs / ((1024L * 1024L) / DEV_BSIZE),
+ ata_printf(scp, device, "%luMB <%.40s> [%d/%d/%d] at ata%d-%s %s%s\n",
+ adp->total_secs / ((1024L * 1024L) / DEV_BSIZE),
AD_PARAM->model, adp->total_secs / (adp->heads * adp->sectors),
adp->heads, adp->sectors, device_get_unit(scp->dev),
(adp->unit == ATA_MASTER) ? "master" : "slave",
@@ -213,7 +226,7 @@ ad_detach(struct ad_softc *adp, int flush)
struct bio *bp;
adp->flags |= AD_F_DETACHING;
- printf("\nad%d: being removed from configuration", adp->lun);
+ ata_printf(adp->controller, adp->unit, "removed from configuration\n");
TAILQ_FOREACH(request, &adp->controller->ata_queue, chain) {
if (request->device != adp)
continue;
@@ -234,7 +247,8 @@ ad_detach(struct ad_softc *adp, int flush)
if (flush) {
if (ata_command(adp->controller, adp->unit, ATA_C_FLUSHCACHE,
0, 0, 0, 0, 0, ATA_WAIT_INTR))
- printf("ad%d: flushing cache on detach failed\n", adp->lun);
+ ata_printf(adp->controller, adp->unit,
+ "flushing cache on detach failed\n");
}
ata_free_lun(&adp_lun_map, adp->lun);
adp->controller->dev_softc[ATA_DEV(adp->unit)] = NULL;
@@ -354,8 +368,8 @@ addump(dev_t dev)
}
if (ata_wait(adp->controller, adp->unit, ATA_S_READY | ATA_S_DSC) < 0)
- printf("ad%d: timeout waiting for final ready\n", adp->lun);
-
+ ata_printf(adp->controller, adp->unit,
+ "timeout waiting for final ready\n");
return 0;
}
@@ -388,7 +402,7 @@ ad_start(struct ad_softc *adp)
}
if (!(request = malloc(sizeof(struct ad_request), M_AD, M_NOWAIT|M_ZERO))) {
- printf("ad%d: out of memory in start\n", adp->lun);
+ ata_printf(adp->controller, adp->unit, "out of memory in start\n");
return;
}
@@ -442,8 +456,8 @@ ad_transfer(struct ad_request *request)
count = howmany(request->bytecount, DEV_BSIZE);
if (count > 256) {
count = 256;
- printf("ad%d: count %d size transfers not supported\n",
- adp->lun, count);
+ ata_printf(adp->controller, adp->unit,
+ "count %d size transfers not supported\n", count);
}
if (adp->flags & AD_F_LBA_ENABLED) {
@@ -479,11 +493,13 @@ ad_transfer(struct ad_request *request)
if (ata_command(adp->controller, adp->unit, cmd,
cylinder, head, sector, request->tag << 3,
count, ATA_IMMEDIATE)) {
- printf("ad%d: error executing command", adp->lun);
+ ata_printf(adp->controller, adp->unit,
+ "error executing command");
goto transfer_failed;
}
if (ata_wait(adp->controller, adp->unit, ATA_S_READY)) {
- printf("ad%d: timeout waiting for READY\n", adp->lun);
+ ata_printf(adp->controller, adp->unit,
+ "timeout waiting for READY\n");
goto transfer_failed;
}
adp->outstanding++;
@@ -500,7 +516,8 @@ ad_transfer(struct ad_request *request)
if (ata_command(adp->controller, adp->unit, cmd, cylinder,
head, sector, count, 0, ATA_IMMEDIATE)) {
- printf("ad%d: error executing command", adp->lun);
+ ata_printf(adp->controller, adp->unit,
+ "error executing command");
goto transfer_failed;
}
#if 0
@@ -514,7 +531,8 @@ ad_transfer(struct ad_request *request)
*/
if (ata_wait(adp->controller, adp->unit,
ATA_S_READY | ATA_S_DRQ)) {
- printf("ad%d: timeout waiting for data phase\n", adp->lun);
+ ata_printf(adp->controller, adp->unit,
+ "timeout waiting for data phase\n");
goto transfer_failed;
}
#endif
@@ -536,7 +554,7 @@ ad_transfer(struct ad_request *request)
if (ata_command(adp->controller, adp->unit, cmd,
cylinder, head, sector, count, 0, ATA_IMMEDIATE)) {
- printf("ad%d: error executing command", adp->lun);
+ ata_printf(adp->controller, adp->unit, "error executing command");
goto transfer_failed;
}
}
@@ -551,7 +569,7 @@ ad_transfer(struct ad_request *request)
/* ready to write PIO data ? */
if (ata_wait(adp->controller, adp->unit,
(ATA_S_READY | ATA_S_DSC | ATA_S_DRQ)) < 0) {
- printf("ad%d: timeout waiting for DRQ", adp->lun);
+ ata_printf(adp->controller, adp->unit, "timeout waiting for DRQ");
goto transfer_failed;
}
@@ -650,7 +668,8 @@ ad_interrupt(struct ad_request *request)
/* if we arrived here with forced PIO mode, DMA doesn't work right */
if (request->flags & ADR_F_FORCE_PIO)
- printf("ad%d: DMA problem fallback to PIO mode\n", adp->lun);
+ ata_printf(adp->controller, adp->unit,
+ "DMA problem fallback to PIO mode\n");
/* if this was a PIO read operation, get the data */
if (!(request->flags & ADR_F_DMA_USED) &&
@@ -659,11 +678,13 @@ ad_interrupt(struct ad_request *request)
/* ready to receive data? */
if ((adp->controller->status & (ATA_S_READY | ATA_S_DSC | ATA_S_DRQ))
!= (ATA_S_READY | ATA_S_DSC | ATA_S_DRQ))
- printf("ad%d: read interrupt arrived early", adp->lun);
+ ata_printf(adp->controller, adp->unit,
+ "read interrupt arrived early");
if (ata_wait(adp->controller, adp->unit,
(ATA_S_READY | ATA_S_DSC | ATA_S_DRQ)) != 0) {
- printf("ad%d: read error detected (too) late", adp->lun);
+ ata_printf(adp->controller, adp->unit,
+ "read error detected (too) late");
request->flags |= ADR_F_ERROR;
}
else {
@@ -703,7 +724,7 @@ ad_interrupt(struct ad_request *request)
request->flags |= ADR_F_FLUSHCACHE;
if (ata_command(adp->controller, adp->unit, ATA_C_FLUSHCACHE,
0, 0, 0, 0, 0, ATA_IMMEDIATE))
- printf("ad%d: flushing cache failed\n", adp->lun);
+ ata_printf(adp->controller, adp->unit, "flushing cache failed\n");
else
return ATA_OP_CONTINUES;
}
@@ -758,8 +779,9 @@ ad_service(struct ad_softc *adp, int change)
/* check for error */
if (adp->controller->status & ATA_S_ERROR) {
- printf("ad%d: Oops! controller says s=0x%02x e=0x%02x\n",
- adp->lun, adp->controller->status, adp->controller->error);
+ ata_printf(adp->controller, adp->unit,
+ "Oops! controller says s=0x%02x e=0x%02x\n",
+ adp->controller->status, adp->controller->error);
ad_invalidatequeue(adp, NULL);
return ATA_OP_FINISHED;
}
@@ -767,22 +789,25 @@ ad_service(struct ad_softc *adp, int change)
/* issue SERVICE cmd */
if (ata_command(adp->controller, adp->unit, ATA_C_SERVICE,
0, 0, 0, 0, 0, ATA_IMMEDIATE)) {
- printf("ad%d: problem executing SERVICE cmd\n", adp->lun);
+ ata_printf(adp->controller, adp->unit,
+ "problem executing SERVICE cmd\n");
ad_invalidatequeue(adp, NULL);
return ATA_OP_FINISHED;
}
/* setup the transfer environment when ready */
if (ata_wait(adp->controller, adp->unit, ATA_S_READY)) {
- printf("ad%d: problem issueing SERVICE tag=%d s=0x%02x e=0x%02x\n",
- adp->lun, ATA_INB(adp->controller->r_io, ATA_COUNT) >> 3,
- adp->controller->status, adp->controller->error);
+ ata_printf(adp->controller, adp->unit,
+ "problem issueing SERVICE tag=%d s=0x%02x e=0x%02x\n",
+ ATA_INB(adp->controller->r_io, ATA_COUNT) >> 3,
+ adp->controller->status, adp->controller->error);
ad_invalidatequeue(adp, NULL);
return ATA_OP_FINISHED;
}
tag = ATA_INB(adp->controller->r_io, ATA_COUNT) >> 3;
if (!(request = adp->tags[tag])) {
- printf("ad%d: no request for this tag=%d??\n", adp->lun, tag);
+ ata_printf(adp->controller, adp->unit,
+ "no request for tag=%d\n", tag);
ad_invalidatequeue(adp, NULL);
return ATA_OP_FINISHED;
}
@@ -792,8 +817,9 @@ ad_service(struct ad_softc *adp, int change)
/* start DMA transfer when ready */
if (ata_wait(adp->controller, adp->unit, ATA_S_READY | ATA_S_DRQ)) {
- printf("ad%d: timeout waiting for data phase s=%02x e=%02x\n",
- adp->lun, adp->controller->status, adp->controller->error);
+ ata_printf(adp->controller, adp->unit,
+ "timeout waiting for data phase s=%02x e=%02x\n",
+ adp->controller->status, adp->controller->error);
ad_invalidatequeue(adp, NULL);
return ATA_OP_FINISHED;
}
@@ -825,7 +851,7 @@ ad_invalidatequeue(struct ad_softc *adp, struct ad_request *request)
struct ad_request *tmpreq;
int tag;
- printf("ad%d: invalidating queued requests\n", adp->lun);
+ ata_printf(adp->controller, adp->unit,"invalidating queued requests\n");
for (tag = 0; tag <= adp->num_tags; tag++) {
tmpreq = adp->tags[tag];
adp->tags[tag] = NULL;
@@ -836,7 +862,7 @@ ad_invalidatequeue(struct ad_softc *adp, struct ad_request *request)
}
if (ata_command(adp->controller, adp->unit, ATA_C_NOP,
0, 0, 0, 0, ATA_C_F_FLUSHQUEUE, ATA_WAIT_READY))
- printf("ad%d: flushing queue failed\n", adp->lun);
+ ata_printf(adp->controller, adp->unit, "flush queue failed\n");
adp->outstanding = 0;
}
}
@@ -844,7 +870,6 @@ ad_invalidatequeue(struct ad_softc *adp, struct ad_request *request)
static int
ad_tagsupported(struct ad_softc *adp)
{
-#ifdef ATA_ENABLE_TAGS
const char *drives[] = {"IBM-DPTA", "IBM-DTLA", NULL};
int i = 0;
@@ -852,15 +877,15 @@ ad_tagsupported(struct ad_softc *adp)
if ((adp->controller->chiptype & 0x0000ffff) == 0x0000105a)
return 0;
- /* check that drive has tags enabled, and is one we know works */
- if (AD_PARAM->supqueued && AD_PARAM->enabqueued) {
+ /* check that drive does DMA, has tags enabled, and is one we know works */
+ if (adp->controller->mode[ATA_DEV(adp->unit)] >= ATA_DMA &&
+ AD_PARAM->supqueued && AD_PARAM->enabqueued) {
while (drives[i] != NULL) {
if (!strncmp(AD_PARAM->model, drives[i], strlen(drives[i])))
return 1;
i++;
}
}
-#endif
return 0;
}
@@ -871,9 +896,10 @@ ad_timeout(struct ad_request *request)
int s = splbio();
adp->controller->running = NULL;
- printf("ad%d: %s command timeout tag=%d serv=%d - resetting\n",
- adp->lun, (request->flags & ADR_F_READ) ? "READ" : "WRITE",
- request->tag, request->serv);
+ ata_printf(adp->controller, adp->unit,
+ "%s command timeout tag=%d serv=%d - resetting\n",
+ (request->flags & ADR_F_READ) ? "READ" : "WRITE",
+ request->tag, request->serv);
if (request->flags & ADR_F_DMA_USED) {
ata_dmadone(adp->controller);
@@ -881,7 +907,8 @@ ad_timeout(struct ad_request *request)
if (request->retries == AD_MAX_RETRIES) {
ata_dmainit(adp->controller, adp->unit,
ata_pmode(AD_PARAM), -1, -1);
- printf("ad%d: trying fallback to PIO mode\n", adp->lun);
+ ata_printf(adp->controller, adp->unit,
+ "trying fallback to PIO mode\n");
request->retries = 0;
}
}
diff --git a/sys/dev/ata/ata-dma.c b/sys/dev/ata/ata-dma.c
index 4832248..e6cf1ca 100644
--- a/sys/dev/ata/ata-dma.c
+++ b/sys/dev/ata/ata-dma.c
@@ -31,6 +31,7 @@
#include "pci.h"
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/ata.h>
#include <sys/bio.h>
#include <sys/malloc.h>
#include <sys/bus.h>
diff --git a/sys/dev/ata/ata-raid.c b/sys/dev/ata/ata-raid.c
index 19f6a34..8f876a3 100644
--- a/sys/dev/ata/ata-raid.c
+++ b/sys/dev/ata/ata-raid.c
@@ -32,6 +32,7 @@
#include "opt_ata.h"
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/ata.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/bio.h>
diff --git a/sys/dev/ata/atapi-all.c b/sys/dev/ata/atapi-all.c
index 002288b..c19e0d8 100644
--- a/sys/dev/ata/atapi-all.c
+++ b/sys/dev/ata/atapi-all.c
@@ -32,6 +32,7 @@
#include "opt_ata.h"
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/ata.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/malloc.h>
@@ -51,6 +52,8 @@ static char *atapi_skey2str(u_int8_t);
/* internal vars */
static MALLOC_DEFINE(M_ATAPI, "ATAPI generic", "ATAPI driver generic layer");
+static int atapi_dma;
+TUNABLE_INT_DECL("hw.ata.atapi_dma", 0, atapi_dma);
/* defines */
#define ATAPI_MAX_RETRIES 3
@@ -73,8 +76,7 @@ atapi_attach(struct ata_softc *scp, int device)
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)) {
+ if (atapi_dma && !(ATP_PARAM->drqtype == ATAPI_DRQT_INTR)){
ata_dmainit(atp->controller, atp->unit,
(ata_pmode(ATP_PARAM) < 0) ?
(ATP_PARAM->dmaflag ? 4 : 0) : ata_pmode(ATP_PARAM),
@@ -83,10 +85,8 @@ atapi_attach(struct ata_softc *scp, int device)
ata_umode(ATP_PARAM));
}
else
-#endif
- /* set PIO mode */
ata_dmainit(atp->controller, atp->unit,
- ata_pmode(ATP_PARAM)<0 ? 0 : ata_pmode(ATP_PARAM), -1, -1);
+ ata_pmode(ATP_PARAM) < 0 ? 0 : ata_pmode(ATP_PARAM), -1,-1);
switch (ATP_PARAM->device_type) {
#ifdef DEV_ATAPICD
@@ -126,7 +126,7 @@ atapi_detach(struct atapi_softc *atp)
struct atapi_request *request;
atp->flags |= ATAPI_F_DETACHING;
- printf("\n%s: being removed from configuration", atp->devname);
+ ata_printf(atp->controller, atp->unit, "removed from configuration\n");
switch (ATP_PARAM->device_type) {
#ifdef DEV_ATAPICD
case ATAPI_TYPE_CDROM:
@@ -200,8 +200,8 @@ atapi_queue_cmd(struct atapi_softc *atp, int8_t *ccb, caddr_t data,
/* append onto controller queue and try to start controller */
#ifdef ATAPI_DEBUG
- printf("%s: queueing %s ",
- request->device->devname, atapi_cmd2str(request->ccb[0]));
+ ata_printf(atp->controller, atp->unit, "queueing %s ",
+ atapi_cmd2str(request->ccb[0]));
atapi_dump("ccb = ", &request->ccb[0], sizeof(request->ccb));
#endif
if (flags & ATPR_F_AT_HEAD)
@@ -221,8 +221,8 @@ atapi_queue_cmd(struct atapi_softc *atp, int8_t *ccb, caddr_t data,
splx(s);
error = request->error;
#ifdef ATAPI_DEBUG
- printf("%s: finished %s\n",
- request->device->devname, atapi_cmd2str(request->ccb[0]));
+ ata_printf(atp->controller, atp->unit, "finished %s\n",
+ atapi_cmd2str(request->ccb[0]));
#endif
if (request->dmatab)
free(request->dmatab, M_DEVBUF);
@@ -262,8 +262,8 @@ atapi_transfer(struct atapi_request *request)
u_int8_t reason;
#ifdef ATAPI_DEBUG
- printf("%s: starting %s ",
- request->device->devname, atapi_cmd2str(request->ccb[0]));
+ ata_printf(atp->controller, atp->unit, "starting %s ",
+ atapi_cmd2str(request->ccb[0]));
atapi_dump("ccb = ", &request->ccb[0], sizeof(request->ccb));
#endif
/* is this just a POLL DSC command ? */
@@ -312,7 +312,8 @@ atapi_transfer(struct atapi_request *request)
request->bytecount, 0, 0, 0,
(request->flags & ATPR_F_DMA_USED) ? ATA_F_DMA : 0,
ATA_IMMEDIATE))
- printf("%s: failure to send ATAPI packet command\n", atp->devname);
+ ata_printf(atp->controller, atp->unit,
+ "failure to send ATAPI packet command\n");
if (request->flags & ATPR_F_DMA_USED)
ata_dmastart(atp->controller, atp->unit,
@@ -334,7 +335,8 @@ atapi_transfer(struct atapi_request *request)
}
if (timout <= 0) {
request->result = ATA_INB(atp->controller->r_io, ATA_ERROR);
- printf("%s: failure to execute ATAPI packet command\n", atp->devname);
+ ata_printf(atp->controller, atp->unit,
+ "failure to execute ATAPI packet command\n");
return;
}
@@ -358,7 +360,8 @@ atapi_interrupt(struct atapi_request *request)
if (reason == ATAPI_P_CMDOUT) {
if (!(atp->controller->status & ATA_S_DRQ)) {
request->result = ATA_INB(atp->controller->r_io, ATA_ERROR);
- printf("%s: command interrupt without DRQ\n", atp->devname);
+ ata_printf(atp->controller, atp->unit,
+ "command interrupt without DRQ\n");
goto op_finished;
}
ATA_OUTSW(atp->controller->r_io, ATA_DATA, (int16_t *)request->ccb,
@@ -386,8 +389,9 @@ atapi_interrupt(struct atapi_request *request)
case ATAPI_P_WRITE:
if (request->flags & ATPR_F_READ) {
request->result = ATA_INB(atp->controller->r_io, ATA_ERROR);
- printf("%s: %s trying to write on read buffer\n",
- atp->devname, atapi_cmd2str(atp->cmd));
+ ata_printf(atp->controller, atp->unit,
+ "%s trying to write on read buffer\n",
+ atapi_cmd2str(atp->cmd));
break;
}
atapi_write(request, length);
@@ -396,15 +400,17 @@ atapi_interrupt(struct atapi_request *request)
case ATAPI_P_READ:
if (!(request->flags & ATPR_F_READ)) {
request->result = ATA_INB(atp->controller->r_io, ATA_ERROR);
- printf("%s: %s trying to read on write buffer\n",
- atp->devname, atapi_cmd2str(atp->cmd));
+ ata_printf(atp->controller, atp->unit,
+ "%s trying to read on write buffer\n",
+ atapi_cmd2str(atp->cmd));
break;
}
atapi_read(request, length);
return ATA_OP_CONTINUES;
case ATAPI_P_DONEDRQ:
- printf("%s: %s DONEDRQ\n", atp->devname, atapi_cmd2str(atp->cmd));
+ ata_printf(atp->controller, atp->unit, "%s DONEDRQ\n",
+ atapi_cmd2str(atp->cmd));
if (request->flags & ATPR_F_READ)
atapi_read(request, length);
else
@@ -421,7 +427,8 @@ atapi_interrupt(struct atapi_request *request)
break;
default:
- printf("%s: unknown transfer phase %d\n", atp->devname, reason);
+ ata_printf(atp->controller, atp->unit,
+ "unknown transfer phase %d\n", reason);
}
}
@@ -442,9 +449,10 @@ op_finished:
if (request->result) {
switch ((request->result & ATAPI_SK_MASK)) {
case ATAPI_SK_RESERVED:
- printf("%s: %s - timeout error = %02x\n",
- atp->devname,
- atapi_cmd2str(atp->cmd), request->result & ATAPI_E_MASK);
+ ata_printf(atp->controller, atp->unit,
+ "%s - timeout error=0x%02x\n",
+ atapi_cmd2str(atp->cmd),
+ request->result & ATAPI_E_MASK);
request->error = EIO;
break;
@@ -453,8 +461,9 @@ op_finished:
break;
case ATAPI_SK_RECOVERED_ERROR:
- printf("%s: %s - recovered error\n",
- atp->devname, atapi_cmd2str(atp->cmd));
+ ata_printf(atp->controller, atp->unit,
+ "%s - recovered error\n",
+ atapi_cmd2str(atp->cmd));
request->error = 0;
break;
@@ -468,16 +477,17 @@ op_finished:
break;
default:
- printf("%s: %s - %s asc=%02x ascq=%02x ",
- atp->devname, atapi_cmd2str(atp->cmd),
- atapi_skey2str(request->sense.sense_key),
- request->sense.asc, request->sense.ascq);
+ ata_printf(atp->controller, atp->unit,
+ "%s - %s asc=0x%02x ascq=0x%02x ",
+ atapi_cmd2str(atp->cmd),
+ atapi_skey2str(request->sense.sense_key),
+ request->sense.asc, request->sense.ascq);
if (request->sense.sksv)
- printf("sks=%02x %02x %02x ",
+ printf("sks=0x%02x 0x%02x 0x%02x ",
request->sense.sk_specific,
request->sense.sk_specific1,
request->sense.sk_specific2);
- printf("error=%02x\n", request->result & ATAPI_E_MASK);
+ printf("error=0x%02x\n", request->result & ATAPI_E_MASK);
request->error = EIO;
}
}
@@ -485,8 +495,8 @@ op_finished:
request->error = 0;
if (request->callback) {
#ifdef ATAPI_DEBUG
- printf("%s: finished %s (callback)\n",
- request->device->devname, atapi_cmd2str(request->ccb[0]));
+ ata_printf(atp->controller, atp->unit, "finished %s (callback)\n",
+ atapi_cmd2str(request->ccb[0]));
#endif
if (!((request->callback)(request))) {
if (request->dmatab)
@@ -548,10 +558,10 @@ atapi_dump(char *label, void *data, int len)
{
u_int8_t *p = data;
- printf ("%s %02x", label, *p++);
+ printf("%s %02x", label, *p++);
while (--len > 0)
printf ("-%02x", *p++);
- printf ("\n");
+ printf("\n");
}
static void
@@ -559,24 +569,24 @@ atapi_read(struct atapi_request *request, int length)
{
int8_t **buffer = (int8_t **)&request->data;
int size = min(request->bytecount, length);
+ struct ata_softc *scp = request->device->controller;
int resid;
if (request->flags & ATPR_F_INTERNAL)
*buffer = (int8_t *)&request->sense;
- if (request->device->controller->flags & ATA_USE_16BIT ||
- (size % sizeof(int32_t)))
- ATA_INSW(request->device->controller->r_io, ATA_DATA,
- (void *)((uintptr_t)*buffer), size / sizeof(int16_t));
+ if (scp->flags & ATA_USE_16BIT || (size % sizeof(int32_t)))
+ ATA_INSW(scp->r_io, ATA_DATA, (void *)((uintptr_t)*buffer),
+ size / sizeof(int16_t));
else
- ATA_INSL(request->device->controller->r_io, ATA_DATA,
- (void *)((uintptr_t)*buffer), size / sizeof(int32_t));
+ ATA_INSL(scp->r_io, ATA_DATA, (void *)((uintptr_t)*buffer),
+ size / sizeof(int32_t));
if (request->bytecount < length) {
- printf("%s: read data overrun %d/%d\n",
- request->device->devname, length, request->bytecount);
+ ata_printf(scp, request->device->unit, "read data overrun %d/%d\n",
+ length, request->bytecount);
for (resid=request->bytecount; resid<length; resid+=sizeof(int16_t))
- ATA_INW(request->device->controller->r_io, ATA_DATA);
+ ATA_INW(scp->r_io, ATA_DATA);
}
*buffer += size;
request->bytecount -= size;
@@ -588,24 +598,24 @@ atapi_write(struct atapi_request *request, int length)
{
int8_t **buffer = (int8_t **)&request->data;
int size = min(request->bytecount, length);
+ struct ata_softc *scp = request->device->controller;
int resid;
if (request->flags & ATPR_F_INTERNAL)
*buffer = (int8_t *)&request->sense;
- if (request->device->controller->flags & ATA_USE_16BIT ||
- (size % sizeof(int32_t)))
- ATA_OUTSW(request->device->controller->r_io, ATA_DATA,
- (void *)((uintptr_t)*buffer), size / sizeof(int16_t));
+ if (scp->flags & ATA_USE_16BIT || (size % sizeof(int32_t)))
+ ATA_OUTSW(scp->r_io, ATA_DATA, (void *)((uintptr_t)*buffer),
+ size / sizeof(int16_t));
else
- ATA_OUTSL(request->device->controller->r_io, ATA_DATA,
- (void *)((uintptr_t)*buffer), size / sizeof(int32_t));
+ ATA_OUTSL(scp->r_io, ATA_DATA, (void *)((uintptr_t)*buffer),
+ size / sizeof(int32_t));
if (request->bytecount < length) {
- printf("%s: write data underrun %d/%d\n",
- request->device->devname, length, request->bytecount);
+ ata_printf(scp, request->device->unit, "write data underrun %d/%d\n",
+ length, request->bytecount);
for (resid=request->bytecount; resid<length; resid+=sizeof(int16_t))
- ATA_OUTW(request->device->controller->r_io, ATA_DATA, 0);
+ ATA_OUTW(scp->r_io, ATA_DATA, 0);
}
*buffer += size;
request->bytecount -= size;
@@ -619,15 +629,16 @@ atapi_timeout(struct atapi_request *request)
int s = splbio();
atp->controller->running = NULL;
- printf("%s: %s command timeout - resetting\n",
- atp->devname, atapi_cmd2str(request->ccb[0]));
+ ata_printf(atp->controller, atp->unit, "%s command timeout - resetting\n",
+ atapi_cmd2str(request->ccb[0]));
if (request->flags & ATPR_F_DMA_USED) {
ata_dmadone(atp->controller);
if (request->retries == ATAPI_MAX_RETRIES) {
ata_dmainit(atp->controller, atp->unit,
(ata_pmode(ATP_PARAM)<0)?0:ata_pmode(ATP_PARAM),-1,-1);
- printf("%s: trying fallback to PIO mode\n", atp->devname);
+ ata_printf(atp->controller, atp->unit,
+ "trying fallback to PIO mode\n");
request->retries = 0;
}
}
diff --git a/sys/dev/ata/atapi-all.h b/sys/dev/ata/atapi-all.h
index e08589d..10263e1 100644
--- a/sys/dev/ata/atapi-all.h
+++ b/sys/dev/ata/atapi-all.h
@@ -146,7 +146,6 @@ struct atapi_softc {
struct ata_softc *controller; /* ptr to controller softc */
int unit; /* ATA_MASTER or ATA_SLAVE */
void *driver; /* ptr to subdriver softc */
- char *devname; /* this devices name */
u_int8_t cmd; /* last cmd executed */
int flags; /* drive flags */
#define ATAPI_F_MEDIA_CHANGED 0x0001
diff --git a/sys/dev/ata/atapi-cd.c b/sys/dev/ata/atapi-cd.c
index 7f7e6e5..773d7b4 100644
--- a/sys/dev/ata/atapi-cd.c
+++ b/sys/dev/ata/atapi-cd.c
@@ -30,6 +30,7 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/ata.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/bio.h>
@@ -107,6 +108,7 @@ acdattach(struct atapi_softc *atp)
struct acd_softc *cdp;
struct changer *chp;
int count, error = 0;
+ char name[16];
static int acd_cdev_done = 0;
if (!acd_cdev_done) {
@@ -116,7 +118,7 @@ acdattach(struct atapi_softc *atp)
}
if ((cdp = acd_init_lun(atp, NULL)) == NULL) {
- printf("acd: out of memory\n");
+ ata_printf(atp->controller, atp->unit, "acd: out of memory\n");
return -1;
}
@@ -146,7 +148,7 @@ acdattach(struct atapi_softc *atp)
chp = malloc(sizeof(struct changer), M_ACD, M_NOWAIT | M_ZERO);
if (chp == NULL) {
- printf("acd: out of memory\n");
+ ata_printf(atp->controller, atp->unit, "out of memory\n");
free(cdp, M_ACD);
return -1;
}
@@ -158,12 +160,11 @@ acdattach(struct atapi_softc *atp)
struct acd_softc *tmpcdp = cdp;
struct acd_softc **cdparr;
int count;
- char string[16];
chp->table_length = htons(chp->table_length);
if (!(cdparr = malloc(sizeof(struct acd_softc) * chp->slots,
M_ACD, M_NOWAIT))) {
- printf("acd: out of memory\n");
+ ata_printf(atp->controller, atp->unit, "out of memory\n");
free(chp, M_ACD);
free(cdp, M_ACD);
return -1;
@@ -172,7 +173,7 @@ acdattach(struct atapi_softc *atp)
if (count > 0) {
tmpcdp = acd_init_lun(atp, cdp->stats);
if (!tmpcdp) {
- printf("acd: out of memory\n");
+ ata_printf(atp->controller,atp->unit,"out of memory\n");
break;
}
}
@@ -180,20 +181,14 @@ acdattach(struct atapi_softc *atp)
tmpcdp->driver = cdparr;
tmpcdp->slot = count;
tmpcdp->changer_info = chp;
- if (bootverbose)
- printf("acd%d: changer slot %d %s\n", tmpcdp->lun, count,
- (chp->slot[count].present ? "CD present" : "empty"));
acd_make_dev(tmpcdp);
}
- sprintf(string, "acd%d-%d", cdp->lun,
+ sprintf(name, "acd%d-%d", cdp->lun,
cdp->lun + cdp->changer_info->slots - 1);
- devstat_add_entry(cdp->stats, string, tmpcdp->lun, DEV_BSIZE,
+ devstat_add_entry(cdp->stats, name, tmpcdp->lun, DEV_BSIZE,
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_IDE,
DEVSTAT_PRIORITY_CD);
- if ((cdp->atp->devname = malloc(8, M_ACD, M_NOWAIT)))
- sprintf(cdp->atp->devname, "acd%d-%d", cdp->lun,
- cdp->lun + cdp->changer_info->slots - 1);
}
}
else {
@@ -202,8 +197,8 @@ acdattach(struct atapi_softc *atp)
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_IDE,
DEVSTAT_PRIORITY_CD);
- if ((cdp->atp->devname = malloc(8, M_ACD, M_NOWAIT)))
- sprintf(cdp->atp->devname, "acd%d", cdp->lun);
+ sprintf(name, "acd%d", cdp->lun);
+ ata_set_name(atp->controller, atp->unit, name);
}
cdp->atp->driver = cdp;
acd_describe(cdp);
@@ -230,7 +225,6 @@ acddetach(struct atapi_softc *atp)
destroy_dev(cdp->dev2);
devstat_remove_entry(cdp->stats);
free(cdp->stats, M_ACD);
- free(cdp->atp->devname, M_ACD);
ata_free_lun(&acd_lun_map, cdp->lun);
free(cdp, M_ACD);
}
@@ -246,7 +240,7 @@ acddetach(struct atapi_softc *atp)
destroy_dev(cdp->dev2);
devstat_remove_entry(cdp->stats);
free(cdp->stats, M_ACD);
- free(cdp->atp->devname, M_ACD);
+ ata_free_name(atp->controller, atp->unit);
ata_free_lun(&acd_lun_map, cdp->lun);
free(cdp, M_ACD);
}
@@ -322,20 +316,21 @@ acd_describe(struct acd_softc *cdp)
char *mechanism;
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",
- device_get_unit(cdp->atp->controller->dev),
- (cdp->atp->unit == ATA_MASTER) ? "master" : "slave");
-
- printf("acd%d:", cdp->lun);
+ ata_printf(cdp->atp->controller, cdp->atp->unit,
+ "<%.40s/%.8s> %s drive at ata%d as %s\n",
+ 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",
+ device_get_unit(cdp->atp->controller->dev),
+ (cdp->atp->unit == ATA_MASTER) ? "master" : "slave");
+
+ ata_printf(cdp->atp->controller, cdp->atp->unit, "");
if (cdp->cap.cur_read_speed) {
- printf(" read %dKB/s", cdp->cap.cur_read_speed * 1000 / 1024);
+ 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) &&
@@ -355,7 +350,7 @@ acd_describe(struct acd_softc *cdp)
comma ? "," : "", ata_mode2str(
cdp->atp->controller->mode[ATA_DEV(cdp->atp->unit)]));
- printf("acd%d: Reads:", cdp->lun);
+ ata_printf(cdp->atp->controller, cdp->atp->unit, "Reads:");
comma = 0;
if (cdp->cap.read_cdr) {
printf(" CD-R"); comma = 1;
@@ -382,9 +377,10 @@ acd_describe(struct acd_softc *cdp)
if (cdp->cap.read_packet)
printf("%s packet", comma ? "," : "");
+ printf("\n");
+ ata_printf(cdp->atp->controller, cdp->atp->unit, "Writes:");
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;
@@ -404,14 +400,16 @@ acd_describe(struct acd_softc *cdp)
if (cdp->cap.burnproof)
printf("%s burnproof", comma ? "," : "");
}
+ printf("\n");
if (cdp->cap.audio_play) {
- printf("\nacd%d: Audio: ", cdp->lun);
+ ata_printf(cdp->atp->controller, cdp->atp->unit, "Audio:");
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);
+ printf("\n");
+ ata_printf(cdp->atp->controller, cdp->atp->unit, "Mechanism:");
switch (cdp->cap.mech) {
case MST_MECH_CADDY:
mechanism = "caddy"; break;
@@ -432,7 +430,7 @@ acd_describe(struct acd_softc *cdp)
printf("ejectable");
if (cdp->cap.mech != MST_MECH_CHANGER) {
- printf("\nacd%d: Medium: ", cdp->lun);
+ ata_printf(cdp->atp->controller, cdp->atp->unit, "Medium:");
switch (cdp->cap.medium_type & MST_TYPE_MASK_HIGH) {
case MST_CDROM:
printf("CD-ROM "); break;
@@ -486,28 +484,24 @@ acd_describe(struct acd_softc *cdp)
printf("\n");
}
else {
- char changer[32];
- char devnum[8];
-
- bzero(changer, sizeof(changer));
- if (cdp->changer_info) {
- sprintf(devnum, "%d-%d",
- cdp->lun, cdp->lun + cdp->changer_info->slots - 1);
- sprintf(changer, " with %d CD changer", cdp->changer_info->slots);
- }
- else
- sprintf(devnum, "%d", cdp->lun);
-
- printf("acd%s: %s%s <%.40s> at ata%d-%s %s\n",
- devnum, (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,
- device_get_unit(cdp->atp->controller->dev),
- (cdp->atp->unit == ATA_MASTER) ? "master" : "slave",
- ata_mode2str(cdp->atp->controller->mode[ATA_DEV(cdp->atp->unit)])
+ char chg[32];
+
+ bzero(chg, sizeof(chg));
+ if (cdp->changer_info)
+ sprintf(chg, " with %d CD changer", cdp->changer_info->slots);
+
+ ata_printf(cdp->atp->controller, cdp->atp->unit,
+ "%s%s <%.40s> at ata%d-%s %s\n",
+ (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",
+ chg, ATA_PARAM(cdp->atp->controller, cdp->atp->unit)->model,
+ device_get_unit(cdp->atp->controller->dev),
+ (cdp->atp->unit == ATA_MASTER) ? "master" : "slave",
+ ata_mode2str(cdp->atp->controller->
+ mode[ATA_DEV(cdp->atp->unit)])
);
}
}
@@ -1316,8 +1310,9 @@ acd_read_toc(struct acd_softc *cdp)
bzero(&cdp->disklabel, sizeof(struct disklabel));
strncpy(cdp->disklabel.d_typename, " ",
sizeof(cdp->disklabel.d_typename));
- strncpy(cdp->disklabel.d_typename, cdp->atp->devname,
- min(strlen(cdp->atp->devname),
+ strncpy(cdp->disklabel.d_typename,
+ cdp->atp->controller->dev_name[ATA_DEV(cdp->atp->unit)],
+ min(strlen(cdp->atp->controller->dev_name[ATA_DEV(cdp->atp->unit)]),
sizeof(cdp->disklabel.d_typename) - 1));
strncpy(cdp->disklabel.d_packname, "unknown ",
sizeof(cdp->disklabel.d_packname));
@@ -1340,15 +1335,15 @@ acd_read_toc(struct acd_softc *cdp)
#ifdef ACD_DEBUG
if (cdp->info.volsize && cdp->toc.hdr.ending_track) {
- printf("acd%d: ", cdp->lun);
+ ata_printf(cdp->atp->controller, cdp->atp->unit,
+ "(%d sectors (%d bytes)), %d tracks ",
+ cdp->info.volsize, cdp->info.blksize,
+ cdp->toc.hdr.ending_track - cdp->toc.hdr.starting_track + 1);
if (cdp->toc.tab[0].control & 4)
- printf("%dMB ", cdp->info.volsize / 512);
+ printf("%dMB\n", cdp->info.volsize / 512);
else
- printf("%d:%d audio ", cdp->info.volsize / 75 / 60,
+ printf("%d:%d audio\n", cdp->info.volsize / 75 / 60,
cdp->info.volsize / 75 % 60);
- printf("(%d sectors (%d bytes)), %d tracks\n",
- cdp->info.volsize, cdp->info.blksize,
- cdp->toc.hdr.ending_track - cdp->toc.hdr.starting_track + 1);
}
#endif
}
@@ -1895,8 +1890,9 @@ acd_mode_select(struct acd_softc *cdp, caddr_t pagebuf, int pagesize)
pagesize>>8, pagesize, 0, 0, 0, 0, 0, 0, 0 };
#ifdef ACD_DEBUG
- printf("acd: modeselect pagesize=%d\n", pagesize);
- atapi_dump("acd: mode select ", pagebuf, pagesize);
+ ata_printf(cdp->atp->controller, cdp->atp->unit,
+ "modeselect pagesize=%d\n", pagesize);
+ atapi_dump("mode select ", pagebuf, pagesize);
#endif
return atapi_queue_cmd(cdp->atp, ccb, pagebuf, pagesize, 0, 30, NULL, NULL);
}
diff --git a/sys/dev/ata/atapi-fd.c b/sys/dev/ata/atapi-fd.c
index bb3bf3d..9d19984 100644
--- a/sys/dev/ata/atapi-fd.c
+++ b/sys/dev/ata/atapi-fd.c
@@ -30,6 +30,7 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/ata.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/bio.h>
@@ -83,10 +84,11 @@ afdattach(struct atapi_softc *atp)
{
struct afd_softc *fdp;
dev_t dev;
+ char name[16];
fdp = malloc(sizeof(struct afd_softc), M_AFD, M_NOWAIT | M_ZERO);
if (!fdp) {
- printf("afd: out of memory\n");
+ ata_printf(atp->controller, atp->unit, "out of memory\n");
return -1;
}
bioq_init(&fdp->queue);
@@ -112,8 +114,8 @@ afdattach(struct atapi_softc *atp)
fdp->dev = dev;
fdp->atp->flags |= ATAPI_F_MEDIA_CHANGED;
fdp->atp->driver = fdp;
- if ((fdp->atp->devname = malloc(8, M_AFD, M_NOWAIT)))
- sprintf(fdp->atp->devname, "afd%d", fdp->lun);
+ sprintf(name, "afd%d", fdp->lun);
+ ata_set_name(atp->controller, atp->unit, name);
afd_describe(fdp);
return 0;
}
@@ -132,7 +134,7 @@ afddetach(struct atapi_softc *atp)
disk_invalidate(&fdp->disk);
disk_destroy(fdp->dev);
devstat_remove_entry(&fdp->stats);
- free(fdp->atp->devname, M_AFD);
+ ata_free_name(atp->controller, atp->unit);
ata_free_lun(&afd_lun_map, fdp->lun);
free(fdp, M_AFD);
}
@@ -183,25 +185,27 @@ static void
afd_describe(struct afd_softc *fdp)
{
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,
- device_get_unit(fdp->atp->controller->dev),
- (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);
+ ata_printf(fdp->atp->controller, fdp->atp->unit,
+ "<%.40s/%.8s> rewriteable drive at ata%d as %s\n",
+ ATA_PARAM(fdp->atp->controller, fdp->atp->unit)->model,
+ ATA_PARAM(fdp->atp->controller, fdp->atp->unit)->revision,
+ device_get_unit(fdp->atp->controller->dev),
+ (fdp->atp->unit == ATA_MASTER) ? "master" : "slave");
+ ata_printf(fdp->atp->controller, fdp->atp->unit,
+ "%luMB (%u sectors), %u cyls, %u heads, %u S/T, %u B/S\n",
+ (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);
+ ata_printf(fdp->atp->controller, fdp->atp->unit, "%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)]));
if (fdp->header.medium_type) {
- printf("afd%d: Medium: ", fdp->lun);
+ ata_printf(fdp->atp->controller, fdp->atp->unit, "Medium: ");
switch (fdp->header.medium_type) {
case MFD_2DD:
printf("720KB DD disk"); break;
@@ -223,15 +227,16 @@ afd_describe(struct afd_softc *fdp)
printf("\n");
}
else {
- printf("afd%d: %luMB <%.40s> [%d/%d/%d] at ata%d-%s %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->cap.cylinders, fdp->cap.heads, fdp->cap.sectors,
- device_get_unit(fdp->atp->controller->dev),
- (fdp->atp->unit == ATA_MASTER) ? "master" : "slave",
- ata_mode2str(fdp->atp->controller->mode[ATA_DEV(fdp->atp->unit)])
- );
+ ata_printf(fdp->atp->controller, fdp->atp->unit,
+ "%luMB <%.40s> [%d/%d/%d] at ata%d-%s %s\n",
+ (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->cap.cylinders, fdp->cap.heads, fdp->cap.sectors,
+ device_get_unit(fdp->atp->controller->dev),
+ (fdp->atp->unit == ATA_MASTER) ? "master" : "slave",
+ ata_mode2str(fdp->atp->controller->
+ mode[ATA_DEV(fdp->atp->unit)]));
}
}
@@ -247,7 +252,8 @@ afdopen(dev_t dev, int flags, int fmt, struct proc *p)
afd_prevent_allow(fdp, 1);
if (afd_sense(fdp))
- printf("afd%d: sense media type failed\n", fdp->lun);
+ ata_printf(fdp->atp->controller, fdp->atp->unit,
+ "sense media type failed\n");
fdp->atp->flags &= ~ATAPI_F_MEDIA_CHANGED;
diff --git a/sys/dev/ata/atapi-tape.c b/sys/dev/ata/atapi-tape.c
index 7fa8fc5..d9a2843 100644
--- a/sys/dev/ata/atapi-tape.c
+++ b/sys/dev/ata/atapi-tape.c
@@ -30,6 +30,7 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/ata.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/malloc.h>
@@ -90,6 +91,7 @@ astattach(struct atapi_softc *atp)
struct ast_softc *stp;
struct ast_readposition position;
dev_t dev;
+ char name[16];
static int ast_cdev_done = 0;
if (!ast_cdev_done) {
@@ -98,7 +100,7 @@ astattach(struct atapi_softc *atp)
}
stp = malloc(sizeof(struct ast_softc), M_AST, M_NOWAIT | M_ZERO);
if (!stp) {
- printf("ast: out of memory\n");
+ ata_printf(atp->controller, atp->unit, "out of memory\n");
return -1;
}
bioq_init(&stp->queue);
@@ -141,8 +143,8 @@ astattach(struct atapi_softc *atp)
stp->dev2 = dev;
stp->atp->flags |= ATAPI_F_MEDIA_CHANGED;
stp->atp->driver = stp;
- if ((stp->atp->devname = malloc(8, M_AST, M_NOWAIT)))
- sprintf(stp->atp->devname, "ast%d", stp->lun);
+ sprintf(name, "ast%d", stp->lun);
+ ata_set_name(atp->controller, atp->unit, name);
ast_describe(stp);
return 0;
}
@@ -161,7 +163,7 @@ astdetach(struct atapi_softc *atp)
destroy_dev(stp->dev1);
destroy_dev(stp->dev2);
devstat_remove_entry(&stp->stats);
- free(stp->atp->devname, M_AST);
+ ata_free_name(atp->controller, atp->unit);
ata_free_lun(&ast_lun_map, stp->lun);
free(stp, M_AST);
}
@@ -198,19 +200,20 @@ static void
ast_describe(struct ast_softc *stp)
{
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,
- device_get_unit(stp->atp->controller->dev),
- (stp->atp->unit == ATA_MASTER) ? "master" : "slave");
- printf("ast%d: ", stp->lun);
- printf("%dKB/s, ", stp->cap.max_speed);
+ ata_printf(stp->atp->controller, stp->atp->unit,
+ "<%.40s/%.8s> tape drive at ata%d as %s\n",
+ ATA_PARAM(stp->atp->controller, stp->atp->unit)->model,
+ ATA_PARAM(stp->atp->controller, stp->atp->unit)->revision,
+ device_get_unit(stp->atp->controller->dev),
+ (stp->atp->unit == ATA_MASTER) ? "master" : "slave");
+ ata_printf(stp->atp->controller, stp->atp->unit, "%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);
+ ata_printf(stp->atp->controller, stp->atp->unit, "");
switch (stp->cap.medium_type) {
case 0x00:
printf("Drive empty"); break;
@@ -240,12 +243,13 @@ ast_describe(struct ast_softc *stp)
printf("\n");
}
else {
- printf("ast%d: TAPE <%.40s> at ata%d-%s %s\n",
- stp->lun, ATA_PARAM(stp->atp->controller, stp->atp->unit)->model,
- device_get_unit(stp->atp->controller->dev),
- (stp->atp->unit == ATA_MASTER) ? "master" : "slave",
- ata_mode2str(stp->atp->controller->mode[ATA_DEV(stp->atp->unit)])
- );
+ ata_printf(stp->atp->controller, stp->atp->unit,
+ "TAPE <%.40s> at ata%d-%s %s\n",
+ ATA_PARAM(stp->atp->controller, stp->atp->unit)->model,
+ device_get_unit(stp->atp->controller->dev),
+ (stp->atp->unit == ATA_MASTER) ? "master" : "slave",
+ ata_mode2str(stp->atp->controller->
+ mode[ATA_DEV(stp->atp->unit)]));
}
}
@@ -266,7 +270,8 @@ astopen(dev_t dev, int flags, int fmt, struct proc *p)
ast_prevent_allow(stp, 1);
if (ast_sense(stp))
- printf("ast%d: sense media type failed\n", stp->lun);
+ ata_printf(stp->atp->controller, stp->atp->unit,
+ "sense media type failed\n");
stp->atp->flags &= ~ATAPI_F_MEDIA_CHANGED;
stp->flags &= ~(F_DATA_WRITTEN | F_FM_WRITTEN);
@@ -297,7 +302,8 @@ astclose(dev_t dev, int flags, int fmt, struct proc *p)
stp->flags &= F_CTL_WARN;
#ifdef AST_DEBUG
- printf("ast%d: %llu total bytes transferred\n", stp->lun, ast_total);
+ ata_printf(stp->atp->controller, stp->atp->unit,
+ "%llu total bytes transferred\n", ast_total);
#endif
return 0;
}
@@ -442,8 +448,8 @@ aststrategy(struct bio *bp)
/* check for != blocksize requests */
if (bp->bio_bcount % stp->blksize) {
- printf("ast%d: bad request, must be multiple of %d\n",
- stp->lun, stp->blksize);
+ ata_printf(stp->atp->controller, stp->atp->unit,
+ "bad request, must be multiple of %d\n", stp->blksize);
bp->bio_error = EIO;
bp->bio_flags |= BIO_ERROR;
biodone(bp);
@@ -453,8 +459,9 @@ aststrategy(struct bio *bp)
/* warn about transfers bigger than the device suggests */
if (bp->bio_bcount > stp->blksize * stp->cap.ctl) {
if ((stp->flags & F_CTL_WARN) == 0) {
- printf("ast%d: WARNING: CTL exceeded %ld>%d\n",
- stp->lun, bp->bio_bcount, stp->blksize * stp->cap.ctl);
+ ata_printf(stp->atp->controller, stp->atp->unit,
+ "WARNING: CTL exceeded %ld>%d\n",
+ bp->bio_bcount, stp->blksize * stp->cap.ctl);
stp->flags |= F_CTL_WARN;
}
}
@@ -541,8 +548,9 @@ ast_mode_select(struct ast_softc *stp, void *pagebuf, int pagesize)
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
#ifdef AST_DEBUG
- printf("ast: modeselect pagesize=%d\n", pagesize);
- atapi_dump("ast: mode select ", pagebuf, pagesize);
+ ata_printf(stp->atp->controller, stp->atp->unit,
+ "modeselect pagesize=%d\n", pagesize);
+ atapi_dump("mode select ", pagebuf, pagesize);
#endif
return atapi_queue_cmd(stp->atp, ccb, pagebuf, pagesize, 0, 10,
NULL, NULL);
OpenPOWER on IntegriCloud