1 From 660e9bde74d6915227d7ee3485b11e5f52637b26 Mon Sep 17 00:00:00 2001
2 From: Felipe Balbi <felipe.balbi@linux.intel.com>
3 Date: Wed, 30 Mar 2016 09:26:24 +0300
4 Subject: usb: dwc3: remove num_event_buffers
6 We never, ever route any of the other event buffers
7 so we might as well drop support for them.
9 Until someone has a real, proper benefit for
10 multiple event buffers, we will rely on a single
11 one. This also helps reduce memory footprint of
12 dwc3.ko which won't allocate memory for the extra
15 Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
17 drivers/usb/dwc3/core.c | 81 +++++++++++++++++++----------------------------
18 drivers/usb/dwc3/core.h | 2 --
19 drivers/usb/dwc3/gadget.c | 38 +++++++---------------
20 3 files changed, 44 insertions(+), 77 deletions(-)
22 --- a/drivers/usb/dwc3/core.c
23 +++ b/drivers/usb/dwc3/core.c
24 @@ -203,13 +203,10 @@ static struct dwc3_event_buffer *dwc3_al
25 static void dwc3_free_event_buffers(struct dwc3 *dwc)
27 struct dwc3_event_buffer *evt;
30 - for (i = 0; i < dwc->num_event_buffers; i++) {
31 - evt = dwc->ev_buffs[i];
33 - dwc3_free_one_event_buffer(dwc, evt);
35 + evt = dwc->ev_buffs[0];
37 + dwc3_free_one_event_buffer(dwc, evt);
41 @@ -222,27 +219,19 @@ static void dwc3_free_event_buffers(stru
43 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
48 - num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
49 - dwc->num_event_buffers = num;
50 + struct dwc3_event_buffer *evt;
52 - dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num,
53 + dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs),
58 - for (i = 0; i < num; i++) {
59 - struct dwc3_event_buffer *evt;
61 - evt = dwc3_alloc_one_event_buffer(dwc, length);
63 - dev_err(dwc->dev, "can't allocate event buffer\n");
64 - return PTR_ERR(evt);
66 - dwc->ev_buffs[i] = evt;
67 + evt = dwc3_alloc_one_event_buffer(dwc, length);
69 + dev_err(dwc->dev, "can't allocate event buffer\n");
70 + return PTR_ERR(evt);
72 + dwc->ev_buffs[0] = evt;
76 @@ -256,25 +245,22 @@ static int dwc3_alloc_event_buffers(stru
77 static int dwc3_event_buffers_setup(struct dwc3 *dwc)
79 struct dwc3_event_buffer *evt;
82 - for (n = 0; n < dwc->num_event_buffers; n++) {
83 - evt = dwc->ev_buffs[n];
84 - dwc3_trace(trace_dwc3_core,
85 - "Event buf %p dma %08llx length %d\n",
86 - evt->buf, (unsigned long long) evt->dma,
91 - dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n),
92 - lower_32_bits(evt->dma));
93 - dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
94 - upper_32_bits(evt->dma));
95 - dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n),
96 - DWC3_GEVNTSIZ_SIZE(evt->length));
97 - dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
99 + evt = dwc->ev_buffs[0];
100 + dwc3_trace(trace_dwc3_core,
101 + "Event buf %p dma %08llx length %d\n",
102 + evt->buf, (unsigned long long) evt->dma,
107 + dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0),
108 + lower_32_bits(evt->dma));
109 + dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0),
110 + upper_32_bits(evt->dma));
111 + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
112 + DWC3_GEVNTSIZ_SIZE(evt->length));
113 + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
117 @@ -282,19 +268,16 @@ static int dwc3_event_buffers_setup(stru
118 static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
120 struct dwc3_event_buffer *evt;
123 - for (n = 0; n < dwc->num_event_buffers; n++) {
124 - evt = dwc->ev_buffs[n];
125 + evt = dwc->ev_buffs[0];
130 - dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
131 - dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
132 - dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), DWC3_GEVNTSIZ_INTMASK
133 - | DWC3_GEVNTSIZ_SIZE(0));
134 - dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
136 + dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0);
137 + dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0);
138 + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK
139 + | DWC3_GEVNTSIZ_SIZE(0));
140 + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
143 static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
144 --- a/drivers/usb/dwc3/core.h
145 +++ b/drivers/usb/dwc3/core.h
146 @@ -665,7 +665,6 @@ struct dwc3_scratchpad_array {
147 * @regs: base address for our registers
148 * @regs_size: address space size
149 * @nr_scratch: number of scratch buffers
150 - * @num_event_buffers: calculated number of event buffers
151 * @u1u2: only used on revisions <1.83a for workaround
152 * @maximum_speed: maximum speed requested (mainly for testing purposes)
153 * @revision: revision register contents
154 @@ -775,7 +774,6 @@ struct dwc3 {
158 - u32 num_event_buffers;
162 --- a/drivers/usb/dwc3/gadget.c
163 +++ b/drivers/usb/dwc3/gadget.c
164 @@ -2571,14 +2571,14 @@ static void dwc3_process_event_entry(str
168 -static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf)
169 +static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc)
171 struct dwc3_event_buffer *evt;
172 irqreturn_t ret = IRQ_NONE;
176 - evt = dwc->ev_buffs[buf];
177 + evt = dwc->ev_buffs[0];
180 if (!(evt->flags & DWC3_EVENT_PENDING))
181 @@ -2603,7 +2603,7 @@ static irqreturn_t dwc3_process_event_bu
182 evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE;
185 - dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(buf), 4);
186 + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 4);
190 @@ -2611,9 +2611,9 @@ static irqreturn_t dwc3_process_event_bu
193 /* Unmask interrupt */
194 - reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(buf));
195 + reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(0));
196 reg &= ~DWC3_GEVNTSIZ_INTMASK;
197 - dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(buf), reg);
198 + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), reg);
202 @@ -2623,27 +2623,23 @@ static irqreturn_t dwc3_thread_interrupt
203 struct dwc3 *dwc = _dwc;
205 irqreturn_t ret = IRQ_NONE;
208 spin_lock_irqsave(&dwc->lock, flags);
210 - for (i = 0; i < dwc->num_event_buffers; i++)
211 - ret |= dwc3_process_event_buf(dwc, i);
213 + ret = dwc3_process_event_buf(dwc);
214 spin_unlock_irqrestore(&dwc->lock, flags);
219 -static irqreturn_t dwc3_check_event_buf(struct dwc3 *dwc, u32 buf)
220 +static irqreturn_t dwc3_check_event_buf(struct dwc3 *dwc)
222 struct dwc3_event_buffer *evt;
226 - evt = dwc->ev_buffs[buf];
227 + evt = dwc->ev_buffs[0];
229 - count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf));
230 + count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0));
231 count &= DWC3_GEVNTCOUNT_MASK;
234 @@ -2652,9 +2648,9 @@ static irqreturn_t dwc3_check_event_buf(
235 evt->flags |= DWC3_EVENT_PENDING;
238 - reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(buf));
239 + reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(0));
240 reg |= DWC3_GEVNTSIZ_INTMASK;
241 - dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(buf), reg);
242 + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), reg);
244 return IRQ_WAKE_THREAD;
246 @@ -2662,18 +2658,8 @@ static irqreturn_t dwc3_check_event_buf(
247 static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
249 struct dwc3 *dwc = _dwc;
251 - irqreturn_t ret = IRQ_NONE;
253 - for (i = 0; i < dwc->num_event_buffers; i++) {
254 - irqreturn_t status;
256 - status = dwc3_check_event_buf(dwc, i);
257 - if (status == IRQ_WAKE_THREAD)
262 + return dwc3_check_event_buf(dwc);