5067548019214219a6c1e9e37e9e7ad8a8b9439f
[lede.git] / target / linux / ipq806x / patches-4.4 / 096-08-usb-dwc3-remove-num_event_buffers.patch
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
5
6 We never, ever route any of the other event buffers
7 so we might as well drop support for them.
8
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
13 event buffers.
14
15 Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
16 ---
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(-)
21
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)
26  {
27         struct dwc3_event_buffer        *evt;
28 -       int i;
29  
30 -       for (i = 0; i < dwc->num_event_buffers; i++) {
31 -               evt = dwc->ev_buffs[i];
32 -               if (evt)
33 -                       dwc3_free_one_event_buffer(dwc, evt);
34 -       }
35 +       evt = dwc->ev_buffs[0];
36 +       if (evt)
37 +               dwc3_free_one_event_buffer(dwc, evt);
38  }
39  
40  /**
41 @@ -222,27 +219,19 @@ static void dwc3_free_event_buffers(stru
42   */
43  static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
44  {
45 -       int                     num;
46 -       int                     i;
47 -
48 -       num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
49 -       dwc->num_event_buffers = num;
50 +       struct dwc3_event_buffer *evt;
51  
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),
54                         GFP_KERNEL);
55         if (!dwc->ev_buffs)
56                 return -ENOMEM;
57  
58 -       for (i = 0; i < num; i++) {
59 -               struct dwc3_event_buffer        *evt;
60 -
61 -               evt = dwc3_alloc_one_event_buffer(dwc, length);
62 -               if (IS_ERR(evt)) {
63 -                       dev_err(dwc->dev, "can't allocate event buffer\n");
64 -                       return PTR_ERR(evt);
65 -               }
66 -               dwc->ev_buffs[i] = evt;
67 +       evt = dwc3_alloc_one_event_buffer(dwc, length);
68 +       if (IS_ERR(evt)) {
69 +               dev_err(dwc->dev, "can't allocate event buffer\n");
70 +               return PTR_ERR(evt);
71         }
72 +       dwc->ev_buffs[0] = evt;
73  
74         return 0;
75  }
76 @@ -256,25 +245,22 @@ static int dwc3_alloc_event_buffers(stru
77  static int dwc3_event_buffers_setup(struct dwc3 *dwc)
78  {
79         struct dwc3_event_buffer        *evt;
80 -       int                             n;
81  
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,
87 -                               evt->length);
88 -
89 -               evt->lpos = 0;
90 -
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);
98 -       }
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,
103 +                       evt->length);
104 +
105 +       evt->lpos = 0;
106 +
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);
114  
115         return 0;
116  }
117 @@ -282,19 +268,16 @@ static int dwc3_event_buffers_setup(stru
118  static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
119  {
120         struct dwc3_event_buffer        *evt;
121 -       int                             n;
122  
123 -       for (n = 0; n < dwc->num_event_buffers; n++) {
124 -               evt = dwc->ev_buffs[n];
125 +       evt = dwc->ev_buffs[0];
126  
127 -               evt->lpos = 0;
128 +       evt->lpos = 0;
129  
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);
135 -       }
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);
141  }
142  
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 @@ -663,7 +663,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 @@ -773,7 +772,6 @@ struct dwc3 {
155         u32                     gctl;
156  
157         u32                     nr_scratch;
158 -       u32                     num_event_buffers;
159         u32                     u1u2;
160         u32                     maximum_speed;
161  
162 --- a/drivers/usb/dwc3/gadget.c
163 +++ b/drivers/usb/dwc3/gadget.c
164 @@ -2556,14 +2556,14 @@ static void dwc3_process_event_entry(str
165         }
166  }
167  
168 -static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf)
169 +static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc)
170  {
171         struct dwc3_event_buffer *evt;
172         irqreturn_t ret = IRQ_NONE;
173         int left;
174         u32 reg;
175  
176 -       evt = dwc->ev_buffs[buf];
177 +       evt = dwc->ev_buffs[0];
178         left = evt->count;
179  
180         if (!(evt->flags & DWC3_EVENT_PENDING))
181 @@ -2588,7 +2588,7 @@ static irqreturn_t dwc3_process_event_bu
182                 evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE;
183                 left -= 4;
184  
185 -               dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(buf), 4);
186 +               dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 4);
187         }
188  
189         evt->count = 0;
190 @@ -2596,9 +2596,9 @@ static irqreturn_t dwc3_process_event_bu
191         ret = IRQ_HANDLED;
192  
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);
199  
200         return ret;
201  }
202 @@ -2608,27 +2608,23 @@ static irqreturn_t dwc3_thread_interrupt
203         struct dwc3 *dwc = _dwc;
204         unsigned long flags;
205         irqreturn_t ret = IRQ_NONE;
206 -       int i;
207  
208         spin_lock_irqsave(&dwc->lock, flags);
209 -
210 -       for (i = 0; i < dwc->num_event_buffers; i++)
211 -               ret |= dwc3_process_event_buf(dwc, i);
212 -
213 +       ret = dwc3_process_event_buf(dwc);
214         spin_unlock_irqrestore(&dwc->lock, flags);
215  
216         return ret;
217  }
218  
219 -static irqreturn_t dwc3_check_event_buf(struct dwc3 *dwc, u32 buf)
220 +static irqreturn_t dwc3_check_event_buf(struct dwc3 *dwc)
221  {
222         struct dwc3_event_buffer *evt;
223         u32 count;
224         u32 reg;
225  
226 -       evt = dwc->ev_buffs[buf];
227 +       evt = dwc->ev_buffs[0];
228  
229 -       count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf));
230 +       count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0));
231         count &= DWC3_GEVNTCOUNT_MASK;
232         if (!count)
233                 return IRQ_NONE;
234 @@ -2637,9 +2633,9 @@ static irqreturn_t dwc3_check_event_buf(
235         evt->flags |= DWC3_EVENT_PENDING;
236  
237         /* Mask interrupt */
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);
243  
244         return IRQ_WAKE_THREAD;
245  }
246 @@ -2647,18 +2643,8 @@ static irqreturn_t dwc3_check_event_buf(
247  static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
248  {
249         struct dwc3                     *dwc = _dwc;
250 -       int                             i;
251 -       irqreturn_t                     ret = IRQ_NONE;
252 -
253 -       for (i = 0; i < dwc->num_event_buffers; i++) {
254 -               irqreturn_t status;
255  
256 -               status = dwc3_check_event_buf(dwc, i);
257 -               if (status == IRQ_WAKE_THREAD)
258 -                       ret = status;
259 -       }
260 -
261 -       return ret;
262 +       return dwc3_check_event_buf(dwc);
263  }
264  
265  /**