kernel: update linux 3.6 to 3.6.9
[openwrt.git] / target / linux / generic / patches-3.6 / 065-8139cp-fixes.patch
1 commit 01ffc0a7f1c1801a2354719dedbc32aff45b987d
2 Author: David Woodhouse <dwmw2@infradead.org>
3 Date:   Sat Nov 24 12:11:21 2012 +0000
4
5     8139cp: re-enable interrupts after tx timeout
6     
7     Recovery doesn't work too well if we leave interrupts disabled...
8     
9     Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
10     Acked-by: Francois Romieu <romieu@fr.zoreil.com>
11     Signed-off-by: David S. Miller <davem@davemloft.net>
12
13 commit 871f0d4c153e1258d4becf306eca6761bf38b629
14 Author: David Woodhouse <dwmw2@infradead.org>
15 Date:   Thu Nov 22 03:16:58 2012 +0000
16
17     8139cp: enable bql
18     
19     This adds support for byte queue limits on RTL8139C+
20     
21     Tested on real hardware.
22     
23     Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
24     Acked-By: Dave Täht <dave.taht@bufferbloat.net>
25     Signed-off-by: David S. Miller <davem@davemloft.net>
26
27 commit a9dbe40fc10cea2efe6e1ff9e03c62dd7579c5ba
28 Author: David Woodhouse <dwmw2@infradead.org>
29 Date:   Wed Nov 21 10:27:19 2012 +0000
30
31     8139cp: set ring address after enabling C+ mode
32     
33     This fixes (for me) a regression introduced by commit b01af457 ("8139cp:
34     set ring address before enabling receiver"). That commit configured the
35     descriptor ring addresses earlier in the initialisation sequence, in
36     order to avoid the possibility of triggering stray DMA before the
37     correct address had been set up.
38     
39     Unfortunately, it seems that the hardware will scribble garbage into the
40     TxRingAddr registers when we enable "plus mode" Tx in the CpCmd
41     register. Observed on a Traverse Geos router board.
42     
43     To deal with this, while not reintroducing the problem which led to the
44     original commit, we augment cp_start_hw() to write to the CpCmd register
45     *first*, then set the descriptor ring addresses, and then finally to
46     enable Rx and Tx in the original 8139 Cmd register. The datasheet
47     actually indicates that we should enable Tx/Rx in the Cmd register
48     *before* configuring the descriptor addresses, but that would appear to
49     re-introduce the problem that the offending commit b01af457 was trying
50     to solve. And this variant appears to work fine on real hardware.
51     
52     Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
53     Cc: stable@kernel.org [3.5+]
54     Signed-off-by: David S. Miller <davem@davemloft.net>
55
56 --- a/drivers/net/ethernet/realtek/8139cp.c
57 +++ b/drivers/net/ethernet/realtek/8139cp.c
58 @@ -648,6 +648,7 @@ static void cp_tx (struct cp_private *cp
59  {
60         unsigned tx_head = cp->tx_head;
61         unsigned tx_tail = cp->tx_tail;
62 +       unsigned bytes_compl = 0, pkts_compl = 0;
63  
64         while (tx_tail != tx_head) {
65                 struct cp_desc *txd = cp->tx_ring + tx_tail;
66 @@ -666,6 +667,9 @@ static void cp_tx (struct cp_private *cp
67                                  le32_to_cpu(txd->opts1) & 0xffff,
68                                  PCI_DMA_TODEVICE);
69  
70 +               bytes_compl += skb->len;
71 +               pkts_compl++;
72 +
73                 if (status & LastFrag) {
74                         if (status & (TxError | TxFIFOUnder)) {
75                                 netif_dbg(cp, tx_err, cp->dev,
76 @@ -697,6 +701,7 @@ static void cp_tx (struct cp_private *cp
77  
78         cp->tx_tail = tx_tail;
79  
80 +       netdev_completed_queue(cp->dev, pkts_compl, bytes_compl);
81         if (TX_BUFFS_AVAIL(cp) > (MAX_SKB_FRAGS + 1))
82                 netif_wake_queue(cp->dev);
83  }
84 @@ -843,6 +848,8 @@ static netdev_tx_t cp_start_xmit (struct
85                 wmb();
86         }
87         cp->tx_head = entry;
88 +
89 +       netdev_sent_queue(dev, skb->len);
90         netif_dbg(cp, tx_queued, cp->dev, "tx queued, slot %d, skblen %d\n",
91                   entry, skb->len);
92         if (TX_BUFFS_AVAIL(cp) <= (MAX_SKB_FRAGS + 1))
93 @@ -937,6 +944,8 @@ static void cp_stop_hw (struct cp_privat
94  
95         cp->rx_tail = 0;
96         cp->tx_head = cp->tx_tail = 0;
97 +
98 +       netdev_reset_queue(cp->dev);
99  }
100  
101  static void cp_reset_hw (struct cp_private *cp)
102 @@ -957,8 +966,38 @@ static void cp_reset_hw (struct cp_priva
103  
104  static inline void cp_start_hw (struct cp_private *cp)
105  {
106 +       dma_addr_t ring_dma;
107 +
108         cpw16(CpCmd, cp->cpcmd);
109 +
110 +       /*
111 +        * These (at least TxRingAddr) need to be configured after the
112 +        * corresponding bits in CpCmd are enabled. Datasheet v1.6 §6.33
113 +        * (C+ Command Register) recommends that these and more be configured
114 +        * *after* the [RT]xEnable bits in CpCmd are set. And on some hardware
115 +        * it's been observed that the TxRingAddr is actually reset to garbage
116 +        * when C+ mode Tx is enabled in CpCmd.
117 +        */
118 +       cpw32_f(HiTxRingAddr, 0);
119 +       cpw32_f(HiTxRingAddr + 4, 0);
120 +
121 +       ring_dma = cp->ring_dma;
122 +       cpw32_f(RxRingAddr, ring_dma & 0xffffffff);
123 +       cpw32_f(RxRingAddr + 4, (ring_dma >> 16) >> 16);
124 +
125 +       ring_dma += sizeof(struct cp_desc) * CP_RX_RING_SIZE;
126 +       cpw32_f(TxRingAddr, ring_dma & 0xffffffff);
127 +       cpw32_f(TxRingAddr + 4, (ring_dma >> 16) >> 16);
128 +
129 +       /*
130 +        * Strictly speaking, the datasheet says this should be enabled
131 +        * *before* setting the descriptor addresses. But what, then, would
132 +        * prevent it from doing DMA to random unconfigured addresses?
133 +        * This variant appears to work fine.
134 +        */
135         cpw8(Cmd, RxOn | TxOn);
136 +
137 +       netdev_reset_queue(cp->dev);
138  }
139  
140  static void cp_enable_irq(struct cp_private *cp)
141 @@ -969,7 +1008,6 @@ static void cp_enable_irq(struct cp_priv
142  static void cp_init_hw (struct cp_private *cp)
143  {
144         struct net_device *dev = cp->dev;
145 -       dma_addr_t ring_dma;
146  
147         cp_reset_hw(cp);
148  
149 @@ -979,17 +1017,6 @@ static void cp_init_hw (struct cp_privat
150         cpw32_f (MAC0 + 0, le32_to_cpu (*(__le32 *) (dev->dev_addr + 0)));
151         cpw32_f (MAC0 + 4, le32_to_cpu (*(__le32 *) (dev->dev_addr + 4)));
152  
153 -       cpw32_f(HiTxRingAddr, 0);
154 -       cpw32_f(HiTxRingAddr + 4, 0);
155 -
156 -       ring_dma = cp->ring_dma;
157 -       cpw32_f(RxRingAddr, ring_dma & 0xffffffff);
158 -       cpw32_f(RxRingAddr + 4, (ring_dma >> 16) >> 16);
159 -
160 -       ring_dma += sizeof(struct cp_desc) * CP_RX_RING_SIZE;
161 -       cpw32_f(TxRingAddr, ring_dma & 0xffffffff);
162 -       cpw32_f(TxRingAddr + 4, (ring_dma >> 16) >> 16);
163 -
164         cp_start_hw(cp);
165         cpw8(TxThresh, 0x06); /* XXX convert magic num to a constant */
166  
167 @@ -1192,6 +1219,7 @@ static void cp_tx_timeout(struct net_dev
168         cp_clean_rings(cp);
169         rc = cp_init_rings(cp);
170         cp_start_hw(cp);
171 +       cp_enable_irq(cp);
172  
173         netif_wake_queue(dev);
174