]>
Commit | Line | Data |
---|---|---|
c5d96f5a | 1 | --- linux-2.4.19.old/drivers/net/irda/irda-usb.c Sat Aug 3 02:39:44 2002 |
2 | +++ linux-2.4.19/drivers/net/irda/irda-usb.c Mon Nov 25 12:26:36 2002 | |
3 | @@ -45,6 +45,8 @@ | |
4 | * Amongst the reasons : | |
5 | * o uhci doesn't implement USB_ZERO_PACKET | |
6 | * o uhci non-compliant use of urb->timeout | |
7 | + * The final fix for USB_ZERO_PACKET in uhci is likely to be in 2.4.19 and | |
8 | + * 2.5.8. With this fix, the driver will work properly. More on that later. | |
9 | * | |
10 | * Jean II | |
11 | */ | |
12 | @@ -112,9 +114,9 @@ | |
13 | static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *dev); | |
14 | static int irda_usb_open(struct irda_usb_cb *self); | |
15 | static int irda_usb_close(struct irda_usb_cb *self); | |
16 | -static void speed_bulk_callback(purb_t purb); | |
17 | -static void write_bulk_callback(purb_t purb); | |
18 | -static void irda_usb_receive(purb_t purb); | |
19 | +static void speed_bulk_callback(struct urb *urb); | |
20 | +static void write_bulk_callback(struct urb *urb); | |
21 | +static void irda_usb_receive(struct urb *urb); | |
22 | static int irda_usb_net_init(struct net_device *dev); | |
23 | static int irda_usb_net_open(struct net_device *dev); | |
24 | static int irda_usb_net_close(struct net_device *dev); | |
25 | @@ -158,12 +160,12 @@ | |
26 | (!force) && (self->speed != -1)) { | |
27 | /* No speed and xbofs change here | |
28 | * (we'll do it later in the write callback) */ | |
29 | - IRDA_DEBUG(2, __FUNCTION__ "(), not changing speed yet\n"); | |
30 | + IRDA_DEBUG(2, "%s(), not changing speed yet\n", __FUNCTION__); | |
31 | *header = 0; | |
32 | return; | |
33 | } | |
34 | ||
35 | - IRDA_DEBUG(2, __FUNCTION__ "(), changing speed to %d\n", self->new_speed); | |
36 | + IRDA_DEBUG(2, "%s(), changing speed to %d\n", __FUNCTION__, self->new_speed); | |
37 | self->speed = self->new_speed; | |
38 | self->new_speed = -1; | |
39 | ||
40 | @@ -204,7 +206,7 @@ | |
41 | ||
42 | /* Set the negotiated additional XBOFS */ | |
43 | if (self->new_xbofs != -1) { | |
44 | - IRDA_DEBUG(2, __FUNCTION__ "(), changing xbofs to %d\n", self->new_xbofs); | |
45 | + IRDA_DEBUG(2, "%s(), changing xbofs to %d\n", __FUNCTION__, self->new_xbofs); | |
46 | self->xbofs = self->new_xbofs; | |
47 | self->new_xbofs = -1; | |
48 | ||
49 | @@ -243,26 +245,24 @@ | |
50 | /*------------------------------------------------------------------*/ | |
51 | /* | |
52 | * Send a command to change the speed of the dongle | |
53 | + * Need to be called with spinlock on. | |
54 | */ | |
55 | static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self) | |
56 | { | |
57 | - unsigned long flags; | |
58 | __u8 *frame; | |
59 | - purb_t purb; | |
60 | int ret; | |
61 | + struct urb *purb; | |
62 | ||
63 | - IRDA_DEBUG(2, __FUNCTION__ "(), speed=%d, xbofs=%d\n", | |
64 | - self->new_speed, self->new_xbofs); | |
65 | + IRDA_DEBUG(2, "%s(), speed=%d, xbofs=%d\n", | |
66 | + __FUNCTION__, self->new_speed, self->new_xbofs); | |
67 | ||
68 | /* Grab the speed URB */ | |
69 | purb = &self->speed_urb; | |
70 | if (purb->status != USB_ST_NOERROR) { | |
71 | - WARNING(__FUNCTION__ "(), URB still in use!\n"); | |
72 | + WARNING("%s(), URB still in use!\n", __FUNCTION__); | |
73 | return; | |
74 | } | |
75 | ||
76 | - spin_lock_irqsave(&self->lock, flags); | |
77 | - | |
78 | /* Allocate the fake frame */ | |
79 | frame = self->speed_buff; | |
80 | ||
81 | @@ -279,31 +279,30 @@ | |
82 | purb->timeout = MSECS_TO_JIFFIES(100); | |
83 | ||
84 | if ((ret = usb_submit_urb(purb))) { | |
85 | - WARNING(__FUNCTION__ "(), failed Speed URB\n"); | |
86 | + WARNING("%s(), failed Speed URB\n", __FUNCTION__); | |
87 | } | |
88 | - spin_unlock_irqrestore(&self->lock, flags); | |
89 | } | |
90 | ||
91 | /*------------------------------------------------------------------*/ | |
92 | /* | |
93 | * Note : this function will be called with both speed_urb and empty_urb... | |
94 | */ | |
95 | -static void speed_bulk_callback(purb_t purb) | |
96 | +static void speed_bulk_callback(struct urb *purb) | |
97 | { | |
98 | struct irda_usb_cb *self = purb->context; | |
99 | ||
100 | - IRDA_DEBUG(2, __FUNCTION__ "()\n"); | |
101 | + IRDA_DEBUG(2, "%s()\n", __FUNCTION__); | |
102 | ||
103 | /* We should always have a context */ | |
104 | if (self == NULL) { | |
105 | - WARNING(__FUNCTION__ "(), Bug : self == NULL\n"); | |
106 | + WARNING("%s(), Bug : self == NULL\n", __FUNCTION__); | |
107 | return; | |
108 | } | |
109 | ||
110 | /* Check for timeout and other USB nasties */ | |
111 | if(purb->status != USB_ST_NOERROR) { | |
112 | /* I get a lot of -ECONNABORTED = -103 here - Jean II */ | |
113 | - IRDA_DEBUG(0, __FUNCTION__ "(), URB complete status %d, transfer_flags 0x%04X\n", purb->status, purb->transfer_flags); | |
114 | + IRDA_DEBUG(0, "%s(), URB complete status %d, transfer_flags 0x%04X\n", __FUNCTION__, purb->status, purb->transfer_flags); | |
115 | ||
116 | /* Don't do anything here, that might confuse the USB layer. | |
117 | * Instead, we will wait for irda_usb_net_timeout(), the | |
118 | @@ -329,20 +328,26 @@ | |
119 | static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev) | |
120 | { | |
121 | struct irda_usb_cb *self = netdev->priv; | |
122 | - purb_t purb = &self->tx_urb; | |
123 | + struct urb *purb = &self->tx_urb; | |
124 | unsigned long flags; | |
125 | s32 speed; | |
126 | s16 xbofs; | |
127 | int res, mtt; | |
128 | ||
129 | - /* Check if the device is still there */ | |
130 | + netif_stop_queue(netdev); | |
131 | + | |
132 | + /* Protect us from USB callbacks, net watchdog and else. */ | |
133 | + spin_lock_irqsave(&self->lock, flags); | |
134 | + | |
135 | + /* Check if the device is still there. | |
136 | + * We need to check self->present under the spinlock because | |
137 | + * of irda_usb_disconnect() is synchronous - Jean II */ | |
138 | if ((!self) || (!self->present)) { | |
139 | - IRDA_DEBUG(0, __FUNCTION__ "(), Device is gone...\n"); | |
140 | + IRDA_DEBUG(0, "%s(), Device is gone...\n", __FUNCTION__); | |
141 | + spin_unlock_irqrestore(&self->lock, flags); | |
142 | return 1; /* Failed */ | |
143 | } | |
144 | ||
145 | - netif_stop_queue(netdev); | |
146 | - | |
147 | /* Check if we need to change the number of xbofs */ | |
148 | xbofs = irda_get_next_xbofs(skb); | |
149 | if ((xbofs != self->xbofs) && (xbofs != -1)) { | |
150 | @@ -366,16 +371,14 @@ | |
151 | * Jean II */ | |
152 | irda_usb_change_speed_xbofs(self); | |
153 | netdev->trans_start = jiffies; | |
154 | - dev_kfree_skb(skb); | |
155 | /* Will netif_wake_queue() in callback */ | |
156 | - return 0; | |
157 | + goto drop; | |
158 | } | |
159 | } | |
160 | ||
161 | if (purb->status != USB_ST_NOERROR) { | |
162 | - WARNING(__FUNCTION__ "(), URB still in use!\n"); | |
163 | - dev_kfree_skb(skb); | |
164 | - return 0; | |
165 | + WARNING("%s(), URB still in use!\n", __FUNCTION__); | |
166 | + goto drop; | |
167 | } | |
168 | ||
169 | /* Make sure there is room for IrDA-USB header. The actual | |
170 | @@ -383,16 +386,13 @@ | |
171 | * Also, we don't use directly skb_cow(), because it require | |
172 | * headroom >= 16, which force unnecessary copies - Jean II */ | |
173 | if (skb_headroom(skb) < USB_IRDA_HEADER) { | |
174 | - IRDA_DEBUG(0, __FUNCTION__ "(), Insuficient skb headroom.\n"); | |
175 | + IRDA_DEBUG(0, "%s(), Insuficient skb headroom.\n", __FUNCTION__); | |
176 | if (skb_cow(skb, USB_IRDA_HEADER)) { | |
177 | - WARNING(__FUNCTION__ "(), failed skb_cow() !!!\n"); | |
178 | - dev_kfree_skb(skb); | |
179 | - return 0; | |
180 | + WARNING("%s(), failed skb_cow() !!!\n", __FUNCTION__); | |
181 | + goto drop; | |
182 | } | |
183 | } | |
184 | ||
185 | - spin_lock_irqsave(&self->lock, flags); | |
186 | - | |
187 | /* Change setting for next frame */ | |
188 | irda_usb_build_header(self, skb_push(skb, USB_IRDA_HEADER), 0); | |
189 | ||
190 | @@ -459,7 +459,7 @@ | |
191 | ||
192 | /* Ask USB to send the packet */ | |
193 | if ((res = usb_submit_urb(purb))) { | |
194 | - WARNING(__FUNCTION__ "(), failed Tx URB\n"); | |
195 | + WARNING("%s(), failed Tx URB\n", __FUNCTION__); | |
196 | self->stats.tx_errors++; | |
197 | /* Let USB recover : We will catch that in the watchdog */ | |
198 | /*netif_start_queue(netdev);*/ | |
199 | @@ -473,22 +473,29 @@ | |
200 | spin_unlock_irqrestore(&self->lock, flags); | |
201 | ||
202 | return 0; | |
203 | + | |
204 | +drop: | |
205 | + /* Drop silently the skb and exit */ | |
206 | + dev_kfree_skb(skb); | |
207 | + spin_unlock_irqrestore(&self->lock, flags); | |
208 | + return 0; | |
209 | } | |
210 | ||
211 | /*------------------------------------------------------------------*/ | |
212 | /* | |
213 | * Note : this function will be called only for tx_urb... | |
214 | */ | |
215 | -static void write_bulk_callback(purb_t purb) | |
216 | +static void write_bulk_callback(struct urb *purb) | |
217 | { | |
218 | + unsigned long flags; | |
219 | struct sk_buff *skb = purb->context; | |
220 | struct irda_usb_cb *self = ((struct irda_skb_cb *) skb->cb)->context; | |
221 | ||
222 | - IRDA_DEBUG(2, __FUNCTION__ "()\n"); | |
223 | + IRDA_DEBUG(2, "%s()\n", __FUNCTION__); | |
224 | ||
225 | /* We should always have a context */ | |
226 | if (self == NULL) { | |
227 | - WARNING(__FUNCTION__ "(), Bug : self == NULL\n"); | |
228 | + WARNING("%s(), Bug : self == NULL\n", __FUNCTION__); | |
229 | return; | |
230 | } | |
231 | ||
232 | @@ -499,7 +506,7 @@ | |
233 | /* Check for timeout and other USB nasties */ | |
234 | if(purb->status != USB_ST_NOERROR) { | |
235 | /* I get a lot of -ECONNABORTED = -103 here - Jean II */ | |
236 | - IRDA_DEBUG(0, __FUNCTION__ "(), URB complete status %d, transfer_flags 0x%04X\n", purb->status, purb->transfer_flags); | |
237 | + IRDA_DEBUG(0, "%s(), URB complete status %d, transfer_flags 0x%04X\n", __FUNCTION__, purb->status, purb->transfer_flags); | |
238 | ||
239 | /* Don't do anything here, that might confuse the USB layer, | |
240 | * and we could go in recursion and blow the kernel stack... | |
241 | @@ -511,22 +518,27 @@ | |
242 | } | |
243 | ||
244 | /* urb is now available */ | |
245 | - purb->status = USB_ST_NOERROR; | |
246 | + //purb->status = USB_ST_NOERROR; -> tested above | |
247 | + | |
248 | + /* Make sure we read self->present properly */ | |
249 | + spin_lock_irqsave(&self->lock, flags); | |
250 | ||
251 | /* If the network is closed, stop everything */ | |
252 | if ((!self->netopen) || (!self->present)) { | |
253 | - IRDA_DEBUG(0, __FUNCTION__ "(), Network is gone...\n"); | |
254 | + IRDA_DEBUG(0, "%s(), Network is gone...\n", __FUNCTION__); | |
255 | + spin_unlock_irqrestore(&self->lock, flags); | |
256 | return; | |
257 | } | |
258 | ||
259 | /* If we need to change the speed or xbofs, do it now */ | |
260 | if ((self->new_speed != -1) || (self->new_xbofs != -1)) { | |
261 | - IRDA_DEBUG(1, __FUNCTION__ "(), Changing speed now...\n"); | |
262 | + IRDA_DEBUG(1, "%s(), Changing speed now...\n", __FUNCTION__); | |
263 | irda_usb_change_speed_xbofs(self); | |
264 | } else { | |
265 | /* Otherwise, allow the stack to send more packets */ | |
266 | netif_wake_queue(self->netdev); | |
267 | } | |
268 | + spin_unlock_irqrestore(&self->lock, flags); | |
269 | } | |
270 | ||
271 | /*------------------------------------------------------------------*/ | |
272 | @@ -540,15 +552,20 @@ | |
273 | */ | |
274 | static void irda_usb_net_timeout(struct net_device *netdev) | |
275 | { | |
276 | + unsigned long flags; | |
277 | struct irda_usb_cb *self = netdev->priv; | |
278 | - purb_t purb; | |
279 | + struct urb *purb; | |
280 | int done = 0; /* If we have made any progress */ | |
281 | ||
282 | - IRDA_DEBUG(0, __FUNCTION__ "(), Network layer thinks we timed out!\n"); | |
283 | + IRDA_DEBUG(0, "%s(), Network layer thinks we timed out!\n", __FUNCTION__); | |
284 | + | |
285 | + /* Protect us from USB callbacks, net Tx and else. */ | |
286 | + spin_lock_irqsave(&self->lock, flags); | |
287 | ||
288 | if ((!self) || (!self->present)) { | |
289 | - WARNING(__FUNCTION__ "(), device not present!\n"); | |
290 | + WARNING("%s(), device not present!\n", __FUNCTION__); | |
291 | netif_stop_queue(netdev); | |
292 | + spin_unlock_irqrestore(&self->lock, flags); | |
293 | return; | |
294 | } | |
295 | ||
296 | @@ -623,6 +640,7 @@ | |
297 | break; | |
298 | } | |
299 | } | |
300 | + spin_unlock_irqrestore(&self->lock, flags); | |
301 | ||
302 | /* Maybe we need a reset */ | |
303 | /* Note : Some drivers seem to use a usb_set_interface() when they | |
304 | @@ -692,16 +710,16 @@ | |
305 | * | |
306 | * Jean II | |
307 | */ | |
308 | -static void irda_usb_submit(struct irda_usb_cb *self, struct sk_buff *skb, purb_t purb) | |
309 | +static void irda_usb_submit(struct irda_usb_cb *self, struct sk_buff *skb, struct urb *purb) | |
310 | { | |
311 | struct irda_skb_cb *cb; | |
312 | int ret; | |
313 | ||
314 | - IRDA_DEBUG(2, __FUNCTION__ "()\n"); | |
315 | + IRDA_DEBUG(2, "%s()\n", __FUNCTION__); | |
316 | ||
317 | /* Check that we have an urb */ | |
318 | if (!purb) { | |
319 | - WARNING(__FUNCTION__ "(), Bug : purb == NULL\n"); | |
320 | + WARNING("%s(), Bug : purb == NULL\n", __FUNCTION__); | |
321 | return; | |
322 | } | |
323 | ||
324 | @@ -711,7 +729,7 @@ | |
325 | if (!skb) { | |
326 | /* If this ever happen, we are in deep s***. | |
327 | * Basically, the Rx path will stop... */ | |
328 | - WARNING(__FUNCTION__ "(), Failed to allocate Rx skb\n"); | |
329 | + WARNING("%s(), Failed to allocate Rx skb\n", __FUNCTION__); | |
330 | return; | |
331 | } | |
332 | } else { | |
333 | @@ -741,7 +759,7 @@ | |
334 | if (ret) { | |
335 | /* If this ever happen, we are in deep s***. | |
336 | * Basically, the Rx path will stop... */ | |
337 | - WARNING(__FUNCTION__ "(), Failed to submit Rx URB %d\n", ret); | |
338 | + WARNING("%s(), Failed to submit Rx URB %d\n", __FUNCTION__, ret); | |
339 | } | |
340 | } | |
341 | ||
342 | @@ -752,14 +770,14 @@ | |
343 | * Called by the USB subsystem when a frame has been received | |
344 | * | |
345 | */ | |
346 | -static void irda_usb_receive(purb_t purb) | |
347 | +static void irda_usb_receive(struct urb *purb) | |
348 | { | |
349 | struct sk_buff *skb = (struct sk_buff *) purb->context; | |
350 | struct irda_usb_cb *self; | |
351 | struct irda_skb_cb *cb; | |
352 | struct sk_buff *new; | |
353 | ||
354 | - IRDA_DEBUG(2, __FUNCTION__ "(), len=%d\n", purb->actual_length); | |
355 | + IRDA_DEBUG(2, "%s(), len=%d\n", __FUNCTION__, purb->actual_length); | |
356 | ||
357 | /* Find ourselves */ | |
358 | cb = (struct irda_skb_cb *) skb->cb; | |
359 | @@ -769,7 +787,7 @@ | |
360 | ||
361 | /* If the network is closed or the device gone, stop everything */ | |
362 | if ((!self->netopen) || (!self->present)) { | |
363 | - IRDA_DEBUG(0, __FUNCTION__ "(), Network is gone!\n"); | |
364 | + IRDA_DEBUG(0, "%s(), Network is gone!\n", __FUNCTION__); | |
365 | /* Don't re-submit the URB : will stall the Rx path */ | |
366 | return; | |
367 | } | |
368 | @@ -782,13 +800,13 @@ | |
369 | self->stats.rx_crc_errors++; | |
370 | break; | |
371 | case -ECONNRESET: /* -104 */ | |
372 | - IRDA_DEBUG(0, __FUNCTION__ "(), Connection Reset (-104), transfer_flags 0x%04X \n", purb->transfer_flags); | |
373 | + IRDA_DEBUG(0, "%s(), Connection Reset (-104), transfer_flags 0x%04X \n", __FUNCTION__, purb->transfer_flags); | |
374 | /* uhci_cleanup_unlink() is going to kill the Rx | |
375 | * URB just after we return. No problem, at this | |
376 | * point the URB will be idle ;-) - Jean II */ | |
377 | break; | |
378 | default: | |
379 | - IRDA_DEBUG(0, __FUNCTION__ "(), RX status %d,transfer_flags 0x%04X \n", purb->status, purb->transfer_flags); | |
380 | + IRDA_DEBUG(0, "%s(), RX status %d,transfer_flags 0x%04X \n", __FUNCTION__, purb->status, purb->transfer_flags); | |
381 | break; | |
382 | } | |
383 | goto done; | |
384 | @@ -796,7 +814,7 @@ | |
385 | ||
386 | /* Check for empty frames */ | |
387 | if (purb->actual_length <= USB_IRDA_HEADER) { | |
388 | - WARNING(__FUNCTION__ "(), empty frame!\n"); | |
389 | + WARNING("%s(), empty frame!\n", __FUNCTION__); | |
390 | goto done; | |
391 | } | |
392 | ||
393 | @@ -900,7 +918,7 @@ | |
394 | */ | |
395 | static int irda_usb_net_init(struct net_device *dev) | |
396 | { | |
397 | - IRDA_DEBUG(1, __FUNCTION__ "()\n"); | |
398 | + IRDA_DEBUG(1, "%s()\n", __FUNCTION__); | |
399 | ||
400 | /* Set up to be a normal IrDA network device driver */ | |
401 | irda_device_setup(dev); | |
402 | @@ -924,7 +942,7 @@ | |
403 | char hwname[16]; | |
404 | int i; | |
405 | ||
406 | - IRDA_DEBUG(1, __FUNCTION__ "()\n"); | |
407 | + IRDA_DEBUG(1, "%s()\n", __FUNCTION__); | |
408 | ||
409 | ASSERT(netdev != NULL, return -1;); | |
410 | self = (struct irda_usb_cb *) netdev->priv; | |
411 | @@ -932,7 +950,7 @@ | |
412 | ||
413 | /* Can only open the device if it's there */ | |
414 | if(!self->present) { | |
415 | - WARNING(__FUNCTION__ "(), device not present!\n"); | |
416 | + WARNING("%s(), device not present!\n", __FUNCTION__); | |
417 | return -1; | |
418 | } | |
419 | ||
420 | @@ -988,7 +1006,7 @@ | |
421 | struct irda_usb_cb *self; | |
422 | int i; | |
423 | ||
424 | - IRDA_DEBUG(1, __FUNCTION__ "()\n"); | |
425 | + IRDA_DEBUG(1, "%s()\n", __FUNCTION__); | |
426 | ||
427 | ASSERT(netdev != NULL, return -1;); | |
428 | self = (struct irda_usb_cb *) netdev->priv; | |
429 | @@ -1003,7 +1021,7 @@ | |
430 | ||
431 | /* Deallocate all the Rx path buffers (URBs and skb) */ | |
432 | for (i = 0; i < IU_MAX_RX_URBS; i++) { | |
433 | - purb_t purb = &(self->rx_urb[i]); | |
434 | + struct urb *purb = &(self->rx_urb[i]); | |
435 | struct sk_buff *skb = (struct sk_buff *) purb->context; | |
436 | /* Cancel the receive command */ | |
437 | usb_unlink_urb(purb); | |
438 | @@ -1013,8 +1031,10 @@ | |
439 | purb->context = NULL; | |
440 | } | |
441 | } | |
442 | - /* Cancel Tx and speed URB */ | |
443 | + /* Cancel Tx and speed URB - need to be synchronous to avoid races */ | |
444 | + self->tx_urb.transfer_flags &= ~USB_ASYNC_UNLINK; | |
445 | usb_unlink_urb(&(self->tx_urb)); | |
446 | + self->speed_urb.transfer_flags &= ~USB_ASYNC_UNLINK; | |
447 | usb_unlink_urb(&(self->speed_urb)); | |
448 | ||
449 | /* Stop and remove instance of IrLAP */ | |
450 | @@ -1033,6 +1053,7 @@ | |
451 | */ | |
452 | static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | |
453 | { | |
454 | + unsigned long flags; | |
455 | struct if_irda_req *irq = (struct if_irda_req *) rq; | |
456 | struct irda_usb_cb *self; | |
457 | int ret = 0; | |
458 | @@ -1041,25 +1062,28 @@ | |
459 | self = dev->priv; | |
460 | ASSERT(self != NULL, return -1;); | |
461 | ||
462 | - IRDA_DEBUG(2, __FUNCTION__ "(), %s, (cmd=0x%X)\n", dev->name, cmd); | |
463 | - | |
464 | - /* Check if the device is still there */ | |
465 | - if(!self->present) | |
466 | - return -EFAULT; | |
467 | + IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd); | |
468 | ||
469 | switch (cmd) { | |
470 | case SIOCSBANDWIDTH: /* Set bandwidth */ | |
471 | if (!capable(CAP_NET_ADMIN)) | |
472 | return -EPERM; | |
473 | - /* Set the desired speed */ | |
474 | - self->new_speed = irq->ifr_baudrate; | |
475 | - irda_usb_change_speed_xbofs(self); | |
476 | - /* Note : will spinlock in above function */ | |
477 | + /* Protect us from USB callbacks, net watchdog and else. */ | |
478 | + spin_lock_irqsave(&self->lock, flags); | |
479 | + /* Check if the device is still there */ | |
480 | + if(self->present) { | |
481 | + /* Set the desired speed */ | |
482 | + self->new_speed = irq->ifr_baudrate; | |
483 | + irda_usb_change_speed_xbofs(self); | |
484 | + } | |
485 | + spin_unlock_irqrestore(&self->lock, flags); | |
486 | break; | |
487 | case SIOCSMEDIABUSY: /* Set media busy */ | |
488 | if (!capable(CAP_NET_ADMIN)) | |
489 | return -EPERM; | |
490 | - irda_device_set_media_busy(self->netdev, TRUE); | |
491 | + /* Check if the IrDA stack is still there */ | |
492 | + if(self->netopen) | |
493 | + irda_device_set_media_busy(self->netdev, TRUE); | |
494 | break; | |
495 | case SIOCGRECEIVING: /* Check if we are receiving right now */ | |
496 | irq->ifr_receiving = irda_usb_is_receiving(self); | |
497 | @@ -1096,7 +1120,7 @@ | |
498 | { | |
499 | struct irda_class_desc *desc; | |
500 | ||
501 | - IRDA_DEBUG(3, __FUNCTION__ "()\n"); | |
502 | + IRDA_DEBUG(3, "%s()\n", __FUNCTION__); | |
503 | ||
504 | desc = self->irda_desc; | |
505 | ||
506 | @@ -1109,7 +1133,8 @@ | |
507 | self->qos.window_size.bits = desc->bmWindowSize; | |
508 | self->qos.data_size.bits = desc->bmDataSize; | |
509 | ||
510 | - IRDA_DEBUG(0, __FUNCTION__ "(), dongle says speed=0x%X, size=0x%X, window=0x%X, bofs=0x%X, turn=0x%X\n", self->qos.baud_rate.bits, self->qos.data_size.bits, self->qos.window_size.bits, self->qos.additional_bofs.bits, self->qos.min_turn_time.bits); | |
511 | + IRDA_DEBUG(0, "%s(), dongle says speed=0x%X, size=0x%X, window=0x%X, bofs=0x%X, turn=0x%X\n", | |
512 | + __FUNCTION__, self->qos.baud_rate.bits, self->qos.data_size.bits, self->qos.window_size.bits, self->qos.additional_bofs.bits, self->qos.min_turn_time.bits); | |
513 | ||
514 | /* Don't always trust what the dongle tell us */ | |
515 | if(self->capability & IUC_SIR_ONLY) | |
516 | @@ -1153,7 +1178,7 @@ | |
517 | struct net_device *netdev; | |
518 | int err; | |
519 | ||
520 | - IRDA_DEBUG(1, __FUNCTION__ "()\n"); | |
521 | + IRDA_DEBUG(1, "%s()\n", __FUNCTION__); | |
522 | ||
523 | spin_lock_init(&self->lock); | |
524 | ||
525 | @@ -1173,7 +1198,7 @@ | |
526 | ||
527 | /* Create a network device for us */ | |
528 | if (!(netdev = dev_alloc("irda%d", &err))) { | |
529 | - ERROR(__FUNCTION__ "(), dev_alloc() failed!\n"); | |
530 | + ERROR("%s(), dev_alloc() failed!\n", __FUNCTION__); | |
531 | return -1; | |
532 | } | |
533 | self->netdev = netdev; | |
534 | @@ -1193,7 +1218,7 @@ | |
535 | err = register_netdevice(netdev); | |
536 | rtnl_unlock(); | |
537 | if (err) { | |
538 | - ERROR(__FUNCTION__ "(), register_netdev() failed!\n"); | |
539 | + ERROR("%s(), register_netdev() failed!\n", __FUNCTION__); | |
540 | return -1; | |
541 | } | |
542 | MESSAGE("IrDA: Registered device %s\n", netdev->name); | |
543 | @@ -1208,7 +1233,7 @@ | |
544 | */ | |
545 | static inline int irda_usb_close(struct irda_usb_cb *self) | |
546 | { | |
547 | - IRDA_DEBUG(1, __FUNCTION__ "()\n"); | |
548 | + IRDA_DEBUG(1, "%s()\n", __FUNCTION__); | |
549 | ||
550 | ASSERT(self != NULL, return -1;); | |
551 | ||
552 | @@ -1290,12 +1315,13 @@ | |
553 | /* This is our interrupt endpoint */ | |
554 | self->bulk_int_ep = ep; | |
555 | } else { | |
556 | - ERROR(__FUNCTION__ "(), Unrecognised endpoint %02X.\n", ep); | |
557 | + ERROR("%s(), Unrecognised endpoint %02X.\n", __FUNCTION__, ep); | |
558 | } | |
559 | } | |
560 | } | |
561 | ||
562 | - IRDA_DEBUG(0, __FUNCTION__ "(), And our endpoints are : in=%02X, out=%02X (%d), int=%02X\n", self->bulk_in_ep, self->bulk_out_ep, self->bulk_out_mtu, self->bulk_int_ep); | |
563 | + IRDA_DEBUG(0, "%s(), And our endpoints are : in=%02X, out=%02X (%d), int=%02X\n", | |
564 | + __FUNCTION__, self->bulk_in_ep, self->bulk_out_ep, self->bulk_out_mtu, self->bulk_int_ep); | |
565 | /* Should be 8, 16, 32 or 64 bytes */ | |
566 | ASSERT(self->bulk_out_mtu == 64, ;); | |
567 | ||
568 | @@ -1357,7 +1383,7 @@ | |
569 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | |
570 | 0, ifnum, desc, sizeof(*desc), MSECS_TO_JIFFIES(500)); | |
571 | ||
572 | - IRDA_DEBUG(1, __FUNCTION__ "(), ret=%d\n", ret); | |
573 | + IRDA_DEBUG(1, "%s(), ret=%d\n", __FUNCTION__, ret); | |
574 | if (ret < sizeof(*desc)) { | |
575 | WARNING("usb-irda: class_descriptor read %s (%d)\n", | |
576 | (ret<0) ? "failed" : "too short", ret); | |
577 | @@ -1409,15 +1435,14 @@ | |
578 | dev->descriptor.idProduct); | |
579 | ||
580 | /* Try to cleanup all instance that have a pending disconnect | |
581 | - * Instance will be in this state is the disconnect() occurs | |
582 | - * before the net_close(). | |
583 | + * In theory, it can't happen any longer. | |
584 | * Jean II */ | |
585 | for (i = 0; i < NIRUSB; i++) { | |
586 | struct irda_usb_cb *irda = &irda_instance[i]; | |
587 | if((irda->usbdev != NULL) && | |
588 | (irda->present == 0) && | |
589 | (irda->netopen == 0)) { | |
590 | - IRDA_DEBUG(0, __FUNCTION__ "(), found a zombie instance !!!\n"); | |
591 | + IRDA_DEBUG(0, "%s(), found a zombie instance !!!\n", __FUNCTION__); | |
592 | irda_usb_disconnect(irda->usbdev, (void *) irda); | |
593 | } | |
594 | } | |
595 | @@ -1457,10 +1482,10 @@ | |
596 | break; | |
597 | case USB_ST_STALL: /* -EPIPE = -32 */ | |
598 | usb_clear_halt(dev, usb_sndctrlpipe(dev, 0)); | |
599 | - IRDA_DEBUG(0, __FUNCTION__ "(), Clearing stall on control interface\n" ); | |
600 | + IRDA_DEBUG(0, "%s(), Clearing stall on control interface\n", __FUNCTION__); | |
601 | break; | |
602 | default: | |
603 | - IRDA_DEBUG(0, __FUNCTION__ "(), Unknown error %d\n", ret); | |
604 | + IRDA_DEBUG(0, "%s(), Unknown error %d\n", __FUNCTION__, ret); | |
605 | return NULL; | |
606 | break; | |
607 | } | |
608 | @@ -1469,7 +1494,7 @@ | |
609 | interface = &dev->actconfig->interface[ifnum].altsetting[0]; | |
610 | if(!irda_usb_parse_endpoints(self, interface->endpoint, | |
611 | interface->bNumEndpoints)) { | |
612 | - ERROR(__FUNCTION__ "(), Bogus endpoints...\n"); | |
613 | + ERROR("%s(), Bogus endpoints...\n", __FUNCTION__); | |
614 | return NULL; | |
615 | } | |
616 | ||
617 | @@ -1494,40 +1519,54 @@ | |
618 | /* | |
619 | * The current irda-usb device is removed, the USB layer tell us | |
620 | * to shut it down... | |
621 | + * One of the constraints is that when we exit this function, | |
622 | + * we cannot use the usb_device no more. Gone. Destroyed. kfree(). | |
623 | + * Most other subsystem allow you to destroy the instance at a time | |
624 | + * when it's convenient to you, to postpone it to a later date, but | |
625 | + * not the USB subsystem. | |
626 | + * So, we must make bloody sure that everything gets deactivated. | |
627 | + * Jean II | |
628 | */ | |
629 | static void irda_usb_disconnect(struct usb_device *dev, void *ptr) | |
630 | { | |
631 | + unsigned long flags; | |
632 | struct irda_usb_cb *self = (struct irda_usb_cb *) ptr; | |
633 | int i; | |
634 | ||
635 | - IRDA_DEBUG(1, __FUNCTION__ "()\n"); | |
636 | + IRDA_DEBUG(1, "%s()\n", __FUNCTION__); | |
637 | + | |
638 | + /* Make sure that the Tx path is not executing. - Jean II */ | |
639 | + spin_lock_irqsave(&self->lock, flags); | |
640 | ||
641 | - /* Oups ! We are not there any more */ | |
642 | + /* Oups ! We are not there any more. | |
643 | + * This will stop/desactivate the Tx path. - Jean II */ | |
644 | self->present = 0; | |
645 | ||
646 | - /* Hum... Check if networking is still active */ | |
647 | - if (self->netopen) { | |
648 | + /* We need to have irq enabled to unlink the URBs. That's OK, | |
649 | + * at this point the Tx path is gone - Jean II */ | |
650 | + spin_unlock_irqrestore(&self->lock, flags); | |
651 | + | |
652 | + /* Hum... Check if networking is still active (avoid races) */ | |
653 | + if((self->netopen) || (self->irlap)) { | |
654 | /* Accept no more transmissions */ | |
655 | /*netif_device_detach(self->netdev);*/ | |
656 | netif_stop_queue(self->netdev); | |
657 | /* Stop all the receive URBs */ | |
658 | for (i = 0; i < IU_MAX_RX_URBS; i++) | |
659 | usb_unlink_urb(&(self->rx_urb[i])); | |
660 | - /* Cancel Tx and speed URB */ | |
661 | + /* Cancel Tx and speed URB. | |
662 | + * Toggle flags to make sure it's synchronous. */ | |
663 | + self->tx_urb.transfer_flags &= ~USB_ASYNC_UNLINK; | |
664 | usb_unlink_urb(&(self->tx_urb)); | |
665 | + self->speed_urb.transfer_flags &= ~USB_ASYNC_UNLINK; | |
666 | usb_unlink_urb(&(self->speed_urb)); | |
667 | - | |
668 | - IRDA_DEBUG(0, __FUNCTION__ "(), postponing disconnect, network is still active...\n"); | |
669 | - /* better not do anything just yet, usb_irda_cleanup() | |
670 | - * will do whats needed */ | |
671 | - return; | |
672 | } | |
673 | ||
674 | /* Cleanup the device stuff */ | |
675 | irda_usb_close(self); | |
676 | /* No longer attached to USB bus */ | |
677 | self->usbdev = NULL; | |
678 | - IRDA_DEBUG(0, __FUNCTION__ "(), USB IrDA Disconnected\n"); | |
679 | + IRDA_DEBUG(0, "%s(), USB IrDA Disconnected\n", __FUNCTION__); | |
680 | } | |
681 | ||
682 | /*------------------------------------------------------------------*/ | |
683 | @@ -1570,12 +1609,13 @@ | |
684 | struct irda_usb_cb *irda = NULL; | |
685 | int i; | |
686 | ||
687 | - /* Find zombie instances and kill them... */ | |
688 | + /* Find zombie instances and kill them... | |
689 | + * In theory, it can't happen any longer. Jean II */ | |
690 | for (i = 0; i < NIRUSB; i++) { | |
691 | irda = &irda_instance[i]; | |
692 | /* If the Device is zombie */ | |
693 | if((irda->usbdev != NULL) && (irda->present == 0)) { | |
694 | - IRDA_DEBUG(0, __FUNCTION__ "(), disconnect zombie now !\n"); | |
695 | + IRDA_DEBUG(0, "%s(), disconnect zombie now !\n", __FUNCTION__); | |
696 | irda_usb_disconnect(irda->usbdev, (void *) irda); | |
697 | } | |
698 | } |