DrvSCSI.cpp revision 5b465a7c1237993faf8bb50120d247f3f0319ada
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * VBox storage drivers: Generic SCSI command parser and execution driver
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * Copyright (C) 2006-2010 Sun Microsystems, Inc.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * available from http://www.virtualbox.org. This file is free software;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * General Public License (GPL) as published by the Free Software
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * additional information or have any questions.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/*******************************************************************************
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync* Header Files *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync*******************************************************************************/
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync//#define DEBUG
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * SCSI driver instance data.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMISCSICONNECTOR
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIBLOCKASYNCPORT
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIMOUNTNOTIFY
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsynctypedef struct DRVSCSI
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Pointer driver instance. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Pointer to the attached driver's base interface. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Pointer to the attached driver's block interface. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Pointer to the attached driver's async block interface. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Pointer to the attached driver's block bios interface. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Pointer to the attached driver's mount interface. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Pointer to the SCSI port interface of the device above. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** pointer to the Led port interface of the dveice above. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The scsi connector interface .*/
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The block port interface. */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync#if 0 /* these interfaces aren't implemented */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The optional block async port interface. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The mount notify interface. */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync /** Fallback status LED state for this drive.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * This is used in case the device doesn't has a LED interface. */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync /** Pointer to the status LED for this drive. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Device type. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** BIOS PCHS Geometry. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** BIOS LCHS Geometry. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Number of sectors this device has. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The dedicated I/O thread for the non async approach. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Queue for passing the requests to the thread. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Request that we've left pending on wakeup or reset. */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /** Indicates whether PDMDrvHlpAsyncNotificationCompleted should be called by
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * any of the dummy functions. */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync bool volatile fDummySignal;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Release statistics: number of bytes written. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Release statistics: number of bytes read. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Converts a pointer to DRVSCSI::ISCSIConnecotr to a PDRVSCSI. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define PDMISCSICONNECTOR_2_DRVSCSI(pInterface) ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, ISCSIConnector)) )
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Dumps a SCSI request structure for debugging purposes.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns nothing.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pRequest Pointer to the request to dump.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic void drvscsiDumpScsiRequest(PPDMSCSIREQUEST pRequest)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Log(("Dump for pRequest=%#p Command: %s\n", pRequest, SCSICmdText(pRequest->pbCDB[0])));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Log(("cbScatterGather=%u\n", pRequest->cbScatterGather));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Log(("cScatterGatherEntries=%u\n", pRequest->cScatterGatherEntries));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Print all scatter gather entries. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (uint32_t i = 0; i < pRequest->cScatterGatherEntries; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Log(("ScatterGatherEntry[%u].cbSeg=%u\n", i, pRequest->paScatterGatherHead[i].cbSeg));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Log(("ScatterGatherEntry[%u].pvSeg=%#p\n", i, pRequest->paScatterGatherHead[i].pvSeg));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Copy the content of a buffer to a scatter gather list only
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * copying only the amount of data which fits into the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * scatter gather list.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns VBox status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pRequest Pointer to the request which contains the S/G list entries.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvBuf Pointer to the buffer which should be copied.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param cbBuf Size of the buffer.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int drvscsiScatterGatherListCopyFromBuffer(PPDMSCSIREQUEST pRequest, void *pvBuf, size_t cbBuf)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync unsigned cSGEntry = 0;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PPDMDATASEG pSGEntry = &pRequest->paScatterGatherHead[cSGEntry];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync LogFlowFunc(("pRequest=%#p pvBuf=%#p cbBuf=%u\n", pRequest, pvBuf, cbBuf));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync for (unsigned i = 0; i < cbBuf; i++)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Log(("%s: pvBuf[%u]=%#x\n", __FUNCTION__, i, pu8Buf[i]));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync size_t cbToCopy = (cbBuf < pSGEntry->cbSeg) ? cbBuf : pSGEntry->cbSeg;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* We finished. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Advance the buffer. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Go to the next entry in the list. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic void drvscsiPadStr(int8_t *pbDst, const char *pbSrc, uint32_t cbSize)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Set the sense and advanced sense key in the buffer for error conditions.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns SCSI status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pRequest Pointer to the request which contains the sense buffer.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param uSCSISenseKey The sense key to set.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param uSCSIASC The advanced sense key to set.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(int) drvscsiCmdError(PPDMSCSIREQUEST pRequest, uint8_t uSCSISenseKey, uint8_t uSCSIASC)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(pRequest->cbSenseBuffer >= 18, ("Sense buffer is not big enough\n"), SCSI_STATUS_OK);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(pRequest->pbSenseBuffer, ("Sense buffer pointer is NULL\n"), SCSI_STATUS_OK);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync memset(pRequest->pbSenseBuffer, 0, pRequest->cbSenseBuffer);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pRequest->pbSenseBuffer[0] = (1 << 7) | SCSI_SENSE_RESPONSE_CODE_CURR_FIXED; /* Fixed format */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pRequest->pbSenseBuffer[13] = 0x00; /** @todo: Provide more info. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Sets the sense key for a status good condition.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns SCSI status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pRequest Pointer to the request which contains the sense buffer.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(int) drvscsiCmdOk(PPDMSCSIREQUEST pRequest)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(pRequest->cbSenseBuffer >= 18, ("Sense buffer is not big enough\n"), SCSI_STATUS_OK);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(pRequest->pbSenseBuffer, ("Sense buffer pointer is NULL\n"), SCSI_STATUS_OK);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync memset(pRequest->pbSenseBuffer, 0, pRequest->cbSenseBuffer);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Setting this breaks Linux guests on the BusLogic controller.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * According to the SCSI SPC spec sense data is returned after a
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * CHECK CONDITION status or a REQUEST SENSE command.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Both SCSI controllers have a feature called Auto Sense which
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * fetches the sense data automatically from the device
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * with REQUEST SENSE. So the SCSI subsystem in Linux should
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * find this sense data even if the command finishes successfully
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * but if it finds valid sense data it will let the command fail
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * and it doesn't detect attached disks anymore.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Disabling makes it work again and no other guest shows errors
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * so I will leave it disabled for now.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * On the other hand it is possible that the devices fetch the sense data
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * only after a command failed so the content is really invalid if
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * the command succeeds.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pRequest->pbSenseBuffer[0] = (1 << 7) | SCSI_SENSE_RESPONSE_CODE_CURR_FIXED; /* Fixed format */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pRequest->pbSenseBuffer[13] = SCSI_ASC_NONE; /* Should be ASCQ but it has the same value for success. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(void) drvscsiH2BE_U16(uint8_t *pbBuf, uint16_t val)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(void) drvscsiH2BE_U24(uint8_t *pbBuf, uint32_t val)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(void) drvscsiH2BE_U32(uint8_t *pbBuf, uint32_t val)
93540abbca1a7ac8de705de01b9fc04092294a39vboxsyncDECLINLINE(void) drvscsiH2BE_U64(uint8_t *pbBuf, uint64_t val)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(uint16_t) drvscsiBE2H_U16(const uint8_t *pbBuf)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(uint32_t) drvscsiBE2H_U24(const uint8_t *pbBuf)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return (pbBuf[0] << 16) | (pbBuf[1] << 8) | pbBuf[2];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(uint32_t) drvscsiBE2H_U32(const uint8_t *pbBuf)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return (pbBuf[0] << 24) | (pbBuf[1] << 16) | (pbBuf[2] << 8) | pbBuf[3];
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(uint64_t) drvscsiBE2H_U64(const uint8_t *pbBuf)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Parses the CDB of a request and acts accordingly.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns transfer direction type.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pThis Pointer to the SCSI driver instance data.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pRequest Pointer to the request to process.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param puOffset Where to store the start offset to start data transfer from.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pcbToTransfer Where to store the number of bytes to transfer.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param piTxDir Where to store the data transfer direction.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int drvscsiProcessCDB(PDRVSCSI pThis, PPDMSCSIREQUEST pRequest, uint64_t *puOffset, uint32_t *pcbToTransfer, int *piTxDir)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* We check for a command which needs to be handled even for non existant LUNs. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync memset(&ScsiInquiryReply, 0, sizeof(ScsiInquiryReply));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* We support only one attached device at LUN0 at the moment. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ScsiInquiryReply.u5PeripheralDeviceType = SCSI_INQUIRY_DATA_PERIPHERAL_DEVICE_TYPE_UNKNOWN;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ScsiInquiryReply.u3PeripheralQualifier = SCSI_INQUIRY_DATA_PERIPHERAL_QUALIFIER_NOT_CONNECTED_NOT_SUPPORTED;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ScsiInquiryReply.u5PeripheralDeviceType = SCSI_INQUIRY_DATA_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgFailed(("Device type %u not supported\n", pThis->enmType));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ScsiInquiryReply.u3PeripheralQualifier = SCSI_INQUIRY_DATA_PERIPHERAL_QUALIFIER_CONNECTED;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ScsiInquiryReply.u3AnsiVersion = 0x05; /* SPC-4 compliant */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiPadStr(ScsiInquiryReply.achVendorId, "VBOX", 8);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiPadStr(ScsiInquiryReply.achProductId, "HARDDISK", 16);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiPadStr(ScsiInquiryReply.achProductLevel, "1.0", 4);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiScatterGatherListCopyFromBuffer(pRequest, &ScsiInquiryReply, sizeof(SCSIINQUIRYDATA));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * If allocation length is less than 16 bytes SPC compliant devices have
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * to return an error.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = drvscsiCmdError(pRequest, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_INV_FIELD_IN_CMD_PACKET);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiH2BE_U32(&aReply[0], 8); /* List length starts at position 0. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiScatterGatherListCopyFromBuffer(pRequest, aReply, sizeof(aReply));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Now for commands which are only implemented for existant LUNs. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * If sector size exceeds the maximum value that is
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * able to be stored in 4 bytes return 0xffffffff in this field
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiScatterGatherListCopyFromBuffer(pRequest, aReply, sizeof(aReply));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiScatterGatherListCopyFromBuffer(pRequest, aReply, sizeof(aReply));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pcbToTransfer = ((uint32_t)pRequest->pbCDB[4]) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *puOffset = ((uint64_t)drvscsiBE2H_U32(&pRequest->pbCDB[2])) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pcbToTransfer = ((uint32_t)drvscsiBE2H_U16(&pRequest->pbCDB[7])) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *puOffset = ((uint64_t)drvscsiBE2H_U32(&pRequest->pbCDB[2])) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pcbToTransfer = ((uint32_t)drvscsiBE2H_U32(&pRequest->pbCDB[6])) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *puOffset = drvscsiBE2H_U64(&pRequest->pbCDB[2]) * 512;
93540abbca1a7ac8de705de01b9fc04092294a39vboxsync *pcbToTransfer = ((uint32_t)drvscsiBE2H_U32(&pRequest->pbCDB[10])) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pcbToTransfer = ((uint32_t)pRequest->pbCDB[4]) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *puOffset = ((uint64_t)drvscsiBE2H_U32(&pRequest->pbCDB[2])) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pcbToTransfer = ((uint32_t)drvscsiBE2H_U16(&pRequest->pbCDB[7])) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *puOffset = ((uint64_t)drvscsiBE2H_U32(&pRequest->pbCDB[2])) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pcbToTransfer = ((uint32_t)drvscsiBE2H_U32(&pRequest->pbCDB[6])) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *puOffset = drvscsiBE2H_U64(&pRequest->pbCDB[2]) * 512;
93540abbca1a7ac8de705de01b9fc04092294a39vboxsync *pcbToTransfer = ((uint32_t)drvscsiBE2H_U32(&pRequest->pbCDB[10])) * 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* @todo When async mode implemented we have to move this out here. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int rc2 = pThis->pDrvBlock->pfnFlush(pThis->pDrvBlock);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgRC(rc2, ("Flushing data failed rc=%Rrc\n", rc2));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* We do not implement an echo buffer. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiScatterGatherListCopyFromBuffer(pRequest, aReply, sizeof(aReply));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Nothing to do. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint16_t cbMax = drvscsiBE2H_U16(&pRequest->pbCDB[7]);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiScatterGatherListCopyFromBuffer(pRequest, aReply, sizeof(aReply));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = drvscsiCmdError(pRequest, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_INV_FIELD_IN_CMD_PACKET);
93540abbca1a7ac8de705de01b9fc04092294a39vboxsync /* Leave the rest 0 */
93540abbca1a7ac8de705de01b9fc04092294a39vboxsync drvscsiScatterGatherListCopyFromBuffer(pRequest, aReply, sizeof(aReply));
93540abbca1a7ac8de705de01b9fc04092294a39vboxsync rc = drvscsiCmdError(pRequest, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_INV_FIELD_IN_CMD_PACKET); /* Don't know if this is correct */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync //AssertMsgFailed(("Command %#x [%s] not implemented\n", pRequest->pbCDB[0], SCSICmdText(pRequest->pbCDB[0])));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = drvscsiCmdError(pRequest, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_ILLEGAL_OPCODE);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Report an error. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = drvscsiCmdError(pRequest, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_LOGICAL_UNIT_DOES_NOT_RESPOND_TO_SELECTION);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int drvscsiProcessRequestOne(PDRVSCSI pThis, PPDMSCSIREQUEST pRequest)
710a6316a22868b04400caf79719f96c18163cd3vboxsync uint64_t uOffset = UINT64_MAX; /* initialized to shut up gcc warnings. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rcCompletion = drvscsiProcessCDB(pThis, pRequest, &uOffset, &cbToTransfer, &iTxDir);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if ((rcCompletion == SCSI_STATUS_OK) && (iTxDir != PDMBLOCKTXDIR_NONE))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t cbProcess = (cbToTransfer < pSegActual->cbSeg) ? cbToTransfer : (uint32_t)pSegActual->cbSeg;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Log(("%s: uOffset=%llu cbToTransfer=%u\n", __FUNCTION__, uOffset, cbToTransfer));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pThis->pLed->Asserted.s.fReading = pThis->pLed->Actual.s.fReading = 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = pThis->pDrvBlock->pfnRead(pThis->pDrvBlock, uOffset,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgFailed(("%s: Failed to read data %Rrc\n", __FUNCTION__, rc));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync STAM_REL_COUNTER_ADD(&pThis->StatBytesRead, cbProcess);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pThis->pLed->Asserted.s.fWriting = pThis->pLed->Actual.s.fWriting = 1;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = pThis->pDrvBlock->pfnWrite(pThis->pDrvBlock, uOffset,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgFailed(("%s: Failed to write data %Rrc\n", __FUNCTION__, rc));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync STAM_REL_COUNTER_ADD(&pThis->StatBytesWritten, cbProcess);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Go to the next entry. */
93540abbca1a7ac8de705de01b9fc04092294a39vboxsync ("Transfer incomplete cbToTransfer=%u cSegmentsLeft=%u\n", cbToTransfer, cSegmentsLeft));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Notify device. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = pThis->pDevScsiPort->pfnSCSIRequestCompleted(pThis->pDevScsiPort, pRequest, rcCompletion);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgRC(rc, ("Error while notifying device rc=%Rrc\n", rc));
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * Dummy request function used by drvscsiReset to wait for all pending requests
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * to complete prior to the device reset.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pThis Pointer to the instace data.
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync * @returns VINF_SUCCESS.
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncstatic int drvscsiAsyncIOLoopSyncCallback(PDRVSCSI pThis)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync PDMDrvHlpAsyncNotificationCompleted(pThis->pDrvIns);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Request function to wakeup the thread.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pThis Pointer to the instace data.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns VWRN_STATE_CHANGED.
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncstatic int drvscsiAsyncIOLoopWakeupFunc(PDRVSCSI pThis)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync PDMDrvHlpAsyncNotificationCompleted(pThis->pDrvIns);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * The thread function which processes the requests asynchronously.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @returns VBox status code.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pDrvIns Pointer to the driver instance data.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pThread Pointer to the thread instance data.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int drvscsiAsyncIOLoop(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync while (pThread->enmState == PDMTHREADSTATE_RUNNING)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = RTReqProcess(pThis->pQueueRequests, RT_INDEFINITE_WAIT);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsg(rc == VWRN_STATE_CHANGED, ("Left RTReqProcess and error code is not VWRN_STATE_CHANGED rc=%Rrc\n", rc));
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * Deals with any pending dummy request
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @returns true if no pending dummy request, false if still pending.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @param pThis The instance data.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @param cMillies The number of milliseconds to wait for any
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * pending request to finish.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsyncstatic bool drvscsiAsyncIOLoopNoPendingDummy(PDRVSCSI pThis, uint32_t cMillies)
8a339f91959bb7a3315b51a23461b68c7b0cb50evboxsync return true;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync int rc = RTReqWait(pThis->pPendingDummyReq, cMillies);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync return false;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync return true;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic int drvscsiAsyncIOLoopWakeup(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(pThis->pQueueRequests, ("pQueueRequests is NULL\n"), VERR_INVALID_STATE);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 10000 /* 10 sec */))
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync LogRel(("drvscsiAsyncIOLoopWakeup#%u: previous dummy request is still pending\n", pDrvIns->iInstance));
0c4004948fca34f2db87e7b38013137e9472c306vboxsync rc = RTReqCall(pThis->pQueueRequests, &pReq, 10000 /* 10 sec. */, (PFNRT)drvscsiAsyncIOLoopWakeupFunc, 1, pThis);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync LogRel(("drvscsiAsyncIOLoopWakeup#%u: %Rrc pReq=%p\n", pDrvIns->iInstance, rc, pReq));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/* -=-=-=-=- ISCSIConnector -=-=-=-=- */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @copydoc PDMISCSICONNECTOR::pfnSCSIRequestSend. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic DECLCALLBACK(int) drvscsiRequestSend(PPDMISCSICONNECTOR pInterface, PPDMSCSIREQUEST pSCSIRequest)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PDRVSCSI pThis = PDMISCSICONNECTOR_2_DRVSCSI(pInterface);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(pThis->pQueueRequests, ("pQueueRequests is NULL\n"), VERR_INVALID_STATE);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = RTReqCallEx(pThis->pQueueRequests, &pReq, 0, RTREQFLAGS_NO_WAIT, (PFNRT)drvscsiProcessRequestOne, 2, pThis, pSCSIRequest);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(RT_SUCCESS(rc), ("Inserting request into queue failed rc=%Rrc\n", rc), rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/* -=-=-=-=- IBase -=-=-=-=- */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsyncstatic DECLCALLBACK(void *) drvscsiQueryInterface(PPDMIBASE pInterface, const char *pszIID)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
a39ea3668b7019c23a68936259545f9b71bce1aavboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMISCSICONNECTOR, &pThis->ISCSIConnector);
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKPORT, &pThis->IPort);
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * Worker for drvscsiReset, drvscsiSuspend and drvscsiPowerOff.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pDrvIns The driver instance.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pfnAsyncNotify The async callback.
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncstatic void drvscsiR3ResetOrSuspendOrPowerOff(PPDMDRVINS pDrvIns, PFNPDMDRVASYNCNOTIFY pfnAsyncNotify)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if (drvscsiAsyncIOLoopNoPendingDummy(pThis, 0 /*ms*/))
0c4004948fca34f2db87e7b38013137e9472c306vboxsync int rc = RTReqCall(pThis->pQueueRequests, &pReq, 0 /*ms*/, (PFNRT)drvscsiAsyncIOLoopSyncCallback, 1, pThis);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync PDMDrvHlpSetAsyncNotification(pDrvIns, pfnAsyncNotify);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Callback employed by drvscsiSuspend and drvscsiPowerOff.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @returns true if we've quiesced, false if we're still working.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pDrvIns The driver instance.
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncstatic DECLCALLBACK(bool) drvscsiIsAsyncSuspendOrPowerOffDone(PPDMDRVINS pDrvIns)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 0 /*ms*/))
0c4004948fca34f2db87e7b38013137e9472c306vboxsync return false;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync return true;
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * @copydoc FNPDMDRVPOWEROFF
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsyncstatic DECLCALLBACK(void) drvscsiPowerOff(PPDMDRVINS pDrvIns)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync drvscsiR3ResetOrSuspendOrPowerOff(pDrvIns, drvscsiIsAsyncSuspendOrPowerOffDone);
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * @copydoc FNPDMDRVSUSPEND
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsyncstatic DECLCALLBACK(void) drvscsiSuspend(PPDMDRVINS pDrvIns)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync drvscsiR3ResetOrSuspendOrPowerOff(pDrvIns, drvscsiIsAsyncSuspendOrPowerOffDone);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Callback employed by drvscsiReset.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @returns true if we've quiesced, false if we're still working.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pDrvIns The driver instance.
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncstatic DECLCALLBACK(bool) drvscsiIsAsyncResetDone(PPDMDRVINS pDrvIns)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 0 /*ms*/))
0c4004948fca34f2db87e7b38013137e9472c306vboxsync return false;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync return true;
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * @copydoc FNPDMDRVRESET
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsyncstatic DECLCALLBACK(void) drvscsiReset(PPDMDRVINS pDrvIns)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync drvscsiR3ResetOrSuspendOrPowerOff(pDrvIns, drvscsiIsAsyncResetDone);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Destruct a driver instance.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Most VM resources are freed by the VM. This callback is provided so that any non-VM
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * resources can be freed correctly.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pDrvIns The driver instance data.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic DECLCALLBACK(void) drvscsiDestruct(PPDMDRVINS pDrvIns)
8cd2f2e64725096acb682f34a5568b7fb816eda7vboxsync if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 100 /*ms*/))
8cd2f2e64725096acb682f34a5568b7fb816eda7vboxsync LogRel(("drvscsiDestruct#%u: previous dummy request is still pending\n", pDrvIns->iInstance));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgRC(rc, ("Failed to destroy queue rc=%Rrc\n", rc));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Construct a block driver instance.
cba6719bd64ec749967bbe931230452664109857vboxsync * @copydoc FNPDMDRVCONSTRUCT
cba6719bd64ec749967bbe931230452664109857vboxsyncstatic DECLCALLBACK(int) drvscsiConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync LogFlowFunc(("pDrvIns=%#p pCfgHandle=%#p\n", pDrvIns, pCfgHandle));
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync * Initialize the instance data.
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync pThis->ISCSIConnector.pfnSCSIRequestSend = drvscsiRequestSend;
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync pDrvIns->IBase.pfnQueryInterface = drvscsiQueryInterface;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Try attach driver below and query it's block interface.
cba6719bd64ec749967bbe931230452664109857vboxsync int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pThis->pDrvBase);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(RT_SUCCESS(rc), ("Attaching driver below failed rc=%Rrc\n", rc), rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Query the block and blockbios interfaces.
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync pThis->pDrvBlock = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIBLOCK);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgFailed(("Configuration error: No block interface!\n"));
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync pThis->pDrvBlockBios = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIBLOCKBIOS);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgFailed(("Configuration error: No block BIOS interface!\n"));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Query the SCSI port interface above. */
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync pThis->pDevScsiPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMISCSIPORT);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(pThis->pDevScsiPort, ("Missing SCSI port interface above\n"), VERR_PDM_MISSING_INTERFACE);
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync pThis->pDrvMount = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIMOUNT);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Query the optional LED interface above. */
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync pThis->pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Get The Led. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = pThis->pLedPort->pfnQueryStatusLed(pThis->pLedPort, 0, &pThis->pLed);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Try to get the optional async block interface. */
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync pThis->pDrvBlockAsync = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIBLOCKASYNC);
cba6719bd64ec749967bbe931230452664109857vboxsync PDMBLOCKTYPE enmType = pThis->pDrvBlock->pfnGetType(pThis->pDrvBlock);
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync return PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_UNSUPPORTED_BLOCK_TYPE, RT_SRC_POS,
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync N_("Only hard disks are currently supported as SCSI devices (enmType=%d)"),
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pThis->cSectors = pThis->pDrvBlock->pfnGetSize(pThis->pDrvBlock) / 512;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Create request queue. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(RT_SUCCESS(rc), ("Failed to create request queue rc=%Rrc\n"), rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Register statistics counter. */
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync /** @todo aeichner: Find a way to put the instance number of the attached
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync * controller device when we support more than one controller of the same type.
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync * At the moment we have the 0 hardcoded. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatBytesRead, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,
c91345f92b829d3fba05ce7a97206d83c5183ce0vboxsync "Amount of data read.", "/Devices/SCSI0/%d/ReadBytes", pDrvIns->iInstance);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatBytesWritten, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,
c91345f92b829d3fba05ce7a97206d83c5183ce0vboxsync "Amount of data written.", "/Devices/SCSI0/%d/WrittenBytes", pDrvIns->iInstance);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Create I/O thread. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = PDMDrvHlpPDMThreadCreate(pDrvIns, &pThis->pAsyncIOThread, pThis, drvscsiAsyncIOLoop,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync drvscsiAsyncIOLoopWakeup, 0, RTTHREADTYPE_IO, "SCSI async IO");
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn(RT_SUCCESS(rc), ("Failed to create async I/O thread rc=%Rrc\n"), rc);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * SCSI driver registration record.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* u32Version */
5b465a7c1237993faf8bb50120d247f3f0319adavboxsync /* szName */
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync /* szRCMod */
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync /* szR0Mod */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* pszDescription */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync "Generic SCSI driver.",
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* fFlags */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* fClass. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* cMaxInstances */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* cbInstance */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* pfnConstruct */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* pfnDestruct */
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync /* pfnRelocate */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* pfnIOCtl */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* pfnPowerOn */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* pfnReset */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* pfnSuspend */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* pfnResume */
cba6719bd64ec749967bbe931230452664109857vboxsync /* pfnAttach */
cba6719bd64ec749967bbe931230452664109857vboxsync /* pfnDetach */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* pfnPowerOff */
cba6719bd64ec749967bbe931230452664109857vboxsync /* pfnSoftReset */
cba6719bd64ec749967bbe931230452664109857vboxsync /* u32EndVersion */