Index: kern/kern_poll.c =================================================================== RCS file: kern/kern_poll.c diff -N kern/kern_poll.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ kern/kern_poll.c 9 Feb 2002 23:02:37 -0000 1.2.2.1 @@ -0,0 +1,487 @@ +/*- + * Copyright (c) 2002 Luigi Rizzo + * + * Supported by: the Xorp Project (www.xorp.org) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/sys/kern/kern_poll.c,v 1.2.2.1 2002/02/09 23:02:37 luigi Exp $ + */ + +#include +#include +#include +#include /* needed by net/if.h */ +#include + +#include /* for vm_page_zero_idle() */ +#include /* for IFF_* flags */ +#include /* for NETISR_POLL */ + +#ifdef SMP +#error DEVICE_POLLING is not compatible with SMP +#endif + +static void netisr_poll(void); /* the two netisr handlers */ +static void netisr_pollmore(void); + +void init_device_poll(void); /* init routine */ +void hardclock_device_poll(void); /* hook from hardclock */ +void ether_poll(int); /* polling while in trap */ +int idle_poll(void); /* poll while in idle loop */ + +/* + * Polling support for [network] device drivers. + * + * Drivers which support this feature try to register with the + * polling code. + * + * If registration is successful, the driver must disable interrupts, + * and further I/O is performed through the handler, which is invoked + * (at least once per clock tick) with 3 arguments: the "arg" passed at + * register time (a struct ifnet pointer), a command, and a "count" limit. + * + * The command can be one of the following: + * POLL_ONLY: quick move of "count" packets from input/output queues. + * POLL_AND_CHECK_STATUS: as above, plus check status registers or do + * other more expensive operations. This command is issued periodically + * but less frequently than POLL_ONLY. + * POLL_DEREGISTER: deregister and return to interrupt mode. + * + * The first two commands are only issued if the interface is marked as + * 'IFF_UP and IFF_RUNNING', the last one only if IFF_RUNNING is set. + * + * The count limit specifies how much work the handler can do during the + * call -- typically this is the number of packets to be received, or + * transmitted, etc. (drivers are free to interpret this number, as long + * as the max time spent in the function grows roughly linearly with the + * count). + * + * Deregistration can be requested by the driver itself (typically in the + * *_stop() routine), or by the polling code, by invoking the handler. + * + * Polling can be globally enabled or disabled with the sysctl variable + * kern.polling.enable (default is 0, disabled) + * + * A second variable controls the sharing of CPU between polling/kernel + * network processing, and other activities (typically userlevel tasks): + * kern.polling.user_frac (between 0 and 100, default 50) sets the share + * of CPU allocated to user tasks. CPU is allocated proportionally to the + * shares, by dynamically adjusting the "count" (poll_burst). + * + * Other parameters can should be left to their default values. + * The following constraints hold + * + * 1 <= poll_each_burst <= poll_burst <= poll_burst_max + * 0 <= poll_in_trap <= poll_each_burst + * MIN_POLL_BURST_MAX <= poll_burst_max <= MAX_POLL_BURST_MAX + */ + +#define MIN_POLL_BURST_MAX 10 +#define MAX_POLL_BURST_MAX 1000 + +SYSCTL_NODE(_kern, OID_AUTO, polling, CTLFLAG_RW, 0, + "Device polling parameters"); + +static u_int32_t poll_burst = 5; +SYSCTL_ULONG(_kern_polling, OID_AUTO, burst, CTLFLAG_RW, + &poll_burst, 0, "Current polling burst size"); + +static u_int32_t poll_each_burst = 5; +SYSCTL_ULONG(_kern_polling, OID_AUTO, each_burst, CTLFLAG_RW, + &poll_each_burst, 0, "Max size of each burst"); + +static u_int32_t poll_burst_max = 150; /* good for 100Mbit net and HZ=1000 */ +SYSCTL_ULONG(_kern_polling, OID_AUTO, burst_max, CTLFLAG_RW, + &poll_burst_max, 0, "Max Polling burst size"); + +static u_int32_t poll_in_idle_loop=1; /* do we poll in idle loop ? */ +SYSCTL_ULONG(_kern_polling, OID_AUTO, idle_poll, CTLFLAG_RW, + &poll_in_idle_loop, 0, "Enable device polling in idle loop"); + +u_int32_t poll_in_trap; /* used in trap.c */ +SYSCTL_ULONG(_kern_polling, OID_AUTO, poll_in_trap, CTLFLAG_RW, + &poll_in_trap, 0, "Poll burst size during a trap"); + +static u_int32_t user_frac = 50; +SYSCTL_ULONG(_kern_polling, OID_AUTO, user_frac, CTLFLAG_RW, + &user_frac, 0, "Desired user fraction of cpu time"); + +static u_int32_t reg_frac = 20 ; +SYSCTL_ULONG(_kern_polling, OID_AUTO, reg_frac, CTLFLAG_RW, + ®_frac, 0, "Every this many cycles poll register"); + +static u_int32_t short_ticks; +SYSCTL_ULONG(_kern_polling, OID_AUTO, short_ticks, CTLFLAG_RW, + &short_ticks, 0, "Hardclock ticks shorter than they should be"); + +static u_int32_t lost_polls; +SYSCTL_ULONG(_kern_polling, OID_AUTO, lost_polls, CTLFLAG_RW, + &lost_polls, 0, "How many times we would have lost a poll tick"); + +static u_int32_t pending_polls; +SYSCTL_ULONG(_kern_polling, OID_AUTO, pending_polls, CTLFLAG_RW, + &pending_polls, 0, "Do we need to poll again"); + +static int residual_burst = 0; +SYSCTL_INT(_kern_polling, OID_AUTO, residual_burst, CTLFLAG_RW, + &residual_burst, 0, "# of residual cycles in burst"); + +static u_int32_t poll_handlers; /* next free entry in pr[]. */ +SYSCTL_ULONG(_kern_polling, OID_AUTO, handlers, CTLFLAG_RD, + &poll_handlers, 0, "Number of registered poll handlers"); + +static int polling = 0; /* global polling enable */ +SYSCTL_ULONG(_kern_polling, OID_AUTO, enable, CTLFLAG_RW, + &polling, 0, "Polling enabled"); + +static volatile u_int32_t phase; +SYSCTL_ULONG(_kern_polling, OID_AUTO, phase, CTLFLAG_RW, + &phase, 0, "Polling phase"); + +static u_int32_t suspect; +SYSCTL_ULONG(_kern_polling, OID_AUTO, suspect, CTLFLAG_RW, + &suspect, 0, "suspect event"); + +static volatile u_int32_t stalled; +SYSCTL_ULONG(_kern_polling, OID_AUTO, stalled, CTLFLAG_RW, + &stalled, 0, "potential stalls"); + + +#define POLL_LIST_LEN 128 +struct pollrec { + poll_handler_t *handler; + struct ifnet *ifp; +}; + +static struct pollrec pr[POLL_LIST_LEN]; + +/* + * register relevant netisr. Called from kern_clock.c: + */ +void +init_device_poll(void) +{ + register_netisr(NETISR_POLL, netisr_poll); + register_netisr(NETISR_POLLMORE, netisr_pollmore); +} + +/* + * Hook from hardclock. Tries to schedule a netisr, but keeps track + * of lost ticks due to the previous handler taking too long. + * The first part of the code is just for debugging purposes, and tries + * to count how often hardclock ticks are shorter than they should, + * meaning either stray interrupts or delayed events. + */ +void +hardclock_device_poll(void) +{ + static struct timeval prev_t, t; + int delta; + + if (poll_handlers == 0) + return; + + microuptime(&t); + delta = (t.tv_usec - prev_t.tv_usec) + + (t.tv_sec - prev_t.tv_sec)*1000000; + if (delta * hz < 500000) + short_ticks++; + else + prev_t = t; + + if (pending_polls > 100) { + /* too much, assume it has stalled */ + stalled++; + printf("poll stalled [%d] in phase %d\n", + stalled, phase); + pending_polls = 0; + phase = 0; + } + + if (phase <= 2) { + if (phase != 0) + suspect++; + phase = 1; + schednetisr(NETISR_POLL); + phase = 2; + } + if (pending_polls++ > 0) + lost_polls++; +} + +/* + * ether_poll is called from the idle loop or from the trap handler. + */ +void +ether_poll(int count) +{ + int i; + int s = splimp(); + + if (count > poll_each_burst) + count = poll_each_burst; + for (i = 0 ; i < poll_handlers ; i++) + if (pr[i].handler && (IFF_UP|IFF_RUNNING) == + (pr[i].ifp->if_flags & (IFF_UP|IFF_RUNNING)) ) + pr[i].handler(pr[i].ifp, 0, count); /* quick check */ + splx(s); +} + +/* + * idle_poll is replaces the body of the idle loop when DEVICE_POLLING + * is used. + */ +int +idle_poll(void) +{ + if (poll_in_idle_loop && poll_handlers > 0) { + int s = splimp(); + enable_intr(); + ether_poll(poll_each_burst); + disable_intr(); + splx(s); + vm_page_zero_idle(); + return 1; + } else + return vm_page_zero_idle(); +} + +/* + * netisr_pollmore is called after other netisr's, possibly scheduling + * another NETISR_POLL call, or adapting the burst size for the next cycle. + * + * It is very bad to fetch large bursts of packets from a single card at once, + * because the burst could take a long time to be completely processed, or + * could saturate the intermediate queue (ipintrq or similar) leading to + * losses or unfairness. To reduce the problem, and also to account better for + * time spent in network-related processnig, we split the burst in smaller + * chunks of fixed size, giving control to the other netisr's between chunks. + * This helps in improving the fairness, reducing livelock (because we + * emulate more closely the "process to completion" that we have with + * fastforwarding) and accounting for the work performed in low level + * handling and forwarding. + */ + + +static struct timeval poll_start_t; + +static void +netisr_pollmore() +{ + struct timeval t; + int kern_load; + int s = splhigh(); + + phase = 5; + if (residual_burst > 0) { + schednetisr(NETISR_POLL); + /* will run immediately on return, followed by netisrs */ + splx(s); + return ; + } + /* here we can account time spent in netisr's in this tick */ + microuptime(&t); + kern_load = (t.tv_usec - poll_start_t.tv_usec) + + (t.tv_sec - poll_start_t.tv_sec)*1000000; /* us */ + kern_load = (kern_load * hz) / 10000; /* 0..100 */ + if (kern_load > (100 - user_frac)) { /* try decrease ticks */ + if (poll_burst > 1) + poll_burst--; + } else { + if (poll_burst < poll_burst_max) + poll_burst++; + } + + pending_polls--; + if (pending_polls == 0) /* we are done */ + phase = 0; + else { + /* + * Last cycle was long and caused us to miss one or more + * hardclock ticks. Restart processing again, but slightly + * reduce the burst size to prevent that this happens again. + */ + poll_burst -= (poll_burst / 8); + if (poll_burst < 1) + poll_burst = 1; + schednetisr(NETISR_POLL); + phase = 6; + } + splx(s); +} + +/* + * netisr_poll scheduled by schednetisr when appropriate, typically once + * per tick. It is called at splnet() so first thing to do is to upgrade to + * splimp(), and call all registered handlers. + */ +static void +netisr_poll(void) +{ + static int reg_frac_count; + int i, cycles; + enum poll_cmd arg = POLL_ONLY; + int s=splimp(); + + phase = 3; + if (residual_burst == 0) { /* first call in this tick */ + microuptime(&poll_start_t); + /* + * Check that paremeters are consistent with runtime + * variables. Some of these tests could be done at sysctl + * time, but the savings would be very limited because we + * still have to check against reg_frac_count and + * poll_each_burst. So, instead of writing separate sysctl + * handlers, we do all here. + */ + + if (reg_frac > hz) + reg_frac = hz; + else if (reg_frac < 1) + reg_frac = 1; + if (reg_frac_count > reg_frac) + reg_frac_count = reg_frac - 1; + if (reg_frac_count-- == 0) { + arg = POLL_AND_CHECK_STATUS; + reg_frac_count = reg_frac - 1; + } + if (poll_burst_max < MIN_POLL_BURST_MAX) + poll_burst_max = MIN_POLL_BURST_MAX; + else if (poll_burst_max > MAX_POLL_BURST_MAX) + poll_burst_max = MAX_POLL_BURST_MAX; + + if (poll_each_burst < 1) + poll_each_burst = 1; + else if (poll_each_burst > poll_burst_max) + poll_each_burst = poll_burst_max; + + residual_burst = poll_burst; + } + cycles = (residual_burst < poll_each_burst) ? + residual_burst : poll_each_burst; + residual_burst -= cycles; + + if (polling) { + for (i = 0 ; i < poll_handlers ; i++) + if (pr[i].handler && (IFF_UP|IFF_RUNNING) == + (pr[i].ifp->if_flags & (IFF_UP|IFF_RUNNING)) ) + pr[i].handler(pr[i].ifp, arg, cycles); + } else { /* unregister */ + for (i = 0 ; i < poll_handlers ; i++) { + if (pr[i].handler && + pr[i].ifp->if_flags & IFF_RUNNING) { + pr[i].ifp->if_ipending &= ~IFF_POLLING; + pr[i].handler(pr[i].ifp, POLL_DEREGISTER, 1); + } + pr[i].handler=NULL; + } + residual_burst = 0; + poll_handlers = 0; + } + schednetisr(NETISR_POLLMORE); + phase = 4; + splx(s); +} + +/* + * Try to register routine for polling. Returns 1 if successful + * (and polling should be enabled), 0 otherwise. + * A device is not supposed to register itself multiple times. + * + * This is called from within the *_intr() functions, so we do not need + * further locking. + */ +int +ether_poll_register(poll_handler_t *h, struct ifnet *ifp) +{ + int s; + + if (polling == 0) /* polling disabled, cannot register */ + return 0; + if (h == NULL || ifp == NULL) /* bad arguments */ + return 0; + if ( !(ifp->if_flags & IFF_UP) ) /* must be up */ + return 0; + if (ifp->if_ipending & IFF_POLLING) /* already polling */ + return 0; + + s = splhigh(); + if (poll_handlers >= POLL_LIST_LEN) { + /* + * List full, cannot register more entries. + * This should never happen; if it does, it is probably a + * broken driver trying to register multiple times. Checking + * this at runtime is expensive, and won't solve the problem + * anyways, so just report a few times and then give up. + */ + static int verbose = 10 ; + splx(s); + if (verbose >0) { + printf("poll handlers list full, " + "maybe a broken driver ?\n"); + verbose--; + } + return 0; /* no polling for you */ + } + + pr[poll_handlers].handler = h; + pr[poll_handlers].ifp = ifp; + poll_handlers++; + ifp->if_ipending |= IFF_POLLING; + splx(s); + return 1; /* polling enabled in next call */ +} + +/* + * Remove interface from the polling list. Normally called by *_stop(). + * It is not an error to call it with IFF_POLLING clear, the call is + * sufficiently rare to be preferable to save the space for the extra + * test in each driver in exchange of one additional function call. + */ +int +ether_poll_deregister(struct ifnet *ifp) +{ + int i; + int s = splimp(); + + if ( !ifp || !(ifp->if_ipending & IFF_POLLING) ) { + splx(s); + return 0; + } + for (i = 0 ; i < poll_handlers ; i++) + if (pr[i].ifp == ifp) /* found it */ + break; + ifp->if_ipending &= ~IFF_POLLING; /* found or not... */ + if (i == poll_handlers) { + splx(s); + printf("ether_poll_deregister: ifp not found!!!\n"); + return 0; + } + poll_handlers--; + if (i < poll_handlers) { /* Last entry replaces this one. */ + pr[i].handler = pr[poll_handlers].handler; + pr[i].ifp = pr[poll_handlers].ifp; + } + splx(s); + return 1; +} Index: kern/kern_clock.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_clock.c,v retrieving revision 1.105.2.6 retrieving revision 1.105.2.8 diff -u -r1.105.2.6 -r1.105.2.8 --- kern/kern_clock.c 8 Dec 2001 00:04:14 -0000 1.105.2.6 +++ kern/kern_clock.c 9 Feb 2002 23:02:37 -0000 1.105.2.8 @@ -37,7 +37,7 @@ * SUCH DAMAGE. * * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94 - * $FreeBSD: src/sys/kern/kern_clock.c,v 1.105.2.6 2001/12/08 00:04:14 luigi Exp $ + * $FreeBSD: src/sys/kern/kern_clock.c,v 1.105.2.8 2002/02/09 23:02:37 luigi Exp $ */ #include "opt_ntp.h" @@ -67,6 +67,11 @@ #include #endif +#ifdef DEVICE_POLLING +extern void init_device_poll(void); +extern void hardclock_device_poll(void); +#endif /* DEVICE_POLLING */ + /* * Number of timecounters used to implement stable storage */ @@ -187,6 +192,10 @@ psdiv = pscnt = 1; cpu_initclocks(); +#ifdef DEVICE_POLLING + init_device_poll(); +#endif + /* * Compute profhz/stathz, and fix profhz if needed. */ @@ -235,6 +244,10 @@ tco_forward(0); ticks++; +#ifdef DEVICE_POLLING + hardclock_device_poll(); /* this is very short and quick */ +#endif /* DEVICE_POLLING */ + /* * Process callouts at a very low cpu priority, so we don't keep the * relatively high clock interrupt priority any longer than necessary. @@ -602,7 +615,7 @@ tv->tv_sec = tc->tc_offset_sec; tv->tv_usec = tc->tc_offset_micro; tv->tv_usec += ((u_int64_t)tco_delta(tc) * tc->tc_scale_micro) >> 32; - if (tv->tv_usec >= 1000000) { + while (tv->tv_usec >= 1000000) { tv->tv_usec -= 1000000; tv->tv_sec++; } @@ -622,7 +635,7 @@ delta += ((u_int64_t)count * tc->tc_scale_nano_f); delta >>= 32; delta += ((u_int64_t)count * tc->tc_scale_nano_i); - if (delta >= 1000000000) { + while (delta >= 1000000000) { delta -= 1000000000; ts->tv_sec++; } @@ -801,7 +814,7 @@ tc->tc_nanotime.tv_nsec = (tc->tc_offset_nano >> 32) + boottime.tv_usec * 1000; tc->tc_microtime.tv_usec = tc->tc_offset_micro + boottime.tv_usec; - if (tc->tc_nanotime.tv_nsec >= 1000000000) { + while (tc->tc_nanotime.tv_nsec >= 1000000000) { tc->tc_nanotime.tv_nsec -= 1000000000; tc->tc_microtime.tv_usec -= 1000000; tc->tc_nanotime.tv_sec++; Index: conf/files.i386 =================================================================== RCS file: /home/ncvs/src/sys/conf/files.i386,v retrieving revision 1.307.2.19 retrieving revision 1.307.2.20 diff -u -r1.307.2.19 -r1.307.2.20 --- conf/files.i386 19 Dec 2001 20:59:28 -0000 1.307.2.19 +++ conf/files.i386 9 Feb 2002 23:02:38 -0000 1.307.2.20 @@ -1,7 +1,7 @@ # This file tells config what files go into building a kernel, # files marked standard are always included. # -# $FreeBSD: src/sys/conf/files.i386,v 1.307.2.19 2001/12/19 20:59:28 fjoe Exp $ +# $FreeBSD: src/sys/conf/files.i386,v 1.307.2.20 2002/02/09 23:02:38 luigi Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -459,6 +459,7 @@ isa/sio.c optional sio isa/syscons_isa.c optional sc isa/vga_isa.c optional vga +kern/kern_poll.c optional device_polling kern/md4c.c optional netsmb kern/subr_diskmbr.c standard libkern/divdi3.c standard Index: conf/options.i386 =================================================================== RCS file: /home/ncvs/src/sys/conf/options.i386,v retrieving revision 1.132.2.11 retrieving revision 1.132.2.12 diff -u -r1.132.2.11 -r1.132.2.12 --- conf/options.i386 10 Dec 2001 12:17:04 -0000 1.132.2.11 +++ conf/options.i386 9 Feb 2002 23:02:38 -0000 1.132.2.12 @@ -1,4 +1,4 @@ -# $FreeBSD: src/sys/conf/options.i386,v 1.132.2.11 2001/12/10 12:17:04 hm Exp $ +# $FreeBSD: src/sys/conf/options.i386,v 1.132.2.12 2002/02/09 23:02:38 luigi Exp $ DISABLE_PSE IDE_DELAY @@ -207,6 +207,11 @@ # SMB/CIFS filesystem SMBFS + +# ------------------------------- +# Polling device handling +# ------------------------------- +DEVICE_POLLING opt_global.h # ------------------------------- # EOF Index: i386/i386/swtch.s =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/swtch.s,v retrieving revision 1.89.2.6 retrieving revision 1.89.2.7 diff -u -r1.89.2.6 -r1.89.2.7 --- i386/i386/swtch.s 8 Dec 2001 00:04:14 -0000 1.89.2.6 +++ i386/i386/swtch.s 9 Feb 2002 23:02:38 -0000 1.89.2.7 @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/i386/i386/swtch.s,v 1.89.2.6 2001/12/08 00:04:14 luigi Exp $ + * $FreeBSD: src/sys/i386/i386/swtch.s,v 1.89.2.7 2002/02/09 23:02:38 luigi Exp $ */ #include "npx.h" @@ -246,7 +246,11 @@ call _procrunnable testl %eax,%eax CROSSJUMP(jnz, sw1a, jz) +#ifdef DEVICE_POLLING + call _idle_poll +#else /* standard code */ call _vm_page_zero_idle +#endif testl %eax, %eax jnz idle_loop call *_hlt_vector /* wait for interrupt */ Index: i386/i386/trap.c =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/trap.c,v retrieving revision 1.147.2.8 retrieving revision 1.147.2.9 diff -u -r1.147.2.8 -r1.147.2.9 --- i386/i386/trap.c 12 Jan 2002 11:03:30 -0000 1.147.2.8 +++ i386/i386/trap.c 9 Feb 2002 23:02:38 -0000 1.147.2.9 @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 - * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.8 2002/01/12 11:03:30 bde Exp $ + * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.9 2002/02/09 23:02:38 luigi Exp $ */ /* @@ -211,6 +211,11 @@ return(have_mplock); } +#ifdef DEVICE_POLLING +extern u_int32_t poll_in_trap; +extern int ether_poll __P((int count)); +#endif /* DEVICE_POLLING */ + /* * Exception, fault, and trap interface to the FreeBSD kernel. * This common code is called from assembly language IDT gate entry @@ -265,6 +270,11 @@ eva = rcr2(); enable_intr(); } + +#ifdef DEVICE_POLLING + if (poll_in_trap) + ether_poll(poll_in_trap); +#endif /* DEVICE_POLLING */ #if defined(I586_CPU) && !defined(NO_F00F_HACK) restart: Index: i386/include/asnames.h =================================================================== RCS file: /home/ncvs/src/sys/i386/include/Attic/asnames.h,v retrieving revision 1.44.2.5 retrieving revision 1.44.2.6 diff -u -r1.44.2.5 -r1.44.2.6 --- i386/include/asnames.h 8 Dec 2001 00:04:14 -0000 1.44.2.5 +++ i386/include/asnames.h 9 Feb 2002 23:02:38 -0000 1.44.2.6 @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/i386/include/asnames.h,v 1.44.2.5 2001/12/08 00:04:14 luigi Exp $ + * $FreeBSD: src/sys/i386/include/asnames.h,v 1.44.2.6 2002/02/09 23:02:38 luigi Exp $ */ #ifndef _MACHINE_ASNAMES_H_ @@ -225,6 +225,7 @@ #define _get_mplock get_mplock #define _get_syscall_lock get_syscall_lock #define _idle idle +#define _idle_poll idle_poll #define _ihandlers ihandlers #define _imen imen #define _imen_lock imen_lock Index: net/if.h =================================================================== RCS file: /home/ncvs/src/sys/net/if.h,v retrieving revision 1.58.2.5 retrieving revision 1.58.2.7 diff -u -r1.58.2.5 -r1.58.2.7 --- net/if.h 14 Dec 2001 19:35:49 -0000 1.58.2.5 +++ net/if.h 9 Feb 2002 23:02:39 -0000 1.58.2.7 @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)if.h 8.1 (Berkeley) 6/10/93 - * $FreeBSD: src/sys/net/if.h,v 1.58.2.5 2001/12/14 19:35:49 jlemon Exp $ + * $FreeBSD: src/sys/net/if.h,v 1.58.2.7 2002/02/09 23:02:39 luigi Exp $ */ #ifndef _NET_IF_H_ @@ -131,6 +131,15 @@ #define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */ #define IFF_MULTICAST 0x8000 /* supports multicast */ +/* + * The following flag(s) ought to go in if_flags, but we cannot change + * struct ifnet because of binary compatibility, so we store them in + * if_ipending, which is not used so far. + * If possible, make sure the value is not conflicting with other + * IFF flags, so we have an easier time when we want to merge them. + */ +#define IFF_POLLING 0x10000 /* Interface is in polling mode. */ + /* flags set internally only: */ #define IFF_CANTCHANGE \ (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\ @@ -186,6 +195,21 @@ int ifmam_flags; /* value of ifa_flags */ u_short ifmam_index; /* index for associated ifp */ }; + +/* + * Message format announcing the arrival or departure of a network interface. + */ +struct if_announcemsghdr { + u_short ifan_msglen; /* to skip over non-understood messages */ + u_char ifan_version; /* future binary compatibility */ + u_char ifan_type; /* message type */ + u_short ifan_index; /* index for associated ifp */ + char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + u_short ifan_what; /* what type of announcement */ +}; + +#define IFAN_ARRIVAL 0 /* interface arrival */ +#define IFAN_DEPARTURE 1 /* interface departure */ /* * Interface request structure used for socket Index: net/if_var.h =================================================================== RCS file: /home/ncvs/src/sys/net/if_var.h,v retrieving revision 1.18.2.11 retrieving revision 1.18.2.12 diff -u -r1.18.2.11 -r1.18.2.12 --- net/if_var.h 20 Dec 2001 10:30:17 -0000 1.18.2.11 +++ net/if_var.h 9 Feb 2002 23:02:39 -0000 1.18.2.12 @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * From: @(#)if.h 8.1 (Berkeley) 6/10/93 - * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.11 2001/12/20 10:30:17 ru Exp $ + * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.12 2002/02/09 23:02:39 luigi Exp $ */ #ifndef _NET_IF_VAR_H_ @@ -415,7 +415,14 @@ int if_clone_create __P((char *, int)); int if_clone_destroy __P((const char *)); -#endif /* _KERNEL */ +#ifdef DEVICE_POLLING +enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS, POLL_DEREGISTER }; +typedef void poll_handler_t __P((struct ifnet *ifp, + enum poll_cmd cmd, int count)); +int ether_poll_register __P((poll_handler_t *h, struct ifnet *ifp)); +int ether_poll_deregister __P((struct ifnet *ifp)); +#endif /* DEVICE_POLLING */ +#endif /* _KERNEL */ #endif /* !_NET_IF_VAR_H_ */ Index: net/netisr.h =================================================================== RCS file: /home/ncvs/src/sys/net/netisr.h,v retrieving revision 1.21.2.4 retrieving revision 1.21.2.5 diff -u -r1.21.2.4 -r1.21.2.5 --- net/netisr.h 8 Dec 2001 00:04:15 -0000 1.21.2.4 +++ net/netisr.h 9 Feb 2002 23:02:39 -0000 1.21.2.5 @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)netisr.h 8.1 (Berkeley) 6/10/93 - * $FreeBSD: src/sys/net/netisr.h,v 1.21.2.4 2001/12/08 00:04:15 luigi Exp $ + * $FreeBSD: src/sys/net/netisr.h,v 1.21.2.5 2002/02/09 23:02:39 luigi Exp $ */ #ifndef _NET_NETISR_H_ @@ -52,6 +52,7 @@ * interrupt used for scheduling the network code to calls * on the lowest level routine of each protocol. */ +#define NETISR_POLL 0 /* polling callback */ #define NETISR_IP 2 /* same as AF_INET */ #define NETISR_NS 6 /* same as AF_NS */ #define NETISR_ATALK 16 /* same as AF_APPLETALK */ @@ -61,7 +62,8 @@ #define NETISR_PPP 27 /* PPP soft interrupt */ #define NETISR_IPV6 28 /* same as AF_INET6 */ #define NETISR_NATM 29 /* same as AF_NATM */ -#define NETISR_NETGRAPH 31 /* same as AF_NETGRAPH */ +#define NETISR_NETGRAPH 30 /* same as AF_NETGRAPH */ +#define NETISR_POLLMORE 31 /* check if we need more polling */ #ifndef LOCORE Index: dev/fxp/if_fxp.c =================================================================== RCS file: /home/ncvs/src/sys/dev/fxp/if_fxp.c,v retrieving revision 1.110.2.16 retrieving revision 1.110.2.17 diff -u -r1.110.2.16 -r1.110.2.17 --- dev/fxp/if_fxp.c 24 Jan 2002 16:07:03 -0000 1.110.2.16 +++ dev/fxp/if_fxp.c 9 Feb 2002 23:02:39 -0000 1.110.2.17 @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/fxp/if_fxp.c,v 1.110.2.16 2002/01/24 16:07:03 jlemon Exp $ + * $FreeBSD: src/sys/dev/fxp/if_fxp.c,v 1.110.2.17 2002/02/09 23:02:39 luigi Exp $ */ /* @@ -170,6 +170,9 @@ static int fxp_resume(device_t dev); static void fxp_intr(void *xsc); +static void fxp_intr_body(struct fxp_softc *sc, + u_int8_t statack, int count); + static void fxp_init(void *xsc); static void fxp_tick(void *xsc); static void fxp_powerstate_d0(device_t dev); @@ -1142,6 +1145,37 @@ } } +#ifdef DEVICE_POLLING +static poll_handler_t fxp_poll; + +static void +fxp_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) +{ + struct fxp_softc *sc = ifp->if_softc; + u_int8_t statack; + + if (cmd == POLL_DEREGISTER) { /* final call, enable interrupts */ + CSR_WRITE_1(sc, FXP_CSR_SCB_INTRCNTL, 0); + return; + } + statack = FXP_SCB_STATACK_CXTNO | FXP_SCB_STATACK_CNA | + FXP_SCB_STATACK_FR; + if (cmd == POLL_AND_CHECK_STATUS) { + u_int8_t tmp; + + tmp = CSR_READ_1(sc, FXP_CSR_SCB_STATACK); + if (tmp == 0xff || tmp == 0) + return; /* nothing to do */ + tmp &= ~statack; + /* ack what we can */ + if (tmp != 0) + CSR_WRITE_1(sc, FXP_CSR_SCB_STATACK, tmp); + statack |= tmp; + } + fxp_intr_body(sc, statack, count); +} +#endif /* DEVICE_POLLING */ + /* * Process interface interrupts. */ @@ -1149,9 +1183,21 @@ fxp_intr(void *xsc) { struct fxp_softc *sc = xsc; - struct ifnet *ifp = &sc->sc_if; u_int8_t statack; +#ifdef DEVICE_POLLING + struct ifnet *ifp = &sc->sc_if; + + if (ifp->if_ipending & IFF_POLLING) + return; + if (ether_poll_register(fxp_poll, ifp)) { + /* disable interrupts */ + CSR_WRITE_1(sc, FXP_CSR_SCB_INTRCNTL, FXP_SCB_INTR_DISABLE); + fxp_poll(ifp, 0, 1); + return; + } +#endif + if (sc->suspended) { return; } @@ -1170,6 +1216,14 @@ * First ACK all the interrupts in this pass. */ CSR_WRITE_1(sc, FXP_CSR_SCB_STATACK, statack); + fxp_intr_body(sc, statack, -1); + } +} + +static void +fxp_intr_body(struct fxp_softc *sc, u_int8_t statack, int count) +{ + struct ifnet *ifp = &sc->sc_if; /* * Free any finished transmit mbuf chains. @@ -1221,6 +1275,9 @@ rfa = (struct fxp_rfa *)(m->m_ext.ext_buf + RFA_ALIGNMENT_FUDGE); +#ifdef DEVICE_POLLING /* loop at most count times if count >=0 */ + if (count < 0 || count-- > 0) +#endif /* DEVICE_POLLING */ if (rfa->rfa_status & FXP_RFA_STATUS_C) { /* * Remove first packet from the chain. @@ -1277,7 +1334,6 @@ fxp_scb_cmd(sc, FXP_SCB_COMMAND_RU_START); } } - } } /* @@ -1405,6 +1461,9 @@ ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); ifp->if_timer = 0; +#ifdef DEVICE_POLLING + ether_poll_deregister(ifp); +#endif /* * Cancel stats updater. */ @@ -1702,6 +1761,15 @@ /* * Enable interrupts. */ +#ifdef DEVICE_POLLING + /* + * ... but only do that if we are not polling. And because (presumably) + * the default is interrupts on, we need to disable them explicitly! + */ + if ( ifp->if_ipending & IFF_POLLING ) + CSR_WRITE_1(sc, FXP_CSR_SCB_INTRCNTL, FXP_SCB_INTR_DISABLE); + else +#endif /* DEVICE_POLLING */ CSR_WRITE_1(sc, FXP_CSR_SCB_INTRCNTL, 0); splx(s); Index: dev/fxp/if_fxpvar.h =================================================================== RCS file: /home/ncvs/src/sys/dev/fxp/if_fxpvar.h,v retrieving revision 1.17.2.4 retrieving revision 1.17.2.5 diff -u -r1.17.2.4 -r1.17.2.5 --- dev/fxp/if_fxpvar.h 2 Nov 2001 16:50:42 -0000 1.17.2.4 +++ dev/fxp/if_fxpvar.h 9 Feb 2002 23:02:39 -0000 1.17.2.5 @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/fxp/if_fxpvar.h,v 1.17.2.4 2001/11/02 16:50:42 jlemon Exp $ + * $FreeBSD: src/sys/dev/fxp/if_fxpvar.h,v 1.17.2.5 2002/02/09 23:02:39 luigi Exp $ */ /* @@ -57,7 +57,11 @@ * Number of receive frame area buffers. These are large so chose * wisely. */ +#ifdef DEVICE_POLLING +#define FXP_NRFABUFS 192 +#else #define FXP_NRFABUFS 64 +#endif /* * Maximum number of seconds that the receiver can be idle before we Index: pci/if_dc.c =================================================================== RCS file: /home/ncvs/src/sys/pci/if_dc.c,v retrieving revision 1.9.2.31 retrieving revision 1.9.2.32 diff -u -r1.9.2.31 -r1.9.2.32 --- pci/if_dc.c 19 Dec 2001 18:37:34 -0000 1.9.2.31 +++ pci/if_dc.c 9 Feb 2002 23:02:40 -0000 1.9.2.32 @@ -29,7 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/pci/if_dc.c,v 1.9.2.31 2001/12/19 18:37:34 wpaul Exp $ + * $FreeBSD: src/sys/pci/if_dc.c,v 1.9.2.32 2002/02/09 23:02:40 luigi Exp $ */ /* @@ -132,7 +132,7 @@ #ifndef lint static const char rcsid[] = - "$FreeBSD: src/sys/pci/if_dc.c,v 1.9.2.31 2001/12/19 18:37:34 wpaul Exp $"; + "$FreeBSD: src/sys/pci/if_dc.c,v 1.9.2.32 2002/02/09 23:02:40 luigi Exp $"; #endif /* @@ -2343,6 +2343,13 @@ while(!(sc->dc_ldata->dc_rx_list[i].dc_status & DC_RXSTAT_OWN)) { +#ifdef DEVICE_POLLING + if (ifp->if_ipending & IFF_POLLING) { + if (sc->rxcycles <= 0) + break; + sc->rxcycles--; + } +#endif /* DEVICE_POLLING */ cur_rx = &sc->dc_ldata->dc_rx_list[i]; rxstat = cur_rx->dc_status; m = sc->dc_cdata.dc_rx_chain[i]; @@ -2660,6 +2667,60 @@ return; } +#ifdef DEVICE_POLLING +static poll_handler_t dc_poll; + +static void +dc_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) +{ + struct dc_softc *sc = ifp->if_softc; + + if (cmd == POLL_DEREGISTER) { /* final call, enable interrupts */ + /* Re-enable interrupts. */ + CSR_WRITE_4(sc, DC_IMR, DC_INTRS); + return; + } + sc->rxcycles = count; + dc_rxeof(sc); + dc_txeof(sc); + if (ifp->if_snd.ifq_head != NULL && !(ifp->if_flags & IFF_OACTIVE)) + dc_start(ifp); + + if (cmd == POLL_AND_CHECK_STATUS) { /* also check status register */ + u_int32_t status; + + status = CSR_READ_4(sc, DC_ISR); + status &= (DC_ISR_RX_WATDOGTIMEO|DC_ISR_RX_NOBUF| + DC_ISR_TX_NOBUF|DC_ISR_TX_IDLE|DC_ISR_TX_UNDERRUN| + DC_ISR_BUS_ERR); + if (!status) + return ; + /* ack what we have */ + CSR_WRITE_4(sc, DC_ISR, status); + + if (status & (DC_ISR_RX_WATDOGTIMEO|DC_ISR_RX_NOBUF) ) { + u_int32_t r = CSR_READ_4(sc, DC_FRAMESDISCARDED); + ifp->if_ierrors += (r & 0xffff) + ((r >> 17) & 0x7ff); + + if (dc_rx_resync(sc)) + dc_rxeof(sc); + } + /* restart transmit unit if necessary */ + if (status & DC_ISR_TX_IDLE && sc->dc_cdata.dc_tx_cnt) + CSR_WRITE_4(sc, DC_TXSTART, 0xFFFFFFFF); + + if (status & DC_ISR_TX_UNDERRUN) + dc_tx_underrun(sc); + + if (status & DC_ISR_BUS_ERR) { + printf("dc_poll: dc%d bus error\n", sc->dc_unit); + dc_reset(sc); + dc_init(sc); + } + } +} +#endif /* DEVICE_POLLING */ + static void dc_intr(arg) void *arg; { @@ -2670,6 +2731,15 @@ sc = arg; ifp = &sc->arpcom.ac_if; +#ifdef DEVICE_POLLING + if (ifp->if_ipending & IFF_POLLING) + return; + if (ether_poll_register(dc_poll, ifp)) { /* ok, disable interrupts */ + CSR_WRITE_4(sc, DC_IMR, 0x00000000); + return; + } +#endif /* DEVICE_POLLING */ + if ( (CSR_READ_4(sc, DC_ISR) & DC_INTRS) == 0) return ; @@ -3011,6 +3081,16 @@ /* * Enable interrupts. */ +#ifdef DEVICE_POLLING + /* + * ... but only if we are not polling, and make sure they are off in + * the case of polling. Some cards (e.g. fxp) turn interrupts on + * after a reset. + */ + if (ifp->if_ipending & IFF_POLLING) + CSR_WRITE_4(sc, DC_IMR, 0x00000000); + else +#endif CSR_WRITE_4(sc, DC_IMR, DC_INTRS); CSR_WRITE_4(sc, DC_ISR, 0xFFFFFFFF); @@ -3221,6 +3301,9 @@ untimeout(dc_tick, sc, sc->dc_stat_ch); ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); +#ifdef DEVICE_POLLING + ether_poll_deregister(ifp); +#endif DC_CLRBIT(sc, DC_NETCFG, (DC_NETCFG_RX_ON|DC_NETCFG_TX_ON)); CSR_WRITE_4(sc, DC_IMR, 0x00000000); Index: pci/if_dcreg.h =================================================================== RCS file: /home/ncvs/src/sys/pci/if_dcreg.h,v retrieving revision 1.4.2.14 retrieving revision 1.4.2.15 diff -u -r1.4.2.14 -r1.4.2.15 --- pci/if_dcreg.h 19 Dec 2001 18:37:35 -0000 1.4.2.14 +++ pci/if_dcreg.h 9 Feb 2002 23:02:40 -0000 1.4.2.15 @@ -29,7 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/pci/if_dcreg.h,v 1.4.2.14 2001/12/19 18:37:35 wpaul Exp $ + * $FreeBSD: src/sys/pci/if_dcreg.h,v 1.4.2.15 2002/02/09 23:02:40 luigi Exp $ */ /* @@ -431,7 +431,11 @@ #define DC_FILTER_HASHONLY 0x10400000 #define DC_MAXFRAGS 16 +#ifdef DEVICE_POLLING +#define DC_RX_LIST_CNT 192 +#else #define DC_RX_LIST_CNT 64 +#endif #define DC_TX_LIST_CNT 256 #define DC_MIN_FRAMELEN 60 #define DC_RXLEN 1536 Index: pci/if_sis.c =================================================================== RCS file: /home/ncvs/src/sys/pci/if_sis.c,v retrieving revision 1.13.4.18 retrieving revision 1.13.4.19 diff -u -r1.13.4.18 -r1.13.4.19 --- pci/if_sis.c 15 Jan 2002 02:16:25 -0000 1.13.4.18 +++ pci/if_sis.c 9 Feb 2002 23:02:40 -0000 1.13.4.19 @@ -29,7 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/pci/if_sis.c,v 1.13.4.18 2002/01/15 02:16:25 wpaul Exp $ + * $FreeBSD: src/sys/pci/if_sis.c,v 1.13.4.19 2002/02/09 23:02:40 luigi Exp $ */ /* @@ -101,7 +101,7 @@ #ifndef lint static const char rcsid[] = - "$FreeBSD: src/sys/pci/if_sis.c,v 1.13.4.18 2002/01/15 02:16:25 wpaul Exp $"; + "$FreeBSD: src/sys/pci/if_sis.c,v 1.13.4.19 2002/02/09 23:02:40 luigi Exp $"; #endif /* @@ -1105,6 +1105,9 @@ { struct mbuf *m_new = NULL; + if (c == NULL) + return(EINVAL); + if (m == NULL) { MGETHDR(m_new, M_DONTWAIT, MT_DATA); if (m_new == NULL) @@ -1150,6 +1153,13 @@ while(SIS_OWNDESC(&sc->sis_ldata->sis_rx_list[i])) { +#ifdef DEVICE_POLLING + if (ifp->if_ipending & IFF_POLLING) { + if (sc->rxcycles <= 0) + break; + sc->rxcycles--; + } +#endif /* DEVICE_POLLING */ cur_rx = &sc->sis_ldata->sis_rx_list[i]; rxstat = cur_rx->sis_rxstat; m = cur_rx->sis_mbuf; @@ -1217,7 +1227,7 @@ struct sis_softc *sc; { sis_rxeof(sc); - sis_init(sc); + /* sis_init(sc); */ return; } @@ -1317,6 +1327,52 @@ return; } +#ifdef DEVICE_POLLING +static poll_handler_t sis_poll; + +static void +sis_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) +{ + struct sis_softc *sc = ifp->if_softc; + + if (cmd == POLL_DEREGISTER) { /* final call, enable interrupts */ + CSR_WRITE_4(sc, SIS_IER, 1); + return; + } + + /* + * On the sis, 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; + sis_rxeof(sc); + sis_txeof(sc); + if (ifp->if_snd.ifq_head != NULL) + sis_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, SIS_ISR); + + if (status & (SIS_ISR_RX_ERR|SIS_ISR_RX_OFLOW)) + sis_rxeoc(sc); + + if (status & (SIS_ISR_RX_IDLE)) + SIS_SETBIT(sc, SIS_CSR, SIS_CSR_RX_ENABLE); + + if (status & SIS_ISR_SYSERR) { + sis_reset(sc); + sis_init(sc); + } + } +} +#endif /* DEVICE_POLLING */ + static void sis_intr(arg) void *arg; { @@ -1327,6 +1383,16 @@ sc = arg; ifp = &sc->arpcom.ac_if; +#ifdef DEVICE_POLLING + if (ifp->if_ipending & IFF_POLLING) + return; + if (ether_poll_register(sis_poll, ifp)) { /* ok, disable interrupts */ + CSR_WRITE_4(sc, SIS_IER, 0); + sis_poll(ifp, 0, 1); + return; + } +#endif /* DEVICE_POLLING */ + /* Supress unwanted interrupts */ if (!(ifp->if_flags & IFF_UP)) { sis_stop(sc); @@ -1344,7 +1410,7 @@ break; if (status & - (SIS_ISR_TX_DESC_OK|SIS_ISR_TX_ERR| \ + (SIS_ISR_TX_DESC_OK|SIS_ISR_TX_ERR| SIS_ISR_TX_OK|SIS_ISR_TX_IDLE) ) sis_txeof(sc); @@ -1605,6 +1671,15 @@ * Enable interrupts. */ CSR_WRITE_4(sc, SIS_IMR, SIS_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, SIS_IER, 0); + else +#endif /* DEVICE_POLLING */ CSR_WRITE_4(sc, SIS_IER, 1); /* Enable receiver and transmitter. */ @@ -1770,7 +1845,9 @@ untimeout(sis_tick, sc, sc->sis_stat_ch); ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); - +#ifdef DEVICE_POLLING + ether_poll_deregister(ifp); +#endif CSR_WRITE_4(sc, SIS_IER, 0); CSR_WRITE_4(sc, SIS_IMR, 0); SIS_SETBIT(sc, SIS_CSR, SIS_CSR_TX_DISABLE|SIS_CSR_RX_DISABLE); Index: pci/if_sisreg.h =================================================================== RCS file: /home/ncvs/src/sys/pci/if_sisreg.h,v retrieving revision 1.1.4.7 retrieving revision 1.1.4.9 diff -u -r1.1.4.7 -r1.1.4.9 --- pci/if_sisreg.h 13 Jan 2002 00:32:22 -0000 1.1.4.7 +++ pci/if_sisreg.h 9 Feb 2002 23:02:40 -0000 1.1.4.9 @@ -29,7 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/pci/if_sisreg.h,v 1.1.4.7 2002/01/13 00:32:22 wpaul Exp $ + * $FreeBSD: src/sys/pci/if_sisreg.h,v 1.1.4.9 2002/02/09 23:02:40 luigi Exp $ */ /* @@ -309,7 +309,7 @@ #define SIS_LASTDESC(x) (!((x)->sis_ctl & SIS_CMDSTS_MORE))) #define SIS_OWNDESC(x) ((x)->sis_ctl & SIS_CMDSTS_OWN) #define SIS_INC(x, y) { if (++(x) == y) x=0 ; } -#define SIS_RXBYTES(x) ((x)->sis_ctl & SIS_CMDSTS_BUFLEN) +#define SIS_RXBYTES(x) (((x)->sis_ctl & SIS_CMDSTS_BUFLEN) - ETHER_CRC_LEN) #define SIS_RXSTAT_COLL 0x00010000 #define SIS_RXSTAT_LOOPBK 0x00020000 @@ -407,6 +407,9 @@ struct sis_list_data *sis_ldata; struct sis_ring_data sis_cdata; struct callout_handle sis_stat_ch; +#ifdef DEVICE_POLLING + int rxcycles; +#endif }; /*