Lines Matching refs:hwep
339 static int add_td_to_list(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq, in add_td_to_list() argument
350 node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC, &node->dma); in add_td_to_list()
359 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) { in add_td_to_list()
360 u32 mul = hwreq->req.length / hwep->ep.maxpacket; in add_td_to_list()
363 || hwreq->req.length % hwep->ep.maxpacket) in add_td_to_list()
409 static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) in _hardware_enqueue() argument
411 struct ci_hdrc *ci = hwep->ci; in _hardware_enqueue()
424 &hwreq->req, hwep->dir); in _hardware_enqueue()
436 ret = add_td_to_list(hwep, hwreq, 0); in _hardware_enqueue()
444 ret = add_td_to_list(hwep, hwreq, count); in _hardware_enqueue()
451 if (hwreq->req.zero && hwreq->req.length && hwep->dir == TX in _hardware_enqueue()
452 && (hwreq->req.length % hwep->ep.maxpacket == 0)) { in _hardware_enqueue()
453 ret = add_td_to_list(hwep, hwreq, 0); in _hardware_enqueue()
469 if (!list_empty(&hwep->qh.queue)) { in _hardware_enqueue()
471 int n = hw_ep_bit(hwep->num, hwep->dir); in _hardware_enqueue()
476 hwreqprev = list_entry(hwep->qh.queue.prev, in _hardware_enqueue()
495 hwep->qh.ptr->td.next = cpu_to_le32(firstnode->dma); in _hardware_enqueue()
496 hwep->qh.ptr->td.token &= in _hardware_enqueue()
499 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == RX) { in _hardware_enqueue()
500 u32 mul = hwreq->req.length / hwep->ep.maxpacket; in _hardware_enqueue()
503 || hwreq->req.length % hwep->ep.maxpacket) in _hardware_enqueue()
505 hwep->qh.ptr->cap |= cpu_to_le32(mul << __ffs(QH_MULT)); in _hardware_enqueue()
508 ret = hw_ep_prime(ci, hwep->num, hwep->dir, in _hardware_enqueue()
509 hwep->type == USB_ENDPOINT_XFER_CONTROL); in _hardware_enqueue()
518 static void free_pending_td(struct ci_hw_ep *hwep) in free_pending_td() argument
520 struct td_node *pending = hwep->pending_td; in free_pending_td()
522 dma_pool_free(hwep->td_pool, pending->ptr, pending->dma); in free_pending_td()
523 hwep->pending_td = NULL; in free_pending_td()
527 static int reprime_dtd(struct ci_hdrc *ci, struct ci_hw_ep *hwep, in reprime_dtd() argument
530 hwep->qh.ptr->td.next = cpu_to_le32(node->dma); in reprime_dtd()
531 hwep->qh.ptr->td.token &= in reprime_dtd()
534 return hw_ep_prime(ci, hwep->num, hwep->dir, in reprime_dtd()
535 hwep->type == USB_ENDPOINT_XFER_CONTROL); in reprime_dtd()
545 static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) in _hardware_dequeue() argument
551 struct ci_hdrc *ci = hwep->ci; in _hardware_dequeue()
561 int n = hw_ep_bit(hwep->num, hwep->dir); in _hardware_dequeue()
565 reprime_dtd(ci, hwep, node); in _hardware_dequeue()
587 if (hwep->dir == TX) { in _hardware_dequeue()
597 if (hwep->pending_td) in _hardware_dequeue()
598 free_pending_td(hwep); in _hardware_dequeue()
600 hwep->pending_td = node; in _hardware_dequeue()
604 usb_gadget_unmap_request_by_dev(hwep->ci->dev->parent, in _hardware_dequeue()
605 &hwreq->req, hwep->dir); in _hardware_dequeue()
622 static int _ep_nuke(struct ci_hw_ep *hwep) in _ep_nuke() argument
623 __releases(hwep->lock) in _ep_nuke()
624 __acquires(hwep->lock) in _ep_nuke()
627 if (hwep == NULL) in _ep_nuke()
630 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in _ep_nuke()
632 while (!list_empty(&hwep->qh.queue)) { in _ep_nuke()
635 struct ci_hw_req *hwreq = list_entry(hwep->qh.queue.next, in _ep_nuke()
639 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in _ep_nuke()
649 spin_unlock(hwep->lock); in _ep_nuke()
650 usb_gadget_giveback_request(&hwep->ep, &hwreq->req); in _ep_nuke()
651 spin_lock(hwep->lock); in _ep_nuke()
655 if (hwep->pending_td) in _ep_nuke()
656 free_pending_td(hwep); in _ep_nuke()
663 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in _ep_set_halt() local
667 if (ep == NULL || hwep->ep.desc == NULL) in _ep_set_halt()
670 if (usb_endpoint_xfer_isoc(hwep->ep.desc)) in _ep_set_halt()
673 spin_lock_irqsave(hwep->lock, flags); in _ep_set_halt()
675 if (value && hwep->dir == TX && check_transfer && in _ep_set_halt()
676 !list_empty(&hwep->qh.queue) && in _ep_set_halt()
677 !usb_endpoint_xfer_control(hwep->ep.desc)) { in _ep_set_halt()
678 spin_unlock_irqrestore(hwep->lock, flags); in _ep_set_halt()
682 direction = hwep->dir; in _ep_set_halt()
684 retval |= hw_ep_set_halt(hwep->ci, hwep->num, hwep->dir, value); in _ep_set_halt()
687 hwep->wedge = 0; in _ep_set_halt()
689 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in _ep_set_halt()
690 hwep->dir = (hwep->dir == TX) ? RX : TX; in _ep_set_halt()
692 } while (hwep->dir != direction); in _ep_set_halt()
694 spin_unlock_irqrestore(hwep->lock, flags); in _ep_set_halt()
803 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in _ep_queue() local
805 struct ci_hdrc *ci = hwep->ci; in _ep_queue()
808 if (ep == NULL || req == NULL || hwep->ep.desc == NULL) in _ep_queue()
811 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) { in _ep_queue()
813 hwep = (ci->ep0_dir == RX) ? in _ep_queue()
815 if (!list_empty(&hwep->qh.queue)) { in _ep_queue()
816 _ep_nuke(hwep); in _ep_queue()
817 dev_warn(hwep->ci->dev, "endpoint ctrl %X nuked\n", in _ep_queue()
818 _usb_addr(hwep)); in _ep_queue()
822 if (usb_endpoint_xfer_isoc(hwep->ep.desc) && in _ep_queue()
823 hwreq->req.length > hwep->ep.mult * hwep->ep.maxpacket) { in _ep_queue()
824 dev_err(hwep->ci->dev, "request length too big for isochronous\n"); in _ep_queue()
830 dev_err(hwep->ci->dev, "request already in queue\n"); in _ep_queue()
838 retval = _hardware_enqueue(hwep, hwreq); in _ep_queue()
843 list_add_tail(&hwreq->queue, &hwep->qh.queue); in _ep_queue()
857 __releases(hwep->lock) in isr_get_status_response()
858 __acquires(hwep->lock) in isr_get_status_response()
860 struct ci_hw_ep *hwep = ci->ep0in; in isr_get_status_response() local
865 if (hwep == NULL || setup == NULL) in isr_get_status_response()
868 spin_unlock(hwep->lock); in isr_get_status_response()
869 req = usb_ep_alloc_request(&hwep->ep, gfp_flags); in isr_get_status_response()
870 spin_lock(hwep->lock); in isr_get_status_response()
894 retval = _ep_queue(&hwep->ep, req, gfp_flags); in isr_get_status_response()
903 spin_unlock(hwep->lock); in isr_get_status_response()
904 usb_ep_free_request(&hwep->ep, req); in isr_get_status_response()
905 spin_lock(hwep->lock); in isr_get_status_response()
944 struct ci_hw_ep *hwep; in isr_setup_status_phase() local
955 hwep = (ci->ep0_dir == TX) ? ci->ep0out : ci->ep0in; in isr_setup_status_phase()
959 return _ep_queue(&hwep->ep, ci->status, GFP_ATOMIC); in isr_setup_status_phase()
969 static int isr_tr_complete_low(struct ci_hw_ep *hwep) in isr_tr_complete_low() argument
970 __releases(hwep->lock) in isr_tr_complete_low()
971 __acquires(hwep->lock) in isr_tr_complete_low()
974 struct ci_hw_ep *hweptemp = hwep; in isr_tr_complete_low()
977 list_for_each_entry_safe(hwreq, hwreqtemp, &hwep->qh.queue, in isr_tr_complete_low()
979 retval = _hardware_dequeue(hwep, hwreq); in isr_tr_complete_low()
984 spin_unlock(hwep->lock); in isr_tr_complete_low()
985 if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) && in isr_tr_complete_low()
987 hweptemp = hwep->ci->ep0in; in isr_tr_complete_low()
989 spin_lock(hwep->lock); in isr_tr_complete_low()
1016 struct ci_hw_ep *hwep = &ci->ci_hw_ep[0]; in isr_setup_packet_handler() local
1031 memcpy(&req, &hwep->qh.ptr->setup, sizeof(req)); in isr_setup_packet_handler()
1170 if (_ep_set_halt(&hwep->ep, 1, false)) in isr_setup_packet_handler()
1190 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; in isr_tr_complete_handler() local
1192 if (hwep->ep.desc == NULL) in isr_tr_complete_handler()
1196 err = isr_tr_complete_low(hwep); in isr_tr_complete_handler()
1197 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) { in isr_tr_complete_handler()
1202 if (_ep_set_halt(&hwep->ep, 1, false)) in isr_tr_complete_handler()
1228 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_enable() local
1236 spin_lock_irqsave(hwep->lock, flags); in ep_enable()
1240 if (!list_empty(&hwep->qh.queue)) { in ep_enable()
1241 dev_warn(hwep->ci->dev, "enabling a non-empty endpoint!\n"); in ep_enable()
1242 spin_unlock_irqrestore(hwep->lock, flags); in ep_enable()
1246 hwep->ep.desc = desc; in ep_enable()
1248 hwep->dir = usb_endpoint_dir_in(desc) ? TX : RX; in ep_enable()
1249 hwep->num = usb_endpoint_num(desc); in ep_enable()
1250 hwep->type = usb_endpoint_type(desc); in ep_enable()
1252 hwep->ep.maxpacket = usb_endpoint_maxp(desc); in ep_enable()
1253 hwep->ep.mult = usb_endpoint_maxp_mult(desc); in ep_enable()
1255 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in ep_enable()
1259 cap |= (hwep->ep.maxpacket << __ffs(QH_MAX_PKT)) & QH_MAX_PKT; in ep_enable()
1264 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) in ep_enable()
1267 hwep->qh.ptr->cap = cpu_to_le32(cap); in ep_enable()
1269 hwep->qh.ptr->td.next |= cpu_to_le32(TD_TERMINATE); /* needed? */ in ep_enable()
1271 if (hwep->num != 0 && hwep->type == USB_ENDPOINT_XFER_CONTROL) { in ep_enable()
1272 dev_err(hwep->ci->dev, "Set control xfer at non-ep0\n"); in ep_enable()
1280 if (hwep->num) in ep_enable()
1281 retval |= hw_ep_enable(hwep->ci, hwep->num, hwep->dir, in ep_enable()
1282 hwep->type); in ep_enable()
1284 spin_unlock_irqrestore(hwep->lock, flags); in ep_enable()
1295 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_disable() local
1301 else if (hwep->ep.desc == NULL) in ep_disable()
1304 spin_lock_irqsave(hwep->lock, flags); in ep_disable()
1308 direction = hwep->dir; in ep_disable()
1310 retval |= _ep_nuke(hwep); in ep_disable()
1311 retval |= hw_ep_disable(hwep->ci, hwep->num, hwep->dir); in ep_disable()
1313 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in ep_disable()
1314 hwep->dir = (hwep->dir == TX) ? RX : TX; in ep_disable()
1316 } while (hwep->dir != direction); in ep_disable()
1318 hwep->ep.desc = NULL; in ep_disable()
1320 spin_unlock_irqrestore(hwep->lock, flags); in ep_disable()
1352 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_free_request() local
1360 dev_err(hwep->ci->dev, "freeing queued request\n"); in ep_free_request()
1364 spin_lock_irqsave(hwep->lock, flags); in ep_free_request()
1367 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in ep_free_request()
1375 spin_unlock_irqrestore(hwep->lock, flags); in ep_free_request()
1386 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_queue() local
1390 if (ep == NULL || req == NULL || hwep->ep.desc == NULL) in ep_queue()
1393 spin_lock_irqsave(hwep->lock, flags); in ep_queue()
1395 spin_unlock_irqrestore(hwep->lock, flags); in ep_queue()
1406 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_dequeue() local
1412 hwep->ep.desc == NULL || list_empty(&hwreq->queue) || in ep_dequeue()
1413 list_empty(&hwep->qh.queue)) in ep_dequeue()
1416 spin_lock_irqsave(hwep->lock, flags); in ep_dequeue()
1418 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in ep_dequeue()
1421 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in ep_dequeue()
1429 usb_gadget_unmap_request(&hwep->ci->gadget, req, hwep->dir); in ep_dequeue()
1434 spin_unlock(hwep->lock); in ep_dequeue()
1435 usb_gadget_giveback_request(&hwep->ep, &hwreq->req); in ep_dequeue()
1436 spin_lock(hwep->lock); in ep_dequeue()
1439 spin_unlock_irqrestore(hwep->lock, flags); in ep_dequeue()
1460 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_set_wedge() local
1463 if (ep == NULL || hwep->ep.desc == NULL) in ep_set_wedge()
1466 spin_lock_irqsave(hwep->lock, flags); in ep_set_wedge()
1467 hwep->wedge = 1; in ep_set_wedge()
1468 spin_unlock_irqrestore(hwep->lock, flags); in ep_set_wedge()
1480 struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep); in ep_fifo_flush() local
1484 dev_err(hwep->ci->dev, "%02X: -EINVAL\n", _usb_addr(hwep)); in ep_fifo_flush()
1488 spin_lock_irqsave(hwep->lock, flags); in ep_fifo_flush()
1490 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in ep_fifo_flush()
1492 spin_unlock_irqrestore(hwep->lock, flags); in ep_fifo_flush()
1587 struct ci_hw_ep *hwep = ci->ep0in; in ci_udc_selfpowered() local
1590 spin_lock_irqsave(hwep->lock, flags); in ci_udc_selfpowered()
1592 spin_unlock_irqrestore(hwep->lock, flags); in ci_udc_selfpowered()
1646 struct ci_hw_ep *hwep = &ci->ci_hw_ep[k]; in init_eps() local
1648 scnprintf(hwep->name, sizeof(hwep->name), "ep%i%s", i, in init_eps()
1651 hwep->ci = ci; in init_eps()
1652 hwep->lock = &ci->lock; in init_eps()
1653 hwep->td_pool = ci->td_pool; in init_eps()
1655 hwep->ep.name = hwep->name; in init_eps()
1656 hwep->ep.ops = &usb_ep_ops; in init_eps()
1659 hwep->ep.caps.type_control = true; in init_eps()
1661 hwep->ep.caps.type_iso = true; in init_eps()
1662 hwep->ep.caps.type_bulk = true; in init_eps()
1663 hwep->ep.caps.type_int = true; in init_eps()
1667 hwep->ep.caps.dir_in = true; in init_eps()
1669 hwep->ep.caps.dir_out = true; in init_eps()
1676 usb_ep_set_maxpacket_limit(&hwep->ep, (unsigned short)~0); in init_eps()
1678 INIT_LIST_HEAD(&hwep->qh.queue); in init_eps()
1679 hwep->qh.ptr = dma_pool_zalloc(ci->qh_pool, GFP_KERNEL, in init_eps()
1680 &hwep->qh.dma); in init_eps()
1681 if (hwep->qh.ptr == NULL) in init_eps()
1690 ci->ep0out = hwep; in init_eps()
1692 ci->ep0in = hwep; in init_eps()
1694 usb_ep_set_maxpacket_limit(&hwep->ep, CTRL_PAYLOAD_MAX); in init_eps()
1698 list_add_tail(&hwep->ep.ep_list, &ci->gadget.ep_list); in init_eps()
1709 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; in destroy_eps() local
1711 if (hwep->pending_td) in destroy_eps()
1712 free_pending_td(hwep); in destroy_eps()
1713 dma_pool_free(ci->qh_pool, hwep->qh.ptr, hwep->qh.dma); in destroy_eps()