2 * Copyright (c) 1998,1999,2000
3 * Traakan, Inc., Los Altos, CA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include "scsiconst.h"
43 smc_scsi_xa (struct smc_ctrl_block *smc)
48 unsigned char * sense_data = smc->scsi_req.sense_data;
50 for (try = 0; try < 2; try++) {
51 rc = (*smc->issue_scsi_req)(smc);
52 if (rc || smc->scsi_req.completion_status != SMCSR_CS_GOOD) {
53 strcpy (smc->errmsg, "SCSI request failed");
58 switch (SCSI_STATUS_BYTE_CODE(smc->scsi_req.status_byte)) {
59 case SCSI_STATUS_GOOD:
62 case SCSI_STATUS_CHECK_CONDITION:
63 /* sense data processed below */
67 strcpy (smc->errmsg, "SCSI unexpected status");
71 sense_key = sense_data[2] & SCSI_SENSE_SENSE_KEY_MASK;
73 if (sense_key == SCSI_SENSE_KEY_UNIT_ATTENTION) {
75 int asc, ascq, asq, cmd;
78 valid = sense_data[0] & SCSI_SENSE_VALID_BIT;
79 info = SMC_GET4(&sense_data[3]);
81 ascq = sense_data[13];
83 cmd = smc->scsi_req.cmd[0];
86 "SCSI attn s0=%x asq=%x,%x cmd=%x info=%lx",
88 asc, ascq, cmd, info);
92 strcpy (smc->errmsg, "SCSI check condition");
94 break; /* don't retry, investigate */
103 #define SINQ_MEDIA_CHANGER 0x08
106 smc_inquire (struct smc_ctrl_block *smc)
108 struct smc_scsi_req * sr = &smc->scsi_req;
109 unsigned char data[128];
113 bzero (sr, sizeof *sr);
114 bzero (data, sizeof data);
117 sr->cmd[0] = SCSI_CMD_INQUIRY;
118 sr->cmd[4] = sizeof data; /* allocation length */
121 sr->n_data_avail = sizeof data;
122 sr->data_dir = SMCSR_DD_IN;
124 rc = smc_scsi_xa (smc);
125 if (rc != 0) return rc;
127 if (data[0] != SINQ_MEDIA_CHANGER) {
128 strcpy (smc->errmsg, "Not a media changer");
132 for (i = 28-1; i >= 0; i--) {
139 for (; i >= 0; i--) {
142 if (! (' ' <= c && c < 0x7F))
151 smc_test_unit_ready (struct smc_ctrl_block *smc)
153 struct smc_scsi_req * sr = &smc->scsi_req;
156 bzero (sr, sizeof *sr);
159 sr->cmd[0] = SCSI_CMD_TEST_UNIT_READY;
161 rc = smc_scsi_xa (smc);
167 smc_get_elem_aa (struct smc_ctrl_block *smc)
169 struct smc_scsi_req * sr = &smc->scsi_req;
170 unsigned char data[256];
173 bzero (sr, sizeof *sr);
174 bzero (data, sizeof data);
175 bzero (&smc->elem_aa, sizeof smc->elem_aa);
176 smc->valid_elem_aa = 0;
179 sr->cmd[0] = SCSI_CMD_MODE_SENSE_6;
180 sr->cmd[1] = 0x08; /* DBD */
181 sr->cmd[2] = 0x1D; /* current elem addrs */
182 sr->cmd[3] = 0; /* reserved */
183 sr->cmd[4] = 255; /* allocation length */
184 sr->cmd[5] = 0; /* reserved */
187 sr->n_data_avail = 255;
188 sr->data_dir = SMCSR_DD_IN;
190 rc = smc_scsi_xa (smc);
191 if (rc != 0) return rc;
194 strcpy (smc->errmsg, "short sense data");
199 rc = smc_parse_element_address_assignment ((void*)&data[4],
202 strcpy (smc->errmsg, "elem_addr_assignment format error");
206 smc->valid_elem_aa = 1;
212 * 17.2.2 INITIALIZE ELEMENT STATUS command
214 * The INITIALIZE ELEMENT STATUS command (see table 329) will cause the
215 * medium changer to check all elements for medium and any other status
216 * relevant to that element. The intent of this command is to enable the
217 * initiator to get a quick response from a following READ ELEMENT STATUS
218 * command. It may be useful to issue this command after a power failure,
219 * or if medium has been changed by an operator, or if configurations have
222 * Table 329 - INITIALIZE ELEMENT STATUS command
223 * +====-=======-========-========-========-========-========-========-======+
224 * | Bit| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
225 * |Byte| | | | | | | | |
226 * |====+====================================================================|
227 * | 0 | Operation code (07h) |
228 * |----+--------------------------------------------------------------------|
229 * | 1 |Logical unit number | Reserved |
230 * |----+--------------------------------------------------------------------|
232 * |----+--------------------------------------------------------------------|
234 * |----+--------------------------------------------------------------------|
236 * |----+--------------------------------------------------------------------|
238 * +=========================================================================+
243 smc_init_elem_status (struct smc_ctrl_block *smc)
245 struct smc_scsi_req * sr = &smc->scsi_req;
248 bzero (sr, sizeof *sr);
251 sr->cmd[0] = SCSI_CMD_INITIALIZE_ELEMENT_STATUS;
253 sr->data_dir = SMCSR_DD_NONE;
255 rc = smc_scsi_xa (smc);
256 if (rc != 0) return rc;
264 * 17.2.5 READ ELEMENT STATUS command
266 * The READ ELEMENT STATUS command (see table 332) requests that the
267 * target report the status of its internal elements to the initiator.
269 * Table 332 - READ ELEMENT STATUS command
270 * +====-=======-========-========-========-========-========-========-=======+
271 * | Bit| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
272 * |Byte| | | | | | | | |
273 * |====+=====================================================================|
274 * | 0 | Operation code (B8h) |
275 * |----+---------------------------------------------------------------------|
276 * | 1 |Logical unit number | VolTag | Element type code |
277 * |----+---------------------------------------------------------------------|
279 * |----+-- Starting element address --|
281 * |----+---------------------------------------------------------------------|
283 * |----+-- Number of elements --|
285 * |----+---------------------------------------------------------------------|
287 * |----+---------------------------------------------------------------------|
290 * | 8 | Allocation length |
293 * |----+---------------------------------------------------------------------|
295 * |----+---------------------------------------------------------------------|
297 * +==========================================================================+
300 * A volume tag (VolTag) bit of one indicates that the target shall report
301 * volume tag information if this feature is supported. A value of zero
302 * indicates that volume tag information shall not be reported. If the
303 * volume tag feature is not supported this field shall be treated as
306 * The element type code field specifies the particular element type(s)
307 * selected for reporting by this command. A value of zero specifies that
308 * status for all element types shall be reported. The element type codes
309 * are defined in table 333.
311 * Table 333 - Element type code
312 * +=============-===================================================+
313 * | Code | Description |
314 * |-------------+---------------------------------------------------|
315 * | 0h | All element types reported, (valid in CDB only) |
316 * | 1h | Medium transport element |
317 * | 2h | Storage element |
318 * | 3h | Import export element |
319 * | 4h | Data transfer element |
320 * | 5h - Fh | Reserved |
321 * +=================================================================+
324 * The starting element address specifies the minimum element address to
325 * report. Only elements with an element type code permitted by the
326 * element type code specification, and an element address greater than or
327 * equal to the starting element address shall be reported. Element
328 * descriptor blocks are not generated for undefined element addresses.
330 * The number of elements specifies the maximum number of element
331 * descriptors to be created by the target for this command. The value
332 * specified by this field is not the range of element addresses to be
333 * considered for reporting but rather the number of defined elements to
334 * report. If the allocation length is not sufficient to transfer all the
335 * element descriptors, the target shall transfer all those descriptors
336 * that can be completely transferred and this shall not be considered an
341 smc_read_elem_status (struct smc_ctrl_block *smc)
343 struct smc_scsi_req * sr = &smc->scsi_req;
344 unsigned char data[8192];
348 bzero (sr, sizeof *sr);
349 bzero (data, sizeof data);
350 bzero (&smc->elem_desc, sizeof smc->elem_desc);
351 smc->n_elem_desc = 0;
352 smc->valid_elem_desc = 0;
355 sr->cmd[0] = SCSI_CMD_READ_ELEMENT_STATUS;
356 if (!smc->dont_ask_for_voltags) {
357 sr->cmd[1] = 0x10; /* VolTag, all types */
359 sr->cmd[1] = 0x00; /* !VolTag, all types */
361 sr->cmd[2] = 0; /* starting elem MSB */
362 sr->cmd[3] = 0; /* starting elem LSB */
363 sr->cmd[4] = 0; /* number of elem MSB */
364 sr->cmd[5] = SMC_MAX_ELEMENT; /* number of elem LSB */
365 sr->cmd[6] = 0; /* reserved */
366 SMC_PUT3 (&sr->cmd[7], sizeof data);
367 sr->cmd[10] = 0; /* reserved */
370 sr->n_data_avail = sizeof data;
371 sr->data_dir = SMCSR_DD_IN;
373 rc = smc_scsi_xa (smc);
375 if (smc->dont_ask_for_voltags)
377 smc->dont_ask_for_voltags = 1;
381 rc = smc_parse_element_status_data ((void*)data, sr->n_data_done,
382 smc->elem_desc, SMC_MAX_ELEMENT);
384 strcpy (smc->errmsg, "elem_status format error");
388 smc->n_elem_desc = rc;
390 smc->valid_elem_aa = 1;
397 smc_move (struct smc_ctrl_block *smc, unsigned from_addr,
398 unsigned to_addr, int invert, unsigned chs_addr)
400 struct smc_scsi_req * sr = &smc->scsi_req;
403 bzero (sr, sizeof *sr);
406 sr->cmd[0] = SCSI_CMD_MOVE_MEDIUM;
407 SMC_PUT2(&sr->cmd[2], chs_addr);
408 SMC_PUT2(&sr->cmd[4], from_addr);
409 SMC_PUT2(&sr->cmd[6], to_addr);
412 sr->data_dir = SMCSR_DD_NONE;
414 rc = smc_scsi_xa (smc);
415 if (rc != 0) return rc;
421 smc_position (struct smc_ctrl_block *smc, unsigned to_addr, int invert)
428 smc_handy_move_to_drive (struct smc_ctrl_block *smc, unsigned from_se_ix)
434 smc_handy_move_from_drive (struct smc_ctrl_block *smc, unsigned to_se_ix)