aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>1999-02-08 19:05:55 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>1999-02-08 19:05:55 +0000
commit12c7f78b7d6e0118492cf5f923031e7e5d2d2879 (patch)
tree7b3667d39190ab8268cdc9df11e022d09387b2b7
parentdb900c809094088e5a49448a58c8c6b775a39a9d (diff)
Notes
-rw-r--r--sys/conf/options3
-rw-r--r--sys/dev/ppbus/if_plip.c86
-rw-r--r--sys/dev/ppbus/nlpt.c52
3 files changed, 74 insertions, 67 deletions
diff --git a/sys/conf/options b/sys/conf/options
index 35ceb1a53ffa..1aa1d94851df 100644
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -1,4 +1,4 @@
-# $Id: options,v 1.120 1999/01/17 19:02:39 peter Exp $
+# $Id: options,v 1.121 1999/01/20 14:49:07 eivind Exp $
#
# On the handling of kernel options
#
@@ -245,6 +245,7 @@ PERIPH_1284 opt_ppb_1284.h
DONTPROBE_1284 opt_ppb_1284.h
VP0_DEBUG opt_vpo.h
NLPT_DEBUG opt_nlpt.h
+PLIP_DEBUG opt_plip.h
LOCKF_DEBUG opt_debug_lockf.h
LOUTB opt_debug_outb.h
NPX_DEBUG opt_debug_npx.h
diff --git a/sys/dev/ppbus/if_plip.c b/sys/dev/ppbus/if_plip.c
index 7d64cd24fef6..4e64a3a93655 100644
--- a/sys/dev/ppbus/if_plip.c
+++ b/sys/dev/ppbus/if_plip.c
@@ -24,7 +24,7 @@
* SUCH DAMAGE.
*
* From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp
- * $Id: if_plip.c,v 1.6 1998/11/07 14:35:41 nsouch Exp $
+ * $Id: if_plip.c,v 1.10 1999/02/08 14:12:38 des Exp $
*/
/*
@@ -101,6 +101,8 @@
#include <dev/ppbus/ppbconf.h>
#include <dev/ppbus/nlpt.h>
+#include "opt_plip.h"
+
#ifndef LPMTU /* MTU for the lp# interfaces */
#define LPMTU 1500
#endif
@@ -129,15 +131,12 @@
#define LPIPTBLSIZE 256 /* Size of octet translation table */
-#ifndef DEBUG
-#define DEBUG
-#endif
-
-#ifndef DEBUG
-#define lprintf (void)
-#else
#define lprintf if (lptflag) printf
+
+#ifdef PLIP_DEBUG
static int volatile lptflag = 1;
+#else
+static int volatile lptflag = 0;
#endif
struct lpt_softc {
@@ -257,7 +256,7 @@ lpattach (struct ppb_device *dev)
if_attach(ifp);
#if NBPFILTER > 0
- bpfattach(ifp, DLT_NULL, LPIPHDRLEN);
+ bpfattach(ifp, DLT_NULL, sizeof(u_int32_t));
#endif
return (1);
@@ -446,6 +445,26 @@ clpinbyte (int spin, struct ppb_device *dev)
return (ctrecvl[cl] | ctrecvh[c]);
}
+#if NBPFILTER > 0
+static void
+lptap(struct ifnet *ifp, struct mbuf *m)
+{
+ /*
+ * Send a packet through bpf. We need to prepend the address family
+ * as a four byte field. Cons up a dummy header to pacify bpf. This
+ * is safe because bpf will only read from the mbuf (i.e., it won't
+ * try to free it or keep a pointer to it).
+ */
+ u_int32_t af = AF_INET;
+ struct mbuf m0;
+
+ m0.m_next = m;
+ m0.m_len = sizeof(u_int32_t);
+ m0.m_data = (char *)&af;
+ bpf_mtap(ifp, &m0);
+}
+#endif
+
static void
lpintr (int unit)
{
@@ -505,6 +524,10 @@ lpintr (int unit)
sc->sc_if.if_ibytes += len;
top = m_devget(sc->sc_ifbuf + CLPIPHDRLEN, len, 0, &sc->sc_if, 0);
if (top) {
+#if NBPFILTER > 0
+ if (sc->sc_if.if_bpf)
+ lptap(&sc->sc_if, top);
+#endif
IF_ENQUEUE(&ipintrq, top);
schednetisr(NETISR_IP);
}
@@ -549,18 +572,17 @@ lpintr (int unit)
IF_DROP(&ipintrq);
goto done;
}
-#if NBPFILTER > 0
- if (sc->sc_if.if_bpf) {
- bpf_tap(&sc->sc_if, sc->sc_ifbuf, len);
- }
-#endif
len -= LPIPHDRLEN;
sc->sc_if.if_ipackets++;
sc->sc_if.if_ibytes += len;
top = m_devget(sc->sc_ifbuf + LPIPHDRLEN, len, 0, &sc->sc_if, 0);
if (top) {
- IF_ENQUEUE(&ipintrq, top);
- schednetisr(NETISR_IP);
+#if NBPFILTER > 0
+ if (sc->sc_if.if_bpf)
+ lptap(&sc->sc_if, top);
+#endif
+ IF_ENQUEUE(&ipintrq, top);
+ schednetisr(NETISR_IP);
}
}
goto done;
@@ -611,8 +633,7 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
u_char *cp = "\0\0";
u_char chksum = 0;
int count = 0;
- int i;
- int spin;
+ int i, len, spin;
/* We need a sensible value if we abort */
cp++;
@@ -669,7 +690,8 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
mm = m;
do {
cp = mtod(mm, u_char *);
- while (mm->m_len--) {
+ len = mm->m_len;
+ while (len--) {
chksum += *cp;
if (clpoutbyte(*cp++, LPMAXSPIN2, &sc->lp_dev))
goto nend;
@@ -692,6 +714,10 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
} else {
ifp->if_opackets++;
ifp->if_obytes += m->m_pkthdr.len;
+#if NBPFILTER > 0
+ if (ifp->if_bpf)
+ lptap(ifp, m);
+#endif
}
m_freem(m);
@@ -717,7 +743,8 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
mm = m;
do {
cp = mtod(mm,u_char *);
- while (mm->m_len--)
+ len = mm->m_len;
+ while (len--)
if (lpoutbyte(*cp++, LPMAXSPIN2, &sc->lp_dev))
goto end;
} while ((mm = mm->m_next));
@@ -735,23 +762,8 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
ifp->if_opackets++;
ifp->if_obytes += m->m_pkthdr.len;
#if NBPFILTER > 0
- if (ifp->if_bpf) {
- /*
- * We need to prepend the packet type as
- * a two byte field. Cons up a dummy header
- * to pacify bpf. This is safe because bpf
- * will only read from the mbuf (i.e., it won't
- * try to free it or keep a pointer to it).
- */
- struct mbuf m0;
- u_short hdr = 0x800;
-
- m0.m_next = m;
- m0.m_len = 2;
- m0.m_data = (char *)&hdr;
-
- bpf_mtap(ifp, &m0);
- }
+ if (ifp->if_bpf)
+ lptap(ifp, m);
#endif
}
diff --git a/sys/dev/ppbus/nlpt.c b/sys/dev/ppbus/nlpt.c
index 89d6c7f5a5a3..b01c387b6994 100644
--- a/sys/dev/ppbus/nlpt.c
+++ b/sys/dev/ppbus/nlpt.c
@@ -47,7 +47,7 @@
*
* from: unknown origin, 386BSD 0.1
* From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp
- * $Id: nlpt.c,v 1.11 1998/12/04 22:00:33 archie Exp $
+ * $Id: nlpt.c,v 1.14 1999/02/08 13:55:43 des Exp $
*/
/*
@@ -221,6 +221,9 @@ nlpt_port_test(struct lpt_data *sc, u_char data, u_char mask)
}
/*
+ * Probe simplified by replacing multiple loops with a hardcoded
+ * test pattern - 1999/02/08 des@freebsd.org
+ *
* New lpt port probe Geoff Rehmet - Rhodes University - 14/2/94
* Based partially on Rod Grimes' printer probe
*
@@ -267,38 +270,29 @@ nlpt_port_test(struct lpt_data *sc, u_char data, u_char mask)
static int
nlpt_detect(struct lpt_data *sc)
{
- int status;
- u_char data;
- u_char mask;
- int i, error;
+ static u_char testbyte[18] = {
+ 0x55, /* alternating zeros */
+ 0xaa, /* alternating ones */
+ 0xfe, 0xfd, 0xfb, 0xf7,
+ 0xef, 0xdf, 0xbf, 0x7f, /* walking zero */
+ 0x01, 0x02, 0x04, 0x08,
+ 0x10, 0x20, 0x40, 0x80 /* walking one */
+ };
+ int i, error, status;
status = 1; /* assume success */
if ((error = lpt_request_ppbus(sc, PPB_DONTWAIT))) {
printf(LPT_NAME ": cannot alloc ppbus (%d)!\n", error);
- status = 0 ; goto end_probe ;
+ status = 0;
+ goto end_probe;
}
- mask = 0xff;
- data = 0x55; /* Alternating zeros */
- if (!nlpt_port_test(sc, data, mask))
- { status = 0 ; goto end_probe ; }
-
- data = 0xaa; /* Alternating ones */
- if (!nlpt_port_test(sc, data, mask))
- { status = 0 ; goto end_probe ; }
-
- for (i = 0; i < 8; i++) { /* Walking zero */
- data = ~(1 << i);
- if (!nlpt_port_test(sc, data, mask))
- { status = 0 ; goto end_probe ; }
- }
-
- for (i = 0; i < 8; i++) { /* Walking one */
- data = (1 << i);
- if (!nlpt_port_test(sc, data, mask))
- { status = 0 ; goto end_probe ; }
- }
+ for (i = 0; i < 18 && status; i++)
+ if (!nlpt_port_test(sc, testbyte[i], 0xff)) {
+ status = 0;
+ goto end_probe;
+ }
end_probe:
/* write 0's to control and data ports */
@@ -467,7 +461,7 @@ nlptopen(dev_t dev, int flags, int fmt, struct proc *p)
}
/* request the ppbus only if we don't have it already */
- if (err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR))
+ if ((err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR)) != 0)
return (err);
s = spltty();
@@ -564,7 +558,7 @@ nlptclose(dev_t dev, int flags, int fmt, struct proc *p)
if(sc->sc_flags & LP_BYPASS)
goto end_close;
- if (err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR))
+ if ((err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR)) != 0)
return (err);
sc->sc_state &= ~OPEN;
@@ -708,7 +702,7 @@ nlptwrite(dev_t dev, struct uio *uio, int ioflag)
}
/* request the ppbus only if we don't have it already */
- if (err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR))
+ if ((err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR)) != 0)
return (err);
sc->sc_state &= ~INTERRUPTED;