Commit b203d0a2 authored by Robert Baldyga's avatar Robert Baldyga Committed by Greg Kroah-Hartman

usb: dwc2/gadget: assign TX FIFO dynamically

Because we have not enough memory to have each TX FIFO of size at least
3072 bytes (the maximum single packet size with 3 transactions per
microframe), we create four FIFOs of lenght 1024, and four of length
3072 bytes, and assing them to endpoints dynamically according to
maxpacket size value of given endpoint.

Up to now there were initialized 16 TX FIFOs, but we use only 8 IN
endpoints, so we can split available memory for 8 FIFOs to have more
memory for each one.

It needed to do some small modifications in few places in code, because
there was assumption that TX FIFO numbers assigned to endpoints are the
same as the endpoint numbers, which is not true since we have dynamic
FIFO assigning.
Signed-off-by: default avatarRobert Baldyga <r.baldyga@samsung.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cff9eb75
...@@ -139,6 +139,7 @@ struct s3c_hsotg_ep { ...@@ -139,6 +139,7 @@ struct s3c_hsotg_ep {
unsigned int last_load; unsigned int last_load;
unsigned int fifo_load; unsigned int fifo_load;
unsigned short fifo_size; unsigned short fifo_size;
unsigned short fifo_index;
unsigned char dir_in; unsigned char dir_in;
unsigned char index; unsigned char index;
...@@ -197,6 +198,7 @@ struct s3c_hsotg { ...@@ -197,6 +198,7 @@ struct s3c_hsotg {
int fifo_mem; int fifo_mem;
unsigned int dedicated_fifos:1; unsigned int dedicated_fifos:1;
unsigned char num_of_eps; unsigned char num_of_eps;
u32 fifo_map;
struct dentry *debug_root; struct dentry *debug_root;
struct dentry *debug_file; struct dentry *debug_file;
......
...@@ -182,14 +182,29 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) ...@@ -182,14 +182,29 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
/* start at the end of the GNPTXFSIZ, rounded up */ /* start at the end of the GNPTXFSIZ, rounded up */
addr = 2048 + 1024; addr = 2048 + 1024;
size = 768;
/* /*
* currently we allocate TX FIFOs for all possible endpoints, * Because we have not enough memory to have each TX FIFO of size at
* and assume that they are all the same size. * least 3072 bytes (the maximum single packet size), we create four
* FIFOs of lenght 1024, and four of length 3072 bytes, and assing
* them to endpoints dynamically according to maxpacket size value of
* given endpoint.
*/ */
for (ep = 1; ep <= 15; ep++) { /* 256*4=1024 bytes FIFO length */
size = 256;
for (ep = 1; ep <= 4; ep++) {
val = addr;
val |= size << FIFOSIZE_DEPTH_SHIFT;
WARN_ONCE(addr + size > hsotg->fifo_mem,
"insufficient fifo memory");
addr += size;
writel(val, hsotg->regs + DPTXFSIZN(ep));
}
/* 768*4=3072 bytes FIFO length */
size = 768;
for (ep = 5; ep <= 8; ep++) {
val = addr; val = addr;
val |= size << FIFOSIZE_DEPTH_SHIFT; val |= size << FIFOSIZE_DEPTH_SHIFT;
WARN_ONCE(addr + size > hsotg->fifo_mem, WARN_ONCE(addr + size > hsotg->fifo_mem,
...@@ -1834,7 +1849,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, ...@@ -1834,7 +1849,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
if (dir_in) { if (dir_in) {
int epctl = readl(hsotg->regs + epctl_reg); int epctl = readl(hsotg->regs + epctl_reg);
s3c_hsotg_txfifo_flush(hsotg, idx); s3c_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index);
if ((epctl & DXEPCTL_STALL) && if ((epctl & DXEPCTL_STALL) &&
(epctl & DXEPCTL_EPTYPE_BULK)) { (epctl & DXEPCTL_EPTYPE_BULK)) {
...@@ -1983,6 +1998,7 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, ...@@ -1983,6 +1998,7 @@ static void kill_all_requests(struct s3c_hsotg *hsotg,
int result, bool force) int result, bool force)
{ {
struct s3c_hsotg_req *req, *treq; struct s3c_hsotg_req *req, *treq;
unsigned size;
list_for_each_entry_safe(req, treq, &ep->queue, queue) { list_for_each_entry_safe(req, treq, &ep->queue, queue) {
/* /*
...@@ -1996,9 +2012,11 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, ...@@ -1996,9 +2012,11 @@ static void kill_all_requests(struct s3c_hsotg *hsotg,
s3c_hsotg_complete_request(hsotg, ep, req, s3c_hsotg_complete_request(hsotg, ep, req,
result); result);
} }
if (hsotg->dedicated_fifos) if (!hsotg->dedicated_fifos)
if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) return;
s3c_hsotg_txfifo_flush(hsotg, ep->index); size = (readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4;
if (size < ep->fifo_size)
s3c_hsotg_txfifo_flush(hsotg, ep->fifo_index);
} }
/** /**
...@@ -2439,6 +2457,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, ...@@ -2439,6 +2457,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
u32 epctrl; u32 epctrl;
u32 mps; u32 mps;
int dir_in; int dir_in;
int i, val, size;
int ret = 0; int ret = 0;
dev_dbg(hsotg->dev, dev_dbg(hsotg->dev,
...@@ -2511,17 +2530,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, ...@@ -2511,17 +2530,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
break; break;
case USB_ENDPOINT_XFER_INT: case USB_ENDPOINT_XFER_INT:
if (dir_in) { if (dir_in)
/*
* Allocate our TxFNum by simply using the index
* of the endpoint for the moment. We could do
* something better if the host indicates how
* many FIFOs we are expecting to use.
*/
hs_ep->periodic = 1; hs_ep->periodic = 1;
epctrl |= DXEPCTL_TXFNUM(index);
}
epctrl |= DXEPCTL_EPTYPE_INTERRUPT; epctrl |= DXEPCTL_EPTYPE_INTERRUPT;
break; break;
...@@ -2535,8 +2545,25 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, ...@@ -2535,8 +2545,25 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
* if the hardware has dedicated fifos, we must give each IN EP * if the hardware has dedicated fifos, we must give each IN EP
* a unique tx-fifo even if it is non-periodic. * a unique tx-fifo even if it is non-periodic.
*/ */
if (dir_in && hsotg->dedicated_fifos) if (dir_in && hsotg->dedicated_fifos) {
epctrl |= DXEPCTL_TXFNUM(index); size = hs_ep->ep.maxpacket*hs_ep->mc;
for (i = 1; i <= 8; ++i) {
if (hsotg->fifo_map & (1<<i))
continue;
val = readl(hsotg->regs + DPTXFSIZN(i));
val = (val >> FIFOSIZE_DEPTH_SHIFT)*4;
if (val < size)
continue;
hsotg->fifo_map |= 1<<i;
epctrl |= DXEPCTL_TXFNUM(i);
hs_ep->fifo_index = i;
hs_ep->fifo_size = val;
break;
}
if (i == 8)
return -ENOMEM;
}
/* for non control endpoints, set PID to D0 */ /* for non control endpoints, set PID to D0 */
if (index) if (index)
...@@ -2583,6 +2610,9 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep) ...@@ -2583,6 +2610,9 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep)
/* terminate all requests with shutdown */ /* terminate all requests with shutdown */
kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false); kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false);
hsotg->fifo_map &= ~(1<<hs_ep->fifo_index);
hs_ep->fifo_index = 0;
hs_ep->fifo_size = 0;
ctrl = readl(hsotg->regs + epctrl_reg); ctrl = readl(hsotg->regs + epctrl_reg);
ctrl &= ~DXEPCTL_EPENA; ctrl &= ~DXEPCTL_EPENA;
...@@ -2974,7 +3004,6 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, ...@@ -2974,7 +3004,6 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg,
struct s3c_hsotg_ep *hs_ep, struct s3c_hsotg_ep *hs_ep,
int epnum) int epnum)
{ {
u32 ptxfifo;
char *dir; char *dir;
if (epnum == 0) if (epnum == 0)
...@@ -3002,15 +3031,6 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, ...@@ -3002,15 +3031,6 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg,
usb_ep_set_maxpacket_limit(&hs_ep->ep, epnum ? 1024 : EP0_MPS_LIMIT); usb_ep_set_maxpacket_limit(&hs_ep->ep, epnum ? 1024 : EP0_MPS_LIMIT);
hs_ep->ep.ops = &s3c_hsotg_ep_ops; hs_ep->ep.ops = &s3c_hsotg_ep_ops;
/*
* Read the FIFO size for the Periodic TX FIFO, even if we're
* an OUT endpoint, we may as well do this if in future the
* code is changed to make each endpoint's direction changeable.
*/
ptxfifo = readl(hsotg->regs + DPTXFSIZN(epnum));
hs_ep->fifo_size = FIFOSIZE_DEPTH_GET(ptxfifo) * 4;
/* /*
* if we're using dma, we need to set the next-endpoint pointer * if we're using dma, we need to set the next-endpoint pointer
* to be something valid. * to be something valid.
......
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