Commit 67d129d1 authored by Eugene Konev's avatar Eugene Konev Committed by Jeff Garzik

cpmac: convert to napi_struct interface

Convert cpmac to new napi_struct API introduced by
bea3348e [NET]: Make NAPI polling independent
of struct net_device objects.
Only disable rx interrupts if napi actually has been scheduled.
Signed-off-by: default avatarEugene Konev <ejka@imfi.kspu.ru>
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent df523b5c
...@@ -205,6 +205,7 @@ struct cpmac_priv { ...@@ -205,6 +205,7 @@ struct cpmac_priv {
struct net_device *dev; struct net_device *dev;
struct work_struct reset_work; struct work_struct reset_work;
struct platform_device *pdev; struct platform_device *pdev;
struct napi_struct napi;
}; };
static irqreturn_t cpmac_irq(int, void *); static irqreturn_t cpmac_irq(int, void *);
...@@ -356,47 +357,48 @@ static void cpmac_set_multicast_list(struct net_device *dev) ...@@ -356,47 +357,48 @@ static void cpmac_set_multicast_list(struct net_device *dev)
} }
} }
static struct sk_buff *cpmac_rx_one(struct net_device *dev, static struct sk_buff *cpmac_rx_one(struct cpmac_priv *priv,
struct cpmac_priv *priv,
struct cpmac_desc *desc) struct cpmac_desc *desc)
{ {
struct sk_buff *skb, *result = NULL; struct sk_buff *skb, *result = NULL;
if (unlikely(netif_msg_hw(priv))) if (unlikely(netif_msg_hw(priv)))
cpmac_dump_desc(dev, desc); cpmac_dump_desc(priv->dev, desc);
cpmac_write(priv->regs, CPMAC_RX_ACK(0), (u32)desc->mapping); cpmac_write(priv->regs, CPMAC_RX_ACK(0), (u32)desc->mapping);
if (unlikely(!desc->datalen)) { if (unlikely(!desc->datalen)) {
if (netif_msg_rx_err(priv) && net_ratelimit()) if (netif_msg_rx_err(priv) && net_ratelimit())
printk(KERN_WARNING "%s: rx: spurious interrupt\n", printk(KERN_WARNING "%s: rx: spurious interrupt\n",
dev->name); priv->dev->name);
return NULL; return NULL;
} }
skb = netdev_alloc_skb(dev, CPMAC_SKB_SIZE); skb = netdev_alloc_skb(priv->dev, CPMAC_SKB_SIZE);
if (likely(skb)) { if (likely(skb)) {
skb_reserve(skb, 2); skb_reserve(skb, 2);
skb_put(desc->skb, desc->datalen); skb_put(desc->skb, desc->datalen);
desc->skb->protocol = eth_type_trans(desc->skb, dev); desc->skb->protocol = eth_type_trans(desc->skb, priv->dev);
desc->skb->ip_summed = CHECKSUM_NONE; desc->skb->ip_summed = CHECKSUM_NONE;
dev->stats.rx_packets++; priv->dev->stats.rx_packets++;
dev->stats.rx_bytes += desc->datalen; priv->dev->stats.rx_bytes += desc->datalen;
result = desc->skb; result = desc->skb;
dma_unmap_single(&dev->dev, desc->data_mapping, CPMAC_SKB_SIZE, dma_unmap_single(&priv->dev->dev, desc->data_mapping,
DMA_FROM_DEVICE); CPMAC_SKB_SIZE, DMA_FROM_DEVICE);
desc->skb = skb; desc->skb = skb;
desc->data_mapping = dma_map_single(&dev->dev, skb->data, desc->data_mapping = dma_map_single(&priv->dev->dev, skb->data,
CPMAC_SKB_SIZE, CPMAC_SKB_SIZE,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
desc->hw_data = (u32)desc->data_mapping; desc->hw_data = (u32)desc->data_mapping;
if (unlikely(netif_msg_pktdata(priv))) { if (unlikely(netif_msg_pktdata(priv))) {
printk(KERN_DEBUG "%s: received packet:\n", dev->name); printk(KERN_DEBUG "%s: received packet:\n",
cpmac_dump_skb(dev, result); priv->dev->name);
cpmac_dump_skb(priv->dev, result);
} }
} else { } else {
if (netif_msg_rx_err(priv) && net_ratelimit()) if (netif_msg_rx_err(priv) && net_ratelimit())
printk(KERN_WARNING printk(KERN_WARNING
"%s: low on skbs, dropping packet\n", dev->name); "%s: low on skbs, dropping packet\n",
dev->stats.rx_dropped++; priv->dev->name);
priv->dev->stats.rx_dropped++;
} }
desc->buflen = CPMAC_SKB_SIZE; desc->buflen = CPMAC_SKB_SIZE;
...@@ -405,25 +407,25 @@ static struct sk_buff *cpmac_rx_one(struct net_device *dev, ...@@ -405,25 +407,25 @@ static struct sk_buff *cpmac_rx_one(struct net_device *dev,
return result; return result;
} }
static int cpmac_poll(struct net_device *dev, int *budget) static int cpmac_poll(struct napi_struct *napi, int budget)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct cpmac_desc *desc; struct cpmac_desc *desc;
int received = 0, quota = min(dev->quota, *budget); int received = 0;
struct cpmac_priv *priv = netdev_priv(dev); struct cpmac_priv *priv = container_of(napi, struct cpmac_priv, napi);
spin_lock(&priv->rx_lock); spin_lock(&priv->rx_lock);
if (unlikely(!priv->rx_head)) { if (unlikely(!priv->rx_head)) {
if (netif_msg_rx_err(priv) && net_ratelimit()) if (netif_msg_rx_err(priv) && net_ratelimit())
printk(KERN_WARNING "%s: rx: polling, but no queue\n", printk(KERN_WARNING "%s: rx: polling, but no queue\n",
dev->name); priv->dev->name);
netif_rx_complete(dev); netif_rx_complete(priv->dev, napi);
return 0; return 0;
} }
desc = priv->rx_head; desc = priv->rx_head;
while ((received < quota) && ((desc->dataflags & CPMAC_OWN) == 0)) { while (((desc->dataflags & CPMAC_OWN) == 0) && (received < budget)) {
skb = cpmac_rx_one(dev, priv, desc); skb = cpmac_rx_one(priv, desc);
if (likely(skb)) { if (likely(skb)) {
netif_receive_skb(skb); netif_receive_skb(skb);
received++; received++;
...@@ -433,13 +435,11 @@ static int cpmac_poll(struct net_device *dev, int *budget) ...@@ -433,13 +435,11 @@ static int cpmac_poll(struct net_device *dev, int *budget)
priv->rx_head = desc; priv->rx_head = desc;
spin_unlock(&priv->rx_lock); spin_unlock(&priv->rx_lock);
*budget -= received;
dev->quota -= received;
if (unlikely(netif_msg_rx_status(priv))) if (unlikely(netif_msg_rx_status(priv)))
printk(KERN_DEBUG "%s: poll processed %d packets\n", dev->name, printk(KERN_DEBUG "%s: poll processed %d packets\n",
received); priv->dev->name, received);
if (desc->dataflags & CPMAC_OWN) { if (desc->dataflags & CPMAC_OWN) {
netif_rx_complete(dev); netif_rx_complete(priv->dev, napi);
cpmac_write(priv->regs, CPMAC_RX_PTR(0), (u32)desc->mapping); cpmac_write(priv->regs, CPMAC_RX_PTR(0), (u32)desc->mapping);
cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1); cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1);
return 0; return 0;
...@@ -649,6 +649,7 @@ static void cpmac_hw_error(struct work_struct *work) ...@@ -649,6 +649,7 @@ static void cpmac_hw_error(struct work_struct *work)
spin_unlock(&priv->rx_lock); spin_unlock(&priv->rx_lock);
cpmac_clear_tx(priv->dev); cpmac_clear_tx(priv->dev);
cpmac_hw_start(priv->dev); cpmac_hw_start(priv->dev);
napi_enable(&priv->napi);
netif_start_queue(priv->dev); netif_start_queue(priv->dev);
} }
...@@ -675,8 +676,10 @@ static irqreturn_t cpmac_irq(int irq, void *dev_id) ...@@ -675,8 +676,10 @@ static irqreturn_t cpmac_irq(int irq, void *dev_id)
if (status & MAC_INT_RX) { if (status & MAC_INT_RX) {
queue = (status >> 8) & 7; queue = (status >> 8) & 7;
netif_rx_schedule(dev); if (netif_rx_schedule_prep(dev, &priv->napi)) {
cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 1 << queue); cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 1 << queue);
__netif_rx_schedule(dev, &priv->napi);
}
} }
cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0); cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
...@@ -686,6 +689,7 @@ static irqreturn_t cpmac_irq(int irq, void *dev_id) ...@@ -686,6 +689,7 @@ static irqreturn_t cpmac_irq(int irq, void *dev_id)
printk(KERN_ERR "%s: hw error, resetting...\n", printk(KERN_ERR "%s: hw error, resetting...\n",
dev->name); dev->name);
netif_stop_queue(dev); netif_stop_queue(dev);
napi_disable(&priv->napi);
cpmac_hw_stop(dev); cpmac_hw_stop(dev);
schedule_work(&priv->reset_work); schedule_work(&priv->reset_work);
if (unlikely(netif_msg_hw(priv))) if (unlikely(netif_msg_hw(priv)))
...@@ -921,6 +925,7 @@ static int cpmac_open(struct net_device *dev) ...@@ -921,6 +925,7 @@ static int cpmac_open(struct net_device *dev)
INIT_WORK(&priv->reset_work, cpmac_hw_error); INIT_WORK(&priv->reset_work, cpmac_hw_error);
cpmac_hw_start(dev); cpmac_hw_start(dev);
napi_enable(&priv->napi);
priv->phy->state = PHY_CHANGELINK; priv->phy->state = PHY_CHANGELINK;
phy_start(priv->phy); phy_start(priv->phy);
...@@ -959,6 +964,7 @@ static int cpmac_stop(struct net_device *dev) ...@@ -959,6 +964,7 @@ static int cpmac_stop(struct net_device *dev)
netif_stop_queue(dev); netif_stop_queue(dev);
cancel_work_sync(&priv->reset_work); cancel_work_sync(&priv->reset_work);
napi_disable(&priv->napi);
phy_stop(priv->phy); phy_stop(priv->phy);
phy_disconnect(priv->phy); phy_disconnect(priv->phy);
priv->phy = NULL; priv->phy = NULL;
...@@ -1048,10 +1054,10 @@ static int __devinit cpmac_probe(struct platform_device *pdev) ...@@ -1048,10 +1054,10 @@ static int __devinit cpmac_probe(struct platform_device *pdev)
dev->set_multicast_list = cpmac_set_multicast_list; dev->set_multicast_list = cpmac_set_multicast_list;
dev->tx_timeout = cpmac_tx_timeout; dev->tx_timeout = cpmac_tx_timeout;
dev->ethtool_ops = &cpmac_ethtool_ops; dev->ethtool_ops = &cpmac_ethtool_ops;
dev->poll = cpmac_poll;
dev->weight = 64;
dev->features |= NETIF_F_MULTI_QUEUE; dev->features |= NETIF_F_MULTI_QUEUE;
netif_napi_add(dev, &priv->napi, cpmac_poll, 64);
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
spin_lock_init(&priv->rx_lock); spin_lock_init(&priv->rx_lock);
priv->dev = dev; priv->dev = dev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment