Skip to contentSkip to conversation

: napi_struct V6

RFC PATCH In review David Miller 3 participants 5 messages Aug 8, 2007 – Aug 9, 2007

Subsystems (7)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

RFC PATCH 1/1 : napi_struct V6

Changes since V5:

1) Revert unnecessary TX locking changes in bnx2 and tg3

2) ++i

This is probably what I'll check into my net-2.6.24 tree

Thanks.

[NET]: Make NAPI polling independant 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.

[ Ported to current tree and all drivers converted. -DaveM ]

Documentation/networking/NAPI_HOWTO.txt +83 -100
index 7907435..e39f763 100644
@@ -60,39 +60,39 @@ A) DMA ring or enough RAM to store packets in software devices.
 B) Ability to turn off interrupts or maybe events that send packets up 
 the stack.
 
-NAPI processes packet events in what is known as dev->poll() method.
-Typically, only packet receive events are processed in dev->poll(). 
+NAPI processes packet events in what is known as napi->poll() method.
+Typically, only packet receive events are processed in napi->poll(). 
 The rest of the events MAY be processed by the regular interrupt handler 
 to reduce processing latency (justified also because there are not that 
 many of them).
-Note, however, NAPI does not enforce that dev->poll() only processes 
+Note, however, NAPI does not enforce that napi->poll() only processes 
 receive events. 
 Tests with the tulip driver indicated slightly increased latency if
-all of the interrupt handler is moved to dev->poll(). Also MII handling
+all of the interrupt handler is moved to napi->poll(). Also MII handling
 gets a little trickier.
 The example used in this document is to move the receive processing only
-to dev->poll(); this is shown with the patch for the tulip driver.
+to napi->poll(); this is shown with the patch for the tulip driver.
 For an example of code that moves all the interrupt driver to 
-dev->poll() look at the ported e1000 code.
+napi->poll() look at the ported e1000 code.
 
 There are caveats that might force you to go with moving everything to 
-dev->poll(). Different NICs work differently depending on their status/event 
+napi->poll(). Different NICs work differently depending on their status/event 
 acknowledgement setup. 
 There are two types of event register ACK mechanisms.
 	I)  what is known as Clear-on-read (COR).
 	when you read the status/event register, it clears everything!
 	The natsemi and sunbmac NICs are known to do this.
-	In this case your only choice is to move all to dev->poll()
+	In this case your only choice is to move all to napi->poll()
 
 	II) Clear-on-write (COW)
 	 i) you clear the status by writing a 1 in the bit-location you want.
 		These are the majority of the NICs and work the best with NAPI.
-		Put only receive events in dev->poll(); leave the rest in
+		Put only receive events in napi->poll(); leave the rest in
 		the old interrupt handler.
 	 ii) whatever you write in the status register clears every thing ;->
 		Cant seem to find any supported by Linux which do this. If
 		someone knows such a chip email us please.
-		Move all to dev->poll()
+		Move all to napi->poll()
 
 C) Ability to detect new work correctly.
 NAPI works by shutting down event interrupts when there's work and
@@ -110,56 +110,64 @@ discussion.
 Locking rules and environmental guarantees
 ==========================================
 
--Guarantee: Only one CPU at any time can call dev->poll(); this is because
+-Guarantee: Only one CPU at any time can call napi->poll(); this is because
 only one CPU can pick the initial interrupt and hence the initial
-netif_rx_schedule(dev);
+netif_rx_schedule(dev, napi);
 - The core layer invokes devices to send packets in a round robin format.
 This implies receive is totally lockless because of the guarantee that only 
 one CPU is executing it.
 -  contention can only be the result of some other CPU accessing the rx
 ring. This happens only in close() and suspend() (when these methods
-try to clean the rx ring); 
-****guarantee: driver authors need not worry about this; synchronization 
-is taken care for them by the top net layer.
--local interrupts are enabled (if you dont move all to dev->poll()). For 
+try to clean the rx ring);  Therefore the close() and suspend() methods
+must take care to invoke napi_disable() on each NAPI instance assosciated
+with the driver.
+-local interrupts are enabled (if you dont move all to napi->poll()). For 
 example link/MII and txcomplete continue functioning just same old way. 
 This improves the latency of processing these events. It is also assumed that 
 the receive interrupt is the largest cause of noise. Note this might not 
 always be true. 
 [according to Manfred Spraul, the winbond insists on sending one 
 txmitcomplete interrupt for each packet (although this can be mitigated)].
-For these broken drivers, move all to dev->poll().
+For these broken drivers, move all to napi->poll().
 
-For the rest of this text, we'll assume that dev->poll() only
+For the rest of this text, we'll assume that napi->poll() only
 processes receive events.
 
 new methods introduce by NAPI
 =============================
 
-a) netif_rx_schedule(dev)
-Called by an IRQ handler to schedule a poll for device
+a) netif_rx_schedule(dev, napi)
+Called by an IRQ handler to schedule a poll on the given NAPI instance
+for device
 
-b) netif_rx_schedule_prep(dev)
-puts the device in a state which allows for it to be added to the
-CPU polling list if it is up and running. You can look at this as
-the first half of  netif_rx_schedule(dev) above; the second half
-being c) below.
+b) netif_rx_schedule_prep(dev, napi)
+puts given NAPI instance of the device in a state which allows for it
+to be added to the CPU polling list if the device is up and running.
+You can look at this as the first half of netif_rx_schedule(dev, napi)
+above; the second half being c) below.
 
-c) __netif_rx_schedule(dev)
-Add device to the poll list for this CPU; assuming that _prep above
-has already been called and returned 1.
+c) __netif_rx_schedule(dev, napi)
+Add NAPI instance of device to the poll list for this CPU; assuming
+that _prep above has already been called and returned 1.
 
-d) netif_rx_reschedule(dev, undo)
-Called to reschedule polling for device specifically for some
-deficient hardware. Read Appendix 2 for more details.
+d) netif_rx_reschedule(dev, napi)
+Called to reschedule polling for a NAPI instance of a device specifically
+for some deficient hardware. Read Appendix 2 for more details.
 
-e) netif_rx_complete(dev)
-
-Remove interface from the CPU poll list: it must be in the poll list
-on current cpu. This primitive is called by dev->poll(), when
+e) netif_rx_complete(dev, napi)
+Remove NAPI instance of device from the CPU poll list: it must be in the
+poll list on the current cpu. This primitive is called by napi->poll(), when
 it completes its work. The device cannot be out of poll list at this
 call, if it is then clearly it is a BUG(). You'll know ;->
 
+f) netif_napi_add(dev, napi, poll, weight)
+Register a NAPI instance for the given device, using the given
+'poll' handler and device weight 'weight'.  For most devices, a
+"struct napi_struct" will be embedded in the netdevice private
+structure, and given as the second argument here.  For more complicated
+devices with multiple receive queues, a seperate NAPI struct instance
+will be allocated and added for each such queue.
+
 All of the above methods are used below, so keep reading for clarity.
 
 Device driver changes to be made when porting NAPI
@@ -167,54 +175,49 @@ Device driver changes to be made when porting NAPI
 
 Below we describe what kind of changes are required for NAPI to work.
 
