Hi

Is it required to call NdisMAllocateMapRegisters before the ndis miniport
calls NdisMAllocateSharedMemory(). (as documented in the ddk)?

Can't the physical address returned by calling NdisMAllocateSharedMemory()
passed to the dma master on the device?

My understanding is - if an Ndis Buffer passed by protocol drivers has to
be mapped directly and passed to the dma master, then a
NdisMStartBufferPhysicalmapping() should be called. To do this, a map
register is required, hence NdisMAllocateMapregisters() should be called
prior to calling NdisMstartBufferPhysixcalmapping().
But if the buffer passed by the protocol driver is copied to a buffer
alloacted using NdisMAllocateSharedMemory(), then NdisMAllocateMapRegister ()
is not required. Please correct me if Im wrong.

basically, What does NdisMAlloacteMapRegisters() do and how and when should
an ndis miniport use it.?

Thanks in Advance,
suu.

Re: Understanding NdisMAllocateMapRegisters by Stephan

Stephan
Wed Feb 01 14:08:01 CST 2006

suu-n-soup wrote:
> Is it required to call NdisMAllocateMapRegisters before the ndis miniport
> calls NdisMAllocateSharedMemory(). (as documented in the ddk)?

Yes, but there is an alternative call, see below.

> Can't the physical address returned by calling NdisMAllocateSharedMemory()
> passed to the dma master on the device?

The 'PhysicalAddress' returned by NdisMAllocateSharedMemory() is
intended to be used for busmaster DMA transfers of the device
associated with the 'MiniportAdapterHandle'.

> My understanding is - if an Ndis Buffer passed by protocol drivers has to
> be mapped directly and passed to the dma master, then a
> NdisMStartBufferPhysicalmapping() should be called. To do this, a map
> register is required, hence NdisMAllocateMapregisters() should be called
> prior to calling NdisMstartBufferPhysixcalmapping().

Correct in principle, but read on...

> But if the buffer passed by the protocol driver is copied to a buffer
> alloacted using NdisMAllocateSharedMemory(), then NdisMAllocateMapRegister ()
> is not required. Please correct me if Im wrong.

Protocol drivers cannot use NdisMAllocateSharedMemory(). Only miniport
drivers can use this function.

Consequently, a physical address must be made available to the
miniport/device for all protocol buffers.

The *old* way of requesting a physical address for a buffer is using
NdisMStartBufferPhysicalMapping(). It still can be done this way, but
is no longer recommended. Note that you would need to allocate quite a
few map registers with NdisMAllocateMapRegisters() during
MiniportInitialize() when using the NdisMStartBufferPhysicalMapping()
method.

The *new* way is to use the scatter/gather facility available in NDIS 5
and higher. Simply call NdisMInitializeScatterGatherDma() instead of
NdisMAllocateMapRegisters() during MiniportInitialize(). Then in
MiniportSend() call
NDIS_PER_PACKET_INFO_FROM_PACKET(ScatterGatherListPacketInfo) to
retrieve the list of physical fragments that make up the complete
NDIS_PACKET.

Always use NdisMAllocateSharedMemory() to allocate the receive buffers
for your busmaster device.

> basically, What does NdisMAlloacteMapRegisters() do and how and when should
> an ndis miniport use it.?

It is all documented in the DDK docs. See the description of the
aforementioned functions there as well as the description of handling
send and receive paths in an NDIS miniport.

http://msdn.microsoft.com/library/
> Win32 and COM Development
> Windows Driver Kit
> Device and Driver Technologies
> Network
> Windows 2000 and Windows XP Networking
> Reference
> NDIS
> NDIS Library Function References

Also see the "Design Guide".

Stephan