From: Murugesan on
Hi all,

I need to perform DMA for 8 bytes for which i've failed.
I've followed the following sequence.

pMem = MmAllocateContiguousMemory(8, HighAddress)
if((pMem == NULL) || FdoData == NULL)
{
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"pcial_dma_transfer() FAILED pMem || FdoData = NULL\n");
return !STATUS_SUCCESS;
}

pMdl = IoAllocateMdl(pMem , 8, FALSE, TRUE, NULL);

if (pMdl == NULL)
{
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"IoAllocateMdl FAILED\n");
return !STATUS_SUCCESS;
}


DmaDirection = (rw == DMARW_CNL_TO_HOST) ?
WdfDmaDirectionReadFromDevice:
WdfDmaDirectionWriteToDevice;

status = WdfDmaTransactionCreate( FdoData->WdfDmaEnabler,
WDF_NO_OBJECT_ATTRIBUTES,
&dmaTransaction );
if(status == STATUS_SUCCESS)
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionCreate SUCCESS\n");
else
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionCreate ERROR\n");


status = WdfDmaTransactionInitialize(
dmaTransaction,
ProgramDmaFunction,
DmaDirection,
pMdl,
pMem,
length);

if(status == STATUS_SUCCESS)
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionInitialize SUCCESS\n");
else
{
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionInitialize ERROR status=0x%x\n",status);
return status;
}

status = WdfDmaTransactionExecute( dmaTransaction, NULL);

if(status == STATUS_SUCCESS)
{
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionExecute SUCCESS\n");
}
else
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"WdfDmaTransactionExecute ERROR\n");


Where in the ProgramDmaFunction(), i've initiated h/w DMA operations by
fetching the physical address from the input
scatter gather list element, poll for DMA completion interrupt bit &
complete the DMA with wdfdmacompletedfinal & released
the dmatransaction.

After this sequence, when i checked the value of pMem, it remains unchanged
as zero which is not my expected value.

I have the following questions related with it.

