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