firewire.c revision 106543
1103285Sikob/* 2103285Sikob * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa 3103285Sikob * 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 acknowledgement as bellow: 15103285Sikob * 16103285Sikob * This product includes software developed by K. Kobayashi and H. Shimokawa 17103285Sikob * 18103285Sikob * 4. The name of the author may not be used to endorse or promote products 19103285Sikob * derived from this software without specific prior written permission. 20103285Sikob * 21103285Sikob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22103285Sikob * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23103285Sikob * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24103285Sikob * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25103285Sikob * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26103285Sikob * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27103285Sikob * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28103285Sikob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29103285Sikob * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30103285Sikob * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31103285Sikob * POSSIBILITY OF SUCH DAMAGE. 32103285Sikob * 33103285Sikob * $FreeBSD: head/sys/dev/firewire/firewire.c 106543 2002-11-07 02:13:40Z simokawa $ 34103285Sikob * 35103285Sikob */ 36103285Sikob 37103285Sikob#include <sys/param.h> 38103285Sikob#include <sys/systm.h> 39103285Sikob#include <sys/types.h> 40103285Sikob#include <sys/mbuf.h> 41103285Sikob#include <sys/socket.h> 42103285Sikob#include <sys/socketvar.h> 43103285Sikob 44103285Sikob#include <sys/kernel.h> 45103285Sikob#include <sys/malloc.h> 46103285Sikob#include <sys/conf.h> 47103285Sikob#include <sys/uio.h> 48103285Sikob#include <sys/sysctl.h> 49103285Sikob#include <sys/poll.h> 50103285Sikob 51103285Sikob#include <machine/cpufunc.h> /* for rdtsc proto for clock.h below */ 52103285Sikob#include <machine/clock.h> 53103285Sikob#include <pci/pcivar.h> 54103285Sikob#include <pci/pcireg.h> 55103285Sikob 56103285Sikob#include <vm/vm.h> 57103285Sikob#include <vm/pmap.h> /* for vtophys proto */ 58103285Sikob#include <vm/vm_extern.h> 59103285Sikob 60103285Sikob#include <sys/bus.h> /* used by smbus and newbus */ 61103285Sikob 62103285Sikob#include <machine/bus.h> /* used by newbus */ 63103285Sikob#include <sys/rman.h> /* used by newbus */ 64103285Sikob#include <machine/resource.h> /* used by newbus */ 65103285Sikob 66103285Sikob#include <sys/signal.h> 67103285Sikob#include <sys/mman.h> 68103285Sikob#include <sys/ioccom.h> 69103285Sikob 70103285Sikob#include <dev/firewire/firewire.h> 71103285Sikob#include <dev/firewire/firewirereg.h> 72103285Sikob#include <dev/firewire/fwmem.h> 73103285Sikob#include <dev/firewire/iec13213.h> 74103285Sikob#include <dev/firewire/iec68113.h> 75103285Sikob 76103285Sikobint firewire_debug=0; 77103285SikobSYSCTL_NODE(_hw, OID_AUTO, firewire, CTLFLAG_RD, 0, "Firewire Subsystem"); 78103285SikobSYSCTL_INT(_debug, OID_AUTO, firewire_debug, CTLFLAG_RW, &firewire_debug, 0, 79103285Sikob "Firewire driver debug flag"); 80103285Sikob 81103285Sikob#define CDEV_MAJOR 127 82103285Sikob#define FW_MAXASYRTY 4 83103285Sikob#define FW_MAXDEVRCNT 4 84103285Sikob#define FWNODE_INVAL 0xffff 85103285Sikob 86103285Sikob#define XFER_TIMEOUT 0 87103285Sikob 88103285Sikobstatic d_open_t fw_open; 89103285Sikobstatic d_close_t fw_close; 90103285Sikobstatic d_ioctl_t fw_ioctl; 91103285Sikobstatic d_poll_t fw_poll; 92103285Sikobstatic d_read_t fw_read; /* for Isochronous packet */ 93103285Sikobstatic d_write_t fw_write; 94103285Sikobstatic d_mmap_t fw_mmap; 95103285Sikob 96103285Sikobdevclass_t firewire_devclass; 97103285Sikob 98103285Sikob 99103285Sikobstatic int firewire_match __P((device_t)); 100103285Sikobstatic int firewire_attach __P((device_t)); 101103285Sikobstatic int firewire_detach __P((device_t)); 102103285Sikob#if 0 103103285Sikobstatic int firewire_shutdown __P((device_t)); 104103285Sikob#endif 105103285Sikobstatic device_t firewire_add_child __P((device_t, int, const char *, int)); 106103285Sikobstatic struct fw_bind *fw_bindlookup __P((struct firewire_comm *, u_int32_t, u_int32_t)); 107103285Sikobstatic void fw_try_bmr __P((void *)); 108103285Sikobstatic void fw_try_bmr_callback __P((struct fw_xfer *)); 109103285Sikobstatic u_int16_t fw_noderesolve __P((struct firewire_comm *, struct fw_eui64)); 110103285Sikobstatic void fw_asystart __P((struct fw_xfer *)); 111103285Sikobstatic int fw_get_tlabel __P((struct firewire_comm *, struct fw_xfer *)); 112103285Sikobstatic void fw_bus_probe __P((struct firewire_comm *)); 113103285Sikobstatic void fw_bus_explore __P((struct firewire_comm *)); 114103285Sikobstatic void fw_bus_explore_callback __P((struct fw_xfer *)); 115103285Sikobstatic void fw_attach_dev __P((struct firewire_comm *)); 116106543Ssimokawa#ifdef FW_VMACCESS 117103285Sikobstatic void fw_vmaccess __P((struct fw_xfer *)); 118106543Ssimokawa#endif 119103285Sikobstruct fw_xfer *asyreqq __P((struct firewire_comm *, u_int8_t, u_int8_t, u_int8_t, 120105620Ssimokawa u_int32_t, u_int32_t, void (*)__P((struct fw_xfer *)))); 121103285Sikob 122103285Sikobstatic device_method_t firewire_methods[] = { 123103285Sikob /* Device interface */ 124103285Sikob DEVMETHOD(device_probe, firewire_match), 125103285Sikob DEVMETHOD(device_attach, firewire_attach), 126103285Sikob DEVMETHOD(device_detach, firewire_detach), 127103285Sikob DEVMETHOD(device_shutdown, bus_generic_shutdown), 128103285Sikob 129103285Sikob /* Bus interface */ 130103285Sikob DEVMETHOD(bus_add_child, firewire_add_child), 131103285Sikob DEVMETHOD(bus_print_child, bus_generic_print_child), 132103285Sikob 133103285Sikob { 0, 0 } 134103285Sikob}; 135103285Sikobchar linkspeed[7][0x10]={"S100","S200","S400","S800","S1600","S3200","Unknown"}; 136103285Sikobu_int maxrec[6]={512,1024,2048,4096,8192,0}; 137103285Sikob 138103285Sikob#define MAX_GAPHOP 16 139103285Sikobu_int gap_cnt[] = {1, 1, 4, 6, 9, 12, 14, 17, 140103285Sikob 20, 23, 25, 28, 31, 33, 36, 39, 42}; 141103285Sikob/* 142103285Sikob * The probe routine. 143103285Sikob */ 144103285Sikobstruct cdevsw firewire_cdevsw = 145103285Sikob{ 146103285Sikob fw_open, fw_close, fw_read, fw_write, fw_ioctl, 147103285Sikob fw_poll, fw_mmap, nostrategy, "fw", CDEV_MAJOR, nodump, nopsize, D_MEM 148103285Sikob}; 149103285Sikobstatic driver_t firewire_driver = { 150103285Sikob "firewire", 151103285Sikob firewire_methods, 152103285Sikob sizeof(struct firewire_softc), 153103285Sikob}; 154103285Sikob 155103285Sikobstatic int 156103285Sikobfw_open (dev_t dev, int flags, int fmt, fw_proc *td) 157103285Sikob{ 158103285Sikob struct firewire_softc *sc; 159103285Sikob int unit = DEV2UNIT(dev); 160103285Sikob int sub = DEV2DMACH(dev); 161103285Sikob 162103285Sikob int err = 0; 163103285Sikob 164103285Sikob if (DEV_FWMEM(dev)) 165103285Sikob return fwmem_open(dev, flags, fmt, td); 166103285Sikob 167103285Sikob sc = devclass_get_softc(firewire_devclass, unit); 168103285Sikob if(sc->fc->ir[sub]->flag & FWXFERQ_OPEN){ 169103285Sikob err = EBUSY; 170103285Sikob return err; 171103285Sikob } 172103285Sikob if(sc->fc->it[sub]->flag & FWXFERQ_OPEN){ 173103285Sikob err = EBUSY; 174103285Sikob return err; 175103285Sikob } 176103285Sikob if(sc->fc->ir[sub]->flag & FWXFERQ_MODEMASK){ 177103285Sikob err = EBUSY; 178103285Sikob return err; 179103285Sikob } 180103285Sikob/* Default is per packet mode */ 181103285Sikob sc->fc->ir[sub]->flag |= FWXFERQ_OPEN; 182103285Sikob sc->fc->it[sub]->flag |= FWXFERQ_OPEN; 183103285Sikob sc->fc->ir[sub]->flag |= FWXFERQ_PACKET; 184103285Sikob return err; 185103285Sikob} 186103285Sikobstatic int 187103285Sikobfw_close (dev_t dev, int flags, int fmt, fw_proc *td) 188103285Sikob{ 189103285Sikob struct firewire_softc *sc; 190103285Sikob int unit = DEV2UNIT(dev); 191103285Sikob int sub = DEV2DMACH(dev); 192103285Sikob struct fw_xfer *xfer; 193103285Sikob struct fw_dvbuf *dvbuf; 194103285Sikob struct fw_bind *fwb; 195103285Sikob int err = 0; 196103285Sikob 197103285Sikob if (DEV_FWMEM(dev)) 198103285Sikob return fwmem_close(dev, flags, fmt, td); 199103285Sikob 200103285Sikob sc = devclass_get_softc(firewire_devclass, unit); 201103285Sikob if(!(sc->fc->ir[sub]->flag & FWXFERQ_OPEN)){ 202103285Sikob err = EINVAL; 203103285Sikob return err; 204103285Sikob } 205103285Sikob sc->fc->ir[sub]->flag &= ~FWXFERQ_OPEN; 206103285Sikob if(!(sc->fc->it[sub]->flag & FWXFERQ_OPEN)){ 207103285Sikob err = EINVAL; 208103285Sikob return err; 209103285Sikob } 210103285Sikob sc->fc->it[sub]->flag &= ~FWXFERQ_OPEN; 211103285Sikob 212103285Sikob if(sc->fc->ir[sub]->flag & FWXFERQ_RUNNING){ 213103285Sikob sc->fc->irx_disable(sc->fc, sub); 214103285Sikob } 215103285Sikob if(sc->fc->it[sub]->flag & FWXFERQ_RUNNING){ 216103285Sikob sc->fc->it[sub]->flag &= ~FWXFERQ_RUNNING; 217103285Sikob sc->fc->itx_disable(sc->fc, sub); 218103285Sikob } 219103285Sikob if(sc->fc->it[sub]->flag & FWXFERQ_DV){ 220103285Sikob if((dvbuf = sc->fc->it[sub]->dvproc) != NULL){ 221103285Sikob free(dvbuf->buf, M_DEVBUF); 222103285Sikob sc->fc->it[sub]->dvproc = NULL; 223103285Sikob } 224103285Sikob if((dvbuf = sc->fc->it[sub]->dvdma) != NULL){ 225103285Sikob free(dvbuf->buf, M_DEVBUF); 226103285Sikob sc->fc->it[sub]->dvdma = NULL; 227103285Sikob } 228103285Sikob while((dvbuf = STAILQ_FIRST(&sc->fc->it[sub]->dvvalid)) != NULL){ 229103285Sikob STAILQ_REMOVE_HEAD(&sc->fc->it[sub]->dvvalid, link); 230103285Sikob free(dvbuf->buf, M_DEVBUF); 231103285Sikob } 232103285Sikob while((dvbuf = STAILQ_FIRST(&sc->fc->it[sub]->dvfree)) != NULL){ 233103285Sikob STAILQ_REMOVE_HEAD(&sc->fc->it[sub]->dvfree, link); 234103285Sikob free(dvbuf->buf, M_DEVBUF); 235103285Sikob } 236103285Sikob free(sc->fc->it[sub]->dvbuf, M_DEVBUF); 237103285Sikob sc->fc->it[sub]->dvbuf = NULL; 238103285Sikob } 239103285Sikob if(sc->fc->ir[sub]->flag & FWXFERQ_EXTBUF){ 240103285Sikob free(sc->fc->ir[sub]->buf, M_DEVBUF); 241103285Sikob sc->fc->ir[sub]->buf = NULL; 242103285Sikob free(sc->fc->ir[sub]->bulkxfer, M_DEVBUF); 243103285Sikob sc->fc->ir[sub]->bulkxfer = NULL; 244103285Sikob sc->fc->ir[sub]->flag &= ~FWXFERQ_EXTBUF; 245103285Sikob sc->fc->ir[sub]->psize = FWPMAX_S400; 246103285Sikob sc->fc->ir[sub]->maxq = FWMAXQUEUE; 247103285Sikob } 248103285Sikob if(sc->fc->it[sub]->flag & FWXFERQ_EXTBUF){ 249103285Sikob free(sc->fc->it[sub]->buf, M_DEVBUF); 250103285Sikob sc->fc->it[sub]->buf = NULL; 251103285Sikob free(sc->fc->it[sub]->bulkxfer, M_DEVBUF); 252103285Sikob sc->fc->it[sub]->bulkxfer = NULL; 253103285Sikob sc->fc->it[sub]->dvbuf = NULL; 254103285Sikob sc->fc->it[sub]->flag &= ~FWXFERQ_EXTBUF; 255103285Sikob sc->fc->it[sub]->psize = FWPMAX_S400; 256103285Sikob sc->fc->it[sub]->maxq = FWMAXQUEUE; 257103285Sikob } 258103285Sikob for(xfer = STAILQ_FIRST(&sc->fc->ir[sub]->q); 259103285Sikob xfer != NULL; xfer = STAILQ_FIRST(&sc->fc->ir[sub]->q)){ 260103285Sikob sc->fc->ir[sub]->queued--; 261103285Sikob STAILQ_REMOVE_HEAD(&sc->fc->ir[sub]->q, link); 262103285Sikob 263103285Sikob xfer->resp = 0; 264103285Sikob switch(xfer->act_type){ 265103285Sikob case FWACT_XFER: 266103285Sikob fw_xfer_done(xfer); 267103285Sikob break; 268103285Sikob default: 269103285Sikob break; 270103285Sikob } 271103285Sikob fw_xfer_free(xfer); 272103285Sikob } 273103285Sikob for(fwb = STAILQ_FIRST(&sc->fc->ir[sub]->binds); fwb != NULL; 274103285Sikob fwb = STAILQ_FIRST(&sc->fc->ir[sub]->binds)){ 275103285Sikob STAILQ_REMOVE(&sc->fc->binds, fwb, fw_bind, fclist); 276103285Sikob STAILQ_REMOVE_HEAD(&sc->fc->ir[sub]->binds, chlist); 277103285Sikob free(fwb, M_DEVBUF); 278103285Sikob } 279103285Sikob sc->fc->ir[sub]->flag &= ~FWXFERQ_MODEMASK; 280103285Sikob sc->fc->it[sub]->flag &= ~FWXFERQ_MODEMASK; 281103285Sikob return err; 282103285Sikob} 283103285Sikob/* 284103285Sikob * read request. 285103285Sikob */ 286103285Sikobstatic int 287103285Sikobfw_read (dev_t dev, struct uio *uio, int ioflag) 288103285Sikob{ 289103285Sikob struct firewire_softc *sc; 290103285Sikob struct fw_xferq *ir; 291103285Sikob struct fw_xfer *xfer; 292103285Sikob int err = 0, s, slept = 0; 293103285Sikob int unit = DEV2UNIT(dev); 294103285Sikob int sub = DEV2DMACH(dev); 295103285Sikob struct fw_pkt *fp; 296103285Sikob 297103285Sikob if (DEV_FWMEM(dev)) 298103285Sikob return fwmem_read(dev, uio, ioflag); 299103285Sikob 300103285Sikob sc = devclass_get_softc(firewire_devclass, unit); 301103285Sikob 302103285Sikob ir = sc->fc->ir[sub]; 303103285Sikob 304103285Sikob if(ir->flag & FWXFERQ_PACKET){ 305103285Sikob ir->stproc = NULL; 306103285Sikob } 307103285Sikobreadloop: 308103285Sikob xfer = STAILQ_FIRST(&ir->q); 309103285Sikob if(!(ir->flag & FWXFERQ_PACKET) && ir->stproc == NULL){ 310103285Sikob ir->stproc = STAILQ_FIRST(&ir->stvalid); 311103285Sikob if(ir->stproc != NULL){ 312103285Sikob s = splfw(); 313103285Sikob STAILQ_REMOVE_HEAD(&ir->stvalid, link); 314103285Sikob splx(s); 315103285Sikob ir->queued = 0; 316103285Sikob } 317103285Sikob } 318103285Sikob 319103285Sikob if(xfer == NULL && ir->stproc == NULL){ 320103285Sikob if(slept == 0){ 321103285Sikob slept = 1; 322103285Sikob if(!(ir->flag & FWXFERQ_RUNNING) 323103285Sikob && (ir->flag & FWXFERQ_PACKET)){ 324103285Sikob err = sc->fc->irx_enable(sc->fc, sub); 325103285Sikob } 326103285Sikob if(err){ 327103285Sikob return err; 328103285Sikob } 329103285Sikob ir->flag |= FWXFERQ_WAKEUP; 330103285Sikob err = tsleep((caddr_t)ir, FWPRI, "fw_read", hz); 331103285Sikob if(err){ 332103285Sikob ir->flag &= ~FWXFERQ_WAKEUP; 333103285Sikob return err; 334103285Sikob } 335103285Sikob goto readloop; 336103285Sikob }else{ 337103285Sikob err = EIO; 338103285Sikob return err; 339103285Sikob } 340103285Sikob }else if(xfer != NULL){ 341103285Sikob s = splfw(); 342103285Sikob ir->queued --; 343103285Sikob STAILQ_REMOVE_HEAD(&ir->q, link); 344103285Sikob splx(s); 345103285Sikob fp = (struct fw_pkt *)(xfer->recv.buf + xfer->recv.off); 346103285Sikob if(sc->fc->irx_post != NULL) 347103285Sikob sc->fc->irx_post(sc->fc, fp->mode.ld); 348103285Sikob err = uiomove(xfer->recv.buf + xfer->recv.off, xfer->recv.len, uio); 349103285Sikob fw_xfer_free( xfer); 350103285Sikob }else if(ir->stproc != NULL){ 351103285Sikob fp = (struct fw_pkt *)(ir->stproc->buf + ir->queued * ir->psize); 352103285Sikob if(sc->fc->irx_post != NULL) 353103285Sikob sc->fc->irx_post(sc->fc, fp->mode.ld); 354103285Sikob if(ntohs(fp->mode.stream.len) == 0){ 355103285Sikob err = EIO; 356103285Sikob return err; 357103285Sikob } 358103285Sikob err = uiomove((caddr_t)fp, ntohs(fp->mode.stream.len) + sizeof(u_int32_t), uio); 359103285Sikob fp->mode.stream.len = 0; 360103285Sikob ir->queued ++; 361103285Sikob if(ir->queued >= ir->bnpacket){ 362103285Sikob s = splfw(); 363103285Sikob ir->stproc->flag = 0; 364103285Sikob STAILQ_INSERT_TAIL(&ir->stfree, ir->stproc, link); 365103285Sikob splx(s); 366103285Sikob ir->stproc = NULL; 367103285Sikob } 368103285Sikob } 369103285Sikob#if 0 370103285Sikob if(STAILQ_FIRST(&ir->q) == NULL && 371103285Sikob (ir->flag & FWXFERQ_RUNNING) && (ir->flag & FWXFERQ_PACKET)){ 372103285Sikob err = sc->fc->irx_enable(sc->fc, sub); 373103285Sikob } 374103285Sikob#endif 375103285Sikob#if 0 376103285Sikob if(STAILQ_FIRST(&ir->stvalid) == NULL && 377103285Sikob (ir->flag & FWXFERQ_RUNNING) && !(ir->flag & FWXFERQ_PACKET)){ 378103285Sikob err = sc->fc->irx_enable(sc->fc, sub); 379103285Sikob } 380103285Sikob#endif 381103285Sikob return err; 382103285Sikob} 383103285Sikobstatic int 384103285Sikobfw_write (dev_t dev, struct uio *uio, int ioflag) 385103285Sikob{ 386103285Sikob int err = 0; 387103285Sikob struct firewire_softc *sc; 388103285Sikob int unit = DEV2UNIT(dev); 389103285Sikob int sub = DEV2DMACH(dev); 390103285Sikob int tl, s, slept = 0; 391103285Sikob struct fw_pkt *fp; 392103285Sikob struct fw_xfer *xfer; 393103285Sikob struct fw_xferq *xferq; 394103285Sikob struct firewire_comm *fc; 395103285Sikob struct fw_xferq *it; 396103285Sikob 397103285Sikob if (DEV_FWMEM(dev)) 398103285Sikob return fwmem_write(dev, uio, ioflag); 399103285Sikob 400103285Sikob sc = devclass_get_softc(firewire_devclass, unit); 401103285Sikob fc = sc->fc; 402103285Sikob it = sc->fc->it[sub]; 403103285Sikob 404103285Sikob fp = (struct fw_pkt *)uio->uio_iov->iov_base; 405103285Sikob switch(fp->mode.common.tcode){ 406103285Sikob case FWTCODE_RREQQ: 407103285Sikob case FWTCODE_RREQB: 408103285Sikob case FWTCODE_LREQ: 409103285Sikob err = EINVAL; 410103285Sikob return err; 411103285Sikob case FWTCODE_WREQQ: 412103285Sikob case FWTCODE_WREQB: 413103285Sikob xferq = fc->atq; 414103285Sikob break; 415103285Sikob case FWTCODE_STREAM: 416103285Sikob if(it->flag & FWXFERQ_PACKET){ 417103285Sikob xferq = fc->atq; 418103285Sikob }else{ 419103285Sikob xferq = NULL; 420103285Sikob } 421103285Sikob break; 422103285Sikob case FWTCODE_WRES: 423103285Sikob case FWTCODE_RRESQ: 424103285Sikob case FWTCODE_RRESB: 425103285Sikob case FWTCODE_LRES: 426103285Sikob xferq = fc->ats; 427103285Sikob break; 428103285Sikob default: 429103285Sikob err = EINVAL; 430103285Sikob return err; 431103285Sikob } 432103285Sikob /* Discard unsent buffered stream packet, when sending Asyrequrst */ 433103285Sikob if(xferq != NULL && it->stproc != NULL){ 434103285Sikob s = splfw(); 435103285Sikob it->stproc->flag = 0; 436103285Sikob STAILQ_INSERT_TAIL(&it->stfree, it->stproc, link); 437103285Sikob splx(s); 438103285Sikob it->stproc = NULL; 439103285Sikob } 440103285Sikob if(xferq == NULL && !(it->flag & FWXFERQ_DV)){ 441103285Sikobisoloop: 442103285Sikob if(it->stproc == NULL){ 443103285Sikob it->stproc = STAILQ_FIRST(&it->stfree); 444103285Sikob if(it->stproc != NULL){ 445103285Sikob s = splfw(); 446103285Sikob STAILQ_REMOVE_HEAD(&it->stfree, link); 447103285Sikob splx(s); 448103285Sikob it->queued = 0; 449103285Sikob }else if(slept == 0){ 450103285Sikob slept = 1; 451103285Sikob err = sc->fc->itx_enable(sc->fc, sub); 452103285Sikob if(err){ 453103285Sikob return err; 454103285Sikob } 455103285Sikob err = tsleep((caddr_t)it, FWPRI, "fw_write", hz); 456103285Sikob if(err){ 457103285Sikob return err; 458103285Sikob } 459103285Sikob goto isoloop; 460103285Sikob }else{ 461103285Sikob err = EIO; 462103285Sikob return err; 463103285Sikob } 464103285Sikob } 465103285Sikob fp = (struct fw_pkt *)(it->stproc->buf + it->queued * it->psize); 466103285Sikob fp->mode.stream.len = htons(uio->uio_resid - sizeof(u_int32_t)); 467103285Sikob err = uiomove(it->stproc->buf + it->queued * it->psize, 468103285Sikob uio->uio_resid, uio); 469103285Sikob it->queued ++; 470103285Sikob if(it->queued >= it->btpacket){ 471103285Sikob s = splfw(); 472103285Sikob STAILQ_INSERT_TAIL(&it->stvalid, it->stproc, link); 473103285Sikob splx(s); 474103285Sikob it->stproc = NULL; 475103285Sikob fw_tbuf_update(sc->fc, sub, 0); 476103285Sikob err = sc->fc->itx_enable(sc->fc, sub); 477103285Sikob } 478103285Sikob return err; 479103285Sikob } if(xferq == NULL && it->flag & FWXFERQ_DV){ 480103285Sikobdvloop: 481103285Sikob if(it->dvproc == NULL){ 482103285Sikob it->dvproc = STAILQ_FIRST(&it->dvfree); 483103285Sikob if(it->dvproc != NULL){ 484103285Sikob s = splfw(); 485103285Sikob STAILQ_REMOVE_HEAD(&it->dvfree, link); 486103285Sikob splx(s); 487103285Sikob it->dvptr = 0; 488103285Sikob }else if(slept == 0){ 489103285Sikob slept = 1; 490103285Sikob err = sc->fc->itx_enable(sc->fc, sub); 491103285Sikob if(err){ 492103285Sikob return err; 493103285Sikob } 494103285Sikob err = tsleep((caddr_t)it, FWPRI, "fw_write", hz); 495103285Sikob if(err){ 496103285Sikob return err; 497103285Sikob } 498103285Sikob goto dvloop; 499103285Sikob }else{ 500103285Sikob err = EIO; 501103285Sikob return err; 502103285Sikob } 503103285Sikob } 504103285Sikob fp = (struct fw_pkt *)(it->dvproc->buf + it->queued * it->psize); 505103285Sikob fp->mode.stream.len = htons(uio->uio_resid - sizeof(u_int32_t)); 506103285Sikob err = uiomove(it->dvproc->buf + it->dvptr, 507103285Sikob uio->uio_resid, uio); 508103285Sikob it->dvptr += it->psize; 509103285Sikob if(err){ 510103285Sikob return err; 511103285Sikob } 512103285Sikob if(it->dvptr >= it->psize * it->dvpacket){ 513103285Sikob s = splfw(); 514103285Sikob STAILQ_INSERT_TAIL(&it->dvvalid, it->dvproc, link); 515103285Sikob splx(s); 516103285Sikob it->dvproc = NULL; 517103285Sikob err = fw_tbuf_update(sc->fc, sub, 0); 518103285Sikob if(err){ 519103285Sikob return err; 520103285Sikob } 521103285Sikob err = sc->fc->itx_enable(sc->fc, sub); 522103285Sikob } 523103285Sikob return err; 524103285Sikob } 525103285Sikob if(xferq != NULL){ 526103285Sikob xfer = fw_xfer_alloc(); 527103285Sikob if(xfer == NULL){ 528103285Sikob err = ENOMEM; 529103285Sikob return err; 530103285Sikob } 531103285Sikob xfer->send.buf = malloc(uio->uio_resid, M_DEVBUF, M_NOWAIT); 532103285Sikob if(xfer->send.buf == NULL){ 533103285Sikob fw_xfer_free( xfer); 534103285Sikob err = ENOBUFS; 535103285Sikob return err; 536103285Sikob } 537103285Sikob xfer->dst = ntohs(fp->mode.hdr.dst); 538103285Sikob 539103285Sikob switch(fp->mode.common.tcode){ 540103285Sikob case FWTCODE_WREQQ: 541103285Sikob case FWTCODE_WREQB: 542103285Sikob if((tl = fw_get_tlabel(fc, xfer)) == -1 ){ 543103285Sikob fw_xfer_free( xfer); 544103285Sikob err = EAGAIN; 545103285Sikob return err; 546103285Sikob } 547103285Sikob fp->mode.hdr.tlrt = tl << 2; 548103285Sikob default: 549103285Sikob break; 550103285Sikob } 551103285Sikob 552103285Sikob xfer->tl = fp->mode.hdr.tlrt >> 2; 553103285Sikob xfer->send.len = uio->uio_resid; 554103285Sikob xfer->send.off = 0; 555103285Sikob xfer->tcode = fp->mode.common.tcode; 556103285Sikob xfer->spd = 0;/* XXX: how to setup it */ 557103285Sikob xfer->fc = fc; 558103285Sikob xfer->q = xferq; 559103285Sikob xfer->act_type = FWACT_XFER; 560103285Sikob xfer->act.hand = fw_asy_callback; 561103285Sikob xfer->retry_req = fw_asybusy; 562103285Sikob 563103285Sikob err = uiomove(xfer->send.buf, uio->uio_resid, uio); 564103285Sikob if(err){ 565103285Sikob return err; 566103285Sikob } 567103285Sikob fw_asystart(xfer); 568103285Sikob err = tsleep((caddr_t)xfer, FWPRI, "fw_write", hz); 569103285Sikob if(xfer->resp == EBUSY) 570103285Sikob return EBUSY; 571103285Sikob fw_xfer_free( xfer); 572103285Sikob return err; 573103285Sikob } 574103285Sikob return EINVAL; 575103285Sikob} 576103285Sikob/* 577103285Sikob * transmitter buffer update. 578103285Sikob */ 579103285Sikobint 580103285Sikobfw_tbuf_update(struct firewire_comm *fc, int sub, int flag){ 581103285Sikob struct fw_bulkxfer *bulkxfer, *bulkxfer2 = NULL; 582103285Sikob struct fw_dvbuf *dvbuf = NULL; 583103285Sikob struct fw_xferq *it; 584103285Sikob int s, err = 0, i, j, chtag; 585103285Sikob struct fw_pkt *fp; 586103285Sikob u_int64_t tmpsync, dvsync; 587103285Sikob 588103285Sikob it = fc->it[sub]; 589103285Sikob 590103285Sikob s = splfw(); 591103285Sikob if(it->stdma == NULL){ 592103285Sikob bulkxfer = STAILQ_FIRST(&it->stvalid); 593103285Sikob }else if(flag != 0){ 594103285Sikob bulkxfer = STAILQ_FIRST(&it->stvalid); 595103285Sikob if(bulkxfer == it->stdma){ 596103285Sikob STAILQ_REMOVE_HEAD(&it->stvalid, link); 597103285Sikob it->stdma->flag = 0; 598103285Sikob STAILQ_INSERT_TAIL(&it->stfree, it->stdma, link); 599103285Sikob if(!(it->flag & FWXFERQ_DV)) 600103285Sikob wakeup(it); 601103285Sikob } 602103285Sikob bulkxfer = STAILQ_FIRST(&it->stvalid); 603103285Sikob }else{ 604103285Sikob bulkxfer = it->stdma; 605103285Sikob } 606103285Sikob splx(s); 607103285Sikob if(bulkxfer != NULL){ 608103285Sikob s = splfw(); 609103285Sikob bulkxfer2 = STAILQ_NEXT(bulkxfer, link); 610103285Sikob#if 0 611103285Sikob if(it->flag & FWXFERQ_DV && bulkxfer2 == NULL){ 612103285Sikob bulkxfer2 = STAILQ_FIRST(&it->stfree); 613103285Sikob STAILQ_REMOVE_HEAD(&it->stfree, link); 614103285Sikob splx(s); 615103285Sikob bcopy(bulkxfer->buf, bulkxfer2->buf, 616103285Sikob it->psize * it->btpacket); 617103285Sikob s = splfw(); 618103285Sikob STAILQ_INSERT_TAIL(&it->stvalid, bulkxfer2, link); 619103285Sikob } 620103285Sikob#endif 621103285Sikob splx(s); 622103285Sikob } 623103285Sikob it->stdma = bulkxfer; 624103285Sikob it->stdma2 = bulkxfer2; 625103285Sikob 626103285Sikob if(it->flag & FWXFERQ_DV){ 627103285Sikob chtag = it->flag & 0xff; 628103285Sikobdvloop: 629103285Sikob if(it->dvdma == NULL){ 630103285Sikob dvbuf = STAILQ_FIRST(&it->dvvalid); 631103285Sikob if(dvbuf != NULL){ 632103285Sikob s = splfw(); 633103285Sikob STAILQ_REMOVE_HEAD(&it->dvvalid, link); 634103285Sikob it->dvdma = dvbuf; 635103285Sikob splx(s); 636103285Sikob it->queued = 0; 637103285Sikob } 638103285Sikob } 639103285Sikob if(it->dvdma == NULL) 640103285Sikob return err; 641103285Sikob 642103285Sikob it->stproc = STAILQ_FIRST(&it->stfree); 643103285Sikob if(it->stproc != NULL){ 644103285Sikob s = splfw(); 645103285Sikob STAILQ_REMOVE_HEAD(&it->stfree, link); 646103285Sikob splx(s); 647103285Sikob }else{ 648103285Sikob return err; 649103285Sikob } 650103285Sikob/* 651103285Sikob * Insert least significant 12 bits timestamp value by computation. 652103285Sikob * Highest significant 4 bits is insert at just before packet sending. 653103285Sikob */ 654103285Sikob fp = (struct fw_pkt *)(it->stproc->buf); 655103285Sikob/* XXX: Parameter relies on NTSC type DV video */ 656103485Sikob tmpsync = (u_int64_t)3072 * 8000 * 100 / 2997; 657103285Sikob tmpsync *= it->dvsync; 658103285Sikob dvsync = tmpsync; 659103285Sikob dvsync %= 0xc00; 660103285Sikob fp->mode.ld[2] = htonl(0x80000000 | (dvsync % 0xc00)); 661103285Sikob it->dvsync ++; 662103285Sikob it->dvsync %= 2997; 663103285Sikob 664103285Sikob for( i = 0, j = 0 ; i < it->dvpacket ; i++){ 665103285Sikob bcopy(it->dvdma->buf + it->queued * it->psize, 666103285Sikob it->stproc->buf + j * it->psize, it->psize); 667103285Sikob fp = (struct fw_pkt *)(it->stproc->buf + j * it->psize); 668103285Sikob fp->mode.stream.len = htons(488); 669103285Sikob fp->mode.stream.chtag = chtag; 670103285Sikob fp->mode.stream.tcode = FWTCODE_STREAM; 671103285Sikob fp->mode.ld[1] = htonl((fc->nodeid << 24) | 0x00780000 | it->dvdbc); 672103285Sikob it->dvdbc++; 673103285Sikob it->dvdbc %= 256; 674103285Sikob it->queued ++; 675103285Sikob j++; 676103285Sikob/* XXX: Parameter relies on NTSC type DV video */ 677103285Sikob#if 1 678103285Sikob#define DVDIFF 203 679103285Sikob#define DVFRAC 2997 680103285Sikob#else 681103285Sikob#define DVDIFF 127 682103285Sikob#define DVFRAC 1875 683103285Sikob#endif 684103285Sikob it->dvdiff += DVDIFF; 685103285Sikob if(it->dvdiff >= DVFRAC){ 686103285Sikob it->dvdiff %= DVFRAC; 687103285Sikob fp = (struct fw_pkt *)(it->stproc->buf + j * it->psize); 688103285Sikob 689103285Sikob fp->mode.stream.len = htons(0x8); 690103285Sikob fp->mode.stream.chtag = chtag; 691103285Sikob fp->mode.stream.tcode = FWTCODE_STREAM; 692103285Sikob fp->mode.ld[1] = htonl((fc->nodeid << 24) | 693103285Sikob 0x00780000 | it->dvdbc); 694103285Sikob j++; 695103285Sikob } 696103285Sikob } 697103285Sikob it->stproc->npacket = j; 698103285Sikob s = splfw(); 699103285Sikob STAILQ_INSERT_TAIL(&it->stvalid, it->stproc, link); 700103285Sikob splx(s); 701103285Sikob if(it->queued >= it->dvpacket){ 702103285Sikob s = splfw(); 703103285Sikob STAILQ_INSERT_TAIL(&it->dvfree, it->dvdma, link); 704103285Sikob it->dvdma = NULL; 705103285Sikob splx(s); 706103285Sikob wakeup(it); 707103285Sikob goto dvloop; 708103285Sikob } 709103285Sikob } 710103285Sikob return err; 711103285Sikob} 712103285Sikob/* 713103285Sikob * receving buffer update. 714103285Sikob */ 715103285Sikobint 716103285Sikobfw_rbuf_update(struct firewire_comm *fc, int sub, int flag){ 717103285Sikob struct fw_bulkxfer *bulkxfer, *bulkxfer2 = NULL; 718103285Sikob struct fw_xferq *ir; 719103285Sikob int s, err = 0; 720103285Sikob 721103285Sikob ir = fc->ir[sub]; 722103285Sikob s = splfw(); 723103285Sikob if(ir->stdma != NULL){ 724103285Sikob if(flag != 0){ 725103285Sikob STAILQ_INSERT_TAIL(&ir->stvalid, ir->stdma, link); 726103285Sikob }else{ 727103285Sikob ir->stdma->flag = 0; 728103285Sikob STAILQ_INSERT_TAIL(&ir->stfree, ir->stdma, link); 729103285Sikob } 730103285Sikob } 731103285Sikob if(ir->stdma2 != NULL){ 732103285Sikob bulkxfer = ir->stdma2; 733103285Sikob bulkxfer2 = STAILQ_FIRST(&ir->stfree); 734103285Sikob if(bulkxfer2 != NULL){ 735103285Sikob STAILQ_REMOVE_HEAD(&ir->stfree, link); 736103285Sikob } 737103285Sikob }else{ 738103285Sikob bulkxfer = STAILQ_FIRST(&ir->stfree); 739103285Sikob if(bulkxfer != NULL){ 740103285Sikob STAILQ_REMOVE_HEAD(&ir->stfree, link); 741103285Sikob bulkxfer2 = STAILQ_FIRST(&ir->stfree); 742103285Sikob if(bulkxfer2 != NULL){ 743103285Sikob STAILQ_REMOVE_HEAD(&ir->stfree, link); 744103285Sikob } 745103285Sikob }else{ 746103285Sikob bulkxfer = STAILQ_FIRST(&ir->stvalid); 747103285Sikob STAILQ_REMOVE_HEAD(&ir->stvalid, link); 748103285Sikob } 749103285Sikob } 750103285Sikob splx(s); 751103285Sikob ir->stdma = bulkxfer; 752103285Sikob ir->stdma2 = bulkxfer2; 753103285Sikob return err; 754103285Sikob} 755103285Sikob/* 756103285Sikob * ioctl support. 757103285Sikob */ 758103285Sikobint 759103285Sikobfw_ioctl (dev_t dev, u_long cmd, caddr_t data, int flag, fw_proc *td) 760103285Sikob{ 761103285Sikob struct firewire_softc *sc; 762103285Sikob int unit = DEV2UNIT(dev); 763103285Sikob int sub = DEV2DMACH(dev); 764103285Sikob int i, len, err = 0; 765103285Sikob struct fw_device *fwdev; 766103285Sikob struct fw_bind *fwb; 767103285Sikob struct fw_xferq *ir, *it; 768103285Sikob struct fw_xfer *xfer; 769103285Sikob struct fw_pkt *fp; 770103285Sikob 771103285Sikob struct fw_devlstreq *fwdevlst = (struct fw_devlstreq *)data; 772103285Sikob struct fw_asyreq *asyreq = (struct fw_asyreq *)data; 773103285Sikob struct fw_isochreq *ichreq = (struct fw_isochreq *)data; 774103285Sikob struct fw_isobufreq *ibufreq = (struct fw_isobufreq *)data; 775103285Sikob struct fw_asybindreq *bindreq = (struct fw_asybindreq *)data; 776103285Sikob#if 0 777103285Sikob struct fw_map_buf *map_buf = (struct fw_map_buf *)data; 778103285Sikob#endif 779103285Sikob struct fw_crom_buf *crom_buf = (struct fw_crom_buf *)data; 780103285Sikob 781103285Sikob if (DEV_FWMEM(dev)) 782103285Sikob return fwmem_ioctl(dev, cmd, data, flag, td); 783103285Sikob 784103285Sikob sc = devclass_get_softc(firewire_devclass, unit); 785103285Sikob if (!data) 786103285Sikob return(EINVAL); 787103285Sikob 788103285Sikob switch (cmd) { 789103285Sikob case FW_STSTREAM: 790103285Sikob sc->fc->it[sub]->flag &= ~0xff; 791103285Sikob sc->fc->it[sub]->flag |= (0x3f & ichreq->ch); 792103285Sikob sc->fc->it[sub]->flag |= ((0x3 & ichreq->tag) << 6); 793103285Sikob err = 0; 794103285Sikob break; 795103285Sikob case FW_GTSTREAM: 796103285Sikob ichreq->ch = sc->fc->it[sub]->flag & 0x3f; 797103285Sikob ichreq->tag =(sc->fc->it[sub]->flag) >> 2 & 0x3; 798103285Sikob err = 0; 799103285Sikob break; 800103285Sikob case FW_SRSTREAM: 801103285Sikob sc->fc->ir[sub]->flag &= ~0xff; 802103285Sikob sc->fc->ir[sub]->flag |= (0x3f & ichreq->ch); 803103285Sikob sc->fc->ir[sub]->flag |= ((0x3 & ichreq->tag) << 6); 804103285Sikob err = sc->fc->irx_enable(sc->fc, sub); 805103285Sikob break; 806103285Sikob case FW_GRSTREAM: 807103285Sikob ichreq->ch = sc->fc->ir[sub]->flag & 0x3f; 808103285Sikob ichreq->tag =(sc->fc->ir[sub]->flag) >> 2 & 0x3; 809103285Sikob err = 0; 810103285Sikob break; 811103285Sikob case FW_SSTDV: 812103285Sikob ibufreq = (struct fw_isobufreq *) 813103285Sikob malloc(sizeof(struct fw_isobufreq), M_DEVBUF, M_NOWAIT); 814103285Sikob if(ibufreq == NULL){ 815103285Sikob err = ENOMEM; 816103285Sikob break; 817103285Sikob } 818103285Sikob#define FWDVPACKET 250 819103285Sikob#define FWDVPMAX 512 820103285Sikob ibufreq->rx.nchunk = 8; 821103285Sikob ibufreq->rx.npacket = 50; 822103285Sikob ibufreq->rx.psize = FWDVPMAX; 823103285Sikob 824103285Sikob ibufreq->tx.nchunk = 5; 825103285Sikob ibufreq->tx.npacket = 300; 826103285Sikob ibufreq->tx.psize = FWDVPMAX; 827103285Sikob 828103285Sikob err = fw_ioctl(dev, FW_SSTBUF, (caddr_t)ibufreq, flag, td); 829103285Sikob sc->fc->it[sub]->dvpacket = FWDVPACKET; 830103285Sikob free(ibufreq, M_DEVBUF); 831103285Sikob/* reserve a buffer space */ 832103285Sikob#define NDVCHUNK 8 833103285Sikob sc->fc->it[sub]->dvproc = NULL; 834103285Sikob sc->fc->it[sub]->dvdma = NULL; 835103285Sikob sc->fc->it[sub]->flag |= FWXFERQ_DV; 836103285Sikob sc->fc->it[sub]->dvbuf 837103285Sikob = (struct fw_dvbuf *)malloc(sizeof(struct fw_dvbuf) * NDVCHUNK, M_DEVBUF, M_DONTWAIT); 838103285Sikob STAILQ_INIT(&sc->fc->it[sub]->dvvalid); 839103285Sikob STAILQ_INIT(&sc->fc->it[sub]->dvfree); 840103285Sikob for( i = 0 ; i < NDVCHUNK ; i++){ 841103285Sikob sc->fc->it[sub]->dvbuf[i].buf 842103285Sikob = malloc(FWDVPMAX * sc->fc->it[sub]->dvpacket, M_DEVBUF, M_DONTWAIT); 843103285Sikob STAILQ_INSERT_TAIL(&sc->fc->it[sub]->dvfree, 844103285Sikob &sc->fc->it[sub]->dvbuf[i], link); 845103285Sikob } 846103285Sikob break; 847103285Sikob case FW_SSTBUF: 848103285Sikob ir = sc->fc->ir[sub]; 849103285Sikob it = sc->fc->it[sub]; 850103285Sikob 851103285Sikob if(ir->flag & FWXFERQ_RUNNING || it->flag & FWXFERQ_RUNNING){ 852103285Sikob return(EBUSY); 853103285Sikob } 854103285Sikob if((ir->flag & FWXFERQ_EXTBUF) || (it->flag & FWXFERQ_EXTBUF)){ 855103285Sikob return(EBUSY); 856103285Sikob } 857103285Sikob if((ibufreq->rx.nchunk * 858103285Sikob ibufreq->rx.psize * ibufreq->rx.npacket) + 859103285Sikob (ibufreq->tx.nchunk * 860103285Sikob ibufreq->tx.psize * ibufreq->tx.npacket) <= 0){ 861103285Sikob return(EINVAL); 862103285Sikob } 863103285Sikob if(ibufreq->rx.nchunk > FWSTMAXCHUNK || 864103285Sikob ibufreq->tx.nchunk > FWSTMAXCHUNK){ 865103285Sikob return(EINVAL); 866103285Sikob } 867103285Sikob ir->bulkxfer 868103285Sikob = (struct fw_bulkxfer *)malloc(sizeof(struct fw_bulkxfer) * ibufreq->rx.nchunk, M_DEVBUF, M_DONTWAIT); 869103285Sikob if(ir->bulkxfer == NULL){ 870103285Sikob return(ENOMEM); 871103285Sikob } 872103285Sikob it->bulkxfer 873103285Sikob = (struct fw_bulkxfer *)malloc(sizeof(struct fw_bulkxfer) * ibufreq->tx.nchunk, M_DEVBUF, M_DONTWAIT); 874103285Sikob if(it->bulkxfer == NULL){ 875103285Sikob return(ENOMEM); 876103285Sikob } 877103285Sikob ir->buf = malloc( 878103285Sikob ibufreq->rx.nchunk * ibufreq->rx.npacket 879103285Sikob * ((ibufreq->rx.psize + 3) &~3), 880103285Sikob M_DEVBUF, M_DONTWAIT); 881103285Sikob if(ir->buf == NULL){ 882103285Sikob free(ir->bulkxfer, M_DEVBUF); 883103285Sikob free(it->bulkxfer, M_DEVBUF); 884103285Sikob ir->bulkxfer = NULL; 885103285Sikob it->bulkxfer = NULL; 886103285Sikob it->buf = NULL; 887103285Sikob return(ENOMEM); 888103285Sikob } 889103285Sikob it->buf = malloc( 890103285Sikob ibufreq->tx.nchunk * ibufreq->tx.npacket 891103285Sikob * ((ibufreq->tx.psize + 3) &~3), 892103285Sikob M_DEVBUF, M_DONTWAIT); 893103285Sikob if(it->buf == NULL){ 894103285Sikob free(ir->bulkxfer, M_DEVBUF); 895103285Sikob free(it->bulkxfer, M_DEVBUF); 896103285Sikob free(ir->buf, M_DEVBUF); 897103285Sikob ir->bulkxfer = NULL; 898103285Sikob it->bulkxfer = NULL; 899103285Sikob it->buf = NULL; 900103285Sikob return(ENOMEM); 901103285Sikob } 902103285Sikob 903103285Sikob ir->bnchunk = ibufreq->rx.nchunk; 904103285Sikob ir->bnpacket = ibufreq->rx.npacket; 905103285Sikob ir->btpacket = ibufreq->rx.npacket; 906103285Sikob ir->psize = (ibufreq->rx.psize + 3) & ~3; 907103285Sikob ir->queued = 0; 908103285Sikob 909103285Sikob it->bnchunk = ibufreq->tx.nchunk; 910103285Sikob it->bnpacket = ibufreq->tx.npacket; 911103285Sikob it->btpacket = ibufreq->tx.npacket; 912103285Sikob it->psize = (ibufreq->tx.psize + 3) & ~3; 913103285Sikob ir->queued = 0; 914103285Sikob it->dvdbc = 0; 915103285Sikob it->dvdiff = 0; 916103285Sikob it->dvsync = 0; 917103285Sikob 918103285Sikob STAILQ_INIT(&ir->stvalid); 919103285Sikob STAILQ_INIT(&ir->stfree); 920103285Sikob ir->stdma = NULL; 921103285Sikob ir->stdma2 = NULL; 922103285Sikob ir->stproc = NULL; 923103285Sikob 924103285Sikob STAILQ_INIT(&it->stvalid); 925103285Sikob STAILQ_INIT(&it->stfree); 926103285Sikob it->stdma = NULL; 927103285Sikob it->stdma2 = NULL; 928103285Sikob it->stproc = NULL; 929103285Sikob 930103285Sikob for(i = 0 ; i < sc->fc->ir[sub]->bnchunk; i++){ 931103285Sikob ir->bulkxfer[i].buf = 932103285Sikob ir->buf + 933103285Sikob i * sc->fc->ir[sub]->bnpacket * 934103285Sikob sc->fc->ir[sub]->psize; 935103285Sikob ir->bulkxfer[i].flag = 0; 936103285Sikob STAILQ_INSERT_TAIL(&ir->stfree, 937103285Sikob &ir->bulkxfer[i], link); 938103285Sikob ir->bulkxfer[i].npacket = ir->bnpacket; 939103285Sikob } 940103285Sikob for(i = 0 ; i < sc->fc->it[sub]->bnchunk; i++){ 941103285Sikob it->bulkxfer[i].buf = 942103285Sikob it->buf + 943103285Sikob i * sc->fc->it[sub]->bnpacket * 944103285Sikob sc->fc->it[sub]->psize; 945103285Sikob it->bulkxfer[i].flag = 0; 946103285Sikob STAILQ_INSERT_TAIL(&it->stfree, 947103285Sikob &it->bulkxfer[i], link); 948103285Sikob it->bulkxfer[i].npacket = it->bnpacket; 949103285Sikob } 950103285Sikob ir->flag &= ~FWXFERQ_MODEMASK; 951103285Sikob ir->flag |= FWXFERQ_STREAM; 952103285Sikob ir->flag |= FWXFERQ_EXTBUF; 953103285Sikob 954103285Sikob it->flag &= ~FWXFERQ_MODEMASK; 955103285Sikob it->flag |= FWXFERQ_STREAM; 956103285Sikob it->flag |= FWXFERQ_EXTBUF; 957103285Sikob err = 0; 958103285Sikob break; 959103285Sikob case FW_GSTBUF: 960103285Sikob ibufreq->rx.nchunk = sc->fc->ir[sub]->bnchunk; 961103285Sikob ibufreq->rx.npacket = sc->fc->ir[sub]->bnpacket; 962103285Sikob ibufreq->rx.psize = sc->fc->ir[sub]->psize; 963103285Sikob 964103285Sikob ibufreq->tx.nchunk = sc->fc->it[sub]->bnchunk; 965103285Sikob ibufreq->tx.npacket = sc->fc->it[sub]->bnpacket; 966103285Sikob ibufreq->tx.psize = sc->fc->it[sub]->psize; 967103285Sikob break; 968103285Sikob case FW_ASYREQ: 969103285Sikob xfer = fw_xfer_alloc(); 970103285Sikob if(xfer == NULL){ 971103285Sikob err = ENOMEM; 972103285Sikob return err; 973103285Sikob } 974103285Sikob fp = &asyreq->pkt; 975103285Sikob switch (asyreq->req.type) { 976103285Sikob case FWASREQNODE: 977103285Sikob xfer->dst = ntohs(fp->mode.hdr.dst); 978103285Sikob break; 979103285Sikob case FWASREQEUI: 980103285Sikob xfer->dst = fw_noderesolve(sc->fc, asyreq->req.dst.eui); 981103285Sikob if(xfer->dst == FWNODE_INVAL ){ 982103285Sikob printf("%s:cannot found node\n", 983103285Sikob device_get_nameunit(sc->fc->dev)); 984103285Sikob err = EINVAL; 985103285Sikob goto error; 986103285Sikob } 987103285Sikob fp->mode.hdr.dst = htons(FWLOCALBUS | xfer->dst); 988103285Sikob break; 989103285Sikob case FWASRESTL: 990103285Sikob /* XXX what's this? */ 991103285Sikob break; 992103285Sikob case FWASREQSTREAM: 993103285Sikob /* nothing to do */ 994103285Sikob break; 995103285Sikob } 996103285Sikob xfer->spd = asyreq->req.sped; 997103285Sikob xfer->send.len = asyreq->req.len; 998103285Sikob xfer->send.buf = malloc(xfer->send.len, M_DEVBUF, M_NOWAIT); 999103285Sikob if(xfer->send.buf == NULL){ 1000103285Sikob return ENOMEM; 1001103285Sikob } 1002103285Sikob xfer->send.off = 0; 1003103285Sikob bcopy(fp, xfer->send.buf, xfer->send.len); 1004103285Sikob xfer->act.hand = fw_asy_callback; 1005103285Sikob err = fw_asyreq(sc->fc, sub, xfer); 1006103285Sikob if(err){ 1007103285Sikob fw_xfer_free( xfer); 1008103285Sikob return err; 1009103285Sikob } 1010103285Sikob err = tsleep((caddr_t)xfer, FWPRI, "asyreq", hz); 1011103285Sikob if(err == 0){ 1012103285Sikob if(asyreq->req.len >= xfer->recv.len){ 1013103285Sikob asyreq->req.len = xfer->recv.len; 1014103285Sikob }else{ 1015103285Sikob err = EINVAL; 1016103285Sikob } 1017103285Sikob bcopy(xfer->recv.buf + xfer->recv.off, fp, asyreq->req.len); 1018103285Sikob } 1019103285Sikoberror: 1020103285Sikob fw_xfer_free( xfer); 1021103285Sikob break; 1022103285Sikob case FW_IBUSRST: 1023103285Sikob sc->fc->ibr(sc->fc); 1024103285Sikob break; 1025103285Sikob case FW_CBINDADDR: 1026103285Sikob fwb = fw_bindlookup(sc->fc, 1027103285Sikob bindreq->start.hi, bindreq->start.lo); 1028103285Sikob if(fwb == NULL){ 1029103285Sikob err = EINVAL; 1030103285Sikob break; 1031103285Sikob } 1032103285Sikob STAILQ_REMOVE(&sc->fc->binds, fwb, fw_bind, fclist); 1033103285Sikob STAILQ_REMOVE(&sc->fc->ir[sub]->binds, fwb, fw_bind, chlist); 1034103285Sikob free(fwb, M_DEVBUF); 1035103285Sikob break; 1036103285Sikob case FW_SBINDADDR: 1037103285Sikob if(bindreq->len <= 0 ){ 1038103285Sikob err = EINVAL; 1039103285Sikob break; 1040103285Sikob } 1041103285Sikob if(bindreq->start.hi > 0xffff ){ 1042103285Sikob err = EINVAL; 1043103285Sikob break; 1044103285Sikob } 1045103285Sikob fwb = (struct fw_bind *)malloc(sizeof (struct fw_bind), M_DEVBUF, M_DONTWAIT); 1046103285Sikob if(fwb == NULL){ 1047103285Sikob err = ENOMEM; 1048103285Sikob break; 1049103285Sikob } 1050103285Sikob fwb->start_hi = bindreq->start.hi; 1051103285Sikob fwb->start_lo = bindreq->start.lo; 1052103285Sikob fwb->addrlen = bindreq->len; 1053103285Sikob 1054103285Sikob xfer = fw_xfer_alloc(); 1055103285Sikob if(xfer == NULL){ 1056103285Sikob err = ENOMEM; 1057103285Sikob return err; 1058103285Sikob } 1059103285Sikob xfer->act_type = FWACT_CH; 1060103285Sikob xfer->sub = sub; 1061103285Sikob xfer->fc = sc->fc; 1062103285Sikob 1063103285Sikob fwb->xfer = xfer; 1064103285Sikob err = fw_bindadd(sc->fc, fwb); 1065103285Sikob break; 1066103285Sikob case FW_GDEVLST: 1067103285Sikob i = 0; 1068103285Sikob for(fwdev = TAILQ_FIRST(&sc->fc->devices); fwdev != NULL; 1069103285Sikob fwdev = TAILQ_NEXT(fwdev, link)){ 1070103285Sikob if(i < fwdevlst->n){ 1071103285Sikob fwdevlst->dst[i] = fwdev->dst; 1072103285Sikob fwdevlst->status[i] = 1073103285Sikob (fwdev->status == FWDEVATTACHED)?1:0; 1074103285Sikob fwdevlst->eui[i].hi = fwdev->eui.hi; 1075103285Sikob fwdevlst->eui[i].lo = fwdev->eui.lo; 1076103285Sikob } 1077103285Sikob i++; 1078103285Sikob } 1079103285Sikob fwdevlst->n = i; 1080103285Sikob break; 1081103285Sikob case FW_GTPMAP: 1082103285Sikob bcopy(sc->fc->topology_map, data, 1083103285Sikob (sc->fc->topology_map->crc_len + 1) * 4); 1084103285Sikob break; 1085103285Sikob case FW_GSPMAP: 1086103285Sikob /* speed_map is larger than a page */ 1087103285Sikob err = copyout(sc->fc->speed_map, *(void **)data, 1088103285Sikob (sc->fc->speed_map->crc_len + 1) * 4); 1089103285Sikob break; 1090103285Sikob case FW_GCROM: 1091103285Sikob for (fwdev = TAILQ_FIRST(&sc->fc->devices); fwdev != NULL; 1092103285Sikob fwdev = TAILQ_NEXT(fwdev, link)) { 1093103285Sikob if (fwdev->eui.hi == crom_buf->eui.hi && 1094103285Sikob fwdev->eui.lo == crom_buf->eui.lo) 1095103285Sikob break; 1096103285Sikob } 1097103285Sikob if (fwdev == NULL) { 1098103285Sikob err = FWNODE_INVAL; 1099103285Sikob break; 1100103285Sikob } 1101103285Sikob#if 0 1102103285Sikob if (fwdev->csrrom[0] >> 24 == 1) 1103103285Sikob len = 4; 1104103285Sikob else 1105103285Sikob len = (1 + ((fwdev->csrrom[0] >> 16) & 0xff)) * 4; 1106103285Sikob#else 1107103285Sikob if (fwdev->rommax < CSRROMOFF) 1108103285Sikob len = 0; 1109103285Sikob else 1110103285Sikob len = fwdev->rommax - CSRROMOFF + 4; 1111103285Sikob#endif 1112103285Sikob if (crom_buf->len < len) 1113103285Sikob len = crom_buf->len; 1114103285Sikob else 1115103285Sikob crom_buf->len = len; 1116103285Sikob err = copyout(&fwdev->csrrom[0], crom_buf->ptr, len); 1117103285Sikob break; 1118103285Sikob default: 1119103285Sikob sc->fc->ioctl (dev, cmd, data, flag, td); 1120103285Sikob break; 1121103285Sikob } 1122103285Sikob return err; 1123103285Sikob} 1124103285Sikobint 1125103285Sikobfw_poll(dev_t dev, int events, fw_proc *td) 1126103285Sikob{ 1127103285Sikob int revents; 1128103285Sikob int tmp; 1129103285Sikob int unit = DEV2UNIT(dev); 1130103285Sikob int sub = DEV2DMACH(dev); 1131103285Sikob struct firewire_softc *sc; 1132103285Sikob 1133103285Sikob if (DEV_FWMEM(dev)) 1134103285Sikob return fwmem_poll(dev, events, td); 1135103285Sikob 1136103285Sikob sc = devclass_get_softc(firewire_devclass, unit); 1137103285Sikob revents = 0; 1138103285Sikob tmp = POLLIN | POLLRDNORM; 1139103285Sikob if (events & tmp) { 1140103285Sikob if (STAILQ_FIRST(&sc->fc->ir[sub]->q) != NULL) 1141103285Sikob revents |= tmp; 1142103285Sikob else 1143103285Sikob selrecord(td, &sc->fc->ir[sub]->rsel); 1144103285Sikob } 1145103285Sikob tmp = POLLOUT | POLLWRNORM; 1146103285Sikob if (events & tmp) { 1147103285Sikob /* XXX should be fixed */ 1148103285Sikob revents |= tmp; 1149103285Sikob } 1150103285Sikob 1151103285Sikob return revents; 1152103285Sikob} 1153103285Sikob 1154103285Sikob/* 1155103285Sikob * To lookup node id. from EUI64. 1156103285Sikob */ 1157103285Sikobu_int16_t fw_noderesolve(struct firewire_comm *fc, struct fw_eui64 eui) 1158103285Sikob{ 1159103285Sikob struct fw_device *fwdev; 1160103285Sikob for(fwdev = TAILQ_FIRST(&fc->devices); fwdev != NULL; 1161103285Sikob fwdev = TAILQ_NEXT(fwdev, link)){ 1162103285Sikob if(fwdev->eui.hi == eui.hi && fwdev->eui.lo == eui.lo){ 1163103285Sikob break; 1164103285Sikob } 1165103285Sikob } 1166103285Sikob if(fwdev == NULL) return FWNODE_INVAL; 1167103285Sikob if(fwdev->status != FWDEVATTACHED) return FWNODE_INVAL; 1168103285Sikob return fwdev->dst; 1169103285Sikob} 1170103285Sikob/* 1171103285Sikob * Async. request procedure for userland application. 1172103285Sikob */ 1173103285Sikobint 1174103285Sikobfw_asyreq(struct firewire_comm *fc, int sub, struct fw_xfer *xfer) 1175103285Sikob{ 1176103285Sikob int err = 0; 1177103285Sikob struct fw_xferq *xferq; 1178103285Sikob int tl = 0, len; 1179103285Sikob struct fw_pkt *fp; 1180103285Sikob int tcode; 1181103285Sikob struct tcode_info *info; 1182103285Sikob 1183103285Sikob if(xfer == NULL) return EINVAL; 1184103285Sikob if(xfer->send.len > fc->maxrec){ 1185103285Sikob printf("send.len > maxrec\n"); 1186103285Sikob return EINVAL; 1187103285Sikob } 1188103285Sikob if(xfer->act.hand == NULL){ 1189103285Sikob printf("act.hand == NULL\n"); 1190103285Sikob return EINVAL; 1191103285Sikob } 1192103285Sikob fp = (struct fw_pkt *)xfer->send.buf; 1193103285Sikob 1194103285Sikob#if 0 1195103285Sikob switch(fp->mode.common.tcode){ 1196103285Sikob case FWTCODE_STREAM: 1197103285Sikob len = ntohs(fp->mode.stream.len) + 4; 1198103285Sikob break; 1199103285Sikob case FWTCODE_RREQQ: 1200103285Sikob case FWTCODE_WRES: 1201103285Sikob case FWTCODE_PHY: 1202103285Sikob len = 12; 1203103285Sikob break; 1204103285Sikob case FWTCODE_WREQQ: 1205103285Sikob case FWTCODE_RRESQ: 1206103285Sikob len = 16; 1207103285Sikob break; 1208103285Sikob default: 1209103285Sikob len = ntohs(fp->mode.rresb.len) + 16; 1210103285Sikob break; 1211103285Sikob } 1212103285Sikob if( len > xfer->send.len ){ 1213103285Sikob printf("len > send.len\n"); 1214103285Sikob return EINVAL; 1215103285Sikob } 1216103285Sikob switch(fp->mode.common.tcode){ 1217103285Sikob case FWTCODE_WREQQ: 1218103285Sikob case FWTCODE_WREQB: 1219103285Sikob case FWTCODE_RREQQ: 1220103285Sikob case FWTCODE_RREQB: 1221103285Sikob case FWTCODE_LREQ: 1222103285Sikob case FWTCODE_PHY: 1223103285Sikob case FWTCODE_STREAM: 1224103285Sikob xferq = fc->atq; 1225103285Sikob break; 1226103285Sikob case FWTCODE_WRES: 1227103285Sikob case FWTCODE_RRESQ: 1228103285Sikob case FWTCODE_RRESB: 1229103285Sikob case FWTCODE_LRES: 1230103285Sikob xferq = fc->ats; 1231103285Sikob break; 1232103285Sikob default: 1233103285Sikob return EINVAL; 1234103285Sikob } 1235103285Sikob#else 1236103285Sikob tcode = fp->mode.common.tcode & 0xf; 1237103285Sikob info = &fc->tcode[tcode]; 1238103285Sikob if (info->flag == 0) { 1239103285Sikob printf("invalid tcode=%d\n", tcode); 1240103285Sikob return EINVAL; 1241103285Sikob } 1242103285Sikob if (info->flag & FWTI_REQ) 1243103285Sikob xferq = fc->atq; 1244103285Sikob else 1245103285Sikob xferq = fc->ats; 1246103285Sikob len = info->hdr_len; 1247103285Sikob if (info->flag & FWTI_BLOCK_STR) 1248103285Sikob len += ntohs(fp->mode.stream.len); 1249103285Sikob else if (info->flag & FWTI_BLOCK_ASY) 1250103285Sikob len += ntohs(fp->mode.rresb.len); 1251103285Sikob if( len > xfer->send.len ){ 1252103285Sikob printf("len(%d) > send.len(%d) (tcode=%d)\n", 1253103285Sikob len, xfer->send.len, tcode); 1254103285Sikob return EINVAL; 1255103285Sikob } 1256103285Sikob xfer->send.len = len; 1257103285Sikob#endif 1258103285Sikob if(xferq->start == NULL){ 1259103285Sikob printf("xferq->start == NULL\n"); 1260103285Sikob return EINVAL; 1261103285Sikob } 1262103285Sikob if(!(xferq->queued < xferq->maxq)){ 1263103285Sikob printf("%s:Discard a packet (queued=%d)\n", 1264103285Sikob device_get_nameunit(fc->dev), xferq->queued); 1265103285Sikob return EINVAL; 1266103285Sikob } 1267103285Sikob 1268103285Sikob 1269103285Sikob#if 0 1270103285Sikob switch(tcode){ 1271103285Sikob case FWTCODE_WREQQ: 1272103285Sikob case FWTCODE_WREQB: 1273103285Sikob case FWTCODE_RREQQ: 1274103285Sikob case FWTCODE_RREQB: 1275103285Sikob case FWTCODE_LREQ: 1276103285Sikob if((tl = fw_get_tlabel(fc, xfer)) == -1 ){ 1277103285Sikob return EIO; 1278103285Sikob } 1279103285Sikob fp->mode.hdr.tlrt = tl << 2; 1280103285Sikob break; 1281103285Sikob default: 1282103285Sikob break; 1283103285Sikob } 1284103285Sikob#else 1285103285Sikob if (info->flag & FWTI_TLABEL) { 1286103285Sikob if((tl = fw_get_tlabel(fc, xfer)) == -1 ) 1287103285Sikob return EIO; 1288103285Sikob fp->mode.hdr.tlrt = tl << 2; 1289103285Sikob } 1290103285Sikob#endif 1291103285Sikob 1292103285Sikob xfer->tl = tl; 1293103285Sikob xfer->tcode = tcode; 1294103285Sikob xfer->resp = 0; 1295103285Sikob xfer->fc = fc; 1296103285Sikob xfer->q = xferq; 1297103285Sikob xfer->act_type = FWACT_XFER; 1298103285Sikob xfer->retry_req = fw_asybusy; 1299103285Sikob 1300103285Sikob fw_asystart(xfer); 1301103285Sikob return err; 1302103285Sikob} 1303103285Sikob/* 1304103285Sikob * Wakeup blocked process. 1305103285Sikob */ 1306103285Sikobvoid 1307103285Sikobfw_asy_callback(struct fw_xfer *xfer){ 1308103285Sikob wakeup(xfer); 1309103285Sikob return; 1310103285Sikob} 1311103285Sikob/* 1312103285Sikob * Postpone to later retry. 1313103285Sikob */ 1314103285Sikobvoid fw_asybusy(struct fw_xfer *xfer){ 1315103285Sikob#if 0 1316103285Sikob printf("fw_asybusy\n"); 1317103285Sikob#endif 1318103285Sikob#if XFER_TIMEOUT 1319103285Sikob untimeout(fw_xfer_timeout, (void *)xfer, xfer->ch); 1320103285Sikob#endif 1321103285Sikob/* 1322103285Sikob xfer->ch = timeout((timeout_t *)fw_asystart, (void *)xfer, 20000); 1323103285Sikob*/ 1324103285Sikob DELAY(20000); 1325103285Sikob fw_asystart(xfer); 1326103285Sikob return; 1327103285Sikob} 1328103285Sikob#if XFER_TIMEOUT 1329103285Sikob/* 1330103285Sikob * Post timeout for async. request. 1331103285Sikob */ 1332103285Sikobvoid 1333103285Sikobfw_xfer_timeout(void *arg) 1334103285Sikob{ 1335103285Sikob int s; 1336103285Sikob struct fw_xfer *xfer; 1337103285Sikob 1338103285Sikob xfer = (struct fw_xfer *)arg; 1339103285Sikob printf("fw_xfer_timeout status=%d resp=%d\n", xfer->state, xfer->resp); 1340103285Sikob /* XXX set error code */ 1341103285Sikob s = splfw(); 1342103285Sikob xfer->act.hand(xfer); 1343103285Sikob splx(s); 1344103285Sikob} 1345103285Sikob#endif 1346103285Sikob/* 1347103285Sikob * Async. request with given xfer structure. 1348103285Sikob */ 1349103285Sikobstatic void fw_asystart(struct fw_xfer *xfer){ 1350103285Sikob struct firewire_comm *fc = xfer->fc; 1351103285Sikob int s; 1352103285Sikob if(xfer->retry++ >= fc->max_asyretry){ 1353103285Sikob xfer->resp = EBUSY; 1354103285Sikob xfer->state = FWXF_BUSY; 1355103285Sikob xfer->act.hand(xfer); 1356103285Sikob return; 1357103285Sikob } 1358103285Sikob#if 0 /* XXX allow bus explore packets only after bus rest */ 1359103285Sikob if (fc->status < FWBUSEXPLORE) { 1360103285Sikob xfer->resp = EAGAIN; 1361103285Sikob xfer->state = FWXF_BUSY; 1362103285Sikob if (xfer->act.hand != NULL) 1363103285Sikob xfer->act.hand(xfer); 1364103285Sikob return; 1365103285Sikob } 1366103285Sikob#endif 1367103285Sikob s = splfw(); 1368103285Sikob xfer->state = FWXF_INQ; 1369103285Sikob STAILQ_INSERT_TAIL(&xfer->q->q, xfer, link); 1370103285Sikob xfer->q->queued ++; 1371103285Sikob splx(s); 1372103285Sikob /* XXX just queue for mbuf */ 1373103285Sikob if (xfer->mbuf == NULL) 1374103285Sikob xfer->q->start(fc); 1375103285Sikob#if XFER_TIMEOUT 1376103285Sikob if (xfer->act.hand != NULL) 1377103285Sikob xfer->ch = timeout(fw_xfer_timeout, (void *)xfer, hz); 1378103285Sikob#endif 1379103285Sikob return; 1380103285Sikob} 1381103285Sikobstatic int 1382103285Sikobfw_mmap (dev_t dev, vm_offset_t offset, int nproto) 1383103285Sikob{ 1384103285Sikob struct firewire_softc *fc; 1385103285Sikob int unit = DEV2UNIT(dev); 1386103285Sikob 1387103285Sikob if (DEV_FWMEM(dev)) 1388103285Sikob return fwmem_mmap(dev, offset, nproto); 1389103285Sikob 1390103285Sikob fc = devclass_get_softc(firewire_devclass, unit); 1391103285Sikob 1392103285Sikob return EINVAL; 1393103285Sikob} 1394103285Sikobstatic int 1395103285Sikobfirewire_match( device_t dev ) 1396103285Sikob{ 1397103285Sikob device_set_desc(dev, "IEEE1394(Firewire) bus"); 1398103285Sikob return -140; 1399103285Sikob} 1400103285Sikob/* 1401103285Sikob * The attach routine. 1402103285Sikob */ 1403103285Sikobstatic int 1404103285Sikobfirewire_attach( device_t dev ) 1405103285Sikob{ 1406103285Sikob int i, unitmask, mn; 1407103285Sikob struct firewire_softc *sc = device_get_softc(dev); 1408103285Sikob device_t pa = device_get_parent(dev); 1409103285Sikob struct firewire_comm *fc; 1410103285Sikob dev_t d; 1411103285Sikob 1412103285Sikob fc = (struct firewire_comm *)device_get_softc(pa); 1413103285Sikob sc->fc = fc; 1414103285Sikob sc->fc->dev = dev; 1415103285Sikob 1416103285Sikob unitmask = UNIT2MIN(device_get_unit(dev)); 1417103285Sikob 1418103285Sikob if( fc->nisodma > FWMAXNDMA) fc->nisodma = FWMAXNDMA; 1419103285Sikob for ( i = 0 ; i < fc->nisodma ; i++ ){ 1420103285Sikob mn = unitmask | i; 1421103285Sikob /* XXX device name should be improved */ 1422103285Sikob d = make_dev(&firewire_cdevsw, unit2minor(mn), 1423103285Sikob UID_ROOT, GID_OPERATOR, 0770, 1424103285Sikob "fw%x", mn); 1425103285Sikob#if __FreeBSD_version >= 500000 1426103285Sikob if (i == 0) 1427103285Sikob sc->dev = d; 1428103285Sikob else 1429103285Sikob dev_depends(sc->dev, d); 1430103285Sikob#else 1431103285Sikob sc->dev[i] = d; 1432103285Sikob#endif 1433103285Sikob } 1434103285Sikob d = make_dev(&firewire_cdevsw, unit2minor(unitmask | FWMEM_FLAG), 1435103285Sikob UID_ROOT, GID_OPERATOR, 0770, 1436103285Sikob "fwmem%d", device_get_unit(dev)); 1437103285Sikob#if __FreeBSD_version >= 500000 1438103285Sikob dev_depends(sc->dev, d); 1439103285Sikob#else 1440103285Sikob sc->dev[i] = d; 1441103285Sikob#endif 1442103285Sikob printf("%s: firewire bus attach\n", device_get_nameunit(sc->fc->dev)); 1443103285Sikob sc->fc->timeouthandle = timeout((timeout_t *)sc->fc->timeout, (void *)sc->fc, hz * 10); 1444103285Sikob 1445103285Sikob /* Locate our children */ 1446103285Sikob bus_generic_probe(dev); 1447103285Sikob 1448103285Sikob /* launch attachement of the added children */ 1449103285Sikob bus_generic_attach(dev); 1450103285Sikob 1451103285Sikob /* bus_reset */ 1452103285Sikob fc->ibr(fc); 1453103285Sikob 1454103285Sikob return 0; 1455103285Sikob} 1456103285Sikob 1457103285Sikob/* 1458103285Sikob * Attach it as child. 1459103285Sikob */ 1460103285Sikobstatic device_t 1461103285Sikobfirewire_add_child(device_t dev, int order, const char *name, int unit) 1462103285Sikob{ 1463103285Sikob device_t child; 1464103285Sikob struct firewire_softc *sc; 1465103285Sikob 1466103285Sikob sc = (struct firewire_softc *)device_get_softc(dev); 1467103285Sikob child = device_add_child(dev, name, unit); 1468103285Sikob if (child) { 1469103285Sikob device_set_ivars(child, sc->fc); 1470103285Sikob device_probe_and_attach(child); 1471103285Sikob } 1472103285Sikob 1473103285Sikob return child; 1474103285Sikob} 1475103285Sikob/* 1476103285Sikob * Dettach it. 1477103285Sikob */ 1478103285Sikobstatic int 1479103285Sikobfirewire_detach( device_t dev ) 1480103285Sikob{ 1481103285Sikob struct firewire_softc *sc; 1482103285Sikob 1483103285Sikob sc = (struct firewire_softc *)device_get_softc(dev); 1484103285Sikob#if 0 1485103285Sikob printf("%s:dettach prevented", device_get_nameunit(dev)); 1486103285Sikob return(EINVAL); 1487103285Sikob#endif 1488103285Sikob#if __FreeBSD_version >= 500000 1489103285Sikob destroy_dev(sc->dev); 1490103285Sikob#else 1491103285Sikob { 1492103285Sikob int j; 1493103285Sikob for (j = 0 ; j < sc->fc->nisodma + 1; j++) 1494103285Sikob destroy_dev(sc->dev[j]); 1495103285Sikob } 1496103285Sikob#endif 1497103285Sikob /* XXX xfree_free and untimeout on all xfers */ 1498103285Sikob untimeout((timeout_t *)sc->fc->timeout, sc->fc, sc->fc->timeouthandle); 1499103285Sikob free(sc->fc->topology_map, M_DEVBUF); 1500103285Sikob free(sc->fc->speed_map, M_DEVBUF); 1501103285Sikob bus_generic_detach(dev); 1502103285Sikob return(0); 1503103285Sikob} 1504103285Sikob#if 0 1505103285Sikobstatic int 1506103285Sikobfirewire_shutdown( device_t dev ) 1507103285Sikob{ 1508103285Sikob return 0; 1509103285Sikob} 1510103285Sikob#endif 1511103285Sikob/* 1512103285Sikob * Call ater bus reset. 1513103285Sikob */ 1514103285Sikobvoid fw_busreset(struct firewire_comm *fc) 1515103285Sikob{ 1516103285Sikob int i; 1517103285Sikob struct fw_xfer *xfer; 1518103285Sikob 1519103285Sikob switch(fc->status){ 1520103285Sikob case FWBUSMGRELECT: 1521103285Sikob untimeout((timeout_t *)fw_try_bmr, (void *)fc, fc->bmrhandle); 1522103285Sikob break; 1523103285Sikob default: 1524103285Sikob break; 1525103285Sikob } 1526103285Sikob fc->status = FWBUSRESET; 1527103285Sikob/* XXX: discard all queued packet */ 1528103285Sikob while((xfer = STAILQ_FIRST(&fc->atq->q)) != NULL){ 1529103285Sikob STAILQ_REMOVE_HEAD(&fc->atq->q, link); 1530103285Sikob xfer->resp = EAGAIN; 1531103285Sikob switch(xfer->act_type){ 1532103285Sikob case FWACT_XFER: 1533103285Sikob fw_xfer_done(xfer); 1534103285Sikob break; 1535103285Sikob default: 1536103285Sikob break; 1537103285Sikob } 1538103285Sikob fw_xfer_free( xfer); 1539103285Sikob } 1540103285Sikob while((xfer = STAILQ_FIRST(&fc->ats->q)) != NULL){ 1541103285Sikob STAILQ_REMOVE_HEAD(&fc->ats->q, link); 1542103285Sikob xfer->resp = EAGAIN; 1543103285Sikob switch(xfer->act_type){ 1544103285Sikob case FWACT_XFER: 1545103285Sikob fw_xfer_done(xfer); 1546103285Sikob default: 1547103285Sikob break; 1548103285Sikob } 1549103285Sikob fw_xfer_free( xfer); 1550103285Sikob } 1551103285Sikob for(i = 0; i < fc->nisodma; i++) 1552103285Sikob while((xfer = STAILQ_FIRST(&fc->it[i]->q)) != NULL){ 1553103285Sikob STAILQ_REMOVE_HEAD(&fc->it[i]->q, link); 1554103285Sikob xfer->resp = 0; 1555103285Sikob switch(xfer->act_type){ 1556103285Sikob case FWACT_XFER: 1557103285Sikob fw_xfer_done(xfer); 1558103285Sikob break; 1559103285Sikob default: 1560103285Sikob break; 1561103285Sikob } 1562103285Sikob fw_xfer_free( xfer); 1563103285Sikob } 1564103285Sikob 1565103285Sikob CSRARC(fc, STATE_CLEAR) 1566103285Sikob = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14 ; 1567103285Sikob CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR); 1568103285Sikob CSRARC(fc, NODE_IDS) = 0x3f; 1569103285Sikob 1570103285Sikob CSRARC(fc, TOPO_MAP + 8) = 0; 1571103285Sikob fc->irm = -1; 1572103285Sikob 1573103285Sikob fc->max_node = -1; 1574103285Sikob 1575103285Sikob for(i = 2; i < 0x100/4 - 2 ; i++){ 1576103285Sikob CSRARC(fc, SPED_MAP + i * 4) = 0; 1577103285Sikob } 1578103285Sikob CSRARC(fc, STATE_CLEAR) = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14 ; 1579103285Sikob CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR); 1580103285Sikob CSRARC(fc, RESET_START) = 0; 1581103285Sikob CSRARC(fc, SPLIT_TIMEOUT_HI) = 0; 1582103285Sikob CSRARC(fc, SPLIT_TIMEOUT_LO) = 800 << 19; 1583103285Sikob CSRARC(fc, CYCLE_TIME) = 0x0; 1584103285Sikob CSRARC(fc, BUS_TIME) = 0x0; 1585103285Sikob CSRARC(fc, BUS_MGR_ID) = 0x3f; 1586103285Sikob CSRARC(fc, BANDWIDTH_AV) = 4915; 1587103285Sikob CSRARC(fc, CHANNELS_AV_HI) = 0xffffffff; 1588103285Sikob CSRARC(fc, CHANNELS_AV_LO) = 0xffffffff; 1589103285Sikob CSRARC(fc, IP_CHANNELS) = (1 << 31); 1590103285Sikob 1591103285Sikob CSRARC(fc, CONF_ROM) = 0x04 << 24; 1592103285Sikob CSRARC(fc, CONF_ROM + 4) = 0x31333934; /* means strings 1394 */ 1593103285Sikob CSRARC(fc, CONF_ROM + 8) = 1 << 31 | 1 << 30 | 1 << 29 | 1594103285Sikob 1 << 28 | 0xff << 16 | 0x09 << 8; 1595103285Sikob CSRARC(fc, CONF_ROM + 0xc) = 0; 1596103285Sikob 1597103285Sikob/* DV depend CSRs see blue book */ 1598103285Sikob CSRARC(fc, oPCR) &= ~DV_BROADCAST_ON; 1599103285Sikob CSRARC(fc, iPCR) &= ~DV_BROADCAST_ON; 1600103285Sikob 1601103285Sikob CSRARC(fc, STATE_CLEAR) &= ~(1 << 23 | 1 << 15 | 1 << 14 ); 1602103285Sikob CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR); 1603103285Sikob} 1604103285Sikob/* Call once after reboot */ 1605103285Sikobvoid fw_init(fc) 1606103285Sikob struct firewire_comm *fc; 1607103285Sikob{ 1608103285Sikob int i; 1609106543Ssimokawa struct csrdir *csrd; 1610106543Ssimokawa#ifdef FW_VMACCESS 1611103285Sikob struct fw_xfer *xfer; 1612103285Sikob struct fw_bind *fwb; 1613106543Ssimokawa#endif 1614103285Sikob 1615103285Sikob fc->max_asyretry = FW_MAXASYRTY; 1616103285Sikob 1617103285Sikob fc->arq->queued = 0; 1618103285Sikob fc->ars->queued = 0; 1619103285Sikob fc->atq->queued = 0; 1620103285Sikob fc->ats->queued = 0; 1621103285Sikob 1622103285Sikob fc->arq->psize = FWPMAX_S400; 1623103285Sikob fc->ars->psize = FWPMAX_S400; 1624103285Sikob fc->atq->psize = FWPMAX_S400; 1625103285Sikob fc->ats->psize = FWPMAX_S400; 1626103285Sikob 1627103285Sikob 1628103285Sikob fc->arq->buf = NULL; 1629103285Sikob fc->ars->buf = NULL; 1630103285Sikob fc->atq->buf = NULL; 1631103285Sikob fc->ats->buf = NULL; 1632103285Sikob 1633103285Sikob fc->arq->flag = FWXFERQ_PACKET; 1634103285Sikob fc->ars->flag = FWXFERQ_PACKET; 1635103285Sikob fc->atq->flag = FWXFERQ_PACKET; 1636103285Sikob fc->ats->flag = FWXFERQ_PACKET; 1637103285Sikob 1638103285Sikob STAILQ_INIT(&fc->atq->q); 1639103285Sikob STAILQ_INIT(&fc->ats->q); 1640103285Sikob 1641103285Sikob for( i = 0 ; i < fc->nisodma ; i ++ ){ 1642103285Sikob fc->it[i]->queued = 0; 1643103285Sikob fc->ir[i]->queued = 0; 1644103285Sikob 1645103285Sikob fc->it[i]->start = NULL; 1646103285Sikob fc->ir[i]->start = NULL; 1647103285Sikob 1648103285Sikob fc->it[i]->buf = NULL; 1649103285Sikob fc->ir[i]->buf = NULL; 1650103285Sikob 1651103285Sikob fc->it[i]->flag = FWXFERQ_STREAM; 1652103285Sikob fc->ir[i]->flag = FWXFERQ_STREAM; 1653103285Sikob 1654103285Sikob STAILQ_INIT(&fc->it[i]->q); 1655103285Sikob STAILQ_INIT(&fc->ir[i]->q); 1656103285Sikob 1657103285Sikob STAILQ_INIT(&fc->it[i]->binds); 1658103285Sikob STAILQ_INIT(&fc->ir[i]->binds); 1659103285Sikob } 1660103285Sikob 1661103285Sikob fc->arq->maxq = FWMAXQUEUE; 1662103285Sikob fc->ars->maxq = FWMAXQUEUE; 1663103285Sikob fc->atq->maxq = FWMAXQUEUE; 1664103285Sikob fc->ats->maxq = FWMAXQUEUE; 1665103285Sikob 1666103285Sikob for( i = 0 ; i < fc->nisodma ; i++){ 1667103285Sikob fc->ir[i]->maxq = FWMAXQUEUE; 1668103285Sikob fc->it[i]->maxq = FWMAXQUEUE; 1669103285Sikob } 1670103285Sikob/* Initialize csr registers */ 1671103285Sikob fc->topology_map = (struct fw_topology_map *)malloc( 1672103285Sikob sizeof(struct fw_topology_map), 1673103285Sikob M_DEVBUF, M_DONTWAIT | M_ZERO); 1674103285Sikob fc->speed_map = (struct fw_speed_map *)malloc( 1675103285Sikob sizeof(struct fw_speed_map), 1676103285Sikob M_DEVBUF, M_DONTWAIT | M_ZERO); 1677103285Sikob CSRARC(fc, TOPO_MAP) = 0x3f1 << 16; 1678103285Sikob CSRARC(fc, TOPO_MAP + 4) = 1; 1679103285Sikob CSRARC(fc, SPED_MAP) = 0x3f1 << 16; 1680103285Sikob CSRARC(fc, SPED_MAP + 4) = 1; 1681103285Sikob 1682103285Sikob TAILQ_INIT(&fc->devices); 1683103285Sikob STAILQ_INIT(&fc->pending); 1684103285Sikob 1685103285Sikob/* Initialize csr ROM work space */ 1686103285Sikob SLIST_INIT(&fc->ongocsr); 1687103285Sikob SLIST_INIT(&fc->csrfree); 1688103285Sikob for( i = 0 ; i < FWMAXCSRDIR ; i++){ 1689103285Sikob csrd = (struct csrdir *) malloc(sizeof(struct csrdir), M_DEVBUF,M_DONTWAIT); 1690103285Sikob if(csrd == NULL) break; 1691103285Sikob SLIST_INSERT_HEAD(&fc->csrfree, csrd, link); 1692103285Sikob } 1693103285Sikob 1694103285Sikob/* Initialize Async handlers */ 1695103285Sikob STAILQ_INIT(&fc->binds); 1696103285Sikob for( i = 0 ; i < 0x40 ; i++){ 1697103285Sikob STAILQ_INIT(&fc->tlabels[i]); 1698103285Sikob } 1699103285Sikob 1700103285Sikob/* DV depend CSRs see blue book */ 1701103285Sikob#if 0 1702103285Sikob CSRARC(fc, oMPR) = 0x3fff0001; /* # output channel = 1 */ 1703103285Sikob CSRARC(fc, oPCR) = 0x8000007a; 1704103285Sikob for(i = 4 ; i < 0x7c/4 ; i+=4){ 1705103285Sikob CSRARC(fc, i + oPCR) = 0x8000007a; 1706103285Sikob } 1707103285Sikob 1708103285Sikob CSRARC(fc, iMPR) = 0x00ff0001; /* # input channel = 1 */ 1709103285Sikob CSRARC(fc, iPCR) = 0x803f0000; 1710103285Sikob for(i = 4 ; i < 0x7c/4 ; i+=4){ 1711103285Sikob CSRARC(fc, i + iPCR) = 0x0; 1712103285Sikob } 1713103285Sikob#endif 1714103285Sikob 1715103285Sikob 1716106543Ssimokawa#ifdef FW_VMACCESS 1717103285Sikob xfer = fw_xfer_alloc(); 1718103285Sikob if(xfer == NULL) return; 1719103285Sikob 1720103285Sikob fwb = (struct fw_bind *)malloc(sizeof (struct fw_bind), M_DEVBUF, M_DONTWAIT); 1721103285Sikob if(fwb == NULL){ 1722103285Sikob fw_xfer_free(xfer); 1723103285Sikob } 1724103285Sikob xfer->act.hand = fw_vmaccess; 1725103285Sikob xfer->act_type = FWACT_XFER; 1726103285Sikob xfer->fc = fc; 1727103285Sikob xfer->sc = NULL; 1728103285Sikob 1729103285Sikob fwb->start_hi = 0x2; 1730103285Sikob fwb->start_lo = 0; 1731103285Sikob fwb->addrlen = 0xffffffff; 1732103285Sikob fwb->xfer = xfer; 1733103285Sikob fw_bindadd(fc, fwb); 1734106543Ssimokawa#endif 1735103285Sikob} 1736103285Sikob/* 1737103285Sikob * To lookup binded process from IEEE1394 address. 1738103285Sikob */ 1739103285Sikobstatic struct fw_bind * 1740103285Sikobfw_bindlookup(fc, dest_hi, dest_lo) 1741103285Sikobstruct firewire_comm *fc; 1742103285Sikobu_int32_t dest_lo, dest_hi; 1743103285Sikob{ 1744103285Sikob struct fw_bind *tfw; 1745103285Sikob for(tfw = STAILQ_FIRST(&fc->binds) ; tfw != NULL ; 1746103285Sikob tfw = STAILQ_NEXT(tfw, fclist)){ 1747103285Sikob if(tfw->xfer->act_type != FWACT_NULL && 1748103285Sikob tfw->start_hi == dest_hi && 1749103285Sikob tfw->start_lo <= dest_lo && 1750103285Sikob (tfw->start_lo + tfw->addrlen) > dest_lo){ 1751103285Sikob return(tfw); 1752103285Sikob } 1753103285Sikob } 1754103285Sikob return(NULL); 1755103285Sikob} 1756103285Sikob/* 1757103285Sikob * To bind IEEE1394 address block to process. 1758103285Sikob */ 1759103285Sikobint fw_bindadd(struct firewire_comm *fc, struct fw_bind *fwb) 1760103285Sikob{ 1761103285Sikob struct fw_bind *tfw, *tfw2 = NULL; 1762103285Sikob int err = 0; 1763103285Sikob tfw = STAILQ_FIRST(&fc->binds); 1764103285Sikob if(tfw == NULL){ 1765103285Sikob STAILQ_INSERT_HEAD(&fc->binds, fwb, fclist); 1766103285Sikob goto out; 1767103285Sikob } 1768103285Sikob if((tfw->start_hi > fwb->start_hi) || 1769103285Sikob (tfw->start_hi == fwb->start_hi && 1770103285Sikob (tfw->start_lo > (fwb->start_lo + fwb->addrlen)))){ 1771103285Sikob STAILQ_INSERT_HEAD(&fc->binds, fwb, fclist); 1772103285Sikob goto out; 1773103285Sikob } 1774103285Sikob for(; tfw != NULL; tfw = STAILQ_NEXT(tfw, fclist)){ 1775103285Sikob if((tfw->start_hi < fwb->start_hi) || 1776103285Sikob (tfw->start_hi == fwb->start_hi && 1777103285Sikob (tfw->start_lo + tfw->addrlen) < fwb->start_lo)){ 1778103285Sikob tfw2 = STAILQ_NEXT(tfw, fclist); 1779103285Sikob if(tfw2 == NULL) 1780103285Sikob break; 1781103285Sikob if((tfw2->start_hi > fwb->start_hi) || 1782103285Sikob (tfw2->start_hi == fwb->start_hi && 1783103285Sikob tfw2->start_lo > (fwb->start_lo + fwb->addrlen))){ 1784103285Sikob break; 1785103285Sikob }else{ 1786103285Sikob err = EBUSY; 1787103285Sikob goto out; 1788103285Sikob } 1789103285Sikob } 1790103285Sikob } 1791103285Sikob if(tfw != NULL){ 1792103285Sikob STAILQ_INSERT_AFTER(&fc->binds, tfw, fwb, fclist); 1793103285Sikob }else{ 1794103285Sikob STAILQ_INSERT_TAIL(&fc->binds, fwb, fclist); 1795103285Sikob } 1796103285Sikobout: 1797103285Sikob if(!err && fwb->xfer->act_type == FWACT_CH){ 1798103285Sikob STAILQ_INSERT_HEAD(&fc->ir[fwb->xfer->sub]->binds, fwb, chlist); 1799103285Sikob } 1800103285Sikob return err; 1801103285Sikob} 1802103285Sikob 1803103285Sikob/* 1804103285Sikob * To free IEEE1394 address block. 1805103285Sikob */ 1806103285Sikobint fw_bindremove(struct firewire_comm *fc, struct fw_bind *fwb) 1807103285Sikob{ 1808103285Sikob int s; 1809103285Sikob 1810103285Sikob s = splfw(); 1811103285Sikob /* shall we check the existance? */ 1812103285Sikob STAILQ_REMOVE(&fc->binds, fwb, fw_bind, fclist); 1813103285Sikob splx(s); 1814103285Sikob if (fwb->xfer) 1815103285Sikob fw_xfer_free(fwb->xfer); 1816103285Sikob 1817103285Sikob return 0; 1818103285Sikob} 1819103285Sikob 1820103285Sikob/* 1821103285Sikob * To free transaction label. 1822103285Sikob */ 1823103285Sikobstatic void fw_tl_free ( struct firewire_comm *fc, struct fw_xfer *xfer ) 1824103285Sikob{ 1825103285Sikob struct tlabel *tl; 1826103285Sikob int s = splfw(); 1827103285Sikob 1828103285Sikob for( tl = STAILQ_FIRST(&fc->tlabels[xfer->tl]); tl != NULL; 1829103285Sikob tl = STAILQ_NEXT(tl, link)){ 1830103285Sikob if(tl->xfer == xfer){ 1831103285Sikob STAILQ_REMOVE(&fc->tlabels[xfer->tl], tl, tlabel, link); 1832103285Sikob free(tl, M_DEVBUF); 1833103285Sikob splx(s); 1834103285Sikob return; 1835103285Sikob } 1836103285Sikob } 1837103285Sikob splx(s); 1838103285Sikob return; 1839103285Sikob} 1840103285Sikob/* 1841103285Sikob * To obtain XFER structure by transaction label. 1842103285Sikob */ 1843103285Sikobstatic struct fw_xfer *fw_tl2xfer ( struct firewire_comm *fc, int node, int tlabel ) 1844103285Sikob{ 1845103285Sikob struct fw_xfer *xfer; 1846103285Sikob struct tlabel *tl; 1847103285Sikob int s = splfw(); 1848103285Sikob 1849103285Sikob for( tl = STAILQ_FIRST(&fc->tlabels[tlabel]); tl != NULL; 1850103285Sikob tl = STAILQ_NEXT(tl, link)){ 1851103285Sikob if(tl->xfer->dst == node){ 1852103285Sikob xfer = tl->xfer; 1853103285Sikob#if 0 1854103285Sikob STAILQ_REMOVE(&fc->tlabels[tlabel], tl, tlabel, link); 1855103285Sikob free(tl, M_DEVBUF); 1856103285Sikob#endif 1857103285Sikob splx(s); 1858103285Sikob return(xfer); 1859103285Sikob } 1860103285Sikob } 1861103285Sikob splx(s); 1862103285Sikob return(NULL); 1863103285Sikob} 1864103285Sikob/* 1865103285Sikob * To allocate IEEE1394 XFER structure. 1866103285Sikob */ 1867103285Sikobstruct fw_xfer *fw_xfer_alloc() 1868103285Sikob{ 1869103285Sikob struct fw_xfer *xfer; 1870103285Sikob#if 0 1871103285Sikob xfer = malloc(sizeof(struct fw_xfer), M_DEVBUF, M_DONTWAIT); 1872103285Sikob#else 1873103285Sikob xfer = malloc(sizeof(struct fw_xfer), M_DEVBUF, M_DONTWAIT | M_ZERO); 1874103285Sikob#endif 1875103285Sikob if(xfer == NULL) return xfer; 1876103285Sikob#if 0 /* xfer->tl = 0 was missing.. */ 1877103285Sikob xfer->act_type = FWACT_NULL; 1878103285Sikob xfer->fc = NULL; 1879103285Sikob xfer->retry = 0; 1880103285Sikob xfer->resp = 0; 1881103285Sikob xfer->state = FWXF_INIT; 1882103285Sikob xfer->time = time_second; 1883103285Sikob xfer->sub = -1; 1884103285Sikob xfer->send.buf = NULL; 1885103285Sikob xfer->send.off = 0; 1886103285Sikob xfer->send.len = 0; 1887103285Sikob xfer->recv.buf = NULL; 1888103285Sikob xfer->recv.off = 0; 1889103285Sikob xfer->recv.len = 0; 1890103285Sikob xfer->retry_req = NULL; 1891103285Sikob xfer->act.hand = NULL; 1892103285Sikob xfer->sc = NULL; 1893103285Sikob#else 1894103285Sikob xfer->time = time_second; 1895103285Sikob xfer->sub = -1; 1896103285Sikob#endif 1897103285Sikob return xfer; 1898103285Sikob} 1899103285Sikob/* 1900103285Sikob * IEEE1394 XFER post process. 1901103285Sikob */ 1902103285Sikobvoid 1903103285Sikobfw_xfer_done(struct fw_xfer *xfer) 1904103285Sikob{ 1905103285Sikob if (xfer->act.hand == NULL) 1906103285Sikob return; 1907103285Sikob 1908103285Sikob#if XFER_TIMEOUT 1909103285Sikob untimeout(fw_xfer_timeout, (void *)xfer, xfer->ch); 1910103285Sikob#endif 1911103285Sikob 1912103285Sikob if (xfer->fc->status != FWBUSRESET) 1913103285Sikob xfer->act.hand(xfer); 1914103285Sikob else { 1915103285Sikob printf("fw_xfer_done: pending\n"); 1916103285Sikob if (xfer->fc != NULL) 1917103285Sikob STAILQ_INSERT_TAIL(&xfer->fc->pending, xfer, link); 1918103285Sikob else 1919103285Sikob panic("fw_xfer_done: why xfer->fc is NULL?"); 1920103285Sikob } 1921103285Sikob} 1922103285Sikob 1923103285Sikob/* 1924103285Sikob * To free IEEE1394 XFER structure. 1925103285Sikob */ 1926103285Sikobvoid fw_xfer_free( struct fw_xfer* xfer) 1927103285Sikob{ 1928103285Sikob int s; 1929103285Sikob if(xfer == NULL ) return; 1930103285Sikob if(xfer->state == FWXF_INQ){ 1931103285Sikob printf("fw_xfer_free FWXF_INQ\n"); 1932103285Sikob s = splfw(); 1933103285Sikob STAILQ_REMOVE(&xfer->q->q, xfer, fw_xfer, link); 1934103285Sikob xfer->q->queued --; 1935103285Sikob splx(s); 1936103285Sikob } 1937103285Sikob if(xfer->fc != NULL){ 1938103285Sikob if(xfer->state == FWXF_START){ 1939103285Sikob#if 0 /* this could happen if we call fwohci_arcv() before fwohci_txd() */ 1940103285Sikob printf("fw_xfer_free FWXF_START\n"); 1941103285Sikob#endif 1942103285Sikob s = splfw(); 1943103285Sikob xfer->q->drain(xfer->fc, xfer); 1944103285Sikob splx(s); 1945103285Sikob } 1946103285Sikob } 1947103285Sikob if(xfer->send.buf != NULL){ 1948103285Sikob free(xfer->send.buf, M_DEVBUF); 1949103285Sikob } 1950103285Sikob if(xfer->recv.buf != NULL){ 1951103285Sikob free(xfer->recv.buf, M_DEVBUF); 1952103285Sikob } 1953103285Sikob if(xfer->fc != NULL){ 1954103285Sikob fw_tl_free(xfer->fc, xfer); 1955103285Sikob } 1956103285Sikob free(xfer, M_DEVBUF); 1957103285Sikob} 1958103285Sikob 1959103285Sikob/* 1960103285Sikob * Callback for PHY configuration. 1961103285Sikob */ 1962103285Sikobstatic void 1963103285Sikobfw_phy_config_callback(struct fw_xfer *xfer) 1964103285Sikob{ 1965103285Sikob#if 0 1966103285Sikob printf("phy_config done state=%d resp=%d\n", 1967103285Sikob xfer->state, xfer->resp); 1968103285Sikob#endif 1969103285Sikob fw_xfer_free(xfer); 1970103285Sikob /* XXX need bus reset ?? */ 1971103285Sikob /* sc->fc->ibr(xfer->fc); LOOP */ 1972103285Sikob} 1973103285Sikob 1974103285Sikob/* 1975103285Sikob * To configure PHY. 1976103285Sikob */ 1977103285Sikobstatic void 1978103285Sikobfw_phy_config(struct firewire_comm *fc, int root_node, int gap_count) 1979103285Sikob{ 1980103285Sikob struct fw_xfer *xfer; 1981103285Sikob struct fw_pkt *fp; 1982103285Sikob 1983103285Sikob fc->status = FWBUSPHYCONF; 1984103285Sikob 1985103285Sikob DELAY(100000); 1986103285Sikob xfer = fw_xfer_alloc(); 1987103285Sikob xfer->send.len = 12; 1988103285Sikob xfer->send.off = 0; 1989103285Sikob xfer->fc = fc; 1990103285Sikob xfer->retry_req = fw_asybusy; 1991103285Sikob xfer->act.hand = fw_phy_config_callback; 1992103285Sikob 1993103285Sikob xfer->send.buf = malloc(sizeof(u_int32_t), 1994103285Sikob M_DEVBUF, M_DONTWAIT | M_ZERO); 1995103285Sikob fp = (struct fw_pkt *)xfer->send.buf; 1996103285Sikob fp->mode.ld[1] = 0; 1997103285Sikob if (root_node >= 0) 1998103285Sikob fp->mode.ld[1] |= htonl((root_node & 0x3f) << 24 | 1 << 23); 1999103285Sikob if (gap_count >= 0) 2000103285Sikob fp->mode.ld[1] |= htonl(1 << 22 | (gap_count & 0x3f) << 16); 2001103285Sikob fp->mode.ld[2] = ~fp->mode.ld[1]; 2002103285Sikob/* XXX Dangerous, how to pass PHY packet to device driver */ 2003103285Sikob fp->mode.common.tcode |= FWTCODE_PHY; 2004103285Sikob 2005103285Sikob printf("send phy_config root_node=%d gap_count=%d\n", 2006103285Sikob root_node, gap_count); 2007103285Sikob fw_asyreq(fc, -1, xfer); 2008103285Sikob} 2009103285Sikob 2010103285Sikob#if 0 2011103285Sikob/* 2012103285Sikob * Dump self ID. 2013103285Sikob */ 2014103285Sikobstatic void 2015103285Sikobfw_print_sid(u_int32_t sid) 2016103285Sikob{ 2017103285Sikob#if 0 2018103285Sikob printf("node:%d link:%d gap:%d spd:%d del:%d con:%d pwr:%d" 2019103285Sikob " p0:%d p1:%d p2:%d i:%d m:%d\n", 2020103285Sikob FWPHYSIDNODE(sid), FWPHYSIDLINK(sid), FWPHYSIDGAP(sid), 2021103285Sikob FWPHYSIDSPD(sid), FWPHYSIDDEL(sid), FWPHYSIDCON(sid), 2022103285Sikob FWPHYSIDPWR(sid), FWPHYSIDP0(sid), FWPHYSIDP1(sid), 2023103285Sikob FWPHYSIDP2(sid), FWPHYSIDIR(sid), FWPHYSIDMORE(sid)); 2024103285Sikob#else 2025103285Sikob union fw_self_id *s; 2026103285Sikob s = (union fw_self_id *) &sid; 2027103285Sikob printf("node:%d link:%d gap:%d spd:%d del:%d con:%d pwr:%d" 2028103285Sikob " p0:%d p1:%d p2:%d i:%d m:%d\n", 2029103285Sikob s->p0.phy_id, s->p0.link_active, s->p0.gap_count, 2030103285Sikob s->p0.phy_speed, s->p0.phy_delay, s->p0.contender, 2031103285Sikob s->p0.power_class, s->p0.port0, s->p0.port1, 2032103285Sikob s->p0.port2, s->p0.initiated_reset, s->p0.more_packets); 2033103285Sikob#endif 2034103285Sikob} 2035103285Sikob#endif 2036103285Sikob 2037103285Sikob/* 2038103285Sikob * To receive self ID. 2039103285Sikob */ 2040103285Sikobvoid fw_sidrcv(struct firewire_comm* fc, caddr_t buf, u_int len, u_int off) 2041103285Sikob{ 2042103285Sikob u_int32_t *p, *sid = (u_int32_t *)(buf + off); 2043103285Sikob union fw_self_id *self_id; 2044103285Sikob u_int i, j, node, c_port = 0, i_branch = 0; 2045103285Sikob 2046103285Sikob fc->sid_cnt = len /(sizeof(u_int32_t) * 2); 2047103285Sikob fc->status = FWBUSINIT; 2048103285Sikob fc->max_node = fc->nodeid & 0x3f; 2049103285Sikob CSRARC(fc, NODE_IDS) = ((u_int32_t)fc->nodeid) << 16; 2050103285Sikob fc->status = FWBUSCYMELECT; 2051103285Sikob fc->topology_map->crc_len = 2; 2052103285Sikob fc->topology_map->generation ++; 2053103285Sikob fc->topology_map->self_id_count = 0; 2054103285Sikob fc->topology_map->node_count = 0; 2055103285Sikob fc->speed_map->generation ++; 2056103285Sikob fc->speed_map->crc_len = 1 + (64*64 + 3) / 4; 2057103285Sikob self_id = &fc->topology_map->self_id[0]; 2058103285Sikob for(i = 0; i < fc->sid_cnt; i ++){ 2059103285Sikob if (sid[1] != ~sid[0]) { 2060103285Sikob printf("fw_sidrcv: invalid self-id packet\n"); 2061103285Sikob sid += 2; 2062103285Sikob continue; 2063103285Sikob } 2064103285Sikob *self_id = *((union fw_self_id *)sid); 2065103285Sikob fc->topology_map->crc_len++; 2066103285Sikob if(self_id->p0.sequel == 0){ 2067103285Sikob fc->topology_map->node_count ++; 2068103285Sikob c_port = 0; 2069103285Sikob#if 0 2070103285Sikob fw_print_sid(sid[0]); 2071103285Sikob#endif 2072103285Sikob node = self_id->p0.phy_id; 2073103285Sikob if(fc->max_node < node){ 2074103285Sikob fc->max_node = self_id->p0.phy_id; 2075103285Sikob } 2076103285Sikob /* XXX I'm not sure this is the right speed_map */ 2077103285Sikob fc->speed_map->speed[node][node] 2078103285Sikob = self_id->p0.phy_speed; 2079103285Sikob for (j = 0; j < node; j ++) { 2080103285Sikob fc->speed_map->speed[j][node] 2081103285Sikob = fc->speed_map->speed[node][j] 2082103285Sikob = min(fc->speed_map->speed[j][j], 2083103285Sikob self_id->p0.phy_speed); 2084103285Sikob } 2085103285Sikob if ((fc->irm == -1 || self_id->p0.phy_id > fc->irm) && 2086103285Sikob (self_id->p0.link_active && self_id->p0.contender)) { 2087103285Sikob fc->irm = self_id->p0.phy_id; 2088103285Sikob } 2089103285Sikob if(self_id->p0.port0 >= 0x2){ 2090103285Sikob c_port++; 2091103285Sikob } 2092103285Sikob if(self_id->p0.port1 >= 0x2){ 2093103285Sikob c_port++; 2094103285Sikob } 2095103285Sikob if(self_id->p0.port2 >= 0x2){ 2096103285Sikob c_port++; 2097103285Sikob } 2098103285Sikob } 2099103285Sikob if(c_port > 2){ 2100103285Sikob i_branch += (c_port - 2); 2101103285Sikob } 2102103285Sikob sid += 2; 2103103285Sikob self_id++; 2104103285Sikob fc->topology_map->self_id_count ++; 2105103285Sikob } 2106103285Sikob printf("%s: %d nodes", device_get_nameunit(fc->dev), fc->max_node + 1); 2107103285Sikob /* CRC */ 2108103285Sikob fc->topology_map->crc = fw_crc16( 2109103285Sikob (u_int32_t *)&fc->topology_map->generation, 2110103285Sikob fc->topology_map->crc_len * 4); 2111103285Sikob fc->speed_map->crc = fw_crc16( 2112103285Sikob (u_int32_t *)&fc->speed_map->generation, 2113103285Sikob fc->speed_map->crc_len * 4); 2114103285Sikob /* byteswap and copy to CSR */ 2115103285Sikob p = (u_int32_t *)fc->topology_map; 2116103285Sikob for (i = 0; i <= fc->topology_map->crc_len; i++) 2117103285Sikob CSRARC(fc, TOPO_MAP + i * 4) = htonl(*p++); 2118103285Sikob p = (u_int32_t *)fc->speed_map; 2119103285Sikob CSRARC(fc, SPED_MAP) = htonl(*p++); 2120103285Sikob CSRARC(fc, SPED_MAP + 4) = htonl(*p++); 2121103285Sikob /* don't byte-swap u_int8_t array */ 2122103285Sikob bcopy(p, &CSRARC(fc, SPED_MAP + 8), (fc->speed_map->crc_len - 1)*4); 2123103285Sikob 2124103285Sikob fc->max_hop = fc->max_node - i_branch; 2125103285Sikob#if 1 2126103285Sikob printf(", maxhop <= %d", fc->max_hop); 2127103285Sikob#endif 2128103285Sikob 2129103285Sikob if(fc->irm == -1 ){ 2130103285Sikob printf(", Not found IRM capable node"); 2131103285Sikob }else{ 2132103285Sikob printf(", cable IRM = %d", fc->irm); 2133103285Sikob if (fc->irm == fc->nodeid) 2134103285Sikob printf(" (me)\n"); 2135103285Sikob else 2136103285Sikob printf("\n"); 2137103285Sikob } 2138103285Sikob 2139103285Sikob if((fc->irm != -1) && (CSRARC(fc, BUS_MGR_ID) == 0x3f) ){ 2140103285Sikob if(fc->irm == ((CSRARC(fc, NODE_IDS) >> 16 ) & 0x3f)){ 2141103285Sikob fc->status = FWBUSMGRDONE; 2142103285Sikob CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, fc->irm); 2143103285Sikob }else{ 2144103285Sikob fc->status = FWBUSMGRELECT; 2145103285Sikob fc->bmrhandle = timeout((timeout_t *)fw_try_bmr,(void *)fc, hz / 8); 2146103285Sikob } 2147103285Sikob }else{ 2148103285Sikob fc->status = FWBUSMGRDONE; 2149103285Sikob printf("%s: BMR = %x\n", device_get_nameunit(fc->dev), CSRARC(fc, BUS_MGR_ID)); 2150103285Sikob } 2151103285Sikob free(buf, M_DEVBUF); 2152103285Sikob#if 1 2153103285Sikob /* XXX optimize gap_count, if I am BMGR */ 2154103285Sikob if(fc->irm == ((CSRARC(fc, NODE_IDS) >> 16 ) & 0x3f)){ 2155103285Sikob fw_phy_config(fc, -1, gap_cnt[fc->max_hop]); 2156103285Sikob } 2157103285Sikob#endif 2158103285Sikob#if 1 2159103285Sikob timeout((timeout_t *)fw_bus_probe, (void *)fc, hz/4); 2160103285Sikob#else 2161103285Sikob fw_bus_probe(fc); 2162103285Sikob#endif 2163103285Sikob} 2164103285Sikob/* 2165103285Sikob * To probe devices on the IEEE1394 bus. 2166103285Sikob */ 2167103285Sikobstatic void fw_bus_probe(struct firewire_comm *fc) 2168103285Sikob{ 2169103285Sikob int s; 2170103285Sikob struct fw_device *fwdev, *next; 2171103285Sikob 2172103285Sikob s = splfw(); 2173103285Sikob fc->status = FWBUSEXPLORE; 2174103285Sikob fc->retry_count = 0; 2175103285Sikob 2176103285Sikob/* 2177103285Sikob * Invalidate all devices, just after bus reset. Devices 2178103285Sikob * to be removed has not been seen longer time. 2179103285Sikob */ 2180103285Sikob for(fwdev = TAILQ_FIRST(&fc->devices); fwdev != NULL; fwdev = next) { 2181103285Sikob next = TAILQ_NEXT(fwdev, link); 2182103285Sikob if(fwdev->status != FWDEVINVAL){ 2183103285Sikob fwdev->status = FWDEVINVAL; 2184103285Sikob fwdev->rcnt = 0; 2185103285Sikob }else if(fwdev->rcnt < FW_MAXDEVRCNT){ 2186103285Sikob fwdev->rcnt ++; 2187103285Sikob }else{ 2188103285Sikob TAILQ_REMOVE(&fc->devices, fwdev, link); 2189103285Sikob free(fwdev, M_DEVBUF); 2190103285Sikob } 2191103285Sikob } 2192103285Sikob fc->ongonode = 0; 2193103285Sikob fc->ongoaddr = CSRROMOFF; 2194103285Sikob fc->ongodev = NULL; 2195103285Sikob fc->ongoeui.hi = 0xffffffff; fc->ongoeui.lo = 0xffffffff; 2196103285Sikob fw_bus_explore(fc); 2197103285Sikob splx(s); 2198103285Sikob} 2199103285Sikob/* 2200103285Sikob * To collect device informations on the IEEE1394 bus. 2201103285Sikob */ 2202103285Sikobstatic void fw_bus_explore(struct firewire_comm *fc ) 2203103285Sikob{ 2204103285Sikob int err = 0; 2205103285Sikob struct fw_device *fwdev, *tfwdev; 2206103285Sikob u_int32_t addr; 2207103285Sikob struct fw_xfer *xfer; 2208103285Sikob struct fw_pkt *fp; 2209103285Sikob 2210103285Sikob if(fc->status != FWBUSEXPLORE) 2211103285Sikob return; 2212103285Sikob 2213103285Sikobloop: 2214103285Sikob if(fc->ongonode == fc->nodeid) fc->ongonode++; 2215103285Sikob 2216103285Sikob if(fc->ongonode > fc->max_node) goto done; 2217103285Sikob if(fc->ongonode >= 0x3f) goto done; 2218103285Sikob 2219103285Sikob /* check link */ 2220103285Sikob /* XXX we need to check phy_id first */ 2221103285Sikob if (!fc->topology_map->self_id[fc->ongonode].p0.link_active) { 2222103285Sikob printf("fw_bus_explore: node %d link down\n", fc->ongonode); 2223103285Sikob fc->ongonode++; 2224103285Sikob goto loop; 2225103285Sikob } 2226103285Sikob 2227103285Sikob if(fc->ongoaddr <= CSRROMOFF && 2228103285Sikob fc->ongoeui.hi == 0xffffffff && 2229103285Sikob fc->ongoeui.lo == 0xffffffff ){ 2230103285Sikob fc->ongoaddr = CSRROMOFF; 2231103285Sikob addr = 0xf0000000 | fc->ongoaddr; 2232103285Sikob }else if(fc->ongoeui.hi == 0xffffffff ){ 2233103285Sikob fc->ongoaddr = CSRROMOFF + 0xc; 2234103285Sikob addr = 0xf0000000 | fc->ongoaddr; 2235103285Sikob }else if(fc->ongoeui.lo == 0xffffffff ){ 2236103285Sikob fc->ongoaddr = CSRROMOFF + 0x10; 2237103285Sikob addr = 0xf0000000 | fc->ongoaddr; 2238103285Sikob }else if(fc->ongodev == NULL){ 2239103285Sikob for(fwdev = TAILQ_FIRST(&fc->devices); fwdev != NULL; 2240103285Sikob fwdev = TAILQ_NEXT(fwdev, link)){ 2241103285Sikob if(fwdev->eui.hi == fc->ongoeui.hi && fwdev->eui.lo == fc->ongoeui.lo){ 2242103285Sikob break; 2243103285Sikob } 2244103285Sikob } 2245103285Sikob if(fwdev != NULL){ 2246103285Sikob fwdev->dst = fc->ongonode; 2247103285Sikob fwdev->status = FWDEVATTACHED; 2248103285Sikob fc->ongonode++; 2249103285Sikob fc->ongoaddr = CSRROMOFF; 2250103285Sikob fc->ongodev = NULL; 2251103285Sikob fc->ongoeui.hi = 0xffffffff; fc->ongoeui.lo = 0xffffffff; 2252103285Sikob goto loop; 2253103285Sikob } 2254103285Sikob fwdev = malloc(sizeof(struct fw_device), M_DEVBUF, M_DONTWAIT); 2255103285Sikob if(fwdev == NULL) 2256103285Sikob return; 2257103285Sikob fwdev->rommax = 0; 2258103285Sikob fwdev->dst = fc->ongonode; 2259103285Sikob fwdev->eui.hi = fc->ongoeui.hi; fwdev->eui.lo = fc->ongoeui.lo; 2260103285Sikob fwdev->status = FWDEVINIT; 2261103285Sikob#if 0 2262103285Sikob fwdev->speed = CSRARC(fc, SPED_MAP + 8 + fc->ongonode / 4) 2263103285Sikob >> ((3 - (fc->ongonode % 4)) * 8); 2264103285Sikob#else 2265103285Sikob fwdev->speed = fc->speed_map->speed[fc->nodeid][fc->ongonode]; 2266103285Sikob#endif 2267103285Sikob 2268103285Sikob#if 0 2269103285Sikob TAILQ_INSERT_TAIL(&fc->devices, fwdev, link); 2270103285Sikob#else 2271103285Sikob tfwdev = TAILQ_FIRST(&fc->devices); 2272103285Sikob while( tfwdev != NULL && 2273103285Sikob (tfwdev->eui.hi > fwdev->eui.hi) && 2274103285Sikob ((tfwdev->eui.hi == fwdev->eui.hi) && 2275103285Sikob tfwdev->eui.lo > fwdev->eui.lo)){ 2276103285Sikob tfwdev = TAILQ_NEXT( tfwdev, link); 2277103285Sikob } 2278103285Sikob if(tfwdev == NULL){ 2279103285Sikob TAILQ_INSERT_TAIL(&fc->devices, fwdev, link); 2280103285Sikob }else{ 2281103285Sikob TAILQ_INSERT_BEFORE(tfwdev, fwdev, link); 2282103285Sikob } 2283103285Sikob#endif 2284103285Sikob 2285103285Sikob printf("%s:Discover new %s device ID:%08x%08x\n", device_get_nameunit(fc->dev), linkspeed[fwdev->speed], fc->ongoeui.hi, fc->ongoeui.lo); 2286103285Sikob 2287103285Sikob fc->ongodev = fwdev; 2288103285Sikob fc->ongoaddr = CSRROMOFF; 2289103285Sikob addr = 0xf0000000 | fc->ongoaddr; 2290103285Sikob }else{ 2291103285Sikob addr = 0xf0000000 | fc->ongoaddr; 2292103285Sikob } 2293103285Sikob#if 0 2294103285Sikob xfer = asyreqq(fc, FWSPD_S100, 0, 0, 2295103285Sikob ((FWLOCALBUS | fc->ongonode) << 16) | 0xffff , addr, 2296103285Sikob fw_bus_explore_callback); 2297103285Sikob if(xfer == NULL) goto done; 2298103285Sikob#else 2299103285Sikob xfer = fw_xfer_alloc(); 2300103285Sikob if(xfer == NULL){ 2301103285Sikob goto done; 2302103285Sikob } 2303103285Sikob xfer->send.len = 16; 2304103285Sikob xfer->spd = 0; 2305103285Sikob xfer->send.buf = malloc(16, M_DEVBUF, M_DONTWAIT); 2306103285Sikob if(xfer->send.buf == NULL){ 2307103285Sikob fw_xfer_free( xfer); 2308103285Sikob return; 2309103285Sikob } 2310103285Sikob 2311103285Sikob xfer->send.off = 0; 2312103285Sikob fp = (struct fw_pkt *)xfer->send.buf; 2313103285Sikob fp->mode.rreqq.dest_hi = htons(0xffff); 2314103285Sikob fp->mode.rreqq.tlrt = 0; 2315103285Sikob fp->mode.rreqq.tcode = FWTCODE_RREQQ; 2316103285Sikob fp->mode.rreqq.pri = 0; 2317103285Sikob fp->mode.rreqq.src = 0; 2318103285Sikob xfer->dst = FWLOCALBUS | fc->ongonode; 2319103285Sikob fp->mode.rreqq.dst = htons(xfer->dst); 2320103285Sikob fp->mode.rreqq.dest_lo = htonl(addr); 2321103285Sikob xfer->act.hand = fw_bus_explore_callback; 2322103285Sikob 2323103285Sikob err = fw_asyreq(fc, -1, xfer); 2324103285Sikob if(err){ 2325103285Sikob fw_xfer_free( xfer); 2326103285Sikob return; 2327103285Sikob } 2328103285Sikob#endif 2329103285Sikob return; 2330103285Sikobdone: 2331103285Sikob /* fw_attach_devs */ 2332103285Sikob fc->status = FWBUSEXPDONE; 2333103285Sikob printf("bus_explore done\n"); 2334103285Sikob fw_attach_dev(fc); 2335103285Sikob return; 2336103285Sikob 2337103285Sikob} 2338103285Sikob/* Portable Async. request read quad */ 2339103285Sikobstruct fw_xfer *asyreqq(struct firewire_comm *fc, 2340103285Sikob u_int8_t spd, u_int8_t tl, u_int8_t rt, 2341105620Ssimokawa u_int32_t addr_hi, u_int32_t addr_lo, 2342105620Ssimokawa void (*hand) __P((struct fw_xfer*))) 2343103285Sikob{ 2344103285Sikob struct fw_xfer *xfer; 2345103285Sikob struct fw_pkt *fp; 2346103285Sikob int err; 2347103285Sikob 2348103285Sikob xfer = fw_xfer_alloc(); 2349103285Sikob if(xfer == NULL){ 2350103285Sikob return NULL; 2351103285Sikob } 2352103285Sikob xfer->send.len = 16; 2353103285Sikob xfer->spd = spd; /* XXX:min(spd, fc->spd) */ 2354103285Sikob xfer->send.buf = malloc(16, M_DEVBUF, M_DONTWAIT); 2355103285Sikob if(xfer->send.buf == NULL){ 2356103285Sikob fw_xfer_free( xfer); 2357103285Sikob return NULL; 2358103285Sikob } 2359103285Sikob 2360103285Sikob xfer->send.off = 0; 2361103285Sikob fp = (struct fw_pkt *)xfer->send.buf; 2362103285Sikob fp->mode.rreqq.dest_hi = htons(addr_hi & 0xffff); 2363103285Sikob if(tl & FWP_TL_VALID){ 2364103285Sikob fp->mode.rreqq.tlrt = (tl & 0x3f) << 2; 2365103285Sikob }else{ 2366103285Sikob fp->mode.rreqq.tlrt = 0; 2367103285Sikob } 2368103285Sikob fp->mode.rreqq.tlrt |= rt & 0x3; 2369103285Sikob fp->mode.rreqq.tcode = FWTCODE_RREQQ; 2370103285Sikob fp->mode.rreqq.pri = 0; 2371103285Sikob fp->mode.rreqq.src = 0; 2372103285Sikob xfer->dst = addr_hi >> 16; 2373103285Sikob fp->mode.rreqq.dst = htons(xfer->dst); 2374103285Sikob fp->mode.rreqq.dest_lo = htonl(addr_lo); 2375103285Sikob xfer->act.hand = hand; 2376103285Sikob 2377103285Sikob err = fw_asyreq(fc, -1, xfer); 2378103285Sikob if(err){ 2379103285Sikob fw_xfer_free( xfer); 2380103285Sikob return NULL; 2381103285Sikob } 2382103285Sikob return xfer; 2383103285Sikob} 2384103285Sikob/* 2385103285Sikob * Callback for the IEEE1394 bus information collection. 2386103285Sikob */ 2387103285Sikobstatic void fw_bus_explore_callback(struct fw_xfer *xfer){ 2388103285Sikob struct firewire_comm *fc; 2389103285Sikob struct fw_pkt *sfp,*rfp; 2390103285Sikob struct csrhdr *chdr; 2391103285Sikob struct csrdir *csrd; 2392103285Sikob struct csrreg *csrreg; 2393103285Sikob u_int32_t offset; 2394103285Sikob 2395103285Sikob 2396103285Sikob if(xfer == NULL) return; 2397103285Sikob fc = xfer->fc; 2398103285Sikob if(xfer->resp != 0){ 2399103285Sikob printf("resp != 0: node=%d addr=0x%x\n", 2400103285Sikob fc->ongonode, fc->ongoaddr); 2401103285Sikob fc->retry_count++; 2402103285Sikob goto nextnode; 2403103285Sikob } 2404103285Sikob 2405103285Sikob if(xfer->send.buf == NULL){ 2406103285Sikob printf("send.buf == NULL: node=%d addr=0x%x\n", 2407103285Sikob fc->ongonode, fc->ongoaddr); 2408103285Sikob printf("send.buf == NULL\n"); 2409103285Sikob fc->retry_count++; 2410103285Sikob goto nextnode; 2411103285Sikob } 2412103285Sikob sfp = (struct fw_pkt *)xfer->send.buf; 2413103285Sikob 2414103285Sikob if(xfer->recv.buf == NULL){ 2415103285Sikob printf("recv.buf == NULL: node=%d addr=0x%x\n", 2416103285Sikob fc->ongonode, fc->ongoaddr); 2417103285Sikob fc->retry_count++; 2418103285Sikob goto nextnode; 2419103285Sikob } 2420103285Sikob rfp = (struct fw_pkt *)xfer->recv.buf; 2421103285Sikob#if 0 2422103285Sikob { 2423103285Sikob u_int32_t *qld; 2424103285Sikob int i; 2425103285Sikob qld = (u_int32_t *)xfer->recv.buf; 2426103285Sikob printf("len:%d\n", xfer->recv.len); 2427103285Sikob for( i = 0 ; i <= xfer->recv.len && i < 32; i+= 4){ 2428103285Sikob printf("0x%08x ", ntohl(rfp->mode.ld[i/4])); 2429103285Sikob if((i % 16) == 15) printf("\n"); 2430103285Sikob } 2431103285Sikob if((i % 16) != 15) printf("\n"); 2432103285Sikob } 2433103285Sikob#endif 2434103285Sikob if(fc->ongodev == NULL){ 2435103285Sikob if(sfp->mode.rreqq.dest_lo == htonl((0xf0000000 | CSRROMOFF))){ 2436103285Sikob rfp->mode.rresq.data = ntohl(rfp->mode.rresq.data); 2437103285Sikob chdr = (struct csrhdr *)(&rfp->mode.rresq.data); 2438103285Sikob/* If CSR is minimul confinguration, more investgation is not needed. */ 2439103285Sikob if(chdr->info_len == 1){ 2440103285Sikob goto nextnode; 2441103285Sikob }else{ 2442103285Sikob fc->ongoaddr = CSRROMOFF + 0xc; 2443103285Sikob } 2444103285Sikob }else if(sfp->mode.rreqq.dest_lo == htonl((0xf0000000 |(CSRROMOFF + 0xc)))){ 2445103285Sikob fc->ongoeui.hi = ntohl(rfp->mode.rresq.data); 2446103285Sikob fc->ongoaddr = CSRROMOFF + 0x10; 2447103285Sikob }else if(sfp->mode.rreqq.dest_lo == htonl((0xf0000000 |(CSRROMOFF + 0x10)))){ 2448103285Sikob fc->ongoeui.lo = ntohl(rfp->mode.rresq.data); 2449103285Sikob if (fc->ongoeui.hi == 0 && fc->ongoeui.lo == 0) 2450103285Sikob goto nextnode; 2451103285Sikob fc->ongoaddr = CSRROMOFF; 2452103285Sikob } 2453103285Sikob }else{ 2454103285Sikob fc->ongodev->csrrom[(fc->ongoaddr - CSRROMOFF)/4] = ntohl(rfp->mode.rresq.data); 2455103285Sikob if(fc->ongoaddr > fc->ongodev->rommax){ 2456103285Sikob fc->ongodev->rommax = fc->ongoaddr; 2457103285Sikob } 2458103285Sikob csrd = SLIST_FIRST(&fc->ongocsr); 2459103285Sikob if((csrd = SLIST_FIRST(&fc->ongocsr)) == NULL){ 2460103285Sikob chdr = (struct csrhdr *)(fc->ongodev->csrrom); 2461103285Sikob offset = CSRROMOFF; 2462103285Sikob }else{ 2463103285Sikob chdr = (struct csrhdr *)&fc->ongodev->csrrom[(csrd->off - CSRROMOFF)/4]; 2464103285Sikob offset = csrd->off; 2465103285Sikob } 2466103285Sikob if(fc->ongoaddr > (CSRROMOFF + 0x14) && fc->ongoaddr != offset){ 2467103285Sikob csrreg = (struct csrreg *)&fc->ongodev->csrrom[(fc->ongoaddr - CSRROMOFF)/4]; 2468103285Sikob if( csrreg->key == 0x81 || csrreg->key == 0xd1){ 2469103285Sikob csrd = SLIST_FIRST(&fc->csrfree); 2470103285Sikob if(csrd == NULL){ 2471103285Sikob goto nextnode; 2472103285Sikob }else{ 2473103285Sikob csrd->ongoaddr = fc->ongoaddr; 2474103285Sikob fc->ongoaddr += csrreg->val * 4; 2475103285Sikob csrd->off = fc->ongoaddr; 2476103285Sikob SLIST_REMOVE_HEAD(&fc->csrfree, link); 2477103285Sikob SLIST_INSERT_HEAD(&fc->ongocsr, csrd, link); 2478103285Sikob goto nextaddr; 2479103285Sikob } 2480103285Sikob } 2481103285Sikob } 2482103285Sikob fc->ongoaddr += 4; 2483103285Sikob if(((fc->ongoaddr - offset)/4 > chdr->crc_len) && 2484103285Sikob (fc->ongodev->rommax < 0x414)){ 2485103285Sikob if(fc->ongodev->rommax <= 0x414){ 2486103285Sikob csrd = SLIST_FIRST(&fc->csrfree); 2487103285Sikob if(csrd == NULL) goto nextnode; 2488103285Sikob csrd->off = fc->ongoaddr; 2489103285Sikob csrd->ongoaddr = fc->ongoaddr; 2490103285Sikob SLIST_REMOVE_HEAD(&fc->csrfree, link); 2491103285Sikob SLIST_INSERT_HEAD(&fc->ongocsr, csrd, link); 2492103285Sikob } 2493103285Sikob goto nextaddr; 2494103285Sikob } 2495103285Sikob 2496103285Sikob while(((fc->ongoaddr - offset)/4 > chdr->crc_len)){ 2497103285Sikob if(csrd == NULL){ 2498103285Sikob goto nextnode; 2499103285Sikob }; 2500103285Sikob fc->ongoaddr = csrd->ongoaddr + 4; 2501103285Sikob SLIST_REMOVE_HEAD(&fc->ongocsr, link); 2502103285Sikob SLIST_INSERT_HEAD(&fc->csrfree, csrd, link); 2503103285Sikob csrd = SLIST_FIRST(&fc->ongocsr); 2504103285Sikob if((csrd = SLIST_FIRST(&fc->ongocsr)) == NULL){ 2505103285Sikob chdr = (struct csrhdr *)(fc->ongodev->csrrom); 2506103285Sikob offset = CSRROMOFF; 2507103285Sikob }else{ 2508103285Sikob chdr = (struct csrhdr *)&(fc->ongodev->csrrom[(csrd->off - CSRROMOFF)/4]); 2509103285Sikob offset = csrd->off; 2510103285Sikob } 2511103285Sikob } 2512103285Sikob if((fc->ongoaddr - CSRROMOFF) > CSRROMSIZE){ 2513103285Sikob goto nextnode; 2514103285Sikob } 2515103285Sikob } 2516103285Sikobnextaddr: 2517103285Sikob fw_xfer_free( xfer); 2518103285Sikob fw_bus_explore(fc); 2519103285Sikob return; 2520103285Sikobnextnode: 2521103285Sikob fw_xfer_free( xfer); 2522103285Sikob fc->ongonode++; 2523103285Sikob/* housekeeping work space */ 2524103285Sikob fc->ongoaddr = CSRROMOFF; 2525103285Sikob fc->ongodev = NULL; 2526103285Sikob fc->ongoeui.hi = 0xffffffff; fc->ongoeui.lo = 0xffffffff; 2527103285Sikob while((csrd = SLIST_FIRST(&fc->ongocsr)) != NULL){ 2528103285Sikob SLIST_REMOVE_HEAD(&fc->ongocsr, link); 2529103285Sikob SLIST_INSERT_HEAD(&fc->csrfree, csrd, link); 2530103285Sikob } 2531103285Sikob fw_bus_explore(fc); 2532103285Sikob return; 2533103285Sikob} 2534103285Sikob/* 2535103285Sikob * Async. write responce support for kernel internal use. 2536103285Sikob */ 2537103285Sikobint fw_writeres(struct firewire_comm *fc, u_int32_t dst, u_int32_t tlrt){ 2538103285Sikob int err = 0; 2539103285Sikob struct fw_xfer *xfer; 2540103285Sikob struct fw_pkt *fp; 2541103285Sikob 2542103285Sikob xfer = fw_xfer_alloc(); 2543103285Sikob if(xfer == NULL){ 2544103285Sikob err = ENOMEM; 2545103285Sikob return err; 2546103285Sikob } 2547103285Sikob xfer->send.len = 12; 2548103285Sikob xfer->spd = 0; 2549103285Sikob xfer->send.buf = malloc(xfer->send.len, M_DEVBUF, M_NOWAIT); 2550103285Sikob if(xfer->send.buf == NULL){ 2551103285Sikob return ENOMEM; 2552103285Sikob } 2553103285Sikob xfer->send.off = 0; 2554103285Sikob fp = (struct fw_pkt *)xfer->send.buf; 2555103285Sikob 2556103285Sikob fp->mode.wres.tlrt = tlrt; 2557103285Sikob fp->mode.wres.tcode = FWTCODE_WRES; 2558103285Sikob fp->mode.wres.pri = 0; 2559103285Sikob fp->mode.wres.dst = htons(dst); 2560103285Sikob 2561103285Sikob xfer->act.hand = fw_asy_callback; 2562103285Sikob err = fw_asyreq(fc, -1, xfer); 2563103285Sikob if(err){ 2564103285Sikob fw_xfer_free( xfer); 2565103285Sikob return err; 2566103285Sikob } 2567103285Sikob err = tsleep((caddr_t)xfer, FWPRI, "asyreq", 0); 2568103285Sikob fw_xfer_free( xfer); 2569103285Sikob 2570103285Sikob return err; 2571103285Sikob} 2572103285Sikob/* 2573103285Sikob * Async. read responce block support for kernel internal use. 2574103285Sikob */ 2575103285Sikobint fw_readresb(struct firewire_comm *fc, u_int32_t dst, u_int32_t tlrt, u_int32_t len, u_int32_t *buf){ 2576103285Sikob int err = 0; 2577103285Sikob struct fw_xfer *xfer ; 2578103285Sikob struct fw_pkt *fp; 2579103285Sikob 2580103285Sikob xfer = fw_xfer_alloc(); 2581103285Sikob if(xfer == NULL){ 2582103285Sikob err = ENOMEM; 2583103285Sikob return err; 2584103285Sikob } 2585103285Sikob xfer->send.len = sizeof(struct fw_pkt) + len; 2586103285Sikob xfer->spd = 0; 2587103285Sikob xfer->send.buf = malloc(sizeof(struct fw_pkt) + 1024, M_DEVBUF, M_DONTWAIT); 2588103285Sikob if(xfer->send.buf == NULL){ 2589103285Sikob return ENOMEM; 2590103285Sikob } 2591103285Sikob xfer->send.off = 0; 2592103285Sikob fp = (struct fw_pkt *)xfer->send.buf; 2593103285Sikob fp->mode.rresb.tlrt = tlrt; 2594103285Sikob fp->mode.rresb.tcode = FWTCODE_RRESB; 2595103285Sikob fp->mode.rresb.pri = 0; 2596103285Sikob fp->mode.rresb.dst = htons(dst); 2597103285Sikob fp->mode.rresb.rtcode = 0; 2598103285Sikob fp->mode.rresb.extcode = 0; 2599103285Sikob fp->mode.rresb.len = htons(len); 2600103285Sikob bcopy(buf, fp->mode.rresb.payload, len); 2601103285Sikob xfer->act.hand = fw_asy_callback; 2602103285Sikob err = fw_asyreq(fc, -1, xfer); 2603103285Sikob if(err){ 2604103285Sikob fw_xfer_free( xfer); 2605103285Sikob return err; 2606103285Sikob } 2607103285Sikob err = tsleep((caddr_t)xfer, FWPRI, "asyreq", 0); 2608103285Sikob 2609103285Sikob fw_xfer_free( xfer); 2610103285Sikob return err; 2611103285Sikob} 2612103285Sikob/* 2613103285Sikob * Async. write request block support for kernel internal use. 2614103285Sikob */ 2615103285Sikobint fw_writereqb(struct firewire_comm *fc, u_int32_t addr_hi, u_int32_t addr_lo, u_int len, u_int32_t *buf){ 2616103285Sikob int err = 0; 2617103285Sikob struct fw_xfer *xfer ; 2618103285Sikob struct fw_pkt *fp; 2619103285Sikob 2620103285Sikob xfer = fw_xfer_alloc(); 2621103285Sikob if(xfer == NULL){ 2622103285Sikob err = ENOMEM; 2623103285Sikob return err; 2624103285Sikob } 2625103285Sikob xfer->send.len = sizeof(struct fw_pkt) + len; 2626103285Sikob xfer->spd = 0; 2627103285Sikob xfer->send.buf = malloc(sizeof(struct fw_pkt) + 1024, M_DEVBUF, M_DONTWAIT); 2628103285Sikob if(xfer->send.buf == NULL){ 2629103285Sikob return ENOMEM; 2630103285Sikob } 2631103285Sikob xfer->send.off = 0; 2632103285Sikob fp = (struct fw_pkt *)xfer->send.buf; 2633103285Sikob fp->mode.wreqb.dest_hi = htonl(addr_hi & 0xffff); 2634103285Sikob fp->mode.wreqb.tlrt = 0; 2635103285Sikob fp->mode.wreqb.tcode = FWTCODE_WREQB; 2636103285Sikob fp->mode.wreqb.pri = 0; 2637103285Sikob fp->mode.wreqb.dst = htons(addr_hi >> 16); 2638103285Sikob fp->mode.wreqb.dest_lo = htonl(addr_lo); 2639103285Sikob fp->mode.wreqb.len = htons(len); 2640103285Sikob fp->mode.wreqb.extcode = 0; 2641103285Sikob bcopy(buf, fp->mode.wreqb.payload, len); 2642103285Sikob xfer->act.hand = fw_asy_callback; 2643103285Sikob err = fw_asyreq(fc, -1, xfer); 2644103285Sikob if(err){ 2645103285Sikob fw_xfer_free( xfer); 2646103285Sikob return err; 2647103285Sikob } 2648103285Sikob err = tsleep((caddr_t)xfer, FWPRI, "asyreq", 0); 2649103285Sikob 2650103285Sikob fw_xfer_free( xfer); 2651103285Sikob return err; 2652103285Sikob} 2653103285Sikob/* 2654103285Sikob * Async. read request support for kernel internal use. 2655103285Sikob */ 2656103285Sikobint fw_readreqq(struct firewire_comm *fc, u_int32_t addr_hi, u_int32_t addr_lo, u_int32_t *ret){ 2657103285Sikob int err = 0; 2658103285Sikob struct fw_xfer *xfer ; 2659103285Sikob struct fw_pkt *fp, *rfp; 2660103285Sikob 2661103285Sikob xfer = fw_xfer_alloc(); 2662103285Sikob if(xfer == NULL){ 2663103285Sikob err = ENOMEM; 2664103285Sikob return err; 2665103285Sikob } 2666103285Sikob xfer->send.len = 16; 2667103285Sikob xfer->spd = 0; 2668103285Sikob xfer->send.buf = malloc(16, M_DEVBUF, M_DONTWAIT); 2669103285Sikob if(xfer->send.buf == NULL){ 2670103285Sikob return ENOMEM; 2671103285Sikob } 2672103285Sikob xfer->send.off = 0; 2673103285Sikob fp = (struct fw_pkt *)xfer->send.buf; 2674103285Sikob fp->mode.rreqq.dest_hi = htonl(addr_hi & 0xffff); 2675103285Sikob fp->mode.rreqq.tlrt = 0; 2676103285Sikob fp->mode.rreqq.tcode = FWTCODE_RREQQ; 2677103285Sikob fp->mode.rreqq.pri = 0; 2678103285Sikob xfer->dst = addr_hi >> 16; 2679103285Sikob fp->mode.rreqq.dst = htons(xfer->dst); 2680103285Sikob fp->mode.rreqq.dest_lo = htonl(addr_lo); 2681103285Sikob xfer->act.hand = fw_asy_callback; 2682103285Sikob err = fw_asyreq(fc, -1, xfer); 2683103285Sikob if(err){ 2684103285Sikob fw_xfer_free( xfer); 2685103285Sikob return err; 2686103285Sikob } 2687103285Sikob err = tsleep((caddr_t)xfer, FWPRI, "asyreq", 0); 2688103285Sikob 2689103285Sikob if(err == 0 && xfer->recv.buf != NULL){ 2690103285Sikob rfp = (struct fw_pkt *)xfer->recv.buf; 2691103285Sikob *ret = ntohl(rfp->mode.rresq.data); 2692103285Sikob } 2693103285Sikob fw_xfer_free( xfer); 2694103285Sikob return err; 2695103285Sikob} 2696103285Sikob/* 2697103285Sikob * To obtain CSR register values. 2698103285Sikob */ 2699103285Sikobu_int32_t getcsrdata(struct fw_device *fwdev, u_int8_t key) 2700103285Sikob{ 2701103285Sikob int i; 2702103285Sikob struct csrhdr *chdr; 2703103285Sikob struct csrreg *creg; 2704103285Sikob chdr = (struct csrhdr *)&fwdev->csrrom[0]; 2705103285Sikob for( i = chdr->info_len + 4; i <= fwdev->rommax - CSRROMOFF; i+=4){ 2706103285Sikob creg = (struct csrreg *)&fwdev->csrrom[i/4]; 2707103285Sikob if(creg->key == key){ 2708103285Sikob return (u_int32_t)creg->val; 2709103285Sikob } 2710103285Sikob } 2711103285Sikob return 0; 2712103285Sikob} 2713103285Sikob/* 2714103285Sikob * To attach sub-devices layer onto IEEE1394 bus. 2715103285Sikob */ 2716103285Sikobstatic void fw_attach_dev(struct firewire_comm *fc) 2717103285Sikob{ 2718103285Sikob struct fw_device *fwdev; 2719103285Sikob struct fw_xfer *xfer; 2720103285Sikob int i, err; 2721103285Sikob device_t *devlistp; 2722103285Sikob int devcnt; 2723103285Sikob struct firewire_dev_comm *fdc; 2724103285Sikob 2725103285Sikob for(fwdev = TAILQ_FIRST(&fc->devices); fwdev != NULL; 2726103285Sikob fwdev = TAILQ_NEXT(fwdev, link)){ 2727103285Sikob if(fwdev->status == FWDEVINIT){ 2728103285Sikob fwdev->spec = getcsrdata(fwdev, CSRKEY_SPEC); 2729103285Sikob if(fwdev->spec == 0) 2730103285Sikob continue; 2731103285Sikob fwdev->ver = getcsrdata(fwdev, CSRKEY_VER); 2732103285Sikob if(fwdev->ver == 0) 2733103285Sikob continue; 2734103285Sikob fwdev->maxrec = (fwdev->csrrom[2] >> 12) & 0xf; 2735103285Sikob 2736103285Sikob switch(fwdev->spec){ 2737103285Sikob case CSRVAL_ANSIT10: 2738103285Sikob switch(fwdev->ver){ 2739103285Sikob case CSRVAL_T10SBP2: 2740103285Sikob printf("Device SBP-II"); 2741103285Sikob break; 2742103285Sikob default: 2743103285Sikob break; 2744103285Sikob } 2745103285Sikob break; 2746103285Sikob case CSRVAL_1394TA: 2747103285Sikob switch(fwdev->ver){ 2748103285Sikob case CSR_PROTAVC: 2749103285Sikob printf("Device AV/C"); 2750103285Sikob break; 2751103285Sikob case CSR_PROTCAL: 2752103285Sikob printf("Device CAL"); 2753103285Sikob break; 2754103285Sikob case CSR_PROTEHS: 2755103285Sikob printf("Device EHS"); 2756103285Sikob break; 2757103285Sikob case CSR_PROTHAVI: 2758103285Sikob printf("Device HAVi"); 2759103285Sikob break; 2760103285Sikob case CSR_PROTCAM104: 2761103285Sikob printf("Device 1394 Cam 1.04"); 2762103285Sikob break; 2763103285Sikob case CSR_PROTCAM120: 2764103285Sikob printf("Device 1394 Cam 1.20"); 2765103285Sikob break; 2766103285Sikob case CSR_PROTCAM130: 2767103285Sikob printf("Device 1394 Cam 1.30"); 2768103285Sikob break; 2769103285Sikob case CSR_PROTDPP: 2770103285Sikob printf("Device 1394 Direct print"); 2771103285Sikob break; 2772103285Sikob case CSR_PROTIICP: 2773103285Sikob printf("Device Industrial & Instrument"); 2774103285Sikob break; 2775103285Sikob default: 2776103285Sikob printf("Device unkwon 1394TA"); 2777103285Sikob break; 2778103285Sikob } 2779103285Sikob break; 2780103285Sikob default: 2781103285Sikob break; 2782103285Sikob } 2783103285Sikob fwdev->status = FWDEVATTACHED; 2784103285Sikob printf("\n"); 2785103285Sikob } 2786103285Sikob } 2787103285Sikob err = device_get_children(fc->dev, &devlistp, &devcnt); 2788103285Sikob if( err != 0 ) 2789103285Sikob return; 2790103285Sikob for( i = 0 ; i < devcnt ; i++){ 2791103285Sikob if (device_get_state(devlistp[i]) >= DS_ATTACHED) { 2792103285Sikob fdc = device_get_softc(devlistp[i]); 2793103285Sikob if (fdc->post_explore != NULL) 2794103285Sikob fdc->post_explore(fdc); 2795103285Sikob } 2796103285Sikob } 2797103285Sikob free(devlistp, M_TEMP); 2798103285Sikob 2799103285Sikob /* call pending handlers */ 2800103285Sikob i = 0; 2801103285Sikob while ((xfer = STAILQ_FIRST(&fc->pending))) { 2802103285Sikob STAILQ_REMOVE_HEAD(&fc->pending, link); 2803103285Sikob i++; 2804103285Sikob if (xfer->act.hand) 2805103285Sikob xfer->act.hand(xfer); 2806103285Sikob } 2807103285Sikob if (i > 0) 2808103285Sikob printf("fw_attach_dev: %d pending handlers called\n", i); 2809103285Sikob if (fc->retry_count > 0) { 2810103285Sikob printf("retry_count = %d\n", fc->retry_count); 2811103285Sikob fc->retry_probe_handle = timeout((timeout_t *)fc->ibr, 2812103285Sikob (void *)fc, hz*2); 2813103285Sikob } 2814103285Sikob return; 2815103285Sikob} 2816103285Sikob/* 2817103285Sikob * To allocate uniq transaction label. 2818103285Sikob */ 2819103285Sikobstatic int fw_get_tlabel(struct firewire_comm *fc, struct fw_xfer *xfer) 2820103285Sikob{ 2821103285Sikob u_int i; 2822103285Sikob struct tlabel *tl, *tmptl; 2823103285Sikob int s; 2824103285Sikob static u_int32_t label = 0; 2825103285Sikob 2826103285Sikob s = splfw(); 2827103285Sikob for( i = 0 ; i < 0x40 ; i ++){ 2828103285Sikob label = (label + 1) & 0x3f; 2829103285Sikob for(tmptl = STAILQ_FIRST(&fc->tlabels[label]); 2830103285Sikob tmptl != NULL; tmptl = STAILQ_NEXT(tmptl, link)){ 2831103285Sikob if(tmptl->xfer->dst == xfer->dst) break; 2832103285Sikob } 2833103285Sikob if(tmptl == NULL) { 2834103285Sikob tl = malloc(sizeof(struct tlabel),M_DEVBUF,M_DONTWAIT); 2835103285Sikob if (tl == NULL) { 2836103285Sikob splx(s); 2837103285Sikob return (-1); 2838103285Sikob } 2839103285Sikob tl->xfer = xfer; 2840103285Sikob STAILQ_INSERT_TAIL(&fc->tlabels[label], tl, link); 2841103285Sikob splx(s); 2842103285Sikob return(label); 2843103285Sikob } 2844103285Sikob } 2845103285Sikob splx(s); 2846103285Sikob 2847103285Sikob printf("fw_get_tlabel: no free tlabel\n"); 2848103285Sikob return(-1); 2849103285Sikob} 2850103285Sikob/* 2851103285Sikob * Generic packet receving process. 2852103285Sikob */ 2853103285Sikobvoid fw_rcv(struct firewire_comm* fc, caddr_t buf, u_int len, u_int sub, u_int off, u_int spd) 2854103285Sikob{ 2855103285Sikob struct fw_pkt *fp, *resfp; 2856103285Sikob struct fw_xfer *xfer; 2857103285Sikob struct fw_bind *bind; 2858103285Sikob struct firewire_softc *sc; 2859103285Sikob int s; 2860103285Sikob#if 0 2861103285Sikob { 2862103285Sikob u_int32_t *qld; 2863103285Sikob int i; 2864103285Sikob qld = (u_int32_t *)buf; 2865103285Sikob printf("spd %d len:%d\n", spd, len); 2866103285Sikob for( i = 0 ; i <= len && i < 32; i+= 4){ 2867103285Sikob printf("0x%08x ", ntohl(qld[i/4])); 2868103285Sikob if((i % 16) == 15) printf("\n"); 2869103285Sikob } 2870103285Sikob if((i % 16) != 15) printf("\n"); 2871103285Sikob } 2872103285Sikob#endif 2873103285Sikob fp = (struct fw_pkt *)(buf + off); 2874103285Sikob switch(fp->mode.common.tcode){ 2875103285Sikob case FWTCODE_WRES: 2876103285Sikob case FWTCODE_RRESQ: 2877103285Sikob case FWTCODE_RRESB: 2878103285Sikob case FWTCODE_LRES: 2879103285Sikob xfer = fw_tl2xfer(fc, ntohs(fp->mode.hdr.src), 2880103285Sikob fp->mode.hdr.tlrt >> 2); 2881103285Sikob if(xfer == NULL) { 2882103285Sikob printf("fw_rcv: unknown response " 2883103285Sikob "tcode=%d src=0x%x tl=%x rt=%d data=0x%x\n", 2884103285Sikob fp->mode.common.tcode, 2885103285Sikob ntohs(fp->mode.hdr.src), 2886103285Sikob fp->mode.hdr.tlrt >> 2, 2887103285Sikob fp->mode.hdr.tlrt & 3, 2888103285Sikob fp->mode.rresq.data); 2889103285Sikob#if 1 2890103285Sikob printf("try ad-hoc work around!!\n"); 2891103285Sikob xfer = fw_tl2xfer(fc, ntohs(fp->mode.hdr.src), 2892103285Sikob (fp->mode.hdr.tlrt >> 2)^3); 2893103285Sikob if (xfer == NULL) { 2894103285Sikob printf("no use...\n"); 2895103285Sikob goto err; 2896103285Sikob } 2897103285Sikob#else 2898103285Sikob goto err; 2899103285Sikob#endif 2900103285Sikob } 2901103285Sikob switch(xfer->act_type){ 2902103285Sikob case FWACT_XFER: 2903103285Sikob if((xfer->sub >= 0) && 2904103285Sikob ((fc->ir[xfer->sub]->flag & FWXFERQ_MODEMASK ) == 0)){ 2905103285Sikob xfer->resp = EINVAL; 2906103285Sikob fw_xfer_done(xfer); 2907103285Sikob goto err; 2908103285Sikob } 2909103285Sikob xfer->recv.len = len; 2910103285Sikob xfer->recv.off = off; 2911103285Sikob xfer->recv.buf = buf; 2912103285Sikob xfer->resp = 0; 2913103285Sikob fw_xfer_done(xfer); 2914103285Sikob return; 2915103285Sikob break; 2916103285Sikob case FWACT_CH: 2917103285Sikob default: 2918103285Sikob goto err; 2919103285Sikob break; 2920103285Sikob } 2921103285Sikob break; 2922103285Sikob case FWTCODE_WREQQ: 2923103285Sikob case FWTCODE_WREQB: 2924103285Sikob case FWTCODE_RREQQ: 2925103285Sikob case FWTCODE_RREQB: 2926103285Sikob case FWTCODE_LREQ: 2927103285Sikob bind = fw_bindlookup(fc, ntohs(fp->mode.rreqq.dest_hi), 2928103285Sikob ntohl(fp->mode.rreqq.dest_lo)); 2929103285Sikob if(bind == NULL){ 2930103285Sikob printf("Unknown service addr 0x%08x:0x%08x tcode=%x\n", 2931103285Sikob ntohs(fp->mode.rreqq.dest_hi), 2932103285Sikob ntohl(fp->mode.rreqq.dest_lo), 2933103285Sikob fp->mode.common.tcode); 2934103285Sikob if (fc->status == FWBUSRESET) { 2935103285Sikob printf("fw_rcv: cannot response(bus reset)!\n"); 2936103285Sikob goto err; 2937103285Sikob } 2938103285Sikob xfer = fw_xfer_alloc(); 2939103285Sikob if(xfer == NULL){ 2940103285Sikob return; 2941103285Sikob } 2942103285Sikob xfer->spd = spd; 2943103285Sikob xfer->send.buf = malloc(16, M_DEVBUF, M_DONTWAIT); 2944103285Sikob resfp = (struct fw_pkt *)xfer->send.buf; 2945103285Sikob switch(fp->mode.common.tcode){ 2946103285Sikob case FWTCODE_WREQQ: 2947103285Sikob case FWTCODE_WREQB: 2948103285Sikob resfp->mode.hdr.tcode = FWTCODE_WRES; 2949103285Sikob xfer->send.len = 12; 2950103285Sikob break; 2951103285Sikob case FWTCODE_RREQQ: 2952103285Sikob resfp->mode.hdr.tcode = FWTCODE_RRESQ; 2953103285Sikob xfer->send.len = 16; 2954103285Sikob break; 2955103285Sikob case FWTCODE_RREQB: 2956103285Sikob resfp->mode.hdr.tcode = FWTCODE_RRESB; 2957103285Sikob xfer->send.len = 16; 2958103285Sikob break; 2959103285Sikob case FWTCODE_LREQ: 2960103285Sikob resfp->mode.hdr.tcode = FWTCODE_LRES; 2961103285Sikob xfer->send.len = 16; 2962103285Sikob break; 2963103285Sikob } 2964103285Sikob resfp->mode.hdr.dst = fp->mode.hdr.src; 2965103285Sikob resfp->mode.hdr.tlrt = fp->mode.hdr.tlrt; 2966103285Sikob resfp->mode.hdr.pri = fp->mode.hdr.pri; 2967103285Sikob resfp->mode.rresb.rtcode = 7; 2968103285Sikob resfp->mode.rresb.extcode = 0; 2969103285Sikob resfp->mode.rresb.len = 0; 2970103285Sikob/* 2971103285Sikob xfer->act.hand = fw_asy_callback; 2972103285Sikob*/ 2973103285Sikob xfer->act.hand = fw_xfer_free; 2974103285Sikob if(fw_asyreq(fc, -1, xfer)){ 2975103285Sikob fw_xfer_free( xfer); 2976103285Sikob return; 2977103285Sikob } 2978103285Sikob goto err; 2979103285Sikob } 2980103285Sikob switch(bind->xfer->act_type){ 2981103285Sikob case FWACT_XFER: 2982103285Sikob xfer = fw_xfer_alloc(); 2983103285Sikob if(xfer == NULL) goto err; 2984103285Sikob xfer->fc = bind->xfer->fc; 2985103285Sikob xfer->sc = bind->xfer->sc; 2986103285Sikob xfer->recv.buf = buf; 2987103285Sikob xfer->recv.len = len; 2988103285Sikob xfer->recv.off = off; 2989103285Sikob xfer->spd = spd; 2990103285Sikob xfer->act.hand = bind->xfer->act.hand; 2991103285Sikob if (fc->status != FWBUSRESET) 2992103285Sikob xfer->act.hand(xfer); 2993103285Sikob else 2994103285Sikob STAILQ_INSERT_TAIL(&fc->pending, xfer, link); 2995103285Sikob return; 2996103285Sikob break; 2997103285Sikob case FWACT_CH: 2998103285Sikob if(fc->ir[bind->xfer->sub]->queued >= 2999103285Sikob fc->ir[bind->xfer->sub]->maxq){ 3000103285Sikob printf("%s:Discard a packet %x %d\n", 3001103285Sikob device_get_nameunit(fc->dev), 3002103285Sikob bind->xfer->sub, 3003103285Sikob fc->ir[bind->xfer->sub]->queued); 3004103285Sikob goto err; 3005103285Sikob } 3006103285Sikob xfer = fw_xfer_alloc(); 3007103285Sikob if(xfer == NULL) goto err; 3008103285Sikob xfer->recv.buf = buf; 3009103285Sikob xfer->recv.len = len; 3010103285Sikob xfer->recv.off = off; 3011103285Sikob xfer->spd = spd; 3012103285Sikob s = splfw(); 3013103285Sikob fc->ir[bind->xfer->sub]->queued++; 3014103285Sikob STAILQ_INSERT_TAIL(&fc->ir[bind->xfer->sub]->q, xfer, link); 3015103285Sikob splx(s); 3016103285Sikob 3017103285Sikob wakeup((caddr_t)fc->ir[bind->xfer->sub]); 3018103285Sikob 3019103285Sikob return; 3020103285Sikob break; 3021103285Sikob default: 3022103285Sikob goto err; 3023103285Sikob break; 3024103285Sikob } 3025103285Sikob break; 3026103285Sikob case FWTCODE_STREAM: 3027103285Sikob { 3028103285Sikob struct fw_xferq *xferq; 3029103285Sikob 3030103285Sikob xferq = fc->ir[sub]; 3031103285Sikob#if 0 3032103285Sikob printf("stream rcv dma %d len %d off %d spd %d\n", 3033103285Sikob sub, len, off, spd); 3034103285Sikob#endif 3035103285Sikob if(xferq->queued >= xferq->maxq) { 3036103285Sikob printf("receive queue is full\n"); 3037103285Sikob goto err; 3038103285Sikob } 3039103285Sikob xfer = fw_xfer_alloc(); 3040103285Sikob if(xfer == NULL) goto err; 3041103285Sikob xfer->recv.buf = buf; 3042103285Sikob xfer->recv.len = len; 3043103285Sikob xfer->recv.off = off; 3044103285Sikob xfer->spd = spd; 3045103285Sikob s = splfw(); 3046103285Sikob xferq->queued++; 3047103285Sikob STAILQ_INSERT_TAIL(&xferq->q, xfer, link); 3048103285Sikob splx(s); 3049103285Sikob sc = device_get_softc(fc->bdev); 3050103285Sikob#if __FreeBSD_version >= 500000 3051103285Sikob if (SEL_WAITING(&xferq->rsel)) 3052103285Sikob#else 3053103285Sikob if (&xferq->rsel.si_pid != 0) 3054103285Sikob#endif 3055103285Sikob selwakeup(&xferq->rsel); 3056103285Sikob if (xferq->flag & FWXFERQ_WAKEUP) { 3057103285Sikob xferq->flag &= ~FWXFERQ_WAKEUP; 3058103285Sikob wakeup((caddr_t)xferq); 3059103285Sikob } 3060103285Sikob if (xferq->flag & FWXFERQ_HANDLER) { 3061103285Sikob xferq->hand(xferq); 3062103285Sikob } 3063103285Sikob return; 3064103285Sikob break; 3065103285Sikob } 3066103285Sikob default: 3067103285Sikob printf("fw_rcv: unknow tcode\n"); 3068103285Sikob break; 3069103285Sikob } 3070103285Sikoberr: 3071103285Sikob free(buf, M_DEVBUF); 3072103285Sikob} 3073103285Sikob/* 3074103285Sikob * Post process for Bus Manager election process. 3075103285Sikob */ 3076103285Sikobstatic void 3077103285Sikobfw_try_bmr_callback(struct fw_xfer *xfer) 3078103285Sikob{ 3079103285Sikob struct fw_pkt *sfp,*rfp; 3080103285Sikob struct firewire_comm *fc; 3081103285Sikob 3082103285Sikob if(xfer == NULL) return; 3083103285Sikob fc = xfer->fc; 3084103285Sikob if(xfer->resp != 0){ 3085103285Sikob goto error; 3086103285Sikob } 3087103285Sikob 3088103285Sikob if(xfer->send.buf == NULL){ 3089103285Sikob goto error; 3090103285Sikob } 3091103285Sikob sfp = (struct fw_pkt *)xfer->send.buf; 3092103285Sikob 3093103285Sikob if(xfer->recv.buf == NULL){ 3094103285Sikob goto error; 3095103285Sikob } 3096103285Sikob rfp = (struct fw_pkt *)xfer->recv.buf; 3097103285Sikob CSRARC(fc, BUS_MGR_ID) 3098103285Sikob = fc->set_bmr(fc, ntohl(rfp->mode.lres.payload[0]) & 0x3f); 3099103285Sikob printf("%s: new bus manager %d ", 3100103285Sikob device_get_nameunit(fc->dev), CSRARC(fc, BUS_MGR_ID)); 3101103285Sikob if((htonl(rfp->mode.lres.payload[0]) & 0x3f) == fc->nodeid){ 3102103285Sikob printf("(me)\n"); 3103103285Sikob/* If I am bus manager, optimize gapcount */ 3104103285Sikob if(fc->max_hop <= MAX_GAPHOP ){ 3105103285Sikob fw_phy_config(fc, -1, gap_cnt[fc->max_hop]); 3106103285Sikob } 3107103285Sikob }else{ 3108103285Sikob printf("\n"); 3109103285Sikob } 3110103285Sikoberror: 3111103285Sikob fw_xfer_free(xfer); 3112103285Sikob} 3113103285Sikob/* 3114103285Sikob * To candidate Bus Manager election process. 3115103285Sikob */ 3116103285Sikobvoid fw_try_bmr(void *arg) 3117103285Sikob{ 3118103285Sikob struct fw_xfer *xfer; 3119103285Sikob struct firewire_comm *fc = (struct firewire_comm *)arg; 3120103285Sikob struct fw_pkt *fp; 3121103285Sikob int err = 0; 3122103285Sikob 3123103285Sikob xfer = fw_xfer_alloc(); 3124103285Sikob if(xfer == NULL){ 3125103285Sikob return; 3126103285Sikob } 3127103285Sikob xfer->send.len = 24; 3128103285Sikob xfer->spd = 0; 3129103285Sikob xfer->send.buf = malloc(24, M_DEVBUF, M_DONTWAIT); 3130103285Sikob if(xfer->send.buf == NULL){ 3131103285Sikob fw_xfer_free( xfer); 3132103285Sikob return; 3133103285Sikob } 3134103285Sikob 3135103285Sikob fc->status = FWBUSMGRELECT; 3136103285Sikob 3137103285Sikob xfer->send.off = 0; 3138103285Sikob fp = (struct fw_pkt *)xfer->send.buf; 3139103285Sikob fp->mode.lreq.dest_hi = htons(0xffff); 3140103285Sikob fp->mode.lreq.tlrt = 0; 3141103285Sikob fp->mode.lreq.tcode = FWTCODE_LREQ; 3142103285Sikob fp->mode.lreq.pri = 0; 3143103285Sikob fp->mode.lreq.src = 0; 3144103285Sikob fp->mode.lreq.len = htons(8); 3145103285Sikob fp->mode.lreq.extcode = htons(FW_LREQ_CMPSWAP); 3146103285Sikob xfer->dst = FWLOCALBUS | fc->irm; 3147103285Sikob fp->mode.lreq.dst = htons(xfer->dst); 3148103285Sikob fp->mode.lreq.dest_lo = htonl(0xf0000000 | BUS_MGR_ID); 3149103285Sikob fp->mode.lreq.payload[0] = 0x3f; 3150103285Sikob fp->mode.lreq.payload[1] = fc->nodeid; 3151103285Sikob xfer->act_type = FWACT_XFER; 3152103285Sikob xfer->act.hand = fw_try_bmr_callback; 3153103285Sikob 3154103285Sikob err = fw_asyreq(fc, -1, xfer); 3155103285Sikob if(err){ 3156103285Sikob fw_xfer_free( xfer); 3157103285Sikob return; 3158103285Sikob } 3159103285Sikob return; 3160103285Sikob} 3161106543Ssimokawa 3162106543Ssimokawa#ifdef FW_VMACCESS 3163103285Sikob/* 3164103285Sikob * Software implementation for physical memory block access. 3165103285Sikob * XXX:Too slow, usef for debug purpose only. 3166103285Sikob */ 3167103285Sikobstatic void fw_vmaccess(struct fw_xfer *xfer){ 3168103285Sikob struct fw_pkt *rfp, *sfp = NULL; 3169103285Sikob u_int32_t *ld = (u_int32_t *)(xfer->recv.buf + xfer->recv.off); 3170103285Sikob 3171103285Sikob printf("vmaccess spd:%2x len:%03x %d data:%08x %08x %08x %08x\n", 3172103285Sikob xfer->spd, xfer->recv.len, xfer->recv.off, ntohl(ld[0]), ntohl(ld[1]), ntohl(ld[2]), ntohl(ld[3])); 3173103285Sikob printf("vmaccess data:%08x %08x %08x %08x\n", ntohl(ld[4]), ntohl(ld[5]), ntohl(ld[6]), ntohl(ld[7])); 3174103285Sikob if(xfer->resp != 0){ 3175103285Sikob fw_xfer_free( xfer); 3176103285Sikob return; 3177103285Sikob } 3178103285Sikob if(xfer->recv.buf == NULL){ 3179103285Sikob fw_xfer_free( xfer); 3180103285Sikob return; 3181103285Sikob } 3182103285Sikob rfp = (struct fw_pkt *)xfer->recv.buf; 3183103285Sikob switch(rfp->mode.hdr.tcode){ 3184103285Sikob /* XXX need fix for 64bit arch */ 3185103285Sikob case FWTCODE_WREQB: 3186103285Sikob xfer->send.buf = malloc(12, M_DEVBUF, M_NOWAIT); 3187103285Sikob xfer->send.len = 12; 3188103285Sikob sfp = (struct fw_pkt *)xfer->send.buf; 3189103285Sikob bcopy(rfp->mode.wreqb.payload, 3190103285Sikob (caddr_t)ntohl(rfp->mode.wreqb.dest_lo), ntohs(rfp->mode.wreqb.len)); 3191103285Sikob sfp->mode.wres.tcode = FWTCODE_WRES; 3192103285Sikob sfp->mode.wres.rtcode = 0; 3193103285Sikob break; 3194103285Sikob case FWTCODE_WREQQ: 3195103285Sikob xfer->send.buf = malloc(12, M_DEVBUF, M_NOWAIT); 3196103285Sikob xfer->send.len = 12; 3197103285Sikob sfp->mode.wres.tcode = FWTCODE_WRES; 3198103285Sikob *((u_int32_t *)(ntohl(rfp->mode.wreqb.dest_lo))) = rfp->mode.wreqq.data; 3199103285Sikob sfp->mode.wres.rtcode = 0; 3200103285Sikob break; 3201103285Sikob case FWTCODE_RREQB: 3202103285Sikob xfer->send.buf = malloc(16 + rfp->mode.rreqb.len, M_DEVBUF, M_NOWAIT); 3203103285Sikob xfer->send.len = 16 + ntohs(rfp->mode.rreqb.len); 3204103285Sikob sfp = (struct fw_pkt *)xfer->send.buf; 3205103285Sikob bcopy((caddr_t)ntohl(rfp->mode.rreqb.dest_lo), 3206103285Sikob sfp->mode.rresb.payload, (u_int16_t)ntohs(rfp->mode.rreqb.len)); 3207103285Sikob sfp->mode.rresb.tcode = FWTCODE_RRESB; 3208103285Sikob sfp->mode.rresb.len = rfp->mode.rreqb.len; 3209103285Sikob sfp->mode.rresb.rtcode = 0; 3210103285Sikob sfp->mode.rresb.extcode = 0; 3211103285Sikob break; 3212103285Sikob case FWTCODE_RREQQ: 3213103285Sikob xfer->send.buf = malloc(16, M_DEVBUF, M_NOWAIT); 3214103285Sikob xfer->send.len = 16; 3215103285Sikob sfp = (struct fw_pkt *)xfer->send.buf; 3216103285Sikob sfp->mode.rresq.data = *(u_int32_t *)(ntohl(rfp->mode.rreqq.dest_lo)); 3217103285Sikob sfp->mode.wres.tcode = FWTCODE_RRESQ; 3218103285Sikob sfp->mode.rresb.rtcode = 0; 3219103285Sikob break; 3220103285Sikob default: 3221103285Sikob fw_xfer_free( xfer); 3222103285Sikob return; 3223103285Sikob } 3224103285Sikob xfer->send.off = 0; 3225103285Sikob sfp->mode.hdr.dst = rfp->mode.hdr.src; 3226103285Sikob xfer->dst = ntohs(rfp->mode.hdr.src); 3227103285Sikob xfer->act.hand = fw_xfer_free; 3228103285Sikob xfer->retry_req = fw_asybusy; 3229103285Sikob 3230103285Sikob sfp->mode.hdr.tlrt = rfp->mode.hdr.tlrt; 3231103285Sikob sfp->mode.hdr.pri = 0; 3232103285Sikob 3233103285Sikob fw_asyreq(xfer->fc, -1, xfer); 3234103285Sikob/**/ 3235103285Sikob return; 3236103285Sikob} 3237106543Ssimokawa#endif 3238106543Ssimokawa 3239103285Sikob/* 3240103285Sikob * CRC16 check-sum for IEEE1394 register blocks. 3241103285Sikob */ 3242103285Sikobu_int16_t fw_crc16(u_int32_t *ptr, u_int32_t len){ 3243103285Sikob u_int32_t i, sum, crc = 0; 3244103285Sikob int shift; 3245103285Sikob len = (len + 3) & ~3; 3246103285Sikob for(i = 0 ; i < len ; i+= 4){ 3247103285Sikob for( shift = 28 ; shift >= 0 ; shift -= 4){ 3248103285Sikob sum = ((crc >> 12) ^ (ptr[i/4] >> shift)) & 0xf; 3249103285Sikob crc = (crc << 4) ^ ( sum << 12 ) ^ ( sum << 5) ^ sum; 3250103285Sikob } 3251103285Sikob crc &= 0xffff; 3252103285Sikob } 3253103285Sikob return((u_int16_t) crc); 3254103285Sikob} 3255103285SikobDRIVER_MODULE(firewire,fwohci,firewire_driver,firewire_devclass,0,0); 3256103285SikobMODULE_VERSION(firewire, 1); 3257