Message ID | 20181002092645.1115-4-ben.dooks@codethink.co.uk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/4] usbnet: smsc95xx: add kconfig for turbo mode | expand |
Hello! On 10/2/2018 12:26 PM, Ben Dooks wrote: > 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 s/chec/check/? > + * 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) > { [...] MBR, Sergei
On Tue, 2018-10-02 at 10:26 +0100, Ben Dooks wrote: [...] > @@ -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)) { It would make more sense to move the length check into smsc95xx_can_checksum() as well. Ben. > /* workaround - hardware tx checksum does not work > * properly with extremely small packets */ > long csstart = skb_checksum_start_offset(skb);
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);
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(-)