2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2003-04-17 03:38:03 +00:00
|
|
|
* Copyright (c) 2002-2003
|
2002-09-13 12:31:56 +00:00
|
|
|
* Hidetoshi Shimokawa. All rights reserved.
|
2014-09-27 16:50:21 +00:00
|
|
|
*
|
2002-09-13 12:31:56 +00:00
|
|
|
* 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 following acknowledgement:
|
|
|
|
*
|
|
|
|
* This product includes software developed by Hidetoshi Shimokawa.
|
|
|
|
*
|
|
|
|
* 4. Neither the name of the author nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2014-09-27 16:50:21 +00:00
|
|
|
*
|
2002-09-13 12:31:56 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
2014-09-27 16:50:21 +00:00
|
|
|
*
|
2002-09-13 12:31:56 +00:00
|
|
|
*/
|
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
#ifdef __FreeBSD__
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2004-03-26 23:17:10 +00:00
|
|
|
#endif
|
2003-08-24 17:55:58 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/sysctl.h>
|
2003-10-02 04:06:56 +00:00
|
|
|
#include <sys/bio.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
#include <sys/bus.h>
|
2003-04-17 03:38:03 +00:00
|
|
|
#include <machine/bus.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/ioccom.h>
|
2003-11-07 12:39:39 +00:00
|
|
|
#include <sys/fcntl.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
#include <dev/firewire/firewire.h>
|
|
|
|
#include <dev/firewire/firewirereg.h>
|
|
|
|
#include <dev/firewire/fwmem.h>
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
static int fwmem_speed = 2, fwmem_debug = 0;
|
2002-11-12 13:49:17 +00:00
|
|
|
static struct fw_eui64 fwmem_eui64;
|
2002-09-13 12:31:56 +00:00
|
|
|
SYSCTL_DECL(_hw_firewire);
|
2011-11-07 15:43:11 +00:00
|
|
|
static SYSCTL_NODE(_hw_firewire, OID_AUTO, fwmem, CTLFLAG_RD, 0,
|
2002-12-26 06:50:09 +00:00
|
|
|
"FireWire Memory Access");
|
2002-11-12 13:49:17 +00:00
|
|
|
SYSCTL_UINT(_hw_firewire_fwmem, OID_AUTO, eui64_hi, CTLFLAG_RW,
|
|
|
|
&fwmem_eui64.hi, 0, "Fwmem target EUI64 high");
|
2003-02-09 10:14:22 +00:00
|
|
|
SYSCTL_UINT(_hw_firewire_fwmem, OID_AUTO, eui64_lo, CTLFLAG_RW,
|
2002-11-12 13:49:17 +00:00
|
|
|
&fwmem_eui64.lo, 0, "Fwmem target EUI64 low");
|
2002-09-13 12:31:56 +00:00
|
|
|
SYSCTL_INT(_hw_firewire_fwmem, OID_AUTO, speed, CTLFLAG_RW, &fwmem_speed, 0,
|
|
|
|
"Fwmem link speed");
|
|
|
|
SYSCTL_INT(_debug, OID_AUTO, fwmem_debug, CTLFLAG_RW, &fwmem_debug, 0,
|
|
|
|
"Fwmem driver debug flag");
|
|
|
|
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_FWMEM, "fwmem", "fwmem/FireWire");
|
2004-01-05 14:21:18 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
#define MAXLEN (512 << fwmem_speed)
|
|
|
|
|
2003-11-07 12:39:39 +00:00
|
|
|
struct fwmem_softc {
|
|
|
|
struct fw_eui64 eui;
|
2007-06-06 14:31:36 +00:00
|
|
|
struct firewire_softc *sc;
|
2003-11-07 12:39:39 +00:00
|
|
|
int refcount;
|
|
|
|
};
|
|
|
|
|
2002-11-12 17:19:21 +00:00
|
|
|
static struct fw_xfer *
|
|
|
|
fwmem_xfer_req(
|
2002-11-12 13:49:17 +00:00
|
|
|
struct fw_device *fwdev,
|
2002-11-12 17:19:21 +00:00
|
|
|
caddr_t sc,
|
|
|
|
int spd,
|
2003-04-17 03:38:03 +00:00
|
|
|
int slen,
|
|
|
|
int rlen,
|
2002-11-12 17:19:21 +00:00
|
|
|
void *hand)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
|
2004-01-05 14:21:18 +00:00
|
|
|
xfer = fw_xfer_alloc(M_FWMEM);
|
2002-11-12 11:08:50 +00:00
|
|
|
if (xfer == NULL)
|
2002-09-13 12:31:56 +00:00
|
|
|
return NULL;
|
2002-11-12 11:08:50 +00:00
|
|
|
|
2002-11-12 13:49:17 +00:00
|
|
|
xfer->fc = fwdev->fc;
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.hdr.mode.hdr.dst = FWLOCALBUS | fwdev->dst;
|
2002-11-12 17:19:21 +00:00
|
|
|
if (spd < 0)
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.spd = fwdev->speed;
|
2002-11-12 17:19:21 +00:00
|
|
|
else
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.spd = min(spd, fwdev->speed);
|
2007-03-16 05:39:33 +00:00
|
|
|
xfer->hand = hand;
|
2002-11-12 17:19:21 +00:00
|
|
|
xfer->sc = sc;
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.pay_len = slen;
|
|
|
|
xfer->recv.pay_len = rlen;
|
2002-11-12 17:19:21 +00:00
|
|
|
|
|
|
|
return xfer;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct fw_xfer *
|
|
|
|
fwmem_read_quad(
|
|
|
|
struct fw_device *fwdev,
|
|
|
|
caddr_t sc,
|
2004-05-22 16:14:17 +00:00
|
|
|
uint8_t spd,
|
|
|
|
uint16_t dst_hi,
|
|
|
|
uint32_t dst_lo,
|
2003-10-02 04:06:56 +00:00
|
|
|
void *data,
|
2002-11-12 17:19:21 +00:00
|
|
|
void (*hand)(struct fw_xfer *))
|
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
xfer = fwmem_xfer_req(fwdev, sc, spd, 0, 4, hand);
|
2003-10-02 04:06:56 +00:00
|
|
|
if (xfer == NULL) {
|
2002-11-12 17:19:21 +00:00
|
|
|
return NULL;
|
2003-10-02 04:06:56 +00:00
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
fp = &xfer->send.hdr;
|
2002-09-13 12:31:56 +00:00
|
|
|
fp->mode.rreqq.tcode = FWTCODE_RREQQ;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.rreqq.dest_hi = dst_hi;
|
|
|
|
fp->mode.rreqq.dest_lo = dst_lo;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.payload = NULL;
|
2004-05-22 16:14:17 +00:00
|
|
|
xfer->recv.payload = (uint32_t *)data;
|
2003-10-02 04:06:56 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
if (fwmem_debug)
|
2002-11-12 17:19:21 +00:00
|
|
|
printf("fwmem_read_quad: %d %04x:%08x\n", fwdev->dst,
|
2014-09-27 16:50:21 +00:00
|
|
|
dst_hi, dst_lo);
|
2002-11-12 11:08:50 +00:00
|
|
|
|
2002-11-12 13:49:17 +00:00
|
|
|
if (fw_asyreq(xfer->fc, -1, xfer) == 0)
|
|
|
|
return xfer;
|
|
|
|
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct fw_xfer *
|
|
|
|
fwmem_write_quad(
|
|
|
|
struct fw_device *fwdev,
|
|
|
|
caddr_t sc,
|
2004-05-22 16:14:17 +00:00
|
|
|
uint8_t spd,
|
|
|
|
uint16_t dst_hi,
|
|
|
|
uint32_t dst_lo,
|
2003-10-02 04:06:56 +00:00
|
|
|
void *data,
|
2002-11-12 13:49:17 +00:00
|
|
|
void (*hand)(struct fw_xfer *))
|
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer = fwmem_xfer_req(fwdev, sc, spd, 0, 0, hand);
|
2002-11-12 13:49:17 +00:00
|
|
|
if (xfer == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
fp = &xfer->send.hdr;
|
2003-01-30 05:18:35 +00:00
|
|
|
fp->mode.wreqq.tcode = FWTCODE_WREQQ;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.wreqq.dest_hi = dst_hi;
|
|
|
|
fp->mode.wreqq.dest_lo = dst_lo;
|
2004-05-22 16:14:17 +00:00
|
|
|
fp->mode.wreqq.data = *(uint32_t *)data;
|
2002-11-12 13:49:17 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.payload = xfer->recv.payload = NULL;
|
2002-11-12 13:49:17 +00:00
|
|
|
|
|
|
|
if (fwmem_debug)
|
2002-11-12 17:19:21 +00:00
|
|
|
printf("fwmem_write_quad: %d %04x:%08x %08x\n", fwdev->dst,
|
2014-09-27 16:50:21 +00:00
|
|
|
dst_hi, dst_lo, *(uint32_t *)data);
|
2002-11-12 13:49:17 +00:00
|
|
|
|
|
|
|
if (fw_asyreq(xfer->fc, -1, xfer) == 0)
|
2002-09-13 12:31:56 +00:00
|
|
|
return xfer;
|
2002-11-12 11:08:50 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct fw_xfer *
|
|
|
|
fwmem_read_block(
|
2002-11-12 13:49:17 +00:00
|
|
|
struct fw_device *fwdev,
|
|
|
|
caddr_t sc,
|
2004-05-22 16:14:17 +00:00
|
|
|
uint8_t spd,
|
|
|
|
uint16_t dst_hi,
|
|
|
|
uint32_t dst_lo,
|
2002-11-12 11:08:50 +00:00
|
|
|
int len,
|
2003-10-02 04:06:56 +00:00
|
|
|
void *data,
|
2002-11-12 11:08:50 +00:00
|
|
|
void (*hand)(struct fw_xfer *))
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt *fp;
|
2014-09-27 16:50:21 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer = fwmem_xfer_req(fwdev, sc, spd, 0, roundup2(len, 4), hand);
|
2002-11-12 11:08:50 +00:00
|
|
|
if (xfer == NULL)
|
2002-09-13 12:31:56 +00:00
|
|
|
return NULL;
|
2002-11-12 11:08:50 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
fp = &xfer->send.hdr;
|
2002-09-13 12:31:56 +00:00
|
|
|
fp->mode.rreqb.tcode = FWTCODE_RREQB;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.rreqb.dest_hi = dst_hi;
|
|
|
|
fp->mode.rreqb.dest_lo = dst_lo;
|
|
|
|
fp->mode.rreqb.len = len;
|
2003-10-02 04:06:56 +00:00
|
|
|
fp->mode.rreqb.extcode = 0;
|
|
|
|
|
|
|
|
xfer->send.payload = NULL;
|
|
|
|
xfer->recv.payload = data;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
if (fwmem_debug)
|
2002-11-12 17:19:21 +00:00
|
|
|
printf("fwmem_read_block: %d %04x:%08x %d\n", fwdev->dst,
|
2014-09-27 16:50:21 +00:00
|
|
|
dst_hi, dst_lo, len);
|
2002-11-12 13:49:17 +00:00
|
|
|
if (fw_asyreq(xfer->fc, -1, xfer) == 0)
|
2002-09-13 12:31:56 +00:00
|
|
|
return xfer;
|
2002-11-12 11:08:50 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-02-04 17:09:59 +00:00
|
|
|
struct fw_xfer *
|
|
|
|
fwmem_write_block(
|
|
|
|
struct fw_device *fwdev,
|
|
|
|
caddr_t sc,
|
2004-05-22 16:14:17 +00:00
|
|
|
uint8_t spd,
|
|
|
|
uint16_t dst_hi,
|
|
|
|
uint32_t dst_lo,
|
2003-02-04 17:09:59 +00:00
|
|
|
int len,
|
2003-10-02 04:06:56 +00:00
|
|
|
void *data,
|
2003-02-04 17:09:59 +00:00
|
|
|
void (*hand)(struct fw_xfer *))
|
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer = fwmem_xfer_req(fwdev, sc, spd, len, 0, hand);
|
2003-02-04 17:09:59 +00:00
|
|
|
if (xfer == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
fp = &xfer->send.hdr;
|
2003-02-05 17:19:34 +00:00
|
|
|
fp->mode.wreqb.tcode = FWTCODE_WREQB;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.wreqb.dest_hi = dst_hi;
|
|
|
|
fp->mode.wreqb.dest_lo = dst_lo;
|
|
|
|
fp->mode.wreqb.len = len;
|
2003-10-02 04:06:56 +00:00
|
|
|
fp->mode.wreqb.extcode = 0;
|
|
|
|
|
|
|
|
xfer->send.payload = data;
|
|
|
|
xfer->recv.payload = NULL;
|
2003-02-04 17:09:59 +00:00
|
|
|
|
|
|
|
if (fwmem_debug)
|
|
|
|
printf("fwmem_write_block: %d %04x:%08x %d\n", fwdev->dst,
|
|
|
|
dst_hi, dst_lo, len);
|
|
|
|
if (fw_asyreq(xfer->fc, -1, xfer) == 0)
|
|
|
|
return xfer;
|
|
|
|
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
int
|
2014-09-27 16:50:21 +00:00
|
|
|
fwmem_open(struct cdev *dev, int flags, int fmt, fw_proc *td)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-11-07 12:39:39 +00:00
|
|
|
struct fwmem_softc *fms;
|
2007-06-06 14:31:36 +00:00
|
|
|
struct firewire_softc *sc;
|
|
|
|
int unit = DEV2UNIT(dev);
|
|
|
|
|
|
|
|
sc = devclass_get_softc(firewire_devclass, unit);
|
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
2003-06-03 22:52:55 +00:00
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GLOCK(sc->fc);
|
2003-11-07 12:39:39 +00:00
|
|
|
if (dev->si_drv1 != NULL) {
|
2007-06-06 14:31:36 +00:00
|
|
|
if ((flags & FWRITE) != 0) {
|
|
|
|
FW_GUNLOCK(sc->fc);
|
2014-09-27 16:50:21 +00:00
|
|
|
return (EBUSY);
|
2007-06-06 14:31:36 +00:00
|
|
|
}
|
|
|
|
FW_GUNLOCK(sc->fc);
|
2014-09-27 16:50:21 +00:00
|
|
|
fms = dev->si_drv1;
|
|
|
|
fms->refcount++;
|
2003-11-07 12:39:39 +00:00
|
|
|
} else {
|
2007-06-06 14:31:36 +00:00
|
|
|
dev->si_drv1 = (void *)-1;
|
|
|
|
FW_GUNLOCK(sc->fc);
|
|
|
|
dev->si_drv1 = malloc(sizeof(struct fwmem_softc),
|
2014-09-27 16:50:21 +00:00
|
|
|
M_FWMEM, M_WAITOK);
|
2007-06-06 14:31:36 +00:00
|
|
|
if (dev->si_drv1 == NULL)
|
2014-09-27 16:50:21 +00:00
|
|
|
return (ENOMEM);
|
2003-11-07 12:39:39 +00:00
|
|
|
dev->si_iosize_max = DFLTPHYS;
|
2014-09-27 16:50:21 +00:00
|
|
|
fms = dev->si_drv1;
|
2007-06-06 14:31:36 +00:00
|
|
|
bcopy(&fwmem_eui64, &fms->eui, sizeof(struct fw_eui64));
|
|
|
|
fms->sc = sc;
|
2003-11-07 12:39:39 +00:00
|
|
|
fms->refcount = 1;
|
|
|
|
}
|
|
|
|
if (fwmem_debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: refcount=%d\n", __func__, fms->refcount);
|
2003-02-09 10:14:22 +00:00
|
|
|
|
|
|
|
return (0);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-06-16 09:47:26 +00:00
|
|
|
fwmem_close (struct cdev *dev, int flags, int fmt, fw_proc *td)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-11-07 12:39:39 +00:00
|
|
|
struct fwmem_softc *fms;
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
fms = dev->si_drv1;
|
2007-06-06 14:31:36 +00:00
|
|
|
|
|
|
|
FW_GLOCK(fms->sc->fc);
|
2014-09-27 16:50:21 +00:00
|
|
|
fms->refcount--;
|
2007-06-06 14:31:36 +00:00
|
|
|
FW_GUNLOCK(fms->sc->fc);
|
2003-11-07 12:39:39 +00:00
|
|
|
if (fwmem_debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: refcount=%d\n", __func__, fms->refcount);
|
2003-11-07 12:39:39 +00:00
|
|
|
if (fms->refcount < 1) {
|
2004-11-10 06:21:47 +00:00
|
|
|
free(dev->si_drv1, M_FWMEM);
|
2003-11-07 12:39:39 +00:00
|
|
|
dev->si_drv1 = NULL;
|
|
|
|
}
|
2003-06-03 22:52:55 +00:00
|
|
|
|
2003-02-09 10:14:22 +00:00
|
|
|
return (0);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fwmem_biodone(struct fw_xfer *xfer)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-10-02 04:06:56 +00:00
|
|
|
struct bio *bp;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
bp = (struct bio *)xfer->sc;
|
|
|
|
bp->bio_error = xfer->resp;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
if (bp->bio_error != 0) {
|
2003-10-23 01:55:03 +00:00
|
|
|
if (fwmem_debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: err=%d\n", __func__, bp->bio_error);
|
2003-10-02 04:06:56 +00:00
|
|
|
bp->bio_flags |= BIO_ERROR;
|
|
|
|
bp->bio_resid = bp->bio_bcount;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
biodone(bp);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
fwmem_strategy(struct bio *bp)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-11-07 12:39:39 +00:00
|
|
|
struct fwmem_softc *fms;
|
2003-02-04 17:09:59 +00:00
|
|
|
struct fw_device *fwdev;
|
|
|
|
struct fw_xfer *xfer;
|
2004-06-16 09:47:26 +00:00
|
|
|
struct cdev *dev;
|
2015-01-21 20:05:10 +00:00
|
|
|
int err = 0, iolen;
|
2003-10-02 04:06:56 +00:00
|
|
|
|
|
|
|
dev = bp->bio_dev;
|
|
|
|
/* XXX check request length */
|
2003-02-04 17:09:59 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
fms = dev->si_drv1;
|
2007-06-06 14:31:36 +00:00
|
|
|
fwdev = fw_noderesolve_eui64(fms->sc->fc, &fms->eui);
|
2003-02-04 17:09:59 +00:00
|
|
|
if (fwdev == NULL) {
|
2003-02-09 07:16:01 +00:00
|
|
|
if (fwmem_debug)
|
|
|
|
printf("fwmem: no such device ID:%08x%08x\n",
|
2014-09-27 16:50:21 +00:00
|
|
|
fms->eui.hi, fms->eui.lo);
|
2003-10-02 04:06:56 +00:00
|
|
|
err = EINVAL;
|
|
|
|
goto error;
|
2003-02-04 17:09:59 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
iolen = MIN(bp->bio_bcount, MAXLEN);
|
|
|
|
if ((bp->bio_cmd & BIO_READ) == BIO_READ) {
|
|
|
|
if (iolen == 4 && (bp->bio_offset & 3) == 0)
|
|
|
|
xfer = fwmem_read_quad(fwdev,
|
2014-09-27 16:50:21 +00:00
|
|
|
(void *)bp, fwmem_speed,
|
2003-10-02 04:06:56 +00:00
|
|
|
bp->bio_offset >> 32, bp->bio_offset & 0xffffffff,
|
|
|
|
bp->bio_data, fwmem_biodone);
|
|
|
|
else
|
|
|
|
xfer = fwmem_read_block(fwdev,
|
2014-09-27 16:50:21 +00:00
|
|
|
(void *)bp, fwmem_speed,
|
2003-10-02 04:06:56 +00:00
|
|
|
bp->bio_offset >> 32, bp->bio_offset & 0xffffffff,
|
|
|
|
iolen, bp->bio_data, fwmem_biodone);
|
|
|
|
} else {
|
|
|
|
if (iolen == 4 && (bp->bio_offset & 3) == 0)
|
|
|
|
xfer = fwmem_write_quad(fwdev,
|
|
|
|
(void *)bp, fwmem_speed,
|
|
|
|
bp->bio_offset >> 32, bp->bio_offset & 0xffffffff,
|
|
|
|
bp->bio_data, fwmem_biodone);
|
|
|
|
else
|
|
|
|
xfer = fwmem_write_block(fwdev,
|
|
|
|
(void *)bp, fwmem_speed,
|
|
|
|
bp->bio_offset >> 32, bp->bio_offset & 0xffffffff,
|
|
|
|
iolen, bp->bio_data, fwmem_biodone);
|
|
|
|
}
|
|
|
|
if (xfer == NULL) {
|
|
|
|
err = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/* XXX */
|
|
|
|
bp->bio_resid = bp->bio_bcount - iolen;
|
|
|
|
error:
|
|
|
|
if (err != 0) {
|
2003-10-23 01:55:03 +00:00
|
|
|
if (fwmem_debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: err=%d\n", __func__, err);
|
2003-10-02 04:06:56 +00:00
|
|
|
bp->bio_error = err;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
|
|
|
bp->bio_resid = bp->bio_bcount;
|
|
|
|
biodone(bp);
|
2003-02-04 17:09:59 +00:00
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-02-04 17:09:59 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
int
|
2014-09-27 16:50:21 +00:00
|
|
|
fwmem_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, fw_proc *td)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-11-07 12:39:39 +00:00
|
|
|
struct fwmem_softc *fms;
|
2003-02-09 10:14:22 +00:00
|
|
|
int err = 0;
|
2003-11-07 12:39:39 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
fms = dev->si_drv1;
|
2003-02-09 10:14:22 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case FW_SDEUI64:
|
2003-11-07 12:39:39 +00:00
|
|
|
bcopy(data, &fms->eui, sizeof(struct fw_eui64));
|
2003-02-09 10:14:22 +00:00
|
|
|
break;
|
|
|
|
case FW_GDEUI64:
|
2003-11-07 12:39:39 +00:00
|
|
|
bcopy(&fms->eui, data, sizeof(struct fw_eui64));
|
2003-02-09 10:14:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = EINVAL;
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
return (err);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
int
|
2014-09-27 16:50:21 +00:00
|
|
|
fwmem_poll(struct cdev *dev, int events, fw_proc *td)
|
|
|
|
{
|
2002-09-13 12:31:56 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
int
|
2014-09-27 16:50:21 +00:00
|
|
|
fwmem_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
|
2009-12-29 21:51:28 +00:00
|
|
|
int nproto, vm_memattr_t *memattr)
|
2014-09-27 16:50:21 +00:00
|
|
|
{
|
2002-09-13 12:31:56 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|