static int ehci_qh_do_overlay(EHCIQueue *q)

{

    int i;

    int dtoggle;

    int ping;

    int eps;

    int reload;



    // remember values in fields to preserve in qh after overlay



    dtoggle = q->qh.token & QTD_TOKEN_DTOGGLE;

    ping    = q->qh.token & QTD_TOKEN_PING;



    q->qh.current_qtd = q->qtdaddr;

    q->qh.next_qtd    = q->qtd.next;

    q->qh.altnext_qtd = q->qtd.altnext;

    q->qh.token       = q->qtd.token;





    eps = get_field(q->qh.epchar, QH_EPCHAR_EPS);

    if (eps == EHCI_QH_EPS_HIGH) {

        q->qh.token &= ~QTD_TOKEN_PING;

        q->qh.token |= ping;

    }



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

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



    for (i = 0; i < 5; i++) {

        q->qh.bufptr[i] = q->qtd.bufptr[i];

    }



    if (!(q->qh.epchar & QH_EPCHAR_DTC)) {

        // preserve QH DT bit

        q->qh.token &= ~QTD_TOKEN_DTOGGLE;

        q->qh.token |= dtoggle;

    }



    q->qh.bufptr[1] &= ~BUFPTR_CPROGMASK_MASK;

    q->qh.bufptr[2] &= ~BUFPTR_FRAMETAG_MASK;



    put_dwords(NLPTR_GET(q->qhaddr), (uint32_t *) &q->qh, sizeof(EHCIqh) >> 2);



    return 0;

}

static int ehci_qh_do_overlay(EHCIQueue *q)

{

    int i;

    int dtoggle;

    int ping;

    int eps;

    int reload;



    



    dtoggle = q->qh.token & QTD_TOKEN_DTOGGLE;

    ping    = q->qh.token & QTD_TOKEN_PING;



    q->qh.current_qtd = q->qtdaddr;

    q->qh.next_qtd    = q->qtd.next;

    q->qh.altnext_qtd = q->qtd.altnext;

    q->qh.token       = q->qtd.token;





    eps = get_field(q->qh.epchar, QH_EPCHAR_EPS);

    if (eps == EHCI_QH_EPS_HIGH) {

        q->qh.token &= ~QTD_TOKEN_PING;

        q->qh.token |= ping;

    }



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

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



    for (i = 0; i < 5; i++) {

        q->qh.bufptr[i] = q->qtd.bufptr[i];

    }



    if (!(q->qh.epchar & QH_EPCHAR_DTC)) {

        

        q->qh.token &= ~QTD_TOKEN_DTOGGLE;

        q->qh.token |= dtoggle;

    }



    q->qh.bufptr[1] &= ~BUFPTR_CPROGMASK_MASK;

    q->qh.bufptr[2] &= ~BUFPTR_FRAMETAG_MASK;



    put_dwords(NLPTR_GET(q->qhaddr), (uint32_t *) &q->qh, sizeof(EHCIqh) >> 2);



    return 0;

}

static int FUNC_0(EHCIQueue *VAR_0)

{

    int VAR_1;

    int VAR_2;

    int VAR_3;

    int VAR_4;

    int VAR_5;



    



    VAR_2 = VAR_0->qh.token & QTD_TOKEN_DTOGGLE;

    VAR_3    = VAR_0->qh.token & QTD_TOKEN_PING;



    VAR_0->qh.current_qtd = VAR_0->qtdaddr;

    VAR_0->qh.next_qtd    = VAR_0->qtd.next;

    VAR_0->qh.altnext_qtd = VAR_0->qtd.altnext;

    VAR_0->qh.token       = VAR_0->qtd.token;





    VAR_4 = get_field(VAR_0->qh.epchar, QH_EPCHAR_EPS);

    if (VAR_4 == EHCI_QH_EPS_HIGH) {

        VAR_0->qh.token &= ~QTD_TOKEN_PING;

        VAR_0->qh.token |= VAR_3;

    }



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

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



    for (VAR_1 = 0; VAR_1 < 5; VAR_1++) {

        VAR_0->qh.bufptr[VAR_1] = VAR_0->qtd.bufptr[VAR_1];

    }



    if (!(VAR_0->qh.epchar & QH_EPCHAR_DTC)) {

        

        VAR_0->qh.token &= ~QTD_TOKEN_DTOGGLE;

        VAR_0->qh.token |= VAR_2;

    }



    VAR_0->qh.bufptr[1] &= ~BUFPTR_CPROGMASK_MASK;

    VAR_0->qh.bufptr[2] &= ~BUFPTR_FRAMETAG_MASK;



    put_dwords(NLPTR_GET(VAR_0->qhaddr), (uint32_t *) &VAR_0->qh, sizeof(EHCIqh) >> 2);



    return 0;

}

static int FUNC_0(EHCIQueue *VAR_0)
{ int VAR_1; int VAR_2; int VAR_3; int VAR_4; int VAR_5; VAR_2 = VAR_0->qh.token & QTD_TOKEN_DTOGGLE; VAR_3    = VAR_0->qh.token & QTD_TOKEN_PING; VAR_0->qh.current_qtd = VAR_0->qtdaddr; VAR_0->qh.next_qtd    = VAR_0->qtd.next; VAR_0->qh.altnext_qtd = VAR_0->qtd.altnext; VAR_0->qh.token       = VAR_0->qtd.token; VAR_4 = get_field(VAR_0->qh.epchar, QH_EPCHAR_EPS); if (VAR_4 == EHCI_QH_EPS_HIGH) { VAR_0->qh.token &= ~QTD_TOKEN_PING; VAR_0->qh.token |= VAR_3; } VAR_5 = get_field(VAR_0->qh.epchar, QH_EPCHAR_RL); set_field(&VAR_0->qh.altnext_qtd, VAR_5, QH_ALTNEXT_NAKCNT); for (VAR_1 = 0; VAR_1 < 5; VAR_1++) { VAR_0->qh.bufptr[VAR_1] = VAR_0->qtd.bufptr[VAR_1]; } if (!(VAR_0->qh.epchar & QH_EPCHAR_DTC)) { VAR_0->qh.token &= ~QTD_TOKEN_DTOGGLE; VAR_0->qh.token |= VAR_2; } VAR_0->qh.bufptr[1] &= ~BUFPTR_CPROGMASK_MASK; VAR_0->qh.bufptr[2] &= ~BUFPTR_FRAMETAG_MASK; put_dwords(NLPTR_GET(VAR_0->qhaddr), (uint32_t *) &VAR_0->qh, sizeof(EHCIqh) >> 2); return 0; }