View | Details | Raw Unified | Return to bug 4916 | Differences between
and this patch

Collapse All | Expand All

(-)linux-2.6.15/drivers/usb/input/hid-core.c (-21 / +132 lines)
Lines 911-916 static int hid_input_report(int type, st Link Here
911
}
911
}
912
912
913
/*
913
/*
914
 * Input submission and I/O error handler.
915
 */
916
917
static void hid_io_error(struct hid_device *hid);
918
919
/* Start up the input URB */
920
static int hid_start_in(struct hid_device *hid)
921
{
922
	unsigned long flags;
923
	int rc = 0;
924
925
	spin_lock_irqsave(&hid->inlock, flags);
926
	if (hid->open > 0 && !test_bit(HID_SUSPENDED, &hid->iofl) &&
927
			!test_and_set_bit(HID_IN_RUNNING, &hid->iofl)) {
928
		rc = usb_submit_urb(hid->urbin, GFP_ATOMIC);
929
		if (rc != 0)
930
			clear_bit(HID_IN_RUNNING, &hid->iofl);
931
	}
932
	spin_unlock_irqrestore(&hid->inlock, flags);
933
	return rc;
934
}
935
936
/* I/O retry timer routine */
937
static void hid_retry_timeout(unsigned long _hid)
938
{
939
	struct hid_device *hid = (struct hid_device *) _hid;
940
941
	dev_dbg(&hid->intf->dev, "retrying intr urb\n");
942
	if (hid_start_in(hid))
943
		hid_io_error(hid);
944
}
945
946
/* Workqueue routine to reset the device */
947
static void hid_reset(void *_hid)
948
{
949
	struct hid_device *hid = (struct hid_device *) _hid;
950
	int rc_lock, rc;
951
952
	dev_dbg(&hid->intf->dev, "resetting device\n");
953
	rc = rc_lock = usb_lock_device_for_reset(hid->dev, hid->intf);
954
	if (rc_lock >= 0) {
955
		rc = usb_reset_device(hid->dev);
956
		if (rc_lock)
957
			usb_unlock_device(hid->dev);
958
	}
959
	clear_bit(HID_RESET_PENDING, &hid->iofl);
960
961
	if (rc == 0) {
962
		hid->retry_delay = 0;
963
		if (hid_start_in(hid))
964
			hid_io_error(hid);
965
	} else if (!(rc == -ENODEV || rc == -EHOSTUNREACH || rc == -EINTR))
966
		err("can't reset device, %s-%s/input%d, status %d",
967
				hid->dev->bus->bus_name,
968
				hid->dev->devpath,
969
				hid->ifnum, rc);
970
}
971
972
/* Main I/O error handler */
973
static void hid_io_error(struct hid_device *hid)
974
{
975
	unsigned long flags;
976
977
	spin_lock_irqsave(&hid->inlock, flags);
978
979
	/* Stop when disconnected */
980
	if (usb_get_intfdata(hid->intf) == NULL)
981
		goto done;
982
983
	/* When an error occurs, retry at increasing intervals */
984
	if (hid->retry_delay == 0) {
985
		hid->retry_delay = 13;	/* Then 26, 52, 104, 104, ... */
986
		hid->stop_retry = jiffies + msecs_to_jiffies(1000);
987
	} else if (hid->retry_delay < 100)
988
		hid->retry_delay *= 2;
989
990
	if (time_after(jiffies, hid->stop_retry)) {
991
992
		/* Retries failed, so do a port reset */
993
		if (!test_and_set_bit(HID_RESET_PENDING, &hid->iofl)) {
994
			if (schedule_work(&hid->reset_work))
995
				goto done;
996
			clear_bit(HID_RESET_PENDING, &hid->iofl);
997
		}
998
	}
999
1000
	mod_timer(&hid->io_retry,
1001
			jiffies + msecs_to_jiffies(hid->retry_delay));
1002
done:
1003
	spin_unlock_irqrestore(&hid->inlock, flags);
1004
}
1005
1006
/*
914
 * Input interrupt completion handler.
1007
 * Input interrupt completion handler.
915
 */
1008
 */
