VirtualBox

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

Last change on this file since 62634 was 62476, checked in by vboxsync, 8 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.2 KB
Line 
1/* $Id: vscsi.h 62476 2016-07-22 18:23:50Z vboxsync $ */
2/** @file
3 * VBox storage drivers - Virtual SCSI driver
4 */
5
6/*
7 * Copyright (C) 2006-2016 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
34RT_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/** @defgroup grp_drv_vscsi Virtual VSCSI Driver
41 * @ingroup grp_devdrv
42 * @{
43 */
44/** @todo figure better grouping. */
45
46/** A virtual SCSI device handle */
47typedef struct VSCSIDEVICEINT *VSCSIDEVICE;
48/** A pointer to a virtual SCSI device handle. */
49typedef VSCSIDEVICE *PVSCSIDEVICE;
50/** A virtual SCSI LUN handle. */
51typedef struct VSCSILUNINT *VSCSILUN;
52/** A pointer to a virtual SCSI LUN handle. */
53typedef VSCSILUN *PVSCSILUN;
54/** A virtual SCSI request handle. */
55typedef struct VSCSIREQINT *VSCSIREQ;
56/** A pointer to a virtual SCSI request handle. */
57typedef VSCSIREQ *PVSCSIREQ;
58/** A SCSI I/O request handle. */
59typedef struct VSCSIIOREQINT *VSCSIIOREQ;
60/** A pointer to a SCSI I/O request handle. */
61typedef VSCSIIOREQ *PVSCSIIOREQ;
62
63/**
64 * Virtual SCSI I/O request transfer direction.
65 */
66typedef enum VSCSIIOREQTXDIR
67{
68 /** Invalid direction */
69 VSCSIIOREQTXDIR_INVALID = 0,
70 /** Read */
71 VSCSIIOREQTXDIR_READ,
72 /** Write */
73 VSCSIIOREQTXDIR_WRITE,
74 /** Flush */
75 VSCSIIOREQTXDIR_FLUSH,
76 /** Unmap */
77 VSCSIIOREQTXDIR_UNMAP,
78 /** 32bit hack */
79 VSCSIIOREQTXDIR_32BIT_HACK = 0x7fffffff
80} VSCSIIOREQTXDIR;
81/** Pointer to a SCSI LUN type */
82typedef VSCSIIOREQTXDIR *PVSCSIIOREQTXDIR;
83
84/**
85 * LUN types we support
86 */
87typedef enum VSCSILUNTYPE
88{
89 /** Invalid type */
90 VSCSILUNTYPE_INVALID = 0,
91 /** Hard disk (SBC) */
92 VSCSILUNTYPE_SBC,
93 /** CD/DVD drive (MMC) */
94 VSCSILUNTYPE_MMC,
95 /** Tape drive (SSC) */
96 VSCSILUNTYPE_SSC,
97 /** Last value to indicate an invalid device */
98 VSCSILUNTYPE_LAST,
99 /** 32bit hack */
100 VSCSILUNTYPE_32BIT_HACK = 0x7fffffff
101} VSCSILUNTYPE;
102/** Pointer to a SCSI LUN type */
103typedef VSCSILUNTYPE *PVSCSILUNTYPE;
104
105/** The LUN can handle the UNMAP command. */
106#define VSCSI_LUN_FEATURE_UNMAP RT_BIT(0)
107/** The LUN has a non rotational medium. */
108#define VSCSI_LUN_FEATURE_NON_ROTATIONAL RT_BIT(1)
109/** The medium of the LUN is readonly. */
110#define VSCSI_LUN_FEATURE_READONLY RT_BIT(2)
111
112/**
113 * Virtual SCSI LUN I/O Callback table.
114 */
115typedef struct VSCSILUNIOCALLBACKS
116{
117 /**
118 * Retrieve the size of the underlying medium.
119 *
120 * @returns VBox status status code.
121 * @param hVScsiLun Virtual SCSI LUN handle.
122 * @param pvScsiLunUser Opaque user data which may be used to identify the
123 * medium.
124 * @param pcbSize Where to store the size of the medium.
125 */
126 DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumGetSize,(VSCSILUN hVScsiLun, void *pvScsiLunUser, uint64_t *pcbSize));
127
128 /**
129 * Retrieve the sector size of the underlying medium.
130 *
131 * @returns VBox status status code.
132 * @param hVScsiLun Virtual SCSI LUN handle.
133 * @param pvScsiLunUser Opaque user data which may be used to identify the
134 * medium.
135 * @param pcbSectorSize Where to store the sector size of the medium.
136 */
137 DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumGetSectorSize,(VSCSILUN hVScsiLun, void *pvScsiLunUser, 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 be used to identify the
145 * medium.
146 * @param fLocked New lock state (locked/unlocked).
147 */
148 DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumSetLock,(VSCSILUN hVScsiLun, void *pvScsiLunUser, bool fLocked));
149 /**
150 * Enqueue a read or write request from the medium.
151 *
152 * @returns VBox status status code.
153 * @param hVScsiLun Virtual SCSI LUN handle.
154 * @param pvScsiLunUser Opaque user data which may be used to identify the
155 * medium.
156 * @param hVScsiIoReq Virtual SCSI I/O request handle.
157 */
158 DECLR3CALLBACKMEMBER(int, pfnVScsiLunReqTransferEnqueue,(VSCSILUN hVScsiLun, void *pvScsiLunUser, VSCSIIOREQ hVScsiIoReq));
159
160 /**
161 * Returns flags of supported features.
162 *
163 * @returns VBox status status code.
164 * @param hVScsiLun Virtual SCSI LUN handle.
165 * @param pvScsiLunUser Opaque user data which may be used to identify the
166 * medium.
167 * @param pfFeatures Where to return the queried features.
168 */
169 DECLR3CALLBACKMEMBER(int, pfnVScsiLunGetFeatureFlags,(VSCSILUN hVScsiLun, void *pvScsiLunUser, uint64_t *pfFeatures));
170
171} VSCSILUNIOCALLBACKS;
172/** Pointer to a virtual SCSI LUN I/O callback table. */
173typedef VSCSILUNIOCALLBACKS *PVSCSILUNIOCALLBACKS;
174
175/**
176 * The virtual SCSI request completed callback.
177 */
178typedef DECLCALLBACK(void) FNVSCSIREQCOMPLETED(VSCSIDEVICE hVScsiDevice,
179 void *pvVScsiDeviceUser,
180 void *pvVScsiReqUser,
181 int rcScsiCode,
182 bool fRedoPossible,
183 int rcReq);
184/** Pointer to a virtual SCSI request completed callback. */
185typedef FNVSCSIREQCOMPLETED *PFNVSCSIREQCOMPLETED;
186
187/**
188 * Create a new empty SCSI device instance.
189 *
190 * @returns VBox status code.
191 * @param phVScsiDevice Where to store the SCSI device handle.
192 * @param pfnVScsiReqCompleted The method call after a request completed.
193 * @param pvVScsiDeviceUser Opaque user data given in the completion callback.
194 */
195VBOXDDU_DECL(int) VSCSIDeviceCreate(PVSCSIDEVICE phVScsiDevice,
196 PFNVSCSIREQCOMPLETED pfnVScsiReqCompleted,
197 void *pvVScsiDeviceUser);
198
199/**
200 * Destroy a SCSI device instance.
201 *
202 * @returns VBox status code.
203 * @param hVScsiDevice The SCSI device handle to destroy.
204 */
205VBOXDDU_DECL(int) VSCSIDeviceDestroy(VSCSIDEVICE hVScsiDevice);
206
207/**
208 * Attach a LUN to the SCSI device.
209 *
210 * @returns VBox status code.
211 * @param hVScsiDevice The SCSI device handle to add the LUN to.
212 * @param hVScsiLun The LUN handle to add.
213 * @param iLun The LUN number.
214 */
215VBOXDDU_DECL(int) VSCSIDeviceLunAttach(VSCSIDEVICE hVScsiDevice, VSCSILUN hVScsiLun, uint32_t iLun);
216
217/**
218 * Detach a LUN from the SCSI device.
219 *
220 * @returns VBox status code.
221 * @param hVScsiDevice The SCSI device handle to add the LUN to.
222 * @param iLun The LUN number to remove.
223 * @param phVScsiLun Where to store the detached LUN handle.
224 */
225VBOXDDU_DECL(int) VSCSIDeviceLunDetach(VSCSIDEVICE hVScsiDevice, uint32_t iLun,
226 PVSCSILUN phVScsiLun);
227
228/**
229 * Query the SCSI LUN type.
230 *
231 * @returns VBox status code.
232 * @param hVScsiDevice The SCSI device handle.
233 * @param iLun The LUN number to get.
234 * @param pEnmLunType Where to store the LUN type.
235 */
236VBOXDDU_DECL(int) VSCSIDeviceLunQueryType(VSCSIDEVICE hVScsiDevice, uint32_t iLun,
237 PVSCSILUNTYPE pEnmLunType);
238
239/**
240 * Enqueue a request to the SCSI device.
241 *
242 * @returns VBox status code.
243 * @param hVScsiDevice The SCSI device handle.
244 * @param hVScsiReq The SCSI request handle to enqueue.
245 */
246VBOXDDU_DECL(int) VSCSIDeviceReqEnqueue(VSCSIDEVICE hVScsiDevice, VSCSIREQ hVScsiReq);
247
248/**
249 * Allocate a new request handle.
250 *
251 * @returns VBox status code.
252 * @param hVScsiDevice The SCSI device handle.
253 * @param phVScsiReq Where to SCSI request handle.
254 * @param iLun The LUN the request is for.
255 * @param pbCDB The CDB for the request.
256 * @param cbCDB The size of the CDB in bytes.
257 * @param cbSGList Number of bytes the S/G list describes.
258 * @param cSGListEntries Number of S/G list entries.
259 * @param paSGList Pointer to the S/G list.
260 * @param pbSense Pointer to the sense buffer.
261 * @param cbSense Size of the sense buffer.
262 * @param pvVScsiReqUser Opqaue user data returned when the request completes.
263 */
264VBOXDDU_DECL(int) VSCSIDeviceReqCreate(VSCSIDEVICE hVScsiDevice, PVSCSIREQ phVScsiReq,
265 uint32_t iLun, uint8_t *pbCDB, size_t cbCDB,
266 size_t cbSGList, unsigned cSGListEntries,
267 PCRTSGSEG paSGList, uint8_t *pbSense,
268 size_t cbSense, void *pvVScsiReqUser);
269
270/**
271 * Create a new LUN.
272 *
273 * @returns VBox status code.
274 * @param phVScsiLun Where to store the SCSI LUN handle.
275 * @param enmLunType The Lun type.
276 * @param pVScsiLunIoCallbacks Pointer to the I/O callbacks to use for his LUN.
277 * @param pvVScsiLunUser Opaque user argument which
278 * is returned in the pvScsiLunUser parameter
279 * when the request completion callback is called.
280 */
281VBOXDDU_DECL(int) VSCSILunCreate(PVSCSILUN phVScsiLun, VSCSILUNTYPE enmLunType,
282 PVSCSILUNIOCALLBACKS pVScsiLunIoCallbacks,
283 void *pvVScsiLunUser);
284
285/**
286 * Destroy virtual SCSI LUN.
287 *
288 * @returns VBox status code.
289 * @param hVScsiLun The virtual SCSI LUN handle to destroy.
290 */
291VBOXDDU_DECL(int) VSCSILunDestroy(VSCSILUN hVScsiLun);
292
293/**
294 * Notify virtual SCSI LUN of medium being mounted.
295 *
296 * @returns VBox status code.
297 * @param hVScsiLun The virtual SCSI LUN handle to destroy.
298 */
299VBOXDDU_DECL(int) VSCSILunMountNotify(VSCSILUN hVScsiLun);
300
301/**
302 * Notify virtual SCSI LUN of medium being unmounted.
303 *
304 * @returns VBox status code.
305 * @param hVScsiLun The virtual SCSI LUN handle to destroy.
306 */
307VBOXDDU_DECL(int) VSCSILunUnmountNotify(VSCSILUN hVScsiLun);
308
309/**
310 * Notify a that a I/O request completed.
311 *
312 * @returns VBox status code.
313 * @param hVScsiIoReq The I/O request handle that completed.
314 * This is given when a I/O callback for
315 * the LUN is called by the virtual SCSI layer.
316 * @param rcIoReq The status code the I/O request completed with.
317 * @param fRedoPossible Flag whether it is possible to redo the request.
318 * If true setting any sense code will be omitted
319 * in case of an error to not alter the device state.
320 */
321VBOXDDU_DECL(int) VSCSIIoReqCompleted(VSCSIIOREQ hVScsiIoReq, int rcIoReq, bool fRedoPossible);
322
323/**
324 * Query the transfer direction of the I/O request.
325 *
326 * @returns Transfer direction.of the given I/O request
327 * @param hVScsiIoReq The SCSI I/O request handle.
328 */
329VBOXDDU_DECL(VSCSIIOREQTXDIR) VSCSIIoReqTxDirGet(VSCSIIOREQ hVScsiIoReq);
330
331/**
332 * Query I/O parameters.
333 *
334 * @returns VBox status code.
335 * @param hVScsiIoReq The SCSI I/O request handle.
336 * @param puOffset Where to store the start offset.
337 * @param pcbTransfer Where to store the amount of bytes to transfer.
338 * @param pcSeg Where to store the number of segments in the S/G list.
339 * @param pcbSeg Where to store the number of bytes the S/G list describes.
340 * @param ppaSeg Where to store the pointer to the S/G list.
341 */
342VBOXDDU_DECL(int) VSCSIIoReqParamsGet(VSCSIIOREQ hVScsiIoReq, uint64_t *puOffset,
343 size_t *pcbTransfer, unsigned *pcSeg,
344 size_t *pcbSeg, PCRTSGSEG *ppaSeg);
345
346/**
347 * Query unmap parameters.
348 *
349 * @returns VBox status code.
350 * @param hVScsiIoReq The SCSI I/O request handle.
351 * @param ppaRanges Where to store the pointer to the range array on success.
352 * @param pcRanges Where to store the number of ranges on success.
353 */
354VBOXDDU_DECL(int) VSCSIIoReqUnmapParamsGet(VSCSIIOREQ hVScsiIoReq, PCRTRANGE *ppaRanges,
355 unsigned *pcRanges);
356
357/** @} */
358RT_C_DECLS_END
359
360#endif /* ___VBox_vscsi_h */
361
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