Lines Matching defs:dbc

89 static void xhci_dbc_init_contexts(struct xhci_dbc *dbc, u32 string_length)
97 if (!dbc)
101 info = (struct dbc_info_context *)dbc->ctx->bytes;
102 dma = dbc->string_dma;
110 ep_ctx = dbc_bulkout_ctx(dbc);
111 max_burst = DBC_CTRL_MAXBURST(readl(&dbc->regs->control));
112 deq = dbc_bulkout_enq(dbc);
115 ep_ctx->deq = cpu_to_le64(deq | dbc->ring_out->cycle_state);
118 ep_ctx = dbc_bulkin_ctx(dbc);
119 deq = dbc_bulkin_enq(dbc);
122 ep_ctx->deq = cpu_to_le64(deq | dbc->ring_in->cycle_state);
125 lo_hi_writeq(dbc->ctx->dma, &dbc->regs->dccp);
128 writel(dev_info, &dbc->regs->devinfo1);
131 writel(dev_info, &dbc->regs->devinfo2);
135 __releases(&dbc->lock)
136 __acquires(&dbc->lock)
138 struct xhci_dbc *dbc = req->dbc;
139 struct device *dev = dbc->dev;
156 spin_unlock(&dbc->lock);
157 req->complete(dbc, req);
158 spin_lock(&dbc->lock);
182 static void xhci_dbc_flush_requests(struct xhci_dbc *dbc)
184 xhci_dbc_flush_endpoint_requests(&dbc->eps[BULK_OUT]);
185 xhci_dbc_flush_endpoint_requests(&dbc->eps[BULK_IN]);
189 dbc_alloc_request(struct xhci_dbc *dbc, unsigned int direction, gfp_t flags)
197 if (!dbc)
204 req->dbc = dbc;
251 struct xhci_dbc *dbc = req->dbc;
289 writel(DBC_DOOR_BELL_TARGET(dep->direction), &dbc->regs->doorbell);
298 struct xhci_dbc *dbc = req->dbc;
299 struct device *dev = dbc->dev;
300 struct dbc_ep *dep = &dbc->eps[req->direction];
313 dev_err(dbc->dev, "failed to map buffer\n");
319 dev_err(dbc->dev, "failed to queue trbs\n");
335 struct xhci_dbc *dbc = req->dbc;
338 if (!dbc)
345 spin_lock_irqsave(&dbc->lock, flags);
346 if (dbc->state == DS_CONFIGURED)
348 spin_unlock_irqrestore(&dbc->lock, flags);
350 mod_delayed_work(system_wq, &dbc->event_work, 0);
357 static inline void xhci_dbc_do_eps_init(struct xhci_dbc *dbc, bool direction)
361 dep = &dbc->eps[direction];
362 dep->dbc = dbc;
364 dep->ring = direction ? dbc->ring_in : dbc->ring_out;
369 static void xhci_dbc_eps_init(struct xhci_dbc *dbc)
371 xhci_dbc_do_eps_init(dbc, BULK_OUT);
372 xhci_dbc_do_eps_init(dbc, BULK_IN);
375 static void xhci_dbc_eps_exit(struct xhci_dbc *dbc)
377 memset(dbc->eps, 0, sizeof(struct dbc_ep) * ARRAY_SIZE(dbc->eps));
467 static int xhci_dbc_mem_init(struct xhci_dbc *dbc, gfp_t flags)
472 struct device *dev = dbc->dev;
475 dbc->ring_evt = xhci_dbc_ring_alloc(dev, TYPE_EVENT, flags);
476 if (!dbc->ring_evt)
479 dbc->ring_in = xhci_dbc_ring_alloc(dev, TYPE_BULK, flags);
480 if (!dbc->ring_in)
483 dbc->ring_out = xhci_dbc_ring_alloc(dev, TYPE_BULK, flags);
484 if (!dbc->ring_out)
488 ret = dbc_erst_alloc(dev, dbc->ring_evt, &dbc->erst, flags);
493 dbc->ctx = dbc_alloc_ctx(dev, flags); /* was sysdev, and is still */
494 if (!dbc->ctx)
498 dbc->string_size = sizeof(struct dbc_str_descs);
499 dbc->string = dma_alloc_coherent(dev, dbc->string_size,
500 &dbc->string_dma, flags);
501 if (!dbc->string)
505 writel(dbc->erst.erst_size, &dbc->regs->ersts);
507 lo_hi_writeq(dbc->erst.erst_dma_addr, &dbc->regs->erstba);
508 deq = xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg,
509 dbc->ring_evt->dequeue);
510 lo_hi_writeq(deq, &dbc->regs->erdp);
513 string_length = xhci_dbc_populate_strings(dbc->string);
514 xhci_dbc_init_contexts(dbc, string_length);
516 xhci_dbc_eps_init(dbc);
517 dbc->state = DS_INITIALIZED;
522 dbc_free_ctx(dev, dbc->ctx);
523 dbc->ctx = NULL;
525 dbc_erst_free(dev, &dbc->erst);
527 dbc_ring_free(dev, dbc->ring_out);
528 dbc->ring_out = NULL;
530 dbc_ring_free(dev, dbc->ring_in);
531 dbc->ring_in = NULL;
533 dbc_ring_free(dev, dbc->ring_evt);
534 dbc->ring_evt = NULL;
539 static void xhci_dbc_mem_cleanup(struct xhci_dbc *dbc)
541 if (!dbc)
544 xhci_dbc_eps_exit(dbc);
546 if (dbc->string) {
547 dma_free_coherent(dbc->dev, dbc->string_size,
548 dbc->string, dbc->string_dma);
549 dbc->string = NULL;
552 dbc_free_ctx(dbc->dev, dbc->ctx);
553 dbc->ctx = NULL;
555 dbc_erst_free(dbc->dev, &dbc->erst);
556 dbc_ring_free(dbc->dev, dbc->ring_out);
557 dbc_ring_free(dbc->dev, dbc->ring_in);
558 dbc_ring_free(dbc->dev, dbc->ring_evt);
559 dbc->ring_in = NULL;
560 dbc->ring_out = NULL;
561 dbc->ring_evt = NULL;
564 static int xhci_do_dbc_start(struct xhci_dbc *dbc)
569 if (dbc->state != DS_DISABLED)
572 writel(0, &dbc->regs->control);
573 ret = xhci_handshake(&dbc->regs->control,
579 ret = xhci_dbc_mem_init(dbc, GFP_ATOMIC);
583 ctrl = readl(&dbc->regs->control);
585 &dbc->regs->control);
586 ret = xhci_handshake(&dbc->regs->control,
592 dbc->state = DS_ENABLED;
597 static int xhci_do_dbc_stop(struct xhci_dbc *dbc)
599 if (dbc->state == DS_DISABLED)
602 writel(0, &dbc->regs->control);
603 dbc->state = DS_DISABLED;
608 static int xhci_dbc_start(struct xhci_dbc *dbc)
613 WARN_ON(!dbc);
615 pm_runtime_get_sync(dbc->dev); /* note this was self.controller */
617 spin_lock_irqsave(&dbc->lock, flags);
618 ret = xhci_do_dbc_start(dbc);
619 spin_unlock_irqrestore(&dbc->lock, flags);
622 pm_runtime_put(dbc->dev); /* note this was self.controller */
626 return mod_delayed_work(system_wq, &dbc->event_work, 1);
629 static void xhci_dbc_stop(struct xhci_dbc *dbc)
634 WARN_ON(!dbc);
636 switch (dbc->state) {
641 if (dbc->driver->disconnect)
642 dbc->driver->disconnect(dbc);
648 cancel_delayed_work_sync(&dbc->event_work);
650 spin_lock_irqsave(&dbc->lock, flags);
651 ret = xhci_do_dbc_stop(dbc);
652 spin_unlock_irqrestore(&dbc->lock, flags);
655 xhci_dbc_mem_cleanup(dbc);
656 pm_runtime_put_sync(dbc->dev); /* note, was self.controller */
661 dbc_handle_port_status(struct xhci_dbc *dbc, union xhci_trb *event)
665 portsc = readl(&dbc->regs->portsc);
667 dev_info(dbc->dev, "DbC port connect change\n");
670 dev_info(dbc->dev, "DbC port reset change\n");
673 dev_info(dbc->dev, "DbC port link status change\n");
676 dev_info(dbc->dev, "DbC config error change\n");
679 writel(portsc & ~DBC_PORTSC_RESET_CHANGE, &dbc->regs->portsc);
682 static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event)
696 get_out_ep(dbc) : get_in_ep(dbc);
710 dev_warn(dbc->dev, "tx error %d detected\n", comp_code);
714 dev_err(dbc->dev, "unknown tx error %d\n", comp_code);
728 dev_warn(dbc->dev, "no matched request\n");
750 static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
759 switch (dbc->state) {
765 portsc = readl(&dbc->regs->portsc);
767 dbc->state = DS_CONNECTED;
768 dev_info(dbc->dev, "DbC connected\n");
773 ctrl = readl(&dbc->regs->control);
775 dbc->state = DS_CONFIGURED;
776 dev_info(dbc->dev, "DbC configured\n");
777 portsc = readl(&dbc->regs->portsc);
778 writel(portsc, &dbc->regs->portsc);
785 portsc = readl(&dbc->regs->portsc);
788 dev_info(dbc->dev, "DbC cable unplugged\n");
789 dbc->state = DS_ENABLED;
790 xhci_dbc_flush_requests(dbc);
797 dev_info(dbc->dev, "DbC port reset\n");
798 writel(portsc, &dbc->regs->portsc);
799 dbc->state = DS_ENABLED;
800 xhci_dbc_flush_requests(dbc);
806 ctrl = readl(&dbc->regs->control);
809 dev_info(dbc->dev, "DbC Endpoint stall\n");
810 dbc->state = DS_STALLED;
813 dep = get_in_ep(dbc);
818 dep = get_out_ep(dbc);
827 writel(ctrl, &dbc->regs->control);
828 ctrl = readl(&dbc->regs->control);
833 ctrl = readl(&dbc->regs->control);
837 dbc->state = DS_CONFIGURED;
843 dev_err(dbc->dev, "Unknown DbC state %d\n", dbc->state);
848 evt = dbc->ring_evt->dequeue;
850 dbc->ring_evt->cycle_state) {
857 trace_xhci_dbc_handle_event(dbc->ring_evt, &evt->generic);
861 dbc_handle_port_status(dbc, evt);
864 dbc_handle_xfer_event(dbc, evt);
870 inc_evt_deq(dbc->ring_evt);
872 evt = dbc->ring_evt->dequeue;
878 deq = xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg,
879 dbc->ring_evt->dequeue);
880 lo_hi_writeq(deq, &dbc->regs->erdp);
889 struct xhci_dbc *dbc;
892 dbc = container_of(to_delayed_work(work), struct xhci_dbc, event_work);
894 spin_lock_irqsave(&dbc->lock, flags);
895 evtr = xhci_dbc_do_handle_events(dbc);
896 spin_unlock_irqrestore(&dbc->lock, flags);
900 if (dbc->driver->configure)
901 dbc->driver->configure(dbc);
904 if (dbc->driver->disconnect)
905 dbc->driver->disconnect(dbc);
910 dev_info(dbc->dev, "stop handling dbc events\n");
914 mod_delayed_work(system_wq, &dbc->event_work, 1);
922 kfree(xhci->dbc);
923 xhci->dbc = NULL;
930 struct xhci_dbc *dbc;
940 dbc = kzalloc(sizeof(*dbc), GFP_KERNEL);
941 if (!dbc)
944 dbc->regs = base + dbc_cap_offs;
947 reg = readl(&dbc->regs->control);
949 kfree(dbc);
954 if (xhci->dbc) {
956 kfree(dbc);
959 xhci->dbc = dbc;
962 dbc->xhci = xhci;
963 dbc->dev = xhci_to_hcd(xhci)->self.sysdev;
964 INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events);
965 spin_lock_init(&dbc->lock);
975 struct xhci_dbc *dbc;
979 dbc = xhci->dbc;
981 switch (dbc->state) {
1012 struct xhci_dbc *dbc;
1015 dbc = xhci->dbc;
1018 xhci_dbc_start(dbc);
1020 xhci_dbc_stop(dbc);
1027 static DEVICE_ATTR_RW(dbc);
1049 xhci_dbc_tty_remove(xhci->dbc);
1060 if (!xhci->dbc)
1064 xhci_dbc_tty_remove(xhci->dbc);
1065 xhci_dbc_stop(xhci->dbc);
1072 struct xhci_dbc *dbc = xhci->dbc;
1074 if (!dbc)
1077 if (dbc->state == DS_CONFIGURED)
1078 dbc->resume_required = 1;
1080 xhci_dbc_stop(dbc);
1088 struct xhci_dbc *dbc = xhci->dbc;
1090 if (!dbc)
1093 if (dbc->resume_required) {
1094 dbc->resume_required = 0;
1095 xhci_dbc_start(dbc);