aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/ata/atapi-tape.c
diff options
context:
space:
mode:
authorSøren Schmidt <sos@FreeBSD.org>2005-03-30 12:03:40 +0000
committerSøren Schmidt <sos@FreeBSD.org>2005-03-30 12:03:40 +0000
commit8ca4df3299628bad609cb74ee2f76671e07b4788 (patch)
treed973712ac291429795c126539153aec43f4cd2c1 /sys/dev/ata/atapi-tape.c
parent4cb39345c04e97c604c2ed923eea4db5fa7e2632 (diff)
downloadsrc-8ca4df3299628bad609cb74ee2f76671e07b4788.tar.gz
src-8ca4df3299628bad609cb74ee2f76671e07b4788.zip
This is the much rumoured ATA mkIII update that I've been working on.
o ATA is now fully newbus'd and split into modules. This means that on a modern system you just load "atapci and ata" to get the base support, and then one or more of the device subdrivers "atadisk atapicd atapifd atapist ataraid". All can be loaded/unloaded anytime, but for obvious reasons you dont want to unload atadisk when you have mounted filesystems. o The device identify part of the probe has been rewritten to fix the problems with odd devices the old had, and to try to remove so of the long delays some HW could provoke. Also probing is done without the need for interrupts, making earlier probing possible. o SATA devices can be hot inserted/removed and devices will be created/ removed in /dev accordingly. NOTE: only supported on controllers that has this feature: Promise and Silicon Image for now. On other controllers the usual atacontrol detach/attach dance is still needed. o Support for "atomic" composite ATA requests used for RAID. o ATA RAID support has been rewritten and and now supports these metadata formats: "Adaptec HostRAID" "Highpoint V2 RocketRAID" "Highpoint V3 RocketRAID" "Intel MatrixRAID" "Integrated Technology Express" "LSILogic V2 MegaRAID" "LSILogic V3 MegaRAID" "Promise FastTrak" "Silicon Image Medley" "FreeBSD PseudoRAID" o Update the ioctl API to match new RAID levels etc. o Update atacontrol to know about the new RAID levels etc NOTE: you need to recompile atacontrol with the new sys/ata.h, make world will take care of that. NOTE2: that rebuild is done differently from the old system as the rebuild is now done piggybacked on read requests to the array, so atacontrol simply starts a background "dd" to rebuild the array. o The reinit code has been worked over to be much more robust. o The timeout code has been overhauled for races. o Support of new chipsets. o Lots of fixes for bugs found while doing the modulerization and reviewing the old code. Missing or changed features from current ATA: o atapi-cd no longer has support for ATAPI changers. Todays its much cheaper and alot faster to copy those CD images to disk and serve them from there. Besides they dont seem to be made anymore, maybe for that exact reason. o ATA RAID can only read metadata from all the above metadata formats, not write all of them (Promise and Highpoint V2 so far). This means that arrays can be picked up from the BIOS, but they cannot be created from FreeBSD. There is more to it than just the missing write metadata support, those formats are not unique to a given controller like Promise and Highpoint formats, instead they exist for several types, and even worse, some controllers can have different formats and its impossible to tell which one. The outcome is that we cannot reliably create the metadata of those formats and be sure the controller BIOS will understand it. However write support is needed to update/fail/rebuild the arrays properly so it sits fairly high on the TODO list. o So far atapicam is not supported with these changes. When/if this will change is up to the maintainer of atapi-cam so go there for questions. HW donated by: Webveveriet AS HW donated by: Frode Nordahl HW donated by: Yahoo! HW donated by: Sentex Patience by: Vife and my boys (and even the cats)
Notes
Notes: svn path=/head/; revision=144330
Diffstat (limited to 'sys/dev/ata/atapi-tape.c')
-rw-r--r--sys/dev/ata/atapi-tape.c630
1 files changed, 347 insertions, 283 deletions
diff --git a/sys/dev/ata/atapi-tape.c b/sys/dev/ata/atapi-tape.c
index 827edec19c11..b1e90f06fb30 100644
--- a/sys/dev/ata/atapi-tape.c
+++ b/sys/dev/ata/atapi-tape.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 1998 - 2004 Søren Schmidt <sos@FreeBSD.org>
+ * Copyright (c) 1998 - 2005 Søren Schmidt <sos@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,8 +34,9 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/ata.h>
#include <sys/kernel.h>
-#include <sys/conf.h>
+#include <sys/module.h>
#include <sys/malloc.h>
+#include <sys/conf.h>
#include <sys/bio.h>
#include <sys/bus.h>
#include <sys/mtio.h>
@@ -46,281 +47,234 @@ __FBSDID("$FreeBSD$");
#include <machine/bus.h>
#include <dev/ata/ata-all.h>
#include <dev/ata/atapi-tape.h>
+#include <ata_if.h>
-/* device structures */
-static d_open_t ast_open;
-static d_close_t ast_close;
-static d_ioctl_t ast_ioctl;
-static d_strategy_t ast_strategy;
+/* device structure */
+static d_open_t ast_open;
+static d_close_t ast_close;
+static d_ioctl_t ast_ioctl;
+static d_strategy_t ast_strategy;
static struct cdevsw ast_cdevsw = {
- .d_version = D_VERSION,
- .d_open = ast_open,
- .d_close = ast_close,
- .d_read = physread,
- .d_write = physwrite,
- .d_ioctl = ast_ioctl,
- .d_strategy = ast_strategy,
- .d_name = "ast",
- .d_flags = D_TAPE | D_TRACKCLOSE,
+ .d_version = D_VERSION,
+ .d_open = ast_open,
+ .d_close = ast_close,
+ .d_read = physread,
+ .d_write = physwrite,
+ .d_ioctl = ast_ioctl,
+ .d_strategy = ast_strategy,
+ .d_name = "ast",
+ .d_flags = D_TAPE | D_TRACKCLOSE,
};
/* prototypes */
-static void ast_detach(struct ata_device *);
-static void ast_start(struct ata_device *);
-static int ast_sense(struct ast_softc *);
-static void ast_describe(struct ast_softc *);
+static int ast_sense(device_t);
+static void ast_describe(device_t);
static void ast_done(struct ata_request *);
-static int ast_mode_sense(struct ast_softc *, int, void *, int);
-static int ast_mode_select(struct ast_softc *, void *, int);
-static int ast_write_filemark(struct ast_softc *, u_int8_t);
-static int ast_read_position(struct ast_softc *, int, struct ast_readposition *);
-static int ast_space(struct ast_softc *, u_int8_t, int32_t);
-static int ast_locate(struct ast_softc *, int, u_int32_t);
-static int ast_prevent_allow(struct ast_softc *stp, int);
-static int ast_load_unload(struct ast_softc *, u_int8_t);
-static int ast_rewind(struct ast_softc *);
-static int ast_erase(struct ast_softc *);
-static int ast_test_ready(struct ata_device *);
-static int ast_wait_dsc(struct ata_device *, int);
+static int ast_mode_sense(device_t, int, void *, int);
+static int ast_mode_select(device_t, void *, int);
+static int ast_write_filemark(device_t, u_int8_t);
+static int ast_read_position(device_t, int, struct ast_readposition *);
+static int ast_space(device_t, u_int8_t, int32_t);
+static int ast_locate(device_t, int, u_int32_t);
+static int ast_prevent_allow(device_t, int);
+static int ast_load_unload(device_t, u_int8_t);
+static int ast_rewind(device_t);
+static int ast_erase(device_t);
+static int ast_test_ready(device_t);
+static int ast_wait_dsc(device_t, int);
/* internal vars */
-static u_int32_t ast_lun_map = 0;
static u_int64_t ast_total = 0;
static MALLOC_DEFINE(M_AST, "AST driver", "ATAPI tape driver buffers");
-void
-ast_attach(struct ata_device *atadev)
+static void
+ast_identify(driver_t *driver, device_t parent)
+{
+ ata_identify(driver, parent, ATA_ATAPI_TYPE_TAPE, "ast");
+}
+
+static int
+ast_probe(device_t dev)
+{
+ return 0;
+}
+
+static int
+ast_attach(device_t dev)
{
+ struct ata_channel *ch = device_get_softc(device_get_parent(dev));
+ struct ata_device *atadev = device_get_softc(dev);
struct ast_softc *stp;
struct ast_readposition position;
- struct cdev *dev;
+ struct cdev *device;
- stp = malloc(sizeof(struct ast_softc), M_AST, M_NOWAIT | M_ZERO);
- if (!stp) {
- ata_prtdev(atadev, "out of memory\n");
- return;
+ if (!(stp = malloc(sizeof(struct ast_softc), M_AST, M_NOWAIT | M_ZERO))) {
+ device_printf(dev, "out of memory\n");
+ device_set_softc(dev, NULL);
+ free(atadev, M_ATA);
+ return ENOMEM;
}
+ device_set_ivars(dev, stp);
+ ATA_SETMODE(GRANDPARENT(dev), dev);
- stp->device = atadev;
- stp->lun = ata_get_lun(&ast_lun_map);
- ata_set_name(atadev, "ast", stp->lun);
- bioq_init(&stp->queue);
- mtx_init(&stp->queue_mtx, "ATAPI TAPE bioqueue lock", NULL, MTX_DEF);
-
- if (ast_sense(stp)) {
+ if (ast_sense(dev)) {
+ device_set_ivars(dev, NULL);
free(stp, M_AST);
- return;
+ device_set_softc(dev, NULL);
+ free(atadev, M_ATA);
+ return ENXIO;
}
-
- if (!strcmp(atadev->param->model, "OnStream DI-30")) {
+ if (!strcmp(atadev->param.model, "OnStream DI-30")) {
struct ast_transferpage transfer;
struct ast_identifypage identify;
stp->flags |= F_ONSTREAM;
bzero(&transfer, sizeof(struct ast_transferpage));
- ast_mode_sense(stp, ATAPI_TAPE_TRANSFER_PAGE,
+ ast_mode_sense(dev, ATAPI_TAPE_TRANSFER_PAGE,
&transfer, sizeof(transfer));
bzero(&identify, sizeof(struct ast_identifypage));
- ast_mode_sense(stp, ATAPI_TAPE_IDENTIFY_PAGE,
+ ast_mode_sense(dev, ATAPI_TAPE_IDENTIFY_PAGE,
&identify, sizeof(identify));
strncpy(identify.ident, "FBSD", 4);
- ast_mode_select(stp, &identify, sizeof(identify));
- ast_read_position(stp, 0, &position);
+ ast_mode_select(dev, &identify, sizeof(identify));
+ ast_read_position(dev, 0, &position);
}
- stp->stats = devstat_new_entry("ast", stp->lun, DEV_BSIZE,
+ stp->stats = devstat_new_entry("ast", device_get_unit(dev), DEV_BSIZE,
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_SEQUENTIAL | DEVSTAT_TYPE_IF_IDE,
DEVSTAT_PRIORITY_TAPE);
- dev = make_dev(&ast_cdevsw, 2 * stp->lun,
- UID_ROOT, GID_OPERATOR, 0640, "ast%d", stp->lun);
- dev->si_drv1 = stp;
- if (atadev->channel->dma)
- dev->si_iosize_max = atadev->channel->dma->max_iosize;
+ device = make_dev(&ast_cdevsw, 2 * device_get_unit(dev),
+ UID_ROOT, GID_OPERATOR, 0640, "ast%d",
+ device_get_unit(dev));
+ device->si_drv1 = dev;
+ if (ch->dma)
+ device->si_iosize_max = ch->dma->max_iosize;
else
- dev->si_iosize_max = DFLTPHYS;
- stp->dev1 = dev;
- dev = make_dev(&ast_cdevsw, 2 * stp->lun + 1,
- UID_ROOT, GID_OPERATOR, 0640, "nast%d", stp->lun);
-
- dev->si_drv1 = stp;
- if (atadev->channel->dma)
- dev->si_iosize_max = atadev->channel->dma->max_iosize;
+ device->si_iosize_max = DFLTPHYS;
+ stp->dev1 = device;
+ device = make_dev(&ast_cdevsw, 2 * device_get_unit(dev) + 1,
+ UID_ROOT, GID_OPERATOR, 0640, "nast%d",
+ device_get_unit(dev));
+ device->si_drv1 = dev;
+ if (ch->dma)
+ device->si_iosize_max = ch->dma->max_iosize;
else
- dev->si_iosize_max = DFLTPHYS;
- stp->dev2 = dev;
-
- /* setup the function ptrs */
- atadev->detach = ast_detach;
- atadev->start = ast_start;
- atadev->softc = stp;
- atadev->flags |= ATA_D_MEDIA_CHANGED;
+ device->si_iosize_max = DFLTPHYS;
+ stp->dev2 = device;
- /* announce we are here */
- ast_describe(stp);
+ /* announce we are here and ready */
+ ast_describe(dev);
+ return 0;
}
-static void
-ast_detach(struct ata_device *atadev)
+static int
+ast_detach(device_t dev)
{
- struct ast_softc *stp = atadev->softc;
+ struct ata_channel *ch = device_get_softc(device_get_parent(dev));
+ struct ata_device *atadev = device_get_softc(dev);
+ struct ast_softc *stp = device_get_ivars(dev);
- mtx_lock(&stp->queue_mtx);
- bioq_flush(&stp->queue, NULL, ENXIO);
- mtx_unlock(&stp->queue_mtx);
- mtx_destroy(&stp->queue_mtx);
+ /* detroy devices from the system so we dont get any further requests */
destroy_dev(stp->dev1);
destroy_dev(stp->dev2);
+
+ /* fail requests on the queue and any thats "in flight" for this device */
+ ata_fail_requests(ch, dev);
+
+ /* dont leave anything behind */
devstat_remove_entry(stp->stats);
- ata_prtdev(atadev, "WARNING - removed from configuration\n");
- ata_free_name(atadev);
- ata_free_lun(&ast_lun_map, stp->lun);
- atadev->attach = NULL;
- atadev->detach = NULL;
- atadev->start = NULL;
- atadev->softc = NULL;
- atadev->flags = 0;
+ device_set_ivars(dev, NULL);
free(stp, M_AST);
+ device_set_softc(dev, NULL);
+ free(atadev, M_ATA);
+ return 0;
}
-static int
-ast_sense(struct ast_softc *stp)
+static void
+ast_shutdown(device_t dev)
{
- int count;
+ struct ata_device *atadev = device_get_softc(dev);
- /* get drive capabilities, some bugridden drives needs this repeated */
- for (count = 0 ; count < 5 ; count++) {
- if (!ast_mode_sense(stp, ATAPI_TAPE_CAP_PAGE,
- &stp->cap, sizeof(stp->cap)) &&
- stp->cap.page_code == ATAPI_TAPE_CAP_PAGE) {
- 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;
- }
- }
- return 1;
+ if (atadev->param.support.command2 & ATA_SUPPORT_FLUSHCACHE)
+ ata_controlcmd(atadev, ATA_FLUSHCACHE, 0, 0, 0);
}
-static void
-ast_describe(struct ast_softc *stp)
+static int
+ast_reinit(device_t dev)
{
- if (bootverbose) {
- ata_prtdev(stp->device, "<%.40s/%.8s> tape drive at ata%d as %s\n",
- stp->device->param->model, stp->device->param->revision,
- device_get_unit(stp->device->channel->dev),
- (stp->device->unit == ATA_MASTER) ? "master" : "slave");
- ata_prtdev(stp->device, "%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->device->mode));
- ata_prtdev(stp->device, "Medium: ");
- switch (stp->cap.medium_type) {
- case 0x00:
- printf("none"); break;
- case 0x17:
- printf("Travan 1 (400 Mbyte)"); break;
- case 0xb6:
- printf("Travan 4 (4 Gbyte)"); break;
- case 0xda:
- printf("OnStream ADR (15Gyte)"); break;
- default:
- printf("unknown (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 {
- ata_prtdev(stp->device, "TAPE <%.40s/%.8s> at ata%d-%s %s\n",
- stp->device->param->model, stp->device->param->revision,
- device_get_unit(stp->device->channel->dev),
- (stp->device->unit == ATA_MASTER) ? "master" : "slave",
- ata_mode2str(stp->device->mode));
+ struct ata_channel *ch = device_get_softc(device_get_parent(dev));
+ struct ata_device *atadev = device_get_softc(dev);
+ struct ast_softc *stp = device_get_ivars(dev);
+
+ if (((atadev->unit == ATA_MASTER) && !(ch->devices & ATA_ATAPI_MASTER)) ||
+ ((atadev->unit == ATA_SLAVE) && !(ch->devices & ATA_ATAPI_SLAVE))) {
+ device_set_ivars(dev, NULL);
+ free(stp, M_AST);
+ return 1;
}
+ ATA_SETMODE(GRANDPARENT(dev), dev);
+ return 0;
}
static int
-ast_open(struct cdev *dev, int flags, int fmt, struct thread *td)
+ast_open(struct cdev *cdev, int flags, int fmt, struct thread *td)
{
- struct ast_softc *stp = dev->si_drv1;
+ device_t dev = cdev->si_drv1;
+ struct ata_device *atadev = device_get_softc(dev);
+ struct ast_softc *stp = device_get_ivars(dev);
- if (!stp || stp->device->flags & ATA_D_DETACHING)
+ if (!stp)
return ENXIO;
-
- if (count_dev(dev) > 1)
+ if (!device_is_attached(dev))
return EBUSY;
- ast_test_ready(stp->device);
-
+ ast_test_ready(dev);
if (stp->cap.lock)
- ast_prevent_allow(stp, 1);
-
- if (ast_sense(stp))
- ata_prtdev(stp->device, "sense media type failed\n");
+ ast_prevent_allow(dev, 1);
+ if (ast_sense(dev))
+ device_printf(dev, "sense media type failed\n");
- stp->device->flags &= ~ATA_D_MEDIA_CHANGED;
+ atadev->flags &= ~ATA_D_MEDIA_CHANGED;
stp->flags &= ~(F_DATA_WRITTEN | F_FM_WRITTEN);
ast_total = 0;
return 0;
}
static int
-ast_close(struct cdev *dev, int flags, int fmt, struct thread *td)
+ast_close(struct cdev *cdev, int flags, int fmt, struct thread *td)
{
- struct ast_softc *stp = dev->si_drv1;
+ device_t dev = cdev->si_drv1;
+ struct ast_softc *stp = device_get_ivars(dev);
/* flush buffers, some drives fail here, they should report ctl = 0 */
if (stp->cap.ctl && (stp->flags & F_DATA_WRITTEN))
- ast_write_filemark(stp, 0);
+ ast_write_filemark(dev, 0);
/* write filemark if data written to tape */
if (!(stp->flags & F_ONSTREAM) &&
(stp->flags & (F_DATA_WRITTEN | F_FM_WRITTEN)) == F_DATA_WRITTEN)
- ast_write_filemark(stp, ATAPI_WF_WRITE);
+ ast_write_filemark(dev, ATAPI_WF_WRITE);
/* if minor is even rewind on close */
- if (!(minor(dev) & 0x01))
- ast_rewind(stp);
+ if (!(minor(cdev) & 0x01))
+ ast_rewind(dev);
- if (stp->cap.lock && count_dev(dev) == 1)
- ast_prevent_allow(stp, 0);
+ if (stp->cap.lock && count_dev(cdev) == 1)
+ ast_prevent_allow(dev, 0);
stp->flags &= ~F_CTL_WARN;
#ifdef AST_DEBUG
- ata_prtdev(stp->device, "%ju total bytes transferred\n",
- (uintmax_t)ast_total);
+ device_printf(dev, "%ju total bytes transferred\n", (uintmax_t)ast_total);
#endif
return 0;
}
static int
-ast_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
+ast_ioctl(struct cdev *cdev, u_long cmd, caddr_t addr, int flag, struct thread *td)
{
- struct ast_softc *stp = dev->si_drv1;
+ device_t dev = cdev->si_drv1;
+ struct ast_softc *stp = device_get_ivars(dev);
int error = 0;
switch (cmd) {
@@ -340,10 +294,10 @@ ast_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *t
g->mt_comp0 = 0; g->mt_comp1 = 0;
g->mt_comp2 = 0; g->mt_comp3 = 0;
}
- break;
+ break;
case MTIOCTOP:
- {
+ {
int i;
struct mtop *mt = (struct mtop *)addr;
@@ -351,44 +305,44 @@ ast_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *t
case MTWEOF:
for (i=0; i < mt->mt_count && !error; i++)
- error = ast_write_filemark(stp, ATAPI_WF_WRITE);
+ error = ast_write_filemark(dev, ATAPI_WF_WRITE);
break;
case MTFSF:
if (mt->mt_count)
- error = ast_space(stp, ATAPI_SP_FM, mt->mt_count);
+ error = ast_space(dev, ATAPI_SP_FM, mt->mt_count);
break;
case MTBSF:
if (mt->mt_count)
- error = ast_space(stp, ATAPI_SP_FM, -(mt->mt_count));
+ error = ast_space(dev, ATAPI_SP_FM, -(mt->mt_count));
break;
case MTREW:
- error = ast_rewind(stp);
+ error = ast_rewind(dev);
break;
case MTOFFL:
- error = ast_load_unload(stp, ATAPI_SS_EJECT);
+ error = ast_load_unload(dev, ATAPI_SS_EJECT);
break;
case MTNOP:
- error = ast_write_filemark(stp, 0);
+ error = ast_write_filemark(dev, 0);
break;
case MTERASE:
- error = ast_erase(stp);
+ error = ast_erase(dev);
break;
case MTEOD:
- error = ast_space(stp, ATAPI_SP_EOD, 0);
+ error = ast_space(dev, ATAPI_SP_EOD, 0);
break;
case MTRETENS:
- error = ast_load_unload(stp, ATAPI_SS_RETENSION|ATAPI_SS_LOAD);
+ error = ast_load_unload(dev, ATAPI_SS_RETENSION|ATAPI_SS_LOAD);
break;
- case MTFSR:
+ case MTFSR:
case MTBSR:
case MTCACHE:
case MTNOCACHE:
@@ -405,7 +359,7 @@ ast_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *t
{
struct ast_readposition position;
- if ((error = ast_read_position(stp, 0, &position)))
+ if ((error = ast_read_position(dev, 0, &position)))
break;
*(u_int32_t *)addr = position.tape;
}
@@ -415,18 +369,18 @@ ast_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *t
{
struct ast_readposition position;
- if ((error = ast_read_position(stp, 1, &position)))
+ if ((error = ast_read_position(dev, 1, &position)))
break;
*(u_int32_t *)addr = position.tape;
}
break;
case MTIOCSLOCATE:
- error = ast_locate(stp, 0, *(u_int32_t *)addr);
+ error = ast_locate(dev, 0, *(u_int32_t *)addr);
break;
case MTIOCHLOCATE:
- error = ast_locate(stp, 1, *(u_int32_t *)addr);
+ error = ast_locate(dev, 1, *(u_int32_t *)addr);
break;
default:
@@ -438,12 +392,12 @@ ast_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *t
static void
ast_strategy(struct bio *bp)
{
- struct ast_softc *stp = bp->bio_dev->si_drv1;
-
- if (stp->device->flags & ATA_D_DETACHING) {
- biofinish(bp, NULL, ENXIO);
- return;
- }
+ device_t dev = bp->bio_dev->si_drv1;
+ struct ata_device *atadev = device_get_softc(dev);
+ struct ast_softc *stp = device_get_ivars(dev);
+ struct ata_request *request;
+ u_int32_t blkcount;
+ int8_t ccb[16];
/* if it's a null transfer, return immediatly. */
if (bp->bio_bcount == 0) {
@@ -458,45 +412,20 @@ ast_strategy(struct bio *bp)
/* check for != blocksize requests */
if (bp->bio_bcount % stp->blksize) {
- ata_prtdev(stp->device, "transfers must be multiple of %d\n",
- stp->blksize);
+ device_printf(dev, "transfers must be multiple of %d\n", stp->blksize);
biofinish(bp, NULL, EIO);
return;
}
/* warn about transfers bigger than the device suggests */
- if (bp->bio_bcount > stp->blksize * stp->cap.ctl) {
+ if (bp->bio_bcount > stp->blksize * stp->cap.ctl) {
if ((stp->flags & F_CTL_WARN) == 0) {
- ata_prtdev(stp->device, "WARNING: CTL exceeded %ld>%d\n",
- bp->bio_bcount, stp->blksize * stp->cap.ctl);
+ device_printf(dev, "WARNING: CTL exceeded %ld>%d\n",
+ bp->bio_bcount, stp->blksize * stp->cap.ctl);
stp->flags |= F_CTL_WARN;
}
}
- mtx_lock(&stp->queue_mtx);
- bioq_insert_tail(&stp->queue, bp);
- mtx_unlock(&stp->queue_mtx);
- ata_start(stp->device->channel);
-}
-
-static void
-ast_start(struct ata_device *atadev)
-{
- struct ast_softc *stp = atadev->softc;
- struct bio *bp;
- struct ata_request *request;
- u_int32_t blkcount;
- int8_t ccb[16];
-
- mtx_lock(&stp->queue_mtx);
- bp = bioq_first(&stp->queue);
- if (!bp) {
- mtx_unlock(&stp->queue_mtx);
- return;
- }
- bioq_remove(&stp->queue, bp);
- mtx_unlock(&stp->queue_mtx);
-
bzero(ccb, sizeof(ccb));
if (bp->bio_cmd == BIO_READ)
@@ -507,18 +436,18 @@ ast_start(struct ata_device *atadev)
blkcount = bp->bio_bcount / stp->blksize;
ccb[1] = 1;
- ccb[2] = blkcount>>16;
- ccb[3] = blkcount>>8;
+ ccb[2] = blkcount >> 16;
+ ccb[3] = blkcount >> 8;
ccb[4] = blkcount;
if (!(request = ata_alloc_request())) {
biofinish(bp, NULL, ENOMEM);
return;
}
- request->device = atadev;
+ request->dev = dev;
request->driver = bp;
bcopy(ccb, request->u.atapi.ccb,
- (request->device->param->config & ATA_PROTO_MASK) ==
+ (atadev->param.config & ATA_PROTO_MASK) ==
ATA_PROTO_ATAPI_12 ? 16 : 12);
request->data = bp->bio_data;
request->bytecount = blkcount * stp->blksize;
@@ -534,7 +463,7 @@ ast_start(struct ata_device *atadev)
request->flags |= (ATA_R_ATAPI | ATA_R_WRITE);
break;
default:
- ata_prtdev(atadev, "unknown BIO operation\n");
+ device_printf(dev, "unknown BIO operation\n");
ata_free_request(request);
biofinish(bp, NULL, EIO);
return;
@@ -546,8 +475,8 @@ ast_start(struct ata_device *atadev)
static void
ast_done(struct ata_request *request)
{
+ struct ast_softc *stp = device_get_ivars(request->dev);
struct bio *bp = request->driver;
- struct ast_softc *stp = request->device->softc;
/* finish up transfer */
if ((bp->bio_error = request->result))
@@ -561,41 +490,68 @@ ast_done(struct ata_request *request)
}
static int
-ast_mode_sense(struct ast_softc *stp, int page, void *pagebuf, int pagesize)
+ast_sense(device_t dev)
{
+ struct ast_softc *stp = device_get_ivars(dev);
+ int count;
+
+ /* get drive capabilities, some bugridden drives needs this repeated */
+ for (count = 0 ; count < 5 ; count++) {
+ if (!ast_mode_sense(dev, ATAPI_TAPE_CAP_PAGE,
+ &stp->cap, sizeof(stp->cap)) &&
+ stp->cap.page_code == ATAPI_TAPE_CAP_PAGE) {
+ 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;
+ }
+ }
+ return 1;
+}
+
+static int
+ast_mode_sense(device_t dev, int page, void *pagebuf, int pagesize)
+{
+ struct ata_device *atadev = device_get_softc(dev);
int8_t ccb[16] = { ATAPI_MODE_SENSE, 0x08, page, pagesize>>8, pagesize,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int error;
- error = ata_atapicmd(stp->device, ccb, pagebuf, pagesize, ATA_R_READ, 10);
-#ifdef AST_DEBUG
- atapi_dump("ast: mode sense ", pagebuf, pagesize);
-#endif
+ error = ata_atapicmd(atadev, ccb, pagebuf, pagesize, ATA_R_READ, 10);
return error;
}
-static int
-ast_mode_select(struct ast_softc *stp, void *pagebuf, int pagesize)
+static int
+ast_mode_select(device_t dev, void *pagebuf, int pagesize)
{
+ struct ata_device *atadev = device_get_softc(dev);
int8_t ccb[16] = { ATAPI_MODE_SELECT, 0x10, 0, pagesize>>8, pagesize,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-#ifdef AST_DEBUG
- ata_prtdev(stp->device, "modeselect pagesize=%d\n", pagesize);
- atapi_dump("mode select ", pagebuf, pagesize);
-#endif
- return ata_atapicmd(stp->device, ccb, pagebuf, pagesize, 0, 10);
+ return ata_atapicmd(atadev, ccb, pagebuf, pagesize, 0, 10);
}
static int
-ast_write_filemark(struct ast_softc *stp, u_int8_t function)
+ast_write_filemark(device_t dev, u_int8_t function)
{
+ struct ata_device *atadev = device_get_softc(dev);
+ struct ast_softc *stp = device_get_ivars(dev);
int8_t ccb[16] = { ATAPI_WEOF, 0x01, 0, 0, function, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 };
int error;
if (stp->flags & F_ONSTREAM)
- ccb[4] = 0x00; /* only flush buffers supported */
+ ccb[4] = 0x00; /* only flush buffers supported */
else {
if (function) {
if (stp->flags & F_FM_WRITTEN)
@@ -604,21 +560,21 @@ ast_write_filemark(struct ast_softc *stp, u_int8_t function)
stp->flags |= F_FM_WRITTEN;
}
}
- error = ata_atapicmd(stp->device, ccb, NULL, 0, 0, 10);
+ error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 10);
if (error)
return error;
- return ast_wait_dsc(stp->device, 10*60);
+ return ast_wait_dsc(dev, 10*60);
}
static int
-ast_read_position(struct ast_softc *stp, int hard,
- struct ast_readposition *position)
+ast_read_position(device_t dev, int hard, struct ast_readposition *position)
{
+ struct ata_device *atadev = device_get_softc(dev);
int8_t ccb[16] = { ATAPI_READ_POSITION, (hard ? 0x01 : 0), 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 };
int error;
- error = ata_atapicmd(stp->device, ccb, (caddr_t)position,
+ error = ata_atapicmd(atadev, ccb, (caddr_t)position,
sizeof(struct ast_readposition), ATA_R_READ, 10);
position->tape = ntohl(position->tape);
position->host = ntohl(position->host);
@@ -626,84 +582,93 @@ ast_read_position(struct ast_softc *stp, int hard,
}
static int
-ast_space(struct ast_softc *stp, u_int8_t function, int32_t count)
+ast_space(device_t dev, u_int8_t function, int32_t count)
{
+ struct ata_device *atadev = device_get_softc(dev);
int8_t ccb[16] = { ATAPI_SPACE, function, count>>16, count>>8, count,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- return ata_atapicmd(stp->device, ccb, NULL, 0, 0, 60*60);
+ return ata_atapicmd(atadev, ccb, NULL, 0, 0, 60*60);
}
static int
-ast_locate(struct ast_softc *stp, int hard, u_int32_t pos)
+ast_locate(device_t dev, int hard, u_int32_t pos)
{
+ struct ata_device *atadev = device_get_softc(dev);
int8_t ccb[16] = { ATAPI_LOCATE, 0x01 | (hard ? 0x4 : 0), 0,
pos>>24, pos>>16, pos>>8, pos,
0, 0, 0, 0, 0, 0, 0, 0, 0 };
int error;
- error = ata_atapicmd(stp->device, ccb, NULL, 0, 0, 10);
+ error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 10);
if (error)
return error;
- return ast_wait_dsc(stp->device, 60*60);
+ return ast_wait_dsc(dev, 60*60);
}
static int
-ast_prevent_allow(struct ast_softc *stp, int lock)
+ast_prevent_allow(device_t dev, int lock)
{
+ struct ata_device *atadev = device_get_softc(dev);
int8_t ccb[16] = { ATAPI_PREVENT_ALLOW, 0, 0, 0, lock,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- return ata_atapicmd(stp->device, ccb, NULL, 0, 0, 30);
+ return ata_atapicmd(atadev, ccb, NULL, 0, 0, 30);
}
static int
-ast_load_unload(struct ast_softc *stp, u_int8_t function)
+ast_load_unload(device_t dev, u_int8_t function)
{
+ struct ata_device *atadev = device_get_softc(dev);
+ struct ast_softc *stp = device_get_ivars(dev);
int8_t ccb[16] = { ATAPI_START_STOP, 0x01, 0, 0, function, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 };
int error;
if ((function & ATAPI_SS_EJECT) && !stp->cap.eject)
return 0;
- error = ata_atapicmd(stp->device, ccb, NULL, 0, 0, 10);
+ error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 10);
if (error)
return error;
tsleep((caddr_t)&error, PRIBIO, "astlu", 1 * hz);
if (function == ATAPI_SS_EJECT)
return 0;
- return ast_wait_dsc(stp->device, 60*60);
+ return ast_wait_dsc(dev, 60*60);
}
static int
-ast_rewind(struct ast_softc *stp)
+ast_rewind(device_t dev)
{
+ struct ata_device *atadev = device_get_softc(dev);
int8_t ccb[16] = { ATAPI_REZERO, 0x01, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 };
int error;
- error = ata_atapicmd(stp->device, ccb, NULL, 0, 0, 10);
+ error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 10);
if (error)
return error;
- return ast_wait_dsc(stp->device, 60*60);
+ return ast_wait_dsc(dev, 60*60);
}
static int
-ast_erase(struct ast_softc *stp)
+ast_erase(device_t dev)
{
+ struct ata_device *atadev = device_get_softc(dev);
int8_t ccb[16] = { ATAPI_ERASE, 3, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 };
int error;
- if ((error = ast_rewind(stp)))
+ if ((error = ast_rewind(dev)))
return error;
- return ata_atapicmd(stp->device, ccb, NULL, 0, 0, 60*60);
+ return ata_atapicmd(atadev, ccb, NULL, 0, 0, 60*60);
}
static int
-ast_test_ready(struct ata_device *atadev)
+ast_test_ready(device_t dev)
{
+ struct ata_device *atadev = device_get_softc(dev);
+
int8_t ccb[16] = { ATAPI_TEST_UNIT_READY, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -711,8 +676,10 @@ ast_test_ready(struct ata_device *atadev)
}
static int
-ast_wait_dsc(struct ata_device *atadev, int timeout)
+ast_wait_dsc(device_t dev, int timeout)
{
+ struct ata_device *atadev = device_get_softc(dev);
+
int error = 0;
int8_t ccb[16] = { ATAPI_POLL_DSC, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -727,3 +694,100 @@ ast_wait_dsc(struct ata_device *atadev, int timeout)
}
return error;
}
+
+static void
+ast_describe(device_t dev)
+{
+ struct ata_channel *ch = device_get_softc(device_get_parent(dev));
+ struct ata_device *atadev = device_get_softc(dev);
+ struct ast_softc *stp = device_get_ivars(dev);
+
+ if (bootverbose) {
+ device_printf(dev, "<%.40s/%.8s> tape drive at ata%d as %s\n",
+ atadev->param.model, atadev->param.revision,
+ device_get_unit(ch->dev),
+ (atadev->unit == ATA_MASTER) ? "master" : "slave");
+ device_printf(dev, "%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(atadev->mode));
+ device_printf(dev, "Medium: ");
+ switch (stp->cap.medium_type) {
+ case 0x00:
+ printf("none"); break;
+ case 0x17:
+ printf("Travan 1 (400 Mbyte)"); break;
+ case 0xb6:
+ printf("Travan 4 (4 Gbyte)"); break;
+ case 0xda:
+ printf("OnStream ADR (15Gyte)"); break;
+ default:
+ printf("unknown (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 {
+ device_printf(dev, "TAPE <%.40s/%.8s> at ata%d-%s %s\n",
+ atadev->param.model, atadev->param.revision,
+ device_get_unit(ch->dev),
+ (atadev->unit == ATA_MASTER) ? "master" : "slave",
+ ata_mode2str(atadev->mode));
+ }
+}
+
+static device_method_t ast_methods[] = {
+ /* device interface */
+ DEVMETHOD(device_identify, ast_identify),
+ DEVMETHOD(device_probe, ast_probe),
+ DEVMETHOD(device_attach, ast_attach),
+ DEVMETHOD(device_detach, ast_detach),
+ DEVMETHOD(device_shutdown, ast_shutdown),
+
+ /* ATA methods */
+ DEVMETHOD(ata_reinit, ast_reinit),
+
+ { 0, 0 }
+};
+
+static driver_t ast_driver = {
+ "ast",
+ ast_methods,
+ sizeof(struct ast_softc)
+};
+
+static devclass_t ast_devclass;
+
+static int
+ast_modevent(module_t mod, int what, void *arg)
+{
+ device_t *devs;
+ int ndevs, i;
+
+ if (what == MOD_UNLOAD) {
+ if (!devclass_get_devices(ast_devclass, &devs, &ndevs) && devs) {
+ for (i = 0; i < ndevs; i++)
+ device_delete_child(device_get_parent(devs[i]), devs[i]);
+ free(devs, M_TEMP);
+ }
+ }
+ return 0;
+}
+
+DRIVER_MODULE(ast, ata, ast_driver, ast_devclass, ast_modevent, NULL);
+MODULE_VERSION(ast, 1);
+MODULE_DEPEND(ast, ata, 1, 1, 1);