Lines Matching refs:hwep

355 static int add_td_to_list(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq,  in add_td_to_list()  argument
366 node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC, &node->dma); in add_td_to_list()
375 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) { in add_td_to_list()
376 u32 mul = hwreq->req.length / hwep->ep.maxpacket; in add_td_to_list()
379 || hwreq->req.length % hwep->ep.maxpacket) in add_td_to_list()
424 static int prepare_td_for_non_sg(struct ci_hw_ep *hwep, in prepare_td_for_non_sg() argument
432 ret = add_td_to_list(hwep, hwreq, 0, NULL); in prepare_td_for_non_sg()
448 ret = add_td_to_list(hwep, hwreq, count, NULL); in prepare_td_for_non_sg()
455 if (hwreq->req.zero && hwreq->req.length && hwep->dir == TX in prepare_td_for_non_sg()
456 && (hwreq->req.length % hwep->ep.maxpacket == 0)) { in prepare_td_for_non_sg()
457 ret = add_td_to_list(hwep, hwreq, 0, NULL); in prepare_td_for_non_sg()
465 static int prepare_td_per_sg(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq, in prepare_td_per_sg() argument
476 ret = add_td_to_list(hwep, hwreq, count, s); in prepare_td_per_sg()
505 static int prepare_td_for_sg(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) in prepare_td_for_sg() argument
513 dev_err(hwep->ci->dev, "not supported operation for sg\n"); in prepare_td_for_sg()
519 dev_err(hwep->ci->dev, "not page aligned sg buffer\n"); in prepare_td_for_sg()
527 ret = prepare_td_per_sg(hwep, hwreq, s); in prepare_td_for_sg()
548 static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) in _hardware_enqueue() argument
550 struct ci_hdrc *ci = hwep->ci; in _hardware_enqueue()
561 &hwreq->req, hwep->dir); in _hardware_enqueue()
566 ret = prepare_td_for_sg(hwep, hwreq); in _hardware_enqueue()
568 ret = prepare_td_for_non_sg(hwep, hwreq); in _hardware_enqueue()
581 trace_ci_prepare_td(hwep, hwreq, firstnode); in _hardware_enqueue()
588 if (!list_empty(&hwep->qh.queue)) { in _hardware_enqueue()
590 int n = hw_ep_bit(hwep->num, hwep->dir); in _hardware_enqueue()
595 hwreqprev = list_entry(hwep->qh.queue.prev, in _hardware_enqueue()
614 hwep->qh.ptr->td.next = cpu_to_le32(firstnode->dma); in _hardware_enqueue()
615 hwep->qh.ptr->td.token &= in _hardware_enqueue()
618 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == RX) { in _hardware_enqueue()
619 u32 mul = hwreq->req.length / hwep->ep.maxpacket; in _hardware_enqueue()
622 || hwreq->req.length % hwep->ep.maxpacket) in _hardware_enqueue()
624 hwep->qh.ptr->cap |= cpu_to_le32(mul << __ffs(QH_MULT)); in _hardware_enqueue()
627 ret = hw_ep_prime(ci, hwep->num, hwep->dir, in _hardware_enqueue()
628 hwep->type == USB_ENDPOINT_XFER_CONTROL); in _hardware_enqueue()
637 static void free_pending_td(struct ci_hw_ep *hwep) in free_pending_td() argument
639 struct td_node *pending = hwep->pending_td; in free_pending_td()
641 dma_pool_free(hwep->td_pool, pending->ptr, pending->dma); in free_pending_td()
642 hwep->pending_td = NULL; in free_pending_td()
646 static int reprime_dtd(struct ci_hdrc *ci, struct ci_hw_ep *hwep, in reprime_dtd() argument
649 hwep->qh.ptr->td.next = cpu_to_le32(node->dma); in reprime_dtd()
650 hwep->qh.ptr->td.token &= in reprime_dtd()
653 return hw_ep_prime(ci, hwep->num, hwep->dir, in reprime_dtd()
654 hwep->type == USB_ENDPOINT_XFER_CONTROL); in reprime_dtd()
664 static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) in _hardware_dequeue() argument
670 struct ci_hdrc *ci = hwep->ci; in _hardware_dequeue()
679 trace_ci_complete_td(hwep, hwreq, node); in _hardware_dequeue()
681 int n = hw_ep_bit(hwep->num, hwep->dir); in _hardware_dequeue()
685 reprime_dtd(ci, hwep, node); in _hardware_dequeue()
707 if (hwep->dir == TX) { in _hardware_dequeue()
717 if (hwep->pending_td) in _hardware_dequeue()
718 free_pending_td(hwep); in _hardware_dequeue()
720 hwep->pending_td = node; in _hardware_dequeue()
724 usb_gadget_unmap_request_by_dev(hwep->ci->dev->parent, in _hardware_dequeue()
725 &hwreq->req, hwep->dir); in _hardware_dequeue()
742 static int _ep_nuke(struct ci_hw_ep *hwep) in _ep_nuke() argument
743 __releases(hwep->lock) in _ep_nuke()
744 __acquires(hwep->lock) in _ep_nuke()
747 if (hwep == NULL) in _ep_nuke()
750 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in _ep_nuke()
752 while (!list_empty(&hwep->qh.queue)) { in _ep_nuke()
755 struct ci_hw_req *hwreq = list_entry(hwep->qh.queue.next, in _ep_nuke()
759 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in _ep_nuke()
769 spin_unlock(hwep->lock); in _ep_nuke()
770 usb_gadget_giveback_request(&hwep->ep, &hwreq->req); in _ep_nuke()
771 spin_lock(hwep->lock); in _ep_nuke()
775 if (hwep->pending_td) in _ep_nuke()
776 free_pending_td(hwep); in _ep_nuke()
783 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in _ep_set_halt() local
787 if (ep == NULL || hwep->ep.desc == NULL) in _ep_set_halt()
790 if (usb_endpoint_xfer_isoc(hwep->ep.desc)) in _ep_set_halt()
793 spin_lock_irqsave(hwep->lock, flags); in _ep_set_halt()
795 if (value && hwep->dir == TX && check_transfer && in _ep_set_halt()
796 !list_empty(&hwep->qh.queue) && in _ep_set_halt()
797 !usb_endpoint_xfer_control(hwep->ep.desc)) { in _ep_set_halt()
798 spin_unlock_irqrestore(hwep->lock, flags); in _ep_set_halt()
802 direction = hwep->dir; in _ep_set_halt()
804 retval |= hw_ep_set_halt(hwep->ci, hwep->num, hwep->dir, value); in _ep_set_halt()
807 hwep->wedge = 0; in _ep_set_halt()
809 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in _ep_set_halt()
810 hwep->dir = (hwep->dir == TX) ? RX : TX; in _ep_set_halt()
812 } while (hwep->dir != direction); in _ep_set_halt()
814 spin_unlock_irqrestore(hwep->lock, flags); in _ep_set_halt()
923 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in _ep_queue() local
925 struct ci_hdrc *ci = hwep->ci; in _ep_queue()
928 if (ep == NULL || req == NULL || hwep->ep.desc == NULL) in _ep_queue()
931 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) { in _ep_queue()
933 hwep = (ci->ep0_dir == RX) ? in _ep_queue()
935 if (!list_empty(&hwep->qh.queue)) { in _ep_queue()
936 _ep_nuke(hwep); in _ep_queue()
937 dev_warn(hwep->ci->dev, "endpoint ctrl %X nuked\n", in _ep_queue()
938 _usb_addr(hwep)); in _ep_queue()
942 if (usb_endpoint_xfer_isoc(hwep->ep.desc) && in _ep_queue()
943 hwreq->req.length > hwep->ep.mult * hwep->ep.maxpacket) { in _ep_queue()
944 dev_err(hwep->ci->dev, "request length too big for isochronous\n"); in _ep_queue()
950 dev_err(hwep->ci->dev, "request already in queue\n"); in _ep_queue()
958 retval = _hardware_enqueue(hwep, hwreq); in _ep_queue()
963 list_add_tail(&hwreq->queue, &hwep->qh.queue); in _ep_queue()
977 __releases(hwep->lock) in isr_get_status_response()
978 __acquires(hwep->lock) in isr_get_status_response()
980 struct ci_hw_ep *hwep = ci->ep0in; in isr_get_status_response() local
985 if (hwep == NULL || setup == NULL) in isr_get_status_response()
988 spin_unlock(hwep->lock); in isr_get_status_response()
989 req = usb_ep_alloc_request(&hwep->ep, gfp_flags); in isr_get_status_response()
990 spin_lock(hwep->lock); in isr_get_status_response()
1014 retval = _ep_queue(&hwep->ep, req, gfp_flags); in isr_get_status_response()
1023 spin_unlock(hwep->lock); in isr_get_status_response()
1024 usb_ep_free_request(&hwep->ep, req); in isr_get_status_response()
1025 spin_lock(hwep->lock); in isr_get_status_response()
1064 struct ci_hw_ep *hwep; in isr_setup_status_phase() local
1075 hwep = (ci->ep0_dir == TX) ? ci->ep0out : ci->ep0in; in isr_setup_status_phase()
1079 return _ep_queue(&hwep->ep, ci->status, GFP_ATOMIC); in isr_setup_status_phase()
1089 static int isr_tr_complete_low(struct ci_hw_ep *hwep) in isr_tr_complete_low() argument
1090 __releases(hwep->lock) in isr_tr_complete_low()
1091 __acquires(hwep->lock) in isr_tr_complete_low()
1094 struct ci_hw_ep *hweptemp = hwep; in isr_tr_complete_low()
1097 list_for_each_entry_safe(hwreq, hwreqtemp, &hwep->qh.queue, in isr_tr_complete_low()
1099 retval = _hardware_dequeue(hwep, hwreq); in isr_tr_complete_low()
1104 spin_unlock(hwep->lock); in isr_tr_complete_low()
1105 if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) && in isr_tr_complete_low()
1107 hweptemp = hwep->ci->ep0in; in isr_tr_complete_low()
1109 spin_lock(hwep->lock); in isr_tr_complete_low()
1136 struct ci_hw_ep *hwep = &ci->ci_hw_ep[0]; in isr_setup_packet_handler() local
1151 memcpy(&req, &hwep->qh.ptr->setup, sizeof(req)); in isr_setup_packet_handler()
1290 if (_ep_set_halt(&hwep->ep, 1, false)) in isr_setup_packet_handler()
1310 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; in isr_tr_complete_handler() local
1312 if (hwep->ep.desc == NULL) in isr_tr_complete_handler()
1316 err = isr_tr_complete_low(hwep); in isr_tr_complete_handler()
1317 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) { in isr_tr_complete_handler()
1322 if (_ep_set_halt(&hwep->ep, 1, false)) in isr_tr_complete_handler()
1348 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_enable() local
1356 spin_lock_irqsave(hwep->lock, flags); in ep_enable()
1360 if (!list_empty(&hwep->qh.queue)) { in ep_enable()
1361 dev_warn(hwep->ci->dev, "enabling a non-empty endpoint!\n"); in ep_enable()
1362 spin_unlock_irqrestore(hwep->lock, flags); in ep_enable()
1366 hwep->ep.desc = desc; in ep_enable()
1368 hwep->dir = usb_endpoint_dir_in(desc) ? TX : RX; in ep_enable()
1369 hwep->num = usb_endpoint_num(desc); in ep_enable()
1370 hwep->type = usb_endpoint_type(desc); in ep_enable()
1372 hwep->ep.maxpacket = usb_endpoint_maxp(desc); in ep_enable()
1373 hwep->ep.mult = usb_endpoint_maxp_mult(desc); in ep_enable()
1375 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in ep_enable()
1379 cap |= (hwep->ep.maxpacket << __ffs(QH_MAX_PKT)) & QH_MAX_PKT; in ep_enable()
1384 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) in ep_enable()
1387 hwep->qh.ptr->cap = cpu_to_le32(cap); in ep_enable()
1389 hwep->qh.ptr->td.next |= cpu_to_le32(TD_TERMINATE); /* needed? */ in ep_enable()
1391 if (hwep->num != 0 && hwep->type == USB_ENDPOINT_XFER_CONTROL) { in ep_enable()
1392 dev_err(hwep->ci->dev, "Set control xfer at non-ep0\n"); in ep_enable()
1400 if (hwep->num) in ep_enable()
1401 retval |= hw_ep_enable(hwep->ci, hwep->num, hwep->dir, in ep_enable()
1402 hwep->type); in ep_enable()
1404 spin_unlock_irqrestore(hwep->lock, flags); in ep_enable()
1415 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_disable() local
1421 else if (hwep->ep.desc == NULL) in ep_disable()
1424 spin_lock_irqsave(hwep->lock, flags); in ep_disable()
1425 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_disable()
1426 spin_unlock_irqrestore(hwep->lock, flags); in ep_disable()
1432 direction = hwep->dir; in ep_disable()
1434 retval |= _ep_nuke(hwep); in ep_disable()
1435 retval |= hw_ep_disable(hwep->ci, hwep->num, hwep->dir); in ep_disable()
1437 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in ep_disable()
1438 hwep->dir = (hwep->dir == TX) ? RX : TX; in ep_disable()
1440 } while (hwep->dir != direction); in ep_disable()
1442 hwep->ep.desc = NULL; in ep_disable()
1444 spin_unlock_irqrestore(hwep->lock, flags); in ep_disable()
1476 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_free_request() local
1484 dev_err(hwep->ci->dev, "freeing queued request\n"); in ep_free_request()
1488 spin_lock_irqsave(hwep->lock, flags); in ep_free_request()
1491 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in ep_free_request()
1499 spin_unlock_irqrestore(hwep->lock, flags); in ep_free_request()
1510 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_queue() local
1514 if (ep == NULL || req == NULL || hwep->ep.desc == NULL) in ep_queue()
1517 spin_lock_irqsave(hwep->lock, flags); in ep_queue()
1518 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_queue()
1519 spin_unlock_irqrestore(hwep->lock, flags); in ep_queue()
1523 spin_unlock_irqrestore(hwep->lock, flags); in ep_queue()
1534 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_dequeue() local
1540 hwep->ep.desc == NULL || list_empty(&hwreq->queue) || in ep_dequeue()
1541 list_empty(&hwep->qh.queue)) in ep_dequeue()
1544 spin_lock_irqsave(hwep->lock, flags); in ep_dequeue()
1545 if (hwep->ci->gadget.speed != USB_SPEED_UNKNOWN) in ep_dequeue()
1546 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in ep_dequeue()
1549 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in ep_dequeue()
1557 usb_gadget_unmap_request(&hwep->ci->gadget, req, hwep->dir); in ep_dequeue()
1562 spin_unlock(hwep->lock); in ep_dequeue()
1563 usb_gadget_giveback_request(&hwep->ep, &hwreq->req); in ep_dequeue()
1564 spin_lock(hwep->lock); in ep_dequeue()
1567 spin_unlock_irqrestore(hwep->lock, flags); in ep_dequeue()
1588 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_set_wedge() local
1591 if (ep == NULL || hwep->ep.desc == NULL) in ep_set_wedge()
1594 spin_lock_irqsave(hwep->lock, flags); in ep_set_wedge()
1595 hwep->wedge = 1; in ep_set_wedge()
1596 spin_unlock_irqrestore(hwep->lock, flags); in ep_set_wedge()
1608 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_fifo_flush() local
1612 dev_err(hwep->ci->dev, "%02X: -EINVAL\n", _usb_addr(hwep)); in ep_fifo_flush()
1616 spin_lock_irqsave(hwep->lock, flags); in ep_fifo_flush()
1617 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_fifo_flush()
1618 spin_unlock_irqrestore(hwep->lock, flags); in ep_fifo_flush()
1622 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in ep_fifo_flush()
1624 spin_unlock_irqrestore(hwep->lock, flags); in ep_fifo_flush()
1740 struct ci_hw_ep *hwep = ci->ep0in; in ci_udc_selfpowered() local
1743 spin_lock_irqsave(hwep->lock, flags); in ci_udc_selfpowered()
1745 spin_unlock_irqrestore(hwep->lock, flags); in ci_udc_selfpowered()
1819 struct ci_hw_ep *hwep = &ci->ci_hw_ep[k]; in init_eps() local
1821 scnprintf(hwep->name, sizeof(hwep->name), "ep%i%s", i, in init_eps()
1824 hwep->ci = ci; in init_eps()
1825 hwep->lock = &ci->lock; in init_eps()
1826 hwep->td_pool = ci->td_pool; in init_eps()
1828 hwep->ep.name = hwep->name; in init_eps()
1829 hwep->ep.ops = &usb_ep_ops; in init_eps()
1832 hwep->ep.caps.type_control = true; in init_eps()
1834 hwep->ep.caps.type_iso = true; in init_eps()
1835 hwep->ep.caps.type_bulk = true; in init_eps()
1836 hwep->ep.caps.type_int = true; in init_eps()
1840 hwep->ep.caps.dir_in = true; in init_eps()
1842 hwep->ep.caps.dir_out = true; in init_eps()
1849 usb_ep_set_maxpacket_limit(&hwep->ep, (unsigned short)~0); in init_eps()
1851 INIT_LIST_HEAD(&hwep->qh.queue); in init_eps()
1852 hwep->qh.ptr = dma_pool_zalloc(ci->qh_pool, GFP_KERNEL, in init_eps()
1853 &hwep->qh.dma); in init_eps()
1854 if (hwep->qh.ptr == NULL) in init_eps()
1863 ci->ep0out = hwep; in init_eps()
1865 ci->ep0in = hwep; in init_eps()
1867 usb_ep_set_maxpacket_limit(&hwep->ep, CTRL_PAYLOAD_MAX); in init_eps()
1871 list_add_tail(&hwep->ep.ep_list, &ci->gadget.ep_list); in init_eps()
1882 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; in destroy_eps() local
1884 if (hwep->pending_td) in destroy_eps()
1885 free_pending_td(hwep); in destroy_eps()
1886 dma_pool_free(ci->qh_pool, hwep->qh.ptr, hwep->qh.dma); in destroy_eps()