2 * hcd_intr.c - DesignWare HS OTG Controller host-mode interrupt handling
4 * Copyright (C) 2004-2013 Synopsys, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
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.
38 * This file contains the interrupt handlers for Host mode
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>
46 #include <linux/slab.h>
47 #include <linux/usb.h>
49 #include <linux/usb/hcd.h>
50 #include <linux/usb/ch11.h>
55 /* This function is for debug only */
56 static void dwc2_track_missed_sofs(struct dwc2_hsotg *hsotg)
58 #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
59 #warning Compiling code to track missed SOFs
61 u16 curr_frame_number = hsotg->frame_number;
63 if (hsotg->frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
64 if (((hsotg->last_frame_num + 1) & HFNUM_MAX_FRNUM) !=
66 hsotg->frame_num_array[hsotg->frame_num_idx] =
68 hsotg->last_frame_num_array[hsotg->frame_num_idx] =
69 hsotg->last_frame_num;
70 hsotg->frame_num_idx++;
72 } else if (!hsotg->dumped_frame_num_array) {
75 dev_info(hsotg->dev, "Frame Last Frame\n");
76 dev_info(hsotg->dev, "----- ----------\n");
77 for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
78 dev_info(hsotg->dev, "0x%04x 0x%04x\n",
79 hsotg->frame_num_array[i],
80 hsotg->last_frame_num_array[i]);
82 hsotg->dumped_frame_num_array = 1;
84 hsotg->last_frame_num = curr_frame_number;
88 static void dwc2_hc_handle_tt_clear(struct dwc2_hsotg *hsotg,
89 struct dwc2_host_chan *chan,
94 if (!chan->qh || !qtd->urb)
97 usb_urb = qtd->urb->priv;
98 if (!usb_urb || !usb_urb->dev)
101 if (chan->qh->dev_speed != USB_SPEED_HIGH &&
102 qtd->urb->status != -EPIPE && qtd->urb->status != -EREMOTEIO) {
103 chan->qh->tt_buffer_dirty = 1;
104 if (usb_hub_clear_tt_buffer(usb_urb))
105 /* Clear failed; let's hope things work anyway */
106 chan->qh->tt_buffer_dirty = 0;
111 * Handles the start-of-frame interrupt in host mode. Non-periodic
112 * transactions may be queued to the DWC_otg controller for the current
113 * (micro)frame. Periodic transactions may be queued to the controller
114 * for the next (micro)frame.
116 static void dwc2_sof_intr(struct dwc2_hsotg *hsotg)
118 struct list_head *qh_entry;
121 enum dwc2_transaction_type tr_type;
124 dev_vdbg(hsotg->dev, "--Start of Frame Interrupt--\n");
127 hfnum = readl(hsotg->regs + HFNUM);
128 hsotg->frame_number = hfnum >> HFNUM_FRNUM_SHIFT &
129 HFNUM_FRNUM_MASK >> HFNUM_FRNUM_SHIFT;
131 dwc2_track_missed_sofs(hsotg);
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))
140 * Move QH to the ready list to be executed next
143 list_move(&qh->qh_list_entry,
144 &hsotg->periodic_sched_ready);
146 tr_type = dwc2_hcd_select_transactions(hsotg);
147 if (tr_type != DWC2_TRANSACTION_NONE)
148 dwc2_hcd_queue_transactions(hsotg, tr_type);
150 /* Clear interrupt */
151 writel(GINTSTS_SOF, hsotg->regs + GINTSTS);
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.
159 static void dwc2_rx_fifo_level_intr(struct dwc2_hsotg *hsotg)
161 u32 grxsts, chnum, bcnt, dpid, pktsts;
162 struct dwc2_host_chan *chan;
164 dev_vdbg(hsotg->dev, "--RxFIFO Level Interrupt--\n");
166 grxsts = readl(hsotg->regs + GRXSTSP);
167 chnum = grxsts >> GRXSTS_HCHNUM_SHIFT &
168 GRXSTS_HCHNUM_MASK >> GRXSTS_HCHNUM_SHIFT;
169 chan = hsotg->hc_ptr_array[chnum];
171 dev_err(hsotg->dev, "Unable to get corresponding channel\n");
175 bcnt = grxsts >> GRXSTS_BYTECNT_SHIFT &
176 GRXSTS_BYTECNT_MASK >> GRXSTS_BYTECNT_SHIFT;
177 dpid = grxsts >> GRXSTS_DPID_SHIFT &
178 GRXSTS_DPID_MASK >> GRXSTS_DPID_SHIFT;
179 pktsts = grxsts & GRXSTS_PKTSTS_MASK;
182 dev_vdbg(hsotg->dev, " Ch num = %d\n", chnum);
183 dev_vdbg(hsotg->dev, " Count = %d\n", bcnt);
184 dev_vdbg(hsotg->dev, " DPID = %d, chan.dpid = %d\n", dpid,
185 chan->data_pid_start);
186 dev_vdbg(hsotg->dev, " PStatus = %d\n",
187 pktsts >> GRXSTS_PKTSTS_SHIFT &
188 GRXSTS_PKTSTS_MASK >> GRXSTS_PKTSTS_SHIFT);
191 case GRXSTS_PKTSTS_HCHIN:
192 /* Read the data into the host buffer */
194 dwc2_read_packet(hsotg, chan->xfer_buf, bcnt);
196 /* Update the HC fields for the next packet received */
197 chan->xfer_count += bcnt;
198 chan->xfer_buf += bcnt;
201 case GRXSTS_PKTSTS_HCHIN_XFER_COMP:
202 case GRXSTS_PKTSTS_DATATOGGLEERR:
203 case GRXSTS_PKTSTS_HCHHALTED:
204 /* Handled in interrupt, just ignore data */
208 "RxFIFO Level Interrupt: Unknown status %d\n", pktsts);
214 * This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
215 * data packets may be written to the FIFO for OUT transfers. More requests
216 * may be written to the non-periodic request queue for IN transfers. This
217 * interrupt is enabled only in Slave mode.
219 static void dwc2_np_tx_fifo_empty_intr(struct dwc2_hsotg *hsotg)
221 dev_vdbg(hsotg->dev, "--Non-Periodic TxFIFO Empty Interrupt--\n");
222 dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_NON_PERIODIC);
226 * This interrupt occurs when the periodic Tx FIFO is half-empty. More data
227 * packets may be written to the FIFO for OUT transfers. More requests may be
228 * written to the periodic request queue for IN transfers. This interrupt is
229 * enabled only in Slave mode.
231 static void dwc2_perio_tx_fifo_empty_intr(struct dwc2_hsotg *hsotg)
233 dev_vdbg(hsotg->dev, "--Periodic TxFIFO Empty Interrupt--\n");
234 dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_PERIODIC);
237 static void dwc2_hprt0_enable(struct dwc2_hsotg *hsotg, u32 hprt0,
240 struct dwc2_core_params *params = hsotg->core_params;
247 dev_vdbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
249 /* Every time when port enables calculate HFIR.FrInterval */
250 hfir = readl(hsotg->regs + HFIR);
251 hfir &= ~HFIR_FRINT_MASK;
252 hfir |= dwc2_calc_frame_interval(hsotg) << HFIR_FRINT_SHIFT &
254 writel(hfir, hsotg->regs + HFIR);
256 /* Check if we need to adjust the PHY clock speed for low power */
257 if (!params->host_support_fs_ls_low_power) {
258 /* Port has been enabled, set the reset change flag */
259 hsotg->flags.b.port_reset_change = 1;
263 usbcfg = readl(hsotg->regs + GUSBCFG);
264 prtspd = hprt0 & HPRT0_SPD_MASK;
266 if (prtspd == HPRT0_SPD_LOW_SPEED || prtspd == HPRT0_SPD_FULL_SPEED) {
268 if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL)) {
269 /* Set PHY low power clock select for FS/LS devices */
270 usbcfg |= GUSBCFG_PHY_LP_CLK_SEL;
271 writel(usbcfg, hsotg->regs + GUSBCFG);
275 hcfg = readl(hsotg->regs + HCFG);
277 if (prtspd == HPRT0_SPD_LOW_SPEED &&
278 params->host_ls_low_power_phy_clk ==
279 DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ) {
282 "FS_PHY programming HCFG to 6 MHz\n");
283 if ((hcfg & HCFG_FSLSPCLKSEL_MASK) !=
284 HCFG_FSLSPCLKSEL_6_MHZ) {
285 hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
286 hcfg |= HCFG_FSLSPCLKSEL_6_MHZ;
287 writel(hcfg, hsotg->regs + HCFG);
293 "FS_PHY programming HCFG to 48 MHz\n");
294 if ((hcfg & HCFG_FSLSPCLKSEL_MASK) !=
295 HCFG_FSLSPCLKSEL_48_MHZ) {
296 hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
297 hcfg |= HCFG_FSLSPCLKSEL_48_MHZ;
298 writel(hcfg, hsotg->regs + HCFG);
304 if (usbcfg & GUSBCFG_PHY_LP_CLK_SEL) {
305 usbcfg &= ~GUSBCFG_PHY_LP_CLK_SEL;
306 writel(usbcfg, hsotg->regs + GUSBCFG);
312 *hprt0_modify |= HPRT0_RST;
313 queue_delayed_work(hsotg->wq_otg, &hsotg->reset_work,
314 msecs_to_jiffies(60));
316 /* Port has been enabled, set the reset change flag */
317 hsotg->flags.b.port_reset_change = 1;
322 * There are multiple conditions that can cause a port interrupt. This function
323 * determines which interrupt conditions have occurred and handles them
326 static void dwc2_port_intr(struct dwc2_hsotg *hsotg)
331 dev_vdbg(hsotg->dev, "--Port Interrupt--\n");
333 hprt0 = readl(hsotg->regs + HPRT0);
334 hprt0_modify = hprt0;
337 * Clear appropriate bits in HPRT0 to clear the interrupt bit in
340 hprt0_modify &= ~(HPRT0_ENA | HPRT0_CONNDET | HPRT0_ENACHG |
344 * Port Connect Detected
345 * Set flag and clear if detected
347 if (hprt0 & HPRT0_CONNDET) {
349 "--Port Interrupt HPRT0=0x%08x Port Connect Detected--\n",
351 hsotg->flags.b.port_connect_status_change = 1;
352 hsotg->flags.b.port_connect_status = 1;
353 hprt0_modify |= HPRT0_CONNDET;
356 * The Hub driver asserts a reset when it sees port connect
362 * Port Enable Changed
363 * Clear if detected - Set internal flag if disabled
365 if (hprt0 & HPRT0_ENACHG) {
367 " --Port Interrupt HPRT0=0x%08x Port Enable Changed (now %d)--\n",
368 hprt0, !!(hprt0 & HPRT0_ENA));
369 hprt0_modify |= HPRT0_ENACHG;
370 if (hprt0 & HPRT0_ENA)
371 dwc2_hprt0_enable(hsotg, hprt0, &hprt0_modify);
373 hsotg->flags.b.port_enable_change = 1;
376 /* Overcurrent Change Interrupt */
377 if (hprt0 & HPRT0_OVRCURRCHG) {
379 " --Port Interrupt HPRT0=0x%08x Port Overcurrent Changed--\n",
381 hsotg->flags.b.port_over_current_change = 1;
382 hprt0_modify |= HPRT0_OVRCURRCHG;
385 /* Clear Port Interrupts */
386 writel(hprt0_modify, hsotg->regs + HPRT0);
390 * Gets the actual length of a transfer after the transfer halts. halt_status
391 * holds the reason for the halt.
393 * For IN transfers where halt_status is DWC2_HC_XFER_COMPLETE, *short_read
394 * is set to 1 upon return if less than the requested number of bytes were
395 * transferred. short_read may also be NULL on entry, in which case it remains
398 static u32 dwc2_get_actual_xfer_length(struct dwc2_hsotg *hsotg,
399 struct dwc2_host_chan *chan, int chnum,
400 struct dwc2_qtd *qtd,
401 enum dwc2_halt_status halt_status,
404 u32 hctsiz, count, length;
406 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
408 if (halt_status == DWC2_HC_XFER_COMPLETE) {
409 if (chan->ep_is_in) {
410 count = hctsiz >> TSIZ_XFERSIZE_SHIFT &
411 TSIZ_XFERSIZE_MASK >> TSIZ_XFERSIZE_SHIFT;
412 length = chan->xfer_len - count;
413 if (short_read != NULL)
414 *short_read = (count != 0);
415 } else if (chan->qh->do_split) {
416 length = qtd->ssplit_out_xfer_count;
418 length = chan->xfer_len;
422 * Must use the hctsiz.pktcnt field to determine how much data
423 * has been transferred. This field reflects the number of
424 * packets that have been transferred via the USB. This is
425 * always an integral number of packets if the transfer was
426 * halted before its normal completion. (Can't use the
427 * hctsiz.xfersize field because that reflects the number of
428 * bytes transferred via the AHB, not the USB).
430 count = hctsiz >> TSIZ_PKTCNT_SHIFT &
431 TSIZ_PKTCNT_MASK >> TSIZ_PKTCNT_SHIFT;
432 length = (chan->start_pkt_count - count) * chan->max_packet;
439 * dwc2_update_urb_state() - Updates the state of the URB after a Transfer
440 * Complete interrupt on the host channel. Updates the actual_length field
441 * of the URB based on the number of bytes transferred via the host channel.
442 * Sets the URB status if the data transfer is finished.
444 * Return: 1 if the data transfer specified by the URB is completely finished,
447 static int dwc2_update_urb_state(struct dwc2_hsotg *hsotg,
448 struct dwc2_host_chan *chan, int chnum,
449 struct dwc2_hcd_urb *urb,
450 struct dwc2_qtd *qtd)
455 int xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
456 DWC2_HC_XFER_COMPLETE,
459 if (urb->actual_length + xfer_length > urb->length) {
460 dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
461 xfer_length = urb->length - urb->actual_length;
464 /* Non DWORD-aligned buffer case handling */
465 if (chan->align_buf && xfer_length && chan->ep_is_in) {
466 dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
467 dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length,
469 memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
471 dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length,
475 dev_vdbg(hsotg->dev, "urb->actual_length=%d xfer_length=%d\n",
476 urb->actual_length, xfer_length);
477 urb->actual_length += xfer_length;
479 if (xfer_length && chan->ep_type == USB_ENDPOINT_XFER_BULK &&
480 (urb->flags & URB_SEND_ZERO_PACKET) &&
481 urb->actual_length >= urb->length &&
482 !(urb->length % chan->max_packet)) {
484 } else if (short_read || urb->actual_length >= urb->length) {
489 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
490 dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
491 __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
492 dev_vdbg(hsotg->dev, " chan->xfer_len %d\n", chan->xfer_len);
493 dev_vdbg(hsotg->dev, " hctsiz.xfersize %d\n",
494 hctsiz >> TSIZ_XFERSIZE_SHIFT &
495 TSIZ_XFERSIZE_MASK >> TSIZ_XFERSIZE_SHIFT);
496 dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n", urb->length);
497 dev_vdbg(hsotg->dev, " urb->actual_length %d\n", urb->actual_length);
498 dev_vdbg(hsotg->dev, " short_read %d, xfer_done %d\n", short_read,
505 * Save the starting data toggle for the next transfer. The data toggle is
506 * saved in the QH for non-control transfers and it's saved in the QTD for
509 void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,
510 struct dwc2_host_chan *chan, int chnum,
511 struct dwc2_qtd *qtd)
513 u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
514 u32 pid = hctsiz & TSIZ_SC_MC_PID_MASK;
516 if (chan->ep_type != USB_ENDPOINT_XFER_CONTROL) {
517 if (pid == TSIZ_SC_MC_PID_DATA0)
518 chan->qh->data_toggle = DWC2_HC_PID_DATA0;
520 chan->qh->data_toggle = DWC2_HC_PID_DATA1;
522 if (pid == TSIZ_SC_MC_PID_DATA0)
523 qtd->data_toggle = DWC2_HC_PID_DATA0;
525 qtd->data_toggle = DWC2_HC_PID_DATA1;
530 * dwc2_update_isoc_urb_state() - Updates the state of an Isochronous URB when
531 * the transfer is stopped for any reason. The fields of the current entry in
532 * the frame descriptor array are set based on the transfer state and the input
533 * halt_status. Completes the Isochronous URB if all the URB frames have been
536 * Return: DWC2_HC_XFER_COMPLETE if there are more frames remaining to be
537 * transferred in the URB. Otherwise return DWC2_HC_XFER_URB_COMPLETE.
539 static enum dwc2_halt_status dwc2_update_isoc_urb_state(
540 struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
541 int chnum, struct dwc2_qtd *qtd,
542 enum dwc2_halt_status halt_status)
544 struct dwc2_hcd_iso_packet_desc *frame_desc;
545 struct dwc2_hcd_urb *urb = qtd->urb;
548 return DWC2_HC_XFER_NO_HALT_STATUS;
550 frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
552 switch (halt_status) {
553 case DWC2_HC_XFER_COMPLETE:
554 frame_desc->status = 0;
555 frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
556 chan, chnum, qtd, halt_status, NULL);
558 /* Non DWORD-aligned buffer case handling */
559 if (chan->align_buf && frame_desc->actual_length &&
561 dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n",
563 dma_sync_single_for_cpu(hsotg->dev, urb->dma,
564 urb->length, DMA_FROM_DEVICE);
565 memcpy(urb->buf + frame_desc->offset +
566 qtd->isoc_split_offset, chan->qh->dw_align_buf,
567 frame_desc->actual_length);
568 dma_sync_single_for_device(hsotg->dev, urb->dma,
573 case DWC2_HC_XFER_FRAME_OVERRUN:
576 frame_desc->status = -ENOSR;
578 frame_desc->status = -ECOMM;
579 frame_desc->actual_length = 0;
581 case DWC2_HC_XFER_BABBLE_ERR:
583 frame_desc->status = -EOVERFLOW;
584 /* Don't need to update actual_length in this case */
586 case DWC2_HC_XFER_XACT_ERR:
588 frame_desc->status = -EPROTO;
589 frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
590 chan, chnum, qtd, halt_status, NULL);
592 /* Non DWORD-aligned buffer case handling */
593 if (chan->align_buf && frame_desc->actual_length &&
595 dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n",
597 dma_sync_single_for_cpu(hsotg->dev, urb->dma,
598 urb->length, DMA_FROM_DEVICE);
599 memcpy(urb->buf + frame_desc->offset +
600 qtd->isoc_split_offset, chan->qh->dw_align_buf,
601 frame_desc->actual_length);
602 dma_sync_single_for_device(hsotg->dev, urb->dma,
607 /* Skip whole frame */
608 if (chan->qh->do_split &&
609 chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
610 hsotg->core_params->dma_enable > 0) {
611 qtd->complete_split = 0;
612 qtd->isoc_split_offset = 0;
617 dev_err(hsotg->dev, "Unhandled halt_status (%d)\n",
622 if (++qtd->isoc_frame_index == urb->packet_count) {
624 * urb->status is not used for isoc transfers. The individual
625 * frame_desc statuses are used instead.
627 dwc2_host_complete(hsotg, urb->priv, urb, 0);
628 halt_status = DWC2_HC_XFER_URB_COMPLETE;
630 halt_status = DWC2_HC_XFER_COMPLETE;
637 * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
638 * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
639 * still linked to the QH, the QH is added to the end of the inactive
640 * non-periodic schedule. For periodic QHs, removes the QH from the periodic
641 * schedule if no more QTDs are linked to the QH.
643 static void dwc2_deactivate_qh(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
646 int continue_split = 0;
647 struct dwc2_qtd *qtd;
649 dev_vdbg(hsotg->dev, " %s(%p,%p,%d)\n", __func__, hsotg, qh, free_qtd);
651 if (list_empty(&qh->qtd_list)) {
652 dev_dbg(hsotg->dev, "## QTD list empty ##\n");
656 qtd = list_first_entry(&qh->qtd_list, struct dwc2_qtd, qtd_list_entry);
658 if (qtd->complete_split)
660 else if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_MID ||
661 qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_END)
665 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
671 qh->channel->align_buf = 0;
673 dwc2_hcd_qh_deactivate(hsotg, qh, continue_split);
677 * dwc2_release_channel() - Releases a host channel for use by other transfers
679 * @hsotg: The HCD state structure
680 * @chan: The host channel to release
681 * @qtd: The QTD associated with the host channel. This QTD may be
682 * freed if the transfer is complete or an error has occurred.
683 * @halt_status: Reason the channel is being released. This status
684 * determines the actions taken by this function.
686 * Also attempts to select and queue more transactions since at least one host
687 * channel is available.
689 static void dwc2_release_channel(struct dwc2_hsotg *hsotg,
690 struct dwc2_host_chan *chan,
691 struct dwc2_qtd *qtd,
692 enum dwc2_halt_status halt_status)
694 enum dwc2_transaction_type tr_type;
698 dev_vdbg(hsotg->dev, " %s: channel %d, halt_status %d\n",
699 __func__, chan->hc_num, halt_status);
701 switch (halt_status) {
702 case DWC2_HC_XFER_URB_COMPLETE:
705 case DWC2_HC_XFER_AHB_ERR:
706 case DWC2_HC_XFER_STALL:
707 case DWC2_HC_XFER_BABBLE_ERR:
710 case DWC2_HC_XFER_XACT_ERR:
711 if (qtd->error_count >= 3) {
713 " Complete URB with transaction error\n");
716 qtd->urb->status = -EPROTO;
717 dwc2_host_complete(hsotg, qtd->urb->priv,
722 case DWC2_HC_XFER_URB_DEQUEUE:
724 * The QTD has already been removed and the QH has been
725 * deactivated. Don't want to do anything except release the
726 * host channel and try to queue more transfers.
729 case DWC2_HC_XFER_PERIODIC_INCOMPLETE:
730 dev_vdbg(hsotg->dev, " Complete URB with I/O error\n");
733 qtd->urb->status = -EIO;
734 dwc2_host_complete(hsotg, qtd->urb->priv, qtd->urb,
738 case DWC2_HC_XFER_NO_HALT_STATUS:
743 dwc2_deactivate_qh(hsotg, chan->qh, free_qtd);
747 * Release the host channel for use by other transfers. The cleanup
748 * function clears the channel interrupt enables and conditions, so
749 * there's no need to clear the Channel Halted interrupt separately.
751 if (!list_empty(&chan->hc_list_entry))
752 list_del(&chan->hc_list_entry);
753 dwc2_hc_cleanup(hsotg, chan);
754 list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list);
756 switch (chan->ep_type) {
757 case USB_ENDPOINT_XFER_CONTROL:
758 case USB_ENDPOINT_XFER_BULK:
759 hsotg->non_periodic_channels--;
763 * Don't release reservations for periodic channels here.
764 * That's done when a periodic transfer is descheduled (i.e.
765 * when the QH is removed from the periodic schedule).
770 haintmsk = readl(hsotg->regs + HAINTMSK);
771 haintmsk &= ~(1 << chan->hc_num);
772 writel(haintmsk, hsotg->regs + HAINTMSK);
774 /* Try to queue more transfers now that there's a free channel */
775 tr_type = dwc2_hcd_select_transactions(hsotg);
776 if (tr_type != DWC2_TRANSACTION_NONE)
777 dwc2_hcd_queue_transactions(hsotg, tr_type);
781 * Halts a host channel. If the channel cannot be halted immediately because
782 * the request queue is full, this function ensures that the FIFO empty
783 * interrupt for the appropriate queue is enabled so that the halt request can
784 * be queued when there is space in the request queue.
786 * This function may also be called in DMA mode. In that case, the channel is
787 * simply released since the core always halts the channel automatically in
790 static void dwc2_halt_channel(struct dwc2_hsotg *hsotg,
791 struct dwc2_host_chan *chan, struct dwc2_qtd *qtd,
792 enum dwc2_halt_status halt_status)
794 dev_vdbg(hsotg->dev, "%s()\n", __func__);
796 if (hsotg->core_params->dma_enable > 0) {
797 dev_vdbg(hsotg->dev, "DMA enabled\n");
798 dwc2_release_channel(hsotg, chan, qtd, halt_status);
802 /* Slave mode processing */
803 dwc2_hc_halt(hsotg, chan, halt_status);
805 if (chan->halt_on_queue) {
808 dev_vdbg(hsotg->dev, "Halt on queue\n");
809 if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
810 chan->ep_type == USB_ENDPOINT_XFER_BULK) {
811 dev_vdbg(hsotg->dev, "control/bulk\n");
813 * Make sure the Non-periodic Tx FIFO empty interrupt
814 * is enabled so that the non-periodic schedule will
817 gintmsk = readl(hsotg->regs + GINTMSK);
818 gintmsk |= GINTSTS_NPTXFEMP;
819 writel(gintmsk, hsotg->regs + GINTMSK);
821 dev_vdbg(hsotg->dev, "isoc/intr\n");
823 * Move the QH from the periodic queued schedule to
824 * the periodic assigned schedule. This allows the
825 * halt to be queued when the periodic schedule is
828 list_move(&chan->qh->qh_list_entry,
829 &hsotg->periodic_sched_assigned);
832 * Make sure the Periodic Tx FIFO Empty interrupt is
833 * enabled so that the periodic schedule will be
836 gintmsk = readl(hsotg->regs + GINTMSK);
837 gintmsk |= GINTSTS_PTXFEMP;
838 writel(gintmsk, hsotg->regs + GINTMSK);
844 * Performs common cleanup for non-periodic transfers after a Transfer
845 * Complete interrupt. This function should be called after any endpoint type
846 * specific handling is finished to release the host channel.
848 static void dwc2_complete_non_periodic_xfer(struct dwc2_hsotg *hsotg,
849 struct dwc2_host_chan *chan,
850 int chnum, struct dwc2_qtd *qtd,
851 enum dwc2_halt_status halt_status)
853 dev_vdbg(hsotg->dev, "%s()\n", __func__);
855 qtd->error_count = 0;
857 if (chan->hcint & HCINTMSK_NYET) {
859 * Got a NYET on the last transaction of the transfer. This
860 * means that the endpoint should be in the PING state at the
861 * beginning of the next transfer.
863 dev_vdbg(hsotg->dev, "got NYET\n");
864 chan->qh->ping_state = 1;
868 * Always halt and release the host channel to make it available for
869 * more transfers. There may still be more phases for a control
870 * transfer or more data packets for a bulk transfer at this point,
871 * but the host channel is still halted. A channel will be reassigned
872 * to the transfer when the non-periodic schedule is processed after
873 * the channel is released. This allows transactions to be queued
874 * properly via dwc2_hcd_queue_transactions, which also enables the
875 * Tx FIFO Empty interrupt if necessary.
877 if (chan->ep_is_in) {
879 * IN transfers in Slave mode require an explicit disable to
880 * halt the channel. (In DMA mode, this call simply releases
883 dwc2_halt_channel(hsotg, chan, qtd, halt_status);
886 * The channel is automatically disabled by the core for OUT
887 * transfers in Slave mode
889 dwc2_release_channel(hsotg, chan, qtd, halt_status);
894 * Performs common cleanup for periodic transfers after a Transfer Complete
895 * interrupt. This function should be called after any endpoint type specific
896 * handling is finished to release the host channel.
898 static void dwc2_complete_periodic_xfer(struct dwc2_hsotg *hsotg,
899 struct dwc2_host_chan *chan, int chnum,
900 struct dwc2_qtd *qtd,
901 enum dwc2_halt_status halt_status)
903 u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
905 qtd->error_count = 0;
907 if (!chan->ep_is_in || (hctsiz & TSIZ_PKTCNT_MASK) == 0)
908 /* Core halts channel in these cases */
909 dwc2_release_channel(hsotg, chan, qtd, halt_status);
911 /* Flush any outstanding requests from the Tx queue */
912 dwc2_halt_channel(hsotg, chan, qtd, halt_status);
915 static int dwc2_xfercomp_isoc_split_in(struct dwc2_hsotg *hsotg,
916 struct dwc2_host_chan *chan, int chnum,
917 struct dwc2_qtd *qtd)
919 struct dwc2_hcd_iso_packet_desc *frame_desc;
925 frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
926 len = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
927 DWC2_HC_XFER_COMPLETE, NULL);
929 qtd->complete_split = 0;
930 qtd->isoc_split_offset = 0;
934 frame_desc->actual_length += len;
936 if (chan->align_buf && len) {
937 dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
938 dma_sync_single_for_cpu(hsotg->dev, qtd->urb->dma,
939 qtd->urb->length, DMA_FROM_DEVICE);
940 memcpy(qtd->urb->buf + frame_desc->offset +
941 qtd->isoc_split_offset, chan->qh->dw_align_buf, len);
942 dma_sync_single_for_device(hsotg->dev, qtd->urb->dma,
943 qtd->urb->length, DMA_FROM_DEVICE);
946 qtd->isoc_split_offset += len;
948 if (frame_desc->actual_length >= frame_desc->length) {
949 frame_desc->status = 0;
950 qtd->isoc_frame_index++;
951 qtd->complete_split = 0;
952 qtd->isoc_split_offset = 0;
955 if (qtd->isoc_frame_index == qtd->urb->packet_count) {
956 dwc2_host_complete(hsotg, qtd->urb->priv, qtd->urb, 0);
957 dwc2_release_channel(hsotg, chan, qtd,
958 DWC2_HC_XFER_URB_COMPLETE);
960 dwc2_release_channel(hsotg, chan, qtd,
961 DWC2_HC_XFER_NO_HALT_STATUS);
964 return 1; /* Indicates that channel released */
968 * Handles a host channel Transfer Complete interrupt. This handler may be
969 * called in either DMA mode or Slave mode.
971 static void dwc2_hc_xfercomp_intr(struct dwc2_hsotg *hsotg,
972 struct dwc2_host_chan *chan, int chnum,
973 struct dwc2_qtd *qtd)
975 struct dwc2_hcd_urb *urb = qtd->urb;
976 int pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
977 enum dwc2_halt_status halt_status = DWC2_HC_XFER_COMPLETE;
981 "--Host Channel %d Interrupt: Transfer Complete--\n", chnum);
983 if (hsotg->core_params->dma_desc_enable > 0) {
984 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, halt_status);
985 if (pipe_type == USB_ENDPOINT_XFER_ISOC)
986 /* Do not disable the interrupt, just clear it */
988 goto handle_xfercomp_done;
991 /* Handle xfer complete on CSPLIT */
992 if (chan->qh->do_split) {
993 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
994 hsotg->core_params->dma_enable > 0) {
995 if (qtd->complete_split &&
996 dwc2_xfercomp_isoc_split_in(hsotg, chan, chnum,
998 goto handle_xfercomp_done;
1000 qtd->complete_split = 0;
1005 goto handle_xfercomp_done;
1007 /* Update the QTD and URB states */
1008 switch (pipe_type) {
1009 case USB_ENDPOINT_XFER_CONTROL:
1010 switch (qtd->control_phase) {
1011 case DWC2_CONTROL_SETUP:
1012 if (urb->length > 0)
1013 qtd->control_phase = DWC2_CONTROL_DATA;
1015 qtd->control_phase = DWC2_CONTROL_STATUS;
1016 dev_vdbg(hsotg->dev,
1017 " Control setup transaction done\n");
1018 halt_status = DWC2_HC_XFER_COMPLETE;
1020 case DWC2_CONTROL_DATA:
1021 urb_xfer_done = dwc2_update_urb_state(hsotg, chan,
1023 if (urb_xfer_done) {
1024 qtd->control_phase = DWC2_CONTROL_STATUS;
1025 dev_vdbg(hsotg->dev,
1026 " Control data transfer done\n");
1028 dwc2_hcd_save_data_toggle(hsotg, chan, chnum,
1031 halt_status = DWC2_HC_XFER_COMPLETE;
1033 case DWC2_CONTROL_STATUS:
1034 dev_vdbg(hsotg->dev, " Control transfer complete\n");
1035 if (urb->status == -EINPROGRESS)
1037 dwc2_host_complete(hsotg, urb->priv, urb, urb->status);
1038 halt_status = DWC2_HC_XFER_URB_COMPLETE;
1042 dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd,
1045 case USB_ENDPOINT_XFER_BULK:
1046 dev_vdbg(hsotg->dev, " Bulk transfer complete\n");
1047 urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb,
1049 if (urb_xfer_done) {
1050 dwc2_host_complete(hsotg, urb->priv, urb, urb->status);
1051 halt_status = DWC2_HC_XFER_URB_COMPLETE;
1053 halt_status = DWC2_HC_XFER_COMPLETE;
1056 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1057 dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd,
1060 case USB_ENDPOINT_XFER_INT:
1061 dev_vdbg(hsotg->dev, " Interrupt transfer complete\n");
1062 urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb,
1066 * Interrupt URB is done on the first transfer complete
1069 if (urb_xfer_done) {
1070 dwc2_host_complete(hsotg, urb->priv, urb,
1072 halt_status = DWC2_HC_XFER_URB_COMPLETE;
1074 halt_status = DWC2_HC_XFER_COMPLETE;
1077 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1078 dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd,
1081 case USB_ENDPOINT_XFER_ISOC:
1082 dev_vdbg(hsotg->dev, " Isochronous transfer complete\n");
1083 if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_ALL)
1084 halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
1085 chnum, qtd, DWC2_HC_XFER_COMPLETE);
1086 dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd,
1091 handle_xfercomp_done:
1092 disable_hc_int(hsotg, chnum, HCINTMSK_XFERCOMPL);
1096 * Handles a host channel STALL interrupt. This handler may be called in
1097 * either DMA mode or Slave mode.
1099 static void dwc2_hc_stall_intr(struct dwc2_hsotg *hsotg,
1100 struct dwc2_host_chan *chan, int chnum,
1101 struct dwc2_qtd *qtd)
1103 struct dwc2_hcd_urb *urb = qtd->urb;
1104 int pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
1106 dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: STALL Received--\n",
1109 if (hsotg->core_params->dma_desc_enable > 0) {
1110 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1111 DWC2_HC_XFER_STALL);
1112 goto handle_stall_done;
1116 goto handle_stall_halt;
1118 if (pipe_type == USB_ENDPOINT_XFER_CONTROL)
1119 dwc2_host_complete(hsotg, urb->priv, urb, -EPIPE);
1121 if (pipe_type == USB_ENDPOINT_XFER_BULK ||
1122 pipe_type == USB_ENDPOINT_XFER_INT) {
1123 dwc2_host_complete(hsotg, urb->priv, urb, -EPIPE);
1125 * USB protocol requires resetting the data toggle for bulk
1126 * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
1127 * setup command is issued to the endpoint. Anticipate the
1128 * CLEAR_FEATURE command since a STALL has occurred and reset
1129 * the data toggle now.
1131 chan->qh->data_toggle = 0;
1135 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_STALL);
1138 disable_hc_int(hsotg, chnum, HCINTMSK_STALL);
1142 * Updates the state of the URB when a transfer has been stopped due to an
1143 * abnormal condition before the transfer completes. Modifies the
1144 * actual_length field of the URB to reflect the number of bytes that have
1145 * actually been transferred via the host channel.
1147 static void dwc2_update_urb_state_abn(struct dwc2_hsotg *hsotg,
1148 struct dwc2_host_chan *chan, int chnum,
1149 struct dwc2_hcd_urb *urb,
1150 struct dwc2_qtd *qtd,
1151 enum dwc2_halt_status halt_status)
1153 u32 xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum,
1154 qtd, halt_status, NULL);
1157 if (urb->actual_length + xfer_length > urb->length) {
1158 dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
1159 xfer_length = urb->length - urb->actual_length;
1162 /* Non DWORD-aligned buffer case handling */
1163 if (chan->align_buf && xfer_length && chan->ep_is_in) {
1164 dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
1165 dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length,
1167 memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
1169 dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length,
1173 urb->actual_length += xfer_length;
1175 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
1176 dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
1177 __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
1178 dev_vdbg(hsotg->dev, " chan->start_pkt_count %d\n",
1179 chan->start_pkt_count);
1180 dev_vdbg(hsotg->dev, " hctsiz.pktcnt %d\n",
1181 hctsiz >> TSIZ_PKTCNT_SHIFT &
1182 TSIZ_PKTCNT_MASK >> TSIZ_PKTCNT_SHIFT);
1183 dev_vdbg(hsotg->dev, " chan->max_packet %d\n", chan->max_packet);
1184 dev_vdbg(hsotg->dev, " bytes_transferred %d\n",
1186 dev_vdbg(hsotg->dev, " urb->actual_length %d\n",
1187 urb->actual_length);
1188 dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n",
1193 * Handles a host channel NAK interrupt. This handler may be called in either
1194 * DMA mode or Slave mode.
1196 static void dwc2_hc_nak_intr(struct dwc2_hsotg *hsotg,
1197 struct dwc2_host_chan *chan, int chnum,
1198 struct dwc2_qtd *qtd)
1200 dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NAK Received--\n",
1204 * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
1205 * interrupt. Re-start the SSPLIT transfer.
1207 if (chan->do_split) {
1208 if (chan->complete_split)
1209 qtd->error_count = 0;
1210 qtd->complete_split = 0;
1211 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
1212 goto handle_nak_done;
1215 switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
1216 case USB_ENDPOINT_XFER_CONTROL:
1217 case USB_ENDPOINT_XFER_BULK:
1218 if (hsotg->core_params->dma_enable > 0 && chan->ep_is_in) {
1220 * NAK interrupts are enabled on bulk/control IN
1221 * transfers in DMA mode for the sole purpose of
1222 * resetting the error count after a transaction error
1223 * occurs. The core will continue transferring data.
1225 qtd->error_count = 0;
1230 * NAK interrupts normally occur during OUT transfers in DMA
1231 * or Slave mode. For IN transfers, more requests will be
1232 * queued as request queue space is available.
1234 qtd->error_count = 0;
1236 if (!chan->qh->ping_state) {
1237 dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
1238 qtd, DWC2_HC_XFER_NAK);
1239 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1241 if (chan->speed == USB_SPEED_HIGH)
1242 chan->qh->ping_state = 1;
1246 * Halt the channel so the transfer can be re-started from
1247 * the appropriate point or the PING protocol will
1250 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
1252 case USB_ENDPOINT_XFER_INT:
1253 qtd->error_count = 0;
1254 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
1256 case USB_ENDPOINT_XFER_ISOC:
1257 /* Should never get called for isochronous transfers */
1258 dev_err(hsotg->dev, "NACK interrupt for ISOC transfer\n");
1263 disable_hc_int(hsotg, chnum, HCINTMSK_NAK);
1267 * Handles a host channel ACK interrupt. This interrupt is enabled when
1268 * performing the PING protocol in Slave mode, when errors occur during
1269 * either Slave mode or DMA mode, and during Start Split transactions.
1271 static void dwc2_hc_ack_intr(struct dwc2_hsotg *hsotg,
1272 struct dwc2_host_chan *chan, int chnum,
1273 struct dwc2_qtd *qtd)
1275 struct dwc2_hcd_iso_packet_desc *frame_desc;
1277 dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: ACK Received--\n",
1280 if (chan->do_split) {
1281 /* Handle ACK on SSPLIT. ACK should not occur in CSPLIT. */
1282 if (!chan->ep_is_in &&
1283 chan->data_pid_start != DWC2_HC_PID_SETUP)
1284 qtd->ssplit_out_xfer_count = chan->xfer_len;
1286 if (chan->ep_type != USB_ENDPOINT_XFER_ISOC || chan->ep_is_in) {
1287 qtd->complete_split = 1;
1288 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
1291 switch (chan->xact_pos) {
1292 case DWC2_HCSPLT_XACTPOS_ALL:
1294 case DWC2_HCSPLT_XACTPOS_END:
1295 qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL;
1296 qtd->isoc_split_offset = 0;
1298 case DWC2_HCSPLT_XACTPOS_BEGIN:
1299 case DWC2_HCSPLT_XACTPOS_MID:
1301 * For BEGIN or MID, calculate the length for
1302 * the next microframe to determine the correct
1303 * SSPLIT token, either MID or END
1305 frame_desc = &qtd->urb->iso_descs[
1306 qtd->isoc_frame_index];
1307 qtd->isoc_split_offset += 188;
1309 if (frame_desc->length - qtd->isoc_split_offset
1311 qtd->isoc_split_pos =
1312 DWC2_HCSPLT_XACTPOS_END;
1314 qtd->isoc_split_pos =
1315 DWC2_HCSPLT_XACTPOS_MID;
1320 qtd->error_count = 0;
1322 if (chan->qh->ping_state) {
1323 chan->qh->ping_state = 0;
1325 * Halt the channel so the transfer can be re-started
1326 * from the appropriate point. This only happens in
1327 * Slave mode. In DMA mode, the ping_state is cleared
1328 * when the transfer is started because the core
1329 * automatically executes the PING, then the transfer.
1331 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
1336 * If the ACK occurred when _not_ in the PING state, let the channel
1337 * continue transferring data after clearing the error count
1339 disable_hc_int(hsotg, chnum, HCINTMSK_ACK);
1343 * Handles a host channel NYET interrupt. This interrupt should only occur on
1344 * Bulk and Control OUT endpoints and for complete split transactions. If a
1345 * NYET occurs at the same time as a Transfer Complete interrupt, it is
1346 * handled in the xfercomp interrupt handler, not here. This handler may be
1347 * called in either DMA mode or Slave mode.
1349 static void dwc2_hc_nyet_intr(struct dwc2_hsotg *hsotg,
1350 struct dwc2_host_chan *chan, int chnum,
1351 struct dwc2_qtd *qtd)
1353 dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NYET Received--\n",
1358 * re-do the CSPLIT immediately on non-periodic
1360 if (chan->do_split && chan->complete_split) {
1361 if (chan->ep_is_in && chan->ep_type == USB_ENDPOINT_XFER_ISOC &&
1362 hsotg->core_params->dma_enable > 0) {
1363 qtd->complete_split = 0;
1364 qtd->isoc_split_offset = 0;
1365 if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
1367 dwc2_host_complete(hsotg,
1370 dwc2_release_channel(hsotg, chan, qtd,
1371 DWC2_HC_XFER_URB_COMPLETE);
1373 dwc2_release_channel(hsotg, chan, qtd,
1374 DWC2_HC_XFER_NO_HALT_STATUS);
1376 goto handle_nyet_done;
1379 if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
1380 chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
1381 int frnum = dwc2_hcd_get_frame_number(hsotg);
1383 if (dwc2_full_frame_num(frnum) !=
1384 dwc2_full_frame_num(chan->qh->sched_frame)) {
1386 * No longer in the same full speed frame.
1387 * Treat this as a transaction error.
1391 * Todo: Fix system performance so this can
1392 * be treated as an error. Right now complete
1393 * splits cannot be scheduled precisely enough
1394 * due to other system activity, so this error
1395 * occurs regularly in Slave mode.
1399 qtd->complete_split = 0;
1400 dwc2_halt_channel(hsotg, chan, qtd,
1401 DWC2_HC_XFER_XACT_ERR);
1402 /* Todo: add support for isoc release */
1403 goto handle_nyet_done;
1407 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
1408 goto handle_nyet_done;
1411 chan->qh->ping_state = 1;
1412 qtd->error_count = 0;
1414 dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb, qtd,
1416 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1419 * Halt the channel and re-start the transfer so the PING protocol
1422 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
1425 disable_hc_int(hsotg, chnum, HCINTMSK_NYET);
1429 * Handles a host channel babble interrupt. This handler may be called in
1430 * either DMA mode or Slave mode.
1432 static void dwc2_hc_babble_intr(struct dwc2_hsotg *hsotg,
1433 struct dwc2_host_chan *chan, int chnum,
1434 struct dwc2_qtd *qtd)
1436 dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Babble Error--\n",
1439 if (hsotg->core_params->dma_desc_enable > 0) {
1440 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1441 DWC2_HC_XFER_BABBLE_ERR);
1442 goto handle_babble_done;
1445 if (chan->ep_type != USB_ENDPOINT_XFER_ISOC) {
1447 dwc2_host_complete(hsotg, qtd->urb->priv, qtd->urb,
1449 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_BABBLE_ERR);
1451 enum dwc2_halt_status halt_status;
1453 halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
1454 qtd, DWC2_HC_XFER_BABBLE_ERR);
1455 dwc2_halt_channel(hsotg, chan, qtd, halt_status);
1459 dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
1460 disable_hc_int(hsotg, chnum, HCINTMSK_BBLERR);
1464 * Handles a host channel AHB error interrupt. This handler is only called in
1467 static void dwc2_hc_ahberr_intr(struct dwc2_hsotg *hsotg,
1468 struct dwc2_host_chan *chan, int chnum,
1469 struct dwc2_qtd *qtd)
1471 struct dwc2_hcd_urb *urb = qtd->urb;
1472 char *pipetype, *speed;
1478 dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: AHB Error--\n",
1482 goto handle_ahberr_halt;
1484 hcchar = readl(hsotg->regs + HCCHAR(chnum));
1485 hcsplt = readl(hsotg->regs + HCSPLT(chnum));
1486 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
1487 hc_dma = readl(hsotg->regs + HCDMA(chnum));
1489 dev_err(hsotg->dev, "AHB ERROR, Channel %d\n", chnum);
1490 dev_err(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", hcchar, hcsplt);
1491 dev_err(hsotg->dev, " hctsiz 0x%08x, hc_dma 0x%08x\n", hctsiz, hc_dma);
1492 dev_err(hsotg->dev, " Device address: %d\n",
1493 dwc2_hcd_get_dev_addr(&urb->pipe_info));
1494 dev_err(hsotg->dev, " Endpoint: %d, %s\n",
1495 dwc2_hcd_get_ep_num(&urb->pipe_info),
1496 dwc2_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
1498 switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) {
1499 case USB_ENDPOINT_XFER_CONTROL:
1500 pipetype = "CONTROL";
1502 case USB_ENDPOINT_XFER_BULK:
1505 case USB_ENDPOINT_XFER_INT:
1506 pipetype = "INTERRUPT";
1508 case USB_ENDPOINT_XFER_ISOC:
1509 pipetype = "ISOCHRONOUS";
1512 pipetype = "UNKNOWN";
1516 dev_err(hsotg->dev, " Endpoint type: %s\n", pipetype);
1518 switch (chan->speed) {
1519 case USB_SPEED_HIGH:
1522 case USB_SPEED_FULL:
1533 dev_err(hsotg->dev, " Speed: %s\n", speed);
1535 dev_err(hsotg->dev, " Max packet size: %d\n",
1536 dwc2_hcd_get_mps(&urb->pipe_info));
1537 dev_err(hsotg->dev, " Data buffer length: %d\n", urb->length);
1538 dev_err(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %p\n",
1539 urb->buf, (void *)urb->dma);
1540 dev_err(hsotg->dev, " Setup buffer: %p, Setup DMA: %p\n",
1541 urb->setup_packet, (void *)urb->setup_dma);
1542 dev_err(hsotg->dev, " Interval: %d\n", urb->interval);
1544 /* Core halts the channel for Descriptor DMA mode */
1545 if (hsotg->core_params->dma_desc_enable > 0) {
1546 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1547 DWC2_HC_XFER_AHB_ERR);
1548 goto handle_ahberr_done;
1551 dwc2_host_complete(hsotg, urb->priv, urb, -EIO);
1555 * Force a channel halt. Don't call dwc2_halt_channel because that won't
1556 * write to the HCCHARn register in DMA mode to force the halt.
1558 dwc2_hc_halt(hsotg, chan, DWC2_HC_XFER_AHB_ERR);
1561 dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
1562 disable_hc_int(hsotg, chnum, HCINTMSK_AHBERR);
1566 * Handles a host channel transaction error interrupt. This handler may be
1567 * called in either DMA mode or Slave mode.
1569 static void dwc2_hc_xacterr_intr(struct dwc2_hsotg *hsotg,
1570 struct dwc2_host_chan *chan, int chnum,
1571 struct dwc2_qtd *qtd)
1574 "--Host Channel %d Interrupt: Transaction Error--\n", chnum);
1576 if (hsotg->core_params->dma_desc_enable > 0) {
1577 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1578 DWC2_HC_XFER_XACT_ERR);
1579 goto handle_xacterr_done;
1582 switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
1583 case USB_ENDPOINT_XFER_CONTROL:
1584 case USB_ENDPOINT_XFER_BULK:
1586 if (!chan->qh->ping_state) {
1588 dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
1589 qtd, DWC2_HC_XFER_XACT_ERR);
1590 dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
1591 if (!chan->ep_is_in && chan->speed == USB_SPEED_HIGH)
1592 chan->qh->ping_state = 1;
1596 * Halt the channel so the transfer can be re-started from
1597 * the appropriate point or the PING protocol will start
1599 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
1601 case USB_ENDPOINT_XFER_INT:
1603 if (chan->do_split && chan->complete_split)
1604 qtd->complete_split = 0;
1605 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
1607 case USB_ENDPOINT_XFER_ISOC:
1609 enum dwc2_halt_status halt_status;
1611 halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
1612 chnum, qtd, DWC2_HC_XFER_XACT_ERR);
1613 dwc2_halt_channel(hsotg, chan, qtd, halt_status);
1618 handle_xacterr_done:
1619 dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
1620 disable_hc_int(hsotg, chnum, HCINTMSK_XACTERR);
1624 * Handles a host channel frame overrun interrupt. This handler may be called
1625 * in either DMA mode or Slave mode.
1627 static void dwc2_hc_frmovrun_intr(struct dwc2_hsotg *hsotg,
1628 struct dwc2_host_chan *chan, int chnum,
1629 struct dwc2_qtd *qtd)
1631 enum dwc2_halt_status halt_status;
1633 dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Frame Overrun--\n",
1636 switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
1637 case USB_ENDPOINT_XFER_CONTROL:
1638 case USB_ENDPOINT_XFER_BULK:
1640 case USB_ENDPOINT_XFER_INT:
1641 dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_FRAME_OVERRUN);
1643 case USB_ENDPOINT_XFER_ISOC:
1644 halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
1645 qtd, DWC2_HC_XFER_FRAME_OVERRUN);
1646 dwc2_halt_channel(hsotg, chan, qtd, halt_status);
1650 dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
1651 disable_hc_int(hsotg, chnum, HCINTMSK_FRMOVRUN);
1655 * Handles a host channel data toggle error interrupt. This handler may be
1656 * called in either DMA mode or Slave mode.
1658 static void dwc2_hc_datatglerr_intr(struct dwc2_hsotg *hsotg,
1659 struct dwc2_host_chan *chan, int chnum,
1660 struct dwc2_qtd *qtd)
1663 "--Host Channel %d Interrupt: Data Toggle Error--\n", chnum);
1666 qtd->error_count = 0;
1669 "Data Toggle Error on OUT transfer, channel %d\n",
1672 dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
1673 disable_hc_int(hsotg, chnum, HCINTMSK_DATATGLERR);
1677 * For debug only. It checks that a valid halt status is set and that
1678 * HCCHARn.chdis is clear. If there's a problem, corrective action is
1679 * taken and a warning is issued.
1681 * Return: true if halt status is ok, false otherwise
1683 static bool dwc2_halt_status_ok(struct dwc2_hsotg *hsotg,
1684 struct dwc2_host_chan *chan, int chnum,
1685 struct dwc2_qtd *qtd)
1693 if (chan->halt_status == DWC2_HC_XFER_NO_HALT_STATUS) {
1695 * This code is here only as a check. This condition should
1696 * never happen. Ignore the halt if it does occur.
1698 hcchar = readl(hsotg->regs + HCCHAR(chnum));
1699 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
1700 hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
1701 hcsplt = readl(hsotg->regs + HCSPLT(chnum));
1703 "%s: chan->halt_status DWC2_HC_XFER_NO_HALT_STATUS,\n",
1706 "channel %d, hcchar 0x%08x, hctsiz 0x%08x,\n",
1707 chnum, hcchar, hctsiz);
1709 "hcint 0x%08x, hcintmsk 0x%08x, hcsplt 0x%08x,\n",
1710 chan->hcint, hcintmsk, hcsplt);
1711 dev_dbg(hsotg->dev, "qtd->complete_split %d\n",
1712 qtd->complete_split);
1713 dev_warn(hsotg->dev,
1714 "%s: no halt status, channel %d, ignoring interrupt\n",
1720 * This code is here only as a check. hcchar.chdis should never be set
1721 * when the halt interrupt occurs. Halt the channel again if it does
1724 hcchar = readl(hsotg->regs + HCCHAR(chnum));
1725 if (hcchar & HCCHAR_CHDIS) {
1726 dev_warn(hsotg->dev,
1727 "%s: hcchar.chdis set unexpectedly, hcchar 0x%08x, trying to halt again\n",
1729 chan->halt_pending = 0;
1730 dwc2_halt_channel(hsotg, chan, qtd, chan->halt_status);
1739 * Handles a host Channel Halted interrupt in DMA mode. This handler
1740 * determines the reason the channel halted and proceeds accordingly.
1742 static void dwc2_hc_chhltd_intr_dma(struct dwc2_hsotg *hsotg,
1743 struct dwc2_host_chan *chan, int chnum,
1744 struct dwc2_qtd *qtd)
1747 int out_nak_enh = 0;
1749 dev_vdbg(hsotg->dev,
1750 "--Host Channel %d Interrupt: DMA Channel Halted--\n", chnum);
1753 * For core with OUT NAK enhancement, the flow for high-speed
1754 * CONTROL/BULK OUT is handled a little differently
1756 if (hsotg->snpsid >= DWC2_CORE_REV_2_71a) {
1757 if (chan->speed == USB_SPEED_HIGH && !chan->ep_is_in &&
1758 (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
1759 chan->ep_type == USB_ENDPOINT_XFER_BULK)) {
1764 if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE ||
1765 (chan->halt_status == DWC2_HC_XFER_AHB_ERR &&
1766 hsotg->core_params->dma_desc_enable <= 0)) {
1767 if (hsotg->core_params->dma_desc_enable > 0)
1768 dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
1772 * Just release the channel. A dequeue can happen on a
1773 * transfer timeout. In the case of an AHB Error, the
1774 * channel was forced to halt because there's no way to
1775 * gracefully recover.
1777 dwc2_release_channel(hsotg, chan, qtd,
1782 hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
1784 if (chan->hcint & HCINTMSK_XFERCOMPL) {
1786 * Todo: This is here because of a possible hardware bug. Spec
1787 * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
1788 * interrupt w/ACK bit set should occur, but I only see the
1789 * XFERCOMP bit, even with it masked out. This is a workaround
1790 * for that behavior. Should fix this when hardware is fixed.
1792 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && !chan->ep_is_in)
1793 dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
1794 dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
1795 } else if (chan->hcint & HCINTMSK_STALL) {
1796 dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
1797 } else if ((chan->hcint & HCINTMSK_XACTERR) &&
1798 hsotg->core_params->dma_desc_enable <= 0) {
1801 (HCINTMSK_NYET | HCINTMSK_NAK | HCINTMSK_ACK)) {
1802 dev_vdbg(hsotg->dev,
1803 "XactErr with NYET/NAK/ACK\n");
1804 qtd->error_count = 0;
1806 dev_vdbg(hsotg->dev,
1807 "XactErr without NYET/NAK/ACK\n");
1812 * Must handle xacterr before nak or ack. Could get a xacterr
1813 * at the same time as either of these on a BULK/CONTROL OUT
1814 * that started with a PING. The xacterr takes precedence.
1816 dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
1817 } else if ((chan->hcint & HCINTMSK_XCS_XACT) &&
1818 hsotg->core_params->dma_desc_enable > 0) {
1819 dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
1820 } else if ((chan->hcint & HCINTMSK_AHBERR) &&
1821 hsotg->core_params->dma_desc_enable > 0) {
1822 dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
1823 } else if (chan->hcint & HCINTMSK_BBLERR) {
1824 dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
1825 } else if (chan->hcint & HCINTMSK_FRMOVRUN) {
1826 dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
1827 } else if (!out_nak_enh) {
1828 if (chan->hcint & HCINTMSK_NYET) {
1830 * Must handle nyet before nak or ack. Could get a nyet
1831 * at the same time as either of those on a BULK/CONTROL
1832 * OUT that started with a PING. The nyet takes
1835 dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
1836 } else if ((chan->hcint & HCINTMSK_NAK) &&
1837 !(hcintmsk & HCINTMSK_NAK)) {
1839 * If nak is not masked, it's because a non-split IN
1840 * transfer is in an error state. In that case, the nak
1841 * is handled by the nak interrupt handler, not here.
1842 * Handle nak here for BULK/CONTROL OUT transfers, which
1843 * halt on a NAK to allow rewinding the buffer pointer.
1845 dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
1846 } else if ((chan->hcint & HCINTMSK_ACK) &&
1847 !(hcintmsk & HCINTMSK_ACK)) {
1849 * If ack is not masked, it's because a non-split IN
1850 * transfer is in an error state. In that case, the ack
1851 * is handled by the ack interrupt handler, not here.
1852 * Handle ack here for split transfers. Start splits
1855 dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
1857 if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
1858 chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
1860 * A periodic transfer halted with no other
1861 * channel interrupts set. Assume it was halted
1862 * by the core because it could not be completed
1863 * in its scheduled (micro)frame.
1866 "%s: Halt channel %d (assume incomplete periodic transfer)\n",
1868 dwc2_halt_channel(hsotg, chan, qtd,
1869 DWC2_HC_XFER_PERIODIC_INCOMPLETE);
1872 "%s: Channel %d - ChHltd set, but reason is unknown\n",
1875 "hcint 0x%08x, intsts 0x%08x\n",
1877 readl(hsotg->regs + GINTSTS));
1881 dev_info(hsotg->dev,
1882 "NYET/NAK/ACK/other in non-error case, 0x%08x\n",
1888 * Handles a host channel Channel Halted interrupt
1890 * In slave mode, this handler is called only when the driver specifically
1891 * requests a halt. This occurs during handling other host channel interrupts
1892 * (e.g. nak, xacterr, stall, nyet, etc.).
1894 * In DMA mode, this is the interrupt that occurs when the core has finished
1895 * processing a transfer on a channel. Other host channel interrupts (except
1896 * ahberr) are disabled in DMA mode.
1898 static void dwc2_hc_chhltd_intr(struct dwc2_hsotg *hsotg,
1899 struct dwc2_host_chan *chan, int chnum,
1900 struct dwc2_qtd *qtd)
1902 dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: Channel Halted--\n",
1905 if (hsotg->core_params->dma_enable > 0) {
1906 dwc2_hc_chhltd_intr_dma(hsotg, chan, chnum, qtd);
1908 if (!dwc2_halt_status_ok(hsotg, chan, chnum, qtd))
1910 dwc2_release_channel(hsotg, chan, qtd, chan->halt_status);
1914 /* Handles interrupt for a specific Host Channel */
1915 static void dwc2_hc_n_intr(struct dwc2_hsotg *hsotg, int chnum)
1917 struct dwc2_qtd *qtd;
1918 struct dwc2_host_chan *chan;
1919 u32 hcint, hcintmsk;
1921 dev_vdbg(hsotg->dev, "--Host Channel Interrupt--, Channel %d\n", chnum);
1923 hcint = readl(hsotg->regs + HCINT(chnum));
1924 hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
1925 dev_vdbg(hsotg->dev,
1926 " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
1927 hcint, hcintmsk, hcint & hcintmsk);
1929 chan = hsotg->hc_ptr_array[chnum];
1931 dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n");
1932 writel(hcint, hsotg->regs + HCINT(chnum));
1936 writel(hcint, hsotg->regs + HCINT(chnum));
1937 chan->hcint = hcint;
1940 if (list_empty(&chan->qh->qtd_list)) {
1941 dev_dbg(hsotg->dev, "## no QTD queued for channel %d ##\n",
1944 " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
1945 chan->hcint, hcintmsk, hcint);
1946 chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS;
1947 disable_hc_int(hsotg, chnum, HCINTMSK_CHHLTD);
1952 qtd = list_first_entry(&chan->qh->qtd_list, struct dwc2_qtd,
1955 if (hsotg->core_params->dma_enable <= 0) {
1956 if ((hcint & HCINTMSK_CHHLTD) && hcint != HCINTMSK_CHHLTD)
1957 hcint &= ~HCINTMSK_CHHLTD;
1960 if (hcint & HCINTMSK_XFERCOMPL) {
1961 dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
1963 * If NYET occurred at same time as Xfer Complete, the NYET is
1964 * handled by the Xfer Complete interrupt handler. Don't want
1965 * to call the NYET interrupt handler in this case.
1967 hcint &= ~HCINTMSK_NYET;
1969 if (hcint & HCINTMSK_CHHLTD)
1970 dwc2_hc_chhltd_intr(hsotg, chan, chnum, qtd);
1971 if (hcint & HCINTMSK_AHBERR)
1972 dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
1973 if (hcint & HCINTMSK_STALL)
1974 dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
1975 if (hcint & HCINTMSK_NAK)
1976 dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
1977 if (hcint & HCINTMSK_ACK)
1978 dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
1979 if (hcint & HCINTMSK_NYET)
1980 dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
1981 if (hcint & HCINTMSK_XACTERR)
1982 dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
1983 if (hcint & HCINTMSK_BBLERR)
1984 dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
1985 if (hcint & HCINTMSK_FRMOVRUN)
1986 dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
1987 if (hcint & HCINTMSK_DATATGLERR)
1988 dwc2_hc_datatglerr_intr(hsotg, chan, chnum, qtd);
1994 * This interrupt indicates that one or more host channels has a pending
1995 * interrupt. There are multiple conditions that can cause each host channel
1996 * interrupt. This function determines which conditions have occurred for each
1997 * host channel interrupt and handles them appropriately.
1999 static void dwc2_hc_intr(struct dwc2_hsotg *hsotg)
2004 dev_vdbg(hsotg->dev, "%s()\n", __func__);
2006 haint = readl(hsotg->regs + HAINT);
2007 dev_vdbg(hsotg->dev, "HAINT=%08x\n", haint);
2009 for (i = 0; i < hsotg->core_params->host_channels; i++) {
2010 if (haint & (1 << i))
2011 dwc2_hc_n_intr(hsotg, i);
2015 /* This function handles interrupts for the HCD */
2016 int dwc2_hcd_intr(struct dwc2_hsotg *hsotg)
2021 if (dwc2_check_core_status(hsotg) < 0) {
2022 dev_warn(hsotg->dev, "Controller is disconnected");
2026 spin_lock(&hsotg->lock);
2028 /* Check if HOST Mode */
2029 if (dwc2_is_host_mode(hsotg)) {
2030 gintsts = dwc2_read_core_intr(hsotg);
2032 spin_unlock(&hsotg->lock);
2039 /* Don't print debug message in the interrupt handler on SOF */
2040 if (gintsts != GINTSTS_SOF)
2042 dev_vdbg(hsotg->dev,
2043 "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n",
2046 if (gintsts & GINTSTS_SOF)
2047 dwc2_sof_intr(hsotg);
2048 if (gintsts & GINTSTS_RXFLVL)
2049 dwc2_rx_fifo_level_intr(hsotg);
2050 if (gintsts & GINTSTS_NPTXFEMP)
2051 dwc2_np_tx_fifo_empty_intr(hsotg);
2052 if (gintsts & GINTSTS_I2CINT)
2053 /* Todo: Implement i2cintr handler */
2054 writel(GINTSTS_I2CINT, hsotg->regs + GINTSTS);
2055 if (gintsts & GINTSTS_PRTINT)
2056 dwc2_port_intr(hsotg);
2057 if (gintsts & GINTSTS_HCHINT)
2058 dwc2_hc_intr(hsotg);
2059 if (gintsts & GINTSTS_PTXFEMP)
2060 dwc2_perio_tx_fifo_empty_intr(hsotg);
2063 if (gintsts != GINTSTS_SOF) {
2065 dev_vdbg(hsotg->dev,
2066 "DWC OTG HCD Finished Servicing Interrupts\n");
2067 dev_vdbg(hsotg->dev,
2068 "DWC OTG HCD gintsts=0x%08x gintmsk=0x%08x\n",
2069 readl(hsotg->regs + GINTSTS),
2070 readl(hsotg->regs + GINTMSK));
2076 spin_unlock(&hsotg->lock);