Lines Matching refs:ep

33 #define CHECK(ep, expr, fmt...)					\  argument
35 if (!(expr)) EPDBG(ep, "CHECK:" fmt); \
38 #define CHECK(ep, expr, fmt...) do { } while(0) argument
41 static void ast_vhub_epn_kick(struct ast_vhub_ep *ep, struct ast_vhub_req *req) in ast_vhub_epn_kick() argument
52 if (chunk > ep->ep.maxpacket) in ast_vhub_epn_kick()
53 chunk = ep->ep.maxpacket; in ast_vhub_epn_kick()
54 else if ((chunk < ep->ep.maxpacket) || !req->req.zero) in ast_vhub_epn_kick()
57 EPVDBG(ep, "kick req %p act=%d/%d chunk=%d last=%d\n", in ast_vhub_epn_kick()
64 if (ep->epn.is_in) { in ast_vhub_epn_kick()
65 memcpy(ep->buf, req->req.buf + act, chunk); in ast_vhub_epn_kick()
66 vhub_dma_workaround(ep->buf); in ast_vhub_epn_kick()
68 writel(ep->buf_dma, ep->epn.regs + AST_VHUB_EP_DESC_BASE); in ast_vhub_epn_kick()
70 if (ep->epn.is_in) in ast_vhub_epn_kick()
72 writel(req->req.dma + act, ep->epn.regs + AST_VHUB_EP_DESC_BASE); in ast_vhub_epn_kick()
78 ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_kick()
80 ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_kick()
83 static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep) in ast_vhub_epn_handle_ack() argument
91 stat = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_handle_ack()
94 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue); in ast_vhub_epn_handle_ack()
96 EPVDBG(ep, "ACK status=%08x is_in=%d, req=%p (active=%d)\n", in ast_vhub_epn_handle_ack()
97 stat, ep->epn.is_in, req, req ? req->active : 0); in ast_vhub_epn_handle_ack()
112 EPDBG(ep, "DMA read pointer not 0 !\n"); in ast_vhub_epn_handle_ack()
123 if (!req->req.dma && !ep->epn.is_in && len) { in ast_vhub_epn_handle_ack()
129 memcpy(req->req.buf + req->req.actual, ep->buf, len); in ast_vhub_epn_handle_ack()
136 if (len < ep->ep.maxpacket) in ast_vhub_epn_handle_ack()
142 ast_vhub_done(ep, req, status); in ast_vhub_epn_handle_ack()
143 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, in ast_vhub_epn_handle_ack()
155 ast_vhub_epn_kick(ep, req); in ast_vhub_epn_handle_ack()
158 static inline unsigned int ast_vhub_count_free_descs(struct ast_vhub_ep *ep) in ast_vhub_count_free_descs() argument
165 return (ep->epn.d_last + AST_VHUB_DESCS_COUNT - ep->epn.d_next - 1) & in ast_vhub_count_free_descs()
169 static void ast_vhub_epn_kick_desc(struct ast_vhub_ep *ep, in ast_vhub_epn_kick_desc() argument
184 EPVDBG(ep, "kick act=%d/%d chunk_max=%d free_descs=%d\n", in ast_vhub_epn_kick_desc()
185 act, len, ep->epn.chunk_max, ast_vhub_count_free_descs(ep)); in ast_vhub_epn_kick_desc()
188 while (ast_vhub_count_free_descs(ep) && req->last_desc < 0) { in ast_vhub_epn_kick_desc()
192 d_num = ep->epn.d_next; in ast_vhub_epn_kick_desc()
193 desc = &ep->epn.descs[d_num]; in ast_vhub_epn_kick_desc()
194 ep->epn.d_next = (d_num + 1) & (AST_VHUB_DESCS_COUNT - 1); in ast_vhub_epn_kick_desc()
198 if (chunk <= ep->epn.chunk_max) { in ast_vhub_epn_kick_desc()
207 if (!chunk || !req->req.zero || (chunk % ep->ep.maxpacket) != 0) in ast_vhub_epn_kick_desc()
210 chunk = ep->epn.chunk_max; in ast_vhub_epn_kick_desc()
213 EPVDBG(ep, " chunk: act=%d/%d chunk=%d last=%d desc=%d free=%d\n", in ast_vhub_epn_kick_desc()
215 ast_vhub_count_free_descs(ep)); in ast_vhub_epn_kick_desc()
231 if (req->last_desc >= 0 || !ast_vhub_count_free_descs(ep)) in ast_vhub_epn_kick_desc()
242 writel(VHUB_EP_DMA_SET_CPU_WPTR(ep->epn.d_next), in ast_vhub_epn_kick_desc()
243 ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_kick_desc()
245 EPVDBG(ep, "HW kicked, d_next=%d dstat=%08x\n", in ast_vhub_epn_kick_desc()
246 ep->epn.d_next, readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS)); in ast_vhub_epn_kick_desc()
249 static void ast_vhub_epn_handle_ack_desc(struct ast_vhub_ep *ep) in ast_vhub_epn_handle_ack_desc() argument
257 stat = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_handle_ack_desc()
258 stat1 = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_handle_ack_desc()
265 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue); in ast_vhub_epn_handle_ack_desc()
267 EPVDBG(ep, "ACK status=%08x is_in=%d ep->d_last=%d..%d\n", in ast_vhub_epn_handle_ack_desc()
268 stat, ep->epn.is_in, ep->epn.d_last, d_last); in ast_vhub_epn_handle_ack_desc()
271 while (ep->epn.d_last != d_last) { in ast_vhub_epn_handle_ack_desc()
277 d_num = ep->epn.d_last; in ast_vhub_epn_handle_ack_desc()
278 desc = &ep->epn.descs[d_num]; in ast_vhub_epn_handle_ack_desc()
279 ep->epn.d_last = (d_num + 1) & (AST_VHUB_DESCS_COUNT - 1); in ast_vhub_epn_handle_ack_desc()
284 EPVDBG(ep, " desc %d len=%d req=%p (act=%d)\n", in ast_vhub_epn_handle_ack_desc()
296 CHECK(ep, is_last_desc == (len < ep->ep.maxpacket || in ast_vhub_epn_handle_ack_desc()
302 req->req.zero, ep->ep.maxpacket); in ast_vhub_epn_handle_ack_desc()
310 CHECK(ep, d_last == ep->epn.d_last, in ast_vhub_epn_handle_ack_desc()
312 d_last, ep->epn.d_last); in ast_vhub_epn_handle_ack_desc()
315 ast_vhub_done(ep, req, 0); in ast_vhub_epn_handle_ack_desc()
316 req = list_first_entry_or_null(&ep->queue, in ast_vhub_epn_handle_ack_desc()
325 ast_vhub_epn_kick_desc(ep, req); in ast_vhub_epn_handle_ack_desc()
328 void ast_vhub_epn_ack_irq(struct ast_vhub_ep *ep) in ast_vhub_epn_ack_irq() argument
330 if (ep->epn.desc_mode) in ast_vhub_epn_ack_irq()
331 ast_vhub_epn_handle_ack_desc(ep); in ast_vhub_epn_ack_irq()
333 ast_vhub_epn_handle_ack(ep); in ast_vhub_epn_ack_irq()
340 struct ast_vhub_ep *ep = to_ast_ep(u_ep); in ast_vhub_epn_queue() local
341 struct ast_vhub *vhub = ep->vhub; in ast_vhub_epn_queue()
357 if (!ep->epn.enabled || !u_ep->desc || !ep->dev || !ep->d_idx || in ast_vhub_epn_queue()
358 !ep->dev->enabled) { in ast_vhub_epn_queue()
359 EPDBG(ep, "Enqueuing request on wrong or disabled EP\n"); in ast_vhub_epn_queue()
379 if (ep->epn.desc_mode || in ast_vhub_epn_queue()
381 (ep->epn.is_in || !(u_req->length & (u_ep->maxpacket - 1))))) { in ast_vhub_epn_queue()
383 ep->epn.is_in); in ast_vhub_epn_queue()
392 EPVDBG(ep, "enqueue req @%p\n", req); in ast_vhub_epn_queue()
393 EPVDBG(ep, " l=%d dma=0x%x zero=%d noshort=%d noirq=%d is_in=%d\n", in ast_vhub_epn_queue()
396 ep->epn.is_in); in ast_vhub_epn_queue()
405 empty = list_empty(&ep->queue); in ast_vhub_epn_queue()
408 list_add_tail(&req->queue, &ep->queue); in ast_vhub_epn_queue()
410 if (ep->epn.desc_mode) in ast_vhub_epn_queue()
411 ast_vhub_epn_kick_desc(ep, req); in ast_vhub_epn_queue()
413 ast_vhub_epn_kick(ep, req); in ast_vhub_epn_queue()
420 static void ast_vhub_stop_active_req(struct ast_vhub_ep *ep, in ast_vhub_stop_active_req() argument
426 if (ep->epn.desc_mode) in ast_vhub_stop_active_req()
427 writel(VHUB_EP_DMA_CTRL_RESET, ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_stop_active_req()
429 writel(0, ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_stop_active_req()
433 state = readl(ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_stop_active_req()
441 dev_warn(&ep->vhub->pdev->dev, "Timeout waiting for DMA\n"); in ast_vhub_stop_active_req()
448 if (ep->epn.desc_mode) { in ast_vhub_stop_active_req()
459 reg = VHUB_EP_DMA_SET_RPTR(ep->epn.d_next) | in ast_vhub_stop_active_req()
460 VHUB_EP_DMA_SET_CPU_WPTR(ep->epn.d_next); in ast_vhub_stop_active_req()
461 writel(reg, ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_stop_active_req()
464 writel(ep->epn.dma_conf, in ast_vhub_stop_active_req()
465 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_stop_active_req()
468 writel(ep->epn.dma_conf, in ast_vhub_stop_active_req()
469 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_stop_active_req()
475 struct ast_vhub_ep *ep = to_ast_ep(u_ep); in ast_vhub_epn_dequeue() local
476 struct ast_vhub *vhub = ep->vhub; in ast_vhub_epn_dequeue()
484 list_for_each_entry(iter, &ep->queue, queue) { in ast_vhub_epn_dequeue()
492 EPVDBG(ep, "dequeue req @%p active=%d\n", in ast_vhub_epn_dequeue()
495 ast_vhub_stop_active_req(ep, true); in ast_vhub_epn_dequeue()
496 ast_vhub_done(ep, req, -ECONNRESET); in ast_vhub_epn_dequeue()
504 void ast_vhub_update_epn_stall(struct ast_vhub_ep *ep) in ast_vhub_update_epn_stall() argument
508 if (WARN_ON(ep->d_idx == 0)) in ast_vhub_update_epn_stall()
510 reg = readl(ep->epn.regs + AST_VHUB_EP_CONFIG); in ast_vhub_update_epn_stall()
511 if (ep->epn.stalled || ep->epn.wedged) in ast_vhub_update_epn_stall()
515 writel(reg, ep->epn.regs + AST_VHUB_EP_CONFIG); in ast_vhub_update_epn_stall()
517 if (!ep->epn.stalled && !ep->epn.wedged) in ast_vhub_update_epn_stall()
518 writel(VHUB_EP_TOGGLE_SET_EPNUM(ep->epn.g_idx), in ast_vhub_update_epn_stall()
519 ep->vhub->regs + AST_VHUB_EP_TOGGLE); in ast_vhub_update_epn_stall()
525 struct ast_vhub_ep *ep = to_ast_ep(u_ep); in ast_vhub_set_halt_and_wedge() local
526 struct ast_vhub *vhub = ep->vhub; in ast_vhub_set_halt_and_wedge()
529 EPDBG(ep, "Set halt (%d) & wedge (%d)\n", halt, wedge); in ast_vhub_set_halt_and_wedge()
533 if (ep->d_idx == 0) in ast_vhub_set_halt_and_wedge()
535 if (ep->epn.is_iso) in ast_vhub_set_halt_and_wedge()
541 if (halt && ep->epn.is_in && !list_empty(&ep->queue)) { in ast_vhub_set_halt_and_wedge()
545 ep->epn.stalled = halt; in ast_vhub_set_halt_and_wedge()
546 ep->epn.wedged = wedge; in ast_vhub_set_halt_and_wedge()
547 ast_vhub_update_epn_stall(ep); in ast_vhub_set_halt_and_wedge()
566 struct ast_vhub_ep *ep = to_ast_ep(u_ep); in ast_vhub_epn_disable() local
567 struct ast_vhub *vhub = ep->vhub; in ast_vhub_epn_disable()
571 EPDBG(ep, "Disabling !\n"); in ast_vhub_epn_disable()
575 ep->epn.enabled = false; in ast_vhub_epn_disable()
578 ast_vhub_stop_active_req(ep, false); in ast_vhub_epn_disable()
581 writel(0, ep->epn.regs + AST_VHUB_EP_CONFIG); in ast_vhub_epn_disable()
584 imask = VHUB_EP_IRQ(ep->epn.g_idx); in ast_vhub_epn_disable()
591 ast_vhub_nuke(ep, -ESHUTDOWN); in ast_vhub_epn_disable()
594 ep->ep.desc = NULL; in ast_vhub_epn_disable()
604 struct ast_vhub_ep *ep = to_ast_ep(u_ep); in ast_vhub_epn_enable() local
616 if (!ep->d_idx || !ep->dev || in ast_vhub_epn_enable()
618 maxpacket == 0 || maxpacket > ep->ep.maxpacket) { in ast_vhub_epn_enable()
619 EPDBG(ep, "Invalid EP enable,d_idx=%d,dev=%p,type=%d,mp=%d/%d\n", in ast_vhub_epn_enable()
620 ep->d_idx, ep->dev, desc->bDescriptorType, in ast_vhub_epn_enable()
621 maxpacket, ep->ep.maxpacket); in ast_vhub_epn_enable()
624 if (ep->d_idx != usb_endpoint_num(desc)) { in ast_vhub_epn_enable()
625 EPDBG(ep, "EP number mismatch !\n"); in ast_vhub_epn_enable()
629 if (ep->epn.enabled) { in ast_vhub_epn_enable()
630 EPDBG(ep, "Already enabled\n"); in ast_vhub_epn_enable()
633 dev = ep->dev; in ast_vhub_epn_enable()
634 vhub = ep->vhub; in ast_vhub_epn_enable()
638 EPDBG(ep, "Bogus device state: driver=%p speed=%d\n", in ast_vhub_epn_enable()
644 ep->epn.is_in = usb_endpoint_dir_in(desc); in ast_vhub_epn_enable()
645 ep->ep.maxpacket = maxpacket; in ast_vhub_epn_enable()
647 ep->epn.d_next = ep->epn.d_last = 0; in ast_vhub_epn_enable()
648 ep->epn.is_iso = false; in ast_vhub_epn_enable()
649 ep->epn.stalled = false; in ast_vhub_epn_enable()
650 ep->epn.wedged = false; in ast_vhub_epn_enable()
652 EPDBG(ep, "Enabling [%s] %s num %d maxpacket=%d\n", in ast_vhub_epn_enable()
653 ep->epn.is_in ? "in" : "out", usb_ep_type_string(type), in ast_vhub_epn_enable()
657 ep->epn.desc_mode = ep->epn.descs && ep->epn.is_in; in ast_vhub_epn_enable()
658 if (ep->epn.desc_mode) in ast_vhub_epn_enable()
659 memset(ep->epn.descs, 0, 8 * AST_VHUB_DESCS_COUNT); in ast_vhub_epn_enable()
665 ep->epn.chunk_max = ep->ep.maxpacket; in ast_vhub_epn_enable()
666 if (ep->epn.is_in) { in ast_vhub_epn_enable()
667 ep->epn.chunk_max <<= 3; in ast_vhub_epn_enable()
668 while (ep->epn.chunk_max > 4095) in ast_vhub_epn_enable()
669 ep->epn.chunk_max -= ep->ep.maxpacket; in ast_vhub_epn_enable()
674 EPDBG(ep, "Only one control endpoint\n"); in ast_vhub_epn_enable()
684 ep->epn.is_iso = true; in ast_vhub_epn_enable()
693 if (!ep->epn.is_in) in ast_vhub_epn_enable()
698 EPVDBG(ep, "config=%08x\n", ep_conf); in ast_vhub_epn_enable()
703 writel(0, ep->epn.regs + AST_VHUB_EP_CONFIG); in ast_vhub_epn_enable()
705 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_epn_enable()
708 writel(ep_conf, ep->epn.regs + AST_VHUB_EP_CONFIG); in ast_vhub_epn_enable()
710 if (ep->epn.desc_mode) { in ast_vhub_epn_enable()
712 writel(0, ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_enable()
715 writel(ep->epn.descs_dma, in ast_vhub_epn_enable()
716 ep->epn.regs + AST_VHUB_EP_DESC_BASE); in ast_vhub_epn_enable()
719 ep->epn.dma_conf = VHUB_EP_DMA_DESC_MODE; in ast_vhub_epn_enable()
720 if (ep->epn.is_in) in ast_vhub_epn_enable()
721 ep->epn.dma_conf |= VHUB_EP_DMA_IN_LONG_MODE; in ast_vhub_epn_enable()
724 writel(ep->epn.dma_conf | VHUB_EP_DMA_CTRL_RESET, in ast_vhub_epn_enable()
725 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_epn_enable()
728 writel(ep->epn.dma_conf, in ast_vhub_epn_enable()
729 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_epn_enable()
732 ep->epn.dma_conf = VHUB_EP_DMA_SINGLE_STAGE; in ast_vhub_epn_enable()
735 writel(ep->epn.dma_conf | VHUB_EP_DMA_CTRL_RESET, in ast_vhub_epn_enable()
736 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_epn_enable()
737 writel(ep->epn.dma_conf, in ast_vhub_epn_enable()
738 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_epn_enable()
739 writel(0, ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_enable()
743 writel(VHUB_EP_TOGGLE_SET_EPNUM(ep->epn.g_idx), in ast_vhub_epn_enable()
747 imask = VHUB_EP_IRQ(ep->epn.g_idx); in ast_vhub_epn_enable()
754 ep->epn.enabled = true; in ast_vhub_epn_enable()
763 struct ast_vhub_ep *ep = to_ast_ep(u_ep); in ast_vhub_epn_dispose() local
765 if (WARN_ON(!ep->dev || !ep->d_idx)) in ast_vhub_epn_dispose()
768 EPDBG(ep, "Releasing endpoint\n"); in ast_vhub_epn_dispose()
771 list_del_init(&ep->ep.ep_list); in ast_vhub_epn_dispose()
774 ep->dev->epns[ep->d_idx - 1] = NULL; in ast_vhub_epn_dispose()
777 kfree(ep->ep.name); in ast_vhub_epn_dispose()
778 ep->ep.name = NULL; in ast_vhub_epn_dispose()
779 dma_free_coherent(&ep->vhub->pdev->dev, in ast_vhub_epn_dispose()
782 ep->buf, ep->buf_dma); in ast_vhub_epn_dispose()
783 ep->buf = NULL; in ast_vhub_epn_dispose()
784 ep->epn.descs = NULL; in ast_vhub_epn_dispose()
787 ep->dev = NULL; in ast_vhub_epn_dispose()
805 struct ast_vhub_ep *ep; in ast_vhub_alloc_epn() local
820 ep = &vhub->epns[i]; in ast_vhub_alloc_epn()
821 ep->dev = d; in ast_vhub_alloc_epn()
825 INIT_LIST_HEAD(&ep->queue); in ast_vhub_alloc_epn()
826 ep->d_idx = addr; in ast_vhub_alloc_epn()
827 ep->vhub = vhub; in ast_vhub_alloc_epn()
828 ep->ep.ops = &ast_vhub_epn_ops; in ast_vhub_alloc_epn()
829 ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", addr); in ast_vhub_alloc_epn()
830 d->epns[addr-1] = ep; in ast_vhub_alloc_epn()
831 ep->epn.g_idx = i; in ast_vhub_alloc_epn()
832 ep->epn.regs = vhub->regs + 0x200 + (i * 0x10); in ast_vhub_alloc_epn()
834 ep->buf = dma_alloc_coherent(&vhub->pdev->dev, in ast_vhub_alloc_epn()
837 &ep->buf_dma, GFP_KERNEL); in ast_vhub_alloc_epn()
838 if (!ep->buf) { in ast_vhub_alloc_epn()
839 kfree(ep->ep.name); in ast_vhub_alloc_epn()
840 ep->ep.name = NULL; in ast_vhub_alloc_epn()
843 ep->epn.descs = ep->buf + AST_VHUB_EPn_MAX_PACKET; in ast_vhub_alloc_epn()
844 ep->epn.descs_dma = ep->buf_dma + AST_VHUB_EPn_MAX_PACKET; in ast_vhub_alloc_epn()
846 usb_ep_set_maxpacket_limit(&ep->ep, AST_VHUB_EPn_MAX_PACKET); in ast_vhub_alloc_epn()
847 list_add_tail(&ep->ep.ep_list, &d->gadget.ep_list); in ast_vhub_alloc_epn()
848 ep->ep.caps.type_iso = true; in ast_vhub_alloc_epn()
849 ep->ep.caps.type_bulk = true; in ast_vhub_alloc_epn()
850 ep->ep.caps.type_int = true; in ast_vhub_alloc_epn()
851 ep->ep.caps.dir_in = true; in ast_vhub_alloc_epn()
852 ep->ep.caps.dir_out = true; in ast_vhub_alloc_epn()
854 return ep; in ast_vhub_alloc_epn()