NetBSD Problem Report #1278

From gnats  Wed Jul 26 00:40:14 1995
Received: from linteuto.teuto.de (root@linteuto.teuto.de [194.77.23.26]) by sun-lamp.pc.cs.cmu.edu (8.6.11/8.6.10) with SMTP id AAA05125 for <gnats-bugs@gnats.netbsd.org>; Wed, 26 Jul 1995 00:40:08 -0400
Message-Id: <199507252046.WAA00451@rumolt.teuto.de>
Date: Tue, 25 Jul 1995 22:46:25 +0200
From: martin@rumolt.teuto.de
Reply-To: martin@rumolt.teuto.de
To: gnats-bugs@gnats.netbsd.org
Subject: i386 has no PLIP interface
X-Send-Pr-Version: 3.2

>Number:         1278
>Category:       port-i386
>Synopsis:       add a PLIP interface to i386 parallel driver
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    martin
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 26 00:50:04 +0000 1995
>Closed-Date:    Mon Feb 17 00:57:20 +0000 2003
>Last-Modified:  Mon Feb 17 00:57:20 +0000 2003
>Originator:     Martin Husemann
>Release:        19950720
>Organization:
private
>Environment:
System: NetBSD rumolt.teuto.de 1.0A NetBSD 1.0A (RUMOLT) #4: Tue Jul 25 21:58:06 MET DST 1995 root@rumolt.teuto.de:/usr/src/sys/arch/i386/compile/RUMOLT i386


>Description:

While the pc532 port provides PLIP in its lpt.c driver (which was developed
from the i386 lpt.c driver), the i386 doesn't. (Just in case you don't
know: PLIP is the parallel IP protocol, used originaly by Russel Nelson's
Crynwr packet driver for DOS. It emulates ethernet using a LapLink(tm)
cable connecting two parallel ports.)


>How-To-Repeat:

ifconfig -a
and watch the missing "plip0" line.

>Fix:

Reintegrate the PLIP parts of the pc532's lpt.c into sys/dev/isa/lpt.c.
The following patch does this. It works for me. I didn't stress-test it
yet. I didn't test it with PLIP_COMPAT10 defined.

To use it define options INET and PLIP in your kernel config file. Make
sure you have at least one ethernet driver configured to pull in the
generic ethernet support. (How do you tell "config" to require "ether"
on lpt.c if INET and PLIP are defined?)


*** lpt.c.orig	Sun Jul 23 10:36:56 1995
--- lpt.c	Tue Jul 25 21:57:38 1995
***************
*** 1,8 ****
--- 1,10 ----
  /*	$NetBSD: lpt.c,v 1.30 1995/04/17 12:09:17 cgd Exp $	*/

  /*
+  * Copyright (c) 1994 Matthias Pfaller.
+  * Copyright (c) 1994 Poul-Henning Kamp
   * Copyright (c) 1993, 1994 Charles Hannum.
   * Copyright (c) 1990 William F. Jolitz, TeleMuse
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
***************
*** 62,71 ****
--- 64,87 ----
  #include <sys/ioctl.h>
  #include <sys/uio.h>
  #include <sys/device.h>
  #include <sys/syslog.h>

+ #if defined(INET) && defined(PLIP)
+ #include <sys/mbuf.h>
+ #include <sys/socket.h>
+ #include <net/if.h>
+ #include <net/if_types.h>
+ #include <net/netisr.h>
+ #include <net/route.h>
+ #include <netinet/in.h>
+ #include <netinet/in_systm.h>
+ #include <netinet/in_var.h>
+ #include <netinet/ip.h>
+ #include <netinet/if_ether.h>
+ #endif
+ 
  #include <machine/cpu.h>
  #include <machine/pio.h>

  #include <dev/isa/isavar.h>
  #include <dev/isa/lptreg.h>
***************
*** 74,83 ****
--- 90,127 ----
  #define	STEP		hz/4

  #define	LPTPRI		(PZERO+8)
  #define	LPT_BSIZE	1024

+ #if defined(INET) && defined(PLIP)
+ #ifndef PLIPMTU			/* MTU for the plip# interfaces */
+ #if defined(COMPAT_PLIP10)
+ #define	PLIPMTU		1600
+ #else
+ #define	PLIPMTU		(ETHERMTU - ifp->if_hdrlen)
+ #endif
+ #endif
+ 
+ #ifndef PLIPMXSPIN1		/* DELAY factor for the plip# interfaces */
+ #define	PLIPMXSPIN1	2000	/* Spinning for remote intr to happen */
+ #endif
+ 
+ #ifndef PLIPMXSPIN2		/* DELAY factor for the plip# interfaces */
+ #define	PLIPMXSPIN2	6000	/* Spinning for remote handshake to happen */
+ #endif
+ 
+ #ifndef PLIPMXERRS		/* Max errors before !RUNNING */
+ #define	PLIPMXERRS	20
+ #endif
+ #ifndef PLIPMXRETRY
+ #define PLIPMXRETRY	20	/* Max number of retransmits */
+ #endif
+ #ifndef PLIPRETRY
+ #define PLIPRETRY	hz/50	/* Time between retransmits */
+ #endif
+ #endif
+ 
  #if !defined(DEBUG) || !defined(notdef)
  #define lprintf
  #else
  #define lprintf		if (lptdebug) printf
  int lptdebug = 1;
***************
*** 101,116 ****
--- 145,178 ----
  #define	LPT_AUTOLF	0x20	/* automatic LF on CR */
  #define	LPT_NOPRIME	0x40	/* don't prime on open */
  #define	LPT_NOINTR	0x80	/* do not use interrupt */
  	u_char sc_control;
  	u_char sc_laststatus;
+ 
+ #if defined(INET) && defined(PLIP)
+ 	struct	arpcom	sc_arpcom;
+ 	u_char		*sc_ifbuf;
+ 	int		sc_ifierrs;	/* consecutive input errors */
+ 	int		sc_ifoerrs;	/* consecutive output errors */
+ #if defined(COMPAT_PLIP10)
+ 	u_char		sc_adrcksum;
+ #endif
+ #endif
  };

  int lptprobe __P((struct device *, void *, void *));
  void lptattach __P((struct device *, struct device *, void *));
  int lptintr __P((void *));

+ #if defined(INET) && defined(PLIP)
+ /* Functions for the plip# interface */
+ static void plipattach(struct lpt_softc *,int);
+ static int plipioctl(struct ifnet *, u_long, caddr_t);
+ static void plipstart(struct ifnet *);
+ static void plipintr(struct lpt_softc *);
+ #endif
+ 
  struct cfdriver lptcd = {
  	NULL, "lpt", lptprobe, lptattach, DV_TTY, sizeof(struct lpt_softc)
  };

  #define	LPTUNIT(s)	(minor(s) & 0x1f)
***************
*** 235,247 ****
--- 297,315 ----
  	sc->sc_iobase = iobase;
  	sc->sc_irq = ia->ia_irq;
  	sc->sc_state = 0;
  	outb(iobase + lpt_control, LPC_NINIT);

+ #if defined(INET) && defined(PLIP)
+ 	plipattach(sc, self->dv_unit);
+ 	sc->sc_ih = isa_intr_establish(ia->ia_irq, ISA_IST_EDGE,
+ 				       ISA_IPL_NET, lptintr, sc);
+ #else
  	if (ia->ia_irq != IRQUNK)
  		sc->sc_ih = isa_intr_establish(ia->ia_irq, ISA_IST_EDGE,
  		    ISA_IPL_NONE, lptintr, sc);
+ #endif
  }

  /*
   * Reset the printer, then wait until it's selected and not busy.
   */
***************
*** 483,492 ****
--- 551,567 ----
  	void *arg;
  {
  	struct lpt_softc *sc = arg;
  	int iobase = sc->sc_iobase;

+ #if defined(INET) && defined(PLIP)
+ 	if(sc->sc_arpcom.ac_if.if_flags & IFF_UP) {
+ 		plipintr(sc);
+ 		return;
+ 	}
+ #endif
+ 
  #if 0
  	if ((sc->sc_state & LPT_OPEN) == 0)
  		return 0;
  #endif

***************
*** 527,531 ****
--- 602,1012 ----
  		error = ENODEV;
  	}

  	return error;
  }
