Hi Hongzhi, I suggest the following title instead:
net: fix checksum on big endian CPUs On Wed, Jun 24, 2020 at 05:11:19PM +0200, Morten Brørup wrote: > > From: dev [mailto:dev-boun...@dpdk.org] On Behalf Of Thomas Monjalon > > Sent: Wednesday, June 24, 2020 5:04 PM > > > > 24/06/2020 15:00, Morten Brørup: > > > > From: Thomas Monjalon [mailto:tho...@monjalon.net] > > > > Sent: Wednesday, June 24, 2020 2:22 PM > > > > > > > > 27/05/2020 15:40, guohongzhi: > > > > > From: Hongzhi Guo <guohongz...@huawei.com> > > > > > > > > > > __rte_raw_cksum should consider Big Endian. > > > > > > > > We need to explain the logic in the commit log. Here is a suggestion of commit log: With current code, the checksum of odd-length buffers is wrong on big endian CPUs: the last byte is not properly summed to the accumulator. Fix this by left-shifting the remaining byte by 8. For instance, if the last byte is 0x42, we should add 0x4200 to the accumulator on big endian CPUs. This change is similar to what is suggested in Errata 3133 of RFC 1071. Can you please submit a new version with the 2 changes above? > > > > > > Having grown up with big endian CPUs, reading the final byte like > > this is obvious to me. I struggle understanding the little endian way > > of reading the last byte. (Not really anymore, but back when little > > endian was unfamiliar to me I would have struggled.) > > > > > > An RFC (I can't remember which) describes why the same checksum > > calculation code works on both big and little endian CPUs. Is it this > > explanation you are asking for? > > > > This explanation may be interesting. > > > > RFC 1071, especially chapter 3. > > Please note that big endian is considered "Normal" order in the RFC. :-) There is an errata for this RFC about the C code: see https://www.rfc-editor.org/errata/eid3133 > > > > > > > Signed-off-by: Hongzhi Guo <guohongz...@huawei.com> > > > > > --- > > > > > +#if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN) > > > > > + sum += *((const uint8_t *)u16_buf) << 8; > > > > > +#else > > > > > sum += *((const uint8_t *)u16_buf); > > > > > +#endif > > > > > > > > *((const uint8_t *)u16_buf) should be an uint8_t. > > > > What is the expected behaviour of shifting 8 bits of a byte? > > > > > > Yes, the value will be an uint8_t type. But the shift operation will > > cause the compiler to promote the type to int before shifting it. > > > > This is the explanation I was looking for :-) > > > > >