1 --- a/drivers/net/cpmac.c
2 +++ b/drivers/net/cpmac.c
4 #define CPMAC_EOQ 0x1000
6 struct cpmac_desc *next;
7 + struct cpmac_desc *prev;
9 dma_addr_t data_mapping;
15 +static void cpmac_dump_all_desc(struct net_device *dev)
17 + struct cpmac_priv *priv = netdev_priv(dev);
18 + struct cpmac_desc *dump = priv->rx_head;
20 + cpmac_dump_desc(dev, dump);
22 + } while (dump != priv->rx_head);
25 static void cpmac_dump_skb(struct net_device *dev, struct sk_buff *skb)
29 static int cpmac_poll(struct napi_struct *napi, int budget)
32 - struct cpmac_desc *desc;
34 + struct cpmac_desc *desc, *restart;
35 struct cpmac_priv *priv = container_of(napi, struct cpmac_priv, napi);
36 + int received = 0, processed = 0;
38 spin_lock(&priv->rx_lock);
39 if (unlikely(!priv->rx_head)) {
40 if (netif_msg_rx_err(priv) && net_ratelimit())
41 printk(KERN_WARNING "%s: rx: polling, but no queue\n",
43 + spin_unlock(&priv->rx_lock);
44 netif_rx_complete(priv->dev, napi);
50 while (((desc->dataflags & CPMAC_OWN) == 0) && (received < budget)) {
53 + if ((desc->dataflags & CPMAC_EOQ) != 0) {
54 + /* The last update to eoq->hw_next didn't happen soon enough, and the
55 + * receiver stopped here. Remember this descriptor so we can restart
56 + * the receiver after freeing some space.
58 + if (unlikely(restart)) {
59 + if (netif_msg_rx_err(priv))
60 + printk(KERN_ERR "%s: poll found a duplicate EOQ: %p and %p\n",
61 + priv->dev->name, restart, desc);
65 + restart = desc->next;
68 skb = cpmac_rx_one(priv, desc);
70 netif_receive_skb(skb);
75 + if (desc != priv->rx_head) {
76 + /* We freed some buffers, but not the whole ring, add what we did free to the rx list */
77 + desc->prev->hw_next = (u32)0;
78 + priv->rx_head->prev->hw_next = priv->rx_head->mapping;
81 + /* Optimization: If we did not actually process an EOQ (perhaps because of
82 + * quota limits), check to see if the tail of the queue has EOQ set. We
83 + * should immediately restart in that case so that the receiver can restart
84 + * and run in parallel with more packet processing. This lets us handle slightly
85 + * larger bursts before running out of ring space (assuming dev->weight < ring_size)
88 + (priv->rx_head->prev->dataflags & (CPMAC_OWN|CPMAC_EOQ)) == CPMAC_EOQ &&
89 + (priv->rx_head->dataflags & CPMAC_OWN) != 0) {
90 + /* reset EOQ so the poll loop (above) doesn't try to restart this when it
91 + * eventually gets to this descriptor.
93 + priv->rx_head->prev->dataflags &= ~CPMAC_EOQ;
94 + restart = priv->rx_head;
98 + priv->dev->stats.rx_errors++;
99 + priv->dev->stats.rx_fifo_errors++;
100 + if (netif_msg_rx_err(priv) && net_ratelimit())
101 + printk(KERN_WARNING "%s: rx dma ring overrun\n", priv->dev->name);
103 + if (unlikely((restart->dataflags & CPMAC_OWN) == 0)) {
104 + if (netif_msg_drv(priv))
105 + printk(KERN_ERR "%s: cpmac_poll is trying to restart rx from a descriptor that's not free: %p\n",
106 + priv->dev->name, restart);
110 + cpmac_write(priv->regs, CPMAC_RX_PTR(0), restart->mapping);
113 priv->rx_head = desc;
114 spin_unlock(&priv->rx_lock);
115 if (unlikely(netif_msg_rx_status(priv)))
116 printk(KERN_DEBUG "%s: poll processed %d packets\n",
117 priv->dev->name, received);
118 - if (desc->dataflags & CPMAC_OWN) {
119 + if (processed == 0) {
120 + /* we ran out of packets to read, revert to interrupt-driven mode */
121 netif_rx_complete(priv->dev, napi);
122 - cpmac_write(priv->regs, CPMAC_RX_PTR(0), (u32)desc->mapping);
123 cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1);
130 + /* Something went horribly wrong. Reset hardware to try to recover rather than wedging. */
132 + if (netif_msg_drv(priv)) {
133 + printk(KERN_ERR "%s: cpmac_poll is confused. Resetting hardware\n", priv->dev->name);
134 + cpmac_dump_all_desc(priv->dev);
135 + printk(KERN_DEBUG "%s: RX_PTR(0)=0x%08x RX_ACK(0)=0x%08x\n",
137 + cpmac_read(priv->regs, CPMAC_RX_PTR(0)),
138 + cpmac_read(priv->regs, CPMAC_RX_ACK(0)));
141 + spin_unlock(&priv->rx_lock);
142 + netif_rx_complete(priv->dev, napi);
143 + netif_stop_queue(priv->dev);
144 + napi_disable(&priv->napi);
146 + atomic_inc(&priv->reset_pending);
147 + cpmac_hw_stop(priv->dev);
148 + if (!schedule_work(&priv->reset_work))
149 + atomic_dec(&priv->reset_pending);
154 static int cpmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
156 desc->dataflags = CPMAC_OWN;
157 dev->stats.rx_dropped++;
159 + desc->hw_next = desc->next->mapping;
162 + priv->rx_head->prev->hw_next = 0;
165 static void cpmac_clear_tx(struct net_device *dev)
166 @@ -928,9 +1022,12 @@
167 desc->buflen = CPMAC_SKB_SIZE;
168 desc->dataflags = CPMAC_OWN;
169 desc->next = &priv->rx_head[(i + 1) % priv->ring_size];
170 + desc->next->prev = desc;
171 desc->hw_next = (u32)desc->next->mapping;
174 + priv->rx_head->prev->hw_next = (u32)0;
176 if ((res = request_irq(dev->irq, cpmac_irq, IRQF_SHARED,
178 if (netif_msg_drv(priv))