2 * $FreeBSD: src/sys/cam/scsi/scsi_sa.c,v 1.45.2.13 2002/12/17 17:08:50 trhodes Exp $
3 * $DragonFly: src/sys/bus/cam/scsi/scsi_sa.c,v 1.33 2007/12/02 01:46:13 pavalos Exp $
5 * Implementation of SCSI Sequential Access Peripheral driver for CAM.
7 * Copyright (c) 1999, 2000 Matthew Jacob
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification, immediately at the beginning of the file.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/param.h>
34 #include <sys/queue.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <sys/types.h>
42 #include <sys/malloc.h>
49 #include <sys/thread2.h>
51 #include <sys/fcntl.h>
52 #include <sys/devicestat.h>
53 #include <machine/limits.h>
61 #include "../cam_ccb.h"
62 #include "../cam_extend.h"
63 #include "../cam_periph.h"
64 #include "../cam_xpt_periph.h"
65 #include "../cam_debug.h"
68 #include "scsi_message.h"
76 #define SA_IO_TIMEOUT 4
78 #ifndef SA_SPACE_TIMEOUT
79 #define SA_SPACE_TIMEOUT 1 * 60
81 #ifndef SA_REWIND_TIMEOUT
82 #define SA_REWIND_TIMEOUT 2 * 60
84 #ifndef SA_ERASE_TIMEOUT
85 #define SA_ERASE_TIMEOUT 4 * 60
88 #define SCSIOP_TIMEOUT (60 * 1000) /* not an option */
90 #define IO_TIMEOUT (SA_IO_TIMEOUT * 60 * 1000)
91 #define REWIND_TIMEOUT (SA_REWIND_TIMEOUT * 60 * 1000)
92 #define ERASE_TIMEOUT (SA_ERASE_TIMEOUT * 60 * 1000)
93 #define SPACE_TIMEOUT (SA_SPACE_TIMEOUT * 60 * 1000)
96 * Additional options that can be set for config: SA_1FM_AT_EOT
99 #ifndef UNUSED_PARAMETER
100 #define UNUSED_PARAMETER(x) x = x
104 if (((ccb)->ccb_h.status & CAM_DEV_QFRZN) != 0) \
105 cam_release_devq((ccb)->ccb_h.path, 0, 0, 0, FALSE)
111 MALLOC_DEFINE(M_SCSISA
, "SCSI sa", "SCSI sequential access buffers");
114 SA_STATE_NORMAL
, SA_STATE_ABNORMAL
117 #define ccb_pflags ppriv_field0
118 #define ccb_bio ppriv_ptr1
120 #define SA_CCB_BUFFER_IO 0x0
121 #define SA_CCB_WAITING 0x1
122 #define SA_CCB_TYPEMASK 0x1
123 #define SA_POSITION_UPDATED 0x2
125 #define Set_CCB_Type(x, type) \
126 x->ccb_h.ccb_pflags &= ~SA_CCB_TYPEMASK; \
127 x->ccb_h.ccb_pflags |= type
129 #define CCB_Type(x) (x->ccb_h.ccb_pflags & SA_CCB_TYPEMASK)
134 SA_FLAG_OPEN
= 0x0001,
135 SA_FLAG_FIXED
= 0x0002,
136 SA_FLAG_TAPE_LOCKED
= 0x0004,
137 SA_FLAG_TAPE_MOUNTED
= 0x0008,
138 SA_FLAG_TAPE_WP
= 0x0010,
139 SA_FLAG_TAPE_WRITTEN
= 0x0020,
140 SA_FLAG_EOM_PENDING
= 0x0040,
141 SA_FLAG_EIO_PENDING
= 0x0080,
142 SA_FLAG_EOF_PENDING
= 0x0100,
143 SA_FLAG_ERR_PENDING
= (SA_FLAG_EOM_PENDING
|SA_FLAG_EIO_PENDING
|
144 SA_FLAG_EOF_PENDING
),
145 SA_FLAG_INVALID
= 0x0200,
146 SA_FLAG_COMP_ENABLED
= 0x0400,
147 SA_FLAG_COMP_SUPP
= 0x0800,
148 SA_FLAG_COMP_UNSUPP
= 0x1000,
149 SA_FLAG_TAPE_FROZEN
= 0x2000
153 SA_MODE_REWIND
= 0x00,
154 SA_MODE_NOREWIND
= 0x01,
155 SA_MODE_OFFLINE
= 0x02
159 SA_PARAM_NONE
= 0x00,
160 SA_PARAM_BLOCKSIZE
= 0x01,
161 SA_PARAM_DENSITY
= 0x02,
162 SA_PARAM_COMPRESSION
= 0x04,
163 SA_PARAM_BUFF_MODE
= 0x08,
164 SA_PARAM_NUMBLOCKS
= 0x10,
166 SA_PARAM_SPEED
= 0x40,
171 SA_QUIRK_NONE
= 0x00,
172 SA_QUIRK_NOCOMP
= 0x01, /* Can't deal with compression at all */
173 SA_QUIRK_FIXED
= 0x02, /* Force fixed mode */
174 SA_QUIRK_VARIABLE
= 0x04, /* Force variable mode */
175 SA_QUIRK_2FM
= 0x08, /* Needs Two File Marks at EOD */
176 SA_QUIRK_1FM
= 0x10, /* No more than 1 File Mark at EOD */
177 SA_QUIRK_NODREAD
= 0x20, /* Don't try and dummy read density */
178 SA_QUIRK_NO_MODESEL
= 0x40, /* Don't do mode select at all */
179 SA_QUIRK_NO_CPAGE
= 0x80 /* Don't use DEVICE COMPRESSION page */
182 /* units are bits 4-7, 16-21 (1024 units) */
183 #define SAUNIT(DEV) \
184 (((minor(DEV) & 0xF0) >> 4) | ((minor(DEV) & 0x3f0000) >> 16))
186 #define SAMODE(z) ((minor(z) & 0x3))
187 #define SADENSITY(z) (((minor(z) >> 2) & 0x3))
188 #define SA_IS_CTRL(z) (minor(z) & (1 << 29))
190 #define SA_NOT_CTLDEV 0
194 #define SA_ATYPE_NR 1
195 #define SA_ATYPE_ER 2
197 #define SAMINOR(ctl, unit, mode, access) \
198 ((ctl << 29) | ((unit & 0x3f0) << 16) | ((unit & 0xf) << 4) | \
199 (mode << 0x2) | (access & 0x3))
201 #define SA_UNITMASK SAMINOR(0, -1, 0, 0)
202 #define SA_UNIT(unit) SAMINOR(0, unit, 0, 0)
204 #define SA_NUM_MODES 4
210 struct bio_queue_head bio_queue
;
212 struct devstat device_stats
;
218 u_int32_t comp_algorithm
;
219 u_int32_t saved_comp_algorithm
;
220 u_int32_t media_blksize
;
221 u_int32_t last_media_blksize
;
222 u_int32_t media_numblks
;
223 u_int8_t media_density
;
226 u_int8_t dsreg
; /* mtio mt_dsreg, redux */
230 int last_resid_was_io
;
233 * Relative to BOT Location.
242 struct scsi_sense_data _last_io_sense
;
243 u_int32_t _last_io_resid
;
244 u_int8_t _last_io_cdb
[CAM_MAX_CDBLEN
];
245 struct scsi_sense_data _last_ctl_sense
;
246 u_int32_t _last_ctl_resid
;
247 u_int8_t _last_ctl_cdb
[CAM_MAX_CDBLEN
];
248 #define last_io_sense errinfo._last_io_sense
249 #define last_io_resid errinfo._last_io_resid
250 #define last_io_cdb errinfo._last_io_cdb
251 #define last_ctl_sense errinfo._last_ctl_sense
252 #define last_ctl_resid errinfo._last_ctl_resid
253 #define last_ctl_cdb errinfo._last_ctl_cdb
256 * Misc other flags/state
260 open_rdonly
: 1, /* open read-only */
261 open_pending_mount
: 1, /* open pending mount */
262 ctrl_mode
: 1; /* control device open */
265 struct sa_quirk_entry
{
266 struct scsi_inquiry_pattern inq_pat
; /* matching pattern */
267 sa_quirks quirks
; /* specific quirk type */
268 u_int32_t prefblk
; /* preferred blocksize when in fixed mode */
271 static struct sa_quirk_entry sa_quirk_table
[] =
274 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "OnStream",
275 "ADR*", "*"}, SA_QUIRK_FIXED
|SA_QUIRK_NODREAD
|
276 SA_QUIRK_1FM
|SA_QUIRK_NO_MODESEL
, 32768
279 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "ARCHIVE",
280 "Python 06408*", "*"}, SA_QUIRK_NODREAD
, 0
283 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "ARCHIVE",
284 "Python 25601*", "*"}, SA_QUIRK_NOCOMP
|SA_QUIRK_NODREAD
, 0
287 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "ARCHIVE",
288 "Python*", "*"}, SA_QUIRK_NODREAD
, 0
291 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "ARCHIVE",
292 "VIPER 150*", "*"}, SA_QUIRK_FIXED
|SA_QUIRK_1FM
, 512
295 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "ARCHIVE",
296 "VIPER 2525 25462", "-011"},
297 SA_QUIRK_NOCOMP
|SA_QUIRK_1FM
|SA_QUIRK_NODREAD
, 0
300 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "ARCHIVE",
301 "VIPER 2525*", "*"}, SA_QUIRK_FIXED
|SA_QUIRK_1FM
, 1024
305 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "HP",
306 "C15*", "*"}, SA_QUIRK_VARIABLE
|SA_QUIRK_NO_CPAGE
, 0,
310 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "HP",
311 "C56*", "*"}, SA_QUIRK_VARIABLE
|SA_QUIRK_2FM
, 0
314 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "HP",
315 "T20*", "*"}, SA_QUIRK_FIXED
|SA_QUIRK_1FM
, 512
318 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "HP",
319 "T4000*", "*"}, SA_QUIRK_FIXED
|SA_QUIRK_1FM
, 512
322 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "HP",
323 "HP-88780*", "*"}, SA_QUIRK_VARIABLE
|SA_QUIRK_2FM
, 0
326 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "KENNEDY",
327 "*", "*"}, SA_QUIRK_VARIABLE
|SA_QUIRK_2FM
, 0
330 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "M4 DATA",
331 "123107 SCSI*", "*"}, SA_QUIRK_VARIABLE
|SA_QUIRK_2FM
, 0
333 { /* jreynold@primenet.com */
334 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "Seagate",
335 "STT8000N*", "*"}, SA_QUIRK_1FM
, 0
337 { /* mike@sentex.net */
338 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "Seagate",
339 "STT20000*", "*"}, SA_QUIRK_1FM
, 0
342 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "TANDBERG",
343 " TDC 3600", "U07:"}, SA_QUIRK_NOCOMP
|SA_QUIRK_1FM
, 512
346 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "TANDBERG",
347 " TDC 3800", "*"}, SA_QUIRK_NOCOMP
|SA_QUIRK_1FM
, 512
350 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "TANDBERG",
351 " TDC 4100", "*"}, SA_QUIRK_NOCOMP
|SA_QUIRK_1FM
, 512
354 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "TANDBERG",
355 " TDC 4200", "*"}, SA_QUIRK_NOCOMP
|SA_QUIRK_1FM
, 512
358 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "TANDBERG",
359 " SLR*", "*"}, SA_QUIRK_1FM
, 0
362 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "WANGTEK",
363 "5525ES*", "*"}, SA_QUIRK_FIXED
|SA_QUIRK_1FM
, 512
366 { T_SEQUENTIAL
, SIP_MEDIA_REMOVABLE
, "WANGTEK",
367 "51000*", "*"}, SA_QUIRK_FIXED
|SA_QUIRK_1FM
, 1024
371 static d_open_t saopen
;
372 static d_close_t saclose
;
373 static d_strategy_t sastrategy
;
374 static d_ioctl_t saioctl
;
375 static periph_init_t sainit
;
376 static periph_ctor_t saregister
;
377 static periph_oninv_t saoninvalidate
;
378 static periph_dtor_t sacleanup
;
379 static periph_start_t sastart
;
380 static void saasync(void *callback_arg
, u_int32_t code
,
381 struct cam_path
*path
, void *arg
);
382 static void sadone(struct cam_periph
*periph
,
383 union ccb
*start_ccb
);
384 static int saerror(union ccb
*ccb
, u_int32_t cam_flags
,
385 u_int32_t sense_flags
);
386 static int samarkswanted(struct cam_periph
*);
387 static int sacheckeod(struct cam_periph
*periph
);
388 static int sagetparams(struct cam_periph
*periph
,
389 sa_params params_to_get
,
390 u_int32_t
*blocksize
, u_int8_t
*density
,
391 u_int32_t
*numblocks
, int *buff_mode
,
392 u_int8_t
*write_protect
, u_int8_t
*speed
,
393 int *comp_supported
, int *comp_enabled
,
394 u_int32_t
*comp_algorithm
,
395 sa_comp_t
*comp_page
);
396 static int sasetparams(struct cam_periph
*periph
,
397 sa_params params_to_set
,
398 u_int32_t blocksize
, u_int8_t density
,
399 u_int32_t comp_algorithm
,
400 u_int32_t sense_flags
);
401 static void saprevent(struct cam_periph
*periph
, int action
);
402 static int sarewind(struct cam_periph
*periph
);
403 static int saspace(struct cam_periph
*periph
, int count
,
404 scsi_space_code code
);
405 static int samount(struct cam_periph
*, int, cdev_t
);
406 static int saretension(struct cam_periph
*periph
);
407 static int sareservereleaseunit(struct cam_periph
*periph
,
409 static int saloadunload(struct cam_periph
*periph
, int load
);
410 static int saerase(struct cam_periph
*periph
, int longerase
);
411 static int sawritefilemarks(struct cam_periph
*periph
,
412 int nmarks
, int setmarks
);
413 static int sardpos(struct cam_periph
*periph
, int, u_int32_t
*);
414 static int sasetpos(struct cam_periph
*periph
, int, u_int32_t
*);
417 static struct periph_driver sadriver
=
420 TAILQ_HEAD_INITIALIZER(sadriver
.units
), /* generation */ 0
423 PERIPHDRIVER_DECLARE(sa
, sadriver
);
425 /* For 2.2-stable support */
430 #define SA_CDEV_MAJOR 14
432 static struct dev_ops sa_ops
= {
433 { "sa", SA_CDEV_MAJOR
, D_TAPE
},
437 .d_write
= physwrite
,
439 .d_strategy
= sastrategy
,
442 static struct extend_array
*saperiphs
;
445 saopen(struct dev_open_args
*ap
)
447 cdev_t dev
= ap
->a_head
.a_dev
;
448 struct cam_periph
*periph
;
449 struct sa_softc
*softc
;
456 periph
= cam_extend_get(saperiphs
, unit
);
457 if (periph
== NULL
) {
461 softc
= (struct sa_softc
*)periph
->softc
;
462 if ((error
= cam_periph_lock(periph
, PCATCH
)) != 0) {
468 CAM_DEBUG(periph
->path
, CAM_DEBUG_TRACE
|CAM_DEBUG_INFO
,
469 ("saopen(%d): dev=0x%x softc=0x%x\n", unit
, unit
, softc
->flags
));
471 if (cam_periph_acquire(periph
) != CAM_REQ_CMP
) {
472 cam_periph_unlock(periph
);
476 if (SA_IS_CTRL(dev
)) {
477 softc
->ctrl_mode
= 1;
478 cam_periph_unlock(periph
);
482 if (softc
->flags
& SA_FLAG_OPEN
) {
484 } else if (softc
->flags
& SA_FLAG_INVALID
) {
488 * Preserve whether this is a read_only open.
490 softc
->open_rdonly
= (ap
->a_oflags
& O_RDWR
) == O_RDONLY
;
493 * The function samount ensures media is loaded and ready.
494 * It also does a device RESERVE if the tape isn't yet mounted.
496 * If the mount fails and this was a non-blocking open,
497 * make this a 'open_pending_mount' action.
499 error
= samount(periph
, ap
->a_oflags
, dev
);
500 if (error
&& (ap
->a_oflags
& O_NONBLOCK
)) {
501 softc
->flags
|= SA_FLAG_OPEN
;
502 softc
->open_pending_mount
= 1;
503 cam_periph_unlock(periph
);
509 cam_periph_release(periph
);
511 saprevent(periph
, PR_PREVENT
);
512 softc
->flags
|= SA_FLAG_OPEN
;
514 cam_periph_unlock(periph
);
519 saclose(struct dev_close_args
*ap
)
521 cdev_t dev
= ap
->a_head
.a_dev
;
522 struct cam_periph
*periph
;
523 struct sa_softc
*softc
;
524 int unit
, mode
, error
, writing
, tmp
;
525 int closedbits
= SA_FLAG_OPEN
;
529 periph
= cam_extend_get(saperiphs
, unit
);
533 softc
= (struct sa_softc
*)periph
->softc
;
535 CAM_DEBUG(periph
->path
, CAM_DEBUG_TRACE
|CAM_DEBUG_INFO
,
536 ("saclose(%d): dev=0x%x softc=0x%x\n", unit
, unit
, softc
->flags
));
539 if ((error
= cam_periph_lock(periph
, 0)) != 0) {
543 softc
->open_rdonly
= 0;
544 if (SA_IS_CTRL(dev
)) {
545 softc
->ctrl_mode
= 0;
546 cam_periph_release(periph
);
547 cam_periph_unlock(periph
);
551 if (softc
->open_pending_mount
) {
552 softc
->flags
&= ~SA_FLAG_OPEN
;
553 softc
->open_pending_mount
= 0;
554 cam_periph_release(periph
);
555 cam_periph_unlock(periph
);
560 * Were we writing the tape?
562 writing
= (softc
->flags
& SA_FLAG_TAPE_WRITTEN
) != 0;
565 * See whether or not we need to write filemarks. If this
566 * fails, we probably have to assume we've lost tape
569 error
= sacheckeod(periph
);
571 xpt_print_path(periph
->path
);
572 kprintf("failed to write terminating filemark(s)\n");
573 softc
->flags
|= SA_FLAG_TAPE_FROZEN
;
577 * Whatever we end up doing, allow users to eject tapes from here on.
579 saprevent(periph
, PR_ALLOW
);
582 * Decide how to end...
584 if ((softc
->flags
& SA_FLAG_TAPE_MOUNTED
) == 0) {
585 closedbits
|= SA_FLAG_TAPE_FROZEN
;
586 } else switch (mode
) {
587 case SA_MODE_OFFLINE
:
589 * An 'offline' close is an unconditional release of
590 * frozen && mount conditions, irrespective of whether
591 * these operations succeeded. The reason for this is
592 * to allow at least some kind of programmatic way
593 * around our state getting all fouled up. If somebody
594 * issues an 'offline' command, that will be allowed
598 saloadunload(periph
, FALSE
);
599 closedbits
|= SA_FLAG_TAPE_MOUNTED
|SA_FLAG_TAPE_FROZEN
;
603 * If the rewind fails, return an error- if anyone cares,
604 * but not overwriting any previous error.
606 * We don't clear the notion of mounted here, but we do
607 * clear the notion of frozen if we successfully rewound.
609 tmp
= sarewind(periph
);
614 closedbits
|= SA_FLAG_TAPE_FROZEN
;
617 case SA_MODE_NOREWIND
:
619 * If we're not rewinding/unloading the tape, find out
620 * whether we need to back up over one of two filemarks
621 * we wrote (if we wrote two filemarks) so that appends
622 * from this point on will be sane.
624 if (error
== 0 && writing
&& (softc
->quirks
& SA_QUIRK_2FM
)) {
625 tmp
= saspace(periph
, -1, SS_FILEMARKS
);
627 xpt_print_path(periph
->path
);
628 kprintf("unable to backspace over one of double"
629 " filemarks at end of tape\n");
630 xpt_print_path(periph
->path
);
631 kprintf("it is possible that this device"
632 " needs a SA_QUIRK_1FM quirk set for it\n");
633 softc
->flags
|= SA_FLAG_TAPE_FROZEN
;
638 xpt_print_path(periph
->path
);
639 panic("unknown mode 0x%x in saclose", mode
);
645 * We wish to note here that there are no more filemarks to be written.
647 softc
->filemarks
= 0;
648 softc
->flags
&= ~SA_FLAG_TAPE_WRITTEN
;
651 * And we are no longer open for business.
653 softc
->flags
&= ~closedbits
;
656 * Inform users if tape state if frozen....
658 if (softc
->flags
& SA_FLAG_TAPE_FROZEN
) {
659 xpt_print_path(periph
->path
);
660 kprintf("tape is now frozen- use an OFFLINE, REWIND or MTEOM "
661 "command to clear this state.\n");
664 /* release the device if it is no longer mounted */
665 if ((softc
->flags
& SA_FLAG_TAPE_MOUNTED
) == 0)
666 sareservereleaseunit(periph
, FALSE
);
668 cam_periph_unlock(periph
);
669 cam_periph_release(periph
);
675 * Actually translate the requested transfer into one the physical driver
676 * can understand. The transfer is described by a buf and will include
677 * only one physical transfer.
680 sastrategy(struct dev_strategy_args
*ap
)
682 cdev_t dev
= ap
->a_head
.a_dev
;
683 struct bio
*bio
= ap
->a_bio
;
684 struct buf
*bp
= bio
->bio_buf
;
685 struct cam_periph
*periph
;
686 struct sa_softc
*softc
;
689 if (SA_IS_CTRL(dev
)) {
690 bp
->b_error
= EINVAL
;
694 periph
= cam_extend_get(saperiphs
, unit
);
695 if (periph
== NULL
) {
699 softc
= (struct sa_softc
*)periph
->softc
;
703 if (softc
->flags
& SA_FLAG_INVALID
) {
709 if (softc
->flags
& SA_FLAG_TAPE_FROZEN
) {
716 * This should actually never occur as the write(2)
717 * system call traps attempts to write to a read-only
720 if (bp
->b_cmd
== BUF_CMD_WRITE
&& softc
->open_rdonly
) {
728 if (softc
->open_pending_mount
) {
729 int error
= samount(periph
, 0, dev
);
734 saprevent(periph
, PR_PREVENT
);
735 softc
->open_pending_mount
= 0;
739 * If it's a null transfer, return immediately
741 if (bp
->b_bcount
== 0)
745 if (softc
->flags
& SA_FLAG_FIXED
) {
747 * Fixed block device. The byte count must
748 * be a multiple of our block size.
750 if (((softc
->blk_mask
!= ~0) &&
751 ((bp
->b_bcount
& softc
->blk_mask
) != 0)) ||
752 ((softc
->blk_mask
== ~0) &&
753 ((bp
->b_bcount
% softc
->min_blk
) != 0))) {
754 xpt_print_path(periph
->path
);
755 kprintf("Invalid request. Fixed block device "
756 "requests must be a multiple "
757 "of %d bytes\n", softc
->media_blksize
);
758 bp
->b_error
= EINVAL
;
761 } else if ((bp
->b_bcount
> softc
->max_blk
) ||
762 (bp
->b_bcount
< softc
->min_blk
) ||
763 (bp
->b_bcount
& softc
->blk_mask
) != 0) {
765 xpt_print_path(periph
->path
);
766 kprintf("Invalid request. Variable block device "
767 "requests must be ");
768 if (softc
->blk_mask
!= 0) {
769 kprintf("a multiple of %d ", (0x1 << softc
->blk_gran
));
771 kprintf("between %d and %d bytes\n", softc
->min_blk
,
773 bp
->b_error
= EINVAL
;
778 * Mask interrupts so that the device cannot be invalidated until
779 * after we are in the queue. Otherwise, we might not properly
780 * clean up one of the buffers.
785 * Place it at the end of the queue.
787 bioq_insert_tail(&softc
->bio_queue
, bio
);
788 softc
->queue_count
++;
790 CAM_DEBUG(periph
->path
, CAM_DEBUG_INFO
,
791 ("sastrategy: queuing a %ld %s byte %s\n", bp
->bio_bcount
,
792 (softc
->flags
& SA_FLAG_FIXED
)? "fixed" : "variable",
793 (bp
->bio_cmd
== BIO_READ
)? "read" : "write"));
795 if (softc
->queue_count
> 1) {
796 CAM_DEBUG(periph
->path
, CAM_DEBUG_INFO
,
797 ("sastrategy: queue count now %d\n", softc
->queue_count
));
802 * Schedule ourselves for performing the work.
804 xpt_schedule(periph
, 1);
808 bp
->b_flags
|= B_ERROR
;
812 * Correctly set the buf to indicate a completed xfer
814 bp
->b_resid
= bp
->b_bcount
;
820 #define PENDING_MOUNT_CHECK(softc, periph, dev) \
821 if (softc->open_pending_mount) { \
822 error = samount(periph, 0, dev); \
826 saprevent(periph, PR_PREVENT); \
827 softc->open_pending_mount = 0; \
831 saioctl(struct dev_ioctl_args
*ap
)
833 cdev_t dev
= ap
->a_head
.a_dev
;
834 caddr_t addr
= ap
->a_data
;
835 struct cam_periph
*periph
;
836 struct sa_softc
*softc
;
837 scsi_space_code spaceop
;
838 int didlockperiph
= 0;
845 error
= 0; /* shut up gcc */
846 spaceop
= 0; /* shut up gcc */
848 periph
= cam_extend_get(saperiphs
, unit
);
852 softc
= (struct sa_softc
*)periph
->softc
;
855 * Check for control mode accesses. We allow MTIOCGET and
856 * MTIOCERRSTAT (but need to be the only one open in order
857 * to clear latched status), and MTSETBSIZE, MTSETDNSTY
858 * and MTCOMP (but need to be the only one accessing this
859 * device to run those).
862 if (SA_IS_CTRL(dev
)) {
864 case MTIOCGETEOTMODEL
:
869 * If the periph isn't already locked, lock it
870 * so our MTIOCERRSTAT can reset latched error stats.
872 * If the periph is already locked, skip it because
873 * we're just getting status and it'll be up to the
874 * other thread that has this device open to do
875 * an MTIOCERRSTAT that would clear latched status.
878 if ((periph
->flags
& CAM_PERIPH_LOCKED
) == 0) {
879 error
= cam_periph_lock(periph
, PCATCH
);
891 struct mtop
*mt
= (struct mtop
*) addr
;
894 * Check to make sure it's an OP we can perform
895 * with no media inserted.
911 case MTIOCSETEOTMODEL
:
913 * We need to acquire the peripheral here rather
914 * than at open time because we are sharing writable
915 * access to data structures.
918 error
= cam_periph_lock(periph
, PCATCH
);
933 * Find the device that the user is talking about
938 struct mtget
*g
= (struct mtget
*)addr
;
941 * If this isn't the control mode device, actually go out
942 * and ask the drive again what it's set to.
944 if (!SA_IS_CTRL(dev
) && !softc
->open_pending_mount
) {
945 u_int8_t write_protect
;
946 int comp_enabled
, comp_supported
;
947 error
= sagetparams(periph
, SA_PARAM_ALL
,
948 &softc
->media_blksize
, &softc
->media_density
,
949 &softc
->media_numblks
, &softc
->buffer_mode
,
950 &write_protect
, &softc
->speed
, &comp_supported
,
951 &comp_enabled
, &softc
->comp_algorithm
, NULL
);
955 softc
->flags
|= SA_FLAG_TAPE_WP
;
957 softc
->flags
&= ~SA_FLAG_TAPE_WP
;
958 softc
->flags
&= ~(SA_FLAG_COMP_SUPP
|
959 SA_FLAG_COMP_ENABLED
|SA_FLAG_COMP_UNSUPP
);
960 if (comp_supported
) {
961 if (softc
->saved_comp_algorithm
== 0)
962 softc
->saved_comp_algorithm
=
963 softc
->comp_algorithm
;
964 softc
->flags
|= SA_FLAG_COMP_SUPP
;
966 softc
->flags
|= SA_FLAG_COMP_ENABLED
;
968 softc
->flags
|= SA_FLAG_COMP_UNSUPP
;
970 bzero(g
, sizeof(struct mtget
));
971 g
->mt_type
= MT_ISAR
;
972 if (softc
->flags
& SA_FLAG_COMP_UNSUPP
) {
973 g
->mt_comp
= MT_COMP_UNSUPP
;
974 g
->mt_comp0
= MT_COMP_UNSUPP
;
975 g
->mt_comp1
= MT_COMP_UNSUPP
;
976 g
->mt_comp2
= MT_COMP_UNSUPP
;
977 g
->mt_comp3
= MT_COMP_UNSUPP
;
979 if ((softc
->flags
& SA_FLAG_COMP_ENABLED
) == 0) {
980 g
->mt_comp
= MT_COMP_DISABLED
;
982 g
->mt_comp
= softc
->comp_algorithm
;
984 g
->mt_comp0
= softc
->comp_algorithm
;
985 g
->mt_comp1
= softc
->comp_algorithm
;
986 g
->mt_comp2
= softc
->comp_algorithm
;
987 g
->mt_comp3
= softc
->comp_algorithm
;
989 g
->mt_density
= softc
->media_density
;
990 g
->mt_density0
= softc
->media_density
;
991 g
->mt_density1
= softc
->media_density
;
992 g
->mt_density2
= softc
->media_density
;
993 g
->mt_density3
= softc
->media_density
;
994 g
->mt_blksiz
= softc
->media_blksize
;
995 g
->mt_blksiz0
= softc
->media_blksize
;
996 g
->mt_blksiz1
= softc
->media_blksize
;
997 g
->mt_blksiz2
= softc
->media_blksize
;
998 g
->mt_blksiz3
= softc
->media_blksize
;
999 g
->mt_fileno
= softc
->fileno
;
1000 g
->mt_blkno
= softc
->blkno
;
1001 g
->mt_dsreg
= (short) softc
->dsreg
;
1003 * Yes, we know that this is likely to overflow
1005 if (softc
->last_resid_was_io
) {
1006 if ((g
->mt_resid
= (short) softc
->last_io_resid
) != 0) {
1007 if (SA_IS_CTRL(dev
) == 0 || didlockperiph
) {
1008 softc
->last_io_resid
= 0;
1012 if ((g
->mt_resid
= (short)softc
->last_ctl_resid
) != 0) {
1013 if (SA_IS_CTRL(dev
) == 0 || didlockperiph
) {
1014 softc
->last_ctl_resid
= 0;
1023 struct scsi_tape_errors
*sep
=
1024 &((union mterrstat
*)addr
)->scsi_errstat
;
1026 CAM_DEBUG(periph
->path
, CAM_DEBUG_TRACE
,
1027 ("saioctl: MTIOCERRSTAT\n"));
1029 bzero(sep
, sizeof(*sep
));
1030 sep
->io_resid
= softc
->last_io_resid
;
1031 bcopy((caddr_t
) &softc
->last_io_sense
, sep
->io_sense
,
1032 sizeof (sep
->io_sense
));
1033 bcopy((caddr_t
) &softc
->last_io_cdb
, sep
->io_cdb
,
1034 sizeof (sep
->io_cdb
));
1035 sep
->ctl_resid
= softc
->last_ctl_resid
;
1036 bcopy((caddr_t
) &softc
->last_ctl_sense
, sep
->ctl_sense
,
1037 sizeof (sep
->ctl_sense
));
1038 bcopy((caddr_t
) &softc
->last_ctl_cdb
, sep
->ctl_cdb
,
1039 sizeof (sep
->ctl_cdb
));
1041 if ((SA_IS_CTRL(dev
) == 0 && softc
->open_pending_mount
) ||
1043 bzero((caddr_t
) &softc
->errinfo
,
1044 sizeof (softc
->errinfo
));
1053 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1055 mt
= (struct mtop
*)addr
;
1057 CAM_DEBUG(periph
->path
, CAM_DEBUG_TRACE
,
1058 ("saioctl: op=0x%x count=0x%x\n",
1059 mt
->mt_op
, mt
->mt_count
));
1061 count
= mt
->mt_count
;
1062 switch (mt
->mt_op
) {
1063 case MTWEOF
: /* write an end-of-file marker */
1065 * We don't need to clear the SA_FLAG_TAPE_WRITTEN
1066 * flag because by keeping track of filemarks
1067 * we have last written we know ehether or not
1068 * we need to write more when we close the device.
1070 error
= sawritefilemarks(periph
, count
, FALSE
);
1072 case MTWSS
: /* write a setmark */
1073 error
= sawritefilemarks(periph
, count
, TRUE
);
1075 case MTBSR
: /* backward space record */
1076 case MTFSR
: /* forward space record */
1077 case MTBSF
: /* backward space file */
1078 case MTFSF
: /* forward space file */
1079 case MTBSS
: /* backward space setmark */
1080 case MTFSS
: /* forward space setmark */
1081 case MTEOD
: /* space to end of recorded medium */
1085 spaceop
= SS_FILEMARKS
;
1086 nmarks
= softc
->filemarks
;
1087 error
= sacheckeod(periph
);
1089 xpt_print_path(periph
->path
);
1090 kprintf("EOD check prior to spacing failed\n");
1091 softc
->flags
|= SA_FLAG_EIO_PENDING
;
1094 nmarks
-= softc
->filemarks
;
1100 spaceop
= SS_BLOCKS
;
1111 spaceop
= SS_SETMARKS
;
1125 nmarks
= softc
->filemarks
;
1127 * XXX: Why are we checking again?
1129 error
= sacheckeod(periph
);
1132 nmarks
-= softc
->filemarks
;
1133 error
= saspace(periph
, count
- nmarks
, spaceop
);
1135 * At this point, clear that we've written the tape
1136 * and that we've written any filemarks. We really
1137 * don't know what the applications wishes to do next-
1138 * the sacheckeod's will make sure we terminated the
1139 * tape correctly if we'd been writing, but the next
1140 * action the user application takes will set again
1141 * whether we need to write filemarks.
1144 ~(SA_FLAG_TAPE_WRITTEN
|SA_FLAG_TAPE_FROZEN
);
1145 softc
->filemarks
= 0;
1148 case MTREW
: /* rewind */
1149 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1151 error
= sarewind(periph
);
1154 ~(SA_FLAG_TAPE_WRITTEN
|SA_FLAG_TAPE_FROZEN
);
1155 softc
->flags
&= ~SA_FLAG_ERR_PENDING
;
1156 softc
->filemarks
= 0;
1158 case MTERASE
: /* erase */
1159 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1160 error
= saerase(periph
, count
);
1162 ~(SA_FLAG_TAPE_WRITTEN
|SA_FLAG_TAPE_FROZEN
);
1163 softc
->flags
&= ~SA_FLAG_ERR_PENDING
;
1165 case MTRETENS
: /* re-tension tape */
1166 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1167 error
= saretension(periph
);
1169 ~(SA_FLAG_TAPE_WRITTEN
|SA_FLAG_TAPE_FROZEN
);
1170 softc
->flags
&= ~SA_FLAG_ERR_PENDING
;
1172 case MTOFFL
: /* rewind and put the drive offline */
1174 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1178 softc
->flags
&= ~SA_FLAG_TAPE_WRITTEN
;
1179 softc
->filemarks
= 0;
1181 error
= sarewind(periph
);
1182 /* clear the frozen flag anyway */
1183 softc
->flags
&= ~SA_FLAG_TAPE_FROZEN
;
1186 * Be sure to allow media removal before ejecting.
1189 saprevent(periph
, PR_ALLOW
);
1191 error
= saloadunload(periph
, FALSE
);
1193 softc
->flags
&= ~SA_FLAG_TAPE_MOUNTED
;
1198 case MTNOP
: /* no operation, sets status only */
1199 case MTCACHE
: /* enable controller cache */
1200 case MTNOCACHE
: /* disable controller cache */
1204 case MTSETBSIZ
: /* Set block size for device */
1206 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1208 error
= sasetparams(periph
, SA_PARAM_BLOCKSIZE
, count
,
1211 softc
->last_media_blksize
=
1212 softc
->media_blksize
;
1213 softc
->media_blksize
= count
;
1215 softc
->flags
|= SA_FLAG_FIXED
;
1216 if (powerof2(count
)) {
1219 softc
->blk_mask
= count
- 1;
1221 softc
->blk_mask
= ~0;
1222 softc
->blk_shift
= 0;
1225 * Make the user's desire 'persistent'.
1227 softc
->quirks
&= ~SA_QUIRK_VARIABLE
;
1228 softc
->quirks
|= SA_QUIRK_FIXED
;
1230 softc
->flags
&= ~SA_FLAG_FIXED
;
1231 if (softc
->max_blk
== 0) {
1232 softc
->max_blk
= ~0;
1234 softc
->blk_shift
= 0;
1235 if (softc
->blk_gran
!= 0) {
1237 softc
->blk_gran
- 1;
1239 softc
->blk_mask
= 0;
1242 * Make the user's desire 'persistent'.
1244 softc
->quirks
|= SA_QUIRK_VARIABLE
;
1245 softc
->quirks
&= ~SA_QUIRK_FIXED
;
1249 case MTSETDNSTY
: /* Set density for device and mode */
1250 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1252 if (count
> UCHAR_MAX
) {
1256 error
= sasetparams(periph
, SA_PARAM_DENSITY
,
1260 case MTCOMP
: /* enable compression */
1261 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1263 * Some devices don't support compression, and
1264 * don't like it if you ask them for the
1267 if ((softc
->quirks
& SA_QUIRK_NOCOMP
) ||
1268 (softc
->flags
& SA_FLAG_COMP_UNSUPP
)) {
1272 error
= sasetparams(periph
, SA_PARAM_COMPRESSION
,
1273 0, 0, count
, SF_NO_PRINT
);
1285 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1286 error
= sardpos(periph
, 0, (u_int32_t
*) addr
);
1289 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1290 error
= sardpos(periph
, 1, (u_int32_t
*) addr
);
1293 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1294 error
= sasetpos(periph
, 0, (u_int32_t
*) addr
);
1297 PENDING_MOUNT_CHECK(softc
, periph
, dev
);
1298 error
= sasetpos(periph
, 1, (u_int32_t
*) addr
);
1300 case MTIOCGETEOTMODEL
:
1302 if (softc
->quirks
& SA_QUIRK_1FM
)
1306 *((u_int32_t
*) addr
) = mode
;
1308 case MTIOCSETEOTMODEL
:
1310 switch (*((u_int32_t
*) addr
)) {
1312 softc
->quirks
&= ~SA_QUIRK_2FM
;
1313 softc
->quirks
|= SA_QUIRK_1FM
;
1316 softc
->quirks
&= ~SA_QUIRK_1FM
;
1317 softc
->quirks
|= SA_QUIRK_2FM
;
1325 error
= cam_periph_ioctl(periph
, ap
->a_cmd
, addr
, saerror
);
1330 * Check to see if we cleared a frozen state
1332 if (error
== 0 && (softc
->flags
& SA_FLAG_TAPE_FROZEN
)) {
1338 softc
->fileno
= (daddr_t
) -1;
1339 softc
->blkno
= (daddr_t
) -1;
1340 softc
->flags
&= ~SA_FLAG_TAPE_FROZEN
;
1341 xpt_print_path(periph
->path
);
1342 kprintf("tape state now unfrozen.\n");
1348 if (didlockperiph
) {
1349 cam_periph_unlock(periph
);
1358 struct cam_path
*path
;
1361 * Create our extend array for storing the devices we attach to.
1363 saperiphs
= cam_extend_new();
1364 if (saperiphs
== NULL
) {
1365 kprintf("sa: Failed to alloc extend array!\n");
1370 * Install a global async callback.
1372 status
= xpt_create_path(&path
, NULL
, CAM_XPT_PATH_ID
,
1373 CAM_TARGET_WILDCARD
, CAM_LUN_WILDCARD
);
1375 if (status
== CAM_REQ_CMP
) {
1376 /* Register the async callbacks of interrest */
1377 struct ccb_setasync csa
; /*
1378 * This is an immediate CCB,
1379 * so using the stack is OK
1381 xpt_setup_ccb(&csa
.ccb_h
, path
, 5);
1382 csa
.ccb_h
.func_code
= XPT_SASYNC_CB
;
1383 csa
.event_enable
= AC_FOUND_DEVICE
;
1384 csa
.callback
= saasync
;
1385 csa
.callback_arg
= NULL
;
1386 xpt_action((union ccb
*)&csa
);
1387 status
= csa
.ccb_h
.status
;
1388 xpt_free_path(path
);
1391 if (status
!= CAM_REQ_CMP
) {
1392 kprintf("sa: Failed to attach master async callback "
1393 "due to status 0x%x!\n", status
);
1398 saoninvalidate(struct cam_periph
*periph
)
1400 struct sa_softc
*softc
;
1403 struct ccb_setasync csa
;
1405 softc
= (struct sa_softc
*)periph
->softc
;
1408 * De-register any async callbacks.
1410 xpt_setup_ccb(&csa
.ccb_h
, periph
->path
,
1412 csa
.ccb_h
.func_code
= XPT_SASYNC_CB
;
1413 csa
.event_enable
= 0;
1414 csa
.callback
= saasync
;
1415 csa
.callback_arg
= periph
;
1416 xpt_action((union ccb
*)&csa
);
1418 softc
->flags
|= SA_FLAG_INVALID
;
1421 * We need to be in a critical section here to keep the buffer
1422 * queue from being modified while we traverse it.
1427 * Return all queued I/O with ENXIO.
1428 * XXX Handle any transactions queued to the card
1429 * with XPT_ABORT_CCB.
1431 while ((q_bio
= bioq_first(&softc
->bio_queue
)) != NULL
){
1432 bioq_remove(&softc
->bio_queue
, q_bio
);
1433 q_bp
= q_bio
->bio_buf
;
1434 q_bp
->b_resid
= q_bp
->b_bcount
;
1435 q_bp
->b_error
= ENXIO
;
1436 q_bp
->b_flags
|= B_ERROR
;
1439 softc
->queue_count
= 0;
1442 xpt_print_path(periph
->path
);
1443 kprintf("lost device\n");
1448 sacleanup(struct cam_periph
*periph
)
1450 struct sa_softc
*softc
;
1452 softc
= (struct sa_softc
*)periph
->softc
;
1454 devstat_remove_entry(&softc
->device_stats
);
1456 cam_extend_release(saperiphs
, periph
->unit_number
);
1457 xpt_print_path(periph
->path
);
1458 kprintf("removing device entry\n");
1459 dev_ops_remove(&sa_ops
, SA_UNITMASK
, SA_UNIT(periph
->unit_number
));
1460 kfree(softc
, M_SCSISA
);
1464 saasync(void *callback_arg
, u_int32_t code
,
1465 struct cam_path
*path
, void *arg
)
1467 struct cam_periph
*periph
;
1469 periph
= (struct cam_periph
*)callback_arg
;
1471 case AC_FOUND_DEVICE
:
1473 struct ccb_getdev
*cgd
;
1476 cgd
= (struct ccb_getdev
*)arg
;
1480 if (SID_TYPE(&cgd
->inq_data
) != T_SEQUENTIAL
)
1484 * Allocate a peripheral instance for
1485 * this device and start the probe
1488 status
= cam_periph_alloc(saregister
, saoninvalidate
,
1490 "sa", CAM_PERIPH_BIO
, cgd
->ccb_h
.path
,
1491 saasync
, AC_FOUND_DEVICE
, cgd
);
1493 if (status
!= CAM_REQ_CMP
1494 && status
!= CAM_REQ_INPROG
)
1495 kprintf("saasync: Unable to probe new device "
1496 "due to status 0x%x\n", status
);
1500 cam_periph_async(periph
, code
, path
, arg
);
1506 saregister(struct cam_periph
*periph
, void *arg
)
1508 struct sa_softc
*softc
;
1509 struct ccb_setasync csa
;
1510 struct ccb_getdev
*cgd
;
1514 cgd
= (struct ccb_getdev
*)arg
;
1515 if (periph
== NULL
) {
1516 kprintf("saregister: periph was NULL!!\n");
1517 return (CAM_REQ_CMP_ERR
);
1521 kprintf("saregister: no getdev CCB, can't register device\n");
1522 return (CAM_REQ_CMP_ERR
);
1525 softc
= kmalloc(sizeof (*softc
), M_SCSISA
, M_INTWAIT
| M_ZERO
);
1526 softc
->scsi_rev
= SID_ANSI_REV(&cgd
->inq_data
);
1527 softc
->state
= SA_STATE_NORMAL
;
1528 softc
->fileno
= (daddr_t
) -1;
1529 softc
->blkno
= (daddr_t
) -1;
1531 bioq_init(&softc
->bio_queue
);
1532 periph
->softc
= softc
;
1533 cam_extend_set(saperiphs
, periph
->unit_number
, periph
);
1536 * See if this device has any quirks.
1538 match
= cam_quirkmatch((caddr_t
)&cgd
->inq_data
,
1539 (caddr_t
)sa_quirk_table
,
1540 sizeof(sa_quirk_table
)/sizeof(*sa_quirk_table
),
1541 sizeof(*sa_quirk_table
), scsi_inquiry_match
);
1543 if (match
!= NULL
) {
1544 softc
->quirks
= ((struct sa_quirk_entry
*)match
)->quirks
;
1545 softc
->last_media_blksize
=
1546 ((struct sa_quirk_entry
*)match
)->prefblk
;
1548 xpt_print_path(periph
->path
);
1549 kprintf("found quirk entry %d\n", (int)
1550 (((struct sa_quirk_entry
*) match
) - sa_quirk_table
));
1553 softc
->quirks
= SA_QUIRK_NONE
;
1556 * The SA driver supports a blocksize, but we don't know the
1557 * blocksize until we media is inserted. So, set a flag to
1558 * indicate that the blocksize is unavailable right now.
1560 devstat_add_entry(&softc
->device_stats
, "sa", periph
->unit_number
, 0,
1561 DEVSTAT_BS_UNAVAILABLE
, SID_TYPE(&cgd
->inq_data
) |
1562 DEVSTAT_TYPE_IF_SCSI
, DEVSTAT_PRIORITY_TAPE
);
1564 dev_ops_add(&sa_ops
, SA_UNITMASK
, SA_UNIT(periph
->unit_number
));
1565 make_dev(&sa_ops
, SAMINOR(SA_CTLDEV
,
1566 periph
->unit_number
, 0, SA_ATYPE_R
), UID_ROOT
, GID_OPERATOR
,
1567 0660, "%s%d.ctl", periph
->periph_name
, periph
->unit_number
);
1569 make_dev(&sa_ops
, SAMINOR(SA_NOT_CTLDEV
,
1570 periph
->unit_number
, 0, SA_ATYPE_R
), UID_ROOT
, GID_OPERATOR
,
1571 0660, "%s%d", periph
->periph_name
, periph
->unit_number
);
1573 make_dev(&sa_ops
, SAMINOR(SA_NOT_CTLDEV
,
1574 periph
->unit_number
, 0, SA_ATYPE_NR
), UID_ROOT
, GID_OPERATOR
,
1575 0660, "n%s%d", periph
->periph_name
, periph
->unit_number
);
1577 make_dev(&sa_ops
, SAMINOR(SA_NOT_CTLDEV
,
1578 periph
->unit_number
, 0, SA_ATYPE_ER
), UID_ROOT
, GID_OPERATOR
,
1579 0660, "e%s%d", periph
->periph_name
, periph
->unit_number
);
1581 for (i
= 0; i
< SA_NUM_MODES
; i
++) {
1584 SAMINOR(SA_NOT_CTLDEV
, periph
->unit_number
, i
, SA_ATYPE_R
),
1585 UID_ROOT
, GID_OPERATOR
, 0660, "%s%d.%d",
1586 periph
->periph_name
, periph
->unit_number
, i
);
1589 SAMINOR(SA_NOT_CTLDEV
, periph
->unit_number
, i
, SA_ATYPE_NR
),
1590 UID_ROOT
, GID_OPERATOR
, 0660, "n%s%d.%d",
1591 periph
->periph_name
, periph
->unit_number
, i
);
1595 SAMINOR(SA_NOT_CTLDEV
, periph
->unit_number
, i
, SA_ATYPE_ER
),
1596 UID_ROOT
, GID_OPERATOR
, 0660, "e%s%d.%d",
1597 periph
->periph_name
, periph
->unit_number
, i
);
1601 * Add an async callback so that we get
1602 * notified if this device goes away.
1604 xpt_setup_ccb(&csa
.ccb_h
, periph
->path
, /* priority */ 5);
1605 csa
.ccb_h
.func_code
= XPT_SASYNC_CB
;
1606 csa
.event_enable
= AC_LOST_DEVICE
;
1607 csa
.callback
= saasync
;
1608 csa
.callback_arg
= periph
;
1609 xpt_action((union ccb
*)&csa
);
1611 xpt_announce_periph(periph
, NULL
);
1613 return (CAM_REQ_CMP
);
1617 sastart(struct cam_periph
*periph
, union ccb
*start_ccb
)
1619 struct sa_softc
*softc
;
1621 softc
= (struct sa_softc
*)periph
->softc
;
1623 CAM_DEBUG(periph
->path
, CAM_DEBUG_TRACE
, ("sastart\n"));
1626 switch (softc
->state
) {
1627 case SA_STATE_NORMAL
:
1629 /* Pull a buffer from the queue and get going on it */
1634 * See if there is a buf with work for us to do..
1637 bio
= bioq_first(&softc
->bio_queue
);
1638 if (periph
->immediate_priority
<= periph
->pinfo
.priority
) {
1639 CAM_DEBUG_PRINT(CAM_DEBUG_SUBTRACE
,
1640 ("queuing for immediate ccb\n"));
1641 Set_CCB_Type(start_ccb
, SA_CCB_WAITING
);
1642 SLIST_INSERT_HEAD(&periph
->ccb_list
, &start_ccb
->ccb_h
,
1644 periph
->immediate_priority
= CAM_PRIORITY_NONE
;
1646 wakeup(&periph
->ccb_list
);
1647 } else if (bio
== NULL
) {
1649 xpt_release_ccb(start_ccb
);
1650 } else if ((softc
->flags
& SA_FLAG_ERR_PENDING
) != 0) {
1651 struct bio
*done_bio
;
1653 softc
->queue_count
--;
1654 bioq_remove(&softc
->bio_queue
, bio
);
1656 bp
->b_resid
= bp
->b_bcount
;
1658 if ((softc
->flags
& SA_FLAG_EOM_PENDING
) != 0) {
1660 * We now just clear errors in this case
1661 * and let the residual be the notifier.
1664 } else if ((softc
->flags
& SA_FLAG_EOF_PENDING
) != 0) {
1666 * This can only happen if we're reading
1667 * in fixed length mode. In this case,
1668 * we dump the rest of the list the
1672 if (bioq_first(&softc
->bio_queue
) != NULL
) {
1676 } else if ((softc
->flags
& SA_FLAG_EIO_PENDING
) != 0) {
1678 bp
->b_flags
|= B_ERROR
;
1680 bio
= bioq_first(&softc
->bio_queue
);
1682 * Only if we have no other buffers queued up
1683 * do we clear the pending error flag.
1686 softc
->flags
&= ~SA_FLAG_ERR_PENDING
;
1687 CAM_DEBUG(periph
->path
, CAM_DEBUG_INFO
,
1688 ("sastart- ERR_PENDING now 0x%x, bio is %sNULL, "
1689 "%d more buffers queued up\n",
1690 (softc
->flags
& SA_FLAG_ERR_PENDING
),
1691 (bio
!= NULL
)? "not " : " ", softc
->queue_count
));
1693 xpt_release_ccb(start_ccb
);
1698 bioq_remove(&softc
->bio_queue
, bio
);
1700 softc
->queue_count
--;
1702 if ((softc
->flags
& SA_FLAG_FIXED
) != 0) {
1703 if (softc
->blk_shift
!= 0) {
1705 bp
->b_bcount
>> softc
->blk_shift
;
1706 } else if (softc
->media_blksize
!= 0) {
1708 bp
->b_bcount
/ softc
->media_blksize
;
1711 xpt_print_path(periph
->path
);
1712 kprintf("zero blocksize for "
1713 "FIXED length writes?\n");
1719 CAM_DEBUG(start_ccb
->ccb_h
.path
, CAM_DEBUG_INFO
,
1720 ("issuing a %d fixed record %s\n",
1721 length
, (bp
->bio_cmd
== BIO_READ
)? "read" :
1725 length
= bp
->b_bcount
;
1727 CAM_DEBUG(start_ccb
->ccb_h
.path
, CAM_DEBUG_INFO
,
1728 ("issuing a %d variable byte %s\n",
1729 length
, (bp
->bio_cmd
== BIO_READ
)? "read" :
1733 devstat_start_transaction(&softc
->device_stats
);
1735 * Some people have theorized that we should
1736 * suppress illegal length indication if we are
1737 * running in variable block mode so that we don't
1738 * have to request sense every time our requested
1739 * block size is larger than the written block.
1740 * The residual information from the ccb allows
1741 * us to identify this situation anyway. The only
1742 * problem with this is that we will not get
1743 * information about blocks that are larger than
1744 * our read buffer unless we set the block size
1745 * in the mode page to something other than 0.
1747 * I believe that this is a non-issue. If user apps
1748 * don't adjust their read size to match our record
1749 * size, that's just life. Anyway, the typical usage
1750 * would be to issue, e.g., 64KB reads and occasionally
1751 * have to do deal with 512 byte or 1KB intermediate
1754 softc
->dsreg
= (bp
->b_cmd
== BUF_CMD_READ
) ?
1755 MTIO_DSREG_RD
: MTIO_DSREG_WR
;
1756 scsi_sa_read_write(&start_ccb
->csio
, 0, sadone
,
1757 MSG_SIMPLE_Q_TAG
, (bp
->b_cmd
== BUF_CMD_READ
) != 0,
1758 FALSE
, (softc
->flags
& SA_FLAG_FIXED
) != 0,
1759 length
, bp
->b_data
, bp
->b_bcount
, SSD_FULL_SIZE
,
1761 start_ccb
->ccb_h
.ccb_pflags
&= ~SA_POSITION_UPDATED
;
1762 Set_CCB_Type(start_ccb
, SA_CCB_BUFFER_IO
);
1763 start_ccb
->ccb_h
.ccb_bio
= bio
;
1764 bio
= bioq_first(&softc
->bio_queue
);
1766 xpt_action(start_ccb
);
1770 /* Have more work to do, so ensure we stay scheduled */
1771 xpt_schedule(periph
, 1);
1775 case SA_STATE_ABNORMAL
:
1777 panic("state 0x%x in sastart", softc
->state
);
1784 sadone(struct cam_periph
*periph
, union ccb
*done_ccb
)
1786 struct sa_softc
*softc
;
1787 struct ccb_scsiio
*csio
;
1789 softc
= (struct sa_softc
*)periph
->softc
;
1790 csio
= &done_ccb
->csio
;
1791 switch (CCB_Type(csio
)) {
1792 case SA_CCB_BUFFER_IO
:
1798 softc
->dsreg
= MTIO_DSREG_REST
;
1799 bio
= (struct bio
*)done_ccb
->ccb_h
.ccb_bio
;
1802 if ((done_ccb
->ccb_h
.status
& CAM_STATUS_MASK
) != CAM_REQ_CMP
) {
1803 if ((error
= saerror(done_ccb
, 0, 0)) == ERESTART
) {
1805 * A retry was scheduled, so just return.
1816 * Catastrophic error. Mark the tape as frozen
1817 * (we no longer know tape position).
1819 * Return all queued I/O with EIO, and unfreeze
1820 * our queue so that future transactions that
1821 * attempt to fix this problem can get to the
1827 softc
->flags
|= SA_FLAG_TAPE_FROZEN
;
1828 while ((q_bio
= bioq_first(&softc
->bio_queue
)) != NULL
) {
1829 bioq_remove(&softc
->bio_queue
, q_bio
);
1830 q_bp
= q_bio
->bio_buf
;
1831 q_bp
->b_resid
= q_bp
->b_bcount
;
1832 q_bp
->b_error
= EIO
;
1833 q_bp
->b_flags
|= B_ERROR
;
1839 bp
->b_resid
= bp
->b_bcount
;
1840 bp
->b_error
= error
;
1841 bp
->b_flags
|= B_ERROR
;
1843 * In the error case, position is updated in saerror.
1846 bp
->b_resid
= csio
->resid
;
1848 if (csio
->resid
!= 0) {
1849 bp
->b_flags
|= B_ERROR
;
1851 if (bp
->b_cmd
!= BUF_CMD_READ
) {
1852 softc
->flags
|= SA_FLAG_TAPE_WRITTEN
;
1853 softc
->filemarks
= 0;
1855 if (!(csio
->ccb_h
.ccb_pflags
& SA_POSITION_UPDATED
) &&
1856 (softc
->blkno
!= (daddr_t
) -1)) {
1857 if ((softc
->flags
& SA_FLAG_FIXED
) != 0) {
1859 if (softc
->blk_shift
!= 0) {
1864 softc
->media_blksize
;
1866 softc
->blkno
+= (daddr_t
) l
;
1873 * If we had an error (immediate or pending),
1874 * release the device queue now.
1876 if (error
|| (softc
->flags
& SA_FLAG_ERR_PENDING
))
1877 cam_release_devq(done_ccb
->ccb_h
.path
, 0, 0, 0, 0);
1879 if (error
|| bp
->b_resid
) {
1880 CAM_DEBUG(periph
->path
, CAM_DEBUG_INFO
,
1881 ("error %d resid %d count %d\n", error
,
1882 bp
->b_resid
, bp
->b_bcount
));
1885 devstat_end_transaction_buf(&softc
->device_stats
, bp
);
1889 case SA_CCB_WAITING
:
1891 /* Caller will release the CCB */
1892 wakeup(&done_ccb
->ccb_h
.cbfcnp
);
1896 xpt_release_ccb(done_ccb
);
1900 * Mount the tape (make sure it's ready for I/O).
1903 samount(struct cam_periph
*periph
, int oflags
, cdev_t dev
)
1905 struct sa_softc
*softc
;
1910 * oflags can be checked for 'kind' of open (read-only check) - later
1911 * dev can be checked for a control-mode or compression open - later
1913 UNUSED_PARAMETER(oflags
);
1914 UNUSED_PARAMETER(dev
);
1917 softc
= (struct sa_softc
*)periph
->softc
;
1920 * This should determine if something has happend since the last
1921 * open/mount that would invalidate the mount. We do *not* want
1922 * to retry this command- we just want the status. But we only
1923 * do this if we're mounted already- if we're not mounted,
1924 * we don't care about the unit read state and can instead use
1925 * this opportunity to attempt to reserve the tape unit.
1928 if (softc
->flags
& SA_FLAG_TAPE_MOUNTED
) {
1929 ccb
= cam_periph_getccb(periph
, 1);
1930 scsi_test_unit_ready(&ccb
->csio
, 0, sadone
,
1931 MSG_SIMPLE_Q_TAG
, SSD_FULL_SIZE
, IO_TIMEOUT
);
1932 error
= cam_periph_runccb(ccb
, saerror
, 0, SF_NO_PRINT
,
1933 &softc
->device_stats
);
1935 if (error
== ENXIO
) {
1936 softc
->flags
&= ~SA_FLAG_TAPE_MOUNTED
;
1937 scsi_test_unit_ready(&ccb
->csio
, 0, sadone
,
1938 MSG_SIMPLE_Q_TAG
, SSD_FULL_SIZE
, IO_TIMEOUT
);
1939 error
= cam_periph_runccb(ccb
, saerror
, 0, SF_NO_PRINT
,
1940 &softc
->device_stats
);
1944 * We don't need to freeze the tape because we
1945 * will now attempt to rewind/load it.
1947 softc
->flags
&= ~SA_FLAG_TAPE_MOUNTED
;
1948 if (CAM_DEBUGGED(periph
->path
, CAM_DEBUG_INFO
)) {
1949 xpt_print_path(periph
->path
);
1950 kprintf("error %d on TUR in samount\n", error
);
1954 error
= sareservereleaseunit(periph
, TRUE
);
1958 ccb
= cam_periph_getccb(periph
, 1);
1959 scsi_test_unit_ready(&ccb
->csio
, 0, sadone
,
1960 MSG_SIMPLE_Q_TAG
, SSD_FULL_SIZE
, IO_TIMEOUT
);
1961 error
= cam_periph_runccb(ccb
, saerror
, 0, SF_NO_PRINT
,
1962 &softc
->device_stats
);
1966 if ((softc
->flags
& SA_FLAG_TAPE_MOUNTED
) == 0) {
1967 struct scsi_read_block_limits_data
*rblim
= NULL
;
1968 int comp_enabled
, comp_supported
;
1969 u_int8_t write_protect
, guessing
= 0;
1972 * Clear out old state.
1974 softc
->flags
&= ~(SA_FLAG_TAPE_WP
|SA_FLAG_TAPE_WRITTEN
|
1975 SA_FLAG_ERR_PENDING
|SA_FLAG_COMP_ENABLED
|
1976 SA_FLAG_COMP_SUPP
|SA_FLAG_COMP_UNSUPP
);
1977 softc
->filemarks
= 0;
1980 * *Very* first off, make sure we're loaded to BOT.
1982 scsi_load_unload(&ccb
->csio
, 2, sadone
, MSG_SIMPLE_Q_TAG
, FALSE
,
1983 FALSE
, FALSE
, 1, SSD_FULL_SIZE
, REWIND_TIMEOUT
);
1984 error
= cam_periph_runccb(ccb
, saerror
, 0, SF_NO_PRINT
,
1985 &softc
->device_stats
);
1989 * In case this doesn't work, do a REWIND instead
1992 scsi_rewind(&ccb
->csio
, 2, sadone
, MSG_SIMPLE_Q_TAG
,
1993 FALSE
, SSD_FULL_SIZE
, REWIND_TIMEOUT
);
1994 error
= cam_periph_runccb(ccb
, saerror
, 0, SF_NO_PRINT
,
1995 &softc
->device_stats
);
1999 xpt_release_ccb(ccb
);
2004 * Do a dummy test read to force access to the
2005 * media so that the drive will really know what's
2006 * there. We actually don't really care what the
2007 * blocksize on tape is and don't expect to really
2008 * read a full record.
2010 rblim
= kmalloc(8192, M_TEMP
, M_INTWAIT
);
2012 if ((softc
->quirks
& SA_QUIRK_NODREAD
) == 0) {
2013 scsi_sa_read_write(&ccb
->csio
, 0, sadone
,
2014 MSG_SIMPLE_Q_TAG
, 1, FALSE
, 0, 8192,
2015 (void *) rblim
, 8192, SSD_FULL_SIZE
,
2017 cam_periph_runccb(ccb
, saerror
, 0, SF_NO_PRINT
,
2018 &softc
->device_stats
);
2020 scsi_rewind(&ccb
->csio
, 1, sadone
, MSG_SIMPLE_Q_TAG
,
2021 FALSE
, SSD_FULL_SIZE
, REWIND_TIMEOUT
);
2022 error
= cam_periph_runccb(ccb
, saerror
, CAM_RETRY_SELTO
,
2023 SF_NO_PRINT
| SF_RETRY_UA
,
2024 &softc
->device_stats
);
2027 xpt_print_path(periph
->path
);
2028 kprintf("unable to rewind after test read\n");
2029 xpt_release_ccb(ccb
);
2035 * Next off, determine block limits.
2037 scsi_read_block_limits(&ccb
->csio
, 5, sadone
, MSG_SIMPLE_Q_TAG
,
2038 rblim
, SSD_FULL_SIZE
, SCSIOP_TIMEOUT
);
2040 error
= cam_periph_runccb(ccb
, saerror
, CAM_RETRY_SELTO
,
2041 SF_NO_PRINT
| SF_RETRY_UA
, &softc
->device_stats
);
2044 xpt_release_ccb(ccb
);
2048 * If it's less than SCSI-2, READ BLOCK LIMITS is not
2049 * a MANDATORY command. Anyway- it doesn't matter-
2050 * we can proceed anyway.
2052 softc
->blk_gran
= 0;
2053 softc
->max_blk
= ~0;
2056 if (softc
->scsi_rev
>= SCSI_REV_SPC
) {
2057 softc
->blk_gran
= RBL_GRAN(rblim
);
2059 softc
->blk_gran
= 0;
2062 * We take max_blk == min_blk to mean a default to
2063 * fixed mode- but note that whatever we get out of
2064 * sagetparams below will actually determine whether
2065 * we are actually *in* fixed mode.
2067 softc
->max_blk
= scsi_3btoul(rblim
->maximum
);
2068 softc
->min_blk
= scsi_2btoul(rblim
->minimum
);
2073 * Next, perform a mode sense to determine
2074 * current density, blocksize, compression etc.
2076 error
= sagetparams(periph
, SA_PARAM_ALL
,
2077 &softc
->media_blksize
,
2078 &softc
->media_density
,
2079 &softc
->media_numblks
,
2080 &softc
->buffer_mode
, &write_protect
,
2081 &softc
->speed
, &comp_supported
,
2082 &comp_enabled
, &softc
->comp_algorithm
,
2087 * We could work a little harder here. We could
2088 * adjust our attempts to get information. It
2089 * might be an ancient tape drive. If someone
2090 * nudges us, we'll do that.
2096 * If no quirk has determined that this is a device that is
2097 * preferred to be in fixed or variable mode, now is the time
2100 if ((softc
->quirks
& (SA_QUIRK_FIXED
|SA_QUIRK_VARIABLE
)) == 0) {
2103 * This could be expensive to find out. Luckily we
2104 * only need to do this once. If we start out in
2105 * 'default' mode, try and set ourselves to one
2106 * of the densities that would determine a wad
2107 * of other stuff. Go from highest to lowest.
2109 if (softc
->media_density
== SCSI_DEFAULT_DENSITY
) {
2111 static u_int8_t ctry
[] = {
2112 SCSI_DENSITY_HALFINCH_PE
,
2113 SCSI_DENSITY_HALFINCH_6250C
,
2114 SCSI_DENSITY_HALFINCH_6250
,
2115 SCSI_DENSITY_HALFINCH_1600
,
2116 SCSI_DENSITY_HALFINCH_800
,
2117 SCSI_DENSITY_QIC_4GB
,
2118 SCSI_DENSITY_QIC_2GB
,
2119 SCSI_DENSITY_QIC_525_320
,
2120 SCSI_DENSITY_QIC_150
,
2121 SCSI_DENSITY_QIC_120
,
2122 SCSI_DENSITY_QIC_24
,
2123 SCSI_DENSITY_QIC_11_9TRK
,
2124 SCSI_DENSITY_QIC_11_4TRK
,
2125 SCSI_DENSITY_QIC_1320
,
2126 SCSI_DENSITY_QIC_3080
,
2129 for (i
= 0; ctry
[i
]; i
++) {
2130 error
= sasetparams(periph
,
2131 SA_PARAM_DENSITY
, 0, ctry
[i
],
2134 softc
->media_density
= ctry
[i
];
2139 switch (softc
->media_density
) {
2140 case SCSI_DENSITY_QIC_11_4TRK
:
2141 case SCSI_DENSITY_QIC_11_9TRK
:
2142 case SCSI_DENSITY_QIC_24
:
2143 case SCSI_DENSITY_QIC_120
:
2144 case SCSI_DENSITY_QIC_150
:
2145 case SCSI_DENSITY_QIC_525_320
:
2146 case SCSI_DENSITY_QIC_1320
:
2147 case SCSI_DENSITY_QIC_3080
:
2148 softc
->quirks
&= ~SA_QUIRK_2FM
;
2149 softc
->quirks
|= SA_QUIRK_FIXED
|SA_QUIRK_1FM
;
2150 softc
->last_media_blksize
= 512;
2152 case SCSI_DENSITY_QIC_4GB
:
2153 case SCSI_DENSITY_QIC_2GB
:
2154 softc
->quirks
&= ~SA_QUIRK_2FM
;
2155 softc
->quirks
|= SA_QUIRK_FIXED
|SA_QUIRK_1FM
;
2156 softc
->last_media_blksize
= 1024;
2159 softc
->last_media_blksize
=
2160 softc
->media_blksize
;
2161 softc
->quirks
|= SA_QUIRK_VARIABLE
;
2167 * If no quirk has determined that this is a device that needs
2168 * to have 2 Filemarks at EOD, now is the time to find out.
2171 if ((softc
->quirks
& SA_QUIRK_2FM
) == 0) {
2172 switch (softc
->media_density
) {
2173 case SCSI_DENSITY_HALFINCH_800
:
2174 case SCSI_DENSITY_HALFINCH_1600
:
2175 case SCSI_DENSITY_HALFINCH_6250
:
2176 case SCSI_DENSITY_HALFINCH_6250C
:
2177 case SCSI_DENSITY_HALFINCH_PE
:
2178 softc
->quirks
&= ~SA_QUIRK_1FM
;
2179 softc
->quirks
|= SA_QUIRK_2FM
;
2187 * Now validate that some info we got makes sense.
2189 if ((softc
->max_blk
< softc
->media_blksize
) ||
2190 (softc
->min_blk
> softc
->media_blksize
&&
2191 softc
->media_blksize
)) {
2192 xpt_print_path(periph
->path
);
2193 kprintf("BLOCK LIMITS (%d..%d) could not match current "
2194 "block settings (%d)- adjusting\n", softc
->min_blk
,
2195 softc
->max_blk
, softc
->media_blksize
);
2196 softc
->max_blk
= softc
->min_blk
=
2197 softc
->media_blksize
;
2201 * Now put ourselves into the right frame of mind based
2206 * If we want to be in FIXED mode and our current blocksize
2207 * is not equal to our last blocksize (if nonzero), try and
2208 * set ourselves to this last blocksize (as the 'preferred'
2209 * block size). The initial quirkmatch at registry sets the
2210 * initial 'last' blocksize. If, for whatever reason, this
2211 * 'last' blocksize is zero, set the blocksize to 512,
2212 * or min_blk if that's larger.
2214 if ((softc
->quirks
& SA_QUIRK_FIXED
) &&
2215 (softc
->quirks
& SA_QUIRK_NO_MODESEL
) == 0 &&
2216 (softc
->media_blksize
!= softc
->last_media_blksize
)) {
2217 softc
->media_blksize
= softc
->last_media_blksize
;
2218 if (softc
->media_blksize
== 0) {
2219 softc
->media_blksize
= 512;
2220 if (softc
->media_blksize
< softc
->min_blk
) {
2221 softc
->media_blksize
= softc
->min_blk
;
2224 error
= sasetparams(periph
, SA_PARAM_BLOCKSIZE
,
2225 softc
->media_blksize
, 0, 0, SF_NO_PRINT
);
2227 xpt_print_path(periph
->path
);
2228 kprintf("unable to set fixed blocksize to %d\n",
2229 softc
->media_blksize
);
2234 if ((softc
->quirks
& SA_QUIRK_VARIABLE
) &&
2235 (softc
->media_blksize
!= 0)) {
2236 softc
->last_media_blksize
= softc
->media_blksize
;
2237 softc
->media_blksize
= 0;
2238 error
= sasetparams(periph
, SA_PARAM_BLOCKSIZE
,
2239 0, 0, 0, SF_NO_PRINT
);
2242 * If this fails and we were guessing, just
2243 * assume that we got it wrong and go try
2244 * fixed block mode. Don't even check against
2245 * density code at this point.
2248 softc
->quirks
&= ~SA_QUIRK_VARIABLE
;
2249 softc
->quirks
|= SA_QUIRK_FIXED
;
2250 if (softc
->last_media_blksize
== 0)
2251 softc
->last_media_blksize
= 512;
2254 xpt_print_path(periph
->path
);
2255 kprintf("unable to set variable blocksize\n");
2261 * Now that we have the current block size,
2262 * set up some parameters for sastart's usage.
2264 if (softc
->media_blksize
) {
2265 softc
->flags
|= SA_FLAG_FIXED
;
2266 if (powerof2(softc
->media_blksize
)) {
2268 ffs(softc
->media_blksize
) - 1;
2269 softc
->blk_mask
= softc
->media_blksize
- 1;
2271 softc
->blk_mask
= ~0;
2272 softc
->blk_shift
= 0;
2276 * The SCSI-3 spec allows 0 to mean "unspecified".
2277 * The SCSI-1 spec allows 0 to mean 'infinite'.
2279 * Either works here.
2281 if (softc
->max_blk
== 0) {
2282 softc
->max_blk
= ~0;
2284 softc
->blk_shift
= 0;
2285 if (softc
->blk_gran
!= 0) {
2286 softc
->blk_mask
= softc
->blk_gran
- 1;
2288 softc
->blk_mask
= 0;
2293 softc
->flags
|= SA_FLAG_TAPE_WP
;
2295 if (comp_supported
) {
2296 if (softc
->saved_comp_algorithm
== 0)
2297 softc
->saved_comp_algorithm
=
2298 softc
->comp_algorithm
;
2299 softc
->flags
|= SA_FLAG_COMP_SUPP
;
2301 softc
->flags
|= SA_FLAG_COMP_ENABLED
;
2303 softc
->flags
|= SA_FLAG_COMP_UNSUPP
;
2305 if ((softc
->buffer_mode
== SMH_SA_BUF_MODE_NOBUF
) &&
2306 (softc
->quirks
& SA_QUIRK_NO_MODESEL
) == 0) {
2307 error
= sasetparams(periph
, SA_PARAM_BUFF_MODE
, 0,
2310 softc
->buffer_mode
= SMH_SA_BUF_MODE_SIBUF
;
2312 xpt_print_path(periph
->path
);
2313 kprintf("unable to set buffered mode\n");
2315 error
= 0; /* not an error */
2320 softc
->flags
|= SA_FLAG_TAPE_MOUNTED
;
2324 kfree(rblim
, M_TEMP
);
2327 softc
->dsreg
= MTIO_DSREG_NIL
;
2329 softc
->fileno
= softc
->blkno
= 0;
2330 softc
->dsreg
= MTIO_DSREG_REST
;
2332 #ifdef SA_1FM_AT_EOD
2333 if ((softc
->quirks
& SA_QUIRK_2FM
) == 0)
2334 softc
->quirks
|= SA_QUIRK_1FM
;
2336 if ((softc
->quirks
& SA_QUIRK_1FM
) == 0)
2337 softc
->quirks
|= SA_QUIRK_2FM
;
2340 xpt_release_ccb(ccb
);
2343 * If we return an error, we're not mounted any more,
2344 * so release any device reservation.
2347 sareservereleaseunit(periph
, FALSE
);
2350 * Clear I/O residual.
2352 softc
->last_io_resid
= 0;
2353 softc
->last_ctl_resid
= 0;
2359 * How many filemarks do we need to write if we were to terminate the
2360 * tape session right now? Note that this can be a negative number
2364 samarkswanted(struct cam_periph
*periph
)
2367 struct sa_softc
*softc
;
2369 softc
= (struct sa_softc
*)periph
->softc
;
2371 if ((softc
->flags
& SA_FLAG_TAPE_WRITTEN
) != 0) {
2373 if (softc
->quirks
& SA_QUIRK_2FM
)
2376 markswanted
-= softc
->filemarks
;
2377 return (markswanted
);
2381 sacheckeod(struct cam_periph
*periph
)
2386 markswanted
= samarkswanted(periph
);
2388 if (markswanted
> 0) {
2389 error
= sawritefilemarks(periph
, markswanted
, FALSE
);
2397 saerror(union ccb
*ccb
, u_int32_t cflgs
, u_int32_t sflgs
)
2399 static const char *toobig
=
2400 "%d-byte tape record bigger than supplied buffer\n";
2401 struct cam_periph
*periph
;
2402 struct sa_softc
*softc
;
2403 struct ccb_scsiio
*csio
;
2404 struct scsi_sense_data
*sense
;
2405 u_int32_t resid
= 0;
2408 int error_code
, sense_key
, asc
, ascq
, error
, aqvalid
;
2410 periph
= xpt_path_periph(ccb
->ccb_h
.path
);
2411 softc
= (struct sa_softc
*)periph
->softc
;
2413 sense
= &csio
->sense_data
;
2414 scsi_extract_sense(sense
, &error_code
, &sense_key
, &asc
, &ascq
);
2415 aqvalid
= sense
->extra_len
>= 6;
2418 status
= csio
->ccb_h
.status
& CAM_STATUS_MASK
;
2421 * Calculate/latch up, any residuals... We do this in a funny 2-step
2422 * so we can print stuff here if we have CAM_DEBUG enabled for this
2425 if (status
== CAM_SCSI_STATUS_ERROR
) {
2426 if ((sense
->error_code
& SSD_ERRCODE_VALID
) != 0) {
2427 info
= (int32_t) scsi_4btoul(sense
->info
);
2429 if ((softc
->flags
& SA_FLAG_FIXED
) != 0)
2430 resid
*= softc
->media_blksize
;
2432 resid
= csio
->dxfer_len
;
2434 if ((softc
->flags
& SA_FLAG_FIXED
) != 0) {
2435 if (softc
->media_blksize
)
2436 info
/= softc
->media_blksize
;
2439 if (CCB_Type(csio
) == SA_CCB_BUFFER_IO
) {
2440 bcopy((caddr_t
) sense
, (caddr_t
) &softc
->last_io_sense
,
2441 sizeof (struct scsi_sense_data
));
2442 bcopy(csio
->cdb_io
.cdb_bytes
, softc
->last_io_cdb
,
2443 (int) csio
->cdb_len
);
2444 softc
->last_io_resid
= resid
;
2445 softc
->last_resid_was_io
= 1;
2447 bcopy((caddr_t
) sense
, (caddr_t
) &softc
->last_ctl_sense
,
2448 sizeof (struct scsi_sense_data
));
2449 bcopy(csio
->cdb_io
.cdb_bytes
, softc
->last_ctl_cdb
,
2450 (int) csio
->cdb_len
);
2451 softc
->last_ctl_resid
= resid
;
2452 softc
->last_resid_was_io
= 0;
2454 CAM_DEBUG(periph
->path
, CAM_DEBUG_INFO
, ("CDB[0]=0x%x Key 0x%x "
2455 "ASC/ASCQ 0x%x/0x%x CAM STATUS 0x%x flags 0x%x resid %d "
2456 "dxfer_len %d\n", csio
->cdb_io
.cdb_bytes
[0] & 0xff,
2457 sense_key
, asc
, ascq
, status
,
2458 sense
->flags
& ~SSD_KEY_RESERVED
, resid
, csio
->dxfer_len
));
2460 CAM_DEBUG(periph
->path
, CAM_DEBUG_INFO
,
2461 ("Cam Status 0x%x\n", status
));
2467 case CAM_SCSI_STATUS_ERROR
:
2469 * If a read/write command, we handle it here.
2471 if (CCB_Type(csio
) != SA_CCB_WAITING
) {
2475 * If this was just EOM/EOP, Filemark, Setmark or ILI detected
2476 * on a non read/write command, we assume it's not an error
2477 * and propagate the residule and return.
2479 if ((aqvalid
&& asc
== 0 && ascq
> 0 && ascq
<= 5) ||
2480 (aqvalid
== 0 && sense_key
== SSD_KEY_NO_SENSE
)) {
2481 csio
->resid
= resid
;
2486 * Otherwise, we let the common code handle this.
2488 return (cam_periph_error(ccb
, cflgs
, sflgs
, &softc
->saved_ccb
));
2492 * We cannot depend upon CAM honoring retry counts for these.
2494 case CAM_SCSI_BUS_RESET
:
2496 if (ccb
->ccb_h
.retry_count
<= 0) {
2501 return (cam_periph_error(ccb
, cflgs
, sflgs
, &softc
->saved_ccb
));
2505 * Handle filemark, end of tape, mismatched record sizes....
2506 * From this point out, we're only handling read/write cases.
2507 * Handle writes && reads differently.
2510 if (csio
->cdb_io
.cdb_bytes
[0] == SA_WRITE
) {
2511 if (sense_key
== SSD_KEY_VOLUME_OVERFLOW
) {
2512 csio
->resid
= resid
;
2514 } else if (sense
->flags
& SSD_EOM
) {
2515 softc
->flags
|= SA_FLAG_EOM_PENDING
;
2517 * Grotesque as it seems, the few times
2518 * I've actually seen a non-zero resid,
2519 * the tape drive actually lied and had
2520 * written all the data!.
2525 csio
->resid
= resid
;
2526 if (sense_key
== SSD_KEY_BLANK_CHECK
) {
2527 if (softc
->quirks
& SA_QUIRK_1FM
) {
2529 softc
->flags
|= SA_FLAG_EOM_PENDING
;
2533 } else if (sense
->flags
& SSD_FILEMARK
) {
2534 if (softc
->flags
& SA_FLAG_FIXED
) {
2536 softc
->flags
|= SA_FLAG_EOF_PENDING
;
2539 * Unconditionally, if we detected a filemark on a read,
2540 * mark that we've run moved a file ahead.
2542 if (softc
->fileno
!= (daddr_t
) -1) {
2545 csio
->ccb_h
.ccb_pflags
|= SA_POSITION_UPDATED
;
2551 * Incorrect Length usually applies to read, but can apply to writes.
2553 if (error
== 0 && (sense
->flags
& SSD_ILI
)) {
2555 xpt_print_path(csio
->ccb_h
.path
);
2556 kprintf(toobig
, csio
->dxfer_len
- info
);
2557 csio
->resid
= csio
->dxfer_len
;
2560 csio
->resid
= resid
;
2561 if (softc
->flags
& SA_FLAG_FIXED
) {
2562 softc
->flags
|= SA_FLAG_EIO_PENDING
;
2565 * Bump the block number if we hadn't seen a filemark.
2566 * Do this independent of errors (we've moved anyway).
2568 if ((sense
->flags
& SSD_FILEMARK
) == 0) {
2569 if (softc
->blkno
!= (daddr_t
) -1) {
2571 csio
->ccb_h
.ccb_pflags
|=
2572 SA_POSITION_UPDATED
;
2580 * Unfreeze the queue if frozen as we're not returning anything
2581 * to our waiters that would indicate an I/O error has occurred
2591 sagetparams(struct cam_periph
*periph
, sa_params params_to_get
,
2592 u_int32_t
*blocksize
, u_int8_t
*density
, u_int32_t
*numblocks
,
2593 int *buff_mode
, u_int8_t
*write_protect
, u_int8_t
*speed
,
2594 int *comp_supported
, int *comp_enabled
, u_int32_t
*comp_algorithm
,
2599 struct scsi_mode_header_6
*mode_hdr
;
2600 struct scsi_mode_blk_desc
*mode_blk
;
2601 int mode_buffer_len
;
2602 struct sa_softc
*softc
;
2607 softc
= (struct sa_softc
*)periph
->softc
;
2608 ccb
= cam_periph_getccb(periph
, 1);
2609 if (softc
->quirks
& SA_QUIRK_NO_CPAGE
)
2610 cpage
= SA_DEVICE_CONFIGURATION_PAGE
;
2612 cpage
= SA_DATA_COMPRESSION_PAGE
;
2615 mode_buffer_len
= sizeof(*mode_hdr
) + sizeof(*mode_blk
);
2617 if (params_to_get
& SA_PARAM_COMPRESSION
) {
2618 if (softc
->quirks
& SA_QUIRK_NOCOMP
) {
2619 *comp_supported
= FALSE
;
2620 params_to_get
&= ~SA_PARAM_COMPRESSION
;
2622 mode_buffer_len
+= sizeof (sa_comp_t
);
2625 mode_buffer
= kmalloc(mode_buffer_len
, M_TEMP
, M_INTWAIT
| M_ZERO
);
2626 mode_hdr
= (struct scsi_mode_header_6
*)mode_buffer
;
2627 mode_blk
= (struct scsi_mode_blk_desc
*)&mode_hdr
[1];
2629 /* it is safe to retry this */
2630 scsi_mode_sense(&ccb
->csio
, 5, sadone
, MSG_SIMPLE_Q_TAG
, FALSE
,
2631 SMS_PAGE_CTRL_CURRENT
, (params_to_get
& SA_PARAM_COMPRESSION
) ?
2632 cpage
: SMS_VENDOR_SPECIFIC_PAGE
, mode_buffer
, mode_buffer_len
,
2633 SSD_FULL_SIZE
, SCSIOP_TIMEOUT
);
2635 error
= cam_periph_runccb(ccb
, saerror
, 0, SF_NO_PRINT
,
2636 &softc
->device_stats
);
2639 status
= ccb
->ccb_h
.status
& CAM_STATUS_MASK
;
2641 if (error
== EINVAL
&& (params_to_get
& SA_PARAM_COMPRESSION
) != 0) {
2643 * Hmm. Let's see if we can try another page...
2644 * If we've already done that, give up on compression
2645 * for this device and remember this for the future
2646 * and attempt the request without asking for compression
2649 if (cpage
== SA_DATA_COMPRESSION_PAGE
) {
2650 cpage
= SA_DEVICE_CONFIGURATION_PAGE
;
2653 softc
->quirks
|= SA_QUIRK_NOCOMP
;
2654 kfree(mode_buffer
, M_TEMP
);
2656 } else if (status
== CAM_SCSI_STATUS_ERROR
) {
2657 /* Tell the user about the fatal error. */
2658 scsi_sense_print(&ccb
->csio
);
2659 goto sagetparamsexit
;
2663 * If the user only wants the compression information, and
2664 * the device doesn't send back the block descriptor, it's
2665 * no big deal. If the user wants more than just
2666 * compression, though, and the device doesn't pass back the
2667 * block descriptor, we need to send another mode sense to
2668 * get the block descriptor.
2670 if ((mode_hdr
->blk_desc_len
== 0) &&
2671 (params_to_get
& SA_PARAM_COMPRESSION
) &&
2672 (params_to_get
& ~(SA_PARAM_COMPRESSION
))) {
2675 * Decrease the mode buffer length by the size of
2676 * the compression page, to make sure the data
2677 * there doesn't get overwritten.
2679 mode_buffer_len
-= sizeof (sa_comp_t
);
2682 * Now move the compression page that we presumably
2683 * got back down the memory chunk a little bit so
2684 * it doesn't get spammed.
2686 bcopy(&mode_hdr
[0], &mode_hdr
[1], sizeof (sa_comp_t
));
2687 bzero(&mode_hdr
[0], sizeof (mode_hdr
[0]));
2690 * Now, we issue another mode sense and just ask
2691 * for the block descriptor, etc.
2694 scsi_mode_sense(&ccb
->csio
, 2, sadone
, MSG_SIMPLE_Q_TAG
, FALSE
,
2695 SMS_PAGE_CTRL_CURRENT
, SMS_VENDOR_SPECIFIC_PAGE
,
2696 mode_buffer
, mode_buffer_len
, SSD_FULL_SIZE
,
2699 error
= cam_periph_runccb(ccb
, saerror
, 0, SF_NO_PRINT
,
2700 &softc
->device_stats
);
2704 goto sagetparamsexit
;
2707 if (params_to_get
& SA_PARAM_BLOCKSIZE
)
2708 *blocksize
= scsi_3btoul(mode_blk
->blklen
);
2710 if (params_to_get
& SA_PARAM_NUMBLOCKS
)
2711 *numblocks
= scsi_3btoul(mode_blk
->nblocks
);
2713 if (params_to_get
& SA_PARAM_BUFF_MODE
)
2714 *buff_mode
= mode_hdr
->dev_spec
& SMH_SA_BUF_MODE_MASK
;
2716 if (params_to_get
& SA_PARAM_DENSITY
)
2717 *density
= mode_blk
->density
;
2719 if (params_to_get
& SA_PARAM_WP
)
2720 *write_protect
= (mode_hdr
->dev_spec
& SMH_SA_WP
)? TRUE
: FALSE
;
2722 if (params_to_get
& SA_PARAM_SPEED
)
2723 *speed
= mode_hdr
->dev_spec
& SMH_SA_SPEED_MASK
;
2725 if (params_to_get
& SA_PARAM_COMPRESSION
) {
2726 sa_comp_t
*ntcs
= (sa_comp_t
*) &mode_blk
[1];
2727 if (cpage
== SA_DATA_COMPRESSION_PAGE
) {
2728 struct scsi_data_compression_page
*cp
= &ntcs
->dcomp
;
2730 (cp
->dce_and_dcc
& SA_DCP_DCC
)? TRUE
: FALSE
;
2732 (cp
->dce_and_dcc
& SA_DCP_DCE
)? TRUE
: FALSE
;
2733 *comp_algorithm
= scsi_4btoul(cp
->comp_algorithm
);
2735 struct scsi_dev_conf_page
*cp
= &ntcs
->dconf
;
2737 * We don't really know whether this device supports
2738 * Data Compression if the the algorithm field is
2739 * zero. Just say we do.
2741 *comp_supported
= TRUE
;
2743 (cp
->sel_comp_alg
!= SA_COMP_NONE
)? TRUE
: FALSE
;
2744 *comp_algorithm
= cp
->sel_comp_alg
;
2747 bcopy(ntcs
, tcs
, sizeof (sa_comp_t
));
2750 if (CAM_DEBUGGED(periph
->path
, CAM_DEBUG_INFO
)) {
2752 char *xyz
= mode_buffer
;
2753 xpt_print_path(periph
->path
);
2754 kprintf("Mode Sense Data=");
2755 for (idx
= 0; idx
< mode_buffer_len
; idx
++)
2756 kprintf(" 0x%02x", xyz
[idx
] & 0xff);
2762 xpt_release_ccb(ccb
);
2763 kfree(mode_buffer
, M_TEMP
);
2768 * The purpose of this function is to set one of four different parameters
2772 * - compression / compression algorithm
2775 * The assumption is that this will be called from saioctl(), and therefore
2776 * from a process context. Thus the waiting malloc calls below. If that
2777 * assumption ever changes, the malloc calls should be changed to be
2780 * Any or all of the four parameters may be set when this function is
2781 * called. It should handle setting more than one parameter at once.
2784 sasetparams(struct cam_periph
*periph
, sa_params params_to_set
,
2785 u_int32_t blocksize
, u_int8_t density
, u_int32_t calg
,
2786 u_int32_t sense_flags
)
2788 struct sa_softc
*softc
;
2789 u_int32_t current_blocksize
;
2790 u_int32_t current_calg
;
2791 u_int8_t current_density
;
2792 u_int8_t current_speed
;
2793 int comp_enabled
, comp_supported
;
2795 int mode_buffer_len
;
2796 struct scsi_mode_header_6
*mode_hdr
;
2797 struct scsi_mode_blk_desc
*mode_blk
;
2798 sa_comp_t
*ccomp
, *cpage
;
2800 union ccb
*ccb
= NULL
;
2803 softc
= (struct sa_softc
*)periph
->softc
;
2805 ccomp
= kmalloc(sizeof (sa_comp_t
), M_TEMP
, M_INTWAIT
);
2808 * Since it doesn't make sense to set the number of blocks, or
2809 * write protection, we won't try to get the current value. We
2810 * always want to get the blocksize, so we can set it back to the
2813 error
= sagetparams(periph
,
2814 params_to_set
| SA_PARAM_BLOCKSIZE
| SA_PARAM_SPEED
,
2815 ¤t_blocksize
, ¤t_density
, NULL
, &buff_mode
, NULL
,
2816 ¤t_speed
, &comp_supported
, &comp_enabled
,
2817 ¤t_calg
, ccomp
);
2820 kfree(ccomp
, M_TEMP
);
2824 mode_buffer_len
= sizeof(*mode_hdr
) + sizeof(*mode_blk
);
2825 if (params_to_set
& SA_PARAM_COMPRESSION
)
2826 mode_buffer_len
+= sizeof (sa_comp_t
);
2828 mode_buffer
= kmalloc(mode_buffer_len
, M_TEMP
, M_INTWAIT
| M_ZERO
);
2830 mode_hdr
= (struct scsi_mode_header_6
*)mode_buffer
;
2831 mode_blk
= (struct scsi_mode_blk_desc
*)&mode_hdr
[1];
2833 ccb
= cam_periph_getccb(periph
, 1);
2837 if (params_to_set
& SA_PARAM_COMPRESSION
) {
2839 cpage
= (sa_comp_t
*)&mode_blk
[1];
2841 cpage
= (sa_comp_t
*)&mode_hdr
[1];
2843 bcopy(ccomp
, cpage
, sizeof (sa_comp_t
));
2844 cpage
->hdr
.pagecode
&= ~0x80;
2849 * If the caller wants us to set the blocksize, use the one they
2850 * pass in. Otherwise, use the blocksize we got back from the
2851 * mode select above.
2854 if (params_to_set
& SA_PARAM_BLOCKSIZE
)
2855 scsi_ulto3b(blocksize
, mode_blk
->blklen
);
2857 scsi_ulto3b(current_blocksize
, mode_blk
->blklen
);
2860 * Set density if requested, else preserve old density.
2861 * SCSI_SAME_DENSITY only applies to SCSI-2 or better
2862 * devices, else density we've latched up in our softc.
2864 if (params_to_set
& SA_PARAM_DENSITY
) {
2865 mode_blk
->density
= density
;
2866 } else if (softc
->scsi_rev
> SCSI_REV_CCS
) {
2867 mode_blk
->density
= SCSI_SAME_DENSITY
;
2869 mode_blk
->density
= softc
->media_density
;
2874 * For mode selects, these two fields must be zero.
2876 mode_hdr
->data_length
= 0;
2877 mode_hdr
->medium_type
= 0;
2879 /* set the speed to the current value */
2880 mode_hdr
->dev_spec
= current_speed
;
2882 /* if set, set single-initiator buffering mode */
2883 if (softc
->buffer_mode
== SMH_SA_BUF_MODE_SIBUF
) {
2884 mode_hdr
->dev_spec
|= SMH_SA_BUF_MODE_SIBUF
;
2888 mode_hdr
->blk_desc_len
= sizeof(struct scsi_mode_blk_desc
);
2890 mode_hdr
->blk_desc_len
= 0;
2893 * First, if the user wants us to set the compression algorithm or
2894 * just turn compression on, check to make sure that this drive
2895 * supports compression.
2897 if (params_to_set
& SA_PARAM_COMPRESSION
) {
2899 * If the compression algorithm is 0, disable compression.
2900 * If the compression algorithm is non-zero, enable
2901 * compression and set the compression type to the
2902 * specified compression algorithm, unless the algorithm is
2903 * MT_COMP_ENABLE. In that case, we look at the
2904 * compression algorithm that is currently set and if it is
2905 * non-zero, we leave it as-is. If it is zero, and we have
2906 * saved a compression algorithm from a time when
2907 * compression was enabled before, set the compression to
2910 switch (ccomp
->hdr
.pagecode
& ~0x80) {
2911 case SA_DEVICE_CONFIGURATION_PAGE
:
2913 struct scsi_dev_conf_page
*dcp
= &cpage
->dconf
;
2915 dcp
->sel_comp_alg
= SA_COMP_NONE
;
2918 if (calg
!= MT_COMP_ENABLE
) {
2919 dcp
->sel_comp_alg
= calg
;
2920 } else if (dcp
->sel_comp_alg
== SA_COMP_NONE
&&
2921 softc
->saved_comp_algorithm
!= 0) {
2922 dcp
->sel_comp_alg
= softc
->saved_comp_algorithm
;
2926 case SA_DATA_COMPRESSION_PAGE
:
2927 if (ccomp
->dcomp
.dce_and_dcc
& SA_DCP_DCC
) {
2928 struct scsi_data_compression_page
*dcp
= &cpage
->dcomp
;
2931 * Disable compression, but leave the
2932 * decompression and the capability bit
2935 dcp
->dce_and_dcc
= SA_DCP_DCC
;
2936 dcp
->dde_and_red
|= SA_DCP_DDE
;
2939 /* enable compression && decompression */
2940 dcp
->dce_and_dcc
= SA_DCP_DCE
| SA_DCP_DCC
;
2941 dcp
->dde_and_red
|= SA_DCP_DDE
;
2943 * If there, use compression algorithm from caller.
2944 * Otherwise, if there's a saved compression algorithm
2945 * and there is no current algorithm, use the saved
2946 * algorithm. Else parrot back what we got and hope
2949 if (calg
!= MT_COMP_ENABLE
) {
2950 scsi_ulto4b(calg
, dcp
->comp_algorithm
);
2951 scsi_ulto4b(calg
, dcp
->decomp_algorithm
);
2952 } else if (scsi_4btoul(dcp
->comp_algorithm
) == 0 &&
2953 softc
->saved_comp_algorithm
!= 0) {
2954 scsi_ulto4b(softc
->saved_comp_algorithm
,
2955 dcp
->comp_algorithm
);
2956 scsi_ulto4b(softc
->saved_comp_algorithm
,
2957 dcp
->decomp_algorithm
);
2962 * Compression does not appear to be supported-
2963 * at least via the DATA COMPRESSION page. It
2964 * would be too much to ask us to believe that
2965 * the page itself is supported, but incorrectly
2966 * reports an ability to manipulate data compression,
2967 * so we'll assume that this device doesn't support
2968 * compression. We can just fall through for that.
2973 * The drive doesn't seem to support compression,
2974 * so turn off the set compression bit.
2976 params_to_set
&= ~SA_PARAM_COMPRESSION
;
2977 xpt_print_path(periph
->path
);
2978 kprintf("device does not seem to support compression\n");
2981 * If that was the only thing the user wanted us to set,
2982 * clean up allocated resources and return with
2983 * 'operation not supported'.
2985 if (params_to_set
== SA_PARAM_NONE
) {
2986 kfree(mode_buffer
, M_TEMP
);
2987 xpt_release_ccb(ccb
);
2992 * That wasn't the only thing the user wanted us to set.
2993 * So, decrease the stated mode buffer length by the
2994 * size of the compression mode page.
2996 mode_buffer_len
-= sizeof(sa_comp_t
);
3000 /* It is safe to retry this operation */
3001 scsi_mode_select(&ccb
->csio
, 5, sadone
, MSG_SIMPLE_Q_TAG
,
3002 (params_to_set
& SA_PARAM_COMPRESSION
)? TRUE
: FALSE
,
3003 FALSE
, mode_buffer
, mode_buffer_len
, SSD_FULL_SIZE
, SCSIOP_TIMEOUT
);
3005 error
= cam_periph_runccb(ccb
, saerror
, 0,
3006 sense_flags
, &softc
->device_stats
);
3009 if (CAM_DEBUGGED(periph
->path
, CAM_DEBUG_INFO
)) {
3011 char *xyz
= mode_buffer
;
3012 xpt_print_path(periph
->path
);
3013 kprintf("Err%d, Mode Select Data=", error
);
3014 for (idx
= 0; idx
< mode_buffer_len
; idx
++)
3015 kprintf(" 0x%02x", xyz
[idx
] & 0xff);
3022 * If we can, try without setting density/blocksize.
3025 if ((params_to_set
&
3026 (SA_PARAM_DENSITY
|SA_PARAM_BLOCKSIZE
)) == 0) {
3031 mode_blk
= (struct scsi_mode_blk_desc
*)&mode_hdr
[1];
3032 cpage
= (sa_comp_t
*)&mode_blk
[1];
3036 * If we were setting the blocksize, and that failed, we
3037 * want to set it to its original value. If we weren't
3038 * setting the blocksize, we don't want to change it.
3040 scsi_ulto3b(current_blocksize
, mode_blk
->blklen
);
3043 * Set density if requested, else preserve old density.
3044 * SCSI_SAME_DENSITY only applies to SCSI-2 or better
3045 * devices, else density we've latched up in our softc.
3047 if (params_to_set
& SA_PARAM_DENSITY
) {
3048 mode_blk
->density
= current_density
;
3049 } else if (softc
->scsi_rev
> SCSI_REV_CCS
) {
3050 mode_blk
->density
= SCSI_SAME_DENSITY
;
3052 mode_blk
->density
= softc
->media_density
;
3055 if (params_to_set
& SA_PARAM_COMPRESSION
)
3056 bcopy(ccomp
, cpage
, sizeof (sa_comp_t
));
3059 * The retry count is the only CCB field that might have been
3060 * changed that we care about, so reset it back to 1.
3062 ccb
->ccb_h
.retry_count
= 1;
3063 cam_periph_runccb(ccb
, saerror
, 0, sense_flags
,
3064 &softc
->device_stats
);
3068 xpt_release_ccb(ccb
);
3071 kfree(ccomp
, M_TEMP
);
3073 if (params_to_set
& SA_PARAM_COMPRESSION
) {
3075 softc
->flags
&= ~SA_FLAG_COMP_ENABLED
;
3077 * Even if we get an error setting compression,
3078 * do not say that we don't support it. We could
3079 * have been wrong, or it may be media specific.
3080 * softc->flags &= ~SA_FLAG_COMP_SUPP;
3082 softc
->saved_comp_algorithm
= softc
->comp_algorithm
;
3083 softc
->comp_algorithm
= 0;
3085 softc
->flags
|= SA_FLAG_COMP_ENABLED
;
3086 softc
->comp_algorithm
= calg
;
3090 kfree(mode_buffer
, M_TEMP
);
3095 saprevent(struct cam_periph
*periph
, int action
)
3097 struct sa_softc
*softc
;
3101 softc
= (struct sa_softc
*)periph
->softc
;
3103 if ((action
== PR_ALLOW
) && (softc
->flags
& SA_FLAG_TAPE_LOCKED
) == 0)
3105 if ((action
== PR_PREVENT
) && (softc
->flags
& SA_FLAG_TAPE_LOCKED
) != 0)
3109 * We can be quiet about illegal requests.
3111 if (CAM_DEBUGGED(periph
->path
, CAM_DEBUG_INFO
)) {
3116 ccb
= cam_periph_getccb(periph
, 1);
3118 /* It is safe to retry this operation */
3119 scsi_prevent(&ccb
->csio
, 5, sadone
, MSG_SIMPLE_Q_TAG
, action
,
3120 SSD_FULL_SIZE
, SCSIOP_TIMEOUT
);
3122 error
= cam_periph_runccb(ccb
, saerror
, 0, sf
, &softc
->device_stats
);
3125 if (action
== PR_ALLOW
)
3126 softc
->flags
&= ~SA_FLAG_TAPE_LOCKED
;
3128 softc
->flags
|= SA_FLAG_TAPE_LOCKED
;
3131 xpt_release_ccb(ccb
);
3135 sarewind(struct cam_periph
*periph
)
3138 struct sa_softc
*softc
;
3141 softc
= (struct sa_softc
*)periph
->softc
;
3143 ccb
= cam_periph_getccb(periph
, 1);
3145 /* It is safe to retry this operation */
3146 scsi_rewind(&ccb
->csio
, 2, sadone
, MSG_SIMPLE_Q_TAG
, FALSE
,
3147 SSD_FULL_SIZE
, REWIND_TIMEOUT
);
3149 softc
->dsreg
= MTIO_DSREG_REW
;
3150 error
= cam_periph_runccb(ccb
, saerror
, 0, 0, &softc
->device_stats
);
3151 softc
->dsreg
= MTIO_DSREG_REST
;
3153 if ((ccb
->ccb_h
.status
& CAM_DEV_QFRZN
) != 0)
3154 cam_release_devq(ccb
->ccb_h
.path
, 0, 0, 0, FALSE
);
3156 xpt_release_ccb(ccb
);
3158 softc
->fileno
= softc
->blkno
= (daddr_t
) 0;
3160 softc
->fileno
= softc
->blkno
= (daddr_t
) -1;
3165 saspace(struct cam_periph
*periph
, int count
, scsi_space_code code
)
3168 struct sa_softc
*softc
;
3171 softc
= (struct sa_softc
*)periph
->softc
;
3173 ccb
= cam_periph_getccb(periph
, 1);
3175 /* This cannot be retried */
3177 scsi_space(&ccb
->csio
, 0, sadone
, MSG_SIMPLE_Q_TAG
, code
, count
,
3178 SSD_FULL_SIZE
, SPACE_TIMEOUT
);
3181 * Clear residual because we will be using it.
3183 softc
->last_ctl_resid
= 0;
3185 softc
->dsreg
= (count
< 0)? MTIO_DSREG_REV
: MTIO_DSREG_FWD
;
3186 error
= cam_periph_runccb(ccb
, saerror
, 0, 0, &softc
->device_stats
);
3187 softc
->dsreg
= MTIO_DSREG_REST
;
3189 if ((ccb
->ccb_h
.status
& CAM_DEV_QFRZN
) != 0)
3190 cam_release_devq(ccb
->ccb_h
.path
, 0, 0, 0, FALSE
);
3192 xpt_release_ccb(ccb
);
3195 * If a spacing operation has failed, we need to invalidate
3198 * If the spacing operation was setmarks or to end of recorded data,
3199 * we no longer know our relative position.
3201 * If the spacing operations was spacing files in reverse, we
3202 * take account of the residual, but still check against less
3203 * than zero- if we've gone negative, we must have hit BOT.
3205 * If the spacing operations was spacing records in reverse and
3206 * we have a residual, we've either hit BOT or hit a filemark.
3207 * In the former case, we know our new record number (0). In
3208 * the latter case, we have absolutely no idea what the real
3209 * record number is- we've stopped between the end of the last
3210 * record in the previous file and the filemark that stopped
3211 * our spacing backwards.
3214 softc
->fileno
= softc
->blkno
= (daddr_t
) -1;
3215 } else if (code
== SS_SETMARKS
|| code
== SS_EOD
) {
3216 softc
->fileno
= softc
->blkno
= (daddr_t
) -1;
3217 } else if (code
== SS_FILEMARKS
&& softc
->fileno
!= (daddr_t
) -1) {
3218 softc
->fileno
+= (count
- softc
->last_ctl_resid
);
3219 if (softc
->fileno
< 0) /* we must of hit BOT */
3222 } else if (code
== SS_BLOCKS
&& softc
->blkno
!= (daddr_t
) -1) {
3223 softc
->blkno
+= (count
- softc
->last_ctl_resid
);
3225 if (softc
->last_ctl_resid
|| softc
->blkno
< 0) {
3226 if (softc
->fileno
== 0) {
3229 softc
->blkno
= (daddr_t
) -1;
3238 sawritefilemarks(struct cam_periph
*periph
, int nmarks
, int setmarks
)
3241 struct sa_softc
*softc
;
3244 softc
= (struct sa_softc
*)periph
->softc
;
3245 if (softc
->open_rdonly
)
3248 ccb
= cam_periph_getccb(periph
, 1);
3250 * Clear residual because we will be using it.
3252 softc
->last_ctl_resid
= 0;
3254 softc
->dsreg
= MTIO_DSREG_FMK
;
3255 /* this *must* not be retried */
3256 scsi_write_filemarks(&ccb
->csio
, 0, sadone
, MSG_SIMPLE_Q_TAG
,
3257 FALSE
, setmarks
, nmarks
, SSD_FULL_SIZE
, IO_TIMEOUT
);
3258 softc
->dsreg
= MTIO_DSREG_REST
;
3261 error
= cam_periph_runccb(ccb
, saerror
, 0, 0, &softc
->device_stats
);
3263 if ((ccb
->ccb_h
.status
& CAM_DEV_QFRZN
) != 0)
3264 cam_release_devq(ccb
->ccb_h
.path
, 0, 0, 0, FALSE
);
3266 if (error
== 0 && nmarks
) {
3267 struct sa_softc
*softc
= (struct sa_softc
*)periph
->softc
;
3268 nwm
= nmarks
- softc
->last_ctl_resid
;
3269 softc
->filemarks
+= nwm
;
3272 xpt_release_ccb(ccb
);
3275 * Update relative positions (if we're doing that).
3278 softc
->fileno
= softc
->blkno
= (daddr_t
) -1;
3279 } else if (softc
->fileno
!= (daddr_t
) -1) {
3280 softc
->fileno
+= nwm
;
3287 sardpos(struct cam_periph
*periph
, int hard
, u_int32_t
*blkptr
)
3289 struct scsi_tape_position_data loc
;
3291 struct sa_softc
*softc
= (struct sa_softc
*)periph
->softc
;
3295 * We try and flush any buffered writes here if we were writing
3296 * and we're trying to get hardware block position. It eats
3297 * up performance substantially, but I'm wary of drive firmware.
3299 * I think that *logical* block position is probably okay-
3300 * but hardware block position might have to wait for data
3301 * to hit media to be valid. Caveat Emptor.
3304 if (hard
&& (softc
->flags
& SA_FLAG_TAPE_WRITTEN
)) {
3305 error
= sawritefilemarks(periph
, 0, 0);
3306 if (error
&& error
!= EACCES
)
3310 ccb
= cam_periph_getccb(periph
, 1);
3311 scsi_read_position(&ccb
->csio
, 1, sadone
, MSG_SIMPLE_Q_TAG
,
3312 hard
, &loc
, SSD_FULL_SIZE
, SCSIOP_TIMEOUT
);
3313 softc
->dsreg
= MTIO_DSREG_RBSY
;
3314 error
= cam_periph_runccb(ccb
, saerror
, 0, 0, &softc
->device_stats
);
3315 softc
->dsreg
= MTIO_DSREG_REST
;
3316 if ((ccb
->ccb_h
.status
& CAM_DEV_QFRZN
) != 0)
3317 cam_release_devq(ccb
->ccb_h
.path
, 0, 0, 0, 0);
3320 if (loc
.flags
& SA_RPOS_UNCERTAIN
) {
3321 error
= EINVAL
; /* nothing is certain */
3323 *blkptr
= scsi_4btoul(loc
.firstblk
);
3327 xpt_release_ccb(ccb
);
3332 sasetpos(struct cam_periph
*periph
, int hard
, u_int32_t
*blkptr
)
3335 struct sa_softc
*softc
;
3339 * We used to try and flush any buffered writes here.
3340 * Now we push this onto user applications to either
3341 * flush the pending writes themselves (via a zero count
3342 * WRITE FILEMARKS command) or they can trust their tape
3343 * drive to do this correctly for them.
3346 softc
= (struct sa_softc
*)periph
->softc
;
3347 ccb
= cam_periph_getccb(periph
, 1);
3350 scsi_set_position(&ccb
->csio
, 1, sadone
, MSG_SIMPLE_Q_TAG
,
3351 hard
, *blkptr
, SSD_FULL_SIZE
, SPACE_TIMEOUT
);
3354 softc
->dsreg
= MTIO_DSREG_POS
;
3355 error
= cam_periph_runccb(ccb
, saerror
, 0, 0, &softc
->device_stats
);
3356 softc
->dsreg
= MTIO_DSREG_REST
;
3357 if ((ccb
->ccb_h
.status
& CAM_DEV_QFRZN
) != 0)
3358 cam_release_devq(ccb
->ccb_h
.path
, 0, 0, 0, 0);
3359 xpt_release_ccb(ccb
);
3361 * Note relative file && block number position as now unknown.
3363 softc
->fileno
= softc
->blkno
= (daddr_t
) -1;
3368 saretension(struct cam_periph
*periph
)
3371 struct sa_softc
*softc
;
3374 softc
= (struct sa_softc
*)periph
->softc
;
3376 ccb
= cam_periph_getccb(periph
, 1);
3378 /* It is safe to retry this operation */
3379 scsi_load_unload(&ccb
->csio
, 5, sadone
, MSG_SIMPLE_Q_TAG
, FALSE
,
3380 FALSE
, TRUE
, TRUE
, SSD_FULL_SIZE
, ERASE_TIMEOUT
);
3382 softc
->dsreg
= MTIO_DSREG_TEN
;
3383 error
= cam_periph_runccb(ccb
, saerror
, 0, 0, &softc
->device_stats
);
3384 softc
->dsreg
= MTIO_DSREG_REST
;
3386 if ((ccb
->ccb_h
.status
& CAM_DEV_QFRZN
) != 0)
3387 cam_release_devq(ccb
->ccb_h
.path
, 0, 0, 0, FALSE
);
3388 xpt_release_ccb(ccb
);
3390 softc
->fileno
= softc
->blkno
= (daddr_t
) 0;
3392 softc
->fileno
= softc
->blkno
= (daddr_t
) -1;
3397 sareservereleaseunit(struct cam_periph
*periph
, int reserve
)
3400 struct sa_softc
*softc
;
3403 softc
= (struct sa_softc
*)periph
->softc
;
3404 ccb
= cam_periph_getccb(periph
, 1);
3406 /* It is safe to retry this operation */
3407 scsi_reserve_release_unit(&ccb
->csio
, 2, sadone
, MSG_SIMPLE_Q_TAG
,
3408 FALSE
, 0, SSD_FULL_SIZE
, SCSIOP_TIMEOUT
, reserve
);
3409 softc
->dsreg
= MTIO_DSREG_RBSY
;
3410 error
= cam_periph_runccb(ccb
, saerror
, 0,
3411 SF_RETRY_UA
| SF_NO_PRINT
, &softc
->device_stats
);
3412 softc
->dsreg
= MTIO_DSREG_REST
;
3414 xpt_release_ccb(ccb
);
3417 * If the error was Illegal Request, then the device doesn't support
3418 * RESERVE/RELEASE. This is not an error.
3420 if (error
== EINVAL
) {
3428 saloadunload(struct cam_periph
*periph
, int load
)
3431 struct sa_softc
*softc
;
3434 softc
= (struct sa_softc
*)periph
->softc
;
3436 ccb
= cam_periph_getccb(periph
, 1);
3438 /* It is safe to retry this operation */
3439 scsi_load_unload(&ccb
->csio
, 5, sadone
, MSG_SIMPLE_Q_TAG
, FALSE
,
3440 FALSE
, FALSE
, load
, SSD_FULL_SIZE
, REWIND_TIMEOUT
);
3442 softc
->dsreg
= (load
)? MTIO_DSREG_LD
: MTIO_DSREG_UNL
;
3443 error
= cam_periph_runccb(ccb
, saerror
, 0, 0, &softc
->device_stats
);
3444 softc
->dsreg
= MTIO_DSREG_REST
;
3446 xpt_release_ccb(ccb
);
3448 if (error
|| load
== 0)
3449 softc
->fileno
= softc
->blkno
= (daddr_t
) -1;
3450 else if (error
== 0)
3451 softc
->fileno
= softc
->blkno
= (daddr_t
) 0;
3456 saerase(struct cam_periph
*periph
, int longerase
)
3460 struct sa_softc
*softc
;
3463 softc
= (struct sa_softc
*)periph
->softc
;
3464 if (softc
->open_rdonly
)
3467 ccb
= cam_periph_getccb(periph
, 1);
3469 scsi_erase(&ccb
->csio
, 1, sadone
, MSG_SIMPLE_Q_TAG
, FALSE
, longerase
,
3470 SSD_FULL_SIZE
, ERASE_TIMEOUT
);
3472 softc
->dsreg
= MTIO_DSREG_ZER
;
3473 error
= cam_periph_runccb(ccb
, saerror
, 0, 0, &softc
->device_stats
);
3474 softc
->dsreg
= MTIO_DSREG_REST
;
3476 if ((ccb
->ccb_h
.status
& CAM_DEV_QFRZN
) != 0)
3477 cam_release_devq(ccb
->ccb_h
.path
, 0, 0, 0, FALSE
);
3478 xpt_release_ccb(ccb
);
3482 #endif /* _KERNEL */
3485 * Read tape block limits command.
3488 scsi_read_block_limits(struct ccb_scsiio
*csio
, u_int32_t retries
,
3489 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
3490 u_int8_t tag_action
,
3491 struct scsi_read_block_limits_data
*rlimit_buf
,
3492 u_int8_t sense_len
, u_int32_t timeout
)
3494 struct scsi_read_block_limits
*scsi_cmd
;
3496 cam_fill_csio(csio
, retries
, cbfcnp
, CAM_DIR_IN
, tag_action
,
3497 (u_int8_t
*)rlimit_buf
, sizeof(*rlimit_buf
), sense_len
,
3498 sizeof(*scsi_cmd
), timeout
);
3500 scsi_cmd
= (struct scsi_read_block_limits
*)&csio
->cdb_io
.cdb_bytes
;
3501 bzero(scsi_cmd
, sizeof(*scsi_cmd
));
3502 scsi_cmd
->opcode
= READ_BLOCK_LIMITS
;
3506 scsi_sa_read_write(struct ccb_scsiio
*csio
, u_int32_t retries
,
3507 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
3508 u_int8_t tag_action
, int readop
, int sli
,
3509 int fixed
, u_int32_t length
, u_int8_t
*data_ptr
,
3510 u_int32_t dxfer_len
, u_int8_t sense_len
, u_int32_t timeout
)
3512 struct scsi_sa_rw
*scsi_cmd
;
3514 scsi_cmd
= (struct scsi_sa_rw
*)&csio
->cdb_io
.cdb_bytes
;
3515 scsi_cmd
->opcode
= readop
? SA_READ
: SA_WRITE
;
3516 scsi_cmd
->sli_fixed
= 0;
3518 scsi_cmd
->sli_fixed
|= SAR_SLI
;
3520 scsi_cmd
->sli_fixed
|= SARW_FIXED
;
3521 scsi_ulto3b(length
, scsi_cmd
->length
);
3522 scsi_cmd
->control
= 0;
3524 cam_fill_csio(csio
, retries
, cbfcnp
, readop
? CAM_DIR_IN
: CAM_DIR_OUT
,
3525 tag_action
, data_ptr
, dxfer_len
, sense_len
,
3526 sizeof(*scsi_cmd
), timeout
);
3530 scsi_load_unload(struct ccb_scsiio
*csio
, u_int32_t retries
,
3531 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
3532 u_int8_t tag_action
, int immediate
, int eot
,
3533 int reten
, int load
, u_int8_t sense_len
,
3536 struct scsi_load_unload
*scsi_cmd
;
3538 scsi_cmd
= (struct scsi_load_unload
*)&csio
->cdb_io
.cdb_bytes
;
3539 bzero(scsi_cmd
, sizeof(*scsi_cmd
));
3540 scsi_cmd
->opcode
= LOAD_UNLOAD
;
3542 scsi_cmd
->immediate
= SLU_IMMED
;
3544 scsi_cmd
->eot_reten_load
|= SLU_EOT
;
3546 scsi_cmd
->eot_reten_load
|= SLU_RETEN
;
3548 scsi_cmd
->eot_reten_load
|= SLU_LOAD
;
3550 cam_fill_csio(csio
, retries
, cbfcnp
, CAM_DIR_NONE
, tag_action
,
3551 NULL
, 0, sense_len
, sizeof(*scsi_cmd
), timeout
);
3555 scsi_rewind(struct ccb_scsiio
*csio
, u_int32_t retries
,
3556 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
3557 u_int8_t tag_action
, int immediate
, u_int8_t sense_len
,
3560 struct scsi_rewind
*scsi_cmd
;
3562 scsi_cmd
= (struct scsi_rewind
*)&csio
->cdb_io
.cdb_bytes
;
3563 bzero(scsi_cmd
, sizeof(*scsi_cmd
));
3564 scsi_cmd
->opcode
= REWIND
;
3566 scsi_cmd
->immediate
= SREW_IMMED
;
3568 cam_fill_csio(csio
, retries
, cbfcnp
, CAM_DIR_NONE
, tag_action
, NULL
,
3569 0, sense_len
, sizeof(*scsi_cmd
), timeout
);
3573 scsi_space(struct ccb_scsiio
*csio
, u_int32_t retries
,
3574 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
3575 u_int8_t tag_action
, scsi_space_code code
,
3576 u_int32_t count
, u_int8_t sense_len
, u_int32_t timeout
)
3578 struct scsi_space
*scsi_cmd
;
3580 scsi_cmd
= (struct scsi_space
*)&csio
->cdb_io
.cdb_bytes
;
3581 scsi_cmd
->opcode
= SPACE
;
3582 scsi_cmd
->code
= code
;
3583 scsi_ulto3b(count
, scsi_cmd
->count
);
3584 scsi_cmd
->control
= 0;
3586 cam_fill_csio(csio
, retries
, cbfcnp
, CAM_DIR_NONE
, tag_action
, NULL
,
3587 0, sense_len
, sizeof(*scsi_cmd
), timeout
);
3591 scsi_write_filemarks(struct ccb_scsiio
*csio
, u_int32_t retries
,
3592 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
3593 u_int8_t tag_action
, int immediate
, int setmark
,
3594 u_int32_t num_marks
, u_int8_t sense_len
,
3597 struct scsi_write_filemarks
*scsi_cmd
;
3599 scsi_cmd
= (struct scsi_write_filemarks
*)&csio
->cdb_io
.cdb_bytes
;
3600 bzero(scsi_cmd
, sizeof(*scsi_cmd
));
3601 scsi_cmd
->opcode
= WRITE_FILEMARKS
;
3603 scsi_cmd
->byte2
|= SWFMRK_IMMED
;
3605 scsi_cmd
->byte2
|= SWFMRK_WSMK
;
3607 scsi_ulto3b(num_marks
, scsi_cmd
->num_marks
);
3609 cam_fill_csio(csio
, retries
, cbfcnp
, CAM_DIR_NONE
, tag_action
, NULL
,
3610 0, sense_len
, sizeof(*scsi_cmd
), timeout
);
3614 * The reserve and release unit commands differ only by their opcodes.
3617 scsi_reserve_release_unit(struct ccb_scsiio
*csio
, u_int32_t retries
,
3618 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
3619 u_int8_t tag_action
, int third_party
,
3620 int third_party_id
, u_int8_t sense_len
,
3621 u_int32_t timeout
, int reserve
)
3623 struct scsi_reserve_release_unit
*scsi_cmd
;
3625 scsi_cmd
= (struct scsi_reserve_release_unit
*)&csio
->cdb_io
.cdb_bytes
;
3626 bzero(scsi_cmd
, sizeof(*scsi_cmd
));
3629 scsi_cmd
->opcode
= RESERVE_UNIT
;
3631 scsi_cmd
->opcode
= RELEASE_UNIT
;
3634 scsi_cmd
->lun_thirdparty
|= SRRU_3RD_PARTY
;
3635 scsi_cmd
->lun_thirdparty
|=
3636 ((third_party_id
<< SRRU_3RD_SHAMT
) & SRRU_3RD_MASK
);
3639 cam_fill_csio(csio
, retries
, cbfcnp
, CAM_DIR_NONE
, tag_action
, NULL
,
3640 0, sense_len
, sizeof(*scsi_cmd
), timeout
);
3644 scsi_erase(struct ccb_scsiio
*csio
, u_int32_t retries
,
3645 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
3646 u_int8_t tag_action
, int immediate
, int long_erase
,
3647 u_int8_t sense_len
, u_int32_t timeout
)
3649 struct scsi_erase
*scsi_cmd
;
3651 scsi_cmd
= (struct scsi_erase
*)&csio
->cdb_io
.cdb_bytes
;
3652 bzero(scsi_cmd
, sizeof(*scsi_cmd
));
3654 scsi_cmd
->opcode
= ERASE
;
3657 scsi_cmd
->lun_imm_long
|= SE_IMMED
;
3660 scsi_cmd
->lun_imm_long
|= SE_LONG
;
3662 cam_fill_csio(csio
, retries
, cbfcnp
, CAM_DIR_NONE
, tag_action
, NULL
,
3663 0, sense_len
, sizeof(*scsi_cmd
), timeout
);
3667 * Read Tape Position command.
3670 scsi_read_position(struct ccb_scsiio
*csio
, u_int32_t retries
,
3671 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
3672 u_int8_t tag_action
, int hardsoft
,
3673 struct scsi_tape_position_data
*sbp
,
3674 u_int8_t sense_len
, u_int32_t timeout
)
3676 struct scsi_tape_read_position
*scmd
;
3678 cam_fill_csio(csio
, retries
, cbfcnp
, CAM_DIR_IN
, tag_action
,
3679 (u_int8_t
*)sbp
, sizeof (*sbp
), sense_len
, sizeof(*scmd
), timeout
);
3680 scmd
= (struct scsi_tape_read_position
*)&csio
->cdb_io
.cdb_bytes
;
3681 bzero(scmd
, sizeof(*scmd
));
3682 scmd
->opcode
= READ_POSITION
;
3683 scmd
->byte1
= hardsoft
;
3687 * Set Tape Position command.
3690 scsi_set_position(struct ccb_scsiio
*csio
, u_int32_t retries
,
3691 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
3692 u_int8_t tag_action
, int hardsoft
, u_int32_t blkno
,
3693 u_int8_t sense_len
, u_int32_t timeout
)
3695 struct scsi_tape_locate
*scmd
;
3697 cam_fill_csio(csio
, retries
, cbfcnp
, CAM_DIR_NONE
, tag_action
,
3698 (u_int8_t
*)NULL
, 0, sense_len
, sizeof(*scmd
), timeout
);
3699 scmd
= (struct scsi_tape_locate
*)&csio
->cdb_io
.cdb_bytes
;
3700 bzero(scmd
, sizeof(*scmd
));
3701 scmd
->opcode
= LOCATE
;
3703 scmd
->byte1
|= SA_SPOS_BT
;
3704 scsi_ulto4b(blkno
, scmd
->blkaddr
);