Lines Matching +full:generic +full:- +full:xhci
1 // SPDX-License-Identifier: GPL-2.0
3 * xhci-dbgcap.c - xHCI debug capability support
11 #include <linux/dma-mapping.h>
24 #include <linux/io-64-nonatomic-lo-hi.h>
28 #include "xhci.h"
29 #include "xhci-trace.h"
30 #include "xhci-dbgcap.h"
36 dma_free_coherent(dev, ctx->size, ctx->bytes, ctx->dma); in dbc_free_ctx()
46 if (ring->first_seg) { in dbc_ring_free()
48 ring->first_seg->trbs, in dbc_ring_free()
49 ring->first_seg->dma); in dbc_ring_free()
50 kfree(ring->first_seg); in dbc_ring_free()
61 s_desc = (struct usb_string_descriptor *)strings->serial; in xhci_dbc_populate_strings()
63 UTF16_LITTLE_ENDIAN, (wchar_t *)s_desc->wData, in xhci_dbc_populate_strings()
66 s_desc->bLength = (strlen(DBC_STRING_SERIAL) + 1) * 2; in xhci_dbc_populate_strings()
67 s_desc->bDescriptorType = USB_DT_STRING; in xhci_dbc_populate_strings()
68 string_length = s_desc->bLength; in xhci_dbc_populate_strings()
72 s_desc = (struct usb_string_descriptor *)strings->product; in xhci_dbc_populate_strings()
74 UTF16_LITTLE_ENDIAN, (wchar_t *)s_desc->wData, in xhci_dbc_populate_strings()
77 s_desc->bLength = (strlen(DBC_STRING_PRODUCT) + 1) * 2; in xhci_dbc_populate_strings()
78 s_desc->bDescriptorType = USB_DT_STRING; in xhci_dbc_populate_strings()
79 string_length += s_desc->bLength; in xhci_dbc_populate_strings()
83 s_desc = (struct usb_string_descriptor *)strings->manufacturer; in xhci_dbc_populate_strings()
86 UTF16_LITTLE_ENDIAN, (wchar_t *)s_desc->wData, in xhci_dbc_populate_strings()
89 s_desc->bLength = (strlen(DBC_STRING_MANUFACTURER) + 1) * 2; in xhci_dbc_populate_strings()
90 s_desc->bDescriptorType = USB_DT_STRING; in xhci_dbc_populate_strings()
91 string_length += s_desc->bLength; in xhci_dbc_populate_strings()
95 strings->string0[0] = 4; in xhci_dbc_populate_strings()
96 strings->string0[1] = USB_DT_STRING; in xhci_dbc_populate_strings()
97 strings->string0[2] = 0x09; in xhci_dbc_populate_strings()
98 strings->string0[3] = 0x04; in xhci_dbc_populate_strings()
116 info = (struct dbc_info_context *)dbc->ctx->bytes; in xhci_dbc_init_contexts()
117 dma = dbc->string_dma; in xhci_dbc_init_contexts()
118 info->string0 = cpu_to_le64(dma); in xhci_dbc_init_contexts()
119 info->manufacturer = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH); in xhci_dbc_init_contexts()
120 info->product = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH * 2); in xhci_dbc_init_contexts()
121 info->serial = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH * 3); in xhci_dbc_init_contexts()
122 info->length = cpu_to_le32(string_length); in xhci_dbc_init_contexts()
126 max_burst = DBC_CTRL_MAXBURST(readl(&dbc->regs->control)); in xhci_dbc_init_contexts()
128 ep_ctx->ep_info = 0; in xhci_dbc_init_contexts()
129 ep_ctx->ep_info2 = dbc_epctx_info2(BULK_OUT_EP, 1024, max_burst); in xhci_dbc_init_contexts()
130 ep_ctx->deq = cpu_to_le64(deq | dbc->ring_out->cycle_state); in xhci_dbc_init_contexts()
135 ep_ctx->ep_info = 0; in xhci_dbc_init_contexts()
136 ep_ctx->ep_info2 = dbc_epctx_info2(BULK_IN_EP, 1024, max_burst); in xhci_dbc_init_contexts()
137 ep_ctx->deq = cpu_to_le64(deq | dbc->ring_in->cycle_state); in xhci_dbc_init_contexts()
140 lo_hi_writeq(dbc->ctx->dma, &dbc->regs->dccp); in xhci_dbc_init_contexts()
142 dev_info = (dbc->idVendor << 16) | dbc->bInterfaceProtocol; in xhci_dbc_init_contexts()
143 writel(dev_info, &dbc->regs->devinfo1); in xhci_dbc_init_contexts()
145 dev_info = (dbc->bcdDevice << 16) | dbc->idProduct; in xhci_dbc_init_contexts()
146 writel(dev_info, &dbc->regs->devinfo2); in xhci_dbc_init_contexts()
150 __releases(&dbc->lock) in xhci_dbc_giveback()
151 __acquires(&dbc->lock) in xhci_dbc_giveback()
153 struct xhci_dbc *dbc = req->dbc; in xhci_dbc_giveback()
154 struct device *dev = dbc->dev; in xhci_dbc_giveback()
156 list_del_init(&req->list_pending); in xhci_dbc_giveback()
157 req->trb_dma = 0; in xhci_dbc_giveback()
158 req->trb = NULL; in xhci_dbc_giveback()
160 if (req->status == -EINPROGRESS) in xhci_dbc_giveback()
161 req->status = status; in xhci_dbc_giveback()
166 req->dma, in xhci_dbc_giveback()
167 req->length, in xhci_dbc_giveback()
171 spin_unlock(&dbc->lock); in xhci_dbc_giveback()
172 req->complete(dbc, req); in xhci_dbc_giveback()
173 spin_lock(&dbc->lock); in xhci_dbc_giveback()
178 trb->generic.field[0] = 0; in trb_to_noop()
179 trb->generic.field[1] = 0; in trb_to_noop()
180 trb->generic.field[2] = 0; in trb_to_noop()
181 trb->generic.field[3] &= cpu_to_le32(TRB_CYCLE); in trb_to_noop()
182 trb->generic.field[3] |= cpu_to_le32(TRB_TYPE(TRB_TR_NOOP)); in trb_to_noop()
187 trb_to_noop(req->trb); in xhci_dbc_flush_single_request()
188 xhci_dbc_giveback(req, -ESHUTDOWN); in xhci_dbc_flush_single_request()
195 list_for_each_entry_safe(req, tmp, &dep->list_pending, list_pending) in xhci_dbc_flush_endpoint_requests()
201 xhci_dbc_flush_endpoint_requests(&dbc->eps[BULK_OUT]); in xhci_dbc_flush_requests()
202 xhci_dbc_flush_endpoint_requests(&dbc->eps[BULK_IN]); in xhci_dbc_flush_requests()
221 req->dbc = dbc; in dbc_alloc_request()
222 INIT_LIST_HEAD(&req->list_pending); in dbc_alloc_request()
223 INIT_LIST_HEAD(&req->list_pool); in dbc_alloc_request()
224 req->direction = direction; in dbc_alloc_request()
245 trb = ring->enqueue; in xhci_dbc_queue_trb()
246 trb->generic.field[0] = cpu_to_le32(field1); in xhci_dbc_queue_trb()
247 trb->generic.field[1] = cpu_to_le32(field2); in xhci_dbc_queue_trb()
248 trb->generic.field[2] = cpu_to_le32(field3); in xhci_dbc_queue_trb()
249 trb->generic.field[3] = cpu_to_le32(field4); in xhci_dbc_queue_trb()
251 trace_xhci_dbc_gadget_ep_queue(ring, &trb->generic, in xhci_dbc_queue_trb()
252 xhci_trb_virt_to_dma(ring->enq_seg, in xhci_dbc_queue_trb()
253 ring->enqueue)); in xhci_dbc_queue_trb()
254 ring->num_trbs_free--; in xhci_dbc_queue_trb()
255 next = ++(ring->enqueue); in xhci_dbc_queue_trb()
256 if (TRB_TYPE_LINK_LE32(next->link.control)) { in xhci_dbc_queue_trb()
257 next->link.control ^= cpu_to_le32(TRB_CYCLE); in xhci_dbc_queue_trb()
258 ring->enqueue = ring->enq_seg->trbs; in xhci_dbc_queue_trb()
259 ring->cycle_state ^= 1; in xhci_dbc_queue_trb()
269 struct xhci_dbc *dbc = req->dbc; in xhci_dbc_queue_bulk_tx()
270 struct xhci_ring *ring = dep->ring; in xhci_dbc_queue_bulk_tx()
273 num_trbs = count_trbs(req->dma, req->length); in xhci_dbc_queue_bulk_tx()
275 if (ring->num_trbs_free < num_trbs) in xhci_dbc_queue_bulk_tx()
276 return -EBUSY; in xhci_dbc_queue_bulk_tx()
278 addr = req->dma; in xhci_dbc_queue_bulk_tx()
279 trb = ring->enqueue; in xhci_dbc_queue_bulk_tx()
280 cycle = ring->cycle_state; in xhci_dbc_queue_bulk_tx()
281 length = TRB_LEN(req->length); in xhci_dbc_queue_bulk_tx()
289 req->trb = ring->enqueue; in xhci_dbc_queue_bulk_tx()
290 req->trb_dma = xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue); in xhci_dbc_queue_bulk_tx()
303 trb->generic.field[3] |= cpu_to_le32(TRB_CYCLE); in xhci_dbc_queue_bulk_tx()
305 trb->generic.field[3] &= cpu_to_le32(~TRB_CYCLE); in xhci_dbc_queue_bulk_tx()
307 writel(DBC_DOOR_BELL_TARGET(dep->direction), &dbc->regs->doorbell); in xhci_dbc_queue_bulk_tx()
316 struct xhci_dbc *dbc = req->dbc; in dbc_ep_do_queue()
317 struct device *dev = dbc->dev; in dbc_ep_do_queue()
318 struct dbc_ep *dep = &dbc->eps[req->direction]; in dbc_ep_do_queue()
320 if (!req->length || !req->buf) in dbc_ep_do_queue()
321 return -EINVAL; in dbc_ep_do_queue()
323 req->actual = 0; in dbc_ep_do_queue()
324 req->status = -EINPROGRESS; in dbc_ep_do_queue()
326 req->dma = dma_map_single(dev, in dbc_ep_do_queue()
327 req->buf, in dbc_ep_do_queue()
328 req->length, in dbc_ep_do_queue()
330 if (dma_mapping_error(dev, req->dma)) { in dbc_ep_do_queue()
331 dev_err(dbc->dev, "failed to map buffer\n"); in dbc_ep_do_queue()
332 return -EFAULT; in dbc_ep_do_queue()
337 dev_err(dbc->dev, "failed to queue trbs\n"); in dbc_ep_do_queue()
339 req->dma, in dbc_ep_do_queue()
340 req->length, in dbc_ep_do_queue()
342 return -EFAULT; in dbc_ep_do_queue()
345 list_add_tail(&req->list_pending, &dep->list_pending); in dbc_ep_do_queue()
353 struct xhci_dbc *dbc = req->dbc; in dbc_ep_queue()
354 int ret = -ESHUTDOWN; in dbc_ep_queue()
357 return -ENODEV; in dbc_ep_queue()
359 if (req->direction != BULK_IN && in dbc_ep_queue()
360 req->direction != BULK_OUT) in dbc_ep_queue()
361 return -EINVAL; in dbc_ep_queue()
363 spin_lock_irqsave(&dbc->lock, flags); in dbc_ep_queue()
364 if (dbc->state == DS_CONFIGURED) in dbc_ep_queue()
366 spin_unlock_irqrestore(&dbc->lock, flags); in dbc_ep_queue()
368 mod_delayed_work(system_wq, &dbc->event_work, 0); in dbc_ep_queue()
379 dep = &dbc->eps[direction]; in xhci_dbc_do_eps_init()
380 dep->dbc = dbc; in xhci_dbc_do_eps_init()
381 dep->direction = direction; in xhci_dbc_do_eps_init()
382 dep->ring = direction ? dbc->ring_in : dbc->ring_out; in xhci_dbc_do_eps_init()
384 INIT_LIST_HEAD(&dep->list_pending); in xhci_dbc_do_eps_init()
395 memset(dbc->eps, 0, sizeof_field(struct xhci_dbc, eps)); in xhci_dbc_eps_exit()
401 erst->entries = dma_alloc_coherent(dev, sizeof(*erst->entries), in dbc_erst_alloc()
402 &erst->erst_dma_addr, flags); in dbc_erst_alloc()
403 if (!erst->entries) in dbc_erst_alloc()
404 return -ENOMEM; in dbc_erst_alloc()
406 erst->num_entries = 1; in dbc_erst_alloc()
407 erst->entries[0].seg_addr = cpu_to_le64(evt_ring->first_seg->dma); in dbc_erst_alloc()
408 erst->entries[0].seg_size = cpu_to_le32(TRBS_PER_SEGMENT); in dbc_erst_alloc()
409 erst->entries[0].rsvd = 0; in dbc_erst_alloc()
415 dma_free_coherent(dev, sizeof(*erst->entries), erst->entries, in dbc_erst_free()
416 erst->erst_dma_addr); in dbc_erst_free()
417 erst->entries = NULL; in dbc_erst_free()
429 /* xhci 7.6.9, all three contexts; info, ep-out and ep-in. Each 64 bytes*/ in dbc_alloc_ctx()
430 ctx->size = 3 * DBC_CONTEXT_SIZE; in dbc_alloc_ctx()
431 ctx->bytes = dma_alloc_coherent(dev, ctx->size, &ctx->dma, flags); in dbc_alloc_ctx()
432 if (!ctx->bytes) { in dbc_alloc_ctx()
450 ring->num_segs = 1; in xhci_dbc_ring_alloc()
451 ring->type = type; in xhci_dbc_ring_alloc()
457 ring->first_seg = seg; in xhci_dbc_ring_alloc()
458 ring->last_seg = seg; in xhci_dbc_ring_alloc()
459 seg->next = seg; in xhci_dbc_ring_alloc()
461 seg->trbs = dma_alloc_coherent(dev, TRB_SEGMENT_SIZE, &dma, flags); in xhci_dbc_ring_alloc()
462 if (!seg->trbs) in xhci_dbc_ring_alloc()
465 seg->dma = dma; in xhci_dbc_ring_alloc()
469 union xhci_trb *trb = &seg->trbs[TRBS_PER_SEGMENT - 1]; in xhci_dbc_ring_alloc()
471 trb->link.segment_ptr = cpu_to_le64(dma); in xhci_dbc_ring_alloc()
472 trb->link.control = cpu_to_le32(LINK_TOGGLE | TRB_TYPE(TRB_LINK)); in xhci_dbc_ring_alloc()
474 INIT_LIST_HEAD(&ring->td_list); in xhci_dbc_ring_alloc()
489 struct device *dev = dbc->dev; in xhci_dbc_mem_init()
492 dbc->ring_evt = xhci_dbc_ring_alloc(dev, TYPE_EVENT, flags); in xhci_dbc_mem_init()
493 if (!dbc->ring_evt) in xhci_dbc_mem_init()
496 dbc->ring_in = xhci_dbc_ring_alloc(dev, TYPE_BULK, flags); in xhci_dbc_mem_init()
497 if (!dbc->ring_in) in xhci_dbc_mem_init()
500 dbc->ring_out = xhci_dbc_ring_alloc(dev, TYPE_BULK, flags); in xhci_dbc_mem_init()
501 if (!dbc->ring_out) in xhci_dbc_mem_init()
505 ret = dbc_erst_alloc(dev, dbc->ring_evt, &dbc->erst, flags); in xhci_dbc_mem_init()
510 dbc->ctx = dbc_alloc_ctx(dev, flags); /* was sysdev, and is still */ in xhci_dbc_mem_init()
511 if (!dbc->ctx) in xhci_dbc_mem_init()
515 dbc->string_size = sizeof(*dbc->string); in xhci_dbc_mem_init()
516 dbc->string = dma_alloc_coherent(dev, dbc->string_size, in xhci_dbc_mem_init()
517 &dbc->string_dma, flags); in xhci_dbc_mem_init()
518 if (!dbc->string) in xhci_dbc_mem_init()
522 writel(dbc->erst.num_entries, &dbc->regs->ersts); in xhci_dbc_mem_init()
524 lo_hi_writeq(dbc->erst.erst_dma_addr, &dbc->regs->erstba); in xhci_dbc_mem_init()
525 deq = xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg, in xhci_dbc_mem_init()
526 dbc->ring_evt->dequeue); in xhci_dbc_mem_init()
527 lo_hi_writeq(deq, &dbc->regs->erdp); in xhci_dbc_mem_init()
530 string_length = xhci_dbc_populate_strings(dbc->string); in xhci_dbc_mem_init()
534 dbc->state = DS_INITIALIZED; in xhci_dbc_mem_init()
539 dbc_free_ctx(dev, dbc->ctx); in xhci_dbc_mem_init()
540 dbc->ctx = NULL; in xhci_dbc_mem_init()
542 dbc_erst_free(dev, &dbc->erst); in xhci_dbc_mem_init()
544 dbc_ring_free(dev, dbc->ring_out); in xhci_dbc_mem_init()
545 dbc->ring_out = NULL; in xhci_dbc_mem_init()
547 dbc_ring_free(dev, dbc->ring_in); in xhci_dbc_mem_init()
548 dbc->ring_in = NULL; in xhci_dbc_mem_init()
550 dbc_ring_free(dev, dbc->ring_evt); in xhci_dbc_mem_init()
551 dbc->ring_evt = NULL; in xhci_dbc_mem_init()
553 return -ENOMEM; in xhci_dbc_mem_init()
563 dma_free_coherent(dbc->dev, dbc->string_size, dbc->string, dbc->string_dma); in xhci_dbc_mem_cleanup()
564 dbc->string = NULL; in xhci_dbc_mem_cleanup()
566 dbc_free_ctx(dbc->dev, dbc->ctx); in xhci_dbc_mem_cleanup()
567 dbc->ctx = NULL; in xhci_dbc_mem_cleanup()
569 dbc_erst_free(dbc->dev, &dbc->erst); in xhci_dbc_mem_cleanup()
570 dbc_ring_free(dbc->dev, dbc->ring_out); in xhci_dbc_mem_cleanup()
571 dbc_ring_free(dbc->dev, dbc->ring_in); in xhci_dbc_mem_cleanup()
572 dbc_ring_free(dbc->dev, dbc->ring_evt); in xhci_dbc_mem_cleanup()
573 dbc->ring_in = NULL; in xhci_dbc_mem_cleanup()
574 dbc->ring_out = NULL; in xhci_dbc_mem_cleanup()
575 dbc->ring_evt = NULL; in xhci_dbc_mem_cleanup()
583 if (dbc->state != DS_DISABLED) in xhci_do_dbc_start()
584 return -EINVAL; in xhci_do_dbc_start()
586 writel(0, &dbc->regs->control); in xhci_do_dbc_start()
587 ret = xhci_handshake(&dbc->regs->control, in xhci_do_dbc_start()
597 ctrl = readl(&dbc->regs->control); in xhci_do_dbc_start()
599 &dbc->regs->control); in xhci_do_dbc_start()
600 ret = xhci_handshake(&dbc->regs->control, in xhci_do_dbc_start()
606 dbc->state = DS_ENABLED; in xhci_do_dbc_start()
613 if (dbc->state == DS_DISABLED) in xhci_do_dbc_stop()
614 return -EINVAL; in xhci_do_dbc_stop()
616 writel(0, &dbc->regs->control); in xhci_do_dbc_stop()
617 dbc->state = DS_DISABLED; in xhci_do_dbc_stop()
629 pm_runtime_get_sync(dbc->dev); /* note this was self.controller */ in xhci_dbc_start()
631 spin_lock_irqsave(&dbc->lock, flags); in xhci_dbc_start()
633 spin_unlock_irqrestore(&dbc->lock, flags); in xhci_dbc_start()
636 pm_runtime_put(dbc->dev); /* note this was self.controller */ in xhci_dbc_start()
640 return mod_delayed_work(system_wq, &dbc->event_work, in xhci_dbc_start()
641 msecs_to_jiffies(dbc->poll_interval)); in xhci_dbc_start()
651 switch (dbc->state) { in xhci_dbc_stop()
655 if (dbc->driver->disconnect) in xhci_dbc_stop()
656 dbc->driver->disconnect(dbc); in xhci_dbc_stop()
662 cancel_delayed_work_sync(&dbc->event_work); in xhci_dbc_stop()
664 spin_lock_irqsave(&dbc->lock, flags); in xhci_dbc_stop()
666 spin_unlock_irqrestore(&dbc->lock, flags); in xhci_dbc_stop()
671 pm_runtime_put_sync(dbc->dev); /* note, was self.controller */ in xhci_dbc_stop()
678 dev_info(dbc->dev, "DbC Endpoint halted\n"); in handle_ep_halt_changes()
679 dep->halted = 1; in handle_ep_halt_changes()
681 } else if (dep->halted) { in handle_ep_halt_changes()
682 dev_info(dbc->dev, "DbC Endpoint halt cleared\n"); in handle_ep_halt_changes()
683 dep->halted = 0; in handle_ep_halt_changes()
685 if (!list_empty(&dep->list_pending)) in handle_ep_halt_changes()
686 writel(DBC_DOOR_BELL_TARGET(dep->direction), in handle_ep_halt_changes()
687 &dbc->regs->doorbell); in handle_ep_halt_changes()
696 portsc = readl(&dbc->regs->portsc); in dbc_handle_port_status()
698 dev_info(dbc->dev, "DbC port connect change\n"); in dbc_handle_port_status()
701 dev_info(dbc->dev, "DbC port reset change\n"); in dbc_handle_port_status()
704 dev_info(dbc->dev, "DbC port link status change\n"); in dbc_handle_port_status()
707 dev_info(dbc->dev, "DbC config error change\n"); in dbc_handle_port_status()
710 writel(portsc & ~DBC_PORTSC_RESET_CHANGE, &dbc->regs->portsc); in dbc_handle_port_status()
724 comp_code = GET_COMP_CODE(le32_to_cpu(event->generic.field[2])); in dbc_handle_xfer_event()
725 remain_length = EVENT_TRB_LEN(le32_to_cpu(event->generic.field[2])); in dbc_handle_xfer_event()
726 ep_id = TRB_TO_EP_ID(le32_to_cpu(event->generic.field[3])); in dbc_handle_xfer_event()
731 ring = dep->ring; in dbc_handle_xfer_event()
734 list_for_each_entry(r, &dep->list_pending, list_pending) { in dbc_handle_xfer_event()
735 if (r->trb_dma == event->trans_event.buffer) { in dbc_handle_xfer_event()
739 if (r->status == -COMP_STALL_ERROR) { in dbc_handle_xfer_event()
740 dev_warn(dbc->dev, "Give back stale stalled req\n"); in dbc_handle_xfer_event()
741 ring->num_trbs_free++; in dbc_handle_xfer_event()
747 dev_warn(dbc->dev, "no matched request\n"); in dbc_handle_xfer_event()
751 trace_xhci_dbc_handle_transfer(ring, &req->trb->generic, req->trb_dma); in dbc_handle_xfer_event()
763 dev_warn(dbc->dev, "tx error %d detected\n", comp_code); in dbc_handle_xfer_event()
764 status = -comp_code; in dbc_handle_xfer_event()
767 dev_warn(dbc->dev, "Stall error at bulk TRB %llx, remaining %zu, ep deq %llx\n", in dbc_handle_xfer_event()
768 event->trans_event.buffer, remain_length, ep_ctx->deq); in dbc_handle_xfer_event()
770 dep->halted = 1; in dbc_handle_xfer_event()
783 * In this case mark the TRB as No-Op to avoid hw from using the in dbc_handle_xfer_event()
787 if ((ep_ctx->deq & ~TRB_CYCLE) == event->trans_event.buffer) { in dbc_handle_xfer_event()
788 dev_dbg(dbc->dev, "Ep stopped on Stalled TRB\n"); in dbc_handle_xfer_event()
789 if (remain_length == req->length) { in dbc_handle_xfer_event()
790 dev_dbg(dbc->dev, "Spurious stall event, keep req\n"); in dbc_handle_xfer_event()
791 req->status = -COMP_STALL_ERROR; in dbc_handle_xfer_event()
792 req->actual = 0; in dbc_handle_xfer_event()
795 dev_dbg(dbc->dev, "Give back stalled req, but turn TRB to No-op\n"); in dbc_handle_xfer_event()
796 trb_to_noop(req->trb); in dbc_handle_xfer_event()
801 dev_err(dbc->dev, "unknown tx error %d\n", comp_code); in dbc_handle_xfer_event()
802 status = -comp_code; in dbc_handle_xfer_event()
806 ring->num_trbs_free++; in dbc_handle_xfer_event()
807 req->actual = req->length - remain_length; in dbc_handle_xfer_event()
814 if (ring->dequeue == &ring->deq_seg->trbs[TRBS_PER_SEGMENT - 1]) { in inc_evt_deq()
815 ring->cycle_state ^= 1; in inc_evt_deq()
816 ring->dequeue = ring->deq_seg->trbs; in inc_evt_deq()
819 ring->dequeue++; in inc_evt_deq()
831 switch (dbc->state) { in xhci_dbc_do_handle_events()
837 portsc = readl(&dbc->regs->portsc); in xhci_dbc_do_handle_events()
839 dbc->state = DS_CONNECTED; in xhci_dbc_do_handle_events()
840 dev_info(dbc->dev, "DbC connected\n"); in xhci_dbc_do_handle_events()
845 ctrl = readl(&dbc->regs->control); in xhci_dbc_do_handle_events()
847 dbc->state = DS_CONFIGURED; in xhci_dbc_do_handle_events()
848 dev_info(dbc->dev, "DbC configured\n"); in xhci_dbc_do_handle_events()
849 portsc = readl(&dbc->regs->portsc); in xhci_dbc_do_handle_events()
850 writel(portsc, &dbc->regs->portsc); in xhci_dbc_do_handle_events()
857 portsc = readl(&dbc->regs->portsc); in xhci_dbc_do_handle_events()
860 dev_info(dbc->dev, "DbC cable unplugged\n"); in xhci_dbc_do_handle_events()
861 dbc->state = DS_ENABLED; in xhci_dbc_do_handle_events()
869 dev_info(dbc->dev, "DbC port reset\n"); in xhci_dbc_do_handle_events()
870 writel(portsc, &dbc->regs->portsc); in xhci_dbc_do_handle_events()
871 dbc->state = DS_ENABLED; in xhci_dbc_do_handle_events()
878 ctrl = readl(&dbc->regs->control); in xhci_dbc_do_handle_events()
884 writel(ctrl, &dbc->regs->control); in xhci_dbc_do_handle_events()
885 ctrl = readl(&dbc->regs->control); in xhci_dbc_do_handle_events()
889 dev_err(dbc->dev, "Unknown DbC state %d\n", dbc->state); in xhci_dbc_do_handle_events()
894 evt = dbc->ring_evt->dequeue; in xhci_dbc_do_handle_events()
895 while ((le32_to_cpu(evt->event_cmd.flags) & TRB_CYCLE) == in xhci_dbc_do_handle_events()
896 dbc->ring_evt->cycle_state) { in xhci_dbc_do_handle_events()
903 trace_xhci_dbc_handle_event(dbc->ring_evt, &evt->generic, in xhci_dbc_do_handle_events()
904 xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg, in xhci_dbc_do_handle_events()
905 dbc->ring_evt->dequeue)); in xhci_dbc_do_handle_events()
907 switch (le32_to_cpu(evt->event_cmd.flags) & TRB_TYPE_BITMASK) { in xhci_dbc_do_handle_events()
919 inc_evt_deq(dbc->ring_evt); in xhci_dbc_do_handle_events()
921 evt = dbc->ring_evt->dequeue; in xhci_dbc_do_handle_events()
927 deq = xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg, in xhci_dbc_do_handle_events()
928 dbc->ring_evt->dequeue); in xhci_dbc_do_handle_events()
929 lo_hi_writeq(deq, &dbc->regs->erdp); in xhci_dbc_do_handle_events()
944 poll_interval = dbc->poll_interval; in xhci_dbc_handle_events()
946 spin_lock_irqsave(&dbc->lock, flags); in xhci_dbc_handle_events()
948 spin_unlock_irqrestore(&dbc->lock, flags); in xhci_dbc_handle_events()
952 if (dbc->driver->configure) in xhci_dbc_handle_events()
953 dbc->driver->configure(dbc); in xhci_dbc_handle_events()
956 if (dbc->driver->disconnect) in xhci_dbc_handle_events()
957 dbc->driver->disconnect(dbc); in xhci_dbc_handle_events()
964 busypoll_timelimit = dbc->xfer_timestamp + in xhci_dbc_handle_events()
967 if (!list_empty(&dbc->eps[BULK_OUT].list_pending) || in xhci_dbc_handle_events()
972 dbc->xfer_timestamp = jiffies; in xhci_dbc_handle_events()
976 dev_info(dbc->dev, "stop handling dbc events\n"); in xhci_dbc_handle_events()
980 mod_delayed_work(system_wq, &dbc->event_work, in xhci_dbc_handle_events()
997 struct xhci_hcd *xhci; in dbc_show() local
999 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_show()
1000 dbc = xhci->dbc; in dbc_show()
1002 if (dbc->state >= ARRAY_SIZE(dbc_state_strings)) in dbc_show()
1005 return sysfs_emit(buf, "%s\n", dbc_state_strings[dbc->state]); in dbc_show()
1012 struct xhci_hcd *xhci; in dbc_store() local
1015 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_store()
1016 dbc = xhci->dbc; in dbc_store()
1023 return -EINVAL; in dbc_store()
1033 struct xhci_hcd *xhci; in dbc_idVendor_show() local
1035 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_idVendor_show()
1036 dbc = xhci->dbc; in dbc_idVendor_show()
1038 return sysfs_emit(buf, "%04x\n", dbc->idVendor); in dbc_idVendor_show()
1046 struct xhci_hcd *xhci; in dbc_idVendor_store() local
1056 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_idVendor_store()
1057 dbc = xhci->dbc; in dbc_idVendor_store()
1058 if (dbc->state != DS_DISABLED) in dbc_idVendor_store()
1059 return -EBUSY; in dbc_idVendor_store()
1061 dbc->idVendor = value; in dbc_idVendor_store()
1062 ptr = &dbc->regs->devinfo1; in dbc_idVendor_store()
1075 struct xhci_hcd *xhci; in dbc_idProduct_show() local
1077 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_idProduct_show()
1078 dbc = xhci->dbc; in dbc_idProduct_show()
1080 return sysfs_emit(buf, "%04x\n", dbc->idProduct); in dbc_idProduct_show()
1088 struct xhci_hcd *xhci; in dbc_idProduct_store() local
1098 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_idProduct_store()
1099 dbc = xhci->dbc; in dbc_idProduct_store()
1100 if (dbc->state != DS_DISABLED) in dbc_idProduct_store()
1101 return -EBUSY; in dbc_idProduct_store()
1103 dbc->idProduct = value; in dbc_idProduct_store()
1104 ptr = &dbc->regs->devinfo2; in dbc_idProduct_store()
1116 struct xhci_hcd *xhci; in dbc_bcdDevice_show() local
1118 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_bcdDevice_show()
1119 dbc = xhci->dbc; in dbc_bcdDevice_show()
1121 return sysfs_emit(buf, "%04x\n", dbc->bcdDevice); in dbc_bcdDevice_show()
1129 struct xhci_hcd *xhci; in dbc_bcdDevice_store() local
1139 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_bcdDevice_store()
1140 dbc = xhci->dbc; in dbc_bcdDevice_store()
1141 if (dbc->state != DS_DISABLED) in dbc_bcdDevice_store()
1142 return -EBUSY; in dbc_bcdDevice_store()
1144 dbc->bcdDevice = value; in dbc_bcdDevice_store()
1145 ptr = &dbc->regs->devinfo2; in dbc_bcdDevice_store()
1158 struct xhci_hcd *xhci; in dbc_bInterfaceProtocol_show() local
1160 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_bInterfaceProtocol_show()
1161 dbc = xhci->dbc; in dbc_bInterfaceProtocol_show()
1163 return sysfs_emit(buf, "%02x\n", dbc->bInterfaceProtocol); in dbc_bInterfaceProtocol_show()
1171 struct xhci_hcd *xhci; in dbc_bInterfaceProtocol_store() local
1182 /* ...xhci only supports values 0 and 1 */ in dbc_bInterfaceProtocol_store()
1184 return -EINVAL; in dbc_bInterfaceProtocol_store()
1186 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_bInterfaceProtocol_store()
1187 dbc = xhci->dbc; in dbc_bInterfaceProtocol_store()
1188 if (dbc->state != DS_DISABLED) in dbc_bInterfaceProtocol_store()
1189 return -EBUSY; in dbc_bInterfaceProtocol_store()
1191 dbc->bInterfaceProtocol = value; in dbc_bInterfaceProtocol_store()
1192 ptr = &dbc->regs->devinfo1; in dbc_bInterfaceProtocol_store()
1205 struct xhci_hcd *xhci; in dbc_poll_interval_ms_show() local
1207 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_poll_interval_ms_show()
1208 dbc = xhci->dbc; in dbc_poll_interval_ms_show()
1210 return sysfs_emit(buf, "%u\n", dbc->poll_interval); in dbc_poll_interval_ms_show()
1218 struct xhci_hcd *xhci; in dbc_poll_interval_ms_store() local
1224 return -EINVAL; in dbc_poll_interval_ms_store()
1226 xhci = hcd_to_xhci(dev_get_drvdata(dev)); in dbc_poll_interval_ms_store()
1227 dbc = xhci->dbc; in dbc_poll_interval_ms_store()
1229 dbc->poll_interval = value; in dbc_poll_interval_ms_store()
1231 mod_delayed_work(system_wq, &dbc->event_work, 0); in dbc_poll_interval_ms_store()
1264 dbc->regs = base; in xhci_alloc_dbc()
1265 dbc->dev = dev; in xhci_alloc_dbc()
1266 dbc->driver = driver; in xhci_alloc_dbc()
1267 dbc->idProduct = DBC_PRODUCT_ID; in xhci_alloc_dbc()
1268 dbc->idVendor = DBC_VENDOR_ID; in xhci_alloc_dbc()
1269 dbc->bcdDevice = DBC_DEVICE_REV; in xhci_alloc_dbc()
1270 dbc->bInterfaceProtocol = DBC_PROTOCOL; in xhci_alloc_dbc()
1271 dbc->poll_interval = DBC_POLL_INTERVAL_DEFAULT; in xhci_alloc_dbc()
1273 if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE) in xhci_alloc_dbc()
1276 INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events); in xhci_alloc_dbc()
1277 spin_lock_init(&dbc->lock); in xhci_alloc_dbc()
1279 ret = sysfs_create_groups(&dev->kobj, dbc_dev_groups); in xhci_alloc_dbc()
1294 /* stop hw, stop wq and call dbc->ops->stop() */ in xhci_dbc_remove()
1298 sysfs_remove_groups(&dbc->dev->kobj, dbc_dev_groups); in xhci_dbc_remove()
1304 int xhci_create_dbc_dev(struct xhci_hcd *xhci) in xhci_create_dbc_dev() argument
1312 dev = xhci_to_hcd(xhci)->self.controller; in xhci_create_dbc_dev()
1313 base = &xhci->cap_regs->hc_capbase; in xhci_create_dbc_dev()
1317 return -ENODEV; in xhci_create_dbc_dev()
1320 if (xhci->dbc) in xhci_create_dbc_dev()
1321 return -EBUSY; in xhci_create_dbc_dev()
1323 ret = xhci_dbc_tty_probe(dev, base + dbc_cap_offs, xhci); in xhci_create_dbc_dev()
1328 void xhci_remove_dbc_dev(struct xhci_hcd *xhci) in xhci_remove_dbc_dev() argument
1332 if (!xhci->dbc) in xhci_remove_dbc_dev()
1335 xhci_dbc_tty_remove(xhci->dbc); in xhci_remove_dbc_dev()
1336 spin_lock_irqsave(&xhci->lock, flags); in xhci_remove_dbc_dev()
1337 xhci->dbc = NULL; in xhci_remove_dbc_dev()
1338 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_remove_dbc_dev()
1342 int xhci_dbc_suspend(struct xhci_hcd *xhci) in xhci_dbc_suspend() argument
1344 struct xhci_dbc *dbc = xhci->dbc; in xhci_dbc_suspend()
1349 if (dbc->state == DS_CONFIGURED) in xhci_dbc_suspend()
1350 dbc->resume_required = 1; in xhci_dbc_suspend()
1357 int xhci_dbc_resume(struct xhci_hcd *xhci) in xhci_dbc_resume() argument
1360 struct xhci_dbc *dbc = xhci->dbc; in xhci_dbc_resume()
1365 if (dbc->resume_required) { in xhci_dbc_resume()
1366 dbc->resume_required = 0; in xhci_dbc_resume()