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()
174 ep->bd_list.bd_table_array[index] = bd_table; in ep_bd_list_alloc()
181 chain_table(prev_table, ep->bd_list.bd_table_array[0], bd_p_tab); in ep_bd_list_alloc()
183 ep->bd_list.num_tabs = num_tabs; in ep_bd_list_alloc()
184 ep->bd_list.max_bdi = (num_tabs * bd_p_tab) - 1; in ep_bd_list_alloc()
185 ep->bd_list.num_tabs = num_tabs; in ep_bd_list_alloc()
186 ep->bd_list.num_bds_table = bd_p_tab; in ep_bd_list_alloc()
187 ep->bd_list.eqp_bdi = 0; in ep_bd_list_alloc()
188 ep->bd_list.hwd_bdi = 0; in ep_bd_list_alloc()
193 ep_bd_list_free(ep, num_tabs); in ep_bd_list_alloc()
221 static int bd_add_to_bdi(struct bdc_ep *ep, dma_addr_t bd_dma_addr) in bd_add_to_bdi() argument
223 struct bd_list *bd_list = &ep->bd_list; in bd_add_to_bdi()
225 struct bdc *bdc = ep->bdc; in bd_add_to_bdi()
264 static int bdi_to_tbi(struct bdc_ep *ep, int bdi) in bdi_to_tbi() argument
268 tbi = bdi / ep->bd_list.num_bds_table; in bdi_to_tbi()
269 dev_vdbg(ep->bdc->dev, in bdi_to_tbi()
271 bdi, ep->bd_list.num_bds_table, tbi); in bdi_to_tbi()
277 static inline int find_end_bdi(struct bdc_ep *ep, int next_hwd_bdi) in find_end_bdi() argument
283 end_bdi = ep->bd_list.max_bdi - 1; in find_end_bdi()
284 else if ((end_bdi % (ep->bd_list.num_bds_table-1)) == 0) in find_end_bdi()
294 static int bd_available_ep(struct bdc_ep *ep) in bd_available_ep() argument
296 struct bd_list *bd_list = &ep->bd_list; in bd_available_ep()
298 struct bdc *bdc = ep->bdc; in bd_available_ep()
327 if (!(bdi_to_tbi(ep, bd_list->hwd_bdi) in bd_available_ep()
328 == bdi_to_tbi(ep, bd_list->eqp_bdi))) { in bd_available_ep()
349 struct bdc_ep *ep = bdc->bdc_ep_array[epnum]; in bdc_notify_xfr() local
356 if (unlikely(ep->flags & BDC_EP_STOP)) in bdc_notify_xfr()
357 ep->flags &= ~BDC_EP_STOP; in bdc_notify_xfr()
363 static struct bdc_bd *bdi_to_bd(struct bdc_ep *ep, int bdi) in bdi_to_bd() argument
365 int tbi = bdi_to_tbi(ep, bdi); in bdi_to_bd()
368 local_bdi = bdi - (tbi * ep->bd_list.num_bds_table); in bdi_to_bd()
369 dev_vdbg(ep->bdc->dev, in bdi_to_bd()
373 return (ep->bd_list.bd_table_array[tbi]->start_bd + local_bdi); in bdi_to_bd()
377 static void ep_bdlist_eqp_adv(struct bdc_ep *ep) in ep_bdlist_eqp_adv() argument
379 ep->bd_list.eqp_bdi++; in ep_bdlist_eqp_adv()
381 if (((ep->bd_list.eqp_bdi + 1) % ep->bd_list.num_bds_table) == 0) in ep_bdlist_eqp_adv()
382 ep->bd_list.eqp_bdi++; in ep_bdlist_eqp_adv()
385 if (ep->bd_list.eqp_bdi == (ep->bd_list.max_bdi + 1)) in ep_bdlist_eqp_adv()
386 ep->bd_list.eqp_bdi = 0; in ep_bdlist_eqp_adv()
395 req->ep->dir = 0; in setup_first_bd_ep0()
437 struct bdc_ep *ep; in setup_bd_list_xfr() local
442 ep = req->ep; in setup_bd_list_xfr()
443 bd_list = &ep->bd_list; in setup_bd_list_xfr()
447 bd = bdi_to_bd(ep, bd_list->eqp_bdi); in setup_bd_list_xfr()
449 maxp = usb_endpoint_maxp(ep->desc) & 0x7ff; in setup_bd_list_xfr()
453 __func__, ep->name, num_bds, tfs, req_len, bd); in setup_bd_list_xfr()
462 if (ep->ep_num == 1) { in setup_bd_list_xfr()
468 if (!req->ep->dir) in setup_bd_list_xfr()
482 bd = bdi_to_bd(ep, ep->bd_list.eqp_bdi); in setup_bd_list_xfr()
493 ep_bdlist_eqp_adv(ep); in setup_bd_list_xfr()
498 ep->bd_list.eqp_bdi); in setup_bd_list_xfr()
499 bd = bdi_to_bd(ep, ep->bd_list.eqp_bdi); in setup_bd_list_xfr()
503 bd = bdi_to_bd(ep, bd_xfr->start_bdi); in setup_bd_list_xfr()
507 bd_xfr->next_hwd_bdi = ep->bd_list.eqp_bdi; in setup_bd_list_xfr()
518 struct bdc_ep *ep; in bdc_queue_xfr() local
521 ep = req->ep; in bdc_queue_xfr()
524 ep->bd_list.eqp_bdi, ep->bd_list.hwd_bdi); in bdc_queue_xfr()
527 bd_available = bd_available_ep(ep); in bdc_queue_xfr()
536 list_add_tail(&req->queue, &ep->queue); in bdc_queue_xfr()
537 bdc_dbg_bd_list(bdc, ep); in bdc_queue_xfr()
538 bdc_notify_xfr(bdc, ep->ep_num); in bdc_queue_xfr()
544 static void bdc_req_complete(struct bdc_ep *ep, struct bdc_req *req, in bdc_req_complete() argument
547 struct bdc *bdc = ep->bdc; in bdc_req_complete()
552 dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status); in bdc_req_complete()
555 usb_gadget_unmap_request(&bdc->gadget, &req->usb_req, ep->dir); in bdc_req_complete()
558 usb_gadget_giveback_request(&ep->usb_ep, &req->usb_req); in bdc_req_complete()
564 int bdc_ep_disable(struct bdc_ep *ep) in bdc_ep_disable() argument
571 bdc = ep->bdc; in bdc_ep_disable()
572 dev_dbg(bdc->dev, "%s() ep->ep_num=%d\n", __func__, ep->ep_num); in bdc_ep_disable()
574 ret = bdc_stop_ep(bdc, ep->ep_num); in bdc_ep_disable()
581 while (!list_empty(&ep->queue)) { in bdc_ep_disable()
582 req = list_entry(ep->queue.next, struct bdc_req, in bdc_ep_disable()
584 bdc_req_complete(ep, req, -ESHUTDOWN); in bdc_ep_disable()
587 ret = bdc_dconfig_ep(bdc, ep); in bdc_ep_disable()
592 ep->flags = 0; in bdc_ep_disable()
594 if (ep->ep_num == 1) in bdc_ep_disable()
598 ep_bd_list_free(ep, ep->bd_list.num_tabs); in bdc_ep_disable()
599 ep->desc = NULL; in bdc_ep_disable()
600 ep->comp_desc = NULL; in bdc_ep_disable()
601 ep->usb_ep.desc = NULL; in bdc_ep_disable()
602 ep->ep_type = 0; in bdc_ep_disable()
608 int bdc_ep_enable(struct bdc_ep *ep) in bdc_ep_enable() argument
613 bdc = ep->bdc; in bdc_ep_enable()
617 ret = ep_bd_list_alloc(ep); in bdc_ep_enable()
622 bdc_dbg_bd_list(bdc, ep); in bdc_ep_enable()
624 ep->flags |= BDC_EP_ENABLED; in bdc_ep_enable()
625 if (ep->ep_num == 1) in bdc_ep_enable()
629 ret = bdc_config_ep(bdc, ep); in bdc_ep_enable()
633 ep->usb_ep.maxpacket = usb_endpoint_maxp(ep->desc); in bdc_ep_enable()
634 ep->usb_ep.desc = ep->desc; in bdc_ep_enable()
635 ep->usb_ep.comp_desc = ep->comp_desc; in bdc_ep_enable()
636 ep->ep_type = usb_endpoint_type(ep->desc); in bdc_ep_enable()
637 ep->flags |= BDC_EP_ENABLED; in bdc_ep_enable()
648 struct bdc_ep *ep; in ep0_queue_status_stage() local
651 ep = bdc->bdc_ep_array[1]; in ep0_queue_status_stage()
652 status_req->ep = ep; in ep0_queue_status_stage()
663 static int ep0_queue(struct bdc_ep *ep, struct bdc_req *req) in ep0_queue() argument
668 bdc = ep->bdc; in ep0_queue()
672 req->epnum = ep->ep_num; in ep0_queue()
693 ret = usb_gadget_map_request(&bdc->gadget, &req->usb_req, ep->dir); in ep0_queue()
695 dev_err(bdc->dev, "dma mapping failed %s\n", ep->name); in ep0_queue()
706 struct bdc_ep *ep; in ep0_queue_data_stage() local
710 ep = bdc->bdc_ep_array[1]; in ep0_queue_data_stage()
711 bdc->ep0_req.ep = ep; in ep0_queue_data_stage()
714 return ep0_queue(ep, &bdc->ep0_req); in ep0_queue_data_stage()
718 static int ep_queue(struct bdc_ep *ep, struct bdc_req *req) in ep_queue() argument
723 if (!req || !ep->usb_ep.desc) in ep_queue()
726 bdc = ep->bdc; in ep_queue()
730 req->epnum = ep->ep_num; in ep_queue()
732 ret = usb_gadget_map_request(&bdc->gadget, &req->usb_req, ep->dir); in ep_queue()
742 static int ep_dequeue(struct bdc_ep *ep, struct bdc_req *req) in ep_dequeue() argument
756 bdc = ep->bdc; in ep_dequeue()
758 eqp_bdi = ep->bd_list.eqp_bdi - 1; in ep_dequeue()
761 eqp_bdi = ep->bd_list.max_bdi; in ep_dequeue()
764 end_bdi = find_end_bdi(ep, req->bd_xfr.next_hwd_bdi); in ep_dequeue()
767 __func__, ep->name, start_bdi, end_bdi); in ep_dequeue()
769 ep, (void *)ep->usb_ep.desc); in ep_dequeue()
771 ret = bdc_stop_ep(bdc, ep->ep_num); in ep_dequeue()
788 curr_hw_dqpi = bd_add_to_bdi(ep, deq_ptr_64); in ep_dequeue()
828 tbi = bdi_to_tbi(ep, req->bd_xfr.next_hwd_bdi); in ep_dequeue()
829 table = ep->bd_list.bd_table_array[tbi]; in ep_dequeue()
832 tbi * ep->bd_list.num_bds_table); in ep_dequeue()
834 first_req = list_first_entry(&ep->queue, struct bdc_req, in ep_dequeue()
850 bd_start = bdi_to_bd(ep, start_bdi); in ep_dequeue()
855 bdc_dbg_bd_list(bdc, ep); in ep_dequeue()
861 ret = bdc_ep_bla(bdc, ep, next_bd_dma); in ep_dequeue()
872 static int ep_set_halt(struct bdc_ep *ep, u32 value) in ep_set_halt() argument
877 bdc = ep->bdc; in ep_set_halt()
878 dev_dbg(bdc->dev, "%s ep:%s value=%d\n", __func__, ep->name, value); in ep_set_halt()
882 if (ep->ep_num == 1) in ep_set_halt()
885 ret = bdc_ep_set_stall(bdc, ep->ep_num); in ep_set_halt()
888 ep->name); in ep_set_halt()
890 ep->flags |= BDC_EP_STALL; in ep_set_halt()
894 ret = bdc_ep_clear_stall(bdc, ep->ep_num); in ep_set_halt()
897 ep->name); in ep_set_halt()
899 ep->flags &= ~BDC_EP_STALL; in ep_set_halt()
909 struct bdc_ep *ep; in bdc_free_ep() local
914 ep = bdc->bdc_ep_array[epnum]; in bdc_free_ep()
915 if (!ep) in bdc_free_ep()
918 if (ep->flags & BDC_EP_ENABLED) in bdc_free_ep()
919 ep_bd_list_free(ep, ep->bd_list.num_tabs); in bdc_free_ep()
923 list_del(&ep->usb_ep.ep_list); in bdc_free_ep()
925 kfree(ep); in bdc_free_ep()
958 static void handle_xsr_succ_status(struct bdc *bdc, struct bdc_ep *ep, in handle_xsr_succ_status() argument
962 struct bd_list *bd_list = &ep->bd_list; in handle_xsr_succ_status()
972 dev_dbg(bdc->dev, "%s ep:%p\n", __func__, ep); in handle_xsr_succ_status()
975 if (ep->ignore_next_sr) { in handle_xsr_succ_status()
976 ep->ignore_next_sr = false; in handle_xsr_succ_status()
980 if (unlikely(list_empty(&ep->queue))) { in handle_xsr_succ_status()
984 req = list_entry(ep->queue.next, struct bdc_req, in handle_xsr_succ_status()
1004 short_bdi = bd_add_to_bdi(ep, deq_ptr_64); in handle_xsr_succ_status()
1016 if (!(bdi_to_tbi(ep, start_bdi) == in handle_xsr_succ_status()
1017 bdi_to_tbi(ep, short_bdi))) in handle_xsr_succ_status()
1033 end_bdi = find_end_bdi(ep, bd_xfr->next_hwd_bdi); in handle_xsr_succ_status()
1035 ep->ignore_next_sr = true; in handle_xsr_succ_status()
1038 short_bd = bdi_to_bd(ep, short_bdi); in handle_xsr_succ_status()
1055 ep->bd_list.hwd_bdi = bd_xfr->next_hwd_bdi; in handle_xsr_succ_status()
1057 dev_dbg(bdc->dev, "short xfr on %d\n", ep->ep_num); in handle_xsr_succ_status()
1061 bdc_req_complete(ep, bd_xfr->req, status); in handle_xsr_succ_status()
1096 struct bdc_ep *ep = bdc->bdc_ep_array[1]; in ep0_stall() local
1101 ep_set_halt(ep, 1); in ep0_stall()
1104 while (!list_empty(&ep->queue)) { in ep0_stall()
1105 req = list_entry(ep->queue.next, struct bdc_req, in ep0_stall()
1107 bdc_req_complete(ep, req, -ESHUTDOWN); in ep0_stall()
1239 struct bdc_ep *ep; in ep0_handle_feature() local
1296 ep = bdc->bdc_ep_array[epnum]; in ep0_handle_feature()
1297 if (!ep) in ep0_handle_feature()
1300 return ep_set_halt(ep, set); in ep0_handle_feature()
1314 struct bdc_ep *ep; in ep0_handle_status() local
1362 ep = bdc->bdc_ep_array[epnum]; in ep0_handle_status()
1363 if (!ep) { in ep0_handle_status()
1367 if (ep->flags & BDC_EP_STALL) in ep0_handle_status()
1394 struct bdc_ep *ep; in ep0_set_sel() local
1405 ep = bdc->bdc_ep_array[1]; in ep0_set_sel()
1406 bdc->ep0_req.ep = ep; in ep0_set_sel()
1424 bdc->ep0_req.ep = bdc->bdc_ep_array[1]; in ep0_queue_zlp()
1520 struct bdc_ep *ep; in bdc_xsf_ep0_data_start() local
1524 ep = bdc->bdc_ep_array[1]; in bdc_xsf_ep0_data_start()
1526 if (ep->flags & BDC_EP_STALL) { in bdc_xsf_ep0_data_start()
1527 ret = ep_set_halt(ep, 0); in bdc_xsf_ep0_data_start()
1559 struct bdc_ep *ep; in bdc_xsf_ep0_status_start() local
1565 ep = bdc->bdc_ep_array[1]; in bdc_xsf_ep0_status_start()
1571 if (ep->flags & BDC_EP_STALL) { in bdc_xsf_ep0_status_start()
1572 ret = ep_set_halt(ep, 0); in bdc_xsf_ep0_status_start()
1654 struct bdc_ep *ep; in bdc_sr_xsf() local
1659 ep = bdc->bdc_ep_array[ep_num]; in bdc_sr_xsf()
1660 if (!ep || !(ep->flags & BDC_EP_ENABLED)) { in bdc_sr_xsf()
1675 __func__, sr_status, ep->name); in bdc_sr_xsf()
1680 handle_xsr_succ_status(bdc, ep, sreport); in bdc_sr_xsf()
1723 struct bdc_ep *ep; in bdc_gadget_ep_queue() local
1733 ep = to_bdc_ep(_ep); in bdc_gadget_ep_queue()
1735 bdc = ep->bdc; in bdc_gadget_ep_queue()
1736 dev_dbg(bdc->dev, "%s ep:%p req:%p\n", __func__, ep, req); in bdc_gadget_ep_queue()
1738 _req, ep->name, _req->length, _req->zero); in bdc_gadget_ep_queue()
1740 if (!ep->usb_ep.desc) { in bdc_gadget_ep_queue()
1743 _req, ep->name); in bdc_gadget_ep_queue()
1754 if (ep == bdc->bdc_ep_array[1]) in bdc_gadget_ep_queue()
1755 ret = ep0_queue(ep, req); in bdc_gadget_ep_queue()
1757 ret = ep_queue(ep, req); in bdc_gadget_ep_queue()
1769 struct bdc_ep *ep; in bdc_gadget_ep_dequeue() local
1776 ep = to_bdc_ep(_ep); in bdc_gadget_ep_dequeue()
1778 bdc = ep->bdc; in bdc_gadget_ep_dequeue()
1779 dev_dbg(bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); in bdc_gadget_ep_dequeue()
1780 bdc_dbg_bd_list(bdc, ep); in bdc_gadget_ep_dequeue()
1783 list_for_each_entry(req, &ep->queue, queue) { in bdc_gadget_ep_dequeue()
1792 ret = ep_dequeue(ep, req); in bdc_gadget_ep_dequeue()
1797 bdc_req_complete(ep, req, -ECONNRESET); in bdc_gadget_ep_dequeue()
1800 bdc_dbg_bd_list(bdc, ep); in bdc_gadget_ep_dequeue()
1809 struct bdc_ep *ep; in bdc_gadget_ep_set_halt() local
1813 ep = to_bdc_ep(_ep); in bdc_gadget_ep_set_halt()
1814 bdc = ep->bdc; in bdc_gadget_ep_set_halt()
1815 dev_dbg(bdc->dev, "%s ep:%s value=%d\n", __func__, ep->name, value); in bdc_gadget_ep_set_halt()
1817 if (usb_endpoint_xfer_isoc(ep->usb_ep.desc)) in bdc_gadget_ep_set_halt()
1819 else if (!list_empty(&ep->queue)) in bdc_gadget_ep_set_halt()
1822 ret = ep_set_halt(ep, value); in bdc_gadget_ep_set_halt()
1833 struct bdc_ep *ep; in bdc_gadget_alloc_request() local
1839 ep = to_bdc_ep(_ep); in bdc_gadget_alloc_request()
1840 req->ep = ep; in bdc_gadget_alloc_request()
1841 req->epnum = ep->ep_num; in bdc_gadget_alloc_request()
1843 dev_dbg(ep->bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); in bdc_gadget_alloc_request()
1864 struct bdc_ep *ep; in bdc_gadget_ep_enable() local
1878 ep = to_bdc_ep(_ep); in bdc_gadget_ep_enable()
1879 bdc = ep->bdc; in bdc_gadget_ep_enable()
1882 if (ep == bdc->bdc_ep_array[1]) in bdc_gadget_ep_enable()
1890 dev_dbg(bdc->dev, "%s Enabling %s\n", __func__, ep->name); in bdc_gadget_ep_enable()
1892 ep->desc = desc; in bdc_gadget_ep_enable()
1893 ep->comp_desc = _ep->comp_desc; in bdc_gadget_ep_enable()
1894 ret = bdc_ep_enable(ep); in bdc_gadget_ep_enable()
1903 struct bdc_ep *ep; in bdc_gadget_ep_disable() local
1911 ep = to_bdc_ep(_ep); in bdc_gadget_ep_disable()
1912 bdc = ep->bdc; in bdc_gadget_ep_disable()
1915 if (ep == bdc->bdc_ep_array[1]) { in bdc_gadget_ep_disable()
1921 __func__, ep->name, ep->flags); in bdc_gadget_ep_disable()
1923 if (!(ep->flags & BDC_EP_ENABLED)) { in bdc_gadget_ep_disable()
1924 dev_warn(bdc->dev, "%s is already disabled\n", ep->name); in bdc_gadget_ep_disable()
1928 ret = bdc_ep_disable(ep); in bdc_gadget_ep_disable()
1947 struct bdc_ep *ep; in init_ep() local
1950 ep = kzalloc(sizeof(*ep), GFP_KERNEL); in init_ep()
1951 if (!ep) in init_ep()
1954 ep->bdc = bdc; in init_ep()
1955 ep->dir = dir; in init_ep()
1958 ep->usb_ep.caps.dir_in = true; in init_ep()
1960 ep->usb_ep.caps.dir_out = true; in init_ep()
1964 ep->ep_num = 1; in init_ep()
1965 bdc->bdc_ep_array[ep->ep_num] = ep; in init_ep()
1966 snprintf(ep->name, sizeof(ep->name), "ep%d", epnum - 1); in init_ep()
1967 usb_ep_set_maxpacket_limit(&ep->usb_ep, EP0_MAX_PKT_SIZE); in init_ep()
1968 ep->usb_ep.caps.type_control = true; in init_ep()
1969 ep->comp_desc = NULL; in init_ep()
1970 bdc->gadget.ep0 = &ep->usb_ep; in init_ep()
1973 ep->ep_num = epnum * 2 - 1; in init_ep()
1975 ep->ep_num = epnum * 2 - 2; in init_ep()
1977 bdc->bdc_ep_array[ep->ep_num] = ep; in init_ep()
1978 snprintf(ep->name, sizeof(ep->name), "ep%d%s", epnum - 1, in init_ep()
1981 usb_ep_set_maxpacket_limit(&ep->usb_ep, 1024); in init_ep()
1982 ep->usb_ep.caps.type_iso = true; in init_ep()
1983 ep->usb_ep.caps.type_bulk = true; in init_ep()
1984 ep->usb_ep.caps.type_int = true; in init_ep()
1985 ep->usb_ep.max_streams = 0; in init_ep()
1986 list_add_tail(&ep->usb_ep.ep_list, &bdc->gadget.ep_list); in init_ep()
1988 ep->usb_ep.ops = &bdc_gadget_ep_ops; in init_ep()
1989 ep->usb_ep.name = ep->name; in init_ep()
1990 ep->flags = 0; in init_ep()
1991 ep->ignore_next_sr = false; in init_ep()
1993 ep, ep->usb_ep.name, epnum, ep->ep_num); in init_ep()
1995 INIT_LIST_HEAD(&ep->queue); in init_ep()