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-02-08 20:04:58.000000000 +0100
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);
51 + atomic_dec(&priv->reset_pending);
53 + for (i = 0; i < CPMAC_QUEUES; i++) {
54 + netif_wake_subqueue(priv->dev, i);
56 + netif_wake_queue(priv->dev);
59 +static void cpmac_check_status(struct net_device *dev)
61 + struct cpmac_priv *priv = netdev_priv(dev);
63 + u32 macstatus = cpmac_read(priv->regs, CPMAC_MAC_STATUS);
64 + int rx_channel = (macstatus >> 8) & 7;
65 + int rx_code = (macstatus >> 12) & 15;
66 + int tx_channel = (macstatus >> 16) & 7;
67 + int tx_code = (macstatus >> 20) & 15;
69 + if (rx_code || tx_code) {
70 + if (netif_msg_drv(priv) && net_ratelimit()) {
71 + /* Can't find any documentation on what these error codes actually are.
72 + * So just log them and hope..
75 + printk(KERN_WARNING "%s: host error %d on rx channel %d (macstatus %08x), resetting\n",
76 + dev->name, rx_code, rx_channel, macstatus);
78 + printk(KERN_WARNING "%s: host error %d on tx channel %d (macstatus %08x), resetting\n",
79 + dev->name, tx_code, tx_channel, macstatus);
82 + netif_stop_queue(dev);
84 + if (schedule_work(&priv->reset_work))
85 + atomic_inc(&priv->reset_pending);
86 + if (unlikely(netif_msg_hw(priv)))
87 + cpmac_dump_regs(dev);
89 napi_enable(&priv->napi);
90 - netif_start_queue(priv->dev);
93 static irqreturn_t cpmac_irq(int irq, void *dev_id)
101 priv = netdev_priv(dev);
103 status = cpmac_read(priv->regs, CPMAC_MAC_INT_VECTOR);
104 @@ -685,49 +725,33 @@
106 cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
108 - if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS))) {
109 - if (netif_msg_drv(priv) && net_ratelimit())
110 - printk(KERN_ERR "%s: hw error, resetting...\n",
112 - netif_stop_queue(dev);
113 - napi_disable(&priv->napi);
114 - cpmac_hw_stop(dev);
115 - schedule_work(&priv->reset_work);
116 - if (unlikely(netif_msg_hw(priv)))
117 - cpmac_dump_regs(dev);
119 + if (unlikely(status & (MAC_INT_HOST | MAC_INT_STATUS)))
120 + cpmac_check_status(dev);
125 static void cpmac_tx_timeout(struct net_device *dev)
127 - struct cpmac_priv *priv = netdev_priv(dev);
129 + struct cpmac_priv *priv = netdev_priv(dev);
131 spin_lock(&priv->lock);
132 dev->stats.tx_errors++;
133 spin_unlock(&priv->lock);
134 if (netif_msg_tx_err(priv) && net_ratelimit())
135 printk(KERN_WARNING "%s: transmit timeout\n", dev->name);
137 - * FIXME: waking up random queue is not the best thing to
138 - * do... on the other hand why we got here at all?
140 -#ifdef CONFIG_NETDEVICES_MULTIQUEUE
141 - for (i = 0; i < CPMAC_QUEUES; i++)
142 - if (priv->desc_ring[i].skb) {
143 - priv->desc_ring[i].dataflags = 0;
144 - dev_kfree_skb_any(priv->desc_ring[i].skb);
145 - netif_wake_subqueue(dev, i);
149 - priv->desc_ring[0].dataflags = 0;
150 - if (priv->desc_ring[0].skb)
151 - dev_kfree_skb_any(priv->desc_ring[0].skb);
152 - netif_wake_queue(dev);
155 + atomic_inc(&priv->reset_pending);
157 + cpmac_clear_tx(dev);
159 + atomic_dec(&priv->reset_pending);
161 + netif_wake_queue(priv->dev);
162 + for (i = 0; i < CPMAC_QUEUES; i++) {
163 + netif_wake_subqueue(dev, i);
167 static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
169 spin_unlock(&priv->lock);
172 -static int cpmac_link_update(struct net_device *dev,
173 - struct fixed_phy_status *status)
176 - status->speed = 100;
177 - status->duplex = 1;
181 static int cpmac_open(struct net_device *dev)
188 + atomic_set(&priv->reset_pending, 0);
189 INIT_WORK(&priv->reset_work, cpmac_hw_error);
192 @@ -999,11 +1015,11 @@
193 static int __devinit cpmac_probe(struct platform_device *pdev)
196 + int mdio_bus_id = cpmac_mii.id;
197 struct resource *mem;
198 struct cpmac_priv *priv;
199 struct net_device *dev;
200 struct plat_cpmac_data *pdata;
201 - struct fixed_info *fixed_phy;
202 DECLARE_MAC_BUF(mac);
204 pdata = pdev->dev.platform_data;
205 @@ -1017,9 +1033,23 @@
208 if (phy_id == PHY_MAX_ADDR) {
209 - if (external_switch || dumb_switch)
210 + if (external_switch || dumb_switch) {
211 + struct fixed_phy_status status = {};
216 + * FIXME: this should be in the platform code!
217 + * Since there is not platform code at all (that is,
218 + * no mainline users of that driver), place it here
225 + status.speed = 100;
226 + fixed_phy_add(PHY_POLL, phy_id, &status);
228 printk(KERN_ERR "cpmac: no PHY present\n");
231 @@ -1063,32 +1093,8 @@
232 priv->msg_enable = netif_msg_init(debug_level, 0xff);
233 memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
235 - if (phy_id == 31) {
236 - snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, cpmac_mii.id,
239 - /* Let's try to get a free fixed phy... */
240 - for (i = 0; i < MAX_PHY_AMNT; i++) {
241 - fixed_phy = fixed_mdio_get_phydev(i);
244 - if (!fixed_phy->phydev->attached_dev) {
245 - strncpy(priv->phy_name,
246 - fixed_phy->phydev->dev.bus_id,
248 - fixed_mdio_set_link_update(fixed_phy->phydev,
249 - &cpmac_link_update);
253 - if (netif_msg_drv(priv))
254 - printk(KERN_ERR "%s: Could not find fixed PHY\n",
259 + snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
262 priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0,
263 PHY_INTERFACE_MODE_MII);
264 if (IS_ERR(priv->phy)) {