summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/io/1394/targets/av1394/av1394_isoch.c
blob: 9a16a26454e1e39acbcb8123e984933ac1004a1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * av1394 isochronous module
 */
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/av/iec61883.h>
#include <sys/1394/targets/av1394/av1394_impl.h>

/* configuration routines */
static int	av1394_isoch_create_minor_node(av1394_inst_t *);
static void	av1394_isoch_remove_minor_node(av1394_inst_t *);
static void	av1394_isoch_cleanup(av1394_inst_t *, int);
av1394_isoch_seg_t *av1394_isoch_find_seg(av1394_inst_t *, offset_t, size_t);
static int	av1394_isoch_autorecv_init(av1394_inst_t *, av1394_ic_t **);
static int	av1394_isoch_autoxmit_init(av1394_inst_t *, av1394_ic_t **,
		struct uio *);

/* ioctls */
static int	av1394_ioctl_isoch_init(av1394_inst_t *, void *, int);
static av1394_ic_t *av1394_ioctl_isoch_handle2ic(av1394_inst_t *, void *);
static int	av1394_ioctl_isoch_fini(av1394_inst_t *, void *, int);
static int	av1394_ioctl_start(av1394_inst_t *, void *, int);
static int	av1394_ioctl_stop(av1394_inst_t *, void *, int);
static int	av1394_ioctl_recv(av1394_inst_t *, void *, int);
static int	av1394_ioctl_xmit(av1394_inst_t *, void *, int);

static uint_t av1394_isoch_softintr(caddr_t);

static struct devmap_callback_ctl av1394_isoch_devmap_ops = {
	DEVMAP_OPS_REV,		/* rev */
	NULL,			/* map */
	NULL,			/* access */
	NULL,			/* dup */
	NULL,			/* unmap */
};

/* tunables */
int av1394_rate_n_dv_ntsc = 246;
int av1394_rate_d_dv_ntsc = 3840;
int av1394_rate_n_dv_pal = 1;
int av1394_rate_d_dv_pal = 16;

int av1394_isoch_autorecv_nframes = 50;
int av1394_isoch_autorecv_framesz = 250;
int av1394_isoch_autoxmit_nframes = 50;
int av1394_isoch_autoxmit_framesz = 250;

int
av1394_isoch_attach(av1394_inst_t *avp)
{
	av1394_isoch_t	*ip = &avp->av_i;
	ddi_iblock_cookie_t ibc = avp->av_attachinfo.iblock_cookie;

	mutex_init(&ip->i_mutex, NULL, MUTEX_DRIVER, ibc);

	mutex_enter(&ip->i_mutex);
	if (av1394_isoch_create_minor_node(avp) != DDI_SUCCESS) {
		mutex_exit(&ip->i_mutex);
		av1394_isoch_cleanup(avp, 1);
		return (DDI_FAILURE);
	}

	if (ddi_add_softintr(avp->av_dip, DDI_SOFTINT_LOW, &ip->i_softintr_id,
	    0, 0, av1394_isoch_softintr, (caddr_t)avp) != DDI_SUCCESS) {
		mutex_exit(&ip->i_mutex);
		av1394_isoch_cleanup(avp, 2);
		return (DDI_FAILURE);
	}

	if (av1394_cmp_init(avp) != DDI_SUCCESS) {
		mutex_exit(&ip->i_mutex);
		av1394_isoch_cleanup(avp, 3);
		return (DDI_FAILURE);
	}

	av1394_as_init(&ip->i_mmap_as);
	mutex_exit(&ip->i_mutex);

	return (DDI_SUCCESS);
}

void
av1394_isoch_detach(av1394_inst_t *avp)
{
	av1394_isoch_cleanup(avp, AV1394_CLEANUP_LEVEL_MAX);
}

int
av1394_isoch_cpr_suspend(av1394_inst_t *avp)
{
	av1394_isoch_t	*ip = &avp->av_i;
	av1394_ic_t	*icp;
	int		i;
	int		ret = DDI_SUCCESS;

	/*
	 * suspend only if there are no active channels
	 */
	mutex_enter(&ip->i_mutex);
	for (i = 0; (i < NELEM(ip->i_ic)) && (ret == DDI_SUCCESS); i++) {
		icp = ip->i_ic[i];
		if (icp) {
			mutex_enter(&icp->ic_mutex);
			if (icp->ic_state != AV1394_IC_IDLE) {
				ret = DDI_FAILURE;
			}
			mutex_exit(&icp->ic_mutex);
		}
	}
	mutex_exit(&ip->i_mutex);

	return (ret);
}

