Skip to content

Commit 094bdad

Browse files
committed
Merge branch 'lan78xx-minor-fixes'
Dave Stevenson says: ==================== lan78xx minor fixes This is a small set of patches for the Microchip LAN78xx chip, as used in the Raspberry Pi 3B+. The main debug/discussion was on raspberrypi#2458 Initial symptoms were that VLANs were very unreliable. A couple of things were found: - firstly that the hardware timeout value set failed to take into account the VLAN tag, so a full MTU packet would be timed out. - second was that regular checksum failures were being reported. Disabling checksum offload confirmed that the checksums were valid, and further experimentation identified that it was only if the VLAN tags were being passed through to the kernel that there were issues. The hardware supports VLAN filtering and tag stripping, therefore those have been implemented (much of the work was already done), and the driver drops back to s/w checksums should the choice be made not to use the h/w VLAN stripping. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 0ee1f47 + 9343ac8 commit 094bdad

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

‎drivers/net/usb/lan78xx.c‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#define DEFAULT_RX_CSUM_ENABLE (true)
6565
#define DEFAULT_TSO_CSUM_ENABLE (true)
6666
#define DEFAULT_VLAN_FILTER_ENABLE (true)
67+
#define DEFAULT_VLAN_RX_OFFLOAD (true)
6768
#define TX_OVERHEAD (8)
6869
#define RXW_PADDING 2
6970

@@ -2298,7 +2299,7 @@ static int lan78xx_change_mtu(struct net_device *netdev, int new_mtu)
22982299
if ((ll_mtu % dev->maxpacket) == 0)
22992300
return -EDOM;
23002301

2301-
ret = lan78xx_set_rx_max_frame_length(dev, new_mtu + ETH_HLEN);
2302+
ret = lan78xx_set_rx_max_frame_length(dev, new_mtu + VLAN_ETH_HLEN);
23022303

23032304
netdev->mtu = new_mtu;
23042305

@@ -2364,6 +2365,11 @@ static int lan78xx_set_features(struct net_device *netdev,
23642365
}
23652366

23662367
if (features & NETIF_F_HW_VLAN_CTAG_RX)
2368+
pdata->rfe_ctl |= RFE_CTL_VLAN_STRIP_;
2369+
else
2370+
pdata->rfe_ctl &= ~RFE_CTL_VLAN_STRIP_;
2371+
2372+
if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
23672373
pdata->rfe_ctl |= RFE_CTL_VLAN_FILTER_;
23682374
else
23692375
pdata->rfe_ctl &= ~RFE_CTL_VLAN_FILTER_;
@@ -2587,7 +2593,8 @@ static int lan78xx_reset(struct lan78xx_net *dev)
25872593
buf |= FCT_TX_CTL_EN_;
25882594
ret = lan78xx_write_reg(dev, FCT_TX_CTL, buf);
25892595

2590-
ret = lan78xx_set_rx_max_frame_length(dev, dev->net->mtu + ETH_HLEN);
2596+
ret = lan78xx_set_rx_max_frame_length(dev,
2597+
dev->net->mtu + VLAN_ETH_HLEN);
25912598

25922599
ret = lan78xx_read_reg(dev, MAC_RX, &buf);
25932600
buf |= MAC_RX_RXEN_;
@@ -2975,6 +2982,12 @@ static int lan78xx_bind(struct lan78xx_net *dev, struct usb_interface *intf)
29752982
if (DEFAULT_TSO_CSUM_ENABLE)
29762983
dev->net->features |= NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_SG;
29772984

2985+
if (DEFAULT_VLAN_RX_OFFLOAD)
2986+
dev->net->features |= NETIF_F_HW_VLAN_CTAG_RX;
2987+
2988+
if (DEFAULT_VLAN_FILTER_ENABLE)
2989+
dev->net->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2990+
29782991
dev->net->hw_features = dev->net->features;
29792992

29802993
ret = lan78xx_setup_irq_domain(dev);
@@ -3039,15 +3052,30 @@ static void lan78xx_rx_csum_offload(struct lan78xx_net *dev,
30393052
struct sk_buff *skb,
30403053
u32 rx_cmd_a, u32 rx_cmd_b)
30413054
{
3055+
/* HW Checksum offload appears to be flawed if used when not stripping
3056+
* VLAN headers. Drop back to S/W checksums under these conditions.
3057+
*/
30423058
if (!(dev->net->features & NETIF_F_RXCSUM) ||
3043-
unlikely(rx_cmd_a & RX_CMD_A_ICSM_)) {
3059+
unlikely(rx_cmd_a & RX_CMD_A_ICSM_) ||
3060+
((rx_cmd_a & RX_CMD_A_FVTG_) &&
3061+
!(dev->net->features & NETIF_F_HW_VLAN_CTAG_RX))) {
30443062
skb->ip_summed = CHECKSUM_NONE;
30453063
} else {
30463064
skb->csum = ntohs((u16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT_));
30473065
skb->ip_summed = CHECKSUM_COMPLETE;
30483066
}
30493067
}
30503068

3069+
static void lan78xx_rx_vlan_offload(struct lan78xx_net *dev,
3070+
struct sk_buff *skb,
3071+
u32 rx_cmd_a, u32 rx_cmd_b)
3072+
{
3073+
if ((dev->net->features & NETIF_F_HW_VLAN_CTAG_RX) &&
3074+
(rx_cmd_a & RX_CMD_A_FVTG_))
3075+
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
3076+
(rx_cmd_b & 0xffff));
3077+
}
3078+
30513079
static void lan78xx_skb_return(struct lan78xx_net *dev, struct sk_buff *skb)
30523080
{
30533081
int status;
@@ -3112,6 +3140,8 @@ static int lan78xx_rx(struct lan78xx_net *dev, struct sk_buff *skb)
31123140
if (skb->len == size) {
31133141
lan78xx_rx_csum_offload(dev, skb,
31143142
rx_cmd_a, rx_cmd_b);
3143+
lan78xx_rx_vlan_offload(dev, skb,
3144+
rx_cmd_a, rx_cmd_b);
31153145

31163146
skb_trim(skb, skb->len - 4); /* remove fcs */
31173147
skb->truesize = size + sizeof(struct sk_buff);
@@ -3130,6 +3160,7 @@ static int lan78xx_rx(struct lan78xx_net *dev, struct sk_buff *skb)
31303160
skb_set_tail_pointer(skb2, size);
31313161

31323162
lan78xx_rx_csum_offload(dev, skb2, rx_cmd_a, rx_cmd_b);
3163+
lan78xx_rx_vlan_offload(dev, skb2, rx_cmd_a, rx_cmd_b);
31333164

31343165
skb_trim(skb2, skb2->len - 4); /* remove fcs */
31353166
skb2->truesize = size + sizeof(struct sk_buff);

0 commit comments

Comments
 (0)