Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bea3348e authored by Stephen Hemminger's avatar Stephen Hemminger Committed by David S. Miller
Browse files

[NET]: Make NAPI polling independent of struct net_device objects.



Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.

In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.

The signature of the ->poll() call back goes from:

	int foo_poll(struct net_device *dev, int *budget)

to

	int foo_poll(struct napi_struct *napi, int budget)

The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract).  The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.

The napi_struct is to be embedded in the device driver private data
structures.

Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler.  Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.

With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.

Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.

[ Ported to current tree and all drivers converted.  Integrated
  Stephen's follow-on kerneldoc additions, and restored poll_list
  handling to the old style to fix mutual exclusion issues.  -DaveM ]

Signed-off-by: default avatarStephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dde4e47e
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -240,17 +240,23 @@ X!Ilib/string.c
     <sect1><title>Driver Support</title>
!Enet/core/dev.c
!Enet/ethernet/eth.c
!Enet/sched/sch_generic.c
!Iinclude/linux/etherdevice.h
!Iinclude/linux/netdevice.h
     </sect1>
     <sect1><title>PHY Support</title>
!Edrivers/net/phy/phy.c
!Idrivers/net/phy/phy.c
!Edrivers/net/phy/phy_device.c
!Idrivers/net/phy/phy_device.c
!Edrivers/net/phy/mdio_bus.c
!Idrivers/net/phy/mdio_bus.c
     </sect1>
<!-- FIXME: Removed for now since no structured comments in source
     <sect1><title>Wireless</title>
X!Enet/core/wireless.c
-->
     </sect1>
-->
     <sect1><title>Synchronous PPP</title>
!Edrivers/net/wan/syncppp.c
     </sect1>
+0 −766

File deleted.

Preview size limit exceeded, changes collapsed.

+8 −4
Original line number Diff line number Diff line
@@ -95,9 +95,13 @@ dev->set_multicast_list:
	Synchronization: netif_tx_lock spinlock.
	Context: BHs disabled

dev->poll:
	Synchronization: __LINK_STATE_RX_SCHED bit in dev->state.  See
		dev_close code and comments in net/core/dev.c for more info.
struct napi_struct synchronization rules
========================================
napi->poll:
	Synchronization: NAPI_STATE_SCHED bit in napi->state.  Device
		driver's dev->close method will invoke napi_disable() on
		all NAPI instances which will do a sleeping poll on the
		NAPI_STATE_SCHED napi->state bit, waiting for all pending
		NAPI activity to cease.
	Context: softirq
	         will be called with interrupts disabled by netconsole.
+3 −1
Original line number Diff line number Diff line
@@ -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,
+18 −25
Original line number Diff line number Diff line
@@ -281,63 +281,58 @@ static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
			   wc->status, wr_id, wc->vendor_err);
}

int ipoib_poll(struct net_device *dev, int *budget)
int ipoib_poll(struct napi_struct *napi, int budget)
{
	struct ipoib_dev_priv *priv = netdev_priv(dev);
	int max = min(*budget, dev->quota);
	struct ipoib_dev_priv *priv = container_of(napi, struct ipoib_dev_priv, napi);
	struct net_device *dev = priv->dev;
	int done;
	int t;
	int empty;
	int n, i;

	done  = 0;
	empty = 0;

	while (max) {
poll_more:
	while (done < budget) {
		int max = (budget - done);

		t = min(IPOIB_NUM_WC, max);
		n = ib_poll_cq(priv->cq, t, priv->ibwc);

		for (i = 0; i < n; ++i) {
		for (i = 0; i < n; i++) {
			struct ib_wc *wc = priv->ibwc + i;

			if (wc->wr_id & IPOIB_CM_OP_SRQ) {
				++done;
				--max;
				ipoib_cm_handle_rx_wc(dev, wc);
			} else if (wc->wr_id & IPOIB_OP_RECV) {
				++done;
				--max;
				ipoib_ib_handle_rx_wc(dev, wc);
			} else
				ipoib_ib_handle_tx_wc(dev, wc);
		}

		if (n != t) {
			empty = 1;
		if (n != t)
			break;
	}
	}

	dev->quota -= done;
	*budget    -= done;

	if (empty) {
		netif_rx_complete(dev);
	if (done < budget) {
		netif_rx_complete(dev, napi);
		if (unlikely(ib_req_notify_cq(priv->cq,
					      IB_CQ_NEXT_COMP |
					      IB_CQ_REPORT_MISSED_EVENTS)) &&
		    netif_rx_reschedule(dev, 0))
			return 1;

		return 0;
		    netif_rx_reschedule(dev, napi))
			goto poll_more;
	}

	return 1;
	return done;
}

void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr)
{
	netif_rx_schedule(dev_ptr);
	struct net_device *dev = dev_ptr;
	struct ipoib_dev_priv *priv = netdev_priv(dev);

	netif_rx_schedule(dev, &priv->napi);
}

static inline int post_send(struct ipoib_dev_priv *priv,
@@ -577,7 +572,6 @@ int ipoib_ib_dev_stop(struct net_device *dev, int flush)
	int i;

	clear_bit(IPOIB_FLAG_INITIALIZED, &priv->flags);
	netif_poll_disable(dev);

	ipoib_cm_dev_stop(dev);

@@ -660,7 +654,6 @@ timeout:
		msleep(1);
	}

	netif_poll_enable(dev);
	ib_req_notify_cq(priv->cq, IB_CQ_NEXT_COMP);

	return 0;
Loading