43fc81a434cfd28f7fa14d2eba95ceac73f1ca3f
[dragonfly.git] / sys / dev / disk / nata / atapi-tape.c
blob43fc81a434cfd28f7fa14d2eba95ceac73f1ca3f
1 /*-
2 * Copyright (c) 1998 - 2006 Søren Schmidt <sos@FreeBSD.org>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sys/dev/ata/atapi-tape.c,v 1.101 2006/01/05 21:27:19 sos Exp $
27 * $DragonFly: src/sys/dev/disk/nata/atapi-tape.c,v 1.3 2007/06/03 04:48:29 dillon Exp $
30 #include "opt_ata.h"
32 #include <sys/param.h>
33 #include <sys/bio.h>
34 #include <sys/buf.h>
35 #include <sys/bus.h>
36 #include <sys/conf.h>
37 #include <sys/device.h>
38 #include <sys/devicestat.h>
39 #include <sys/disk.h>
40 #include <sys/kernel.h>
41 #include <sys/libkern.h>
42 #include <sys/malloc.h>
43 #include <sys/module.h>
44 #include <sys/mtio.h>
45 #include <sys/nata.h>
46 #include <sys/systm.h>
48 #include "ata-all.h"
49 #include "atapi-tape.h"
50 #include "ata_if.h"
52 /* device structure */
53 static d_open_t ast_open;
54 static d_close_t ast_close;
55 static d_ioctl_t ast_ioctl;
56 static d_strategy_t ast_strategy;
57 static struct dev_ops ast_ops = {
58 { "ast", 119, D_TAPE | D_TRACKCLOSE },
59 .d_open = ast_open,
60 .d_close = ast_close,
61 .d_read = physread,
62 .d_write = physwrite,
63 .d_ioctl = ast_ioctl,
64 .d_strategy = ast_strategy
67 /* prototypes */
68 static int ast_sense(device_t);
69 static void ast_describe(device_t);
70 static void ast_done(struct ata_request *);
71 static int ast_mode_sense(device_t, int, void *, int);
72 static int ast_mode_select(device_t, void *, int);
73 static int ast_write_filemark(device_t, u_int8_t);
74 static int ast_read_position(device_t, int, struct ast_readposition *);
75 static int ast_space(device_t, u_int8_t, int32_t);
76 static int ast_locate(device_t, int, u_int32_t);
77 static int ast_prevent_allow(device_t, int);
78 static int ast_load_unload(device_t, u_int8_t);
79 static int ast_rewind(device_t);
80 static int ast_erase(device_t);
81 static int ast_test_ready(device_t);
82 static int ast_wait_dsc(device_t, int);
84 /* internal vars */
85 static u_int64_t ast_total = 0;
86 static MALLOC_DEFINE(M_AST, "ast_driver", "ATAPI tape driver buffers");
88 static int
89 ast_probe(device_t dev)
91 struct ata_device *atadev = device_get_softc(dev);
93 if ((atadev->param.config & ATA_PROTO_ATAPI) &&
94 (atadev->param.config & ATA_ATAPI_TYPE_MASK) == ATA_ATAPI_TYPE_TAPE)
95 return 0;
96 else
97 return ENXIO;
100 static int
101 ast_attach(device_t dev)
103 struct ata_channel *ch = device_get_softc(device_get_parent(dev));
104 struct ata_device *atadev = device_get_softc(dev);
105 struct ast_softc *stp;
106 struct ast_readposition position;
107 cdev_t cdev;
109 stp = kmalloc(sizeof(struct ast_softc), M_AST, M_WAITOK | M_ZERO);
110 device_set_ivars(dev, stp);
111 ATA_SETMODE(device_get_parent(dev), dev);
113 if (ast_sense(dev)) {
114 device_set_ivars(dev, NULL);
115 kfree(stp, M_AST);
116 return ENXIO;
118 if (!strcmp(atadev->param.model, "OnStream DI-30")) {
119 struct ast_transferpage transfer;
120 struct ast_identifypage identify;
122 stp->flags |= F_ONSTREAM;
123 bzero(&transfer, sizeof(struct ast_transferpage));
124 ast_mode_sense(dev, ATAPI_TAPE_TRANSFER_PAGE,
125 &transfer, sizeof(transfer));
126 bzero(&identify, sizeof(struct ast_identifypage));
127 ast_mode_sense(dev, ATAPI_TAPE_IDENTIFY_PAGE,
128 &identify, sizeof(identify));
129 strncpy(identify.ident, "FBSD", 4);
130 ast_mode_select(dev, &identify, sizeof(identify));
131 ast_read_position(dev, 0, &position);
134 devstat_add_entry(&stp->stats, "ast", device_get_unit(dev), DEV_BSIZE,
135 DEVSTAT_NO_ORDERED_TAGS,
136 DEVSTAT_TYPE_SEQUENTIAL | DEVSTAT_TYPE_IF_IDE,
137 DEVSTAT_PRIORITY_TAPE);
138 dev_ops_add(&ast_ops, dkunitmask(), dkmakeunit(device_get_unit(dev)));
139 cdev = make_dev(&ast_ops, 2 * device_get_unit(dev), UID_ROOT, GID_OPERATOR,
140 0640, "ast%d", device_get_unit(dev));
141 reference_dev(cdev);
142 cdev->si_drv1 = dev;
143 if (ch->dma)
144 cdev->si_iosize_max = ch->dma->max_iosize;
145 else
146 cdev->si_iosize_max = DFLTPHYS;
147 stp->cdev1 = cdev;
148 cdev = make_dev(&ast_ops, 2 * device_get_unit(dev) + 1, UID_ROOT,
149 GID_OPERATOR, 0640, "nast%d", device_get_unit(dev));
150 reference_dev(cdev);
151 cdev->si_drv1 = dev;
152 if (ch->dma)
153 cdev->si_iosize_max = ch->dma->max_iosize;
154 else
155 cdev->si_iosize_max = DFLTPHYS;
156 stp->cdev2 = cdev;
158 /* announce we are here and ready */
159 ast_describe(dev);
160 return 0;
163 static int
164 ast_detach(device_t dev)
166 struct ast_softc *stp = device_get_ivars(dev);
168 /* detroy devices from the system so we dont get any further requests */
169 destroy_dev(stp->cdev1);
170 destroy_dev(stp->cdev2);
172 /* fail requests on the queue and any thats "in flight" for this device */
173 ata_fail_requests(dev);
175 /* dont leave anything behind */
176 dev_ops_remove(&ast_ops, dkunitmask(), dkmakeunit(device_get_unit(dev)));
177 devstat_remove_entry(&stp->stats);
178 device_set_ivars(dev, NULL);
179 kfree(stp, M_AST);
180 return 0;
183 static void
184 ast_shutdown(device_t dev)
186 struct ata_device *atadev = device_get_softc(dev);
188 if (atadev->param.support.command2 & ATA_SUPPORT_FLUSHCACHE)
189 ata_controlcmd(dev, ATA_FLUSHCACHE, 0, 0, 0);
192 static int
193 ast_reinit(device_t dev)
195 struct ata_channel *ch = device_get_softc(device_get_parent(dev));
196 struct ata_device *atadev = device_get_softc(dev);
197 struct ast_softc *stp = device_get_ivars(dev);
199 if (((atadev->unit == ATA_MASTER) && !(ch->devices & ATA_ATAPI_MASTER)) ||
200 ((atadev->unit == ATA_SLAVE) && !(ch->devices & ATA_ATAPI_SLAVE))) {
201 device_set_ivars(dev, NULL);
202 kfree(stp, M_AST);
203 return 1;
205 ATA_SETMODE(device_get_parent(dev), dev);
206 return 0;
209 static int
210 ast_open(struct dev_open_args *ap)
212 device_t dev = ap->a_head.a_dev->si_drv1;
213 struct ata_device *atadev = device_get_softc(dev);
214 struct ast_softc *stp = device_get_ivars(dev);
216 if (!stp)
217 return ENXIO;
218 if (!device_is_attached(dev))
219 return EBUSY;
221 ast_test_ready(dev);
222 if (stp->cap.lock)
223 ast_prevent_allow(dev, 1);
224 if (ast_sense(dev))
225 device_printf(dev, "sense media type failed\n");
227 atadev->flags &= ~ATA_D_MEDIA_CHANGED;
228 stp->flags &= ~(F_DATA_WRITTEN | F_FM_WRITTEN);
229 ast_total = 0;
230 return 0;
233 static int
234 ast_close(struct dev_close_args *ap)
236 device_t dev = ap->a_head.a_dev->si_drv1;
237 struct ast_softc *stp = device_get_ivars(dev);
238 cdev_t cdev = ap->a_head.a_dev;
240 /* flush buffers, some drives fail here, they should report ctl = 0 */
241 if (stp->cap.ctl && (stp->flags & F_DATA_WRITTEN))
242 ast_write_filemark(dev, 0);
244 /* write filemark if data written to tape */
245 if (!(stp->flags & F_ONSTREAM) &&
246 (stp->flags & (F_DATA_WRITTEN | F_FM_WRITTEN)) == F_DATA_WRITTEN)
247 ast_write_filemark(dev, ATAPI_WF_WRITE);
249 /* if minor is even rewind on close */
250 if (!(minor(cdev) & 0x01))
251 ast_rewind(dev);
253 if (stp->cap.lock && count_dev(cdev) == 1)
254 ast_prevent_allow(dev, 0);
256 stp->flags &= ~F_CTL_WARN;
257 #ifdef AST_DEBUG
258 device_printf(dev, "%llu total bytes transferred\n",
259 (unsigned long long)ast_total);
260 #endif
261 return 0;
264 static int
265 ast_ioctl(struct dev_ioctl_args *ap)
267 device_t dev = ap->a_head.a_dev->si_drv1;
268 struct ast_softc *stp = device_get_ivars(dev);
269 int error = 0;
271 switch (ap->a_cmd) {
272 case MTIOCGET:
274 struct mtget *g = (struct mtget *)ap->a_data;
276 bzero(g, sizeof(struct mtget));
277 g->mt_type = 7;
278 g->mt_density = 1;
279 g->mt_blksiz = stp->blksize;
280 g->mt_comp = stp->cap.compress;
281 g->mt_density0 = 0; g->mt_density1 = 0;
282 g->mt_density2 = 0; g->mt_density3 = 0;
283 g->mt_blksiz0 = 0; g->mt_blksiz1 = 0;
284 g->mt_blksiz2 = 0; g->mt_blksiz3 = 0;
285 g->mt_comp0 = 0; g->mt_comp1 = 0;
286 g->mt_comp2 = 0; g->mt_comp3 = 0;
288 break;
290 case MTIOCTOP:
292 int i;
293 struct mtop *mt = (struct mtop *)ap->a_data;
295 switch ((int16_t) (mt->mt_op)) {
297 case MTWEOF:
298 for (i=0; i < mt->mt_count && !error; i++)
299 error = ast_write_filemark(dev, ATAPI_WF_WRITE);
300 break;
302 case MTFSF:
303 if (mt->mt_count)
304 error = ast_space(dev, ATAPI_SP_FM, mt->mt_count);
305 break;
307 case MTBSF:
308 if (mt->mt_count)
309 error = ast_space(dev, ATAPI_SP_FM, -(mt->mt_count));
310 break;
312 case MTREW:
313 error = ast_rewind(dev);
314 break;
316 case MTOFFL:
317 error = ast_load_unload(dev, ATAPI_SS_EJECT);
318 break;
320 case MTNOP:
321 error = ast_write_filemark(dev, 0);
322 break;
324 case MTERASE:
325 error = ast_erase(dev);
326 break;
328 case MTEOD:
329 error = ast_space(dev, ATAPI_SP_EOD, 0);
330 break;
332 case MTRETENS:
333 error = ast_load_unload(dev, ATAPI_SS_RETENSION|ATAPI_SS_LOAD);
334 break;
336 case MTFSR:
337 case MTBSR:
338 case MTCACHE:
339 case MTNOCACHE:
340 case MTSETBSIZ:
341 case MTSETDNSTY:
342 case MTCOMP:
343 default:
344 error = EINVAL;
347 break;
349 case MTIOCRDSPOS:
351 struct ast_readposition position;
353 if ((error = ast_read_position(dev, 0, &position)))
354 break;
355 *(u_int32_t *)ap->a_data = position.tape;
357 break;
359 case MTIOCRDHPOS:
361 struct ast_readposition position;
363 if ((error = ast_read_position(dev, 1, &position)))
364 break;
365 *(u_int32_t *)ap->a_data = position.tape;
367 break;
369 case MTIOCSLOCATE:
370 error = ast_locate(dev, 0, *(u_int32_t *)ap->a_data);
371 break;
373 case MTIOCHLOCATE:
374 error = ast_locate(dev, 1, *(u_int32_t *)ap->a_data);
375 break;
377 default:
378 error = ata_device_ioctl(dev, ap->a_cmd, ap->a_data);
380 return error;
383 static int
384 ast_strategy(struct dev_strategy_args *ap)
386 device_t dev = ap->a_head.a_dev->si_drv1;
387 struct bio *bp = ap->a_bio;
388 struct buf *bbp = bp->bio_buf;
389 struct ata_device *atadev = device_get_softc(dev);
390 struct ast_softc *stp = device_get_ivars(dev);
391 struct ata_request *request;
392 u_int32_t blkcount;
393 int8_t ccb[16];
395 /* if it's a null transfer, return immediatly. */
396 if (bbp->b_bcount == 0) {
397 bbp->b_resid = 0;
398 biodone(bp);
399 return 0;
401 if (!(bbp->b_cmd == BUF_CMD_READ) && stp->flags & F_WRITEPROTECT) {
402 bbp->b_flags |= B_ERROR;
403 bbp->b_error = EPERM;
404 biodone(bp);
405 return 0;
408 /* check for != blocksize requests */
409 if (bbp->b_bcount % stp->blksize) {
410 device_printf(dev, "transfers must be multiple of %d\n", stp->blksize);
411 bbp->b_flags |= B_ERROR;
412 bbp->b_error = EIO;
413 biodone(bp);
414 return 0;
417 /* warn about transfers bigger than the device suggests */
418 if (bbp->b_bcount > stp->blksize * stp->cap.ctl) {
419 if ((stp->flags & F_CTL_WARN) == 0) {
420 device_printf(dev, "WARNING: CTL exceeded %d>%d\n",
421 bbp->b_bcount, stp->blksize * stp->cap.ctl);
422 stp->flags |= F_CTL_WARN;
426 bzero(ccb, sizeof(ccb));
428 if (bbp->b_cmd == BUF_CMD_READ)
429 ccb[0] = ATAPI_READ;
430 else
431 ccb[0] = ATAPI_WRITE;
433 blkcount = bbp->b_bcount / stp->blksize;
435 ccb[1] = 1;
436 ccb[2] = blkcount >> 16;
437 ccb[3] = blkcount >> 8;
438 ccb[4] = blkcount;
440 if (!(request = ata_alloc_request())) {
441 bbp->b_flags |= B_ERROR;
442 bbp->b_error = ENOMEM;
443 biodone(bp);
444 return 0;
446 request->dev = dev;
447 request->bio = bp;
448 bcopy(ccb, request->u.atapi.ccb,
449 (atadev->param.config & ATA_PROTO_MASK) ==
450 ATA_PROTO_ATAPI_12 ? 16 : 12);
451 request->data = bbp->b_data;
452 request->bytecount = blkcount * stp->blksize;
453 request->transfersize = min(request->bytecount, 65534);
454 request->timeout = (ccb[0] == ATAPI_WRITE_BIG) ? 180 : 120;
455 request->retries = 2;
456 request->callback = ast_done;
457 switch (bbp->b_cmd) {
458 case BUF_CMD_READ:
459 request->flags |= (ATA_R_ATAPI | ATA_R_READ);
460 break;
461 case BUF_CMD_WRITE:
462 request->flags |= (ATA_R_ATAPI | ATA_R_WRITE);
463 break;
464 default:
465 device_printf(dev, "unknown BUF operation\n");
466 ata_free_request(request);
467 bbp->b_flags |= B_ERROR;
468 bbp->b_error = EIO;
469 biodone(bp);
470 return 0;
472 devstat_start_transaction(&stp->stats);
473 ata_queue_request(request);
474 return 0;
477 static void
478 ast_done(struct ata_request *request)
480 struct ast_softc *stp = device_get_ivars(request->dev);
481 struct bio *bp = request->bio;
482 struct buf *bbp = bp->bio_buf;
484 /* finish up transfer */
485 if ((bbp->b_error = request->result))
486 bbp->b_flags |= B_ERROR;
487 if (bbp->b_cmd == BUF_CMD_WRITE)
488 stp->flags |= F_DATA_WRITTEN;
489 bbp->b_resid = bbp->b_bcount - request->donecount;
490 ast_total += (bbp->b_bcount - bbp->b_resid);
491 devstat_end_transaction_buf(&stp->stats, bbp);
492 biodone(bp);
493 ata_free_request(request);
496 static int
497 ast_sense(device_t dev)
499 struct ast_softc *stp = device_get_ivars(dev);
500 int count;
502 /* get drive capabilities, some bugridden drives needs this repeated */
503 for (count = 0 ; count < 5 ; count++) {
504 if (!ast_mode_sense(dev, ATAPI_TAPE_CAP_PAGE,
505 &stp->cap, sizeof(stp->cap)) &&
506 stp->cap.page_code == ATAPI_TAPE_CAP_PAGE) {
507 if (stp->cap.blk32k)
508 stp->blksize = 32768;
509 if (stp->cap.blk1024)
510 stp->blksize = 1024;
511 if (stp->cap.blk512)
512 stp->blksize = 512;
513 if (!stp->blksize)
514 continue;
515 stp->cap.max_speed = ntohs(stp->cap.max_speed);
516 stp->cap.max_defects = ntohs(stp->cap.max_defects);
517 stp->cap.ctl = ntohs(stp->cap.ctl);
518 stp->cap.speed = ntohs(stp->cap.speed);
519 stp->cap.buffer_size = ntohs(stp->cap.buffer_size);
520 return 0;
523 return 1;
526 static int
527 ast_mode_sense(device_t dev, int page, void *pagebuf, int pagesize)
529 int8_t ccb[16] = { ATAPI_MODE_SENSE, 0x08, page, pagesize>>8, pagesize,
530 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
531 int error;
533 error = ata_atapicmd(dev, ccb, pagebuf, pagesize, ATA_R_READ, 10);
534 return error;
537 static int
538 ast_mode_select(device_t dev, void *pagebuf, int pagesize)
540 int8_t ccb[16] = { ATAPI_MODE_SELECT, 0x10, 0, pagesize>>8, pagesize,
541 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
543 return ata_atapicmd(dev, ccb, pagebuf, pagesize, 0, 10);
546 static int
547 ast_write_filemark(device_t dev, u_int8_t function)
549 struct ast_softc *stp = device_get_ivars(dev);
550 int8_t ccb[16] = { ATAPI_WEOF, 0x01, 0, 0, function, 0, 0, 0,
551 0, 0, 0, 0, 0, 0, 0, 0 };
552 int error;
554 if (stp->flags & F_ONSTREAM)
555 ccb[4] = 0x00; /* only flush buffers supported */
556 else {
557 if (function) {
558 if (stp->flags & F_FM_WRITTEN)
559 stp->flags &= ~F_DATA_WRITTEN;
560 else
561 stp->flags |= F_FM_WRITTEN;
564 error = ata_atapicmd(dev, ccb, NULL, 0, 0, 10);
565 if (error)
566 return error;
567 return ast_wait_dsc(dev, 10*60);
570 static int
571 ast_read_position(device_t dev, int hard, struct ast_readposition *position)
573 int8_t ccb[16] = { ATAPI_READ_POSITION, (hard ? 0x01 : 0), 0, 0, 0, 0, 0, 0,
574 0, 0, 0, 0, 0, 0, 0, 0 };
575 int error;
577 error = ata_atapicmd(dev, ccb, (caddr_t)position,
578 sizeof(struct ast_readposition), ATA_R_READ, 10);
579 position->tape = ntohl(position->tape);
580 position->host = ntohl(position->host);
581 return error;
584 static int
585 ast_space(device_t dev, u_int8_t function, int32_t count)
587 int8_t ccb[16] = { ATAPI_SPACE, function, count>>16, count>>8, count,
588 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
590 return ata_atapicmd(dev, ccb, NULL, 0, 0, 60*60);
593 static int
594 ast_locate(device_t dev, int hard, u_int32_t pos)
596 int8_t ccb[16] = { ATAPI_LOCATE, 0x01 | (hard ? 0x4 : 0), 0,
597 pos>>24, pos>>16, pos>>8, pos,
598 0, 0, 0, 0, 0, 0, 0, 0, 0 };
599 int error;
601 error = ata_atapicmd(dev, ccb, NULL, 0, 0, 10);
602 if (error)
603 return error;
604 return ast_wait_dsc(dev, 60*60);
607 static int
608 ast_prevent_allow(device_t dev, int lock)
610 int8_t ccb[16] = { ATAPI_PREVENT_ALLOW, 0, 0, 0, lock,
611 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
613 return ata_atapicmd(dev, ccb, NULL, 0, 0, 30);
616 static int
617 ast_load_unload(device_t dev, u_int8_t function)
619 struct ast_softc *stp = device_get_ivars(dev);
620 int8_t ccb[16] = { ATAPI_START_STOP, 0x01, 0, 0, function, 0, 0, 0,
621 0, 0, 0, 0, 0, 0, 0, 0 };
622 int error;
624 if ((function & ATAPI_SS_EJECT) && !stp->cap.eject)
625 return 0;
626 error = ata_atapicmd(dev, ccb, NULL, 0, 0, 10);
627 if (error)
628 return error;
629 tsleep((caddr_t)&error, 0, "astlu", 1 * hz);
630 if (function == ATAPI_SS_EJECT)
631 return 0;
632 return ast_wait_dsc(dev, 60*60);
635 static int
636 ast_rewind(device_t dev)
638 int8_t ccb[16] = { ATAPI_REZERO, 0x01, 0, 0, 0, 0, 0, 0,
639 0, 0, 0, 0, 0, 0, 0, 0 };
640 int error;
642 error = ata_atapicmd(dev, ccb, NULL, 0, 0, 10);
643 if (error)
644 return error;
645 return ast_wait_dsc(dev, 60*60);
648 static int
649 ast_erase(device_t dev)
651 int8_t ccb[16] = { ATAPI_ERASE, 3, 0, 0, 0, 0, 0, 0,
652 0, 0, 0, 0, 0, 0, 0, 0 };
653 int error;
655 if ((error = ast_rewind(dev)))
656 return error;
658 return ata_atapicmd(dev, ccb, NULL, 0, 0, 60*60);
661 static int
662 ast_test_ready(device_t dev)
664 int8_t ccb[16] = { ATAPI_TEST_UNIT_READY, 0, 0, 0, 0,
665 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
667 return ata_atapicmd(dev, ccb, NULL, 0, 0, 30);
670 static int
671 ast_wait_dsc(device_t dev, int timeout)
673 int error = 0;
674 int8_t ccb[16] = { ATAPI_POLL_DSC, 0, 0, 0, 0,
675 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
677 timeout *= hz;
678 while (timeout > 0) {
679 error = ata_atapicmd(dev, ccb, NULL, 0, 0, 0);
680 if (error != EBUSY)
681 break;
682 tsleep(&error, 0, "atpwt", hz / 2);
683 timeout -= (hz / 2);
685 return error;
688 static void
689 ast_describe(device_t dev)
691 struct ata_channel *ch = device_get_softc(device_get_parent(dev));
692 struct ata_device *atadev = device_get_softc(dev);
693 struct ast_softc *stp = device_get_ivars(dev);
695 if (bootverbose) {
696 device_printf(dev, "<%.40s/%.8s> tape drive at ata%d as %s\n",
697 atadev->param.model, atadev->param.revision,
698 device_get_unit(ch->dev),
699 (atadev->unit == ATA_MASTER) ? "master" : "slave");
700 device_printf(dev, "%dKB/s, ", stp->cap.max_speed);
701 kprintf("transfer limit %d blk%s, ",
702 stp->cap.ctl, (stp->cap.ctl > 1) ? "s" : "");
703 kprintf("%dKB buffer, ", (stp->cap.buffer_size * DEV_BSIZE) / 1024);
704 kprintf("%s\n", ata_mode2str(atadev->mode));
705 device_printf(dev, "Medium: ");
706 switch (stp->cap.medium_type) {
707 case 0x00:
708 kprintf("none"); break;
709 case 0x17:
710 kprintf("Travan 1 (400 Mbyte)"); break;
711 case 0xb6:
712 kprintf("Travan 4 (4 Gbyte)"); break;
713 case 0xda:
714 kprintf("OnStream ADR (15Gyte)"); break;
715 default:
716 kprintf("unknown (0x%x)", stp->cap.medium_type);
718 if (stp->cap.readonly) kprintf(", readonly");
719 if (stp->cap.reverse) kprintf(", reverse");
720 if (stp->cap.eformat) kprintf(", eformat");
721 if (stp->cap.qfa) kprintf(", qfa");
722 if (stp->cap.lock) kprintf(", lock");
723 if (stp->cap.locked) kprintf(", locked");
724 if (stp->cap.prevent) kprintf(", prevent");
725 if (stp->cap.eject) kprintf(", eject");
726 if (stp->cap.disconnect) kprintf(", disconnect");
727 if (stp->cap.ecc) kprintf(", ecc");
728 if (stp->cap.compress) kprintf(", compress");
729 if (stp->cap.blk512) kprintf(", 512b");
730 if (stp->cap.blk1024) kprintf(", 1024b");
731 if (stp->cap.blk32k) kprintf(", 32kb");
732 kprintf("\n");
734 else {
735 device_printf(dev, "TAPE <%.40s/%.8s> at ata%d-%s %s\n",
736 atadev->param.model, atadev->param.revision,
737 device_get_unit(ch->dev),
738 (atadev->unit == ATA_MASTER) ? "master" : "slave",
739 ata_mode2str(atadev->mode));
743 static device_method_t ast_methods[] = {
744 /* device interface */
745 DEVMETHOD(device_probe, ast_probe),
746 DEVMETHOD(device_attach, ast_attach),
747 DEVMETHOD(device_detach, ast_detach),
748 DEVMETHOD(device_shutdown, ast_shutdown),
750 /* ATA methods */
751 DEVMETHOD(ata_reinit, ast_reinit),
753 { 0, 0 }
756 static driver_t ast_driver = {
757 "ast",
758 ast_methods,
762 static devclass_t ast_devclass;
764 DRIVER_MODULE(ast, ata, ast_driver, ast_devclass, NULL, NULL);
765 MODULE_VERSION(ast, 1);
766 MODULE_DEPEND(ast, ata, 1, 1, 1);