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