@samitouri / QOSamiQemu / commits / 6fc2655f70

hw/usb/hcd-ehci: Replace DPRINTF debug logs with trace events

Replace legacy DPRINTF() debug logging in the EHCI host controller implementation with QEMU trace events. The EHCI_DEBUG macro and associated DPRINTF() definitions are removed as they are no longer needed. Trace events are added for: - packet submission and completion - queue head execution state - periodic schedule advancement - ITD error conditions - port state handling - skipped microframes No functional change. Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260424080508.53992-7-jamin_lin@aspeedtech.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Jamin Lin committed Apr 23, 2026 at 07:18 UTC 6fc2655f706c7cc6252217eb157d9d2949a37877
3 files changed +30 -38
hw/usb/hcd-ehci.c
+21 -28
@@ -839,7 +839,7 @@ static USBDevice *ehci_find_device(EHCIState *ehci, uint8_t addr)
839 for (i = 0; i < EHCI_PORTS; i++) {
840 port = &ehci->ports[i];
841 if (!(ehci->portsc[i] & PORTSC_PED)) {
842 - DPRINTF("Port %d not enabled\n", i);
842 + trace_usb_ehci_port_disable(i);
843 continue;
844 }
845 dev = usb_find_device(port, addr);
@@ -1281,10 +1281,8 @@ static void ehci_execute_complete(EHCIQueue *q)
1281 assert(p->async == EHCI_ASYNC_INITIALIZED ||
1282 p->async == EHCI_ASYNC_FINISHED);
1283
1284 - DPRINTF("execute_complete: qhaddr 0x%x, next 0x%x, qtdaddr 0x%x, "
1285 - "status %d, actual_length %d\n",
1286 - q->qhaddr, q->qh.next, q->qtdaddr,
1287 - p->packet.status, p->packet.actual_length);
1284 + trace_usb_ehci_execute_complete(q->qhaddr, q->qh.next, q->qtdaddr,
1285 + p->packet.status, p->packet.actual_length);
1286
1287 switch (p->packet.status) {
1288 case USB_RET_SUCCESS:
@@ -1327,7 +1325,7 @@ static void ehci_execute_complete(EHCIQueue *q)
1325 } else {
1326 tbytes = 0;
1327 }
1330 - DPRINTF("updating tbytes to %d\n", tbytes);
1328 + trace_usb_ehci_qh_tbytes(tbytes);
1329 set_field(&q->qh.token, tbytes, QTD_TOKEN_TBYTES);
1330
1331 ehci_finish_transfer(q, p->packet.actual_length);
@@ -1392,10 +1390,9 @@ static int ehci_execute(EHCIPacket *p, const char *action)
1390
1391 trace_usb_ehci_packet_action(p->queue, p, action);
1392 usb_handle_packet(p->queue->dev, &p->packet);
1395 - DPRINTF("submit: qh 0x%x next 0x%x qtd 0x%x pid 0x%x len %zd endp 0x%x "
1396 - "status %d actual_length %d\n", p->queue->qhaddr, p->qtd.next,
1397 - p->qtdaddr, p->pid, p->packet.iov.size, endp, p->packet.status,
1398 - p->packet.actual_length);
1393 + trace_usb_ehci_packet_submit(p->queue->qhaddr, p->qtd.next, p->qtdaddr,
1394 + p->pid, p->packet.iov.size, endp,
1395 + p->packet.status, p->packet.actual_length);
1396
1397 if (p->packet.actual_length > BUFF_SIZE) {
1398 qemu_log_mask(LOG_GUEST_ERROR,
@@ -1472,7 +1469,8 @@ static int ehci_process_itd(EHCIState *ehci,
1469 usb_handle_packet(dev, &ehci->ipacket);
1470 usb_packet_unmap(&ehci->ipacket, &ehci->isgl);
1471 } else {
1475 - DPRINTF("ISOCH: attempt to address non-iso endpoint\n");
1472 + trace_usb_ehci_log("ISOCH: "
1473 + "attempt to address non-iso endpoint");
1474 ehci->ipacket.status = USB_RET_NAK;
1475 ehci->ipacket.actual_length = 0;
1476 }
@@ -1677,24 +1675,22 @@ static EHCIQueue *ehci_state_fetchqh(EHCIState *ehci, int async)
1675 if (ehci->usbsts & USBSTS_REC) {
1676 ehci_clear_usbsts(ehci, USBSTS_REC);
1677 } else {
1680 - DPRINTF("FETCHQH: QH 0x%08x. H-bit set, reclamation status reset"
1681 - " - done processing\n", q->qhaddr);
1678 + trace_usb_ehci_fetchqh_reclaim_done(q->qhaddr);
1679 ehci_set_state(ehci, async, EST_ACTIVE);
1680 q = NULL;
1681 goto out;
1682 }
1683 }
1684
1688 -#if EHCI_DEBUG
1689 - if (q->qhaddr != q->qh.next) {
1690 - DPRINTF("FETCHQH: QH 0x%08x (h %x halt %x active %x) next 0x%08x\n",
1691 - q->qhaddr,
1692 - q->qh.epchar & QH_EPCHAR_H,
1693 - q->qh.token & QTD_TOKEN_HALT,
1694 - q->qh.token & QTD_TOKEN_ACTIVE,
1695 - q->qh.next);
1685 + if (trace_event_get_state_backends(TRACE_USB_EHCI_FETCHQH_DBG)) {
1686 + if (q->qhaddr != q->qh.next) {
1687 + trace_usb_ehci_fetchqh_dbg(q->qhaddr,
1688 + q->qh.epchar & QH_EPCHAR_H,
1689 + q->qh.token & QTD_TOKEN_HALT,
1690 + q->qh.token & QTD_TOKEN_ACTIVE,
1691 + q->qh.next);
1692 + }
1693 }
1697 -#endif
1694
1695 if (q->qh.token & QTD_TOKEN_HALT) {
1696 ehci_set_state(ehci, async, EST_HORIZONTALQH);
@@ -2161,7 +2157,7 @@ static void ehci_advance_async_state(EHCIState *ehci)
2157 /* make sure guest has acknowledged the doorbell interrupt */
2158 /* TO-DO: is this really needed? */
2159 if (ehci->usbsts & USBSTS_IAA) {
2164 - DPRINTF("IAA status bit still set.\n");
2160 + trace_usb_ehci_log("IAA status bit still set.");
2161 break;
2162 }
2163
@@ -2226,9 +2222,7 @@ static void ehci_advance_periodic_state(EHCIState *ehci)
2222 if (get_dwords(ehci, list, &entry, 1) < 0) {
2223 break;
2224 }
2229 -
2230 - DPRINTF("PERIODIC state adv fr=%d. [%08X] -> %08X\n",
2231 - ehci->frindex / 8, list, entry);
2225 + trace_usb_ehci_periodic_state_advance(ehci->frindex / 8, list, entry);
2226 ehci_set_fetch_addr(ehci, async, entry);
2227 ehci_set_state(ehci, async, EST_FETCHENTRY);
2228 ehci_advance_state(ehci, async);
@@ -2294,8 +2288,7 @@ static void ehci_work_bh(void *opaque)
2288 ehci_update_frindex(ehci, skipped_uframes);
2289 ehci->last_run_ns += UFRAME_TIMER_NS * skipped_uframes;
2290 uframes -= skipped_uframes;
2297 - DPRINTF("WARNING - EHCI skipped %"PRIu64" uframes\n",
2298 - skipped_uframes);
2291 + trace_usb_ehci_skipped_uframes(skipped_uframes);
2292 }
2293
2294 for (i = 0; i < uframes; i++) {
hw/usb/hcd-ehci.h
-10
@@ -24,16 +24,6 @@
24 #include "hw/pci/pci_device.h"
25 #include "hw/core/sysbus.h"
26
27 -#ifndef EHCI_DEBUG
28 -#define EHCI_DEBUG 0
29 -#endif
30 -
31 -#if EHCI_DEBUG
32 -#define DPRINTF printf
33 -#else
34 -#define DPRINTF(...)
35 -#endif
36 -
27 #define MMIO_SIZE 0x1000
28 #define CAPA_SIZE 0x10
29
hw/usb/trace-events
+9
@@ -89,6 +89,7 @@ usb_ehci_state(const char *schedule, const char *state) "%s schedule %s"
89 usb_ehci_qh_ptrs(void *q, uint32_t addr, uint32_t nxt, uint32_t c_qtd, uint32_t n_qtd, uint32_t a_qtd) "q %p - QH @ 0x%08x: next 0x%08x qtds 0x%08x,0x%08x,0x%08x"
90 usb_ehci_qh_fields(uint32_t addr, int rl, int mplen, int eps, int ep, int devaddr) "QH @ 0x%08x - rl %d, mplen %d, eps %d, ep %d, dev %d"
91 usb_ehci_qh_bits(uint32_t addr, int c, int h, int dtc, int i) "QH @ 0x%08x - c %d, h %d, dtc %d, i %d"
92 +usb_ehci_qh_tbytes(uint32_t tbytes) "updating tbytes to %d"
93 usb_ehci_qtd_ptrs(void *q, uint32_t addr, uint32_t nxt, uint32_t altnext) "q %p - QTD @ 0x%08x: next 0x%08x altnext 0x%08x"
94 usb_ehci_qtd_fields(uint32_t addr, int tbytes, int cpage, int cerr, int pid) "QTD @ 0x%08x - tbytes %d, cpage %d, cerr %d, pid %d"
95 usb_ehci_qtd_bits(uint32_t addr, int ioc, int active, int halt, int babble, int xacterr) "QTD @ 0x%08x - ioc %d, active %d, halt %d, babble %d, xacterr %d"
@@ -100,13 +101,21 @@ usb_ehci_port_reset(uint32_t port, int enable) "reset port #%d - %d"
101 usb_ehci_port_suspend(uint32_t port) "port #%d"
102 usb_ehci_port_wakeup(uint32_t port) "port #%d"
103 usb_ehci_port_resume(uint32_t port) "port #%d"
104 +usb_ehci_port_disable(uint32_t port) "port #%d"
105 usb_ehci_queue_action(void *q, const char *action) "q %p: %s"
106 usb_ehci_packet_action(void *q, void *p, const char *action) "q %p p %p: %s"
107 +usb_ehci_packet_submit(uint32_t qhaddr, uint32_t next, uint32_t qtdaddr, int pid, size_t len, int endp, int status, int actual_length) "qh=0x%x, next=0x%x, qtd=0x%x, pid=0x%x, len=%zd, endp=0x%x, status=%d, actual_length=%d"
108 usb_ehci_irq(uint32_t level, uint32_t frindex, uint32_t sts, uint32_t mask) "level %d, frindex 0x%04x, sts 0x%x, mask 0x%x"
109 usb_ehci_guest_bug(const char *reason) "%s"
110 usb_ehci_doorbell_ring(void) ""
111 usb_ehci_doorbell_ack(void) ""
112 usb_ehci_dma_error(void) ""
113 +usb_ehci_execute_complete(uint32_t qhaddr, uint32_t next, uint32_t qtdaddr, int status, int actual_length) "qhaddr=0x%x, next=0x%x, qtdaddr=0x%x, status=%d, actual_length=%d"
114 +usb_ehci_fetchqh_reclaim_done(uint32_t qhaddr) "QH 0x%08x H-bit set, reclamation status reset - done processing"
115 +usb_ehci_fetchqh_dbg(uint32_t qhaddr, uint32_t h, uint32_t halt, uint32_t active, uint32_t next) "QH 0x%08x (h 0x%x halt 0x%x active 0x%x) next 0x%08x"
116 +usb_ehci_periodic_state_advance(uint32_t frame, uint32_t list, uint32_t entry) "frame=%d, list=0x%x, entry=0x%x"
117 +usb_ehci_skipped_uframes(uint64_t skipped_uframes) "skipped %" PRIu64 " uframes"
118 +usb_ehci_log(const char *msg) "%s"
119
120 # hcd-uhci.c
121 usb_uhci_reset(void) "=== RESET ==="