Hi:
This patches merges the separate calls to le16_to_cpu and ntohl into one
swab32 call so that it is clear that we're simply changing a little-endian
value from the hardware to big-endian for the networking stack.
Let x be any 16 any 16-bit integer, we have
csum_fold(x << 16) = csum_fold(x).
So on big endian, we have
csum_fold(swab32(x ^ 0xffff)) =
csum_fold(swab16(x ^ 0xffff) << 16) =
csum_fold(swab16(x ^ 0xffff)) =
csum_fold(swab16(x) ^ 0xffff) =
csum_fold(ntohl(swab16(x) ^ 0xffff)) =
csum_fold(ntohl(le16_to_cpu(x) ^ 0xffff))
On little endian we have
csum_fold(swab32(x ^ 0xffff)) =
csum_fold(ntohl(x ^ 0xffff)) =
csum_fold(ntohl(le16_to_cpu(x) ^ 0xffff))
I used swab32 instead of swab16 because 32-bit arithmetic usually generates
better code.
So this should genereate the same code on little-endian, and slightly better
code for big-endian architectures.
Signed-off-by: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 49cd096..10aec70 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -3478,10 +3478,10 @@
} else if (adapter->hw.mac_type > e1000_82547_rev_2) {
/* IP fragment with UDP payload */
/* Hardware complements the payload checksum, so we undo it
- * and then put the value in host order for further stack use.
+ * and then put the value in network order for further stack
+ * use.
*/
- csum = ntohl(csum ^ 0xFFFF);
- skb->csum = csum;
+ skb->csum = swab32(csum ^ 0xffff);
skb->ip_summed = CHECKSUM_HW;
}
adapter->hw_csum_good++;
@@ -3600,7 +3600,7 @@
e1000_rx_checksum(adapter,
(uint32_t)(status) |
((uint32_t)(rx_desc->errors) << 24),
- le16_to_cpu(rx_desc->csum), skb);
+ rx_desc->csum, skb);
skb->protocol = eth_type_trans(skb, netdev);
#ifdef CONFIG_E1000_NAPI
@@ -3773,7 +3773,7 @@
copydone:
e1000_rx_checksum(adapter, staterr,
-
le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
+ rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
skb->protocol = eth_type_trans(skb, netdev);
if (likely(rx_desc->wb.upper.header_status &