[ar71xx] create firmware image for the Ubiquiti LS-SR71 board
[openwrt.git] / target / linux / ar7 / patches-2.6.25 / 140-cpmac_fix.patch
1 --- a/drivers/net/cpmac.c
2 +++ b/drivers/net/cpmac.c
3 @@ -38,6 +38,7 @@
4  #include <linux/platform_device.h>
5  #include <linux/dma-mapping.h>
6  #include <asm/gpio.h>
7 +#include <asm/atomic.h>
8  
9  MODULE_AUTHOR("Eugene Konev <ejka@imfi.kspu.ru>");
10  MODULE_DESCRIPTION("TI AR7 ethernet driver (CPMAC)");
11 @@ -207,6 +208,7 @@
12         struct work_struct reset_work;
13         struct platform_device *pdev;
14         struct napi_struct napi;
15 +       atomic_t reset_pending;
16  };
17  
18  static irqreturn_t cpmac_irq(int, void *);
19 @@ -455,6 +457,9 @@
20         struct cpmac_desc *desc;
21         struct cpmac_priv *priv = netdev_priv(dev);
22  
23 +       if (unlikely(atomic_read(&priv->reset_pending)))
24 +               return NETDEV_TX_BUSY;
25 +
26         if (unlikely(skb_padto(skb, ETH_ZLEN)))
27                 return NETDEV_TX_OK;
28  
29 @@ -634,14 +639,14 @@
30                 priv->desc_ring[i].dataflags = 0;
31                 if (priv->desc_ring[i].skb) {
32                         dev_kfree_skb_any(priv->desc_ring[i].skb);
33 -                       if (netif_subqueue_stopped(dev, i))
34 -                           netif_wake_subqueue(dev, i);
35 +                       priv->desc_ring[i].skb = NULL;
36                 }
37         }
38  }
39  
40  static void cpmac_hw_error(struct work_struct *work)
41  {
42 +       int i;
43         struct cpmac_priv *priv =
44                 container_of(work, struct cpmac_priv, reset_work);
45  
46 @@ -650,8 +655,47 @@
47         spin_unlock(&priv->rx_lock);
48         cpmac_clear_tx(priv->dev);
49         cpmac_hw_start(priv->dev);
50 -       napi_enable(&priv->napi);
51 -       netif_start_queue(priv->dev);
52 +       barrier();
53 +       atomic_dec(&priv->reset_pending);
54 +       
55 +       for (i = 0; i < CPMAC_QUEUES; i++) {
56 +               netif_wake_subqueue(priv->dev, i);
57 +       }
58 +       netif_wake_queue(priv->dev);
59 +       cpmac_write(priv->regs, CPMAC_MAC_INT_ENABLE, 3);
60 +}
61 +
62 +static void cpmac_check_status(struct net_device *dev)
63 +{
64 +       struct cpmac_priv *priv = netdev_priv(dev);
65 +
66 +       u32 macstatus = cpmac_read(priv->regs, CPMAC_MAC_STATUS);
67 +       int rx_channel = (macstatus >> 8) & 7;
68 +       int rx_code = (macstatus >> 12) & 15;
69 +       int tx_channel = (macstatus >> 16) & 7;
70 +       int tx_code = (macstatus >> 20) & 15;
71 +
72 +       if (rx_code || tx_code) {
73 +               if (netif_msg_drv(priv) && net_ratelimit()) {
74 +                       /* Can't find any documentation on what these error codes actually are.
75 +                        * So just log them and hope..
76 +                        */
77 +                       if (rx_code)
78 +                               printk(KERN_WARNING "%s: host error %d on rx channel %d (macstatus %08x), resetting\n",
79 +                                      dev->name, rx_code, rx_channel, macstatus);
80 +                       if (tx_code)
81 +                               printk(KERN_WARNING "%s: host error %d on tx channel %d (macstatus %08x), resetting\n",
82 +                                      dev->name, tx_code, tx_channel, macstatus);
83 +               }
84 +               
85 +               netif_stop_queue(dev);
86 +               cpmac_hw_stop(dev);
87 +               if (schedule_work(&priv->reset_work))
88 +                       atomic_inc(&priv->reset_pending);
89 +               if (unlikely(netif_msg_hw(priv)))
90 +                       cpmac_dump_regs(dev);
91 +       }
92 +       cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff);
93  }
94  
95  static irqreturn_t cpmac_irq(int irq, void *dev_id)
96 @@ -682,49 +726,33 @@
97  
98         cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
99  
100 -       if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS))) {
101 -               if (netif_msg_drv(priv) && net_ratelimit())
102 -                       printk(KERN_ERR "%s: hw error, resetting...\n",
103 -                              dev->name);
104 -               netif_stop_queue(dev);
105 -               napi_disable(&priv->napi);
106 -               cpmac_hw_stop(dev);
107 -               schedule_work(&priv->reset_work);
108 -               if (unlikely(netif_msg_hw(priv)))
109 -                       cpmac_dump_regs(dev);
110 -       }
111 +       if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS)))
112 +               cpmac_check_status(dev);
113  
114         return IRQ_HANDLED;
115  }
116  
117  static void cpmac_tx_timeout(struct net_device *dev)
118  {
119 -       struct cpmac_priv *priv = netdev_priv(dev);
120         int i;
121 +       struct cpmac_priv *priv = netdev_priv(dev);
122  
123         spin_lock(&priv->lock);
124         dev->stats.tx_errors++;
125         spin_unlock(&priv->lock);
126         if (netif_msg_tx_err(priv) && net_ratelimit())
127                 printk(KERN_WARNING "%s: transmit timeout\n", dev->name);
128 -       /* 
129 -        * FIXME: waking up random queue is not the best thing to
130 -        * do... on the other hand why we got here at all?
131 -        */
132 -#ifdef CONFIG_NETDEVICES_MULTIQUEUE
133 -       for (i = 0; i < CPMAC_QUEUES; i++)
134 -               if (priv->desc_ring[i].skb) {
135 -                       priv->desc_ring[i].dataflags = 0;
136 -                       dev_kfree_skb_any(priv->desc_ring[i].skb);
137 -                       netif_wake_subqueue(dev, i);
138 -                       break;
139 -               }
140 -#else
141 -       priv->desc_ring[0].dataflags = 0;
142 -       if (priv->desc_ring[0].skb)
143 -               dev_kfree_skb_any(priv->desc_ring[0].skb);
144 -       netif_wake_queue(dev);
145 -#endif
146 +
147 +       atomic_inc(&priv->reset_pending);
148 +       barrier();
149 +       cpmac_clear_tx(dev);
150 +       barrier();
151 +       atomic_dec(&priv->reset_pending);
152 +
153 +       netif_wake_queue(priv->dev);
154 +       for (i = 0; i < CPMAC_QUEUES; i++) {
155 +               netif_wake_subqueue(dev, i);
156 +       }
157  }
158  
159  static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
160 @@ -911,6 +939,7 @@
161                 goto fail_irq;
162         }
163  
164 +       atomic_set(&priv->reset_pending, 0);
165         INIT_WORK(&priv->reset_work, cpmac_hw_error);
166         cpmac_hw_start(dev);
167