VSCSIInternal.h revision e961f5bfe1727c6816d3dad3805ebe21b6ba1c64
/* $Id$ */
/** @file
* Virtual SCSI driver: Internal defines
*/
/*
* Copyright (C) 2006-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef ___VSCSIInternal_h
#define ___VSCSIInternal_h
#include <iprt/memcache.h>
#include "VSCSIInline.h"
#include "VSCSIVpdPages.h"
/** Pointer to an internal virtual SCSI device. */
typedef VSCSIDEVICEINT *PVSCSIDEVICEINT;
/** Pointer to an internal virtual SCSI device LUN. */
typedef VSCSILUNINT *PVSCSILUNINT;
/** Pointer to an internal virtual SCSI device LUN pointer. */
typedef PVSCSILUNINT *PPVSCSILUNINT;
/** Pointer to a virtual SCSI LUN descriptor. */
typedef struct VSCSILUNDESC *PVSCSILUNDESC;
/** Pointer to a virtual SCSI request. */
typedef VSCSIREQINT *PVSCSIREQINT;
/** Pointer to a virtual SCSI I/O request. */
typedef VSCSIIOREQINT *PVSCSIIOREQINT;
/** Pointer to virtual SCSI sense data state. */
typedef struct VSCSISENSE *PVSCSISENSE;
/**
* Virtual SCSI sense data handling.
*/
typedef struct VSCSISENSE
{
/** Buffer holding the sense data. */
} VSCSISENSE;
/**
* Virtual SCSI device.
*/
typedef struct VSCSIDEVICEINT
{
/** Request completion callback */
/** Opaque user data. */
void *pvVScsiDeviceUser;
/** Number of LUNs currently attached. */
/** How many LUNs are fitting in the array. */
/** Request cache */
/** Sense data handling. */
/** Pointer to the array of LUN handles.
* The index is the LUN id. */
/**
* Virtual SCSI device LUN.
*/
typedef struct VSCSILUNINT
{
/** Pointer to the parent SCSI device. */
/** Opaque user data */
void *pvVScsiLunUser;
/** I/O callback table */
/** Pointer to the LUN type descriptor. */
/** Flags of supported features. */
/** I/O request processing data */
struct
{
/** Number of outstanding tasks on this LUN. */
volatile uint32_t cReqOutstanding;
} IoReq;
} VSCSILUNINT;
/**
* Virtual SCSI request.
*/
typedef struct VSCSIREQINT
{
/** The LUN the request is for. */
/** The CDB */
/** Size of the CDB */
/** S/G buffer. */
/** Pointer to the sense buffer. */
/** Size of the sense buffer */
/** Opaque user data associated with this request */
void *pvVScsiReqUser;
} VSCSIREQINT;
/**
* Virtual SCSI I/O request.
*/
typedef struct VSCSIIOREQINT
{
/** The associated request. */
/** Lun for this I/O request. */
/** Transfer direction */
/** Direction dependent data. */
union
{
struct
{
/** Start offset */
/** Number of bytes to transfer */
/** Number of bytes the S/G list holds */
/** Number of segments. */
unsigned cSeg;
/** Segment array. */
} Io;
/** Unmape request. */
struct
{
/** Array of ranges to unmap. */
/** Number of ranges. */
unsigned cRanges;
} Unmap;
} u;
/**
* VPD page pool.
*/
typedef struct VSCSIVPDPOOL
{
/** List of registered pages (VSCSIVPDPAGE). */
} VSCSIVPDPOOL;
/** Pointer to the VSCSI VPD page pool. */
typedef VSCSIVPDPOOL *PVSCSIVPDPOOL;
/**
* Virtual SCSI LUN descriptor.
*/
typedef struct VSCSILUNDESC
{
/** Device type this descriptor emulates. */
/** Descriptor name */
const char *pcszDescName;
/** LUN type size */
/**
* Initialise a Lun instance.
*
* @returns VBox status code.
* @param pVScsiLun The SCSI LUN instance.
*/
/**
* Destroy a Lun instance.
*
* @returns VBox status code.
* @param pVScsiLun The SCSI LUN instance.
*/
/**
* Processes a SCSI request.
*
* @returns VBox status code.
* @param pVScsiLun The SCSI LUN instance.
* @param pVScsiReq The SCSi request to process.
*/
} VSCSILUNDESC;
/** Maximum number of LUNs a device can have. */
#define VSCSI_DEVICE_LUN_MAX 128
/**
* Completes a SCSI request and calls the completion handler.
*
* @returns nothing.
* @param pVScsiDevice The virtual SCSI device.
* @param pVScsiReq The request which completed.
* @param rcScsiCode The status code
* One of the SCSI_STATUS_* #defines.
* @param fRedoPossible Flag whether redo is possible.
* @param rcReq Informational return code of the request.
*/
/**
* Init the sense data state.
*
* @returns nothing.
* @param pVScsiSense The SCSI sense data state to init.
*/
/**
* Sets a ok sense code.
*
* @returns SCSI status code.
* @param pVScsiSense The SCSI sense state to use.
* @param pVScsiReq The SCSI request.
*/
/**
* Sets a error sense code.
*
* @returns SCSI status code.
* @param pVScsiSense The SCSI sense state to use.
* @param pVScsiReq The SCSI request.
* @param uSCSISenseKey The SCSI sense key to set.
* @param uSCSIASC The ASC value.
* @param uSCSIASC The ASCQ value.
*/
/**
* Process a request sense command.
*
* @returns SCSI status code.
* @param pVScsiSense The SCSI sense state to use.
* @param pVScsiReq The SCSI request.
*/
/**
* Inits the VPD page pool.
*
* @returns VBox status code.
* @param pVScsiVpdPool The VPD page pool to initialize.
*/
/**
* Destroys the given VPD page pool freeing all pages in it.
*
* @returns nothing.
* @param pVScsiVpdPool The VPD page pool to destroy.
*/
/**
* Allocates a new page in the VPD page pool with the given number.
*
* @returns VBox status code.
* @retval VERR_ALREADY_EXIST if the page number is in use.
* @param pVScsiVpdPool The VPD page pool the page will belong to.
* @param uPage The page number, must be unique.
* @param cbPage Size of the page in bytes.
* @param ppbPage Where to store the pointer to the raw page data on success.
*/
int vscsiVpdPagePoolAllocNewPage(PVSCSIVPDPOOL pVScsiVpdPool, uint8_t uPage, size_t cbPage, uint8_t **ppbPage);
/**
* Queries the given page from the pool and cpies it to the buffer given
* by the SCSI request.
*
* @returns VBox status code.
* @retval VERR_NOT_FOUND if the page is not in the pool.
* @param pVScsiVpdPool The VPD page pool to use.
* @param pVScsiReq The SCSI request.
* @param uPage Page to query.
*/
/**
* Enqueues a new flush request
*
* @returns VBox status code.
* @param pVScsiLun The LUN instance which issued the request.
* @param pVScsiReq The virtual SCSI request associated with the flush.
*/
/**
* Enqueue a new data transfer request.
*
* @returns VBox status code.
* @param pVScsiLun The LUN instance which issued the request.
* @param pVScsiReq The virtual SCSI request associated with the transfer.
* @param enmTxDir Transfer direction.
* @param uOffset Start offset of the transfer.
* @param cbTransfer Number of bytes to transfer.
*/
/**
* Enqueue a new unmap request.
*
* @returns VBox status code.
* @param pVScsiLun The LUN instance which issued the request.
* @param pVScsiReq The virtual SCSI request associated with the transfer.
* @param paRanges The array of ranges to unmap.
* @param cRanges Number of ranges in the array.
*/
/**
* Returns the current number of outstanding tasks on the given LUN.
*
* @returns Number of outstanding tasks.
* @param pVScsiLun The LUN to check.
*/
/**
* Wrapper for the get medium size I/O callback.
*
* @returns VBox status code.
* @param pVScsiLun The LUN.
* @param pcbSize Where to store the size on success.
*/
{
pcbSize);
}
/**
* Wrapper for the I/O request enqueue I/O callback.
*
* @returns VBox status code.
* @param pVScsiLun The LUN.
* @param pVScsiIoReq The I/O request to enqueue.
*/
{
}
/**
* Wrapper for the get feature flags I/O callback.
*
* @returns VBox status code.
* @param pVScsiLun The LUN.
* @param pVScsiIoReq The I/O request to enqueue.
*/
{
}
/**
* Wrapper around vscsiReqSenseOkSet()
*/
{
}
/**
* Wrapper around vscsiReqSenseErrorSet()
*/
DECLINLINE(int) vscsiLunReqSenseErrorSet(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey, uint8_t uSCSIASC, uint8_t uSCSIASCQ)
{
return vscsiReqSenseErrorSet(&pVScsiLun->pVScsiDevice->VScsiSense, pVScsiReq, uSCSISenseKey, uSCSIASC, uSCSIASCQ);
}
#endif /* ___VSCSIInternal_h */