1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 * $FreeBSD$ 29 */ 30 31 #ifndef _VIRTIO_SCSI_H 32 #define _VIRTIO_SCSI_H 33 34 /* Feature bits */ 35 #define VIRTIO_SCSI_F_INOUT 0x0001 /* Single request can contain both 36 * read and write buffers */ 37 #define VIRTIO_SCSI_F_HOTPLUG 0x0002 /* Host should enable hot plug/unplug 38 * of new LUNs and targets. 39 */ 40 41 #define VIRTIO_SCSI_CDB_SIZE 32 42 #define VIRTIO_SCSI_SENSE_SIZE 96 43 44 /* SCSI command request, followed by data-out */ 45 struct virtio_scsi_cmd_req { 46 uint8_t lun[8]; /* Logical Unit Number */ 47 uint64_t tag; /* Command identifier */ 48 uint8_t task_attr; /* Task attribute */ 49 uint8_t prio; 50 uint8_t crn; 51 uint8_t cdb[VIRTIO_SCSI_CDB_SIZE]; 52 } __packed; 53 54 /* Response, followed by sense data and data-in */ 55 struct virtio_scsi_cmd_resp { 56 uint32_t sense_len; /* Sense data length */ 57 uint32_t resid; /* Residual bytes in data buffer */ 58 uint16_t status_qualifier; /* Status qualifier */ 59 uint8_t status; /* Command completion status */ 60 uint8_t response; /* Response values */ 61 uint8_t sense[VIRTIO_SCSI_SENSE_SIZE]; 62 } __packed; 63 64 /* Task Management Request */ 65 struct virtio_scsi_ctrl_tmf_req { 66 uint32_t type; 67 uint32_t subtype; 68 uint8_t lun[8]; 69 uint64_t tag; 70 } __packed; 71 72 struct virtio_scsi_ctrl_tmf_resp { 73 uint8_t response; 74 } __packed; 75 76 /* Asynchronous notification query/subscription */ 77 struct virtio_scsi_ctrl_an_req { 78 uint32_t type; 79 uint8_t lun[8]; 80 uint32_t event_requested; 81 } __packed; 82 83 struct virtio_scsi_ctrl_an_resp { 84 uint32_t event_actual; 85 uint8_t response; 86 } __packed; 87 88 struct virtio_scsi_event { 89 uint32_t event; 90 uint8_t lun[8]; 91 uint32_t reason; 92 } __packed; 93 94 struct virtio_scsi_config { 95 uint32_t num_queues; 96 uint32_t seg_max; 97 uint32_t max_sectors; 98 uint32_t cmd_per_lun; 99 uint32_t event_info_size; 100 uint32_t sense_size; 101 uint32_t cdb_size; 102 uint16_t max_channel; 103 uint16_t max_target; 104 uint32_t max_lun; 105 } __packed; 106 107 /* Response codes */ 108 #define VIRTIO_SCSI_S_OK 0 109 #define VIRTIO_SCSI_S_FUNCTION_COMPLETE 0 110 #define VIRTIO_SCSI_S_OVERRUN 1 111 #define VIRTIO_SCSI_S_ABORTED 2 112 #define VIRTIO_SCSI_S_BAD_TARGET 3 113 #define VIRTIO_SCSI_S_RESET 4 114 #define VIRTIO_SCSI_S_BUSY 5 115 #define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6 116 #define VIRTIO_SCSI_S_TARGET_FAILURE 7 117 #define VIRTIO_SCSI_S_NEXUS_FAILURE 8 118 #define VIRTIO_SCSI_S_FAILURE 9 119 #define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10 120 #define VIRTIO_SCSI_S_FUNCTION_REJECTED 11 121 #define VIRTIO_SCSI_S_INCORRECT_LUN 12 122 123 /* Controlq type codes. */ 124 #define VIRTIO_SCSI_T_TMF 0 125 #define VIRTIO_SCSI_T_AN_QUERY 1 126 #define VIRTIO_SCSI_T_AN_SUBSCRIBE 2 127 128 /* Valid TMF subtypes. */ 129 #define VIRTIO_SCSI_T_TMF_ABORT_TASK 0 130 #define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1 131 #define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2 132 #define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3 133 #define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4 134 #define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5 135 #define VIRTIO_SCSI_T_TMF_QUERY_TASK 6 136 #define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7 137 138 /* Events. */ 139 #define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000 140 #define VIRTIO_SCSI_T_NO_EVENT 0 141 #define VIRTIO_SCSI_T_TRANSPORT_RESET 1 142 #define VIRTIO_SCSI_T_ASYNC_NOTIFY 2 143 144 /* Reasons of transport reset event */ 145 #define VIRTIO_SCSI_EVT_RESET_HARD 0 146 #define VIRTIO_SCSI_EVT_RESET_RESCAN 1 147 #define VIRTIO_SCSI_EVT_RESET_REMOVED 2 148 149 #define VIRTIO_SCSI_S_SIMPLE 0 150 #define VIRTIO_SCSI_S_ORDERED 1 151 #define VIRTIO_SCSI_S_HEAD 2 152 #define VIRTIO_SCSI_S_ACA 3 153 154 #endif /* _VIRTIO_SCSI_H */ 155