1. Can we perform DMA for 8 bytes using dmatransaction ?( I have no other
option of PIO since my h/w design is in such a way, that supports only DMA)
2. What is wrong in the above mentioned sequence ?
3. Is it mandatory to call WdfDmaTransactionDmaCompleted in DPC handler ? [
Right now, i've some problem with the interrupt, so only polling mode is used)
4. I won't initiate DMA on the context of a wdfrequest, so i can't use
WdfDmaTransactionInitializeUsingRequest(), will it be an issue ? [ This is
because all the sample drivers provided by microsoft has used
WdfDmaTransactionInitializeUsingRequest() and DMA has been initiated from
EvtIoQueue dispatched by any WdfRequest.

Thanks in advance,
Murugesan.S
From: eagersh on
On Nov 2, 2:03 pm, Murugesan <Muruge...(a)discussions.microsoft.com>
wrote:
> Hi all,
>
> I need to perform DMA for 8 bytes for which i've failed.
> I've followed the following sequence.
>
>       pMem = MmAllocateContiguousMemory(8, HighAddress)
>       if((pMem == NULL) || FdoData == NULL)
>       {
>             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
>                   "pcial_dma_transfer() FAILED pMem || FdoData = NULL\n");
>             return !STATUS_SUCCESS;
>       }
>
>       pMdl = IoAllocateMdl(pMem , 8, FALSE, TRUE, NULL);
>
>       if (pMdl == NULL)
>       {
>                   TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
>                         "IoAllocateMdl FAILED\n");
>             return !STATUS_SUCCESS;            
>       }
>
>       DmaDirection = (rw == DMARW_CNL_TO_HOST) ?
>             WdfDmaDirectionReadFromDevice:
>             WdfDmaDirectionWriteToDevice;
>
>       status = WdfDmaTransactionCreate( FdoData->WdfDmaEnabler,
>                                       WDF_NO_OBJECT_ATTRIBUTES,
>                                       &dmaTransaction );
>       if(status == STATUS_SUCCESS)
>             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
>             "WdfDmaTransactionCreate SUCCESS\n");
>       else
>             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
>             "WdfDmaTransactionCreate ERROR\n");
>
>       status = WdfDmaTransactionInitialize(
>                                                  dmaTransaction,
>                                                  ProgramDmaFunction,
>                                                  DmaDirection,
>                                                  pMdl,
>                                                  pMem,
>                                                  length);
>
>       if(status == STATUS_SUCCESS)
>             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
>             "WdfDmaTransactionInitialize SUCCESS\n");
>       else
>       {
>             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
>             "WdfDmaTransactionInitialize ERROR status=0x%x\n",status);
>             return status;          
>       }
>
>     status = WdfDmaTransactionExecute( dmaTransaction, NULL);
>
>       if(status == STATUS_SUCCESS)
>       {
>             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
>             "WdfDmaTransactionExecute SUCCESS\n");
>       }
>       else
>             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
>             "WdfDmaTransactionExecute ERROR\n");
>
> Where in the ProgramDmaFunction(), i've initiated h/w DMA operations by
> fetching the physical address from the input
> scatter gather list element, poll for DMA completion interrupt bit &
> complete the DMA with wdfdmacompletedfinal & released
> the dmatransaction.
>
> After this sequence, when i checked the value of pMem, it remains unchanged
> as zero which is not my expected value.
>
> I have the following questions related with it.
>
> 1. Can we perform DMA for 8 bytes using dmatransaction ?( I have no other
> option of PIO since my h/w design is in such a way, that supports only DMA)
> 2. What is wrong in the above mentioned sequence ?
> 3. Is it mandatory to call WdfDmaTransactionDmaCompleted in DPC handler ? [
> Right now, i've some problem with the interrupt, so only polling mode is used)
> 4. I won't initiate DMA on the context of a wdfrequest, so i can't use
> WdfDmaTransactionInitializeUsingRequest(), will it be an issue ? [ This is
> because all the sample drivers provided by microsoft has used
> WdfDmaTransactionInitializeUsingRequest() and DMA has been initiated from
> EvtIoQueue dispatched by any WdfRequest.
>
> Thanks in advance,
> Murugesan.S

You should check in your Hardware Engineer group if DMA engine could
support such small transaction.
It is very inefficient to use DMA for this amount of data. You should
use simple Read/Write PCI operations for such transfer.

Igor Sharovar

From: Murugesan on
Hi Igor,

I am pretty sure that my h/w DMA engine supports such small transaction. I
have a reference driver in linux which does the same operation. As I
mentioned earlier, the h/w has not mapped these buffers into PCI registers.
So I cannot do PCI read/write, performing DMA is the only way as per my h/w
design. I am wondering whether KMDF DMA methodology supports such small
transaction. Also why they haven't provided any sample which performs DMA
using the memory allocated in the same layer ?
Is any thing incorrect in my sequence of DMA operation other than the number
of bytes ?

Murugesan

"eagersh" wrote:

> On Nov 2, 2:03 pm, Murugesan <Muruge...(a)discussions.microsoft.com>
> wrote:
> > Hi all,
> >
> > I need to perform DMA for 8 bytes for which i've failed.
> > I've followed the following sequence.
> >
> > pMem = MmAllocateContiguousMemory(8, HighAddress)
> > if((pMem == NULL) || FdoData == NULL)
> > {
> > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > "pcial_dma_transfer() FAILED pMem || FdoData = NULL\n");
> > return !STATUS_SUCCESS;
> > }
> >
> > pMdl = IoAllocateMdl(pMem , 8, FALSE, TRUE, NULL);
> >
> > if (pMdl == NULL)
> > {
> > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > "IoAllocateMdl FAILED\n");
> > return !STATUS_SUCCESS;
> > }
> >
> > DmaDirection = (rw == DMARW_CNL_TO_HOST) ?
> > WdfDmaDirectionReadFromDevice:
> > WdfDmaDirectionWriteToDevice;
> >
> > status = WdfDmaTransactionCreate( FdoData->WdfDmaEnabler,
> > WDF_NO_OBJECT_ATTRIBUTES,
> > &dmaTransaction );
> > if(status == STATUS_SUCCESS)
> > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > "WdfDmaTransactionCreate SUCCESS\n");
> > else
> > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > "WdfDmaTransactionCreate ERROR\n");
> >
> > status = WdfDmaTransactionInitialize(
> > dmaTransaction,
> > ProgramDmaFunction,
> > DmaDirection,
> > pMdl,
> > pMem,
> > length);
> >
> > if(status == STATUS_SUCCESS)
> > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > "WdfDmaTransactionInitialize SUCCESS\n");
> > else
> > {
> > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > "WdfDmaTransactionInitialize ERROR status=0x%x\n",status);
> > return status;
> > }
> >
> > status = WdfDmaTransactionExecute( dmaTransaction, NULL);
> >
> > if(status == STATUS_SUCCESS)
> > {
> > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > "WdfDmaTransactionExecute SUCCESS\n");
> > }
> > else
> > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > "WdfDmaTransactionExecute ERROR\n");
> >
> > Where in the ProgramDmaFunction(), i've initiated h/w DMA operations by
> > fetching the physical address from the input
> > scatter gather list element, poll for DMA completion interrupt bit &
> > complete the DMA with wdfdmacompletedfinal & released
> > the dmatransaction.
> >
> > After this sequence, when i checked the value of pMem, it remains unchanged
> > as zero which is not my expected value.
> >
> > I have the following questions related with it.
> >
> > 1. Can we perform DMA for 8 bytes using dmatransaction ?( I have no other
> > option of PIO since my h/w design is in such a way, that supports only DMA)
> > 2. What is wrong in the above mentioned sequence ?
> > 3. Is it mandatory to call WdfDmaTransactionDmaCompleted in DPC handler ? [
> > Right now, i've some problem with the interrupt, so only polling mode is used)
> > 4. I won't initiate DMA on the context of a wdfrequest, so i can't use
> > WdfDmaTransactionInitializeUsingRequest(), will it be an issue ? [ This is
> > because all the sample drivers provided by microsoft has used
> > WdfDmaTransactionInitializeUsingRequest() and DMA has been initiated from
> > EvtIoQueue dispatched by any WdfRequest.
> >
> > Thanks in advance,
> > Murugesan.S
>
> You should check in your Hardware Engineer group if DMA engine could
> support such small transaction.
> It is very inefficient to use DMA for this amount of data. You should
> use simple Read/Write PCI operations for such transfer.
>
> Igor Sharovar
>
> .
>
From: eagersh on
On Nov 10, 11:37 pm, Murugesan <Muruge...(a)discussions.microsoft.com>
wrote:
> Hi Igor,
>
>  I am pretty sure that my h/w DMA engine supports such small transaction. I
> have a reference driver in linux which does the same operation. As I
> mentioned earlier, the h/w has not mapped these buffers into PCI registers.
> So I cannot do PCI read/write, performing DMA is the only way as per my h/w
> design. I am wondering whether KMDF DMA methodology supports such small
> transaction. Also why they haven't provided any sample which performs DMA
> using the memory allocated in the same layer ?
> Is any thing incorrect in my sequence of DMA operation other than the number
> of bytes ?
>
> Murugesan
>
> "eagersh" wrote:
> > On Nov 2, 2:03 pm, Murugesan <Muruge...(a)discussions.microsoft.com>
> > wrote:
> > > Hi all,
>
> > > I need to perform DMA for 8 bytes for which i've failed.
> > > I've followed the following sequence.
>
> > >       pMem = MmAllocateContiguousMemory(8, HighAddress)
> > >       if((pMem == NULL) || FdoData == NULL)
> > >       {
> > >             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > >                   "pcial_dma_transfer() FAILED pMem || FdoData = NULL\n");
> > >             return !STATUS_SUCCESS;
> > >       }
>
> > >       pMdl = IoAllocateMdl(pMem , 8, FALSE, TRUE, NULL);
>
> > >       if (pMdl == NULL)
> > >       {
> > >                   TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > >                         "IoAllocateMdl FAILED\n");
> > >             return !STATUS_SUCCESS;            
> > >       }
>
> > >       DmaDirection = (rw == DMARW_CNL_TO_HOST) ?
> > >             WdfDmaDirectionReadFromDevice:
> > >             WdfDmaDirectionWriteToDevice;
>
> > >       status = WdfDmaTransactionCreate( FdoData->WdfDmaEnabler,
> > >                                       WDF_NO_OBJECT_ATTRIBUTES,
> > >                                       &dmaTransaction );
> > >       if(status == STATUS_SUCCESS)
> > >             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > >             "WdfDmaTransactionCreate SUCCESS\n");
> > >       else
> > >             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > >             "WdfDmaTransactionCreate ERROR\n");
>
> > >       status = WdfDmaTransactionInitialize(
> > >                                                  dmaTransaction,
> > >                                                  ProgramDmaFunction,
> > >                                                  DmaDirection,
> > >                                                  pMdl,
> > >                                                  pMem,
> > >                                                  length);
>
> > >       if(status == STATUS_SUCCESS)
> > >             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > >             "WdfDmaTransactionInitialize SUCCESS\n");
> > >       else
> > >       {
> > >             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > >             "WdfDmaTransactionInitialize ERROR status=0x%x\n",status);
> > >             return status;          
> > >       }
>
> > >     status = WdfDmaTransactionExecute( dmaTransaction, NULL);
>
> > >       if(status == STATUS_SUCCESS)
> > >       {
> > >             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > >             "WdfDmaTransactionExecute SUCCESS\n");
> > >       }
> > >       else
> > >             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > >             "WdfDmaTransactionExecute ERROR\n");
>
> > > Where in the ProgramDmaFunction(), i've initiated h/w DMA operations by
> > > fetching the physical address from the input
> > > scatter gather list element, poll for DMA completion interrupt bit &
> > > complete the DMA with wdfdmacompletedfinal & released
> > > the dmatransaction.
>
> > > After this sequence, when i checked the value of pMem, it remains unchanged
> > > as zero which is not my expected value.
>
> > > I have the following questions related with it.
>
> > > 1. Can we perform DMA for 8 bytes using dmatransaction ?( I have no other
> > > option of PIO since my h/w design is in such a way, that supports only DMA)
> > > 2. What is wrong in the above mentioned sequence ?
> > > 3. Is it mandatory to call WdfDmaTransactionDmaCompleted in DPC handler ? [
> > > Right now, i've some problem with the interrupt, so only polling mode is used)
> > > 4. I won't initiate DMA on the context of a wdfrequest, so i can't use
> > > WdfDmaTransactionInitializeUsingRequest(), will it be an issue ? [ This is
> > > because all the sample drivers provided by microsoft has used
> > > WdfDmaTransactionInitializeUsingRequest() and DMA has been initiated from
> > > EvtIoQueue dispatched by any WdfRequest.
>
> > > Thanks in advance,
> > > Murugesan.S
>
> > You should check in your Hardware Engineer group if DMA engine could
> > support such small transaction.
> > It is very inefficient to use DMA for this amount of data. You should
> > use simple Read/Write PCI operations for such transfer.
>
> > Igor Sharovar
>
> > .

If you hardware does not support Read/Write PCI transactions how could
you control DMA operation? You need at least access to DMA registers
of the device. And you could do it only through PCI Read/Write.
Do I miss something?

Igor Sharovar
From: Murugesan on
Sorry Igor, my information might be unclear.I doesn't mean like that. We have
a separate core which follows a vendor specific protocol. Some registers are
there to control this core which is in a separate memory in the h/w & can be
read/write only by using DMA.
We have some registers mapped from PCI space separately which includes DMA
ADDR registers, DMA Control registers. The registers to control the core are
not mapped to PCI space, so slave access to these registers are not possible.
Core regiser read/write can only done through DMA. Now my question is does
framework supports to perform DMA for such
small length?

Murugesan

agersh" wrote:

> On Nov 10, 11:37 pm, Murugesan <Muruge...(a)discussions.microsoft.com>
> wrote:
> > Hi Igor,
> >
> > I am pretty sure that my h/w DMA engine supports such small transaction. I
> > have a reference driver in linux which does the same operation. As I
> > mentioned earlier, the h/w has not mapped these buffers into PCI registers.
> > So I cannot do PCI read/write, performing DMA is the only way as per my h/w
> > design. I am wondering whether KMDF DMA methodology supports such small
> > transaction. Also why they haven't provided any sample which performs DMA
> > using the memory allocated in the same layer ?
> > Is any thing incorrect in my sequence of DMA operation other than the number
> > of bytes ?
> >
> > Murugesan
> >
> > "eagersh" wrote:
> > > On Nov 2, 2:03 pm, Murugesan <Muruge...(a)discussions.microsoft.com>
> > > wrote:
> > > > Hi all,
> >
> > > > I need to perform DMA for 8 bytes for which i've failed.
> > > > I've followed the following sequence.
> >
> > > > pMem = MmAllocateContiguousMemory(8, HighAddress)
> > > > if((pMem == NULL) || FdoData == NULL)
> > > > {
> > > > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > > > "pcial_dma_transfer() FAILED pMem || FdoData = NULL\n");
> > > > return !STATUS_SUCCESS;
> > > > }
> >
> > > > pMdl = IoAllocateMdl(pMem , 8, FALSE, TRUE, NULL);
> >
> > > > if (pMdl == NULL)
> > > > {
> > > > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > > > "IoAllocateMdl FAILED\n");
> > > > return !STATUS_SUCCESS;
> > > > }
> >
> > > > DmaDirection = (rw == DMARW_CNL_TO_HOST) ?
> > > > WdfDmaDirectionReadFromDevice:
> > > > WdfDmaDirectionWriteToDevice;
> >
> > > > status = WdfDmaTransactionCreate( FdoData->WdfDmaEnabler,
> > > > WDF_NO_OBJECT_ATTRIBUTES,
> > > > &dmaTransaction );
> > > > if(status == STATUS_SUCCESS)
> > > > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > > > "WdfDmaTransactionCreate SUCCESS\n");
> > > > else
> > > > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > > > "WdfDmaTransactionCreate ERROR\n");
> >
> > > > status = WdfDmaTransactionInitialize(
> > > > dmaTransaction,
> > > > ProgramDmaFunction,
> > > > DmaDirection,
> > > > pMdl,
> > > > pMem,
> > > > length);
> >
> > > > if(status == STATUS_SUCCESS)
> > > > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > > > "WdfDmaTransactionInitialize SUCCESS\n");
> > > > else
> > > > {
> > > > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > > > "WdfDmaTransactionInitialize ERROR status=0x%x\n",status);
> > > > return status;
> > > > }
> >
> > > > status = WdfDmaTransactionExecute( dmaTransaction, NULL);
> >
> > > > if(status == STATUS_SUCCESS)
> > > > {
> > > > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > > > "WdfDmaTransactionExecute SUCCESS\n");
> > > > }
> > > > else
> > > > TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
> > > > "WdfDmaTransactionExecute ERROR\n");
> >
> > > > Where in the ProgramDmaFunction(), i've initiated h/w DMA operations by
> > > > fetching the physical address from the input
> > > > scatter gather list element, poll for DMA completion interrupt bit &
> > > > complete the DMA with wdfdmacompletedfinal & released
> > > > the dmatransaction.
> >
> > > > After this sequence, when i checked the value of pMem, it remains unchanged
> > > > as zero which is not my expected value.
> >
> > > > I have the following questions related with it.
> >
> > > > 1. Can we perform DMA for 8 bytes using dmatransaction ?( I have no other
> > > > option of PIO since my h/w design is in such a way, that supports only DMA)
> > > > 2. What is wrong in the above mentioned sequence ?
> > > > 3. Is it mandatory to call WdfDmaTransactionDmaCompleted in DPC handler ? [
> > > > Right now, i've some problem with the interrupt, so only polling mode is used)
> > > > 4. I won't initiate DMA on the context of a wdfrequest, so i can't use
> > > > WdfDmaTransactionInitializeUsingRequest(), will it be an issue ? [ This is
> > > > because all the sample drivers provided by microsoft has used
> > > > WdfDmaTransactionInitializeUsingRequest() and DMA has been initiated from
> > > > EvtIoQueue dispatched by any WdfRequest.
> >
> > > > Thanks in advance,
> > > > Murugesan.S
> >
> > > You should check in your Hardware Engineer group if DMA engine could
> > > support such small transaction.
> > > It is very inefficient to use DMA for this amount of data. You should
> > > use simple Read/Write PCI operations for such transfer.
> >
> > > Igor Sharovar
> >
> > > .
>
> If you hardware does not support Read/Write PCI transactions how could
> you control DMA operation? You need at least access to DMA registers
> of the device. And you could do it only through PCI Read/Write.
> Do I miss something?
>
> Igor Sharovar
> .
>