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