static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)

{

    XHCITRB *trb_setup, *trb_status;

    uint8_t bmRequestType;



    trb_setup = &xfer->trbs[0];

    trb_status = &xfer->trbs[xfer->trb_count-1];



    trace_usb_xhci_xfer_start(xfer, xfer->epctx->slotid,

                              xfer->epctx->epid, xfer->streamid);



    /* at most one Event Data TRB allowed after STATUS */

    if (TRB_TYPE(*trb_status) == TR_EVDATA && xfer->trb_count > 2) {

        trb_status--;

    }



    /* do some sanity checks */

    if (TRB_TYPE(*trb_setup) != TR_SETUP) {

        DPRINTF("xhci: ep0 first TD not SETUP: %d\n",

                TRB_TYPE(*trb_setup));

        return -1;

    }

    if (TRB_TYPE(*trb_status) != TR_STATUS) {

        DPRINTF("xhci: ep0 last TD not STATUS: %d\n",

                TRB_TYPE(*trb_status));

        return -1;

    }

    if (!(trb_setup->control & TRB_TR_IDT)) {

        DPRINTF("xhci: Setup TRB doesn't have IDT set\n");

        return -1;

    }

    if ((trb_setup->status & 0x1ffff) != 8) {

        DPRINTF("xhci: Setup TRB has bad length (%d)\n",

                (trb_setup->status & 0x1ffff));

        return -1;

    }



    bmRequestType = trb_setup->parameter;



    xfer->in_xfer = bmRequestType & USB_DIR_IN;

    xfer->iso_xfer = false;

    xfer->timed_xfer = false;



    if (xhci_setup_packet(xfer) < 0) {

        return -1;

    }

    xfer->packet.parameter = trb_setup->parameter;



    usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);



    xhci_try_complete_packet(xfer);

    if (!xfer->running_async && !xfer->running_retry) {

        xhci_kick_epctx(xfer->epctx, 0);

    }

    return 0;

}

static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)

{

    XHCITRB *trb_setup, *trb_status;

    uint8_t bmRequestType;



    trb_setup = &xfer->trbs[0];

    trb_status = &xfer->trbs[xfer->trb_count-1];



    trace_usb_xhci_xfer_start(xfer, xfer->epctx->slotid,

                              xfer->epctx->epid, xfer->streamid);



    

    if (TRB_TYPE(*trb_status) == TR_EVDATA && xfer->trb_count > 2) {

        trb_status--;

    }



    

    if (TRB_TYPE(*trb_setup) != TR_SETUP) {

        DPRINTF("xhci: ep0 first TD not SETUP: %d\n",

                TRB_TYPE(*trb_setup));

        return -1;

    }

    if (TRB_TYPE(*trb_status) != TR_STATUS) {

        DPRINTF("xhci: ep0 last TD not STATUS: %d\n",

                TRB_TYPE(*trb_status));

        return -1;

    }

    if (!(trb_setup->control & TRB_TR_IDT)) {

        DPRINTF("xhci: Setup TRB doesn't have IDT set\n");

        return -1;

    }

    if ((trb_setup->status & 0x1ffff) != 8) {

        DPRINTF("xhci: Setup TRB has bad length (%d)\n",

                (trb_setup->status & 0x1ffff));

        return -1;

    }



    bmRequestType = trb_setup->parameter;



    xfer->in_xfer = bmRequestType & USB_DIR_IN;

    xfer->iso_xfer = false;

    xfer->timed_xfer = false;



    if (xhci_setup_packet(xfer) < 0) {

        return -1;

    }

    xfer->packet.parameter = trb_setup->parameter;



    usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);



    xhci_try_complete_packet(xfer);

    if (!xfer->running_async && !xfer->running_retry) {

        xhci_kick_epctx(xfer->epctx, 0);

    }

    return 0;

}

static int FUNC_0(XHCIState *VAR_0, XHCITransfer *VAR_1)

