The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/cam/scsi/scsi_all.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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: releng/9.0/sys/cam/scsi/scsi_all.h 226067 2011-10-06 19:15:51Z ken $
   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 #include <machine/stdarg.h>
   29 
   30 #ifdef _KERNEL
   31 /*
   32  * This is the number of seconds we wait for devices to settle after a SCSI
   33  * bus reset.
   34  */
   35 extern int scsi_delay;
   36 #endif /* _KERNEL */
   37 
   38 /*
   39  * SCSI command format
   40  */
   41 
   42 /*
   43  * Define dome bits that are in ALL (or a lot of) scsi commands
   44  */
   45 #define SCSI_CTL_LINK           0x01
   46 #define SCSI_CTL_FLAG           0x02
   47 #define SCSI_CTL_VENDOR         0xC0
   48 #define SCSI_CMD_LUN            0xA0    /* these two should not be needed */
   49 #define SCSI_CMD_LUN_SHIFT      5       /* LUN in the cmd is no longer SCSI */
   50 
   51 #define SCSI_MAX_CDBLEN         16      /* 
   52                                          * 16 byte commands are in the 
   53                                          * SCSI-3 spec 
   54                                          */
   55 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN)
   56 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN"
   57 #endif
   58 
   59 /* 6byte CDBs special case 0 length to be 256 */
   60 #define SCSI_CDB6_LEN(len)      ((len) == 0 ? 256 : len)
   61 
   62 /*
   63  * This type defines actions to be taken when a particular sense code is
   64  * received.  Right now, these flags are only defined to take up 16 bits,
   65  * but can be expanded in the future if necessary.
   66  */
   67 typedef enum {
   68         SS_NOP      = 0x000000, /* Do nothing */
   69         SS_RETRY    = 0x010000, /* Retry the command */
   70         SS_FAIL     = 0x020000, /* Bail out */
   71         SS_START    = 0x030000, /* Send a Start Unit command to the device,
   72                                  * then retry the original command.
   73                                  */
   74         SS_TUR      = 0x040000, /* Send a Test Unit Ready command to the
   75                                  * device, then retry the original command.
   76                                  */
   77         SS_REQSENSE = 0x050000, /* Send a RequestSense command to the
   78                                  * device, then retry the original command.
   79                                  */
   80         SS_MASK     = 0xff0000
   81 } scsi_sense_action;
   82 
   83 typedef enum {
   84         SSQ_NONE                = 0x0000,
   85         SSQ_DECREMENT_COUNT     = 0x0100,  /* Decrement the retry count */
   86         SSQ_MANY                = 0x0200,  /* send lots of recovery commands */
   87         SSQ_RANGE               = 0x0400,  /*
   88                                             * This table entry represents the
   89                                             * end of a range of ASCQs that
   90                                             * have identical error actions
   91                                             * and text.
   92                                             */
   93         SSQ_PRINT_SENSE         = 0x0800,
   94         SSQ_MASK                = 0xff00
   95 } scsi_sense_action_qualifier;
   96 
   97 /* Mask for error status values */
   98 #define SS_ERRMASK      0xff
   99 
  100 /* The default, retyable, error action */
  101 #define SS_RDEF         SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
  102 
  103 /* The retyable, error action, with table specified error code */
  104 #define SS_RET          SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
  105 
  106 /* Fatal error action, with table specified error code */
  107 #define SS_FATAL        SS_FAIL|SSQ_PRINT_SENSE
  108 
  109 struct scsi_generic
  110 {
  111         u_int8_t opcode;
  112         u_int8_t bytes[11];
  113 };
  114 
  115 struct scsi_request_sense
  116 {
  117         u_int8_t opcode;
  118         u_int8_t byte2;
  119 #define SRS_DESC        0x01
  120         u_int8_t unused[2];
  121         u_int8_t length;
  122         u_int8_t control;
  123 };
  124 
  125 struct scsi_test_unit_ready
  126 {
  127         u_int8_t opcode;
  128         u_int8_t byte2;
  129         u_int8_t unused[3];
  130         u_int8_t control;
  131 };
  132 
  133 struct scsi_receive_diag {
  134         uint8_t opcode;
  135         uint8_t byte2;
  136 #define SRD_PCV         0x01
  137         uint8_t page_code;
  138         uint8_t length[2]; 
  139         uint8_t control;
  140 };
  141 
  142 struct scsi_send_diag {
  143         uint8_t opcode;
  144         uint8_t byte2;
  145 #define SSD_UNITOFFL                            0x01
  146 #define SSD_DEVOFFL                             0x02
  147 #define SSD_SELFTEST                            0x04
  148 #define SSD_PF                                  0x10
  149 #define SSD_SELF_TEST_CODE_MASK                 0xE0
  150 #define SSD_SELF_TEST_CODE_SHIFT                5
  151 #define         SSD_SELF_TEST_CODE_NONE         0x00
  152 #define         SSD_SELF_TEST_CODE_BG_SHORT     0x01
  153 #define         SSD_SELF_TEST_CODE_BG_EXTENDED  0x02
  154 #define         SSD_SELF_TEST_CODE_BG_ABORT     0x04
  155 #define         SSD_SELF_TEST_CODE_FG_SHORT     0x05
  156 #define         SSD_SELF_TEST_CODE_FG_EXTENDED  0x06
  157         uint8_t reserved;
  158         uint8_t length[2];
  159         uint8_t control;
  160 };
  161 
  162 struct scsi_sense
  163 {
  164         u_int8_t opcode;
  165         u_int8_t byte2;
  166         u_int8_t unused[2];
  167         u_int8_t length;
  168         u_int8_t control;
  169 };
  170 
  171 struct scsi_inquiry
  172 {
  173         u_int8_t opcode;
  174         u_int8_t byte2;
  175 #define SI_EVPD         0x01
  176 #define SI_CMDDT        0x02
  177         u_int8_t page_code;
  178         u_int8_t reserved;
  179         u_int8_t length;
  180         u_int8_t control;
  181 };
  182 
  183 struct scsi_mode_sense_6
  184 {
  185         u_int8_t opcode;
  186         u_int8_t byte2;
  187 #define SMS_DBD                         0x08
  188         u_int8_t page;
  189 #define SMS_PAGE_CODE                   0x3F
  190 #define SMS_VENDOR_SPECIFIC_PAGE        0x00
  191 #define SMS_DISCONNECT_RECONNECT_PAGE   0x02
  192 #define SMS_FORMAT_DEVICE_PAGE          0x03
  193 #define SMS_GEOMETRY_PAGE               0x04
  194 #define SMS_CACHE_PAGE                  0x08
  195 #define SMS_PERIPHERAL_DEVICE_PAGE      0x09
  196 #define SMS_CONTROL_MODE_PAGE           0x0A
  197 #define SMS_PROTO_SPECIFIC_PAGE         0x19
  198 #define SMS_INFO_EXCEPTIONS_PAGE        0x1C
  199 #define SMS_ALL_PAGES_PAGE              0x3F
  200 #define SMS_PAGE_CTRL_MASK              0xC0
  201 #define SMS_PAGE_CTRL_CURRENT           0x00
  202 #define SMS_PAGE_CTRL_CHANGEABLE        0x40
  203 #define SMS_PAGE_CTRL_DEFAULT           0x80
  204 #define SMS_PAGE_CTRL_SAVED             0xC0
  205         u_int8_t subpage;
  206 #define SMS_SUBPAGE_PAGE_0              0x00
  207 #define SMS_SUBPAGE_ALL                 0xff
  208         u_int8_t length;
  209         u_int8_t control;
  210 };
  211 
  212 struct scsi_mode_sense_10
  213 {
  214         u_int8_t opcode;
  215         u_int8_t byte2;         /* same bits as small version */
  216 #define SMS10_LLBAA                     0x10
  217         u_int8_t page;          /* same bits as small version */
  218         u_int8_t subpage;
  219         u_int8_t unused[3];
  220         u_int8_t length[2];
  221         u_int8_t control;
  222 };
  223 
  224 struct scsi_mode_select_6
  225 {
  226         u_int8_t opcode;
  227         u_int8_t byte2;
  228 #define SMS_SP  0x01
  229 #define SMS_PF  0x10
  230         u_int8_t unused[2];
  231         u_int8_t length;
  232         u_int8_t control;
  233 };
  234 
  235 struct scsi_mode_select_10
  236 {
  237         u_int8_t opcode;
  238         u_int8_t byte2;         /* same bits as small version */
  239         u_int8_t unused[5];
  240         u_int8_t length[2];
  241         u_int8_t control;
  242 };
  243 
  244 /*
  245  * When sending a mode select to a tape drive, the medium type must be 0.
  246  */
  247 struct scsi_mode_hdr_6
  248 {
  249         u_int8_t datalen;
  250         u_int8_t medium_type;
  251         u_int8_t dev_specific;
  252         u_int8_t block_descr_len;
  253 };
  254 
  255 struct scsi_mode_hdr_10
  256 {
  257         u_int8_t datalen[2];
  258         u_int8_t medium_type;
  259         u_int8_t dev_specific;
  260         u_int8_t reserved[2];
  261         u_int8_t block_descr_len[2];
  262 };
  263 
  264 struct scsi_mode_block_descr
  265 {
  266         u_int8_t density_code;
  267         u_int8_t num_blocks[3];
  268         u_int8_t reserved;
  269         u_int8_t block_len[3];
  270 };
  271 
  272 struct scsi_per_res_in
  273 {
  274         u_int8_t opcode;
  275         u_int8_t action;
  276 #define SPRI_RK 0x00
  277 #define SPRI_RR 0x01
  278 #define SPRI_RC 0x02
  279 #define SPRI_RS 0x03
  280         u_int8_t reserved[5];
  281         u_int8_t length[2];
  282         u_int8_t control;
  283 };
  284 
  285 struct scsi_per_res_in_header
  286 {
  287         u_int8_t generation[4];
  288         u_int8_t length[4];
  289 };
  290 
  291 struct scsi_per_res_key
  292 {
  293         u_int8_t key[8];
  294 };
  295 
  296 struct scsi_per_res_in_keys
  297 {
  298         struct scsi_per_res_in_header header;
  299         struct scsi_per_res_key keys[0];
  300 };
  301 
  302 struct scsi_per_res_cap
  303 {
  304         uint8_t length[2];
  305         uint8_t flags1;
  306 #define SPRI_CRH        0x10
  307 #define SPRI_SIP_C      0x08
  308 #define SPRI_ATP_C      0x04
  309 #define SPRI_PTPL_C     0x01
  310         uint8_t flags2;
  311 #define SPRI_TMV        0x80
  312 #define SPRI_PTPL_A     0x01
  313         uint8_t type_mask[2];
  314 #define SPRI_TM_WR_EX_AR        0x8000
  315 #define SPRI_TM_EX_AC_RO        0x4000
  316 #define SPRI_TM_WR_EX_RO        0x2000
  317 #define SPRI_TM_EX_AC           0x0800
  318 #define SPRI_TM_WR_EX           0x0200
  319 #define SPRI_TM_EX_AC_AR        0x0001
  320         uint8_t reserved[2];
  321 };
  322 
  323 struct scsi_per_res_in_rsrv_data
  324 {
  325         uint8_t reservation[8];
  326         uint8_t obsolete1[4];
  327         uint8_t reserved;
  328         uint8_t scopetype;
  329 #define SPRT_WE    0x01
  330 #define SPRT_EA    0x03
  331 #define SPRT_WERO  0x05
  332 #define SPRT_EARO  0x06
  333 #define SPRT_WEAR  0x07
  334 #define SPRT_EAAR  0x08
  335         uint8_t obsolete2[2];
  336 };
  337 
  338 struct scsi_per_res_in_rsrv
  339 {
  340         struct scsi_per_res_in_header header;
  341         struct scsi_per_res_in_rsrv_data data;
  342 };
  343 
  344 struct scsi_per_res_out
  345 {
  346         u_int8_t opcode;
  347         u_int8_t action;
  348 #define SPRO_REGISTER           0x00
  349 #define SPRO_RESERVE            0x01
  350 #define SPRO_RELEASE            0x02
  351 #define SPRO_CLEAR              0x03
  352 #define SPRO_PREEMPT            0x04
  353 #define SPRO_PRE_ABO            0x05
  354 #define SPRO_REG_IGNO           0x06
  355 #define SPRO_REG_MOVE           0x07
  356 #define SPRO_ACTION_MASK        0x1f
  357         u_int8_t scope_type;
  358 #define SPR_SCOPE_MASK          0xf0
  359 #define SPR_LU_SCOPE            0x00
  360 #define SPR_TYPE_MASK           0x0f
  361 #define SPR_TYPE_WR_EX          0x01
  362 #define SPR_TYPE_EX_AC          0x03
  363 #define SPR_TYPE_WR_EX_RO       0x05
  364 #define SPR_TYPE_EX_AC_RO       0x06
  365 #define SPR_TYPE_WR_EX_AR       0x07
  366 #define SPR_TYPE_EX_AC_AR       0x08
  367         u_int8_t reserved[2];
  368         u_int8_t length[4];
  369         u_int8_t control;
  370 };
  371 
  372 struct scsi_per_res_out_parms
  373 {
  374         struct scsi_per_res_key res_key;
  375         u_int8_t serv_act_res_key[8];
  376         u_int8_t obsolete1[4];
  377         u_int8_t flags;
  378 #define SPR_SPEC_I_PT           0x08
  379 #define SPR_ALL_TG_PT           0x04
  380 #define SPR_APTPL               0x01
  381         u_int8_t reserved1;
  382         u_int8_t obsolete2[2];
  383 };
  384 
  385 
  386 struct scsi_log_sense
  387 {
  388         u_int8_t opcode;
  389         u_int8_t byte2;
  390 #define SLS_SP                          0x01
  391 #define SLS_PPC                         0x02
  392         u_int8_t page;
  393 #define SLS_PAGE_CODE                   0x3F
  394 #define SLS_ALL_PAGES_PAGE              0x00
  395 #define SLS_OVERRUN_PAGE                0x01
  396 #define SLS_ERROR_WRITE_PAGE            0x02
  397 #define SLS_ERROR_READ_PAGE             0x03
  398 #define SLS_ERROR_READREVERSE_PAGE      0x04
  399 #define SLS_ERROR_VERIFY_PAGE           0x05
  400 #define SLS_ERROR_NONMEDIUM_PAGE        0x06
  401 #define SLS_ERROR_LASTN_PAGE            0x07
  402 #define SLS_SELF_TEST_PAGE              0x10
  403 #define SLS_IE_PAGE                     0x2f
  404 #define SLS_PAGE_CTRL_MASK              0xC0
  405 #define SLS_PAGE_CTRL_THRESHOLD         0x00
  406 #define SLS_PAGE_CTRL_CUMULATIVE        0x40
  407 #define SLS_PAGE_CTRL_THRESH_DEFAULT    0x80
  408 #define SLS_PAGE_CTRL_CUMUL_DEFAULT     0xC0
  409         u_int8_t reserved[2];
  410         u_int8_t paramptr[2];
  411         u_int8_t length[2];
  412         u_int8_t control;
  413 };
  414 
  415 struct scsi_log_select
  416 {
  417         u_int8_t opcode;
  418         u_int8_t byte2;
  419 /*      SLS_SP                          0x01 */
  420 #define SLS_PCR                         0x02
  421         u_int8_t page;
  422 /*      SLS_PAGE_CTRL_MASK              0xC0 */
  423 /*      SLS_PAGE_CTRL_THRESHOLD         0x00 */
  424 /*      SLS_PAGE_CTRL_CUMULATIVE        0x40 */
  425 /*      SLS_PAGE_CTRL_THRESH_DEFAULT    0x80 */
  426 /*      SLS_PAGE_CTRL_CUMUL_DEFAULT     0xC0 */
  427         u_int8_t reserved[4];
  428         u_int8_t length[2];
  429         u_int8_t control;
  430 };
  431 
  432 struct scsi_log_header
  433 {
  434         u_int8_t page;
  435         u_int8_t reserved;
  436         u_int8_t datalen[2];
  437 };
  438 
  439 struct scsi_log_param_header {
  440         u_int8_t param_code[2];
  441         u_int8_t param_control;
  442 #define SLP_LP                          0x01
  443 #define SLP_LBIN                        0x02
  444 #define SLP_TMC_MASK                    0x0C
  445 #define SLP_TMC_ALWAYS                  0x00
  446 #define SLP_TMC_EQUAL                   0x04
  447 #define SLP_TMC_NOTEQUAL                0x08
  448 #define SLP_TMC_GREATER                 0x0C
  449 #define SLP_ETC                         0x10
  450 #define SLP_TSD                         0x20
  451 #define SLP_DS                          0x40
  452 #define SLP_DU                          0x80
  453         u_int8_t param_len;
  454 };
  455 
  456 struct scsi_control_page {
  457         u_int8_t page_code;
  458         u_int8_t page_length;
  459         u_int8_t rlec;
  460 #define SCP_RLEC                        0x01    /*Report Log Exception Cond*/
  461 #define SCP_GLTSD                       0x02    /*Global Logging target
  462                                                   save disable */
  463 #define SCP_DSENSE                      0x04    /*Descriptor Sense */
  464 #define SCP_DPICZ                       0x08    /*Disable Prot. Info Check
  465                                                   if Prot. Field is Zero */
  466 #define SCP_TMF_ONLY                    0x10    /*TM Functions Only*/
  467 #define SCP_TST_MASK                    0xE0    /*Task Set Type Mask*/
  468 #define SCP_TST_ONE                     0x00    /*One Task Set*/
  469 #define SCP_TST_SEPARATE                0x20    /*Separate Task Sets*/
  470         u_int8_t queue_flags;
  471 #define SCP_QUEUE_ALG_MASK              0xF0
  472 #define SCP_QUEUE_ALG_RESTRICTED        0x00
  473 #define SCP_QUEUE_ALG_UNRESTRICTED      0x10
  474 #define SCP_QUEUE_ERR                   0x02    /*Queued I/O aborted for CACs*/
  475 #define SCP_QUEUE_DQUE                  0x01    /*Queued I/O disabled*/
  476         u_int8_t eca_and_aen;
  477 #define SCP_EECA                        0x80    /*Enable Extended CA*/
  478 #define SCP_RAENP                       0x04    /*Ready AEN Permission*/
  479 #define SCP_UAAENP                      0x02    /*UA AEN Permission*/
  480 #define SCP_EAENP                       0x01    /*Error AEN Permission*/
  481         u_int8_t reserved;
  482         u_int8_t aen_holdoff_period[2];
  483 };
  484 
  485 struct scsi_cache_page {
  486         u_int8_t page_code;
  487 #define SCHP_PAGE_SAVABLE               0x80    /* Page is savable */
  488         u_int8_t page_length;
  489         u_int8_t cache_flags;
  490 #define SCHP_FLAGS_WCE                  0x04    /* Write Cache Enable */
  491 #define SCHP_FLAGS_MF                   0x02    /* Multiplication factor */
  492 #define SCHP_FLAGS_RCD                  0x01    /* Read Cache Disable */
  493         u_int8_t rw_cache_policy;
  494         u_int8_t dis_prefetch[2];
  495         u_int8_t min_prefetch[2];
  496         u_int8_t max_prefetch[2];
  497         u_int8_t max_prefetch_ceil[2];
  498 };
  499 
  500 /*
  501  * XXX KDM
  502  * Updated version of the cache page, as of SBC.  Update this to SBC-3 and
  503  * rationalize the two.
  504  */
  505 struct scsi_caching_page {
  506         uint8_t page_code;
  507 #define SMS_CACHING_PAGE                0x08
  508         uint8_t page_length;
  509         uint8_t flags1;
  510 #define SCP_IC          0x80
  511 #define SCP_ABPF        0x40
  512 #define SCP_CAP         0x20
  513 #define SCP_DISC        0x10
  514 #define SCP_SIZE        0x08
  515 #define SCP_WCE         0x04
  516 #define SCP_MF          0x02
  517 #define SCP_RCD         0x01
  518         uint8_t ret_priority;
  519         uint8_t disable_pf_transfer_len[2];
  520         uint8_t min_prefetch[2];
  521         uint8_t max_prefetch[2];
  522         uint8_t max_pf_ceiling[2];
  523         uint8_t flags2;
  524 #define SCP_FSW         0x80
  525 #define SCP_LBCSS       0x40
  526 #define SCP_DRA         0x20
  527 #define SCP_VS1         0x10
  528 #define SCP_VS2         0x08
  529         uint8_t cache_segments;
  530         uint8_t cache_seg_size[2];
  531         uint8_t reserved;
  532         uint8_t non_cache_seg_size[3];
  533 };
  534 
  535 struct scsi_info_exceptions_page {
  536         u_int8_t page_code;
  537 #define SIEP_PAGE_SAVABLE               0x80    /* Page is savable */
  538         u_int8_t page_length;
  539         u_int8_t info_flags;
  540 #define SIEP_FLAGS_PERF                 0x80
  541 #define SIEP_FLAGS_EBF                  0x20
  542 #define SIEP_FLAGS_EWASC                0x10
  543 #define SIEP_FLAGS_DEXCPT               0x08
  544 #define SIEP_FLAGS_TEST                 0x04
  545 #define SIEP_FLAGS_EBACKERR             0x02
  546 #define SIEP_FLAGS_LOGERR               0x01
  547         u_int8_t mrie;
  548         u_int8_t interval_timer[4];
  549         u_int8_t report_count[4];
  550 };
  551 
  552 struct scsi_proto_specific_page {
  553         u_int8_t page_code;
  554 #define SPSP_PAGE_SAVABLE               0x80    /* Page is savable */
  555         u_int8_t page_length;
  556         u_int8_t protocol;
  557 #define SPSP_PROTO_FC                   0x00
  558 #define SPSP_PROTO_SPI                  0x01
  559 #define SPSP_PROTO_SSA                  0x02
  560 #define SPSP_PROTO_1394                 0x03
  561 #define SPSP_PROTO_RDMA                 0x04
  562 #define SPSP_PROTO_ISCSI                0x05
  563 #define SPSP_PROTO_SAS                  0x06
  564 #define SPSP_PROTO_ADT                  0x07
  565 #define SPSP_PROTO_ATA                  0x08
  566 #define SPSP_PROTO_NONE                 0x0f
  567 };
  568 
  569 struct scsi_reserve
  570 {
  571         u_int8_t opcode;
  572         u_int8_t byte2;
  573 #define SR_EXTENT       0x01
  574 #define SR_ID_MASK      0x0e
  575 #define SR_3RDPTY       0x10
  576 #define SR_LUN_MASK     0xe0
  577         u_int8_t resv_id;
  578         u_int8_t length[2];
  579         u_int8_t control;
  580 };
  581 
  582 struct scsi_reserve_10 {
  583         uint8_t opcode;
  584         uint8_t byte2;
  585 #define SR10_3RDPTY     0x10
  586 #define SR10_LONGID     0x02
  587 #define SR10_EXTENT     0x01
  588         uint8_t resv_id;
  589         uint8_t thirdparty_id;
  590         uint8_t reserved[3];
  591         uint8_t length[2];
  592         uint8_t control;
  593 };
  594 
  595 
  596 struct scsi_release
  597 {
  598         u_int8_t opcode;
  599         u_int8_t byte2;
  600         u_int8_t resv_id;
  601         u_int8_t unused[1];
  602         u_int8_t length;
  603         u_int8_t control;
  604 };
  605 
  606 struct scsi_release_10 {
  607         uint8_t opcode;
  608         uint8_t byte2;
  609         uint8_t resv_id;
  610         uint8_t thirdparty_id;
  611         uint8_t reserved[3];
  612         uint8_t length[2];
  613         uint8_t control;
  614 };
  615 
  616 struct scsi_prevent
  617 {
  618         u_int8_t opcode;
  619         u_int8_t byte2;
  620         u_int8_t unused[2];
  621         u_int8_t how;
  622         u_int8_t control;
  623 };
  624 #define PR_PREVENT 0x01
  625 #define PR_ALLOW   0x00
  626 
  627 struct scsi_sync_cache
  628 {
  629         u_int8_t opcode;
  630         u_int8_t byte2;
  631 #define SSC_IMMED       0x02
  632 #define SSC_RELADR      0x01
  633         u_int8_t begin_lba[4];
  634         u_int8_t reserved;
  635         u_int8_t lb_count[2];
  636         u_int8_t control;       
  637 };
  638 
  639 struct scsi_sync_cache_16
  640 {
  641         uint8_t opcode;
  642         uint8_t byte2;
  643         uint8_t begin_lba[8];
  644         uint8_t lb_count[4];
  645         uint8_t reserved;
  646         uint8_t control;
  647 };
  648 
  649 struct scsi_format {
  650         uint8_t opcode;
  651         uint8_t byte2;
  652 #define SF_LONGLIST             0x20
  653 #define SF_FMTDATA              0x10
  654 #define SF_CMPLIST              0x08
  655 #define SF_FORMAT_MASK          0x07
  656 #define SF_FORMAT_BLOCK         0x00
  657 #define SF_FORMAT_LONG_BLOCK    0x03
  658 #define SF_FORMAT_BFI           0x04
  659 #define SF_FORMAT_PHYS          0x05
  660         uint8_t vendor;
  661         uint8_t interleave[2];
  662         uint8_t control;
  663 };
  664 
  665 struct scsi_format_header_short {
  666         uint8_t reserved;
  667 #define SF_DATA_FOV     0x80
  668 #define SF_DATA_DPRY    0x40
  669 #define SF_DATA_DCRT    0x20
  670 #define SF_DATA_STPF    0x10
  671 #define SF_DATA_IP      0x08
  672 #define SF_DATA_DSP     0x04
  673 #define SF_DATA_IMMED   0x02
  674 #define SF_DATA_VS      0x01
  675         uint8_t byte2;
  676         uint8_t defect_list_len[2];
  677 };
  678 
  679 struct scsi_format_header_long {
  680         uint8_t reserved;
  681         uint8_t byte2;
  682         uint8_t reserved2[2];
  683         uint8_t defect_list_len[4];
  684 };
  685 
  686 struct scsi_changedef
  687 {
  688         u_int8_t opcode;
  689         u_int8_t byte2;
  690         u_int8_t unused1;
  691         u_int8_t how;
  692         u_int8_t unused[4];
  693         u_int8_t datalen;
  694         u_int8_t control;
  695 };
  696 
  697 struct scsi_read_buffer
  698 {
  699         u_int8_t opcode;
  700         u_int8_t byte2;
  701 #define RWB_MODE                0x07
  702 #define RWB_MODE_HDR_DATA       0x00
  703 #define RWB_MODE_VENDOR         0x01
  704 #define RWB_MODE_DATA           0x02
  705 #define RWB_MODE_DOWNLOAD       0x04
  706 #define RWB_MODE_DOWNLOAD_SAVE  0x05
  707         u_int8_t buffer_id;
  708         u_int8_t offset[3];
  709         u_int8_t length[3];
  710         u_int8_t control;
  711 };
  712 
  713 struct scsi_write_buffer
  714 {
  715         u_int8_t opcode;
  716         u_int8_t byte2;
  717         u_int8_t buffer_id;
  718         u_int8_t offset[3];
  719         u_int8_t length[3];
  720         u_int8_t control;
  721 };
  722 
  723 struct scsi_rw_6
  724 {
  725         u_int8_t opcode;
  726         u_int8_t addr[3];
  727 /* only 5 bits are valid in the MSB address byte */
  728 #define SRW_TOPADDR     0x1F
  729         u_int8_t length;
  730         u_int8_t control;
  731 };
  732 
  733 struct scsi_rw_10
  734 {
  735         u_int8_t opcode;
  736 #define SRW10_RELADDR   0x01
  737 /* EBP defined for WRITE(10) only */
  738 #define SRW10_EBP       0x04
  739 #define SRW10_FUA       0x08
  740 #define SRW10_DPO       0x10
  741         u_int8_t byte2;
  742         u_int8_t addr[4];
  743         u_int8_t reserved;
  744         u_int8_t length[2];
  745         u_int8_t control;
  746 };
  747 
  748 struct scsi_rw_12
  749 {
  750         u_int8_t opcode;
  751 #define SRW12_RELADDR   0x01
  752 #define SRW12_FUA       0x08
  753 #define SRW12_DPO       0x10
  754         u_int8_t byte2;
  755         u_int8_t addr[4];
  756         u_int8_t length[4];
  757         u_int8_t reserved;
  758         u_int8_t control;
  759 };
  760 
  761 struct scsi_rw_16
  762 {
  763         u_int8_t opcode;
  764 #define SRW16_RELADDR   0x01
  765 #define SRW16_FUA       0x08
  766 #define SRW16_DPO       0x10
  767         u_int8_t byte2;
  768         u_int8_t addr[8];
  769         u_int8_t length[4];
  770         u_int8_t reserved;
  771         u_int8_t control;
  772 };
  773 
  774 struct scsi_write_verify_10
  775 {
  776         uint8_t opcode;
  777         uint8_t byte2;
  778 #define SWV_BYTCHK              0x02
  779 #define SWV_DPO                 0x10
  780 #define SWV_WRPROECT_MASK       0xe0
  781         uint8_t addr[4];
  782         uint8_t group;
  783         uint8_t length[2];
  784         uint8_t control;
  785 };
  786 
  787 struct scsi_write_verify_12
  788 {
  789         uint8_t opcode;
  790         uint8_t byte2;
  791         uint8_t addr[4];
  792         uint8_t length[4];
  793         uint8_t group;
  794         uint8_t control;
  795 };
  796 
  797 struct scsi_write_verify_16
  798 {
  799         uint8_t opcode;
  800         uint8_t byte2;
  801         uint8_t addr[8];
  802         uint8_t length[4];
  803         uint8_t group;
  804         uint8_t control;
  805 };
  806 
  807 
  808 struct scsi_start_stop_unit
  809 {
  810         u_int8_t opcode;
  811         u_int8_t byte2;
  812 #define SSS_IMMED               0x01
  813         u_int8_t reserved[2];
  814         u_int8_t how;
  815 #define SSS_START               0x01
  816 #define SSS_LOEJ                0x02
  817 #define SSS_PC_MASK             0xf0
  818 #define SSS_PC_START_VALID      0x00
  819 #define SSS_PC_ACTIVE           0x10
  820 #define SSS_PC_IDLE             0x20
  821 #define SSS_PC_STANDBY          0x30
  822 #define SSS_PC_LU_CONTROL       0x70
  823 #define SSS_PC_FORCE_IDLE_0     0xa0
  824 #define SSS_PC_FORCE_STANDBY_0  0xb0
  825         u_int8_t control;
  826 };
  827 
  828 struct ata_pass_12 {
  829         u_int8_t opcode;
  830         u_int8_t protocol;
  831 #define AP_MULTI        0xe0
  832         u_int8_t flags;
  833 #define AP_T_LEN        0x03
  834 #define AP_BB           0x04
  835 #define AP_T_DIR        0x08
  836 #define AP_CK_COND      0x20
  837 #define AP_OFFLINE      0x60
  838         u_int8_t features;
  839         u_int8_t sector_count;
  840         u_int8_t lba_low;
  841         u_int8_t lba_mid;
  842         u_int8_t lba_high;
  843         u_int8_t device;
  844         u_int8_t command;
  845         u_int8_t reserved;
  846         u_int8_t control;
  847 };
  848 
  849 struct scsi_maintenance_in
  850 {
  851         uint8_t  opcode;
  852         uint8_t  byte2;
  853 #define SERVICE_ACTION_MASK  0x1f
  854 #define SA_RPRT_TRGT_GRP     0x0a
  855         uint8_t  reserved[4];
  856         uint8_t  length[4];
  857         uint8_t  reserved1;
  858         uint8_t  control;
  859 };
  860 
  861 struct ata_pass_16 {
  862         u_int8_t opcode;
  863         u_int8_t protocol;
  864 #define AP_EXTEND       0x01
  865         u_int8_t flags;
  866         u_int8_t features_ext;
  867         u_int8_t features;
  868         u_int8_t sector_count_ext;
  869         u_int8_t sector_count;
  870         u_int8_t lba_low_ext;
  871         u_int8_t lba_low;
  872         u_int8_t lba_mid_ext;
  873         u_int8_t lba_mid;
  874         u_int8_t lba_high_ext;
  875         u_int8_t lba_high;
  876         u_int8_t device;
  877         u_int8_t command;
  878         u_int8_t control;
  879 };
  880 
  881 #define SC_SCSI_1 0x01
  882 #define SC_SCSI_2 0x03
  883 
  884 /*
  885  * Opcodes
  886  */
  887 
  888 #define TEST_UNIT_READY         0x00
  889 #define REQUEST_SENSE           0x03
  890 #define READ_6                  0x08
  891 #define WRITE_6                 0x0A
  892 #define INQUIRY                 0x12
  893 #define MODE_SELECT_6           0x15
  894 #define MODE_SENSE_6            0x1A
  895 #define START_STOP_UNIT         0x1B
  896 #define START_STOP              0x1B
  897 #define RESERVE                 0x16
  898 #define RELEASE                 0x17
  899 #define RECEIVE_DIAGNOSTIC      0x1C
  900 #define SEND_DIAGNOSTIC         0x1D
  901 #define PREVENT_ALLOW           0x1E
  902 #define READ_CAPACITY           0x25
  903 #define READ_10                 0x28
  904 #define WRITE_10                0x2A
  905 #define POSITION_TO_ELEMENT     0x2B
  906 #define WRITE_VERIFY_10         0x2E
  907 #define SYNCHRONIZE_CACHE       0x35
  908 #define READ_DEFECT_DATA_10     0x37
  909 #define WRITE_BUFFER            0x3B
  910 #define READ_BUFFER             0x3C
  911 #define CHANGE_DEFINITION       0x40
  912 #define LOG_SELECT              0x4C
  913 #define LOG_SENSE               0x4D
  914 #define MODE_SELECT_10          0x55
  915 #define RESERVE_10              0x56
  916 #define RELEASE_10              0x57
  917 #define MODE_SENSE_10           0x5A
  918 #define PERSISTENT_RES_IN       0x5E
  919 #define PERSISTENT_RES_OUT      0x5F
  920 #define ATA_PASS_16             0x85
  921 #define READ_16                 0x88
  922 #define WRITE_16                0x8A
  923 #define WRITE_VERIFY_16         0x8E
  924 #define SYNCHRONIZE_CACHE_16    0x91
  925 #define SERVICE_ACTION_IN       0x9E
  926 #define REPORT_LUNS             0xA0
  927 #define ATA_PASS_12             0xA1
  928 #define MAINTENANCE_IN          0xA3
  929 #define MAINTENANCE_OUT         0xA4
  930 #define MOVE_MEDIUM             0xA5
  931 #define READ_12                 0xA8
  932 #define WRITE_12                0xAA
  933 #define WRITE_VERIFY_12         0xAE
  934 #define READ_ELEMENT_STATUS     0xB8
  935 
  936 /* Maintenance In Service Action Codes */
  937 #define REPORT_IDENTIFYING_INFRMATION           0x05
  938 #define REPORT_TARGET_PORT_GROUPS               0x0A
  939 #define REPORT_ALIASES                          0x0B
  940 #define REPORT_SUPPORTED_OPERATION_CODES        0x0C
  941 #define REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS      0x0D
  942 #define REPORT_PRIORITY                         0x0E
  943 #define REPORT_TIMESTAMP                        0x0F
  944 #define MANAGEMENT_PROTOCOL_IN                  0x10
  945 /* Maintenance Out Service Action Codes */
  946 #define SET_IDENTIFY_INFORMATION                0x06
  947 #define SET_TARGET_PORT_GROUPS                  0x0A
  948 #define CHANGE_ALIASES                          0x0B
  949 #define SET_PRIORITY                            0x0E
  950 #define SET_TIMESTAMP                           0x0F
  951 #define MANGAEMENT_PROTOCOL_OUT                 0x10
  952 
  953 /*
  954  * Device Types
  955  */
  956 #define T_DIRECT        0x00
  957 #define T_SEQUENTIAL    0x01
  958 #define T_PRINTER       0x02
  959 #define T_PROCESSOR     0x03
  960 #define T_WORM          0x04
  961 #define T_CDROM         0x05
  962 #define T_SCANNER       0x06
  963 #define T_OPTICAL       0x07
  964 #define T_CHANGER       0x08
  965 #define T_COMM          0x09
  966 #define T_ASC0          0x0a
  967 #define T_ASC1          0x0b
  968 #define T_STORARRAY     0x0c
  969 #define T_ENCLOSURE     0x0d
  970 #define T_RBC           0x0e
  971 #define T_OCRW          0x0f
  972 #define T_OSD           0x11
  973 #define T_ADC           0x12
  974 #define T_NODEVICE      0x1f
  975 #define T_ANY           0xff    /* Used in Quirk table matches */
  976 
  977 #define T_REMOV         1
  978 #define T_FIXED         0
  979 
  980 /*
  981  * This length is the initial inquiry length used by the probe code, as    
  982  * well as the legnth necessary for scsi_print_inquiry() to function 
  983  * correctly.  If either use requires a different length in the future, 
  984  * the two values should be de-coupled.
  985  */
  986 #define SHORT_INQUIRY_LENGTH    36
  987 
  988 struct scsi_inquiry_data
  989 {
  990         u_int8_t device;
  991 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
  992 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
  993 #define SID_QUAL_LU_CONNECTED   0x00    /*
  994                                          * The specified peripheral device
  995                                          * type is currently connected to
  996                                          * logical unit.  If the target cannot
  997                                          * determine whether or not a physical
  998                                          * device is currently connected, it
  999                                          * shall also use this peripheral
 1000                                          * qualifier when returning the INQUIRY
 1001                                          * data.  This peripheral qualifier
 1002                                          * does not mean that the device is
 1003                                          * ready for access by the initiator.
 1004                                          */
 1005 #define SID_QUAL_LU_OFFLINE     0x01    /*
 1006                                          * The target is capable of supporting
 1007                                          * the specified peripheral device type
 1008                                          * on this logical unit; however, the
 1009                                          * physical device is not currently
 1010                                          * connected to this logical unit.
 1011                                          */
 1012 #define SID_QUAL_RSVD           0x02
 1013 #define SID_QUAL_BAD_LU         0x03    /*
 1014                                          * The target is not capable of
 1015                                          * supporting a physical device on
 1016                                          * this logical unit. For this
 1017                                          * peripheral qualifier the peripheral
 1018                                          * device type shall be set to 1Fh to
 1019                                          * provide compatibility with previous
 1020                                          * versions of SCSI. All other
 1021                                          * peripheral device type values are
 1022                                          * reserved for this peripheral
 1023                                          * qualifier.
 1024                                          */
 1025 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
 1026         u_int8_t dev_qual2;
 1027 #define SID_QUAL2       0x7F
 1028 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
 1029         u_int8_t version;
 1030 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
 1031 #define         SCSI_REV_0              0
 1032 #define         SCSI_REV_CCS            1
 1033 #define         SCSI_REV_2              2
 1034 #define         SCSI_REV_SPC            3
 1035 #define         SCSI_REV_SPC2           4
 1036 #define         SCSI_REV_SPC3           5
 1037 #define         SCSI_REV_SPC4           6
 1038 
 1039 #define SID_ECMA        0x38
 1040 #define SID_ISO         0xC0
 1041         u_int8_t response_format;
 1042 #define SID_AENC        0x80
 1043 #define SID_TrmIOP      0x40
 1044 #define SID_NormACA     0x20
 1045 #define SID_HiSup       0x10
 1046         u_int8_t additional_length;
 1047 #define SID_ADDITIONAL_LENGTH(iqd)                                      \
 1048         ((iqd)->additional_length +                                     \
 1049         __offsetof(struct scsi_inquiry_data, additional_length) + 1)
 1050         u_int8_t spc3_flags;
 1051 #define SPC3_SID_PROTECT        0x01
 1052 #define SPC3_SID_3PC            0x08
 1053 #define SPC3_SID_TPGS_MASK      0x30
 1054 #define SPC3_SID_TPGS_IMPLICIT  0x10
 1055 #define SPC3_SID_TPGS_EXPLICIT  0x20
 1056 #define SPC3_SID_ACC            0x40
 1057 #define SPC3_SID_SCCS           0x80
 1058         u_int8_t spc2_flags;
 1059 #define SPC2_SID_ADDR16         0x01
 1060 #define SPC2_SID_MChngr         0x08
 1061 #define SPC2_SID_MultiP         0x10
 1062 #define SPC2_SID_EncServ        0x40
 1063 #define SPC2_SID_BQueue         0x80
 1064 
 1065 #define INQ_DATA_TQ_ENABLED(iqd)                                \
 1066     ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \
 1067     (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \
 1068     (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue)))
 1069 
 1070         u_int8_t flags;
 1071 #define SID_SftRe       0x01
 1072 #define SID_CmdQue      0x02
 1073 #define SID_Linked      0x08
 1074 #define SID_Sync        0x10
 1075 #define SID_WBus16      0x20
 1076 #define SID_WBus32      0x40
 1077 #define SID_RelAdr      0x80
 1078 #define SID_VENDOR_SIZE   8
 1079         char     vendor[SID_VENDOR_SIZE];
 1080 #define SID_PRODUCT_SIZE  16
 1081         char     product[SID_PRODUCT_SIZE];
 1082 #define SID_REVISION_SIZE 4
 1083         char     revision[SID_REVISION_SIZE];
 1084         /*
 1085          * The following fields were taken from SCSI Primary Commands - 2
 1086          * (SPC-2) Revision 14, Dated 11 November 1999
 1087          */
 1088 #define SID_VENDOR_SPECIFIC_0_SIZE      20
 1089         u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
 1090         /*
 1091          * An extension of SCSI Parallel Specific Values
 1092          */
 1093 #define SID_SPI_IUS             0x01
 1094 #define SID_SPI_QAS             0x02
 1095 #define SID_SPI_CLOCK_ST        0x00
 1096 #define SID_SPI_CLOCK_DT        0x04
 1097 #define SID_SPI_CLOCK_DT_ST     0x0C
 1098 #define SID_SPI_MASK            0x0F
 1099         u_int8_t spi3data;
 1100         u_int8_t reserved2;
 1101         /*
 1102          * Version Descriptors, stored 2 byte values.
 1103          */
 1104         u_int8_t version1[2];
 1105         u_int8_t version2[2];
 1106         u_int8_t version3[2];
 1107         u_int8_t version4[2];
 1108         u_int8_t version5[2];
 1109         u_int8_t version6[2];
 1110         u_int8_t version7[2];
 1111         u_int8_t version8[2];
 1112 
 1113         u_int8_t reserved3[22];
 1114 
 1115 #define SID_VENDOR_SPECIFIC_1_SIZE      160
 1116         u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
 1117 };
 1118 
 1119 /*
 1120  * This structure is more suited to initiator operation, because the
 1121  * maximum number of supported pages is already allocated.
 1122  */
 1123 struct scsi_vpd_supported_page_list
 1124 {
 1125         u_int8_t device;
 1126         u_int8_t page_code;
 1127 #define SVPD_SUPPORTED_PAGE_LIST        0x00
 1128 #define SVPD_SUPPORTED_PAGES_HDR_LEN    4
 1129         u_int8_t reserved;
 1130         u_int8_t length;        /* number of VPD entries */
 1131 #define SVPD_SUPPORTED_PAGES_SIZE       251
 1132         u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE];
 1133 };
 1134 
 1135 /*
 1136  * This structure is more suited to target operation, because the
 1137  * number of supported pages is left to the user to allocate.
 1138  */
 1139 struct scsi_vpd_supported_pages
 1140 {
 1141         u_int8_t device;
 1142         u_int8_t page_code;
 1143         u_int8_t reserved;
 1144 #define SVPD_SUPPORTED_PAGES    0x00
 1145         u_int8_t length;
 1146         u_int8_t page_list[0];
 1147 };
 1148 
 1149 
 1150 struct scsi_vpd_unit_serial_number
 1151 {
 1152         u_int8_t device;
 1153         u_int8_t page_code;
 1154 #define SVPD_UNIT_SERIAL_NUMBER 0x80
 1155         u_int8_t reserved;
 1156         u_int8_t length; /* serial number length */
 1157 #define SVPD_SERIAL_NUM_SIZE 251
 1158         u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
 1159 };
 1160 
 1161 struct scsi_vpd_device_id
 1162 {
 1163         u_int8_t device;
 1164         u_int8_t page_code;
 1165 #define SVPD_DEVICE_ID                  0x83
 1166 #define SVPD_DEVICE_ID_MAX_SIZE         252
 1167 #define SVPD_DEVICE_ID_HDR_LEN \
 1168     __offsetof(struct scsi_vpd_device_id, desc_list)
 1169         u_int8_t length[2];
 1170         u_int8_t desc_list[];
 1171 };
 1172 
 1173 struct scsi_vpd_id_descriptor
 1174 {
 1175         u_int8_t        proto_codeset;
 1176 #define SCSI_PROTO_FC           0x00
 1177 #define SCSI_PROTO_SPI          0x01
 1178 #define SCSI_PROTO_SSA          0x02
 1179 #define SCSI_PROTO_1394         0x03
 1180 #define SCSI_PROTO_RDMA         0x04
 1181 #define SCSI_PROTO_iSCSI        0x05
 1182 #define SCSI_PROTO_SAS          0x06
 1183 #define SVPD_ID_PROTO_SHIFT     4
 1184 #define SVPD_ID_CODESET_BINARY  0x01
 1185 #define SVPD_ID_CODESET_ASCII   0x02
 1186 #define SVPD_ID_CODESET_MASK    0x0f
 1187         u_int8_t        id_type;
 1188 #define SVPD_ID_PIV             0x80
 1189 #define SVPD_ID_ASSOC_LUN       0x00
 1190 #define SVPD_ID_ASSOC_PORT      0x10
 1191 #define SVPD_ID_ASSOC_TARGET    0x20
 1192 #define SVPD_ID_ASSOC_MASK      0x30
 1193 #define SVPD_ID_TYPE_VENDOR     0x00
 1194 #define SVPD_ID_TYPE_T10        0x01
 1195 #define SVPD_ID_TYPE_EUI64      0x02
 1196 #define SVPD_ID_TYPE_NAA        0x03
 1197 #define SVPD_ID_TYPE_RELTARG    0x04
 1198 #define SVPD_ID_TYPE_TPORTGRP   0x05
 1199 #define SVPD_ID_TYPE_LUNGRP     0x06
 1200 #define SVPD_ID_TYPE_MD5_LUN_ID 0x07
 1201 #define SVPD_ID_TYPE_SCSI_NAME  0x08
 1202 #define SVPD_ID_TYPE_MASK       0x0f
 1203         u_int8_t        reserved;
 1204         u_int8_t        length;
 1205 #define SVPD_DEVICE_ID_DESC_HDR_LEN \
 1206     __offsetof(struct scsi_vpd_id_descriptor, identifier) 
 1207         u_int8_t        identifier[];
 1208 };
 1209 
 1210 struct scsi_vpd_id_t10
 1211 {
 1212         u_int8_t        vendor[8];
 1213         u_int8_t        vendor_spec_id[0];
 1214 };
 1215 
 1216 struct scsi_vpd_id_eui64
 1217 {
 1218         u_int8_t        ieee_company_id[3];
 1219         u_int8_t        extension_id[5];
 1220 };
 1221 
 1222 struct scsi_vpd_id_naa_basic
 1223 {
 1224         uint8_t naa;
 1225         /* big endian, packed:
 1226         uint8_t naa : 4;
 1227         uint8_t naa_desig : 4;
 1228         */
 1229 #define SVPD_ID_NAA_NAA_SHIFT           4
 1230 #define SVPD_ID_NAA_IEEE_EXT            0x02
 1231 #define SVPD_ID_NAA_LOCAL_REG           0x03
 1232 #define SVPD_ID_NAA_IEEE_REG            0x05
 1233 #define SVPD_ID_NAA_IEEE_REG_EXT        0x06
 1234         uint8_t naa_data[];
 1235 };
 1236 
 1237 struct scsi_vpd_id_naa_ieee_extended_id
 1238 {
 1239         uint8_t naa;
 1240         uint8_t vendor_specific_id_a;
 1241         uint8_t ieee_company_id[3];
 1242         uint8_t vendor_specific_id_b[4];
 1243 };
 1244 
 1245 struct scsi_vpd_id_naa_local_reg
 1246 {
 1247         uint8_t naa;
 1248         uint8_t local_value[7];
 1249 };
 1250 
 1251 struct scsi_vpd_id_naa_ieee_reg
 1252 {
 1253         uint8_t naa;
 1254         uint8_t reg_value[7];
 1255         /* big endian, packed:
 1256         uint8_t naa_basic : 4;
 1257         uint8_t ieee_company_id_0 : 4;
 1258         uint8_t ieee_company_id_1[2];
 1259         uint8_t ieee_company_id_2 : 4;
 1260         uint8_t vendor_specific_id_0 : 4;
 1261         uint8_t vendor_specific_id_1[4];
 1262         */
 1263 };
 1264 
 1265 struct scsi_vpd_id_naa_ieee_reg_extended
 1266 {
 1267         uint8_t naa;
 1268         uint8_t reg_value[15];
 1269         /* big endian, packed:
 1270         uint8_t naa_basic : 4;
 1271         uint8_t ieee_company_id_0 : 4;
 1272         uint8_t ieee_company_id_1[2];
 1273         uint8_t ieee_company_id_2 : 4;
 1274         uint8_t vendor_specific_id_0 : 4;
 1275         uint8_t vendor_specific_id_1[4];
 1276         uint8_t vendor_specific_id_ext[8];
 1277         */
 1278 };
 1279 
 1280 struct scsi_vpd_id_rel_trgt_port_id
 1281 {
 1282         uint8_t obsolete[2];
 1283         uint8_t rel_trgt_port_id[2];
 1284 };
 1285 
 1286 struct scsi_vpd_id_trgt_port_grp_id
 1287 {
 1288         uint8_t reserved[2];
 1289         uint8_t trgt_port_grp[2];
 1290 };
 1291 
 1292 struct scsi_vpd_id_lun_grp_id
 1293 {
 1294         uint8_t reserved[2];
 1295         uint8_t log_unit_grp[2];
 1296 };
 1297 
 1298 struct scsi_vpd_id_md5_lun_id
 1299 {
 1300         uint8_t lun_id[16];
 1301 };
 1302 
 1303 struct scsi_vpd_id_scsi_name
 1304 {
 1305         uint8_t name_string[256];
 1306 };
 1307 
 1308 struct scsi_service_action_in
 1309 {
 1310         uint8_t opcode;
 1311         uint8_t service_action;
 1312         uint8_t action_dependent[13];
 1313         uint8_t control;
 1314 };
 1315 
 1316 struct scsi_read_capacity
 1317 {
 1318         u_int8_t opcode;
 1319         u_int8_t byte2;
 1320 #define SRC_RELADR      0x01
 1321         u_int8_t addr[4];
 1322         u_int8_t unused[2];
 1323         u_int8_t pmi;
 1324 #define SRC_PMI         0x01
 1325         u_int8_t control;
 1326 };
 1327 
 1328 struct scsi_read_capacity_16
 1329 {
 1330         uint8_t opcode;
 1331 #define SRC16_SERVICE_ACTION    0x10
 1332         uint8_t service_action;
 1333         uint8_t addr[8];
 1334         uint8_t alloc_len[4];
 1335 #define SRC16_PMI               0x01
 1336 #define SRC16_RELADR            0x02
 1337         uint8_t reladr;
 1338         uint8_t control;
 1339 };
 1340 
 1341 struct scsi_read_capacity_data
 1342 {
 1343         u_int8_t addr[4];
 1344         u_int8_t length[4];
 1345 };
 1346 
 1347 struct scsi_read_capacity_data_long
 1348 {
 1349         uint8_t addr[8];
 1350         uint8_t length[4];
 1351 };
 1352 
 1353 struct scsi_report_luns
 1354 {
 1355         uint8_t opcode;
 1356         uint8_t reserved1;
 1357 #define RPL_REPORT_DEFAULT      0x00
 1358 #define RPL_REPORT_WELLKNOWN    0x01
 1359 #define RPL_REPORT_ALL          0x02
 1360         uint8_t select_report;
 1361         uint8_t reserved2[3];
 1362         uint8_t length[4];
 1363         uint8_t reserved3;
 1364         uint8_t control;
 1365 };
 1366 
 1367 struct scsi_report_luns_lundata {
 1368         uint8_t lundata[8];
 1369 #define RPL_LUNDATA_PERIPH_BUS_MASK     0x3f
 1370 #define RPL_LUNDATA_FLAT_LUN_MASK       0x3f
 1371 #define RPL_LUNDATA_FLAT_LUN_BITS       0x06
 1372 #define RPL_LUNDATA_LUN_TARG_MASK       0x3f
 1373 #define RPL_LUNDATA_LUN_BUS_MASK        0xe0
 1374 #define RPL_LUNDATA_LUN_LUN_MASK        0x1f
 1375 #define RPL_LUNDATA_EXT_LEN_MASK        0x30
 1376 #define RPL_LUNDATA_EXT_EAM_MASK        0x0f
 1377 #define RPL_LUNDATA_EXT_EAM_WK          0x01
 1378 #define RPL_LUNDATA_EXT_EAM_NOT_SPEC    0x0f
 1379 #define RPL_LUNDATA_ATYP_MASK   0xc0    /* MBZ for type 0 lun */
 1380 #define RPL_LUNDATA_ATYP_PERIPH 0x00
 1381 #define RPL_LUNDATA_ATYP_FLAT   0x40
 1382 #define RPL_LUNDATA_ATYP_LUN    0x80
 1383 #define RPL_LUNDATA_ATYP_EXTLUN 0xc0
 1384 };
 1385 
 1386 struct scsi_report_luns_data {
 1387         u_int8_t length[4];     /* length of LUN inventory, in bytes */
 1388         u_int8_t reserved[4];   /* unused */
 1389         /*
 1390          * LUN inventory- we only support the type zero form for now.
 1391          */
 1392         struct scsi_report_luns_lundata luns[0];
 1393 };
 1394 
 1395 struct scsi_target_group
 1396 {
 1397         uint8_t opcode;
 1398         uint8_t service_action;
 1399 #define STG_PDF_LENGTH          0x00
 1400 #define RPL_PDF_EXTENDED        0x20
 1401         uint8_t reserved1[4];
 1402         uint8_t length[4];
 1403         uint8_t reserved2;
 1404         uint8_t control;
 1405 };
 1406 
 1407 struct scsi_target_port_descriptor {
 1408         uint8_t reserved[2];
 1409         uint8_t relative_target_port_identifier[2];
 1410         uint8_t desc_list[];
 1411 };
 1412 
 1413 struct scsi_target_port_group_descriptor {
 1414         uint8_t pref_state;
 1415 #define TPG_PRIMARY                             0x80
 1416 #define TPG_ASYMMETRIC_ACCESS_STATE_MASK        0xf
 1417 #define TPG_ASYMMETRIC_ACCESS_OPTIMIZED         0x0
 1418 #define TPG_ASYMMETRIC_ACCESS_NONOPTIMIZED      0x1
 1419 #define TPG_ASYMMETRIC_ACCESS_STANDBY           0x2
 1420 #define TPG_ASYMMETRIC_ACCESS_UNAVAILABLE       0x3
 1421 #define TPG_ASYMMETRIC_ACCESS_LBA_DEPENDENT     0x4
 1422 #define TPG_ASYMMETRIC_ACCESS_OFFLINE           0xE
 1423 #define TPG_ASYMMETRIC_ACCESS_TRANSITIONING     0xF
 1424         uint8_t support;
 1425 #define TPG_AO_SUP      0x01
 1426 #define TPG_AN_SUP      0x02
 1427 #define TPG_S_SUP       0x04
 1428 #define TPG_U_SUP       0x08
 1429 #define TPG_LBD_SUP     0x10
 1430 #define TPG_O_SUP       0x40
 1431 #define TPG_T_SUP       0x80
 1432         uint8_t target_port_group[2];
 1433         uint8_t reserved;
 1434         uint8_t status;
 1435 #define TPG_UNAVLBL      0
 1436 #define TPG_SET_BY_STPG  0x01
 1437 #define TPG_IMPLICIT     0x02
 1438         uint8_t vendor_specific;
 1439         uint8_t target_port_count;
 1440         struct scsi_target_port_descriptor descriptors[];
 1441 };
 1442 
 1443 struct scsi_target_group_data {
 1444         uint8_t length[4];      /* length of returned data, in bytes */
 1445         struct scsi_target_port_group_descriptor groups[];
 1446 };
 1447 
 1448 struct scsi_target_group_data_extended {
 1449         uint8_t length[4];      /* length of returned data, in bytes */
 1450         uint8_t format_type;    /* STG_PDF_LENGTH or RPL_PDF_EXTENDED */
 1451         uint8_t implicit_transition_time;
 1452         uint8_t reserved[2];
 1453         struct scsi_target_port_group_descriptor groups[];
 1454 };
 1455 
 1456 
 1457 typedef enum {
 1458         SSD_TYPE_NONE,
 1459         SSD_TYPE_FIXED,
 1460         SSD_TYPE_DESC
 1461 } scsi_sense_data_type;
 1462 
 1463 typedef enum {
 1464         SSD_ELEM_NONE,
 1465         SSD_ELEM_SKIP,
 1466         SSD_ELEM_DESC,
 1467         SSD_ELEM_SKS,
 1468         SSD_ELEM_COMMAND,
 1469         SSD_ELEM_INFO,
 1470         SSD_ELEM_FRU,
 1471         SSD_ELEM_STREAM,
 1472         SSD_ELEM_MAX
 1473 } scsi_sense_elem_type;
 1474 
 1475 
 1476 struct scsi_sense_data
 1477 {
 1478         uint8_t error_code;
 1479         /*
 1480          * SPC-4 says that the maximum length of sense data is 252 bytes.
 1481          * So this structure is exactly 252 bytes log.
 1482          */
 1483 #define SSD_FULL_SIZE 252
 1484         uint8_t sense_buf[SSD_FULL_SIZE - 1];
 1485         /*
 1486          * XXX KDM is this still a reasonable minimum size?
 1487          */
 1488 #define SSD_MIN_SIZE 18
 1489         /*
 1490          * Maximum value for the extra_len field in the sense data.
 1491          */
 1492 #define SSD_EXTRA_MAX 244
 1493 };
 1494 
 1495 /*
 1496  * Fixed format sense data.
 1497  */
 1498 struct scsi_sense_data_fixed
 1499 {
 1500         u_int8_t error_code;
 1501 #define SSD_ERRCODE                     0x7F
 1502 #define         SSD_CURRENT_ERROR       0x70
 1503 #define         SSD_DEFERRED_ERROR      0x71
 1504 #define SSD_ERRCODE_VALID       0x80    
 1505         u_int8_t segment;
 1506         u_int8_t flags;
 1507 #define SSD_KEY                         0x0F
 1508 #define         SSD_KEY_NO_SENSE        0x00
 1509 #define         SSD_KEY_RECOVERED_ERROR 0x01
 1510 #define         SSD_KEY_NOT_READY       0x02
 1511 #define         SSD_KEY_MEDIUM_ERROR    0x03
 1512 #define         SSD_KEY_HARDWARE_ERROR  0x04
 1513 #define         SSD_KEY_ILLEGAL_REQUEST 0x05
 1514 #define         SSD_KEY_UNIT_ATTENTION  0x06
 1515 #define         SSD_KEY_DATA_PROTECT    0x07
 1516 #define         SSD_KEY_BLANK_CHECK     0x08
 1517 #define         SSD_KEY_Vendor_Specific 0x09
 1518 #define         SSD_KEY_COPY_ABORTED    0x0a
 1519 #define         SSD_KEY_ABORTED_COMMAND 0x0b            
 1520 #define         SSD_KEY_EQUAL           0x0c
 1521 #define         SSD_KEY_VOLUME_OVERFLOW 0x0d
 1522 #define         SSD_KEY_MISCOMPARE      0x0e
 1523 #define         SSD_KEY_COMPLETED       0x0f                    
 1524 #define SSD_ILI         0x20
 1525 #define SSD_EOM         0x40
 1526 #define SSD_FILEMARK    0x80
 1527         u_int8_t info[4];
 1528         u_int8_t extra_len;
 1529         u_int8_t cmd_spec_info[4];
 1530         u_int8_t add_sense_code;
 1531         u_int8_t add_sense_code_qual;
 1532         u_int8_t fru;
 1533         u_int8_t sense_key_spec[3];
 1534 #define SSD_SCS_VALID           0x80
 1535 #define SSD_FIELDPTR_CMD        0x40
 1536 #define SSD_BITPTR_VALID        0x08
 1537 #define SSD_BITPTR_VALUE        0x07
 1538         u_int8_t extra_bytes[14];
 1539 #define SSD_FIXED_IS_PRESENT(sense, length, field)                      \
 1540         ((length >= (offsetof(struct scsi_sense_data_fixed, field) +    \
 1541         sizeof(sense->field))) ? 1 :0)
 1542 #define SSD_FIXED_IS_FILLED(sense, field)                               \
 1543         ((((offsetof(struct scsi_sense_data_fixed, field) +             \
 1544         sizeof(sense->field)) -                                         \
 1545         (offsetof(struct scsi_sense_data_fixed, extra_len) +            \
 1546         sizeof(sense->extra_len))) <= sense->extra_len) ? 1 : 0)
 1547 };
 1548 
 1549 /*
 1550  * Descriptor format sense data definitions.
 1551  * Introduced in SPC-3.
 1552  */
 1553 struct scsi_sense_data_desc 
 1554 {
 1555         uint8_t error_code;
 1556 #define SSD_DESC_CURRENT_ERROR  0x72
 1557 #define SSD_DESC_DEFERRED_ERROR 0x73
 1558         uint8_t sense_key;
 1559         uint8_t add_sense_code;
 1560         uint8_t add_sense_code_qual;
 1561         uint8_t reserved[3];
 1562         /*
 1563          * Note that SPC-4, section 4.5.2.1 says that the extra_len field
 1564          * must be less than or equal to 244.
 1565          */
 1566         uint8_t extra_len;
 1567         uint8_t sense_desc[0];
 1568 #define SSD_DESC_IS_PRESENT(sense, length, field)                       \
 1569         ((length >= (offsetof(struct scsi_sense_data_desc, field) +     \
 1570         sizeof(sense->field))) ? 1 :0)
 1571 };
 1572 
 1573 struct scsi_sense_desc_header
 1574 {
 1575         uint8_t desc_type;
 1576         uint8_t length;
 1577 };
 1578 /*
 1579  * The information provide in the Information descriptor is device type or
 1580  * command specific information, and defined in a command standard.
 1581  *
 1582  * Note that any changes to the field names or positions in this structure,
 1583  * even reserved fields, should be accompanied by an examination of the
 1584  * code in ctl_set_sense() that uses them.
 1585  *
 1586  * Maximum descriptors allowed: 1 (as of SPC-4)
 1587  */
 1588 struct scsi_sense_info
 1589 {
 1590         uint8_t desc_type;
 1591 #define SSD_DESC_INFO   0x00
 1592         uint8_t length;
 1593         uint8_t byte2;
 1594 #define SSD_INFO_VALID  0x80
 1595         uint8_t reserved;
 1596         uint8_t info[8];
 1597 };
 1598 
 1599 /*
 1600  * Command-specific information depends on the command for which the
 1601  * reported condition occured.
 1602  *
 1603  * Note that any changes to the field names or positions in this structure,
 1604  * even reserved fields, should be accompanied by an examination of the
 1605  * code in ctl_set_sense() that uses them.
 1606  *
 1607  * Maximum descriptors allowed: 1 (as of SPC-4)
 1608  */
 1609 struct scsi_sense_command
 1610 {
 1611         uint8_t desc_type;
 1612 #define SSD_DESC_COMMAND        0x01
 1613         uint8_t length;
 1614         uint8_t reserved[2];
 1615         uint8_t command_info[8];
 1616 };
 1617 
 1618 /*
 1619  * Sense key specific descriptor.  The sense key specific data format
 1620  * depends on the sense key in question.
 1621  *
 1622  * Maximum descriptors allowed: 1 (as of SPC-4)
 1623  */
 1624 struct scsi_sense_sks
 1625 {
 1626         uint8_t desc_type;
 1627 #define SSD_DESC_SKS            0x02
 1628         uint8_t length;
 1629         uint8_t reserved1[2];
 1630         uint8_t sense_key_spec[3];
 1631 #define SSD_SKS_VALID           0x80
 1632         uint8_t reserved2;
 1633 };
 1634 
 1635 /*
 1636  * This is used for the Illegal Request sense key (0x05) only.
 1637  */
 1638 struct scsi_sense_sks_field
 1639 {
 1640         uint8_t byte0;
 1641 #define SSD_SKS_FIELD_VALID     0x80
 1642 #define SSD_SKS_FIELD_CMD       0x40
 1643 #define SSD_SKS_BPV             0x08
 1644 #define SSD_SKS_BIT_VALUE       0x07
 1645         uint8_t field[2];
 1646 };
 1647 
 1648 
 1649 /* 
 1650  * This is used for the Hardware Error (0x04), Medium Error (0x03) and
 1651  * Recovered Error (0x01) sense keys.
 1652  */
 1653 struct scsi_sense_sks_retry
 1654 {
 1655         uint8_t byte0;
 1656 #define SSD_SKS_RETRY_VALID     0x80
 1657         uint8_t actual_retry_count[2];
 1658 };
 1659 
 1660 /*
 1661  * Used with the NO Sense (0x00) or Not Ready (0x02) sense keys.
 1662  */
 1663 struct scsi_sense_sks_progress
 1664 {
 1665         uint8_t byte0;
 1666 #define SSD_SKS_PROGRESS_VALID  0x80
 1667         uint8_t progress[2];
 1668 #define SSD_SKS_PROGRESS_DENOM  0x10000
 1669 };
 1670 
 1671 /*
 1672  * Used with the Copy Aborted (0x0a) sense key.
 1673  */
 1674 struct scsi_sense_sks_segment
 1675 {
 1676         uint8_t byte0;
 1677 #define SSD_SKS_SEGMENT_VALID   0x80
 1678 #define SSD_SKS_SEGMENT_SD      0x20
 1679 #define SSD_SKS_SEGMENT_BPV     0x08
 1680 #define SSD_SKS_SEGMENT_BITPTR  0x07
 1681         uint8_t field[2];
 1682 };
 1683 
 1684 /*
 1685  * Used with the Unit Attention (0x06) sense key.
 1686  *
 1687  * This is currently used to indicate that the unit attention condition
 1688  * queue has overflowed (when the overflow bit is set).
 1689  */
 1690 struct scsi_sense_sks_overflow
 1691 {
 1692         uint8_t byte0;
 1693 #define SSD_SKS_OVERFLOW_VALID  0x80
 1694 #define SSD_SKS_OVERFLOW_SET    0x01
 1695         uint8_t reserved[2];
 1696 };
 1697 
 1698 /*
 1699  * This specifies which component is associated with the sense data.  There
 1700  * is no standard meaning for the fru value.
 1701  *
 1702  * Maximum descriptors allowed: 1 (as of SPC-4)
 1703  */
 1704 struct scsi_sense_fru
 1705 {
 1706         uint8_t desc_type;
 1707 #define SSD_DESC_FRU            0x03
 1708         uint8_t length;
 1709         uint8_t reserved;
 1710         uint8_t fru;
 1711 };
 1712 
 1713 /*
 1714  * Used for Stream commands, defined in SSC-4.
 1715  *
 1716  * Maximum descriptors allowed: 1 (as of SPC-4)
 1717  */
 1718  
 1719 struct scsi_sense_stream
 1720 {
 1721         uint8_t desc_type;
 1722 #define SSD_DESC_STREAM         0x04
 1723         uint8_t length;
 1724         uint8_t reserved;
 1725         uint8_t byte3;
 1726 #define SSD_DESC_STREAM_FM      0x80
 1727 #define SSD_DESC_STREAM_EOM     0x40
 1728 #define SSD_DESC_STREAM_ILI     0x20
 1729 };
 1730 
 1731 /*
 1732  * Used for Block commands, defined in SBC-3.
 1733  *
 1734  * This is currently (as of SBC-3) only used for the Incorrect Length
 1735  * Indication (ILI) bit, which says that the data length requested in the
 1736  * READ LONG or WRITE LONG command did not match the length of the logical
 1737  * block.
 1738  *
 1739  * Maximum descriptors allowed: 1 (as of SPC-4)
 1740  */
 1741 struct scsi_sense_block
 1742 {
 1743         uint8_t desc_type;
 1744 #define SSD_DESC_BLOCK          0x05
 1745         uint8_t length;
 1746         uint8_t reserved;
 1747         uint8_t byte3;
 1748 #define SSD_DESC_BLOCK_ILI      0x20
 1749 };
 1750 
 1751 /*
 1752  * Used for Object-Based Storage Devices (OSD-3).
 1753  *
 1754  * Maximum descriptors allowed: 1 (as of SPC-4)
 1755  */
 1756 struct scsi_sense_osd_objid
 1757 {
 1758         uint8_t desc_type;
 1759 #define SSD_DESC_OSD_OBJID      0x06
 1760         uint8_t length;
 1761         uint8_t reserved[6];
 1762         /*
 1763          * XXX KDM provide the bit definitions here?  There are a lot of
 1764          * them, and we don't have an OSD driver yet.
 1765          */
 1766         uint8_t not_init_cmds[4];
 1767         uint8_t completed_cmds[4];
 1768         uint8_t partition_id[8];
 1769         uint8_t object_id[8];
 1770 };
 1771 
 1772 /*
 1773  * Used for Object-Based Storage Devices (OSD-3).
 1774  *
 1775  * Maximum descriptors allowed: 1 (as of SPC-4)
 1776  */
 1777 struct scsi_sense_osd_integrity
 1778 {
 1779         uint8_t desc_type;
 1780 #define SSD_DESC_OSD_INTEGRITY  0x07
 1781         uint8_t length;
 1782         uint8_t integ_check_val[32];
 1783 };
 1784 
 1785 /*
 1786  * Used for Object-Based Storage Devices (OSD-3).
 1787  *
 1788  * Maximum descriptors allowed: 1 (as of SPC-4)
 1789  */
 1790 struct scsi_sense_osd_attr_id
 1791 {
 1792         uint8_t desc_type;
 1793 #define SSD_DESC_OSD_ATTR_ID    0x08
 1794         uint8_t length;
 1795         uint8_t reserved[2];
 1796         uint8_t attr_desc[0];
 1797 };
 1798 
 1799 /*
 1800  * Used with Sense keys No Sense (0x00) and Not Ready (0x02).
 1801  *
 1802  * Maximum descriptors allowed: 32 (as of SPC-4)
 1803  */
 1804 struct scsi_sense_progress
 1805 {
 1806         uint8_t desc_type;
 1807 #define SSD_DESC_PROGRESS       0x0a
 1808         uint8_t length;
 1809         uint8_t sense_key;
 1810         uint8_t add_sense_code;
 1811         uint8_t add_sense_code_qual;
 1812         uint8_t reserved;
 1813         uint8_t progress[2];
 1814 };
 1815 
 1816 /*
 1817  * This is typically forwarded as the result of an EXTENDED COPY command.
 1818  *
 1819  * Maximum descriptors allowed: 2 (as of SPC-4)
 1820  */
 1821 struct scsi_sense_forwarded
 1822 {
 1823         uint8_t desc_type;
 1824 #define SSD_DESC_FORWARDED      0x0c
 1825         uint8_t length;
 1826         uint8_t byte2;
 1827 #define SSD_FORWARDED_FSDT      0x80
 1828 #define SSD_FORWARDED_SDS_MASK  0x0f
 1829 #define SSD_FORWARDED_SDS_UNK   0x00
 1830 #define SSD_FORWARDED_SDS_EXSRC 0x01
 1831 #define SSD_FORWARDED_SDS_EXDST 0x02
 1832 };
 1833 
 1834 /*
 1835  * Vendor-specific sense descriptor.  The desc_type field will be in the
 1836  * range bewteen MIN and MAX inclusive.
 1837  */
 1838 struct scsi_sense_vendor
 1839 {
 1840         uint8_t desc_type;
 1841 #define SSD_DESC_VENDOR_MIN     0x80
 1842 #define SSD_DESC_VENDOR_MAX     0xff
 1843         uint8_t length;
 1844         uint8_t data[0];
 1845 };
 1846 
 1847 struct scsi_mode_header_6
 1848 {
 1849         u_int8_t data_length;   /* Sense data length */
 1850         u_int8_t medium_type;
 1851         u_int8_t dev_spec;
 1852         u_int8_t blk_desc_len;
 1853 };
 1854 
 1855 struct scsi_mode_header_10
 1856 {
 1857         u_int8_t data_length[2];/* Sense data length */
 1858         u_int8_t medium_type;
 1859         u_int8_t dev_spec;
 1860         u_int8_t unused[2];
 1861         u_int8_t blk_desc_len[2];
 1862 };
 1863 
 1864 struct scsi_mode_page_header
 1865 {
 1866         u_int8_t page_code;
 1867 #define SMPH_PS         0x80
 1868 #define SMPH_SPF        0x40
 1869 #define SMPH_PC_MASK    0x3f
 1870         u_int8_t page_length;
 1871 };
 1872 
 1873 struct scsi_mode_page_header_sp
 1874 {
 1875         uint8_t page_code;
 1876         uint8_t subpage;
 1877         uint8_t page_length[2];
 1878 };
 1879 
 1880 
 1881 struct scsi_mode_blk_desc
 1882 {
 1883         u_int8_t density;
 1884         u_int8_t nblocks[3];
 1885         u_int8_t reserved;
 1886         u_int8_t blklen[3];
 1887 };
 1888 
 1889 #define SCSI_DEFAULT_DENSITY    0x00    /* use 'default' density */
 1890 #define SCSI_SAME_DENSITY       0x7f    /* use 'same' density- >= SCSI-2 only */
 1891 
 1892 
 1893 /*
 1894  * Status Byte
 1895  */
 1896 #define SCSI_STATUS_OK                  0x00
 1897 #define SCSI_STATUS_CHECK_COND          0x02
 1898 #define SCSI_STATUS_COND_MET            0x04
 1899 #define SCSI_STATUS_BUSY                0x08
 1900 #define SCSI_STATUS_INTERMED            0x10
 1901 #define SCSI_STATUS_INTERMED_COND_MET   0x14
 1902 #define SCSI_STATUS_RESERV_CONFLICT     0x18
 1903 #define SCSI_STATUS_CMD_TERMINATED      0x22    /* Obsolete in SAM-2 */
 1904 #define SCSI_STATUS_QUEUE_FULL          0x28
 1905 #define SCSI_STATUS_ACA_ACTIVE          0x30
 1906 #define SCSI_STATUS_TASK_ABORTED        0x40
 1907 
 1908 struct scsi_inquiry_pattern {
 1909         u_int8_t   type;
 1910         u_int8_t   media_type;
 1911 #define SIP_MEDIA_REMOVABLE     0x01
 1912 #define SIP_MEDIA_FIXED         0x02
 1913         const char *vendor;
 1914         const char *product;
 1915         const char *revision;
 1916 }; 
 1917 
 1918 struct scsi_static_inquiry_pattern {
 1919         u_int8_t   type;
 1920         u_int8_t   media_type;
 1921         char       vendor[SID_VENDOR_SIZE+1];
 1922         char       product[SID_PRODUCT_SIZE+1];
 1923         char       revision[SID_REVISION_SIZE+1];
 1924 };
 1925 
 1926 struct scsi_sense_quirk_entry {
 1927         struct scsi_inquiry_pattern     inq_pat;
 1928         int                             num_sense_keys;
 1929         int                             num_ascs;
 1930         struct sense_key_table_entry    *sense_key_info;
 1931         struct asc_table_entry          *asc_info;
 1932 };
 1933 
 1934 struct sense_key_table_entry {
 1935         u_int8_t    sense_key;
 1936         u_int32_t   action;
 1937         const char *desc;
 1938 };
 1939 
 1940 struct asc_table_entry {
 1941         u_int8_t    asc;
 1942         u_int8_t    ascq;
 1943         u_int32_t   action;
 1944         const char *desc;
 1945 };
 1946 
 1947 struct op_table_entry {
 1948         u_int8_t    opcode;
 1949         u_int32_t   opmask;
 1950         const char  *desc;
 1951 };
 1952 
 1953 struct scsi_op_quirk_entry {
 1954         struct scsi_inquiry_pattern     inq_pat;
 1955         int                             num_ops;
 1956         struct op_table_entry           *op_table;
 1957 };
 1958 
 1959 typedef enum {
 1960         SSS_FLAG_NONE           = 0x00,
 1961         SSS_FLAG_PRINT_COMMAND  = 0x01
 1962 } scsi_sense_string_flags;
 1963 
 1964 struct ccb_scsiio;
 1965 struct cam_periph;
 1966 union  ccb;
 1967 #ifndef _KERNEL
 1968 struct cam_device;
 1969 #endif
 1970 
 1971 extern const char *scsi_sense_key_text[];
 1972 
 1973 struct sbuf;
 1974 
 1975 __BEGIN_DECLS
 1976 void scsi_sense_desc(int sense_key, int asc, int ascq,
 1977                      struct scsi_inquiry_data *inq_data,
 1978                      const char **sense_key_desc, const char **asc_desc);
 1979 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
 1980                                     struct scsi_inquiry_data *inq_data,
 1981                                     u_int32_t sense_flags);
 1982 const char *    scsi_status_string(struct ccb_scsiio *csio);
 1983 
 1984 void scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len,
 1985                        int (*iter_func)(struct scsi_sense_data_desc *sense,
 1986                                         u_int, struct scsi_sense_desc_header *,
 1987                                         void *), void *arg);
 1988 uint8_t *scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len,
 1989                         uint8_t desc_type);
 1990 void scsi_set_sense_data(struct scsi_sense_data *sense_data, 
 1991                          scsi_sense_data_type sense_format, int current_error,
 1992                          int sense_key, int asc, int ascq, ...) ;
 1993 void scsi_set_sense_data_va(struct scsi_sense_data *sense_data,
 1994                             scsi_sense_data_type sense_format,
 1995                             int current_error, int sense_key, int asc,
 1996                             int ascq, va_list ap);
 1997 int scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len,
 1998                         uint8_t info_type, uint64_t *info,
 1999                         int64_t *signed_info);
 2000 int scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len,
 2001                  uint8_t *sks);
 2002 int scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
 2003                         struct scsi_inquiry_data *inq_data,
 2004                         uint8_t *block_bits);
 2005 int scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len,
 2006                          struct scsi_inquiry_data *inq_data,
 2007                          uint8_t *stream_bits);
 2008 void scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
 2009                     struct scsi_inquiry_data *inq_data, uint64_t info);
 2010 void scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
 2011                        struct scsi_inquiry_data *inq_data, uint64_t csi);
 2012 void scsi_progress_sbuf(struct sbuf *sb, uint16_t progress);
 2013 int scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks);
 2014 void scsi_fru_sbuf(struct sbuf *sb, uint64_t fru);
 2015 void scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info);
 2016 void scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info);
 2017 void scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
 2018                           u_int sense_len, uint8_t *cdb, int cdb_len,
 2019                           struct scsi_inquiry_data *inq_data,
 2020                           struct scsi_sense_desc_header *header);
 2021 
 2022 void scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
 2023                              u_int sense_len, uint8_t *cdb, int cdb_len,
 2024                              struct scsi_inquiry_data *inq_data,
 2025                              struct scsi_sense_desc_header *header);
 2026 void scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
 2027                          u_int sense_len, uint8_t *cdb, int cdb_len,
 2028                          struct scsi_inquiry_data *inq_data,
 2029                          struct scsi_sense_desc_header *header);
 2030 void scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
 2031                          u_int sense_len, uint8_t *cdb, int cdb_len,
 2032                          struct scsi_inquiry_data *inq_data,
 2033                          struct scsi_sense_desc_header *header);
 2034 void scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
 2035                             u_int sense_len, uint8_t *cdb, int cdb_len,
 2036                             struct scsi_inquiry_data *inq_data,
 2037                             struct scsi_sense_desc_header *header);
 2038 void scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
 2039                            u_int sense_len, uint8_t *cdb, int cdb_len,
 2040                            struct scsi_inquiry_data *inq_data,
 2041                            struct scsi_sense_desc_header *header);
 2042 void scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
 2043                               u_int sense_len, uint8_t *cdb, int cdb_len,
 2044                               struct scsi_inquiry_data *inq_data,
 2045                               struct scsi_sense_desc_header *header);
 2046 void scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
 2047                              u_int sense_len, uint8_t *cdb, int cdb_len,
 2048                              struct scsi_inquiry_data *inq_data,
 2049                              struct scsi_sense_desc_header *header);
 2050 void scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
 2051                           u_int sense_len, uint8_t *cdb, int cdb_len,
 2052                           struct scsi_inquiry_data *inq_data,
 2053                           struct scsi_sense_desc_header *header);
 2054 scsi_sense_data_type scsi_sense_type(struct scsi_sense_data *sense_data);
 2055 
 2056 void scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len,
 2057                           struct sbuf *sb, char *path_str,
 2058                           struct scsi_inquiry_data *inq_data, uint8_t *cdb,
 2059                           int cdb_len);
 2060 
 2061 #ifdef _KERNEL
 2062 int             scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
 2063 int             scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
 2064                                 scsi_sense_string_flags flags);
 2065 char *          scsi_sense_string(struct ccb_scsiio *csio,
 2066                                   char *str, int str_len);
 2067 void            scsi_sense_print(struct ccb_scsiio *csio);
 2068 int             scsi_interpret_sense(union ccb *ccb, 
 2069                                      u_int32_t sense_flags,
 2070                                      u_int32_t *relsim_flags, 
 2071                                      u_int32_t *reduction,
 2072                                      u_int32_t *timeout,
 2073                                      scsi_sense_action error_action);
 2074 #else /* _KERNEL */
 2075 int             scsi_command_string(struct cam_device *device,
 2076                                     struct ccb_scsiio *csio, struct sbuf *sb);
 2077 int             scsi_sense_sbuf(struct cam_device *device, 
 2078                                 struct ccb_scsiio *csio, struct sbuf *sb,
 2079                                 scsi_sense_string_flags flags);
 2080 char *          scsi_sense_string(struct cam_device *device, 
 2081                                   struct ccb_scsiio *csio,
 2082                                   char *str, int str_len);
 2083 void            scsi_sense_print(struct cam_device *device, 
 2084                                  struct ccb_scsiio *csio, FILE *ofile);
 2085 int             scsi_interpret_sense(struct cam_device *device,
 2086                                      union ccb *ccb,
 2087                                      u_int32_t sense_flags,
 2088                                      u_int32_t *relsim_flags, 
 2089                                      u_int32_t *reduction,
 2090                                      u_int32_t *timeout,
 2091                                      scsi_sense_action error_action);
 2092 #endif /* _KERNEL */
 2093 
 2094 #define SF_RETRY_UA     0x01
 2095 #define SF_NO_PRINT     0x02
 2096 #define SF_QUIET_IR     0x04    /* Be quiet about Illegal Request reponses */
 2097 #define SF_PRINT_ALWAYS 0x08
 2098 
 2099 
 2100 const char *    scsi_op_desc(u_int16_t opcode, 
 2101                              struct scsi_inquiry_data *inq_data);
 2102 char *          scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
 2103                                 size_t len);
 2104 
 2105 void            scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
 2106 
 2107 u_int           scsi_calc_syncsrate(u_int period_factor);
 2108 u_int           scsi_calc_syncparam(u_int period);
 2109 
 2110 typedef int     (*scsi_devid_checkfn_t)(uint8_t *);
 2111 int             scsi_devid_is_naa_ieee_reg(uint8_t *bufp);
 2112 int             scsi_devid_is_sas_target(uint8_t *bufp);
 2113 uint8_t *       scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t len,
 2114                                scsi_devid_checkfn_t ck_fn);
 2115 
 2116 void            scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
 2117                                      void (*cbfcnp)(struct cam_periph *, 
 2118                                                     union ccb *),
 2119                                      u_int8_t tag_action, 
 2120                                      u_int8_t sense_len, u_int32_t timeout);
 2121 
 2122 void            scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
 2123                                    void (*cbfcnp)(struct cam_periph *, 
 2124                                                   union ccb *),
 2125                                    void *data_ptr, u_int8_t dxfer_len,
 2126                                    u_int8_t tag_action, u_int8_t sense_len,
 2127                                    u_int32_t timeout);
 2128 
 2129 void            scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
 2130                              void (*cbfcnp)(struct cam_periph *, union ccb *),
 2131                              u_int8_t tag_action, u_int8_t *inq_buf, 
 2132                              u_int32_t inq_len, int evpd, u_int8_t page_code,
 2133                              u_int8_t sense_len, u_int32_t timeout);
 2134 
 2135 void            scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
 2136                                 void (*cbfcnp)(struct cam_periph *,
 2137                                                union ccb *),
 2138                                 u_int8_t tag_action, int dbd,
 2139                                 u_int8_t page_code, u_int8_t page,
 2140                                 u_int8_t *param_buf, u_int32_t param_len,
 2141                                 u_int8_t sense_len, u_int32_t timeout);
 2142 
 2143 void            scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
 2144                                     void (*cbfcnp)(struct cam_periph *,
 2145                                                    union ccb *),
 2146                                     u_int8_t tag_action, int dbd,
 2147                                     u_int8_t page_code, u_int8_t page,
 2148                                     u_int8_t *param_buf, u_int32_t param_len,
 2149                                     int minimum_cmd_size, u_int8_t sense_len,
 2150                                     u_int32_t timeout);
 2151 
 2152 void            scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
 2153                                  void (*cbfcnp)(struct cam_periph *,
 2154                                                 union ccb *),
 2155                                  u_int8_t tag_action, int scsi_page_fmt,
 2156                                  int save_pages, u_int8_t *param_buf,
 2157                                  u_int32_t param_len, u_int8_t sense_len,
 2158                                  u_int32_t timeout);
 2159 
 2160 void            scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
 2161                                      void (*cbfcnp)(struct cam_periph *,
 2162                                                     union ccb *),
 2163                                      u_int8_t tag_action, int scsi_page_fmt,
 2164                                      int save_pages, u_int8_t *param_buf,
 2165                                      u_int32_t param_len, int minimum_cmd_size,
 2166                                      u_int8_t sense_len, u_int32_t timeout);
 2167 
 2168 void            scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
 2169                                void (*cbfcnp)(struct cam_periph *, union ccb *),
 2170                                u_int8_t tag_action, u_int8_t page_code,
 2171                                u_int8_t page, int save_pages, int ppc,
 2172                                u_int32_t paramptr, u_int8_t *param_buf,
 2173                                u_int32_t param_len, u_int8_t sense_len,
 2174                                u_int32_t timeout);
 2175 
 2176 void            scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
 2177                                 void (*cbfcnp)(struct cam_periph *,
 2178                                 union ccb *), u_int8_t tag_action,
 2179                                 u_int8_t page_code, int save_pages,
 2180                                 int pc_reset, u_int8_t *param_buf,
 2181                                 u_int32_t param_len, u_int8_t sense_len,
 2182                                 u_int32_t timeout);
 2183 
 2184 void            scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
 2185                              void (*cbfcnp)(struct cam_periph *, union ccb *),
 2186                              u_int8_t tag_action, u_int8_t action,
 2187                              u_int8_t sense_len, u_int32_t timeout);
 2188 
 2189 void            scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
 2190                                    void (*cbfcnp)(struct cam_periph *, 
 2191                                    union ccb *), u_int8_t tag_action, 
 2192                                    struct scsi_read_capacity_data *,
 2193                                    u_int8_t sense_len, u_int32_t timeout);
 2194 void            scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
 2195                                       void (*cbfcnp)(struct cam_periph *,
 2196                                       union ccb *), uint8_t tag_action,
 2197                                       uint64_t lba, int reladr, int pmi,
 2198                                       struct scsi_read_capacity_data_long
 2199                                       *rcap_buf, uint8_t sense_len,
 2200                                       uint32_t timeout);
 2201 
 2202 void            scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
 2203                                  void (*cbfcnp)(struct cam_periph *, 
 2204                                  union ccb *), u_int8_t tag_action, 
 2205                                  u_int8_t select_report,
 2206                                  struct scsi_report_luns_data *rpl_buf,
 2207                                  u_int32_t alloc_len, u_int8_t sense_len,
 2208                                  u_int32_t timeout);
 2209 
 2210 void            scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
 2211                                  void (*cbfcnp)(struct cam_periph *, 
 2212                                  union ccb *), u_int8_t tag_action, 
 2213                                  u_int8_t pdf,
 2214                                  void *buf,
 2215                                  u_int32_t alloc_len, u_int8_t sense_len,
 2216                                  u_int32_t timeout);
 2217 
 2218 void            scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
 2219                                  void (*cbfcnp)(struct cam_periph *, 
 2220                                  union ccb *), u_int8_t tag_action, void *buf,
 2221                                  u_int32_t alloc_len, u_int8_t sense_len,
 2222                                  u_int32_t timeout);
 2223 
 2224 void            scsi_synchronize_cache(struct ccb_scsiio *csio, 
 2225                                        u_int32_t retries,
 2226                                        void (*cbfcnp)(struct cam_periph *, 
 2227                                        union ccb *), u_int8_t tag_action, 
 2228                                        u_int32_t begin_lba, u_int16_t lb_count,
 2229                                        u_int8_t sense_len, u_int32_t timeout);
 2230 
 2231 void scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
 2232                                      void (*cbfcnp)(struct cam_periph *,
 2233                                                     union ccb*),
 2234                                      uint8_t tag_action, int pcv,
 2235                                      uint8_t page_code, uint8_t *data_ptr,
 2236                                      uint16_t allocation_length,
 2237                                      uint8_t sense_len, uint32_t timeout);
 2238 
 2239 void scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
 2240                           void (*cbfcnp)(struct cam_periph *, union ccb *),
 2241                           uint8_t tag_action, int unit_offline,
 2242                           int device_offline, int self_test, int page_format,
 2243                           int self_test_code, uint8_t *data_ptr,
 2244                           uint16_t param_list_length, uint8_t sense_len,
 2245                           uint32_t timeout);
 2246 
 2247 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
 2248                      void (*cbfcnp)(struct cam_periph *, union ccb *),
 2249                      u_int8_t tag_action, int readop, u_int8_t byte2, 
 2250                      int minimum_cmd_size, u_int64_t lba,
 2251                      u_int32_t block_count, u_int8_t *data_ptr,
 2252                      u_int32_t dxfer_len, u_int8_t sense_len,
 2253                      u_int32_t timeout);
 2254 
 2255 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
 2256                      void (*cbfcnp)(struct cam_periph *, union ccb *),
 2257                      u_int8_t tag_action, int start, int load_eject,
 2258                      int immediate, u_int8_t sense_len, u_int32_t timeout);
 2259 
 2260 int             scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
 2261 int             scsi_static_inquiry_match(caddr_t inqbuffer,
 2262                                           caddr_t table_entry);
 2263 int             scsi_devid_match(uint8_t *rhs, size_t rhs_len,
 2264                                  uint8_t *lhs, size_t lhs_len);
 2265 
 2266 void scsi_extract_sense(struct scsi_sense_data *sense, int *error_code,
 2267                         int *sense_key, int *asc, int *ascq);
 2268 void scsi_extract_sense_len(struct scsi_sense_data *sense,
 2269                             u_int sense_len, int *error_code, int *sense_key,
 2270                             int *asc, int *ascq, int show_errors);
 2271 int scsi_get_sense_key(struct scsi_sense_data *sense, u_int sense_len,
 2272                        int show_errors);
 2273 int scsi_get_asc(struct scsi_sense_data *sense, u_int sense_len,
 2274                  int show_errors);
 2275 int scsi_get_ascq(struct scsi_sense_data *sense, u_int sense_len,
 2276                   int show_errors);
 2277 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
 2278 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
 2279 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
 2280 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
 2281 static __inline uint32_t scsi_2btoul(const uint8_t *bytes);
 2282 static __inline uint32_t scsi_3btoul(const uint8_t *bytes);
 2283 static __inline int32_t scsi_3btol(const uint8_t *bytes);
 2284 static __inline uint32_t scsi_4btoul(const uint8_t *bytes);
 2285 static __inline uint64_t scsi_8btou64(const uint8_t *bytes);
 2286 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
 2287 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
 2288 
 2289 static __inline void
 2290 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
 2291 {
 2292 
 2293         bytes[0] = (val >> 8) & 0xff;
 2294         bytes[1] = val & 0xff;
 2295 }
 2296 
 2297 static __inline void
 2298 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
 2299 {
 2300 
 2301         bytes[0] = (val >> 16) & 0xff;
 2302         bytes[1] = (val >> 8) & 0xff;
 2303         bytes[2] = val & 0xff;
 2304 }
 2305 
 2306 static __inline void
 2307 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
 2308 {
 2309 
 2310         bytes[0] = (val >> 24) & 0xff;
 2311         bytes[1] = (val >> 16) & 0xff;
 2312         bytes[2] = (val >> 8) & 0xff;
 2313         bytes[3] = val & 0xff;
 2314 }
 2315 
 2316 static __inline void
 2317 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
 2318 {
 2319 
 2320         bytes[0] = (val >> 56) & 0xff;
 2321         bytes[1] = (val >> 48) & 0xff;
 2322         bytes[2] = (val >> 40) & 0xff;
 2323         bytes[3] = (val >> 32) & 0xff;
 2324         bytes[4] = (val >> 24) & 0xff;
 2325         bytes[5] = (val >> 16) & 0xff;
 2326         bytes[6] = (val >> 8) & 0xff;
 2327         bytes[7] = val & 0xff;
 2328 }
 2329 
 2330 static __inline uint32_t
 2331 scsi_2btoul(const uint8_t *bytes)
 2332 {
 2333         uint32_t rv;
 2334 
 2335         rv = (bytes[0] << 8) |
 2336              bytes[1];
 2337         return (rv);
 2338 }
 2339 
 2340 static __inline uint32_t
 2341 scsi_3btoul(const uint8_t *bytes)
 2342 {
 2343         uint32_t rv;
 2344 
 2345         rv = (bytes[0] << 16) |
 2346              (bytes[1] << 8) |
 2347              bytes[2];
 2348         return (rv);
 2349 }
 2350 
 2351 static __inline int32_t 
 2352 scsi_3btol(const uint8_t *bytes)
 2353 {
 2354         uint32_t rc = scsi_3btoul(bytes);
 2355  
 2356         if (rc & 0x00800000)
 2357                 rc |= 0xff000000;
 2358 
 2359         return (int32_t) rc;
 2360 }
 2361 
 2362 static __inline uint32_t
 2363 scsi_4btoul(const uint8_t *bytes)
 2364 {
 2365         uint32_t rv;
 2366 
 2367         rv = (bytes[0] << 24) |
 2368              (bytes[1] << 16) |
 2369              (bytes[2] << 8) |
 2370              bytes[3];
 2371         return (rv);
 2372 }
 2373 
 2374 static __inline uint64_t
 2375 scsi_8btou64(const uint8_t *bytes)
 2376 {
 2377         uint64_t rv;
 2378  
 2379         rv = (((uint64_t)bytes[0]) << 56) |
 2380              (((uint64_t)bytes[1]) << 48) |
 2381              (((uint64_t)bytes[2]) << 40) |
 2382              (((uint64_t)bytes[3]) << 32) |
 2383              (((uint64_t)bytes[4]) << 24) |
 2384              (((uint64_t)bytes[5]) << 16) |
 2385              (((uint64_t)bytes[6]) << 8) |
 2386              bytes[7];
 2387         return (rv);
 2388 }
 2389 
 2390 /*
 2391  * Given the pointer to a returned mode sense buffer, return a pointer to
 2392  * the start of the first mode page.
 2393  */
 2394 static __inline void *
 2395 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
 2396 {
 2397         void *page_start;
 2398 
 2399         page_start = (void *)((u_int8_t *)&mode_header[1] +
 2400                               mode_header->blk_desc_len);
 2401 
 2402         return(page_start);
 2403 }
 2404 
 2405 static __inline void *
 2406 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
 2407 {
 2408         void *page_start;
 2409 
 2410         page_start = (void *)((u_int8_t *)&mode_header[1] +
 2411                                scsi_2btoul(mode_header->blk_desc_len));
 2412 
 2413         return(page_start);
 2414 }
 2415 
 2416 __END_DECLS
 2417 
 2418 #endif /*_SCSI_SCSI_ALL_H*/

Cache object: 74c8e54c6ad5894368b8c3dc5f0c1f82


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.