VirtualBox

source: vbox/trunk/include/VBox/vscsi.h@ 79896

Last change on this file since 79896 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.3 KB
Line 
1/* $Id: vscsi.h 76585 2019-01-01 06:31:29Z vboxsync $ */
2/** @file
3 * VBox storage drivers - Virtual SCSI driver
4 */
5
6/*
7 * Copyright (C) 2006-2019 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_INCLUDED_vscsi_h
28#define VBOX_INCLUDED_vscsi_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#include <VBox/cdefs.h>
34#include <VBox/types.h>
35#include <VBox/vdmedia.h>
36#include <iprt/sg.h>
37
38RT_C_DECLS_BEGIN
39
40#ifdef IN_RING0
41# error "There are no VBox VSCSI APIs available in Ring-0 Host Context!"
42#endif
43
44/** @defgroup grp_drv_vscsi Virtual VSCSI Driver
45 * @ingroup grp_devdrv
46 * @{
47 */
48/** @todo figure better grouping. */
49
50/** A virtual SCSI device handle */
51typedef struct VSCSIDEVICEINT *VSCSIDEVICE;
52/** A pointer to a virtual SCSI device handle. */
53typedef VSCSIDEVICE *PVSCSIDEVICE;
54/** A virtual SCSI LUN handle. */
55typedef struct VSCSILUNINT *VSCSILUN;
56/** A pointer to a virtual SCSI LUN handle. */
57typedef VSCSILUN *PVSCSILUN;
58/** A virtual SCSI request handle. */
59typedef struct VSCSIREQINT *VSCSIREQ;
60/** A pointer to a virtual SCSI request handle. */
61typedef VSCSIREQ *PVSCSIREQ;
62/** A SCSI I/O request handle. */
63typedef struct VSCSIIOREQINT *VSCSIIOREQ;
64/** A pointer to a SCSI I/O request handle. */
65typedef VSCSIIOREQ *PVSCSIIOREQ;
66
67/**
68 * Virtual SCSI I/O request transfer direction.
69 */
70typedef enum VSCSIIOREQTXDIR
71{
72 /** Invalid direction */
73 VSCSIIOREQTXDIR_INVALID = 0,
74 /** Read */
75 VSCSIIOREQTXDIR_READ,
76 /** Write */
77 VSCSIIOREQTXDIR_WRITE,
78 /** Flush */
79 VSCSIIOREQTXDIR_FLUSH,
80 /** Unmap */
81 VSCSIIOREQTXDIR_UNMAP,
82 /** 32bit hack */
83 VSCSIIOREQTXDIR_32BIT_HACK = 0x7fffffff
84} VSCSIIOREQTXDIR;
85/** Pointer to a SCSI LUN type */
86typedef VSCSIIOREQTXDIR *PVSCSIIOREQTXDIR;
87
88/**
89 * LUN types we support
90 */
91typedef enum VSCSILUNTYPE
92{
93 /** Invalid type */
94 VSCSILUNTYPE_INVALID = 0,
95 /** Hard disk (SBC) */
96 VSCSILUNTYPE_SBC,
97 /** CD/DVD drive (MMC) */
98 VSCSILUNTYPE_MMC,
99 /** Tape drive (SSC) */
100 VSCSILUNTYPE_SSC,
101 /** Last value to indicate an invalid device */
102 VSCSILUNTYPE_LAST,
103 /** 32bit hack */
104 VSCSILUNTYPE_32BIT_HACK = 0x7fffffff
105} VSCSILUNTYPE;
106/** Pointer to a SCSI LUN type */
107typedef VSCSILUNTYPE *PVSCSILUNTYPE;
108
109/** The LUN can handle the UNMAP command. */
110#define VSCSI_LUN_FEATURE_UNMAP RT_BIT(0)
111/** The LUN has a non rotational medium. */
112#define VSCSI_LUN_FEATURE_NON_ROTATIONAL RT_BIT(1)
113/** The medium of the LUN is readonly. */
114#define VSCSI_LUN_FEATURE_READONLY RT_BIT(2)
115
116/**
117 * Virtual SCSI LUN I/O Callback table.
118 */
119typedef struct VSCSILUNIOCALLBACKS
120{
121 /**
122 * Sets the size of the allocator specific memory for a I/O request.
123 *
124 * @returns VBox status code.
125 * @param hVScsiLun Virtual SCSI LUN handle.
126 * @param pvScsiLunUser Opaque user data which may be used to identify the
127 * medium.
128 * @param cbVScsiIoReqAlloc The size of the allocator specific memory in bytes.
129 * @thread EMT.
130 */
131 DECLR3CALLBACKMEMBER(int, pfnVScsiLunReqAllocSizeSet, (VSCSILUN hVScsiLun, void *pvScsiLunUser,
132 size_t cbVScsiIoReqAlloc));
133
134 /**
135 * Allocates a new I/O request.
136 *
137 * @returns VBox status code.
138 * @param hVScsiLun Virtual SCSI LUN handle.
139 * @param pvScsiLunUser Opaque user data which may be used to identify the
140 * medium.
141 * @param u64Tag A tag to assign to the request handle for identification later on.
142 * @param phVScsiIoReq Where to store the handle to the allocated I/O request on success.
143 * @thread Any thread.
144 */
145 DECLR3CALLBACKMEMBER(int, pfnVScsiLunReqAlloc, (VSCSILUN hVScsiLun, void *pvScsiLunUser,
146 uint64_t u64Tag, PVSCSIIOREQ phVScsiIoReq));
147
148 /**
149 * Frees a given I/O request.
150 *
151 * @returns VBox status code.
152 * @param hVScsiLun Virtual SCSI LUN handle.
153 * @param pvScsiLunUser Opaque user data which may be used to identify the
154 * medium.
155 * @param hVScsiIoReq The VSCSI I/O request to free.
156 * @thread Any thread.
157 */
158 DECLR3CALLBACKMEMBER(int, pfnVScsiLunReqFree, (VSCSILUN hVScsiLun, void *pvScsiLunUser, VSCSIIOREQ hVScsiIoReq));
159
160 /**
161 * Returns the number of regions for the medium.
162 *
163 * @returns Number of regions.
164 * @param hVScsiLun Virtual SCSI LUN handle.
165 * @param pvScsiLunUser Opaque user data which may be used to identify the
166 * medium.
167 */
168 DECLR3CALLBACKMEMBER(uint32_t, pfnVScsiLunMediumGetRegionCount,(VSCSILUN hVScsiLun, void *pvScsiLunUser));
169
170 /**
171 * Queries the properties for the given region.
172 *
173 * @returns VBox status code.
174 * @retval VERR_NOT_FOUND if the region index is not known.
175 * @param hVScsiLun Virtual SCSI LUN handle.
176 * @param pvScsiLunUser Opaque user data which may be used to identify the
177 * medium.
178 * @param uRegion The region index to query the properties of.
179 * @param pu64LbaStart Where to store the starting LBA for the region on success.
180 * @param pcBlocks Where to store the number of blocks for the region on success.
181 * @param pcbBlock Where to store the size of one block in bytes on success.
182 * @param penmDataForm WHere to store the data form for the region on success.
183 */
184 DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumQueryRegionProperties,(VSCSILUN hVScsiLun, void *pvScsiLunUser,
185 uint32_t uRegion, uint64_t *pu64LbaStart,
186 uint64_t *pcBlocks, uint64_t *pcbBlock,
187 PVDREGIONDATAFORM penmDataForm));
188
189 /**
190 * Queries the properties for the region covering the given LBA.
191 *
192 * @returns VBox status code.
193 * @retval VERR_NOT_FOUND if the region index is not known.
194 * @param hVScsiLun Virtual SCSI LUN handle.
195 * @param pvScsiLunUser Opaque user data which may be used to identify the
196 * medium.
197 * @param u64LbaStart Where to store the starting LBA for the region on success.
198 * @param puRegion Where to store the region number on success.
199 * @param pcBlocks Where to store the number of blocks left in this region starting from the given LBA.
200 * @param pcbBlock Where to store the size of one block in bytes on success.
201 * @param penmDataForm WHere to store the data form for the region on success.
202 */
203 DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumQueryRegionPropertiesForLba,(VSCSILUN hVScsiLun, void *pvScsiLunUser,
204 uint64_t u64LbaStart, uint32_t *puRegion,
205 uint64_t *pcBlocks, uint64_t *pcbBlock,
206 PVDREGIONDATAFORM penmDataForm));
207
208 /**
209 * Set the lock state of the underlying medium.
210 *
211 * @returns VBox status status code.
212 * @param hVScsiLun Virtual SCSI LUN handle.
213 * @param pvScsiLunUser Opaque user data which may be used to identify the
214 * medium.
215 * @param fLocked New lock state (locked/unlocked).
216 */
217 DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumSetLock,(VSCSILUN hVScsiLun, void *pvScsiLunUser, bool fLocked));
218
219 /**
220 * Eject the attached medium.
221 *
222 * @returns VBox status code.
223 * @param hVScsiLun Virtual SCSI LUN handle.
224 * @param pvScsiLunUser Opaque user data which may be used to identify the
225 * medium.
226 */
227 DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumEject, (VSCSILUN hVScsiLun, void *pvScsiLunUser));
228
229 /**
230 * Enqueue a read or write request from the medium.
231 *
232 * @returns VBox status status code.
233 * @param hVScsiLun Virtual SCSI LUN handle.
234 * @param pvScsiLunUser Opaque user data which may be used to identify the
235 * medium.
236 * @param hVScsiIoReq Virtual SCSI I/O request handle.
237 */
238 DECLR3CALLBACKMEMBER(int, pfnVScsiLunReqTransferEnqueue,(VSCSILUN hVScsiLun, void *pvScsiLunUser, VSCSIIOREQ hVScsiIoReq));
239
240 /**
241 * Returns flags of supported features.
242 *
243 * @returns VBox status status code.
244 * @param hVScsiLun Virtual SCSI LUN handle.
245 * @param pvScsiLunUser Opaque user data which may be used to identify the
246 * medium.
247 * @param pfFeatures Where to return the queried features.
248 */
249 DECLR3CALLBACKMEMBER(int, pfnVScsiLunGetFeatureFlags,(VSCSILUN hVScsiLun, void *pvScsiLunUser, uint64_t *pfFeatures));
250
251 /**
252 * Queries the vendor and product ID and revision to report for INQUIRY commands of the given LUN.
253 *
254 * @returns VBox status status code.
255 * @retval VERR_NOT_FOUND if the data is not available and some defaults should be sued instead.
256 * @param hVScsiLun Virtual SCSI LUN handle.
257 * @param pvScsiLunUser Opaque user data which may be used to identify the
258 * medium.
259 * @param ppszVendorId Where to store the pointer to the vendor ID string to report.
260 * @param ppszProductId Where to store the pointer to the product ID string to report.
261 * @param ppszProductLevel Where to store the pointer to the product level string to report.
262 */
263 DECLR3CALLBACKMEMBER(int, pfnVScsiLunQueryInqStrings, (VSCSILUN hVScsiLun, void *pvScsiLunUser, const char **ppszVendorId,
264 const char **ppszProductId, const char **ppszProductLevel));
265
266} VSCSILUNIOCALLBACKS;
267/** Pointer to a virtual SCSI LUN I/O callback table. */
268typedef VSCSILUNIOCALLBACKS *PVSCSILUNIOCALLBACKS;
269
270/**
271 * The virtual SCSI request completed callback.
272 */
273typedef DECLCALLBACK(void) FNVSCSIREQCOMPLETED(VSCSIDEVICE hVScsiDevice,
274 void *pvVScsiDeviceUser,
275 void *pvVScsiReqUser,
276 int rcScsiCode,
277 bool fRedoPossible,
278 int rcReq,
279 size_t cbXfer);
280/** Pointer to a virtual SCSI request completed callback. */
281typedef FNVSCSIREQCOMPLETED *PFNVSCSIREQCOMPLETED;
282
283/**
284 * Create a new empty SCSI device instance.
285 *
286 * @returns VBox status code.
287 * @param phVScsiDevice Where to store the SCSI device handle.
288 * @param pfnVScsiReqCompleted The method call after a request completed.
289 * @param pvVScsiDeviceUser Opaque user data given in the completion callback.
290 */
291VBOXDDU_DECL(int) VSCSIDeviceCreate(PVSCSIDEVICE phVScsiDevice,
292 PFNVSCSIREQCOMPLETED pfnVScsiReqCompleted,
293 void *pvVScsiDeviceUser);
294
295/**
296 * Destroy a SCSI device instance.
297 *
298 * @returns VBox status code.
299 * @param hVScsiDevice The SCSI device handle to destroy.
300 */
301VBOXDDU_DECL(int) VSCSIDeviceDestroy(VSCSIDEVICE hVScsiDevice);
302
303/**
304 * Attach a LUN to the SCSI device.
305 *
306 * @returns VBox status code.
307 * @param hVScsiDevice The SCSI device handle to add the LUN to.
308 * @param hVScsiLun The LUN handle to add.
309 * @param iLun The LUN number.
310 */
311VBOXDDU_DECL(int) VSCSIDeviceLunAttach(VSCSIDEVICE hVScsiDevice, VSCSILUN hVScsiLun, uint32_t iLun);
312
313/**
314 * Detach a LUN from the SCSI device.
315 *
316 * @returns VBox status code.
317 * @param hVScsiDevice The SCSI device handle to add the LUN to.
318 * @param iLun The LUN number to remove.
319 * @param phVScsiLun Where to store the detached LUN handle.
320 */
321VBOXDDU_DECL(int) VSCSIDeviceLunDetach(VSCSIDEVICE hVScsiDevice, uint32_t iLun,
322 PVSCSILUN phVScsiLun);
323
324/**
325 * Query the SCSI LUN type.
326 *
327 * @returns VBox status code.
328 * @param hVScsiDevice The SCSI device handle.
329 * @param iLun The LUN number to get.
330 * @param pEnmLunType Where to store the LUN type.
331 */
332VBOXDDU_DECL(int) VSCSIDeviceLunQueryType(VSCSIDEVICE hVScsiDevice, uint32_t iLun,
333 PVSCSILUNTYPE pEnmLunType);
334
335/**
336 * Enqueue a request to the SCSI device.
337 *
338 * @returns VBox status code.
339 * @param hVScsiDevice The SCSI device handle.
340 * @param hVScsiReq The SCSI request handle to enqueue.
341 */
342VBOXDDU_DECL(int) VSCSIDeviceReqEnqueue(VSCSIDEVICE hVScsiDevice, VSCSIREQ hVScsiReq);
343
344/**
345 * Allocate a new request handle.
346 *
347 * @returns VBox status code.
348 * @param hVScsiDevice The SCSI device handle.
349 * @param phVScsiReq Where to SCSI request handle.
350 * @param iLun The LUN the request is for.
351 * @param pbCDB The CDB for the request.
352 * @param cbCDB The size of the CDB in bytes.
353 * @param cbSGList Number of bytes the S/G list describes.
354 * @param cSGListEntries Number of S/G list entries.
355 * @param paSGList Pointer to the S/G list.
356 * @param pbSense Pointer to the sense buffer.
357 * @param cbSense Size of the sense buffer.
358 * @param pvVScsiReqUser Opqaue user data returned when the request completes.
359 */
360VBOXDDU_DECL(int) VSCSIDeviceReqCreate(VSCSIDEVICE hVScsiDevice, PVSCSIREQ phVScsiReq,
361 uint32_t iLun, uint8_t *pbCDB, size_t cbCDB,
362 size_t cbSGList, unsigned cSGListEntries,
363 PCRTSGSEG paSGList, uint8_t *pbSense,
364 size_t cbSense, void *pvVScsiReqUser);
365
366/**
367 * Create a new LUN.
368 *
369 * @returns VBox status code.
370 * @param phVScsiLun Where to store the SCSI LUN handle.
371 * @param enmLunType The Lun type.
372 * @param pVScsiLunIoCallbacks Pointer to the I/O callbacks to use for his LUN.
373 * @param pvVScsiLunUser Opaque user argument which
374 * is returned in the pvScsiLunUser parameter
375 * when the request completion callback is called.
376 */
377VBOXDDU_DECL(int) VSCSILunCreate(PVSCSILUN phVScsiLun, VSCSILUNTYPE enmLunType,
378 PVSCSILUNIOCALLBACKS pVScsiLunIoCallbacks,
379 void *pvVScsiLunUser);
380
381/**
382 * Destroy virtual SCSI LUN.
383 *
384 * @returns VBox status code.
385 * @param hVScsiLun The virtual SCSI LUN handle to destroy.
386 */
387VBOXDDU_DECL(int) VSCSILunDestroy(VSCSILUN hVScsiLun);
388
389/**
390 * Notify virtual SCSI LUN of medium being mounted.
391 *
392 * @returns VBox status code.
393 * @param hVScsiLun The virtual SCSI LUN handle to destroy.
394 */
395VBOXDDU_DECL(int) VSCSILunMountNotify(VSCSILUN hVScsiLun);
396
397/**
398 * Notify virtual SCSI LUN of medium being unmounted.
399 *
400 * @returns VBox status code.
401 * @param hVScsiLun The virtual SCSI LUN handle to destroy.
402 */
403VBOXDDU_DECL(int) VSCSILunUnmountNotify(VSCSILUN hVScsiLun);
404
405/**
406 * Notify a that a I/O request completed.
407 *
408 * @returns VBox status code.
409 * @param hVScsiIoReq The I/O request handle that completed.
410 * This is given when a I/O callback for
411 * the LUN is called by the virtual SCSI layer.
412 * @param rcIoReq The status code the I/O request completed with.
413 * @param fRedoPossible Flag whether it is possible to redo the request.
414 * If true setting any sense code will be omitted
415 * in case of an error to not alter the device state.
416 */
417VBOXDDU_DECL(int) VSCSIIoReqCompleted(VSCSIIOREQ hVScsiIoReq, int rcIoReq, bool fRedoPossible);
418
419/**
420 * Query the transfer direction of the I/O request.
421 *
422 * @returns Transfer direction.of the given I/O request
423 * @param hVScsiIoReq The SCSI I/O request handle.
424 */
425VBOXDDU_DECL(VSCSIIOREQTXDIR) VSCSIIoReqTxDirGet(VSCSIIOREQ hVScsiIoReq);
426
427/**
428 * Query I/O parameters.
429 *
430 * @returns VBox status code.
431 * @param hVScsiIoReq The SCSI I/O request handle.
432 * @param puOffset Where to store the start offset.
433 * @param pcbTransfer Where to store the amount of bytes to transfer.
434 * @param pcSeg Where to store the number of segments in the S/G list.
435 * @param pcbSeg Where to store the number of bytes the S/G list describes.
436 * @param ppaSeg Where to store the pointer to the S/G list.
437 */
438VBOXDDU_DECL(int) VSCSIIoReqParamsGet(VSCSIIOREQ hVScsiIoReq, uint64_t *puOffset,
439 size_t *pcbTransfer, unsigned *pcSeg,
440 size_t *pcbSeg, PCRTSGSEG *ppaSeg);
441
442/**
443 * Query unmap parameters.
444 *
445 * @returns VBox status code.
446 * @param hVScsiIoReq The SCSI I/O request handle.
447 * @param ppaRanges Where to store the pointer to the range array on success.
448 * @param pcRanges Where to store the number of ranges on success.
449 */
450VBOXDDU_DECL(int) VSCSIIoReqUnmapParamsGet(VSCSIIOREQ hVScsiIoReq, PCRTRANGE *ppaRanges,
451 unsigned *pcRanges);
452
453/** @} */
454RT_C_DECLS_END
455
456#endif /* !VBOX_INCLUDED_vscsi_h */
457
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette