1 /*****************************************************************
5 * Description: Driver for the Toshiba OBOE (or type-O or 701)
6 * FIR Chipset, also supports the DONAUOBOE (type-DO
7 * or d01) FIR chipset which as far as I know is
9 * Documentation: http://libxg.free.fr/irda/lib-irda.html
10 * Status: Experimental.
11 * Author: James McKenzie <james@fishsoup.dhs.org>
12 * Created at: Sat May 8 12:35:27 1999
13 * Modified: Paul Bristow <paul.bristow@technologist.com>
14 * Modified: Mon Nov 11 19:10:05 1999
15 * Modified: James McKenzie <james@fishsoup.dhs.org>
16 * Modified: Thu Mar 16 12:49:00 2000 (Substantial rewrite)
17 * Modified: Sat Apr 29 00:23:03 2000 (Added DONAUOBOE support)
18 * Modified: Wed May 24 23:45:02 2000 (Fixed chipio_t structure)
19 * Modified: 2.13 Christian Gennerat <christian.gennerat@polytechnique.org>
20 * Modified: 2.13 dim jan 07 21:57:39 2001 (tested with kernel 2.4 & irnet/ppp)
21 * Modified: 2.14 Christian Gennerat <christian.gennerat@polytechnique.org>
22 * Modified: 2.14 lun fev 05 17:55:59 2001 (adapted to patch-2.4.1-pre8-irda1)
23 * Modified: 2.15 Martin Lucina <mato@kotelna.sk>
24 * Modified: 2.15 Fri Jun 21 20:40:59 2002 (sync with 2.4.18, substantial fixes)
25 * Modified: 2.16 Martin Lucina <mato@kotelna.sk>
26 * Modified: 2.16 Sat Jun 22 18:54:29 2002 (fix freeregion, default to verbose)
27 * Modified: 2.17 Christian Gennerat <christian.gennerat@polytechnique.org>
28 * Modified: 2.17 jeu sep 12 08:50:20 2002 (save_flags();cli(); replaced by spinlocks)
29 * Modified: 2.18 Christian Gennerat <christian.gennerat@polytechnique.org>
30 * Modified: 2.18 ven jan 10 03:14:16 2003 Change probe default options
32 * Copyright (c) 1999 James McKenzie, All Rights Reserved.
34 * This program is free software; you can redistribute it and/or
35 * modify it under the terms of the GNU General Public License as
36 * published by the Free Software Foundation; either version 2 of
37 * the License, or (at your option) any later version.
39 * Neither James McKenzie nor Cambridge University admit liability nor
40 * provide warranty for any of this software. This material is
41 * provided "AS-IS" and at no charge.
43 * Applicable Models : Libretto 100/110CT and many more.
44 * Toshiba refers to this chip as the type-O IR port,
45 * or the type-DO IR port.
47 ********************************************************************/
49 /* Look at toshoboe.h (currently in include/net/irda) for details of */
50 /* Where to get documentation on the chip */
52 /* See below for a description of the logic in this driver */
54 /* User servicable parts */
55 /* USE_PROBE Create the code which probes the chip and does a few tests */
56 /* do_probe module parameter Enable this code */
57 /* Probe code is very useful for understanding how the hardware works */
58 /* Use it with various combinations of TT_LEN, RX_LEN */
59 /* Strongly recommended, disable if the probe fails on your machine */
60 /* and send me <james@fishsoup.dhs.org> the output of dmesg */
64 /* Trace Transmit ring, interrupts, Receive ring or not ? */
65 #define PROBE_VERBOSE 1
67 /* Debug option, examine sent and received raw data */
68 /* Irdadump is better, but does not see all packets. enable it if you want. */
71 /* MIR mode has not been tested. Some behaviour is different */
72 /* Seems to work against an Ericsson R520 for me. -Martin */
75 /* Schedule back to back hardware transmits wherever possible, otherwise */
76 /* we need an interrupt for every frame, unset if oboe works for a bit and */
80 /* Set the number of slots in the rings */
81 /* If you get rx/tx fifo overflows at high bitrates, you can try increasing */
84 #define RING_SIZE (OBOE_RING_SIZE_RX8 | OBOE_RING_SIZE_TX8)
89 /* Less user servicable parts below here */
91 /* Test, Transmit and receive buffer sizes, adjust at your peril */
92 /* remarks: nfs usually needs 1k blocks */
93 /* remarks: in SIR mode, CRC is received, -> RX_LEN=TX_LEN+2 */
94 /* remarks: test accepts large blocks. Standard is 0x80 */
95 /* When TT_LEN > RX_LEN (SIR mode) data is stored in successive slots. */
96 /* When 3 or more slots are needed for each test packet, */
97 /* data received in the first slots is overwritten, even */
98 /* if OBOE_CTL_RX_HW_OWNS is not set, without any error! */
102 /* Real transmitted length (SIR mode) is about 14+(2%*TX_LEN) more */
103 /* long than user-defined length (see async_wrap_skb) and is less then 4K */
104 /* Real received length is (max RX_LEN) differs from user-defined */
105 /* length only b the CRC (2 or 4 bytes) */
106 #define BUF_SAFETY 0x7a
107 #define RX_BUF_SZ (RX_LEN)
108 #define TX_BUF_SZ (TX_LEN+BUF_SAFETY)
111 /* Logic of the netdev part of this driver */
113 /* The RX ring is filled with buffers, when a packet arrives */
114 /* it is DMA'd into the buffer which is marked used and RxDone called */
115 /* RxDone forms an skb (and checks the CRC if in SIR mode) and ships */
116 /* the packet off upstairs */
118 /* The transmitter on the oboe chip can work in one of two modes */
119 /* for each ring->tx[] the transmitter can either */
120 /* a) transmit the packet, leave the trasmitter enabled and proceed to */
123 /* b) transmit the packet, switch off the transmitter and issue TxDone */
125 /* All packets are entered into the ring in mode b), if the ring was */
126 /* empty the transmitter is started. */
128 /* If OPTIMIZE_TX is defined then in TxDone if the ring contains */
129 /* more than one packet, all but the last are set to mode a) [HOWEVER */
130 /* the hardware may not notice this, this is why we start in mode b) ] */
131 /* then restart the transmitter */
133 /* If OPTIMIZE_TX is not defined then we just restart the transmitter */
134 /* if the ring isn't empty */
136 /* Speed changes are delayed until the TxRing is empty */
137 /* mtt is handled by generating packets with bad CRCs, before the data */
140 /* check the mtt works ok */
141 /* finish the watchdog */
143 /* No user servicable parts below here */
145 #include <linux/module.h>
147 #include <linux/kernel.h>
148 #include <linux/types.h>
149 #include <linux/skbuff.h>
150 #include <linux/netdevice.h>
151 #include <linux/ioport.h>
152 #include <linux/delay.h>
153 #include <linux/slab.h>
154 #include <linux/init.h>
155 #include <linux/interrupt.h>
156 #include <linux/pci.h>
157 #include <linux/rtnetlink.h>
161 #include <net/irda/wrapper.h>
162 #include <net/irda/irda.h>
163 //#include <net/irda/irmod.h>
164 //#include <net/irda/irlap_frame.h>
165 #include <net/irda/irda_device.h>
166 #include <net/irda/crc.h>
168 #include "donauboe.h"
170 #define INB(port) inb_p(port)
171 #define OUTB(val,port) outb_p(val,port)
172 #define OUTBP(val,port) outb_p(val,port)
174 #define PROMPT OUTB(OBOE_PROMPT_BIT,OBOE_PROMPT);
177 #define PROBE_DEBUG(args...) (printk (args))
179 #define PROBE_DEBUG(args...) ;
182 /* Set the DMA to be byte at a time */
183 #define CONFIG0H_DMA_OFF OBOE_CONFIG0H_RCVANY
184 #define CONFIG0H_DMA_ON_NORX CONFIG0H_DMA_OFF| OBOE_CONFIG0H_ENDMAC
185 #define CONFIG0H_DMA_ON CONFIG0H_DMA_ON_NORX | OBOE_CONFIG0H_ENRX
187 static const struct pci_device_id toshoboe_pci_tbl
[] = {
188 { PCI_VENDOR_ID_TOSHIBA
, PCI_DEVICE_ID_FIR701
, PCI_ANY_ID
, PCI_ANY_ID
, },
189 { PCI_VENDOR_ID_TOSHIBA
, PCI_DEVICE_ID_FIRD01
, PCI_ANY_ID
, PCI_ANY_ID
, },
190 { } /* Terminating entry */
192 MODULE_DEVICE_TABLE(pci
, toshoboe_pci_tbl
);
194 #define DRIVER_NAME "toshoboe"
195 static char *driver_name
= DRIVER_NAME
;
197 static int max_baud
= 4000000;
199 static bool do_probe
= false;
203 /**********************************************************************/
205 toshoboe_checkfcs (unsigned char *buf
, int len
)
215 fcs
.value
= INIT_FCS
;
217 for (i
= 0; i
< len
; ++i
)
218 fcs
.value
= irda_fcs (fcs
.value
, *(buf
++));
220 return fcs
.value
== GOOD_FCS
;
223 /***********************************************************************/
224 /* Generic chip handling code */
226 static unsigned char dump
[50];
228 _dumpbufs (unsigned char *data
, int len
, char tete
)
232 for (i
=0;i
<len
;i
+=16) {
233 for (j
=0;j
<16 && i
+j
<len
;j
++) { sprintf(&dump
[3*j
],"%02x.",data
[i
+j
]); }
235 pr_debug("%c%s\n", head
, dump
);
242 /* Dump the registers */
244 toshoboe_dumpregs (struct toshoboe_cb
*self
)
248 ringbase
= INB (OBOE_RING_BASE0
) << 10;
249 ringbase
|= INB (OBOE_RING_BASE1
) << 18;
250 ringbase
|= INB (OBOE_RING_BASE2
) << 26;
252 printk (KERN_ERR DRIVER_NAME
": Register dump:\n");
253 printk (KERN_ERR
"Interrupts: Tx:%d Rx:%d TxUnder:%d RxOver:%d Sip:%d\n",
254 self
->int_tx
, self
->int_rx
, self
->int_txunder
, self
->int_rxover
,
256 printk (KERN_ERR
"RX %02x TX %02x RingBase %08x\n",
257 INB (OBOE_RXSLOT
), INB (OBOE_TXSLOT
), ringbase
);
258 printk (KERN_ERR
"RING_SIZE %02x IER %02x ISR %02x\n",
259 INB (OBOE_RING_SIZE
), INB (OBOE_IER
), INB (OBOE_ISR
));
260 printk (KERN_ERR
"CONFIG1 %02x STATUS %02x\n",
261 INB (OBOE_CONFIG1
), INB (OBOE_STATUS
));
262 printk (KERN_ERR
"CONFIG0 %02x%02x ENABLE %02x%02x\n",
263 INB (OBOE_CONFIG0H
), INB (OBOE_CONFIG0L
),
264 INB (OBOE_ENABLEH
), INB (OBOE_ENABLEL
));
265 printk (KERN_ERR
"NEW_PCONFIG %02x%02x CURR_PCONFIG %02x%02x\n",
266 INB (OBOE_NEW_PCONFIGH
), INB (OBOE_NEW_PCONFIGL
),
267 INB (OBOE_CURR_PCONFIGH
), INB (OBOE_CURR_PCONFIGL
));
268 printk (KERN_ERR
"MAXLEN %02x%02x RXCOUNT %02x%02x\n",
269 INB (OBOE_MAXLENH
), INB (OBOE_MAXLENL
),
270 INB (OBOE_RXCOUNTL
), INB (OBOE_RXCOUNTH
));
275 ringbase
= virt_to_bus (self
->ring
);
276 printk (KERN_ERR
"Ring at %08x:\n", ringbase
);
277 printk (KERN_ERR
"RX:");
278 for (i
= 0; i
< RX_SLOTS
; ++i
)
279 printk (" (%d,%02x)",self
->ring
->rx
[i
].len
,self
->ring
->rx
[i
].control
);
281 printk (KERN_ERR
"TX:");
282 for (i
= 0; i
< RX_SLOTS
; ++i
)
283 printk (" (%d,%02x)",self
->ring
->tx
[i
].len
,self
->ring
->tx
[i
].control
);
289 /*Don't let the chip look at memory */
291 toshoboe_disablebm (struct toshoboe_cb
*self
)
294 pci_read_config_byte (self
->pdev
, PCI_COMMAND
, &command
);
295 command
&= ~PCI_COMMAND_MASTER
;
296 pci_write_config_byte (self
->pdev
, PCI_COMMAND
, command
);
300 /* Shutdown the chip and point the taskfile reg somewhere else */
302 toshoboe_stopchip (struct toshoboe_cb
*self
)
304 /*Disable interrupts */
305 OUTB (0x0, OBOE_IER
);
306 /*Disable DMA, Disable Rx, Disable Tx */
307 OUTB (CONFIG0H_DMA_OFF
, OBOE_CONFIG0H
);
308 /*Disable SIR MIR FIR, Tx and Rx */
309 OUTB (0x00, OBOE_ENABLEH
);
310 /*Point the ring somewhere safe */
311 OUTB (0x3f, OBOE_RING_BASE2
);
312 OUTB (0xff, OBOE_RING_BASE1
);
313 OUTB (0xff, OBOE_RING_BASE0
);
315 OUTB (RX_LEN
>> 8, OBOE_MAXLENH
);
316 OUTB (RX_LEN
& 0xff, OBOE_MAXLENL
);
318 /*Acknoledge any pending interrupts */
319 OUTB (0xff, OBOE_ISR
);
322 OUTB (OBOE_ENABLEH_PHYANDCLOCK
, OBOE_ENABLEH
);
325 OUTB (OBOE_CONFIG1_OFF
, OBOE_CONFIG1
);
327 toshoboe_disablebm (self
);
330 /* Transmitter initialization */
332 toshoboe_start_DMA (struct toshoboe_cb
*self
, int opts
)
334 OUTB (0x0, OBOE_ENABLEH
);
335 OUTB (CONFIG0H_DMA_ON
| opts
, OBOE_CONFIG0H
);
336 OUTB (OBOE_ENABLEH_PHYANDCLOCK
, OBOE_ENABLEH
);
340 /*Set the baud rate */
342 toshoboe_setbaud (struct toshoboe_cb
*self
)
347 pr_debug("%s(%d/%d)\n", __func__
, self
->speed
, self
->io
.speed
);
365 printk (KERN_ERR DRIVER_NAME
": switch to unsupported baudrate %d\n",
372 /* For SIR the preamble is done by adding XBOFs */
374 /* set to filtered SIR mode, filter looks for BOF and EOF */
376 pconfig
|= 47 << OBOE_PCONFIG_BAUDSHIFT
;
377 pconfig
|= 25 << OBOE_PCONFIG_WIDTHSHIFT
;
380 pconfig
|= 23 << OBOE_PCONFIG_BAUDSHIFT
;
381 pconfig
|= 25 << OBOE_PCONFIG_WIDTHSHIFT
;
384 pconfig
|= 11 << OBOE_PCONFIG_BAUDSHIFT
;
385 pconfig
|= 25 << OBOE_PCONFIG_WIDTHSHIFT
;
388 pconfig
|= 5 << OBOE_PCONFIG_BAUDSHIFT
;
389 pconfig
|= 25 << OBOE_PCONFIG_WIDTHSHIFT
;
392 pconfig
|= 2 << OBOE_PCONFIG_BAUDSHIFT
;
393 pconfig
|= 25 << OBOE_PCONFIG_WIDTHSHIFT
;
396 pconfig
|= 1 << OBOE_PCONFIG_BAUDSHIFT
;
397 pconfig
|= 25 << OBOE_PCONFIG_WIDTHSHIFT
;
400 pconfig
|= 0 << OBOE_PCONFIG_BAUDSHIFT
;
401 pconfig
|= 25 << OBOE_PCONFIG_WIDTHSHIFT
;
404 /*Set to packet based reception */
405 OUTB (RX_LEN
>> 8, OBOE_MAXLENH
);
406 OUTB (RX_LEN
& 0xff, OBOE_MAXLENL
);
419 config0l
= OBOE_CONFIG0L_ENSIR
;
422 /*Set to character based reception */
423 /*System will lock if MAXLEN=0 */
424 /*so have to be careful */
425 OUTB (0x01, OBOE_MAXLENH
);
426 OUTB (0x01, OBOE_MAXLENL
);
427 OUTB (0x00, OBOE_MAXLENH
);
431 /*Set to packet based reception */
432 config0l
|= OBOE_CONFIG0L_ENSIRF
;
433 OUTB (RX_LEN
>> 8, OBOE_MAXLENH
);
434 OUTB (RX_LEN
& 0xff, OBOE_MAXLENL
);
440 /* Set for 16 bit CRC and enable MIR */
441 /* Preamble now handled by the chip */
443 pconfig
|= 0 << OBOE_PCONFIG_BAUDSHIFT
;
444 pconfig
|= 8 << OBOE_PCONFIG_WIDTHSHIFT
;
445 pconfig
|= 1 << OBOE_PCONFIG_PREAMBLESHIFT
;
446 config0l
= OBOE_CONFIG0L_CRC16
| OBOE_CONFIG0L_ENMIR
;
450 /* Set for 32 bit CRC and enable FIR */
451 /* Preamble handled by the chip */
453 pconfig
|= 0 << OBOE_PCONFIG_BAUDSHIFT
;
454 /* Documentation says 14, but toshiba use 15 in their drivers */
455 pconfig
|= 15 << OBOE_PCONFIG_PREAMBLESHIFT
;
456 config0l
= OBOE_CONFIG0L_ENFIR
;
460 /* Copy into new PHY config buffer */
461 OUTBP (pconfig
>> 8, OBOE_NEW_PCONFIGH
);
462 OUTB (pconfig
& 0xff, OBOE_NEW_PCONFIGL
);
463 OUTB (config0l
, OBOE_CONFIG0L
);
465 /* Now make OBOE copy from new PHY to current PHY */
466 OUTB (0x0, OBOE_ENABLEH
);
467 OUTB (OBOE_ENABLEH_PHYANDCLOCK
, OBOE_ENABLEH
);
470 /* speed change executed */
472 self
->io
.speed
= self
->speed
;
475 /*Let the chip look at memory */
477 toshoboe_enablebm (struct toshoboe_cb
*self
)
479 pci_set_master (self
->pdev
);
484 toshoboe_initring (struct toshoboe_cb
*self
)
488 for (i
= 0; i
< TX_SLOTS
; ++i
)
490 self
->ring
->tx
[i
].len
= 0;
491 self
->ring
->tx
[i
].control
= 0x00;
492 self
->ring
->tx
[i
].address
= virt_to_bus (self
->tx_bufs
[i
]);
495 for (i
= 0; i
< RX_SLOTS
; ++i
)
497 self
->ring
->rx
[i
].len
= RX_LEN
;
498 self
->ring
->rx
[i
].len
= 0;
499 self
->ring
->rx
[i
].address
= virt_to_bus (self
->rx_bufs
[i
]);
500 self
->ring
->rx
[i
].control
= OBOE_CTL_RX_HW_OWNS
;
505 toshoboe_resetptrs (struct toshoboe_cb
*self
)
507 /* Can reset pointers by twidling DMA */
508 OUTB (0x0, OBOE_ENABLEH
);
509 OUTBP (CONFIG0H_DMA_OFF
, OBOE_CONFIG0H
);
510 OUTB (OBOE_ENABLEH_PHYANDCLOCK
, OBOE_ENABLEH
);
512 self
->rxs
= inb_p (OBOE_RXSLOT
) & OBOE_SLOT_MASK
;
513 self
->txs
= inb_p (OBOE_TXSLOT
) & OBOE_SLOT_MASK
;
516 /* Called in locked state */
518 toshoboe_initptrs (struct toshoboe_cb
*self
)
521 /* spin_lock_irqsave(self->spinlock, flags); */
522 /* save_flags (flags); */
524 /* Can reset pointers by twidling DMA */
525 toshoboe_resetptrs (self
);
527 OUTB (0x0, OBOE_ENABLEH
);
528 OUTB (CONFIG0H_DMA_ON
, OBOE_CONFIG0H
);
529 OUTB (OBOE_ENABLEH_PHYANDCLOCK
, OBOE_ENABLEH
);
533 /* spin_unlock_irqrestore(self->spinlock, flags); */
534 /* restore_flags (flags); */
537 /* Wake the chip up and get it looking at the rings */
538 /* Called in locked state */
540 toshoboe_startchip (struct toshoboe_cb
*self
)
544 toshoboe_initring (self
);
545 toshoboe_enablebm (self
);
546 OUTBP (OBOE_CONFIG1_RESET
, OBOE_CONFIG1
);
547 OUTBP (OBOE_CONFIG1_ON
, OBOE_CONFIG1
);
549 /* Stop the clocks */
550 OUTB (0, OBOE_ENABLEH
);
552 /*Set size of rings */
553 OUTB (RING_SIZE
, OBOE_RING_SIZE
);
555 /*Acknoledge any pending interrupts */
556 OUTB (0xff, OBOE_ISR
);
559 OUTB (OBOE_INT_TXDONE
| OBOE_INT_RXDONE
|
560 OBOE_INT_TXUNDER
| OBOE_INT_RXOVER
| OBOE_INT_SIP
, OBOE_IER
);
562 /*Acknoledge any pending interrupts */
563 OUTB (0xff, OBOE_ISR
);
565 /*Set the maximum packet length to 0xfff (4095) */
566 OUTB (RX_LEN
>> 8, OBOE_MAXLENH
);
567 OUTB (RX_LEN
& 0xff, OBOE_MAXLENL
);
570 OUTB (CONFIG0H_DMA_OFF
, OBOE_CONFIG0H
);
572 /*Find out where the rings live */
573 physaddr
= virt_to_bus (self
->ring
);
575 IRDA_ASSERT ((physaddr
& 0x3ff) == 0,
576 printk (KERN_ERR DRIVER_NAME
"ring not correctly aligned\n");
579 OUTB ((physaddr
>> 10) & 0xff, OBOE_RING_BASE0
);
580 OUTB ((physaddr
>> 18) & 0xff, OBOE_RING_BASE1
);
581 OUTB ((physaddr
>> 26) & 0x3f, OBOE_RING_BASE2
);
583 /*Enable DMA controller in byte mode and RX */
584 OUTB (CONFIG0H_DMA_ON
, OBOE_CONFIG0H
);
586 /* Start up the clocks */
587 OUTB (OBOE_ENABLEH_PHYANDCLOCK
, OBOE_ENABLEH
);
589 /*set to sensible speed */
591 toshoboe_setbaud (self
);
592 toshoboe_initptrs (self
);
596 toshoboe_isntstuck (struct toshoboe_cb
*self
)
601 toshoboe_checkstuck (struct toshoboe_cb
*self
)
607 spin_lock_irqsave(&self
->spinlock
, flags
);
609 /* This will reset the chip completely */
610 printk (KERN_ERR DRIVER_NAME
": Resetting chip\n");
612 toshoboe_stopchip (self
);
613 toshoboe_startchip (self
);
614 spin_unlock_irqrestore(&self
->spinlock
, flags
);
618 /*Generate packet of about mtt us long */
620 toshoboe_makemttpacket (struct toshoboe_cb
*self
, void *buf
, int mtt
)
624 xbofs
= ((int) (mtt
/100)) * (int) (self
->speed
);
625 xbofs
=xbofs
/80000; /*Eight bits per byte, and mtt is in us*/
628 pr_debug(DRIVER_NAME
": generated mtt of %d bytes for %d us at %d baud\n",
629 xbofs
, mtt
, self
->speed
);
633 printk (KERN_ERR DRIVER_NAME
": wanted %d bytes MTT but TX_LEN is %d\n",
638 /*xbofs will do for SIR, MIR and FIR,SIR mode doesn't generate a checksum anyway */
639 memset (buf
, XBOF
, xbofs
);
645 /***********************************************************************/
649 toshoboe_dumptx (struct toshoboe_cb
*self
)
652 PROBE_DEBUG(KERN_WARNING
"TX:");
653 for (i
= 0; i
< RX_SLOTS
; ++i
)
654 PROBE_DEBUG(" (%d,%02x)",self
->ring
->tx
[i
].len
,self
->ring
->tx
[i
].control
);
655 PROBE_DEBUG(" [%d]\n",self
->speed
);
659 toshoboe_dumprx (struct toshoboe_cb
*self
, int score
)
662 PROBE_DEBUG(" %d\nRX:",score
);
663 for (i
= 0; i
< RX_SLOTS
; ++i
)
664 PROBE_DEBUG(" (%d,%02x)",self
->ring
->rx
[i
].len
,self
->ring
->rx
[i
].control
);
669 stuff_byte (__u8 byte
, __u8
* buf
)
673 case BOF
: /* FALLTHROUGH */
674 case EOF
: /* FALLTHROUGH */
676 /* Insert transparently coded */
677 buf
[0] = CE
; /* Send link escape */
678 buf
[1] = byte
^ IRDA_TRANS
; /* Complement bit 5 */
682 /* Non-special value, no transparency required */
690 toshoboe_probeinterrupt (int irq
, void *dev_id
)
692 struct toshoboe_cb
*self
= dev_id
;
695 irqstat
= INB (OBOE_ISR
);
698 if (!(irqstat
& OBOE_INT_MASK
))
701 /* Ack all the interrupts */
702 OUTB (irqstat
, OBOE_ISR
);
704 if (irqstat
& OBOE_INT_TXDONE
)
711 txp
= INB (OBOE_TXSLOT
) & OBOE_SLOT_MASK
;
712 if (self
->ring
->tx
[txp
].control
& OBOE_CTL_TX_HW_OWNS
)
716 toshoboe_start_DMA(self
, OBOE_CONFIG0H_ENTX
| OBOE_CONFIG0H_LOOP
);
720 if (irqstat
& OBOE_INT_RXDONE
) {
723 if (irqstat
& OBOE_INT_TXUNDER
) {
726 if (irqstat
& OBOE_INT_RXOVER
) {
729 if (irqstat
& OBOE_INT_SIP
) {
736 toshoboe_maketestpacket (unsigned char *buf
, int badcrc
, int fir
)
749 memset (buf
, 0, TT_LEN
);
753 fcs
.value
= INIT_FCS
;
755 memset (buf
, XBOF
, 10);
759 for (i
= 0; i
< TT_LEN
; ++i
)
761 len
+= stuff_byte (i
, buf
+ len
);
762 fcs
.value
= irda_fcs (fcs
.value
, i
);
765 len
+= stuff_byte (fcs
.bytes
[0] ^ badcrc
, buf
+ len
);
766 len
+= stuff_byte (fcs
.bytes
[1] ^ badcrc
, buf
+ len
);
773 toshoboe_probefail (struct toshoboe_cb
*self
, char *msg
)
775 printk (KERN_ERR DRIVER_NAME
"probe(%d) failed %s\n",self
-> speed
, msg
);
776 toshoboe_dumpregs (self
);
777 toshoboe_stopchip (self
);
778 free_irq (self
->io
.irq
, (void *) self
);
783 toshoboe_numvalidrcvs (struct toshoboe_cb
*self
)
786 for (i
= 0; i
< RX_SLOTS
; ++i
)
787 if ((self
->ring
->rx
[i
].control
& 0xe0) == 0)
794 toshoboe_numrcvs (struct toshoboe_cb
*self
)
797 for (i
= 0; i
< RX_SLOTS
; ++i
)
798 if (!(self
->ring
->rx
[i
].control
& OBOE_CTL_RX_HW_OWNS
))
805 toshoboe_probe (struct toshoboe_cb
*self
)
809 static const int bauds
[] = { 9600, 115200, 4000000, 1152000 };
811 static const int bauds
[] = { 9600, 115200, 4000000 };
815 if (request_irq (self
->io
.irq
, toshoboe_probeinterrupt
,
816 self
->io
.irqflags
, "toshoboe", (void *) self
))
818 printk (KERN_ERR DRIVER_NAME
": probe failed to allocate irq %d\n",
823 /* test 1: SIR filter and back to back */
825 for (j
= 0; j
< ARRAY_SIZE(bauds
); ++j
)
828 toshoboe_stopchip (self
);
831 spin_lock_irqsave(&self
->spinlock
, flags
);
832 /*Address is already setup */
833 toshoboe_startchip (self
);
834 self
->int_rx
= self
->int_tx
= 0;
835 self
->speed
= bauds
[j
];
836 toshoboe_setbaud (self
);
837 toshoboe_initptrs (self
);
838 spin_unlock_irqrestore(&self
->spinlock
, flags
);
840 self
->ring
->tx
[self
->txs
].control
=
841 /* (FIR only) OBOE_CTL_TX_SIP needed for switching to next slot */
842 /* MIR: all received data is stored in one slot */
843 (fir
) ? OBOE_CTL_TX_HW_OWNS
| OBOE_CTL_TX_RTCENTX
844 : OBOE_CTL_TX_HW_OWNS
;
845 self
->ring
->tx
[self
->txs
].len
=
846 toshoboe_maketestpacket (self
->tx_bufs
[self
->txs
], 0, fir
);
848 self
->txs
%= TX_SLOTS
;
850 self
->ring
->tx
[self
->txs
].control
=
851 (fir
) ? OBOE_CTL_TX_HW_OWNS
| OBOE_CTL_TX_SIP
852 : OBOE_CTL_TX_HW_OWNS
| OBOE_CTL_TX_RTCENTX
;
853 self
->ring
->tx
[self
->txs
].len
=
854 toshoboe_maketestpacket (self
->tx_bufs
[self
->txs
], 0, fir
);
856 self
->txs
%= TX_SLOTS
;
858 self
->ring
->tx
[self
->txs
].control
=
859 (fir
) ? OBOE_CTL_TX_HW_OWNS
| OBOE_CTL_TX_RTCENTX
860 : OBOE_CTL_TX_HW_OWNS
;
861 self
->ring
->tx
[self
->txs
].len
=
862 toshoboe_maketestpacket (self
->tx_bufs
[self
->txs
], 0, fir
);
864 self
->txs
%= TX_SLOTS
;
866 self
->ring
->tx
[self
->txs
].control
=
867 (fir
) ? OBOE_CTL_TX_HW_OWNS
| OBOE_CTL_TX_RTCENTX
868 | OBOE_CTL_TX_SIP
| OBOE_CTL_TX_BAD_CRC
869 : OBOE_CTL_TX_HW_OWNS
| OBOE_CTL_TX_RTCENTX
;
870 self
->ring
->tx
[self
->txs
].len
=
871 toshoboe_maketestpacket (self
->tx_bufs
[self
->txs
], 0, fir
);
873 self
->txs
%= TX_SLOTS
;
875 toshoboe_dumptx (self
);
876 /* Turn on TX and RX and loopback */
877 toshoboe_start_DMA(self
, OBOE_CONFIG0H_ENTX
| OBOE_CONFIG0H_LOOP
);
881 while (toshoboe_numvalidrcvs (self
) != n
)
884 return toshoboe_probefail (self
, "filter test");
885 udelay ((9600*(TT_LEN
+16))/self
->speed
);
890 while ((toshoboe_numrcvs(self
) != self
->int_rx
) || (self
->int_tx
!= n
))
893 return toshoboe_probefail (self
, "interrupt test");
894 udelay ((9600*(TT_LEN
+16))/self
->speed
);
897 toshoboe_dumprx (self
,i
);
901 /* test 2: SIR in char at a time */
903 toshoboe_stopchip (self
);
904 self
->int_rx
= self
->int_tx
= 0;
906 spin_lock_irqsave(&self
->spinlock
, flags
);
907 toshoboe_startchip (self
);
908 spin_unlock_irqrestore(&self
->spinlock
, flags
);
911 self
->speed
= 115200;
912 toshoboe_setbaud (self
);
913 self
->ring
->tx
[self
->txs
].control
=
914 OBOE_CTL_TX_RTCENTX
| OBOE_CTL_TX_HW_OWNS
;
915 self
->ring
->tx
[self
->txs
].len
= 4;
917 ((unsigned char *) self
->tx_bufs
[self
->txs
])[0] = 'f';
918 ((unsigned char *) self
->tx_bufs
[self
->txs
])[1] = 'i';
919 ((unsigned char *) self
->tx_bufs
[self
->txs
])[2] = 's';
920 ((unsigned char *) self
->tx_bufs
[self
->txs
])[3] = 'h';
921 toshoboe_dumptx (self
);
922 toshoboe_start_DMA(self
, OBOE_CONFIG0H_ENTX
| OBOE_CONFIG0H_LOOP
);
925 while (toshoboe_numvalidrcvs (self
) != 4)
928 return toshoboe_probefail (self
, "Async test");
933 while ((toshoboe_numrcvs (self
) != self
->int_rx
) || (self
->int_tx
!= 1))
936 return toshoboe_probefail (self
, "Async interrupt test");
940 toshoboe_dumprx (self
,i
);
944 toshoboe_setbaud (self
);
945 toshoboe_stopchip (self
);
947 free_irq (self
->io
.irq
, (void *) self
);
949 printk (KERN_WARNING DRIVER_NAME
": Self test passed ok\n");
955 /******************************************************************/
956 /* Netdev style code */
958 /* Transmit something */
960 toshoboe_hard_xmit (struct sk_buff
*skb
, struct net_device
*dev
)
962 struct toshoboe_cb
*self
;
966 struct irda_skb_cb
*cb
= (struct irda_skb_cb
*) skb
->cb
;
968 self
= netdev_priv(dev
);
970 IRDA_ASSERT (self
!= NULL
, return NETDEV_TX_OK
; );
972 pr_debug("%s.tx:%x(%x)%x\n",
973 __func__
, skb
->len
, self
->txpending
, INB(OBOE_ENABLEH
));
975 pr_debug("%s.Not IrLAP:%x\n", __func__
, cb
->magic
);
977 _dumpbufs(skb
->data
,skb
->len
,'>');
981 /* change speed pending, wait for its execution */
983 return NETDEV_TX_BUSY
;
985 /* device stopped (apm) wait for restart */
987 return NETDEV_TX_BUSY
;
989 toshoboe_checkstuck (self
);
991 /* Check if we need to change the speed */
992 /* But not now. Wait after transmission if mtt not required */
993 speed
=irda_get_next_speed(skb
);
994 if ((speed
!= self
->io
.speed
) && (speed
!= -1))
996 spin_lock_irqsave(&self
->spinlock
, flags
);
998 if (self
->txpending
|| skb
->len
)
1000 self
->new_speed
= speed
;
1001 pr_debug("%s: Queued TxDone scheduled speed change %d\n" ,
1003 /* if no data, that's all! */
1006 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1007 dev_kfree_skb (skb
);
1008 return NETDEV_TX_OK
;
1010 /* True packet, go on, but */
1011 /* do not accept anything before change speed execution */
1012 netif_stop_queue(dev
);
1013 /* ready to process TxDone interrupt */
1014 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1018 /* idle and no data, change speed now */
1019 self
->speed
= speed
;
1020 toshoboe_setbaud (self
);
1021 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1022 dev_kfree_skb (skb
);
1023 return NETDEV_TX_OK
;
1028 if ((mtt
= irda_get_mtt(skb
)))
1030 /* This is fair since the queue should be empty anyway */
1031 spin_lock_irqsave(&self
->spinlock
, flags
);
1033 if (self
->txpending
)
1035 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1036 return NETDEV_TX_BUSY
;
1039 /* If in SIR mode we need to generate a string of XBOFs */
1040 /* In MIR and FIR we need to generate a string of data */
1041 /* which we will add a wrong checksum to */
1043 mtt
= toshoboe_makemttpacket (self
, self
->tx_bufs
[self
->txs
], mtt
);
1044 pr_debug("%s.mtt:%x(%x)%d\n", __func__
, skb
->len
, mtt
, self
->txpending
);
1047 self
->ring
->tx
[self
->txs
].len
= mtt
& 0xfff;
1049 ctl
= OBOE_CTL_TX_HW_OWNS
| OBOE_CTL_TX_RTCENTX
;
1050 if (INB (OBOE_ENABLEH
) & OBOE_ENABLEH_FIRON
)
1052 ctl
|= OBOE_CTL_TX_BAD_CRC
| OBOE_CTL_TX_SIP
;
1055 else if (INB (OBOE_ENABLEH
) & OBOE_ENABLEH_MIRON
)
1057 ctl
|= OBOE_CTL_TX_BAD_CRC
;
1060 self
->ring
->tx
[self
->txs
].control
= ctl
;
1062 OUTB (0x0, OBOE_ENABLEH
);
1063 /* It is only a timer. Do not send mtt packet outside! */
1064 toshoboe_start_DMA(self
, OBOE_CONFIG0H_ENTX
| OBOE_CONFIG0H_LOOP
);
1069 self
->txs
%= TX_SLOTS
;
1074 printk(KERN_ERR DRIVER_NAME
": problem with mtt packet - ignored\n");
1076 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1080 dumpbufs(skb
->data
,skb
->len
,'>');
1083 spin_lock_irqsave(&self
->spinlock
, flags
);
1085 if (self
->ring
->tx
[self
->txs
].control
& OBOE_CTL_TX_HW_OWNS
)
1087 pr_debug("%s.ful:%x(%x)%x\n",
1088 __func__
, skb
->len
, self
->ring
->tx
[self
->txs
].control
,
1090 toshoboe_start_DMA(self
, OBOE_CONFIG0H_ENTX
);
1091 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1092 return NETDEV_TX_BUSY
;
1095 if (INB (OBOE_ENABLEH
) & OBOE_ENABLEH_SIRON
)
1097 len
= async_wrap_skb (skb
, self
->tx_bufs
[self
->txs
], TX_BUF_SZ
);
1102 skb_copy_from_linear_data(skb
, self
->tx_bufs
[self
->txs
], len
);
1104 self
->ring
->tx
[self
->txs
].len
= len
& 0x0fff;
1106 /*Sometimes the HW doesn't see us assert RTCENTX in the interrupt code */
1107 /*later this plays safe, we garuntee the last packet to be transmitted */
1108 /*has RTCENTX set */
1110 ctl
= OBOE_CTL_TX_HW_OWNS
| OBOE_CTL_TX_RTCENTX
;
1111 if (INB (OBOE_ENABLEH
) & OBOE_ENABLEH_FIRON
)
1113 ctl
|= OBOE_CTL_TX_SIP
;
1115 self
->ring
->tx
[self
->txs
].control
= ctl
;
1117 /* If transmitter is idle start in one-shot mode */
1119 if (!self
->txpending
)
1120 toshoboe_start_DMA(self
, OBOE_CONFIG0H_ENTX
);
1125 self
->txs
%= TX_SLOTS
;
1127 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1128 dev_kfree_skb (skb
);
1130 return NETDEV_TX_OK
;
1133 /*interrupt handler */
1135 toshoboe_interrupt (int irq
, void *dev_id
)
1137 struct toshoboe_cb
*self
= dev_id
;
1139 struct sk_buff
*skb
= NULL
;
1141 irqstat
= INB (OBOE_ISR
);
1144 if (!(irqstat
& OBOE_INT_MASK
))
1147 /* Ack all the interrupts */
1148 OUTB (irqstat
, OBOE_ISR
);
1150 toshoboe_isntstuck (self
);
1153 if (irqstat
& OBOE_INT_TXDONE
)
1158 txp
= self
->txpending
;
1159 self
->txpending
= 0;
1161 for (i
= 0; i
< TX_SLOTS
; ++i
)
1163 if (self
->ring
->tx
[i
].control
& OBOE_CTL_TX_HW_OWNS
)
1166 pr_debug("%s.txd(%x)%x/%x\n", __func__
, irqstat
, txp
, self
->txpending
);
1168 txp
= INB (OBOE_TXSLOT
) & OBOE_SLOT_MASK
;
1170 /* Got anything queued ? start it together */
1171 if (self
->ring
->tx
[txp
].control
& OBOE_CTL_TX_HW_OWNS
)
1175 while (self
->ring
->tx
[txpc
].control
& OBOE_CTL_TX_HW_OWNS
)
1180 self
->netdev
->stats
.tx_packets
++;
1181 if (self
->ring
->tx
[txpc
].control
& OBOE_CTL_TX_HW_OWNS
)
1182 self
->ring
->tx
[txp
].control
&= ~OBOE_CTL_TX_RTCENTX
;
1184 self
->netdev
->stats
.tx_packets
--;
1186 self
->netdev
->stats
.tx_packets
++;
1188 toshoboe_start_DMA(self
, OBOE_CONFIG0H_ENTX
);
1191 if ((!self
->txpending
) && (self
->new_speed
))
1193 self
->speed
= self
->new_speed
;
1194 pr_debug("%s: Executed TxDone scheduled speed change %d\n",
1195 __func__
, self
->speed
);
1196 toshoboe_setbaud (self
);
1199 /* Tell network layer that we want more frames */
1200 if (!self
->new_speed
)
1201 netif_wake_queue(self
->netdev
);
1204 if (irqstat
& OBOE_INT_RXDONE
)
1206 while (!(self
->ring
->rx
[self
->rxs
].control
& OBOE_CTL_RX_HW_OWNS
))
1208 int len
= self
->ring
->rx
[self
->rxs
].len
;
1210 pr_debug("%s.rcv:%x(%x)\n", __func__
1211 , len
, self
->ring
->rx
[self
->rxs
].control
);
1214 dumpbufs(self
->rx_bufs
[self
->rxs
],len
,'<');
1217 if (self
->ring
->rx
[self
->rxs
].control
== 0)
1219 __u8 enable
= INB (OBOE_ENABLEH
);
1221 /* In SIR mode we need to check the CRC as this */
1222 /* hasn't been done by the hardware */
1223 if (enable
& OBOE_ENABLEH_SIRON
)
1225 if (!toshoboe_checkfcs (self
->rx_bufs
[self
->rxs
], len
))
1227 /*Trim off the CRC */
1232 pr_debug("%s.SIR:%x(%x)\n", __func__
, len
, enable
);
1236 else if (enable
& OBOE_ENABLEH_MIRON
)
1242 pr_debug("%s.MIR:%x(%x)\n", __func__
, len
, enable
);
1245 else if (enable
& OBOE_ENABLEH_FIRON
)
1248 len
-= 4; /*FIXME: check this */
1251 pr_debug("%s.FIR:%x(%x)\n", __func__
, len
, enable
);
1254 pr_debug("%s.?IR:%x(%x)\n", __func__
, len
, enable
);
1258 skb
= dev_alloc_skb (len
+ 1);
1261 skb_reserve (skb
, 1);
1264 skb_copy_to_linear_data(skb
, self
->rx_bufs
[self
->rxs
],
1266 self
->netdev
->stats
.rx_packets
++;
1267 skb
->dev
= self
->netdev
;
1268 skb_reset_mac_header(skb
);
1269 skb
->protocol
= htons (ETH_P_IRDA
);
1274 "%s(), memory squeeze, dropping frame.\n",
1281 /* TODO: =========================================== */
1282 /* if OBOE_CTL_RX_LENGTH, our buffers are too small */
1283 /* (MIR or FIR) data is lost. */
1284 /* (SIR) data is splitted in several slots. */
1285 /* we have to join all the received buffers received */
1286 /*in a large buffer before checking CRC. */
1287 pr_debug("%s.err:%x(%x)\n", __func__
1288 , len
, self
->ring
->rx
[self
->rxs
].control
);
1291 self
->ring
->rx
[self
->rxs
].len
= 0x0;
1292 self
->ring
->rx
[self
->rxs
].control
= OBOE_CTL_RX_HW_OWNS
;
1295 self
->rxs
%= RX_SLOTS
;
1303 if (irqstat
& OBOE_INT_TXUNDER
)
1305 printk (KERN_WARNING DRIVER_NAME
": tx fifo underflow\n");
1307 if (irqstat
& OBOE_INT_RXOVER
)
1309 printk (KERN_WARNING DRIVER_NAME
": rx fifo overflow\n");
1311 /* This must be useful for something... */
1312 if (irqstat
& OBOE_INT_SIP
)
1315 pr_debug("%s.sip:%x(%x)%x\n",
1316 __func__
, self
->int_sip
, irqstat
, self
->txpending
);
1323 toshoboe_net_open (struct net_device
*dev
)
1325 struct toshoboe_cb
*self
;
1326 unsigned long flags
;
1329 self
= netdev_priv(dev
);
1337 rc
= request_irq (self
->io
.irq
, toshoboe_interrupt
,
1338 IRQF_SHARED
, dev
->name
, self
);
1342 spin_lock_irqsave(&self
->spinlock
, flags
);
1343 toshoboe_startchip (self
);
1344 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1346 /* Ready to play! */
1347 netif_start_queue(dev
);
1350 * Open new IrLAP layer instance, now that everything should be
1351 * initialized properly
1353 self
->irlap
= irlap_open (dev
, &self
->qos
, driver_name
);
1361 toshoboe_net_close (struct net_device
*dev
)
1363 struct toshoboe_cb
*self
;
1365 IRDA_ASSERT (dev
!= NULL
, return -1; );
1366 self
= netdev_priv(dev
);
1369 netif_stop_queue(dev
);
1371 /* Stop and remove instance of IrLAP */
1373 irlap_close (self
->irlap
);
1378 free_irq (self
->io
.irq
, (void *) self
);
1382 toshoboe_stopchip (self
);
1389 * Function toshoboe_net_ioctl (dev, rq, cmd)
1391 * Process IOCTL commands for this device
1395 toshoboe_net_ioctl (struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1397 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
1398 struct toshoboe_cb
*self
;
1399 unsigned long flags
;
1402 IRDA_ASSERT (dev
!= NULL
, return -1; );
1404 self
= netdev_priv(dev
);
1406 IRDA_ASSERT (self
!= NULL
, return -1; );
1408 pr_debug("%s(), %s, (cmd=0x%X)\n", __func__
, dev
->name
, cmd
);
1410 /* Disable interrupts & save flags */
1411 spin_lock_irqsave(&self
->spinlock
, flags
);
1415 case SIOCSBANDWIDTH
: /* Set bandwidth */
1416 /* This function will also be used by IrLAP to change the
1417 * speed, so we still must allow for speed change within
1418 * interrupt context.
1420 pr_debug("%s(BANDWIDTH), %s, (%X/%ld\n",
1421 __func__
, dev
->name
, INB(OBOE_STATUS
), irq
->ifr_baudrate
);
1422 if (!in_interrupt () && !capable (CAP_NET_ADMIN
)) {
1427 /* self->speed=irq->ifr_baudrate; */
1428 /* toshoboe_setbaud(self); */
1429 /* Just change speed once - inserted by Paul Bristow */
1430 self
->new_speed
= irq
->ifr_baudrate
;
1432 case SIOCSMEDIABUSY
: /* Set media busy */
1433 pr_debug("%s(MEDIABUSY), %s, (%X/%x)\n",
1434 __func__
, dev
->name
,
1435 INB(OBOE_STATUS
), capable(CAP_NET_ADMIN
));
1436 if (!capable (CAP_NET_ADMIN
)) {
1440 irda_device_set_media_busy (self
->netdev
, TRUE
);
1442 case SIOCGRECEIVING
: /* Check if we are receiving right now */
1443 irq
->ifr_receiving
= (INB (OBOE_STATUS
) & OBOE_STATUS_RXBUSY
) ? 1 : 0;
1444 pr_debug("%s(RECEIVING), %s, (%X/%x)\n",
1445 __func__
, dev
->name
, INB(OBOE_STATUS
), irq
->ifr_receiving
);
1448 pr_debug("%s(?), %s, (cmd=0x%X)\n", __func__
, dev
->name
, cmd
);
1452 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1457 MODULE_DESCRIPTION("Toshiba OBOE IrDA Device Driver");
1458 MODULE_AUTHOR("James McKenzie <james@fishsoup.dhs.org>");
1459 MODULE_LICENSE("GPL");
1461 module_param (max_baud
, int, 0);
1462 MODULE_PARM_DESC(max_baud
, "Maximum baud rate");
1465 module_param (do_probe
, bool, 0);
1466 MODULE_PARM_DESC(do_probe
, "Enable/disable chip probing and self-test");
1470 toshoboe_close (struct pci_dev
*pci_dev
)
1473 struct toshoboe_cb
*self
= pci_get_drvdata(pci_dev
);
1475 IRDA_ASSERT (self
!= NULL
, return; );
1479 toshoboe_stopchip (self
);
1482 release_region (self
->io
.fir_base
, self
->io
.fir_ext
);
1484 for (i
= 0; i
< TX_SLOTS
; ++i
)
1486 kfree (self
->tx_bufs
[i
]);
1487 self
->tx_bufs
[i
] = NULL
;
1490 for (i
= 0; i
< RX_SLOTS
; ++i
)
1492 kfree (self
->rx_bufs
[i
]);
1493 self
->rx_bufs
[i
] = NULL
;
1496 unregister_netdev(self
->netdev
);
1498 kfree (self
->ringbuf
);
1499 self
->ringbuf
= NULL
;
1502 free_netdev(self
->netdev
);
1505 static const struct net_device_ops toshoboe_netdev_ops
= {
1506 .ndo_open
= toshoboe_net_open
,
1507 .ndo_stop
= toshoboe_net_close
,
1508 .ndo_start_xmit
= toshoboe_hard_xmit
,
1509 .ndo_do_ioctl
= toshoboe_net_ioctl
,
1513 toshoboe_open (struct pci_dev
*pci_dev
, const struct pci_device_id
*pdid
)
1515 struct toshoboe_cb
*self
;
1516 struct net_device
*dev
;
1521 if ((err
=pci_enable_device(pci_dev
)))
1524 dev
= alloc_irdadev(sizeof (struct toshoboe_cb
));
1527 printk (KERN_ERR DRIVER_NAME
": can't allocate memory for "
1528 "IrDA control block\n");
1532 self
= netdev_priv(dev
);
1534 self
->pdev
= pci_dev
;
1535 self
->base
= pci_resource_start(pci_dev
,0);
1537 self
->io
.fir_base
= self
->base
;
1538 self
->io
.fir_ext
= OBOE_IO_EXTENT
;
1539 self
->io
.irq
= pci_dev
->irq
;
1540 self
->io
.irqflags
= IRQF_SHARED
;
1542 self
->speed
= self
->io
.speed
= 9600;
1545 /* Lock the port that we need */
1546 if (NULL
==request_region (self
->io
.fir_base
, self
->io
.fir_ext
, driver_name
))
1548 printk (KERN_ERR DRIVER_NAME
": can't get iobase of 0x%03x\n"
1549 ,self
->io
.fir_base
);
1554 spin_lock_init(&self
->spinlock
);
1556 irda_init_max_qos_capabilies (&self
->qos
);
1557 self
->qos
.baud_rate
.bits
= 0;
1559 if (max_baud
>= 2400)
1560 self
->qos
.baud_rate
.bits
|= IR_2400
;
1561 /*if (max_baud>=4800) idev->qos.baud_rate.bits|=IR_4800; */
1562 if (max_baud
>= 9600)
1563 self
->qos
.baud_rate
.bits
|= IR_9600
;
1564 if (max_baud
>= 19200)
1565 self
->qos
.baud_rate
.bits
|= IR_19200
;
1566 if (max_baud
>= 115200)
1567 self
->qos
.baud_rate
.bits
|= IR_115200
;
1569 if (max_baud
>= 1152000)
1571 self
->qos
.baud_rate
.bits
|= IR_1152000
;
1574 if (max_baud
>= 4000000)
1576 self
->qos
.baud_rate
.bits
|= (IR_4000000
<< 8);
1579 /*FIXME: work this out... */
1580 self
->qos
.min_turn_time
.bits
= 0xff;
1582 irda_qos_bits_to_value (&self
->qos
);
1584 /* Allocate twice the size to guarantee alignment */
1585 self
->ringbuf
= kmalloc(OBOE_RING_LEN
<< 1, GFP_KERNEL
);
1592 #if (BITS_PER_LONG == 64)
1593 #error broken on 64-bit: casts pointer to 32-bit, and then back to pointer.
1596 /*We need to align the taskfile on a taskfile size boundary */
1600 addr
= (__u32
) self
->ringbuf
;
1601 addr
&= ~(OBOE_RING_LEN
- 1);
1602 addr
+= OBOE_RING_LEN
;
1603 self
->ring
= (struct OboeRing
*) addr
;
1606 memset (self
->ring
, 0, OBOE_RING_LEN
);
1607 self
->io
.mem_base
= (__u32
) self
->ring
;
1610 for (i
= 0; i
< TX_SLOTS
; ++i
)
1612 self
->tx_bufs
[i
] = kmalloc (TX_BUF_SZ
, GFP_KERNEL
);
1613 if (!self
->tx_bufs
[i
])
1617 for (i
= 0; i
< RX_SLOTS
; ++i
)
1619 self
->rx_bufs
[i
] = kmalloc (RX_BUF_SZ
, GFP_KERNEL
);
1620 if (!self
->rx_bufs
[i
])
1633 if (!toshoboe_probe (self
))
1640 SET_NETDEV_DEV(dev
, &pci_dev
->dev
);
1641 dev
->netdev_ops
= &toshoboe_netdev_ops
;
1643 err
= register_netdev(dev
);
1646 printk (KERN_ERR DRIVER_NAME
": register_netdev() failed\n");
1650 printk (KERN_INFO
"IrDA: Registered device %s\n", dev
->name
);
1652 pci_set_drvdata(pci_dev
,self
);
1654 printk (KERN_INFO DRIVER_NAME
": Using multiple tasks\n");
1659 for (i
= 0; i
< TX_SLOTS
; ++i
)
1660 kfree (self
->tx_bufs
[i
]);
1661 for (i
= 0; i
< RX_SLOTS
; ++i
)
1662 kfree (self
->rx_bufs
[i
]);
1663 kfree(self
->ringbuf
);
1666 release_region (self
->io
.fir_base
, self
->io
.fir_ext
);
1675 toshoboe_gotosleep (struct pci_dev
*pci_dev
, pm_message_t crap
)
1677 struct toshoboe_cb
*self
= pci_get_drvdata(pci_dev
);
1678 unsigned long flags
;
1681 if (!self
|| self
->stopped
)
1684 if ((!self
->irdad
) && (!self
->async
))
1687 /* Flush all packets */
1688 while ((i
--) && (self
->txpending
))
1691 spin_lock_irqsave(&self
->spinlock
, flags
);
1693 toshoboe_stopchip (self
);
1695 self
->txpending
= 0;
1697 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1702 toshoboe_wakeup (struct pci_dev
*pci_dev
)
1704 struct toshoboe_cb
*self
= pci_get_drvdata(pci_dev
);
1705 unsigned long flags
;
1707 if (!self
|| !self
->stopped
)
1710 if ((!self
->irdad
) && (!self
->async
))
1713 spin_lock_irqsave(&self
->spinlock
, flags
);
1715 toshoboe_startchip (self
);
1718 netif_wake_queue(self
->netdev
);
1719 spin_unlock_irqrestore(&self
->spinlock
, flags
);
1723 static struct pci_driver donauboe_pci_driver
= {
1725 .id_table
= toshoboe_pci_tbl
,
1726 .probe
= toshoboe_open
,
1727 .remove
= toshoboe_close
,
1728 .suspend
= toshoboe_gotosleep
,
1729 .resume
= toshoboe_wakeup
1732 module_pci_driver(donauboe_pci_driver
);