1 | /* $Id: VSCSIInternal.h 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Virtual SCSI driver: Internal defines
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 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 |
|
---|
18 | #ifndef VBOX_INCLUDED_SRC_Storage_VSCSI_VSCSIInternal_h
|
---|
19 | #define VBOX_INCLUDED_SRC_Storage_VSCSI_VSCSIInternal_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/vscsi.h>
|
---|
25 | #include <VBox/scsi.h>
|
---|
26 | #include <VBox/scsiinline.h>
|
---|
27 | #include <iprt/err.h>
|
---|
28 | #include <iprt/memcache.h>
|
---|
29 | #include <iprt/sg.h>
|
---|
30 | #include <iprt/list.h>
|
---|
31 |
|
---|
32 | #include "VSCSIVpdPages.h"
|
---|
33 |
|
---|
34 | /** Pointer to an internal virtual SCSI device. */
|
---|
35 | typedef VSCSIDEVICEINT *PVSCSIDEVICEINT;
|
---|
36 | /** Pointer to an internal virtual SCSI device LUN. */
|
---|
37 | typedef VSCSILUNINT *PVSCSILUNINT;
|
---|
38 | /** Pointer to an internal virtual SCSI device LUN pointer. */
|
---|
39 | typedef PVSCSILUNINT *PPVSCSILUNINT;
|
---|
40 | /** Pointer to a virtual SCSI LUN descriptor. */
|
---|
41 | typedef struct VSCSILUNDESC *PVSCSILUNDESC;
|
---|
42 | /** Pointer to a virtual SCSI request. */
|
---|
43 | typedef VSCSIREQINT *PVSCSIREQINT;
|
---|
44 | /** Pointer to a virtual SCSI I/O request. */
|
---|
45 | typedef VSCSIIOREQINT *PVSCSIIOREQINT;
|
---|
46 | /** Pointer to virtual SCSI sense data state. */
|
---|
47 | typedef struct VSCSISENSE *PVSCSISENSE;
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Virtual SCSI sense data handling.
|
---|
51 | */
|
---|
52 | typedef struct VSCSISENSE
|
---|
53 | {
|
---|
54 | /** Buffer holding the sense data. */
|
---|
55 | uint8_t abSenseBuf[32];
|
---|
56 | } VSCSISENSE;
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Virtual SCSI device.
|
---|
60 | */
|
---|
61 | typedef struct VSCSIDEVICEINT
|
---|
62 | {
|
---|
63 | /** Request completion callback */
|
---|
64 | PFNVSCSIREQCOMPLETED pfnVScsiReqCompleted;
|
---|
65 | /** Opaque user data. */
|
---|
66 | void *pvVScsiDeviceUser;
|
---|
67 | /** Number of LUNs currently attached. */
|
---|
68 | uint32_t cLunsAttached;
|
---|
69 | /** How many LUNs are fitting in the array. */
|
---|
70 | uint32_t cLunsMax;
|
---|
71 | /** Request cache */
|
---|
72 | RTMEMCACHE hCacheReq;
|
---|
73 | /** Sense data handling. */
|
---|
74 | VSCSISENSE VScsiSense;
|
---|
75 | /** Pointer to the array of LUN handles.
|
---|
76 | * The index is the LUN id. */
|
---|
77 | PPVSCSILUNINT papVScsiLun;
|
---|
78 | } VSCSIDEVICEINT;
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Virtual SCSI device LUN.
|
---|
82 | */
|
---|
83 | typedef struct VSCSILUNINT
|
---|
84 | {
|
---|
85 | /** Pointer to the parent SCSI device. */
|
---|
86 | PVSCSIDEVICEINT pVScsiDevice;
|
---|
87 | /** Opaque user data */
|
---|
88 | void *pvVScsiLunUser;
|
---|
89 | /** I/O callback table */
|
---|
90 | PVSCSILUNIOCALLBACKS pVScsiLunIoCallbacks;
|
---|
91 | /** Pointer to the LUN type descriptor. */
|
---|
92 | PVSCSILUNDESC pVScsiLunDesc;
|
---|
93 | /** Flag indicating whether LUN is ready. */
|
---|
94 | bool fReady;
|
---|
95 | /** Flag indicating media presence in LUN. */
|
---|
96 | bool fMediaPresent;
|
---|
97 | /** Flags of supported features. */
|
---|
98 | uint64_t fFeatures;
|
---|
99 | /** I/O request processing data */
|
---|
100 | struct
|
---|
101 | {
|
---|
102 | /** Number of outstanding tasks on this LUN. */
|
---|
103 | volatile uint32_t cReqOutstanding;
|
---|
104 | } IoReq;
|
---|
105 | } VSCSILUNINT;
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Virtual SCSI request.
|
---|
109 | */
|
---|
110 | typedef struct VSCSIREQINT
|
---|
111 | {
|
---|
112 | /** The LUN the request is for. */
|
---|
113 | uint32_t iLun;
|
---|
114 | /** The CDB */
|
---|
115 | uint8_t *pbCDB;
|
---|
116 | /** Size of the CDB */
|
---|
117 | size_t cbCDB;
|
---|
118 | /** S/G buffer. */
|
---|
119 | RTSGBUF SgBuf;
|
---|
120 | /** Pointer to the sense buffer. */
|
---|
121 | uint8_t *pbSense;
|
---|
122 | /** Size of the sense buffer */
|
---|
123 | size_t cbSense;
|
---|
124 | /** Opaque user data associated with this request */
|
---|
125 | void *pvVScsiReqUser;
|
---|
126 | /** Transfer size determined from the CDB. */
|
---|
127 | size_t cbXfer;
|
---|
128 | /** Number of bytes of sense data written. */
|
---|
129 | size_t cbSenseWritten;
|
---|
130 | /** Transfer direction as indicated by the CDB. */
|
---|
131 | VSCSIXFERDIR enmXferDir;
|
---|
132 | /** Pointer to the opaque data which may be allocated by the LUN
|
---|
133 | * the request is for. */
|
---|
134 | void *pvLun;
|
---|
135 | } VSCSIREQINT;
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Virtual SCSI I/O request.
|
---|
139 | */
|
---|
140 | typedef struct VSCSIIOREQINT
|
---|
141 | {
|
---|
142 | /** The associated request. */
|
---|
143 | PVSCSIREQINT pVScsiReq;
|
---|
144 | /** Lun for this I/O request. */
|
---|
145 | PVSCSILUNINT pVScsiLun;
|
---|
146 | /** Transfer direction */
|
---|
147 | VSCSIIOREQTXDIR enmTxDir;
|
---|
148 | /** Direction dependent data. */
|
---|
149 | union
|
---|
150 | {
|
---|
151 | /** Read/Write request. */
|
---|
152 | struct
|
---|
153 | {
|
---|
154 | /** Start offset */
|
---|
155 | uint64_t uOffset;
|
---|
156 | /** Number of bytes to transfer */
|
---|
157 | size_t cbTransfer;
|
---|
158 | /** Number of bytes the S/G list holds */
|
---|
159 | size_t cbSeg;
|
---|
160 | /** Number of segments. */
|
---|
161 | unsigned cSeg;
|
---|
162 | /** Segment array. */
|
---|
163 | PCRTSGSEG paSeg;
|
---|
164 | } Io;
|
---|
165 | /** Unmap request. */
|
---|
166 | struct
|
---|
167 | {
|
---|
168 | /** Array of ranges to unmap. */
|
---|
169 | PRTRANGE paRanges;
|
---|
170 | /** Number of ranges. */
|
---|
171 | unsigned cRanges;
|
---|
172 | } Unmap;
|
---|
173 | } u;
|
---|
174 | } VSCSIIOREQINT;
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * VPD page pool.
|
---|
178 | */
|
---|
179 | typedef struct VSCSIVPDPOOL
|
---|
180 | {
|
---|
181 | /** List of registered pages (VSCSIVPDPAGE). */
|
---|
182 | RTLISTANCHOR ListPages;
|
---|
183 | } VSCSIVPDPOOL;
|
---|
184 | /** Pointer to the VSCSI VPD page pool. */
|
---|
185 | typedef VSCSIVPDPOOL *PVSCSIVPDPOOL;
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Supported operation code information entry.
|
---|
189 | */
|
---|
190 | typedef struct VSCSILUNSUPOPC
|
---|
191 | {
|
---|
192 | /** The operation code. */
|
---|
193 | uint8_t u8Opc;
|
---|
194 | /** Service action code if required as indicated by
|
---|
195 | * VSCSI_LUN_SUP_OPC_SVC_ACTION_REQUIRED */
|
---|
196 | uint16_t u16SvcAction;
|
---|
197 | /** Flags. */
|
---|
198 | uint32_t fFlags;
|
---|
199 | /** Readable description for the op code. */
|
---|
200 | const char *pszOpc;
|
---|
201 | /** The length of the CDB for this operation code. */
|
---|
202 | uint8_t cbCdb;
|
---|
203 | /** Pointer to the CDB usage data. */
|
---|
204 | uint8_t *pbCdbUsage;
|
---|
205 | /* The operation specific valuefor the timeout descriptor. */
|
---|
206 | uint8_t u8OpcTimeoutSpec;
|
---|
207 | /** The nominal processing timeout in seconds. */
|
---|
208 | uint16_t cNominalProcessingTimeout;
|
---|
209 | /** The recommend timeout in seconds. */
|
---|
210 | uint16_t cRecommendTimeout;
|
---|
211 | } VSCSILUNSUPOPC;
|
---|
212 | /** Pointer to a operation code information entry. */
|
---|
213 | typedef VSCSILUNSUPOPC *PVSCSILUNSUPOPC;
|
---|
214 | /** Pointer to a const operation code information entry. */
|
---|
215 | typedef const VSCSILUNSUPOPC *PCVSCSILUNSUPOPC;
|
---|
216 |
|
---|
217 | /** @name Flags for the supported operation code infromation entries.
|
---|
218 | * @{ */
|
---|
219 | /** Flag indicating wheter the service action member is valid and should be
|
---|
220 | * evaluated to find the desired opcode information. */
|
---|
221 | #define VSCSI_LUN_SUP_OPC_SVC_ACTION_REQUIRED RT_BIT_32(0)
|
---|
222 | /** Flag whether the values for the timeout descriptor are valid. */
|
---|
223 | #define VSCSI_LUN_SUP_OPC_TIMEOUT_DESC_VALID RT_BIT_32(1)
|
---|
224 | /** @} */
|
---|
225 |
|
---|
226 | /** @name Support macros to create supported operation code information entries.
|
---|
227 | * @{ */
|
---|
228 | #define VSCSI_LUN_SUP_OPC(a_u8Opc, a_pszOpc, a_cbCdb, a_pbCdbUsage) \
|
---|
229 | { a_u8Opc, 0, 0, a_pszOpc, a_cbCdb, a_pbCdbUsage, 0, 0, 0}
|
---|
230 | #define VSCSI_LUN_SUP_OPC_SVC(a_u8Opc, a_u16SvcAction, a_pszOpc, a_cbCdb, a_pbCdbUsage) \
|
---|
231 | { a_u8Opc, a_u16SvcAction, VSCSI_LUN_SUP_OPC_SVC_ACTION_REQUIRED, a_pszOpc, a_cbCdb, a_pbCdbUsage, 0, 0, 0}
|
---|
232 | /** @} */
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * Virtual SCSI LUN descriptor.
|
---|
236 | */
|
---|
237 | typedef struct VSCSILUNDESC
|
---|
238 | {
|
---|
239 | /** Device type this descriptor emulates. */
|
---|
240 | VSCSILUNTYPE enmLunType;
|
---|
241 | /** Descriptor name */
|
---|
242 | const char *pcszDescName;
|
---|
243 | /** LUN type size */
|
---|
244 | size_t cbLun;
|
---|
245 | /** Number of entries in the supported operation codes array. */
|
---|
246 | uint32_t cSupOpcInfo;
|
---|
247 | /** Pointer to the array of supported operation codes for the
|
---|
248 | * REPORT RUPPORTED OPERATION CODES command handled by the generic
|
---|
249 | * device driver - optional.
|
---|
250 | */
|
---|
251 | PCVSCSILUNSUPOPC paSupOpcInfo;
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * Initialise a Lun instance.
|
---|
255 | *
|
---|
256 | * @returns VBox status code.
|
---|
257 | * @param pVScsiLun The SCSI LUN instance.
|
---|
258 | */
|
---|
259 | DECLR3CALLBACKMEMBER(int, pfnVScsiLunInit, (PVSCSILUNINT pVScsiLun));
|
---|
260 |
|
---|
261 | /**
|
---|
262 | * Destroy a Lun instance.
|
---|
263 | *
|
---|
264 | * @returns VBox status code.
|
---|
265 | * @param pVScsiLun The SCSI LUN instance.
|
---|
266 | */
|
---|
267 | DECLR3CALLBACKMEMBER(int, pfnVScsiLunDestroy, (PVSCSILUNINT pVScsiLun));
|
---|
268 |
|
---|
269 | /**
|
---|
270 | * Processes a SCSI request.
|
---|
271 | *
|
---|
272 | * @returns VBox status code.
|
---|
273 | * @param pVScsiLun The SCSI LUN instance.
|
---|
274 | * @param pVScsiReq The SCSi request to process.
|
---|
275 | */
|
---|
276 | DECLR3CALLBACKMEMBER(int, pfnVScsiLunReqProcess, (PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq));
|
---|
277 |
|
---|
278 | /**
|
---|
279 | * Frees additional allocated resources for the given request if it was allocated before.
|
---|
280 | *
|
---|
281 | * @returns void.
|
---|
282 | * @param pVScsiLun The SCSI LUN instance.
|
---|
283 | * @param pVScsiReq The SCSI request.
|
---|
284 | * @param pvScsiReqLun The opaque data allocated previously.
|
---|
285 | */
|
---|
286 | DECLR3CALLBACKMEMBER(void, pfnVScsiLunReqFree, (PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq,
|
---|
287 | void *pvScsiReqLun));
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * Informs about a medium being inserted - optional.
|
---|
291 | *
|
---|
292 | * @returns VBox status code.
|
---|
293 | * @param pVScsiLun The SCSI LUN instance.
|
---|
294 | */
|
---|
295 | DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumInserted, (PVSCSILUNINT pVScsiLun));
|
---|
296 |
|
---|
297 | /**
|
---|
298 | * Informs about a medium being removed - optional.
|
---|
299 | *
|
---|
300 | * @returns VBox status code.
|
---|
301 | * @param pVScsiLun The SCSI LUN instance.
|
---|
302 | */
|
---|
303 | DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumRemoved, (PVSCSILUNINT pVScsiLun));
|
---|
304 |
|
---|
305 | } VSCSILUNDESC;
|
---|
306 |
|
---|
307 | /** Maximum number of LUNs a device can have. */
|
---|
308 | #define VSCSI_DEVICE_LUN_MAX 128
|
---|
309 |
|
---|
310 | /**
|
---|
311 | * Completes a SCSI request and calls the completion handler.
|
---|
312 | *
|
---|
313 | * @returns nothing.
|
---|
314 | * @param pVScsiDevice The virtual SCSI device.
|
---|
315 | * @param pVScsiReq The request which completed.
|
---|
316 | * @param rcScsiCode The status code
|
---|
317 | * One of the SCSI_STATUS_* #defines.
|
---|
318 | * @param fRedoPossible Flag whether redo is possible.
|
---|
319 | * @param rcReq Informational return code of the request.
|
---|
320 | */
|
---|
321 | void vscsiDeviceReqComplete(PVSCSIDEVICEINT pVScsiDevice, PVSCSIREQINT pVScsiReq,
|
---|
322 | int rcScsiCode, bool fRedoPossible, int rcReq);
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * Init the sense data state.
|
---|
326 | *
|
---|
327 | * @returns nothing.
|
---|
328 | * @param pVScsiSense The SCSI sense data state to init.
|
---|
329 | */
|
---|
330 | void vscsiSenseInit(PVSCSISENSE pVScsiSense);
|
---|
331 |
|
---|
332 | /**
|
---|
333 | * Sets a ok sense code.
|
---|
334 | *
|
---|
335 | * @returns SCSI status code.
|
---|
336 | * @param pVScsiSense The SCSI sense state to use.
|
---|
337 | * @param pVScsiReq The SCSI request.
|
---|
338 | */
|
---|
339 | int vscsiReqSenseOkSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq);
|
---|
340 |
|
---|
341 | /**
|
---|
342 | * Sets an error sense code.
|
---|
343 | *
|
---|
344 | * @returns SCSI status code.
|
---|
345 | * @param pVScsiSense The SCSI sense state to use.
|
---|
346 | * @param pVScsiReq The SCSI request.
|
---|
347 | * @param uSCSISenseKey The SCSI sense key to set.
|
---|
348 | * @param uSCSIASC The ASC value.
|
---|
349 | * @param uSCSIASC The ASCQ value.
|
---|
350 | */
|
---|
351 | int vscsiReqSenseErrorSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey,
|
---|
352 | uint8_t uSCSIASC, uint8_t uSCSIASCQ);
|
---|
353 |
|
---|
354 | /**
|
---|
355 | * Sets an error sense code with additional information.
|
---|
356 | *
|
---|
357 | * @returns SCSI status code.
|
---|
358 | * @param pVScsiSense The SCSI sense state to use.
|
---|
359 | * @param pVScsiReq The SCSI request.
|
---|
360 | * @param uSCSISenseKey The SCSI sense key to set.
|
---|
361 | * @param uSCSIASC The ASC value.
|
---|
362 | * @param uSCSIASC The ASCQ value.
|
---|
363 | * @param uInfo The 32-bit sense information.
|
---|
364 | */
|
---|
365 | int vscsiReqSenseErrorInfoSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey,
|
---|
366 | uint8_t uSCSIASC, uint8_t uSCSIASCQ, uint32_t uInfo);
|
---|
367 |
|
---|
368 | /**
|
---|
369 | * Process a request sense command.
|
---|
370 | *
|
---|
371 | * @returns SCSI status code.
|
---|
372 | * @param pVScsiSense The SCSI sense state to use.
|
---|
373 | * @param pVScsiReq The SCSI request.
|
---|
374 | */
|
---|
375 | int vscsiReqSenseCmd(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq);
|
---|
376 |
|
---|
377 | /**
|
---|
378 | * Inits the VPD page pool.
|
---|
379 | *
|
---|
380 | * @returns VBox status code.
|
---|
381 | * @param pVScsiVpdPool The VPD page pool to initialize.
|
---|
382 | */
|
---|
383 | int vscsiVpdPagePoolInit(PVSCSIVPDPOOL pVScsiVpdPool);
|
---|
384 |
|
---|
385 | /**
|
---|
386 | * Destroys the given VPD page pool freeing all pages in it.
|
---|
387 | *
|
---|
388 | * @returns nothing.
|
---|
389 | * @param pVScsiVpdPool The VPD page pool to destroy.
|
---|
390 | */
|
---|
391 | void vscsiVpdPagePoolDestroy(PVSCSIVPDPOOL pVScsiVpdPool);
|
---|
392 |
|
---|
393 | /**
|
---|
394 | * Allocates a new page in the VPD page pool with the given number.
|
---|
395 | *
|
---|
396 | * @returns VBox status code.
|
---|
397 | * @retval VERR_ALREADY_EXIST if the page number is in use.
|
---|
398 | * @param pVScsiVpdPool The VPD page pool the page will belong to.
|
---|
399 | * @param uPage The page number, must be unique.
|
---|
400 | * @param cbPage Size of the page in bytes.
|
---|
401 | * @param ppbPage Where to store the pointer to the raw page data on success.
|
---|
402 | */
|
---|
403 | int vscsiVpdPagePoolAllocNewPage(PVSCSIVPDPOOL pVScsiVpdPool, uint8_t uPage, size_t cbPage, uint8_t **ppbPage);
|
---|
404 |
|
---|
405 | /**
|
---|
406 | * Queries the given page from the pool and cpies it to the buffer given
|
---|
407 | * by the SCSI request.
|
---|
408 | *
|
---|
409 | * @returns VBox status code.
|
---|
410 | * @retval VERR_NOT_FOUND if the page is not in the pool.
|
---|
411 | * @param pVScsiVpdPool The VPD page pool to use.
|
---|
412 | * @param pVScsiReq The SCSI request.
|
---|
413 | * @param uPage Page to query.
|
---|
414 | */
|
---|
415 | int vscsiVpdPagePoolQueryPage(PVSCSIVPDPOOL pVScsiVpdPool, PVSCSIREQINT pVScsiReq, uint8_t uPage);
|
---|
416 |
|
---|
417 | /**
|
---|
418 | * Inits the I/O request related state for the LUN.
|
---|
419 | *
|
---|
420 | * @returns VBox status code.
|
---|
421 | * @param pVScsiLun The LUN instance.
|
---|
422 | */
|
---|
423 | int vscsiIoReqInit(PVSCSILUNINT pVScsiLun);
|
---|
424 |
|
---|
425 | /**
|
---|
426 | * Enqueues a new flush request
|
---|
427 | *
|
---|
428 | * @returns VBox status code.
|
---|
429 | * @param pVScsiLun The LUN instance which issued the request.
|
---|
430 | * @param pVScsiReq The virtual SCSI request associated with the flush.
|
---|
431 | */
|
---|
432 | int vscsiIoReqFlushEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq);
|
---|
433 |
|
---|
434 | /**
|
---|
435 | * Enqueue a new data transfer request.
|
---|
436 | *
|
---|
437 | * @returns VBox status code.
|
---|
438 | * @param pVScsiLun The LUN instance which issued the request.
|
---|
439 | * @param pVScsiReq The virtual SCSI request associated with the transfer.
|
---|
440 | * @param enmTxDir Transfer direction.
|
---|
441 | * @param uOffset Start offset of the transfer.
|
---|
442 | * @param cbTransfer Number of bytes to transfer.
|
---|
443 | */
|
---|
444 | int vscsiIoReqTransferEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq,
|
---|
445 | VSCSIIOREQTXDIR enmTxDir, uint64_t uOffset,
|
---|
446 | size_t cbTransfer);
|
---|
447 |
|
---|
448 | /**
|
---|
449 | * Enqueue a new data transfer request - extended variant.
|
---|
450 | *
|
---|
451 | * @returns VBox status code.
|
---|
452 | * @param pVScsiLun The LUN instance which issued the request.
|
---|
453 | * @param pVScsiReq The virtual SCSI request associated with the transfer.
|
---|
454 | * @param enmTxDir Transfer direction.
|
---|
455 | * @param uOffset Start offset of the transfer.
|
---|
456 | * @param paSegs Pointer to the array holding the memory buffer segments.
|
---|
457 | * @param cSegs Number of segments in the array.
|
---|
458 | * @param cbTransfer Number of bytes to transfer.
|
---|
459 | */
|
---|
460 | int vscsiIoReqTransferEnqueueEx(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq,
|
---|
461 | VSCSIIOREQTXDIR enmTxDir, uint64_t uOffset,
|
---|
462 | PCRTSGSEG paSegs, unsigned cSegs, size_t cbTransfer);
|
---|
463 |
|
---|
464 | /**
|
---|
465 | * Enqueue a new unmap request.
|
---|
466 | *
|
---|
467 | * @returns VBox status code.
|
---|
468 | * @param pVScsiLun The LUN instance which issued the request.
|
---|
469 | * @param pVScsiReq The virtual SCSI request associated with the transfer.
|
---|
470 | * @param paRanges The array of ranges to unmap.
|
---|
471 | * @param cRanges Number of ranges in the array.
|
---|
472 | */
|
---|
473 | int vscsiIoReqUnmapEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq,
|
---|
474 | PRTRANGE paRanges, unsigned cRanges);
|
---|
475 |
|
---|
476 | /**
|
---|
477 | * Returns the current number of outstanding tasks on the given LUN.
|
---|
478 | *
|
---|
479 | * @returns Number of outstanding tasks.
|
---|
480 | * @param pVScsiLun The LUN to check.
|
---|
481 | */
|
---|
482 | uint32_t vscsiIoReqOutstandingCountGet(PVSCSILUNINT pVScsiLun);
|
---|
483 |
|
---|
484 | /**
|
---|
485 | * Sets the transfer size for the given request.
|
---|
486 | *
|
---|
487 | * @returns nothing.
|
---|
488 | * @param pVScsiReq The SCSI request.
|
---|
489 | * @param cbXfer The transfer size for the request.
|
---|
490 | */
|
---|
491 | DECLINLINE(void) vscsiReqSetXferSize(PVSCSIREQINT pVScsiReq, size_t cbXfer)
|
---|
492 | {
|
---|
493 | pVScsiReq->cbXfer = cbXfer;
|
---|
494 | }
|
---|
495 |
|
---|
496 | /**
|
---|
497 | * Sets the transfer direction for the given request.
|
---|
498 | *
|
---|
499 | * @returns nothing.
|
---|
500 | * @param pVScsiReq The SCSI request.
|
---|
501 | * @param cbXfer The transfer size for the request.
|
---|
502 | */
|
---|
503 | DECLINLINE(void) vscsiReqSetXferDir(PVSCSIREQINT pVScsiReq, VSCSIXFERDIR enmXferDir)
|
---|
504 | {
|
---|
505 | pVScsiReq->enmXferDir = enmXferDir;
|
---|
506 | }
|
---|
507 |
|
---|
508 | /**
|
---|
509 | * Wrapper for the set I/O request allocation size I/O callback.
|
---|
510 | *
|
---|
511 | * @returns VBox status code.
|
---|
512 | * @param pVScsiLun The LUN.
|
---|
513 | * @param cbVScsiIoReqAlloc The additional size for the request to allocate.
|
---|
514 | */
|
---|
515 | DECLINLINE(int) vscsiLunReqAllocSizeSet(PVSCSILUNINT pVScsiLun, size_t cbVScsiIoReqAlloc)
|
---|
516 | {
|
---|
517 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunReqAllocSizeSet(pVScsiLun,
|
---|
518 | pVScsiLun->pvVScsiLunUser,
|
---|
519 | cbVScsiIoReqAlloc);
|
---|
520 | }
|
---|
521 |
|
---|
522 | /**
|
---|
523 | * Wrapper for the allocate I/O request I/O callback.
|
---|
524 | *
|
---|
525 | * @returns VBox status code.
|
---|
526 | * @param pVScsiLun The LUN.
|
---|
527 | * @param u64Tag A unique tag to assign to the request.
|
---|
528 | * @param ppVScsiIoReq Where to store the pointer to the request on success.
|
---|
529 | */
|
---|
530 | DECLINLINE(int) vscsiLunReqAlloc(PVSCSILUNINT pVScsiLun, uint64_t u64Tag, PVSCSIIOREQINT *ppVScsiIoReq)
|
---|
531 | {
|
---|
532 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunReqAlloc(pVScsiLun,
|
---|
533 | pVScsiLun->pvVScsiLunUser,
|
---|
534 | u64Tag, ppVScsiIoReq);
|
---|
535 | }
|
---|
536 |
|
---|
537 | /**
|
---|
538 | * Wrapper for the free I/O request I/O callback.
|
---|
539 | *
|
---|
540 | * @returns VBox status code.
|
---|
541 | * @param pVScsiLun The LUN.
|
---|
542 | * @param pVScsiIoReq The request to free.
|
---|
543 | */
|
---|
544 | DECLINLINE(int) vscsiLunReqFree(PVSCSILUNINT pVScsiLun, PVSCSIIOREQINT pVScsiIoReq)
|
---|
545 | {
|
---|
546 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunReqFree(pVScsiLun,
|
---|
547 | pVScsiLun->pvVScsiLunUser,
|
---|
548 | pVScsiIoReq);
|
---|
549 | }
|
---|
550 |
|
---|
551 | /**
|
---|
552 | * Wrapper for the get medium region count I/O callback.
|
---|
553 | *
|
---|
554 | * @returns Number of regions for the underlying medium.
|
---|
555 | * @param pVScsiLun The LUN.
|
---|
556 | */
|
---|
557 | DECLINLINE(uint32_t) vscsiLunMediumGetRegionCount(PVSCSILUNINT pVScsiLun)
|
---|
558 | {
|
---|
559 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumGetRegionCount(pVScsiLun,
|
---|
560 | pVScsiLun->pvVScsiLunUser);
|
---|
561 | }
|
---|
562 |
|
---|
563 | /**
|
---|
564 | * Wrapper for the query medium region properties I/O callback.
|
---|
565 | *
|
---|
566 | * @returns VBox status code.
|
---|
567 | * @param pVScsiLun The LUN.
|
---|
568 | * @param uRegion The region index to query the properties of.
|
---|
569 | * @param pu64LbaStart Where to store the starting LBA for the region on success.
|
---|
570 | * @param pcBlocks Where to store the number of blocks for the region on success.
|
---|
571 | * @param pcbBlock Where to store the size of one block in bytes on success.
|
---|
572 | * @param penmDataForm WHere to store the data form for the region on success.
|
---|
573 | */
|
---|
574 | DECLINLINE(int) vscsiLunMediumQueryRegionProperties(PVSCSILUNINT pVScsiLun, uint32_t uRegion,
|
---|
575 | uint64_t *pu64LbaStart, uint64_t *pcBlocks,
|
---|
576 | uint64_t *pcbBlock, PVDREGIONDATAFORM penmDataForm)
|
---|
577 | {
|
---|
578 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumQueryRegionProperties(pVScsiLun,
|
---|
579 | pVScsiLun->pvVScsiLunUser,
|
---|
580 | uRegion, pu64LbaStart,
|
---|
581 | pcBlocks, pcbBlock,
|
---|
582 | penmDataForm);
|
---|
583 | }
|
---|
584 |
|
---|
585 | /**
|
---|
586 | * Wrapper for the query medium region properties for LBA I/O callback.
|
---|
587 | *
|
---|
588 | * @returns VBox status code.
|
---|
589 | * @param pVScsiLun The LUN.
|
---|
590 | * @param uRegion The region index to query the properties of.
|
---|
591 | * @param pu64LbaStart Where to store the starting LBA for the region on success.
|
---|
592 | * @param pcBlocks Where to store the number of blocks for the region on success.
|
---|
593 | * @param pcbBlock Where to store the size of one block in bytes on success.
|
---|
594 | * @param penmDataForm WHere to store the data form for the region on success.
|
---|
595 | */
|
---|
596 | DECLINLINE(int) vscsiLunMediumQueryRegionPropertiesForLba(PVSCSILUNINT pVScsiLun, uint64_t u64LbaStart, uint32_t *puRegion,
|
---|
597 | uint64_t *pcBlocks, uint64_t *pcbBlock,
|
---|
598 | PVDREGIONDATAFORM penmDataForm)
|
---|
599 | {
|
---|
600 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumQueryRegionPropertiesForLba(pVScsiLun,
|
---|
601 | pVScsiLun->pvVScsiLunUser,
|
---|
602 | u64LbaStart, puRegion,
|
---|
603 | pcBlocks, pcbBlock,
|
---|
604 | penmDataForm);
|
---|
605 | }
|
---|
606 |
|
---|
607 | /**
|
---|
608 | * Wrapper for the get medium lock/unlock I/O callback.
|
---|
609 | *
|
---|
610 | * @returns VBox status code.
|
---|
611 | * @param pVScsiLun The LUN.
|
---|
612 | * @param bool The new medium lock state.
|
---|
613 | */
|
---|
614 | DECLINLINE(int) vscsiLunMediumSetLock(PVSCSILUNINT pVScsiLun, bool fLocked)
|
---|
615 | {
|
---|
616 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumSetLock(pVScsiLun,
|
---|
617 | pVScsiLun->pvVScsiLunUser,
|
---|
618 | fLocked);
|
---|
619 | }
|
---|
620 |
|
---|
621 | /**
|
---|
622 | * Wrapper for the eject medium I/O callback.
|
---|
623 | *
|
---|
624 | * @returns VBox status code.
|
---|
625 | * @param pVScsiLun The LUN.
|
---|
626 | */
|
---|
627 | DECLINLINE(int) vscsiLunMediumEject(PVSCSILUNINT pVScsiLun)
|
---|
628 | {
|
---|
629 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumEject(pVScsiLun,
|
---|
630 | pVScsiLun->pvVScsiLunUser);
|
---|
631 | }
|
---|
632 |
|
---|
633 | /**
|
---|
634 | * Wrapper for the I/O request enqueue I/O callback.
|
---|
635 | *
|
---|
636 | * @returns VBox status code.
|
---|
637 | * @param pVScsiLun The LUN.
|
---|
638 | * @param pVScsiIoReq The I/O request to enqueue.
|
---|
639 | */
|
---|
640 | DECLINLINE(int) vscsiLunReqTransferEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIIOREQINT pVScsiIoReq)
|
---|
641 | {
|
---|
642 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunReqTransferEnqueue(pVScsiLun,
|
---|
643 | pVScsiLun->pvVScsiLunUser,
|
---|
644 | pVScsiIoReq);
|
---|
645 | }
|
---|
646 |
|
---|
647 | /**
|
---|
648 | * Wrapper for the get feature flags I/O callback.
|
---|
649 | *
|
---|
650 | * @returns VBox status code.
|
---|
651 | * @param pVScsiLun The LUN.
|
---|
652 | * @param pfFeatures Where to sthre supported flags on success.
|
---|
653 | */
|
---|
654 | DECLINLINE(int) vscsiLunGetFeatureFlags(PVSCSILUNINT pVScsiLun, uint64_t *pfFeatures)
|
---|
655 | {
|
---|
656 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunGetFeatureFlags(pVScsiLun,
|
---|
657 | pVScsiLun->pvVScsiLunUser,
|
---|
658 | pfFeatures);
|
---|
659 | }
|
---|
660 |
|
---|
661 | /**
|
---|
662 | * Wrapper for the query INQUIRY strings I/O callback.
|
---|
663 | *
|
---|
664 | * @returns VBox status code.
|
---|
665 | * @param pVScsiLun The LUN.
|
---|
666 | * @param ppszVendorId Where to store the pointer to the vendor ID string to report.
|
---|
667 | * @param ppszProductId Where to store the pointer to the product ID string to report.
|
---|
668 | * @param ppszProductLevel Where to store the pointer to the revision string to report.
|
---|
669 | */
|
---|
670 | DECLINLINE(int) vscsiLunQueryInqStrings(PVSCSILUNINT pVScsiLun, const char **ppszVendorId,
|
---|
671 | const char **ppszProductId, const char **ppszProductLevel)
|
---|
672 | {
|
---|
673 | if (pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunQueryInqStrings)
|
---|
674 | {
|
---|
675 | return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunQueryInqStrings(pVScsiLun,
|
---|
676 | pVScsiLun->pvVScsiLunUser,
|
---|
677 | ppszVendorId, ppszProductId,
|
---|
678 | ppszProductLevel);
|
---|
679 | }
|
---|
680 |
|
---|
681 | return VERR_NOT_FOUND;
|
---|
682 | }
|
---|
683 |
|
---|
684 | /**
|
---|
685 | * Wrapper around vscsiReqSenseOkSet()
|
---|
686 | */
|
---|
687 | DECLINLINE(int) vscsiLunReqSenseOkSet(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq)
|
---|
688 | {
|
---|
689 | return vscsiReqSenseOkSet(&pVScsiLun->pVScsiDevice->VScsiSense, pVScsiReq);
|
---|
690 | }
|
---|
691 |
|
---|
692 | /**
|
---|
693 | * Wrapper around vscsiReqSenseErrorSet()
|
---|
694 | */
|
---|
695 | DECLINLINE(int) vscsiLunReqSenseErrorSet(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey, uint8_t uSCSIASC, uint8_t uSCSIASCQ)
|
---|
696 | {
|
---|
697 | return vscsiReqSenseErrorSet(&pVScsiLun->pVScsiDevice->VScsiSense, pVScsiReq, uSCSISenseKey, uSCSIASC, uSCSIASCQ);
|
---|
698 | }
|
---|
699 |
|
---|
700 | /**
|
---|
701 | * Wrapper around vscsiReqSenseErrorInfoSet()
|
---|
702 | */
|
---|
703 | DECLINLINE(int) vscsiLunReqSenseErrorInfoSet(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey, uint8_t uSCSIASC, uint8_t uSCSIASCQ, uint32_t uInfo)
|
---|
704 | {
|
---|
705 | return vscsiReqSenseErrorInfoSet(&pVScsiLun->pVScsiDevice->VScsiSense, pVScsiReq, uSCSISenseKey, uSCSIASC, uSCSIASCQ, uInfo);
|
---|
706 | }
|
---|
707 |
|
---|
708 | #endif /* !VBOX_INCLUDED_SRC_Storage_VSCSI_VSCSIInternal_h */
|
---|
709 |
|
---|