Commit 15157c506d742b6767edcd486d6c73ea907fb7cf
Committed by
Mauro Carvalho Chehab
1 parent
7330f7c157
Exists in
master
and in
6 other branches
[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>
Showing 1 changed file with 50 additions and 11 deletions Side-by-side Diff
drivers/media/dvb/dvb-usb/it913x.c
... | ... | @@ -67,23 +67,43 @@ |
67 | 67 | |
68 | 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 | 74 | static int it913x_bulk_write(struct usb_device *dev, |
71 | 75 | u8 *snd, int len, u8 pipe) |
72 | 76 | { |
73 | - int ret, actual_l; | |
77 | + int ret, actual_l, i; | |
74 | 78 | |
75 | - ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe), | |
76 | - snd, len , &actual_l, 100); | |
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; | |
88 | + | |
77 | 89 | return ret; |
78 | 90 | } |
79 | 91 | |
80 | 92 | static int it913x_bulk_read(struct usb_device *dev, |
81 | 93 | u8 *rev, int len, u8 pipe) |
82 | 94 | { |
83 | - int ret, actual_l; | |
95 | + int ret, actual_l, i; | |
84 | 96 | |
85 | - ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe), | |
86 | - rev, len , &actual_l, 200); | |
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; | |
106 | + | |
87 | 107 | return ret; |
88 | 108 | } |
89 | 109 | |
... | ... | @@ -96,7 +116,7 @@ |
96 | 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 | 120 | u8 cmd, u32 reg, u8 addr, u8 *data, u8 len) |
101 | 121 | { |
102 | 122 | int ret = 0, i, buf_size = 1; |
103 | 123 | |
104 | 124 | |
105 | 125 | |
106 | 126 | |
107 | 127 | |
... | ... | @@ -155,22 +175,41 @@ |
155 | 175 | buff[buf_size++] = (chk_sum & 0xff); |
156 | 176 | |
157 | 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 | 182 | 5 : len + 5 , 0x01); |
183 | + if (ret < 0) | |
184 | + goto error; | |
161 | 185 | |
162 | 186 | rlen = (mode & 0x1) ? 0x1 : len; |
163 | 187 | |
164 | 188 | if (mode & 1) |
165 | - ret |= buff[2]; | |
189 | + ret = buff[2]; | |
166 | 190 | else |
167 | 191 | memcpy(data, &buff[3], rlen); |
168 | 192 | |
169 | 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 | 215 | static int it913x_wr_reg(struct usb_device *udev, u8 pro, u32 reg , u8 data) |