Skip to contentSkip to conversation

: napi_struct V3

PATCH In review David Miller 5 participants 17 messages Jul 24, 2007 – Jul 29, 2007

Subsystems (5)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

PATCH 1/1 : napi_struct V3

Ok I converted everything with Rusty's suggestion to move napi_struct out of net_device, this was mostly mechanical but some devices took some unanticipated amount of work.

In particular, cxgb3 required a lot of hacking. It is even totally broken in current 2.6.23-rc1 because it:

1) relies upon netdev_priv() and netdev->priv being seperate. So it hangs a second private pointer in netdev->priv and expects netdev_priv() to return the other pointer.

Yuck!

2) It hangs device private bits in netdev->atalk_priv, breaking Appletalk.

DOUBLE YUCK!

Anyways, I reworked everything in cxgb3 to use per queue-set napi_struct's and added the appropriate ->netdev back pointers where needed to make it all work out.

Most drivers now look something like this:

static int foo_poll(struct napi_struct *napi, int budget)

{
	struct foo *fp = container_of(napi, struct foo, napi);
	struct net_device *dev = tp->dev;
	int rx;

	rx = do_rx_work(fp, dev);
	do_tx_work(fp, dev);

	if (rx < budget) {
		netif_rx_complete(dev, napi);
		foo_restart_ints(fp);
	}

	return rx;
}

With the caveat that foo_restart_ints() _MUST_ trigger an interrupt somehow if it sees any interrupt conditions pending after turning IRQs back on. This is absolutely required in order to not lose events.

Another area of consternation are drivers that were using netif_rx_reschedule(), as that interface was removed because it doesn't fit well with the caller managing the dev->quota et al. I left race conditions in the drivers that were using that interface, but they should still basically work nonetheless.

I tried to jam a lot of drivers through the compiler by forcing them to be enable'able in Kconfig on my sparc64 machine, so I think I have added few, if any, build regressions from these changes. But if you have one of these weird platform devices, please check things out.

I also didn't play with turning off NAPI in kconfig where drivers allow that, can we just get rid of that crap already? :-/

I know I promised to convert sunvnet.c as a multi-queue NAPI driver, but this de-napi_struct'ification of net_device took longer than anticipated and I wanted to publish this so people could play with it and provide comments.

As before, netpoll is busted and needs a rewrite, any suggestions appreciated.

[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.

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

drivers/net/8139cp.c +17 -18
index e970e64..dfe9d3b 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,19 +590,16 @@ 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)
@@ -608,13 +607,11 @@ rx_next:
 
 		local_irq_save(flags);
 		cpw16_f(IntrMask, cp_intr_mask);
-		__netif_rx_complete(dev);
+		__netif_rx_complete(dev, napi);
 		local_irq_restore(flags);
-
-		return 0;	/* done */
 	}
 
-	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);
 
@@ -1934,11 +1933,11 @@ 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;
+	cp->napi.poll = cp_rx_poll;
+	cp->napi.weight = 16;	/* arbitrary? from NAPI_HOWTO.txt. */
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	dev->poll_controller = cp_poll_controller;
 #endif
-	dev->weight = 16;	/* arbitrary? from NAPI_HOWTO.txt. */
 #ifdef BROKEN
 	dev->change_mtu = cp_change_mtu;
 #endif
drivers/net/8139too.c +20 -23

101 lines not on this page · raw message

drivers/net/amd8111e.c +12 -16
index a61b2f8..ce349c5 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,8 @@ 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;
+	lp->napi.poll = amd8111e_rx_poll;
+	lp->napi.weight = 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 -37

140 lines not on this page · raw message

drivers/net/b44.c +17 -29

99 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 +18 -24

117 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 +15 -20
index f6e4030..37a19d5 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,8 @@ 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;
+	cp->napi.poll = cas_poll;
+	cp->napi.weight = 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 +3 -2
index 231ce43..fd3beb6 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,8 @@ 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;
+		adapter->napi.weight = 64;
+		adapter->napi.poll = t1_poll;
 #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 +83 -104

456 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 +18 -20
index 6b6401e..8ca2e4d 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);
@@ -2573,14 +2570,14 @@ 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);
+	nic->napi.poll = e100_poll;
+	nic->napi.weight = E100_NAPI_WEIGHT;
 	nic->netdev = netdev;
 	nic->pdev = pdev;
 	nic->msg_enable = (1 << debug) - 1;
@@ -2734,7 +2731,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);
@@ -2780,7 +2777,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);
 
@@ -2805,12 +2802,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 +22 -24

136 lines not on this page · raw message

drivers/net/ehea/ehea.h +1 -1
index 489c8b2..5b5b0b8 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 +26 -41

180 lines not on this page · raw message

drivers/net/epic100.c +15 -17
index 1197784..51fa494 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,8 @@ 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;
+	ep->napi.poll = epic_poll;
+	ep->napi.weight = 64;
 
 	ret = register_netdev(dev);
 	if (ret < 0)
