VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/VSCSI/VSCSIInternal.h@ 28065

Last change on this file since 28065 was 28065, checked in by vboxsync, 15 years ago

Storage: Convert from PDMDATASEG to RTSGSEG to avoid casting between those two in VBoxHDD and more async I/O updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1/* $Id: VSCSIInternal.h 28065 2010-04-07 20:54:34Z vboxsync $ */
2/** @file
3 * Virtual SCSI driver: Internal defines
4 */
5
6/*
7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21#ifndef ___VSCSIInternal_h
22#define ___VSCSIInternal_h
23
24#include <VBox/vscsi.h>
25#include <VBox/scsi.h>
26#include <iprt/memcache.h>
27
28#include "VSCSIInline.h"
29
30/** Pointer to an internal virtual SCSI device. */
31typedef VSCSIDEVICEINT *PVSCSIDEVICEINT;
32/** Pointer to an internal virtual SCSI device LUN. */
33typedef VSCSILUNINT *PVSCSILUNINT;
34/** Pointer to an internal virtual SCSI device LUN pointer. */
35typedef PVSCSILUNINT *PPVSCSILUNINT;
36/** Pointer to a virtual SCSI LUN descriptor. */
37typedef struct VSCSILUNDESC *PVSCSILUNDESC;
38/** Pointer to a virtual SCSI request. */
39typedef VSCSIREQINT *PVSCSIREQINT;
40/** Pointer to a virtual SCSI I/O request. */
41typedef VSCSIIOREQINT *PVSCSIIOREQINT;
42
43/**
44 * Virtual SCSI device.
45 */
46typedef struct VSCSIDEVICEINT
47{
48 /** Request completion callback */
49 PFNVSCSIREQCOMPLETED pfnVScsiReqCompleted;
50 /** Opaque user data. */
51 void *pvVScsiDeviceUser;
52 /** Number of LUNs currently attached. */
53 uint32_t cLunsAttached;
54 /** How many LUNs are fitting in the array. */
55 uint32_t cLunsMax;
56 /** Request cache */
57 RTMEMCACHE hCacheReq;
58 /** Pointer to the array of LUN handles.
59 * The index is the LUN id. */
60 PPVSCSILUNINT papVScsiLun;
61} VSCSIDEVICEINT;
62
63/**
64 * Virtual SCSI device LUN.
65 */
66typedef struct VSCSILUNINT
67{
68 /** Pointer to the parent SCSI device. */
69 PVSCSIDEVICEINT pVScsiDevice;
70 /** Opaque user data */
71 void *pvVScsiLunUser;
72 /** I/O callback table */
73 PVSCSILUNIOCALLBACKS pVScsiLunIoCallbacks;
74 /** Pointer to the LUN type descriptor. */
75 PVSCSILUNDESC pVScsiLunDesc;
76 /** I/O request processing data */
77 struct
78 {
79 /** Number of outstanding tasks on this LUN. */
80 volatile uint32_t cReqOutstanding;
81 } IoReq;
82} VSCSILUNINT;
83
84/**
85 * VSCSI Scatter/gather list handling
86 */
87typedef struct VSCSIIOMEMCTX
88{
89 /** Pointer to the scatter/gather list. */
90 PCRTSGSEG paDataSeg;
91 /** Number of segments. */
92 size_t cSegments;
93 /** Current segment we are in. */
94 unsigned iSegIdx;
95 /** Pointer to the current buffer. */
96 uint8_t *pbBuf;
97 /** Number of bytes left in the current buffer. */
98 size_t cbBufLeft;
99} VSCSIIOMEMCTX;
100/** Pointer to a I/O memory context. */
101typedef VSCSIIOMEMCTX *PVSCSIIOMEMCTX;
102
103/**
104 * Virtual SCSI request.
105 */
106typedef struct VSCSIREQINT
107{
108 /** The LUN the request is for. */
109 uint32_t iLun;
110 /** The CDB */
111 uint8_t *pbCDB;
112 /** Size of the CDB */
113 size_t cbCDB;
114 /** I/O memory context */
115 VSCSIIOMEMCTX IoMemCtx;
116 /** Pointer to the sense buffer. */
117 uint8_t *pbSense;
118 /** Size of the sense buffer */
119 size_t cbSense;
120 /** Opaque user data associated with this request */
121 void *pvVScsiReqUser;
122} VSCSIREQINT;
123
124/**
125 * Virtual SCSI I/O request.
126 */
127typedef struct VSCSIIOREQINT
128{
129 /** The associated request. */
130 PVSCSIREQINT pVScsiReq;
131 /** Lun for this I/O request. */
132 PVSCSILUNINT pVScsiLun;
133 /** Transfer direction */
134 VSCSIIOREQTXDIR enmTxDir;
135 /** Start offset */
136 uint64_t uOffset;
137 /** Number of bytes to transfer */
138 size_t cbTransfer;
139 /** Number of bytes the S/G list holds */
140 size_t cbSeg;
141 /** Number of segments. */
142 unsigned cSeg;
143 /** Segment array. */
144 PCRTSGSEG paSeg;
145} VSCSIIOREQINT;
146
147/**
148 * Virtual SCSI LUN descriptor.
149 */
150typedef struct VSCSILUNDESC
151{
152 /** Device type this descriptor emulates. */
153 VSCSILUNTYPE enmLunType;
154 /** Descriptor name */
155 const char *pcszDescName;
156 /** LUN type size */
157 size_t cbLun;
158
159 /**
160 * Initialise a Lun instance.
161 *
162 * @returns VBox status code.
163 * @param pVScsiLun The SCSI LUN instance.
164 */
165 DECLR3CALLBACKMEMBER(int, pfnVScsiLunInit, (PVSCSILUNINT pVScsiLun));
166
167 /**
168 * Destroy a Lun instance.
169 *
170 * @returns VBox status code.
171 * @param pVScsiLun The SCSI LUN instance.
172 */
173 DECLR3CALLBACKMEMBER(int, pfnVScsiLunDestroy, (PVSCSILUNINT pVScsiLun));
174
175 /**
176 * Processes a SCSI request.
177 *
178 * @returns VBox status code.
179 * @param pVScsiLun The SCSI LUN instance.
180 * @param pVScsiReq The SCSi request to process.
181 */
182 DECLR3CALLBACKMEMBER(int, pfnVScsiLunReqProcess, (PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq));
183
184} VSCSILUNDESC;
185
186/** Maximum number of LUNs a device can have. */
187#define VSCSI_DEVICE_LUN_MAX 128
188
189/**
190 * Completesa SCSI request and calls the completion handler.
191 *
192 * @returns nothing.
193 * @param pVScsiDevice The virtual SCSI device.
194 * @param pVScsiReq The request which completed.
195 * @param rcReq The status code
196 * One of the SCSI_STATUS_* #defines.
197 */
198void vscsiDeviceReqComplete(PVSCSIDEVICEINT pVScsiDevice, PVSCSIREQINT pVScsiReq,
199 int rcReq);
200
201/**
202 * Initialize a I/O memory context.
203 *
204 * @returns nothing
205 * @param pIoMemCtx Pointer to a unitialized I/O memory context.
206 * @param paDataSeg Pointer to the S/G list.
207 * @param cSegments Number of segments in the S/G list.
208 */
209void vscsiIoMemCtxInit(PVSCSIIOMEMCTX pIoMemCtx, PCRTSGSEG paDataSeg, size_t cSegments);
210
211/**
212 * Return a buffer from the I/O memory context.
213 *
214 * @returns Pointer to the buffer
215 * @param pIoMemCtx Pointer to the I/O memory context.
216 * @param pcbData Pointer to the amount of byte requested.
217 * If the current buffer doesn't have enough bytes left
218 * the amount is returned in the variable.
219 */
220uint8_t *vscsiIoMemCtxGetBuffer(PVSCSIIOMEMCTX pIoMemCtx, size_t *pcbData);
221
222/**
223 * Copies data to a buffer described by a I/O memory context.
224 *
225 * @returns The amount of data copied before we run out of either
226 * I/O memory or src data.
227 * @param pIoMemCtx The I/O memory context to copy the data into.
228 * @param pbData Pointer to the data data to copy.
229 * @param cbData Amount of data to copy.
230 */
231size_t vscsiCopyToIoMemCtx(PVSCSIIOMEMCTX pIoMemCtx, uint8_t *pbData, size_t cbData);
232
233/**
234 * Copies data from a buffer described by a I/O memory context.
235 *
236 * @returns The amount of data copied before we run out of either
237 * I/O memory or dst data.
238 * @param pIoMemCtx The I/O memory context to copy the data from.
239 * @param pbData Pointer to the destination buffer.
240 * @param cbData Amount of data to copy.
241 */
242size_t vscsiCopyFromIoMemCtx(PVSCSIIOMEMCTX pIoMemCtx, uint8_t *pbData, size_t cbData);
243
244/**
245 * Sets a ok sense code.
246 *
247 * @returns SCSI status code.
248 * @param pVScsiReq The SCSI request.
249 */
250int vscsiReqSenseOkSet(PVSCSIREQINT pVScsiReq);
251
252/**
253 * Sets a error sense code.
254 *
255 * @returns SCSI status code.
256 * @param pVScsiReq The SCSI request.
257 * @param uSCSISenseKey The SCSi sense key to set.
258 * @param uSCSIASC The ASC value.
259 */
260int vscsiReqSenseErrorSet(PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey, uint8_t uSCSIASC);
261
262/**
263 * Enqueues a new flush request
264 *
265 * @retruns VBox status code.
266 * @param pVScsiLun The LUN instance which issued the request.
267 * @param pVScsiReq The virtual SCSI request associated with the flush.
268 */
269int vscsiIoReqFlushEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq);
270
271/**
272 * Enqueue a new data transfer request.
273 *
274 * @returns VBox status code.
275 * @param pVScsiLun The LUN instance which issued the request.
276 * @param pVScsiReq The virtual SCSI request associated with the transfer.
277 * @param enmTxDir Transfer direction.
278 * @param uOffset Start offset of the transfer.
279 * @param cbTransfer Number of bytes to transfer.
280 */
281int vscsiIoReqTransferEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq,
282 VSCSIIOREQTXDIR enmTxDir, uint64_t uOffset,
283 size_t cbTransfer);
284
285/**
286 * Returns the current number of outstanding tasks on the given LUN.
287 *
288 * @returns Number of outstanding tasks.
289 * @param pVScsiLun The LUN to check.
290 */
291uint32_t vscsiIoReqOutstandingCountGet(PVSCSILUNINT pVScsiLun);
292
293DECLINLINE(int) vscsiLunMediumGetSize(PVSCSILUNINT pVScsiLun, uint64_t *pcbSize)
294{
295 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumGetSize(pVScsiLun,
296 pVScsiLun->pvVScsiLunUser,
297 pcbSize);
298}
299
300DECLINLINE(int) vscsiLunReqTransferEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIIOREQINT pVScsiIoReq)
301{
302 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunReqTransferEnqueue(pVScsiLun,
303 pVScsiLun->pvVScsiLunUser,
304 pVScsiIoReq);
305}
306
307#endif /* ___VSCSIInternal_h */
308
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