From takashi@luna.gotdns.com  Wed Oct 30 20:14:24 2002
Return-Path: <takashi@luna.gotdns.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 645A437B401
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Oct 2002 20:14:24 -0800 (PST)
Received: from luna.wipeout.jp (193.104.111.219.dy.excite.co.jp [219.111.104.193])
	by mx1.FreeBSD.org (Postfix) with ESMTP id F16DA43E6E
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Oct 2002 20:14:17 -0800 (PST)
	(envelope-from takashi@luna.gotdns.com)
Received: from luna.wipeout.jp (localhost [127.0.0.1])
	by luna.wipeout.jp (8.12.6/8.12.6) with ESMTP id g9V4E6pT003364
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 31 Oct 2002 13:14:06 +0900 (JST)
	(envelope-from takashi@luna.gotdns.com)
Received: (from takashi@localhost)
	by luna.wipeout.jp (8.12.6/8.12.6/Submit) id g9V4E6mZ003363;
	Thu, 31 Oct 2002 13:14:06 +0900 (JST)
Message-Id: <200210310414.g9V4E6mZ003363@luna.wipeout.jp>
Date: Thu, 31 Oct 2002 13:14:06 +0900 (JST)
From: Takashi Oono <takashi@yha.att.ne.jp>
Reply-To: Takashi Oono <takashi@yha.att.ne.jp>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Device polling support for nge(4) driver
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         44772
>Category:       kern
>Synopsis:       Device polling support for nge(4) driver
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    simokawa
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 30 20:20:01 PST 2002
>Closed-Date:    Sat Nov 23 10:33:23 PST 2002
>Last-Modified:  Sat Nov 23 10:33:23 PST 2002
>Originator:     Takashi Oono
>Release:        FreeBSD 4.7-STABLE i386
>Organization:
AlphaNet Co.,LTD.
>Environment:
System: FreeBSD luna.wipeout.jp 4.7-STABLE FreeBSD 4.7-STABLE #0: Tue Oct 22 11:54:15 JST 2002 root@luna.wipeout.jp:/export/obj/export/src/sys/GENERIC i386


>Description:
		Device polling support for nge(4) driver
>How-To-Repeat:
		nothing
>Fix:


*** if_nge.c.orig	Fri Aug 16 01:38:55 2002
--- if_nge.c	Thu Oct 31 10:33:49 2002
***************
*** 1380,1385 ****
--- 1380,1393 ----
  		struct mbuf		*m0 = NULL;
  		u_int32_t		extsts;
  
+ #ifdef DEVICE_POLLING
+ 		if (ifp->if_ipending & IFF_POLLING) {
+ 			if (sc->rxcycles <= 0)
+ 				break;
+ 			sc->rxcycles--;
+ 		}
+ #endif /* DEVICE_POLLING */
+ 
  		cur_rx = &sc->nge_ldata->nge_rx_list[i];
  		rxstat = cur_rx->nge_rxstat;
  		extsts = cur_rx->nge_extsts;
***************
*** 1584,1589 ****
--- 1592,1645 ----
  	return;
  }
  
+ #ifdef DEVICE_POLLING
+ static poll_handler_t nge_poll;
+ 
+ static void
+ nge_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
+ {
+ 	struct  nge_softc *sc = ifp->if_softc;
+ 
+ 	if (cmd == POLL_DEREGISTER) {	/* final call, enable interrupts */
+ 		CSR_WRITE_4(sc, NGE_IER, 1);
+ 		return;
+ 	}
+ 
+ 	/*
+ 	 * On the nge, reading the status register also clears it.
+ 	 * So before returning to intr mode we must make sure that all
+ 	 * possible pending sources of interrupts have been served.
+ 	 * In practice this means run to completion the *eof routines,
+ 	 * and then call the interrupt routine
+ 	 */
+ 	sc->rxcycles = count;
+ 	nge_rxeof(sc);
+ 	nge_txeof(sc);
+ 	if (ifp->if_snd.ifq_head != NULL)
+ 		nge_start(ifp);
+ 
+ 	if (sc->rxcycles > 0 || cmd == POLL_AND_CHECK_STATUS) {
+ 		u_int32_t	status;
+ 
+ 		/* Reading the ISR register clears all interrupts. */
+ 		status = CSR_READ_4(sc, NGE_ISR);
+ 
+ 		if (status & (NGE_ISR_RX_ERR|NGE_ISR_RX_OFLOW))
+ 			nge_rxeof(sc);
+ 
+ 		if (status & (NGE_ISR_RX_IDLE))
+ 			NGE_SETBIT(sc, NGE_CSR, NGE_CSR_RX_ENABLE);
+ 
+ 		if (status & NGE_ISR_SYSERR) {
+ 			nge_reset(sc);
+ 			nge_init(sc);
+ 		}
+ 	}
+ }
+ #endif /* DEVICE_POLLING */
+ 
+ 
+ 
  static void nge_intr(arg)
  	void			*arg;
  {
***************
*** 1594,1599 ****
--- 1650,1665 ----
  	sc = arg;
  	ifp = &sc->arpcom.ac_if;
  
+ #ifdef DEVICE_POLLING
+ 	if (ifp->if_ipending & IFF_POLLING)
+ 		return;
+ 	if (ether_poll_register(nge_poll, ifp)) { /* ok, disable interrupts */
+ 		CSR_WRITE_4(sc, NGE_IER, 0);
+ 		nge_poll(ifp, 0, 1);
+ 		return;
+ 	}
+ #endif /* DEVICE_POLLING */
+ 
  	/* Supress unwanted interrupts */
  	if (!(ifp->if_flags & IFF_UP)) {
  		nge_stop(sc);
***************
*** 1957,1962 ****
--- 2023,2037 ----
  	 * Enable interrupts.
  	 */
  	CSR_WRITE_4(sc, NGE_IMR, NGE_INTRS);
+ #ifdef DEVICE_POLLING
+ 	/*
+ 	 * ... only enable interrupts if we are not polling, make sure
+ 	 * they are off otherwise.
+ 	 */
+ 	if (ifp->if_ipending & IFF_POLLING)
+ 		CSR_WRITE_4(sc, NGE_IER, 0);
+ 	else
+ #endif /* DEVICE_POLLING */
  	CSR_WRITE_4(sc, NGE_IER, 1);
  
  	/* Enable receiver and transmitter. */
***************
*** 2210,2215 ****
--- 2285,2293 ----
  	}
  
  	untimeout(nge_tick, sc, sc->nge_stat_ch);
+ #ifdef DEVICE_POLLING
+ 	ether_poll_deregister(ifp);
+ #endif
  	CSR_WRITE_4(sc, NGE_IER, 0);
  	CSR_WRITE_4(sc, NGE_IMR, 0);
  	NGE_SETBIT(sc, NGE_CSR, NGE_CSR_TX_DISABLE|NGE_CSR_RX_DISABLE);





*** if_ngereg.h.orig	Fri Aug 16 01:38:55 2002
--- if_ngereg.h	Thu Oct 31 10:33:59 2002
***************
*** 664,669 ****
--- 664,672 ----
  	SLIST_HEAD(__nge_jinusehead, nge_jpool_entry)	nge_jinuse_listhead;
  	u_int8_t		nge_tbi;
  	struct ifmedia		nge_ifmedia;
+ #ifdef DEVICE_POLLING
+ 	int			rxcycles;
+ #endif
  };
  
  /*

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->luigi 
Responsible-Changed-By: nork 
Responsible-Changed-When: Wed Oct 30 21:14:12 PST 2002 
Responsible-Changed-Why:  
Over to maintainer(maybe).  Authority of DEVICE_POLLING is luigi. 
But I don't know authority of nge(4).  If anyone knew, please commit 
to src/MAINTAINERS. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=44772 
State-Changed-From-To: open->feedback 
State-Changed-By: simokawa 
State-Changed-When: Wed Nov 6 07:55:15 PST 2002 
State-Changed-Why:  
Thanks, committed to HEAD branch. 
I will do MFC next week. 


Responsible-Changed-From-To: luigi->simokawa 
Responsible-Changed-By: simokawa 
Responsible-Changed-When: Wed Nov 6 07:55:15 PST 2002 
Responsible-Changed-Why:  
Thanks, committed to HEAD branch. 
I will do MFC next week. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=44772 
State-Changed-From-To: feedback->closed 
State-Changed-By: nork 
State-Changed-When: Sat Nov 23 10:32:59 PST 2002 
State-Changed-Why:  
It seems already committed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=44772 
>Unformatted:
