static int ehci_state_fetchqtd(EHCIQueue *q)

{

    EHCIqtd qtd;

    EHCIPacket *p;

    int again = 0;



    get_dwords(q->ehci, NLPTR_GET(q->qtdaddr), (uint32_t *) &qtd,

               sizeof(EHCIqtd) >> 2);

    ehci_trace_qtd(q, NLPTR_GET(q->qtdaddr), &qtd);



    p = QTAILQ_FIRST(&q->packets);

    if (p != NULL) {

        if (p->qtdaddr != q->qtdaddr ||

            (!NLPTR_TBIT(p->qtd.next) && (p->qtd.next != qtd.next)) ||

            (!NLPTR_TBIT(p->qtd.altnext) && (p->qtd.altnext != qtd.altnext)) ||

            p->qtd.bufptr[0] != qtd.bufptr[0]) {

            ehci_cancel_queue(q);

            ehci_trace_guest_bug(q->ehci, "guest updated active QH or qTD");

            p = NULL;

        } else {

            p->qtd = qtd;

            ehci_qh_do_overlay(q);

        }

    }



    if (!(qtd.token & QTD_TOKEN_ACTIVE)) {

        if (p != NULL) {

            /* transfer canceled by guest (clear active) */

            ehci_cancel_queue(q);

            p = NULL;

        }

        ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH);

        again = 1;

    } else if (p != NULL) {

        switch (p->async) {

        case EHCI_ASYNC_NONE:

        case EHCI_ASYNC_INITIALIZED:

            /* Not yet executed (MULT), or previously nacked (int) packet */

            ehci_set_state(q->ehci, q->async, EST_EXECUTE);

            break;

        case EHCI_ASYNC_INFLIGHT:

            /* Unfinished async handled packet, go horizontal */

            ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH);

            break;

        case EHCI_ASYNC_FINISHED:

            /*

             * We get here when advqueue moves to a packet which is already

             * finished, which can happen with packets queued up by fill_queue

             */

            ehci_set_state(q->ehci, q->async, EST_EXECUTING);

            break;

        }

        again = 1;

    } else {

        p = ehci_alloc_packet(q);

        p->qtdaddr = q->qtdaddr;

        p->qtd = qtd;

        ehci_set_state(q->ehci, q->async, EST_EXECUTE);

        again = 1;

    }



    return again;

}

static int ehci_state_fetchqtd(EHCIQueue *q)

{

    EHCIqtd qtd;

    EHCIPacket *p;

    int again = 0;



    get_dwords(q->ehci, NLPTR_GET(q->qtdaddr), (uint32_t *) &qtd,

               sizeof(EHCIqtd) >> 2);

    ehci_trace_qtd(q, NLPTR_GET(q->qtdaddr), &qtd);



    p = QTAILQ_FIRST(&q->packets);

    if (p != NULL) {

        if (p->qtdaddr != q->qtdaddr ||

            (!NLPTR_TBIT(p->qtd.next) && (p->qtd.next != qtd.next)) ||

            (!NLPTR_TBIT(p->qtd.altnext) && (p->qtd.altnext != qtd.altnext)) ||

            p->qtd.bufptr[0] != qtd.bufptr[0]) {

            ehci_cancel_queue(q);

            ehci_trace_guest_bug(q->ehci, "guest updated active QH or qTD");

            p = NULL;

        } else {

            p->qtd = qtd;

            ehci_qh_do_overlay(q);

        }

    }



    if (!(qtd.token & QTD_TOKEN_ACTIVE)) {

        if (p != NULL) {

            

            ehci_cancel_queue(q);

            p = NULL;

        }

        ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH);

        again = 1;

    } else if (p != NULL) {

        switch (p->async) {

        case EHCI_ASYNC_NONE:

        case EHCI_ASYNC_INITIALIZED:

            

            ehci_set_state(q->ehci, q->async, EST_EXECUTE);

            break;

        case EHCI_ASYNC_INFLIGHT:

            

            ehci_set_state(q->ehci, q->async, EST_HORIZONTALQH);

            break;

        case EHCI_ASYNC_FINISHED:

            







            ehci_set_state(q->ehci, q->async, EST_EXECUTING);

            break;

        }

        again = 1;

    } else {

        p = ehci_alloc_packet(q);

        p->qtdaddr = q->qtdaddr;

        p->qtd = qtd;

        ehci_set_state(q->ehci, q->async, EST_EXECUTE);

        again = 1;

    }



    return again;

}

static int FUNC_0(EHCIQueue *VAR_0)

