From: Martin on
Hello everyone,
I'm developing a SDIO driver. I followed the sample sdiomars in WDK.
But it always hanged when I calling SdBusSubmitRequest to send CMD52.
And no command send to the device from the host controller.
It seems some guys asked the same question before. But sadly ,no one
answers.
Could you help me out of this? Here is my code:

1. Open an interface to the SD bus driver
//
// Open an interface to the SD bus driver
//
status = SdBusOpenInterface(WdfDeviceWdmGetPhysicalDevice (device),
&fdoData->BusInterface,
sizeof(SDBUS_INTERFACE_STANDARD),
SDBUS_INTERFACE_VERSION);

if (!NT_SUCCESS(status)) {
KdPrint(("SdBusOpenInterface failed - %X\n", status));
KdPrint(("<<===MarsEvtDeviceAdd!\n"));
return status;
}

interfaceParameters.Size =
sizeof(SDBUS_INTERFACE_PARAMETERS);
interfaceParameters.TargetObject =
WdfDeviceWdmGetAttachedDevice(device);
interfaceParameters.DeviceGeneratesInterrupts = TRUE; //change to
true eventually
interfaceParameters.CallbackAtDpcLevel = FALSE;
interfaceParameters.CallbackRoutine =
(PSDBUS_CALLBACK_ROUTINE)MarsEventCallback;
interfaceParameters.CallbackRoutineContext = fdoData;

status = STATUS_UNSUCCESSFUL;
if (fdoData->BusInterface.InitializeInterface) {
status =
(fdoData->BusInterface.InitializeInterface)(fdoData->BusInterface.Context,

&interfaceParameters);
}

if (!NT_SUCCESS(status)) {
KdPrint(("InitializeInterface failed - %X\n", status));
KdPrint(("<<===MarsEvtDeviceAdd!\n"));
return status;
}

//
// now fill in the function number
//

status = SdioGetProperty(device,
SDP_FUNCTION_NUMBER,
&fdoData->FunctionNumber,
sizeof(fdoData->FunctionNumber));
if (!NT_SUCCESS(status)) {
KdPrint(("SdioGetProperty failed - %X\n", status));
KdPrint(("<<===MarsEvtDeviceAdd!\n"));
return status;
}


fdoData->DriverVersion = SDBUS_DRIVER_VERSION_1;

SdioGetProperty(device,
SDP_BUS_DRIVER_VERSION,
&fdoData->DriverVersion,
sizeof(fdoData->DriverVersion));

fdoData->FunctionFocus = fdoData->FunctionNumber;

if (fdoData->DriverVersion < SDBUS_DRIVER_VERSION_2) {
fdoData->BlockMode = 0;
} else {
fdoData->BlockMode = 1;
}


2 funtion to send command52
NTSTATUS
SdioSendCommand52(
IN WDFDEVICE Device,
IN OUT PUCHAR Data,
IN SD_RW_DIRECT_ARGUMENT directArgument
)
{
PFDO_DATA fdoData;
NTSTATUS status;
PSDBUS_REQUEST_PACKET sdrp;


const SDCMD_DESCRIPTOR ReadIoDirectDesc =
{SDCMD_IO_RW_DIRECT, SDCC_STANDARD, SDTD_READ, SDTT_CMD_ONLY, SDRT_5};

const SDCMD_DESCRIPTOR WriteIoDirectDesc =
{SDCMD_IO_RW_DIRECT, SDCC_STANDARD, SDTD_WRITE, SDTT_CMD_ONLY, SDRT_5};

ULONG Function;
ULONG Address = directArgument.u.bits.Address;
BOOLEAN WriteToDevice = (BOOLEAN)directArgument.u.bits.WriteToDevice;
UCHAR TempData = (UCHAR)directArgument.u.bits.Data;
BOOLEAN ReadAfterWrite = (BOOLEAN)directArgument.u.bits.ReadAfterWrite;

fdoData = MarsFdoGetData(Device);

Function = fdoData->FunctionNumber;

sdrp = (PSDBUS_REQUEST_PACKET) ExAllocatePoolWithTag(NonPagedPool,
sizeof(SDBUS_REQUEST_PACKET), 'prds');
if (!sdrp)
{
KdPrint(("Can't allocate SDRP!\n"));
return STATUS_INSUFFICIENT_RESOURCES;
}
KdPrint(("SDRP Allocated!\n"));
RtlZeroMemory(sdrp, sizeof(SDBUS_REQUEST_PACKET));

sdrp->RequestFunction = SDRF_DEVICE_COMMAND;


directArgument.u.AsULONG = 0;
directArgument.u.bits.Function = Function;
directArgument.u.bits.Address = Address;


if (WriteToDevice) {
directArgument.u.bits.WriteToDevice = 1;
directArgument.u.bits.Data = TempData;
directArgument.u.bits.ReadAfterWrite = ReadAfterWrite;
sdrp->Parameters.DeviceCommand.CmdDesc = WriteIoDirectDesc;
} else {
sdrp->Parameters.DeviceCommand.CmdDesc = ReadIoDirectDesc;
}

sdrp->Parameters.DeviceCommand.Argument = directArgument.u.AsULONG;

//
// Send the IO request down to the bus driver
//

KdPrint(("WriteToDevice: %d\n", WriteToDevice));
KdPrint(("Function: %d\n", Function));
KdPrint(("Address: %X\n", Address));
KdPrint(("ReadAfterWrite: %d\n", ReadAfterWrite));
KdPrint(("Data: %X\n", TempData));


status = SdBusSubmitRequest(fdoData->BusInterface.Context, sdrp);

if (NT_SUCCESS(status) && !WriteToDevice) {
*Data = sdrp->ResponseData.AsUCHAR[0];
}

ExFreePool(sdrp);
return status;
}

From: Martin on
No one knows how to deal with this?
Can you give me some advice to debug?
Thank you