- Allocate for each srb its one sense info buffer.

- Reinitialize the transfer size if a retry is necessary in ScsiClassSendSrbSynchronous.

svn path=/trunk/; revision=9650
This commit is contained in:
Hartmut Birr 2004-06-10 07:56:42 +00:00
parent c3e66860e4
commit b5273a652c

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: class2.c,v 1.53 2004/05/10 18:02:20 gvg Exp $ /* $Id: class2.c,v 1.54 2004/06/10 07:56:42 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -46,6 +46,11 @@
#define INQUIRY_DATA_SIZE 2048 #define INQUIRY_DATA_SIZE 2048
#define START_UNIT_TIMEOUT 30 #define START_UNIT_TIMEOUT 30
/*
* FIXME:
* Create a macro, which rounds up a size value to the next multiple of two.
*/
#define SENSEINFO_ALIGNMENT 32
static NTSTATUS STDCALL static NTSTATUS STDCALL
ScsiClassCreateClose(IN PDEVICE_OBJECT DeviceObject, ScsiClassCreateClose(IN PDEVICE_OBJECT DeviceObject,
@ -205,7 +210,7 @@ ScsiClassBuildRequest(IN PDEVICE_OBJECT DeviceObject,
Srb->QueueAction = SRB_SIMPLE_TAG_REQUEST; Srb->QueueAction = SRB_SIMPLE_TAG_REQUEST;
Srb->QueueSortKey = LogicalBlockAddress; Srb->QueueSortKey = LogicalBlockAddress;
Srb->SenseInfoBuffer = DeviceExtension->SenseData; Srb->SenseInfoBuffer = (SENSE_DATA*)ROUND_UP((ULONG_PTR)(Srb + 1), SENSEINFO_ALIGNMENT);
Srb->SenseInfoBufferLength = SENSE_BUFFER_SIZE; Srb->SenseInfoBufferLength = SENSE_BUFFER_SIZE;
Srb->TimeOutValue = Srb->TimeOutValue =
@ -558,9 +563,9 @@ ScsiClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
Irp)); Irp));
} }
/* Allocate an SRB */ /* Allocate and initialize an SRB */
Srb = ExAllocatePool (NonPagedPool, Srb = ExAllocateFromNPagedLookasideList(&DeviceExtension->SrbLookasideListHead);
sizeof(SCSI_REQUEST_BLOCK));
if (Srb == NULL) if (Srb == NULL)
{ {
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
@ -588,7 +593,9 @@ ScsiClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
DPRINT ("ScsiClassDeviceControl: IOCTL_DISK_CHECK_VERIFY SMALL\n"); DPRINT ("ScsiClassDeviceControl: IOCTL_DISK_CHECK_VERIFY SMALL\n");
Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL; Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
ExFreePool (Srb); /* Free the SRB */
ExFreeToNPagedLookasideList(&DeviceExtension->SrbLookasideListHead,
Srb);
IoCompleteRequest (Irp, IoCompleteRequest (Irp,
IO_NO_INCREMENT); IO_NO_INCREMENT);
return STATUS_BUFFER_TOO_SMALL; return STATUS_BUFFER_TOO_SMALL;
@ -599,10 +606,12 @@ ScsiClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
FALSE); FALSE);
if (SubIrp == NULL) if (SubIrp == NULL)
{ {
DPRINT ("ScsiClassDeviceControl: IOCTL_DISK_CHECK_VERIFY NotEnuf\n"); DPRINT ("ScsiClassDeviceControl: IOCTL_DISK_CHECK_VERIFY NotEnuf\n");
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
ExFreePool (Srb); /* Free the SRB */
ExFreeToNPagedLookasideList(&DeviceExtension->SrbLookasideListHead,
Srb);
IoCompleteRequest (Irp, IoCompleteRequest (Irp,
IO_NO_INCREMENT); IO_NO_INCREMENT);
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
@ -650,8 +659,9 @@ DPRINT ("ScsiClassDeviceControl: IOCTL_DISK_CHECK_VERIFY SrbAsync\n");
default: default:
DPRINT("Unknown device io control code %lx\n", DPRINT("Unknown device io control code %lx\n",
ModifiedControlCode); ModifiedControlCode);
ExFreePool(Srb); /* Free the SRB */
ExFreeToNPagedLookasideList(&DeviceExtension->SrbLookasideListHead,
Srb);
/* Pass the IOCTL down to the port driver */ /* Pass the IOCTL down to the port driver */
NextStack = IoGetNextIrpStackLocation(Irp); NextStack = IoGetNextIrpStackLocation(Irp);
NextStack->Parameters = Stack->Parameters; NextStack->Parameters = Stack->Parameters;
@ -993,7 +1003,7 @@ ScsiClassInitializeSrbLookasideList(IN PDEVICE_EXTENSION DeviceExtension,
NULL, NULL,
NULL, NULL,
NonPagedPool, NonPagedPool,
sizeof(SCSI_REQUEST_BLOCK), sizeof(SCSI_REQUEST_BLOCK) + sizeof(SENSE_DATA) + SENSEINFO_ALIGNMENT - 1,
TAG_SRBT, TAG_SRBT,
(USHORT)NumberElements); (USHORT)NumberElements);
} }
@ -1720,7 +1730,7 @@ ScsiClassReadDriveCapacity(IN PDEVICE_OBJECT DeviceObject)
DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension; DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
CapacityBuffer = ExAllocatePool(NonPagedPool, CapacityBuffer = ExAllocatePool(NonPagedPoolCacheAligned,
sizeof(READ_CAPACITY_DATA)); sizeof(READ_CAPACITY_DATA));
if (CapacityBuffer == NULL) if (CapacityBuffer == NULL)
{ {
@ -1925,7 +1935,7 @@ ScsiClassSendSrbAsynchronous(PDEVICE_OBJECT DeviceObject,
Srb->Function = SRB_FUNCTION_EXECUTE_SCSI; Srb->Function = SRB_FUNCTION_EXECUTE_SCSI;
Srb->Cdb[1] |= DeviceExtension->Lun << 5; Srb->Cdb[1] |= DeviceExtension->Lun << 5;
Srb->SenseInfoBuffer = DeviceExtension->SenseData; Srb->SenseInfoBuffer = (SENSE_DATA*)ROUND_UP((ULONG_PTR)(Srb + 1), SENSEINFO_ALIGNMENT);
Srb->SenseInfoBufferLength = SENSE_BUFFER_SIZE; Srb->SenseInfoBufferLength = SENSE_BUFFER_SIZE;
Srb->DataBuffer = BufferAddress; Srb->DataBuffer = BufferAddress;
@ -2002,7 +2012,7 @@ ScsiClassSendSrbSynchronous(PDEVICE_OBJECT DeviceObject,
ULONG RequestType; ULONG RequestType;
BOOLEAN Retry; BOOLEAN Retry;
ULONG RetryCount; ULONG RetryCount;
PKEVENT Event; KEVENT Event;
PIRP Irp; PIRP Irp;
NTSTATUS Status; NTSTATUS Status;
LARGE_INTEGER RetryWait; LARGE_INTEGER RetryWait;
@ -2044,13 +2054,11 @@ ScsiClassSendSrbSynchronous(PDEVICE_OBJECT DeviceObject,
} }
} }
Srb->DataTransferLength = BufferLength;
Srb->DataBuffer = BufferAddress; Srb->DataBuffer = BufferAddress;
Event = ExAllocatePool(NonPagedPool,
sizeof(KEVENT));
TryAgain: TryAgain:
KeInitializeEvent(Event, Srb->DataTransferLength = BufferLength;
KeInitializeEvent(&Event,
NotificationEvent, NotificationEvent,
FALSE); FALSE);
@ -2061,13 +2069,14 @@ TryAgain:
BufferAddress, BufferAddress,
BufferLength, BufferLength,
TRUE, TRUE,
Event, &Event,
&IoStatusBlock); &IoStatusBlock);
if (Irp == NULL) if (Irp == NULL)
{ {
DPRINT("IoBuildDeviceIoControlRequest() failed\n"); DPRINT("IoBuildDeviceIoControlRequest() failed\n");
ExFreePool(Srb->SenseInfoBuffer); ExFreePool(Srb->SenseInfoBuffer);
ExFreePool(Event); Srb->SenseInfoBuffer = NULL;
Srb->SenseInfoBufferLength = 0;
return(STATUS_INSUFFICIENT_RESOURCES); return(STATUS_INSUFFICIENT_RESOURCES);
} }
@ -2081,7 +2090,7 @@ TryAgain:
Irp); Irp);
if (Status == STATUS_PENDING) if (Status == STATUS_PENDING)
{ {
KeWaitForSingleObject(Event, KeWaitForSingleObject(&Event,
Suspended, Suspended,
KernelMode, KernelMode,
FALSE, FALSE,
@ -2123,7 +2132,6 @@ TryAgain:
} }
ExFreePool(Srb->SenseInfoBuffer); ExFreePool(Srb->SenseInfoBuffer);
ExFreePool(Event);
DPRINT("ScsiClassSendSrbSynchronous() done\n"); DPRINT("ScsiClassSendSrbSynchronous() done\n");