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
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.
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);
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__);
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;
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;
51 /*------------------------------------------------------------------*/
53 * Send a command to change the speed of the dongle
54 + * Need to be called with spinlock on.
56 static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
58 - unsigned long flags;
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);
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__);
77 - spin_lock_irqsave(&self->lock, flags);
79 /* Allocate the fake frame */
80 frame = self->speed_buff;
83 purb->timeout = MSECS_TO_JIFFIES(100);
85 if ((ret = usb_submit_urb(purb))) {
86 - WARNING(__FUNCTION__ "(), failed Speed URB\n");
87 + WARNING("%s(), failed Speed URB\n", __FUNCTION__);
89 - spin_unlock_irqrestore(&self->lock, flags);
92 /*------------------------------------------------------------------*/
94 * Note : this function will be called with both speed_urb and empty_urb...
96 -static void speed_bulk_callback(purb_t purb)
97 +static void speed_bulk_callback(struct urb *purb)
99 struct irda_usb_cb *self = purb->context;
101 - IRDA_DEBUG(2, __FUNCTION__ "()\n");
102 + IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
104 /* We should always have a context */
106 - WARNING(__FUNCTION__ "(), Bug : self == NULL\n");
107 + WARNING("%s(), Bug : self == NULL\n", __FUNCTION__);
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);
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)
122 struct irda_usb_cb *self = netdev->priv;
123 - purb_t purb = &self->tx_urb;
124 + struct urb *purb = &self->tx_urb;
130 - /* Check if the device is still there */
131 + netif_stop_queue(netdev);
133 + /* Protect us from USB callbacks, net watchdog and else. */
134 + spin_lock_irqsave(&self->lock, flags);
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 */
146 - netif_stop_queue(netdev);
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 @@
153 irda_usb_change_speed_xbofs(self);
154 netdev->trans_start = jiffies;
155 - dev_kfree_skb(skb);
156 /* Will netif_wake_queue() in callback */
162 if (purb->status != USB_ST_NOERROR) {
163 - WARNING(__FUNCTION__ "(), URB still in use!\n");
164 - dev_kfree_skb(skb);
166 + WARNING("%s(), URB still in use!\n", __FUNCTION__);
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);
181 + WARNING("%s(), failed skb_cow() !!!\n", __FUNCTION__);
186 - spin_lock_irqsave(&self->lock, flags);
188 /* Change setting for next frame */
189 irda_usb_build_header(self, skb_push(skb, USB_IRDA_HEADER), 0);
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);
206 + /* Drop silently the skb and exit */
207 + dev_kfree_skb(skb);
208 + spin_unlock_irqrestore(&self->lock, flags);
212 /*------------------------------------------------------------------*/
214 * Note : this function will be called only for tx_urb...
216 -static void write_bulk_callback(purb_t purb)
217 +static void write_bulk_callback(struct urb *purb)
219 + unsigned long flags;
220 struct sk_buff *skb = purb->context;
221 struct irda_usb_cb *self = ((struct irda_skb_cb *) skb->cb)->context;
223 - IRDA_DEBUG(2, __FUNCTION__ "()\n");
224 + IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
226 /* We should always have a context */
228 - WARNING(__FUNCTION__ "(), Bug : self == NULL\n");
229 + WARNING("%s(), Bug : self == NULL\n", __FUNCTION__);
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);
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 @@
245 /* urb is now available */
246 - purb->status = USB_ST_NOERROR;
247 + //purb->status = USB_ST_NOERROR; -> tested above
249 + /* Make sure we read self->present properly */
250 + spin_lock_irqsave(&self->lock, flags);
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);
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);
266 /* Otherwise, allow the stack to send more packets */
267 netif_wake_queue(self->netdev);
269 + spin_unlock_irqrestore(&self->lock, flags);
272 /*------------------------------------------------------------------*/
273 @@ -540,15 +552,20 @@
275 static void irda_usb_net_timeout(struct net_device *netdev)
277 + unsigned long flags;
278 struct irda_usb_cb *self = netdev->priv;
281 int done = 0; /* If we have made any progress */
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__);
286 + /* Protect us from USB callbacks, net Tx and else. */
287 + spin_lock_irqsave(&self->lock, flags);
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);
301 + spin_unlock_irqrestore(&self->lock, flags);
303 /* Maybe we need a reset */
304 /* Note : Some drivers seem to use a usb_set_interface() when they
305 @@ -692,16 +710,16 @@
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)
312 struct irda_skb_cb *cb;
315 - IRDA_DEBUG(2, __FUNCTION__ "()\n");
316 + IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
318 /* Check that we have an urb */
320 - WARNING(__FUNCTION__ "(), Bug : purb == NULL\n");
321 + WARNING("%s(), Bug : purb == NULL\n", __FUNCTION__);
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__);
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);
343 @@ -752,14 +770,14 @@
344 * Called by the USB subsystem when a frame has been received
347 -static void irda_usb_receive(purb_t purb)
348 +static void irda_usb_receive(struct urb *purb)
350 struct sk_buff *skb = (struct sk_buff *) purb->context;
351 struct irda_usb_cb *self;
352 struct irda_skb_cb *cb;
355 - IRDA_DEBUG(2, __FUNCTION__ "(), len=%d\n", purb->actual_length);
356 + IRDA_DEBUG(2, "%s(), len=%d\n", __FUNCTION__, purb->actual_length);
359 cb = (struct irda_skb_cb *) skb->cb;
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 */
369 @@ -782,13 +800,13 @@
370 self->stats.rx_crc_errors++;
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 */
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);
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__);
396 static int irda_usb_net_init(struct net_device *dev)
398 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
399 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
401 /* Set up to be a normal IrDA network device driver */
402 irda_device_setup(dev);
407 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
408 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
410 ASSERT(netdev != NULL, return -1;);
411 self = (struct irda_usb_cb *) netdev->priv;
414 /* Can only open the device if it's there */
416 - WARNING(__FUNCTION__ "(), device not present!\n");
417 + WARNING("%s(), device not present!\n", __FUNCTION__);
422 struct irda_usb_cb *self;
425 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
426 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
428 ASSERT(netdev != NULL, return -1;);
429 self = (struct irda_usb_cb *) netdev->priv;
430 @@ -1003,7 +1021,7 @@
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;
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));
450 /* Stop and remove instance of IrLAP */
451 @@ -1033,6 +1053,7 @@
453 static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
455 + unsigned long flags;
456 struct if_irda_req *irq = (struct if_irda_req *) rq;
457 struct irda_usb_cb *self;
459 @@ -1041,25 +1062,28 @@
461 ASSERT(self != NULL, return -1;);
463 - IRDA_DEBUG(2, __FUNCTION__ "(), %s, (cmd=0x%X)\n", dev->name, cmd);
465 - /* Check if the device is still there */
468 + IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
471 case SIOCSBANDWIDTH: /* Set bandwidth */
472 if (!capable(CAP_NET_ADMIN))
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);
486 + spin_unlock_irqrestore(&self->lock, flags);
488 case SIOCSMEDIABUSY: /* Set media busy */
489 if (!capable(CAP_NET_ADMIN))
491 - irda_device_set_media_busy(self->netdev, TRUE);
492 + /* Check if the IrDA stack is still there */
494 + irda_device_set_media_busy(self->netdev, TRUE);
496 case SIOCGRECEIVING: /* Check if we are receiving right now */
497 irq->ifr_receiving = irda_usb_is_receiving(self);
498 @@ -1096,7 +1120,7 @@
500 struct irda_class_desc *desc;
502 - IRDA_DEBUG(3, __FUNCTION__ "()\n");
503 + IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
505 desc = self->irda_desc;
507 @@ -1109,7 +1133,8 @@
508 self->qos.window_size.bits = desc->bmWindowSize;
509 self->qos.data_size.bits = desc->bmDataSize;
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);
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;
521 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
522 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
524 spin_lock_init(&self->lock);
526 @@ -1173,7 +1198,7 @@
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__);
534 self->netdev = netdev;
535 @@ -1193,7 +1218,7 @@
536 err = register_netdevice(netdev);
539 - ERROR(__FUNCTION__ "(), register_netdev() failed!\n");
540 + ERROR("%s(), register_netdev() failed!\n", __FUNCTION__);
543 MESSAGE("IrDA: Registered device %s\n", netdev->name);
544 @@ -1208,7 +1233,7 @@
546 static inline int irda_usb_close(struct irda_usb_cb *self)
548 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
549 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
551 ASSERT(self != NULL, return -1;);
553 @@ -1290,12 +1315,13 @@
554 /* This is our interrupt endpoint */
555 self->bulk_int_ep = ep;
557 - ERROR(__FUNCTION__ "(), Unrecognised endpoint %02X.\n", ep);
558 + ERROR("%s(), Unrecognised endpoint %02X.\n", __FUNCTION__, ep);
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, ;);
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));
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);
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.
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);
596 @@ -1457,10 +1482,10 @@
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__);
604 - IRDA_DEBUG(0, __FUNCTION__ "(), Unknown error %d\n", ret);
605 + IRDA_DEBUG(0, "%s(), Unknown error %d\n", __FUNCTION__, ret);
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__);
618 @@ -1494,40 +1519,54 @@
620 * The current irda-usb device is removed, the USB layer tell us
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.
630 static void irda_usb_disconnect(struct usb_device *dev, void *ptr)
632 + unsigned long flags;
633 struct irda_usb_cb *self = (struct irda_usb_cb *) ptr;
636 - IRDA_DEBUG(1, __FUNCTION__ "()\n");
637 + IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
639 + /* Make sure that the Tx path is not executing. - Jean II */
640 + spin_lock_irqsave(&self->lock, flags);
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 */
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);
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));
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 */
675 /* Cleanup the device stuff */
676 irda_usb_close(self);
677 /* No longer attached to USB bus */
679 - IRDA_DEBUG(0, __FUNCTION__ "(), USB IrDA Disconnected\n");
680 + IRDA_DEBUG(0, "%s(), USB IrDA Disconnected\n", __FUNCTION__);
683 /*------------------------------------------------------------------*/
684 @@ -1570,12 +1609,13 @@
685 struct irda_usb_cb *irda = NULL;
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);