1 /* ==========================================================================
2 * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
7 * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8 * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9 * otherwise expressly agreed to in writing between Synopsys and you.
11 * The Software IS NOT an item of Licensed Software or Licensed Product under
12 * any End User Software License Agreement or Agreement for Licensed Product
13 * with Synopsys or any supplement thereto. You are permitted to use and
14 * redistribute this Software in source and binary forms, with or without
15 * modification, provided that redistributions of source code must retain this
16 * notice. You may not view, use, disclose, copy or distribute this file or
17 * any information contained herein except pursuant to this license grant from
18 * Synopsys. If you do not agree with this notice, including the disclaimer
19 * below, then you are not authorized to use the Software.
21 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32 * ========================================================================== */
33 #ifndef DWC_DEVICE_ONLY
37 #include "dwc_otg_driver.h"
38 #include "dwc_otg_hcd.h"
39 #include "dwc_otg_regs.h"
42 * This file contains the implementation of the HCD Interrupt handlers.
45 /** This function handles interrupts for the HCD. */
46 int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
50 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
51 gintsts_data_t gintsts;
53 dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
56 /* Exit from ISR if core is hibernated */
57 if (core_if->hibernation_suspend == 1) {
60 DWC_SPINLOCK(dwc_otg_hcd->lock);
61 /* Check if HOST Mode */
62 if (dwc_otg_is_host_mode(core_if)) {
63 gintsts.d32 = dwc_otg_read_core_intr(core_if);
65 DWC_SPINUNLOCK(dwc_otg_hcd->lock);
69 /* Don't print debug message in the interrupt handler on SOF */
71 if (gintsts.d32 != DWC_SOF_INTR_MASK)
73 DWC_DEBUGPL(DBG_HCD, "\n");
78 if (gintsts.d32 != DWC_SOF_INTR_MASK)
81 "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n",
85 if (gintsts.b.sofintr) {
86 retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
88 if (gintsts.b.rxstsqlvl) {
90 dwc_otg_hcd_handle_rx_status_q_level_intr
93 if (gintsts.b.nptxfempty) {
95 dwc_otg_hcd_handle_np_tx_fifo_empty_intr
98 if (gintsts.b.i2cintr) {
99 /** @todo Implement i2cintr handler. */
101 if (gintsts.b.portintr) {
102 retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
104 if (gintsts.b.hcintr) {
105 retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
107 if (gintsts.b.ptxfempty) {
109 dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
114 if (gintsts.d32 != DWC_SOF_INTR_MASK)
118 "DWC OTG HCD Finished Servicing Interrupts\n");
119 DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
120 DWC_READ_REG32(&global_regs->gintsts));
121 DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
122 DWC_READ_REG32(&global_regs->gintmsk));
128 if (gintsts.d32 != DWC_SOF_INTR_MASK)
130 DWC_DEBUGPL(DBG_HCD, "\n");
134 DWC_SPINUNLOCK(dwc_otg_hcd->lock);
138 #ifdef DWC_TRACK_MISSED_SOFS
139 #warning Compiling code to track missed SOFs
140 #define FRAME_NUM_ARRAY_SIZE 1000
142 * This function is for debug only.
144 static inline void track_missed_sofs(uint16_t curr_frame_number)
146 static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
147 static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
148 static int frame_num_idx = 0;
149 static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
150 static int dumped_frame_num_array = 0;
152 if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
153 if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
155 frame_num_array[frame_num_idx] = curr_frame_number;
156 last_frame_num_array[frame_num_idx++] = last_frame_num;
158 } else if (!dumped_frame_num_array) {
160 DWC_PRINTF("Frame Last Frame\n");
161 DWC_PRINTF("----- ----------\n");
162 for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
163 DWC_PRINTF("0x%04x 0x%04x\n",
164 frame_num_array[i], last_frame_num_array[i]);
166 dumped_frame_num_array = 1;
168 last_frame_num = curr_frame_number;
173 * Handles the start-of-frame interrupt in host mode. Non-periodic
174 * transactions may be queued to the DWC_otg controller for the current
175 * (micro)frame. Periodic transactions may be queued to the controller for the
178 int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
181 dwc_list_link_t *qh_entry;
183 dwc_otg_transaction_type_e tr_type;
184 gintsts_data_t gintsts = {.d32 = 0 };
187 DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
190 DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
192 hcd->frame_number = hfnum.b.frnum;
195 hcd->frrem_accum += hfnum.b.frrem;
196 hcd->frrem_samples++;
199 #ifdef DWC_TRACK_MISSED_SOFS
200 track_missed_sofs(hcd->frame_number);
202 /* Determine whether any periodic QHs should be executed. */
203 qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
204 while (qh_entry != &hcd->periodic_sched_inactive) {
205 qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
206 qh_entry = qh_entry->next;
207 if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
209 * Move QH to the ready list to be executed next
212 DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
216 tr_type = dwc_otg_hcd_select_transactions(hcd);
217 if (tr_type != DWC_OTG_TRANSACTION_NONE) {
218 dwc_otg_hcd_queue_transactions(hcd, tr_type);
221 /* Clear interrupt */
222 gintsts.b.sofintr = 1;
223 DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
228 /** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
229 * least one packet in the Rx FIFO. The packets are moved from the FIFO to
230 * memory if the DWC_otg controller is operating in Slave mode. */
231 int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
233 host_grxsts_data_t grxsts;
236 DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
239 DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
241 hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
243 DWC_ERROR("Unable to get corresponding channel\n");
248 DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
249 DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
250 DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
252 DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
254 switch (grxsts.b.pktsts) {
255 case DWC_GRXSTS_PKTSTS_IN:
256 /* Read the data into the host buffer. */
257 if (grxsts.b.bcnt > 0) {
258 dwc_otg_read_packet(dwc_otg_hcd->core_if,
259 hc->xfer_buff, grxsts.b.bcnt);
261 /* Update the HC fields for the next packet received. */
262 hc->xfer_count += grxsts.b.bcnt;
263 hc->xfer_buff += grxsts.b.bcnt;
266 case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
267 case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
268 case DWC_GRXSTS_PKTSTS_CH_HALTED:
269 /* Handled in interrupt, just ignore data */
272 DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
280 /** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
281 * data packets may be written to the FIFO for OUT transfers. More requests
282 * may be written to the non-periodic request queue for IN transfers. This
283 * interrupt is enabled only in Slave mode. */
284 int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
286 DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
287 dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
288 DWC_OTG_TRANSACTION_NON_PERIODIC);
292 /** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
293 * packets may be written to the FIFO for OUT transfers. More requests may be
294 * written to the periodic request queue for IN transfers. This interrupt is
295 * enabled only in Slave mode. */
296 int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
298 DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
299 dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
300 DWC_OTG_TRANSACTION_PERIODIC);
304 /** There are multiple conditions that can cause a port interrupt. This function
305 * determines which interrupt conditions have occurred and handles them
307 int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
311 hprt0_data_t hprt0_modify;
313 hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
314 hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
316 /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
319 hprt0_modify.b.prtena = 0;
320 hprt0_modify.b.prtconndet = 0;
321 hprt0_modify.b.prtenchng = 0;
322 hprt0_modify.b.prtovrcurrchng = 0;
324 /* Port Connect Detected
325 * Set flag and clear if detected */
326 if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
327 // Dont modify port status if we are in hibernation state
328 hprt0_modify.b.prtconndet = 1;
329 hprt0_modify.b.prtenchng = 1;
330 DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
331 hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
335 if (hprt0.b.prtconndet) {
336 /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
337 if (dwc_otg_hcd->core_if->adp_enable &&
338 dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
339 DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
340 DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
341 dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
342 /* TODO - check if this is required, as
343 * host initialization was already performed
344 * after initial ADP probing
346 /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
347 dwc_otg_core_init(dwc_otg_hcd->core_if);
348 dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
349 cil_hcd_start(dwc_otg_hcd->core_if);*/
352 DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
353 "Port Connect Detected--\n", hprt0.d32);
354 dwc_otg_hcd->flags.b.port_connect_status_change = 1;
355 dwc_otg_hcd->flags.b.port_connect_status = 1;
356 hprt0_modify.b.prtconndet = 1;
358 /* B-Device has connected, Delete the connection timer. */
359 DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
361 /* The Hub driver asserts a reset when it sees port connect
362 * status change flag */
366 /* Port Enable Changed
367 * Clear if detected - Set internal flag if disabled */
368 if (hprt0.b.prtenchng) {
369 DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
370 "Port Enable Changed--\n", hprt0.d32);
371 hprt0_modify.b.prtenchng = 1;
372 if (hprt0.b.prtena == 1) {
375 dwc_otg_core_params_t *params =
376 dwc_otg_hcd->core_if->core_params;
377 dwc_otg_core_global_regs_t *global_regs =
378 dwc_otg_hcd->core_if->core_global_regs;
379 dwc_otg_host_if_t *host_if =
380 dwc_otg_hcd->core_if->host_if;
382 /* Every time when port enables calculate
385 hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
386 hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
387 DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
389 /* Check if we need to adjust the PHY clock speed for
390 * low power and adjust it */
391 if (params->host_support_fs_ls_low_power) {
392 gusbcfg_data_t usbcfg;
395 DWC_READ_REG32(&global_regs->gusbcfg);
397 if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
399 DWC_HPRT0_PRTSPD_FULL_SPEED) {
404 if (usbcfg.b.phylpwrclksel == 0) {
405 /* Set PHY low power clock select for FS/LS devices */
406 usbcfg.b.phylpwrclksel = 1;
408 (&global_regs->gusbcfg,
415 (&host_if->host_global_regs->hcfg);
417 if (hprt0.b.prtspd ==
418 DWC_HPRT0_PRTSPD_LOW_SPEED
419 && params->host_ls_low_power_phy_clk
421 DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
425 "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
426 if (hcfg.b.fslspclksel !=
431 (&host_if->host_global_regs->hcfg,
438 "FS_PHY programming HCFG to 48 MHz ()\n");
439 if (hcfg.b.fslspclksel !=
444 (&host_if->host_global_regs->hcfg,
453 if (usbcfg.b.phylpwrclksel == 1) {
454 usbcfg.b.phylpwrclksel = 0;
456 (&global_regs->gusbcfg,
463 DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
468 /* Port has been enabled set the reset change flag */
469 dwc_otg_hcd->flags.b.port_reset_change = 1;
472 dwc_otg_hcd->flags.b.port_enable_change = 1;
477 /** Overcurrent Change Interrupt */
478 if (hprt0.b.prtovrcurrchng) {
479 DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
480 "Port Overcurrent Changed--\n", hprt0.d32);
481 dwc_otg_hcd->flags.b.port_over_current_change = 1;
482 hprt0_modify.b.prtovrcurrchng = 1;
486 /* Clear Port Interrupts */
487 DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
492 /** This interrupt indicates that one or more host channels has a pending
493 * interrupt. There are multiple conditions that can cause each host channel
494 * interrupt. This function determines which conditions have occurred for each
495 * host channel interrupt and handles them appropriately. */
496 int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
502 /* Clear appropriate bits in HCINTn to clear the interrupt bit in
505 haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
507 for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
508 if (haint.b2.chint & (1 << i)) {
509 retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
517 * Gets the actual length of a transfer after the transfer halts. _halt_status
518 * holds the reason for the halt.
520 * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
521 * *short_read is set to 1 upon return if less than the requested
522 * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
523 * return. short_read may also be NULL on entry, in which case it remains
526 static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
527 dwc_otg_hc_regs_t * hc_regs,
529 dwc_otg_halt_status_e halt_status,
532 hctsiz_data_t hctsiz;
535 if (short_read != NULL) {
538 hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
540 if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
542 length = hc->xfer_len - hctsiz.b.xfersize;
543 if (short_read != NULL) {
544 *short_read = (hctsiz.b.xfersize != 0);
546 } else if (hc->qh->do_split) {
547 length = qtd->ssplit_out_xfer_count;
549 length = hc->xfer_len;
553 * Must use the hctsiz.pktcnt field to determine how much data
554 * has been transferred. This field reflects the number of
555 * packets that have been transferred via the USB. This is
556 * always an integral number of packets if the transfer was
557 * halted before its normal completion. (Can't use the
558 * hctsiz.xfersize field because that reflects the number of
559 * bytes transferred via the AHB, not the USB).
562 (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
569 * Updates the state of the URB after a Transfer Complete interrupt on the
570 * host channel. Updates the actual_length field of the URB based on the
571 * number of bytes transferred via the host channel. Sets the URB status
572 * if the data transfer is finished.
574 * @return 1 if the data transfer specified by the URB is completely finished,
577 static int update_urb_state_xfer_comp(dwc_hc_t * hc,
578 dwc_otg_hc_regs_t * hc_regs,
579 dwc_otg_hcd_urb_t * urb,
587 xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
588 DWC_OTG_HC_XFER_COMPLETE,
592 /* non DWORD-aligned buffer case handling. */
593 if (hc->align_buff && xfer_length && hc->ep_is_in) {
594 dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
598 urb->actual_length += xfer_length;
600 if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
601 (urb->flags & URB_SEND_ZERO_PACKET)
602 && (urb->actual_length == urb->length)
603 && !(urb->length % hc->max_packet)) {
605 } else if (short_read || urb->actual_length >= urb->length) {
612 hctsiz_data_t hctsiz;
613 hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
614 DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
615 __func__, (hc->ep_is_in ? "IN" : "OUT"),
617 DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
618 DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
620 DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
622 DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
624 DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
625 short_read, xfer_done);
633 * Save the starting data toggle for the next transfer. The data toggle is
634 * saved in the QH for non-control transfers and it's saved in the QTD for
637 void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
638 dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
640 hctsiz_data_t hctsiz;
641 hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
643 if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
644 dwc_otg_qh_t *qh = hc->qh;
645 if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
646 qh->data_toggle = DWC_OTG_HC_PID_DATA0;
648 qh->data_toggle = DWC_OTG_HC_PID_DATA1;
651 if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
652 qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
654 qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
660 * Updates the state of an Isochronous URB when the transfer is stopped for
661 * any reason. The fields of the current entry in the frame descriptor array
662 * are set based on the transfer state and the input _halt_status. Completes
663 * the Isochronous URB if all the URB frames have been completed.
665 * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
666 * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
668 static dwc_otg_halt_status_e
669 update_isoc_urb_state(dwc_otg_hcd_t * hcd,
671 dwc_otg_hc_regs_t * hc_regs,
672 dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
674 dwc_otg_hcd_urb_t *urb = qtd->urb;
675 dwc_otg_halt_status_e ret_val = halt_status;
676 struct dwc_otg_hcd_iso_packet_desc *frame_desc;
678 frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
679 switch (halt_status) {
680 case DWC_OTG_HC_XFER_COMPLETE:
681 frame_desc->status = 0;
682 frame_desc->actual_length =
683 get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
685 /* non DWORD-aligned buffer case handling. */
686 if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
687 dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
688 hc->qh->dw_align_buf, frame_desc->actual_length);
692 case DWC_OTG_HC_XFER_FRAME_OVERRUN:
695 frame_desc->status = -DWC_E_NO_STREAM_RES;
697 frame_desc->status = -DWC_E_COMMUNICATION;
699 frame_desc->actual_length = 0;
701 case DWC_OTG_HC_XFER_BABBLE_ERR:
703 frame_desc->status = -DWC_E_OVERFLOW;
704 /* Don't need to update actual_length in this case. */
706 case DWC_OTG_HC_XFER_XACT_ERR:
708 frame_desc->status = -DWC_E_PROTOCOL;
709 frame_desc->actual_length =
710 get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
712 /* non DWORD-aligned buffer case handling. */
713 if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
714 dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
715 hc->qh->dw_align_buf, frame_desc->actual_length);
717 /* Skip whole frame */
718 if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
719 hc->ep_is_in && hcd->core_if->dma_enable) {
720 qtd->complete_split = 0;
721 qtd->isoc_split_offset = 0;
726 DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
729 if (++qtd->isoc_frame_index == urb->packet_count) {
731 * urb->status is not used for isoc transfers.
732 * The individual frame_desc statuses are used instead.
734 hcd->fops->complete(hcd, urb->priv, urb, 0);
735 ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
737 ret_val = DWC_OTG_HC_XFER_COMPLETE;
743 * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
744 * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
745 * still linked to the QH, the QH is added to the end of the inactive
746 * non-periodic schedule. For periodic QHs, removes the QH from the periodic
747 * schedule if no more QTDs are linked to the QH.
749 static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
751 int continue_split = 0;
754 DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
756 qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
758 if (qtd->complete_split) {
760 } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
761 qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
766 dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
771 dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
775 * Releases a host channel for use by other transfers. Attempts to select and
776 * queue more transactions since at least one host channel is available.
778 * @param hcd The HCD state structure.
779 * @param hc The host channel to release.
780 * @param qtd The QTD associated with the host channel. This QTD may be freed
781 * if the transfer is complete or an error has occurred.
782 * @param halt_status Reason the channel is being released. This status
783 * determines the actions taken by this function.
785 static void release_channel(dwc_otg_hcd_t * hcd,
788 dwc_otg_halt_status_e halt_status)
790 dwc_otg_transaction_type_e tr_type;
793 DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d\n",
794 __func__, hc->hc_num, halt_status);
796 switch (halt_status) {
797 case DWC_OTG_HC_XFER_URB_COMPLETE:
800 case DWC_OTG_HC_XFER_AHB_ERR:
801 case DWC_OTG_HC_XFER_STALL:
802 case DWC_OTG_HC_XFER_BABBLE_ERR:
805 case DWC_OTG_HC_XFER_XACT_ERR:
806 if (qtd->error_count >= 3) {
807 DWC_DEBUGPL(DBG_HCDV,
808 " Complete URB with transaction error\n");
810 qtd->urb->status = -DWC_E_PROTOCOL;
811 hcd->fops->complete(hcd, qtd->urb->priv,
812 qtd->urb, -DWC_E_PROTOCOL);
817 case DWC_OTG_HC_XFER_URB_DEQUEUE:
819 * The QTD has already been removed and the QH has been
820 * deactivated. Don't want to do anything except release the
821 * host channel and try to queue more transfers.
824 case DWC_OTG_HC_XFER_NO_HALT_STATUS:
827 case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
828 DWC_DEBUGPL(DBG_HCDV,
829 " Complete URB with I/O error\n");
831 qtd->urb->status = -DWC_E_IO;
832 hcd->fops->complete(hcd, qtd->urb->priv,
833 qtd->urb, -DWC_E_IO);
840 deactivate_qh(hcd, hc->qh, free_qtd);
844 * Release the host channel for use by other transfers. The cleanup
845 * function clears the channel interrupt enables and conditions, so
846 * there's no need to clear the Channel Halted interrupt separately.
848 dwc_otg_hc_cleanup(hcd->core_if, hc);
849 DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
851 switch (hc->ep_type) {
852 case DWC_OTG_EP_TYPE_CONTROL:
853 case DWC_OTG_EP_TYPE_BULK:
854 hcd->non_periodic_channels--;
859 * Don't release reservations for periodic channels here.
860 * That's done when a periodic transfer is descheduled (i.e.
861 * when the QH is removed from the periodic schedule).
866 /* Try to queue more transfers now that there's a free channel. */
867 tr_type = dwc_otg_hcd_select_transactions(hcd);
868 if (tr_type != DWC_OTG_TRANSACTION_NONE) {
869 dwc_otg_hcd_queue_transactions(hcd, tr_type);
874 * Halts a host channel. If the channel cannot be halted immediately because
875 * the request queue is full, this function ensures that the FIFO empty
876 * interrupt for the appropriate queue is enabled so that the halt request can
877 * be queued when there is space in the request queue.
879 * This function may also be called in DMA mode. In that case, the channel is
880 * simply released since the core always halts the channel automatically in
883 static void halt_channel(dwc_otg_hcd_t * hcd,
885 dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
887 if (hcd->core_if->dma_enable) {
888 release_channel(hcd, hc, qtd, halt_status);
892 /* Slave mode processing... */
893 dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
895 if (hc->halt_on_queue) {
896 gintmsk_data_t gintmsk = {.d32 = 0 };
897 dwc_otg_core_global_regs_t *global_regs;
898 global_regs = hcd->core_if->core_global_regs;
900 if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
901 hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
903 * Make sure the Non-periodic Tx FIFO empty interrupt
904 * is enabled so that the non-periodic schedule will
907 gintmsk.b.nptxfempty = 1;
908 DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
911 * Move the QH from the periodic queued schedule to
912 * the periodic assigned schedule. This allows the
913 * halt to be queued when the periodic schedule is
916 DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
917 &hc->qh->qh_list_entry);
920 * Make sure the Periodic Tx FIFO Empty interrupt is
921 * enabled so that the periodic schedule will be
924 gintmsk.b.ptxfempty = 1;
925 DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
931 * Performs common cleanup for non-periodic transfers after a Transfer
932 * Complete interrupt. This function should be called after any endpoint type
933 * specific handling is finished to release the host channel.
935 static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
937 dwc_otg_hc_regs_t * hc_regs,
939 dwc_otg_halt_status_e halt_status)
943 qtd->error_count = 0;
945 hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
948 * Got a NYET on the last transaction of the transfer. This
949 * means that the endpoint should be in the PING state at the
950 * beginning of the next transfer.
952 hc->qh->ping_state = 1;
953 clear_hc_int(hc_regs, nyet);
957 * Always halt and release the host channel to make it available for
958 * more transfers. There may still be more phases for a control
959 * transfer or more data packets for a bulk transfer at this point,
960 * but the host channel is still halted. A channel will be reassigned
961 * to the transfer when the non-periodic schedule is processed after
962 * the channel is released. This allows transactions to be queued
963 * properly via dwc_otg_hcd_queue_transactions, which also enables the
964 * Tx FIFO Empty interrupt if necessary.
968 * IN transfers in Slave mode require an explicit disable to
969 * halt the channel. (In DMA mode, this call simply releases
972 halt_channel(hcd, hc, qtd, halt_status);
975 * The channel is automatically disabled by the core for OUT
976 * transfers in Slave mode.
978 release_channel(hcd, hc, qtd, halt_status);
983 * Performs common cleanup for periodic transfers after a Transfer Complete
984 * interrupt. This function should be called after any endpoint type specific
985 * handling is finished to release the host channel.
987 static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
989 dwc_otg_hc_regs_t * hc_regs,
991 dwc_otg_halt_status_e halt_status)
993 hctsiz_data_t hctsiz;
994 qtd->error_count = 0;
996 hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
997 if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
998 /* Core halts channel in these cases. */
999 release_channel(hcd, hc, qtd, halt_status);
1001 /* Flush any outstanding requests from the Tx queue. */
1002 halt_channel(hcd, hc, qtd, halt_status);
1006 static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
1008 dwc_otg_hc_regs_t * hc_regs,
1009 dwc_otg_qtd_t * qtd)
1012 struct dwc_otg_hcd_iso_packet_desc *frame_desc;
1013 frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
1015 len = get_actual_xfer_length(hc, hc_regs, qtd,
1016 DWC_OTG_HC_XFER_COMPLETE, NULL);
1019 qtd->complete_split = 0;
1020 qtd->isoc_split_offset = 0;
1023 frame_desc->actual_length += len;
1025 if (hc->align_buff && len)
1026 dwc_memcpy(qtd->urb->buf + frame_desc->offset +
1027 qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
1028 qtd->isoc_split_offset += len;
1030 if (frame_desc->length == frame_desc->actual_length) {
1031 frame_desc->status = 0;
1032 qtd->isoc_frame_index++;
1033 qtd->complete_split = 0;
1034 qtd->isoc_split_offset = 0;
1037 if (qtd->isoc_frame_index == qtd->urb->packet_count) {
1038 hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
1039 release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
1041 release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
1044 return 1; /* Indicates that channel released */
1048 * Handles a host channel Transfer Complete interrupt. This handler may be
1049 * called in either DMA mode or Slave mode.
1051 static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
1053 dwc_otg_hc_regs_t * hc_regs,
1054 dwc_otg_qtd_t * qtd)
1057 dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
1058 dwc_otg_hcd_urb_t *urb = qtd->urb;
1059 int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
1061 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
1062 "Transfer Complete--\n", hc->hc_num);
1064 if (hcd->core_if->dma_desc_enable) {
1065 dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
1066 if (pipe_type == UE_ISOCHRONOUS) {
1067 /* Do not disable the interrupt, just clear it */
1068 clear_hc_int(hc_regs, xfercomp);
1071 goto handle_xfercomp_done;
1075 * Handle xfer complete on CSPLIT.
1078 if (hc->qh->do_split) {
1079 if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
1080 && hcd->core_if->dma_enable) {
1081 if (qtd->complete_split
1082 && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
1084 goto handle_xfercomp_done;
1086 qtd->complete_split = 0;
1090 /* Update the QTD and URB states. */
1091 switch (pipe_type) {
1093 switch (qtd->control_phase) {
1094 case DWC_OTG_CONTROL_SETUP:
1095 if (urb->length > 0) {
1096 qtd->control_phase = DWC_OTG_CONTROL_DATA;
1098 qtd->control_phase = DWC_OTG_CONTROL_STATUS;
1100 DWC_DEBUGPL(DBG_HCDV,
1101 " Control setup transaction done\n");
1102 halt_status = DWC_OTG_HC_XFER_COMPLETE;
1104 case DWC_OTG_CONTROL_DATA:{
1106 update_urb_state_xfer_comp(hc, hc_regs, urb,
1108 if (urb_xfer_done) {
1109 qtd->control_phase =
1110 DWC_OTG_CONTROL_STATUS;
1111 DWC_DEBUGPL(DBG_HCDV,
1112 " Control data transfer done\n");
1114 dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
1116 halt_status = DWC_OTG_HC_XFER_COMPLETE;
1119 case DWC_OTG_CONTROL_STATUS:
1120 DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
1121 if (urb->status == -DWC_E_IN_PROGRESS) {
1124 hcd->fops->complete(hcd, urb->priv, urb, urb->status);
1125 halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
1129 complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
1132 DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
1134 update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
1135 if (urb_xfer_done) {
1136 hcd->fops->complete(hcd, urb->priv, urb, urb->status);
1137 halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
1139 halt_status = DWC_OTG_HC_XFER_COMPLETE;
1142 dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
1143 complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
1146 DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
1148 update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
1151 * Interrupt URB is done on the first transfer complete
1154 if (urb_xfer_done) {
1155 hcd->fops->complete(hcd, urb->priv, urb, urb->status);
1156 halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
1158 halt_status = DWC_OTG_HC_XFER_COMPLETE;
1161 dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
1162 complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
1164 case UE_ISOCHRONOUS:
1165 DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
1166 if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
1168 update_isoc_urb_state(hcd, hc, hc_regs, qtd,
1169 DWC_OTG_HC_XFER_COMPLETE);
1171 complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
1175 handle_xfercomp_done:
1176 disable_hc_int(hc_regs, xfercompl);
1182 * Handles a host channel STALL interrupt. This handler may be called in
1183 * either DMA mode or Slave mode.
1185 static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
1187 dwc_otg_hc_regs_t * hc_regs,
1188 dwc_otg_qtd_t * qtd)
1190 dwc_otg_hcd_urb_t *urb = qtd->urb;
1191 int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
1193 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
1194 "STALL Received--\n", hc->hc_num);
1196 if (hcd->core_if->dma_desc_enable) {
1197 dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
1198 goto handle_stall_done;
1201 if (pipe_type == UE_CONTROL) {
1202 hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
1205 if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
1206 hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
1208 * USB protocol requires resetting the data toggle for bulk
1209 * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
1210 * setup command is issued to the endpoint. Anticipate the
1211 * CLEAR_FEATURE command since a STALL has occurred and reset
1212 * the data toggle now.
1214 hc->qh->data_toggle = 0;
1217 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
1220 disable_hc_int(hc_regs, stall);
1226 * Updates the state of the URB when a transfer has been stopped due to an
1227 * abnormal condition before the transfer completes. Modifies the
1228 * actual_length field of the URB to reflect the number of bytes that have
1229 * actually been transferred via the host channel.
1231 static void update_urb_state_xfer_intr(dwc_hc_t * hc,
1232 dwc_otg_hc_regs_t * hc_regs,
1233 dwc_otg_hcd_urb_t * urb,
1234 dwc_otg_qtd_t * qtd,
1235 dwc_otg_halt_status_e halt_status)
1237 uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
1239 /* non DWORD-aligned buffer case handling. */
1240 if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
1241 dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
1245 urb->actual_length += bytes_transferred;
1249 hctsiz_data_t hctsiz;
1250 hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
1251 DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
1252 __func__, (hc->ep_is_in ? "IN" : "OUT"),
1254 DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
1255 hc->start_pkt_count);
1256 DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
1257 DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
1258 DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
1260 DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
1261 urb->actual_length);
1262 DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
1269 * Handles a host channel NAK interrupt. This handler may be called in either
1270 * DMA mode or Slave mode.
1272 static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
1274 dwc_otg_hc_regs_t * hc_regs,
1275 dwc_otg_qtd_t * qtd)
1277 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
1278 "NAK Received--\n", hc->hc_num);
1281 * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
1282 * interrupt. Re-start the SSPLIT transfer.
1285 if (hc->complete_split) {
1286 qtd->error_count = 0;
1288 qtd->complete_split = 0;
1289 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
1290 goto handle_nak_done;
1293 switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
1296 if (hcd->core_if->dma_enable && hc->ep_is_in) {
1298 * NAK interrupts are enabled on bulk/control IN
1299 * transfers in DMA mode for the sole purpose of
1300 * resetting the error count after a transaction error
1301 * occurs. The core will continue transferring data.
1302 * Disable other interrupts unmasked for the same
1305 disable_hc_int(hc_regs, datatglerr);
1306 disable_hc_int(hc_regs, ack);
1307 qtd->error_count = 0;
1308 goto handle_nak_done;
1312 * NAK interrupts normally occur during OUT transfers in DMA
1313 * or Slave mode. For IN transfers, more requests will be
1314 * queued as request queue space is available.
1316 qtd->error_count = 0;
1318 if (!hc->qh->ping_state) {
1319 update_urb_state_xfer_intr(hc, hc_regs,
1321 DWC_OTG_HC_XFER_NAK);
1322 dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
1324 if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
1325 hc->qh->ping_state = 1;
1329 * Halt the channel so the transfer can be re-started from
1330 * the appropriate point or the PING protocol will
1333 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
1336 qtd->error_count = 0;
1337 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
1339 case UE_ISOCHRONOUS:
1340 /* Should never get called for isochronous transfers. */
1341 DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
1346 disable_hc_int(hc_regs, nak);
1352 * Handles a host channel ACK interrupt. This interrupt is enabled when
1353 * performing the PING protocol in Slave mode, when errors occur during
1354 * either Slave mode or DMA mode, and during Start Split transactions.
1356 static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
1358 dwc_otg_hc_regs_t * hc_regs,
1359 dwc_otg_qtd_t * qtd)
1361 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
1362 "ACK Received--\n", hc->hc_num);
1366 * Handle ACK on SSPLIT.
1367 * ACK should not occur in CSPLIT.
1369 if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
1370 qtd->ssplit_out_xfer_count = hc->xfer_len;
1372 if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
1373 /* Don't need complete for isochronous out transfers. */
1374 qtd->complete_split = 1;
1378 if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
1379 switch (hc->xact_pos) {
1380 case DWC_HCSPLIT_XACTPOS_ALL:
1382 case DWC_HCSPLIT_XACTPOS_END:
1383 qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
1384 qtd->isoc_split_offset = 0;
1386 case DWC_HCSPLIT_XACTPOS_BEGIN:
1387 case DWC_HCSPLIT_XACTPOS_MID:
1389 * For BEGIN or MID, calculate the length for
1390 * the next microframe to determine the correct
1391 * SSPLIT token, either MID or END.
1394 struct dwc_otg_hcd_iso_packet_desc
1399 iso_descs[qtd->isoc_frame_index];
1400 qtd->isoc_split_offset += 188;
1402 if ((frame_desc->length -
1403 qtd->isoc_split_offset) <= 188) {
1404 qtd->isoc_split_pos =
1405 DWC_HCSPLIT_XACTPOS_END;
1407 qtd->isoc_split_pos =
1408 DWC_HCSPLIT_XACTPOS_MID;
1415 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
1419 * An unmasked ACK on a non-split DMA transaction is
1420 * for the sole purpose of resetting error counts. Disable other
1421 * interrupts unmasked for the same reason.
1423 if(hcd->core_if->dma_enable) {
1424 disable_hc_int(hc_regs, datatglerr);
1425 disable_hc_int(hc_regs, nak);
1427 qtd->error_count = 0;
1429 if (hc->qh->ping_state) {
1430 hc->qh->ping_state = 0;
1432 * Halt the channel so the transfer can be re-started
1433 * from the appropriate point. This only happens in
1434 * Slave mode. In DMA mode, the ping_state is cleared
1435 * when the transfer is started because the core
1436 * automatically executes the PING, then the transfer.
1438 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
1443 * If the ACK occurred when _not_ in the PING state, let the channel
1444 * continue transferring data after clearing the error count.
1447 disable_hc_int(hc_regs, ack);
1453 * Handles a host channel NYET interrupt. This interrupt should only occur on
1454 * Bulk and Control OUT endpoints and for complete split transactions. If a
1455 * NYET occurs at the same time as a Transfer Complete interrupt, it is
1456 * handled in the xfercomp interrupt handler, not here. This handler may be
1457 * called in either DMA mode or Slave mode.
1459 static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
1461 dwc_otg_hc_regs_t * hc_regs,
1462 dwc_otg_qtd_t * qtd)
1464 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
1465 "NYET Received--\n", hc->hc_num);
1469 * re-do the CSPLIT immediately on non-periodic
1471 if (hc->do_split && hc->complete_split) {
1472 if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
1473 && hcd->core_if->dma_enable) {
1474 qtd->complete_split = 0;
1475 qtd->isoc_split_offset = 0;
1476 if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
1477 hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
1478 release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
1481 release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
1482 goto handle_nyet_done;
1485 if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
1486 hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
1487 int frnum = dwc_otg_hcd_get_frame_number(hcd);
1489 if (dwc_full_frame_num(frnum) !=
1490 dwc_full_frame_num(hc->qh->sched_frame)) {
1492 * No longer in the same full speed frame.
1493 * Treat this as a transaction error.
1496 /** @todo Fix system performance so this can
1497 * be treated as an error. Right now complete
1498 * splits cannot be scheduled precisely enough
1499 * due to other system activity, so this error
1500 * occurs regularly in Slave mode.
1504 qtd->complete_split = 0;
1505 halt_channel(hcd, hc, qtd,
1506 DWC_OTG_HC_XFER_XACT_ERR);
1507 /** @todo add support for isoc release */
1508 goto handle_nyet_done;
1512 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
1513 goto handle_nyet_done;
1516 hc->qh->ping_state = 1;
1517 qtd->error_count = 0;
1519 update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
1520 DWC_OTG_HC_XFER_NYET);
1521 dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
1524 * Halt the channel and re-start the transfer so the PING
1525 * protocol will start.
1527 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
1530 disable_hc_int(hc_regs, nyet);
1535 * Handles a host channel babble interrupt. This handler may be called in
1536 * either DMA mode or Slave mode.
1538 static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
1540 dwc_otg_hc_regs_t * hc_regs,
1541 dwc_otg_qtd_t * qtd)
1543 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
1544 "Babble Error--\n", hc->hc_num);
1546 if (hcd->core_if->dma_desc_enable) {
1547 dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
1548 DWC_OTG_HC_XFER_BABBLE_ERR);
1549 goto handle_babble_done;
1552 if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
1553 hcd->fops->complete(hcd, qtd->urb->priv,
1554 qtd->urb, -DWC_E_OVERFLOW);
1555 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
1557 dwc_otg_halt_status_e halt_status;
1558 halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
1559 DWC_OTG_HC_XFER_BABBLE_ERR);
1560 halt_channel(hcd, hc, qtd, halt_status);
1564 disable_hc_int(hc_regs, bblerr);
1569 * Handles a host channel AHB error interrupt. This handler is only called in
1572 static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
1574 dwc_otg_hc_regs_t * hc_regs,
1575 dwc_otg_qtd_t * qtd)
1577 hcchar_data_t hcchar;
1578 hcsplt_data_t hcsplt;
1579 hctsiz_data_t hctsiz;
1581 char *pipetype, *speed;
1583 dwc_otg_hcd_urb_t *urb = qtd->urb;
1585 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
1586 "AHB Error--\n", hc->hc_num);
1588 hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
1589 hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
1590 hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
1591 hcdma = DWC_READ_REG32(&hc_regs->hcdma);
1593 DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
1594 DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
1595 DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
1596 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
1597 DWC_ERROR(" Device address: %d\n",
1598 dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
1599 DWC_ERROR(" Endpoint: %d, %s\n",
1600 dwc_otg_hcd_get_ep_num(&urb->pipe_info),
1601 (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
1603 switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
1605 pipetype = "CONTROL";
1611 pipetype = "INTERRUPT";
1613 case UE_ISOCHRONOUS:
1614 pipetype = "ISOCHRONOUS";
1617 pipetype = "UNKNOWN";
1621 DWC_ERROR(" Endpoint type: %s\n", pipetype);
1623 switch (hc->speed) {
1624 case DWC_OTG_EP_SPEED_HIGH:
1627 case DWC_OTG_EP_SPEED_FULL:
1630 case DWC_OTG_EP_SPEED_LOW:
1638 DWC_ERROR(" Speed: %s\n", speed);
1640 DWC_ERROR(" Max packet size: %d\n",
1641 dwc_otg_hcd_get_mps(&urb->pipe_info));
1642 DWC_ERROR(" Data buffer length: %d\n", urb->length);
1643 DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
1644 urb->buf, (void *)urb->dma);
1645 DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
1646 urb->setup_packet, (void *)urb->setup_dma);
1647 DWC_ERROR(" Interval: %d\n", urb->interval);
1649 /* Core haltes the channel for Descriptor DMA mode */
1650 if (hcd->core_if->dma_desc_enable) {
1651 dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
1652 DWC_OTG_HC_XFER_AHB_ERR);
1653 goto handle_ahberr_done;
1656 hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
1659 * Force a channel halt. Don't call halt_channel because that won't
1660 * write to the HCCHARn register in DMA mode to force the halt.
1662 dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
1664 disable_hc_int(hc_regs, ahberr);
1669 * Handles a host channel transaction error interrupt. This handler may be
1670 * called in either DMA mode or Slave mode.
1672 static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
1674 dwc_otg_hc_regs_t * hc_regs,
1675 dwc_otg_qtd_t * qtd)
1677 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
1678 "Transaction Error--\n", hc->hc_num);
1680 if (hcd->core_if->dma_desc_enable) {
1681 dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
1682 DWC_OTG_HC_XFER_XACT_ERR);
1683 goto handle_xacterr_done;
1686 switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
1690 if (!hc->qh->ping_state) {
1692 update_urb_state_xfer_intr(hc, hc_regs,
1694 DWC_OTG_HC_XFER_XACT_ERR);
1695 dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
1696 if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
1697 hc->qh->ping_state = 1;
1702 * Halt the channel so the transfer can be re-started from
1703 * the appropriate point or the PING protocol will start.
1705 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
1709 if (hc->do_split && hc->complete_split) {
1710 qtd->complete_split = 0;
1712 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
1714 case UE_ISOCHRONOUS:
1716 dwc_otg_halt_status_e halt_status;
1718 update_isoc_urb_state(hcd, hc, hc_regs, qtd,
1719 DWC_OTG_HC_XFER_XACT_ERR);
1721 halt_channel(hcd, hc, qtd, halt_status);
1725 handle_xacterr_done:
1726 disable_hc_int(hc_regs, xacterr);
1732 * Handles a host channel frame overrun interrupt. This handler may be called
1733 * in either DMA mode or Slave mode.
1735 static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
1737 dwc_otg_hc_regs_t * hc_regs,
1738 dwc_otg_qtd_t * qtd)
1740 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
1741 "Frame Overrun--\n", hc->hc_num);
1743 switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
1748 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
1750 case UE_ISOCHRONOUS:
1752 dwc_otg_halt_status_e halt_status;
1754 update_isoc_urb_state(hcd, hc, hc_regs, qtd,
1755 DWC_OTG_HC_XFER_FRAME_OVERRUN);
1757 halt_channel(hcd, hc, qtd, halt_status);
1762 disable_hc_int(hc_regs, frmovrun);
1768 * Handles a host channel data toggle error interrupt. This handler may be
1769 * called in either DMA mode or Slave mode.
1771 static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
1773 dwc_otg_hc_regs_t * hc_regs,
1774 dwc_otg_qtd_t * qtd)
1776 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
1777 "Data Toggle Error--\n", hc->hc_num);
1780 /* An unmasked data toggle error on a non-split DMA transaction is
1781 * for the sole purpose of resetting error counts. Disable other
1782 * interrupts unmasked for the same reason.
1784 if(hcd->core_if->dma_enable) {
1785 disable_hc_int(hc_regs, ack);
1786 disable_hc_int(hc_regs, nak);
1788 qtd->error_count = 0;
1790 DWC_ERROR("Data Toggle Error on OUT transfer,"
1791 "channel %d\n", hc->hc_num);
1794 disable_hc_int(hc_regs, datatglerr);
1801 * This function is for debug only. It checks that a valid halt status is set
1802 * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
1803 * taken and a warning is issued.
1804 * @return 1 if halt status is ok, 0 otherwise.
1806 static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
1808 dwc_otg_hc_regs_t * hc_regs,
1809 dwc_otg_qtd_t * qtd)
1811 hcchar_data_t hcchar;
1812 hctsiz_data_t hctsiz;
1814 hcintmsk_data_t hcintmsk;
1815 hcsplt_data_t hcsplt;
1817 if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
1819 * This code is here only as a check. This condition should
1820 * never happen. Ignore the halt if it does occur.
1822 hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
1823 hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
1824 hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
1825 hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
1826 hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
1828 ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
1829 "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
1830 "hcint 0x%08x, hcintmsk 0x%08x, "
1831 "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
1832 hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
1833 hcintmsk.d32, hcsplt.d32, qtd->complete_split);
1835 DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
1836 __func__, hc->hc_num);
1838 clear_hc_int(hc_regs, chhltd);
1843 * This code is here only as a check. hcchar.chdis should
1844 * never be set when the halt interrupt occurs. Halt the
1845 * channel again if it does occur.
1847 hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
1848 if (hcchar.b.chdis) {
1849 DWC_WARN("%s: hcchar.chdis set unexpectedly, "
1850 "hcchar 0x%08x, trying to halt again\n",
1851 __func__, hcchar.d32);
1852 clear_hc_int(hc_regs, chhltd);
1853 hc->halt_pending = 0;
1854 halt_channel(hcd, hc, qtd, hc->halt_status);
1863 * Handles a host Channel Halted interrupt in DMA mode. This handler
1864 * determines the reason the channel halted and proceeds accordingly.
1866 static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
1868 dwc_otg_hc_regs_t * hc_regs,
1869 dwc_otg_qtd_t * qtd)
1872 hcintmsk_data_t hcintmsk;
1873 int out_nak_enh = 0;
1875 /* For core with OUT NAK enhancement, the flow for high-
1876 * speed CONTROL/BULK OUT is handled a little differently.
1878 if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
1879 if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
1880 (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
1881 hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
1886 if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
1887 (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
1888 && !hcd->core_if->dma_desc_enable)) {
1890 * Just release the channel. A dequeue can happen on a
1891 * transfer timeout. In the case of an AHB Error, the channel
1892 * was forced to halt because there's no way to gracefully
1895 if (hcd->core_if->dma_desc_enable)
1896 dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
1899 release_channel(hcd, hc, qtd, hc->halt_status);
1903 /* Read the HCINTn register to determine the cause for the halt. */
1904 hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
1905 hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
1907 if (hcint.b.xfercomp) {
1908 /** @todo This is here because of a possible hardware bug. Spec
1909 * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
1910 * interrupt w/ACK bit set should occur, but I only see the
1911 * XFERCOMP bit, even with it masked out. This is a workaround
1912 * for that behavior. Should fix this when hardware is fixed.
1914 if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
1915 handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
1917 handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
1918 } else if (hcint.b.stall) {
1919 handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
1920 } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
1922 if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
1923 DWC_DEBUG("XactErr with NYET/NAK/ACK\n");
1924 qtd->error_count = 0;
1926 DWC_DEBUG("XactErr without NYET/NAK/ACK\n");
1931 * Must handle xacterr before nak or ack. Could get a xacterr
1932 * at the same time as either of these on a BULK/CONTROL OUT
1933 * that started with a PING. The xacterr takes precedence.
1935 handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
1936 } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
1937 handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
1938 } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
1939 handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
1940 } else if (hcint.b.bblerr) {
1941 handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
1942 } else if (hcint.b.frmovrun) {
1943 handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
1944 } else if (!out_nak_enh) {
1947 * Must handle nyet before nak or ack. Could get a nyet at the
1948 * same time as either of those on a BULK/CONTROL OUT that
1949 * started with a PING. The nyet takes precedence.
1951 handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
1952 } else if (hcint.b.nak && !hcintmsk.b.nak) {
1954 * If nak is not masked, it's because a non-split IN transfer
1955 * is in an error state. In that case, the nak is handled by
1956 * the nak interrupt handler, not here. Handle nak here for
1957 * BULK/CONTROL OUT transfers, which halt on a NAK to allow
1958 * rewinding the buffer pointer.
1960 handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
1961 } else if (hcint.b.ack && !hcintmsk.b.ack) {
1963 * If ack is not masked, it's because a non-split IN transfer
1964 * is in an error state. In that case, the ack is handled by
1965 * the ack interrupt handler, not here. Handle ack here for
1966 * split transfers. Start splits halt on ACK.
1968 handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
1970 if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
1971 hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
1973 * A periodic transfer halted with no other channel
1974 * interrupts set. Assume it was halted by the core
1975 * because it could not be completed in its scheduled
1980 ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
1981 __func__, hc->hc_num);
1986 ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
1987 "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
1988 __func__, hc->hc_num, hcint.d32,
1989 DWC_READ_REG32(&hcd->
1990 core_if->core_global_regs->
1997 DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
2004 * Even if the reason for landing here is unknown, handle
2005 * it like previously. Someone that understands how the
2006 * driver works should probably explain why this works
2009 clear_hc_int(hc_regs, chhltd);
2010 halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
2014 * Handles a host channel Channel Halted interrupt.
2016 * In slave mode, this handler is called only when the driver specifically
2017 * requests a halt. This occurs during handling other host channel interrupts
2018 * (e.g. nak, xacterr, stall, nyet, etc.).
2020 * In DMA mode, this is the interrupt that occurs when the core has finished
2021 * processing a transfer on a channel. Other host channel interrupts (except
2022 * ahberr) are disabled in DMA mode.
2024 static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
2026 dwc_otg_hc_regs_t * hc_regs,
2027 dwc_otg_qtd_t * qtd)
2029 DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
2030 "Channel Halted--\n", hc->hc_num);
2032 if (hcd->core_if->dma_enable) {
2033 handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
2036 if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
2040 release_channel(hcd, hc, qtd, hc->halt_status);
2046 /** Handles interrupt for a specific Host Channel */
2047 int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
2051 hcintmsk_data_t hcintmsk;
2053 dwc_otg_hc_regs_t *hc_regs;
2056 DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
2058 hc = dwc_otg_hcd->hc_ptr_array[num];
2059 hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
2060 if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
2061 /* We are responding to a channel disable. Driver
2062 * state is cleared - our qtd has gone away.
2064 release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
2067 qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
2069 hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
2070 hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
2071 DWC_DEBUGPL(DBG_HCDV,
2072 " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
2073 hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
2074 hcint.d32 = hcint.d32 & hcintmsk.d32;
2076 if (!dwc_otg_hcd->core_if->dma_enable) {
2077 if (hcint.b.chhltd && hcint.d32 != 0x2) {
2082 if (hcint.b.xfercomp) {
2084 handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2086 * If NYET occurred at same time as Xfer Complete, the NYET is
2087 * handled by the Xfer Complete interrupt handler. Don't want
2088 * to call the NYET interrupt handler in this case.
2092 if (hcint.b.chhltd) {
2093 retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2095 if (hcint.b.ahberr) {
2096 retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2098 if (hcint.b.stall) {
2099 retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2102 retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2105 if (!hcint.b.chhltd)
2106 retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2109 retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2111 if (hcint.b.xacterr) {
2112 retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2114 if (hcint.b.bblerr) {
2115 retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2117 if (hcint.b.frmovrun) {
2119 handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2121 if (hcint.b.datatglerr) {
2123 handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
2129 #endif /* DWC_DEVICE_ONLY */