lwIP - A Lightweight TCP/IP stack - Tasks: task #16111, Set checksum to zero optimized-out...
You are not allowed to post comments on this tracker with your current authentication level.
task #16111: Set checksum to zero optimized-out in case of using a HW Checksum Block
Submitter: | Zakaria Abu Al-Ailah <zakaria> | ||
Submitted: | Fri 21 Jan 2022 03:02:38 PM UTC | ||
Category: | IPv4 | Should Start On: | Fri 21 Jan 2022 12:00:00 AM UTC |
Should be Finished on: | Mon 31 Jan 2022 12:00:00 AM UTC | Priority: | 9 - Immediate |
Status: | None | Privacy: | Public |
Assigned to: | None | Percent Complete: | 0% |
Open/Closed: | Open | Planned Release: | None |
Effort: | 0.00 |
Sat 22 Jan 2022 08:43:35 PM UTC, comment #2: |
Zakaria Abu Al-Ailah <zakaria> |
Fri 21 Jan 2022 04:26:41 PM UTC, comment #1: Is this from reading the code or do you actually have a problem?
|
Simon Goldschmidt <goldsimon> |
Fri 21 Jan 2022 03:02:38 PM UTC, original submission:
Hi,
|
Zakaria Abu Al-Ailah <zakaria> |
No files currently attached
Depends on the following items: None found
Items that depend on this one: None found
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Follows 1 latest change.
Date | Changed by | Updated Field | Previous Value | => | Replaced by |
---|---|---|---|---|---|
2022-01-21 | zakaria | Carbon-Copy | - | Added -email is unavailable- |
Powered by Savane 3.13-bb6a.
Corresponding source code
Hi Simon,
I hope you are doing well.
Thank you for your prompt reply.
We have been using LwIP for a long time ago, and didn't face a single issue with it.
Actually, we started having this problem after starting to use our own HARDWARE CHECKSUM BLOCK, so the checksum is computed in Hardware in order to speed up the process and get higher throughput.
To do so, we defined 'LWIP_CHKSUM' in 'lwipopts.h' as follows:
#define LWIP_CHKSUM hw_cks
The function 'hw_cks' sets the input parameters ('dataptr' and 'len') in some registers and then starts the HW BLOCK, and when the output gets ready, it reads the checksum from some register and returns it.
In unit testing, the HW BLOCK works 100% properly, but in integration with LwIP, we figured out that ping-replies are sent out with wrong header checksum!
In this case, we checked the disassembly code, and found out that the compiler has completely removed the code of the instruction 'IPH_CHKSUM_SET(iphdr, 0)' (line 236).
That said, the problem is never related to delay storing or something related to the cache.
The compiler is doing so, since the same field '_chksum' is sets twice (line 236 and 239), and this field is not used in software between the two sets, but actually the HW BLOCK will pass on it (in memory) in order to compute the new checksum (for the ping-reply).
We added a dummy instruction inside the function 'hw_cks(const void *dataptr, int len)', e.g.
uint8_t val = ((uint8_t )dataptr + 10); /* read the first byte of '_chksum' */
We then checked the disassembly code, and found that the compiler didn't remove the code of 'IPH_CHKSUM_SET(iphdr, 0)' (in this case, it is aware that this field is used).
We also did a test (receive ping-requests from the host and send ping-replies out) and verified that everything is working fine.
I guess you should add 'volatile' to the field '_chksum', in order to explicitly tell the compiler that this field might be used in hardware.
Note: We are using FTO optimization. It is required in our case.
Regards,
Zakaria