Lines Matching +full:ignore +full:- +full:power +full:- +full:on +full:- +full:sel

1 // SPDX-License-Identifier: GPL-2.0
3 * ep0.c - DesignWare USB3 DRD Controller Endpoint 0 Handling
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
19 #include <linux/dma-mapping.h>
40 dwc = dep->dwc; in dwc3_ep0_prepare_one_trb()
41 trb = &dwc->ep0_trb[dep->trb_enqueue]; in dwc3_ep0_prepare_one_trb()
44 dep->trb_enqueue++; in dwc3_ep0_prepare_one_trb()
46 trb->bpl = lower_32_bits(buf_dma); in dwc3_ep0_prepare_one_trb()
47 trb->bph = upper_32_bits(buf_dma); in dwc3_ep0_prepare_one_trb()
48 trb->size = len; in dwc3_ep0_prepare_one_trb()
49 trb->ctrl = type; in dwc3_ep0_prepare_one_trb()
51 trb->ctrl |= (DWC3_TRB_CTRL_HWO in dwc3_ep0_prepare_one_trb()
55 trb->ctrl |= DWC3_TRB_CTRL_CHN; in dwc3_ep0_prepare_one_trb()
57 trb->ctrl |= (DWC3_TRB_CTRL_IOC in dwc3_ep0_prepare_one_trb()
69 if (dep->flags & DWC3_EP_TRANSFER_STARTED) in dwc3_ep0_start_trans()
72 dwc = dep->dwc; in dwc3_ep0_start_trans()
75 params.param0 = upper_32_bits(dwc->ep0_trb_addr); in dwc3_ep0_start_trans()
76 params.param1 = lower_32_bits(dwc->ep0_trb_addr); in dwc3_ep0_start_trans()
82 dwc->ep0_next_event = DWC3_EP0_COMPLETE; in dwc3_ep0_start_trans()
90 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep0_queue()
92 req->request.actual = 0; in __dwc3_gadget_ep0_queue()
93 req->request.status = -EINPROGRESS; in __dwc3_gadget_ep0_queue()
94 req->epnum = dep->number; in __dwc3_gadget_ep0_queue()
96 list_add_tail(&req->list, &dep->pending_list); in __dwc3_gadget_ep0_queue()
100 * before we get a Transfer Not Ready event on this endpoint. in __dwc3_gadget_ep0_queue()
107 if (dep->flags & DWC3_EP_PENDING_REQUEST) { in __dwc3_gadget_ep0_queue()
110 direction = !!(dep->flags & DWC3_EP0_DIR_IN); in __dwc3_gadget_ep0_queue()
112 if (dwc->ep0state != EP0_DATA_PHASE) { in __dwc3_gadget_ep0_queue()
113 dev_WARN(dwc->dev, "Unexpected pending request\n"); in __dwc3_gadget_ep0_queue()
117 __dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req); in __dwc3_gadget_ep0_queue()
119 dep->flags &= ~(DWC3_EP_PENDING_REQUEST | in __dwc3_gadget_ep0_queue()
129 if (dwc->delayed_status) { in __dwc3_gadget_ep0_queue()
132 direction = !dwc->ep0_expect_in; in __dwc3_gadget_ep0_queue()
133 dwc->delayed_status = false; in __dwc3_gadget_ep0_queue()
134 usb_gadget_set_state(dwc->gadget, USB_STATE_CONFIGURED); in __dwc3_gadget_ep0_queue()
136 if (dwc->ep0state == EP0_STATUS_PHASE) in __dwc3_gadget_ep0_queue()
137 __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); in __dwc3_gadget_ep0_queue()
148 * the DATA phase. Such cases happen at least on TD.7.6 of the Link in __dwc3_gadget_ep0_queue()
151 * The problem surfaces due to the fact that in case of back-to-back in __dwc3_gadget_ep0_queue()
155 * By looking at tables 9-13 and 9-14 of the Databook, we can see that in __dwc3_gadget_ep0_queue()
166 * model of control transfers and support on-demand transfers only for in __dwc3_gadget_ep0_queue()
171 * If we're actually in a 2-stage transfer, we will wait for in __dwc3_gadget_ep0_queue()
174 if (dwc->three_stage_setup) { in __dwc3_gadget_ep0_queue()
177 direction = dwc->ep0_expect_in; in __dwc3_gadget_ep0_queue()
178 dwc->ep0state = EP0_DATA_PHASE; in __dwc3_gadget_ep0_queue()
180 __dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req); in __dwc3_gadget_ep0_queue()
182 dep->flags &= ~DWC3_EP0_DIR_IN; in __dwc3_gadget_ep0_queue()
193 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep0_queue()
199 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep0_queue()
200 if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) { in dwc3_gadget_ep0_queue()
201 dev_err(dwc->dev, "%s: can't queue to disabled endpoint\n", in dwc3_gadget_ep0_queue()
202 dep->name); in dwc3_gadget_ep0_queue()
203 ret = -ESHUTDOWN; in dwc3_gadget_ep0_queue()
208 if (!list_empty(&dep->pending_list)) { in dwc3_gadget_ep0_queue()
209 ret = -EBUSY; in dwc3_gadget_ep0_queue()
216 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep0_queue()
226 dep = dwc->eps[1]; in dwc3_ep0_stall_and_restart()
227 dep->flags = DWC3_EP_ENABLED; in dwc3_ep0_stall_and_restart()
229 /* stall is always issued on EP0 */ in dwc3_ep0_stall_and_restart()
230 dep = dwc->eps[0]; in dwc3_ep0_stall_and_restart()
232 dep->flags = DWC3_EP_ENABLED; in dwc3_ep0_stall_and_restart()
233 dwc->delayed_status = false; in dwc3_ep0_stall_and_restart()
235 if (!list_empty(&dep->pending_list)) { in dwc3_ep0_stall_and_restart()
238 req = next_request(&dep->pending_list); in dwc3_ep0_stall_and_restart()
239 dwc3_gadget_giveback(dep, req, -ECONNRESET); in dwc3_ep0_stall_and_restart()
242 dwc->eps[0]->trb_enqueue = 0; in dwc3_ep0_stall_and_restart()
243 dwc->eps[1]->trb_enqueue = 0; in dwc3_ep0_stall_and_restart()
244 dwc->ep0state = EP0_SETUP_PHASE; in dwc3_ep0_stall_and_restart()
251 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep0_set_halt()
261 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep0_set_halt()
265 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep0_set_halt()
267 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep0_set_halt()
278 complete(&dwc->ep0_in_setup); in dwc3_ep0_out_start()
280 dep = dwc->eps[0]; in dwc3_ep0_out_start()
281 dwc3_ep0_prepare_one_trb(dep, dwc->ep0_trb_addr, 8, in dwc3_ep0_out_start()
288 dwc3_ep = dwc->eps[i]; in dwc3_ep0_out_start()
292 if (!(dwc3_ep->flags & DWC3_EP_DELAY_STOP)) in dwc3_ep0_out_start()
295 dwc3_ep->flags &= ~DWC3_EP_DELAY_STOP; in dwc3_ep0_out_start()
296 if (dwc->connected) in dwc3_ep0_out_start()
299 dwc3_remove_requests(dwc, dwc3_ep, -ESHUTDOWN); in dwc3_ep0_out_start()
313 dep = dwc->eps[epnum]; in dwc3_wIndex_to_dep()
317 if (dep->flags & DWC3_EP_ENABLED) in dwc3_wIndex_to_dep()
340 value = le16_to_cpu(ctrl->wValue); in dwc3_ep0_handle_status()
342 return -EINVAL; in dwc3_ep0_handle_status()
344 recip = ctrl->bRequestType & USB_RECIP_MASK; in dwc3_ep0_handle_status()
350 usb_status |= dwc->gadget->is_selfpowered; in dwc3_ep0_handle_status()
352 if ((dwc->speed == DWC3_DSTS_SUPERSPEED) || in dwc3_ep0_handle_status()
353 (dwc->speed == DWC3_DSTS_SUPERSPEED_PLUS)) { in dwc3_ep0_handle_status()
354 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_handle_status()
371 dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex); in dwc3_ep0_handle_status()
373 return -EINVAL; in dwc3_ep0_handle_status()
375 if (dep->flags & DWC3_EP_STALL) in dwc3_ep0_handle_status()
379 return -EINVAL; in dwc3_ep0_handle_status()
382 response_pkt = (__le16 *) dwc->setup_buf; in dwc3_ep0_handle_status()
385 dep = dwc->eps[0]; in dwc3_ep0_handle_status()
386 dwc->ep0_usb_req.dep = dep; in dwc3_ep0_handle_status()
387 dwc->ep0_usb_req.request.length = sizeof(*response_pkt); in dwc3_ep0_handle_status()
388 dwc->ep0_usb_req.request.buf = dwc->setup_buf; in dwc3_ep0_handle_status()
389 dwc->ep0_usb_req.request.complete = dwc3_ep0_status_cmpl; in dwc3_ep0_handle_status()
391 return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); in dwc3_ep0_handle_status()
400 return -EINVAL; in dwc3_ep0_handle_u1()
401 if ((dwc->speed != DWC3_DSTS_SUPERSPEED) && in dwc3_ep0_handle_u1()
402 (dwc->speed != DWC3_DSTS_SUPERSPEED_PLUS)) in dwc3_ep0_handle_u1()
403 return -EINVAL; in dwc3_ep0_handle_u1()
404 if (set && dwc->dis_u1_entry_quirk) in dwc3_ep0_handle_u1()
405 return -EINVAL; in dwc3_ep0_handle_u1()
407 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_handle_u1()
412 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_ep0_handle_u1()
424 return -EINVAL; in dwc3_ep0_handle_u2()
425 if ((dwc->speed != DWC3_DSTS_SUPERSPEED) && in dwc3_ep0_handle_u2()
426 (dwc->speed != DWC3_DSTS_SUPERSPEED_PLUS)) in dwc3_ep0_handle_u2()
427 return -EINVAL; in dwc3_ep0_handle_u2()
428 if (set && dwc->dis_u2_entry_quirk) in dwc3_ep0_handle_u2()
429 return -EINVAL; in dwc3_ep0_handle_u2()
431 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_handle_u2()
436 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_ep0_handle_u2()
445 return -EINVAL; in dwc3_ep0_handle_test()
447 return -EINVAL; in dwc3_ep0_handle_test()
455 dwc->test_mode_nr = wIndex >> 8; in dwc3_ep0_handle_test()
456 dwc->test_mode = true; in dwc3_ep0_handle_test()
459 return -EINVAL; in dwc3_ep0_handle_test()
473 wValue = le16_to_cpu(ctrl->wValue); in dwc3_ep0_handle_device()
474 wIndex = le16_to_cpu(ctrl->wIndex); in dwc3_ep0_handle_device()
475 state = dwc->gadget->state; in dwc3_ep0_handle_device()
491 ret = -EINVAL; in dwc3_ep0_handle_device()
497 ret = -EINVAL; in dwc3_ep0_handle_device()
509 wValue = le16_to_cpu(ctrl->wValue); in dwc3_ep0_handle_intf()
514 * REVISIT: Ideally we would enable some low power mode here, in dwc3_ep0_handle_intf()
522 ret = -EINVAL; in dwc3_ep0_handle_intf()
535 wValue = le16_to_cpu(ctrl->wValue); in dwc3_ep0_handle_endpoint()
539 dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex); in dwc3_ep0_handle_endpoint()
541 return -EINVAL; in dwc3_ep0_handle_endpoint()
543 if (set == 0 && (dep->flags & DWC3_EP_WEDGE)) in dwc3_ep0_handle_endpoint()
548 return -EINVAL; in dwc3_ep0_handle_endpoint()
551 if (!set && (dep->flags & DWC3_EP_END_TRANSFER_PENDING)) in dwc3_ep0_handle_endpoint()
556 return -EINVAL; in dwc3_ep0_handle_endpoint()
568 recip = ctrl->bRequestType & USB_RECIP_MASK; in dwc3_ep0_handle_feature()
581 ret = -EINVAL; in dwc3_ep0_handle_feature()
589 enum usb_device_state state = dwc->gadget->state; in dwc3_ep0_set_address()
593 addr = le16_to_cpu(ctrl->wValue); in dwc3_ep0_set_address()
595 dev_err(dwc->dev, "invalid device address %d\n", addr); in dwc3_ep0_set_address()
596 return -EINVAL; in dwc3_ep0_set_address()
600 dev_err(dwc->dev, "can't SetAddress() from Configured State\n"); in dwc3_ep0_set_address()
601 return -EINVAL; in dwc3_ep0_set_address()
604 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_ep0_set_address()
607 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_ep0_set_address()
610 usb_gadget_set_state(dwc->gadget, USB_STATE_ADDRESS); in dwc3_ep0_set_address()
612 usb_gadget_set_state(dwc->gadget, USB_STATE_DEFAULT); in dwc3_ep0_set_address()
619 int ret = -EINVAL; in dwc3_ep0_delegate_req()
621 if (dwc->async_callbacks) { in dwc3_ep0_delegate_req()
622 spin_unlock(&dwc->lock); in dwc3_ep0_delegate_req()
623 ret = dwc->gadget_driver->setup(dwc->gadget, ctrl); in dwc3_ep0_delegate_req()
624 spin_lock(&dwc->lock); in dwc3_ep0_delegate_req()
631 enum usb_device_state state = dwc->gadget->state; in dwc3_ep0_set_config()
636 cfg = le16_to_cpu(ctrl->wValue); in dwc3_ep0_set_config()
640 return -EINVAL; in dwc3_ep0_set_config()
653 * to change the state on the next usb_ep_queue() in dwc3_ep0_set_config()
656 usb_gadget_set_state(dwc->gadget, in dwc3_ep0_set_config()
663 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_set_config()
664 if (!dwc->dis_u1_entry_quirk) in dwc3_ep0_set_config()
666 if (!dwc->dis_u2_entry_quirk) in dwc3_ep0_set_config()
668 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_ep0_set_config()
675 usb_gadget_set_state(dwc->gadget, in dwc3_ep0_set_config()
679 ret = -EINVAL; in dwc3_ep0_set_config()
687 struct dwc3 *dwc = dep->dwc; in dwc3_ep0_set_sel_cmpl()
701 memcpy(&timing, req->buf, sizeof(timing)); in dwc3_ep0_set_sel_cmpl()
703 dwc->u1sel = timing.u1sel; in dwc3_ep0_set_sel_cmpl()
704 dwc->u1pel = timing.u1pel; in dwc3_ep0_set_sel_cmpl()
705 dwc->u2sel = le16_to_cpu(timing.u2sel); in dwc3_ep0_set_sel_cmpl()
706 dwc->u2pel = le16_to_cpu(timing.u2pel); in dwc3_ep0_set_sel_cmpl()
708 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_set_sel_cmpl()
710 param = dwc->u2pel; in dwc3_ep0_set_sel_cmpl()
712 param = dwc->u1pel; in dwc3_ep0_set_sel_cmpl()
722 /* now that we have the time, issue DGCMD Set Sel */ in dwc3_ep0_set_sel_cmpl()
731 enum usb_device_state state = dwc->gadget->state; in dwc3_ep0_set_sel()
735 return -EINVAL; in dwc3_ep0_set_sel()
737 wLength = le16_to_cpu(ctrl->wLength); in dwc3_ep0_set_sel()
740 dev_err(dwc->dev, "Set SEL should be 6 bytes, got %d\n", in dwc3_ep0_set_sel()
742 return -EINVAL; in dwc3_ep0_set_sel()
746 * To handle Set SEL we need to receive 6 bytes from Host. So let's in dwc3_ep0_set_sel()
749 * Remember, though, this controller can't handle non-wMaxPacketSize in dwc3_ep0_set_sel()
750 * aligned transfers on the OUT direction, so we queue a request for in dwc3_ep0_set_sel()
753 dep = dwc->eps[0]; in dwc3_ep0_set_sel()
754 dwc->ep0_usb_req.dep = dep; in dwc3_ep0_set_sel()
755 dwc->ep0_usb_req.request.length = dep->endpoint.maxpacket; in dwc3_ep0_set_sel()
756 dwc->ep0_usb_req.request.buf = dwc->setup_buf; in dwc3_ep0_set_sel()
757 dwc->ep0_usb_req.request.complete = dwc3_ep0_set_sel_cmpl; in dwc3_ep0_set_sel()
759 return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); in dwc3_ep0_set_sel()
768 wValue = le16_to_cpu(ctrl->wValue); in dwc3_ep0_set_isoch_delay()
769 wLength = le16_to_cpu(ctrl->wLength); in dwc3_ep0_set_isoch_delay()
770 wIndex = le16_to_cpu(ctrl->wIndex); in dwc3_ep0_set_isoch_delay()
773 return -EINVAL; in dwc3_ep0_set_isoch_delay()
775 dwc->gadget->isoch_delay = wValue; in dwc3_ep0_set_isoch_delay()
784 switch (ctrl->bRequest) { in dwc3_ep0_std_request()
817 struct usb_ctrlrequest *ctrl = (void *) dwc->ep0_trb; in dwc3_ep0_inspect_setup()
818 int ret = -EINVAL; in dwc3_ep0_inspect_setup()
821 if (!dwc->gadget_driver || !dwc->softconnect || !dwc->connected) in dwc3_ep0_inspect_setup()
826 len = le16_to_cpu(ctrl->wLength); in dwc3_ep0_inspect_setup()
828 dwc->three_stage_setup = false; in dwc3_ep0_inspect_setup()
829 dwc->ep0_expect_in = false; in dwc3_ep0_inspect_setup()
830 dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS; in dwc3_ep0_inspect_setup()
832 dwc->three_stage_setup = true; in dwc3_ep0_inspect_setup()
833 dwc->ep0_expect_in = !!(ctrl->bRequestType & USB_DIR_IN); in dwc3_ep0_inspect_setup()
834 dwc->ep0_next_event = DWC3_EP0_NRDY_DATA; in dwc3_ep0_inspect_setup()
837 if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) in dwc3_ep0_inspect_setup()
843 dwc->delayed_status = true; in dwc3_ep0_inspect_setup()
862 epnum = event->endpoint_number; in dwc3_ep0_complete_data()
863 ep0 = dwc->eps[0]; in dwc3_ep0_complete_data()
865 dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS; in dwc3_ep0_complete_data()
866 trb = dwc->ep0_trb; in dwc3_ep0_complete_data()
869 r = next_request(&ep0->pending_list); in dwc3_ep0_complete_data()
873 status = DWC3_TRB_SIZE_TRBSTS(trb->size); in dwc3_ep0_complete_data()
875 dwc->setup_packet_pending = true; in dwc3_ep0_complete_data()
877 dwc3_gadget_giveback(ep0, r, -ECONNRESET); in dwc3_ep0_complete_data()
882 ur = &r->request; in dwc3_ep0_complete_data()
884 length = trb->size & DWC3_TRB_SIZE_MASK; in dwc3_ep0_complete_data()
885 transferred = ur->length - length; in dwc3_ep0_complete_data()
886 ur->actual += transferred; in dwc3_ep0_complete_data()
888 if ((IS_ALIGNED(ur->length, ep0->endpoint.maxpacket) && in dwc3_ep0_complete_data()
889 ur->length && ur->zero) || dwc->ep0_bounced) { in dwc3_ep0_complete_data()
891 trb->ctrl &= ~DWC3_TRB_CTRL_HWO; in dwc3_ep0_complete_data()
894 if (r->direction) in dwc3_ep0_complete_data()
895 dwc->eps[1]->trb_enqueue = 0; in dwc3_ep0_complete_data()
897 dwc->eps[0]->trb_enqueue = 0; in dwc3_ep0_complete_data()
899 dwc->ep0_bounced = false; in dwc3_ep0_complete_data()
902 if ((epnum & 1) && ur->actual < ur->length) in dwc3_ep0_complete_data()
916 dep = dwc->eps[0]; in dwc3_ep0_complete_status()
917 trb = dwc->ep0_trb; in dwc3_ep0_complete_status()
921 if (!list_empty(&dep->pending_list)) { in dwc3_ep0_complete_status()
922 r = next_request(&dep->pending_list); in dwc3_ep0_complete_status()
927 if (dwc->test_mode) { in dwc3_ep0_complete_status()
930 ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr); in dwc3_ep0_complete_status()
932 dev_err(dwc->dev, "invalid test #%d\n", in dwc3_ep0_complete_status()
933 dwc->test_mode_nr); in dwc3_ep0_complete_status()
939 status = DWC3_TRB_SIZE_TRBSTS(trb->size); in dwc3_ep0_complete_status()
941 dwc->setup_packet_pending = true; in dwc3_ep0_complete_status()
943 dwc->ep0state = EP0_SETUP_PHASE; in dwc3_ep0_complete_status()
950 struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; in dwc3_ep0_xfer_complete()
952 dep->flags &= ~DWC3_EP_TRANSFER_STARTED; in dwc3_ep0_xfer_complete()
953 dep->resource_index = 0; in dwc3_ep0_xfer_complete()
954 dwc->setup_packet_pending = false; in dwc3_ep0_xfer_complete()
956 switch (dwc->ep0state) { in dwc3_ep0_xfer_complete()
969 WARN(true, "UNKNOWN ep0state %d\n", dwc->ep0state); in dwc3_ep0_xfer_complete()
979 req->direction = !!dep->number; in __dwc3_ep0_do_control_data()
981 if (req->request.length == 0) { in __dwc3_ep0_do_control_data()
982 if (!req->direction) in __dwc3_ep0_do_control_data()
983 trb_length = dep->endpoint.maxpacket; in __dwc3_ep0_do_control_data()
985 dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, trb_length, in __dwc3_ep0_do_control_data()
988 } else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket) in __dwc3_ep0_do_control_data()
989 && (dep->number == 0)) { in __dwc3_ep0_do_control_data()
993 ret = usb_gadget_map_request_by_dev(dwc->sysdev, in __dwc3_ep0_do_control_data()
994 &req->request, dep->number); in __dwc3_ep0_do_control_data()
998 maxpacket = dep->endpoint.maxpacket; in __dwc3_ep0_do_control_data()
999 rem = req->request.length % maxpacket; in __dwc3_ep0_do_control_data()
1000 dwc->ep0_bounced = true; in __dwc3_ep0_do_control_data()
1003 dwc3_ep0_prepare_one_trb(dep, req->request.dma, in __dwc3_ep0_do_control_data()
1004 req->request.length, in __dwc3_ep0_do_control_data()
1008 req->trb = &dwc->ep0_trb[dep->trb_enqueue - 1]; in __dwc3_ep0_do_control_data()
1011 dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, in __dwc3_ep0_do_control_data()
1012 maxpacket - rem, in __dwc3_ep0_do_control_data()
1016 } else if (IS_ALIGNED(req->request.length, dep->endpoint.maxpacket) && in __dwc3_ep0_do_control_data()
1017 req->request.length && req->request.zero) { in __dwc3_ep0_do_control_data()
1019 ret = usb_gadget_map_request_by_dev(dwc->sysdev, in __dwc3_ep0_do_control_data()
1020 &req->request, dep->number); in __dwc3_ep0_do_control_data()
1025 dwc3_ep0_prepare_one_trb(dep, req->request.dma, in __dwc3_ep0_do_control_data()
1026 req->request.length, in __dwc3_ep0_do_control_data()
1030 req->trb = &dwc->ep0_trb[dep->trb_enqueue - 1]; in __dwc3_ep0_do_control_data()
1032 if (!req->direction) in __dwc3_ep0_do_control_data()
1033 trb_length = dep->endpoint.maxpacket; in __dwc3_ep0_do_control_data()
1036 dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, in __dwc3_ep0_do_control_data()
1041 ret = usb_gadget_map_request_by_dev(dwc->sysdev, in __dwc3_ep0_do_control_data()
1042 &req->request, dep->number); in __dwc3_ep0_do_control_data()
1046 dwc3_ep0_prepare_one_trb(dep, req->request.dma, in __dwc3_ep0_do_control_data()
1047 req->request.length, DWC3_TRBCTL_CONTROL_DATA, in __dwc3_ep0_do_control_data()
1050 req->trb = &dwc->ep0_trb[dep->trb_enqueue]; in __dwc3_ep0_do_control_data()
1060 struct dwc3 *dwc = dep->dwc; in dwc3_ep0_start_control_status()
1063 type = dwc->three_stage_setup ? DWC3_TRBCTL_CONTROL_STATUS3 in dwc3_ep0_start_control_status()
1066 dwc3_ep0_prepare_one_trb(dep, dwc->ep0_trb_addr, 0, type, false); in dwc3_ep0_start_control_status()
1078 struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; in dwc3_ep0_do_control_status()
1085 unsigned int direction = !dwc->ep0_expect_in; in dwc3_ep0_send_delayed_status()
1087 dwc->delayed_status = false; in dwc3_ep0_send_delayed_status()
1088 dwc->clear_stall_protocol = 0; in dwc3_ep0_send_delayed_status()
1090 if (dwc->ep0state != EP0_STATUS_PHASE) in dwc3_ep0_send_delayed_status()
1093 __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); in dwc3_ep0_send_delayed_status()
1103 * For status/DATA OUT stage, TRB will be queued on ep0 out in dwc3_ep0_end_control_data()
1107 if (!dep->resource_index && dep->number) in dwc3_ep0_end_control_data()
1112 cmd |= DWC3_DEPCMD_PARAM(dep->resource_index); in dwc3_ep0_end_control_data()
1116 dep->resource_index = 0; in dwc3_ep0_end_control_data()
1122 switch (event->status) { in dwc3_ep0_xfernotready()
1124 if (!dwc->softconnect || !dwc->connected) in dwc3_ep0_xfernotready()
1128 * if we receive a XferNotReady(DATA) we will ignore it, unless in dwc3_ep0_xfernotready()
1132 * Phase we already have started and issue SetStall on the in dwc3_ep0_xfernotready()
1135 if (dwc->ep0_expect_in != event->endpoint_number) { in dwc3_ep0_xfernotready()
1136 struct dwc3_ep *dep = dwc->eps[dwc->ep0_expect_in]; in dwc3_ep0_xfernotready()
1138 dev_err(dwc->dev, "unexpected direction for Data Phase\n"); in dwc3_ep0_xfernotready()
1147 if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) in dwc3_ep0_xfernotready()
1150 if (dwc->setup_packet_pending) { in dwc3_ep0_xfernotready()
1155 dwc->ep0state = EP0_STATUS_PHASE; in dwc3_ep0_xfernotready()
1157 if (dwc->delayed_status) { in dwc3_ep0_xfernotready()
1158 struct dwc3_ep *dep = dwc->eps[0]; in dwc3_ep0_xfernotready()
1160 WARN_ON_ONCE(event->endpoint_number != 1); in dwc3_ep0_xfernotready()
1166 if (!list_empty(&dep->pending_list)) { in dwc3_ep0_xfernotready()
1167 dwc->delayed_status = false; in dwc3_ep0_xfernotready()
1168 usb_gadget_set_state(dwc->gadget, in dwc3_ep0_xfernotready()
1183 struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; in dwc3_ep0_interrupt()
1186 switch (event->endpoint_event) { in dwc3_ep0_interrupt()
1200 cmd = DEPEVT_PARAMETER_CMD(event->parameters); in dwc3_ep0_interrupt()
1203 dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING; in dwc3_ep0_interrupt()
1204 dep->flags &= ~DWC3_EP_TRANSFER_STARTED; in dwc3_ep0_interrupt()