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