patch-2.3.38 linux/drivers/usb/usb.c

Next file: linux/drivers/usb/usb.h
Previous file: linux/drivers/usb/usb-serial.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.37/linux/drivers/usb/usb.c linux/drivers/usb/usb.c
@@ -18,8 +18,6 @@
  * $Id: usb.c,v 1.39 1999/12/27 15:17:47 acher Exp $
  */
 
-#define USB_DEBUG	1
-
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/string.h>
@@ -27,15 +25,9 @@
 #include <linux/malloc.h>
 #include <linux/interrupt.h>  /* for in_interrupt() */
 
-#include "usb.h"
-
-#define MODSTR "usbcore: "
+#define DEBUG
 
-#ifdef USB_DEBUG
-	#define dbg(format, arg...) printk(format, ## arg)
-#else
-	#define dbg(format, arg...)
-#endif
+#include "usb.h"
 
 /*
  * Prototypes for the device driver probing/loading functions
@@ -60,14 +52,13 @@
 
 	if (new_driver->fops != NULL) {
 		if (usb_minors[new_driver->minor/16]) {
-			 printk(KERN_ERR "Error registering %s driver\n",
-				new_driver->name);
+			 err("error registering %s driver", new_driver->name);
 			return -EINVAL;
 		}
 		usb_minors[new_driver->minor/16] = new_driver;
 	}
 
-	printk("usbcore: Registered new driver %s\n", new_driver->name);
+	info("registered new driver %s", new_driver->name);
 	/* Add it to the list of known drivers */
 	list_add(&new_driver->driver_list, &usb_driver_list);
 
@@ -97,7 +88,7 @@
 	int i;
 
 	if (!dev) {
-		printk(KERN_ERR "usbcore: null device being purged!!!\n");
+		err("null device being purged!!!");
 		return;
 	}
 
