I am having issues relating to allocating and freeing buffers on the 5272 (using the standard driver code). There is a case in my code where I may allocate a buffer, start to fill it, but then another Ethernet interrupt comes in before it is completed and sent. This could cause me to have to allocate another buffer, for example if the interrupt was caused by an ARP request that I need to respond to. Then, when that interrupt completes, I resume filling the first buffer. If that first buffer is sent out, I have a minor issue, in that the 2 packets are sent out in reverse order and the second interrupt-driven packet (e.g. ARP) has to wait to go out until the first packet is sent. (I noticed that the driver has specific code for dealing with this in the case of ARP requests, but not the general case.) The much worse problem for me is if for some reason the first packet cannot be sent (error condition, destination route cannot be resolved, etc.). Then I would like to de-allocate/free this packet. That's where things get messy. Since another buffer has already been allocated and attempted to be sent, I have a problem with my ring buffer pointer being out of sync with the FEC's own pointer.
It seems that the FEC has its own internal pointer to where it is in the ring buffer. And if my own ring buffer pointer gets out of sync with that, it never recovers. From there on out, nothing goes out until I send 8 packets, then all 8 go out in a burst. (I have 8 buffer descriptors in my ring.) Furthermore, I don't see any way to change or even read the FEC's internal pointer. So detecting/correcting this is difficult. I suppose resetting the FEC would work, though it seems drastic.
Any thoughts on this? Is there any way to handle de-allocating a buffer, especially if another buffer has already been allocated? Or should I try to avoid ever allocating a second buffer before I am finished with the first (could be difficult with the way my code is structured)? Another thought I had was when I want to de-allocate, I still send out a packet, but make it a dummy packet sent to a loopback address or something (how?). I have also considered trying to generalize the buffer swapping code used for ARP requests to handle other cases of multiple buffers being allocated.