1 /*
2 * Largely written by Julian Elischer (julian@tfs.com)
3 * for TRW Financial Systems.
4 *
5 * TRW Financial Systems, in accordance with their agreement with Carnegie
6 * Mellon University, makes this software available to CMU to distribute
7 * or use in any manner that they see fit as long as this message is kept with
8 * the software. For this reason TFS also grants any other persons or
9 * organisations permission to use or modify this software.
10 *
11 * TFS supplies this software to be publicly redistributed
12 * on the understanding that TFS is not responsible for the correct
13 * functioning of this software in any circumstances.
14 *
15 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
16 *
17 * $FreeBSD$
18 */
19
20 /*
21 * SCSI general interface description
22 */
23
24 #ifndef _SCSI_SCSI_ALL_H
25 #define _SCSI_SCSI_ALL_H 1
26
27 #include <sys/cdefs.h>
28
29 #ifdef KERNEL
30 #include "opt_scsi.h"
31 /*
32 * This is the number of seconds we wait for devices to settle after a SCSI
33 * bus reset.
34 */
35 #ifndef SCSI_DELAY
36 #define SCSI_DELAY 2000
37 #endif
38 /*
39 * If someone sets this to 0, we assume that they want the minimum
40 * allowable bus settle delay. All devices need _some_ sort of bus settle
41 * delay, so we'll set it to a minimum value of 100ms.
42 */
43 #if (SCSI_DELAY == 0)
44 #undef SCSI_DELAY
45 #define SCSI_DELAY 100
46 #endif
47
48 /*
49 * Make sure the user isn't using seconds instead of milliseconds.
50 */
51 #if (SCSI_DELAY < 100)
52 #error "SCSI_DELAY is in milliseconds, not seconds! Please use a larger value"
53 #endif
54 #endif /* KERNEL */
55
56 /*
57 * SCSI command format
58 */
59
60 /*
61 * Define dome bits that are in ALL (or a lot of) scsi commands
62 */
63 #define SCSI_CTL_LINK 0x01
64 #define SCSI_CTL_FLAG 0x02
65 #define SCSI_CTL_VENDOR 0xC0
66 #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */
67 #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */
68
69 #define SCSI_MAX_CDBLEN 16 /*
70 * 16 byte commands are in the
71 * SCSI-3 spec
72 */
73 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN)
74 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN"
75 #endif
76
77 /*
78 * This type defines actions to be taken when a particular sense code is
79 * received. Right now, these flags are only defined to take up 16 bits,
80 * but can be expanded in the future if necessary.
81 */
82 typedef enum {
83 SS_NOP = 0x000000, /* Do nothing */
84 SS_RETRY = 0x010000, /* Retry the command */
85 SS_FAIL = 0x020000, /* Bail out */
86 SS_START = 0x030000, /* Send a Start Unit command to the device,
87 * then retry the original command.
88 */
89 SS_TUR = 0x040000, /* Send a Test Unit Ready command to the
90 * device, then retry the original command.
91 */
92 SS_MANUAL = 0x050000, /*
93 * This error must be handled manually,
94 * i.e. the code must look at the asc and
95 * ascq values and determine the proper
96 * course of action.
97 */
98 SS_TURSTART = 0x060000, /*
99 * Send a Test Unit Ready command to the
100 * device, and if that fails, send a start
101 * unit.
102 */
103 SS_MASK = 0xff0000
104 } scsi_sense_action;
105
106 typedef enum {
107 SSQ_NONE = 0x0000,
108 SSQ_DECREMENT_COUNT = 0x0100, /* Decrement the retry count */
109 SSQ_MANY = 0x0200, /* send lots of recovery commands */
110 SSQ_RANGE = 0x0400, /*
111 * Yes, this is a hack. Basically,
112 * if this flag is set then it
113 * represents an ascq range. The
114 * "correct" way to implement the
115 * ranges might be to add a special
116 * field to the sense code table,
117 * but that would take up a lot of
118 * additional space. This solution
119 * isn't as elegant, but is more
120 * space efficient.
121 */
122 SSQ_PRINT_SENSE = 0x0800,
123 SSQ_MASK = 0xff00
124 } scsi_sense_action_qualifier;
125
126 /* Mask for error status values */
127 #define SS_ERRMASK 0xff
128
129 /* The default error action */
130 #define SS_DEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
131
132 /* Default error action, without an error return value */
133 #define SS_NEDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
134
135 /* Default error action, without sense printing or an error return value */
136 #define SS_NEPDEF SS_RETRY|SSQ_DECREMENT_COUNT
137
138 struct scsi_generic
139 {
140 u_int8_t opcode;
141 u_int8_t bytes[11];
142 };
143
144 struct scsi_request_sense
145 {
146 u_int8_t opcode;
147 u_int8_t byte2;
148 u_int8_t unused[2];
149 u_int8_t length;
150 u_int8_t control;
151 };
152
153 struct scsi_test_unit_ready
154 {
155 u_int8_t opcode;
156 u_int8_t byte2;
157 u_int8_t unused[3];
158 u_int8_t control;
159 };
160
161 struct scsi_send_diag
162 {
163 u_int8_t opcode;
164 u_int8_t byte2;
165 #define SSD_UOL 0x01
166 #define SSD_DOL 0x02
167 #define SSD_SELFTEST 0x04
168 #define SSD_PF 0x10
169 u_int8_t unused[1];
170 u_int8_t paramlen[2];
171 u_int8_t control;
172 };
173
174 struct scsi_sense
175 {
176 u_int8_t opcode;
177 u_int8_t byte2;
178 u_int8_t unused[2];
179 u_int8_t length;
180 u_int8_t control;
181 };
182
183 struct scsi_inquiry
184 {
185 u_int8_t opcode;
186 u_int8_t byte2;
187 #define SI_EVPD 0x01
188 u_int8_t page_code;
189 u_int8_t reserved;
190 u_int8_t length;
191 u_int8_t control;
192 };
193
194 struct scsi_mode_sense_6
195 {
196 u_int8_t opcode;
197 u_int8_t byte2;
198 #define SMS_DBD 0x08
199 u_int8_t page;
200 #define SMS_PAGE_CODE 0x3F
201 #define SMS_VENDOR_SPECIFIC_PAGE 0x00
202 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02
203 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
204 #define SMS_CONTROL_MODE_PAGE 0x0A
205 #define SMS_ALL_PAGES_PAGE 0x3F
206 #define SMS_PAGE_CTRL_MASK 0xC0
207 #define SMS_PAGE_CTRL_CURRENT 0x00
208 #define SMS_PAGE_CTRL_CHANGEABLE 0x40
209 #define SMS_PAGE_CTRL_DEFAULT 0x80
210 #define SMS_PAGE_CTRL_SAVED 0xC0
211 u_int8_t unused;
212 u_int8_t length;
213 u_int8_t control;
214 };
215
216 struct scsi_mode_sense_10
217 {
218 u_int8_t opcode;
219 u_int8_t byte2; /* same bits as small version */
220 u_int8_t page; /* same bits as small version */
221 u_int8_t unused[4];
222 u_int8_t length[2];
223 u_int8_t control;
224 };
225
226 struct scsi_mode_select_6
227 {
228 u_int8_t opcode;
229 u_int8_t byte2;
230 #define SMS_SP 0x01
231 #define SMS_PF 0x10
232 u_int8_t unused[2];
233 u_int8_t length;
234 u_int8_t control;
235 };
236
237 struct scsi_mode_select_10
238 {
239 u_int8_t opcode;
240 u_int8_t byte2; /* same bits as small version */
241 u_int8_t unused[5];
242 u_int8_t length[2];
243 u_int8_t control;
244 };
245
246 /*
247 * When sending a mode select to a tape drive, the medium type must be 0.
248 */
249 struct scsi_mode_hdr_6
250 {
251 u_int8_t datalen;
252 u_int8_t medium_type;
253 u_int8_t dev_specific;
254 u_int8_t block_descr_len;
255 };
256
257 struct scsi_mode_hdr_10
258 {
259 u_int8_t datalen[2];
260 u_int8_t medium_type;
261 u_int8_t dev_specific;
262 u_int8_t reserved[2];
263 u_int8_t block_descr_len[2];
264 };
265
266 struct scsi_mode_block_descr
267 {
268 u_int8_t density_code;
269 u_int8_t num_blocks[3];
270 u_int8_t reserved;
271 u_int8_t block_len[3];
272 };
273
274 struct scsi_control_page {
275 u_int8_t page_code;
276 u_int8_t page_length;
277 u_int8_t rlec;
278 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/
279 u_int8_t queue_flags;
280 #define SCP_QUEUE_ALG_MASK 0xF0
281 #define SCP_QUEUE_ALG_RESTRICTED 0x00
282 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
283 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
284 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
285 u_int8_t eca_and_aen;
286 #define SCP_EECA 0x80 /*Enable Extended CA*/
287 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
288 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
289 #define SCP_EAENP 0x01 /*Error AEN Permission*/
290 u_int8_t reserved;
291 u_int8_t aen_holdoff_period[2];
292 };
293
294 struct scsi_reserve
295 {
296 u_int8_t opcode;
297 u_int8_t byte2;
298 u_int8_t unused[2];
299 u_int8_t length;
300 u_int8_t control;
301 };
302
303 struct scsi_release
304 {
305 u_int8_t opcode;
306 u_int8_t byte2;
307 u_int8_t unused[2];
308 u_int8_t length;
309 u_int8_t control;
310 };
311
312 struct scsi_prevent
313 {
314 u_int8_t opcode;
315 u_int8_t byte2;
316 u_int8_t unused[2];
317 u_int8_t how;
318 u_int8_t control;
319 };
320 #define PR_PREVENT 0x01
321 #define PR_ALLOW 0x00
322
323 struct scsi_sync_cache
324 {
325 u_int8_t opcode;
326 u_int8_t byte2;
327 u_int8_t begin_lba[4];
328 u_int8_t reserved;
329 u_int8_t lb_count[2];
330 u_int8_t control;
331 };
332
333
334 struct scsi_changedef
335 {
336 u_int8_t opcode;
337 u_int8_t byte2;
338 u_int8_t unused1;
339 u_int8_t how;
340 u_int8_t unused[4];
341 u_int8_t datalen;
342 u_int8_t control;
343 };
344
345 struct scsi_read_buffer
346 {
347 u_int8_t opcode;
348 u_int8_t byte2;
349 #define RWB_MODE 0x07
350 #define RWB_MODE_HDR_DATA 0x00
351 #define RWB_MODE_DATA 0x02
352 #define RWB_MODE_DOWNLOAD 0x04
353 #define RWB_MODE_DOWNLOAD_SAVE 0x05
354 u_int8_t buffer_id;
355 u_int8_t offset[3];
356 u_int8_t length[3];
357 u_int8_t control;
358 };
359
360 struct scsi_write_buffer
361 {
362 u_int8_t opcode;
363 u_int8_t byte2;
364 u_int8_t buffer_id;
365 u_int8_t offset[3];
366 u_int8_t length[3];
367 u_int8_t control;
368 };
369
370 struct scsi_rw_6
371 {
372 u_int8_t opcode;
373 u_int8_t addr[3];
374 /* only 5 bits are valid in the MSB address byte */
375 #define SRW_TOPADDR 0x1F
376 u_int8_t length;
377 u_int8_t control;
378 };
379
380 struct scsi_rw_10
381 {
382 u_int8_t opcode;
383 #define SRW10_RELADDR 0x01
384 #define SRW10_FUA 0x08
385 #define SRW10_DPO 0x10
386 u_int8_t byte2;
387 u_int8_t addr[4];
388 u_int8_t reserved;
389 u_int8_t length[2];
390 u_int8_t control;
391 };
392
393 struct scsi_rw_12
394 {
395 u_int8_t opcode;
396 #define SRW12_RELADDR 0x01
397 #define SRW12_FUA 0x08
398 #define SRW12_DPO 0x10
399 u_int8_t byte2;
400 u_int8_t addr[4];
401 u_int8_t reserved;
402 u_int8_t length[4];
403 u_int8_t control;
404 };
405
406 struct scsi_start_stop_unit
407 {
408 u_int8_t opcode;
409 u_int8_t byte2;
410 #define SSS_IMMED 0x01
411 u_int8_t reserved[2];
412 u_int8_t how;
413 #define SSS_START 0x01
414 #define SSS_LOEJ 0x02
415 u_int8_t control;
416 };
417
418 #define SC_SCSI_1 0x01
419 #define SC_SCSI_2 0x03
420
421 /*
422 * Opcodes
423 */
424
425 #define TEST_UNIT_READY 0x00
426 #define REQUEST_SENSE 0x03
427 #define READ_6 0x08
428 #define WRITE_6 0x0a
429 #define INQUIRY 0x12
430 #define MODE_SELECT_6 0x15
431 #define MODE_SENSE_6 0x1a
432 #define START_STOP_UNIT 0x1b
433 #define START_STOP 0x1b
434 #define RESERVE 0x16
435 #define RELEASE 0x17
436 #define PREVENT_ALLOW 0x1e
437 #define READ_CAPACITY 0x25
438 #define READ_10 0x28
439 #define WRITE_10 0x2a
440 #define POSITION_TO_ELEMENT 0x2b
441 #define SYNCHRONIZE_CACHE 0x35
442 #define WRITE_BUFFER 0x3b
443 #define READ_BUFFER 0x3c
444 #define CHANGE_DEFINITION 0x40
445 #define MODE_SELECT_10 0x55
446 #define MODE_SENSE_10 0x5A
447 #define MOVE_MEDIUM 0xa5
448 #define READ_12 0xa8
449 #define WRITE_12 0xaa
450 #define READ_ELEMENT_STATUS 0xb8
451
452
453 /*
454 * Device Types
455 */
456 #define T_DIRECT 0x00
457 #define T_SEQUENTIAL 0x01
458 #define T_PRINTER 0x02
459 #define T_PROCESSOR 0x03
460 #define T_WORM 0x04
461 #define T_CDROM 0x05
462 #define T_SCANNER 0x06
463 #define T_OPTICAL 0x07
464 #define T_CHANGER 0x08
465 #define T_COMM 0x09
466 #define T_ASC0 0x0a
467 #define T_ASC1 0x0b
468 #define T_STORARRAY 0x0c
469 #define T_ENCLOSURE 0x0d
470 #define T_NODEVICE 0x1F
471 #define T_ANY 0xFF /* Used in Quirk table matches */
472
473 #define T_REMOV 1
474 #define T_FIXED 0
475
476 struct scsi_inquiry_data
477 {
478 u_int8_t device;
479 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
480 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
481 #define SID_QUAL_LU_CONNECTED 0x00 /* The specified peripheral device
482 * type is currently connected to
483 * logical unit. If the target cannot
484 * determine whether or not a physical
485 * device is currently connected, it
486 * shall also use this peripheral
487 * qualifier when returning the INQUIRY
488 * data. This peripheral qualifier
489 * does not mean that the device is
490 * ready for access by the initiator.
491 */
492 #define SID_QUAL_LU_OFFLINE 0x01 /* The target is capable of supporting
493 * the specified peripheral device type
494 * on this logical unit; however, the
495 * physical device is not currently
496 * connected to this logical unit.
497 */
498 #define SID_QUAL_RSVD 0x02
499 #define SID_QUAL_BAD_LU 0x03 /* The target is not capable of
500 * supporting a physical device on
501 * this logical unit. For this
502 * peripheral qualifier the peripheral
503 * device type shall be set to 1Fh to
504 * provide compatibility with previous
505 * versions of SCSI. All other
506 * peripheral device type values are
507 * reserved for this peripheral
508 * qualifier.
509 */
510 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
511 u_int8_t dev_qual2;
512 #define SID_QUAL2 0x7F
513 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
514 u_int8_t version;
515 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
516 #define SCSI_REV_0 0
517 #define SCSI_REV_CCS 1
518 #define SCSI_REV_2 2
519 #define SCSI_REV_3 3
520
521 #define SID_ECMA 0x38
522 #define SID_ISO 0xC0
523 u_int8_t response_format;
524 #define SID_AENC 0x80
525 #define SID_TrmIOP 0x40
526 u_int8_t additional_length;
527 u_int8_t reserved[2];
528 u_int8_t flags;
529 #define SID_SftRe 0x01
530 #define SID_CmdQue 0x02
531 #define SID_Linked 0x08
532 #define SID_Sync 0x10
533 #define SID_WBus16 0x20
534 #define SID_WBus32 0x40
535 #define SID_RelAdr 0x80
536 #define SID_VENDOR_SIZE 8
537 char vendor[SID_VENDOR_SIZE];
538 #define SID_PRODUCT_SIZE 16
539 char product[SID_PRODUCT_SIZE];
540 #define SID_REVISION_SIZE 4
541 char revision[SID_REVISION_SIZE];
542 };
543
544 struct scsi_vpd_unit_serial_number
545 {
546 u_int8_t device;
547 u_int8_t page_code;
548 #define SVPD_UNIT_SERIAL_NUMBER 0x80
549 u_int8_t reserved;
550 u_int8_t length; /* serial number length */
551 #define SVPD_SERIAL_NUM_SIZE 251
552 char serial_num[SVPD_SERIAL_NUM_SIZE];
553 };
554
555 struct scsi_read_capacity
556 {
557 u_int8_t opcode;
558 u_int8_t byte2;
559 u_int8_t addr[4];
560 u_int8_t unused[3];
561 u_int8_t control;
562 };
563
564 struct scsi_read_capacity_data
565 {
566 u_int8_t addr[4];
567 u_int8_t length[4];
568 };
569
570 struct scsi_sense_data
571 {
572 u_int8_t error_code;
573 #define SSD_ERRCODE 0x7F
574 #define SSD_CURRENT_ERROR 0x70
575 #define SSD_DEFERRED_ERROR 0x71
576 #define SSD_ERRCODE_VALID 0x80
577 u_int8_t segment;
578 u_int8_t flags;
579 #define SSD_KEY 0x0F
580 #define SSD_KEY_NO_SENSE 0x00
581 #define SSD_KEY_RECOVERED_ERROR 0x01
582 #define SSD_KEY_NOT_READY 0x02
583 #define SSD_KEY_MEDIUM_ERROR 0x03
584 #define SSD_KEY_HARDWARE_ERROR 0x04
585 #define SSD_KEY_ILLEGAL_REQUEST 0x05
586 #define SSD_KEY_UNIT_ATTENTION 0x06
587 #define SSD_KEY_DATA_PROTECT 0x07
588 #define SSD_KEY_BLANK_CHECK 0x08
589 #define SSD_KEY_Vendor_Specific 0x09
590 #define SSD_KEY_COPY_ABORTED 0x0a
591 #define SSD_KEY_ABORTED_COMMAND 0x0b
592 #define SSD_KEY_EQUAL 0x0c
593 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
594 #define SSD_KEY_MISCOMPARE 0x0e
595 #define SSD_KEY_RESERVED 0x0f
596 #define SSD_ILI 0x20
597 #define SSD_EOM 0x40
598 #define SSD_FILEMARK 0x80
599 u_int8_t info[4];
600 u_int8_t extra_len;
601 u_int8_t cmd_spec_info[4];
602 u_int8_t add_sense_code;
603 u_int8_t add_sense_code_qual;
604 u_int8_t fru;
605 u_int8_t sense_key_spec[3];
606 #define SSD_SCS_VALID 0x80
607 #define SSD_FIELDPTR_CMD 0x40
608 #define SSD_BITPTR_VALID 0x08
609 #define SSD_BITPTR_VALUE 0x07
610 #define SSD_MIN_SIZE 18
611 u_int8_t extra_bytes[14];
612 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
613 };
614
615 struct scsi_mode_header_6
616 {
617 u_int8_t data_length; /* Sense data length */
618 u_int8_t medium_type;
619 u_int8_t dev_spec;
620 u_int8_t blk_desc_len;
621 };
622
623 struct scsi_mode_header_10
624 {
625 u_int8_t data_length[2];/* Sense data length */
626 u_int8_t medium_type;
627 u_int8_t dev_spec;
628 u_int8_t unused[2];
629 u_int8_t blk_desc_len[2];
630 };
631
632 struct scsi_mode_blk_desc
633 {
634 u_int8_t density;
635 u_int8_t nblocks[3];
636 u_int8_t reserved;
637 u_int8_t blklen[3];
638 };
639
640 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
641 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
642 /*
643 * Status Byte
644 */
645 #define SCSI_STATUS_OK 0x00
646 #define SCSI_STATUS_CHECK_COND 0x02
647 #define SCSI_STATUS_COND_MET 0x04
648 #define SCSI_STATUS_BUSY 0x08
649 #define SCSI_STATUS_INTERMED 0x10
650 #define SCSI_STATUS_INTERMED_COND_MET 0x14
651 #define SCSI_STATUS_RESERV_CONFLICT 0x18
652 #define SCSI_STATUS_CMD_TERMINATED 0x22
653 #define SCSI_STATUS_QUEUE_FULL 0x28
654
655 struct scsi_inquiry_pattern {
656 u_int8_t type;
657 u_int8_t media_type;
658 #define SIP_MEDIA_REMOVABLE 0x01
659 #define SIP_MEDIA_FIXED 0x02
660 const char *vendor;
661 const char *product;
662 const char *revision;
663 };
664
665 struct scsi_static_inquiry_pattern {
666 u_int8_t type;
667 u_int8_t media_type;
668 char vendor[SID_VENDOR_SIZE+1];
669 char product[SID_PRODUCT_SIZE+1];
670 char revision[SID_REVISION_SIZE+1];
671 };
672
673 struct scsi_sense_quirk_entry {
674 struct scsi_inquiry_pattern inq_pat;
675 int num_ascs;
676 struct asc_table_entry *asc_info;
677 };
678
679 struct asc_table_entry {
680 u_int8_t asc;
681 u_int8_t ascq;
682 u_int32_t action;
683 #if !defined(SCSI_NO_SENSE_STRINGS)
684 const char *desc;
685 #endif
686 };
687
688 struct op_table_entry {
689 u_int8_t opcode;
690 u_int16_t opmask;
691 const char *desc;
692 };
693
694 struct scsi_op_quirk_entry {
695 struct scsi_inquiry_pattern inq_pat;
696 int num_ops;
697 struct op_table_entry *op_table;
698 };
699
700
701 struct ccb_scsiio;
702 struct cam_periph;
703 union ccb;
704 #ifndef KERNEL
705 struct cam_device;
706 #endif
707
708 extern const char *scsi_sense_key_text[];
709
710 __BEGIN_DECLS
711 const char * scsi_sense_desc(int asc, int ascq,
712 struct scsi_inquiry_data *inq_data);
713 scsi_sense_action scsi_error_action(int asc, int ascq,
714 struct scsi_inquiry_data *inq_data);
715 #ifdef KERNEL
716 void scsi_sense_print(struct ccb_scsiio *csio);
717 int scsi_interpret_sense(union ccb *ccb,
718 u_int32_t sense_flags,
719 u_int32_t *relsim_flags,
720 u_int32_t *reduction,
721 u_int32_t *timeout,
722 scsi_sense_action error_action);
723 #else
724 char * scsi_sense_string(struct cam_device *device,
725 struct ccb_scsiio *csio,
726 char *str, int str_len);
727 void scsi_sense_print(struct cam_device *device,
728 struct ccb_scsiio *csio, FILE *ofile);
729 int scsi_interpret_sense(struct cam_device *device,
730 union ccb *ccb,
731 u_int32_t sense_flags,
732 u_int32_t *relsim_flags,
733 u_int32_t *reduction,
734 u_int32_t *timeout,
735 scsi_sense_action error_action);
736 #endif /* KERNEL */
737
738 #define SF_RETRY_UA 0x01
739 #define SF_NO_PRINT 0x02
740 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
741 #define SF_PRINT_ALWAYS 0x08
742 #define SF_RETRY_SELTO 0x10 /* Retry selection timeouts */
743
744
745 const char * scsi_op_desc(u_int16_t opcode,
746 struct scsi_inquiry_data *inq_data);
747 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
748 size_t len);
749
750 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
751
752 u_int scsi_calc_syncsrate(u_int period_factor);
753 u_int scsi_calc_syncparam(u_int period);
754
755 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
756 void (*cbfcnp)(struct cam_periph *,
757 union ccb *),
758 u_int8_t tag_action,
759 u_int8_t sense_len, u_int32_t timeout);
760
761 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
762 void (*cbfcnp)(struct cam_periph *,
763 union ccb *),
764 void *data_ptr, u_int8_t dxfer_len,
765 u_int8_t tag_action, u_int8_t sense_len,
766 u_int32_t timeout);
767
768 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
769 void (*cbfcnp)(struct cam_periph *, union ccb *),
770 u_int8_t tag_action, u_int8_t *inq_buf,
771 u_int32_t inq_len, int evpd, u_int8_t page_code,
772 u_int8_t sense_len, u_int32_t timeout);
773
774 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
775 void (*cbfcnp)(struct cam_periph *,
776 union ccb *),
777 u_int8_t tag_action, int dbd,
778 u_int8_t page_code, u_int8_t page,
779 u_int8_t *param_buf, u_int32_t param_len,
780 u_int8_t sense_len, u_int32_t timeout);
781
782 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
783 void (*cbfcnp)(struct cam_periph *,
784 union ccb *),
785 u_int8_t tag_action, int scsi_page_fmt,
786 int save_pages, u_int8_t *param_buf,
787 u_int32_t param_len, u_int8_t sense_len,
788 u_int32_t timeout);
789
790 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
791 void (*cbfcnp)(struct cam_periph *,
792 union ccb *), u_int8_t tag_action,
793 struct scsi_read_capacity_data *rcap_buf,
794 u_int8_t sense_len, u_int32_t timeout);
795
796 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
797 void (*cbfcnp)(struct cam_periph *, union ccb *),
798 u_int8_t tag_action, u_int8_t action,
799 u_int8_t sense_len, u_int32_t timeout);
800
801 void scsi_synchronize_cache(struct ccb_scsiio *csio,
802 u_int32_t retries,
803 void (*cbfcnp)(struct cam_periph *,
804 union ccb *), u_int8_t tag_action,
805 u_int32_t begin_lba, u_int16_t lb_count,
806 u_int8_t sense_len, u_int32_t timeout);
807
808 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
809 void (*cbfcnp)(struct cam_periph *, union ccb *),
810 u_int8_t tag_action, int readop, u_int8_t byte2,
811 int minimum_cmd_size, u_int32_t lba,
812 u_int32_t block_count, u_int8_t *data_ptr,
813 u_int32_t dxfer_len, u_int8_t sense_len,
814 u_int32_t timeout);
815
816 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
817 void (*cbfcnp)(struct cam_periph *, union ccb *),
818 u_int8_t tag_action, int start, int load_eject,
819 int immediate, u_int8_t sense_len, u_int32_t timeout);
820
821 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
822 int scsi_static_inquiry_match(caddr_t inqbuffer,
823 caddr_t table_entry);
824
825 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
826 int *error_code, int *sense_key,
827 int *asc, int *ascq);
828 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
829 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
830 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
831 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes);
832 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes);
833 static __inline int32_t scsi_3btol(u_int8_t *bytes);
834 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes);
835 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
836 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
837
838 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
839 int *error_code, int *sense_key,
840 int *asc, int *ascq)
841 {
842 *error_code = sense->error_code & SSD_ERRCODE;
843 *sense_key = sense->flags & SSD_KEY;
844 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
845 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
846 }
847
848 static __inline void
849 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
850 {
851
852 bytes[0] = (val >> 8) & 0xff;
853 bytes[1] = val & 0xff;
854 }
855
856 static __inline void
857 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
858 {
859
860 bytes[0] = (val >> 16) & 0xff;
861 bytes[1] = (val >> 8) & 0xff;
862 bytes[2] = val & 0xff;
863 }
864
865 static __inline void
866 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
867 {
868
869 bytes[0] = (val >> 24) & 0xff;
870 bytes[1] = (val >> 16) & 0xff;
871 bytes[2] = (val >> 8) & 0xff;
872 bytes[3] = val & 0xff;
873 }
874
875 static __inline u_int32_t
876 scsi_2btoul(u_int8_t *bytes)
877 {
878 u_int32_t rv;
879
880 rv = (bytes[0] << 8) |
881 bytes[1];
882 return (rv);
883 }
884
885 static __inline u_int32_t
886 scsi_3btoul(u_int8_t *bytes)
887 {
888 u_int32_t rv;
889
890 rv = (bytes[0] << 16) |
891 (bytes[1] << 8) |
892 bytes[2];
893 return (rv);
894 }
895
896 static __inline int32_t
897 scsi_3btol(u_int8_t *bytes)
898 {
899 u_int32_t rc = scsi_3btoul(bytes);
900
901 if (rc & 0x00800000)
902 rc |= 0xff000000;
903
904 return (int32_t) rc;
905 }
906
907 static __inline u_int32_t
908 scsi_4btoul(u_int8_t *bytes)
909 {
910 u_int32_t rv;
911
912 rv = (bytes[0] << 24) |
913 (bytes[1] << 16) |
914 (bytes[2] << 8) |
915 bytes[3];
916 return (rv);
917 }
918
919 /*
920 * Given the pointer to a returned mode sense buffer, return a pointer to
921 * the start of the first mode page.
922 */
923 static __inline void *
924 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
925 {
926 void *page_start;
927
928 page_start = (void *)((u_int8_t *)&mode_header[1] +
929 mode_header->blk_desc_len);
930
931 return(page_start);
932 }
933
934 static __inline void *
935 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
936 {
937 void *page_start;
938
939 page_start = (void *)((u_int8_t *)&mode_header[1] +
940 scsi_2btoul(mode_header->blk_desc_len));
941
942 return(page_start);
943 }
944
945 __END_DECLS
946
947 #endif /*_SCSI_SCSI_ALL_H*/
Cache object: 5c24177574ba7501bc9fa9c645f400ac
|