1 From e303bfb934b2a5adb549b43bbd51b1a0e33c33b3 Mon Sep 17 00:00:00 2001
2 From: P33M <p33m@github.com>
3 Date: Wed, 1 May 2019 17:04:32 +0100
4 Subject: [PATCH 484/703] smsc95xx: dynamically fix up TX buffer alignment with
7 dwc_otg requires a 32-bit aligned buffer start address, otherwise
8 expensive bounce buffers are used. The LAN951x hardware can skip up to
9 3 bytes between the TX header and the start of frame data, which can
10 be used to force alignment of the URB passed to dwc_otg.
12 As found in https://github.com/raspberrypi/linux/issues/2924
14 drivers/net/usb/smsc95xx.c | 12 +++++++-----
15 drivers/net/usb/smsc95xx.h | 2 +-
16 2 files changed, 8 insertions(+), 6 deletions(-)
18 --- a/drivers/net/usb/smsc95xx.c
19 +++ b/drivers/net/usb/smsc95xx.c
20 @@ -2082,7 +2082,9 @@ static struct sk_buff *smsc95xx_tx_fixup
21 struct sk_buff *skb, gfp_t flags)
23 bool csum = skb->ip_summed == CHECKSUM_PARTIAL;
24 - int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD;
25 + unsigned int align_bytes = -((uintptr_t)skb->data) & 0x3;
26 + int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM + align_bytes
27 + : SMSC95XX_TX_OVERHEAD + align_bytes;
28 u32 tx_cmd_a, tx_cmd_b;
30 /* We do not advertise SG, so skbs should be already linearized */
31 @@ -2116,16 +2118,16 @@ static struct sk_buff *smsc95xx_tx_fixup
36 - tx_cmd_b = (u32)(skb->len - 4);
37 + skb_push(skb, 4 + align_bytes);
38 + tx_cmd_b = (u32)(skb->len - 4 - align_bytes);
40 tx_cmd_b |= TX_CMD_B_CSUM_ENABLE;
41 cpu_to_le32s(&tx_cmd_b);
42 memcpy(skb->data, &tx_cmd_b, 4);
45 - tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ |
47 + tx_cmd_a = (u32)(skb->len - 8 - align_bytes) | TX_CMD_A_FIRST_SEG_ |
48 + (align_bytes << 16) | TX_CMD_A_LAST_SEG_;
49 cpu_to_le32s(&tx_cmd_a);
50 memcpy(skb->data, &tx_cmd_a, 4);
52 --- a/drivers/net/usb/smsc95xx.h
53 +++ b/drivers/net/usb/smsc95xx.h
57 /* Tx command words */
58 -#define TX_CMD_A_DATA_OFFSET_ (0x001F0000) /* Data Start Offset */
59 +#define TX_CMD_A_DATA_OFFSET_ (0x00030000) /* Data Start Offset */
60 #define TX_CMD_A_FIRST_SEG_ (0x00002000) /* First Segment */
61 #define TX_CMD_A_LAST_SEG_ (0x00001000) /* Last Segment */
62 #define TX_CMD_A_BUF_SIZE_ (0x000007FF) /* Buffer Size */