-1) introduction of dev->poll() method 
+1) introduction of napi->poll() method 
 =====================================
 
 This is the method that is invoked by the network core when it requests
-for new packets from the driver. A driver is allowed to send upto
-dev->quota packets by the current CPU before yielding to the network
-subsystem (so other devices can also get opportunity to send to the stack).
+for new packets from the driver for a specific NAPI instance. A driver
+is allowed to send upto 'budget' packets by the current CPU before yielding
+to the network subsystem (so other devices can also get opportunity to send
+to the stack).
 
-dev->poll() prototype looks as follows:
-int my_poll(struct net_device *dev, int *budget)
+napi->poll() prototype looks as follows:
+
+int my_poll(struct napi_struct *napi, int budget)
 
 budget is the remaining number of packets the network subsystem on the
 current CPU can send up the stack before yielding to other system tasks.
-*Each driver is responsible for decrementing budget by the total number of
-packets sent.
-	Total number of packets cannot exceed dev->quota.
 
-dev->poll() method is invoked by the top layer, the driver just sends if it 
-can to the stack the packet quantity requested.
+The napi->poll() method is invoked by the top layer, the driver just sends
+if it can to the stack the packet quantity requested.
 
-more on dev->poll() below after the interrupt changes are explained.
+more on napi->poll() below after the interrupt changes are explained.
 
-2) registering dev->poll() method
+2) registering napi->poll() method
 ===================================
 
-dev->poll should be set in the dev->probe() method. 
+napi->poll should be registered in the dev->probe() method via
+netif_napi_add() as explained above.
+
 e.g:
 dev->open = my_open;
 .
 .
-/* two new additions */
-/* first register my poll method */
-dev->poll = my_poll;
-/* next register my weight/quanta; can be overridden in /proc */
-dev->weight = 16;
+netif_napi_add(dev, &private->napi, my_poll, 16);
 .
 .
 dev->stop = my_close;
 
-
-
-3) scheduling dev->poll()
+3) scheduling napi->poll()
 =============================
 This involves modifying the interrupt handler and the code
 path which takes the packet off the NIC and sends them to the 
 stack.
 
-it's important at this point to introduce the classical D Becker 
+It's important at this point to introduce the classical D Becker 
 interrupt processor:
 
 ------------------
