3b3eb456999dd89b99890b9da41b91f8a4e36cee
[linux-flexiantxendom0-3.2.10.git] / drivers / net / irda / toshoboe.c
1 /*********************************************************************
2  *                
3  * Filename:      toshoboe.c
4  * Version:       0.1
5  * Description:   Driver for the Toshiba OBOE (or type-O or 700 or 701)
6  *                FIR Chipset. 
7  * Status:        Experimental.
8  * Author:        James McKenzie <james@fishsoup.dhs.org>
9  * Created at:    Sat May 8  12:35:27 1999
10  * Modified:      Paul Bristow <paul.bristow@technologist.com>
11  * Modified:      Mon Nov 11 19:10:05 1999
12  * 
13  *     Copyright (c) 1999-2000 James McKenzie, All Rights Reserved.
14  *      
15  *     This program is free software; you can redistribute it and/or 
16  *     modify it under the terms of the GNU General Public License as 
17  *     published by the Free Software Foundation; either version 2 of 
18  *     the License, or (at your option) any later version.
19  *  
20  *     Neither James McKenzie nor Cambridge University admit liability nor
21  *     provide warranty for any of this software. This material is 
22  *     provided "AS-IS" and at no charge.
23  *
24  *     Applicable Models : Libretto 100CT. and many more
25  *     Toshiba refers to this chip as the type-O IR port.
26  *
27  ********************************************************************/
28
29 /* This driver is experimental, I have only three ir devices */
30 /* an olivetti notebook which doesn't have FIR, a toshiba libretto, and */
31 /* an hp printer, this works fine at 4MBPS with my HP printer */
32
33 static char *rcsid = "$Id: toshoboe.c,v 1.91 1999/06/29 14:21:06 root Exp $";
34
35 /* Define this to have only one frame in the XMIT or RECV queue */
36 /* Toshiba's drivers do this, but it disables back to back tansfers */
37 /* I think that the chip may have some problems certainly, I have */
38 /* seen it jump over tasks in the taskfile->xmit with this turned on */
39 #define ONETASK 
40
41 /* To adjust the number of tasks in use edit toshoboe.h */
42
43 /* Define this to enable FIR and MIR support */
44 #define ENABLE_FAST
45
46 /* Size of IO window */
47 #define CHIP_IO_EXTENT  0x1f
48
49 /* Transmit and receive buffer sizes, adjust at your peril */
50 #define RX_BUF_SZ       4196
51 #define TX_BUF_SZ       4196
52
53 /* No user servicable parts below here */
54
55 #include <linux/module.h>
56 #include <linux/kernel.h>
57 #include <linux/types.h>
58 #include <linux/skbuff.h>
59 #include <linux/netdevice.h>
60 #include <linux/ioport.h>
61 #include <linux/delay.h>
62 #include <linux/slab.h>
63 #include <linux/init.h>
64 #include <linux/pci.h>
65 #include <linux/rtnetlink.h>
66
67 #include <asm/system.h>
68 #include <asm/io.h>
69
70 #include <net/irda/wrapper.h>
71 #include <net/irda/irda.h>
72 #include <net/irda/irda_device.h>
73
74 #include <linux/pm.h>
75
76 #include <net/irda/toshoboe.h>
77
78 #define PCI_DEVICE_ID_FIR701b  0x0d01
79
80 static struct pci_device_id toshoboe_pci_tbl[] __initdata = {
81         { PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_FIR701, PCI_ANY_ID, PCI_ANY_ID, },
82         { PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_FIR701b, PCI_ANY_ID, PCI_ANY_ID, },
83         { }                     /* Terminating entry */
84 };
85 MODULE_DEVICE_TABLE(pci, toshoboe_pci_tbl);
86
87 static const char *driver_name = "toshoboe";
88
89 static int max_baud = 4000000;
90
91 /* Shutdown the chip and point the taskfile reg somewhere else */
92 static void
93 toshoboe_stopchip (struct toshoboe_cb *self)
94 {
95   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
96
97   outb_p (0x0e, OBOE_REG_11);
98
99   outb_p (0x00, OBOE_RST);
100   outb_p (0x3f, OBOE_TFP2);     /*Write the taskfile address */
101   outb_p (0xff, OBOE_TFP1);
102   outb_p (0xff, OBOE_TFP0);
103   outb_p (0x0f, OBOE_REG_1B);
104   outb_p (0xff, OBOE_REG_1A);
105   outb_p (0x00, OBOE_ISR);      /*FIXME: should i do this to disbale ints */
106   outb_p (0x80, OBOE_RST);
107   outb_p (0xe, OBOE_LOCK);
108
109 }
110
111 /*Set the baud rate */
112 static void
113 toshoboe_setbaud (struct toshoboe_cb *self, int baud)
114 {
115   unsigned long flags;
116   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
117
118   printk (KERN_WARNING "ToshOboe: setting baud to %d\n", baud);
119
120   save_flags (flags);
121   cli ();
122   switch (baud)
123     {
124     case 2400:
125       outb_p (OBOE_PMDL_SIR, OBOE_PMDL);
126       outb_p (OBOE_SMDL_SIR, OBOE_SMDL);
127       outb_p (0xbf, OBOE_UDIV);
128       break;
129     case 4800:
130       outb_p (OBOE_PMDL_SIR, OBOE_PMDL);
131       outb_p (OBOE_SMDL_SIR, OBOE_SMDL);
132       outb_p (0x5f, OBOE_UDIV);
133       break;
134     case 9600:
135       outb_p (OBOE_PMDL_SIR, OBOE_PMDL);
136       outb_p (OBOE_SMDL_SIR, OBOE_SMDL);
137       outb_p (0x2f, OBOE_UDIV);
138       break;
139     case 19200:
140       outb_p (OBOE_PMDL_SIR, OBOE_PMDL);
141       outb_p (OBOE_SMDL_SIR, OBOE_SMDL);
142       outb_p (0x17, OBOE_UDIV);
143       break;
144     case 38400:
145       outb_p (OBOE_PMDL_SIR, OBOE_PMDL);
146       outb_p (OBOE_SMDL_SIR, OBOE_SMDL);
147       outb_p (0xb, OBOE_UDIV);
148       break;
149     case 57600:
150       outb_p (OBOE_PMDL_SIR, OBOE_PMDL);
151       outb_p (OBOE_SMDL_SIR, OBOE_SMDL);
152       outb_p (0x7, OBOE_UDIV);
153       break;
154     case 115200:
155       outb_p (OBOE_PMDL_SIR, OBOE_PMDL);
156       outb_p (OBOE_SMDL_SIR, OBOE_SMDL);
157       outb_p (0x3, OBOE_UDIV);
158       break;
159     case 1152000:
160       outb_p (OBOE_PMDL_MIR, OBOE_PMDL);
161       outb_p (OBOE_SMDL_MIR, OBOE_SMDL);
162       outb_p (0x1, OBOE_UDIV);
163       break;
164     case 4000000:
165       outb_p (OBOE_PMDL_FIR, OBOE_PMDL);
166       outb_p (OBOE_SMDL_FIR, OBOE_SMDL);
167       outb_p (0x0, OBOE_UDIV);
168       break;
169     }
170
171   restore_flags (flags);
172
173   outb_p (0x00, OBOE_RST);
174   outb_p (0x80, OBOE_RST);
175   outb_p (0x01, OBOE_REG_9);
176
177   self->io.speed = baud;
178 }
179
180 /* Wake the chip up and get it looking at the taskfile */
181 static void
182 toshoboe_startchip (struct toshoboe_cb *self)
183 {
184   __u32 physaddr;
185
186   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
187
188
189   outb_p (0, OBOE_LOCK);
190   outb_p (0, OBOE_RST);
191   outb_p (OBOE_NTR_VAL, OBOE_NTR);
192   outb_p (0xf0, OBOE_REG_D);
193   outb_p (0xff, OBOE_ISR);
194   outb_p (0x0f, OBOE_REG_1B);
195   outb_p (0xff, OBOE_REG_1A);
196
197
198   physaddr = virt_to_bus (self->taskfile);
199
200   outb_p ((physaddr >> 0x0a) & 0xff, OBOE_TFP0);
201   outb_p ((physaddr >> 0x12) & 0xff, OBOE_TFP1);
202   outb_p ((physaddr >> 0x1a) & 0x3f, OBOE_TFP2);
203
204   outb_p (0x0e, OBOE_REG_11);
205   outb_p (0x80, OBOE_RST);
206
207   toshoboe_setbaud (self, 9600);
208
209 }
210
211 /*Let the chip look at memory */
212 static void
213 toshoboe_enablebm (struct toshoboe_cb *self)
214 {
215   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
216   pci_set_master (self->pdev);
217 }
218
219 /*Don't let the chip look at memory */
220 static void
221 toshoboe_disablebm (struct toshoboe_cb *self)
222 {
223   __u8 command;
224   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
225
226   pci_read_config_byte (self->pdev, PCI_COMMAND, &command);
227   command &= ~PCI_COMMAND_MASTER;
228   pci_write_config_byte (self->pdev, PCI_COMMAND, command);
229
230 }
231
232 /*setup the taskfile */
233 static void
234 toshoboe_initbuffs (struct toshoboe_cb *self)
235 {
236   int i;
237   unsigned long flags;
238
239   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
240
241   save_flags (flags);
242   cli ();
243
244   for (i = 0; i < TX_SLOTS; ++i)
245     {
246       self->taskfile->xmit[i].len = 0;
247       self->taskfile->xmit[i].control = 0x00;
248       self->taskfile->xmit[i].buffer = virt_to_bus (self->xmit_bufs[i]);
249     }
250
251   for (i = 0; i < RX_SLOTS; ++i)
252     {
253       self->taskfile->recv[i].len = 0;
254       self->taskfile->recv[i].control = 0x83;
255       self->taskfile->recv[i].buffer = virt_to_bus (self->recv_bufs[i]);
256     }
257
258   restore_flags (flags);
259 }
260
261 /*Transmit something */
262 static int
263 toshoboe_hard_xmit (struct sk_buff *skb, struct net_device *dev)
264 {
265   struct toshoboe_cb *self;
266   __s32 speed;
267   int mtt, len;
268
269   self = (struct toshoboe_cb *) dev->priv;
270
271   ASSERT (self != NULL, return 0;
272     );
273
274   /* Check if we need to change the speed */
275   speed = irda_get_next_speed(skb);
276   if ((speed != self->io.speed) && (speed != -1)) {
277         /* Check for empty frame */
278         if (!skb->len) {
279             toshoboe_setbaud(self, speed); 
280             dev_kfree_skb(skb);
281             return 0;
282         } else
283             self->new_speed = speed;
284   }
285
286   netif_stop_queue(dev);
287   
288   if (self->stopped) {
289           dev_kfree_skb(skb);
290     return 0;
291   }
292
293 #ifdef ONETASK
294   if (self->txpending)
295     return -EBUSY;
296
297   self->txs = inb_p (OBOE_XMTT) - OBOE_XMTT_OFFSET;
298
299   self->txs &= 0x3f;
300
301 #endif
302
303   if (self->taskfile->xmit[self->txs].control)
304     return -EBUSY;
305
306
307   if (inb_p (OBOE_RST) & OBOE_RST_WRAP)
308     {
309       len = async_wrap_skb (skb, self->xmit_bufs[self->txs], TX_BUF_SZ);
310     }
311   else
312     {
313       len = skb->len;
314       memcpy (self->xmit_bufs[self->txs], skb->data, len);
315     }
316   self->taskfile->xmit[self->txs].len = len & 0x0fff;
317
318
319
320   outb_p (0, OBOE_RST);
321   outb_p (0x1e, OBOE_REG_11);
322
323   self->taskfile->xmit[self->txs].control = 0x84;
324
325   mtt = irda_get_mtt (skb);
326   if (mtt)
327     udelay (mtt);
328
329   self->txpending++;
330
331   /*FIXME: ask about busy,media_busy stuff, for the moment */
332   /*busy means can't queue any more */
333 #ifndef ONETASK
334   if (self->txpending != TX_SLOTS)
335   {
336         netif_wake_queue(dev);
337   }
338 #endif
339
340   outb_p (0x80, OBOE_RST);
341   outb_p (1, OBOE_REG_9);
342
343   self->txs++;
344   self->txs %= TX_SLOTS;
345
346   dev_kfree_skb (skb);
347
348   return 0;
349 }
350
351 /*interrupt handler */
352 static irqreturn_t
353 toshoboe_interrupt (int irq, void *dev_id, struct pt_regs *regs)
354 {
355   struct toshoboe_cb *self = (struct toshoboe_cb *) dev_id;
356   __u8 irqstat;
357   struct sk_buff *skb;
358
359   if (self == NULL)
360     {
361       printk (KERN_WARNING "%s: irq %d for unknown device.\n",
362               driver_name, irq);
363       return IRQ_NONE;
364     }
365
366   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
367
368   irqstat = inb_p (OBOE_ISR);
369
370 /* woz it us */
371   if (!(irqstat & 0xf8))
372     return IRQ_NONE;
373
374   outb_p (irqstat, OBOE_ISR);   /*Acknologede it */
375
376
377 /* Txdone */
378   if (irqstat & OBOE_ISR_TXDONE)
379     {
380       self->txpending--;
381
382       self->stats.tx_packets++;
383
384       if (self->new_speed) {
385               toshoboe_setbaud(self, self->new_speed);
386
387               self->new_speed = 0;
388       }
389       /* Tell network layer that we want more frames */
390       netif_wake_queue(self->netdev);
391     }
392
393   if (irqstat & OBOE_ISR_RXDONE)
394     {
395
396 #ifdef ONETASK
397       self->rxs = inb_p (OBOE_RCVT);
398       self->rxs += (RX_SLOTS - 1);
399       self->rxs %= RX_SLOTS;
400 #else
401       while (self->taskfile->recv[self->rxs].control == 0)
402 #endif
403         {
404           int len = self->taskfile->recv[self->rxs].len;
405
406           if (len > 2)
407             len -= 2;
408
409           skb = dev_alloc_skb (len + 1);
410           if (skb)
411             {
412               skb_reserve (skb, 1);
413
414               skb_put (skb, len);
415               memcpy (skb->data, self->recv_bufs[self->rxs], len);
416
417               self->stats.rx_packets++;
418               skb->dev = self->netdev;
419               skb->mac.raw = skb->data;
420               skb->protocol = htons (ETH_P_IRDA);
421             }
422           else
423             {
424               printk (KERN_INFO
425                       "%s(), memory squeeze, dropping frame.\n", __FUNCTION__);
426             }
427
428           self->taskfile->recv[self->rxs].control = 0x83;
429           self->taskfile->recv[self->rxs].len = 0x0;
430
431           self->rxs++;
432           self->rxs %= RX_SLOTS;
433
434           if (skb) {
435             netif_rx (skb);
436             self->netdev->last_rx = jiffies;
437           }
438
439         }
440
441     }
442
443   if (irqstat & OBOE_ISR_20)
444     {
445       printk (KERN_WARNING "Oboe_irq: 20\n");
446     }
447   if (irqstat & OBOE_ISR_10)
448     {
449       printk (KERN_WARNING "Oboe_irq: 10\n");
450     }
451   if (irqstat & 0x8)
452     {
453       /*FIXME: I think this is a TX or RX error of some sort */
454
455       self->stats.tx_errors++;
456       self->stats.rx_errors++;
457
458     }
459   return IRQ_HANDLED;
460 }
461
462 static int
463 toshoboe_net_init (struct net_device *dev)
464 {
465   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
466
467   /* Setup to be a normal IrDA network device driver */
468   irda_device_setup (dev);
469
470   /* Insert overrides below this line! */
471   return 0;
472 }
473
474
475 static void 
476 toshoboe_initptrs (struct toshoboe_cb *self)
477 {
478
479   unsigned long flags;
480   save_flags (flags);
481   cli ();
482
483   /*FIXME: need to test this carefully to check which one */
484   /*of the two possible startup logics the chip uses */
485   /*although it won't make any difference if no-one xmits durining init */
486   /*and none what soever if using ONETASK */
487
488   self->rxs = inb_p (OBOE_RCVT);
489   self->txs = inb_p (OBOE_XMTT) - OBOE_XMTT_OFFSET;
490
491 #if 0
492   self->rxs = 0;
493   self->txs = 0;
494 #endif
495 #if 0
496   self->rxs = RX_SLOTS - 1;
497   self->txs = 0;
498 #endif
499
500
501   self->txpending = 0;
502
503   restore_flags (flags);
504
505 }
506
507
508 static int
509 toshoboe_net_open (struct net_device *dev)
510 {
511   struct toshoboe_cb *self;
512   char hwname[32];
513
514   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
515
516   ASSERT (dev != NULL, return -1;
517     );
518   self = (struct toshoboe_cb *) dev->priv;
519
520   ASSERT (self != NULL, return 0;
521     );
522
523   if (self->stopped)
524     return 0;
525
526   if (request_irq (self->io.irq, toshoboe_interrupt,
527                    SA_SHIRQ | SA_INTERRUPT, dev->name, (void *) self))
528     {
529
530       return -EAGAIN;
531     }
532
533   toshoboe_initbuffs (self);
534   toshoboe_enablebm (self);
535   toshoboe_startchip (self);
536   toshoboe_initptrs (self);
537
538   /* Ready to play! */
539   netif_start_queue(dev);  
540   /* Give self a hardware name */
541   sprintf(hwname, "Toshiba-FIR @ 0x%03x", self->base);
542   /* 
543    * Open new IrLAP layer instance, now that everything should be
544    * initialized properly 
545    */
546   self->irlap = irlap_open(dev, &self->qos, hwname);    
547
548   self->open = 1;
549         
550   MOD_INC_USE_COUNT;
551
552   return 0;
553
554 }
555
556 static int
557 toshoboe_net_close (struct net_device *dev)
558 {
559   struct toshoboe_cb *self;
560
561   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
562
563   ASSERT (dev != NULL, return -1;
564     );
565   self = (struct toshoboe_cb *) dev->priv;
566
567   /* Stop device */
568   netif_stop_queue(dev);
569     
570   /* Stop and remove instance of IrLAP */
571   if (self->irlap)
572           irlap_close(self->irlap);
573   self->irlap = NULL;
574
575   self->open = 0;
576
577   free_irq (self->io.irq, (void *) self);
578
579   if (!self->stopped)
580     {
581       toshoboe_stopchip (self);
582       toshoboe_disablebm (self);
583     }
584
585   MOD_DEC_USE_COUNT;
586
587   return 0;
588
589 }
590
591 /*
592  * Function toshoboe_net_ioctl (dev, rq, cmd)
593  *
594  *    Process IOCTL commands for this device
595  *
596  */
597 static int toshoboe_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
598 {
599         struct if_irda_req *irq = (struct if_irda_req *) rq;
600         struct toshoboe_cb *self;
601         unsigned long flags;
602         int ret = 0;
603
604         ASSERT(dev != NULL, return -1;);
605
606         self = dev->priv;
607
608         ASSERT(self != NULL, return -1;);
609
610         IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__ , dev->name, cmd);
611         
612         /* Disable interrupts & save flags */
613         save_flags(flags);
614         cli();
615         switch (cmd) {
616         case SIOCSBANDWIDTH: /* Set bandwidth */
617                 if (!capable(CAP_NET_ADMIN)) {
618                         ret = -EPERM;
619                         goto out;
620                 }
621                 /* toshoboe_setbaud(self, irq->ifr_baudrate); */
622                 /* Just change speed once - inserted by Paul Bristow */
623                 self->new_speed = irq->ifr_baudrate;
624                 break;
625         case SIOCSMEDIABUSY: /* Set media busy */
626                 if (!capable(CAP_NET_ADMIN)) {
627                         ret = -EPERM;
628                         goto out;
629                 }
630                 irda_device_set_media_busy(self->netdev, TRUE);
631                 break;
632         case SIOCGRECEIVING: /* Check if we are receiving right now */
633                 irq->ifr_receiving = 0; /* Can't tell */
634                 break;
635         default:
636                 ret = -EOPNOTSUPP;
637         }
638 out:
639         restore_flags(flags);
640         return ret;
641 }
642
643 MODULE_DESCRIPTION("Toshiba OBOE IrDA Device Driver");
644 MODULE_AUTHOR("James McKenzie <james@fishsoup.dhs.org>");
645 MODULE_LICENSE("GPL");
646
647 MODULE_PARM (max_baud, "i");
648 MODULE_PARM_DESC(max_baus, "Maximum baud rate");
649
650 static void
651 toshoboe_remove (struct pci_dev *pci_dev)
652 {
653   int i;
654   struct toshoboe_cb *self = (struct toshoboe_cb*)pci_get_drvdata(pci_dev);
655
656   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
657
658   ASSERT (self != NULL, return;
659     );
660
661   if (!self->stopped)
662     {
663       toshoboe_stopchip (self);
664       toshoboe_disablebm (self);
665     }
666
667   release_region (self->io.sir_base, self->io.sir_ext);
668
669
670   for (i = 0; i < TX_SLOTS; ++i)
671     {
672       kfree (self->xmit_bufs[i]);
673       self->xmit_bufs[i] = NULL;
674     }
675
676   for (i = 0; i < RX_SLOTS; ++i)
677     {
678       kfree (self->recv_bufs[i]);
679       self->recv_bufs[i] = NULL;
680     }
681
682   if (self->netdev)
683           unregister_netdev(self->netdev);
684
685   kfree (self->taskfilebuf);
686   self->taskfilebuf = NULL;
687   self->taskfile = NULL;
688
689   return;
690
691 }
692
693 static int
694 toshoboe_probe (struct pci_dev *pci_dev, const struct pci_device_id *pdid)
695 {
696   struct toshoboe_cb *self;
697   struct net_device *dev;
698   int i = 0;
699   int ok = 0;
700   int err;
701
702   IRDA_DEBUG (4, "%s()\n", __FUNCTION__ );
703
704   if ((err=pci_enable_device(pci_dev)))
705           return err;
706
707   self = kmalloc (sizeof (struct toshoboe_cb), GFP_KERNEL);
708
709   if (self == NULL)
710     {
711       printk (KERN_ERR "IrDA: Can't allocate memory for "
712               "IrDA control block!\n");
713       return -ENOMEM;
714     }
715
716   memset (self, 0, sizeof (struct toshoboe_cb));
717
718   self->open = 0;
719   self->stopped = 0;
720   self->pdev = pci_dev;
721   self->base = pci_resource_start(pci_dev,0);
722
723   self->io.sir_base = self->base;
724   self->io.irq = pci_dev->irq;
725   self->io.sir_ext = CHIP_IO_EXTENT;
726   self->io.speed = 9600;
727
728   /* Lock the port that we need */
729   if (NULL==request_region (self->io.sir_base, self->io.sir_ext, driver_name))
730     {
731       IRDA_DEBUG (0, "%s(), can't get iobase of 0x%03x\n", __FUNCTION__ ,
732              self->io.sir_base);
733
734       err = -EBUSY;
735       goto freeself;
736     }
737
738   irda_init_max_qos_capabilies (&self->qos);
739   self->qos.baud_rate.bits = 0;
740
741   if (max_baud >= 2400)
742     self->qos.baud_rate.bits |= IR_2400;
743   /*if (max_baud>=4800) idev->qos.baud_rate.bits|=IR_4800; */
744   if (max_baud >= 9600)
745     self->qos.baud_rate.bits |= IR_9600;
746   if (max_baud >= 19200)
747     self->qos.baud_rate.bits |= IR_19200;
748   if (max_baud >= 115200)
749     self->qos.baud_rate.bits |= IR_115200;
750 #ifdef ENABLE_FAST
751   if (max_baud >= 576000)
752     self->qos.baud_rate.bits |= IR_576000;
753   if (max_baud >= 1152000)
754     self->qos.baud_rate.bits |= IR_1152000;
755   if (max_baud >= 4000000)
756     self->qos.baud_rate.bits |= (IR_4000000 << 8);
757 #endif
758
759
760   self->qos.min_turn_time.bits = 0xff;  /*FIXME: what does this do? */
761
762   irda_qos_bits_to_value (&self->qos);
763
764   self->flags = IFF_SIR | IFF_DMA | IFF_PIO;
765
766 #ifdef ENABLE_FAST
767   if (max_baud >= 576000)
768     self->flags |= IFF_FIR;
769 #endif
770
771   /* Now setup the endless buffers we need */
772
773   self->txs = 0;
774   self->rxs = 0;
775
776   self->taskfilebuf = kmalloc (OBOE_TASK_BUF_LEN, GFP_KERNEL);
777   if (!self->taskfilebuf)
778     {
779       printk (KERN_ERR "toshoboe: kmalloc for DMA failed()\n");
780       err = -ENOMEM;
781       goto freeregion;
782     }
783
784
785   memset (self->taskfilebuf, 0, OBOE_TASK_BUF_LEN);
786
787   /*We need to align the taskfile on a taskfile size boundary */
788   {
789     __u32 addr;
790
791     addr = (__u32) self->taskfilebuf;
792     addr &= ~(sizeof (struct OboeTaskFile) - 1);
793     addr += sizeof (struct OboeTaskFile);
794
795     self->taskfile = (struct OboeTaskFile *) addr;
796   }
797
798   for (i = 0; i < TX_SLOTS; ++i)
799     {
800       self->xmit_bufs[i] = kmalloc (TX_BUF_SZ, GFP_KERNEL | GFP_DMA);
801       if (self->xmit_bufs[i])
802         ok++;
803     }
804
805   for (i = 0; i < RX_SLOTS; ++i)
806     {
807       self->recv_bufs[i] = kmalloc (TX_BUF_SZ, GFP_KERNEL | GFP_DMA);
808       if (self->recv_bufs[i])
809         ok++;
810     }
811
812   if (ok != RX_SLOTS + TX_SLOTS)
813     {
814       printk (KERN_ERR "toshoboe: kmalloc for buffers failed()\n");
815       err = -ENOMEM;
816       goto freebufs;
817
818   }
819
820
821   if (!(dev = dev_alloc("irda%d", &err))) {
822       ERROR("%s(), dev_alloc() failed!\n", __FUNCTION__);
823       err = -ENOMEM;
824       goto freebufs;
825   }
826   dev->priv = (void *) self;
827   self->netdev = dev;
828   
829   MESSAGE("IrDA: Registered device %s\n", dev->name);
830
831   dev->init = toshoboe_net_init;
832   dev->hard_start_xmit = toshoboe_hard_xmit;
833   dev->open = toshoboe_net_open;
834   dev->stop = toshoboe_net_close;
835   dev->do_ioctl = toshoboe_net_ioctl;
836
837   rtnl_lock();
838   err = register_netdevice(dev);
839   rtnl_unlock();
840   if (err) {
841           ERROR("%s(), register_netdev() failed!\n", __FUNCTION__);
842           /* XXX there is not freeing for dev? */
843           goto freebufs;
844   }
845   pci_set_drvdata(pci_dev,self);
846
847   printk (KERN_WARNING "ToshOboe: Using ");
848 #ifdef ONETASK
849   printk ("single");
850 #else
851   printk ("multiple");
852 #endif
853   printk (" tasks, version %s\n", rcsid);
854
855   return (0);
856 freebufs:
857       for (i = 0; i < TX_SLOTS; ++i)
858         if (self->xmit_bufs[i])
859           kfree (self->xmit_bufs[i]);
860       for (i = 0; i < RX_SLOTS; ++i)
861         if (self->recv_bufs[i])
862           kfree (self->recv_bufs[i]);
863       kfree(self->taskfilebuf);
864 freeregion:
865       release_region (self->io.sir_base, self->io.sir_ext);
866 freeself:
867       kfree (self);
868       return err;
869 }
870
871 static int
872 toshoboe_suspend (struct pci_dev *pci_dev, u32 crap)
873 {
874   int i = 10;
875   struct toshoboe_cb *self = (struct toshoboe_cb*)pci_get_drvdata(pci_dev);
876
877   printk (KERN_WARNING "ToshOboe: suspending\n");
878
879   if (!self || self->stopped)
880     return 0;
881
882   self->stopped = 1;
883
884   if (!self->open)
885     return 0;
886
887 /*FIXME: can't sleep here wait one second */
888
889   while ((i--) && (self->txpending))
890     udelay (100);
891
892   toshoboe_stopchip (self);
893   toshoboe_disablebm (self);
894
895   self->txpending = 0;
896   return 0;
897 }
898
899
900 static int 
901 toshoboe_resume (struct pci_dev *pci_dev)
902 {
903   struct toshoboe_cb *self = (struct toshoboe_cb*)pci_get_drvdata(pci_dev);
904   unsigned long flags;
905
906   if (!self)
907     return 0;
908
909   if (!self->stopped)
910     return 0;
911
912   if (!self->open)
913     {
914       self->stopped = 0;
915       return 0;
916     }
917
918   save_flags (flags);
919   cli ();
920
921   toshoboe_initbuffs (self);
922   toshoboe_enablebm (self);
923   toshoboe_startchip (self);
924
925   toshoboe_setbaud (self, self->io.speed);
926
927   toshoboe_initptrs (self);
928
929   netif_wake_queue(self->netdev);
930   restore_flags (flags);
931   printk (KERN_WARNING "ToshOboe: waking up\n");
932   return 0;
933 }
934
935 static struct pci_driver toshoboe_pci_driver = {
936         .name           = "toshoboe",
937         .id_table       = toshoboe_pci_tbl,
938         .probe          = toshoboe_probe,
939         .remove         = toshoboe_remove,
940         .suspend        = toshoboe_suspend,
941         .resume         = toshoboe_resume 
942 };
943
944 int __init
945 toshoboe_init (void)
946 {
947   return pci_module_init(&toshoboe_pci_driver);
948 }
949
950 void
951 toshoboe_cleanup (void)
952 {
953   pci_unregister_driver(&toshoboe_pci_driver);
954 }
955
956 module_init(toshoboe_init);
957 module_exit(toshoboe_cleanup);