Lines Matching refs:ep

57 static void ep_bd_list_free(struct bdc_ep *ep, u32 num_tabs)  in ep_bd_list_free()  argument
59 struct bd_list *bd_list = &ep->bd_list; in ep_bd_list_free()
60 struct bdc *bdc = ep->bdc; in ep_bd_list_free()
65 __func__, ep->name, num_tabs); in ep_bd_list_free()
68 dev_dbg(bdc->dev, "%s already freed\n", ep->name); in ep_bd_list_free()
100 kfree(ep->bd_list.bd_table_array); in ep_bd_list_free()
126 static int ep_bd_list_alloc(struct bdc_ep *ep) in ep_bd_list_alloc() argument
130 struct bdc *bdc = ep->bdc; in ep_bd_list_alloc()
134 if (usb_endpoint_xfer_isoc(ep->desc)) in ep_bd_list_alloc()
143 __func__, ep, num_tabs); in ep_bd_list_alloc()
146 ep->bd_list.bd_table_array = kzalloc( in ep_bd_list_alloc()
149 if (!ep->bd_list.bd_table_array) in ep_bd_list_alloc()
172 ep->bd_list.bd_table_array[index] = bd_table; in ep_bd_list_alloc()
179 chain_table(prev_table, ep->bd_list.bd_table_array[0], bd_p_tab); in ep_bd_list_alloc()
181 ep->bd_list.num_tabs = num_tabs; in ep_bd_list_alloc()
182 ep->bd_list.max_bdi = (num_tabs * bd_p_tab) - 1; in ep_bd_list_alloc()
183 ep->bd_list.num_tabs = num_tabs; in ep_bd_list_alloc()
184 ep->bd_list.num_bds_table = bd_p_tab; in ep_bd_list_alloc()
185 ep->bd_list.eqp_bdi = 0; in ep_bd_list_alloc()
186 ep->bd_list.hwd_bdi = 0; in ep_bd_list_alloc()
191 ep_bd_list_free(ep, num_tabs); in ep_bd_list_alloc()
219 static int bd_add_to_bdi(struct bdc_ep *ep, dma_addr_t bd_dma_addr) in bd_add_to_bdi() argument
221 struct bd_list *bd_list = &ep->bd_list; in bd_add_to_bdi()
223 struct bdc *bdc = ep->bdc; in bd_add_to_bdi()
262 static int bdi_to_tbi(struct bdc_ep *ep, int bdi) in bdi_to_tbi() argument
266 tbi = bdi / ep->bd_list.num_bds_table; in bdi_to_tbi()
267 dev_vdbg(ep->bdc->dev, in bdi_to_tbi()
269 bdi, ep->bd_list.num_bds_table, tbi); in bdi_to_tbi()
275 static inline int find_end_bdi(struct bdc_ep *ep, int next_hwd_bdi) in find_end_bdi() argument
281 end_bdi = ep->bd_list.max_bdi - 1; in find_end_bdi()
282 else if ((end_bdi % (ep->bd_list.num_bds_table-1)) == 0) in find_end_bdi()
292 static int bd_available_ep(struct bdc_ep *ep) in bd_available_ep() argument
294 struct bd_list *bd_list = &ep->bd_list; in bd_available_ep()
296 struct bdc *bdc = ep->bdc; in bd_available_ep()
325 if (!(bdi_to_tbi(ep, bd_list->hwd_bdi) in bd_available_ep()
326 == bdi_to_tbi(ep, bd_list->eqp_bdi))) { in bd_available_ep()
347 struct bdc_ep *ep = bdc->bdc_ep_array[epnum]; in bdc_notify_xfr() local
354 if (unlikely(ep->flags & BDC_EP_STOP)) in bdc_notify_xfr()
355 ep->flags &= ~BDC_EP_STOP; in bdc_notify_xfr()
361 static struct bdc_bd *bdi_to_bd(struct bdc_ep *ep, int bdi) in bdi_to_bd() argument
363 int tbi = bdi_to_tbi(ep, bdi); in bdi_to_bd()
366 local_bdi = bdi - (tbi * ep->bd_list.num_bds_table); in bdi_to_bd()
367 dev_vdbg(ep->bdc->dev, in bdi_to_bd()
371 return (ep->bd_list.bd_table_array[tbi]->start_bd + local_bdi); in bdi_to_bd()
375 static void ep_bdlist_eqp_adv(struct bdc_ep *ep) in ep_bdlist_eqp_adv() argument
377 ep->bd_list.eqp_bdi++; in ep_bdlist_eqp_adv()
379 if (((ep->bd_list.eqp_bdi + 1) % ep->bd_list.num_bds_table) == 0) in ep_bdlist_eqp_adv()
380 ep->bd_list.eqp_bdi++; in ep_bdlist_eqp_adv()
383 if (ep->bd_list.eqp_bdi == (ep->bd_list.max_bdi + 1)) in ep_bdlist_eqp_adv()
384 ep->bd_list.eqp_bdi = 0; in ep_bdlist_eqp_adv()
393 req->ep->dir = 0; in setup_first_bd_ep0()
435 struct bdc_ep *ep; in setup_bd_list_xfr() local
440 ep = req->ep; in setup_bd_list_xfr()
441 bd_list = &ep->bd_list; in setup_bd_list_xfr()
445 bd = bdi_to_bd(ep, bd_list->eqp_bdi); in setup_bd_list_xfr()
447 maxp = usb_endpoint_maxp(ep->desc) & 0x7ff; in setup_bd_list_xfr()
451 __func__, ep->name, num_bds, tfs, req_len, bd); in setup_bd_list_xfr()
460 if (ep->ep_num == 1) { in setup_bd_list_xfr()
466 if (!req->ep->dir) in setup_bd_list_xfr()
480 bd = bdi_to_bd(ep, ep->bd_list.eqp_bdi); in setup_bd_list_xfr()
491 ep_bdlist_eqp_adv(ep); in setup_bd_list_xfr()
496 ep->bd_list.eqp_bdi); in setup_bd_list_xfr()
497 bd = bdi_to_bd(ep, ep->bd_list.eqp_bdi); in setup_bd_list_xfr()
501 bd = bdi_to_bd(ep, bd_xfr->start_bdi); in setup_bd_list_xfr()
505 bd_xfr->next_hwd_bdi = ep->bd_list.eqp_bdi; in setup_bd_list_xfr()
516 struct bdc_ep *ep; in bdc_queue_xfr() local
519 ep = req->ep; in bdc_queue_xfr()
522 ep->bd_list.eqp_bdi, ep->bd_list.hwd_bdi); in bdc_queue_xfr()
525 bd_available = bd_available_ep(ep); in bdc_queue_xfr()
534 list_add_tail(&req->queue, &ep->queue); in bdc_queue_xfr()
535 bdc_dbg_bd_list(bdc, ep); in bdc_queue_xfr()
536 bdc_notify_xfr(bdc, ep->ep_num); in bdc_queue_xfr()
542 static void bdc_req_complete(struct bdc_ep *ep, struct bdc_req *req, in bdc_req_complete() argument
545 struct bdc *bdc = ep->bdc; in bdc_req_complete()
550 dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status); in bdc_req_complete()
553 usb_gadget_unmap_request(&bdc->gadget, &req->usb_req, ep->dir); in bdc_req_complete()
556 usb_gadget_giveback_request(&ep->usb_ep, &req->usb_req); in bdc_req_complete()
562 int bdc_ep_disable(struct bdc_ep *ep) in bdc_ep_disable() argument
569 bdc = ep->bdc; in bdc_ep_disable()
570 dev_dbg(bdc->dev, "%s() ep->ep_num=%d\n", __func__, ep->ep_num); in bdc_ep_disable()
572 ret = bdc_stop_ep(bdc, ep->ep_num); in bdc_ep_disable()
579 while (!list_empty(&ep->queue)) { in bdc_ep_disable()
580 req = list_entry(ep->queue.next, struct bdc_req, in bdc_ep_disable()
582 bdc_req_complete(ep, req, -ESHUTDOWN); in bdc_ep_disable()
585 ret = bdc_dconfig_ep(bdc, ep); in bdc_ep_disable()
590 ep->flags = 0; in bdc_ep_disable()
592 if (ep->ep_num == 1) in bdc_ep_disable()
596 ep_bd_list_free(ep, ep->bd_list.num_tabs); in bdc_ep_disable()
597 ep->desc = NULL; in bdc_ep_disable()
598 ep->comp_desc = NULL; in bdc_ep_disable()
599 ep->usb_ep.desc = NULL; in bdc_ep_disable()
600 ep->ep_type = 0; in bdc_ep_disable()
606 int bdc_ep_enable(struct bdc_ep *ep) in bdc_ep_enable() argument
611 bdc = ep->bdc; in bdc_ep_enable()
615 ret = ep_bd_list_alloc(ep); in bdc_ep_enable()
620 bdc_dbg_bd_list(bdc, ep); in bdc_ep_enable()
622 ep->flags |= BDC_EP_ENABLED; in bdc_ep_enable()
623 if (ep->ep_num == 1) in bdc_ep_enable()
627 ret = bdc_config_ep(bdc, ep); in bdc_ep_enable()
631 ep->usb_ep.maxpacket = usb_endpoint_maxp(ep->desc); in bdc_ep_enable()
632 ep->usb_ep.desc = ep->desc; in bdc_ep_enable()
633 ep->usb_ep.comp_desc = ep->comp_desc; in bdc_ep_enable()
634 ep->ep_type = usb_endpoint_type(ep->desc); in bdc_ep_enable()
635 ep->flags |= BDC_EP_ENABLED; in bdc_ep_enable()
646 struct bdc_ep *ep; in ep0_queue_status_stage() local
649 ep = bdc->bdc_ep_array[1]; in ep0_queue_status_stage()
650 status_req->ep = ep; in ep0_queue_status_stage()
661 static int ep0_queue(struct bdc_ep *ep, struct bdc_req *req) in ep0_queue() argument
666 bdc = ep->bdc; in ep0_queue()
670 req->epnum = ep->ep_num; in ep0_queue()
691 ret = usb_gadget_map_request(&bdc->gadget, &req->usb_req, ep->dir); in ep0_queue()
693 dev_err(bdc->dev, "dma mapping failed %s\n", ep->name); in ep0_queue()
704 struct bdc_ep *ep; in ep0_queue_data_stage() local
708 ep = bdc->bdc_ep_array[1]; in ep0_queue_data_stage()
709 bdc->ep0_req.ep = ep; in ep0_queue_data_stage()
712 return ep0_queue(ep, &bdc->ep0_req); in ep0_queue_data_stage()
716 static int ep_queue(struct bdc_ep *ep, struct bdc_req *req) in ep_queue() argument
721 if (!req || !ep->usb_ep.desc) in ep_queue()
724 bdc = ep->bdc; in ep_queue()
728 req->epnum = ep->ep_num; in ep_queue()
730 ret = usb_gadget_map_request(&bdc->gadget, &req->usb_req, ep->dir); in ep_queue()
740 static int ep_dequeue(struct bdc_ep *ep, struct bdc_req *req) in ep_dequeue() argument
754 bdc = ep->bdc; in ep_dequeue()
756 eqp_bdi = ep->bd_list.eqp_bdi - 1; in ep_dequeue()
759 eqp_bdi = ep->bd_list.max_bdi; in ep_dequeue()
762 end_bdi = find_end_bdi(ep, req->bd_xfr.next_hwd_bdi); in ep_dequeue()
765 __func__, ep->name, start_bdi, end_bdi); in ep_dequeue()
767 ep, (void *)ep->usb_ep.desc); in ep_dequeue()
769 ret = bdc_stop_ep(bdc, ep->ep_num); in ep_dequeue()
786 curr_hw_dqpi = bd_add_to_bdi(ep, deq_ptr_64); in ep_dequeue()
826 tbi = bdi_to_tbi(ep, req->bd_xfr.next_hwd_bdi); in ep_dequeue()
827 table = ep->bd_list.bd_table_array[tbi]; in ep_dequeue()
830 tbi * ep->bd_list.num_bds_table); in ep_dequeue()
832 first_req = list_first_entry(&ep->queue, struct bdc_req, in ep_dequeue()
848 bd_start = bdi_to_bd(ep, start_bdi); in ep_dequeue()
853 bdc_dbg_bd_list(bdc, ep); in ep_dequeue()
859 ret = bdc_ep_bla(bdc, ep, next_bd_dma); in ep_dequeue()
870 static int ep_set_halt(struct bdc_ep *ep, u32 value) in ep_set_halt() argument
875 bdc = ep->bdc; in ep_set_halt()
876 dev_dbg(bdc->dev, "%s ep:%s value=%d\n", __func__, ep->name, value); in ep_set_halt()
880 if (ep->ep_num == 1) in ep_set_halt()
883 ret = bdc_ep_set_stall(bdc, ep->ep_num); in ep_set_halt()
886 ep->name); in ep_set_halt()
888 ep->flags |= BDC_EP_STALL; in ep_set_halt()
892 ret = bdc_ep_clear_stall(bdc, ep->ep_num); in ep_set_halt()
895 ep->name); in ep_set_halt()
897 ep->flags &= ~BDC_EP_STALL; in ep_set_halt()
907 struct bdc_ep *ep; in bdc_free_ep() local
912 ep = bdc->bdc_ep_array[epnum]; in bdc_free_ep()
913 if (!ep) in bdc_free_ep()
916 if (ep->flags & BDC_EP_ENABLED) in bdc_free_ep()
917 ep_bd_list_free(ep, ep->bd_list.num_tabs); in bdc_free_ep()
921 list_del(&ep->usb_ep.ep_list); in bdc_free_ep()
923 kfree(ep); in bdc_free_ep()
956 static void handle_xsr_succ_status(struct bdc *bdc, struct bdc_ep *ep, in handle_xsr_succ_status() argument
960 struct bd_list *bd_list = &ep->bd_list; in handle_xsr_succ_status()
970 dev_dbg(bdc->dev, "%s ep:%p\n", __func__, ep); in handle_xsr_succ_status()
973 if (ep->ignore_next_sr) { in handle_xsr_succ_status()
974 ep->ignore_next_sr = false; in handle_xsr_succ_status()
978 if (unlikely(list_empty(&ep->queue))) { in handle_xsr_succ_status()
982 req = list_entry(ep->queue.next, struct bdc_req, in handle_xsr_succ_status()
1002 short_bdi = bd_add_to_bdi(ep, deq_ptr_64); in handle_xsr_succ_status()
1014 if (!(bdi_to_tbi(ep, start_bdi) == in handle_xsr_succ_status()
1015 bdi_to_tbi(ep, short_bdi))) in handle_xsr_succ_status()
1031 end_bdi = find_end_bdi(ep, bd_xfr->next_hwd_bdi); in handle_xsr_succ_status()
1033 ep->ignore_next_sr = true; in handle_xsr_succ_status()
1036 short_bd = bdi_to_bd(ep, short_bdi); in handle_xsr_succ_status()
1053 ep->bd_list.hwd_bdi = bd_xfr->next_hwd_bdi; in handle_xsr_succ_status()
1055 dev_dbg(bdc->dev, "short xfr on %d\n", ep->ep_num); in handle_xsr_succ_status()
1059 bdc_req_complete(ep, bd_xfr->req, status); in handle_xsr_succ_status()
1094 struct bdc_ep *ep = bdc->bdc_ep_array[1]; in ep0_stall() local
1099 ep_set_halt(ep, 1); in ep0_stall()
1102 while (!list_empty(&ep->queue)) { in ep0_stall()
1103 req = list_entry(ep->queue.next, struct bdc_req, in ep0_stall()
1105 bdc_req_complete(ep, req, -ESHUTDOWN); in ep0_stall()
1237 struct bdc_ep *ep; in ep0_handle_feature() local
1294 ep = bdc->bdc_ep_array[epnum]; in ep0_handle_feature()
1295 if (!ep) in ep0_handle_feature()
1298 return ep_set_halt(ep, set); in ep0_handle_feature()
1312 struct bdc_ep *ep; in ep0_handle_status() local
1360 ep = bdc->bdc_ep_array[epnum]; in ep0_handle_status()
1361 if (!ep) { in ep0_handle_status()
1365 if (ep->flags & BDC_EP_STALL) in ep0_handle_status()
1392 struct bdc_ep *ep; in ep0_set_sel() local
1403 ep = bdc->bdc_ep_array[1]; in ep0_set_sel()
1404 bdc->ep0_req.ep = ep; in ep0_set_sel()
1422 bdc->ep0_req.ep = bdc->bdc_ep_array[1]; in ep0_queue_zlp()
1518 struct bdc_ep *ep; in bdc_xsf_ep0_data_start() local
1522 ep = bdc->bdc_ep_array[1]; in bdc_xsf_ep0_data_start()
1524 if (ep->flags & BDC_EP_STALL) { in bdc_xsf_ep0_data_start()
1525 ret = ep_set_halt(ep, 0); in bdc_xsf_ep0_data_start()
1557 struct bdc_ep *ep; in bdc_xsf_ep0_status_start() local
1563 ep = bdc->bdc_ep_array[1]; in bdc_xsf_ep0_status_start()
1569 if (ep->flags & BDC_EP_STALL) { in bdc_xsf_ep0_status_start()
1570 ret = ep_set_halt(ep, 0); in bdc_xsf_ep0_status_start()
1652 struct bdc_ep *ep; in bdc_sr_xsf() local
1657 ep = bdc->bdc_ep_array[ep_num]; in bdc_sr_xsf()
1658 if (!ep || !(ep->flags & BDC_EP_ENABLED)) { in bdc_sr_xsf()
1673 __func__, sr_status, ep->name); in bdc_sr_xsf()
1678 handle_xsr_succ_status(bdc, ep, sreport); in bdc_sr_xsf()
1721 struct bdc_ep *ep; in bdc_gadget_ep_queue() local
1731 ep = to_bdc_ep(_ep); in bdc_gadget_ep_queue()
1733 bdc = ep->bdc; in bdc_gadget_ep_queue()
1734 dev_dbg(bdc->dev, "%s ep:%p req:%p\n", __func__, ep, req); in bdc_gadget_ep_queue()
1736 _req, ep->name, _req->length, _req->zero); in bdc_gadget_ep_queue()
1738 if (!ep->usb_ep.desc) { in bdc_gadget_ep_queue()
1741 _req, ep->name); in bdc_gadget_ep_queue()
1752 if (ep == bdc->bdc_ep_array[1]) in bdc_gadget_ep_queue()
1753 ret = ep0_queue(ep, req); in bdc_gadget_ep_queue()
1755 ret = ep_queue(ep, req); in bdc_gadget_ep_queue()
1767 struct bdc_ep *ep; in bdc_gadget_ep_dequeue() local
1774 ep = to_bdc_ep(_ep); in bdc_gadget_ep_dequeue()
1776 bdc = ep->bdc; in bdc_gadget_ep_dequeue()
1777 dev_dbg(bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); in bdc_gadget_ep_dequeue()
1778 bdc_dbg_bd_list(bdc, ep); in bdc_gadget_ep_dequeue()
1781 list_for_each_entry(req, &ep->queue, queue) { in bdc_gadget_ep_dequeue()
1790 ret = ep_dequeue(ep, req); in bdc_gadget_ep_dequeue()
1795 bdc_req_complete(ep, req, -ECONNRESET); in bdc_gadget_ep_dequeue()
1798 bdc_dbg_bd_list(bdc, ep); in bdc_gadget_ep_dequeue()
1807 struct bdc_ep *ep; in bdc_gadget_ep_set_halt() local
1811 ep = to_bdc_ep(_ep); in bdc_gadget_ep_set_halt()
1812 bdc = ep->bdc; in bdc_gadget_ep_set_halt()
1813 dev_dbg(bdc->dev, "%s ep:%s value=%d\n", __func__, ep->name, value); in bdc_gadget_ep_set_halt()
1815 if (usb_endpoint_xfer_isoc(ep->usb_ep.desc)) in bdc_gadget_ep_set_halt()
1817 else if (!list_empty(&ep->queue)) in bdc_gadget_ep_set_halt()
1820 ret = ep_set_halt(ep, value); in bdc_gadget_ep_set_halt()
1831 struct bdc_ep *ep; in bdc_gadget_alloc_request() local
1837 ep = to_bdc_ep(_ep); in bdc_gadget_alloc_request()
1838 req->ep = ep; in bdc_gadget_alloc_request()
1839 req->epnum = ep->ep_num; in bdc_gadget_alloc_request()
1841 dev_dbg(ep->bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); in bdc_gadget_alloc_request()
1862 struct bdc_ep *ep; in bdc_gadget_ep_enable() local
1876 ep = to_bdc_ep(_ep); in bdc_gadget_ep_enable()
1877 bdc = ep->bdc; in bdc_gadget_ep_enable()
1880 if (ep == bdc->bdc_ep_array[1]) in bdc_gadget_ep_enable()
1888 dev_dbg(bdc->dev, "%s Enabling %s\n", __func__, ep->name); in bdc_gadget_ep_enable()
1890 ep->desc = desc; in bdc_gadget_ep_enable()
1891 ep->comp_desc = _ep->comp_desc; in bdc_gadget_ep_enable()
1892 ret = bdc_ep_enable(ep); in bdc_gadget_ep_enable()
1901 struct bdc_ep *ep; in bdc_gadget_ep_disable() local
1909 ep = to_bdc_ep(_ep); in bdc_gadget_ep_disable()
1910 bdc = ep->bdc; in bdc_gadget_ep_disable()
1913 if (ep == bdc->bdc_ep_array[1]) { in bdc_gadget_ep_disable()
1919 __func__, ep->name, ep->flags); in bdc_gadget_ep_disable()
1921 if (!(ep->flags & BDC_EP_ENABLED)) { in bdc_gadget_ep_disable()
1922 dev_warn(bdc->dev, "%s is already disabled\n", ep->name); in bdc_gadget_ep_disable()
1926 ret = bdc_ep_disable(ep); in bdc_gadget_ep_disable()
1945 struct bdc_ep *ep; in init_ep() local
1948 ep = kzalloc(sizeof(*ep), GFP_KERNEL); in init_ep()
1949 if (!ep) in init_ep()
1952 ep->bdc = bdc; in init_ep()
1953 ep->dir = dir; in init_ep()
1957 ep->ep_num = 1; in init_ep()
1958 bdc->bdc_ep_array[ep->ep_num] = ep; in init_ep()
1959 snprintf(ep->name, sizeof(ep->name), "ep%d", epnum - 1); in init_ep()
1960 usb_ep_set_maxpacket_limit(&ep->usb_ep, EP0_MAX_PKT_SIZE); in init_ep()
1961 ep->comp_desc = NULL; in init_ep()
1962 bdc->gadget.ep0 = &ep->usb_ep; in init_ep()
1965 ep->ep_num = epnum * 2 - 1; in init_ep()
1967 ep->ep_num = epnum * 2 - 2; in init_ep()
1969 bdc->bdc_ep_array[ep->ep_num] = ep; in init_ep()
1970 snprintf(ep->name, sizeof(ep->name), "ep%d%s", epnum - 1, in init_ep()
1973 usb_ep_set_maxpacket_limit(&ep->usb_ep, 1024); in init_ep()
1974 ep->usb_ep.max_streams = 0; in init_ep()
1975 list_add_tail(&ep->usb_ep.ep_list, &bdc->gadget.ep_list); in init_ep()
1977 ep->usb_ep.ops = &bdc_gadget_ep_ops; in init_ep()
1978 ep->usb_ep.name = ep->name; in init_ep()
1979 ep->flags = 0; in init_ep()
1980 ep->ignore_next_sr = false; in init_ep()
1982 ep, ep->usb_ep.name, epnum, ep->ep_num); in init_ep()
1984 INIT_LIST_HEAD(&ep->queue); in init_ep()