Skip to contentSkip to conversation

SMSC95xx driver updates (round 1)

PATCH In review Ben Dooks 5 participants 10 messages Nov 14, 2018 – Nov 17, 2018

Subsystems (5)
lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

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.

author
#1 lore raw

PATCH 1/4 usbnet: smsc95xx: fix rx packet alignment

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.

---
 drivers/net/usb/smsc95xx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/usb/smsc95xx.c +1 -0
index 06b4d290784d..401ec9feb495 100644
@@ -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);
 
author
#2 lore raw

PATCH 2/4 usbnet: smsc95xx: simplify tx_fixup code

In reply to 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.

---
Since v1:
- Add alignment changes using put_unaligned_le32()

---
 drivers/net/usb/smsc95xx.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
drivers/net/usb/smsc95xx.c +13 -15
index 401ec9feb495..50e97a159500 100644
@@ -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;
 }
author
#3 lore raw

PATCH 3/4 usbnet: smsc95xx: fix memcpy for accessing rx-data

In reply to Ben Dooks

Change the RX code to use get_unaligned_le32() instead of the combo of memcpy and cpu_to_le32s(&var).

---
 drivers/net/usb/smsc95xx.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/usb/smsc95xx.c +2 -5
index 50e97a159500..8f7c473f3260 100644
@@ -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;
 
author
#4 lore raw

PATCH 4/4 usbnet: smsc95xx: check for csum being in last four bytes

In reply to 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.

---
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(-)
drivers/net/usb/smsc95xx.c +18 -1
index 8f7c473f3260..cc78ef78cc93 100644
@@ -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);
#5 lore raw

Re: [PATCH 4/4] usbnet: smsc95xx: check for csum being in last four bytes

Quoted 24 lines · 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.

---
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(-)
drivers/net/usb/smsc95xx.c +0 -0
index 8f7c473f3260..cc78ef78cc93 100644
@@ -1997,6 +1997,23 @@ static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
 	return (high_16 << 16) | low_16;

drivers/net/usb/smsc95xx.c static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) · line 2007

Quoted 10 lines
drivers/net/usb/smsc95xx.c +8 -0
 }
 
+/* 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

#6 lore raw
In reply to Ben Dooks
Quoted 6 lines · Ben Dooks

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

#7 lore raw
In reply to Ben Dooks

Hi Ben,

Quoted 8 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Ben Dooks
Sent: Wednesday, November 14, 2018 6:50 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: SMSC95xx driver updates (round 1)

Quoted 6 lines

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 [email protected] 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 <[email protected]>
M: Microchip Linux Driver Support <[email protected]>
L: [email protected]
S: Maintained
F: drivers/net/usb/smsc95xx.*

Best Regards,
Woojung

author
#8 lore raw
Quoted 21 lines · On 15/11/18 18:06, [email protected] wrote:

Hi Ben,

Quoted 8 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Ben Dooks
Sent: Wednesday, November 14, 2018 6:50 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: SMSC95xx driver updates (round 1)

Quoted 6 lines

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 [email protected] is NOT included in CC. Please add it in following patch series you are creating to have a chance to review by proper reviewers.

Quoted 6 lines

USB SMSC95XX ETHERNET DRIVER
M: Steve Glendinning <[email protected]>
M: Microchip Linux Driver Support <[email protected]>
L: [email protected]
S: Maintained
F: drivers/net/usb/smsc95xx.*

Sorry, must have missed this when rebasing from v4.18 to v4.19.

Signature · 4 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html
maintainer
#9 lore raw
In reply to Ben Dooks

From: Ben Dooks <[email protected]>
Date: Wed, 14 Nov 2018 11:50:18 +0000

Quoted 6 lines

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.