1 /* SPDX-License-Identifier: MIT */
2 /******************************************************************************
5 * Based on the blkif.h code.
7 * Copyright(c) FUJITSU Limited 2008.
10 #ifndef __XEN__PUBLIC_IO_SCSI_H__
11 #define __XEN__PUBLIC_IO_SCSI_H__
14 #include "../grant_table.h"
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.
24 * Any specified default value is in effect if the corresponding XenBus node
25 * is not present in the XenStore.
27 * XenStore nodes in sections marked "PRIVATE" are solely for use by the
28 * driver side whose XenBus tree contains them.
30 *****************************************************************************
31 * Backend XenBus Nodes
32 *****************************************************************************
34 *------------------ Backend Device Identification (PRIVATE) ------------------
39 * A free string used to identify the physical device (e.g. a disk name).
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").
51 * A string specifying the frontend device in form of a 4-tuple "h:c:t:l"
52 * (host, controller, target, lun, all integers).
54 *--------------------------------- Features ---------------------------------
57 * Values: unsigned [VSCSIIF_SG_TABLESIZE...65535]
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.
64 *****************************************************************************
65 * Frontend XenBus Nodes
66 *****************************************************************************
68 *----------------------- Request Transport Parameters -----------------------
73 * The identifier of the Xen event channel used to signal activity
79 * The Xen grant reference granting permission for the backend to map
80 * the sole page in a single page sized ring buffer.
83 * Values: string (XEN_IO_PROTO_ABI_*)
84 * Default Value: XEN_IO_PROTO_ABI_NATIVE
86 * The machine ABI rules governing the format of all ring request and
87 * response structures.
90 /* Requests from the frontend to the backend */
93 * Request a SCSI operation specified via a CDB in vscsiif_request.cmnd.
94 * The target is specified via channel, id and lun.
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).
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.
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).
122 #define VSCSIIF_ACT_SCSI_CDB 1
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.
128 #define VSCSIIF_ACT_SCSI_ABORT 2
131 * Request a device reset of the specified target (channel and id).
133 #define VSCSIIF_ACT_SCSI_RESET 3
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.
139 #define VSCSIIF_ACT_SCSI_SG_PRESET 4
142 * Maximum scatter/gather segments per request.
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.
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.
153 #define VSCSIIF_SG_TABLESIZE 26
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
161 #define VSCSIIF_MAX_COMMAND_SIZE 16
162 #define VSCSIIF_SENSE_BUFFERSIZE 96
164 struct scsiif_request_segment {
170 #define VSCSIIF_SG_PER_PAGE (PAGE_SIZE / sizeof(struct scsiif_request_segment))
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 */
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)
184 DMA_NONE(3) requests */
185 uint8_t nr_segments; /* Number of pieces of scatter-gather */
187 * flag in nr_segments: SG elements via grant page
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.
192 #define VSCSIIF_SG_GRANT 0x80
194 struct scsiif_request_segment seg[VSCSIIF_SG_TABLESIZE];
195 uint32_t reserved[3];
198 /* Size of one response is 252 bytes */
199 struct vscsiif_response {
200 uint16_t rqid; /* identifies request */
203 uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
205 uint32_t residual_len; /* request bufflen -
206 return the value from physical device */
207 uint32_t reserved[36];
210 DEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response);
212 #endif /*__XEN__PUBLIC_IO_SCSI_H__*/