Commit a31e63b6 authored by Anurag Kumar Vulisha's avatar Anurag Kumar Vulisha Committed by Felipe Balbi

usb: dwc3: gadget: Correct handling of scattergather lists

The code logic in dwc3_prepare_one_trb() incorrectly uses the address
and length fields present in req packet for mapping TRB's instead of
using the address and length fields of scattergather lists. This patch
correct's the code to use sg->address and sg->length when scattergather
lists are present.
Signed-off-by: default avatarAnurag Kumar Vulisha <anuragku@xilinx.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 5f0b74e5
...@@ -832,6 +832,7 @@ struct dwc3_hwparams { ...@@ -832,6 +832,7 @@ struct dwc3_hwparams {
* @list: a list_head used for request queueing * @list: a list_head used for request queueing
* @dep: struct dwc3_ep owning this request * @dep: struct dwc3_ep owning this request
* @sg: pointer to first incomplete sg * @sg: pointer to first incomplete sg
* @start_sg: pointer to the sg which should be queued next
* @num_pending_sgs: counter to pending sgs * @num_pending_sgs: counter to pending sgs
* @remaining: amount of data remaining * @remaining: amount of data remaining
* @epnum: endpoint number to which this request refers * @epnum: endpoint number to which this request refers
...@@ -848,6 +849,7 @@ struct dwc3_request { ...@@ -848,6 +849,7 @@ struct dwc3_request {
struct list_head list; struct list_head list;
struct dwc3_ep *dep; struct dwc3_ep *dep;
struct scatterlist *sg; struct scatterlist *sg;
struct scatterlist *start_sg;
unsigned num_pending_sgs; unsigned num_pending_sgs;
unsigned remaining; unsigned remaining;
......
...@@ -985,11 +985,19 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, ...@@ -985,11 +985,19 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
struct dwc3_request *req, unsigned chain, unsigned node) struct dwc3_request *req, unsigned chain, unsigned node)
{ {
struct dwc3_trb *trb; struct dwc3_trb *trb;
unsigned length = req->request.length; unsigned int length;
dma_addr_t dma;
unsigned stream_id = req->request.stream_id; unsigned stream_id = req->request.stream_id;
unsigned short_not_ok = req->request.short_not_ok; unsigned short_not_ok = req->request.short_not_ok;
unsigned no_interrupt = req->request.no_interrupt; unsigned no_interrupt = req->request.no_interrupt;
dma_addr_t dma = req->request.dma;
if (req->request.num_sgs > 0) {
length = sg_dma_len(req->start_sg);
dma = sg_dma_address(req->start_sg);
} else {
length = req->request.length;
dma = req->request.dma;
}
trb = &dep->trb_pool[dep->trb_enqueue]; trb = &dep->trb_pool[dep->trb_enqueue];
...@@ -1055,7 +1063,7 @@ static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep) ...@@ -1055,7 +1063,7 @@ static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
struct dwc3_request *req) struct dwc3_request *req)
{ {
struct scatterlist *sg = req->sg; struct scatterlist *sg = req->start_sg;
struct scatterlist *s; struct scatterlist *s;
int i; int i;
...@@ -1088,6 +1096,16 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, ...@@ -1088,6 +1096,16 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
dwc3_prepare_one_trb(dep, req, chain, i); dwc3_prepare_one_trb(dep, req, chain, i);
} }
/*
* There can be a situation where all sgs in sglist are not
* queued because of insufficient trb number. To handle this
* case, update start_sg to next sg to be queued, so that
* we have free trbs we can continue queuing from where we
* previously stopped
*/
if (chain)
req->start_sg = sg_next(s);
if (!dwc3_calc_trbs_left(dep)) if (!dwc3_calc_trbs_left(dep))
break; break;
} }
...@@ -1178,6 +1196,7 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep) ...@@ -1178,6 +1196,7 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep)
return; return;
req->sg = req->request.sg; req->sg = req->request.sg;
req->start_sg = req->sg;
req->num_pending_sgs = req->request.num_mapped_sgs; req->num_pending_sgs = req->request.num_mapped_sgs;
if (req->num_pending_sgs > 0) if (req->num_pending_sgs > 0)
......
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