@@ -296,13 +299,13 @@ netdevice_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 		}
 /************************ start note *********************************/		
 		if (status & rx_interrupt || (status & rx_nobuffs)) {
-			if (netif_rx_schedule_prep(dev)) {
+			if (netif_rx_schedule_prep(dev, &tp->napi)) {
 
 				/* disable interrupts caused 
 			         *	by arriving packets */
 				disable_rx_and_rxnobuff_ints();
 				/* tell system we have work to be done. */
-				__netif_rx_schedule(dev);
+				__netif_rx_schedule(dev, &tp->napi);
 			} else {
 				printk("driver bug! interrupt while in poll\n");
 				/* FIX by disabling interrupts  */
@@ -344,10 +347,10 @@ register for those two items above; clearing is done in the place where
 proper work is done within NAPI; at the poll() and refill_rx_ring() 
 discussed further below.
 netif_rx_schedule_prep() returns 1 if device is in running state and
-gets successfully added to the core poll list. If we get a zero value
-we can _almost_ assume are already added to the list (instead of not running. 
-Logic based on the fact that you shouldn't get interrupt if not running)
-We rectify this by disabling rx and rxnobuf interrupts.
+the NAPI instance gets successfully added to the core poll list. If we get
+a zero value we can _almost_ assume are already added to the list (instead
+of not running.  Logic based on the fact that you shouldn't get interrupt
+if not running) We rectify this by disabling rx and rxnobuf interrupts.
 
 II) that receive_packets(dev) and make_rx_buffs_avail() may have disappeared.
 These functionalities are still around actually......
@@ -355,7 +358,7 @@ These functionalities are still around actually......
 infact, receive_packets(dev) is very close to my_poll() and 
 make_rx_buffs_avail() is invoked from my_poll()
 
-4) converting receive_packets() to dev->poll()
+4) converting receive_packets() to napi->poll()
 ===============================================
 
 We need to convert the classical D Becker receive_packets(dev) to my_poll()
@@ -430,18 +433,15 @@ the call.
 -------------------------------------------------------------------
 
 /* this is called by the network core */
-static int my_poll (struct net_device *dev, int *budget)
+static int my_poll (struct napi_struct *napi, int budget)
 {
-
-	struct my_private *tp = (struct my_private *)dev->priv;
+	struct my_private *tp = container_of(napi, struct my_private, napi);
+	struct net_device *dev = tp->dev;
 	rx_ring = tp->rx_ring;
 	cur_rx = tp->cur_rx;
 	int entry = cur_rx % RX_BUF_LEN;
-	/* maximum packets to send to the stack */
-/************************ note note *********************************/		
-	int rx_work_limit = dev->quota;
+	int work_done = 0;
 
-/************************ end note note *********************************/		
     do {  // outer beginning loop starts here
 
 	clear_rx_status_register_bit();
@@ -461,11 +461,11 @@ static int my_poll (struct net_device *dev, int *budget)
                 if ((rx_size > (MAX_ETH_FRAME_SIZE+4)) ||
                     (!(rx_status & RxStatusOK))) {
                         netdrv_rx_err (rx_status, dev, tp, ioaddr);
-                        return 1;
+                        return work_done;
                 }
 
 /************************ note note *********************************/		
-                if (--rx_work_limit < 0) { /* we got packets, but no quota */
+		if (work_done >= budget) { /* we got packets, but no quota */
 			/* store current ring pointer state */
 			tp->cur_rx = cur_rx;
 
@@ -492,7 +492,7 @@ static int my_poll (struct net_device *dev, int *budget)
 
 		/* move to the next skb on the ring */
 		entry = (++tp->cur_rx) % RX_RING_SIZE;
-		received++ ;
+		work_done++;
 
         }
 
@@ -518,17 +518,13 @@ static int my_poll (struct net_device *dev, int *budget)
 
 done:
 
-/************************ note note *********************************/		
-        dev->quota -= received;
-        *budget -= received;
-
         /* If RX ring is not full we are out of memory. */
         if (tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
                 goto oom;
 
 	/* we are happy/done, no more packets on ring; put us back
 	to where we can start processing interrupts again */
-        netif_rx_complete(dev);
+        netif_rx_complete(dev, napi);
 	enable_rx_and_rxnobuf_ints();
 
        /* The last op happens after poll completion. Which means the following:
@@ -544,20 +540,14 @@ done:
         * processed irqs. The good news: no events are ever lost.
         */
 
-        return 0;   /* done */
+        return work_done;   /* done */
 
 not_done:
         if (tp->cur_rx - tp->dirty_rx > RX_RING_SIZE/2 ||
             tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
                 refill_rx_ring(dev);
 
-        if (!received) {
-                printk("received==0\n");
-                received = 1;
-        }
-        dev->quota -= received;
-        *budget -= received;
-        return 1;  /* not_done */
+        return work_done;
 
 oom:
         /* Start timer, stop polling, but do not enable rx interrupts. */
@@ -569,7 +559,6 @@ oom:
 -------------------------------------------------------------------
 
 From above we note that:
-0) rx_work_limit = dev->quota 
 1) refill_rx_ring() is in charge of clearing the bit for rxnobuff when
 it does the work.
 2) We have a done and not_done state.
@@ -597,18 +586,12 @@ a)
         if (tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
                 restart_timer();
 
-	else netif_rx_schedule(dev);  /* we are back on the poll list */
+	else netif_rx_schedule(dev, napi);  /* we are back on the poll list */
 	
 5) dev->close() and dev->suspend() issues
 ==========================================
-The driver writer needn't worry about this; the top net layer takes
-care of it.
-
-6) Adding new Stats to /proc 
-=============================
-In order to debug some of the new features, we introduce new stats
-that need to be collected.
-TODO: Fill this later.
+These handlers should shut off all NAPI instances for a given device using
+napi_disable(napi)
 
 APPENDIX 1: discussion on using ethernet HW FC
 ==============================================
@@ -708,8 +691,8 @@ restart_poll:
 	.
 	.
 	enable_rx_interrupts()
-	netif_rx_complete(dev);
-	if (ring_has_new_packet() && netif_rx_reschedule(dev, received)) {
+	netif_rx_complete(dev, napi);
+	if (ring_has_new_packet() && netif_rx_reschedule(dev, napi)) {
 		disable_rx_and_rxnobufs()
 		goto restart_poll
 	} while (rx_status_is_set);
drivers/infiniband/ulp/ipoib/ipoib.h +3 -1
index 285c143..35f3ca4 100644
@@ -228,6 +228,8 @@ struct ipoib_dev_priv {
 
 	struct net_device *dev;
 
+	struct napi_struct napi;
+
 	unsigned long flags;
 
 	struct mutex mcast_mutex;
@@ -351,7 +353,7 @@ extern struct workqueue_struct *ipoib_workqueue;
 
 /* functions */
 
-int ipoib_poll(struct net_device *dev, int *budget);
+int ipoib_poll(struct napi_struct *napi, int budget);
 void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr);
 
 struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
drivers/infiniband/ulp/ipoib/ipoib_ib.c +17 -26

93 lines not on this page · raw message

drivers/infiniband/ulp/ipoib/ipoib_main.c +4 -2
index 894b1dc..8d4dad4 100644
@@ -141,6 +141,8 @@ static int ipoib_stop(struct net_device *dev)
 
 	clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
 
+	napi_disable(&priv->napi);
+
 	netif_stop_queue(dev);
 
 	clear_bit(IPOIB_FLAG_NETIF_STOPPED, &priv->flags);
@@ -948,8 +950,8 @@ static void ipoib_setup(struct net_device *dev)
 	dev->hard_header 	 = ipoib_hard_header;
 	dev->set_multicast_list  = ipoib_set_mcast_list;
 	dev->neigh_setup         = ipoib_neigh_setup_dev;
-	dev->poll                = ipoib_poll;
-	dev->weight              = 100;
+
+	netif_napi_add(dev, &priv->napi, ipoib_poll, 100);
 
 	dev->watchdog_timeo 	 = HZ;
 
drivers/net/8139cp.c +18 -20
index a79f28c..923821d 100644
@@ -334,6 +334,8 @@ struct cp_private {
 	spinlock_t		lock;
 	u32			msg_enable;
 
+	struct napi_struct	napi;
+
 	struct pci_dev		*pdev;
 	u32			rx_config;
 	u16			cpcmd;
@@ -501,12 +503,12 @@ static inline unsigned int cp_rx_csum_ok (u32 status)
 	return 0;
 }
 
-static int cp_rx_poll (struct net_device *dev, int *budget)
+static int cp_rx_poll(struct napi_struct *napi, int budget)
 {
-	struct cp_private *cp = netdev_priv(dev);
-	unsigned rx_tail = cp->rx_tail;
-	unsigned rx_work = dev->quota;
-	unsigned rx;
+	struct cp_private *cp = container_of(napi, struct cp_private, napi);
+	struct net_device *dev = cp->dev;
+	unsigned int rx_tail = cp->rx_tail;
+	int rx;
 
 rx_status_loop:
 	rx = 0;
@@ -588,33 +590,28 @@ rx_next:
 			desc->opts1 = cpu_to_le32(DescOwn | cp->rx_buf_sz);
 		rx_tail = NEXT_RX(rx_tail);
 
-		if (!rx_work--)
+		if (rx >= budget)
 			break;
 	}
 
 	cp->rx_tail = rx_tail;
 
-	dev->quota -= rx;
-	*budget -= rx;
-
 	/* if we did not reach work limit, then we're done with
 	 * this round of polling
 	 */
-	if (rx_work) {
+	if (rx < budget) {
 		unsigned long flags;
 
 		if (cpr16(IntrStatus) & cp_rx_intr_mask)
 			goto rx_status_loop;
 
-		local_irq_save(flags);
+		spin_lock_irqsave(&cp->lock, flags);
 		cpw16_f(IntrMask, cp_intr_mask);
-		__netif_rx_complete(dev);
-		local_irq_restore(flags);
-
-		return 0;	/* done */
+		__netif_rx_complete(dev, napi);
+		spin_unlock_irqrestore(&cp->lock, flags);
 	}
 
-	return 1;		/* not done */
+	return rx;
 }
 
 static irqreturn_t cp_interrupt (int irq, void *dev_instance)
@@ -647,9 +644,9 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
 	}
 
 	if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr))
