All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roland Dreier <rdreier@cisco.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org, jeff@garzik.org, general@lists.openfabrics.org
Subject: [ofa-general] [PATCH 2/4] ibm_emac: Convert to use napi_struct independent of struct net_device
Date: Tue, 09 Oct 2007 15:47:37 -0700	[thread overview]
Message-ID: <ada8x6bhpme.fsf_-_@cisco.com> (raw)
In-Reply-To: <adad4vnhpoq.fsf_-_@cisco.com> (Roland Dreier's message of "Tue, 09 Oct 2007 15:46:13 -0700")

Commit da3dedd9 ("[NET]: Make NAPI polling independent of struct
net_device objects.") changed the interface to NAPI polling.  Fix up
the ibm_emac driver so that it works with this new interface.  This is
actually a nice cleanup because ibm_emac is one of the drivers that
wants to have multiple NAPI structures for a single net_device.

Tested with the internal MAC of a PowerPC 440SPe SoC with an AMCC
'Yucca' evaluation board.

Signed-off-by: Roland Dreier <rolandd@cisco.com>
---
 drivers/net/ibm_emac/ibm_emac_mal.c |   48 ++++++++++++----------------------
 drivers/net/ibm_emac/ibm_emac_mal.h |    2 +-
 include/linux/netdevice.h           |   10 +++++++
 3 files changed, 28 insertions(+), 32 deletions(-)

diff --git a/drivers/net/ibm_emac/ibm_emac_mal.c b/drivers/net/ibm_emac/ibm_emac_mal.c
index cabd984..cc3ddc9 100644
--- a/drivers/net/ibm_emac/ibm_emac_mal.c
+++ b/drivers/net/ibm_emac/ibm_emac_mal.c
@@ -207,10 +207,10 @@ static irqreturn_t mal_serr(int irq, void *dev_instance)
 
 static inline void mal_schedule_poll(struct ibm_ocp_mal *mal)
 {
-	if (likely(netif_rx_schedule_prep(&mal->poll_dev))) {
+	if (likely(napi_schedule_prep(&mal->napi))) {
 		MAL_DBG2("%d: schedule_poll" NL, mal->def->index);
 		mal_disable_eob_irq(mal);
-		__netif_rx_schedule(&mal->poll_dev);
+		__napi_schedule(&mal->napi);
 	} else
 		MAL_DBG2("%d: already in poll" NL, mal->def->index);
 }
@@ -273,11 +273,11 @@ static irqreturn_t mal_rxde(int irq, void *dev_instance)
 	return IRQ_HANDLED;
 }
 
-static int mal_poll(struct net_device *ndev, int *budget)
+static int mal_poll(struct napi_struct *napi, int budget)
 {
-	struct ibm_ocp_mal *mal = ndev->priv;
+	struct ibm_ocp_mal *mal = container_of(napi, struct ibm_ocp_mal, napi);
 	struct list_head *l;
-	int rx_work_limit = min(ndev->quota, *budget), received = 0, done;
+	int received = 0;
 
 	MAL_DBG2("%d: poll(%d) %d ->" NL, mal->def->index, *budget,
 		 rx_work_limit);
@@ -295,38 +295,34 @@ static int mal_poll(struct net_device *ndev, int *budget)
 	list_for_each(l, &mal->poll_list) {
 		struct mal_commac *mc =
 		    list_entry(l, struct mal_commac, poll_list);
-		int n = mc->ops->poll_rx(mc->dev, rx_work_limit);
+		int n = mc->ops->poll_rx(mc->dev, budget);
 		if (n) {
 			received += n;
-			rx_work_limit -= n;
-			if (rx_work_limit <= 0) {
-				done = 0;
+			budget -= n;
+			if (budget <= 0)
 				goto more_work;	// XXX What if this is the last one ?
-			}
 		}
 	}
 
 	/* We need to disable IRQs to protect from RXDE IRQ here */
 	local_irq_disable();
-	__netif_rx_complete(ndev);
+	__napi_complete(napi);
 	mal_enable_eob_irq(mal);
 	local_irq_enable();
 
-	done = 1;
-
 	/* Check for "rotting" packet(s) */
 	list_for_each(l, &mal->poll_list) {
 		struct mal_commac *mc =
 		    list_entry(l, struct mal_commac, poll_list);
 		if (unlikely(mc->ops->peek_rx(mc->dev) || mc->rx_stopped)) {
 			MAL_DBG2("%d: rotting packet" NL, mal->def->index);
-			if (netif_rx_reschedule(ndev, received))
+			if (napi_reschedule(napi))
 				mal_disable_eob_irq(mal);
 			else
 				MAL_DBG2("%d: already in poll list" NL,
 					 mal->def->index);
 
-			if (rx_work_limit > 0)
+			if (budget > 0)
 				goto again;
 			else
 				goto more_work;
@@ -335,12 +331,8 @@ static int mal_poll(struct net_device *ndev, int *budget)
 	}
 
       more_work:
-	ndev->quota -= received;
-	*budget -= received;
-
-	MAL_DBG2("%d: poll() %d <- %d" NL, mal->def->index, *budget,
-		 done ? 0 : 1);
-	return done ? 0 : 1;
+	MAL_DBG2("%d: poll() %d <- %d" NL, mal->def->index, budget, received);
+	return received;
 }
 
 static void mal_reset(struct ibm_ocp_mal *mal)
@@ -425,11 +417,8 @@ static int __init mal_probe(struct ocp_device *ocpdev)
 	mal->def = ocpdev->def;
 
 	INIT_LIST_HEAD(&mal->poll_list);
-	set_bit(__LINK_STATE_START, &mal->poll_dev.state);
-	mal->poll_dev.weight = CONFIG_IBM_EMAC_POLL_WEIGHT;
-	mal->poll_dev.poll = mal_poll;
-	mal->poll_dev.priv = mal;
-	atomic_set(&mal->poll_dev.refcnt, 1);
+	mal->napi.weight = CONFIG_IBM_EMAC_POLL_WEIGHT;
+	mal->napi.poll = mal_poll;
 
 	INIT_LIST_HEAD(&mal->list);
 
@@ -520,11 +509,8 @@ static void __exit mal_remove(struct ocp_device *ocpdev)
 
 	MAL_DBG("%d: remove" NL, mal->def->index);
 
-	/* Syncronize with scheduled polling, 
-	   stolen from net/core/dev.c:dev_close() 
-	 */
-	clear_bit(__LINK_STATE_START, &mal->poll_dev.state);
-	netif_poll_disable(&mal->poll_dev);
+	/* Synchronize with scheduled polling */
+	napi_disable(&mal->napi);
 
 	if (!list_empty(&mal->list)) {
 		/* This is *very* bad */
diff --git a/drivers/net/ibm_emac/ibm_emac_mal.h b/drivers/net/ibm_emac/ibm_emac_mal.h
index 64bc338..8f54d62 100644
--- a/drivers/net/ibm_emac/ibm_emac_mal.h
+++ b/drivers/net/ibm_emac/ibm_emac_mal.h
@@ -195,7 +195,7 @@ struct ibm_ocp_mal {
 	dcr_host_t		dcrhost;
 
 	struct list_head	poll_list;
-	struct net_device	poll_dev;
+	struct napi_struct	napi;
 
 	struct list_head	list;
 	u32			tx_chan_mask;
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 91cd3f3..4848c7a 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -349,6 +349,16 @@ static inline void napi_schedule(struct napi_struct *n)
 		__napi_schedule(n);
 }
 
+/* Try to reschedule poll. Called by dev->poll() after napi_complete().  */
+static inline int napi_reschedule(struct napi_struct *napi)
+{
+	if (napi_schedule_prep(napi)) {
+		__napi_schedule(napi);
+		return 1;
+	}
+	return 0;
+}
+
 /**
  *	napi_complete - NAPI processing complete
  *	@n: napi context

  reply	other threads:[~2007-10-09 22:47 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-08 18:26 [PATCH 2/3][NET_BATCH] net core use batching jamal
2007-10-08 19:46 ` Waskiewicz Jr, Peter P
2007-10-08 20:48   ` jamal
2007-10-08 21:26     ` [ofa-general] " David Miller
2007-10-08 22:34       ` jamal
2007-10-08 22:36         ` [ofa-general] " Waskiewicz Jr, Peter P
2007-10-08 22:33     ` Waskiewicz Jr, Peter P
2007-10-08 23:40       ` jamal
2007-10-09  1:13         ` Jeff Garzik
2007-10-09  1:41           ` [ofa-general] " David Miller
2007-10-09  2:01             ` Herbert Xu
2007-10-09  2:03               ` Herbert Xu
2007-10-09  2:04                 ` Herbert Xu
2007-10-09  2:15                   ` jamal
2007-10-09  2:16                     ` Herbert Xu
2007-10-09  2:19                       ` [ofa-general] " jamal
2007-10-09  2:20                         ` Herbert Xu
2007-10-09  2:45                   ` [ofa-general] " David Miller
2007-10-09  2:43                 ` David Miller
2007-10-09  2:46                   ` Herbert Xu
2007-10-09  2:12             ` [ofa-general] " Jeff Garzik
2007-10-09  2:46               ` David Miller
2007-10-09 18:48               ` [ofa-general] " Waskiewicz Jr, Peter P
2007-10-09 19:04                 ` Jeff Garzik
2007-10-09 19:07                   ` Waskiewicz Jr, Peter P
2007-10-09  2:14             ` [ofa-general] " jamal
2007-10-09  2:16               ` Herbert Xu
2007-10-09  2:47                 ` [ofa-general] " David Miller
2007-10-09 16:51             ` Andi Kleen
2007-10-09 18:22               ` Stephen Hemminger
2007-10-09 18:30                 ` Andi Kleen
2007-10-09 20:43               ` David Miller
2007-10-09 20:53                 ` Stephen Hemminger
2007-10-09 21:22                   ` David Miller
2007-10-09 21:56                     ` jamal
2007-10-10  0:04                       ` David Miller
2007-10-10  0:37                         ` Andi Kleen
2007-10-10  0:50                           ` David Miller
2007-10-10  9:16                             ` Andi Kleen
2007-10-10  9:25                               ` David Miller
2007-10-10 10:23                                 ` Andi Kleen
2007-10-10 10:44                                   ` David Miller
2007-10-10 13:08                                     ` jamal
2007-10-10 22:37                                       ` David Miller
2007-10-10 15:35                                     ` Waskiewicz Jr, Peter P
2007-10-10 16:02                                       ` Andi Kleen
2007-10-10 16:42                                         ` Waskiewicz Jr, Peter P
2007-10-10  9:53                               ` Herbert Xu
2007-10-12 16:08                           ` Brandeburg, Jesse
2007-10-12 17:05                             ` Stephen Hemminger
2007-10-12 18:29                               ` Andi Kleen
2007-10-12 18:27                             ` Andi Kleen
2007-10-10 16:02                         ` Bill Fink
2007-10-10 22:53                           ` David Miller
2007-10-11  6:52                 ` Krishna Kumar2
2007-10-09  1:31         ` Jeff Garzik
2007-10-09 10:58       ` [ofa-general] " Krishna Kumar2
2007-10-09 11:02         ` David Miller
2007-10-09 11:20           ` [ofa-general] " Krishna Kumar2
2007-10-09 11:21           ` Krishna Kumar2
2007-10-09 11:24             ` David Miller
2007-10-09 12:44               ` [ofa-general] " Jeff Garzik
2007-10-09 12:55                 ` Herbert Xu
2007-10-09 13:00                   ` Jeff Garzik
2007-10-09 20:14                 ` David Miller
2007-10-09 20:20                   ` [ofa-general] " Jeff Garzik
2007-10-09 21:25                     ` David Miller
2007-10-09 20:22               ` [ofa-general] " Roland Dreier
2007-10-09 20:51                 ` David Miller
2007-10-09 21:40                   ` Roland Dreier
2007-10-09 22:44                   ` [ofa-general] " Roland Dreier
2007-10-09 22:46                     ` [ofa-general] [PATCH 1/4] IPoIB: Fix unused variable warning Roland Dreier
2007-10-09 22:47                       ` Roland Dreier [this message]
2007-10-09 22:47                       ` [PATCH 3/4] ibm_new_emac: Nuke SET_MODULE_OWNER() use Roland Dreier
2007-10-09 22:48                       ` [PATCH 4/4] ibm_emac: Convert to use napi_struct independent of struct net_device Roland Dreier
2007-10-09 22:51                         ` [ofa-general] " Roland Dreier
2007-10-09 23:17                       ` [PATCH 1/4] IPoIB: Fix unused variable warning David Miller
2007-10-10  0:32                         ` Jeff Garzik
2007-10-10  0:47                       ` [ofa-general] " Jeff Garzik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ada8x6bhpme.fsf_-_@cisco.com \
    --to=rdreier@cisco.com \
    --cc=davem@davemloft.net \
    --cc=general@lists.openfabrics.org \
    --cc=jeff@garzik.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.