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
6 #include <linux/platform_device.h>
7 #include <linux/dma-mapping.h>
9 +#include <asm/atomic.h>
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;
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);
25 + if (unlikely(atomic_read(&priv->reset_pending)))
26 + return NETDEV_TX_BUSY;
28 if (unlikely(skb_padto(skb, ETH_ZLEN)))
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;
42 static void cpmac_hw_error(struct work_struct *work)
45 struct cpmac_priv *priv =
46 container_of(work, struct cpmac_priv, reset_work);
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);
55 + atomic_dec(&priv->reset_pending);
57 + for (i = 0; i < CPMAC_QUEUES; i++) {
58 + netif_wake_subqueue(priv->dev, i);
60 + netif_wake_queue(priv->dev);
61 + cpmac_write(priv->regs, CPMAC_MAC_INT_ENABLE, 3);
64 +static void cpmac_check_status(struct net_device *dev)
66 + struct cpmac_priv *priv = netdev_priv(dev);
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;
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..
80 + printk(KERN_WARNING "%s: host error %d on rx channel %d (macstatus %08x), resetting\n",
81 + dev->name, rx_code, rx_channel, macstatus);
83 + printk(KERN_WARNING "%s: host error %d on tx channel %d (macstatus %08x), resetting\n",
84 + dev->name, tx_code, tx_channel, macstatus);
87 + netif_stop_queue(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);
94 + cpmac_write(priv->regs, CPMAC_MAC_INT_CLEAR, 0xff);
97 static irqreturn_t cpmac_irq(int irq, void *dev_id)
98 @@ -661,9 +705,6 @@ static irqreturn_t cpmac_irq(int irq, vo
105 priv = netdev_priv(dev);
107 status = cpmac_read(priv->regs, CPMAC_MAC_INT_VECTOR);
108 @@ -685,49 +726,33 @@ static irqreturn_t cpmac_irq(int irq, vo
110 cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
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",
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);
123 + if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS)))
124 + cpmac_check_status(dev);
129 static void cpmac_tx_timeout(struct net_device *dev)
131 - struct cpmac_priv *priv = netdev_priv(dev);
133 + struct cpmac_priv *priv = netdev_priv(dev);
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);
141 - * FIXME: waking up random queue is not the best thing to
142 - * do... on the other hand why we got here at all?
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);
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);
159 + atomic_inc(&priv->reset_pending);
161 + cpmac_clear_tx(dev);
163 + atomic_dec(&priv->reset_pending);
165 + netif_wake_queue(priv->dev);
166 + for (i = 0; i < CPMAC_QUEUES; i++) {
167 + netif_wake_subqueue(dev, i);
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);
176 -static int cpmac_link_update(struct net_device *dev,
177 - struct fixed_phy_status *status)
180 - status->speed = 100;
181 - status->duplex = 1;
185 static int cpmac_open(struct net_device *dev)
188 @@ -923,6 +939,7 @@ static int cpmac_open(struct net_device
192 + atomic_set(&priv->reset_pending, 0);
193 INIT_WORK(&priv->reset_work, cpmac_hw_error);
196 @@ -999,11 +1016,11 @@ static int external_switch;
197 static int __devinit cpmac_probe(struct platform_device *pdev)
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);
208 pdata = pdev->dev.platform_data;
209 @@ -1017,9 +1034,23 @@ static int __devinit cpmac_probe(struct
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 = {};
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
229 + status.speed = 100;
230 + fixed_phy_add(PHY_POLL, phy_id, &status);
232 printk(KERN_ERR "cpmac: no PHY present\n");
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));
239 - if (phy_id == 31) {
240 - snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, cpmac_mii.id,
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);
248 - if (!fixed_phy->phydev->attached_dev) {
249 - strncpy(priv->phy_name,
250 - fixed_phy->phydev->dev.bus_id,
252 - fixed_mdio_set_link_update(fixed_phy->phydev,
253 - &cpmac_link_update);
257 - if (netif_msg_drv(priv))
258 - printk(KERN_ERR "%s: Could not find fixed PHY\n",
263 + snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
266 priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0,
267 PHY_INTERFACE_MODE_MII);
268 if (IS_ERR(priv->phy)) {