Index: head/sys/dev/ppbus/if_plip.c =================================================================== --- head/sys/dev/ppbus/if_plip.c (revision 43998) +++ head/sys/dev/ppbus/if_plip.c (revision 43999) @@ -1,781 +1,780 @@ /*- * Copyright (c) 1997 Poul-Henning Kamp * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp - * $Id: if_plip.c,v 1.10 1999/02/08 14:12:38 des Exp $ + * $Id: if_plip.c,v 1.11 1999/02/14 11:59:59 nsouch Exp $ */ /* * Parallel port TCP/IP interfaces added. I looked at the driver from * MACH but this is a complete rewrite, and btw. incompatible, and it * should perform better too. I have never run the MACH driver though. * * This driver sends two bytes (0x08, 0x00) in front of each packet, * to allow us to distinguish another format later. * * Now added an Linux/Crynwr compatibility mode which is enabled using * IF_LINK0 - Tim Wilkinson. * * TODO: * Make HDLC/PPP mode, use IF_LLC1 to enable. * * Connect the two computers using a Laplink parallel cable to use this * feature: * * +----------------------------------------+ * |A-name A-End B-End Descr. Port/Bit | * +----------------------------------------+ * |DATA0 2 15 Data 0/0x01 | * |-ERROR 15 2 1/0x08 | * +----------------------------------------+ * |DATA1 3 13 Data 0/0x02 | * |+SLCT 13 3 1/0x10 | * +----------------------------------------+ * |DATA2 4 12 Data 0/0x04 | * |+PE 12 4 1/0x20 | * +----------------------------------------+ * |DATA3 5 10 Strobe 0/0x08 | * |-ACK 10 5 1/0x40 | * +----------------------------------------+ * |DATA4 6 11 Data 0/0x10 | * |BUSY 11 6 1/~0x80 | * +----------------------------------------+ * |GND 18-25 18-25 GND - | * +----------------------------------------+ * * Expect transfer-rates up to 75 kbyte/sec. * * If GCC could correctly grok * register int port asm("edx") * the code would be cleaner * * Poul-Henning Kamp */ /* * Update for ppbus, PLIP support only - Nicolas Souchu */ #include #include #include #include #include #include #include #include #include #include #include #include #include "bpfilter.h" #if NBPFILTER > 0 #include #endif #include -#include #include "opt_plip.h" #ifndef LPMTU /* MTU for the lp# interfaces */ #define LPMTU 1500 #endif #ifndef LPMAXSPIN1 /* DELAY factor for the lp# interfaces */ #define LPMAXSPIN1 8000 /* Spinning for remote intr to happen */ #endif #ifndef LPMAXSPIN2 /* DELAY factor for the lp# interfaces */ #define LPMAXSPIN2 500 /* Spinning for remote handshake to happen */ #endif #ifndef LPMAXERRS /* Max errors before !RUNNING */ #define LPMAXERRS 100 #endif #define CLPIPHDRLEN 14 /* We send dummy ethernet addresses (two) + packet type in front of packet */ #define CLPIP_SHAKE 0x80 /* This bit toggles between nibble reception */ #define MLPIPHDRLEN CLPIPHDRLEN #define LPIPHDRLEN 2 /* We send 0x08, 0x00 in front of packet */ #define LPIP_SHAKE 0x40 /* This bit toggles between nibble reception */ #if !defined(MLPIPHDRLEN) || LPIPHDRLEN > MLPIPHDRLEN #define MLPIPHDRLEN LPIPHDRLEN #endif #define LPIPTBLSIZE 256 /* Size of octet translation table */ #define lprintf if (lptflag) printf #ifdef PLIP_DEBUG static int volatile lptflag = 1; #else static int volatile lptflag = 0; #endif struct lpt_softc { unsigned short lp_unit; struct ppb_device lp_dev; struct ifnet sc_if; u_char *sc_ifbuf; int sc_iferrs; }; static int nlp = 0; #define MAXPLIP 8 /* XXX not much better! */ static struct lpt_softc *lpdata[MAXPLIP]; /* Tables for the lp# interface */ static u_char *txmith; #define txmitl (txmith+(1*LPIPTBLSIZE)) #define trecvh (txmith+(2*LPIPTBLSIZE)) #define trecvl (txmith+(3*LPIPTBLSIZE)) static u_char *ctxmith; #define ctxmitl (ctxmith+(1*LPIPTBLSIZE)) #define ctrecvh (ctxmith+(2*LPIPTBLSIZE)) #define ctrecvl (ctxmith+(3*LPIPTBLSIZE)) /* Functions for the lp# interface */ static struct ppb_device *lpprobe(struct ppb_data *); static int lpattach(struct ppb_device *); static int lpinittables(void); static int lpioctl(struct ifnet *, u_long, caddr_t); static int lpoutput(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *); static void lpintr(int); /* * Make ourselves visible as a ppbus driver */ static struct ppb_driver lpdriver = { lpprobe, lpattach, "lp" }; DATA_SET(ppbdriver_set, lpdriver); /* * lpprobe() */ static struct ppb_device * lpprobe(struct ppb_data *ppb) { struct lpt_softc *lp; /* if we haven't interrupts, the probe fails */ if (!ppb->ppb_link->id_irq) { printf("plip: not an interrupt driven port, failed.\n"); return (0); } lp = (struct lpt_softc *) malloc(sizeof(struct lpt_softc), M_TEMP, M_NOWAIT); if (!lp) { printf("lp: cannot malloc!\n"); return (0); } bzero(lp, sizeof(struct lpt_softc)); lpdata[nlp] = lp; /* * lp dependent initialisation. */ lp->lp_unit = nlp; if (bootverbose) printf("plip: irq %d\n", ppb->ppb_link->id_irq); /* * ppbus dependent initialisation. */ lp->lp_dev.id_unit = lp->lp_unit; lp->lp_dev.name = lpdriver.name; lp->lp_dev.ppb = ppb; lp->lp_dev.intr = lpintr; /* Ok, go to next device on next probe */ nlp ++; return (&lp->lp_dev); } static int lpattach (struct ppb_device *dev) { int unit = dev->id_unit; struct lpt_softc *sc = lpdata[unit]; struct ifnet *ifp = &sc->sc_if; /* * Report ourselves */ printf("plip%d: on ppbus %d\n", dev->id_unit, dev->ppb->ppb_link->adapter_unit); ifp->if_softc = sc; ifp->if_name = "lp"; ifp->if_unit = unit; ifp->if_mtu = LPMTU; ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST; ifp->if_ioctl = lpioctl; ifp->if_output = lpoutput; ifp->if_type = IFT_PARA; ifp->if_hdrlen = 0; ifp->if_addrlen = 0; ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; if_attach(ifp); #if NBPFILTER > 0 bpfattach(ifp, DLT_NULL, sizeof(u_int32_t)); #endif return (1); } /* * Build the translation tables for the LPIP (BSD unix) protocol. * We don't want to calculate these nasties in our tight loop, so we * precalculate them when we initialize. */ static int lpinittables (void) { int i; if (!txmith) txmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT); if (!txmith) return 1; if (!ctxmith) ctxmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT); if (!ctxmith) return 1; for (i=0; i < LPIPTBLSIZE; i++) { ctxmith[i] = (i & 0xF0) >> 4; ctxmitl[i] = 0x10 | (i & 0x0F); ctrecvh[i] = (i & 0x78) << 1; ctrecvl[i] = (i & 0x78) >> 3; } for (i=0; i < LPIPTBLSIZE; i++) { txmith[i] = ((i & 0x80) >> 3) | ((i & 0x70) >> 4) | 0x08; txmitl[i] = ((i & 0x08) << 1) | (i & 0x07); trecvh[i] = ((~i) & 0x80) | ((i & 0x38) << 1); trecvl[i] = (((~i) & 0x80) >> 4) | ((i & 0x38) >> 3); } return 0; } /* * Process an ioctl request. */ static int lpioctl (struct ifnet *ifp, u_long cmd, caddr_t data) { struct lpt_softc *sc = lpdata[ifp->if_unit]; struct ifaddr *ifa = (struct ifaddr *)data; struct ifreq *ifr = (struct ifreq *)data; u_char *ptr; int error; switch (cmd) { case SIOCSIFDSTADDR: case SIOCAIFADDR: case SIOCSIFADDR: if (ifa->ifa_addr->sa_family != AF_INET) return EAFNOSUPPORT; ifp->if_flags |= IFF_UP; /* FALLTHROUGH */ case SIOCSIFFLAGS: if ((!(ifp->if_flags & IFF_UP)) && (ifp->if_flags & IFF_RUNNING)) { ppb_wctr(&sc->lp_dev, 0x00); ifp->if_flags &= ~IFF_RUNNING; /* IFF_UP is not set, try to release the bus anyway */ ppb_release_bus(&sc->lp_dev); break; } if (((ifp->if_flags & IFF_UP)) && (!(ifp->if_flags & IFF_RUNNING))) { /* XXX * Should the request be interruptible? */ if ((error = ppb_request_bus(&sc->lp_dev, PPB_WAIT|PPB_INTR))) return (error); /* Now IFF_UP means that we own the bus */ ppb_set_mode(&sc->lp_dev, PPB_COMPATIBLE); if (lpinittables()) { ppb_release_bus(&sc->lp_dev); return ENOBUFS; } sc->sc_ifbuf = malloc(sc->sc_if.if_mtu + MLPIPHDRLEN, M_DEVBUF, M_WAITOK); if (!sc->sc_ifbuf) { ppb_release_bus(&sc->lp_dev); return ENOBUFS; } - ppb_wctr(&sc->lp_dev, LPC_ENA); + ppb_wctr(&sc->lp_dev, IRQENABLE); ifp->if_flags |= IFF_RUNNING; } break; case SIOCSIFMTU: ptr = sc->sc_ifbuf; sc->sc_ifbuf = malloc(ifr->ifr_mtu+MLPIPHDRLEN, M_DEVBUF, M_NOWAIT); if (!sc->sc_ifbuf) { sc->sc_ifbuf = ptr; return ENOBUFS; } if (ptr) free(ptr,M_DEVBUF); sc->sc_if.if_mtu = ifr->ifr_mtu; break; case SIOCGIFMTU: ifr->ifr_mtu = sc->sc_if.if_mtu; break; case SIOCADDMULTI: case SIOCDELMULTI: if (ifr == 0) { return EAFNOSUPPORT; /* XXX */ } switch (ifr->ifr_addr.sa_family) { case AF_INET: break; default: return EAFNOSUPPORT; } break; case SIOCGIFMEDIA: /* * No ifmedia support at this stage; maybe use it * in future for eg. protocol selection. */ return EINVAL; default: lprintf("LP:ioctl(0x%lx)\n", cmd); return EINVAL; } return 0; } static __inline int clpoutbyte (u_char byte, int spin, struct ppb_device *dev) { ppb_wdtr(dev, ctxmitl[byte]); while (ppb_rstr(dev) & CLPIP_SHAKE) if (--spin == 0) { return 1; } ppb_wdtr(dev, ctxmith[byte]); while (!(ppb_rstr(dev) & CLPIP_SHAKE)) if (--spin == 0) { return 1; } return 0; } static __inline int clpinbyte (int spin, struct ppb_device *dev) { u_char c, cl; while((ppb_rstr(dev) & CLPIP_SHAKE)) if(!--spin) { return -1; } cl = ppb_rstr(dev); ppb_wdtr(dev, 0x10); while(!(ppb_rstr(dev) & CLPIP_SHAKE)) if(!--spin) { return -1; } c = ppb_rstr(dev); ppb_wdtr(dev, 0x00); return (ctrecvl[cl] | ctrecvh[c]); } #if NBPFILTER > 0 static void lptap(struct ifnet *ifp, struct mbuf *m) { /* * Send a packet through bpf. We need to prepend the address family * as a four byte field. Cons up a dummy header to pacify bpf. This * is safe because bpf will only read from the mbuf (i.e., it won't * try to free it or keep a pointer to it). */ u_int32_t af = AF_INET; struct mbuf m0; m0.m_next = m; m0.m_len = sizeof(u_int32_t); m0.m_data = (char *)⁡ bpf_mtap(ifp, &m0); } #endif static void lpintr (int unit) { struct lpt_softc *sc = lpdata[unit]; int len, s, j; u_char *bp; u_char c, cl; struct mbuf *top; s = splhigh(); if (sc->sc_if.if_flags & IFF_LINK0) { /* Ack. the request */ ppb_wdtr(&sc->lp_dev, 0x01); /* Get the packet length */ j = clpinbyte(LPMAXSPIN2, &sc->lp_dev); if (j == -1) goto err; len = j; j = clpinbyte(LPMAXSPIN2, &sc->lp_dev); if (j == -1) goto err; len = len + (j << 8); if (len > sc->sc_if.if_mtu + MLPIPHDRLEN) goto err; bp = sc->sc_ifbuf; while (len--) { j = clpinbyte(LPMAXSPIN2, &sc->lp_dev); if (j == -1) { goto err; } *bp++ = j; } /* Get and ignore checksum */ j = clpinbyte(LPMAXSPIN2, &sc->lp_dev); if (j == -1) { goto err; } len = bp - sc->sc_ifbuf; if (len <= CLPIPHDRLEN) goto err; sc->sc_iferrs = 0; if (IF_QFULL(&ipintrq)) { lprintf("DROP"); IF_DROP(&ipintrq); goto done; } len -= CLPIPHDRLEN; sc->sc_if.if_ipackets++; sc->sc_if.if_ibytes += len; top = m_devget(sc->sc_ifbuf + CLPIPHDRLEN, len, 0, &sc->sc_if, 0); if (top) { #if NBPFILTER > 0 if (sc->sc_if.if_bpf) lptap(&sc->sc_if, top); #endif IF_ENQUEUE(&ipintrq, top); schednetisr(NETISR_IP); } goto done; } while ((ppb_rstr(&sc->lp_dev) & LPIP_SHAKE)) { len = sc->sc_if.if_mtu + LPIPHDRLEN; bp = sc->sc_ifbuf; while (len--) { cl = ppb_rstr(&sc->lp_dev); ppb_wdtr(&sc->lp_dev, 8); j = LPMAXSPIN2; while((ppb_rstr(&sc->lp_dev) & LPIP_SHAKE)) if(!--j) goto err; c = ppb_rstr(&sc->lp_dev); ppb_wdtr(&sc->lp_dev, 0); *bp++= trecvh[cl] | trecvl[c]; j = LPMAXSPIN2; while (!((cl=ppb_rstr(&sc->lp_dev)) & LPIP_SHAKE)) { if (cl != c && (((cl = ppb_rstr(&sc->lp_dev)) ^ 0xb8) & 0xf8) == (c & 0xf8)) goto end; if (!--j) goto err; } } end: len = bp - sc->sc_ifbuf; if (len <= LPIPHDRLEN) goto err; sc->sc_iferrs = 0; if (IF_QFULL(&ipintrq)) { lprintf("DROP"); IF_DROP(&ipintrq); goto done; } len -= LPIPHDRLEN; sc->sc_if.if_ipackets++; sc->sc_if.if_ibytes += len; top = m_devget(sc->sc_ifbuf + LPIPHDRLEN, len, 0, &sc->sc_if, 0); if (top) { #if NBPFILTER > 0 if (sc->sc_if.if_bpf) lptap(&sc->sc_if, top); #endif IF_ENQUEUE(&ipintrq, top); schednetisr(NETISR_IP); } } goto done; err: ppb_wdtr(&sc->lp_dev, 0); lprintf("R"); sc->sc_if.if_ierrors++; sc->sc_iferrs++; /* * We are not able to send receive anything for now, * so stop wasting our time */ if (sc->sc_iferrs > LPMAXERRS) { printf("lp%d: Too many errors, Going off-line.\n", unit); ppb_wctr(&sc->lp_dev, 0x00); sc->sc_if.if_flags &= ~IFF_RUNNING; sc->sc_iferrs=0; } done: splx(s); return; } static __inline int lpoutbyte (u_char byte, int spin, struct ppb_device *dev) { ppb_wdtr(dev, txmith[byte]); while (!(ppb_rstr(dev) & LPIP_SHAKE)) if (--spin == 0) return 1; ppb_wdtr(dev, txmitl[byte]); while (ppb_rstr(dev) & LPIP_SHAKE) if (--spin == 0) return 1; return 0; } static int lpoutput (struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt) { struct lpt_softc *sc = lpdata[ifp->if_unit]; int s, err; struct mbuf *mm; u_char *cp = "\0\0"; u_char chksum = 0; int count = 0; int i, len, spin; /* We need a sensible value if we abort */ cp++; ifp->if_flags |= IFF_RUNNING; err = 1; /* assume we're aborting because of an error */ s = splhigh(); /* Suspend (on laptops) or receive-errors might have taken us offline */ - ppb_wctr(&sc->lp_dev, LPC_ENA); + ppb_wctr(&sc->lp_dev, IRQENABLE); if (ifp->if_flags & IFF_LINK0) { if (!(ppb_rstr(&sc->lp_dev) & CLPIP_SHAKE)) { lprintf("&"); lpintr(ifp->if_unit); } /* Alert other end to pending packet */ spin = LPMAXSPIN1; ppb_wdtr(&sc->lp_dev, 0x08); while ((ppb_rstr(&sc->lp_dev) & 0x08) == 0) if (--spin == 0) { goto nend; } /* Calculate length of packet, then send that */ count += 14; /* Ethernet header len */ mm = m; for (mm = m; mm; mm = mm->m_next) { count += mm->m_len; } if (clpoutbyte(count & 0xFF, LPMAXSPIN1, &sc->lp_dev)) goto nend; if (clpoutbyte((count >> 8) & 0xFF, LPMAXSPIN1, &sc->lp_dev)) goto nend; /* Send dummy ethernet header */ for (i = 0; i < 12; i++) { if (clpoutbyte(i, LPMAXSPIN1, &sc->lp_dev)) goto nend; chksum += i; } if (clpoutbyte(0x08, LPMAXSPIN1, &sc->lp_dev)) goto nend; if (clpoutbyte(0x00, LPMAXSPIN1, &sc->lp_dev)) goto nend; chksum += 0x08 + 0x00; /* Add into checksum */ mm = m; do { cp = mtod(mm, u_char *); len = mm->m_len; while (len--) { chksum += *cp; if (clpoutbyte(*cp++, LPMAXSPIN2, &sc->lp_dev)) goto nend; } } while ((mm = mm->m_next)); /* Send checksum */ if (clpoutbyte(chksum, LPMAXSPIN2, &sc->lp_dev)) goto nend; /* Go quiescent */ ppb_wdtr(&sc->lp_dev, 0); err = 0; /* No errors */ nend: if (err) { /* if we didn't timeout... */ ifp->if_oerrors++; lprintf("X"); } else { ifp->if_opackets++; ifp->if_obytes += m->m_pkthdr.len; #if NBPFILTER > 0 if (ifp->if_bpf) lptap(ifp, m); #endif } m_freem(m); if (!(ppb_rstr(&sc->lp_dev) & CLPIP_SHAKE)) { lprintf("^"); lpintr(ifp->if_unit); } (void) splx(s); return 0; } if (ppb_rstr(&sc->lp_dev) & LPIP_SHAKE) { lprintf("&"); lpintr(ifp->if_unit); } if (lpoutbyte(0x08, LPMAXSPIN1, &sc->lp_dev)) goto end; if (lpoutbyte(0x00, LPMAXSPIN2, &sc->lp_dev)) goto end; mm = m; do { cp = mtod(mm,u_char *); len = mm->m_len; while (len--) if (lpoutbyte(*cp++, LPMAXSPIN2, &sc->lp_dev)) goto end; } while ((mm = mm->m_next)); err = 0; /* no errors were encountered */ end: --cp; ppb_wdtr(&sc->lp_dev, txmitl[*cp] ^ 0x17); if (err) { /* if we didn't timeout... */ ifp->if_oerrors++; lprintf("X"); } else { ifp->if_opackets++; ifp->if_obytes += m->m_pkthdr.len; #if NBPFILTER > 0 if (ifp->if_bpf) lptap(ifp, m); #endif } m_freem(m); if (ppb_rstr(&sc->lp_dev) & LPIP_SHAKE) { lprintf("^"); lpintr(ifp->if_unit); } (void) splx(s); return 0; } Index: head/sys/dev/ppbus/lpt.c =================================================================== --- head/sys/dev/ppbus/lpt.c (revision 43998) +++ head/sys/dev/ppbus/lpt.c (revision 43999) @@ -1,921 +1,955 @@ /* * Copyright (c) 1990 William F. Jolitz, TeleMuse * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This software is a component of "386BSD" developed by * William F. Jolitz, TeleMuse. * 4. Neither the name of the developer nor the name "386BSD" * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT. * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT * NOT MAKE USE OF THIS WORK. * * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN * REFERENCES SUCH AS THE "PORTING UNIX TO THE 386" SERIES * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992. * * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * from: unknown origin, 386BSD 0.1 * From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp * From Id: nlpt.c,v 1.14 1999/02/08 13:55:43 des Exp - * $Id$ + * $Id: lpt.c,v 1.1 1999/02/14 11:59:59 nsouch Exp $ */ /* * Device Driver for AT parallel printer port * Written by William Jolitz 12/18/90 */ /* * Updated for ppbus by Nicolas Souchu * [Mon Jul 28 1997] */ #ifdef KERNEL #include "opt_devfs.h" #include #include #include #include #include #include #include #ifdef DEVFS #include #endif /*DEVFS*/ #include #include #include #endif /*KERNEL*/ #include #include #include #include "opt_lpt.h" #ifndef LPT_DEBUG #define lprintf(args) #else #define lprintf(args) \ do { \ if (lptflag) \ printf args; \ } while (0) static int volatile lptflag = 1; #endif #define LPINITRDY 4 /* wait up to 4 seconds for a ready */ #define LPTOUTINITIAL 10 /* initial timeout to wait for ready 1/10 s */ #define LPTOUTMAX 1 /* maximal timeout 1 s */ #define LPPRI (PZERO+8) #define BUFSIZE 1024 #define BUFSTATSIZE 32 #define LPTUNIT(s) ((s)&0x03) #define LPTFLAGS(s) ((s)&0xfc) + +struct lpt_data { + unsigned short lpt_unit; + + struct ppb_device lpt_dev; + + short sc_state; + /* default case: negative prime, negative ack, handshake strobe, + prime once */ + u_char sc_control; + char sc_flags; +#define LP_POS_INIT 0x04 /* if we are a postive init signal */ +#define LP_POS_ACK 0x08 /* if we are a positive going ack */ +#define LP_NO_PRIME 0x10 /* don't prime the printer at all */ +#define LP_PRIMEOPEN 0x20 /* prime on every open */ +#define LP_AUTOLF 0x40 /* tell printer to do an automatic lf */ +#define LP_BYPASS 0x80 /* bypass printer ready checks */ + struct buf *sc_inbuf; + struct buf *sc_statbuf; + short sc_xfercnt ; + char sc_primed; + char *sc_cp ; + u_short sc_irq ; /* IRQ status of port */ +#define LP_HAS_IRQ 0x01 /* we have an irq available */ +#define LP_USE_IRQ 0x02 /* we are using our irq */ +#define LP_ENABLE_IRQ 0x04 /* enable IRQ on open */ +#define LP_ENABLE_EXT 0x10 /* we shall use advanced mode when possible */ + u_char sc_backoff ; /* time to call lptout() again */ + +#ifdef DEVFS + void *devfs_token; + void *devfs_token_ctl; +#endif +}; static int nlpt = 0; #define MAXLPT 8 /* XXX not much better! */ static struct lpt_data *lptdata[MAXLPT]; #define LPT_NAME "lpt" /* our official name */ static timeout_t lptout; static int lpt_port_test(struct lpt_data *sc, u_char data, u_char mask); static int lpt_detect(struct lpt_data *sc); /* * Make ourselves visible as a ppbus driver */ static struct ppb_device *lptprobe(struct ppb_data *ppb); static int lptattach(struct ppb_device *dev); static void lptintr(int unit); static void lpt_drvinit(void *unused); static void lpt_intr(int unit); /* without spls */ #ifdef KERNEL static struct ppb_driver lptdriver = { lptprobe, lptattach, LPT_NAME }; DATA_SET(ppbdriver_set, lptdriver); #endif /* KERNEL */ /* bits for state */ #define OPEN (1<<0) /* device is open */ #define ASLP (1<<1) /* awaiting draining of printer */ #define EERROR (1<<2) /* error was received from printer */ #define OBUSY (1<<3) /* printer is busy doing output */ #define LPTOUT (1<<4) /* timeout while not selected */ #define TOUT (1<<5) /* timeout while not selected */ #define LPTINIT (1<<6) /* waiting to initialize for open */ #define INTERRUPTED (1<<7) /* write call was interrupted */ #define HAVEBUS (1<<8) /* the driver owns the bus */ /* status masks to interrogate printer status */ #define RDY_MASK (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR) /* ready ? */ #define LP_READY (LPS_SEL|LPS_NBSY|LPS_NERR) /* Printer Ready condition - from lpa.c */ /* Only used in polling code */ #define LPS_INVERT (LPS_NBSY | LPS_NACK | LPS_SEL | LPS_NERR) #define LPS_MASK (LPS_NBSY | LPS_NACK | LPS_OUT | LPS_SEL | LPS_NERR) #define NOT_READY(lpt) ((ppb_rstr(&(lpt)->lpt_dev)^LPS_INVERT)&LPS_MASK) #define MAX_SLEEP (hz*5) /* Timeout while waiting for device ready */ #define MAX_SPIN 20 /* Max delay for device ready in usecs */ static d_open_t lptopen; static d_close_t lptclose; static d_write_t lptwrite; static d_read_t lptread; static d_ioctl_t lptioctl; #define CDEV_MAJOR 16 static struct cdevsw lpt_cdevsw = { lptopen, lptclose, lptread, lptwrite, /*16*/ lptioctl, nullstop, nullreset, nodevtotty, /* lpt */ seltrue, nommap, nostrat, LPT_NAME, NULL, -1 }; static int lpt_request_ppbus(struct lpt_data *sc, int how) { int error; if (sc->sc_state & HAVEBUS) return (0); /* we have the bus only if the request succeded */ if ((error = ppb_request_bus(&sc->lpt_dev, how)) == 0) sc->sc_state |= HAVEBUS; return (error); } static int lpt_release_ppbus(struct lpt_data *sc) { ppb_release_bus(&sc->lpt_dev); sc->sc_state &= ~HAVEBUS; return (0); } /* * Internal routine to lptprobe to do port tests of one byte value */ static int lpt_port_test(struct lpt_data *sc, u_char data, u_char mask) { int temp, timeout; data = data & mask; ppb_wdtr(&sc->lpt_dev, data); timeout = 10000; do { DELAY(10); temp = ppb_rdtr(&sc->lpt_dev) & mask; } while (temp != data && --timeout); lprintf(("out=%x\tin=%x\ttout=%d\n", data, temp, timeout)); return (temp == data); } /* * Probe simplified by replacing multiple loops with a hardcoded * test pattern - 1999/02/08 des@freebsd.org * * New lpt port probe Geoff Rehmet - Rhodes University - 14/2/94 * Based partially on Rod Grimes' printer probe * * Logic: * 1) If no port address was given, use the bios detected ports * and autodetect what ports the printers are on. * 2) Otherwise, probe the data port at the address given, * using the method in Rod Grimes' port probe. * (Much code ripped off directly from Rod's probe.) * * Comments from Rod's probe: * Logic: * 1) You should be able to write to and read back the same value * to the data port. Do an alternating zeros, alternating ones, * walking zero, and walking one test to check for stuck bits. * * 2) You should be able to write to and read back the same value * to the control port lower 5 bits, the upper 3 bits are reserved * per the IBM PC technical reference manauls and different boards * do different things with them. Do an alternating zeros, alternating * ones, walking zero, and walking one test to check for stuck bits. * * Some printers drag the strobe line down when the are powered off * so this bit has been masked out of the control port test. * * XXX Some printers may not like a fast pulse on init or strobe, I * don't know at this point, if that becomes a problem these bits * should be turned off in the mask byte for the control port test. * * We are finally left with a mask of 0x14, due to some printers * being adamant about holding other bits high ........ * * Before probing the control port, we write a 0 to the data port - * If not, some printers chuck out garbage when the strobe line * gets toggled. * * 3) Set the data and control ports to a value of 0 * * This probe routine has been tested on Epson Lx-800, HP LJ3P, * Epson FX-1170 and C.Itoh 8510RM * printers. * Quick exit on fail added. */ static int lpt_detect(struct lpt_data *sc) { static u_char testbyte[18] = { 0x55, /* alternating zeros */ 0xaa, /* alternating ones */ 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f, /* walking zero */ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 /* walking one */ }; int i, error, status; status = 1; /* assume success */ if ((error = lpt_request_ppbus(sc, PPB_DONTWAIT))) { printf(LPT_NAME ": cannot alloc ppbus (%d)!\n", error); status = 0; goto end_probe; } for (i = 0; i < 18 && status; i++) if (!lpt_port_test(sc, testbyte[i], 0xff)) { status = 0; goto end_probe; } end_probe: /* write 0's to control and data ports */ ppb_wdtr(&sc->lpt_dev, 0); ppb_wctr(&sc->lpt_dev, 0); lpt_release_ppbus(sc); return (status); } /* * lptprobe() */ static struct ppb_device * lptprobe(struct ppb_data *ppb) { struct lpt_data *sc; sc = (struct lpt_data *) malloc(sizeof(struct lpt_data), M_TEMP, M_NOWAIT); if (!sc) { printf(LPT_NAME ": cannot malloc!\n"); return (0); } bzero(sc, sizeof(struct lpt_data)); lptdata[nlpt] = sc; /* * lpt dependent initialisation. */ sc->lpt_unit = nlpt; /* * ppbus dependent initialisation. */ sc->lpt_dev.id_unit = sc->lpt_unit; sc->lpt_dev.name = lptdriver.name; sc->lpt_dev.ppb = ppb; sc->lpt_dev.intr = lptintr; /* * Now, try to detect the printer. */ if (!lpt_detect(sc)) { free(sc, M_TEMP); return (0); } /* Ok, go to next device on next probe */ nlpt ++; return (&sc->lpt_dev); } static int lptattach(struct ppb_device *dev) { struct lpt_data *sc = lptdata[dev->id_unit]; int error; /* * Report ourselves */ printf(LPT_NAME "%d: on ppbus %d\n", dev->id_unit, dev->ppb->ppb_link->adapter_unit); sc->sc_primed = 0; /* not primed yet */ if ((error = lpt_request_ppbus(sc, PPB_DONTWAIT))) { printf(LPT_NAME ": cannot alloc ppbus (%d)!\n", error); return (0); } ppb_wctr(&sc->lpt_dev, LPC_NINIT); /* check if we can use interrupt, should be done by ppc stuff */ lprintf(("oldirq %x\n", sc->sc_irq)); if (ppb_get_irq(&sc->lpt_dev)) { sc->sc_irq = LP_HAS_IRQ | LP_USE_IRQ | LP_ENABLE_IRQ; printf(LPT_NAME "%d: Interrupt-driven port\n", dev->id_unit); } else { sc->sc_irq = 0; lprintf((LPT_NAME "%d: Polled port\n", dev->id_unit)); } lprintf(("irq %x\n", sc->sc_irq)); lpt_release_ppbus(sc); #ifdef DEVFS sc->devfs_token = devfs_add_devswf(&lpt_cdevsw, dev->id_unit, DV_CHR, UID_ROOT, GID_WHEEL, 0600, LPT_NAME "%d", dev->id_unit); sc->devfs_token_ctl = devfs_add_devswf(&lpt_cdevsw, dev->id_unit | LP_BYPASS, DV_CHR, UID_ROOT, GID_WHEEL, 0600, LPT_NAME "%d.ctl", dev->id_unit); #endif return (1); } static void lptout(void *arg) { struct lpt_data *sc = arg; int pl; lprintf(("T %x ", ppb_rstr(&sc->lpt_dev))); if (sc->sc_state & OPEN) { sc->sc_backoff++; if (sc->sc_backoff > hz/LPTOUTMAX) sc->sc_backoff = sc->sc_backoff > hz/LPTOUTMAX; timeout(lptout, (caddr_t)sc, sc->sc_backoff); } else sc->sc_state &= ~TOUT; if (sc->sc_state & EERROR) sc->sc_state &= ~EERROR; /* * Avoid possible hangs do to missed interrupts */ if (sc->sc_xfercnt) { pl = spltty(); lpt_intr(sc->lpt_unit); splx(pl); } else { sc->sc_state &= ~OBUSY; wakeup((caddr_t)sc); } } /* * lptopen -- reset the printer, then wait until it's selected and not busy. * If LP_BYPASS flag is selected, then we do not try to select the * printer -- this is just used for passing ioctls. */ static int lptopen(dev_t dev, int flags, int fmt, struct proc *p) { struct lpt_data *sc; int s; int trys, err; u_int unit = LPTUNIT(minor(dev)); if ((unit >= nlpt)) return (ENXIO); sc = lptdata[unit]; if (sc->sc_state) { lprintf((LPT_NAME ": still open %x\n", sc->sc_state)); return(EBUSY); } else sc->sc_state |= LPTINIT; sc->sc_flags = LPTFLAGS(minor(dev)); /* Check for open with BYPASS flag set. */ if (sc->sc_flags & LP_BYPASS) { sc->sc_state = OPEN; return(0); } /* request the ppbus only if we don't have it already */ if ((err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR)) != 0) return (err); s = spltty(); lprintf((LPT_NAME " flags 0x%x\n", sc->sc_flags)); /* set IRQ status according to ENABLE_IRQ flag */ if (sc->sc_irq & LP_ENABLE_IRQ) sc->sc_irq |= LP_USE_IRQ; else sc->sc_irq &= ~LP_USE_IRQ; /* init printer */ if ((sc->sc_flags & LP_NO_PRIME) == 0) { if((sc->sc_flags & LP_PRIMEOPEN) || sc->sc_primed == 0) { ppb_wctr(&sc->lpt_dev, 0); sc->sc_primed++; DELAY(500); } } ppb_wctr(&sc->lpt_dev, LPC_SEL|LPC_NINIT); /* wait till ready (printer running diagnostics) */ trys = 0; do { /* ran out of waiting for the printer */ if (trys++ >= LPINITRDY*4) { splx(s); sc->sc_state = 0; lprintf(("status %x\n", ppb_rstr(&sc->lpt_dev))); lpt_release_ppbus(sc); return (EBUSY); } /* wait 1/4 second, give up if we get a signal */ if (tsleep((caddr_t)sc, LPPRI|PCATCH, "lptinit", hz/4) != EWOULDBLOCK) { sc->sc_state = 0; splx(s); lpt_release_ppbus(sc); return (EBUSY); } /* is printer online and ready for output */ } while ((ppb_rstr(&sc->lpt_dev) & (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) != (LPS_SEL|LPS_NBSY|LPS_NERR)); sc->sc_control = LPC_SEL|LPC_NINIT; if (sc->sc_flags & LP_AUTOLF) sc->sc_control |= LPC_AUTOL; /* enable interrupt if interrupt-driven */ if (sc->sc_irq & LP_USE_IRQ) sc->sc_control |= LPC_ENA; ppb_wctr(&sc->lpt_dev, sc->sc_control); sc->sc_state = OPEN; sc->sc_inbuf = geteblk(BUFSIZE); sc->sc_statbuf = geteblk(BUFSTATSIZE); sc->sc_xfercnt = 0; splx(s); /* release the ppbus */ lpt_release_ppbus(sc); /* only use timeout if using interrupt */ lprintf(("irq %x\n", sc->sc_irq)); if (sc->sc_irq & LP_USE_IRQ) { sc->sc_state |= TOUT; timeout(lptout, (caddr_t)sc, (sc->sc_backoff = hz/LPTOUTINITIAL)); } lprintf(("opened.\n")); return(0); } /* * lptclose -- close the device, free the local line buffer. * * Check for interrupted write call added. */ static int lptclose(dev_t dev, int flags, int fmt, struct proc *p) { struct lpt_data *sc = lptdata[LPTUNIT(minor(dev))]; int err; if(sc->sc_flags & LP_BYPASS) goto end_close; if ((err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR)) != 0) return (err); sc->sc_state &= ~OPEN; /* if the last write was interrupted, don't complete it */ if((!(sc->sc_state & INTERRUPTED)) && (sc->sc_irq & LP_USE_IRQ)) while ((ppb_rstr(&sc->lpt_dev) & (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) != (LPS_SEL|LPS_NBSY|LPS_NERR) || sc->sc_xfercnt) /* wait 1/4 second, give up if we get a signal */ if (tsleep((caddr_t)sc, LPPRI|PCATCH, "lpclose", hz) != EWOULDBLOCK) break; ppb_wctr(&sc->lpt_dev, LPC_NINIT); brelse(sc->sc_inbuf); brelse(sc->sc_statbuf); end_close: /* release the bus anyway */ lpt_release_ppbus(sc); sc->sc_state = 0; sc->sc_xfercnt = 0; lprintf(("closed.\n")); return(0); } /* * lpt_pushbytes() * Workhorse for actually spinning and writing bytes to printer * Derived from lpa.c * Originally by ? * * This code is only used when we are polling the port */ static int lpt_pushbytes(struct lpt_data *sc) { int spin, err, tic; char ch; lprintf(("p")); /* loop for every character .. */ while (sc->sc_xfercnt > 0) { /* printer data */ ch = *(sc->sc_cp); sc->sc_cp++; sc->sc_xfercnt--; /* * Wait for printer ready. * Loop 20 usecs testing BUSY bit, then sleep * for exponentially increasing timeout. (vak) */ for (spin = 0; NOT_READY(sc) && spin < MAX_SPIN; ++spin) DELAY(1); /* XXX delay is NOT this accurate! */ if (spin >= MAX_SPIN) { tic = 0; while (NOT_READY(sc)) { /* * Now sleep, every cycle a * little longer .. */ tic = tic + tic + 1; /* * But no more than 10 seconds. (vak) */ if (tic > MAX_SLEEP) tic = MAX_SLEEP; err = tsleep((caddr_t)sc, LPPRI, LPT_NAME "poll", tic); if (err != EWOULDBLOCK) { return (err); } } } /* output data */ ppb_wdtr(&sc->lpt_dev, ch); /* strobe */ ppb_wctr(&sc->lpt_dev, sc->sc_control|LPC_STB); ppb_wctr(&sc->lpt_dev, sc->sc_control); } return(0); } /* * lptread --retrieve printer status in IEEE1284 NIBBLE mode */ static int lptread(dev_t dev, struct uio *uio, int ioflag) { struct lpt_data *sc = lptdata[LPTUNIT(minor(dev))]; int error = 0, len; if ((error = ppb_1284_negociate(&sc->lpt_dev, PPB_NIBBLE, 0))) return (error); /* read data in an other buffer, read/write may be simultaneous */ len = 0; while (uio->uio_resid) { if ((error = ppb_1284_read(&sc->lpt_dev, PPB_NIBBLE, sc->sc_statbuf->b_data, min(BUFSTATSIZE, uio->uio_resid), &len))) { goto error; } if (!len) goto error; /* no more data */ if ((error = uiomove(sc->sc_statbuf->b_data, len, uio))) goto error; } error: ppb_1284_terminate(&sc->lpt_dev); return (error); } /* * lptwrite --copy a line from user space to a local buffer, then call * putc to get the chars moved to the output queue. * * Flagging of interrupted write added. */ static int lptwrite(dev_t dev, struct uio *uio, int ioflag) { register unsigned n; int pl, err; u_int unit = LPTUNIT(minor(dev)); struct lpt_data *sc = lptdata[LPTUNIT(minor(dev))]; if(sc->sc_flags & LP_BYPASS) { /* we can't do writes in bypass mode */ return(EPERM); } /* request the ppbus only if we don't have it already */ if ((err = lpt_request_ppbus(sc, PPB_WAIT|PPB_INTR)) != 0) return (err); sc->sc_state &= ~INTERRUPTED; while ((n = min(BUFSIZE, uio->uio_resid)) != 0) { sc->sc_cp = sc->sc_inbuf->b_data ; uiomove(sc->sc_cp, n, uio); sc->sc_xfercnt = n ; if (sc->sc_irq & LP_ENABLE_EXT) { /* try any extended mode */ err = ppb_write(&sc->lpt_dev, sc->sc_cp, sc->sc_xfercnt, 0); switch (err) { case 0: /* if not all data was sent, we could rely * on polling for the last bytes */ sc->sc_xfercnt = 0; break; case EINTR: sc->sc_state |= INTERRUPTED; return(err); case EINVAL: /* advanced mode not avail */ log(LOG_NOTICE, LPT_NAME "%d: advanced mode not avail, polling\n", unit); break; default: return(err); } } else while ((sc->sc_xfercnt > 0)&&(sc->sc_irq & LP_USE_IRQ)) { lprintf(("i")); /* if the printer is ready for a char, */ /* give it one */ if ((sc->sc_state & OBUSY) == 0){ lprintf(("\nC %d. ", sc->sc_xfercnt)); pl = spltty(); lpt_intr(sc->lpt_unit); (void) splx(pl); } lprintf(("W ")); if (sc->sc_state & OBUSY) if ((err = tsleep((caddr_t)sc, LPPRI|PCATCH, LPT_NAME "write", 0))) { sc->sc_state |= INTERRUPTED; return(err); } } /* check to see if we must do a polled write */ if(!(sc->sc_irq & LP_USE_IRQ) && (sc->sc_xfercnt)) { lprintf(("p")); err = lpt_pushbytes(sc); if (err) return(err); } } /* we have not been interrupted, release the ppbus */ lpt_release_ppbus(sc); return(0); } /* * lpt_intr -- handle printer interrupts which occur when the printer is * ready to accept another char. * * do checking for interrupted write call. */ static void lpt_intr(int unit) { struct lpt_data *sc = lptdata[unit]; int sts; int i; /* we must own the bus to use it */ if ((sc->sc_state & HAVEBUS) == 0) return; /* * Is printer online and ready for output? * * Avoid falling back to lptout() too quickly. First spin-loop * to see if the printer will become ready ``really soon now''. */ for (i = 0; i < 100 && ((sts=ppb_rstr(&sc->lpt_dev)) & RDY_MASK) != LP_READY; i++) ; if ((sts & RDY_MASK) == LP_READY) { sc->sc_state = (sc->sc_state | OBUSY) & ~EERROR; sc->sc_backoff = hz/LPTOUTINITIAL; if (sc->sc_xfercnt) { /* send char */ /*lprintf(("%x ", *sc->sc_cp)); */ ppb_wdtr(&sc->lpt_dev, *sc->sc_cp++) ; ppb_wctr(&sc->lpt_dev, sc->sc_control|LPC_STB); /* DELAY(X) */ ppb_wctr(&sc->lpt_dev, sc->sc_control); /* any more data for printer */ if(--(sc->sc_xfercnt) > 0) return; } /* * No more data waiting for printer. * Wakeup is not done if write call was interrupted. */ sc->sc_state &= ~OBUSY; if(!(sc->sc_state & INTERRUPTED)) wakeup((caddr_t)sc); lprintf(("w ")); return; } else { /* check for error */ if(((sts & (LPS_NERR | LPS_OUT) ) != LPS_NERR) && (sc->sc_state & OPEN)) sc->sc_state |= EERROR; /* lptout() will jump in and try to restart. */ } lprintf(("sts %x ", sts)); } static void lptintr(int unit) { /* call the interrupt at required spl level */ int s = spltty(); lpt_intr(unit); splx(s); return; } static int lptioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p) { int error = 0; struct lpt_data *sc; u_int unit = LPTUNIT(minor(dev)); u_char old_sc_irq; /* old printer IRQ status */ sc = lptdata[unit]; switch (cmd) { case LPT_IRQ : if(sc->sc_irq & LP_HAS_IRQ) { /* * NOTE: * If the IRQ status is changed, * this will only be visible on the * next open. * * If interrupt status changes, * this gets syslog'd. */ old_sc_irq = sc->sc_irq; switch(*(int*)data) { case 0: sc->sc_irq &= (~LP_ENABLE_IRQ); break; case 1: sc->sc_irq &= (~LP_ENABLE_EXT); sc->sc_irq |= LP_ENABLE_IRQ; break; case 2: /* classic irq based transfer and advanced * modes are in conflict */ sc->sc_irq &= (~LP_ENABLE_IRQ); sc->sc_irq |= LP_ENABLE_EXT; break; case 3: sc->sc_irq &= (~LP_ENABLE_EXT); break; default: break; } if (old_sc_irq != sc->sc_irq ) log(LOG_NOTICE, LPT_NAME "%d: switched to %s %s mode\n", unit, (sc->sc_irq & LP_ENABLE_IRQ)? "interrupt-driven":"polled", (sc->sc_irq & LP_ENABLE_EXT)? "extended":"standard"); } else /* polled port */ error = EOPNOTSUPP; break; default: error = ENODEV; } return(error); } static lpt_devsw_installed = 0; static void lpt_drvinit(void *unused) { dev_t dev; if( ! lpt_devsw_installed ) { dev = makedev(CDEV_MAJOR, 0); cdevsw_add(&dev,&lpt_cdevsw, NULL); lpt_devsw_installed = 1; } } SYSINIT(lptdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,lpt_drvinit,NULL) Index: head/sys/dev/ppbus/lpt.h =================================================================== --- head/sys/dev/ppbus/lpt.h (revision 43998) +++ head/sys/dev/ppbus/lpt.h (revision 43999) @@ -1,82 +1,65 @@ /*- - * Copyright (c) 1997 Nicolas Souchu + * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Copyright (c) 1997, 1999 Nicolas Souchu + * All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * Distantly from : * @(#)lptreg.h 1.1 (Berkeley) 12/19/90 * Id: lptreg.h,v 1.6 1997/02/22 09:36:52 peter Exp * From Id: nlpt.h,v 1.3 1999/01/10 12:04:54 nsouch Exp * - * $Id$ + * $Id: lpt.h,v 1.1 1999/02/14 11:59:59 nsouch Exp $ */ -#ifndef __NLPT_H -#define __NLPT_H +/* + * AT Parallel Port (for lineprinter) + * Interface port and bit definitions + * Written by William Jolitz 12/18/90 + * Copyright (C) William Jolitz 1990 + */ + +#ifndef __LPT_H +#define __LPT_H + +/* machine independent definitions, it shall only depend on the ppbus + * parallel port model */ + #define LPS_NERR 0x08 /* printer no error */ #define LPS_SEL 0x10 /* printer selected */ #define LPS_OUT 0x20 /* printer out of paper */ #define LPS_NACK 0x40 /* printer no ack of data */ #define LPS_NBSY 0x80 /* printer no ack of data */ #define LPC_STB 0x01 /* strobe data to printer */ #define LPC_AUTOL 0x02 /* automatic linefeed */ #define LPC_NINIT 0x04 /* initialize printer */ #define LPC_SEL 0x08 /* printer selected */ #define LPC_ENA 0x10 /* enable IRQ */ - -struct lpt_data { - unsigned short lpt_unit; - - struct ppb_device lpt_dev; - - short sc_state; - /* default case: negative prime, negative ack, handshake strobe, - prime once */ - u_char sc_control; - char sc_flags; -#define LP_POS_INIT 0x04 /* if we are a postive init signal */ -#define LP_POS_ACK 0x08 /* if we are a positive going ack */ -#define LP_NO_PRIME 0x10 /* don't prime the printer at all */ -#define LP_PRIMEOPEN 0x20 /* prime on every open */ -#define LP_AUTOLF 0x40 /* tell printer to do an automatic lf */ -#define LP_BYPASS 0x80 /* bypass printer ready checks */ - struct buf *sc_inbuf; - struct buf *sc_statbuf; - short sc_xfercnt ; - char sc_primed; - char *sc_cp ; - u_short sc_irq ; /* IRQ status of port */ -#define LP_HAS_IRQ 0x01 /* we have an irq available */ -#define LP_USE_IRQ 0x02 /* we are using our irq */ -#define LP_ENABLE_IRQ 0x04 /* enable IRQ on open */ -#define LP_ENABLE_EXT 0x10 /* we shall use advanced mode when possible */ - u_char sc_backoff ; /* time to call lptout() again */ - -#ifdef DEVFS - void *devfs_token; - void *devfs_token_ctl; -#endif -}; #endif