Lines Matching refs:ep

32 #define CHECK(ep, expr, fmt...)					\
34 if (!(expr)) EPDBG(ep, "CHECK:" fmt); \
37 #define CHECK(ep, expr, fmt...) do { } while(0)
40 static void ast_vhub_epn_kick(struct ast_vhub_ep *ep, struct ast_vhub_req *req)
51 if (chunk > ep->ep.maxpacket)
52 chunk = ep->ep.maxpacket;
53 else if ((chunk < ep->ep.maxpacket) || !req->req.zero)
56 EPVDBG(ep, "kick req %p act=%d/%d chunk=%d last=%d\n",
63 if (ep->epn.is_in) {
64 memcpy(ep->buf, req->req.buf + act, chunk);
65 vhub_dma_workaround(ep->buf);
67 writel(ep->buf_dma, ep->epn.regs + AST_VHUB_EP_DESC_BASE);
69 if (ep->epn.is_in)
71 writel(req->req.dma + act, ep->epn.regs + AST_VHUB_EP_DESC_BASE);
77 ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
79 ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
82 static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep)
90 stat = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
93 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue);
95 EPVDBG(ep, "ACK status=%08x is_in=%d, req=%p (active=%d)\n",
96 stat, ep->epn.is_in, req, req ? req->active : 0);
111 EPDBG(ep, "DMA read pointer not 0 !\n");
122 if (!req->req.dma && !ep->epn.is_in && len) {
128 memcpy(req->req.buf + req->req.actual, ep->buf, len);
135 if (len < ep->ep.maxpacket)
141 ast_vhub_done(ep, req, status);
142 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req,
154 ast_vhub_epn_kick(ep, req);
157 static inline unsigned int ast_vhub_count_free_descs(struct ast_vhub_ep *ep)
164 return (ep->epn.d_last + AST_VHUB_DESCS_COUNT - ep->epn.d_next - 1) &
168 static void ast_vhub_epn_kick_desc(struct ast_vhub_ep *ep,
183 EPVDBG(ep, "kick act=%d/%d chunk_max=%d free_descs=%d\n",
184 act, len, ep->epn.chunk_max, ast_vhub_count_free_descs(ep));
187 while (ast_vhub_count_free_descs(ep) && req->last_desc < 0) {
191 d_num = ep->epn.d_next;
192 desc = &ep->epn.descs[d_num];
193 ep->epn.d_next = (d_num + 1) & (AST_VHUB_DESCS_COUNT - 1);
197 if (chunk <= ep->epn.chunk_max) {
201 * with ep.maxpacket. We have to see if it's a multiple
206 if (!chunk || !req->req.zero || (chunk % ep->ep.maxpacket) != 0)
209 chunk = ep->epn.chunk_max;
212 EPVDBG(ep, " chunk: act=%d/%d chunk=%d last=%d desc=%d free=%d\n",
214 ast_vhub_count_free_descs(ep));
230 if (req->last_desc >= 0 || !ast_vhub_count_free_descs(ep))
241 writel(VHUB_EP_DMA_SET_CPU_WPTR(ep->epn.d_next),
242 ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
244 EPVDBG(ep, "HW kicked, d_next=%d dstat=%08x\n",
245 ep->epn.d_next, readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS));
248 static void ast_vhub_epn_handle_ack_desc(struct ast_vhub_ep *ep)
256 stat = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
257 stat1 = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
264 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue);
266 EPVDBG(ep, "ACK status=%08x is_in=%d ep->d_last=%d..%d\n",
267 stat, ep->epn.is_in, ep->epn.d_last, d_last);
270 while (ep->epn.d_last != d_last) {
276 d_num = ep->epn.d_last;
277 desc = &ep->epn.descs[d_num];
278 ep->epn.d_last = (d_num + 1) & (AST_VHUB_DESCS_COUNT - 1);
283 EPVDBG(ep, " desc %d len=%d req=%p (act=%d)\n",
295 CHECK(ep, is_last_desc == (len < ep->ep.maxpacket ||
301 req->req.zero, ep->ep.maxpacket);
307 * d_last and ep->d_last should now be equal
309 CHECK(ep, d_last == ep->epn.d_last,
311 d_last, ep->epn.d_last);
314 ast_vhub_done(ep, req, 0);
315 req = list_first_entry_or_null(&ep->queue,
324 ast_vhub_epn_kick_desc(ep, req);
327 void ast_vhub_epn_ack_irq(struct ast_vhub_ep *ep)
329 if (ep->epn.desc_mode)
330 ast_vhub_epn_handle_ack_desc(ep);
332 ast_vhub_epn_handle_ack(ep);
339 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
340 struct ast_vhub *vhub = ep->vhub;
356 if (!ep->epn.enabled || !u_ep->desc || !ep->dev || !ep->d_idx ||
357 !ep->dev->enabled) {
358 EPDBG(ep, "Enqueuing request on wrong or disabled EP\n");
378 if (ep->epn.desc_mode ||
380 (ep->epn.is_in || !(u_req->length & (u_ep->maxpacket - 1))))) {
382 ep->epn.is_in);
391 EPVDBG(ep, "enqueue req @%p\n", req);
392 EPVDBG(ep, " l=%d dma=0x%x zero=%d noshort=%d noirq=%d is_in=%d\n",
395 ep->epn.is_in);
404 empty = list_empty(&ep->queue);
407 list_add_tail(&req->queue, &ep->queue);
409 if (ep->epn.desc_mode)
410 ast_vhub_epn_kick_desc(ep, req);
412 ast_vhub_epn_kick(ep, req);
419 static void ast_vhub_stop_active_req(struct ast_vhub_ep *ep,
425 if (ep->epn.desc_mode)
426 writel(VHUB_EP_DMA_CTRL_RESET, ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
428 writel(0, ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
432 state = readl(ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
440 dev_warn(&ep->vhub->pdev->dev, "Timeout waiting for DMA\n");
447 if (ep->epn.desc_mode) {
458 reg = VHUB_EP_DMA_SET_RPTR(ep->epn.d_next) |
459 VHUB_EP_DMA_SET_CPU_WPTR(ep->epn.d_next);
460 writel(reg, ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
463 writel(ep->epn.dma_conf,
464 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
467 writel(ep->epn.dma_conf,
468 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
474 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
475 struct ast_vhub *vhub = ep->vhub;
483 list_for_each_entry(iter, &ep->queue, queue) {
491 EPVDBG(ep, "dequeue req @%p active=%d\n",
494 ast_vhub_stop_active_req(ep, true);
495 ast_vhub_done(ep, req, -ECONNRESET);
503 void ast_vhub_update_epn_stall(struct ast_vhub_ep *ep)
507 if (WARN_ON(ep->d_idx == 0))
509 reg = readl(ep->epn.regs + AST_VHUB_EP_CONFIG);
510 if (ep->epn.stalled || ep->epn.wedged)
514 writel(reg, ep->epn.regs + AST_VHUB_EP_CONFIG);
516 if (!ep->epn.stalled && !ep->epn.wedged)
517 writel(VHUB_EP_TOGGLE_SET_EPNUM(ep->epn.g_idx),
518 ep->vhub->regs + AST_VHUB_EP_TOGGLE);
524 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
525 struct ast_vhub *vhub = ep->vhub;
528 EPDBG(ep, "Set halt (%d) & wedge (%d)\n", halt, wedge);
532 if (ep->d_idx == 0)
534 if (ep->epn.is_iso)
540 if (halt && ep->epn.is_in && !list_empty(&ep->queue)) {
544 ep->epn.stalled = halt;
545 ep->epn.wedged = wedge;
546 ast_vhub_update_epn_stall(ep);
565 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
566 struct ast_vhub *vhub = ep->vhub;
570 EPDBG(ep, "Disabling !\n");
574 ep->epn.enabled = false;
577 ast_vhub_stop_active_req(ep, false);
580 writel(0, ep->epn.regs + AST_VHUB_EP_CONFIG);
583 imask = VHUB_EP_IRQ(ep->epn.g_idx);
590 ast_vhub_nuke(ep, -ESHUTDOWN);
593 ep->ep.desc = NULL;
603 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
615 if (!ep->d_idx || !ep->dev ||
617 maxpacket == 0 || maxpacket > ep->ep.maxpacket) {
618 EPDBG(ep, "Invalid EP enable,d_idx=%d,dev=%p,type=%d,mp=%d/%d\n",
619 ep->d_idx, ep->dev, desc->bDescriptorType,
620 maxpacket, ep->ep.maxpacket);
623 if (ep->d_idx != usb_endpoint_num(desc)) {
624 EPDBG(ep, "EP number mismatch !\n");
628 if (ep->epn.enabled) {
629 EPDBG(ep, "Already enabled\n");
632 dev = ep->dev;
633 vhub = ep->vhub;
637 EPDBG(ep, "Bogus device state: driver=%p speed=%d\n",
643 ep->epn.is_in = usb_endpoint_dir_in(desc);
644 ep->ep.maxpacket = maxpacket;
646 ep->epn.d_next = ep->epn.d_last = 0;
647 ep->epn.is_iso = false;
648 ep->epn.stalled = false;
649 ep->epn.wedged = false;
651 EPDBG(ep, "Enabling [%s] %s num %d maxpacket=%d\n",
652 ep->epn.is_in ? "in" : "out", usb_ep_type_string(type),
656 ep->epn.desc_mode = ep->epn.descs && ep->epn.is_in;
657 if (ep->epn.desc_mode)
658 memset(ep->epn.descs, 0, 8 * AST_VHUB_DESCS_COUNT);
664 ep->epn.chunk_max = ep->ep.maxpacket;
665 if (ep->epn.is_in) {
666 ep->epn.chunk_max <<= 3;
667 while (ep->epn.chunk_max > 4095)
668 ep->epn.chunk_max -= ep->ep.maxpacket;
673 EPDBG(ep, "Only one control endpoint\n");
683 ep->epn.is_iso = true;
692 if (!ep->epn.is_in)
697 EPVDBG(ep, "config=%08x\n", ep_conf);
702 writel(0, ep->epn.regs + AST_VHUB_EP_CONFIG);
704 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
707 writel(ep_conf, ep->epn.regs + AST_VHUB_EP_CONFIG);
709 if (ep->epn.desc_mode) {
711 writel(0, ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
714 writel(ep->epn.descs_dma,
715 ep->epn.regs + AST_VHUB_EP_DESC_BASE);
718 ep->epn.dma_conf = VHUB_EP_DMA_DESC_MODE;
719 if (ep->epn.is_in)
720 ep->epn.dma_conf |= VHUB_EP_DMA_IN_LONG_MODE;
723 writel(ep->epn.dma_conf | VHUB_EP_DMA_CTRL_RESET,
724 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
727 writel(ep->epn.dma_conf,
728 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
731 ep->epn.dma_conf = VHUB_EP_DMA_SINGLE_STAGE;
734 writel(ep->epn.dma_conf | VHUB_EP_DMA_CTRL_RESET,
735 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
736 writel(ep->epn.dma_conf,
737 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
738 writel(0, ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
742 writel(VHUB_EP_TOGGLE_SET_EPNUM(ep->epn.g_idx),
746 imask = VHUB_EP_IRQ(ep->epn.g_idx);
753 ep->epn.enabled = true;
762 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
764 if (WARN_ON(!ep->dev || !ep->d_idx))
767 EPDBG(ep, "Releasing endpoint\n");
770 list_del_init(&ep->ep.ep_list);
773 ep->dev->epns[ep->d_idx - 1] = NULL;
776 kfree(ep->ep.name);
777 ep->ep.name = NULL;
778 dma_free_coherent(&ep->vhub->pdev->dev,
781 ep->buf, ep->buf_dma);
782 ep->buf = NULL;
783 ep->epn.descs = NULL;
786 ep->dev = NULL;
804 struct ast_vhub_ep *ep;
819 ep = &vhub->epns[i];
820 ep->dev = d;
824 INIT_LIST_HEAD(&ep->queue);
825 ep->d_idx = addr;
826 ep->vhub = vhub;
827 ep->ep.ops = &ast_vhub_epn_ops;
828 ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", addr);
829 d->epns[addr-1] = ep;
830 ep->epn.g_idx = i;
831 ep->epn.regs = vhub->regs + 0x200 + (i * 0x10);
833 ep->buf = dma_alloc_coherent(&vhub->pdev->dev,
836 &ep->buf_dma, GFP_KERNEL);
837 if (!ep->buf) {
838 kfree(ep->ep.name);
839 ep->ep.name = NULL;
842 ep->epn.descs = ep->buf + AST_VHUB_EPn_MAX_PACKET;
843 ep->epn.descs_dma = ep->buf_dma + AST_VHUB_EPn_MAX_PACKET;
845 usb_ep_set_maxpacket_limit(&ep->ep, AST_VHUB_EPn_MAX_PACKET);
846 list_add_tail(&ep->ep.ep_list, &d->gadget.ep_list);
847 ep->ep.caps.type_iso = true;
848 ep->ep.caps.type_bulk = true;
849 ep->ep.caps.type_int = true;
850 ep->ep.caps.dir_in = true;
851 ep->ep.caps.dir_out = true;
853 return ep;