1 | /* $Id: vscsi.h 56439 2015-06-15 17:14:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox storage drivers: Virtual SCSI driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef ___VBox_vscsi_h
|
---|
28 | #define ___VBox_vscsi_h
|
---|
29 |
|
---|
30 | #include <VBox/cdefs.h>
|
---|
31 | #include <VBox/types.h>
|
---|
32 | #include <iprt/sg.h>
|
---|
33 |
|
---|
34 | RT_C_DECLS_BEGIN
|
---|
35 |
|
---|
36 | #ifdef IN_RING0
|
---|
37 | # error "There are no VBox VSCSI APIs available in Ring-0 Host Context!"
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | /** A virtual SCSI device handle */
|
---|
41 | typedef struct VSCSIDEVICEINT *VSCSIDEVICE;
|
---|
42 | /** A pointer to a virtual SCSI device handle. */
|
---|
43 | typedef VSCSIDEVICE *PVSCSIDEVICE;
|
---|
44 | /** A virtual SCSI LUN handle. */
|
---|
45 | typedef struct VSCSILUNINT *VSCSILUN;
|
---|
46 | /** A pointer to a virtual SCSI LUN handle. */
|
---|
47 | typedef VSCSILUN *PVSCSILUN;
|
---|
48 | /** A virtual SCSI request handle. */
|
---|
49 | typedef struct VSCSIREQINT *VSCSIREQ;
|
---|
50 | /** A pointer to a virtual SCSI request handle. */
|
---|
51 | typedef VSCSIREQ *PVSCSIREQ;
|
---|
52 | /** A SCSI I/O request handle. */
|
---|
53 | typedef struct VSCSIIOREQINT *VSCSIIOREQ;
|
---|
54 | /** A pointer to a SCSI I/O request handle. */
|
---|
55 | typedef VSCSIIOREQ *PVSCSIIOREQ;
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Virtual SCSI I/O request transfer direction.
|
---|
59 | */
|
---|
60 | typedef enum VSCSIIOREQTXDIR
|
---|
61 | {
|
---|
62 | /** Invalid direction */
|
---|
63 | VSCSIIOREQTXDIR_INVALID = 0,
|
---|
64 | /** Read */
|
---|
65 | VSCSIIOREQTXDIR_READ,
|
---|
66 | /** Write */
|
---|
67 | VSCSIIOREQTXDIR_WRITE,
|
---|
68 | /** Flush */
|
---|
69 | VSCSIIOREQTXDIR_FLUSH,
|
---|
70 | /** Unmap */
|
---|
71 | VSCSIIOREQTXDIR_UNMAP,
|
---|
72 | /** 32bit hack */
|
---|
73 | VSCSIIOREQTXDIR_32BIT_HACK = 0x7fffffff
|
---|
74 | } VSCSIIOREQTXDIR;
|
---|
75 | /** Pointer to a SCSI LUN type */
|
---|
76 | typedef VSCSIIOREQTXDIR *PVSCSIIOREQTXDIR;
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * LUN types we support
|
---|
80 | */
|
---|
81 | typedef enum VSCSILUNTYPE
|
---|
82 | {
|
---|
83 | /** Invalid type */
|
---|
84 | VSCSILUNTYPE_INVALID = 0,
|
---|
85 | /** Hard disk (SBC) */
|
---|
86 | VSCSILUNTYPE_SBC,
|
---|
87 | /** CD/DVD drive (MMC) */
|
---|
88 | VSCSILUNTYPE_MMC,
|
---|
89 | /** Tape drive (SSC) */
|
---|
90 | VSCSILUNTYPE_SSC,
|
---|
91 | /** Last value to indicate an invalid device */
|
---|
92 | VSCSILUNTYPE_LAST,
|
---|
93 | /** 32bit hack */
|
---|
94 | VSCSILUNTYPE_32BIT_HACK = 0x7fffffff
|
---|
95 | } VSCSILUNTYPE;
|
---|
96 | /** Pointer to a SCSI LUN type */
|
---|
97 | typedef VSCSILUNTYPE *PVSCSILUNTYPE;
|
---|
98 |
|
---|
99 | /** The LUN can handle the UNMAP command. */
|
---|
100 | #define VSCSI_LUN_FEATURE_UNMAP RT_BIT(0)
|
---|
101 | /** The LUN has a non rotational medium. */
|
---|
102 | #define VSCSI_LUN_FEATURE_NON_ROTATIONAL RT_BIT(1)
|
---|
103 | /** The medium of the LUN is readonly. */
|
---|
104 | #define VSCSI_LUN_FEATURE_READONLY RT_BIT(2)
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Virtual SCSI LUN I/O Callback table.
|
---|
108 | */
|
---|
109 | typedef struct VSCSILUNIOCALLBACKS
|
---|
110 | {
|
---|
111 | /**
|
---|
112 | * Retrieve the size of the underlying medium.
|
---|
113 | *
|
---|
114 | * @returns VBox status status code.
|
---|
115 | * @param hVScsiLun Virtual SCSI LUN handle.
|
---|
116 | * @param pvScsiLunUser Opaque user data which may
|
---|
117 | * be used to identify the medium.
|
---|
118 | * @param pcbSize Where to store the size of the
|
---|
119 | * medium.
|
---|
120 | */
|
---|
121 | DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumGetSize, (VSCSILUN hVScsiLun,
|
---|
122 | void *pvScsiLunUser,
|
---|
123 | uint64_t *pcbSize));
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Retrieve the sector size of the underlying medium.
|
---|
127 | *
|
---|
128 | * @returns VBox status status code.
|
---|
129 | * @param hVScsiLun Virtual SCSI LUN handle.
|
---|
130 | * @param pvScsiLunUser Opaque user data which may
|
---|
131 | * be used to identify the medium.
|
---|
132 | * @param pcbSectorSize Where to store the sector size of the
|
---|
133 | * medium.
|
---|
134 | */
|
---|
135 | DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumGetSectorSize, (VSCSILUN hVScsiLun,
|
---|
136 | void *pvScsiLunUser,
|
---|
137 | uint32_t *pcbSectorSize));
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Set the lock state of the underlying medium.
|
---|
141 | *
|
---|
142 | * @returns VBox status status code.
|
---|
143 | * @param hVScsiLun Virtual SCSI LUN handle.
|
---|
144 | * @param pvScsiLunUser Opaque user data which may
|
---|
145 | * be used to identify the medium.
|
---|
146 | * @param fLocked New lock state (locked/unlocked).
|
---|
147 | */
|
---|
148 | DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumSetLock, (VSCSILUN hVScsiLun,
|
---|
149 | void *pvScsiLunUser,
|
---|
150 | bool fLocked));
|
---|
151 | /**
|
---|
152 | * Enqueue a read or write request from the medium.
|
---|
153 | *
|
---|
154 | * @returns VBox status status code.
|
---|
155 | * @param hVScsiLun Virtual SCSI LUN handle.
|
---|
156 | * @param pvScsiLunUser Opaque user data which may
|
---|
157 | * be used to identify the medium.
|
---|
158 | * @param hVScsiIoReq Virtual SCSI I/O request handle.
|
---|
159 | */
|
---|
160 | DECLR3CALLBACKMEMBER(int, pfnVScsiLunReqTransferEnqueue, (VSCSILUN hVScsiLun,
|
---|
161 | void *pvScsiLunUser,
|
---|
162 | VSCSIIOREQ hVScsiIoReq));
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Returns flags of supported features.
|
---|
166 | *
|
---|
167 | * @returns VBox status status code.
|
---|
168 | * @param hVScsiLun Virtual SCSI LUN handle.
|
---|
169 | * @param pvScsiLunUser Opaque user data which may
|
---|
170 | * be used to identify the medium.
|
---|
171 | * @param hVScsiIoReq Virtual SCSI I/O request handle.
|
---|
172 | */
|
---|
173 | DECLR3CALLBACKMEMBER(int, pfnVScsiLunGetFeatureFlags, (VSCSILUN hVScsiLun,
|
---|
174 | void *pvScsiLunUser,
|
---|
175 | uint64_t *pfFeatures));
|
---|
176 |
|
---|
177 |
|
---|
178 | } VSCSILUNIOCALLBACKS;
|
---|
179 | /** Pointer to a virtual SCSI LUN I/O callback table. */
|
---|
180 | typedef VSCSILUNIOCALLBACKS *PVSCSILUNIOCALLBACKS;
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * The virtual SCSI request completed callback.
|
---|
184 | */
|
---|
185 | typedef DECLCALLBACK(void) FNVSCSIREQCOMPLETED(VSCSIDEVICE hVScsiDevice,
|
---|
186 | void *pvVScsiDeviceUser,
|
---|
187 | void *pvVScsiReqUser,
|
---|
188 | int rcScsiCode,
|
---|
189 | bool fRedoPossible,
|
---|
190 | int rcReq);
|
---|
191 | /** Pointer to a virtual SCSI request completed callback. */
|
---|
192 | typedef FNVSCSIREQCOMPLETED *PFNVSCSIREQCOMPLETED;
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Create a new empty SCSI device instance.
|
---|
196 | *
|
---|
197 | * @returns VBox status code.
|
---|
198 | * @param phVScsiDevice Where to store the SCSI device handle.
|
---|
199 | * @param pfnVScsiReqCompleted The method call after a request completed.
|
---|
200 | * @param pvVScsiDeviceUser Opaque user data given in the completion callback.
|
---|
201 | */
|
---|
202 | VBOXDDU_DECL(int) VSCSIDeviceCreate(PVSCSIDEVICE phVScsiDevice,
|
---|
203 | PFNVSCSIREQCOMPLETED pfnVScsiReqCompleted,
|
---|
204 | void *pvVScsiDeviceUser);
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Destroy a SCSI device instance.
|
---|
208 | *
|
---|
209 | * @returns VBox status code.
|
---|
210 | * @param hScsiDevice The SCSI device handle to destroy.
|
---|
211 | */
|
---|
212 | VBOXDDU_DECL(int) VSCSIDeviceDestroy(VSCSIDEVICE hVScsiDevice);
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Attach a LUN to the SCSI device.
|
---|
216 | *
|
---|
217 | * @returns VBox status code.
|
---|
218 | * @param hScsiDevice The SCSI device handle to add the LUN to.
|
---|
219 | * @param hScsiLun The LUN handle to add.
|
---|
220 | * @param iLun The LUN number.
|
---|
221 | */
|
---|
222 | VBOXDDU_DECL(int) VSCSIDeviceLunAttach(VSCSIDEVICE hVScsiDevice, VSCSILUN hVScsiLun, uint32_t iLun);
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Detach a LUN from the SCSI device.
|
---|
226 | *
|
---|
227 | * @returns VBox status code.
|
---|
228 | * @param hVScsiDevice The SCSI device handle to add the LUN to.
|
---|
229 | * @param iLun The LUN number to remove.
|
---|
230 | * @param phVScsiLun Where to store the detached LUN handle.
|
---|
231 | */
|
---|
232 | VBOXDDU_DECL(int) VSCSIDeviceLunDetach(VSCSIDEVICE hVScsiDevice, uint32_t iLun,
|
---|
233 | PVSCSILUN phVScsiLun);
|
---|
234 |
|
---|
235 | /**
|
---|
236 | * Query the SCSI LUN type.
|
---|
237 | *
|
---|
238 | * @returns VBox status code.
|
---|
239 | * @param hVScsiDevice The SCSI device handle.
|
---|
240 | * @param iLun The LUN number to get.
|
---|
241 | * @param pEnmLunType Where to store the LUN type.
|
---|
242 | */
|
---|
243 | VBOXDDU_DECL(int) VSCSIDeviceLunQueryType(VSCSIDEVICE hVScsiDevice, uint32_t iLun,
|
---|
244 | PVSCSILUNTYPE pEnmLunType);
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Enqueue a request to the SCSI device.
|
---|
248 | *
|
---|
249 | * @returns VBox status code.
|
---|
250 | * @param hVScsiDevice The SCSI device handle.
|
---|
251 | * @param hVScsiReq The SCSI request handle to enqueue.
|
---|
252 | */
|
---|
253 | VBOXDDU_DECL(int) VSCSIDeviceReqEnqueue(VSCSIDEVICE hVScsiDevice, VSCSIREQ hVScsiReq);
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * Allocate a new request handle.
|
---|
257 | *
|
---|
258 | * @returns VBox status code.
|
---|
259 | * @param phVScsiDevice The SCSI device handle.
|
---|
260 | * @param phVScsiReq Where to SCSI request handle.
|
---|
261 | * @param iLun The LUN the request is for.
|
---|
262 | * @param pbCDB The CDB for the request.
|
---|
263 | * @param cbCDB The size of the CDB in bytes.
|
---|
264 | * @param cbSGList Number of bytes the S/G list describes.
|
---|
265 | * @param cSGListEntries Number of S/G list entries.
|
---|
266 | * @param paSGList Pointer to the S/G list.
|
---|
267 | * @param pbSense Pointer to the sense buffer.
|
---|
268 | * @param cbSense Size of the sense buffer.
|
---|
269 | * @param pvVScsiReqUser Opqaue user data returned when the request completes.
|
---|
270 | */
|
---|
271 | VBOXDDU_DECL(int) VSCSIDeviceReqCreate(VSCSIDEVICE hVScsiDevice, PVSCSIREQ phVScsiReq,
|
---|
272 | uint32_t iLun, uint8_t *pbCDB, size_t cbCDB,
|
---|
273 | size_t cbSGList, unsigned cSGListEntries,
|
---|
274 | PCRTSGSEG paSGList, uint8_t *pbSense,
|
---|
275 | size_t cbSense, void *pvVScsiReqUser);
|
---|
276 |
|
---|
277 | /**
|
---|
278 | * Create a new LUN.
|
---|
279 | *
|
---|
280 | * @returns VBox status code.
|
---|
281 | * @param phVScsiLun Where to store the SCSI LUN handle.
|
---|
282 | * @param enmLunType The Lun type.
|
---|
283 | * @param pVScsiLunIoCallbacks Pointer to the I/O callbacks to use for his LUN.
|
---|
284 | * @param pvVScsiLunUser Opaque user argument which
|
---|
285 | * is returned in the pvScsiLunUser parameter
|
---|
286 | * when the request completion callback is called.
|
---|
287 | */
|
---|
288 | VBOXDDU_DECL(int) VSCSILunCreate(PVSCSILUN phVScsiLun, VSCSILUNTYPE enmLunType,
|
---|
289 | PVSCSILUNIOCALLBACKS pVScsiLunIoCallbacks,
|
---|
290 | void *pvVScsiLunUser);
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * Destroy virtual SCSI LUN.
|
---|
294 | *
|
---|
295 | * @returns VBox status code.
|
---|
296 | * @param hVScsiLun The virtual SCSI LUN handle to destroy.
|
---|
297 | */
|
---|
298 | VBOXDDU_DECL(int) VSCSILunDestroy(VSCSILUN hVScsiLun);
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * Notify virtual SCSI LUN of medium being mounted.
|
---|
302 | *
|
---|
303 | * @returns VBox status code.
|
---|
304 | * @param hVScsiLun The virtual SCSI LUN handle to destroy.
|
---|
305 | */
|
---|
306 | VBOXDDU_DECL(int) VSCSILunMountNotify(VSCSILUN hVScsiLun);
|
---|
307 |
|
---|
308 | /**
|
---|
309 | * Notify virtual SCSI LUN of medium being unmounted.
|
---|
310 | *
|
---|
311 | * @returns VBox status code.
|
---|
312 | * @param hVScsiLun The virtual SCSI LUN handle to destroy.
|
---|
313 | */
|
---|
314 | VBOXDDU_DECL(int) VSCSILunUnmountNotify(VSCSILUN hVScsiLun);
|
---|
315 |
|
---|
316 | /**
|
---|
317 | * Notify a that a I/O request completed.
|
---|
318 | *
|
---|
319 | * @returns VBox status code.
|
---|
320 | * @param hVScsiIoReq The I/O request handle that completed.
|
---|
321 | * This is given when a I/O callback for
|
---|
322 | * the LUN is called by the virtual SCSI layer.
|
---|
323 | * @param rcIoReq The status code the I/O request completed with.
|
---|
324 | * @param fRedoPossible Flag whether it is possible to redo the request.
|
---|
325 | * If true setting any sense code will be omitted
|
---|
326 | * in case of an error to not alter the device state.
|
---|
327 | */
|
---|
328 | VBOXDDU_DECL(int) VSCSIIoReqCompleted(VSCSIIOREQ hVScsiIoReq, int rcIoReq, bool fRedoPossible);
|
---|
329 |
|
---|
330 | /**
|
---|
331 | * Query the transfer direction of the I/O request.
|
---|
332 | *
|
---|
333 | * @returns Transfer direction.of the given I/O request
|
---|
334 | * @param hVScsiIoReq The SCSI I/O request handle.
|
---|
335 | */
|
---|
336 | VBOXDDU_DECL(VSCSIIOREQTXDIR) VSCSIIoReqTxDirGet(VSCSIIOREQ hVScsiIoReq);
|
---|
337 |
|
---|
338 | /**
|
---|
339 | * Query I/O parameters.
|
---|
340 | *
|
---|
341 | * @returns VBox status code.
|
---|
342 | * @param hVScsiIoReq The SCSI I/O request handle.
|
---|
343 | * @param puOffset Where to store the start offset.
|
---|
344 | * @param pcbTransfer Where to store the amount of bytes to transfer.
|
---|
345 | * @param pcSeg Where to store the number of segments in the S/G list.
|
---|
346 | * @param pcbSeg Where to store the number of bytes the S/G list describes.
|
---|
347 | * @param ppaSeg Where to store the pointer to the S/G list.
|
---|
348 | */
|
---|
349 | VBOXDDU_DECL(int) VSCSIIoReqParamsGet(VSCSIIOREQ hVScsiIoReq, uint64_t *puOffset,
|
---|
350 | size_t *pcbTransfer, unsigned *pcSeg,
|
---|
351 | size_t *pcbSeg, PCRTSGSEG *ppaSeg);
|
---|
352 |
|
---|
353 | /**
|
---|
354 | * Query unmap parameters.
|
---|
355 | *
|
---|
356 | * @returns VBox status code.
|
---|
357 | * @param hVScsiIoReq The SCSI I/O request handle.
|
---|
358 | * @param ppaRanges Where to store the pointer to the range array on success.
|
---|
359 | * @param pcRanges Where to store the number of ranges on success.
|
---|
360 | */
|
---|
361 | VBOXDDU_DECL(int) VSCSIIoReqUnmapParamsGet(VSCSIIOREQ hVScsiIoReq, PCRTRANGE *ppaRanges,
|
---|
362 | unsigned *pcRanges);
|
---|
363 |
|
---|
364 | RT_C_DECLS_END
|
---|
365 |
|
---|
366 | #endif /* ___VBox_vscsi_h */
|
---|
367 |
|
---|