static int ehci_state_executing(EHCIQueue *q, int async)

{

    int again = 0;

    int reload, nakcnt;



    ehci_execute_complete(q);

    if (q->usb_status == USB_RET_ASYNC) {

        goto out;

    }

    if (q->usb_status == USB_RET_PROCERR) {

        again = -1;

        goto out;

    }



    // 4.10.3

    if (!async) {

        int transactCtr = get_field(q->qh.epcap, QH_EPCAP_MULT);

        transactCtr--;

        set_field(&q->qh.epcap, transactCtr, QH_EPCAP_MULT);

        // 4.10.3, bottom of page 82, should exit this state when transaction

        // counter decrements to 0

    }



    reload = get_field(q->qh.epchar, QH_EPCHAR_RL);

    if (reload) {

        nakcnt = get_field(q->qh.altnext_qtd, QH_ALTNEXT_NAKCNT);

        if (q->usb_status == USB_RET_NAK) {

            if (nakcnt) {

                nakcnt--;

            }

        } else {

            nakcnt = reload;

        }

        set_field(&q->qh.altnext_qtd, nakcnt, QH_ALTNEXT_NAKCNT);

    }



    /* 4.10.5 */

    if ((q->usb_status == USB_RET_NAK) || (q->qh.token & QTD_TOKEN_ACTIVE)) {

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

    } else {

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

    }



    again = 1;



out:

    ehci_flush_qh(q);

    return again;

}

static int ehci_state_executing(EHCIQueue *q, int async)

{

    int again = 0;

    int reload, nakcnt;



    ehci_execute_complete(q);

    if (q->usb_status == USB_RET_ASYNC) {

        goto out;

    }

    if (q->usb_status == USB_RET_PROCERR) {

        again = -1;

        goto out;

    }



    

    if (!async) {

        int transactCtr = get_field(q->qh.epcap, QH_EPCAP_MULT);

        transactCtr--;

        set_field(&q->qh.epcap, transactCtr, QH_EPCAP_MULT);

        , bottom of page 82, should exit this state when transaction

        

    }



    reload = get_field(q->qh.epchar, QH_EPCHAR_RL);

    if (reload) {

        nakcnt = get_field(q->qh.altnext_qtd, QH_ALTNEXT_NAKCNT);

        if (q->usb_status == USB_RET_NAK) {

            if (nakcnt) {

                nakcnt--;

            }

        } else {

            nakcnt = reload;

        }

        set_field(&q->qh.altnext_qtd, nakcnt, QH_ALTNEXT_NAKCNT);

    }



    

    if ((q->usb_status == USB_RET_NAK) || (q->qh.token & QTD_TOKEN_ACTIVE)) {

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

    } else {

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

    }



    again = 1;



out:

    ehci_flush_qh(q);

    return again;

}

static int FUNC_0(EHCIQueue *VAR_0, int VAR_1)

{

    int VAR_2 = 0;

    int VAR_3, VAR_4;



    ehci_execute_complete(VAR_0);

    if (VAR_0->usb_status == USB_RET_ASYNC) {

        goto out;

    }

    if (VAR_0->usb_status == USB_RET_PROCERR) {

        VAR_2 = -1;

        goto out;

    }



    

    if (!VAR_1) {

        int VAR_5 = get_field(VAR_0->qh.epcap, QH_EPCAP_MULT);

        VAR_5--;

        set_field(&VAR_0->qh.epcap, VAR_5, QH_EPCAP_MULT);

        , bottom of page 82, should exit this state when transaction

        

    }



    VAR_3 = get_field(VAR_0->qh.epchar, QH_EPCHAR_RL);

    if (VAR_3) {

        VAR_4 = get_field(VAR_0->qh.altnext_qtd, QH_ALTNEXT_NAKCNT);

        if (VAR_0->usb_status == USB_RET_NAK) {

            if (VAR_4) {

                VAR_4--;

            }

        } else {

            VAR_4 = VAR_3;

        }

        set_field(&VAR_0->qh.altnext_qtd, VAR_4, QH_ALTNEXT_NAKCNT);

    }



    

    if ((VAR_0->usb_status == USB_RET_NAK) || (VAR_0->qh.token & QTD_TOKEN_ACTIVE)) {

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

    } else {

        ehci_set_state(VAR_0->ehci, VAR_1, EST_WRITEBACK);

    }



    VAR_2 = 1;



out:

    ehci_flush_qh(VAR_0);

    return VAR_2;

}

static int FUNC_0(EHCIQueue *VAR_0, int VAR_1)
{ int VAR_2 = 0; int VAR_3, VAR_4; ehci_execute_complete(VAR_0); if (VAR_0->usb_status == USB_RET_ASYNC) { goto out; } if (VAR_0->usb_status == USB_RET_PROCERR) { VAR_2 = -1; goto out; } if (!VAR_1) { int VAR_5 = get_field(VAR_0->qh.epcap, QH_EPCAP_MULT); VAR_5--; set_field(&VAR_0->qh.epcap, VAR_5, QH_EPCAP_MULT); , bottom of page 82, should exit this state when transaction
} VAR_3 = get_field(VAR_0->qh.epchar, QH_EPCHAR_RL); if (VAR_3) { VAR_4 = get_field(VAR_0->qh.altnext_qtd, QH_ALTNEXT_NAKCNT); if (VAR_0->usb_status == USB_RET_NAK) { if (VAR_4) { VAR_4--; } } else { VAR_4 = VAR_3; } set_field(&VAR_0->qh.altnext_qtd, VAR_4, QH_ALTNEXT_NAKCNT); } if ((VAR_0->usb_status == USB_RET_NAK) || (VAR_0->qh.token & QTD_TOKEN_ACTIVE)) { ehci_set_state(VAR_0->ehci, VAR_1, EST_HORIZONTALQH); } else { ehci_set_state(VAR_0->ehci, VAR_1, EST_WRITEBACK); } VAR_2 = 1; out:
ehci_flush_qh(VAR_0); return VAR_2; }