@@ -1103,9 +1104,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 +1258,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 +1283,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 +1295,7 @@ rx_action:
 			goto rx_action;
 	}
 
-	return (work_done >= orig_budget);
+	return work_done;
 }
 
 static int epic_close(struct net_device *dev)
@@ -1309,6 +1306,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 +24 -28

121 lines not on this page · raw message

drivers/net/forcedeth.c +25 -24

151 lines not on this page · raw message

drivers/net/fs_enet/fs_enet-main.c +17 -27

103 lines not on this page · raw message

drivers/net/fs_enet/fs_enet.h +1 -0
index 569be22..46d0606 100644
@@ -121,6 +121,7 @@ struct fs_enet_mii_bus {
 };
 
 struct fs_enet_private {
+	struct napi_struct napi;
 	struct device *dev;	/* pointer back to the device (must be initialized first) */
 	spinlock_t lock;	/* during all ops except TX pckt processing */
 	spinlock_t tx_lock;	/* during fs_start_xmit and fs_tx         */
drivers/net/gianfar.c +17 -21
index f926905..7bb78e9 100644
@@ -134,7 +134,7 @@ static void gfar_configure_serdes(struct net_device *dev);
 extern int gfar_local_mdio_write(struct gfar_mii *regs, int mii_id, int regnum, u16 value);
 extern int gfar_local_mdio_read(struct gfar_mii *regs, int mii_id, int regnum);
 #ifdef CONFIG_GFAR_NAPI
-static int gfar_poll(struct net_device *dev, int *budget);
+static int gfar_poll(struct napi_struct *napi, int budget);
 #endif
 #ifdef CONFIG_NET_POLL_CONTROLLER
 static void gfar_netpoll(struct net_device *dev);
@@ -188,6 +188,7 @@ static int gfar_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	priv = netdev_priv(dev);
+	priv->dev = dev;
 
 	/* Set the info in the priv to the current info */
 	priv->einfo = einfo;
@@ -262,8 +263,8 @@ static int gfar_probe(struct platform_device *pdev)
 	dev->tx_timeout = gfar_timeout;
 	dev->watchdog_timeo = TX_TIMEOUT;
 #ifdef CONFIG_GFAR_NAPI
-	dev->poll = gfar_poll;
-	dev->weight = GFAR_DEV_WEIGHT;
+	priv->napi.poll = gfar_poll;
+	priv->napi.weight = GFAR_DEV_WEIGHT;
 #endif
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	dev->poll_controller = gfar_netpoll;
@@ -1102,6 +1103,9 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
 static int gfar_close(struct net_device *dev)
 {
 	struct gfar_private *priv = netdev_priv(dev);
+
+	napi_disable(&priv->napi);
+
 	stop_gfar(dev);
 
 	/* Disconnect from the PHY */
@@ -1318,7 +1322,7 @@ struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)
 		return NULL;
 
 	alignamount = RXBUF_ALIGNMENT -
-		(((unsigned) skb->data) & (RXBUF_ALIGNMENT - 1));
+		(((unsigned long) skb->data) & (RXBUF_ALIGNMENT - 1));
 
 	/* We need the data buffer to be aligned properly.  We will reserve
 	 * as many bytes as needed to align the data properly
@@ -1390,12 +1394,12 @@ irqreturn_t gfar_receive(int irq, void *dev_id)
 
 	/* support NAPI */
 #ifdef CONFIG_GFAR_NAPI
-	if (netif_rx_schedule_prep(dev)) {
+	if (netif_rx_schedule_prep(dev, &priv->napi)) {
 		tempval = gfar_read(&priv->regs->imask);
 		tempval &= IMASK_RX_DISABLED;
 		gfar_write(&priv->regs->imask, tempval);
 
-		__netif_rx_schedule(dev);
+		__netif_rx_schedule(dev, &priv->napi);
 	} else {
 		if (netif_msg_rx_err(priv))
 			printk(KERN_DEBUG "%s: receive called twice (%x)[%x]\n",
@@ -1569,23 +1573,16 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
 }
 
 #ifdef CONFIG_GFAR_NAPI
-static int gfar_poll(struct net_device *dev, int *budget)
+static int gfar_poll(struct napi_struct *napi, int budget)
 {
+	struct gfar_private *priv = container_of(napi, struct gfar_private, napi);
+	struct net_device *dev = priv->dev;
 	int howmany;
-	struct gfar_private *priv = netdev_priv(dev);
-	int rx_work_limit = *budget;
 
-	if (rx_work_limit > dev->quota)
-		rx_work_limit = dev->quota;
+	howmany = gfar_clean_rx_ring(dev, budget);
 
-	howmany = gfar_clean_rx_ring(dev, rx_work_limit);
-
-	dev->quota -= howmany;
-	rx_work_limit -= howmany;
-	*budget -= howmany;
-
-	if (rx_work_limit > 0) {
-		netif_rx_complete(dev);
+	if (howmany < budget) {
+		netif_rx_complete(dev, napi);
 
 		/* Clear the halt bit in RSTAT */
 		gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
@@ -1601,8 +1598,7 @@ static int gfar_poll(struct net_device *dev, int *budget)
 			gfar_write(&priv->regs->rxic, 0);
 	}
 
-	/* Return 1 if there's more work to do */
-	return (rx_work_limit > 0) ? 0 : 1;
+	return howmany;
 }
 #endif
 
drivers/net/gianfar.h +3 -0
index d8e779c..b8714e0 100644
@@ -691,6 +691,9 @@ struct gfar_private {
 	/* RX Locked fields */
 	spinlock_t rxlock;
 
+	struct net_device *dev;
+	struct napi_struct napi;
+
 	/* skb array and index */
 	struct sk_buff ** rx_skbuff;
 	u16 skb_currx;
drivers/net/ibmveth.c +44 -60

161 lines not on this page · raw message

drivers/net/ibmveth.h +1 -0
index bb69cca..bb2e5e1 100644
@@ -115,6 +115,7 @@ struct ibmveth_rx_q {
 struct ibmveth_adapter {
     struct vio_dev *vdev;
     struct net_device *netdev;
+    struct napi_struct napi;
     struct net_device_stats stats;
     unsigned int mcastFilterSize;
     unsigned long mac_addr;
drivers/net/ixgb/ixgb.h +1 -0
index 3569d5b..1eee889 100644
@@ -184,6 +184,7 @@ struct ixgb_adapter {
 	boolean_t rx_csum;
 
 	/* OS defined structs */
+	struct napi_struct napi;
 	struct net_device *netdev;
 	struct pci_dev *pdev;
 	struct net_device_stats net_stats;
drivers/net/ixgb/ixgb_main.c +13 -17
index 991c883..b6e5a7b 100644
@@ -97,7 +97,7 @@ static irqreturn_t ixgb_intr(int irq, void *data);
 static boolean_t ixgb_clean_tx_irq(struct ixgb_adapter *adapter);
 
 #ifdef CONFIG_IXGB_NAPI
-static int ixgb_clean(struct net_device *netdev, int *budget);
+static int ixgb_clean(struct napi_struct *napi, int budget);
 static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter,
 				   int *work_done, int work_to_do);
 #else
@@ -288,7 +288,7 @@ ixgb_up(struct ixgb_adapter *adapter)
 	mod_timer(&adapter->watchdog_timer, jiffies);
 
 #ifdef CONFIG_IXGB_NAPI
-	netif_poll_enable(netdev);
+	napi_enable(&adapter->napi);
 #endif
 	ixgb_irq_enable(adapter);
 
@@ -309,7 +309,7 @@ ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog)
 	if(kill_watchdog)
 		del_timer_sync(&adapter->watchdog_timer);
 #ifdef CONFIG_IXGB_NAPI
-	netif_poll_disable(netdev);
+	napi_disable(&adapter->napi);
 #endif
 	adapter->link_speed = 0;
 	adapter->link_duplex = 0;
@@ -421,8 +421,8 @@ ixgb_probe(struct pci_dev *pdev,
 	netdev->tx_timeout = &ixgb_tx_timeout;
 	netdev->watchdog_timeo = 5 * HZ;
 #ifdef CONFIG_IXGB_NAPI
-	netdev->poll = &ixgb_clean;
-	netdev->weight = 64;
+	adapter->napi.poll = &ixgb_clean;
+	adapter->napi.weight = 64;
 #endif
 	netdev->vlan_rx_register = ixgb_vlan_rx_register;
 	netdev->vlan_rx_add_vid = ixgb_vlan_rx_add_vid;
@@ -1746,7 +1746,7 @@ ixgb_intr(int irq, void *data)
 	}
 
 #ifdef CONFIG_IXGB_NAPI
-	if(netif_rx_schedule_prep(netdev)) {
+	if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
 
 		/* Disable interrupts and register for poll. The flush 
 		  of the posted write is intentionally left out.
@@ -1754,7 +1754,7 @@ ixgb_intr(int irq, void *data)
 
 		atomic_inc(&adapter->irq_sem);
 		IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
-		__netif_rx_schedule(netdev);
+		__netif_rx_schedule(netdev, &adapter->napi);
 	}
 #else
 	/* yes, that is actually a & and it is meant to make sure that
@@ -1776,27 +1776,23 @@ ixgb_intr(int irq, void *data)
  **/
 
 static int
-ixgb_clean(struct net_device *netdev, int *budget)
+ixgb_clean(struct napi_struct *napi, int budget)
 {
-	struct ixgb_adapter *adapter = netdev_priv(netdev);
-	int work_to_do = min(*budget, netdev->quota);
+	struct ixgb_adapter *adapter = container_of(napi, struct ixgb_adapter, napi);
+	struct net_device *netdev = adapter->netdev;
 	int tx_cleaned;
 	int work_done = 0;
 
 	tx_cleaned = ixgb_clean_tx_irq(adapter);
-	ixgb_clean_rx_irq(adapter, &work_done, work_to_do);
-
-	*budget -= work_done;
-	netdev->quota -= work_done;
+	ixgb_clean_rx_irq(adapter, &work_done, budget);
 
 	/* if no Tx and not enough Rx work done, exit the polling mode */
 	if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
-		netif_rx_complete(netdev);
+		netif_rx_complete(netdev, napi);
 		ixgb_irq_enable(adapter);
-		return 0;
 	}
 
-	return 1;
+	return work_done;
 }
 #endif
 
drivers/net/ixp2000/ixpdev.c +24 -14
index d9ce1ae..a3beb71 100644
@@ -74,9 +74,9 @@ static int ixpdev_xmit(struct sk_buff *skb, struct net_device *dev)
 }
 
 
-static int ixpdev_rx(struct net_device *dev, int *budget)
+static int ixpdev_rx(struct net_device *dev, int processed, int budget)
 {
-	while (*budget > 0) {
+	while (processed < budget) {
 		struct ixpdev_rx_desc *desc;
 		struct sk_buff *skb;
 		void *buf;
@@ -122,29 +122,34 @@ static int ixpdev_rx(struct net_device *dev, int *budget)
 
 err:
 		ixp2000_reg_write(RING_RX_PENDING, _desc);
-		dev->quota--;
-		(*budget)--;
+		processed++;
 	}
 
-	return 1;
+	return processed;
 }
 
 /* dev always points to nds[0].  */
-static int ixpdev_poll(struct net_device *dev, int *budget)
+static int ixpdev_poll(struct napi_struct *napi, int budget)
 {
+	struct ixpdev_priv *ip = container_of(napi, struct ixpdev_priv, napi);
+	struct net_device *dev = ip->dev;
+	int rx;
+
 	/* @@@ Have to stop polling when nds[0] is administratively
 	 * downed while we are polling.  */
+	rx = 0;
 	do {
[… more lines in the raw message]

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 +16 -21
index a4bb026..ff58b92 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 +18 -27

45 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..09413e8 100644

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

drivers/net/natsemi.c +17 -17
index 6bb48ba..4b2a727 100644

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

drivers/net/netxen/netxen_nic.h +1 -0
index 325269d..f650e94 100644

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

drivers/net/netxen/netxen_nic_main.c +16 -20
index b703ccf..a065373 100644

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

drivers/net/pasemi_mac.c +14 -18
index 0b3066a..9552415 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 +38 -35

73 lines not on this page · raw message

drivers/net/ps3_gelic_net.c +20 -27

47 lines not on this page · raw message

drivers/net/ps3_gelic_net.h +1 -0
index 5e1c286..9d0316f 100644

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

drivers/net/qla3xxx.c +13 -16
index 8be8be4..062c7c5 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 +24 -25

49 lines not on this page · raw message

drivers/net/s2io.c +13 -20
index afef6c0..8ff32b3 100644

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

drivers/net/s2io.h +2 -1
index 3887fe6..201286b 100644

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

drivers/net/sb1250-mac.c +15 -21
index e7fdcf1..b544515 100644

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

drivers/net/skge.c +21 -24

45 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 -48

82 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 +28 -33

61 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 +24 -21

45 lines not on this page · raw message

drivers/net/sungem.c +23 -28

51 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 +22 -22

44 lines not on this page · raw message

drivers/net/tg3.c +24 -33

57 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 +18 -21
index 1aabc91..c000f6a 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 +4 -2
index f87d769..13d52fc 100644

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

drivers/net/typhoon.c +15 -27

42 lines not on this page · raw message

drivers/net/ucc_geth.c +18 -26

44 lines not on this page · raw message

drivers/net/ucc_geth.h +1 -0
index a29e1c3..a4cb4bb 100644

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

drivers/net/via-rhine.c +16 -16
index f51c2c1..0e63a16 100644

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

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

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

include/linux/netdevice.h +90 -74

164 lines not on this page · raw message

include/linux/netpoll.h +0 -50

50 lines not on this page · raw message

net/core/dev.c +139 -84

223 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 +17 -43

60 lines not on this page · raw message

net/core/rtnetlink.c +0 -6
index 06eccca..b6b3618 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 5 lines · David Miller

Another area of consternation are drivers that were using netif_rx_reschedule(), as that interface was removed because it doesn't fit well with the caller managing the dev->quota et al. I left race conditions in the drivers that were using that interface, but they should still basically work nonetheless.

Hmm, virtio does this, if the implementation returns false from ->restart. But it's basically a bandaid for things like lguest which don't check irq status on irq enable, hence is subject to the race.

But AFAICT netif_rx_reschedule() is implementable in a driver anyway. What am I missing?

static void resched_me(struct work_struct *work)

{
	struct foo *foo = container_of(work, struct foo, work);

	irq_disable();
	netif_rx_schedule(foo->dev);
	irq_enable();
}
struct foo {
	...;
	struct napi_struct napi;
	struct work_struct rescheduler;
};

int foo_poll(struct napi_struct *napi, int budget) {
...

	enable_rx_interrupts();
	netif_rx_complete(napi);

	/* Broken interrupts, so we have race after enabling. */
	if (unlikely(ring_has_new_packet(dev)))
		schedule_work(&foo->rescheduler);
	return used;
}

Cheers,
Rusty.

author maintainer
#2 lore raw

From: Rusty Russell <[email protected]>
Date: Tue, 24 Jul 2007 14:47:19 +1000

Quoted 7 lines · David Miller
Quoted 5 lines

Another area of consternation are drivers that were using netif_rx_reschedule(), as that interface was removed because it doesn't fit well with the caller managing the dev->quota et al. I left race conditions in the drivers that were using that interface, but they should still basically work nonetheless.

Quoted 6 lines

Hmm, virtio does this, if the implementation returns false from ->restart. But it's basically a bandaid for things like lguest which don't check irq status on irq enable, hence is subject to the race.

But AFAICT netif_rx_reschedule() is implementable in a driver anyway. What am I missing?

That looks like it would work, yes.

This is the least understood area, semantically, of NAPI. It is commonly believed that level-triggered interrupts obviate the need to handle this race condition, and nothing could be further from the truth.

I don't think it's wise to implement this over and over again in each driver, since we already know at least a handfull of drivers will use this.

A netdev_napi_init() suggests itself already. We could put the work struct into the napi_struct and make the init routine something like:

static inline void netif_napi_init(struct napi_struct *napi,
int (*poll)(struct napi_struct *, int), void (*resched)(struct work *), int weight)

{
	napi->poll = poll;
	napi->weight = weight;
	INIT_WORK(&napi->work, resched);
}

and then we have napi_resched():

static inline void napi_resched(struct napi_struct *napi)

{
	schedule_work(&napi->work);
}

If this can be handled in a better way inside the driver, as is the case for tg3 et al., "resched" can be passed in as NULL.

Any objections?

#3 lore raw
Quoted 3 lines · David Miller

I don't think it's wise to implement this over and over again in each driver, since we already know at least a handfull of drivers will use this.

Yep. Alternative is a napi_struct_with_restart, but I don't think it's worth the few-byte savings per queue.

Quoted 1 line

Any objections?

On the contrary, this looks good.

Thanks!
Rusty.

#12 lore raw
In reply to David Miller

David Miller <[email protected]> :
[...]

Quoted 2 lines

I also didn't play with turning off NAPI in kconfig where drivers allow that, can we just get rid of that crap already? :-/

Would it be accepted for 2.6.23 or must it be considered post-2.6.23 ?

Signature · 1 line
Ueimor
#13 lore raw
Quoted 6 lines · Francois Romieu

David Miller <[email protected]> :
[...]

Quoted 2 lines

I also didn't play with turning off NAPI in kconfig where drivers allow that, can we just get rid of that crap already? :-/

Would it be accepted for 2.6.23 or must it be considered post-2.6.23 ?

The merge window is closed, so not 2.6.23.

The cases where Kconfig allows selection of NAPI-or-not is generally either (a) the author considers one path new and relatively unproven or (b) the author has not bothered to figure out which is the best choice, and instead just offers both rather than doing the legwork to find out.

Either way, individual cases must be examined and it is not necessarily just a cleanup.

Jeff

author maintainer
#14 lore raw
In reply to Francois Romieu

From: Francois Romieu <[email protected]>
Date: Tue, 24 Jul 2007 09:12:01 +0200

Quoted 6 lines

David Miller <[email protected]> :
[...]

Quoted 2 lines

I also didn't play with turning off NAPI in kconfig where drivers allow that, can we just get rid of that crap already? :-/

Would it be accepted for 2.6.23 or must it be considered post-2.6.23 ?

The 2.6.23 merge window closed already, so this is of course 2.6.24 material.

author maintainer
#4 lore raw
In reply to Rusty Russell

From: Rusty Russell <[email protected]>
Date: Tue, 24 Jul 2007 16:21:43 +1000

Quoted 4 lines · David Miller
Quoted 1 line

Any objections?

On the contrary, this looks good.

It turns out the explicit restart logic isn't necessary. On the first driver I tried to "convert" this became apparent real fast.

The key is what the ->poll() caller does if you don't complete the NAPI, from net_rx_action():

			/* if napi_complete not called, reschedule */
			if (test_bit(NAPI_STATE_SCHED, &n->state))
				__napi_schedule(n);

Let's look at ep93xx_poll() as it sits in my current tree, which used to use netif_rx_reschedule():

static int ep93xx_poll(struct napi_struct *napi, int budget)

{
	struct ep93xx_priv *ep = container_of(napi, struct ep93xx_priv, napi);
	struct net_device *dev = ep->dev;
	int rx;

	/*
	 * @@@ Have to stop polling if device is downed while we
	 * are polling.
	 */

	rx = ep93xx_rx(dev, 0, budget);
	if (rx < budget) {
		spin_lock_irq(&ep->rx_lock);
		wrl(ep, REG_INTEN, REG_INTEN_TX | REG_INTEN_RX);
		if (ep93xx_have_more_rx(ep))
			wrl(ep, REG_INTEN, REG_INTEN_TX);
		else
			netif_rx_complete(dev, napi);
		spin_unlock_irq(&ep->rx_lock);
	}

	return rx;
}

This driver handles TX in it's hardware interrupt handler, and RX via NAPI. So to NAPI poll it simply disables RX interrupts and schedules NAPI.

	if (status & REG_INTSTS_RX) {
		spin_lock(&ep->rx_lock);
		if (likely(__netif_rx_schedule_prep(dev, &ep->napi))) {
			wrl(ep, REG_INTEN, REG_INTEN_TX);
			__netif_rx_schedule(dev, &ep->napi);
		}
		spin_unlock(&ep->rx_lock);
	}

anyways, if after re-enabling RX interrupts it sees some RX work, it can simply re-disable RX interrupts and leave the NAPI state alone. And that's how I've coded things above.

The caller will requeue the NAPI instance onto the poll list, nothing more needs to be done to prevent event loss.

I'm now going to go over the other resched cases and make sure things can be similarly handled in those drivers as well. To be honest I'm quite confident this will be the case.

#5 lore raw
Quoted 3 lines · David Miller

I'm now going to go over the other resched cases and make sure things can be similarly handled in those drivers as well. To be honest I'm quite confident this will be the case.

If I understand correctly, you're looking at a general model like the following:

	while (more_packets()) { ... netif_receive_skb() }

	enable_rx_and_rxnobuf_ints();

	/* Lock protects against race w/ rx interrupt re-queueing us */
	spin_lock_irq();
	if (!more_packets())
		netif_rx_complete(dev);
	else
		/* We'll be scheduled again. */
		disable_rx_and_rxnobuff_ints();
	spin_unlock_irq();

Seems pretty robust to me. The race is probably pretty unusual, so the only downside is the locking overhead? Even non-irq-problematic drivers could use this (ie. virt_net.c probably wants to do it even though virtio implementation may not have this issue).

Cheers,
Rusty.

author maintainer
#6 lore raw

From: Rusty Russell <[email protected]>
Date: Wed, 25 Jul 2007 11:15:49 +1000

Quoted 16 lines

If I understand correctly, you're looking at a general model like the following:

	while (more_packets()) { ... netif_receive_skb() }

	enable_rx_and_rxnobuf_ints();

	/* Lock protects against race w/ rx interrupt re-queueing us */
	spin_lock_irq();
	if (!more_packets())
		netif_rx_complete(dev);
	else
		/* We'll be scheduled again. */
		disable_rx_and_rxnobuff_ints();
	spin_unlock_irq();
Quoted 4 lines

Seems pretty robust to me. The race is probably pretty unusual, so the only downside is the locking overhead? Even non-irq-problematic drivers could use this (ie. virt_net.c probably wants to do it even though virtio implementation may not have this issue).

Yes, interesting cases come up in the existing virtual drivers. They do no locking at all :-) EHEA is another case, in fact EHEA doesn't disable interrupts at all.

The reason is that EHEA has several NAPI sources behind one single hardware interrupt.

That driver's issues were discussed long ago and actually were the initial impetus for Stephen to cut the first napi_struct patch.

Because of that weird layout EHEA needs special consideration, which I will get back to.

Anyways, here is how ibmveth.c looks right now in my tree:

static int ibmveth_poll(struct napi_struct *napi, int budget)

{
	struct ibmveth_adapter *adapter = container_of(napi, struct ibmveth_adapter, napi);
	struct net_device *netdev = adapter->netdev;
	int frames_processed = 0;
	unsigned long lpar_rc;

	do {
		struct sk_buff *skb;

		if (!ibmveth_rxq_pending_buffer(adapter))
			break;

		rmb();
		if (!ibmveth_rxq_buffer_valid(adapter)) {
 ...
		} else {
 ...
			frames_processed++;
 ...
		}
	} while (frames_processed < budget);

	ibmveth_replenish_task(adapter);

	if (frames_processed < budget) {
		/* We think we are done - reenable interrupts,
		 * then check once more to make sure we are done.
		 */
		spin_lock_irq(&adapter->poll_lock);
		lpar_rc = h_vio_signal(adapter->vdev->unit_address,
				       VIO_IRQ_ENABLE);

		ibmveth_assert(lpar_rc == H_SUCCESS);

		if (ibmveth_rxq_pending_buffer(adapter))
			lpar_rc = h_vio_signal(adapter->vdev->unit_address,
					       VIO_IRQ_DISABLE);
		else
			netif_rx_complete(netdev, napi);
		spin_unlock_irq(&adapter->poll_lock);
	}

	return frames_processed;
}

static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance)

{
	struct net_device *netdev = dev_instance;
	struct ibmveth_adapter *adapter = netdev->priv;
	unsigned long lpar_rc;

	spin_lock(&adapter->poll_lock);
	if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
		lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
		ibmveth_assert(lpar_rc == H_SUCCESS);
		__netif_rx_schedule(netdev, &adapter->napi);
	}
	spin_unlock(&adapter->poll_lock);
	return IRQ_HANDLED;
}

A part of me looks at cases like this and almost believes that the new spinlock is even superfluous. Consider:

1) ->poll() is guarenteed single-threaded wrt. itself
2) NAPI_STATE_SCHED provides implicit synchronization, it behaves as a lock

However the lock is necessary to synchronize the:

	reenable_interrupts();
	if (rx_pending())
		disable_interrupts();
	else
		netif_rx_complete(netdev, napi);

sequence.

Any arriving interrupt, up until the moment netif_rx_complete() is invoked, will fail the netif_rx_schedule_prep() test. So we could miss a NAPI schedule without the lock.

One thing that's peculiar is that when netif_rx_schedule_prep() fails, we don't disable interrupts but we also don't clear the condition that is causing the interrupt to occur.

This seems to suggest to me that we can loop a lot, or even get stuck completely handling the interrupt forever, when these scenerios trigger. So at the very least we need a local IRQ disable around the netif_rx_complete() sequence.

Perhaps the lock is avoidable somehow, who knows :)

#7 lore raw
Quoted 3 lines · David Miller

One thing that's peculiar is that when netif_rx_schedule_prep() fails, we don't disable interrupts but we also don't clear the condition that is causing the interrupt to occur.

I think we're ok, but this stuff is tricky.

In the driver in -rc1, I think it will only fail if racing with the netif_rx_reschedule, which will do the right thing.

In your version, there is only one place where prep can fail (ie. interrupts are enabled, but netif_rx_complete() hasn't been called):
when ibmveth_poll saw pending buffers and disabled the irq (which has already been delivered and is spinning on the poll_lock)

In this case, we're ok because the irqs really are disabled now: the running handler is a relic.

Quoted 1 line

Perhaps the lock is avoidable somehow, who knows :)

Maybe by adding YA state bit? Hold on, this might get ugly...

Say netif_rx_schedule_prep() sets the MORE_TODO bit (atomically instead of setting __LINK_STATE_RX_SCHED) if it's going to fail, and netif_rx_complete() returns 0 if it was set, or 1 if it's OK. Now callers do:

	reenable_interrupts();
        if (rx_pending() || !netif_rx_complete(netdev, napi))
                disable_interrupts();

I'm going to go absorb some more caffeine before you reply 8)

Rusty.

author maintainer
#8 lore raw

From: Rusty Russell <[email protected]>
Date: Wed, 25 Jul 2007 12:33:14 +1000

Quoted 10 lines

Maybe by adding YA state bit? Hold on, this might get ugly...

Say netif_rx_schedule_prep() sets the MORE_TODO bit (atomically instead of setting __LINK_STATE_RX_SCHED) if it's going to fail, and netif_rx_complete() returns 0 if it was set, or 1 if it's OK. Now callers do:

	reenable_interrupts();
        if (rx_pending() || !netif_rx_complete(netdev, napi))
                disable_interrupts();

This is an interesting idea, and would work, but the extra atomics for something that 2 or 3 drivers actually need.... unless I misunderstand your suggestion?

#9 lore raw
Quoted 10 lines · David Miller

From: Rusty Russell <[email protected]>
Date: Wed, 25 Jul 2007 12:33:14 +1000

Quoted 7 lines

Maybe by adding YA state bit? Hold on, this might get ugly...

Say netif_rx_schedule_prep() sets the MORE_TODO bit (atomically instead of setting __LINK_STATE_RX_SCHED) if it's going to fail, and netif_rx_complete() returns 0 if it was set, or 1 if it's OK. Now callers do:

Quoted 7 lines
Quoted 3 lines
	reenable_interrupts();
        if (rx_pending() || !netif_rx_complete(netdev, napi))
                disable_interrupts();

This is an interesting idea, and would work, but the extra atomics for something that 2 or 3 drivers actually need.... unless I misunderstand your suggestion?

Well, netif_rx_schedule_prep() becomes a cmpxchg instead of a test_and_set_bit:

	/* We either set MORE_TODO or RX_SCHED. */
	unsigned long state;

again:

	state = napi->state;
	if (!(state & __LINK_STATE_RX_SCHED)) {
		if (cmpxchg(&napi->state, state, state|__LINK_STATE_RX_SCHED) == state)
			return 1;
	} else {
		if (cmpxchg(&napi->state, state, state|__LINK_STATE_MORE_TODO) == state)
			return 0;
	}
	goto again;

netif_rx_complete would need something more complex... hmm...

	unsigned long state;
again:
	state = napi->state;

	if (state & __LINK_STATE_MORE_TODO)
		return 0;

	list_del(&napi->poll_list);
	if (cmpxchg(&napi->state, state, state & ~__LINK_STATE_RX_SCHED) == state)
		return 1;
	list_add_tail(napi->poll_list, &__get_cpu_var(softnet_data).poll_list);
	goto again;

Not pretty 8(

Rusty.

	if (
author maintainer
#11 lore raw
In reply to David Miller

From: David Miller <[email protected]>
Date: Tue, 24 Jul 2007 18:47:59 -0700 (PDT)

Quoted 11 lines

EHEA is another case, in fact EHEA doesn't disable interrupts at all.

The reason is that EHEA has several NAPI sources behind one single hardware interrupt.

That driver's issues were discussed long ago and actually were the initial impetus for Stephen to cut the first napi_struct patch.

Because of that weird layout EHEA needs special consideration, which I will get back to.

Some of the things I say above seem to be not true. :-)

I studied the EHEA driver a bit, enclosed at the end of this email is the current version of the code in my napi_struct tree.

It seems there is one unique interrupt per port. So this device's layout is identical to the one sunvnet, and other virtualized net devices, tend to have. Multiple ports per netdev, each port generating unique events.

It also seems that the EHEA interrupts are "one-shot" in nature, and it seems that the:

ehea_reset_cq_ep(pr->recv_cq);
ehea_reset_cq_ep(pr->send_cq);
ehea_reset_cq_n1(pr->recv_cq);

operations are what get the interrupt going again. If someone reading this understands the hardware better, please let us know if this analysis is accurate, thanks.

So it appears I subconsciously converted this driver to multi-NAPI away from the dreaded "dummy netdevice" scheme a lot of multi-queue drivers are using. It's amusing because I don't remember consciously doing this, but I'll take it nonetheless! :-)

This appears to resolve all of the NAPI limitations in the driver without having to waste memory and resources on dummy net devices.

In short, EHEA is a great fit for napi_struct!

It may look corny how the spinlock in the interrupt handler just sits around the netif_rx_schedule() call and nothing else, but I do believe it is necessary so that the "reenable interrupt, then maybe netif_rx_complete()" runs atomically wrt. the interrupt NAPI trigger in order to avoid lost events.

EHEA is also a perfect candidate for the solutions being suggested for multi-TX-queue situations like sunvnet. I'll have to get back to that at some point.

drivers/net/ehea/ehea.h +2 -1
index 489c8b2..d4227be 100644
@@ -351,6 +351,8 @@ struct ehea_q_skb_arr {
  * Port resources
  */
 struct ehea_port_res {
+	spinlock_t poll_lock;
+	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 +364,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 +29 -40

184 lines not on this page · raw message

author maintainer
#10 lore raw
In reply to Rusty Russell

From: Rusty Russell <[email protected]>
Date: Wed, 25 Jul 2007 15:09:55 +1000

Quoted 1 line

Not pretty 8(

Not at all and cmpxchg() isn't really a generically usable primitive. Yes all platforms provide atomic_cmpxchg() in one form or another, but it's really barbaric and inefficient on some cpu types.

Let's can this idea for now.

#15 lore raw
In reply to David Miller

I've been on vacation so I missed most of this thread. I'm just catching up now...

Quoted 3 lines

Ok I converted everything with Rusty's suggestion to move napi_struct out of net_device, this was mostly mechanical but some devices took some unanticipated amount of work.

Actually you missed drivers/infiniband/ulp/ipoib, which has used NAPI since 2.6.22. I can take a stab at the conversion soon if you want...

Quoted 5 lines

Another area of consternation are drivers that were using netif_rx_reschedule(), as that interface was removed because it doesn't fit well with the caller managing the dev->quota et al. I left race conditions in the drivers that were using that interface, but they should still basically work nonetheless.

...but this is a problem for IPoIB. The underlying IB stuff only allows us to register what is essentially a one-shot edge-triggered interrupt. So there is a race between calling netif_rx_complete() and calling ib_req_notify_cq() (which enables the interrupt), since the interrupt might never happen if a packet arrives between the two calls.

In the current driver we are OK because ib_req_notify_cq() can return a hint if an event was missed, but to use this hint we need a way to restart the NAPI poll without getting into trouble if the interrupt handler calls netif_rx_schedule() too.

Thanks,
Roland

author maintainer
#16 lore raw

From: Roland Dreier <[email protected]>
Date: Sat, 28 Jul 2007 08:21:58 -0700

Quoted 11 lines
Quoted 5 lines

Another area of consternation are drivers that were using netif_rx_reschedule(), as that interface was removed because it doesn't fit well with the caller managing the dev->quota et al. I left race conditions in the drivers that were using that interface, but they should still basically work nonetheless.

...but this is a problem for IPoIB. The underlying IB stuff only allows us to register what is essentially a one-shot edge-triggered interrupt. So there is a race between calling netif_rx_complete() and calling ib_req_notify_cq() (which enables the interrupt), since the interrupt might never happen if a packet arrives between the two calls.

You will see further along in the thread that we have found a locking sequence by which this issue can be resolved.

Please read the full thread and the most recent patch before coming to conclusions :-)