FreeBSD/sys/dev/firewire/firewire.c
/*
 * To allocate unique transaction label.
 */
To allocate unique transaction label.
To allocate unique transaction label .
static int
fw_get_tlabel(struct firewire_comm *fc, struct fw_xfer *xfer)
{
	u_int dst, new_tlabel;
	struct fw_xfer *txfer;
	int s;
	dst = xfer->send.hdr.mode.hdr.dst & 0x3f;
	s = splfw();
	mtx_lock(&fc->tlabel_lock);
	new_tlabel = (fc->last_tlabel[dst] + 1) & 0x3f;
	STAILQ_FOREACH(txfer, &fc->tlabels[new_tlabel], tlabel)
		if ((txfer->send.hdr.mode.hdr.dst & 0x3f) == dst)
			break;
	if (txfer == NULL) {
		fc->last_tlabel[dst] = new_tlabel;
		STAILQ_INSERT_TAIL(&fc->tlabels[new_tlabel], xfer, tlabel);
		mtx_unlock(&fc->tlabel_lock);
		splx(s);
		xfer->tl = new_tlabel;
		xfer->send.hdr.mode.hdr.tlrt = new_tlabel << 2;
		if (firewire_debug > 1)
			printf("fw_get_tlabel: dst=%d tl=%d\n", dst, new_tlabel);
		return (new_tlabel);
	}
	mtx_unlock(&fc->tlabel_lock);
	splx(s);
	if (firewire_debug > 1)
		printf("fw_get_tlabel: no free tlabel\n");
	return (-1);
}
static int fw_get_tlabel ( struct firewire_comm * fc , struct fw_xfer * xfer ) { u_int dst , new_tlabel ; struct fw_xfer * txfer ; int s ; dst = xfer -> send . hdr . mode . hdr . dst & 0x3f ; s = splfw ( ) ; mtx_lock ( & fc -> tlabel_lock ) ; new_tlabel = ( fc -> last_tlabel [ dst ] + 1 ) & 0x3f ; STAILQ_FOREACH ( txfer , & fc -> tlabels [ new_tlabel ] , tlabel ) if ( ( txfer -> send . hdr . mode . hdr . dst & 0x3f ) == dst ) break ; if ( txfer == NULL ) { fc -> last_tlabel [ dst ] = new_tlabel ; STAILQ_INSERT_TAIL ( & fc -> tlabels [ new_tlabel ] , xfer , tlabel ) ; mtx_unlock ( & fc -> tlabel_lock ) ; splx ( s ) ; xfer -> tl = new_tlabel ; xfer -> send . hdr . mode . hdr . tlrt = new_tlabel << 2 ; if ( firewire_debug > 1 ) printf ( " \n " , dst , new_tlabel ) ; return ( new_tlabel ) ; } mtx_unlock ( & fc -> tlabel_lock ) ; splx ( s ) ; if ( firewire_debug > 1 ) printf ( " \n " ) ; return ( -1 ) ; }
To allocate unique transaction label.
To allocate unique transaction label .