Hi,
I'm doing sdio driver on XP SP2. This SDIO driver is compiled using 2003
SP1 ddk. SDIO card is coming up properly and i could do several
operations using CMD52 (read/write etc). I have not enabled the
interrupts yet. Now, i'm trying the CMD53. CMD53 works fine in byte
mode. That is BlockMode in SD_RW_EXTENDED_ARGUMENT is set to 0 and the
parameters in SDCMD_DESCRIPTOR set to SDTT_SINGLE_BLOCK and SDRT_5.

But when i try the SDTT_MULTI_BLOCK mode, the command sent on the bus is
not proper. I captured the CMD53 on the bus using LA, and this is what i
found.

My block size set was 4 bytes. I was trying to read/write 8 bytes so
that two blocks of transaction should happen. But all the time, the
CMD53 on the bus had 8 as Block Count. After i did some different
exercise, i found that the Parameters.DeviceCommand.Length is sent as
block count for CMD53 instead of .u.bits.Count in
SD_RW_EXTENDED_ARGUMENT. (I made sure that the Block Mode in
SD_RW_EXTENDED_ARGUMENT is set to 1 so that even on the bus i see the
same for cmd53. I do not see any response from the SDIO card for this
and also, the bus driver is returning back, 0xC0000185 or 0x80000011..
My sdio card supports block mode (the card capability reg- 0x08 of cccr
reads 0x1F .....)

Is the bus driver in XP SP2 tested with CMD53 block mode (or
SDTT_MULTI_BLOCK) ?
I have attached the CMD53 function i've written, along with this mail...
Please let me know if there is any problem.

Eliyas, please help !

Rgds
Esha
------------------------------------
NTSTATUS
SdioReadWriteBuffer(PDEVICE_OBJECT fdo,IN ULONG Function,IN PUCHAR
PBuffer,IN ULONG Address,
IN UCHAR BlockMode,IN ULONG Length,IN BOOLEAN WriteToDevice,OUT PULONG
BytesRead)
{
PFDO_DATA fdoData;
PSDBUS_REQUEST_PACKET sdrp;
SD_RW_EXTENDED_ARGUMENT extendedArgument;
NTSTATUS status = STATUS_SUCCESS;
PMDL Mdl=NULL;
UCHAR i;
PUCHAR pBuf=NULL;
ULONG BlockSize=0;
ULONG len = Length;
ULONG Data=0;

SDCMD_DESCRIPTOR ReadIoExtendedDesc =
{SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
SDTT_MULTI_BLOCK , SDRT_5};
//{SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
SDTT_MULTI_BLOCK , SDRT_1};

SDCMD_DESCRIPTOR WriteIoExtendedDesc =
{SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_WRITE,
SDTT_MULTI_BLOCK , SDRT_5};

fdoData = (PFDO_DATA)fdo->DeviceExtension;

SdioDbgPrint(TRACE,"cmd53: fn %d len %d,add 0x%X blkmode %d WrRd
%d\n",Function,
Length,Address,BlockMode,WriteToDevice);
if(BlockMode == BYTE_MODE)
{
ReadIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
WriteIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
//len = BlockSize;
len = Length;
}
else
{
//(Function == FN0) ? (BlockSize = fdoData->BlockSizeFN0) :
(BlockSize = fdoData->BlockSizeFNx);
//status = SdioReadWriteByte(fdo,
FN0,(PUCHAR)&BlockSize,FN0_BLOCK_SIZE_REG,FALSE);

//just for testing, make sure that the same is written in
FN0_BLOCK_SIZE_REG before running this
BlockSize = 0x04;
SdioDbgPrint(TRACE,"\nBlksize 0x%X\n",BlockSize);

//Round of the length to the block size
if(Length % BlockSize)
len = (((Length / BlockSize) * BlockSize) + BlockSize);
else
len = ((Length / BlockSize) * BlockSize);
}

SdioDbgPrint(TRACE,"Calc len 0x%X\n",len);
pBuf = ExAllocatePool(NonPagedPool,len);
if (!pBuf) {
return STATUS_INSUFFICIENT_RESOURCES;
}

RtlZeroMemory(pBuf, len);
if (WriteToDevice)
RtlCopyMemory(pBuf,PBuffer, Length);
// first, get an MDL to map the data. Call IoAllocateMdl to
// allocate an MDL and pass in a pointer to a buffer
// allocated from the non-paged pool.
Mdl = IoAllocateMdl(pBuf, len, FALSE, FALSE, NULL);
if (Mdl == NULL) {

ExFreePool(pBuf);
return STATUS_INSUFFICIENT_RESOURCES;
}

MmBuildMdlForNonPagedPool (Mdl);
// next, allocate a request packet for the arguments of the command
sdrp = ExAllocatePool(NonPagedPool, sizeof(SDBUS_REQUEST_PACKET));
if (!sdrp) {
IoFreeMdl(Mdl);
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(sdrp, sizeof(SDBUS_REQUEST_PACKET));
sdrp->RequestFunction = SDRF_DEVICE_COMMAND;
extendedArgument.u.AsULONG = 0;
if(BlockMode == BYTE_MODE)
{
extendedArgument.u.bits.BlockMode = 0;
extendedArgument.u.bits.Count = len;
}
else
{
extendedArgument.u.bits.BlockMode = 1;
extendedArgument.u.bits.Count = len / BlockSize;
}
SdioDbgPrint(TRACE,"cmd53:set Count %d, blkmode
%d\n",extendedArgument.u.bits.Count,
extendedArgument.u.bits.BlockMode);
extendedArgument.u.bits.Function = Function;
extendedArgument.u.bits.OpCode = 1; // increment address
extendedArgument.u.bits.Address = Address;

if (WriteToDevice) {
extendedArgument.u.bits.WriteToDevice = 1;
sdrp->Parameters.DeviceCommand.CmdDesc = WriteIoExtendedDesc;

} else {
extendedArgument.u.bits.WriteToDevice = 0;
sdrp->Parameters.DeviceCommand.CmdDesc = ReadIoExtendedDesc;
}
sdrp->Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG;
sdrp->Parameters.DeviceCommand.Mdl = Mdl;

//This send the Block Count in CMD3 as the blocksize * num of block and
//makes the system crash - BSOD
//sdrp->Parameters.DeviceCommand.Length = len;

//With this the SdBusSubmitRequest returns 0xc0000185 status and
//the Block count in CMD53 gets the actual byte read/write length
//sdrp->Parameters.DeviceCommand.Length = Length;

//This send the Block Count in CMD3 as proper block count, but
still the
//bus drivers gives status as 0xc0000185 or 0x80000011
sdrp->Parameters.DeviceCommand.Length =
extendedArgument.u.bits.Count; //len;


// finally, submit the request
status = SdBusSubmitRequest(fdoData->SDBusInterface.Context,sdrp);

SdioDbgPrint(TRACE,"cmd53: resplen: %d\n",sdrp->ResponseLength);
SdioDbgPrint(TRACE,"cmd53: sts: %X \n",status);
SdioDbgPrint(TRACE,"cmd53: info: %X\n",sdrp->Information);

if (NT_SUCCESS(status) && !WriteToDevice) {

*BytesRead = Length;
RtlCopyMemory(PBuffer, pBuf, Length);
}
IoFreeMdl(Mdl);
ExFreePool(pBuf);
ExFreePool(sdrp);
return status;
}
----------------------------------

Re: Is cmd53 tested with sdbus driver in XP, SP2 for block mode ? by QuasiCodo

QuasiCodo
Tue Jun 20 15:12:37 CDT 2006

A couple of months ago, I was developing an SDIO driver for XP SP2 and I
believe we had CMD53 block mode working. I think your problem is setting
SD_RW_EXTENDED_ARGUMENT to 0. I seem to remember there are parameters that
are needed. If you look at the source in the example from MS:

excerpt from
http://msdn.microsoft.com/library/en-us/Buses_d/hh/Buses_d/securedigital_dg_97e9062d-965e-46bd-a399-7cd60bf932fa.xml.asp

// then, set up the argument and command descriptor
sdIoArgument.u.AsULONG = 0; // <---- INITIALIZATION ONLY
sdIoArgument.u.bits.Address = Offset;

// retrieve function number, the driver previously initialized
// this value with the SdBus GetProperty call
sdIoArgument.u.bits.Function = pDevExt->FunctionNumber;
sdIoArgument.u.bits.WriteToDevice = 1;

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

Setting the ext args to 0 is only initializing the variable. Notice that
for simplicity, the ext args is really a separate local variable, which is
setup and then transferred into the sdrp structure. Within the ext args,
you should set the Function, Address, WriteToDevice and other fields. Then
the separate ext arg variable is then transferred into
sdrp->Parameters.DeviceCommand.Argument member.

I hope this helps

