4 * Copyright (c) 2002-2003
5 * Hidetoshi Shimokawa. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
18 * This product includes software developed by Hidetoshi Shimokawa.
20 * 4. Neither the name of the author nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #ifdef HAVE_KERNEL_OPTION_HEADERS
40 #include "opt_device_polling.h"
44 #include <sys/param.h>
45 #include <sys/kernel.h>
46 #include <sys/malloc.h>
48 #include <sys/socket.h>
49 #include <sys/sockio.h>
50 #include <sys/sysctl.h>
51 #include <sys/systm.h>
52 #include <sys/taskqueue.h>
53 #include <sys/module.h>
55 #include <machine/bus.h>
59 #include <net/firewire.h>
60 #include <net/if_arp.h>
61 #include <net/if_types.h>
63 #include <bus/firewire/firewire.h>
64 #include <bus/firewire/firewirereg.h>
65 #include "if_fwipvar.h"
67 #include <dev/firewire/firewire.h>
68 #include <dev/firewire/firewirereg.h>
69 #include <dev/firewire/iec13213.h>
70 #include <dev/firewire/if_fwipvar.h>
74 * We really need a mechanism for allocating regions in the FIFO
75 * address space. We pick a address in the OHCI controller's 'middle'
76 * address space. This means that the controller will automatically
77 * send responses for us, which is fine since we don't have any
78 * important information to put in the response anyway.
80 #define INET_FIFO 0xfffe00000000LL
82 #define FWIPDEBUG if (fwipdebug) if_printf
83 #define TX_MAX_QUEUE (FWMAXQUEUE - 1)
85 /* network interface */
86 static void fwip_start (struct ifnet *);
87 static int fwip_ioctl (struct ifnet *, u_long, caddr_t);
88 static void fwip_init (void *);
90 static void fwip_post_busreset (void *);
91 static void fwip_output_callback (struct fw_xfer *);
92 static void fwip_async_output (struct fwip_softc *, struct ifnet *);
93 static void fwip_start_send (void *, int);
94 static void fwip_stream_input (struct fw_xferq *);
95 static void fwip_unicast_input(struct fw_xfer *);
97 static int fwipdebug = 0;
98 static int broadcast_channel = 0xc0 | 0x1f; /* tag | channel(XXX) */
99 static int tx_speed = 2;
100 static int rx_queue_len = FWMAXQUEUE;
102 MALLOC_DEFINE(M_FWIP, "if_fwip", "IP over FireWire interface");
103 SYSCTL_INT(_debug, OID_AUTO, if_fwip_debug, CTLFLAG_RW, &fwipdebug, 0, "");
104 SYSCTL_DECL(_hw_firewire);
105 SYSCTL_NODE(_hw_firewire, OID_AUTO, fwip, CTLFLAG_RD, 0,
106 "Firewire ip subsystem");
107 SYSCTL_INT(_hw_firewire_fwip, OID_AUTO, rx_queue_len, CTLFLAG_RW, &rx_queue_len,
108 0, "Length of the receive queue");
110 TUNABLE_INT("hw.firewire.fwip.rx_queue_len", &rx_queue_len);
112 #ifdef DEVICE_POLLING
113 static poll_handler_t fwip_poll;
116 fwip_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
118 struct fwip_softc *fwip;
119 struct firewire_comm *fc;
121 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
124 fwip = ((struct fwip_eth_softc *)ifp->if_softc)->fwip;
126 fc->poll(fc, (cmd == POLL_AND_CHECK_STATUS)?0:1, count);
129 #endif /* DEVICE_POLLING */
132 fwip_identify(driver_t *driver, device_t parent)
134 BUS_ADD_CHILD(parent, 0, "fwip", device_get_unit(parent));
138 fwip_probe(device_t dev)
142 pa = device_get_parent(dev);
143 if(device_get_unit(dev) != device_get_unit(pa)){
147 device_set_desc(dev, "IP over FireWire");
152 fwip_attach(device_t dev)
154 struct fwip_softc *fwip;
157 struct fw_hwaddr *hwaddr;
159 fwip = ((struct fwip_softc *)device_get_softc(dev));
160 unit = device_get_unit(dev);
161 ifp = fwip->fw_softc.fwip_ifp = if_alloc(IFT_IEEE1394);
165 mtx_init(&fwip->mtx, "fwip", NULL, MTX_DEF);
169 fwip->fd.fc = device_get_ivars(dev);
171 tx_speed = fwip->fd.fc->speed;
174 fwip->fd.post_explore = NULL;
175 fwip->fd.post_busreset = fwip_post_busreset;
176 fwip->fw_softc.fwip = fwip;
177 TASK_INIT(&fwip->start_send, 0, fwip_start_send, fwip);
180 * Encode our hardware the way that arp likes it.
182 hwaddr = &IFP2FWC(fwip->fw_softc.fwip_ifp)->fc_hwaddr;
183 hwaddr->sender_unique_ID_hi = htonl(fwip->fd.fc->eui.hi);
184 hwaddr->sender_unique_ID_lo = htonl(fwip->fd.fc->eui.lo);
185 hwaddr->sender_max_rec = fwip->fd.fc->maxrec;
186 hwaddr->sspd = fwip->fd.fc->speed;
187 hwaddr->sender_unicast_FIFO_hi = htons((uint16_t)(INET_FIFO >> 32));
188 hwaddr->sender_unicast_FIFO_lo = htonl((uint32_t)INET_FIFO);
190 /* fill the rest and attach interface */
191 ifp->if_softc = &fwip->fw_softc;
193 #if __FreeBSD_version >= 501113 || defined(__DragonFly__)
194 if_initname(ifp, device_get_name(dev), unit);
197 ifp->if_name = "fwip";
199 ifp->if_init = fwip_init;
200 ifp->if_start = fwip_start;
201 ifp->if_ioctl = fwip_ioctl;
202 ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
203 ifp->if_snd.ifq_maxlen = TX_MAX_QUEUE;
204 #ifdef DEVICE_POLLING
205 ifp->if_capabilities |= IFCAP_POLLING;
209 firewire_ifattach(ifp, hwaddr);
212 FWIPDEBUG(ifp, "interface created\n");
217 fwip_stop(struct fwip_softc *fwip)
219 struct firewire_comm *fc;
220 struct fw_xferq *xferq;
221 struct ifnet *ifp = fwip->fw_softc.fwip_ifp;
222 struct fw_xfer *xfer, *next;
227 if (fwip->dma_ch >= 0) {
228 xferq = fc->ir[fwip->dma_ch];
230 if (xferq->flag & FWXFERQ_RUNNING)
231 fc->irx_disable(fc, fwip->dma_ch);
233 ~(FWXFERQ_MODEMASK | FWXFERQ_OPEN | FWXFERQ_STREAM |
234 FWXFERQ_EXTBUF | FWXFERQ_HANDLER | FWXFERQ_CHTAGMASK);
237 for (i = 0; i < xferq->bnchunk; i ++)
238 m_freem(xferq->bulkxfer[i].mbuf);
239 free(xferq->bulkxfer, M_FWIP);
241 fw_bindremove(fc, &fwip->fwb);
242 for (xfer = STAILQ_FIRST(&fwip->fwb.xferlist); xfer != NULL;
244 next = STAILQ_NEXT(xfer, link);
248 for (xfer = STAILQ_FIRST(&fwip->xferlist); xfer != NULL;
250 next = STAILQ_NEXT(xfer, link);
253 STAILQ_INIT(&fwip->xferlist);
255 xferq->bulkxfer = NULL;
259 #if defined(__FreeBSD__)
260 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
262 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
267 fwip_detach(device_t dev)
269 struct fwip_softc *fwip;
273 fwip = (struct fwip_softc *)device_get_softc(dev);
274 ifp = fwip->fw_softc.fwip_ifp;
276 #ifdef DEVICE_POLLING
277 if (ifp->if_capenable & IFCAP_POLLING)
278 ether_poll_deregister(ifp);
284 firewire_ifdetach(ifp);
286 mtx_destroy(&fwip->mtx);
295 struct fwip_softc *fwip = ((struct fwip_eth_softc *)arg)->fwip;
296 struct firewire_comm *fc;
297 struct ifnet *ifp = fwip->fw_softc.fwip_ifp;
298 struct fw_xferq *xferq;
299 struct fw_xfer *xfer;
303 FWIPDEBUG(ifp, "initializing\n");
307 if (fwip->dma_ch < 0) {
308 fwip->dma_ch = fw_open_isodma(fc, /* tx */0);
309 if (fwip->dma_ch < 0)
311 xferq = fc->ir[fwip->dma_ch];
312 xferq->flag |= FWXFERQ_EXTBUF |
313 FWXFERQ_HANDLER | FWXFERQ_STREAM;
314 xferq->flag &= ~0xff;
315 xferq->flag |= broadcast_channel & 0xff;
316 /* register fwip_input handler */
317 xferq->sc = (caddr_t) fwip;
318 xferq->hand = fwip_stream_input;
319 xferq->bnchunk = rx_queue_len;
321 xferq->psize = MCLBYTES;
324 xferq->bulkxfer = (struct fw_bulkxfer *) malloc(
325 sizeof(struct fw_bulkxfer) * xferq->bnchunk,
327 if (xferq->bulkxfer == NULL) {
328 printf("if_fwip: malloc failed\n");
331 STAILQ_INIT(&xferq->stvalid);
332 STAILQ_INIT(&xferq->stfree);
333 STAILQ_INIT(&xferq->stdma);
334 xferq->stproc = NULL;
335 for (i = 0; i < xferq->bnchunk; i ++) {
336 m = m_getcl(M_WAIT, MT_DATA, M_PKTHDR);
337 xferq->bulkxfer[i].mbuf = m;
338 m->m_len = m->m_pkthdr.len = m->m_ext.ext_size;
339 STAILQ_INSERT_TAIL(&xferq->stfree,
340 &xferq->bulkxfer[i], link);
343 fwip->fwb.start = INET_FIFO;
344 fwip->fwb.end = INET_FIFO + 16384; /* S3200 packet size */
346 /* pre-allocate xfer */
347 STAILQ_INIT(&fwip->fwb.xferlist);
348 for (i = 0; i < rx_queue_len; i ++) {
349 xfer = fw_xfer_alloc(M_FWIP);
352 m = m_getcl(M_WAIT, MT_DATA, M_PKTHDR);
353 xfer->recv.payload = mtod(m, uint32_t *);
354 xfer->recv.pay_len = MCLBYTES;
355 xfer->hand = fwip_unicast_input;
357 xfer->sc = (caddr_t)fwip;
359 STAILQ_INSERT_TAIL(&fwip->fwb.xferlist, xfer, link);
361 fw_bindadd(fc, &fwip->fwb);
363 STAILQ_INIT(&fwip->xferlist);
364 for (i = 0; i < TX_MAX_QUEUE; i++) {
365 xfer = fw_xfer_alloc(M_FWIP);
368 xfer->send.spd = tx_speed;
369 xfer->fc = fwip->fd.fc;
370 xfer->sc = (caddr_t)fwip;
371 xfer->hand = fwip_output_callback;
372 STAILQ_INSERT_TAIL(&fwip->xferlist, xfer, link);
375 xferq = fc->ir[fwip->dma_ch];
377 fwip->last_dest.hi = 0;
378 fwip->last_dest.lo = 0;
381 if ((xferq->flag & FWXFERQ_RUNNING) == 0)
382 fc->irx_enable(fc, fwip->dma_ch);
384 #if defined(__FreeBSD__)
385 ifp->if_drv_flags |= IFF_DRV_RUNNING;
386 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
388 ifp->if_flags |= IFF_RUNNING;
389 ifp->if_flags &= ~IFF_OACTIVE;
393 /* attempt to start output */
399 fwip_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
401 struct fwip_softc *fwip = ((struct fwip_eth_softc *)ifp->if_softc)->fwip;
407 if (ifp->if_flags & IFF_UP) {
408 #if defined(__FreeBSD__)
409 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
411 if (!(ifp->if_flags & IFF_RUNNING))
413 fwip_init(&fwip->fw_softc);
415 #if defined(__FreeBSD__)
416 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
418 if (ifp->if_flags & IFF_RUNNING)
428 #ifdef DEVICE_POLLING
430 struct ifreq *ifr = (struct ifreq *) data;
431 struct firewire_comm *fc = fwip->fd.fc;
433 if (ifr->ifr_reqcap & IFCAP_POLLING &&
434 !(ifp->if_capenable & IFCAP_POLLING)) {
435 error = ether_poll_register(fwip_poll, ifp);
438 /* Disable interrupts */
440 ifp->if_capenable |= IFCAP_POLLING |
441 IFCAP_POLLING_NOCOUNT;
445 if (!(ifr->ifr_reqcap & IFCAP_POLLING) &&
446 ifp->if_capenable & IFCAP_POLLING) {
447 error = ether_poll_deregister(ifp);
448 /* Enable interrupts. */
450 ifp->if_capenable &= ~IFCAP_POLLING;
451 ifp->if_capenable &= ~IFCAP_POLLING_NOCOUNT;
455 #endif /* DEVICE_POLLING */
457 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
465 error = firewire_ioctl(ifp, cmd, data);
468 #if defined(__DragonFly__) || __FreeBSD_version < 500000
478 fwip_post_busreset(void *arg)
480 struct fwip_softc *fwip = arg;
481 struct crom_src *src;
482 struct crom_chunk *root;
484 src = fwip->fd.fc->crom_src;
485 root = fwip->fd.fc->crom_root;
487 /* RFC2734 IPv4 over IEEE1394 */
488 bzero(&fwip->unit4, sizeof(struct crom_chunk));
489 crom_add_chunk(src, root, &fwip->unit4, CROM_UDIR);
490 crom_add_entry(&fwip->unit4, CSRKEY_SPEC, CSRVAL_IETF);
491 crom_add_simple_text(src, &fwip->unit4, &fwip->spec4, "IANA");
492 crom_add_entry(&fwip->unit4, CSRKEY_VER, 1);
493 crom_add_simple_text(src, &fwip->unit4, &fwip->ver4, "IPv4");
495 /* RFC3146 IPv6 over IEEE1394 */
496 bzero(&fwip->unit6, sizeof(struct crom_chunk));
497 crom_add_chunk(src, root, &fwip->unit6, CROM_UDIR);
498 crom_add_entry(&fwip->unit6, CSRKEY_SPEC, CSRVAL_IETF);
499 crom_add_simple_text(src, &fwip->unit6, &fwip->spec6, "IANA");
500 crom_add_entry(&fwip->unit6, CSRKEY_VER, 2);
501 crom_add_simple_text(src, &fwip->unit6, &fwip->ver6, "IPv6");
503 fwip->last_dest.hi = 0;
504 fwip->last_dest.lo = 0;
505 firewire_busreset(fwip->fw_softc.fwip_ifp);
509 fwip_output_callback(struct fw_xfer *xfer)
511 struct fwip_softc *fwip;
515 fwip = (struct fwip_softc *)xfer->sc;
516 ifp = fwip->fw_softc.fwip_ifp;
517 /* XXX error check */
518 FWIPDEBUG(ifp, "resp = %d\n", xfer->resp);
523 fw_xfer_unload(xfer);
527 STAILQ_INSERT_TAIL(&fwip->xferlist, xfer, link);
532 if (ifp->if_snd.ifq_head != NULL) {
538 fwip_start(struct ifnet *ifp)
540 struct fwip_softc *fwip = ((struct fwip_eth_softc *)ifp->if_softc)->fwip;
543 FWIPDEBUG(ifp, "starting\n");
545 if (fwip->dma_ch < 0) {
546 struct mbuf *m = NULL;
548 FWIPDEBUG(ifp, "not ready\n");
552 IF_DEQUEUE(&ifp->if_snd, m);
563 #if defined(__FreeBSD__)
564 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
566 ifp->if_flags |= IFF_OACTIVE;
569 if (ifp->if_snd.ifq_len != 0)
570 fwip_async_output(fwip, ifp);
572 #if defined(__FreeBSD__)
573 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
575 ifp->if_flags &= ~IFF_OACTIVE;
580 /* Async. stream output */
582 fwip_async_output(struct fwip_softc *fwip, struct ifnet *ifp)
584 struct firewire_comm *fc = fwip->fd.fc;
587 struct fw_hwaddr *destfw;
588 struct fw_xfer *xfer;
589 struct fw_xferq *xferq;
597 while ((xferq->queued < xferq->maxq - 1) &&
598 (ifp->if_snd.ifq_head != NULL)) {
600 xfer = STAILQ_FIRST(&fwip->xferlist);
604 printf("if_fwip: lack of xfer\n");
608 STAILQ_REMOVE_HEAD(&fwip->xferlist, link);
611 IF_DEQUEUE(&ifp->if_snd, m);
614 STAILQ_INSERT_HEAD(&fwip->xferlist, xfer, link);
620 * Dig out the link-level address which
621 * firewire_output got via arp or neighbour
622 * discovery. If we don't have a link-level address,
623 * just stick the thing on the broadcast channel.
625 mtag = m_tag_locate(m, MTAG_FIREWIRE, MTAG_FIREWIRE_HWADDR, 0);
629 destfw = (struct fw_hwaddr *) (mtag + 1);
633 * We don't do any bpf stuff here - the generic code
634 * in firewire_output gives the packet to bpf before
635 * it adds the link-level encapsulation.
639 * Put the mbuf in the xfer early in case we hit an
640 * error case below - fwip_output_callback will free
646 * We use the arp result (if any) to add a suitable firewire
647 * packet header before handing off to the bus.
649 fp = &xfer->send.hdr;
650 nodeid = FWLOCALBUS | fc->nodeid;
651 if ((m->m_flags & M_BCAST) || !destfw) {
653 * Broadcast packets are sent as GASP packets with
654 * specifier ID 0x00005e, version 1 on the broadcast
655 * channel. To be conservative, we send at the
656 * slowest possible speed.
660 M_PREPEND(m, 2*sizeof(uint32_t), M_DONTWAIT);
661 p = mtod(m, uint32_t *);
662 fp->mode.stream.len = m->m_pkthdr.len;
663 fp->mode.stream.chtag = broadcast_channel;
664 fp->mode.stream.tcode = FWTCODE_STREAM;
665 fp->mode.stream.sy = 0;
667 p[0] = htonl(nodeid << 16);
668 p[1] = htonl((0x5e << 24) | 1);
671 * Unicast packets are sent as block writes to the
672 * target's unicast fifo address. If we can't
673 * find the node address, we just give up. We
674 * could broadcast it but that might overflow
675 * the packet size limitations due to the
676 * extra GASP header. Note: the hardware
677 * address is stored in network byte order to
678 * make life easier for ARP.
680 struct fw_device *fd;
683 eui.hi = ntohl(destfw->sender_unique_ID_hi);
684 eui.lo = ntohl(destfw->sender_unique_ID_lo);
685 if (fwip->last_dest.hi != eui.hi ||
686 fwip->last_dest.lo != eui.lo) {
687 fd = fw_noderesolve_eui64(fc, &eui);
691 /* XXX set error code */
692 fwip_output_callback(xfer);
696 fwip->last_hdr.mode.wreqb.dst = FWLOCALBUS | fd->dst;
697 fwip->last_hdr.mode.wreqb.tlrt = 0;
698 fwip->last_hdr.mode.wreqb.tcode = FWTCODE_WREQB;
699 fwip->last_hdr.mode.wreqb.pri = 0;
700 fwip->last_hdr.mode.wreqb.src = nodeid;
701 fwip->last_hdr.mode.wreqb.dest_hi =
702 ntohs(destfw->sender_unicast_FIFO_hi);
703 fwip->last_hdr.mode.wreqb.dest_lo =
704 ntohl(destfw->sender_unicast_FIFO_lo);
705 fwip->last_hdr.mode.wreqb.extcode = 0;
706 fwip->last_dest = eui;
709 fp->mode.wreqb = fwip->last_hdr.mode.wreqb;
710 fp->mode.wreqb.len = m->m_pkthdr.len;
711 xfer->send.spd = min(destfw->sspd, fc->speed);
714 xfer->send.pay_len = m->m_pkthdr.len;
716 error = fw_asyreq(fc, -1, xfer);
717 if (error == EAGAIN) {
719 * We ran out of tlabels - requeue the packet
720 * for later transmission.
724 STAILQ_INSERT_TAIL(&fwip->xferlist, xfer, link);
726 IF_PREPEND(&ifp->if_snd, m);
732 /* XXX set error code */
733 fwip_output_callback(xfer);
742 printf("%d queued\n", i);
749 fwip_start_send (void *arg, int count)
751 struct fwip_softc *fwip = arg;
753 fwip->fd.fc->atq->start(fwip->fd.fc);
756 /* Async. stream output */
758 fwip_stream_input(struct fw_xferq *xferq)
763 struct fwip_softc *fwip;
764 struct fw_bulkxfer *sxfer;
770 fwip = (struct fwip_softc *)xferq->sc;
771 ifp = fwip->fw_softc.fwip_ifp;
773 while ((sxfer = STAILQ_FIRST(&xferq->stvalid)) != NULL) {
774 STAILQ_REMOVE_HEAD(&xferq->stvalid, link);
775 fp = mtod(sxfer->mbuf, struct fw_pkt *);
776 if (fwip->fd.fc->irx_post != NULL)
777 fwip->fd.fc->irx_post(fwip->fd.fc, fp->mode.ld);
780 /* insert new rbuf */
781 sxfer->mbuf = m0 = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
783 m0->m_len = m0->m_pkthdr.len = m0->m_ext.ext_size;
784 STAILQ_INSERT_TAIL(&xferq->stfree, sxfer, link);
786 printf("fwip_as_input: m_getcl failed\n");
789 * We must have a GASP header - leave the
790 * encapsulation sanity checks to the generic
791 * code. Remeber that we also have the firewire async
792 * stream header even though that isn't accounted for
793 * in mode.stream.len.
795 if (sxfer->resp != 0 || fp->mode.stream.len <
796 2*sizeof(uint32_t)) {
801 m->m_len = m->m_pkthdr.len = fp->mode.stream.len
802 + sizeof(fp->mode.stream);
805 * If we received the packet on the broadcast channel,
806 * mark it as broadcast, otherwise we assume it must
809 if (fp->mode.stream.chtag == broadcast_channel)
810 m->m_flags |= M_BCAST;
812 m->m_flags |= M_MCAST;
815 * Make sure we recognise the GASP specifier and
818 p = mtod(m, uint32_t *);
819 if ((((ntohl(p[1]) & 0xffff) << 8) | ntohl(p[2]) >> 24) != 0x00005e
820 || (ntohl(p[2]) & 0xffffff) != 1) {
821 FWIPDEBUG(ifp, "Unrecognised GASP header %#08x %#08x\n",
822 ntohl(p[1]), ntohl(p[2]));
829 * Record the sender ID for possible BPF usage.
831 src = ntohl(p[1]) >> 16;
832 if (bpf_peers_present(ifp->if_bpf)) {
833 mtag = m_tag_alloc(MTAG_FIREWIRE,
834 MTAG_FIREWIRE_SENDER_EUID,
835 2*sizeof(uint32_t), M_NOWAIT);
837 /* bpf wants it in network byte order */
838 struct fw_device *fd;
839 uint32_t *p = (uint32_t *) (mtag + 1);
840 fd = fw_noderesolve_nodeid(fwip->fd.fc,
843 p[0] = htonl(fd->eui.hi);
844 p[1] = htonl(fd->eui.lo);
849 m_tag_prepend(m, mtag);
854 * Trim off the GASP header
856 m_adj(m, 3*sizeof(uint32_t));
857 m->m_pkthdr.rcvif = ifp;
858 firewire_input(ifp, m, src);
861 if (STAILQ_FIRST(&xferq->stfree) != NULL)
862 fwip->fd.fc->irx_enable(fwip->fd.fc, fwip->dma_ch);
866 fwip_unicast_input_recycle(struct fwip_softc *fwip, struct fw_xfer *xfer)
871 * We have finished with a unicast xfer. Allocate a new
872 * cluster and stick it on the back of the input queue.
874 m = m_getcl(M_WAIT, MT_DATA, M_PKTHDR);
876 xfer->recv.payload = mtod(m, uint32_t *);
877 xfer->recv.pay_len = MCLBYTES;
879 STAILQ_INSERT_TAIL(&fwip->fwb.xferlist, xfer, link);
883 fwip_unicast_input(struct fw_xfer *xfer)
889 struct fwip_softc *fwip;
891 //struct fw_pkt *sfp;
894 fwip = (struct fwip_softc *)xfer->sc;
895 ifp = fwip->fw_softc.fwip_ifp;
898 fp = &xfer->recv.hdr;
901 * Check the fifo address - we only accept addresses of
904 address = ((uint64_t)fp->mode.wreqb.dest_hi << 32)
905 | fp->mode.wreqb.dest_lo;
906 if (fp->mode.wreqb.tcode != FWTCODE_WREQB) {
907 rtcode = FWRCODE_ER_TYPE;
908 } else if (address != INET_FIFO) {
909 rtcode = FWRCODE_ER_ADDR;
911 rtcode = FWRCODE_COMPLETE;
915 * Pick up a new mbuf and stick it on the back of the receive
918 fwip_unicast_input_recycle(fwip, xfer);
921 * If we've already rejected the packet, give up now.
923 if (rtcode != FWRCODE_COMPLETE) {
929 if (bpf_peers_present(ifp->if_bpf)) {
931 * Record the sender ID for possible BPF usage.
933 mtag = m_tag_alloc(MTAG_FIREWIRE, MTAG_FIREWIRE_SENDER_EUID,
934 2*sizeof(uint32_t), M_NOWAIT);
936 /* bpf wants it in network byte order */
937 struct fw_device *fd;
938 uint32_t *p = (uint32_t *) (mtag + 1);
939 fd = fw_noderesolve_nodeid(fwip->fd.fc,
940 fp->mode.wreqb.src & 0x3f);
942 p[0] = htonl(fd->eui.hi);
943 p[1] = htonl(fd->eui.lo);
948 m_tag_prepend(m, mtag);
953 * Hand off to the generic encapsulation code. We don't use
954 * ifp->if_input so that we can pass the source nodeid as an
955 * argument to facilitate link-level fragment reassembly.
957 m->m_len = m->m_pkthdr.len = fp->mode.wreqb.len;
958 m->m_pkthdr.rcvif = ifp;
959 firewire_input(ifp, m, fp->mode.wreqb.src);
963 static devclass_t fwip_devclass;
965 static device_method_t fwip_methods[] = {
966 /* device interface */
967 DEVMETHOD(device_identify, fwip_identify),
968 DEVMETHOD(device_probe, fwip_probe),
969 DEVMETHOD(device_attach, fwip_attach),
970 DEVMETHOD(device_detach, fwip_detach),
974 static driver_t fwip_driver = {
977 sizeof(struct fwip_softc),
982 DECLARE_DUMMY_MODULE(fwip);
984 DRIVER_MODULE(fwip, firewire, fwip_driver, fwip_devclass, 0, 0);
985 MODULE_VERSION(fwip, 1);
986 MODULE_DEPEND(fwip, firewire, 1, 1, 1);