2002-09-13 12:31:56 +00:00
|
|
|
/*
|
2003-04-17 03:38:03 +00:00
|
|
|
* Copyright (c) 2003 Hidetoshi Shimokawa
|
2002-09-13 12:31:56 +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/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
2003-06-30 06:33:18 +00:00
|
|
|
#if __FreeBSD_version < 500000
|
|
|
|
#include <machine/clock.h> /* for DELAY() */
|
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
#include <sys/bus.h> /* used by smbus and newbus */
|
2003-04-17 03:38:03 +00:00
|
|
|
#include <machine/bus.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
#include <dev/firewire/firewire.h>
|
|
|
|
#include <dev/firewire/firewirereg.h>
|
2003-01-30 05:18:35 +00:00
|
|
|
#include <dev/firewire/fwmem.h>
|
2002-09-13 12:31:56 +00:00
|
|
|
#include <dev/firewire/iec13213.h>
|
|
|
|
#include <dev/firewire/iec68113.h>
|
|
|
|
|
2003-06-15 04:09:26 +00:00
|
|
|
struct crom_src_buf {
|
|
|
|
struct crom_src src;
|
|
|
|
struct crom_chunk root;
|
|
|
|
struct crom_chunk vendor;
|
|
|
|
struct crom_chunk hw;
|
|
|
|
};
|
|
|
|
|
2003-10-06 07:17:43 +00:00
|
|
|
int firewire_debug=0, try_bmr=1, hold_count=3;
|
2002-09-13 12:31:56 +00:00
|
|
|
SYSCTL_INT(_debug, OID_AUTO, firewire_debug, CTLFLAG_RW, &firewire_debug, 0,
|
2002-12-26 06:50:09 +00:00
|
|
|
"FireWire driver debug flag");
|
2003-01-23 13:34:40 +00:00
|
|
|
SYSCTL_NODE(_hw, OID_AUTO, firewire, CTLFLAG_RD, 0, "FireWire Subsystem");
|
|
|
|
SYSCTL_INT(_hw_firewire, OID_AUTO, try_bmr, CTLFLAG_RW, &try_bmr, 0,
|
|
|
|
"Try to be a bus manager");
|
2003-10-06 07:17:43 +00:00
|
|
|
SYSCTL_INT(_hw_firewire, OID_AUTO, hold_count, CTLFLAG_RW, &hold_count, 0,
|
|
|
|
"Number of count of bus resets for removing lost device information");
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-02-01 15:04:33 +00:00
|
|
|
MALLOC_DEFINE(M_FW, "firewire", "FireWire");
|
2003-02-03 07:33:31 +00:00
|
|
|
MALLOC_DEFINE(M_FWXFER, "fw_xfer", "XFER/FireWire");
|
2003-02-01 15:04:33 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
#define FW_MAXASYRTY 4
|
|
|
|
|
|
|
|
devclass_t firewire_devclass;
|
|
|
|
|
2004-01-06 14:30:47 +00:00
|
|
|
static int firewire_match (device_t);
|
|
|
|
static int firewire_attach (device_t);
|
|
|
|
static int firewire_detach (device_t);
|
|
|
|
static int firewire_resume (device_t);
|
2002-09-13 12:31:56 +00:00
|
|
|
#if 0
|
2004-01-06 14:30:47 +00:00
|
|
|
static int firewire_shutdown (device_t);
|
2002-09-13 12:31:56 +00:00
|
|
|
#endif
|
2004-01-06 14:30:47 +00:00
|
|
|
static device_t firewire_add_child (device_t, int, const char *, int);
|
|
|
|
static void fw_try_bmr (void *);
|
|
|
|
static void fw_try_bmr_callback (struct fw_xfer *);
|
|
|
|
static void fw_asystart (struct fw_xfer *);
|
|
|
|
static int fw_get_tlabel (struct firewire_comm *, struct fw_xfer *);
|
|
|
|
static void fw_bus_probe (struct firewire_comm *);
|
|
|
|
static void fw_bus_explore (struct firewire_comm *);
|
|
|
|
static void fw_bus_explore_callback (struct fw_xfer *);
|
|
|
|
static void fw_attach_dev (struct firewire_comm *);
|
2002-11-07 02:13:40 +00:00
|
|
|
#ifdef FW_VMACCESS
|
2004-01-06 14:30:47 +00:00
|
|
|
static void fw_vmaccess (struct fw_xfer *);
|
2002-11-07 02:13:40 +00:00
|
|
|
#endif
|
2004-01-06 14:30:47 +00:00
|
|
|
struct fw_xfer *asyreqq (struct firewire_comm *, u_int8_t, u_int8_t, u_int8_t,
|
|
|
|
u_int32_t, u_int32_t, void (*)(struct fw_xfer *));
|
|
|
|
static int fw_bmr (struct firewire_comm *);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
static device_method_t firewire_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, firewire_match),
|
|
|
|
DEVMETHOD(device_attach, firewire_attach),
|
|
|
|
DEVMETHOD(device_detach, firewire_detach),
|
2003-01-04 06:40:57 +00:00
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
2003-06-28 11:11:36 +00:00
|
|
|
DEVMETHOD(device_resume, firewire_resume),
|
2002-09-13 12:31:56 +00:00
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_add_child, firewire_add_child),
|
|
|
|
DEVMETHOD(bus_print_child, bus_generic_print_child),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
char linkspeed[7][0x10]={"S100","S200","S400","S800","S1600","S3200","Unknown"};
|
|
|
|
|
2003-05-11 10:32:20 +00:00
|
|
|
/* IEEE-1394a Table C-2 Gap count as a function of hops*/
|
|
|
|
#define MAX_GAPHOP 15
|
|
|
|
u_int gap_cnt[] = { 5, 5, 7, 8, 10, 13, 16, 18,
|
|
|
|
21, 24, 26, 29, 32, 35, 37, 40};
|
2002-11-12 15:22:19 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
static driver_t firewire_driver = {
|
|
|
|
"firewire",
|
|
|
|
firewire_methods,
|
|
|
|
sizeof(struct firewire_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2003-01-30 05:18:35 +00:00
|
|
|
* Lookup fwdev by node id.
|
2002-09-13 12:31:56 +00:00
|
|
|
*/
|
2002-11-12 13:49:17 +00:00
|
|
|
struct fw_device *
|
2003-01-30 05:18:35 +00:00
|
|
|
fw_noderesolve_nodeid(struct firewire_comm *fc, int dst)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fw_device *fwdev;
|
2003-01-30 05:18:35 +00:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splfw();
|
2003-02-01 14:42:49 +00:00
|
|
|
STAILQ_FOREACH(fwdev, &fc->devices, link)
|
2003-10-02 04:06:56 +00:00
|
|
|
if (fwdev->dst == dst && fwdev->status != FWDEVINVAL)
|
2002-09-13 12:31:56 +00:00
|
|
|
break;
|
2003-01-30 05:18:35 +00:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return fwdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup fwdev by EUI64.
|
|
|
|
*/
|
|
|
|
struct fw_device *
|
2003-02-09 10:14:22 +00:00
|
|
|
fw_noderesolve_eui64(struct firewire_comm *fc, struct fw_eui64 *eui)
|
2003-01-30 05:18:35 +00:00
|
|
|
{
|
|
|
|
struct fw_device *fwdev;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splfw();
|
2003-02-01 14:42:49 +00:00
|
|
|
STAILQ_FOREACH(fwdev, &fc->devices, link)
|
2003-02-09 10:14:22 +00:00
|
|
|
if (FW_EUI64_EQUAL(fwdev->eui, *eui))
|
2003-01-30 05:18:35 +00:00
|
|
|
break;
|
|
|
|
splx(s);
|
|
|
|
|
2002-11-12 13:49:17 +00:00
|
|
|
if(fwdev == NULL) return NULL;
|
|
|
|
if(fwdev->status == FWDEVINVAL) return NULL;
|
|
|
|
return fwdev;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 15:22:19 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* Async. request procedure for userland application.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
fw_asyreq(struct firewire_comm *fc, int sub, struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct fw_xferq *xferq;
|
|
|
|
int tl = 0, len;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
int tcode;
|
|
|
|
struct tcode_info *info;
|
|
|
|
|
|
|
|
if(xfer == NULL) return EINVAL;
|
|
|
|
if(xfer->act.hand == NULL){
|
|
|
|
printf("act.hand == NULL\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
fp = &xfer->send.hdr;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
tcode = fp->mode.common.tcode & 0xf;
|
|
|
|
info = &fc->tcode[tcode];
|
|
|
|
if (info->flag == 0) {
|
|
|
|
printf("invalid tcode=%d\n", tcode);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
if (info->flag & FWTI_REQ)
|
|
|
|
xferq = fc->atq;
|
|
|
|
else
|
|
|
|
xferq = fc->ats;
|
|
|
|
len = info->hdr_len;
|
2003-10-02 04:06:56 +00:00
|
|
|
if (xfer->send.pay_len > MAXREC(fc->maxrec)) {
|
|
|
|
printf("send.pay_len > maxrec\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
if (info->flag & FWTI_BLOCK_STR)
|
2003-10-02 04:06:56 +00:00
|
|
|
len = fp->mode.stream.len;
|
2002-09-13 12:31:56 +00:00
|
|
|
else if (info->flag & FWTI_BLOCK_ASY)
|
2003-10-02 04:06:56 +00:00
|
|
|
len = fp->mode.rresb.len;
|
|
|
|
else
|
|
|
|
len = 0;
|
|
|
|
if (len != xfer->send.pay_len){
|
|
|
|
printf("len(%d) != send.pay_len(%d) (tcode=%d)\n",
|
|
|
|
len, xfer->send.pay_len, tcode);
|
2002-09-13 12:31:56 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
if(xferq->start == NULL){
|
|
|
|
printf("xferq->start == NULL\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
if(!(xferq->queued < xferq->maxq)){
|
2003-01-04 10:21:11 +00:00
|
|
|
device_printf(fc->bdev, "Discard a packet (queued=%d)\n",
|
|
|
|
xferq->queued);
|
2002-09-13 12:31:56 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
microtime(&xfer->tv);
|
2002-09-13 12:31:56 +00:00
|
|
|
if (info->flag & FWTI_TLABEL) {
|
|
|
|
if((tl = fw_get_tlabel(fc, xfer)) == -1 )
|
|
|
|
return EIO;
|
|
|
|
fp->mode.hdr.tlrt = tl << 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
xfer->tl = tl;
|
|
|
|
xfer->resp = 0;
|
|
|
|
xfer->fc = fc;
|
|
|
|
xfer->q = xferq;
|
|
|
|
xfer->retry_req = fw_asybusy;
|
|
|
|
|
|
|
|
fw_asystart(xfer);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Wakeup blocked process.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fw_asy_callback(struct fw_xfer *xfer){
|
|
|
|
wakeup(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Postpone to later retry.
|
|
|
|
*/
|
|
|
|
void fw_asybusy(struct fw_xfer *xfer){
|
|
|
|
printf("fw_asybusy\n");
|
|
|
|
/*
|
|
|
|
xfer->ch = timeout((timeout_t *)fw_asystart, (void *)xfer, 20000);
|
|
|
|
*/
|
2004-01-05 14:21:18 +00:00
|
|
|
#if 0
|
2002-09-13 12:31:56 +00:00
|
|
|
DELAY(20000);
|
2004-01-05 14:21:18 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
fw_asystart(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Async. request with given xfer structure.
|
|
|
|
*/
|
2002-11-12 05:52:01 +00:00
|
|
|
static void
|
|
|
|
fw_asystart(struct fw_xfer *xfer)
|
|
|
|
{
|
2002-09-13 12:31:56 +00:00
|
|
|
struct firewire_comm *fc = xfer->fc;
|
|
|
|
int s;
|
|
|
|
if(xfer->retry++ >= fc->max_asyretry){
|
2003-04-17 03:38:03 +00:00
|
|
|
device_printf(fc->bdev, "max_asyretry exceeded\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer->resp = EBUSY;
|
|
|
|
xfer->state = FWXF_BUSY;
|
|
|
|
xfer->act.hand(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if 0 /* XXX allow bus explore packets only after bus rest */
|
|
|
|
if (fc->status < FWBUSEXPLORE) {
|
|
|
|
xfer->resp = EAGAIN;
|
|
|
|
xfer->state = FWXF_BUSY;
|
|
|
|
if (xfer->act.hand != NULL)
|
|
|
|
xfer->act.hand(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
s = splfw();
|
|
|
|
xfer->state = FWXF_INQ;
|
|
|
|
STAILQ_INSERT_TAIL(&xfer->q->q, xfer, link);
|
|
|
|
xfer->q->queued ++;
|
|
|
|
splx(s);
|
|
|
|
/* XXX just queue for mbuf */
|
|
|
|
if (xfer->mbuf == NULL)
|
|
|
|
xfer->q->start(fc);
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
static int
|
|
|
|
firewire_match( device_t dev )
|
|
|
|
{
|
2002-12-26 06:50:09 +00:00
|
|
|
device_set_desc(dev, "IEEE1394(FireWire) bus");
|
2002-09-13 12:31:56 +00:00
|
|
|
return -140;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-02-09 07:16:01 +00:00
|
|
|
static void
|
|
|
|
firewire_xfer_timeout(struct firewire_comm *fc)
|
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct tlabel *tl;
|
|
|
|
struct timeval tv;
|
|
|
|
struct timeval split_timeout;
|
2003-02-17 14:24:06 +00:00
|
|
|
int i, s;
|
2003-02-09 07:16:01 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
split_timeout.tv_sec = 0;
|
|
|
|
split_timeout.tv_usec = 200 * 1000; /* 200 msec */
|
2003-02-09 07:16:01 +00:00
|
|
|
|
|
|
|
microtime(&tv);
|
|
|
|
timevalsub(&tv, &split_timeout);
|
|
|
|
|
2003-02-17 14:24:06 +00:00
|
|
|
s = splfw();
|
2003-02-09 07:16:01 +00:00
|
|
|
for (i = 0; i < 0x40; i ++) {
|
|
|
|
while ((tl = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
|
|
|
|
xfer = tl->xfer;
|
|
|
|
if (timevalcmp(&xfer->tv, &tv, >))
|
|
|
|
/* the rests are newer than this */
|
|
|
|
break;
|
2004-01-05 14:21:18 +00:00
|
|
|
if (xfer->state == FWXF_START)
|
|
|
|
/* not sent yet */
|
|
|
|
break;
|
2003-02-09 07:16:01 +00:00
|
|
|
device_printf(fc->bdev,
|
2003-07-18 05:28:30 +00:00
|
|
|
"split transaction timeout dst=0x%x tl=0x%x state=%d\n",
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.hdr.mode.hdr.dst, i, xfer->state);
|
2003-02-09 07:16:01 +00:00
|
|
|
xfer->resp = ETIMEDOUT;
|
|
|
|
STAILQ_REMOVE_HEAD(&fc->tlabels[i], link);
|
2003-04-17 03:38:03 +00:00
|
|
|
fw_xfer_done(xfer);
|
2003-02-09 07:16:01 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-17 14:24:06 +00:00
|
|
|
splx(s);
|
2003-02-09 07:16:01 +00:00
|
|
|
}
|
|
|
|
|
2003-10-24 07:42:21 +00:00
|
|
|
#define WATCHDOC_HZ 10
|
2003-02-09 07:16:01 +00:00
|
|
|
static void
|
|
|
|
firewire_watchdog(void *arg)
|
|
|
|
{
|
|
|
|
struct firewire_comm *fc;
|
2003-10-24 07:42:21 +00:00
|
|
|
static int watchdoc_clock = 0;
|
2003-02-09 07:16:01 +00:00
|
|
|
|
|
|
|
fc = (struct firewire_comm *)arg;
|
2003-10-24 07:42:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* At boot stage, the device interrupt is disabled and
|
|
|
|
* We encounter a timeout easily. To avoid this,
|
|
|
|
* ignore clock interrupt for a while.
|
|
|
|
*/
|
|
|
|
if (watchdoc_clock > WATCHDOC_HZ * 15) {
|
|
|
|
firewire_xfer_timeout(fc);
|
|
|
|
fc->timeout(fc);
|
|
|
|
} else
|
|
|
|
watchdoc_clock ++;
|
|
|
|
|
|
|
|
callout_reset(&fc->timeout_callout, hz / WATCHDOC_HZ,
|
2003-02-09 07:16:01 +00:00
|
|
|
(void *)firewire_watchdog, (void *)fc);
|
|
|
|
}
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* The attach routine.
|
|
|
|
*/
|
|
|
|
static int
|
2003-08-05 03:11:39 +00:00
|
|
|
firewire_attach(device_t dev)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-08-05 03:11:39 +00:00
|
|
|
int unit;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct firewire_softc *sc = device_get_softc(dev);
|
|
|
|
device_t pa = device_get_parent(dev);
|
|
|
|
struct firewire_comm *fc;
|
|
|
|
|
|
|
|
fc = (struct firewire_comm *)device_get_softc(pa);
|
|
|
|
sc->fc = fc;
|
2003-06-28 11:11:36 +00:00
|
|
|
fc->status = FWBUSNOTREADY;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-08-05 03:11:39 +00:00
|
|
|
unit = device_get_unit(dev);
|
2002-09-13 12:31:56 +00:00
|
|
|
if( fc->nisodma > FWMAXNDMA) fc->nisodma = FWMAXNDMA;
|
2003-08-05 03:11:39 +00:00
|
|
|
|
|
|
|
fwdev_makedev(sc);
|
|
|
|
|
2003-02-01 14:42:49 +00:00
|
|
|
CALLOUT_INIT(&sc->fc->timeout_callout);
|
|
|
|
CALLOUT_INIT(&sc->fc->bmr_callout);
|
|
|
|
CALLOUT_INIT(&sc->fc->retry_probe_callout);
|
|
|
|
CALLOUT_INIT(&sc->fc->busprobe_callout);
|
|
|
|
|
2003-02-09 07:16:01 +00:00
|
|
|
callout_reset(&sc->fc->timeout_callout, hz,
|
|
|
|
(void *)firewire_watchdog, (void *)sc->fc);
|
2003-01-07 04:26:45 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/* Locate our children */
|
|
|
|
bus_generic_probe(dev);
|
|
|
|
|
|
|
|
/* launch attachement of the added children */
|
|
|
|
bus_generic_attach(dev);
|
|
|
|
|
|
|
|
/* bus_reset */
|
|
|
|
fc->ibr(fc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach it as child.
|
|
|
|
*/
|
|
|
|
static device_t
|
|
|
|
firewire_add_child(device_t dev, int order, const char *name, int unit)
|
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
struct firewire_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct firewire_softc *)device_get_softc(dev);
|
|
|
|
child = device_add_child(dev, name, unit);
|
|
|
|
if (child) {
|
|
|
|
device_set_ivars(child, sc->fc);
|
|
|
|
device_probe_and_attach(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-06-28 11:11:36 +00:00
|
|
|
static int
|
|
|
|
firewire_resume(device_t dev)
|
|
|
|
{
|
|
|
|
struct firewire_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct firewire_softc *)device_get_softc(dev);
|
|
|
|
sc->fc->status = FWBUSNOTREADY;
|
|
|
|
|
|
|
|
bus_generic_resume(dev);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* Dettach it.
|
|
|
|
*/
|
|
|
|
static int
|
2003-08-05 03:11:39 +00:00
|
|
|
firewire_detach(device_t dev)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct firewire_softc *sc;
|
2003-02-18 09:39:48 +00:00
|
|
|
struct csrdir *csrd, *next;
|
2003-02-18 10:56:00 +00:00
|
|
|
struct fw_device *fwdev, *fwdev_next;
|
2003-08-05 03:11:39 +00:00
|
|
|
int err;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
sc = (struct firewire_softc *)device_get_softc(dev);
|
2003-08-05 03:11:39 +00:00
|
|
|
if ((err = fwdev_destroydev(sc)) != 0)
|
|
|
|
return err;
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-08-05 03:11:39 +00:00
|
|
|
if ((err = bus_generic_detach(dev)) != 0)
|
|
|
|
return err;
|
2003-02-18 10:56:00 +00:00
|
|
|
|
|
|
|
callout_stop(&sc->fc->timeout_callout);
|
|
|
|
callout_stop(&sc->fc->bmr_callout);
|
|
|
|
callout_stop(&sc->fc->retry_probe_callout);
|
|
|
|
callout_stop(&sc->fc->busprobe_callout);
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/* XXX xfree_free and untimeout on all xfers */
|
2003-02-18 10:56:00 +00:00
|
|
|
for (fwdev = STAILQ_FIRST(&sc->fc->devices); fwdev != NULL;
|
|
|
|
fwdev = fwdev_next) {
|
|
|
|
fwdev_next = STAILQ_NEXT(fwdev, link);
|
|
|
|
free(fwdev, M_FW);
|
|
|
|
}
|
2003-02-18 09:39:48 +00:00
|
|
|
for (csrd = SLIST_FIRST(&sc->fc->csrfree); csrd != NULL; csrd = next) {
|
|
|
|
next = SLIST_NEXT(csrd, link);
|
|
|
|
free(csrd, M_FW);
|
|
|
|
}
|
2003-02-01 15:04:33 +00:00
|
|
|
free(sc->fc->topology_map, M_FW);
|
|
|
|
free(sc->fc->speed_map, M_FW);
|
2003-06-15 04:09:26 +00:00
|
|
|
free(sc->fc->crom_src_buf, M_FW);
|
2002-09-13 12:31:56 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
static int
|
|
|
|
firewire_shutdown( device_t dev )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-02-09 07:16:01 +00:00
|
|
|
|
|
|
|
static void
|
2003-02-13 13:35:57 +00:00
|
|
|
fw_xferq_drain(struct fw_xferq *xferq)
|
2003-02-09 07:16:01 +00:00
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
|
|
|
|
while ((xfer = STAILQ_FIRST(&xferq->q)) != NULL) {
|
|
|
|
STAILQ_REMOVE_HEAD(&xferq->q, link);
|
2003-03-06 05:06:44 +00:00
|
|
|
xferq->queued --;
|
2003-02-09 07:16:01 +00:00
|
|
|
xfer->resp = EAGAIN;
|
2003-04-17 03:38:03 +00:00
|
|
|
fw_xfer_done(xfer);
|
2003-02-09 07:16:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-13 13:35:57 +00:00
|
|
|
void
|
|
|
|
fw_drain_txq(struct firewire_comm *fc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fw_xferq_drain(fc->atq);
|
|
|
|
fw_xferq_drain(fc->ats);
|
|
|
|
for(i = 0; i < fc->nisodma; i++)
|
|
|
|
fw_xferq_drain(fc->it[i]);
|
|
|
|
}
|
|
|
|
|
2003-06-15 04:09:26 +00:00
|
|
|
static void
|
|
|
|
fw_reset_csr(struct firewire_comm *fc)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
CSRARC(fc, STATE_CLEAR)
|
|
|
|
= 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14 ;
|
|
|
|
CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
|
|
|
|
CSRARC(fc, NODE_IDS) = 0x3f;
|
|
|
|
|
|
|
|
CSRARC(fc, TOPO_MAP + 8) = 0;
|
|
|
|
fc->irm = -1;
|
|
|
|
|
|
|
|
fc->max_node = -1;
|
|
|
|
|
|
|
|
for(i = 2; i < 0x100/4 - 2 ; i++){
|
|
|
|
CSRARC(fc, SPED_MAP + i * 4) = 0;
|
|
|
|
}
|
|
|
|
CSRARC(fc, STATE_CLEAR) = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14 ;
|
|
|
|
CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
|
|
|
|
CSRARC(fc, RESET_START) = 0;
|
|
|
|
CSRARC(fc, SPLIT_TIMEOUT_HI) = 0;
|
|
|
|
CSRARC(fc, SPLIT_TIMEOUT_LO) = 800 << 19;
|
|
|
|
CSRARC(fc, CYCLE_TIME) = 0x0;
|
|
|
|
CSRARC(fc, BUS_TIME) = 0x0;
|
|
|
|
CSRARC(fc, BUS_MGR_ID) = 0x3f;
|
|
|
|
CSRARC(fc, BANDWIDTH_AV) = 4915;
|
|
|
|
CSRARC(fc, CHANNELS_AV_HI) = 0xffffffff;
|
|
|
|
CSRARC(fc, CHANNELS_AV_LO) = 0xffffffff;
|
|
|
|
CSRARC(fc, IP_CHANNELS) = (1 << 31);
|
|
|
|
|
|
|
|
CSRARC(fc, CONF_ROM) = 0x04 << 24;
|
|
|
|
CSRARC(fc, CONF_ROM + 4) = 0x31333934; /* means strings 1394 */
|
|
|
|
CSRARC(fc, CONF_ROM + 8) = 1 << 31 | 1 << 30 | 1 << 29 |
|
|
|
|
1 << 28 | 0xff << 16 | 0x09 << 8;
|
|
|
|
CSRARC(fc, CONF_ROM + 0xc) = 0;
|
|
|
|
|
|
|
|
/* DV depend CSRs see blue book */
|
|
|
|
CSRARC(fc, oPCR) &= ~DV_BROADCAST_ON;
|
|
|
|
CSRARC(fc, iPCR) &= ~DV_BROADCAST_ON;
|
|
|
|
|
|
|
|
CSRARC(fc, STATE_CLEAR) &= ~(1 << 23 | 1 << 15 | 1 << 14 );
|
|
|
|
CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
|
2003-06-15 04:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fw_init_crom(struct firewire_comm *fc)
|
|
|
|
{
|
|
|
|
struct crom_src *src;
|
|
|
|
|
|
|
|
fc->crom_src_buf = (struct crom_src_buf *)
|
|
|
|
malloc(sizeof(struct crom_src_buf), M_FW, M_WAITOK | M_ZERO);
|
|
|
|
if (fc->crom_src_buf == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
src = &fc->crom_src_buf->src;
|
|
|
|
bzero(src, sizeof(struct crom_src));
|
|
|
|
|
|
|
|
/* BUS info sample */
|
|
|
|
src->hdr.info_len = 4;
|
|
|
|
|
|
|
|
src->businfo.bus_name = CSR_BUS_NAME_IEEE1394;
|
|
|
|
|
|
|
|
src->businfo.irmc = 1;
|
|
|
|
src->businfo.cmc = 1;
|
|
|
|
src->businfo.isc = 1;
|
|
|
|
src->businfo.bmc = 1;
|
|
|
|
src->businfo.pmc = 0;
|
|
|
|
src->businfo.cyc_clk_acc = 100;
|
|
|
|
src->businfo.max_rec = fc->maxrec;
|
|
|
|
src->businfo.max_rom = MAXROM_4;
|
2003-07-09 13:07:35 +00:00
|
|
|
src->businfo.generation = 1;
|
2003-06-15 04:09:26 +00:00
|
|
|
src->businfo.link_spd = fc->speed;
|
|
|
|
|
|
|
|
src->businfo.eui64.hi = fc->eui.hi;
|
|
|
|
src->businfo.eui64.lo = fc->eui.lo;
|
|
|
|
|
|
|
|
STAILQ_INIT(&src->chunk_list);
|
|
|
|
|
|
|
|
fc->crom_src = src;
|
|
|
|
fc->crom_root = &fc->crom_src_buf->root;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fw_reset_crom(struct firewire_comm *fc)
|
|
|
|
{
|
|
|
|
struct crom_src_buf *buf;
|
|
|
|
struct crom_src *src;
|
|
|
|
struct crom_chunk *root;
|
|
|
|
|
|
|
|
if (fc->crom_src_buf == NULL)
|
|
|
|
fw_init_crom(fc);
|
|
|
|
|
|
|
|
buf = fc->crom_src_buf;
|
|
|
|
src = fc->crom_src;
|
|
|
|
root = fc->crom_root;
|
|
|
|
|
|
|
|
STAILQ_INIT(&src->chunk_list);
|
|
|
|
|
|
|
|
bzero(root, sizeof(struct crom_chunk));
|
|
|
|
crom_add_chunk(src, NULL, root, 0);
|
|
|
|
crom_add_entry(root, CSRKEY_NCAP, 0x0083c0); /* XXX */
|
|
|
|
/* private company_id */
|
|
|
|
crom_add_entry(root, CSRKEY_VENDOR, CSRVAL_VENDOR_PRIVATE);
|
|
|
|
crom_add_simple_text(src, root, &buf->vendor, "FreeBSD Project");
|
|
|
|
crom_add_entry(root, CSRKEY_HW, __FreeBSD_version);
|
|
|
|
crom_add_simple_text(src, root, &buf->hw, hostname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called after bus reset.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fw_busreset(struct firewire_comm *fc)
|
|
|
|
{
|
|
|
|
struct firewire_dev_comm *fdc;
|
2003-07-09 13:07:35 +00:00
|
|
|
struct crom_src *src;
|
2003-06-15 04:09:26 +00:00
|
|
|
device_t *devlistp;
|
2003-07-09 13:07:35 +00:00
|
|
|
void *newrom;
|
2003-06-15 04:09:26 +00:00
|
|
|
int i, devcnt;
|
|
|
|
|
|
|
|
switch(fc->status){
|
|
|
|
case FWBUSMGRELECT:
|
|
|
|
callout_stop(&fc->bmr_callout);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fc->status = FWBUSRESET;
|
|
|
|
fw_reset_csr(fc);
|
|
|
|
fw_reset_crom(fc);
|
2003-04-17 03:38:03 +00:00
|
|
|
|
|
|
|
if (device_get_children(fc->bdev, &devlistp, &devcnt) == 0) {
|
|
|
|
for( i = 0 ; i < devcnt ; i++)
|
|
|
|
if (device_get_state(devlistp[i]) >= DS_ATTACHED) {
|
|
|
|
fdc = device_get_softc(devlistp[i]);
|
|
|
|
if (fdc->post_busreset != NULL)
|
|
|
|
fdc->post_busreset(fdc);
|
|
|
|
}
|
|
|
|
free(devlistp, M_TEMP);
|
|
|
|
}
|
2003-06-15 04:09:26 +00:00
|
|
|
|
2003-07-09 13:07:35 +00:00
|
|
|
newrom = malloc(CROMSIZE, M_FW, M_NOWAIT | M_ZERO);
|
|
|
|
src = &fc->crom_src_buf->src;
|
|
|
|
crom_load(src, (u_int32_t *)newrom, CROMSIZE);
|
|
|
|
if (bcmp(newrom, fc->config_rom, CROMSIZE) != 0) {
|
|
|
|
/* bump generation and reload */
|
|
|
|
src->businfo.generation ++;
|
|
|
|
/* generation must be between 0x2 and 0xF */
|
|
|
|
if (src->businfo.generation < 2)
|
|
|
|
src->businfo.generation ++;
|
|
|
|
crom_load(src, (u_int32_t *)newrom, CROMSIZE);
|
|
|
|
bcopy(newrom, (void *)fc->config_rom, CROMSIZE);
|
|
|
|
}
|
|
|
|
free(newrom, M_FW);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/* Call once after reboot */
|
2002-11-12 05:52:01 +00:00
|
|
|
void fw_init(struct firewire_comm *fc)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int i;
|
2002-11-07 02:13:40 +00:00
|
|
|
struct csrdir *csrd;
|
|
|
|
#ifdef FW_VMACCESS
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_bind *fwb;
|
2002-11-07 02:13:40 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
fc->max_asyretry = FW_MAXASYRTY;
|
|
|
|
|
|
|
|
fc->arq->queued = 0;
|
|
|
|
fc->ars->queued = 0;
|
|
|
|
fc->atq->queued = 0;
|
|
|
|
fc->ats->queued = 0;
|
|
|
|
|
|
|
|
fc->arq->buf = NULL;
|
|
|
|
fc->ars->buf = NULL;
|
|
|
|
fc->atq->buf = NULL;
|
|
|
|
fc->ats->buf = NULL;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
fc->arq->flag = 0;
|
|
|
|
fc->ars->flag = 0;
|
|
|
|
fc->atq->flag = 0;
|
|
|
|
fc->ats->flag = 0;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
STAILQ_INIT(&fc->atq->q);
|
|
|
|
STAILQ_INIT(&fc->ats->q);
|
|
|
|
|
|
|
|
for( i = 0 ; i < fc->nisodma ; i ++ ){
|
|
|
|
fc->it[i]->queued = 0;
|
|
|
|
fc->ir[i]->queued = 0;
|
|
|
|
|
|
|
|
fc->it[i]->start = NULL;
|
|
|
|
fc->ir[i]->start = NULL;
|
|
|
|
|
|
|
|
fc->it[i]->buf = NULL;
|
|
|
|
fc->ir[i]->buf = NULL;
|
|
|
|
|
|
|
|
fc->it[i]->flag = FWXFERQ_STREAM;
|
|
|
|
fc->ir[i]->flag = FWXFERQ_STREAM;
|
|
|
|
|
|
|
|
STAILQ_INIT(&fc->it[i]->q);
|
|
|
|
STAILQ_INIT(&fc->ir[i]->q);
|
|
|
|
|
|
|
|
STAILQ_INIT(&fc->it[i]->binds);
|
|
|
|
STAILQ_INIT(&fc->ir[i]->binds);
|
|
|
|
}
|
|
|
|
|
|
|
|
fc->arq->maxq = FWMAXQUEUE;
|
|
|
|
fc->ars->maxq = FWMAXQUEUE;
|
|
|
|
fc->atq->maxq = FWMAXQUEUE;
|
|
|
|
fc->ats->maxq = FWMAXQUEUE;
|
|
|
|
|
|
|
|
for( i = 0 ; i < fc->nisodma ; i++){
|
|
|
|
fc->ir[i]->maxq = FWMAXQUEUE;
|
|
|
|
fc->it[i]->maxq = FWMAXQUEUE;
|
|
|
|
}
|
|
|
|
/* Initialize csr registers */
|
|
|
|
fc->topology_map = (struct fw_topology_map *)malloc(
|
|
|
|
sizeof(struct fw_topology_map),
|
2003-02-01 15:04:33 +00:00
|
|
|
M_FW, M_NOWAIT | M_ZERO);
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->speed_map = (struct fw_speed_map *)malloc(
|
|
|
|
sizeof(struct fw_speed_map),
|
2003-02-01 15:04:33 +00:00
|
|
|
M_FW, M_NOWAIT | M_ZERO);
|
2002-09-13 12:31:56 +00:00
|
|
|
CSRARC(fc, TOPO_MAP) = 0x3f1 << 16;
|
|
|
|
CSRARC(fc, TOPO_MAP + 4) = 1;
|
|
|
|
CSRARC(fc, SPED_MAP) = 0x3f1 << 16;
|
|
|
|
CSRARC(fc, SPED_MAP + 4) = 1;
|
|
|
|
|
2003-02-01 14:42:49 +00:00
|
|
|
STAILQ_INIT(&fc->devices);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
/* Initialize csr ROM work space */
|
|
|
|
SLIST_INIT(&fc->ongocsr);
|
|
|
|
SLIST_INIT(&fc->csrfree);
|
|
|
|
for( i = 0 ; i < FWMAXCSRDIR ; i++){
|
2003-02-01 15:04:33 +00:00
|
|
|
csrd = (struct csrdir *) malloc(sizeof(struct csrdir), M_FW,M_NOWAIT);
|
2002-09-13 12:31:56 +00:00
|
|
|
if(csrd == NULL) break;
|
|
|
|
SLIST_INSERT_HEAD(&fc->csrfree, csrd, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize Async handlers */
|
|
|
|
STAILQ_INIT(&fc->binds);
|
|
|
|
for( i = 0 ; i < 0x40 ; i++){
|
|
|
|
STAILQ_INIT(&fc->tlabels[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DV depend CSRs see blue book */
|
|
|
|
#if 0
|
|
|
|
CSRARC(fc, oMPR) = 0x3fff0001; /* # output channel = 1 */
|
|
|
|
CSRARC(fc, oPCR) = 0x8000007a;
|
|
|
|
for(i = 4 ; i < 0x7c/4 ; i+=4){
|
|
|
|
CSRARC(fc, i + oPCR) = 0x8000007a;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSRARC(fc, iMPR) = 0x00ff0001; /* # input channel = 1 */
|
|
|
|
CSRARC(fc, iPCR) = 0x803f0000;
|
|
|
|
for(i = 4 ; i < 0x7c/4 ; i+=4){
|
|
|
|
CSRARC(fc, i + iPCR) = 0x0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-06-15 04:09:26 +00:00
|
|
|
fc->crom_src_buf = NULL;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2002-11-07 02:13:40 +00:00
|
|
|
#ifdef FW_VMACCESS
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer = fw_xfer_alloc();
|
|
|
|
if(xfer == NULL) return;
|
|
|
|
|
2003-02-01 15:04:33 +00:00
|
|
|
fwb = (struct fw_bind *)malloc(sizeof (struct fw_bind), M_FW, M_NOWAIT);
|
2002-09-13 12:31:56 +00:00
|
|
|
if(fwb == NULL){
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
}
|
|
|
|
xfer->act.hand = fw_vmaccess;
|
|
|
|
xfer->fc = fc;
|
|
|
|
xfer->sc = NULL;
|
|
|
|
|
|
|
|
fwb->start_hi = 0x2;
|
|
|
|
fwb->start_lo = 0;
|
|
|
|
fwb->addrlen = 0xffffffff;
|
|
|
|
fwb->xfer = xfer;
|
|
|
|
fw_bindadd(fc, fwb);
|
2002-11-07 02:13:40 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
#define BIND_CMP(addr, fwb) (((addr) < (fwb)->start)?-1:\
|
|
|
|
((fwb)->end < (addr))?1:0)
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* To lookup binded process from IEEE1394 address.
|
|
|
|
*/
|
2002-11-12 15:22:19 +00:00
|
|
|
struct fw_bind *
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_bindlookup(struct firewire_comm *fc, u_int16_t dest_hi, u_int32_t dest_lo)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-10-02 04:06:56 +00:00
|
|
|
u_int64_t addr;
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fw_bind *tfw;
|
2003-10-02 04:06:56 +00:00
|
|
|
|
|
|
|
addr = ((u_int64_t)dest_hi << 32) | dest_lo;
|
|
|
|
STAILQ_FOREACH(tfw, &fc->binds, fclist)
|
|
|
|
if (tfw->act_type != FWACT_NULL && BIND_CMP(addr, tfw) == 0)
|
2002-09-13 12:31:56 +00:00
|
|
|
return(tfw);
|
|
|
|
return(NULL);
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* To bind IEEE1394 address block to process.
|
|
|
|
*/
|
2002-11-12 05:52:01 +00:00
|
|
|
int
|
|
|
|
fw_bindadd(struct firewire_comm *fc, struct fw_bind *fwb)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fw_bind *tfw, *prev = NULL;
|
|
|
|
|
|
|
|
if (fwb->start > fwb->end) {
|
|
|
|
printf("%s: invalid range\n", __FUNCTION__);
|
|
|
|
return EINVAL;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
|
|
|
|
STAILQ_FOREACH(tfw, &fc->binds, fclist) {
|
|
|
|
if (fwb->end < tfw->start)
|
|
|
|
break;
|
|
|
|
prev = tfw;
|
|
|
|
}
|
|
|
|
if (prev == NULL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
STAILQ_INSERT_HEAD(&fc->binds, fwb, fclist);
|
|
|
|
goto out;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
if (prev->end < fwb->start) {
|
|
|
|
STAILQ_INSERT_AFTER(&fc->binds, prev, fwb, fclist);
|
|
|
|
goto out;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
|
|
|
|
printf("%s: bind failed\n", __FUNCTION__);
|
|
|
|
return (EBUSY);
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
out:
|
2003-10-02 04:06:56 +00:00
|
|
|
if (fwb->act_type == FWACT_CH)
|
2003-04-17 03:38:03 +00:00
|
|
|
STAILQ_INSERT_HEAD(&fc->ir[fwb->sub]->binds, fwb, chlist);
|
2003-10-02 04:06:56 +00:00
|
|
|
return (0);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To free IEEE1394 address block.
|
|
|
|
*/
|
2002-11-12 05:52:01 +00:00
|
|
|
int
|
|
|
|
fw_bindremove(struct firewire_comm *fc, struct fw_bind *fwb)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-10-02 04:06:56 +00:00
|
|
|
#if 0
|
2003-04-17 03:38:03 +00:00
|
|
|
struct fw_xfer *xfer, *next;
|
2003-10-02 04:06:56 +00:00
|
|
|
#endif
|
|
|
|
struct fw_bind *tfw;
|
|
|
|
int s;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
s = splfw();
|
2003-10-02 04:06:56 +00:00
|
|
|
STAILQ_FOREACH(tfw, &fc->binds, fclist)
|
|
|
|
if (tfw == fwb) {
|
|
|
|
STAILQ_REMOVE(&fc->binds, fwb, fw_bind, fclist);
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s: no such bind\n", __FUNCTION__);
|
|
|
|
splx(s);
|
|
|
|
return (1);
|
|
|
|
found:
|
|
|
|
#if 0
|
2003-04-17 03:38:03 +00:00
|
|
|
/* shall we do this? */
|
|
|
|
for (xfer = STAILQ_FIRST(&fwb->xferlist); xfer != NULL; xfer = next) {
|
|
|
|
next = STAILQ_NEXT(xfer, link);
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
}
|
|
|
|
STAILQ_INIT(&fwb->xferlist);
|
2003-10-02 04:06:56 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
splx(s);
|
2002-09-13 12:31:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To free transaction label.
|
|
|
|
*/
|
2002-11-12 05:52:01 +00:00
|
|
|
static void
|
|
|
|
fw_tl_free(struct firewire_comm *fc, struct fw_xfer *xfer)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct tlabel *tl;
|
|
|
|
int s = splfw();
|
|
|
|
|
|
|
|
for( tl = STAILQ_FIRST(&fc->tlabels[xfer->tl]); tl != NULL;
|
|
|
|
tl = STAILQ_NEXT(tl, link)){
|
|
|
|
if(tl->xfer == xfer){
|
|
|
|
STAILQ_REMOVE(&fc->tlabels[xfer->tl], tl, tlabel, link);
|
2003-02-01 15:04:33 +00:00
|
|
|
free(tl, M_FW);
|
2002-09-13 12:31:56 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* To obtain XFER structure by transaction label.
|
|
|
|
*/
|
2002-11-12 05:52:01 +00:00
|
|
|
static struct fw_xfer *
|
|
|
|
fw_tl2xfer(struct firewire_comm *fc, int node, int tlabel)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct tlabel *tl;
|
|
|
|
int s = splfw();
|
|
|
|
|
|
|
|
for( tl = STAILQ_FIRST(&fc->tlabels[tlabel]); tl != NULL;
|
|
|
|
tl = STAILQ_NEXT(tl, link)){
|
2003-10-02 04:06:56 +00:00
|
|
|
if(tl->xfer->send.hdr.mode.hdr.dst == node){
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer = tl->xfer;
|
|
|
|
splx(s);
|
2003-02-09 07:16:01 +00:00
|
|
|
if (firewire_debug > 2)
|
|
|
|
printf("fw_tl2xfer: found tl=%d\n", tlabel);
|
2002-09-13 12:31:56 +00:00
|
|
|
return(xfer);
|
|
|
|
}
|
|
|
|
}
|
2003-02-09 07:16:01 +00:00
|
|
|
if (firewire_debug > 1)
|
|
|
|
printf("fw_tl2xfer: not found tl=%d\n", tlabel);
|
2002-09-13 12:31:56 +00:00
|
|
|
splx(s);
|
|
|
|
return(NULL);
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* To allocate IEEE1394 XFER structure.
|
|
|
|
*/
|
2002-11-12 05:52:01 +00:00
|
|
|
struct fw_xfer *
|
2003-02-03 07:33:31 +00:00
|
|
|
fw_xfer_alloc(struct malloc_type *type)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-02-03 07:33:31 +00:00
|
|
|
xfer = malloc(sizeof(struct fw_xfer), type, M_NOWAIT | M_ZERO);
|
2002-11-12 05:52:01 +00:00
|
|
|
if (xfer == NULL)
|
|
|
|
return xfer;
|
|
|
|
|
2003-02-03 07:33:31 +00:00
|
|
|
xfer->malloc = type;
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
return xfer;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
struct fw_xfer *
|
|
|
|
fw_xfer_alloc_buf(struct malloc_type *type, int send_len, int recv_len)
|
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
|
|
|
|
xfer = fw_xfer_alloc(type);
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.pay_len = send_len;
|
|
|
|
xfer->recv.pay_len = recv_len;
|
2003-04-17 03:38:03 +00:00
|
|
|
if (xfer == NULL)
|
|
|
|
return(NULL);
|
2003-10-02 04:06:56 +00:00
|
|
|
if (send_len > 0) {
|
|
|
|
xfer->send.payload = malloc(send_len, type, M_NOWAIT | M_ZERO);
|
|
|
|
if (xfer->send.payload == NULL) {
|
2003-04-17 03:38:03 +00:00
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
if (recv_len > 0) {
|
|
|
|
xfer->recv.payload = malloc(recv_len, type, M_NOWAIT);
|
|
|
|
if (xfer->recv.payload == NULL) {
|
|
|
|
if (xfer->send.payload != NULL)
|
|
|
|
free(xfer->send.payload, type);
|
2003-04-17 03:38:03 +00:00
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(xfer);
|
|
|
|
}
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* IEEE1394 XFER post process.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fw_xfer_done(struct fw_xfer *xfer)
|
|
|
|
{
|
2003-07-18 05:28:30 +00:00
|
|
|
if (xfer->act.hand == NULL) {
|
|
|
|
printf("act.hand == NULL\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
2003-07-18 05:28:30 +00:00
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-10-25 15:04:49 +00:00
|
|
|
if (xfer->fc == NULL)
|
|
|
|
panic("fw_xfer_done: why xfer->fc is NULL?");
|
|
|
|
|
2004-01-05 14:21:18 +00:00
|
|
|
xfer->act.hand(xfer);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
2002-11-12 05:52:01 +00:00
|
|
|
void
|
2003-04-17 03:38:03 +00:00
|
|
|
fw_xfer_unload(struct fw_xfer* xfer)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int s;
|
2003-04-17 03:38:03 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
if(xfer == NULL ) return;
|
|
|
|
if(xfer->state == FWXF_INQ){
|
|
|
|
printf("fw_xfer_free FWXF_INQ\n");
|
|
|
|
s = splfw();
|
|
|
|
STAILQ_REMOVE(&xfer->q->q, xfer, fw_xfer, link);
|
|
|
|
xfer->q->queued --;
|
|
|
|
splx(s);
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
if (xfer->fc != NULL) {
|
2003-05-05 10:14:52 +00:00
|
|
|
#if 1
|
2003-04-17 03:38:03 +00:00
|
|
|
if(xfer->state == FWXF_START)
|
2003-05-05 10:14:52 +00:00
|
|
|
/*
|
|
|
|
* This could happen if:
|
|
|
|
* 1. We call fwohci_arcv() before fwohci_txd().
|
|
|
|
* 2. firewire_watch() is called.
|
|
|
|
*/
|
|
|
|
printf("fw_xfer_free FWXF_START\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
#endif
|
2003-04-17 03:38:03 +00:00
|
|
|
fw_tl_free(xfer->fc, xfer);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
xfer->state = FWXF_INIT;
|
|
|
|
xfer->resp = 0;
|
|
|
|
xfer->retry = 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* To free IEEE1394 XFER structure.
|
|
|
|
*/
|
|
|
|
void
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_xfer_free_buf( struct fw_xfer* xfer)
|
2003-04-17 03:38:03 +00:00
|
|
|
{
|
2003-10-02 04:06:56 +00:00
|
|
|
if (xfer == NULL) {
|
|
|
|
printf("%s: xfer == NULL\n", __FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
fw_xfer_unload(xfer);
|
2003-10-02 04:06:56 +00:00
|
|
|
if(xfer->send.payload != NULL){
|
|
|
|
free(xfer->send.payload, xfer->malloc);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
if(xfer->recv.payload != NULL){
|
|
|
|
free(xfer->recv.payload, xfer->malloc);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-02-03 07:33:31 +00:00
|
|
|
free(xfer, xfer->malloc);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
void
|
|
|
|
fw_xfer_free( struct fw_xfer* xfer)
|
|
|
|
{
|
|
|
|
if (xfer == NULL) {
|
|
|
|
printf("%s: xfer == NULL\n", __FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fw_xfer_unload(xfer);
|
|
|
|
free(xfer, xfer->malloc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-01-30 05:18:35 +00:00
|
|
|
fw_asy_callback_free(struct fw_xfer *xfer)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
#if 0
|
2003-01-30 05:18:35 +00:00
|
|
|
printf("asyreq done state=%d resp=%d\n",
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer->state, xfer->resp);
|
|
|
|
#endif
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To configure PHY.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fw_phy_config(struct firewire_comm *fc, int root_node, int gap_count)
|
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
|
|
|
|
fc->status = FWBUSPHYCONF;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer = fw_xfer_alloc(M_FWXFER);
|
2003-04-17 03:38:03 +00:00
|
|
|
if (xfer == NULL)
|
|
|
|
return;
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer->fc = fc;
|
|
|
|
xfer->retry_req = fw_asybusy;
|
2003-01-30 05:18:35 +00:00
|
|
|
xfer->act.hand = fw_asy_callback_free;
|
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.ld[1] = 0;
|
|
|
|
if (root_node >= 0)
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.ld[1] |= (root_node & 0x3f) << 24 | 1 << 23;
|
2002-09-13 12:31:56 +00:00
|
|
|
if (gap_count >= 0)
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.ld[1] |= 1 << 22 | (gap_count & 0x3f) << 16;
|
2002-09-13 12:31:56 +00:00
|
|
|
fp->mode.ld[2] = ~fp->mode.ld[1];
|
|
|
|
/* XXX Dangerous, how to pass PHY packet to device driver */
|
|
|
|
fp->mode.common.tcode |= FWTCODE_PHY;
|
|
|
|
|
2002-12-06 02:17:30 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
printf("send phy_config root_node=%d gap_count=%d\n",
|
2002-09-13 12:31:56 +00:00
|
|
|
root_node, gap_count);
|
|
|
|
fw_asyreq(fc, -1, xfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Dump self ID.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fw_print_sid(u_int32_t sid)
|
|
|
|
{
|
|
|
|
union fw_self_id *s;
|
|
|
|
s = (union fw_self_id *) &sid;
|
|
|
|
printf("node:%d link:%d gap:%d spd:%d del:%d con:%d pwr:%d"
|
|
|
|
" p0:%d p1:%d p2:%d i:%d m:%d\n",
|
|
|
|
s->p0.phy_id, s->p0.link_active, s->p0.gap_count,
|
|
|
|
s->p0.phy_speed, s->p0.phy_delay, s->p0.contender,
|
|
|
|
s->p0.power_class, s->p0.port0, s->p0.port1,
|
|
|
|
s->p0.port2, s->p0.initiated_reset, s->p0.more_packets);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To receive self ID.
|
|
|
|
*/
|
2003-04-17 03:38:03 +00:00
|
|
|
void fw_sidrcv(struct firewire_comm* fc, u_int32_t *sid, u_int len)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-04-17 03:38:03 +00:00
|
|
|
u_int32_t *p;
|
2002-09-13 12:31:56 +00:00
|
|
|
union fw_self_id *self_id;
|
|
|
|
u_int i, j, node, c_port = 0, i_branch = 0;
|
|
|
|
|
|
|
|
fc->sid_cnt = len /(sizeof(u_int32_t) * 2);
|
|
|
|
fc->status = FWBUSINIT;
|
|
|
|
fc->max_node = fc->nodeid & 0x3f;
|
|
|
|
CSRARC(fc, NODE_IDS) = ((u_int32_t)fc->nodeid) << 16;
|
|
|
|
fc->status = FWBUSCYMELECT;
|
|
|
|
fc->topology_map->crc_len = 2;
|
|
|
|
fc->topology_map->generation ++;
|
|
|
|
fc->topology_map->self_id_count = 0;
|
|
|
|
fc->topology_map->node_count = 0;
|
|
|
|
fc->speed_map->generation ++;
|
|
|
|
fc->speed_map->crc_len = 1 + (64*64 + 3) / 4;
|
|
|
|
self_id = &fc->topology_map->self_id[0];
|
|
|
|
for(i = 0; i < fc->sid_cnt; i ++){
|
|
|
|
if (sid[1] != ~sid[0]) {
|
|
|
|
printf("fw_sidrcv: invalid self-id packet\n");
|
|
|
|
sid += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*self_id = *((union fw_self_id *)sid);
|
|
|
|
fc->topology_map->crc_len++;
|
|
|
|
if(self_id->p0.sequel == 0){
|
|
|
|
fc->topology_map->node_count ++;
|
|
|
|
c_port = 0;
|
|
|
|
#if 0
|
|
|
|
fw_print_sid(sid[0]);
|
|
|
|
#endif
|
|
|
|
node = self_id->p0.phy_id;
|
|
|
|
if(fc->max_node < node){
|
|
|
|
fc->max_node = self_id->p0.phy_id;
|
|
|
|
}
|
|
|
|
/* XXX I'm not sure this is the right speed_map */
|
|
|
|
fc->speed_map->speed[node][node]
|
|
|
|
= self_id->p0.phy_speed;
|
|
|
|
for (j = 0; j < node; j ++) {
|
|
|
|
fc->speed_map->speed[j][node]
|
|
|
|
= fc->speed_map->speed[node][j]
|
|
|
|
= min(fc->speed_map->speed[j][j],
|
|
|
|
self_id->p0.phy_speed);
|
|
|
|
}
|
|
|
|
if ((fc->irm == -1 || self_id->p0.phy_id > fc->irm) &&
|
|
|
|
(self_id->p0.link_active && self_id->p0.contender)) {
|
|
|
|
fc->irm = self_id->p0.phy_id;
|
|
|
|
}
|
|
|
|
if(self_id->p0.port0 >= 0x2){
|
|
|
|
c_port++;
|
|
|
|
}
|
|
|
|
if(self_id->p0.port1 >= 0x2){
|
|
|
|
c_port++;
|
|
|
|
}
|
|
|
|
if(self_id->p0.port2 >= 0x2){
|
|
|
|
c_port++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(c_port > 2){
|
|
|
|
i_branch += (c_port - 2);
|
|
|
|
}
|
|
|
|
sid += 2;
|
|
|
|
self_id++;
|
|
|
|
fc->topology_map->self_id_count ++;
|
|
|
|
}
|
2003-01-04 10:21:11 +00:00
|
|
|
device_printf(fc->bdev, "%d nodes", fc->max_node + 1);
|
2002-09-13 12:31:56 +00:00
|
|
|
/* CRC */
|
|
|
|
fc->topology_map->crc = fw_crc16(
|
|
|
|
(u_int32_t *)&fc->topology_map->generation,
|
|
|
|
fc->topology_map->crc_len * 4);
|
|
|
|
fc->speed_map->crc = fw_crc16(
|
|
|
|
(u_int32_t *)&fc->speed_map->generation,
|
|
|
|
fc->speed_map->crc_len * 4);
|
|
|
|
/* byteswap and copy to CSR */
|
|
|
|
p = (u_int32_t *)fc->topology_map;
|
|
|
|
for (i = 0; i <= fc->topology_map->crc_len; i++)
|
|
|
|
CSRARC(fc, TOPO_MAP + i * 4) = htonl(*p++);
|
|
|
|
p = (u_int32_t *)fc->speed_map;
|
|
|
|
CSRARC(fc, SPED_MAP) = htonl(*p++);
|
|
|
|
CSRARC(fc, SPED_MAP + 4) = htonl(*p++);
|
|
|
|
/* don't byte-swap u_int8_t array */
|
|
|
|
bcopy(p, &CSRARC(fc, SPED_MAP + 8), (fc->speed_map->crc_len - 1)*4);
|
|
|
|
|
|
|
|
fc->max_hop = fc->max_node - i_branch;
|
|
|
|
printf(", maxhop <= %d", fc->max_hop);
|
|
|
|
|
|
|
|
if(fc->irm == -1 ){
|
|
|
|
printf(", Not found IRM capable node");
|
|
|
|
}else{
|
|
|
|
printf(", cable IRM = %d", fc->irm);
|
|
|
|
if (fc->irm == fc->nodeid)
|
2003-01-29 02:13:31 +00:00
|
|
|
printf(" (me)");
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-01-29 02:13:31 +00:00
|
|
|
printf("\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-01-23 13:34:40 +00:00
|
|
|
if (try_bmr && (fc->irm != -1) && (CSRARC(fc, BUS_MGR_ID) == 0x3f)) {
|
2003-05-11 10:32:20 +00:00
|
|
|
if (fc->irm == fc->nodeid) {
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->status = FWBUSMGRDONE;
|
|
|
|
CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, fc->irm);
|
2003-05-11 10:32:20 +00:00
|
|
|
fw_bmr(fc);
|
2003-01-23 13:34:40 +00:00
|
|
|
} else {
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->status = FWBUSMGRELECT;
|
2003-02-01 14:42:49 +00:00
|
|
|
callout_reset(&fc->bmr_callout, hz/8,
|
|
|
|
(void *)fw_try_bmr, (void *)fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-05-11 10:32:20 +00:00
|
|
|
} else
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->status = FWBUSMGRDONE;
|
2003-05-11 10:32:20 +00:00
|
|
|
|
2003-01-07 04:26:45 +00:00
|
|
|
callout_reset(&fc->busprobe_callout, hz/4,
|
|
|
|
(void *)fw_bus_probe, (void *)fc);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* To probe devices on the IEEE1394 bus.
|
|
|
|
*/
|
2002-11-12 05:52:01 +00:00
|
|
|
static void
|
|
|
|
fw_bus_probe(struct firewire_comm *fc)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int s;
|
2003-10-06 07:17:43 +00:00
|
|
|
struct fw_device *fwdev;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
s = splfw();
|
|
|
|
fc->status = FWBUSEXPLORE;
|
|
|
|
fc->retry_count = 0;
|
|
|
|
|
2003-10-06 07:17:43 +00:00
|
|
|
/* Invalidate all devices, just after bus reset. */
|
|
|
|
STAILQ_FOREACH(fwdev, &fc->devices, link)
|
2003-02-01 14:42:49 +00:00
|
|
|
if (fwdev->status != FWDEVINVAL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
fwdev->status = FWDEVINVAL;
|
|
|
|
fwdev->rcnt = 0;
|
|
|
|
}
|
2003-10-06 07:17:43 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->ongonode = 0;
|
|
|
|
fc->ongoaddr = CSRROMOFF;
|
|
|
|
fc->ongodev = NULL;
|
|
|
|
fc->ongoeui.hi = 0xffffffff; fc->ongoeui.lo = 0xffffffff;
|
|
|
|
fw_bus_explore(fc);
|
|
|
|
splx(s);
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* To collect device informations on the IEEE1394 bus.
|
|
|
|
*/
|
2002-11-12 05:52:01 +00:00
|
|
|
static void
|
|
|
|
fw_bus_explore(struct firewire_comm *fc )
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
2003-02-01 06:34:36 +00:00
|
|
|
struct fw_device *fwdev, *pfwdev, *tfwdev;
|
2002-09-13 12:31:56 +00:00
|
|
|
u_int32_t addr;
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
|
|
|
|
if(fc->status != FWBUSEXPLORE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
loop:
|
|
|
|
if(fc->ongonode == fc->nodeid) fc->ongonode++;
|
|
|
|
|
|
|
|
if(fc->ongonode > fc->max_node) goto done;
|
|
|
|
if(fc->ongonode >= 0x3f) goto done;
|
|
|
|
|
|
|
|
/* check link */
|
|
|
|
/* XXX we need to check phy_id first */
|
|
|
|
if (!fc->topology_map->self_id[fc->ongonode].p0.link_active) {
|
2003-02-09 07:16:01 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
printf("node%d: link down\n", fc->ongonode);
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->ongonode++;
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fc->ongoaddr <= CSRROMOFF &&
|
|
|
|
fc->ongoeui.hi == 0xffffffff &&
|
|
|
|
fc->ongoeui.lo == 0xffffffff ){
|
|
|
|
fc->ongoaddr = CSRROMOFF;
|
|
|
|
addr = 0xf0000000 | fc->ongoaddr;
|
|
|
|
}else if(fc->ongoeui.hi == 0xffffffff ){
|
|
|
|
fc->ongoaddr = CSRROMOFF + 0xc;
|
|
|
|
addr = 0xf0000000 | fc->ongoaddr;
|
|
|
|
}else if(fc->ongoeui.lo == 0xffffffff ){
|
|
|
|
fc->ongoaddr = CSRROMOFF + 0x10;
|
|
|
|
addr = 0xf0000000 | fc->ongoaddr;
|
|
|
|
}else if(fc->ongodev == NULL){
|
2003-02-01 14:42:49 +00:00
|
|
|
STAILQ_FOREACH(fwdev, &fc->devices, link)
|
|
|
|
if (FW_EUI64_EQUAL(fwdev->eui, fc->ongoeui))
|
2002-09-13 12:31:56 +00:00
|
|
|
break;
|
|
|
|
if(fwdev != NULL){
|
|
|
|
fwdev->dst = fc->ongonode;
|
2003-07-09 13:07:35 +00:00
|
|
|
fwdev->status = FWDEVINIT;
|
|
|
|
fc->ongodev = fwdev;
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->ongoaddr = CSRROMOFF;
|
2003-07-09 13:07:35 +00:00
|
|
|
addr = 0xf0000000 | fc->ongoaddr;
|
|
|
|
goto dorequest;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-06-03 22:58:22 +00:00
|
|
|
fwdev = malloc(sizeof(struct fw_device), M_FW,
|
|
|
|
M_NOWAIT | M_ZERO);
|
2002-09-13 12:31:56 +00:00
|
|
|
if(fwdev == NULL)
|
|
|
|
return;
|
2002-11-12 13:49:17 +00:00
|
|
|
fwdev->fc = fc;
|
2002-09-13 12:31:56 +00:00
|
|
|
fwdev->rommax = 0;
|
|
|
|
fwdev->dst = fc->ongonode;
|
|
|
|
fwdev->eui.hi = fc->ongoeui.hi; fwdev->eui.lo = fc->ongoeui.lo;
|
|
|
|
fwdev->status = FWDEVINIT;
|
|
|
|
fwdev->speed = fc->speed_map->speed[fc->nodeid][fc->ongonode];
|
|
|
|
|
2003-02-01 06:34:36 +00:00
|
|
|
pfwdev = NULL;
|
2003-02-01 14:42:49 +00:00
|
|
|
STAILQ_FOREACH(tfwdev, &fc->devices, link) {
|
2003-02-01 06:34:36 +00:00
|
|
|
if (tfwdev->eui.hi > fwdev->eui.hi ||
|
|
|
|
(tfwdev->eui.hi == fwdev->eui.hi &&
|
|
|
|
tfwdev->eui.lo > fwdev->eui.lo))
|
|
|
|
break;
|
|
|
|
pfwdev = tfwdev;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-02-01 06:34:36 +00:00
|
|
|
if (pfwdev == NULL)
|
2003-02-01 14:42:49 +00:00
|
|
|
STAILQ_INSERT_HEAD(&fc->devices, fwdev, link);
|
2003-02-01 06:34:36 +00:00
|
|
|
else
|
2003-02-01 14:42:49 +00:00
|
|
|
STAILQ_INSERT_AFTER(&fc->devices, pfwdev, fwdev, link);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-01-04 10:21:11 +00:00
|
|
|
device_printf(fc->bdev, "New %s device ID:%08x%08x\n",
|
2002-12-06 02:17:30 +00:00
|
|
|
linkspeed[fwdev->speed],
|
|
|
|
fc->ongoeui.hi, fc->ongoeui.lo);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
fc->ongodev = fwdev;
|
|
|
|
fc->ongoaddr = CSRROMOFF;
|
|
|
|
addr = 0xf0000000 | fc->ongoaddr;
|
|
|
|
}else{
|
|
|
|
addr = 0xf0000000 | fc->ongoaddr;
|
|
|
|
}
|
2003-07-09 13:07:35 +00:00
|
|
|
dorequest:
|
2002-09-13 12:31:56 +00:00
|
|
|
#if 0
|
|
|
|
xfer = asyreqq(fc, FWSPD_S100, 0, 0,
|
|
|
|
((FWLOCALBUS | fc->ongonode) << 16) | 0xffff , addr,
|
|
|
|
fw_bus_explore_callback);
|
|
|
|
if(xfer == NULL) goto done;
|
|
|
|
#else
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer = fw_xfer_alloc(M_FWXFER);
|
2002-09-13 12:31:56 +00:00
|
|
|
if(xfer == NULL){
|
|
|
|
goto done;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.spd = 0;
|
|
|
|
fp = &xfer->send.hdr;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.rreqq.dest_hi = 0xffff;
|
2002-09-13 12:31:56 +00:00
|
|
|
fp->mode.rreqq.tlrt = 0;
|
|
|
|
fp->mode.rreqq.tcode = FWTCODE_RREQQ;
|
|
|
|
fp->mode.rreqq.pri = 0;
|
|
|
|
fp->mode.rreqq.src = 0;
|
2003-10-02 04:06:56 +00:00
|
|
|
fp->mode.rreqq.dst = FWLOCALBUS | fc->ongonode;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.rreqq.dest_lo = addr;
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer->act.hand = fw_bus_explore_callback;
|
|
|
|
|
2003-02-09 07:16:01 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
printf("node%d: explore addr=0x%x\n",
|
|
|
|
fc->ongonode, fc->ongoaddr);
|
2002-09-13 12:31:56 +00:00
|
|
|
err = fw_asyreq(fc, -1, xfer);
|
|
|
|
if(err){
|
|
|
|
fw_xfer_free( xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
done:
|
|
|
|
/* fw_attach_devs */
|
|
|
|
fc->status = FWBUSEXPDONE;
|
2002-12-06 02:17:30 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
printf("bus_explore done\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
fw_attach_dev(fc);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/* Portable Async. request read quad */
|
2002-11-12 05:52:01 +00:00
|
|
|
struct fw_xfer *
|
|
|
|
asyreqq(struct firewire_comm *fc, u_int8_t spd, u_int8_t tl, u_int8_t rt,
|
2002-10-21 10:21:49 +00:00
|
|
|
u_int32_t addr_hi, u_int32_t addr_lo,
|
2004-01-06 14:30:47 +00:00
|
|
|
void (*hand) (struct fw_xfer*))
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
int err;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer = fw_xfer_alloc(M_FWXFER);
|
2003-04-17 03:38:03 +00:00
|
|
|
if (xfer == NULL)
|
2002-09-13 12:31:56 +00:00
|
|
|
return NULL;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.spd = spd; /* XXX:min(spd, fc->spd) */
|
|
|
|
fp = &xfer->send.hdr;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.rreqq.dest_hi = addr_hi & 0xffff;
|
2002-09-13 12:31:56 +00:00
|
|
|
if(tl & FWP_TL_VALID){
|
|
|
|
fp->mode.rreqq.tlrt = (tl & 0x3f) << 2;
|
|
|
|
}else{
|
|
|
|
fp->mode.rreqq.tlrt = 0;
|
|
|
|
}
|
|
|
|
fp->mode.rreqq.tlrt |= rt & 0x3;
|
|
|
|
fp->mode.rreqq.tcode = FWTCODE_RREQQ;
|
|
|
|
fp->mode.rreqq.pri = 0;
|
|
|
|
fp->mode.rreqq.src = 0;
|
2003-10-02 04:06:56 +00:00
|
|
|
fp->mode.rreqq.dst = addr_hi >> 16;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.rreqq.dest_lo = addr_lo;
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer->act.hand = hand;
|
|
|
|
|
|
|
|
err = fw_asyreq(fc, -1, xfer);
|
|
|
|
if(err){
|
|
|
|
fw_xfer_free( xfer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return xfer;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* Callback for the IEEE1394 bus information collection.
|
|
|
|
*/
|
2002-11-12 05:52:01 +00:00
|
|
|
static void
|
|
|
|
fw_bus_explore_callback(struct fw_xfer *xfer)
|
|
|
|
{
|
2002-09-13 12:31:56 +00:00
|
|
|
struct firewire_comm *fc;
|
|
|
|
struct fw_pkt *sfp,*rfp;
|
|
|
|
struct csrhdr *chdr;
|
|
|
|
struct csrdir *csrd;
|
|
|
|
struct csrreg *csrreg;
|
|
|
|
u_int32_t offset;
|
|
|
|
|
|
|
|
|
2003-02-09 07:16:01 +00:00
|
|
|
if(xfer == NULL) {
|
|
|
|
printf("xfer == NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
fc = xfer->fc;
|
2003-02-09 07:16:01 +00:00
|
|
|
|
|
|
|
if (firewire_debug)
|
|
|
|
printf("node%d: callback addr=0x%x\n",
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->ongonode, fc->ongoaddr);
|
2003-02-09 07:16:01 +00:00
|
|
|
|
|
|
|
if(xfer->resp != 0){
|
|
|
|
printf("node%d: resp=%d addr=0x%x\n",
|
|
|
|
fc->ongonode, xfer->resp, fc->ongoaddr);
|
2003-04-30 10:20:24 +00:00
|
|
|
goto errnode;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
sfp = &xfer->send.hdr;
|
|
|
|
rfp = &xfer->recv.hdr;
|
2002-09-13 12:31:56 +00:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
u_int32_t *qld;
|
|
|
|
int i;
|
|
|
|
qld = (u_int32_t *)xfer->recv.buf;
|
|
|
|
printf("len:%d\n", xfer->recv.len);
|
|
|
|
for( i = 0 ; i <= xfer->recv.len && i < 32; i+= 4){
|
2003-04-17 03:38:03 +00:00
|
|
|
printf("0x%08x ", rfp->mode.ld[i/4]);
|
2002-09-13 12:31:56 +00:00
|
|
|
if((i % 16) == 15) printf("\n");
|
|
|
|
}
|
|
|
|
if((i % 16) != 15) printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if(fc->ongodev == NULL){
|
2003-04-17 03:38:03 +00:00
|
|
|
if(sfp->mode.rreqq.dest_lo == (0xf0000000 | CSRROMOFF)){
|
2002-09-13 12:31:56 +00:00
|
|
|
rfp->mode.rresq.data = ntohl(rfp->mode.rresq.data);
|
|
|
|
chdr = (struct csrhdr *)(&rfp->mode.rresq.data);
|
2003-02-09 07:16:01 +00:00
|
|
|
/* If CSR is minimal confinguration, more investgation is not needed. */
|
2002-09-13 12:31:56 +00:00
|
|
|
if(chdr->info_len == 1){
|
2003-02-09 07:16:01 +00:00
|
|
|
if (firewire_debug)
|
|
|
|
printf("node%d: minimal config\n",
|
|
|
|
fc->ongonode);
|
2002-09-13 12:31:56 +00:00
|
|
|
goto nextnode;
|
|
|
|
}else{
|
|
|
|
fc->ongoaddr = CSRROMOFF + 0xc;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
}else if(sfp->mode.rreqq.dest_lo == (0xf0000000 |(CSRROMOFF + 0xc))){
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->ongoeui.hi = ntohl(rfp->mode.rresq.data);
|
|
|
|
fc->ongoaddr = CSRROMOFF + 0x10;
|
2003-04-17 03:38:03 +00:00
|
|
|
}else if(sfp->mode.rreqq.dest_lo == (0xf0000000 |(CSRROMOFF + 0x10))){
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->ongoeui.lo = ntohl(rfp->mode.rresq.data);
|
2003-02-09 07:16:01 +00:00
|
|
|
if (fc->ongoeui.hi == 0 && fc->ongoeui.lo == 0) {
|
|
|
|
if (firewire_debug)
|
|
|
|
printf("node%d: eui64 is zero.\n",
|
|
|
|
fc->ongonode);
|
2002-09-13 12:31:56 +00:00
|
|
|
goto nextnode;
|
2003-02-09 07:16:01 +00:00
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->ongoaddr = CSRROMOFF;
|
|
|
|
}
|
|
|
|
}else{
|
2003-07-09 13:07:35 +00:00
|
|
|
if (fc->ongoaddr == CSRROMOFF &&
|
|
|
|
fc->ongodev->csrrom[0] == ntohl(rfp->mode.rresq.data)) {
|
|
|
|
fc->ongodev->status = FWDEVATTACHED;
|
|
|
|
goto nextnode;
|
|
|
|
}
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->ongodev->csrrom[(fc->ongoaddr - CSRROMOFF)/4] = ntohl(rfp->mode.rresq.data);
|
|
|
|
if(fc->ongoaddr > fc->ongodev->rommax){
|
|
|
|
fc->ongodev->rommax = fc->ongoaddr;
|
|
|
|
}
|
|
|
|
csrd = SLIST_FIRST(&fc->ongocsr);
|
|
|
|
if((csrd = SLIST_FIRST(&fc->ongocsr)) == NULL){
|
|
|
|
chdr = (struct csrhdr *)(fc->ongodev->csrrom);
|
|
|
|
offset = CSRROMOFF;
|
|
|
|
}else{
|
|
|
|
chdr = (struct csrhdr *)&fc->ongodev->csrrom[(csrd->off - CSRROMOFF)/4];
|
|
|
|
offset = csrd->off;
|
|
|
|
}
|
|
|
|
if(fc->ongoaddr > (CSRROMOFF + 0x14) && fc->ongoaddr != offset){
|
|
|
|
csrreg = (struct csrreg *)&fc->ongodev->csrrom[(fc->ongoaddr - CSRROMOFF)/4];
|
|
|
|
if( csrreg->key == 0x81 || csrreg->key == 0xd1){
|
|
|
|
csrd = SLIST_FIRST(&fc->csrfree);
|
|
|
|
if(csrd == NULL){
|
|
|
|
goto nextnode;
|
|
|
|
}else{
|
|
|
|
csrd->ongoaddr = fc->ongoaddr;
|
|
|
|
fc->ongoaddr += csrreg->val * 4;
|
|
|
|
csrd->off = fc->ongoaddr;
|
|
|
|
SLIST_REMOVE_HEAD(&fc->csrfree, link);
|
|
|
|
SLIST_INSERT_HEAD(&fc->ongocsr, csrd, link);
|
|
|
|
goto nextaddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fc->ongoaddr += 4;
|
|
|
|
if(((fc->ongoaddr - offset)/4 > chdr->crc_len) &&
|
|
|
|
(fc->ongodev->rommax < 0x414)){
|
|
|
|
if(fc->ongodev->rommax <= 0x414){
|
|
|
|
csrd = SLIST_FIRST(&fc->csrfree);
|
|
|
|
if(csrd == NULL) goto nextnode;
|
|
|
|
csrd->off = fc->ongoaddr;
|
|
|
|
csrd->ongoaddr = fc->ongoaddr;
|
|
|
|
SLIST_REMOVE_HEAD(&fc->csrfree, link);
|
|
|
|
SLIST_INSERT_HEAD(&fc->ongocsr, csrd, link);
|
|
|
|
}
|
|
|
|
goto nextaddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(((fc->ongoaddr - offset)/4 > chdr->crc_len)){
|
|
|
|
if(csrd == NULL){
|
|
|
|
goto nextnode;
|
|
|
|
};
|
|
|
|
fc->ongoaddr = csrd->ongoaddr + 4;
|
|
|
|
SLIST_REMOVE_HEAD(&fc->ongocsr, link);
|
|
|
|
SLIST_INSERT_HEAD(&fc->csrfree, csrd, link);
|
|
|
|
csrd = SLIST_FIRST(&fc->ongocsr);
|
|
|
|
if((csrd = SLIST_FIRST(&fc->ongocsr)) == NULL){
|
|
|
|
chdr = (struct csrhdr *)(fc->ongodev->csrrom);
|
|
|
|
offset = CSRROMOFF;
|
|
|
|
}else{
|
|
|
|
chdr = (struct csrhdr *)&(fc->ongodev->csrrom[(csrd->off - CSRROMOFF)/4]);
|
|
|
|
offset = csrd->off;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if((fc->ongoaddr - CSRROMOFF) > CSRROMSIZE){
|
|
|
|
goto nextnode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nextaddr:
|
|
|
|
fw_xfer_free( xfer);
|
|
|
|
fw_bus_explore(fc);
|
|
|
|
return;
|
2003-04-30 10:20:24 +00:00
|
|
|
errnode:
|
|
|
|
fc->retry_count++;
|
|
|
|
if (fc->ongodev != NULL)
|
|
|
|
fc->ongodev->status = FWDEVINVAL;
|
2002-09-13 12:31:56 +00:00
|
|
|
nextnode:
|
|
|
|
fw_xfer_free( xfer);
|
|
|
|
fc->ongonode++;
|
|
|
|
/* housekeeping work space */
|
|
|
|
fc->ongoaddr = CSRROMOFF;
|
|
|
|
fc->ongodev = NULL;
|
|
|
|
fc->ongoeui.hi = 0xffffffff; fc->ongoeui.lo = 0xffffffff;
|
|
|
|
while((csrd = SLIST_FIRST(&fc->ongocsr)) != NULL){
|
|
|
|
SLIST_REMOVE_HEAD(&fc->ongocsr, link);
|
|
|
|
SLIST_INSERT_HEAD(&fc->csrfree, csrd, link);
|
|
|
|
}
|
|
|
|
fw_bus_explore(fc);
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 05:52:01 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* To attach sub-devices layer onto IEEE1394 bus.
|
|
|
|
*/
|
2002-11-12 17:16:20 +00:00
|
|
|
static void
|
|
|
|
fw_attach_dev(struct firewire_comm *fc)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
2003-10-06 07:17:43 +00:00
|
|
|
struct fw_device *fwdev, *next;
|
2002-09-13 12:31:56 +00:00
|
|
|
int i, err;
|
|
|
|
device_t *devlistp;
|
|
|
|
int devcnt;
|
|
|
|
struct firewire_dev_comm *fdc;
|
2003-04-26 16:45:40 +00:00
|
|
|
|
2003-10-06 07:17:43 +00:00
|
|
|
for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL; fwdev = next) {
|
|
|
|
next = STAILQ_NEXT(fwdev, link);
|
|
|
|
if (fwdev->status == FWDEVINIT) {
|
2002-09-13 12:31:56 +00:00
|
|
|
fwdev->status = FWDEVATTACHED;
|
2003-10-06 07:17:43 +00:00
|
|
|
} else if (fwdev->status == FWDEVINVAL) {
|
|
|
|
fwdev->rcnt ++;
|
|
|
|
if (fwdev->rcnt > hold_count) {
|
|
|
|
/*
|
|
|
|
* Remove devices which have not been seen
|
|
|
|
* for a while.
|
|
|
|
*/
|
|
|
|
STAILQ_REMOVE(&fc->devices, fwdev, fw_device,
|
|
|
|
link);
|
|
|
|
free(fwdev, M_FW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-26 16:45:40 +00:00
|
|
|
|
2003-01-06 05:57:48 +00:00
|
|
|
err = device_get_children(fc->bdev, &devlistp, &devcnt);
|
2002-09-13 12:31:56 +00:00
|
|
|
if( err != 0 )
|
|
|
|
return;
|
|
|
|
for( i = 0 ; i < devcnt ; i++){
|
|
|
|
if (device_get_state(devlistp[i]) >= DS_ATTACHED) {
|
|
|
|
fdc = device_get_softc(devlistp[i]);
|
|
|
|
if (fdc->post_explore != NULL)
|
|
|
|
fdc->post_explore(fdc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(devlistp, M_TEMP);
|
|
|
|
|
|
|
|
if (fc->retry_count > 0) {
|
2003-02-17 14:24:06 +00:00
|
|
|
printf("probe failed for %d node\n", fc->retry_count);
|
|
|
|
#if 0
|
2003-02-01 14:42:49 +00:00
|
|
|
callout_reset(&fc->retry_probe_callout, hz*2,
|
|
|
|
(void *)fc->ibr, (void *)fc);
|
2003-02-17 14:24:06 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2002-11-12 17:16:20 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* To allocate uniq transaction label.
|
|
|
|
*/
|
2002-11-12 17:16:20 +00:00
|
|
|
static int
|
|
|
|
fw_get_tlabel(struct firewire_comm *fc, struct fw_xfer *xfer)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
struct tlabel *tl, *tmptl;
|
|
|
|
int s;
|
|
|
|
static u_int32_t label = 0;
|
|
|
|
|
|
|
|
s = splfw();
|
|
|
|
for( i = 0 ; i < 0x40 ; i ++){
|
|
|
|
label = (label + 1) & 0x3f;
|
|
|
|
for(tmptl = STAILQ_FIRST(&fc->tlabels[label]);
|
|
|
|
tmptl != NULL; tmptl = STAILQ_NEXT(tmptl, link)){
|
2003-10-02 04:06:56 +00:00
|
|
|
if (tmptl->xfer->send.hdr.mode.hdr.dst ==
|
|
|
|
xfer->send.hdr.mode.hdr.dst)
|
|
|
|
break;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
|
|
|
if(tmptl == NULL) {
|
2003-02-01 15:04:33 +00:00
|
|
|
tl = malloc(sizeof(struct tlabel),M_FW,M_NOWAIT);
|
2002-09-13 12:31:56 +00:00
|
|
|
if (tl == NULL) {
|
|
|
|
splx(s);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
tl->xfer = xfer;
|
|
|
|
STAILQ_INSERT_TAIL(&fc->tlabels[label], tl, link);
|
|
|
|
splx(s);
|
2003-02-09 07:16:01 +00:00
|
|
|
if (firewire_debug > 1)
|
|
|
|
printf("fw_get_tlabel: dst=%d tl=%d\n",
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.hdr.mode.hdr.dst, label);
|
2002-09-13 12:31:56 +00:00
|
|
|
return(label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
printf("fw_get_tlabel: no free tlabel\n");
|
|
|
|
return(-1);
|
|
|
|
}
|
2002-11-12 17:16:20 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
static void
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_rcv_copy(struct fw_rcv_buf *rb)
|
2003-04-17 03:38:03 +00:00
|
|
|
{
|
2003-10-02 04:06:56 +00:00
|
|
|
struct fw_pkt *pkt;
|
|
|
|
u_char *p;
|
|
|
|
struct tcode_info *tinfo;
|
|
|
|
u_int res, i, len, plen;
|
|
|
|
|
|
|
|
rb->xfer->recv.spd -= rb->spd;
|
|
|
|
|
|
|
|
pkt = (struct fw_pkt *)rb->vec->iov_base;
|
|
|
|
tinfo = &rb->fc->tcode[pkt->mode.hdr.tcode];
|
|
|
|
|
|
|
|
/* Copy header */
|
|
|
|
p = (u_char *)&rb->xfer->recv.hdr;
|
|
|
|
bcopy(rb->vec->iov_base, p, tinfo->hdr_len);
|
|
|
|
(u_char *)rb->vec->iov_base += tinfo->hdr_len;
|
|
|
|
rb->vec->iov_len -= tinfo->hdr_len;
|
|
|
|
|
|
|
|
/* Copy payload */
|
|
|
|
p = (u_char *)rb->xfer->recv.payload;
|
|
|
|
res = rb->xfer->recv.pay_len;
|
|
|
|
|
|
|
|
/* special handling for RRESQ */
|
|
|
|
if (pkt->mode.hdr.tcode == FWTCODE_RRESQ &&
|
|
|
|
p != NULL && res >= sizeof(u_int32_t)) {
|
|
|
|
*(u_int32_t *)p = pkt->mode.rresq.data;
|
|
|
|
rb->xfer->recv.pay_len = sizeof(u_int32_t);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((tinfo->flag & FWTI_BLOCK_ASY) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
plen = pkt->mode.rresb.len;
|
2003-04-17 03:38:03 +00:00
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
for (i = 0; i < rb->nvec; i++, rb->vec++) {
|
|
|
|
len = MIN(rb->vec->iov_len, plen);
|
2003-04-17 03:38:03 +00:00
|
|
|
if (res < len) {
|
|
|
|
printf("rcv buffer(%d) is %d bytes short.\n",
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer->recv.pay_len, len - res);
|
2003-04-17 03:38:03 +00:00
|
|
|
len = res;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
bcopy(rb->vec->iov_base, p, len);
|
2003-04-17 03:38:03 +00:00
|
|
|
p += len;
|
|
|
|
res -= len;
|
2003-10-02 04:06:56 +00:00
|
|
|
plen -= len;
|
|
|
|
if (res == 0 || plen == 0)
|
2003-04-17 03:38:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer->recv.pay_len -= res;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
}
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* Generic packet receving process.
|
|
|
|
*/
|
2002-11-12 17:16:20 +00:00
|
|
|
void
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_rcv(struct fw_rcv_buf *rb)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fw_pkt *fp, *resfp;
|
|
|
|
struct fw_bind *bind;
|
2003-04-17 03:38:03 +00:00
|
|
|
int tcode, s;
|
|
|
|
int i, len, oldstate;
|
2002-09-13 12:31:56 +00:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
u_int32_t *qld;
|
|
|
|
int i;
|
|
|
|
qld = (u_int32_t *)buf;
|
|
|
|
printf("spd %d len:%d\n", spd, len);
|
|
|
|
for( i = 0 ; i <= len && i < 32; i+= 4){
|
|
|
|
printf("0x%08x ", ntohl(qld[i/4]));
|
|
|
|
if((i % 16) == 15) printf("\n");
|
|
|
|
}
|
|
|
|
if((i % 16) != 15) printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2003-10-02 04:06:56 +00:00
|
|
|
fp = (struct fw_pkt *)rb->vec[0].iov_base;
|
2003-04-17 03:38:03 +00:00
|
|
|
tcode = fp->mode.common.tcode;
|
|
|
|
switch (tcode) {
|
2002-09-13 12:31:56 +00:00
|
|
|
case FWTCODE_WRES:
|
|
|
|
case FWTCODE_RRESQ:
|
|
|
|
case FWTCODE_RRESB:
|
|
|
|
case FWTCODE_LRES:
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer = fw_tl2xfer(rb->fc, fp->mode.hdr.src,
|
2002-09-13 12:31:56 +00:00
|
|
|
fp->mode.hdr.tlrt >> 2);
|
2003-10-02 04:06:56 +00:00
|
|
|
if(rb->xfer == NULL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
printf("fw_rcv: unknown response "
|
2003-02-15 00:54:10 +00:00
|
|
|
"tcode=%d src=0x%x tl=0x%x rt=%d data=0x%x\n",
|
2003-04-17 03:38:03 +00:00
|
|
|
tcode,
|
|
|
|
fp->mode.hdr.src,
|
2002-09-13 12:31:56 +00:00
|
|
|
fp->mode.hdr.tlrt >> 2,
|
|
|
|
fp->mode.hdr.tlrt & 3,
|
|
|
|
fp->mode.rresq.data);
|
|
|
|
#if 1
|
|
|
|
printf("try ad-hoc work around!!\n");
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer = fw_tl2xfer(rb->fc, fp->mode.hdr.src,
|
2002-09-13 12:31:56 +00:00
|
|
|
(fp->mode.hdr.tlrt >> 2)^3);
|
2003-10-02 04:06:56 +00:00
|
|
|
if (rb->xfer == NULL) {
|
2002-09-13 12:31:56 +00:00
|
|
|
printf("no use...\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
goto err;
|
|
|
|
#endif
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_rcv_copy(rb);
|
|
|
|
if (rb->xfer->recv.hdr.mode.wres.rtcode != RESP_CMP)
|
|
|
|
rb->xfer->resp = EIO;
|
|
|
|
else
|
|
|
|
rb->xfer->resp = 0;
|
2003-04-17 03:38:03 +00:00
|
|
|
/* make sure the packet is drained in AT queue */
|
2003-10-02 04:06:56 +00:00
|
|
|
oldstate = rb->xfer->state;
|
|
|
|
rb->xfer->state = FWXF_RCVD;
|
2003-04-17 03:38:03 +00:00
|
|
|
switch (oldstate) {
|
|
|
|
case FWXF_SENT:
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_xfer_done(rb->xfer);
|
2002-09-13 12:31:56 +00:00
|
|
|
break;
|
2003-04-17 03:38:03 +00:00
|
|
|
case FWXF_START:
|
2003-08-22 07:30:41 +00:00
|
|
|
#if 0
|
2003-04-17 03:38:03 +00:00
|
|
|
if (firewire_debug)
|
2003-10-02 04:06:56 +00:00
|
|
|
printf("not sent yet tl=%x\n", rb->xfer->tl);
|
2003-08-22 07:30:41 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
break;
|
2003-04-17 03:38:03 +00:00
|
|
|
default:
|
2003-10-02 04:06:56 +00:00
|
|
|
printf("unexpected state %d\n", rb->xfer->state);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
return;
|
2002-09-13 12:31:56 +00:00
|
|
|
case FWTCODE_WREQQ:
|
|
|
|
case FWTCODE_WREQB:
|
|
|
|
case FWTCODE_RREQQ:
|
|
|
|
case FWTCODE_RREQB:
|
|
|
|
case FWTCODE_LREQ:
|
2003-10-02 04:06:56 +00:00
|
|
|
bind = fw_bindlookup(rb->fc, fp->mode.rreqq.dest_hi,
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.rreqq.dest_lo);
|
2002-09-13 12:31:56 +00:00
|
|
|
if(bind == NULL){
|
2003-04-24 09:27:17 +00:00
|
|
|
#if __FreeBSD_version >= 500000
|
2003-10-02 04:06:56 +00:00
|
|
|
printf("Unknown service addr 0x%04x:0x%08x tcode=%x src=0x%x data=%x\n",
|
2003-04-24 09:27:17 +00:00
|
|
|
#else
|
2003-10-02 04:06:56 +00:00
|
|
|
printf("Unknown service addr 0x%04x:0x%08x tcode=%x src=0x%x data=%lx\n",
|
2003-04-24 09:27:17 +00:00
|
|
|
#endif
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.wreqq.dest_hi,
|
|
|
|
fp->mode.wreqq.dest_lo,
|
|
|
|
tcode,
|
|
|
|
fp->mode.hdr.src,
|
|
|
|
ntohl(fp->mode.wreqq.data));
|
2003-10-02 04:06:56 +00:00
|
|
|
if (rb->fc->status == FWBUSRESET) {
|
2003-02-13 13:35:57 +00:00
|
|
|
printf("fw_rcv: cannot respond(bus reset)!\n");
|
2002-09-13 12:31:56 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer = fw_xfer_alloc(M_FWXFER);
|
|
|
|
if(rb->xfer == NULL){
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer->send.spd = rb->spd;
|
|
|
|
rb->xfer->send.pay_len = 0;
|
|
|
|
resfp = &rb->xfer->send.hdr;
|
2003-04-17 03:38:03 +00:00
|
|
|
switch (tcode) {
|
2002-09-13 12:31:56 +00:00
|
|
|
case FWTCODE_WREQQ:
|
|
|
|
case FWTCODE_WREQB:
|
|
|
|
resfp->mode.hdr.tcode = FWTCODE_WRES;
|
|
|
|
break;
|
|
|
|
case FWTCODE_RREQQ:
|
|
|
|
resfp->mode.hdr.tcode = FWTCODE_RRESQ;
|
|
|
|
break;
|
|
|
|
case FWTCODE_RREQB:
|
|
|
|
resfp->mode.hdr.tcode = FWTCODE_RRESB;
|
|
|
|
break;
|
|
|
|
case FWTCODE_LREQ:
|
|
|
|
resfp->mode.hdr.tcode = FWTCODE_LRES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
resfp->mode.hdr.dst = fp->mode.hdr.src;
|
|
|
|
resfp->mode.hdr.tlrt = fp->mode.hdr.tlrt;
|
|
|
|
resfp->mode.hdr.pri = fp->mode.hdr.pri;
|
2003-10-02 04:06:56 +00:00
|
|
|
resfp->mode.rresb.rtcode = RESP_ADDRESS_ERROR;
|
2002-09-13 12:31:56 +00:00
|
|
|
resfp->mode.rresb.extcode = 0;
|
|
|
|
resfp->mode.rresb.len = 0;
|
|
|
|
/*
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer->act.hand = fw_asy_callback;
|
2002-09-13 12:31:56 +00:00
|
|
|
*/
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer->act.hand = fw_xfer_free;
|
|
|
|
if(fw_asyreq(rb->fc, -1, rb->xfer)){
|
|
|
|
fw_xfer_free(rb->xfer);
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
goto err;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
len = 0;
|
2003-10-02 04:06:56 +00:00
|
|
|
for (i = 0; i < rb->nvec; i ++)
|
|
|
|
len += rb->vec[i].iov_len;
|
2003-04-17 03:38:03 +00:00
|
|
|
switch(bind->act_type){
|
2002-09-13 12:31:56 +00:00
|
|
|
case FWACT_XFER:
|
2003-04-17 03:38:03 +00:00
|
|
|
/* splfw()?? */
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer = STAILQ_FIRST(&bind->xferlist);
|
|
|
|
if (rb->xfer == NULL) {
|
2003-04-17 03:38:03 +00:00
|
|
|
printf("Discard a packet for this bind.\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
STAILQ_REMOVE_HEAD(&bind->xferlist, link);
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_rcv_copy(rb);
|
2004-01-05 14:21:18 +00:00
|
|
|
rb->xfer->act.hand(rb->xfer);
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case FWACT_CH:
|
2003-10-02 04:06:56 +00:00
|
|
|
if(rb->fc->ir[bind->sub]->queued >=
|
|
|
|
rb->fc->ir[bind->sub]->maxq){
|
|
|
|
device_printf(rb->fc->bdev,
|
2003-01-04 10:21:11 +00:00
|
|
|
"Discard a packet %x %d\n",
|
2003-04-17 03:38:03 +00:00
|
|
|
bind->sub,
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->fc->ir[bind->sub]->queued);
|
2002-09-13 12:31:56 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer = STAILQ_FIRST(&bind->xferlist);
|
|
|
|
if (rb->xfer == NULL) {
|
2003-04-17 03:38:03 +00:00
|
|
|
printf("Discard packet for this bind\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
STAILQ_REMOVE_HEAD(&bind->xferlist, link);
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_rcv_copy(rb);
|
2002-09-13 12:31:56 +00:00
|
|
|
s = splfw();
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->fc->ir[bind->sub]->queued++;
|
|
|
|
STAILQ_INSERT_TAIL(&rb->fc->ir[bind->sub]->q,
|
|
|
|
rb->xfer, link);
|
2002-09-13 12:31:56 +00:00
|
|
|
splx(s);
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
wakeup((caddr_t)rb->fc->ir[bind->sub]);
|
2002-09-13 12:31:56 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2003-10-02 04:06:56 +00:00
|
|
|
#if 0 /* shouldn't happen ?? or for GASP */
|
2002-09-13 12:31:56 +00:00
|
|
|
case FWTCODE_STREAM:
|
|
|
|
{
|
|
|
|
struct fw_xferq *xferq;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
xferq = rb->fc->ir[sub];
|
2002-09-13 12:31:56 +00:00
|
|
|
#if 0
|
|
|
|
printf("stream rcv dma %d len %d off %d spd %d\n",
|
|
|
|
sub, len, off, spd);
|
|
|
|
#endif
|
|
|
|
if(xferq->queued >= xferq->maxq) {
|
|
|
|
printf("receive queue is full\n");
|
|
|
|
goto err;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
/* XXX get xfer from xfer queue, we don't need copy for
|
|
|
|
per packet mode */
|
2003-10-02 04:06:56 +00:00
|
|
|
rb->xfer = fw_xfer_alloc_buf(M_FWXFER, 0, /* XXX */
|
2003-04-17 03:38:03 +00:00
|
|
|
vec[0].iov_len);
|
2003-10-02 04:06:56 +00:00
|
|
|
if (rb->xfer == NULL) goto err;
|
|
|
|
fw_rcv_copy(rb)
|
2002-09-13 12:31:56 +00:00
|
|
|
s = splfw();
|
|
|
|
xferq->queued++;
|
2003-10-02 04:06:56 +00:00
|
|
|
STAILQ_INSERT_TAIL(&xferq->q, rb->xfer, link);
|
2002-09-13 12:31:56 +00:00
|
|
|
splx(s);
|
2003-10-02 04:06:56 +00:00
|
|
|
sc = device_get_softc(rb->fc->bdev);
|
2002-09-13 12:31:56 +00:00
|
|
|
#if __FreeBSD_version >= 500000
|
|
|
|
if (SEL_WAITING(&xferq->rsel))
|
|
|
|
#else
|
|
|
|
if (&xferq->rsel.si_pid != 0)
|
|
|
|
#endif
|
2003-11-09 09:17:26 +00:00
|
|
|
selwakeuppri(&xferq->rsel, FWPRI);
|
2002-09-13 12:31:56 +00:00
|
|
|
if (xferq->flag & FWXFERQ_WAKEUP) {
|
|
|
|
xferq->flag &= ~FWXFERQ_WAKEUP;
|
|
|
|
wakeup((caddr_t)xferq);
|
|
|
|
}
|
|
|
|
if (xferq->flag & FWXFERQ_HANDLER) {
|
|
|
|
xferq->hand(xferq);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
#endif
|
2002-09-13 12:31:56 +00:00
|
|
|
default:
|
2003-04-17 03:38:03 +00:00
|
|
|
printf("fw_rcv: unknow tcode %d\n", tcode);
|
2002-09-13 12:31:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
err:
|
2003-04-17 03:38:03 +00:00
|
|
|
return;
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 17:16:20 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* Post process for Bus Manager election process.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fw_try_bmr_callback(struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
struct firewire_comm *fc;
|
2003-01-17 15:03:25 +00:00
|
|
|
int bmr;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-01-17 15:03:25 +00:00
|
|
|
if (xfer == NULL)
|
|
|
|
return;
|
2002-09-13 12:31:56 +00:00
|
|
|
fc = xfer->fc;
|
2003-01-17 15:03:25 +00:00
|
|
|
if (xfer->resp != 0)
|
2002-09-13 12:31:56 +00:00
|
|
|
goto error;
|
2003-10-02 04:06:56 +00:00
|
|
|
if (xfer->recv.payload == NULL)
|
2002-09-13 12:31:56 +00:00
|
|
|
goto error;
|
2003-10-02 04:06:56 +00:00
|
|
|
if (xfer->recv.hdr.mode.lres.rtcode != FWRCODE_COMPLETE)
|
2003-01-17 15:03:25 +00:00
|
|
|
goto error;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
bmr = ntohl(xfer->recv.payload[0]);
|
2003-01-17 15:03:25 +00:00
|
|
|
if (bmr == 0x3f)
|
|
|
|
bmr = fc->nodeid;
|
|
|
|
|
|
|
|
CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, bmr & 0x3f);
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_xfer_free_buf(xfer);
|
2003-05-11 10:32:20 +00:00
|
|
|
fw_bmr(fc);
|
|
|
|
return;
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
error:
|
2003-05-11 10:32:20 +00:00
|
|
|
device_printf(fc->bdev, "bus manager election failed\n");
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_xfer_free_buf(xfer);
|
2002-09-13 12:31:56 +00:00
|
|
|
}
|
2002-11-12 17:16:20 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* To candidate Bus Manager election process.
|
|
|
|
*/
|
2003-02-03 08:10:50 +00:00
|
|
|
static void
|
2002-11-12 17:16:20 +00:00
|
|
|
fw_try_bmr(void *arg)
|
2002-09-13 12:31:56 +00:00
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
struct firewire_comm *fc = (struct firewire_comm *)arg;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
int err = 0;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer = fw_xfer_alloc_buf(M_FWXFER, 8, 4);
|
2002-09-13 12:31:56 +00:00
|
|
|
if(xfer == NULL){
|
|
|
|
return;
|
|
|
|
}
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.spd = 0;
|
2002-09-13 12:31:56 +00:00
|
|
|
fc->status = FWBUSMGRELECT;
|
|
|
|
|
2003-10-02 04:06:56 +00:00
|
|
|
fp = &xfer->send.hdr;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.lreq.dest_hi = 0xffff;
|
2002-09-13 12:31:56 +00:00
|
|
|
fp->mode.lreq.tlrt = 0;
|
|
|
|
fp->mode.lreq.tcode = FWTCODE_LREQ;
|
|
|
|
fp->mode.lreq.pri = 0;
|
|
|
|
fp->mode.lreq.src = 0;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.lreq.len = 8;
|
2003-10-02 04:06:56 +00:00
|
|
|
fp->mode.lreq.extcode = EXTCODE_CMP_SWAP;
|
|
|
|
fp->mode.lreq.dst = FWLOCALBUS | fc->irm;
|
2003-04-17 03:38:03 +00:00
|
|
|
fp->mode.lreq.dest_lo = 0xf0000000 | BUS_MGR_ID;
|
2003-10-02 04:06:56 +00:00
|
|
|
xfer->send.payload[0] = htonl(0x3f);
|
|
|
|
xfer->send.payload[1] = htonl(fc->nodeid);
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer->act.hand = fw_try_bmr_callback;
|
|
|
|
|
|
|
|
err = fw_asyreq(fc, -1, xfer);
|
|
|
|
if(err){
|
2003-10-02 04:06:56 +00:00
|
|
|
fw_xfer_free_buf(xfer);
|
2002-09-13 12:31:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 02:13:40 +00:00
|
|
|
|
|
|
|
#ifdef FW_VMACCESS
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* Software implementation for physical memory block access.
|
|
|
|
* XXX:Too slow, usef for debug purpose only.
|
|
|
|
*/
|
2002-11-12 17:16:20 +00:00
|
|
|
static void
|
|
|
|
fw_vmaccess(struct fw_xfer *xfer){
|
2002-09-13 12:31:56 +00:00
|
|
|
struct fw_pkt *rfp, *sfp = NULL;
|
2003-04-17 03:38:03 +00:00
|
|
|
u_int32_t *ld = (u_int32_t *)xfer->recv.buf;
|
2002-09-13 12:31:56 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
printf("vmaccess spd:%2x len:%03x data:%08x %08x %08x %08x\n",
|
|
|
|
xfer->spd, xfer->recv.len, ntohl(ld[0]), ntohl(ld[1]), ntohl(ld[2]), ntohl(ld[3]));
|
2002-09-13 12:31:56 +00:00
|
|
|
printf("vmaccess data:%08x %08x %08x %08x\n", ntohl(ld[4]), ntohl(ld[5]), ntohl(ld[6]), ntohl(ld[7]));
|
|
|
|
if(xfer->resp != 0){
|
|
|
|
fw_xfer_free( xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(xfer->recv.buf == NULL){
|
|
|
|
fw_xfer_free( xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rfp = (struct fw_pkt *)xfer->recv.buf;
|
|
|
|
switch(rfp->mode.hdr.tcode){
|
|
|
|
/* XXX need fix for 64bit arch */
|
|
|
|
case FWTCODE_WREQB:
|
2003-02-01 15:04:33 +00:00
|
|
|
xfer->send.buf = malloc(12, M_FW, M_NOWAIT);
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer->send.len = 12;
|
|
|
|
sfp = (struct fw_pkt *)xfer->send.buf;
|
|
|
|
bcopy(rfp->mode.wreqb.payload,
|
|
|
|
(caddr_t)ntohl(rfp->mode.wreqb.dest_lo), ntohs(rfp->mode.wreqb.len));
|
|
|
|
sfp->mode.wres.tcode = FWTCODE_WRES;
|
|
|
|
sfp->mode.wres.rtcode = 0;
|
|
|
|
break;
|
|
|
|
case FWTCODE_WREQQ:
|
2003-02-01 15:04:33 +00:00
|
|
|
xfer->send.buf = malloc(12, M_FW, M_NOWAIT);
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer->send.len = 12;
|
|
|
|
sfp->mode.wres.tcode = FWTCODE_WRES;
|
|
|
|
*((u_int32_t *)(ntohl(rfp->mode.wreqb.dest_lo))) = rfp->mode.wreqq.data;
|
|
|
|
sfp->mode.wres.rtcode = 0;
|
|
|
|
break;
|
|
|
|
case FWTCODE_RREQB:
|
2003-02-01 15:04:33 +00:00
|
|
|
xfer->send.buf = malloc(16 + rfp->mode.rreqb.len, M_FW, M_NOWAIT);
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer->send.len = 16 + ntohs(rfp->mode.rreqb.len);
|
|
|
|
sfp = (struct fw_pkt *)xfer->send.buf;
|
|
|
|
bcopy((caddr_t)ntohl(rfp->mode.rreqb.dest_lo),
|
|
|
|
sfp->mode.rresb.payload, (u_int16_t)ntohs(rfp->mode.rreqb.len));
|
|
|
|
sfp->mode.rresb.tcode = FWTCODE_RRESB;
|
|
|
|
sfp->mode.rresb.len = rfp->mode.rreqb.len;
|
|
|
|
sfp->mode.rresb.rtcode = 0;
|
|
|
|
sfp->mode.rresb.extcode = 0;
|
|
|
|
break;
|
|
|
|
case FWTCODE_RREQQ:
|
2003-02-01 15:04:33 +00:00
|
|
|
xfer->send.buf = malloc(16, M_FW, M_NOWAIT);
|
2002-09-13 12:31:56 +00:00
|
|
|
xfer->send.len = 16;
|
|
|
|
sfp = (struct fw_pkt *)xfer->send.buf;
|
|
|
|
sfp->mode.rresq.data = *(u_int32_t *)(ntohl(rfp->mode.rreqq.dest_lo));
|
|
|
|
sfp->mode.wres.tcode = FWTCODE_RRESQ;
|
|
|
|
sfp->mode.rresb.rtcode = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fw_xfer_free( xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sfp->mode.hdr.dst = rfp->mode.hdr.src;
|
|
|
|
xfer->dst = ntohs(rfp->mode.hdr.src);
|
|
|
|
xfer->act.hand = fw_xfer_free;
|
|
|
|
xfer->retry_req = fw_asybusy;
|
|
|
|
|
|
|
|
sfp->mode.hdr.tlrt = rfp->mode.hdr.tlrt;
|
|
|
|
sfp->mode.hdr.pri = 0;
|
|
|
|
|
|
|
|
fw_asyreq(xfer->fc, -1, xfer);
|
|
|
|
/**/
|
|
|
|
return;
|
|
|
|
}
|
2002-11-07 02:13:40 +00:00
|
|
|
#endif
|
|
|
|
|
2002-09-13 12:31:56 +00:00
|
|
|
/*
|
|
|
|
* CRC16 check-sum for IEEE1394 register blocks.
|
|
|
|
*/
|
2002-11-12 17:16:20 +00:00
|
|
|
u_int16_t
|
|
|
|
fw_crc16(u_int32_t *ptr, u_int32_t len){
|
2002-09-13 12:31:56 +00:00
|
|
|
u_int32_t i, sum, crc = 0;
|
|
|
|
int shift;
|
|
|
|
len = (len + 3) & ~3;
|
|
|
|
for(i = 0 ; i < len ; i+= 4){
|
|
|
|
for( shift = 28 ; shift >= 0 ; shift -= 4){
|
|
|
|
sum = ((crc >> 12) ^ (ptr[i/4] >> shift)) & 0xf;
|
|
|
|
crc = (crc << 4) ^ ( sum << 12 ) ^ ( sum << 5) ^ sum;
|
|
|
|
}
|
|
|
|
crc &= 0xffff;
|
|
|
|
}
|
|
|
|
return((u_int16_t) crc);
|
|
|
|
}
|
2002-11-12 17:16:20 +00:00
|
|
|
|
2003-02-03 08:10:50 +00:00
|
|
|
static int
|
2003-01-30 05:18:35 +00:00
|
|
|
fw_bmr(struct firewire_comm *fc)
|
|
|
|
{
|
|
|
|
struct fw_device fwdev;
|
2003-04-17 03:38:03 +00:00
|
|
|
union fw_self_id *self_id;
|
2003-01-30 05:18:35 +00:00
|
|
|
int cmstr;
|
2003-10-02 04:06:56 +00:00
|
|
|
u_int32_t quad;
|
2003-01-30 05:18:35 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
/* Check to see if the current root node is cycle master capable */
|
|
|
|
self_id = &fc->topology_map->self_id[fc->max_node];
|
|
|
|
if (fc->max_node > 0) {
|
2003-05-11 10:32:20 +00:00
|
|
|
/* XXX check cmc bit of businfo block rather than contender */
|
|
|
|
if (self_id->p0.link_active && self_id->p0.contender)
|
2003-04-17 03:38:03 +00:00
|
|
|
cmstr = fc->max_node;
|
2003-05-11 10:32:20 +00:00
|
|
|
else {
|
|
|
|
device_printf(fc->bdev,
|
|
|
|
"root node is not cycle master capable\n");
|
|
|
|
/* XXX shall we be the cycle master? */
|
2003-04-17 03:38:03 +00:00
|
|
|
cmstr = fc->nodeid;
|
2003-05-11 10:32:20 +00:00
|
|
|
/* XXX need bus reset */
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
} else
|
|
|
|
cmstr = -1;
|
2003-05-11 10:32:20 +00:00
|
|
|
|
|
|
|
device_printf(fc->bdev, "bus manager %d ", CSRARC(fc, BUS_MGR_ID));
|
|
|
|
if(CSRARC(fc, BUS_MGR_ID) != fc->nodeid) {
|
|
|
|
/* We are not the bus manager */
|
|
|
|
printf("\n");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
printf("(me)\n");
|
|
|
|
|
|
|
|
/* Optimize gapcount */
|
2003-04-17 03:38:03 +00:00
|
|
|
if(fc->max_hop <= MAX_GAPHOP )
|
|
|
|
fw_phy_config(fc, cmstr, gap_cnt[fc->max_hop]);
|
2003-01-30 05:18:35 +00:00
|
|
|
/* If we are the cycle master, nothing to do */
|
2003-04-17 03:38:03 +00:00
|
|
|
if (cmstr == fc->nodeid || cmstr == -1)
|
2003-01-30 05:18:35 +00:00
|
|
|
return 0;
|
|
|
|
/* Bus probe has not finished, make dummy fwdev for cmstr */
|
|
|
|
bzero(&fwdev, sizeof(fwdev));
|
|
|
|
fwdev.fc = fc;
|
|
|
|
fwdev.dst = cmstr;
|
|
|
|
fwdev.speed = 0;
|
|
|
|
fwdev.maxrec = 8; /* 512 */
|
|
|
|
fwdev.status = FWDEVINIT;
|
|
|
|
/* Set cmstr bit on the cycle master */
|
2003-10-02 04:06:56 +00:00
|
|
|
quad = htonl(1 << 8);
|
2003-01-30 05:18:35 +00:00
|
|
|
fwmem_write_quad(&fwdev, NULL, 0/*spd*/,
|
2003-10-02 04:06:56 +00:00
|
|
|
0xffff, 0xf0000000 | STATE_SET, &quad, fw_asy_callback_free);
|
2003-01-30 05:18:35 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-05 03:11:39 +00:00
|
|
|
static int
|
|
|
|
fw_modevent(module_t mode, int type, void *data)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
#if __FreeBSD_version >= 500000
|
|
|
|
static eventhandler_tag fwdev_ehtag = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
#if __FreeBSD_version >= 500000
|
|
|
|
fwdev_ehtag = EVENTHANDLER_REGISTER(dev_clone,
|
|
|
|
fwdev_clone, 0, 1000);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
#if __FreeBSD_version >= 500000
|
|
|
|
if (fwdev_ehtag != NULL)
|
|
|
|
EVENTHANDLER_DEREGISTER(dev_clone, fwdev_ehtag);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case MOD_SHUTDOWN:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DRIVER_MODULE(firewire,fwohci,firewire_driver,firewire_devclass,fw_modevent,0);
|
2002-09-13 12:31:56 +00:00
|
|
|
MODULE_VERSION(firewire, 1);
|