1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * This header is BSD licensed so anyone can use the definitions to implement 5 * compatible drivers/servers. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _VIRTIO_SCSI_H 30 #define _VIRTIO_SCSI_H 31 32 /* Default values of the CDB and sense data size configuration fields */ 33 #define VIRTIO_SCSI_CDB_SIZE 32 34 #define VIRTIO_SCSI_SENSE_SIZE 96 35 36 /* SCSI command request, followed by data-out */ 37 struct virtio_scsi_cmd_req { 38 uint8_t lun[8]; /* Logical Unit Number */ 39 uint64_t tag; /* Command identifier */ 40 uint8_t task_attr; /* Task attribute */ 41 uint8_t prio; /* SAM command priority field */ 42 uint8_t crn; 43 uint8_t cdb[VIRTIO_SCSI_CDB_SIZE]; 44 } __packed; 45 46 /* SCSI command request, followed by protection information */ 47 struct virtio_scsi_cmd_req_pi { 48 uint8_t lun[8]; /* Logical Unit Number */ 49 uint64_t tag; /* Command identifier */ 50 uint8_t task_attr; /* Task attribute */ 51 uint8_t prio; /* SAM command priority field */ 52 uint8_t crn; 53 uint32_t pi_bytesout; /* DataOUT PI Number of bytes */ 54 uint32_t pi_bytesin; /* DataIN PI Number of bytes */ 55 uint8_t cdb[VIRTIO_SCSI_CDB_SIZE]; 56 } __packed; 57 58 /* Response, followed by sense data and data-in */ 59 struct virtio_scsi_cmd_resp { 60 uint32_t sense_len; /* Sense data length */ 61 uint32_t resid; /* Residual bytes in data buffer */ 62 uint16_t status_qualifier; /* Status qualifier */ 63 uint8_t status; /* Command completion status */ 64 uint8_t response; /* Response values */ 65 uint8_t sense[VIRTIO_SCSI_SENSE_SIZE]; 66 } __packed; 67 68 /* Task Management Request */ 69 struct virtio_scsi_ctrl_tmf_req { 70 uint32_t type; 71 uint32_t subtype; 72 uint8_t lun[8]; 73 uint64_t tag; 74 } __packed; 75 76 struct virtio_scsi_ctrl_tmf_resp { 77 uint8_t response; 78 } __packed; 79 80 /* Asynchronous notification query/subscription */ 81 struct virtio_scsi_ctrl_an_req { 82 uint32_t type; 83 uint8_t lun[8]; 84 uint32_t event_requested; 85 } __packed; 86 87 struct virtio_scsi_ctrl_an_resp { 88 uint32_t event_actual; 89 uint8_t response; 90 } __packed; 91 92 struct virtio_scsi_event { 93 uint32_t event; 94 uint8_t lun[8]; 95 uint32_t reason; 96 } __packed; 97 98 struct virtio_scsi_config { 99 uint32_t num_queues; 100 uint32_t seg_max; 101 uint32_t max_sectors; 102 uint32_t cmd_per_lun; 103 uint32_t event_info_size; 104 uint32_t sense_size; 105 uint32_t cdb_size; 106 uint16_t max_channel; 107 uint16_t max_target; 108 uint32_t max_lun; 109 } __packed; 110 111 /* Feature bits */ 112 #define VIRTIO_SCSI_F_INOUT 0x0001 /* Single request can contain both 113 * read and write buffers. 114 */ 115 #define VIRTIO_SCSI_F_HOTPLUG 0x0002 /* Host should enable hot plug/unplug 116 * of new LUNs and targets. 117 */ 118 #define VIRTIO_SCSI_F_CHANGE 0x0004 /* Host will report changes to LUN 119 * parameters via a 120 * VIRTIO_SCSI_T_PARAM_CHANGE event. 121 */ 122 #define VIRTIO_SCSI_F_T10_PI 0x0008 /* Extended fields for T10 protection 123 * information (DIF/DIX) are included 124 * in the SCSI request header. 125 */ 126 127 /* Response codes */ 128 #define VIRTIO_SCSI_S_OK 0 129 #define VIRTIO_SCSI_S_FUNCTION_COMPLETE 0 130 #define VIRTIO_SCSI_S_OVERRUN 1 131 #define VIRTIO_SCSI_S_ABORTED 2 132 #define VIRTIO_SCSI_S_BAD_TARGET 3 133 #define VIRTIO_SCSI_S_RESET 4 134 #define VIRTIO_SCSI_S_BUSY 5 135 #define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6 136 #define VIRTIO_SCSI_S_TARGET_FAILURE 7 137 #define VIRTIO_SCSI_S_NEXUS_FAILURE 8 138 #define VIRTIO_SCSI_S_FAILURE 9 139 #define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10 140 #define VIRTIO_SCSI_S_FUNCTION_REJECTED 11 141 #define VIRTIO_SCSI_S_INCORRECT_LUN 12 142 143 /* Controlq type codes. */ 144 #define VIRTIO_SCSI_T_TMF 0 145 #define VIRTIO_SCSI_T_AN_QUERY 1 146 #define VIRTIO_SCSI_T_AN_SUBSCRIBE 2 147 148 /* Valid TMF subtypes. */ 149 #define VIRTIO_SCSI_T_TMF_ABORT_TASK 0 150 #define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1 151 #define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2 152 #define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3 153 #define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4 154 #define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5 155 #define VIRTIO_SCSI_T_TMF_QUERY_TASK 6 156 #define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7 157 158 /* Events. */ 159 #define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000 160 #define VIRTIO_SCSI_T_NO_EVENT 0 161 #define VIRTIO_SCSI_T_TRANSPORT_RESET 1 162 #define VIRTIO_SCSI_T_ASYNC_NOTIFY 2 163 #define VIRTIO_SCSI_T_PARAM_CHANGE 3 164 165 /* Reasons of transport reset event */ 166 #define VIRTIO_SCSI_EVT_RESET_HARD 0 167 #define VIRTIO_SCSI_EVT_RESET_RESCAN 1 168 #define VIRTIO_SCSI_EVT_RESET_REMOVED 2 169 170 #define VIRTIO_SCSI_S_SIMPLE 0 171 #define VIRTIO_SCSI_S_ORDERED 1 172 #define VIRTIO_SCSI_S_HEAD 2 173 #define VIRTIO_SCSI_S_ACA 3 174 175 #endif /* _VIRTIO_SCSI_H */ 176