if_plip.c (184896) | if_plip.c (185003) |
---|---|
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 --- 13 unchanged lines hidden (view full) --- 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 */ 28 29#include <sys/cdefs.h> | 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 --- 13 unchanged lines hidden (view full) --- 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 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/dev/ppbus/if_plip.c 184896 2008-11-12 22:14:05Z jhb $"); | 30__FBSDID("$FreeBSD: head/sys/dev/ppbus/if_plip.c 185003 2008-11-16 17:42:02Z jhb $"); |
31 32/* 33 * Parallel port TCP/IP interfaces added. I looked at the driver from 34 * MACH but this is a complete rewrite, and btw. incompatible, and it 35 * should perform better too. I have never run the MACH driver though. 36 * 37 * This driver sends two bytes (0x08, 0x00) in front of each packet, 38 * to allow us to distinguish another format later. --- 81 unchanged lines hidden (view full) --- 120#ifndef LPMAXSPIN2 /* DELAY factor for the lp# interfaces */ 121#define LPMAXSPIN2 500 /* Spinning for remote handshake to happen */ 122#endif 123 124#ifndef LPMAXERRS /* Max errors before !RUNNING */ 125#define LPMAXERRS 100 126#endif 127 | 31 32/* 33 * Parallel port TCP/IP interfaces added. I looked at the driver from 34 * MACH but this is a complete rewrite, and btw. incompatible, and it 35 * should perform better too. I have never run the MACH driver though. 36 * 37 * This driver sends two bytes (0x08, 0x00) in front of each packet, 38 * to allow us to distinguish another format later. --- 81 unchanged lines hidden (view full) --- 120#ifndef LPMAXSPIN2 /* DELAY factor for the lp# interfaces */ 121#define LPMAXSPIN2 500 /* Spinning for remote handshake to happen */ 122#endif 123 124#ifndef LPMAXERRS /* Max errors before !RUNNING */ 125#define LPMAXERRS 100 126#endif 127 |
128#define CLPIPHDRLEN 14 /* We send dummy ethernet addresses (two) + packet type in front of packet */ | 128#define CLPIPHDRLEN 14 /* We send dummy ethernet addresses (two) + packet type in front of packet */ |
129#define CLPIP_SHAKE 0x80 /* This bit toggles between nibble reception */ | 129#define CLPIP_SHAKE 0x80 /* This bit toggles between nibble reception */ |
130#define MLPIPHDRLEN CLPIPHDRLEN | 130#define MLPIPHDRLEN CLPIPHDRLEN |
131 | 131 |
132#define LPIPHDRLEN 2 /* We send 0x08, 0x00 in front of packet */ | 132#define LPIPHDRLEN 2 /* We send 0x08, 0x00 in front of packet */ |
133#define LPIP_SHAKE 0x40 /* This bit toggles between nibble reception */ 134#if !defined(MLPIPHDRLEN) || LPIPHDRLEN > MLPIPHDRLEN | 133#define LPIP_SHAKE 0x40 /* This bit toggles between nibble reception */ 134#if !defined(MLPIPHDRLEN) || LPIPHDRLEN > MLPIPHDRLEN |
135#define MLPIPHDRLEN LPIPHDRLEN | 135#define MLPIPHDRLEN LPIPHDRLEN |
136#endif 137 138#define LPIPTBLSIZE 256 /* Size of octet translation table */ 139 | 136#endif 137 138#define LPIPTBLSIZE 256 /* Size of octet translation table */ 139 |
140#define lprintf if (lptflag) printf | 140#define lprintf if (lptflag) printf |
141 142#ifdef PLIP_DEBUG 143static int volatile lptflag = 1; 144#else 145static int volatile lptflag = 0; 146#endif 147 148struct lp_data { 149 struct ifnet *sc_ifp; 150 device_t sc_dev; 151 u_char *sc_ifbuf; 152 int sc_iferrs; 153 154 struct resource *res_irq; 155}; 156 157/* Tables for the lp# interface */ 158static u_char *txmith; | 141 142#ifdef PLIP_DEBUG 143static int volatile lptflag = 1; 144#else 145static int volatile lptflag = 0; 146#endif 147 148struct lp_data { 149 struct ifnet *sc_ifp; 150 device_t sc_dev; 151 u_char *sc_ifbuf; 152 int sc_iferrs; 153 154 struct resource *res_irq; 155}; 156 157/* Tables for the lp# interface */ 158static u_char *txmith; |
159#define txmitl (txmith + (1 * LPIPTBLSIZE)) 160#define trecvh (txmith + (2 * LPIPTBLSIZE)) 161#define trecvl (txmith + (3 * LPIPTBLSIZE)) | 159#define txmitl (txmith + (1 * LPIPTBLSIZE)) 160#define trecvh (txmith + (2 * LPIPTBLSIZE)) 161#define trecvl (txmith + (3 * LPIPTBLSIZE)) |
162 163static u_char *ctxmith; | 162 163static u_char *ctxmith; |
164#define ctxmitl (ctxmith + (1 * LPIPTBLSIZE)) 165#define ctrecvh (ctxmith + (2 * LPIPTBLSIZE)) 166#define ctrecvl (ctxmith + (3 * LPIPTBLSIZE)) | 164#define ctxmitl (ctxmith + (1 * LPIPTBLSIZE)) 165#define ctrecvh (ctxmith + (2 * LPIPTBLSIZE)) 166#define ctrecvl (ctxmith + (3 * LPIPTBLSIZE)) |
167 168/* Functions for the lp# interface */ 169static int lpinittables(void); 170static int lpioctl(struct ifnet *, u_long, caddr_t); 171static int lpoutput(struct ifnet *, struct mbuf *, struct sockaddr *, 172 struct rtentry *); 173static void lp_intr(void *); 174 | 167 168/* Functions for the lp# interface */ 169static int lpinittables(void); 170static int lpioctl(struct ifnet *, u_long, caddr_t); 171static int lpoutput(struct ifnet *, struct mbuf *, struct sockaddr *, 172 struct rtentry *); 173static void lp_intr(void *); 174 |
175#define DEVTOSOFTC(dev) \ | 175#define DEVTOSOFTC(dev) \ |
176 ((struct lp_data *)device_get_softc(dev)) 177 178static devclass_t lp_devclass; 179 180static void 181lp_identify(driver_t *driver, device_t parent) 182{ 183 device_t dev; --- 65 unchanged lines hidden (view full) --- 249 250 if (txmith == NULL) 251 txmith = malloc(4 * LPIPTBLSIZE, M_DEVBUF, M_NOWAIT); 252 253 if (txmith == NULL) 254 return (1); 255 256 if (ctxmith == NULL) | 176 ((struct lp_data *)device_get_softc(dev)) 177 178static devclass_t lp_devclass; 179 180static void 181lp_identify(driver_t *driver, device_t parent) 182{ 183 device_t dev; --- 65 unchanged lines hidden (view full) --- 249 250 if (txmith == NULL) 251 txmith = malloc(4 * LPIPTBLSIZE, M_DEVBUF, M_NOWAIT); 252 253 if (txmith == NULL) 254 return (1); 255 256 if (ctxmith == NULL) |
257 ctxmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT); | 257 ctxmith = malloc(4 * LPIPTBLSIZE, M_DEVBUF, M_NOWAIT); |
258 259 if (ctxmith == NULL) 260 return (1); 261 262 for (i = 0; i < LPIPTBLSIZE; i++) { 263 ctxmith[i] = (i & 0xF0) >> 4; 264 ctxmitl[i] = 0x10 | (i & 0x0F); 265 ctrecvh[i] = (i & 0x78) << 1; --- 175 unchanged lines hidden (view full) --- 441 442 bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m); 443} 444 445static void 446lp_intr(void *arg) 447{ 448 device_t dev = (device_t)arg; | 258 259 if (ctxmith == NULL) 260 return (1); 261 262 for (i = 0; i < LPIPTBLSIZE; i++) { 263 ctxmith[i] = (i & 0xF0) >> 4; 264 ctxmitl[i] = 0x10 | (i & 0x0F); 265 ctrecvh[i] = (i & 0x78) << 1; --- 175 unchanged lines hidden (view full) --- 441 442 bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m); 443} 444 445static void 446lp_intr(void *arg) 447{ 448 device_t dev = (device_t)arg; |
449 device_t ppbus = device_get_parent(dev); | 449 device_t ppbus = device_get_parent(dev); |
450 struct lp_data *sc = DEVTOSOFTC(dev); 451 int len, s, j; 452 u_char *bp; 453 u_char c, cl; 454 struct mbuf *top; 455 456 s = splhigh(); 457 --- 96 unchanged lines hidden (view full) --- 554 lptap(sc->sc_ifp, top); 555 556 /* mbuf is free'd on failure. */ 557 netisr_queue(NETISR_IP, top); 558 } 559 } 560 goto done; 561 | 450 struct lp_data *sc = DEVTOSOFTC(dev); 451 int len, s, j; 452 u_char *bp; 453 u_char c, cl; 454 struct mbuf *top; 455 456 s = splhigh(); 457 --- 96 unchanged lines hidden (view full) --- 554 lptap(sc->sc_ifp, top); 555 556 /* mbuf is free'd on failure. */ 557 netisr_queue(NETISR_IP, top); 558 } 559 } 560 goto done; 561 |
562 err: | 562err: |
563 ppb_wdtr(ppbus, 0); 564 lprintf("R"); 565 sc->sc_ifp->if_ierrors++; 566 sc->sc_iferrs++; 567 568 /* 569 * We are not able to send receive anything for now, 570 * so stop wasting our time 571 */ 572 if (sc->sc_iferrs > LPMAXERRS) { 573 if_printf(sc->sc_ifp, "Too many errors, Going off-line.\n"); 574 ppb_wctr(ppbus, 0x00); 575 sc->sc_ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 576 sc->sc_iferrs = 0; 577 } 578 | 563 ppb_wdtr(ppbus, 0); 564 lprintf("R"); 565 sc->sc_ifp->if_ierrors++; 566 sc->sc_iferrs++; 567 568 /* 569 * We are not able to send receive anything for now, 570 * so stop wasting our time 571 */ 572 if (sc->sc_iferrs > LPMAXERRS) { 573 if_printf(sc->sc_ifp, "Too many errors, Going off-line.\n"); 574 ppb_wctr(ppbus, 0x00); 575 sc->sc_ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 576 sc->sc_iferrs = 0; 577 } 578 |
579 done: | 579done: |
580 splx(s); 581} 582 583static __inline int | 580 splx(s); 581} 582 583static __inline int |
584lpoutbyte (u_char byte, int spin, device_t ppbus) | 584lpoutbyte(u_char byte, int spin, device_t ppbus) |
585{ 586 587 ppb_wdtr(ppbus, txmith[byte]); 588 while (!(ppb_rstr(ppbus) & LPIP_SHAKE)) 589 if (--spin == 0) 590 return (1); 591 ppb_wdtr(ppbus, txmitl[byte]); 592 while (ppb_rstr(ppbus) & LPIP_SHAKE) --- 174 unchanged lines hidden --- | 585{ 586 587 ppb_wdtr(ppbus, txmith[byte]); 588 while (!(ppb_rstr(ppbus) & LPIP_SHAKE)) 589 if (--spin == 0) 590 return (1); 591 ppb_wdtr(ppbus, txmitl[byte]); 592 while (ppb_rstr(ppbus) & LPIP_SHAKE) --- 174 unchanged lines hidden --- |