-		if (netif_rx_schedule_prep(dev)) {
+		if (netif_rx_schedule_prep(dev, &cp->napi)) {
 			cpw16_f(IntrMask, cp_norx_intr_mask);
-			__netif_rx_schedule(dev);
+			__netif_rx_schedule(dev, &cp->napi);
 		}
 
 	if (status & (TxOK | TxErr | TxEmpty | SWInt))
@@ -1198,6 +1195,8 @@ static int cp_close (struct net_device *dev)
 	struct cp_private *cp = netdev_priv(dev);
 	unsigned long flags;
 
+	napi_disable(&cp->napi);
+
 	if (netif_msg_ifdown(cp))
 		printk(KERN_DEBUG "%s: disabling interface\n", dev->name);
 
@@ -1933,11 +1932,10 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
 	dev->hard_start_xmit = cp_start_xmit;
 	dev->get_stats = cp_get_stats;
 	dev->do_ioctl = cp_ioctl;
-	dev->poll = cp_rx_poll;
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	dev->poll_controller = cp_poll_controller;
 #endif
-	dev->weight = 16;	/* arbitrary? from NAPI_HOWTO.txt. */
+	netif_napi_add(dev, &cp->napi, cp_rx_poll, 16);
 #ifdef BROKEN
 	dev->change_mtu = cp_change_mtu;
 #endif
drivers/net/8139too.c +21 -25

106 lines not on this page · raw message

drivers/net/amd8111e.c +11 -16
index a61b2f8..2f7af7c 100644
@@ -723,9 +723,10 @@ static int amd8111e_tx(struct net_device *dev)
 
 #ifdef CONFIG_AMD8111E_NAPI
 /* This function handles the driver receive operation in polling mode */
-static int amd8111e_rx_poll(struct net_device *dev, int * budget)
+static int amd8111e_rx_poll(struct napi_struct *napi, int budget)
 {
-	struct amd8111e_priv *lp = netdev_priv(dev);
+	struct amd8111e_priv *lp = container_of(napi, struct amd8111e_priv, napi);
+	struct net_device *dev = lp->amd8111e_net_dev;
 	int rx_index = lp->rx_idx & RX_RING_DR_MOD_MASK;
 	void __iomem *mmio = lp->mmio;
 	struct sk_buff *skb,*new_skb;
@@ -737,7 +738,7 @@ static int amd8111e_rx_poll(struct net_device *dev, int * budget)
 #if AMD8111E_VLAN_TAG_USED
 	short vtag;
 #endif
-	int rx_pkt_limit = dev->quota;
+	int rx_pkt_limit = budget;
 	unsigned long flags;
 
 	do{
@@ -838,21 +839,14 @@ static int amd8111e_rx_poll(struct net_device *dev, int * budget)
 	} while(intr0 & RINT0);
 
 	/* Receive descriptor is empty now */
-	dev->quota -= num_rx_pkt;
-	*budget -= num_rx_pkt;
-
 	spin_lock_irqsave(&lp->lock, flags);
-	netif_rx_complete(dev);
+	__netif_rx_complete(dev, napi);
 	writel(VAL0|RINTEN0, mmio + INTEN0);
 	writel(VAL2 | RDMD0, mmio + CMD0);
 	spin_unlock_irqrestore(&lp->lock, flags);
-	return 0;
 
 rx_not_empty:
-	/* Do not call a netif_rx_complete */
-	dev->quota -= num_rx_pkt;
-	*budget -= num_rx_pkt;
-	return 1;
+	return num_rx_pkt;
 }
 
 #else
@@ -1287,11 +1281,11 @@ static irqreturn_t amd8111e_interrupt(int irq, void *dev_id)
 	/* Check if Receive Interrupt has occurred. */
 #ifdef CONFIG_AMD8111E_NAPI
 	if(intr0 & RINT0){
-		if(netif_rx_schedule_prep(dev)){
+		if(netif_rx_schedule_prep(dev, &lp->napi)){
 			/* Disable receive interupts */
 			writel(RINTEN0, mmio + INTEN0);
 			/* Schedule a polling routine */
-			__netif_rx_schedule(dev);
+			__netif_rx_schedule(dev, &lp->napi);
 		}
 		else if (intren0 & RINTEN0) {
 			printk("************Driver bug! \
@@ -1345,6 +1339,8 @@ static int amd8111e_close(struct net_device * dev)
 	struct amd8111e_priv *lp = netdev_priv(dev);
 	netif_stop_queue(dev);
 
+	napi_disable(&lp->napi);
+
 	spin_lock_irq(&lp->lock);
 
 	amd8111e_disable_interrupt(lp);
@@ -2031,8 +2027,7 @@ static int __devinit amd8111e_probe_one(struct pci_dev *pdev,
 	dev->tx_timeout = amd8111e_tx_timeout;
 	dev->watchdog_timeo = AMD8111E_TX_TIMEOUT;
 #ifdef CONFIG_AMD8111E_NAPI
-	dev->poll = amd8111e_rx_poll;
-	dev->weight = 32;
+	netif_napi_add(dev, &lp->napi, amd8111e_rx_poll, 32);
 #endif
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	dev->poll_controller = amd8111e_poll;
drivers/net/amd8111e.h +2 -0
index e65080a..612e653 100644
@@ -763,6 +763,8 @@ struct amd8111e_priv{
 	/* Reg memory mapped address */
 	void __iomem *mmio;
 
+	struct napi_struct napi;
+
 	spinlock_t lock;	/* Guard lock */
 	unsigned long rx_idx, tx_idx;	/* The next free ring entry */
 	unsigned long tx_complete_idx;
drivers/net/arm/ep93xx_eth.c +29 -38

140 lines not on this page · raw message

drivers/net/b44.c +16 -29

98 lines not on this page · raw message

drivers/net/b44.h +2 -0
index e537e63..63c55a4 100644
@@ -423,6 +423,8 @@ struct b44 {
 	struct ring_info	*rx_buffers;
 	struct ring_info	*tx_buffers;
 
+	struct napi_struct	napi;
+
 	u32			dma_offset;
 	u32			flags;
 #define B44_FLAG_B0_ANDLATER	0x00000001
drivers/net/bnx2.c +17 -24

116 lines not on this page · raw message

drivers/net/bnx2.h +2 -0
index 102adfe..fbae439 100644
@@ -6473,6 +6473,8 @@ struct bnx2 {
 	struct net_device	*dev;
 	struct pci_dev		*pdev;
 
+	struct napi_struct	napi;
+
 	atomic_t		intr_sem;
 
 	struct status_block	*status_blk;
drivers/net/cassini.c +14 -20
index f6e4030..ffcefa2 100644
@@ -2485,7 +2485,7 @@ static irqreturn_t cas_interruptN(int irq, void *dev_id)
 	if (status & INTR_RX_DONE_ALT) { /* handle rx separately */
 #ifdef USE_NAPI
 		cas_mask_intr(cp);
-		netif_rx_schedule(dev);
+		netif_rx_schedule(dev, &cp->napi);
 #else
 		cas_rx_ringN(cp, ring, 0);
 #endif
@@ -2536,7 +2536,7 @@ static irqreturn_t cas_interrupt1(int irq, void *dev_id)
 	if (status & INTR_RX_DONE_ALT) { /* handle rx separately */
 #ifdef USE_NAPI
 		cas_mask_intr(cp);
-		netif_rx_schedule(dev);
+		netif_rx_schedule(dev, &cp->napi);
 #else
 		cas_rx_ringN(cp, 1, 0);
 #endif
@@ -2592,7 +2592,7 @@ static irqreturn_t cas_interrupt(int irq, void *dev_id)
 	if (status & INTR_RX_DONE) {
 #ifdef USE_NAPI
 		cas_mask_intr(cp);
-		netif_rx_schedule(dev);
+		netif_rx_schedule(dev, &cp->napi);
 #else
 		cas_rx_ringN(cp, 0, 0);
 #endif
@@ -2607,9 +2607,10 @@ static irqreturn_t cas_interrupt(int irq, void *dev_id)
 
 
 #ifdef USE_NAPI
-static int cas_poll(struct net_device *dev, int *budget)
+static int cas_poll(struct napi_struct *napi, int budget)
 {
-	struct cas *cp = netdev_priv(dev);
+	struct cas *cp = container_of(napi, struct cas, napi);
+	struct net_device *dev = cp->dev;
 	int i, enable_intr, todo, credits;
 	u32 status = readl(cp->regs + REG_INTR_STATUS);
 	unsigned long flags;
@@ -2620,20 +2621,18 @@ static int cas_poll(struct net_device *dev, int *budget)
 
 	/* NAPI rx packets. we spread the credits across all of the
 	 * rxc rings
-	 */
-	todo = min(*budget, dev->quota);
-
-	/* to make sure we're fair with the work we loop through each
+	 *
+	 * to make sure we're fair with the work we loop through each
 	 * ring N_RX_COMP_RING times with a request of
-	 * todo / N_RX_COMP_RINGS
+	 * budget / N_RX_COMP_RINGS
 	 */
 	enable_intr = 1;
 	credits = 0;
 	for (i = 0; i < N_RX_COMP_RINGS; i++) {
 		int j;
 		for (j = 0; j < N_RX_COMP_RINGS; j++) {
-			credits += cas_rx_ringN(cp, j, todo / N_RX_COMP_RINGS);
-			if (credits >= todo) {
+			credits += cas_rx_ringN(cp, j, budget / N_RX_COMP_RINGS);
+			if (credits >= budget) {
 				enable_intr = 0;
 				goto rx_comp;
 			}
@@ -2641,9 +2640,6 @@ static int cas_poll(struct net_device *dev, int *budget)
 	}
 
 rx_comp:
-	*budget    -= credits;
-	dev->quota -= credits;
-
 	/* final rx completion */
 	spin_lock_irqsave(&cp->lock, flags);
 	if (status)
@@ -2674,11 +2670,10 @@ rx_comp:
 #endif
 	spin_unlock_irqrestore(&cp->lock, flags);
 	if (enable_intr) {
-		netif_rx_complete(dev);
+		netif_rx_complete(dev, napi);
 		cas_unmask_intr(cp);
-		return 0;
 	}
-	return 1;
+	return credits;
 }
 #endif
 
@@ -5062,8 +5057,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev,
 	dev->watchdog_timeo = CAS_TX_TIMEOUT;
 	dev->change_mtu = cas_change_mtu;
 #ifdef USE_NAPI
-	dev->poll = cas_poll;
-	dev->weight = 64;
+	netif_napi_add(dev, &cp->napi, cas_poll, 64);
 #endif
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	dev->poll_controller = cas_netpoll;
drivers/net/cassini.h +2 -0
index a970804..2f93f83 100644
@@ -4280,6 +4280,8 @@ struct cas {
 	int rx_cur[N_RX_COMP_RINGS], rx_new[N_RX_COMP_RINGS];
 	int rx_last[N_RX_DESC_RINGS];
 
+	struct napi_struct napi;
+
 	/* Set when chip is actually in operational state
 	 * (ie. not power managed) */
 	int hw_running;
drivers/net/chelsio/common.h +1 -0
index 8ba702c..b5de445 100644
@@ -278,6 +278,7 @@ struct adapter {
 	struct peespi *espi;
 	struct petp   *tp;
 
+	struct napi_struct napi;
 	struct port_info port[MAX_NPORTS];
 	struct delayed_work stats_update_task;
 	struct timer_list stats_update_timer;
drivers/net/chelsio/cxgb2.c +2 -2
index 231ce43..66da0c7 100644
@@ -274,6 +274,7 @@ static int cxgb_close(struct net_device *dev)
 	struct cmac *mac = p->mac;
 
 	netif_stop_queue(dev);
+	napi_disable(&adapter->napi);
 	mac->ops->disable(mac, MAC_DIRECTION_TX | MAC_DIRECTION_RX);
 	netif_carrier_off(dev);
 
@@ -1113,8 +1114,7 @@ static int __devinit init_one(struct pci_dev *pdev,
 		netdev->poll_controller = t1_netpoll;
 #endif
 #ifdef CONFIG_CHELSIO_T1_NAPI
-		netdev->weight = 64;
-		netdev->poll = t1_poll;
+		netif_napi_add(netdev, &adapter->napi, t1_poll, 64);
 #endif
 
 		SET_ETHTOOL_OPS(netdev, &t1_ethtool_ops);
drivers/net/chelsio/sge.c +13 -16
index e4f874a..0e5504d 100644
@@ -1620,23 +1620,20 @@ static int process_pure_responses(struct adapter *adapter)
  * or protection from interrupts as data interrupts are off at this point and
  * other adapter interrupts do not interfere.
  */
-int t1_poll(struct net_device *dev, int *budget)
+int t1_poll(struct napi_struct *napi, int budget)
 {
-	struct adapter *adapter = dev->priv;
+	struct adapter *adapter = container_of(napi, struct adapter, napi); 
+	struct net_device *dev = adapter->port[0].dev;
 	int work_done;
 
-	work_done = process_responses(adapter, min(*budget, dev->quota));
-	*budget -= work_done;
-	dev->quota -= work_done;
-
-	if (unlikely(responses_pending(adapter)))
-		return 1;
-
-	netif_rx_complete(dev);
-	writel(adapter->sge->respQ.cidx, adapter->regs + A_SG_SLEEPING);
-
-	return 0;
+	work_done = process_responses(adapter, budget);
 
+	if (likely(!responses_pending(adapter))) {
+		netif_rx_complete(dev, napi);
+		writel(adapter->sge->respQ.cidx,
+		       adapter->regs + A_SG_SLEEPING);
+	}
+	return work_done;
 }
 
 /*
@@ -1653,13 +1650,13 @@ irqreturn_t t1_interrupt(int irq, void *data)
 
 		writel(F_PL_INTR_SGE_DATA, adapter->regs + A_PL_CAUSE);
 
-		if (__netif_rx_schedule_prep(dev)) {
+		if (napi_schedule_prep(&adapter->napi)) {
 			if (process_pure_responses(adapter))
-				__netif_rx_schedule(dev);
+				__netif_rx_schedule(dev, &adapter->napi);
 			else {
 				/* no data, no NAPI needed */
 				writel(sge->respQ.cidx, adapter->regs + A_SG_SLEEPING);
-				netif_poll_enable(dev);	/* undo schedule_prep */
+				napi_enable(&adapter->napi);	/* undo schedule_prep */
 			}
 		}
 		return IRQ_HANDLED;
drivers/net/chelsio/sge.h +1 -1
index d132a0e..713d9c5 100644
@@ -77,7 +77,7 @@ int t1_sge_configure(struct sge *, struct sge_params *);
 int t1_sge_set_coalesce_params(struct sge *, struct sge_params *);
 void t1_sge_destroy(struct sge *);
 irqreturn_t t1_interrupt(int irq, void *cookie);
-int t1_poll(struct net_device *, int *);
+int t1_poll(struct napi_struct *, int);
 
 int t1_start_xmit(struct sk_buff *skb, struct net_device *dev);
 void t1_set_vlan_accel(struct adapter *adapter, int on_off);
drivers/net/cxgb3/adapter.h +15 -13
index ab72563..e723e7b 100644
@@ -50,7 +50,9 @@ typedef irqreturn_t(*intr_handler_t) (int, void *);
 
 struct vlan_group;
 
+struct adapter;
 struct port_info {
+	struct adapter *adapter;
 	struct vlan_group *vlan_grp;
 	const struct port_type_info *port_type;
 	u8 port_id;
@@ -170,11 +172,13 @@ enum {				/* per port SGE statistics */
 	SGE_PSTAT_MAX		/* must be last */
 };
 
+struct adapter_napi;
 struct sge_qset {		/* an SGE queue set */
 	struct sge_rspq rspq;
 	struct sge_fl fl[SGE_RXQ_PER_SET];
 	struct sge_txq txq[SGE_TXQ_PER_SET];
-	struct net_device *netdev;	/* associated net device */
+	struct adapter_napi *anapi;
+	struct net_device *netdev;
 	unsigned long txq_stopped;	/* which Tx queues are stopped */
 	struct timer_list tx_reclaim_timer;	/* reclaims TX buffers */
 	unsigned long port_stats[SGE_PSTAT_MAX];
@@ -185,6 +189,13 @@ struct sge {
 	spinlock_t reg_lock;	/* guards non-atomic SGE registers (eg context) */
 };
 
+struct adapter_napi {
+	struct napi_struct napi;
+	struct adapter *adapter;
+	int port;
+	int qset;
+};
+
 struct adapter {
 	struct t3cdev tdev;
 	struct list_head adapter_list;
@@ -219,11 +230,7 @@ struct adapter {
 	struct delayed_work adap_check_task;
 	struct work_struct ext_intr_handler_task;
 
-	/*
-	 * Dummy netdevices are needed when using multiple receive queues with
-	 * NAPI as each netdevice can service only one queue.
-	 */
-	struct net_device *dummy_netdev[SGE_QSETS - 1];
+	struct adapter_napi napi[SGE_QSETS];
 
 	struct dentry *debugfs_root;
 
@@ -251,12 +258,6 @@ static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)
 	return netdev_priv(adap->port[idx]);
 }
 
-/*
- * We use the spare atalk_ptr to map a net device to its SGE queue set.
- * This is a macro so it can be used as l-value.
- */
-#define dev2qset(netdev) ((netdev)->atalk_ptr)
-
 #define OFFLOAD_DEVMAP_BIT 15
 
 #define tdev2adap(d) container_of(d, struct adapter, tdev)
@@ -282,7 +283,8 @@ int t3_mgmt_tx(struct adapter *adap, struct sk_buff *skb);
 void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p);
 int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
 		      int irq_vec_idx, const struct qset_params *p,
-		      int ntxq, struct net_device *netdev);
+		      int ntxq, struct adapter_napi *anapi,
+		      struct net_device *dev);
 int t3_get_desc(const struct sge_qset *qs, unsigned int qnum, unsigned int idx,
 		unsigned char *data);
 irqreturn_t t3_sge_intr_msix(int irq, void *cookie);
drivers/net/cxgb3/cxgb3_main.c +84 -104

457 lines not on this page · raw message

drivers/net/cxgb3/sge.c +76 -86

318 lines not on this page · raw message

drivers/net/e100.c +17 -20
index 280313b..e25f5ec 100644
@@ -539,6 +539,7 @@ struct nic {
 	struct csr __iomem *csr;
 	enum scb_cmd_lo cuc_cmd;
 	unsigned int cbs_avail;
+	struct napi_struct napi;
 	struct cb *cbs;
 	struct cb *cb_to_use;
 	struct cb *cb_to_send;
@@ -1974,35 +1975,31 @@ static irqreturn_t e100_intr(int irq, void *dev_id)
 	if(stat_ack & stat_ack_rnr)
 		nic->ru_running = RU_SUSPENDED;
 
-	if(likely(netif_rx_schedule_prep(netdev))) {
+	if(likely(netif_rx_schedule_prep(netdev, &nic->napi))) {
 		e100_disable_irq(nic);
-		__netif_rx_schedule(netdev);
+		__netif_rx_schedule(netdev, &nic->napi);
 	}
 
 	return IRQ_HANDLED;
 }
 
-static int e100_poll(struct net_device *netdev, int *budget)
+static int e100_poll(struct napi_struct *napi, int budget)
 {
-	struct nic *nic = netdev_priv(netdev);
-	unsigned int work_to_do = min(netdev->quota, *budget);
-	unsigned int work_done = 0;
+	struct nic *nic = container_of(napi, struct nic, napi);
+	struct net_device *netdev = nic->netdev;
+	int work_done = 0;
 	int tx_cleaned;
 
-	e100_rx_clean(nic, &work_done, work_to_do);
+	e100_rx_clean(nic, &work_done, budget);
 	tx_cleaned = e100_tx_clean(nic);
 
 	/* If no Rx and Tx cleanup work was done, exit polling mode. */
 	if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
-		netif_rx_complete(netdev);
+		netif_rx_complete(netdev, napi);
 		e100_enable_irq(nic);
-		return 0;
 	}
 
-	*budget -= work_done;
-	netdev->quota -= work_done;
-
-	return 1;
+	return work_done;
 }
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
@@ -2071,7 +2068,7 @@ static int e100_up(struct nic *nic)
 		nic->netdev->name, nic->netdev)))
 		goto err_no_irq;
 	netif_wake_queue(nic->netdev);
-	netif_poll_enable(nic->netdev);
+	napi_enable(&nic->napi);
 	/* enable ints _after_ enabling poll, preventing a race between
 	 * disable ints+schedule */
 	e100_enable_irq(nic);
@@ -2089,7 +2086,7 @@ err_rx_clean_list:
 static void e100_down(struct nic *nic)
 {
 	/* wait here for poll to complete */
-	netif_poll_disable(nic->netdev);
+	napi_disable(&nic->napi);
 	netif_stop_queue(nic->netdev);
 	e100_hw_reset(nic);
 	free_irq(nic->pdev->irq, nic->netdev);
@@ -2572,14 +2569,13 @@ static int __devinit e100_probe(struct pci_dev *pdev,
 	SET_ETHTOOL_OPS(netdev, &e100_ethtool_ops);
 	netdev->tx_timeout = e100_tx_timeout;
 	netdev->watchdog_timeo = E100_WATCHDOG_PERIOD;
-	netdev->poll = e100_poll;
-	netdev->weight = E100_NAPI_WEIGHT;
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	netdev->poll_controller = e100_netpoll;
 #endif
 	strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
 
 	nic = netdev_priv(netdev);
+	netif_napi_add(netdev, &nic->napi, e100_poll, E100_NAPI_WEIGHT);
 	nic->netdev = netdev;
 	nic->pdev = pdev;
 	nic->msg_enable = (1 << debug) - 1;
@@ -2733,7 +2729,7 @@ static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
 	struct nic *nic = netdev_priv(netdev);
 
 	if (netif_running(netdev))
-		netif_poll_disable(nic->netdev);
+		napi_disable(&nic->napi);
 	del_timer_sync(&nic->watchdog);
 	netif_carrier_off(nic->netdev);
 	netif_device_detach(netdev);
@@ -2779,7 +2775,7 @@ static void e100_shutdown(struct pci_dev *pdev)
 	struct nic *nic = netdev_priv(netdev);
 
 	if (netif_running(netdev))
-		netif_poll_disable(nic->netdev);
+		napi_disable(&nic->napi);
 	del_timer_sync(&nic->watchdog);
 	netif_carrier_off(nic->netdev);
 
@@ -2804,12 +2800,13 @@ static void e100_shutdown(struct pci_dev *pdev)
 static pci_ers_result_t e100_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
 {
 	struct net_device *netdev = pci_get_drvdata(pdev);
+	struct nic *nic = netdev_priv(netdev);
 
 	/* Similar to calling e100_down(), but avoids adpater I/O. */
 	netdev->stop(netdev);
 
 	/* Detach; put netif into state similar to hotplug unplug. */
-	netif_poll_enable(netdev);
+	napi_enable(&nic->napi);
 	netif_device_detach(netdev);
 	pci_disable_device(pdev);
 
drivers/net/e1000/e1000.h +1 -0
index 16a6edf..781ed99 100644
@@ -300,6 +300,7 @@ struct e1000_adapter {
 				int cleaned_count);
 	struct e1000_rx_ring *rx_ring;      /* One per active queue */
 #ifdef CONFIG_E1000_NAPI
+	struct napi_struct napi;
 	struct net_device *polling_netdev;  /* One per active queue */
 #endif
 	int num_tx_queues;
drivers/net/e1000/e1000_main.c +21 -24

135 lines not on this page · raw message

drivers/net/ehea/ehea.h +1 -1
index 8ee2c2c..eb019c8 100644
@@ -351,6 +351,7 @@ struct ehea_q_skb_arr {
  * Port resources
  */
 struct ehea_port_res {
+	struct napi_struct napi;
 	struct port_stats p_stats;
 	struct ehea_mr send_mr;       	/* send memory region */
 	struct ehea_mr recv_mr;       	/* receive memory region */
@@ -362,7 +363,6 @@ struct ehea_port_res {
 	struct ehea_cq *send_cq;
 	struct ehea_cq *recv_cq;
 	struct ehea_eq *eq;
-	struct net_device *d_netdev;
 	struct ehea_q_skb_arr rq1_skba;
 	struct ehea_q_skb_arr rq2_skba;
 	struct ehea_q_skb_arr rq3_skba;
drivers/net/ehea/ehea_main.c +22 -37

176 lines not on this page · raw message

drivers/net/epic100.c +14 -17
index 1197784..211909d 100644
@@ -262,6 +262,7 @@ struct epic_private {
 	/* Ring pointers. */
 	spinlock_t lock;				/* Group with Tx control cache line. */
 	spinlock_t napi_lock;
+	struct napi_struct napi;
 	unsigned int reschedule_in_poll;
 	unsigned int cur_tx, dirty_tx;
 
@@ -294,7 +295,7 @@ static void epic_tx_timeout(struct net_device *dev);
 static void epic_init_ring(struct net_device *dev);
 static int epic_start_xmit(struct sk_buff *skb, struct net_device *dev);
 static int epic_rx(struct net_device *dev, int budget);
-static int epic_poll(struct net_device *dev, int *budget);
+static int epic_poll(struct napi_struct *napi, int budget);
 static irqreturn_t epic_interrupt(int irq, void *dev_instance);
 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 static const struct ethtool_ops netdev_ethtool_ops;
@@ -487,8 +488,7 @@ static int __devinit epic_init_one (struct pci_dev *pdev,
 	dev->ethtool_ops = &netdev_ethtool_ops;
 	dev->watchdog_timeo = TX_TIMEOUT;
 	dev->tx_timeout = &epic_tx_timeout;
-	dev->poll = epic_poll;
-	dev->weight = 64;
+	netif_napi_add(dev, &ep->napi, epic_poll, 64);
 
 	ret = register_netdev(dev);
 	if (ret < 0)
@@ -1103,9 +1103,9 @@ static irqreturn_t epic_interrupt(int irq, void *dev_instance)
 
 	if ((status & EpicNapiEvent) && !ep->reschedule_in_poll) {
 		spin_lock(&ep->napi_lock);
-		if (netif_rx_schedule_prep(dev)) {
+		if (netif_rx_schedule_prep(dev, &ep->napi)) {
 			epic_napi_irq_off(dev, ep);
-			__netif_rx_schedule(dev);
+			__netif_rx_schedule(dev, &ep->napi);
 		} else
 			ep->reschedule_in_poll++;
 		spin_unlock(&ep->napi_lock);
@@ -1257,26 +1257,22 @@ static void epic_rx_err(struct net_device *dev, struct epic_private *ep)
 		outw(RxQueued, ioaddr + COMMAND);
 }
 
-static int epic_poll(struct net_device *dev, int *budget)
+static int epic_poll(struct napi_struct *napi, int budget)
 {
-	struct epic_private *ep = dev->priv;
-	int work_done = 0, orig_budget;
+	struct epic_private *ep = container_of(napi, struct epic_private, napi);
+	struct net_device *dev = ep->mii.dev;
+	int work_done = 0;
 	long ioaddr = dev->base_addr;
 
-	orig_budget = (*budget > dev->quota) ? dev->quota : *budget;
-
 rx_action:
 
 	epic_tx(dev, ep);
 
-	work_done += epic_rx(dev, *budget);
+	work_done += epic_rx(dev, budget);
 
 	epic_rx_err(dev, ep);
 
-	*budget -= work_done;
-	dev->quota -= work_done;
-
-	if (netif_running(dev) && (work_done < orig_budget)) {
+	if (netif_running(dev) && (work_done < budget)) {
 		unsigned long flags;
 		int more;
 
@@ -1286,7 +1282,7 @@ rx_action:
 
 		more = ep->reschedule_in_poll;
 		if (!more) {
-			__netif_rx_complete(dev);
+			__netif_rx_complete(dev, napi);
 			outl(EpicNapiEvent, ioaddr + INTSTAT);
 			epic_napi_irq_on(dev, ep);
 		} else
@@ -1298,7 +1294,7 @@ rx_action:
 			goto rx_action;
 	}
 
-	return (work_done >= orig_budget);
+	return work_done;
 }
 
 static int epic_close(struct net_device *dev)
@@ -1309,6 +1305,7 @@ static int epic_close(struct net_device *dev)
 	int i;
 
 	netif_stop_queue(dev);
+	napi_disable(&ep->napi);
 
 	if (debug > 1)
 		printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
drivers/net/fec_8xx/fec_8xx.h +2 -0
index 5af60b0..f3b1c6f 100644
@@ -105,6 +105,8 @@ struct fec;
 struct fec_enet_private {
 	spinlock_t lock;	/* during all ops except TX pckt processing */
 	spinlock_t tx_lock;	/* during fec_start_xmit and fec_tx         */
+	struct net_device *dev;
+	struct napi_struct napi;
 	int fecno;
 	struct fec *fecp;
 	const struct fec_platform_info *fpi;
drivers/net/fec_8xx/fec_main.c +26 -30

125 lines not on this page · raw message

drivers/net/forcedeth.c +28 -29

162 lines not on this page · raw message

drivers/net/fs_enet/fs_enet-main.c +19 -29

48 lines not on this page · raw message

drivers/net/fs_enet/fs_enet.h +1 -0
index 569be22..46d0606 100644

Lines of this file are not shown. View the raw message.

drivers/net/gianfar.c +16 -21
index f926905..89c2fb4 100644

Lines of this file are not shown. View the raw message.

drivers/net/gianfar.h +3 -0
index d8e779c..b8714e0 100644

Lines of this file are not shown. View the raw message.

drivers/net/ibmveth.c +50 -59

109 lines not on this page · raw message

drivers/net/ibmveth.h +1 -0
index bb69cca..bb2e5e1 100644

Lines of this file are not shown. View the raw message.

drivers/net/ixgb/ixgb.h +1 -0
index 3569d5b..1eee889 100644

Lines of this file are not shown. View the raw message.

drivers/net/ixgb/ixgb_main.c +12 -17
index 991c883..e3f27c6 100644

Lines of this file are not shown. View the raw message.

drivers/net/ixp2000/ixpdev.c +23 -14
index d9ce1ae..5148a92 100644

Lines of this file are not shown. View the raw message.

drivers/net/ixp2000/ixpdev.h +2 -0
index bd686cb..391ece6 100644

Lines of this file are not shown. View the raw message.

drivers/net/macb.c +15 -21
index a4bb026..0bd7d21 100644

Lines of this file are not shown. View the raw message.

drivers/net/macb.h +1 -0
index 4e3283e..57b85ac 100644

Lines of this file are not shown. View the raw message.

drivers/net/mv643xx_eth.c +17 -27

44 lines not on this page · raw message

drivers/net/mv643xx_eth.h +2 -0
index 82f8c0c..6f2aaa6 100644

Lines of this file are not shown. View the raw message.

drivers/net/myri10ge/myri10ge.c +17 -23
index deca653..3cd7921 100644

Lines of this file are not shown. View the raw message.

drivers/net/natsemi.c +16 -17
index 6bb48ba..df978f5 100644

Lines of this file are not shown. View the raw message.

drivers/net/netxen/netxen_nic.h +1 -0
index d4c92cc..aaa3493 100644

Lines of this file are not shown. View the raw message.

drivers/net/netxen/netxen_nic_main.c +16 -20
index 08a62ac..61e3d32 100644

Lines of this file are not shown. View the raw message.

drivers/net/pasemi_mac.c +15 -19
index 0b3066a..c9d148d 100644

Lines of this file are not shown. View the raw message.

drivers/net/pasemi_mac.h +1 -0
index c29ee15..85d3b78 100644

Lines of this file are not shown. View the raw message.

drivers/net/pcnet32.c +37 -35

72 lines not on this page · raw message

drivers/net/ps3_gelic_net.c +18 -26

44 lines not on this page · raw message

drivers/net/ps3_gelic_net.h +1 -0
index a9c4c4f..9685602 100644

Lines of this file are not shown. View the raw message.

drivers/net/qla3xxx.c +12 -17
index 69da95b..3287b69 100755

Lines of this file are not shown. View the raw message.

drivers/net/qla3xxx.h +2 -0
index 4a832c4..aa2216f 100755

Lines of this file are not shown. View the raw message.

drivers/net/r8169.c +23 -25

48 lines not on this page · raw message

drivers/net/s2io.c +12 -20
index 24feb00..6686e88 100644

Lines of this file are not shown. View the raw message.

drivers/net/s2io.h +2 -1
index 92983ee..420fefb 100644

Lines of this file are not shown. View the raw message.

drivers/net/sb1250-mac.c +16 -29

45 lines not on this page · raw message

drivers/net/skge.c +20 -24

44 lines not on this page · raw message

drivers/net/skge.h +1 -0
index edd7146..dd0fd45 100644

Lines of this file are not shown. View the raw message.

drivers/net/sky2.c +34 -46

80 lines not on this page · raw message

drivers/net/sky2.h +1 -0
index dce4d27..8d6a260 100644

Lines of this file are not shown. View the raw message.

drivers/net/spider_net.c +27 -33

60 lines not on this page · raw message

drivers/net/spider_net.h +2 -0
index dbbdb8c..a2fcdeb 100644

Lines of this file are not shown. View the raw message.

drivers/net/starfire.c +23 -23

46 lines not on this page · raw message

drivers/net/sungem.c +22 -28

50 lines not on this page · raw message

drivers/net/sungem.h +1 -0
index 58cf87c..76d760a 100644

Lines of this file are not shown. View the raw message.

drivers/net/tc35815.c +21 -22

43 lines not on this page · raw message

drivers/net/tg3.c +23 -33

56 lines not on this page · raw message

drivers/net/tg3.h +1 -0
index 5c21f49..a6a23bb 100644

Lines of this file are not shown. View the raw message.

drivers/net/tsi108_eth.c +17 -21
index 1aabc91..781e40b 100644

Lines of this file are not shown. View the raw message.

drivers/net/tulip/interrupt.c +23 -31

54 lines not on this page · raw message

drivers/net/tulip/tulip.h +2 -1
index 16f26a8..5a4d727 100644

Lines of this file are not shown. View the raw message.

drivers/net/tulip/tulip_core.c +2 -2
index eca984f..da05a3a 100644

Lines of this file are not shown. View the raw message.

drivers/net/typhoon.c +14 -27

41 lines not on this page · raw message

drivers/net/ucc_geth.c +17 -26

43 lines not on this page · raw message

drivers/net/ucc_geth.h +1 -0
index bb4dac8..0579ba0 100644

Lines of this file are not shown. View the raw message.

drivers/net/via-rhine.c +15 -16
index c3fe230..6af7925 100644

Lines of this file are not shown. View the raw message.

drivers/net/xen-netfront.c +15 -16
index 489f69c..ec710eb 100644

Lines of this file are not shown. View the raw message.

include/linux/netdevice.h +113 -72

185 lines not on this page · raw message

include/linux/netpoll.h +40 -13

53 lines not on this page · raw message

net/core/dev.c +85 -82

167 lines not on this page · raw message

net/core/net-sysfs.c +0 -15
index 5c19b06..79159db 100644

Lines of this file are not shown. View the raw message.

net/core/netpoll.c +25 -14
index de1b26a..abe6e3a 100644

Lines of this file are not shown. View the raw message.

net/core/rtnetlink.c +0 -6
index 4756d58..2b0b6fa 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 44 lines · On Tue, 07 Aug 2007 21:54:32 -0700 (PDT) David Miller <[email protected]>…

Changes since V5:

1) Revert unnecessary TX locking changes in bnx2 and tg3

2) ++i

This is probably what I'll check into my net-2.6.24 tree

Thanks.

[NET]: Make NAPI polling independant 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.

Quoted 6 lines

With lots of help and suggestions from Rusty Russell.

[ Ported to current tree and all drivers converted. -DaveM ]

Thanks for doing all this. Looks great.
Documentation of NAPI still needs more work. I'll take a start at getting net_device docbook format cleaned up, then start on a redo of the API documentation.

#2 lore raw

Someone please make sure Documentation/networking/netdevices.txt remains correct with regards to APIs and locking.

It -is- up to date, unlike NAPI howto. It should not change very much due to this napi_struct work though, if at all.

Jeff

author maintainer
#3 lore raw

From: Jeff Garzik <[email protected]>
Date: Wed, 08 Aug 2007 12:27:35 -0400

Quoted 5 lines

Someone please make sure Documentation/networking/netdevices.txt remains correct with regards to APIs and locking.

It -is- up to date, unlike NAPI howto. It should not change very much due to this napi_struct work though, if at all.

I'll take care of it when I cut my net-2.6.24 tree later today.

author maintainer
#4 lore raw
In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>
Date: Wed, 8 Aug 2007 07:06:28 -0400

Quoted 3 lines

Documentation of NAPI still needs more work. I'll take a start at getting net_device docbook format cleaned up, then start on a redo of the API documentation.

Thanks for stepping up to do this Stephen.