2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2003-04-17 03:38:03 +00:00
|
|
|
* Copyright (c) 2003 Hidetoshi Shimokawa
|
2002-11-12 15:22:19 +00:00
|
|
|
* Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the acknowledgement as bellow:
|
|
|
|
*
|
|
|
|
* This product includes software developed by K. Kobayashi and H. Shimokawa
|
|
|
|
*
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/mbuf.h>
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__DragonFly__) || __FreeBSD_version < 500000
|
2003-10-02 04:06:56 +00:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#else
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#endif
|
2002-11-12 15:22:19 +00:00
|
|
|
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
|
|
|
|
#include <sys/bus.h>
|
2003-08-05 03:11:39 +00:00
|
|
|
#include <sys/ctype.h>
|
2003-04-17 03:38:03 +00:00
|
|
|
#include <machine/bus.h>
|
2002-11-12 15:22:19 +00:00
|
|
|
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
#ifdef __DragonFly__
|
|
|
|
#include "firewire.h"
|
|
|
|
#include "firewirereg.h"
|
|
|
|
#include "fwdma.h"
|
|
|
|
#include "fwmem.h"
|
|
|
|
#include "iec68113.h"
|
|
|
|
#else
|
2002-11-12 15:22:19 +00:00
|
|
|
#include <dev/firewire/firewire.h>
|
|
|
|
#include <dev/firewire/firewirereg.h>
|
2003-04-17 03:38:03 +00:00
|
|
|
#include <dev/firewire/fwdma.h>
|
2002-11-12 15:22:19 +00:00
|
|
|
#include <dev/firewire/fwmem.h>
|
2003-01-15 05:26:23 +00:00
|
|
|
#include <dev/firewire/iec68113.h>
|
2004-03-26 23:17:10 +00:00
|
|
|
#endif
|
2002-11-12 15:22:19 +00:00
|
|
|
|
|
|
|
#define FWNODE_INVAL 0xffff
|
|
|
|
|
|
|
|
static d_open_t fw_open;
|
|
|
|
static d_close_t fw_close;
|
|
|
|
static d_ioctl_t fw_ioctl;
|
|
|
|
static d_poll_t fw_poll;
|
|
|
|
static d_read_t fw_read; /* for Isochronous packet */
|
|
|
|
static d_write_t fw_write;
|
|
|
|
static d_mmap_t fw_mmap;
|
2003-10-02 04:06:56 +00:00
|
|
|
static d_strategy_t fw_strategy;
|
2002-11-12 15:22:19 +00:00
|
|
|
|
2004-02-21 21:10:55 +00:00
|
|
|
struct cdevsw firewire_cdevsw = {
|
2004-03-26 23:17:10 +00:00
|
|
|
#ifdef __DragonFly__
|
|
|
|
#define CDEV_MAJOR 127
|
|
|
|
"fw", CDEV_MAJOR, D_MEM, NULL, 0,
|
|
|
|
fw_open, fw_close, fw_read, fw_write, fw_ioctl,
|
|
|
|
fw_poll, fw_mmap, fw_strategy, nodump, nopsize,
|
|
|
|
#elif __FreeBSD_version >= 500104
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = fw_open,
|
|
|
|
.d_close = fw_close,
|
|
|
|
.d_read = fw_read,
|
|
|
|
.d_write = fw_write,
|
|
|
|
.d_ioctl = fw_ioctl,
|
|
|
|
.d_poll = fw_poll,
|
|
|
|
.d_mmap = fw_mmap,
|
2003-10-02 04:06:56 +00:00
|
|
|
.d_strategy = fw_strategy,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_name = "fw",
|
2007-06-06 14:31:36 +00:00
|
|
|
.d_flags = D_MEM
|
2003-03-06 05:06:44 +00:00
|
|
|
#else
|
2004-03-26 23:17:10 +00:00
|
|
|
#define CDEV_MAJOR 127
|
2003-03-06 05:06:44 +00:00
|
|
|
fw_open, fw_close, fw_read, fw_write, fw_ioctl,
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_poll, fw_mmap, fw_strategy, "fw", CDEV_MAJOR,
|
2003-08-05 03:11:39 +00:00
|
|
|
nodump, nopsize, D_MEM, -1
|
2003-03-06 05:06:44 +00:00
|
|
|
#endif
|
2002-11-12 15:22:19 +00:00
|
|
|
};
|
|
|
|
|
2003-08-01 04:51:21 +00:00
|
|
|
struct fw_drv1 {
|
2007-04-30 13:41:40 +00:00
|
|
|
struct firewire_comm *fc;
|
2003-08-01 04:51:21 +00:00
|
|
|
struct fw_xferq *ir;
|
|
|
|
struct fw_xferq *it;
|
|
|
|
struct fw_isobufreq bufreq;
|
2007-04-30 13:41:40 +00:00
|
|
|
STAILQ_HEAD(, fw_bind) binds;
|
|
|
|
STAILQ_HEAD(, fw_xfer) rq;
|
2003-08-01 04:51:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
fwdev_allocbuf(struct firewire_comm *fc, struct fw_xferq *q,
|
|
|
|
struct fw_bufspec *b)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (q->flag & (FWXFERQ_RUNNING | FWXFERQ_EXTBUF))
|
|
|
|
return(EBUSY);
|
|
|
|
|
|
|
|
q->bulkxfer = (struct fw_bulkxfer *) malloc(
|
|
|
|
sizeof(struct fw_bulkxfer) * b->nchunk,
|
|
|
|
M_FW, M_WAITOK);
|
|
|
|
if (q->bulkxfer == NULL)
|
|
|
|
return(ENOMEM);
|
|
|
|
|
2004-05-22 16:14:17 +00:00
|
|
|
b->psize = roundup2(b->psize, sizeof(uint32_t));
|
|
|
|
q->buf = fwdma_malloc_multiseg(fc, sizeof(uint32_t),
|
2003-08-01 04:51:21 +00:00
|
|
|
b->psize, b->nchunk * b->npacket, BUS_DMA_WAITOK);
|
|
|
|
|
|
|
|
if (q->buf == NULL) {
|
|
|
|
free(q->bulkxfer, M_FW);
|
|
|
|
q->bulkxfer = NULL;
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
q->bnchunk = b->nchunk;
|
|
|
|
q->bnpacket = b->npacket;
|
|
|
|
q->psize = (b->psize + 3) & ~3;
|
|
|
|
q->queued = 0;
|
|
|
|
|
|
|
|
STAILQ_INIT(&q->stvalid);
|
|
|
|
STAILQ_INIT(&q->stfree);
|
|
|
|
STAILQ_INIT(&q->stdma);
|
|
|
|
q->stproc = NULL;
|
|
|
|
|
|
|
|
for(i = 0 ; i < q->bnchunk; i++){
|
|
|
|
q->bulkxfer[i].poffset = i * q->bnpacket;
|
|
|
|
q->bulkxfer[i].mbuf = NULL;
|
|
|
|
STAILQ_INSERT_TAIL(&q->stfree, &q->bulkxfer[i], link);
|
|
|
|
}
|
|
|
|
|
|
|
|
q->flag &= ~FWXFERQ_MODEMASK;
|
|
|
|
q->flag |= FWXFERQ_STREAM;
|
|
|
|
q->flag |= FWXFERQ_EXTBUF;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fwdev_freebuf(struct fw_xferq *q)
|
|
|
|
{
|
|
|
|
if (q->flag & FWXFERQ_EXTBUF) {
|
|
|
|
if (q->buf != NULL)
|
|
|
|
fwdma_free_multiseg(q->buf);
|
|
|
|
q->buf = NULL;
|
|
|
|
free(q->bulkxfer, M_FW);
|
|
|
|
q->bulkxfer = NULL;
|
|
|
|
q->flag &= ~FWXFERQ_EXTBUF;
|
|
|
|
q->psize = 0;
|
|
|
|
q->maxq = FWMAXQUEUE;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-12 15:22:19 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
fw_open (struct cdev *dev, int flags, int fmt, fw_proc *td)
|
2002-11-12 15:22:19 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
2007-04-30 13:41:40 +00:00
|
|
|
int unit = DEV2UNIT(dev);
|
|
|
|
struct fw_drv1 *d;
|
|
|
|
struct firewire_softc *sc;
|
2002-11-12 15:22:19 +00:00
|
|
|
|
|
|
|
if (DEV_FWMEM(dev))
|
|
|
|
return fwmem_open(dev, flags, fmt, td);
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
sc = devclass_get_softc(firewire_devclass, unit);
|
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
FW_GLOCK(sc->fc);
|
|
|
|
if (dev->si_drv1 != NULL) {
|
|
|
|
FW_GUNLOCK(sc->fc);
|
2003-11-07 12:30:57 +00:00
|
|
|
return (EBUSY);
|
2007-06-06 14:31:36 +00:00
|
|
|
}
|
|
|
|
/* set dummy value for allocation */
|
|
|
|
dev->si_drv1 = (void *)-1;
|
|
|
|
FW_GUNLOCK(sc->fc);
|
|
|
|
|
|
|
|
dev->si_drv1 = malloc(sizeof(struct fw_drv1), M_FW, M_WAITOK | M_ZERO);
|
|
|
|
if (dev->si_drv1 == NULL)
|
|
|
|
return (ENOMEM);
|
2003-11-07 12:30:57 +00:00
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
|
2003-08-05 03:11:39 +00:00
|
|
|
if ((dev->si_flags & SI_NAMED) == 0) {
|
|
|
|
int unit = DEV2UNIT(dev);
|
|
|
|
int sub = DEV2SUB(dev);
|
|
|
|
|
2008-09-27 08:51:18 +00:00
|
|
|
make_dev(&firewire_cdevsw, dev2unit(dev),
|
2003-08-01 04:51:21 +00:00
|
|
|
UID_ROOT, GID_OPERATOR, 0660,
|
|
|
|
"fw%d.%d", unit, sub);
|
2003-08-05 03:11:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-04-30 13:41:40 +00:00
|
|
|
d = (struct fw_drv1 *)dev->si_drv1;
|
|
|
|
d->fc = sc->fc;
|
|
|
|
STAILQ_INIT(&d->binds);
|
|
|
|
STAILQ_INIT(&d->rq);
|
2003-08-01 04:51:21 +00:00
|
|
|
|
2002-11-12 15:22:19 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
fw_close (struct cdev *dev, int flags, int fmt, fw_proc *td)
|
2002-11-12 15:22:19 +00:00
|
|
|
{
|
2003-08-01 04:51:21 +00:00
|
|
|
struct firewire_comm *fc;
|
|
|
|
struct fw_drv1 *d;
|
2002-11-12 15:22:19 +00:00
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_bind *fwb;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (DEV_FWMEM(dev))
|
|
|
|
return fwmem_close(dev, flags, fmt, td);
|
|
|
|
|
2003-08-01 04:51:21 +00:00
|
|
|
d = (struct fw_drv1 *)dev->si_drv1;
|
2007-04-30 13:41:40 +00:00
|
|
|
fc = d->fc;
|
|
|
|
|
|
|
|
/* remove binding */
|
|
|
|
for (fwb = STAILQ_FIRST(&d->binds); fwb != NULL;
|
|
|
|
fwb = STAILQ_FIRST(&d->binds)) {
|
|
|
|
fw_bindremove(fc, fwb);
|
|
|
|
STAILQ_REMOVE_HEAD(&d->binds, chlist);
|
|
|
|
fw_xferlist_remove(&fwb->xferlist);
|
|
|
|
free(fwb, M_FW);
|
|
|
|
}
|
2003-08-01 04:51:21 +00:00
|
|
|
if (d->ir != NULL) {
|
|
|
|
struct fw_xferq *ir = d->ir;
|
|
|
|
|
|
|
|
if ((ir->flag & FWXFERQ_OPEN) == 0)
|
|
|
|
return (EINVAL);
|
|
|
|
if (ir->flag & FWXFERQ_RUNNING) {
|
|
|
|
ir->flag &= ~FWXFERQ_RUNNING;
|
|
|
|
fc->irx_disable(fc, ir->dmach);
|
|
|
|
}
|
|
|
|
/* free extbuf */
|
|
|
|
fwdev_freebuf(ir);
|
|
|
|
/* drain receiving buffer */
|
|
|
|
for (xfer = STAILQ_FIRST(&ir->q);
|
|
|
|
xfer != NULL; xfer = STAILQ_FIRST(&ir->q)) {
|
|
|
|
ir->queued --;
|
|
|
|
STAILQ_REMOVE_HEAD(&ir->q, link);
|
|
|
|
|
|
|
|
xfer->resp = 0;
|
|
|
|
fw_xfer_done(xfer);
|
|
|
|
}
|
|
|
|
ir->flag &= ~(FWXFERQ_OPEN |
|
|
|
|
FWXFERQ_MODEMASK | FWXFERQ_CHTAGMASK);
|
|
|
|
d->ir = NULL;
|
2002-11-12 15:22:19 +00:00
|
|
|
|
|
|
|
}
|
2003-08-01 04:51:21 +00:00
|
|
|
if (d->it != NULL) {
|
|
|
|
struct fw_xferq *it = d->it;
|
|
|
|
|
|
|
|
if ((it->flag & FWXFERQ_OPEN) == 0)
|
|
|
|
return (EINVAL);
|
|
|
|
if (it->flag & FWXFERQ_RUNNING) {
|
|
|
|
it->flag &= ~FWXFERQ_RUNNING;
|
|
|
|
fc->itx_disable(fc, it->dmach);
|
|
|
|
}
|
|
|
|
/* free extbuf */
|
|
|
|
fwdev_freebuf(it);
|
|
|
|
it->flag &= ~(FWXFERQ_OPEN |
|
|
|
|
FWXFERQ_MODEMASK | FWXFERQ_CHTAGMASK);
|
|
|
|
d->it = NULL;
|
2002-11-12 15:22:19 +00:00
|
|
|
}
|
2003-08-01 04:51:21 +00:00
|
|
|
free(dev->si_drv1, M_FW);
|
|
|
|
dev->si_drv1 = NULL;
|
|
|
|
|
2002-11-12 15:22:19 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-04-30 13:41:40 +00:00
|
|
|
static int
|
|
|
|
fw_read_async(struct fw_drv1 *d, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
int err = 0, s;
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_bind *fwb;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
struct tcode_info *tinfo;
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(d->fc);
|
2007-04-30 13:41:40 +00:00
|
|
|
while ((xfer = STAILQ_FIRST(&d->rq)) == NULL && err == 0)
|
2007-06-06 14:31:36 +00:00
|
|
|
err = msleep(&d->rq, FW_GMTX(d->fc), FWPRI, "fwra", 0);
|
2007-04-30 13:41:40 +00:00
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
if (err != 0) {
|
|
|
|
FW_GUNLOCK(d->fc);
|
2007-04-30 13:41:40 +00:00
|
|
|
return (err);
|
2007-06-06 14:31:36 +00:00
|
|
|
}
|
2007-04-30 13:41:40 +00:00
|
|
|
|
|
|
|
s = splfw();
|
|
|
|
STAILQ_REMOVE_HEAD(&d->rq, link);
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(xfer->fc);
|
2007-04-30 13:41:40 +00:00
|
|
|
splx(s);
|
|
|
|
fp = &xfer->recv.hdr;
|
|
|
|
#if 0 /* for GASP ?? */
|
|
|
|
if (fc->irx_post != NULL)
|
|
|
|
fc->irx_post(fc, fp->mode.ld);
|
|
|
|
#endif
|
|
|
|
tinfo = &xfer->fc->tcode[fp->mode.hdr.tcode];
|
|
|
|
err = uiomove((void *)fp, tinfo->hdr_len, uio);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
err = uiomove((void *)xfer->recv.payload, xfer->recv.pay_len, uio);
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* recycle this xfer */
|
|
|
|
fwb = (struct fw_bind *)xfer->sc;
|
|
|
|
fw_xfer_unload(xfer);
|
|
|
|
xfer->recv.pay_len = PAGE_SIZE;
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(xfer->fc);
|
2007-04-30 13:41:40 +00:00
|
|
|
STAILQ_INSERT_TAIL(&fwb->xferlist, xfer, link);
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(xfer->fc);
|
2007-04-30 13:41:40 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2002-11-12 15:22:19 +00:00
|
|
|
/*
|
|
|
|
* read request.
|
|
|
|
*/
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
fw_read (struct cdev *dev, struct uio *uio, int ioflag)
|
2002-11-12 15:22:19 +00:00
|
|
|
{
|
2007-04-30 13:41:40 +00:00
|
|
|
struct fw_drv1 *d;
|
2002-11-12 15:22:19 +00:00
|
|
|
struct fw_xferq *ir;
|
2007-04-30 13:41:40 +00:00
|
|
|
struct firewire_comm *fc;
|
2002-11-12 15:22:19 +00:00
|
|
|
int err = 0, s, slept = 0;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
|
|
|
|
if (DEV_FWMEM(dev))
|
2007-06-06 14:31:36 +00:00
|
|
|
return (physio(dev, uio, ioflag));
|
2002-11-12 15:22:19 +00:00
|
|
|
|
2007-04-30 13:41:40 +00:00
|
|
|
d = (struct fw_drv1 *)dev->si_drv1;
|
|
|
|
fc = d->fc;
|
|
|
|
ir = d->ir;
|
|
|
|
|
|
|
|
if (ir == NULL)
|
|
|
|
return (fw_read_async(d, uio, ioflag));
|
|
|
|
|
|
|
|
if (ir->buf == NULL)
|
2003-08-01 04:51:21 +00:00
|
|
|
return (EIO);
|
2002-11-12 15:22:19 +00:00
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(fc);
|
2002-11-12 15:22:19 +00:00
|
|
|
readloop:
|
2003-04-17 03:38:03 +00:00
|
|
|
if (ir->stproc == NULL) {
|
2003-01-28 15:09:07 +00:00
|
|
|
/* iso bulkxfer */
|
2002-11-12 15:22:19 +00:00
|
|
|
ir->stproc = STAILQ_FIRST(&ir->stvalid);
|
2003-01-28 15:09:07 +00:00
|
|
|
if (ir->stproc != NULL) {
|
2002-11-12 15:22:19 +00:00
|
|
|
s = splfw();
|
|
|
|
STAILQ_REMOVE_HEAD(&ir->stvalid, link);
|
|
|
|
splx(s);
|
|
|
|
ir->queued = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-04-30 13:41:40 +00:00
|
|
|
if (ir->stproc == NULL) {
|
2003-01-28 15:09:07 +00:00
|
|
|
/* no data avaliable */
|
|
|
|
if (slept == 0) {
|
2002-11-12 15:22:19 +00:00
|
|
|
slept = 1;
|
|
|
|
ir->flag |= FWXFERQ_WAKEUP;
|
2007-06-06 14:31:36 +00:00
|
|
|
err = msleep(ir, FW_GMTX(fc), FWPRI, "fw_read", hz);
|
2003-01-28 15:09:07 +00:00
|
|
|
ir->flag &= ~FWXFERQ_WAKEUP;
|
|
|
|
if (err == 0)
|
|
|
|
goto readloop;
|
|
|
|
} else if (slept == 1)
|
2002-11-12 15:22:19 +00:00
|
|
|
err = EIO;
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(fc);
|
2003-01-28 15:09:07 +00:00
|
|
|
return err;
|
|
|
|
} else if(ir->stproc != NULL) {
|
|
|
|
/* iso bulkxfer */
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(fc);
|
2003-04-17 03:38:03 +00:00
|
|
|
fp = (struct fw_pkt *)fwdma_v_addr(ir->buf,
|
|
|
|
ir->stproc->poffset + ir->queued);
|
2007-04-30 13:41:40 +00:00
|
|
|
if(fc->irx_post != NULL)
|
|
|
|
fc->irx_post(fc, fp->mode.ld);
|
2003-04-17 03:38:03 +00:00
|
|
|
if(fp->mode.stream.len == 0){
|
2002-11-12 15:22:19 +00:00
|
|
|
err = EIO;
|
|
|
|
return err;
|
|
|
|
}
|
2003-01-28 15:09:07 +00:00
|
|
|
err = uiomove((caddr_t)fp,
|
2004-05-22 16:14:17 +00:00
|
|
|
fp->mode.stream.len + sizeof(uint32_t), uio);
|
2002-11-12 15:22:19 +00:00
|
|
|
ir->queued ++;
|
|
|
|
if(ir->queued >= ir->bnpacket){
|
|
|
|
s = splfw();
|
|
|
|
STAILQ_INSERT_TAIL(&ir->stfree, ir->stproc, link);
|
|
|
|
splx(s);
|
2007-04-30 13:41:40 +00:00
|
|
|
fc->irx_enable(fc, ir->dmach);
|
2002-11-12 15:22:19 +00:00
|
|
|
ir->stproc = NULL;
|
|
|
|
}
|
2003-01-28 15:09:07 +00:00
|
|
|
if (uio->uio_resid >= ir->psize) {
|
|
|
|
slept = -1;
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(fc);
|
2003-01-28 15:09:07 +00:00
|
|
|
goto readloop;
|
|
|
|
}
|
2002-11-12 15:22:19 +00:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-04-30 13:41:40 +00:00
|
|
|
static int
|
|
|
|
fw_write_async(struct fw_drv1 *d, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt pkt;
|
|
|
|
struct tcode_info *tinfo;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
bzero(&pkt, sizeof(struct fw_pkt));
|
|
|
|
if ((err = uiomove((caddr_t)&pkt, sizeof(uint32_t), uio)))
|
|
|
|
return (err);
|
|
|
|
tinfo = &d->fc->tcode[pkt.mode.hdr.tcode];
|
|
|
|
if ((err = uiomove((caddr_t)&pkt + sizeof(uint32_t),
|
|
|
|
tinfo->hdr_len - sizeof(uint32_t), uio)))
|
|
|
|
return (err);
|
|
|
|
|
|
|
|
if ((xfer = fw_xfer_alloc_buf(M_FWXFER, uio->uio_resid,
|
|
|
|
PAGE_SIZE/*XXX*/)) == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
bcopy(&pkt, &xfer->send.hdr, sizeof(struct fw_pkt));
|
|
|
|
xfer->send.pay_len = uio->uio_resid;
|
|
|
|
if (uio->uio_resid > 0) {
|
|
|
|
if ((err = uiomove((caddr_t)&xfer->send.payload[0],
|
2009-06-23 09:02:24 +00:00
|
|
|
uio->uio_resid, uio)))
|
2007-04-30 13:41:40 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
xfer->fc = d->fc;
|
|
|
|
xfer->sc = NULL;
|
2007-06-06 14:31:36 +00:00
|
|
|
xfer->hand = fw_xferwake;
|
2007-04-30 13:41:40 +00:00
|
|
|
xfer->send.spd = 2 /* XXX */;
|
|
|
|
|
|
|
|
if ((err = fw_asyreq(xfer->fc, -1, xfer)))
|
|
|
|
goto out;
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
if ((err = fw_xferwait(xfer)))
|
2007-04-30 13:41:40 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (xfer->resp != 0) {
|
|
|
|
err = xfer->resp;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
if (xfer->flag & FWXF_RCVD) {
|
|
|
|
FW_GLOCK(xfer->fc);
|
2007-04-30 13:41:40 +00:00
|
|
|
STAILQ_INSERT_TAIL(&d->rq, xfer, link);
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(xfer->fc);
|
2007-04-30 13:41:40 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2002-11-12 15:22:19 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
fw_write (struct cdev *dev, struct uio *uio, int ioflag)
|
2002-11-12 15:22:19 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
int s, slept = 0;
|
2007-04-30 13:41:40 +00:00
|
|
|
struct fw_drv1 *d;
|
2002-11-12 15:22:19 +00:00
|
|
|
struct fw_pkt *fp;
|
|
|
|
struct firewire_comm *fc;
|
|
|
|
struct fw_xferq *it;
|
|
|
|
|
|
|
|
if (DEV_FWMEM(dev))
|
2007-06-06 14:31:36 +00:00
|
|
|
return (physio(dev, uio, ioflag));
|
2002-11-12 15:22:19 +00:00
|
|
|
|
2007-04-30 13:41:40 +00:00
|
|
|
d = (struct fw_drv1 *)dev->si_drv1;
|
|
|
|
fc = d->fc;
|
|
|
|
it = d->it;
|
|
|
|
|
|
|
|
if (it == NULL)
|
|
|
|
return (fw_write_async(d, uio, ioflag));
|
|
|
|
|
|
|
|
if (it->buf == NULL)
|
2003-08-01 04:51:21 +00:00
|
|
|
return (EIO);
|
2007-06-06 14:31:36 +00:00
|
|
|
|
|
|
|
FW_GLOCK(fc);
|
2002-11-12 15:22:19 +00:00
|
|
|
isoloop:
|
2003-04-21 16:41:20 +00:00
|
|
|
if (it->stproc == NULL) {
|
|
|
|
it->stproc = STAILQ_FIRST(&it->stfree);
|
|
|
|
if (it->stproc != NULL) {
|
2002-11-12 15:22:19 +00:00
|
|
|
s = splfw();
|
2003-04-21 16:41:20 +00:00
|
|
|
STAILQ_REMOVE_HEAD(&it->stfree, link);
|
2002-11-12 15:22:19 +00:00
|
|
|
splx(s);
|
2003-04-21 16:41:20 +00:00
|
|
|
it->queued = 0;
|
|
|
|
} else if (slept == 0) {
|
|
|
|
slept = 1;
|
2007-06-06 14:31:36 +00:00
|
|
|
#if 0 /* XXX to avoid lock recursion */
|
2007-04-30 13:41:40 +00:00
|
|
|
err = fc->itx_enable(fc, it->dmach);
|
2003-04-21 16:41:20 +00:00
|
|
|
if (err)
|
2007-06-06 14:31:36 +00:00
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
err = msleep(it, FW_GMTX(fc), FWPRI, "fw_write", hz);
|
2003-04-21 16:41:20 +00:00
|
|
|
if (err)
|
2007-06-06 14:31:36 +00:00
|
|
|
goto out;
|
2003-01-28 15:09:07 +00:00
|
|
|
goto isoloop;
|
2003-04-21 16:41:20 +00:00
|
|
|
} else {
|
|
|
|
err = EIO;
|
2007-06-06 14:31:36 +00:00
|
|
|
goto out;
|
2002-11-12 15:22:19 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(fc);
|
2003-04-21 16:41:20 +00:00
|
|
|
fp = (struct fw_pkt *)fwdma_v_addr(it->buf,
|
|
|
|
it->stproc->poffset + it->queued);
|
|
|
|
err = uiomove((caddr_t)fp, sizeof(struct fw_isohdr), uio);
|
|
|
|
err = uiomove((caddr_t)fp->mode.stream.payload,
|
|
|
|
fp->mode.stream.len, uio);
|
|
|
|
it->queued ++;
|
|
|
|
if (it->queued >= it->bnpacket) {
|
|
|
|
s = splfw();
|
|
|
|
STAILQ_INSERT_TAIL(&it->stvalid, it->stproc, link);
|
|
|
|
splx(s);
|
|
|
|
it->stproc = NULL;
|
2007-04-30 13:41:40 +00:00
|
|
|
err = fc->itx_enable(fc, it->dmach);
|
2003-04-21 16:41:20 +00:00
|
|
|
}
|
|
|
|
if (uio->uio_resid >= sizeof(struct fw_isohdr)) {
|
|
|
|
slept = 0;
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(fc);
|
2003-04-21 16:41:20 +00:00
|
|
|
goto isoloop;
|
|
|
|
}
|
|
|
|
return err;
|
2007-06-06 14:31:36 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
FW_GUNLOCK(fc);
|
|
|
|
return err;
|
2002-11-12 15:22:19 +00:00
|
|
|
}
|
2007-04-30 13:41:40 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fw_hand(struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
struct fw_bind *fwb;
|
|
|
|
struct fw_drv1 *d;
|
|
|
|
|
|
|
|
fwb = (struct fw_bind *)xfer->sc;
|
|
|
|
d = (struct fw_drv1 *)fwb->sc;
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(xfer->fc);
|
2007-04-30 13:41:40 +00:00
|
|
|
STAILQ_INSERT_TAIL(&d->rq, xfer, link);
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(xfer->fc);
|
2007-04-30 13:41:40 +00:00
|
|
|
wakeup(&d->rq);
|
|
|
|
}
|
|
|
|
|
2002-11-12 15:22:19 +00:00
|
|
|
/*
|
|
|
|
* ioctl support.
|
|
|
|
*/
|
|
|
|
int
|
2004-06-16 09:47:26 +00:00
|
|
|
fw_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, fw_proc *td)
|
2002-11-12 15:22:19 +00:00
|
|
|
{
|
2003-08-01 04:51:21 +00:00
|
|
|
struct firewire_comm *fc;
|
|
|
|
struct fw_drv1 *d;
|
2007-04-30 13:41:40 +00:00
|
|
|
int i, len, err = 0;
|
2002-11-12 15:22:19 +00:00
|
|
|
struct fw_device *fwdev;
|
|
|
|
struct fw_bind *fwb;
|
|
|
|
struct fw_xferq *ir, *it;
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt *fp;
|
2003-01-25 14:47:33 +00:00
|
|
|
struct fw_devinfo *devinfo;
|
2003-07-12 09:34:44 +00:00
|
|
|
void *ptr;
|
2002-11-12 15:22:19 +00:00
|
|
|
|
|
|
|
struct fw_devlstreq *fwdevlst = (struct fw_devlstreq *)data;
|
|
|
|
struct fw_asyreq *asyreq = (struct fw_asyreq *)data;
|
|
|
|
struct fw_isochreq *ichreq = (struct fw_isochreq *)data;
|
|
|
|
struct fw_isobufreq *ibufreq = (struct fw_isobufreq *)data;
|
|
|
|
struct fw_asybindreq *bindreq = (struct fw_asybindreq *)data;
|
|
|
|
struct fw_crom_buf *crom_buf = (struct fw_crom_buf *)data;
|
|
|
|
|
|
|
|
if (DEV_FWMEM(dev))
|
|
|
|
return fwmem_ioctl(dev, cmd, data, flag, td);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return(EINVAL);
|
|
|
|
|
2003-08-01 04:51:21 +00:00
|
|
|
d = (struct fw_drv1 *)dev->si_drv1;
|
2007-04-30 13:41:40 +00:00
|
|
|
fc = d->fc;
|
2003-08-01 04:51:21 +00:00
|
|
|
ir = d->ir;
|
|
|
|
it = d->it;
|
|
|
|
|
2002-11-12 15:22:19 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case FW_STSTREAM:
|
2003-08-01 04:51:21 +00:00
|
|
|
if (it == NULL) {
|
2007-06-06 14:31:36 +00:00
|
|
|
i = fw_open_isodma(fc, /* tx */1);
|
|
|
|
if (i < 0) {
|
2003-08-01 04:51:21 +00:00
|
|
|
err = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
it = fc->it[i];
|
2003-08-01 04:51:21 +00:00
|
|
|
err = fwdev_allocbuf(fc, it, &d->bufreq.tx);
|
2007-06-06 14:31:36 +00:00
|
|
|
if (err) {
|
|
|
|
it->flag &= ~FWXFERQ_OPEN;
|
2003-08-01 04:51:21 +00:00
|
|
|
break;
|
2007-06-06 14:31:36 +00:00
|
|
|
}
|
2003-08-01 04:51:21 +00:00
|
|
|
}
|
|
|
|
it->flag &= ~0xff;
|
|
|
|
it->flag |= (0x3f & ichreq->ch);
|
|
|
|
it->flag |= ((0x3 & ichreq->tag) << 6);
|
|
|
|
d->it = it;
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_GTSTREAM:
|
2003-08-01 04:51:21 +00:00
|
|
|
if (it != NULL) {
|
|
|
|
ichreq->ch = it->flag & 0x3f;
|
|
|
|
ichreq->tag = it->flag >> 2 & 0x3;
|
|
|
|
} else
|
|
|
|
err = EINVAL;
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_SRSTREAM:
|
2003-08-01 04:51:21 +00:00
|
|
|
if (ir == NULL) {
|
2007-06-06 14:31:36 +00:00
|
|
|
i = fw_open_isodma(fc, /* tx */0);
|
|
|
|
if (i < 0) {
|
2003-08-01 04:51:21 +00:00
|
|
|
err = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
ir = fc->ir[i];
|
2003-08-01 04:51:21 +00:00
|
|
|
err = fwdev_allocbuf(fc, ir, &d->bufreq.rx);
|
2007-06-06 14:31:36 +00:00
|
|
|
if (err) {
|
|
|
|
ir->flag &= ~FWXFERQ_OPEN;
|
2003-08-01 04:51:21 +00:00
|
|
|
break;
|
2007-06-06 14:31:36 +00:00
|
|
|
}
|
2003-08-01 04:51:21 +00:00
|
|
|
}
|
|
|
|
ir->flag &= ~0xff;
|
|
|
|
ir->flag |= (0x3f & ichreq->ch);
|
|
|
|
ir->flag |= ((0x3 & ichreq->tag) << 6);
|
|
|
|
d->ir = ir;
|
|
|
|
err = fc->irx_enable(fc, ir->dmach);
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_GRSTREAM:
|
2003-08-01 04:51:21 +00:00
|
|
|
if (d->ir != NULL) {
|
|
|
|
ichreq->ch = ir->flag & 0x3f;
|
|
|
|
ichreq->tag = ir->flag >> 2 & 0x3;
|
|
|
|
} else
|
|
|
|
err = EINVAL;
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_SSTBUF:
|
2003-08-01 04:51:21 +00:00
|
|
|
bcopy(ibufreq, &d->bufreq, sizeof(d->bufreq));
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_GSTBUF:
|
2003-08-01 04:51:21 +00:00
|
|
|
bzero(&ibufreq->rx, sizeof(ibufreq->rx));
|
|
|
|
if (ir != NULL) {
|
|
|
|
ibufreq->rx.nchunk = ir->bnchunk;
|
|
|
|
ibufreq->rx.npacket = ir->bnpacket;
|
|
|
|
ibufreq->rx.psize = ir->psize;
|
|
|
|
}
|
|
|
|
bzero(&ibufreq->tx, sizeof(ibufreq->tx));
|
|
|
|
if (it != NULL) {
|
|
|
|
ibufreq->tx.nchunk = it->bnchunk;
|
|
|
|
ibufreq->tx.npacket = it->bnpacket;
|
|
|
|
ibufreq->tx.psize = it->psize;
|
|
|
|
}
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_ASYREQ:
|
2003-10-02 04:06:56 +00:00
|
|
|
{
|
|
|
|
struct tcode_info *tinfo;
|
2003-10-24 13:55:51 +00:00
|
|
|
int pay_len = 0;
|
2003-10-02 04:06:56 +00:00
|
|
|
|
2002-11-12 15:22:19 +00:00
|
|
|
fp = &asyreq->pkt;
|
2007-04-30 13:41:40 +00:00
|
|
|
tinfo = &fc->tcode[fp->mode.hdr.tcode];
|
2003-10-24 13:55:51 +00:00
|
|
|
|
|
|
|
if ((tinfo->flag & FWTI_BLOCK_ASY) != 0)
|
|
|
|
pay_len = MAX(0, asyreq->req.len - tinfo->hdr_len);
|
|
|
|
|
|
|
|
xfer = fw_xfer_alloc_buf(M_FWXFER, pay_len, PAGE_SIZE/*XXX*/);
|
|
|
|
if (xfer == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
2002-11-12 15:22:19 +00:00
|
|
|
switch (asyreq->req.type) {
|
|
|
|
case FWASREQNODE:
|
|
|
|
break;
|
|
|
|
case FWASREQEUI:
|
2007-04-30 13:41:40 +00:00
|
|
|
fwdev = fw_noderesolve_eui64(fc,
|
2003-02-09 10:14:22 +00:00
|
|
|
&asyreq->req.dst.eui);
|
2002-11-12 15:22:19 +00:00
|
|
|
if (fwdev == NULL) {
|
2007-04-30 13:41:40 +00:00
|
|
|
device_printf(fc->bdev,
|
2003-01-06 08:07:20 +00:00
|
|
|
"cannot find node\n");
|
2002-11-12 15:22:19 +00:00
|
|
|
err = EINVAL;
|
2003-10-24 13:55:51 +00:00
|
|
|
goto out;
|
2002-11-12 15:22:19 +00:00
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
fp->mode.hdr.dst = FWLOCALBUS | fwdev->dst;
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FWASRESTL:
|
|
|
|
/* XXX what's this? */
|
|
|
|
break;
|
|
|
|
case FWASREQSTREAM:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
}
|
2003-10-24 13:55:51 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
bcopy(fp, (void *)&xfer->send.hdr, tinfo->hdr_len);
|
2003-10-24 13:55:51 +00:00
|
|
|
if (pay_len > 0)
|
2003-10-02 04:06:56 +00:00
|
|
|
bcopy((char *)fp + tinfo->hdr_len,
|
2004-03-24 01:29:08 +00:00
|
|
|
(void *)xfer->send.payload, pay_len);
|
2003-10-24 13:55:51 +00:00
|
|
|
xfer->send.spd = asyreq->req.sped;
|
2007-06-06 14:31:36 +00:00
|
|
|
xfer->hand = fw_xferwake;
|
2003-10-24 13:55:51 +00:00
|
|
|
|
2007-04-30 13:41:40 +00:00
|
|
|
if ((err = fw_asyreq(fc, -1, xfer)) != 0)
|
2003-10-24 13:55:51 +00:00
|
|
|
goto out;
|
2007-06-06 14:31:36 +00:00
|
|
|
if ((err = fw_xferwait(xfer)) != 0)
|
2003-10-24 13:55:51 +00:00
|
|
|
goto out;
|
|
|
|
if (xfer->resp != 0) {
|
|
|
|
err = EIO;
|
|
|
|
goto out;
|
2002-11-12 15:22:19 +00:00
|
|
|
}
|
2003-10-24 13:55:51 +00:00
|
|
|
if ((tinfo->flag & FWTI_TLABEL) == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* copy response */
|
2007-04-30 13:41:40 +00:00
|
|
|
tinfo = &fc->tcode[xfer->recv.hdr.mode.hdr.tcode];
|
2004-05-23 18:43:44 +00:00
|
|
|
if (xfer->recv.hdr.mode.hdr.tcode == FWTCODE_RRESB ||
|
|
|
|
xfer->recv.hdr.mode.hdr.tcode == FWTCODE_LRES) {
|
|
|
|
pay_len = xfer->recv.pay_len;
|
|
|
|
if (asyreq->req.len >= xfer->recv.pay_len + tinfo->hdr_len) {
|
|
|
|
asyreq->req.len = xfer->recv.pay_len +
|
|
|
|
tinfo->hdr_len;
|
|
|
|
} else {
|
|
|
|
err = EINVAL;
|
|
|
|
pay_len = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pay_len = 0;
|
|
|
|
}
|
2003-10-24 13:55:51 +00:00
|
|
|
bcopy(&xfer->recv.hdr, fp, tinfo->hdr_len);
|
2004-05-23 18:43:44 +00:00
|
|
|
bcopy(xfer->recv.payload, (char *)fp + tinfo->hdr_len, pay_len);
|
2003-10-24 13:55:51 +00:00
|
|
|
out:
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_xfer_free_buf(xfer);
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
2003-10-02 04:06:56 +00:00
|
|
|
}
|
2002-11-12 15:22:19 +00:00
|
|
|
case FW_IBUSRST:
|
2007-04-30 13:41:40 +00:00
|
|
|
fc->ibr(fc);
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_CBINDADDR:
|
2007-04-30 13:41:40 +00:00
|
|
|
fwb = fw_bindlookup(fc,
|
2002-11-12 15:22:19 +00:00
|
|
|
bindreq->start.hi, bindreq->start.lo);
|
|
|
|
if(fwb == NULL){
|
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-30 13:41:40 +00:00
|
|
|
fw_bindremove(fc, fwb);
|
|
|
|
STAILQ_REMOVE(&d->binds, fwb, fw_bind, chlist);
|
|
|
|
fw_xferlist_remove(&fwb->xferlist);
|
2003-02-01 15:04:33 +00:00
|
|
|
free(fwb, M_FW);
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_SBINDADDR:
|
|
|
|
if(bindreq->len <= 0 ){
|
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(bindreq->start.hi > 0xffff ){
|
|
|
|
err = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
fwb = (struct fw_bind *)malloc(sizeof (struct fw_bind), M_FW, M_WAITOK);
|
2002-11-12 15:22:19 +00:00
|
|
|
if(fwb == NULL){
|
|
|
|
err = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
fwb->start = ((u_int64_t)bindreq->start.hi << 32) |
|
|
|
|
bindreq->start.lo;
|
|
|
|
fwb->end = fwb->start + bindreq->len;
|
2007-04-30 13:41:40 +00:00
|
|
|
fwb->sc = (void *)d;
|
2003-04-17 03:38:03 +00:00
|
|
|
STAILQ_INIT(&fwb->xferlist);
|
2007-04-30 13:41:40 +00:00
|
|
|
err = fw_bindadd(fc, fwb);
|
|
|
|
if (err == 0) {
|
|
|
|
fw_xferlist_add(&fwb->xferlist, M_FWXFER,
|
|
|
|
/* XXX */
|
|
|
|
PAGE_SIZE, PAGE_SIZE, 5,
|
|
|
|
fc, (void *)fwb, fw_hand);
|
|
|
|
STAILQ_INSERT_TAIL(&d->binds, fwb, chlist);
|
|
|
|
}
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_GDEVLST:
|
2003-01-25 14:47:33 +00:00
|
|
|
i = len = 1;
|
|
|
|
/* myself */
|
|
|
|
devinfo = &fwdevlst->dev[0];
|
2007-04-30 13:41:40 +00:00
|
|
|
devinfo->dst = fc->nodeid;
|
2003-01-25 14:47:33 +00:00
|
|
|
devinfo->status = 0; /* XXX */
|
2007-04-30 13:41:40 +00:00
|
|
|
devinfo->eui.hi = fc->eui.hi;
|
|
|
|
devinfo->eui.lo = fc->eui.lo;
|
|
|
|
STAILQ_FOREACH(fwdev, &fc->devices, link) {
|
2003-01-25 14:47:33 +00:00
|
|
|
if(len < FW_MAX_DEVLST){
|
|
|
|
devinfo = &fwdevlst->dev[len++];
|
|
|
|
devinfo->dst = fwdev->dst;
|
|
|
|
devinfo->status =
|
|
|
|
(fwdev->status == FWDEVINVAL)?0:1;
|
|
|
|
devinfo->eui.hi = fwdev->eui.hi;
|
|
|
|
devinfo->eui.lo = fwdev->eui.lo;
|
2002-11-12 15:22:19 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
fwdevlst->n = i;
|
2003-01-25 14:47:33 +00:00
|
|
|
fwdevlst->info_len = len;
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_GTPMAP:
|
2007-04-30 13:41:40 +00:00
|
|
|
bcopy(fc->topology_map, data,
|
|
|
|
(fc->topology_map->crc_len + 1) * 4);
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
case FW_GCROM:
|
2007-04-30 13:41:40 +00:00
|
|
|
STAILQ_FOREACH(fwdev, &fc->devices, link)
|
2003-02-01 14:42:49 +00:00
|
|
|
if (FW_EUI64_EQUAL(fwdev->eui, crom_buf->eui))
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
if (fwdev == NULL) {
|
2007-04-30 13:41:40 +00:00
|
|
|
if (!FW_EUI64_EQUAL(fc->eui, crom_buf->eui)) {
|
2003-07-12 09:34:44 +00:00
|
|
|
err = FWNODE_INVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* myself */
|
|
|
|
ptr = malloc(CROMSIZE, M_FW, M_WAITOK);
|
|
|
|
len = CROMSIZE;
|
|
|
|
for (i = 0; i < CROMSIZE/4; i++)
|
2004-05-22 16:14:17 +00:00
|
|
|
((uint32_t *)ptr)[i]
|
2007-04-30 13:41:40 +00:00
|
|
|
= ntohl(fc->config_rom[i]);
|
2003-07-12 09:34:44 +00:00
|
|
|
} else {
|
|
|
|
/* found */
|
|
|
|
ptr = (void *)&fwdev->csrrom[0];
|
|
|
|
if (fwdev->rommax < CSRROMOFF)
|
|
|
|
len = 0;
|
|
|
|
else
|
|
|
|
len = fwdev->rommax - CSRROMOFF + 4;
|
2002-11-12 15:22:19 +00:00
|
|
|
}
|
2007-04-24 12:15:05 +00:00
|
|
|
if (crom_buf->len < len)
|
2002-11-12 15:22:19 +00:00
|
|
|
len = crom_buf->len;
|
|
|
|
else
|
|
|
|
crom_buf->len = len;
|
2003-07-12 09:34:44 +00:00
|
|
|
err = copyout(ptr, crom_buf->ptr, len);
|
|
|
|
if (fwdev == NULL)
|
|
|
|
/* myself */
|
|
|
|
free(ptr, M_FW);
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-04-30 13:41:40 +00:00
|
|
|
fc->ioctl (dev, cmd, data, flag, td);
|
2002-11-12 15:22:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
int
|
2004-06-16 09:47:26 +00:00
|
|
|
fw_poll(struct cdev *dev, int events, fw_proc *td)
|
2002-11-12 15:22:19 +00:00
|
|
|
{
|
2003-08-01 04:51:21 +00:00
|
|
|
struct fw_xferq *ir;
|
2002-11-12 15:22:19 +00:00
|
|
|
int revents;
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
if (DEV_FWMEM(dev))
|
|
|
|
return fwmem_poll(dev, events, td);
|
|
|
|
|
2003-08-01 04:51:21 +00:00
|
|
|
ir = ((struct fw_drv1 *)dev->si_drv1)->ir;
|
2002-11-12 15:22:19 +00:00
|
|
|
revents = 0;
|
|
|
|
tmp = POLLIN | POLLRDNORM;
|
|
|
|
if (events & tmp) {
|
2003-08-01 04:51:21 +00:00
|
|
|
if (STAILQ_FIRST(&ir->q) != NULL)
|
2002-11-12 15:22:19 +00:00
|
|
|
revents |= tmp;
|
|
|
|
else
|
2003-08-01 04:51:21 +00:00
|
|
|
selrecord(td, &ir->rsel);
|
2002-11-12 15:22:19 +00:00
|
|
|
}
|
|
|
|
tmp = POLLOUT | POLLWRNORM;
|
|
|
|
if (events & tmp) {
|
|
|
|
/* XXX should be fixed */
|
|
|
|
revents |= tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return revents;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__DragonFly__) || __FreeBSD_version < 500102
|
2004-06-16 09:47:26 +00:00
|
|
|
fw_mmap (struct cdev *dev, vm_offset_t offset, int nproto)
|
2003-02-27 12:51:24 +00:00
|
|
|
#else
|
2009-12-29 21:51:28 +00:00
|
|
|
fw_mmap (struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
|
|
|
|
int nproto, vm_memattr_t *memattr)
|
2003-02-27 12:51:24 +00:00
|
|
|
#endif
|
2002-11-12 15:22:19 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (DEV_FWMEM(dev))
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__DragonFly__) || __FreeBSD_version < 500102
|
2003-02-27 12:51:24 +00:00
|
|
|
return fwmem_mmap(dev, offset, nproto);
|
|
|
|
#else
|
2009-12-29 21:51:28 +00:00
|
|
|
return fwmem_mmap(dev, offset, paddr, nproto, memattr);
|
2003-02-27 12:51:24 +00:00
|
|
|
#endif
|
2002-11-12 15:22:19 +00:00
|
|
|
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2003-08-05 03:11:39 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
static void
|
|
|
|
fw_strategy(struct bio *bp)
|
|
|
|
{
|
2004-06-16 09:47:26 +00:00
|
|
|
struct cdev *dev;
|
2003-10-02 04:06:56 +00:00
|
|
|
|
|
|
|
dev = bp->bio_dev;
|
|
|
|
if (DEV_FWMEM(dev)) {
|
|
|
|
fwmem_strategy(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bp->bio_error = EOPNOTSUPP;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
|
|
|
bp->bio_resid = bp->bio_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
2003-08-05 03:11:39 +00:00
|
|
|
int
|
|
|
|
fwdev_makedev(struct firewire_softc *sc)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__DragonFly__) || __FreeBSD_version < 500000
|
|
|
|
cdevsw_add(&firewire_cdevsw);
|
|
|
|
#else
|
2004-06-16 09:47:26 +00:00
|
|
|
struct cdev *d;
|
2003-08-05 03:11:39 +00:00
|
|
|
int unit;
|
|
|
|
|
|
|
|
unit = device_get_unit(sc->fc->bdev);
|
|
|
|
sc->dev = make_dev(&firewire_cdevsw, MAKEMINOR(0, unit, 0),
|
|
|
|
UID_ROOT, GID_OPERATOR, 0660,
|
|
|
|
"fw%d.%d", unit, 0);
|
|
|
|
d = make_dev(&firewire_cdevsw,
|
|
|
|
MAKEMINOR(FWMEM_FLAG, unit, 0),
|
|
|
|
UID_ROOT, GID_OPERATOR, 0660,
|
|
|
|
"fwmem%d.%d", unit, 0);
|
|
|
|
dev_depends(sc->dev, d);
|
|
|
|
make_dev_alias(sc->dev, "fw%d", unit);
|
|
|
|
make_dev_alias(d, "fwmem%d", unit);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fwdev_destroydev(struct firewire_softc *sc)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__DragonFly__) || __FreeBSD_version < 500000
|
2003-08-05 03:11:39 +00:00
|
|
|
cdevsw_remove(&firewire_cdevsw);
|
2004-03-26 23:17:10 +00:00
|
|
|
#else
|
|
|
|
destroy_dev(sc->dev);
|
2003-08-05 03:11:39 +00:00
|
|
|
#endif
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
|
2003-08-05 03:11:39 +00:00
|
|
|
#define NDEVTYPE 2
|
|
|
|
void
|
2005-08-08 19:55:32 +00:00
|
|
|
fwdev_clone(void *arg, struct ucred *cred, char *name, int namelen,
|
|
|
|
struct cdev **dev)
|
2003-08-05 03:11:39 +00:00
|
|
|
{
|
|
|
|
struct firewire_softc *sc;
|
|
|
|
char *devnames[NDEVTYPE] = {"fw", "fwmem"};
|
|
|
|
char *subp = NULL;
|
|
|
|
int devflag[NDEVTYPE] = {0, FWMEM_FLAG};
|
|
|
|
int i, unit = 0, sub = 0;
|
|
|
|
|
2004-06-17 17:16:53 +00:00
|
|
|
if (*dev != NULL)
|
2003-08-05 03:11:39 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < NDEVTYPE; i++)
|
2003-10-01 06:04:30 +00:00
|
|
|
if (dev_stdclone(name, &subp, devnames[i], &unit) == 2)
|
2003-08-05 03:11:39 +00:00
|
|
|
goto found;
|
|
|
|
/* not match */
|
|
|
|
return;
|
|
|
|
found:
|
|
|
|
|
|
|
|
if (subp == NULL || *subp++ != '.')
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* /dev/fwU.S */
|
|
|
|
while (isdigit(*subp)) {
|
|
|
|
sub *= 10;
|
|
|
|
sub += *subp++ - '0';
|
|
|
|
}
|
|
|
|
if (*subp != '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
sc = devclass_get_softc(firewire_devclass, unit);
|
|
|
|
if (sc == NULL)
|
|
|
|
return;
|
2013-09-07 13:45:44 +00:00
|
|
|
*dev = make_dev_credf(MAKEDEV_REF, &firewire_cdevsw,
|
|
|
|
MAKEMINOR(devflag[i], unit, sub), cred, UID_ROOT, GID_OPERATOR,
|
|
|
|
0660, "%s%d.%d", devnames[i], unit, sub);
|
2003-08-05 03:11:39 +00:00
|
|
|
dev_depends(sc->dev, *dev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|