netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Helmut Buchsbaum <helmut.buchsbaum@gmail.com>
To: David Miller <davem@davemloft.net>,
	Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: tom@herbertland.com, Michal Simek <michal.simek@xilinx.com>,
	netdev@vger.kernel.org,
	Cyrille Pitchen <cyrille.pitchen@atmel.com>,
	Helmut Buchsbaum <helmut.buchsbaum@gmail.com>
Subject: [PATCH v3] net: macb: initialize checksum when using checksum offloading
Date: Sun,  4 Sep 2016 18:09:47 +0200	[thread overview]
Message-ID: <1473005387-24917-1-git-send-email-helmut.buchsbaum@gmail.com> (raw)
In-Reply-To: <1472479045-8814-2-git-send-email-helmut.buchsbaum@gmail.com>

I'm still struggling to get this fix right..

Changes since v2:
 - do not blindly modify SKB contents according to Dave's legitimate
   objection

Changes since v1:
 - dropped disabling HW checksum offload for Zynq
 - initialize checksum similar to net/ethernet/freescale/fec_main.c

-- >8 --
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 | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 89c0cfa..d954a97 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -1323,6 +1323,24 @@ dma_error:
 	return 0;
 }
 
+static inline int macb_clear_csum(struct sk_buff *skb)
+{
+	/* no change for packets without checksum offloading */
+	if (skb->ip_summed != CHECKSUM_PARTIAL)
+		return 0;
+
+	/* make sure we can modify the header */
+	if (unlikely(skb_cow_head(skb, 0)))
+		return -1;
+
+	/* 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_checksum_start(skb) + skb->csum_offset) = 0;
+	return 0;
+}
+
 static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	u16 queue_index = skb_get_queue_mapping(skb);
@@ -1362,6 +1380,11 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		return NETDEV_TX_BUSY;
 	}
 
+	if (macb_clear_csum(skb)) {
+		dev_kfree_skb_any(skb);
+		return NETDEV_TX_OK;
+	}
+
 	/* Map socket buffer for DMA transfer */
 	if (!macb_tx_map(bp, queue, skb)) {
 		dev_kfree_skb_any(skb);
-- 
2.1.4

  parent reply	other threads:[~2016-09-04 16:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19 13:04 [PATCH 0/1] HW checksum offload problem on Xilinx Zynq GEM Helmut Buchsbaum
2016-08-19 13:04 ` [PATCH 1/1] net: macb: disable HW checksum offload for Xilinx Zynq Helmut Buchsbaum
2016-08-29 13:57   ` [PATCH v2 0/1] net: macb: initialize checksum when using checksum Helmut Buchsbaum
2016-08-29 13:57     ` [PATCH v2 1/1] net: macb: initialize checksum when using checksum offloading Helmut Buchsbaum
2016-09-01 17:03       ` David Miller
2016-09-04 16:09       ` Helmut Buchsbaum [this message]
2016-09-06 20:43         ` [PATCH v3] " David Miller
2016-08-19 19:28 ` [PATCH 0/1] HW checksum offload problem on Xilinx Zynq GEM David Miller
2016-08-19 20:00   ` Tom Herbert
2016-08-23  5:39     ` Helmut Buchsbaum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473005387-24917-1-git-send-email-helmut.buchsbaum@gmail.com \
    --to=helmut.buchsbaum@gmail.com \
    --cc=cyrille.pitchen@atmel.com \
    --cc=davem@davemloft.net \
    --cc=michal.simek@xilinx.com \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@atmel.com \
    --cc=tom@herbertland.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).