wiznet: lwip: Implement zero-copy for socket buffers. #17447
+342
−46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This is closer to a zero-copy mechanism for the Wiznet chip and LwIP stack. Instead of using a static Ethernet frame buffer, it copies from the device directly into LwIP pbufs and visa versa.
Additionally, it avoids an issue for WIZnet devices:
wiznet5k_poll
method, if the chip indicates there is data available to receive and it is received but no buffer space is available in LwIP, then the packet will be fetched from the device and discarded. Instead, now it will remain on the device until sufficient memory is available in the MCU.Furthermore, it optimizes and simplifies the usage of the WIZnet device based on the particular usage that the MACRAW mode will be used on exactly one socket on the device. It frees 1514 bytes of a static Ethernet frame buffer over the baseline.
Testing
I've tested this pretty extensively on the RP2040 and WIZnet W5100S. Based on interest, I'm happy to test it further on other devices.
Trade-offs and Alternatives
As written, it removes support for the W5200 and W5300 chips- although there is no reference board or firmware in the project for these devices.
However, insourcing a simplified driver could make for a simpler platform to add support for the W6100.
If Ethernet tracing is enabled, when traces are written to the console, if the LwIP pbuf is fragmented, only the first fragment is traced. This is to prevent the need for a copy of the buffer.