📄 donauboe.c
字号:
/***************************************************************** * * Filename: donauboe.c * Version: 2.17 * Description: Driver for the Toshiba OBOE (or type-O or 701) * FIR Chipset, also supports the DONAUOBOE (type-DO * or d01) FIR chipset which as far as I know is * register compatible. * Documentation: http://libxg.free.fr/irda/lib-irda.html * Status: Experimental. * Author: James McKenzie <james@fishsoup.dhs.org> * Created at: Sat May 8 12:35:27 1999 * Modified: Paul Bristow <paul.bristow@technologist.com> * Modified: Mon Nov 11 19:10:05 1999 * Modified: James McKenzie <james@fishsoup.dhs.org> * Modified: Thu Mar 16 12:49:00 2000 (Substantial rewrite) * Modified: Sat Apr 29 00:23:03 2000 (Added DONAUOBOE support) * Modified: Wed May 24 23:45:02 2000 (Fixed chipio_t structure) * Modified: 2.13 Christian Gennerat <christian.gennerat@polytechnique.org> * Modified: 2.13 dim jan 07 21:57:39 2001 (tested with kernel 2.4 & irnet/ppp) * Modified: 2.14 Christian Gennerat <christian.gennerat@polytechnique.org> * Modified: 2.14 lun fev 05 17:55:59 2001 (adapted to patch-2.4.1-pre8-irda1) * Modified: 2.15 Martin Lucina <mato@kotelna.sk> * Modified: 2.15 Fri Jun 21 20:40:59 2002 (sync with 2.4.18, substantial fixes) * Modified: 2.16 Martin Lucina <mato@kotelna.sk> * Modified: 2.16 Sat Jun 22 18:54:29 2002 (fix freeregion, default to verbose) * Modified: 2.17 Christian Gennerat <christian.gennerat@polytechnique.org> * Modified: 2.17 jeu sep 12 08:50:20 2002 (save_flags();cli(); replaced by spinlocks) * Modified: 2.18 Christian Gennerat <christian.gennerat@polytechnique.org> * Modified: 2.18 ven jan 10 03:14:16 2003 Change probe default options * * Copyright (c) 1999 James McKenzie, All Rights Reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Neither James McKenzie nor Cambridge University admit liability nor * provide warranty for any of this software. This material is * provided "AS-IS" and at no charge. * * Applicable Models : Libretto 100/110CT and many more. * Toshiba refers to this chip as the type-O IR port, * or the type-DO IR port. * ********************************************************************//* Look at toshoboe.h (currently in include/net/irda) for details of *//* Where to get documentation on the chip */static char *rcsid = "$Id: donauboe.c V2.18 ven jan 10 03:14:16 2003$";/* See below for a description of the logic in this driver *//* User servicable parts *//* USE_PROBE Create the code which probes the chip and does a few tests *//* do_probe module parameter Enable this code *//* Probe code is very useful for understanding how the hardware works *//* Use it with various combinations of TT_LEN, RX_LEN *//* Strongly recomended, disable if the probe fails on your machine *//* and send me <james@fishsoup.dhs.org> the output of dmesg */#define USE_PROBE 1#undef USE_PROBE/* Trace Transmit ring, interrupts, Receive ring or not ? */#define PROBE_VERBOSE 1/* Debug option, examine sent and received raw data *//* Irdadump is better, but does not see all packets. enable it if you want. */#undef DUMP_PACKETS/* MIR mode has not been tested. Some behaviour is different *//* Seems to work against an Ericsson R520 for me. -Martin */#define USE_MIR/* Schedule back to back hardware transmits wherever possible, otherwise *//* we need an interrupt for every frame, unset if oboe works for a bit and *//* then hangs */#define OPTIMIZE_TX/* Set the number of slots in the rings *//* If you get rx/tx fifo overflows at high bitrates, you can try increasing *//* these */#define RING_SIZE (OBOE_RING_SIZE_RX8 | OBOE_RING_SIZE_TX8)#define TX_SLOTS 8#define RX_SLOTS 8/* Less user servicable parts below here *//* Test, Transmit and receive buffer sizes, adjust at your peril *//* remarks: nfs usually needs 1k blocks *//* remarks: in SIR mode, CRC is received, -> RX_LEN=TX_LEN+2 *//* remarks: test accepts large blocks. Standard is 0x80 *//* When TT_LEN > RX_LEN (SIR mode) data is stored in successive slots. *//* When 3 or more slots are needed for each test packet, *//* data received in the first slots is overwritten, even *//* if OBOE_CTL_RX_HW_OWNS is not set, without any error! */#define TT_LEN 0x80#define TX_LEN 0xc00#define RX_LEN 0xc04/* Real transmitted length (SIR mode) is about 14+(2%*TX_LEN) more *//* long than user-defined length (see async_wrap_skb) and is less then 4K *//* Real received length is (max RX_LEN) differs from user-defined *//* length only b the CRC (2 or 4 bytes) */#define BUF_SAFETY 0x7a#define RX_BUF_SZ (RX_LEN)#define TX_BUF_SZ (TX_LEN+BUF_SAFETY)/* Logic of the netdev part of this driver *//* The RX ring is filled with buffers, when a packet arrives *//* it is DMA'd into the buffer which is marked used and RxDone called *//* RxDone forms an skb (and checks the CRC if in SIR mode) and ships *//* the packet off upstairs *//* The transmitter on the oboe chip can work in one of two modes *//* for each ring->tx[] the transmitter can either *//* a) transmit the packet, leave the trasmitter enabled and proceed to *//* the next ring *//* OR *//* b) transmit the packet, switch off the transmitter and issue TxDone *//* All packets are entered into the ring in mode b), if the ring was *//* empty the transmitter is started. *//* If OPTIMIZE_TX is defined then in TxDone if the ring contains *//* more than one packet, all but the last are set to mode a) [HOWEVER *//* the hardware may not notice this, this is why we start in mode b) ] *//* then restart the transmitter *//* If OPTIMIZE_TX is not defined then we just restart the transmitter *//* if the ring isn't empty *//* Speed changes are delayed until the TxRing is empty *//* mtt is handled by generating packets with bad CRCs, before the data *//* TODO: *//* check the mtt works ok *//* finish the watchdog *//* No user servicable parts below here */#include <linux/module.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/skbuff.h>#include <linux/netdevice.h>#include <linux/ioport.h>#include <linux/delay.h>#include <linux/slab.h>#include <linux/init.h>#include <linux/pci.h>#include <linux/rtnetlink.h>#include <asm/system.h>#include <asm/io.h>#include <net/irda/wrapper.h>#include <net/irda/irda.h>//#include <net/irda/irmod.h>//#include <net/irda/irlap_frame.h>#include <net/irda/irda_device.h>#include <net/irda/crc.h>#include "donauboe.h"#define INB(port) inb_p(port)#define OUTB(val,port) outb_p(val,port)#define OUTBP(val,port) outb_p(val,port)#define PROMPT OUTB(OBOE_PROMPT_BIT,OBOE_PROMPT);#if PROBE_VERBOSE#define PROBE_DEBUG(args...) (printk (args))#else#define PROBE_DEBUG(args...) ;#endif/* Set the DMA to be byte at a time */#define CONFIG0H_DMA_OFF OBOE_CONFIG0H_RCVANY#define CONFIG0H_DMA_ON_NORX CONFIG0H_DMA_OFF| OBOE_CONFIG0H_ENDMAC#define CONFIG0H_DMA_ON CONFIG0H_DMA_ON_NORX | OBOE_CONFIG0H_ENRXstatic struct pci_device_id toshoboe_pci_tbl[] = { { PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_FIR701, PCI_ANY_ID, PCI_ANY_ID, }, { PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_FIRD01, PCI_ANY_ID, PCI_ANY_ID, }, { } /* Terminating entry */};MODULE_DEVICE_TABLE(pci, toshoboe_pci_tbl);#define DRIVER_NAME "toshoboe"static char *driver_name = DRIVER_NAME;static int max_baud = 4000000;#ifdef USE_PROBEstatic int do_probe = 0;#endif/**********************************************************************/static inttoshoboe_checkfcs (unsigned char *buf, int len){ int i; union { __u16 value; __u8 bytes[2]; } fcs; fcs.value = INIT_FCS; for (i = 0; i < len; ++i) fcs.value = irda_fcs (fcs.value, *(buf++)); return (fcs.value == GOOD_FCS);}/***********************************************************************//* Generic chip handling code */#ifdef DUMP_PACKETSstatic unsigned char dump[50];static void_dumpbufs (unsigned char *data, int len, char tete){int i,j;char head=tete;for (i=0;i<len;i+=16) { for (j=0;j<16 && i+j<len;j++) { sprintf(&dump[3*j],"%02x.",data[i+j]); } dump [3*j]=0; IRDA_DEBUG (2, "%c%s\n",head , dump); head='+'; }}#endif#ifdef USE_PROBE/* Dump the registers */static voidtoshoboe_dumpregs (struct toshoboe_cb *self){ __u32 ringbase; IRDA_DEBUG (4, "%s()\n", __FUNCTION__); ringbase = INB (OBOE_RING_BASE0) << 10; ringbase |= INB (OBOE_RING_BASE1) << 18; ringbase |= INB (OBOE_RING_BASE2) << 26; printk (KERN_ERR DRIVER_NAME ": Register dump:\n"); printk (KERN_ERR "Interrupts: Tx:%d Rx:%d TxUnder:%d RxOver:%d Sip:%d\n", self->int_tx, self->int_rx, self->int_txunder, self->int_rxover, self->int_sip); printk (KERN_ERR "RX %02x TX %02x RingBase %08x\n", INB (OBOE_RXSLOT), INB (OBOE_TXSLOT), ringbase); printk (KERN_ERR "RING_SIZE %02x IER %02x ISR %02x\n", INB (OBOE_RING_SIZE), INB (OBOE_IER), INB (OBOE_ISR)); printk (KERN_ERR "CONFIG1 %02x STATUS %02x\n", INB (OBOE_CONFIG1), INB (OBOE_STATUS)); printk (KERN_ERR "CONFIG0 %02x%02x ENABLE %02x%02x\n", INB (OBOE_CONFIG0H), INB (OBOE_CONFIG0L), INB (OBOE_ENABLEH), INB (OBOE_ENABLEL)); printk (KERN_ERR "NEW_PCONFIG %02x%02x CURR_PCONFIG %02x%02x\n", INB (OBOE_NEW_PCONFIGH), INB (OBOE_NEW_PCONFIGL), INB (OBOE_CURR_PCONFIGH), INB (OBOE_CURR_PCONFIGL)); printk (KERN_ERR "MAXLEN %02x%02x RXCOUNT %02x%02x\n", INB (OBOE_MAXLENH), INB (OBOE_MAXLENL), INB (OBOE_RXCOUNTL), INB (OBOE_RXCOUNTH)); if (self->ring) { int i; ringbase = virt_to_bus (self->ring); printk (KERN_ERR "Ring at %08x:\n", ringbase); printk (KERN_ERR "RX:"); for (i = 0; i < RX_SLOTS; ++i) printk (" (%d,%02x)",self->ring->rx[i].len,self->ring->rx[i].control); printk ("\n"); printk (KERN_ERR "TX:"); for (i = 0; i < RX_SLOTS; ++i) printk (" (%d,%02x)",self->ring->tx[i].len,self->ring->tx[i].control); printk ("\n"); }}#endif/*Don't let the chip look at memory */static voidtoshoboe_disablebm (struct toshoboe_cb *self){ __u8 command; IRDA_DEBUG (4, "%s()\n", __FUNCTION__); pci_read_config_byte (self->pdev, PCI_COMMAND, &command); command &= ~PCI_COMMAND_MASTER; pci_write_config_byte (self->pdev, PCI_COMMAND, command);}/* Shutdown the chip and point the taskfile reg somewhere else */static voidtoshoboe_stopchip (struct toshoboe_cb *self){ IRDA_DEBUG (4, "%s()\n", __FUNCTION__); /*Disable interrupts */ OUTB (0x0, OBOE_IER); /*Disable DMA, Disable Rx, Disable Tx */ OUTB (CONFIG0H_DMA_OFF, OBOE_CONFIG0H); /*Disable SIR MIR FIR, Tx and Rx */ OUTB (0x00, OBOE_ENABLEH); /*Point the ring somewhere safe */ OUTB (0x3f, OBOE_RING_BASE2); OUTB (0xff, OBOE_RING_BASE1); OUTB (0xff, OBOE_RING_BASE0); OUTB (RX_LEN >> 8, OBOE_MAXLENH); OUTB (RX_LEN & 0xff, OBOE_MAXLENL); /*Acknoledge any pending interrupts */ OUTB (0xff, OBOE_ISR); /*Why */ OUTB (OBOE_ENABLEH_PHYANDCLOCK, OBOE_ENABLEH); /*switch it off */ OUTB (OBOE_CONFIG1_OFF, OBOE_CONFIG1); toshoboe_disablebm (self);}/* Transmitter initialization */static voidtoshoboe_start_DMA (struct toshoboe_cb *self, int opts){ OUTB (0x0, OBOE_ENABLEH); OUTB (CONFIG0H_DMA_ON | opts, OBOE_CONFIG0H); OUTB (OBOE_ENABLEH_PHYANDCLOCK, OBOE_ENABLEH); PROMPT;}/*Set the baud rate */static voidtoshoboe_setbaud (struct toshoboe_cb *self){ __u16 pconfig = 0; __u8 config0l = 0; IRDA_DEBUG (2, "%s(%d/%d)\n", __FUNCTION__, self->speed, self->io.speed); switch (self->speed) { case 2400: case 4800: case 9600: case 19200: case 38400: case 57600: case 115200:#ifdef USE_MIR case 1152000:#endif case 4000000: break; default: printk (KERN_ERR DRIVER_NAME ": switch to unsupported baudrate %d\n", self->speed); return; } switch (self->speed) { /* For SIR the preamble is done by adding XBOFs */ /* to the packet */ /* set to filtered SIR mode, filter looks for BOF and EOF */ case 2400: pconfig |= 47 << OBOE_PCONFIG_BAUDSHIFT; pconfig |= 25 << OBOE_PCONFIG_WIDTHSHIFT; break; case 4800: pconfig |= 23 << OBOE_PCONFIG_BAUDSHIFT; pconfig |= 25 << OBOE_PCONFIG_WIDTHSHIFT; break; case 9600: pconfig |= 11 << OBOE_PCONFIG_BAUDSHIFT; pconfig |= 25 << OBOE_PCONFIG_WIDTHSHIFT; break; case 19200: pconfig |= 5 << OBOE_PCONFIG_BAUDSHIFT; pconfig |= 25 << OBOE_PCONFIG_WIDTHSHIFT; break; case 38400: pconfig |= 2 << OBOE_PCONFIG_BAUDSHIFT; pconfig |= 25 << OBOE_PCONFIG_WIDTHSHIFT; break; case 57600: pconfig |= 1 << OBOE_PCONFIG_BAUDSHIFT; pconfig |= 25 << OBOE_PCONFIG_WIDTHSHIFT; break; case 115200: pconfig |= 0 << OBOE_PCONFIG_BAUDSHIFT; pconfig |= 25 << OBOE_PCONFIG_WIDTHSHIFT; break; default: /*Set to packet based reception */ OUTB (RX_LEN >> 8, OBOE_MAXLENH); OUTB (RX_LEN & 0xff, OBOE_MAXLENL); break; } switch (self->speed) { case 2400: case 4800: case 9600: case 19200: case 38400: case 57600: case 115200: config0l = OBOE_CONFIG0L_ENSIR; if (self->async) { /*Set to character based reception */ /*System will lock if MAXLEN=0 */ /*so have to be careful */ OUTB (0x01, OBOE_MAXLENH); OUTB (0x01, OBOE_MAXLENL); OUTB (0x00, OBOE_MAXLENH); } else { /*Set to packet based reception */ config0l |= OBOE_CONFIG0L_ENSIRF; OUTB (RX_LEN >> 8, OBOE_MAXLENH); OUTB (RX_LEN & 0xff, OBOE_MAXLENL); } break;#ifdef USE_MIR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -