Deleted Added
full compact
firewire.c (271795) firewire.c (272214)
1/*-
2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 19 unchanged lines hidden (view full) ---

28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 19 unchanged lines hidden (view full) ---

28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/sys/dev/firewire/firewire.c 271795 2014-09-18 17:28:21Z will $");
36__FBSDID("$FreeBSD: head/sys/dev/firewire/firewire.c 272214 2014-09-27 16:50:21Z kan $");
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/types.h>
41
42#include <sys/jail.h>
43#include <sys/kernel.h>
44#include <sys/module.h>
45#include <sys/malloc.h>
46#include <sys/conf.h>
47#include <sys/sysctl.h>
48#include <sys/kthread.h>
49
50#include <sys/kdb.h>
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/types.h>
41
42#include <sys/jail.h>
43#include <sys/kernel.h>
44#include <sys/module.h>
45#include <sys/malloc.h>
46#include <sys/conf.h>
47#include <sys/sysctl.h>
48#include <sys/kthread.h>
49
50#include <sys/kdb.h>
51
52#include <sys/bus.h> /* used by smbus and newbus */
53#include <machine/bus.h>
54
55#include <dev/firewire/firewire.h>
56#include <dev/firewire/firewirereg.h>
57#include <dev/firewire/fwmem.h>
58#include <dev/firewire/iec13213.h>
59#include <dev/firewire/iec68113.h>
60
61struct crom_src_buf {
62 struct crom_src src;
63 struct crom_chunk root;
64 struct crom_chunk vendor;
65 struct crom_chunk hw;
66};
67
51#include <sys/bus.h> /* used by smbus and newbus */
52#include <machine/bus.h>
53
54#include <dev/firewire/firewire.h>
55#include <dev/firewire/firewirereg.h>
56#include <dev/firewire/fwmem.h>
57#include <dev/firewire/iec13213.h>
58#include <dev/firewire/iec68113.h>
59
60struct crom_src_buf {
61 struct crom_src src;
62 struct crom_chunk root;
63 struct crom_chunk vendor;
64 struct crom_chunk hw;
65};
66
68int firewire_debug=0, try_bmr=1, hold_count=0;
67int firewire_debug = 0, try_bmr = 1, hold_count = 0;
69SYSCTL_INT(_debug, OID_AUTO, firewire_debug, CTLFLAG_RW, &firewire_debug, 0,
70 "FireWire driver debug flag");
71SYSCTL_NODE(_hw, OID_AUTO, firewire, CTLFLAG_RD, 0, "FireWire Subsystem");
72SYSCTL_INT(_hw_firewire, OID_AUTO, try_bmr, CTLFLAG_RW, &try_bmr, 0,
73 "Try to be a bus manager");
74SYSCTL_INT(_hw_firewire, OID_AUTO, hold_count, CTLFLAG_RW, &hold_count, 0,
75 "Number of count of bus resets for removing lost device information");
76
77MALLOC_DEFINE(M_FW, "firewire", "FireWire");
78MALLOC_DEFINE(M_FWXFER, "fw_xfer", "XFER/FireWire");
79
80#define FW_MAXASYRTY 4
81
82devclass_t firewire_devclass;
83
68SYSCTL_INT(_debug, OID_AUTO, firewire_debug, CTLFLAG_RW, &firewire_debug, 0,
69 "FireWire driver debug flag");
70SYSCTL_NODE(_hw, OID_AUTO, firewire, CTLFLAG_RD, 0, "FireWire Subsystem");
71SYSCTL_INT(_hw_firewire, OID_AUTO, try_bmr, CTLFLAG_RW, &try_bmr, 0,
72 "Try to be a bus manager");
73SYSCTL_INT(_hw_firewire, OID_AUTO, hold_count, CTLFLAG_RW, &hold_count, 0,
74 "Number of count of bus resets for removing lost device information");
75
76MALLOC_DEFINE(M_FW, "firewire", "FireWire");
77MALLOC_DEFINE(M_FWXFER, "fw_xfer", "XFER/FireWire");
78
79#define FW_MAXASYRTY 4
80
81devclass_t firewire_devclass;
82
84static void firewire_identify (driver_t *, device_t);
85static int firewire_probe (device_t);
86static int firewire_attach (device_t);
87static int firewire_detach (device_t);
88static int firewire_resume (device_t);
83static void firewire_identify(driver_t *, device_t);
84static int firewire_probe(device_t);
85static int firewire_attach(device_t);
86static int firewire_detach(device_t);
87static int firewire_resume(device_t);
89static void firewire_xfer_timeout(void *, int);
90static device_t firewire_add_child(device_t, u_int, const char *, int);
88static void firewire_xfer_timeout(void *, int);
89static device_t firewire_add_child(device_t, u_int, const char *, int);
91static void fw_try_bmr (void *);
92static void fw_try_bmr_callback (struct fw_xfer *);
93static void fw_asystart (struct fw_xfer *);
94static int fw_get_tlabel (struct firewire_comm *, struct fw_xfer *);
95static void fw_bus_probe (struct firewire_comm *);
96static void fw_attach_dev (struct firewire_comm *);
90static void fw_try_bmr(void *);
91static void fw_try_bmr_callback(struct fw_xfer *);
92static void fw_asystart(struct fw_xfer *);
93static int fw_get_tlabel(struct firewire_comm *, struct fw_xfer *);
94static void fw_bus_probe(void *);
95static void fw_attach_dev(struct firewire_comm *);
97static void fw_bus_probe_thread(void *);
98#ifdef FW_VMACCESS
99static void fw_vmaccess (struct fw_xfer *);
100#endif
101static int fw_bmr (struct firewire_comm *);
102static void fw_dump_hdr(struct fw_pkt *, char *);
103
104static device_method_t firewire_methods[] = {

--- 6 unchanged lines hidden (view full) ---

111 DEVMETHOD(device_resume, firewire_resume),
112 DEVMETHOD(device_shutdown, bus_generic_shutdown),
113
114 /* Bus interface */
115 DEVMETHOD(bus_add_child, firewire_add_child),
116
117 DEVMETHOD_END
118};
96static void fw_bus_probe_thread(void *);
97#ifdef FW_VMACCESS
98static void fw_vmaccess (struct fw_xfer *);
99#endif
100static int fw_bmr (struct firewire_comm *);
101static void fw_dump_hdr(struct fw_pkt *, char *);
102
103static device_method_t firewire_methods[] = {

--- 6 unchanged lines hidden (view full) ---

110 DEVMETHOD(device_resume, firewire_resume),
111 DEVMETHOD(device_shutdown, bus_generic_shutdown),
112
113 /* Bus interface */
114 DEVMETHOD(bus_add_child, firewire_add_child),
115
116 DEVMETHOD_END
117};
118
119char *linkspeed[] = {
120 "S100", "S200", "S400", "S800",
121 "S1600", "S3200", "undef", "undef"
122};
123
124static char *tcode_str[] = {
125 "WREQQ", "WREQB", "WRES", "undef",
126 "RREQQ", "RREQB", "RRESQ", "RRESB",

--- 42 unchanged lines hidden (view full) ---

169 s = splfw();
170 FW_GLOCK(fc);
171 STAILQ_FOREACH(fwdev, &fc->devices, link)
172 if (FW_EUI64_EQUAL(fwdev->eui, *eui))
173 break;
174 FW_GUNLOCK(fc);
175 splx(s);
176
119char *linkspeed[] = {
120 "S100", "S200", "S400", "S800",
121 "S1600", "S3200", "undef", "undef"
122};
123
124static char *tcode_str[] = {
125 "WREQQ", "WREQB", "WRES", "undef",
126 "RREQQ", "RREQB", "RRESQ", "RRESB",

--- 42 unchanged lines hidden (view full) ---

169 s = splfw();
170 FW_GLOCK(fc);
171 STAILQ_FOREACH(fwdev, &fc->devices, link)
172 if (FW_EUI64_EQUAL(fwdev->eui, *eui))
173 break;
174 FW_GUNLOCK(fc);
175 splx(s);
176
177 if(fwdev == NULL) return NULL;
178 if(fwdev->status == FWDEVINVAL) return NULL;
177 if (fwdev == NULL)
178 return NULL;
179 if (fwdev->status == FWDEVINVAL)
180 return NULL;
179 return fwdev;
180}
181
182/*
183 * Async. request procedure for userland application.
184 */
185int
186fw_asyreq(struct firewire_comm *fc, int sub, struct fw_xfer *xfer)
187{
188 int err = 0;
189 struct fw_xferq *xferq;
190 int len;
191 struct fw_pkt *fp;
192 int tcode;
193 struct tcode_info *info;
194
181 return fwdev;
182}
183
184/*
185 * Async. request procedure for userland application.
186 */
187int
188fw_asyreq(struct firewire_comm *fc, int sub, struct fw_xfer *xfer)
189{
190 int err = 0;
191 struct fw_xferq *xferq;
192 int len;
193 struct fw_pkt *fp;
194 int tcode;
195 struct tcode_info *info;
196
195 if(xfer == NULL) return EINVAL;
196 if(xfer->hand == NULL){
197 if (xfer == NULL)
198 return EINVAL;
199 if (xfer->hand == NULL) {
197 printf("hand == NULL\n");
198 return EINVAL;
199 }
200 fp = &xfer->send.hdr;
201
202 tcode = fp->mode.common.tcode & 0xf;
203 info = &fc->tcode[tcode];
204 if (info->flag == 0) {

--- 21 unchanged lines hidden (view full) ---

226 return EINVAL;
227 }
228 if (info->flag & FWTI_BLOCK_STR)
229 len = fp->mode.stream.len;
230 else if (info->flag & FWTI_BLOCK_ASY)
231 len = fp->mode.rresb.len;
232 else
233 len = 0;
200 printf("hand == NULL\n");
201 return EINVAL;
202 }
203 fp = &xfer->send.hdr;
204
205 tcode = fp->mode.common.tcode & 0xf;
206 info = &fc->tcode[tcode];
207 if (info->flag == 0) {

--- 21 unchanged lines hidden (view full) ---

229 return EINVAL;
230 }
231 if (info->flag & FWTI_BLOCK_STR)
232 len = fp->mode.stream.len;
233 else if (info->flag & FWTI_BLOCK_ASY)
234 len = fp->mode.rresb.len;
235 else
236 len = 0;
234 if (len != xfer->send.pay_len){
237 if (len != xfer->send.pay_len) {
235 printf("len(%d) != send.pay_len(%d) %s(%x)\n",
236 len, xfer->send.pay_len, tcode_str[tcode], tcode);
238 printf("len(%d) != send.pay_len(%d) %s(%x)\n",
239 len, xfer->send.pay_len, tcode_str[tcode], tcode);
237 return EINVAL;
240 return EINVAL;
238 }
239
241 }
242
240 if(xferq->start == NULL){
243 if (xferq->start == NULL) {
241 printf("xferq->start == NULL\n");
242 return EINVAL;
243 }
244 printf("xferq->start == NULL\n");
245 return EINVAL;
246 }
244 if(!(xferq->queued < xferq->maxq)){
247 if (!(xferq->queued < xferq->maxq)) {
245 device_printf(fc->bdev, "Discard a packet (queued=%d)\n",
246 xferq->queued);
247 return EAGAIN;
248 }
249
250 xfer->tl = -1;
251 if (info->flag & FWTI_TLABEL) {
252 if (fw_get_tlabel(fc, xfer) < 0)
253 return EAGAIN;
254 }
255
256 xfer->resp = 0;
257 xfer->fc = fc;
258 xfer->q = xferq;
259
260 fw_asystart(xfer);
261 return err;
262}
248 device_printf(fc->bdev, "Discard a packet (queued=%d)\n",
249 xferq->queued);
250 return EAGAIN;
251 }
252
253 xfer->tl = -1;
254 if (info->flag & FWTI_TLABEL) {
255 if (fw_get_tlabel(fc, xfer) < 0)
256 return EAGAIN;
257 }
258
259 xfer->resp = 0;
260 xfer->fc = fc;
261 xfer->q = xferq;
262
263 fw_asystart(xfer);
264 return err;
265}
266
263/*
264 * Wakeup blocked process.
265 */
266void
267fw_xferwake(struct fw_xfer *xfer)
268{
269 struct mtx *lock = &xfer->fc->wait_lock;
270

--- 7 unchanged lines hidden (view full) ---

278
279int
280fw_xferwait(struct fw_xfer *xfer)
281{
282 struct mtx *lock = &xfer->fc->wait_lock;
283 int err = 0;
284
285 mtx_lock(lock);
267/*
268 * Wakeup blocked process.
269 */
270void
271fw_xferwake(struct fw_xfer *xfer)
272{
273 struct mtx *lock = &xfer->fc->wait_lock;
274

--- 7 unchanged lines hidden (view full) ---

282
283int
284fw_xferwait(struct fw_xfer *xfer)
285{
286 struct mtx *lock = &xfer->fc->wait_lock;
287 int err = 0;
288
289 mtx_lock(lock);
286 if ((xfer->flag & FWXF_WAKE) == 0)
287 err = msleep((void *)xfer, lock, PWAIT|PCATCH, "fw_xferwait", 0);
290 while ((xfer->flag & FWXF_WAKE) == 0)
291 err = msleep(xfer, lock, PWAIT|PCATCH, "fw_xferwait", 0);
288 mtx_unlock(lock);
289
290 return (err);
291}
292
293/*
294 * Async. request with given xfer structure.
295 */
296static void
297fw_asystart(struct fw_xfer *xfer)
298{
299 struct firewire_comm *fc = xfer->fc;
300 int s;
292 mtx_unlock(lock);
293
294 return (err);
295}
296
297/*
298 * Async. request with given xfer structure.
299 */
300static void
301fw_asystart(struct fw_xfer *xfer)
302{
303 struct firewire_comm *fc = xfer->fc;
304 int s;
305
301 s = splfw();
302 /* Protect from interrupt/timeout */
303 FW_GLOCK(fc);
304 xfer->flag = FWXF_INQ;
305 STAILQ_INSERT_TAIL(&xfer->q->q, xfer, link);
306#if 0
306 s = splfw();
307 /* Protect from interrupt/timeout */
308 FW_GLOCK(fc);
309 xfer->flag = FWXF_INQ;
310 STAILQ_INSERT_TAIL(&xfer->q->q, xfer, link);
311#if 0
307 xfer->q->queued ++;
312 xfer->q->queued++;
308#endif
309 FW_GUNLOCK(fc);
310 splx(s);
311 /* XXX just queue for mbuf */
312 if (xfer->mbuf == NULL)
313 xfer->q->start(fc);
314 return;
315}

--- 25 unchanged lines hidden (view full) ---

341 split_timeout.tv_usec = 200 * 1000; /* 200 msec */
342
343 microtime(&tv);
344 timevalsub(&tv, &split_timeout);
345 STAILQ_INIT(&xfer_timeout);
346
347 s = splfw();
348 mtx_lock(&fc->tlabel_lock);
313#endif
314 FW_GUNLOCK(fc);
315 splx(s);
316 /* XXX just queue for mbuf */
317 if (xfer->mbuf == NULL)
318 xfer->q->start(fc);
319 return;
320}

--- 25 unchanged lines hidden (view full) ---

346 split_timeout.tv_usec = 200 * 1000; /* 200 msec */
347
348 microtime(&tv);
349 timevalsub(&tv, &split_timeout);
350 STAILQ_INIT(&xfer_timeout);
351
352 s = splfw();
353 mtx_lock(&fc->tlabel_lock);
349 for (i = 0; i < 0x40; i ++) {
354 for (i = 0; i < 0x40; i++) {
350 while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
351 if ((xfer->flag & FWXF_SENT) == 0)
352 /* not sent yet */
353 break;
354 if (timevalcmp(&xfer->tv, &tv, >))
355 /* the rests are newer than this */
356 break;
357 device_printf(fc->bdev,
355 while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
356 if ((xfer->flag & FWXF_SENT) == 0)
357 /* not sent yet */
358 break;
359 if (timevalcmp(&xfer->tv, &tv, >))
360 /* the rests are newer than this */
361 break;
362 device_printf(fc->bdev,
358 "split transaction timeout: "
359 "tl=0x%x flag=0x%02x\n", i, xfer->flag);
363 "split transaction timeout: tl=0x%x flag=0x%02x\n",
364 i, xfer->flag);
360 fw_dump_hdr(&xfer->send.hdr, "send");
361 xfer->resp = ETIMEDOUT;
362 xfer->tl = -1;
363 STAILQ_REMOVE_HEAD(&fc->tlabels[i], tlabel);
364 STAILQ_INSERT_TAIL(&xfer_timeout, xfer, tlabel);
365 }
366 }
367 mtx_unlock(&fc->tlabel_lock);
368 splx(s);
369 fc->timeout(fc);
370
371 STAILQ_FOREACH_SAFE(xfer, &xfer_timeout, tlabel, txfer)
365 fw_dump_hdr(&xfer->send.hdr, "send");
366 xfer->resp = ETIMEDOUT;
367 xfer->tl = -1;
368 STAILQ_REMOVE_HEAD(&fc->tlabels[i], tlabel);
369 STAILQ_INSERT_TAIL(&xfer_timeout, xfer, tlabel);
370 }
371 }
372 mtx_unlock(&fc->tlabel_lock);
373 splx(s);
374 fc->timeout(fc);
375
376 STAILQ_FOREACH_SAFE(xfer, &xfer_timeout, tlabel, txfer)
372 xfer->hand(xfer);
377 xfer->hand(xfer);
373}
374
375#define WATCHDOG_HZ 10
376static void
377firewire_watchdog(void *arg)
378{
379 struct firewire_comm *fc;
380 static int watchdog_clock = 0;
381
378}
379
380#define WATCHDOG_HZ 10
381static void
382firewire_watchdog(void *arg)
383{
384 struct firewire_comm *fc;
385 static int watchdog_clock = 0;
386
382 fc = (struct firewire_comm *)arg;
387 fc = arg;
383
384 /*
385 * At boot stage, the device interrupt is disabled and
386 * We encounter a timeout easily. To avoid this,
387 * ignore clock interrupt for a while.
388 */
389 if (watchdog_clock > WATCHDOG_HZ * 15)
390 taskqueue_enqueue(fc->taskqueue, &fc->task_timeout);
391 else
388
389 /*
390 * At boot stage, the device interrupt is disabled and
391 * We encounter a timeout easily. To avoid this,
392 * ignore clock interrupt for a while.
393 */
394 if (watchdog_clock > WATCHDOG_HZ * 15)
395 taskqueue_enqueue(fc->taskqueue, &fc->task_timeout);
396 else
392 watchdog_clock ++;
397 watchdog_clock++;
393
394 callout_reset(&fc->timeout_callout, hz / WATCHDOG_HZ,
398
399 callout_reset(&fc->timeout_callout, hz / WATCHDOG_HZ,
395 (void *)firewire_watchdog, (void *)fc);
400 firewire_watchdog, fc);
396}
397
398/*
399 * The attach routine.
400 */
401static int
402firewire_attach(device_t dev)
403{
404 int unit;
405 struct firewire_softc *sc = device_get_softc(dev);
406 device_t pa = device_get_parent(dev);
407 struct firewire_comm *fc;
408
401}
402
403/*
404 * The attach routine.
405 */
406static int
407firewire_attach(device_t dev)
408{
409 int unit;
410 struct firewire_softc *sc = device_get_softc(dev);
411 device_t pa = device_get_parent(dev);
412 struct firewire_comm *fc;
413
409 fc = (struct firewire_comm *)device_get_softc(pa);
414 fc = device_get_softc(pa);
410 sc->fc = fc;
411 fc->status = FWBUSNOTREADY;
412
413 unit = device_get_unit(dev);
415 sc->fc = fc;
416 fc->status = FWBUSNOTREADY;
417
418 unit = device_get_unit(dev);
414 if( fc->nisodma > FWMAXNDMA) fc->nisodma = FWMAXNDMA;
419 if (fc->nisodma > FWMAXNDMA)
420 fc->nisodma = FWMAXNDMA;
415
416 fwdev_makedev(sc);
417
421
422 fwdev_makedev(sc);
423
418 fc->crom_src_buf = (struct crom_src_buf *)malloc(
419 sizeof(struct crom_src_buf),
420 M_FW, M_NOWAIT | M_ZERO);
424 fc->crom_src_buf = malloc(sizeof(struct crom_src_buf),
425 M_FW, M_NOWAIT | M_ZERO);
421 if (fc->crom_src_buf == NULL) {
426 if (fc->crom_src_buf == NULL) {
422 device_printf(fc->dev, "%s: Malloc Failure crom src buff\n", __func__);
427 device_printf(fc->dev,
428 "%s: unable to allocate crom src buffer\n", __func__);
423 return ENOMEM;
424 }
429 return ENOMEM;
430 }
425 fc->topology_map = (struct fw_topology_map *)malloc(
426 sizeof(struct fw_topology_map),
427 M_FW, M_NOWAIT | M_ZERO);
431 fc->topology_map = malloc(sizeof(struct fw_topology_map),
432 M_FW, M_NOWAIT | M_ZERO);
428 if (fc->topology_map == NULL) {
433 if (fc->topology_map == NULL) {
429 device_printf(fc->dev, "%s: Malloc Failure topology map\n", __func__);
434 device_printf(fc->dev, "%s: unable to allocate topology map\n",
435 __func__);
430 free(fc->crom_src_buf, M_FW);
431 return ENOMEM;
432 }
436 free(fc->crom_src_buf, M_FW);
437 return ENOMEM;
438 }
433 fc->speed_map = (struct fw_speed_map *)malloc(
434 sizeof(struct fw_speed_map),
435 M_FW, M_NOWAIT | M_ZERO);
439 fc->speed_map = malloc(sizeof(struct fw_speed_map),
440 M_FW, M_NOWAIT | M_ZERO);
436 if (fc->speed_map == NULL) {
441 if (fc->speed_map == NULL) {
437 device_printf(fc->dev, "%s: Malloc Failure speed map\n", __func__);
442 device_printf(fc->dev, "%s: unable to allocate speed map\n",
443 __func__);
438 free(fc->crom_src_buf, M_FW);
439 free(fc->topology_map, M_FW);
440 return ENOMEM;
441 }
442
443 mtx_init(&fc->wait_lock, "fwwait", NULL, MTX_DEF);
444 mtx_init(&fc->tlabel_lock, "fwtlabel", NULL, MTX_DEF);
445 CALLOUT_INIT(&fc->timeout_callout);
446 CALLOUT_INIT(&fc->bmr_callout);
447 CALLOUT_INIT(&fc->busprobe_callout);
444 free(fc->crom_src_buf, M_FW);
445 free(fc->topology_map, M_FW);
446 return ENOMEM;
447 }
448
449 mtx_init(&fc->wait_lock, "fwwait", NULL, MTX_DEF);
450 mtx_init(&fc->tlabel_lock, "fwtlabel", NULL, MTX_DEF);
451 CALLOUT_INIT(&fc->timeout_callout);
452 CALLOUT_INIT(&fc->bmr_callout);
453 CALLOUT_INIT(&fc->busprobe_callout);
448 TASK_INIT(&fc->task_timeout, 0, firewire_xfer_timeout, (void *)fc);
454 TASK_INIT(&fc->task_timeout, 0, firewire_xfer_timeout, fc);
449
450 callout_reset(&sc->fc->timeout_callout, hz,
455
456 callout_reset(&sc->fc->timeout_callout, hz,
451 (void *)firewire_watchdog, (void *)sc->fc);
457 firewire_watchdog, sc->fc);
452
453 /* create thread */
458
459 /* create thread */
454 kproc_create(fw_bus_probe_thread, (void *)fc, &fc->probe_thread,
455 0, 0, "fw%d_probe", unit);
460 kproc_create(fw_bus_probe_thread, fc, &fc->probe_thread,
461 0, 0, "fw%d_probe", unit);
456
457 /* Locate our children */
458 bus_generic_probe(dev);
459
460 /* launch attachement of the added children */
461 bus_generic_attach(dev);
462
463 /* bus_reset */

--- 6 unchanged lines hidden (view full) ---

470}
471
472/*
473 * Attach it as child.
474 */
475static device_t
476firewire_add_child(device_t dev, u_int order, const char *name, int unit)
477{
462
463 /* Locate our children */
464 bus_generic_probe(dev);
465
466 /* launch attachement of the added children */
467 bus_generic_attach(dev);
468
469 /* bus_reset */

--- 6 unchanged lines hidden (view full) ---

476}
477
478/*
479 * Attach it as child.
480 */
481static device_t
482firewire_add_child(device_t dev, u_int order, const char *name, int unit)
483{
478 device_t child;
484 device_t child;
479 struct firewire_softc *sc;
480
485 struct firewire_softc *sc;
486
481 sc = (struct firewire_softc *)device_get_softc(dev);
487 sc = device_get_softc(dev);
482 child = device_add_child(dev, name, unit);
483 if (child) {
484 device_set_ivars(child, sc->fc);
485 device_probe_and_attach(child);
486 }
487
488 return child;
489}
490
491static int
492firewire_resume(device_t dev)
493{
494 struct firewire_softc *sc;
495
488 child = device_add_child(dev, name, unit);
489 if (child) {
490 device_set_ivars(child, sc->fc);
491 device_probe_and_attach(child);
492 }
493
494 return child;
495}
496
497static int
498firewire_resume(device_t dev)
499{
500 struct firewire_softc *sc;
501
496 sc = (struct firewire_softc *)device_get_softc(dev);
502 sc = device_get_softc(dev);
497 sc->fc->status = FWBUSNOTREADY;
503 sc->fc->status = FWBUSNOTREADY;
498
504
499 bus_generic_resume(dev);
500
505 bus_generic_resume(dev);
506
501 return(0);
507 return (0);
502}
503
504/*
508}
509
510/*
505 * Dettach it.
511 * Detach it.
506 */
507static int
508firewire_detach(device_t dev)
509{
510 struct firewire_softc *sc;
511 struct firewire_comm *fc;
512 struct fw_device *fwdev, *fwdev_next;
513 int err;
514
512 */
513static int
514firewire_detach(device_t dev)
515{
516 struct firewire_softc *sc;
517 struct firewire_comm *fc;
518 struct fw_device *fwdev, *fwdev_next;
519 int err;
520
515 sc = (struct firewire_softc *)device_get_softc(dev);
521 sc = device_get_softc(dev);
516 fc = sc->fc;
517 mtx_lock(&fc->wait_lock);
518 fc->status = FWBUSDETACH;
519 wakeup(fc);
520 if (msleep(fc->probe_thread, &fc->wait_lock, PWAIT, "fwthr", hz * 60))
521 printf("firewire probe thread didn't die\n");
522 mtx_unlock(&fc->wait_lock);
523
522 fc = sc->fc;
523 mtx_lock(&fc->wait_lock);
524 fc->status = FWBUSDETACH;
525 wakeup(fc);
526 if (msleep(fc->probe_thread, &fc->wait_lock, PWAIT, "fwthr", hz * 60))
527 printf("firewire probe thread didn't die\n");
528 mtx_unlock(&fc->wait_lock);
529
524 if (fc->arq !=0 && fc->arq->maxq > 0)
530 if (fc->arq != 0 && fc->arq->maxq > 0)
525 fw_drain_txq(fc);
526
527 if ((err = fwdev_destroydev(sc)) != 0)
528 return err;
529
530 if ((err = bus_generic_detach(dev)) != 0)
531 return err;
532
533 callout_stop(&fc->timeout_callout);
534 callout_stop(&fc->bmr_callout);
535 callout_stop(&fc->busprobe_callout);
536
537 /* XXX xfer_free and untimeout on all xfers */
538 for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL;
531 fw_drain_txq(fc);
532
533 if ((err = fwdev_destroydev(sc)) != 0)
534 return err;
535
536 if ((err = bus_generic_detach(dev)) != 0)
537 return err;
538
539 callout_stop(&fc->timeout_callout);
540 callout_stop(&fc->bmr_callout);
541 callout_stop(&fc->busprobe_callout);
542
543 /* XXX xfer_free and untimeout on all xfers */
544 for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL;
539 fwdev = fwdev_next) {
545 fwdev = fwdev_next) {
540 fwdev_next = STAILQ_NEXT(fwdev, link);
541 free(fwdev, M_FW);
542 }
543 free(fc->topology_map, M_FW);
544 free(fc->speed_map, M_FW);
545 free(fc->crom_src_buf, M_FW);
546
547 mtx_destroy(&fc->tlabel_lock);
548 mtx_destroy(&fc->wait_lock);
546 fwdev_next = STAILQ_NEXT(fwdev, link);
547 free(fwdev, M_FW);
548 }
549 free(fc->topology_map, M_FW);
550 free(fc->speed_map, M_FW);
551 free(fc->crom_src_buf, M_FW);
552
553 mtx_destroy(&fc->tlabel_lock);
554 mtx_destroy(&fc->wait_lock);
549 return(0);
555 return (0);
550}
551
552static void
553fw_xferq_drain(struct fw_xferq *xferq)
554{
555 struct fw_xfer *xfer;
556
557 while ((xfer = STAILQ_FIRST(&xferq->q)) != NULL) {
558 STAILQ_REMOVE_HEAD(&xferq->q, link);
559#if 0
556}
557
558static void
559fw_xferq_drain(struct fw_xferq *xferq)
560{
561 struct fw_xfer *xfer;
562
563 while ((xfer = STAILQ_FIRST(&xferq->q)) != NULL) {
564 STAILQ_REMOVE_HEAD(&xferq->q, link);
565#if 0
560 xferq->queued --;
566 xferq->queued--;
561#endif
562 xfer->resp = EAGAIN;
563 xfer->flag = FWXF_SENTERR;
564 fw_xfer_done(xfer);
565 }
566}
567
568void
569fw_drain_txq(struct firewire_comm *fc)
570{
571 struct fw_xfer *xfer, *txfer;
572 STAILQ_HEAD(, fw_xfer) xfer_drain;
573 int i;
574
575 STAILQ_INIT(&xfer_drain);
576
577 FW_GLOCK(fc);
578 fw_xferq_drain(fc->atq);
579 fw_xferq_drain(fc->ats);
567#endif
568 xfer->resp = EAGAIN;
569 xfer->flag = FWXF_SENTERR;
570 fw_xfer_done(xfer);
571 }
572}
573
574void
575fw_drain_txq(struct firewire_comm *fc)
576{
577 struct fw_xfer *xfer, *txfer;
578 STAILQ_HEAD(, fw_xfer) xfer_drain;
579 int i;
580
581 STAILQ_INIT(&xfer_drain);
582
583 FW_GLOCK(fc);
584 fw_xferq_drain(fc->atq);
585 fw_xferq_drain(fc->ats);
580 for(i = 0; i < fc->nisodma; i++)
586 for (i = 0; i < fc->nisodma; i++)
581 fw_xferq_drain(fc->it[i]);
582 FW_GUNLOCK(fc);
583
584 mtx_lock(&fc->tlabel_lock);
587 fw_xferq_drain(fc->it[i]);
588 FW_GUNLOCK(fc);
589
590 mtx_lock(&fc->tlabel_lock);
585 for (i = 0; i < 0x40; i ++)
591 for (i = 0; i < 0x40; i++)
586 while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
587 if (firewire_debug)
588 printf("tl=%d flag=%d\n", i, xfer->flag);
589 xfer->tl = -1;
590 xfer->resp = EAGAIN;
591 STAILQ_REMOVE_HEAD(&fc->tlabels[i], tlabel);
592 STAILQ_INSERT_TAIL(&xfer_drain, xfer, tlabel);
593 }
594 mtx_unlock(&fc->tlabel_lock);
595
596 STAILQ_FOREACH_SAFE(xfer, &xfer_drain, tlabel, txfer)
592 while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
593 if (firewire_debug)
594 printf("tl=%d flag=%d\n", i, xfer->flag);
595 xfer->tl = -1;
596 xfer->resp = EAGAIN;
597 STAILQ_REMOVE_HEAD(&fc->tlabels[i], tlabel);
598 STAILQ_INSERT_TAIL(&xfer_drain, xfer, tlabel);
599 }
600 mtx_unlock(&fc->tlabel_lock);
601
602 STAILQ_FOREACH_SAFE(xfer, &xfer_drain, tlabel, txfer)
597 xfer->hand(xfer);
603 xfer->hand(xfer);
598}
599
600static void
601fw_reset_csr(struct firewire_comm *fc)
602{
603 int i;
604
605 CSRARC(fc, STATE_CLEAR)
604}
605
606static void
607fw_reset_csr(struct firewire_comm *fc)
608{
609 int i;
610
611 CSRARC(fc, STATE_CLEAR)
606 = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14 ;
612 = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14;
607 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
608 CSRARC(fc, NODE_IDS) = 0x3f;
609
610 CSRARC(fc, TOPO_MAP + 8) = 0;
611 fc->irm = -1;
612
613 fc->max_node = -1;
614
613 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
614 CSRARC(fc, NODE_IDS) = 0x3f;
615
616 CSRARC(fc, TOPO_MAP + 8) = 0;
617 fc->irm = -1;
618
619 fc->max_node = -1;
620
615 for(i = 2; i < 0x100/4 - 2 ; i++){
621 for (i = 2; i < 0x100 / 4 - 2; i++) {
616 CSRARC(fc, SPED_MAP + i * 4) = 0;
617 }
622 CSRARC(fc, SPED_MAP + i * 4) = 0;
623 }
618 CSRARC(fc, STATE_CLEAR) = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14 ;
624 CSRARC(fc, STATE_CLEAR) = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14;
619 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
620 CSRARC(fc, RESET_START) = 0;
621 CSRARC(fc, SPLIT_TIMEOUT_HI) = 0;
622 CSRARC(fc, SPLIT_TIMEOUT_LO) = 800 << 19;
623 CSRARC(fc, CYCLE_TIME) = 0x0;
624 CSRARC(fc, BUS_TIME) = 0x0;
625 CSRARC(fc, BUS_MGR_ID) = 0x3f;
626 CSRARC(fc, BANDWIDTH_AV) = 4915;
627 CSRARC(fc, CHANNELS_AV_HI) = 0xffffffff;
628 CSRARC(fc, CHANNELS_AV_LO) = 0xffffffff;
629 CSRARC(fc, IP_CHANNELS) = (1U << 31);
630
631 CSRARC(fc, CONF_ROM) = 0x04 << 24;
632 CSRARC(fc, CONF_ROM + 4) = 0x31333934; /* means strings 1394 */
633 CSRARC(fc, CONF_ROM + 8) = 1 << 31 | 1 << 30 | 1 << 29 |
625 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
626 CSRARC(fc, RESET_START) = 0;
627 CSRARC(fc, SPLIT_TIMEOUT_HI) = 0;
628 CSRARC(fc, SPLIT_TIMEOUT_LO) = 800 << 19;
629 CSRARC(fc, CYCLE_TIME) = 0x0;
630 CSRARC(fc, BUS_TIME) = 0x0;
631 CSRARC(fc, BUS_MGR_ID) = 0x3f;
632 CSRARC(fc, BANDWIDTH_AV) = 4915;
633 CSRARC(fc, CHANNELS_AV_HI) = 0xffffffff;
634 CSRARC(fc, CHANNELS_AV_LO) = 0xffffffff;
635 CSRARC(fc, IP_CHANNELS) = (1U << 31);
636
637 CSRARC(fc, CONF_ROM) = 0x04 << 24;
638 CSRARC(fc, CONF_ROM + 4) = 0x31333934; /* means strings 1394 */
639 CSRARC(fc, CONF_ROM + 8) = 1 << 31 | 1 << 30 | 1 << 29 |
634 1 << 28 | 0xff << 16 | 0x09 << 8;
640 1 << 28 | 0xff << 16 | 0x09 << 8;
635 CSRARC(fc, CONF_ROM + 0xc) = 0;
636
641 CSRARC(fc, CONF_ROM + 0xc) = 0;
642
637/* DV depend CSRs see blue book */
638 CSRARC(fc, oPCR) &= ~DV_BROADCAST_ON;
639 CSRARC(fc, iPCR) &= ~DV_BROADCAST_ON;
643 /* DV depend CSRs see blue book */
644 CSRARC(fc, oPCR) &= ~DV_BROADCAST_ON;
645 CSRARC(fc, iPCR) &= ~DV_BROADCAST_ON;
640
646
641 CSRARC(fc, STATE_CLEAR) &= ~(1 << 23 | 1 << 15 | 1 << 14 );
647 CSRARC(fc, STATE_CLEAR) &= ~(1 << 23 | 1 << 15 | 1 << 14);
642 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
643}
644
645static void
646fw_init_crom(struct firewire_comm *fc)
647{
648 struct crom_src *src;
649

--- 39 unchanged lines hidden (view full) ---

689
690 STAILQ_INIT(&src->chunk_list);
691
692 bzero(root, sizeof(struct crom_chunk));
693 crom_add_chunk(src, NULL, root, 0);
694 crom_add_entry(root, CSRKEY_NCAP, 0x0083c0); /* XXX */
695 /* private company_id */
696 crom_add_entry(root, CSRKEY_VENDOR, CSRVAL_VENDOR_PRIVATE);
648 CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
649}
650
651static void
652fw_init_crom(struct firewire_comm *fc)
653{
654 struct crom_src *src;
655

--- 39 unchanged lines hidden (view full) ---

695
696 STAILQ_INIT(&src->chunk_list);
697
698 bzero(root, sizeof(struct crom_chunk));
699 crom_add_chunk(src, NULL, root, 0);
700 crom_add_entry(root, CSRKEY_NCAP, 0x0083c0); /* XXX */
701 /* private company_id */
702 crom_add_entry(root, CSRKEY_VENDOR, CSRVAL_VENDOR_PRIVATE);
697#ifdef __DragonFly__
698 crom_add_simple_text(src, root, &buf->vendor, "DragonFly Project");
699 crom_add_entry(root, CSRKEY_HW, __DragonFly_cc_version);
700#else
701 crom_add_simple_text(src, root, &buf->vendor, "FreeBSD Project");
702 crom_add_entry(root, CSRKEY_HW, __FreeBSD_version);
703 crom_add_simple_text(src, root, &buf->vendor, "FreeBSD Project");
704 crom_add_entry(root, CSRKEY_HW, __FreeBSD_version);
703#endif
704 mtx_lock(&prison0.pr_mtx);
705 crom_add_simple_text(src, root, &buf->hw, prison0.pr_hostname);
706 mtx_unlock(&prison0.pr_mtx);
707}
708
709/*
710 * Called after bus reset.
711 */

