From owner-svn-src-all@freebsd.org Mon Jan 6 09:21:17 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8B6A41FE3A9; Mon, 6 Jan 2020 09:21:17 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47rqkj3BjXz4RTx; Mon, 6 Jan 2020 09:21:17 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 68E03C398; Mon, 6 Jan 2020 09:21:17 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0069LHp3003162; Mon, 6 Jan 2020 09:21:17 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0069LGOj003154; Mon, 6 Jan 2020 09:21:16 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <202001060921.0069LGOj003154@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 6 Jan 2020 09:21:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r356398 - stable/11/lib/libusb X-SVN-Group: stable-11 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: stable/11/lib/libusb X-SVN-Commit-Revision: 356398 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Jan 2020 09:21:17 -0000 Author: hselasky Date: Mon Jan 6 09:21:15 2020 New Revision: 356398 URL: https://svnweb.freebsd.org/changeset/base/356398 Log: MFC r356136: Implement new libusb v2.0 API function, libusb20_dev_get_stats(). This function is useful when debugging USB device issues. Sponsored by: Mellanox Technologies Modified: stable/11/lib/libusb/Makefile stable/11/lib/libusb/libusb20.3 stable/11/lib/libusb/libusb20.c stable/11/lib/libusb/libusb20.h stable/11/lib/libusb/libusb20_int.h stable/11/lib/libusb/libusb20_ugen20.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libusb/Makefile ============================================================================== --- stable/11/lib/libusb/Makefile Mon Jan 6 09:20:04 2020 (r356397) +++ stable/11/lib/libusb/Makefile Mon Jan 6 09:21:15 2020 (r356398) @@ -220,6 +220,7 @@ MLINKS += libusb20.3 libusb20_dev_get_backend_name.3 MLINKS += libusb20.3 libusb20_dev_get_info.3 MLINKS += libusb20.3 libusb20_dev_get_iface_desc.3 MLINKS += libusb20.3 libusb20_dev_get_desc.3 +MLINKS += libusb20.3 libusb20_dev_get_stats.3 MLINKS += libusb20.3 libusb20_dev_close.3 MLINKS += libusb20.3 libusb20_dev_detach_kernel_driver.3 MLINKS += libusb20.3 libusb20_dev_set_config_index.3 Modified: stable/11/lib/libusb/libusb20.3 ============================================================================== --- stable/11/lib/libusb/libusb20.3 Mon Jan 6 09:20:04 2020 (r356397) +++ stable/11/lib/libusb/libusb20.3 Mon Jan 6 09:21:15 2020 (r356398) @@ -1,5 +1,5 @@ .\" -.\" Copyright (c) 2008 Hans Petter Selasky +.\" Copyright (c) 2008-2019 Hans Petter Selasky .\" .\" All rights reserved. .\" @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 3, 2013 +.Dd December 27, 2019 .Dt LIBUSB20 3 .Os .Sh NAME @@ -122,6 +122,8 @@ USB access library (libusb -lusb) .Ft const char * .Fn libusb20_dev_get_desc "struct libusb20_device *pdev" .Ft int +.Fn libusb20_dev_get_stats "struct libusb20_device *pdev" "struct libusb20_device_stats *pstats" +.Ft int .Fn libusb20_dev_close "struct libusb20_device *pdev" .Ft int .Fn libusb20_dev_detach_kernel_driver "struct libusb20_device *pdev" "uint8_t iface_index" @@ -594,6 +596,14 @@ This function returns zero on success else a LIBUSB20_ .Fn libusb20_dev_get_desc returns a zero terminated string describing the given USB device. The format of the string is: "drivername: " +. +.Pp +. +.Fn libusb20_dev_get_stats +retrieves the device statistics into the structure pointed to by the +.Fa pstats +argument. +This function returns zero on success else a LIBUSB20_ERROR value is returned. . .Pp . Modified: stable/11/lib/libusb/libusb20.c ============================================================================== --- stable/11/lib/libusb/libusb20.c Mon Jan 6 09:20:04 2020 (r356397) +++ stable/11/lib/libusb/libusb20.c Mon Jan 6 09:21:15 2020 (r356398) @@ -76,6 +76,7 @@ dummy_callback(struct libusb20_transfer *xfer) #define dummy_set_power_mode (void *)dummy_int #define dummy_get_power_mode (void *)dummy_int #define dummy_get_power_usage (void *)dummy_int +#define dummy_get_stats (void *)dummy_int #define dummy_kernel_driver_active (void *)dummy_int #define dummy_detach_kernel_driver (void *)dummy_int #define dummy_do_request_sync (void *)dummy_int @@ -1045,6 +1046,31 @@ uint8_t libusb20_dev_get_speed(struct libusb20_device *pdev) { return (pdev->usb_speed); +} + +int +libusb20_dev_get_stats(struct libusb20_device *pdev, struct libusb20_device_stats *pstats) +{ + uint8_t do_close; + int error; + + if (!pdev->is_opened) { + error = libusb20_dev_open(pdev, 0); + if (error == 0) { + do_close = 1; + } else { + do_close = 0; + } + } else { + do_close = 0; + } + + error = pdev->methods->get_stats(pdev, pstats); + + if (do_close) + (void) libusb20_dev_close(pdev); + + return (error); } /* if this function returns an error, the device is gone */ Modified: stable/11/lib/libusb/libusb20.h ============================================================================== --- stable/11/lib/libusb/libusb20.h Mon Jan 6 09:20:04 2020 (r356397) +++ stable/11/lib/libusb/libusb20.h Mon Jan 6 09:21:15 2020 (r356398) @@ -193,6 +193,12 @@ struct libusb20_quirk { char quirkname[64 - 12]; }; +struct libusb20_device_stats { + uint64_t xfer_ok[4]; /* sorted by USB transfer type, UE_XXX */ + uint64_t xfer_fail[4]; /* sorted by USB transfer type, UE_XXX */ + uint64_t xfer_reserved[24]; /* reserved */ +}; + #define LIBUSB20_MAX_FRAME_PRE_SCALE (1U << 31) /* USB transfer operations */ @@ -241,6 +247,7 @@ int libusb20_dev_detach_kernel_driver(struct libusb20_ int libusb20_dev_set_config_index(struct libusb20_device *pdev, uint8_t configIndex); int libusb20_dev_get_debug(struct libusb20_device *pdev); int libusb20_dev_get_fd(struct libusb20_device *pdev); +int libusb20_dev_get_stats(struct libusb20_device *pdev, struct libusb20_device_stats *pstat); int libusb20_dev_kernel_driver_active(struct libusb20_device *pdev, uint8_t iface_index); int libusb20_dev_open(struct libusb20_device *pdev, uint16_t transfer_max); int libusb20_dev_process(struct libusb20_device *pdev); Modified: stable/11/lib/libusb/libusb20_int.h ============================================================================== --- stable/11/lib/libusb/libusb20_int.h Mon Jan 6 09:20:04 2020 (r356397) +++ stable/11/lib/libusb/libusb20_int.h Mon Jan 6 09:21:15 2020 (r356398) @@ -106,10 +106,12 @@ typedef int (libusb20_reset_device_t)(struct libusb20_ typedef int (libusb20_set_power_mode_t)(struct libusb20_device *pdev, uint8_t power_mode); typedef int (libusb20_get_power_mode_t)(struct libusb20_device *pdev, uint8_t *power_mode); typedef int (libusb20_get_power_usage_t)(struct libusb20_device *pdev, uint16_t *power_usage); +typedef int (libusb20_get_stats_t)(struct libusb20_device *pdev, struct libusb20_device_stats *pstats); typedef int (libusb20_set_alt_index_t)(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index); typedef int (libusb20_set_config_index_t)(struct libusb20_device *pdev, uint8_t index); typedef int (libusb20_check_connected_t)(struct libusb20_device *pdev); + /* USB transfer specific */ typedef int (libusb20_tr_open_t)(struct libusb20_transfer *xfer, uint32_t MaxBufSize, uint32_t MaxFrameCount, uint8_t ep_no, uint16_t stream_id, uint8_t pre_scale); typedef int (libusb20_tr_close_t)(struct libusb20_transfer *xfer); @@ -129,6 +131,7 @@ typedef void (libusb20_tr_cancel_async_t)(struct libus m(n, set_power_mode) \ m(n, get_power_mode) \ m(n, get_power_usage) \ + m(n, get_stats) \ m(n, set_alt_index) \ m(n, set_config_index) \ m(n, tr_cancel_async) \ Modified: stable/11/lib/libusb/libusb20_ugen20.c ============================================================================== --- stable/11/lib/libusb/libusb20_ugen20.c Mon Jan 6 09:20:04 2020 (r356397) +++ stable/11/lib/libusb/libusb20_ugen20.c Mon Jan 6 09:21:15 2020 (r356398) @@ -78,6 +78,7 @@ static libusb20_check_connected_t ugen20_check_connect static libusb20_set_power_mode_t ugen20_set_power_mode; static libusb20_get_power_mode_t ugen20_get_power_mode; static libusb20_get_power_usage_t ugen20_get_power_usage; +static libusb20_get_stats_t ugen20_get_stats; static libusb20_kernel_driver_active_t ugen20_kernel_driver_active; static libusb20_detach_kernel_driver_t ugen20_detach_kernel_driver; static libusb20_do_request_sync_t ugen20_do_request_sync; @@ -664,6 +665,29 @@ ugen20_get_power_usage(struct libusb20_device *pdev, u return (LIBUSB20_ERROR_OTHER); } *power_usage = temp; + return (0); /* success */ +} + +static int +ugen20_get_stats(struct libusb20_device *pdev, struct libusb20_device_stats *pstats) +{ + struct usb_device_stats st; + + if (ioctl(pdev->file_ctrl, IOUSB(USB_DEVICESTATS), &st)) + return (LIBUSB20_ERROR_OTHER); + + memset(pstats, 0, sizeof(*pstats)); + + pstats->xfer_ok[0] = st.uds_requests_ok[0]; + pstats->xfer_ok[1] = st.uds_requests_ok[1]; + pstats->xfer_ok[2] = st.uds_requests_ok[2]; + pstats->xfer_ok[3] = st.uds_requests_ok[3]; + + pstats->xfer_fail[0] = st.uds_requests_fail[0]; + pstats->xfer_fail[1] = st.uds_requests_fail[1]; + pstats->xfer_fail[2] = st.uds_requests_fail[2]; + pstats->xfer_fail[3] = st.uds_requests_fail[3]; + return (0); /* success */ }