[PATCH] net: phy: ncsi: Correct the endian of the checksum

Jacky Chou jacky_chou at aspeedtech.com
Mon Mar 4 09:59:47 CET 2024


> On Sun, Mar 03, 2024 at 02:14:43AM +0000, Jacky Chou wrote:
> > Hi Dan Carpenter,
> >
> > I have verified it on the little-endian platform, such as ASPEED AST2600.
> 
> Awesome.  Thanks for this.
> 
> > I think put_unaligned_be32() and htonl() functions have no effect on
> big-endian platforms.
> > And keep put_unaligned_be32() to help access the unaligned memory, such
> as pchecksum variable.
> 
> Yes.  I know that.
> 
> What I'm just puzzled by is how we ever merged this code when it doesn't work
> for little endian systems.  How was it tested originally?  How do the errors
> look like?  Perhaps they're not as bad I assume from looking at the code...

I am not sure how it was originally tested.
The first patch was based on Linux NC-SI driver.
I found the code in the Linux kernel where NC-SI calculates the checksum.
	...
	/* Fill with calculated checksum */
	checksum = ncsi_calculate_checksum((unsigned char *)h,
					   sizeof(*h) + nca->payload);
	pchecksum = (__be32 *)((void *)h + sizeof(struct ncsi_pkt_hdr) +
		    ALIGN(nca->payload, 4));
	*pchecksum = htonl(checksum);
	...
It gets the pointer of checksum field and call htonl() to do endian conversion.
Linux NC-IS driver only performs endian conversion.

Thanks,
Jacky


More information about the U-Boot mailing list