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