summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/pc98/cbus/olpt.c656
-rw-r--r--sys/pc98/pc98/olpt.c656
2 files changed, 0 insertions, 1312 deletions
diff --git a/sys/pc98/cbus/olpt.c b/sys/pc98/cbus/olpt.c
index 54a4507..2dcb706 100644
--- a/sys/pc98/cbus/olpt.c
+++ b/sys/pc98/cbus/olpt.c
@@ -101,11 +101,6 @@
* Poul-Henning Kamp <phk@freebsd.org>
*/
-#include "opt_inet.h"
-#ifdef PC98
-#undef INET /* PLIP is not supported for old PC-98 */
-#endif
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
@@ -126,57 +121,12 @@
#include <i386/isa/lptreg.h>
#include <dev/ppbus/lptio.h>
-#ifdef INET
-#include <sys/malloc.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-
-#include <net/if.h>
-#include <net/if_types.h>
-#include <net/netisr.h>
-#include <netinet/in.h>
-#include <netinet/in_var.h>
-#include <net/bpf.h>
-#endif /* INET */
-
#define LPINITRDY 4 /* wait up to 4 seconds for a ready */
#define LPTOUTINITIAL 10 /* initial timeout to wait for ready 1/10 s */
#define LPTOUTMAX 1 /* maximal timeout 1 s */
#define LPPRI (PZERO+8)
#define BUFSIZE 1024
-#ifdef INET
-#ifndef LPMTU /* MTU for the lp# interfaces */
-#define LPMTU 1500
-#endif
-
-#ifndef LPMAXSPIN1 /* DELAY factor for the lp# interfaces */
-#define LPMAXSPIN1 8000 /* Spinning for remote intr to happen */
-#endif
-
-#ifndef LPMAXSPIN2 /* DELAY factor for the lp# interfaces */
-#define LPMAXSPIN2 500 /* Spinning for remote handshake to happen */
-#endif
-
-#ifndef LPMAXERRS /* Max errors before !RUNNING */
-#define LPMAXERRS 100
-#endif
-
-#define CLPIPHDRLEN 14 /* We send dummy ethernet addresses (two) + packet type in front of packet */
-#define CLPIP_SHAKE 0x80 /* This bit toggles between nibble reception */
-#define MLPIPHDRLEN CLPIPHDRLEN
-
-#define LPIPHDRLEN 2 /* We send 0x08, 0x00 in front of packet */
-#define LPIP_SHAKE 0x40 /* This bit toggles between nibble reception */
-#if !defined(MLPIPHDRLEN) || LPIPHDRLEN > MLPIPHDRLEN
-#define MLPIPHDRLEN LPIPHDRLEN
-#endif
-
-#define LPIPTBLSIZE 256 /* Size of octet translation table */
-
-#endif /* INET */
-
#ifndef PC98
/* BIOS printer list - used by BIOS probe*/
#define BIOS_LPT_PORTS 0x408
@@ -224,12 +174,6 @@ struct lpt_softc {
#define LP_USE_IRQ 0x02 /* we are using our irq */
#define LP_ENABLE_IRQ 0x04 /* enable IRQ on open */
u_char sc_backoff ; /* time to call lptout() again */
-
-#ifdef INET
- struct ifnet sc_if;
- u_char *sc_ifbuf;
- int sc_iferrs;
-#endif
};
/* bits for state */
@@ -265,30 +209,6 @@ static int lpt_probe(device_t);
static int lpt_attach(device_t);
static void lpt_intr(void *);
-#ifdef INET
-
-/* Tables for the lp# interface */
-static u_char *txmith;
-#define txmitl (txmith+(1*LPIPTBLSIZE))
-#define trecvh (txmith+(2*LPIPTBLSIZE))
-#define trecvl (txmith+(3*LPIPTBLSIZE))
-
-static u_char *ctxmith;
-#define ctxmitl (ctxmith+(1*LPIPTBLSIZE))
-#define ctrecvh (ctxmith+(2*LPIPTBLSIZE))
-#define ctrecvl (ctxmith+(3*LPIPTBLSIZE))
-
-/* Functions for the lp# interface */
-static void lpattach(struct lpt_softc *,int);
-#ifndef PC98
-static int lpinittables(void);
-#endif
-static int lpioctl(struct ifnet *, u_long, caddr_t);
-static int lpoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
- struct rtentry *);
-static void lpintr(int);
-#endif /* INET */
-
static devclass_t olpt_devclass;
static device_method_t olpt_methods[] = {
@@ -536,9 +456,6 @@ lpt_attach(device_t dev)
}
sc->sc_irq = LP_HAS_IRQ | LP_USE_IRQ | LP_ENABLE_IRQ;
device_printf(dev, "Interrupt-driven port");
-#ifdef INET
- lpattach(sc, unit);
-#endif
}
/* XXX what to do about the flags in the minor number? */
@@ -570,11 +487,6 @@ lptopen (dev_t dev, int flags, int fmt, struct proc *p)
if (sc->sc_port == 0)
return (ENXIO);
-#ifdef INET
- if (sc->sc_if.if_flags & IFF_UP)
- return(EBUSY);
-#endif
-
if (sc->sc_state) {
lprintf(("lp: still open %x\n", sc->sc_state));
return(EBUSY);
@@ -868,65 +780,6 @@ lptwrite(dev_t dev, struct uio * uio, int ioflag)
static void
lpt_intr(void *arg)
{
-#if defined(INET) || !defined(PC98)
- struct lpt_softc *sc = arg;
-#endif
-#ifndef PC98
- int port = sc->sc_port, sts;
- int i;
-#endif
-
-#ifdef INET
- if(sc->sc_if.if_flags & IFF_UP) {
- lpintr(unit);
- return;
- }
-#endif /* INET */
-
-#ifndef PC98
- /*
- * Is printer online and ready for output?
- *
- * Avoid falling back to lptout() too quickly. First spin-loop
- * to see if the printer will become ready ``really soon now''.
- */
- for (i = 0;
- i < 100 &&
- ((sts=inb(port+lpt_status)) & RDY_MASK) != LP_READY;
- i++) ;
- if ((sts & RDY_MASK) == LP_READY) {
- sc->sc_state = (sc->sc_state | OBUSY) & ~ERROR;
- sc->sc_backoff = hz/LPTOUTINITIAL;
-
- if (sc->sc_xfercnt) {
- /* send char */
- /*lprintf(("%x ", *sc->sc_cp)); */
- outb(port+lpt_data, *sc->sc_cp++) ;
- outb(port+lpt_control, sc->sc_control|LPC_STB);
- /* DELAY(X) */
- outb(port+lpt_control, sc->sc_control);
-
- /* any more data for printer */
- if(--(sc->sc_xfercnt) > 0) return;
- }
-
- /*
- * No more data waiting for printer.
- * Wakeup is not done if write call was interrupted.
- */
- sc->sc_state &= ~OBUSY;
- if(!(sc->sc_state & INTERRUPTED))
- wakeup((caddr_t)sc);
- lprintf(("w "));
- return;
- } else { /* check for error */
- if(((sts & (LPS_NERR | LPS_OUT) ) != LPS_NERR) &&
- (sc->sc_state & OPEN))
- sc->sc_state |= ERROR;
- /* lptout() will jump in and try to restart. */
- }
-#endif
- lprintf(("sts %x ", sts));
}
static int
@@ -970,512 +823,3 @@ lptioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
return(error);
}
-
-#ifdef INET
-
-static void
-lpattach (struct lpt_softc *sc, int unit)
-{
- struct ifnet *ifp = &sc->sc_if;
-
- ifp->if_softc = sc;
- ifp->if_name = "lp";
- ifp->if_unit = unit;
- ifp->if_mtu = LPMTU;
- ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST;
- ifp->if_ioctl = lpioctl;
- ifp->if_output = lpoutput;
- ifp->if_type = IFT_PARA;
- ifp->if_hdrlen = 0;
- ifp->if_addrlen = 0;
- ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
- if_attach(ifp);
- printf("lp%d: TCP/IP capable interface\n", unit);
-
- bpfattach(ifp, DLT_NULL, LPIPHDRLEN);
-}
-
-#ifndef PC98
-/*
- * Build the translation tables for the LPIP (BSD unix) protocol.
- * We don't want to calculate these nasties in our tight loop, so we
- * precalculate them when we initialize.
- */
-static int
-lpinittables (void)
-{
- int i;
-
- if (!txmith)
- txmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT);
-
- if (!txmith)
- return 1;
-
- if (!ctxmith)
- ctxmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT);
-
- if (!ctxmith)
- return 1;
-
- for (i=0; i < LPIPTBLSIZE; i++) {
- ctxmith[i] = (i & 0xF0) >> 4;
- ctxmitl[i] = 0x10 | (i & 0x0F);
- ctrecvh[i] = (i & 0x78) << 1;
- ctrecvl[i] = (i & 0x78) >> 3;
- }
-
- for (i=0; i < LPIPTBLSIZE; i++) {
- txmith[i] = ((i & 0x80) >> 3) | ((i & 0x70) >> 4) | 0x08;
- txmitl[i] = ((i & 0x08) << 1) | (i & 0x07);
- trecvh[i] = ((~i) & 0x80) | ((i & 0x38) << 1);
- trecvl[i] = (((~i) & 0x80) >> 4) | ((i & 0x38) >> 3);
- }
-
- return 0;
-}
-#endif /* PC98 */
-
-/*
- * Process an ioctl request.
- */
-
-static int
-lpioctl (struct ifnet *ifp, u_long cmd, caddr_t data)
-{
- struct lpt_softc *sc = lpt_sc + ifp->if_unit;
- struct ifaddr *ifa = (struct ifaddr *)data;
- struct ifreq *ifr = (struct ifreq *)data;
- u_char *ptr;
-
- switch (cmd) {
-
- case SIOCSIFDSTADDR:
- case SIOCAIFADDR:
- case SIOCSIFADDR:
- if (ifa->ifa_addr->sa_family != AF_INET)
- return EAFNOSUPPORT;
- ifp->if_flags |= IFF_UP;
- /* FALLTHROUGH */
- case SIOCSIFFLAGS:
- if ((!(ifp->if_flags & IFF_UP)) && (ifp->if_flags & IFF_RUNNING)) {
- outb(sc->sc_port + lpt_control, 0x00);
- ifp->if_flags &= ~IFF_RUNNING;
- break;
- }
-#ifdef PC98
- /* XXX */
- return ENOBUFS;
-#else
- if (((ifp->if_flags & IFF_UP)) && (!(ifp->if_flags & IFF_RUNNING))) {
- if (lpinittables())
- return ENOBUFS;
- sc->sc_ifbuf = malloc(sc->sc_if.if_mtu + MLPIPHDRLEN,
- M_DEVBUF, M_WAITOK);
- if (!sc->sc_ifbuf)
- return ENOBUFS;
-
- outb(sc->sc_port + lpt_control, LPC_ENA);
- ifp->if_flags |= IFF_RUNNING;
- }
- break;
-#endif
- case SIOCSIFMTU:
- ptr = sc->sc_ifbuf;
- sc->sc_ifbuf = malloc(ifr->ifr_mtu+MLPIPHDRLEN, M_DEVBUF, M_NOWAIT);
- if (!sc->sc_ifbuf) {
- sc->sc_ifbuf = ptr;
- return ENOBUFS;
- }
- if (ptr)
- free(ptr,M_DEVBUF);
- sc->sc_if.if_mtu = ifr->ifr_mtu;
- break;
-
- case SIOCGIFMTU:
- ifr->ifr_mtu = sc->sc_if.if_mtu;
- break;
-
- case SIOCADDMULTI:
- case SIOCDELMULTI:
- if (ifr == 0) {
- return EAFNOSUPPORT; /* XXX */
- }
- switch (ifr->ifr_addr.sa_family) {
-
-#ifdef INET
- case AF_INET:
- break;
-#endif
-
- default:
- return EAFNOSUPPORT;
- }
- break;
-
- default:
- lprintf(("LP:ioctl(0x%lx)\n", cmd));
- return EINVAL;
- }
- return 0;
-}
-
-static __inline int
-clpoutbyte (u_char byte, int spin, int data_port, int status_port)
-{
- outb(data_port, ctxmitl[byte]);
- while (inb(status_port) & CLPIP_SHAKE)
- if (--spin == 0) {
- return 1;
- }
- outb(data_port, ctxmith[byte]);
- while (!(inb(status_port) & CLPIP_SHAKE))
- if (--spin == 0) {
- return 1;
- }
- return 0;
-}
-
-static __inline int
-clpinbyte (int spin, int data_port, int status_port)
-{
- int c, cl;
-
- while((inb(status_port) & CLPIP_SHAKE))
- if(!--spin) {
- return -1;
- }
- cl = inb(status_port);
- outb(data_port, 0x10);
-
- while(!(inb(status_port) & CLPIP_SHAKE))
- if(!--spin) {
- return -1;
- }
- c = inb(status_port);
- outb(data_port, 0x00);
-
- return (ctrecvl[cl] | ctrecvh[c]);
-}
-
-static void
-lpintr (int unit)
-{
- struct lpt_softc *sc = lpt_sc + unit;
- register int lpt_data_port = sc->sc_port + lpt_data;
- register int lpt_stat_port = sc->sc_port + lpt_status;
- int lpt_ctrl_port = sc->sc_port + lpt_control;
- int len, s, j;
- u_char *bp;
- u_char c, cl;
- struct mbuf *top;
-
- s = splhigh();
-
- if (sc->sc_if.if_flags & IFF_LINK0) {
-
- /* Ack. the request */
- outb(lpt_data_port, 0x01);
-
- /* Get the packet length */
- j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
- if (j == -1)
- goto err;
- len = j;
- j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
- if (j == -1)
- goto err;
- len = len + (j << 8);
- if (len > sc->sc_if.if_mtu + MLPIPHDRLEN)
- goto err;
-
- bp = sc->sc_ifbuf;
-
- while (len--) {
- j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
- if (j == -1) {
- goto err;
- }
- *bp++ = j;
- }
- /* Get and ignore checksum */
- j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
- if (j == -1) {
- goto err;
- }
-
- len = bp - sc->sc_ifbuf;
- if (len <= CLPIPHDRLEN)
- goto err;
-
- sc->sc_iferrs = 0;
-
- len -= CLPIPHDRLEN;
- sc->sc_if.if_ipackets++;
- sc->sc_if.if_ibytes += len;
- top = m_devget(sc->sc_ifbuf + CLPIPHDRLEN, len, 0, &sc->sc_if, 0);
- if (top) {
- if (! IF_HANDOFF(&ipintrq, top, NULL))
- lprintf(("DROP"));
- else
- schednetisr(NETISR_IP);
- }
- goto done;
- }
- while ((inb(lpt_stat_port) & LPIP_SHAKE)) {
- len = sc->sc_if.if_mtu + LPIPHDRLEN;
- bp = sc->sc_ifbuf;
- while (len--) {
-
- cl = inb(lpt_stat_port);
- outb(lpt_data_port, 8);
-
- j = LPMAXSPIN2;
- while((inb(lpt_stat_port) & LPIP_SHAKE))
- if(!--j) goto err;
-
- c = inb(lpt_stat_port);
- outb(lpt_data_port, 0);
-
- *bp++= trecvh[cl] | trecvl[c];
-
- j = LPMAXSPIN2;
- while (!((cl=inb(lpt_stat_port)) & LPIP_SHAKE)) {
- if (cl != c &&
- (((cl = inb(lpt_stat_port)) ^ 0xb8) & 0xf8) ==
- (c & 0xf8))
- goto end;
- if (!--j) goto err;
- }
- }
-
- end:
- len = bp - sc->sc_ifbuf;
- if (len <= LPIPHDRLEN)
- goto err;
-
- sc->sc_iferrs = 0;
-
- if (sc->sc_if.if_bpf) {
- bpf_tap(&sc->sc_if, sc->sc_ifbuf, len);
- }
- 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 (! IF_HANDOFF(&ipintrq, top, NULL))
- lprintf(("DROP"));
- else
- schednetisr(NETISR_IP);
- }
- }
- goto done;
-
- err:
- outb(lpt_data_port, 0);
- lprintf(("R"));
- sc->sc_if.if_ierrors++;
- sc->sc_iferrs++;
-
- /*
- * We are not able to send receive anything for now,
- * so stop wasting our time
- */
- if (sc->sc_iferrs > LPMAXERRS) {
- printf("lp%d: Too many errors, Going off-line.\n", unit);
- outb(lpt_ctrl_port, 0x00);
- sc->sc_if.if_flags &= ~IFF_RUNNING;
- sc->sc_iferrs=0;
- }
-
- done:
- splx(s);
- return;
-}
-
-static __inline int
-lpoutbyte (u_char byte, int spin, int data_port, int status_port)
-{
- outb(data_port, txmith[byte]);
- while (!(inb(status_port) & LPIP_SHAKE))
- if (--spin == 0)
- return 1;
- outb(data_port, txmitl[byte]);
- while (inb(status_port) & LPIP_SHAKE)
- if (--spin == 0)
- return 1;
- return 0;
-}
-
-static int
-lpoutput (struct ifnet *ifp, struct mbuf *m,
- struct sockaddr *dst, struct rtentry *rt)
-{
- register int lpt_data_port = lpt_sc[ifp->if_unit].sc_port + lpt_data;
- register int lpt_stat_port = lpt_sc[ifp->if_unit].sc_port + lpt_status;
-#ifndef PC98
- int lpt_ctrl_port = lpt_sc[ifp->if_unit].sc_port + lpt_control;
-#endif
-
- int s, err;
- struct mbuf *mm;
- u_char *cp = "\0\0";
- u_char chksum = 0;
- int count = 0;
- int i;
- int spin;
-
- /* We need a sensible value if we abort */
- cp++;
- ifp->if_flags |= IFF_RUNNING;
-
- err = 1; /* assume we're aborting because of an error */
-
- s = splhigh();
-
-#ifndef PC98
- /* Suspend (on laptops) or receive-errors might have taken us offline */
- outb(lpt_ctrl_port, LPC_ENA);
-#endif
-
- if (ifp->if_flags & IFF_LINK0) {
-
- if (!(inb(lpt_stat_port) & CLPIP_SHAKE)) {
- lprintf(("&"));
- lptintr(ifp->if_unit);
- }
-
- /* Alert other end to pending packet */
- spin = LPMAXSPIN1;
- outb(lpt_data_port, 0x08);
- while ((inb(lpt_stat_port) & 0x08) == 0)
- if (--spin == 0) {
- goto nend;
- }
-
- /* Calculate length of packet, then send that */
-
- count += 14; /* Ethernet header len */
-
- mm = m;
- for (mm = m; mm; mm = mm->m_next) {
- count += mm->m_len;
- }
- if (clpoutbyte(count & 0xFF, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto nend;
- if (clpoutbyte((count >> 8) & 0xFF, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto nend;
-
- /* Send dummy ethernet header */
- for (i = 0; i < 12; i++) {
- if (clpoutbyte(i, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto nend;
- chksum += i;
- }
-
- if (clpoutbyte(0x08, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto nend;
- if (clpoutbyte(0x00, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto nend;
- chksum += 0x08 + 0x00; /* Add into checksum */
-
- mm = m;
- do {
- cp = mtod(mm, u_char *);
- while (mm->m_len--) {
- chksum += *cp;
- if (clpoutbyte(*cp++, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
- goto nend;
- }
- } while ((mm = mm->m_next));
-
- /* Send checksum */
- if (clpoutbyte(chksum, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
- goto nend;
-
- /* Go quiescent */
- outb(lpt_data_port, 0);
-
- err = 0; /* No errors */
-
- nend:
- if (err) { /* if we didn't timeout... */
- ifp->if_oerrors++;
- lprintf(("X"));
- } else {
- ifp->if_opackets++;
- ifp->if_obytes += m->m_pkthdr.len;
- }
-
- m_freem(m);
-
- if (!(inb(lpt_stat_port) & CLPIP_SHAKE)) {
- lprintf(("^"));
- lptintr(ifp->if_unit);
- }
- (void) splx(s);
- return 0;
- }
-
- if (inb(lpt_stat_port) & LPIP_SHAKE) {
- lprintf(("&"));
- lptintr(ifp->if_unit);
- }
-
- if (lpoutbyte(0x08, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto end;
- if (lpoutbyte(0x00, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
- goto end;
-
- mm = m;
- do {
- cp = mtod(mm,u_char *);
- while (mm->m_len--)
- if (lpoutbyte(*cp++, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
- goto end;
- } while ((mm = mm->m_next));
-
- err = 0; /* no errors were encountered */
-
- end:
- --cp;
- outb(lpt_data_port, txmitl[*cp] ^ 0x17);
-
- if (err) { /* if we didn't timeout... */
- ifp->if_oerrors++;
- lprintf(("X"));
- } else {
- ifp->if_opackets++;
- ifp->if_obytes += m->m_pkthdr.len;
- 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);
- }
- }
-
- m_freem(m);
-
- if (inb(lpt_stat_port) & LPIP_SHAKE) {
- lprintf(("^"));
- lptintr(ifp->if_unit);
- }
-
- (void) splx(s);
- return 0;
-}
-
-#endif /* INET */
diff --git a/sys/pc98/pc98/olpt.c b/sys/pc98/pc98/olpt.c
index 54a4507..2dcb706 100644
--- a/sys/pc98/pc98/olpt.c
+++ b/sys/pc98/pc98/olpt.c
@@ -101,11 +101,6 @@
* Poul-Henning Kamp <phk@freebsd.org>
*/
-#include "opt_inet.h"
-#ifdef PC98
-#undef INET /* PLIP is not supported for old PC-98 */
-#endif
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
@@ -126,57 +121,12 @@
#include <i386/isa/lptreg.h>
#include <dev/ppbus/lptio.h>
-#ifdef INET
-#include <sys/malloc.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-
-#include <net/if.h>
-#include <net/if_types.h>
-#include <net/netisr.h>
-#include <netinet/in.h>
-#include <netinet/in_var.h>
-#include <net/bpf.h>
-#endif /* INET */
-
#define LPINITRDY 4 /* wait up to 4 seconds for a ready */
#define LPTOUTINITIAL 10 /* initial timeout to wait for ready 1/10 s */
#define LPTOUTMAX 1 /* maximal timeout 1 s */
#define LPPRI (PZERO+8)
#define BUFSIZE 1024
-#ifdef INET
-#ifndef LPMTU /* MTU for the lp# interfaces */
-#define LPMTU 1500
-#endif
-
-#ifndef LPMAXSPIN1 /* DELAY factor for the lp# interfaces */
-#define LPMAXSPIN1 8000 /* Spinning for remote intr to happen */
-#endif
-
-#ifndef LPMAXSPIN2 /* DELAY factor for the lp# interfaces */
-#define LPMAXSPIN2 500 /* Spinning for remote handshake to happen */
-#endif
-
-#ifndef LPMAXERRS /* Max errors before !RUNNING */
-#define LPMAXERRS 100
-#endif
-
-#define CLPIPHDRLEN 14 /* We send dummy ethernet addresses (two) + packet type in front of packet */
-#define CLPIP_SHAKE 0x80 /* This bit toggles between nibble reception */
-#define MLPIPHDRLEN CLPIPHDRLEN
-
-#define LPIPHDRLEN 2 /* We send 0x08, 0x00 in front of packet */
-#define LPIP_SHAKE 0x40 /* This bit toggles between nibble reception */
-#if !defined(MLPIPHDRLEN) || LPIPHDRLEN > MLPIPHDRLEN
-#define MLPIPHDRLEN LPIPHDRLEN
-#endif
-
-#define LPIPTBLSIZE 256 /* Size of octet translation table */
-
-#endif /* INET */
-
#ifndef PC98
/* BIOS printer list - used by BIOS probe*/
#define BIOS_LPT_PORTS 0x408
@@ -224,12 +174,6 @@ struct lpt_softc {
#define LP_USE_IRQ 0x02 /* we are using our irq */
#define LP_ENABLE_IRQ 0x04 /* enable IRQ on open */
u_char sc_backoff ; /* time to call lptout() again */
-
-#ifdef INET
- struct ifnet sc_if;
- u_char *sc_ifbuf;
- int sc_iferrs;
-#endif
};
/* bits for state */
@@ -265,30 +209,6 @@ static int lpt_probe(device_t);
static int lpt_attach(device_t);
static void lpt_intr(void *);
-#ifdef INET
-
-/* Tables for the lp# interface */
-static u_char *txmith;
-#define txmitl (txmith+(1*LPIPTBLSIZE))
-#define trecvh (txmith+(2*LPIPTBLSIZE))
-#define trecvl (txmith+(3*LPIPTBLSIZE))
-
-static u_char *ctxmith;
-#define ctxmitl (ctxmith+(1*LPIPTBLSIZE))
-#define ctrecvh (ctxmith+(2*LPIPTBLSIZE))
-#define ctrecvl (ctxmith+(3*LPIPTBLSIZE))
-
-/* Functions for the lp# interface */
-static void lpattach(struct lpt_softc *,int);
-#ifndef PC98
-static int lpinittables(void);
-#endif
-static int lpioctl(struct ifnet *, u_long, caddr_t);
-static int lpoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
- struct rtentry *);
-static void lpintr(int);
-#endif /* INET */
-
static devclass_t olpt_devclass;
static device_method_t olpt_methods[] = {
@@ -536,9 +456,6 @@ lpt_attach(device_t dev)
}
sc->sc_irq = LP_HAS_IRQ | LP_USE_IRQ | LP_ENABLE_IRQ;
device_printf(dev, "Interrupt-driven port");
-#ifdef INET
- lpattach(sc, unit);
-#endif
}
/* XXX what to do about the flags in the minor number? */
@@ -570,11 +487,6 @@ lptopen (dev_t dev, int flags, int fmt, struct proc *p)
if (sc->sc_port == 0)
return (ENXIO);
-#ifdef INET
- if (sc->sc_if.if_flags & IFF_UP)
- return(EBUSY);
-#endif
-
if (sc->sc_state) {
lprintf(("lp: still open %x\n", sc->sc_state));
return(EBUSY);
@@ -868,65 +780,6 @@ lptwrite(dev_t dev, struct uio * uio, int ioflag)
static void
lpt_intr(void *arg)
{
-#if defined(INET) || !defined(PC98)
- struct lpt_softc *sc = arg;
-#endif
-#ifndef PC98
- int port = sc->sc_port, sts;
- int i;
-#endif
-
-#ifdef INET
- if(sc->sc_if.if_flags & IFF_UP) {
- lpintr(unit);
- return;
- }
-#endif /* INET */
-
-#ifndef PC98
- /*
- * Is printer online and ready for output?
- *
- * Avoid falling back to lptout() too quickly. First spin-loop
- * to see if the printer will become ready ``really soon now''.
- */
- for (i = 0;
- i < 100 &&
- ((sts=inb(port+lpt_status)) & RDY_MASK) != LP_READY;
- i++) ;
- if ((sts & RDY_MASK) == LP_READY) {
- sc->sc_state = (sc->sc_state | OBUSY) & ~ERROR;
- sc->sc_backoff = hz/LPTOUTINITIAL;
-
- if (sc->sc_xfercnt) {
- /* send char */
- /*lprintf(("%x ", *sc->sc_cp)); */
- outb(port+lpt_data, *sc->sc_cp++) ;
- outb(port+lpt_control, sc->sc_control|LPC_STB);
- /* DELAY(X) */
- outb(port+lpt_control, sc->sc_control);
-
- /* any more data for printer */
- if(--(sc->sc_xfercnt) > 0) return;
- }
-
- /*
- * No more data waiting for printer.
- * Wakeup is not done if write call was interrupted.
- */
- sc->sc_state &= ~OBUSY;
- if(!(sc->sc_state & INTERRUPTED))
- wakeup((caddr_t)sc);
- lprintf(("w "));
- return;
- } else { /* check for error */
- if(((sts & (LPS_NERR | LPS_OUT) ) != LPS_NERR) &&
- (sc->sc_state & OPEN))
- sc->sc_state |= ERROR;
- /* lptout() will jump in and try to restart. */
- }
-#endif
- lprintf(("sts %x ", sts));
}
static int
@@ -970,512 +823,3 @@ lptioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
return(error);
}
-
-#ifdef INET
-
-static void
-lpattach (struct lpt_softc *sc, int unit)
-{
- struct ifnet *ifp = &sc->sc_if;
-
- ifp->if_softc = sc;
- ifp->if_name = "lp";
- ifp->if_unit = unit;
- ifp->if_mtu = LPMTU;
- ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST;
- ifp->if_ioctl = lpioctl;
- ifp->if_output = lpoutput;
- ifp->if_type = IFT_PARA;
- ifp->if_hdrlen = 0;
- ifp->if_addrlen = 0;
- ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
- if_attach(ifp);
- printf("lp%d: TCP/IP capable interface\n", unit);
-
- bpfattach(ifp, DLT_NULL, LPIPHDRLEN);
-}
-
-#ifndef PC98
-/*
- * Build the translation tables for the LPIP (BSD unix) protocol.
- * We don't want to calculate these nasties in our tight loop, so we
- * precalculate them when we initialize.
- */
-static int
-lpinittables (void)
-{
- int i;
-
- if (!txmith)
- txmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT);
-
- if (!txmith)
- return 1;
-
- if (!ctxmith)
- ctxmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT);
-
- if (!ctxmith)
- return 1;
-
- for (i=0; i < LPIPTBLSIZE; i++) {
- ctxmith[i] = (i & 0xF0) >> 4;
- ctxmitl[i] = 0x10 | (i & 0x0F);
- ctrecvh[i] = (i & 0x78) << 1;
- ctrecvl[i] = (i & 0x78) >> 3;
- }
-
- for (i=0; i < LPIPTBLSIZE; i++) {
- txmith[i] = ((i & 0x80) >> 3) | ((i & 0x70) >> 4) | 0x08;
- txmitl[i] = ((i & 0x08) << 1) | (i & 0x07);
- trecvh[i] = ((~i) & 0x80) | ((i & 0x38) << 1);
- trecvl[i] = (((~i) & 0x80) >> 4) | ((i & 0x38) >> 3);
- }
-
- return 0;
-}
-#endif /* PC98 */
-
-/*
- * Process an ioctl request.
- */
-
-static int
-lpioctl (struct ifnet *ifp, u_long cmd, caddr_t data)
-{
- struct lpt_softc *sc = lpt_sc + ifp->if_unit;
- struct ifaddr *ifa = (struct ifaddr *)data;
- struct ifreq *ifr = (struct ifreq *)data;
- u_char *ptr;
-
- switch (cmd) {
-
- case SIOCSIFDSTADDR:
- case SIOCAIFADDR:
- case SIOCSIFADDR:
- if (ifa->ifa_addr->sa_family != AF_INET)
- return EAFNOSUPPORT;
- ifp->if_flags |= IFF_UP;
- /* FALLTHROUGH */
- case SIOCSIFFLAGS:
- if ((!(ifp->if_flags & IFF_UP)) && (ifp->if_flags & IFF_RUNNING)) {
- outb(sc->sc_port + lpt_control, 0x00);
- ifp->if_flags &= ~IFF_RUNNING;
- break;
- }
-#ifdef PC98
- /* XXX */
- return ENOBUFS;
-#else
- if (((ifp->if_flags & IFF_UP)) && (!(ifp->if_flags & IFF_RUNNING))) {
- if (lpinittables())
- return ENOBUFS;
- sc->sc_ifbuf = malloc(sc->sc_if.if_mtu + MLPIPHDRLEN,
- M_DEVBUF, M_WAITOK);
- if (!sc->sc_ifbuf)
- return ENOBUFS;
-
- outb(sc->sc_port + lpt_control, LPC_ENA);
- ifp->if_flags |= IFF_RUNNING;
- }
- break;
-#endif
- case SIOCSIFMTU:
- ptr = sc->sc_ifbuf;
- sc->sc_ifbuf = malloc(ifr->ifr_mtu+MLPIPHDRLEN, M_DEVBUF, M_NOWAIT);
- if (!sc->sc_ifbuf) {
- sc->sc_ifbuf = ptr;
- return ENOBUFS;
- }
- if (ptr)
- free(ptr,M_DEVBUF);
- sc->sc_if.if_mtu = ifr->ifr_mtu;
- break;
-
- case SIOCGIFMTU:
- ifr->ifr_mtu = sc->sc_if.if_mtu;
- break;
-
- case SIOCADDMULTI:
- case SIOCDELMULTI:
- if (ifr == 0) {
- return EAFNOSUPPORT; /* XXX */
- }
- switch (ifr->ifr_addr.sa_family) {
-
-#ifdef INET
- case AF_INET:
- break;
-#endif
-
- default:
- return EAFNOSUPPORT;
- }
- break;
-
- default:
- lprintf(("LP:ioctl(0x%lx)\n", cmd));
- return EINVAL;
- }
- return 0;
-}
-
-static __inline int
-clpoutbyte (u_char byte, int spin, int data_port, int status_port)
-{
- outb(data_port, ctxmitl[byte]);
- while (inb(status_port) & CLPIP_SHAKE)
- if (--spin == 0) {
- return 1;
- }
- outb(data_port, ctxmith[byte]);
- while (!(inb(status_port) & CLPIP_SHAKE))
- if (--spin == 0) {
- return 1;
- }
- return 0;
-}
-
-static __inline int
-clpinbyte (int spin, int data_port, int status_port)
-{
- int c, cl;
-
- while((inb(status_port) & CLPIP_SHAKE))
- if(!--spin) {
- return -1;
- }
- cl = inb(status_port);
- outb(data_port, 0x10);
-
- while(!(inb(status_port) & CLPIP_SHAKE))
- if(!--spin) {
- return -1;
- }
- c = inb(status_port);
- outb(data_port, 0x00);
-
- return (ctrecvl[cl] | ctrecvh[c]);
-}
-
-static void
-lpintr (int unit)
-{
- struct lpt_softc *sc = lpt_sc + unit;
- register int lpt_data_port = sc->sc_port + lpt_data;
- register int lpt_stat_port = sc->sc_port + lpt_status;
- int lpt_ctrl_port = sc->sc_port + lpt_control;
- int len, s, j;
- u_char *bp;
- u_char c, cl;
- struct mbuf *top;
-
- s = splhigh();
-
- if (sc->sc_if.if_flags & IFF_LINK0) {
-
- /* Ack. the request */
- outb(lpt_data_port, 0x01);
-
- /* Get the packet length */
- j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
- if (j == -1)
- goto err;
- len = j;
- j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
- if (j == -1)
- goto err;
- len = len + (j << 8);
- if (len > sc->sc_if.if_mtu + MLPIPHDRLEN)
- goto err;
-
- bp = sc->sc_ifbuf;
-
- while (len--) {
- j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
- if (j == -1) {
- goto err;
- }
- *bp++ = j;
- }
- /* Get and ignore checksum */
- j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
- if (j == -1) {
- goto err;
- }
-
- len = bp - sc->sc_ifbuf;
- if (len <= CLPIPHDRLEN)
- goto err;
-
- sc->sc_iferrs = 0;
-
- len -= CLPIPHDRLEN;
- sc->sc_if.if_ipackets++;
- sc->sc_if.if_ibytes += len;
- top = m_devget(sc->sc_ifbuf + CLPIPHDRLEN, len, 0, &sc->sc_if, 0);
- if (top) {
- if (! IF_HANDOFF(&ipintrq, top, NULL))
- lprintf(("DROP"));
- else
- schednetisr(NETISR_IP);
- }
- goto done;
- }
- while ((inb(lpt_stat_port) & LPIP_SHAKE)) {
- len = sc->sc_if.if_mtu + LPIPHDRLEN;
- bp = sc->sc_ifbuf;
- while (len--) {
-
- cl = inb(lpt_stat_port);
- outb(lpt_data_port, 8);
-
- j = LPMAXSPIN2;
- while((inb(lpt_stat_port) & LPIP_SHAKE))
- if(!--j) goto err;
-
- c = inb(lpt_stat_port);
- outb(lpt_data_port, 0);
-
- *bp++= trecvh[cl] | trecvl[c];
-
- j = LPMAXSPIN2;
- while (!((cl=inb(lpt_stat_port)) & LPIP_SHAKE)) {
- if (cl != c &&
- (((cl = inb(lpt_stat_port)) ^ 0xb8) & 0xf8) ==
- (c & 0xf8))
- goto end;
- if (!--j) goto err;
- }
- }
-
- end:
- len = bp - sc->sc_ifbuf;
- if (len <= LPIPHDRLEN)
- goto err;
-
- sc->sc_iferrs = 0;
-
- if (sc->sc_if.if_bpf) {
- bpf_tap(&sc->sc_if, sc->sc_ifbuf, len);
- }
- 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 (! IF_HANDOFF(&ipintrq, top, NULL))
- lprintf(("DROP"));
- else
- schednetisr(NETISR_IP);
- }
- }
- goto done;
-
- err:
- outb(lpt_data_port, 0);
- lprintf(("R"));
- sc->sc_if.if_ierrors++;
- sc->sc_iferrs++;
-
- /*
- * We are not able to send receive anything for now,
- * so stop wasting our time
- */
- if (sc->sc_iferrs > LPMAXERRS) {
- printf("lp%d: Too many errors, Going off-line.\n", unit);
- outb(lpt_ctrl_port, 0x00);
- sc->sc_if.if_flags &= ~IFF_RUNNING;
- sc->sc_iferrs=0;
- }
-
- done:
- splx(s);
- return;
-}
-
-static __inline int
-lpoutbyte (u_char byte, int spin, int data_port, int status_port)
-{
- outb(data_port, txmith[byte]);
- while (!(inb(status_port) & LPIP_SHAKE))
- if (--spin == 0)
- return 1;
- outb(data_port, txmitl[byte]);
- while (inb(status_port) & LPIP_SHAKE)
- if (--spin == 0)
- return 1;
- return 0;
-}
-
-static int
-lpoutput (struct ifnet *ifp, struct mbuf *m,
- struct sockaddr *dst, struct rtentry *rt)
-{
- register int lpt_data_port = lpt_sc[ifp->if_unit].sc_port + lpt_data;
- register int lpt_stat_port = lpt_sc[ifp->if_unit].sc_port + lpt_status;
-#ifndef PC98
- int lpt_ctrl_port = lpt_sc[ifp->if_unit].sc_port + lpt_control;
-#endif
-
- int s, err;
- struct mbuf *mm;
- u_char *cp = "\0\0";
- u_char chksum = 0;
- int count = 0;
- int i;
- int spin;
-
- /* We need a sensible value if we abort */
- cp++;
- ifp->if_flags |= IFF_RUNNING;
-
- err = 1; /* assume we're aborting because of an error */
-
- s = splhigh();
-
-#ifndef PC98
- /* Suspend (on laptops) or receive-errors might have taken us offline */
- outb(lpt_ctrl_port, LPC_ENA);
-#endif
-
- if (ifp->if_flags & IFF_LINK0) {
-
- if (!(inb(lpt_stat_port) & CLPIP_SHAKE)) {
- lprintf(("&"));
- lptintr(ifp->if_unit);
- }
-
- /* Alert other end to pending packet */
- spin = LPMAXSPIN1;
- outb(lpt_data_port, 0x08);
- while ((inb(lpt_stat_port) & 0x08) == 0)
- if (--spin == 0) {
- goto nend;
- }
-
- /* Calculate length of packet, then send that */
-
- count += 14; /* Ethernet header len */
-
- mm = m;
- for (mm = m; mm; mm = mm->m_next) {
- count += mm->m_len;
- }
- if (clpoutbyte(count & 0xFF, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto nend;
- if (clpoutbyte((count >> 8) & 0xFF, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto nend;
-
- /* Send dummy ethernet header */
- for (i = 0; i < 12; i++) {
- if (clpoutbyte(i, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto nend;
- chksum += i;
- }
-
- if (clpoutbyte(0x08, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto nend;
- if (clpoutbyte(0x00, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto nend;
- chksum += 0x08 + 0x00; /* Add into checksum */
-
- mm = m;
- do {
- cp = mtod(mm, u_char *);
- while (mm->m_len--) {
- chksum += *cp;
- if (clpoutbyte(*cp++, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
- goto nend;
- }
- } while ((mm = mm->m_next));
-
- /* Send checksum */
- if (clpoutbyte(chksum, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
- goto nend;
-
- /* Go quiescent */
- outb(lpt_data_port, 0);
-
- err = 0; /* No errors */
-
- nend:
- if (err) { /* if we didn't timeout... */
- ifp->if_oerrors++;
- lprintf(("X"));
- } else {
- ifp->if_opackets++;
- ifp->if_obytes += m->m_pkthdr.len;
- }
-
- m_freem(m);
-
- if (!(inb(lpt_stat_port) & CLPIP_SHAKE)) {
- lprintf(("^"));
- lptintr(ifp->if_unit);
- }
- (void) splx(s);
- return 0;
- }
-
- if (inb(lpt_stat_port) & LPIP_SHAKE) {
- lprintf(("&"));
- lptintr(ifp->if_unit);
- }
-
- if (lpoutbyte(0x08, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
- goto end;
- if (lpoutbyte(0x00, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
- goto end;
-
- mm = m;
- do {
- cp = mtod(mm,u_char *);
- while (mm->m_len--)
- if (lpoutbyte(*cp++, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
- goto end;
- } while ((mm = mm->m_next));
-
- err = 0; /* no errors were encountered */
-
- end:
- --cp;
- outb(lpt_data_port, txmitl[*cp] ^ 0x17);
-
- if (err) { /* if we didn't timeout... */
- ifp->if_oerrors++;
- lprintf(("X"));
- } else {
- ifp->if_opackets++;
- ifp->if_obytes += m->m_pkthdr.len;
- 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);
- }
- }
-
- m_freem(m);
-
- if (inb(lpt_stat_port) & LPIP_SHAKE) {
- lprintf(("^"));
- lptintr(ifp->if_unit);
- }
-
- (void) splx(s);
- return 0;
-}
-
-#endif /* INET */
OpenPOWER on IntegriCloud