+ 
+ #if defined(INET) && defined(PLIP)
+ 
+ static void
+ plipattach(struct lpt_softc *sc, int unit)
+ {
+ 	struct ifnet *ifp = &sc->sc_arpcom.ac_if;
+ 
+ 	sc->sc_ifbuf = NULL;
+ 	ifp->if_unit = unit;
+ 	ifp->if_name = "plip";
+ 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
+ 	ifp->if_output = ether_output;
+ 	ifp->if_start = plipstart;
+ 	ifp->if_ioctl = plipioctl;
+ 	ifp->if_watchdog = 0;
+ 
+ 	ifp->if_type = IFT_ETHER;
+ 	ifp->if_addrlen = 6;
+ 	ifp->if_hdrlen = 14;
+ 	ifp->if_mtu = PLIPMTU;
+ 
+ 	if_attach(ifp);
+ }
+ 
+ /*
+  * Process an ioctl request.
+  */
+ static int
+ plipioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+ {
+         struct proc *p = curproc;
+ 	struct lpt_softc *sc = (struct lpt_softc *) lptcd.cd_devs[ifp->if_unit];
+ 	int iobase = sc->sc_iobase;
+ 	u_char control = sc->sc_control;
+ 	struct ifaddr *ifa = (struct ifaddr *)data;
+ 	struct ifreq *ifr = (struct ifreq *)data; 
+ 	int s;
+ 	int error = 0;
+ 
+ 	switch (cmd) {
+ 
+ 	case SIOCSIFFLAGS:
+ 		if (((ifp->if_flags & IFF_UP) == 0) &&
+ 		    (ifp->if_flags & IFF_RUNNING)) {
+ 		        ifp->if_flags &= ~IFF_RUNNING;
+ 			control = LPC_SELECT | LPC_NINIT;
+ 			outb(iobase + lpt_control, control);
+ 
+ 			if (sc->sc_ifbuf)
+ 				free(sc->sc_ifbuf, M_DEVBUF);
+ 			sc->sc_ifbuf = NULL;
+ 		}
+ 		if (((ifp->if_flags & IFF_UP)) &&
+ 		    ((ifp->if_flags & IFF_RUNNING) == 0)) {
+ 			if (sc->sc_state) {
+ 				error = EBUSY;
+ 				break;
+ 			}
+ 			if (!sc->sc_ifbuf)
+ 				sc->sc_ifbuf =
+ 					malloc(ifp->if_mtu + ifp->if_hdrlen,
+ 					       M_DEVBUF, M_WAITOK);
+ 		        ifp->if_flags |= IFF_RUNNING;
+ 			control &= ~LPC_IENABLE;
+ 			outb(iobase + lpt_control, control);
+ 			outb(iobase + lpt_data, 0);
+ 			control |= LPC_IENABLE;
+ 			outb(iobase + lpt_control, control);
+ 		}
+ 		break;
+ 
+ 	case SIOCSIFADDR:
+ 		if (ifa->ifa_addr->sa_family == AF_INET) {
+ 			if (!sc->sc_ifbuf)
+ 				sc->sc_ifbuf =
+ 					malloc(PLIPMTU + ifp->if_hdrlen,
+ 					       M_DEVBUF, M_WAITOK);
+ 			sc->sc_arpcom.ac_enaddr[0] = 0xfc;
+ 			sc->sc_arpcom.ac_enaddr[1] = 0xfc;
+ 			bcopy((caddr_t)&IA_SIN(ifa)->sin_addr,
+ 			      (caddr_t)&sc->sc_arpcom.ac_enaddr[2], 4);
+ 			sc->sc_arpcom.ac_ipaddr = IA_SIN(ifa)->sin_addr;
+ #if defined(COMPAT_PLIP10)
+ 			if (ifp->if_flags & IFF_LINK0) {
+ 				int i;
+ 				sc->sc_arpcom.ac_enaddr[0] = 0xfd;
+ 				sc->sc_arpcom.ac_enaddr[1] = 0xfd;
+ 				for (i = sc->sc_adrcksum = 0; i < 5; i++)
+ 					sc->sc_adrcksum += sc->sc_arpcom.ac_enaddr[i];
+ 				sc->sc_adrcksum *= 2;
+ 			}
+ #endif
+ 			ifp->if_flags |= IFF_RUNNING | IFF_UP;
+ #if 0
+ 			for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
+ 				struct sockaddr_dl *sdl;
+ 				if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) &&
+ 				    sdl->sdl_family == AF_LINK) {
+ 					sdl->sdl_type = IFT_ETHER;
+ 					sdl->sdl_alen = ifp->if_addrlen;
+ 					bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr,
+ 					      LLADDR(sdl), ifp->if_addrlen);
+ 					break;
+ 				    }
+ 			}
+ #endif
+ 			control &= ~LPC_IENABLE;
+ 			outb(iobase + lpt_control, control);
+ 			outb(iobase + lpt_data, 0);
+ 			control |= LPC_IENABLE;
+ 			outb(iobase + lpt_control, control);
+ 
+ 			arp_ifinit(&sc->sc_arpcom, ifa);
+ 		} else
+ 			error = EAFNOSUPPORT;
+ 		break;
+ 
+ 	case SIOCAIFADDR:
+ 	case SIOCDIFADDR:
+ 	case SIOCSIFDSTADDR:
+ 		if (ifa->ifa_addr->sa_family != AF_INET)
+ 			error = EAFNOSUPPORT;
+ 		break;
+ 
+ 	case SIOCSIFMTU:
+         	if ((error = suser(p->p_ucred, &p->p_acflag)))
+             		return(error);
+ 		if (ifp->if_mtu != ifr->ifr_metric) {
+ 		        ifp->if_mtu = ifr->ifr_metric;
+ 			if (sc->sc_ifbuf) {
+ 				s = splimp();
+ 				free(sc->sc_ifbuf, M_DEVBUF);
+ 				sc->sc_ifbuf =
+ 					malloc(ifp->if_mtu + ifp->if_hdrlen,
+ 					       M_DEVBUF, M_WAITOK);
+ 				splx(s);
+ 			}
+ 		}
+ 		break;
+ 
+         case SIOCGIFMTU:
+ 	        ifr->ifr_metric = ifp->if_mtu;
+ 		break;
+ 
+ 	default:
+ 		error = EINVAL;
+ 	}
+ 	sc->sc_control = control;
+ 	return (error);
+ }
+ 
+ static int
+ plipreceive(int iobase, u_char *buf, int len)
+ {
+ 	int num = len;
+ 	int i;
+ 	u_char cksum = 0, c;
+ 
+ 	while (len--) {
+ 		i = PLIPMXSPIN2;
+ 		while ((inb(iobase + lpt_status) & LPS_NBSY) != 0)
+ 			if (i-- < 0) return -1;
+ 		c = (inb(iobase + lpt_status) >> 3) & 0x0f;
+ 		outb(iobase + lpt_data, 0x11);
+ 		while ((inb(iobase + lpt_status) & LPS_NBSY) == 0)
+ 			if (i-- < 0) return -1;
+ 		c |= (inb(iobase + lpt_status) << 1) & 0xf0;
+ 		outb(iobase + lpt_data, 0x01);
+ 		cksum += (*buf++ = c);
+ 	}
+ 	return(cksum);
+ }
+ 
+ static void
+ plipintr(struct lpt_softc *sc)
+ {
+ 	extern struct mbuf *m_devget(char *, int, int, struct ifnet *, void (*)());
+ 	struct ifnet *ifp = &sc->sc_arpcom.ac_if;
+ 	int iobase = sc->sc_iobase;
+ 	struct mbuf *m;
+ 	struct ether_header *eh;
+ 	u_char *p = sc->sc_ifbuf, minibuf[4];
+ 	int c, i = 0, s, len, cksum;
+ 
+ 	outb(iobase + lpt_control, sc->sc_control & ~LPC_IENABLE);
+ 	outb(iobase + lpt_data, 0x01);
+ 
+ #if defined(COMPAT_PLIP10)
+ 	if (ifp->if_flags & IFF_LINK0) {
+ 		if (plipreceive(iobase, minibuf, 3) < 0) goto err;
+ 		len = (minibuf[1] << 8) | minibuf[2];
+ 		if (len > (ifp->if_mtu + ifp->if_hdrlen)) goto err;
+ 
+ 		switch (minibuf[0]) {
+ 		case 0xfc:
+ 			p[0] = p[ 6] = ifp->ac_enaddr[0];
+ 			p[1] = p[ 7] = ifp->ac_enaddr[1];
+ 			p[2] = p[ 8] = ifp->ac_enaddr[2];
+ 			p[3] = p[ 9] = ifp->ac_enaddr[3];
+ 			p[4] = p[10] = ifp->ac_enaddr[4];
+ 			p += 5;
+ 			if ((cksum = plipreceive(iobase, p, 1)) < 0) goto err;
+ 			p += 6;
+ 			if ((c = plipreceive(iobase, p, len - 11)) < 0) goto err;
+ 			cksum += c + sc->sc_adrcksum;
+ 			c = p[1]; p[1] = p[2]; p[2] = c;
+ 			cksum &= 0xff;
+ 			break;
+ 		case 0xfd:
+ 			if ((cksum = plipreceive(iobase, p, len)) < 0) goto err;
+ 			break;
+ 		default:
+ 			goto err;
+ 		}
+ 	} else
+ #endif
+ 	{
+ 		if (plipreceive(iobase, minibuf, 2) < 0) goto err;
+ 		len = (minibuf[1] << 8) | minibuf[0];
+ 		if (len > (ifp->if_mtu + ifp->if_hdrlen)) {
+ 			log(LOG_NOTICE, "plip%d: packet > MTU\n", ifp->if_unit);
+ 			goto err;
+ 		}
+ 		if ((cksum = plipreceive(iobase, p, len)) < 0) goto err;
+ 	}
+ 	
+ 	if (plipreceive(iobase, minibuf, 1) < 0) goto err;
+ 	if (cksum != minibuf[0]) {
+ 		log(LOG_NOTICE, "plip%d: checksum error\n", ifp->if_unit);
+ 		goto err;
+ 	}
+ 	outb(iobase + lpt_data, 0x00);
+ 
+ 	s = splimp();
+ 	if (m = m_devget(sc->sc_ifbuf, len, 0, ifp, NULL)) {
+ 		/* We assume that the header fit entirely in one mbuf. */
+ 		eh = mtod(m, struct ether_header *);
+ 		m->m_pkthdr.len -= sizeof(*eh);
+ 		m->m_len -= sizeof(*eh);
+ 		m->m_data += sizeof(*eh);
+ 		ether_input(ifp, eh, m);
+ 	}
+ 	splx(s);
+ 	sc->sc_ifierrs = 0;
+ 	ifp->if_ipackets++;
+ 	outb(iobase + lpt_control, sc->sc_control);
+ 	return;
+ 
+ err:
+ 	outb(iobase + lpt_data, 0x00);
+ 
+ 	if (sc->sc_ifierrs < PLIPMXERRS) {
+ 		if (sc->sc_ifierrs > 4 && (inb(iobase + lpt_status) & LPS_NBSY)) {
+ 			/* Avoid interrupt nesting ... */
+ 			sc->sc_ifierrs = PLIPMXERRS - 1;
+ 		}
+ 		outb(iobase + lpt_control, sc->sc_control);
+ 	} else {
+ 		/* We are not able to send receive anything for now,
+ 		 * so stop wasting our time and leave the interrupt
+ 		 * disabled.
+ 		 */
+ 		if (sc->sc_ifierrs == PLIPMXERRS)
+ 			log(LOG_NOTICE, "plip%d: rx hard error\n", ifp->if_unit);
+ 	}
+ 	ifp->if_ierrors++;
+ 	sc->sc_ifierrs++;
+ 	return;
+ }
+ 
+ static int
+ pliptransmit(int iobase, u_char *buf, int len)
+ {
+ 	int num = len;
+ 	int i;
+ 	u_char cksum = 0, c;
+ 
+ 	while (len--) {
+ 		i = PLIPMXSPIN2;
+ 		cksum += (c = *buf++);
+ 		while ((inb(iobase + lpt_status) & LPS_NBSY) == 0)
+ 			if (i-- < 0) return -1;
+ 		outb(iobase + lpt_data, c & 0x0f);
+ 		outb(iobase + lpt_data, c & 0x0f | 0x10);
+ 		c >>= 4;
+ 		while ((inb(iobase + lpt_status) & LPS_NBSY) != 0)
+ 			if (i-- < 0) return -1;
+ 		outb(iobase + lpt_data, c | 0x10);
+ 		outb(iobase + lpt_data, c);
+ 	}
+ 	return(cksum);
+ }
+ 
+ /*
+  * Setup output on interface.
+  */
+ static void
+ plipstart(struct ifnet *ifp)
+ {
+ 	struct lpt_softc *sc = (struct lpt_softc *) lptcd.cd_devs[ifp->if_unit];
+ 	int iobase = sc->sc_iobase;
+ 	struct mbuf *m0, *m;
+ 	u_char minibuf[4], cksum;
+ 	int len, i, s;
+ 
+ 	if (ifp->if_flags & IFF_OACTIVE)
+ 		return;
+ 	ifp->if_flags |= IFF_OACTIVE;
+ 
+ 	if (sc->sc_ifoerrs)
+ 		untimeout((void (*)(void *))plipstart, ifp);
+ 
+ 	for (;;) {
+ 		s = splimp();
+ 		IF_DEQUEUE(&ifp->if_snd, m0);
+ 		splx(s);
+ 		if (!m0)
+ 			break;
+ 
+ 		for (len = 0, m = m0; m; m = m->m_next)
+ 			len += m->m_len;
+ #if defined(COMPAT_PLIP10)
+ 		if (ifp->if_flags & IFF_LINK0) {
+ 			minibuf[0] = 3;
+ 			minibuf[1] = 0xfd;
+ 			minibuf[2] = len >> 8;
+ 			minibuf[3] = len;
+ 		} else
+ #endif
+ 		{
+ 			minibuf[0] = 2;
+ 			minibuf[1] = len;
+ 			minibuf[2] = len >> 8;
+ 		}
+ 
+ 		for (i = PLIPMXSPIN1; (inb(iobase + lpt_status) & LPS_NERR) != 0; i--)
+ 			if (i < 0) goto retry;
+ 
+ 		/* Trigger remote interrupt */
+ 		sc->sc_control &= ~LPC_IENABLE;
+ 		outb(iobase + lpt_control, sc->sc_control);
+ 		outb(iobase + lpt_data, 0x08);
+ 
+ 		for (i = PLIPMXSPIN1; (inb(iobase + lpt_status) & LPS_NERR) == 0; i--)
+ 			if (i < 0 || (i > PLIPMXSPIN1/3
+ 			    && inb(iobase + lpt_status) & LPS_NACK)) 
+ 				goto retry;
+ 
+ 		if (pliptransmit(iobase, minibuf + 1, minibuf[0]) < 0) goto retry;
+ 		for (cksum = 0, m = m0; m; m = m->m_next) {
+ 			i = pliptransmit(iobase, mtod(m, u_char *), m->m_len);
+ 			if (i < 0) goto retry;
+ 			cksum += i;
+ 		}
+ 		if (pliptransmit(iobase, &cksum, 1) < 0) goto retry;
+ 		i = PLIPMXSPIN2;
+ 		while ((inb(iobase + lpt_status) & LPS_NBSY) == 0)
+ 			if (i-- < 0) goto retry;
+ 		outb(iobase + lpt_data, 0x00);
+ 
+ 		ifp->if_opackets++;
+ 		ifp->if_obytes += len + 4;
+ 		sc->sc_ifoerrs = 0;
+ 		s = splimp();
+ 		m_freem(m0);
+ 		splx(s);
+ 		sc->sc_control |= LPC_IENABLE;
+ 		outb(iobase + lpt_control, sc->sc_control);
+ 	}
+ 	ifp->if_flags &= ~IFF_OACTIVE;
+ 	return;
+ 
+ retry:
+ 	if (inb(iobase + lpt_status) & LPS_NACK)
+ 		ifp->if_collisions++;
+ 	else
+ 		ifp->if_oerrors++;
+ 	if ((ifp->if_flags & (IFF_RUNNING | IFF_UP)) == (IFF_RUNNING | IFF_UP)
+ 	    && sc->sc_ifoerrs < PLIPMXRETRY) {
+ 		s = splimp();
+ 		IF_PREPEND(&ifp->if_snd, m0);
+ 		splx(s);
+ 		timeout((void (*)(void *))plipstart, ifp, PLIPRETRY);
+ 	} else {
+ 		if (sc->sc_ifoerrs == PLIPMXRETRY) {
+ 			log(LOG_NOTICE, "plip%d: tx hard error\n", ifp->if_unit);
+ 		}
+ 		s = splimp();
+ 		m_freem(m0);
+ 		splx(s);
+ 	}
+ 	sc->sc_ifoerrs++;
+ 	ifp->if_flags &= ~IFF_OACTIVE;
+ 	outb(iobase + lpt_data, 0x00);
+ 	if (sc->sc_ifierrs >= PLIPMXERRS)
+ 	       ;
+ 	else
+ 	{
+ 		sc->sc_control |= LPC_IENABLE;
+ 		outb(iobase + lpt_control, sc->sc_control);
+ 	}
+ 	return;
+ }
+ 
+ #endif
>Release-Note:
>Audit-Trail:

