xref: /freebsd/sys/dev/ppbus/if_plip.c (revision 0f210c922b80eef92f841effdded7996a621a9da)
146f3ff79SMike Smith /*-
246f3ff79SMike Smith  * Copyright (c) 1997 Poul-Henning Kamp
346f3ff79SMike Smith  * All rights reserved.
446f3ff79SMike Smith  *
546f3ff79SMike Smith  * Redistribution and use in source and binary forms, with or without
646f3ff79SMike Smith  * modification, are permitted provided that the following conditions
746f3ff79SMike Smith  * are met:
846f3ff79SMike Smith  * 1. Redistributions of source code must retain the above copyright
946f3ff79SMike Smith  *    notice, this list of conditions and the following disclaimer.
1046f3ff79SMike Smith  * 2. Redistributions in binary form must reproduce the above copyright
1146f3ff79SMike Smith  *    notice, this list of conditions and the following disclaimer in the
1246f3ff79SMike Smith  *    documentation and/or other materials provided with the distribution.
1346f3ff79SMike Smith  *
1446f3ff79SMike Smith  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1546f3ff79SMike Smith  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1646f3ff79SMike Smith  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1746f3ff79SMike Smith  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1846f3ff79SMike Smith  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1946f3ff79SMike Smith  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2046f3ff79SMike Smith  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2146f3ff79SMike Smith  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2246f3ff79SMike Smith  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2346f3ff79SMike Smith  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2446f3ff79SMike Smith  * SUCH DAMAGE.
2546f3ff79SMike Smith  *
2646f3ff79SMike Smith  *	From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp
27c3aac50fSPeter Wemm  * $FreeBSD$
2846f3ff79SMike Smith  */
2946f3ff79SMike Smith 
3046f3ff79SMike Smith /*
3146f3ff79SMike Smith  * Parallel port TCP/IP interfaces added.  I looked at the driver from
3246f3ff79SMike Smith  * MACH but this is a complete rewrite, and btw. incompatible, and it
3346f3ff79SMike Smith  * should perform better too.  I have never run the MACH driver though.
3446f3ff79SMike Smith  *
3546f3ff79SMike Smith  * This driver sends two bytes (0x08, 0x00) in front of each packet,
3646f3ff79SMike Smith  * to allow us to distinguish another format later.
3746f3ff79SMike Smith  *
3846f3ff79SMike Smith  * Now added an Linux/Crynwr compatibility mode which is enabled using
3946f3ff79SMike Smith  * IF_LINK0 - Tim Wilkinson.
4046f3ff79SMike Smith  *
4146f3ff79SMike Smith  * TODO:
4246f3ff79SMike Smith  *    Make HDLC/PPP mode, use IF_LLC1 to enable.
4346f3ff79SMike Smith  *
4446f3ff79SMike Smith  * Connect the two computers using a Laplink parallel cable to use this
4546f3ff79SMike Smith  * feature:
4646f3ff79SMike Smith  *
4746f3ff79SMike Smith  *      +----------------------------------------+
4846f3ff79SMike Smith  * 	|A-name	A-End	B-End	Descr.	Port/Bit |
4946f3ff79SMike Smith  *      +----------------------------------------+
5046f3ff79SMike Smith  *	|DATA0	2	15	Data	0/0x01   |
5146f3ff79SMike Smith  *	|-ERROR	15	2	   	1/0x08   |
5246f3ff79SMike Smith  *      +----------------------------------------+
5346f3ff79SMike Smith  *	|DATA1	3	13	Data	0/0x02	 |
5446f3ff79SMike Smith  *	|+SLCT	13	3	   	1/0x10   |
5546f3ff79SMike Smith  *      +----------------------------------------+
5646f3ff79SMike Smith  *	|DATA2	4	12	Data	0/0x04   |
5746f3ff79SMike Smith  *	|+PE	12	4	   	1/0x20   |
5846f3ff79SMike Smith  *      +----------------------------------------+
5946f3ff79SMike Smith  *	|DATA3	5	10	Strobe	0/0x08   |
6046f3ff79SMike Smith  *	|-ACK	10	5	   	1/0x40   |
6146f3ff79SMike Smith  *      +----------------------------------------+
6246f3ff79SMike Smith  *	|DATA4	6	11	Data	0/0x10   |
6346f3ff79SMike Smith  *	|BUSY	11	6	   	1/~0x80  |
6446f3ff79SMike Smith  *      +----------------------------------------+
6546f3ff79SMike Smith  *	|GND	18-25	18-25	GND	-        |
6646f3ff79SMike Smith  *      +----------------------------------------+
6746f3ff79SMike Smith  *
6846f3ff79SMike Smith  * Expect transfer-rates up to 75 kbyte/sec.
6946f3ff79SMike Smith  *
7046f3ff79SMike Smith  * If GCC could correctly grok
7146f3ff79SMike Smith  *	register int port asm("edx")
7246f3ff79SMike Smith  * the code would be cleaner
7346f3ff79SMike Smith  *
7446f3ff79SMike Smith  * Poul-Henning Kamp <phk@freebsd.org>
7546f3ff79SMike Smith  */
7646f3ff79SMike Smith 
7746f3ff79SMike Smith /*
7846f3ff79SMike Smith  * Update for ppbus, PLIP support only - Nicolas Souchu
7946f3ff79SMike Smith  */
800f210c92SNicolas Souchu #include "plip.h"
810f210c92SNicolas Souchu 
820f210c92SNicolas Souchu #if NPLIP > 0
830f210c92SNicolas Souchu 
840f210c92SNicolas Souchu #include "opt_plip.h"
8546f3ff79SMike Smith 
8646f3ff79SMike Smith #include <sys/param.h>
8746f3ff79SMike Smith #include <sys/systm.h>
880f210c92SNicolas Souchu #include <sys/module.h>
890f210c92SNicolas Souchu #include <sys/bus.h>
900f210c92SNicolas Souchu #include <sys/conf.h>
9146f3ff79SMike Smith #include <sys/mbuf.h>
9246f3ff79SMike Smith #include <sys/socket.h>
9346f3ff79SMike Smith #include <sys/sockio.h>
9446f3ff79SMike Smith #include <sys/kernel.h>
9546f3ff79SMike Smith #include <sys/malloc.h>
9646f3ff79SMike Smith 
970f210c92SNicolas Souchu #include <machine/clock.h>
980f210c92SNicolas Souchu #include <machine/bus.h>
990f210c92SNicolas Souchu #include <machine/resource.h>
1000f210c92SNicolas Souchu #include <sys/rman.h>
1010f210c92SNicolas Souchu 
10246f3ff79SMike Smith #include <net/if.h>
10346f3ff79SMike Smith #include <net/if_types.h>
10446f3ff79SMike Smith #include <net/netisr.h>
10546f3ff79SMike Smith 
10646f3ff79SMike Smith #include <netinet/in.h>
10746f3ff79SMike Smith #include <netinet/in_var.h>
10846f3ff79SMike Smith 
10946f3ff79SMike Smith #include <net/bpf.h>
11046f3ff79SMike Smith 
11146f3ff79SMike Smith #include <dev/ppbus/ppbconf.h>
1120f210c92SNicolas Souchu #include "ppbus_if.h"
1130f210c92SNicolas Souchu #include <dev/ppbus/ppbio.h>
1147b7bf77eSNicolas Souchu 
11546f3ff79SMike Smith #ifndef LPMTU			/* MTU for the lp# interfaces */
11646f3ff79SMike Smith #define	LPMTU	1500
11746f3ff79SMike Smith #endif
11846f3ff79SMike Smith 
11946f3ff79SMike Smith #ifndef LPMAXSPIN1		/* DELAY factor for the lp# interfaces */
12046f3ff79SMike Smith #define	LPMAXSPIN1	8000   /* Spinning for remote intr to happen */
12146f3ff79SMike Smith #endif
12246f3ff79SMike Smith 
12346f3ff79SMike Smith #ifndef LPMAXSPIN2		/* DELAY factor for the lp# interfaces */
12446f3ff79SMike Smith #define	LPMAXSPIN2	500	/* Spinning for remote handshake to happen */
12546f3ff79SMike Smith #endif
12646f3ff79SMike Smith 
12746f3ff79SMike Smith #ifndef LPMAXERRS		/* Max errors before !RUNNING */
12846f3ff79SMike Smith #define	LPMAXERRS	100
12946f3ff79SMike Smith #endif
13046f3ff79SMike Smith 
13146f3ff79SMike Smith #define CLPIPHDRLEN	14	/* We send dummy ethernet addresses (two) + packet type in front of packet */
13246f3ff79SMike Smith #define	CLPIP_SHAKE	0x80	/* This bit toggles between nibble reception */
13346f3ff79SMike Smith #define MLPIPHDRLEN	CLPIPHDRLEN
13446f3ff79SMike Smith 
13546f3ff79SMike Smith #define LPIPHDRLEN	2	/* We send 0x08, 0x00 in front of packet */
13646f3ff79SMike Smith #define	LPIP_SHAKE	0x40	/* This bit toggles between nibble reception */
13746f3ff79SMike Smith #if !defined(MLPIPHDRLEN) || LPIPHDRLEN > MLPIPHDRLEN
13846f3ff79SMike Smith #define MLPIPHDRLEN	LPIPHDRLEN
13946f3ff79SMike Smith #endif
14046f3ff79SMike Smith 
14146f3ff79SMike Smith #define	LPIPTBLSIZE	256	/* Size of octet translation table */
14246f3ff79SMike Smith 
14346f3ff79SMike Smith #define lprintf		if (lptflag) printf
14420240fa3SNicolas Souchu 
14520240fa3SNicolas Souchu #ifdef PLIP_DEBUG
14646f3ff79SMike Smith static int volatile lptflag = 1;
14720240fa3SNicolas Souchu #else
14820240fa3SNicolas Souchu static int volatile lptflag = 0;
14946f3ff79SMike Smith #endif
15046f3ff79SMike Smith 
1510f210c92SNicolas Souchu struct lp_data {
15246f3ff79SMike Smith 	unsigned short lp_unit;
15346f3ff79SMike Smith 
15446f3ff79SMike Smith 	struct  ifnet	sc_if;
15546f3ff79SMike Smith 	u_char		*sc_ifbuf;
15646f3ff79SMike Smith 	int		sc_iferrs;
1570f210c92SNicolas Souchu 
1580f210c92SNicolas Souchu 	struct resource *res_irq;
15946f3ff79SMike Smith };
16046f3ff79SMike Smith 
16146f3ff79SMike Smith /* Tables for the lp# interface */
16246f3ff79SMike Smith static u_char *txmith;
16346f3ff79SMike Smith #define txmitl (txmith+(1*LPIPTBLSIZE))
16446f3ff79SMike Smith #define trecvh (txmith+(2*LPIPTBLSIZE))
16546f3ff79SMike Smith #define trecvl (txmith+(3*LPIPTBLSIZE))
16646f3ff79SMike Smith 
16746f3ff79SMike Smith static u_char *ctxmith;
16846f3ff79SMike Smith #define ctxmitl (ctxmith+(1*LPIPTBLSIZE))
16946f3ff79SMike Smith #define ctrecvh (ctxmith+(2*LPIPTBLSIZE))
17046f3ff79SMike Smith #define ctrecvl (ctxmith+(3*LPIPTBLSIZE))
17146f3ff79SMike Smith 
17246f3ff79SMike Smith /* Functions for the lp# interface */
1730f210c92SNicolas Souchu static int lp_probe(device_t dev);
1740f210c92SNicolas Souchu static int lp_attach(device_t dev);
17546f3ff79SMike Smith 
17646f3ff79SMike Smith static int lpinittables(void);
17746f3ff79SMike Smith static int lpioctl(struct ifnet *, u_long, caddr_t);
17846f3ff79SMike Smith static int lpoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
17946f3ff79SMike Smith 	struct rtentry *);
1800f210c92SNicolas Souchu static void lp_intr(void *);
18146f3ff79SMike Smith 
1820f210c92SNicolas Souchu #define DEVTOSOFTC(dev) \
1830f210c92SNicolas Souchu 	((struct lp_data *)device_get_softc(dev))
1840f210c92SNicolas Souchu #define UNITOSOFTC(unit) \
1850f210c92SNicolas Souchu 	((struct lp_data *)devclass_get_softc(lp_devclass, (unit)))
1860f210c92SNicolas Souchu #define UNITODEVICE(unit) \
1870f210c92SNicolas Souchu 	(devclass_get_device(lp_devclass, (unit)))
18846f3ff79SMike Smith 
1890f210c92SNicolas Souchu static devclass_t lp_devclass;
1900f210c92SNicolas Souchu 
1910f210c92SNicolas Souchu static device_method_t lp_methods[] = {
1920f210c92SNicolas Souchu   	/* device interface */
1930f210c92SNicolas Souchu 	DEVMETHOD(device_probe,		lp_probe),
1940f210c92SNicolas Souchu 	DEVMETHOD(device_attach,	lp_attach),
1950f210c92SNicolas Souchu 
1960f210c92SNicolas Souchu 	{ 0, 0 }
19746f3ff79SMike Smith };
19846f3ff79SMike Smith 
1990f210c92SNicolas Souchu static driver_t lp_driver = {
2000f210c92SNicolas Souchu   "plip",
2010f210c92SNicolas Souchu   lp_methods,
2020f210c92SNicolas Souchu   sizeof(struct lp_data),
2030f210c92SNicolas Souchu };
20446f3ff79SMike Smith 
20546f3ff79SMike Smith /*
20646f3ff79SMike Smith  * lpprobe()
20746f3ff79SMike Smith  */
2080f210c92SNicolas Souchu static int
2090f210c92SNicolas Souchu lp_probe(device_t dev)
21046f3ff79SMike Smith {
2110f210c92SNicolas Souchu 	device_t ppbus = device_get_parent(dev);
2120f210c92SNicolas Souchu 	struct lp_data *lp;
2130f210c92SNicolas Souchu 	int irq, zero = 0;
2140f210c92SNicolas Souchu 
2150f210c92SNicolas Souchu 	lp = DEVTOSOFTC(dev);
2160f210c92SNicolas Souchu 	bzero(lp, sizeof(struct lp_data));
2170f210c92SNicolas Souchu 
2180f210c92SNicolas Souchu 	/* retrieve the ppbus irq */
2190f210c92SNicolas Souchu 	BUS_READ_IVAR(ppbus, dev, PPBUS_IVAR_IRQ, &irq);
22046f3ff79SMike Smith 
22146f3ff79SMike Smith 	/* if we haven't interrupts, the probe fails */
2220f210c92SNicolas Souchu 	if (irq == -1) {
2230f210c92SNicolas Souchu 		device_printf(dev, "not an interrupt driven port, failed.\n");
2240f210c92SNicolas Souchu 		return (ENXIO);
225fdf94d1aSNicolas Souchu 	}
22646f3ff79SMike Smith 
2270f210c92SNicolas Souchu 	/* reserve the interrupt resource, expecting irq is available to continue */
2280f210c92SNicolas Souchu 	lp->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &zero, irq, irq, 1,
2290f210c92SNicolas Souchu 					 RF_SHAREABLE);
2300f210c92SNicolas Souchu 	if (lp->res_irq == 0) {
2310f210c92SNicolas Souchu 		device_printf(dev, "cannot reserve interrupt, failed.\n");
2320f210c92SNicolas Souchu 		return (ENXIO);
23346f3ff79SMike Smith 	}
23446f3ff79SMike Smith 
23546f3ff79SMike Smith 	/*
23646f3ff79SMike Smith 	 * lp dependent initialisation.
23746f3ff79SMike Smith 	 */
2380f210c92SNicolas Souchu 	lp->lp_unit = device_get_unit(dev);
23946f3ff79SMike Smith 
2400f210c92SNicolas Souchu 	device_set_desc(dev, "PLIP network interface");
24146f3ff79SMike Smith 
2420f210c92SNicolas Souchu 	return (0);
24346f3ff79SMike Smith }
24446f3ff79SMike Smith 
24546f3ff79SMike Smith static int
2460f210c92SNicolas Souchu lp_attach (device_t dev)
24746f3ff79SMike Smith {
2480f210c92SNicolas Souchu 	struct lp_data *lp = DEVTOSOFTC(dev);
2490f210c92SNicolas Souchu 	struct ifnet *ifp = &lp->sc_if;
25046f3ff79SMike Smith 
2510f210c92SNicolas Souchu 	ifp->if_softc = lp;
25246f3ff79SMike Smith 	ifp->if_name = "lp";
2530f210c92SNicolas Souchu 	ifp->if_unit = device_get_unit(dev);
25446f3ff79SMike Smith 	ifp->if_mtu = LPMTU;
25546f3ff79SMike Smith 	ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST;
25646f3ff79SMike Smith 	ifp->if_ioctl = lpioctl;
25746f3ff79SMike Smith 	ifp->if_output = lpoutput;
25846f3ff79SMike Smith 	ifp->if_type = IFT_PARA;
25946f3ff79SMike Smith 	ifp->if_hdrlen = 0;
26046f3ff79SMike Smith 	ifp->if_addrlen = 0;
26146f3ff79SMike Smith 	ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
26246f3ff79SMike Smith 	if_attach(ifp);
26346f3ff79SMike Smith 
2648f84257eSDag-Erling Smørgrav 	bpfattach(ifp, DLT_NULL, sizeof(u_int32_t));
26546f3ff79SMike Smith 
2660f210c92SNicolas Souchu 	return (0);
26746f3ff79SMike Smith }
26846f3ff79SMike Smith /*
26946f3ff79SMike Smith  * Build the translation tables for the LPIP (BSD unix) protocol.
27046f3ff79SMike Smith  * We don't want to calculate these nasties in our tight loop, so we
27146f3ff79SMike Smith  * precalculate them when we initialize.
27246f3ff79SMike Smith  */
27346f3ff79SMike Smith static int
27446f3ff79SMike Smith lpinittables (void)
27546f3ff79SMike Smith {
27646f3ff79SMike Smith     int i;
27746f3ff79SMike Smith 
27846f3ff79SMike Smith     if (!txmith)
27946f3ff79SMike Smith 	txmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT);
28046f3ff79SMike Smith 
28146f3ff79SMike Smith     if (!txmith)
28246f3ff79SMike Smith 	return 1;
28346f3ff79SMike Smith 
28446f3ff79SMike Smith     if (!ctxmith)
28546f3ff79SMike Smith 	ctxmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT);
28646f3ff79SMike Smith 
28746f3ff79SMike Smith     if (!ctxmith)
28846f3ff79SMike Smith 	return 1;
28946f3ff79SMike Smith 
29046f3ff79SMike Smith     for (i=0; i < LPIPTBLSIZE; i++) {
29146f3ff79SMike Smith 	ctxmith[i] = (i & 0xF0) >> 4;
29246f3ff79SMike Smith 	ctxmitl[i] = 0x10 | (i & 0x0F);
29346f3ff79SMike Smith 	ctrecvh[i] = (i & 0x78) << 1;
29446f3ff79SMike Smith 	ctrecvl[i] = (i & 0x78) >> 3;
29546f3ff79SMike Smith     }
29646f3ff79SMike Smith 
29746f3ff79SMike Smith     for (i=0; i < LPIPTBLSIZE; i++) {
29846f3ff79SMike Smith 	txmith[i] = ((i & 0x80) >> 3) | ((i & 0x70) >> 4) | 0x08;
29946f3ff79SMike Smith 	txmitl[i] = ((i & 0x08) << 1) | (i & 0x07);
30046f3ff79SMike Smith 	trecvh[i] = ((~i) & 0x80) | ((i & 0x38) << 1);
30146f3ff79SMike Smith 	trecvl[i] = (((~i) & 0x80) >> 4) | ((i & 0x38) >> 3);
30246f3ff79SMike Smith     }
30346f3ff79SMike Smith 
30446f3ff79SMike Smith     return 0;
30546f3ff79SMike Smith }
30646f3ff79SMike Smith 
30746f3ff79SMike Smith /*
30846f3ff79SMike Smith  * Process an ioctl request.
30946f3ff79SMike Smith  */
31046f3ff79SMike Smith 
31146f3ff79SMike Smith static int
31246f3ff79SMike Smith lpioctl (struct ifnet *ifp, u_long cmd, caddr_t data)
31346f3ff79SMike Smith {
3140f210c92SNicolas Souchu     device_t dev = UNITODEVICE(ifp->if_unit);
3150f210c92SNicolas Souchu     device_t ppbus = device_get_parent(dev);
3160f210c92SNicolas Souchu     struct lp_data *sc = DEVTOSOFTC(dev);
31746f3ff79SMike Smith     struct ifaddr *ifa = (struct ifaddr *)data;
31846f3ff79SMike Smith     struct ifreq *ifr = (struct ifreq *)data;
31946f3ff79SMike Smith     u_char *ptr;
3200f210c92SNicolas Souchu     void *ih;
32146f3ff79SMike Smith     int error;
32246f3ff79SMike Smith 
32346f3ff79SMike Smith     switch (cmd) {
32446f3ff79SMike Smith 
32546f3ff79SMike Smith     case SIOCSIFDSTADDR:
32646f3ff79SMike Smith     case SIOCAIFADDR:
32746f3ff79SMike Smith     case SIOCSIFADDR:
32846f3ff79SMike Smith 	if (ifa->ifa_addr->sa_family != AF_INET)
32946f3ff79SMike Smith 	    return EAFNOSUPPORT;
33046f3ff79SMike Smith 
33146f3ff79SMike Smith 	ifp->if_flags |= IFF_UP;
33246f3ff79SMike Smith 	/* FALLTHROUGH */
33346f3ff79SMike Smith     case SIOCSIFFLAGS:
33446f3ff79SMike Smith 	if ((!(ifp->if_flags & IFF_UP)) && (ifp->if_flags & IFF_RUNNING)) {
33546f3ff79SMike Smith 
3360f210c92SNicolas Souchu 	    ppb_wctr(ppbus, 0x00);
33746f3ff79SMike Smith 	    ifp->if_flags &= ~IFF_RUNNING;
33846f3ff79SMike Smith 
33946f3ff79SMike Smith 	    /* IFF_UP is not set, try to release the bus anyway */
3400f210c92SNicolas Souchu 	    ppb_release_bus(ppbus, dev);
34146f3ff79SMike Smith 	    break;
34246f3ff79SMike Smith 	}
34346f3ff79SMike Smith 	if (((ifp->if_flags & IFF_UP)) && (!(ifp->if_flags & IFF_RUNNING))) {
34446f3ff79SMike Smith 
34524063475SNicolas Souchu 	    /* XXX
34646f3ff79SMike Smith 	     * Should the request be interruptible?
34746f3ff79SMike Smith 	     */
3480f210c92SNicolas Souchu 	    if ((error = ppb_request_bus(ppbus, dev, PPB_WAIT|PPB_INTR)))
34946f3ff79SMike Smith 		return (error);
35046f3ff79SMike Smith 
35124063475SNicolas Souchu 	    /* Now IFF_UP means that we own the bus */
35224063475SNicolas Souchu 
3530f210c92SNicolas Souchu 	    ppb_set_mode(ppbus, PPB_COMPATIBLE);
35424063475SNicolas Souchu 
35546f3ff79SMike Smith 	    if (lpinittables()) {
3560f210c92SNicolas Souchu 		ppb_release_bus(ppbus, dev);
35746f3ff79SMike Smith 		return ENOBUFS;
35846f3ff79SMike Smith 	    }
35946f3ff79SMike Smith 
36046f3ff79SMike Smith 	    sc->sc_ifbuf = malloc(sc->sc_if.if_mtu + MLPIPHDRLEN,
36146f3ff79SMike Smith 				  M_DEVBUF, M_WAITOK);
36246f3ff79SMike Smith 	    if (!sc->sc_ifbuf) {
3630f210c92SNicolas Souchu 		ppb_release_bus(ppbus, dev);
36446f3ff79SMike Smith 		return ENOBUFS;
36546f3ff79SMike Smith 	    }
36646f3ff79SMike Smith 
3670f210c92SNicolas Souchu 	    /* attach our interrupt handler, later detached when the bus is released */
3680f210c92SNicolas Souchu 	    if ((error = BUS_SETUP_INTR(ppbus, dev, sc->res_irq,
3690f210c92SNicolas Souchu 					INTR_TYPE_NET, lp_intr, dev, &ih))) {
3700f210c92SNicolas Souchu 		ppb_release_bus(ppbus, dev);
3710f210c92SNicolas Souchu 		return (error);
3720f210c92SNicolas Souchu 	    }
3730f210c92SNicolas Souchu 
3740f210c92SNicolas Souchu 	    ppb_wctr(ppbus, IRQENABLE);
37546f3ff79SMike Smith 	    ifp->if_flags |= IFF_RUNNING;
37646f3ff79SMike Smith 	}
37746f3ff79SMike Smith 	break;
37846f3ff79SMike Smith 
37946f3ff79SMike Smith     case SIOCSIFMTU:
38046f3ff79SMike Smith 	ptr = sc->sc_ifbuf;
38146f3ff79SMike Smith 	sc->sc_ifbuf = malloc(ifr->ifr_mtu+MLPIPHDRLEN, M_DEVBUF, M_NOWAIT);
38246f3ff79SMike Smith 	if (!sc->sc_ifbuf) {
38346f3ff79SMike Smith 	    sc->sc_ifbuf = ptr;
38446f3ff79SMike Smith 	    return ENOBUFS;
38546f3ff79SMike Smith 	}
38646f3ff79SMike Smith 	if (ptr)
38746f3ff79SMike Smith 	    free(ptr,M_DEVBUF);
38846f3ff79SMike Smith 	sc->sc_if.if_mtu = ifr->ifr_mtu;
38946f3ff79SMike Smith 	break;
39046f3ff79SMike Smith 
39146f3ff79SMike Smith     case SIOCGIFMTU:
39246f3ff79SMike Smith 	ifr->ifr_mtu = sc->sc_if.if_mtu;
39346f3ff79SMike Smith 	break;
39446f3ff79SMike Smith 
39546f3ff79SMike Smith     case SIOCADDMULTI:
39646f3ff79SMike Smith     case SIOCDELMULTI:
39746f3ff79SMike Smith 	if (ifr == 0) {
39846f3ff79SMike Smith 	    return EAFNOSUPPORT;		/* XXX */
39946f3ff79SMike Smith 	}
40046f3ff79SMike Smith 	switch (ifr->ifr_addr.sa_family) {
40146f3ff79SMike Smith 
40246f3ff79SMike Smith 	case AF_INET:
40346f3ff79SMike Smith 	    break;
40446f3ff79SMike Smith 
40546f3ff79SMike Smith 	default:
40646f3ff79SMike Smith 	    return EAFNOSUPPORT;
40746f3ff79SMike Smith 	}
40846f3ff79SMike Smith 	break;
40946f3ff79SMike Smith 
41080015f13SMike Smith     case SIOCGIFMEDIA:
41180015f13SMike Smith 	/*
41280015f13SMike Smith 	 * No ifmedia support at this stage; maybe use it
41380015f13SMike Smith 	 * in future for eg. protocol selection.
41480015f13SMike Smith 	 */
41580015f13SMike Smith 	return EINVAL;
41680015f13SMike Smith 
41746f3ff79SMike Smith     default:
418162886e2SBruce Evans 	lprintf("LP:ioctl(0x%lx)\n", cmd);
41946f3ff79SMike Smith 	return EINVAL;
42046f3ff79SMike Smith     }
42146f3ff79SMike Smith     return 0;
42246f3ff79SMike Smith }
42346f3ff79SMike Smith 
42446f3ff79SMike Smith static __inline int
4250f210c92SNicolas Souchu clpoutbyte (u_char byte, int spin, device_t ppbus)
42646f3ff79SMike Smith {
4270f210c92SNicolas Souchu 	ppb_wdtr(ppbus, ctxmitl[byte]);
4280f210c92SNicolas Souchu 	while (ppb_rstr(ppbus) & CLPIP_SHAKE)
42946f3ff79SMike Smith 		if (--spin == 0) {
43046f3ff79SMike Smith 			return 1;
43146f3ff79SMike Smith 		}
4320f210c92SNicolas Souchu 	ppb_wdtr(ppbus, ctxmith[byte]);
4330f210c92SNicolas Souchu 	while (!(ppb_rstr(ppbus) & CLPIP_SHAKE))
43446f3ff79SMike Smith 		if (--spin == 0) {
43546f3ff79SMike Smith 			return 1;
43646f3ff79SMike Smith 		}
43746f3ff79SMike Smith 	return 0;
43846f3ff79SMike Smith }
43946f3ff79SMike Smith 
44046f3ff79SMike Smith static __inline int
4410f210c92SNicolas Souchu clpinbyte (int spin, device_t ppbus)
44246f3ff79SMike Smith {
44324063475SNicolas Souchu 	u_char c, cl;
44446f3ff79SMike Smith 
4450f210c92SNicolas Souchu 	while((ppb_rstr(ppbus) & CLPIP_SHAKE))
44646f3ff79SMike Smith 	    if(!--spin) {
44746f3ff79SMike Smith 		return -1;
44846f3ff79SMike Smith 	    }
4490f210c92SNicolas Souchu 	cl = ppb_rstr(ppbus);
4500f210c92SNicolas Souchu 	ppb_wdtr(ppbus, 0x10);
45146f3ff79SMike Smith 
4520f210c92SNicolas Souchu 	while(!(ppb_rstr(ppbus) & CLPIP_SHAKE))
45346f3ff79SMike Smith 	    if(!--spin) {
45446f3ff79SMike Smith 		return -1;
45546f3ff79SMike Smith 	    }
4560f210c92SNicolas Souchu 	c = ppb_rstr(ppbus);
4570f210c92SNicolas Souchu 	ppb_wdtr(ppbus, 0x00);
45846f3ff79SMike Smith 
45946f3ff79SMike Smith 	return (ctrecvl[cl] | ctrecvh[c]);
46046f3ff79SMike Smith }
46146f3ff79SMike Smith 
4628f84257eSDag-Erling Smørgrav static void
4638f84257eSDag-Erling Smørgrav lptap(struct ifnet *ifp, struct mbuf *m)
4648f84257eSDag-Erling Smørgrav {
4658f84257eSDag-Erling Smørgrav 	/*
4668f84257eSDag-Erling Smørgrav 	 * Send a packet through bpf. We need to prepend the address family
4678f84257eSDag-Erling Smørgrav 	 * as a four byte field. Cons up a dummy header to pacify bpf. This
4688f84257eSDag-Erling Smørgrav 	 * is safe because bpf will only read from the mbuf (i.e., it won't
4698f84257eSDag-Erling Smørgrav 	 * try to free it or keep a pointer to it).
4708f84257eSDag-Erling Smørgrav 	 */
4718f84257eSDag-Erling Smørgrav 	u_int32_t af = AF_INET;
4728f84257eSDag-Erling Smørgrav 	struct mbuf m0;
4738f84257eSDag-Erling Smørgrav 
4748f84257eSDag-Erling Smørgrav 	m0.m_next = m;
4758f84257eSDag-Erling Smørgrav 	m0.m_len = sizeof(u_int32_t);
4768f84257eSDag-Erling Smørgrav 	m0.m_data = (char *)&af;
4778f84257eSDag-Erling Smørgrav 	bpf_mtap(ifp, &m0);
4788f84257eSDag-Erling Smørgrav }
4798f84257eSDag-Erling Smørgrav 
48046f3ff79SMike Smith static void
4810f210c92SNicolas Souchu lp_intr (void *arg)
48246f3ff79SMike Smith {
4830f210c92SNicolas Souchu 	device_t dev = (device_t)arg;
4840f210c92SNicolas Souchu         device_t ppbus = device_get_parent(dev);
4850f210c92SNicolas Souchu 	struct lp_data *sc = DEVTOSOFTC(dev);
48646f3ff79SMike Smith 	int len, s, j;
48746f3ff79SMike Smith 	u_char *bp;
48846f3ff79SMike Smith 	u_char c, cl;
48946f3ff79SMike Smith 	struct mbuf *top;
49046f3ff79SMike Smith 
49146f3ff79SMike Smith 	s = splhigh();
49246f3ff79SMike Smith 
49346f3ff79SMike Smith 	if (sc->sc_if.if_flags & IFF_LINK0) {
49446f3ff79SMike Smith 
49546f3ff79SMike Smith 	    /* Ack. the request */
4960f210c92SNicolas Souchu 	    ppb_wdtr(ppbus, 0x01);
49746f3ff79SMike Smith 
49846f3ff79SMike Smith 	    /* Get the packet length */
4990f210c92SNicolas Souchu 	    j = clpinbyte(LPMAXSPIN2, ppbus);
50046f3ff79SMike Smith 	    if (j == -1)
50146f3ff79SMike Smith 		goto err;
50246f3ff79SMike Smith 	    len = j;
5030f210c92SNicolas Souchu 	    j = clpinbyte(LPMAXSPIN2, ppbus);
50446f3ff79SMike Smith 	    if (j == -1)
50546f3ff79SMike Smith 		goto err;
50646f3ff79SMike Smith 	    len = len + (j << 8);
50746f3ff79SMike Smith 	    if (len > sc->sc_if.if_mtu + MLPIPHDRLEN)
50846f3ff79SMike Smith 		goto err;
50946f3ff79SMike Smith 
51046f3ff79SMike Smith 	    bp  = sc->sc_ifbuf;
51146f3ff79SMike Smith 
51246f3ff79SMike Smith 	    while (len--) {
5130f210c92SNicolas Souchu 	        j = clpinbyte(LPMAXSPIN2, ppbus);
51446f3ff79SMike Smith 	        if (j == -1) {
51546f3ff79SMike Smith 		    goto err;
51646f3ff79SMike Smith 	        }
51746f3ff79SMike Smith 	        *bp++ = j;
51846f3ff79SMike Smith 	    }
51946f3ff79SMike Smith 	    /* Get and ignore checksum */
5200f210c92SNicolas Souchu 	    j = clpinbyte(LPMAXSPIN2, ppbus);
52146f3ff79SMike Smith 	    if (j == -1) {
52246f3ff79SMike Smith 	        goto err;
52346f3ff79SMike Smith 	    }
52446f3ff79SMike Smith 
52546f3ff79SMike Smith 	    len = bp - sc->sc_ifbuf;
52646f3ff79SMike Smith 	    if (len <= CLPIPHDRLEN)
52746f3ff79SMike Smith 	        goto err;
52846f3ff79SMike Smith 
52946f3ff79SMike Smith 	    sc->sc_iferrs = 0;
53046f3ff79SMike Smith 
53146f3ff79SMike Smith 	    if (IF_QFULL(&ipintrq)) {
53246f3ff79SMike Smith 	        lprintf("DROP");
53346f3ff79SMike Smith 	        IF_DROP(&ipintrq);
53446f3ff79SMike Smith 		goto done;
53546f3ff79SMike Smith 	    }
53646f3ff79SMike Smith 	    len -= CLPIPHDRLEN;
53746f3ff79SMike Smith 	    sc->sc_if.if_ipackets++;
53846f3ff79SMike Smith 	    sc->sc_if.if_ibytes += len;
53946f3ff79SMike Smith 	    top = m_devget(sc->sc_ifbuf + CLPIPHDRLEN, len, 0, &sc->sc_if, 0);
54046f3ff79SMike Smith 	    if (top) {
5418f84257eSDag-Erling Smørgrav 		if (sc->sc_if.if_bpf)
5428f84257eSDag-Erling Smørgrav 		    lptap(&sc->sc_if, top);
54346f3ff79SMike Smith 	        IF_ENQUEUE(&ipintrq, top);
54446f3ff79SMike Smith 	        schednetisr(NETISR_IP);
54546f3ff79SMike Smith 	    }
54646f3ff79SMike Smith 	    goto done;
54746f3ff79SMike Smith 	}
5480f210c92SNicolas Souchu 	while ((ppb_rstr(ppbus) & LPIP_SHAKE)) {
54946f3ff79SMike Smith 	    len = sc->sc_if.if_mtu + LPIPHDRLEN;
55046f3ff79SMike Smith 	    bp  = sc->sc_ifbuf;
55146f3ff79SMike Smith 	    while (len--) {
55246f3ff79SMike Smith 
5530f210c92SNicolas Souchu 		cl = ppb_rstr(ppbus);
5540f210c92SNicolas Souchu 		ppb_wdtr(ppbus, 8);
55546f3ff79SMike Smith 
55646f3ff79SMike Smith 		j = LPMAXSPIN2;
5570f210c92SNicolas Souchu 		while((ppb_rstr(ppbus) & LPIP_SHAKE))
55846f3ff79SMike Smith 		    if(!--j) goto err;
55946f3ff79SMike Smith 
5600f210c92SNicolas Souchu 		c = ppb_rstr(ppbus);
5610f210c92SNicolas Souchu 		ppb_wdtr(ppbus, 0);
56246f3ff79SMike Smith 
56346f3ff79SMike Smith 		*bp++= trecvh[cl] | trecvl[c];
56446f3ff79SMike Smith 
56546f3ff79SMike Smith 		j = LPMAXSPIN2;
5660f210c92SNicolas Souchu 		while (!((cl=ppb_rstr(ppbus)) & LPIP_SHAKE)) {
56746f3ff79SMike Smith 		    if (cl != c &&
5680f210c92SNicolas Souchu 			(((cl = ppb_rstr(ppbus)) ^ 0xb8) & 0xf8) ==
56946f3ff79SMike Smith 			  (c & 0xf8))
57046f3ff79SMike Smith 			goto end;
57146f3ff79SMike Smith 		    if (!--j) goto err;
57246f3ff79SMike Smith 		}
57346f3ff79SMike Smith 	    }
57446f3ff79SMike Smith 
57546f3ff79SMike Smith 	end:
57646f3ff79SMike Smith 	    len = bp - sc->sc_ifbuf;
57746f3ff79SMike Smith 	    if (len <= LPIPHDRLEN)
57846f3ff79SMike Smith 		goto err;
57946f3ff79SMike Smith 
58046f3ff79SMike Smith 	    sc->sc_iferrs = 0;
58146f3ff79SMike Smith 
58246f3ff79SMike Smith 	    if (IF_QFULL(&ipintrq)) {
58346f3ff79SMike Smith 		lprintf("DROP");
58446f3ff79SMike Smith 		IF_DROP(&ipintrq);
58546f3ff79SMike Smith 		goto done;
58646f3ff79SMike Smith 	    }
58746f3ff79SMike Smith 	    len -= LPIPHDRLEN;
58846f3ff79SMike Smith 	    sc->sc_if.if_ipackets++;
58946f3ff79SMike Smith 	    sc->sc_if.if_ibytes += len;
59046f3ff79SMike Smith 	    top = m_devget(sc->sc_ifbuf + LPIPHDRLEN, len, 0, &sc->sc_if, 0);
59146f3ff79SMike Smith 	    if (top) {
5928f84257eSDag-Erling Smørgrav 		if (sc->sc_if.if_bpf)
5938f84257eSDag-Erling Smørgrav 		    lptap(&sc->sc_if, top);
59446f3ff79SMike Smith 		IF_ENQUEUE(&ipintrq, top);
59546f3ff79SMike Smith 		schednetisr(NETISR_IP);
59646f3ff79SMike Smith 	    }
59746f3ff79SMike Smith 	}
59846f3ff79SMike Smith 	goto done;
59946f3ff79SMike Smith 
60046f3ff79SMike Smith     err:
6010f210c92SNicolas Souchu 	ppb_wdtr(ppbus, 0);
60246f3ff79SMike Smith 	lprintf("R");
60346f3ff79SMike Smith 	sc->sc_if.if_ierrors++;
60446f3ff79SMike Smith 	sc->sc_iferrs++;
60546f3ff79SMike Smith 
60646f3ff79SMike Smith 	/*
60746f3ff79SMike Smith 	 * We are not able to send receive anything for now,
60846f3ff79SMike Smith 	 * so stop wasting our time
60946f3ff79SMike Smith 	 */
61046f3ff79SMike Smith 	if (sc->sc_iferrs > LPMAXERRS) {
6110f210c92SNicolas Souchu 	    printf("lp%d: Too many errors, Going off-line.\n", device_get_unit(dev));
6120f210c92SNicolas Souchu 	    ppb_wctr(ppbus, 0x00);
61346f3ff79SMike Smith 	    sc->sc_if.if_flags &= ~IFF_RUNNING;
61446f3ff79SMike Smith 	    sc->sc_iferrs=0;
61546f3ff79SMike Smith 	}
61646f3ff79SMike Smith 
61746f3ff79SMike Smith     done:
61846f3ff79SMike Smith 	splx(s);
61946f3ff79SMike Smith 	return;
62046f3ff79SMike Smith }
62146f3ff79SMike Smith 
62246f3ff79SMike Smith static __inline int
6230f210c92SNicolas Souchu lpoutbyte (u_char byte, int spin, device_t ppbus)
62446f3ff79SMike Smith {
6250f210c92SNicolas Souchu     ppb_wdtr(ppbus, txmith[byte]);
6260f210c92SNicolas Souchu     while (!(ppb_rstr(ppbus) & LPIP_SHAKE))
62746f3ff79SMike Smith 	if (--spin == 0)
62846f3ff79SMike Smith 		return 1;
6290f210c92SNicolas Souchu     ppb_wdtr(ppbus, txmitl[byte]);
6300f210c92SNicolas Souchu     while (ppb_rstr(ppbus) & LPIP_SHAKE)
63146f3ff79SMike Smith 	if (--spin == 0)
63246f3ff79SMike Smith 		return 1;
63346f3ff79SMike Smith     return 0;
63446f3ff79SMike Smith }
63546f3ff79SMike Smith 
63646f3ff79SMike Smith static int
63746f3ff79SMike Smith lpoutput (struct ifnet *ifp, struct mbuf *m,
63846f3ff79SMike Smith 	  struct sockaddr *dst, struct rtentry *rt)
63946f3ff79SMike Smith {
6400f210c92SNicolas Souchu     device_t dev = UNITODEVICE(ifp->if_unit);
6410f210c92SNicolas Souchu     device_t ppbus = device_get_parent(dev);
64246f3ff79SMike Smith     int s, err;
64346f3ff79SMike Smith     struct mbuf *mm;
64446f3ff79SMike Smith     u_char *cp = "\0\0";
64546f3ff79SMike Smith     u_char chksum = 0;
64646f3ff79SMike Smith     int count = 0;
6478f84257eSDag-Erling Smørgrav     int i, len, spin;
64846f3ff79SMike Smith 
64946f3ff79SMike Smith     /* We need a sensible value if we abort */
65046f3ff79SMike Smith     cp++;
65146f3ff79SMike Smith     ifp->if_flags |= IFF_RUNNING;
65246f3ff79SMike Smith 
65346f3ff79SMike Smith     err = 1;			/* assume we're aborting because of an error */
65446f3ff79SMike Smith 
65546f3ff79SMike Smith     s = splhigh();
65646f3ff79SMike Smith 
65746f3ff79SMike Smith     /* Suspend (on laptops) or receive-errors might have taken us offline */
6580f210c92SNicolas Souchu     ppb_wctr(ppbus, IRQENABLE);
65946f3ff79SMike Smith 
66046f3ff79SMike Smith     if (ifp->if_flags & IFF_LINK0) {
66146f3ff79SMike Smith 
6620f210c92SNicolas Souchu 	if (!(ppb_rstr(ppbus) & CLPIP_SHAKE)) {
66346f3ff79SMike Smith 	    lprintf("&");
6640f210c92SNicolas Souchu 	    lp_intr(dev);
66546f3ff79SMike Smith 	}
66646f3ff79SMike Smith 
66746f3ff79SMike Smith 	/* Alert other end to pending packet */
66846f3ff79SMike Smith 	spin = LPMAXSPIN1;
6690f210c92SNicolas Souchu 	ppb_wdtr(ppbus, 0x08);
6700f210c92SNicolas Souchu 	while ((ppb_rstr(ppbus) & 0x08) == 0)
67146f3ff79SMike Smith 		if (--spin == 0) {
67246f3ff79SMike Smith 			goto nend;
67346f3ff79SMike Smith 		}
67446f3ff79SMike Smith 
67546f3ff79SMike Smith 	/* Calculate length of packet, then send that */
67646f3ff79SMike Smith 
67746f3ff79SMike Smith 	count += 14;		/* Ethernet header len */
67846f3ff79SMike Smith 
67946f3ff79SMike Smith 	mm = m;
68046f3ff79SMike Smith 	for (mm = m; mm; mm = mm->m_next) {
68146f3ff79SMike Smith 		count += mm->m_len;
68246f3ff79SMike Smith 	}
6830f210c92SNicolas Souchu 	if (clpoutbyte(count & 0xFF, LPMAXSPIN1, ppbus))
68446f3ff79SMike Smith 		goto nend;
6850f210c92SNicolas Souchu 	if (clpoutbyte((count >> 8) & 0xFF, LPMAXSPIN1, ppbus))
68646f3ff79SMike Smith 		goto nend;
68746f3ff79SMike Smith 
68846f3ff79SMike Smith 	/* Send dummy ethernet header */
68946f3ff79SMike Smith 	for (i = 0; i < 12; i++) {
6900f210c92SNicolas Souchu 		if (clpoutbyte(i, LPMAXSPIN1, ppbus))
69146f3ff79SMike Smith 			goto nend;
69246f3ff79SMike Smith 		chksum += i;
69346f3ff79SMike Smith 	}
69446f3ff79SMike Smith 
6950f210c92SNicolas Souchu 	if (clpoutbyte(0x08, LPMAXSPIN1, ppbus))
69646f3ff79SMike Smith 		goto nend;
6970f210c92SNicolas Souchu 	if (clpoutbyte(0x00, LPMAXSPIN1, ppbus))
69846f3ff79SMike Smith 		goto nend;
69946f3ff79SMike Smith 	chksum += 0x08 + 0x00;		/* Add into checksum */
70046f3ff79SMike Smith 
70146f3ff79SMike Smith 	mm = m;
70246f3ff79SMike Smith 	do {
70346f3ff79SMike Smith 		cp = mtod(mm, u_char *);
7048f84257eSDag-Erling Smørgrav 		len = mm->m_len;
7058f84257eSDag-Erling Smørgrav 		while (len--) {
70646f3ff79SMike Smith 			chksum += *cp;
7070f210c92SNicolas Souchu 			if (clpoutbyte(*cp++, LPMAXSPIN2, ppbus))
70846f3ff79SMike Smith 				goto nend;
70946f3ff79SMike Smith 		}
71046f3ff79SMike Smith 	} while ((mm = mm->m_next));
71146f3ff79SMike Smith 
71246f3ff79SMike Smith 	/* Send checksum */
7130f210c92SNicolas Souchu 	if (clpoutbyte(chksum, LPMAXSPIN2, ppbus))
71446f3ff79SMike Smith 		goto nend;
71546f3ff79SMike Smith 
71646f3ff79SMike Smith 	/* Go quiescent */
7170f210c92SNicolas Souchu 	ppb_wdtr(ppbus, 0);
71846f3ff79SMike Smith 
71946f3ff79SMike Smith 	err = 0;			/* No errors */
72046f3ff79SMike Smith 
72146f3ff79SMike Smith 	nend:
72246f3ff79SMike Smith 	if (err)  {				/* if we didn't timeout... */
72346f3ff79SMike Smith 		ifp->if_oerrors++;
72446f3ff79SMike Smith 		lprintf("X");
72546f3ff79SMike Smith 	} else {
72646f3ff79SMike Smith 		ifp->if_opackets++;
72746f3ff79SMike Smith 		ifp->if_obytes += m->m_pkthdr.len;
7288f84257eSDag-Erling Smørgrav 		if (ifp->if_bpf)
7298f84257eSDag-Erling Smørgrav 		    lptap(ifp, m);
73046f3ff79SMike Smith 	}
73146f3ff79SMike Smith 
73246f3ff79SMike Smith 	m_freem(m);
73346f3ff79SMike Smith 
7340f210c92SNicolas Souchu 	if (!(ppb_rstr(ppbus) & CLPIP_SHAKE)) {
73546f3ff79SMike Smith 		lprintf("^");
7360f210c92SNicolas Souchu 		lp_intr(dev);
73746f3ff79SMike Smith 	}
73846f3ff79SMike Smith 	(void) splx(s);
73946f3ff79SMike Smith 	return 0;
74046f3ff79SMike Smith     }
74146f3ff79SMike Smith 
7420f210c92SNicolas Souchu     if (ppb_rstr(ppbus) & LPIP_SHAKE) {
74346f3ff79SMike Smith         lprintf("&");
7440f210c92SNicolas Souchu         lp_intr(dev);
74546f3ff79SMike Smith     }
74646f3ff79SMike Smith 
7470f210c92SNicolas Souchu     if (lpoutbyte(0x08, LPMAXSPIN1, ppbus))
74846f3ff79SMike Smith         goto end;
7490f210c92SNicolas Souchu     if (lpoutbyte(0x00, LPMAXSPIN2, ppbus))
75046f3ff79SMike Smith         goto end;
75146f3ff79SMike Smith 
75246f3ff79SMike Smith     mm = m;
75346f3ff79SMike Smith     do {
75446f3ff79SMike Smith         cp = mtod(mm,u_char *);
7558f84257eSDag-Erling Smørgrav 	len = mm->m_len;
7568f84257eSDag-Erling Smørgrav         while (len--)
7570f210c92SNicolas Souchu 	    if (lpoutbyte(*cp++, LPMAXSPIN2, ppbus))
75846f3ff79SMike Smith 	        goto end;
75946f3ff79SMike Smith     } while ((mm = mm->m_next));
76046f3ff79SMike Smith 
76146f3ff79SMike Smith     err = 0;				/* no errors were encountered */
76246f3ff79SMike Smith 
76346f3ff79SMike Smith     end:
76446f3ff79SMike Smith     --cp;
7650f210c92SNicolas Souchu     ppb_wdtr(ppbus, txmitl[*cp] ^ 0x17);
76646f3ff79SMike Smith 
76746f3ff79SMike Smith     if (err)  {				/* if we didn't timeout... */
76846f3ff79SMike Smith 	ifp->if_oerrors++;
76946f3ff79SMike Smith         lprintf("X");
77046f3ff79SMike Smith     } else {
77146f3ff79SMike Smith 	ifp->if_opackets++;
77246f3ff79SMike Smith 	ifp->if_obytes += m->m_pkthdr.len;
7738f84257eSDag-Erling Smørgrav 	if (ifp->if_bpf)
7748f84257eSDag-Erling Smørgrav 	    lptap(ifp, m);
77546f3ff79SMike Smith     }
77646f3ff79SMike Smith 
77746f3ff79SMike Smith     m_freem(m);
77846f3ff79SMike Smith 
7790f210c92SNicolas Souchu     if (ppb_rstr(ppbus) & LPIP_SHAKE) {
78046f3ff79SMike Smith 	lprintf("^");
7810f210c92SNicolas Souchu 	lp_intr(dev);
78246f3ff79SMike Smith     }
78346f3ff79SMike Smith 
78446f3ff79SMike Smith     (void) splx(s);
78546f3ff79SMike Smith     return 0;
78646f3ff79SMike Smith }
7870f210c92SNicolas Souchu 
7880f210c92SNicolas Souchu DRIVER_MODULE(plip, ppbus, lp_driver, lp_devclass, 0, 0);
7890f210c92SNicolas Souchu 
7900f210c92SNicolas Souchu #endif /* NPLIP > 0 */
791