blob: 093a75c3d0db60317ea3e0b20f9411f26e9f8ed4 [file] [log] [blame]
Paul Zimmerman7359d482013-03-11 17:47:59 -07001/*
2 * hcd_intr.c - DesignWare HS OTG Controller host-mode interrupt handling
3 *
4 * Copyright (C) 2004-2013 Synopsys, Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The names of the above-listed copyright holders may not be used
16 * to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * ALTERNATIVELY, this software may be distributed under the terms of the
20 * GNU General Public License ("GPL") as published by the Free Software
21 * Foundation; either version 2 of the License, or (at your option) any
22 * later version.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37/*
38 * This file contains the interrupt handlers for Host mode
39 */
40#include <linux/kernel.h>
41#include <linux/module.h>
42#include <linux/spinlock.h>
43#include <linux/interrupt.h>
44#include <linux/dma-mapping.h>
45#include <linux/io.h>
46#include <linux/slab.h>
47#include <linux/usb.h>
48
49#include <linux/usb/hcd.h>
50#include <linux/usb/ch11.h>
51
52#include "core.h"
53#include "hcd.h"
54
55/* This function is for debug only */
56static void dwc2_track_missed_sofs(struct dwc2_hsotg *hsotg)
57{
58#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
Paul Zimmerman7359d482013-03-11 17:47:59 -070059 u16 curr_frame_number = hsotg->frame_number;
60
61 if (hsotg->frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
62 if (((hsotg->last_frame_num + 1) & HFNUM_MAX_FRNUM) !=
63 curr_frame_number) {
64 hsotg->frame_num_array[hsotg->frame_num_idx] =
65 curr_frame_number;
66 hsotg->last_frame_num_array[hsotg->frame_num_idx] =
67 hsotg->last_frame_num;
68 hsotg->frame_num_idx++;
69 }
70 } else if (!hsotg->dumped_frame_num_array) {
71 int i;
72
73 dev_info(hsotg->dev, "Frame Last Frame\n");
74 dev_info(hsotg->dev, "----- ----------\n");
75 for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
76 dev_info(hsotg->dev, "0x%04x 0x%04x\n",
77 hsotg->frame_num_array[i],
78 hsotg->last_frame_num_array[i]);
79 }
80 hsotg->dumped_frame_num_array = 1;
81 }
82 hsotg->last_frame_num = curr_frame_number;
83#endif
84}
85
86static void dwc2_hc_handle_tt_clear(struct dwc2_hsotg *hsotg,
87 struct dwc2_host_chan *chan,
88 struct dwc2_qtd *qtd)
89{
90 struct urb *usb_urb;
91
Paul Zimmerman399fdf92013-07-13 14:53:50 -070092 if (!chan->qh)
93 return;
94
95 if (chan->qh->dev_speed == USB_SPEED_HIGH)
96 return;
97
98 if (!qtd->urb)
Paul Zimmerman7359d482013-03-11 17:47:59 -070099 return;
100
101 usb_urb = qtd->urb->priv;
Paul Zimmerman399fdf92013-07-13 14:53:50 -0700102 if (!usb_urb || !usb_urb->dev || !usb_urb->dev->tt)
Paul Zimmerman7359d482013-03-11 17:47:59 -0700103 return;
104
Paul Zimmerman399fdf92013-07-13 14:53:50 -0700105 if (qtd->urb->status != -EPIPE && qtd->urb->status != -EREMOTEIO) {
Paul Zimmerman7359d482013-03-11 17:47:59 -0700106 chan->qh->tt_buffer_dirty = 1;
107 if (usb_hub_clear_tt_buffer(usb_urb))
108 /* Clear failed; let's hope things work anyway */
109 chan->qh->tt_buffer_dirty = 0;
110 }
111}
112
113/*
114 * Handles the start-of-frame interrupt in host mode. Non-periodic
115 * transactions may be queued to the DWC_otg controller for the current
116 * (micro)frame. Periodic transactions may be queued to the controller
117 * for the next (micro)frame.
118 */
119static void dwc2_sof_intr(struct dwc2_hsotg *hsotg)
120{
121 struct list_head *qh_entry;
122 struct dwc2_qh *qh;
Paul Zimmerman7359d482013-03-11 17:47:59 -0700123 enum dwc2_transaction_type tr_type;
124
125#ifdef DEBUG_SOF
126 dev_vdbg(hsotg->dev, "--Start of Frame Interrupt--\n");
127#endif
128
Matthijs Kooijman37e1dcc2013-04-29 19:40:23 +0000129 hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg);
Paul Zimmerman7359d482013-03-11 17:47:59 -0700130
131 dwc2_track_missed_sofs(hsotg);
132
133 /* Determine whether any periodic QHs should be executed */
134 qh_entry = hsotg->periodic_sched_inactive.next;
135 while (qh_entry != &hsotg->periodic_sched_inactive) {
136 qh = list_entry(qh_entry, struct dwc2_qh, qh_list_entry);
137 qh_entry = qh_entry->next;
138 if (dwc2_frame_num_le(qh->sched_frame, hsotg->frame_number))
139 /*
140 * Move QH to the ready list to be executed next
141 * (micro)frame
142 */
143 list_move(&qh->qh_list_entry,
144 &hsotg->periodic_sched_ready);
145 }
146 tr_type = dwc2_hcd_select_transactions(hsotg);
147 if (tr_type != DWC2_TRANSACTION_NONE)
148 dwc2_hcd_queue_transactions(hsotg, tr_type);
149
150 /* Clear interrupt */
151 writel(GINTSTS_SOF, hsotg->regs + GINTSTS);
152}
153
154/*
155 * Handles the Rx FIFO Level Interrupt, which indicates that there is
156 * at least one packet in the Rx FIFO. The packets are moved from the FIFO to
157 * memory if the DWC_otg controller is operating in Slave mode.
158 */
159static void dwc2_rx_fifo_level_intr(struct dwc2_hsotg *hsotg)
160{
161 u32 grxsts, chnum, bcnt, dpid, pktsts;
162 struct dwc2_host_chan *chan;
163
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +0200164 if (dbg_perio())
165 dev_vdbg(hsotg->dev, "--RxFIFO Level Interrupt--\n");
Paul Zimmerman7359d482013-03-11 17:47:59 -0700166
167 grxsts = readl(hsotg->regs + GRXSTSP);
168 chnum = grxsts >> GRXSTS_HCHNUM_SHIFT &
169 GRXSTS_HCHNUM_MASK >> GRXSTS_HCHNUM_SHIFT;
170 chan = hsotg->hc_ptr_array[chnum];
171 if (!chan) {
172 dev_err(hsotg->dev, "Unable to get corresponding channel\n");
173 return;
174 }
175
176 bcnt = grxsts >> GRXSTS_BYTECNT_SHIFT &
177 GRXSTS_BYTECNT_MASK >> GRXSTS_BYTECNT_SHIFT;
178 dpid = grxsts >> GRXSTS_DPID_SHIFT &
179 GRXSTS_DPID_MASK >> GRXSTS_DPID_SHIFT;
180 pktsts = grxsts & GRXSTS_PKTSTS_MASK;
181
182 /* Packet Status */
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +0200183 if (dbg_perio()) {
184 dev_vdbg(hsotg->dev, " Ch num = %d\n", chnum);
185 dev_vdbg(hsotg->dev, " Count = %d\n", bcnt);
186 dev_vdbg(hsotg->dev, " DPID = %d, chan.dpid = %d\n", dpid,
187 chan->data_pid_start);
188 dev_vdbg(hsotg->dev, " PStatus = %d\n",
189 pktsts >> GRXSTS_PKTSTS_SHIFT &
190 GRXSTS_PKTSTS_MASK >> GRXSTS_PKTSTS_SHIFT);
191 }
Paul Zimmerman7359d482013-03-11 17:47:59 -0700192
193 switch (pktsts) {
194 case GRXSTS_PKTSTS_HCHIN:
195 /* Read the data into the host buffer */
196 if (bcnt > 0) {
197 dwc2_read_packet(hsotg, chan->xfer_buf, bcnt);
198
199 /* Update the HC fields for the next packet received */
200 chan->xfer_count += bcnt;
201 chan->xfer_buf += bcnt;
202 }
203 break;
204 case GRXSTS_PKTSTS_HCHIN_XFER_COMP:
205 case GRXSTS_PKTSTS_DATATOGGLEERR:
206 case GRXSTS_PKTSTS_HCHHALTED:
207 /* Handled in interrupt, just ignore data */
208 break;
209 default:
210 dev_err(hsotg->dev,
211 "RxFIFO Level Interrupt: Unknown status %d\n", pktsts);
212 break;
213 }
214}
215
216/*
217 * This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
218 * data packets may be written to the FIFO for OUT transfers. More requests
219 * may be written to the non-periodic request queue for IN transfers. This
220 * interrupt is enabled only in Slave mode.
221 */
222static void dwc2_np_tx_fifo_empty_intr(struct dwc2_hsotg *hsotg)
223{
224 dev_vdbg(hsotg->dev, "--Non-Periodic TxFIFO Empty Interrupt--\n");
225 dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_NON_PERIODIC);
226}
227
228/*
229 * This interrupt occurs when the periodic Tx FIFO is half-empty. More data
230 * packets may be written to the FIFO for OUT transfers. More requests may be
231 * written to the periodic request queue for IN transfers. This interrupt is
232 * enabled only in Slave mode.
233 */
234static void dwc2_perio_tx_fifo_empty_intr(struct dwc2_hsotg *hsotg)
235{
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +0200236 if (dbg_perio())
237 dev_vdbg(hsotg->dev, "--Periodic TxFIFO Empty Interrupt--\n");
Paul Zimmerman7359d482013-03-11 17:47:59 -0700238 dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_PERIODIC);
239}
240
241static void dwc2_hprt0_enable(struct dwc2_hsotg *hsotg, u32 hprt0,
242 u32 *hprt0_modify)
243{
244 struct dwc2_core_params *params = hsotg->core_params;
245 int do_reset = 0;
246 u32 usbcfg;
247 u32 prtspd;
248 u32 hcfg;
Matthijs Kooijmanbcc5def2013-04-29 19:42:00 +0000249 u32 fslspclksel;
Paul Zimmerman7359d482013-03-11 17:47:59 -0700250 u32 hfir;
251
252 dev_vdbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
253
254 /* Every time when port enables calculate HFIR.FrInterval */
255 hfir = readl(hsotg->regs + HFIR);
256 hfir &= ~HFIR_FRINT_MASK;
257 hfir |= dwc2_calc_frame_interval(hsotg) << HFIR_FRINT_SHIFT &
258 HFIR_FRINT_MASK;
259 writel(hfir, hsotg->regs + HFIR);
260
261 /* Check if we need to adjust the PHY clock speed for low power */
262 if (!params->host_support_fs_ls_low_power) {
263 /* Port has been enabled, set the reset change flag */
264 hsotg->flags.b.port_reset_change = 1;
265 return;
266 }
267
268 usbcfg = readl(hsotg->regs + GUSBCFG);
269 prtspd = hprt0 & HPRT0_SPD_MASK;
270
271 if (prtspd == HPRT0_SPD_LOW_SPEED || prtspd == HPRT0_SPD_FULL_SPEED) {
272 /* Low power */
273 if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL)) {
274 /* Set PHY low power clock select for FS/LS devices */
275 usbcfg |= GUSBCFG_PHY_LP_CLK_SEL;
276 writel(usbcfg, hsotg->regs + GUSBCFG);
277 do_reset = 1;
278 }
279
280 hcfg = readl(hsotg->regs + HCFG);
Matthijs Kooijmanbcc5def2013-04-29 19:42:00 +0000281 fslspclksel = hcfg & HCFG_FSLSPCLKSEL_MASK;
Paul Zimmerman7359d482013-03-11 17:47:59 -0700282
283 if (prtspd == HPRT0_SPD_LOW_SPEED &&
284 params->host_ls_low_power_phy_clk ==
285 DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ) {
286 /* 6 MHZ */
287 dev_vdbg(hsotg->dev,
288 "FS_PHY programming HCFG to 6 MHz\n");
Matthijs Kooijmanbcc5def2013-04-29 19:42:00 +0000289 if (fslspclksel != HCFG_FSLSPCLKSEL_6_MHZ) {
Paul Zimmerman7359d482013-03-11 17:47:59 -0700290 hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
291 hcfg |= HCFG_FSLSPCLKSEL_6_MHZ;
292 writel(hcfg, hsotg->regs + HCFG);
293 do_reset = 1;
294 }
295 } else {
296 /* 48 MHZ */
297 dev_vdbg(hsotg->dev,
298 "FS_PHY programming HCFG to 48 MHz\n");
Matthijs Kooijmanbcc5def2013-04-29 19:42:00 +0000299 if (fslspclksel != HCFG_FSLSPCLKSEL_48_MHZ) {
Paul Zimmerman7359d482013-03-11 17:47:59 -0700300 hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
301 hcfg |= HCFG_FSLSPCLKSEL_48_MHZ;
302 writel(hcfg, hsotg->regs + HCFG);
303 do_reset = 1;
304 }
305 }
306 } else {
307 /* Not low power */
308 if (usbcfg & GUSBCFG_PHY_LP_CLK_SEL) {
309 usbcfg &= ~GUSBCFG_PHY_LP_CLK_SEL;
310 writel(usbcfg, hsotg->regs + GUSBCFG);
311 do_reset = 1;
312 }
313 }
314
315 if (do_reset) {
316 *hprt0_modify |= HPRT0_RST;
317 queue_delayed_work(hsotg->wq_otg, &hsotg->reset_work,
318 msecs_to_jiffies(60));
319 } else {
320 /* Port has been enabled, set the reset change flag */
321 hsotg->flags.b.port_reset_change = 1;
322 }
323}
324
325/*
326 * There are multiple conditions that can cause a port interrupt. This function
327 * determines which interrupt conditions have occurred and handles them
328 * appropriately.
329 */
330static void dwc2_port_intr(struct dwc2_hsotg *hsotg)
331{
332 u32 hprt0;
333 u32 hprt0_modify;
334
335 dev_vdbg(hsotg->dev, "--Port Interrupt--\n");
336
337 hprt0 = readl(hsotg->regs + HPRT0);
338 hprt0_modify = hprt0;
339
340 /*
341 * Clear appropriate bits in HPRT0 to clear the interrupt bit in
342 * GINTSTS
343 */
344 hprt0_modify &= ~(HPRT0_ENA | HPRT0_CONNDET | HPRT0_ENACHG |
345 HPRT0_OVRCURRCHG);
346
347 /*
348 * Port Connect Detected
349 * Set flag and clear if detected
350 */
351 if (hprt0 & HPRT0_CONNDET) {
352 dev_vdbg(hsotg->dev,
353 "--Port Interrupt HPRT0=0x%08x Port Connect Detected--\n",
354 hprt0);
355 hsotg->flags.b.port_connect_status_change = 1;
356 hsotg->flags.b.port_connect_status = 1;
357 hprt0_modify |= HPRT0_CONNDET;
358
359 /*
360 * The Hub driver asserts a reset when it sees port connect
361 * status change flag
362 */
363 }
364
365 /*
366 * Port Enable Changed
367 * Clear if detected - Set internal flag if disabled
368 */
369 if (hprt0 & HPRT0_ENACHG) {
370 dev_vdbg(hsotg->dev,
371 " --Port Interrupt HPRT0=0x%08x Port Enable Changed (now %d)--\n",
372 hprt0, !!(hprt0 & HPRT0_ENA));
373 hprt0_modify |= HPRT0_ENACHG;
374 if (hprt0 & HPRT0_ENA)
375 dwc2_hprt0_enable(hsotg, hprt0, &hprt0_modify);
376 else
377 hsotg->flags.b.port_enable_change = 1;
378 }
379
380 /* Overcurrent Change Interrupt */
381 if (hprt0 & HPRT0_OVRCURRCHG) {
382 dev_vdbg(hsotg->dev,
383 " --Port Interrupt HPRT0=0x%08x Port Overcurrent Changed--\n",
384 hprt0);
385 hsotg->flags.b.port_over_current_change = 1;
386 hprt0_modify |= HPRT0_OVRCURRCHG;
387 }
388
389 /* Clear Port Interrupts */
390 writel(hprt0_modify, hsotg->regs + HPRT0);
391}
392
393/*
394 * Gets the actual length of a transfer after the transfer halts. halt_status
395 * holds the reason for the halt.
396 *
397 * For IN transfers where halt_status is DWC2_HC_XFER_COMPLETE, *short_read
398 * is set to 1 upon return if less than the requested number of bytes were
399 * transferred. short_read may also be NULL on entry, in which case it remains
400 * unchanged.
401 */
402static u32 dwc2_get_actual_xfer_length(struct dwc2_hsotg *hsotg,
403 struct dwc2_host_chan *chan, int chnum,
404 struct dwc2_qtd *qtd,
405 enum dwc2_halt_status halt_status,
406 int *short_read)
407{
408 u32 hctsiz, count, length;
409
410 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
411
412 if (halt_status == DWC2_HC_XFER_COMPLETE) {
413 if (chan->ep_is_in) {
414 count = hctsiz >> TSIZ_XFERSIZE_SHIFT &
415 TSIZ_XFERSIZE_MASK >> TSIZ_XFERSIZE_SHIFT;
416 length = chan->xfer_len - count;
417 if (short_read != NULL)
418 *short_read = (count != 0);
419 } else if (chan->qh->do_split) {
420 length = qtd->ssplit_out_xfer_count;
421 } else {
422 length = chan->xfer_len;
423 }
424 } else {
425 /*
426 * Must use the hctsiz.pktcnt field to determine how much data
427 * has been transferred. This field reflects the number of
428 * packets that have been transferred via the USB. This is
429 * always an integral number of packets if the transfer was
430 * halted before its normal completion. (Can't use the
431 * hctsiz.xfersize field because that reflects the number of
432 * bytes transferred via the AHB, not the USB).
433 */
434 count = hctsiz >> TSIZ_PKTCNT_SHIFT &
435 TSIZ_PKTCNT_MASK >> TSIZ_PKTCNT_SHIFT;
436 length = (chan->start_pkt_count - count) * chan->max_packet;
437 }
438
439 return length;
440}
441
442/**
443 * dwc2_update_urb_state() - Updates the state of the URB after a Transfer
444 * Complete interrupt on the host channel. Updates the actual_length field
445 * of the URB based on the number of bytes transferred via the host channel.
446 * Sets the URB status if the data transfer is finished.
447 *
448 * Return: 1 if the data transfer specified by the URB is completely finished,
449 * 0 otherwise
450 */
451static int dwc2_update_urb_state(struct dwc2_hsotg *hsotg,
452 struct dwc2_host_chan *chan, int chnum,
453 struct dwc2_hcd_urb *urb,
454 struct dwc2_qtd *qtd)
455{
456 u32 hctsiz;
457 int xfer_done = 0;
458 int short_read = 0;
459 int xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
460 DWC2_HC_XFER_COMPLETE,
461 &short_read);
462
463 if (urb->actual_length + xfer_length > urb->length) {
464 dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
465 xfer_length = urb->length - urb->actual_length;
466 }
467
468 /* Non DWORD-aligned buffer case handling */
469 if (chan->align_buf && xfer_length && chan->ep_is_in) {
470 dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
471 dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length,
472 DMA_FROM_DEVICE);
473 memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
474 xfer_length);
475 dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length,
476 DMA_FROM_DEVICE);
477 }
478
479 dev_vdbg(hsotg->dev, "urb->actual_length=%d xfer_length=%d\n",
480 urb->actual_length, xfer_length);
481 urb->actual_length += xfer_length;
482
483 if (xfer_length && chan->ep_type == USB_ENDPOINT_XFER_BULK &&
484 (urb->flags & URB_SEND_ZERO_PACKET) &&
485 urb->actual_length >= urb->length &&
486 !(urb->length % chan->max_packet)) {
487 xfer_done = 0;
488 } else if (short_read || urb->actual_length >= urb->length) {
489 xfer_done = 1;
490 urb->status = 0;
491 }
492
493 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
494 dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
495 __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
496 dev_vdbg(hsotg->dev, " chan->xfer_len %d\n", chan->xfer_len);
497 dev_vdbg(hsotg->dev, " hctsiz.xfersize %d\n",
498 hctsiz >> TSIZ_XFERSIZE_SHIFT &
499 TSIZ_XFERSIZE_MASK >> TSIZ_XFERSIZE_SHIFT);
500 dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n", urb->length);
501 dev_vdbg(hsotg->dev, " urb->actual_length %d\n", urb->actual_length);
502 dev_vdbg(hsotg->dev, " short_read %d, xfer_done %d\n", short_read,
503 xfer_done);
504
505 return xfer_done;
506}
507
508/*
509 * Save the starting data toggle for the next transfer. The data toggle is
510 * saved in the QH for non-control transfers and it's saved in the QTD for
511 * control transfers.
512 */
513void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,
514 struct dwc2_host_chan *chan, int chnum,
515 struct dwc2_qtd *qtd)
516{
517 u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
518 u32 pid = hctsiz & TSIZ_SC_MC_PID_MASK;
519
520 if (chan->ep_type != USB_ENDPOINT_XFER_CONTROL) {
521 if (pid == TSIZ_SC_MC_PID_DATA0)
522 chan->qh->data_toggle = DWC2_HC_PID_DATA0;
523 else
524 chan->qh->data_toggle = DWC2_HC_PID_DATA1;
525 } else {
526 if (pid == TSIZ_SC_MC_PID_DATA0)
527 qtd->data_toggle = DWC2_HC_PID_DATA0;
528 else
529 qtd->data_toggle = DWC2_HC_PID_DATA1;
530 }
531}
532
533/**
534 * dwc2_update_isoc_urb_state() - Updates the state of an Isochronous URB when
535 * the transfer is stopped for any reason. The fields of the current entry in
536 * the frame descriptor array are set based on the transfer state and the input
537 * halt_status. Completes the Isochronous URB if all the URB frames have been
538 * completed.
539 *
540 * Return: DWC2_HC_XFER_COMPLETE if there are more frames remaining to be
541 * transferred in the URB. Otherwise return DWC2_HC_XFER_URB_COMPLETE.
542 */
543static enum dwc2_halt_status dwc2_update_isoc_urb_state(
544 struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
545 int chnum, struct dwc2_qtd *qtd,
546 enum dwc2_halt_status halt_status)
547{
548 struct dwc2_hcd_iso_packet_desc *frame_desc;
549 struct dwc2_hcd_urb *urb = qtd->urb;
550
551 if (!urb)
552 return DWC2_HC_XFER_NO_HALT_STATUS;
553
554 frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
555
556 switch (halt_status) {
557 case DWC2_HC_XFER_COMPLETE:
558 frame_desc->status = 0;
559 frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
560 chan, chnum, qtd, halt_status, NULL);
561
562 /* Non DWORD-aligned buffer case handling */
563 if (chan->align_buf && frame_desc->actual_length &&
564 chan->ep_is_in) {
565 dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n",
566 __func__);
567 dma_sync_single_for_cpu(hsotg->dev, urb->dma,
568 urb->length, DMA_FROM_DEVICE);
569 memcpy(urb->buf + frame_desc->offset +
570 qtd->isoc_split_offset, chan->qh->dw_align_buf,
571 frame_desc->actual_length);
572 dma_sync_single_for_device(hsotg->dev, urb->dma,
573 urb->length,
574 DMA_FROM_DEVICE);
575 }
576 break;
577 case DWC2_HC_XFER_FRAME_OVERRUN:
578 urb->error_count++;
579 if (chan->ep_is_in)
580 frame_desc->status = -ENOSR;
581 else
582 frame_desc->status = -ECOMM;
583 frame_desc->actual_length = 0;
584 break;
585 case DWC2_HC_XFER_BABBLE_ERR:
586 urb->error_count++;
587 frame_desc->status = -EOVERFLOW;
588 /* Don't need to update actual_length in this case */
589 break;
590 case DWC2_HC_XFER_XACT_ERR:
591 urb->error_count++;
592 frame_desc->status = -EPROTO;
593 frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
594 chan, chnum, qtd, halt_status, NULL);
595
596 /* Non DWORD-aligned buffer case handling */
597 if (chan->align_buf && frame_desc->actual_length &&
598 chan->ep_is_in) {
599 dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n",
600 __func__);
601 dma_sync_single_for_cpu(hsotg->dev, urb->dma,
602 urb->length, DMA_FROM_DEVICE);
603 memcpy(urb->buf + frame_desc->offset +
604 qtd->isoc_split_offset, chan->qh->dw_align_buf,
605 frame_desc->actual_length);
606 dma_sync_single_for_device(hsotg->dev, urb->dma,
607 urb->length,
608 DMA_FROM_DEVICE);
609 }
610
611 /* Skip whole frame */
612 if (chan->qh->do_split &&
613 chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
614 hsotg->core_params->dma_enable > 0) {
615 qtd->complete_split = 0;
616 qtd->isoc_split_offset = 0;
617 }
618
619 break;
620 default:
621 dev_err(hsotg->dev, "Unhandled halt_status (%d)\n",
622 halt_status);
623 break;
624 }
625
626 if (++qtd->isoc_frame_index == urb->packet_count) {
627 /*
628 * urb->status is not used for isoc transfers. The individual
629 * frame_desc statuses are used instead.
630 */
Paul Zimmerman0d012b92013-07-13 14:53:48 -0700631 dwc2_host_complete(hsotg, qtd, 0);
Paul Zimmerman7359d482013-03-11 17:47:59 -0700632 halt_status = DWC2_HC_XFER_URB_COMPLETE;
633 } else {
634 halt_status = DWC2_HC_XFER_COMPLETE;
635 }
636
637 return halt_status;
638}
639
640/*
641 * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
642 * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
643 * still linked to the QH, the QH is added to the end of the inactive
644 * non-periodic schedule. For periodic QHs, removes the QH from the periodic
645 * schedule if no more QTDs are linked to the QH.
646 */
647static void dwc2_deactivate_qh(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
648 int free_qtd)
649{
650 int continue_split = 0;
651 struct dwc2_qtd *qtd;
652
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +0200653 if (dbg_qh(qh))
654 dev_vdbg(hsotg->dev, " %s(%p,%p,%d)\n", __func__,
655 hsotg, qh, free_qtd);
Paul Zimmerman7359d482013-03-11 17:47:59 -0700656
657 if (list_empty(&qh->qtd_list)) {
658 dev_dbg(hsotg->dev, "## QTD list empty ##\n");
659 goto no_qtd;
660 }
661
662 qtd = list_first_entry(&qh->qtd_list, struct dwc2_qtd, qtd_list_entry);
663
664 if (qtd->complete_split)
665 continue_split = 1;
666 else if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_MID ||
667 qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_END)
668 continue_split = 1;
669
670 if (free_qtd) {
671 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
672 continue_split = 0;
673 }
674
675no_qtd:
676 if (qh->channel)
677 qh->channel->align_buf = 0;
678 qh->channel = NULL;
679 dwc2_hcd_qh_deactivate(hsotg, qh, continue_split);
680}
681
682/**
683 * dwc2_release_channel() - Releases a host channel for use by other transfers
684 *
685 * @hsotg: The HCD state structure
686 * @chan: The host channel to release
687 * @qtd: The QTD associated with the host channel. This QTD may be
688 * freed if the transfer is complete or an error has occurred.
689 * @halt_status: Reason the channel is being released. This status
690 * determines the actions taken by this function.
691 *
692 * Also attempts to select and queue more transactions since at least one host
693 * channel is available.
694 */
695static void dwc2_release_channel(struct dwc2_hsotg *hsotg,
696 struct dwc2_host_chan *chan,
697 struct dwc2_qtd *qtd,
698 enum dwc2_halt_status halt_status)
699{
700 enum dwc2_transaction_type tr_type;
701 u32 haintmsk;
702 int free_qtd = 0;
703
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +0200704 if (dbg_hc(chan))
705 dev_vdbg(hsotg->dev, " %s: channel %d, halt_status %d\n",
706 __func__, chan->hc_num, halt_status);
Paul Zimmerman7359d482013-03-11 17:47:59 -0700707
708 switch (halt_status) {
709 case DWC2_HC_XFER_URB_COMPLETE:
710 free_qtd = 1;
711 break;
712 case DWC2_HC_XFER_AHB_ERR:
713 case DWC2_HC_XFER_STALL:
714 case DWC2_HC_XFER_BABBLE_ERR:
715 free_qtd = 1;
716 break;
717 case DWC2_HC_XFER_XACT_ERR:
Matthijs Kooijman8509f2f2013-03-25 12:00:25 -0700718 if (qtd && qtd->error_count >= 3) {
Paul Zimmerman7359d482013-03-11 17:47:59 -0700719 dev_vdbg(hsotg->dev,
720 " Complete URB with transaction error\n");
721 free_qtd = 1;
Paul Zimmerman0d012b92013-07-13 14:53:48 -0700722 dwc2_host_complete(hsotg, qtd, -EPROTO);
Paul Zimmerman7359d482013-03-11 17:47:59 -0700723 }
724 break;
725 case DWC2_HC_XFER_URB_DEQUEUE:
726 /*
727 * The QTD has already been removed and the QH has been
728 * deactivated. Don't want to do anything except release the
729 * host channel and try to queue more transfers.
730 */
731 goto cleanup;
732 case DWC2_HC_XFER_PERIODIC_INCOMPLETE:
733 dev_vdbg(hsotg->dev, " Complete URB with I/O error\n");
734 free_qtd = 1;
Paul Zimmerman0d012b92013-07-13 14:53:48 -0700735 dwc2_host_complete(hsotg, qtd, -EIO);
Paul Zimmerman7359d482013-03-11 17:47:59 -0700736 break;
737 case DWC2_HC_XFER_NO_HALT_STATUS:
738 default:
739 break;
740 }
741
742 dwc2_deactivate_qh(hsotg, chan->qh, free_qtd);
743
744cleanup:
745 /*
746 * Release the host channel for use by other transfers. The cleanup
747 * function clears the channel interrupt enables and conditions, so
748 * there's no need to clear the Channel Halted interrupt separately.
749 */
750 if (!list_empty(&chan->hc_list_entry))
751 list_del(&chan->hc_list_entry);
752 dwc2_hc_cleanup(hsotg, chan);
753 list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list);
754
755 switch (chan->ep_type) {
756 case USB_ENDPOINT_XFER_CONTROL:
757 case USB_ENDPOINT_XFER_BULK:
758 hsotg->non_periodic_channels--;
759 break;
760 default:
761 /*
762 * Don't release reservations for periodic channels here.
763 * That's done when a periodic transfer is descheduled (i.e.
764 * when the QH is removed from the periodic schedule).
765 */
766 break;
767 }
768
769 haintmsk = readl(hsotg->regs + HAINTMSK);
770 haintmsk &= ~(1 << chan->hc_num);
771 writel(haintmsk, hsotg->regs + HAINTMSK);
772
773 /* Try to queue more transfers now that there's a free channel */
774 tr_type = dwc2_hcd_select_transactions(hsotg);
775 if (tr_type != DWC2_TRANSACTION_NONE)
776 dwc2_hcd_queue_transactions(hsotg, tr_type);
777}
778
779/*
780 * Halts a host channel. If the channel cannot be halted immediately because
781 * the request queue is full, this function ensures that the FIFO empty
782 * interrupt for the appropriate queue is enabled so that the halt request can
783 * be queued when there is space in the request queue.
784 *
785 * This function may also be called in DMA mode. In that case, the channel is
786 * simply released since the core always halts the channel automatically in
787 * DMA mode.
788 */
789static void dwc2_halt_channel(struct dwc2_hsotg *hsotg,
790 struct dwc2_host_chan *chan, struct dwc2_qtd *qtd,
791 enum dwc2_halt_status halt_status)
792{
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +0200793 if (dbg_hc(chan))
794 dev_vdbg(hsotg->dev, "%s()\n", __func__);
Paul Zimmerman7359d482013-03-11 17:47:59 -0700795
796 if (hsotg->core_params->dma_enable > 0) {
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +0200797 if (dbg_hc(chan))
798 dev_vdbg(hsotg->dev, "DMA enabled\n");
Paul Zimmerman7359d482013-03-11 17:47:59 -0700799 dwc2_release_channel(hsotg, chan, qtd, halt_status);
800 return;
801 }
802
803 /* Slave mode processing */
804 dwc2_hc_halt(hsotg, chan, halt_status);
805
806 if (chan->halt_on_queue) {
807 u32 gintmsk;
808
809 dev_vdbg(hsotg->dev, "Halt on queue\n");
810 if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
811 chan->ep_type == USB_ENDPOINT_XFER_BULK) {
812 dev_vdbg(hsotg->dev, "control/bulk\n");
813 /*
814 * Make sure the Non-periodic Tx FIFO empty interrupt
815 * is enabled so that the non-periodic schedule will
816 * be processed
817 */
818 gintmsk = readl(hsotg->regs + GINTMSK);
819 gintmsk |= GINTSTS_NPTXFEMP;
820 writel(gintmsk, hsotg->regs + GINTMSK);
821 } else {
822 dev_vdbg(hsotg->dev, "isoc/intr\n");
823 /*
824 * Move the QH from the periodic queued schedule to
825 * the periodic assigned schedule. This allows the
826 * halt to be queued when the periodic schedule is
827 * processed.
828 */
829 list_move(&chan->qh->qh_list_entry,
830 &hsotg->periodic_sched_assigned);
831
832 /*
833 * Make sure the Periodic Tx FIFO Empty interrupt is
834 * enabled so that the periodic schedule will be
835 * processed
836 */
837 gintmsk = readl(hsotg->regs + GINTMSK);
838 gintmsk |= GINTSTS_PTXFEMP;
839 writel(gintmsk, hsotg->regs + GINTMSK);
840 }
841 }
842}
843
844/*
845 * Performs common cleanup for non-periodic transfers after a Transfer
846 * Complete interrupt. This function should be called after any endpoint type
847 * specific handling is finished to release the host channel.
848 */
849static void dwc2_complete_non_periodic_xfer(struct dwc2_hsotg *hsotg,
850 struct dwc2_host_chan *chan,
851 int chnum, struct dwc2_qtd *qtd,
852 enum dwc2_halt_status halt_status)
853{
854 dev_vdbg(hsotg->dev, "%s()\n", __func__);
855
856 qtd->error_count = 0;
857
858 if (chan->hcint & HCINTMSK_NYET) {
859 /*
860 * Got a NYET on the last transaction of the transfer. This
861 * means that the endpoint should be in the PING state at the
862 * beginning of the next transfer.
863 */
864 dev_vdbg(hsotg->dev, "got NYET\n");
865 chan->qh->ping_state = 1;
866 }
867
868 /*
869 * Always halt and release the host channel to make it available for
870 * more transfers. There may still be more phases for a control
871 * transfer or more data packets for a bulk transfer at this point,
872 * but the host channel is still halted. A channel will be reassigned
873 * to the transfer when the non-periodic schedule is processed after
874 * the channel is released. This allows transactions to be queued
875 * properly via dwc2_hcd_queue_transactions, which also enables the
876 * Tx FIFO Empty interrupt if necessary.
877 */
878 if (chan->ep_is_in) {
879 /*
880 * IN transfers in Slave mode require an explicit disable to
881 * halt the channel. (In DMA mode, this call simply releases
882 * the channel.)
883 */
884 dwc2_halt_channel(hsotg, chan, qtd, halt_status);
885 } else {
886 /*
887 * The channel is automatically disabled by the core for OUT
888 * transfers in Slave mode
889 */
890 dwc2_release_channel(hsotg, chan, qtd, halt_status);
891 }
892}
893
894/*
895 * Performs common cleanup for periodic transfers after a Transfer Complete
896 * interrupt. This function should be called after any endpoint type specific
897 * handling is finished to release the host channel.
898 */
899static void dwc2_complete_periodic_xfer(struct dwc2_hsotg *hsotg,
900 struct dwc2_host_chan *chan, int chnum,
901 struct dwc2_qtd *qtd,
902 enum dwc2_halt_status halt_status)
903{
904 u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
905
906 qtd->error_count = 0;
907
908 if (!chan->ep_is_in || (hctsiz & TSIZ_PKTCNT_MASK) == 0)
909 /* Core halts channel in these cases */
910 dwc2_release_channel(hsotg, chan, qtd, halt_status);
911 else
912 /* Flush any outstanding requests from the Tx queue */
913 dwc2_halt_channel(hsotg, chan, qtd, halt_status);
914}
915
916static int dwc2_xfercomp_isoc_split_in(struct dwc2_hsotg *hsotg,
917 struct dwc2_host_chan *chan, int chnum,
918 struct dwc2_qtd *qtd)
919{
920 struct dwc2_hcd_iso_packet_desc *frame_desc;
921 u32 len;
922
923 if (!qtd->urb)
924 return 0;
925
926 frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
927 len = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
928 DWC2_HC_XFER_COMPLETE, NULL);
929 if (!len) {
930 qtd->complete_split = 0;
931 qtd->isoc_split_offset = 0;
932 return 0;
933 }
934
935 frame_desc->actual_length += len;
936
937 if (chan->align_buf && len) {
938 dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
939 dma_sync_single_for_cpu(hsotg->dev, qtd->urb->dma,
940 qtd->urb->length, DMA_FROM_DEVICE);
941 memcpy(qtd->urb->buf + frame_desc->offset +
942 qtd->isoc_split_offset, chan->qh->dw_align_buf, len);
943 dma_sync_single_for_device(hsotg->dev, qtd->urb->dma,
944 qtd->urb->length, DMA_FROM_DEVICE);
945 }
946
947 qtd->isoc_split_offset += len;
948
949 if (frame_desc->actual_length >= frame_desc->length) {
950 frame_desc->status = 0;
951 qtd->isoc_frame_index++;
952 qtd->complete_split = 0;
953 qtd->isoc_split_offset = 0;
954 }
955
956 if (qtd->isoc_frame_index == qtd->urb->packet_count) {
Paul Zimmerman0d012b92013-07-13 14:53:48 -0700957 dwc2_host_complete(hsotg, qtd, 0);
Paul Zimmerman7359d482013-03-11 17:47:59 -0700958 dwc2_release_channel(hsotg, chan, qtd,
959 DWC2_HC_XFER_URB_COMPLETE);
960 } else {
961 dwc2_release_channel(hsotg, chan, qtd,
962 DWC2_HC_XFER_NO_HALT_STATUS);
963 }
964
965 return 1; /* Indicates that channel released */
966}
967
968/*
969 * Handles a host channel Transfer Complete interrupt. This handler may be
970 * called in either DMA mode or Slave mode.
971 */
972static void dwc2_hc_xfercomp_intr(struct dwc2_hsotg *hsotg,
973 struct dwc2_host_chan *chan, int chnum,
974 struct dwc2_qtd *qtd)
975{
976 struct dwc2_hcd_urb *urb = qtd->urb;
977 int pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
978 enum dwc2_halt_status halt_status = DWC2_HC_XFER_COMPLETE;
979 int urb_xfer_done;
980
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +0200981 if (dbg_hc(chan))
982 dev_vdbg(hsotg->dev,
983 "--Host Channel %d Interrupt: Transfer Complete--\n",
984 chnum);
Paul Zimmerman7359d482013-03-11 17:47:59 -0700985
986 if (hsotg->core_params->dma_desc_enable > 0) {
987 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, halt_status);
988 if (pipe_type == USB_ENDPOINT_XFER_ISOC)
989 /* Do not disable the interrupt, just clear it */
990 return;
991 goto handle_xfercomp_done;
992 }
993
994 /* Handle xfer complete on CSPLIT */
995 if (chan->qh->do_split) {
996 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
997 hsotg->core_params->dma_enable > 0) {
998 if (qtd->complete_split &&
999 dwc2_xfercomp_isoc_split_in(hsotg, chan, chnum,
1000 qtd))
1001 goto handle_xfercomp_done;
1002 } else {
1003 qtd->complete_split = 0;
1004 }
1005 }
1006
1007 if (!urb)
1008 goto handle_xfercomp_done;
1009
1010 /* Update the QTD and URB states */
1011 switch (pipe_type) {
1012 case USB_ENDPOINT_XFER_CONTROL:
1013 switch (qtd->control_phase) {
1014 case DWC2_CONTROL_SETUP:
1015 if (urb->length > 0)
1016 qtd->control_phase = DWC2_CONTROL_DATA;
1017 else
1018 qtd->control_phase = DWC2_CONTROL_STATUS;
1019 dev_vdbg(hsotg->dev,
1020 " Control setup transaction done\n");
1021 halt_status = DWC2_HC_XFER_COMPLETE;
1022 break;
1023 case DWC2_CONTROL_DATA:
1024 urb_xfer_done = dwc2_update_urb_state(hsotg, chan,
1025 chnum, urb, qtd);
1026 if (urb_xfer_done) {
1027 qtd->control_phase = DWC2_CONTROL_STATUS;
1028 dev_vdbg(hsotg->dev,
1029 " Control data transfer done\n");
1030 } else {
1031 dwc2_hcd_save_data_toggle(hsotg, chan, chnum,
1032 qtd);
1033 }
1034 halt_status = DWC2_HC_XFER_COMPLETE;
1035 break;
1036 case DWC2_CONTROL_STATUS:
1037 dev_vdbg(hsotg->dev, " Control transfer complete\n");
1038 if (urb->status == -EINPROGRESS)
1039 urb->status = 0;
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001040 dwc2_host_complete(hsotg, qtd, urb->status);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001041 halt_status = DWC2_HC_XFER_URB_COMPLETE;
1042 break;
1043 }
1044
1045 dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd,
1046 halt_status);
1047 break;
1048 case USB_ENDPOINT_XFER_BULK:
1049 dev_vdbg(hsotg->dev, " Bulk transfer complete\n");
1050 urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb,
1051 qtd);
1052 if (urb_xfer_done) {
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001053 dwc2_host_complete(hsotg, qtd, urb->status);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001054 halt_status = DWC2_HC_XFER_URB_COMPLETE;
1055 } else {
1056 halt_status = DWC2_HC_XFER_COMPLETE;
1057 }
1058
1059 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1060 dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd,
1061 halt_status);
1062 break;
1063 case USB_ENDPOINT_XFER_INT:
1064 dev_vdbg(hsotg->dev, " Interrupt transfer complete\n");
1065 urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb,
1066 qtd);
1067
1068 /*
1069 * Interrupt URB is done on the first transfer complete
1070 * interrupt
1071 */
1072 if (urb_xfer_done) {
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001073 dwc2_host_complete(hsotg, qtd, urb->status);
1074 halt_status = DWC2_HC_XFER_URB_COMPLETE;
Paul Zimmerman7359d482013-03-11 17:47:59 -07001075 } else {
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001076 halt_status = DWC2_HC_XFER_COMPLETE;
Paul Zimmerman7359d482013-03-11 17:47:59 -07001077 }
1078
1079 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1080 dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd,
1081 halt_status);
1082 break;
1083 case USB_ENDPOINT_XFER_ISOC:
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02001084 if (dbg_perio())
1085 dev_vdbg(hsotg->dev, " Isochronous transfer complete\n");
Paul Zimmerman7359d482013-03-11 17:47:59 -07001086 if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_ALL)
1087 halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
1088 chnum, qtd, DWC2_HC_XFER_COMPLETE);
1089 dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd,
1090 halt_status);
1091 break;
1092 }
1093
1094handle_xfercomp_done:
1095 disable_hc_int(hsotg, chnum, HCINTMSK_XFERCOMPL);
1096}
1097
1098/*
1099 * Handles a host channel STALL interrupt. This handler may be called in
1100 * either DMA mode or Slave mode.
1101 */
1102static void dwc2_hc_stall_intr(struct dwc2_hsotg *hsotg,
1103 struct dwc2_host_chan *chan, int chnum,
1104 struct dwc2_qtd *qtd)
1105{
1106 struct dwc2_hcd_urb *urb = qtd->urb;
1107 int pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
1108
1109 dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: STALL Received--\n",
1110 chnum);
1111
1112 if (hsotg->core_params->dma_desc_enable > 0) {
1113 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1114 DWC2_HC_XFER_STALL);
1115 goto handle_stall_done;
1116 }
1117
1118 if (!urb)
1119 goto handle_stall_halt;
1120
1121 if (pipe_type == USB_ENDPOINT_XFER_CONTROL)
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001122 dwc2_host_complete(hsotg, qtd, -EPIPE);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001123
1124 if (pipe_type == USB_ENDPOINT_XFER_BULK ||
1125 pipe_type == USB_ENDPOINT_XFER_INT) {
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001126 dwc2_host_complete(hsotg, qtd, -EPIPE);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001127 /*
1128 * USB protocol requires resetting the data toggle for bulk
1129 * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
1130 * setup command is issued to the endpoint. Anticipate the
1131 * CLEAR_FEATURE command since a STALL has occurred and reset
1132 * the data toggle now.
1133 */
1134 chan->qh->data_toggle = 0;
1135 }
1136
1137handle_stall_halt:
1138 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_STALL);
1139
1140handle_stall_done:
1141 disable_hc_int(hsotg, chnum, HCINTMSK_STALL);
1142}
1143
1144/*
1145 * Updates the state of the URB when a transfer has been stopped due to an
1146 * abnormal condition before the transfer completes. Modifies the
1147 * actual_length field of the URB to reflect the number of bytes that have
1148 * actually been transferred via the host channel.
1149 */
1150static void dwc2_update_urb_state_abn(struct dwc2_hsotg *hsotg,
1151 struct dwc2_host_chan *chan, int chnum,
1152 struct dwc2_hcd_urb *urb,
1153 struct dwc2_qtd *qtd,
1154 enum dwc2_halt_status halt_status)
1155{
1156 u32 xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum,
1157 qtd, halt_status, NULL);
1158 u32 hctsiz;
1159
1160 if (urb->actual_length + xfer_length > urb->length) {
1161 dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
1162 xfer_length = urb->length - urb->actual_length;
1163 }
1164
1165 /* Non DWORD-aligned buffer case handling */
1166 if (chan->align_buf && xfer_length && chan->ep_is_in) {
1167 dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
1168 dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length,
1169 DMA_FROM_DEVICE);
1170 memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
1171 xfer_length);
1172 dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length,
1173 DMA_FROM_DEVICE);
1174 }
1175
1176 urb->actual_length += xfer_length;
1177
1178 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
1179 dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
1180 __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
1181 dev_vdbg(hsotg->dev, " chan->start_pkt_count %d\n",
1182 chan->start_pkt_count);
1183 dev_vdbg(hsotg->dev, " hctsiz.pktcnt %d\n",
1184 hctsiz >> TSIZ_PKTCNT_SHIFT &
1185 TSIZ_PKTCNT_MASK >> TSIZ_PKTCNT_SHIFT);
1186 dev_vdbg(hsotg->dev, " chan->max_packet %d\n", chan->max_packet);
1187 dev_vdbg(hsotg->dev, " bytes_transferred %d\n",
1188 xfer_length);
1189 dev_vdbg(hsotg->dev, " urb->actual_length %d\n",
1190 urb->actual_length);
1191 dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n",
1192 urb->length);
1193}
1194
1195/*
1196 * Handles a host channel NAK interrupt. This handler may be called in either
1197 * DMA mode or Slave mode.
1198 */
1199static void dwc2_hc_nak_intr(struct dwc2_hsotg *hsotg,
1200 struct dwc2_host_chan *chan, int chnum,
1201 struct dwc2_qtd *qtd)
1202{
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02001203 if (dbg_hc(chan))
1204 dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NAK Received--\n",
1205 chnum);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001206
1207 /*
1208 * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
1209 * interrupt. Re-start the SSPLIT transfer.
1210 */
1211 if (chan->do_split) {
1212 if (chan->complete_split)
1213 qtd->error_count = 0;
1214 qtd->complete_split = 0;
1215 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
1216 goto handle_nak_done;
1217 }
1218
1219 switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
1220 case USB_ENDPOINT_XFER_CONTROL:
1221 case USB_ENDPOINT_XFER_BULK:
1222 if (hsotg->core_params->dma_enable > 0 && chan->ep_is_in) {
1223 /*
1224 * NAK interrupts are enabled on bulk/control IN
1225 * transfers in DMA mode for the sole purpose of
1226 * resetting the error count after a transaction error
1227 * occurs. The core will continue transferring data.
1228 */
1229 qtd->error_count = 0;
1230 break;
1231 }
1232
1233 /*
1234 * NAK interrupts normally occur during OUT transfers in DMA
1235 * or Slave mode. For IN transfers, more requests will be
1236 * queued as request queue space is available.
1237 */
1238 qtd->error_count = 0;
1239
1240 if (!chan->qh->ping_state) {
1241 dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
1242 qtd, DWC2_HC_XFER_NAK);
1243 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1244
1245 if (chan->speed == USB_SPEED_HIGH)
1246 chan->qh->ping_state = 1;
1247 }
1248
1249 /*
1250 * Halt the channel so the transfer can be re-started from
1251 * the appropriate point or the PING protocol will
1252 * start/continue
1253 */
1254 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
1255 break;
1256 case USB_ENDPOINT_XFER_INT:
1257 qtd->error_count = 0;
1258 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
1259 break;
1260 case USB_ENDPOINT_XFER_ISOC:
1261 /* Should never get called for isochronous transfers */
1262 dev_err(hsotg->dev, "NACK interrupt for ISOC transfer\n");
1263 break;
1264 }
1265
1266handle_nak_done:
1267 disable_hc_int(hsotg, chnum, HCINTMSK_NAK);
1268}
1269
1270/*
1271 * Handles a host channel ACK interrupt. This interrupt is enabled when
1272 * performing the PING protocol in Slave mode, when errors occur during
1273 * either Slave mode or DMA mode, and during Start Split transactions.
1274 */
1275static void dwc2_hc_ack_intr(struct dwc2_hsotg *hsotg,
1276 struct dwc2_host_chan *chan, int chnum,
1277 struct dwc2_qtd *qtd)
1278{
1279 struct dwc2_hcd_iso_packet_desc *frame_desc;
1280
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02001281 if (dbg_hc(chan))
1282 dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: ACK Received--\n",
1283 chnum);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001284
1285 if (chan->do_split) {
1286 /* Handle ACK on SSPLIT. ACK should not occur in CSPLIT. */
1287 if (!chan->ep_is_in &&
1288 chan->data_pid_start != DWC2_HC_PID_SETUP)
1289 qtd->ssplit_out_xfer_count = chan->xfer_len;
1290
1291 if (chan->ep_type != USB_ENDPOINT_XFER_ISOC || chan->ep_is_in) {
1292 qtd->complete_split = 1;
1293 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
1294 } else {
1295 /* ISOC OUT */
1296 switch (chan->xact_pos) {
1297 case DWC2_HCSPLT_XACTPOS_ALL:
1298 break;
1299 case DWC2_HCSPLT_XACTPOS_END:
1300 qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL;
1301 qtd->isoc_split_offset = 0;
1302 break;
1303 case DWC2_HCSPLT_XACTPOS_BEGIN:
1304 case DWC2_HCSPLT_XACTPOS_MID:
1305 /*
1306 * For BEGIN or MID, calculate the length for
1307 * the next microframe to determine the correct
1308 * SSPLIT token, either MID or END
1309 */
1310 frame_desc = &qtd->urb->iso_descs[
1311 qtd->isoc_frame_index];
1312 qtd->isoc_split_offset += 188;
1313
1314 if (frame_desc->length - qtd->isoc_split_offset
1315 <= 188)
1316 qtd->isoc_split_pos =
1317 DWC2_HCSPLT_XACTPOS_END;
1318 else
1319 qtd->isoc_split_pos =
1320 DWC2_HCSPLT_XACTPOS_MID;
1321 break;
1322 }
1323 }
1324 } else {
1325 qtd->error_count = 0;
1326
1327 if (chan->qh->ping_state) {
1328 chan->qh->ping_state = 0;
1329 /*
1330 * Halt the channel so the transfer can be re-started
1331 * from the appropriate point. This only happens in
1332 * Slave mode. In DMA mode, the ping_state is cleared
1333 * when the transfer is started because the core
1334 * automatically executes the PING, then the transfer.
1335 */
1336 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
1337 }
1338 }
1339
1340 /*
1341 * If the ACK occurred when _not_ in the PING state, let the channel
1342 * continue transferring data after clearing the error count
1343 */
1344 disable_hc_int(hsotg, chnum, HCINTMSK_ACK);
1345}
1346
1347/*
1348 * Handles a host channel NYET interrupt. This interrupt should only occur on
1349 * Bulk and Control OUT endpoints and for complete split transactions. If a
1350 * NYET occurs at the same time as a Transfer Complete interrupt, it is
1351 * handled in the xfercomp interrupt handler, not here. This handler may be
1352 * called in either DMA mode or Slave mode.
1353 */
1354static void dwc2_hc_nyet_intr(struct dwc2_hsotg *hsotg,
1355 struct dwc2_host_chan *chan, int chnum,
1356 struct dwc2_qtd *qtd)
1357{
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02001358 if (dbg_hc(chan))
1359 dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NYET Received--\n",
1360 chnum);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001361
1362 /*
1363 * NYET on CSPLIT
1364 * re-do the CSPLIT immediately on non-periodic
1365 */
1366 if (chan->do_split && chan->complete_split) {
1367 if (chan->ep_is_in && chan->ep_type == USB_ENDPOINT_XFER_ISOC &&
1368 hsotg->core_params->dma_enable > 0) {
1369 qtd->complete_split = 0;
1370 qtd->isoc_split_offset = 0;
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001371 qtd->isoc_frame_index++;
Paul Zimmerman7902c162013-04-22 14:00:18 -07001372 if (qtd->urb &&
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001373 qtd->isoc_frame_index == qtd->urb->packet_count) {
1374 dwc2_host_complete(hsotg, qtd, 0);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001375 dwc2_release_channel(hsotg, chan, qtd,
Paul Zimmerman7902c162013-04-22 14:00:18 -07001376 DWC2_HC_XFER_URB_COMPLETE);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001377 } else {
1378 dwc2_release_channel(hsotg, chan, qtd,
1379 DWC2_HC_XFER_NO_HALT_STATUS);
1380 }
1381 goto handle_nyet_done;
1382 }
1383
1384 if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
1385 chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
1386 int frnum = dwc2_hcd_get_frame_number(hsotg);
1387
1388 if (dwc2_full_frame_num(frnum) !=
1389 dwc2_full_frame_num(chan->qh->sched_frame)) {
1390 /*
1391 * No longer in the same full speed frame.
1392 * Treat this as a transaction error.
1393 */
1394#if 0
1395 /*
1396 * Todo: Fix system performance so this can
1397 * be treated as an error. Right now complete
1398 * splits cannot be scheduled precisely enough
1399 * due to other system activity, so this error
1400 * occurs regularly in Slave mode.
1401 */
1402 qtd->error_count++;
1403#endif
1404 qtd->complete_split = 0;
1405 dwc2_halt_channel(hsotg, chan, qtd,
1406 DWC2_HC_XFER_XACT_ERR);
1407 /* Todo: add support for isoc release */
1408 goto handle_nyet_done;
1409 }
1410 }
1411
1412 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
1413 goto handle_nyet_done;
1414 }
1415
1416 chan->qh->ping_state = 1;
1417 qtd->error_count = 0;
1418
1419 dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb, qtd,
1420 DWC2_HC_XFER_NYET);
1421 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1422
1423 /*
1424 * Halt the channel and re-start the transfer so the PING protocol
1425 * will start
1426 */
1427 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
1428
1429handle_nyet_done:
1430 disable_hc_int(hsotg, chnum, HCINTMSK_NYET);
1431}
1432
1433/*
1434 * Handles a host channel babble interrupt. This handler may be called in
1435 * either DMA mode or Slave mode.
1436 */
1437static void dwc2_hc_babble_intr(struct dwc2_hsotg *hsotg,
1438 struct dwc2_host_chan *chan, int chnum,
1439 struct dwc2_qtd *qtd)
1440{
1441 dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Babble Error--\n",
1442 chnum);
1443
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001444 dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
1445
Paul Zimmerman7359d482013-03-11 17:47:59 -07001446 if (hsotg->core_params->dma_desc_enable > 0) {
1447 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1448 DWC2_HC_XFER_BABBLE_ERR);
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001449 goto disable_int;
Paul Zimmerman7359d482013-03-11 17:47:59 -07001450 }
1451
1452 if (chan->ep_type != USB_ENDPOINT_XFER_ISOC) {
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001453 dwc2_host_complete(hsotg, qtd, -EOVERFLOW);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001454 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_BABBLE_ERR);
1455 } else {
1456 enum dwc2_halt_status halt_status;
1457
1458 halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
1459 qtd, DWC2_HC_XFER_BABBLE_ERR);
1460 dwc2_halt_channel(hsotg, chan, qtd, halt_status);
1461 }
1462
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001463disable_int:
Paul Zimmerman7359d482013-03-11 17:47:59 -07001464 disable_hc_int(hsotg, chnum, HCINTMSK_BBLERR);
1465}
1466
1467/*
1468 * Handles a host channel AHB error interrupt. This handler is only called in
1469 * DMA mode.
1470 */
1471static void dwc2_hc_ahberr_intr(struct dwc2_hsotg *hsotg,
1472 struct dwc2_host_chan *chan, int chnum,
1473 struct dwc2_qtd *qtd)
1474{
1475 struct dwc2_hcd_urb *urb = qtd->urb;
1476 char *pipetype, *speed;
1477 u32 hcchar;
1478 u32 hcsplt;
1479 u32 hctsiz;
1480 u32 hc_dma;
1481
1482 dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: AHB Error--\n",
1483 chnum);
1484
1485 if (!urb)
1486 goto handle_ahberr_halt;
1487
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001488 dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
1489
Paul Zimmerman7359d482013-03-11 17:47:59 -07001490 hcchar = readl(hsotg->regs + HCCHAR(chnum));
1491 hcsplt = readl(hsotg->regs + HCSPLT(chnum));
1492 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
1493 hc_dma = readl(hsotg->regs + HCDMA(chnum));
1494
1495 dev_err(hsotg->dev, "AHB ERROR, Channel %d\n", chnum);
1496 dev_err(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", hcchar, hcsplt);
1497 dev_err(hsotg->dev, " hctsiz 0x%08x, hc_dma 0x%08x\n", hctsiz, hc_dma);
1498 dev_err(hsotg->dev, " Device address: %d\n",
1499 dwc2_hcd_get_dev_addr(&urb->pipe_info));
1500 dev_err(hsotg->dev, " Endpoint: %d, %s\n",
1501 dwc2_hcd_get_ep_num(&urb->pipe_info),
1502 dwc2_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
1503
1504 switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) {
1505 case USB_ENDPOINT_XFER_CONTROL:
1506 pipetype = "CONTROL";
1507 break;
1508 case USB_ENDPOINT_XFER_BULK:
1509 pipetype = "BULK";
1510 break;
1511 case USB_ENDPOINT_XFER_INT:
1512 pipetype = "INTERRUPT";
1513 break;
1514 case USB_ENDPOINT_XFER_ISOC:
1515 pipetype = "ISOCHRONOUS";
1516 break;
1517 default:
1518 pipetype = "UNKNOWN";
1519 break;
1520 }
1521
1522 dev_err(hsotg->dev, " Endpoint type: %s\n", pipetype);
1523
1524 switch (chan->speed) {
1525 case USB_SPEED_HIGH:
1526 speed = "HIGH";
1527 break;
1528 case USB_SPEED_FULL:
1529 speed = "FULL";
1530 break;
1531 case USB_SPEED_LOW:
1532 speed = "LOW";
1533 break;
1534 default:
1535 speed = "UNKNOWN";
1536 break;
1537 }
1538
1539 dev_err(hsotg->dev, " Speed: %s\n", speed);
1540
1541 dev_err(hsotg->dev, " Max packet size: %d\n",
1542 dwc2_hcd_get_mps(&urb->pipe_info));
1543 dev_err(hsotg->dev, " Data buffer length: %d\n", urb->length);
Paul Zimmerman157dfaa2013-03-14 13:12:00 -07001544 dev_err(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %08lx\n",
1545 urb->buf, (unsigned long)urb->dma);
1546 dev_err(hsotg->dev, " Setup buffer: %p, Setup DMA: %08lx\n",
1547 urb->setup_packet, (unsigned long)urb->setup_dma);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001548 dev_err(hsotg->dev, " Interval: %d\n", urb->interval);
1549
1550 /* Core halts the channel for Descriptor DMA mode */
1551 if (hsotg->core_params->dma_desc_enable > 0) {
1552 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1553 DWC2_HC_XFER_AHB_ERR);
1554 goto handle_ahberr_done;
1555 }
1556
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001557 dwc2_host_complete(hsotg, qtd, -EIO);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001558
1559handle_ahberr_halt:
1560 /*
1561 * Force a channel halt. Don't call dwc2_halt_channel because that won't
1562 * write to the HCCHARn register in DMA mode to force the halt.
1563 */
1564 dwc2_hc_halt(hsotg, chan, DWC2_HC_XFER_AHB_ERR);
1565
1566handle_ahberr_done:
Paul Zimmerman7359d482013-03-11 17:47:59 -07001567 disable_hc_int(hsotg, chnum, HCINTMSK_AHBERR);
1568}
1569
1570/*
1571 * Handles a host channel transaction error interrupt. This handler may be
1572 * called in either DMA mode or Slave mode.
1573 */
1574static void dwc2_hc_xacterr_intr(struct dwc2_hsotg *hsotg,
1575 struct dwc2_host_chan *chan, int chnum,
1576 struct dwc2_qtd *qtd)
1577{
1578 dev_dbg(hsotg->dev,
1579 "--Host Channel %d Interrupt: Transaction Error--\n", chnum);
1580
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001581 dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
1582
Paul Zimmerman7359d482013-03-11 17:47:59 -07001583 if (hsotg->core_params->dma_desc_enable > 0) {
1584 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1585 DWC2_HC_XFER_XACT_ERR);
1586 goto handle_xacterr_done;
1587 }
1588
1589 switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
1590 case USB_ENDPOINT_XFER_CONTROL:
1591 case USB_ENDPOINT_XFER_BULK:
1592 qtd->error_count++;
1593 if (!chan->qh->ping_state) {
1594
1595 dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
1596 qtd, DWC2_HC_XFER_XACT_ERR);
1597 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1598 if (!chan->ep_is_in && chan->speed == USB_SPEED_HIGH)
1599 chan->qh->ping_state = 1;
1600 }
1601
1602 /*
1603 * Halt the channel so the transfer can be re-started from
1604 * the appropriate point or the PING protocol will start
1605 */
1606 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
1607 break;
1608 case USB_ENDPOINT_XFER_INT:
1609 qtd->error_count++;
1610 if (chan->do_split && chan->complete_split)
1611 qtd->complete_split = 0;
1612 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
1613 break;
1614 case USB_ENDPOINT_XFER_ISOC:
1615 {
1616 enum dwc2_halt_status halt_status;
1617
1618 halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
1619 chnum, qtd, DWC2_HC_XFER_XACT_ERR);
1620 dwc2_halt_channel(hsotg, chan, qtd, halt_status);
1621 }
1622 break;
1623 }
1624
1625handle_xacterr_done:
Paul Zimmerman7359d482013-03-11 17:47:59 -07001626 disable_hc_int(hsotg, chnum, HCINTMSK_XACTERR);
1627}
1628
1629/*
1630 * Handles a host channel frame overrun interrupt. This handler may be called
1631 * in either DMA mode or Slave mode.
1632 */
1633static void dwc2_hc_frmovrun_intr(struct dwc2_hsotg *hsotg,
1634 struct dwc2_host_chan *chan, int chnum,
1635 struct dwc2_qtd *qtd)
1636{
1637 enum dwc2_halt_status halt_status;
1638
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02001639 if (dbg_hc(chan))
1640 dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Frame Overrun--\n",
1641 chnum);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001642
Paul Zimmerman0d012b92013-07-13 14:53:48 -07001643 dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
1644
Paul Zimmerman7359d482013-03-11 17:47:59 -07001645 switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
1646 case USB_ENDPOINT_XFER_CONTROL:
1647 case USB_ENDPOINT_XFER_BULK:
1648 break;
1649 case USB_ENDPOINT_XFER_INT:
1650 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_FRAME_OVERRUN);
1651 break;
1652 case USB_ENDPOINT_XFER_ISOC:
1653 halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
1654 qtd, DWC2_HC_XFER_FRAME_OVERRUN);
1655 dwc2_halt_channel(hsotg, chan, qtd, halt_status);
1656 break;
1657 }
1658
Paul Zimmerman7359d482013-03-11 17:47:59 -07001659 disable_hc_int(hsotg, chnum, HCINTMSK_FRMOVRUN);
1660}
1661
1662/*
1663 * Handles a host channel data toggle error interrupt. This handler may be
1664 * called in either DMA mode or Slave mode.
1665 */
1666static void dwc2_hc_datatglerr_intr(struct dwc2_hsotg *hsotg,
1667 struct dwc2_host_chan *chan, int chnum,
1668 struct dwc2_qtd *qtd)
1669{
1670 dev_dbg(hsotg->dev,
1671 "--Host Channel %d Interrupt: Data Toggle Error--\n", chnum);
1672
1673 if (chan->ep_is_in)
1674 qtd->error_count = 0;
1675 else
1676 dev_err(hsotg->dev,
1677 "Data Toggle Error on OUT transfer, channel %d\n",
1678 chnum);
1679
1680 dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
1681 disable_hc_int(hsotg, chnum, HCINTMSK_DATATGLERR);
1682}
1683
1684/*
1685 * For debug only. It checks that a valid halt status is set and that
1686 * HCCHARn.chdis is clear. If there's a problem, corrective action is
1687 * taken and a warning is issued.
1688 *
1689 * Return: true if halt status is ok, false otherwise
1690 */
1691static bool dwc2_halt_status_ok(struct dwc2_hsotg *hsotg,
1692 struct dwc2_host_chan *chan, int chnum,
1693 struct dwc2_qtd *qtd)
1694{
1695#ifdef DEBUG
1696 u32 hcchar;
1697 u32 hctsiz;
1698 u32 hcintmsk;
1699 u32 hcsplt;
1700
1701 if (chan->halt_status == DWC2_HC_XFER_NO_HALT_STATUS) {
1702 /*
1703 * This code is here only as a check. This condition should
1704 * never happen. Ignore the halt if it does occur.
1705 */
1706 hcchar = readl(hsotg->regs + HCCHAR(chnum));
1707 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
1708 hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
1709 hcsplt = readl(hsotg->regs + HCSPLT(chnum));
1710 dev_dbg(hsotg->dev,
1711 "%s: chan->halt_status DWC2_HC_XFER_NO_HALT_STATUS,\n",
1712 __func__);
1713 dev_dbg(hsotg->dev,
1714 "channel %d, hcchar 0x%08x, hctsiz 0x%08x,\n",
1715 chnum, hcchar, hctsiz);
1716 dev_dbg(hsotg->dev,
1717 "hcint 0x%08x, hcintmsk 0x%08x, hcsplt 0x%08x,\n",
1718 chan->hcint, hcintmsk, hcsplt);
Matthijs Kooijman8509f2f2013-03-25 12:00:25 -07001719 if (qtd)
1720 dev_dbg(hsotg->dev, "qtd->complete_split %d\n",
1721 qtd->complete_split);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001722 dev_warn(hsotg->dev,
1723 "%s: no halt status, channel %d, ignoring interrupt\n",
1724 __func__, chnum);
1725 return false;
1726 }
1727
1728 /*
1729 * This code is here only as a check. hcchar.chdis should never be set
1730 * when the halt interrupt occurs. Halt the channel again if it does
1731 * occur.
1732 */
1733 hcchar = readl(hsotg->regs + HCCHAR(chnum));
1734 if (hcchar & HCCHAR_CHDIS) {
1735 dev_warn(hsotg->dev,
1736 "%s: hcchar.chdis set unexpectedly, hcchar 0x%08x, trying to halt again\n",
1737 __func__, hcchar);
1738 chan->halt_pending = 0;
1739 dwc2_halt_channel(hsotg, chan, qtd, chan->halt_status);
1740 return false;
1741 }
1742#endif
1743
1744 return true;
1745}
1746
1747/*
1748 * Handles a host Channel Halted interrupt in DMA mode. This handler
1749 * determines the reason the channel halted and proceeds accordingly.
1750 */
1751static void dwc2_hc_chhltd_intr_dma(struct dwc2_hsotg *hsotg,
1752 struct dwc2_host_chan *chan, int chnum,
1753 struct dwc2_qtd *qtd)
1754{
1755 u32 hcintmsk;
1756 int out_nak_enh = 0;
1757
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02001758 if (dbg_hc(chan))
1759 dev_vdbg(hsotg->dev,
1760 "--Host Channel %d Interrupt: DMA Channel Halted--\n",
1761 chnum);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001762
1763 /*
1764 * For core with OUT NAK enhancement, the flow for high-speed
1765 * CONTROL/BULK OUT is handled a little differently
1766 */
1767 if (hsotg->snpsid >= DWC2_CORE_REV_2_71a) {
1768 if (chan->speed == USB_SPEED_HIGH && !chan->ep_is_in &&
1769 (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
1770 chan->ep_type == USB_ENDPOINT_XFER_BULK)) {
1771 out_nak_enh = 1;
1772 }
1773 }
1774
1775 if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE ||
1776 (chan->halt_status == DWC2_HC_XFER_AHB_ERR &&
1777 hsotg->core_params->dma_desc_enable <= 0)) {
1778 if (hsotg->core_params->dma_desc_enable > 0)
1779 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1780 chan->halt_status);
1781 else
1782 /*
1783 * Just release the channel. A dequeue can happen on a
1784 * transfer timeout. In the case of an AHB Error, the
1785 * channel was forced to halt because there's no way to
1786 * gracefully recover.
1787 */
1788 dwc2_release_channel(hsotg, chan, qtd,
1789 chan->halt_status);
1790 return;
1791 }
1792
1793 hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
1794
1795 if (chan->hcint & HCINTMSK_XFERCOMPL) {
1796 /*
1797 * Todo: This is here because of a possible hardware bug. Spec
1798 * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
1799 * interrupt w/ACK bit set should occur, but I only see the
1800 * XFERCOMP bit, even with it masked out. This is a workaround
1801 * for that behavior. Should fix this when hardware is fixed.
1802 */
1803 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && !chan->ep_is_in)
1804 dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
1805 dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
1806 } else if (chan->hcint & HCINTMSK_STALL) {
1807 dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
1808 } else if ((chan->hcint & HCINTMSK_XACTERR) &&
1809 hsotg->core_params->dma_desc_enable <= 0) {
1810 if (out_nak_enh) {
1811 if (chan->hcint &
1812 (HCINTMSK_NYET | HCINTMSK_NAK | HCINTMSK_ACK)) {
1813 dev_vdbg(hsotg->dev,
1814 "XactErr with NYET/NAK/ACK\n");
1815 qtd->error_count = 0;
1816 } else {
1817 dev_vdbg(hsotg->dev,
1818 "XactErr without NYET/NAK/ACK\n");
1819 }
1820 }
1821
1822 /*
1823 * Must handle xacterr before nak or ack. Could get a xacterr
1824 * at the same time as either of these on a BULK/CONTROL OUT
1825 * that started with a PING. The xacterr takes precedence.
1826 */
1827 dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
1828 } else if ((chan->hcint & HCINTMSK_XCS_XACT) &&
1829 hsotg->core_params->dma_desc_enable > 0) {
1830 dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
1831 } else if ((chan->hcint & HCINTMSK_AHBERR) &&
1832 hsotg->core_params->dma_desc_enable > 0) {
1833 dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
1834 } else if (chan->hcint & HCINTMSK_BBLERR) {
1835 dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
1836 } else if (chan->hcint & HCINTMSK_FRMOVRUN) {
1837 dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
1838 } else if (!out_nak_enh) {
1839 if (chan->hcint & HCINTMSK_NYET) {
1840 /*
1841 * Must handle nyet before nak or ack. Could get a nyet
1842 * at the same time as either of those on a BULK/CONTROL
1843 * OUT that started with a PING. The nyet takes
1844 * precedence.
1845 */
1846 dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
1847 } else if ((chan->hcint & HCINTMSK_NAK) &&
1848 !(hcintmsk & HCINTMSK_NAK)) {
1849 /*
1850 * If nak is not masked, it's because a non-split IN
1851 * transfer is in an error state. In that case, the nak
1852 * is handled by the nak interrupt handler, not here.
1853 * Handle nak here for BULK/CONTROL OUT transfers, which
1854 * halt on a NAK to allow rewinding the buffer pointer.
1855 */
1856 dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
1857 } else if ((chan->hcint & HCINTMSK_ACK) &&
1858 !(hcintmsk & HCINTMSK_ACK)) {
1859 /*
1860 * If ack is not masked, it's because a non-split IN
1861 * transfer is in an error state. In that case, the ack
1862 * is handled by the ack interrupt handler, not here.
1863 * Handle ack here for split transfers. Start splits
1864 * halt on ACK.
1865 */
1866 dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
1867 } else {
1868 if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
1869 chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
1870 /*
1871 * A periodic transfer halted with no other
1872 * channel interrupts set. Assume it was halted
1873 * by the core because it could not be completed
1874 * in its scheduled (micro)frame.
1875 */
1876 dev_dbg(hsotg->dev,
1877 "%s: Halt channel %d (assume incomplete periodic transfer)\n",
1878 __func__, chnum);
1879 dwc2_halt_channel(hsotg, chan, qtd,
1880 DWC2_HC_XFER_PERIODIC_INCOMPLETE);
1881 } else {
1882 dev_err(hsotg->dev,
1883 "%s: Channel %d - ChHltd set, but reason is unknown\n",
1884 __func__, chnum);
1885 dev_err(hsotg->dev,
1886 "hcint 0x%08x, intsts 0x%08x\n",
1887 chan->hcint,
1888 readl(hsotg->regs + GINTSTS));
1889 }
1890 }
1891 } else {
1892 dev_info(hsotg->dev,
1893 "NYET/NAK/ACK/other in non-error case, 0x%08x\n",
1894 chan->hcint);
1895 }
1896}
1897
1898/*
1899 * Handles a host channel Channel Halted interrupt
1900 *
1901 * In slave mode, this handler is called only when the driver specifically
1902 * requests a halt. This occurs during handling other host channel interrupts
1903 * (e.g. nak, xacterr, stall, nyet, etc.).
1904 *
1905 * In DMA mode, this is the interrupt that occurs when the core has finished
1906 * processing a transfer on a channel. Other host channel interrupts (except
1907 * ahberr) are disabled in DMA mode.
1908 */
1909static void dwc2_hc_chhltd_intr(struct dwc2_hsotg *hsotg,
1910 struct dwc2_host_chan *chan, int chnum,
1911 struct dwc2_qtd *qtd)
1912{
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02001913 if (dbg_hc(chan))
1914 dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: Channel Halted--\n",
1915 chnum);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001916
1917 if (hsotg->core_params->dma_enable > 0) {
1918 dwc2_hc_chhltd_intr_dma(hsotg, chan, chnum, qtd);
1919 } else {
1920 if (!dwc2_halt_status_ok(hsotg, chan, chnum, qtd))
1921 return;
1922 dwc2_release_channel(hsotg, chan, qtd, chan->halt_status);
1923 }
1924}
1925
1926/* Handles interrupt for a specific Host Channel */
1927static void dwc2_hc_n_intr(struct dwc2_hsotg *hsotg, int chnum)
1928{
1929 struct dwc2_qtd *qtd;
1930 struct dwc2_host_chan *chan;
1931 u32 hcint, hcintmsk;
1932
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02001933 chan = hsotg->hc_ptr_array[chnum];
1934
1935 if (dbg_hc(chan))
1936 dev_vdbg(hsotg->dev, "--Host Channel Interrupt--, Channel %d\n",
1937 chnum);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001938
1939 hcint = readl(hsotg->regs + HCINT(chnum));
1940 hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02001941 if (dbg_hc(chan))
1942 dev_vdbg(hsotg->dev,
1943 " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
1944 hcint, hcintmsk, hcint & hcintmsk);
Paul Zimmerman7359d482013-03-11 17:47:59 -07001945
Paul Zimmerman7359d482013-03-11 17:47:59 -07001946 if (!chan) {
1947 dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n");
1948 writel(hcint, hsotg->regs + HCINT(chnum));
1949 return;
1950 }
1951
1952 writel(hcint, hsotg->regs + HCINT(chnum));
1953 chan->hcint = hcint;
1954 hcint &= hcintmsk;
1955
Matthijs Kooijman8509f2f2013-03-25 12:00:25 -07001956 /*
1957 * If the channel was halted due to a dequeue, the qtd list might
1958 * be empty or at least the first entry will not be the active qtd.
1959 * In this case, take a shortcut and just release the channel.
1960 */
1961 if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) {
1962 /*
1963 * If the channel was halted, this should be the only
1964 * interrupt unmasked
1965 */
1966 WARN_ON(hcint != HCINTMSK_CHHLTD);
1967 if (hsotg->core_params->dma_desc_enable > 0)
1968 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1969 chan->halt_status);
1970 else
1971 dwc2_release_channel(hsotg, chan, NULL,
1972 chan->halt_status);
1973 return;
1974 }
1975
Paul Zimmerman7359d482013-03-11 17:47:59 -07001976 if (list_empty(&chan->qh->qtd_list)) {
Matthijs Kooijman8509f2f2013-03-25 12:00:25 -07001977 /*
1978 * TODO: Will this ever happen with the
1979 * DWC2_HC_XFER_URB_DEQUEUE handling above?
1980 */
Paul Zimmerman7359d482013-03-11 17:47:59 -07001981 dev_dbg(hsotg->dev, "## no QTD queued for channel %d ##\n",
1982 chnum);
1983 dev_dbg(hsotg->dev,
1984 " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
1985 chan->hcint, hcintmsk, hcint);
1986 chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS;
1987 disable_hc_int(hsotg, chnum, HCINTMSK_CHHLTD);
1988 chan->hcint = 0;
1989 return;
1990 }
1991
1992 qtd = list_first_entry(&chan->qh->qtd_list, struct dwc2_qtd,
1993 qtd_list_entry);
1994
1995 if (hsotg->core_params->dma_enable <= 0) {
1996 if ((hcint & HCINTMSK_CHHLTD) && hcint != HCINTMSK_CHHLTD)
1997 hcint &= ~HCINTMSK_CHHLTD;
1998 }
1999
2000 if (hcint & HCINTMSK_XFERCOMPL) {
2001 dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
2002 /*
2003 * If NYET occurred at same time as Xfer Complete, the NYET is
2004 * handled by the Xfer Complete interrupt handler. Don't want
2005 * to call the NYET interrupt handler in this case.
2006 */
2007 hcint &= ~HCINTMSK_NYET;
2008 }
2009 if (hcint & HCINTMSK_CHHLTD)
2010 dwc2_hc_chhltd_intr(hsotg, chan, chnum, qtd);
2011 if (hcint & HCINTMSK_AHBERR)
2012 dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
2013 if (hcint & HCINTMSK_STALL)
2014 dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
2015 if (hcint & HCINTMSK_NAK)
2016 dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
2017 if (hcint & HCINTMSK_ACK)
2018 dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
2019 if (hcint & HCINTMSK_NYET)
2020 dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
2021 if (hcint & HCINTMSK_XACTERR)
2022 dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
2023 if (hcint & HCINTMSK_BBLERR)
2024 dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
2025 if (hcint & HCINTMSK_FRMOVRUN)
2026 dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
2027 if (hcint & HCINTMSK_DATATGLERR)
2028 dwc2_hc_datatglerr_intr(hsotg, chan, chnum, qtd);
2029
2030 chan->hcint = 0;
2031}
2032
2033/*
2034 * This interrupt indicates that one or more host channels has a pending
2035 * interrupt. There are multiple conditions that can cause each host channel
2036 * interrupt. This function determines which conditions have occurred for each
2037 * host channel interrupt and handles them appropriately.
2038 */
2039static void dwc2_hc_intr(struct dwc2_hsotg *hsotg)
2040{
2041 u32 haint;
2042 int i;
2043
Paul Zimmerman7359d482013-03-11 17:47:59 -07002044 haint = readl(hsotg->regs + HAINT);
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02002045 if (dbg_perio()) {
2046 dev_vdbg(hsotg->dev, "%s()\n", __func__);
2047
2048 dev_vdbg(hsotg->dev, "HAINT=%08x\n", haint);
2049 }
Paul Zimmerman7359d482013-03-11 17:47:59 -07002050
2051 for (i = 0; i < hsotg->core_params->host_channels; i++) {
2052 if (haint & (1 << i))
2053 dwc2_hc_n_intr(hsotg, i);
2054 }
2055}
2056
2057/* This function handles interrupts for the HCD */
Matthijs Kooijmanca18f4a2013-04-25 23:39:15 +02002058irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg)
Paul Zimmerman7359d482013-03-11 17:47:59 -07002059{
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02002060 u32 gintsts, dbg_gintsts;
Matthijs Kooijman6aafb002013-04-25 23:39:14 +02002061 irqreturn_t retval = IRQ_NONE;
Paul Zimmerman7359d482013-03-11 17:47:59 -07002062
2063 if (dwc2_check_core_status(hsotg) < 0) {
Paul Zimmermande9169a2013-04-22 14:00:17 -07002064 dev_warn(hsotg->dev, "Controller is disconnected\n");
Matthijs Kooijman6aafb002013-04-25 23:39:14 +02002065 return retval;
Paul Zimmerman7359d482013-03-11 17:47:59 -07002066 }
2067
2068 spin_lock(&hsotg->lock);
2069
2070 /* Check if HOST Mode */
2071 if (dwc2_is_host_mode(hsotg)) {
2072 gintsts = dwc2_read_core_intr(hsotg);
2073 if (!gintsts) {
2074 spin_unlock(&hsotg->lock);
Matthijs Kooijman6aafb002013-04-25 23:39:14 +02002075 return retval;
Paul Zimmerman7359d482013-03-11 17:47:59 -07002076 }
2077
Matthijs Kooijman6aafb002013-04-25 23:39:14 +02002078 retval = IRQ_HANDLED;
Paul Zimmerman7359d482013-03-11 17:47:59 -07002079
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02002080 dbg_gintsts = gintsts;
Paul Zimmerman7359d482013-03-11 17:47:59 -07002081#ifndef DEBUG_SOF
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02002082 dbg_gintsts &= ~GINTSTS_SOF;
Paul Zimmerman7359d482013-03-11 17:47:59 -07002083#endif
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02002084 if (!dbg_perio())
2085 dbg_gintsts &= ~(GINTSTS_HCHINT | GINTSTS_RXFLVL |
2086 GINTSTS_PTXFEMP);
2087
2088 /* Only print if there are any non-suppressed interrupts left */
2089 if (dbg_gintsts)
Paul Zimmerman7359d482013-03-11 17:47:59 -07002090 dev_vdbg(hsotg->dev,
2091 "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n",
2092 gintsts);
2093
2094 if (gintsts & GINTSTS_SOF)
2095 dwc2_sof_intr(hsotg);
2096 if (gintsts & GINTSTS_RXFLVL)
2097 dwc2_rx_fifo_level_intr(hsotg);
2098 if (gintsts & GINTSTS_NPTXFEMP)
2099 dwc2_np_tx_fifo_empty_intr(hsotg);
Paul Zimmerman7359d482013-03-11 17:47:59 -07002100 if (gintsts & GINTSTS_PRTINT)
2101 dwc2_port_intr(hsotg);
2102 if (gintsts & GINTSTS_HCHINT)
2103 dwc2_hc_intr(hsotg);
2104 if (gintsts & GINTSTS_PTXFEMP)
2105 dwc2_perio_tx_fifo_empty_intr(hsotg);
2106
Matthijs Kooijmanb49977a2013-04-10 09:55:50 +02002107 if (dbg_gintsts) {
Paul Zimmerman7359d482013-03-11 17:47:59 -07002108 dev_vdbg(hsotg->dev,
2109 "DWC OTG HCD Finished Servicing Interrupts\n");
2110 dev_vdbg(hsotg->dev,
2111 "DWC OTG HCD gintsts=0x%08x gintmsk=0x%08x\n",
2112 readl(hsotg->regs + GINTSTS),
2113 readl(hsotg->regs + GINTMSK));
Paul Zimmerman7359d482013-03-11 17:47:59 -07002114 }
Paul Zimmerman7359d482013-03-11 17:47:59 -07002115 }
2116
2117 spin_unlock(&hsotg->lock);
2118
2119 return retval;
2120}