cb605e531cde0c64e4a84177f32a97c36d3b48a5
[openwrt/staging/chunkeey.git] / target / linux / generic / patches-4.1 / 761-8139cp-fixes-from-4.4.patch
1 commit 8b7a7048220f86547db31de0abe1ea6dd2cfa892
2 Author: David Woodhouse <dwmw2@infradead.org>
3 Date: Thu Sep 24 11:38:22 2015 +0100
4
5 8139cp: Fix GSO MSS handling
6
7 When fixing the TSO support I noticed we just mask ->gso_size with the
8 MSSMask value and don't care about the consequences.
9
10 Provide a .ndo_features_check() method which drops the NETIF_F_TSO
11 feature for any skb which would exceed the maximum, and thus forces it
12 to be segmented by software.
13
14 Then we can stop the masking in cp_start_xmit(), and just WARN if the
15 maximum is exceeded, which should now never happen.
16
17 Finally, Francois Romieu noticed that we didn't even have the right
18 value for MSSMask anyway; it should be 0x7ff (11 bits) not 0xfff.
19
20 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
21 Signed-off-by: David S. Miller <davem@davemloft.net>
22
23 commit 5a58f227790faded5a3ef6075f3ddd65093e0f86
24 Author: David Woodhouse <David.Woodhouse@intel.com>
25 Date: Wed Sep 23 09:46:09 2015 +0100
26
27 8139cp: Enable offload features by default
28
29 I fixed TSO. Hardware checksum and scatter/gather also appear to be
30 working correctly both on real hardware and in QEMU's emulation.
31
32 Let's enable them by default and see if anyone screams...
33
34 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
35 Signed-off-by: David S. Miller <davem@davemloft.net>
36 diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
37 index 686334f..deae10d 100644
38 --- a/drivers/net/ethernet/realtek/8139cp.c
39 +++ b/drivers/net/ethernet/realtek/8139cp.c
40 @@ -175,7 +175,7 @@ enum {
41 LastFrag = (1 << 28), /* Final segment of a packet */
42 LargeSend = (1 << 27), /* TCP Large Send Offload (TSO) */
43 MSSShift = 16, /* MSS value position */
44 - MSSMask = 0xfff, /* MSS value: 11 bits */
45 + MSSMask = 0x7ff, /* MSS value: 11 bits */
46 TxError = (1 << 23), /* Tx error summary */
47 RxError = (1 << 20), /* Rx error summary */
48 IPCS = (1 << 18), /* Calculate IP checksum */
49 @@ -754,10 +754,16 @@ static netdev_tx_t cp_start_xmit (struct sk_buff *skb,
50 eor = (entry == (CP_TX_RING_SIZE - 1)) ? RingEnd : 0;
51 mss = skb_shinfo(skb)->gso_size;
52
53 + if (mss > MSSMask) {
54 + WARN_ONCE(1, "Net bug: GSO size %d too large for 8139CP\n",
55 + mss);
56 + goto out_dma_error;
57 + }
58 +
59 opts2 = cpu_to_le32(cp_tx_vlan_tag(skb));
60 opts1 = DescOwn;
61 if (mss)
62 - opts1 |= LargeSend | ((mss & MSSMask) << MSSShift);
63 + opts1 |= LargeSend | (mss << MSSShift);
64 else if (skb->ip_summed == CHECKSUM_PARTIAL) {
65 const struct iphdr *ip = ip_hdr(skb);
66 if (ip->protocol == IPPROTO_TCP)
67 @@ -1852,6 +1858,15 @@ static void cp_set_d3_state (struct cp_private *cp)
68 pci_set_power_state (cp->pdev, PCI_D3hot);
69 }
70
71 +static netdev_features_t cp_features_check(struct sk_buff *skb,
72 + struct net_device *dev,
73 + netdev_features_t features)
74 +{
75 + if (skb_shinfo(skb)->gso_size > MSSMask)
76 + features &= ~NETIF_F_TSO;
77 +
78 + return vlan_features_check(skb, features);
79 +}
80 static const struct net_device_ops cp_netdev_ops = {
81 .ndo_open = cp_open,
82 .ndo_stop = cp_close,
83 @@ -1864,6 +1879,7 @@ static const struct net_device_ops cp_netdev_ops = {
84 .ndo_tx_timeout = cp_tx_timeout,
85 .ndo_set_features = cp_set_features,
86 .ndo_change_mtu = cp_change_mtu,
87 + .ndo_features_check = cp_features_check,
88
89 #ifdef CONFIG_NET_POLL_CONTROLLER
90 .ndo_poll_controller = cp_poll_controller,
91 @@ -1983,12 +1999,12 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
92 dev->ethtool_ops = &cp_ethtool_ops;
93 dev->watchdog_timeo = TX_TIMEOUT;
94
95 - dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
96 + dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
97 + NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
98
99 if (pci_using_dac)
100 dev->features |= NETIF_F_HIGHDMA;
101
102 - /* disabled by default until verified */
103 dev->hw_features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
104 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
105 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |