more generalization of the dbg() diagnostic message prints

This commit is contained in:
Markus Fröschle
2014-09-01 07:20:22 +00:00
parent df57613c13
commit f2aae64892
3 changed files with 413 additions and 403 deletions

110
usb/usb.c
View File

@@ -56,13 +56,13 @@
extern int usb_stor_curr_dev;
extern uint32_t usb_1st_disk_drive;
//#define USB_DEBUG
#ifdef USB_DEBUG
#define debug_printf(fmt, args...) xprintf(fmt , ##args)
#define DEBUG_USB
#ifdef DEBUG_USB
#define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0)
#else
#define debug_printf(fmt, args...)
#endif
#define dbg(format, arg...) do { ; } while (0)
#endif /* DEBUG_USB */
#define USB_BUFSIZ 512
@@ -157,20 +157,20 @@ int usb_init(int32_t handle, const struct pci_device_id *ent)
usb_hub_reset(bus_index);
/* init low_level USB */
debug_printf("USB: ");
dbg("USB: ");
switch(ent->class)
{
case PCI_CLASS_SERIAL_USB_UHCI:
//res = uhci_usb_lowlevel_init(handle, ent, &priv);
debug_printf("sorry, no uhci driver available\r\n");
dbg("sorry, no uhci driver available\r\n");
break;
case PCI_CLASS_SERIAL_USB_OHCI:
debug_printf("initialize ohci interface\r\n");
dbg("initialize ohci interface\r\n");
res = ohci_usb_lowlevel_init(handle, ent, &priv);
break;
case PCI_CLASS_SERIAL_USB_EHCI:
debug_printf("initialize ehci interface\r\n");
dbg("initialize ehci interface\r\n");
res = ehci_usb_lowlevel_init(handle, ent, &priv);
break;
default: res = -1; break;
@@ -315,7 +315,7 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
setup_packet->value = swpw(value);
setup_packet->index = swpw(index);
setup_packet->length = swpw(size);
debug_printf("usb_control_msg: request: 0x%X, requesttype: 0x%X, value 0x%X index 0x%X length 0x%X\r\n", request, requesttype, value, index, size);
dbg("usb_control_msg: request: 0x%X, requesttype: 0x%X, value 0x%X index 0x%X length 0x%X\r\n", request, requesttype, value, index, size);
switch(priv->ent->class)
{
case PCI_CLASS_SERIAL_USB_OHCI:
@@ -414,7 +414,7 @@ static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev
/* Control => bidirectional */
dev->epmaxpacketout[b] = ep->wMaxPacketSize;
dev->epmaxpacketin[b] = ep->wMaxPacketSize;
debug_printf("##Control EP epmaxpacketout/in[%d] = %d\r\n", b, dev->epmaxpacketin[b]);
dbg("##Control EP epmaxpacketout/in[%d] = %d\r\n", b, dev->epmaxpacketin[b]);
}
else
{
@@ -424,7 +424,7 @@ static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev
if (ep->wMaxPacketSize > dev->epmaxpacketout[b])
{
dev->epmaxpacketout[b] = ep->wMaxPacketSize;
debug_printf("##EP epmaxpacketout[%d] = %d\r\n", b, dev->epmaxpacketout[b]);
dbg("##EP epmaxpacketout[%d] = %d\r\n", b, dev->epmaxpacketout[b]);
}
}
else
@@ -433,7 +433,7 @@ static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev
if (ep->wMaxPacketSize > dev->epmaxpacketin[b])
{
dev->epmaxpacketin[b] = ep->wMaxPacketSize;
debug_printf("##EP epmaxpacketin[%d] = %d\r\n", b, dev->epmaxpacketin[b]);
dbg("##EP epmaxpacketin[%d] = %d\r\n", b, dev->epmaxpacketin[b]);
}
} /* if out */
} /* if control */
@@ -467,7 +467,7 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
head = (struct usb_descriptor_header *)&buffer[0];
if (head->bDescriptorType != USB_DT_CONFIG)
{
debug_printf(" ERROR: NOT USB_CONFIG_DESC %x\r\n", head->bDescriptorType);
dbg(" ERROR: NOT USB_CONFIG_DESC %x\r\n", head->bDescriptorType);
return -1;
}
memcpy(&dev->config, buffer, buffer[0]);
@@ -504,12 +504,12 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
dev->config.if_desc[ifno].no_of_ep++;
memcpy(&dev->config.if_desc[ifno].ep_desc[epno], &buffer[index], buffer[index]);
dev->config.if_desc[ifno].ep_desc[epno].wMaxPacketSize = swpw(dev->config.if_desc[ifno].ep_desc[epno].wMaxPacketSize);
debug_printf("if %d, ep %d\r\n", ifno, epno);
dbg("if %d, ep %d\r\n", ifno, epno);
break;
default:
if (head->bLength == 0)
return 1;
debug_printf("unknown Description Type : %x\r\n", head->bDescriptorType);
dbg("unknown Description Type : %x\r\n", head->bDescriptorType);
#ifdef USB_DEBUG
{
unsigned char *ch;
@@ -517,8 +517,8 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
ch = (unsigned char *)head;
for (i = 0; i < head->bLength; i++)
debug_printf(" %02X", *ch++);
debug_printf("\r\n");
dbg(" %02X", *ch++);
dbg("\r\n");
}
#endif /* USB_DEBUG */
break;
@@ -577,19 +577,19 @@ int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer, int
if (result < 9)
{
if (result < 0)
debug_printf("unable to get descriptor, error %lX\r\n", dev->status);
dbg("unable to get descriptor, error %lX\r\n", dev->status);
else
debug_printf("config descriptor too short (expected %i, got %i)\n", 9, result);
dbg("config descriptor too short (expected %i, got %i)\n", 9, result);
return -1;
}
tmp = swpw(config->wTotalLength);
if (tmp > USB_BUFSIZ)
{
debug_printf("usb_get_configuration_no: failed to get descriptor - too long: %d\r\n", tmp);
dbg("usb_get_configuration_no: failed to get descriptor - too long: %d\r\n", tmp);
return -1;
}
result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, tmp);
debug_printf("get_conf_no %d Result %d, wLength %d\r\n", cfgno, result, tmp);
dbg("get_conf_no %d Result %d, wLength %d\r\n", cfgno, result, tmp);
return result;
}
@@ -600,7 +600,7 @@ int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer, int
int usb_set_address(struct usb_device *dev)
{
int res;
debug_printf("set address %d\r\n", dev->devnum);
dbg("set address %d\r\n", dev->devnum);
res = usb_control_msg(dev, usb_snddefctrl(dev), USB_REQ_SET_ADDRESS, 0, (dev->devnum), 0, NULL, 0, USB_CNTL_TIMEOUT);
return res;
}
@@ -622,7 +622,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
}
if (!if_face)
{
debug_printf("selecting invalid interface %d", interface);
dbg("selecting invalid interface %d", interface);
return -1;
}
/*
@@ -647,7 +647,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
int usb_set_configuration(struct usb_device *dev, int configuration)
{
int res;
debug_printf("set configuration %d\r\n", configuration);
dbg("set configuration %d\r\n", configuration);
/* set setup command */
res = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
USB_REQ_SET_CONFIGURATION, 0, configuration, 0, NULL, 0, USB_CNTL_TIMEOUT);
@@ -781,7 +781,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
tbuf = (unsigned char *)driver_mem_alloc(USB_BUFSIZ);
if (tbuf == NULL)
{
debug_printf("usb_string: malloc failure\r\n");
dbg("usb_string: malloc failure\r\n");
return -1;
}
/* get langid for strings if it's not yet known */
@@ -790,13 +790,13 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
err = usb_string_sub(dev, 0, 0, tbuf);
if (err < 0)
{
debug_printf("error getting string descriptor 0 (error=%lx)\r\n", dev->status);
dbg("error getting string descriptor 0 (error=%lx)\r\n", dev->status);
driver_mem_free(tbuf);
return -1;
}
else if (tbuf[0] < 4)
{
debug_printf("string descriptor 0 too short\r\n");
dbg("string descriptor 0 too short\r\n");
driver_mem_free(tbuf);
return -1;
}
@@ -805,7 +805,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
dev->have_langid = -1;
dev->string_langid = tbuf[2] | (tbuf[3] << 8);
/* always use the first langid listed */
debug_printf("USB device number %d default language ID 0x%x\r\n", dev->devnum, dev->string_langid);
dbg("USB device number %d default language ID 0x%x\r\n", dev->devnum, dev->string_langid);
}
}
err = usb_string_sub(dev, dev->string_langid, index, tbuf);
@@ -844,8 +844,8 @@ void usb_disconnect(struct usb_device **pdev)
if (dev != NULL)
{
int i;
debug_printf("USB %d disconnect on device %d\r\n", dev->parent->usbnum, dev->parent->devnum);
debug_printf("USB %d disconnected, device number %d\r\n", dev->usbnum, dev->devnum);
dbg("USB %d disconnect on device %d\r\n", dev->parent->usbnum, dev->parent->devnum);
dbg("USB %d disconnected, device number %d\r\n", dev->usbnum, dev->devnum);
if (dev->deregister != NULL)
dev->deregister(dev);
/* Free up all the children.. */
@@ -853,7 +853,7 @@ void usb_disconnect(struct usb_device **pdev)
{
if (dev->children[i] != NULL)
{
debug_printf("USB %d, disconnect children %d\r\n", dev->usbnum, dev->children[i]->devnum);
dbg("USB %d, disconnect children %d\r\n", dev->usbnum, dev->children[i]->devnum);
usb_disconnect(&dev->children[i]);
dev->children[i] = NULL;
}
@@ -889,24 +889,28 @@ struct usb_device *usb_get_dev_index(int index, int index_bus)
*/
struct usb_device *usb_alloc_new_device(int bus_index, void *priv)
{
int i, index = dev_index[bus_index];
int i;
int index = dev_index[bus_index];
struct usb_device *dev;
debug_printf("USB %d new device %d\r\n", bus_index, index);
dbg("USB %d new device %d\r\n", bus_index, index);
if (index >= USB_MAX_DEVICE)
{
debug_printf("ERROR, too many USB Devices, max=%d\r\n", USB_MAX_DEVICE);
dbg("ERROR, too many USB Devices, max=%d\r\n", USB_MAX_DEVICE);
return NULL;
}
/* default Address is 0, real addresses start with 1 */
dev = &usb_dev[(bus_index * USB_MAX_DEVICE) + index];
dev->devnum = index + 1;
dev->maxchild = 0;
for (i = 0; i < USB_MAXCHILDREN; dev->children[i++] = NULL);
for (i = 0; i < USB_MAXCHILDREN; dev->children[i++] = NULL)
;
dev->parent = NULL;
dev->priv_hcd = priv;
dev->usbnum = bus_index;
dev_index[bus_index]++;
return dev;
}
@@ -940,7 +944,7 @@ int usb_new_device(struct usb_device *dev)
tmpbuf = (unsigned char *) driver_mem_alloc(USB_BUFSIZ);
if (tmpbuf == NULL)
{
debug_printf("usb_new_device: malloc failure\r\n");
dbg("usb_new_device: malloc failure\r\n");
return 1;
}
@@ -957,7 +961,7 @@ int usb_new_device(struct usb_device *dev)
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, 8);
if (err < 8)
{
debug_printf("\r\nUSB device not responding, giving up (status=%lX)\r\n", dev->status);
dbg("\r\nUSB device not responding, giving up (status=%lX)\r\n", dev->status);
driver_mem_free(tmpbuf);
return 1;
}
@@ -982,7 +986,7 @@ int usb_new_device(struct usb_device *dev)
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
if (err < 0)
{
debug_printf("usb_new_device: usb_get_descriptor() failed\r\n");
dbg("usb_new_device: usb_get_descriptor() failed\r\n");
driver_mem_free(tmpbuf);
return 1;
}
@@ -1002,7 +1006,7 @@ int usb_new_device(struct usb_device *dev)
}
if (port < 0)
{
debug_printf("usb_new_device: cannot locate device's port.\r\n");
dbg("usb_new_device: cannot locate device's port.\r\n");
driver_mem_free(tmpbuf);
return 1;
}
@@ -1010,7 +1014,7 @@ int usb_new_device(struct usb_device *dev)
err = hub_port_reset(dev->parent, port, &portstatus);
if (err < 0)
{
debug_printf("\r\nCouldn't reset port %d\r\n", port);
dbg("\r\nCouldn't reset port %d\r\n", port);
driver_mem_free(tmpbuf);
return 1;
}
@@ -1029,7 +1033,7 @@ int usb_new_device(struct usb_device *dev)
err = usb_set_address(dev); /* set address */
if (err < 0)
{
debug_printf("\r\nUSB device not accepting new address (error=%lX)\r\n", dev->status);
dbg("\r\nUSB device not accepting new address (error=%lX)\r\n", dev->status);
driver_mem_free(tmpbuf);
return 1;
}
@@ -1039,9 +1043,9 @@ int usb_new_device(struct usb_device *dev)
if (err < tmp)
{
if (err < 0)
debug_printf("unable to get device descriptor (error=%d)\r\n", err);
dbg("unable to get device descriptor (error=%d)\r\n", err);
else
debug_printf("USB device descriptor short read (expected %i, got %i)\r\n", tmp, err);
dbg("USB device descriptor short read (expected %i, got %i)\r\n", tmp, err);
driver_mem_free(tmpbuf);
return 1;
}
@@ -1057,11 +1061,11 @@ int usb_new_device(struct usb_device *dev)
/* we set the default configuration here */
if (usb_set_configuration(dev, dev->config.bConfigurationValue))
{
debug_printf("failed to set default configuration len %d, status %lX\r\n", dev->act_len, dev->status);
dbg("failed to set default configuration len %d, status %lX\r\n", dev->act_len, dev->status);
driver_mem_free(tmpbuf);
return -1;
}
debug_printf("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\r\n",
dbg("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\r\n",
dev->descriptor.iManufacturer, dev->descriptor.iProduct,
dev->descriptor.iSerialNumber);
memset(dev->mf, 0, sizeof(dev->mf));
@@ -1073,9 +1077,9 @@ int usb_new_device(struct usb_device *dev)
usb_string(dev, dev->descriptor.iProduct, dev->prod, sizeof(dev->prod));
if (dev->descriptor.iSerialNumber)
usb_string(dev, dev->descriptor.iSerialNumber, dev->serial, sizeof(dev->serial));
debug_printf("Manufacturer %s\r\n", dev->mf);
debug_printf("Product %s\r\n", dev->prod);
debug_printf("SerialNumber %s\r\n", dev->serial);
dbg("Manufacturer %s\r\n", dev->mf);
dbg("Product %s\r\n", dev->prod);
dbg("SerialNumber %s\r\n", dev->serial);
/* now prode if the device is a hub */
usb_hub_probe(dev, 0);
driver_mem_free(tmpbuf);
@@ -1604,10 +1608,16 @@ int usb_hub_probe(struct usb_device *dev, int ifnum)
struct usb_interface_descriptor *iface;
struct usb_endpoint_descriptor *ep;
int ret;
iface = &dev->config.if_desc[ifnum];
/* Is it a hub? */
if (iface->bInterfaceClass != USB_CLASS_HUB)
{
dbg("iface->bInterfaceClass != USB_CLASS_HUB (%d), %d instead\r\n", USB_CLASS_HUB, iface->bInterfaceClass);
return 0;
}
/* Some hubs have a subclass of 1, which AFAICT according to the */
/* specs is not defined, but it works */
if ((iface->bInterfaceSubClass != 0) && (iface->bInterfaceSubClass != 1))

View File

@@ -222,24 +222,24 @@ static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum)
iface = &dev->config.if_desc[ifnum];
if (iface->bInterfaceClass != 3)
if (iface->bInterfaceClass != USB_CLASS_HID)
{
dbg("iface->bInterfaceClass != 3 (%d instead)\r\n", iface->bInterfaceClass);
dbg("iface->bInterfaceClass != USB_CLASS_HID (%d instead)\r\n", iface->bInterfaceClass);
return 0;
}
if (iface->bInterfaceSubClass != 1)
if (iface->bInterfaceSubClass != USB_SUB_HID_BOOT)
{
dbg("iface->bInterfaceSubClass != 1 (%d instead)\r\n", iface->bInterfaceSubClass);
dbg("iface->bInterfaceSubClass != USB_SUB_HID_BOOT (%d instead)\r\n", iface->bInterfaceSubClass);
return 0;
}
if (iface->bInterfaceProtocol != 2)
if (iface->bInterfaceProtocol != USB_PROT_HID_MOUSE)
{
dbg("iface->bInterfaceProtocol != 2 (%d)\r\n", iface->bInterfaceProtocol);
dbg("iface->bInterfaceProtocol != USB_PROT_HID_MOUSE (%d)\r\n", iface->bInterfaceProtocol);
return 0;
}