hw/usb/canokey: Add trace events

Signed-off-by: Hongren (Zenithal) Zheng <i@zenithal.me>
Message-Id: <YoY6RoDKQIxSkFwL@Sun>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Hongren (Zenithal) Zheng 2022-05-19 20:38:30 +08:00 committed by Gerd Hoffmann
parent d7d3491855
commit d37d0e0e85
2 changed files with 29 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include "qapi/error.h"
#include "hw/usb.h"
#include "hw/qdev-properties.h"
#include "trace.h"
#include "desc.h"
#include "canokey.h"
@ -66,6 +67,7 @@ static const USBDesc desc_canokey = {
*/
int canokey_emu_stall_ep(void *base, uint8_t ep)
{
trace_canokey_emu_stall_ep(ep);
CanoKeyState *key = base;
uint8_t ep_in = CANOKEY_EP_IN(ep); /* INTR IN has ep 129 */
key->ep_in_size[ep_in] = 0;
@ -75,6 +77,7 @@ int canokey_emu_stall_ep(void *base, uint8_t ep)
int canokey_emu_set_address(void *base, uint8_t addr)
{
trace_canokey_emu_set_address(addr);
CanoKeyState *key = base;
key->dev.addr = addr;
return 0;
@ -83,6 +86,7 @@ int canokey_emu_set_address(void *base, uint8_t addr)
int canokey_emu_prepare_receive(
void *base, uint8_t ep, uint8_t *pbuf, uint16_t size)
{
trace_canokey_emu_prepare_receive(ep, size);
CanoKeyState *key = base;
key->ep_out[ep] = pbuf;
key->ep_out_size[ep] = size;
@ -92,6 +96,7 @@ int canokey_emu_prepare_receive(
int canokey_emu_transmit(
void *base, uint8_t ep, const uint8_t *pbuf, uint16_t size)
{
trace_canokey_emu_transmit(ep, size);
CanoKeyState *key = base;
uint8_t ep_in = CANOKEY_EP_IN(ep); /* INTR IN has ep 129 */
memcpy(key->ep_in[ep_in] + key->ep_in_size[ep_in],
@ -125,6 +130,7 @@ uint32_t canokey_emu_get_rx_data_size(void *base, uint8_t ep)
*/
static void canokey_handle_reset(USBDevice *dev)
{
trace_canokey_handle_reset();
CanoKeyState *key = CANOKEY(dev);
for (int i = 0; i != CANOKEY_EP_NUM; ++i) {
key->ep_in_state[i] = CANOKEY_EP_IN_WAIT;
@ -137,6 +143,7 @@ static void canokey_handle_reset(USBDevice *dev)
static void canokey_handle_control(USBDevice *dev, USBPacket *p,
int request, int value, int index, int length, uint8_t *data)
{
trace_canokey_handle_control_setup(request, value, index, length);
CanoKeyState *key = CANOKEY(dev);
canokey_emu_setup(request, value, index, length);
@ -144,6 +151,7 @@ static void canokey_handle_control(USBDevice *dev, USBPacket *p,
uint32_t dir_in = request & DeviceRequest;
if (!dir_in) {
/* OUT */
trace_canokey_handle_control_out();
if (key->ep_out[0] != NULL) {
memcpy(key->ep_out[0], data, length);
}
@ -163,6 +171,7 @@ static void canokey_handle_control(USBDevice *dev, USBPacket *p,
case CANOKEY_EP_IN_READY:
memcpy(data, key->ep_in[0], key->ep_in_size[0]);
p->actual_length = key->ep_in_size[0];
trace_canokey_handle_control_in(p->actual_length);
/* reset state */
key->ep_in_state[0] = CANOKEY_EP_IN_WAIT;
key->ep_in_size[0] = 0;
@ -182,6 +191,7 @@ static void canokey_handle_data(USBDevice *dev, USBPacket *p)
uint32_t out_len;
switch (p->pid) {
case USB_TOKEN_OUT:
trace_canokey_handle_data_out(ep_out, p->iov.size);
usb_packet_copy(p, key->ep_out_buffer[ep_out], p->iov.size);
out_pos = 0;
while (out_pos != p->iov.size) {
@ -226,6 +236,7 @@ static void canokey_handle_data(USBDevice *dev, USBPacket *p)
key->ep_in_size[ep_in] = 0;
key->ep_in_pos[ep_in] = 0;
}
trace_canokey_handle_data_in(ep_in, in_len);
break;
}
break;
@ -237,6 +248,7 @@ static void canokey_handle_data(USBDevice *dev, USBPacket *p)
static void canokey_realize(USBDevice *base, Error **errp)
{
trace_canokey_realize();
CanoKeyState *key = CANOKEY(base);
if (key->file == NULL) {
@ -260,6 +272,7 @@ static void canokey_realize(USBDevice *base, Error **errp)
static void canokey_unrealize(USBDevice *base)
{
trace_canokey_unrealize();
}
static Property canokey_properties[] = {

View File

@ -345,3 +345,19 @@ usb_serial_set_baud(int bus, int addr, int baud) "dev %d:%u baud rate %d"
usb_serial_set_data(int bus, int addr, int parity, int data, int stop) "dev %d:%u parity %c, data bits %d, stop bits %d"
usb_serial_set_flow_control(int bus, int addr, int index) "dev %d:%u flow control %d"
usb_serial_set_xonxoff(int bus, int addr, uint8_t xon, uint8_t xoff) "dev %d:%u xon 0x%x xoff 0x%x"
# canokey.c
canokey_emu_stall_ep(uint8_t ep) "ep %d"
canokey_emu_set_address(uint8_t addr) "addr %d"
canokey_emu_prepare_receive(uint8_t ep, uint16_t size) "ep %d size %d"
canokey_emu_transmit(uint8_t ep, uint16_t size) "ep %d size %d"
canokey_thread_start(void)
canokey_thread_stop(void)
canokey_handle_reset(void)
canokey_handle_control_setup(int request, int value, int index, int length) "request 0x%04X value 0x%04X index 0x%04X length 0x%04X"
canokey_handle_control_out(void)
canokey_handle_control_in(int actual_len) "len %d"
canokey_handle_data_out(uint8_t ep_out, uint32_t out_len) "ep %d len %d"
canokey_handle_data_in(uint8_t ep_in, uint32_t in_len) "ep %d len %d"
canokey_realize(void)
canokey_unrealize(void)