Module Name:    src
Committed By:   maxv
Date:           Sat Feb  8 08:47:27 UTC 2020

Modified Files:
        src/sys/dev/usb: usb_subr.c usbdi_util.c usbdi_util.h usbdivar.h

Log Message:
Move three functions into usbdi_util.c, where they belong. No functional
change.


To generate a diff of this commit:
cvs rdiff -u -r1.241 -r1.242 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.77 -r1.78 src/sys/dev/usb/usbdi_util.c
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/usb/usbdi_util.h
cvs rdiff -u -r1.119 -r1.120 src/sys/dev/usb/usbdivar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.241 src/sys/dev/usb/usb_subr.c:1.242
--- src/sys/dev/usb/usb_subr.c:1.241	Thu Oct  3 05:20:31 2019
+++ src/sys/dev/usb/usb_subr.c	Sat Feb  8 08:47:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.241 2019/10/03 05:20:31 maxv Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.242 2020/02/08 08:47:27 maxv Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.241 2019/10/03 05:20:31 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.242 2020/02/08 08:47:27 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -66,7 +66,6 @@ __KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v
 #define	DPRINTF(FMT,A,B,C,D)	USBHIST_LOG(usbdebug,FMT,A,B,C,D)
 #define	DPRINTFN(N,FMT,A,B,C,D)	USBHIST_LOGN(usbdebug,N,FMT,A,B,C,D)
 
-Static usbd_status usbd_set_config(struct usbd_device *, int);
 Static void usbd_devinfo(struct usbd_device *, int, char *, size_t);
 Static int usbd_getnewaddr(struct usbd_bus *);
 Static int usbd_print(void *, const char *);
@@ -113,51 +112,6 @@ usbd_errstr(usbd_status err)
 	}
 }
 
-usbd_status
-usbd_get_string_desc(struct usbd_device *dev, int sindex, int langid,
-		     usb_string_descriptor_t *sdesc, int *sizep)
-{
-	USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
-	usb_device_request_t req;
-	usbd_status err;
-	int actlen;
-
-	/*
-	 * Pass a full-sized buffer to usbd_do_request_len().  At least
-	 * one device has been seen returning additional data beyond the
-	 * provided buffers (2-bytes written shortly after the request
-	 * claims to have completed and returned the 2 byte header,
-	 * corrupting other memory.)
-	 */
-	req.bmRequestType = UT_READ_DEVICE;
-	req.bRequest = UR_GET_DESCRIPTOR;
-	USETW2(req.wValue, UDESC_STRING, sindex);
-	USETW(req.wIndex, langid);
-	USETW(req.wLength, 2);	/* only size byte first */
-	err = usbd_do_request_len(dev, &req, sizeof(*sdesc), sdesc,
-	    USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
-	if (err)
-		return err;
-
-	if (actlen < 2)
-		return USBD_SHORT_XFER;
-
-	if (sdesc->bLength > sizeof(*sdesc))
-		return USBD_INVAL;
-	USETW(req.wLength, sdesc->bLength);	/* the whole string */
-	err = usbd_do_request_len(dev, &req, sizeof(*sdesc), sdesc,
-	    USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
-	if (err)
-		return err;
-
-	if (actlen != sdesc->bLength) {
-		DPRINTF("expected %jd, got %jd", sdesc->bLength, actlen, 0, 0);
-	}
-
-	*sizep = actlen;
-	return USBD_NORMAL_COMPLETION;
-}
-
 static void
 usbd_trim_spaces(char *p)
 {
@@ -549,23 +503,6 @@ usbd_free_iface_data(struct usbd_device 
 	}
 }
 
-Static usbd_status
-usbd_set_config(struct usbd_device *dev, int conf)
-{
-	usb_device_request_t req;
-
-	USBHIST_FUNC();
-	USBHIST_CALLARGS(usbdebug, "dev %#jx conf %jd",
-	    (uintptr_t)dev, conf, 0, 0);
-
-	req.bmRequestType = UT_WRITE_DEVICE;
-	req.bRequest = UR_SET_CONFIG;
-	USETW(req.wValue, conf);
-	USETW(req.wIndex, 0);
-	USETW(req.wLength, 0);
-	return usbd_do_request(dev, &req, 0);
-}
-
 usbd_status
 usbd_set_config_no(struct usbd_device *dev, int no, int msg)
 {
@@ -1164,36 +1101,6 @@ usbd_reattach_device(device_t parent, st
 }
 
 /*
- * Get the first 8 bytes of the device descriptor.
- * Do as Windows does: try to read 64 bytes -- there are devices which
- * recognize the initial descriptor fetch (before the control endpoint's
- * MaxPacketSize is known by the host) by exactly this length.
- */
-usbd_status
-usbd_get_initial_ddesc(struct usbd_device *dev, usb_device_descriptor_t *desc)
-{
-	USBHIST_FUNC();
-	USBHIST_CALLARGS(usbdebug, "dev %#jx", (uintptr_t)dev, 0, 0, 0);
-	usb_device_request_t req;
-	char buf[64];
-	int res, actlen;
-
-	req.bmRequestType = UT_READ_DEVICE;
-	req.bRequest = UR_GET_DESCRIPTOR;
-	USETW2(req.wValue, UDESC_DEVICE, 0);
-	USETW(req.wIndex, 0);
-	USETW(req.wLength, 8);
-	res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
-		&actlen, USBD_DEFAULT_TIMEOUT);
-	if (res)
-		return res;
-	if (actlen < 8)
-		return USBD_SHORT_XFER;
-	memcpy(desc, buf, 8);
-	return USBD_NORMAL_COMPLETION;
-}
-
-/*
  * Called when a new device has been put in the powered state,
  * but not yet in the addressed state.
  * Get initial descriptor, set the address, get full descriptor,

Index: src/sys/dev/usb/usbdi_util.c
diff -u src/sys/dev/usb/usbdi_util.c:1.77 src/sys/dev/usb/usbdi_util.c:1.78
--- src/sys/dev/usb/usbdi_util.c:1.77	Sat Feb  8 08:18:06 2020
+++ src/sys/dev/usb/usbdi_util.c	Sat Feb  8 08:47:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi_util.c,v 1.77 2020/02/08 08:18:06 maxv Exp $	*/
+/*	$NetBSD: usbdi_util.c,v 1.78 2020/02/08 08:47:27 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.77 2020/02/08 08:18:06 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.78 2020/02/08 08:47:27 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -154,6 +154,81 @@ usbd_get_device_desc(struct usbd_device 
 			     0, USB_DEVICE_DESCRIPTOR_SIZE, d);
 }
 
+/*
+ * Get the first 8 bytes of the device descriptor.
+ * Do as Windows does: try to read 64 bytes -- there are devices which
+ * recognize the initial descriptor fetch (before the control endpoint's
+ * MaxPacketSize is known by the host) by exactly this length.
+ */
+usbd_status
+usbd_get_initial_ddesc(struct usbd_device *dev, usb_device_descriptor_t *desc)
+{
+	USBHIST_FUNC();
+	USBHIST_CALLARGS(usbdebug, "dev %#jx", (uintptr_t)dev, 0, 0, 0);
+	usb_device_request_t req;
+	char buf[64];
+	int res, actlen;
+
+	req.bmRequestType = UT_READ_DEVICE;
+	req.bRequest = UR_GET_DESCRIPTOR;
+	USETW2(req.wValue, UDESC_DEVICE, 0);
+	USETW(req.wIndex, 0);
+	USETW(req.wLength, 8);
+	res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
+		&actlen, USBD_DEFAULT_TIMEOUT);
+	if (res)
+		return res;
+	if (actlen < 8)
+		return USBD_SHORT_XFER;
+	memcpy(desc, buf, 8);
+	return USBD_NORMAL_COMPLETION;
+}
+
+usbd_status
+usbd_get_string_desc(struct usbd_device *dev, int sindex, int langid,
+    usb_string_descriptor_t *sdesc, int *sizep)
+{
+	USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+	usb_device_request_t req;
+	usbd_status err;
+	int actlen;
+
+	/*
+	 * Pass a full-sized buffer to usbd_do_request_len().  At least
+	 * one device has been seen returning additional data beyond the
+	 * provided buffers (2-bytes written shortly after the request
+	 * claims to have completed and returned the 2 byte header,
+	 * corrupting other memory.)
+	 */
+	req.bmRequestType = UT_READ_DEVICE;
+	req.bRequest = UR_GET_DESCRIPTOR;
+	USETW2(req.wValue, UDESC_STRING, sindex);
+	USETW(req.wIndex, langid);
+	USETW(req.wLength, 2);	/* only size byte first */
+	err = usbd_do_request_len(dev, &req, sizeof(*sdesc), sdesc,
+	    USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
+	if (err)
+		return err;
+
+	if (actlen < 2)
+		return USBD_SHORT_XFER;
+
+	if (sdesc->bLength > sizeof(*sdesc))
+		return USBD_INVAL;
+	USETW(req.wLength, sdesc->bLength);	/* the whole string */
+	err = usbd_do_request_len(dev, &req, sizeof(*sdesc), sdesc,
+	    USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
+	if (err)
+		return err;
+
+	if (actlen != sdesc->bLength) {
+		DPRINTF("expected %jd, got %jd", sdesc->bLength, actlen, 0, 0);
+	}
+
+	*sizep = actlen;
+	return USBD_NORMAL_COMPLETION;
+}
+
 /* -------------------------------------------------------------------------- */
 
 usbd_status
@@ -349,6 +424,22 @@ usbd_get_config(struct usbd_device *dev,
 }
 
 usbd_status
+usbd_set_config(struct usbd_device *dev, int conf)
+{
+	USBHIST_FUNC();
+	USBHIST_CALLARGS(usbdebug, "dev %#jx conf %jd",
+	    (uintptr_t)dev, conf, 0, 0);
+	usb_device_request_t req;
+
+	req.bmRequestType = UT_WRITE_DEVICE;
+	req.bRequest = UR_SET_CONFIG;
+	USETW(req.wValue, conf);
+	USETW(req.wIndex, 0);
+	USETW(req.wLength, 0);
+	return usbd_do_request(dev, &req, 0);
+}
+
+usbd_status
 usbd_set_address(struct usbd_device *dev, int addr)
 {
 	USBHIST_FUNC();

Index: src/sys/dev/usb/usbdi_util.h
diff -u src/sys/dev/usb/usbdi_util.h:1.51 src/sys/dev/usb/usbdi_util.h:1.52
--- src/sys/dev/usb/usbdi_util.h:1.51	Sat Feb  8 08:18:06 2020
+++ src/sys/dev/usb/usbdi_util.h	Sat Feb  8 08:47:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi_util.h,v 1.51 2020/02/08 08:18:06 maxv Exp $	*/
+/*	$NetBSD: usbdi_util.h,v 1.52 2020/02/08 08:47:27 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -45,6 +45,8 @@ usbd_status	usbd_get_bos_desc(struct usb
 usbd_status	usbd_get_bos_desc_full(struct usbd_device *, int, void *, int);
 usbd_status	usbd_get_device_desc(struct usbd_device *,
 		    usb_device_descriptor_t *);
+usbd_status	usbd_get_initial_ddesc(struct usbd_device *,
+		    usb_device_descriptor_t *);
 usbd_status	usbd_get_string_desc(struct usbd_device *, int, int,
 		    usb_string_descriptor_t *, int *);
 
@@ -66,6 +68,7 @@ usbd_status	usbd_set_port_u2_timeout(str
 usbd_status	usbd_clear_endpoint_feature(struct usbd_device *, int, int);
 
 usbd_status	usbd_get_config(struct usbd_device *, uint8_t *);
+usbd_status	usbd_set_config(struct usbd_device *, int);
 usbd_status	usbd_set_address(struct usbd_device *, int);
 usbd_status	usbd_set_idle(struct usbd_interface *, int, int);
 

Index: src/sys/dev/usb/usbdivar.h
diff -u src/sys/dev/usb/usbdivar.h:1.119 src/sys/dev/usb/usbdivar.h:1.120
--- src/sys/dev/usb/usbdivar.h:1.119	Thu Sep 26 01:35:08 2019
+++ src/sys/dev/usb/usbdivar.h	Sat Feb  8 08:47:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdivar.h,v 1.119 2019/09/26 01:35:08 christos Exp $	*/
+/*	$NetBSD: usbdivar.h,v 1.120 2020/02/08 08:47:27 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -334,8 +334,6 @@ int		usb_disconnect_port(struct usbd_por
 void		usbd_kill_pipe(struct usbd_pipe *);
 usbd_status	usbd_attach_roothub(device_t, struct usbd_device *);
 usbd_status	usbd_probe_and_attach(device_t, struct usbd_device *, int, int);
-usbd_status	usbd_get_initial_ddesc(struct usbd_device *,
-				       usb_device_descriptor_t *);
 
 /* Routines from usb.c */
 void		usb_needs_explore(struct usbd_device *);

Reply via email to