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