This is a series of a few driver cleanups and some fixups of the code for the SMSC95XX driver. There have been a few reviews, and the issues have been fixed so this should be ready for merging. I will work on the tx-alignment and the other bits of usbnet changes and produce at least two more patch series for this later.
The smsc95xx driver already takes into account the NET_IP_ALIGN parameter when setting up the receive packet data, which means we do not need to worry about aligning the packets in the usbnet driver. Adding the EVENT_NO_IP_ALIGN means that the IPv4 header is now passed to the ip_rcv() routine with the start on an aligned address. Tested on Raspberry Pi B3. Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> --- drivers/net/usb/smsc95xx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 06b4d290784d..401ec9feb495 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -1292,6 +1292,7 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) dev->net->features |= NETIF_F_RXCSUM; dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM; + set_bit(EVENT_NO_IP_ALIGN, &dev->flags); smsc95xx_init_mac_address(dev); -- 2.19.1
The smsc95xx_tx_fixup is doing multiple calls to skb_push() to put an 8-byte command header onto the packet. It would be easier to do one skb_push() and then copy the data in once the push is done. We also make the code smaller by using proper unaligned puts for the header. This merges in the CPU to LE32 conversion as well and makes the whole sequence easier to understand hopefully. Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> --- Since v1: - Add alignment changes using put_unaligned_le32() --- drivers/net/usb/smsc95xx.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 401ec9feb495..50e97a159500 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -2006,6 +2006,7 @@ static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, bool csum = skb->ip_summed == CHECKSUM_PARTIAL; int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; u32 tx_cmd_a, tx_cmd_b; + void *ptr; /* We do not advertise SG, so skbs should be already linearized */ BUG_ON(skb_shinfo(skb)->nr_frags); @@ -2019,6 +2020,9 @@ static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, return NULL; } + tx_cmd_b = (u32)skb->len; + tx_cmd_a = tx_cmd_b | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_; + if (csum) { if (skb->len <= 45) { /* workaround - hardware tx checksum does not work @@ -2032,24 +2036,18 @@ static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, csum = false; } else { u32 csum_preamble = smsc95xx_calc_csum_preamble(skb); - skb_push(skb, 4); - cpu_to_le32s(&csum_preamble); - memcpy(skb->data, &csum_preamble, 4); + ptr = skb_push(skb, 4); + put_unaligned_le32(csum_preamble, ptr); + + tx_cmd_a += 4; + tx_cmd_b += 4; + tx_cmd_b |= TX_CMD_B_CSUM_ENABLE; } } - skb_push(skb, 4); - tx_cmd_b = (u32)(skb->len - 4); - if (csum) - tx_cmd_b |= TX_CMD_B_CSUM_ENABLE; - cpu_to_le32s(&tx_cmd_b); - memcpy(skb->data, &tx_cmd_b, 4); - - skb_push(skb, 4); - tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ | - TX_CMD_A_LAST_SEG_; - cpu_to_le32s(&tx_cmd_a); - memcpy(skb->data, &tx_cmd_a, 4); + ptr = skb_push(skb, 8); + put_unaligned_le32(tx_cmd_a, ptr); + put_unaligned_le32(tx_cmd_b, ptr+4); return skb; } -- 2.19.1
Change the RX code to use get_unaligned_le32() instead of the combo of memcpy and cpu_to_le32s(&var). Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> --- drivers/net/usb/smsc95xx.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 50e97a159500..8f7c473f3260 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -618,9 +618,7 @@ static void smsc95xx_status(struct usbnet *dev, struct urb *urb) return; } - memcpy(&intdata, urb->transfer_buffer, 4); - le32_to_cpus(&intdata); - + intdata = get_unaligned_le32(urb->transfer_buffer); netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); if (intdata & INT_ENP_PHY_INT_) @@ -1922,8 +1920,7 @@ static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) unsigned char *packet; u16 size; - memcpy(&header, skb->data, sizeof(header)); - le32_to_cpus(&header); + header = get_unaligned_le32(skb->data); skb_pull(skb, 4 + NET_IP_ALIGN); packet = skb->data; -- 2.19.1
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> --- Fixes for v2: - Fix spelling of check at Sergei's suggestion - Move skb->len check into smsc95xx_can_tx_checksum() - Change name of smsc95xx_can_checksum to explicitly say it is tx-csum --- drivers/net/usb/smsc95xx.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index 8f7c473f3260..cc78ef78cc93 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -1997,6 +1997,23 @@ static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) return (high_16 << 16) | low_16; } +/* The TX 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 check for csum being in the last four bytes + * of the packet should be ok for now. +*/ +static bool smsc95xx_can_tx_checksum(struct sk_buff *skb) +{ + unsigned int len = skb->len - skb_checksum_start_offset(skb); + + if (skb->len <= 45) + return false; + return skb->csum_offset < (len - (4 + 1)); +} + static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) { @@ -2021,7 +2038,7 @@ static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, tx_cmd_a = tx_cmd_b | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_; if (csum) { - if (skb->len <= 45) { + if (!smsc95xx_can_tx_checksum(skb)) { /* workaround - hardware tx checksum does not work * properly with extremely small packets */ long csstart = skb_checksum_start_offset(skb); -- 2.19.1
On Mi, 2018-11-14 at 11:50 +0000, Ben Dooks wrote:
> This is a series of a few driver cleanups and some fixups of the code
> for the SMSC95XX driver. There have been a few reviews, and the issues
> have been fixed so this should be ready for merging.
>
> I will work on the tx-alignment and the other bits of usbnet changes
> and produce at least two more patch series for this later.
That looks good to me.
Regards
Oliver
On 11/14/2018 02:50 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>
> ---
> Fixes for v2:
> - Fix spelling of check at Sergei's suggestion
> - Move skb->len check into smsc95xx_can_tx_checksum()
> - Change name of smsc95xx_can_checksum to explicitly say it is tx-csum
> ---
> drivers/net/usb/smsc95xx.c | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
> index 8f7c473f3260..cc78ef78cc93 100644
> --- a/drivers/net/usb/smsc95xx.c
> +++ b/drivers/net/usb/smsc95xx.c
> @@ -1997,6 +1997,23 @@ static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
> return (high_16 << 16) | low_16;
> }
>
> +/* The TX 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 check for csum being in the last four bytes
> + * of the packet should be ok for now.
> +*/
Missed a space before */.
[...]
MBR, Sergei
Hi Ben,
> -----Original Message-----
> From: netdev-owner@vger.kernel.org <netdev-owner@vger.kernel.org> On Behalf Of Ben Dooks
> Sent: Wednesday, November 14, 2018 6:50 AM
> To: netdev@vger.kernel.org
> Cc: oneukum@suse.com; davem@davemloft.net; linux-usb@vger.kernel.org; linux-
> kernel@vger.kernel.org; steve.glendinning@shawell.net; linux-kernel@lists.codethink.co.uk
> Subject: SMSC95xx driver updates (round 1)
>
> This is a series of a few driver cleanups and some fixups of the code
> for the SMSC95XX driver. There have been a few reviews, and the issues
> have been fixed so this should be ready for merging.
>
> I will work on the tx-alignment and the other bits of usbnet changes
> and produce at least two more patch series for this later.
Some reason, maintainer email of UNGLinuxDriver@microchip.com is NOT included in CC.
Please add it in following patch series you are creating to have a chance to review by
proper reviewers.
USB SMSC95XX ETHERNET DRIVER
M: Steve Glendinning <steve.glendinning@shawell.net>
M: Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>
L: netdev@vger.kernel.org
S: Maintained
F: drivers/net/usb/smsc95xx.*
Best Regards,
Woojung
On 15/11/18 18:06, Woojung.Huh@microchip.com wrote: > Hi Ben, > >> -----Original Message----- >> From: netdev-owner@vger.kernel.org <netdev-owner@vger.kernel.org> On Behalf Of Ben Dooks >> Sent: Wednesday, November 14, 2018 6:50 AM >> To: netdev@vger.kernel.org >> Cc: oneukum@suse.com; davem@davemloft.net; linux-usb@vger.kernel.org; linux- >> kernel@vger.kernel.org; steve.glendinning@shawell.net; linux-kernel@lists.codethink.co.uk >> Subject: SMSC95xx driver updates (round 1) >> >> This is a series of a few driver cleanups and some fixups of the code >> for the SMSC95XX driver. There have been a few reviews, and the issues >> have been fixed so this should be ready for merging. >> >> I will work on the tx-alignment and the other bits of usbnet changes >> and produce at least two more patch series for this later. > > Some reason, maintainer email of UNGLinuxDriver@microchip.com is NOT included in CC. > Please add it in following patch series you are creating to have a chance to review by > proper reviewers. > > USB SMSC95XX ETHERNET DRIVER > M: Steve Glendinning <steve.glendinning@shawell.net> > M: Microchip Linux Driver Support <UNGLinuxDriver@microchip.com> > L: netdev@vger.kernel.org > S: Maintained > F: drivers/net/usb/smsc95xx.* Sorry, must have missed this when rebasing from v4.18 to v4.19. -- Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html
From: Ben Dooks <ben.dooks@codethink.co.uk>
Date: Wed, 14 Nov 2018 11:50:18 +0000
> This is a series of a few driver cleanups and some fixups of the code
> for the SMSC95XX driver. There have been a few reviews, and the issues
> have been fixed so this should be ready for merging.
>
> I will work on the tx-alignment and the other bits of usbnet changes
> and produce at least two more patch series for this later.
Series applied with the missing space in the comment of patch #4 fixed.
Thanks.