From: David Brownlee <D.K.Brownlee@city.ac.uk>
To: martin@rumolt.teuto.de
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: port-i386/1278: i386 has no PLIP interface
Date: Wed, 26 Jul 1995 10:03:28 +0100 (BST)

 	Is there any chance of coming up with a more device independant
 	PLIP driver that all ports could use - a large part of the pc532 
 	& i386 code must be common, so even extracting that common part 
 	would be a start?

 		David

  D.K.Brownlee@city.ac.uk (MIME) +44 171 477 8186  {post,host}master  (abs)
 Network Analyst, UCS, City University, Northampton Square, London EC1V 0HB.
  <<< Monochrome - Largest UK Internet BBS - try telnet mono.city.ac.uk >>>


From: Martin Husemann <martin@rumolt.teuto.de>
To: D.K.Brownlee@city.ac.uk (David Brownlee)
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: port-i386/1278: i386 has no PLIP interface
Date: Thu, 27 Jul 1995 06:18:52 +0200 (MET DST)

 > 	Is there any chance of coming up with a more device independant
 > 	PLIP driver that all ports could use - a large part of the pc532 
 > 	& i386 code must be common, so even extracting that common part 
 > 	would be a start?

 Yes, next step will be a architecture independend solution for plip
 and other parallel port line disciplines. The interface is not yet
 clear to me, I'm going to discuss this with tech-kernel....


 Martin

