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);
127 dev_info = (dbc->idVendor << 16) | dbc->bInterfaceProtocol;
128 writel(dev_info, &dbc->regs->devinfo1);
130 dev_info = (dbc->bcdDevice << 16) | dbc->idProduct;
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 struct xhci_dbc *dbc;
926 dbc = xhci->dbc;
928 switch (dbc->state) {
959 struct xhci_dbc *dbc;
962 dbc = xhci->dbc;
965 xhci_dbc_start(dbc);
967 xhci_dbc_stop(dbc);
978 struct xhci_dbc *dbc;
982 dbc = xhci->dbc;
984 return sprintf(buf, "%04x\n", dbc->idVendor);
991 struct xhci_dbc *dbc;
1001 dbc = xhci->dbc;
1002 if (dbc->state != DS_DISABLED)
1005 dbc->idVendor = value;
1006 ptr = &dbc->regs->devinfo1;
1018 struct xhci_dbc *dbc;
1022 dbc = xhci->dbc;
1024 return sprintf(buf, "%04x\n", dbc->idProduct);
1031 struct xhci_dbc *dbc;
1041 dbc = xhci->dbc;
1042 if (dbc->state != DS_DISABLED)
1045 dbc->idProduct = value;
1046 ptr = &dbc->regs->devinfo2;
1057 struct xhci_dbc *dbc;
1061 dbc = xhci->dbc;
1063 return sprintf(buf, "%04x\n", dbc->bcdDevice);
1070 struct xhci_dbc *dbc;
1080 dbc = xhci->dbc;
1081 if (dbc->state != DS_DISABLED)
1084 dbc->bcdDevice = value;
1085 ptr = &dbc->regs->devinfo2;
1097 struct xhci_dbc *dbc;
1101 dbc = xhci->dbc;
1103 return sprintf(buf, "%02x\n", dbc->bInterfaceProtocol);
1110 struct xhci_dbc *dbc;
1123 dbc = xhci->dbc;
1124 if (dbc->state != DS_DISABLED)
1127 dbc->bInterfaceProtocol = value;
1128 ptr = &dbc->regs->devinfo1;
1136 static DEVICE_ATTR_RW(dbc);
1158 struct xhci_dbc *dbc;
1161 dbc = kzalloc(sizeof(*dbc), GFP_KERNEL);
1162 if (!dbc)
1165 dbc->regs = base;
1166 dbc->dev = dev;
1167 dbc->driver = driver;
1168 dbc->idProduct = DBC_PRODUCT_ID;
1169 dbc->idVendor = DBC_VENDOR_ID;
1170 dbc->bcdDevice = DBC_DEVICE_REV;
1171 dbc->bInterfaceProtocol = DBC_PROTOCOL;
1173 if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE)
1176 INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events);
1177 spin_lock_init(&dbc->lock);
1183 return dbc;
1185 kfree(dbc);
1190 void xhci_dbc_remove(struct xhci_dbc *dbc)
1192 if (!dbc)
1194 /* stop hw, stop wq and call dbc->ops->stop() */
1195 xhci_dbc_stop(dbc);
1198 sysfs_remove_group(&dbc->dev->kobj, &dbc_dev_attrib_grp);
1200 kfree(dbc);
1211 /* create all parameters needed resembling a dbc device */
1220 if (xhci->dbc)
1232 if (!xhci->dbc)
1235 xhci_dbc_tty_remove(xhci->dbc);
1237 xhci->dbc = NULL;
1244 struct xhci_dbc *dbc = xhci->dbc;
1246 if (!dbc)
1249 if (dbc->state == DS_CONFIGURED)
1250 dbc->resume_required = 1;
1252 xhci_dbc_stop(dbc);
1260 struct xhci_dbc *dbc = xhci->dbc;
1262 if (!dbc)
1265 if (dbc->resume_required) {
1266 dbc->resume_required = 0;
1267 xhci_dbc_start(dbc);