From 23b6e1b12d8e48174a79a1756dbf7b9b5bab13b9 Mon Sep 17 00:00:00 2001 From: hselasky Date: Mon, 6 Jan 2020 09:40:59 +0000 Subject: [PATCH] MFC r356137: Implement dump_stats command for usbconfig(8). This command is useful when debugging USB device issues. Sponsored by: Mellanox Technologies git-svn-id: svn://svn.freebsd.org/base/stable/10@356408 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.sbin/usbconfig/dump.c | 29 +++++++++++++++++++++++++++++ usr.sbin/usbconfig/dump.h | 1 + usr.sbin/usbconfig/usbconfig.8 | 6 ++++-- usr.sbin/usbconfig/usbconfig.c | 17 ++++++++++++++++- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/usr.sbin/usbconfig/dump.c b/usr.sbin/usbconfig/dump.c index df5cde0c5..7e8a10b7a 100644 --- a/usr.sbin/usbconfig/dump.c +++ b/usr.sbin/usbconfig/dump.c @@ -481,3 +481,32 @@ dump_string_by_index(struct libusb20_device *pdev, uint8_t str_index) } free(pbuf); } + +void +dump_device_stats(struct libusb20_device *pdev) +{ + struct libusb20_device_stats st; + + if (libusb20_dev_get_stats(pdev, &st)) { + printf("{}\n"); + } else { + printf("{\n" + " UE_CONTROL_OK : %llu\n" + " UE_ISOCHRONOUS_OK : %llu\n" + " UE_BULK_OK : %llu\n" + " UE_INTERRUPT_OK : %llu\n" + " UE_CONTROL_FAIL : %llu\n" + " UE_ISOCHRONOUS_FAIL : %llu\n" + " UE_BULK_FAIL : %llu\n" + " UE_INTERRUPT_FAIL : %llu\n" + "}\n", + (unsigned long long)st.xfer_ok[0], + (unsigned long long)st.xfer_ok[1], + (unsigned long long)st.xfer_ok[2], + (unsigned long long)st.xfer_ok[3], + (unsigned long long)st.xfer_fail[0], + (unsigned long long)st.xfer_fail[1], + (unsigned long long)st.xfer_fail[2], + (unsigned long long)st.xfer_fail[3]); + } +} diff --git a/usr.sbin/usbconfig/dump.h b/usr.sbin/usbconfig/dump.h index 581684a4c..1949d0d86 100644 --- a/usr.sbin/usbconfig/dump.h +++ b/usr.sbin/usbconfig/dump.h @@ -35,6 +35,7 @@ void dump_device_info(struct libusb20_device *pdev, uint8_t show_drv); void dump_be_quirk_names(struct libusb20_backend *pbe); void dump_be_dev_quirks(struct libusb20_backend *pbe); void dump_device_desc(struct libusb20_device *pdev); +void dump_device_stats(struct libusb20_device *pdev); void dump_config(struct libusb20_device *pdev, uint8_t all_cfg); #endif /* _DUMP_H_ */ diff --git a/usr.sbin/usbconfig/usbconfig.8 b/usr.sbin/usbconfig/usbconfig.8 index 60b337a09..79f070b16 100644 --- a/usr.sbin/usbconfig/usbconfig.8 +++ b/usr.sbin/usbconfig/usbconfig.8 @@ -1,6 +1,6 @@ .\" $FreeBSD$ .\" -.\" Copyright (c) 2008-2010 Hans Petter Selasky. All rights reserved. +.\" Copyright (c) 2008-2019 Hans Petter Selasky. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd August 16, 2019 +.Dd December 27, 2019 .Dt USBCONFIG 8 .Os .Sh NAME @@ -116,6 +116,8 @@ Display all the configuration descriptors. Display string descriptor at selected index. .It Cm dump_info Display summary information about the device. +.It Cm dump_stats +Display USB transfer statistics. .It Cm show_ifdrv Display the list of interface drivers (such as .Xr ukbd 4 diff --git a/usr.sbin/usbconfig/usbconfig.c b/usr.sbin/usbconfig/usbconfig.c index 3a1f6d62d..c8a108e83 100644 --- a/usr.sbin/usbconfig/usbconfig.c +++ b/usr.sbin/usbconfig/usbconfig.c @@ -80,6 +80,7 @@ struct options { uint8_t got_dump_curr_config:1; uint8_t got_dump_all_config:1; uint8_t got_dump_info:1; + uint8_t got_dump_stats:1; uint8_t got_show_iface_driver:1; uint8_t got_remove_device_quirk:1; uint8_t got_add_device_quirk:1; @@ -119,6 +120,7 @@ enum { T_DUMP_ALL_CONFIG_DESC, T_DUMP_STRING, T_DUMP_INFO, + T_DUMP_STATS, T_SUSPEND, T_RESUME, T_POWER_OFF, @@ -153,6 +155,7 @@ static const struct token token[] = { {"dump_all_config_desc", T_DUMP_ALL_CONFIG_DESC, 0}, {"dump_string", T_DUMP_STRING, 1}, {"dump_info", T_DUMP_INFO, 0}, + {"dump_stats", T_DUMP_STATS, 0}, {"show_ifdrv", T_SHOW_IFACE_DRIVER, 0}, {"suspend", T_SUSPEND, 0}, {"resume", T_RESUME, 0}, @@ -294,6 +297,7 @@ usage(void) " dump_all_config_desc" "\n" " dump_string " "\n" " dump_info" "\n" + " dump_stats" "\n" " show_ifdrv" "\n" " suspend" "\n" " resume" "\n" @@ -504,7 +508,8 @@ flush_command(struct libusb20_backend *pbe, struct options *opt) opt->got_dump_device_desc || opt->got_dump_curr_config || opt->got_dump_all_config || - opt->got_dump_info); + opt->got_dump_info || + opt->got_dump_stats); if (opt->got_list || dump_any) { dump_device_info(pdev, @@ -525,6 +530,10 @@ flush_command(struct libusb20_backend *pbe, struct options *opt) dump_device_desc(pdev); dump_config(pdev, 1); } + if (opt->got_dump_stats) { + printf("\n"); + dump_device_stats(pdev); + } if (dump_any) { printf("\n"); } @@ -749,6 +758,12 @@ main(int argc, char **argv) opt->got_dump_info = 1; opt->got_any++; break; + case T_DUMP_STATS: + if (opt->got_dump_stats) + duplicate_option(argv[n]); + opt->got_dump_stats = 1; + opt->got_any++; + break; case T_DUMP_STRING: if (opt->got_dump_string) duplicate_option(argv[n]); -- 2.42.0