diff mbox

[v2,1/1] net: macb: initialize checksum when using checksum offloading

Message ID 1472479045-8814-2-git-send-email-helmut.buchsbaum@gmail.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Helmut Buchsbaum Aug. 29, 2016, 1:57 p.m. UTC
MACB/GEM needs the checksum field initialized to 0 to get correct
results on transmit in all cases, e.g. on Zynq, UDP packets with
payload <= 2 otherwise contain a wrong checksums.

Signed-off-by: Helmut Buchsbaum <helmut.buchsbaum@gmail.com>
---
 drivers/net/ethernet/cadence/macb.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

David Miller Sept. 1, 2016, 5:03 p.m. UTC | #1
From: Helmut Buchsbaum <helmut.buchsbaum@gmail.com>
Date: Mon, 29 Aug 2016 15:57:25 +0200

> diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
> index 89c0cfa..de2f791 100644
> --- a/drivers/net/ethernet/cadence/macb.c
> +++ b/drivers/net/ethernet/cadence/macb.c
> @@ -1323,6 +1323,19 @@ dma_error:
>  	return 0;
>  }
>  
> +static inline void macb_clear_csum(struct sk_buff *skb)
> +{
> +	/* no change for packets without checksum offloading */
> +	if (skb->ip_summed != CHECKSUM_PARTIAL)
> +		return;
> +
> +	/* initialize checksum field
> +	 * This is required - at least for Zynq, which otherwise calculates
> +	 * wrong UDP header checksums for UDP packets with UDP data len <=2
> +	 */
> +	*(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) = 0;
> +}
> +

It is not valid to blindly modify the SKB contents, you must make sure that no
other references to this SKB's data exist.

You do this via skb_cow_head(skb, 0), which may fail.

See for example drivers/net/ethernet/broadcom/tg3.c's tg3_start_xmit()
diff mbox

Patch

diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 89c0cfa..de2f791 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -1323,6 +1323,19 @@  dma_error:
 	return 0;
 }
 
+static inline void macb_clear_csum(struct sk_buff *skb)
+{
+	/* no change for packets without checksum offloading */
+	if (skb->ip_summed != CHECKSUM_PARTIAL)
+		return;
+
+	/* initialize checksum field
+	 * This is required - at least for Zynq, which otherwise calculates
+	 * wrong UDP header checksums for UDP packets with UDP data len <=2
+	 */
+	*(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) = 0;
+}
+
 static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	u16 queue_index = skb_get_queue_mapping(skb);
@@ -1362,6 +1375,8 @@  static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		return NETDEV_TX_BUSY;
 	}
 
+	macb_clear_csum(skb);
+
 	/* Map socket buffer for DMA transfer */
 	if (!macb_tx_map(bp, queue, skb)) {
 		dev_kfree_skb_any(skb);