{

    EHCIqtd qtd;

    EHCIPacket *p;

    int VAR_1 = 0;



    get_dwords(VAR_0->ehci, NLPTR_GET(VAR_0->qtdaddr), (uint32_t *) &qtd,

               sizeof(EHCIqtd) >> 2);

    ehci_trace_qtd(VAR_0, NLPTR_GET(VAR_0->qtdaddr), &qtd);



    p = QTAILQ_FIRST(&VAR_0->packets);

    if (p != NULL) {

        if (p->qtdaddr != VAR_0->qtdaddr ||

            (!NLPTR_TBIT(p->qtd.next) && (p->qtd.next != qtd.next)) ||

            (!NLPTR_TBIT(p->qtd.altnext) && (p->qtd.altnext != qtd.altnext)) ||

            p->qtd.bufptr[0] != qtd.bufptr[0]) {

            ehci_cancel_queue(VAR_0);

            ehci_trace_guest_bug(VAR_0->ehci, "guest updated active QH or qTD");

            p = NULL;

        } else {

            p->qtd = qtd;

            ehci_qh_do_overlay(VAR_0);

        }

    }



    if (!(qtd.token & QTD_TOKEN_ACTIVE)) {

        if (p != NULL) {

            

            ehci_cancel_queue(VAR_0);

            p = NULL;

        }

        ehci_set_state(VAR_0->ehci, VAR_0->async, EST_HORIZONTALQH);

        VAR_1 = 1;

    } else if (p != NULL) {

        switch (p->async) {

        case EHCI_ASYNC_NONE:

        case EHCI_ASYNC_INITIALIZED:

            

            ehci_set_state(VAR_0->ehci, VAR_0->async, EST_EXECUTE);

            break;

        case EHCI_ASYNC_INFLIGHT:

            

            ehci_set_state(VAR_0->ehci, VAR_0->async, EST_HORIZONTALQH);

            break;

        case EHCI_ASYNC_FINISHED:

            







            ehci_set_state(VAR_0->ehci, VAR_0->async, EST_EXECUTING);

            break;

        }

        VAR_1 = 1;

    } else {

        p = ehci_alloc_packet(VAR_0);

        p->qtdaddr = VAR_0->qtdaddr;

        p->qtd = qtd;

        ehci_set_state(VAR_0->ehci, VAR_0->async, EST_EXECUTE);

        VAR_1 = 1;

    }



    return VAR_1;

}

static int FUNC_0(EHCIQueue *VAR_0)
{ EHCIqtd qtd; EHCIPacket *p; int VAR_1 = 0; get_dwords(VAR_0->ehci, NLPTR_GET(VAR_0->qtdaddr), (uint32_t *) &qtd,
sizeof(EHCIqtd) >> 2); ehci_trace_qtd(VAR_0, NLPTR_GET(VAR_0->qtdaddr), &qtd); p = QTAILQ_FIRST(&VAR_0->packets); if (p != NULL) { if (p->qtdaddr != VAR_0->qtdaddr ||
(!NLPTR_TBIT(p->qtd.next) && (p->qtd.next != qtd.next)) ||
(!NLPTR_TBIT(p->qtd.altnext) && (p->qtd.altnext != qtd.altnext)) ||
p->qtd.bufptr[0] != qtd.bufptr[0]) { ehci_cancel_queue(VAR_0); ehci_trace_guest_bug(VAR_0->ehci, "guest updated active QH or qTD"); p = NULL; } else { p->qtd = qtd; ehci_qh_do_overlay(VAR_0); } } if (!(qtd.token & QTD_TOKEN_ACTIVE)) { if (p != NULL) { ehci_cancel_queue(VAR_0); p = NULL; } ehci_set_state(VAR_0->ehci, VAR_0->async, EST_HORIZONTALQH); VAR_1 = 1; } else if (p != NULL) { switch (p->async) { case EHCI_ASYNC_NONE:
case EHCI_ASYNC_INITIALIZED:
ehci_set_state(VAR_0->ehci, VAR_0->async, EST_EXECUTE); break; case EHCI_ASYNC_INFLIGHT:
ehci_set_state(VAR_0->ehci, VAR_0->async, EST_HORIZONTALQH); break; case EHCI_ASYNC_FINISHED:
ehci_set_state(VAR_0->ehci, VAR_0->async, EST_EXECUTING); break; } VAR_1 = 1; } else { p = ehci_alloc_packet(VAR_0); p->qtdaddr = VAR_0->qtdaddr; p->qtd = qtd; ehci_set_state(VAR_0->ehci, VAR_0->async, EST_EXECUTE); VAR_1 = 1; } return VAR_1; }