/*ARGSUSED*/
int
av1394_isoch_close(av1394_inst_t *avp, int flag)
{
	int	ret;

	ret = av1394_ic_close(avp, flag);
	av1394_cmp_close(avp);

	return (ret);
}

int
av1394_isoch_read(av1394_inst_t *avp, struct uio *uiop)
{
	av1394_ic_t	*icp;
	int		ret;

	/* use broadcast channel */
	icp = avp->av_i.i_ic[63];
	if (icp == NULL) {
		if ((ret = av1394_isoch_autorecv_init(avp, &icp)) != 0) {
			return (ret);
		}
	} else if (icp->ic_dir != AV1394_IR) {
		/* channel already used for xmit */
		return (EBUSY);
	}

	if ((ret = av1394_ir_start(icp)) == 0) {
		ret = av1394_ir_read(icp, uiop);
	}

	return (ret);
}

int
av1394_isoch_write(av1394_inst_t *avp, struct uio *uiop)
{
	av1394_ic_t	*icp;
	int		ret;

	/* use broadcast channel */
	icp = avp->av_i.i_ic[63];
	if (icp == NULL) {
		if ((ret = av1394_isoch_autoxmit_init(avp, &icp, uiop)) != 0) {
			return (ret);
		}
	} else if (icp->ic_dir != AV1394_IT) {
		/* channel already used for recv */
		return (EBUSY);
	}

	ret = av1394_it_write(icp, uiop);

	return (ret);
}

/*ARGSUSED*/
int
av1394_isoch_ioctl(av1394_inst_t *avp, int cmd, intptr_t arg, int mode,
    int *rvalp)
{
	int		ret = EINVAL;

	switch (cmd) {
	case IEC61883_ISOCH_INIT:
		ret = av1394_ioctl_isoch_init(avp, (void *)arg, mode);
		break;
	case IEC61883_ISOCH_FINI:
		ret = av1394_ioctl_isoch_fini(avp, (void *)arg, mode);
		break;
	case IEC61883_START:
		ret = av1394_ioctl_start(avp, (void *)arg, mode);
		break;
	case IEC61883_STOP:
		ret = av1394_ioctl_stop(avp, (void *)arg, mode);
		break;
	case IEC61883_RECV:
		ret = av1394_ioctl_recv(avp, (void *)arg, mode);
		break;
	case IEC61883_XMIT:
		ret = av1394_ioctl_xmit(avp, (void *)arg, mode);
		break;
	case IEC61883_PLUG_INIT:
		ret = av1394_ioctl_plug_init(avp, (void *)arg, mode);
		break;
	case IEC61883_PLUG_FINI:
		ret = av1394_ioctl_plug_fini(avp, (void *)arg, mode);
		break;
	case IEC61883_PLUG_REG_READ:
		ret = av1394_ioctl_plug_reg_read(avp, (void *)arg, mode);
		break;
	case IEC61883_PLUG_REG_CAS:
		ret = av1394_ioctl_plug_reg_cas(avp, (void *)arg, mode);
		break;
	}

	return (ret);
}

/*ARGSUSED*/
int
av1394_isoch_devmap(av1394_inst_t *avp, devmap_cookie_t dhp, offset_t off,
    size_t len, size_t *maplen, uint_t model)
{
	av1394_isoch_seg_t *isp;

	*maplen = 0;

	/* find segment */
	isp = av1394_isoch_find_seg(avp, off, ptob(btopr(len)));
	if (isp == NULL) {
		return (EINVAL);
	}

	/* map segment */
	if (devmap_umem_setup(dhp, avp->av_dip, &av1394_isoch_devmap_ops,
	    isp->is_umem_cookie, 0, isp->is_umem_size, PROT_ALL, 0,
	    &avp->av_attachinfo.acc_attr) != 0) {
		return (EINVAL);
	}
	*maplen = isp->is_umem_size;

	return (0);
}

/*
 *
 * --- configuration routines
 *
 * av1394_isoch_create_minor_node()
 *    Create isoch minor node
 */
static int
av1394_isoch_create_minor_node(av1394_inst_t *avp)
{
	int	ret;

	ret = ddi_create_minor_node(avp->av_dip, "isoch",
	    S_IFCHR, AV1394_ISOCH_INST2MINOR(avp->av_instance),
	    DDI_NT_AV_ISOCH, 0);
	return (ret);
}