((&->


"Eshanye_kp" <esha@procsys.com> wrote in message
news:%23jDRP6ClGHA.1244@TK2MSFTNGP05.phx.gbl...
> Hi,
> I'm doing sdio driver on XP SP2. This SDIO driver is compiled using 2003
> SP1 ddk. SDIO card is coming up properly and i could do several operations
> using CMD52 (read/write etc). I have not enabled the interrupts yet. Now,
> i'm trying the CMD53. CMD53 works fine in byte mode. That is BlockMode in
> SD_RW_EXTENDED_ARGUMENT is set to 0 and the parameters in SDCMD_DESCRIPTOR
> set to SDTT_SINGLE_BLOCK and SDRT_5.
>
> But when i try the SDTT_MULTI_BLOCK mode, the command sent on the bus is
> not proper. I captured the CMD53 on the bus using LA, and this is what i
> found.
>
> My block size set was 4 bytes. I was trying to read/write 8 bytes so that
> two blocks of transaction should happen. But all the time, the CMD53 on
> the bus had 8 as Block Count. After i did some different exercise, i found
> that the Parameters.DeviceCommand.Length is sent as block count for CMD53
> instead of .u.bits.Count in SD_RW_EXTENDED_ARGUMENT. (I made sure that the
> Block Mode in SD_RW_EXTENDED_ARGUMENT is set to 1 so that even on the bus
> i see the same for cmd53. I do not see any response from the SDIO card
> for this and also, the bus driver is returning back, 0xC0000185 or
> 0x80000011..
> My sdio card supports block mode (the card capability reg- 0x08 of cccr
> reads 0x1F .....)
>
> Is the bus driver in XP SP2 tested with CMD53 block mode (or
> SDTT_MULTI_BLOCK) ?
> I have attached the CMD53 function i've written, along with this mail...
> Please let me know if there is any problem.
>
> Eliyas, please help !
>
> Rgds
> Esha
> ------------------------------------
> NTSTATUS
> SdioReadWriteBuffer(PDEVICE_OBJECT fdo,IN ULONG Function,IN PUCHAR
> PBuffer,IN ULONG Address,
> IN UCHAR BlockMode,IN ULONG Length,IN BOOLEAN WriteToDevice,OUT PULONG
> BytesRead)
> {
> PFDO_DATA fdoData;
> PSDBUS_REQUEST_PACKET sdrp;
> SD_RW_EXTENDED_ARGUMENT extendedArgument;
> NTSTATUS status = STATUS_SUCCESS;
> PMDL Mdl=NULL;
> UCHAR i;
> PUCHAR pBuf=NULL;
> ULONG BlockSize=0;
> ULONG len = Length;
> ULONG Data=0;
>
> SDCMD_DESCRIPTOR ReadIoExtendedDesc =
> {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
> SDTT_MULTI_BLOCK , SDRT_5};
> //{SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
> SDTT_MULTI_BLOCK , SDRT_1};
>
> SDCMD_DESCRIPTOR WriteIoExtendedDesc =
> {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_WRITE,
> SDTT_MULTI_BLOCK , SDRT_5};
>
> fdoData = (PFDO_DATA)fdo->DeviceExtension;
>
> SdioDbgPrint(TRACE,"cmd53: fn %d len %d,add 0x%X blkmode %d WrRd
> %d\n",Function,
> Length,Address,BlockMode,WriteToDevice);
> if(BlockMode == BYTE_MODE)
> {
> ReadIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
> WriteIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
> //len = BlockSize;
> len = Length;
> }
> else
> {
> //(Function == FN0) ? (BlockSize = fdoData->BlockSizeFN0) :
> (BlockSize = fdoData->BlockSizeFNx);
> //status = SdioReadWriteByte(fdo,
> FN0,(PUCHAR)&BlockSize,FN0_BLOCK_SIZE_REG,FALSE);
>
> //just for testing, make sure that the same is written in
> FN0_BLOCK_SIZE_REG before running this
> BlockSize = 0x04;
> SdioDbgPrint(TRACE,"\nBlksize 0x%X\n",BlockSize);
>
> //Round of the length to the block size
> if(Length % BlockSize)
> len = (((Length / BlockSize) * BlockSize) + BlockSize);
> else
> len = ((Length / BlockSize) * BlockSize);
> }
>
> SdioDbgPrint(TRACE,"Calc len 0x%X\n",len);
> pBuf = ExAllocatePool(NonPagedPool,len);
> if (!pBuf) {
> return STATUS_INSUFFICIENT_RESOURCES;
> }
>
> RtlZeroMemory(pBuf, len);
> if (WriteToDevice)
> RtlCopyMemory(pBuf,PBuffer, Length);
> // first, get an MDL to map the data. Call IoAllocateMdl to
> // allocate an MDL and pass in a pointer to a buffer
> // allocated from the non-paged pool.
> Mdl = IoAllocateMdl(pBuf, len, FALSE, FALSE, NULL);
> if (Mdl == NULL) {
>
> ExFreePool(pBuf);
> return STATUS_INSUFFICIENT_RESOURCES;
> }
>
> MmBuildMdlForNonPagedPool (Mdl);
> // next, allocate a request packet for the arguments of the command
> sdrp = ExAllocatePool(NonPagedPool, sizeof(SDBUS_REQUEST_PACKET));
> if (!sdrp) {
> IoFreeMdl(Mdl);
> return STATUS_INSUFFICIENT_RESOURCES;
> }
> RtlZeroMemory(sdrp, sizeof(SDBUS_REQUEST_PACKET));
> sdrp->RequestFunction = SDRF_DEVICE_COMMAND;
> extendedArgument.u.AsULONG = 0;
> if(BlockMode == BYTE_MODE)
> {
> extendedArgument.u.bits.BlockMode = 0;
> extendedArgument.u.bits.Count = len;
> }
> else
> {
> extendedArgument.u.bits.BlockMode = 1;
> extendedArgument.u.bits.Count = len / BlockSize;
> }
> SdioDbgPrint(TRACE,"cmd53:set Count %d, blkmode
> %d\n",extendedArgument.u.bits.Count,
> extendedArgument.u.bits.BlockMode);
> extendedArgument.u.bits.Function = Function;
> extendedArgument.u.bits.OpCode = 1; // increment address
> extendedArgument.u.bits.Address = Address;
>
> if (WriteToDevice) {
> extendedArgument.u.bits.WriteToDevice = 1;
> sdrp->Parameters.DeviceCommand.CmdDesc = WriteIoExtendedDesc;
>
> } else {
> extendedArgument.u.bits.WriteToDevice = 0;
> sdrp->Parameters.DeviceCommand.CmdDesc = ReadIoExtendedDesc;
> }
> sdrp->Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG;
> sdrp->Parameters.DeviceCommand.Mdl = Mdl;
>
> //This send the Block Count in CMD3 as the blocksize * num of block
> and
> //makes the system crash - BSOD
> //sdrp->Parameters.DeviceCommand.Length = len;
>
> //With this the SdBusSubmitRequest returns 0xc0000185 status and
> //the Block count in CMD53 gets the actual byte read/write length
> //sdrp->Parameters.DeviceCommand.Length = Length;
>
> //This send the Block Count in CMD3 as proper block count, but still
> the
> //bus drivers gives status as 0xc0000185 or 0x80000011
> sdrp->Parameters.DeviceCommand.Length = extendedArgument.u.bits.Count;
> //len;
>
>
> // finally, submit the request
> status = SdBusSubmitRequest(fdoData->SDBusInterface.Context,sdrp);
>
> SdioDbgPrint(TRACE,"cmd53: resplen: %d\n",sdrp->ResponseLength);
> SdioDbgPrint(TRACE,"cmd53: sts: %X \n",status);
> SdioDbgPrint(TRACE,"cmd53: info: %X\n",sdrp->Information);
>
> if (NT_SUCCESS(status) && !WriteToDevice) {
>
> *BytesRead = Length;
> RtlCopyMemory(PBuffer, pBuf, Length);
> }
> IoFreeMdl(Mdl);
> ExFreePool(pBuf);
> ExFreePool(sdrp);
> return status;
> }
> ----------------------------------



Re: Is cmd53 tested with sdbus driver in XP, SP2 for block mode ? by Eshanye_kp

Eshanye_kp
Wed Jun 21 00:55:52 CDT 2006

Thanks for the response, Quasi... but as you have pointed out i'm
updating the parameters of extended_argument with block mode, address,
Opcode, and the block count etc and then putting that in the sdrp
structure, like...

extendedArgument.u.AsULONG = 0;

extendedArgument.u.bits.Function = Function;
extendedArgument.u.bits.OpCode = 1; // increment address
extendedArgument.u.bits.Address = Address;
extendedArgument.u.bits.Count = len / BlockSize;
extendedArgument.u.bits.WriteToDevice = 1;

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

Also, note that in the descriptor i'm using SDTT_MULTI_BLOCK and SDRT_5
instead of SDTT_MULTI_BLOCK and SDRT_1 as given in the ddk example....

I found that the bus driver is replacing the block count in the CMD53
with the MDL length i sent in sdrp->Parameters.DeviceCommand.Length.....

Could you please send me the code segment of the implementation for
CMD53 which you made it work... also could you tell me on which platform
your sdio driver was supported ? I'm running on XP SP2 and compiling the
driver in 2003SP1 ddk (3790.1830)

Please help.
Esha


QuasiCodo wrote:

> A couple of months ago, I was developing an SDIO driver for XP SP2 and I
> believe we had CMD53 block mode working. I think your problem is setting
> SD_RW_EXTENDED_ARGUMENT to 0. I seem to remember there are parameters that
> are needed. If you look at the source in the example from MS:
>
> excerpt from
> http://msdn.microsoft.com/library/en-us/Buses_d/hh/Buses_d/securedigital_dg_97e9062d-965e-46bd-a399-7cd60bf932fa.xml.asp
>
> // then, set up the argument and command descriptor
> sdIoArgument.u.AsULONG = 0; // <---- INITIALIZATION ONLY
> sdIoArgument.u.bits.Address = Offset;
>
> // retrieve function number, the driver previously initialized
> // this value with the SdBus GetProperty call
> sdIoArgument.u.bits.Function = pDevExt->FunctionNumber;
> sdIoArgument.u.bits.WriteToDevice = 1;
>
> sdrp->Parameters.DeviceCommand.Argument =
> sdIoArgument.u.AsULONG;
>
> Setting the ext args to 0 is only initializing the variable. Notice that
> for simplicity, the ext args is really a separate local variable, which is
> setup and then transferred into the sdrp structure. Within the ext args,
> you should set the Function, Address, WriteToDevice and other fields. Then
> the separate ext arg variable is then transferred into
> sdrp->Parameters.DeviceCommand.Argument member.
>
> I hope this helps
>
> ((&->
>
>
> "Eshanye_kp" <esha@procsys.com> wrote in message
> news:%23jDRP6ClGHA.1244@TK2MSFTNGP05.phx.gbl...
>
>>Hi,
>>I'm doing sdio driver on XP SP2. This SDIO driver is compiled using 2003
>>SP1 ddk. SDIO card is coming up properly and i could do several operations
>>using CMD52 (read/write etc). I have not enabled the interrupts yet. Now,
>>i'm trying the CMD53. CMD53 works fine in byte mode. That is BlockMode in
>>SD_RW_EXTENDED_ARGUMENT is set to 0 and the parameters in SDCMD_DESCRIPTOR
>>set to SDTT_SINGLE_BLOCK and SDRT_5.
>>
>>But when i try the SDTT_MULTI_BLOCK mode, the command sent on the bus is
>>not proper. I captured the CMD53 on the bus using LA, and this is what i
>>found.
>>
>>My block size set was 4 bytes. I was trying to read/write 8 bytes so that
>>two blocks of transaction should happen. But all the time, the CMD53 on
>>the bus had 8 as Block Count. After i did some different exercise, i found
>>that the Parameters.DeviceCommand.Length is sent as block count for CMD53
>>instead of .u.bits.Count in SD_RW_EXTENDED_ARGUMENT. (I made sure that the
>>Block Mode in SD_RW_EXTENDED_ARGUMENT is set to 1 so that even on the bus
>>i see the same for cmd53. I do not see any response from the SDIO card
>>for this and also, the bus driver is returning back, 0xC0000185 or
>>0x80000011..
>>My sdio card supports block mode (the card capability reg- 0x08 of cccr
>>reads 0x1F .....)
>>
>>Is the bus driver in XP SP2 tested with CMD53 block mode (or
>>SDTT_MULTI_BLOCK) ?
>>I have attached the CMD53 function i've written, along with this mail...
>>Please let me know if there is any problem.
>>
>>Eliyas, please help !
>>
>>Rgds
>>Esha
>>------------------------------------
>>NTSTATUS
>>SdioReadWriteBuffer(PDEVICE_OBJECT fdo,IN ULONG Function,IN PUCHAR
>>PBuffer,IN ULONG Address,
>>IN UCHAR BlockMode,IN ULONG Length,IN BOOLEAN WriteToDevice,OUT PULONG
>>BytesRead)
>>{
>> PFDO_DATA fdoData;
>> PSDBUS_REQUEST_PACKET sdrp;
>> SD_RW_EXTENDED_ARGUMENT extendedArgument;
>> NTSTATUS status = STATUS_SUCCESS;
>> PMDL Mdl=NULL;
>> UCHAR i;
>> PUCHAR pBuf=NULL;
>> ULONG BlockSize=0;
>> ULONG len = Length;
>> ULONG Data=0;
>>
>> SDCMD_DESCRIPTOR ReadIoExtendedDesc =
>> {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
>>SDTT_MULTI_BLOCK , SDRT_5};
>> //{SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
>>SDTT_MULTI_BLOCK , SDRT_1};
>>
>> SDCMD_DESCRIPTOR WriteIoExtendedDesc =
>> {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_WRITE,
>>SDTT_MULTI_BLOCK , SDRT_5};
>>
>> fdoData = (PFDO_DATA)fdo->DeviceExtension;
>>
>> SdioDbgPrint(TRACE,"cmd53: fn %d len %d,add 0x%X blkmode %d WrRd
>>%d\n",Function,
>> Length,Address,BlockMode,WriteToDevice);
>> if(BlockMode == BYTE_MODE)
>> {
>> ReadIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
>> WriteIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
>> //len = BlockSize;
>> len = Length;
>> }
>> else
>> {
>> //(Function == FN0) ? (BlockSize = fdoData->BlockSizeFN0) :
>>(BlockSize = fdoData->BlockSizeFNx);
>> //status = SdioReadWriteByte(fdo,
>>FN0,(PUCHAR)&BlockSize,FN0_BLOCK_SIZE_REG,FALSE);
>>
>> //just for testing, make sure that the same is written in
>>FN0_BLOCK_SIZE_REG before running this
>> BlockSize = 0x04;
>> SdioDbgPrint(TRACE,"\nBlksize 0x%X\n",BlockSize);
>>
>> //Round of the length to the block size
>> if(Length % BlockSize)
>> len = (((Length / BlockSize) * BlockSize) + BlockSize);
>> else
>> len = ((Length / BlockSize) * BlockSize);
>> }
>>
>> SdioDbgPrint(TRACE,"Calc len 0x%X\n",len);
>> pBuf = ExAllocatePool(NonPagedPool,len);
>> if (!pBuf) {
>> return STATUS_INSUFFICIENT_RESOURCES;
>> }
>>
>> RtlZeroMemory(pBuf, len);
>> if (WriteToDevice)
>> RtlCopyMemory(pBuf,PBuffer, Length);
>> // first, get an MDL to map the data. Call IoAllocateMdl to
>> // allocate an MDL and pass in a pointer to a buffer
>> // allocated from the non-paged pool.
>> Mdl = IoAllocateMdl(pBuf, len, FALSE, FALSE, NULL);
>> if (Mdl == NULL) {
>>
>> ExFreePool(pBuf);
>> return STATUS_INSUFFICIENT_RESOURCES;
>> }
>>
>> MmBuildMdlForNonPagedPool (Mdl);
>> // next, allocate a request packet for the arguments of the command
>> sdrp = ExAllocatePool(NonPagedPool, sizeof(SDBUS_REQUEST_PACKET));
>> if (!sdrp) {
>> IoFreeMdl(Mdl);
>> return STATUS_INSUFFICIENT_RESOURCES;
>> }
>> RtlZeroMemory(sdrp, sizeof(SDBUS_REQUEST_PACKET));
>> sdrp->RequestFunction = SDRF_DEVICE_COMMAND;
>> extendedArgument.u.AsULONG = 0;
>> if(BlockMode == BYTE_MODE)
>> {
>> extendedArgument.u.bits.BlockMode = 0;
>> extendedArgument.u.bits.Count = len;
>> }
>> else
>> {
>> extendedArgument.u.bits.BlockMode = 1;
>> extendedArgument.u.bits.Count = len / BlockSize;
>> }
>> SdioDbgPrint(TRACE,"cmd53:set Count %d, blkmode
>>%d\n",extendedArgument.u.bits.Count,
>> extendedArgument.u.bits.BlockMode);
>> extendedArgument.u.bits.Function = Function;
>> extendedArgument.u.bits.OpCode = 1; // increment address
>> extendedArgument.u.bits.Address = Address;
>>
>> if (WriteToDevice) {
>> extendedArgument.u.bits.WriteToDevice = 1;
>> sdrp->Parameters.DeviceCommand.CmdDesc = WriteIoExtendedDesc;
>>
>> } else {
>> extendedArgument.u.bits.WriteToDevice = 0;
>> sdrp->Parameters.DeviceCommand.CmdDesc = ReadIoExtendedDesc;
>> }
>> sdrp->Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG;
>> sdrp->Parameters.DeviceCommand.Mdl = Mdl;
>>
>> //This send the Block Count in CMD3 as the blocksize * num of block
>>and
>> //makes the system crash - BSOD
>> //sdrp->Parameters.DeviceCommand.Length = len;
>>
>> //With this the SdBusSubmitRequest returns 0xc0000185 status and
>> //the Block count in CMD53 gets the actual byte read/write length
>> //sdrp->Parameters.DeviceCommand.Length = Length;
>>
>> //This send the Block Count in CMD3 as proper block count, but still
>>the
>> //bus drivers gives status as 0xc0000185 or 0x80000011
>> sdrp->Parameters.DeviceCommand.Length = extendedArgument.u.bits.Count;
>>//len;
>>
>>
>> // finally, submit the request
>> status = SdBusSubmitRequest(fdoData->SDBusInterface.Context,sdrp);
>>
>> SdioDbgPrint(TRACE,"cmd53: resplen: %d\n",sdrp->ResponseLength);
>> SdioDbgPrint(TRACE,"cmd53: sts: %X \n",status);
>> SdioDbgPrint(TRACE,"cmd53: info: %X\n",sdrp->Information);
>>
>> if (NT_SUCCESS(status) && !WriteToDevice) {
>>
>> *BytesRead = Length;
>> RtlCopyMemory(PBuffer, pBuf, Length);
>> }
>> IoFreeMdl(Mdl);
>> ExFreePool(pBuf);
>> ExFreePool(sdrp);
>> return status;
>>}
>>----------------------------------
>
>
>

Re: Is cmd53 tested with sdbus driver in XP, SP2 for block mode ? by QuasiCodo

QuasiCodo
Wed Jun 21 10:05:13 CDT 2006

Another possibility is that you are not setting the block size registers in
the FBR before you submit the CMD53 to SDBUS. What I did was use CMD52's to
write to the block size registers. Are you doing this, too?

((&->

"Eshanye_kp" <esha@procsys.com> wrote in message
news:4498DF68.7030301@procsys.com...
> Thanks for the response, Quasi... but as you have pointed out i'm updating
> the parameters of extended_argument with block mode, address, Opcode, and
> the block count etc and then putting that in the sdrp structure, like...
>
> extendedArgument.u.AsULONG = 0;
>
> extendedArgument.u.bits.Function = Function;
> extendedArgument.u.bits.OpCode = 1; // increment address
> extendedArgument.u.bits.Address = Address;
> extendedArgument.u.bits.Count = len / BlockSize;
> extendedArgument.u.bits.WriteToDevice = 1;
>
> sdrp->Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG;
>
> Also, note that in the descriptor i'm using SDTT_MULTI_BLOCK and SDRT_5
> instead of SDTT_MULTI_BLOCK and SDRT_1 as given in the ddk example....
>
> I found that the bus driver is replacing the block count in the CMD53 with
> the MDL length i sent in sdrp->Parameters.DeviceCommand.Length.....
>
> Could you please send me the code segment of the implementation for CMD53
> which you made it work... also could you tell me on which platform your
> sdio driver was supported ? I'm running on XP SP2 and compiling the driver
> in 2003SP1 ddk (3790.1830)
>
> Please help.
> Esha
>
>
> QuasiCodo wrote:
>
>> A couple of months ago, I was developing an SDIO driver for XP SP2 and I
>> believe we had CMD53 block mode working. I think your problem is setting
>> SD_RW_EXTENDED_ARGUMENT to 0. I seem to remember there are parameters
>> that are needed. If you look at the source in the example from MS:
>>
>> excerpt from
>> http://msdn.microsoft.com/library/en-us/Buses_d/hh/Buses_d/securedigital_dg_97e9062d-965e-46bd-a399-7cd60bf932fa.xml.asp
>>
>> // then, set up the argument and command descriptor
>> sdIoArgument.u.AsULONG = 0; // <---- INITIALIZATION ONLY
>> sdIoArgument.u.bits.Address = Offset;
>>
>> // retrieve function number, the driver previously initialized
>> // this value with the SdBus GetProperty call
>> sdIoArgument.u.bits.Function = pDevExt->FunctionNumber;
>> sdIoArgument.u.bits.WriteToDevice = 1;
>>
>> sdrp->Parameters.DeviceCommand.Argument =
>> sdIoArgument.u.AsULONG;
>>
>> Setting the ext args to 0 is only initializing the variable. Notice that
>> for simplicity, the ext args is really a separate local variable, which
>> is setup and then transferred into the sdrp structure. Within the ext
>> args, you should set the Function, Address, WriteToDevice and other
>> fields. Then the separate ext arg variable is then transferred into
>> sdrp->Parameters.DeviceCommand.Argument member.
>>
>> I hope this helps
>>
>> ((&->
>>
>>
>> "Eshanye_kp" <esha@procsys.com> wrote in message
>> news:%23jDRP6ClGHA.1244@TK2MSFTNGP05.phx.gbl...
>>
>>>Hi,
>>>I'm doing sdio driver on XP SP2. This SDIO driver is compiled using 2003
>>>SP1 ddk. SDIO card is coming up properly and i could do several
>>>operations using CMD52 (read/write etc). I have not enabled the
>>>interrupts yet. Now, i'm trying the CMD53. CMD53 works fine in byte mode.
>>>That is BlockMode in SD_RW_EXTENDED_ARGUMENT is set to 0 and the
>>>parameters in SDCMD_DESCRIPTOR set to SDTT_SINGLE_BLOCK and SDRT_5.
>>>
>>>But when i try the SDTT_MULTI_BLOCK mode, the command sent on the bus is
>>>not proper. I captured the CMD53 on the bus using LA, and this is what i
>>>found.
>>>
>>>My block size set was 4 bytes. I was trying to read/write 8 bytes so that
>>>two blocks of transaction should happen. But all the time, the CMD53 on
>>>the bus had 8 as Block Count. After i did some different exercise, i
>>>found that the Parameters.DeviceCommand.Length is sent as block count for
>>>CMD53 instead of .u.bits.Count in SD_RW_EXTENDED_ARGUMENT. (I made sure
>>>that the Block Mode in SD_RW_EXTENDED_ARGUMENT is set to 1 so that even
>>>on the bus i see the same for cmd53. I do not see any response from the
>>>SDIO card for this and also, the bus driver is returning back,
>>>0xC0000185 or 0x80000011..
>>>My sdio card supports block mode (the card capability reg- 0x08 of cccr
>>>reads 0x1F .....)
>>>
>>>Is the bus driver in XP SP2 tested with CMD53 block mode (or
>>>SDTT_MULTI_BLOCK) ?
>>>I have attached the CMD53 function i've written, along with this mail...
>>>Please let me know if there is any problem.
>>>
>>>Eliyas, please help !
>>>
>>>Rgds
>>>Esha
>>>------------------------------------
>>>NTSTATUS
>>>SdioReadWriteBuffer(PDEVICE_OBJECT fdo,IN ULONG Function,IN PUCHAR
>>>PBuffer,IN ULONG Address,
>>>IN UCHAR BlockMode,IN ULONG Length,IN BOOLEAN WriteToDevice,OUT PULONG
>>>BytesRead)
>>>{
>>> PFDO_DATA fdoData;
>>> PSDBUS_REQUEST_PACKET sdrp;
>>> SD_RW_EXTENDED_ARGUMENT extendedArgument;
>>> NTSTATUS status = STATUS_SUCCESS;
>>> PMDL Mdl=NULL;
>>> UCHAR i;
>>> PUCHAR pBuf=NULL;
>>> ULONG BlockSize=0;
>>> ULONG len = Length;
>>> ULONG Data=0;
>>>
>>> SDCMD_DESCRIPTOR ReadIoExtendedDesc =
>>> {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
>>> SDTT_MULTI_BLOCK , SDRT_5};
>>> //{SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
>>> SDTT_MULTI_BLOCK , SDRT_1};
>>>
>>> SDCMD_DESCRIPTOR WriteIoExtendedDesc =
>>> {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_WRITE,
>>> SDTT_MULTI_BLOCK , SDRT_5};
>>>
>>> fdoData = (PFDO_DATA)fdo->DeviceExtension;
>>>
>>> SdioDbgPrint(TRACE,"cmd53: fn %d len %d,add 0x%X blkmode %d WrRd
>>> %d\n",Function,
>>> Length,Address,BlockMode,WriteToDevice);
>>> if(BlockMode == BYTE_MODE)
>>> {
>>> ReadIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
>>> WriteIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
>>> //len = BlockSize;
>>> len = Length;
>>> }
>>> else
>>> {
>>> //(Function == FN0) ? (BlockSize = fdoData->BlockSizeFN0) :
>>> (BlockSize = fdoData->BlockSizeFNx);
>>> //status = SdioReadWriteByte(fdo,
>>> FN0,(PUCHAR)&BlockSize,FN0_BLOCK_SIZE_REG,FALSE);
>>>
>>> //just for testing, make sure that the same is written in
>>> FN0_BLOCK_SIZE_REG before running this
>>> BlockSize = 0x04;
>>> SdioDbgPrint(TRACE,"\nBlksize 0x%X\n",BlockSize);
>>>
>>> //Round of the length to the block size
>>> if(Length % BlockSize)
>>> len = (((Length / BlockSize) * BlockSize) + BlockSize);
>>> else
>>> len = ((Length / BlockSize) * BlockSize);
>>> }
>>>
>>> SdioDbgPrint(TRACE,"Calc len 0x%X\n",len);
>>> pBuf = ExAllocatePool(NonPagedPool,len);
>>> if (!pBuf) {
>>> return STATUS_INSUFFICIENT_RESOURCES;
>>> }
>>>
>>> RtlZeroMemory(pBuf, len);
>>> if (WriteToDevice)
>>> RtlCopyMemory(pBuf,PBuffer, Length);
>>> // first, get an MDL to map the data. Call IoAllocateMdl to
>>> // allocate an MDL and pass in a pointer to a buffer
>>> // allocated from the non-paged pool.
>>> Mdl = IoAllocateMdl(pBuf, len, FALSE, FALSE, NULL);
>>> if (Mdl == NULL) {
>>>
>>> ExFreePool(pBuf);
>>> return STATUS_INSUFFICIENT_RESOURCES;
>>> }
>>>
>>> MmBuildMdlForNonPagedPool (Mdl);
>>> // next, allocate a request packet for the arguments of the command
>>> sdrp = ExAllocatePool(NonPagedPool, sizeof(SDBUS_REQUEST_PACKET));
>>> if (!sdrp) {
>>> IoFreeMdl(Mdl);
>>> return STATUS_INSUFFICIENT_RESOURCES;
>>> }
>>> RtlZeroMemory(sdrp, sizeof(SDBUS_REQUEST_PACKET));
>>> sdrp->RequestFunction = SDRF_DEVICE_COMMAND;
>>> extendedArgument.u.AsULONG = 0;
>>> if(BlockMode == BYTE_MODE)
>>> {
>>> extendedArgument.u.bits.BlockMode = 0;
>>> extendedArgument.u.bits.Count = len;
>>> }
>>> else
>>> {
>>> extendedArgument.u.bits.BlockMode = 1;
>>> extendedArgument.u.bits.Count = len / BlockSize;
>>> }
>>> SdioDbgPrint(TRACE,"cmd53:set Count %d, blkmode
>>> %d\n",extendedArgument.u.bits.Count,
>>> extendedArgument.u.bits.BlockMode);
>>> extendedArgument.u.bits.Function = Function;
>>> extendedArgument.u.bits.OpCode = 1; // increment address
>>> extendedArgument.u.bits.Address = Address;
>>>
>>> if (WriteToDevice) {
>>> extendedArgument.u.bits.WriteToDevice = 1;
>>> sdrp->Parameters.DeviceCommand.CmdDesc = WriteIoExtendedDesc;
>>>
>>> } else {
>>> extendedArgument.u.bits.WriteToDevice = 0;
>>> sdrp->Parameters.DeviceCommand.CmdDesc = ReadIoExtendedDesc;
>>> }
>>> sdrp->Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG;
>>> sdrp->Parameters.DeviceCommand.Mdl = Mdl;
>>>
>>> //This send the Block Count in CMD3 as the blocksize * num of block
>>> and
>>> //makes the system crash - BSOD
>>> //sdrp->Parameters.DeviceCommand.Length = len;
>>>
>>> //With this the SdBusSubmitRequest returns 0xc0000185 status and
>>> //the Block count in CMD53 gets the actual byte read/write length
>>> //sdrp->Parameters.DeviceCommand.Length = Length;
>>>
>>> //This send the Block Count in CMD3 as proper block count, but still
>>> the
>>> //bus drivers gives status as 0xc0000185 or 0x80000011
>>> sdrp->Parameters.DeviceCommand.Length =
>>> extendedArgument.u.bits.Count; //len;
>>>
>>>
>>> // finally, submit the request
>>> status = SdBusSubmitRequest(fdoData->SDBusInterface.Context,sdrp);
>>>
>>> SdioDbgPrint(TRACE,"cmd53: resplen: %d\n",sdrp->ResponseLength);
>>> SdioDbgPrint(TRACE,"cmd53: sts: %X \n",status);
>>> SdioDbgPrint(TRACE,"cmd53: info: %X\n",sdrp->Information);
>>>
>>> if (NT_SUCCESS(status) && !WriteToDevice) {
>>>
>>> *BytesRead = Length;
>>> RtlCopyMemory(PBuffer, pBuf, Length);
>>> }
>>> IoFreeMdl(Mdl);
>>> ExFreePool(pBuf);
>>> ExFreePool(sdrp);
>>> return status;
>>>}
>>>----------------------------------
>>
>>


Re: Is cmd53 tested with sdbus driver in XP, SP2 for block mode ? by Eshanye_kp

Eshanye_kp
Thu Jun 22 03:55:17 CDT 2006

I have set the FN0 block size (0x10 in cccr) and FN1 block size (0x110
in FBR) for 4 bytes.. also, i'm trying to read 8 bytes from 0x00 offset
of CCCR using CMD53. I have a memory which i can access using some
registers at the address range 0xF0 -0xFF (FN0 vendor specific), which
i'm trying to write using CMD53 (so essentially i'm using function FN0
for my operations).. can i access FN0 stuffs with CMD53 ?, I do not have
the CSA or CIS for function 1 at this point of development (Even CSA is
not there for FN0). The other options is to read CIS of FN0, which is
also giving me the same result when used with CMD53 block mode. (All
these are with FN0)

Now the same memory can be accessed using a FN1 register also, so i
tried cmd53 block mode to write and read the same memory using this FN1
register, but the result is same.

Note: CMD53 byte mode (block mode =0) is working fine because it expects
the number of bytes to read in place of block count which is what the
bus driver is doing always..

Do you have any more idea's for me to check ?

-Esha


QuasiCodo wrote:
> Another possibility is that you are not setting the block size registers in
> the FBR before you submit the CMD53 to SDBUS. What I did was use CMD52's to
> write to the block size registers. Are you doing this, too?
>
> ((&->
>
> "Eshanye_kp" <esha@procsys.com> wrote in message
> news:4498DF68.7030301@procsys.com...
>
>>Thanks for the response, Quasi... but as you have pointed out i'm updating
>>the parameters of extended_argument with block mode, address, Opcode, and
>>the block count etc and then putting that in the sdrp structure, like...
>>
>>extendedArgument.u.AsULONG = 0;
>>
>>extendedArgument.u.bits.Function = Function;
>>extendedArgument.u.bits.OpCode = 1; // increment address
>>extendedArgument.u.bits.Address = Address;
>>extendedArgument.u.bits.Count = len / BlockSize;
>>extendedArgument.u.bits.WriteToDevice = 1;
>>
>>sdrp->Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG;
>>
>>Also, note that in the descriptor i'm using SDTT_MULTI_BLOCK and SDRT_5
>>instead of SDTT_MULTI_BLOCK and SDRT_1 as given in the ddk example....
>>
>>I found that the bus driver is replacing the block count in the CMD53 with
>>the MDL length i sent in sdrp->Parameters.DeviceCommand.Length.....
>>
>>Could you please send me the code segment of the implementation for CMD53
>>which you made it work... also could you tell me on which platform your
>>sdio driver was supported ? I'm running on XP SP2 and compiling the driver
>>in 2003SP1 ddk (3790.1830)
>>
>>Please help.
>>Esha
>>
>>
>>QuasiCodo wrote:
>>
>>
>>>A couple of months ago, I was developing an SDIO driver for XP SP2 and I
>>>believe we had CMD53 block mode working. I think your problem is setting
>>>SD_RW_EXTENDED_ARGUMENT to 0. I seem to remember there are parameters
>>>that are needed. If you look at the source in the example from MS:
>>>
>>>excerpt from
>>>http://msdn.microsoft.com/library/en-us/Buses_d/hh/Buses_d/securedigital_dg_97e9062d-965e-46bd-a399-7cd60bf932fa.xml.asp
>>>
>>>// then, set up the argument and command descriptor
>>>sdIoArgument.u.AsULONG = 0; // <---- INITIALIZATION ONLY
>>>sdIoArgument.u.bits.Address = Offset;
>>>
>>>// retrieve function number, the driver previously initialized
>>>// this value with the SdBus GetProperty call
>>>sdIoArgument.u.bits.Function = pDevExt->FunctionNumber;
>>>sdIoArgument.u.bits.WriteToDevice = 1;
>>>
>>>sdrp->Parameters.DeviceCommand.Argument =
>>> sdIoArgument.u.AsULONG;
>>>
>>>Setting the ext args to 0 is only initializing the variable. Notice that
>>>for simplicity, the ext args is really a separate local variable, which
>>>is setup and then transferred into the sdrp structure. Within the ext
>>>args, you should set the Function, Address, WriteToDevice and other
>>>fields. Then the separate ext arg variable is then transferred into
>>>sdrp->Parameters.DeviceCommand.Argument member.
>>>
>>>I hope this helps
>>>
>>>((&->
>>>
>>>
>>>"Eshanye_kp" <esha@procsys.com> wrote in message
>>>news:%23jDRP6ClGHA.1244@TK2MSFTNGP05.phx.gbl...
>>>
>>>
>>>>Hi,
>>>>I'm doing sdio driver on XP SP2. This SDIO driver is compiled using 2003
>>>>SP1 ddk. SDIO card is coming up properly and i could do several
>>>>operations using CMD52 (read/write etc). I have not enabled the
>>>>interrupts yet. Now, i'm trying the CMD53. CMD53 works fine in byte mode.
>>>>That is BlockMode in SD_RW_EXTENDED_ARGUMENT is set to 0 and the
>>>>parameters in SDCMD_DESCRIPTOR set to SDTT_SINGLE_BLOCK and SDRT_5.
>>>>
>>>>But when i try the SDTT_MULTI_BLOCK mode, the command sent on the bus is
>>>>not proper. I captured the CMD53 on the bus using LA, and this is what i
>>>>found.
>>>>
>>>>My block size set was 4 bytes. I was trying to read/write 8 bytes so that
>>>>two blocks of transaction should happen. But all the time, the CMD53 on
>>>>the bus had 8 as Block Count. After i did some different exercise, i
>>>>found that the Parameters.DeviceCommand.Length is sent as block count for
>>>>CMD53 instead of .u.bits.Count in SD_RW_EXTENDED_ARGUMENT. (I made sure
>>>>that the Block Mode in SD_RW_EXTENDED_ARGUMENT is set to 1 so that even
>>>>on the bus i see the same for cmd53. I do not see any response from the
>>>>SDIO card for this and also, the bus driver is returning back,
>>>>0xC0000185 or 0x80000011..
>>>>My sdio card supports block mode (the card capability reg- 0x08 of cccr
>>>>reads 0x1F .....)
>>>>
>>>>Is the bus driver in XP SP2 tested with CMD53 block mode (or
>>>>SDTT_MULTI_BLOCK) ?
>>>>I have attached the CMD53 function i've written, along with this mail...
>>>>Please let me know if there is any problem.
>>>>
>>>>Eliyas, please help !
>>>>
>>>>Rgds
>>>>Esha
>>>>------------------------------------
>>>>NTSTATUS
>>>>SdioReadWriteBuffer(PDEVICE_OBJECT fdo,IN ULONG Function,IN PUCHAR
>>>>PBuffer,IN ULONG Address,
>>>>IN UCHAR BlockMode,IN ULONG Length,IN BOOLEAN WriteToDevice,OUT PULONG
>>>>BytesRead)
>>>>{
>>>> PFDO_DATA fdoData;
>>>> PSDBUS_REQUEST_PACKET sdrp;
>>>> SD_RW_EXTENDED_ARGUMENT extendedArgument;
>>>> NTSTATUS status = STATUS_SUCCESS;
>>>> PMDL Mdl=NULL;
>>>> UCHAR i;
>>>> PUCHAR pBuf=NULL;
>>>> ULONG BlockSize=0;
>>>> ULONG len = Length;
>>>> ULONG Data=0;
>>>>
>>>> SDCMD_DESCRIPTOR ReadIoExtendedDesc =
>>>> {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
>>>>SDTT_MULTI_BLOCK , SDRT_5};
>>>> //{SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
>>>>SDTT_MULTI_BLOCK , SDRT_1};
>>>>
>>>> SDCMD_DESCRIPTOR WriteIoExtendedDesc =
>>>> {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_WRITE,
>>>>SDTT_MULTI_BLOCK , SDRT_5};
>>>>
>>>> fdoData = (PFDO_DATA)fdo->DeviceExtension;
>>>>
>>>> SdioDbgPrint(TRACE,"cmd53: fn %d len %d,add 0x%X blkmode %d WrRd
>>>>%d\n",Function,
>>>> Length,Address,BlockMode,WriteToDevice);
>>>> if(BlockMode == BYTE_MODE)
>>>> {
>>>> ReadIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
>>>> WriteIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
>>>> //len = BlockSize;
>>>> len = Length;
>>>> }
>>>> else
>>>> {
>>>> //(Function == FN0) ? (BlockSize = fdoData->BlockSizeFN0) :
>>>>(BlockSize = fdoData->BlockSizeFNx);
>>>> //status = SdioReadWriteByte(fdo,
>>>>FN0,(PUCHAR)&BlockSize,FN0_BLOCK_SIZE_REG,FALSE);
>>>>
>>>> //just for testing, make sure that the same is written in
>>>>FN0_BLOCK_SIZE_REG before running this
>>>> BlockSize = 0x04;
>>>> SdioDbgPrint(TRACE,"\nBlksize 0x%X\n",BlockSize);
>>>>
>>>> //Round of the length to the block size
>>>> if(Length % BlockSize)
>>>> len = (((Length / BlockSize) * BlockSize) + BlockSize);
>>>> else
>>>> len = ((Length / BlockSize) * BlockSize);
>>>> }
>>>>
>>>> SdioDbgPrint(TRACE,"Calc len 0x%X\n",len);
>>>> pBuf = ExAllocatePool(NonPagedPool,len);
>>>> if (!pBuf) {
>>>> return STATUS_INSUFFICIENT_RESOURCES;
>>>> }
>>>>
>>>> RtlZeroMemory(pBuf, len);
>>>> if (WriteToDevice)
>>>> RtlCopyMemory(pBuf,PBuffer, Length);
>>>> // first, get an MDL to map the data. Call IoAllocateMdl to
>>>> // allocate an MDL and pass in a pointer to a buffer
>>>> // allocated from the non-paged pool.
>>>> Mdl = IoAllocateMdl(pBuf, len, FALSE, FALSE, NULL);
>>>> if (Mdl == NULL) {
>>>>
>>>> ExFreePool(pBuf);
>>>> return STATUS_INSUFFICIENT_RESOURCES;
>>>> }
>>>>
>>>> MmBuildMdlForNonPagedPool (Mdl);
>>>> // next, allocate a request packet for the arguments of the command
>>>> sdrp = ExAllocatePool(NonPagedPool, sizeof(SDBUS_REQUEST_PACKET));
>>>> if (!sdrp) {
>>>> IoFreeMdl(Mdl);
>>>> return STATUS_INSUFFICIENT_RESOURCES;
>>>> }
>>>> RtlZeroMemory(sdrp, sizeof(SDBUS_REQUEST_PACKET));
>>>> sdrp->RequestFunction = SDRF_DEVICE_COMMAND;
>>>> extendedArgument.u.AsULONG = 0;
>>>> if(BlockMode == BYTE_MODE)
>>>> {
>>>> extendedArgument.u.bits.BlockMode = 0;
>>>> extendedArgument.u.bits.Count = len;
>>>> }
>>>> else
>>>> {
>>>> extendedArgument.u.bits.BlockMode = 1;
>>>> extendedArgument.u.bits.Count = len / BlockSize;
>>>> }
>>>> SdioDbgPrint(TRACE,"cmd53:set Count %d, blkmode
>>>>%d\n",extendedArgument.u.bits.Count,
>>>> extendedArgument.u.bits.BlockMode);
>>>> extendedArgument.u.bits.Function = Function;
>>>> extendedArgument.u.bits.OpCode = 1; // increment address
>>>> extendedArgument.u.bits.Address = Address;
>>>>
>>>> if (WriteToDevice) {
>>>> extendedArgument.u.bits.WriteToDevice = 1;
>>>> sdrp->Parameters.DeviceCommand.CmdDesc = WriteIoExtendedDesc;
>>>>
>>>> } else {
>>>> extendedArgument.u.bits.WriteToDevice = 0;
>>>> sdrp->Parameters.DeviceCommand.CmdDesc = ReadIoExtendedDesc;
>>>> }
>>>> sdrp->Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG;
>>>> sdrp->Parameters.DeviceCommand.Mdl = Mdl;
>>>>
>>>> //This send the Block Count in CMD3 as the blocksize * num of block
>>>>and
>>>> //makes the system crash - BSOD
>>>> //sdrp->Parameters.DeviceCommand.Length = len;
>>>>
>>>> //With this the SdBusSubmitRequest returns 0xc0000185 status and
>>>> //the Block count in CMD53 gets the actual byte read/write length
>>>> //sdrp->Parameters.DeviceCommand.Length = Length;
>>>>
>>>> //This send the Block Count in CMD3 as proper block count, but still
>>>>the
>>>> //bus drivers gives status as 0xc0000185 or 0x80000011
>>>> sdrp->Parameters.DeviceCommand.Length =
>>>>extendedArgument.u.bits.Count; //len;
>>>>
>>>>
>>>> // finally, submit the request
>>>> status = SdBusSubmitRequest(fdoData->SDBusInterface.Context,sdrp);
>>>>
>>>> SdioDbgPrint(TRACE,"cmd53: resplen: %d\n",sdrp->ResponseLength);
>>>> SdioDbgPrint(TRACE,"cmd53: sts: %X \n",status);
>>>> SdioDbgPrint(TRACE,"cmd53: info: %X\n",sdrp->Information);
>>>>
>>>> if (NT_SUCCESS(status) && !WriteToDevice) {
>>>>
>>>> *BytesRead = Length;
>>>> RtlCopyMemory(PBuffer, pBuf, Length);
>>>> }
>>>> IoFreeMdl(Mdl);
>>>> ExFreePool(pBuf);
>>>> ExFreePool(sdrp);
>>>> return status;
>>>>}
>>>>----------------------------------
>>>
>>>
>

Re: Is cmd53 tested with sdbus driver in XP, SP2 for block mode ? by David

David
Fri Jun 23 14:09:56 CDT 2006

Hello Esha,

I too have attempted to use SDIO block mode with Windows XP SP2 and I
too reached the same conclusion. The SDBus driver appears to be broken
with respect to
block mode. In particular I could find no way to specify a number of
blocks. All attempts to do so resulted in the block count being used as
the length field in XP.

I have captured this sequence on a scope so I am pretty convinced that
this is the case.
When using "EXTENDED" mode the resultant waveforms were exactly as if
the host was sending a CMD52 operation except that the command code was
53 rather than 52.

In the end I simply had to reach the conclusion that Windows XP just
does not support SDIO block mode. However I should point out that I
have not received any official confirmation of this from Microsoft.

Best Regards,
David
Eshanye_kp wrote:
> I have set the FN0 block size (0x10 in cccr) and FN1 block size (0x110
> in FBR) for 4 bytes.. also, i'm trying to read 8 bytes from 0x00 offset
> of CCCR using CMD53. I have a memory which i can access using some
> registers at the address range 0xF0 -0xFF (FN0 vendor specific), which
> i'm trying to write using CMD53 (so essentially i'm using function FN0
> for my operations).. can i access FN0 stuffs with CMD53 ?, I do not have
> the CSA or CIS for function 1 at this point of development (Even CSA is
> not there for FN0). The other options is to read CIS of FN0, which is
> also giving me the same result when used with CMD53 block mode. (All
> these are with FN0)
>
> Now the same memory can be accessed using a FN1 register also, so i
> tried cmd53 block mode to write and read the same memory using this FN1
> register, but the result is same.
>
> Note: CMD53 byte mode (block mode =0) is working fine because it expects
> the number of bytes to read in place of block count which is what the
> bus driver is doing always..
>
> Do you have any more idea's for me to check ?
>
> -Esha
>
>
> QuasiCodo wrote:
> > Another possibility is that you are not setting the block size registers in
> > the FBR before you submit the CMD53 to SDBUS. What I did was use CMD52's to
> > write to the block size registers. Are you doing this, too?
> >
> > ((&->
> >
> > "Eshanye_kp" <esha@procsys.com> wrote in message
> > news:4498DF68.7030301@procsys.com...
> >
> >>Thanks for the response, Quasi... but as you have pointed out i'm updating
> >>the parameters of extended_argument with block mode, address, Opcode, and
> >>the block count etc and then putting that in the sdrp structure, like...
> >>
> >>extendedArgument.u.AsULONG = 0;
> >>
> >>extendedArgument.u.bits.Function = Function;
> >>extendedArgument.u.bits.OpCode = 1; // increment address
> >>extendedArgument.u.bits.Address = Address;
> >>extendedArgument.u.bits.Count = len / BlockSize;
> >>extendedArgument.u.bits.WriteToDevice = 1;
> >>
> >>sdrp->Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG;
> >>
> >>Also, note that in the descriptor i'm using SDTT_MULTI_BLOCK and SDRT_5
> >>instead of SDTT_MULTI_BLOCK and SDRT_1 as given in the ddk example....
> >>
> >>I found that the bus driver is replacing the block count in the CMD53 with
> >>the MDL length i sent in sdrp->Parameters.DeviceCommand.Length.....
> >>
> >>Could you please send me the code segment of the implementation for CMD53
> >>which you made it work... also could you tell me on which platform your
> >>sdio driver was supported ? I'm running on XP SP2 and compiling the driver
> >>in 2003SP1 ddk (3790.1830)
> >>
> >>Please help.
> >>Esha
> >>
> >>
> >>QuasiCodo wrote:
> >>
> >>
> >>>A couple of months ago, I was developing an SDIO driver for XP SP2 and I
> >>>believe we had CMD53 block mode working. I think your problem is setting
> >>>SD_RW_EXTENDED_ARGUMENT to 0. I seem to remember there are parameters
> >>>that are needed. If you look at the source in the example from MS:
> >>>
> >>>excerpt from
> >>>http://msdn.microsoft.com/library/en-us/Buses_d/hh/Buses_d/securedigital_dg_97e9062d-965e-46bd-a399-7cd60bf932fa.xml.asp
> >>>
> >>>// then, set up the argument and command descriptor
> >>>sdIoArgument.u.AsULONG = 0; // <---- INITIALIZATION ONLY
> >>>sdIoArgument.u.bits.Address = Offset;
> >>>
> >>>// retrieve function number, the driver previously initialized
> >>>// this value with the SdBus GetProperty call
> >>>sdIoArgument.u.bits.Function = pDevExt->FunctionNumber;
> >>>sdIoArgument.u.bits.WriteToDevice = 1;
> >>>
> >>>sdrp->Parameters.DeviceCommand.Argument =
> >>> sdIoArgument.u.AsULONG;
> >>>
> >>>Setting the ext args to 0 is only initializing the variable. Notice that
> >>>for simplicity, the ext args is really a separate local variable, which
> >>>is setup and then transferred into the sdrp structure. Within the ext
> >>>args, you should set the Function, Address, WriteToDevice and other
> >>>fields. Then the separate ext arg variable is then transferred into
> >>>sdrp->Parameters.DeviceCommand.Argument member.
> >>>
> >>>I hope this helps
> >>>
> >>>((&->
> >>>
> >>>
> >>>"Eshanye_kp" <esha@procsys.com> wrote in message
> >>>news:%23jDRP6ClGHA.1244@TK2MSFTNGP05.phx.gbl...
> >>>
> >>>
> >>>>Hi,
> >>>>I'm doing sdio driver on XP SP2. This SDIO driver is compiled using 2003
> >>>>SP1 ddk. SDIO card is coming up properly and i could do several
> >>>>operations using CMD52 (read/write etc). I have not enabled the
> >>>>interrupts yet. Now, i'm trying the CMD53. CMD53 works fine in byte mode.
> >>>>That is BlockMode in SD_RW_EXTENDED_ARGUMENT is set to 0 and the
> >>>>parameters in SDCMD_DESCRIPTOR set to SDTT_SINGLE_BLOCK and SDRT_5.
> >>>>
> >>>>But when i try the SDTT_MULTI_BLOCK mode, the command sent on the bus is
> >>>>not proper. I captured the CMD53 on the bus using LA, and this is what i
> >>>>found.
> >>>>
> >>>>My block size set was 4 bytes. I was trying to read/write 8 bytes so that
> >>>>two blocks of transaction should happen. But all the time, the CMD53 on
> >>>>the bus had 8 as Block Count. After i did some different exercise, i
> >>>>found that the Parameters.DeviceCommand.Length is sent as block count for
> >>>>CMD53 instead of .u.bits.Count in SD_RW_EXTENDED_ARGUMENT. (I made sure
> >>>>that the Block Mode in SD_RW_EXTENDED_ARGUMENT is set to 1 so that even
> >>>>on the bus i see the same for cmd53. I do not see any response from the
> >>>>SDIO card for this and also, the bus driver is returning back,
> >>>>0xC0000185 or 0x80000011..
> >>>>My sdio card supports block mode (the card capability reg- 0x08 of cccr
> >>>>reads 0x1F .....)
> >>>>
> >>>>Is the bus driver in XP SP2 tested with CMD53 block mode (or
> >>>>SDTT_MULTI_BLOCK) ?
> >>>>I have attached the CMD53 function i've written, along with this mail...
> >>>>Please let me know if there is any problem.
> >>>>
> >>>>Eliyas, please help !
> >>>>
> >>>>Rgds
> >>>>Esha
> >>>>------------------------------------
> >>>>NTSTATUS
> >>>>SdioReadWriteBuffer(PDEVICE_OBJECT fdo,IN ULONG Function,IN PUCHAR
> >>>>PBuffer,IN ULONG Address,
> >>>>IN UCHAR BlockMode,IN ULONG Length,IN BOOLEAN WriteToDevice,OUT PULONG
> >>>>BytesRead)
> >>>>{
> >>>> PFDO_DATA fdoData;
> >>>> PSDBUS_REQUEST_PACKET sdrp;
> >>>> SD_RW_EXTENDED_ARGUMENT extendedArgument;
> >>>> NTSTATUS status = STATUS_SUCCESS;
> >>>> PMDL Mdl=NULL;
> >>>> UCHAR i;
> >>>> PUCHAR pBuf=NULL;
> >>>> ULONG BlockSize=0;
> >>>> ULONG len = Length;
> >>>> ULONG Data=0;
> >>>>
> >>>> SDCMD_DESCRIPTOR ReadIoExtendedDesc =
> >>>> {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
> >>>>SDTT_MULTI_BLOCK , SDRT_5};
> >>>> //{SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_READ,
> >>>>SDTT_MULTI_BLOCK , SDRT_1};
> >>>>
> >>>> SDCMD_DESCRIPTOR WriteIoExtendedDesc =
> >>>> {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD,SDTD_WRITE,
> >>>>SDTT_MULTI_BLOCK , SDRT_5};
> >>>>
> >>>> fdoData = (PFDO_DATA)fdo->DeviceExtension;
> >>>>
> >>>> SdioDbgPrint(TRACE,"cmd53: fn %d len %d,add 0x%X blkmode %d WrRd
> >>>>%d\n",Function,
> >>>> Length,Address,BlockMode,WriteToDevice);
> >>>> if(BlockMode == BYTE_MODE)
> >>>> {
> >>>> ReadIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
> >>>> WriteIoExtendedDesc.TransferType = SDTT_SINGLE_BLOCK;
> >>>> //len = BlockSize;
> >>>> len = Length;
> >>>> }
> >>>> else
> >>>> {
> >>>> //(Function == FN0) ? (BlockSize = fdoData->BlockSizeFN0) :
> >>>>(BlockSize = fdoData->BlockSizeFNx);
> >>>> //status = SdioReadWriteByte(fdo,
> >>>>FN0,(PUCHAR)&BlockSize,FN0_BLOCK_SIZE_REG,FALSE);
> >>>>
> >>>> //just for testing, make sure that the same is written in
> >>>>FN0_BLOCK_SIZE_REG before running this
> >>>> BlockSize = 0x04;
> >>>> SdioDbgPrint(TRACE,"\nBlksize 0x%X\n",BlockSize);
> >>>>
> >>>> //Round of the length to the block size
> >>>> if(Length % BlockSize)
> >>>> len = (((Length / BlockSize) * BlockSize) + BlockSize);
> >>>> else
> >>>> len = ((Length / BlockSize) * BlockSize);
> >>>> }
> >>>>
> >>>> SdioDbgPrint(TRACE,"Calc len 0x%X\n",len);
> >>>> pBuf = ExAllocatePool(NonPagedPool,len);
> >>>> if (!pBuf) {
> >>>> return STATUS_INSUFFICIENT_RESOURCES;
> >>>> }
> >>>>
> >>>> RtlZeroMemory(pBuf, len);
> >>>> if (WriteToDevice)
> >>>> RtlCopyMemory(pBuf,PBuffer, Length);
> >>>> // first, get an MDL to map the data. Call IoAllocateMdl to
> >>>> // allocate an MDL and pass in a pointer to a buffer
> >>>> // allocated from the non-paged pool.
> >>>> Mdl = IoAllocateMdl(pBuf, len, FALSE, FALSE, NULL);
> >>>> if (Mdl == NULL) {
> >>>>
> >>>> ExFreePool(pBuf);
> >>>> return STATUS_INSUFFICIENT_RESOURCES;
> >>>> }
> >>>>
> >>>> MmBuildMdlForNonPagedPool (Mdl);
> >>>> // next, allocate a request packet for the arguments of the command
> >>>> sdrp = ExAllocatePool(NonPagedPool, sizeof(SDBUS_REQUEST_PACKET));
> >>>> if (!sdrp) {
> >>>> IoFreeMdl(Mdl);
> >>>> return STATUS_INSUFFICIENT_RESOURCES;
> >>>> }
> >>>> RtlZeroMemory(sdrp, sizeof(SDBUS_REQUEST_PACKET));
> >>>> sdrp->RequestFunction = SDRF_DEVICE_COMMAND;
> >>>> extendedArgument.u.AsULONG = 0;
> >>>> if(BlockMode == BYTE_MODE)
> >>>> {
> >>>> extendedArgument.u.bits.BlockMode = 0;
> >>>> extendedArgument.u.bits.Count = len;
> >>>> }
> >>>> else
> >>>> {
> >>>> extendedArgument.u.bits.BlockMode = 1;
> >>>> extendedArgument.u.bits.Count = len / BlockSize;
> >>>> }
> >>>> SdioDbgPrint(TRACE,"cmd53:set Count %d, blkmode
> >>>>%d\n",extendedArgument.u.bits.Count,
> >>>> extendedArgument.u.bits.BlockMode);
> >>>> extendedArgument.u.bits.Function = Function;
> >>>> extendedArgument.u.bits.OpCode = 1; // increment address
> >>>> extendedArgument.u.bits.Address = Address;
> >>>>
> >>>> if (WriteToDevice) {
> >>>> extendedArgument.u.bits.WriteToDevice = 1;
> >>>> sdrp->Parameters.DeviceCommand.CmdDesc = WriteIoExtendedDesc;
> >>>>
> >>>> } else {
> >>>> extendedArgument.u.bits.WriteToDevice = 0;
> >>>> sdrp->Parameters.DeviceCommand.CmdDesc = ReadIoExtendedDesc;
> >>>> }
> >>>> sdrp->Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG;
> >>>> sdrp->Parameters.DeviceCommand.Mdl = Mdl;
> >>>>
> >>>> //This send the Block Count in CMD3 as the blocksize * num of block
> >>>>and
> >>>> //makes the system crash - BSOD
> >>>> //sdrp->Parameters.DeviceCommand.Length = len;
> >>>>
> >>>> //With this the SdBusSubmitRequest returns 0xc0000185 status and
> >>>> //the Block count in CMD53 gets the actual byte read/write length
> >>>> //sdrp->Parameters.DeviceCommand.Length = Length;
> >>>>
> >>>> //This send the Block Count in CMD3 as proper block count, but still
> >>>>the
> >>>> //bus drivers gives status as 0xc0000185 or 0x80000011
> >>>> sdrp->Parameters.DeviceCommand.Length =
> >>>>extendedArgument.u.bits.Count; //len;
> >>>>
> >>>>
> >>>> // finally, submit the request
> >>>> status = SdBusSubmitRequest(fdoData->SDBusInterface.Context,sdrp);
> >>>>
> >>>> SdioDbgPrint(TRACE,"cmd53: resplen: %d\n",sdrp->ResponseLength);
> >>>> SdioDbgPrint(TRACE,"cmd53: sts: %X \n",status);
> >>>> SdioDbgPrint(TRACE,"cmd53: info: %X\n",sdrp->Information);
> >>>>
> >>>> if (NT_SUCCESS(status) && !WriteToDevice) {
> >>>>
> >>>> *BytesRead = Length;
> >>>> RtlCopyMemory(PBuffer, pBuf, Length);
> >>>> }
> >>>> IoFreeMdl(Mdl);
> >>>> ExFreePool(pBuf);
> >>>> ExFreePool(sdrp);
> >>>> return status;
> >>>>}
> >>>>----------------------------------
> >>>
> >>>
> >


Re: Is cmd53 tested with sdbus driver in XP, SP2 for block mode ? by david

david
Fri Jun 23 14:14:25 CDT 2006

Hello Esha,

I too have attempted to use SDIO block mode with Windows XP SP2 and I
too reached the same conclusion. The SDBus driver appears to be broken
with respect to
block mode. In particular I could find no way to specify a number of
blocks. All attempts to do so resulted in the block count being used as
the length field in XP.

I have captured this sequence on a scope so I am pretty convinced that
this is the case.
When using "EXTENDED" mode the resultant waveforms were exactly as if
the host was sending a CMD52 operation except that the command code was
53 rather than 52.

In the end I simply had to reach the conclusion that Windows XP just
does not support SDIO block mode. However I should point out that I
have not received any official confirmation of this from Microsoft.

Best Regards,
David


Eshanye_kp wrote:
> I have set the FN0 block size (0x10 in cccr) and FN1 block size (0x110
> in FBR) for 4 bytes.. also, i'm trying to read 8 bytes from 0x00 offset
> of CCCR using CMD53. I have a memory which i can access using some
> registers at the address range 0xF0 -0xFF (FN0 vendor specific), which
> i'm trying to write using CMD53 (so essentially i'm using function FN0
> for my operations).. can i access FN0 stuffs with CMD53 ?, I do not have
> the CSA or CIS for function 1 at this point of development (Even CSA is
> not there for FN0). The other options is to read CIS of FN0, which is
> also giving me the same result when used with CMD53 block mode. (All
> these are with FN0)
>
> Now the same memory can be accessed using a FN1 register also, so i
> tried cmd53 block mode to write and read the same memory using this FN1
> register, but the result is same.
>
> Note: CMD53 byte mode (block mode =0) is working fine because it expects
> the number of bytes to read in place of block count which is what the
> bus driver is doing always..
>
> Do you have any more idea's for me to check ?
>
> -Esha
>
>
> QuasiCodo wrote:
> > Another possibility is that you are not setting the block size registers in
> > the FBR before you submit the CMD53 to SDBUS. What I did was use CMD52's to
> > write to the block size registers. Are you doing this, too?
> >
> > ((&->
> >
> > "Eshanye_kp" <esha@procsys.com> wrote in message
> > news:4498DF68.7030301@procsys.com...
> >
> >>Thanks for the response, Quasi... but as you have pointed out i'm updating
> >>the parameters of extended_argument with block mode, address, Opcode, and
> >>the block count etc and then putting that in the sdrp structure, like...
> >>
> >>extendedArgument.u.AsULONG = 0;
> >>
> >>extendedArgument.u.bits.Function = Function;
> >>extendedArgument.u.bits.OpCode = 1; // increment address
> >>extendedArgument.u.bits.Address = Address;
> >>extendedArgument.u.bits.Count = len / BlockSize;
> >>extendedArgument.u.bits.WriteToDevice = 1;
> >>
> >>sdrp->Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG;
> >>
> >>Also, note that in the descr