19fbe302bSMichael S. Tsirkin /*
29fbe302bSMichael S. Tsirkin  * This header is BSD licensed so anyone can use the definitions to implement
39fbe302bSMichael S. Tsirkin  * compatible drivers/servers.
49fbe302bSMichael S. Tsirkin  *
59fbe302bSMichael S. Tsirkin  * Redistribution and use in source and binary forms, with or without
69fbe302bSMichael S. Tsirkin  * modification, are permitted provided that the following conditions
79fbe302bSMichael S. Tsirkin  * are met:
89fbe302bSMichael S. Tsirkin  * 1. Redistributions of source code must retain the above copyright
99fbe302bSMichael S. Tsirkin  *    notice, this list of conditions and the following disclaimer.
109fbe302bSMichael S. Tsirkin  * 2. Redistributions in binary form must reproduce the above copyright
119fbe302bSMichael S. Tsirkin  *    notice, this list of conditions and the following disclaimer in the
129fbe302bSMichael S. Tsirkin  *    documentation and/or other materials provided with the distribution.
139fbe302bSMichael S. Tsirkin  *
149fbe302bSMichael S. Tsirkin  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
159fbe302bSMichael S. Tsirkin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
169fbe302bSMichael S. Tsirkin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
179fbe302bSMichael S. Tsirkin  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
189fbe302bSMichael S. Tsirkin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199fbe302bSMichael S. Tsirkin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
209fbe302bSMichael S. Tsirkin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
219fbe302bSMichael S. Tsirkin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
229fbe302bSMichael S. Tsirkin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
239fbe302bSMichael S. Tsirkin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
249fbe302bSMichael S. Tsirkin  * SUCH DAMAGE.
259fbe302bSMichael S. Tsirkin  */
269fbe302bSMichael S. Tsirkin 
279fbe302bSMichael S. Tsirkin #ifndef _LINUX_VIRTIO_SCSI_H
289fbe302bSMichael S. Tsirkin #define _LINUX_VIRTIO_SCSI_H
299fbe302bSMichael S. Tsirkin 
309fbe302bSMichael S. Tsirkin #include "standard-headers/linux/virtio_types.h"
319fbe302bSMichael S. Tsirkin 
32*2106ba30SMichael S. Tsirkin /* Default values of the CDB and sense data size configuration fields */
33*2106ba30SMichael S. Tsirkin #define VIRTIO_SCSI_CDB_DEFAULT_SIZE   32
34*2106ba30SMichael S. Tsirkin #define VIRTIO_SCSI_SENSE_DEFAULT_SIZE 96
35*2106ba30SMichael S. Tsirkin 
36*2106ba30SMichael S. Tsirkin #ifndef VIRTIO_SCSI_CDB_SIZE
37*2106ba30SMichael S. Tsirkin #define VIRTIO_SCSI_CDB_SIZE VIRTIO_SCSI_CDB_DEFAULT_SIZE
38*2106ba30SMichael S. Tsirkin #endif
39*2106ba30SMichael S. Tsirkin #ifndef VIRTIO_SCSI_SENSE_SIZE
40*2106ba30SMichael S. Tsirkin #define VIRTIO_SCSI_SENSE_SIZE VIRTIO_SCSI_SENSE_DEFAULT_SIZE
41*2106ba30SMichael S. Tsirkin #endif
429fbe302bSMichael S. Tsirkin 
439fbe302bSMichael S. Tsirkin /* SCSI command request, followed by data-out */
449fbe302bSMichael S. Tsirkin struct virtio_scsi_cmd_req {
459fbe302bSMichael S. Tsirkin 	uint8_t lun[8];		/* Logical Unit Number */
469fbe302bSMichael S. Tsirkin 	__virtio64 tag;		/* Command identifier */
479fbe302bSMichael S. Tsirkin 	uint8_t task_attr;		/* Task attribute */
489fbe302bSMichael S. Tsirkin 	uint8_t prio;		/* SAM command priority field */
499fbe302bSMichael S. Tsirkin 	uint8_t crn;
509fbe302bSMichael S. Tsirkin 	uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
519fbe302bSMichael S. Tsirkin } QEMU_PACKED;
529fbe302bSMichael S. Tsirkin 
539fbe302bSMichael S. Tsirkin /* SCSI command request, followed by protection information */
549fbe302bSMichael S. Tsirkin struct virtio_scsi_cmd_req_pi {
559fbe302bSMichael S. Tsirkin 	uint8_t lun[8];		/* Logical Unit Number */
569fbe302bSMichael S. Tsirkin 	__virtio64 tag;		/* Command identifier */
579fbe302bSMichael S. Tsirkin 	uint8_t task_attr;		/* Task attribute */
589fbe302bSMichael S. Tsirkin 	uint8_t prio;		/* SAM command priority field */
599fbe302bSMichael S. Tsirkin 	uint8_t crn;
609fbe302bSMichael S. Tsirkin 	__virtio32 pi_bytesout;	/* DataOUT PI Number of bytes */
619fbe302bSMichael S. Tsirkin 	__virtio32 pi_bytesin;		/* DataIN PI Number of bytes */
629fbe302bSMichael S. Tsirkin 	uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
639fbe302bSMichael S. Tsirkin } QEMU_PACKED;
649fbe302bSMichael S. Tsirkin 
659fbe302bSMichael S. Tsirkin /* Response, followed by sense data and data-in */
669fbe302bSMichael S. Tsirkin struct virtio_scsi_cmd_resp {
679fbe302bSMichael S. Tsirkin 	__virtio32 sense_len;		/* Sense data length */
689fbe302bSMichael S. Tsirkin 	__virtio32 resid;		/* Residual bytes in data buffer */
699fbe302bSMichael S. Tsirkin 	__virtio16 status_qualifier;	/* Status qualifier */
709fbe302bSMichael S. Tsirkin 	uint8_t status;		/* Command completion status */
719fbe302bSMichael S. Tsirkin 	uint8_t response;		/* Response values */
729fbe302bSMichael S. Tsirkin 	uint8_t sense[VIRTIO_SCSI_SENSE_SIZE];
739fbe302bSMichael S. Tsirkin } QEMU_PACKED;
749fbe302bSMichael S. Tsirkin 
759fbe302bSMichael S. Tsirkin /* Task Management Request */
769fbe302bSMichael S. Tsirkin struct virtio_scsi_ctrl_tmf_req {
779fbe302bSMichael S. Tsirkin 	__virtio32 type;
789fbe302bSMichael S. Tsirkin 	__virtio32 subtype;
799fbe302bSMichael S. Tsirkin 	uint8_t lun[8];
809fbe302bSMichael S. Tsirkin 	__virtio64 tag;
819fbe302bSMichael S. Tsirkin } QEMU_PACKED;
829fbe302bSMichael S. Tsirkin 
839fbe302bSMichael S. Tsirkin struct virtio_scsi_ctrl_tmf_resp {
849fbe302bSMichael S. Tsirkin 	uint8_t response;
859fbe302bSMichael S. Tsirkin } QEMU_PACKED;
869fbe302bSMichael S. Tsirkin 
879fbe302bSMichael S. Tsirkin /* Asynchronous notification query/subscription */
889fbe302bSMichael S. Tsirkin struct virtio_scsi_ctrl_an_req {
899fbe302bSMichael S. Tsirkin 	__virtio32 type;
909fbe302bSMichael S. Tsirkin 	uint8_t lun[8];
919fbe302bSMichael S. Tsirkin 	__virtio32 event_requested;
929fbe302bSMichael S. Tsirkin } QEMU_PACKED;
939fbe302bSMichael S. Tsirkin 
949fbe302bSMichael S. Tsirkin struct virtio_scsi_ctrl_an_resp {
959fbe302bSMichael S. Tsirkin 	__virtio32 event_actual;
969fbe302bSMichael S. Tsirkin 	uint8_t response;
979fbe302bSMichael S. Tsirkin } QEMU_PACKED;
989fbe302bSMichael S. Tsirkin 
999fbe302bSMichael S. Tsirkin struct virtio_scsi_event {
1009fbe302bSMichael S. Tsirkin 	__virtio32 event;
1019fbe302bSMichael S. Tsirkin 	uint8_t lun[8];
1029fbe302bSMichael S. Tsirkin 	__virtio32 reason;
1039fbe302bSMichael S. Tsirkin } QEMU_PACKED;
1049fbe302bSMichael S. Tsirkin 
1059fbe302bSMichael S. Tsirkin struct virtio_scsi_config {
1069fbe302bSMichael S. Tsirkin 	uint32_t num_queues;
1079fbe302bSMichael S. Tsirkin 	uint32_t seg_max;
1089fbe302bSMichael S. Tsirkin 	uint32_t max_sectors;
1099fbe302bSMichael S. Tsirkin 	uint32_t cmd_per_lun;
1109fbe302bSMichael S. Tsirkin 	uint32_t event_info_size;
1119fbe302bSMichael S. Tsirkin 	uint32_t sense_size;
1129fbe302bSMichael S. Tsirkin 	uint32_t cdb_size;
1139fbe302bSMichael S. Tsirkin 	uint16_t max_channel;
1149fbe302bSMichael S. Tsirkin 	uint16_t max_target;
1159fbe302bSMichael S. Tsirkin 	uint32_t max_lun;
1169fbe302bSMichael S. Tsirkin } QEMU_PACKED;
1179fbe302bSMichael S. Tsirkin 
1189fbe302bSMichael S. Tsirkin /* Feature Bits */
1199fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_F_INOUT                    0
1209fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_F_HOTPLUG                  1
1219fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_F_CHANGE                   2
1229fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_F_T10_PI                   3
1239fbe302bSMichael S. Tsirkin 
1249fbe302bSMichael S. Tsirkin /* Response codes */
1259fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_OK                       0
1269fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_OVERRUN                  1
1279fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_ABORTED                  2
1289fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_BAD_TARGET               3
1299fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_RESET                    4
1309fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_BUSY                     5
1319fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_TRANSPORT_FAILURE        6
1329fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_TARGET_FAILURE           7
1339fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_NEXUS_FAILURE            8
1349fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_FAILURE                  9
1359fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED       10
1369fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_FUNCTION_REJECTED        11
1379fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_INCORRECT_LUN            12
1389fbe302bSMichael S. Tsirkin 
1399fbe302bSMichael S. Tsirkin /* Controlq type codes.  */
1409fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_TMF                      0
1419fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_AN_QUERY                 1
1429fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_AN_SUBSCRIBE             2
1439fbe302bSMichael S. Tsirkin 
1449fbe302bSMichael S. Tsirkin /* Valid TMF subtypes.  */
1459fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_TMF_ABORT_TASK           0
1469fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET       1
1479fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_TMF_CLEAR_ACA            2
1489fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET       3
1499fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET      4
1509fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET   5
1519fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_TMF_QUERY_TASK           6
1529fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET       7
1539fbe302bSMichael S. Tsirkin 
1549fbe302bSMichael S. Tsirkin /* Events.  */
1559fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_EVENTS_MISSED            0x80000000
1569fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_NO_EVENT                 0
1579fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_TRANSPORT_RESET          1
1589fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_ASYNC_NOTIFY             2
1599fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_T_PARAM_CHANGE             3
1609fbe302bSMichael S. Tsirkin 
1619fbe302bSMichael S. Tsirkin /* Reasons of transport reset event */
1629fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_EVT_RESET_HARD             0
1639fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_EVT_RESET_RESCAN           1
1649fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_EVT_RESET_REMOVED          2
1659fbe302bSMichael S. Tsirkin 
1669fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_SIMPLE                   0
1679fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_ORDERED                  1
1689fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_HEAD                     2
1699fbe302bSMichael S. Tsirkin #define VIRTIO_SCSI_S_ACA                      3
1709fbe302bSMichael S. Tsirkin 
1719fbe302bSMichael S. Tsirkin 
1729fbe302bSMichael S. Tsirkin #endif /* _LINUX_VIRTIO_SCSI_H */
173