/*
 * av1394_isoch_remove_minor_node()
 *    Remove isoch minor node
 */
static void
av1394_isoch_remove_minor_node(av1394_inst_t *avp)
{
	ddi_remove_minor_node(avp->av_dip, "isoch");
}

/*
 * av1394_isoch_cleanup()
 *    Cleanup after attach
 */
static void
av1394_isoch_cleanup(av1394_inst_t *avp, int level)
{
	av1394_isoch_t	*ip = &avp->av_i;

	ASSERT((level > 0) && (level <= AV1394_CLEANUP_LEVEL_MAX));

	switch (level) {
	default:
		mutex_enter(&ip->i_mutex);
		av1394_as_fini(&ip->i_mmap_as);
		av1394_cmp_fini(avp);
		mutex_exit(&ip->i_mutex);
		/* FALLTHRU */
	case 3:
		ddi_remove_softintr(ip->i_softintr_id);
		/* FALLTHRU */
	case 2:
		av1394_isoch_remove_minor_node(avp);
		/* FALLTHRU */
	case 1:
		mutex_destroy(&ip->i_mutex);
	}
}

/*
 * av1394_isoch_find_seg()
 *    Given an offset and size, find a matching av1394_isoch_seg_t structure.
 */
av1394_isoch_seg_t *
av1394_isoch_find_seg(av1394_inst_t *avp, offset_t off, size_t len)
{
	av1394_isoch_t	*ip = &avp->av_i;
	av1394_ic_t	*icp;
	av1394_isoch_pool_t *pool;
	av1394_isoch_seg_t *isp;
	offset_t	segoff;
	int		i;

	/* find channel from within this range */
	for (i = 0; i < NELEM(ip->i_ic); i++) {
		icp = ip->i_ic[i];
		if (icp == NULL) {
			continue;
		}
		if ((off >= icp->ic_mmap_off) &&
		    (off + len <= icp->ic_mmap_off + icp->ic_mmap_sz)) {
			off -= icp->ic_mmap_off;	/* convert to base */
			break;
		}
		icp = NULL;
	}
	if (icp == NULL) {
		return (NULL);
	}

	/* find a segment */
	pool = (icp->ic_dir == AV1394_IR) ?
	    &icp->ic_ir.ir_data_pool : &icp->ic_it.it_data_pool;
	for (segoff = 0, i = 0; i < pool->ip_nsegs; i++) {
		isp = &pool->ip_seg[i];
		if (off == segoff) {
			break;
		}
		segoff += isp->is_umem_size;
		isp = NULL;
	}
	if (isp == NULL) {
		return (NULL);
	}

	/* only whole segments can be mapped */
	if (len != isp->is_umem_size) {
		return (NULL);
	}
	return (isp);
}

/*
 * initialize default channel for data receipt
 */
static int
av1394_isoch_autorecv_init(av1394_inst_t *avp, av1394_ic_t **icpp)
{
	iec61883_isoch_init_t ii;
	int		ret = 0;

	bzero(&ii, sizeof (ii));
	ii.ii_version = IEC61883_V1_0;
	ii.ii_pkt_size = 512;
	ii.ii_frame_size = av1394_isoch_autorecv_framesz;
	ii.ii_frame_cnt = av1394_isoch_autorecv_nframes;
	ii.ii_direction = IEC61883_DIR_RECV;
	ii.ii_bus_speed = IEC61883_S100;
	ii.ii_channel = (1ULL << 63);

	ret = av1394_ic_init(avp, &ii, icpp);

	return (ret);
}

/*
 * initialize default channel for data xmit
 */
static int
av1394_isoch_autoxmit_init(av1394_inst_t *avp, av1394_ic_t **icpp,
    struct uio *uiop)
{
	av1394_isoch_autoxmit_t *axp = &avp->av_i.i_autoxmit;
	iec61883_isoch_init_t ii;
	uint_t		fmt, dbs, fn, f5060, stype;	/* CIP fields */
	int		ret = 0;

	/* copyin the first CIP header */
	axp->ax_copy_ciph = B_FALSE;
	if (uiop->uio_resid < AV1394_CIPSZ) {
		return (EINVAL);
	}
	ret = uiomove(axp->ax_ciph, AV1394_CIPSZ, UIO_WRITE, uiop);
	if (ret != 0) {
		return (ret);
	}
	axp->ax_copy_ciph = B_TRUE;

