if_plip.c revision 43109
1/*-
2 * Copyright (c) 1997 Poul-Henning Kamp
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 *	From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp
27 *	$Id: if_plip.c,v 1.7 1999/01/09 18:10:37 nsouch Exp $
28 */
29
30/*
31 * Parallel port TCP/IP interfaces added.  I looked at the driver from
32 * MACH but this is a complete rewrite, and btw. incompatible, and it
33 * should perform better too.  I have never run the MACH driver though.
34 *
35 * This driver sends two bytes (0x08, 0x00) in front of each packet,
36 * to allow us to distinguish another format later.
37 *
38 * Now added an Linux/Crynwr compatibility mode which is enabled using
39 * IF_LINK0 - Tim Wilkinson.
40 *
41 * TODO:
42 *    Make HDLC/PPP mode, use IF_LLC1 to enable.
43 *
44 * Connect the two computers using a Laplink parallel cable to use this
45 * feature:
46 *
47 *      +----------------------------------------+
48 * 	|A-name	A-End	B-End	Descr.	Port/Bit |
49 *      +----------------------------------------+
50 *	|DATA0	2	15	Data	0/0x01   |
51 *	|-ERROR	15	2	   	1/0x08   |
52 *      +----------------------------------------+
53 *	|DATA1	3	13	Data	0/0x02	 |
54 *	|+SLCT	13	3	   	1/0x10   |
55 *      +----------------------------------------+
56 *	|DATA2	4	12	Data	0/0x04   |
57 *	|+PE	12	4	   	1/0x20   |
58 *      +----------------------------------------+
59 *	|DATA3	5	10	Strobe	0/0x08   |
60 *	|-ACK	10	5	   	1/0x40   |
61 *      +----------------------------------------+
62 *	|DATA4	6	11	Data	0/0x10   |
63 *	|BUSY	11	6	   	1/~0x80  |
64 *      +----------------------------------------+
65 *	|GND	18-25	18-25	GND	-        |
66 *      +----------------------------------------+
67 *
68 * Expect transfer-rates up to 75 kbyte/sec.
69 *
70 * If GCC could correctly grok
71 *	register int port asm("edx")
72 * the code would be cleaner
73 *
74 * Poul-Henning Kamp <phk@freebsd.org>
75 */
76
77/*
78 * Update for ppbus, PLIP support only - Nicolas Souchu
79 */
80
81#include <sys/param.h>
82#include <sys/systm.h>
83#include <sys/mbuf.h>
84#include <sys/socket.h>
85#include <sys/sockio.h>
86#include <sys/kernel.h>
87#include <sys/malloc.h>
88
89#include <net/if.h>
90#include <net/if_types.h>
91#include <net/netisr.h>
92
93#include <netinet/in.h>
94#include <netinet/in_var.h>
95
96#include "bpfilter.h"
97#if NBPFILTER > 0
98#include <net/bpf.h>
99#endif
100
101#include <dev/ppbus/ppbconf.h>
102#include <dev/ppbus/nlpt.h>
103
104#include "opt_plip.h"
105
106#ifndef LPMTU			/* MTU for the lp# interfaces */
107#define	LPMTU	1500
108#endif
109
110#ifndef LPMAXSPIN1		/* DELAY factor for the lp# interfaces */
111#define	LPMAXSPIN1	8000   /* Spinning for remote intr to happen */
112#endif
113
114#ifndef LPMAXSPIN2		/* DELAY factor for the lp# interfaces */
115#define	LPMAXSPIN2	500	/* Spinning for remote handshake to happen */
116#endif
117
118#ifndef LPMAXERRS		/* Max errors before !RUNNING */
119#define	LPMAXERRS	100
120#endif
121
122#define CLPIPHDRLEN	14	/* We send dummy ethernet addresses (two) + packet type in front of packet */
123#define	CLPIP_SHAKE	0x80	/* This bit toggles between nibble reception */
124#define MLPIPHDRLEN	CLPIPHDRLEN
125
126#define LPIPHDRLEN	2	/* We send 0x08, 0x00 in front of packet */
127#define	LPIP_SHAKE	0x40	/* This bit toggles between nibble reception */
128#if !defined(MLPIPHDRLEN) || LPIPHDRLEN > MLPIPHDRLEN
129#define MLPIPHDRLEN	LPIPHDRLEN
130#endif
131
132#define	LPIPTBLSIZE	256	/* Size of octet translation table */
133
134#ifndef PLIP_DEBUG
135#define lprintf (void)
136#else
137#define lprintf		if (lptflag) printf
138static int volatile lptflag = 1;
139#endif
140
141struct lpt_softc {
142	unsigned short lp_unit;
143
144	struct ppb_device lp_dev;
145
146	struct  ifnet	sc_if;
147	u_char		*sc_ifbuf;
148	int		sc_iferrs;
149};
150
151static int	nlp = 0;
152#define MAXPLIP	8			/* XXX not much better! */
153static struct lpt_softc *lpdata[MAXPLIP];
154
155
156/* Tables for the lp# interface */
157static u_char *txmith;
158#define txmitl (txmith+(1*LPIPTBLSIZE))
159#define trecvh (txmith+(2*LPIPTBLSIZE))
160#define trecvl (txmith+(3*LPIPTBLSIZE))
161
162static u_char *ctxmith;
163#define ctxmitl (ctxmith+(1*LPIPTBLSIZE))
164#define ctrecvh (ctxmith+(2*LPIPTBLSIZE))
165#define ctrecvl (ctxmith+(3*LPIPTBLSIZE))
166
167/* Functions for the lp# interface */
168static struct ppb_device	*lpprobe(struct ppb_data *);
169static int			lpattach(struct ppb_device *);
170
171static int lpinittables(void);
172static int lpioctl(struct ifnet *, u_long, caddr_t);
173static int lpoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
174	struct rtentry *);
175static void lpintr(int);
176
177/*
178 * Make ourselves visible as a ppbus driver
179 */
180
181static struct ppb_driver lpdriver = {
182    lpprobe, lpattach, "lp"
183};
184DATA_SET(ppbdriver_set, lpdriver);
185
186
187/*
188 * lpprobe()
189 */
190static struct ppb_device *
191lpprobe(struct ppb_data *ppb)
192{
193	struct lpt_softc *lp;
194
195	/* if we haven't interrupts, the probe fails */
196	if (!ppb->ppb_link->id_irq)
197		return (0);
198
199	lp = (struct lpt_softc *) malloc(sizeof(struct lpt_softc),
200							M_TEMP, M_NOWAIT);
201	if (!lp) {
202		printf("lp: cannot malloc!\n");
203		return (0);
204	}
205	bzero(lp, sizeof(struct lpt_softc));
206
207	lpdata[nlp] = lp;
208
209	/*
210	 * lp dependent initialisation.
211	 */
212	lp->lp_unit = nlp;
213
214	if (bootverbose)
215		printf("plip: irq %d\n", ppb->ppb_link->id_irq);
216
217	/*
218	 * ppbus dependent initialisation.
219	 */
220	lp->lp_dev.id_unit = lp->lp_unit;
221	lp->lp_dev.name = lpdriver.name;
222	lp->lp_dev.ppb = ppb;
223	lp->lp_dev.intr = lpintr;
224
225	/* Ok, go to next device on next probe */
226	nlp ++;
227
228	return (&lp->lp_dev);
229}
230
231static int
232lpattach (struct ppb_device *dev)
233{
234	int unit = dev->id_unit;
235	struct lpt_softc *sc = lpdata[unit];
236	struct ifnet *ifp = &sc->sc_if;
237
238	/*
239	 * Report ourselves
240	 */
241	printf("plip%d: <PLIP network interface> on ppbus %d\n",
242	       dev->id_unit, dev->ppb->ppb_link->adapter_unit);
243
244	ifp->if_softc = sc;
245	ifp->if_name = "lp";
246	ifp->if_unit = unit;
247	ifp->if_mtu = LPMTU;
248	ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST;
249	ifp->if_ioctl = lpioctl;
250	ifp->if_output = lpoutput;
251	ifp->if_type = IFT_PARA;
252	ifp->if_hdrlen = 0;
253	ifp->if_addrlen = 0;
254	ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
255	if_attach(ifp);
256
257#if NBPFILTER > 0
258	bpfattach(ifp, DLT_NULL, LPIPHDRLEN);
259#endif
260
261	return (1);
262}
263/*
264 * Build the translation tables for the LPIP (BSD unix) protocol.
265 * We don't want to calculate these nasties in our tight loop, so we
266 * precalculate them when we initialize.
267 */
268static int
269lpinittables (void)
270{
271    int i;
272
273    if (!txmith)
274	txmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT);
275
276    if (!txmith)
277	return 1;
278
279    if (!ctxmith)
280	ctxmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT);
281
282    if (!ctxmith)
283	return 1;
284
285    for (i=0; i < LPIPTBLSIZE; i++) {
286	ctxmith[i] = (i & 0xF0) >> 4;
287	ctxmitl[i] = 0x10 | (i & 0x0F);
288	ctrecvh[i] = (i & 0x78) << 1;
289	ctrecvl[i] = (i & 0x78) >> 3;
290    }
291
292    for (i=0; i < LPIPTBLSIZE; i++) {
293	txmith[i] = ((i & 0x80) >> 3) | ((i & 0x70) >> 4) | 0x08;
294	txmitl[i] = ((i & 0x08) << 1) | (i & 0x07);
295	trecvh[i] = ((~i) & 0x80) | ((i & 0x38) << 1);
296	trecvl[i] = (((~i) & 0x80) >> 4) | ((i & 0x38) >> 3);
297    }
298
299    return 0;
300}
301
302/*
303 * Process an ioctl request.
304 */
305
306static int
307lpioctl (struct ifnet *ifp, u_long cmd, caddr_t data)
308{
309    struct lpt_softc *sc = lpdata[ifp->if_unit];
310    struct ifaddr *ifa = (struct ifaddr *)data;
311    struct ifreq *ifr = (struct ifreq *)data;
312    u_char *ptr;
313    int error;
314
315    switch (cmd) {
316
317    case SIOCSIFDSTADDR:
318    case SIOCAIFADDR:
319    case SIOCSIFADDR:
320	if (ifa->ifa_addr->sa_family != AF_INET)
321	    return EAFNOSUPPORT;
322
323	ifp->if_flags |= IFF_UP;
324	/* FALLTHROUGH */
325    case SIOCSIFFLAGS:
326	if ((!(ifp->if_flags & IFF_UP)) && (ifp->if_flags & IFF_RUNNING)) {
327
328	    ppb_wctr(&sc->lp_dev, 0x00);
329	    ifp->if_flags &= ~IFF_RUNNING;
330
331	    /* IFF_UP is not set, try to release the bus anyway */
332	    ppb_release_bus(&sc->lp_dev);
333	    break;
334	}
335	if (((ifp->if_flags & IFF_UP)) && (!(ifp->if_flags & IFF_RUNNING))) {
336
337	    /* XXX
338	     * Should the request be interruptible?
339	     */
340	    if ((error = ppb_request_bus(&sc->lp_dev, PPB_WAIT|PPB_INTR)))
341		return (error);
342
343	    /* Now IFF_UP means that we own the bus */
344
345	    ppb_set_mode(&sc->lp_dev, PPB_COMPATIBLE);
346
347	    if (lpinittables()) {
348		ppb_release_bus(&sc->lp_dev);
349		return ENOBUFS;
350	    }
351
352	    sc->sc_ifbuf = malloc(sc->sc_if.if_mtu + MLPIPHDRLEN,
353				  M_DEVBUF, M_WAITOK);
354	    if (!sc->sc_ifbuf) {
355		ppb_release_bus(&sc->lp_dev);
356		return ENOBUFS;
357	    }
358
359	    ppb_wctr(&sc->lp_dev, LPC_ENA);
360	    ifp->if_flags |= IFF_RUNNING;
361	}
362	break;
363
364    case SIOCSIFMTU:
365	ptr = sc->sc_ifbuf;
366	sc->sc_ifbuf = malloc(ifr->ifr_mtu+MLPIPHDRLEN, M_DEVBUF, M_NOWAIT);
367	if (!sc->sc_ifbuf) {
368	    sc->sc_ifbuf = ptr;
369	    return ENOBUFS;
370	}
371	if (ptr)
372	    free(ptr,M_DEVBUF);
373	sc->sc_if.if_mtu = ifr->ifr_mtu;
374	break;
375
376    case SIOCGIFMTU:
377	ifr->ifr_mtu = sc->sc_if.if_mtu;
378	break;
379
380    case SIOCADDMULTI:
381    case SIOCDELMULTI:
382	if (ifr == 0) {
383	    return EAFNOSUPPORT;		/* XXX */
384	}
385	switch (ifr->ifr_addr.sa_family) {
386
387	case AF_INET:
388	    break;
389
390	default:
391	    return EAFNOSUPPORT;
392	}
393	break;
394
395    case SIOCGIFMEDIA:
396	/*
397	 * No ifmedia support at this stage; maybe use it
398	 * in future for eg. protocol selection.
399	 */
400	return EINVAL;
401
402    default:
403	lprintf("LP:ioctl(0x%lx)\n", cmd);
404	return EINVAL;
405    }
406    return 0;
407}
408
409static __inline int
410clpoutbyte (u_char byte, int spin, struct ppb_device *dev)
411{
412	ppb_wdtr(dev, ctxmitl[byte]);
413	while (ppb_rstr(dev) & CLPIP_SHAKE)
414		if (--spin == 0) {
415			return 1;
416		}
417	ppb_wdtr(dev, ctxmith[byte]);
418	while (!(ppb_rstr(dev) & CLPIP_SHAKE))
419		if (--spin == 0) {
420			return 1;
421		}
422	return 0;
423}
424
425static __inline int
426clpinbyte (int spin, struct ppb_device *dev)
427{
428	u_char c, cl;
429
430	while((ppb_rstr(dev) & CLPIP_SHAKE))
431	    if(!--spin) {
432		return -1;
433	    }
434	cl = ppb_rstr(dev);
435	ppb_wdtr(dev, 0x10);
436
437	while(!(ppb_rstr(dev) & CLPIP_SHAKE))
438	    if(!--spin) {
439		return -1;
440	    }
441	c = ppb_rstr(dev);
442	ppb_wdtr(dev, 0x00);
443
444	return (ctrecvl[cl] | ctrecvh[c]);
445}
446
447static void
448lpintr (int unit)
449{
450	struct   lpt_softc *sc = lpdata[unit];
451	int len, s, j;
452	u_char *bp;
453	u_char c, cl;
454	struct mbuf *top;
455
456	s = splhigh();
457
458	if (sc->sc_if.if_flags & IFF_LINK0) {
459
460	    /* Ack. the request */
461	    ppb_wdtr(&sc->lp_dev, 0x01);
462
463	    /* Get the packet length */
464	    j = clpinbyte(LPMAXSPIN2, &sc->lp_dev);
465	    if (j == -1)
466		goto err;
467	    len = j;
468	    j = clpinbyte(LPMAXSPIN2, &sc->lp_dev);
469	    if (j == -1)
470		goto err;
471	    len = len + (j << 8);
472	    if (len > sc->sc_if.if_mtu + MLPIPHDRLEN)
473		goto err;
474
475	    bp  = sc->sc_ifbuf;
476
477	    while (len--) {
478	        j = clpinbyte(LPMAXSPIN2, &sc->lp_dev);
479	        if (j == -1) {
480		    goto err;
481	        }
482	        *bp++ = j;
483	    }
484	    /* Get and ignore checksum */
485	    j = clpinbyte(LPMAXSPIN2, &sc->lp_dev);
486	    if (j == -1) {
487	        goto err;
488	    }
489
490	    len = bp - sc->sc_ifbuf;
491	    if (len <= CLPIPHDRLEN)
492	        goto err;
493
494	    sc->sc_iferrs = 0;
495
496	    if (IF_QFULL(&ipintrq)) {
497	        lprintf("DROP");
498	        IF_DROP(&ipintrq);
499		goto done;
500	    }
501	    len -= CLPIPHDRLEN;
502	    sc->sc_if.if_ipackets++;
503	    sc->sc_if.if_ibytes += len;
504	    top = m_devget(sc->sc_ifbuf + CLPIPHDRLEN, len, 0, &sc->sc_if, 0);
505	    if (top) {
506	        IF_ENQUEUE(&ipintrq, top);
507	        schednetisr(NETISR_IP);
508	    }
509	    goto done;
510	}
511	while ((ppb_rstr(&sc->lp_dev) & LPIP_SHAKE)) {
512	    len = sc->sc_if.if_mtu + LPIPHDRLEN;
513	    bp  = sc->sc_ifbuf;
514	    while (len--) {
515
516		cl = ppb_rstr(&sc->lp_dev);
517		ppb_wdtr(&sc->lp_dev, 8);
518
519		j = LPMAXSPIN2;
520		while((ppb_rstr(&sc->lp_dev) & LPIP_SHAKE))
521		    if(!--j) goto err;
522
523		c = ppb_rstr(&sc->lp_dev);
524		ppb_wdtr(&sc->lp_dev, 0);
525
526		*bp++= trecvh[cl] | trecvl[c];
527
528		j = LPMAXSPIN2;
529		while (!((cl=ppb_rstr(&sc->lp_dev)) & LPIP_SHAKE)) {
530		    if (cl != c &&
531			(((cl = ppb_rstr(&sc->lp_dev)) ^ 0xb8) & 0xf8) ==
532			  (c & 0xf8))
533			goto end;
534		    if (!--j) goto err;
535		}
536	    }
537
538	end:
539	    len = bp - sc->sc_ifbuf;
540	    if (len <= LPIPHDRLEN)
541		goto err;
542
543	    sc->sc_iferrs = 0;
544
545	    if (IF_QFULL(&ipintrq)) {
546		lprintf("DROP");
547		IF_DROP(&ipintrq);
548		goto done;
549	    }
550#if NBPFILTER > 0
551	    if (sc->sc_if.if_bpf) {
552		bpf_tap(&sc->sc_if, sc->sc_ifbuf, len);
553	    }
554#endif
555	    len -= LPIPHDRLEN;
556	    sc->sc_if.if_ipackets++;
557	    sc->sc_if.if_ibytes += len;
558	    top = m_devget(sc->sc_ifbuf + LPIPHDRLEN, len, 0, &sc->sc_if, 0);
559	    if (top) {
560		    IF_ENQUEUE(&ipintrq, top);
561		    schednetisr(NETISR_IP);
562	    }
563	}
564	goto done;
565
566    err:
567	ppb_wdtr(&sc->lp_dev, 0);
568	lprintf("R");
569	sc->sc_if.if_ierrors++;
570	sc->sc_iferrs++;
571
572	/*
573	 * We are not able to send receive anything for now,
574	 * so stop wasting our time
575	 */
576	if (sc->sc_iferrs > LPMAXERRS) {
577	    printf("lp%d: Too many errors, Going off-line.\n", unit);
578	    ppb_wctr(&sc->lp_dev, 0x00);
579	    sc->sc_if.if_flags &= ~IFF_RUNNING;
580	    sc->sc_iferrs=0;
581	}
582
583    done:
584	splx(s);
585	return;
586}
587
588static __inline int
589lpoutbyte (u_char byte, int spin, struct ppb_device *dev)
590{
591    ppb_wdtr(dev, txmith[byte]);
592    while (!(ppb_rstr(dev) & LPIP_SHAKE))
593	if (--spin == 0)
594		return 1;
595    ppb_wdtr(dev, txmitl[byte]);
596    while (ppb_rstr(dev) & LPIP_SHAKE)
597	if (--spin == 0)
598		return 1;
599    return 0;
600}
601
602static int
603lpoutput (struct ifnet *ifp, struct mbuf *m,
604	  struct sockaddr *dst, struct rtentry *rt)
605{
606    struct lpt_softc *sc = lpdata[ifp->if_unit];
607    int s, err;
608    struct mbuf *mm;
609    u_char *cp = "\0\0";
610    u_char chksum = 0;
611    int count = 0;
612    int i;
613    int spin;
614
615    /* We need a sensible value if we abort */
616    cp++;
617    ifp->if_flags |= IFF_RUNNING;
618
619    err = 1;			/* assume we're aborting because of an error */
620
621    s = splhigh();
622
623    /* Suspend (on laptops) or receive-errors might have taken us offline */
624    ppb_wctr(&sc->lp_dev, LPC_ENA);
625
626    if (ifp->if_flags & IFF_LINK0) {
627
628	if (!(ppb_rstr(&sc->lp_dev) & CLPIP_SHAKE)) {
629	    lprintf("&");
630	    lpintr(ifp->if_unit);
631	}
632
633	/* Alert other end to pending packet */
634	spin = LPMAXSPIN1;
635	ppb_wdtr(&sc->lp_dev, 0x08);
636	while ((ppb_rstr(&sc->lp_dev) & 0x08) == 0)
637		if (--spin == 0) {
638			goto nend;
639		}
640
641	/* Calculate length of packet, then send that */
642
643	count += 14;		/* Ethernet header len */
644
645	mm = m;
646	for (mm = m; mm; mm = mm->m_next) {
647		count += mm->m_len;
648	}
649	if (clpoutbyte(count & 0xFF, LPMAXSPIN1, &sc->lp_dev))
650		goto nend;
651	if (clpoutbyte((count >> 8) & 0xFF, LPMAXSPIN1, &sc->lp_dev))
652		goto nend;
653
654	/* Send dummy ethernet header */
655	for (i = 0; i < 12; i++) {
656		if (clpoutbyte(i, LPMAXSPIN1, &sc->lp_dev))
657			goto nend;
658		chksum += i;
659	}
660
661	if (clpoutbyte(0x08, LPMAXSPIN1, &sc->lp_dev))
662		goto nend;
663	if (clpoutbyte(0x00, LPMAXSPIN1, &sc->lp_dev))
664		goto nend;
665	chksum += 0x08 + 0x00;		/* Add into checksum */
666
667	mm = m;
668	do {
669		cp = mtod(mm, u_char *);
670		while (mm->m_len--) {
671			chksum += *cp;
672			if (clpoutbyte(*cp++, LPMAXSPIN2, &sc->lp_dev))
673				goto nend;
674		}
675	} while ((mm = mm->m_next));
676
677	/* Send checksum */
678	if (clpoutbyte(chksum, LPMAXSPIN2, &sc->lp_dev))
679		goto nend;
680
681	/* Go quiescent */
682	ppb_wdtr(&sc->lp_dev, 0);
683
684	err = 0;			/* No errors */
685
686	nend:
687	if (err)  {				/* if we didn't timeout... */
688		ifp->if_oerrors++;
689		lprintf("X");
690	} else {
691		ifp->if_opackets++;
692		ifp->if_obytes += m->m_pkthdr.len;
693	}
694
695	m_freem(m);
696
697	if (!(ppb_rstr(&sc->lp_dev) & CLPIP_SHAKE)) {
698		lprintf("^");
699		lpintr(ifp->if_unit);
700	}
701	(void) splx(s);
702	return 0;
703    }
704
705    if (ppb_rstr(&sc->lp_dev) & LPIP_SHAKE) {
706        lprintf("&");
707        lpintr(ifp->if_unit);
708    }
709
710    if (lpoutbyte(0x08, LPMAXSPIN1, &sc->lp_dev))
711        goto end;
712    if (lpoutbyte(0x00, LPMAXSPIN2, &sc->lp_dev))
713        goto end;
714
715    mm = m;
716    do {
717        cp = mtod(mm,u_char *);
718        while (mm->m_len--)
719	    if (lpoutbyte(*cp++, LPMAXSPIN2, &sc->lp_dev))
720	        goto end;
721    } while ((mm = mm->m_next));
722
723    err = 0;				/* no errors were encountered */
724
725    end:
726    --cp;
727    ppb_wdtr(&sc->lp_dev, txmitl[*cp] ^ 0x17);
728
729    if (err)  {				/* if we didn't timeout... */
730	ifp->if_oerrors++;
731        lprintf("X");
732    } else {
733	ifp->if_opackets++;
734	ifp->if_obytes += m->m_pkthdr.len;
735#if NBPFILTER > 0
736	if (ifp->if_bpf) {
737	    /*
738	     * We need to prepend the packet type as
739	     * a two byte field.  Cons up a dummy header
740	     * to pacify bpf.  This is safe because bpf
741	     * will only read from the mbuf (i.e., it won't
742	     * try to free it or keep a pointer to it).
743	     */
744	    struct mbuf m0;
745	    u_short hdr = 0x800;
746
747	    m0.m_next = m;
748	    m0.m_len = 2;
749	    m0.m_data = (char *)&hdr;
750
751	    bpf_mtap(ifp, &m0);
752	}
753#endif
754    }
755
756    m_freem(m);
757
758    if (ppb_rstr(&sc->lp_dev) & LPIP_SHAKE) {
759	lprintf("^");
760	lpintr(ifp->if_unit);
761    }
762
763    (void) splx(s);
764    return 0;
765}
766