Author: hselasky
Date: Mon Jan  6 09:22:33 2020
New Revision: 356399
URL: https://svnweb.freebsd.org/changeset/base/356399

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/10/lib/libusb/Makefile
  stable/10/lib/libusb/libusb20.3
  stable/10/lib/libusb/libusb20.c
  stable/10/lib/libusb/libusb20.h
  stable/10/lib/libusb/libusb20_int.h
  stable/10/lib/libusb/libusb20_ugen20.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libusb/Makefile
==============================================================================
--- stable/10/lib/libusb/Makefile       Mon Jan  6 09:21:15 2020        
(r356398)
+++ stable/10/lib/libusb/Makefile       Mon Jan  6 09:22:33 2020        
(r356399)
@@ -222,6 +222,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/10/lib/libusb/libusb20.3
==============================================================================
--- stable/10/lib/libusb/libusb20.3     Mon Jan  6 09:21:15 2020        
(r356398)
+++ stable/10/lib/libusb/libusb20.3     Mon Jan  6 09:22:33 2020        
(r356399)
@@ -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<unit>: <description>"
+.
+.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/10/lib/libusb/libusb20.c
==============================================================================
--- stable/10/lib/libusb/libusb20.c     Mon Jan  6 09:21:15 2020        
(r356398)
+++ stable/10/lib/libusb/libusb20.c     Mon Jan  6 09:22:33 2020        
(r356399)
@@ -77,6 +77,7 @@ dummy_callback(struct libusb20_transfer *xfer)
 #define        dummy_get_power_mode (void *)dummy_int
 #define        dummy_get_port_path (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
@@ -1027,6 +1028,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/10/lib/libusb/libusb20.h
==============================================================================
--- stable/10/lib/libusb/libusb20.h     Mon Jan  6 09:21:15 2020        
(r356398)
+++ stable/10/lib/libusb/libusb20.h     Mon Jan  6 09:22:33 2020        
(r356399)
@@ -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/10/lib/libusb/libusb20_int.h
==============================================================================
--- stable/10/lib/libusb/libusb20_int.h Mon Jan  6 09:21:15 2020        
(r356398)
+++ stable/10/lib/libusb/libusb20_int.h Mon Jan  6 09:22:33 2020        
(r356399)
@@ -107,10 +107,12 @@ typedef int (libusb20_set_power_mode_t)(struct libusb2
 typedef int (libusb20_get_power_mode_t)(struct libusb20_device *pdev, uint8_t 
*power_mode);
 typedef int (libusb20_get_port_path_t)(struct libusb20_device *pdev, uint8_t 
*buf, uint8_t bufsize);
 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);
@@ -131,6 +133,7 @@ typedef void (libusb20_tr_cancel_async_t)(struct libus
   m(n, get_power_mode) \
   m(n, get_port_path) \
   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/10/lib/libusb/libusb20_ugen20.c
==============================================================================
--- stable/10/lib/libusb/libusb20_ugen20.c      Mon Jan  6 09:21:15 2020        
(r356398)
+++ stable/10/lib/libusb/libusb20_ugen20.c      Mon Jan  6 09:22:33 2020        
(r356399)
@@ -79,6 +79,7 @@ static libusb20_set_power_mode_t ugen20_set_power_mode
 static libusb20_get_power_mode_t ugen20_get_power_mode;
 static libusb20_get_port_path_t ugen20_get_port_path;
 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;
@@ -673,6 +674,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 */
 }
 
_______________________________________________
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"

Reply via email to