Commit 0b6c324c authored by Mathias Nyman's avatar Mathias Nyman Committed by Greg Kroah-Hartman

xhci: cleanup and refactor process_ctrl_td()

Refactor pricess_ctrl_tx() to make it more readable
No functional changes
Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 52ab8685
...@@ -1932,6 +1932,8 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td, ...@@ -1932,6 +1932,8 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
int ep_index; int ep_index;
struct xhci_ep_ctx *ep_ctx; struct xhci_ep_ctx *ep_ctx;
u32 trb_comp_code; u32 trb_comp_code;
u32 remaining, requested;
bool on_data_stage;
slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
xdev = xhci->devs[slot_id]; xdev = xhci->devs[slot_id];
...@@ -1939,89 +1941,74 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td, ...@@ -1939,89 +1941,74 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer)); ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer));
ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len));
requested = td->urb->transfer_buffer_length;
remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
/* not setup (dequeue), or status stage means we are at data stage */
on_data_stage = (event_trb != ep_ring->dequeue &&
event_trb != td->last_trb);
switch (trb_comp_code) { switch (trb_comp_code) {
case COMP_SUCCESS: case COMP_SUCCESS:
if (event_trb == ep_ring->dequeue) { if (event_trb != td->last_trb) {
xhci_warn(xhci, "WARN: Success on ctrl setup TRB " xhci_warn(xhci, "WARN: Success on ctrl %s TRB without IOC set?\n",
"without IOC set??\n"); on_data_stage ? "data" : "setup");
*status = -ESHUTDOWN;
} else if (event_trb != td->last_trb) {
xhci_warn(xhci, "WARN: Success on ctrl data TRB "
"without IOC set??\n");
*status = -ESHUTDOWN; *status = -ESHUTDOWN;
} else { break;
*status = 0;
} }
*status = 0;
break; break;
case COMP_SHORT_TX: case COMP_SHORT_TX:
*status = 0; *status = 0;
break; break;
case COMP_STOP_SHORT: case COMP_STOP_SHORT:
if (event_trb == ep_ring->dequeue || event_trb == td->last_trb) if (on_data_stage)
xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl setup or status TRB\n"); td->urb->actual_length = remaining;
else else
td->urb->actual_length = xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl setup or status TRB\n");
EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); goto finish_td;
return finish_td(xhci, td, event_trb, event, ep, status, false);
case COMP_STOP: case COMP_STOP:
/* Did we stop at data stage? */ if (on_data_stage)
if (event_trb != ep_ring->dequeue && event_trb != td->last_trb) td->urb->actual_length = requested - remaining;
td->urb->actual_length = goto finish_td;
td->urb->transfer_buffer_length -
EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
/* fall through */
case COMP_STOP_INVAL: case COMP_STOP_INVAL:
return finish_td(xhci, td, event_trb, event, ep, status, false); goto finish_td;
default: default:
if (!xhci_requires_manual_halt_cleanup(xhci, if (!xhci_requires_manual_halt_cleanup(xhci,
ep_ctx, trb_comp_code)) ep_ctx, trb_comp_code))
break; break;
xhci_dbg(xhci, "TRB error code %u, " xhci_dbg(xhci, "TRB error %u, halted endpoint index = %u\n",
"halted endpoint index = %u\n", trb_comp_code, ep_index);
trb_comp_code, ep_index);
/* else fall through */ /* else fall through */
case COMP_STALL: case COMP_STALL:
/* Did we transfer part of the data (middle) phase? */ /* Did we transfer part of the data (middle) phase? */
if (event_trb != ep_ring->dequeue && if (on_data_stage)
event_trb != td->last_trb) td->urb->actual_length = requested - remaining;
td->urb->actual_length =
td->urb->transfer_buffer_length -
EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
else if (!td->urb_length_set) else if (!td->urb_length_set)
td->urb->actual_length = 0; td->urb->actual_length = 0;
goto finish_td;
return finish_td(xhci, td, event_trb, event, ep, status, false);
} }
/* stopped at setup stage, no data transferred */
if (event_trb == ep_ring->dequeue)
goto finish_td;
/* /*
* Did we transfer any data, despite the errors that might have * if on data stage then update the actual_length of the URB and flag it
* happened? I.e. did we get past the setup stage? * as set, so it won't be overwritten in the event for the last TRB.
*/ */
if (event_trb != ep_ring->dequeue) { if (on_data_stage) {
/* The event was for the status stage */ td->urb_length_set = true;
if (event_trb == td->last_trb) { td->urb->actual_length = requested - remaining;
if (!td->urb_length_set) { xhci_dbg(xhci, "Waiting for status stage event\n");
td->urb->actual_length = return 0;
td->urb->transfer_buffer_length;
}
} else {
/*
* Maybe the event was for the data stage? If so, update
* already the actual_length of the URB and flag it as
* set, so that it is not overwritten in the event for
* the last TRB.
*/
td->urb_length_set = true;
td->urb->actual_length =
td->urb->transfer_buffer_length -
EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
xhci_dbg(xhci, "Waiting for status "
"stage event\n");
return 0;
}
} }
/* at status stage */
if (!td->urb_length_set)
td->urb->actual_length = requested;
finish_td:
return finish_td(xhci, td, event_trb, event, ep, status, false); return finish_td(xhci, td, event_trb, event, ep, status, false);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment