Thinking in OOP that function would be a method of the descriptor not of the driver, if it cannot be avoided then I would add a member to the descriptor.
Yes, with the added benefit of not changing the existing API. Also, if both MACDriver and MACReceiveDescriptor had to be passed to mac_lld_release_receive_descriptor, the lwipthread layer would still have to encapsulate both of them together and tie to the pbuf chain.
Though conceptually a call to mac_lld_release_receive_descriptor doesn't make sense outside of a MAC driver context.
This is purely a conceptual construct, you can see as well the descriptor as the object that encapsulates everything related to a frame, including buffers.
Well, I was thinking actually more along the lines of wasted memory. Just a few bytes per frame, so I'm probably being paranoid because I'm having trouble with the available SRAM in my application.
Agreed, this pool can be implemented in lwupthread, there is no need for the driver to handle the pool so it does not impact us in this moment.
I though of a way to not have to use a separate pool for those structs, but I'm sure you won't like it (neither I do much): use a #define to make mac_lld reserve some padding space at the beginning of each buffer. Data would beging after this padding. Then lwipthread would place the custom pbuf structure there. An #if in lwipthread would be needed to make sure the padding space is at least as large as the custom pbuf struct.
I agree, we need a mechanism to associate a callback only to the last element of a pbuf chain and release the descriptor there.
That is not a problem: set the PBUF_FLAG_IS_CUSTOM only for the last pbuf in the chain. The callback will be called by pbuf_free only for that particular pbuf. In fact, you could also use the first pbuf, doesn't really matter.
Handling buffers one by one is not really necessary, it is just how lwIP does things.
Yep, but to be totally honest, I'm with jcbarlow here. lwIP may not be perfect, but works quite well, is very mature and writing a new TCP/IP stack from scratch is an enormous task, so making Chibi/OS [b]just a bit[/b] dependant on how lwIP handles buffers is not such a bad thing.
And most importantly, I'll insist that I don't see a conceptual problem with the individual buffers becoming independent objects once they are read with mac_lld_get_next_receive_buffer. There can be just a mac_lld_release_receive_buffer function taking as argument ONLY the buffer address. Any other information that mac_lld driver needs to properly dispose of or recycle this memory can be stored in a special, internal header located before the buffer and that is easily accessible by just substracting an offset.
I'm definitely going to implement zero-copy with this approach and see how it goes, then once it's complete and tested you can evaluate whether merge it into trunk as is. Remember: it imposes no restrictions on the existing drivers: they can remain as they are now as long as they stick to non-zero-copy.
I think you should finish it and then offer it as an alternative implementation, this is why I think it should be a drop-in replacement for the current implementation. If somebody want the functionality it must be as simple as replacing the files, everything else should be transparent.
So far I think it would require to replace mac_lld.c, mac_lld.h and lwipthread.c. It will require also IP_FRAG enabled in lwipopts.h (though with a tiny patch to lwIP we could allow enabling the custom pbufs in lwipopts.h without having to enable IP_FRAG too).