aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ps3_gelic_net.c
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@linux-foundation.org>2007-10-03 19:41:36 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:47:45 -0400
commitbea3348eef27e6044b6161fd04c3152215f96411 (patch)
treef0990b263e5ce42505d290a4c346fe990bcd4c33 /drivers/net/ps3_gelic_net.c
parentdde4e47e8fe333a5649a3fa0e7db1fa7c08d6158 (diff)
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net device, and some have a single interrupt doorbell for several queues. In either case, it's easier to support layouts like that if the structure representing the poll is independant from the net device itself. The signature of the ->poll() call back goes from: int foo_poll(struct net_device *dev, int *budget) to int foo_poll(struct napi_struct *napi, int budget) The caller is returned the number of RX packets processed (or the number of "NAPI credits" consumed if you want to get abstract). The callee no longer messes around bumping dev->quota, *budget, etc. because that is all handled in the caller upon return. The napi_struct is to be embedded in the device driver private data structures. Furthermore, it is the driver's responsibility to disable all NAPI instances in it's ->stop() device close handler. Since the napi_struct is privatized into the driver's private data structures, only the driver knows how to get at all of the napi_struct instances it may have per-device. With lots of help and suggestions from Rusty Russell, Roland Dreier, Michael Chan, Jeff Garzik, and Jamal Hadi Salim. Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra, Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan. [ Ported to current tree and all drivers converted. Integrated Stephen's follow-on kerneldoc additions, and restored poll_list handling to the old style to fix mutual exclusion issues. -DaveM ] Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ps3_gelic_net.c')
-rw-r--r--drivers/net/ps3_gelic_net.c45
1 files changed, 20 insertions, 25 deletions
diff --git a/drivers/net/ps3_gelic_net.c b/drivers/net/ps3_gelic_net.c
index e56503918436..92561c0450bc 100644
--- a/drivers/net/ps3_gelic_net.c
+++ b/drivers/net/ps3_gelic_net.c
@@ -556,6 +556,7 @@ static int gelic_net_stop(struct net_device *netdev)
556{ 556{
557 struct gelic_net_card *card = netdev_priv(netdev); 557 struct gelic_net_card *card = netdev_priv(netdev);
558 558
559 napi_disable(&card->napi);
559 netif_stop_queue(netdev); 560 netif_stop_queue(netdev);
560 561
561 /* turn off DMA, force end */ 562 /* turn off DMA, force end */
@@ -987,32 +988,24 @@ refill:
987 * if the quota is exceeded, but the driver has still packets. 988 * if the quota is exceeded, but the driver has still packets.
988 * 989 *
989 */ 990 */
990static int gelic_net_poll(struct net_device *netdev, int *budget) 991static int gelic_net_poll(struct napi_struct *napi, int budget)
991{ 992{
992 struct gelic_net_card *card = netdev_priv(netdev); 993 struct gelic_net_card *card = container_of(napi, struct gelic_net_card, napi);
993 int packets_to_do, packets_done = 0; 994 struct net_device *netdev = card->netdev;
994 int no_more_packets = 0; 995 int packets_done = 0;
995
996 packets_to_do = min(*budget, netdev->quota);
997 996
998 while (packets_to_do) { 997 while (packets_done < budget) {
999 if (gelic_net_decode_one_descr(card)) { 998 if (!gelic_net_decode_one_descr(card))
1000 packets_done++;
1001 packets_to_do--;
1002 } else {
1003 /* no more packets for the stack */
1004 no_more_packets = 1;
1005 break; 999 break;
1006 } 1000
1001 packets_done++;
1007 } 1002 }
1008 netdev->quota -= packets_done; 1003
1009 *budget -= packets_done; 1004 if (packets_done < budget) {
1010 if (no_more_packets) { 1005 netif_rx_complete(netdev, napi);
1011 netif_rx_complete(netdev);
1012 gelic_net_rx_irq_on(card); 1006 gelic_net_rx_irq_on(card);
1013 return 0; 1007 }
1014 } else 1008 return packets_done;
1015 return 1;
1016} 1009}
1017/** 1010/**
1018 * gelic_net_change_mtu - changes the MTU of an interface 1011 * gelic_net_change_mtu - changes the MTU of an interface
@@ -1055,7 +1048,7 @@ static irqreturn_t gelic_net_interrupt(int irq, void *ptr)
1055 1048
1056 if (status & GELIC_NET_RXINT) { 1049 if (status & GELIC_NET_RXINT) {
1057 gelic_net_rx_irq_off(card); 1050 gelic_net_rx_irq_off(card);
1058 netif_rx_schedule(netdev); 1051 netif_rx_schedule(netdev, &card->napi);
1059 } 1052 }
1060 1053
1061 if (status & GELIC_NET_TXINT) { 1054 if (status & GELIC_NET_TXINT) {
@@ -1159,6 +1152,8 @@ static int gelic_net_open(struct net_device *netdev)
1159 if (gelic_net_alloc_rx_skbs(card)) 1152 if (gelic_net_alloc_rx_skbs(card))
1160 goto alloc_skbs_failed; 1153 goto alloc_skbs_failed;
1161 1154
1155 napi_enable(&card->napi);
1156
1162 card->tx_dma_progress = 0; 1157 card->tx_dma_progress = 0;
1163 card->ghiintmask = GELIC_NET_RXINT | GELIC_NET_TXINT; 1158 card->ghiintmask = GELIC_NET_RXINT | GELIC_NET_TXINT;
1164 1159
@@ -1360,9 +1355,6 @@ static void gelic_net_setup_netdev_ops(struct net_device *netdev)
1360 /* tx watchdog */ 1355 /* tx watchdog */
1361 netdev->tx_timeout = &gelic_net_tx_timeout; 1356 netdev->tx_timeout = &gelic_net_tx_timeout;
1362 netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT; 1357 netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
1363 /* NAPI */
1364 netdev->poll = &gelic_net_poll;
1365 netdev->weight = GELIC_NET_NAPI_WEIGHT;
1366 netdev->ethtool_ops = &gelic_net_ethtool_ops; 1358 netdev->ethtool_ops = &gelic_net_ethtool_ops;
1367} 1359}
1368 1360
@@ -1390,6 +1382,9 @@ static int gelic_net_setup_netdev(struct gelic_net_card *card)
1390 1382
1391 gelic_net_setup_netdev_ops(netdev); 1383 gelic_net_setup_netdev_ops(netdev);
1392 1384
1385 netif_napi_add(netdev, &card->napi,
1386 gelic_net_poll, GELIC_NET_NAPI_WEIGHT);
1387
1393 netdev->features = NETIF_F_IP_CSUM; 1388 netdev->features = NETIF_F_IP_CSUM;
1394 1389
1395 status = lv1_net_control(bus_id(card), dev_id(card), 1390 status = lv1_net_control(bus_id(card), dev_id(card),