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
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.
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);
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__);
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;
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;
50 /*------------------------------------------------------------------*/
52 * Send a command to change the speed of the dongle
53 + * Need to be called with spinlock on.
55 static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
57 - unsigned long flags;
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);
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__);
76 - spin_lock_irqsave(&self->lock, flags);
78 /* Allocate the fake frame */
79 frame = self->speed_buff;
82 purb->timeout = MSECS_TO_JIFFIES(100);
84 if ((ret = usb_submit_urb(purb))) {
85 - WARNING(__FUNCTION__ "(), failed Speed URB\n");
86 + WARNING("%s(), failed Speed URB\n", __FUNCTION__);
88 - spin_unlock_irqrestore(&self->lock, flags);
91 /*------------------------------------------------------------------*/
93 * Note : this function will be called with both speed_urb and empty_urb...
95 -static void speed_bulk_callback(purb_t purb)
96 +static void speed_bulk_callback(struct urb *purb)
98 struct irda_usb_cb *self = purb->context;
100 - IRDA_DEBUG(2, __FUNCTION__ "()\n");
101 + IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
103 /* We should always have a context */
105 - WARNING(__FUNCTION__ "(), Bug : self == NULL\n");
106 + WARNING("%s(), Bug : self == NULL\n", __FUNCTION__);
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);
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)
121 struct irda_usb_cb *self = netdev->priv;
122 - purb_t purb = &self->tx_urb;
123 + struct urb *purb = &self->tx_urb;
129 - /* Check if the device is still there */
130 + netif_stop_queue(netdev);
132 + /* Protect us from USB callbacks, net watchdog and else. */
133 + spin_lock_irqsave(&self->lock, flags);
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 */
145 - netif_stop_queue(netdev);
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 @@
152 irda_usb_change_speed_xbofs(self);
153 netdev->trans_start = jiffies;
154 - dev_kfree_skb(skb);
155 /* Will netif_wake_queue() in callback */
161 if (purb->status != USB_ST_NOERROR) {
162 - WARNING(__FUNCTION__ "(), URB still in use!\n");
163 - dev_kfree_skb(skb);
165 + WARNING("%s(), URB still in use!\n", __FUNCTION__);
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);
180 + WARNING("%s(), failed skb_cow() !!!\n", __FUNCTION__);
185 - spin_lock_irqsave(&self->lock, flags);
187 /* Change setting for next frame */
188 irda_usb_build_header(self, skb_push(skb, USB_IRDA_HEADER), 0);
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);
205 + /* Drop silently the skb and exit */
206 + dev_kfree_skb(skb);
207 + spin_unlock_irqrestore(&self->lock, flags);
211 /*------------------------------------------------------------------*/
213 * Note : this function will be called only for tx_urb...
215 -static void write_bulk_callback(purb_t purb)
216 +static void write_bulk_callback(struct urb *purb)
218 + unsigned long flags;
219 struct sk_buff *skb = purb->context;
220 struct irda_usb_cb *self = ((struct irda_skb_cb *) skb->cb)->context;
222 - IRDA_DEBUG(2, __FUNCTION__ "()\n");
223 + IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
225 /* We should always have a context */
227 - WARNING(__FUNCTION__ "(), Bug : self == NULL\n");
228 + WARNING("%s(), Bug : self == NULL\n", __FUNCTION__);
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);
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 @@
244 /* urb is now available */
245 - purb->status = USB_ST_NOERROR;
246 + //purb->status = USB_ST_NOERROR; -> tested above
248 + /* Make sure we read self->present properly */
249 + spin_lock_irqsave(&self->lock, flags);
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);
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);
265 /* Otherwise, allow the stack to send more packets */
266 netif_wake_queue(self->netdev);
268 + spin_unlock_irqrestore(&self->lock, flags);
271 /*------------------------------------------------------------------*/
272 @@ -540,15 +552,20 @@
274 static void irda_usb_net_timeout(struct net_device *netdev)
276 + unsigned long flags;
277 struct irda_usb_cb *self = netdev->priv;
280 int done = 0; /* If we have made any progress */
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__);
285 + /* Protect us from USB callbacks, net Tx and else. */
286 + spin_lock_irqsave(&self->lock, flags);
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);
300 + spin_unlock_irqrestore(&self->lock, flags);
302 /* Maybe we need a reset */
303 /* Note : Some drivers seem to use a usb_set_interface() when they
304 @@ -692,16 +710,16 @@
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)
311 struct irda_skb_cb *cb;
314 - IRDA_DEBUG(2, __FUNCTION__ "()\n");
315 + IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
317 /* Check that we have an urb */
319 - WARNING(__FUNCTION__ "(), Bug : purb == NULL\n");
320 + WARNING("%s(), Bug : purb == NULL\n", __FUNCTION__);
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__);
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);
342 @@ -752,14 +770,14 @@
343 * Called by the USB subsystem when a frame has been received
346 -static void irda_usb_receive(purb_t purb)
347 +static void irda_usb_receive(struct urb *purb)
349 struct sk_buff *skb = (struct sk_buff *) purb->context;
350 struct irda_usb_cb *self;
351 struct irda_skb_cb *cb;
354 - IRDA_DEBUG(2, __FUNCTION__ "(), len=%d\n", purb->actual_length);
355 + IRDA_DEBUG(2, "%s(), len=%d\n", __FUNCTION__, purb->actual_length);
358 cb = (struct irda_skb_cb *) skb->cb;
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 */
368 @@ -782,13 +800,13 @@
369 self->stats.rx_crc_errors++;
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 */
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);
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__);
395 static int irda_usb_net_init(struct net_device *dev)
397 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
398 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
400 /* Set up to be a normal IrDA network device driver */
401 irda_device_setup(dev);
406 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
407 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
409 ASSERT(netdev != NULL, return -1;);
410 self = (struct irda_usb_cb *) netdev->priv;
413 /* Can only open the device if it's there */
415 - WARNING(__FUNCTION__ "(), device not present!\n");
416 + WARNING("%s(), device not present!\n", __FUNCTION__);
421 struct irda_usb_cb *self;
424 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
425 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
427 ASSERT(netdev != NULL, return -1;);
428 self = (struct irda_usb_cb *) netdev->priv;
429 @@ -1003,7 +1021,7 @@
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;
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));
449 /* Stop and remove instance of IrLAP */
450 @@ -1033,6 +1053,7 @@
452 static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
454 + unsigned long flags;
455 struct if_irda_req *irq = (struct if_irda_req *) rq;
456 struct irda_usb_cb *self;
458 @@ -1041,25 +1062,28 @@
460 ASSERT(self != NULL, return -1;);
462 - IRDA_DEBUG(2, __FUNCTION__ "(), %s, (cmd=0x%X)\n", dev->name, cmd);
464 - /* Check if the device is still there */
467 + IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
470 case SIOCSBANDWIDTH: /* Set bandwidth */
471 if (!capable(CAP_NET_ADMIN))
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);
485 + spin_unlock_irqrestore(&self->lock, flags);
487 case SIOCSMEDIABUSY: /* Set media busy */
488 if (!capable(CAP_NET_ADMIN))
490 - irda_device_set_media_busy(self->netdev, TRUE);
491 + /* Check if the IrDA stack is still there */
493 + irda_device_set_media_busy(self->netdev, TRUE);
495 case SIOCGRECEIVING: /* Check if we are receiving right now */
496 irq->ifr_receiving = irda_usb_is_receiving(self);
497 @@ -1096,7 +1120,7 @@
499 struct irda_class_desc *desc;
501 - IRDA_DEBUG(3, __FUNCTION__ "()\n");
502 + IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
504 desc = self->irda_desc;
506 @@ -1109,7 +1133,8 @@
507 self->qos.window_size.bits = desc->bmWindowSize;
508 self->qos.data_size.bits = desc->bmDataSize;
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);
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;
520 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
521 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
523 spin_lock_init(&self->lock);
525 @@ -1173,7 +1198,7 @@
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__);
533 self->netdev = netdev;
534 @@ -1193,7 +1218,7 @@
535 err = register_netdevice(netdev);
538 - ERROR(__FUNCTION__ "(), register_netdev() failed!\n");
539 + ERROR("%s(), register_netdev() failed!\n", __FUNCTION__);
542 MESSAGE("IrDA: Registered device %s\n", netdev->name);
543 @@ -1208,7 +1233,7 @@
545 static inline int irda_usb_close(struct irda_usb_cb *self)
547 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
548 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
550 ASSERT(self != NULL, return -1;);
552 @@ -1290,12 +1315,13 @@
553 /* This is our interrupt endpoint */
554 self->bulk_int_ep = ep;
556 - ERROR(__FUNCTION__ "(), Unrecognised endpoint %02X.\n", ep);
557 + ERROR("%s(), Unrecognised endpoint %02X.\n", __FUNCTION__, ep);
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, ;);
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));
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);
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.
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);
595 @@ -1457,10 +1482,10 @@
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__);
603 - IRDA_DEBUG(0, __FUNCTION__ "(), Unknown error %d\n", ret);
604 + IRDA_DEBUG(0, "%s(), Unknown error %d\n", __FUNCTION__, ret);
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__);
617 @@ -1494,40 +1519,54 @@
619 * The current irda-usb device is removed, the USB layer tell us
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.
629 static void irda_usb_disconnect(struct usb_device *dev, void *ptr)
631 + unsigned long flags;
632 struct irda_usb_cb *self = (struct irda_usb_cb *) ptr;
635 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
636 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
638 + /* Make sure that the Tx path is not executing. - Jean II */
639 + spin_lock_irqsave(&self->lock, flags);
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 */
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);
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));
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 */
674 /* Cleanup the device stuff */
675 irda_usb_close(self);
676 /* No longer attached to USB bus */
678 - IRDA_DEBUG(0, __FUNCTION__ "(), USB IrDA Disconnected\n");
679 + IRDA_DEBUG(0, "%s(), USB IrDA Disconnected\n", __FUNCTION__);
682 /*------------------------------------------------------------------*/
683 @@ -1570,12 +1609,13 @@
684 struct irda_usb_cb *irda = NULL;
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);