	/* parse CIP header */
	dbs = axp->ax_ciph[1];
	fn = (axp->ax_ciph[2] >> 6) & 0x3;
	fmt = axp->ax_ciph[4] & 0x3F;
	stype = (axp->ax_ciph[5] >> 2) & 0x1F;

	/* fill out the init structure */
	bzero(&ii, sizeof (ii));
	ii.ii_version = IEC61883_V1_0;
	ii.ii_frame_cnt = av1394_isoch_autoxmit_nframes;
	ii.ii_direction = IEC61883_DIR_XMIT;
	ii.ii_bus_speed = IEC61883_S100;
	ii.ii_channel = (1ULL << 63);
	ii.ii_dbs = dbs;
	ii.ii_fn = fn;

	if ((fmt == 0) && (dbs == 0x78) && (fn == 0) && (stype == 0)) {
		/* either DV-NTSC or DV-PAL */
		ii.ii_pkt_size = 488;
		ii.ii_ts_mode = IEC61883_TS_SYT;
		f5060 = axp->ax_ciph[5] & 0x80;
		if (f5060 == 0) {
			axp->ax_fmt = AV1394_ISOCH_AUTOXMIT_DV_NTSC;
			ii.ii_frame_size = AV1394_DV_NTSC_FRAMESZ;
			ii.ii_rate_n = av1394_rate_n_dv_ntsc;
			ii.ii_rate_d = av1394_rate_d_dv_ntsc;
		} else {
			axp->ax_fmt = AV1394_ISOCH_AUTOXMIT_DV_PAL;
			ii.ii_frame_size = AV1394_DV_PAL_FRAMESZ;
			ii.ii_rate_n = av1394_rate_n_dv_pal;
			ii.ii_rate_d = av1394_rate_d_dv_pal;
		}
	} else {
		/* raw stream */
		axp->ax_fmt = AV1394_ISOCH_AUTOXMIT_UNKNOWN;
		ii.ii_pkt_size = 512;
		ii.ii_frame_size = av1394_isoch_autoxmit_framesz;
		ii.ii_ts_mode = IEC61883_TS_NONE;
	}

	ret = av1394_ic_init(avp, &ii, icpp);

	return (ret);
}


/*
 *
 * --- ioctls
 *	these routines are generally responsible for copyin/out of arguments
 *	and passing control to the actual implementation.
 *
 */
static int
av1394_ioctl_isoch_init(av1394_inst_t *avp, void *arg, int mode)
{
	iec61883_isoch_init_t	ii;
#ifdef _MULTI_DATAMODEL
	iec61883_isoch_init32_t	ii32;
#endif
	av1394_ic_t		*icp;
	int			ret;

	if (ddi_copyin(arg, &ii, sizeof (ii), mode) != 0) {
		return (EFAULT);
	}

	ret = av1394_ic_init(avp, &ii, &icp);

	if (ret != 0) {
#ifdef _MULTI_DATAMODEL
		if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
			bcopy(&ii, &ii32, sizeof (ii32));
			ii32.ii_error = ii.ii_error;
			(void) ddi_copyout(&ii32, arg, sizeof (ii32), mode);
		} else
#endif
		(void) ddi_copyout(&ii, arg, sizeof (ii), mode);
		return (ret);
	}

#ifdef _MULTI_DATAMODEL
	/* fixup 32-bit deviations */
	if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
		bcopy(&ii, &ii32, sizeof (ii32));
		ii32.ii_mmap_off = ii.ii_mmap_off;
		ii32.ii_rchannel = ii.ii_rchannel;
		ii32.ii_error = ii.ii_error;
		ret = ddi_copyout(&ii32, arg, sizeof (ii32), mode);
	} else
#endif
	ret = ddi_copyout(&ii, arg, sizeof (ii), mode);
	if (ret != 0) {
		return (ENOMEM);
	}

	return (ret);
}

static av1394_ic_t *
av1394_ioctl_isoch_handle2ic(av1394_inst_t *avp, void *arg)
{
	int		num = (int)(intptr_t)arg;
	av1394_isoch_t	*ip = &avp->av_i;

	if (num >= NELEM(ip->i_ic)) {
		return (NULL);
	}
	return (ip->i_ic[num]);
}

/*ARGSUSED*/
static int
av1394_ioctl_isoch_fini(av1394_inst_t *avp, void *arg, int mode)
{
	av1394_ic_t	*icp;

	if ((icp = av1394_ioctl_isoch_handle2ic(avp, arg)) != NULL) {
		av1394_ic_fini(icp);
	}

	return (0);
}