From: Martin Husemann <martin@rumolt.teuto.de>
To: gnats-bugs@gnats.NetBSD.ORG
Cc:  Subject: Re: port-i386/1278
Date: Fri, 9 Jan 1998 08:35:48 +0100 (MET)

 This is an update of the PLIP stuff for port i386 to NetBSD 1.3.
 By accident I appended this to the duplicate (port-i386/1516) a 
 few days ago - but it belongs to this PR.

 In case the enclosed patches are munged by gnats or the html query script,
 you should be able to get a version from

 http://homepages.teuto.net/martin/plip-NetBSD-i386-1.3.tar.gz

 but I'm not yet realy sure, if that works due to config problems at
 my ISP. Ask me for a copy if it doesn't...


 Martin

 # This is a shell archive.  Save it in a file, remove anything before
 # this line, and then unpack it by entering "sh file".  Note, it may
 # create directories; files and directories will be owned by you and
 # have default permissions.
 #
 # This archive contains:
 #
 #	plip.4
 #	plip.patch
 #
 echo x - plip.4
 sed 's/^X//' >plip.4 << 'END-of-plip.4'
 X.\"
 X.\" Copyright (c) 1997, 1998 Martin Husemann <martin@rumolt.teuto.de>
 X.\" All rights reserved.
 X.\"
 X.\" Redistribution and use in source and binary forms, with or without
 X.\" modification, are permitted provided that the following conditions
 X.\" are met:
 X.\" 1. Redistributions of source code must retain the above copyright
 X.\"    notice, this list of conditions and the following disclaimer.
 X.\" 2. The name of the author may not be used to endorse or promote products
 X.\"    derived from this software withough specific prior written permission
 X.\"
 X.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 X.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 X.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 X.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 X.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 X.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 X.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 X.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 X.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 X.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 X.\"
 X.Dd
 X.Dt PLIP 4 i386
 X.Os
 X.Sh NAME
 X.Nm plip
 X.Nd Networking via the standard PC parallel port
 X.Sh SYNOPSIS
 X.Cd "options PLIP"
 X.Cd "#options PLIP_NO_INCOLL # might help if not working otherwise"
 X.Cd "lpt0 at isa? port 0x378 irq 7"
 X.Cd "lpt1 at isa? port 0x278 irq 5"
 X.Cd "lpt2 at isa? port 0x3bc irq 5"
 X.sp
 XThe
 X.Nm
 Xnetwork interface shows up as \fBplip0\fP when using \fBlpt0\fP, as
 X\fBplip1\fP when using \fBlpt1\fP and \fBplip2\fP when using \fBlpt2\fP.
 X.sp
 XA parallel port can not drive a 
 X.Nm
 Xinterface when configured without an irq. The port can be used to drive
 Xother devices when the corresponding 
 X.Nm
 Xinterface is configured down.
 X.Sh DESCRIPTION
 XThe
 X.Nm
 Xinterface simulates Ethernet on a parallel cable with special wiring (see
 Xbelow), known as a
 X.Ar "parallel LapLink cable" 
 Xwidely available from PC shops.
 X
 XIt's acronym is derived from SLIP and means
 X.Ar "Parallel IP Protocol",
 Xwhich, in fact, is wrong: it can handle any protocol available on
 Xethernet, not just IP.
 X
 XAlthough a
 X.Nm
 Xconnection always is point-to-point, the interface is configured
 Xlike every standard ethernet interface and uses 
 X.Ar ARP
 Xto find its neighbour. This is inefficient, but provides interoperability
 Xwith other operating systems.
 X.Sh INTEROPERABILITY
 X.Nm
 Xuses the
 X.Ar "Crynwr protocol"
 Xdefined by Russel Nelson. This make it interoperable with the DOS
 Xpacket driver
 X.Ar "PLIP.COM"
 Xand Linux (make sure to configure the interface to use
 X.Ar ARP
 Xwhen connecting to a Linux system.)
 X.Sh WIRING
 XThe following describes the connection of two male 25 pin sub-D connectors
 Xwhich fit into standard PC parallel ports (no, PC's don't use Centronics
 Xconnectors).
 X
 X.Bl -tag -width -offset -indent -compact
 X.It INIT(16) - INIT(16)
 X.It SLCTIN(17) - SLCTIN(17)
 X.It GROUND(25) - GROUND(25)
 X.It D0(2) - ERROR(15)
 X.It D1(3) - SLCT(13)
 X.It D2(4) - PAPOUT(12)
 X.It D3(5) - ACK(10)
 X.It D4(6) - BUSY(11)
 X.El
 X
 XAdditional grounds are 18, 19, 20, 21, 22, 23 and 24.
 XDo not connect D5(7), D6(8), D7(9), STROBE(1) and FEED(14).
 X.Sh BUGS
 XThe driver uses a hardcoded network softinterrupt, which is the only
 Xthing that makes it i386 architecture dependend. As soon as generic
 Xsoftinterrupt allocation is available, this should be changed, which
 Xwould make the driver machine independend (but still dependend on the
 XISA parallel port architecture).
 X.sp
 XThe protocol is too much overhead, a bidirectional input/output
 Xroutine switchable to a well-designed network line discipline
 Xwith on-line compression would be far superiour.
 X
 XThere are some parallel ports which can use all 8 data bits for input
 Xand output, you can make up a parallel handshake protocol and a cable
 Xwith different wiring to get an 8 bit clean (instead of 4 bit now) 
 Xdata path out of this. This is currently not supported.
 X
 XThere is apparently work on the way (the parbus) which will integrate
 Xthis and other paralell-port devices (zip drives e.a.) more smoothley.
 X.Sh HINTS
 XGo buy a pocket ethernet adaptor or a PCMCIA ethernet adaptor and
 Xwrite a driver for it. It's much better throughput, lesser load and
 Xa less coupled system between client and server.
 X.Sh AUTHORS
 XMatthias Pfaller wrote the original \fBpc532\fP version.
 XMartin Husemann ported it to the \fBi386\fP.
 X.Sh SEE ALSO
 X.Xr ifconfig 8
 X.Xr slip 8
 X.Xr pppd 8
 END-of-plip.4
 echo x - plip.patch
 sed 's/^X//' >plip.patch << 'END-of-plip.patch'
 Xdiff -rc2 /tmp/sys/arch/i386/isa/icu.s sys/arch/i386/isa/icu.s
 X*** /tmp/sys/arch/i386/isa/icu.s	Tue Nov 18 13:49:40 1997
 X--- sys/arch/i386/isa/icu.s	Sat Jan  3 12:33:07 1998
 X***************
 X*** 177,180 ****
 X--- 177,186 ----
 X  	DONET(NETISR_PPP, _pppintr)
 X  #endif
 X+ #include "lpt.h"
 X+ #if NLPT > 0
 X+ #ifdef PLIP
 X+ 	DONET(NETISR_PLIP, _plipsoftint)
 X+ #endif
 X+ #endif
 X  	movl	%ebx,_cpl
 X  	jmp	%esi
 Xdiff -rc2 /tmp/sys/dev/ic/lpt.c sys/dev/ic/lpt.c
 X*** /tmp/sys/dev/ic/lpt.c	Mon Dec  8 13:27:55 1997
 X--- sys/dev/ic/lpt.c	Sat Jan  3 12:33:07 1998
 X***************
 X*** 2,5 ****
 X--- 2,7 ----
 X  
 X  /*
 X+  * Copyright (c) 1994 Matthias Pfaller.
 X+  * Copyright (c) 1994 Poul-Henning Kamp
 X   * Copyright (c) 1993, 1994 Charles Hannum.
 X   * Copyright (c) 1990 William F. Jolitz, TeleMuse
 X***************
 X*** 69,72 ****
 X--- 71,96 ----
 X  #include <machine/intr.h>
 X  
 X+ #if defined(INET) && defined(PLIP)
 X+ #include "bpfilter.h"
 X+ #include <sys/mbuf.h>
 X+ #include <sys/socket.h>
 X+ 
 X+ #include <net/if.h>
 X+ #include <net/if_dl.h>
 X+ #include <net/if_types.h>
 X+ #include <net/if_ether.h>
 X+ #include <net/netisr.h>
 X+ 
 X+ #include <netinet/in.h>
 X+ #include <netinet/in_systm.h>
 X+ #include <netinet/in_var.h>
 X+ #include <netinet/ip.h>
 X+ #include <netinet/if_inarp.h>
 X+ #if NBPFILTER > 0
 X+ #include <sys/time.h>
 X+ #include <net/bpf.h>
 X+ #endif
 X+ #endif
 X+ 
 X  #include <dev/ic/lptreg.h>
 X  #include <dev/ic/lptvar.h>
 X***************
 X*** 87,90 ****
 X--- 111,165 ----
 X  #endif
 X  
 X+ #if defined(INET) && defined(PLIP)
 X+ #if defined(COMPAT_PLIP10)
 X+ #define	PLIPMTU		1600				/* Linux 1.0.x */
 X+ #elif defined(COMPAT_PLIP11)
 X+ #define	PLIPMTU		(ETHERMTU - ifp->if_hdrlen)	/* Linux 1.1.x */
 X+ #else
 X+ #define PLIPMTU		ETHERMTU			/* Linux 1.3.x */
 X+ #endif
 X+ 
 X+ #ifndef PLIPMXSPIN1		/* DELAY factor for the plip# interfaces */
 X+ #define	PLIPMXSPIN1	50000	/* Spinning for remote intr to happen */
 X+ #endif
 X+ 
 X+ #ifndef PLIPMXSPIN2		/* DELAY factor for the plip# interfaces */
 X+ #define	PLIPMXSPIN2	50000	/* Spinning for remote handshake to happen */
 X+ #endif
 X+ 
 X+ #ifndef PLIPMXERRS		/* Max errors before !RUNNING */
 X+ #define	PLIPMXERRS	50
 X+ #endif
 X+ #ifndef PLIPMXRETRY
 X+ #define PLIPMXRETRY	20	/* Max number of retransmits */
 X+ #endif
 X+ #ifndef PLIPRETRY
 X+ #define PLIPRETRY	hz/50	/* Time between retransmits */
 X+ #endif
 X+ 
 X+ #define STABILIZE(iot, ioh, io) ({ \
 X+ 		int v1, v2; \
 X+ 		v2 = bus_space_read_1(iot, ioh, io); \
 X+ 		do { \
 X+ 			v1 = v2; \
 X+ 			v2 = bus_space_read_1(iot, ioh, io); \
 X+ 		} while (v1 != v2); \
 X+ 		v2; \
 X+ 	})
 X+ #endif
 X+  
 X+ #if defined(INET) && defined(PLIP)
 X+ /* Functions for the plip# interface */
 X+ static void	plipattach __P((struct lpt_softc *));
 X+ static void	plipinput __P((struct lpt_softc *));
 X+ static int	plipioctl __P((struct ifnet *, u_long, caddr_t));
 X+ static void	plipoutput __P((void *));
 X+ static int	plipreceive __P((struct lpt_softc *, u_char *, int));
 X+ static void	pliprxenable __P((void *));
 X+ void		plipsoftint __P((void));
 X+ static void	plipstart __P((struct ifnet *));
 X+ static int	pliptransmit __P((struct lpt_softc *, u_char *, int));
 X+ #endif
 X+ 
 X  /* XXX does not belong here */
 X  cdev_decl(lpt);
 X***************
 X*** 110,113 ****
 X--- 185,192 ----
 X  
 X  	bus_space_write_1(iot, ioh, lpt_control, LPC_NINIT);
 X+ 
 X+ #if defined(INET) && defined(PLIP)
 X+ 	plipattach(sc);
 X+ #endif
 X  }
 X  
 X***************
 X*** 150,153 ****
 X--- 229,236 ----
 X  	if (sc->sc_state)
 X  		return EBUSY;
 X+ #if defined(INET) && defined(PLIP)
 X+ 	if (sc->sc_ethercom.ec_if.if_flags & IFF_UP)
 X+ 		return EBUSY;
 X+ #endif
 X  
 X  	sc->sc_state = LPT_INIT;
 X***************
 X*** 376,379 ****
 X--- 459,475 ----
 X  		return 0;
 X  #endif
 X+   
 X+ #if defined(INET) && defined(PLIP)
 X+ 	if (sc->sc_ethercom.ec_if.if_flags & IFF_UP) {
 X+ 		if ((sc->sc_control & LPC_IENABLE) == 0)
 X+ 			return 0;	/* dispose spurious interrupt */
 X+ 
 X+ 		bus_space_write_1(iot, ioh, lpt_control, sc->sc_control &= ~LPC_IENABLE);
 X+ 		sc->sc_pending |= PLIP_IPENDING;
 X+ 		/*softintr(sc->sc_ifsoftint);*/
 X+ 		schednetisr(NETISR_PLIP);
 X+ 		return 0;
 X+ 	}
 X+ #endif
 X  
 X  	/* is printer online and ready for output */
 X***************
 X*** 417,418 ****
 X--- 513,990 ----
 X  	return error;
 X  }
 X+ 
 X+ #if defined(INET) && defined(PLIP)
 X+ 
 X+ static void
 X+ plipattach(sc)
 X+ 	struct lpt_softc *sc;
 X+ {
 X+ 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
 X+ 	u_int8_t myaddr[ETHER_ADDR_LEN];
 X+ 
 X+ 	sc->sc_ifbuf = NULL;
 X+ 	sprintf(ifp->if_xname, "plip%d", sc->sc_dev.dv_unit);
 X+ 	bzero(myaddr, sizeof(myaddr));
 X+ 	ifp->if_softc = sc;
 X+ 	ifp->if_start = plipstart;
 X+ 	ifp->if_ioctl = plipioctl;
 X+ 	ifp->if_watchdog = 0;
 X+ 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
 X+ 
 X+ 	if_attach(ifp);
 X+ 	ether_ifattach(ifp, myaddr);
 X+ 	ifp->if_mtu = PLIPMTU;
 X+ 
 X+ #if NBPFILTER > 0
 X+ 	bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
 X+ #endif                 
 X+ 	/*
 X+ 	 * We hope to get Charle's MI softint establish RSN - the
 X+ 	 * current hack involves patching icu.s and hardcoding
 X+ 	 * the softinterupts in a complete unrelated peace
 X+ 	 * of code....
 X+ 	sc->sc_ifsoftint = isa_intr_establish(SOFTINT, 0, ISA_IPL_NET,
 X+ 				plipsoftint, sc);
 X+ 	 */
 X+ }
 X+ 
 X+ /*
 X+  * Process an ioctl request.
 X+  */
 X+ static int
 X+ plipioctl(ifp, cmd, data)
 X+ 	struct ifnet *ifp;
 X+ 	u_long cmd;
 X+ 	caddr_t data;
 X+ {
 X+ 	struct proc *p = curproc;
 X+ 	struct lpt_softc *sc = (struct lpt_softc *) ifp->if_softc;
 X+ 	u_char control = sc->sc_control;
 X+ 	struct ifaddr *ifa = (struct ifaddr *)data;
 X+ 	struct ifreq *ifr = (struct ifreq *)data; 
 X+ 	bus_space_tag_t iot = sc->sc_iot;
 X+ 	bus_space_handle_t ioh = sc->sc_ioh;
 X+ 	struct sockaddr_dl *sdl;
 X+ 	int error = 0;
 X+ 
 X+ 	switch (cmd) {
 X+ 	case SIOCSIFFLAGS:
 X+ 		if (((ifp->if_flags & IFF_UP) == 0) &&
 X+ 		    (ifp->if_flags & IFF_RUNNING)) {
 X+ 		        ifp->if_flags &= ~IFF_RUNNING;
 X+ 			control = LPC_SELECT | LPC_NINIT;
 X+ 			bus_space_write_1(iot, ioh, lpt_control, control);
 X+ 
 X+ 			if (sc->sc_ifbuf)
 X+ 				free(sc->sc_ifbuf, M_DEVBUF);
 X+ 			sc->sc_ifbuf = NULL;
 X+ 		}
 X+ 		if (((ifp->if_flags & IFF_UP)) &&
 X+ 		    ((ifp->if_flags & IFF_RUNNING) == 0)) {
 X+ 			if (sc->sc_state) {
 X+ 				error = EBUSY;
 X+ 				break;
 X+ 			}
 X+ 			if (sc->sc_ih == 0) {
 X+ 				error = EINVAL;
 X+ 				break;
 X+ 			}
 X+ 			if (!sc->sc_ifbuf)
 X+ 				sc->sc_ifbuf =
 X+ 					malloc(ifp->if_mtu + ifp->if_hdrlen,
 X+ 					       M_DEVBUF, M_WAITOK);
 X+ 		        ifp->if_flags |= IFF_RUNNING;
 X+ 			bus_space_write_1(iot, ioh, lpt_control, control & ~LPC_IENABLE);
 X+ 			bus_space_write_1(iot, ioh, lpt_data, 0);
 X+ 			bus_space_write_1(iot, ioh, lpt_control, control |= LPC_IENABLE);
 X+ 		}
 X+ 		break;
 X+ 
 X+ 	case SIOCSIFADDR:
 X+ 		sdl = ifp->if_sadl;
 X+ 		if (ifa->ifa_addr->sa_family == AF_INET) {
 X+ 			if (!sc->sc_ifbuf)
 X+ 				sc->sc_ifbuf =
 X+ 					malloc(PLIPMTU + ifp->if_hdrlen,
 X+ 					       M_DEVBUF, M_WAITOK);
 X+ 			LLADDR(sdl)[0] = 0xfc;
 X+ 			LLADDR(sdl)[1] = 0xfc;
 X+ 			bcopy((caddr_t)&IA_SIN(ifa)->sin_addr,
 X+ 			      (caddr_t)&LLADDR(sdl)[2], 4);
 X+ #if defined(COMPAT_PLIP10)
 X+ 			if (ifp->if_flags & IFF_LINK0) {
 X+ 				int i;
 X+ 				LLADDR(sdl)[0] = 0xfd;
 X+ 				LLADDR(sdl)[1] = 0xfd;
 X+ 				for (i = sc->sc_adrcksum = 0; i < 5; i++)
 X+ 					sc->sc_adrcksum += LLADDR(sdl)[i];
 X+ 				sc->sc_adrcksum *= 2;
 X+ 			}
 X+ #endif
 X+ 			ifp->if_flags |= IFF_RUNNING | IFF_UP;
 X+ 			bus_space_write_1(iot, ioh, lpt_control, control & ~LPC_IENABLE);
 X+ 			bus_space_write_1(iot, ioh, lpt_data, 0);
 X+ 			bus_space_write_1(iot, ioh, lpt_control, control |= LPC_IENABLE);
 X+ 			arp_ifinit(ifp, ifa);
 X+ 		} else
 X+ 			error = EAFNOSUPPORT;
 X+ 		break;
 X+ 
 X+ 	case SIOCAIFADDR:
 X+ 	case SIOCDIFADDR:
 X+ 	case SIOCSIFDSTADDR:
 X+ 		if (ifa->ifa_addr->sa_family != AF_INET)
 X+ 			error = EAFNOSUPPORT;
 X+ 		break;
 X+ 
 X+ 	case SIOCSIFMTU:
 X+         	if ((error = suser(p->p_ucred, &p->p_acflag)))
 X+             		return(error);
 X+ 		if (ifp->if_mtu != ifr->ifr_metric) {
 X+ 		        ifp->if_mtu = ifr->ifr_metric;
 X+ 			if (sc->sc_ifbuf) {
 X+ 				free(sc->sc_ifbuf, M_DEVBUF);
 X+ 				sc->sc_ifbuf =
 X+ 					malloc(ifp->if_mtu + ifp->if_hdrlen,
 X+ 					       M_DEVBUF, M_WAITOK);
 X+ 			}
 X+ 		}
 X+ 		break;
 X+ 
 X+ 	default:
 X+ 		error = EINVAL;
 X+ 	}
 X+ 	sc->sc_control = control;
 X+ 	return (error);
 X+ }
 X+ 
 X+ void
 X+ plipsoftint()
 X+ {
 X+ 	/* while the MI softint framework isn't there, we check
 X+ 	   check all lpt devices */
 X+ 	struct device *dev;
 X+ 
 X+ 	for (dev = alldevs.tqh_first; dev; dev = dev->dv_list.tqe_next) {
 X+ 		if (dev->dv_cfdata->cf_driver == &lpt_cd) {
 X+ 			int pending;
 X+ 			struct lpt_softc *sc = (struct lpt_softc*)dev;
 X+ 
 X+ 			pending = sc->sc_pending;
 X+ 			while (sc->sc_pending & PLIP_IPENDING) {
 X+ 				pending |= sc->sc_pending;
 X+ 				sc->sc_pending = 0;
 X+ 				plipinput(sc);
 X+ 			}
 X+ 
 X+ 			if (pending & PLIP_OPENDING)
 X+ 				plipoutput(sc);
 X+ 		}
 X+ 	}
 X+ }
 X+ 
 X+ static int
 X+ plipreceive(sc, buf, len)
 X+ 	struct lpt_softc *sc;
 X+ 	u_char *buf;
 X+ 	int len;
 X+ {
 X+ 	bus_space_tag_t iot = sc->sc_iot;
 X+ 	bus_space_handle_t ioh = sc->sc_ioh;
 X+ 	int i;
 X+ 	u_char cksum = 0, cl, ch;
 X+ 
 X+ 	while (len--) {
 X+ 		i = PLIPMXSPIN2;
 X+ 		while (((cl = STABILIZE(iot, ioh, lpt_status)) & LPS_NBSY) != 0)
 X+ 			if (i-- < 0) return -1;
 X+ 		cl = (cl >> 3) & 0x0f;
 X+ 		bus_space_write_1(iot, ioh, lpt_data, 0x11);
 X+ 		while (((ch = STABILIZE(iot, ioh, lpt_status)) & LPS_NBSY) == 0)
 X+ 			if (i-- < 0) return -1;
 X+ 		cl |= (ch << 1) & 0xf0;
 X+ 		bus_space_write_1(iot, ioh, lpt_data, 0x01);
 X+ 		cksum += (*buf++ = cl);
 X+ 	}
 X+ 	return(cksum);
 X+ }
 X+ 
 X+ static void
 X+ pliprxenable(arg)
 X+ 	void *arg;
 X+ {
 X+ 	struct lpt_softc *sc = arg;
 X+ 	bus_space_tag_t iot = sc->sc_iot;
 X+ 	bus_space_handle_t ioh = sc->sc_ioh;
 X+ 	bus_space_write_1(iot, ioh, lpt_control, sc->sc_control |= LPC_IENABLE);
 X+ }
 X+ 
 X+ static void
 X+ plipinput(sc)
 X+ 	struct lpt_softc *sc;
 X+ {
 X+ 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
 X+ 	bus_space_tag_t iot = sc->sc_iot;
 X+ 	bus_space_handle_t ioh = sc->sc_ioh;
 X+ 	struct mbuf *m;
 X+ 	struct ether_header *eh;
 X+ 	u_char *p = sc->sc_ifbuf, minibuf[4];
 X+ 	int s, len, cksum;
 X+ 
 X+ #ifndef PLIP_NO_INCOLL
 X+ 	if (!(STABILIZE(iot, ioh, lpt_status) & LPS_NACK)) {
 X+ 		bus_space_write_1(iot, ioh, lpt_control, sc->sc_control |= LPC_IENABLE);
 X+ 		ifp->if_collisions++;
 X+ 		return;
 X+ 	}
 X+ #endif
 X+ 	bus_space_write_1(iot, ioh, lpt_data, 0x01);
 X+ 	bus_space_write_1(iot, ioh, lpt_control, sc->sc_control &= ~LPC_IENABLE);
 X+ 
 X+ 	if (sc->sc_ifierrs)
 X+ 		untimeout(pliprxenable, sc);
 X+ 
 X+ #if defined(COMPAT_PLIP10)
 X+ 	if (ifp->if_flags & IFF_LINK0) {
 X+ 		int c;
 X+ 		if (plipreceive(sc, minibuf, 3) < 0) goto err;
 X+ 		len = (minibuf[1] << 8) | minibuf[2];
 X+ 		if (len > (ifp->if_mtu + ifp->if_hdrlen)) goto err;
 X+ 
 X+ 		switch (minibuf[0]) {
 X+ 		case 0xfc:
 X+ 			p[0] = p[ 6] = LLADDR(ifp->if_sadl)[0];
 X+ 			p[1] = p[ 7] = LLADDR(ifp->if_sadl)[1];
 X+ 			p[2] = p[ 8] = LLADDR(ifp->if_sadl)[2];
 X+ 			p[3] = p[ 9] = LLADDR(ifp->if_sadl)[3];
 X+ 			p[4] = p[10] = LLADDR(ifp->if_sadl)[4];
 X+ 			p += 5;
 X+ 			if ((cksum = plipreceive(sc, p, 1)) < 0) goto err;
 X+ 			p += 6;
 X+ 			if ((c = plipreceive(sc, p, len - 11)) < 0) goto err;
 X+ 			cksum += c + sc->sc_adrcksum;
 X+ 			c = p[1]; p[1] = p[2]; p[2] = c;
 X+ 			cksum &= 0xff;
 X+ 			break;
 X+ 		case 0xfd:
 X+ 			if ((cksum = plipreceive(sc, p, len)) < 0) goto err;
 X+ 			break;
 X+ 		default:
 X+ 			goto err;
 X+ 		}
 X+ 	} else
 X+ #endif
 X+ 	{
 X+ 		if (plipreceive(sc, minibuf, 2) < 0) goto err;
 X+ 		len = (minibuf[1] << 8) | minibuf[0];
 X+ 		if (len > (ifp->if_mtu + ifp->if_hdrlen)) {
 X+ 			log(LOG_NOTICE, "%s: packet > MTU\n", ifp->if_xname);
 X+ 			goto err;
 X+ 		}
 X+ 		if ((cksum = plipreceive(sc, p, len)) < 0) goto err;
 X+ 	}
 X+ 	
 X+ 	if (plipreceive(sc, minibuf, 1) < 0) goto err;
 X+ 	if (cksum != minibuf[0]) {
 X+ 		log(LOG_NOTICE, "%s: checksum error\n", ifp->if_xname);
 X+ 		goto err;
 X+ 	}
 X+ 	bus_space_write_1(iot, ioh, lpt_data, 0x00);
 X+ 
 X+ 	s = splimp();
 X+ 	if ((m = m_devget(sc->sc_ifbuf, len, 0, ifp, NULL)) != NULL) {
 X+ 		/* We assume that the header fit entirely in one mbuf. */
 X+ 		eh = mtod(m, struct ether_header *);
 X+ #if NBPFILTER > 0
 X+ 		/*
 X+ 		 * Check if there's a BPF listener on this interface.
 X+ 		 * If so, hand off the raw packet to bpf.
 X+ 		 */
 X+ 		if (ifp->if_bpf) {
 X+ 			bpf_mtap(ifp->if_bpf, m);
 X+ 		}
 X+ #endif
 X+ 		/* We assume the header fit entirely in one mbuf. */
 X+ 		m_adj(m, sizeof(struct ether_header));
 X+ 		ether_input(ifp, eh, m);
 X+ 	}
 X+ 	splx(s);
 X+ 	sc->sc_ifierrs = 0;
 X+ 	ifp->if_ipackets++;
 X+ 	bus_space_write_1(iot, ioh, lpt_control, sc->sc_control |= LPC_IENABLE);
 X+ 	return;
 X+ 
 X+ err:
 X+ 	bus_space_write_1(iot, ioh, lpt_data, 0x00);
 X+ 
 X+ 	if (sc->sc_ifierrs < PLIPMXERRS) {
 X+ 		if (sc->sc_ifierrs > 4 && (STABILIZE(iot, ioh, lpt_status) & LPS_NBSY)) {
 X+ 			/* Avoid interrupt nesting ... */
 X+ 			sc->sc_ifierrs = PLIPMXERRS - 1;
 X+ 		}
 X+ 		bus_space_write_1(iot, ioh, lpt_control, sc->sc_control |= LPC_IENABLE);
 X+ 	} else {
 X+ 		/* We are not able to send or receive anything for now,
 X+ 		 * so stop wasting our time and leave the interrupt
 X+ 		 * disabled.
 X+ 		 */
 X+ 		if (sc->sc_ifierrs == PLIPMXERRS)
 X+ 			log(LOG_NOTICE, "%s: rx hard error\n", ifp->if_xname);
 X+ 		/* But we will retry from time to time. */
 X+ 		timeout(pliprxenable, sc, PLIPRETRY * 10);
 X+ 	}
 X+ 	ifp->if_ierrors++;
 X+ 	sc->sc_ifierrs++;
 X+ 	return;
 X+ }
 X+ 
 X+ static int
 X+ pliptransmit(sc, buf, len)
 X+ 	struct lpt_softc *sc;
 X+ 	u_char *buf;
 X+ 	int len;
 X+ {
 X+ 	bus_space_tag_t iot = sc->sc_iot;
 X+ 	bus_space_handle_t ioh = sc->sc_ioh;
 X+ 	int i;
 X+ 	u_char cksum = 0, c;
 X+ 
 X+ 	while (len--) {
 X+ 		i = PLIPMXSPIN2;
 X+ 		cksum += (c = *buf++);
 X+ 		while ((STABILIZE(iot, ioh, lpt_status) & LPS_NBSY) == 0)
 X+ 			if (i-- < 0) return -1;
 X+ 		bus_space_write_1(iot, ioh, lpt_data, c & 0x0f);
 X+ 		bus_space_write_1(iot, ioh, lpt_data, (c & 0x0f) | 0x10);
 X+ 		c >>= 4;
 X+ 		while ((STABILIZE(iot, ioh, lpt_status) & LPS_NBSY) != 0)
 X+ 			if (i-- < 0) return -1;
 X+ 		bus_space_write_1(iot, ioh, lpt_data, c | 0x10);
 X+ 		bus_space_write_1(iot, ioh, lpt_data, c);
 X+ 	}
 X+ 	return(cksum);
 X+ }
 X+ 
 X+ /*
 X+  * Setup output on interface.
 X+  */
 X+ static void
 X+ plipstart(ifp)
 X+ 	struct ifnet *ifp;
 X+ {
 X+ 	struct lpt_softc *sc = (struct lpt_softc *) ifp->if_softc;
 X+ 	sc->sc_pending |= PLIP_OPENDING;
 X+ 	/*softintr(sc->sc_ifsoftint);*/
 X+ 	schednetisr(NETISR_PLIP);
 X+ }
 X+ 
 X+ static void
 X+ plipoutput(arg)
 X+ 	void *arg;
 X+ {
 X+ 	struct lpt_softc *sc = arg;
 X+ 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
 X+ 	bus_space_tag_t iot = sc->sc_iot;
 X+ 	bus_space_handle_t ioh = sc->sc_ioh;
 X+ 	struct mbuf *m0, *m;
 X+ 	u_char minibuf[4], cksum;
 X+ 	int len, i, s;
 X+ 
 X+ 	if (ifp->if_flags & IFF_OACTIVE)
 X+ 		return;
 X+ 	ifp->if_flags |= IFF_OACTIVE;
 X+ 
 X+ 	if (sc->sc_ifoerrs)
 X+ 		untimeout(plipoutput, sc);
 X+ 
 X+ 	for (;;) {
 X+ 		s = splnet();
 X+ 		IF_DEQUEUE(&ifp->if_snd, m0);
 X+ 		splx(s);
 X+ 		if (!m0)
 X+ 			break;
 X+ 
 X+ #if NBPFILTER > 0
 X+ 		if (ifp->if_bpf)
 X+ 			bpf_mtap(ifp->if_bpf, m0);
 X+ #endif
 X+ 
 X+ 		len = m0->m_pkthdr.len;
 X+ 
 X+ #if defined(COMPAT_PLIP10)
 X+ 		if (ifp->if_flags & IFF_LINK0) {
 X+ 			minibuf[0] = 3;
 X+ 			minibuf[1] = 0xfd;
 X+ 			minibuf[2] = len >> 8;
 X+ 			minibuf[3] = len;
 X+ 		} else
 X+ #endif
 X+ 		{
 X+ 			minibuf[0] = 2;
 X+ 			minibuf[1] = len;
 X+ 			minibuf[2] = len >> 8;
 X+ 		}
 X+ 
 X+ 		/* Trigger remote interrupt */
 X+ 		i = PLIPMXSPIN1;
 X+ 		do {
 X+ 			if (sc->sc_pending & PLIP_IPENDING) {
 X+ 				bus_space_write_1(iot, ioh, lpt_data, 0x00);
 X+ 				sc->sc_pending = 0;
 X+ 				plipinput(sc);
 X+ 				i = PLIPMXSPIN1;
 X+ 			} else if (i-- < 0)
 X+ 				goto retry;
 X+ 			/* Retrigger remote interrupt */
 X+ 			bus_space_write_1(iot, ioh, lpt_data, 0x08);
 X+ 		} while ((STABILIZE(iot, ioh, lpt_status) & LPS_NERR) == 0);
 X+ 		bus_space_write_1(iot, ioh, lpt_control, sc->sc_control &= ~LPC_IENABLE);
 X+ 		if (pliptransmit(sc, minibuf + 1, minibuf[0]) < 0) goto retry;
 X+ 		for (cksum = 0, m = m0; m; m = m->m_next) {
 X+ 			i = pliptransmit(sc, mtod(m, u_char *), m->m_len);
 X+ 			if (i < 0) goto retry;
 X+ 			cksum += i;
 X+ 		}
 X+ 		if (pliptransmit(sc, &cksum, 1) < 0) goto retry;
 X+ 		i = PLIPMXSPIN2;
 X+ 		while ((STABILIZE(iot, ioh, lpt_status) & LPS_NBSY) == 0)
 X+ 			if (i-- < 0) goto retry;
 X+ 		sc->sc_pending = 0;
 X+ 		bus_space_write_1(iot, ioh, lpt_data, 0x00);
 X+ 
 X+ 		ifp->if_opackets++;
 X+ 		ifp->if_obytes += len + 4;
 X+ 		sc->sc_ifoerrs = 0;
 X+ 		m_freem(m0);
 X+ 		bus_space_write_1(iot, ioh, lpt_control, sc->sc_control |= LPC_IENABLE);
 X+ 	}
 X+ 	ifp->if_flags &= ~IFF_OACTIVE;
 X+ 	return;
 X+ 
 X+ retry:
 X+ 	if (STABILIZE(iot, ioh, lpt_status) & LPS_NACK)
 X+ 		ifp->if_collisions++;
 X+ 	else
 X+ 		ifp->if_oerrors++;
 X+ 
 X+ 	ifp->if_flags &= ~IFF_OACTIVE;
 X+ 	bus_space_write_1(iot, ioh, lpt_data, 0x00);
 X+ 
 X+ 	if ((ifp->if_flags & (IFF_RUNNING | IFF_UP)) == (IFF_RUNNING | IFF_UP)
 X+ 	    && sc->sc_ifoerrs < PLIPMXRETRY) {
 X+ 		s = splnet();
 X+ 		IF_PREPEND(&ifp->if_snd, m0);
 X+ 		splx(s);
 X+ 		timeout(plipoutput, sc, PLIPRETRY);
 X+ 	} else {
 X+ 		/* we are not able to send this... give up for now */
 X+ 		if (sc->sc_ifoerrs == PLIPMXRETRY) {
 X+ 			log(LOG_NOTICE, "%s: tx hard error\n", ifp->if_xname);
 X+ 		}
 X+ 		m_freem(m0);
 X+ 	}
 X+ 	bus_space_write_1(iot, ioh, lpt_control, sc->sc_control |= LPC_IENABLE);
 X+ 	sc->sc_ifoerrs++;
 X+ }
 X+ 
 X+ #endif
 Xdiff -rc2 /tmp/sys/dev/ic/lptvar.h sys/dev/ic/lptvar.h
 X*** /tmp/sys/dev/ic/lptvar.h	Mon Dec  8 13:27:55 1997
 X--- sys/dev/ic/lptvar.h	Sat Jan  3 12:33:08 1998
 X***************
 X*** 59,62 ****
 X--- 59,63 ----
 X  struct lpt_softc {
 X  	struct device sc_dev;
 X+ 
 X  	void *sc_ih;
 X  	size_t sc_count;
 X***************
 X*** 76,79 ****
 X--- 77,95 ----
 X  	u_char sc_control;
 X  	u_char sc_laststatus;
 X+ 
 X+ #if defined(INET) && defined(PLIP)
 X+ 	struct	ethercom sc_ethercom;
 X+ 	u_char		*sc_ifbuf;
 X+ 	int		sc_ifierrs;	/* consecutive input errors */
 X+ 	int		sc_ifoerrs;	/* consecutive output errors */
 X+ 	int		sc_ifsoftint;	/* i/o software interrupt */
 X+ 	volatile int	sc_pending;	/* interrputs pending */
 X+ #define PLIP_IPENDING	1
 X+ #define PLIP_OPENDING	2
 X+ 
 X+ #if defined(COMPAT_PLIP10)
 X+ 	u_char		sc_adrcksum;
 X+ #endif
 X+ #endif
 X  };
 X  
 Xdiff -rc2 /tmp/sys/dev/isa/files.isa sys/dev/isa/files.isa
 X*** /tmp/sys/dev/isa/files.isa	Sat Nov 22 13:27:20 1997
 X--- sys/dev/isa/files.isa	Sat Jan  3 12:33:08 1998
 X***************
 X*** 56,60 ****
 X  # PC-style parallel ports (XXX what chip?)
 X  # XXX chip driver should be defined elsewhere
 X! device	lpt
 X  file	dev/ic/lpt.c			lpt needs-flag
 X  
 X--- 56,60 ----
 X  # PC-style parallel ports (XXX what chip?)
 X  # XXX chip driver should be defined elsewhere
 X! device	lpt: ifnet, ether, arp	# XXX - "ifnet, ether, arp" only if option PLIP
 X  file	dev/ic/lpt.c			lpt needs-flag
 X  
 Xdiff -rc2 /tmp/sys/dev/isa/lpt_isa.c sys/dev/isa/lpt_isa.c
 X*** /tmp/sys/dev/isa/lpt_isa.c	Tue Oct 21 10:19:42 1997
 X--- sys/dev/isa/lpt_isa.c	Sat Jan  3 12:33:08 1998
 X***************
 X*** 69,72 ****
 X--- 69,78 ----
 X  #include <machine/intr.h>
 X  
 X+ #if defined(INET) && defined(PLIP)
 X+ #include <sys/socket.h>
 X+ #include <net/if.h>
 X+ #include <net/if_ether.h>
 X+ #endif
 X+ 
 X  #include <dev/isa/isavar.h>
 X  #include <dev/ic/lptreg.h>
 X***************
 X*** 248,252 ****
 X  	if (ia->ia_irq != IRQUNK)
 X  		lsc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
 X! 		    IPL_TTY, lptintr, lsc);
 X  }
 X  
 X--- 254,258 ----
 X  	if (ia->ia_irq != IRQUNK)
 X  		lsc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
 X! 		    IPL_NONE, lptintr, lsc);
 X  }
 X  
 Xdiff -rc2 /tmp/sys/net/netisr.h sys/net/netisr.h
 X*** /tmp/sys/net/netisr.h	Thu Apr  3 14:26:56 1997
 X--- sys/net/netisr.h	Sat Jan  3 12:33:08 1998
 X***************
 X*** 64,67 ****
 X--- 64,68 ----
 X  #define NETISR_NATM	27		/* same as AF_NATM */
 X  #define NETISR_PPP	28		/* for PPP processing */
 X+ #define	NETISR_PLIP	29		/* for PLIP processing */
 X  
 X  #define	schednetisr(anisr)	{ netisr |= 1<<(anisr); setsoftnet(); }
 END-of-plip.patch
 exit


