xref: /openbmc/linux/include/xen/interface/io/vscsiif.h (revision c10d12e3)
1 /* SPDX-License-Identifier: MIT */
2 /******************************************************************************
3  * vscsiif.h
4  *
5  * Based on the blkif.h code.
6  *
7  * Copyright(c) FUJITSU Limited 2008.
8  */
9 
10 #ifndef __XEN__PUBLIC_IO_SCSI_H__
11 #define __XEN__PUBLIC_IO_SCSI_H__
12 
13 #include "ring.h"
14 #include "../grant_table.h"
15 
16 /*
17  * Feature and Parameter Negotiation
18  * =================================
19  * The two halves of a Xen pvSCSI driver utilize nodes within the XenStore to
20  * communicate capabilities and to negotiate operating parameters.  This
21  * section enumerates these nodes which reside in the respective front and
22  * backend portions of the XenStore, following the XenBus convention.
23  *
24  * Any specified default value is in effect if the corresponding XenBus node
25  * is not present in the XenStore.
26  *
27  * XenStore nodes in sections marked "PRIVATE" are solely for use by the
28  * driver side whose XenBus tree contains them.
29  *
30  *****************************************************************************
31  *                            Backend XenBus Nodes
32  *****************************************************************************
33  *
34  *------------------ Backend Device Identification (PRIVATE) ------------------
35  *
36  * p-devname
37  *      Values:         string
38  *
39  *      A free string used to identify the physical device (e.g. a disk name).
40  *
41  * p-dev
42  *      Values:         string
43  *
44  *      A string specifying the backend device: either a 4-tuple "h:c:t:l"
45  *      (host, controller, target, lun, all integers), or a WWN (e.g.
46  *      "naa.60014054ac780582").
47  *
48  * v-dev
49  *      Values:         string
50  *
51  *      A string specifying the frontend device in form of a 4-tuple "h:c:t:l"
52  *      (host, controller, target, lun, all integers).
53  *
54  *--------------------------------- Features ---------------------------------
55  *
56  * feature-sg-grant
57  *      Values:         unsigned [VSCSIIF_SG_TABLESIZE...65535]
58  *      Default Value:  0
59  *
60  *      Specifies the maximum number of scatter/gather elements in grant pages
61  *      supported. If not set, the backend supports up to VSCSIIF_SG_TABLESIZE
62  *      SG elements specified directly in the request.
63  *
64  *****************************************************************************
65  *                            Frontend XenBus Nodes
66  *****************************************************************************
67  *
68  *----------------------- Request Transport Parameters -----------------------
69  *
70  * event-channel
71  *      Values:         unsigned
72  *
73  *      The identifier of the Xen event channel used to signal activity
74  *      in the ring buffer.
75  *
76  * ring-ref
77  *      Values:         unsigned
78  *
79  *      The Xen grant reference granting permission for the backend to map
80  *      the sole page in a single page sized ring buffer.
81  *
82  * protocol
83  *      Values:         string (XEN_IO_PROTO_ABI_*)
84  *      Default Value:  XEN_IO_PROTO_ABI_NATIVE
85  *
86  *      The machine ABI rules governing the format of all ring request and
87  *      response structures.
88  */
89 
90 /* Requests from the frontend to the backend */
91 
92 /*
93  * Request a SCSI operation specified via a CDB in vscsiif_request.cmnd.
94  * The target is specified via channel, id and lun.
95  *
96  * The operation to be performed is specified via a CDB in cmnd[], the length
97  * of the CDB is in cmd_len. sc_data_direction specifies the direction of data
98  * (to the device, from the device, or none at all).
99  *
100  * If data is to be transferred to or from the device the buffer(s) in the
101  * guest memory is/are specified via one or multiple scsiif_request_segment
102  * descriptors each specifying a memory page via a grant_ref_t, a offset into
103  * the page and the length of the area in that page. All scsiif_request_segment
104  * areas concatenated form the resulting data buffer used by the operation.
105  * If the number of scsiif_request_segment areas is not too large (less than
106  * or equal VSCSIIF_SG_TABLESIZE) the areas can be specified directly in the
107  * seg[] array and the number of valid scsiif_request_segment elements is to be
108  * set in nr_segments.
109  *
110  * If "feature-sg-grant" in the Xenstore is set it is possible to specify more
111  * than VSCSIIF_SG_TABLESIZE scsiif_request_segment elements via indirection.
112  * The maximum number of allowed scsiif_request_segment elements is the value
113  * of the "feature-sg-grant" entry from Xenstore. When using indirection the
114  * seg[] array doesn't contain specifications of the data buffers, but
115  * references to scsiif_request_segment arrays, which in turn reference the
116  * data buffers. While nr_segments holds the number of populated seg[] entries
117  * (plus the set VSCSIIF_SG_GRANT bit), the number of scsiif_request_segment
118  * elements referencing the target data buffers is calculated from the lengths
119  * of the seg[] elements (the sum of all valid seg[].length divided by the
120  * size of one scsiif_request_segment structure).
121  */
122 #define VSCSIIF_ACT_SCSI_CDB		1
123 
124 /*
125  * Request abort of a running operation for the specified target given by
126  * channel, id, lun and the operation's rqid in ref_rqid.
127  */
128 #define VSCSIIF_ACT_SCSI_ABORT		2
129 
130 /*
131  * Request a device reset of the specified target (channel and id).
132  */
133 #define VSCSIIF_ACT_SCSI_RESET		3
134 
135 /*
136  * Preset scatter/gather elements for a following request. Deprecated.
137  * Keeping the define only to avoid usage of the value "4" for other actions.
138  */
139 #define VSCSIIF_ACT_SCSI_SG_PRESET	4
140 
141 /*
142  * Maximum scatter/gather segments per request.
143  *
144  * Considering balance between allocating at least 16 "vscsiif_request"
145  * structures on one page (4096 bytes) and the number of scatter/gather
146  * elements needed, we decided to use 26 as a magic number.
147  *
148  * If "feature-sg-grant" is set, more scatter/gather elements can be specified
149  * by placing them in one or more (up to VSCSIIF_SG_TABLESIZE) granted pages.
150  * In this case the vscsiif_request seg elements don't contain references to
151  * the user data, but to the SG elements referencing the user data.
152  */
153 #define VSCSIIF_SG_TABLESIZE		26
154 
155 /*
156  * based on Linux kernel 2.6.18, still valid
157  * Changing these values requires support of multiple protocols via the rings
158  * as "old clients" will blindly use these values and the resulting structure
159  * sizes.
160  */
161 #define VSCSIIF_MAX_COMMAND_SIZE	16
162 #define VSCSIIF_SENSE_BUFFERSIZE	96
163 
164 struct scsiif_request_segment {
165 	grant_ref_t gref;
166 	uint16_t offset;
167 	uint16_t length;
168 };
169 
170 #define VSCSIIF_SG_PER_PAGE (PAGE_SIZE / sizeof(struct scsiif_request_segment))
171 
172 /* Size of one request is 252 bytes */
173 struct vscsiif_request {
174 	uint16_t rqid;		/* private guest value, echoed in resp  */
175 	uint8_t act;		/* command between backend and frontend */
176 	uint8_t cmd_len;	/* valid CDB bytes */
177 
178 	uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE];	/* the CDB */
179 	uint16_t timeout_per_command;	/* deprecated */
180 	uint16_t channel, id, lun;	/* (virtual) device specification */
181 	uint16_t ref_rqid;		/* command abort reference */
182 	uint8_t sc_data_direction;	/* for DMA_TO_DEVICE(1)
183 					   DMA_FROM_DEVICE(2)
184 					   DMA_NONE(3) requests */
185 	uint8_t nr_segments;		/* Number of pieces of scatter-gather */
186 /*
187  * flag in nr_segments: SG elements via grant page
188  *
189  * If VSCSIIF_SG_GRANT is set, the low 7 bits of nr_segments specify the number
190  * of grant pages containing SG elements. Usable if "feature-sg-grant" set.
191  */
192 #define VSCSIIF_SG_GRANT	0x80
193 
194 	struct scsiif_request_segment seg[VSCSIIF_SG_TABLESIZE];
195 	uint32_t reserved[3];
196 };
197 
198 /* Size of one response is 252 bytes */
199 struct vscsiif_response {
200 	uint16_t rqid;		/* identifies request */
201 	uint8_t padding;
202 	uint8_t sense_len;
203 	uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
204 	int32_t rslt;
205 	uint32_t residual_len;	/* request bufflen -
206 				   return the value from physical device */
207 	uint32_t reserved[36];
208 };
209 
210 DEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response);
211 
212 #endif /*__XEN__PUBLIC_IO_SCSI_H__*/
213