@@ -130,7 +121,7 @@
 {
 	struct list_head *tmp;
 
-	printk("usbcore: Deregistering driver %s\n", driver->name);
+	info("deregistering driver %s", driver->name);
 	if (driver->fops != NULL)
 		usb_minors[driver->minor/16] = NULL;
 
@@ -218,7 +209,7 @@
 	new_alloc = old_alloc + bustime;
 		/* what new total allocated bus time would be */
 
-	PRINTD ("usb-bandwidth-alloc: was: %u, new: %u, "
+	dbg("usb-bandwidth-alloc: was: %u, new: %u, "
 		"bustime = %ld us, Pipe allowed: %s",
 		old_alloc, new_alloc, bustime,
 		(new_alloc <= FRAME_TIME_MAX_USECS_ALLOC) ?
@@ -270,19 +261,19 @@
 		set_bit(busnum, busmap.busmap);
 		bus->busnum = busnum;
 	} else
-		printk(KERN_INFO "usb: too many buses\n");
+		warn("too many buses");
 
 	proc_usb_add_bus(bus);
 
 	/* Add it to the list of buses */
 	list_add(&bus->bus_list, &usb_bus_list);
 
-	printk("New USB bus registered, assigned bus number %d\n", bus->busnum);
+	info("new USB bus registered, assigned bus number %d", bus->busnum);
 }
 
 void usb_deregister_bus(struct usb_bus *bus)
 {
-	printk("usbcore: USB bus %d deregistered\n", bus->busnum);
+	info("USB bus %d deregistered", bus->busnum);
 
 	/*
 	 * NOTE: make sure that all the devices are removed by the
@@ -305,7 +296,7 @@
 	int i;
 
 	if (!dev) {
-		printk(KERN_ERR "usbcore: null device being checked!!!\n");
+		err("null device being checked!!!");
 		return;
 	}
 
@@ -335,7 +326,7 @@
 	if (!iface || !driver)
 		return;
 
-	printk(KERN_DEBUG "usbcore: %s driver claimed interface %p\n", driver->name, iface);
+	dbg("%s driver claimed interface %p", driver->name, iface);
 
 	iface->driver = driver;
 	iface->private_data = priv;
@@ -384,7 +375,7 @@
 	struct usb_interface *interface;
 	
 	if ((!dev) || (ifnum >= dev->actconfig->bNumInterfaces)) {
-		printk(KERN_ERR "usb-core: bad find_interface_driver params\n");
+		err("bad find_interface_driver params");
 		return -1;
 	}
 
@@ -428,7 +419,11 @@
 	}
  
 	if (rejected)
-		printk(KERN_DEBUG "usbcore: unhandled interfaces on device.\n");
+		dbg("unhandled interfaces on device");
+
+#ifdef DEBUG
+	usb_show_device(dev);
+#endif
 }
 
 /*
@@ -478,7 +473,7 @@
 	      in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
 	if (!urb)
 	{
-		printk(KERN_ERR MODSTR"alloc_urb: kmalloc failed\n");
+		err("alloc_urb: kmalloc failed");
 		return 0;
 	}
 	memset(urb,0,sizeof(urb_t));
@@ -522,7 +517,7 @@
 		wake_up(awd->wakeup);
 #if 0
 	else
-		dbg(KERN_DEBUG MODSTR "(blocking_completion): waitqueue empty!\n"); 
+		dbg("(blocking_completion): waitqueue empty!"); 
 		// even occurs if urb was unlinked by timeout...
 #endif
 }
@@ -573,7 +568,7 @@
 
 	if (!status) {
 		// timeout
-		printk(KERN_DEBUG MODSTR"usb_control/bulk_msg: timeout\n");
+		dbg("usb_control/bulk_msg: timeout");
 		usb_unlink_urb(urb);  // remove urb safely
 		status=-ETIMEDOUT;
 	}
@@ -621,7 +616,7 @@
 	dr.value = cpu_to_le16p(&value);
 	dr.index = cpu_to_le16p(&index);
 	dr.length = cpu_to_le16p(&size);
-	//dbg(KERN_DEBUG MODSTR"usb_control_msg\n");	
+	//dbg("usb_control_msg");	
 	return usb_internal_control_msg(dev, pipe, &dr, data, size, timeout);
 }
 
@@ -683,7 +678,7 @@
 int usb_terminate_bulk(struct usb_device *dev, void *first)
 {
 	urb_t *urb=(urb_t*)first;
-	dbg(KERN_DEBUG MODSTR"usb_terminate_bulk: urb:%p\n",urb);
+	dbg("usb_terminate_bulk: urb:%p",urb);
 	if (!urb) // none found? there is nothing to remove!
 		return -ENODEV;
   
@@ -702,7 +697,7 @@
 {
 	dev->bus->bandwidth_allocated -= bw_alloc;
 	dev->bus->bandwidth_int_reqs--;
-	PRINTD ("bw_alloc reduced to %d for %d requesters",
+	dbg("bw_alloc reduced to %d for %d requesters",
 		dev->bus->bandwidth_allocated,
 		dev->bus->bandwidth_int_reqs +
 		dev->bus->bandwidth_isoc_reqs);
@@ -716,7 +711,7 @@
 		return;
 #if 0 // verbose...
 	if (!wd->handler(urb->status, urb->transfer_buffer, urb->actual_length, wd->context))
-		printk(KERN_ERR "usb: legacy irq callback returned 0!!!\n");
+		err("legacy irq callback returned 0!!!");
 #else
 	wd->handler(urb->status, urb->transfer_buffer, urb->actual_length, wd->context);
 #endif
@@ -732,7 +727,7 @@
 
 	*handle = NULL;
 	
-	//printk("irq: dev:%p pipe:%08X handler:%p period:%d dev_id:%p max:%d\n", dev, pipe, handler, period, dev_id, maxsze);
+	//dbg("irq: dev:%p pipe:%08X handler:%p period:%d dev_id:%p max:%d", dev, pipe, handler, period, dev_id, maxsze);
 	
 	/* Check host controller's bandwidth for this int. request. */
 	bustime = calc_bus_time (usb_pipeslow(pipe), usb_pipein(pipe), 0,
@@ -776,7 +771,7 @@
 	if (!ret) {
 		dev->bus->bandwidth_allocated += bustime;
 		dev->bus->bandwidth_int_reqs++;
-		PRINTD ("bw_alloc bumped to %d for %d requesters",
+		dbg("bw_alloc bumped to %d for %d requesters",
 			dev->bus->bandwidth_allocated,
 			dev->bus->bandwidth_int_reqs +
 			dev->bus->bandwidth_isoc_reqs);
@@ -830,12 +825,12 @@
 	/* Everything should be fine being passed into here, but we sanity */
 	/*  check JIC */
 	if (header->bLength > size) {
-		printk(KERN_ERR "usb: ran out of descriptors parsing\n");
+		err("ran out of descriptors parsing");
 		return -1;
 	}
 		
 	if (header->bDescriptorType != USB_DT_ENDPOINT) {
-		printk(KERN_INFO "usb: unexpected descriptor 0x%X, expecting endpoint descriptor, type 0x%X\n",
+		warn("unexpected descriptor 0x%X, expecting endpoint descriptor, type 0x%X",
 			endpoint->bDescriptorType, USB_DT_ENDPOINT);
 		return parsed;
 	}
@@ -859,7 +854,7 @@
 		header = (struct usb_descriptor_header *)buffer;
 
 		if (header->bLength < 2) {
-			printk(KERN_ERR "usb: invalid descriptor length of %d\n", header->bLength);
+			err("invalid descriptor length of %d", header->bLength);
 			return -1;
 		}
 
@@ -871,7 +866,7 @@
 		    (header->bDescriptorType == USB_DT_DEVICE))
 			break;
 
-		printk(KERN_INFO "usb: skipping descriptor 0x%X\n",
+		dbg("skipping descriptor 0x%X",
 			header->bDescriptorType);
 		numskipped++;
 
@@ -880,7 +875,7 @@
 		parsed += header->bLength;
 	}
 	if (numskipped)
-		printk(KERN_INFO "usb: skipped %d class/vendor specific endpoint descriptors\n", numskipped);
+		dbg("skipped %d class/vendor specific endpoint descriptors", numskipped);
 
 	/* Copy any unknown descriptors into a storage area for drivers */
 	/*  to later parse */
@@ -894,7 +889,7 @@
 	endpoint->extra = kmalloc(len, GFP_KERNEL);
 
 	if (!endpoint->extra) {
-		printk(KERN_ERR "Couldn't allocate memory for endpoint extra descriptors\n");
+		err("couldn't allocate memory for endpoint extra descriptors");
 		endpoint->extralen = 0;
 		return parsed;
 	}
@@ -919,7 +914,7 @@
 	interface->altsetting = kmalloc(sizeof(struct usb_interface_descriptor) * interface->max_altsetting, GFP_KERNEL);
 	
 	if (!interface->altsetting) {
-		printk(KERN_ERR "couldn't kmalloc interface->altsetting\n");
+		err("couldn't kmalloc interface->altsetting");
 		return -1;
 	}
 
@@ -931,7 +926,7 @@
 			oldmas = interface->max_altsetting;
 			interface->max_altsetting += USB_ALTSETTINGALLOC;
 			if (interface->max_altsetting > USB_MAXALTSETTING) {
-				printk(KERN_WARNING "usb: too many alternate settings (max %d)\n",
+				warn("too many alternate settings (max %d)",
 					USB_MAXALTSETTING);
 				return -1;
 			}
@@ -939,7 +934,7 @@
 			ptr = interface->altsetting;
 			interface->altsetting = kmalloc(sizeof(struct usb_interface_descriptor) * interface->max_altsetting, GFP_KERNEL);
 			if (!interface->altsetting) {
-				printk("couldn't kmalloc interface->altsetting\n");
+				err("couldn't kmalloc interface->altsetting");
 				interface->altsetting = ptr;
 				return -1;
 			}
@@ -966,7 +961,7 @@
 			header = (struct usb_descriptor_header *)buffer;
 
 			if (header->bLength < 2) {
-				printk(KERN_ERR "usb: invalid descriptor length of %d\n", header->bLength);
+				err("invalid descriptor length of %d", header->bLength);
 				return -1;
 			}
 
@@ -986,7 +981,7 @@
 		}
 
 		if (numskipped)
-			printk(KERN_INFO "usb: skipped %d class/vendor specific interface descriptors\n", numskipped);
+			dbg("skipped %d class/vendor specific interface descriptors", numskipped);
 
 		/* Copy any unknown descriptors into a storage area for */
 		/*  drivers to later parse */
@@ -998,7 +993,7 @@
 			ifp->extra = kmalloc(len, GFP_KERNEL);
 
 			if (!ifp->extra) {
-				printk(KERN_ERR "couldn't allocate memory for interface extra descriptors\n");
+				err("couldn't allocate memory for interface extra descriptors");
 				ifp->extralen = 0;
 				return -1;
 			}
@@ -1014,7 +1009,7 @@
 			return parsed;
 
 		if (ifp->bNumEndpoints > USB_MAXENDPOINTS) {
-			printk(KERN_WARNING "usb: too many endpoints\n");
+			warn("too many endpoints");
 			return -1;
 		}
 
@@ -1022,7 +1017,7 @@
 			kmalloc(ifp->bNumEndpoints *
 			sizeof(struct usb_endpoint_descriptor), GFP_KERNEL);
 		if (!ifp->endpoint) {
-			printk(KERN_WARNING "usb: out of memory\n");
+			err("out of memory");
 			return -1;	
 		}
 
@@ -1033,7 +1028,7 @@
 			header = (struct usb_descriptor_header *)buffer;
 
 			if (header->bLength > size) {
-				printk(KERN_ERR "usb: ran out of descriptors parsing\n");
+				err("ran out of descriptors parsing");
 				return -1;
 			}
 		
@@ -1065,21 +1060,20 @@
 	struct usb_descriptor_header *header;
 
 	memcpy(config, buffer, USB_DT_INTERFACE_SIZE);
-	usb_show_config_descriptor(config);
 	le16_to_cpus(&config->wTotalLength);
 	size = config->wTotalLength;
 
 	if (config->bNumInterfaces > USB_MAXINTERFACES) {
-		printk(KERN_WARNING "usb: too many interfaces\n");
+		warn("too many interfaces");
 		return -1;
 	}
 
 	config->interface = (struct usb_interface *)
 		kmalloc(config->bNumInterfaces *
 		sizeof(struct usb_interface), GFP_KERNEL);
-	printk("kmalloc IF %p, numif %i\n",config->interface,config->bNumInterfaces);
+	dbg("kmalloc IF %p, numif %i",config->interface,config->bNumInterfaces);
 	if (!config->interface) {
-		printk(KERN_WARNING "usb: out of memory\n");
+		err("out of memory");
 		return -1;	
 	}
 
@@ -1092,12 +1086,12 @@
 	for (i = 0; i < config->bNumInterfaces; i++) {
 		header = (struct usb_descriptor_header *)buffer;
 		if (header->bLength > size) {
-			printk(KERN_ERR "usb: ran out of descriptors parsing\n");
+			err("ran out of descriptors parsing");
 			return -1;
 		}
 		
 		if (header->bDescriptorType != USB_DT_INTERFACE) {
-			printk(KERN_INFO "usb: unexpected descriptor 0x%X\n",
+			warn("unexpected descriptor 0x%X",
 				header->bDescriptorType);
 
 			buffer += header->bLength;
@@ -1187,7 +1181,7 @@
 		header = (struct usb_descriptor_header *)buffer;
 
 		if (header->bLength < 2) {
-			printk(KERN_ERR "usb: invalid descriptor length of %d\n", header->bLength);
+			err("invalid descriptor length of %d", header->bLength);
 			return -1;
 		}
 
@@ -1215,7 +1209,7 @@
 
 	*pdev = NULL;
 
-	printk("usbcore: USB disconnect on device %d\n", dev->devnum);
+	info("USB disconnect on device %d", dev->devnum);
 
 	if (dev->actconfig) {
 		for (i = 0; i < dev->actconfig->bNumInterfaces; i++) {
@@ -1427,7 +1421,7 @@
 		}
 	}
 	if (!iface) {
-		printk(KERN_INFO "usb: selecting invalid interface %d\n", interface);
+		warn("selecting invalid interface %d", interface);
 		return -EINVAL;
 	}
 
@@ -1453,7 +1447,7 @@
 		}
 	}
 	if (!cp) {
-		printk(KERN_INFO "usb: selecting invalid configuration %d\n", configuration);
+		warn("selecting invalid configuration %d", configuration);
 		return -1;
 	}
 
@@ -1478,7 +1472,7 @@
 
 int usb_set_report(struct usb_device *dev, unsigned char type, unsigned char id, unsigned char index, void *buf, int size)
 {
-	return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
+	return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
 		USB_REQ_SET_REPORT, USB_RT_HIDD,
 		(type << 8) + id, index, buf, size, HZ);
 }
@@ -1493,7 +1487,7 @@
 		(struct usb_config_descriptor *)buffer;
 
 	if (dev->descriptor.bNumConfigurations > USB_MAXCONFIG) {
-		printk(KERN_WARNING "usb: too many configurations\n");
+		warn("too many configurations");
 		return -1;
 	}
 
@@ -1501,7 +1495,7 @@
 		kmalloc(dev->descriptor.bNumConfigurations *
 		sizeof(struct usb_config_descriptor), GFP_KERNEL);
 	if (!dev->config) {
-		printk(KERN_WARNING "usb: out of memory.\n");
+		err("out of memory");
 		return -1;	
 	}
 	memset(dev->config, 0, dev->descriptor.bNumConfigurations *
@@ -1514,7 +1508,7 @@
 		/*  configuration is */
 		result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 8);
 		if (result < 0) {
-			printk(KERN_ERR "usb: unable to get descriptor\n");
+			err("unable to get descriptor");
 			goto err;
 		}
 
@@ -1523,7 +1517,7 @@
 
 		bigbuffer = kmalloc(desc->wTotalLength, GFP_KERNEL);
 		if (!bigbuffer) {
-			printk(KERN_ERR "unable to allocate memory for configuration descriptors\n");
+			err("unable to allocate memory for configuration descriptors");
 			result=-ENOMEM;
 			goto err;
 		}
@@ -1531,7 +1525,7 @@
 		/* Now that we know the length, get the whole thing */
 		result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, bigbuffer, desc->wTotalLength);
 		if (result < 0) {
-			printk(KERN_ERR "couldn't get all of config descriptors\n");
+			err("couldn't get all of config descriptors");
 			kfree(bigbuffer);
 			goto err;
 		}		
@@ -1539,7 +1533,7 @@
 		kfree(bigbuffer);
 
 		if (result > 0)
-			printk(KERN_INFO "usb: descriptor data left\n");
+			dbg("descriptor data left");
 		else if (result < 0)
 		{
 			result=-1;
@@ -1573,14 +1567,14 @@
 		if (ret >= 0 && u.desc.bLength >= 4)
 			dev->string_langid = le16_to_cpup(&u.desc.wData[0]);
 		else
-			printk(KERN_ERR "usb: error getting string!\n");
+			err("error getting string");
 		dev->string_langid |= 0x10000;	/* so it's non-zero */
 	}
 
 	if (usb_get_string(dev, dev->string_langid, index, u.buffer, 4) < 0 ||
 	    ((ret = usb_get_string(dev, dev->string_langid, index, u.buffer,
 			      u.desc.bLength)) < 0)) {
-		printk(KERN_ERR "usb: error retrieving string\n");
+		err("error retrieving string");
 		return NULL;
 	}
 
@@ -1591,7 +1585,7 @@
 
 	ptr = kmalloc(len, GFP_KERNEL);
 	if (!ptr) {
-		printk(KERN_ERR "usb: couldn't allocate memory for string\n");
+		err("couldn't allocate memory for string");
 		return NULL;
 	}
 
@@ -1614,7 +1608,7 @@
 {
 	int addr, err;
 
-	printk(KERN_INFO "USB new device connect, assigned device number %d\n",
+	info("USB new device connect, assigned device number %d",
 		dev->devnum);
  
 	dev->maxpacketsize = 0;		/* Default to 8 byte max packet size */
@@ -1627,7 +1621,7 @@
 
 	err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, 8);
 	if (err < 0) {
-		printk(KERN_ERR "usbcore: USB device not responding, giving up (error=%d)\n", err);
+		err("USB device not responding, giving up (error=%d)", err);
 		clear_bit(addr, &dev->bus->devmap.devicemap);
 		dev->devnum = -1;
 		return 1;
@@ -1647,7 +1641,7 @@
 	err = usb_set_address(dev);
 	
 	if (err < 0) {
-		printk(KERN_ERR "usbcore: USB device not accepting new address (error=%d)\n", err);
+		err("USB device not accepting new address (error=%d)", err);
 		clear_bit(dev->devnum, &dev->bus->devmap.devicemap);
 		dev->devnum = -1;
 		return 1;
@@ -1657,7 +1651,7 @@
 
 	err = usb_get_device_descriptor(dev);
 	if (err < 0) {
-		printk(KERN_ERR "usbcore: unable to get device descriptor (error=%d)\n",err);
+		err("unable to get device descriptor (error=%d)",err);
 		clear_bit(dev->devnum, &dev->bus->devmap.devicemap);
 		dev->devnum = -1;
 		return 1;
@@ -1666,7 +1660,7 @@
 	err=usb_get_configuration(dev);
 	
 	if (err < 0) {
-		printk(KERN_ERR "usbcore: unable to get configuration (error=%d)\n", err);
+		err("unable to get configuration (error=%d)", err);
 		clear_bit(dev->devnum, &dev->bus->devmap.devicemap);
 		dev->devnum = -1;
 		return 1;
@@ -1677,7 +1671,7 @@
 
 	/* we set the default configuration here */
 	if (usb_set_configuration(dev, dev->config[0].bConfigurationValue)) {
-		printk(KERN_ERR "usbcore: failed to set default configuration\n");
+		err("failed to set default configuration");
 		return -1;
 	}
 
@@ -1723,7 +1717,7 @@
 int usb_major_init(void)
 {
 	if (register_chrdev(USB_MAJOR,"usb",&usb_fops)) {
-		printk("unable to get major %d for usb devices\n", USB_MAJOR);
+		err("unable to get major %d for usb devices", USB_MAJOR);
 		return -EBUSY;
 	}
 	return 0;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)