Lines Matching refs:ep
38 #define CHECK(ep, expr, fmt...) \
40 if (!(expr)) EPDBG(ep, "CHECK:" fmt); \
43 #define CHECK(ep, expr, fmt...) do { } while(0)
46 static void ast_vhub_epn_kick(struct ast_vhub_ep *ep, struct ast_vhub_req *req)
57 if (chunk > ep->ep.maxpacket)
58 chunk = ep->ep.maxpacket;
59 else if ((chunk < ep->ep.maxpacket) || !req->req.zero)
62 EPVDBG(ep, "kick req %p act=%d/%d chunk=%d last=%d\n",
69 if (ep->epn.is_in) {
70 memcpy(ep->buf, req->req.buf + act, chunk);
71 vhub_dma_workaround(ep->buf);
73 writel(ep->buf_dma, ep->epn.regs + AST_VHUB_EP_DESC_BASE);
75 if (ep->epn.is_in)
77 writel(req->req.dma + act, ep->epn.regs + AST_VHUB_EP_DESC_BASE);
83 ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
85 ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
88 static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep)
95 stat = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
98 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue);
100 EPVDBG(ep, "ACK status=%08x is_in=%d, req=%p (active=%d)\n",
101 stat, ep->epn.is_in, req, req ? req->active : 0);
116 EPDBG(ep, "DMA read pointer not 0 !\n");
127 if (!req->req.dma && !ep->epn.is_in && len)
128 memcpy(req->req.buf + req->req.actual, ep->buf, len);
134 if (len < ep->ep.maxpacket)
139 ast_vhub_done(ep, req, 0);
140 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req,
152 ast_vhub_epn_kick(ep, req);
155 static inline unsigned int ast_vhub_count_free_descs(struct ast_vhub_ep *ep)
162 return (ep->epn.d_last + AST_VHUB_DESCS_COUNT - ep->epn.d_next - 1) &
166 static void ast_vhub_epn_kick_desc(struct ast_vhub_ep *ep,
181 EPVDBG(ep, "kick act=%d/%d chunk_max=%d free_descs=%d\n",
182 act, len, ep->epn.chunk_max, ast_vhub_count_free_descs(ep));
185 while (ast_vhub_count_free_descs(ep) && req->last_desc < 0) {
189 d_num = ep->epn.d_next;
190 desc = &ep->epn.descs[d_num];
191 ep->epn.d_next = (d_num + 1) & (AST_VHUB_DESCS_COUNT - 1);
195 if (chunk <= ep->epn.chunk_max) {
199 * with ep.maxpacket. We have to see if it's a multiple
204 if (!chunk || !req->req.zero || (chunk % ep->ep.maxpacket) != 0)
207 chunk = ep->epn.chunk_max;
210 EPVDBG(ep, " chunk: act=%d/%d chunk=%d last=%d desc=%d free=%d\n",
212 ast_vhub_count_free_descs(ep));
228 if (req->last_desc >= 0 || !ast_vhub_count_free_descs(ep))
239 writel(VHUB_EP_DMA_SET_CPU_WPTR(ep->epn.d_next),
240 ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
242 EPVDBG(ep, "HW kicked, d_next=%d dstat=%08x\n",
243 ep->epn.d_next, readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS));
246 static void ast_vhub_epn_handle_ack_desc(struct ast_vhub_ep *ep)
254 stat = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
255 stat1 = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
262 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue);
264 EPVDBG(ep, "ACK status=%08x is_in=%d ep->d_last=%d..%d\n",
265 stat, ep->epn.is_in, ep->epn.d_last, d_last);
268 while (ep->epn.d_last != d_last) {
274 d_num = ep->epn.d_last;
275 desc = &ep->epn.descs[d_num];
276 ep->epn.d_last = (d_num + 1) & (AST_VHUB_DESCS_COUNT - 1);
281 EPVDBG(ep, " desc %d len=%d req=%p (act=%d)\n",
293 CHECK(ep, is_last_desc == (len < ep->ep.maxpacket ||
299 req->req.zero, ep->ep.maxpacket);
305 * d_last and ep->d_last should now be equal
307 CHECK(ep, d_last == ep->epn.d_last,
309 d_last, ep->epn.d_last);
312 ast_vhub_done(ep, req, 0);
313 req = list_first_entry_or_null(&ep->queue,
322 ast_vhub_epn_kick_desc(ep, req);
325 void ast_vhub_epn_ack_irq(struct ast_vhub_ep *ep)
327 if (ep->epn.desc_mode)
328 ast_vhub_epn_handle_ack_desc(ep);
330 ast_vhub_epn_handle_ack(ep);
337 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
338 struct ast_vhub *vhub = ep->vhub;
354 if (!ep->epn.enabled || !u_ep->desc || !ep->dev || !ep->d_idx ||
355 !ep->dev->enabled) {
356 EPDBG(ep, "Enqueuing request on wrong or disabled EP\n");
376 if (ep->epn.desc_mode ||
378 (ep->epn.is_in || !(u_req->length & (u_ep->maxpacket - 1))))) {
380 ep->epn.is_in);
389 EPVDBG(ep, "enqueue req @%p\n", req);
390 EPVDBG(ep, " l=%d dma=0x%x zero=%d noshort=%d noirq=%d is_in=%d\n",
393 ep->epn.is_in);
402 empty = list_empty(&ep->queue);
405 list_add_tail(&req->queue, &ep->queue);
407 if (ep->epn.desc_mode)
408 ast_vhub_epn_kick_desc(ep, req);
410 ast_vhub_epn_kick(ep, req);
417 static void ast_vhub_stop_active_req(struct ast_vhub_ep *ep,
423 if (ep->epn.desc_mode)
424 writel(VHUB_EP_DMA_CTRL_RESET, ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
426 writel(0, ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
430 state = readl(ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
438 dev_warn(&ep->vhub->pdev->dev, "Timeout waiting for DMA\n");
445 if (ep->epn.desc_mode) {
456 reg = VHUB_EP_DMA_SET_RPTR(ep->epn.d_next) |
457 VHUB_EP_DMA_SET_CPU_WPTR(ep->epn.d_next);
458 writel(reg, ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
461 writel(ep->epn.dma_conf,
462 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
465 writel(ep->epn.dma_conf,
466 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
472 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
473 struct ast_vhub *vhub = ep->vhub;
481 list_for_each_entry (req, &ep->queue, queue) {
487 EPVDBG(ep, "dequeue req @%p active=%d\n",
490 ast_vhub_stop_active_req(ep, true);
491 ast_vhub_done(ep, req, -ECONNRESET);
499 void ast_vhub_update_epn_stall(struct ast_vhub_ep *ep)
503 if (WARN_ON(ep->d_idx == 0))
505 reg = readl(ep->epn.regs + AST_VHUB_EP_CONFIG);
506 if (ep->epn.stalled || ep->epn.wedged)
510 writel(reg, ep->epn.regs + AST_VHUB_EP_CONFIG);
512 if (!ep->epn.stalled && !ep->epn.wedged)
513 writel(VHUB_EP_TOGGLE_SET_EPNUM(ep->epn.g_idx),
514 ep->vhub->regs + AST_VHUB_EP_TOGGLE);
520 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
521 struct ast_vhub *vhub = ep->vhub;
524 EPDBG(ep, "Set halt (%d) & wedge (%d)\n", halt, wedge);
528 if (ep->d_idx == 0)
530 if (ep->epn.is_iso)
536 if (halt && ep->epn.is_in && !list_empty(&ep->queue)) {
540 ep->epn.stalled = halt;
541 ep->epn.wedged = wedge;
542 ast_vhub_update_epn_stall(ep);
561 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
562 struct ast_vhub *vhub = ep->vhub;
566 EPDBG(ep, "Disabling !\n");
570 ep->epn.enabled = false;
573 ast_vhub_stop_active_req(ep, false);
576 writel(0, ep->epn.regs + AST_VHUB_EP_CONFIG);
579 imask = VHUB_EP_IRQ(ep->epn.g_idx);
586 ast_vhub_nuke(ep, -ESHUTDOWN);
589 ep->ep.desc = NULL;
599 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
611 if (!ep->d_idx || !ep->dev ||
613 maxpacket == 0 || maxpacket > ep->ep.maxpacket) {
614 EPDBG(ep, "Invalid EP enable,d_idx=%d,dev=%p,type=%d,mp=%d/%d\n",
615 ep->d_idx, ep->dev, desc->bDescriptorType,
616 maxpacket, ep->ep.maxpacket);
619 if (ep->d_idx != usb_endpoint_num(desc)) {
620 EPDBG(ep, "EP number mismatch !\n");
624 if (ep->epn.enabled) {
625 EPDBG(ep, "Already enabled\n");
628 dev = ep->dev;
629 vhub = ep->vhub;
633 EPDBG(ep, "Bogus device state: driver=%p speed=%d\n",
639 ep->epn.is_in = usb_endpoint_dir_in(desc);
640 ep->ep.maxpacket = maxpacket;
642 ep->epn.d_next = ep->epn.d_last = 0;
643 ep->epn.is_iso = false;
644 ep->epn.stalled = false;
645 ep->epn.wedged = false;
647 EPDBG(ep, "Enabling [%s] %s num %d maxpacket=%d\n",
648 ep->epn.is_in ? "in" : "out", usb_ep_type_string(type),
652 ep->epn.desc_mode = ep->epn.descs && ep->epn.is_in;
653 if (ep->epn.desc_mode)
654 memset(ep->epn.descs, 0, 8 * AST_VHUB_DESCS_COUNT);
660 ep->epn.chunk_max = ep->ep.maxpacket;
661 if (ep->epn.is_in) {
662 ep->epn.chunk_max <<= 3;
663 while (ep->epn.chunk_max > 4095)
664 ep->epn.chunk_max -= ep->ep.maxpacket;
669 EPDBG(ep, "Only one control endpoint\n");
679 ep->epn.is_iso = true;
688 if (!ep->epn.is_in)
693 EPVDBG(ep, "config=%08x\n", ep_conf);
698 writel(0, ep->epn.regs + AST_VHUB_EP_CONFIG);
700 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
703 writel(ep_conf, ep->epn.regs + AST_VHUB_EP_CONFIG);
705 if (ep->epn.desc_mode) {
707 writel(0, ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
710 writel(ep->epn.descs_dma,
711 ep->epn.regs + AST_VHUB_EP_DESC_BASE);
714 ep->epn.dma_conf = VHUB_EP_DMA_DESC_MODE;
715 if (ep->epn.is_in)
716 ep->epn.dma_conf |= VHUB_EP_DMA_IN_LONG_MODE;
719 writel(ep->epn.dma_conf | VHUB_EP_DMA_CTRL_RESET,
720 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
723 writel(ep->epn.dma_conf,
724 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
727 ep->epn.dma_conf = VHUB_EP_DMA_SINGLE_STAGE;
730 writel(ep->epn.dma_conf | VHUB_EP_DMA_CTRL_RESET,
731 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
732 writel(ep->epn.dma_conf,
733 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT);
734 writel(0, ep->epn.regs + AST_VHUB_EP_DESC_STATUS);
738 writel(VHUB_EP_TOGGLE_SET_EPNUM(ep->epn.g_idx),
742 imask = VHUB_EP_IRQ(ep->epn.g_idx);
749 ep->epn.enabled = true;
758 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
760 if (WARN_ON(!ep->dev || !ep->d_idx))
763 EPDBG(ep, "Releasing endpoint\n");
766 list_del_init(&ep->ep.ep_list);
769 ep->dev->epns[ep->d_idx - 1] = NULL;
772 kfree(ep->ep.name);
773 ep->ep.name = NULL;
774 dma_free_coherent(&ep->vhub->pdev->dev,
777 ep->buf, ep->buf_dma);
778 ep->buf = NULL;
779 ep->epn.descs = NULL;
782 ep->dev = NULL;
800 struct ast_vhub_ep *ep;
815 ep = &vhub->epns[i];
816 ep->dev = d;
820 INIT_LIST_HEAD(&ep->queue);
821 ep->d_idx = addr;
822 ep->vhub = vhub;
823 ep->ep.ops = &ast_vhub_epn_ops;
824 ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", addr);
825 d->epns[addr-1] = ep;
826 ep->epn.g_idx = i;
827 ep->epn.regs = vhub->regs + 0x200 + (i * 0x10);
829 ep->buf = dma_alloc_coherent(&vhub->pdev->dev,
832 &ep->buf_dma, GFP_KERNEL);
833 if (!ep->buf) {
834 kfree(ep->ep.name);
835 ep->ep.name = NULL;
838 ep->epn.descs = ep->buf + AST_VHUB_EPn_MAX_PACKET;
839 ep->epn.descs_dma = ep->buf_dma + AST_VHUB_EPn_MAX_PACKET;
841 usb_ep_set_maxpacket_limit(&ep->ep, AST_VHUB_EPn_MAX_PACKET);
842 list_add_tail(&ep->ep.ep_list, &d->gadget.ep_list);
843 ep->ep.caps.type_iso = true;
844 ep->ep.caps.type_bulk = true;
845 ep->ep.caps.type_int = true;
846 ep->ep.caps.dir_in = true;
847 ep->ep.caps.dir_out = true;
849 return ep;