/*ARGSUSED*/
static int
av1394_ioctl_start(av1394_inst_t *avp, void *arg, int mode)
{
	av1394_ic_t	*icp;
	int		ret = EINVAL;

	if ((icp = av1394_ioctl_isoch_handle2ic(avp, arg)) != NULL) {
		ret = av1394_ic_start(icp);
	}

	return (ret);
}

/*ARGSUSED*/
static int
av1394_ioctl_stop(av1394_inst_t *avp, void *arg, int mode)
{
	av1394_ic_t	*icp;
	int		ret = EINVAL;

	if ((icp = av1394_ioctl_isoch_handle2ic(avp, arg)) != NULL) {
		ret = av1394_ic_stop(icp);
	}

	return (ret);
}

static int
av1394_ioctl_recv(av1394_inst_t *avp, void *arg, int mode)
{
	av1394_isoch_t	*ip = &avp->av_i;
	av1394_ic_t	*icp;
	iec61883_recv_t	recv;
	int		num;
	int		ret = EINVAL;

	/* copyin the structure and get channel pointer */
	if (ddi_copyin(arg, &recv, sizeof (recv), mode) != 0) {
		return (EFAULT);
	}
	num = recv.rx_handle;
	if (num >= NELEM(ip->i_ic)) {
		return (EINVAL);
	}
	icp = ip->i_ic[num];

	/* now call the actual handler */
	if (icp->ic_dir != AV1394_IR) {
		ret = EINVAL;
	} else {
		ret = av1394_ir_recv(icp, &recv);
	}

	/* copyout the result */
	if (ret == 0) {
		if (ddi_copyout(&recv, arg, sizeof (recv), mode) != 0) {
			return (EFAULT);
		}
	}

	return (ret);
}

static int
av1394_ioctl_xmit(av1394_inst_t *avp, void *arg, int mode)
{
	av1394_isoch_t	*ip = &avp->av_i;
	av1394_ic_t	*icp;
	iec61883_xmit_t	xmit;
	int		num;
	int		ret = EINVAL;

	/* copyin the structure and get channel pointer */
	if (ddi_copyin(arg, &xmit, sizeof (xmit), mode) != 0) {
		return (EFAULT);
	}
	num = xmit.tx_handle;
	if (num >= NELEM(ip->i_ic)) {
		return (EINVAL);
	}
	icp = ip->i_ic[num];

	/* now call the actual handler */
	if (icp->ic_dir != AV1394_IT) {
		ret = EINVAL;
	} else {
		ret = av1394_it_xmit(icp, &xmit);
	}

	/* copyout the result */
	if (ret == 0) {
		if (ddi_copyout(&xmit, arg, sizeof (xmit), mode) != 0) {
			return (EFAULT);
		}
	}

	return (ret);
}

static uint_t
av1394_isoch_softintr(caddr_t arg)
{
	av1394_inst_t	*avp = (av1394_inst_t *)arg;
	av1394_isoch_t	*ip = &avp->av_i;
	int		i;
	uint64_t	ch;
	av1394_ic_t	*icp;

	mutex_enter(&ip->i_mutex);
	do {
		for (i = 63, ch = (1ULL << 63);
		    (i > 0) && (ip->i_softintr_ch != 0);
		    i--, ch >>= 1) {
			if ((ip->i_softintr_ch & ch) == 0) {
				continue;
			}
			ip->i_softintr_ch &= ~ch;
			icp = ip->i_ic[i];
			if (icp == NULL) {
				continue;
			}

			mutex_exit(&ip->i_mutex);
			mutex_enter(&icp->ic_mutex);
			if (icp->ic_preq & AV1394_PREQ_IR_OVERFLOW) {
				icp->ic_preq &= ~AV1394_PREQ_IR_OVERFLOW;
				av1394_ir_overflow(icp);
			}
			if (icp->ic_preq & AV1394_PREQ_IT_UNDERRUN) {
				icp->ic_preq &= ~AV1394_PREQ_IT_UNDERRUN;
				av1394_it_underrun(icp);
			}
			mutex_exit(&icp->ic_mutex);
			mutex_enter(&ip->i_mutex);
		}
	} while (ip->i_softintr_ch != 0);
	mutex_exit(&ip->i_mutex);

	return (DDI_INTR_CLAIMED);
}