1 --- linux-2.6.24/drivers/net/cpmac.c 2008-01-25 02:20:37.000000000 +0100
2 +++ linux-2.6.24/drivers/net/cpmac.c 2008-04-06 21:30:03.000000000 +0200
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)
103 priv = netdev_priv(dev);
105 status = cpmac_read(priv->regs, CPMAC_MAC_INT_VECTOR);
106 @@ -685,49 +726,33 @@
108 cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
110 - if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS))) {
111 - if (netif_msg_drv(priv) && net_ratelimit())
112 - printk(KERN_ERR "%s: hw error, resetting...\n",
114 - netif_stop_queue(dev);
115 - napi_disable(&priv->napi);
116 - cpmac_hw_stop(dev);
117 - schedule_work(&priv->reset_work);
118 - if (unlikely(netif_msg_hw(priv)))
119 - cpmac_dump_regs(dev);
121 + if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS)))
122 + cpmac_check_status(dev);
127 static void cpmac_tx_timeout(struct net_device *dev)
129 - struct cpmac_priv *priv = netdev_priv(dev);
131 + struct cpmac_priv *priv = netdev_priv(dev);
133 spin_lock(&priv->lock);
134 dev->stats.tx_errors++;
135 spin_unlock(&priv->lock);
136 if (netif_msg_tx_err(priv) && net_ratelimit())
137 printk(KERN_WARNING "%s: transmit timeout\n", dev->name);
139 - * FIXME: waking up random queue is not the best thing to
140 - * do... on the other hand why we got here at all?
142 -#ifdef CONFIG_NETDEVICES_MULTIQUEUE
143 - for (i = 0; i < CPMAC_QUEUES; i++)
144 - if (priv->desc_ring[i].skb) {
145 - priv->desc_ring[i].dataflags = 0;
146 - dev_kfree_skb_any(priv->desc_ring[i].skb);
147 - netif_wake_subqueue(dev, i);
151 - priv->desc_ring[0].dataflags = 0;
152 - if (priv->desc_ring[0].skb)
153 - dev_kfree_skb_any(priv->desc_ring[0].skb);
154 - netif_wake_queue(dev);
157 + atomic_inc(&priv->reset_pending);
159 + cpmac_clear_tx(dev);
161 + atomic_dec(&priv->reset_pending);
163 + netif_wake_queue(priv->dev);
164 + for (i = 0; i < CPMAC_QUEUES; i++) {
165 + netif_wake_subqueue(dev, i);
169 static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
171 spin_unlock(&priv->lock);
174 -static int cpmac_link_update(struct net_device *dev,
175 - struct fixed_phy_status *status)
178 - status->speed = 100;
179 - status->duplex = 1;
183 static int cpmac_open(struct net_device *dev)
190 + atomic_set(&priv->reset_pending, 0);
191 INIT_WORK(&priv->reset_work, cpmac_hw_error);
194 @@ -999,11 +1016,11 @@
195 static int __devinit cpmac_probe(struct platform_device *pdev)
198 + int mdio_bus_id = cpmac_mii.id;
199 struct resource *mem;
200 struct cpmac_priv *priv;
201 struct net_device *dev;
202 struct plat_cpmac_data *pdata;
203 - struct fixed_info *fixed_phy;
204 DECLARE_MAC_BUF(mac);
206 pdata = pdev->dev.platform_data;
207 @@ -1017,9 +1034,23 @@
210 if (phy_id == PHY_MAX_ADDR) {
211 - if (external_switch || dumb_switch)
212 + if (external_switch || dumb_switch) {
213 + struct fixed_phy_status status = {};
218 + * FIXME: this should be in the platform code!
219 + * Since there is not platform code at all (that is,
220 + * no mainline users of that driver), place it here
227 + status.speed = 100;
228 + fixed_phy_add(PHY_POLL, phy_id, &status);
230 printk(KERN_ERR "cpmac: no PHY present\n");
233 @@ -1063,32 +1094,8 @@
234 priv->msg_enable = netif_msg_init(debug_level, 0xff);
235 memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
237 - if (phy_id == 31) {
238 - snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, cpmac_mii.id,
241 - /* Let's try to get a free fixed phy... */
242 - for (i = 0; i < MAX_PHY_AMNT; i++) {
243 - fixed_phy = fixed_mdio_get_phydev(i);
246 - if (!fixed_phy->phydev->attached_dev) {
247 - strncpy(priv->phy_name,
248 - fixed_phy->phydev->dev.bus_id,
250 - fixed_mdio_set_link_update(fixed_phy->phydev,
251 - &cpmac_link_update);
255 - if (netif_msg_drv(priv))
256 - printk(KERN_ERR "%s: Could not find fixed PHY\n",
261 + snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
264 priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0,
265 PHY_INTERFACE_MODE_MII);
266 if (IS_ERR(priv->phy)) {