if_fwe.c revision 103285
1103285Sikob/* 2103285Sikob * Copyright (C) 2002 3103285Sikob * Hidetoshi Shimokawa. All rights reserved. 4103285Sikob * 5103285Sikob * Redistribution and use in source and binary forms, with or without 6103285Sikob * modification, are permitted provided that the following conditions 7103285Sikob * are met: 8103285Sikob * 1. Redistributions of source code must retain the above copyright 9103285Sikob * notice, this list of conditions and the following disclaimer. 10103285Sikob * 2. Redistributions in binary form must reproduce the above copyright 11103285Sikob * notice, this list of conditions and the following disclaimer in the 12103285Sikob * documentation and/or other materials provided with the distribution. 13103285Sikob * 3. All advertising materials mentioning features or use of this software 14103285Sikob * must display the following acknowledgement: 15103285Sikob * 16103285Sikob * This product includes software developed by Hidetoshi Shimokawa. 17103285Sikob * 18103285Sikob * 4. Neither the name of the author nor the names of its contributors 19103285Sikob * may be used to endorse or promote products derived from this software 20103285Sikob * without specific prior written permission. 21103285Sikob * 22103285Sikob * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23103285Sikob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24103285Sikob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25103285Sikob * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26103285Sikob * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27103285Sikob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28103285Sikob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29103285Sikob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30103285Sikob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31103285Sikob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32103285Sikob * SUCH DAMAGE. 33103285Sikob * 34103285Sikob * $FreeBSD: head/sys/dev/firewire/if_fwe.c 103285 2002-09-13 12:31:56Z ikob $ 35103285Sikob */ 36103285Sikob 37103285Sikob#include "opt_inet.h" 38103285Sikob 39103285Sikob#include <sys/param.h> 40103285Sikob#include <sys/conf.h> 41103285Sikob#include <sys/kernel.h> 42103285Sikob#include <sys/malloc.h> 43103285Sikob#include <sys/mbuf.h> 44103285Sikob#include <sys/socket.h> 45103285Sikob#include <sys/sockio.h> 46103285Sikob#include <sys/sysctl.h> 47103285Sikob#include <sys/systm.h> 48103285Sikob#include <sys/module.h> 49103285Sikob#include <sys/bus.h> 50103285Sikob 51103285Sikob#include <net/bpf.h> 52103285Sikob#include <net/ethernet.h> 53103285Sikob#include <net/if.h> 54103285Sikob#include <net/if_arp.h> 55103285Sikob#include <net/if_vlan_var.h> 56103285Sikob#include <net/route.h> 57103285Sikob 58103285Sikob#include <netinet/in.h> 59103285Sikob 60103285Sikob#include <dev/firewire/firewire.h> 61103285Sikob#include <dev/firewire/firewirereg.h> 62103285Sikob#include <dev/firewire/if_fwevar.h> 63103285Sikob 64103285Sikob#define FWEDEBUG if (fwedebug) printf 65103285Sikob#define MAX_QUEUED IFQ_MAXLEN /* 50 */ 66103285Sikob 67103285Sikob/* network interface */ 68103285Sikobstatic void fwe_start __P((struct ifnet *)); 69103285Sikobstatic int fwe_ioctl __P((struct ifnet *, u_long, caddr_t)); 70103285Sikobstatic void fwe_init __P((void *)); 71103285Sikob 72103285Sikobstatic void fwe_as_output __P((struct fwe_softc *, struct ifnet *)); 73103285Sikobstatic void fwe_as_input __P((struct fw_xferq *)); 74103285Sikob 75103285Sikobstatic int fwedebug = 0; 76103285Sikobstatic int stream_ch = 1; 77103285Sikob 78103285SikobMALLOC_DECLARE(M_FWE); 79103285SikobMALLOC_DEFINE(M_FWE, "if_fwe", "Ethernet over Firewire interface"); 80103285SikobSYSCTL_INT(_debug, OID_AUTO, if_fwe_debug, CTLFLAG_RW, &fwedebug, 0, ""); 81103285SikobSYSCTL_DECL(_hw_firewire); 82103285SikobSYSCTL_NODE(_hw_firewire, OID_AUTO, fwe, CTLFLAG_RD, 0, 83103285Sikob "Ethernet Emulation Subsystem"); 84103285SikobSYSCTL_INT(_hw_firewire_fwe, OID_AUTO, stream_ch, CTLFLAG_RW, &stream_ch, 0, 85103285Sikob "Stream channel to use"); 86103285Sikob 87103285Sikob#ifdef DEVICE_POLLING 88103285Sikob#define FWE_POLL_REGISTER(func, fwe, ifp) \ 89103285Sikob if (ether_poll_register(func, ifp)) { \ 90103285Sikob struct firewire_comm *fc = (fwe)->fd.fc; \ 91103285Sikob fc->set_intr(fc, 0); \ 92103285Sikob } 93103285Sikob 94103285Sikob#define FWE_POLL_DEREGISTER(fwe, ifp) \ 95103285Sikob do { \ 96103285Sikob struct firewire_comm *fc = (fwe)->fd.fc; \ 97103285Sikob ether_poll_deregister(ifp); \ 98103285Sikob fc->set_intr(fc, 1); \ 99103285Sikob } while(0) \ 100103285Sikob 101103285Sikobstatic poll_handler_t fwe_poll; 102103285Sikob 103103285Sikobstatic void 104103285Sikobfwe_poll(struct ifnet *ifp, enum poll_cmd cmd, int count) 105103285Sikob{ 106103285Sikob struct fwe_softc *fwe; 107103285Sikob struct firewire_comm *fc; 108103285Sikob 109103285Sikob fwe = ((struct fwe_eth_softc *)ifp->if_softc)->fwe; 110103285Sikob fc = fwe->fd.fc; 111103285Sikob if (cmd == POLL_DEREGISTER) { 112103285Sikob /* enable interrupts */ 113103285Sikob fc->set_intr(fc, 1); 114103285Sikob return; 115103285Sikob } 116103285Sikob fc->poll(fc, (cmd == POLL_AND_CHECK_STATUS)?0:1, count); 117103285Sikob} 118103285Sikob#else 119103285Sikob#define FWE_POLL_REGISTER(func, fwe, ifp) 120103285Sikob#define FWE_POLL_DEREGISTER(fwe, ifp) 121103285Sikob#endif 122103285Sikobstatic void 123103285Sikobfwe_identify(driver_t *driver, device_t parent) 124103285Sikob{ 125103285Sikob BUS_ADD_CHILD(parent, 0, "if_fwe", device_get_unit(parent)); 126103285Sikob} 127103285Sikob 128103285Sikobstatic int 129103285Sikobfwe_probe(device_t dev) 130103285Sikob{ 131103285Sikob device_t pa; 132103285Sikob 133103285Sikob pa = device_get_parent(dev); 134103285Sikob if(device_get_unit(dev) != device_get_unit(pa)){ 135103285Sikob return(ENXIO); 136103285Sikob } 137103285Sikob 138103285Sikob device_set_desc(dev, "Ethernet over Firewire"); 139103285Sikob return (0); 140103285Sikob} 141103285Sikob 142103285Sikobstatic int 143103285Sikobfwe_attach(device_t dev) 144103285Sikob{ 145103285Sikob struct fwe_softc *fwe; 146103285Sikob struct ifnet *ifp; 147103285Sikob int unit, s; 148103285Sikob u_char *eaddr; 149103285Sikob 150103285Sikob fwe = ((struct fwe_softc *)device_get_softc(dev)); 151103285Sikob unit = device_get_unit(dev); 152103285Sikob 153103285Sikob bzero(fwe, sizeof(struct fwe_softc)); 154103285Sikob /* XXX */ 155103285Sikob fwe->stream_ch = stream_ch; 156103285Sikob fwe->dma_ch = -1; 157103285Sikob 158103285Sikob fwe->fd.fc = device_get_ivars(dev); 159103285Sikob fwe->fd.dev = dev; 160103285Sikob fwe->fd.post_explore = NULL; 161103285Sikob fwe->eth_softc.fwe = fwe; 162103285Sikob 163103285Sikob fwe->pkt_hdr.mode.stream.tcode = FWTCODE_STREAM; 164103285Sikob fwe->pkt_hdr.mode.stream.sy = 0; 165103285Sikob fwe->pkt_hdr.mode.stream.chtag = fwe->stream_ch; 166103285Sikob 167103285Sikob /* generate fake MAC address: first and last 3bytes from eui64 */ 168103285Sikob#define LOCAL (0x02) 169103285Sikob#define GROUP (0x01) 170103285Sikob eaddr = &fwe->eth_softc.arpcom.ac_enaddr[0]; 171103285Sikob eaddr[0] = (fwe->fd.fc->eui[0] | LOCAL) & ~GROUP; 172103285Sikob eaddr[1] = fwe->fd.fc->eui[1]; 173103285Sikob eaddr[2] = fwe->fd.fc->eui[2]; 174103285Sikob eaddr[3] = fwe->fd.fc->eui[5]; 175103285Sikob eaddr[4] = fwe->fd.fc->eui[6]; 176103285Sikob eaddr[5] = fwe->fd.fc->eui[7]; 177103285Sikob printf("if_fwe%d: %02x:%02x:%02x:%02x:%02x:%02x\n", unit, 178103285Sikob eaddr[0], eaddr[1], eaddr[2], eaddr[3], eaddr[4], eaddr[5]); 179103285Sikob 180103285Sikob /* fill the rest and attach interface */ 181103285Sikob ifp = &fwe->fwe_if; 182103285Sikob ifp->if_softc = &fwe->eth_softc; 183103285Sikob 184103285Sikob ifp->if_unit = unit; 185103285Sikob ifp->if_name = "fwe"; 186103285Sikob ifp->if_init = fwe_init; 187103285Sikob ifp->if_output = ether_output; 188103285Sikob ifp->if_start = fwe_start; 189103285Sikob ifp->if_ioctl = fwe_ioctl; 190103285Sikob ifp->if_mtu = ETHERMTU; 191103285Sikob ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST); 192103285Sikob ifp->if_snd.ifq_maxlen = FWMAXQUEUE - 1; 193103285Sikob 194103285Sikob s = splimp(); 195103285Sikob ether_ifattach(ifp, 1); 196103285Sikob splx(s); 197103285Sikob 198103285Sikob /* Tell the upper layer(s) we support long frames. */ 199103285Sikob ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); 200103285Sikob 201103285Sikob ifp->if_snd.ifq_maxlen = MAX_QUEUED - 1; 202103285Sikob 203103285Sikob FWEDEBUG("interface %s%d created.\n", ifp->if_name, ifp->if_unit); 204103285Sikob return 0; 205103285Sikob} 206103285Sikob 207103285Sikobstatic void 208103285Sikobfwe_stop(struct fwe_softc *fwe) 209103285Sikob{ 210103285Sikob struct firewire_comm *fc; 211103285Sikob struct fw_xferq *xferq; 212103285Sikob struct ifnet *ifp = &fwe->fwe_if; 213103285Sikob 214103285Sikob fc = fwe->fd.fc; 215103285Sikob 216103285Sikob FWE_POLL_DEREGISTER(fwe, ifp); 217103285Sikob 218103285Sikob if (fwe->dma_ch >= 0) { 219103285Sikob xferq = fc->ir[fwe->dma_ch]; 220103285Sikob 221103285Sikob if (xferq->flag & FWXFERQ_RUNNING) 222103285Sikob fc->irx_disable(fc, fwe->dma_ch); 223103285Sikob xferq->flag &= 224103285Sikob ~(FWXFERQ_MODEMASK | FWXFERQ_OPEN | FWXFERQ_HANDLER); 225103285Sikob /* XXX dequeue xferq->q */ 226103285Sikob fwe->dma_ch = -1; 227103285Sikob } 228103285Sikob 229103285Sikob ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); 230103285Sikob} 231103285Sikob 232103285Sikobstatic int 233103285Sikobfwe_detach(device_t dev) 234103285Sikob{ 235103285Sikob struct fwe_softc *fwe; 236103285Sikob int s; 237103285Sikob 238103285Sikob fwe = (struct fwe_softc *)device_get_softc(dev); 239103285Sikob s = splimp(); 240103285Sikob 241103285Sikob fwe_stop(fwe); 242103285Sikob ether_ifdetach(&fwe->fwe_if, 1); 243103285Sikob 244103285Sikob splx(s); 245103285Sikob return 0; 246103285Sikob} 247103285Sikob 248103285Sikob 249103285Sikobstatic void 250103285Sikobfwe_init(void *arg) 251103285Sikob{ 252103285Sikob struct fwe_softc *fwe = ((struct fwe_eth_softc *)arg)->fwe; 253103285Sikob struct firewire_comm *fc; 254103285Sikob struct ifnet *ifp = &fwe->fwe_if; 255103285Sikob struct fw_xferq *xferq; 256103285Sikob int i; 257103285Sikob 258103285Sikob FWEDEBUG("initializing %s%d\n", ifp->if_name, ifp->if_unit); 259103285Sikob 260103285Sikob /* XXX keep promiscoud mode */ 261103285Sikob ifp->if_flags |= IFF_PROMISC; 262103285Sikob 263103285Sikob fc = fwe->fd.fc; 264103285Sikob#define START 0 265103285Sikob if (fwe->dma_ch < 0) { 266103285Sikob xferq = NULL; 267103285Sikob for (i = START; i < fc->nisodma; i ++) { 268103285Sikob xferq = fc->ir[i]; 269103285Sikob if ((xferq->flag & FWXFERQ_OPEN) == 0) 270103285Sikob break; 271103285Sikob } 272103285Sikob 273103285Sikob if (xferq == NULL) { 274103285Sikob printf("no free dma channel\n"); 275103285Sikob return; 276103285Sikob } 277103285Sikob fwe->dma_ch = i; 278103285Sikob fwe->stream_ch = stream_ch; 279103285Sikob fwe->pkt_hdr.mode.stream.chtag = fwe->stream_ch; 280103285Sikob /* allocate DMA channel and init packet mode */ 281103285Sikob xferq->flag |= FWXFERQ_OPEN | FWXFERQ_PACKET; 282103285Sikob xferq->flag |= fwe->stream_ch & 0xff; 283103285Sikob /* register fwe_input handler */ 284103285Sikob xferq->sc = (caddr_t) fwe; 285103285Sikob xferq->hand = fwe_as_input; 286103285Sikob xferq->flag |= FWXFERQ_HANDLER; 287103285Sikob } else 288103285Sikob xferq = fc->ir[fwe->dma_ch]; 289103285Sikob 290103285Sikob 291103285Sikob /* start dma */ 292103285Sikob if ((xferq->flag & FWXFERQ_RUNNING) == 0) 293103285Sikob fc->irx_enable(fc, fwe->dma_ch); 294103285Sikob 295103285Sikob ifp->if_flags |= IFF_RUNNING; 296103285Sikob ifp->if_flags &= ~IFF_OACTIVE; 297103285Sikob 298103285Sikob FWE_POLL_REGISTER(fwe_poll, fwe, ifp); 299103285Sikob#if 0 300103285Sikob /* attempt to start output */ 301103285Sikob fwe_start(ifp); 302103285Sikob#endif 303103285Sikob} 304103285Sikob 305103285Sikob 306103285Sikobstatic int 307103285Sikobfwe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) 308103285Sikob{ 309103285Sikob struct fwe_softc *fwe = ((struct fwe_eth_softc *)ifp->if_softc)->fwe; 310103285Sikob struct ifstat *ifs = NULL; 311103285Sikob int s, error, len; 312103285Sikob 313103285Sikob switch (cmd) { 314103285Sikob case SIOCSIFADDR: 315103285Sikob case SIOCGIFADDR: 316103285Sikob case SIOCSIFMTU: 317103285Sikob s = splimp(); 318103285Sikob error = ether_ioctl(ifp, cmd, data); 319103285Sikob splx(s); 320103285Sikob return (error); 321103285Sikob case SIOCSIFFLAGS: 322103285Sikob s = splimp(); 323103285Sikob if (ifp->if_flags & IFF_UP) { 324103285Sikob if (!(ifp->if_flags & IFF_RUNNING)) 325103285Sikob fwe_init(&fwe->eth_softc); 326103285Sikob } else { 327103285Sikob if (ifp->if_flags & IFF_RUNNING) 328103285Sikob fwe_stop(fwe); 329103285Sikob } 330103285Sikob /* XXX keep promiscoud mode */ 331103285Sikob ifp->if_flags |= IFF_PROMISC; 332103285Sikob splx(s); 333103285Sikob break; 334103285Sikob case SIOCADDMULTI: 335103285Sikob case SIOCDELMULTI: 336103285Sikob break; 337103285Sikob 338103285Sikob case SIOCGIFSTATUS: 339103285Sikob s = splimp(); 340103285Sikob ifs = (struct ifstat *)data; 341103285Sikob len = strlen(ifs->ascii); 342103285Sikob if (len < sizeof(ifs->ascii)) 343103285Sikob snprintf(ifs->ascii + len, 344103285Sikob sizeof(ifs->ascii) - len, 345103285Sikob "\tch %d dma %d\n", 346103285Sikob fwe->stream_ch, fwe->dma_ch); 347103285Sikob splx(s); 348103285Sikob break; 349103285Sikob 350103285Sikob default: 351103285Sikob return (EINVAL); 352103285Sikob } 353103285Sikob 354103285Sikob return (0); 355103285Sikob} 356103285Sikob 357103285Sikobstatic void 358103285Sikobfwe_start(struct ifnet *ifp) 359103285Sikob{ 360103285Sikob struct fwe_softc *fwe = ((struct fwe_eth_softc *)ifp->if_softc)->fwe; 361103285Sikob int s; 362103285Sikob 363103285Sikob#if 1 364103285Sikob FWEDEBUG("%s%d starting\n", ifp->if_name, ifp->if_unit); 365103285Sikob 366103285Sikob if (fwe->dma_ch < 0) { 367103285Sikob struct mbuf *m = NULL; 368103285Sikob 369103285Sikob FWEDEBUG("%s%d not ready.\n", ifp->if_name, ifp->if_unit); 370103285Sikob 371103285Sikob s = splimp(); 372103285Sikob do { 373103285Sikob IF_DEQUEUE(&ifp->if_snd, m); 374103285Sikob if (m != NULL) 375103285Sikob m_freem(m); 376103285Sikob ifp->if_oerrors ++; 377103285Sikob } while (m != NULL); 378103285Sikob splx(s); 379103285Sikob 380103285Sikob return; 381103285Sikob } 382103285Sikob 383103285Sikob#endif 384103285Sikob s = splimp(); 385103285Sikob ifp->if_flags |= IFF_OACTIVE; 386103285Sikob 387103285Sikob if (ifp->if_snd.ifq_len != 0) 388103285Sikob fwe_as_output(fwe, ifp); 389103285Sikob 390103285Sikob ifp->if_flags &= ~IFF_OACTIVE; 391103285Sikob splx(s); 392103285Sikob} 393103285Sikob 394103285Sikob 395103285Sikobstatic void 396103285Sikobfwe_output_callback(struct fw_xfer *xfer) 397103285Sikob{ 398103285Sikob struct fwe_softc *fwe; 399103285Sikob struct ifnet *ifp; 400103285Sikob 401103285Sikob fwe = (struct fwe_softc *)xfer->sc; 402103285Sikob /* XXX error check */ 403103285Sikob FWEDEBUG("resp = %d\n", xfer->resp); 404103285Sikob m_freem(xfer->mbuf); 405103285Sikob xfer->send.buf = NULL; 406103285Sikob fw_xfer_free(xfer); 407103285Sikob#if 1 408103285Sikob /* XXX for queue full */ 409103285Sikob ifp = &fwe->fwe_if; 410103285Sikob if (ifp->if_snd.ifq_head != NULL) 411103285Sikob fwe_start(ifp); 412103285Sikob#endif 413103285Sikob} 414103285Sikob 415103285Sikob#define HDR_LEN 4 416103285Sikob#define ALIGN_PAD 2 417103285Sikob/* Async. stream output */ 418103285Sikobstatic void 419103285Sikobfwe_as_output(struct fwe_softc *fwe, struct ifnet *ifp) 420103285Sikob{ 421103285Sikob struct mbuf *m; 422103285Sikob struct fw_xfer *xfer; 423103285Sikob struct fw_xferq *xferq; 424103285Sikob struct fw_pkt *fp; 425103285Sikob int i = 0; 426103285Sikob 427103285Sikob xfer = NULL; 428103285Sikob xferq = fwe->fd.fc->atq; 429103285Sikob while (xferq->queued < xferq->maxq) { 430103285Sikob IF_DEQUEUE(&ifp->if_snd, m); 431103285Sikob if (m == NULL) 432103285Sikob break; 433103285Sikob xfer = fw_xfer_alloc(); 434103285Sikob if (xfer == NULL) { 435103285Sikob return; 436103285Sikob } 437103285Sikob if (ifp->if_bpf != NULL) 438103285Sikob bpf_mtap(ifp, m); 439103285Sikob 440103285Sikob xfer->send.off = 0; 441103285Sikob xfer->spd = 2; 442103285Sikob xfer->fc = fwe->fd.fc; 443103285Sikob xfer->retry_req = fw_asybusy; 444103285Sikob xfer->sc = (caddr_t)fwe; 445103285Sikob xfer->act.hand = fwe_output_callback; 446103285Sikob 447103285Sikob /* keep ip packet alignment for alpha */ 448103285Sikob M_PREPEND(m, ALIGN_PAD, M_DONTWAIT); 449103285Sikob fp = (struct fw_pkt *)&xfer->dst; /* XXX */ 450103285Sikob xfer->dst = *((int32_t *)&fwe->pkt_hdr); 451103285Sikob fp->mode.stream.len = htons(m->m_pkthdr.len); 452103285Sikob xfer->send.buf = (caddr_t) fp; 453103285Sikob xfer->mbuf = m; 454103285Sikob xfer->send.len = m->m_pkthdr.len + HDR_LEN; 455103285Sikob 456103285Sikob i++; 457103285Sikob if (fw_asyreq(xfer->fc, -1, xfer) != 0) { 458103285Sikob /* error */ 459103285Sikob ifp->if_oerrors ++; 460103285Sikob /* XXX set error code */ 461103285Sikob fwe_output_callback(xfer); 462103285Sikob } else { 463103285Sikob ifp->if_opackets ++; 464103285Sikob } 465103285Sikob } 466103285Sikob#if 0 467103285Sikob if (i > 1) 468103285Sikob printf("%d queued\n", i); 469103285Sikob#endif 470103285Sikob if (xfer != NULL) 471103285Sikob xferq->start(xfer->fc); 472103285Sikob} 473103285Sikob 474103285Sikob#if __FreeBSD_version >= 500000 475103285Sikobstatic void 476103285Sikobfwe_free(void *buf, void *args) 477103285Sikob{ 478103285Sikob FWEDEBUG("fwe_free:\n"); 479103285Sikob free(buf, M_DEVBUF); 480103285Sikob} 481103285Sikob 482103285Sikob#else 483103285Sikobstatic void 484103285Sikobfwe_free(caddr_t buf, u_int size) 485103285Sikob{ 486103285Sikob int *p; 487103285Sikob FWEDEBUG("fwe_free:\n"); 488103285Sikob p = (int *)buf; 489103285Sikob (*p) --; 490103285Sikob if (*p < 1) 491103285Sikob free(buf, M_DEVBUF); 492103285Sikob} 493103285Sikob 494103285Sikobstatic void 495103285Sikobfwe_ref(caddr_t buf, u_int size) 496103285Sikob{ 497103285Sikob int *p; 498103285Sikob 499103285Sikob FWEDEBUG("fwe_ref: called\n"); 500103285Sikob p = (int *)buf; 501103285Sikob (*p) ++; 502103285Sikob} 503103285Sikob#endif 504103285Sikob 505103285Sikob/* Async. stream output */ 506103285Sikobstatic void 507103285Sikobfwe_as_input(struct fw_xferq *xferq) 508103285Sikob{ 509103285Sikob struct mbuf *m; 510103285Sikob struct ether_header *eh; 511103285Sikob struct ifnet *ifp; 512103285Sikob struct fw_xfer *xfer; 513103285Sikob struct fwe_softc *fwe; 514103285Sikob u_char *c; 515103285Sikob int len; 516103285Sikob caddr_t p; 517103285Sikob 518103285Sikob fwe = (struct fwe_softc *)xferq->sc; 519103285Sikob ifp = &fwe->fwe_if; 520103285Sikob#if 0 521103285Sikob FWE_POLL_REGISTER(fwe_poll, fwe, ifp); 522103285Sikob#endif 523103285Sikob while ((xfer = STAILQ_FIRST(&xferq->q)) != NULL) { 524103285Sikob STAILQ_REMOVE_HEAD(&xferq->q, link); 525103285Sikob xferq->queued --; 526103285Sikob MGETHDR(m, M_DONTWAIT, MT_DATA); 527103285Sikob if (m == NULL) { 528103285Sikob printf("MGETHDR failed\n"); 529103285Sikob fw_xfer_free(xfer); 530103285Sikob return; 531103285Sikob } 532103285Sikob len = xfer->recv.off + xfer->recv.len; 533103285Sikob FWEDEBUG("fwe_as_input len=%d\n", len); 534103285Sikob#if __FreeBSD_version >= 500000 535103285Sikob MEXTADD(m, xfer->recv.buf, len, fwe_free, NULL, 0, EXT_NET_DRV); 536103285Sikob#else 537103285Sikob m->m_flags |= M_EXT; 538103285Sikob m->m_ext.ext_buf = xfer->recv.buf; 539103285Sikob m->m_ext.ext_size = len; 540103285Sikob m->m_ext.ext_free = fwe_free; 541103285Sikob m->m_ext.ext_ref = fwe_ref; 542103285Sikob *((int *)m->m_ext.ext_buf) = 1; /* XXX refcount */ 543103285Sikob#endif 544103285Sikob p = xfer->recv.buf + xfer->recv.off + HDR_LEN + ALIGN_PAD; 545103285Sikob eh = (struct ether_header *)p; 546103285Sikob p += sizeof(struct ether_header); 547103285Sikob len -= xfer->recv.off + HDR_LEN + ALIGN_PAD 548103285Sikob + sizeof(struct ether_header); 549103285Sikob m->m_data = p; 550103285Sikob m->m_len = m->m_pkthdr.len = len; 551103285Sikob m->m_pkthdr.rcvif = ifp; 552103285Sikob c = (char *)eh; 553103285Sikob#if 0 554103285Sikob FWEDEBUG("%02x %02x %02x %02x %02x %02x\n" 555103285Sikob "%02x %02x %02x %02x %02x %02x\n" 556103285Sikob "%02x %02x %02x %02x\n" 557103285Sikob "%02x %02x %02x %02x\n" 558103285Sikob "%02x %02x %02x %02x\n" 559103285Sikob "%02x %02x %02x %02x\n", 560103285Sikob c[0], c[1], c[2], c[3], c[4], c[5], 561103285Sikob c[6], c[7], c[8], c[9], c[10], c[11], 562103285Sikob c[12], c[13], c[14], c[15], 563103285Sikob c[16], c[17], c[18], c[19], 564103285Sikob c[20], c[21], c[22], c[23], 565103285Sikob c[20], c[21], c[22], c[23] 566103285Sikob ); 567103285Sikob#endif 568103285Sikob ether_input(ifp, eh, m); 569103285Sikob ifp->if_ipackets ++; 570103285Sikob 571103285Sikob xfer->recv.buf = NULL; 572103285Sikob fw_xfer_free(xfer); 573103285Sikob } 574103285Sikob} 575103285Sikob 576103285Sikob 577103285Sikobstatic devclass_t fwe_devclass; 578103285Sikob 579103285Sikobstatic device_method_t fwe_methods[] = { 580103285Sikob /* device interface */ 581103285Sikob DEVMETHOD(device_identify, fwe_identify), 582103285Sikob DEVMETHOD(device_probe, fwe_probe), 583103285Sikob DEVMETHOD(device_attach, fwe_attach), 584103285Sikob DEVMETHOD(device_detach, fwe_detach), 585103285Sikob { 0, 0 } 586103285Sikob}; 587103285Sikob 588103285Sikobstatic driver_t fwe_driver = { 589103285Sikob "if_fwe", 590103285Sikob fwe_methods, 591103285Sikob sizeof(struct fwe_softc), 592103285Sikob}; 593103285Sikob 594103285Sikob 595103285SikobDRIVER_MODULE(if_fwe, firewire, fwe_driver, fwe_devclass, 0, 0); 596103285SikobMODULE_VERSION(if_fwe, 1); 597103285SikobMODULE_DEPEND(if_fwe, firewire, 1, 1, 1); 598