096-08-usb-dwc3-remove-num_event_buffers.patch 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. We never, ever route any of the other event buffers
  6. so we might as well drop support for them.
  7. Until someone has a real, proper benefit for
  8. multiple event buffers, we will rely on a single
  9. one. This also helps reduce memory footprint of
  10. dwc3.ko which won't allocate memory for the extra
  11. event buffers.
  12. Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
  13. ---
  14. drivers/usb/dwc3/core.c | 81 +++++++++++++++++++----------------------------
  15. drivers/usb/dwc3/core.h | 2 --
  16. drivers/usb/dwc3/gadget.c | 38 +++++++---------------
  17. 3 files changed, 44 insertions(+), 77 deletions(-)
  18. --- a/drivers/usb/dwc3/core.c
  19. +++ b/drivers/usb/dwc3/core.c
  20. @@ -203,13 +203,10 @@ static struct dwc3_event_buffer *dwc3_al
  21. static void dwc3_free_event_buffers(struct dwc3 *dwc)
  22. {
  23. struct dwc3_event_buffer *evt;
  24. - int i;
  25. - for (i = 0; i < dwc->num_event_buffers; i++) {
  26. - evt = dwc->ev_buffs[i];
  27. - if (evt)
  28. - dwc3_free_one_event_buffer(dwc, evt);
  29. - }
  30. + evt = dwc->ev_buffs[0];
  31. + if (evt)
  32. + dwc3_free_one_event_buffer(dwc, evt);
  33. }
  34. /**
  35. @@ -222,27 +219,19 @@ static void dwc3_free_event_buffers(stru
  36. */
  37. static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
  38. {
  39. - int num;
  40. - int i;
  41. -
  42. - num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
  43. - dwc->num_event_buffers = num;
  44. + struct dwc3_event_buffer *evt;
  45. - dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num,
  46. + dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs),
  47. GFP_KERNEL);
  48. if (!dwc->ev_buffs)
  49. return -ENOMEM;
  50. - for (i = 0; i < num; i++) {
  51. - struct dwc3_event_buffer *evt;
  52. -
  53. - evt = dwc3_alloc_one_event_buffer(dwc, length);
  54. - if (IS_ERR(evt)) {
  55. - dev_err(dwc->dev, "can't allocate event buffer\n");
  56. - return PTR_ERR(evt);
  57. - }
  58. - dwc->ev_buffs[i] = evt;
  59. + evt = dwc3_alloc_one_event_buffer(dwc, length);
  60. + if (IS_ERR(evt)) {
  61. + dev_err(dwc->dev, "can't allocate event buffer\n");
  62. + return PTR_ERR(evt);
  63. }
  64. + dwc->ev_buffs[0] = evt;
  65. return 0;
  66. }
  67. @@ -256,25 +245,22 @@ static int dwc3_alloc_event_buffers(stru
  68. static int dwc3_event_buffers_setup(struct dwc3 *dwc)
  69. {
  70. struct dwc3_event_buffer *evt;
  71. - int n;
  72. - for (n = 0; n < dwc->num_event_buffers; n++) {
  73. - evt = dwc->ev_buffs[n];
  74. - dwc3_trace(trace_dwc3_core,
  75. - "Event buf %p dma %08llx length %d\n",
  76. - evt->buf, (unsigned long long) evt->dma,
  77. - evt->length);
  78. -
  79. - evt->lpos = 0;
  80. -
  81. - dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n),
  82. - lower_32_bits(evt->dma));
  83. - dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
  84. - upper_32_bits(evt->dma));
  85. - dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n),
  86. - DWC3_GEVNTSIZ_SIZE(evt->length));
  87. - dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
  88. - }
  89. + evt = dwc->ev_buffs[0];
  90. + dwc3_trace(trace_dwc3_core,
  91. + "Event buf %p dma %08llx length %d\n",
  92. + evt->buf, (unsigned long long) evt->dma,
  93. + evt->length);
  94. +
  95. + evt->lpos = 0;
  96. +
  97. + dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0),
  98. + lower_32_bits(evt->dma));
  99. + dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0),
  100. + upper_32_bits(evt->dma));
  101. + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
  102. + DWC3_GEVNTSIZ_SIZE(evt->length));
  103. + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
  104. return 0;
  105. }
  106. @@ -282,19 +268,16 @@ static int dwc3_event_buffers_setup(stru
  107. static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
  108. {
  109. struct dwc3_event_buffer *evt;
  110. - int n;
  111. - for (n = 0; n < dwc->num_event_buffers; n++) {
  112. - evt = dwc->ev_buffs[n];
  113. + evt = dwc->ev_buffs[0];
  114. - evt->lpos = 0;
  115. + evt->lpos = 0;
  116. - dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
  117. - dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
  118. - dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), DWC3_GEVNTSIZ_INTMASK
  119. - | DWC3_GEVNTSIZ_SIZE(0));
  120. - dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
  121. - }
  122. + dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0);
  123. + dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0);
  124. + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK
  125. + | DWC3_GEVNTSIZ_SIZE(0));
  126. + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
  127. }
  128. static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
  129. --- a/drivers/usb/dwc3/core.h
  130. +++ b/drivers/usb/dwc3/core.h
  131. @@ -665,7 +665,6 @@ struct dwc3_scratchpad_array {
  132. * @regs: base address for our registers
  133. * @regs_size: address space size
  134. * @nr_scratch: number of scratch buffers
  135. - * @num_event_buffers: calculated number of event buffers
  136. * @u1u2: only used on revisions <1.83a for workaround
  137. * @maximum_speed: maximum speed requested (mainly for testing purposes)
  138. * @revision: revision register contents
  139. @@ -775,7 +774,6 @@ struct dwc3 {
  140. u32 gctl;
  141. u32 nr_scratch;
  142. - u32 num_event_buffers;
  143. u32 u1u2;
  144. u32 maximum_speed;
  145. --- a/drivers/usb/dwc3/gadget.c
  146. +++ b/drivers/usb/dwc3/gadget.c
  147. @@ -2572,14 +2572,14 @@ static void dwc3_process_event_entry(str
  148. }
  149. }
  150. -static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf)
  151. +static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc)
  152. {
  153. struct dwc3_event_buffer *evt;
  154. irqreturn_t ret = IRQ_NONE;
  155. int left;
  156. u32 reg;
  157. - evt = dwc->ev_buffs[buf];
  158. + evt = dwc->ev_buffs[0];
  159. left = evt->count;
  160. if (!(evt->flags & DWC3_EVENT_PENDING))
  161. @@ -2604,7 +2604,7 @@ static irqreturn_t dwc3_process_event_bu
  162. evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE;
  163. left -= 4;
  164. - dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(buf), 4);
  165. + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 4);
  166. }
  167. evt->count = 0;
  168. @@ -2612,9 +2612,9 @@ static irqreturn_t dwc3_process_event_bu
  169. ret = IRQ_HANDLED;
  170. /* Unmask interrupt */
  171. - reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(buf));
  172. + reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(0));
  173. reg &= ~DWC3_GEVNTSIZ_INTMASK;
  174. - dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(buf), reg);
  175. + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), reg);
  176. return ret;
  177. }
  178. @@ -2624,27 +2624,23 @@ static irqreturn_t dwc3_thread_interrupt
  179. struct dwc3 *dwc = _dwc;
  180. unsigned long flags;
  181. irqreturn_t ret = IRQ_NONE;
  182. - int i;
  183. spin_lock_irqsave(&dwc->lock, flags);
  184. -
  185. - for (i = 0; i < dwc->num_event_buffers; i++)
  186. - ret |= dwc3_process_event_buf(dwc, i);
  187. -
  188. + ret = dwc3_process_event_buf(dwc);
  189. spin_unlock_irqrestore(&dwc->lock, flags);
  190. return ret;
  191. }
  192. -static irqreturn_t dwc3_check_event_buf(struct dwc3 *dwc, u32 buf)
  193. +static irqreturn_t dwc3_check_event_buf(struct dwc3 *dwc)
  194. {
  195. struct dwc3_event_buffer *evt;
  196. u32 count;
  197. u32 reg;
  198. - evt = dwc->ev_buffs[buf];
  199. + evt = dwc->ev_buffs[0];
  200. - count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf));
  201. + count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0));
  202. count &= DWC3_GEVNTCOUNT_MASK;
  203. if (!count)
  204. return IRQ_NONE;
  205. @@ -2653,9 +2649,9 @@ static irqreturn_t dwc3_check_event_buf(
  206. evt->flags |= DWC3_EVENT_PENDING;
  207. /* Mask interrupt */
  208. - reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(buf));
  209. + reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(0));
  210. reg |= DWC3_GEVNTSIZ_INTMASK;
  211. - dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(buf), reg);
  212. + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), reg);
  213. return IRQ_WAKE_THREAD;
  214. }
  215. @@ -2663,18 +2659,8 @@ static irqreturn_t dwc3_check_event_buf(
  216. static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
  217. {
  218. struct dwc3 *dwc = _dwc;
  219. - int i;
  220. - irqreturn_t ret = IRQ_NONE;
  221. -
  222. - for (i = 0; i < dwc->num_event_buffers; i++) {
  223. - irqreturn_t status;
  224. - status = dwc3_check_event_buf(dwc, i);
  225. - if (status == IRQ_WAKE_THREAD)
  226. - ret = status;
  227. - }
  228. -
  229. - return ret;
  230. + return dwc3_check_event_buf(dwc);
  231. }
  232. /**