--- 14 unchanged lines hidden (view full) ---

726 fw_reset_csr(fc);
727
728 if (fc->status == FWBUSNOTREADY)
729 fw_init_crom(fc);
730
731 fw_reset_crom(fc);
732
733 if (device_get_children(fc->bdev, &devlistp, &devcnt) == 0) {
705 mtx_lock(&prison0.pr_mtx);
706 crom_add_simple_text(src, root, &buf->hw, prison0.pr_hostname);
707 mtx_unlock(&prison0.pr_mtx);
708}
709
710/*
711 * Called after bus reset.
712 */

--- 14 unchanged lines hidden (view full) ---

727 fw_reset_csr(fc);
728
729 if (fc->status == FWBUSNOTREADY)
730 fw_init_crom(fc);
731
732 fw_reset_crom(fc);
733
734 if (device_get_children(fc->bdev, &devlistp, &devcnt) == 0) {
734 for( i = 0 ; i < devcnt ; i++)
735 if (device_get_state(devlistp[i]) >= DS_ATTACHED) {
735 for (i = 0; i < devcnt; i++)
736 if (device_get_state(devlistp[i]) >= DS_ATTACHED) {
736 fdc = device_get_softc(devlistp[i]);
737 if (fdc->post_busreset != NULL)
738 fdc->post_busreset(fdc);
739 }
740 free(devlistp, M_TEMP);
741 }
742
743 src = &fc->crom_src_buf->src;
737 fdc = device_get_softc(devlistp[i]);
738 if (fdc->post_busreset != NULL)
739 fdc->post_busreset(fdc);
740 }
741 free(devlistp, M_TEMP);
742 }
743
744 src = &fc->crom_src_buf->src;
744 /*
745 * If the old config rom needs to be overwritten,
746 * bump the businfo.generation indicator to
747 * indicate that we need to be reprobed
748 * See 1394a-2000 8.3.2.5.4 for more details.
749 * generation starts at 2 and rolls over at 0xF
750 * back to 2.
751 *
752 * A generation of 0 indicates a device
753 * that is not 1394a-2000 compliant.
754 * A generation of 1 indicates a device that
755 * does not change it's Bus Info Block or
756 * Configuration ROM.
757 */
745 /*
746 * If the old config rom needs to be overwritten,
747 * bump the businfo.generation indicator to
748 * indicate that we need to be reprobed
749 * See 1394a-2000 8.3.2.5.4 for more details.
750 * generation starts at 2 and rolls over at 0xF
751 * back to 2.
752 *
753 * A generation of 0 indicates a device
754 * that is not 1394a-2000 compliant.
755 * A generation of 1 indicates a device that
756 * does not change it's Bus Info Block or
757 * Configuration ROM.
758 */
758#define FW_MAX_GENERATION 0xF
759 newrom = malloc(CROMSIZE, M_FW, M_NOWAIT | M_ZERO);
760 src = &fc->crom_src_buf->src;
761 crom_load(src, newrom, CROMSIZE);
762 if (bcmp(newrom, fc->config_rom, CROMSIZE) != 0) {
759#define FW_MAX_GENERATION 0xF
760 newrom = malloc(CROMSIZE, M_FW, M_NOWAIT | M_ZERO);
761 src = &fc->crom_src_buf->src;
762 crom_load(src, newrom, CROMSIZE);
763 if (bcmp(newrom, fc->config_rom, CROMSIZE) != 0) {
763 if ( src->businfo.generation++ > FW_MAX_GENERATION )
764 if (src->businfo.generation++ > FW_MAX_GENERATION)
764 src->businfo.generation = FW_GENERATION_CHANGEABLE;
765 src->businfo.generation = FW_GENERATION_CHANGEABLE;
765 bcopy(newrom, (void *)fc->config_rom, CROMSIZE);
766 bcopy(newrom, fc->config_rom, CROMSIZE);
766 }
767 free(newrom, M_FW);
767 }
768 free(newrom, M_FW);
768
769}
770
771/* Call once after reboot */
772void fw_init(struct firewire_comm *fc)
773{
774 int i;
775#ifdef FW_VMACCESS
776 struct fw_xfer *xfer;

--- 13 unchanged lines hidden (view full) ---

790 fc->arq->flag = 0;
791 fc->ars->flag = 0;
792 fc->atq->flag = 0;
793 fc->ats->flag = 0;
794
795 STAILQ_INIT(&fc->atq->q);
796 STAILQ_INIT(&fc->ats->q);
797
769}
770
771/* Call once after reboot */
772void fw_init(struct firewire_comm *fc)
773{
774 int i;
775#ifdef FW_VMACCESS
776 struct fw_xfer *xfer;

--- 13 unchanged lines hidden (view full) ---

790 fc->arq->flag = 0;
791 fc->ars->flag = 0;
792 fc->atq->flag = 0;
793 fc->ats->flag = 0;
794
795 STAILQ_INIT(&fc->atq->q);
796 STAILQ_INIT(&fc->ats->q);
797
798 for( i = 0 ; i < fc->nisodma ; i ++ ){
798 for (i = 0; i < fc->nisodma; i++) {
799 fc->it[i]->queued = 0;
800 fc->ir[i]->queued = 0;
801
802 fc->it[i]->start = NULL;
803 fc->ir[i]->start = NULL;
804
805 fc->it[i]->buf = NULL;
806 fc->ir[i]->buf = NULL;

--- 5 unchanged lines hidden (view full) ---

812 STAILQ_INIT(&fc->ir[i]->q);
813 }
814
815 fc->arq->maxq = FWMAXQUEUE;
816 fc->ars->maxq = FWMAXQUEUE;
817 fc->atq->maxq = FWMAXQUEUE;
818 fc->ats->maxq = FWMAXQUEUE;
819
799 fc->it[i]->queued = 0;
800 fc->ir[i]->queued = 0;
801
802 fc->it[i]->start = NULL;
803 fc->ir[i]->start = NULL;
804
805 fc->it[i]->buf = NULL;
806 fc->ir[i]->buf = NULL;

--- 5 unchanged lines hidden (view full) ---

812 STAILQ_INIT(&fc->ir[i]->q);
813 }
814
815 fc->arq->maxq = FWMAXQUEUE;
816 fc->ars->maxq = FWMAXQUEUE;
817 fc->atq->maxq = FWMAXQUEUE;
818 fc->ats->maxq = FWMAXQUEUE;
819
820 for( i = 0 ; i < fc->nisodma ; i++){
820 for (i = 0; i < fc->nisodma; i++) {
821 fc->ir[i]->maxq = FWMAXQUEUE;
822 fc->it[i]->maxq = FWMAXQUEUE;
823 }
824
825 CSRARC(fc, TOPO_MAP) = 0x3f1 << 16;
826 CSRARC(fc, TOPO_MAP + 4) = 1;
827 CSRARC(fc, SPED_MAP) = 0x3f1 << 16;
828 CSRARC(fc, SPED_MAP + 4) = 1;
829
830 STAILQ_INIT(&fc->devices);
831
821 fc->ir[i]->maxq = FWMAXQUEUE;
822 fc->it[i]->maxq = FWMAXQUEUE;
823 }
824
825 CSRARC(fc, TOPO_MAP) = 0x3f1 << 16;
826 CSRARC(fc, TOPO_MAP + 4) = 1;
827 CSRARC(fc, SPED_MAP) = 0x3f1 << 16;
828 CSRARC(fc, SPED_MAP + 4) = 1;
829
830 STAILQ_INIT(&fc->devices);
831
832/* Initialize Async handlers */
832 /* Initialize Async handlers */
833 STAILQ_INIT(&fc->binds);
833 STAILQ_INIT(&fc->binds);
834 for( i = 0 ; i < 0x40 ; i++){
834 for (i = 0; i < 0x40; i++) {
835 STAILQ_INIT(&fc->tlabels[i]);
836 }
837
838/* DV depend CSRs see blue book */
839#if 0
840 CSRARC(fc, oMPR) = 0x3fff0001; /* # output channel = 1 */
841 CSRARC(fc, oPCR) = 0x8000007a;
835 STAILQ_INIT(&fc->tlabels[i]);
836 }
837
838/* DV depend CSRs see blue book */
839#if 0
840 CSRARC(fc, oMPR) = 0x3fff0001; /* # output channel = 1 */
841 CSRARC(fc, oPCR) = 0x8000007a;
842 for(i = 4 ; i < 0x7c/4 ; i+=4){
843 CSRARC(fc, i + oPCR) = 0x8000007a;
842 for (i = 4; i < 0x7c/4; i += 4) {
843 CSRARC(fc, i + oPCR) = 0x8000007a;
844 }
844 }
845
845
846 CSRARC(fc, iMPR) = 0x00ff0001; /* # input channel = 1 */
847 CSRARC(fc, iPCR) = 0x803f0000;
846 CSRARC(fc, iMPR) = 0x00ff0001; /* # input channel = 1 */
847 CSRARC(fc, iPCR) = 0x803f0000;
848 for(i = 4 ; i < 0x7c/4 ; i+=4){
849 CSRARC(fc, i + iPCR) = 0x0;
848 for (i = 4; i < 0x7c/4; i += 4) {
849 CSRARC(fc, i + iPCR) = 0x0;
850 }
851#endif
852
853 fc->crom_src_buf = NULL;
854
855#ifdef FW_VMACCESS
856 xfer = fw_xfer_alloc();
850 }
851#endif
852
853 fc->crom_src_buf = NULL;
854
855#ifdef FW_VMACCESS
856 xfer = fw_xfer_alloc();
857 if(xfer == NULL) return;
857 if (xfer == NULL)
858 return;
858
859
859 fwb = (struct fw_bind *)malloc(sizeof (struct fw_bind), M_FW, M_NOWAIT);
860 if(fwb == NULL){
860 fwb = malloc(sizeof(struct fw_bind), M_FW, M_NOWAIT);
861 if (fwb == NULL) {
861 fw_xfer_free(xfer);
862 return;
863 }
864 xfer->hand = fw_vmaccess;
865 xfer->fc = fc;
866 xfer->sc = NULL;
867
868 fwb->start_hi = 0x2;
869 fwb->start_lo = 0;
870 fwb->addrlen = 0xffffffff;
871 fwb->xfer = xfer;
872 fw_bindadd(fc, fwb);
873#endif
874}
875
862 fw_xfer_free(xfer);
863 return;
864 }
865 xfer->hand = fw_vmaccess;
866 xfer->fc = fc;
867 xfer->sc = NULL;
868
869 fwb->start_hi = 0x2;
870 fwb->start_lo = 0;
871 fwb->addrlen = 0xffffffff;
872 fwb->xfer = xfer;
873 fw_bindadd(fc, fwb);
874#endif
875}
876
876#define BIND_CMP(addr, fwb) (((addr) < (fwb)->start)?-1:\
877 ((fwb)->end < (addr))?1:0)
877#define BIND_CMP(addr, fwb) (((addr) < (fwb)->start)? -1 : \
878 ((fwb)->end < (addr)) ? 1 : 0)
878
879/*
880 * To lookup bound process from IEEE1394 address.
881 */
882struct fw_bind *
883fw_bindlookup(struct firewire_comm *fc, uint16_t dest_hi, uint32_t dest_lo)
884{
885 u_int64_t addr;
886 struct fw_bind *tfw, *r = NULL;
887
888 addr = ((u_int64_t)dest_hi << 32) | dest_lo;
889 FW_GLOCK(fc);
890 STAILQ_FOREACH(tfw, &fc->binds, fclist)
891 if (BIND_CMP(addr, tfw) == 0) {
892 r = tfw;
893 break;
894 }
895 FW_GUNLOCK(fc);
879
880/*
881 * To lookup bound process from IEEE1394 address.
882 */
883struct fw_bind *
884fw_bindlookup(struct firewire_comm *fc, uint16_t dest_hi, uint32_t dest_lo)
885{
886 u_int64_t addr;
887 struct fw_bind *tfw, *r = NULL;
888
889 addr = ((u_int64_t)dest_hi << 32) | dest_lo;
890 FW_GLOCK(fc);
891 STAILQ_FOREACH(tfw, &fc->binds, fclist)
892 if (BIND_CMP(addr, tfw) == 0) {
893 r = tfw;
894 break;
895 }
896 FW_GUNLOCK(fc);
896 return(r);
897 return (r);
897}
898
899/*
900 * To bind IEEE1394 address block to process.
901 */
902int
903fw_bindadd(struct firewire_comm *fc, struct fw_bind *fwb)
904{

--- 68 unchanged lines hidden (view full) ---

973 struct firewire_comm *fc, void *sc, void (*hand)(struct fw_xfer *))
974{
975 int i, s;
976 struct fw_xfer *xfer;
977
978 for (i = 0; i < n; i++) {
979 xfer = fw_xfer_alloc_buf(type, slen, rlen);
980 if (xfer == NULL)
898}
899
900/*
901 * To bind IEEE1394 address block to process.
902 */
903int
904fw_bindadd(struct firewire_comm *fc, struct fw_bind *fwb)
905{

--- 68 unchanged lines hidden (view full) ---

974 struct firewire_comm *fc, void *sc, void (*hand)(struct fw_xfer *))
975{
976 int i, s;
977 struct fw_xfer *xfer;
978
979 for (i = 0; i < n; i++) {
980 xfer = fw_xfer_alloc_buf(type, slen, rlen);
981 if (xfer == NULL)
981 return (n);
982 return (i);
982 xfer->fc = fc;
983 xfer->sc = sc;
984 xfer->hand = hand;
985 s = splfw();
986 STAILQ_INSERT_TAIL(q, xfer, link);
987 splx(s);
988 }
989 return (n);
990}
991
992void
993fw_xferlist_remove(struct fw_xferlist *q)
994{
995 struct fw_xfer *xfer, *next;
996
997 for (xfer = STAILQ_FIRST(q); xfer != NULL; xfer = next) {
983 xfer->fc = fc;
984 xfer->sc = sc;
985 xfer->hand = hand;
986 s = splfw();
987 STAILQ_INSERT_TAIL(q, xfer, link);
988 splx(s);
989 }
990 return (n);
991}
992
993void
994fw_xferlist_remove(struct fw_xferlist *q)
995{
996 struct fw_xfer *xfer, *next;
997
998 for (xfer = STAILQ_FIRST(q); xfer != NULL; xfer = next) {
998 next = STAILQ_NEXT(xfer, link);
999 fw_xfer_free_buf(xfer);
1000 }
1001 STAILQ_INIT(q);
999 next = STAILQ_NEXT(xfer, link);
1000 fw_xfer_free_buf(xfer);
1001 }
1002 STAILQ_INIT(q);
1002}
1003/*
1004 * dump packet header
1005 */
1006static void
1007fw_dump_hdr(struct fw_pkt *fp, char *prefix)
1008{
1009 printf("%s: dst=0x%02x tl=0x%02x rt=%d tcode=0x%x pri=0x%x "

--- 16 unchanged lines hidden (view full) ---

1026 s = splfw();
1027 mtx_lock(&fc->tlabel_lock);
1028 if (xfer->tl < 0) {
1029 mtx_unlock(&fc->tlabel_lock);
1030 return;
1031 }
1032 /* make sure the label is allocated */
1033 STAILQ_FOREACH(txfer, &fc->tlabels[xfer->tl], tlabel)
1003}
1004/*
1005 * dump packet header
1006 */
1007static void
1008fw_dump_hdr(struct fw_pkt *fp, char *prefix)
1009{
1010 printf("%s: dst=0x%02x tl=0x%02x rt=%d tcode=0x%x pri=0x%x "

--- 16 unchanged lines hidden (view full) ---

1027 s = splfw();
1028 mtx_lock(&fc->tlabel_lock);
1029 if (xfer->tl < 0) {
1030 mtx_unlock(&fc->tlabel_lock);
1031 return;
1032 }
1033 /* make sure the label is allocated */
1034 STAILQ_FOREACH(txfer, &fc->tlabels[xfer->tl], tlabel)
1034 if(txfer == xfer)
1035 if (txfer == xfer)
1035 break;
1036 if (txfer == NULL) {
1037 printf("%s: the xfer is not in the queue "
1038 "(tlabel=%d, flag=0x%x)\n",
1039 __FUNCTION__, xfer->tl, xfer->flag);
1040 fw_dump_hdr(&xfer->send.hdr, "send");
1041 fw_dump_hdr(&xfer->recv.hdr, "recv");
1042 kdb_backtrace();

--- 16 unchanged lines hidden (view full) ---

1059fw_tl2xfer(struct firewire_comm *fc, int node, int tlabel, int tcode)
1060{
1061 struct fw_xfer *xfer;
1062 int s = splfw();
1063 int req;
1064
1065 mtx_lock(&fc->tlabel_lock);
1066 STAILQ_FOREACH(xfer, &fc->tlabels[tlabel], tlabel)
1036 break;
1037 if (txfer == NULL) {
1038 printf("%s: the xfer is not in the queue "
1039 "(tlabel=%d, flag=0x%x)\n",
1040 __FUNCTION__, xfer->tl, xfer->flag);
1041 fw_dump_hdr(&xfer->send.hdr, "send");
1042 fw_dump_hdr(&xfer->recv.hdr, "recv");
1043 kdb_backtrace();

--- 16 unchanged lines hidden (view full) ---

1060fw_tl2xfer(struct firewire_comm *fc, int node, int tlabel, int tcode)
1061{
1062 struct fw_xfer *xfer;
1063 int s = splfw();
1064 int req;
1065
1066 mtx_lock(&fc->tlabel_lock);
1067 STAILQ_FOREACH(xfer, &fc->tlabels[tlabel], tlabel)
1067 if(xfer->send.hdr.mode.hdr.dst == node) {
1068 if (xfer->send.hdr.mode.hdr.dst == node) {
1068 mtx_unlock(&fc->tlabel_lock);
1069 splx(s);
1070 KASSERT(xfer->tl == tlabel,
1071 ("xfer->tl 0x%x != 0x%x", xfer->tl, tlabel));
1072 /* extra sanity check */
1073 req = xfer->send.hdr.mode.hdr.tcode;
1074 if (xfer->fc->tcode[req].valid_res != tcode) {
1075 printf("%s: invalid response tcode "
1076 "(0x%x for 0x%x)\n", __FUNCTION__,
1077 tcode, req);
1069 mtx_unlock(&fc->tlabel_lock);
1070 splx(s);
1071 KASSERT(xfer->tl == tlabel,
1072 ("xfer->tl 0x%x != 0x%x", xfer->tl, tlabel));
1073 /* extra sanity check */
1074 req = xfer->send.hdr.mode.hdr.tcode;
1075 if (xfer->fc->tcode[req].valid_res != tcode) {
1076 printf("%s: invalid response tcode "
1077 "(0x%x for 0x%x)\n", __FUNCTION__,
1078 tcode, req);
1078 return(NULL);
1079 return (NULL);
1079 }
1080 }
1080
1081
1081 if (firewire_debug > 2)
1082 printf("fw_tl2xfer: found tl=%d\n", tlabel);
1082 if (firewire_debug > 2)
1083 printf("fw_tl2xfer: found tl=%d\n", tlabel);
1083 return(xfer);
1084 return (xfer);
1084 }
1085 mtx_unlock(&fc->tlabel_lock);
1086 if (firewire_debug > 1)
1087 printf("fw_tl2xfer: not found tl=%d\n", tlabel);
1088 splx(s);
1085 }
1086 mtx_unlock(&fc->tlabel_lock);
1087 if (firewire_debug > 1)
1088 printf("fw_tl2xfer: not found tl=%d\n", tlabel);
1089 splx(s);
1089 return(NULL);
1090 return (NULL);
1090}
1091
1092/*
1093 * To allocate IEEE1394 XFER structure.
1094 */
1095struct fw_xfer *
1096fw_xfer_alloc(struct malloc_type *type)
1097{

--- 10 unchanged lines hidden (view full) ---

1108
1109struct fw_xfer *
1110fw_xfer_alloc_buf(struct malloc_type *type, int send_len, int recv_len)
1111{
1112 struct fw_xfer *xfer;
1113
1114 xfer = fw_xfer_alloc(type);
1115 if (xfer == NULL)
1091}
1092
1093/*
1094 * To allocate IEEE1394 XFER structure.
1095 */
1096struct fw_xfer *
1097fw_xfer_alloc(struct malloc_type *type)
1098{

--- 10 unchanged lines hidden (view full) ---

1109
1110struct fw_xfer *
1111fw_xfer_alloc_buf(struct malloc_type *type, int send_len, int recv_len)
1112{
1113 struct fw_xfer *xfer;
1114
1115 xfer = fw_xfer_alloc(type);
1116 if (xfer == NULL)
1116 return(NULL);
1117 return (NULL);
1117 xfer->send.pay_len = send_len;
1118 xfer->recv.pay_len = recv_len;
1119 if (send_len > 0) {
1120 xfer->send.payload = malloc(send_len, type, M_NOWAIT | M_ZERO);
1121 if (xfer->send.payload == NULL) {
1122 fw_xfer_free(xfer);
1118 xfer->send.pay_len = send_len;
1119 xfer->recv.pay_len = recv_len;
1120 if (send_len > 0) {
1121 xfer->send.payload = malloc(send_len, type, M_NOWAIT | M_ZERO);
1122 if (xfer->send.payload == NULL) {
1123 fw_xfer_free(xfer);
1123 return(NULL);
1124 return (NULL);
1124 }
1125 }
1126 if (recv_len > 0) {
1127 xfer->recv.payload = malloc(recv_len, type, M_NOWAIT);
1128 if (xfer->recv.payload == NULL) {
1129 if (xfer->send.payload != NULL)
1130 free(xfer->send.payload, type);
1131 fw_xfer_free(xfer);
1125 }
1126 }
1127 if (recv_len > 0) {
1128 xfer->recv.payload = malloc(recv_len, type, M_NOWAIT);
1129 if (xfer->recv.payload == NULL) {
1130 if (xfer->send.payload != NULL)
1131 free(xfer->send.payload, type);
1132 fw_xfer_free(xfer);
1132 return(NULL);
1133 return (NULL);
1133 }
1134 }
1134 }
1135 }
1135 return(xfer);
1136 return (xfer);
1136}
1137
1138/*
1139 * IEEE1394 XFER post process.
1140 */
1141void
1142fw_xfer_done(struct fw_xfer *xfer)
1143{

--- 5 unchanged lines hidden (view full) ---

1149 if (xfer->fc == NULL)
1150 panic("fw_xfer_done: why xfer->fc is NULL?");
1151
1152 fw_tl_free(xfer->fc, xfer);
1153 xfer->hand(xfer);
1154}
1155
1156void
1137}
1138
1139/*
1140 * IEEE1394 XFER post process.
1141 */
1142void
1143fw_xfer_done(struct fw_xfer *xfer)
1144{

--- 5 unchanged lines hidden (view full) ---

1150 if (xfer->fc == NULL)
1151 panic("fw_xfer_done: why xfer->fc is NULL?");
1152
1153 fw_tl_free(xfer->fc, xfer);
1154 xfer->hand(xfer);
1155}
1156
1157void
1157fw_xfer_unload(struct fw_xfer* xfer)
1158fw_xfer_unload(struct fw_xfer *xfer)
1158{
1159 int s;
1160
1159{
1160 int s;
1161
1161 if(xfer == NULL ) return;
1162 if(xfer->flag & FWXF_INQ){
1162 if (xfer == NULL)
1163 return;
1164 if (xfer->flag & FWXF_INQ) {
1163 printf("fw_xfer_free FWXF_INQ\n");
1164 s = splfw();
1165 FW_GLOCK(xfer->fc);
1166 STAILQ_REMOVE(&xfer->q->q, xfer, fw_xfer, link);
1167#if 0
1165 printf("fw_xfer_free FWXF_INQ\n");
1166 s = splfw();
1167 FW_GLOCK(xfer->fc);
1168 STAILQ_REMOVE(&xfer->q->q, xfer, fw_xfer, link);
1169#if 0
1168 xfer->q->queued --;
1170 xfer->q->queued--;
1169#endif
1170 FW_GUNLOCK(xfer->fc);
1171 splx(s);
1172 }
1173 if (xfer->fc != NULL) {
1174 /*
1175 * Ensure that any tlabel owner can't access this
1176 * xfer after it's freed.
1177 */
1178 fw_tl_free(xfer->fc, xfer);
1179#if 1
1171#endif
1172 FW_GUNLOCK(xfer->fc);
1173 splx(s);
1174 }
1175 if (xfer->fc != NULL) {
1176 /*
1177 * Ensure that any tlabel owner can't access this
1178 * xfer after it's freed.
1179 */
1180 fw_tl_free(xfer->fc, xfer);
1181#if 1
1180 if(xfer->flag & FWXF_START)
1182 if (xfer->flag & FWXF_START)
1181 /*
1182 * This could happen if:
1183 * 1. We call fwohci_arcv() before fwohci_txd().
1184 * 2. firewire_watch() is called.
1185 */
1186 printf("fw_xfer_free FWXF_START\n");
1187#endif
1188 }
1189 xfer->flag = FWXF_INIT;
1190 xfer->resp = 0;
1191}
1183 /*
1184 * This could happen if:
1185 * 1. We call fwohci_arcv() before fwohci_txd().
1186 * 2. firewire_watch() is called.
1187 */
1188 printf("fw_xfer_free FWXF_START\n");
1189#endif
1190 }
1191 xfer->flag = FWXF_INIT;
1192 xfer->resp = 0;
1193}
1194
1192/*
1195/*
1193 * To free IEEE1394 XFER structure.
1196 * To free IEEE1394 XFER structure.
1194 */
1195void
1197 */
1198void
1196fw_xfer_free_buf( struct fw_xfer* xfer)
1199fw_xfer_free_buf(struct fw_xfer *xfer)
1197{
1198 if (xfer == NULL) {
1199 printf("%s: xfer == NULL\n", __func__);
1200 return;
1201 }
1202 fw_xfer_unload(xfer);
1200{
1201 if (xfer == NULL) {
1202 printf("%s: xfer == NULL\n", __func__);
1203 return;
1204 }
1205 fw_xfer_unload(xfer);
1203 if(xfer->send.payload != NULL){
1206 if (xfer->send.payload != NULL)
1204 free(xfer->send.payload, xfer->malloc);
1207 free(xfer->send.payload, xfer->malloc);
1205 }
1206 if(xfer->recv.payload != NULL){
1208 if (xfer->recv.payload != NULL)
1207 free(xfer->recv.payload, xfer->malloc);
1209 free(xfer->recv.payload, xfer->malloc);
1208 }
1209 free(xfer, xfer->malloc);
1210}
1211
1212void
1210 free(xfer, xfer->malloc);
1211}
1212
1213void
1213fw_xfer_free( struct fw_xfer* xfer)
1214fw_xfer_free(struct fw_xfer *xfer)
1214{
1215 if (xfer == NULL) {
1216 printf("%s: xfer == NULL\n", __func__);
1217 return;
1218 }
1219 fw_xfer_unload(xfer);
1220 free(xfer, xfer->malloc);
1221}

--- 4 unchanged lines hidden (view full) ---

1226#if 0
1227 printf("asyreq done flag=0x%02x resp=%d\n",
1228 xfer->flag, xfer->resp);
1229#endif
1230 fw_xfer_free(xfer);
1231}
1232
1233/*
1215{
1216 if (xfer == NULL) {
1217 printf("%s: xfer == NULL\n", __func__);
1218 return;
1219 }
1220 fw_xfer_unload(xfer);
1221 free(xfer, xfer->malloc);
1222}

--- 4 unchanged lines hidden (view full) ---

1227#if 0
1228 printf("asyreq done flag=0x%02x resp=%d\n",
1229 xfer->flag, xfer->resp);
1230#endif
1231 fw_xfer_free(xfer);
1232}
1233
1234/*
1234 * To configure PHY.
1235 * To configure PHY.
1235 */
1236static void
1237fw_phy_config(struct firewire_comm *fc, int root_node, int gap_count)
1238{
1239 struct fw_xfer *xfer;
1240 struct fw_pkt *fp;
1241
1242 fc->status = FWBUSPHYCONF;
1243
1244 xfer = fw_xfer_alloc(M_FWXFER);
1245 if (xfer == NULL)
1246 return;
1247 xfer->fc = fc;
1248 xfer->hand = fw_asy_callback_free;
1249
1250 fp = &xfer->send.hdr;
1251 fp->mode.ld[1] = 0;
1252 if (root_node >= 0)
1236 */
1237static void
1238fw_phy_config(struct firewire_comm *fc, int root_node, int gap_count)
1239{
1240 struct fw_xfer *xfer;
1241 struct fw_pkt *fp;
1242
1243 fc->status = FWBUSPHYCONF;
1244
1245 xfer = fw_xfer_alloc(M_FWXFER);
1246 if (xfer == NULL)
1247 return;
1248 xfer->fc = fc;
1249 xfer->hand = fw_asy_callback_free;
1250
1251 fp = &xfer->send.hdr;
1252 fp->mode.ld[1] = 0;
1253 if (root_node >= 0)
1253 fp->mode.ld[1] |= (root_node & 0x3f) << 24 | 1 << 23;
1254 fp->mode.ld[1] |= (1 << 23) | (root_node & 0x3f) << 24;
1254 if (gap_count >= 0)
1255 if (gap_count >= 0)
1255 fp->mode.ld[1] |= 1 << 22 | (gap_count & 0x3f) << 16;
1256 fp->mode.ld[1] |= (1 << 22) | (gap_count & 0x3f) << 16;
1256 fp->mode.ld[2] = ~fp->mode.ld[1];
1257/* XXX Dangerous, how to pass PHY packet to device driver */
1258 fp->mode.common.tcode |= FWTCODE_PHY;
1259
1260 if (firewire_debug)
1261 device_printf(fc->bdev, "%s: root_node=%d gap_count=%d\n",
1262 __func__, root_node, gap_count);
1263 fw_asyreq(fc, -1, xfer);
1264}
1265
1266/*
1257 fp->mode.ld[2] = ~fp->mode.ld[1];
1258/* XXX Dangerous, how to pass PHY packet to device driver */
1259 fp->mode.common.tcode |= FWTCODE_PHY;
1260
1261 if (firewire_debug)
1262 device_printf(fc->bdev, "%s: root_node=%d gap_count=%d\n",
1263 __func__, root_node, gap_count);
1264 fw_asyreq(fc, -1, xfer);
1265}
1266
1267/*
1267 * Dump self ID.
1268 * Dump self ID.
1268 */
1269static void
1270fw_print_sid(uint32_t sid)
1271{
1272 union fw_self_id *s;
1273 s = (union fw_self_id *) &sid;
1269 */
1270static void
1271fw_print_sid(uint32_t sid)
1272{
1273 union fw_self_id *s;
1274 s = (union fw_self_id *) &sid;
1274 if ( s->p0.sequel ) {
1275 if ( s->p1.sequence_num == FW_SELF_ID_PAGE0 ) {
1275 if (s->p0.sequel) {
1276 if (s->p1.sequence_num == FW_SELF_ID_PAGE0) {
1276 printf("node:%d p3:%d p4:%d p5:%d p6:%d p7:%d"
1277 printf("node:%d p3:%d p4:%d p5:%d p6:%d p7:%d"
1277 "p8:%d p9:%d p10:%d\n",
1278 s->p1.phy_id, s->p1.port3, s->p1.port4,
1279 s->p1.port5, s->p1.port6, s->p1.port7,
1280 s->p1.port8, s->p1.port9, s->p1.port10);
1281 } else if (s->p2.sequence_num == FW_SELF_ID_PAGE1 ){
1278 "p8:%d p9:%d p10:%d\n",
1279 s->p1.phy_id, s->p1.port3, s->p1.port4,
1280 s->p1.port5, s->p1.port6, s->p1.port7,
1281 s->p1.port8, s->p1.port9, s->p1.port10);
1282 } else if (s->p2.sequence_num == FW_SELF_ID_PAGE1) {
1282 printf("node:%d p11:%d p12:%d p13:%d p14:%d p15:%d\n",
1283 printf("node:%d p11:%d p12:%d p13:%d p14:%d p15:%d\n",
1283 s->p2.phy_id, s->p2.port11, s->p2.port12,
1284 s->p2.port13, s->p2.port14, s->p2.port15);
1284 s->p2.phy_id, s->p2.port11, s->p2.port12,
1285 s->p2.port13, s->p2.port14, s->p2.port15);
1285 } else {
1286 printf("node:%d Unknown Self ID Page number %d\n",
1286 } else {
1287 printf("node:%d Unknown Self ID Page number %d\n",
1287 s->p1.phy_id, s->p1.sequence_num);
1288 s->p1.phy_id, s->p1.sequence_num);
1288 }
1289 } else {
1290 printf("node:%d link:%d gap:%d spd:%d con:%d pwr:%d"
1289 }
1290 } else {
1291 printf("node:%d link:%d gap:%d spd:%d con:%d pwr:%d"
1291 " p0:%d p1:%d p2:%d i:%d m:%d\n",
1292 s->p0.phy_id, s->p0.link_active, s->p0.gap_count,
1293 s->p0.phy_speed, s->p0.contender,
1294 s->p0.power_class, s->p0.port0, s->p0.port1,
1295 s->p0.port2, s->p0.initiated_reset, s->p0.more_packets);
1292 " p0:%d p1:%d p2:%d i:%d m:%d\n",
1293 s->p0.phy_id, s->p0.link_active, s->p0.gap_count,
1294 s->p0.phy_speed, s->p0.contender,
1295 s->p0.power_class, s->p0.port0, s->p0.port1,
1296 s->p0.port2, s->p0.initiated_reset, s->p0.more_packets);
1296 }
1297}
1298
1299/*
1297 }
1298}
1299
1300/*
1300 * To receive self ID.
1301 * To receive self ID.
1301 */
1302 */
1302void fw_sidrcv(struct firewire_comm* fc, uint32_t *sid, u_int len)
1303void fw_sidrcv(struct firewire_comm *fc, uint32_t *sid, u_int len)
1303{
1304 uint32_t *p;
1305 union fw_self_id *self_id;
1306 u_int i, j, node, c_port = 0, i_branch = 0;
1307
1304{
1305 uint32_t *p;
1306 union fw_self_id *self_id;
1307 u_int i, j, node, c_port = 0, i_branch = 0;
1308
1308 fc->sid_cnt = len /(sizeof(uint32_t) * 2);
1309 fc->sid_cnt = len / (sizeof(uint32_t) * 2);
1309 fc->max_node = fc->nodeid & 0x3f;
1310 CSRARC(fc, NODE_IDS) = ((uint32_t)fc->nodeid) << 16;
1311 fc->status = FWBUSCYMELECT;
1312 fc->topology_map->crc_len = 2;
1310 fc->max_node = fc->nodeid & 0x3f;
1311 CSRARC(fc, NODE_IDS) = ((uint32_t)fc->nodeid) << 16;
1312 fc->status = FWBUSCYMELECT;
1313 fc->topology_map->crc_len = 2;
1313 fc->topology_map->generation ++;
1314 fc->topology_map->generation++;
1314 fc->topology_map->self_id_count = 0;
1315 fc->topology_map->self_id_count = 0;
1315 fc->topology_map->node_count = 0;
1316 fc->speed_map->generation ++;
1317 fc->speed_map->crc_len = 1 + (64*64 + 3) / 4;
1316 fc->topology_map->node_count= 0;
1317 fc->speed_map->generation++;
1318 fc->speed_map->crc_len = 1 + (64 * 64 + 3) / 4;
1318 self_id = &fc->topology_map->self_id[0];
1319 self_id = &fc->topology_map->self_id[0];
1319 for(i = 0; i < fc->sid_cnt; i ++){
1320 for (i = 0; i < fc->sid_cnt; i++) {
1320 if (sid[1] != ~sid[0]) {
1321 if (sid[1] != ~sid[0]) {
1321 device_printf(fc->bdev, "%s: ERROR invalid self-id packet\n",
1322 __func__);
1322 device_printf(fc->bdev,
1323 "%s: ERROR invalid self-id packet\n", __func__);
1323 sid += 2;
1324 continue;
1325 }
1326 *self_id = *((union fw_self_id *)sid);
1327 fc->topology_map->crc_len++;
1324 sid += 2;
1325 continue;
1326 }
1327 *self_id = *((union fw_self_id *)sid);
1328 fc->topology_map->crc_len++;
1328 if(self_id->p0.sequel == 0){
1329 fc->topology_map->node_count ++;
1329 if (self_id->p0.sequel == 0) {
1330 fc->topology_map->node_count++;
1330 c_port = 0;
1331 if (firewire_debug)
1332 fw_print_sid(sid[0]);
1333 node = self_id->p0.phy_id;
1331 c_port = 0;
1332 if (firewire_debug)
1333 fw_print_sid(sid[0]);
1334 node = self_id->p0.phy_id;
1334 if(fc->max_node < node){
1335 if (fc->max_node < node)
1335 fc->max_node = self_id->p0.phy_id;
1336 fc->max_node = self_id->p0.phy_id;
1336 }
1337 /* XXX I'm not sure this is the right speed_map */
1337 /* XXX I'm not sure this is the right speed_map */
1338 fc->speed_map->speed[node][node]
1339 = self_id->p0.phy_speed;
1340 for (j = 0; j < node; j ++) {
1341 fc->speed_map->speed[j][node]
1342 = fc->speed_map->speed[node][j]
1343 = min(fc->speed_map->speed[j][j],
1344 self_id->p0.phy_speed);
1338 fc->speed_map->speed[node][node] =
1339 self_id->p0.phy_speed;
1340 for (j = 0; j < node; j++) {
1341 fc->speed_map->speed[j][node] =
1342 fc->speed_map->speed[node][j] =
1343 min(fc->speed_map->speed[j][j],
1344 self_id->p0.phy_speed);
1345 }
1346 if ((fc->irm == -1 || self_id->p0.phy_id > fc->irm) &&
1345 }
1346 if ((fc->irm == -1 || self_id->p0.phy_id > fc->irm) &&
1347 (self_id->p0.link_active && self_id->p0.contender)) {
1347 (self_id->p0.link_active && self_id->p0.contender))
1348 fc->irm = self_id->p0.phy_id;
1348 fc->irm = self_id->p0.phy_id;
1349 }
1350 if(self_id->p0.port0 >= 0x2){
1349 if (self_id->p0.port0 >= 0x2)
1351 c_port++;
1350 c_port++;
1352 }
1353 if(self_id->p0.port1 >= 0x2){
1351 if (self_id->p0.port1 >= 0x2)
1354 c_port++;
1352 c_port++;
1355 }
1356 if(self_id->p0.port2 >= 0x2){
1353 if (self_id->p0.port2 >= 0x2)
1357 c_port++;
1354 c_port++;
1358 }
1359 }
1355 }
1360 if(c_port > 2){
1356 if (c_port > 2)
1361 i_branch += (c_port - 2);
1357 i_branch += (c_port - 2);
1362 }
1363 sid += 2;
1364 self_id++;
1358 sid += 2;
1359 self_id++;
1365 fc->topology_map->self_id_count ++;
1360 fc->topology_map->self_id_count++;
1366 }
1367 /* CRC */
1368 fc->topology_map->crc = fw_crc16(
1361 }
1362 /* CRC */
1363 fc->topology_map->crc = fw_crc16(
1369 (uint32_t *)&fc->topology_map->generation,
1370 fc->topology_map->crc_len * 4);
1364 (uint32_t *)&fc->topology_map->generation,
1365 fc->topology_map->crc_len * 4);
1371 fc->speed_map->crc = fw_crc16(
1366 fc->speed_map->crc = fw_crc16(
1372 (uint32_t *)&fc->speed_map->generation,
1373 fc->speed_map->crc_len * 4);
1367 (uint32_t *)&fc->speed_map->generation,
1368 fc->speed_map->crc_len * 4);
1374 /* byteswap and copy to CSR */
1375 p = (uint32_t *)fc->topology_map;
1376 for (i = 0; i <= fc->topology_map->crc_len; i++)
1377 CSRARC(fc, TOPO_MAP + i * 4) = htonl(*p++);
1378 p = (uint32_t *)fc->speed_map;
1379 CSRARC(fc, SPED_MAP) = htonl(*p++);
1380 CSRARC(fc, SPED_MAP + 4) = htonl(*p++);
1381 /* don't byte-swap uint8_t array */
1369 /* byteswap and copy to CSR */
1370 p = (uint32_t *)fc->topology_map;
1371 for (i = 0; i <= fc->topology_map->crc_len; i++)
1372 CSRARC(fc, TOPO_MAP + i * 4) = htonl(*p++);
1373 p = (uint32_t *)fc->speed_map;
1374 CSRARC(fc, SPED_MAP) = htonl(*p++);
1375 CSRARC(fc, SPED_MAP + 4) = htonl(*p++);
1376 /* don't byte-swap uint8_t array */
1382 bcopy(p, &CSRARC(fc, SPED_MAP + 8), (fc->speed_map->crc_len - 1)*4);
1377 bcopy(p, &CSRARC(fc, SPED_MAP + 8), (fc->speed_map->crc_len - 1) * 4);
1383
1384 fc->max_hop = fc->max_node - i_branch;
1385 device_printf(fc->bdev, "%d nodes, maxhop <= %d %s irm(%d) %s\n",
1378
1379 fc->max_hop = fc->max_node - i_branch;
1380 device_printf(fc->bdev, "%d nodes, maxhop <= %d %s irm(%d) %s\n",
1386 fc->max_node + 1, fc->max_hop,
1387 (fc->irm == -1) ? "Not IRM capable" : "cable IRM",
1388 fc->irm,
1389 (fc->irm == fc->nodeid) ? " (me) " : "");
1381 fc->max_node + 1, fc->max_hop,
1382 (fc->irm == -1) ? "Not IRM capable" : "cable IRM",
1383 fc->irm, (fc->irm == fc->nodeid) ? " (me) " : "");
1390
1391 if (try_bmr && (fc->irm != -1) && (CSRARC(fc, BUS_MGR_ID) == 0x3f)) {
1392 if (fc->irm == fc->nodeid) {
1393 fc->status = FWBUSMGRDONE;
1394 CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, fc->irm);
1395 fw_bmr(fc);
1396 } else {
1397 fc->status = FWBUSMGRELECT;
1384
1385 if (try_bmr && (fc->irm != -1) && (CSRARC(fc, BUS_MGR_ID) == 0x3f)) {
1386 if (fc->irm == fc->nodeid) {
1387 fc->status = FWBUSMGRDONE;
1388 CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, fc->irm);
1389 fw_bmr(fc);
1390 } else {
1391 fc->status = FWBUSMGRELECT;
1398 callout_reset(&fc->bmr_callout, hz/8,
1399 (void *)fw_try_bmr, (void *)fc);
1392 callout_reset(&fc->bmr_callout, hz / 8,
1393 fw_try_bmr, fc);
1400 }
1401 } else
1402 fc->status = FWBUSMGRDONE;
1403
1394 }
1395 } else
1396 fc->status = FWBUSMGRDONE;
1397
1404 callout_reset(&fc->busprobe_callout, hz/4,
1405 (void *)fw_bus_probe, (void *)fc);
1398 callout_reset(&fc->busprobe_callout, hz / 4, fw_bus_probe, fc);
1406}
1407
1408/*
1399}
1400
1401/*
1409 * To probe devices on the IEEE1394 bus.
1402 * To probe devices on the IEEE1394 bus.
1410 */
1411static void
1403 */
1404static void
1412fw_bus_probe(struct firewire_comm *fc)
1405fw_bus_probe(void *arg)
1413{
1406{
1414 int s;
1407 struct firewire_comm *fc;
1415 struct fw_device *fwdev;
1408 struct fw_device *fwdev;
1409 int s;
1416
1417 s = splfw();
1410
1411 s = splfw();
1412 fc = arg;
1418 fc->status = FWBUSEXPLORE;
1419
1420 /* Invalidate all devices, just after bus reset. */
1421 if (firewire_debug)
1422 device_printf(fc->bdev, "%s:"
1423 "iterate and invalidate all nodes\n",
1424 __func__);
1425 STAILQ_FOREACH(fwdev, &fc->devices, link)

--- 7 unchanged lines hidden (view full) ---

1433 } else {
1434 if (firewire_debug)
1435 device_printf(fc->bdev, "%s:"
1436 "Dev ID: %08x%08x already invalid\n",
1437 __func__, fwdev->eui.hi, fwdev->eui.lo);
1438 }
1439 splx(s);
1440
1413 fc->status = FWBUSEXPLORE;
1414
1415 /* Invalidate all devices, just after bus reset. */
1416 if (firewire_debug)
1417 device_printf(fc->bdev, "%s:"
1418 "iterate and invalidate all nodes\n",
1419 __func__);
1420 STAILQ_FOREACH(fwdev, &fc->devices, link)

--- 7 unchanged lines hidden (view full) ---

1428 } else {
1429 if (firewire_debug)
1430 device_printf(fc->bdev, "%s:"
1431 "Dev ID: %08x%08x already invalid\n",
1432 __func__, fwdev->eui.hi, fwdev->eui.lo);
1433 }
1434 splx(s);
1435
1441 wakeup((void *)fc);
1436 wakeup(fc);
1442}
1443
1444static int
1445fw_explore_read_quads(struct fw_device *fwdev, int offset,
1446 uint32_t *quad, int length)
1447{
1448 struct fw_xfer *xfer;
1449 uint32_t tmp;
1450 int i, error;
1451
1437}
1438
1439static int
1440fw_explore_read_quads(struct fw_device *fwdev, int offset,
1441 uint32_t *quad, int length)
1442{
1443 struct fw_xfer *xfer;
1444 uint32_t tmp;
1445 int i, error;
1446
1452 for (i = 0; i < length; i ++, offset += sizeof(uint32_t)) {
1453 xfer = fwmem_read_quad(fwdev, NULL, -1,
1454 0xffff, 0xf0000000 | offset, (void *)&tmp,
1455 fw_xferwake);
1447 for (i = 0; i < length; i++, offset += sizeof(uint32_t)) {
1448 xfer = fwmem_read_quad(fwdev, NULL, -1, 0xffff,
1449 0xf0000000 | offset, &tmp, fw_xferwake);
1456 if (xfer == NULL)
1457 return (-1);
1458 fw_xferwait(xfer);
1459
1460 if (xfer->resp == 0)
1461 quad[i] = ntohl(tmp);
1462
1463 error = xfer->resp;

--- 7 unchanged lines hidden (view full) ---

1471
1472static int
1473fw_explore_csrblock(struct fw_device *fwdev, int offset, int recur)
1474{
1475 int err, i, off;
1476 struct csrdirectory *dir;
1477 struct csrreg *reg;
1478
1450 if (xfer == NULL)
1451 return (-1);
1452 fw_xferwait(xfer);
1453
1454 if (xfer->resp == 0)
1455 quad[i] = ntohl(tmp);
1456
1457 error = xfer->resp;

--- 7 unchanged lines hidden (view full) ---

1465
1466static int
1467fw_explore_csrblock(struct fw_device *fwdev, int offset, int recur)
1468{
1469 int err, i, off;
1470 struct csrdirectory *dir;
1471 struct csrreg *reg;
1472
1479 dir = (struct csrdirectory *)&fwdev->csrrom[offset/sizeof(uint32_t)];
1473 dir = (struct csrdirectory *)&fwdev->csrrom[offset / sizeof(uint32_t)];
1480 err = fw_explore_read_quads(fwdev, CSRROMOFF + offset,
1481 (uint32_t *)dir, 1);
1482 if (err)
1483 return (-1);
1484
1485 offset += sizeof(uint32_t);
1474 err = fw_explore_read_quads(fwdev, CSRROMOFF + offset,
1475 (uint32_t *)dir, 1);
1476 if (err)
1477 return (-1);
1478
1479 offset += sizeof(uint32_t);
1486 reg = (struct csrreg *)&fwdev->csrrom[offset/sizeof(uint32_t)];
1480 reg = (struct csrreg *)&fwdev->csrrom[offset / sizeof(uint32_t)];
1487 err = fw_explore_read_quads(fwdev, CSRROMOFF + offset,
1488 (uint32_t *)reg, dir->crc_len);
1489 if (err)
1490 return (-1);
1491
1492 /* XXX check CRC */
1493
1494 off = CSRROMOFF + offset + sizeof(uint32_t) * (dir->crc_len - 1);
1495 if (fwdev->rommax < off)
1496 fwdev->rommax = off;
1497
1498 if (recur == 0)
1499 return (0);
1500
1481 err = fw_explore_read_quads(fwdev, CSRROMOFF + offset,
1482 (uint32_t *)reg, dir->crc_len);
1483 if (err)
1484 return (-1);
1485
1486 /* XXX check CRC */
1487
1488 off = CSRROMOFF + offset + sizeof(uint32_t) * (dir->crc_len - 1);
1489 if (fwdev->rommax < off)
1490 fwdev->rommax = off;
1491
1492 if (recur == 0)
1493 return (0);
1494
1501 for (i = 0; i < dir->crc_len; i ++, offset += sizeof(uint32_t)) {
1495 for (i = 0; i < dir->crc_len; i++, offset += sizeof(uint32_t)) {
1502 if ((reg[i].key & CSRTYPE_MASK) == CSRTYPE_D)
1503 recur = 1;
1504 else if ((reg[i].key & CSRTYPE_MASK) == CSRTYPE_L)
1505 recur = 0;
1506 else
1507 continue;
1508
1509 off = offset + reg[i].val * sizeof(uint32_t);
1510 if (off > CROMSIZE) {
1511 printf("%s: invalid offset %d\n", __FUNCTION__, off);
1496 if ((reg[i].key & CSRTYPE_MASK) == CSRTYPE_D)
1497 recur = 1;
1498 else if ((reg[i].key & CSRTYPE_MASK) == CSRTYPE_L)
1499 recur = 0;
1500 else
1501 continue;
1502
1503 off = offset + reg[i].val * sizeof(uint32_t);
1504 if (off > CROMSIZE) {
1505 printf("%s: invalid offset %d\n", __FUNCTION__, off);
1512 return(-1);
1506 return (-1);
1513 }
1514 err = fw_explore_csrblock(fwdev, off, recur);
1515 if (err)
1516 return (-1);
1517 }
1518 return (0);
1519}
1520

--- 16 unchanged lines hidden (view full) ---

1537 err = fw_explore_read_quads(dfwdev, CSRROMOFF, &csr[0], 1);
1538 if (err) {
1539 dfwdev->status = FWDEVINVAL;
1540 return (-1);
1541 }
1542 hdr = (struct csrhdr *)&csr[0];
1543 if (hdr->info_len != 4) {
1544 if (firewire_debug)
1507 }
1508 err = fw_explore_csrblock(fwdev, off, recur);
1509 if (err)
1510 return (-1);
1511 }
1512 return (0);
1513}
1514

--- 16 unchanged lines hidden (view full) ---

1531 err = fw_explore_read_quads(dfwdev, CSRROMOFF, &csr[0], 1);
1532 if (err) {
1533 dfwdev->status = FWDEVINVAL;
1534 return (-1);
1535 }
1536 hdr = (struct csrhdr *)&csr[0];
1537 if (hdr->info_len != 4) {
1538 if (firewire_debug)
1545 device_printf(fc->bdev, "%s: node%d: wrong bus info len(%d)\n",
1539 device_printf(fc->bdev,
1540 "%s: node%d: wrong bus info len(%d)\n",
1546 __func__, node, hdr->info_len);
1547 dfwdev->status = FWDEVINVAL;
1548 return (-1);
1549 }
1550
1551 /* bus info */
1552 err = fw_explore_read_quads(dfwdev, CSRROMOFF + 0x04, &csr[1], 4);
1553 if (err) {
1554 dfwdev->status = FWDEVINVAL;
1555 return (-1);
1556 }
1557 binfo = (struct bus_info *)&csr[1];
1558 if (binfo->bus_name != CSR_BUS_NAME_IEEE1394) {
1559 dfwdev->status = FWDEVINVAL;
1560 return (-1);
1561 }
1562
1563 if (firewire_debug)
1564 device_printf(fc->bdev, "%s: node(%d) BUS INFO BLOCK:\n"
1541 __func__, node, hdr->info_len);
1542 dfwdev->status = FWDEVINVAL;
1543 return (-1);
1544 }
1545
1546 /* bus info */
1547 err = fw_explore_read_quads(dfwdev, CSRROMOFF + 0x04, &csr[1], 4);
1548 if (err) {
1549 dfwdev->status = FWDEVINVAL;
1550 return (-1);
1551 }
1552 binfo = (struct bus_info *)&csr[1];
1553 if (binfo->bus_name != CSR_BUS_NAME_IEEE1394) {
1554 dfwdev->status = FWDEVINVAL;
1555 return (-1);
1556 }
1557
1558 if (firewire_debug)
1559 device_printf(fc->bdev, "%s: node(%d) BUS INFO BLOCK:\n"
1565 "irmc(%d) cmc(%d) isc(%d) bmc(%d) pmc(%d) "
1566 "cyc_clk_acc(%d) max_rec(%d) max_rom(%d) "
1567 "generation(%d) link_spd(%d)\n",
1568 __func__, node,
1569 binfo->irmc, binfo->cmc, binfo->isc,
1570 binfo->bmc, binfo->pmc, binfo->cyc_clk_acc,
1571 binfo->max_rec, binfo->max_rom,
1572 binfo->generation, binfo->link_spd);
1560 "irmc(%d) cmc(%d) isc(%d) bmc(%d) pmc(%d) "
1561 "cyc_clk_acc(%d) max_rec(%d) max_rom(%d) "
1562 "generation(%d) link_spd(%d)\n",
1563 __func__, node,
1564 binfo->irmc, binfo->cmc, binfo->isc,
1565 binfo->bmc, binfo->pmc, binfo->cyc_clk_acc,
1566 binfo->max_rec, binfo->max_rom,
1567 binfo->generation, binfo->link_spd);
1573
1574 STAILQ_FOREACH(fwdev, &fc->devices, link)
1575 if (FW_EUI64_EQUAL(fwdev->eui, binfo->eui64))
1576 break;
1577 if (fwdev == NULL) {
1578 /* new device */
1579 fwdev = malloc(sizeof(struct fw_device), M_FW,
1568
1569 STAILQ_FOREACH(fwdev, &fc->devices, link)
1570 if (FW_EUI64_EQUAL(fwdev->eui, binfo->eui64))
1571 break;
1572 if (fwdev == NULL) {
1573 /* new device */
1574 fwdev = malloc(sizeof(struct fw_device), M_FW,
1580 M_NOWAIT | M_ZERO);
1575 M_NOWAIT | M_ZERO);
1581 if (fwdev == NULL) {
1582 device_printf(fc->bdev, "%s: node%d: no memory\n",
1583 __func__, node);
1584 return (-1);
1585 }
1586 fwdev->fc = fc;
1587 fwdev->eui = binfo->eui64;
1588 fwdev->dst = dfwdev->dst;
1589 fwdev->maxrec = dfwdev->maxrec;
1590 fwdev->status = dfwdev->status;
1591
1592 /*
1593 * Pre-1394a-2000 didn't have link_spd in
1576 if (fwdev == NULL) {
1577 device_printf(fc->bdev, "%s: node%d: no memory\n",
1578 __func__, node);
1579 return (-1);
1580 }
1581 fwdev->fc = fc;
1582 fwdev->eui = binfo->eui64;
1583 fwdev->dst = dfwdev->dst;
1584 fwdev->maxrec = dfwdev->maxrec;
1585 fwdev->status = dfwdev->status;
1586
1587 /*
1588 * Pre-1394a-2000 didn't have link_spd in
1594 * the Bus Info block, so try and use the
1589 * the Bus Info block, so try and use the
1595 * speed map value.
1596 * 1394a-2000 compliant devices only use
1597 * the Bus Info Block link spd value, so
1598 * ignore the speed map alltogether. SWB
1599 */
1590 * speed map value.
1591 * 1394a-2000 compliant devices only use
1592 * the Bus Info Block link spd value, so
1593 * ignore the speed map alltogether. SWB
1594 */
1600 if ( binfo->link_spd == FWSPD_S100 /* 0 */) {
1595 if (binfo->link_spd == FWSPD_S100 /* 0 */) {
1601 device_printf(fc->bdev, "%s: "
1596 device_printf(fc->bdev, "%s: "
1602 "Pre 1394a-2000 detected\n",
1603 __func__);
1597 "Pre 1394a-2000 detected\n", __func__);
1604 fwdev->speed = fc->speed_map->speed[fc->nodeid][node];
1605 } else
1606 fwdev->speed = binfo->link_spd;
1607 /*
1608 * Test this speed with a read to the CSRROM.
1609 * If it fails, slow down the speed and retry.
1610 */
1611 while (fwdev->speed > FWSPD_S100 /* 0 */) {
1612 err = fw_explore_read_quads(fwdev, CSRROMOFF,
1598 fwdev->speed = fc->speed_map->speed[fc->nodeid][node];
1599 } else
1600 fwdev->speed = binfo->link_spd;
1601 /*
1602 * Test this speed with a read to the CSRROM.
1603 * If it fails, slow down the speed and retry.
1604 */
1605 while (fwdev->speed > FWSPD_S100 /* 0 */) {
1606 err = fw_explore_read_quads(fwdev, CSRROMOFF,
1613 &speed_test, 1);
1607 &speed_test, 1);
1614 if (err) {
1608 if (err) {
1615 device_printf(fc->bdev, "%s: fwdev->speed(%s)"
1616 " decremented due to negotiation\n",
1617 __func__,
1618 linkspeed[fwdev->speed]);
1609 device_printf(fc->bdev,
1610 "%s: fwdev->speed(%s) decremented due to negotiation\n",
1611 __func__, linkspeed[fwdev->speed]);
1619 fwdev->speed--;
1620 } else
1621 break;
1612 fwdev->speed--;
1613 } else
1614 break;
1622
1615
1623 }
1624
1625 /*
1616 }
1617
1618 /*
1626 * If the fwdev is not found in the
1619 * If the fwdev is not found in the
1627 * fc->devices TAILQ, then we will add it.
1628 */
1629 pfwdev = NULL;
1630 STAILQ_FOREACH(tfwdev, &fc->devices, link) {
1631 if (tfwdev->eui.hi > fwdev->eui.hi ||
1632 (tfwdev->eui.hi == fwdev->eui.hi &&
1633 tfwdev->eui.lo > fwdev->eui.lo))
1634 break;

--- 4 unchanged lines hidden (view full) ---

1639 else
1640 STAILQ_INSERT_AFTER(&fc->devices, pfwdev, fwdev, link);
1641 } else {
1642 fwdev->dst = node;
1643 fwdev->status = FWDEVINIT;
1644 /* unchanged ? */
1645 if (bcmp(&csr[0], &fwdev->csrrom[0], sizeof(uint32_t) * 5) == 0) {
1646 if (firewire_debug)
1620 * fc->devices TAILQ, then we will add it.
1621 */
1622 pfwdev = NULL;
1623 STAILQ_FOREACH(tfwdev, &fc->devices, link) {
1624 if (tfwdev->eui.hi > fwdev->eui.hi ||
1625 (tfwdev->eui.hi == fwdev->eui.hi &&
1626 tfwdev->eui.lo > fwdev->eui.lo))
1627 break;

--- 4 unchanged lines hidden (view full) ---

1632 else
1633 STAILQ_INSERT_AFTER(&fc->devices, pfwdev, fwdev, link);
1634 } else {
1635 fwdev->dst = node;
1636 fwdev->status = FWDEVINIT;
1637 /* unchanged ? */
1638 if (bcmp(&csr[0], &fwdev->csrrom[0], sizeof(uint32_t) * 5) == 0) {
1639 if (firewire_debug)
1647 device_printf(fc->dev, "node%d: crom unchanged\n", node);
1640 device_printf(fc->dev,
1641 "node%d: crom unchanged\n", node);
1648 return (0);
1649 }
1650 }
1651
1652 bzero(&fwdev->csrrom[0], CROMSIZE);
1653
1654 /* copy first quad and bus info block */
1655 bcopy(&csr[0], &fwdev->csrrom[0], sizeof(uint32_t) * 5);

--- 41 unchanged lines hidden (view full) ---

1697
1698 todo = 0;
1699 /* setup dummy fwdev */
1700 dfwdev.fc = fc;
1701 dfwdev.speed = 0;
1702 dfwdev.maxrec = 8; /* 512 */
1703 dfwdev.status = FWDEVINIT;
1704
1642 return (0);
1643 }
1644 }
1645
1646 bzero(&fwdev->csrrom[0], CROMSIZE);
1647
1648 /* copy first quad and bus info block */
1649 bcopy(&csr[0], &fwdev->csrrom[0], sizeof(uint32_t) * 5);

--- 41 unchanged lines hidden (view full) ---

1691
1692 todo = 0;
1693 /* setup dummy fwdev */
1694 dfwdev.fc = fc;
1695 dfwdev.speed = 0;
1696 dfwdev.maxrec = 8; /* 512 */
1697 dfwdev.status = FWDEVINIT;
1698
1705 for (node = 0; node <= fc->max_node; node ++) {
1699 for (node = 0; node <= fc->max_node; node++) {
1706 /* We don't probe myself and linkdown nodes */
1707 if (node == fc->nodeid) {
1708 if (firewire_debug)
1709 device_printf(fc->bdev, "%s:"
1700 /* We don't probe myself and linkdown nodes */
1701 if (node == fc->nodeid) {
1702 if (firewire_debug)
1703 device_printf(fc->bdev, "%s:"
1710 "found myself node(%d) fc->nodeid(%d) fc->max_node(%d)\n",
1711 __func__, node, fc->nodeid, fc->max_node);
1704 "found myself node(%d) fc->nodeid(%d) fc->max_node(%d)\n",
1705 __func__, node, fc->nodeid, fc->max_node);
1712 continue;
1713 } else if (firewire_debug) {
1714 device_printf(fc->bdev, "%s:"
1706 continue;
1707 } else if (firewire_debug) {
1708 device_printf(fc->bdev, "%s:"
1715 "node(%d) fc->max_node(%d) found\n",
1716 __func__, node, fc->max_node);
1709 "node(%d) fc->max_node(%d) found\n",
1710 __func__, node, fc->max_node);
1717 }
1718 fwsid = fw_find_self_id(fc, node);
1719 if (!fwsid || !fwsid->p0.link_active) {
1720 if (firewire_debug)
1711 }
1712 fwsid = fw_find_self_id(fc, node);
1713 if (!fwsid || !fwsid->p0.link_active) {
1714 if (firewire_debug)
1721 device_printf(fc->bdev, "%s: node%d: link down\n",
1722 __func__, node);
1715 device_printf(fc->bdev,
1716 "%s: node%d: link down\n",
1717 __func__, node);
1723 continue;
1724 }
1725 nodes[todo++] = node;
1726 }
1727
1728 s = splfw();
1718 continue;
1719 }
1720 nodes[todo++] = node;
1721 }
1722
1723 s = splfw();
1729 for (trys = 0; todo > 0 && trys < 3; trys ++) {
1724 for (trys = 0; todo > 0 && trys < 3; trys++) {
1730 todo2 = 0;
1725 todo2 = 0;
1731 for (i = 0; i < todo; i ++) {
1726 for (i = 0; i < todo; i++) {
1732 dfwdev.dst = nodes[i];
1733 err = fw_explore_node(&dfwdev);
1734 if (err)
1735 nodes[todo2++] = nodes[i];
1736 if (firewire_debug)
1727 dfwdev.dst = nodes[i];
1728 err = fw_explore_node(&dfwdev);
1729 if (err)
1730 nodes[todo2++] = nodes[i];
1731 if (firewire_debug)
1737 device_printf(fc->bdev, "%s: node %d, err = %d\n",
1738 __func__, node, err);
1732 device_printf(fc->bdev,
1733 "%s: node %d, err = %d\n",
1734 __func__, node, err);
1739 }
1740 todo = todo2;
1741 }
1742 splx(s);
1743}
1744
1735 }
1736 todo = todo2;
1737 }
1738 splx(s);
1739}
1740
1745
1746static void
1747fw_bus_probe_thread(void *arg)
1748{
1749 struct firewire_comm *fc;
1750
1741static void
1742fw_bus_probe_thread(void *arg)
1743{
1744 struct firewire_comm *fc;
1745
1751 fc = (struct firewire_comm *)arg;
1746 fc = arg;
1752
1753 mtx_lock(&fc->wait_lock);
1754 while (fc->status != FWBUSDETACH) {
1755 if (fc->status == FWBUSEXPLORE) {
1756 mtx_unlock(&fc->wait_lock);
1757 fw_explore(fc);
1758 fc->status = FWBUSEXPDONE;
1759 if (firewire_debug)

--- 19 unchanged lines hidden (view full) ---

1779 int devcnt;
1780 struct firewire_dev_comm *fdc;
1781
1782 for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL; fwdev = next) {
1783 next = STAILQ_NEXT(fwdev, link);
1784 if (fwdev->status == FWDEVINIT) {
1785 fwdev->status = FWDEVATTACHED;
1786 } else if (fwdev->status == FWDEVINVAL) {
1747
1748 mtx_lock(&fc->wait_lock);
1749 while (fc->status != FWBUSDETACH) {
1750 if (fc->status == FWBUSEXPLORE) {
1751 mtx_unlock(&fc->wait_lock);
1752 fw_explore(fc);
1753 fc->status = FWBUSEXPDONE;
1754 if (firewire_debug)

--- 19 unchanged lines hidden (view full) ---

1774 int devcnt;
1775 struct firewire_dev_comm *fdc;
1776
1777 for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL; fwdev = next) {
1778 next = STAILQ_NEXT(fwdev, link);
1779 if (fwdev->status == FWDEVINIT) {
1780 fwdev->status = FWDEVATTACHED;
1781 } else if (fwdev->status == FWDEVINVAL) {
1787 fwdev->rcnt ++;
1782 fwdev->rcnt++;
1788 if (firewire_debug)
1789 device_printf(fc->bdev, "%s:"
1783 if (firewire_debug)
1784 device_printf(fc->bdev, "%s:"
1790 "fwdev->rcnt(%d), hold_count(%d)\n",
1791 __func__, fwdev->rcnt, hold_count);
1785 "fwdev->rcnt(%d), hold_count(%d)\n",
1786 __func__, fwdev->rcnt, hold_count);
1792 if (fwdev->rcnt > hold_count) {
1793 /*
1794 * Remove devices which have not been seen
1795 * for a while.
1796 */
1797 STAILQ_REMOVE(&fc->devices, fwdev, fw_device,
1798 link);
1799 free(fwdev, M_FW);
1800 }
1801 }
1802 }
1803
1804 err = device_get_children(fc->bdev, &devlistp, &devcnt);
1787 if (fwdev->rcnt > hold_count) {
1788 /*
1789 * Remove devices which have not been seen
1790 * for a while.
1791 */
1792 STAILQ_REMOVE(&fc->devices, fwdev, fw_device,
1793 link);
1794 free(fwdev, M_FW);
1795 }
1796 }
1797 }
1798
1799 err = device_get_children(fc->bdev, &devlistp, &devcnt);
1805 if( err == 0 ) {
1806 for( i = 0 ; i < devcnt ; i++){
1807 if (device_get_state(devlistp[i]) >= DS_ATTACHED) {
1800 if (err == 0) {
1801 for (i = 0; i < devcnt; i++) {
1802 if (device_get_state(devlistp[i]) >= DS_ATTACHED) {
1808 fdc = device_get_softc(devlistp[i]);
1809 if (fdc->post_explore != NULL)
1810 fdc->post_explore(fdc);
1811 }
1812 }
1813 free(devlistp, M_TEMP);
1814 }
1815

--- 11 unchanged lines hidden (view full) ---

1827 int s;
1828
1829 dst = xfer->send.hdr.mode.hdr.dst & 0x3f;
1830 s = splfw();
1831 mtx_lock(&fc->tlabel_lock);
1832 new_tlabel = (fc->last_tlabel[dst] + 1) & 0x3f;
1833 STAILQ_FOREACH(txfer, &fc->tlabels[new_tlabel], tlabel)
1834 if ((txfer->send.hdr.mode.hdr.dst & 0x3f) == dst)
1803 fdc = device_get_softc(devlistp[i]);
1804 if (fdc->post_explore != NULL)
1805 fdc->post_explore(fdc);
1806 }
1807 }
1808 free(devlistp, M_TEMP);
1809 }
1810

--- 11 unchanged lines hidden (view full) ---

1822 int s;
1823
1824 dst = xfer->send.hdr.mode.hdr.dst & 0x3f;
1825 s = splfw();
1826 mtx_lock(&fc->tlabel_lock);
1827 new_tlabel = (fc->last_tlabel[dst] + 1) & 0x3f;
1828 STAILQ_FOREACH(txfer, &fc->tlabels[new_tlabel], tlabel)
1829 if ((txfer->send.hdr.mode.hdr.dst & 0x3f) == dst)
1835 break;
1836 if(txfer == NULL) {
1830 break;
1831 if (txfer == NULL) {
1837 fc->last_tlabel[dst] = new_tlabel;
1838 STAILQ_INSERT_TAIL(&fc->tlabels[new_tlabel], xfer, tlabel);
1839 mtx_unlock(&fc->tlabel_lock);
1840 splx(s);
1841 xfer->tl = new_tlabel;
1842 xfer->send.hdr.mode.hdr.tlrt = new_tlabel << 2;
1843 if (firewire_debug > 1)
1844 printf("fw_get_tlabel: dst=%d tl=%d\n", dst, new_tlabel);

--- 15 unchanged lines hidden (view full) ---

1860 struct tcode_info *tinfo;
1861 u_int res, i, len, plen;
1862
1863 rb->xfer->recv.spd = rb->spd;
1864
1865 pkt = (struct fw_pkt *)rb->vec->iov_base;
1866 tinfo = &rb->fc->tcode[pkt->mode.hdr.tcode];
1867
1832 fc->last_tlabel[dst] = new_tlabel;
1833 STAILQ_INSERT_TAIL(&fc->tlabels[new_tlabel], xfer, tlabel);
1834 mtx_unlock(&fc->tlabel_lock);
1835 splx(s);
1836 xfer->tl = new_tlabel;
1837 xfer->send.hdr.mode.hdr.tlrt = new_tlabel << 2;
1838 if (firewire_debug > 1)
1839 printf("fw_get_tlabel: dst=%d tl=%d\n", dst, new_tlabel);

--- 15 unchanged lines hidden (view full) ---

1855 struct tcode_info *tinfo;
1856 u_int res, i, len, plen;
1857
1858 rb->xfer->recv.spd = rb->spd;
1859
1860 pkt = (struct fw_pkt *)rb->vec->iov_base;
1861 tinfo = &rb->fc->tcode[pkt->mode.hdr.tcode];
1862
1868 /* Copy header */
1863 /* Copy header */
1869 p = (u_char *)&rb->xfer->recv.hdr;
1870 bcopy(rb->vec->iov_base, p, tinfo->hdr_len);
1871 rb->vec->iov_base = (u_char *)rb->vec->iov_base + tinfo->hdr_len;
1872 rb->vec->iov_len -= tinfo->hdr_len;
1873
1874 /* Copy payload */
1875 p = (u_char *)rb->xfer->recv.payload;
1876 res = rb->xfer->recv.pay_len;

--- 22 unchanged lines hidden (view full) ---

1899 bcopy(rb->vec->iov_base, p, len);
1900 p += len;
1901 res -= len;
1902 plen -= len;
1903 if (res == 0 || plen == 0)
1904 break;
1905 }
1906 rb->xfer->recv.pay_len -= res;
1864 p = (u_char *)&rb->xfer->recv.hdr;
1865 bcopy(rb->vec->iov_base, p, tinfo->hdr_len);
1866 rb->vec->iov_base = (u_char *)rb->vec->iov_base + tinfo->hdr_len;
1867 rb->vec->iov_len -= tinfo->hdr_len;
1868
1869 /* Copy payload */
1870 p = (u_char *)rb->xfer->recv.payload;
1871 res = rb->xfer->recv.pay_len;

--- 22 unchanged lines hidden (view full) ---

1894 bcopy(rb->vec->iov_base, p, len);
1895 p += len;
1896 res -= len;
1897 plen -= len;
1898 if (res == 0 || plen == 0)
1899 break;
1900 }
1901 rb->xfer->recv.pay_len -= res;
1907
1908}
1909
1910/*
1911 * Generic packet receiving process.
1912 */
1913void
1914fw_rcv(struct fw_rcv_buf *rb)
1915{
1916 struct fw_pkt *fp, *resfp;
1917 struct fw_bind *bind;
1918 int tcode;
1919 int i, len, oldstate;
1920#if 0
1921 {
1922 uint32_t *qld;
1923 int i;
1924 qld = (uint32_t *)buf;
1925 printf("spd %d len:%d\n", spd, len);
1902}
1903
1904/*
1905 * Generic packet receiving process.
1906 */
1907void
1908fw_rcv(struct fw_rcv_buf *rb)
1909{
1910 struct fw_pkt *fp, *resfp;
1911 struct fw_bind *bind;
1912 int tcode;
1913 int i, len, oldstate;
1914#if 0
1915 {
1916 uint32_t *qld;
1917 int i;
1918 qld = (uint32_t *)buf;
1919 printf("spd %d len:%d\n", spd, len);
1926 for( i = 0 ; i <= len && i < 32; i+= 4){
1920 for (i = 0; i <= len && i < 32; i+= 4) {
1927 printf("0x%08x ", ntohl(qld[i/4]));
1921 printf("0x%08x ", ntohl(qld[i/4]));
1928 if((i % 16) == 15) printf("\n");
1922 if ((i % 16) == 15) printf("\n");
1929 }
1923 }
1930 if((i % 16) != 15) printf("\n");
1924 if ((i % 16) != 15) printf("\n");
1931 }
1932#endif
1933 fp = (struct fw_pkt *)rb->vec[0].iov_base;
1934 tcode = fp->mode.common.tcode;
1935 switch (tcode) {
1936 case FWTCODE_WRES:
1937 case FWTCODE_RRESQ:
1938 case FWTCODE_RRESB:
1939 case FWTCODE_LRES:
1940 rb->xfer = fw_tl2xfer(rb->fc, fp->mode.hdr.src,
1941 fp->mode.hdr.tlrt >> 2, fp->mode.hdr.tcode);
1925 }
1926#endif
1927 fp = (struct fw_pkt *)rb->vec[0].iov_base;
1928 tcode = fp->mode.common.tcode;
1929 switch (tcode) {
1930 case FWTCODE_WRES:
1931 case FWTCODE_RRESQ:
1932 case FWTCODE_RRESB:
1933 case FWTCODE_LRES:
1934 rb->xfer = fw_tl2xfer(rb->fc, fp->mode.hdr.src,
1935 fp->mode.hdr.tlrt >> 2, fp->mode.hdr.tcode);
1942 if(rb->xfer == NULL) {
1943 device_printf(rb->fc->bdev, "%s: "
1944 "unknown response "
1945 "%s(%x) src=0x%x tl=0x%x rt=%d data=0x%x\n",
1946 __func__,
1947 tcode_str[tcode], tcode,
1948 fp->mode.hdr.src,
1949 fp->mode.hdr.tlrt >> 2,
1950 fp->mode.hdr.tlrt & 3,
1951 fp->mode.rresq.data);
1936 if (rb->xfer == NULL) {
1937 device_printf(rb->fc->bdev, "%s: unknown response "
1938 "%s(%x) src=0x%x tl=0x%x rt=%d data=0x%x\n",
1939 __func__,
1940 tcode_str[tcode], tcode,
1941 fp->mode.hdr.src,
1942 fp->mode.hdr.tlrt >> 2,
1943 fp->mode.hdr.tlrt & 3,
1944 fp->mode.rresq.data);
1952#if 0
1953 printf("try ad-hoc work around!!\n");
1954 rb->xfer = fw_tl2xfer(rb->fc, fp->mode.hdr.src,
1945#if 0
1946 printf("try ad-hoc work around!!\n");
1947 rb->xfer = fw_tl2xfer(rb->fc, fp->mode.hdr.src,
1955 (fp->mode.hdr.tlrt >> 2)^3);
1948 (fp->mode.hdr.tlrt >> 2)^3);
1956 if (rb->xfer == NULL) {
1957 printf("no use...\n");
1958 return;
1959 }
1960#else
1961 return;
1962#endif
1963 }

--- 12 unchanged lines hidden (view full) ---

1976 case FWXF_START:
1977#if 0
1978 if (firewire_debug)
1979 printf("not sent yet tl=%x\n", rb->xfer->tl);
1980#endif
1981 break;
1982 default:
1983 device_printf(rb->fc->bdev, "%s: "
1949 if (rb->xfer == NULL) {
1950 printf("no use...\n");
1951 return;
1952 }
1953#else
1954 return;
1955#endif
1956 }

--- 12 unchanged lines hidden (view full) ---

1969 case FWXF_START:
1970#if 0
1971 if (firewire_debug)
1972 printf("not sent yet tl=%x\n", rb->xfer->tl);
1973#endif
1974 break;
1975 default:
1976 device_printf(rb->fc->bdev, "%s: "
1984 "unexpected flag 0x%02x\n", __func__, rb->xfer->flag);
1977 "unexpected flag 0x%02x\n", __func__,
1978 rb->xfer->flag);
1985 }
1986 return;
1987 case FWTCODE_WREQQ:
1988 case FWTCODE_WREQB:
1989 case FWTCODE_RREQQ:
1990 case FWTCODE_RREQB:
1991 case FWTCODE_LREQ:
1992 bind = fw_bindlookup(rb->fc, fp->mode.rreqq.dest_hi,
1979 }
1980 return;
1981 case FWTCODE_WREQQ:
1982 case FWTCODE_WREQB:
1983 case FWTCODE_RREQQ:
1984 case FWTCODE_RREQB:
1985 case FWTCODE_LREQ:
1986 bind = fw_bindlookup(rb->fc, fp->mode.rreqq.dest_hi,
1993 fp->mode.rreqq.dest_lo);
1994 if(bind == NULL){
1987 fp->mode.rreqq.dest_lo);
1988 if (bind == NULL) {
1995 device_printf(rb->fc->bdev, "%s: "
1989 device_printf(rb->fc->bdev, "%s: "
1996 "Unknown service addr 0x%04x:0x%08x %s(%x)"
1997#if defined(__DragonFly__) || __FreeBSD_version < 500000
1998 " src=0x%x data=%lx\n",
1999#else
2000 " src=0x%x data=%x\n",
2001#endif
2002 __func__,
2003 fp->mode.wreqq.dest_hi,
2004 fp->mode.wreqq.dest_lo,
2005 tcode_str[tcode], tcode,
2006 fp->mode.hdr.src,
2007 ntohl(fp->mode.wreqq.data));
1990 "Unknown service addr 0x%04x:0x%08x %s(%x)"
1991 " src=0x%x data=%x\n",
1992 __func__,
1993 fp->mode.wreqq.dest_hi,
1994 fp->mode.wreqq.dest_lo,
1995 tcode_str[tcode], tcode,
1996 fp->mode.hdr.src,
1997 ntohl(fp->mode.wreqq.data));
2008
2009 if (rb->fc->status == FWBUSINIT) {
1998
1999 if (rb->fc->status == FWBUSINIT) {
2010 device_printf(rb->fc->bdev, "%s: cannot respond(bus reset)!\n",
2011 __func__);
2000 device_printf(rb->fc->bdev,
2001 "%s: cannot respond(bus reset)!\n",
2002 __func__);
2012 return;
2013 }
2014 rb->xfer = fw_xfer_alloc(M_FWXFER);
2003 return;
2004 }
2005 rb->xfer = fw_xfer_alloc(M_FWXFER);
2015 if(rb->xfer == NULL){
2006 if (rb->xfer == NULL) {
2016 return;
2017 }
2018 rb->xfer->send.spd = rb->spd;
2019 rb->xfer->send.pay_len = 0;
2020 resfp = &rb->xfer->send.hdr;
2021 switch (tcode) {
2022 case FWTCODE_WREQQ:
2023 case FWTCODE_WREQB:

--- 14 unchanged lines hidden (view full) ---

2038 resfp->mode.hdr.pri = fp->mode.hdr.pri;
2039 resfp->mode.rresb.rtcode = RESP_ADDRESS_ERROR;
2040 resfp->mode.rresb.extcode = 0;
2041 resfp->mode.rresb.len = 0;
2042/*
2043 rb->xfer->hand = fw_xferwake;
2044*/
2045 rb->xfer->hand = fw_xfer_free;
2007 return;
2008 }
2009 rb->xfer->send.spd = rb->spd;
2010 rb->xfer->send.pay_len = 0;
2011 resfp = &rb->xfer->send.hdr;
2012 switch (tcode) {
2013 case FWTCODE_WREQQ:
2014 case FWTCODE_WREQB:

--- 14 unchanged lines hidden (view full) ---

2029 resfp->mode.hdr.pri = fp->mode.hdr.pri;
2030 resfp->mode.rresb.rtcode = RESP_ADDRESS_ERROR;
2031 resfp->mode.rresb.extcode = 0;
2032 resfp->mode.rresb.len = 0;
2033/*
2034 rb->xfer->hand = fw_xferwake;
2035*/
2036 rb->xfer->hand = fw_xfer_free;
2046 if(fw_asyreq(rb->fc, -1, rb->xfer)){
2037 if (fw_asyreq(rb->fc, -1, rb->xfer))
2047 fw_xfer_free(rb->xfer);
2038 fw_xfer_free(rb->xfer);
2048 return;
2049 }
2050 return;
2051 }
2052 len = 0;
2039 }
2040 len = 0;
2053 for (i = 0; i < rb->nvec; i ++)
2041 for (i = 0; i < rb->nvec; i++)
2054 len += rb->vec[i].iov_len;
2055 rb->xfer = STAILQ_FIRST(&bind->xferlist);
2056 if (rb->xfer == NULL) {
2057 device_printf(rb->fc->bdev, "%s: "
2042 len += rb->vec[i].iov_len;
2043 rb->xfer = STAILQ_FIRST(&bind->xferlist);
2044 if (rb->xfer == NULL) {
2045 device_printf(rb->fc->bdev, "%s: "
2058 "Discard a packet for this bind.\n",
2059 __func__);
2046 "Discard a packet for this bind.\n", __func__);
2060 return;
2061 }
2062 STAILQ_REMOVE_HEAD(&bind->xferlist, link);
2063 fw_rcv_copy(rb);
2064 rb->xfer->hand(rb->xfer);
2065 return;
2066#if 0 /* shouldn't happen ?? or for GASP */
2067 case FWTCODE_STREAM:
2068 {
2069 struct fw_xferq *xferq;
2070
2071 xferq = rb->fc->ir[sub];
2072#if 0
2073 printf("stream rcv dma %d len %d off %d spd %d\n",
2074 sub, len, off, spd);
2075#endif
2047 return;
2048 }
2049 STAILQ_REMOVE_HEAD(&bind->xferlist, link);
2050 fw_rcv_copy(rb);
2051 rb->xfer->hand(rb->xfer);
2052 return;
2053#if 0 /* shouldn't happen ?? or for GASP */
2054 case FWTCODE_STREAM:
2055 {
2056 struct fw_xferq *xferq;
2057
2058 xferq = rb->fc->ir[sub];
2059#if 0
2060 printf("stream rcv dma %d len %d off %d spd %d\n",
2061 sub, len, off, spd);
2062#endif
2076 if(xferq->queued >= xferq->maxq) {
2063 if (xferq->queued >= xferq->maxq) {
2077 printf("receive queue is full\n");
2078 return;
2079 }
2064 printf("receive queue is full\n");
2065 return;
2066 }
2080 /* XXX get xfer from xfer queue, we don't need copy for
2067 /* XXX get xfer from xfer queue, we don't need copy for
2081 per packet mode */
2082 rb->xfer = fw_xfer_alloc_buf(M_FWXFER, 0, /* XXX */
2083 vec[0].iov_len);
2084 if (rb->xfer == NULL)
2085 return;
2086 fw_rcv_copy(rb)
2087 s = splfw();
2088 xferq->queued++;
2089 STAILQ_INSERT_TAIL(&xferq->q, rb->xfer, link);
2090 splx(s);
2091 sc = device_get_softc(rb->fc->bdev);
2068 per packet mode */
2069 rb->xfer = fw_xfer_alloc_buf(M_FWXFER, 0, /* XXX */
2070 vec[0].iov_len);
2071 if (rb->xfer == NULL)
2072 return;
2073 fw_rcv_copy(rb)
2074 s = splfw();
2075 xferq->queued++;
2076 STAILQ_INSERT_TAIL(&xferq->q, rb->xfer, link);
2077 splx(s);
2078 sc = device_get_softc(rb->fc->bdev);
2092#if defined(__DragonFly__) || __FreeBSD_version < 500000
2093 if (&xferq->rsel.si_pid != 0)
2094#else
2095 if (SEL_WAITING(&xferq->rsel))
2079 if (SEL_WAITING(&xferq->rsel))
2096#endif
2097 selwakeuppri(&xferq->rsel, FWPRI);
2098 if (xferq->flag & FWXFERQ_WAKEUP) {
2099 xferq->flag &= ~FWXFERQ_WAKEUP;
2100 wakeup((caddr_t)xferq);
2101 }
2102 if (xferq->flag & FWXFERQ_HANDLER) {
2103 xferq->hand(xferq);
2104 }
2105 return;
2106 break;
2107 }
2108#endif
2109 default:
2110 device_printf(rb->fc->bdev,"%s: unknown tcode %d\n",
2080 selwakeuppri(&xferq->rsel, FWPRI);
2081 if (xferq->flag & FWXFERQ_WAKEUP) {
2082 xferq->flag &= ~FWXFERQ_WAKEUP;
2083 wakeup((caddr_t)xferq);
2084 }
2085 if (xferq->flag & FWXFERQ_HANDLER) {
2086 xferq->hand(xferq);
2087 }
2088 return;
2089 break;
2090 }
2091#endif
2092 default:
2093 device_printf(rb->fc->bdev,"%s: unknown tcode %d\n",
2111 __func__, tcode);
2094 __func__, tcode);
2112 break;
2113 }
2114}
2115
2116/*
2117 * Post process for Bus Manager election process.
2118 */
2119static void

--- 29 unchanged lines hidden (view full) ---

2149
2150/*
2151 * To candidate Bus Manager election process.
2152 */
2153static void
2154fw_try_bmr(void *arg)
2155{
2156 struct fw_xfer *xfer;
2095 break;
2096 }
2097}
2098
2099/*
2100 * Post process for Bus Manager election process.
2101 */
2102static void

--- 29 unchanged lines hidden (view full) ---

2132
2133/*
2134 * To candidate Bus Manager election process.
2135 */
2136static void
2137fw_try_bmr(void *arg)
2138{
2139 struct fw_xfer *xfer;
2157 struct firewire_comm *fc = (struct firewire_comm *)arg;
2140 struct firewire_comm *fc = arg;
2158 struct fw_pkt *fp;
2159 int err = 0;
2160
2161 xfer = fw_xfer_alloc_buf(M_FWXFER, 8, 4);
2141 struct fw_pkt *fp;
2142 int err = 0;
2143
2144 xfer = fw_xfer_alloc_buf(M_FWXFER, 8, 4);
2162 if(xfer == NULL){
2145 if (xfer == NULL)
2163 return;
2146 return;
2164 }
2165 xfer->send.spd = 0;
2166 fc->status = FWBUSMGRELECT;
2167
2168 fp = &xfer->send.hdr;
2169 fp->mode.lreq.dest_hi = 0xffff;
2170 fp->mode.lreq.tlrt = 0;
2171 fp->mode.lreq.tcode = FWTCODE_LREQ;
2172 fp->mode.lreq.pri = 0;
2173 fp->mode.lreq.src = 0;
2174 fp->mode.lreq.len = 8;
2175 fp->mode.lreq.extcode = EXTCODE_CMP_SWAP;
2176 fp->mode.lreq.dst = FWLOCALBUS | fc->irm;
2177 fp->mode.lreq.dest_lo = 0xf0000000 | BUS_MGR_ID;
2178 xfer->send.payload[0] = htonl(0x3f);
2179 xfer->send.payload[1] = htonl(fc->nodeid);
2180 xfer->hand = fw_try_bmr_callback;
2181
2182 err = fw_asyreq(fc, -1, xfer);
2147 xfer->send.spd = 0;
2148 fc->status = FWBUSMGRELECT;
2149
2150 fp = &xfer->send.hdr;
2151 fp->mode.lreq.dest_hi = 0xffff;
2152 fp->mode.lreq.tlrt = 0;
2153 fp->mode.lreq.tcode = FWTCODE_LREQ;
2154 fp->mode.lreq.pri = 0;
2155 fp->mode.lreq.src = 0;
2156 fp->mode.lreq.len = 8;
2157 fp->mode.lreq.extcode = EXTCODE_CMP_SWAP;
2158 fp->mode.lreq.dst = FWLOCALBUS | fc->irm;
2159 fp->mode.lreq.dest_lo = 0xf0000000 | BUS_MGR_ID;
2160 xfer->send.payload[0] = htonl(0x3f);
2161 xfer->send.payload[1] = htonl(fc->nodeid);
2162 xfer->hand = fw_try_bmr_callback;
2163
2164 err = fw_asyreq(fc, -1, xfer);
2183 if(err){
2165 if (err) {
2184 fw_xfer_free_buf(xfer);
2185 return;
2186 }
2187 return;
2188}
2189
2190#ifdef FW_VMACCESS
2191/*
2192 * Software implementation for physical memory block access.
2166 fw_xfer_free_buf(xfer);
2167 return;
2168 }
2169 return;
2170}
2171
2172#ifdef FW_VMACCESS
2173/*
2174 * Software implementation for physical memory block access.
2193 * XXX:Too slow, usef for debug purpose only.
2175 * XXX:Too slow, useful for debug purpose only.
2194 */
2195static void
2176 */
2177static void
2196fw_vmaccess(struct fw_xfer *xfer){
2178fw_vmaccess(struct fw_xfer *xfer)
2179{
2197 struct fw_pkt *rfp, *sfp = NULL;
2198 uint32_t *ld = (uint32_t *)xfer->recv.buf;
2199
2200 printf("vmaccess spd:%2x len:%03x data:%08x %08x %08x %08x\n",
2180 struct fw_pkt *rfp, *sfp = NULL;
2181 uint32_t *ld = (uint32_t *)xfer->recv.buf;
2182
2183 printf("vmaccess spd:%2x len:%03x data:%08x %08x %08x %08x\n",
2201 xfer->spd, xfer->recv.len, ntohl(ld[0]), ntohl(ld[1]), ntohl(ld[2]), ntohl(ld[3]));
2202 printf("vmaccess data:%08x %08x %08x %08x\n", ntohl(ld[4]), ntohl(ld[5]), ntohl(ld[6]), ntohl(ld[7]));
2203 if(xfer->resp != 0){
2204 fw_xfer_free( xfer);
2184 xfer->spd, xfer->recv.len, ntohl(ld[0]), ntohl(ld[1]), ntohl(ld[2]),
2185 ntohl(ld[3]));
2186 printf("vmaccess data:%08x %08x %08x %08x\n", ntohl(ld[4]),
2187 ntohl(ld[5]), ntohl(ld[6]), ntohl(ld[7]));
2188 if (xfer->resp != 0) {
2189 fw_xfer_free(xfer);
2205 return;
2206 }
2190 return;
2191 }
2207 if(xfer->recv.buf == NULL){
2208 fw_xfer_free( xfer);
2192 if (xfer->recv.buf == NULL) {
2193 fw_xfer_free(xfer);
2209 return;
2210 }
2211 rfp = (struct fw_pkt *)xfer->recv.buf;
2194 return;
2195 }
2196 rfp = (struct fw_pkt *)xfer->recv.buf;
2212 switch(rfp->mode.hdr.tcode){
2197 switch (rfp->mode.hdr.tcode) {
2213 /* XXX need fix for 64bit arch */
2214 case FWTCODE_WREQB:
2215 xfer->send.buf = malloc(12, M_FW, M_NOWAIT);
2216 xfer->send.len = 12;
2217 sfp = (struct fw_pkt *)xfer->send.buf;
2218 bcopy(rfp->mode.wreqb.payload,
2198 /* XXX need fix for 64bit arch */
2199 case FWTCODE_WREQB:
2200 xfer->send.buf = malloc(12, M_FW, M_NOWAIT);
2201 xfer->send.len = 12;
2202 sfp = (struct fw_pkt *)xfer->send.buf;
2203 bcopy(rfp->mode.wreqb.payload,
2219 (caddr_t)ntohl(rfp->mode.wreqb.dest_lo), ntohs(rfp->mode.wreqb.len));
2204 (caddr_t)ntohl(rfp->mode.wreqb.dest_lo),s
2205 ntohs(rfp->mode.wreqb.len));
2220 sfp->mode.wres.tcode = FWTCODE_WRES;
2221 sfp->mode.wres.rtcode = 0;
2222 break;
2223 case FWTCODE_WREQQ:
2224 xfer->send.buf = malloc(12, M_FW, M_NOWAIT);
2225 xfer->send.len = 12;
2226 sfp->mode.wres.tcode = FWTCODE_WRES;
2206 sfp->mode.wres.tcode = FWTCODE_WRES;
2207 sfp->mode.wres.rtcode = 0;
2208 break;
2209 case FWTCODE_WREQQ:
2210 xfer->send.buf = malloc(12, M_FW, M_NOWAIT);
2211 xfer->send.len = 12;
2212 sfp->mode.wres.tcode = FWTCODE_WRES;
2227 *((uint32_t *)(ntohl(rfp->mode.wreqb.dest_lo))) = rfp->mode.wreqq.data;
2213 *((uint32_t *)(ntohl(rfp->mode.wreqb.dest_lo))) =
2214 rfp->mode.wreqq.data;
2228 sfp->mode.wres.rtcode = 0;
2229 break;
2230 case FWTCODE_RREQB:
2215 sfp->mode.wres.rtcode = 0;
2216 break;
2217 case FWTCODE_RREQB:
2231 xfer->send.buf = malloc(16 + rfp->mode.rreqb.len, M_FW, M_NOWAIT);
2218 xfer->send.buf = malloc(16 + rfp->mode.rreqb.len,
2219 M_FW, M_NOWAIT);
2232 xfer->send.len = 16 + ntohs(rfp->mode.rreqb.len);
2233 sfp = (struct fw_pkt *)xfer->send.buf;
2234 bcopy((caddr_t)ntohl(rfp->mode.rreqb.dest_lo),
2220 xfer->send.len = 16 + ntohs(rfp->mode.rreqb.len);
2221 sfp = (struct fw_pkt *)xfer->send.buf;
2222 bcopy((caddr_t)ntohl(rfp->mode.rreqb.dest_lo),
2235 sfp->mode.rresb.payload, (uint16_t)ntohs(rfp->mode.rreqb.len));
2223 sfp->mode.rresb.payload,
2224 ntohs(rfp->mode.rreqb.len));
2236 sfp->mode.rresb.tcode = FWTCODE_RRESB;
2237 sfp->mode.rresb.len = rfp->mode.rreqb.len;
2238 sfp->mode.rresb.rtcode = 0;
2239 sfp->mode.rresb.extcode = 0;
2240 break;
2241 case FWTCODE_RREQQ:
2242 xfer->send.buf = malloc(16, M_FW, M_NOWAIT);
2243 xfer->send.len = 16;
2244 sfp = (struct fw_pkt *)xfer->send.buf;
2225 sfp->mode.rresb.tcode = FWTCODE_RRESB;
2226 sfp->mode.rresb.len = rfp->mode.rreqb.len;
2227 sfp->mode.rresb.rtcode = 0;
2228 sfp->mode.rresb.extcode = 0;
2229 break;
2230 case FWTCODE_RREQQ:
2231 xfer->send.buf = malloc(16, M_FW, M_NOWAIT);
2232 xfer->send.len = 16;
2233 sfp = (struct fw_pkt *)xfer->send.buf;
2245 sfp->mode.rresq.data = *(uint32_t *)(ntohl(rfp->mode.rreqq.dest_lo));
2234 sfp->mode.rresq.data =
2235 *(uint32_t *)(ntohl(rfp->mode.rreqq.dest_lo));
2246 sfp->mode.wres.tcode = FWTCODE_RRESQ;
2247 sfp->mode.rresb.rtcode = 0;
2248 break;
2249 default:
2236 sfp->mode.wres.tcode = FWTCODE_RRESQ;
2237 sfp->mode.rresb.rtcode = 0;
2238 break;
2239 default:
2250 fw_xfer_free( xfer);
2240 fw_xfer_free(xfer);
2251 return;
2252 }
2253 sfp->mode.hdr.dst = rfp->mode.hdr.src;
2254 xfer->dst = ntohs(rfp->mode.hdr.src);
2255 xfer->hand = fw_xfer_free;
2256
2257 sfp->mode.hdr.tlrt = rfp->mode.hdr.tlrt;
2258 sfp->mode.hdr.pri = 0;
2259
2260 fw_asyreq(xfer->fc, -1, xfer);
2261/**/
2262 return;
2263}
2241 return;
2242 }
2243 sfp->mode.hdr.dst = rfp->mode.hdr.src;
2244 xfer->dst = ntohs(rfp->mode.hdr.src);
2245 xfer->hand = fw_xfer_free;
2246
2247 sfp->mode.hdr.tlrt = rfp->mode.hdr.tlrt;
2248 sfp->mode.hdr.pri = 0;
2249
2250 fw_asyreq(xfer->fc, -1, xfer);
2251/**/
2252 return;
2253}
2264#endif
2254#endif
2265
2266/*
2267 * CRC16 check-sum for IEEE1394 register blocks.
2268 */
2269uint16_t
2255
2256/*
2257 * CRC16 check-sum for IEEE1394 register blocks.
2258 */
2259uint16_t
2270fw_crc16(uint32_t *ptr, uint32_t len){
2260fw_crc16(uint32_t *ptr, uint32_t len)
2261{
2271 uint32_t i, sum, crc = 0;
2272 int shift;
2273 len = (len + 3) & ~3;
2262 uint32_t i, sum, crc = 0;
2263 int shift;
2264 len = (len + 3) & ~3;
2274 for(i = 0 ; i < len ; i+= 4){
2275 for( shift = 28 ; shift >= 0 ; shift -= 4){
2265 for (i = 0; i < len; i += 4) {
2266 for (shift = 28; shift >= 0; shift -= 4) {
2276 sum = ((crc >> 12) ^ (ptr[i/4] >> shift)) & 0xf;
2267 sum = ((crc >> 12) ^ (ptr[i/4] >> shift)) & 0xf;
2277 crc = (crc << 4) ^ ( sum << 12 ) ^ ( sum << 5) ^ sum;
2268 crc = (crc << 4) ^ (sum << 12) ^ (sum << 5) ^ sum;
2278 }
2279 crc &= 0xffff;
2280 }
2269 }
2270 crc &= 0xffff;
2271 }
2281 return((uint16_t) crc);
2272 return ((uint16_t) crc);
2282}
2283
2284/*
2285 * Find the root node, if it is not
2286 * Cycle Master Capable, then we should
2287 * override this and become the Cycle
2288 * Master
2289 */

--- 8 unchanged lines hidden (view full) ---

2298 /* Check to see if the current root node is cycle master capable */
2299 self_id = fw_find_self_id(fc, fc->max_node);
2300 if (fc->max_node > 0) {
2301 /* XXX check cmc bit of businfo block rather than contender */
2302 if (self_id->p0.link_active && self_id->p0.contender)
2303 cmstr = fc->max_node;
2304 else {
2305 device_printf(fc->bdev,
2273}
2274
2275/*
2276 * Find the root node, if it is not
2277 * Cycle Master Capable, then we should
2278 * override this and become the Cycle
2279 * Master
2280 */

--- 8 unchanged lines hidden (view full) ---

2289 /* Check to see if the current root node is cycle master capable */
2290 self_id = fw_find_self_id(fc, fc->max_node);
2291 if (fc->max_node > 0) {
2292 /* XXX check cmc bit of businfo block rather than contender */
2293 if (self_id->p0.link_active && self_id->p0.contender)
2294 cmstr = fc->max_node;
2295 else {
2296 device_printf(fc->bdev,
2306 "root node is not cycle master capable\n");
2297 "root node is not cycle master capable\n");
2307 /* XXX shall we be the cycle master? */
2308 cmstr = fc->nodeid;
2309 /* XXX need bus reset */
2310 }
2311 } else
2312 cmstr = -1;
2313
2314 device_printf(fc->bdev, "bus manager %d %s\n",
2315 CSRARC(fc, BUS_MGR_ID),
2316 (CSRARC(fc, BUS_MGR_ID) != fc->nodeid) ? "(me)" : "");
2298 /* XXX shall we be the cycle master? */
2299 cmstr = fc->nodeid;
2300 /* XXX need bus reset */
2301 }
2302 } else
2303 cmstr = -1;
2304
2305 device_printf(fc->bdev, "bus manager %d %s\n",
2306 CSRARC(fc, BUS_MGR_ID),
2307 (CSRARC(fc, BUS_MGR_ID) != fc->nodeid) ? "(me)" : "");
2317 if(CSRARC(fc, BUS_MGR_ID) != fc->nodeid) {
2308 if (CSRARC(fc, BUS_MGR_ID) != fc->nodeid) {
2318 /* We are not the bus manager */
2309 /* We are not the bus manager */
2319 return(0);
2310 return (0);
2320 }
2321
2322 /* Optimize gapcount */
2311 }
2312
2313 /* Optimize gapcount */
2323 if(fc->max_hop <= MAX_GAPHOP )
2314 if (fc->max_hop <= MAX_GAPHOP)
2324 fw_phy_config(fc, cmstr, gap_cnt[fc->max_hop]);
2325 /* If we are the cycle master, nothing to do */
2326 if (cmstr == fc->nodeid || cmstr == -1)
2327 return 0;
2328 /* Bus probe has not finished, make dummy fwdev for cmstr */
2329 bzero(&fwdev, sizeof(fwdev));
2330 fwdev.fc = fc;
2331 fwdev.dst = cmstr;
2332 fwdev.speed = 0;
2333 fwdev.maxrec = 8; /* 512 */
2334 fwdev.status = FWDEVINIT;
2335 /* Set cmstr bit on the cycle master */
2336 quad = htonl(1 << 8);
2337 fwmem_write_quad(&fwdev, NULL, 0/*spd*/,
2315 fw_phy_config(fc, cmstr, gap_cnt[fc->max_hop]);
2316 /* If we are the cycle master, nothing to do */
2317 if (cmstr == fc->nodeid || cmstr == -1)
2318 return 0;
2319 /* Bus probe has not finished, make dummy fwdev for cmstr */
2320 bzero(&fwdev, sizeof(fwdev));
2321 fwdev.fc = fc;
2322 fwdev.dst = cmstr;
2323 fwdev.speed = 0;
2324 fwdev.maxrec = 8; /* 512 */
2325 fwdev.status = FWDEVINIT;
2326 /* Set cmstr bit on the cycle master */
2327 quad = htonl(1 << 8);
2328 fwmem_write_quad(&fwdev, NULL, 0/*spd*/,
2338 0xffff, 0xf0000000 | STATE_SET, &quad, fw_asy_callback_free);
2329 0xffff, 0xf0000000 | STATE_SET, &quad, fw_asy_callback_free);
2339
2340 return 0;
2341}
2342
2343int
2344fw_open_isodma(struct firewire_comm *fc, int tx)
2345{
2346 struct fw_xferq **xferqa;
2347 struct fw_xferq *xferq;
2348 int i;
2349
2350 if (tx)
2351 xferqa = &fc->it[0];
2352 else
2353 xferqa = &fc->ir[0];
2354
2355 FW_GLOCK(fc);
2330
2331 return 0;
2332}
2333
2334int
2335fw_open_isodma(struct firewire_comm *fc, int tx)
2336{
2337 struct fw_xferq **xferqa;
2338 struct fw_xferq *xferq;
2339 int i;
2340
2341 if (tx)
2342 xferqa = &fc->it[0];
2343 else
2344 xferqa = &fc->ir[0];
2345
2346 FW_GLOCK(fc);
2356 for (i = 0; i < fc->nisodma; i ++) {
2347 for (i = 0; i < fc->nisodma; i++) {
2357 xferq = xferqa[i];
2358 if ((xferq->flag & FWXFERQ_OPEN) == 0) {
2359 xferq->flag |= FWXFERQ_OPEN;
2360 break;
2361 }
2362 }
2363 if (i == fc->nisodma) {
2364 printf("no free dma channel (tx=%d)\n", tx);
2365 i = -1;
2366 }
2367 FW_GUNLOCK(fc);
2368 return (i);
2369}
2370
2371static int
2372fw_modevent(module_t mode, int type, void *data)
2373{
2374 int err = 0;
2348 xferq = xferqa[i];
2349 if ((xferq->flag & FWXFERQ_OPEN) == 0) {
2350 xferq->flag |= FWXFERQ_OPEN;
2351 break;
2352 }
2353 }
2354 if (i == fc->nisodma) {
2355 printf("no free dma channel (tx=%d)\n", tx);
2356 i = -1;
2357 }
2358 FW_GUNLOCK(fc);
2359 return (i);
2360}
2361
2362static int
2363fw_modevent(module_t mode, int type, void *data)
2364{
2365 int err = 0;
2375#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
2376 static eventhandler_tag fwdev_ehtag = NULL;
2366 static eventhandler_tag fwdev_ehtag = NULL;
2377#endif
2378
2379 switch (type) {
2380 case MOD_LOAD:
2367
2368 switch (type) {
2369 case MOD_LOAD:
2381#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
2382 fwdev_ehtag = EVENTHANDLER_REGISTER(dev_clone,
2370 fwdev_ehtag = EVENTHANDLER_REGISTER(dev_clone,
2383 fwdev_clone, 0, 1000);
2384#endif
2371 fwdev_clone, 0, 1000);
2385 break;
2386 case MOD_UNLOAD:
2372 break;
2373 case MOD_UNLOAD:
2387#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
2388 if (fwdev_ehtag != NULL)
2389 EVENTHANDLER_DEREGISTER(dev_clone, fwdev_ehtag);
2374 if (fwdev_ehtag != NULL)
2375 EVENTHANDLER_DEREGISTER(dev_clone, fwdev_ehtag);
2390#endif
2391 break;
2392 case MOD_SHUTDOWN:
2393 break;
2394 default:
2395 return (EOPNOTSUPP);
2396 }
2397 return (err);
2398}
2399
2400
2376 break;
2377 case MOD_SHUTDOWN:
2378 break;
2379 default:
2380 return (EOPNOTSUPP);
2381 }
2382 return (err);
2383}
2384
2385
2401#ifdef __DragonFly__
2402DECLARE_DUMMY_MODULE(firewire);
2403#endif
2404DRIVER_MODULE(firewire,fwohci,firewire_driver,firewire_devclass,fw_modevent,0);
2386DRIVER_MODULE(firewire, fwohci, firewire_driver, firewire_devclass,
2387 fw_modevent,0);
2405MODULE_VERSION(firewire, 1);
2388MODULE_VERSION(firewire, 1);