Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / dev / netif / fwe / if_fwe.c
1 /*
2  * Copyright (c) 2002-2003
3  *      Hidetoshi Shimokawa. 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  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *
16  *      This product includes software developed by Hidetoshi Shimokawa.
17  *
18  * 4. Neither the name of the author nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  * 
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  * 
34  * $FreeBSD: src/sys/dev/firewire/if_fwe.c,v 1.1.2.11 2003/04/28 03:29:18 simokawa Exp $
35  */
36
37 #include "opt_inet.h"
38
39 #include <sys/param.h>
40 #include <sys/conf.h>
41 #include <sys/kernel.h>
42 #include <sys/malloc.h>
43 #include <sys/mbuf.h>
44 #include <sys/socket.h>
45 #include <sys/sockio.h>
46 #include <sys/sysctl.h>
47 #include <sys/systm.h>
48 #include <sys/module.h>
49 #include <sys/bus.h>
50 #include <machine/bus.h>
51
52 #include <net/bpf.h>
53 #include <net/ethernet.h>
54 #include <net/if.h>
55 #include <net/if_arp.h>
56 #include <net/if_vlan_var.h>
57 #include <net/route.h>
58
59 #include <netinet/in.h>
60
61 #include <dev/firewire/firewire.h>
62 #include <dev/firewire/firewirereg.h>
63 #include <dev/firewire/if_fwevar.h>
64
65 #define FWEDEBUG        if (fwedebug) printf
66 #define TX_MAX_QUEUE    (FWMAXQUEUE - 1)
67 #define RX_MAX_QUEUE    FWMAXQUEUE
68
69 /* network interface */
70 static void fwe_start __P((struct ifnet *));
71 static int fwe_ioctl __P((struct ifnet *, u_long, caddr_t));
72 static void fwe_init __P((void *));
73
74 static void fwe_output_callback __P((struct fw_xfer *));
75 static void fwe_as_output __P((struct fwe_softc *, struct ifnet *));
76 static void fwe_as_input __P((struct fw_xferq *));
77
78 static int fwedebug = 0;
79 static int stream_ch = 1;
80
81 MALLOC_DEFINE(M_FWE, "if_fwe", "Ethernet over FireWire interface");
82 SYSCTL_INT(_debug, OID_AUTO, if_fwe_debug, CTLFLAG_RW, &fwedebug, 0, "");
83 SYSCTL_DECL(_hw_firewire);
84 SYSCTL_NODE(_hw_firewire, OID_AUTO, fwe, CTLFLAG_RD, 0,
85         "Ethernet Emulation Subsystem");
86 SYSCTL_INT(_hw_firewire_fwe, OID_AUTO, stream_ch, CTLFLAG_RW, &stream_ch, 0,
87         "Stream channel to use");
88
89 #ifdef DEVICE_POLLING
90 #define FWE_POLL_REGISTER(func, fwe, ifp)                       \
91         if (ether_poll_register(func, ifp)) {                   \
92                 struct firewire_comm *fc = (fwe)->fd.fc;        \
93                 fc->set_intr(fc, 0);                            \
94         }
95
96 #define FWE_POLL_DEREGISTER(fwe, ifp)                           \
97         do {                                                    \
98                 struct firewire_comm *fc = (fwe)->fd.fc;        \
99                 ether_poll_deregister(ifp);                     \
100                 fc->set_intr(fc, 1);                            \
101         } while(0)                                              \
102
103 static poll_handler_t fwe_poll;
104
105 static void
106 fwe_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
107 {
108         struct fwe_softc *fwe;
109         struct firewire_comm *fc;
110
111         fwe = ((struct fwe_eth_softc *)ifp->if_softc)->fwe;
112         fc = fwe->fd.fc;
113         if (cmd == POLL_DEREGISTER) {
114                 /* enable interrupts */
115                 fc->set_intr(fc, 1);
116                 return;
117         }
118         fc->poll(fc, (cmd == POLL_AND_CHECK_STATUS)?0:1, count);
119 }
120 #else
121 #define FWE_POLL_REGISTER(func, fwe, ifp)
122 #define FWE_POLL_DEREGISTER(fwe, ifp)
123 #endif
124 static void
125 fwe_identify(driver_t *driver, device_t parent)
126 {
127         BUS_ADD_CHILD(parent, 0, "if_fwe", device_get_unit(parent));
128 }
129
130 static int
131 fwe_probe(device_t dev)
132 {
133         device_t pa;
134
135         pa = device_get_parent(dev);
136         if(device_get_unit(dev) != device_get_unit(pa)){
137                 return(ENXIO);
138         }
139
140         device_set_desc(dev, "Ethernet over FireWire");
141         return (0);
142 }
143
144 static int
145 fwe_attach(device_t dev)
146 {
147         struct fwe_softc *fwe;
148         struct ifnet *ifp;
149         int unit, s;
150         u_char *eaddr;
151         struct fw_eui64 *eui;
152
153         fwe = ((struct fwe_softc *)device_get_softc(dev));
154         unit = device_get_unit(dev);
155
156         bzero(fwe, sizeof(struct fwe_softc));
157         /* XXX */
158         fwe->stream_ch = stream_ch;
159         fwe->dma_ch = -1;
160
161         fwe->fd.fc = device_get_ivars(dev);
162         fwe->fd.dev = dev;
163         fwe->fd.post_explore = NULL;
164         fwe->eth_softc.fwe = fwe;
165
166         fwe->pkt_hdr.mode.stream.tcode = FWTCODE_STREAM;
167         fwe->pkt_hdr.mode.stream.sy = 0;
168         fwe->pkt_hdr.mode.stream.chtag = fwe->stream_ch;
169
170         /* generate fake MAC address: first and last 3bytes from eui64 */
171 #define LOCAL (0x02)
172 #define GROUP (0x01)
173         eaddr = &fwe->eth_softc.arpcom.ac_enaddr[0];
174
175         eui = &fwe->fd.fc->eui;
176         eaddr[0] = (FW_EUI64_BYTE(eui, 0) | LOCAL) & ~GROUP;
177         eaddr[1] = FW_EUI64_BYTE(eui, 1);
178         eaddr[2] = FW_EUI64_BYTE(eui, 2);
179         eaddr[3] = FW_EUI64_BYTE(eui, 5);
180         eaddr[4] = FW_EUI64_BYTE(eui, 6);
181         eaddr[5] = FW_EUI64_BYTE(eui, 7);
182         printf("if_fwe%d: Fake Ethernet address: "
183                 "%02x:%02x:%02x:%02x:%02x:%02x\n", unit,
184                 eaddr[0], eaddr[1], eaddr[2], eaddr[3], eaddr[4], eaddr[5]);
185
186         /* fill the rest and attach interface */        
187         ifp = &fwe->fwe_if;
188         ifp->if_softc = &fwe->eth_softc;
189
190         ifp->if_unit = unit;
191         ifp->if_name = "fwe";
192         ifp->if_init = fwe_init;
193         ifp->if_output = ether_output;
194         ifp->if_start = fwe_start;
195         ifp->if_ioctl = fwe_ioctl;
196         ifp->if_mtu = ETHERMTU;
197         ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
198         ifp->if_snd.ifq_maxlen = TX_MAX_QUEUE;
199
200         s = splimp();
201 #if __FreeBSD_version >= 500000
202         ether_ifattach(ifp, eaddr);
203 #else
204         ether_ifattach(ifp, 1);
205 #endif
206         splx(s);
207
208         /* Tell the upper layer(s) we support long frames. */
209         ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
210 #if __FreeBSD_version >= 500000
211         ifp->if_capabilities |= IFCAP_VLAN_MTU;
212 #endif
213
214
215         FWEDEBUG("interface %s%d created.\n", ifp->if_name, ifp->if_unit);
216         return 0;
217 }
218
219 static void
220 fwe_stop(struct fwe_softc *fwe)
221 {
222         struct firewire_comm *fc;
223         struct fw_xferq *xferq;
224         struct ifnet *ifp = &fwe->fwe_if;
225         struct fw_xfer *xfer, *next;
226         int i;
227
228         fc = fwe->fd.fc;
229
230         FWE_POLL_DEREGISTER(fwe, ifp);
231
232         if (fwe->dma_ch >= 0) {
233                 xferq = fc->ir[fwe->dma_ch];
234
235                 if (xferq->flag & FWXFERQ_RUNNING)
236                         fc->irx_disable(fc, fwe->dma_ch);
237                 xferq->flag &= 
238                         ~(FWXFERQ_MODEMASK | FWXFERQ_OPEN | FWXFERQ_STREAM |
239                         FWXFERQ_EXTBUF | FWXFERQ_HANDLER | FWXFERQ_CHTAGMASK);
240                 xferq->hand =  NULL;
241
242                 for (i = 0; i < xferq->bnchunk; i ++)
243                         m_freem(xferq->bulkxfer[i].mbuf);
244                 free(xferq->bulkxfer, M_FWE);
245
246                 for (xfer = STAILQ_FIRST(&fwe->xferlist); xfer != NULL;
247                                         xfer = next) {
248                         next = STAILQ_NEXT(xfer, link);
249                         fw_xfer_free(xfer);
250                 }
251                 STAILQ_INIT(&fwe->xferlist);
252
253                 xferq->bulkxfer =  NULL;
254                 fwe->dma_ch = -1;
255         }
256
257         ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
258 }
259
260 static int
261 fwe_detach(device_t dev)
262 {
263         struct fwe_softc *fwe;
264         int s;
265
266         fwe = (struct fwe_softc *)device_get_softc(dev);
267         s = splimp();
268
269         fwe_stop(fwe);
270 #if __FreeBSD_version >= 500000
271         ether_ifdetach(&fwe->fwe_if);
272 #else
273         ether_ifdetach(&fwe->fwe_if, 1);
274 #endif
275
276         splx(s);
277         return 0;
278 }
279
280 static void
281 fwe_init(void *arg)
282 {
283         struct fwe_softc *fwe = ((struct fwe_eth_softc *)arg)->fwe;
284         struct firewire_comm *fc;
285         struct ifnet *ifp = &fwe->fwe_if;
286         struct fw_xferq *xferq;
287         struct fw_xfer *xfer;
288         struct mbuf *m;
289         int i;
290
291         FWEDEBUG("initializing %s%d\n", ifp->if_name, ifp->if_unit);
292
293         /* XXX keep promiscoud mode */
294         ifp->if_flags |= IFF_PROMISC;
295
296         fc = fwe->fd.fc;
297 #define START 0
298         if (fwe->dma_ch < 0) {
299                 xferq = NULL;
300                 for (i = START; i < fc->nisodma; i ++) {
301                         xferq = fc->ir[i];
302                         if ((xferq->flag & FWXFERQ_OPEN) == 0)
303                                 break;
304                 }
305
306                 if (xferq == NULL) {
307                         printf("no free dma channel\n");
308                         return;
309                 }
310                 fwe->dma_ch = i;
311                 fwe->stream_ch = stream_ch;
312                 fwe->pkt_hdr.mode.stream.chtag = fwe->stream_ch;
313                 /* allocate DMA channel and init packet mode */
314                 xferq->flag |= FWXFERQ_OPEN | FWXFERQ_EXTBUF |
315                                 FWXFERQ_HANDLER | FWXFERQ_STREAM;
316                 xferq->flag &= ~0xff;
317                 xferq->flag |= fwe->stream_ch & 0xff;
318                 /* register fwe_input handler */
319                 xferq->sc = (caddr_t) fwe;
320                 xferq->hand = fwe_as_input;
321                 xferq->bnchunk = RX_MAX_QUEUE;
322                 xferq->bnpacket = 1;
323                 xferq->psize = MCLBYTES;
324                 xferq->queued = 0;
325                 xferq->buf = NULL;
326                 xferq->bulkxfer = (struct fw_bulkxfer *) malloc(
327                         sizeof(struct fw_bulkxfer) * xferq->bnchunk,
328                                                         M_FWE, M_WAITOK);
329                 if (xferq->bulkxfer == NULL) {
330                         printf("if_fwe: malloc failed\n");
331                         return;
332                 }
333                 STAILQ_INIT(&xferq->stvalid);
334                 STAILQ_INIT(&xferq->stfree);
335                 STAILQ_INIT(&xferq->stdma);
336                 xferq->stproc = NULL;
337                 for (i = 0; i < xferq->bnchunk; i ++) {
338                         m =
339 #if __FreeBSD_version >= 500000
340                                 m_getcl(M_TRYWAIT, MT_DATA, M_PKTHDR);
341 #else
342                                 m_getcl(M_WAIT, MT_DATA, M_PKTHDR);
343 #endif
344                         xferq->bulkxfer[i].mbuf = m;
345                         if (m != NULL) {
346                                 m->m_len = m->m_pkthdr.len = m->m_ext.ext_size;
347                                 STAILQ_INSERT_TAIL(&xferq->stfree,
348                                                 &xferq->bulkxfer[i], link);
349                         } else
350                                 printf("fwe_as_input: m_getcl failed\n");
351                 }
352                 STAILQ_INIT(&fwe->xferlist);
353                 for (i = 0; i < TX_MAX_QUEUE; i++) {
354                         xfer = fw_xfer_alloc(M_FWE);
355                         if (xfer == NULL)
356                                 break;
357                         xfer->spd = 2;
358                         xfer->fc = fwe->fd.fc;
359                         xfer->retry_req = fw_asybusy;
360                         xfer->sc = (caddr_t)fwe;
361                         xfer->act.hand = fwe_output_callback;
362                         STAILQ_INSERT_TAIL(&fwe->xferlist, xfer, link);
363                 }
364         } else
365                 xferq = fc->ir[fwe->dma_ch];
366
367
368         /* start dma */
369         if ((xferq->flag & FWXFERQ_RUNNING) == 0)
370                 fc->irx_enable(fc, fwe->dma_ch);
371
372         ifp->if_flags |= IFF_RUNNING;
373         ifp->if_flags &= ~IFF_OACTIVE;
374
375         FWE_POLL_REGISTER(fwe_poll, fwe, ifp);
376 #if 0
377         /* attempt to start output */
378         fwe_start(ifp);
379 #endif
380 }
381
382
383 static int
384 fwe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
385 {
386         struct fwe_softc *fwe = ((struct fwe_eth_softc *)ifp->if_softc)->fwe;
387         struct ifstat *ifs = NULL;
388         int s, error, len;
389
390         switch (cmd) {
391                 case SIOCSIFFLAGS:
392                         s = splimp();
393                         if (ifp->if_flags & IFF_UP) {
394                                 if (!(ifp->if_flags & IFF_RUNNING))
395                                         fwe_init(&fwe->eth_softc);
396                         } else {
397                                 if (ifp->if_flags & IFF_RUNNING)
398                                         fwe_stop(fwe);
399                         }
400                         /* XXX keep promiscoud mode */
401                         ifp->if_flags |= IFF_PROMISC;
402                         splx(s);
403                         break;
404                 case SIOCADDMULTI:
405                 case SIOCDELMULTI:
406                         break;
407
408                 case SIOCGIFSTATUS:
409                         s = splimp();
410                         ifs = (struct ifstat *)data;
411                         len = strlen(ifs->ascii);
412                         if (len < sizeof(ifs->ascii))
413                                 snprintf(ifs->ascii + len,
414                                         sizeof(ifs->ascii) - len,
415                                         "\tch %d dma %d\n",
416                                                 fwe->stream_ch, fwe->dma_ch);
417                         splx(s);
418                         break;
419 #if __FreeBSD_version >= 500000
420                 default:
421 #else
422                 case SIOCSIFADDR:
423                 case SIOCGIFADDR:
424                 case SIOCSIFMTU:
425 #endif
426                         s = splimp();
427                         error = ether_ioctl(ifp, cmd, data);
428                         splx(s);
429                         return (error);
430 #if __FreeBSD_version < 500000
431                 default:
432                         return (EINVAL);
433 #endif
434         }
435
436         return (0);
437 }
438
439 static void
440 fwe_output_callback(struct fw_xfer *xfer)
441 {
442         struct fwe_softc *fwe;
443         struct ifnet *ifp;
444         int s;
445
446         fwe = (struct fwe_softc *)xfer->sc;
447         ifp = &fwe->fwe_if;
448         /* XXX error check */
449         FWEDEBUG("resp = %d\n", xfer->resp);
450         if (xfer->resp != 0)
451                 ifp->if_oerrors ++;
452                 
453         m_freem(xfer->mbuf);
454         xfer->send.buf = NULL;
455         fw_xfer_unload(xfer);
456
457         s = splimp();
458         STAILQ_INSERT_TAIL(&fwe->xferlist, xfer, link);
459         splx(s);
460
461         /* for queue full */
462         if (ifp->if_snd.ifq_head != NULL)
463                 fwe_start(ifp);
464 }
465
466 static void
467 fwe_start(struct ifnet *ifp)
468 {
469         struct fwe_softc *fwe = ((struct fwe_eth_softc *)ifp->if_softc)->fwe;
470         int s;
471
472         FWEDEBUG("%s%d starting\n", ifp->if_name, ifp->if_unit);
473
474         if (fwe->dma_ch < 0) {
475                 struct mbuf     *m = NULL;
476
477                 FWEDEBUG("%s%d not ready.\n", ifp->if_name, ifp->if_unit);
478
479                 s = splimp();
480                 do {
481                         IF_DEQUEUE(&ifp->if_snd, m);
482                         if (m != NULL)
483                                 m_freem(m);
484                         ifp->if_oerrors ++;
485                 } while (m != NULL);
486                 splx(s);
487
488                 return;
489         }
490
491         s = splimp();
492         ifp->if_flags |= IFF_OACTIVE;
493
494         if (ifp->if_snd.ifq_len != 0)
495                 fwe_as_output(fwe, ifp);
496
497         ifp->if_flags &= ~IFF_OACTIVE;
498         splx(s);
499 }
500
501 #define HDR_LEN 4
502 #ifndef ETHER_ALIGN
503 #define ETHER_ALIGN 2
504 #endif
505 /* Async. stream output */
506 static void
507 fwe_as_output(struct fwe_softc *fwe, struct ifnet *ifp)
508 {
509         struct mbuf *m;
510         struct fw_xfer *xfer;
511         struct fw_xferq *xferq;
512         struct fw_pkt *fp;
513         int i = 0;
514
515         xfer = NULL;
516         xferq = fwe->fd.fc->atq;
517         while (xferq->queued < xferq->maxq - 1) {
518                 xfer = STAILQ_FIRST(&fwe->xferlist);
519                 if (xfer == NULL) {
520                         printf("if_fwe: lack of xfer\n");
521                         return;
522                 }
523                 IF_DEQUEUE(&ifp->if_snd, m);
524                 if (m == NULL)
525                         break;
526                 STAILQ_REMOVE_HEAD(&fwe->xferlist, link);
527 #if __FreeBSD_version >= 500000
528                 BPF_MTAP(ifp, m);
529 #else
530                 if (ifp->if_bpf != NULL)
531                         bpf_mtap(ifp, m);
532 #endif
533
534                 /* keep ip packet alignment for alpha */
535                 M_PREPEND(m, ETHER_ALIGN, M_DONTWAIT);
536                 fp = (struct fw_pkt *)&xfer->dst; /* XXX */
537                 xfer->dst = *((int32_t *)&fwe->pkt_hdr);
538                 fp->mode.stream.len = m->m_pkthdr.len;
539                 xfer->send.buf = (caddr_t) fp;
540                 xfer->mbuf = m;
541                 xfer->send.len = m->m_pkthdr.len + HDR_LEN;
542
543                 if (fw_asyreq(fwe->fd.fc, -1, xfer) != 0) {
544                         /* error */
545                         ifp->if_oerrors ++;
546                         /* XXX set error code */
547                         fwe_output_callback(xfer);
548                 } else {
549                         ifp->if_opackets ++;
550                         i++;
551                 }
552         }
553 #if 0
554         if (i > 1)
555                 printf("%d queued\n", i);
556 #endif
557         if (i > 0)
558                 xferq->start(fwe->fd.fc);
559 }
560
561 /* Async. stream output */
562 static void
563 fwe_as_input(struct fw_xferq *xferq)
564 {
565         struct mbuf *m, *m0;
566         struct ifnet *ifp;
567         struct fwe_softc *fwe;
568         struct fw_bulkxfer *sxfer;
569         struct fw_pkt *fp;
570         u_char *c;
571 #if __FreeBSD_version < 500000
572         struct ether_header *eh;
573 #endif
574
575         fwe = (struct fwe_softc *)xferq->sc;
576         ifp = &fwe->fwe_if;
577 #if 0
578         FWE_POLL_REGISTER(fwe_poll, fwe, ifp);
579 #endif
580         while ((sxfer = STAILQ_FIRST(&xferq->stvalid)) != NULL) {
581                 STAILQ_REMOVE_HEAD(&xferq->stvalid, link);
582                 if (sxfer->resp != 0)
583                         ifp->if_ierrors ++;
584                 fp = mtod(sxfer->mbuf, struct fw_pkt *);
585                 /* XXX */
586                 if (fwe->fd.fc->irx_post != NULL)
587                         fwe->fd.fc->irx_post(fwe->fd.fc, fp->mode.ld);
588                 m = sxfer->mbuf;
589
590                 /* insert rbuf */
591                 sxfer->mbuf = m0 = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
592                 if (m0 != NULL) {
593                         m0->m_len = m0->m_pkthdr.len = m0->m_ext.ext_size;
594                         STAILQ_INSERT_TAIL(&xferq->stfree, sxfer, link);
595                 } else
596                         printf("fwe_as_input: m_getcl failed\n");
597
598                 m->m_data += HDR_LEN + ETHER_ALIGN;
599                 c = mtod(m, char *);
600 #if __FreeBSD_version < 500000
601                 eh = (struct ether_header *)c;
602                 m->m_data += sizeof(struct ether_header);
603 #endif
604                 m->m_len = m->m_pkthdr.len =
605                                 fp->mode.stream.len - ETHER_ALIGN;
606                 m->m_pkthdr.rcvif = ifp;
607 #if 0
608                 FWEDEBUG("%02x %02x %02x %02x %02x %02x\n"
609                          "%02x %02x %02x %02x %02x %02x\n"
610                          "%02x %02x %02x %02x\n"
611                          "%02x %02x %02x %02x\n"
612                          "%02x %02x %02x %02x\n"
613                          "%02x %02x %02x %02x\n",
614                          c[0], c[1], c[2], c[3], c[4], c[5],
615                          c[6], c[7], c[8], c[9], c[10], c[11],
616                          c[12], c[13], c[14], c[15],
617                          c[16], c[17], c[18], c[19],
618                          c[20], c[21], c[22], c[23],
619                          c[20], c[21], c[22], c[23]
620                  );
621 #endif
622 #if __FreeBSD_version >= 500000
623                 (*ifp->if_input)(ifp, m);
624 #else
625                 ether_input(ifp, eh, m);
626 #endif
627                 ifp->if_ipackets ++;
628         }
629         if (STAILQ_FIRST(&xferq->stfree) != NULL)
630                 fwe->fd.fc->irx_enable(fwe->fd.fc, fwe->dma_ch);
631 }
632
633
634 static devclass_t fwe_devclass;
635
636 static device_method_t fwe_methods[] = {
637         /* device interface */
638         DEVMETHOD(device_identify,      fwe_identify),
639         DEVMETHOD(device_probe,         fwe_probe),
640         DEVMETHOD(device_attach,        fwe_attach),
641         DEVMETHOD(device_detach,        fwe_detach),
642         { 0, 0 }
643 };
644
645 static driver_t fwe_driver = {
646         "if_fwe",
647         fwe_methods,
648         sizeof(struct fwe_softc),
649 };
650
651
652 DRIVER_MODULE(fwe, firewire, fwe_driver, fwe_devclass, 0, 0);
653 MODULE_VERSION(fwe, 1);
654 MODULE_DEPEND(fwe, firewire, 1, 1, 1);