Lines Matching refs:pep

75 			     struct cdns2_endpoint *pep)  in cdns2_get_dma_pos()  argument
79 dma_index = readl(&pdev->adma_regs->ep_traddr) - pep->ring.dma; in cdns2_get_dma_pos()
99 dma_addr_t cdns2_trb_virt_to_dma(struct cdns2_endpoint *pep, in cdns2_trb_virt_to_dma() argument
102 u32 offset = (char *)trb - (char *)pep->ring.trbs; in cdns2_trb_virt_to_dma()
104 return pep->ring.dma + offset; in cdns2_trb_virt_to_dma()
107 static void cdns2_free_tr_segment(struct cdns2_endpoint *pep) in cdns2_free_tr_segment() argument
109 struct cdns2_device *pdev = pep->pdev; in cdns2_free_tr_segment()
110 struct cdns2_ring *ring = &pep->ring; in cdns2_free_tr_segment()
112 if (pep->ring.trbs) { in cdns2_free_tr_segment()
119 static int cdns2_alloc_tr_segment(struct cdns2_endpoint *pep) in cdns2_alloc_tr_segment() argument
121 struct cdns2_device *pdev = pep->pdev; in cdns2_alloc_tr_segment()
125 ring = &pep->ring; in cdns2_alloc_tr_segment()
137 if (!pep->num) in cdns2_alloc_tr_segment()
153 static void cdns2_ep_stall_flush(struct cdns2_endpoint *pep) in cdns2_ep_stall_flush() argument
155 struct cdns2_device *pdev = pep->pdev; in cdns2_ep_stall_flush()
158 trace_cdns2_ep_halt(pep, 1, 1); in cdns2_ep_stall_flush()
165 pep->ep_state |= EP_STALLED; in cdns2_ep_stall_flush()
166 pep->ep_state &= ~EP_STALL_PENDING; in cdns2_ep_stall_flush()
227 static struct cdns2_trb *cdns2_next_trb(struct cdns2_endpoint *pep, in cdns2_next_trb() argument
230 if (trb == (pep->ring.trbs + (TRBS_PER_SEGMENT - 1))) in cdns2_next_trb()
231 return pep->ring.trbs; in cdns2_next_trb()
236 void cdns2_gadget_giveback(struct cdns2_endpoint *pep, in cdns2_gadget_giveback() argument
241 struct cdns2_device *pdev = pep->pdev; in cdns2_gadget_giveback()
248 usb_gadget_unmap_request_by_dev(pdev->dev, request, pep->dir); in cdns2_gadget_giveback()
257 usb_gadget_giveback_request(&pep->endpoint, request); in cdns2_gadget_giveback()
262 cdns2_gadget_ep_free_request(&pep->endpoint, request); in cdns2_gadget_giveback()
265 static void cdns2_wa1_restore_cycle_bit(struct cdns2_endpoint *pep) in cdns2_wa1_restore_cycle_bit() argument
268 if (pep->wa1_set) { in cdns2_wa1_restore_cycle_bit()
269 trace_cdns2_wa1(pep, "restore cycle bit"); in cdns2_wa1_restore_cycle_bit()
271 pep->wa1_set = 0; in cdns2_wa1_restore_cycle_bit()
272 pep->wa1_trb_index = 0xFFFF; in cdns2_wa1_restore_cycle_bit()
273 if (pep->wa1_cycle_bit) in cdns2_wa1_restore_cycle_bit()
274 pep->wa1_trb->control |= cpu_to_le32(0x1); in cdns2_wa1_restore_cycle_bit()
276 pep->wa1_trb->control &= cpu_to_le32(~0x1); in cdns2_wa1_restore_cycle_bit()
280 static int cdns2_wa1_update_guard(struct cdns2_endpoint *pep, in cdns2_wa1_update_guard() argument
283 struct cdns2_device *pdev = pep->pdev; in cdns2_wa1_update_guard()
285 if (!pep->wa1_set) { in cdns2_wa1_update_guard()
291 pep->wa1_cycle_bit = pep->ring.pcs ? TRB_CYCLE : 0; in cdns2_wa1_update_guard()
292 pep->wa1_set = 1; in cdns2_wa1_update_guard()
293 pep->wa1_trb = trb; in cdns2_wa1_update_guard()
294 pep->wa1_trb_index = pep->ring.enqueue; in cdns2_wa1_update_guard()
295 trace_cdns2_wa1(pep, "set guard"); in cdns2_wa1_update_guard()
303 struct cdns2_endpoint *pep) in cdns2_wa1_tray_restore_cycle_bit() argument
309 dma_index = cdns2_get_dma_pos(pdev, pep); in cdns2_wa1_tray_restore_cycle_bit()
311 if (!doorbell || dma_index != pep->wa1_trb_index) in cdns2_wa1_tray_restore_cycle_bit()
312 cdns2_wa1_restore_cycle_bit(pep); in cdns2_wa1_tray_restore_cycle_bit()
316 struct cdns2_endpoint *pep, in cdns2_prepare_ring() argument
324 ring = &pep->ring; in cdns2_prepare_ring()
327 pep->ep_state |= EP_RING_FULL; in cdns2_prepare_ring()
334 dma_index = cdns2_get_dma_pos(pdev, pep); in cdns2_prepare_ring()
338 pep->ep_state |= EP_DEFERRED_DRDY; in cdns2_prepare_ring()
353 if (pep->type == USB_ENDPOINT_XFER_ISOC || TRBS_PER_SEGMENT > 2) in cdns2_prepare_ring()
363 static void cdns2_dbg_request_trbs(struct cdns2_endpoint *pep, in cdns2_dbg_request_trbs() argument
366 struct cdns2_trb *link_trb = pep->ring.trbs + (TRBS_PER_SEGMENT - 1); in cdns2_dbg_request_trbs()
372 trace_cdns2_queue_trb(pep, trb + i); in cdns2_dbg_request_trbs()
374 trb = pep->ring.trbs; in cdns2_dbg_request_trbs()
383 static unsigned int cdns2_count_trbs(struct cdns2_endpoint *pep, in cdns2_count_trbs() argument
388 if (pep->type == USB_ENDPOINT_XFER_ISOC) { in cdns2_count_trbs()
398 if (pep->interval > 1) in cdns2_count_trbs()
399 num_trbs = pep->dir ? num_trbs * pep->interval : 1; in cdns2_count_trbs()
400 } else if (pep->dir) { in cdns2_count_trbs()
412 static unsigned int cdns2_count_sg_trbs(struct cdns2_endpoint *pep, in cdns2_count_sg_trbs() argument
423 num_trbs += cdns2_count_trbs(pep, sg_dma_address(sg), len); in cdns2_count_sg_trbs()
435 if (pep->type == USB_ENDPOINT_XFER_ISOC) { in cdns2_count_sg_trbs()
498 static void cdns2_ep_tx_isoc(struct cdns2_endpoint *pep, in cdns2_ep_tx_isoc() argument
523 num_tds = pep->dir ? pep->interval : 1; in cdns2_ep_tx_isoc()
564 if (enqd_len + trb_buff_len >= full_len || !pep->dir) in cdns2_ep_tx_isoc()
574 if (pep->ring.pcs == 0) in cdns2_ep_tx_isoc()
577 control |= pep->ring.pcs; in cdns2_ep_tx_isoc()
584 TRB_BURST(pep->pdev->burst_opt[trb_buff_len]); in cdns2_ep_tx_isoc()
586 trb = pep->ring.trbs + pep->ring.enqueue; in cdns2_ep_tx_isoc()
607 preq->end_trb = pep->ring.enqueue; in cdns2_ep_tx_isoc()
609 cdns2_ep_inc_enq(&pep->ring); in cdns2_ep_tx_isoc()
614 static void cdns2_ep_tx_bulk(struct cdns2_endpoint *pep, in cdns2_ep_tx_bulk() argument
635 ring = &pep->ring; in cdns2_ep_tx_bulk()
639 trb = pep->ring.trbs + ring->enqueue; in cdns2_ep_tx_bulk()
641 if (pep->dir && sg_iter == trbs_per_td - 1) { in cdns2_ep_tx_bulk()
645 cdns2_ep_inc_enq(&pep->ring); in cdns2_ep_tx_bulk()
651 trb->buffer = cpu_to_le32(pep->ring.dma + in cdns2_ep_tx_bulk()
667 if (sg_iter == (trbs_per_td - (pep->dir ? 2 : 1))) in cdns2_ep_tx_bulk()
673 trb->length = cpu_to_le32(TRB_BURST(pep->trb_burst_size) | in cdns2_ep_tx_bulk()
684 cdns2_ep_inc_enq(&pep->ring); in cdns2_ep_tx_bulk()
689 struct cdns2_endpoint *pep) in cdns2_set_drdy() argument
691 trace_cdns2_ring(pep); in cdns2_set_drdy()
708 trace_cdns2_doorbell_epx(pep, readl(&pdev->adma_regs->ep_traddr)); in cdns2_set_drdy()
712 struct cdns2_endpoint *pep) in cdns2_prepare_first_isoc_transfer() argument
721 if (!pep->dir) { in cdns2_prepare_first_isoc_transfer()
723 writel(pep->ring.dma + pep->ring.dequeue, in cdns2_prepare_first_isoc_transfer()
732 buffer = pep->ring.dma + pep->ring.dequeue * TRB_SIZE; in cdns2_prepare_first_isoc_transfer()
735 trb = &pep->ring.trbs[TRBS_PER_SEGMENT]; in cdns2_prepare_first_isoc_transfer()
750 if (hw_ccs != pep->ring.ccs) in cdns2_prepare_first_isoc_transfer()
754 writel(pep->ring.dma + (TRBS_PER_SEGMENT * TRB_SIZE), in cdns2_prepare_first_isoc_transfer()
761 static int cdns2_ep_run_transfer(struct cdns2_endpoint *pep, in cdns2_ep_run_transfer() argument
764 struct cdns2_device *pdev = pep->pdev; in cdns2_ep_run_transfer()
770 cdns2_select_ep(pdev, pep->endpoint.address); in cdns2_ep_run_transfer()
773 num_trbs = cdns2_count_sg_trbs(pep, &preq->request); in cdns2_ep_run_transfer()
775 num_trbs = cdns2_count_trbs(pep, preq->request.dma, in cdns2_ep_run_transfer()
778 ret = cdns2_prepare_ring(pdev, pep, num_trbs); in cdns2_ep_run_transfer()
782 ring = &pep->ring; in cdns2_ep_run_transfer()
786 if (usb_endpoint_xfer_isoc(pep->endpoint.desc)) { in cdns2_ep_run_transfer()
787 cdns2_ep_tx_isoc(pep, preq, num_trbs); in cdns2_ep_run_transfer()
789 togle_pcs = cdns2_wa1_update_guard(pep, ring->trbs + ring->enqueue); in cdns2_ep_run_transfer()
790 cdns2_ep_tx_bulk(pep, preq, num_trbs); in cdns2_ep_run_transfer()
804 cdns2_wa1_tray_restore_cycle_bit(pdev, pep); in cdns2_ep_run_transfer()
805 cdns2_dbg_request_trbs(pep, preq); in cdns2_ep_run_transfer()
807 if (!pep->wa1_set && !(pep->ep_state & EP_STALLED) && !pep->skip) { in cdns2_ep_run_transfer()
808 if (pep->type == USB_ENDPOINT_XFER_ISOC) { in cdns2_ep_run_transfer()
809 ret = cdns2_prepare_first_isoc_transfer(pdev, pep); in cdns2_ep_run_transfer()
814 cdns2_set_drdy(pdev, pep); in cdns2_ep_run_transfer()
822 struct cdns2_endpoint *pep) in cdns2_start_all_request() argument
827 while (!list_empty(&pep->deferred_list)) { in cdns2_start_all_request()
828 preq = cdns2_next_preq(&pep->deferred_list); in cdns2_start_all_request()
830 ret = cdns2_ep_run_transfer(pep, preq); in cdns2_start_all_request()
834 list_move_tail(&preq->list, &pep->pending_list); in cdns2_start_all_request()
837 pep->ep_state &= ~EP_RING_FULL; in cdns2_start_all_request()
878 static bool cdns2_trb_handled(struct cdns2_endpoint *pep, in cdns2_trb_handled() argument
881 struct cdns2_device *pdev = pep->pdev; in cdns2_trb_handled()
888 ring = &pep->ring; in cdns2_trb_handled()
889 current_index = cdns2_get_dma_pos(pdev, pep); in cdns2_trb_handled()
925 if (TRBS_PER_SEGMENT == 2 && pep->type != USB_ENDPOINT_XFER_ISOC) { in cdns2_trb_handled()
950 struct cdns2_endpoint *pep, in cdns2_skip_isoc_td() argument
956 trb = pep->ring.trbs + pep->ring.dequeue; in cdns2_skip_isoc_td()
960 trace_cdns2_complete_trb(pep, trb); in cdns2_skip_isoc_td()
961 cdns2_ep_inc_deq(&pep->ring); in cdns2_skip_isoc_td()
962 trb = cdns2_next_trb(pep, trb); in cdns2_skip_isoc_td()
965 cdns2_gadget_giveback(pep, preq, 0); in cdns2_skip_isoc_td()
966 cdns2_prepare_first_isoc_transfer(pdev, pep); in cdns2_skip_isoc_td()
967 pep->skip = false; in cdns2_skip_isoc_td()
968 cdns2_set_drdy(pdev, pep); in cdns2_skip_isoc_td()
972 struct cdns2_endpoint *pep) in cdns2_transfer_completed() argument
978 while (!list_empty(&pep->pending_list)) { in cdns2_transfer_completed()
979 preq = cdns2_next_preq(&pep->pending_list); in cdns2_transfer_completed()
980 trb = pep->ring.trbs + pep->ring.dequeue; in cdns2_transfer_completed()
988 trace_cdns2_complete_trb(pep, trb); in cdns2_transfer_completed()
989 cdns2_ep_inc_deq(&pep->ring); in cdns2_transfer_completed()
990 trb = pep->ring.trbs + pep->ring.dequeue; in cdns2_transfer_completed()
997 cdns2_select_ep(pdev, pep->endpoint.address); in cdns2_transfer_completed()
999 while (cdns2_trb_handled(pep, preq)) { in cdns2_transfer_completed()
1005 trb = pep->ring.trbs + pep->ring.dequeue; in cdns2_transfer_completed()
1006 trace_cdns2_complete_trb(pep, trb); in cdns2_transfer_completed()
1008 if (pep->dir && pep->type == USB_ENDPOINT_XFER_ISOC) in cdns2_transfer_completed()
1018 cdns2_ep_inc_deq(&pep->ring); in cdns2_transfer_completed()
1022 cdns2_gadget_giveback(pep, preq, 0); in cdns2_transfer_completed()
1028 if (pep->type != USB_ENDPOINT_XFER_ISOC && in cdns2_transfer_completed()
1034 if (pep->skip && preq) in cdns2_transfer_completed()
1035 cdns2_skip_isoc_td(pdev, pep, preq); in cdns2_transfer_completed()
1037 if (!(pep->ep_state & EP_STALLED) && in cdns2_transfer_completed()
1038 !(pep->ep_state & EP_STALL_PENDING)) in cdns2_transfer_completed()
1039 cdns2_start_all_request(pdev, pep); in cdns2_transfer_completed()
1051 static void cdns2_rearm_transfer(struct cdns2_endpoint *pep, u8 rearm) in cdns2_rearm_transfer() argument
1053 struct cdns2_device *pdev = pep->pdev; in cdns2_rearm_transfer()
1055 cdns2_wa1_restore_cycle_bit(pep); in cdns2_rearm_transfer()
1058 trace_cdns2_ring(pep); in cdns2_rearm_transfer()
1067 trace_cdns2_doorbell_epx(pep, in cdns2_rearm_transfer()
1072 static void cdns2_handle_epx_interrupt(struct cdns2_endpoint *pep) in cdns2_handle_epx_interrupt() argument
1074 struct cdns2_device *pdev = pep->pdev; in cdns2_handle_epx_interrupt()
1079 cdns2_select_ep(pdev, pep->endpoint.address); in cdns2_handle_epx_interrupt()
1081 trace_cdns2_epx_irq(pdev, pep); in cdns2_handle_epx_interrupt()
1086 if (pep->type == USB_ENDPOINT_XFER_ISOC) { in cdns2_handle_epx_interrupt()
1090 mult = USB_EP_MAXP_MULT(pep->endpoint.desc->wMaxPacketSize); in cdns2_handle_epx_interrupt()
1091 cs = pep->dir ? readb(&pdev->epx_regs->ep[pep->num - 1].txcs) : in cdns2_handle_epx_interrupt()
1092 readb(&pdev->epx_regs->ep[pep->num - 1].rxcs); in cdns2_handle_epx_interrupt()
1109 writel(DMA_EP_CMD_DFLUSH, &pep->pdev->adma_regs->ep_cmd); in cdns2_handle_epx_interrupt()
1112 readl_poll_timeout_atomic(&pep->pdev->adma_regs->ep_cmd, val, in cdns2_handle_epx_interrupt()
1115 pep->skip = true; in cdns2_handle_epx_interrupt()
1118 if (ep_sts_reg & DMA_EP_STS_TRBERR || pep->skip) { in cdns2_handle_epx_interrupt()
1119 if (pep->ep_state & EP_STALL_PENDING && in cdns2_handle_epx_interrupt()
1121 cdns2_ep_stall_flush(pep); in cdns2_handle_epx_interrupt()
1130 if (pep->type == USB_ENDPOINT_XFER_ISOC && !pep->wa1_set) { in cdns2_handle_epx_interrupt()
1131 if (!pep->dir) in cdns2_handle_epx_interrupt()
1135 cdns2_transfer_completed(pdev, pep); in cdns2_handle_epx_interrupt()
1136 if (pep->ep_state & EP_DEFERRED_DRDY) { in cdns2_handle_epx_interrupt()
1137 pep->ep_state &= ~EP_DEFERRED_DRDY; in cdns2_handle_epx_interrupt()
1138 cdns2_set_drdy(pdev, pep); in cdns2_handle_epx_interrupt()
1144 cdns2_transfer_completed(pdev, pep); in cdns2_handle_epx_interrupt()
1146 if (!(pep->ep_state & EP_STALLED) && in cdns2_handle_epx_interrupt()
1147 !(pep->ep_state & EP_STALL_PENDING)) { in cdns2_handle_epx_interrupt()
1148 if (pep->ep_state & EP_DEFERRED_DRDY) { in cdns2_handle_epx_interrupt()
1149 pep->ep_state &= ~EP_DEFERRED_DRDY; in cdns2_handle_epx_interrupt()
1150 cdns2_start_all_request(pdev, pep); in cdns2_handle_epx_interrupt()
1152 cdns2_rearm_transfer(pep, pep->wa1_set); in cdns2_handle_epx_interrupt()
1160 cdns2_transfer_completed(pdev, pep); in cdns2_handle_epx_interrupt()
1342 struct cdns2_endpoint *pep; in cdns2_eps_onchip_buffer_init() local
1351 pep = &pdev->eps[i]; in cdns2_eps_onchip_buffer_init()
1353 if (!(pep->ep_state & EP_CLAIMED)) in cdns2_eps_onchip_buffer_init()
1356 if (pep->dir) in cdns2_eps_onchip_buffer_init()
1357 min_buf_tx += pep->buffering; in cdns2_eps_onchip_buffer_init()
1359 min_buf_rx += pep->buffering; in cdns2_eps_onchip_buffer_init()
1363 pep = &pdev->eps[i]; in cdns2_eps_onchip_buffer_init()
1365 if (!(pep->ep_state & EP_CLAIMED)) in cdns2_eps_onchip_buffer_init()
1368 if (pep->dir) { in cdns2_eps_onchip_buffer_init()
1371 if (free + pep->buffering >= 4) in cdns2_eps_onchip_buffer_init()
1374 free = free + pep->buffering; in cdns2_eps_onchip_buffer_init()
1376 min_buf_tx = min_buf_tx - pep->buffering + free; in cdns2_eps_onchip_buffer_init()
1378 pep->buffering = free; in cdns2_eps_onchip_buffer_init()
1381 &pdev->epx_regs->txstaddr[pep->num - 1]); in cdns2_eps_onchip_buffer_init()
1382 pdev->epx_regs->txstaddr[pep->num - 1] = tx_offset; in cdns2_eps_onchip_buffer_init()
1385 pep->name, tx_offset, pep->buffering); in cdns2_eps_onchip_buffer_init()
1387 tx_offset += pep->buffering * 1024; in cdns2_eps_onchip_buffer_init()
1391 if (free + pep->buffering >= 4) in cdns2_eps_onchip_buffer_init()
1394 free = free + pep->buffering; in cdns2_eps_onchip_buffer_init()
1396 min_buf_rx = min_buf_rx - pep->buffering + free; in cdns2_eps_onchip_buffer_init()
1398 pep->buffering = free; in cdns2_eps_onchip_buffer_init()
1400 &pdev->epx_regs->rxstaddr[pep->num - 1]); in cdns2_eps_onchip_buffer_init()
1403 pep->name, rx_offset, pep->buffering); in cdns2_eps_onchip_buffer_init()
1405 rx_offset += pep->buffering * 1024; in cdns2_eps_onchip_buffer_init()
1411 static int cdns2_ep_config(struct cdns2_endpoint *pep, bool enable) in cdns2_ep_config() argument
1413 bool is_iso_ep = (pep->type == USB_ENDPOINT_XFER_ISOC); in cdns2_ep_config()
1414 struct cdns2_device *pdev = pep->pdev; in cdns2_ep_config()
1422 switch (pep->type) { in cdns2_ep_config()
1430 mult = USB_EP_MAXP_MULT(pep->endpoint.desc->wMaxPacketSize); in cdns2_ep_config()
1434 if (pep->dir) { in cdns2_ep_config()
1435 set_reg_bit_8(&pdev->epx_regs->isoautoarm, BIT(pep->num)); in cdns2_ep_config()
1436 set_reg_bit_8(&pdev->epx_regs->isoautodump, BIT(pep->num)); in cdns2_ep_config()
1437 set_reg_bit_8(&pdev->epx_regs->isodctrl, BIT(pep->num)); in cdns2_ep_config()
1453 ep_cfg |= (EPX_CON_VAL | (pep->buffering - 1)); in cdns2_ep_config()
1455 if (pep->dir) { in cdns2_ep_config()
1457 writew(max_packet_size, &pdev->epx_regs->txmaxpack[pep->num - 1]); in cdns2_ep_config()
1458 writeb(ep_cfg, &pdev->epx_regs->ep[pep->num - 1].txcon); in cdns2_ep_config()
1460 writew(max_packet_size, &pdev->epx_regs->rxmaxpack[pep->num - 1]); in cdns2_ep_config()
1461 writeb(ep_cfg, &pdev->epx_regs->ep[pep->num - 1].rxcon); in cdns2_ep_config()
1464 writeb(pep->num | dir | FIFOCTRL_FIFOAUTO, in cdns2_ep_config()
1466 writeb(pep->num | dir, &pdev->epx_regs->endprst); in cdns2_ep_config()
1467 writeb(pep->num | ENDPRST_FIFORST | ENDPRST_TOGRST | dir, in cdns2_ep_config()
1471 pep->trb_burst_size = 128; in cdns2_ep_config()
1473 pep->trb_burst_size = 64; in cdns2_ep_config()
1475 pep->trb_burst_size = 16; in cdns2_ep_config()
1477 cdns2_select_ep(pdev, pep->num | pep->dir); in cdns2_ep_config()
1493 trace_cdns2_epx_hw_cfg(pdev, pep); in cdns2_ep_config()
1496 pep->name, max_packet_size, ep_cfg); in cdns2_ep_config()
1504 struct cdns2_endpoint *pep = ep_to_cdns2_ep(ep); in cdns2_gadget_ep_alloc_request() local
1511 preq->pep = pep; in cdns2_gadget_ep_alloc_request()
1531 struct cdns2_endpoint *pep; in cdns2_gadget_ep_enable() local
1542 pep = ep_to_cdns2_ep(ep); in cdns2_gadget_ep_enable()
1543 pdev = pep->pdev; in cdns2_gadget_ep_enable()
1545 if (dev_WARN_ONCE(pdev->dev, pep->ep_state & EP_ENABLED, in cdns2_gadget_ep_enable()
1546 "%s is already enabled\n", pep->name)) in cdns2_gadget_ep_enable()
1551 pep->type = usb_endpoint_type(desc); in cdns2_gadget_ep_enable()
1552 pep->interval = desc->bInterval ? BIT(desc->bInterval - 1) : 0; in cdns2_gadget_ep_enable()
1555 if (pep->type == USB_ENDPOINT_XFER_INT) in cdns2_gadget_ep_enable()
1556 pep->interval = desc->bInterval; in cdns2_gadget_ep_enable()
1558 if (pep->interval > ISO_MAX_INTERVAL && in cdns2_gadget_ep_enable()
1559 pep->type == USB_ENDPOINT_XFER_ISOC) { in cdns2_gadget_ep_enable()
1561 ISO_MAX_INTERVAL, pep->interval); in cdns2_gadget_ep_enable()
1575 if (pep->type == USB_ENDPOINT_XFER_ISOC && !pep->dir) in cdns2_gadget_ep_enable()
1578 ret = cdns2_alloc_tr_segment(pep); in cdns2_gadget_ep_enable()
1582 ret = cdns2_ep_config(pep, enable); in cdns2_gadget_ep_enable()
1584 cdns2_free_tr_segment(pep); in cdns2_gadget_ep_enable()
1589 trace_cdns2_gadget_ep_enable(pep); in cdns2_gadget_ep_enable()
1591 pep->ep_state &= ~(EP_STALLED | EP_STALL_PENDING); in cdns2_gadget_ep_enable()
1592 pep->ep_state |= EP_ENABLED; in cdns2_gadget_ep_enable()
1593 pep->wa1_set = 0; in cdns2_gadget_ep_enable()
1594 pep->ring.enqueue = 0; in cdns2_gadget_ep_enable()
1595 pep->ring.dequeue = 0; in cdns2_gadget_ep_enable()
1597 pep->ring.pcs = !!DMA_EP_STS_CCS(reg); in cdns2_gadget_ep_enable()
1598 pep->ring.ccs = !!DMA_EP_STS_CCS(reg); in cdns2_gadget_ep_enable()
1600 writel(pep->ring.dma, &pdev->adma_regs->ep_traddr); in cdns2_gadget_ep_enable()
1603 pep->ring.free_trbs = TRBS_PER_SEGMENT - 1; in cdns2_gadget_ep_enable()
1613 struct cdns2_endpoint *pep; in cdns2_gadget_ep_disable() local
1622 pep = ep_to_cdns2_ep(ep); in cdns2_gadget_ep_disable()
1623 pdev = pep->pdev; in cdns2_gadget_ep_disable()
1625 if (dev_WARN_ONCE(pdev->dev, !(pep->ep_state & EP_ENABLED), in cdns2_gadget_ep_disable()
1626 "%s is already disabled\n", pep->name)) in cdns2_gadget_ep_disable()
1631 trace_cdns2_gadget_ep_disable(pep); in cdns2_gadget_ep_disable()
1650 while (!list_empty(&pep->pending_list)) { in cdns2_gadget_ep_disable()
1651 preq = cdns2_next_preq(&pep->pending_list); in cdns2_gadget_ep_disable()
1652 cdns2_gadget_giveback(pep, preq, -ESHUTDOWN); in cdns2_gadget_ep_disable()
1655 while (!list_empty(&pep->deferred_list)) { in cdns2_gadget_ep_disable()
1656 preq = cdns2_next_preq(&pep->deferred_list); in cdns2_gadget_ep_disable()
1657 cdns2_gadget_giveback(pep, preq, -ESHUTDOWN); in cdns2_gadget_ep_disable()
1661 pep->ep_state &= ~EP_ENABLED; in cdns2_gadget_ep_disable()
1668 static int cdns2_ep_enqueue(struct cdns2_endpoint *pep, in cdns2_ep_enqueue() argument
1672 struct cdns2_device *pdev = pep->pdev; in cdns2_ep_enqueue()
1680 ret = usb_gadget_map_request_by_dev(pdev->dev, request, pep->dir); in cdns2_ep_enqueue()
1686 list_add_tail(&preq->list, &pep->deferred_list); in cdns2_ep_enqueue()
1689 if (!(pep->ep_state & EP_STALLED) && !(pep->ep_state & EP_STALL_PENDING)) in cdns2_ep_enqueue()
1690 cdns2_start_all_request(pdev, pep); in cdns2_ep_enqueue()
1700 struct cdns2_endpoint *pep; in cdns2_gadget_ep_queue() local
1708 pep = ep_to_cdns2_ep(ep); in cdns2_gadget_ep_queue()
1709 pdev = pep->pdev; in cdns2_gadget_ep_queue()
1711 if (!(pep->ep_state & EP_ENABLED)) { in cdns2_gadget_ep_queue()
1713 pep->name); in cdns2_gadget_ep_queue()
1720 ret = cdns2_ep_enqueue(pep, preq, gfp_flags); in cdns2_gadget_ep_queue()
1731 ret = cdns2_ep_enqueue(pep, preq, gfp_flags); in cdns2_gadget_ep_queue()
1742 struct cdns2_endpoint *pep; in cdns2_gadget_ep_dequeue() local
1752 pep = ep_to_cdns2_ep(ep); in cdns2_gadget_ep_dequeue()
1753 if (!pep->endpoint.desc) { in cdns2_gadget_ep_dequeue()
1754 dev_err(pep->pdev->dev, "%s: can't dequeue to disabled endpoint\n", in cdns2_gadget_ep_dequeue()
1755 pep->name); in cdns2_gadget_ep_dequeue()
1760 if (!(pep->ep_state & EP_ENABLED)) in cdns2_gadget_ep_dequeue()
1763 spin_lock_irqsave(&pep->pdev->lock, flags); in cdns2_gadget_ep_dequeue()
1768 list_for_each_entry_safe(preq, preq_temp, &pep->pending_list, list) { in cdns2_gadget_ep_dequeue()
1775 list_for_each_entry_safe(preq, preq_temp, &pep->deferred_list, list) { in cdns2_gadget_ep_dequeue()
1788 writel(DMA_EP_CMD_DFLUSH, &pep->pdev->adma_regs->ep_cmd); in cdns2_gadget_ep_dequeue()
1791 readl_poll_timeout_atomic(&pep->pdev->adma_regs->ep_cmd, val, in cdns2_gadget_ep_dequeue()
1794 buffer = cpu_to_le32(TRB_BUFFER(pep->ring.dma + in cdns2_gadget_ep_dequeue()
1803 trace_cdns2_queue_trb(pep, link_trb); in cdns2_gadget_ep_dequeue()
1804 link_trb = cdns2_next_trb(pep, link_trb); in cdns2_gadget_ep_dequeue()
1807 if (pep->wa1_trb == preq->trb) in cdns2_gadget_ep_dequeue()
1808 cdns2_wa1_restore_cycle_bit(pep); in cdns2_gadget_ep_dequeue()
1811 cdns2_gadget_giveback(pep, cur_preq, -ECONNRESET); in cdns2_gadget_ep_dequeue()
1813 preq = cdns2_next_preq(&pep->pending_list); in cdns2_gadget_ep_dequeue()
1815 cdns2_rearm_transfer(pep, 1); in cdns2_gadget_ep_dequeue()
1818 spin_unlock_irqrestore(&pep->pdev->lock, flags); in cdns2_gadget_ep_dequeue()
1823 struct cdns2_endpoint *pep, in cdns2_halt_endpoint() argument
1829 if (!(pep->ep_state & EP_ENABLED)) in cdns2_halt_endpoint()
1832 if (pep->dir) { in cdns2_halt_endpoint()
1834 conf = &pdev->epx_regs->ep[pep->num - 1].txcon; in cdns2_halt_endpoint()
1836 conf = &pdev->epx_regs->ep[pep->num - 1].rxcon; in cdns2_halt_endpoint()
1844 preq = cdns2_next_preq(&pep->pending_list); in cdns2_halt_endpoint()
1853 trace_cdns2_ep_halt(pep, 0, 0); in cdns2_halt_endpoint()
1856 writeb(dir | pep->num, &pdev->epx_regs->endprst); in cdns2_halt_endpoint()
1857 writeb(dir | ENDPRST_TOGRST | pep->num, in cdns2_halt_endpoint()
1862 pep->ep_state &= ~(EP_STALLED | EP_STALL_PENDING); in cdns2_halt_endpoint()
1868 cdns2_rearm_transfer(pep, 1); in cdns2_halt_endpoint()
1871 cdns2_start_all_request(pdev, pep); in cdns2_halt_endpoint()
1873 trace_cdns2_ep_halt(pep, 1, 0); in cdns2_halt_endpoint()
1875 writeb(dir | pep->num, &pdev->epx_regs->endprst); in cdns2_halt_endpoint()
1876 writeb(dir | ENDPRST_FIFORST | pep->num, in cdns2_halt_endpoint()
1878 pep->ep_state |= EP_STALLED; in cdns2_halt_endpoint()
1887 struct cdns2_endpoint *pep = ep_to_cdns2_ep(ep); in cdns2_gadget_ep_set_halt() local
1888 struct cdns2_device *pdev = pep->pdev; in cdns2_gadget_ep_set_halt()
1895 preq = cdns2_next_preq(&pep->pending_list); in cdns2_gadget_ep_set_halt()
1897 trace_cdns2_ep_busy_try_halt_again(pep); in cdns2_gadget_ep_set_halt()
1903 pep->ep_state &= ~EP_WEDGE; in cdns2_gadget_ep_set_halt()
1905 ret = cdns2_halt_endpoint(pdev, pep, value); in cdns2_gadget_ep_set_halt()
1914 struct cdns2_endpoint *pep = ep_to_cdns2_ep(ep); in cdns2_gadget_ep_set_wedge() local
1917 pep->ep_state |= EP_WEDGE; in cdns2_gadget_ep_set_wedge()
1926 struct cdns2_endpoint *pep; in cdns2_find_available_ep() local
1939 pep = ep_to_cdns2_ep(ep); in cdns2_find_available_ep()
1941 if (pep->num != num) in cdns2_find_available_ep()
1944 ep_correct = (pep->endpoint.caps.dir_in && in cdns2_find_available_ep()
1946 (pep->endpoint.caps.dir_out && in cdns2_find_available_ep()
1949 if (ep_correct && !(pep->ep_state & EP_CLAIMED)) in cdns2_find_available_ep()
1950 return pep; in cdns2_find_available_ep()
1966 struct cdns2_endpoint *pep; in cdns2_gadget_match_ep() local
1969 pep = cdns2_find_available_ep(pdev, desc); in cdns2_gadget_match_ep()
1970 if (IS_ERR(pep)) { in cdns2_gadget_match_ep()
1978 pep->buffering = 4; in cdns2_gadget_match_ep()
1980 pep->buffering = 1; in cdns2_gadget_match_ep()
1982 pep->ep_state |= EP_CLAIMED; in cdns2_gadget_match_ep()
1985 return &pep->endpoint; in cdns2_gadget_match_ep()
2130 struct cdns2_endpoint *pep; in cdns2_gadget_udc_stop() local
2139 pep = ep_to_cdns2_ep(ep); in cdns2_gadget_udc_stop()
2140 bEndpointAddress = pep->num | pep->dir; in cdns2_gadget_udc_stop()
2178 struct cdns2_endpoint *pep; in cdns2_init_eps() local
2192 pep = &pdev->eps[i]; in cdns2_init_eps()
2193 pep->pdev = pdev; in cdns2_init_eps()
2194 pep->num = epnum; in cdns2_init_eps()
2196 pep->dir = direction ? USB_DIR_IN : USB_DIR_OUT; in cdns2_init_eps()
2197 pep->idx = i; in cdns2_init_eps()
2203 snprintf(pep->name, sizeof(pep->name), "ep%d%s", in cdns2_init_eps()
2206 cdns2_init_ep0(pdev, pep); in cdns2_init_eps()
2208 ret = cdns2_alloc_tr_segment(pep); in cdns2_init_eps()
2214 snprintf(pep->name, sizeof(pep->name), "ep%d%s", in cdns2_init_eps()
2216 pep->endpoint.name = pep->name; in cdns2_init_eps()
2218 usb_ep_set_maxpacket_limit(&pep->endpoint, 1024); in cdns2_init_eps()
2219 pep->endpoint.ops = &cdns2_gadget_ep_ops; in cdns2_init_eps()
2220 list_add_tail(&pep->endpoint.ep_list, &pdev->gadget.ep_list); in cdns2_init_eps()
2222 pep->endpoint.caps.dir_in = direction; in cdns2_init_eps()
2223 pep->endpoint.caps.dir_out = !direction; in cdns2_init_eps()
2225 pep->endpoint.caps.type_iso = 1; in cdns2_init_eps()
2226 pep->endpoint.caps.type_bulk = 1; in cdns2_init_eps()
2227 pep->endpoint.caps.type_int = 1; in cdns2_init_eps()
2230 pep->endpoint.name = pep->name; in cdns2_init_eps()
2231 pep->ep_state = 0; in cdns2_init_eps()
2235 pep->name, in cdns2_init_eps()
2236 (pep->endpoint.caps.type_control) ? "yes" : "no", in cdns2_init_eps()
2237 (pep->endpoint.caps.type_int) ? "yes" : "no", in cdns2_init_eps()
2238 (pep->endpoint.caps.type_bulk) ? "yes" : "no", in cdns2_init_eps()
2239 (pep->endpoint.caps.type_iso) ? "yes" : "no", in cdns2_init_eps()
2240 (pep->endpoint.caps.dir_in) ? "yes" : "no", in cdns2_init_eps()
2241 (pep->endpoint.caps.dir_out) ? "yes" : "no"); in cdns2_init_eps()
2243 INIT_LIST_HEAD(&pep->pending_list); in cdns2_init_eps()
2244 INIT_LIST_HEAD(&pep->deferred_list); in cdns2_init_eps()