linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Dooks <ben.dooks@codethink.co.uk>
To: netdev@vger.kernel.org
Cc: oneukum@suse.com, davem@davemloft.net, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-kernel@lists.codethink.co.uk,
	Ben Dooks <ben.dooks@codethink.co.uk>
Subject: [PATCH 3/4] usbnet: smsc95xx: check for csum being in last four bytes
Date: Tue,  2 Oct 2018 10:26:44 +0100	[thread overview]
Message-ID: <20181002092645.1115-4-ben.dooks@codethink.co.uk> (raw)
In-Reply-To: <20181002092645.1115-1-ben.dooks@codethink.co.uk>

The manual states that the checksum cannot lie in the last DWORD of the
transmission, so add a basic check for this and fall back to software
checksumming the packet.

This only seems to trigger for ACK packets with no options or data to
return to the other end, and the use of the tx-alignment option makes
it more likely to happen.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
 drivers/net/usb/smsc95xx.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index d244357bf1ad..46385a4b8b98 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -2003,6 +2003,20 @@ static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
 	return (high_16 << 16) | low_16;
 }
 
+/* The CSUM won't work if the checksum lies in the last 4 bytes of the
+ * transmission. This is fairly unlikely, only seems to trigger with some
+ * short TCP ACK packets sent.
+ *
+ * Note, this calculation should probably check for the alignment of the
+ * data as well, but a straight chec for csum being in the last four bytes
+ * of the packet should be ok for now.
+*/
+static bool smsc95xx_can_checksum(struct sk_buff *skb)
+{
+       unsigned int len = skb->len - skb_checksum_start_offset(skb);
+       return skb->csum_offset < (len - (4 + 1));
+}
+
 static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
 					 struct sk_buff *skb, gfp_t flags)
 {
@@ -2031,7 +2045,8 @@ static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
 	}
 
 	if (csum) {
-		if (skb->len <= 45) {
+		/* note, csum does not work if csum in last DWORD of packet */
+		if (skb->len <= 45 || !smsc95xx_can_checksum(skb)) {
 			/* workaround - hardware tx checksum does not work
 			 * properly with extremely small packets */
 			long csstart = skb_checksum_start_offset(skb);
-- 
2.19.0


  parent reply	other threads:[~2018-10-02  9:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02  9:26 SMSC95XX driver updates Ben Dooks
2018-10-02  9:26 ` [PATCH 1/4] usbnet: smsc95xx: add kconfig for turbo mode Ben Dooks
2018-10-02 12:46   ` Andrew Lunn
2018-10-02  9:26 ` [PATCH 2/4] usbnet: smsc95xx: align tx-buffer to word Ben Dooks
2018-10-02 13:19   ` David Laight
2018-10-02 13:35     ` Ben Dooks
2018-10-02 16:56     ` [PATCH] usbnet: smsc95xx: simplify tx_fixup code Ben Dooks
2018-10-03 13:36       ` David Laight
2018-10-03 16:25         ` Ben Dooks
2018-10-05 21:24       ` David Miller
2018-10-06 11:27         ` Ben Dooks
2018-10-06 17:28           ` David Miller
2018-10-08  8:41         ` David Laight
2018-10-04 16:53   ` [Linux-kernel] [PATCH 2/4] usbnet: smsc95xx: align tx-buffer to word Ben Hutchings
2018-10-02  9:26 ` Ben Dooks [this message]
2018-10-02  9:45   ` [PATCH 3/4] usbnet: smsc95xx: check for csum being in last four bytes Sergei Shtylyov
2018-10-04 16:55   ` [Linux-kernel] " Ben Hutchings
2018-10-02  9:26 ` [PATCH 4/4] usbnet: smsc95xx: fix rx packet alignment Ben Dooks

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=20181002092645.1115-4-ben.dooks@codethink.co.uk \
    --to=ben.dooks@codethink.co.uk \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@lists.codethink.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oneukum@suse.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).