From 33a0249fad46f8287b0a625a0231149afdc5b82b Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Sat, 2 Aug 1997 18:46:42 +0000 Subject: [PATCH 1/2] Import Lite2's src/libexec, except for makekey (which was spammed by a repository copy from 1.1.5 and patched back to Lite1) and rbootd/bootdir/SYSHPBSD (which is binary). All changed files have already left the vendor branch. --- libexec/getty/Makefile | 12 +- libexec/getty/extern.h | 5 +- libexec/getty/getty.8 | 3 +- libexec/getty/gettytab.5 | 130 ++++--------- libexec/getty/gettytab.h | 28 +-- libexec/getty/init.c | 50 ++--- libexec/getty/main.c | 147 +++++++------- libexec/getty/pathnames.h | 3 +- libexec/getty/subr.c | 381 +++++++++---------------------------- libexec/getty/ttys.5 | 18 +- libexec/rbootd/Makefile | 9 +- libexec/rbootd/bpf.c | 26 +-- libexec/rbootd/conf.c | 16 +- libexec/rbootd/defs.h | 21 +- libexec/rbootd/parseconf.c | 16 +- libexec/rbootd/pathnames.h | 6 +- libexec/rbootd/rbootd.8 | 8 +- libexec/rbootd/rbootd.c | 93 +++++++-- libexec/rbootd/rmp.h | 26 ++- libexec/rbootd/rmp_var.h | 98 +++++----- libexec/rbootd/rmpproto.c | 55 +++--- libexec/rbootd/utils.c | 54 +++--- 22 files changed, 463 insertions(+), 742 deletions(-) diff --git a/libexec/getty/Makefile b/libexec/getty/Makefile index a201e6252a6f..7f2eabe6f0d7 100644 --- a/libexec/getty/Makefile +++ b/libexec/getty/Makefile @@ -1,10 +1,10 @@ -# from: @(#)Makefile 8.1 (Berkeley) 6/4/93 -# $Id: Makefile,v 1.7 1994/12/22 10:27:06 cgd Exp $ +# @(#)Makefile 8.1 (Berkeley) 6/4/93 PROG= getty -SRCS= main.c init.c subr.c -DPADD+= ${LIBUTIL} -LDADD+= -lutil -MAN= getty.8 gettytab.5 ttys.5 +SRCS= main.c init.c subr.c ttydefaults.c +DPADD= ${LIBUTIL} +LDADD= -lutil +MAN5= gettytab.0 ttys.0 +MAN8= getty.0 .include diff --git a/libexec/getty/extern.h b/libexec/getty/extern.h index 366316641b80..644f93f10747 100644 --- a/libexec/getty/extern.h +++ b/libexec/getty/extern.h @@ -30,8 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)extern.h 8.1 (Berkeley) 6/4/93 - * $Id: extern.h,v 1.2 1994/08/17 20:10:29 pk Exp $ + * @(#)extern.h 8.1 (Berkeley) 6/4/93 */ struct delayval; @@ -51,7 +50,7 @@ char *portselector __P((void)); void set_ttydefaults __P((int)); void setchars __P((void)); void setdefaults __P((void)); -void setflags __P((int)); +long setflags __P((int)); int speed __P((int)); int login_tty __P((int)); /* From libutil. */ diff --git a/libexec/getty/getty.8 b/libexec/getty/getty.8 index 1b00ae5a05ed..ffd506064046 100644 --- a/libexec/getty/getty.8 +++ b/libexec/getty/getty.8 @@ -29,8 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" from: @(#)getty.8 8.1 (Berkeley) 6/4/93 -.\" $Id: getty.8,v 1.3 1994/08/17 20:10:30 pk Exp $ +.\" @(#)getty.8 8.1 (Berkeley) 6/4/93 .\" .Dd June 4, 1993 .Dt GETTY 8 diff --git a/libexec/getty/gettytab.5 b/libexec/getty/gettytab.5 index 2c2589911dcc..e5de06bd976b 100644 --- a/libexec/getty/gettytab.5 +++ b/libexec/getty/gettytab.5 @@ -29,10 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" from: @(#)gettytab.5 8.4 (Berkeley) 4/19/94 -.\" $Id: gettytab.5,v 1.12 1994/09/24 00:56:05 mycroft Exp $ +.\" @(#)gettytab.5 8.5 (Berkeley) 6/1/94 .\" -.Dd April 19, 1994 +.Dd June 1, 1994 .Dt GETTYTAB 5 .Os BSD 4.2 .Sh NAME @@ -77,10 +76,10 @@ table. .Bl -column Namexx /usr/bin/login Default .It Sy Name Type Default Description .It "ap bool false terminal uses any parity" +.It "bd num 0 backspace delay" .It "bk str 0377 alternate end of line character (input break)" -.It "c0 num unused tty control flags to write messages" -.It "c1 num unused tty control flags to read login name" -.It "c2 num unused tty control flags to leave terminal as" +.It "cb bool false use crt backspace mode" +.It "cd num 0 carriage-return delay" .It "ce bool false use crt erase algorithm" .It "ck bool false use crt kill algorithm" .It "cl str" Ta Dv NULL Ta @@ -106,6 +105,7 @@ character .It "f0 num unused tty mode flags to write messages" .It "f1 num unused tty mode flags to read login name" .It "f2 num unused tty mode flags to leave terminal as" +.It "fd num 0 form-feed (vertical motion) delay" .It "fl str" Ta So Li ^O Sc Ta .No "output flush character" .It "hc bool false do" @@ -115,9 +115,6 @@ hangup line on last close .No "hostname editing string" .It "hn str hostname hostname" .It "ht bool false terminal has real tabs" -.It "i0 num unused tty input flags to write messages" -.It "i1 num unused tty input flags to read login name" -.It "i2 num unused tty input flags to leave terminal as" .It "ig bool false ignore garbage characters in login name" .It "im str" Ta Dv NULL Ta .No "initial (banner) message" @@ -126,22 +123,16 @@ hangup line on last close .It "is num unused input speed" .It "kl str" Ta So Li ^U Sc Ta .No "kill character" -.It "l0 num unused tty local flags to write messages" -.It "l1 num unused tty local flags to read login name" -.It "l2 num unused tty local flags to leave terminal as" .It "lc bool false terminal has lower case" .It "lm str login: login prompt" .It "ln str" Ta So Li ^V Sc Ta .No "``literal next'' character" .It "lo str" Ta Pa /usr/bin/login Ta .No "program to exec when name obtained" -.It "mb bool false do flow control based on carrier" +.It "nd num 0 newline (line-feed) delay" .It "nl bool false terminal has (or might have) a newline character" .It "np bool false terminal uses no parity (i.e. 8-bit characters)" .It "nx str default next table (for auto speed selection)" -.It "o0 num unused tty output flags to write messages" -.It "o1 num unused tty output flags to read login name" -.It "o2 num unused tty output flags to leave terminal as" .It "op bool false terminal uses odd parity" .It "os num unused output speed" .It "pc str" Ta So Li \e0 Sc Ta @@ -167,6 +158,7 @@ use raw for input, use cbreak .It "tt str" Ta Dv NULL Ta .No "terminal type (for environment)" .It "ub bool false do unbuffered output (of prompts etc)" +.It "uc bool false terminal is known upper case only" .It "we str" Ta So Li ^W Sc Ta .No "word erase character" .It "xc bool false do @@ -179,16 +171,6 @@ echo control chars as (start output) character .El .Pp -The following capabilities are no longer supported by getty(8): -.Bl -column Namexx /usr/bin/login Default -.It "bd num 0 backspace delay" -.It "cb bool false use crt backspace mode" -.It "cd num 0 carriage-return delay" -.It "fd num 0 form-feed (vertical motion) delay" -.It "nd num 0 newline (line-feed) delay" -.It "uc bool false terminal is known upper case only" -.El -.Pp If no line speed is specified, speed will not be altered from that which prevails when getty is entered. Specifying an input or output speed will override @@ -201,43 +183,18 @@ are derived from the boolean flags specified. If the derivation should prove inadequate, any (or all) of these three may be overridden with one of the -.Em \&c0 , -.Em \&c1 , -.Em \&c2 , -.Em \&i0 , -.Em \&i1 , -.Em \&i2 , -.Em \&l0 , -.Em \&l1 , -.Em \&l2 , -.Em \&o0 , -.Em \&o1 , +.Em \&f0 , +.Em \&f1 , or -.Em \&o2 +.Em \&f2 numeric specifications, which can be used to specify (usually in octal, with a leading '0') the exact values of the flags. -These flags correspond to the termios -.Em c_cflag , -.Em c_iflag , -.Em c_lflag , -and -.Em c_oflag -fields, respectively. Each these sets must be completely specified to be -effective. -The -.Em \&f0 , -.Em \&f1 , -and -.Em \&f2 -are excepted for backwards compatibility with a previous incarnation of -the TTY sub-system. In these flags the bottom 16 bits of the (32 bits) -value contain the sgttyb -.Em sg_flags -field, while the top 16 bits represent the local mode word. +Local (new tty) flags are set in the top 16 bits +of this (32 bit) value. .Pp Should -.Xr getty 8 +.Xr getty receive a null character (presumed to indicate a line break) it will restart using the table indicated by the @@ -256,52 +213,39 @@ screen clear string may be preceded by a (decimal) number of milliseconds of delay required (a la termcap). This delay is simulated by repeated use of the pad character .Em \&pc . +.pl -1 .Pp The initial message, and login message, .Em \&im and .Em \&lm -may include any of the following character sequences, which expand to -information about the environment in which -.Xr getty 8 -is running. -.Pp -.Bl -tag -width \&%xxx -compact -.It \&%d -The current date. -.It \&%h -The hostname of the machine, which is normally obtained from the -system using -.Xr gethostname 2 , -but may also be overridden by the +may include the character sequence +.Em \&%h +or +.Em \&%t +to obtain +the hostname or tty name respectively. +.Pf ( Em %% +obtains a single '%' character.) +The hostname is normally obtained from the system, +but may be set by the .Em \&hn table entry. -In either case it may be edited with the +In either case it may be edited with +.Em \&he . +The .Em \&he -string. +string is a sequence of characters, each character that +is neither '@' nor '#' is copied into the final hostname. A '@' in the .Em \&he -string causes one character from the real hostname to +string, causes one character from the real hostname to be copied to the final hostname. A '#' in the .Em \&he -string causes the next character of the real hostname +string, causes the next character of the real hostname to be skipped. -Each character that -is neither '@' nor '#' is copied into the final hostname. Surplus '@' and '#' characters are ignored. -.It \&%t -The tty name. -.It "\&%m, \&%r, \&%s, \&%v" -The type of machine, release of the operating system, name of the -operating system, and version of the kernel, respectively, as -returned by -.Xr uname 2 . -.It \&%% -A -.Dq % -character. -.El .Pp When getty execs the login process, given in the @@ -327,16 +271,14 @@ then getty will exit within the indicated number of seconds, either having received a login name and passed control to -.Xr login 1 , +.Xr login , or having received an alarm signal, and exited. This may be useful to hangup dial in lines. .Pp Output from -.Xr getty 8 +.Xr getty is even parity unless .Em \&op -or -.Em \&np is specified. The .Em \&op @@ -347,14 +289,12 @@ to allow any parity on input, but generate odd parity output. Note: this only applies while getty is being run, terminal driver limitations prevent a more complete implementation. -.Xr Getty 8 +.Xr Getty does not check parity of input characters in .Dv RAW mode. .Sh SEE ALSO .Xr login 1 , -.Xr gethostname 2 , -.Xr uname 2 , .Xr termcap 5 , .Xr getty 8 . .Sh BUGS diff --git a/libexec/getty/gettytab.h b/libexec/getty/gettytab.h index a712e43909bd..fb2b14f280d6 100644 --- a/libexec/getty/gettytab.h +++ b/libexec/getty/gettytab.h @@ -30,8 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)gettytab.h 8.2 (Berkeley) 3/30/94 - * $Id: gettytab.h,v 1.7 1994/08/17 20:10:34 pk Exp $ + * @(#)gettytab.h 8.2 (Berkeley) 3/30/94 */ /* @@ -105,30 +104,6 @@ struct gettyflags { #define F2 gettynums[11].value #define F2set gettynums[11].set #define PF gettynums[12].value -#define C0 gettynums[13].value -#define C0set gettynums[13].set -#define C1 gettynums[14].value -#define C1set gettynums[14].set -#define C2 gettynums[15].value -#define C2set gettynums[15].set -#define I0 gettynums[16].value -#define I0set gettynums[16].set -#define I1 gettynums[17].value -#define I1set gettynums[17].set -#define I2 gettynums[18].value -#define I2set gettynums[18].set -#define L0 gettynums[19].value -#define L0set gettynums[19].set -#define L1 gettynums[20].value -#define L1set gettynums[20].set -#define L2 gettynums[21].value -#define L2set gettynums[21].set -#define O0 gettynums[22].value -#define O0set gettynums[22].set -#define O1 gettynums[23].value -#define O1set gettynums[23].set -#define O2 gettynums[24].value -#define O2set gettynums[24].set /* * Boolean values. @@ -158,7 +133,6 @@ struct gettyflags { #define AB gettyflags[19].value #define DX gettyflags[20].value #define NP gettyflags[21].value -#define MB gettyflags[22].value int getent __P((char *, char *)); long getnum __P((char *)); diff --git a/libexec/getty/init.c b/libexec/getty/init.c index f3e78c00e1f6..835acd753b43 100644 --- a/libexec/getty/init.c +++ b/libexec/getty/init.c @@ -32,8 +32,7 @@ */ #ifndef lint -/*static char sccsid[] = "from: @(#)init.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$Id: init.c,v 1.6 1994/08/17 20:10:35 pk Exp $"; +static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ /* @@ -41,11 +40,13 @@ static char rcsid[] = "$Id: init.c,v 1.6 1994/08/17 20:10:35 pk Exp $"; * * Melbourne getty. */ -#include +#include #include "gettytab.h" #include "pathnames.h" -extern struct termios tmode; +extern struct sgttyb tmode; +extern struct tchars tc; +extern struct ltchars ltc; extern char hostname[]; struct gettystrs gettystrs[] = { @@ -53,26 +54,26 @@ struct gettystrs gettystrs[] = { { "cl" }, /* screen clear characters */ { "im" }, /* initial message */ { "lm", "login: " }, /* login message */ - { "er", &tmode.c_cc[VERASE] }, /* erase character */ - { "kl", &tmode.c_cc[VKILL] }, /* kill character */ - { "et", &tmode.c_cc[VEOF] }, /* eof chatacter (eot) */ + { "er", &tmode.sg_erase }, /* erase character */ + { "kl", &tmode.sg_kill }, /* kill character */ + { "et", &tc.t_eofc }, /* eof chatacter (eot) */ { "pc", "" }, /* pad character */ { "tt" }, /* terminal type */ { "ev" }, /* enviroment */ { "lo", _PATH_LOGIN }, /* login program */ { "hn", hostname }, /* host name */ { "he" }, /* host name edit */ - { "in", &tmode.c_cc[VINTR] }, /* interrupt char */ - { "qu", &tmode.c_cc[VQUIT] }, /* quit char */ - { "xn", &tmode.c_cc[VSTART] }, /* XON (start) char */ - { "xf", &tmode.c_cc[VSTOP] }, /* XOFF (stop) char */ - { "bk", &tmode.c_cc[VEOL] }, /* brk char (alt \n) */ - { "su", &tmode.c_cc[VSUSP] }, /* suspend char */ - { "ds", &tmode.c_cc[VDSUSP] }, /* delayed suspend */ - { "rp", &tmode.c_cc[VREPRINT] },/* reprint char */ - { "fl", &tmode.c_cc[VDISCARD] },/* flush output */ - { "we", &tmode.c_cc[VWERASE] }, /* word erase */ - { "ln", &tmode.c_cc[VLNEXT] }, /* literal next */ + { "in", &tc.t_intrc }, /* interrupt char */ + { "qu", &tc.t_quitc }, /* quit char */ + { "xn", &tc.t_startc }, /* XON (start) char */ + { "xf", &tc.t_stopc }, /* XOFF (stop) char */ + { "bk", &tc.t_brkc }, /* brk char (alt \n) */ + { "su", <c.t_suspc }, /* suspend char */ + { "ds", <c.t_dsuspc }, /* delayed suspend */ + { "rp", <c.t_rprntc }, /* reprint char */ + { "fl", <c.t_flushc }, /* flush output */ + { "we", <c.t_werasc }, /* word erase */ + { "ln", <c.t_lnextc }, /* literal next */ { 0 } }; @@ -90,18 +91,6 @@ struct gettynums gettynums[] = { { "f1" }, /* input flags */ { "f2" }, /* user mode flags */ { "pf" }, /* delay before flush at 1st prompt */ - { "c0" }, /* output c_flags */ - { "c1" }, /* input c_flags */ - { "c2" }, /* user mode c_flags */ - { "i0" }, /* output i_flags */ - { "i1" }, /* input i_flags */ - { "i2" }, /* user mode i_flags */ - { "l0" }, /* output l_flags */ - { "l1" }, /* input l_flags */ - { "l2" }, /* user mode l_flags */ - { "o0" }, /* output o_flags */ - { "o1" }, /* input o_flags */ - { "o2" }, /* user mode o_flags */ { 0 } }; @@ -128,6 +117,5 @@ struct gettyflags gettyflags[] = { { "ab", 0 }, /* auto-baud detect with '\r' */ { "dx", 0 }, /* set decctlq */ { "np", 0 }, /* no parity at all (8bit chars) */ - { "mb", 0 }, /* do MDMBUF flow control */ { 0 } }; diff --git a/libexec/getty/main.c b/libexec/getty/main.c index 0539b1749f4e..c27ddf40a480 100644 --- a/libexec/getty/main.c +++ b/libexec/getty/main.c @@ -38,23 +38,20 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -/*static char sccsid[] = "from: @(#)main.c 8.1 (Berkeley) 6/20/93";*/ -static char rcsid[] = "$Id: main.c,v 1.15 1995/08/13 04:08:27 cgd Exp $"; +static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/20/93"; #endif /* not lint */ +#define USE_OLD_TTY + #include #include -#include -#include #include -#include -#include -#include -#include -#include + +#include #include #include #include +#include #include #include #include @@ -72,12 +69,21 @@ static char rcsid[] = "$Id: main.c,v 1.15 1995/08/13 04:08:27 cgd Exp $"; */ #define GETTY_TIMEOUT 60 /* seconds */ -struct termios tmode, omode; +struct sgttyb tmode = { + 0, 0, CERASE, CKILL, 0 +}; +struct tchars tc = { + CINTR, CQUIT, CSTART, + CSTOP, CEOF, CBRK, +}; +struct ltchars ltc = { + CSUSP, CDSUSP, CRPRNT, + CFLUSH, CWERASE, CLNEXT +}; int crmod, digit, lower, upper; char hostname[MAXHOSTNAMELEN]; -struct utsname kerninfo; char name[16]; char dev[] = _PATH_DEV; char ttyn[32]; @@ -111,9 +117,9 @@ char partab[] = { 0000,0200,0200,0000,0200,0000,0000,0201 }; -#define ERASE tmode.c_cc[VERASE] -#define KILL tmode.c_cc[VKILL] -#define EOT tmode.c_cc[VEOF] +#define ERASE tmode.sg_erase +#define KILL tmode.sg_kill +#define EOT tc.t_eofc jmp_buf timeout; @@ -164,18 +170,17 @@ main(argc, argv) extern char **environ; char *tname; long allflags; - int repcnt = 0, failopenlogged = 0; + int repcnt = 0; struct rlimit limit; signal(SIGINT, SIG_IGN); /* signal(SIGQUIT, SIG_DFL); */ - openlog("getty", LOG_ODELAY|LOG_CONS|LOG_PID, LOG_AUTH); + openlog("getty", LOG_ODELAY|LOG_CONS, LOG_AUTH); gethostname(hostname, sizeof(hostname)); if (hostname[0] == '\0') strcpy(hostname, "Amnesiac"); - uname(&kerninfo); /* * Limit running time to deal with broken or dead lines. @@ -208,11 +213,9 @@ main(argc, argv) */ sleep(2); while ((i = open(ttyn, O_RDWR)) == -1) { - if ((repcnt % 10 == 0) && - (errno != ENXIO || !failopenlogged)) { + if (repcnt % 10 == 0) { syslog(LOG_ERR, "%s: %m", ttyn); closelog(); - failopenlogged = 1; } repcnt++; sleep(60); @@ -221,13 +224,6 @@ main(argc, argv) } } - /* Start with default tty settings */ - if (tcgetattr(0, &tmode) < 0) { - syslog(LOG_ERR, "%s: %m", ttyn); - exit(1); - } - omode = tmode; - gettable("default", defent); gendefaults(); tname = "default"; @@ -241,24 +237,23 @@ main(argc, argv) APset++, OPset++, EPset++; setdefaults(); off = 0; - (void)tcflush(0, TCIOFLUSH); /* clear out the crap */ + ioctl(0, TIOCFLUSH, &off); /* clear out the crap */ ioctl(0, FIONBIO, &off); /* turn off non-blocking mode */ ioctl(0, FIOASYNC, &off); /* ditto for async mode */ - if (IS) - cfsetispeed(&tmode, IS); + tmode.sg_ispeed = speed(IS); else if (SP) - cfsetispeed(&tmode, SP); + tmode.sg_ispeed = speed(SP); if (OS) - cfsetospeed(&tmode, OS); + tmode.sg_ospeed = speed(OS); else if (SP) - cfsetospeed(&tmode, SP); - setflags(0); + tmode.sg_ospeed = speed(SP); + tmode.sg_flags = setflags(0); + ioctl(0, TIOCSETP, &tmode); setchars(); - if (tcsetattr(0, TCSANOW, &tmode) < 0) { - syslog(LOG_ERR, "%s: %m", ttyn); - exit(1); - } + ioctl(0, TIOCSETC, &tc); + if (HC) + ioctl(0, TIOCHPCL, 0); if (AB) { extern char *autobaud(); @@ -275,8 +270,8 @@ main(argc, argv) if (IM && *IM) putf(IM); if (setjmp(timeout)) { - tmode.c_ispeed = tmode.c_ospeed = 0; - (void)tcsetattr(0, TCSANOW, &tmode); + tmode.sg_ispeed = tmode.sg_ospeed = 0; + ioctl(0, TIOCSETP, &tmode); exit(1); } if (TO) { @@ -295,26 +290,28 @@ main(argc, argv) } if (!(upper || lower || digit)) continue; - setflags(2); - if (crmod) { - tmode.c_iflag |= ICRNL; - tmode.c_oflag |= ONLCR; - } -#if XXX + allflags = setflags(2); + tmode.sg_flags = allflags & 0xffff; + allflags >>= 16; + if (crmod || NL) + tmode.sg_flags |= CRMOD; if (upper || UC) tmode.sg_flags |= LCASE; if (lower || LC) tmode.sg_flags &= ~LCASE; -#endif - if (tcsetattr(0, TCSANOW, &tmode) < 0) { - syslog(LOG_ERR, "%s: %m", ttyn); - exit(1); - } + ioctl(0, TIOCSETP, &tmode); + ioctl(0, TIOCSLTC, <c); + ioctl(0, TIOCLSET, &allflags); signal(SIGINT, SIG_DFL); for (i = 0; environ[i] != (char *)0; i++) env[i] = environ[i]; makeenv(&env[i]); + /* + * this is what login was doing anyway. + * soon we rewrite getty completely. + */ + set_ttydefaults(0); limit.rlim_max = RLIM_INFINITY; limit.rlim_cur = RLIM_INFINITY; (void)setrlimit(RLIMIT_CPU, &limit); @@ -345,17 +342,16 @@ getname() return (0); } signal(SIGINT, interrupt); - setflags(1); + tmode.sg_flags = setflags(0); + ioctl(0, TIOCSETP, &tmode); + tmode.sg_flags = setflags(1); prompt(); if (PF > 0) { oflush(); sleep(PF); PF = 0; } - if (tcsetattr(0, TCSANOW, &tmode) < 0) { - syslog(LOG_ERR, "%s: %m", ttyn); - exit(1); - } + ioctl(0, TIOCSETP, &tmode); crmod = digit = lower = upper = 0; np = name; for (;;) { @@ -377,7 +373,7 @@ getname() else if (c == ERASE || c == '#' || c == '\b') { if (np > name) { np--; - if (cfgetospeed(&tmode) >= 1200) + if (tmode.sg_ospeed >= B1200) puts("\b \b"); else putchr(cs); @@ -386,7 +382,7 @@ getname() } else if (c == KILL || c == '@') { putchr(cs); putchr('\r'); - if (cfgetospeed(&tmode) < 1200) + if (tmode.sg_ospeed < B1200) putchr('\n'); /* this is the way they do it down under ... */ else if (np > name) @@ -412,12 +408,17 @@ getname() return (1); } +static +short tmspc10[] = { + 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 15 +}; + static void putpad(s) register char *s; { register pad = 0; - speed_t ospeed = cfgetospeed(&tmode); + register mspc10; if (isdigit(*s)) { while (isdigit(*s)) { @@ -436,7 +437,10 @@ putpad(s) * If no delay needed, or output speed is * not comprehensible, then don't try to delay. */ - if (pad == 0 || ospeed <= 0) + if (pad == 0) + return; + if (tmode.sg_ospeed <= 0 || + tmode.sg_ospeed >= (sizeof tmspc10 / sizeof tmspc10[0])) return; /* @@ -445,8 +449,9 @@ putpad(s) * Transmitting pad characters slows many terminals down and also * loads the system. */ - pad = (pad * ospeed + 50000) / 100000; - while (pad--) + mspc10 = tmspc10[tmode.sg_ospeed]; + pad += mspc10 / 2; + for (pad /= mspc10; pad > 0; pad--) putchr(*PC); } @@ -526,29 +531,13 @@ putf(cp) break; case 'd': { - static char fmt[] = "%l:% %p on %A, %d %B %Y"; + static char fmt[] = "%l:% %P on %A, %d %B %Y"; fmt[4] = 'M'; /* I *hate* SCCS... */ (void)time(&t); (void)strftime(db, sizeof(db), fmt, localtime(&t)); puts(db); break; - - case 's': - puts(kerninfo.sysname); - break; - - case 'm': - puts(kerninfo.machine); - break; - - case 'r': - puts(kerninfo.release); - break; - - case 'v': - puts(kerninfo.version); - break; } case '%': diff --git a/libexec/getty/pathnames.h b/libexec/getty/pathnames.h index 5cfe73dfa6fd..714a9ccc35bf 100644 --- a/libexec/getty/pathnames.h +++ b/libexec/getty/pathnames.h @@ -30,8 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)pathnames.h 8.1 (Berkeley) 6/4/93 - * $Id: pathnames.h,v 1.3 1994/08/17 20:10:39 pk Exp $ + * @(#)pathnames.h 8.1 (Berkeley) 6/4/93 */ #include diff --git a/libexec/getty/subr.c b/libexec/getty/subr.c index 8c55e37dc4f7..4a2abb3ded41 100644 --- a/libexec/getty/subr.c +++ b/libexec/getty/subr.c @@ -32,27 +32,25 @@ */ #ifndef lint -/*static char sccsid[] = "from: @(#)subr.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$Id: subr.c,v 1.18 1995/10/05 08:51:31 mycroft Exp $"; +static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ /* * Melbourne getty. */ -#define COMPAT_43 +#define USE_OLD_TTY #include -#include +#include #include -#include -#include +#include #include "gettytab.h" -#include "pathnames.h" #include "extern.h" +#include "pathnames.h" -extern struct termios tmode, omode; - -static void compatflags __P((long)); +extern struct sgttyb tmode; +extern struct tchars tc; +extern struct ltchars ltc; /* * Get a table entry. @@ -72,7 +70,7 @@ gettable(name, buf) if (cgetent(&buf, dba, name) != 0) return; - for (sp = gettystrs; sp->field; sp++) + for (sp = gettystrs; sp->field; sp++) cgetstr(buf, sp->field, &sp->value); for (np = gettynums; np->field; np++) { if (cgetnum(buf, np->field, &n) == -1) @@ -149,11 +147,11 @@ charnames[] = { static char * charvars[] = { - &tmode.c_cc[VERASE], &tmode.c_cc[VKILL], &tmode.c_cc[VINTR], - &tmode.c_cc[VQUIT], &tmode.c_cc[VSTART], &tmode.c_cc[VSTOP], - &tmode.c_cc[VEOF], &tmode.c_cc[VEOL], &tmode.c_cc[VSUSP], - &tmode.c_cc[VDSUSP], &tmode.c_cc[VREPRINT], &tmode.c_cc[VDISCARD], - &tmode.c_cc[VWERASE], &tmode.c_cc[VLNEXT], 0 + &tmode.sg_erase, &tmode.sg_kill, &tc.t_intrc, + &tc.t_quitc, &tc.t_startc, &tc.t_stopc, + &tc.t_eofc, &tc.t_brkc, <c.t_suspc, + <c.t_dsuspc, <c.t_rprntc, <c.t_flushc, + <c.t_werasc, <c.t_lnextc, 0 }; void @@ -167,320 +165,86 @@ setchars() if (p && *p) *charvars[i] = *p; else - *charvars[i] = _POSIX_VDISABLE; + *charvars[i] = '\377'; } } -/* Macros to clear/set/test flags. */ -#define SET(t, f) (t) |= (f) -#define CLR(t, f) (t) &= ~(f) -#define ISSET(t, f) ((t) & (f)) - -void +long setflags(n) int n; { - register tcflag_t iflag, oflag, cflag, lflag; - -#ifdef COMPAT_43 - switch (n) { - case 0: - if (F0set) { - compatflags(F0); - return; - } - break; - case 1: - if (F1set) { - compatflags(F1); - return; - } - break; - default: - if (F2set) { - compatflags(F2); - return; - } - break; - } -#endif + register long f; switch (n) { case 0: - if (C0set && I0set && L0set && O0set) { - tmode.c_cflag = C0; - tmode.c_iflag = I0; - tmode.c_lflag = L0; - tmode.c_oflag = O0; - return; - } + if (F0set) + return(F0); break; case 1: - if (C1set && I1set && L1set && O1set) { - tmode.c_cflag = C1; - tmode.c_iflag = I1; - tmode.c_lflag = L1; - tmode.c_oflag = O1; - return; - } + if (F1set) + return(F1); break; default: - if (C2set && I2set && L2set && O2set) { - tmode.c_cflag = C2; - tmode.c_iflag = I2; - tmode.c_lflag = L2; - tmode.c_oflag = O2; - return; - } + if (F2set) + return(F2); break; } - iflag = omode.c_iflag; - oflag = omode.c_oflag; - cflag = omode.c_cflag; - lflag = omode.c_lflag; + f = 0; - if (NP) { - CLR(cflag, CSIZE|PARENB); - SET(cflag, CS8); - CLR(iflag, ISTRIP|INPCK|IGNPAR); - } else if (AP || EP || OP) { - CLR(cflag, CSIZE); - SET(cflag, CS7|PARENB); - SET(iflag, ISTRIP); - if (OP && !EP) { - SET(iflag, INPCK|IGNPAR); - SET(cflag, PARODD); - if (AP) - CLR(iflag, INPCK); - } else if (EP && !OP) { - SET(iflag, INPCK|IGNPAR); - CLR(cflag, PARODD); - if (AP) - CLR(iflag, INPCK); - } else if (AP || EP && OP) { - CLR(iflag, INPCK|IGNPAR); - CLR(cflag, PARODD); - } - } /* else, leave as is */ + if (AP) + f |= ANYP; + else if (OP) + f |= ODDP; + else if (EP) + f |= EVENP; -#if 0 if (UC) f |= LCASE; -#endif - if (HC) - SET(cflag, HUPCL); - else - CLR(cflag, HUPCL); + if (NL) + f |= CRMOD; - if (MB) - SET(cflag, MDMBUF); - else - CLR(cflag, MDMBUF); + f |= delaybits(); - if (NL) { - SET(iflag, ICRNL); - SET(oflag, ONLCR|OPOST); - } else { - CLR(iflag, ICRNL); - CLR(oflag, ONLCR); + if (n == 1) { /* read mode flags */ + if (RW) + f |= RAW; + else + f |= CBREAK; + return (f); } if (!HT) - SET(oflag, OXTABS|OPOST); - else - CLR(oflag, OXTABS); - -#ifdef XXX_DELAY - SET(f, delaybits()); -#endif - - if (n == 1) { /* read mode flags */ - if (RW) { - iflag = 0; - CLR(oflag, OPOST); - CLR(cflag, CSIZE|PARENB); - SET(cflag, CS8); - lflag = 0; - } else { - CLR(lflag, ICANON); - } - goto out; - } + f |= XTABS; if (n == 0) - goto out; + return (f); -#if 0 if (CB) - SET(f, CRTBS); -#endif + f |= CRTBS; if (CE) - SET(lflag, ECHOE); - else - CLR(lflag, ECHOE); + f |= CRTERA; if (CK) - SET(lflag, ECHOKE); - else - CLR(lflag, ECHOKE); + f |= CRTKIL; if (PE) - SET(lflag, ECHOPRT); - else - CLR(lflag, ECHOPRT); + f |= PRTERA; if (EC) - SET(lflag, ECHO); - else - CLR(lflag, ECHO); + f |= ECHO; if (XC) - SET(lflag, ECHOCTL); - else - CLR(lflag, ECHOCTL); + f |= CTLECH; if (DX) - SET(lflag, IXANY); - else - CLR(lflag, IXANY); + f |= DECCTQ; -out: - tmode.c_iflag = iflag; - tmode.c_oflag = oflag; - tmode.c_cflag = cflag; - tmode.c_lflag = lflag; + return (f); } -#ifdef COMPAT_43 -/* - * Old TTY => termios, snatched from - */ -void -compatflags(flags) -register long flags; -{ - register tcflag_t iflag, oflag, cflag, lflag; - - iflag = BRKINT|ICRNL|IMAXBEL|IXON|IXANY; - oflag = OPOST|ONLCR|OXTABS; - cflag = CREAD; - lflag = ICANON|ISIG|IEXTEN; - - if (ISSET(flags, TANDEM)) - SET(iflag, IXOFF); - else - CLR(iflag, IXOFF); - if (ISSET(flags, ECHO)) - SET(lflag, ECHO); - else - CLR(lflag, ECHO); - if (ISSET(flags, CRMOD)) { - SET(iflag, ICRNL); - SET(oflag, ONLCR); - } else { - CLR(iflag, ICRNL); - CLR(oflag, ONLCR); - } - if (ISSET(flags, XTABS)) - SET(oflag, OXTABS); - else - CLR(oflag, OXTABS); - - - if (ISSET(flags, RAW)) { - iflag &= IXOFF; - CLR(lflag, ISIG|ICANON|IEXTEN); - CLR(cflag, PARENB); - } else { - SET(iflag, BRKINT|IXON|IMAXBEL); - SET(lflag, ISIG|IEXTEN); - if (ISSET(flags, CBREAK)) - CLR(lflag, ICANON); - else - SET(lflag, ICANON); - switch (ISSET(flags, ANYP)) { - case 0: - CLR(cflag, PARENB); - break; - case ANYP: - SET(cflag, PARENB); - CLR(iflag, INPCK); - break; - case EVENP: - SET(cflag, PARENB); - SET(iflag, INPCK); - CLR(cflag, PARODD); - break; - case ODDP: - SET(cflag, PARENB); - SET(iflag, INPCK); - SET(cflag, PARODD); - break; - } - } - - /* Nothing we can do with CRTBS. */ - if (ISSET(flags, PRTERA)) - SET(lflag, ECHOPRT); - else - CLR(lflag, ECHOPRT); - if (ISSET(flags, CRTERA)) - SET(lflag, ECHOE); - else - CLR(lflag, ECHOE); - /* Nothing we can do with TILDE. */ - if (ISSET(flags, MDMBUF)) - SET(cflag, MDMBUF); - else - CLR(cflag, MDMBUF); - if (ISSET(flags, NOHANG)) - CLR(cflag, HUPCL); - else - SET(cflag, HUPCL); - if (ISSET(flags, CRTKIL)) - SET(lflag, ECHOKE); - else - CLR(lflag, ECHOKE); - if (ISSET(flags, CTLECH)) - SET(lflag, ECHOCTL); - else - CLR(lflag, ECHOCTL); - if (!ISSET(flags, DECCTQ)) - SET(iflag, IXANY); - else - CLR(iflag, IXANY); - CLR(lflag, TOSTOP|FLUSHO|PENDIN|NOFLSH); - SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH)); - - if (ISSET(flags, RAW|LITOUT|PASS8)) { - CLR(cflag, CSIZE); - SET(cflag, CS8); - if (!ISSET(flags, RAW|PASS8)) - SET(iflag, ISTRIP); - else - CLR(iflag, ISTRIP); - if (!ISSET(flags, RAW|LITOUT)) - SET(oflag, OPOST); - else - CLR(oflag, OPOST); - } else { - CLR(cflag, CSIZE); - SET(cflag, CS7); - SET(iflag, ISTRIP); - SET(oflag, OPOST); - } - - tmode.c_iflag = iflag; - tmode.c_oflag = oflag; - tmode.c_cflag = cflag; - tmode.c_lflag = lflag; -} -#endif - -#ifdef XXX_DELAY struct delayval { unsigned delay; /* delay in ms */ int bits; @@ -550,7 +314,6 @@ adelay(ms, dp) dp++; return (dp->bits); } -#endif char editedhost[32]; @@ -594,6 +357,47 @@ edithost(pat) editedhost[sizeof editedhost - 1] = '\0'; } +struct speedtab { + int speed; + int uxname; +} speedtab[] = { + { 50, B50 }, + { 75, B75 }, + { 110, B110 }, + { 134, B134 }, + { 150, B150 }, + { 200, B200 }, + { 300, B300 }, + { 600, B600 }, + { 1200, B1200 }, + { 1800, B1800 }, + { 2400, B2400 }, + { 4800, B4800 }, + { 9600, B9600 }, + { 19200, EXTA }, + { 19, EXTA }, /* for people who say 19.2K */ + { 38400, EXTB }, + { 38, EXTB }, + { 7200, EXTB }, /* alternative */ + { 0 } +}; + +int +speed(val) + int val; +{ + register struct speedtab *sp; + + if (val <= 15) + return (val); + + for (sp = speedtab; sp->speed; sp++) + if (sp->speed == val) + return (sp->uxname); + + return (B300); /* default in impossible cases */ +} + void makeenv(env) char *env[]; @@ -684,8 +488,9 @@ autobaud() int rfds; struct timeval timeout; char c, *type = "9600-baud"; + int null = 0; - (void)tcflush(0, TCIOFLUSH); + ioctl(0, TIOCFLUSH, &null); rfds = 1 << 0; timeout.tv_sec = 5; timeout.tv_usec = 0; @@ -698,7 +503,7 @@ autobaud() timeout.tv_usec = 20; (void) select(32, (fd_set *)NULL, (fd_set *)NULL, (fd_set *)NULL, &timeout); - (void)tcflush(0, TCIOFLUSH); + ioctl(0, TIOCFLUSH, &null); switch (c & 0377) { case 0200: /* 300-baud */ diff --git a/libexec/getty/ttys.5 b/libexec/getty/ttys.5 index 59287821c827..cbbdbb67253c 100644 --- a/libexec/getty/ttys.5 +++ b/libexec/getty/ttys.5 @@ -29,8 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" from: @(#)ttys.5 8.1 (Berkeley) 6/4/93 -.\" $Id: ttys.5,v 1.6 1994/08/17 20:10:41 pk Exp $ +.\" @(#)ttys.5 8.1 (Berkeley) 6/4/93 .\" .Dd June 4, 1993 .Dt TTYS 5 @@ -97,18 +96,6 @@ should (should not) execute the command given in the second field, while ``secure'' (if ``on'' is also specified) allows users with a uid of 0 to login on this line. -The flags ``local'', ``rtscts'', ``mdmbuf'', and ``softcar'' -modify the default behaviour of the terminal line, and their actions -are driver dependent. -The ``local'' flag causes the driver to -treat the line as if it locally connected. -The ``rtscts'' flag -instructs the driver to use RTS/CTS hardware flow control, if -possible. -The ``mdmbuf'' flag instructs the driver to use -DTR/DCD flow control, if possible. -The ``softcar'' flag causes the driver to ignore -hardware carrier on the line. These flag fields should not be quoted. .Pp The string ``window='' may be followed by a quoted command @@ -144,8 +131,7 @@ ttyp1 none network off .Xr gettytab 5 , .Xr termcap 5 , .Xr getty 8 , -.Xr init 8 , -.Xr ttyflags 8 +.Xr init 8 .Sh HISTORY A .Nm diff --git a/libexec/rbootd/Makefile b/libexec/rbootd/Makefile index 59d3137bb790..6e377fc51d8a 100644 --- a/libexec/rbootd/Makefile +++ b/libexec/rbootd/Makefile @@ -1,8 +1,11 @@ -# from: @(#)Makefile 8.1 (Berkeley) 6/4/93 -# $NetBSD: Makefile,v 1.4 1995/08/21 17:05:08 thorpej Exp $ +# @(#)Makefile 8.1 (Berkeley) 6/4/93 PROG= rbootd SRCS= bpf.c conf.c parseconf.c rbootd.c rmpproto.c utils.c -MAN= rbootd.8 +MAN8= rbootd.0 + +afterinstall: + (cd ${.CURDIR}/bootdir && install -c -o ${BINOWN} -g ${BINGRP} \ + -m 444 * ${DESTDIR}/usr/mdec/) .include diff --git a/libexec/rbootd/bpf.c b/libexec/rbootd/bpf.c index 2ccf7da94590..7ecd41957a32 100644 --- a/libexec/rbootd/bpf.c +++ b/libexec/rbootd/bpf.c @@ -1,5 +1,3 @@ -/* $NetBSD: bpf.c,v 1.7 1997/01/27 22:51:50 thorpej Exp $ */ - /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -40,15 +38,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)bpf.c 8.1 (Berkeley) 6/4/93 + * @(#)bpf.c 8.1 (Berkeley) 6/4/93 * - * From: Utah Hdr: bpf.c 3.1 92/07/06 + * Utah $Hdr: bpf.c 3.1 92/07/06$ * Author: Jeff Forys, University of Utah CSS */ #ifndef lint -/*static char sccsid[] = "@(#)bpf.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$NetBSD: bpf.c,v 1.7 1997/01/27 22:51:50 thorpej Exp $"; +static char sccsid[] = "@(#)bpf.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ #include @@ -71,7 +68,7 @@ static char rcsid[] = "$NetBSD: bpf.c,v 1.7 1997/01/27 22:51:50 thorpej Exp $"; static int BpfFd = -1; static unsigned BpfLen = 0; -static u_int8_t *BpfPkt = NULL; +static u_char *BpfPkt = NULL; /* ** BpfOpen -- Open and initialize a BPF device. @@ -148,9 +145,14 @@ BpfOpen() #endif ifr.ifr_addr.sa_family = AF_UNSPEC; bcopy(&RmpMcastAddr[0], (char *)&ifr.ifr_addr.sa_data[0], RMP_ADDRLEN); - if (ioctl(BpfFd, BIOCPROMISC, (caddr_t)0) < 0) { - syslog(LOG_ERR, "bpf: can't set promiscuous mode: %m"); - Exit(0); + if (ioctl(BpfFd, SIOCADDMULTI, (caddr_t)&ifr) < 0) { + syslog(LOG_WARNING, + "bpf: can't add mcast addr (%m), setting promiscuous mode"); + + if (ioctl(BpfFd, BIOCPROMISC, (caddr_t)0) < 0) { + syslog(LOG_ERR, "bpf: can't set promiscuous mode: %m"); + Exit(0); + } } /* @@ -161,7 +163,7 @@ BpfOpen() Exit(0); } if (BpfPkt == NULL) - BpfPkt = (u_int8_t *)malloc(BpfLen); + BpfPkt = (u_char *)malloc(BpfLen); if (BpfPkt == NULL) { syslog(LOG_ERR, "bpf: out of memory (%u bytes for bpfpkt)", @@ -310,7 +312,7 @@ BpfRead(rconn, doread) int doread; { register int datlen, caplen, hdrlen; - static u_int8_t *bp = NULL, *ep = NULL; + static u_char *bp = NULL, *ep = NULL; int cc; /* diff --git a/libexec/rbootd/conf.c b/libexec/rbootd/conf.c index 51ad23bac5ca..b890eeadae7c 100644 --- a/libexec/rbootd/conf.c +++ b/libexec/rbootd/conf.c @@ -1,5 +1,3 @@ -/* $NetBSD: conf.c,v 1.5 1995/10/06 05:12:13 thorpej Exp $ */ - /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -40,15 +38,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)conf.c 8.1 (Berkeley) 6/4/93 + * @(#)conf.c 8.1 (Berkeley) 6/4/93 * - * From: Utah Hdr: conf.c 3.1 92/07/06 + * Utah $Hdr: conf.c 3.1 92/07/06$ * Author: Jeff Forys, University of Utah CSS */ #ifndef lint -/*static char sccsid[] = "@(#)conf.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$NetBSD: conf.c,v 1.5 1995/10/06 05:12:13 thorpej Exp $"; +static char sccsid[] = "@(#)conf.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ #include @@ -68,8 +65,9 @@ static char rcsid[] = "$NetBSD: conf.c,v 1.5 1995/10/06 05:12:13 thorpej Exp $"; ** simplify the boot file search code. */ +char *ProgName; /* path-stripped argv[0] */ char MyHost[MAXHOSTNAMELEN+1]; /* host name */ -pid_t MyPid; /* process id */ +int MyPid; /* process id */ int DebugFlg = 0; /* set true if debugging */ int BootAny = 0; /* set true if we boot anyone */ @@ -82,11 +80,11 @@ char *DbgFile = _PATH_RBOOTDDBG; /* debug output file */ FILE *DbgFp = NULL; /* debug file pointer */ char *IntfName = NULL; /* intf we are attached to */ -u_int16_t SessionID = 0; /* generated session ID */ +u_short SessionID = 0; /* generated session ID */ char *BootFiles[C_MAXFILE]; /* list of boot files */ CLIENT *Clients = NULL; /* list of addrs we'll accept */ RMPCONN *RmpConns = NULL; /* list of active connections */ -u_int8_t RmpMcastAddr[RMP_ADDRLEN] = RMP_ADDR; /* RMP multicast address */ +char RmpMcastAddr[RMP_ADDRLEN] = RMP_ADDR; /* RMP multicast address */ diff --git a/libexec/rbootd/defs.h b/libexec/rbootd/defs.h index 9ff814e2c309..a2e0cd0616c7 100644 --- a/libexec/rbootd/defs.h +++ b/libexec/rbootd/defs.h @@ -1,5 +1,3 @@ -/* $NetBSD: defs.h,v 1.5 1995/10/06 05:12:14 thorpej Exp $ */ - /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -40,9 +38,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)defs.h 8.1 (Berkeley) 6/4/93 + * @(#)defs.h 8.1 (Berkeley) 6/4/93 * - * From: Utah Hdr: defs.h 3.1 92/07/06 + * Utah $Hdr: defs.h 3.1 92/07/06$ * Author: Jeff Forys, University of Utah CSS */ @@ -109,7 +107,7 @@ * (unless there are no restrictions on who we can boot). */ typedef struct client_s { - u_int8_t addr[RMP_ADDRLEN]; /* addr of machine */ + u_char addr[RMP_ADDRLEN]; /* addr of machine */ char *files[C_MAXFILE]; /* boot-able files */ struct client_s *next; /* ptr to next */ } CLIENT; @@ -128,8 +126,9 @@ typedef struct rmpconn_s { /* * All these variables are defined in "conf.c". */ +extern char *ProgName; /* path-stripped argv[0] */ extern char MyHost[]; /* this hosts' name */ -extern pid_t MyPid; /* this processes' ID */ +extern int MyPid; /* this processes' ID */ extern int DebugFlg; /* set true if debugging */ extern int BootAny; /* set true if we can boot anyone */ @@ -142,14 +141,14 @@ extern char *BootDir; /* directory w/boot files */ extern FILE *DbgFp; /* debug file pointer */ extern char *IntfName; /* interface we are attached to */ -extern u_int16_t SessionID; /* generated session ID */ +extern u_short SessionID; /* generated session ID */ extern char *BootFiles[]; /* list of boot files */ extern CLIENT *Clients; /* list of addrs we'll accept */ extern RMPCONN *RmpConns; /* list of active connections */ -extern u_int8_t RmpMcastAddr[]; /* RMP multicast address */ +extern char RmpMcastAddr[]; /* RMP multicast address */ void AddConn __P((RMPCONN *)); int BootDone __P((RMPCONN *)); @@ -170,11 +169,11 @@ void FreeClients __P((void)); void FreeConn __P((RMPCONN *)); void FreeConns __P((void)); int GetBootFiles __P((void)); -char *GetEtherAddr __P((u_int8_t *)); -CLIENT *NewClient __P((u_int8_t *)); +char *GetEtherAddr __P((u_char *)); +CLIENT *NewClient __P((u_char *)); RMPCONN *NewConn __P((RMPCONN *)); char *NewStr __P((char *)); -u_int8_t *ParseAddr __P((char *)); +u_char *ParseAddr __P((char *)); int ParseConfig __P((void)); void ProcessPacket __P((RMPCONN *, CLIENT *)); void ReConfig __P((int)); diff --git a/libexec/rbootd/parseconf.c b/libexec/rbootd/parseconf.c index e96e9275d737..d00436f071c8 100644 --- a/libexec/rbootd/parseconf.c +++ b/libexec/rbootd/parseconf.c @@ -1,5 +1,3 @@ -/* $NetBSD: parseconf.c,v 1.4 1995/10/06 05:12:16 thorpej Exp $ */ - /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -40,15 +38,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)parseconf.c 8.1 (Berkeley) 6/4/93 + * @(#)parseconf.c 8.1 (Berkeley) 6/4/93 * - * From: Utah Hdr: parseconf.c 3.1 92/07/06 + * Utah $Hdr: parseconf.c 3.1 92/07/06$ * Author: Jeff Forys, University of Utah CSS */ #ifndef lint -/*static char sccsid[] = "@(#)parseconf.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$NetBSD: parseconf.c,v 1.4 1995/10/06 05:12:16 thorpej Exp $"; +static char sccsid[] = "@(#)parseconf.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ #include @@ -85,7 +82,7 @@ ParseConfig() { FILE *fp; CLIENT *client; - u_int8_t *addr; + u_char *addr; char line[C_LINELEN]; register char *cp, *bcp; register int i, j; @@ -244,12 +241,13 @@ ParseConfig() ** Warnings: ** - The return value points to a static buffer; it must ** be copied if it's to be saved. +** - For speed, we assume a u_char consists of 8 bits. */ -u_int8_t * +u_char * ParseAddr(str) char *str; { - static u_int8_t addr[RMP_ADDRLEN]; + static u_char addr[RMP_ADDRLEN]; register char *cp; register unsigned i; register int part, subpart; diff --git a/libexec/rbootd/pathnames.h b/libexec/rbootd/pathnames.h index 381864abc45c..d960dcee96ac 100644 --- a/libexec/rbootd/pathnames.h +++ b/libexec/rbootd/pathnames.h @@ -1,5 +1,3 @@ -/* $NetBSD: pathnames.h,v 1.3 1995/08/21 17:05:15 thorpej Exp $ */ - /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -40,9 +38,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)pathnames.h 8.1 (Berkeley) 6/4/93 + * @(#)pathnames.h 8.1 (Berkeley) 6/4/93 * - * From: Utah Hdr: pathnames.h 3.1 92/07/06 + * Utah $Hdr: pathnames.h 3.1 92/07/06$ * Author: Jeff Forys, University of Utah CSS */ diff --git a/libexec/rbootd/rbootd.8 b/libexec/rbootd/rbootd.8 index 3b783bb77516..f4eb36477def 100644 --- a/libexec/rbootd/rbootd.8 +++ b/libexec/rbootd/rbootd.8 @@ -1,5 +1,3 @@ -.\" $NetBSD: rbootd.8,v 1.4 1997/05/29 01:48:46 cgd Exp $ -.\" .\" Copyright (c) 1988, 1992 The University of Utah and the Center .\" for Software Science (CSS). .\" Copyright (c) 1992, 1993 @@ -39,12 +37,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" from: @(#)rbootd.8 8.2 (Berkeley) 12/11/93 +.\" @(#)rbootd.8 8.2 (Berkeley) 12/11/93 .\" -.\" Utah Hdr: rbootd.man 3.1 92/07/06 +.\" Utah $Hdr: rbootd.man 3.1 92/07/06$ .\" Author: Jeff Forys, University of Utah CSS .\" -.Dd December 11, 1993 +.Dd "December 11, 1993" .Dt RBOOTD 8 .Os .Sh NAME diff --git a/libexec/rbootd/rbootd.c b/libexec/rbootd/rbootd.c index 11d5445911ac..aa01583496f2 100644 --- a/libexec/rbootd/rbootd.c +++ b/libexec/rbootd/rbootd.c @@ -1,5 +1,3 @@ -/* $NetBSD: rbootd.c,v 1.5 1995/10/06 05:12:17 thorpej Exp $ */ - /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -40,9 +38,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)rbootd.c 8.1 (Berkeley) 6/4/93 + * @(#)rbootd.c 8.2 (Berkeley) 2/22/94 * - * From: Utah Hdr: rbootd.c 3.1 92/07/06 + * Utah $Hdr: rbootd.c 3.1 92/07/06$ * Author: Jeff Forys, University of Utah CSS */ @@ -53,14 +51,14 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -/*static char sccsid[] = "@(#)rbootd.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$NetBSD: rbootd.c,v 1.5 1995/10/06 05:12:17 thorpej Exp $"; +static char sccsid[] = "@(#)rbootd.c 8.2 (Berkeley) 2/22/94"; #endif /* not lint */ #include +#include #include + #include -#include #include #include #include @@ -71,7 +69,19 @@ static char rcsid[] = "$NetBSD: rbootd.c,v 1.5 1995/10/06 05:12:17 thorpej Exp $ #include #include "defs.h" -extern char *__progname; /* from crt0.o */ + +/* fd mask macros (backward compatibility with 4.2BSD) */ +#ifndef FD_SET +#ifdef notdef +typedef struct fd_set { /* this should already be in 4.2 */ + int fds_bits[1]; +} fd_set; +#endif +#define FD_ZERO(p) ((p)->fds_bits[0] = 0) +#define FD_SET(n, p) ((p)->fds_bits[0] |= (1 << (n))) +#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1 << (n))) +#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1 << (n))) +#endif int main(argc, argv) @@ -81,6 +91,11 @@ main(argc, argv) int c, fd, omask, maxfds; fd_set rset; + /* + * Find what name we are running under. + */ + ProgName = (ProgName = rindex(argv[0],'/')) ? ++ProgName : *argv; + /* * Close any open file descriptors. * Temporarily leave stdin & stdout open for `-d', @@ -114,8 +129,9 @@ main(argc, argv) if (ConfigFile == NULL) ConfigFile = argv[optind]; else { - warnx("too many config files (`%s' ignored)\n", - argv[optind]); + fprintf(stderr, + "%s: too many config files (`%s' ignored)\n", + ProgName, argv[optind]); } } @@ -127,16 +143,57 @@ main(argc, argv) (void) signal(SIGUSR1, SIG_IGN); /* dont muck w/DbgFp */ (void) signal(SIGUSR2, SIG_IGN); - (void) fclose(stderr); /* finished with it */ } else { - if (daemon(0, 0)) - err(1, "can't detach from terminal"); + (void) fclose(stdin); /* dont need these */ + (void) fclose(stdout); + + /* + * Fork off a child to do the work & exit. + */ + switch(fork()) { + case -1: /* fork failed */ + fprintf(stderr, "%s: ", ProgName); + perror("fork"); + Exit(0); + case 0: /* this is the CHILD */ + break; + default: /* this is the PARENT */ + _exit(0); + } + + /* + * Try to disassociate from the current tty. + */ + { + char *devtty = "/dev/tty"; + int i; + + if ((i = open(devtty, O_RDWR)) < 0) { + /* probably already disassociated */ + if (setpgrp(0, 0) < 0) { + fprintf(stderr, "%s: ", ProgName); + perror("setpgrp"); + } + } else { + if (ioctl(i, (u_long)TIOCNOTTY, (char *)0) < 0){ + fprintf(stderr, "%s: ", ProgName); + perror("ioctl"); + } + (void) close(i); + } + } (void) signal(SIGUSR1, DebugOn); (void) signal(SIGUSR2, DebugOff); } - openlog(__progname, LOG_PID, LOG_DAEMON); + (void) fclose(stderr); /* finished with it */ + +#ifdef SYSLOG4_2 + openlog(ProgName, LOG_PID); +#else + openlog(ProgName, LOG_PID, LOG_DAEMON); +#endif /* * If no interface was specified, get one now. @@ -180,7 +237,7 @@ main(argc, argv) FILE *fp; if ((fp = fopen(PidFile, "w")) != NULL) { - (void) fprintf(fp, "%d\n", (int) MyPid); + (void) fprintf(fp, "%d\n", MyPid); (void) fclose(fp); } else { syslog(LOG_WARNING, "fopen: failed (%s)", PidFile); @@ -229,11 +286,13 @@ main(argc, argv) r = rset; if (RmpConns == NULL) { /* timeout isnt necessary */ - nsel = select(maxfds, &r, NULL, NULL, NULL); + nsel = select(maxfds, &r, (fd_set *)0, (fd_set *)0, + (struct timeval *)0); } else { timeout.tv_sec = RMP_TIMEOUT; timeout.tv_usec = 0; - nsel = select(maxfds, &r, NULL, NULL, &timeout); + nsel = select(maxfds, &r, (fd_set *)0, (fd_set *)0, + &timeout); } if (nsel < 0) { diff --git a/libexec/rbootd/rmp.h b/libexec/rbootd/rmp.h index 4a686ef2b451..d3b016760d35 100644 --- a/libexec/rbootd/rmp.h +++ b/libexec/rbootd/rmp.h @@ -1,5 +1,3 @@ -/* $NetBSD: rmp.h,v 1.4 1995/10/06 05:12:18 thorpej Exp $ */ - /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -40,9 +38,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)rmp.h 8.1 (Berkeley) 6/4/93 + * @(#)rmp.h 8.1 (Berkeley) 6/4/93 * - * From: Utah Hdr: rmp.h 3.1 92/07/06 + * Utah $Hdr: rmp.h 3.1 92/07/06$ * Author: Jeff Forys, University of Utah CSS */ @@ -77,21 +75,21 @@ */ struct hp_hdr { - u_int8_t daddr[RMP_ADDRLEN]; - u_int8_t saddr[RMP_ADDRLEN]; - u_int16_t len; + u_char daddr[RMP_ADDRLEN]; + u_char saddr[RMP_ADDRLEN]; + u_short len; }; /* * HP uses 802.2 LLC with their own local extensions. This struct makes - * sense out of this data (encapsulated in the above 802.3 packet). + * sence out of this data (encapsulated in the above 802.3 packet). */ struct hp_llc { - u_int8_t dsap; /* 802.2 DSAP */ - u_int8_t ssap; /* 802.2 SSAP */ - u_int16_t cntrl; /* 802.2 control field */ - u_int16_t filler; /* HP filler (must be zero) */ - u_int16_t dxsap; /* HP extended DSAP */ - u_int16_t sxsap; /* HP extended SSAP */ + u_char dsap; /* 802.2 DSAP */ + u_char ssap; /* 802.2 SSAP */ + u_short cntrl; /* 802.2 control field */ + u_short filler; /* HP filler (must be zero) */ + u_short dxsap; /* HP extended DSAP */ + u_short sxsap; /* HP extended SSAP */ }; diff --git a/libexec/rbootd/rmp_var.h b/libexec/rbootd/rmp_var.h index c60b6ddf3637..7df1e87465fc 100644 --- a/libexec/rbootd/rmp_var.h +++ b/libexec/rbootd/rmp_var.h @@ -1,5 +1,3 @@ -/* $NetBSD: rmp_var.h,v 1.8 1995/11/14 08:41:44 thorpej Exp $ */ - /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -40,9 +38,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)rmp_var.h 8.1 (Berkeley) 6/4/93 + * @(#)rmp_var.h 8.1 (Berkeley) 6/4/93 * - * from: Utah Hdr: rmp_var.h 3.1 92/07/06 + * Utah $Hdr: rmp_var.h 3.1 92/07/06$ * Author: Jeff Forys, University of Utah CSS */ @@ -102,12 +100,12 @@ sizeof(struct rmp_boot_repl) + s - sizeof(restofpkt)) #define RMPREADSIZE(s) (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ sizeof(struct rmp_read_repl) + s - sizeof(restofpkt) \ - - sizeof(u_int8_t)) + - sizeof(u_char)) #define RMPDONESIZE (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ sizeof(struct rmp_boot_done)) #define RMPBOOTDATA 255 #define RMPREADDATA (RMPDATALEN - \ - (2*sizeof(u_int8_t)+sizeof(u_int16_t)+sizeof(u_word))) + (2*sizeof(u_char)+sizeof(u_short)+sizeof(u_word))) /* * This protocol defines some field sizes as "rest of ethernet packet". @@ -119,9 +117,9 @@ typedef char restofpkt; /* * Due to the RMP packet layout, we'll run into alignment problems - * on machines that can't access (or don't, by default, align) words - * on half-word boundaries. If you know that your machine does not suffer - * from this problem, add it to the vax/tahoe/m68k #define below. + * on machines that cant access words on half-word boundaries. If + * you know that your machine does not suffer from this problem, + * add it to the hp300 #define below. * * The following macros are used to deal with this problem: * WORDZE(w) Return True if u_word `w' is zero, False otherwise. @@ -129,25 +127,25 @@ typedef char restofpkt; * COPYWORD(w1,w2) Copy u_word `w1' to `w2'. * GETWORD(w,i) Copy u_word `w' into int `i'. * PUTWORD(i,w) Copy int `i' into u_word `w'. - * - * N.B. Endianness is handled by use of ntohl/htonl + * + * N.B. We do not support little endian alignment-challenged machines. */ -#if defined(__vax__) || defined(__tahoe__) || defined(__m68k__) +#if defined(vax) || defined(tahoe) || defined(hp300) -typedef u_int32_t u_word; +typedef u_int u_word; #define WORDZE(w) ((w) == 0) #define ZEROWORD(w) (w) = 0 #define COPYWORD(w1,w2) (w2) = (w1) -#define GETWORD(w, i) (i) = ntohl(w) -#define PUTWORD(i, w) (w) = htonl(i) +#define GETWORD(w, i) (i) = (w) +#define PUTWORD(i, w) (w) = (i) #else -#define _WORD_HIGHPART 0 +#define _WORD_HIGHPART 0 /* XXX: assume Big Endian for now */ #define _WORD_LOWPART 1 -typedef struct _uword { u_int16_t val[2]; } u_word; +typedef struct _uword { u_short val[2]; } u_word; #define WORDZE(w) \ ((w.val[_WORD_HIGHPART] == 0) && (w.val[_WORD_LOWPART] == 0)) @@ -158,10 +156,10 @@ typedef struct _uword { u_int16_t val[2]; } u_word; (w2).val[_WORD_LOWPART] = (w1).val[_WORD_LOWPART]; \ } #define GETWORD(w, i) \ - (i) = (((u_int32_t)ntohs((w).val[_WORD_HIGHPART])) << 16) | ntohs((w).val[_WORD_LOWPART]) + (i) = (((u_int)(w).val[_WORD_HIGHPART]) << 16) | (w).val[_WORD_LOWPART] #define PUTWORD(i, w) \ - { (w).val[_WORD_HIGHPART] = htons((u_int16_t) ((i >> 16) & 0xffff)); \ - (w).val[_WORD_LOWPART] = htons((u_int16_t) (i & 0xffff)); \ + { (w).val[_WORD_HIGHPART] = (u_short) (((i) >> 16) & 0xffff); \ + (w).val[_WORD_LOWPART] = (u_short) (i & 0xffff); \ } #endif @@ -171,53 +169,53 @@ typedef struct _uword { u_int16_t val[2]; } u_word; */ struct rmp_raw { /* generic RMP packet */ - u_int8_t rmp_type; /* packet type */ - u_int8_t rmp_rawdata[RMPDATALEN-1]; + u_char rmp_type; /* packet type */ + u_char rmp_rawdata[RMPDATALEN-1]; }; struct rmp_boot_req { /* boot request */ - u_int8_t rmp_type; /* packet type (RMP_BOOT_REQ) */ - u_int8_t rmp_retcode; /* return code (0) */ - u_word rmp_seqno; /* sequence number (real time clock) */ - u_int16_t rmp_session; /* session id (normally 0) */ - u_int16_t rmp_version; /* protocol version (RMP_VERSION) */ - char rmp_machtype[RMP_MACHLEN]; /* machine type */ - u_int8_t rmp_flnmsize; /* length of rmp_flnm */ + u_char rmp_type; /* packet type (RMP_BOOT_REQ) */ + u_char rmp_retcode; /* return code (0) */ + u_word rmp_seqno; /* sequence number (real time clock) */ + u_short rmp_session; /* session id (normally 0) */ + u_short rmp_version; /* protocol version (RMP_VERSION) */ + char rmp_machtype[RMP_MACHLEN]; /* machine type */ + u_char rmp_flnmsize; /* length of rmp_flnm */ restofpkt rmp_flnm; /* name of file to be read */ }; struct rmp_boot_repl { /* boot reply */ - u_int8_t rmp_type; /* packet type (RMP_BOOT_REPL) */ - u_int8_t rmp_retcode; /* return code (normally 0) */ - u_word rmp_seqno; /* sequence number (from boot req) */ - u_int16_t rmp_session; /* session id (generated) */ - u_int16_t rmp_version; /* protocol version (RMP_VERSION) */ - u_int8_t rmp_flnmsize; /* length of rmp_flnm */ + u_char rmp_type; /* packet type (RMP_BOOT_REPL) */ + u_char rmp_retcode; /* return code (normally 0) */ + u_word rmp_seqno; /* sequence number (from boot req) */ + u_short rmp_session; /* session id (generated) */ + u_short rmp_version; /* protocol version (RMP_VERSION) */ + u_char rmp_flnmsize; /* length of rmp_flnm */ restofpkt rmp_flnm; /* name of file (from boot req) */ }; struct rmp_read_req { /* read request */ - u_int8_t rmp_type; /* packet type (RMP_READ_REQ) */ - u_int8_t rmp_retcode; /* return code (0) */ - u_word rmp_offset; /* file relative byte offset */ - u_int16_t rmp_session; /* session id (from boot repl) */ - u_int16_t rmp_size; /* max no of bytes to send */ + u_char rmp_type; /* packet type (RMP_READ_REQ) */ + u_char rmp_retcode; /* return code (0) */ + u_word rmp_offset; /* file relative byte offset */ + u_short rmp_session; /* session id (from boot repl) */ + u_short rmp_size; /* max no of bytes to send */ }; struct rmp_read_repl { /* read reply */ - u_int8_t rmp_type; /* packet type (RMP_READ_REPL) */ - u_int8_t rmp_retcode; /* return code (normally 0) */ - u_word rmp_offset; /* byte offset (from read req) */ - u_int16_t rmp_session; /* session id (from read req) */ + u_char rmp_type; /* packet type (RMP_READ_REPL) */ + u_char rmp_retcode; /* return code (normally 0) */ + u_word rmp_offset; /* byte offset (from read req) */ + u_short rmp_session; /* session id (from read req) */ restofpkt rmp_data; /* data (max size from read req) */ - u_int8_t rmp_unused; /* padding to 16-bit boundary */ + u_char rmp_unused; /* padding to 16-bit boundary */ }; struct rmp_boot_done { /* boot complete */ - u_int8_t rmp_type; /* packet type (RMP_BOOT_DONE) */ - u_int8_t rmp_retcode; /* return code (0) */ - u_word rmp_unused; /* not used (0) */ - u_int16_t rmp_session; /* session id (from read repl) */ + u_char rmp_type; /* packet type (RMP_BOOT_DONE) */ + u_char rmp_retcode; /* return code (0) */ + u_word rmp_unused; /* not used (0) */ + u_short rmp_session; /* session id (from read repl) */ }; struct rmp_packet { @@ -238,7 +236,7 @@ struct rmp_packet { */ #define r_type rmp_proto.rmp_raw.rmp_type -#define r_data rmp_proto.rmp_raw.rmp_rawdata +#define r_data rmp_proto.rmp_raw.rmp_data #define r_brq rmp_proto.rmp_brq #define r_brpl rmp_proto.rmp_brpl #define r_rrq rmp_proto.rmp_rrq diff --git a/libexec/rbootd/rmpproto.c b/libexec/rbootd/rmpproto.c index 12a6f5cb1777..d0a8d4a8086f 100644 --- a/libexec/rbootd/rmpproto.c +++ b/libexec/rbootd/rmpproto.c @@ -1,5 +1,3 @@ -/* $NetBSD: rmpproto.c,v 1.7 1996/02/01 21:27:46 mycroft Exp $ */ - /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -40,15 +38,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)rmpproto.c 8.1 (Berkeley) 6/4/93 + * @(#)rmpproto.c 8.1 (Berkeley) 6/4/93 * - * From: Utah Hdr: rmpproto.c 3.1 92/07/06 + * Utah $Hdr: rmpproto.c 3.1 92/07/06$ * Author: Jeff Forys, University of Utah CSS */ #ifndef lint -/*static char sccsid[] = "@(#)rmpproto.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$NetBSD: rmpproto.c,v 1.7 1996/02/01 21:27:46 mycroft Exp $"; +static char sccsid[] = "@(#)rmpproto.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ #include @@ -114,7 +111,7 @@ ProcessPacket(rconn, client) * of active connections, otherwise delete it since * an error was encountered. */ - if (ntohs(rmp->r_brq.rmp_session) == RMP_PROBESID) { + if (rmp->r_brq.rmp_session == RMP_PROBESID) { if (WORDZE(rmp->r_brq.rmp_seqno)) (void) SendServerID(rconnout); else @@ -180,7 +177,7 @@ SendServerID(rconn) { register struct rmp_packet *rpl; register char *src, *dst; - register u_int8_t *size; + register u_char *size; rpl = &rconn->rmp; /* cache ptr to RMP packet */ @@ -191,7 +188,7 @@ SendServerID(rconn) rpl->r_brpl.rmp_retcode = RMP_E_OKAY; ZEROWORD(rpl->r_brpl.rmp_seqno); rpl->r_brpl.rmp_session = 0; - rpl->r_brpl.rmp_version = htons(RMP_VERSION); + rpl->r_brpl.rmp_version = RMP_VERSION; size = &rpl->r_brpl.rmp_flnmsize; /* ptr to length of host name */ @@ -234,8 +231,7 @@ SendFileNo(req, rconn, filelist) { register struct rmp_packet *rpl; register char *src, *dst; - register u_int8_t *size; - register int i; + register u_char *size, i; GETWORD(req->r_brpl.rmp_seqno, i); /* SeqNo is really FileNo */ rpl = &rconn->rmp; /* cache ptr to RMP packet */ @@ -247,7 +243,7 @@ SendFileNo(req, rconn, filelist) PUTWORD(i, rpl->r_brpl.rmp_seqno); i--; rpl->r_brpl.rmp_session = 0; - rpl->r_brpl.rmp_version = htons(RMP_VERSION); + rpl->r_brpl.rmp_version = RMP_VERSION; size = &rpl->r_brpl.rmp_flnmsize; /* ptr to length of filename */ *size = 0; /* init length to zero */ @@ -300,7 +296,7 @@ SendBootRepl(req, rconn, filelist) RMPCONN *oldconn; register struct rmp_packet *rpl; register char *src, *dst1, *dst2; - register u_int8_t i; + register u_char i; /* * If another connection already exists, delete it since we @@ -319,8 +315,8 @@ SendBootRepl(req, rconn, filelist) */ rpl->r_brpl.rmp_type = RMP_BOOT_REPL; COPYWORD(req->r_brq.rmp_seqno, rpl->r_brpl.rmp_seqno); - rpl->r_brpl.rmp_session = htons(GenSessID()); - rpl->r_brpl.rmp_version = htons(RMP_VERSION); + rpl->r_brpl.rmp_session = GenSessID(); + rpl->r_brpl.rmp_version = RMP_VERSION; rpl->r_brpl.rmp_flnmsize = req->r_brq.rmp_flnmsize; /* @@ -402,7 +398,7 @@ int SendReadRepl(rconn) RMPCONN *rconn; { - int retval = 0; + int retval; RMPCONN *oldconn; register struct rmp_packet *rpl, *req; register int size = 0; @@ -432,9 +428,9 @@ SendReadRepl(rconn) /* * Make sure Session ID's match. */ - if (ntohs(req->r_rrq.rmp_session) != - ((rpl->r_type == RMP_BOOT_REPL)? ntohs(rpl->r_brpl.rmp_session): - ntohs(rpl->r_rrpl.rmp_session))) { + if (req->r_rrq.rmp_session != + ((rpl->r_type == RMP_BOOT_REPL)? rpl->r_brpl.rmp_session: + rpl->r_rrpl.rmp_session)) { syslog(LOG_ERR, "SendReadRepl: bad session id (%s)", EnetStr(rconn)); rpl->r_rrpl.rmp_retcode = RMP_E_BADSID; @@ -450,8 +446,8 @@ SendReadRepl(rconn) * to work. This is necessary for bpfwrite() on machines * with MCLBYTES less than 1514. */ - if (ntohs(req->r_rrq.rmp_size) > RMPREADDATA) - req->r_rrq.rmp_size = htons(RMPREADDATA); + if (req->r_rrq.rmp_size > RMPREADDATA) + req->r_rrq.rmp_size = RMPREADDATA; /* * Position read head on file according to info in request packet. @@ -469,7 +465,7 @@ SendReadRepl(rconn) * Read data directly into reply packet. */ if ((size = read(oldconn->bootfd, &rpl->r_rrpl.rmp_data, - (int) ntohs(req->r_rrq.rmp_size))) <= 0) { + (int) req->r_rrq.rmp_size)) <= 0) { if (size < 0) { syslog(LOG_ERR, "SendReadRepl: read: %m (%s)", EnetStr(rconn)); @@ -537,9 +533,9 @@ BootDone(rconn) /* * Make sure Session ID's match. */ - if (ntohs(rconn->rmp.r_rrq.rmp_session) != - ((rpl->r_type == RMP_BOOT_REPL)? ntohs(rpl->r_brpl.rmp_session): - ntohs(rpl->r_rrpl.rmp_session))) { + if (rconn->rmp.r_rrq.rmp_session != + ((rpl->r_type == RMP_BOOT_REPL)? rpl->r_brpl.rmp_session: + rpl->r_rrpl.rmp_session)) { syslog(LOG_ERR, "BootDone: bad session id (%s)", EnetStr(rconn)); return(0); @@ -574,18 +570,13 @@ SendPacket(rconn) */ bcopy((char *)&rconn->rmp.hp_hdr.saddr[0], (char *)&rconn->rmp.hp_hdr.daddr[0], RMP_ADDRLEN); -#ifdef __FreeBSD__ - /* BPF (incorrectly) wants this in host order. */ rconn->rmp.hp_hdr.len = rconn->rmplen - sizeof(struct hp_hdr); -#else - rconn->rmp.hp_hdr.len = htons(rconn->rmplen - sizeof(struct hp_hdr)); -#endif /* * Reverse 802.2/HP Extended Source & Destination Access Pts. */ - rconn->rmp.hp_llc.dxsap = htons(HPEXT_SXSAP); - rconn->rmp.hp_llc.sxsap = htons(HPEXT_DXSAP); + rconn->rmp.hp_llc.dxsap = HPEXT_SXSAP; + rconn->rmp.hp_llc.sxsap = HPEXT_DXSAP; /* * Last time this connection was active. diff --git a/libexec/rbootd/utils.c b/libexec/rbootd/utils.c index 5d37a25bd9ea..58ead7c7144b 100644 --- a/libexec/rbootd/utils.c +++ b/libexec/rbootd/utils.c @@ -1,5 +1,3 @@ -/* $NetBSD: utils.c,v 1.6 1995/11/14 08:41:47 thorpej Exp $ */ - /* * Copyright (c) 1988, 1992 The University of Utah and the Center * for Software Science (CSS). @@ -40,18 +38,18 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * from: @(#)utils.c 8.1 (Berkeley) 6/4/93 + * @(#)utils.c 8.2 (Berkeley) 2/22/94 * - * From: Utah Hdr: utils.c 3.1 92/07/06 + * Utah $Hdr: utils.c 3.1 92/07/06$ * Author: Jeff Forys, University of Utah CSS */ #ifndef lint -/*static char sccsid[] = "@(#)utils.c 8.1 (Berkeley) 6/4/93";*/ -static char rcsid[] = "$NetBSD: utils.c,v 1.6 1995/11/14 08:41:47 thorpej Exp $"; +static char sccsid[] = "@(#)utils.c 8.2 (Berkeley) 2/22/94"; #endif /* not lint */ #include +#include #include #include @@ -87,7 +85,7 @@ DispPkt(rconn, direct) struct tm *tmp; register struct rmp_packet *rmp; int i, omask; - u_int32_t t; + u_int t; /* * Since we will be working with RmpConns as well as DbgFp, we @@ -115,11 +113,11 @@ DispPkt(rconn, direct) /* display IEEE 802.2 Logical Link Control header */ (void) fprintf(DbgFp, "\t802.2 LLC: DSAP:%x SSAP:%x CTRL:%x\n", - rmp->hp_llc.dsap, rmp->hp_llc.ssap, ntohs(rmp->hp_llc.cntrl)); + rmp->hp_llc.dsap, rmp->hp_llc.ssap, rmp->hp_llc.cntrl); /* display HP extensions to 802.2 Logical Link Control header */ (void) fprintf(DbgFp, "\tHP Ext: DXSAP:%x SXSAP:%x\n", - ntohs(rmp->hp_llc.dxsap), ntohs(rmp->hp_llc.sxsap)); + rmp->hp_llc.dxsap, rmp->hp_llc.sxsap); /* * Display information about RMP packet using type field to @@ -129,7 +127,7 @@ DispPkt(rconn, direct) case RMP_BOOT_REQ: /* boot request */ (void) fprintf(DbgFp, "\tBoot Request:"); GETWORD(rmp->r_brq.rmp_seqno, t); - if (ntohs(rmp->r_brq.rmp_session) == RMP_PROBESID) { + if (rmp->r_brq.rmp_session == RMP_PROBESID) { if (WORDZE(rmp->r_brq.rmp_seqno)) fputs(" (Send Server ID)", DbgFp); else @@ -137,8 +135,8 @@ DispPkt(rconn, direct) } (void) fputc('\n', DbgFp); (void) fprintf(DbgFp, BootFmt, rmp->r_brq.rmp_retcode, - t, ntohs(rmp->r_brq.rmp_session), - ntohs(rmp->r_brq.rmp_version)); + t, rmp->r_brq.rmp_session, + rmp->r_brq.rmp_version); (void) fprintf(DbgFp, "\n\t\tMachine Type: "); for (i = 0; i < RMP_MACHLEN; i++) (void) fputc(rmp->r_brq.rmp_machtype[i], DbgFp); @@ -148,23 +146,23 @@ DispPkt(rconn, direct) fprintf(DbgFp, "\tBoot Reply:\n"); GETWORD(rmp->r_brpl.rmp_seqno, t); (void) fprintf(DbgFp, BootFmt, rmp->r_brpl.rmp_retcode, - t, ntohs(rmp->r_brpl.rmp_session), - ntohs(rmp->r_brpl.rmp_version)); + t, rmp->r_brpl.rmp_session, + rmp->r_brpl.rmp_version); DspFlnm(rmp->r_brpl.rmp_flnmsize,&rmp->r_brpl.rmp_flnm); break; case RMP_READ_REQ: /* read request */ (void) fprintf(DbgFp, "\tRead Request:\n"); GETWORD(rmp->r_rrq.rmp_offset, t); (void) fprintf(DbgFp, ReadFmt, rmp->r_rrq.rmp_retcode, - t, ntohs(rmp->r_rrq.rmp_session)); + t, rmp->r_rrq.rmp_session); (void) fprintf(DbgFp, "\t\tNoOfBytes: %u\n", - ntohs(rmp->r_rrq.rmp_size)); + rmp->r_rrq.rmp_size); break; case RMP_READ_REPL: /* read reply */ (void) fprintf(DbgFp, "\tRead Reply:\n"); GETWORD(rmp->r_rrpl.rmp_offset, t); (void) fprintf(DbgFp, ReadFmt, rmp->r_rrpl.rmp_retcode, - t, ntohs(rmp->r_rrpl.rmp_session)); + t, rmp->r_rrpl.rmp_session); (void) fprintf(DbgFp, "\t\tNoOfBytesSent: %d\n", rconn->rmplen - RMPREADSIZE(0)); break; @@ -172,7 +170,7 @@ DispPkt(rconn, direct) (void) fprintf(DbgFp, "\tBoot Complete:\n"); (void) fprintf(DbgFp, "\t\tRetCode:%u SessID:%x\n", rmp->r_done.rmp_retcode, - ntohs(rmp->r_done.rmp_session)); + rmp->r_done.rmp_session); break; default: /* ??? */ (void) fprintf(DbgFp, "\tUnknown Type:(%d)\n", @@ -204,30 +202,32 @@ DispPkt(rconn, direct) ** Warnings: ** - The return value points to a static buffer; it must ** be copied if it's to be saved. +** - For speed, we assume a u_char consists of 8 bits. */ char * GetEtherAddr(addr) - u_int8_t *addr; + u_char *addr; { static char Hex[] = "0123456789abcdef"; static char etherstr[RMP_ADDRLEN*3]; register int i; - register char *cp; + register char *cp1, *cp2; /* * For each byte in `addr', convert it to ":". * The last byte does not get a trailing `:' appended. */ i = 0; - cp = etherstr; + cp1 = (char *)addr; + cp2 = etherstr; for(;;) { - *cp++ = Hex[*addr >> 4 & 0xf]; - *cp++ = Hex[*addr++ & 0xf]; + *cp2++ = Hex[*cp1 >> 4 & 0xf]; + *cp2++ = Hex[*cp1++ & 0xf]; if (++i == RMP_ADDRLEN) break; - *cp++ = ':'; + *cp2++ = ':'; } - *cp = '\0'; + *cp2 = '\0'; return(etherstr); } @@ -253,7 +253,7 @@ DspFlnm(size, flnm) { register int i; - (void) fprintf(DbgFp, "\n\t\tFile Name (%u): <", size); + (void) fprintf(DbgFp, "\n\t\tFile Name (%d): <", size); for (i = 0; i < size; i++) (void) fputc(*flnm++, DbgFp); (void) fputs(">\n", DbgFp); @@ -275,7 +275,7 @@ DspFlnm(size, flnm) */ CLIENT * NewClient(addr) - u_int8_t *addr; + u_char *addr; { CLIENT *ctmp; From fd03752a5d69f81b7bc4b82aa0a41909f4ee42fa Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Sun, 3 Aug 1997 12:17:39 +0000 Subject: [PATCH 2/2] Import Matt's if_de driver 970703 release. This (apparently) supports some newer Cogent (Adaptec) cards and has some other internal changes. --- sys/pci/dc21040reg.h | 5 +- sys/pci/if_de.c | 836 ++++++++++++++++++++++++++++--------------- sys/pci/if_devar.h | 91 ++++- 3 files changed, 636 insertions(+), 296 deletions(-) diff --git a/sys/pci/dc21040reg.h b/sys/pci/dc21040reg.h index bbe5fa2beda1..ec274709ccaf 100644 --- a/sys/pci/dc21040reg.h +++ b/sys/pci/dc21040reg.h @@ -21,7 +21,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: dc21040.h,v 1.23 1997/03/15 17:28:19 thomas Exp $ + * $Id: dc21040reg.h,v 1.24 1997/05/16 19:47:09 thomas Exp $ */ #if !defined(_DC21040_H) @@ -367,7 +367,8 @@ typedef struct { #define TULIP_OUI_COGENT_0 0x00 #define TULIP_OUI_COGENT_1 0x00 #define TULIP_OUI_COGENT_2 0x92 -#define TULIP_COGENT_EM100_ID 0x12 +#define TULIP_COGENT_EM100TX_ID 0x12 +#define TULIP_COGENT_EM100FX_ID 0x15 /* diff --git a/sys/pci/if_de.c b/sys/pci/if_de.c index 87479da748ca..239febcc274e 100644 --- a/sys/pci/if_de.c +++ b/sys/pci/if_de.c @@ -21,7 +21,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_de.c,v 1.86 1997/05/13 15:03:11 thomas Exp $ + * $Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp $ * */ @@ -149,6 +149,10 @@ #define TULIP_DEBUG #endif +#if 0 +#define TULIP_PERFSTATS +#endif + #if 0 #define TULIP_USE_SOFTINTR #endif @@ -167,7 +171,10 @@ static tulip_intrfunc_t tulip_intr_shared(void *arg); static tulip_intrfunc_t tulip_intr_normal(void *arg); static void tulip_init(tulip_softc_t * const sc); static void tulip_reset(tulip_softc_t * const sc); +static ifnet_ret_t tulip_ifstart_one(struct ifnet *ifp); static ifnet_ret_t tulip_ifstart(struct ifnet *ifp); +static struct mbuf *tulip_txput(tulip_softc_t * const sc, struct mbuf *m); +static void tulip_txput_setup(tulip_softc_t * const sc); static void tulip_rx_intr(tulip_softc_t * const sc); static void tulip_addr_filter(tulip_softc_t * const sc); static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno); @@ -188,9 +195,13 @@ tulip_timeout_callback( tulip_softc_t * const sc = arg; tulip_spl_t s = TULIP_RAISESPL(); + TULIP_PERFSTART(timeout) + sc->tulip_flags &= ~TULIP_TIMEOUTPENDING; sc->tulip_probe_timeout -= 1000 / TULIP_HZ; (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER); + + TULIP_PERFEND(timeout); TULIP_RESTORESPL(s); } @@ -236,7 +247,7 @@ tulip_txprobe( /* * Before we are sure this is the right media we need * to send a small packet to make sure there's carrier. - * Strangely, BNC and AUI will 'see" receive data if + * Strangely, BNC and AUI will "see" receive data if * either is connected so the transmit is the only way * to verify the connectivity. */ @@ -257,10 +268,12 @@ tulip_txprobe( * send it! */ sc->tulip_cmdmode |= TULIP_CMD_TXRUN; + sc->tulip_intrmask |= TULIP_STS_TXINTR; sc->tulip_flags |= TULIP_TXPROBE_ACTIVE; TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); - IF_PREPEND(&sc->tulip_if.if_snd, m); - tulip_ifstart(&sc->tulip_if); + TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); + if ((m = tulip_txput(sc, m)) != NULL) + m_freem(m); sc->tulip_probe.probe_txprobes++; return 1; } @@ -1661,26 +1674,38 @@ tulip_21140_cogent_em100_media_probe( tulip_softc_t * const sc) { tulip_media_info_t *mip = sc->tulip_mediainfo; + u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command); sc->tulip_gpinit = TULIP_GP_EM100_PINS; sc->tulip_gpdata = TULIP_GP_EM100_INIT; TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS); TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT); - TULIP_CSR_WRITE(sc, csr_command, - TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | - TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); - TULIP_CSR_WRITE(sc, csr_command, - TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); - sc->tulip_media = TULIP_MEDIA_100BASETX; - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, + cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE; + cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER); + if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) { + TULIP_CSR_WRITE(sc, csr_command, cmdmode); + sc->tulip_media = TULIP_MEDIA_100BASEFX; + + tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX, + TULIP_GP_EM100_INIT, + TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION); + tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD, + TULIP_GP_EM100_INIT, + TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION + |TULIP_CMD_FULLDUPLEX); + } else { + TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER); + sc->tulip_media = TULIP_MEDIA_100BASETX; + tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, TULIP_GP_EM100_INIT, TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION |TULIP_CMD_SCRAMBLER); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, + tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, TULIP_GP_EM100_INIT, TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); + } } static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = { @@ -1752,8 +1777,8 @@ static void tulip_2114x_media_probe( tulip_softc_t * const sc) { - sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE - |TULIP_CMD_BACKOFFCTR; + sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE + |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72; } static const tulip_boardsw_t tulip_2114x_isv_boardsw = { @@ -1810,7 +1835,7 @@ static void tulip_srom_read( tulip_softc_t * const sc) { - int idx; + unsigned idx; const unsigned bitwidth = SROM_BITWIDTH; const unsigned cmdmask = (SROMCMD_RD << bitwidth); const unsigned msb = 1 << (bitwidth + 3 - 1); @@ -1964,7 +1989,7 @@ tulip_mii_writereg( #define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF) #define tulip_srom_crcok(databuf) ( \ - ((tulip_crc32(databuf, 126) & 0xFFFF) ^ 0xFFFF)== \ + ((tulip_crc32(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \ ((databuf)[126] | ((databuf)[127] << 8))) static unsigned @@ -2105,9 +2130,9 @@ tulip_identify_smc_nic( strcpy(&sc->tulip_boardid[4], "9332DST "); sc->tulip_boardsw = &tulip_21140_smc9332_boardsw; } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) { - strcpy(&sc->tulip_boardid[4], "9332BDT "); - } else { strcpy(&sc->tulip_boardid[4], "9334BDT "); + } else { + strcpy(&sc->tulip_boardid[4], "9332BDT "); } return; } @@ -2144,8 +2169,13 @@ tulip_identify_cogent_nic( { strcpy(sc->tulip_boardid, "Cogent "); if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) { - if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100_ID) + if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) { + strcat(sc->tulip_boardid, "EM100FX "); sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; + } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) { + strcat(sc->tulip_boardid, "EM100FX "); + sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; + } /* * Magic number (0x24001109U) is the SubVendor (0x2400) and * SubDevId (0x1109) for the ANA6944TX (EM440TX). @@ -2156,6 +2186,7 @@ tulip_identify_cogent_nic( * Cogent (Adaptec) is still mapping all INTs to INTA of * first 21140. Dumb! Dumb! */ + strcat(sc->tulip_boardid, "EM440TX "); sc->tulip_features |= TULIP_HAVE_SHAREDINTR; } } else if (sc->tulip_chipid == TULIP_21040) { @@ -2223,7 +2254,7 @@ static int tulip_srom_decode( tulip_softc_t * const sc) { - int idx1, idx2, idx3; + unsigned idx1, idx2, idx3; const tulip_srom_header_t *shp = (tulip_srom_header_t *) &sc->tulip_rombuf[0]; const tulip_srom_adapter_info_t *saip = (tulip_srom_adapter_info_t *) (shp + 1); @@ -2595,7 +2626,7 @@ static int tulip_read_macaddr( tulip_softc_t * const sc) { - int cksum, rom_cksum, idx; + unsigned cksum, rom_cksum, idx; u_int32_t csr; unsigned char tmpbuf[8]; static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA }; @@ -2898,12 +2929,13 @@ tulip_addr_filter( struct ether_multi *enm; sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI); - sc->tulip_flags |= TULIP_WANTSETUP; + sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART; sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; #if defined(IFF_ALLMULTI) sc->tulip_if.if_flags &= ~IFF_ALLMULTI; #endif + sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */ if (sc->tulip_multicnt > 14) { u_int32_t *sp = sc->tulip_setupdata; unsigned hash; @@ -3083,7 +3115,8 @@ tulip_reset( sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED - |TULIP_STS_TXBABBLE|TULIP_STS_LINKFAIL|TULIP_STS_RXSTOPPED; + |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE|TULIP_STS_LINKFAIL + |TULIP_STS_RXSTOPPED; if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0) (*sc->tulip_boardsw->bd_media_select)(sc); @@ -3114,6 +3147,7 @@ tulip_init( if (sc->tulip_if.if_flags & IFF_PROMISC) { sc->tulip_flags |= TULIP_PROMISC; sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS; + sc->tulip_intrmask |= TULIP_STS_TXINTR; } else { sc->tulip_flags &= ~TULIP_PROMISC; sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS; @@ -3135,7 +3169,8 @@ tulip_init( } TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); - tulip_ifstart(&sc->tulip_if); + if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) + tulip_txput_setup(sc); } else { sc->tulip_if.if_flags &= ~IFF_RUNNING; tulip_reset(sc); @@ -3146,6 +3181,7 @@ static void tulip_rx_intr( tulip_softc_t * const sc) { + TULIP_PERFSTART(rxintr) tulip_ringinfo_t * const ri = &sc->tulip_rxinfo; struct ifnet * const ifp = &sc->tulip_if; int fillok = 1; @@ -3154,6 +3190,7 @@ tulip_rx_intr( #endif for (;;) { + TULIP_PERFSTART(rxget) struct ether_header eh; tulip_desc_t *eop = ri->ri_nextin; int total_len = 0, last_offset = 0; @@ -3201,6 +3238,8 @@ tulip_rx_intr( sc->tulip_dbg.dbg_rxintrs++; sc->tulip_dbg.dbg_rxpktsperintr[cnt]++; #endif + TULIP_PERFEND(rxget); + TULIP_PERFEND(rxintr); return; } total_len++; @@ -3361,6 +3400,7 @@ tulip_rx_intr( #if defined(TULIP_DEBUG) sc->tulip_dbg.dbg_rxlowbufs++; #endif + TULIP_PERFEND(rxget); continue; } /* @@ -3380,28 +3420,34 @@ tulip_rx_intr( if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET) sc->tulip_flags &= ~TULIP_RXBUFSLOW; + TULIP_PERFEND(rxget); } #if defined(TULIP_DEBUG) sc->tulip_dbg.dbg_rxintrs++; sc->tulip_dbg.dbg_rxpktsperintr[cnt]++; #endif + TULIP_PERFEND(rxintr); } static int tulip_tx_intr( tulip_softc_t * const sc) { + TULIP_PERFSTART(txintr) tulip_ringinfo_t * const ri = &sc->tulip_txinfo; struct mbuf *m; int xmits = 0; + int descs = 0; while (ri->ri_free < ri->ri_max) { + u_int32_t d_flag; if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER) break; - if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxLASTSEG) { - if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxSETUPPKT) { + d_flag = ri->ri_nextin->d_flag; + if (d_flag & TULIP_DFLAG_TxLASTSEG) { + if (d_flag & TULIP_DFLAG_TxSETUPPKT) { /* * We've just finished processing a setup packet. * Mark that we finished it. If there's not @@ -3421,16 +3467,20 @@ tulip_tx_intr( TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); } } else { - tulip_desc_t * const nextin = ri->ri_nextin; + const u_int32_t d_status = ri->ri_nextin->d_status; IF_DEQUEUE(&sc->tulip_txq, m); +#if NBPFILTER > 0 + if (sc->tulip_bpf != NULL) + TULIP_BPF_MTAP(sc, m); +#endif m_freem(m); if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK; - if (nextin->d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) { + if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) { #if defined(TULIP_DEBUG) - if (nextin->d_status & TULIP_DSTS_TxNOCARR) + if (d_status & TULIP_DSTS_TxNOCARR) sc->tulip_dbg.dbg_txprobe_nocarr++; - if (nextin->d_status & TULIP_DSTS_TxEXCCOLL) + if (d_status & TULIP_DSTS_TxEXCCOLL) sc->tulip_dbg.dbg_txprobe_exccoll++; #endif event = TULIP_MEDIAPOLL_TXPROBE_FAILED; @@ -3442,26 +3492,30 @@ tulip_tx_intr( break; } else { xmits++; - if (nextin->d_status & TULIP_DSTS_ERRSUM) { + if (d_status & TULIP_DSTS_ERRSUM) { sc->tulip_if.if_oerrors++; - if (nextin->d_status & TULIP_DSTS_TxEXCCOLL) + if (d_status & TULIP_DSTS_TxEXCCOLL) sc->tulip_dot3stats.dot3StatsExcessiveCollisions++; - if (nextin->d_status & TULIP_DSTS_TxLATECOLL) + if (d_status & TULIP_DSTS_TxLATECOLL) sc->tulip_dot3stats.dot3StatsLateCollisions++; - if (nextin->d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS)) + if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS)) sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++; - if (nextin->d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE)) + if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE)) sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++; + if (d_status & TULIP_DSTS_TxUNDERFLOW) + sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++; + if (d_status & TULIP_DSTS_TxBABBLE) + sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++; } else { u_int32_t collisions = - (nextin->d_status & TULIP_DSTS_TxCOLLMASK) + (d_status & TULIP_DSTS_TxCOLLMASK) >> TULIP_DSTS_V_TxCOLLCNT; sc->tulip_if.if_collisions += collisions; if (collisions == 1) sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++; else if (collisions > 1) sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++; - else if (nextin->d_status & TULIP_DSTS_TxDEFERRED) + else if (d_status & TULIP_DSTS_TxDEFERRED) sc->tulip_dot3stats.dot3StatsDeferredTransmissions++; /* * SQE is only valid for 10baseT/BNC/AUI when not @@ -3469,7 +3523,7 @@ tulip_tx_intr( * test, the corresponding bit in tulip_flags needs to * set as well to get us to count SQE Test Errors. */ - if (nextin->d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags) + if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags) sc->tulip_dot3stats.dot3StatsSQETestErrors++; } } @@ -3480,6 +3534,7 @@ tulip_tx_intr( ri->ri_nextin = ri->ri_first; ri->ri_free++; + descs++; if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) sc->tulip_if.if_flags &= ~IFF_OACTIVE; } @@ -3492,7 +3547,8 @@ tulip_tx_intr( else if (xmits > 0) sc->tulip_txtimer = TULIP_TXTIMER; sc->tulip_if.if_opackets += xmits; - return xmits; + TULIP_PERFEND(txintr); + return descs; } static void @@ -3502,12 +3558,23 @@ tulip_print_abnormal_interrupt( { const char * const *msgp = tulip_status_bits; const char *sep; + u_int32_t mask; + const char thrsh[] = "72|128\0\0\096|256\0\0\0128|512\0\0160|1024\0"; csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1; printf(TULIP_PRINTF_FMT ": abnormal interrupt:", TULIP_PRINTF_ARGS); - for (sep = " "; csr != 0; csr >>= 1, msgp++) { - if ((csr & 1) && *msgp != NULL) { + for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) { + if ((csr & mask) && *msgp != NULL) { printf("%s%s", sep, *msgp); + if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) { + sc->tulip_flags &= ~TULIP_NEWTXTHRESH; + if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) { + printf(" (switching to store-and-forward mode)"); + } else { + printf(" (raising TX threshold to %s)", + &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]); + } + } sep = ", "; } } @@ -3519,6 +3586,7 @@ tulip_intr_handler( tulip_softc_t * const sc, int *progress_p) { + TULIP_PERFSTART(intr) u_int32_t csr; while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) { @@ -3582,6 +3650,15 @@ tulip_intr_handler( if (csr & TULIP_STS_ABNRMLINTR) { u_int32_t tmp = csr & sc->tulip_intrmask & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR); + if (csr & TULIP_STS_TXUNDERFLOW) { + if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) { + sc->tulip_cmdmode += TULIP_CMD_THRSHLD96; + sc->tulip_flags |= TULIP_NEWTXTHRESH; + } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) { + sc->tulip_cmdmode |= TULIP_CMD_STOREFWD; + sc->tulip_flags |= TULIP_NEWTXTHRESH; + } + } if (sc->tulip_flags & TULIP_NOMESSAGES) { sc->tulip_statusbits |= tmp; } else { @@ -3590,7 +3667,7 @@ tulip_intr_handler( } TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); } - if (sc->tulip_txinfo.ri_free < sc->tulip_txinfo.ri_max) { + if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) { tulip_tx_intr(sc); if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) tulip_ifstart(&sc->tulip_if); @@ -3600,6 +3677,7 @@ tulip_intr_handler( tulip_reset(sc); tulip_init(sc); } + TULIP_PERFEND(intr); } #if defined(TULIP_USE_SOFTINTR) @@ -3746,6 +3824,336 @@ tulip_intr_normal( return progress; #endif } + +static struct mbuf * +tulip_mbuf_compress( + struct mbuf *m) +{ + struct mbuf *m0; +#if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET) + MGETHDR(m0, M_DONTWAIT, MT_DATA); + if (m0 != NULL) { + if (m->m_pkthdr.len > MHLEN) { + MCLGET(m0, M_DONTWAIT); + if ((m0->m_flags & M_EXT) == 0) { + m_freem(m); + m_freem(m0); + return NULL; + } + } + m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t)); + m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; + } +#else + int mlen = MHLEN; + int len = m->m_pkthdr.len; + struct mbuf **mp = &m0; + + while (len > 0) { + if (mlen == MHLEN) { + MGETHDR(*mp, M_DONTWAIT, MT_DATA); + } else { + MGET(*mp, M_DONTWAIT, MT_DATA); + } + if (*mp == NULL) { + m_freem(m0); + m0 = NULL; + break; + } + if (len > MLEN) { + MCLGET(*mp, M_DONTWAIT); + if (((*mp)->m_flags & M_EXT) == 0) { + m_freem(m0); + m0 = NULL; + break; + } + (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES; + } else { + (*mp)->m_len = len <= mlen ? len : mlen; + } + m_copydata(m, m->m_pkthdr.len - len, + (*mp)->m_len, mtod((*mp), caddr_t)); + len -= (*mp)->m_len; + mp = &(*mp)->m_next; + mlen = MLEN; + } +#endif + m_freem(m); + return m0; +} + +static struct mbuf * +tulip_txput( + tulip_softc_t * const sc, + struct mbuf *m) +{ + TULIP_PERFSTART(txput) + tulip_ringinfo_t * const ri = &sc->tulip_txinfo; + tulip_desc_t *eop, *nextout; + int segcnt, free; + u_int32_t d_status; + struct mbuf *m0; + +#if defined(TULIP_DEBUG) + if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { + printf(TULIP_PRINTF_FMT ": txput%s: tx not running\n", + TULIP_PRINTF_ARGS, + (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : ""); + sc->tulip_flags |= TULIP_WANTTXSTART; + goto finish; + } +#endif + + /* + * Now we try to fill in our transmit descriptors. This is + * a bit reminiscent of going on the Ark two by two + * since each descriptor for the TULIP can describe + * two buffers. So we advance through packet filling + * each of the two entries at a time to to fill each + * descriptor. Clear the first and last segment bits + * in each descriptor (actually just clear everything + * but the end-of-ring or chain bits) to make sure + * we don't get messed up by previously sent packets. + * + * We may fail to put the entire packet on the ring if + * there is either not enough ring entries free or if the + * packet has more than MAX_TXSEG segments. In the former + * case we will just wait for the ring to empty. In the + * latter case we have to recopy. + */ + again: + d_status = 0; + eop = nextout = ri->ri_nextout; + m0 = m; + segcnt = 0; + free = ri->ri_free; + do { + int len = m0->m_len; + caddr_t addr = mtod(m0, caddr_t); + unsigned clsize = CLBYTES - (((u_long) addr) & (CLBYTES-1)); + + while (len > 0) { + unsigned slen = min(len, clsize); +#ifdef BIG_PACKET + int partial = 0; + if (slen >= 2048) + slen = 2040, partial = 1; +#endif + segcnt++; + if (segcnt > TULIP_MAX_TXSEG) { + /* + * The packet exceeds the number of transmit buffer + * entries that we can use for one packet, so we have + * recopy it into one mbuf and then try again. + */ + m = tulip_mbuf_compress(m); + if (m == NULL) + goto finish; + goto again; + } + if (segcnt & 1) { + if (--free == 0) { + /* + * See if there's any unclaimed space in the + * transmit ring. + */ + if ((free += tulip_tx_intr(sc)) == 0) { + /* + * There's no more room but since nothing + * has been committed at this point, just + * show output is active, put back the + * mbuf and return. + */ + sc->tulip_flags |= TULIP_WANTTXSTART; + goto finish; + } + } + eop = nextout; + if (++nextout == ri->ri_last) + nextout = ri->ri_first; + eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; + eop->d_status = d_status; + eop->d_addr1 = TULIP_KVATOPHYS(sc, addr); + eop->d_length1 = slen; + } else { + /* + * Fill in second half of descriptor + */ + eop->d_addr2 = TULIP_KVATOPHYS(sc, addr); + eop->d_length2 = slen; + } + d_status = TULIP_DSTS_OWNER; + len -= slen; + addr += slen; +#ifdef BIG_PACKET + if (partial) + continue; +#endif + clsize = CLBYTES; + } + } while ((m0 = m0->m_next) != NULL); + + + /* + * The descriptors have been filled in. Now get ready + * to transmit. + */ + IF_ENQUEUE(&sc->tulip_txq, m); + m = NULL; + + /* + * Make sure the next descriptor after this packet is owned + * by us since it may have been set up above if we ran out + * of room in the ring. + */ + nextout->d_status = 0; + + /* + * If we only used the first segment of the last descriptor, + * make sure the second segment will not be used. + */ + if (segcnt & 1) { + eop->d_addr2 = 0; + eop->d_length2 = 0; + } + + /* + * Mark the last and first segments, indicate we want a transmit + * complete interrupt, and tell it to transmit! + */ + eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; + + /* + * Note that ri->ri_nextout is still the start of the packet + * and until we set the OWNER bit, we can still back out of + * everything we have done. + */ + ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG; + ri->ri_nextout->d_status = TULIP_DSTS_OWNER; + + TULIP_CSR_WRITE(sc, csr_txpoll, 1); + + /* + * This advances the ring for us. + */ + ri->ri_nextout = nextout; + ri->ri_free = free; + + TULIP_PERFEND(txput); + + if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { + sc->tulip_if.if_flags |= IFF_OACTIVE; + TULIP_PERFEND(txput); + return NULL; + } + + /* + * switch back to the single queueing ifstart. + */ + sc->tulip_flags &= ~TULIP_WANTTXSTART; + sc->tulip_if.if_start = tulip_ifstart_one; + if (sc->tulip_txtimer == 0) + sc->tulip_txtimer = TULIP_TXTIMER; + + /* + * If we want a txstart, there must be not enough space in the + * transmit ring. So we want to enable transmit done interrupts + * so we can immediately reclaim some space. When the transmit + * interrupt is posted, the interrupt handler will call tx_intr + * to reclaim space and then txstart (since WANTTXSTART is set). + * txstart will move the packet into the transmit ring and clear + * WANTTXSTART thereby causing TXINTR to be cleared. + */ + finish: + if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) { + sc->tulip_if.if_flags |= IFF_OACTIVE; + sc->tulip_if.if_start = tulip_ifstart; + if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { + sc->tulip_intrmask |= TULIP_STS_TXINTR; + TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); + } + } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) { + if (sc->tulip_intrmask & TULIP_STS_TXINTR) { + sc->tulip_intrmask &= ~TULIP_STS_TXINTR; + TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); + } + } + TULIP_PERFEND(txput); + return m; +} + +static void +tulip_txput_setup( + tulip_softc_t * const sc) +{ + tulip_ringinfo_t * const ri = &sc->tulip_txinfo; + tulip_desc_t *nextout; + + /* + * We will transmit, at most, one setup packet per call to ifstart. + */ + +#if defined(TULIP_DEBUG) + if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { + printf(TULIP_PRINTF_FMT ": txput_setup: tx not running\n", + TULIP_PRINTF_ARGS); + sc->tulip_flags |= TULIP_WANTTXSTART; + sc->tulip_if.if_start = tulip_ifstart; + return; + } +#endif + /* + * Try to reclaim some free descriptors.. + */ + if (ri->ri_free < 2) + tulip_tx_intr(sc); + if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { + sc->tulip_flags |= TULIP_WANTTXSTART; + sc->tulip_if.if_start = tulip_ifstart; + return; + } + bcopy(sc->tulip_setupdata, sc->tulip_setupbuf, + sizeof(sc->tulip_setupbuf)); + /* + * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is + * set and DOINGSETUP is clear doing an XOR of the two will DTRT. + */ + sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP; + ri->ri_free--; + nextout = ri->ri_nextout; + nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; + nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG + |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; + if (sc->tulip_flags & TULIP_WANTHASHPERFECT) + nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; + else if (sc->tulip_flags & TULIP_WANTHASHONLY) + nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT; + + nextout->d_length1 = sizeof(sc->tulip_setupbuf); + nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf); + nextout->d_length2 = 0; + nextout->d_addr2 = 0; + + /* + * Advance the ring for the next transmit packet. + */ + if (++ri->ri_nextout == ri->ri_last) + ri->ri_nextout = ri->ri_first; + + /* + * Make sure the next descriptor is owned by us since it + * may have been set up above if we ran out of room in the + * ring. + */ + ri->ri_nextout->d_status = 0; + nextout->d_status = TULIP_DSTS_OWNER; + TULIP_CSR_WRITE(sc, csr_txpoll, 1); + if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { + sc->tulip_intrmask |= TULIP_STS_TXINTR; + TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); + } +} + /* * This routine is entered at splnet() (splsoftnet() on NetBSD) @@ -3754,10 +4162,11 @@ tulip_intr_normal( */ static int tulip_ifioctl( - struct ifnet * const ifp, + struct ifnet * ifp, ioctl_cmd_t cmd, caddr_t data) { + TULIP_PERFSTART(ifioctl) tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); struct ifaddr *ifa = (struct ifaddr *)data; struct ifreq *ifr = (struct ifreq *) data; @@ -3841,7 +4250,7 @@ tulip_ifioctl( } } if (flags) - printf(TULIP_PRINTF_FMT ": ignored invalid media request\n"); + printf(TULIP_PRINTF_FMT ": ignored invalid media request\n", TULIP_PRINTF_ARGS); } #endif tulip_init(sc); @@ -3918,255 +4327,56 @@ tulip_ifioctl( } TULIP_RESTORESPL(s); + TULIP_PERFEND(ifioctl); return error; } /* - * This routine gets called at device spl (from ether_output). This might + * These routines gets called at device spl (from ether_output). This might * pose a problem for TULIP_USE_SOFTINTR if ether_output is called at * device spl from another driver. */ + static ifnet_ret_t tulip_ifstart( struct ifnet * const ifp) { + TULIP_PERFSTART(ifstart) tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); - struct ifqueue * const ifq = &ifp->if_snd; - tulip_ringinfo_t * const ri = &sc->tulip_txinfo; - struct mbuf *m, *m0, *next_m0; - if ((ifp->if_flags & IFF_RUNNING) == 0 - && (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) - return; + if (sc->tulip_if.if_flags & IFF_RUNNING) { - for (;;) { - tulip_desc_t *eop, *nextout; - int segcnt, free, recopy; - u_int32_t d_status; + if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) + tulip_txput_setup(sc); - if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) { -#if defined(TULIP_DEBUG) - if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { - printf(TULIP_PRINTF_FMT ": ifstart: tx not running\n", - TULIP_PRINTF_ARGS); - ifp->if_flags |= IFF_OACTIVE; - return; + while (sc->tulip_if.if_snd.ifq_head != NULL) { + struct mbuf *m; + IF_DEQUEUE(&sc->tulip_if.if_snd, m); + if ((m = tulip_txput(sc, m)) != NULL) { + IF_PREPEND(&sc->tulip_if.if_snd, m); + break; } -#endif - if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { - ifp->if_flags |= IFF_OACTIVE; - return; - } - bcopy(sc->tulip_setupdata, sc->tulip_setupbuf, - sizeof(sc->tulip_setupbuf)); - sc->tulip_flags &= ~TULIP_WANTSETUP; - sc->tulip_flags |= TULIP_DOINGSETUP; - ri->ri_free--; - nextout = ri->ri_nextout; - nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; - nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG - |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; - if (sc->tulip_flags & TULIP_WANTHASHPERFECT) - nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; - else if (sc->tulip_flags & TULIP_WANTHASHONLY) - nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT; - nextout->d_length1 = sizeof(sc->tulip_setupbuf); - nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf); - nextout->d_length2 = 0; - nextout->d_addr2 = 0; - /* - * Advance the ring for the next transmit packet. - */ - if (++ri->ri_nextout == ri->ri_last) - ri->ri_nextout = ri->ri_first; - /* - * Make sure the next descriptor is owned by us since it - * may have been set up above if we ran out of room in the - * ring. - */ - ri->ri_nextout->d_status = 0; - nextout->d_status = TULIP_DSTS_OWNER; - TULIP_CSR_WRITE(sc, csr_txpoll, 1); } - - IF_DEQUEUE(ifq, m); - if (m == NULL) - break; - -#if defined(TULIP_DEBUG) - if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { - printf(TULIP_PRINTF_FMT ": ifstart%s: tx not running\n", - TULIP_PRINTF_ARGS, - (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : ""); - ifp->if_flags |= IFF_OACTIVE; - IF_PREPEND(ifq, m); - return; - } -#endif - - /* - * Now we try to fill in our transmit descriptors. This is - * a bit reminiscent of going on the Ark two by two - * since each descriptor for the TULIP can describe - * two buffers. So we advance through packet filling - * each of the two entries at a time to to fill each - * descriptor. Clear the first and last segment bits - * in each descriptor (actually just clear everything - * but the end-of-ring or chain bits) to make sure - * we don't get messed up by previously sent packets. - * - * We may fail to put the entire packet on the ring if - * there is either not enough ring entries free or if the - * packet has more than MAX_TXSEG segments. In the former - * case we will just wait for the ring to empty. In the - * latter case we have to recopy. - */ - d_status = 0; - recopy = 0; - eop = nextout = ri->ri_nextout; - m0 = m; - segcnt = 0; - free = ri->ri_free; - do { - int len = m0->m_len; - caddr_t addr = mtod(m0, caddr_t); - unsigned clsize = CLBYTES - (((u_long) addr) & (CLBYTES-1)); - - next_m0 = m0->m_next; - while (len > 0) { - unsigned slen = min(len, clsize); -#ifdef BIG_PACKET - int partial = 0; - if (slen >= 2048) - slen = 2040, partial = 1; -#endif - segcnt++; - if (segcnt > TULIP_MAX_TXSEG) { - recopy = 1; - next_m0 = NULL; /* to break out of outside loop */ - break; - } - if (segcnt & 1) { - if (--free == 0) { - /* - * There's no more room but since nothing - * has been committed at this point, just - * show output is active, put back the - * mbuf and return. - */ - ifp->if_flags |= IFF_OACTIVE; - IF_PREPEND(ifq, m); - return; - } - eop = nextout; - if (++nextout == ri->ri_last) - nextout = ri->ri_first; - eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; - eop->d_status = d_status; - eop->d_addr1 = TULIP_KVATOPHYS(sc, addr); - eop->d_length1 = slen; - } else { - /* - * Fill in second half of descriptor - */ - eop->d_addr2 = TULIP_KVATOPHYS(sc, addr); - eop->d_length2 = slen; - } - d_status = TULIP_DSTS_OWNER; - len -= slen; - addr += slen; -#ifdef BIG_PACKET - if (partial) - continue; -#endif - clsize = CLBYTES; - } - } while ((m0 = next_m0) != NULL); - - /* - * The packet exceeds the number of transmit buffer - * entries that we can use for one packet, so we have - * recopy it into one mbuf and then try again. - */ - if (recopy) { - MGETHDR(m0, M_DONTWAIT, MT_DATA); - if (m0 != NULL) { - if (m->m_pkthdr.len > MHLEN) { - MCLGET(m0, M_DONTWAIT); - if ((m0->m_flags & M_EXT) == 0) { - m_freem(m); - m_freem(m0); - continue; - } - } - m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t)); - m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; - IF_PREPEND(ifq, m0); - } - m_freem(m); - continue; - } - - /* - * The descriptors have been filled in. Now get ready - * to transmit. - */ -#if NBPFILTER > 0 - if (sc->tulip_bpf != NULL) - TULIP_BPF_MTAP(sc, m); -#endif - IF_ENQUEUE(&sc->tulip_txq, m); - - /* - * Make sure the next descriptor after this packet is owned - * by us since it may have been set up above if we ran out - * of room in the ring. - */ - nextout->d_status = 0; - - /* - * If we only used the first segment of the last descriptor, - * make sure the second segment will not be used. - */ - if (segcnt & 1) { - eop->d_addr2 = 0; - eop->d_length2 = 0; - } - - /* - * Mark the last and first segments, indicate we want a transmit - * complete interrupt, give the descriptors to the TULIP, and tell - * it to transmit! - */ - eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; - - /* - * Note that ri->ri_nextout is still the start of the packet - * and until we set the OWNER bit, we can still back out of - * everything we have done. - */ - ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG; - ri->ri_nextout->d_status = TULIP_DSTS_OWNER; - - /* - * This advances the ring for us. - */ - ri->ri_nextout = nextout; - ri->ri_free = free; - - TULIP_CSR_WRITE(sc, csr_txpoll, 1); - - if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { - ifp->if_flags |= IFF_OACTIVE; - return; - } - if (sc->tulip_txtimer == 0) - sc->tulip_txtimer = TULIP_TXTIMER; } - if (m != NULL) { - ifp->if_flags |= IFF_OACTIVE; - IF_PREPEND(ifq, m); + + TULIP_PERFEND(ifstart); +} + +static ifnet_ret_t +tulip_ifstart_one( + struct ifnet * const ifp) +{ + TULIP_PERFSTART(ifstart_one) + tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); + + if ((sc->tulip_if.if_flags & IFF_RUNNING) + && sc->tulip_if.if_snd.ifq_head != NULL) { + struct mbuf *m; + IF_DEQUEUE(&sc->tulip_if.if_snd, m); + if ((m = tulip_txput(sc, m)) != NULL) + IF_PREPEND(&sc->tulip_if.if_snd, m); } + TULIP_PERFEND(ifstart_one); } /* @@ -4180,6 +4390,7 @@ static void tulip_ifwatchdog( struct ifnet *ifp) { + TULIP_PERFSTART(ifwatchdog) tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); #if defined(TULIP_DEBUG) @@ -4214,6 +4425,8 @@ tulip_ifwatchdog( sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR); } + if (sc->tulip_txtimer) + tulip_tx_intr(sc); if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) { printf(TULIP_PRINTF_FMT ": transmission timeout\n", TULIP_PRINTF_ARGS); if (TULIP_DO_AUTOSENSE(sc)) { @@ -4224,7 +4437,30 @@ tulip_ifwatchdog( tulip_reset(sc); tulip_init(sc); } + + TULIP_PERFEND(ifwatchdog); + TULIP_PERFMERGE(sc, perf_intr_cycles); + TULIP_PERFMERGE(sc, perf_ifstart_cycles); + TULIP_PERFMERGE(sc, perf_ifioctl_cycles); + TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles); + TULIP_PERFMERGE(sc, perf_timeout_cycles); + TULIP_PERFMERGE(sc, perf_ifstart_one_cycles); + TULIP_PERFMERGE(sc, perf_txput_cycles); + TULIP_PERFMERGE(sc, perf_txintr_cycles); + TULIP_PERFMERGE(sc, perf_rxintr_cycles); + TULIP_PERFMERGE(sc, perf_rxget_cycles); + TULIP_PERFMERGE(sc, perf_intr); + TULIP_PERFMERGE(sc, perf_ifstart); + TULIP_PERFMERGE(sc, perf_ifioctl); + TULIP_PERFMERGE(sc, perf_ifwatchdog); + TULIP_PERFMERGE(sc, perf_timeout); + TULIP_PERFMERGE(sc, perf_ifstart_one); + TULIP_PERFMERGE(sc, perf_txput); + TULIP_PERFMERGE(sc, perf_txintr); + TULIP_PERFMERGE(sc, perf_rxintr); + TULIP_PERFMERGE(sc, perf_rxget); } + #if defined(__bsdi__) || (defined(__FreeBSD__) && BSD < 199506) static ifnet_ret_t tulip_ifwatchdog_wrapper( @@ -4694,10 +4930,8 @@ tulip_pci_attach( #define PCI_CONF_WRITE(r, v) pci_conf_write(pa->pa_pc, pa->pa_tag, (r), (v)) #define PCI_CONF_READ(r) pci_conf_read(pa->pa_pc, pa->pa_tag, (r)) #define PCI_GETBUSDEVINFO(sc) do { \ - int busno, devno, funcno; \ - pci_decompose_tag(pa->pa_pc, pa->pa_tag, &busno, &devno, &funcno); \ - (sc)->tulip_pci_busno = busno; \ - (sc)->tulip_pci_devno = devno; \ + (sc)->tulip_pci_busno = parent; \ + (sc)->tulip_pci_devno = pa->pa_device; \ } while (0) #endif /* __NetBSD__ */ int retval, idx; @@ -4779,7 +5013,7 @@ tulip_pci_attach( sc->tulip_chipid = chipid; sc->tulip_flags |= TULIP_DEVICEPROBE; if (chipid == TULIP_21140 || chipid == TULIP_21140A) - sc->tulip_features |= TULIP_HAVE_GPR; + sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD; if (chipid == TULIP_21140A && revinfo <= 0x22) sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW; if (chipid == TULIP_21140) @@ -4791,7 +5025,7 @@ tulip_pci_attach( if (chipid != TULIP_21041 || sc->tulip_revinfo >= 0x20) sc->tulip_features |= TULIP_HAVE_SIANWAY; if (chipid != TULIP_21041) - sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW; + sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD; } if (sc->tulip_features & TULIP_HAVE_POWERMGMT @@ -4853,14 +5087,40 @@ tulip_pci_attach( #if defined(__NetBSD__) csr_base = 0; - if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, - &sc->tulip_bustag, &sc->tulip_bushandle, NULL, NULL) - && pci_mapreg_map(pa, PCI_CBMA, - PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, - &sc->tulip_bustag, &sc->tulip_bushandle, - NULL, NULL) == 0) { - printf(": unable to map device registers\n"); - return; + { + bus_space_tag_t iot, memt; + bus_space_handle_t ioh, memh; + u_int32_t cfcs = PCI_CONF_READ(PCI_CFCS); + + cfcs &= ~(PCI_COMMAND_IO_ENABLE||PCI_COMMAND_IO_ENABLE); + if (!pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, + &iot, &ioh, NULL, NULL)) { + cfcs |= PCI_COMMAND_IO_ENABLE; + } + if (!pci_mapreg_map(pa, PCI_CBMA, + PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, + 0, &memt, &memh, NULL, NULL) == 0) { + cfcs |= PCI_COMMAND_MEM_ENABLE; + } + if ((cfcs & (PCI_COMMAND_IO_ENABLE||PCI_COMMAND_IO_ENABLE)) == 0) { + printf(": unable to map device registers\n"); + return; + } + cfcs |= PCI_COMMAND_MASTER_ENABLE; + PCI_CONF_WRITE(PCI_CFCS, cfcs); +#if defined(PCI_PREFER_IOSPACE) + if (cfcs & PCI_COMMAND_IO_ENABLE) { + sc->tulip_bustag = iot, sc->tulip_bushandle = ioh; + } else { + sc->tulip_bustag = memt, sc->tulip_bushandle = memh; + } +#else + if (cfcs & PCI_COMMAND_MEM_ENABLE) { + sc->tulip_bustag = memt, sc->tulip_bushandle = memh; + } else { + sc->tulip_bustag = iot, sc->tulip_bushandle = ioh; + } +#endif /* PCI_PREFER_IOSPACE */ } #endif /* __NetBSD__ */ diff --git a/sys/pci/if_devar.h b/sys/pci/if_devar.h index 20e742483fa0..68fbc7b45d77 100644 --- a/sys/pci/if_devar.h +++ b/sys/pci/if_devar.h @@ -21,7 +21,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_devar.h,v 1.22 1997/05/08 16:50:06 thomas Exp $ + * $Id: if_devar.h,v 1.28 1997/07/03 16:55:07 thomas Exp $ */ #if !defined(_DEVAR_H) @@ -437,8 +437,10 @@ typedef struct { u_int32_t dot3StatsDeferredTransmissions; u_int32_t dot3StatsLateCollisions; u_int32_t dot3StatsExcessiveCollisions; - u_int32_t dot3StatsInternalMacTransmitErrors; u_int32_t dot3StatsCarrierSenseErrors; + u_int32_t dot3StatsInternalMacTransmitErrors; + u_int32_t dot3StatsInternalTransmitUnderflows; /* not in rfc1650! */ + u_int32_t dot3StatsInternalTransmitBabbles; /* not in rfc1650! */ /* * Receive Statistics */ @@ -502,8 +504,8 @@ struct _tulip_softc_t { #define TULIP_SQETEST 0x00000800 #define TULIP_xxxxxx0 0x00001000 #define TULIP_xxxxxx1 0x00002000 -#define TULIP_xxxxxx2 0x00004000 -#define TULIP_xxxxxx3 0x00008000 +#define TULIP_WANTTXSTART 0x00004000 +#define TULIP_NEWTXTHRESH 0x00008000 #define TULIP_NOAUTOSENSE 0x00010000 #define TULIP_PRINTLINKUP 0x00020000 #define TULIP_LINKUP 0x00040000 @@ -511,7 +513,7 @@ struct _tulip_softc_t { #define TULIP_NOMESSAGES 0x00100000 #define TULIP_SYSTEMERROR 0x00200000 #define TULIP_TIMEOUTPENDING 0x00400000 -#define TULIP_FASTTIMEOUTPENDING 0x00800000 +#define TULIP_xxxxxx2 0x00800000 #define TULIP_TRYNWAY 0x01000000 #define TULIP_DIDNWAY 0x02000000 #define TULIP_RXIGNORE 0x04000000 @@ -519,7 +521,8 @@ struct _tulip_softc_t { #define TULIP_DEVICEPROBE 0x10000000 #define TULIP_PROMISC 0x20000000 #define TULIP_HASHONLY 0x40000000 - /* only 1 bit left! */ +#define TULIP_xxxxxx3 0x80000000 + /* only 4 bits left! */ u_int32_t tulip_features; /* static bits indicating features of chip */ #define TULIP_HAVE_GPR 0x00000001 /* have gp register (140[A]) */ #define TULIP_HAVE_RXBADOVRFLW 0x00000002 /* RX corrupts on overflow */ @@ -536,6 +539,7 @@ struct _tulip_softc_t { #define TULIP_HAVE_SHAREDINTR 0x00001000 /* Board shares interrupts */ #define TULIP_HAVE_OKROM 0x00002000 /* ROM was recognized */ #define TULIP_HAVE_NOMEDIA 0x00004000 /* did not detect any media */ +#define TULIP_HAVE_STOREFWD 0x00008000 /* have CMD_STOREFWD */ u_int32_t tulip_intrmask; /* our copy of csr_intr */ u_int32_t tulip_cmdmode; /* our copy of csr_cmdmode */ u_int32_t tulip_last_system_error : 3; /* last system error (only value is TULIP_SYSTEMERROR is also set) */ @@ -598,6 +602,35 @@ struct _tulip_softc_t { u_int32_t dbg_events[TULIP_MEDIAPOLL_MAX]; u_int32_t dbg_rxpktsperintr[TULIP_RXDESCS]; } tulip_dbg; +#endif +#if defined(TULIP_PERFSTATS) +#define TULIP_PERF_CURRENT 0 +#define TULIP_PERF_PREVIOUS 1 +#define TULIP_PERF_TOTAL 2 +#define TULIP_PERF_MAX 3 + struct tulip_perfstats { + u_quad_t perf_intr_cycles; + u_quad_t perf_ifstart_cycles; + u_quad_t perf_ifstart_one_cycles; + u_quad_t perf_ifioctl_cycles; + u_quad_t perf_ifwatchdog_cycles; + u_quad_t perf_timeout_cycles; + u_quad_t perf_txput_cycles; + u_quad_t perf_txintr_cycles; + u_quad_t perf_rxintr_cycles; + u_quad_t perf_rxget_cycles; + unsigned perf_intr; + unsigned perf_ifstart; + unsigned perf_ifstart_one; + unsigned perf_ifioctl; + unsigned perf_ifwatchdog; + unsigned perf_timeout; + unsigned perf_txput; + unsigned perf_txintr; + unsigned perf_rxintr; + unsigned perf_rxget; + } tulip_perfstats[TULIP_PERF_MAX]; +#define tulip_curperfstats tulip_perfstats[TULIP_PERF_CURRENT] #endif struct ifqueue tulip_txq; struct ifqueue tulip_rxq; @@ -614,7 +647,11 @@ struct _tulip_softc_t { u_int32_t tulip_setupdata[192/sizeof(u_int32_t)]; char tulip_boardid[16]; /* buffer for board ID */ u_int8_t tulip_rombuf[128]; +#if defined(__NetBSD__) + struct device *tulip_pci_busno; /* needed for multiport boards */ +#else u_int8_t tulip_pci_busno; /* needed for multiport boards */ +#endif u_int8_t tulip_pci_devno; /* needed for multiport boards */ u_int8_t tulip_connidx; tulip_srom_connection_t tulip_conntype; @@ -825,6 +862,7 @@ typedef u_long ioctl_cmd_t; extern struct cfdriver decd; #define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit]) #define TULIP_IFP_TO_SOFTC(ifp) (TULIP_UNIT_TO_SOFTC((ifp)->if_unit)) +#define TULIP_ETHER_IFATTACH(sc) ether_attach(&(sc)->tulip_if) #if _BSDI_VERSION >= 199510 #if 0 #define TULIP_BURSTSIZE(unit) log2_burst_size @@ -942,6 +980,47 @@ extern struct cfdriver de_cd; #define TULIP_BPF_ATTACH(sc) bpfattach(&(sc)->tulip_bpf, &(sc)->tulip_if, DLT_EN10MB, sizeof(struct ether_header)) #endif +#if defined(TULIP_PERFSTATS) +#define TULIP_PERFMERGE(sc, member) \ + do { (sc)->tulip_perfstats[TULIP_PERF_TOTAL].member \ + += (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member; \ + (sc)->tulip_perfstats[TULIP_PERF_PREVIOUS].member \ + = (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member; \ + (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member = 0; } while (0) +#define TULIP_PERFSTART(name) const tulip_cycle_t perfstart_ ## name = TULIP_PERFREAD(); +#define TULIP_PERFEND(name) do { \ + (sc)->tulip_curperfstats.perf_ ## name ## _cycles += TULIP_PERFDIFF(perfstart_ ## name, TULIP_PERFREAD()); \ + (sc)->tulip_curperfstats.perf_ ## name ++; \ + } while (0) +#if defined(__i386__) +typedef u_quad_t tulip_cycle_t; +static __inline__ tulip_cycle_t +TULIP_PERFREAD( + void) +{ + tulip_cycle_t x; + __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); + return x; +} +#define TULIP_PERFDIFF(s, f) ((f) - (s)) +#elif defined(__alpha__) +typedef unsigned long tulip_cycle_t; +static __inline__ tulip_cycle_t +TULIP_PERFREAD( + void) +{ + tulip_cycle_t x; + __asm__ volatile ("rpcc %0" : "=r" (x)); + return x; +} +#define TULIP_PERFDIFF(s, f) ((unsigned int) ((f) - (s))) +#endif +#else +#define TULIP_PERFSTART(name) +#define TULIP_PERFEND(name) do { } while (0) +#define TULIP_PERFMERGE(s,n) do { } while (0) +#endif /* TULIP_PERFSTATS */ + /* * However, this change to FreeBSD I am much less enamored with. */