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