{

    XHCITRB *trb_setup, *trb_status;

    uint8_t bmRequestType;



    trb_setup = &VAR_1->trbs[0];

    trb_status = &VAR_1->trbs[VAR_1->trb_count-1];



    trace_usb_xhci_xfer_start(VAR_1, VAR_1->epctx->slotid,

                              VAR_1->epctx->epid, VAR_1->streamid);



    

    if (TRB_TYPE(*trb_status) == TR_EVDATA && VAR_1->trb_count > 2) {

        trb_status--;

    }



    

    if (TRB_TYPE(*trb_setup) != TR_SETUP) {

        DPRINTF("VAR_0: ep0 first TD not SETUP: %d\n",

                TRB_TYPE(*trb_setup));

        return -1;

    }

    if (TRB_TYPE(*trb_status) != TR_STATUS) {

        DPRINTF("VAR_0: ep0 last TD not STATUS: %d\n",

                TRB_TYPE(*trb_status));

        return -1;

    }

    if (!(trb_setup->control & TRB_TR_IDT)) {

        DPRINTF("VAR_0: Setup TRB doesn't have IDT set\n");

        return -1;

    }

    if ((trb_setup->status & 0x1ffff) != 8) {

        DPRINTF("VAR_0: Setup TRB has bad length (%d)\n",

                (trb_setup->status & 0x1ffff));

        return -1;

    }



    bmRequestType = trb_setup->parameter;



    VAR_1->in_xfer = bmRequestType & USB_DIR_IN;

    VAR_1->iso_xfer = false;

    VAR_1->timed_xfer = false;



    if (xhci_setup_packet(VAR_1) < 0) {

        return -1;

    }

    VAR_1->packet.parameter = trb_setup->parameter;



    usb_handle_packet(VAR_1->packet.ep->dev, &VAR_1->packet);



    xhci_try_complete_packet(VAR_1);

    if (!VAR_1->running_async && !VAR_1->running_retry) {

        xhci_kick_epctx(VAR_1->epctx, 0);

    }

    return 0;

}

static int FUNC_0(XHCIState *VAR_0, XHCITransfer *VAR_1)
{ XHCITRB *trb_setup, *trb_status; uint8_t bmRequestType; trb_setup = &VAR_1->trbs[0]; trb_status = &VAR_1->trbs[VAR_1->trb_count-1]; trace_usb_xhci_xfer_start(VAR_1, VAR_1->epctx->slotid,
VAR_1->epctx->epid, VAR_1->streamid); if (TRB_TYPE(*trb_status) == TR_EVDATA && VAR_1->trb_count > 2) { trb_status--; } if (TRB_TYPE(*trb_setup) != TR_SETUP) { DPRINTF("VAR_0: ep0 first TD not SETUP: %d\n",
TRB_TYPE(*trb_setup)); return -1; } if (TRB_TYPE(*trb_status) != TR_STATUS) { DPRINTF("VAR_0: ep0 last TD not STATUS: %d\n",
TRB_TYPE(*trb_status)); return -1; } if (!(trb_setup->control & TRB_TR_IDT)) { DPRINTF("VAR_0: Setup TRB doesn't have IDT set\n"); return -1; } if ((trb_setup->status & 0x1ffff) != 8) { DPRINTF("VAR_0: Setup TRB has bad length (%d)\n",
(trb_setup->status & 0x1ffff)); return -1; } bmRequestType = trb_setup->parameter; VAR_1->in_xfer = bmRequestType & USB_DIR_IN; VAR_1->iso_xfer = false; VAR_1->timed_xfer = false; if (xhci_setup_packet(VAR_1) < 0) { return -1; } VAR_1->packet.parameter = trb_setup->parameter; usb_handle_packet(VAR_1->packet.ep->dev, &VAR_1->packet); xhci_try_complete_packet(VAR_1); if (!VAR_1->running_async && !VAR_1->running_retry) { xhci_kick_epctx(VAR_1->epctx, 0); } return 0; }