diff options
author | Malcolm Priestley <tvboxspy@gmail.com> | 2011-12-01 15:35:48 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-12-11 06:12:21 -0500 |
commit | 15157c506d742b6767edcd486d6c73ea907fb7cf (patch) | |
tree | 3667eba5c03228a925e9a716e6ad1fba6eb41314 | |
parent | 7330f7c157308166c507da9b9926107d85f960d3 (diff) |
[media] it913x add retry to USB bulk endpoints and IO
This a bus repeater for it913x devices. Commands usually fail because of other
activity on the USB bus.
Bulk failures that report -ETIMEDOUT or -EBUSY are repeated.
Enpoints that return actlen not equal len request -EAGAIN.
The retry is set at 10.
Signed-off-by: Malcolm Priestley <tvboxspy@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/dvb/dvb-usb/it913x.c | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/drivers/media/dvb/dvb-usb/it913x.c b/drivers/media/dvb/dvb-usb/it913x.c index d7c86c2b6a2..c43bddf692b 100644 --- a/drivers/media/dvb/dvb-usb/it913x.c +++ b/drivers/media/dvb/dvb-usb/it913x.c | |||
@@ -67,23 +67,43 @@ struct it913x_state { | |||
67 | 67 | ||
68 | struct ite_config it913x_config; | 68 | struct ite_config it913x_config; |
69 | 69 | ||
70 | #define IT913X_RETRY 10 | ||
71 | #define IT913X_SND_TIMEOUT 100 | ||
72 | #define IT913X_RCV_TIMEOUT 200 | ||
73 | |||
70 | static int it913x_bulk_write(struct usb_device *dev, | 74 | static int it913x_bulk_write(struct usb_device *dev, |
71 | u8 *snd, int len, u8 pipe) | 75 | u8 *snd, int len, u8 pipe) |
72 | { | 76 | { |
73 | int ret, actual_l; | 77 | int ret, actual_l, i; |
78 | |||
79 | for (i = 0; i < IT913X_RETRY; i++) { | ||
80 | ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe), | ||
81 | snd, len , &actual_l, IT913X_SND_TIMEOUT); | ||
82 | if (ret == 0 || ret != -EBUSY || ret != -ETIMEDOUT) | ||
83 | break; | ||
84 | } | ||
85 | |||
86 | if (len != actual_l && ret == 0) | ||
87 | ret = -EAGAIN; | ||
74 | 88 | ||
75 | ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe), | ||
76 | snd, len , &actual_l, 100); | ||
77 | return ret; | 89 | return ret; |
78 | } | 90 | } |
79 | 91 | ||
80 | static int it913x_bulk_read(struct usb_device *dev, | 92 | static int it913x_bulk_read(struct usb_device *dev, |
81 | u8 *rev, int len, u8 pipe) | 93 | u8 *rev, int len, u8 pipe) |
82 | { | 94 | { |
83 | int ret, actual_l; | 95 | int ret, actual_l, i; |
96 | |||
97 | for (i = 0; i < IT913X_RETRY; i++) { | ||
98 | ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe), | ||
99 | rev, len , &actual_l, IT913X_RCV_TIMEOUT); | ||
100 | if (ret == 0 || ret != -EBUSY || ret != -ETIMEDOUT) | ||
101 | break; | ||
102 | } | ||
103 | |||
104 | if (len != actual_l && ret == 0) | ||
105 | ret = -EAGAIN; | ||
84 | 106 | ||
85 | ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe), | ||
86 | rev, len , &actual_l, 200); | ||
87 | return ret; | 107 | return ret; |
88 | } | 108 | } |
89 | 109 | ||
@@ -96,7 +116,7 @@ static u16 check_sum(u8 *p, u8 len) | |||
96 | return ~sum; | 116 | return ~sum; |
97 | } | 117 | } |
98 | 118 | ||
99 | static int it913x_io(struct usb_device *udev, u8 mode, u8 pro, | 119 | static int it913x_usb_talk(struct usb_device *udev, u8 mode, u8 pro, |
100 | u8 cmd, u32 reg, u8 addr, u8 *data, u8 len) | 120 | u8 cmd, u32 reg, u8 addr, u8 *data, u8 len) |
101 | { | 121 | { |
102 | int ret = 0, i, buf_size = 1; | 122 | int ret = 0, i, buf_size = 1; |
@@ -155,22 +175,41 @@ static int it913x_io(struct usb_device *udev, u8 mode, u8 pro, | |||
155 | buff[buf_size++] = (chk_sum & 0xff); | 175 | buff[buf_size++] = (chk_sum & 0xff); |
156 | 176 | ||
157 | ret = it913x_bulk_write(udev, buff, buf_size , 0x02); | 177 | ret = it913x_bulk_write(udev, buff, buf_size , 0x02); |
178 | if (ret < 0) | ||
179 | goto error; | ||
158 | 180 | ||
159 | ret |= it913x_bulk_read(udev, buff, (mode & 1) ? | 181 | ret = it913x_bulk_read(udev, buff, (mode & 1) ? |
160 | 5 : len + 5 , 0x01); | 182 | 5 : len + 5 , 0x01); |
183 | if (ret < 0) | ||
184 | goto error; | ||
161 | 185 | ||
162 | rlen = (mode & 0x1) ? 0x1 : len; | 186 | rlen = (mode & 0x1) ? 0x1 : len; |
163 | 187 | ||
164 | if (mode & 1) | 188 | if (mode & 1) |
165 | ret |= buff[2]; | 189 | ret = buff[2]; |
166 | else | 190 | else |
167 | memcpy(data, &buff[3], rlen); | 191 | memcpy(data, &buff[3], rlen); |
168 | 192 | ||
169 | cmd_counter++; | 193 | cmd_counter++; |
170 | 194 | ||
171 | kfree(buff); | 195 | error: kfree(buff); |
172 | 196 | ||
173 | return (ret < 0) ? -ENODEV : 0; | 197 | return ret; |
198 | } | ||
199 | |||
200 | static int it913x_io(struct usb_device *udev, u8 mode, u8 pro, | ||
201 | u8 cmd, u32 reg, u8 addr, u8 *data, u8 len) | ||
202 | { | ||
203 | int ret, i; | ||
204 | |||
205 | for (i = 0; i < IT913X_RETRY; i++) { | ||
206 | ret = it913x_usb_talk(udev, mode, pro, | ||
207 | cmd, reg, addr, data, len); | ||
208 | if (ret != -EAGAIN) | ||
209 | break; | ||
210 | } | ||
211 | |||
212 | return ret; | ||
174 | } | 213 | } |
175 | 214 | ||
176 | static int it913x_wr_reg(struct usb_device *udev, u8 pro, u32 reg , u8 data) | 215 | static int it913x_wr_reg(struct usb_device *udev, u8 pro, u32 reg , u8 data) |