| 
 Q:  I'm developing a PCI Ethernet driver, and I have two questions about receive
buffer handling: 
	The sample driver uses allocbto create a message block. After a period of time, allocb returns a NULL pointer. How should I handle this situation?How and when is the receive block deallocated? Should my driver handle this, or does something else in the stack handle it? A: 
	If you call allocb to create a message block and the call returns a null pointer, your driver has hit a low memory situation, which means it's time to start discarding packets.The client should deallocate message blocks when  finished. In the case you describe, they are not yet finished.  
In terms of networking services, everyone, including OpenTransport, is a client
to the driver. As packets come in, you need to use allocboresballocto create
the message block to pass along to Open Transport. Once it is passed along, a
client, most likely OpenTransport, processes the packet and releases
(deallocates) the memory for that packet. The esballocroutine may be more suitable for your needs, since you can use
it to allocate DMA memory and to pass along a notifier function that is called
when the client is through using the memory. These are all standard STREAMS
calls documented in Designing Cards and Drivers for PCI. esballocis used primarily to set up a message block for a buffer that is
supplied by the driver (i.e., a DMA buffer). As part of theesballocmessage,
you pass a pointer to afree_rtnstructure, which in turn points to a free
routine.
 On packet receipt, the driver needs to allocate a message block for use in
passing the packet data to it's clients. In this case, it is the clients
responsibility to call freemsg. To allocate a message block, there are two
options:allocbandesballoc. In one case, the memory for the data buffer comes
from the available system memory, while in the case ofesballoc, memory is
allocated for the message block only. It is the responsibility of the driver to
provide the memory from DMA, e.g., for the data. As such, it is useful to
attach afree_rtnparameter so that when the data has been processed, the
driver will know memory is now available for use in processing another message. |