2 * SPDX-License-Identifier: BSD-4-Clause
6 * Copyright (c) 2002-2003
7 * Hidetoshi Shimokawa. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
20 * This product includes software developed by Hidetoshi Shimokawa.
22 * 4. Neither the name of the author nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #ifdef HAVE_KERNEL_OPTION_HEADERS
42 #include "opt_device_polling.h"
46 #include <sys/param.h>
47 #include <sys/kernel.h>
48 #include <sys/malloc.h>
50 #include <sys/socket.h>
51 #include <sys/sockio.h>
52 #include <sys/sysctl.h>
53 #include <sys/systm.h>
54 #include <sys/taskqueue.h>
55 #include <sys/module.h>
57 #include <machine/bus.h>
61 #include <net/if_var.h>
62 #include <net/firewire.h>
63 #include <net/if_arp.h>
64 #include <net/if_types.h>
65 #include <dev/firewire/firewire.h>
66 #include <dev/firewire/firewirereg.h>
67 #include <dev/firewire/iec13213.h>
68 #include <dev/firewire/if_fwipvar.h>
71 * We really need a mechanism for allocating regions in the FIFO
72 * address space. We pick a address in the OHCI controller's 'middle'
73 * address space. This means that the controller will automatically
74 * send responses for us, which is fine since we don't have any
75 * important information to put in the response anyway.
77 #define INET_FIFO 0xfffe00000000LL
79 #define FWIPDEBUG if (fwipdebug) if_printf
80 #define TX_MAX_QUEUE (FWMAXQUEUE - 1)
82 /* network interface */
83 static void fwip_start (struct ifnet *);
84 static int fwip_ioctl (struct ifnet *, u_long, caddr_t);
85 static void fwip_init (void *);
87 static void fwip_post_busreset (void *);
88 static void fwip_output_callback (struct fw_xfer *);
89 static void fwip_async_output (struct fwip_softc *, struct ifnet *);
90 static void fwip_start_send (void *, int);
91 static void fwip_stream_input (struct fw_xferq *);
92 static void fwip_unicast_input(struct fw_xfer *);
94 static int fwipdebug = 0;
95 static int broadcast_channel = 0xc0 | 0x1f; /* tag | channel(XXX) */
96 static int tx_speed = 2;
97 static int rx_queue_len = FWMAXQUEUE;
99 static MALLOC_DEFINE(M_FWIP, "if_fwip", "IP over FireWire interface");
100 SYSCTL_INT(_debug, OID_AUTO, if_fwip_debug, CTLFLAG_RW, &fwipdebug, 0, "");
101 SYSCTL_DECL(_hw_firewire);
102 static SYSCTL_NODE(_hw_firewire, OID_AUTO, fwip, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
103 "Firewire ip subsystem");
104 SYSCTL_INT(_hw_firewire_fwip, OID_AUTO, rx_queue_len, CTLFLAG_RWTUN, &rx_queue_len,
105 0, "Length of the receive queue");
107 #ifdef DEVICE_POLLING
108 static poll_handler_t fwip_poll;
111 fwip_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
113 struct fwip_softc *fwip;
114 struct firewire_comm *fc;
116 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
119 fwip = ((struct fwip_eth_softc *)ifp->if_softc)->fwip;
121 fc->poll(fc, (cmd == POLL_AND_CHECK_STATUS)?0:1, count);
124 #endif /* DEVICE_POLLING */
127 fwip_identify(driver_t *driver, device_t parent)
129 BUS_ADD_CHILD(parent, 0, "fwip", device_get_unit(parent));
133 fwip_probe(device_t dev)
137 pa = device_get_parent(dev);
138 if (device_get_unit(dev) != device_get_unit(pa)) {
142 device_set_desc(dev, "IP over FireWire");
147 fwip_attach(device_t dev)
149 struct fwip_softc *fwip;
152 struct fw_hwaddr *hwaddr;
154 fwip = ((struct fwip_softc *)device_get_softc(dev));
155 unit = device_get_unit(dev);
156 ifp = fwip->fw_softc.fwip_ifp = if_alloc(IFT_IEEE1394);
160 mtx_init(&fwip->mtx, "fwip", NULL, MTX_DEF);
164 fwip->fd.fc = device_get_ivars(dev);
166 tx_speed = fwip->fd.fc->speed;
169 fwip->fd.post_explore = NULL;
170 fwip->fd.post_busreset = fwip_post_busreset;
171 fwip->fw_softc.fwip = fwip;
172 TASK_INIT(&fwip->start_send, 0, fwip_start_send, fwip);
175 * Encode our hardware the way that arp likes it.
177 hwaddr = &IFP2FWC(fwip->fw_softc.fwip_ifp)->fc_hwaddr;
178 hwaddr->sender_unique_ID_hi = htonl(fwip->fd.fc->eui.hi);
179 hwaddr->sender_unique_ID_lo = htonl(fwip->fd.fc->eui.lo);
180 hwaddr->sender_max_rec = fwip->fd.fc->maxrec;
181 hwaddr->sspd = fwip->fd.fc->speed;
182 hwaddr->sender_unicast_FIFO_hi = htons((uint16_t)(INET_FIFO >> 32));
183 hwaddr->sender_unicast_FIFO_lo = htonl((uint32_t)INET_FIFO);
185 /* fill the rest and attach interface */
186 ifp->if_softc = &fwip->fw_softc;
188 if_initname(ifp, device_get_name(dev), unit);
189 ifp->if_init = fwip_init;
190 ifp->if_start = fwip_start;
191 ifp->if_ioctl = fwip_ioctl;
192 ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
193 ifp->if_snd.ifq_maxlen = TX_MAX_QUEUE;
194 #ifdef DEVICE_POLLING
195 ifp->if_capabilities |= IFCAP_POLLING;
199 firewire_ifattach(ifp, hwaddr);
202 FWIPDEBUG(ifp, "interface created\n");
207 fwip_stop(struct fwip_softc *fwip)
209 struct firewire_comm *fc;
210 struct fw_xferq *xferq;
211 struct ifnet *ifp = fwip->fw_softc.fwip_ifp;
212 struct fw_xfer *xfer, *next;
217 if (fwip->dma_ch >= 0) {
218 xferq = fc->ir[fwip->dma_ch];
220 if (xferq->flag & FWXFERQ_RUNNING)
221 fc->irx_disable(fc, fwip->dma_ch);
223 ~(FWXFERQ_MODEMASK | FWXFERQ_OPEN | FWXFERQ_STREAM |
224 FWXFERQ_EXTBUF | FWXFERQ_HANDLER | FWXFERQ_CHTAGMASK);
227 for (i = 0; i < xferq->bnchunk; i++)
228 m_freem(xferq->bulkxfer[i].mbuf);
229 free(xferq->bulkxfer, M_FWIP);
231 fw_bindremove(fc, &fwip->fwb);
232 for (xfer = STAILQ_FIRST(&fwip->fwb.xferlist); xfer != NULL;
234 next = STAILQ_NEXT(xfer, link);
238 for (xfer = STAILQ_FIRST(&fwip->xferlist); xfer != NULL;
240 next = STAILQ_NEXT(xfer, link);
243 STAILQ_INIT(&fwip->xferlist);
245 xferq->bulkxfer = NULL;
249 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
253 fwip_detach(device_t dev)
255 struct fwip_softc *fwip;
259 fwip = (struct fwip_softc *)device_get_softc(dev);
260 ifp = fwip->fw_softc.fwip_ifp;
262 #ifdef DEVICE_POLLING
263 if (ifp->if_capenable & IFCAP_POLLING)
264 ether_poll_deregister(ifp);
270 firewire_ifdetach(ifp);
272 mtx_destroy(&fwip->mtx);
281 struct fwip_softc *fwip = ((struct fwip_eth_softc *)arg)->fwip;
282 struct firewire_comm *fc;
283 struct ifnet *ifp = fwip->fw_softc.fwip_ifp;
284 struct fw_xferq *xferq;
285 struct fw_xfer *xfer;
289 FWIPDEBUG(ifp, "initializing\n");
293 if (fwip->dma_ch < 0) {
294 fwip->dma_ch = fw_open_isodma(fc, /* tx */0);
295 if (fwip->dma_ch < 0)
297 xferq = fc->ir[fwip->dma_ch];
298 xferq->flag |= FWXFERQ_EXTBUF |
299 FWXFERQ_HANDLER | FWXFERQ_STREAM;
300 xferq->flag &= ~0xff;
301 xferq->flag |= broadcast_channel & 0xff;
302 /* register fwip_input handler */
303 xferq->sc = (caddr_t) fwip;
304 xferq->hand = fwip_stream_input;
305 xferq->bnchunk = rx_queue_len;
307 xferq->psize = MCLBYTES;
310 xferq->bulkxfer = (struct fw_bulkxfer *) malloc(
311 sizeof(struct fw_bulkxfer) * xferq->bnchunk,
313 if (xferq->bulkxfer == NULL) {
314 printf("if_fwip: malloc failed\n");
317 STAILQ_INIT(&xferq->stvalid);
318 STAILQ_INIT(&xferq->stfree);
319 STAILQ_INIT(&xferq->stdma);
320 xferq->stproc = NULL;
321 for (i = 0; i < xferq->bnchunk; i++) {
322 m = m_getcl(M_WAITOK, MT_DATA, M_PKTHDR);
323 xferq->bulkxfer[i].mbuf = m;
324 m->m_len = m->m_pkthdr.len = m->m_ext.ext_size;
325 STAILQ_INSERT_TAIL(&xferq->stfree,
326 &xferq->bulkxfer[i], link);
329 fwip->fwb.start = INET_FIFO;
330 fwip->fwb.end = INET_FIFO + 16384; /* S3200 packet size */
332 /* pre-allocate xfer */
333 STAILQ_INIT(&fwip->fwb.xferlist);
334 for (i = 0; i < rx_queue_len; i++) {
335 xfer = fw_xfer_alloc(M_FWIP);
338 m = m_getcl(M_WAITOK, MT_DATA, M_PKTHDR);
339 xfer->recv.payload = mtod(m, uint32_t *);
340 xfer->recv.pay_len = MCLBYTES;
341 xfer->hand = fwip_unicast_input;
343 xfer->sc = (caddr_t)fwip;
345 STAILQ_INSERT_TAIL(&fwip->fwb.xferlist, xfer, link);
347 fw_bindadd(fc, &fwip->fwb);
349 STAILQ_INIT(&fwip->xferlist);
350 for (i = 0; i < TX_MAX_QUEUE; i++) {
351 xfer = fw_xfer_alloc(M_FWIP);
354 xfer->send.spd = tx_speed;
355 xfer->fc = fwip->fd.fc;
356 xfer->sc = (caddr_t)fwip;
357 xfer->hand = fwip_output_callback;
358 STAILQ_INSERT_TAIL(&fwip->xferlist, xfer, link);
361 xferq = fc->ir[fwip->dma_ch];
363 fwip->last_dest.hi = 0;
364 fwip->last_dest.lo = 0;
367 if ((xferq->flag & FWXFERQ_RUNNING) == 0)
368 fc->irx_enable(fc, fwip->dma_ch);
370 ifp->if_drv_flags |= IFF_DRV_RUNNING;
371 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
374 /* attempt to start output */
380 fwip_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
382 struct fwip_softc *fwip = ((struct fwip_eth_softc *)ifp->if_softc)->fwip;
388 if (ifp->if_flags & IFF_UP) {
389 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
390 fwip_init(&fwip->fw_softc);
392 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
401 #ifdef DEVICE_POLLING
403 struct ifreq *ifr = (struct ifreq *) data;
404 struct firewire_comm *fc = fwip->fd.fc;
406 if (ifr->ifr_reqcap & IFCAP_POLLING &&
407 !(ifp->if_capenable & IFCAP_POLLING)) {
408 error = ether_poll_register(fwip_poll, ifp);
411 /* Disable interrupts */
413 ifp->if_capenable |= IFCAP_POLLING;
416 if (!(ifr->ifr_reqcap & IFCAP_POLLING) &&
417 ifp->if_capenable & IFCAP_POLLING) {
418 error = ether_poll_deregister(ifp);
419 /* Enable interrupts. */
421 ifp->if_capenable &= ~IFCAP_POLLING;
425 #endif /* DEVICE_POLLING */
429 error = firewire_ioctl(ifp, cmd, data);
438 fwip_post_busreset(void *arg)
440 struct fwip_softc *fwip = arg;
441 struct crom_src *src;
442 struct crom_chunk *root;
444 src = fwip->fd.fc->crom_src;
445 root = fwip->fd.fc->crom_root;
447 /* RFC2734 IPv4 over IEEE1394 */
448 bzero(&fwip->unit4, sizeof(struct crom_chunk));
449 crom_add_chunk(src, root, &fwip->unit4, CROM_UDIR);
450 crom_add_entry(&fwip->unit4, CSRKEY_SPEC, CSRVAL_IETF);
451 crom_add_simple_text(src, &fwip->unit4, &fwip->spec4, "IANA");
452 crom_add_entry(&fwip->unit4, CSRKEY_VER, 1);
453 crom_add_simple_text(src, &fwip->unit4, &fwip->ver4, "IPv4");
455 /* RFC3146 IPv6 over IEEE1394 */
456 bzero(&fwip->unit6, sizeof(struct crom_chunk));
457 crom_add_chunk(src, root, &fwip->unit6, CROM_UDIR);
458 crom_add_entry(&fwip->unit6, CSRKEY_SPEC, CSRVAL_IETF);
459 crom_add_simple_text(src, &fwip->unit6, &fwip->spec6, "IANA");
460 crom_add_entry(&fwip->unit6, CSRKEY_VER, 2);
461 crom_add_simple_text(src, &fwip->unit6, &fwip->ver6, "IPv6");
463 fwip->last_dest.hi = 0;
464 fwip->last_dest.lo = 0;
465 firewire_busreset(fwip->fw_softc.fwip_ifp);
469 fwip_output_callback(struct fw_xfer *xfer)
471 struct fwip_softc *fwip;
475 fwip = (struct fwip_softc *)xfer->sc;
476 ifp = fwip->fw_softc.fwip_ifp;
477 /* XXX error check */
478 FWIPDEBUG(ifp, "resp = %d\n", xfer->resp);
480 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
482 fw_xfer_unload(xfer);
486 STAILQ_INSERT_TAIL(&fwip->xferlist, xfer, link);
491 if (ifp->if_snd.ifq_head != NULL) {
497 fwip_start(struct ifnet *ifp)
499 struct fwip_softc *fwip = ((struct fwip_eth_softc *)ifp->if_softc)->fwip;
502 FWIPDEBUG(ifp, "starting\n");
504 if (fwip->dma_ch < 0) {
505 struct mbuf *m = NULL;
507 FWIPDEBUG(ifp, "not ready\n");
511 IF_DEQUEUE(&ifp->if_snd, m);
514 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
522 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
524 if (ifp->if_snd.ifq_len != 0)
525 fwip_async_output(fwip, ifp);
527 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
531 /* Async. stream output */
533 fwip_async_output(struct fwip_softc *fwip, struct ifnet *ifp)
535 struct firewire_comm *fc = fwip->fd.fc;
538 struct fw_hwaddr *destfw;
539 struct fw_xfer *xfer;
540 struct fw_xferq *xferq;
548 while ((xferq->queued < xferq->maxq - 1) &&
549 (ifp->if_snd.ifq_head != NULL)) {
551 xfer = STAILQ_FIRST(&fwip->xferlist);
555 printf("if_fwip: lack of xfer\n");
559 STAILQ_REMOVE_HEAD(&fwip->xferlist, link);
562 IF_DEQUEUE(&ifp->if_snd, m);
565 STAILQ_INSERT_HEAD(&fwip->xferlist, xfer, link);
571 * Dig out the link-level address which
572 * firewire_output got via arp or neighbour
573 * discovery. If we don't have a link-level address,
574 * just stick the thing on the broadcast channel.
576 mtag = m_tag_locate(m, MTAG_FIREWIRE, MTAG_FIREWIRE_HWADDR, 0);
580 destfw = (struct fw_hwaddr *) (mtag + 1);
584 * We don't do any bpf stuff here - the generic code
585 * in firewire_output gives the packet to bpf before
586 * it adds the link-level encapsulation.
590 * Put the mbuf in the xfer early in case we hit an
591 * error case below - fwip_output_callback will free
597 * We use the arp result (if any) to add a suitable firewire
598 * packet header before handing off to the bus.
600 fp = &xfer->send.hdr;
601 nodeid = FWLOCALBUS | fc->nodeid;
602 if ((m->m_flags & M_BCAST) || !destfw) {
604 * Broadcast packets are sent as GASP packets with
605 * specifier ID 0x00005e, version 1 on the broadcast
606 * channel. To be conservative, we send at the
607 * slowest possible speed.
611 M_PREPEND(m, 2*sizeof(uint32_t), M_NOWAIT);
612 p = mtod(m, uint32_t *);
613 fp->mode.stream.len = m->m_pkthdr.len;
614 fp->mode.stream.chtag = broadcast_channel;
615 fp->mode.stream.tcode = FWTCODE_STREAM;
616 fp->mode.stream.sy = 0;
618 p[0] = htonl(nodeid << 16);
619 p[1] = htonl((0x5e << 24) | 1);
622 * Unicast packets are sent as block writes to the
623 * target's unicast fifo address. If we can't
624 * find the node address, we just give up. We
625 * could broadcast it but that might overflow
626 * the packet size limitations due to the
627 * extra GASP header. Note: the hardware
628 * address is stored in network byte order to
629 * make life easier for ARP.
631 struct fw_device *fd;
634 eui.hi = ntohl(destfw->sender_unique_ID_hi);
635 eui.lo = ntohl(destfw->sender_unique_ID_lo);
636 if (fwip->last_dest.hi != eui.hi ||
637 fwip->last_dest.lo != eui.lo) {
638 fd = fw_noderesolve_eui64(fc, &eui);
641 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
642 /* XXX set error code */
643 fwip_output_callback(xfer);
647 fwip->last_hdr.mode.wreqb.dst = FWLOCALBUS | fd->dst;
648 fwip->last_hdr.mode.wreqb.tlrt = 0;
649 fwip->last_hdr.mode.wreqb.tcode = FWTCODE_WREQB;
650 fwip->last_hdr.mode.wreqb.pri = 0;
651 fwip->last_hdr.mode.wreqb.src = nodeid;
652 fwip->last_hdr.mode.wreqb.dest_hi =
653 ntohs(destfw->sender_unicast_FIFO_hi);
654 fwip->last_hdr.mode.wreqb.dest_lo =
655 ntohl(destfw->sender_unicast_FIFO_lo);
656 fwip->last_hdr.mode.wreqb.extcode = 0;
657 fwip->last_dest = eui;
660 fp->mode.wreqb = fwip->last_hdr.mode.wreqb;
661 fp->mode.wreqb.len = m->m_pkthdr.len;
662 xfer->send.spd = min(destfw->sspd, fc->speed);
665 xfer->send.pay_len = m->m_pkthdr.len;
667 error = fw_asyreq(fc, -1, xfer);
668 if (error == EAGAIN) {
670 * We ran out of tlabels - requeue the packet
671 * for later transmission.
675 STAILQ_INSERT_TAIL(&fwip->xferlist, xfer, link);
677 IF_PREPEND(&ifp->if_snd, m);
682 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
683 /* XXX set error code */
684 fwip_output_callback(xfer);
687 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
693 printf("%d queued\n", i);
700 fwip_start_send (void *arg, int count)
702 struct fwip_softc *fwip = arg;
704 fwip->fd.fc->atq->start(fwip->fd.fc);
707 /* Async. stream output */
709 fwip_stream_input(struct fw_xferq *xferq)
711 struct epoch_tracker et;
715 struct fwip_softc *fwip;
716 struct fw_bulkxfer *sxfer;
721 fwip = (struct fwip_softc *)xferq->sc;
722 ifp = fwip->fw_softc.fwip_ifp;
725 while ((sxfer = STAILQ_FIRST(&xferq->stvalid)) != NULL) {
726 STAILQ_REMOVE_HEAD(&xferq->stvalid, link);
727 fp = mtod(sxfer->mbuf, struct fw_pkt *);
728 if (fwip->fd.fc->irx_post != NULL)
729 fwip->fd.fc->irx_post(fwip->fd.fc, fp->mode.ld);
732 /* insert new rbuf */
733 sxfer->mbuf = m0 = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
735 m0->m_len = m0->m_pkthdr.len = m0->m_ext.ext_size;
736 STAILQ_INSERT_TAIL(&xferq->stfree, sxfer, link);
738 printf("fwip_as_input: m_getcl failed\n");
741 * We must have a GASP header - leave the
742 * encapsulation sanity checks to the generic
743 * code. Remember that we also have the firewire async
744 * stream header even though that isn't accounted for
745 * in mode.stream.len.
747 if (sxfer->resp != 0 || fp->mode.stream.len <
748 2*sizeof(uint32_t)) {
750 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
753 m->m_len = m->m_pkthdr.len = fp->mode.stream.len
754 + sizeof(fp->mode.stream);
757 * If we received the packet on the broadcast channel,
758 * mark it as broadcast, otherwise we assume it must
761 if (fp->mode.stream.chtag == broadcast_channel)
762 m->m_flags |= M_BCAST;
764 m->m_flags |= M_MCAST;
767 * Make sure we recognise the GASP specifier and
770 p = mtod(m, uint32_t *);
771 if ((((ntohl(p[1]) & 0xffff) << 8) | ntohl(p[2]) >> 24) != 0x00005e
772 || (ntohl(p[2]) & 0xffffff) != 1) {
773 FWIPDEBUG(ifp, "Unrecognised GASP header %#08x %#08x\n",
774 ntohl(p[1]), ntohl(p[2]));
776 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
781 * Record the sender ID for possible BPF usage.
783 src = ntohl(p[1]) >> 16;
784 if (bpf_peers_present(ifp->if_bpf)) {
785 mtag = m_tag_alloc(MTAG_FIREWIRE,
786 MTAG_FIREWIRE_SENDER_EUID,
787 2*sizeof(uint32_t), M_NOWAIT);
789 /* bpf wants it in network byte order */
790 struct fw_device *fd;
791 uint32_t *p = (uint32_t *) (mtag + 1);
792 fd = fw_noderesolve_nodeid(fwip->fd.fc,
795 p[0] = htonl(fd->eui.hi);
796 p[1] = htonl(fd->eui.lo);
801 m_tag_prepend(m, mtag);
806 * Trim off the GASP header
808 m_adj(m, 3*sizeof(uint32_t));
809 m->m_pkthdr.rcvif = ifp;
810 firewire_input(ifp, m, src);
811 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
814 if (STAILQ_FIRST(&xferq->stfree) != NULL)
815 fwip->fd.fc->irx_enable(fwip->fd.fc, fwip->dma_ch);
819 fwip_unicast_input_recycle(struct fwip_softc *fwip, struct fw_xfer *xfer)
824 * We have finished with a unicast xfer. Allocate a new
825 * cluster and stick it on the back of the input queue.
827 m = m_getcl(M_WAITOK, MT_DATA, M_PKTHDR);
829 xfer->recv.payload = mtod(m, uint32_t *);
830 xfer->recv.pay_len = MCLBYTES;
832 STAILQ_INSERT_TAIL(&fwip->fwb.xferlist, xfer, link);
836 fwip_unicast_input(struct fw_xfer *xfer)
841 struct epoch_tracker et;
843 struct fwip_softc *fwip;
845 //struct fw_pkt *sfp;
848 fwip = (struct fwip_softc *)xfer->sc;
849 ifp = fwip->fw_softc.fwip_ifp;
852 fp = &xfer->recv.hdr;
855 * Check the fifo address - we only accept addresses of
858 address = ((uint64_t)fp->mode.wreqb.dest_hi << 32)
859 | fp->mode.wreqb.dest_lo;
860 if (fp->mode.wreqb.tcode != FWTCODE_WREQB) {
861 rtcode = FWRCODE_ER_TYPE;
862 } else if (address != INET_FIFO) {
863 rtcode = FWRCODE_ER_ADDR;
865 rtcode = FWRCODE_COMPLETE;
870 * Pick up a new mbuf and stick it on the back of the receive
873 fwip_unicast_input_recycle(fwip, xfer);
876 * If we've already rejected the packet, give up now.
878 if (rtcode != FWRCODE_COMPLETE) {
880 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
884 if (bpf_peers_present(ifp->if_bpf)) {
886 * Record the sender ID for possible BPF usage.
888 mtag = m_tag_alloc(MTAG_FIREWIRE, MTAG_FIREWIRE_SENDER_EUID,
889 2*sizeof(uint32_t), M_NOWAIT);
891 /* bpf wants it in network byte order */
892 struct fw_device *fd;
893 uint32_t *p = (uint32_t *) (mtag + 1);
894 fd = fw_noderesolve_nodeid(fwip->fd.fc,
895 fp->mode.wreqb.src & 0x3f);
897 p[0] = htonl(fd->eui.hi);
898 p[1] = htonl(fd->eui.lo);
903 m_tag_prepend(m, mtag);
908 * Hand off to the generic encapsulation code. We don't use
909 * ifp->if_input so that we can pass the source nodeid as an
910 * argument to facilitate link-level fragment reassembly.
912 m->m_len = m->m_pkthdr.len = fp->mode.wreqb.len;
913 m->m_pkthdr.rcvif = ifp;
914 firewire_input(ifp, m, fp->mode.wreqb.src);
915 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
920 static devclass_t fwip_devclass;
922 static device_method_t fwip_methods[] = {
923 /* device interface */
924 DEVMETHOD(device_identify, fwip_identify),
925 DEVMETHOD(device_probe, fwip_probe),
926 DEVMETHOD(device_attach, fwip_attach),
927 DEVMETHOD(device_detach, fwip_detach),
931 static driver_t fwip_driver = {
934 sizeof(struct fwip_softc),
938 DRIVER_MODULE(fwip, firewire, fwip_driver, fwip_devclass, 0, 0);
939 MODULE_VERSION(fwip, 1);
940 MODULE_DEPEND(fwip, firewire, 1, 1, 1);