Lines Matching +full:generic +full:- +full:xhci

1 // SPDX-License-Identifier: GPL-2.0
3 * xhci-dbgcap.c - xHCI debug capability support
9 #include <linux/dma-mapping.h>
13 #include "xhci.h"
14 #include "xhci-trace.h"
15 #include "xhci-dbgcap.h"
21 dma_free_coherent(dev, ctx->size, ctx->bytes, ctx->dma); in dbc_free_ctx()
31 if (ring->first_seg && ring->first_seg->trbs) { in dbc_ring_free()
33 ring->first_seg->trbs, in dbc_ring_free()
34 ring->first_seg->dma); in dbc_ring_free()
35 kfree(ring->first_seg); in dbc_ring_free()
46 s_desc = (struct usb_string_descriptor *)strings->serial; in xhci_dbc_populate_strings()
48 UTF16_LITTLE_ENDIAN, (wchar_t *)s_desc->wData, in xhci_dbc_populate_strings()
51 s_desc->bLength = (strlen(DBC_STRING_SERIAL) + 1) * 2; in xhci_dbc_populate_strings()
52 s_desc->bDescriptorType = USB_DT_STRING; in xhci_dbc_populate_strings()
53 string_length = s_desc->bLength; in xhci_dbc_populate_strings()
57 s_desc = (struct usb_string_descriptor *)strings->product; in xhci_dbc_populate_strings()
59 UTF16_LITTLE_ENDIAN, (wchar_t *)s_desc->wData, in xhci_dbc_populate_strings()
62 s_desc->bLength = (strlen(DBC_STRING_PRODUCT) + 1) * 2; in xhci_dbc_populate_strings()
63 s_desc->bDescriptorType = USB_DT_STRING; in xhci_dbc_populate_strings()
64 string_length += s_desc->bLength; in xhci_dbc_populate_strings()
68 s_desc = (struct usb_string_descriptor *)strings->manufacturer; in xhci_dbc_populate_strings()
71 UTF16_LITTLE_ENDIAN, (wchar_t *)s_desc->wData, in xhci_dbc_populate_strings()
74 s_desc->bLength = (strlen(DBC_STRING_MANUFACTURER) + 1) * 2; in xhci_dbc_populate_strings()
75 s_desc->bDescriptorType = USB_DT_STRING; in xhci_dbc_populate_strings()
76 string_length += s_desc->bLength; in xhci_dbc_populate_strings()
80 strings->string0[0] = 4; in xhci_dbc_populate_strings()
81 strings->string0[1] = USB_DT_STRING; in xhci_dbc_populate_strings()
82 strings->string0[2] = 0x09; in xhci_dbc_populate_strings()
83 strings->string0[3] = 0x04; in xhci_dbc_populate_strings()
101 info = (struct dbc_info_context *)dbc->ctx->bytes; in xhci_dbc_init_contexts()
102 dma = dbc->string_dma; in xhci_dbc_init_contexts()
103 info->string0 = cpu_to_le64(dma); in xhci_dbc_init_contexts()
104 info->manufacturer = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH); in xhci_dbc_init_contexts()
105 info->product = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH * 2); in xhci_dbc_init_contexts()
106 info->serial = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH * 3); in xhci_dbc_init_contexts()
107 info->length = cpu_to_le32(string_length); in xhci_dbc_init_contexts()
111 max_burst = DBC_CTRL_MAXBURST(readl(&dbc->regs->control)); in xhci_dbc_init_contexts()
113 ep_ctx->ep_info = 0; in xhci_dbc_init_contexts()
114 ep_ctx->ep_info2 = dbc_epctx_info2(BULK_OUT_EP, 1024, max_burst); in xhci_dbc_init_contexts()
115 ep_ctx->deq = cpu_to_le64(deq | dbc->ring_out->cycle_state); in xhci_dbc_init_contexts()
120 ep_ctx->ep_info = 0; in xhci_dbc_init_contexts()
121 ep_ctx->ep_info2 = dbc_epctx_info2(BULK_IN_EP, 1024, max_burst); in xhci_dbc_init_contexts()
122 ep_ctx->deq = cpu_to_le64(deq | dbc->ring_in->cycle_state); in xhci_dbc_init_contexts()
125 lo_hi_writeq(dbc->ctx->dma, &dbc->regs->dccp); in xhci_dbc_init_contexts()
127 dev_info = (dbc->idVendor << 16) | dbc->bInterfaceProtocol; in xhci_dbc_init_contexts()
128 writel(dev_info, &dbc->regs->devinfo1); in xhci_dbc_init_contexts()
130 dev_info = (dbc->bcdDevice << 16) | dbc->idProduct; in xhci_dbc_init_contexts()
131 writel(dev_info, &dbc->regs->devinfo2); in xhci_dbc_init_contexts()
135 __releases(&dbc->lock) in xhci_dbc_giveback()
136 __acquires(&dbc->lock) in xhci_dbc_giveback()
138 struct xhci_dbc *dbc = req->dbc; in xhci_dbc_giveback()
139 struct device *dev = dbc->dev; in xhci_dbc_giveback()
141 list_del_init(&req->list_pending); in xhci_dbc_giveback()
142 req->trb_dma = 0; in xhci_dbc_giveback()
143 req->trb = NULL; in xhci_dbc_giveback()
145 if (req->status == -EINPROGRESS) in xhci_dbc_giveback()
146 req->status = status; in xhci_dbc_giveback()
151 req->dma, in xhci_dbc_giveback()
152 req->length, in xhci_dbc_giveback()
156 spin_unlock(&dbc->lock); in xhci_dbc_giveback()
157 req->complete(dbc, req); in xhci_dbc_giveback()
158 spin_lock(&dbc->lock); in xhci_dbc_giveback()
163 trb->generic.field[0] = 0; in trb_to_noop()
164 trb->generic.field[1] = 0; in trb_to_noop()
165 trb->generic.field[2] = 0; in trb_to_noop()
166 trb->generic.field[3] &= cpu_to_le32(TRB_CYCLE); in trb_to_noop()
167 trb->generic.field[3] |= cpu_to_le32(TRB_TYPE(TRB_TR_NOOP)); in trb_to_noop()
172 trb_to_noop(req->trb); in xhci_dbc_flush_single_request()
173 xhci_dbc_giveback(req, -ESHUTDOWN); in xhci_dbc_flush_single_request()
180 list_for_each_entry_safe(req, tmp, &dep->list_pending, list_pending) in xhci_dbc_flush_endpoint_requests()
186 xhci_dbc_flush_endpoint_requests(&dbc->eps[BULK_OUT]); in xhci_dbc_flush_requests()
187 xhci_dbc_flush_endpoint_requests(&dbc->eps[BULK_IN]); in xhci_dbc_flush_requests()
206 req->dbc = dbc; in dbc_alloc_request()
207 INIT_LIST_HEAD(&req->list_pending); in dbc_alloc_request()
208 INIT_LIST_HEAD(&req->list_pool); in dbc_alloc_request()
209 req->direction = direction; in dbc_alloc_request()
230 trb = ring->enqueue; in xhci_dbc_queue_trb()
231 trb->generic.field[0] = cpu_to_le32(field1); in xhci_dbc_queue_trb()
232 trb->generic.field[1] = cpu_to_le32(field2); in xhci_dbc_queue_trb()
233 trb->generic.field[2] = cpu_to_le32(field3); in xhci_dbc_queue_trb()
234 trb->generic.field[3] = cpu_to_le32(field4); in xhci_dbc_queue_trb()
236 trace_xhci_dbc_gadget_ep_queue(ring, &trb->generic); in xhci_dbc_queue_trb()
238 ring->num_trbs_free--; in xhci_dbc_queue_trb()
239 next = ++(ring->enqueue); in xhci_dbc_queue_trb()
240 if (TRB_TYPE_LINK_LE32(next->link.control)) { in xhci_dbc_queue_trb()
241 next->link.control ^= cpu_to_le32(TRB_CYCLE); in xhci_dbc_queue_trb()
242 ring->enqueue = ring->enq_seg->trbs; in xhci_dbc_queue_trb()
243 ring->cycle_state ^= 1; in xhci_dbc_queue_trb()
253 struct xhci_dbc *dbc = req->dbc; in xhci_dbc_queue_bulk_tx()
254 struct xhci_ring *ring = dep->ring; in xhci_dbc_queue_bulk_tx()
257 num_trbs = count_trbs(req->dma, req->length); in xhci_dbc_queue_bulk_tx()
259 if (ring->num_trbs_free < num_trbs) in xhci_dbc_queue_bulk_tx()
260 return -EBUSY; in xhci_dbc_queue_bulk_tx()
262 addr = req->dma; in xhci_dbc_queue_bulk_tx()
263 trb = ring->enqueue; in xhci_dbc_queue_bulk_tx()
264 cycle = ring->cycle_state; in xhci_dbc_queue_bulk_tx()
265 length = TRB_LEN(req->length); in xhci_dbc_queue_bulk_tx()
273 req->trb = ring->enqueue; in xhci_dbc_queue_bulk_tx()
274 req->trb_dma = xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue); in xhci_dbc_queue_bulk_tx()
287 trb->generic.field[3] |= cpu_to_le32(TRB_CYCLE); in xhci_dbc_queue_bulk_tx()
289 trb->generic.field[3] &= cpu_to_le32(~TRB_CYCLE); in xhci_dbc_queue_bulk_tx()
291 writel(DBC_DOOR_BELL_TARGET(dep->direction), &dbc->regs->doorbell); in xhci_dbc_queue_bulk_tx()
300 struct xhci_dbc *dbc = req->dbc; in dbc_ep_do_queue()
301 struct device *dev = dbc->dev; in dbc_ep_do_queue()
302 struct dbc_ep *dep = &dbc->eps[req->direction]; in dbc_ep_do_queue()
304 if (!req->length || !req->buf) in dbc_ep_do_queue()
305 return -EINVAL; in dbc_ep_do_queue()
307 req->actual = 0; in dbc_ep_do_queue()
308 req->status = -EINPROGRESS; in dbc_ep_do_queue()
310 req->dma = dma_map_single(dev, in dbc_ep_do_queue()
311 req->buf, in dbc_ep_do_queue()
312 req->length, in dbc_ep_do_queue()
314 if (dma_mapping_error(dev, req->dma)) { in dbc_ep_do_queue()
315 dev_err(dbc->dev, "failed to map buffer\n"); in dbc_ep_do_queue()
316 return -EFAULT; in dbc_ep_do_queue()
321 dev_err(dbc->dev, "failed to queue trbs\n"); in dbc_ep_do_queue()
323 req->dma, in dbc_ep_do_queue()
324 req->length, in dbc_ep_do_queue()
326 return -EFAULT; in dbc_ep_do_queue()
329 list_add_tail(&req->list_pending, &dep->list_pending); in dbc_ep_do_queue()
337 struct xhci_dbc *dbc = req->dbc; in dbc_ep_queue()
338 int ret = -ESHUTDOWN; in dbc_ep_queue()
341 return -ENODEV; in dbc_ep_queue()
343 if (req->direction != BULK_IN && in dbc_ep_queue()
344 req->direction != BULK_OUT) in dbc_ep_queue()
345 return -EINVAL; in dbc_ep_queue()
347 spin_lock_irqsave(&dbc->lock, flags); in dbc_ep_queue()
348 if (dbc->state == DS_CONFIGURED) in dbc_ep_queue()
350 spin_unlock_irqrestore(&dbc->lock, flags); in dbc_ep_queue()
352 mod_delayed_work(system_wq, &dbc->event_work, 0); in dbc_ep_queue()
363 dep = &dbc->eps[direction]; in xhci_dbc_do_eps_init()
364 dep->dbc = dbc; in xhci_dbc_do_eps_init()
365 dep->direction = direction; in xhci_dbc_do_eps_init()
366 dep->ring = direction ? dbc->ring_in : dbc->ring_out; in xhci_dbc_do_eps_init()
368 INIT_LIST_HEAD(&dep->list_pending); in xhci_dbc_do_eps_init()
379 memset(dbc->eps, 0, sizeof(struct dbc_ep) * ARRAY_SIZE(dbc->eps)); in xhci_dbc_eps_exit()
385 erst->entries = dma_alloc_coherent(dev, sizeof(struct xhci_erst_entry), in dbc_erst_alloc()
386 &erst->erst_dma_addr, flags); in dbc_erst_alloc()
387 if (!erst->entries) in dbc_erst_alloc()
388 return -ENOMEM; in dbc_erst_alloc()
390 erst->num_entries = 1; in dbc_erst_alloc()
391 erst->entries[0].seg_addr = cpu_to_le64(evt_ring->first_seg->dma); in dbc_erst_alloc()
392 erst->entries[0].seg_size = cpu_to_le32(TRBS_PER_SEGMENT); in dbc_erst_alloc()
393 erst->entries[0].rsvd = 0; in dbc_erst_alloc()
399 if (erst->entries) in dbc_erst_free()
401 erst->entries, erst->erst_dma_addr); in dbc_erst_free()
402 erst->entries = NULL; in dbc_erst_free()
414 /* xhci 7.6.9, all three contexts; info, ep-out and ep-in. Each 64 bytes*/ in dbc_alloc_ctx()
415 ctx->size = 3 * DBC_CONTEXT_SIZE; in dbc_alloc_ctx()
416 ctx->bytes = dma_alloc_coherent(dev, ctx->size, &ctx->dma, flags); in dbc_alloc_ctx()
417 if (!ctx->bytes) { in dbc_alloc_ctx()
435 ring->num_segs = 1; in xhci_dbc_ring_alloc()
436 ring->type = type; in xhci_dbc_ring_alloc()
442 ring->first_seg = seg; in xhci_dbc_ring_alloc()
443 ring->last_seg = seg; in xhci_dbc_ring_alloc()
444 seg->next = seg; in xhci_dbc_ring_alloc()
446 seg->trbs = dma_alloc_coherent(dev, TRB_SEGMENT_SIZE, &dma, flags); in xhci_dbc_ring_alloc()
447 if (!seg->trbs) in xhci_dbc_ring_alloc()
450 seg->dma = dma; in xhci_dbc_ring_alloc()
454 union xhci_trb *trb = &seg->trbs[TRBS_PER_SEGMENT - 1]; in xhci_dbc_ring_alloc()
456 trb->link.segment_ptr = cpu_to_le64(dma); in xhci_dbc_ring_alloc()
457 trb->link.control = cpu_to_le32(LINK_TOGGLE | TRB_TYPE(TRB_LINK)); in xhci_dbc_ring_alloc()
459 INIT_LIST_HEAD(&ring->td_list); in xhci_dbc_ring_alloc()
474 struct device *dev = dbc->dev; in xhci_dbc_mem_init()
477 dbc->ring_evt = xhci_dbc_ring_alloc(dev, TYPE_EVENT, flags); in xhci_dbc_mem_init()
478 if (!dbc->ring_evt) in xhci_dbc_mem_init()
481 dbc->ring_in = xhci_dbc_ring_alloc(dev, TYPE_BULK, flags); in xhci_dbc_mem_init()
482 if (!dbc->ring_in) in xhci_dbc_mem_init()
485 dbc->ring_out = xhci_dbc_ring_alloc(dev, TYPE_BULK, flags); in xhci_dbc_mem_init()
486 if (!dbc->ring_out) in xhci_dbc_mem_init()
490 ret = dbc_erst_alloc(dev, dbc->ring_evt, &dbc->erst, flags); in xhci_dbc_mem_init()
495 dbc->ctx = dbc_alloc_ctx(dev, flags); /* was sysdev, and is still */ in xhci_dbc_mem_init()
496 if (!dbc->ctx) in xhci_dbc_mem_init()
500 dbc->string_size = sizeof(struct dbc_str_descs); in xhci_dbc_mem_init()
501 dbc->string = dma_alloc_coherent(dev, dbc->string_size, in xhci_dbc_mem_init()
502 &dbc->string_dma, flags); in xhci_dbc_mem_init()
503 if (!dbc->string) in xhci_dbc_mem_init()
507 writel(dbc->erst.erst_size, &dbc->regs->ersts); in xhci_dbc_mem_init()
509 lo_hi_writeq(dbc->erst.erst_dma_addr, &dbc->regs->erstba); in xhci_dbc_mem_init()
510 deq = xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg, in xhci_dbc_mem_init()
511 dbc->ring_evt->dequeue); in xhci_dbc_mem_init()
512 lo_hi_writeq(deq, &dbc->regs->erdp); in xhci_dbc_mem_init()
515 string_length = xhci_dbc_populate_strings(dbc->string); in xhci_dbc_mem_init()
519 dbc->state = DS_INITIALIZED; in xhci_dbc_mem_init()
524 dbc_free_ctx(dev, dbc->ctx); in xhci_dbc_mem_init()
525 dbc->ctx = NULL; in xhci_dbc_mem_init()
527 dbc_erst_free(dev, &dbc->erst); in xhci_dbc_mem_init()
529 dbc_ring_free(dev, dbc->ring_out); in xhci_dbc_mem_init()
530 dbc->ring_out = NULL; in xhci_dbc_mem_init()
532 dbc_ring_free(dev, dbc->ring_in); in xhci_dbc_mem_init()
533 dbc->ring_in = NULL; in xhci_dbc_mem_init()
535 dbc_ring_free(dev, dbc->ring_evt); in xhci_dbc_mem_init()
536 dbc->ring_evt = NULL; in xhci_dbc_mem_init()
538 return -ENOMEM; in xhci_dbc_mem_init()
548 if (dbc->string) { in xhci_dbc_mem_cleanup()
549 dma_free_coherent(dbc->dev, dbc->string_size, in xhci_dbc_mem_cleanup()
550 dbc->string, dbc->string_dma); in xhci_dbc_mem_cleanup()
551 dbc->string = NULL; in xhci_dbc_mem_cleanup()
554 dbc_free_ctx(dbc->dev, dbc->ctx); in xhci_dbc_mem_cleanup()
555 dbc->ctx = NULL; in xhci_dbc_mem_cleanup()
557 dbc_erst_free(dbc->dev, &dbc->erst); in xhci_dbc_mem_cleanup()
558 dbc_ring_free(dbc->dev, dbc->ring_out); in xhci_dbc_mem_cleanup()
559 dbc_ring_free(dbc->dev, dbc->ring_in); in xhci_dbc_mem_cleanup()
560 dbc_ring_free(dbc->dev, dbc->ring_evt); in xhci_dbc_mem_cleanup()
561 dbc->ring_in = NULL; in xhci_dbc_mem_cleanup()
562 dbc->ring_out = NULL; in xhci_dbc_mem_cleanup()
563 dbc->ring_evt = NULL; in xhci_dbc_mem_cleanup()
571 if (dbc->state != DS_DISABLED) in xhci_do_dbc_start()
572 return -EINVAL; in xhci_do_dbc_start()
574 writel(0, &dbc->regs->control); in xhci_do_dbc_start()
575 ret = xhci_handshake(&dbc->regs->control, in xhci_do_dbc_start()
585 ctrl = readl(&dbc->regs->control); in xhci_do_dbc_start()
587 &dbc->regs->control); in xhci_do_dbc_start()
588 ret = xhci_handshake(&dbc->regs->control, in xhci_do_dbc_start()
594 dbc->state = DS_ENABLED; in xhci_do_dbc_start()
601 if (dbc->state == DS_DISABLED) in xhci_do_dbc_stop()
602 return -1; in xhci_do_dbc_stop()
604 writel(0, &dbc->regs->control); in xhci_do_dbc_stop()
605 dbc->state = DS_DISABLED; in xhci_do_dbc_stop()
617 pm_runtime_get_sync(dbc->dev); /* note this was self.controller */ in xhci_dbc_start()
619 spin_lock_irqsave(&dbc->lock, flags); in xhci_dbc_start()
621 spin_unlock_irqrestore(&dbc->lock, flags); in xhci_dbc_start()
624 pm_runtime_put(dbc->dev); /* note this was self.controller */ in xhci_dbc_start()
628 return mod_delayed_work(system_wq, &dbc->event_work, 1); in xhci_dbc_start()
638 switch (dbc->state) { in xhci_dbc_stop()
642 if (dbc->driver->disconnect) in xhci_dbc_stop()
643 dbc->driver->disconnect(dbc); in xhci_dbc_stop()
649 cancel_delayed_work_sync(&dbc->event_work); in xhci_dbc_stop()
651 spin_lock_irqsave(&dbc->lock, flags); in xhci_dbc_stop()
653 spin_unlock_irqrestore(&dbc->lock, flags); in xhci_dbc_stop()
657 pm_runtime_put_sync(dbc->dev); /* note, was self.controller */ in xhci_dbc_stop()
665 dev_info(dbc->dev, "DbC Endpoint halted\n"); in handle_ep_halt_changes()
666 dep->halted = 1; in handle_ep_halt_changes()
668 } else if (dep->halted) { in handle_ep_halt_changes()
669 dev_info(dbc->dev, "DbC Endpoint halt cleared\n"); in handle_ep_halt_changes()
670 dep->halted = 0; in handle_ep_halt_changes()
672 if (!list_empty(&dep->list_pending)) in handle_ep_halt_changes()
673 writel(DBC_DOOR_BELL_TARGET(dep->direction), in handle_ep_halt_changes()
674 &dbc->regs->doorbell); in handle_ep_halt_changes()
683 portsc = readl(&dbc->regs->portsc); in dbc_handle_port_status()
685 dev_info(dbc->dev, "DbC port connect change\n"); in dbc_handle_port_status()
688 dev_info(dbc->dev, "DbC port reset change\n"); in dbc_handle_port_status()
691 dev_info(dbc->dev, "DbC port link status change\n"); in dbc_handle_port_status()
694 dev_info(dbc->dev, "DbC config error change\n"); in dbc_handle_port_status()
697 writel(portsc & ~DBC_PORTSC_RESET_CHANGE, &dbc->regs->portsc); in dbc_handle_port_status()
711 comp_code = GET_COMP_CODE(le32_to_cpu(event->generic.field[2])); in dbc_handle_xfer_event()
712 remain_length = EVENT_TRB_LEN(le32_to_cpu(event->generic.field[2])); in dbc_handle_xfer_event()
713 ep_id = TRB_TO_EP_ID(le32_to_cpu(event->generic.field[3])); in dbc_handle_xfer_event()
718 ring = dep->ring; in dbc_handle_xfer_event()
721 list_for_each_entry(r, &dep->list_pending, list_pending) { in dbc_handle_xfer_event()
722 if (r->trb_dma == event->trans_event.buffer) { in dbc_handle_xfer_event()
726 if (r->status == -COMP_STALL_ERROR) { in dbc_handle_xfer_event()
727 dev_warn(dbc->dev, "Give back stale stalled req\n"); in dbc_handle_xfer_event()
728 ring->num_trbs_free++; in dbc_handle_xfer_event()
734 dev_warn(dbc->dev, "no matched request\n"); in dbc_handle_xfer_event()
738 trace_xhci_dbc_handle_transfer(ring, &req->trb->generic); in dbc_handle_xfer_event()
750 dev_warn(dbc->dev, "tx error %d detected\n", comp_code); in dbc_handle_xfer_event()
751 status = -comp_code; in dbc_handle_xfer_event()
754 dev_warn(dbc->dev, "Stall error at bulk TRB %llx, remaining %zu, ep deq %llx\n", in dbc_handle_xfer_event()
755 event->trans_event.buffer, remain_length, ep_ctx->deq); in dbc_handle_xfer_event()
757 dep->halted = 1; in dbc_handle_xfer_event()
770 * In this case mark the TRB as No-Op to avoid hw from using the in dbc_handle_xfer_event()
774 if ((ep_ctx->deq & ~TRB_CYCLE) == event->trans_event.buffer) { in dbc_handle_xfer_event()
775 dev_dbg(dbc->dev, "Ep stopped on Stalled TRB\n"); in dbc_handle_xfer_event()
776 if (remain_length == req->length) { in dbc_handle_xfer_event()
777 dev_dbg(dbc->dev, "Spurious stall event, keep req\n"); in dbc_handle_xfer_event()
778 req->status = -COMP_STALL_ERROR; in dbc_handle_xfer_event()
779 req->actual = 0; in dbc_handle_xfer_event()
782 dev_dbg(dbc->dev, "Give back stalled req, but turn TRB to No-op\n"); in dbc_handle_xfer_event()
783 trb_to_noop(req->trb); in dbc_handle_xfer_event()
788 dev_err(dbc->dev, "unknown tx error %d\n", comp_code); in dbc_handle_xfer_event()
789 status = -comp_code; in dbc_handle_xfer_event()
793 ring->num_trbs_free++; in dbc_handle_xfer_event()
794 req->actual = req->length - remain_length; in dbc_handle_xfer_event()
801 if (ring->dequeue == &ring->deq_seg->trbs[TRBS_PER_SEGMENT - 1]) { in inc_evt_deq()
802 ring->cycle_state ^= 1; in inc_evt_deq()
803 ring->dequeue = ring->deq_seg->trbs; in inc_evt_deq()
806 ring->dequeue++; in inc_evt_deq()
817 switch (dbc->state) { in xhci_dbc_do_handle_events()
823 portsc = readl(&dbc->regs->portsc); in xhci_dbc_do_handle_events()
825 dbc->state = DS_CONNECTED; in xhci_dbc_do_handle_events()
826 dev_info(dbc->dev, "DbC connected\n"); in xhci_dbc_do_handle_events()
831 ctrl = readl(&dbc->regs->control); in xhci_dbc_do_handle_events()
833 dbc->state = DS_CONFIGURED; in xhci_dbc_do_handle_events()
834 dev_info(dbc->dev, "DbC configured\n"); in xhci_dbc_do_handle_events()
835 portsc = readl(&dbc->regs->portsc); in xhci_dbc_do_handle_events()
836 writel(portsc, &dbc->regs->portsc); in xhci_dbc_do_handle_events()
843 portsc = readl(&dbc->regs->portsc); in xhci_dbc_do_handle_events()
846 dev_info(dbc->dev, "DbC cable unplugged\n"); in xhci_dbc_do_handle_events()
847 dbc->state = DS_ENABLED; in xhci_dbc_do_handle_events()
855 dev_info(dbc->dev, "DbC port reset\n"); in xhci_dbc_do_handle_events()
856 writel(portsc, &dbc->regs->portsc); in xhci_dbc_do_handle_events()
857 dbc->state = DS_ENABLED; in xhci_dbc_do_handle_events()
864 ctrl = readl(&dbc->regs->control); in xhci_dbc_do_handle_events()
870 writel(ctrl, &dbc->regs->control); in xhci_dbc_do_handle_events()
871 ctrl = readl(&dbc->regs->control); in xhci_dbc_do_handle_events()
875 dev_err(dbc->dev, "Unknown DbC state %d\n", dbc->state); in xhci_dbc_do_handle_events()
880 evt = dbc->ring_evt->dequeue; in xhci_dbc_do_handle_events()
881 while ((le32_to_cpu(evt->event_cmd.flags) & TRB_CYCLE) == in xhci_dbc_do_handle_events()
882 dbc->ring_evt->cycle_state) { in xhci_dbc_do_handle_events()
889 trace_xhci_dbc_handle_event(dbc->ring_evt, &evt->generic); in xhci_dbc_do_handle_events()
891 switch (le32_to_cpu(evt->event_cmd.flags) & TRB_TYPE_BITMASK) { in xhci_dbc_do_handle_events()
902 inc_evt_deq(dbc->ring_evt); in xhci_dbc_do_handle_events()
904 evt = dbc->ring_evt->dequeue; in xhci_dbc_do_handle_events()
910 deq = xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg, in xhci_dbc_do_handle_events()
911 dbc->ring_evt->dequeue); in xhci_dbc_do_handle_events()
912 lo_hi_writeq(deq, &dbc->regs->erdp); in xhci_dbc_do_handle_events()
926 spin_lock_irqsave(&dbc->lock, flags); in xhci_dbc_handle_events()
928 spin_unlock_irqrestore(&dbc->lock, flags); in xhci_dbc_handle_events()
932 if (dbc->driver->configure) in xhci_dbc_handle_events()
933 dbc->driver->configure(dbc); in xhci_dbc_handle_events()
936 if (dbc->driver->disconnect) in xhci_dbc_handle_events()
937 dbc->driver->disconnect(dbc); in xhci_dbc_handle_events()
942 dev_info(dbc->dev, "stop handling dbc events\n"); in xhci_dbc_handle_events()
946 mod_delayed_work(system_wq, &dbc->event_work, 1); in xhci_dbc_handle_events()
955 struct xhci_hcd *xhci; in dbc_show() local
957 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_show()
958 dbc = xhci->dbc; in dbc_show()
960 switch (dbc->state) { in dbc_show()
987 struct xhci_hcd *xhci; in dbc_store() local
990 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_store()
991 dbc = xhci->dbc; in dbc_store()
998 return -EINVAL; in dbc_store()
1008 struct xhci_hcd *xhci; in dbc_idVendor_show() local
1010 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_idVendor_show()
1011 dbc = xhci->dbc; in dbc_idVendor_show()
1013 return sprintf(buf, "%04x\n", dbc->idVendor); in dbc_idVendor_show()
1021 struct xhci_hcd *xhci; in dbc_idVendor_store() local
1027 return -EINVAL; in dbc_idVendor_store()
1029 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_idVendor_store()
1030 dbc = xhci->dbc; in dbc_idVendor_store()
1031 if (dbc->state != DS_DISABLED) in dbc_idVendor_store()
1032 return -EBUSY; in dbc_idVendor_store()
1034 dbc->idVendor = value; in dbc_idVendor_store()
1035 ptr = &dbc->regs->devinfo1; in dbc_idVendor_store()
1048 struct xhci_hcd *xhci; in dbc_idProduct_show() local
1050 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_idProduct_show()
1051 dbc = xhci->dbc; in dbc_idProduct_show()
1053 return sprintf(buf, "%04x\n", dbc->idProduct); in dbc_idProduct_show()
1061 struct xhci_hcd *xhci; in dbc_idProduct_store() local
1067 return -EINVAL; in dbc_idProduct_store()
1069 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_idProduct_store()
1070 dbc = xhci->dbc; in dbc_idProduct_store()
1071 if (dbc->state != DS_DISABLED) in dbc_idProduct_store()
1072 return -EBUSY; in dbc_idProduct_store()
1074 dbc->idProduct = value; in dbc_idProduct_store()
1075 ptr = &dbc->regs->devinfo2; in dbc_idProduct_store()
1087 struct xhci_hcd *xhci; in dbc_bcdDevice_show() local
1089 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_bcdDevice_show()
1090 dbc = xhci->dbc; in dbc_bcdDevice_show()
1092 return sprintf(buf, "%04x\n", dbc->bcdDevice); in dbc_bcdDevice_show()
1100 struct xhci_hcd *xhci; in dbc_bcdDevice_store() local
1106 return -EINVAL; in dbc_bcdDevice_store()
1108 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_bcdDevice_store()
1109 dbc = xhci->dbc; in dbc_bcdDevice_store()
1110 if (dbc->state != DS_DISABLED) in dbc_bcdDevice_store()
1111 return -EBUSY; in dbc_bcdDevice_store()
1113 dbc->bcdDevice = value; in dbc_bcdDevice_store()
1114 ptr = &dbc->regs->devinfo2; in dbc_bcdDevice_store()
1127 struct xhci_hcd *xhci; in dbc_bInterfaceProtocol_show() local
1129 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_bInterfaceProtocol_show()
1130 dbc = xhci->dbc; in dbc_bInterfaceProtocol_show()
1132 return sprintf(buf, "%02x\n", dbc->bInterfaceProtocol); in dbc_bInterfaceProtocol_show()
1140 struct xhci_hcd *xhci; in dbc_bInterfaceProtocol_store() local
1146 /* bInterfaceProtocol is 8 bit, but xhci only supports values 0 and 1 */ in dbc_bInterfaceProtocol_store()
1149 return -EINVAL; in dbc_bInterfaceProtocol_store()
1151 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_bInterfaceProtocol_store()
1152 dbc = xhci->dbc; in dbc_bInterfaceProtocol_store()
1153 if (dbc->state != DS_DISABLED) in dbc_bInterfaceProtocol_store()
1154 return -EBUSY; in dbc_bInterfaceProtocol_store()
1156 dbc->bInterfaceProtocol = value; in dbc_bInterfaceProtocol_store()
1157 ptr = &dbc->regs->devinfo1; in dbc_bInterfaceProtocol_store()
1194 dbc->regs = base; in xhci_alloc_dbc()
1195 dbc->dev = dev; in xhci_alloc_dbc()
1196 dbc->driver = driver; in xhci_alloc_dbc()
1197 dbc->idProduct = DBC_PRODUCT_ID; in xhci_alloc_dbc()
1198 dbc->idVendor = DBC_VENDOR_ID; in xhci_alloc_dbc()
1199 dbc->bcdDevice = DBC_DEVICE_REV; in xhci_alloc_dbc()
1200 dbc->bInterfaceProtocol = DBC_PROTOCOL; in xhci_alloc_dbc()
1202 if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE) in xhci_alloc_dbc()
1205 INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events); in xhci_alloc_dbc()
1206 spin_lock_init(&dbc->lock); in xhci_alloc_dbc()
1208 ret = sysfs_create_group(&dev->kobj, &dbc_dev_attrib_grp); in xhci_alloc_dbc()
1223 /* stop hw, stop wq and call dbc->ops->stop() */ in xhci_dbc_remove()
1227 sysfs_remove_group(&dbc->dev->kobj, &dbc_dev_attrib_grp); in xhci_dbc_remove()
1233 int xhci_create_dbc_dev(struct xhci_hcd *xhci) in xhci_create_dbc_dev() argument
1241 dev = xhci_to_hcd(xhci)->self.controller; in xhci_create_dbc_dev()
1242 base = &xhci->cap_regs->hc_capbase; in xhci_create_dbc_dev()
1246 return -ENODEV; in xhci_create_dbc_dev()
1249 if (xhci->dbc) in xhci_create_dbc_dev()
1250 return -EBUSY; in xhci_create_dbc_dev()
1252 ret = xhci_dbc_tty_probe(dev, base + dbc_cap_offs, xhci); in xhci_create_dbc_dev()
1257 void xhci_remove_dbc_dev(struct xhci_hcd *xhci) in xhci_remove_dbc_dev() argument
1261 if (!xhci->dbc) in xhci_remove_dbc_dev()
1264 xhci_dbc_tty_remove(xhci->dbc); in xhci_remove_dbc_dev()
1265 spin_lock_irqsave(&xhci->lock, flags); in xhci_remove_dbc_dev()
1266 xhci->dbc = NULL; in xhci_remove_dbc_dev()
1267 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_remove_dbc_dev()
1271 int xhci_dbc_suspend(struct xhci_hcd *xhci) in xhci_dbc_suspend() argument
1273 struct xhci_dbc *dbc = xhci->dbc; in xhci_dbc_suspend()
1278 if (dbc->state == DS_CONFIGURED) in xhci_dbc_suspend()
1279 dbc->resume_required = 1; in xhci_dbc_suspend()
1286 int xhci_dbc_resume(struct xhci_hcd *xhci) in xhci_dbc_resume() argument
1289 struct xhci_dbc *dbc = xhci->dbc; in xhci_dbc_resume()
1294 if (dbc->resume_required) { in xhci_dbc_resume()
1295 dbc->resume_required = 0; in xhci_dbc_resume()