diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c index 9aaaf9f29..8a8badfde 100644 --- a/devicemodel/hw/pci/xhci.c +++ b/devicemodel/hw/pci/xhci.c @@ -49,10 +49,8 @@ #include "xhci.h" #include "usb_core.h" -static int xhci_debug; -#define DPRINTF(params) do { if (xhci_debug) printf params; } while (0) -#define WPRINTF(params) (printf params) -#define XHCI_NAME "xhci" +#undef LOG_TAG +#define LOG_TAG "xHCI: " #define XHCI_MAX_DEVS 8 /* 4 USB3 + 4 USB2 devs */ #define XHCI_MAX_SLOTS 64 /* min allowed by Windows drivers */ @@ -426,20 +424,20 @@ pci_xhci_portregs_write(struct pci_xhci_vdev *xdev, port = (offset - XHCI_PORTREGS_PORT0) / XHCI_PORTREGS_SETSZ; offset = (offset - XHCI_PORTREGS_PORT0) % XHCI_PORTREGS_SETSZ; - DPRINTF(("pci_xhci: portregs wr offset 0x%lx, port %u: 0x%lx\r\n", - offset, port, value)); + UPRINTF(LDBG, "portregs wr offset 0x%lx, port %u: 0x%lx\r\n", + offset, port, value); assert(port >= 0); if (port > XHCI_MAX_DEVS) { - DPRINTF(("pci_xhci: portregs_write port %d > ndevices\r\n", - port)); + UPRINTF(LWRN, "portregs_write port %d > ndevices\r\n", + port); return; } if (XHCI_DEVINST_PTR(xdev, port) == NULL) { - DPRINTF(("pci_xhci: portregs_write to unattached port %d\r\n", - port)); + UPRINTF(LDBG, "portregs_write to unattached port %d\r\n", + port); } p = XHCI_PORTREG_PTR(xdev, port); @@ -452,8 +450,8 @@ pci_xhci_portregs_write(struct pci_xhci_vdev *xdev, } if ((p->portsc & XHCI_PS_PP) == 0) { - WPRINTF(("pci_xhci: portregs_write to unpowered " - "port %d\r\n", port)); + UPRINTF(LWRN, "portregs_write to unpowered " + "port %d\r\n", port); break; } @@ -489,12 +487,12 @@ pci_xhci_portregs_write(struct pci_xhci_vdev *xdev, /* port disable request; for USB3, don't care */ if (value & XHCI_PS_PED) - DPRINTF(("Disable port %d request\r\n", port)); + UPRINTF(LDBG, "Disable port %d request\r\n", port); if (!(value & XHCI_PS_LWS)) break; - DPRINTF(("Port new PLS: %d\r\n", newpls)); + UPRINTF(LDBG, "Port new PLS: %d\r\n", newpls); switch (newpls) { case 0: /* U0 */ case 3: /* U3 */ @@ -513,8 +511,8 @@ pci_xhci_portregs_write(struct pci_xhci_vdev *xdev, break; default: - DPRINTF(("Unhandled change port %d PLS %u\r\n", - port, newpls)); + UPRINTF(LWRN, "Unhandled change port %d PLS %u\r\n", + port, newpls); break; } break; @@ -524,8 +522,8 @@ pci_xhci_portregs_write(struct pci_xhci_vdev *xdev, break; case 8: /* Port link information register */ - DPRINTF(("pci_xhci attempted write to PORTLI, port %d\r\n", - port)); + UPRINTF(LDBG, "attempted write to PORTLI, port %d\r\n", + port); break; case 12: /* @@ -549,12 +547,12 @@ pci_xhci_get_dev_ctx(struct pci_xhci_vdev *xdev, uint32_t slot) devctx_addr = xdev->opregs.dcbaa_p->dcba[slot]; if (devctx_addr == 0) { - DPRINTF(("get_dev_ctx devctx_addr == 0\r\n")); + UPRINTF(LDBG, "get_dev_ctx devctx_addr == 0\r\n"); return NULL; } - DPRINTF(("pci_xhci: get dev ctx, slot %u devctx addr %016lx\r\n", - slot, devctx_addr)); + UPRINTF(LDBG, "get dev ctx, slot %u devctx addr %016lx\r\n", + slot, devctx_addr); devctx = XHCI_GADDR(xdev, devctx_addr & ~0x3FUL); return devctx; @@ -623,7 +621,8 @@ pci_xhci_init_ep(struct pci_xhci_dev_emu *dev, int epid) devep = &dev->eps[epid]; pstreams = XHCI_EPCTX_0_MAXP_STREAMS_GET(ep_ctx->dwEpCtx0); if (pstreams > 0) { - DPRINTF(("init_ep %d with pstreams %d\r\n", epid, pstreams)); + UPRINTF(LDBG, "init_ep %d with pstreams %d\r\n", + epid, pstreams); assert(devep->ep_sctx_trbs == NULL); devep->ep_sctx = XHCI_GADDR(dev->xdev, ep_ctx->qwEpCtx2 & @@ -638,12 +637,12 @@ pci_xhci_init_ep(struct pci_xhci_dev_emu *dev, int epid) XHCI_SCTX_0_DCS_GET(devep->ep_sctx[i].qwSctx0); } } else { - DPRINTF(("init_ep %d with no pstreams\r\n", epid)); + UPRINTF(LDBG, "init_ep %d with no pstreams\r\n", epid); devep->ep_ringaddr = ep_ctx->qwEpCtx2 & XHCI_EPCTX_2_TR_DQ_PTR_MASK; devep->ep_ccs = XHCI_EPCTX_2_DCS_GET(ep_ctx->qwEpCtx2); devep->ep_tr = XHCI_GADDR(dev->xdev, devep->ep_ringaddr); - DPRINTF(("init_ep tr DCS %x\r\n", devep->ep_ccs)); + UPRINTF(LDBG, "init_ep tr DCS %x\r\n", devep->ep_ccs); } if (devep->ep_xfer == NULL) { @@ -663,7 +662,7 @@ pci_xhci_disable_ep(struct pci_xhci_dev_emu *dev, int epid) struct pci_xhci_dev_ep *devep; struct xhci_endp_ctx *ep_ctx; - DPRINTF(("pci_xhci disable_ep %d\r\n", epid)); + UPRINTF(LDBG, "pci_xhci disable_ep %d\r\n", epid); dev_ctx = dev->dev_ctx; ep_ctx = &dev_ctx->ctx_ep[epid]; @@ -690,7 +689,7 @@ pci_xhci_reset_slot(struct pci_xhci_vdev *xdev, int slot) dev = XHCI_SLOTDEV_PTR(xdev, slot); if (!dev) - DPRINTF(("xhci reset unassigned slot (%d)?\r\n", slot)); + UPRINTF(LDBG, "reset unassigned slot (%d)?\r\n", slot); else dev->dev_slotstate = XHCI_ST_DISABLED; @@ -716,21 +715,21 @@ pci_xhci_insert_event(struct pci_xhci_vdev *xdev, erdp_idx = (erdp - rts->erstba_p[rts->er_deq_seg].qwEvrsTablePtr) / sizeof(struct xhci_trb); - DPRINTF(("pci_xhci: insert event 0[%lx] 2[%x] 3[%x]\r\n" - "\terdp idx %d/seg %d, enq idx %d/seg %d, pcs %u\r\n" - "\t(erdp=0x%lx, erst=0x%lx, tblsz=%u, do_intr %d)\r\n", - evtrb->qwTrb0, evtrb->dwTrb2, evtrb->dwTrb3, - erdp_idx, rts->er_deq_seg, rts->er_enq_idx, - rts->er_enq_seg, - rts->event_pcs, erdp, rts->erstba_p->qwEvrsTablePtr, - rts->erstba_p->dwEvrsTableSize, do_intr)); + UPRINTF(LDBG, "insert event 0[%lx] 2[%x] 3[%x]\r\n" + "\terdp idx %d/seg %d, enq idx %d/seg %d, pcs %u\r\n" + "\t(erdp=0x%lx, erst=0x%lx, tblsz=%u, do_intr %d)\r\n", + evtrb->qwTrb0, evtrb->dwTrb2, evtrb->dwTrb3, + erdp_idx, rts->er_deq_seg, rts->er_enq_idx, + rts->er_enq_seg, + rts->event_pcs, erdp, rts->erstba_p->qwEvrsTablePtr, + rts->erstba_p->dwEvrsTableSize, do_intr); evtrbptr = &rts->erst_p[rts->er_enq_idx]; /* TODO: multi-segment table */ if (rts->er_events_cnt >= rts->erstba_p->dwEvrsTableSize) { - DPRINTF(("pci_xhci[%d] cannot insert event; ring full\r\n", - __LINE__)); + UPRINTF(LWRN, "[%d] cannot insert event; ring full\r\n", + __LINE__); err = XHCI_TRB_ERROR_EV_RING_FULL; goto done; } @@ -740,8 +739,8 @@ pci_xhci_insert_event(struct pci_xhci_vdev *xdev, if ((evtrbptr->dwTrb3 & 0x1) == (rts->event_pcs & 0x1)) { - DPRINTF(("pci_xhci[%d] insert evt err: ring full\r\n", - __LINE__)); + UPRINTF(LWRN, "[%d] insert evt err: ring full\r\n", + __LINE__); errev.qwTrb0 = 0; errev.dwTrb2 = XHCI_TRB_2_ERROR_SET( @@ -800,8 +799,8 @@ pci_xhci_cmd_enable_slot(struct pci_xhci_vdev *xdev, uint32_t *slot) } } - DPRINTF(("pci_xhci enable slot (error=%d) slot %u\r\n", - cmderr != XHCI_TRB_ERROR_SUCCESS, *slot)); + UPRINTF(LDBG, "enable slot (error=%d) slot %u\r\n", + cmderr != XHCI_TRB_ERROR_SUCCESS, *slot); return cmderr; } @@ -812,7 +811,7 @@ pci_xhci_cmd_disable_slot(struct pci_xhci_vdev *xdev, uint32_t slot) struct pci_xhci_dev_emu *dev; uint32_t cmderr; - DPRINTF(("pci_xhci disable slot %u\r\n", slot)); + UPRINTF(LDBG, "pci_xhci disable slot %u\r\n", slot); cmderr = XHCI_TRB_ERROR_NO_SLOTS; if (xdev->portregs == NULL) @@ -851,7 +850,7 @@ pci_xhci_cmd_reset_device(struct pci_xhci_vdev *xdev, uint32_t slot) if (xdev->portregs == NULL) goto done; - DPRINTF(("pci_xhci reset device slot %u\r\n", slot)); + UPRINTF(LDBG, "pci_xhci reset device slot %u\r\n", slot); dev = XHCI_SLOTDEV_PTR(xdev, slot); if (!dev || dev->dev_slotstate == XHCI_ST_DISABLED) @@ -910,19 +909,19 @@ pci_xhci_cmd_address_device(struct pci_xhci_vdev *xdev, cmderr = XHCI_TRB_ERROR_SUCCESS; - DPRINTF(("pci_xhci: address device, input ctl: D 0x%08x A 0x%08x,\r\n" + UPRINTF(LDBG, "address device, input ctl: D 0x%08x A 0x%08x,\r\n" " slot %08x %08x %08x %08x\r\n" " ep0 %08x %08x %016lx %08x\r\n", input_ctx->ctx_input.dwInCtx0, input_ctx->ctx_input.dwInCtx1, islot_ctx->dwSctx0, islot_ctx->dwSctx1, islot_ctx->dwSctx2, islot_ctx->dwSctx3, ep0_ctx->dwEpCtx0, ep0_ctx->dwEpCtx1, ep0_ctx->qwEpCtx2, - ep0_ctx->dwEpCtx4)); + ep0_ctx->dwEpCtx4); /* when setting address: drop-ctx=0, add-ctx=slot+ep0 */ if ((input_ctx->ctx_input.dwInCtx0 != 0) || (input_ctx->ctx_input.dwInCtx1 & 0x03) != 0x03) { - DPRINTF(("pci_xhci: address device, input ctl invalid\r\n")); + UPRINTF(LDBG, "address device, input ctl invalid\r\n"); cmderr = XHCI_TRB_ERROR_TRB; goto done; } @@ -933,10 +932,10 @@ pci_xhci_cmd_address_device(struct pci_xhci_vdev *xdev, cmderr = XHCI_TRB_ERROR_CONTEXT_STATE; goto done; } - DPRINTF(("pci_xhci: address device, dev ctx\r\n" - " slot %08x %08x %08x %08x\r\n", + UPRINTF(LDBG, "address device, dev ctx\r\n" + " slot %08x %08x %08x %08x\r\n", dev_ctx->ctx_slot.dwSctx0, dev_ctx->ctx_slot.dwSctx1, - dev_ctx->ctx_slot.dwSctx2, dev_ctx->ctx_slot.dwSctx3)); + dev_ctx->ctx_slot.dwSctx2, dev_ctx->ctx_slot.dwSctx3); dev = XHCI_SLOTDEV_PTR(xdev, slot); assert(dev != NULL); @@ -968,13 +967,13 @@ pci_xhci_cmd_address_device(struct pci_xhci_vdev *xdev, dev->dev_slotstate = XHCI_ST_ADDRESSED; - DPRINTF(("pci_xhci: address device, output ctx\r\n" - " slot %08x %08x %08x %08x\r\n" - " ep0 %08x %08x %016lx %08x\r\n", + UPRINTF(LDBG, "address device, output ctx\r\n" + " slot %08x %08x %08x %08x\r\n" + " ep0 %08x %08x %016lx %08x\r\n", dev_ctx->ctx_slot.dwSctx0, dev_ctx->ctx_slot.dwSctx1, dev_ctx->ctx_slot.dwSctx2, dev_ctx->ctx_slot.dwSctx3, ep0_ctx->dwEpCtx0, ep0_ctx->dwEpCtx1, ep0_ctx->qwEpCtx2, - ep0_ctx->dwEpCtx4)); + ep0_ctx->dwEpCtx4); done: return cmderr; @@ -994,14 +993,13 @@ pci_xhci_cmd_config_ep(struct pci_xhci_vdev *xdev, cmderr = XHCI_TRB_ERROR_SUCCESS; - DPRINTF(("pci_xhci config_ep slot %u\r\n", slot)); + UPRINTF(LDBG, "config_ep slot %u\r\n", slot); dev = XHCI_SLOTDEV_PTR(xdev, slot); assert(dev != NULL); if ((trb->dwTrb3 & XHCI_TRB_3_DCEP_BIT) != 0) { - DPRINTF(("pci_xhci config_ep - deconfigure ep slot %u\r\n", - slot)); + UPRINTF(LDBG, "config_ep - deconfigure ep slot %u\r\n", slot); if (dev->dev_ue->ue_stop != NULL) dev->dev_ue->ue_stop(dev->dev_instance); @@ -1032,8 +1030,8 @@ pci_xhci_cmd_config_ep(struct pci_xhci_vdev *xdev, } if (dev->dev_slotstate < XHCI_ST_ADDRESSED) { - DPRINTF(("pci_xhci: config_ep slotstate x%x != addressed\r\n", - dev->dev_slotstate)); + UPRINTF(LWRN, "config_ep slotstate x%x != addressed\r\n", + dev->dev_slotstate); cmderr = XHCI_TRB_ERROR_SLOT_NOT_ON; goto done; } @@ -1054,16 +1052,16 @@ pci_xhci_cmd_config_ep(struct pci_xhci_vdev *xdev, input_ctx = XHCI_GADDR(xdev, trb->qwTrb0 & ~0xFUL); dev_ctx = dev->dev_ctx; - DPRINTF(("pci_xhci: config_ep inputctx: D:x%08x A:x%08x 7:x%08x\r\n", + UPRINTF(LDBG, "config_ep inputctx: D:x%08x A:x%08x 7:x%08x\r\n", input_ctx->ctx_input.dwInCtx0, input_ctx->ctx_input.dwInCtx1, - input_ctx->ctx_input.dwInCtx7)); + input_ctx->ctx_input.dwInCtx7); for (i = 2; i <= 31; i++) { ep_ctx = &dev_ctx->ctx_ep[i]; if (input_ctx->ctx_input.dwInCtx0 & XHCI_INCTX_0_DROP_MASK(i)) { - DPRINTF((" config ep - dropping ep %d\r\n", i)); + UPRINTF(LDBG, " config ep - dropping ep %d\r\n", i); pci_xhci_disable_ep(dev, i); } @@ -1071,9 +1069,9 @@ pci_xhci_cmd_config_ep(struct pci_xhci_vdev *xdev, XHCI_INCTX_1_ADD_MASK(i)) { iep_ctx = &input_ctx->ctx_ep[i]; - DPRINTF((" enable ep[%d] %08x %08x %016lx %08x\r\n", + UPRINTF(LDBG, " enable ep%d %08x %08x %016lx %08x\r\n", i, iep_ctx->dwEpCtx0, iep_ctx->dwEpCtx1, - iep_ctx->qwEpCtx2, iep_ctx->dwEpCtx4)); + iep_ctx->qwEpCtx2, iep_ctx->dwEpCtx4); memcpy(ep_ctx, iep_ctx, sizeof(struct xhci_endp_ctx)); @@ -1098,10 +1096,12 @@ pci_xhci_cmd_config_ep(struct pci_xhci_vdev *xdev, input_ctx->ctx_slot.dwSctx0, 0x1F, 27); dev->dev_slotstate = XHCI_ST_CONFIGURED; - DPRINTF(("EP configured; slot %u [0]=0x%08x [1]=0x%08x [2]=0x%08x " - "[3]=0x%08x\r\n", slot, dev_ctx->ctx_slot.dwSctx0, - dev_ctx->ctx_slot.dwSctx1, dev_ctx->ctx_slot.dwSctx2, - dev_ctx->ctx_slot.dwSctx3)); + UPRINTF(LDBG, "EP configured; slot %u [0]=0x%08x [1]=0x%08x" + " [2]=0x%08x [3]=0x%08x\r\n", slot, + dev_ctx->ctx_slot.dwSctx0, + dev_ctx->ctx_slot.dwSctx1, + dev_ctx->ctx_slot.dwSctx2, + dev_ctx->ctx_slot.dwSctx3); done: return cmderr; @@ -1125,7 +1125,7 @@ pci_xhci_cmd_reset_ep(struct pci_xhci_vdev *xdev, epid = XHCI_TRB_3_EP_GET(trb->dwTrb3); - DPRINTF(("pci_xhci: reset ep %u: slot %u\r\n", epid, slot)); + UPRINTF(LDBG, "reset ep %u: slot %u\r\n", epid, slot); cmderr = XHCI_TRB_ERROR_SUCCESS; @@ -1140,7 +1140,7 @@ pci_xhci_cmd_reset_ep(struct pci_xhci_vdev *xdev, } if (epid < 1 || epid > 31) { - DPRINTF(("pci_xhci: reset ep: invalid epid %u\r\n", epid)); + UPRINTF(LDBG, "reset ep: invalid epid %u\r\n", epid); cmderr = XHCI_TRB_ERROR_TRB; goto done; } @@ -1159,9 +1159,9 @@ pci_xhci_cmd_reset_ep(struct pci_xhci_vdev *xdev, if (XHCI_EPCTX_0_MAXP_STREAMS_GET(ep_ctx->dwEpCtx0) == 0) ep_ctx->qwEpCtx2 = devep->ep_ringaddr | devep->ep_ccs; - DPRINTF(("pci_xhci: reset ep[%u] %08x %08x %016lx %08x\r\n", + UPRINTF(LDBG, "reset ep[%u] %08x %08x %016lx %08x\r\n", epid, ep_ctx->dwEpCtx0, ep_ctx->dwEpCtx1, ep_ctx->qwEpCtx2, - ep_ctx->dwEpCtx4)); + ep_ctx->dwEpCtx4); if (type == XHCI_TRB_TYPE_RESET_EP && (dev->dev_ue->ue_reset == NULL || @@ -1191,7 +1191,7 @@ pci_xhci_find_stream(struct pci_xhci_vdev *xdev, return XHCI_TRB_ERROR_INVALID_SID; if (XHCI_EPCTX_0_LSA_GET(ep->dwEpCtx0) == 0) { - DPRINTF(("pci_xhci: find_stream; LSA bit not set\r\n")); + UPRINTF(LWRN, "find_stream; LSA bit not set\r\n"); return XHCI_TRB_ERROR_INVALID_SID; } @@ -1225,16 +1225,16 @@ pci_xhci_cmd_set_tr(struct pci_xhci_vdev *xdev, dev = XHCI_SLOTDEV_PTR(xdev, slot); assert(dev != NULL); - DPRINTF(("pci_xhci set_tr: new-tr x%016lx, SCT %u DCS %u\r\n" - " stream-id %u, slot %u, epid %u, C %u\r\n", + UPRINTF(LDBG, "set_tr: new-tr x%016lx, SCT %u DCS %u\r\n" + " stream-id %u, slot %u, epid %u, C %u\r\n", (trb->qwTrb0 & ~0xF), (uint32_t)((trb->qwTrb0 >> 1) & 0x7), (uint32_t)(trb->qwTrb0 & 0x1), (trb->dwTrb2 >> 16) & 0xFFFF, XHCI_TRB_3_SLOT_GET(trb->dwTrb3), - XHCI_TRB_3_EP_GET(trb->dwTrb3), trb->dwTrb3 & 0x1)); + XHCI_TRB_3_EP_GET(trb->dwTrb3), trb->dwTrb3 & 0x1); epid = XHCI_TRB_3_EP_GET(trb->dwTrb3); if (epid < 1 || epid > 31) { - DPRINTF(("pci_xhci: set_tr_deq: invalid epid %u\r\n", epid)); + UPRINTF(LDBG, "set_tr_deq: invalid epid %u\r\n", epid); cmderr = XHCI_TRB_ERROR_TRB; goto done; } @@ -1250,8 +1250,8 @@ pci_xhci_cmd_set_tr(struct pci_xhci_vdev *xdev, case XHCI_ST_EPCTX_ERROR: break; default: - DPRINTF(("pci_xhci cmd set_tr invalid state %x\r\n", - XHCI_EPCTX_0_EPSTATE_GET(ep_ctx->dwEpCtx0))); + UPRINTF(LDBG, "cmd set_tr invalid state %x\r\n", + XHCI_EPCTX_0_EPSTATE_GET(ep_ctx->dwEpCtx0)); cmderr = XHCI_TRB_ERROR_CONTEXT_STATE; goto done; } @@ -1273,15 +1273,15 @@ pci_xhci_cmd_set_tr(struct pci_xhci_vdev *xdev, } } else { if (streamid != 0) { - DPRINTF(("pci_xhci cmd set_tr streamid %x != 0\r\n", - streamid)); + UPRINTF(LDBG, "cmd set_tr streamid %x != 0\r\n", + streamid); } ep_ctx->qwEpCtx2 = trb->qwTrb0 & ~0xFUL; devep->ep_ringaddr = ep_ctx->qwEpCtx2 & ~0xFUL; devep->ep_ccs = trb->qwTrb0 & 0x1; devep->ep_tr = XHCI_GADDR(xdev, devep->ep_ringaddr); - DPRINTF(("pci_xhci set_tr first TRB:\r\n")); + UPRINTF(LDBG, "set_tr first TRB:\r\n"); pci_xhci_dump_trb(devep->ep_tr); } ep_ctx->dwEpCtx0 = (ep_ctx->dwEpCtx0 & ~0x7) | XHCI_ST_EPCTX_STOPPED; @@ -1306,19 +1306,19 @@ pci_xhci_cmd_eval_ctx(struct pci_xhci_vdev *xdev, ep0_ctx = &input_ctx->ctx_ep[1]; cmderr = XHCI_TRB_ERROR_SUCCESS; - DPRINTF(("pci_xhci: eval ctx, input ctl: D 0x%08x A 0x%08x,\r\n" - " slot %08x %08x %08x %08x\r\n" - " ep0 %08x %08x %016lx %08x\r\n", + UPRINTF(LDBG, "eval ctx, input ctl: D 0x%08x A 0x%08x,\r\n" + " slot %08x %08x %08x %08x\r\n" + " ep0 %08x %08x %016lx %08x\r\n", input_ctx->ctx_input.dwInCtx0, input_ctx->ctx_input.dwInCtx1, islot_ctx->dwSctx0, islot_ctx->dwSctx1, islot_ctx->dwSctx2, islot_ctx->dwSctx3, ep0_ctx->dwEpCtx0, ep0_ctx->dwEpCtx1, ep0_ctx->qwEpCtx2, - ep0_ctx->dwEpCtx4)); + ep0_ctx->dwEpCtx4); /* this command expects drop-ctx=0 & add-ctx=slot+ep0 */ if ((input_ctx->ctx_input.dwInCtx0 != 0) || (input_ctx->ctx_input.dwInCtx1 & 0x03) == 0) { - DPRINTF(("pci_xhci: eval ctx, input ctl invalid\r\n")); + UPRINTF(LWRN, "eval ctx, input ctl invalid\r\n"); cmderr = XHCI_TRB_ERROR_TRB; goto done; } @@ -1330,10 +1330,10 @@ pci_xhci_cmd_eval_ctx(struct pci_xhci_vdev *xdev, goto done; } - DPRINTF(("pci_xhci: eval ctx, dev ctx\r\n" - " slot %08x %08x %08x %08x\r\n", + UPRINTF(LDBG, "eval ctx, dev ctx\r\n" + " slot %08x %08x %08x %08x\r\n", dev_ctx->ctx_slot.dwSctx0, dev_ctx->ctx_slot.dwSctx1, - dev_ctx->ctx_slot.dwSctx2, dev_ctx->ctx_slot.dwSctx3)); + dev_ctx->ctx_slot.dwSctx2, dev_ctx->ctx_slot.dwSctx3); if (input_ctx->ctx_input.dwInCtx1 & 0x01) { /* slot ctx */ /* set max exit latency */ @@ -1355,13 +1355,13 @@ pci_xhci_cmd_eval_ctx(struct pci_xhci_vdev *xdev, ep0_ctx = &dev_ctx->ctx_ep[1]; } - DPRINTF(("pci_xhci: eval ctx, output ctx\r\n" - " slot %08x %08x %08x %08x\r\n" - " ep0 %08x %08x %016lx %08x\r\n", + UPRINTF(LDBG, "eval ctx, output ctx\r\n" + " slot %08x %08x %08x %08x\r\n" + " ep0 %08x %08x %016lx %08x\r\n", dev_ctx->ctx_slot.dwSctx0, dev_ctx->ctx_slot.dwSctx1, dev_ctx->ctx_slot.dwSctx2, dev_ctx->ctx_slot.dwSctx3, ep0_ctx->dwEpCtx0, ep0_ctx->dwEpCtx1, ep0_ctx->qwEpCtx2, - ep0_ctx->dwEpCtx4)); + ep0_ctx->dwEpCtx4); done: return cmderr; @@ -1395,10 +1395,10 @@ pci_xhci_complete_commands(struct pci_xhci_vdev *xdev) (ccs & XHCI_TRB_3_CYCLE_BIT)) break; - DPRINTF(("pci_xhci: cmd type 0x%x, Trb0 x%016lx dwTrb2 x%08x" + UPRINTF(LDBG, "cmd type 0x%x, Trb0 x%016lx dwTrb2 x%08x" " dwTrb3 x%08x, TRB_CYCLE %u/ccs %u\r\n", type, trb->qwTrb0, trb->dwTrb2, trb->dwTrb3, - trb->dwTrb3 & XHCI_TRB_3_CYCLE_BIT, ccs)); + trb->dwTrb3 & XHCI_TRB_3_CYCLE_BIT, ccs); cmderr = XHCI_TRB_ERROR_SUCCESS; evtrb.dwTrb2 = 0; @@ -1437,13 +1437,13 @@ pci_xhci_complete_commands(struct pci_xhci_vdev *xdev) break; case XHCI_TRB_TYPE_RESET_EP: /* 0x0E */ - DPRINTF(("Reset Endpoint on slot %d\r\n", slot)); + UPRINTF(LDBG, "Reset Endpoint on slot %d\r\n", slot); slot = XHCI_TRB_3_SLOT_GET(trb->dwTrb3); cmderr = pci_xhci_cmd_reset_ep(xdev, slot, trb); break; case XHCI_TRB_TYPE_STOP_EP: /* 0x0F */ - DPRINTF(("Stop Endpoint on slot %d\r\n", slot)); + UPRINTF(LDBG, "Stop Endpoint on slot %d\r\n", slot); slot = XHCI_TRB_3_SLOT_GET(trb->dwTrb3); cmderr = pci_xhci_cmd_reset_ep(xdev, slot, trb); break; @@ -1478,7 +1478,7 @@ pci_xhci_complete_commands(struct pci_xhci_vdev *xdev) break; default: - DPRINTF(("pci_xhci: unsupported cmd %x\r\n", type)); + UPRINTF(LDBG, "unsupported cmd %x\r\n", type); break; } @@ -1489,8 +1489,8 @@ pci_xhci_complete_commands(struct pci_xhci_vdev *xdev) evtrb.qwTrb0 = crcr; evtrb.dwTrb2 |= XHCI_TRB_2_ERROR_SET(cmderr); evtrb.dwTrb3 |= XHCI_TRB_3_SLOT_SET(slot); - DPRINTF(("pci_xhci: command 0x%x result: 0x%x\r\n", - type, cmderr)); + UPRINTF(LDBG, "command 0x%x result: 0x%x\r\n", + type, cmderr); pci_xhci_insert_event(xdev, &evtrb, 1); } @@ -1534,10 +1534,10 @@ pci_xhci_dump_trb(struct xhci_trb *trb) uint32_t type; type = XHCI_TRB_3_TYPE_GET(trb->dwTrb3); - DPRINTF(("pci_xhci: trb[@%p] type x%02x %s 0:x%016lx 2:x%08x " + UPRINTF(LDBG, "trb[@%p] type x%02x %s 0:x%016lx 2:x%08x " "3:x%08x\r\n", trb, type, type <= XHCI_TRB_TYPE_NOOP_CMD ? trbtypes[type] : "INVALID", - trb->qwTrb0, trb->dwTrb2, trb->dwTrb3)); + trb->qwTrb0, trb->dwTrb2, trb->dwTrb3); } static int @@ -1576,12 +1576,12 @@ pci_xhci_xfer_complete(struct pci_xhci_vdev *xdev, trb = XHCI_GADDR(xdev, evtrb.qwTrb0); trbflags = trb->dwTrb3; - DPRINTF(("pci_xhci: xfer[%d] done?%u:%d trb %x %016lx %x " + UPRINTF(LDBG, "xfer[%d] done?%u:%d trb %x %016lx %x " "(err %d) IOC?%d\r\n", i, xfer->data[i].processed, xfer->data[i].blen, XHCI_TRB_3_TYPE_GET(trbflags), evtrb.qwTrb0, trbflags, err, - trb->dwTrb3 & XHCI_TRB_3_IOC_BIT ? 1 : 0)); + trb->dwTrb3 & XHCI_TRB_3_IOC_BIT ? 1 : 0); if (!xfer->data[i].processed) { xfer->head = (int)i; @@ -1614,7 +1614,7 @@ pci_xhci_xfer_complete(struct pci_xhci_vdev *xdev, XHCI_TRB_3_SLOT_SET(slot) | XHCI_TRB_3_EP_SET(epid); if (XHCI_TRB_3_TYPE_GET(trbflags) == XHCI_TRB_TYPE_EVENT_DATA) { - DPRINTF(("pci_xhci EVENT_DATA edtla %u\r\n", edtla)); + UPRINTF(LDBG, "EVENT_DATA edtla %u\r\n", edtla); evtrb.qwTrb0 = trb->qwTrb0; evtrb.dwTrb2 = (edtla & 0xFFFFF) | XHCI_TRB_2_ERROR_SET(err); @@ -1651,16 +1651,16 @@ pci_xhci_update_ep_ring(struct pci_xhci_vdev *xdev, devep->ep_sctx_trbs[streamid].ccs = ccs & 0x1; ep_ctx->qwEpCtx2 = (ep_ctx->qwEpCtx2 & ~0x1) | (ccs & 0x1); - DPRINTF(("xhci update ep-ring stream %d, addr %lx\r\n", - streamid, devep->ep_sctx[streamid].qwSctx0)); + UPRINTF(LDBG, "update ep-ring stream %d, addr %lx\r\n", + streamid, devep->ep_sctx[streamid].qwSctx0); } else { devep->ep_ringaddr = ringaddr & ~0xFUL; devep->ep_ccs = ccs & 0x1; devep->ep_tr = XHCI_GADDR(xdev, ringaddr & ~0xFUL); ep_ctx->qwEpCtx2 = (ringaddr & ~0xFUL) | (ccs & 0x1); - DPRINTF(("xhci update ep-ring, addr %lx\r\n", - (devep->ep_ringaddr | devep->ep_ccs))); + UPRINTF(LDBG, "update ep-ring, addr %lx\r\n", + (devep->ep_ringaddr | devep->ep_ccs)); } } @@ -1738,7 +1738,7 @@ pci_xhci_handle_transfer(struct pci_xhci_vdev *xdev, xfer = devep->ep_xfer; USB_DATA_XFER_LOCK(xfer); - DPRINTF(("pci_xhci handle_transfer slot %u\r\n", slot)); + UPRINTF(LDBG, "handle_transfer slot %u\r\n", slot); retry: err = 0; @@ -1754,8 +1754,9 @@ retry: if (XHCI_TRB_3_TYPE_GET(trbflags) != XHCI_TRB_TYPE_LINK && (trbflags & XHCI_TRB_3_CYCLE_BIT) != (ccs & XHCI_TRB_3_CYCLE_BIT)) { - DPRINTF(("Cycle-bit changed trbflags %x, ccs %x\r\n", - trbflags & XHCI_TRB_3_CYCLE_BIT, ccs)); + UPRINTF(LDBG, "Cycle-bit changed trbflags %x," + " ccs %x\r\n", + trbflags & XHCI_TRB_3_CYCLE_BIT, ccs); break; } @@ -1778,7 +1779,7 @@ retry: case XHCI_TRB_TYPE_SETUP_STAGE: if ((trbflags & XHCI_TRB_3_IDT_BIT) == 0 || XHCI_TRB_2_BYTES_GET(trb->dwTrb2) != 8) { - DPRINTF(("pci_xhci: invalid setup trb\r\n")); + UPRINTF(LDBG, "invalid setup trb\r\n"); err = XHCI_TRB_ERROR_TRB; goto errout; } @@ -1809,8 +1810,8 @@ retry: case XHCI_TRB_TYPE_NORMAL: case XHCI_TRB_TYPE_ISOCH: if (setup_trb != NULL) { - DPRINTF(("pci_xhci: trb not supposed to be in " - "ctl scope\r\n")); + UPRINTF(LWRN, "trb not supposed to be in " + "ctl scope\r\n"); err = XHCI_TRB_ERROR_TRB; goto errout; } @@ -1853,16 +1854,16 @@ retry: break; default: - DPRINTF(("pci_xhci: handle xfer unexpected trb type " + UPRINTF(LWRN, "handle xfer unexpected trb type " "0x%x\r\n", - XHCI_TRB_3_TYPE_GET(trbflags))); + XHCI_TRB_3_TYPE_GET(trbflags)); err = XHCI_TRB_ERROR_TRB; goto errout; } trb = pci_xhci_trb_next(xdev, trb, &addr); - DPRINTF(("pci_xhci: next trb: 0x%lx\r\n", (uint64_t)trb)); + UPRINTF(LDBG, "next trb: 0x%lx\r\n", (uint64_t)trb); if (xfer_block) { xfer_block->trbnext = addr; @@ -1876,14 +1877,14 @@ retry: /* handle current batch that requires interrupt on complete */ if (trbflags & XHCI_TRB_3_IOC_BIT) { - DPRINTF(("pci_xhci: trb IOC bit set\r\n")); + UPRINTF(LDBG, "trb IOC bit set\r\n"); if (epid == 1) do_retry = 1; break; } } - DPRINTF(("pci_xhci[%d]: xfer->ndata %u\r\n", __LINE__, xfer->ndata)); + UPRINTF(LDBG, "[%d]: xfer->ndata %u\r\n", __LINE__, xfer->ndata); if (epid == 1) { err = USB_ERR_NOT_STARTED; @@ -1907,7 +1908,7 @@ retry: errout: if (err == XHCI_TRB_ERROR_EV_RING_FULL) - DPRINTF(("pci_xhci[%d]: event ring full\r\n", __LINE__)); + UPRINTF(LDBG, "[%d]: event ring full\r\n", __LINE__); if (!do_retry) USB_DATA_XFER_UNLOCK(xfer); @@ -1917,8 +1918,8 @@ errout: if (do_retry) { USB_DATA_XFER_RESET(xfer); - DPRINTF(("pci_xhci[%d]: retry:continuing with next TRBs\r\n", - __LINE__)); + UPRINTF(LDBG, "[%d]: retry:continuing with next TRBs\r\n", + __LINE__); goto retry; } @@ -1943,11 +1944,11 @@ pci_xhci_device_doorbell(struct pci_xhci_vdev *xdev, uint64_t ringaddr; uint32_t ccs; - DPRINTF(("pci_xhci doorbell slot %u epid %u stream %u\r\n", - slot, epid, streamid)); + UPRINTF(LDBG, "doorbell slot %u epid %u stream %u\r\n", + slot, epid, streamid); if (slot == 0 || slot > xdev->ndevices) { - DPRINTF(("pci_xhci: invalid doorbell slot %u\r\n", slot)); + UPRINTF(LWRN, "invalid doorbell slot %u\r\n", slot); return; } @@ -1960,9 +1961,9 @@ pci_xhci_device_doorbell(struct pci_xhci_vdev *xdev, sctx_tr = NULL; - DPRINTF(("pci_xhci: device doorbell ep[%u] %08x %08x %016lx %08x\r\n", + UPRINTF(LDBG, "device doorbell ep[%u] %08x %08x %016lx %08x\r\n", epid, ep_ctx->dwEpCtx0, ep_ctx->dwEpCtx1, ep_ctx->qwEpCtx2, - ep_ctx->dwEpCtx4)); + ep_ctx->dwEpCtx4); if (ep_ctx->qwEpCtx2 == 0) return; @@ -1979,21 +1980,21 @@ pci_xhci_device_doorbell(struct pci_xhci_vdev *xdev, ringaddr = sctx_tr->ringaddr; ccs = sctx_tr->ccs; trb = XHCI_GADDR(xdev, sctx_tr->ringaddr & ~0xFUL); - DPRINTF(("doorbell, stream %u, ccs %lx, trb ccs %x\r\n", + UPRINTF(LDBG, "doorbell, stream %u, ccs %lx, trb ccs %x\r\n", streamid, ep_ctx->qwEpCtx2 & XHCI_TRB_3_CYCLE_BIT, - trb->dwTrb3 & XHCI_TRB_3_CYCLE_BIT)); + trb->dwTrb3 & XHCI_TRB_3_CYCLE_BIT); } else { ringaddr = devep->ep_ringaddr; ccs = devep->ep_ccs; trb = devep->ep_tr; - DPRINTF(("doorbell, ccs %lx, trb ccs %x\r\n", + UPRINTF(LDBG, "doorbell, ccs %lx, trb ccs %x\r\n", ep_ctx->qwEpCtx2 & XHCI_TRB_3_CYCLE_BIT, - trb->dwTrb3 & XHCI_TRB_3_CYCLE_BIT)); + trb->dwTrb3 & XHCI_TRB_3_CYCLE_BIT); } if (XHCI_TRB_3_TYPE_GET(trb->dwTrb3) == 0) { - DPRINTF(("pci_xhci: ring %lx trb[%lx] EP %u is RESERVED?\r\n", - ep_ctx->qwEpCtx2, devep->ep_ringaddr, epid)); + UPRINTF(LDBG, "ring %lx trb[%lx] EP %u is RESERVED?\r\n", + ep_ctx->qwEpCtx2, devep->ep_ringaddr, epid); return; } @@ -2009,11 +2010,11 @@ pci_xhci_dbregs_write(struct pci_xhci_vdev *xdev, offset = (offset - xdev->dboff) / sizeof(uint32_t); - DPRINTF(("pci_xhci: doorbell write offset 0x%lx: 0x%lx\r\n", - offset, value)); + UPRINTF(LDBG, "doorbell write offset 0x%lx: 0x%lx\r\n", + offset, value); if (XHCI_HALTED(xdev)) { - DPRINTF(("pci_xhci: controller halted\r\n")); + UPRINTF(LWRN, "pci_xhci: controller halted\r\n"); return; } @@ -2035,12 +2036,12 @@ pci_xhci_rtsregs_write(struct pci_xhci_vdev *xdev, offset -= xdev->rtsoff; if (offset == 0) { - DPRINTF(("pci_xhci attempted write to MFINDEX\r\n")); + UPRINTF(LWRN, "attempted write to MFINDEX\r\n"); return; } - DPRINTF(("pci_xhci: runtime regs write offset 0x%lx: 0x%lx\r\n", - offset, value)); + UPRINTF(LDBG, "runtime regs write offset 0x%lx: 0x%lx\r\n", + offset, value); offset -= 0x20; /* start of intrreg */ @@ -2087,10 +2088,10 @@ pci_xhci_rtsregs_write(struct pci_xhci_vdev *xdev, rts->er_enq_idx = 0; rts->er_events_cnt = 0; - DPRINTF(("pci_xhci: wr erstba erst (%p) ptr 0x%lx, sz %u\r\n", + UPRINTF(LDBG, "wr erstba erst (%p) ptr 0x%lx, sz %u\r\n", rts->erstba_p, rts->erstba_p->qwEvrsTablePtr, - rts->erstba_p->dwEvrsTableSize)); + rts->erstba_p->dwEvrsTableSize); break; case 0x18: @@ -2127,15 +2128,15 @@ pci_xhci_rtsregs_write(struct pci_xhci_vdev *xdev, rts->erstba_p->dwEvrsTableSize - (erdp_i - rts->er_enq_idx); - DPRINTF(("pci_xhci: erdp 0x%lx, events cnt %u\r\n", - erdp, rts->er_events_cnt)); + UPRINTF(LDBG, "erdp 0x%lx, events cnt %u\r\n", + erdp, rts->er_events_cnt); } break; default: - DPRINTF(("pci_xhci attempted write to RTS offset 0x%lx\r\n", - offset)); + UPRINTF(LWRN, "attempted write to RTS offset 0x%lx\r\n", + offset); break; } } @@ -2152,8 +2153,8 @@ pci_xhci_portregs_read(struct pci_xhci_vdev *xdev, uint64_t offset) port = (offset - 0x3F0) / 0x10; if (port > XHCI_MAX_DEVS) { - DPRINTF(("pci_xhci: portregs_read port %d >= XHCI_MAX_DEVS\r\n", - port)); + UPRINTF(LWRN, "portregs_read port %d >= XHCI_MAX_DEVS\r\n", + port); /* return default value for unused port */ return XHCI_PS_SPEED_SET(3); @@ -2164,8 +2165,8 @@ pci_xhci_portregs_read(struct pci_xhci_vdev *xdev, uint64_t offset) p = &xdev->portregs[port].portsc; p += offset / sizeof(uint32_t); - DPRINTF(("pci_xhci: portregs read offset 0x%lx port %u -> 0x%x\r\n", - offset, port, *p)); + UPRINTF(LDBG, "portregs read offset 0x%lx port %u -> 0x%x\r\n", + offset, port, *p); return *p; } @@ -2178,8 +2179,8 @@ pci_xhci_hostop_write(struct pci_xhci_vdev *xdev, offset -= XHCI_CAPLEN; if (offset < 0x400) - DPRINTF(("pci_xhci: hostop write offset 0x%lx: 0x%lx\r\n", - offset, value)); + UPRINTF(LDBG, "hostop write offset 0x%lx: 0x%lx\r\n", + offset, value); switch (offset) { case XHCI_USBCMD: @@ -2241,8 +2242,8 @@ pci_xhci_hostop_write(struct pci_xhci_vdev *xdev, xdev->opregs.dcbaa_p = XHCI_GADDR(xdev, xdev->opregs.dcbaap & ~0x3FUL); - DPRINTF(("pci_xhci: opregs dcbaap = 0x%lx (vaddr 0x%lx)\r\n", - xdev->opregs.dcbaap, (uint64_t)xdev->opregs.dcbaa_p)); + UPRINTF(LDBG, "opregs dcbaap = 0x%lx (vaddr 0x%lx)\r\n", + xdev->opregs.dcbaap, (uint64_t)xdev->opregs.dcbaa_p); break; case XHCI_CONFIG: @@ -2274,7 +2275,7 @@ pci_xhci_write(struct vmctx *ctx, pthread_mutex_lock(&xdev->mtx); if (offset < XHCI_CAPLEN) /* read only registers */ - WPRINTF(("pci_xhci: write RO-CAPs offset %ld\r\n", offset)); + UPRINTF(LWRN, "write RO-CAPs offset %ld\r\n", offset); else if (offset < xdev->dboff) pci_xhci_hostop_write(xdev, offset, value); else if (offset < xdev->rtsoff) @@ -2282,7 +2283,7 @@ pci_xhci_write(struct vmctx *ctx, else if (offset < xdev->regsend) pci_xhci_rtsregs_write(xdev, offset, value); else - WPRINTF(("pci_xhci: write invalid offset %ld\r\n", offset)); + UPRINTF(LWRN, "write invalid offset %ld\r\n", offset); pthread_mutex_unlock(&xdev->mtx); } @@ -2330,8 +2331,8 @@ pci_xhci_hostcap_read(struct pci_xhci_vdev *xdev, uint64_t offset) break; } - DPRINTF(("pci_xhci: hostcap read offset 0x%lx -> 0x%lx\r\n", - offset, value)); + UPRINTF(LDBG, "hostcap read offset 0x%lx -> 0x%lx\r\n", + offset, value); return value; } @@ -2390,8 +2391,8 @@ pci_xhci_hostop_read(struct pci_xhci_vdev *xdev, uint64_t offset) } if (offset < 0x400) - DPRINTF(("pci_xhci: hostop read offset 0x%lx -> 0x%lx\r\n", - offset, value)); + UPRINTF(LDBG, "hostop read offset 0x%lx -> 0x%lx\r\n", + offset, value); return value; } @@ -2427,8 +2428,8 @@ pci_xhci_rtsregs_read(struct pci_xhci_vdev *xdev, uint64_t offset) value = *p; } - DPRINTF(("pci_xhci: rtsregs read offset 0x%lx -> 0x%x\r\n", - offset, value)); + UPRINTF(LDBG, "rtsregs read offset 0x%lx -> 0x%x\r\n", + offset, value); return value; } @@ -2471,12 +2472,11 @@ pci_xhci_xecp_read(struct pci_xhci_vdev *xdev, uint64_t offset) case 28: break; default: - DPRINTF(("pci_xhci: xecp invalid offset 0x%lx\r\n", offset)); + UPRINTF(LDBG, "xecp invalid offset 0x%lx\r\n", offset); break; } - DPRINTF(("pci_xhci: xecp read offset 0x%lx -> 0x%x\r\n", - offset, value)); + UPRINTF(LDBG, "xecp read offset 0x%lx -> 0x%x\r\n", offset, value); return value; } @@ -2509,7 +2509,7 @@ pci_xhci_read(struct vmctx *ctx, value = pci_xhci_xecp_read(xdev, offset); else { value = 0; - WPRINTF(("pci_xhci: read invalid offset %ld\r\n", offset)); + UPRINTF(LDBG, "read invalid offset %ld\r\n", offset); } pthread_mutex_unlock(&xdev->mtx); @@ -2539,7 +2539,7 @@ pci_xhci_reset_port(struct pci_xhci_vdev *xdev, int portn, int warm) assert(portn <= XHCI_MAX_DEVS); - DPRINTF(("xhci reset port %d\r\n", portn)); + UPRINTF(LDBG, "reset port %d\r\n", portn); port = XHCI_PORTREG_PTR(xdev, portn); dev = XHCI_DEVINST_PTR(xdev, portn); @@ -2559,8 +2559,8 @@ pci_xhci_reset_port(struct pci_xhci_vdev *xdev, int portn, int warm) XHCI_TRB_EVENT_PORT_STS_CHANGE); error = pci_xhci_insert_event(xdev, &evtrb, 1); if (error != XHCI_TRB_ERROR_SUCCESS) - DPRINTF(("xhci reset port insert event " - "failed\n")); + UPRINTF(LWRN, "reset port insert event " + "failed\n"); } } } @@ -2586,10 +2586,11 @@ pci_xhci_init_port(struct pci_xhci_vdev *xdev, int portn) XHCI_PS_SPEED_SET(dev->dev_ue->ue_usbspeed); } - DPRINTF(("Init port %d 0x%x\n", portn, port->portsc)); + UPRINTF(LDBG, "Init port %d 0x%x\n", portn, port->portsc); } else { port->portsc = XHCI_PS_PLS_SET(UPS_PORT_LS_RX_DET) | XHCI_PS_PP; - DPRINTF(("Init empty port %d 0x%x\n", portn, port->portsc)); + UPRINTF(LDBG, "Init empty port %d 0x%x\n", + portn, port->portsc); } } @@ -2645,12 +2646,12 @@ pci_xhci_dev_intr(struct usb_hci *hci, int epctx) dev_ctx = dev->dev_ctx; ep_ctx = &dev_ctx->ctx_ep[epid]; if ((ep_ctx->dwEpCtx0 & 0x7) == XHCI_ST_EPCTX_DISABLED) { - DPRINTF(("xhci device interrupt on disabled endpoint %d\r\n", - epid)); + UPRINTF(LWRN, "device interrupt on disabled endpoint %d\r\n", + epid); return 0; } - DPRINTF(("xhci device interrupt on endpoint %d\r\n", epid)); + UPRINTF(LDBG, "device interrupt on endpoint %d\r\n", epid); pci_xhci_device_doorbell(xdev, hci->hci_port, epid, 0); @@ -2661,7 +2662,7 @@ done: static int pci_xhci_dev_event(struct usb_hci *hci, enum hci_usbev evid, void *param) { - DPRINTF(("xhci device event port %d\r\n", hci->hci_port)); + UPRINTF(LDBG, "xhci device event port %d\r\n", hci->hci_port); return 0; } @@ -2691,16 +2692,16 @@ pci_xhci_parse_opts(struct pci_xhci_vdev *xdev, char *opts) devices = calloc(XHCI_MAX_DEVS, sizeof(struct pci_xhci_dev_emu *)); if (devices == NULL) { usb2_port = usb3_port = -1; - WPRINTF(("pci_xhci: %s:%d fail to allocate memory(devices)\n", - __func__, __LINE__)); + UPRINTF(LWRN, "%s:%d fail to allocate memory(devices)\n", + __func__, __LINE__); goto done; } xdev->slots = calloc(XHCI_MAX_SLOTS, sizeof(struct pci_xhci_dev_emu *)); if (xdev->slots == NULL) { usb2_port = usb3_port = -1; - WPRINTF(("pci_xhci: %s:%d fail to allocate memory(slots)\n", - __func__, __LINE__)); + UPRINTF(LWRN, "%s:%d fail to allocate memory(slots)\n", + __func__, __LINE__); goto done; } @@ -2715,8 +2716,8 @@ pci_xhci_parse_opts(struct pci_xhci_vdev *xdev, char *opts) ((xdev->usb2_port_start - 1) + XHCI_MAX_DEVS/2) || usb3_port == ((xdev->usb3_port_start - 1) + XHCI_MAX_DEVS/2)) { - WPRINTF(("pci_xhci max number of USB 2 or 3 " - "devices reached, max %d\r\n", XHCI_MAX_DEVS/2)); + UPRINTF(LWRN, "pci_xhci max number of USB 2 or 3 " + "devices reached, max %d\r\n", XHCI_MAX_DEVS/2); usb2_port = usb3_port = -1; goto done; } @@ -2731,19 +2732,19 @@ pci_xhci_parse_opts(struct pci_xhci_vdev *xdev, char *opts) ue = usb_emu_finddev(xopts); if (ue == NULL) { pci_xhci_device_usage(xopts); - DPRINTF(("pci_xhci device not found %s\r\n", xopts)); + UPRINTF(LWRN, "device not found %s\r\n", xopts); usb2_port = usb3_port = -1; goto done; } - DPRINTF(("pci_xhci adding device %s, opts \"%s\"\r\n", - xopts, config)); + UPRINTF(LDBG, "adding device %s, opts \"%s\"\r\n", + xopts, config); dev = calloc(1, sizeof(struct pci_xhci_dev_emu)); if (!dev) { usb2_port = usb3_port = -1; - WPRINTF(("pci_xhci: %s:%d fail to allocate memory\n", - __func__, __LINE__)); + UPRINTF(LWRN, "%s:%d fail to allocate memory\n", + __func__, __LINE__); goto done; } dev->xdev = xdev; @@ -2791,7 +2792,7 @@ portsfinal: for (i = 1; i <= XHCI_MAX_DEVS; i++) pci_xhci_init_port(xdev, i); } else { - WPRINTF(("pci_xhci no USB devices configured\r\n")); + UPRINTF(LWRN, "no USB devices configured\r\n"); xdev->ndevices = 1; } @@ -2816,15 +2817,15 @@ pci_xhci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) int error; if (xhci_in_use) { - WPRINTF(("pci_xhci controller already defined\r\n")); + UPRINTF(LWRN, "controller already defined\r\n"); return -1; } xhci_in_use = 1; xdev = calloc(1, sizeof(struct pci_xhci_vdev)); if (!xdev) { - WPRINTF(("pci_xhci: %s:%d fail to allocate memory\n", - __func__, __LINE__)); + UPRINTF(LWRN, "%s:%d fail to allocate memory\n", + __func__, __LINE__); return -1; } @@ -2867,8 +2868,8 @@ pci_xhci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) if (xdev->rtsoff & 0x1F) xdev->rtsoff = (xdev->rtsoff + 0x1F) & ~0x1F; - DPRINTF(("pci_xhci dboff: 0x%x, rtsoff: 0x%x\r\n", xdev->dboff, - xdev->rtsoff)); + UPRINTF(LDBG, "dboff: 0x%x, rtsoff: 0x%x\r\n", xdev->dboff, + xdev->rtsoff); xdev->opregs.usbsts = XHCI_STS_HCH; xdev->opregs.pgsz = XHCI_PAGESIZE_4K; @@ -2895,7 +2896,7 @@ pci_xhci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) /* regsend + xecp registers */ pci_emul_alloc_bar(dev, 0, PCIBAR_MEM32, xdev->regsend + 4*32); - DPRINTF(("pci_xhci pci_emu_alloc: %d\r\n", xdev->regsend + 4*32)); + UPRINTF(LDBG, "pci_emu_alloc: %d\r\n", xdev->regsend + 4*32); pci_lintr_request(dev); diff --git a/devicemodel/hw/platform/usb_mouse.c b/devicemodel/hw/platform/usb_mouse.c index ed0c5e050..7f4f3cb23 100644 --- a/devicemodel/hw/platform/usb_mouse.c +++ b/devicemodel/hw/platform/usb_mouse.c @@ -39,10 +39,8 @@ #include "console.h" #include "gc.h" -static int umouse_debug; -#define DPRINTF(params) do { if (umouse_debug) printf params; } while (0) -#define WPRINTF(params) (printf params) - +#undef LOG_TAG +#define LOG_TAG "umouse: " /* USB endpoint context (1-15) for reporting mouse data events*/ #define UMOUSE_INTR_ENDPT 1 @@ -290,7 +288,7 @@ umouse_init(struct usb_hci *hci, char *opt) dev = calloc(1, sizeof(struct umouse_vdev)); if (!dev) { - WPRINTF(("umouse: calloc returns NULL\n")); + UPRINTF(LFTL, "calloc returns NULL\n"); return NULL; } dev->hci = hci; @@ -345,7 +343,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) eshort = 0; if (!xfer->ureq) { - DPRINTF(("%s: port %d\r\n", __func__, dev->hci->hci_port)); + UPRINTF(LDBG, "%s: port %d\r\n", __func__, dev->hci->hci_port); goto done; } @@ -353,14 +351,14 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) index = xfer->ureq->wIndex; len = xfer->ureq->wLength; - DPRINTF(("%s: port %d, type 0x%x, req 0x%x," + UPRINTF(LDBG, "%s: port %d, type 0x%x, req 0x%x," "val 0x%x, idx 0x%x, len %u\r\n", __func__, dev->hci->hci_port, xfer->ureq->bmRequestType, - xfer->ureq->bRequest, value, index, len)); + xfer->ureq->bRequest, value, index, len); switch (UREQ(xfer->ureq->bRequest, xfer->ureq->bmRequestType)) { case UREQ(UR_GET_CONFIG, UT_READ_DEVICE): - DPRINTF(("umouse: (UR_GET_CONFIG, UT_READ_DEVICE)\r\n")); + UPRINTF(LDBG, "(UR_GET_CONFIG, UT_READ_DEVICE)\r\n"); if (!data) break; @@ -371,17 +369,17 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) break; case UREQ(UR_GET_DESCRIPTOR, UT_READ_DEVICE): - DPRINTF(("umouse: (UR_GET_DESCRIPTOR,UT_READ_DEVICE)" + UPRINTF(LDBG, "(UR_GET_DESCRIPTOR,UT_READ_DEVICE)" "val %x\r\n", - value >> 8)); + value >> 8); if (!data) break; switch (value >> 8) { case UDESC_DEVICE: - DPRINTF(("umouse: (->UDESC_DEVICE) len %u" + UPRINTF(LDBG, "(->UDESC_DEVICE) len %u" "?= sizeof(umouse_dev_desc) %lu\r\n", - len, sizeof(umouse_dev_desc))); + len, sizeof(umouse_dev_desc)); if ((value & 0xFF) != 0) { err = USB_ERR_IOERROR; goto done; @@ -396,7 +394,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) break; case UDESC_CONFIG: - DPRINTF(("umouse: (->UDESC_CONFIG)\r\n")); + UPRINTF(LDBG, "(->UDESC_CONFIG)\r\n"); if ((value & 0xFF) != 0) { err = USB_ERR_IOERROR; goto done; @@ -412,7 +410,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) break; case UDESC_STRING: - DPRINTF(("umouse: (->UDESC_STRING)\r\n")); + UPRINTF(LDBG, "(->UDESC_STRING)\r\n"); str = NULL; if ((value & 0xFF) < UMSTR_MAX) str = umouse_desc_strings[value & 0xFF]; @@ -455,7 +453,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) break; case UDESC_BOS: - DPRINTF(("umouse: USB3 BOS\r\n")); + UPRINTF(LDBG, "USB3 BOS\r\n"); if (len > sizeof(umouse_bosd)) { data->blen = len - sizeof(umouse_bosd); len = sizeof(umouse_bosd); @@ -466,7 +464,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) break; default: - DPRINTF(("umouse: unknown(%d)->ERROR\r\n", value >> 8)); + UPRINTF(LDBG, "unknown(%d)->ERROR\r\n", value >> 8); err = USB_ERR_IOERROR; goto done; } @@ -474,9 +472,9 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) break; case UREQ(UR_GET_DESCRIPTOR, UT_READ_INTERFACE): - DPRINTF(("umouse: (UR_GET_DESCRIPTOR, UT_READ_INTERFACE)" + UPRINTF(LDBG, "(UR_GET_DESCRIPTOR, UT_READ_INTERFACE)" "0x%x\r\n", - (value >> 8))); + (value >> 8)); if (!data) break; @@ -491,7 +489,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) data->bdone += len; break; default: - DPRINTF(("umouse: IO ERROR\r\n")); + UPRINTF(LWRN, "IO ERROR\r\n"); err = USB_ERR_IOERROR; goto done; } @@ -499,10 +497,10 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) break; case UREQ(UR_GET_INTERFACE, UT_READ_INTERFACE): - DPRINTF(("umouse: (UR_GET_INTERFACE, UT_READ_INTERFACE)\r\n")); + UPRINTF(LDBG, "(UR_GET_INTERFACE, UT_READ_INTERFACE)\r\n"); if (index != 0) { - DPRINTF(("umouse get_interface, invalid index %d\r\n", - index)); + UPRINTF(LDBG, "get_interface, invalid index %d\r\n", + index); err = USB_ERR_IOERROR; goto done; } @@ -519,7 +517,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) break; case UREQ(UR_GET_STATUS, UT_READ_DEVICE): - DPRINTF(("umouse: (UR_GET_STATUS, UT_READ_DEVICE)\r\n")); + UPRINTF(LDBG, "umouse: (UR_GET_STATUS, UT_READ_DEVICE)\r\n"); if (!data) break; @@ -537,7 +535,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) case UREQ(UR_GET_STATUS, UT_READ_INTERFACE): case UREQ(UR_GET_STATUS, UT_READ_ENDPOINT): - DPRINTF(("umouse: (UR_GET_STATUS, UT_READ_INTERFACE)\r\n")); + UPRINTF(LDBG, "(UR_GET_STATUS, UT_READ_INTERFACE)\r\n"); if (!data) break; @@ -551,28 +549,28 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) case UREQ(UR_SET_ADDRESS, UT_WRITE_DEVICE): /* XXX Controller should've handled this */ - DPRINTF(("umouse set address %u\r\n", value)); + UPRINTF(LDBG, "set address %u\r\n", value); break; case UREQ(UR_SET_CONFIG, UT_WRITE_DEVICE): - DPRINTF(("umouse set config %u\r\n", value)); + UPRINTF(LDBG, "set config %u\r\n", value); break; case UREQ(UR_SET_DESCRIPTOR, UT_WRITE_DEVICE): - DPRINTF(("umouse set descriptor %u\r\n", value)); + UPRINTF(LDBG, "set descriptor %u\r\n", value); break; case UREQ(UR_CLEAR_FEATURE, UT_WRITE_DEVICE): - DPRINTF(("umouse: (UR_SET_FEATURE,UT_WRITE_DEVICE) %x\r\n", - value)); + UPRINTF(LDBG, "(UR_SET_FEATURE,UT_WRITE_DEVICE) %x\r\n", + value); if (value == UF_DEVICE_REMOTE_WAKEUP) dev->hid.feature = 0; break; case UREQ(UR_SET_FEATURE, UT_WRITE_DEVICE): - DPRINTF(("umouse: (UR_SET_FEATURE,UT_WRITE_DEVICE) %x\r\n", - value)); + UPRINTF(LDBG, "(UR_SET_FEATURE,UT_WRITE_DEVICE) %x\r\n", + value); if (value == UF_DEVICE_REMOTE_WAKEUP) dev->hid.feature = UF_DEVICE_REMOTE_WAKEUP; break; @@ -581,32 +579,32 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) case UREQ(UR_CLEAR_FEATURE, UT_WRITE_ENDPOINT): case UREQ(UR_SET_FEATURE, UT_WRITE_INTERFACE): case UREQ(UR_SET_FEATURE, UT_WRITE_ENDPOINT): - DPRINTF(("umouse: (UR_CLEAR_FEATURE,UT_WRITE_INTERFACE)\r\n" - )); + UPRINTF(LDBG, "(UR_CLEAR_FEATURE,UT_WRITE_INTERFACE)\r\n" + ); err = USB_ERR_IOERROR; goto done; case UREQ(UR_SET_INTERFACE, UT_WRITE_INTERFACE): - DPRINTF(("umouse set interface %u\r\n", value)); + UPRINTF(LDBG, "set interface %u\r\n", value); break; case UREQ(UR_ISOCH_DELAY, UT_WRITE_DEVICE): - DPRINTF(("umouse set isoch delay %u\r\n", value)); + UPRINTF(LDBG, "set isoch delay %u\r\n", value); break; case UREQ(UR_SET_SEL, 0): - DPRINTF(("umouse set sel\r\n")); + UPRINTF(LDBG, "set sel\r\n"); break; case UREQ(UR_SYNCH_FRAME, UT_WRITE_ENDPOINT): - DPRINTF(("umouse synch frame\r\n")); + UPRINTF(LDBG, "synch frame\r\n"); break; /* HID device requests */ case UREQ(UMOUSE_GET_REPORT, UT_READ_CLASS_INTERFACE): - DPRINTF(("umouse: (UMOUSE_GET_REPORT,UT_READ_CLASS_INTERFACE) " - "0x%x\r\n", (value >> 8))); + UPRINTF(LDBG, "(UMOUSE_GET_REPORT,UT_READ_CLASS_INTERFACE) " + "0x%x\r\n", (value >> 8)); if (!data) break; @@ -653,27 +651,27 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) break; case UREQ(UMOUSE_SET_REPORT, UT_WRITE_CLASS_INTERFACE): - DPRINTF(("umouse: (UMOUSE_SET_REPORT," + UPRINTF(LDBG, "(UMOUSE_SET_REPORT," "UT_WRITE_CLASS_INTERFACE) ignored\r\n" - )); + ); break; case UREQ(UMOUSE_SET_IDLE, UT_WRITE_CLASS_INTERFACE): dev->hid.idle = xfer->ureq->wValue >> 8; - DPRINTF(("umouse: (UMOUSE_SET_IDLE," + UPRINTF(LDBG, "(UMOUSE_SET_IDLE," "UT_WRITE_CLASS_INTERFACE) %x\r\n", - dev->hid.idle)); + dev->hid.idle); break; case UREQ(UMOUSE_SET_PROTOCOL, UT_WRITE_CLASS_INTERFACE): dev->hid.protocol = xfer->ureq->wValue >> 8; - DPRINTF(("umouse: (UR_CLEAR_FEATURE," + UPRINTF(LDBG, "(UR_CLEAR_FEATURE," "UT_WRITE_CLASS_INTERFACE) %x\r\n", - dev->hid.protocol)); + dev->hid.protocol); break; default: - DPRINTF(("**** umouse request unhandled\r\n")); + UPRINTF(LDBG, "**** umouse request unhandled\r\n"); err = USB_ERR_IOERROR; break; } @@ -685,8 +683,8 @@ done: else if (eshort) err = USB_ERR_SHORT_XFER; - DPRINTF(("umouse request error code %d (0=ok), blen %u txlen %u\r\n", - err, (data ? data->blen : 0), (data ? data->bdone : 0))); + UPRINTF(LDBG, "request error code %d (0=ok), blen %u txlen %u\r\n", + err, (data ? data->blen : 0), (data ? data->bdone : 0)); return err; } @@ -703,8 +701,8 @@ umouse_data_handler(void *scarg, struct usb_data_xfer *xfer, int dir, assert(xfer != NULL && xfer->head >= 0); - DPRINTF(("umouse handle data - DIR=%s|EP=%d, blen %d\r\n", - dir ? "IN" : "OUT", epctx, xfer->data[0].blen)); + UPRINTF(LDBG, "handle data - DIR=%s|EP=%d, blen %d\r\n", + dir ? "IN" : "OUT", epctx, xfer->data[0].blen); /* find buffer to add data */ udata = NULL; @@ -729,7 +727,7 @@ umouse_data_handler(void *scarg, struct usb_data_xfer *xfer, int dir, len = data->blen; if (udata == NULL) { - DPRINTF(("umouse no buffer provided for input\r\n")); + UPRINTF(LDBG, "no buffer provided for input\r\n"); err = USB_ERR_NOMEM; goto done; } diff --git a/devicemodel/hw/usb_core.c b/devicemodel/hw/usb_core.c index 7fb380388..8e0eab41a 100644 --- a/devicemodel/hw/usb_core.c +++ b/devicemodel/hw/usb_core.c @@ -36,6 +36,7 @@ #include "usb_core.h" SET_DECLARE(usb_emu_set, struct usb_devemu); +int usb_log_level; struct usb_devemu * usb_emu_finddev(char *name) diff --git a/devicemodel/include/usb_core.h b/devicemodel/include/usb_core.h index 91bf603b2..3e38153c9 100644 --- a/devicemodel/include/usb_core.h +++ b/devicemodel/include/usb_core.h @@ -141,6 +141,18 @@ enum USB_ERRCODE { #define USB_DATA_XFER_UNLOCK(x) \ pthread_mutex_unlock(&((x)->mtx)) +#define LOG_TAG "USB: " +#define LFTL 0 +#define LWRN 1 +#define LINF 2 +#define LDBG 3 +#define LVRB 4 +#define UPRINTF(lvl, fmt, args...) \ + do { if (lvl <= usb_log_level) printf(LOG_TAG fmt, ##args); } while (0) + +extern int usb_log_level; +inline int usb_get_log_level(void) { return usb_log_level; } +inline void usb_set_log_level(int level) { usb_log_level = level; } struct usb_devemu *usb_emu_finddev(char *name); struct usb_data_xfer_block *usb_data_xfer_append(struct usb_data_xfer *xfer,