Lines Matching refs:dep

158 static void dwc3_ep_inc_enq(struct dwc3_ep *dep)  in dwc3_ep_inc_enq()  argument
160 dwc3_ep_inc_trb(&dep->trb_enqueue); in dwc3_ep_inc_enq()
167 static void dwc3_ep_inc_deq(struct dwc3_ep *dep) in dwc3_ep_inc_deq() argument
169 dwc3_ep_inc_trb(&dep->trb_dequeue); in dwc3_ep_inc_deq()
172 static void dwc3_gadget_del_and_unmap_request(struct dwc3_ep *dep, in dwc3_gadget_del_and_unmap_request() argument
175 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_del_and_unmap_request()
191 if (dep->number > 1) in dwc3_gadget_del_and_unmap_request()
205 void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, in dwc3_gadget_giveback() argument
208 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_giveback()
210 dwc3_gadget_del_and_unmap_request(dep, req, status); in dwc3_gadget_giveback()
214 usb_gadget_giveback_request(&dep->endpoint, &req->request); in dwc3_gadget_giveback()
268 int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, in dwc3_send_gadget_ep_cmd() argument
271 const struct usb_endpoint_descriptor *desc = dep->endpoint.desc; in dwc3_send_gadget_ep_cmd()
272 struct dwc3 *dwc = dep->dwc; in dwc3_send_gadget_ep_cmd()
320 dwc3_writel(dep->regs, DWC3_DEPCMDPAR0, params->param0); in dwc3_send_gadget_ep_cmd()
321 dwc3_writel(dep->regs, DWC3_DEPCMDPAR1, params->param1); in dwc3_send_gadget_ep_cmd()
322 dwc3_writel(dep->regs, DWC3_DEPCMDPAR2, params->param2); in dwc3_send_gadget_ep_cmd()
345 dwc3_writel(dep->regs, DWC3_DEPCMD, cmd); in dwc3_send_gadget_ep_cmd()
347 reg = dwc3_readl(dep->regs, DWC3_DEPCMD); in dwc3_send_gadget_ep_cmd()
385 trace_dwc3_gadget_ep_cmd(dep, cmd, params, cmd_status); in dwc3_send_gadget_ep_cmd()
388 dep->flags |= DWC3_EP_TRANSFER_STARTED; in dwc3_send_gadget_ep_cmd()
389 dwc3_gadget_ep_get_transfer_index(dep); in dwc3_send_gadget_ep_cmd()
401 static int dwc3_send_clear_stall_ep_cmd(struct dwc3_ep *dep) in dwc3_send_clear_stall_ep_cmd() argument
403 struct dwc3 *dwc = dep->dwc; in dwc3_send_clear_stall_ep_cmd()
415 if (dep->direction && (dwc->revision >= DWC3_REVISION_260A) && in dwc3_send_clear_stall_ep_cmd()
421 return dwc3_send_gadget_ep_cmd(dep, cmd, &params); in dwc3_send_clear_stall_ep_cmd()
424 static dma_addr_t dwc3_trb_dma_offset(struct dwc3_ep *dep, in dwc3_trb_dma_offset() argument
427 u32 offset = (char *) trb - (char *) dep->trb_pool; in dwc3_trb_dma_offset()
429 return dep->trb_pool_dma + offset; in dwc3_trb_dma_offset()
432 static int dwc3_alloc_trb_pool(struct dwc3_ep *dep) in dwc3_alloc_trb_pool() argument
434 struct dwc3 *dwc = dep->dwc; in dwc3_alloc_trb_pool()
436 if (dep->trb_pool) in dwc3_alloc_trb_pool()
439 dep->trb_pool = dma_alloc_coherent(dwc->sysdev, in dwc3_alloc_trb_pool()
441 &dep->trb_pool_dma, GFP_KERNEL); in dwc3_alloc_trb_pool()
442 if (!dep->trb_pool) { in dwc3_alloc_trb_pool()
443 dev_err(dep->dwc->dev, "failed to allocate trb pool for %s\n", in dwc3_alloc_trb_pool()
444 dep->name); in dwc3_alloc_trb_pool()
451 static void dwc3_free_trb_pool(struct dwc3_ep *dep) in dwc3_free_trb_pool() argument
453 struct dwc3 *dwc = dep->dwc; in dwc3_free_trb_pool()
456 dep->trb_pool, dep->trb_pool_dma); in dwc3_free_trb_pool()
458 dep->trb_pool = NULL; in dwc3_free_trb_pool()
459 dep->trb_pool_dma = 0; in dwc3_free_trb_pool()
462 static int dwc3_gadget_set_xfer_resource(struct dwc3_ep *dep) in dwc3_gadget_set_xfer_resource() argument
470 return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETTRANSFRESOURCE, in dwc3_gadget_set_xfer_resource()
507 static int dwc3_gadget_start_config(struct dwc3_ep *dep) in dwc3_gadget_start_config() argument
515 if (dep->number) in dwc3_gadget_start_config()
520 dwc = dep->dwc; in dwc3_gadget_start_config()
522 ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); in dwc3_gadget_start_config()
527 struct dwc3_ep *dep = dwc->eps[i]; in dwc3_gadget_start_config() local
529 if (!dep) in dwc3_gadget_start_config()
532 ret = dwc3_gadget_set_xfer_resource(dep); in dwc3_gadget_start_config()
540 static int dwc3_gadget_set_ep_config(struct dwc3_ep *dep, unsigned int action) in dwc3_gadget_set_ep_config() argument
545 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_set_ep_config()
547 comp_desc = dep->endpoint.comp_desc; in dwc3_gadget_set_ep_config()
548 desc = dep->endpoint.desc; in dwc3_gadget_set_ep_config()
557 u32 burst = dep->endpoint.maxburst; in dwc3_gadget_set_ep_config()
563 params.param2 |= dep->saved_state; in dwc3_gadget_set_ep_config()
568 if (dep->number <= 1 || usb_endpoint_xfer_isoc(desc)) in dwc3_gadget_set_ep_config()
574 dep->stream_capable = true; in dwc3_gadget_set_ep_config()
586 params.param1 |= DWC3_DEPCFG_EP_NUMBER(dep->number); in dwc3_gadget_set_ep_config()
592 if (dep->direction) in dwc3_gadget_set_ep_config()
593 params.param0 |= DWC3_DEPCFG_FIFO_NUMBER(dep->number >> 1); in dwc3_gadget_set_ep_config()
597 dep->interval = 1 << (desc->bInterval - 1); in dwc3_gadget_set_ep_config()
600 return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETEPCONFIG, &params); in dwc3_gadget_set_ep_config()
611 static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action) in __dwc3_gadget_ep_enable() argument
613 const struct usb_endpoint_descriptor *desc = dep->endpoint.desc; in __dwc3_gadget_ep_enable()
614 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_enable()
619 if (!(dep->flags & DWC3_EP_ENABLED)) { in __dwc3_gadget_ep_enable()
620 ret = dwc3_gadget_start_config(dep); in __dwc3_gadget_ep_enable()
625 ret = dwc3_gadget_set_ep_config(dep, action); in __dwc3_gadget_ep_enable()
629 if (!(dep->flags & DWC3_EP_ENABLED)) { in __dwc3_gadget_ep_enable()
633 dep->type = usb_endpoint_type(desc); in __dwc3_gadget_ep_enable()
634 dep->flags |= DWC3_EP_ENABLED; in __dwc3_gadget_ep_enable()
637 reg |= DWC3_DALEPENA_EP(dep->number); in __dwc3_gadget_ep_enable()
644 dep->trb_dequeue = 0; in __dwc3_gadget_ep_enable()
645 dep->trb_enqueue = 0; in __dwc3_gadget_ep_enable()
646 memset(dep->trb_pool, 0, in __dwc3_gadget_ep_enable()
650 trb_st_hw = &dep->trb_pool[0]; in __dwc3_gadget_ep_enable()
652 trb_link = &dep->trb_pool[DWC3_TRB_NUM - 1]; in __dwc3_gadget_ep_enable()
653 trb_link->bpl = lower_32_bits(dwc3_trb_dma_offset(dep, trb_st_hw)); in __dwc3_gadget_ep_enable()
654 trb_link->bph = upper_32_bits(dwc3_trb_dma_offset(dep, trb_st_hw)); in __dwc3_gadget_ep_enable()
663 if ((usb_endpoint_xfer_bulk(desc) && !dep->stream_capable) || in __dwc3_gadget_ep_enable()
671 trb = &dep->trb_pool[0]; in __dwc3_gadget_ep_enable()
672 trb_dma = dwc3_trb_dma_offset(dep, trb); in __dwc3_gadget_ep_enable()
679 ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); in __dwc3_gadget_ep_enable()
685 trace_dwc3_gadget_ep_enable(dep); in __dwc3_gadget_ep_enable()
690 static void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force,
692 static void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep) in dwc3_remove_requests() argument
696 dwc3_stop_active_transfer(dep, true, false); in dwc3_remove_requests()
699 while (!list_empty(&dep->started_list)) { in dwc3_remove_requests()
700 req = next_request(&dep->started_list); in dwc3_remove_requests()
702 dwc3_gadget_giveback(dep, req, -ESHUTDOWN); in dwc3_remove_requests()
705 while (!list_empty(&dep->pending_list)) { in dwc3_remove_requests()
706 req = next_request(&dep->pending_list); in dwc3_remove_requests()
708 dwc3_gadget_giveback(dep, req, -ESHUTDOWN); in dwc3_remove_requests()
711 while (!list_empty(&dep->cancelled_list)) { in dwc3_remove_requests()
712 req = next_request(&dep->cancelled_list); in dwc3_remove_requests()
714 dwc3_gadget_giveback(dep, req, -ESHUTDOWN); in dwc3_remove_requests()
728 static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep) in __dwc3_gadget_ep_disable() argument
730 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_disable()
733 trace_dwc3_gadget_ep_disable(dep); in __dwc3_gadget_ep_disable()
735 dwc3_remove_requests(dwc, dep); in __dwc3_gadget_ep_disable()
738 if (dep->flags & DWC3_EP_STALL) in __dwc3_gadget_ep_disable()
739 __dwc3_gadget_ep_set_halt(dep, 0, false); in __dwc3_gadget_ep_disable()
742 reg &= ~DWC3_DALEPENA_EP(dep->number); in __dwc3_gadget_ep_disable()
745 dep->stream_capable = false; in __dwc3_gadget_ep_disable()
746 dep->type = 0; in __dwc3_gadget_ep_disable()
747 dep->flags = 0; in __dwc3_gadget_ep_disable()
750 if (dep->number > 1) { in __dwc3_gadget_ep_disable()
751 dep->endpoint.comp_desc = NULL; in __dwc3_gadget_ep_disable()
752 dep->endpoint.desc = NULL; in __dwc3_gadget_ep_disable()
776 struct dwc3_ep *dep; in dwc3_gadget_ep_enable() local
791 dep = to_dwc3_ep(ep); in dwc3_gadget_ep_enable()
792 dwc = dep->dwc; in dwc3_gadget_ep_enable()
794 if (dev_WARN_ONCE(dwc->dev, dep->flags & DWC3_EP_ENABLED, in dwc3_gadget_ep_enable()
796 dep->name)) in dwc3_gadget_ep_enable()
800 ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT); in dwc3_gadget_ep_enable()
808 struct dwc3_ep *dep; in dwc3_gadget_ep_disable() local
818 dep = to_dwc3_ep(ep); in dwc3_gadget_ep_disable()
819 dwc = dep->dwc; in dwc3_gadget_ep_disable()
821 if (dev_WARN_ONCE(dwc->dev, !(dep->flags & DWC3_EP_ENABLED), in dwc3_gadget_ep_disable()
823 dep->name)) in dwc3_gadget_ep_disable()
827 ret = __dwc3_gadget_ep_disable(dep); in dwc3_gadget_ep_disable()
837 struct dwc3_ep *dep = to_dwc3_ep(ep); in dwc3_gadget_ep_alloc_request() local
843 req->direction = dep->direction; in dwc3_gadget_ep_alloc_request()
844 req->epnum = dep->number; in dwc3_gadget_ep_alloc_request()
845 req->dep = dep; in dwc3_gadget_ep_alloc_request()
871 static struct dwc3_trb *dwc3_ep_prev_trb(struct dwc3_ep *dep, u8 index) in dwc3_ep_prev_trb() argument
878 return &dep->trb_pool[tmp - 1]; in dwc3_ep_prev_trb()
881 static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep) in dwc3_calc_trbs_left() argument
893 if (dep->trb_enqueue == dep->trb_dequeue) { in dwc3_calc_trbs_left()
894 tmp = dwc3_ep_prev_trb(dep, dep->trb_enqueue); in dwc3_calc_trbs_left()
901 trbs_left = dep->trb_dequeue - dep->trb_enqueue; in dwc3_calc_trbs_left()
904 if (dep->trb_dequeue < dep->trb_enqueue) in dwc3_calc_trbs_left()
910 static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb, in __dwc3_prepare_one_trb() argument
914 struct dwc3 *dwc = dep->dwc; in __dwc3_prepare_one_trb()
922 switch (usb_endpoint_type(dep->endpoint.desc)) { in __dwc3_prepare_one_trb()
954 struct usb_ep *ep = &dep->endpoint; in __dwc3_prepare_one_trb()
984 usb_endpoint_type(dep->endpoint.desc)); in __dwc3_prepare_one_trb()
991 if (usb_endpoint_dir_out(dep->endpoint.desc)) { in __dwc3_prepare_one_trb()
992 if (!dep->stream_capable) in __dwc3_prepare_one_trb()
1000 (dwc3_calc_trbs_left(dep) == 1)) in __dwc3_prepare_one_trb()
1006 if (usb_endpoint_xfer_bulk(dep->endpoint.desc) && dep->stream_capable) in __dwc3_prepare_one_trb()
1011 dwc3_ep_inc_enq(dep); in __dwc3_prepare_one_trb()
1013 trace_dwc3_prepare_trb(dep, trb); in __dwc3_prepare_one_trb()
1023 static void dwc3_prepare_one_trb(struct dwc3_ep *dep, in dwc3_prepare_one_trb() argument
1041 trb = &dep->trb_pool[dep->trb_enqueue]; in dwc3_prepare_one_trb()
1046 req->trb_dma = dwc3_trb_dma_offset(dep, trb); in dwc3_prepare_one_trb()
1051 __dwc3_prepare_one_trb(dep, trb, dma, length, chain, node, in dwc3_prepare_one_trb()
1055 static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, in dwc3_prepare_one_trb_sg() argument
1067 unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); in dwc3_prepare_one_trb_sg()
1074 if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) { in dwc3_prepare_one_trb_sg()
1075 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_one_trb_sg()
1081 dwc3_prepare_one_trb(dep, req, true, i); in dwc3_prepare_one_trb_sg()
1084 trb = &dep->trb_pool[dep->trb_enqueue]; in dwc3_prepare_one_trb_sg()
1086 __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, in dwc3_prepare_one_trb_sg()
1092 dwc3_prepare_one_trb(dep, req, chain, i); in dwc3_prepare_one_trb_sg()
1107 if (!dwc3_calc_trbs_left(dep)) in dwc3_prepare_one_trb_sg()
1112 static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, in dwc3_prepare_one_trb_linear() argument
1116 unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); in dwc3_prepare_one_trb_linear()
1119 if ((!length || rem) && usb_endpoint_dir_out(dep->endpoint.desc)) { in dwc3_prepare_one_trb_linear()
1120 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_one_trb_linear()
1126 dwc3_prepare_one_trb(dep, req, true, 0); in dwc3_prepare_one_trb_linear()
1129 trb = &dep->trb_pool[dep->trb_enqueue]; in dwc3_prepare_one_trb_linear()
1131 __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp - rem, in dwc3_prepare_one_trb_linear()
1137 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_one_trb_linear()
1143 dwc3_prepare_one_trb(dep, req, true, 0); in dwc3_prepare_one_trb_linear()
1146 trb = &dep->trb_pool[dep->trb_enqueue]; in dwc3_prepare_one_trb_linear()
1148 __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, 0, in dwc3_prepare_one_trb_linear()
1153 dwc3_prepare_one_trb(dep, req, false, 0); in dwc3_prepare_one_trb_linear()
1165 static void dwc3_prepare_trbs(struct dwc3_ep *dep) in dwc3_prepare_trbs() argument
1181 list_for_each_entry(req, &dep->started_list, list) { in dwc3_prepare_trbs()
1183 dwc3_prepare_one_trb_sg(dep, req); in dwc3_prepare_trbs()
1185 if (!dwc3_calc_trbs_left(dep)) in dwc3_prepare_trbs()
1189 list_for_each_entry_safe(req, n, &dep->pending_list, list) { in dwc3_prepare_trbs()
1190 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_trbs()
1194 dep->direction); in dwc3_prepare_trbs()
1204 dwc3_prepare_one_trb_sg(dep, req); in dwc3_prepare_trbs()
1206 dwc3_prepare_one_trb_linear(dep, req); in dwc3_prepare_trbs()
1208 if (!dwc3_calc_trbs_left(dep)) in dwc3_prepare_trbs()
1213 static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep) in __dwc3_gadget_kick_transfer() argument
1221 if (!dwc3_calc_trbs_left(dep)) in __dwc3_gadget_kick_transfer()
1224 starting = !(dep->flags & DWC3_EP_TRANSFER_STARTED); in __dwc3_gadget_kick_transfer()
1226 dwc3_prepare_trbs(dep); in __dwc3_gadget_kick_transfer()
1227 req = next_request(&dep->started_list); in __dwc3_gadget_kick_transfer()
1229 dep->flags |= DWC3_EP_PENDING_REQUEST; in __dwc3_gadget_kick_transfer()
1240 if (dep->stream_capable) in __dwc3_gadget_kick_transfer()
1243 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) in __dwc3_gadget_kick_transfer()
1244 cmd |= DWC3_DEPCMD_PARAM(dep->frame_number); in __dwc3_gadget_kick_transfer()
1247 DWC3_DEPCMD_PARAM(dep->resource_index); in __dwc3_gadget_kick_transfer()
1250 ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); in __dwc3_gadget_kick_transfer()
1259 dwc3_gadget_del_and_unmap_request(dep, req, ret); in __dwc3_gadget_kick_transfer()
1316 static int dwc3_gadget_start_isoc_quirk(struct dwc3_ep *dep) in dwc3_gadget_start_isoc_quirk() argument
1322 while (dep->combo_num < 2) { in dwc3_gadget_start_isoc_quirk()
1331 test_frame_number = dep->frame_number & 0x3fff; in dwc3_gadget_start_isoc_quirk()
1332 test_frame_number |= dep->combo_num << 14; in dwc3_gadget_start_isoc_quirk()
1333 test_frame_number += max_t(u32, 4, dep->interval); in dwc3_gadget_start_isoc_quirk()
1335 params.param0 = upper_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1336 params.param1 = lower_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1340 cmd_status = dwc3_send_gadget_ep_cmd(dep, cmd, &params); in dwc3_gadget_start_isoc_quirk()
1344 dep->start_cmd_status = 0; in dwc3_gadget_start_isoc_quirk()
1345 dep->combo_num = 0; in dwc3_gadget_start_isoc_quirk()
1350 if (dep->combo_num == 0) in dwc3_gadget_start_isoc_quirk()
1351 dep->start_cmd_status = cmd_status; in dwc3_gadget_start_isoc_quirk()
1353 dep->combo_num++; in dwc3_gadget_start_isoc_quirk()
1360 dwc3_stop_active_transfer(dep, true, true); in dwc3_gadget_start_isoc_quirk()
1366 test0 = (dep->start_cmd_status == 0); in dwc3_gadget_start_isoc_quirk()
1370 dep->combo_num = 1; in dwc3_gadget_start_isoc_quirk()
1372 dep->combo_num = 2; in dwc3_gadget_start_isoc_quirk()
1374 dep->combo_num = 3; in dwc3_gadget_start_isoc_quirk()
1376 dep->combo_num = 0; in dwc3_gadget_start_isoc_quirk()
1378 dep->frame_number &= 0x3fff; in dwc3_gadget_start_isoc_quirk()
1379 dep->frame_number |= dep->combo_num << 14; in dwc3_gadget_start_isoc_quirk()
1380 dep->frame_number += max_t(u32, 4, dep->interval); in dwc3_gadget_start_isoc_quirk()
1383 dep->start_cmd_status = 0; in dwc3_gadget_start_isoc_quirk()
1384 dep->combo_num = 0; in dwc3_gadget_start_isoc_quirk()
1386 return __dwc3_gadget_kick_transfer(dep); in dwc3_gadget_start_isoc_quirk()
1389 static int __dwc3_gadget_start_isoc(struct dwc3_ep *dep) in __dwc3_gadget_start_isoc() argument
1391 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_start_isoc()
1395 if (list_empty(&dep->pending_list)) { in __dwc3_gadget_start_isoc()
1396 dep->flags |= DWC3_EP_PENDING_REQUEST; in __dwc3_gadget_start_isoc()
1406 if (dwc->gadget.speed <= USB_SPEED_HIGH && dep->direction) in __dwc3_gadget_start_isoc()
1407 return dwc3_gadget_start_isoc_quirk(dep); in __dwc3_gadget_start_isoc()
1411 dep->frame_number = DWC3_ALIGN_FRAME(dep, i + 1); in __dwc3_gadget_start_isoc()
1413 ret = __dwc3_gadget_kick_transfer(dep); in __dwc3_gadget_start_isoc()
1421 static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) in __dwc3_gadget_ep_queue() argument
1423 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_queue()
1425 if (!dep->endpoint.desc) { in __dwc3_gadget_ep_queue()
1427 dep->name); in __dwc3_gadget_ep_queue()
1431 if (WARN(req->dep != dep, "request %pK belongs to '%s'\n", in __dwc3_gadget_ep_queue()
1432 &req->request, req->dep->name)) in __dwc3_gadget_ep_queue()
1437 dep->name, &req->request)) in __dwc3_gadget_ep_queue()
1447 list_add_tail(&req->list, &dep->pending_list); in __dwc3_gadget_ep_queue()
1458 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { in __dwc3_gadget_ep_queue()
1459 if (!(dep->flags & DWC3_EP_PENDING_REQUEST) && in __dwc3_gadget_ep_queue()
1460 !(dep->flags & DWC3_EP_TRANSFER_STARTED)) in __dwc3_gadget_ep_queue()
1463 if ((dep->flags & DWC3_EP_PENDING_REQUEST)) { in __dwc3_gadget_ep_queue()
1464 if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) { in __dwc3_gadget_ep_queue()
1465 return __dwc3_gadget_start_isoc(dep); in __dwc3_gadget_ep_queue()
1470 return __dwc3_gadget_kick_transfer(dep); in __dwc3_gadget_ep_queue()
1477 struct dwc3_ep *dep = to_dwc3_ep(ep); in dwc3_gadget_ep_queue() local
1478 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_queue()
1485 ret = __dwc3_gadget_ep_queue(dep, req); in dwc3_gadget_ep_queue()
1491 static void dwc3_gadget_ep_skip_trbs(struct dwc3_ep *dep, struct dwc3_request *req) in dwc3_gadget_ep_skip_trbs() argument
1510 dwc3_ep_inc_deq(dep); in dwc3_gadget_ep_skip_trbs()
1516 static void dwc3_gadget_ep_cleanup_cancelled_requests(struct dwc3_ep *dep) in dwc3_gadget_ep_cleanup_cancelled_requests() argument
1521 list_for_each_entry_safe(req, tmp, &dep->cancelled_list, list) { in dwc3_gadget_ep_cleanup_cancelled_requests()
1522 dwc3_gadget_ep_skip_trbs(dep, req); in dwc3_gadget_ep_cleanup_cancelled_requests()
1523 dwc3_gadget_giveback(dep, req, -ECONNRESET); in dwc3_gadget_ep_cleanup_cancelled_requests()
1533 struct dwc3_ep *dep = to_dwc3_ep(ep); in dwc3_gadget_ep_dequeue() local
1534 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_dequeue()
1543 list_for_each_entry(r, &dep->pending_list, list) { in dwc3_gadget_ep_dequeue()
1549 list_for_each_entry(r, &dep->started_list, list) { in dwc3_gadget_ep_dequeue()
1555 dwc3_stop_active_transfer(dep, true, true); in dwc3_gadget_ep_dequeue()
1561 if (dep->flags & DWC3_EP_TRANSFER_STARTED) in dwc3_gadget_ep_dequeue()
1573 dwc3_gadget_giveback(dep, req, -ECONNRESET); in dwc3_gadget_ep_dequeue()
1581 int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol) in __dwc3_gadget_ep_set_halt() argument
1584 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_set_halt()
1587 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { in __dwc3_gadget_ep_set_halt()
1588 dev_err(dwc->dev, "%s is of Isochronous type\n", dep->name); in __dwc3_gadget_ep_set_halt()
1600 if (dep->number > 1) in __dwc3_gadget_ep_set_halt()
1601 trb = dwc3_ep_prev_trb(dep, dep->trb_enqueue); in __dwc3_gadget_ep_set_halt()
1603 trb = &dwc->ep0_trb[dep->trb_enqueue]; in __dwc3_gadget_ep_set_halt()
1606 started = !list_empty(&dep->started_list); in __dwc3_gadget_ep_set_halt()
1608 if (!protocol && ((dep->direction && transfer_in_flight) || in __dwc3_gadget_ep_set_halt()
1609 (!dep->direction && started))) { in __dwc3_gadget_ep_set_halt()
1613 ret = dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETSTALL, in __dwc3_gadget_ep_set_halt()
1617 dep->name); in __dwc3_gadget_ep_set_halt()
1619 dep->flags |= DWC3_EP_STALL; in __dwc3_gadget_ep_set_halt()
1622 ret = dwc3_send_clear_stall_ep_cmd(dep); in __dwc3_gadget_ep_set_halt()
1625 dep->name); in __dwc3_gadget_ep_set_halt()
1627 dep->flags &= ~(DWC3_EP_STALL | DWC3_EP_WEDGE); in __dwc3_gadget_ep_set_halt()
1635 struct dwc3_ep *dep = to_dwc3_ep(ep); in dwc3_gadget_ep_set_halt() local
1636 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_halt()
1643 ret = __dwc3_gadget_ep_set_halt(dep, value, false); in dwc3_gadget_ep_set_halt()
1651 struct dwc3_ep *dep = to_dwc3_ep(ep); in dwc3_gadget_ep_set_wedge() local
1652 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_wedge()
1657 dep->flags |= DWC3_EP_WEDGE; in dwc3_gadget_ep_set_wedge()
1659 if (dep->number == 0 || dep->number == 1) in dwc3_gadget_ep_set_wedge()
1662 ret = __dwc3_gadget_ep_set_halt(dep, 1, false); in dwc3_gadget_ep_set_wedge()
1946 struct dwc3_ep *dep; in __dwc3_gadget_start() local
1981 dep = dwc->eps[0]; in __dwc3_gadget_start()
1982 ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT); in __dwc3_gadget_start()
1984 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
1988 dep = dwc->eps[1]; in __dwc3_gadget_start()
1989 ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT); in __dwc3_gadget_start()
1991 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
2195 static int dwc3_gadget_init_control_endpoint(struct dwc3_ep *dep) in dwc3_gadget_init_control_endpoint() argument
2197 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_control_endpoint()
2199 usb_ep_set_maxpacket_limit(&dep->endpoint, 512); in dwc3_gadget_init_control_endpoint()
2200 dep->endpoint.maxburst = 1; in dwc3_gadget_init_control_endpoint()
2201 dep->endpoint.ops = &dwc3_gadget_ep0_ops; in dwc3_gadget_init_control_endpoint()
2202 if (!dep->direction) in dwc3_gadget_init_control_endpoint()
2203 dwc->gadget.ep0 = &dep->endpoint; in dwc3_gadget_init_control_endpoint()
2205 dep->endpoint.caps.type_control = true; in dwc3_gadget_init_control_endpoint()
2210 static int dwc3_gadget_init_in_endpoint(struct dwc3_ep *dep) in dwc3_gadget_init_in_endpoint() argument
2212 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_in_endpoint()
2221 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1)); in dwc3_gadget_init_in_endpoint()
2242 usb_ep_set_maxpacket_limit(&dep->endpoint, size); in dwc3_gadget_init_in_endpoint()
2244 dep->endpoint.max_streams = 15; in dwc3_gadget_init_in_endpoint()
2245 dep->endpoint.ops = &dwc3_gadget_ep_ops; in dwc3_gadget_init_in_endpoint()
2246 list_add_tail(&dep->endpoint.ep_list, in dwc3_gadget_init_in_endpoint()
2248 dep->endpoint.caps.type_iso = true; in dwc3_gadget_init_in_endpoint()
2249 dep->endpoint.caps.type_bulk = true; in dwc3_gadget_init_in_endpoint()
2250 dep->endpoint.caps.type_int = true; in dwc3_gadget_init_in_endpoint()
2252 return dwc3_alloc_trb_pool(dep); in dwc3_gadget_init_in_endpoint()
2255 static int dwc3_gadget_init_out_endpoint(struct dwc3_ep *dep) in dwc3_gadget_init_out_endpoint() argument
2257 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_out_endpoint()
2259 usb_ep_set_maxpacket_limit(&dep->endpoint, 1024); in dwc3_gadget_init_out_endpoint()
2260 dep->endpoint.max_streams = 15; in dwc3_gadget_init_out_endpoint()
2261 dep->endpoint.ops = &dwc3_gadget_ep_ops; in dwc3_gadget_init_out_endpoint()
2262 list_add_tail(&dep->endpoint.ep_list, in dwc3_gadget_init_out_endpoint()
2264 dep->endpoint.caps.type_iso = true; in dwc3_gadget_init_out_endpoint()
2265 dep->endpoint.caps.type_bulk = true; in dwc3_gadget_init_out_endpoint()
2266 dep->endpoint.caps.type_int = true; in dwc3_gadget_init_out_endpoint()
2268 return dwc3_alloc_trb_pool(dep); in dwc3_gadget_init_out_endpoint()
2273 struct dwc3_ep *dep; in dwc3_gadget_init_endpoint() local
2278 dep = kzalloc(sizeof(*dep), GFP_KERNEL); in dwc3_gadget_init_endpoint()
2279 if (!dep) in dwc3_gadget_init_endpoint()
2282 dep->dwc = dwc; in dwc3_gadget_init_endpoint()
2283 dep->number = epnum; in dwc3_gadget_init_endpoint()
2284 dep->direction = direction; in dwc3_gadget_init_endpoint()
2285 dep->regs = dwc->regs + DWC3_DEP_BASE(epnum); in dwc3_gadget_init_endpoint()
2286 dwc->eps[epnum] = dep; in dwc3_gadget_init_endpoint()
2287 dep->combo_num = 0; in dwc3_gadget_init_endpoint()
2288 dep->start_cmd_status = 0; in dwc3_gadget_init_endpoint()
2290 snprintf(dep->name, sizeof(dep->name), "ep%u%s", num, in dwc3_gadget_init_endpoint()
2293 dep->endpoint.name = dep->name; in dwc3_gadget_init_endpoint()
2295 if (!(dep->number > 1)) { in dwc3_gadget_init_endpoint()
2296 dep->endpoint.desc = &dwc3_gadget_ep0_desc; in dwc3_gadget_init_endpoint()
2297 dep->endpoint.comp_desc = NULL; in dwc3_gadget_init_endpoint()
2301 ret = dwc3_gadget_init_control_endpoint(dep); in dwc3_gadget_init_endpoint()
2303 ret = dwc3_gadget_init_in_endpoint(dep); in dwc3_gadget_init_endpoint()
2305 ret = dwc3_gadget_init_out_endpoint(dep); in dwc3_gadget_init_endpoint()
2310 dep->endpoint.caps.dir_in = direction; in dwc3_gadget_init_endpoint()
2311 dep->endpoint.caps.dir_out = !direction; in dwc3_gadget_init_endpoint()
2313 INIT_LIST_HEAD(&dep->pending_list); in dwc3_gadget_init_endpoint()
2314 INIT_LIST_HEAD(&dep->started_list); in dwc3_gadget_init_endpoint()
2315 INIT_LIST_HEAD(&dep->cancelled_list); in dwc3_gadget_init_endpoint()
2339 struct dwc3_ep *dep; in dwc3_gadget_free_endpoints() local
2343 dep = dwc->eps[epnum]; in dwc3_gadget_free_endpoints()
2344 if (!dep) in dwc3_gadget_free_endpoints()
2356 dwc3_free_trb_pool(dep); in dwc3_gadget_free_endpoints()
2357 list_del(&dep->endpoint.ep_list); in dwc3_gadget_free_endpoints()
2360 kfree(dep); in dwc3_gadget_free_endpoints()
2366 static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, in dwc3_gadget_ep_reclaim_completed_trb() argument
2372 dwc3_ep_inc_deq(dep); in dwc3_gadget_ep_reclaim_completed_trb()
2374 trace_dwc3_complete_trb(dep, trb); in dwc3_gadget_ep_reclaim_completed_trb()
2394 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && in dwc3_gadget_ep_reclaim_completed_trb()
2399 frame_number &= ~(dep->interval - 1); in dwc3_gadget_ep_reclaim_completed_trb()
2429 static int dwc3_gadget_ep_reclaim_trb_sg(struct dwc3_ep *dep, in dwc3_gadget_ep_reclaim_trb_sg() argument
2433 struct dwc3_trb *trb = &dep->trb_pool[dep->trb_dequeue]; in dwc3_gadget_ep_reclaim_trb_sg()
2441 trb = &dep->trb_pool[dep->trb_dequeue]; in dwc3_gadget_ep_reclaim_trb_sg()
2449 ret = dwc3_gadget_ep_reclaim_completed_trb(dep, req, in dwc3_gadget_ep_reclaim_trb_sg()
2458 static int dwc3_gadget_ep_reclaim_trb_linear(struct dwc3_ep *dep, in dwc3_gadget_ep_reclaim_trb_linear() argument
2462 struct dwc3_trb *trb = &dep->trb_pool[dep->trb_dequeue]; in dwc3_gadget_ep_reclaim_trb_linear()
2464 return dwc3_gadget_ep_reclaim_completed_trb(dep, req, trb, in dwc3_gadget_ep_reclaim_trb_linear()
2473 static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, in dwc3_gadget_ep_cleanup_completed_request() argument
2480 ret = dwc3_gadget_ep_reclaim_trb_sg(dep, req, event, in dwc3_gadget_ep_cleanup_completed_request()
2483 ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, in dwc3_gadget_ep_cleanup_completed_request()
2487 ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, in dwc3_gadget_ep_cleanup_completed_request()
2496 __dwc3_gadget_kick_transfer(dep); in dwc3_gadget_ep_cleanup_completed_request()
2500 dwc3_gadget_giveback(dep, req, status); in dwc3_gadget_ep_cleanup_completed_request()
2506 static void dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep, in dwc3_gadget_ep_cleanup_completed_requests() argument
2512 list_for_each_entry_safe(req, tmp, &dep->started_list, list) { in dwc3_gadget_ep_cleanup_completed_requests()
2515 ret = dwc3_gadget_ep_cleanup_completed_request(dep, event, in dwc3_gadget_ep_cleanup_completed_requests()
2522 static void dwc3_gadget_endpoint_frame_from_event(struct dwc3_ep *dep, in dwc3_gadget_endpoint_frame_from_event() argument
2525 dep->frame_number = event->parameters; in dwc3_gadget_endpoint_frame_from_event()
2528 static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep, in dwc3_gadget_endpoint_transfer_in_progress() argument
2531 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_transfer_in_progress()
2535 dwc3_gadget_endpoint_frame_from_event(dep, event); in dwc3_gadget_endpoint_transfer_in_progress()
2543 if (list_empty(&dep->started_list)) in dwc3_gadget_endpoint_transfer_in_progress()
2547 dwc3_gadget_ep_cleanup_completed_requests(dep, event, status); in dwc3_gadget_endpoint_transfer_in_progress()
2550 dwc3_stop_active_transfer(dep, true, true); in dwc3_gadget_endpoint_transfer_in_progress()
2551 dep->flags = DWC3_EP_ENABLED; in dwc3_gadget_endpoint_transfer_in_progress()
2563 dep = dwc->eps[i]; in dwc3_gadget_endpoint_transfer_in_progress()
2565 if (!(dep->flags & DWC3_EP_ENABLED)) in dwc3_gadget_endpoint_transfer_in_progress()
2568 if (!list_empty(&dep->started_list)) in dwc3_gadget_endpoint_transfer_in_progress()
2580 static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3_ep *dep, in dwc3_gadget_endpoint_transfer_not_ready() argument
2583 dwc3_gadget_endpoint_frame_from_event(dep, event); in dwc3_gadget_endpoint_transfer_not_ready()
2584 (void) __dwc3_gadget_start_isoc(dep); in dwc3_gadget_endpoint_transfer_not_ready()
2590 struct dwc3_ep *dep; in dwc3_endpoint_interrupt() local
2594 dep = dwc->eps[epnum]; in dwc3_endpoint_interrupt()
2596 if (!(dep->flags & DWC3_EP_ENABLED)) { in dwc3_endpoint_interrupt()
2597 if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) in dwc3_endpoint_interrupt()
2612 dwc3_gadget_endpoint_transfer_in_progress(dep, event); in dwc3_endpoint_interrupt()
2615 dwc3_gadget_endpoint_transfer_not_ready(dep, event); in dwc3_endpoint_interrupt()
2621 dep->flags &= ~DWC3_EP_TRANSFER_STARTED; in dwc3_endpoint_interrupt()
2622 dwc3_gadget_ep_cleanup_cancelled_requests(dep); in dwc3_endpoint_interrupt()
2671 static void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, in dwc3_stop_active_transfer() argument
2674 struct dwc3 *dwc = dep->dwc; in dwc3_stop_active_transfer()
2679 if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) in dwc3_stop_active_transfer()
2716 cmd |= DWC3_DEPCMD_PARAM(dep->resource_index); in dwc3_stop_active_transfer()
2718 ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); in dwc3_stop_active_transfer()
2720 dep->resource_index = 0; in dwc3_stop_active_transfer()
2731 struct dwc3_ep *dep; in dwc3_clear_stall_all_ep() local
2734 dep = dwc->eps[epnum]; in dwc3_clear_stall_all_ep()
2735 if (!dep) in dwc3_clear_stall_all_ep()
2738 if (!(dep->flags & DWC3_EP_STALL)) in dwc3_clear_stall_all_ep()
2741 dep->flags &= ~DWC3_EP_STALL; in dwc3_clear_stall_all_ep()
2743 ret = dwc3_send_clear_stall_ep_cmd(dep); in dwc3_clear_stall_all_ep()
2821 struct dwc3_ep *dep; in dwc3_gadget_conndone_interrupt() local
2920 dep = dwc->eps[0]; in dwc3_gadget_conndone_interrupt()
2921 ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_MODIFY); in dwc3_gadget_conndone_interrupt()
2923 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
2927 dep = dwc->eps[1]; in dwc3_gadget_conndone_interrupt()
2928 ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_MODIFY); in dwc3_gadget_conndone_interrupt()
2930 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()