Commit 5ee85d89 authored by Felipe Balbi's avatar Felipe Balbi

usb: dwc3: gadget: split __dwc3_gadget_kick_transfer()

To aid code readability, we're gonna split
__dwc3_gadget_kick_transfer() into its constituent
parts: scatter gather and linear buffers.

That way, it's easier to follow the code and focus
debug effort when one or the other fails.
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 6b742899
......@@ -903,33 +903,15 @@ static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
return dep->trb_dequeue - dep->trb_enqueue;
}
/*
* dwc3_prepare_trbs - setup TRBs from requests
* @dep: endpoint for which requests are being prepared
*
* The function goes through the requests list and sets up TRBs for the
* transfers. The function returns once there are no more TRBs available or
* it runs out of requests.
*/
static void dwc3_prepare_trbs(struct dwc3_ep *dep)
static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
struct dwc3_request *req, unsigned int trbs_left)
{
struct dwc3_request *req, *n;
u32 trbs_left;
unsigned int last_one = 0;
BUILD_BUG_ON_NOT_POWER_OF_2(DWC3_TRB_NUM);
trbs_left = dwc3_calc_trbs_left(dep);
list_for_each_entry_safe(req, n, &dep->pending_list, list) {
unsigned length;
dma_addr_t dma;
last_one = false;
if (req->request.num_mapped_sgs > 0) {
struct usb_request *request = &req->request;
struct scatterlist *sg = request->sg;
struct scatterlist *s;
unsigned int last = false;
unsigned int length;
dma_addr_t dma;
int i;
for_each_sg(sg, s, request->num_mapped_sgs, i) {
......@@ -940,45 +922,71 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep)
if (sg_is_last(s)) {
if (list_is_last(&req->list, &dep->pending_list))
last_one = true;
last = true;
chain = false;
}
trbs_left--;
if (!trbs_left)
last_one = true;
last = true;
if (last_one)
if (last)
chain = false;
dwc3_prepare_one_trb(dep, req, dma, length,
last_one, chain, i);
last, chain, i);
if (last_one)
if (last)
break;
}
}
static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep,
struct dwc3_request *req, unsigned int trbs_left)
{
unsigned int last = false;
unsigned int length;
dma_addr_t dma;
if (last_one)
break;
} else {
dma = req->request.dma;
length = req->request.length;
trbs_left--;
if (!trbs_left)
last_one = true;
last = true;
/* Is this the last request? */
if (list_is_last(&req->list, &dep->pending_list))
last_one = true;
last = true;
dwc3_prepare_one_trb(dep, req, dma, length,
last_one, false, 0);
last, false, 0);
}
if (last_one)
break;
}
/*
* dwc3_prepare_trbs - setup TRBs from requests
* @dep: endpoint for which requests are being prepared
*
* The function goes through the requests list and sets up TRBs for the
* transfers. The function returns once there are no more TRBs available or
* it runs out of requests.
*/
static void dwc3_prepare_trbs(struct dwc3_ep *dep)
{
struct dwc3_request *req, *n;
u32 trbs_left;
BUILD_BUG_ON_NOT_POWER_OF_2(DWC3_TRB_NUM);
trbs_left = dwc3_calc_trbs_left(dep);
list_for_each_entry_safe(req, n, &dep->pending_list, list) {
if (req->request.num_mapped_sgs > 0)
dwc3_prepare_one_trb_sg(dep, req, trbs_left--);
else
dwc3_prepare_one_trb_linear(dep, req, trbs_left--);
if (!trbs_left)
return;
}
}
......
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