Lines Matching refs:hwep

354 static int add_td_to_list(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq,  in add_td_to_list()  argument
365 node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC, &node->dma); in add_td_to_list()
374 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) { in add_td_to_list()
375 u32 mul = hwreq->req.length / hwep->ep.maxpacket; in add_td_to_list()
378 || hwreq->req.length % hwep->ep.maxpacket) in add_td_to_list()
423 static int prepare_td_for_non_sg(struct ci_hw_ep *hwep, in prepare_td_for_non_sg() argument
431 ret = add_td_to_list(hwep, hwreq, 0, NULL); in prepare_td_for_non_sg()
447 ret = add_td_to_list(hwep, hwreq, count, NULL); in prepare_td_for_non_sg()
454 if (hwreq->req.zero && hwreq->req.length && hwep->dir == TX in prepare_td_for_non_sg()
455 && (hwreq->req.length % hwep->ep.maxpacket == 0)) { in prepare_td_for_non_sg()
456 ret = add_td_to_list(hwep, hwreq, 0, NULL); in prepare_td_for_non_sg()
464 static int prepare_td_per_sg(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq, in prepare_td_per_sg() argument
475 ret = add_td_to_list(hwep, hwreq, count, s); in prepare_td_per_sg()
504 static int prepare_td_for_sg(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) in prepare_td_for_sg() argument
512 dev_err(hwep->ci->dev, "not supported operation for sg\n"); in prepare_td_for_sg()
518 dev_err(hwep->ci->dev, "not page aligned sg buffer\n"); in prepare_td_for_sg()
526 ret = prepare_td_per_sg(hwep, hwreq, s); in prepare_td_for_sg()
547 static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) in _hardware_enqueue() argument
549 struct ci_hdrc *ci = hwep->ci; in _hardware_enqueue()
560 &hwreq->req, hwep->dir); in _hardware_enqueue()
565 ret = prepare_td_for_sg(hwep, hwreq); in _hardware_enqueue()
567 ret = prepare_td_for_non_sg(hwep, hwreq); in _hardware_enqueue()
583 if (!list_empty(&hwep->qh.queue)) { in _hardware_enqueue()
585 int n = hw_ep_bit(hwep->num, hwep->dir); in _hardware_enqueue()
590 hwreqprev = list_entry(hwep->qh.queue.prev, in _hardware_enqueue()
609 hwep->qh.ptr->td.next = cpu_to_le32(firstnode->dma); in _hardware_enqueue()
610 hwep->qh.ptr->td.token &= in _hardware_enqueue()
613 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == RX) { in _hardware_enqueue()
614 u32 mul = hwreq->req.length / hwep->ep.maxpacket; in _hardware_enqueue()
617 || hwreq->req.length % hwep->ep.maxpacket) in _hardware_enqueue()
619 hwep->qh.ptr->cap |= cpu_to_le32(mul << __ffs(QH_MULT)); in _hardware_enqueue()
622 ret = hw_ep_prime(ci, hwep->num, hwep->dir, in _hardware_enqueue()
623 hwep->type == USB_ENDPOINT_XFER_CONTROL); in _hardware_enqueue()
632 static void free_pending_td(struct ci_hw_ep *hwep) in free_pending_td() argument
634 struct td_node *pending = hwep->pending_td; in free_pending_td()
636 dma_pool_free(hwep->td_pool, pending->ptr, pending->dma); in free_pending_td()
637 hwep->pending_td = NULL; in free_pending_td()
641 static int reprime_dtd(struct ci_hdrc *ci, struct ci_hw_ep *hwep, in reprime_dtd() argument
644 hwep->qh.ptr->td.next = cpu_to_le32(node->dma); in reprime_dtd()
645 hwep->qh.ptr->td.token &= in reprime_dtd()
648 return hw_ep_prime(ci, hwep->num, hwep->dir, in reprime_dtd()
649 hwep->type == USB_ENDPOINT_XFER_CONTROL); in reprime_dtd()
659 static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) in _hardware_dequeue() argument
665 struct ci_hdrc *ci = hwep->ci; in _hardware_dequeue()
675 int n = hw_ep_bit(hwep->num, hwep->dir); in _hardware_dequeue()
679 reprime_dtd(ci, hwep, node); in _hardware_dequeue()
701 if (hwep->dir == TX) { in _hardware_dequeue()
711 if (hwep->pending_td) in _hardware_dequeue()
712 free_pending_td(hwep); in _hardware_dequeue()
714 hwep->pending_td = node; in _hardware_dequeue()
718 usb_gadget_unmap_request_by_dev(hwep->ci->dev->parent, in _hardware_dequeue()
719 &hwreq->req, hwep->dir); in _hardware_dequeue()
736 static int _ep_nuke(struct ci_hw_ep *hwep) in _ep_nuke() argument
737 __releases(hwep->lock) in _ep_nuke()
738 __acquires(hwep->lock) in _ep_nuke()
741 if (hwep == NULL) in _ep_nuke()
744 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in _ep_nuke()
746 while (!list_empty(&hwep->qh.queue)) { in _ep_nuke()
749 struct ci_hw_req *hwreq = list_entry(hwep->qh.queue.next, in _ep_nuke()
753 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in _ep_nuke()
763 spin_unlock(hwep->lock); in _ep_nuke()
764 usb_gadget_giveback_request(&hwep->ep, &hwreq->req); in _ep_nuke()
765 spin_lock(hwep->lock); in _ep_nuke()
769 if (hwep->pending_td) in _ep_nuke()
770 free_pending_td(hwep); in _ep_nuke()
777 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in _ep_set_halt() local
781 if (ep == NULL || hwep->ep.desc == NULL) in _ep_set_halt()
784 if (usb_endpoint_xfer_isoc(hwep->ep.desc)) in _ep_set_halt()
787 spin_lock_irqsave(hwep->lock, flags); in _ep_set_halt()
789 if (value && hwep->dir == TX && check_transfer && in _ep_set_halt()
790 !list_empty(&hwep->qh.queue) && in _ep_set_halt()
791 !usb_endpoint_xfer_control(hwep->ep.desc)) { in _ep_set_halt()
792 spin_unlock_irqrestore(hwep->lock, flags); in _ep_set_halt()
796 direction = hwep->dir; in _ep_set_halt()
798 retval |= hw_ep_set_halt(hwep->ci, hwep->num, hwep->dir, value); in _ep_set_halt()
801 hwep->wedge = 0; in _ep_set_halt()
803 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in _ep_set_halt()
804 hwep->dir = (hwep->dir == TX) ? RX : TX; in _ep_set_halt()
806 } while (hwep->dir != direction); in _ep_set_halt()
808 spin_unlock_irqrestore(hwep->lock, flags); in _ep_set_halt()
917 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in _ep_queue() local
919 struct ci_hdrc *ci = hwep->ci; in _ep_queue()
922 if (ep == NULL || req == NULL || hwep->ep.desc == NULL) in _ep_queue()
925 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) { in _ep_queue()
927 hwep = (ci->ep0_dir == RX) ? in _ep_queue()
929 if (!list_empty(&hwep->qh.queue)) { in _ep_queue()
930 _ep_nuke(hwep); in _ep_queue()
931 dev_warn(hwep->ci->dev, "endpoint ctrl %X nuked\n", in _ep_queue()
932 _usb_addr(hwep)); in _ep_queue()
936 if (usb_endpoint_xfer_isoc(hwep->ep.desc) && in _ep_queue()
937 hwreq->req.length > hwep->ep.mult * hwep->ep.maxpacket) { in _ep_queue()
938 dev_err(hwep->ci->dev, "request length too big for isochronous\n"); in _ep_queue()
944 dev_err(hwep->ci->dev, "request already in queue\n"); in _ep_queue()
952 retval = _hardware_enqueue(hwep, hwreq); in _ep_queue()
957 list_add_tail(&hwreq->queue, &hwep->qh.queue); in _ep_queue()
971 __releases(hwep->lock) in isr_get_status_response()
972 __acquires(hwep->lock) in isr_get_status_response()
974 struct ci_hw_ep *hwep = ci->ep0in; in isr_get_status_response() local
979 if (hwep == NULL || setup == NULL) in isr_get_status_response()
982 spin_unlock(hwep->lock); in isr_get_status_response()
983 req = usb_ep_alloc_request(&hwep->ep, gfp_flags); in isr_get_status_response()
984 spin_lock(hwep->lock); in isr_get_status_response()
1008 retval = _ep_queue(&hwep->ep, req, gfp_flags); in isr_get_status_response()
1017 spin_unlock(hwep->lock); in isr_get_status_response()
1018 usb_ep_free_request(&hwep->ep, req); in isr_get_status_response()
1019 spin_lock(hwep->lock); in isr_get_status_response()
1061 struct ci_hw_ep *hwep; in isr_setup_status_phase() local
1072 hwep = (ci->ep0_dir == TX) ? ci->ep0out : ci->ep0in; in isr_setup_status_phase()
1076 return _ep_queue(&hwep->ep, ci->status, GFP_ATOMIC); in isr_setup_status_phase()
1086 static int isr_tr_complete_low(struct ci_hw_ep *hwep) in isr_tr_complete_low() argument
1087 __releases(hwep->lock) in isr_tr_complete_low()
1088 __acquires(hwep->lock) in isr_tr_complete_low()
1091 struct ci_hw_ep *hweptemp = hwep; in isr_tr_complete_low()
1094 list_for_each_entry_safe(hwreq, hwreqtemp, &hwep->qh.queue, in isr_tr_complete_low()
1096 retval = _hardware_dequeue(hwep, hwreq); in isr_tr_complete_low()
1101 spin_unlock(hwep->lock); in isr_tr_complete_low()
1102 if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) && in isr_tr_complete_low()
1104 hweptemp = hwep->ci->ep0in; in isr_tr_complete_low()
1106 spin_lock(hwep->lock); in isr_tr_complete_low()
1133 struct ci_hw_ep *hwep = &ci->ci_hw_ep[0]; in isr_setup_packet_handler() local
1148 memcpy(&req, &hwep->qh.ptr->setup, sizeof(req)); in isr_setup_packet_handler()
1287 if (_ep_set_halt(&hwep->ep, 1, false)) in isr_setup_packet_handler()
1307 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; in isr_tr_complete_handler() local
1309 if (hwep->ep.desc == NULL) in isr_tr_complete_handler()
1313 err = isr_tr_complete_low(hwep); in isr_tr_complete_handler()
1314 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) { in isr_tr_complete_handler()
1319 if (_ep_set_halt(&hwep->ep, 1, false)) in isr_tr_complete_handler()
1345 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_enable() local
1353 spin_lock_irqsave(hwep->lock, flags); in ep_enable()
1357 if (!list_empty(&hwep->qh.queue)) { in ep_enable()
1358 dev_warn(hwep->ci->dev, "enabling a non-empty endpoint!\n"); in ep_enable()
1359 spin_unlock_irqrestore(hwep->lock, flags); in ep_enable()
1363 hwep->ep.desc = desc; in ep_enable()
1365 hwep->dir = usb_endpoint_dir_in(desc) ? TX : RX; in ep_enable()
1366 hwep->num = usb_endpoint_num(desc); in ep_enable()
1367 hwep->type = usb_endpoint_type(desc); in ep_enable()
1369 hwep->ep.maxpacket = usb_endpoint_maxp(desc); in ep_enable()
1370 hwep->ep.mult = usb_endpoint_maxp_mult(desc); in ep_enable()
1372 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in ep_enable()
1376 cap |= (hwep->ep.maxpacket << __ffs(QH_MAX_PKT)) & QH_MAX_PKT; in ep_enable()
1381 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) in ep_enable()
1384 hwep->qh.ptr->cap = cpu_to_le32(cap); in ep_enable()
1386 hwep->qh.ptr->td.next |= cpu_to_le32(TD_TERMINATE); /* needed? */ in ep_enable()
1388 if (hwep->num != 0 && hwep->type == USB_ENDPOINT_XFER_CONTROL) { in ep_enable()
1389 dev_err(hwep->ci->dev, "Set control xfer at non-ep0\n"); in ep_enable()
1397 if (hwep->num) in ep_enable()
1398 retval |= hw_ep_enable(hwep->ci, hwep->num, hwep->dir, in ep_enable()
1399 hwep->type); in ep_enable()
1401 spin_unlock_irqrestore(hwep->lock, flags); in ep_enable()
1412 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_disable() local
1418 else if (hwep->ep.desc == NULL) in ep_disable()
1421 spin_lock_irqsave(hwep->lock, flags); in ep_disable()
1422 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_disable()
1423 spin_unlock_irqrestore(hwep->lock, flags); in ep_disable()
1429 direction = hwep->dir; in ep_disable()
1431 retval |= _ep_nuke(hwep); in ep_disable()
1432 retval |= hw_ep_disable(hwep->ci, hwep->num, hwep->dir); in ep_disable()
1434 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in ep_disable()
1435 hwep->dir = (hwep->dir == TX) ? RX : TX; in ep_disable()
1437 } while (hwep->dir != direction); in ep_disable()
1439 hwep->ep.desc = NULL; in ep_disable()
1441 spin_unlock_irqrestore(hwep->lock, flags); in ep_disable()
1473 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_free_request() local
1481 dev_err(hwep->ci->dev, "freeing queued request\n"); in ep_free_request()
1485 spin_lock_irqsave(hwep->lock, flags); in ep_free_request()
1488 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in ep_free_request()
1496 spin_unlock_irqrestore(hwep->lock, flags); in ep_free_request()
1507 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_queue() local
1511 if (ep == NULL || req == NULL || hwep->ep.desc == NULL) in ep_queue()
1514 spin_lock_irqsave(hwep->lock, flags); in ep_queue()
1515 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_queue()
1516 spin_unlock_irqrestore(hwep->lock, flags); in ep_queue()
1520 spin_unlock_irqrestore(hwep->lock, flags); in ep_queue()
1531 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_dequeue() local
1537 hwep->ep.desc == NULL || list_empty(&hwreq->queue) || in ep_dequeue()
1538 list_empty(&hwep->qh.queue)) in ep_dequeue()
1541 spin_lock_irqsave(hwep->lock, flags); in ep_dequeue()
1542 if (hwep->ci->gadget.speed != USB_SPEED_UNKNOWN) in ep_dequeue()
1543 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in ep_dequeue()
1546 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in ep_dequeue()
1554 usb_gadget_unmap_request(&hwep->ci->gadget, req, hwep->dir); in ep_dequeue()
1559 spin_unlock(hwep->lock); in ep_dequeue()
1560 usb_gadget_giveback_request(&hwep->ep, &hwreq->req); in ep_dequeue()
1561 spin_lock(hwep->lock); in ep_dequeue()
1564 spin_unlock_irqrestore(hwep->lock, flags); in ep_dequeue()
1585 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_set_wedge() local
1588 if (ep == NULL || hwep->ep.desc == NULL) in ep_set_wedge()
1591 spin_lock_irqsave(hwep->lock, flags); in ep_set_wedge()
1592 hwep->wedge = 1; in ep_set_wedge()
1593 spin_unlock_irqrestore(hwep->lock, flags); in ep_set_wedge()
1605 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_fifo_flush() local
1609 dev_err(hwep->ci->dev, "%02X: -EINVAL\n", _usb_addr(hwep)); in ep_fifo_flush()
1613 spin_lock_irqsave(hwep->lock, flags); in ep_fifo_flush()
1614 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_fifo_flush()
1615 spin_unlock_irqrestore(hwep->lock, flags); in ep_fifo_flush()
1619 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in ep_fifo_flush()
1621 spin_unlock_irqrestore(hwep->lock, flags); in ep_fifo_flush()
1737 struct ci_hw_ep *hwep = ci->ep0in; in ci_udc_selfpowered() local
1740 spin_lock_irqsave(hwep->lock, flags); in ci_udc_selfpowered()
1742 spin_unlock_irqrestore(hwep->lock, flags); in ci_udc_selfpowered()
1816 struct ci_hw_ep *hwep = &ci->ci_hw_ep[k]; in init_eps() local
1818 scnprintf(hwep->name, sizeof(hwep->name), "ep%i%s", i, in init_eps()
1821 hwep->ci = ci; in init_eps()
1822 hwep->lock = &ci->lock; in init_eps()
1823 hwep->td_pool = ci->td_pool; in init_eps()
1825 hwep->ep.name = hwep->name; in init_eps()
1826 hwep->ep.ops = &usb_ep_ops; in init_eps()
1829 hwep->ep.caps.type_control = true; in init_eps()
1831 hwep->ep.caps.type_iso = true; in init_eps()
1832 hwep->ep.caps.type_bulk = true; in init_eps()
1833 hwep->ep.caps.type_int = true; in init_eps()
1837 hwep->ep.caps.dir_in = true; in init_eps()
1839 hwep->ep.caps.dir_out = true; in init_eps()
1846 usb_ep_set_maxpacket_limit(&hwep->ep, (unsigned short)~0); in init_eps()
1848 INIT_LIST_HEAD(&hwep->qh.queue); in init_eps()
1849 hwep->qh.ptr = dma_pool_zalloc(ci->qh_pool, GFP_KERNEL, in init_eps()
1850 &hwep->qh.dma); in init_eps()
1851 if (hwep->qh.ptr == NULL) in init_eps()
1860 ci->ep0out = hwep; in init_eps()
1862 ci->ep0in = hwep; in init_eps()
1864 usb_ep_set_maxpacket_limit(&hwep->ep, CTRL_PAYLOAD_MAX); in init_eps()
1868 list_add_tail(&hwep->ep.ep_list, &ci->gadget.ep_list); in init_eps()
1879 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; in destroy_eps() local
1881 if (hwep->pending_td) in destroy_eps()
1882 free_pending_td(hwep); in destroy_eps()
1883 dma_pool_free(ci->qh_pool, hwep->qh.ptr, hwep->qh.dma); in destroy_eps()