916
1009
Lines 921-945 static void hid_irq_in(struct urb *urb, Link Here
921
1014
922
	switch (urb->status) {
1015
	switch (urb->status) {
923
		case 0:			/* success */
1016
		case 0:			/* success */
1017
			hid->retry_delay = 0;
924
			hid_input_report(HID_INPUT_REPORT, urb, 1, regs);
1018
			hid_input_report(HID_INPUT_REPORT, urb, 1, regs);
925
			break;
1019
			break;
926
		case -ECONNRESET:	/* unlink */
1020
		case -ECONNRESET:	/* unlink */
927
		case -ENOENT:
1021
		case -ENOENT:
928
		case -EPERM:
929
		case -ESHUTDOWN:	/* unplug */
1022
		case -ESHUTDOWN:	/* unplug */
930
		case -EILSEQ:		/* unplug timeout on uhci */
1023
			clear_bit(HID_IN_RUNNING, &hid->iofl);
931
			return;
1024
			return;
1025
		case -EILSEQ:		/* protocol error or unplug */
1026
		case -EPROTO:		/* protocol error or unplug */
932
		case -ETIMEDOUT:	/* NAK */
1027
		case -ETIMEDOUT:	/* NAK */
933
			break;
1028
			clear_bit(HID_IN_RUNNING, &hid->iofl);
1029
			hid_io_error(hid);
1030
			return;
934
		default:		/* error */
1031
		default:		/* error */
935
			warn("input irq status %d received", urb->status);
1032
			warn("input irq status %d received", urb->status);
936
	}
1033
	}
937
1034
938
	status = usb_submit_urb(urb, SLAB_ATOMIC);
1035
	status = usb_submit_urb(urb, SLAB_ATOMIC);
939
	if (status)
1036
	if (status) {
940
		err("can't resubmit intr, %s-%s/input%d, status %d",
1037
		clear_bit(HID_IN_RUNNING, &hid->iofl);
941
				hid->dev->bus->bus_name, hid->dev->devpath,
1038
		if (status != -EPERM) {
942
				hid->ifnum, status);
1039
			err("can't resubmit intr, %s-%s/input%d, status %d",
1040
					hid->dev->bus->bus_name,
1041
					hid->dev->devpath,
1042
					hid->ifnum, status);
1043
			hid_io_error(hid);
1044
		}
1045
	}
943
}
1046
}
944
1047
945
/*
1048
/*
Lines 1101-1108 static void hid_irq_out(struct urb *urb, Link Here
1101
		case 0:			/* success */
1204
		case 0:			/* success */
1102
			break;
1205
			break;
1103
		case -ESHUTDOWN:	/* unplug */
1206
		case -ESHUTDOWN:	/* unplug */
1104
		case -EILSEQ:		/* unplug timeout on uhci */
1105
			unplug = 1;
1207
			unplug = 1;
1208
		case -EILSEQ:		/* protocol error or unplug */
1209
		case -EPROTO:		/* protocol error or unplug */
1106
		case -ECONNRESET:	/* unlink */
1210
		case -ECONNRESET:	/* unlink */
1107
		case -ENOENT:
1211
		case -ENOENT:
1108
			break;
1212
			break;
Lines 1149-1156 static void hid_ctrl(struct urb *urb, st Link Here
1149
				hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0, regs);
1253
				hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0, regs);
1150
			break;
1254
			break;
1151
		case -ESHUTDOWN:	/* unplug */
1255
		case -ESHUTDOWN:	/* unplug */
1152
		case -EILSEQ:		/* unplug timectrl on uhci */
1153
			unplug = 1;
1256
			unplug = 1;
1257
		case -EILSEQ:		/* protocol error or unplug */
1258
		case -EPROTO:		/* protocol error or unplug */
1154
		case -ECONNRESET:	/* unlink */
1259
		case -ECONNRESET:	/* unlink */
1155
		case -ENOENT:
1260
		case -ENOENT:
1156
		case -EPIPE:		/* report not available */
1261
		case -EPIPE:		/* report not available */
