/* Find the segment that trb is in. Start searching in start_seg. If we must move past a segment that has a link TRB with a toggle cycle state bit set, then we will toggle the value pointed at by cycle_state.  */
static struct xhci_segment* find_trb_seg(struct xhci_segment *start_seg, union xhci_trb *trb, int *cycle_state)
/* Find the segment that trb is in. Start searching in start_seg. If we must move past a segment that has a link TRB with a toggle cycle state bit set, then we will toggle the value pointed at by cycle_state.  */
static struct xhci_segment* find_trb_seg(struct xhci_segment *start_seg, union xhci_trb *trb, int *cycle_state)
{
	struct xhci_segment *cur_seg = start_seg;
	struct xhci_generic_trb *generic_trb;
	while (cur_seg->trbs > trb ||
			&cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) {
		generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic;
		if (TRB_TYPE(generic_trb->field[3]) == TRB_LINK &&
				(generic_trb->field[3] & LINK_TOGGLE))
			*cycle_state = ~(*cycle_state) & 0x1;
		cur_seg = cur_seg->next;
		if (cur_seg == start_seg)
			return 0;
	}
	return cur_seg;
}