Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usbnet: smsc95xx: check for csum being in last four bytes

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>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ben Dooks and committed by
David S. Miller
75938f77 6809d216

+18 -1
+18 -1
drivers/net/usb/smsc95xx.c
··· 2009 2009 return (high_16 << 16) | low_16; 2010 2010 } 2011 2011 2012 + /* The TX CSUM won't work if the checksum lies in the last 4 bytes of the 2013 + * transmission. This is fairly unlikely, only seems to trigger with some 2014 + * short TCP ACK packets sent. 2015 + * 2016 + * Note, this calculation should probably check for the alignment of the 2017 + * data as well, but a straight check for csum being in the last four bytes 2018 + * of the packet should be ok for now. 2019 + */ 2020 + static bool smsc95xx_can_tx_checksum(struct sk_buff *skb) 2021 + { 2022 + unsigned int len = skb->len - skb_checksum_start_offset(skb); 2023 + 2024 + if (skb->len <= 45) 2025 + return false; 2026 + return skb->csum_offset < (len - (4 + 1)); 2027 + } 2028 + 2012 2029 static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, 2013 2030 struct sk_buff *skb, gfp_t flags) 2014 2031 { ··· 2050 2033 tx_cmd_a = tx_cmd_b | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_; 2051 2034 2052 2035 if (csum) { 2053 - if (skb->len <= 45) { 2036 + if (!smsc95xx_can_tx_checksum(skb)) { 2054 2037 /* workaround - hardware tx checksum does not work 2055 2038 * properly with extremely small packets */ 2056 2039 long csstart = skb_checksum_start_offset(skb);