1 --- a/drivers/net/cpmac.c
2 +++ b/drivers/net/cpmac.c
4 #include <linux/platform_device.h>
5 #include <linux/dma-mapping.h>
7 +#include <asm/atomic.h>
9 MODULE_AUTHOR("Eugene Konev <ejka@imfi.kspu.ru>");
10 MODULE_DESCRIPTION("TI AR7 ethernet driver (CPMAC)");
12 struct work_struct reset_work;
13 struct platform_device *pdev;
14 struct napi_struct napi;
15 + atomic_t reset_pending;
18 static irqreturn_t cpmac_irq(int, void *);
20 struct cpmac_desc *desc;
21 struct cpmac_priv *priv = netdev_priv(dev);
23 + if (unlikely(atomic_read(&priv->reset_pending)))
24 + return NETDEV_TX_BUSY;
26 if (unlikely(skb_padto(skb, ETH_ZLEN)))
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;
40 static void cpmac_hw_error(struct work_struct *work)
43 struct cpmac_priv *priv =
44 container_of(work, struct cpmac_priv, reset_work);
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);
53 + atomic_dec(&priv->reset_pending);
55 + for (i = 0; i < CPMAC_QUEUES; i++) {
56 + netif_wake_subqueue(priv->dev, i);
58 + netif_wake_queue(priv->dev);
59 + cpmac_write(priv->regs, CPMAC_MAC_INT_ENABLE, 3);
62 +static void cpmac_check_status(struct net_device *dev)
64 + struct cpmac_priv *priv = netdev_priv(dev);
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;
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..
78 + printk(KERN_WARNING "%s: host error %d on rx channel %d (macstatus %08x), resetting\n",
79 + dev->name, rx_code, rx_channel, macstatus);
81 + printk(KERN_WARNING "%s: host error %d on tx channel %d (macstatus %08x), resetting\n",
82 + dev->name, tx_code, tx_channel, macstatus);
85 + netif_stop_queue(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);
92 + cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff);
95 static irqreturn_t cpmac_irq(int irq, void *dev_id)
98 cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
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",
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);
111 + if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS)))
112 + cpmac_check_status(dev);
117 static void cpmac_tx_timeout(struct net_device *dev)
119 - struct cpmac_priv *priv = netdev_priv(dev);
121 + struct cpmac_priv *priv = netdev_priv(dev);
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);
129 - * FIXME: waking up random queue is not the best thing to
130 - * do... on the other hand why we got here at all?
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);
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);
147 + atomic_inc(&priv->reset_pending);
149 + cpmac_clear_tx(dev);
151 + atomic_dec(&priv->reset_pending);
153 + netif_wake_queue(priv->dev);
154 + for (i = 0; i < CPMAC_QUEUES; i++) {
155 + netif_wake_subqueue(dev, i);
159 static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
164 + atomic_set(&priv->reset_pending, 0);
165 INIT_WORK(&priv->reset_work, cpmac_hw_error);