aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2009-06-29 11:02:04 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-09-23 09:46:23 -0400
commit4c6e8971cbe0148085fcf6fd30eaa3c39f8a8cce (patch)
tree74f7a8876a748926ae3f788e1e1e777be2085ec7 /drivers/usb/core
parentccf5b801cef4f9e2d708d3b87e91e2bc6abd5206 (diff)
USB: make the "usbfs_snoop" log more pertinent
This patch (as1261) reduces the amount of detailed URB information logged by usbfs when the usbfs_snoop parameter is enabled. Currently we don't display the final status value for a completed URB. But we do display the entire data buffer twice: both before submission and after completion. The after-completion display doesn't limit itself to the actual_length value. But since usbmon is readily available in virtually all distributions, there's no reason for usbfs to print out any buffer contents at all! So this patch restricts the information to: userspace buffer pointer, endpoint number, type, and direction, length or actual_length, and timeout value or status. Now everything fits neatly into a single line. Along with those changes, the patch also fixes the snoop output for the REAPURBNDELAY and REAPURBNDELAY32 ioctls. The current version omits the 'N' from the names. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/core')
-rw-r--r--drivers/usb/core/devio.c131
1 files changed, 62 insertions, 69 deletions
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 165de5d59005..a1add776e89a 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -100,11 +100,15 @@ MODULE_PARM_DESC(usbfs_snoop, "true to log all usbfs traffic");
100 dev_info(dev , format , ## arg); \ 100 dev_info(dev , format , ## arg); \
101 } while (0) 101 } while (0)
102 102
103#define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0) 103enum snoop_when {
104 SUBMIT, COMPLETE
105};
104 106
107#define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0)
105 108
106#define MAX_USBFS_BUFFER_SIZE 16384 109#define MAX_USBFS_BUFFER_SIZE 16384
107 110
111
108static int connected(struct dev_state *ps) 112static int connected(struct dev_state *ps)
109{ 113{
110 return (!list_empty(&ps->list) && 114 return (!list_empty(&ps->list) &&
@@ -301,24 +305,42 @@ static struct async *async_getpending(struct dev_state *ps,
301 return NULL; 305 return NULL;
302} 306}
303 307
304static void snoop_urb(struct urb *urb, void __user *userurb) 308static void snoop_urb(struct usb_device *udev,
309 void __user *userurb, int pipe, unsigned length,
310 int timeout_or_status, enum snoop_when when)
305{ 311{
306 unsigned j; 312 static const char *types[] = {"isoc", "int", "ctrl", "bulk"};
307 unsigned char *data = urb->transfer_buffer; 313 static const char *dirs[] = {"out", "in"};
314 int ep;
315 const char *t, *d;
308 316
309 if (!usbfs_snoop) 317 if (!usbfs_snoop)
310 return; 318 return;
311 319
312 dev_info(&urb->dev->dev, "direction=%s\n", 320 ep = usb_pipeendpoint(pipe);
313 usb_urb_dir_in(urb) ? "IN" : "OUT"); 321 t = types[usb_pipetype(pipe)];
314 dev_info(&urb->dev->dev, "userurb=%p\n", userurb); 322 d = dirs[!!usb_pipein(pipe)];
315 dev_info(&urb->dev->dev, "transfer_buffer_length=%u\n", 323
316 urb->transfer_buffer_length); 324 if (userurb) { /* Async */
317 dev_info(&urb->dev->dev, "actual_length=%u\n", urb->actual_length); 325 if (when == SUBMIT)
318 dev_info(&urb->dev->dev, "data: "); 326 dev_info(&udev->dev, "userurb %p, ep%d %s-%s, "
319 for (j = 0; j < urb->transfer_buffer_length; ++j) 327 "length %u\n",
320 printk("%02x ", data[j]); 328 userurb, ep, t, d, length);
321 printk("\n"); 329 else
330 dev_info(&udev->dev, "userurb %p, ep%d %s-%s, "
331 "actual_length %u status %d\n",
332 userurb, ep, t, d, length,
333 timeout_or_status);
334 } else {
335 if (when == SUBMIT)
336 dev_info(&udev->dev, "ep%d %s-%s, length %u, "
337 "timeout %d\n",
338 ep, t, d, length, timeout_or_status);
339 else
340 dev_info(&udev->dev, "ep%d %s-%s, actual_length %u, "
341 "status %d\n",
342 ep, t, d, length, timeout_or_status);
343 }
322} 344}
323 345
324static void async_completed(struct urb *urb) 346static void async_completed(struct urb *urb)
@@ -347,7 +369,8 @@ static void async_completed(struct urb *urb)
347 secid = as->secid; 369 secid = as->secid;
348 } 370 }
349 snoop(&urb->dev->dev, "urb complete\n"); 371 snoop(&urb->dev->dev, "urb complete\n");
350 snoop_urb(urb, as->userurb); 372 snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length,
373 as->status, COMPLETE);
351 spin_unlock(&ps->lock); 374 spin_unlock(&ps->lock);
352 375
353 if (signr) 376 if (signr)
@@ -690,7 +713,7 @@ static int proc_control(struct dev_state *ps, void __user *arg)
690 unsigned int tmo; 713 unsigned int tmo;
691 unsigned char *tbuf; 714 unsigned char *tbuf;
692 unsigned wLength; 715 unsigned wLength;
693 int i, j, ret; 716 int i, pipe, ret;
694 717
695 if (copy_from_user(&ctrl, arg, sizeof(ctrl))) 718 if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
696 return -EFAULT; 719 return -EFAULT;
@@ -710,24 +733,17 @@ static int proc_control(struct dev_state *ps, void __user *arg)
710 free_page((unsigned long)tbuf); 733 free_page((unsigned long)tbuf);
711 return -EINVAL; 734 return -EINVAL;
712 } 735 }
713 snoop(&dev->dev, "control read: bRequest=%02x " 736 pipe = usb_rcvctrlpipe(dev, 0);
714 "bRrequestType=%02x wValue=%04x " 737 snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT);
715 "wIndex=%04x wLength=%04x\n",
716 ctrl.bRequest, ctrl.bRequestType, ctrl.wValue,
717 ctrl.wIndex, ctrl.wLength);
718 738
719 usb_unlock_device(dev); 739 usb_unlock_device(dev);
720 i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest, 740 i = usb_control_msg(dev, pipe, ctrl.bRequest,
721 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, 741 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex,
722 tbuf, ctrl.wLength, tmo); 742 tbuf, ctrl.wLength, tmo);
723 usb_lock_device(dev); 743 usb_lock_device(dev);
744 snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE);
745
724 if ((i > 0) && ctrl.wLength) { 746 if ((i > 0) && ctrl.wLength) {
725 if (usbfs_snoop) {
726 dev_info(&dev->dev, "control read: data ");
727 for (j = 0; j < i; ++j)
728 printk("%02x ", (u8)(tbuf)[j]);
729 printk("\n");
730 }
731 if (copy_to_user(ctrl.data, tbuf, i)) { 747 if (copy_to_user(ctrl.data, tbuf, i)) {
732 free_page((unsigned long)tbuf); 748 free_page((unsigned long)tbuf);
733 return -EFAULT; 749 return -EFAULT;
@@ -740,22 +756,15 @@ static int proc_control(struct dev_state *ps, void __user *arg)
740 return -EFAULT; 756 return -EFAULT;
741 } 757 }
742 } 758 }
743 snoop(&dev->dev, "control write: bRequest=%02x " 759 pipe = usb_sndctrlpipe(dev, 0);
744 "bRrequestType=%02x wValue=%04x " 760 snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT);
745 "wIndex=%04x wLength=%04x\n", 761
746 ctrl.bRequest, ctrl.bRequestType, ctrl.wValue,
747 ctrl.wIndex, ctrl.wLength);
748 if (usbfs_snoop) {
749 dev_info(&dev->dev, "control write: data: ");
750 for (j = 0; j < ctrl.wLength; ++j)
751 printk("%02x ", (unsigned char)(tbuf)[j]);
752 printk("\n");
753 }
754 usb_unlock_device(dev); 762 usb_unlock_device(dev);
755 i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, 763 i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest,
756 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, 764 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex,
757 tbuf, ctrl.wLength, tmo); 765 tbuf, ctrl.wLength, tmo);
758 usb_lock_device(dev); 766 usb_lock_device(dev);
767 snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE);
759 } 768 }
760 free_page((unsigned long)tbuf); 769 free_page((unsigned long)tbuf);
761 if (i < 0 && i != -EPIPE) { 770 if (i < 0 && i != -EPIPE) {
@@ -774,7 +783,7 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
774 unsigned int tmo, len1, pipe; 783 unsigned int tmo, len1, pipe;
775 int len2; 784 int len2;
776 unsigned char *tbuf; 785 unsigned char *tbuf;
777 int i, j, ret; 786 int i, ret;
778 787
779 if (copy_from_user(&bulk, arg, sizeof(bulk))) 788 if (copy_from_user(&bulk, arg, sizeof(bulk)))
780 return -EFAULT; 789 return -EFAULT;
@@ -801,18 +810,14 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
801 kfree(tbuf); 810 kfree(tbuf);
802 return -EINVAL; 811 return -EINVAL;
803 } 812 }
804 snoop(&dev->dev, "bulk read: len=0x%02x timeout=%04d\n", 813 snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT);
805 bulk.len, bulk.timeout); 814
806 usb_unlock_device(dev); 815 usb_unlock_device(dev);
807 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); 816 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo);
808 usb_lock_device(dev); 817 usb_lock_device(dev);
818 snoop_urb(dev, NULL, pipe, len2, i, COMPLETE);
819
809 if (!i && len2) { 820 if (!i && len2) {
810 if (usbfs_snoop) {
811 dev_info(&dev->dev, "bulk read: data ");
812 for (j = 0; j < len2; ++j)
813 printk("%02x ", (u8)(tbuf)[j]);
814 printk("\n");
815 }
816 if (copy_to_user(bulk.data, tbuf, len2)) { 821 if (copy_to_user(bulk.data, tbuf, len2)) {
817 kfree(tbuf); 822 kfree(tbuf);
818 return -EFAULT; 823 return -EFAULT;
@@ -825,17 +830,12 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
825 return -EFAULT; 830 return -EFAULT;
826 } 831 }
827 } 832 }
828 snoop(&dev->dev, "bulk write: len=0x%02x timeout=%04d\n", 833 snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT);
829 bulk.len, bulk.timeout); 834
830 if (usbfs_snoop) {
831 dev_info(&dev->dev, "bulk write: data: ");
832 for (j = 0; j < len1; ++j)
833 printk("%02x ", (unsigned char)(tbuf)[j]);
834 printk("\n");
835 }
836 usb_unlock_device(dev); 835 usb_unlock_device(dev);
837 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); 836 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo);
838 usb_lock_device(dev); 837 usb_lock_device(dev);
838 snoop_urb(dev, NULL, pipe, len2, i, COMPLETE);
839 } 839 }
840 kfree(tbuf); 840 kfree(tbuf);
841 if (i < 0) 841 if (i < 0)
@@ -1053,13 +1053,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1053 is_in = 0; 1053 is_in = 0;
1054 uurb->endpoint &= ~USB_DIR_IN; 1054 uurb->endpoint &= ~USB_DIR_IN;
1055 } 1055 }
1056 snoop(&ps->dev->dev, "control urb: bRequest=%02x "
1057 "bRrequestType=%02x wValue=%04x "
1058 "wIndex=%04x wLength=%04x\n",
1059 dr->bRequest, dr->bRequestType,
1060 __le16_to_cpup(&dr->wValue),
1061 __le16_to_cpup(&dr->wIndex),
1062 __le16_to_cpup(&dr->wLength));
1063 break; 1056 break;
1064 1057
1065 case USBDEVFS_URB_TYPE_BULK: 1058 case USBDEVFS_URB_TYPE_BULK:
@@ -1072,7 +1065,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1072 uurb->number_of_packets = 0; 1065 uurb->number_of_packets = 0;
1073 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) 1066 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE)
1074 return -EINVAL; 1067 return -EINVAL;
1075 snoop(&ps->dev->dev, "bulk urb\n");
1076 break; 1068 break;
1077 1069
1078 case USBDEVFS_URB_TYPE_ISO: 1070 case USBDEVFS_URB_TYPE_ISO:
@@ -1104,7 +1096,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1104 return -EINVAL; 1096 return -EINVAL;
1105 } 1097 }
1106 uurb->buffer_length = totlen; 1098 uurb->buffer_length = totlen;
1107 snoop(&ps->dev->dev, "iso urb\n");
1108 break; 1099 break;
1109 1100
1110 case USBDEVFS_URB_TYPE_INTERRUPT: 1101 case USBDEVFS_URB_TYPE_INTERRUPT:
@@ -1113,7 +1104,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1113 return -EINVAL; 1104 return -EINVAL;
1114 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) 1105 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE)
1115 return -EINVAL; 1106 return -EINVAL;
1116 snoop(&ps->dev->dev, "interrupt urb\n");
1117 break; 1107 break;
1118 1108
1119 default: 1109 default:
@@ -1200,11 +1190,14 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1200 return -EFAULT; 1190 return -EFAULT;
1201 } 1191 }
1202 } 1192 }
1203 snoop_urb(as->urb, as->userurb); 1193 snoop_urb(ps->dev, as->userurb, as->urb->pipe,
1194 as->urb->transfer_buffer_length, 0, SUBMIT);
1204 async_newpending(as); 1195 async_newpending(as);
1205 if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) { 1196 if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) {
1206 dev_printk(KERN_DEBUG, &ps->dev->dev, 1197 dev_printk(KERN_DEBUG, &ps->dev->dev,
1207 "usbfs: usb_submit_urb returned %d\n", ret); 1198 "usbfs: usb_submit_urb returned %d\n", ret);
1199 snoop_urb(ps->dev, as->userurb, as->urb->pipe,
1200 0, ret, COMPLETE);
1208 async_removepending(as); 1201 async_removepending(as);
1209 free_async(as); 1202 free_async(as);
1210 return ret; 1203 return ret;
@@ -1670,7 +1663,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file,
1670 break; 1663 break;
1671 1664
1672 case USBDEVFS_REAPURBNDELAY32: 1665 case USBDEVFS_REAPURBNDELAY32:
1673 snoop(&dev->dev, "%s: REAPURBDELAY32\n", __func__); 1666 snoop(&dev->dev, "%s: REAPURBNDELAY32\n", __func__);
1674 ret = proc_reapurbnonblock_compat(ps, p); 1667 ret = proc_reapurbnonblock_compat(ps, p);
1675 break; 1668 break;
1676 1669
@@ -1691,7 +1684,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file,
1691 break; 1684 break;
1692 1685
1693 case USBDEVFS_REAPURBNDELAY: 1686 case USBDEVFS_REAPURBNDELAY:
1694 snoop(&dev->dev, "%s: REAPURBDELAY\n", __func__); 1687 snoop(&dev->dev, "%s: REAPURBNDELAY\n", __func__);
1695 ret = proc_reapurbnonblock(ps, p); 1688 ret = proc_reapurbnonblock(ps, p);
1696 break; 1689 break;
1697 1690