Lines 1263-1276 static int hid_get_class_descriptor(stru Link Here
1263
1368
1264
int hid_open(struct hid_device *hid)
1369
int hid_open(struct hid_device *hid)
1265
{
1370
{
1266
	if (hid->open++)
1371
	++hid->open;
1267
		return 0;
1372
	if (hid_start_in(hid))
1268
1373
		hid_io_error(hid);
1269
	hid->urbin->dev = hid->dev;
1270
1271
	if (usb_submit_urb(hid->urbin, GFP_KERNEL))
1272
		return -EIO;
1273
1274
	return 0;
1374
	return 0;
1275
}
1375
}
1276
1376
Lines 1753-1758 static struct hid_device *usb_hid_config Link Here
1753
1853
1754
	init_waitqueue_head(&hid->wait);
1854
	init_waitqueue_head(&hid->wait);
1755
1855
1856
	INIT_WORK(&hid->reset_work, hid_reset, hid);
1857
	setup_timer(&hid->io_retry, hid_retry_timeout, (unsigned long) hid);
1858
1859
	spin_lock_init(&hid->inlock);
1756
	spin_lock_init(&hid->outlock);
1860
	spin_lock_init(&hid->outlock);
1757
	spin_lock_init(&hid->ctrllock);
1861
	spin_lock_init(&hid->ctrllock);
1758
1862
Lines 1824-1834 static void hid_disconnect(struct usb_in Link Here
1824
	if (!hid)
1928
	if (!hid)
1825
		return;
1929
		return;
1826
1930
1931
	spin_lock_irq(&hid->inlock);	/* Sync with error handler */
1827
	usb_set_intfdata(intf, NULL);
1932
	usb_set_intfdata(intf, NULL);
1933
	spin_unlock_irq(&hid->inlock);
1828
	usb_kill_urb(hid->urbin);
1934
	usb_kill_urb(hid->urbin);
1829
	usb_kill_urb(hid->urbout);
1935
	usb_kill_urb(hid->urbout);
1830
	usb_kill_urb(hid->urbctrl);
1936
	usb_kill_urb(hid->urbctrl);
1831
1937
1938
	del_timer_sync(&hid->io_retry);
1939
	flush_scheduled_work();
1940
1832
	if (hid->claimed & HID_CLAIMED_INPUT)
1941
	if (hid->claimed & HID_CLAIMED_INPUT)
1833
		hidinput_disconnect(hid);
1942
		hidinput_disconnect(hid);
1834
	if (hid->claimed & HID_CLAIMED_HIDDEV)
1943
	if (hid->claimed & HID_CLAIMED_HIDDEV)
Lines 1903-1908 static int hid_suspend(struct usb_interf Link Here
1903
{
2012
{
1904
	struct hid_device *hid = usb_get_intfdata (intf);
2013
	struct hid_device *hid = usb_get_intfdata (intf);
1905
2014
2015
	spin_lock_irq(&hid->inlock);	/* Sync with error handler */
2016
	set_bit(HID_SUSPENDED, &hid->iofl);
2017
	spin_unlock_irq(&hid->inlock);
2018
	del_timer(&hid->io_retry);
1906
	usb_kill_urb(hid->urbin);
2019
	usb_kill_urb(hid->urbin);
1907
	dev_dbg(&intf->dev, "suspend\n");
2020
	dev_dbg(&intf->dev, "suspend\n");
1908
	return 0;
2021
	return 0;
Lines 1913-1922 static int hid_resume(struct usb_interfa Link Here
1913
	struct hid_device *hid = usb_get_intfdata (intf);
2026
	struct hid_device *hid = usb_get_intfdata (intf);
1914
	int status;
2027
	int status;
1915
2028
1916
	if (hid->open)
2029
	clear_bit(HID_SUSPENDED, &hid->iofl);
1917
		status = usb_submit_urb(hid->urbin, GFP_NOIO);
2030
	status = hid_start_in(hid);
1918
	else
1919
		status = 0;
1920
	dev_dbg(&intf->dev, "resume status %d\n", status);
2031
	dev_dbg(&intf->dev, "resume status %d\n", status);
1921
	return status;
2032
	return status;
1922
}
2033
}
(-)linux-2.6.15/drivers/usb/input/hid.h (+10 lines)
Lines 31-36 Link Here
31
#include <linux/types.h>
31
#include <linux/types.h>
32
#include <linux/slab.h>
32
#include <linux/slab.h>
33
#include <linux/list.h>
33
#include <linux/list.h>
34
#include <linux/timer.h>
35
#include <linux/workqueue.h>
34
36
35
/*
37
/*
36
 * USB HID (Human Interface Device) interface class code
38
 * USB HID (Human Interface Device) interface class code
Lines 367-372 struct hid_control_fifo { Link Here
367
369
368
#define HID_CTRL_RUNNING	1
370
#define HID_CTRL_RUNNING	1
369
#define HID_OUT_RUNNING		2
371
#define HID_OUT_RUNNING		2
372
#define HID_IN_RUNNING		3
373
#define HID_RESET_PENDING	4
374
#define HID_SUSPENDED		5
370
375
371
struct hid_input {
376
struct hid_input {
372
	struct list_head list;
377
	struct list_head list;
Lines 390-401 struct hid_device { /* device repo Link Here
390
	int ifnum;							/* USB interface number */
395
	int ifnum;							/* USB interface number */
391
396
392
	unsigned long iofl;						/* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
397
	unsigned long iofl;						/* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
398
	struct timer_list io_retry;					/* Retry timer */
399
	unsigned long stop_retry;					/* Time to give up, in jiffies */
400
	unsigned int retry_delay;					/* Delay length in ms */
401
	struct work_struct reset_work;					/* Task context for resets */
393
402
394
	unsigned int bufsize;						/* URB buffer size */
403
	unsigned int bufsize;						/* URB buffer size */
395
404
396
	struct urb *urbin;						/* Input URB */
405
	struct urb *urbin;						/* Input URB */
397
	char *inbuf;							/* Input buffer */
406
	char *inbuf;							/* Input buffer */
398
	dma_addr_t inbuf_dma;						/* Input buffer dma */
407
	dma_addr_t inbuf_dma;						/* Input buffer dma */
408
	spinlock_t inlock;						/* Input fifo spinlock */
399
409
400
	struct urb *urbctrl;						/* Control URB */
410
	struct urb *urbctrl;						/* Control URB */
401
	struct usb_ctrlrequest *cr;					/* Control request struct */
411
	struct usb_ctrlrequest *cr;					/* Control request struct */

Return to bug 4916