Q: I'm developing a PCI Ethernet driver, and I have two questions about receive
The sample driver uses
allocb to 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?
- 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
esballoc to 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.
esballoc routine 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.
esballoc is 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 the
you pass a pointer to a
free_rtn structure, which in turn points to a free
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
esballoc. In one case, the memory for the data buffer comes
from the available system memory, while in the case of
esballoc, 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
free_rtn parameter so that when the data has been processed, the
driver will know memory is now available for use in processing another message.