Lines Matching +full:bd +full:- +full:address

1 // SPDX-License-Identifier: GPL-2.0+
3 * bdc_ep.c - BRCM BDC USB3.0 device controller endpoint related functions
13 #include <linux/dma-mapping.h>
54 struct bd_list *bd_list = &ep->bd_list; in ep_bd_list_free()
55 struct bdc *bdc = ep->bdc; in ep_bd_list_free()
59 dev_dbg(bdc->dev, "%s ep:%s num_tabs:%d\n", in ep_bd_list_free()
60 __func__, ep->name, num_tabs); in ep_bd_list_free()
62 if (!bd_list->bd_table_array) { in ep_bd_list_free()
63 dev_dbg(bdc->dev, "%s already freed\n", ep->name); in ep_bd_list_free()
69 * if yes, then check if bd memory has been allocated, then in ep_bd_list_free()
72 bd_table = bd_list->bd_table_array[index]; in ep_bd_list_free()
73 dev_dbg(bdc->dev, "bd_table:%p index:%d\n", bd_table, index); in ep_bd_list_free()
75 dev_dbg(bdc->dev, "bd_table not allocated\n"); in ep_bd_list_free()
78 if (!bd_table->start_bd) { in ep_bd_list_free()
79 dev_dbg(bdc->dev, "bd dma pool not allocated\n"); in ep_bd_list_free()
83 dev_dbg(bdc->dev, in ep_bd_list_free()
85 bd_table->start_bd, in ep_bd_list_free()
86 (unsigned long long)bd_table->dma); in ep_bd_list_free()
88 dma_pool_free(bdc->bd_table_pool, in ep_bd_list_free()
89 bd_table->start_bd, in ep_bd_list_free()
90 bd_table->dma); in ep_bd_list_free()
94 /* Free the bd table array */ in ep_bd_list_free()
95 kfree(ep->bd_list.bd_table_array); in ep_bd_list_free()
99 * chain the tables, by insteting a chain bd at the end of prev_table, pointing
107 prev_table->start_bd[bd_p_tab-1].offset[0] = in chain_table()
108 cpu_to_le32(lower_32_bits(next_table->dma)); in chain_table()
110 prev_table->start_bd[bd_p_tab-1].offset[1] = in chain_table()
111 cpu_to_le32(upper_32_bits(next_table->dma)); in chain_table()
113 prev_table->start_bd[bd_p_tab-1].offset[2] = in chain_table()
116 prev_table->start_bd[bd_p_tab-1].offset[3] = in chain_table()
125 struct bdc *bdc = ep->bdc; in ep_bd_list_alloc()
129 if (usb_endpoint_xfer_isoc(ep->desc)) in ep_bd_list_alloc()
135 /* if there is only 1 table in bd list then loop chain to self */ in ep_bd_list_alloc()
136 dev_dbg(bdc->dev, in ep_bd_list_alloc()
141 ep->bd_list.bd_table_array = kcalloc(num_tabs, in ep_bd_list_alloc()
144 if (!ep->bd_list.bd_table_array) in ep_bd_list_alloc()
145 return -ENOMEM; in ep_bd_list_alloc()
154 bd_table->start_bd = dma_pool_zalloc(bdc->bd_table_pool, in ep_bd_list_alloc()
157 if (!bd_table->start_bd) { in ep_bd_list_alloc()
162 bd_table->dma = dma; in ep_bd_list_alloc()
164 dev_dbg(bdc->dev, in ep_bd_list_alloc()
166 index, bd_table->start_bd, in ep_bd_list_alloc()
167 (unsigned long long)bd_table->dma, prev_table); in ep_bd_list_alloc()
169 ep->bd_list.bd_table_array[index] = bd_table; in ep_bd_list_alloc()
175 chain_table(prev_table, ep->bd_list.bd_table_array[0], bd_p_tab); in ep_bd_list_alloc()
177 ep->bd_list.num_tabs = num_tabs; in ep_bd_list_alloc()
178 ep->bd_list.max_bdi = (num_tabs * bd_p_tab) - 1; in ep_bd_list_alloc()
179 ep->bd_list.num_tabs = num_tabs; in ep_bd_list_alloc()
180 ep->bd_list.num_bds_table = bd_p_tab; in ep_bd_list_alloc()
181 ep->bd_list.eqp_bdi = 0; in ep_bd_list_alloc()
182 ep->bd_list.hwd_bdi = 0; in ep_bd_list_alloc()
186 /* Free the bd_table_array, bd_table struct, bd's */ in ep_bd_list_alloc()
189 return -ENOMEM; in ep_bd_list_alloc()
192 /* returns how many bd's are need for this transfer */
198 /* 1 bd needed for 0 byte transfer */ in bd_needed_req()
199 if (req->usb_req.length == 0) in bd_needed_req()
202 /* remaining bytes after tranfering all max BD size BD's */ in bd_needed_req()
203 remaining = req->usb_req.length % BD_MAX_BUFF_SIZE; in bd_needed_req()
207 /* How many maximum BUFF size BD's ? */ in bd_needed_req()
208 remaining = req->usb_req.length / BD_MAX_BUFF_SIZE; in bd_needed_req()
214 /* returns the bd index(bdi) corresponding to bd dma address */
217 struct bd_list *bd_list = &ep->bd_list; in bd_add_to_bdi()
219 struct bdc *bdc = ep->bdc; in bd_add_to_bdi()
225 dev_dbg(bdc->dev, "%s %llx\n", in bd_add_to_bdi()
229 * array and compare addresses of first and last address of bd of each in bd_add_to_bdi()
232 for (tbi = 0; tbi < bd_list->num_tabs; tbi++) { in bd_add_to_bdi()
233 bd_table = bd_list->bd_table_array[tbi]; in bd_add_to_bdi()
234 dma_first_bd = bd_table->dma; in bd_add_to_bdi()
235 dma_last_bd = bd_table->dma + in bd_add_to_bdi()
237 (bd_list->num_bds_table - 1)); in bd_add_to_bdi()
238 dev_dbg(bdc->dev, "dma_first_bd:%llx dma_last_bd:%llx\n", in bd_add_to_bdi()
247 dev_err(bdc->dev, "%s FATAL err, bd not found\n", __func__); in bd_add_to_bdi()
248 return -EINVAL; in bd_add_to_bdi()
251 bdi = (bd_dma_addr - dma_first_bd) / sizeof(struct bdc_bd); in bd_add_to_bdi()
254 return (bdi + (tbi * bd_list->num_bds_table)); in bd_add_to_bdi()
262 tbi = bdi / ep->bd_list.num_bds_table; in bdi_to_tbi()
263 dev_vdbg(ep->bdc->dev, in bdi_to_tbi()
265 bdi, ep->bd_list.num_bds_table, tbi); in bdi_to_tbi()
270 /* Find the bdi last bd in the transfer */
275 end_bdi = next_hwd_bdi - 1; in find_end_bdi()
277 end_bdi = ep->bd_list.max_bdi - 1; in find_end_bdi()
278 else if ((end_bdi % (ep->bd_list.num_bds_table-1)) == 0) in find_end_bdi()
279 end_bdi--; in find_end_bdi()
285 * How many transfer bd's are available on this ep bdl, chain bds are not
290 struct bd_list *bd_list = &ep->bd_list; in bd_available_ep()
292 struct bdc *bdc = ep->bdc; in bd_available_ep()
297 /* if empty then we have all bd's available - number of chain bd's */ in bd_available_ep()
298 if (bd_list->eqp_bdi == bd_list->hwd_bdi) in bd_available_ep()
299 return bd_list->max_bdi - bd_list->num_tabs; in bd_available_ep()
303 * of avaialble bd's in bd_available_ep()
305 if (bd_list->hwd_bdi < bd_list->eqp_bdi) { in bd_available_ep()
306 /* available bd's are from eqp..max_bds + 0..dqp - chain_bds */ in bd_available_ep()
307 available1 = bd_list->max_bdi - bd_list->eqp_bdi; in bd_available_ep()
308 available2 = bd_list->hwd_bdi; in bd_available_ep()
309 chain_bd1 = available1 / bd_list->num_bds_table; in bd_available_ep()
310 chain_bd2 = available2 / bd_list->num_bds_table; in bd_available_ep()
311 dev_vdbg(bdc->dev, "chain_bd1:%d chain_bd2:%d\n", in bd_available_ep()
313 available_bd = available1 + available2 - chain_bd1 - chain_bd2; in bd_available_ep()
315 /* available bd's are from eqp..dqp - number of chain bd's */ in bd_available_ep()
316 available1 = bd_list->hwd_bdi - bd_list->eqp_bdi; in bd_available_ep()
318 if ((bd_list->hwd_bdi - bd_list->eqp_bdi) in bd_available_ep()
319 <= bd_list->num_bds_table) { in bd_available_ep()
320 /* If there any chain bd in between */ in bd_available_ep()
321 if (!(bdi_to_tbi(ep, bd_list->hwd_bdi) in bd_available_ep()
322 == bdi_to_tbi(ep, bd_list->eqp_bdi))) { in bd_available_ep()
323 available_bd = available1 - 1; in bd_available_ep()
326 chain_bd1 = available1 / bd_list->num_bds_table; in bd_available_ep()
327 available_bd = available1 - chain_bd1; in bd_available_ep()
331 * we need to keep one extra bd to check if ring is full or empty so in bd_available_ep()
334 available_bd--; in bd_available_ep()
335 dev_vdbg(bdc->dev, "available_bd:%d\n", available_bd); in bd_available_ep()
340 /* Notify the hardware after queueing the bd to bdl */
343 struct bdc_ep *ep = bdc->bdc_ep_array[epnum]; in bdc_notify_xfr()
345 dev_vdbg(bdc->dev, "%s epnum:%d\n", __func__, epnum); in bdc_notify_xfr()
350 if (unlikely(ep->flags & BDC_EP_STOP)) in bdc_notify_xfr()
351 ep->flags &= ~BDC_EP_STOP; in bdc_notify_xfr()
353 bdc_writel(bdc->regs, BDC_XSFNTF, epnum); in bdc_notify_xfr()
356 /* returns the bd corresponding to bdi */
362 local_bdi = bdi - (tbi * ep->bd_list.num_bds_table); in bdi_to_bd()
363 dev_vdbg(ep->bdc->dev, in bdi_to_bd()
367 return (ep->bd_list.bd_table_array[tbi]->start_bd + local_bdi); in bdi_to_bd()
373 ep->bd_list.eqp_bdi++; in ep_bdlist_eqp_adv()
374 /* if it's chain bd, then move to next */ in ep_bdlist_eqp_adv()
375 if (((ep->bd_list.eqp_bdi + 1) % ep->bd_list.num_bds_table) == 0) in ep_bdlist_eqp_adv()
376 ep->bd_list.eqp_bdi++; in ep_bdlist_eqp_adv()
379 if (ep->bd_list.eqp_bdi == (ep->bd_list.max_bdi + 1)) in ep_bdlist_eqp_adv()
380 ep->bd_list.eqp_bdi = 0; in ep_bdlist_eqp_adv()
383 /* Setup the first bd for ep0 transfer */
389 req->ep->dir = 0; in setup_first_bd_ep0()
390 req_len = req->usb_req.length; in setup_first_bd_ep0()
391 switch (bdc->ep0_state) { in setup_first_bd_ep0()
394 if (bdc->setup_pkt.bRequestType & USB_DIR_IN) in setup_first_bd_ep0()
398 wValue = le16_to_cpu(bdc->setup_pkt.wValue); in setup_first_bd_ep0()
400 (req_len % bdc->gadget.ep0->maxpacket == 0)) { in setup_first_bd_ep0()
401 dev_dbg(bdc->dev, "ZLP needed wVal:%d len:%d MaxP:%d\n", in setup_first_bd_ep0()
403 bdc->gadget.ep0->maxpacket); in setup_first_bd_ep0()
404 bdc->zlp_needed = true; in setup_first_bd_ep0()
410 if (!le16_to_cpu(bdc->setup_pkt.wLength) || in setup_first_bd_ep0()
411 !(bdc->setup_pkt.bRequestType & USB_DIR_IN)) in setup_first_bd_ep0()
415 dev_err(bdc->dev, in setup_first_bd_ep0()
416 "Unknown ep0 state for queueing bd ep0_state:%s\n", in setup_first_bd_ep0()
417 ep0_state_string[bdc->ep0_state]); in setup_first_bd_ep0()
418 return -EINVAL; in setup_first_bd_ep0()
424 /* Setup the bd dma descriptor for a given request */
427 dma_addr_t buf_add = req->usb_req.dma; in setup_bd_list_xfr()
432 struct bdc_bd *bd; in setup_bd_list_xfr() local
436 ep = req->ep; in setup_bd_list_xfr()
437 bd_list = &ep->bd_list; in setup_bd_list_xfr()
438 bd_xfr = &req->bd_xfr; in setup_bd_list_xfr()
439 bd_xfr->req = req; in setup_bd_list_xfr()
440 bd_xfr->start_bdi = bd_list->eqp_bdi; in setup_bd_list_xfr()
441 bd = bdi_to_bd(ep, bd_list->eqp_bdi); in setup_bd_list_xfr()
442 req_len = req->usb_req.length; in setup_bd_list_xfr()
443 maxp = usb_endpoint_maxp(ep->desc); in setup_bd_list_xfr()
444 tfs = roundup(req->usb_req.length, maxp); in setup_bd_list_xfr()
446 dev_vdbg(bdc->dev, "%s ep:%s num_bds:%d tfs:%d r_len:%d bd:%p\n", in setup_bd_list_xfr()
447 __func__, ep->name, num_bds, tfs, req_len, bd); in setup_bd_list_xfr()
451 /* First bd */ in setup_bd_list_xfr()
455 /* format of first bd for ep0 is different than other */ in setup_bd_list_xfr()
456 if (ep->ep_num == 1) { in setup_bd_list_xfr()
462 if (!req->ep->dir) in setup_bd_list_xfr()
467 req_len -= BD_MAX_BUFF_SIZE; in setup_bd_list_xfr()
469 /* this should be the last bd */ in setup_bd_list_xfr()
476 bd = bdi_to_bd(ep, ep->bd_list.eqp_bdi); in setup_bd_list_xfr()
477 if (unlikely(!bd)) { in setup_bd_list_xfr()
478 dev_err(bdc->dev, "Err bd pointing to wrong addr\n"); in setup_bd_list_xfr()
479 return -EINVAL; in setup_bd_list_xfr()
481 /* write bd */ in setup_bd_list_xfr()
482 bd->offset[0] = cpu_to_le32(lower_32_bits(buf_add)); in setup_bd_list_xfr()
483 bd->offset[1] = cpu_to_le32(upper_32_bits(buf_add)); in setup_bd_list_xfr()
484 bd->offset[2] = cpu_to_le32(dword2); in setup_bd_list_xfr()
485 bd->offset[3] = cpu_to_le32(dword3); in setup_bd_list_xfr()
490 dev_vdbg(bdc->dev, "buf_add:%08llx req_len:%d bd:%p eqp:%d\n", in setup_bd_list_xfr()
491 (unsigned long long)buf_add, req_len, bd, in setup_bd_list_xfr()
492 ep->bd_list.eqp_bdi); in setup_bd_list_xfr()
493 bd = bdi_to_bd(ep, ep->bd_list.eqp_bdi); in setup_bd_list_xfr()
494 bd->offset[3] = cpu_to_le32(BD_SBF); in setup_bd_list_xfr()
496 /* clear the STOP BD fetch bit from the first bd of this xfr */ in setup_bd_list_xfr()
497 bd = bdi_to_bd(ep, bd_xfr->start_bdi); in setup_bd_list_xfr()
498 bd->offset[3] &= cpu_to_le32(~BD_SBF); in setup_bd_list_xfr()
500 bd_xfr->num_bds = num_bds; in setup_bd_list_xfr()
501 bd_xfr->next_hwd_bdi = ep->bd_list.eqp_bdi; in setup_bd_list_xfr()
515 ep = req->ep; in bdc_queue_xfr()
516 dev_dbg(bdc->dev, "%s req:%p\n", __func__, req); in bdc_queue_xfr()
517 dev_dbg(bdc->dev, "eqp_bdi:%d hwd_bdi:%d\n", in bdc_queue_xfr()
518 ep->bd_list.eqp_bdi, ep->bd_list.hwd_bdi); in bdc_queue_xfr()
523 /* how many bd's are avaialble on ep */ in bdc_queue_xfr()
525 return -ENOMEM; in bdc_queue_xfr()
530 list_add_tail(&req->queue, &ep->queue); in bdc_queue_xfr()
532 bdc_notify_xfr(bdc, ep->ep_num); in bdc_queue_xfr()
541 struct bdc *bdc = ep->bdc; in bdc_req_complete()
546 dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status); in bdc_req_complete()
547 list_del(&req->queue); in bdc_req_complete()
548 req->usb_req.status = status; in bdc_req_complete()
549 usb_gadget_unmap_request(&bdc->gadget, &req->usb_req, ep->dir); in bdc_req_complete()
550 if (req->usb_req.complete) { in bdc_req_complete()
551 spin_unlock(&bdc->lock); in bdc_req_complete()
552 usb_gadget_giveback_request(&ep->usb_ep, &req->usb_req); in bdc_req_complete()
553 spin_lock(&bdc->lock); in bdc_req_complete()
565 bdc = ep->bdc; in bdc_ep_disable()
566 dev_dbg(bdc->dev, "%s() ep->ep_num=%d\n", __func__, ep->ep_num); in bdc_ep_disable()
568 ret = bdc_stop_ep(bdc, ep->ep_num); in bdc_ep_disable()
574 /* de-queue any pending requests */ in bdc_ep_disable()
575 while (!list_empty(&ep->queue)) { in bdc_ep_disable()
576 req = list_entry(ep->queue.next, struct bdc_req, in bdc_ep_disable()
578 bdc_req_complete(ep, req, -ESHUTDOWN); in bdc_ep_disable()
583 dev_warn(bdc->dev, in bdc_ep_disable()
586 ep->flags = 0; in bdc_ep_disable()
588 if (ep->ep_num == 1) in bdc_ep_disable()
592 ep_bd_list_free(ep, ep->bd_list.num_tabs); in bdc_ep_disable()
593 ep->desc = NULL; in bdc_ep_disable()
594 ep->comp_desc = NULL; in bdc_ep_disable()
595 ep->usb_ep.desc = NULL; in bdc_ep_disable()
596 ep->ep_type = 0; in bdc_ep_disable()
607 bdc = ep->bdc; in bdc_ep_enable()
608 dev_dbg(bdc->dev, "%s NUM_TABLES:%d %d\n", in bdc_ep_enable()
613 dev_err(bdc->dev, "ep bd list allocation failed:%d\n", ret); in bdc_ep_enable()
614 return -ENOMEM; in bdc_ep_enable()
618 if (ep->ep_num == 1) in bdc_ep_enable()
626 ep->usb_ep.maxpacket = usb_endpoint_maxp(ep->desc); in bdc_ep_enable()
627 ep->usb_ep.desc = ep->desc; in bdc_ep_enable()
628 ep->usb_ep.comp_desc = ep->comp_desc; in bdc_ep_enable()
629 ep->ep_type = usb_endpoint_type(ep->desc); in bdc_ep_enable()
630 ep->flags |= BDC_EP_ENABLED; in bdc_ep_enable()
637 /* Queue a status stage BD */
643 status_req = &bdc->status_req; in ep0_queue_status_stage()
644 ep = bdc->bdc_ep_array[1]; in ep0_queue_status_stage()
645 status_req->ep = ep; in ep0_queue_status_stage()
646 status_req->usb_req.length = 0; in ep0_queue_status_stage()
647 status_req->usb_req.status = -EINPROGRESS; in ep0_queue_status_stage()
648 status_req->usb_req.actual = 0; in ep0_queue_status_stage()
649 status_req->usb_req.complete = NULL; in ep0_queue_status_stage()
661 bdc = ep->bdc; in ep0_queue()
662 dev_dbg(bdc->dev, "%s()\n", __func__); in ep0_queue()
663 req->usb_req.actual = 0; in ep0_queue()
664 req->usb_req.status = -EINPROGRESS; in ep0_queue()
665 req->epnum = ep->ep_num; in ep0_queue()
667 if (bdc->delayed_status) { in ep0_queue()
668 bdc->delayed_status = false; in ep0_queue()
670 if (bdc->ep0_state == WAIT_FOR_STATUS_START) { in ep0_queue()
671 /* Queue a status stage BD */ in ep0_queue()
673 bdc->ep0_state = WAIT_FOR_STATUS_XMIT; in ep0_queue()
682 if (req->usb_req.length == 0) in ep0_queue()
686 ret = usb_gadget_map_request(&bdc->gadget, &req->usb_req, ep->dir); in ep0_queue()
688 dev_err(bdc->dev, "dma mapping failed %s\n", ep->name); in ep0_queue()
700 dev_dbg(bdc->dev, "%s\n", __func__); in ep0_queue_data_stage()
701 ep = bdc->bdc_ep_array[1]; in ep0_queue_data_stage()
702 bdc->ep0_req.ep = ep; in ep0_queue_data_stage()
703 bdc->ep0_req.usb_req.complete = NULL; in ep0_queue_data_stage()
705 return ep0_queue(ep, &bdc->ep0_req); in ep0_queue_data_stage()
714 if (!req || !ep->usb_ep.desc) in ep_queue()
715 return -EINVAL; in ep_queue()
717 bdc = ep->bdc; in ep_queue()
719 req->usb_req.actual = 0; in ep_queue()
720 req->usb_req.status = -EINPROGRESS; in ep_queue()
721 req->epnum = ep->ep_num; in ep_queue()
723 ret = usb_gadget_map_request(&bdc->gadget, &req->usb_req, ep->dir); in ep_queue()
725 dev_err(bdc->dev, "dma mapping failed\n"); in ep_queue()
747 bdc = ep->bdc; in ep_dequeue()
749 eqp_bdi = ep->bd_list.eqp_bdi - 1; in ep_dequeue()
752 eqp_bdi = ep->bd_list.max_bdi; in ep_dequeue()
754 start_bdi = req->bd_xfr.start_bdi; in ep_dequeue()
755 end_bdi = find_end_bdi(ep, req->bd_xfr.next_hwd_bdi); in ep_dequeue()
757 dev_dbg(bdc->dev, "%s ep:%s start:%d end:%d\n", in ep_dequeue()
758 __func__, ep->name, start_bdi, end_bdi); in ep_dequeue()
759 dev_dbg(bdc->dev, "%s ep=%p ep->desc=%p\n", __func__, in ep_dequeue()
760 ep, (void *)ep->usb_ep.desc); in ep_dequeue()
762 if (!(bdc_readl(bdc->regs, BDC_USPC) & BDC_PST_MASK)) { in ep_dequeue()
763 ret = bdc_stop_ep(bdc, ep->ep_num); in ep_dequeue()
776 tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS0); in ep_dequeue()
778 tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS1); in ep_dequeue()
781 /* we have the dma addr of next bd that will be fetched by hardware */ in ep_dequeue()
787 * curr_hw_dqpi points to actual dqp of HW and HW owns bd's from in ep_dequeue()
791 /* Check if start_bdi and end_bdi are in range of HW owned BD's */ in ep_dequeue()
808 dev_dbg(bdc->dev, in ep_dequeue()
810 start_pending, end_pending, bdc->gadget.speed); in ep_dequeue()
814 return -EINVAL; in ep_dequeue()
820 if (bdc->gadget.speed == USB_SPEED_UNKNOWN) in ep_dequeue()
822 tbi = bdi_to_tbi(ep, req->bd_xfr.next_hwd_bdi); in ep_dequeue()
823 table = ep->bd_list.bd_table_array[tbi]; in ep_dequeue()
824 next_bd_dma = table->dma + in ep_dequeue()
825 sizeof(struct bdc_bd)*(req->bd_xfr.next_hwd_bdi - in ep_dequeue()
826 tbi * ep->bd_list.num_bds_table); in ep_dequeue()
828 first_req = list_first_entry(&ep->queue, struct bdc_req, in ep_dequeue()
835 * Due to HW limitation we need to bypadd chain bd's and issue ep_bla, in ep_dequeue()
837 * then issue ep_bla instead of marking as chain bd in ep_dequeue()
841 * Mark the start bd as Chain bd, and point the chain in ep_dequeue()
842 * bd to next_bd_dma in ep_dequeue()
845 bd_start->offset[0] = cpu_to_le32(lower_32_bits(next_bd_dma)); in ep_dequeue()
846 bd_start->offset[1] = cpu_to_le32(upper_32_bits(next_bd_dma)); in ep_dequeue()
847 bd_start->offset[2] = 0x0; in ep_dequeue()
848 bd_start->offset[3] = cpu_to_le32(MARK_CHAIN_BD); in ep_dequeue()
857 dev_err(bdc->dev, "error in ep_bla:%d\n", ret); in ep_dequeue()
871 bdc = ep->bdc; in ep_set_halt()
872 dev_dbg(bdc->dev, "%s ep:%s value=%d\n", __func__, ep->name, value); in ep_set_halt()
875 dev_dbg(bdc->dev, "Halt\n"); in ep_set_halt()
876 if (ep->ep_num == 1) in ep_set_halt()
877 bdc->ep0_state = WAIT_FOR_SETUP; in ep_set_halt()
879 ret = bdc_ep_set_stall(bdc, ep->ep_num); in ep_set_halt()
881 dev_err(bdc->dev, "failed to set STALL on %s\n", in ep_set_halt()
882 ep->name); in ep_set_halt()
884 ep->flags |= BDC_EP_STALL; in ep_set_halt()
887 dev_dbg(bdc->dev, "Before Clear\n"); in ep_set_halt()
888 ret = bdc_ep_clear_stall(bdc, ep->ep_num); in ep_set_halt()
890 dev_err(bdc->dev, "failed to clear STALL on %s\n", in ep_set_halt()
891 ep->name); in ep_set_halt()
893 ep->flags &= ~BDC_EP_STALL; in ep_set_halt()
894 dev_dbg(bdc->dev, "After Clear\n"); in ep_set_halt()
906 dev_dbg(bdc->dev, "%s\n", __func__); in bdc_free_ep()
907 for (epnum = 1; epnum < bdc->num_eps; epnum++) { in bdc_free_ep()
908 ep = bdc->bdc_ep_array[epnum]; in bdc_free_ep()
912 if (ep->flags & BDC_EP_ENABLED) in bdc_free_ep()
913 ep_bd_list_free(ep, ep->bd_list.num_tabs); in bdc_free_ep()
917 list_del(&ep->usb_ep.ep_list); in bdc_free_ep()
928 usb2_pm = bdc_readl(bdc->regs, BDC_USPPM2); in bdc_set_test_mode()
930 dev_dbg(bdc->dev, "%s\n", __func__); in bdc_set_test_mode()
931 switch (bdc->test_mode) { in bdc_set_test_mode()
937 usb2_pm |= bdc->test_mode << 28; in bdc_set_test_mode()
940 return -EINVAL; in bdc_set_test_mode()
942 dev_dbg(bdc->dev, "usb2_pm=%08x", usb2_pm); in bdc_set_test_mode()
943 bdc_writel(bdc->regs, BDC_USPPM2, usb2_pm); in bdc_set_test_mode()
956 struct bd_list *bd_list = &ep->bd_list; in handle_xsr_succ_status()
966 dev_dbg(bdc->dev, "%s ep:%p\n", __func__, ep); in handle_xsr_succ_status()
969 if (ep->ignore_next_sr) { in handle_xsr_succ_status()
970 ep->ignore_next_sr = false; in handle_xsr_succ_status()
974 if (unlikely(list_empty(&ep->queue))) { in handle_xsr_succ_status()
975 dev_warn(bdc->dev, "xfr srr with no BD's queued\n"); in handle_xsr_succ_status()
978 req = list_entry(ep->queue.next, struct bdc_req, in handle_xsr_succ_status()
981 bd_xfr = &req->bd_xfr; in handle_xsr_succ_status()
982 sr_status = XSF_STS(le32_to_cpu(sreport->offset[3])); in handle_xsr_succ_status()
985 * sr_status is short and this transfer has more than 1 bd then it needs in handle_xsr_succ_status()
988 if (sr_status == XSF_SHORT && bd_xfr->num_bds > 1) { in handle_xsr_succ_status()
990 * This is multi bd xfr, lets see which bd in handle_xsr_succ_status()
994 tmp_32 = le32_to_cpu(sreport->offset[0]); in handle_xsr_succ_status()
996 tmp_32 = le32_to_cpu(sreport->offset[1]); in handle_xsr_succ_status()
1000 dev_warn(bdc->dev, "bd doesn't exist?\n"); in handle_xsr_succ_status()
1002 start_bdi = bd_xfr->start_bdi; in handle_xsr_succ_status()
1008 max_len_bds = short_bdi - start_bdi; in handle_xsr_succ_status()
1009 if (max_len_bds <= bd_list->num_bds_table) { in handle_xsr_succ_status()
1012 max_len_bds--; in handle_xsr_succ_status()
1014 chain_bds = max_len_bds/bd_list->num_bds_table; in handle_xsr_succ_status()
1015 max_len_bds -= chain_bds; in handle_xsr_succ_status()
1019 chain_bds = (bd_list->max_bdi - start_bdi)/ in handle_xsr_succ_status()
1020 bd_list->num_bds_table; in handle_xsr_succ_status()
1021 chain_bds += short_bdi/bd_list->num_bds_table; in handle_xsr_succ_status()
1022 max_len_bds = bd_list->max_bdi - start_bdi; in handle_xsr_succ_status()
1024 max_len_bds -= chain_bds; in handle_xsr_succ_status()
1027 end_bdi = find_end_bdi(ep, bd_xfr->next_hwd_bdi); in handle_xsr_succ_status()
1029 ep->ignore_next_sr = true; in handle_xsr_succ_status()
1034 length_short = le32_to_cpu(short_bd->offset[2]) & 0x1FFFFF; in handle_xsr_succ_status()
1036 length_short -= SR_BD_LEN(le32_to_cpu(sreport->offset[2])); in handle_xsr_succ_status()
1038 req->usb_req.actual = actual_length; in handle_xsr_succ_status()
1040 req->usb_req.actual = req->usb_req.length - in handle_xsr_succ_status()
1041 SR_BD_LEN(le32_to_cpu(sreport->offset[2])); in handle_xsr_succ_status()
1042 dev_dbg(bdc->dev, in handle_xsr_succ_status()
1043 "len=%d actual=%d bd_xfr->next_hwd_bdi:%d\n", in handle_xsr_succ_status()
1044 req->usb_req.length, req->usb_req.actual, in handle_xsr_succ_status()
1045 bd_xfr->next_hwd_bdi); in handle_xsr_succ_status()
1049 ep->bd_list.hwd_bdi = bd_xfr->next_hwd_bdi; in handle_xsr_succ_status()
1050 if (req->usb_req.actual < req->usb_req.length) { in handle_xsr_succ_status()
1051 dev_dbg(bdc->dev, "short xfr on %d\n", ep->ep_num); in handle_xsr_succ_status()
1052 if (req->usb_req.short_not_ok) in handle_xsr_succ_status()
1053 status = -EREMOTEIO; in handle_xsr_succ_status()
1055 bdc_req_complete(ep, bd_xfr->req, status); in handle_xsr_succ_status()
1069 dev_dbg(bdc->dev, in bdc_xsf_ep0_setup_recv()
1071 __func__, ep0_state_string[bdc->ep0_state]); in bdc_xsf_ep0_setup_recv()
1073 setup_pkt = &bdc->setup_pkt; in bdc_xsf_ep0_setup_recv()
1074 memcpy(setup_pkt, &sreport->offset[0], sizeof(*setup_pkt)); in bdc_xsf_ep0_setup_recv()
1075 len = le16_to_cpu(setup_pkt->wLength); in bdc_xsf_ep0_setup_recv()
1077 bdc->ep0_state = WAIT_FOR_STATUS_START; in bdc_xsf_ep0_setup_recv()
1079 bdc->ep0_state = WAIT_FOR_DATA_START; in bdc_xsf_ep0_setup_recv()
1082 dev_dbg(bdc->dev, in bdc_xsf_ep0_setup_recv()
1084 __func__, ep0_state_string[bdc->ep0_state]); in bdc_xsf_ep0_setup_recv()
1090 struct bdc_ep *ep = bdc->bdc_ep_array[1]; in ep0_stall()
1093 dev_dbg(bdc->dev, "%s\n", __func__); in ep0_stall()
1094 bdc->delayed_status = false; in ep0_stall()
1097 /* de-queue any pendig requests */ in ep0_stall()
1098 while (!list_empty(&ep->queue)) { in ep0_stall()
1099 req = list_entry(ep->queue.next, struct bdc_req, in ep0_stall()
1101 bdc_req_complete(ep, req, -ESHUTDOWN); in ep0_stall()
1108 enum usb_device_state state = bdc->gadget.state; in ep0_set_address()
1112 addr = le16_to_cpu(ctrl->wValue); in ep0_set_address()
1113 dev_dbg(bdc->dev, in ep0_set_address()
1118 return -EINVAL; in ep0_set_address()
1123 /* Issue Address device command */ in ep0_set_address()
1129 usb_gadget_set_state(&bdc->gadget, USB_STATE_ADDRESS); in ep0_set_address()
1131 usb_gadget_set_state(&bdc->gadget, USB_STATE_DEFAULT); in ep0_set_address()
1133 bdc->dev_addr = addr; in ep0_set_address()
1136 dev_warn(bdc->dev, in ep0_set_address()
1137 "SET Address in wrong device state %d\n", in ep0_set_address()
1139 ret = -EINVAL; in ep0_set_address()
1149 enum usb_device_state state = bdc->gadget.state; in ep0_handle_feature_dev()
1152 dev_dbg(bdc->dev, "%s set:%d dev state:%d\n", in ep0_handle_feature_dev()
1156 dev_dbg(bdc->dev, "USB_DEVICE_REMOTE_WAKEUP\n"); in ep0_handle_feature_dev()
1158 bdc->devstatus |= REMOTE_WAKE_ENABLE; in ep0_handle_feature_dev()
1160 bdc->devstatus &= ~REMOTE_WAKE_ENABLE; in ep0_handle_feature_dev()
1164 dev_dbg(bdc->dev, "USB_DEVICE_TEST_MODE\n"); in ep0_handle_feature_dev()
1166 (bdc->gadget.speed != USB_SPEED_HIGH) || !set) in ep0_handle_feature_dev()
1167 return -EINVAL; in ep0_handle_feature_dev()
1169 bdc->test_mode = wIndex >> 8; in ep0_handle_feature_dev()
1173 dev_dbg(bdc->dev, "USB_DEVICE_U1_ENABLE\n"); in ep0_handle_feature_dev()
1175 if (bdc->gadget.speed != USB_SPEED_SUPER || in ep0_handle_feature_dev()
1177 return -EINVAL; in ep0_handle_feature_dev()
1179 usppms = bdc_readl(bdc->regs, BDC_USPPMS); in ep0_handle_feature_dev()
1185 bdc->devstatus |= (1 << USB_DEV_STAT_U1_ENABLED); in ep0_handle_feature_dev()
1189 bdc->devstatus &= ~(1 << USB_DEV_STAT_U1_ENABLED); in ep0_handle_feature_dev()
1191 bdc_writel(bdc->regs, BDC_USPPMS, usppms); in ep0_handle_feature_dev()
1195 dev_dbg(bdc->dev, "USB_DEVICE_U2_ENABLE\n"); in ep0_handle_feature_dev()
1197 if (bdc->gadget.speed != USB_SPEED_SUPER || in ep0_handle_feature_dev()
1199 return -EINVAL; in ep0_handle_feature_dev()
1201 usppms = bdc_readl(bdc->regs, BDC_USPPMS); in ep0_handle_feature_dev()
1205 bdc->devstatus |= (1 << USB_DEV_STAT_U2_ENABLED); in ep0_handle_feature_dev()
1209 bdc->devstatus &= ~(1 << USB_DEV_STAT_U2_ENABLED); in ep0_handle_feature_dev()
1211 bdc_writel(bdc->regs, BDC_USPPMS, usppms); in ep0_handle_feature_dev()
1215 dev_dbg(bdc->dev, "USB_DEVICE_LTM_ENABLE?\n"); in ep0_handle_feature_dev()
1216 if (bdc->gadget.speed != USB_SPEED_SUPER || in ep0_handle_feature_dev()
1218 return -EINVAL; in ep0_handle_feature_dev()
1221 dev_err(bdc->dev, "Unknown wValue:%d\n", wValue); in ep0_handle_feature_dev()
1222 return -EOPNOTSUPP; in ep0_handle_feature_dev()
1232 enum usb_device_state state = bdc->gadget.state; in ep0_handle_feature()
1238 wValue = le16_to_cpu(setup_pkt->wValue); in ep0_handle_feature()
1239 wIndex = le16_to_cpu(setup_pkt->wIndex); in ep0_handle_feature()
1241 dev_dbg(bdc->dev, in ep0_handle_feature()
1244 bdc->gadget.speed, set); in ep0_handle_feature()
1246 switch (setup_pkt->bRequestType & USB_RECIP_MASK) { in ep0_handle_feature()
1250 dev_dbg(bdc->dev, "USB_RECIP_INTERFACE\n"); in ep0_handle_feature()
1253 return -EINVAL; in ep0_handle_feature()
1254 /* USB3 spec, Table 9-8 */ in ep0_handle_feature()
1257 dev_dbg(bdc->dev, "SET REMOTE_WAKEUP\n"); in ep0_handle_feature()
1258 bdc->devstatus |= REMOTE_WAKE_ENABLE; in ep0_handle_feature()
1260 dev_dbg(bdc->dev, "CLEAR REMOTE_WAKEUP\n"); in ep0_handle_feature()
1261 bdc->devstatus &= ~REMOTE_WAKE_ENABLE; in ep0_handle_feature()
1267 dev_dbg(bdc->dev, "USB_RECIP_ENDPOINT\n"); in ep0_handle_feature()
1269 return -EINVAL; in ep0_handle_feature()
1286 dev_dbg(bdc->dev, "ep0 stall already cleared\n"); in ep0_handle_feature()
1289 dev_dbg(bdc->dev, "epnum=%d\n", epnum); in ep0_handle_feature()
1290 ep = bdc->bdc_ep_array[epnum]; in ep0_handle_feature()
1292 return -EINVAL; in ep0_handle_feature()
1296 dev_err(bdc->dev, "Unknown recipient\n"); in ep0_handle_feature()
1297 return -EINVAL; in ep0_handle_feature()
1307 enum usb_device_state state = bdc->gadget.state; in ep0_handle_status()
1315 return -EINVAL; in ep0_handle_status()
1316 wIndex = le16_to_cpu(setup_pkt->wIndex); in ep0_handle_status()
1317 dev_dbg(bdc->dev, "%s\n", __func__); in ep0_handle_status()
1318 usb_status = bdc->devstatus; in ep0_handle_status()
1319 switch (setup_pkt->bRequestType & USB_RECIP_MASK) { in ep0_handle_status()
1321 dev_dbg(bdc->dev, in ep0_handle_status()
1323 bdc->devstatus); in ep0_handle_status()
1325 if (bdc->gadget.speed == USB_SPEED_SUPER) in ep0_handle_status()
1330 dev_dbg(bdc->dev, "USB_RECIP_INTERFACE\n"); in ep0_handle_status()
1331 if (bdc->gadget.speed == USB_SPEED_SUPER) { in ep0_handle_status()
1336 if (bdc->devstatus & REMOTE_WAKE_ENABLE) in ep0_handle_status()
1345 dev_dbg(bdc->dev, "USB_RECIP_ENDPOINT\n"); in ep0_handle_status()
1356 ep = bdc->bdc_ep_array[epnum]; in ep0_handle_status()
1358 dev_err(bdc->dev, "ISSUE, GET_STATUS for invalid EP ?"); in ep0_handle_status()
1359 return -EINVAL; in ep0_handle_status()
1361 if (ep->flags & BDC_EP_STALL) in ep0_handle_status()
1366 dev_err(bdc->dev, "Unknown recipient for get_status\n"); in ep0_handle_status()
1367 return -EINVAL; in ep0_handle_status()
1370 dev_dbg(bdc->dev, "usb_status=%08x\n", usb_status); in ep0_handle_status()
1371 *(__le16 *)bdc->ep0_response_buff = cpu_to_le16(usb_status); in ep0_handle_status()
1372 bdc->ep0_req.usb_req.length = 2; in ep0_handle_status()
1373 bdc->ep0_req.usb_req.buf = &bdc->ep0_response_buff; in ep0_handle_status()
1391 dev_dbg(bdc->dev, "%s\n", __func__); in ep0_set_sel()
1392 wLength = le16_to_cpu(setup_pkt->wLength); in ep0_set_sel()
1394 dev_err(bdc->dev, "%s Wrong wLength:%d\n", __func__, wLength); in ep0_set_sel()
1395 return -EINVAL; in ep0_set_sel()
1397 ep = bdc->bdc_ep_array[1]; in ep0_set_sel()
1398 bdc->ep0_req.ep = ep; in ep0_set_sel()
1399 bdc->ep0_req.usb_req.length = 6; in ep0_set_sel()
1400 bdc->ep0_req.usb_req.buf = bdc->ep0_response_buff; in ep0_set_sel()
1401 bdc->ep0_req.usb_req.complete = ep0_set_sel_cmpl; in ep0_set_sel()
1408 * Queue a 0 byte bd only if wLength is more than the length and length is
1409 * a multiple of MaxPacket then queue 0 byte BD
1415 dev_dbg(bdc->dev, "%s\n", __func__); in ep0_queue_zlp()
1416 bdc->ep0_req.ep = bdc->bdc_ep_array[1]; in ep0_queue_zlp()
1417 bdc->ep0_req.usb_req.length = 0; in ep0_queue_zlp()
1418 bdc->ep0_req.usb_req.complete = NULL; in ep0_queue_zlp()
1419 bdc->ep0_state = WAIT_FOR_DATA_START; in ep0_queue_zlp()
1420 ret = bdc_queue_xfr(bdc, &bdc->ep0_req); in ep0_queue_zlp()
1422 dev_err(bdc->dev, "err queueing zlp :%d\n", ret); in ep0_queue_zlp()
1425 bdc->ep0_state = WAIT_FOR_DATA_XMIT; in ep0_queue_zlp()
1433 enum usb_device_state state = bdc->gadget.state; in handle_control_request()
1439 setup_pkt = &bdc->setup_pkt; in handle_control_request()
1440 dev_dbg(bdc->dev, "%s\n", __func__); in handle_control_request()
1441 if ((setup_pkt->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { in handle_control_request()
1442 switch (setup_pkt->bRequest) { in handle_control_request()
1444 dev_dbg(bdc->dev, "USB_REQ_SET_ADDRESS\n"); in handle_control_request()
1446 bdc->devstatus &= DEVSTATUS_CLEAR; in handle_control_request()
1450 dev_dbg(bdc->dev, "USB_REQ_SET_CONFIGURATION\n"); in handle_control_request()
1452 usb_gadget_set_state(&bdc->gadget, in handle_control_request()
1459 config = le16_to_cpu(setup_pkt->wValue); in handle_control_request()
1462 &bdc->gadget, in handle_control_request()
1469 dev_dbg(bdc->dev, "USB_REQ_SET_FEATURE\n"); in handle_control_request()
1474 dev_dbg(bdc->dev, "USB_REQ_CLEAR_FEATURE\n"); in handle_control_request()
1479 dev_dbg(bdc->dev, "USB_REQ_GET_STATUS\n"); in handle_control_request()
1484 dev_dbg(bdc->dev, "USB_REQ_SET_SEL\n"); in handle_control_request()
1489 dev_warn(bdc->dev, in handle_control_request()
1501 spin_unlock(&bdc->lock); in handle_control_request()
1502 ret = bdc->gadget_driver->setup(&bdc->gadget, setup_pkt); in handle_control_request()
1503 spin_lock(&bdc->lock); in handle_control_request()
1515 dev_dbg(bdc->dev, "%s\n", __func__); in bdc_xsf_ep0_data_start()
1516 ep = bdc->bdc_ep_array[1]; in bdc_xsf_ep0_data_start()
1518 if (ep->flags & BDC_EP_STALL) { in bdc_xsf_ep0_data_start()
1523 if (bdc->ep0_state != WAIT_FOR_DATA_START) in bdc_xsf_ep0_data_start()
1524 dev_warn(bdc->dev, in bdc_xsf_ep0_data_start()
1526 ep0_state_string[bdc->ep0_state]); in bdc_xsf_ep0_data_start()
1534 bdc->delayed_status = true; in bdc_xsf_ep0_data_start()
1538 bdc->ep0_state = WAIT_FOR_DATA_XMIT; in bdc_xsf_ep0_data_start()
1539 dev_dbg(bdc->dev, in bdc_xsf_ep0_data_start()
1540 "ep0_state:%s", ep0_state_string[bdc->ep0_state]); in bdc_xsf_ep0_data_start()
1554 dev_dbg(bdc->dev, in bdc_xsf_ep0_status_start()
1556 __func__, ep0_state_string[bdc->ep0_state]); in bdc_xsf_ep0_status_start()
1557 ep = bdc->bdc_ep_array[1]; in bdc_xsf_ep0_status_start()
1560 if (bdc->zlp_needed) in bdc_xsf_ep0_status_start()
1561 bdc->zlp_needed = false; in bdc_xsf_ep0_status_start()
1563 if (ep->flags & BDC_EP_STALL) { in bdc_xsf_ep0_status_start()
1569 if ((bdc->ep0_state != WAIT_FOR_STATUS_START) && in bdc_xsf_ep0_status_start()
1570 (bdc->ep0_state != WAIT_FOR_DATA_XMIT)) in bdc_xsf_ep0_status_start()
1571 dev_err(bdc->dev, in bdc_xsf_ep0_status_start()
1573 ep0_state_string[bdc->ep0_state]); in bdc_xsf_ep0_status_start()
1576 if (bdc->ep0_state == WAIT_FOR_DATA_XMIT) { in bdc_xsf_ep0_status_start()
1577 bdc->ep0_state = STATUS_PENDING; in bdc_xsf_ep0_status_start()
1579 dev_dbg(bdc->dev, in bdc_xsf_ep0_status_start()
1583 setup_pkt = &bdc->setup_pkt; in bdc_xsf_ep0_status_start()
1589 if (!le16_to_cpu(setup_pkt->wLength)) { in bdc_xsf_ep0_status_start()
1592 bdc->delayed_status = true; in bdc_xsf_ep0_status_start()
1598 /* Queue a status stage BD */ in bdc_xsf_ep0_status_start()
1600 bdc->ep0_state = WAIT_FOR_STATUS_XMIT; in bdc_xsf_ep0_status_start()
1601 dev_dbg(bdc->dev, in bdc_xsf_ep0_status_start()
1602 "ep0_state:%s", ep0_state_string[bdc->ep0_state]); in bdc_xsf_ep0_status_start()
1612 dev_dbg(bdc->dev, "%s\n", __func__); in ep0_xsf_complete()
1613 switch (bdc->ep0_state) { in ep0_xsf_complete()
1615 bdc->ep0_state = WAIT_FOR_STATUS_START; in ep0_xsf_complete()
1618 bdc->ep0_state = WAIT_FOR_SETUP; in ep0_xsf_complete()
1619 if (bdc->test_mode) { in ep0_xsf_complete()
1622 dev_dbg(bdc->dev, "test_mode:%d\n", bdc->test_mode); in ep0_xsf_complete()
1625 dev_err(bdc->dev, "Err in setting Test mode\n"); in ep0_xsf_complete()
1628 bdc->test_mode = 0; in ep0_xsf_complete()
1636 dev_err(bdc->dev, in ep0_xsf_complete()
1638 ep0_state_string[bdc->ep0_state]); in ep0_xsf_complete()
1650 ep_num = (le32_to_cpu(sreport->offset[3])>>4) & 0x1f; in bdc_sr_xsf()
1651 ep = bdc->bdc_ep_array[ep_num]; in bdc_sr_xsf()
1652 if (!ep || !(ep->flags & BDC_EP_ENABLED)) { in bdc_sr_xsf()
1653 dev_err(bdc->dev, "xsf for ep not enabled\n"); in bdc_sr_xsf()
1657 * check if this transfer is after link went from U3->U0 due in bdc_sr_xsf()
1660 if (bdc->devstatus & FUNC_WAKE_ISSUED) { in bdc_sr_xsf()
1661 bdc->devstatus &= ~(FUNC_WAKE_ISSUED); in bdc_sr_xsf()
1662 dev_dbg(bdc->dev, "%s clearing FUNC_WAKE_ISSUED flag\n", in bdc_sr_xsf()
1665 sr_status = XSF_STS(le32_to_cpu(sreport->offset[3])); in bdc_sr_xsf()
1666 dev_dbg_ratelimited(bdc->dev, "%s sr_status=%d ep:%s\n", in bdc_sr_xsf()
1667 __func__, sr_status, ep->name); in bdc_sr_xsf()
1681 dev_err(bdc->dev, in bdc_sr_xsf()
1685 bdc->sr_xsf_ep0[sr_status - XSF_SETUP_RECV](bdc, sreport); in bdc_sr_xsf()
1690 dev_dbg(bdc->dev, "Babble on ep0 zlp_need:%d\n", in bdc_sr_xsf()
1691 bdc->zlp_needed); in bdc_sr_xsf()
1696 if (bdc->zlp_needed) { in bdc_sr_xsf()
1697 /* queue 0 length bd */ in bdc_sr_xsf()
1702 dev_warn(bdc->dev, "Babble on ep not handled\n"); in bdc_sr_xsf()
1705 dev_warn(bdc->dev, "sr status not handled:%x\n", sr_status); in bdc_sr_xsf()
1719 if (!_ep || !_ep->desc) in bdc_gadget_ep_queue()
1720 return -ESHUTDOWN; in bdc_gadget_ep_queue()
1722 if (!_req || !_req->complete || !_req->buf) in bdc_gadget_ep_queue()
1723 return -EINVAL; in bdc_gadget_ep_queue()
1727 bdc = ep->bdc; in bdc_gadget_ep_queue()
1728 dev_dbg(bdc->dev, "%s ep:%p req:%p\n", __func__, ep, req); in bdc_gadget_ep_queue()
1729 dev_dbg(bdc->dev, "queuing request %p to %s length %d zero:%d\n", in bdc_gadget_ep_queue()
1730 _req, ep->name, _req->length, _req->zero); in bdc_gadget_ep_queue()
1732 if (!ep->usb_ep.desc) { in bdc_gadget_ep_queue()
1733 dev_warn(bdc->dev, in bdc_gadget_ep_queue()
1735 _req, ep->name); in bdc_gadget_ep_queue()
1736 return -ESHUTDOWN; in bdc_gadget_ep_queue()
1739 if (_req->length > MAX_XFR_LEN) { in bdc_gadget_ep_queue()
1740 dev_warn(bdc->dev, in bdc_gadget_ep_queue()
1742 MAX_XFR_LEN, _req->length); in bdc_gadget_ep_queue()
1743 return -EOPNOTSUPP; in bdc_gadget_ep_queue()
1745 spin_lock_irqsave(&bdc->lock, flags); in bdc_gadget_ep_queue()
1746 if (ep == bdc->bdc_ep_array[1]) in bdc_gadget_ep_queue()
1751 spin_unlock_irqrestore(&bdc->lock, flags); in bdc_gadget_ep_queue()
1767 return -EINVAL; in bdc_gadget_ep_dequeue()
1771 bdc = ep->bdc; in bdc_gadget_ep_dequeue()
1772 dev_dbg(bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); in bdc_gadget_ep_dequeue()
1774 spin_lock_irqsave(&bdc->lock, flags); in bdc_gadget_ep_dequeue()
1778 list_for_each_entry(iter, &ep->queue, queue) { in bdc_gadget_ep_dequeue()
1779 if (&iter->usb_req != _req) in bdc_gadget_ep_dequeue()
1785 spin_unlock_irqrestore(&bdc->lock, flags); in bdc_gadget_ep_dequeue()
1786 dev_err(bdc->dev, "usb_req !=req n"); in bdc_gadget_ep_dequeue()
1787 return -EINVAL; in bdc_gadget_ep_dequeue()
1791 ret = -EOPNOTSUPP; in bdc_gadget_ep_dequeue()
1794 bdc_req_complete(ep, req, -ECONNRESET); in bdc_gadget_ep_dequeue()
1798 spin_unlock_irqrestore(&bdc->lock, flags); in bdc_gadget_ep_dequeue()
1811 bdc = ep->bdc; in bdc_gadget_ep_set_halt()
1812 dev_dbg(bdc->dev, "%s ep:%s value=%d\n", __func__, ep->name, value); in bdc_gadget_ep_set_halt()
1813 spin_lock_irqsave(&bdc->lock, flags); in bdc_gadget_ep_set_halt()
1814 if (usb_endpoint_xfer_isoc(ep->usb_ep.desc)) in bdc_gadget_ep_set_halt()
1815 ret = -EINVAL; in bdc_gadget_ep_set_halt()
1816 else if (!list_empty(&ep->queue)) in bdc_gadget_ep_set_halt()
1817 ret = -EAGAIN; in bdc_gadget_ep_set_halt()
1821 spin_unlock_irqrestore(&bdc->lock, flags); in bdc_gadget_ep_set_halt()
1837 req->ep = ep; in bdc_gadget_alloc_request()
1838 req->epnum = ep->ep_num; in bdc_gadget_alloc_request()
1839 req->usb_req.dma = DMA_ADDR_INVALID; in bdc_gadget_alloc_request()
1840 dev_dbg(ep->bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); in bdc_gadget_alloc_request()
1842 return &req->usb_req; in bdc_gadget_alloc_request()
1865 if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { in bdc_gadget_ep_enable()
1867 return -EINVAL; in bdc_gadget_ep_enable()
1870 if (!desc->wMaxPacketSize) { in bdc_gadget_ep_enable()
1872 return -EINVAL; in bdc_gadget_ep_enable()
1876 bdc = ep->bdc; in bdc_gadget_ep_enable()
1879 if (ep == bdc->bdc_ep_array[1]) in bdc_gadget_ep_enable()
1880 return -EINVAL; in bdc_gadget_ep_enable()
1882 if (!bdc->gadget_driver in bdc_gadget_ep_enable()
1883 || bdc->gadget.speed == USB_SPEED_UNKNOWN) { in bdc_gadget_ep_enable()
1884 return -ESHUTDOWN; in bdc_gadget_ep_enable()
1887 dev_dbg(bdc->dev, "%s Enabling %s\n", __func__, ep->name); in bdc_gadget_ep_enable()
1888 spin_lock_irqsave(&bdc->lock, flags); in bdc_gadget_ep_enable()
1889 ep->desc = desc; in bdc_gadget_ep_enable()
1890 ep->comp_desc = _ep->comp_desc; in bdc_gadget_ep_enable()
1892 spin_unlock_irqrestore(&bdc->lock, flags); in bdc_gadget_ep_enable()
1906 return -EINVAL; in bdc_gadget_ep_disable()
1909 bdc = ep->bdc; in bdc_gadget_ep_disable()
1912 if (ep == bdc->bdc_ep_array[1]) { in bdc_gadget_ep_disable()
1913 dev_warn(bdc->dev, "%s called for ep0\n", __func__); in bdc_gadget_ep_disable()
1914 return -EINVAL; in bdc_gadget_ep_disable()
1916 dev_dbg(bdc->dev, in bdc_gadget_ep_disable()
1917 "%s() ep:%s ep->flags:%08x\n", in bdc_gadget_ep_disable()
1918 __func__, ep->name, ep->flags); in bdc_gadget_ep_disable()
1920 if (!(ep->flags & BDC_EP_ENABLED)) { in bdc_gadget_ep_disable()
1921 if (bdc->gadget.speed != USB_SPEED_UNKNOWN) in bdc_gadget_ep_disable()
1922 dev_warn(bdc->dev, "%s is already disabled\n", in bdc_gadget_ep_disable()
1923 ep->name); in bdc_gadget_ep_disable()
1926 spin_lock_irqsave(&bdc->lock, flags); in bdc_gadget_ep_disable()
1928 spin_unlock_irqrestore(&bdc->lock, flags); in bdc_gadget_ep_disable()
1948 dev_dbg(bdc->dev, "%s epnum=%d dir=%d\n", __func__, epnum, dir); in init_ep()
1951 return -ENOMEM; in init_ep()
1953 ep->bdc = bdc; in init_ep()
1954 ep->dir = dir; in init_ep()
1957 ep->usb_ep.caps.dir_in = true; in init_ep()
1959 ep->usb_ep.caps.dir_out = true; in init_ep()
1961 /* ep->ep_num is the index inside bdc_ep */ in init_ep()
1963 ep->ep_num = 1; in init_ep()
1964 bdc->bdc_ep_array[ep->ep_num] = ep; in init_ep()
1965 snprintf(ep->name, sizeof(ep->name), "ep%d", epnum - 1); in init_ep()
1966 usb_ep_set_maxpacket_limit(&ep->usb_ep, EP0_MAX_PKT_SIZE); in init_ep()
1967 ep->usb_ep.caps.type_control = true; in init_ep()
1968 ep->comp_desc = NULL; in init_ep()
1969 bdc->gadget.ep0 = &ep->usb_ep; in init_ep()
1972 ep->ep_num = epnum * 2 - 1; in init_ep()
1974 ep->ep_num = epnum * 2 - 2; in init_ep()
1976 bdc->bdc_ep_array[ep->ep_num] = ep; in init_ep()
1977 snprintf(ep->name, sizeof(ep->name), "ep%d%s", epnum - 1, in init_ep()
1980 usb_ep_set_maxpacket_limit(&ep->usb_ep, 1024); in init_ep()
1981 ep->usb_ep.caps.type_iso = true; in init_ep()
1982 ep->usb_ep.caps.type_bulk = true; in init_ep()
1983 ep->usb_ep.caps.type_int = true; in init_ep()
1984 ep->usb_ep.max_streams = 0; in init_ep()
1985 list_add_tail(&ep->usb_ep.ep_list, &bdc->gadget.ep_list); in init_ep()
1987 ep->usb_ep.ops = &bdc_gadget_ep_ops; in init_ep()
1988 ep->usb_ep.name = ep->name; in init_ep()
1989 ep->flags = 0; in init_ep()
1990 ep->ignore_next_sr = false; in init_ep()
1991 dev_dbg(bdc->dev, "ep=%p ep->usb_ep.name=%s epnum=%d ep->epnum=%d\n", in init_ep()
1992 ep, ep->usb_ep.name, epnum, ep->ep_num); in init_ep()
1994 INIT_LIST_HEAD(&ep->queue); in init_ep()
2005 dev_dbg(bdc->dev, "%s()\n", __func__); in bdc_init_ep()
2006 INIT_LIST_HEAD(&bdc->gadget.ep_list); in bdc_init_ep()
2010 dev_err(bdc->dev, "init ep ep0 fail %d\n", ret); in bdc_init_ep()
2014 for (epnum = 2; epnum <= bdc->num_eps / 2; epnum++) { in bdc_init_ep()
2018 dev_err(bdc->dev, in bdc_init_ep()
2027 dev_err(bdc->dev, in bdc_init_ep()