if_plip.c revision 1.26 1 1.26 knakahar /* $NetBSD: if_plip.c,v 1.26 2016/04/20 09:01:03 knakahara Exp $ */
2 1.3 bjh21
3 1.1 jdolecek /*-
4 1.1 jdolecek * Copyright (c) 1997 Poul-Henning Kamp
5 1.5 jdolecek * Copyright (c) 2003, 2004 Gary Thorpe <gathorpe (at) users.sourceforge.net>
6 1.1 jdolecek * All rights reserved.
7 1.1 jdolecek *
8 1.1 jdolecek * Redistribution and use in source and binary forms, with or without
9 1.1 jdolecek * modification, are permitted provided that the following conditions
10 1.1 jdolecek * are met:
11 1.1 jdolecek * 1. Redistributions of source code must retain the above copyright
12 1.1 jdolecek * notice, this list of conditions and the following disclaimer.
13 1.1 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 jdolecek * notice, this list of conditions and the following disclaimer in the
15 1.1 jdolecek * documentation and/or other materials provided with the distribution.
16 1.1 jdolecek *
17 1.1 jdolecek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 1.1 jdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.1 jdolecek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.1 jdolecek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 1.1 jdolecek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.1 jdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.1 jdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.1 jdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.1 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.1 jdolecek * SUCH DAMAGE.
28 1.1 jdolecek *
29 1.1 jdolecek * From Id: lpt.c,v 1.55.2.1 1996/11/12 09:08:38 phk Exp
30 1.4 bjh21 * FreeBSD: src/sys/dev/ppbus/if_plip.c,v 1.19.2.1 2000/05/24 00:20:57 n_hibma Exp
31 1.1 jdolecek */
32 1.1 jdolecek
33 1.4 bjh21 #include <sys/cdefs.h>
34 1.26 knakahar __KERNEL_RCSID(0, "$NetBSD: if_plip.c,v 1.26 2016/04/20 09:01:03 knakahara Exp $");
35 1.4 bjh21
36 1.1 jdolecek /*
37 1.1 jdolecek * Parallel port TCP/IP interfaces added. I looked at the driver from
38 1.1 jdolecek * MACH but this is a complete rewrite, and btw. incompatible, and it
39 1.1 jdolecek * should perform better too. I have never run the MACH driver though.
40 1.1 jdolecek *
41 1.1 jdolecek * This driver sends two bytes (0x08, 0x00) in front of each packet,
42 1.1 jdolecek * to allow us to distinguish another format later.
43 1.1 jdolecek *
44 1.1 jdolecek * Now added an Linux/Crynwr compatibility mode which is enabled using
45 1.1 jdolecek * IF_LINK0 - Tim Wilkinson.
46 1.1 jdolecek *
47 1.1 jdolecek * TODO:
48 1.1 jdolecek * Make HDLC/PPP mode, use IF_LLC1 to enable.
49 1.1 jdolecek *
50 1.1 jdolecek * Connect the two computers using a Laplink parallel cable to use this
51 1.1 jdolecek * feature:
52 1.1 jdolecek *
53 1.1 jdolecek * +----------------------------------------+
54 1.1 jdolecek * |A-name A-End B-End Descr. Port/Bit |
55 1.1 jdolecek * +----------------------------------------+
56 1.1 jdolecek * |DATA0 2 15 Data 0/0x01 |
57 1.1 jdolecek * |-ERROR 15 2 1/0x08 |
58 1.1 jdolecek * +----------------------------------------+
59 1.1 jdolecek * |DATA1 3 13 Data 0/0x02 |
60 1.1 jdolecek * |+SLCT 13 3 1/0x10 |
61 1.1 jdolecek * +----------------------------------------+
62 1.1 jdolecek * |DATA2 4 12 Data 0/0x04 |
63 1.1 jdolecek * |+PE 12 4 1/0x20 |
64 1.1 jdolecek * +----------------------------------------+
65 1.1 jdolecek * |DATA3 5 10 Strobe 0/0x08 |
66 1.1 jdolecek * |-ACK 10 5 1/0x40 |
67 1.1 jdolecek * +----------------------------------------+
68 1.1 jdolecek * |DATA4 6 11 Data 0/0x10 |
69 1.1 jdolecek * |BUSY 11 6 1/~0x80 |
70 1.1 jdolecek * +----------------------------------------+
71 1.1 jdolecek * |GND 18-25 18-25 GND - |
72 1.1 jdolecek * +----------------------------------------+
73 1.1 jdolecek *
74 1.1 jdolecek * Expect transfer-rates up to 75 kbyte/sec.
75 1.1 jdolecek *
76 1.1 jdolecek * If GCC could correctly grok
77 1.9 perry * register int port __asm("edx")
78 1.1 jdolecek * the code would be cleaner
79 1.1 jdolecek *
80 1.1 jdolecek * Poul-Henning Kamp <phk (at) freebsd.org>
81 1.1 jdolecek */
82 1.1 jdolecek
83 1.1 jdolecek /*
84 1.1 jdolecek * Update for ppbus, PLIP support only - Nicolas Souchu
85 1.6 perry */
86 1.1 jdolecek
87 1.1 jdolecek #include "opt_inet.h"
88 1.1 jdolecek #include "opt_plip.h"
89 1.1 jdolecek
90 1.1 jdolecek #include <sys/systm.h>
91 1.1 jdolecek #include <sys/param.h>
92 1.1 jdolecek #include <sys/proc.h>
93 1.1 jdolecek #include <sys/types.h>
94 1.1 jdolecek #include <sys/device.h>
95 1.1 jdolecek #include <sys/ioctl.h>
96 1.1 jdolecek #include <sys/malloc.h>
97 1.1 jdolecek #include <sys/mbuf.h>
98 1.1 jdolecek
99 1.1 jdolecek #include <net/if.h>
100 1.1 jdolecek #include <net/if_types.h>
101 1.1 jdolecek #include <net/netisr.h>
102 1.1 jdolecek
103 1.1 jdolecek #include <sys/time.h>
104 1.1 jdolecek #include <net/bpf.h>
105 1.1 jdolecek
106 1.1 jdolecek #ifdef INET
107 1.1 jdolecek #include <netinet/in_var.h>
108 1.1 jdolecek /* #include <netinet/in.h> */
109 1.1 jdolecek #else
110 1.1 jdolecek #error Cannot config lp/plip without inet
111 1.1 jdolecek #endif
112 1.1 jdolecek
113 1.1 jdolecek #include <dev/ppbus/ppbus_base.h>
114 1.1 jdolecek #include <dev/ppbus/ppbus_device.h>
115 1.1 jdolecek #include <dev/ppbus/ppbus_io.h>
116 1.1 jdolecek #include <dev/ppbus/ppbus_var.h>
117 1.1 jdolecek
118 1.1 jdolecek #include <machine/types.h>
119 1.15 ad #include <sys/intr.h>
120 1.1 jdolecek
121 1.1 jdolecek #ifndef LPMTU /* MTU for the lp# interfaces */
122 1.1 jdolecek #define LPMTU 1500
123 1.1 jdolecek #endif
124 1.1 jdolecek
125 1.1 jdolecek #ifndef LPMAXSPIN1 /* DELAY factor for the lp# interfaces */
126 1.1 jdolecek #define LPMAXSPIN1 8000 /* Spinning for remote intr to happen */
127 1.1 jdolecek #endif
128 1.1 jdolecek
129 1.1 jdolecek #ifndef LPMAXSPIN2 /* DELAY factor for the lp# interfaces */
130 1.1 jdolecek #define LPMAXSPIN2 500 /* Spinning for remote handshake to happen */
131 1.1 jdolecek #endif
132 1.1 jdolecek
133 1.1 jdolecek #ifndef LPMAXERRS /* Max errors before !RUNNING */
134 1.1 jdolecek #define LPMAXERRS 100
135 1.1 jdolecek #endif
136 1.1 jdolecek
137 1.1 jdolecek #ifndef LPMAXRTRY
138 1.6 perry #define LPMAXRTRY 100 /* If channel busy, retry LPMAXRTRY
139 1.1 jdolecek consecutive times */
140 1.1 jdolecek #endif
141 1.1 jdolecek
142 1.1 jdolecek #define CLPIPHDRLEN 14 /* We send dummy ethernet addresses (two) + packet type in front of packet */
143 1.1 jdolecek #define CLPIP_SHAKE 0x80 /* This bit toggles between nibble reception */
144 1.1 jdolecek #define MLPIPHDRLEN CLPIPHDRLEN
145 1.1 jdolecek
146 1.1 jdolecek #define LPIPHDRLEN 2 /* We send 0x08, 0x00 in front of packet */
147 1.1 jdolecek #define LPIP_SHAKE 0x40 /* This bit toggles between nibble reception */
148 1.1 jdolecek #if !defined(MLPIPHDRLEN) || LPIPHDRLEN > MLPIPHDRLEN
149 1.1 jdolecek #define MLPIPHDRLEN LPIPHDRLEN
150 1.1 jdolecek #endif
151 1.1 jdolecek
152 1.1 jdolecek #define LPIPTBLSIZE 256 /* Size of octet translation table */
153 1.1 jdolecek
154 1.1 jdolecek #define LP_PRINTF if (lpflag) printf
155 1.1 jdolecek
156 1.1 jdolecek #ifdef PLIP_DEBUG
157 1.1 jdolecek static int volatile lpflag = 1;
158 1.1 jdolecek #else
159 1.1 jdolecek static int volatile lpflag = 0;
160 1.1 jdolecek #endif
161 1.1 jdolecek
162 1.1 jdolecek /* Tx/Rsv tables for the lp interface */
163 1.1 jdolecek static u_char *txmith;
164 1.1 jdolecek #define txmitl (txmith+(1*LPIPTBLSIZE))
165 1.1 jdolecek #define trecvh (txmith+(2*LPIPTBLSIZE))
166 1.1 jdolecek #define trecvl (txmith+(3*LPIPTBLSIZE))
167 1.1 jdolecek static u_char *ctxmith;
168 1.1 jdolecek #define ctxmitl (ctxmith+(1*LPIPTBLSIZE))
169 1.1 jdolecek #define ctrecvh (ctxmith+(2*LPIPTBLSIZE))
170 1.1 jdolecek #define ctrecvl (ctxmith+(3*LPIPTBLSIZE))
171 1.1 jdolecek static uint16_t lp_count = 0;
172 1.1 jdolecek
173 1.1 jdolecek /* Autoconf functions */
174 1.18 cegger static int lp_probe(device_t, cfdata_t, void *);
175 1.18 cegger static void lp_attach(device_t, device_t, void *);
176 1.18 cegger static int lp_detach(device_t, int);
177 1.1 jdolecek
178 1.1 jdolecek /* Soft config data */
179 1.1 jdolecek struct lp_softc {
180 1.1 jdolecek struct ppbus_device_softc ppbus_dev;
181 1.1 jdolecek struct ifnet sc_if;
182 1.1 jdolecek u_char *sc_ifbuf;
183 1.1 jdolecek unsigned short sc_iferrs;
184 1.1 jdolecek unsigned short sc_xmit_rtry;
185 1.1 jdolecek u_int8_t sc_dev_ok; /* Zero means ok */
186 1.1 jdolecek };
187 1.1 jdolecek
188 1.1 jdolecek /* Autoconf structure */
189 1.18 cegger CFATTACH_DECL_NEW(plip, sizeof(struct lp_softc), lp_probe, lp_attach, lp_detach,
190 1.1 jdolecek NULL);
191 1.1 jdolecek
192 1.1 jdolecek /* Functions for the lp interface */
193 1.1 jdolecek static void lpinittables(void);
194 1.1 jdolecek static void lpfreetables(void);
195 1.12 christos static int lpioctl(struct ifnet *, u_long, void *);
196 1.13 drochner static int lpoutput(struct ifnet *, struct mbuf *, const struct sockaddr *,
197 1.1 jdolecek struct rtentry *);
198 1.1 jdolecek static void lpstart(struct ifnet *);
199 1.1 jdolecek static void lp_intr(void *);
200 1.1 jdolecek
201 1.1 jdolecek
202 1.1 jdolecek static int
203 1.18 cegger lp_probe(device_t parent, cfdata_t match, void *aux)
204 1.1 jdolecek {
205 1.1 jdolecek struct ppbus_attach_args * args = aux;
206 1.6 perry
207 1.6 perry /* Fail if ppbus is not interrupt capable */
208 1.1 jdolecek if(args->capabilities & PPBUS_HAS_INTR)
209 1.1 jdolecek return 1;
210 1.1 jdolecek
211 1.6 perry printf("%s(%s): not an interrupt-driven port.\n", __func__,
212 1.17 cegger device_xname(parent));
213 1.1 jdolecek return 0;
214 1.1 jdolecek }
215 1.1 jdolecek
216 1.6 perry static void
217 1.18 cegger lp_attach(device_t parent, device_t self, void *aux)
218 1.1 jdolecek {
219 1.11 thorpej struct lp_softc * lp = device_private(self);
220 1.1 jdolecek struct ifnet * ifp = &lp->sc_if;
221 1.1 jdolecek
222 1.20 cegger lp->ppbus_dev.sc_dev = self;
223 1.1 jdolecek lp->sc_dev_ok = 0;
224 1.1 jdolecek lp->sc_ifbuf = NULL;
225 1.1 jdolecek lp->sc_iferrs = 0;
226 1.1 jdolecek lp->sc_xmit_rtry = 0;
227 1.1 jdolecek
228 1.11 thorpej ifp->if_softc = lp;
229 1.17 cegger strlcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
230 1.1 jdolecek ifp->if_mtu = LPMTU;
231 1.1 jdolecek ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST;
232 1.1 jdolecek ifp->if_ioctl = lpioctl;
233 1.1 jdolecek ifp->if_output = lpoutput;
234 1.1 jdolecek ifp->if_start = lpstart;
235 1.1 jdolecek ifp->if_type = IFT_PARA;
236 1.1 jdolecek ifp->if_hdrlen = 0;
237 1.1 jdolecek ifp->if_addrlen = 0;
238 1.1 jdolecek ifp->if_dlt = DLT_NULL;
239 1.1 jdolecek IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
240 1.1 jdolecek IFQ_SET_READY(&ifp->if_snd);
241 1.1 jdolecek if_attach(ifp);
242 1.1 jdolecek if_alloc_sadl(ifp);
243 1.1 jdolecek
244 1.24 joerg bpf_attach(ifp, DLT_NULL, sizeof(u_int32_t));
245 1.1 jdolecek
246 1.1 jdolecek if(lp_count++ == 0)
247 1.1 jdolecek lpinittables();
248 1.1 jdolecek printf("\n");
249 1.1 jdolecek }
250 1.1 jdolecek
251 1.1 jdolecek static int
252 1.18 cegger lp_detach(device_t self, int flags)
253 1.1 jdolecek {
254 1.1 jdolecek int error = 0;
255 1.11 thorpej struct lp_softc * lp = device_private(self);
256 1.18 cegger device_t ppbus = device_parent(self);
257 1.6 perry
258 1.1 jdolecek if(lp->sc_dev_ok) {
259 1.1 jdolecek if(!(flags & DETACH_QUIET))
260 1.1 jdolecek LP_PRINTF("%s(%s): device not properly attached! "
261 1.6 perry "Skipping detach....\n", __func__,
262 1.17 cegger device_xname(self));
263 1.1 jdolecek return error;
264 1.1 jdolecek }
265 1.1 jdolecek
266 1.1 jdolecek /* If interface is up, bring it down and release ppbus */
267 1.1 jdolecek if(lp->sc_if.if_flags & IFF_RUNNING) {
268 1.1 jdolecek ppbus_wctr(ppbus, 0x00);
269 1.1 jdolecek if_detach(&lp->sc_if);
270 1.1 jdolecek error = ppbus_remove_handler(ppbus, lp_intr);
271 1.1 jdolecek if(error) {
272 1.1 jdolecek if(!(flags & DETACH_QUIET))
273 1.1 jdolecek LP_PRINTF("%s(%s): unable to remove interrupt "
274 1.6 perry "callback.\n", __func__,
275 1.17 cegger device_xname(self));
276 1.1 jdolecek if(!(flags & DETACH_FORCE))
277 1.1 jdolecek return error;
278 1.1 jdolecek }
279 1.1 jdolecek error = ppbus_release_bus(ppbus, self, 0, 0);
280 1.1 jdolecek if(error) {
281 1.1 jdolecek if(!(flags & DETACH_QUIET))
282 1.6 perry LP_PRINTF("%s(%s): error releasing bus %s.\n",
283 1.17 cegger __func__, device_xname(self),
284 1.17 cegger device_xname(ppbus));
285 1.1 jdolecek if(!(flags & DETACH_FORCE))
286 1.1 jdolecek return error;
287 1.1 jdolecek }
288 1.1 jdolecek }
289 1.1 jdolecek
290 1.1 jdolecek if(lp->sc_ifbuf)
291 1.1 jdolecek free(lp->sc_ifbuf, M_DEVBUF);
292 1.1 jdolecek
293 1.1 jdolecek if(--lp_count == 0)
294 1.1 jdolecek lpfreetables();
295 1.1 jdolecek return error;
296 1.1 jdolecek }
297 1.1 jdolecek
298 1.1 jdolecek /*
299 1.1 jdolecek * Build the translation tables for the LPIP (BSD unix) protocol.
300 1.1 jdolecek * We don't want to calculate these nasties in our tight loop, so we
301 1.1 jdolecek * precalculate them when we initialize.
302 1.1 jdolecek */
303 1.6 perry static void
304 1.1 jdolecek lpinittables (void)
305 1.1 jdolecek {
306 1.1 jdolecek int i;
307 1.1 jdolecek
308 1.1 jdolecek if (!txmith)
309 1.1 jdolecek txmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_WAITOK);
310 1.1 jdolecek
311 1.1 jdolecek if (!ctxmith)
312 1.1 jdolecek ctxmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_WAITOK);
313 1.1 jdolecek
314 1.1 jdolecek for(i = 0; i < LPIPTBLSIZE; i++) {
315 1.1 jdolecek ctxmith[i] = (i & 0xF0) >> 4;
316 1.1 jdolecek ctxmitl[i] = 0x10 | (i & 0x0F);
317 1.1 jdolecek ctrecvh[i] = (i & 0x78) << 1;
318 1.1 jdolecek ctrecvl[i] = (i & 0x78) >> 3;
319 1.1 jdolecek }
320 1.1 jdolecek
321 1.1 jdolecek for(i = 0; i < LPIPTBLSIZE; i++) {
322 1.1 jdolecek txmith[i] = ((i & 0x80) >> 3) | ((i & 0x70) >> 4) | 0x08;
323 1.1 jdolecek txmitl[i] = ((i & 0x08) << 1) | (i & 0x07);
324 1.1 jdolecek trecvh[i] = ((~i) & 0x80) | ((i & 0x38) << 1);
325 1.1 jdolecek trecvl[i] = (((~i) & 0x80) >> 4) | ((i & 0x38) >> 3);
326 1.1 jdolecek }
327 1.1 jdolecek }
328 1.1 jdolecek
329 1.1 jdolecek /* Free translation tables */
330 1.6 perry static void
331 1.1 jdolecek lpfreetables (void)
332 1.1 jdolecek {
333 1.1 jdolecek if (txmith)
334 1.1 jdolecek free(txmith, M_DEVBUF);
335 1.1 jdolecek if (ctxmith)
336 1.1 jdolecek free(ctxmith, M_DEVBUF);
337 1.1 jdolecek txmith = ctxmith = NULL;
338 1.1 jdolecek }
339 1.1 jdolecek
340 1.6 perry
341 1.1 jdolecek /* Process an ioctl request. */
342 1.1 jdolecek static int
343 1.22 dyoung lpioctl(struct ifnet *ifp, u_long cmd, void *data)
344 1.1 jdolecek {
345 1.21 cegger struct lp_softc * sc = ifp->if_softc;
346 1.21 cegger device_t dev = sc->ppbus_dev.sc_dev;
347 1.18 cegger device_t ppbus = device_parent(dev);
348 1.1 jdolecek struct ifaddr * ifa = (struct ifaddr *)data;
349 1.1 jdolecek struct ifreq * ifr = (struct ifreq *)data;
350 1.1 jdolecek u_char * ptr;
351 1.1 jdolecek int error, s;
352 1.1 jdolecek
353 1.1 jdolecek error = 0;
354 1.1 jdolecek s = splnet();
355 1.1 jdolecek
356 1.1 jdolecek if(sc->sc_dev_ok) {
357 1.6 perry LP_PRINTF("%s(%s): device not properly attached!", __func__,
358 1.17 cegger device_xname(dev));
359 1.1 jdolecek error = ENODEV;
360 1.1 jdolecek goto end;
361 1.1 jdolecek }
362 1.6 perry
363 1.1 jdolecek switch (cmd) {
364 1.1 jdolecek
365 1.1 jdolecek case SIOCSIFDSTADDR:
366 1.1 jdolecek if (ifa->ifa_addr->sa_family != AF_INET)
367 1.1 jdolecek error = EAFNOSUPPORT;
368 1.1 jdolecek break;
369 1.6 perry
370 1.22 dyoung case SIOCINITIFADDR:
371 1.1 jdolecek if (ifa->ifa_addr->sa_family != AF_INET) {
372 1.1 jdolecek error = EAFNOSUPPORT;
373 1.1 jdolecek break;
374 1.1 jdolecek }
375 1.1 jdolecek ifp->if_flags |= IFF_UP;
376 1.1 jdolecek /* FALLTHROUGH */
377 1.1 jdolecek case SIOCSIFFLAGS:
378 1.22 dyoung if ((error = ifioctl_common(ifp, cmd, data)) != 0)
379 1.22 dyoung break;
380 1.1 jdolecek if((ifp->if_flags & (IFF_UP|IFF_RUNNING)) == IFF_UP) {
381 1.1 jdolecek if((error = ppbus_request_bus(ppbus, dev, 0, 0)))
382 1.1 jdolecek break;
383 1.1 jdolecek error = ppbus_set_mode(ppbus, PPBUS_COMPATIBLE, 0);
384 1.1 jdolecek if(error)
385 1.1 jdolecek break;
386 1.6 perry
387 1.1 jdolecek error = ppbus_add_handler(ppbus, lp_intr, dev);
388 1.1 jdolecek if(error) {
389 1.1 jdolecek LP_PRINTF("%s(%s): unable to register interrupt"
390 1.6 perry " callback.\n", __func__,
391 1.17 cegger device_xname(dev));
392 1.1 jdolecek ppbus_release_bus(ppbus, dev, 0, 0);
393 1.1 jdolecek break;
394 1.1 jdolecek }
395 1.1 jdolecek
396 1.1 jdolecek /* Allocate a buffer if necessary */
397 1.1 jdolecek if(sc->sc_ifbuf == NULL) {
398 1.6 perry sc->sc_ifbuf = malloc(sc->sc_if.if_mtu +
399 1.1 jdolecek MLPIPHDRLEN, M_DEVBUF, M_NOWAIT);
400 1.1 jdolecek if (!sc->sc_ifbuf) {
401 1.1 jdolecek error = ENOBUFS;
402 1.1 jdolecek ppbus_release_bus(ppbus, dev, 0, 0);
403 1.1 jdolecek break;
404 1.1 jdolecek }
405 1.1 jdolecek }
406 1.1 jdolecek
407 1.1 jdolecek ppbus_wctr(ppbus, IRQENABLE);
408 1.1 jdolecek ifp->if_flags |= IFF_RUNNING;
409 1.1 jdolecek }
410 1.1 jdolecek if((ifp->if_flags & (IFF_UP|IFF_RUNNING)) == IFF_RUNNING) {
411 1.1 jdolecek ppbus_remove_handler(ppbus, lp_intr);
412 1.1 jdolecek error = ppbus_release_bus(ppbus, dev, 0, 0);
413 1.1 jdolecek ifp->if_flags &= ~IFF_RUNNING;
414 1.1 jdolecek }
415 1.1 jdolecek /* Go quiescent */
416 1.1 jdolecek ppbus_wdtr(ppbus, 0);
417 1.1 jdolecek break;
418 1.1 jdolecek
419 1.1 jdolecek case SIOCSIFMTU:
420 1.1 jdolecek if(sc->sc_if.if_mtu == ifr->ifr_mtu)
421 1.1 jdolecek break;
422 1.1 jdolecek ptr = sc->sc_ifbuf;
423 1.6 perry sc->sc_ifbuf = malloc(ifr->ifr_mtu+MLPIPHDRLEN, M_DEVBUF,
424 1.1 jdolecek M_NOWAIT);
425 1.1 jdolecek if (!sc->sc_ifbuf) {
426 1.1 jdolecek sc->sc_ifbuf = ptr;
427 1.1 jdolecek error = ENOBUFS;
428 1.1 jdolecek break;
429 1.1 jdolecek }
430 1.1 jdolecek if(ptr)
431 1.1 jdolecek free(ptr,M_DEVBUF);
432 1.16 dyoung /*FALLTHROUGH*/
433 1.1 jdolecek case SIOCGIFMTU:
434 1.19 cegger if ((error = ifioctl_common(ifp, cmd, data)) == ENETRESET)
435 1.16 dyoung error = 0;
436 1.1 jdolecek break;
437 1.1 jdolecek
438 1.1 jdolecek case SIOCADDMULTI:
439 1.1 jdolecek case SIOCDELMULTI:
440 1.1 jdolecek if (ifr == NULL) {
441 1.1 jdolecek error = EAFNOSUPPORT; /* XXX */
442 1.1 jdolecek break;
443 1.1 jdolecek }
444 1.14 dyoung switch (ifreq_getaddr(cmd, ifr)->sa_family) {
445 1.1 jdolecek case AF_INET:
446 1.1 jdolecek break;
447 1.1 jdolecek default:
448 1.1 jdolecek return EAFNOSUPPORT;
449 1.1 jdolecek }
450 1.1 jdolecek break;
451 1.1 jdolecek
452 1.1 jdolecek case SIOCGIFMEDIA:
453 1.1 jdolecek /*
454 1.1 jdolecek * No ifmedia support at this stage; maybe use it
455 1.1 jdolecek * in future for eg. protocol selection.
456 1.1 jdolecek */
457 1.1 jdolecek default:
458 1.1 jdolecek LP_PRINTF("LP:ioctl(0x%lx)\n", cmd);
459 1.22 dyoung error = ifioctl_common(ifp, cmd, data);
460 1.1 jdolecek }
461 1.1 jdolecek
462 1.1 jdolecek end:
463 1.1 jdolecek splx(s);
464 1.6 perry return error;
465 1.1 jdolecek }
466 1.1 jdolecek
467 1.8 perry static inline int
468 1.18 cegger clpoutbyte (u_char byte, int spin, device_t ppbus)
469 1.1 jdolecek {
470 1.1 jdolecek int s = spin;
471 1.1 jdolecek ppbus_wdtr(ppbus, ctxmitl[byte]);
472 1.1 jdolecek while (ppbus_rstr(ppbus) & CLPIP_SHAKE) {
473 1.1 jdolecek if (--s == 0) {
474 1.1 jdolecek return 1;
475 1.1 jdolecek }
476 1.1 jdolecek }
477 1.1 jdolecek s = spin;
478 1.1 jdolecek ppbus_wdtr(ppbus, ctxmith[byte]);
479 1.1 jdolecek while (!(ppbus_rstr(ppbus) & CLPIP_SHAKE)) {
480 1.1 jdolecek if (--s == 0) {
481 1.1 jdolecek return 1;
482 1.1 jdolecek }
483 1.1 jdolecek }
484 1.1 jdolecek return 0;
485 1.1 jdolecek }
486 1.1 jdolecek
487 1.8 perry static inline int
488 1.18 cegger clpinbyte (int spin, device_t ppbus)
489 1.1 jdolecek {
490 1.1 jdolecek u_char c, cl;
491 1.1 jdolecek int s = spin;
492 1.1 jdolecek
493 1.1 jdolecek while(ppbus_rstr(ppbus) & CLPIP_SHAKE) {
494 1.1 jdolecek if(!--s) {
495 1.1 jdolecek return -1;
496 1.1 jdolecek }
497 1.1 jdolecek }
498 1.1 jdolecek cl = ppbus_rstr(ppbus);
499 1.1 jdolecek ppbus_wdtr(ppbus, 0x10);
500 1.1 jdolecek
501 1.1 jdolecek s = spin;
502 1.1 jdolecek while(!(ppbus_rstr(ppbus) & CLPIP_SHAKE)) {
503 1.1 jdolecek if(!--s) {
504 1.1 jdolecek return -1;
505 1.1 jdolecek }
506 1.1 jdolecek }
507 1.1 jdolecek c = ppbus_rstr(ppbus);
508 1.1 jdolecek ppbus_wdtr(ppbus, 0x00);
509 1.1 jdolecek
510 1.1 jdolecek return (ctrecvl[cl] | ctrecvh[c]);
511 1.1 jdolecek }
512 1.1 jdolecek
513 1.1 jdolecek static void
514 1.1 jdolecek lptap(struct ifnet *ifp, struct mbuf *m)
515 1.1 jdolecek {
516 1.1 jdolecek /*
517 1.1 jdolecek * Send a packet through bpf. We need to prepend the address family
518 1.1 jdolecek * as a four byte field. Cons up a dummy header to pacify bpf. This
519 1.1 jdolecek * is safe because bpf will only read from the mbuf (i.e., it won't
520 1.1 jdolecek * try to free it or keep a pointer to it).
521 1.1 jdolecek */
522 1.1 jdolecek u_int32_t af = AF_INET;
523 1.1 jdolecek struct mbuf m0;
524 1.6 perry
525 1.1 jdolecek m0.m_next = m;
526 1.1 jdolecek m0.m_len = sizeof(u_int32_t);
527 1.1 jdolecek m0.m_data = (char *)⁡
528 1.24 joerg bpf_mtap(ifp, &m0);
529 1.1 jdolecek }
530 1.1 jdolecek
531 1.1 jdolecek /* Soft interrupt handler called by hardware interrupt handler */
532 1.1 jdolecek static void
533 1.1 jdolecek lp_intr (void *arg)
534 1.1 jdolecek {
535 1.18 cegger device_t dev = (device_t)arg;
536 1.18 cegger device_t ppbus = device_parent(dev);
537 1.18 cegger struct lp_softc * sc = device_private(dev);
538 1.1 jdolecek struct ifnet * ifp = &sc->sc_if;
539 1.1 jdolecek struct mbuf *top;
540 1.1 jdolecek int len, s, j;
541 1.1 jdolecek u_char *bp;
542 1.1 jdolecek u_char c, cl;
543 1.1 jdolecek
544 1.1 jdolecek s = splnet();
545 1.1 jdolecek
546 1.1 jdolecek /* Do nothing if device not properly attached */
547 1.1 jdolecek if(sc->sc_dev_ok) {
548 1.6 perry LP_PRINTF("%s(%s): device not properly attached!", __func__,
549 1.17 cegger device_xname(dev));
550 1.1 jdolecek goto done;
551 1.1 jdolecek }
552 1.1 jdolecek
553 1.1 jdolecek /* Do nothing if interface is not up */
554 1.1 jdolecek if((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
555 1.1 jdolecek goto done;
556 1.1 jdolecek
557 1.1 jdolecek /* If other side is no longer transmitting, do nothing */
558 1.6 perry if(!(ppbus_rstr(ppbus) & LPIP_SHAKE))
559 1.1 jdolecek goto done;
560 1.1 jdolecek
561 1.1 jdolecek /* Disable interrupts until we finish */
562 1.1 jdolecek ppbus_wctr(ppbus, ~IRQENABLE);
563 1.1 jdolecek
564 1.1 jdolecek top = NULL;
565 1.1 jdolecek bp = sc->sc_ifbuf;
566 1.1 jdolecek /* Linux/crynwyr protocol receiving */
567 1.1 jdolecek if(ifp->if_flags & IFF_LINK0) {
568 1.1 jdolecek /* Ack. the request */
569 1.1 jdolecek ppbus_wdtr(ppbus, 0x01);
570 1.1 jdolecek
571 1.1 jdolecek /* Get the packet length */
572 1.1 jdolecek j = clpinbyte(LPMAXSPIN2, ppbus);
573 1.1 jdolecek if(j == -1)
574 1.1 jdolecek goto err;
575 1.1 jdolecek len = j;
576 1.1 jdolecek j = clpinbyte(LPMAXSPIN2, ppbus);
577 1.1 jdolecek if(j == -1)
578 1.1 jdolecek goto err;
579 1.1 jdolecek len = len + (j << 8);
580 1.1 jdolecek if(len > ifp->if_mtu + MLPIPHDRLEN)
581 1.1 jdolecek goto err;
582 1.1 jdolecek
583 1.1 jdolecek while(len--) {
584 1.1 jdolecek j = clpinbyte(LPMAXSPIN2, ppbus);
585 1.1 jdolecek if (j == -1) {
586 1.1 jdolecek goto err;
587 1.1 jdolecek }
588 1.1 jdolecek *bp++ = j;
589 1.1 jdolecek }
590 1.1 jdolecek /* Get and ignore checksum */
591 1.1 jdolecek j = clpinbyte(LPMAXSPIN2, ppbus);
592 1.1 jdolecek if(j == -1) {
593 1.1 jdolecek goto err;
594 1.1 jdolecek }
595 1.1 jdolecek
596 1.1 jdolecek /* Return to idle state */
597 1.1 jdolecek ppbus_wdtr(ppbus, 0);
598 1.1 jdolecek len = bp - sc->sc_ifbuf;
599 1.1 jdolecek if (len <= CLPIPHDRLEN)
600 1.1 jdolecek goto err;
601 1.1 jdolecek len -= CLPIPHDRLEN;
602 1.1 jdolecek top = m_devget(sc->sc_ifbuf + CLPIPHDRLEN, len, 0, ifp, NULL);
603 1.1 jdolecek }
604 1.1 jdolecek /* FreeBSD protocol receiving */
605 1.1 jdolecek else {
606 1.1 jdolecek len = ifp->if_mtu + LPIPHDRLEN;
607 1.1 jdolecek while(len--) {
608 1.1 jdolecek cl = ppbus_rstr(ppbus);
609 1.1 jdolecek ppbus_wdtr(ppbus, 0x08);
610 1.1 jdolecek
611 1.1 jdolecek j = LPMAXSPIN2;
612 1.1 jdolecek while((ppbus_rstr(ppbus) & LPIP_SHAKE)) {
613 1.1 jdolecek if(!--j) goto err;
614 1.1 jdolecek }
615 1.1 jdolecek
616 1.1 jdolecek c = ppbus_rstr(ppbus);
617 1.1 jdolecek ppbus_wdtr(ppbus, 0);
618 1.1 jdolecek
619 1.1 jdolecek *bp++= trecvh[cl] | trecvl[c];
620 1.1 jdolecek
621 1.1 jdolecek j = LPMAXSPIN2;
622 1.1 jdolecek while(!((cl=ppbus_rstr(ppbus)) & LPIP_SHAKE)) {
623 1.1 jdolecek if(cl != c &&
624 1.6 perry (((cl = ppbus_rstr(ppbus)) ^ 0xb8) &
625 1.1 jdolecek 0xf8) == (c & 0xf8))
626 1.1 jdolecek goto end;
627 1.1 jdolecek if(!--j) goto err;
628 1.1 jdolecek }
629 1.1 jdolecek }
630 1.1 jdolecek
631 1.1 jdolecek end:
632 1.1 jdolecek len = bp - sc->sc_ifbuf;
633 1.1 jdolecek if(len <= LPIPHDRLEN)
634 1.1 jdolecek goto err;
635 1.1 jdolecek len -= LPIPHDRLEN;
636 1.1 jdolecek top = m_devget(sc->sc_ifbuf + LPIPHDRLEN, len, 0, ifp, NULL);
637 1.1 jdolecek }
638 1.1 jdolecek
639 1.25 rmind if (top == NULL) {
640 1.1 jdolecek ifp->if_iqdrops++;
641 1.1 jdolecek goto err;
642 1.1 jdolecek }
643 1.25 rmind if (ifp->if_bpf) {
644 1.1 jdolecek lptap(ifp, top);
645 1.25 rmind }
646 1.25 rmind if (__predict_false(!pktq_enqueue(ip_pktq, top, 0))) {
647 1.25 rmind ifp->if_iqdrops++;
648 1.25 rmind m_freem(top);
649 1.25 rmind goto err;
650 1.25 rmind }
651 1.1 jdolecek ifp->if_ipackets++;
652 1.1 jdolecek ifp->if_ibytes += len;
653 1.1 jdolecek sc->sc_iferrs = 0;
654 1.1 jdolecek
655 1.1 jdolecek goto done;
656 1.1 jdolecek
657 1.1 jdolecek err:
658 1.1 jdolecek /* Return to idle state */
659 1.1 jdolecek ppbus_wdtr(ppbus, 0);
660 1.1 jdolecek ifp->if_ierrors++;
661 1.1 jdolecek sc->sc_iferrs++;
662 1.1 jdolecek LP_PRINTF("R");
663 1.6 perry /* Disable interface if there are too many errors */
664 1.1 jdolecek if(sc->sc_iferrs > LPMAXERRS) {
665 1.17 cegger aprint_error_dev(dev, "Too many consecutive errors, going off-line.\n");
666 1.1 jdolecek ppbus_wctr(ppbus, ~IRQENABLE);
667 1.1 jdolecek if_down(ifp);
668 1.1 jdolecek sc->sc_iferrs = 0;
669 1.1 jdolecek }
670 1.1 jdolecek
671 1.1 jdolecek done:
672 1.1 jdolecek /* Re-enable interrupts */
673 1.1 jdolecek ppbus_wctr(ppbus, IRQENABLE);
674 1.1 jdolecek /* If interface is not active, send some packets */
675 1.6 perry if((ifp->if_flags & IFF_OACTIVE) == 0)
676 1.1 jdolecek lpstart(ifp);
677 1.1 jdolecek splx(s);
678 1.1 jdolecek return;
679 1.1 jdolecek }
680 1.1 jdolecek
681 1.8 perry static inline int
682 1.18 cegger lpoutbyte(u_char byte, int spin, device_t ppbus)
683 1.1 jdolecek {
684 1.1 jdolecek int s = spin;
685 1.1 jdolecek ppbus_wdtr(ppbus, txmith[byte]);
686 1.1 jdolecek while(!(ppbus_rstr(ppbus) & LPIP_SHAKE)) {
687 1.1 jdolecek if(--s == 0)
688 1.1 jdolecek return 1;
689 1.1 jdolecek }
690 1.1 jdolecek s = spin;
691 1.1 jdolecek ppbus_wdtr(ppbus, txmitl[byte]);
692 1.1 jdolecek while(ppbus_rstr(ppbus) & LPIP_SHAKE) {
693 1.1 jdolecek if(--s == 0)
694 1.1 jdolecek return 1;
695 1.1 jdolecek }
696 1.1 jdolecek return 0;
697 1.1 jdolecek }
698 1.1 jdolecek
699 1.1 jdolecek /* Queue a packet for delivery */
700 1.1 jdolecek static int
701 1.13 drochner lpoutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
702 1.1 jdolecek struct rtentry *rt)
703 1.1 jdolecek {
704 1.21 cegger struct lp_softc * sc = ifp->if_softc;
705 1.21 cegger device_t dev = sc->ppbus_dev.sc_dev;
706 1.18 cegger device_t ppbus = device_parent(dev);
707 1.1 jdolecek int err;
708 1.1 jdolecek int s;
709 1.1 jdolecek
710 1.1 jdolecek s = splnet();
711 1.1 jdolecek
712 1.1 jdolecek if(sc->sc_dev_ok) {
713 1.6 perry LP_PRINTF("%s(%s): device not properly attached!", __func__,
714 1.17 cegger device_xname(dev));
715 1.1 jdolecek err = ENODEV;
716 1.1 jdolecek goto endoutput;
717 1.1 jdolecek }
718 1.6 perry
719 1.1 jdolecek if((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
720 1.1 jdolecek err = ENETDOWN;
721 1.1 jdolecek goto endoutput;
722 1.1 jdolecek }
723 1.6 perry
724 1.1 jdolecek /* Only support INET */
725 1.1 jdolecek if(dst->sa_family != AF_INET) {
726 1.1 jdolecek LP_PRINTF("%s: af%d not supported\n", ifp->if_xname,
727 1.1 jdolecek dst->sa_family);
728 1.1 jdolecek ifp->if_noproto++;
729 1.1 jdolecek err = EAFNOSUPPORT;
730 1.1 jdolecek goto endoutput;
731 1.1 jdolecek }
732 1.6 perry
733 1.26 knakahar IFQ_CLASSIFY(&ifp->if_snd, m, dst->sa_family);
734 1.19 cegger IFQ_ENQUEUE(&ifp->if_snd, m, NULL, err);
735 1.1 jdolecek if(err == 0) {
736 1.1 jdolecek if((ifp->if_flags & IFF_OACTIVE) == 0)
737 1.1 jdolecek lpstart(ifp);
738 1.1 jdolecek }
739 1.1 jdolecek else {
740 1.1 jdolecek ifp->if_oerrors++;
741 1.1 jdolecek sc->sc_iferrs++;
742 1.1 jdolecek LP_PRINTF("Q");
743 1.1 jdolecek
744 1.6 perry /* Disable interface if there are too many errors */
745 1.1 jdolecek if(sc->sc_iferrs > LPMAXERRS) {
746 1.17 cegger aprint_error_dev(dev, "Too many errors, going off-line.\n");
747 1.1 jdolecek ppbus_wctr(ppbus, ~IRQENABLE);
748 1.1 jdolecek if_down(ifp);
749 1.1 jdolecek sc->sc_iferrs = 0;
750 1.1 jdolecek }
751 1.1 jdolecek }
752 1.1 jdolecek
753 1.1 jdolecek endoutput:
754 1.1 jdolecek if((err != 0) && (err != ENOBUFS))
755 1.1 jdolecek m_freem(m);
756 1.1 jdolecek splx(s);
757 1.1 jdolecek return err;
758 1.1 jdolecek }
759 1.1 jdolecek
760 1.1 jdolecek /* Send routine: send packets over PLIP cable. Call at splnet(). */
761 1.1 jdolecek void
762 1.6 perry lpstart(struct ifnet * ifp)
763 1.1 jdolecek {
764 1.1 jdolecek struct lp_softc * lp = ifp->if_softc;
765 1.21 cegger device_t dev = lp->ppbus_dev.sc_dev;
766 1.18 cegger device_t ppbus = device_parent(dev);
767 1.1 jdolecek struct mbuf * mm;
768 1.1 jdolecek struct mbuf * m;
769 1.1 jdolecek u_char * cp;
770 1.1 jdolecek int err, i, len, spin, count;
771 1.1 jdolecek u_char str, chksum;
772 1.1 jdolecek
773 1.1 jdolecek if(lp->sc_dev_ok) {
774 1.6 perry LP_PRINTF("%s(%s): device not properly attached!", __func__,
775 1.17 cegger device_xname(dev));
776 1.1 jdolecek return;
777 1.1 jdolecek }
778 1.6 perry
779 1.1 jdolecek if((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
780 1.1 jdolecek return;
781 1.1 jdolecek }
782 1.1 jdolecek
783 1.1 jdolecek ifp->if_flags |= IFF_OACTIVE;
784 1.1 jdolecek
785 1.1 jdolecek /* Go quiescent */
786 1.1 jdolecek ppbus_wdtr(ppbus, 0);
787 1.1 jdolecek
788 1.1 jdolecek /* Output loop */
789 1.1 jdolecek for(;;) {
790 1.1 jdolecek /* Check if there are packets to send */
791 1.1 jdolecek if(IFQ_IS_EMPTY(&ifp->if_snd)) {
792 1.1 jdolecek goto final;
793 1.1 jdolecek }
794 1.1 jdolecek /* Try to send a packet, dequeue it later if successful */
795 1.1 jdolecek IFQ_POLL(&ifp->if_snd, m);
796 1.1 jdolecek if(m == NULL)
797 1.1 jdolecek goto final;
798 1.1 jdolecek
799 1.1 jdolecek str = ppbus_rstr(ppbus);
800 1.1 jdolecek /* Wait until other side is not transmitting */
801 1.6 perry if((str & LPIP_SHAKE) ||
802 1.1 jdolecek ((ifp->if_flags & IFF_LINK0) && !(str & CLPIP_SHAKE))) {
803 1.1 jdolecek LP_PRINTF("&");
804 1.1 jdolecek if(++lp->sc_xmit_rtry > LPMAXRTRY) {
805 1.17 cegger aprint_error_dev(dev, "Too many retries while channel "
806 1.17 cegger "busy, going off-line.\n");
807 1.1 jdolecek ppbus_wctr(ppbus, ~IRQENABLE);
808 1.1 jdolecek if_down(ifp);
809 1.1 jdolecek lp->sc_xmit_rtry = 0;
810 1.1 jdolecek }
811 1.1 jdolecek goto final;
812 1.1 jdolecek }
813 1.1 jdolecek lp->sc_xmit_rtry = 0;
814 1.1 jdolecek
815 1.1 jdolecek /* Disable interrupt generation */
816 1.1 jdolecek ppbus_wctr(ppbus, ~IRQENABLE);
817 1.6 perry
818 1.1 jdolecek err = 1;
819 1.1 jdolecek
820 1.1 jdolecek /* Output packet for Linux/crynwyr compatible protocol */
821 1.1 jdolecek if(ifp->if_flags & IFF_LINK0) {
822 1.1 jdolecek /* Calculate packet length */
823 1.1 jdolecek count = 14; /* Ethernet header len */
824 1.1 jdolecek for(mm = m; mm; mm = mm->m_next) {
825 1.1 jdolecek count += mm->m_len;
826 1.1 jdolecek }
827 1.1 jdolecek
828 1.1 jdolecek /* Alert other end to pending packet */
829 1.1 jdolecek spin = LPMAXSPIN1;
830 1.1 jdolecek ppbus_wdtr(ppbus, 0x08);
831 1.1 jdolecek while((ppbus_rstr(ppbus) & 0x08) == 0) {
832 1.1 jdolecek if (--spin == 0) {
833 1.1 jdolecek goto nend;
834 1.1 jdolecek }
835 1.1 jdolecek }
836 1.1 jdolecek
837 1.1 jdolecek if(clpoutbyte(count & 0xFF, LPMAXSPIN1, ppbus))
838 1.1 jdolecek goto nend;
839 1.1 jdolecek if(clpoutbyte((count >> 8) & 0xFF, LPMAXSPIN1, ppbus))
840 1.1 jdolecek goto nend;
841 1.1 jdolecek
842 1.1 jdolecek /* Send dummy ethernet header */
843 1.1 jdolecek chksum = 0;
844 1.1 jdolecek for(i = 0; i < 12; i++) {
845 1.1 jdolecek if(clpoutbyte(i, LPMAXSPIN1, ppbus))
846 1.1 jdolecek goto nend;
847 1.1 jdolecek chksum += i;
848 1.1 jdolecek }
849 1.1 jdolecek
850 1.1 jdolecek if(clpoutbyte(0x08, LPMAXSPIN1, ppbus))
851 1.1 jdolecek goto nend;
852 1.1 jdolecek if(clpoutbyte(0x00, LPMAXSPIN1, ppbus))
853 1.1 jdolecek goto nend;
854 1.1 jdolecek chksum += 0x08 + 0x00; /* Add into checksum */
855 1.1 jdolecek
856 1.1 jdolecek mm = m;
857 1.1 jdolecek do {
858 1.1 jdolecek cp = mtod(mm, u_char *);
859 1.1 jdolecek len = mm->m_len;
860 1.1 jdolecek while(len--) {
861 1.1 jdolecek if(clpoutbyte(*cp, LPMAXSPIN2, ppbus))
862 1.1 jdolecek goto nend;
863 1.1 jdolecek chksum += *cp++;
864 1.1 jdolecek }
865 1.1 jdolecek } while ((mm = mm->m_next));
866 1.1 jdolecek
867 1.1 jdolecek /* Send checksum */
868 1.1 jdolecek if(clpoutbyte(chksum, LPMAXSPIN2, ppbus))
869 1.1 jdolecek goto nend;
870 1.1 jdolecek
871 1.1 jdolecek /* No errors */
872 1.1 jdolecek err = 0;
873 1.1 jdolecek /* Go quiescent */
874 1.1 jdolecek ppbus_wdtr(ppbus, 0);
875 1.1 jdolecek }
876 1.1 jdolecek /* Output packet for FreeBSD compatible protocol */
877 1.1 jdolecek else {
878 1.1 jdolecek /* We need a sensible value if we abort */
879 1.1 jdolecek cp = NULL;
880 1.1 jdolecek
881 1.1 jdolecek if(lpoutbyte(0x08, LPMAXSPIN1, ppbus))
882 1.1 jdolecek goto end;
883 1.1 jdolecek if(lpoutbyte(0x00, LPMAXSPIN2, ppbus))
884 1.1 jdolecek goto end;
885 1.1 jdolecek
886 1.1 jdolecek mm = m;
887 1.1 jdolecek do {
888 1.1 jdolecek cp = mtod(mm,u_char *);
889 1.1 jdolecek len = mm->m_len;
890 1.1 jdolecek while(len--)
891 1.1 jdolecek if(lpoutbyte(*cp++, LPMAXSPIN2, ppbus))
892 1.1 jdolecek goto end;
893 1.1 jdolecek } while ((mm = mm->m_next));
894 1.1 jdolecek
895 1.1 jdolecek /* no errors were encountered */
896 1.1 jdolecek err = 0;
897 1.1 jdolecek
898 1.1 jdolecek end:
899 1.1 jdolecek if(cp)
900 1.1 jdolecek ppbus_wdtr(ppbus, txmitl[*(--cp)] ^ 0x17);
901 1.1 jdolecek else
902 1.1 jdolecek ppbus_wdtr(ppbus, txmitl['\0'] ^ 0x17);
903 1.1 jdolecek }
904 1.2 jdolecek
905 1.2 jdolecek nend:
906 1.1 jdolecek /* Re-enable interrupt generation */
907 1.1 jdolecek ppbus_wctr(ppbus, IRQENABLE);
908 1.1 jdolecek
909 1.1 jdolecek if(err) {
910 1.1 jdolecek /* Go quiescent */
911 1.1 jdolecek ppbus_wdtr(ppbus, 0);
912 1.6 perry
913 1.1 jdolecek ifp->if_oerrors++;
914 1.1 jdolecek lp->sc_iferrs++;
915 1.1 jdolecek LP_PRINTF("X");
916 1.1 jdolecek
917 1.6 perry /* Disable interface if there are too many errors */
918 1.1 jdolecek if(lp->sc_iferrs > LPMAXERRS) {
919 1.17 cegger aprint_error_dev(dev, "Too many errors, going off-line.\n");
920 1.1 jdolecek ppbus_wctr(ppbus, ~IRQENABLE);
921 1.1 jdolecek if_down(ifp);
922 1.1 jdolecek lp->sc_iferrs = 0;
923 1.1 jdolecek goto final;
924 1.1 jdolecek }
925 1.1 jdolecek }
926 1.1 jdolecek else {
927 1.1 jdolecek /* Dequeue packet on success */
928 1.1 jdolecek IFQ_DEQUEUE(&ifp->if_snd, m);
929 1.1 jdolecek if(ifp->if_bpf)
930 1.1 jdolecek lptap(ifp, m);
931 1.1 jdolecek ifp->if_opackets++;
932 1.1 jdolecek ifp->if_obytes += m->m_pkthdr.len;
933 1.1 jdolecek m_freem(m);
934 1.1 jdolecek }
935 1.1 jdolecek }
936 1.1 jdolecek
937 1.1 jdolecek final:
938 1.1 jdolecek ifp->if_flags &= ~IFF_OACTIVE;
939 1.1 jdolecek return;
940 1.1 jdolecek }
941