Responsible-Changed-From-To: gnats-admin->port-i386-maintainer 
Responsible-Changed-By: fair 
Responsible-Changed-When: Mon Dec 28 09:48:31 PST 1998 
Responsible-Changed-Why:  
This PR is the responsibility of the portmaster, 
not the GNATS database administrator. 
State-Changed-From-To: open->suspended 
State-Changed-By: martin 
State-Changed-When: Fri Jun 8 01:45:52 PDT 2001 
State-Changed-Why:  
A real solution of this depends on two things: the generic soft
interrupts (which are now basically there on most ports) and a
generic ppbus framework, ported from, or similar to, the one in
FreeBSD.

Interest in PLIP seems to be marginal nowadays, if it ever existed.
Responsible-Changed-From-To: port-i386-maintainer->martin 
Responsible-Changed-By: darcy 
Responsible-Changed-When: Sun Feb 16 15:59:49 PST 2003 
Responsible-Changed-Why:  
Martin - I see you are busy with new PRs but I wonder if you can take a 
moment to look at this old one.  As you say, there isn't much call for 
PLIP support these days.  Is there any value pursuing this or shall we 
simply close it? 
State-Changed-From-To: suspended->closed 
State-Changed-By: martin 
State-Changed-When: Sun Feb 16 16:48:59 PST 2003 
State-Changed-Why:  
Not much interest in this type of connection lately. 
Still no parbus, so we could get it realy right, but at least MI softint 
is there. Anyway, I still have my patches for anyone that wants them 
and I even updated them for 1.6 ;-) 
No reason to kill PR statistics any longer... 
>Unformatted:

 NOTE: Duplicate was submitted also with patches.  See PR 1516.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.