Title: [7671] trunk/drivers/net/bfin_mac.c: Task[#5621] Deduce Ethernet FCS from hardware IP payload checksum.
- Revision
- 7671
- Author
- sonicz
- Date
- 2009-10-19 05:00:10 -0400 (Mon, 19 Oct 2009)
Log Message
Task[#5621] Deduce Ethernet FCS from hardware IP payload checksum.
IP checksum is based on 16-bit one's complement algorithm.
To deduce a value from checksum is equal to add its complement.
Modified Paths
Diff
Modified: trunk/drivers/net/bfin_mac.c (7670 => 7671)
--- trunk/drivers/net/bfin_mac.c 2009-10-19 08:57:16 UTC (rev 7670)
+++ trunk/drivers/net/bfin_mac.c 2009-10-19 09:00:10 UTC (rev 7671)
@@ -997,11 +997,17 @@
return NETDEV_TX_OK;
}
+#define ETH_FCS_LENGTH 4
+
static void bfin_mac_rx(struct net_device *dev)
{
struct sk_buff *skb, *new_skb;
unsigned short len;
struct bfin_mac_local *lp __maybe_unused = netdev_priv(dev);
+#if defined(BFIN_MAC_CSUM_OFFLOAD)
+ unsigned int i;
+ unsigned char fcs[ETH_FCS_LENGTH];
+#endif
/* allocate a new skb for next time receive */
skb = current_rx_ptr->skb;
@@ -1025,6 +1031,8 @@
current_rx_ptr->desc_a.start_addr = (unsigned long)new_skb->data - 2;
len = (unsigned short)((current_rx_ptr->status.status_word) & RX_FRLEN);
+ /* Deduce Ethernet FCS length from Ethernet payload length */
+ len -= ETH_FCS_LENGTH;
skb_put(skb, len);
skb->protocol = eth_type_trans(skb, dev);
@@ -1033,6 +1041,14 @@
#if defined(BFIN_MAC_CSUM_OFFLOAD)
skb->csum = current_rx_ptr->status.ip_payload_csum;
+ /*
+ * Deduce Ethernet FCS from hardware generated IP payload checksum.
+ * IP checksum is based on 16-bit one's complement algorithm.
+ * To deduce a value from checksum is equal to add its complement.
+ */
+ for (i = 0; i < ETH_FCS_LENGTH; i++)
+ fcs[i] = ~skb->data[skb->len + i];
+ skb->csum = csum_partial(fcs, ETH_FCS_LENGTH, skb->csum);
skb->ip_summed = CHECKSUM_COMPLETE;
#endif
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits