PERFORCE change 126736 for review

Hans Petter Selasky hselasky at FreeBSD.org
Sun Sep 23 07:59:53 PDT 2007


http://perforce.freebsd.org/chv.cgi?CH=126736

Change 126736 by hselasky at hselasky_laptop001 on 2007/09/23 14:59:13

	
	FYI; The comments follow the P4 diff from top to bottom.
	
	- remove redundant inclusion of "sys/vnode.h"
	
	- after the change to always USB DMA buffers the "ums" driver
	  needs a temporary buffer for scratching and decoding
	  information, hence the HID library does not understand DMA
	  buffers yet. See "sc_temp[]".
	
	- some space to tab conversion sneaked in two places, sorry.
	
	- actlen of USB control transfers is now 16-bit unsigned.
	
	- print a warning if the USB interrupt data is larger than
	  "max_frame_size".
	
	- the "USB_CDEV_FLAG_FWD_SHORT" flag is redundant and has been
	  removed.
	
	- UMS uses "usb_cdev_put_data_linear()" hence it does not
	  understand DMA buffers ...

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb/ums.c#21 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb/ums.c#21 (text+ko) ====

@@ -50,7 +50,6 @@
 #include <sys/filio.h>
 #include <sys/tty.h>
 #include <sys/file.h>
-#include <sys/vnode.h>
 #include <sys/poll.h>
 #include <sys/mouse.h>
 
@@ -109,6 +108,7 @@
 
   u_int8_t	      sc_buttons;
   u_int8_t	      sc_iid;
+  uint8_t	      sc_temp[64];
 };
 
 static void
@@ -170,7 +170,7 @@
 {
 	struct ums_softc *sc = xfer->priv_sc;
 	struct usbd_mbuf *m;
-	u_int8_t *buf = xfer->buffer;
+	uint8_t *buf = sc->sc_temp;
 	u_int16_t len = xfer->actlen;
 	int32_t buttons = 0;
 	int32_t dx;
@@ -183,6 +183,19 @@
 
  tr_transferred:
 	DPRINTF(5, "sc=%p actlen=%d\n", sc, len);
+
+	if (len > sizeof(sc->sc_temp)) {
+	    DPRINTF(5, "truncating large packet to %d bytes\n",
+		    sizeof(sc->sc_temp));
+	    len = sizeof(sc->sc_temp);
+	}
+
+	if (len == 0) {
+	    goto tr_setup;
+	}
+
+	usbd_copy_out(xfer->frbuffers + 0, 0, buf, len);
+
 	DPRINTF(5, "data = %02x %02x %02x %02x "
 		"%02x %02x %02x %02x\n",
 		(len > 0) ? buf[0] : 0, (len > 1) ? buf[1] : 0,
@@ -190,10 +203,6 @@
 		(len > 4) ? buf[4] : 0, (len > 5) ? buf[5] : 0, 
 		(len > 6) ? buf[6] : 0, (len > 7) ? buf[7] : 0);
 
-	if (len == 0) {
-	    goto tr_setup;
-	}
-
 	/*
 	 * The M$ Wireless Intellimouse 2.0 sends 1 extra leading byte
 	 * of data compared to most USB mice. This byte frequently
@@ -276,11 +285,11 @@
 		(dx == 0) && (dy == 0) && (dz == 0) && (dt == 0) && 
 		(buttons == 0)) {
 
-	        __callout_reset(&(sc->sc_callout), hz / 20, 
+		__callout_reset(&(sc->sc_callout), hz / 20, 
 				&ums_put_queue_timeout, sc);
 	    } else {
 
-	        __callout_stop(&(sc->sc_callout));
+		__callout_stop(&(sc->sc_callout));
 
 		ums_put_queue(sc, dx, dy, dz, dt, buttons);
 	    }
@@ -293,7 +302,8 @@
 	    USBD_IF_POLL(&(sc->sc_cdev.sc_rdq_free), m);
 
 	    if (m) {
-	        usbd_start_hardware(xfer);
+		xfer->frlengths[0] = xfer->max_data_length;
+		usbd_start_hardware(xfer);
 	    }
 	}
 	return;
@@ -313,7 +323,7 @@
       .type      = UE_INTERRUPT,
       .endpoint  = UE_ADDR_ANY,
       .direction = UE_DIR_IN,
-      .flags     = (USBD_PIPE_BOF|USBD_SHORT_XFER_OK),
+      .flags     = { .pipe_bof = 1, .short_xfer_ok = 1, },
       .bufsize   = 0, /* use wMaxPacketSize */
       .callback  = &ums_intr_callback,
     },
@@ -335,8 +345,8 @@
 	struct usb_attach_arg *uaa = device_get_ivars(dev);
 	usb_interface_descriptor_t *id;
 	void *d_ptr;
-	int32_t d_len;
 	int32_t error = 0;
+	uint16_t d_len;
 
 	DPRINTF(10, "\n");
 
@@ -353,8 +363,10 @@
 	    return UMATCH_NONE;
 	}
 
-	error = usbreq_read_report_desc(uaa->device, uaa->iface_index, 
-					&d_ptr, &d_len, M_TEMP);
+	error = hid_read_report_desc_from_usb
+	  (uaa->device, &usb_global_lock,
+	   &d_ptr, &d_len, M_TEMP, uaa->iface_index);
+
 	if (error) {
 	    return UMATCH_NONE;
 	}
@@ -372,10 +384,10 @@
 	void *d_ptr = NULL;
 	const char * p_buf[2];
 	int32_t unit = device_get_unit(dev);
-	int32_t d_len;
 	int32_t isize;
 	u_int32_t flags;
 	int32_t err;
+	uint16_t d_len;
 	u_int8_t i;
 	char buf_1[16];
 
@@ -396,8 +408,10 @@
 	    goto detach;
 	}
 
-	err = usbreq_read_report_desc(uaa->device, uaa->iface_index, 
-				      &d_ptr, &d_len, M_TEMP);
+	err = hid_read_report_desc_from_usb
+	  (uaa->device, &usb_global_lock, &d_ptr, 
+	   &d_len, M_TEMP, uaa->iface_index);
+
 	if (err) {
 	    device_printf(dev, "error reading report description\n");
 	    goto detach;
@@ -486,10 +500,10 @@
 		sc->sc_loc_btn[2].pos = 10;
 	}
 
-	if (isize > sc->sc_xfer[0]->length) {
+	if (isize > sc->sc_xfer[0]->max_frame_size) {
 	    DPRINTF(0, "WARNING: report size, %d bytes, is larger "
 		    "than interrupt size, %d bytes!\n",
-		    isize, sc->sc_xfer[0]->length);
+		    isize, sc->sc_xfer[0]->max_frame_size);
 	}
 
 	/* announce information about the mouse */
@@ -553,8 +567,7 @@
 	sc->sc_cdev.sc_stop_read = &ums_stop_read;
 	sc->sc_cdev.sc_open = &ums_open;
 	sc->sc_cdev.sc_ioctl = &ums_ioctl;
-	sc->sc_cdev.sc_flags |= (USB_CDEV_FLAG_FWD_SHORT|
-				 USB_CDEV_FLAG_WAKEUP_RD_IMMED|
+	sc->sc_cdev.sc_flags |= (USB_CDEV_FLAG_WAKEUP_RD_IMMED|
 				 USB_CDEV_FLAG_WAKEUP_WR_IMMED);
 
 	err = usb_cdev_attach(&(sc->sc_cdev), sc, &(sc->sc_mtx), p_buf,
@@ -647,7 +660,7 @@
 		buf[7] = (((~buttons) >> 3) & MOUSE_SYS_EXTBUTTONS);
 	    }
 
-	    usb_cdev_put_data(&(sc->sc_cdev), buf, 
+	    usb_cdev_put_data_linear(&(sc->sc_cdev), buf, 
 			      sc->sc_mode.packetsize, 1);
 
 	} else {


More information about the p4-projects mailing list