VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

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