Hi,
[openwrt.git] / target / linux / ar7 / patches-2.6.24 / 140-cpmac_fix.patch
1 Index: linux-2.6.24.7/drivers/net/cpmac.c
2 ===================================================================
3 --- linux-2.6.24.7.orig/drivers/net/cpmac.c
4 +++ linux-2.6.24.7/drivers/net/cpmac.c
5 @@ -38,6 +38,7 @@
6 #include <linux/platform_device.h>
7 #include <linux/dma-mapping.h>
8 #include <asm/gpio.h>
9 +#include <asm/atomic.h>
10
11 MODULE_AUTHOR("Eugene Konev <ejka@imfi.kspu.ru>");
12 MODULE_DESCRIPTION("TI AR7 ethernet driver (CPMAC)");
13 @@ -207,6 +208,7 @@ struct cpmac_priv {
14 struct work_struct reset_work;
15 struct platform_device *pdev;
16 struct napi_struct napi;
17 + atomic_t reset_pending;
18 };
19
20 static irqreturn_t cpmac_irq(int, void *);
21 @@ -455,6 +457,9 @@ static int cpmac_start_xmit(struct sk_bu
22 struct cpmac_desc *desc;
23 struct cpmac_priv *priv = netdev_priv(dev);
24
25 + if (unlikely(atomic_read(&priv->reset_pending)))
26 + return NETDEV_TX_BUSY;
27 +
28 if (unlikely(skb_padto(skb, ETH_ZLEN)))
29 return NETDEV_TX_OK;
30
31 @@ -634,14 +639,14 @@ static void cpmac_clear_tx(struct net_de
32 priv->desc_ring[i].dataflags = 0;
33 if (priv->desc_ring[i].skb) {
34 dev_kfree_skb_any(priv->desc_ring[i].skb);
35 - if (netif_subqueue_stopped(dev, i))
36 - netif_wake_subqueue(dev, i);
37 + priv->desc_ring[i].skb = NULL;
38 }
39 }
40 }
41
42 static void cpmac_hw_error(struct work_struct *work)
43 {
44 + int i;
45 struct cpmac_priv *priv =
46 container_of(work, struct cpmac_priv, reset_work);
47
48 @@ -650,8 +655,47 @@ static void cpmac_hw_error(struct work_s
49 spin_unlock(&priv->rx_lock);
50 cpmac_clear_tx(priv->dev);
51 cpmac_hw_start(priv->dev);
52 - napi_enable(&priv->napi);
53 - netif_start_queue(priv->dev);
54 + barrier();
55 + atomic_dec(&priv->reset_pending);
56 +
57 + for (i = 0; i < CPMAC_QUEUES; i++) {
58 + netif_wake_subqueue(priv->dev, i);
59 + }
60 + netif_wake_queue(priv->dev);
61 + cpmac_write(priv->regs, CPMAC_MAC_INT_ENABLE, 3);
62 +}
63 +
64 +static void cpmac_check_status(struct net_device *dev)
65 +{
66 + struct cpmac_priv *priv = netdev_priv(dev);
67 +
68 + u32 macstatus = cpmac_read(priv->regs, CPMAC_MAC_STATUS);
69 + int rx_channel = (macstatus >> 8) & 7;
70 + int rx_code = (macstatus >> 12) & 15;
71 + int tx_channel = (macstatus >> 16) & 7;
72 + int tx_code = (macstatus >> 20) & 15;
73 +
74 + if (rx_code || tx_code) {
75 + if (netif_msg_drv(priv) && net_ratelimit()) {
76 + /* Can't find any documentation on what these error codes actually are.
77 + * So just log them and hope..
78 + */
79 + if (rx_code)
80 + printk(KERN_WARNING "%s: host error %d on rx channel %d (macstatus %08x), resetting\n",
81 + dev->name, rx_code, rx_channel, macstatus);
82 + if (tx_code)
83 + printk(KERN_WARNING "%s: host error %d on tx channel %d (macstatus %08x), resetting\n",
84 + dev->name, tx_code, tx_channel, macstatus);
85 + }
86 +
87 + netif_stop_queue(dev);
88 + cpmac_hw_stop(dev);
89 + if (schedule_work(&priv->reset_work))
90 + atomic_inc(&priv->reset_pending);
91 + if (unlikely(netif_msg_hw(priv)))
92 + cpmac_dump_regs(dev);
93 + }
94 + cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff);
95 }
96
97 static irqreturn_t cpmac_irq(int irq, void *dev_id)
98 @@ -661,9 +705,6 @@ static irqreturn_t cpmac_irq(int irq, vo
99 int queue;
100 u32 status;
101
102 - if (!dev)
103 - return IRQ_NONE;
104 -
105 priv = netdev_priv(dev);
106
107 status = cpmac_read(priv->regs, CPMAC_MAC_INT_VECTOR);
108 @@ -685,49 +726,33 @@ static irqreturn_t cpmac_irq(int irq, vo
109
110 cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
111
112 - if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS))) {
113 - if (netif_msg_drv(priv) && net_ratelimit())
114 - printk(KERN_ERR "%s: hw error, resetting...\n",
115 - dev->name);
116 - netif_stop_queue(dev);
117 - napi_disable(&priv->napi);
118 - cpmac_hw_stop(dev);
119 - schedule_work(&priv->reset_work);
120 - if (unlikely(netif_msg_hw(priv)))
121 - cpmac_dump_regs(dev);
122 - }
123 + if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS)))
124 + cpmac_check_status(dev);
125
126 return IRQ_HANDLED;
127 }
128
129 static void cpmac_tx_timeout(struct net_device *dev)
130 {
131 - struct cpmac_priv *priv = netdev_priv(dev);
132 int i;
133 + struct cpmac_priv *priv = netdev_priv(dev);
134
135 spin_lock(&priv->lock);
136 dev->stats.tx_errors++;
137 spin_unlock(&priv->lock);
138 if (netif_msg_tx_err(priv) && net_ratelimit())
139 printk(KERN_WARNING "%s: transmit timeout\n", dev->name);
140 - /*
141 - * FIXME: waking up random queue is not the best thing to
142 - * do... on the other hand why we got here at all?
143 - */
144 -#ifdef CONFIG_NETDEVICES_MULTIQUEUE
145 - for (i = 0; i < CPMAC_QUEUES; i++)
146 - if (priv->desc_ring[i].skb) {
147 - priv->desc_ring[i].dataflags = 0;
148 - dev_kfree_skb_any(priv->desc_ring[i].skb);
149 - netif_wake_subqueue(dev, i);
150 - break;
151 - }
152 -#else
153 - priv->desc_ring[0].dataflags = 0;
154 - if (priv->desc_ring[0].skb)
155 - dev_kfree_skb_any(priv->desc_ring[0].skb);
156 - netif_wake_queue(dev);
157 -#endif
158 +
159 + atomic_inc(&priv->reset_pending);
160 + barrier();
161 + cpmac_clear_tx(dev);
162 + barrier();
163 + atomic_dec(&priv->reset_pending);
164 +
165 + netif_wake_queue(priv->dev);
166 + for (i = 0; i < CPMAC_QUEUES; i++) {
167 + netif_wake_subqueue(dev, i);
168 + }
169 }
170
171 static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
172 @@ -848,15 +873,6 @@ static void cpmac_adjust_link(struct net
173 spin_unlock(&priv->lock);
174 }
175
176 -static int cpmac_link_update(struct net_device *dev,
177 - struct fixed_phy_status *status)
178 -{
179 - status->link = 1;
180 - status->speed = 100;
181 - status->duplex = 1;
182 - return 0;
183 -}
184 -
185 static int cpmac_open(struct net_device *dev)
186 {
187 int i, size, res;
188 @@ -923,6 +939,7 @@ static int cpmac_open(struct net_device
189 goto fail_irq;
190 }
191
192 + atomic_set(&priv->reset_pending, 0);
193 INIT_WORK(&priv->reset_work, cpmac_hw_error);
194 cpmac_hw_start(dev);
195
196 @@ -999,11 +1016,11 @@ static int external_switch;
197 static int __devinit cpmac_probe(struct platform_device *pdev)
198 {
199 int rc, phy_id, i;
200 + int mdio_bus_id = cpmac_mii.id;
201 struct resource *mem;
202 struct cpmac_priv *priv;
203 struct net_device *dev;
204 struct plat_cpmac_data *pdata;
205 - struct fixed_info *fixed_phy;
206 DECLARE_MAC_BUF(mac);
207
208 pdata = pdev->dev.platform_data;
209 @@ -1017,9 +1034,23 @@ static int __devinit cpmac_probe(struct
210 }
211
212 if (phy_id == PHY_MAX_ADDR) {
213 - if (external_switch || dumb_switch)
214 + if (external_switch || dumb_switch) {
215 + struct fixed_phy_status status = {};
216 +
217 + mdio_bus_id = 0;
218 +
219 + /*
220 + * FIXME: this should be in the platform code!
221 + * Since there is not platform code at all (that is,
222 + * no mainline users of that driver), place it here
223 + * for now.
224 + */
225 phy_id = 0;
226 - else {
227 + status.link = 1;
228 + status.duplex = 1;
229 + status.speed = 100;
230 + fixed_phy_add(PHY_POLL, phy_id, &status);
231 + } else {
232 printk(KERN_ERR "cpmac: no PHY present\n");
233 return -ENODEV;
234 }
235 @@ -1063,32 +1094,8 @@ static int __devinit cpmac_probe(struct
236 priv->msg_enable = netif_msg_init(debug_level, 0xff);
237 memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
238
239 - if (phy_id == 31) {
240 - snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, cpmac_mii.id,
241 - phy_id);
242 - } else {
243 - /* Let's try to get a free fixed phy... */
244 - for (i = 0; i < MAX_PHY_AMNT; i++) {
245 - fixed_phy = fixed_mdio_get_phydev(i);
246 - if (!fixed_phy)
247 - continue;
248 - if (!fixed_phy->phydev->attached_dev) {
249 - strncpy(priv->phy_name,
250 - fixed_phy->phydev->dev.bus_id,
251 - BUS_ID_SIZE);
252 - fixed_mdio_set_link_update(fixed_phy->phydev,
253 - &cpmac_link_update);
254 - goto phy_found;
255 - }
256 - }
257 - if (netif_msg_drv(priv))
258 - printk(KERN_ERR "%s: Could not find fixed PHY\n",
259 - dev->name);
260 - rc = -ENODEV;
261 - goto fail;
262 - }
263 + snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
264
265 -phy_found:
266 priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0,
267 PHY_INTERFACE_MODE_MII);
268 if (IS_ERR(priv->phy)) {
This page took 0.055462 seconds and 5 git commands to generate.