linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* SMSC95xx driver updates (round 1)
@ 2018-11-14 11:50 Ben Dooks
  2018-11-14 11:50 ` [PATCH 1/4] usbnet: smsc95xx: fix rx packet alignment Ben Dooks
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Ben Dooks @ 2018-11-14 11:50 UTC (permalink / raw)
  To: netdev
  Cc: oneukum, davem, linux-usb, linux-kernel, steve.glendinning, linux-kernel

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.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] usbnet: smsc95xx: fix rx packet alignment
  2018-11-14 11:50 SMSC95xx driver updates (round 1) Ben Dooks
@ 2018-11-14 11:50 ` Ben Dooks
  2018-11-14 11:50 ` [PATCH 2/4] usbnet: smsc95xx: simplify tx_fixup code Ben Dooks
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Ben Dooks @ 2018-11-14 11:50 UTC (permalink / raw)
  To: netdev
  Cc: oneukum, davem, linux-usb, linux-kernel, steve.glendinning,
	linux-kernel, Ben Dooks

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/4] usbnet: smsc95xx: simplify tx_fixup code
  2018-11-14 11:50 SMSC95xx driver updates (round 1) Ben Dooks
  2018-11-14 11:50 ` [PATCH 1/4] usbnet: smsc95xx: fix rx packet alignment Ben Dooks
@ 2018-11-14 11:50 ` Ben Dooks
  2018-11-14 11:50 ` [PATCH 3/4] usbnet: smsc95xx: fix memcpy for accessing rx-data Ben Dooks
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Ben Dooks @ 2018-11-14 11:50 UTC (permalink / raw)
  To: netdev
  Cc: oneukum, davem, linux-usb, linux-kernel, steve.glendinning,
	linux-kernel, Ben Dooks

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/4] usbnet: smsc95xx: fix memcpy for accessing rx-data
  2018-11-14 11:50 SMSC95xx driver updates (round 1) Ben Dooks
  2018-11-14 11:50 ` [PATCH 1/4] usbnet: smsc95xx: fix rx packet alignment Ben Dooks
  2018-11-14 11:50 ` [PATCH 2/4] usbnet: smsc95xx: simplify tx_fixup code Ben Dooks
@ 2018-11-14 11:50 ` Ben Dooks
  2018-11-14 11:50 ` [PATCH 4/4] usbnet: smsc95xx: check for csum being in last four bytes Ben Dooks
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Ben Dooks @ 2018-11-14 11:50 UTC (permalink / raw)
  To: netdev
  Cc: oneukum, davem, linux-usb, linux-kernel, steve.glendinning,
	linux-kernel, Ben Dooks

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/4] usbnet: smsc95xx: check for csum being in last four bytes
  2018-11-14 11:50 SMSC95xx driver updates (round 1) Ben Dooks
                   ` (2 preceding siblings ...)
  2018-11-14 11:50 ` [PATCH 3/4] usbnet: smsc95xx: fix memcpy for accessing rx-data Ben Dooks
@ 2018-11-14 11:50 ` Ben Dooks
  2018-11-14 15:59   ` Sergei Shtylyov
  2018-11-14 11:58 ` SMSC95xx driver updates (round 1) Oliver Neukum
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 10+ messages in thread
From: Ben Dooks @ 2018-11-14 11:50 UTC (permalink / raw)
  To: netdev
  Cc: oneukum, davem, linux-usb, linux-kernel, steve.glendinning,
	linux-kernel, Ben Dooks

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: SMSC95xx driver updates (round 1)
  2018-11-14 11:50 SMSC95xx driver updates (round 1) Ben Dooks
                   ` (3 preceding siblings ...)
  2018-11-14 11:50 ` [PATCH 4/4] usbnet: smsc95xx: check for csum being in last four bytes Ben Dooks
@ 2018-11-14 11:58 ` Oliver Neukum
  2018-11-15 18:06 ` Woojung.Huh
  2018-11-17  4:16 ` David Miller
  6 siblings, 0 replies; 10+ messages in thread
From: Oliver Neukum @ 2018-11-14 11:58 UTC (permalink / raw)
  To: Ben Dooks, netdev
  Cc: davem, linux-kernel, steve.glendinning, linux-kernel, linux-usb

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/4] usbnet: smsc95xx: check for csum being in last four bytes
  2018-11-14 11:50 ` [PATCH 4/4] usbnet: smsc95xx: check for csum being in last four bytes Ben Dooks
@ 2018-11-14 15:59   ` Sergei Shtylyov
  0 siblings, 0 replies; 10+ messages in thread
From: Sergei Shtylyov @ 2018-11-14 15:59 UTC (permalink / raw)
  To: Ben Dooks, netdev
  Cc: oneukum, davem, linux-usb, linux-kernel, steve.glendinning, linux-kernel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: SMSC95xx driver updates (round 1)
  2018-11-14 11:50 SMSC95xx driver updates (round 1) Ben Dooks
                   ` (4 preceding siblings ...)
  2018-11-14 11:58 ` SMSC95xx driver updates (round 1) Oliver Neukum
@ 2018-11-15 18:06 ` Woojung.Huh
  2018-11-16 10:49   ` Ben Dooks
  2018-11-17  4:16 ` David Miller
  6 siblings, 1 reply; 10+ messages in thread
From: Woojung.Huh @ 2018-11-15 18:06 UTC (permalink / raw)
  To: ben.dooks, netdev
  Cc: oneukum, davem, linux-usb, linux-kernel, steve.glendinning,
	linux-kernel, UNGLinuxDriver

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: SMSC95xx driver updates (round 1)
  2018-11-15 18:06 ` Woojung.Huh
@ 2018-11-16 10:49   ` Ben Dooks
  0 siblings, 0 replies; 10+ messages in thread
From: Ben Dooks @ 2018-11-16 10:49 UTC (permalink / raw)
  To: Woojung.Huh, netdev
  Cc: oneukum, davem, linux-usb, linux-kernel, steve.glendinning,
	linux-kernel, UNGLinuxDriver

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: SMSC95xx driver updates (round 1)
  2018-11-14 11:50 SMSC95xx driver updates (round 1) Ben Dooks
                   ` (5 preceding siblings ...)
  2018-11-15 18:06 ` Woojung.Huh
@ 2018-11-17  4:16 ` David Miller
  6 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2018-11-17  4:16 UTC (permalink / raw)
  To: ben.dooks
  Cc: netdev, oneukum, linux-usb, linux-kernel, steve.glendinning,
	linux-kernel

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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-11-17  4:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 11:50 SMSC95xx driver updates (round 1) Ben Dooks
2018-11-14 11:50 ` [PATCH 1/4] usbnet: smsc95xx: fix rx packet alignment Ben Dooks
2018-11-14 11:50 ` [PATCH 2/4] usbnet: smsc95xx: simplify tx_fixup code Ben Dooks
2018-11-14 11:50 ` [PATCH 3/4] usbnet: smsc95xx: fix memcpy for accessing rx-data Ben Dooks
2018-11-14 11:50 ` [PATCH 4/4] usbnet: smsc95xx: check for csum being in last four bytes Ben Dooks
2018-11-14 15:59   ` Sergei Shtylyov
2018-11-14 11:58 ` SMSC95xx driver updates (round 1) Oliver Neukum
2018-11-15 18:06 ` Woojung.Huh
2018-11-16 10:49   ` Ben Dooks
2018-11-17  4:16 ` David Miller

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).