Update for the new mbuf code, in a slighly kludgy way. Basically, these

drivers played a somewhat evil trick with clusters, which is now
replaced by a somewhat evil trick with regular malloc'd memory.
This commit is contained in:
thorpej 1997-03-27 20:36:14 +00:00
parent 2a4b742e6a
commit d1c9089a16
4 changed files with 56 additions and 35 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_sl.c,v 1.44 1996/10/13 02:11:04 christos Exp $ */
/* $NetBSD: if_sl.c,v 1.45 1997/03/27 20:36:14 thorpej Exp $ */
/*
* Copyright (c) 1987, 1989, 1992, 1993
@ -73,6 +73,7 @@
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/buf.h>
#include <sys/dkstat.h>
@ -223,12 +224,14 @@ static int
slinit(sc)
register struct sl_softc *sc;
{
register caddr_t p;
if (sc->sc_ep == (u_char *) 0) {
MCLALLOC(p, M_WAIT);
if (p)
sc->sc_ep = (u_char *)p + SLBUFSIZE;
if (sc->sc_ep == NULL) {
/*
* XXX the trick this is used for is evil...
*/
sc->sc_xxx = (u_char *)malloc(MCLBYTES, M_MBUF, M_WAITOK);
if (sc->sc_xxx)
sc->sc_ep = sc->sc_xxx + SLBUFSIZE;
else {
printf("sl%d: can't allocate buffer\n", sc->sc_unit);
sc->sc_if.if_flags &= ~IFF_UP;
@ -321,7 +324,7 @@ slclose(tp)
if_down(&sc->sc_if);
sc->sc_ttyp = NULL;
tp->t_sc = NULL;
MCLFREE((caddr_t)(sc->sc_ep - SLBUFSIZE));
free((caddr_t)(sc->sc_ep - SLBUFSIZE), M_MBUF);
sc->sc_ep = 0;
sc->sc_mp = 0;
sc->sc_buf = 0;
@ -650,6 +653,7 @@ sl_btom(sc, len)
register int len;
{
register struct mbuf *m;
register u_char *p;
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL)
@ -663,18 +667,23 @@ sl_btom(sc, len)
* guarantees that packet will fit in a cluster.
*/
if (len >= MHLEN) {
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
/*
* XXX this is that evil trick I mentioned...
*/
p = sc->sc_xxx;
sc->sc_xxx = (u_char *)malloc(MCLBYTES, M_MBUF, M_NOWAIT);
if (sc->sc_xxx == NULL) {
/*
* we couldn't get a cluster - if memory's this
* low, it's time to start dropping packets.
* We couldn't allocate a new buffer - if
* memory's this low, it's time to start
* dropping packets.
*/
(void) m_free(m);
return (NULL);
}
sc->sc_ep = mtod(m, u_char *) + SLBUFSIZE;
sc->sc_ep = sc->sc_xxx + SLBUFSIZE;
MEXTADD(m, p, MCLBYTES, M_MBUF, NULL, NULL);
m->m_data = (caddr_t)sc->sc_buf;
m->m_ext.ext_buf = (caddr_t)((long)sc->sc_buf &~ MCLOFSET);
} else
bcopy((caddr_t)sc->sc_buf, mtod(m, caddr_t), len);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_slvar.h,v 1.16 1996/05/07 02:40:46 thorpej Exp $ */
/* $NetBSD: if_slvar.h,v 1.17 1997/03/27 20:36:17 thorpej Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -49,6 +49,7 @@ struct sl_softc {
u_char *sc_mp; /* pointer to next available buf char */
u_char *sc_ep; /* pointer to last available buf char */
u_char *sc_buf; /* input buffer */
u_char *sc_xxx; /* XXX don't ask... */
u_int sc_flags; /* see below */
u_int sc_escape; /* =1 if last char input was FRAME_ESCAPE */
long sc_lasttime; /* last time a char arrived */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_strip.c,v 1.8 1996/10/25 22:15:54 cgd Exp $ */
/* $NetBSD: if_strip.c,v 1.9 1997/03/27 20:36:18 thorpej Exp $ */
/* from: NetBSD: if_sl.c,v 1.38 1996/02/13 22:00:23 christos Exp $ */
/*
@ -373,12 +373,15 @@ static int
stripinit(sc)
register struct st_softc *sc;
{
register caddr_t p;
register u_char *p;
if (sc->sc_ep == (u_char *) 0) {
MCLALLOC(p, M_WAIT);
if (p)
sc->sc_ep = (u_char *)p + SLBUFSIZE;
if (sc->sc_ep == NULL) {
/*
* XXX the trick this is used for is evil...
*/
sc->sc_xxx = (u_char *)malloc(MCLBYTES, M_MBUF, M_WAITOK);
if (sc->sc_xxx)
sc->sc_ep = sc_xxx + SLBUFSIZE;
else {
printf("%s: can't allocate buffer\n",
sc->sc_if.if_xname);
@ -388,10 +391,10 @@ stripinit(sc)
}
/* Get contiguous buffer in which to de-bytestuff/rll-decode input */
if (sc->sc_rxbuf == (u_char *) 0) {
MCLALLOC(p, M_WAIT);
if (sc->sc_rxbuf == NULL) {
p = (u_char *)malloc(MCLBYTES, M_DEVBUF, M_WAITOK);
if (p)
sc->sc_rxbuf = (u_char *)p + SLBUFSIZE - SLMAX;
sc->sc_rxbuf = p + SLBUFSIZE - SLMAX;
else {
printf("%s: can't allocate input buffer\n",
sc->sc_if.if_xname);
@ -401,8 +404,8 @@ stripinit(sc)
}
/* Get contiguous buffer in which to bytestuff/rll-encode output */
if (sc->sc_txbuf == (u_char *) 0) {
MCLALLOC(p, M_WAIT);
if (sc->sc_txbuf == NULL) {
p = (u_char *)malloc(MCLBYTES, M_DEVBUF, M_WAITOK);
if (p)
sc->sc_txbuf = (u_char *)p + SLBUFSIZE - SLMAX;
else {
@ -510,9 +513,11 @@ stripclose(tp)
if_down(&sc->sc_if);
sc->sc_ttyp = NULL;
tp->t_sc = NULL;
MCLFREE((caddr_t)(sc->sc_ep - SLBUFSIZE));
MCLFREE((caddr_t)(sc->sc_rxbuf - SLBUFSIZE + SLMAX)); /* XXX */
MCLFREE((caddr_t)(sc->sc_txbuf - SLBUFSIZE + SLMAX)); /* XXX */
free((caddr_t)(sc->sc_ep - SLBUFSIZE), M_MBUF);
/* XXX */
free((caddr_t)(sc->sc_rxbuf - SLBUFSIZE + SLMAX), M_DEVBUF);
/* XXX */
free((caddr_t)(sc->sc_txbuf - SLBUFSIZE + SLMAX), M_DEVBUF);
sc->sc_ep = 0;
sc->sc_mp = 0;
sc->sc_buf = 0;
@ -1065,18 +1070,23 @@ strip_btom(sc, len)
* guarantees that packet will fit in a cluster.
*/
if (len >= MHLEN) {
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
/*
* XXX this is that evil trick I mentioned...
*/
p = sc->sc_xxx;
sc->sc_xxx = (u_char *)malloc(MCLBYTES, M_MBUF, M_NOWAIT);
if (sc->sc_xxx == NULL) {
/*
* we couldn't get a cluster - if memory's this
* low, it's time to start dropping packets.
* We couldn't allocate a new buffer - if
* memory's this low, it's time to start
* dropping packets.
*/
(void) m_free(m);
return (NULL);
}
sc->sc_ep = mtod(m, u_char *) + SLBUFSIZE;
sc->sc_ep = sc->sc_xxx + SLBUFSIZE;
MEXTADD(m, p, MCLBYTES, M_MBUF, NULL, NULL);
m->m_data = (caddr_t)sc->sc_buf;
m->m_ext.ext_buf = (caddr_t)((long)sc->sc_buf &~ MCLOFSET);
} else
bcopy((caddr_t)sc->sc_buf, mtod(m, caddr_t), len);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_stripvar.h,v 1.3 1996/08/02 02:53:39 jonathan Exp $ */
/* $NetBSD: if_stripvar.h,v 1.4 1997/03/27 20:36:21 thorpej Exp $ */
/*
* Definitions for SLIP interface data structures
@ -16,6 +16,7 @@ struct st_softc {
u_char *sc_buf; /* input buffer */
u_char *sc_rxbuf; /* input destuffing buffer */
u_char *sc_txbuf; /* output stuffing buffer */
u_char *sc_xxx; /* XXX don't ask... */
u_int sc_flags; /* see below */
long sc_oqlen; /* previous output queue size */
long sc_otimeout; /* number of times output's stalled */