Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

sk_g16.c

Go to the documentation of this file.
00001 /*-
00002  * Copyright (C) 1994 by PJD Weichmann & SWS Bern, Switzerland
00003  *
00004  * This software may be used and distributed according to the terms
00005  * of the GNU Public License, incorporated herein by reference.
00006  *
00007  * Module         : sk_g16.c
00008  *
00009  * Version        : $Revision: 1.1 $
00010  *
00011  * Author         : Patrick J.D. Weichmann
00012  *
00013  * Date Created   : 94/05/26
00014  * Last Updated   : $Date: 1994/06/30 16:25:15 $
00015  *
00016  * Description    : Schneider & Koch G16 Ethernet Device Driver for
00017  *                  Linux Kernel >= 1.1.22
00018  * Update History :
00019  *                  Paul Gortmaker, 03/97: Fix for v2.1.x to use read{b,w}
00020  *                  write{b,w} and memcpy -> memcpy_{to,from}io
00021  *
00022 -*/
00023 
00024 static const char *rcsid = "$Id: sk_g16.c,v 1.1 1994/06/30 16:25:15 root Exp $";
00025 
00026 /*
00027  * The Schneider & Koch (SK) G16 Network device driver is based
00028  * on the 'ni6510' driver from Michael Hipp which can be found at
00029  * ftp://sunsite.unc.edu/pub/Linux/system/Network/drivers/nidrivers.tar.gz
00030  * 
00031  * Sources: 1) ni6510.c by M. Hipp
00032  *          2) depca.c  by D.C. Davies
00033  *          3) skeleton.c by D. Becker
00034  *          4) Am7990 Local Area Network Controller for Ethernet (LANCE),
00035  *             AMD, Pub. #05698, June 1989
00036  *
00037  * Many Thanks for helping me to get things working to: 
00038  *                 
00039  *                 A. Cox (A.Cox@swansea.ac.uk)
00040  *                 M. Hipp (mhipp@student.uni-tuebingen.de)
00041  *                 R. Bolz (Schneider & Koch, Germany)
00042  *
00043  * To Do: 
00044  *        - Support of SK_G8 and other SK Network Cards.
00045  *        - Autoset memory mapped RAM. Check for free memory and then
00046  *          configure RAM correctly. 
00047  *        - SK_close should really set card in to initial state.
00048  *        - Test if IRQ 3 is not switched off. Use autoirq() functionality.
00049  *          (as in /drivers/net/skeleton.c)
00050  *        - Implement Multicast addressing. At minimum something like
00051  *          in depca.c. 
00052  *        - Redo the statistics part.
00053  *        - Try to find out if the board is in 8 Bit or 16 Bit slot.
00054  *          If in 8 Bit mode don't use IRQ 11.
00055  *        - (Try to make it slightly faster.) 
00056  */
00057 
00058 #include <linux/kernel.h>
00059 #include <linux/sched.h>
00060 #include <linux/ptrace.h>
00061 #include <linux/fcntl.h>
00062 #include <linux/ioport.h>
00063 #include <linux/interrupt.h>
00064 #include <linux/malloc.h>
00065 #include <linux/string.h> 
00066 #include <linux/delay.h>
00067 #include <asm/system.h>
00068 #include <asm/io.h>
00069 #include <asm/bitops.h> 
00070 #include <linux/errno.h>
00071 #include <linux/init.h>
00072 
00073 #include <linux/netdevice.h>
00074 #include <linux/etherdevice.h>
00075 #include <linux/skbuff.h>
00076 
00077 #include "sk_g16.h"
00078 
00079 /* 
00080  * Schneider & Koch Card Definitions 
00081  * =================================
00082  */  
00083 
00084 #define SK_NAME   "SK_G16"
00085 
00086 /*
00087  * SK_G16 Configuration
00088  * --------------------
00089  */ 
00090 
00091 /* 
00092  * Abbreviations
00093  * -------------
00094  *  
00095  * RAM - used for the 16KB shared memory 
00096  * Boot_ROM, ROM - are used for referencing the BootEPROM
00097  *
00098  * SK_BOOT_ROM and SK_ADDR are symbolic constants used to configure
00099  * the behaviour of the driver and the SK_G16.
00100  *
00101  * ! See sk_g16.install on how to install and configure the driver !   
00102  *
00103  * SK_BOOT_ROM defines if the Boot_ROM should be switched off or not.
00104  *
00105  * SK_ADDR defines the address where the RAM will be mapped into the real
00106  *         host memory.
00107  *         valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps.
00108  */  
00109  
00110 #define SK_BOOT_ROM     1              /* 1=BootROM on 0=off */
00111 
00112 #define SK_ADDR         0xcc000
00113 
00114 /* 
00115  * In POS3 are bits A14-A19 of the address bus. These bits can be set
00116  * to choose the RAM address. That's why we only can choose the RAM address
00117  * in 16KB steps.
00118  */
00119 
00120 #define POS_ADDR       (rom_addr>>14)  /* Do not change this line */
00121 
00122 /* 
00123  * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations
00124  * ----------------------------------------------
00125  */
00126 
00127 /* 
00128  * As nearly every card has also SK_G16 a specified I/O Port region and
00129  * only a few possible IRQ's.
00130  * In the Installation Guide from Schneider & Koch is listed a possible
00131  * Interrupt IRQ2. IRQ2 is always IRQ9 in boards with two cascaded interrupt
00132  * controllers. So we use in SK_IRQS IRQ9.
00133  */
00134 
00135 /* Don't touch any of the following #defines. */
00136 
00137 #define SK_IO_PORTS     { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 }
00138 
00139 #define SK_IRQS         { 3, 5, 9, 11, 0 }
00140 
00141 #define SK_BOOT_ROM_LOCATIONS { 0xc0000, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000, 0 }
00142 
00143 #define SK_BOOT_ROM_ID  { 0x55, 0xaa, 0x10, 0x50, 0x06, 0x33 }
00144 
00145 /* 
00146  * SK_G16 POS REGISTERS 
00147  * --------------------
00148  */
00149 
00150 /*
00151  * SK_G16 has a Programmable Option Select (POS) Register.
00152  * The POS is composed of 8 separate registers (POS0-7) which 
00153  * are I/O mapped on an address set by the W1 switch.                    
00154  *
00155  */
00156 
00157 #define SK_POS_SIZE 8           /* 8 I/O Ports are used by SK_G16 */
00158 
00159 #define SK_POS0     ioaddr      /* Card-ID Low (R) */
00160 #define SK_POS1     ioaddr+1    /* Card-ID High (R) */
00161 #define SK_POS2     ioaddr+2    /* Card-Enable, Boot-ROM Disable (RW) */
00162 #define SK_POS3     ioaddr+3    /* Base address of RAM */
00163 #define SK_POS4     ioaddr+4    /* IRQ */
00164 
00165 /* POS5 - POS7 are unused */
00166 
00167 /* 
00168  * SK_G16 MAC PREFIX 
00169  * -----------------
00170  */
00171 
00172 /* 
00173  * Scheider & Koch manufacturer code (00:00:a5).
00174  * This must be checked, that we are sure it is a SK card.
00175  */
00176 
00177 #define SK_MAC0         0x00
00178 #define SK_MAC1         0x00
00179 #define SK_MAC2         0x5a
00180 
00181 /* 
00182  * SK_G16 ID 
00183  * ---------
00184  */ 
00185 
00186 /* 
00187  * If POS0,POS1 contain the following ID, then we know
00188  * at which I/O Port Address we are. 
00189  */
00190 
00191 #define SK_IDLOW  0xfd 
00192 #define SK_IDHIGH 0x6a
00193 
00194 
00195 /* 
00196  * LANCE POS Bit definitions 
00197  * -------------------------
00198  */
00199 
00200 #define SK_ROM_RAM_ON  (POS2_CARD)
00201 #define SK_ROM_RAM_OFF (POS2_EPROM)
00202 #define SK_ROM_ON      (inb(SK_POS2) & POS2_CARD)
00203 #define SK_ROM_OFF     (inb(SK_POS2) | POS2_EPROM)
00204 #define SK_RAM_ON      (inb(SK_POS2) | POS2_CARD)
00205 #define SK_RAM_OFF     (inb(SK_POS2) & POS2_EPROM) 
00206 
00207 #define POS2_CARD  0x0001              /* 1 = SK_G16 on      0 = off */
00208 #define POS2_EPROM 0x0002              /* 1 = Boot EPROM off 0 = on */ 
00209 
00210 /* 
00211  * SK_G16 Memory mapped Registers
00212  * ------------------------------
00213  *
00214  */ 
00215 
00216 #define SK_IOREG        (board->ioreg) /* LANCE data registers.     */ 
00217 #define SK_PORT         (board->port)  /* Control, Status register  */
00218 #define SK_IOCOM        (board->iocom) /* I/O Command               */
00219 
00220 /* 
00221  * SK_G16 Status/Control Register bits
00222  * -----------------------------------
00223  *
00224  * (C) Controlreg (S) Statusreg 
00225  */
00226 
00227 /* 
00228  * Register transfer: 0 = no transfer
00229  *                    1 = transferring data between LANCE and I/O reg 
00230  */
00231 #define SK_IORUN        0x20   
00232 
00233 /* 
00234  * LANCE interrupt: 0 = LANCE interrupt occurred        
00235  *                  1 = no LANCE interrupt occurred
00236  */
00237 #define SK_IRQ          0x10   
00238                         
00239 #define SK_RESET        0x08   /* Reset SK_CARD: 0 = RESET 1 = normal */
00240 #define SK_RW           0x02   /* 0 = write to 1 = read from */
00241 #define SK_ADR          0x01   /* 0 = REG DataPort 1 = RAP Reg addr port */
00242 
00243   
00244 #define SK_RREG         SK_RW  /* Transferdirection to read from lance */
00245 #define SK_WREG         0      /* Transferdirection to write to lance */
00246 #define SK_RAP          SK_ADR /* Destination Register RAP */
00247 #define SK_RDATA        0      /* Destination Register REG DataPort */
00248 
00249 /* 
00250  * SK_G16 I/O Command 
00251  * ------------------
00252  */
00253 
00254 /* 
00255  * Any bitcombination sets the internal I/O bit (transfer will start) 
00256  * when written to I/O Command
00257  */
00258 
00259 #define SK_DOIO         0x80   /* Do Transfer */ 
00260  
00261 /* 
00262  * LANCE RAP (Register Address Port). 
00263  * ---------------------------------
00264  */
00265 
00266 /*   
00267  * The LANCE internal registers are selected through the RAP. 
00268  * The Registers are:
00269  *
00270  * CSR0 - Status and Control flags 
00271  * CSR1 - Low order bits of initialize block (bits 15:00)
00272  * CSR2 - High order bits of initialize block (bits 07:00, 15:08 are reserved)
00273  * CSR3 - Allows redefinition of the Bus Master Interface.
00274  *        This register must be set to 0x0002, which means BSWAP = 0,
00275  *        ACON = 1, BCON = 0;
00276  *
00277  */
00278  
00279 #define CSR0            0x00   
00280 #define CSR1            0x01  
00281 #define CSR2            0x02 
00282 #define CSR3            0x03
00283 
00284 /* 
00285  * General Definitions 
00286  * ===================
00287  */
00288 
00289 /* 
00290  * Set the number of Tx and Rx buffers, using Log_2(# buffers).
00291  * We have 16KB RAM which can be accessed by the LANCE. In the 
00292  * memory are not only the buffers but also the ring descriptors and
00293  * the initialize block. 
00294  * Don't change anything unless you really know what you do.
00295  */
00296 
00297 #define LC_LOG_TX_BUFFERS 1               /* (2 == 2^^1) 2 Transmit buffers */
00298 #define LC_LOG_RX_BUFFERS 3               /* (8 == 2^^3) 8 Receive buffers */
00299 
00300 /* Descriptor ring sizes */
00301 
00302 #define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */
00303 #define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers */
00304 
00305 /* Define Mask for setting RMD, TMD length in the LANCE init_block */
00306 
00307 #define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29)
00308 #define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29)
00309 
00310 /*
00311  * Data Buffer size is set to maximum packet length.
00312  */
00313 
00314 #define PKT_BUF_SZ              1518 
00315 
00316 /* 
00317  * The number of low I/O ports used by the ethercard. 
00318  */
00319 
00320 #define ETHERCARD_TOTAL_SIZE    SK_POS_SIZE
00321 
00322 /* 
00323  * SK_DEBUG
00324  *
00325  * Here you can choose what level of debugging wanted.
00326  *
00327  * If SK_DEBUG and SK_DEBUG2 are undefined, then only the
00328  *  necessary messages will be printed.
00329  *
00330  * If SK_DEBUG is defined, there will be many debugging prints
00331  *  which can help to find some mistakes in configuration or even
00332  *  in the driver code.
00333  *
00334  * If SK_DEBUG2 is defined, many many messages will be printed 
00335  *  which normally you don't need. I used this to check the interrupt
00336  *  routine. 
00337  *
00338  * (If you define only SK_DEBUG2 then only the messages for 
00339  *  checking interrupts will be printed!)
00340  *
00341  * Normal way of live is: 
00342  *
00343  * For the whole thing get going let both symbolic constants
00344  * undefined. If you face any problems and you know what's going
00345  * on (you know something about the card and you can interpret some
00346  * hex LANCE register output) then define SK_DEBUG
00347  * 
00348  */
00349 
00350 #undef  SK_DEBUG        /* debugging */
00351 #undef  SK_DEBUG2       /* debugging with more verbose report */
00352 
00353 #ifdef SK_DEBUG
00354 #define PRINTK(x) printk x
00355 #else
00356 #define PRINTK(x) /**/
00357 #endif
00358 
00359 #ifdef SK_DEBUG2
00360 #define PRINTK2(x) printk x
00361 #else
00362 #define PRINTK2(x) /**/
00363 #endif
00364 
00365 /* 
00366  * SK_G16 RAM
00367  *
00368  * The components are memory mapped and can be set in a region from
00369  * 0x00000 through 0xfc000 in 16KB steps. 
00370  *
00371  * The Network components are: dual ported RAM, Prom, I/O Reg, Status-,
00372  * Controlregister and I/O Command.
00373  *
00374  * dual ported RAM: This is the only memory region which the LANCE chip
00375  *      has access to. From the Lance it is addressed from 0x0000 to
00376  *      0x3fbf. The host accesses it normally.
00377  *
00378  * PROM: The PROM obtains the ETHERNET-MAC-Address. It is realised as a
00379  *       8-Bit PROM, this means only the 16 even addresses are used of the
00380  *       32 Byte Address region. Access to an odd address results in invalid
00381  *       data.
00382  * 
00383  * LANCE I/O Reg: The I/O Reg is build of 4 single Registers, Low-Byte Write,
00384  *       Hi-Byte Write, Low-Byte Read, Hi-Byte Read.
00385  *       Transfer from or to the LANCE is always in 16Bit so Low and High
00386  *       registers are always relevant.
00387  *
00388  *       The Data from the Readregister is not the data in the Writeregister!!
00389  *       
00390  * Port: Status- and Controlregister. 
00391  *       Two different registers which share the same address, Status is 
00392  *       read-only, Control is write-only.
00393  *    
00394  * I/O Command: 
00395  *       Any bitcombination written in here starts the transmission between
00396  *       Host and LANCE.
00397  */
00398 
00399 typedef struct
00400 {
00401         unsigned char  ram[0x3fc0];   /* 16KB dual ported ram */
00402         unsigned char  rom[0x0020];   /* 32Byte PROM containing 6Byte MAC */
00403         unsigned char  res1[0x0010];  /* reserved */
00404         unsigned volatile short ioreg;/* LANCE I/O Register */
00405         unsigned volatile char  port; /* Statusregister and Controlregister */
00406         unsigned char  iocom;         /* I/O Command Register */
00407 } SK_RAM;
00408 
00409 /* struct  */
00410 
00411 /* 
00412  * This is the structure for the dual ported ram. We
00413  * have exactly 16 320 Bytes. In here there must be:
00414  *
00415  *     - Initialize Block   (starting at a word boundary)
00416  *     - Receive and Transmit Descriptor Rings (quadword boundary)
00417  *     - Data Buffers (arbitrary boundary)
00418  *
00419  * This is because LANCE has on SK_G16 only access to the dual ported
00420  * RAM and nowhere else.
00421  */
00422 
00423 struct SK_ram
00424 {
00425     struct init_block ib;
00426     struct tmd tmde[TMDNUM];
00427     struct rmd rmde[RMDNUM];
00428     char tmdbuf[TMDNUM][PKT_BUF_SZ];
00429     char rmdbuf[RMDNUM][PKT_BUF_SZ];
00430 };
00431 
00432 /* 
00433  * Structure where all necessary information is for ring buffer 
00434  * management and statistics.
00435  */
00436 
00437 struct priv
00438 {
00439     struct SK_ram *ram;  /* dual ported ram structure */
00440     struct rmd *rmdhead; /* start of receive ring descriptors */
00441     struct tmd *tmdhead; /* start of transmit ring descriptors */
00442     int        rmdnum;   /* actual used ring descriptor */
00443     int        tmdnum;   /* actual transmit descriptor for transmitting data */
00444     int        tmdlast;  /* last sent descriptor used for error handling, etc */
00445     void       *rmdbufs[RMDNUM]; /* pointer to the receive buffers */
00446     void       *tmdbufs[TMDNUM]; /* pointer to the transmit buffers */
00447     struct net_device_stats stats; /* Device driver statistics */
00448 };
00449 
00450 /* global variable declaration */
00451 
00452 /* IRQ map used to reserve a IRQ (see SK_open()) */
00453 
00454 /* static variables */
00455 
00456 static SK_RAM *board;  /* pointer to our memory mapped board components */
00457 
00458 /* Macros */
00459 
00460 
00461 /* Function Prototypes */
00462 
00463 /*
00464  * Device Driver functions
00465  * -----------------------
00466  * See for short explanation of each function its definitions header.
00467  */
00468 
00469 int          SK_init(struct device *dev);
00470 static int   SK_probe(struct device *dev, short ioaddr);
00471 
00472 static int   SK_open(struct device *dev);
00473 static int   SK_send_packet(struct sk_buff *skb, struct device *dev);
00474 static void  SK_interrupt(int irq, void *dev_id, struct pt_regs * regs);
00475 static void  SK_rxintr(struct device *dev);
00476 static void  SK_txintr(struct device *dev);
00477 static int   SK_close(struct device *dev);
00478 
00479 static struct net_device_stats *SK_get_stats(struct device *dev);
00480 
00481 unsigned int SK_rom_addr(void);
00482 
00483 static void set_multicast_list(struct device *dev);
00484 
00485 /*
00486  * LANCE Functions
00487  * ---------------
00488  */
00489 
00490 static int SK_lance_init(struct device *dev, unsigned short mode);
00491 void   SK_reset_board(void);
00492 void   SK_set_RAP(int reg_number);
00493 int    SK_read_reg(int reg_number);
00494 int    SK_rread_reg(void);
00495 void   SK_write_reg(int reg_number, int value);
00496 
00497 /* 
00498  * Debugging functions
00499  * -------------------
00500  */
00501 
00502 void SK_print_pos(struct device *dev, char *text);
00503 void SK_print_dev(struct device *dev, char *text);
00504 void SK_print_ram(struct device *dev);
00505 
00506 
00507 /*-
00508  * Function       : SK_init
00509  * Author         : Patrick J.D. Weichmann
00510  * Date Created   : 94/05/26
00511  *
00512  * Description    : Check for a SK_G16 network adaptor and initialize it.
00513  *                  This function gets called by dev_init which initializes
00514  *                  all Network devices.
00515  *
00516  * Parameters     : I : struct device *dev - structure preconfigured 
00517  *                                           from Space.c
00518  * Return Value   : 0 = Driver Found and initialized 
00519  * Errors         : ENODEV - no device found
00520  *                  ENXIO  - not probed
00521  * Globals        : None
00522  * Update History :
00523  *     YY/MM/DD  uid  Description
00524 -*/
00525 
00526 /* 
00527  * Check for a network adaptor of this type, and return '0' if one exists.
00528  * If dev->base_addr == 0, probe all likely locations.
00529  * If dev->base_addr == 1, always return failure.
00530  * If dev->base_addr == 2, allocate space for the device and return success
00531  *                         (detachable devices only).
00532  */
00533 
00534 __initfunc(int SK_init(struct device *dev))
00535 {
00536         int ioaddr         = 0;            /* I/O port address used for POS regs */
00537         int *port, ports[] = SK_IO_PORTS;  /* SK_G16 supported ports */
00538 
00539         /* get preconfigured base_addr from dev which is done in Space.c */
00540         int base_addr = dev->base_addr; 
00541 
00542         PRINTK(("%s: %s", SK_NAME, rcsid));
00543         rcsid = NULL;                 /* We do not want to use this further */
00544 
00545         if (base_addr > 0x0ff)        /* Check a single specified address */
00546         {
00547             /* Check if on specified address is a SK_G16 */
00548 
00549             if ( (inb(SK_POS0) == SK_IDLOW) ||
00550                  (inb(SK_POS1) == SK_IDHIGH) )  
00551             {
00552                 return SK_probe(dev, base_addr);  
00553             }
00554 
00555             return ENODEV;            /* Sorry, but on specified address NO SK_G16 */
00556         }
00557         else if (base_addr > 0)       /* Don't probe at all */
00558         {
00559                 return ENXIO;
00560         }
00561 
00562         /* Autoprobe base_addr */
00563 
00564         for (port = &ports[0]; *port; port++) 
00565         {
00566             ioaddr = *port;           /* we need ioaddr for accessing POS regs */
00567 
00568             /* Check if I/O Port region is used by another board */
00569 
00570             if (check_region(ioaddr, ETHERCARD_TOTAL_SIZE))
00571             {
00572                 continue;             /* Try next Port address */
00573             }
00574 
00575             /* Check if at ioaddr is a SK_G16 */
00576 
00577             if ( !(inb(SK_POS0) == SK_IDLOW) ||
00578                  !(inb(SK_POS1) == SK_IDHIGH) )
00579             {
00580                 continue;             /* Try next Port address */
00581             }
00582 
00583             dev->base_addr = ioaddr;  /* Set I/O Port Address */
00584 
00585             if (SK_probe(dev, ioaddr) == 0)  
00586             {
00587                 return 0; /* Card found and initialized */
00588             }
00589         }
00590 
00591         dev->base_addr = base_addr;   /* Write back original base_addr */
00592 
00593         return ENODEV;                /* Failed to find or init driver */
00594 
00595 } /* End of SK_init */
00596 
00597 
00598 /*-
00599  * Function       : SK_probe
00600  * Author         : Patrick J.D. Weichmann
00601  * Date Created   : 94/05/26
00602  *
00603  * Description    : This function is called by SK_init and 
00604  *                  does the main part of initialization.
00605  *                  
00606  * Parameters     : I : struct device *dev - SK_G16 device structure
00607  *                  I : short ioaddr       - I/O Port address where POS is.
00608  * Return Value   : 0 = Initialization done             
00609  * Errors         : ENODEV - No SK_G16 found
00610  *                  -1     - Configuration problem
00611  * Globals        : board       - pointer to SK_RAM
00612  * Update History :
00613  *     YY/MM/DD  uid  Description
00614  *     94/06/30  pwe  SK_ADDR now checked and at the correct place
00615 -*/
00616 
00617 __initfunc(int SK_probe(struct device *dev, short ioaddr))
00618 {
00619     int i,j;                /* Counters */
00620     int sk_addr_flag = 0;   /* SK ADDR correct? 1 - no, 0 - yes */
00621     unsigned int rom_addr;  /* used to store RAM address used for POS_ADDR */
00622 
00623     struct priv *p;         /* SK_G16 private structure */
00624 
00625     if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000)
00626     {
00627       
00628        sk_addr_flag = 1;
00629 
00630        /* 
00631         * Now here we could use a routine which searches for a free
00632         * place in the ram and set SK_ADDR if found. TODO. 
00633         */
00634     }
00635 
00636     if (SK_BOOT_ROM)            /* Shall we keep Boot_ROM on ? */
00637     {
00638         PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME));
00639 
00640         rom_addr = SK_rom_addr();
00641 
00642         if (rom_addr == 0)      /* No Boot_ROM found */
00643         {
00644             if (sk_addr_flag)   /* No or Invalid SK_ADDR is defined */ 
00645             {
00646                 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
00647                        dev->name, SK_ADDR);
00648                 return -1;
00649             }
00650 
00651             rom_addr = SK_ADDR; /* assign predefined address */
00652 
00653             PRINTK(("## %s: NO Bootrom found \n", SK_NAME));
00654 
00655             outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
00656             outb(POS_ADDR, SK_POS3);       /* Set RAM address */
00657             outb(SK_RAM_ON, SK_POS2);      /* enable RAM */
00658         }
00659         else if (rom_addr == SK_ADDR) 
00660         {
00661             printk("%s: RAM + ROM are set to the same address %#08x\n"
00662                    "   Check configuration. Now switching off Boot_ROM\n",
00663                    SK_NAME, rom_addr);
00664 
00665             outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off*/
00666             outb(POS_ADDR, SK_POS3);       /* Set RAM address */
00667             outb(SK_RAM_ON, SK_POS2);      /* enable RAM */
00668         }
00669         else
00670         {
00671             PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME, rom_addr));
00672             PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME));
00673 
00674             if (sk_addr_flag)       /* No or Invalid SK_ADDR is defined */ 
00675             {
00676                 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
00677                        dev->name, SK_ADDR);
00678                 return -1;
00679             }
00680 
00681             rom_addr = SK_ADDR;
00682 
00683             outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */ 
00684             outb(POS_ADDR, SK_POS3);       /* Set RAM address */
00685             outb(SK_ROM_RAM_ON, SK_POS2);  /* RAM on, BOOT_ROM on */
00686         }
00687     }
00688     else /* Don't keep Boot_ROM */
00689     {
00690         PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME));
00691 
00692         if (sk_addr_flag)           /* No or Invalid SK_ADDR is defined */ 
00693         {
00694             printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
00695                    dev->name, SK_ADDR);
00696             return -1;
00697         }
00698 
00699         rom_addr = SK_rom_addr();          /* Try to find a Boot_ROM */
00700 
00701         /* IF we find a Boot_ROM disable it */
00702 
00703         outb(SK_ROM_RAM_OFF, SK_POS2);     /* Boot_ROM + RAM off */  
00704 
00705         /* We found a Boot_ROM and it's gone. Set RAM address on
00706          * Boot_ROM address. 
00707          */ 
00708 
00709         if (rom_addr) 
00710         {
00711             printk("%s: We found Boot_ROM at %#08x. Now setting RAM on"
00712                    "that address\n", SK_NAME, rom_addr);
00713 
00714             outb(POS_ADDR, SK_POS3);       /* Set RAM on Boot_ROM address */
00715         }
00716         else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */
00717         {
00718             if (sk_addr_flag)       /* No or Invalid SK_ADDR is defined */ 
00719             {
00720                 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
00721                        dev->name, SK_ADDR);
00722                 return -1;
00723             }
00724 
00725             rom_addr = SK_ADDR;
00726 
00727             outb(POS_ADDR, SK_POS3);       /* Set RAM address */ 
00728         }
00729         outb(SK_RAM_ON, SK_POS2);          /* enable RAM */
00730     }
00731 
00732 #ifdef SK_DEBUG
00733     SK_print_pos(dev, "POS registers after ROM, RAM config");
00734 #endif
00735 
00736     board = (SK_RAM *) bus_to_virt(rom_addr);
00737 
00738     /* Read in station address */
00739     for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2)
00740     {
00741         dev->dev_addr[i] = readb(board->rom+j);          
00742     }
00743 
00744     /* Check for manufacturer code */
00745     if (!(dev->dev_addr[0] == SK_MAC0 &&
00746           dev->dev_addr[1] == SK_MAC1 &&
00747           dev->dev_addr[2] == SK_MAC2) )
00748     {
00749         PRINTK(("## %s: We did not find SK_G16 at RAM location.\n",
00750                 SK_NAME)); 
00751         return ENODEV;                     /* NO SK_G16 found */
00752     }
00753 
00754     printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n",
00755             dev->name,
00756             "Schneider & Koch Netcard",
00757             (unsigned int) dev->base_addr,
00758             dev->dev_addr[0],
00759             dev->dev_addr[1],
00760             dev->dev_addr[2],
00761             dev->dev_addr[3],
00762             dev->dev_addr[4],
00763             dev->dev_addr[5]);
00764 
00765     /* Allocate memory for private structure */
00766     p = dev->priv = (void *) kmalloc(sizeof(struct priv), GFP_KERNEL);
00767     if (p == NULL) {
00768            printk("%s: ERROR - no memory for driver data!\n", dev->name);
00769            return -ENOMEM;
00770     }
00771     memset((char *) dev->priv, 0, sizeof(struct priv)); /* clear memory */
00772 
00773     /* Grab the I/O Port region */
00774     request_region(ioaddr, ETHERCARD_TOTAL_SIZE,"sk_g16");
00775 
00776     /* Assign our Device Driver functions */
00777 
00778     dev->open                   = &SK_open;
00779     dev->stop                   = &SK_close;
00780     dev->hard_start_xmit        = &SK_send_packet;
00781     dev->get_stats              = &SK_get_stats;
00782     dev->set_multicast_list     = &set_multicast_list;
00783 
00784 
00785     /* Set the generic fields of the device structure */
00786 
00787     ether_setup(dev);
00788     
00789     dev->flags &= ~IFF_MULTICAST;
00790 
00791     /* Initialize private structure */
00792 
00793     p->ram = (struct SK_ram *) rom_addr; /* Set dual ported RAM addr */
00794     p->tmdhead = &(p->ram)->tmde[0];     /* Set TMD head */
00795     p->rmdhead = &(p->ram)->rmde[0];     /* Set RMD head */
00796 
00797     /* Initialize buffer pointers */
00798 
00799     for (i = 0; i < TMDNUM; i++)
00800     {
00801         p->tmdbufs[i] = &(p->ram)->tmdbuf[i];
00802     }
00803 
00804     for (i = 0; i < RMDNUM; i++)
00805     {
00806         p->rmdbufs[i] = &(p->ram)->rmdbuf[i]; 
00807     }
00808 
00809 #ifdef SK_DEBUG
00810     SK_print_pos(dev, "End of SK_probe");
00811     SK_print_ram(dev);
00812 #endif 
00813 
00814     return 0;                            /* Initialization done */
00815 
00816 } /* End of SK_probe() */
00817 
00818 
00819 /*- 
00820  * Function       : SK_open
00821  * Author         : Patrick J.D. Weichmann
00822  * Date Created   : 94/05/26
00823  *
00824  * Description    : This function is called sometimes after booting 
00825  *                  when ifconfig program is run.
00826  *
00827  *                  This function requests an IRQ, sets the correct
00828  *                  IRQ in the card. Then calls SK_lance_init() to 
00829  *                  init and start the LANCE chip. Then if everything is 
00830  *                  ok returns with 0 (OK), which means SK_G16 is now
00831  *                  opened and operational.
00832  *
00833  *                  (Called by dev_open() /net/inet/dev.c)
00834  *
00835  * Parameters     : I : struct device *dev - SK_G16 device structure
00836  * Return Value   : 0 - Device opened
00837  * Errors         : -EAGAIN - Open failed
00838  * Side Effects   : None
00839  * Update History :
00840  *     YY/MM/DD  uid  Description
00841 -*/
00842 
00843 static int SK_open(struct device *dev)
00844 {
00845     int i = 0;
00846     int irqval = 0;
00847     int ioaddr = dev->base_addr;
00848 
00849     int irqtab[] = SK_IRQS; 
00850 
00851     struct priv *p = (struct priv *)dev->priv;
00852 
00853     PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n", 
00854            SK_NAME, SK_read_reg(CSR0)));
00855 
00856     if (dev->irq == 0) /* Autoirq */
00857     {
00858         i = 0;
00859 
00860         /* 
00861          * Check if one IRQ out of SK_IRQS is free and install 
00862          * interrupt handler.
00863          * Most done by request_irq(). 
00864          * irqval: 0       - interrupt handler installed for IRQ irqtab[i]
00865          *         -EBUSY  - interrupt busy 
00866          *         -EINVAL - irq > 15 or handler = NULL
00867          */
00868 
00869         do
00870         {
00871           irqval = request_irq(irqtab[i], &SK_interrupt, 0, "sk_g16", dev);
00872           i++;
00873         } while (irqval && irqtab[i]);
00874 
00875         if (irqval) /* We tried every possible IRQ but no success */
00876         {
00877             printk("%s: unable to get an IRQ\n", dev->name);
00878             return -EAGAIN;
00879         }
00880 
00881         dev->irq = irqtab[--i]; 
00882         
00883         outb(i<<2, SK_POS4);           /* Set Card on probed IRQ */
00884 
00885     }
00886     else if (dev->irq == 2) /* IRQ2 is always IRQ9 */
00887     {
00888         if (request_irq(9, &SK_interrupt, 0, "sk_g16", dev))
00889         {
00890             printk("%s: unable to get IRQ 9\n", dev->name);
00891             return -EAGAIN;
00892         } 
00893         dev->irq = 9;
00894         
00895         /* 
00896          * Now we set card on IRQ2.
00897          * This can be confusing, but remember that IRQ2 on the network
00898          * card is in reality IRQ9
00899          */
00900         outb(0x08, SK_POS4);           /* set card to IRQ2 */
00901 
00902     }
00903     else  /* Check IRQ as defined in Space.c */
00904     {
00905         int i = 0;
00906 
00907         /* check if IRQ free and valid. Then install Interrupt handler */
00908 
00909         if (request_irq(dev->irq, &SK_interrupt, 0, "sk_g16", dev))
00910         {
00911             printk("%s: unable to get selected IRQ\n", dev->name);
00912             return -EAGAIN;
00913         }
00914 
00915         switch(dev->irq)
00916         {
00917             case 3: i = 0;
00918                     break;
00919             case 5: i = 1;
00920                     break;
00921             case 2: i = 2;
00922                     break;
00923             case 11:i = 3;
00924                     break;
00925             default: 
00926                 printk("%s: Preselected IRQ %d is invalid for %s boards",
00927                        dev->name,
00928                        dev->irq,
00929                        SK_NAME);
00930                 return -EAGAIN;
00931         }      
00932   
00933         outb(i<<2, SK_POS4);           /* Set IRQ on card */
00934     }
00935 
00936     printk("%s: Schneider & Koch G16 at %#3x, IRQ %d, shared mem at %#08x\n",
00937             dev->name, (unsigned int)dev->base_addr, 
00938             (int) dev->irq, (unsigned int) p->ram);
00939 
00940     if (!(i = SK_lance_init(dev, 0)))  /* LANCE init OK? */
00941     {
00942 
00943 
00944         dev->tbusy = 0;
00945         dev->interrupt = 0;
00946         dev->start = 1;
00947 
00948 #ifdef SK_DEBUG
00949 
00950         /* 
00951          * This debug block tries to stop LANCE,
00952          * reinit LANCE with transmitter and receiver disabled,
00953          * then stop again and reinit with NORMAL_MODE
00954          */
00955 
00956         printk("## %s: After lance init. CSR0: %#06x\n", 
00957                SK_NAME, SK_read_reg(CSR0));
00958         SK_write_reg(CSR0, CSR0_STOP);
00959         printk("## %s: LANCE stopped. CSR0: %#06x\n", 
00960                SK_NAME, SK_read_reg(CSR0));
00961         SK_lance_init(dev, MODE_DTX | MODE_DRX);
00962         printk("## %s: Reinit with DTX + DRX off. CSR0: %#06x\n", 
00963                SK_NAME, SK_read_reg(CSR0));
00964         SK_write_reg(CSR0, CSR0_STOP);
00965         printk("## %s: LANCE stopped. CSR0: %#06x\n", 
00966                SK_NAME, SK_read_reg(CSR0));
00967         SK_lance_init(dev, MODE_NORMAL);
00968         printk("## %s: LANCE back to normal mode. CSR0: %#06x\n", 
00969                SK_NAME, SK_read_reg(CSR0));
00970         SK_print_pos(dev, "POS regs before returning OK");
00971 
00972 #endif /* SK_DEBUG */
00973        
00974         return 0;              /* SK_open() is successful */
00975     }
00976     else /* LANCE init failed */
00977     {
00978 
00979         PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n", 
00980                SK_NAME, SK_read_reg(CSR0)));
00981 
00982         dev->start = 0;        /* Device not ready */
00983         return -EAGAIN;
00984     }
00985 
00986 } /* End of SK_open() */
00987 
00988 
00989 /*-
00990  * Function       : SK_lance_init
00991  * Author         : Patrick J.D. Weichmann
00992  * Date Created   : 94/05/26
00993  *
00994  * Description    : Reset LANCE chip, fill RMD, TMD structures with
00995  *                  start values and Start LANCE.
00996  *
00997  * Parameters     : I : struct device *dev - SK_G16 device structure
00998  *                  I : int mode - put LANCE into "mode" see data-sheet for
00999  *                                 more info.
01000  * Return Value   : 0  - Init done
01001  * Errors         : -1 - Init failed
01002  * Update History :
01003  *     YY/MM/DD  uid  Description
01004 -*/
01005 
01006 static int SK_lance_init(struct device *dev, unsigned short mode)
01007 {
01008     int i;
01009     unsigned long flags;
01010     struct priv *p = (struct priv *) dev->priv; 
01011     struct tmd  *tmdp;
01012     struct rmd  *rmdp;
01013 
01014     PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n", 
01015            SK_NAME, SK_read_reg(CSR0)));
01016 
01017     /* Reset LANCE */
01018     SK_reset_board();
01019 
01020     /* Initialize TMD's with start values */
01021     p->tmdnum = 0;                   /* First descriptor for transmitting */ 
01022     p->tmdlast = 0;                  /* First descriptor for reading stats */
01023 
01024     for (i = 0; i < TMDNUM; i++)     /* Init all TMD's */
01025     {
01026         tmdp = p->tmdhead + i; 
01027    
01028         writel((unsigned long) p->tmdbufs[i], tmdp->u.buffer); /* assign buffer */
01029         
01030         /* Mark TMD as start and end of packet */
01031         writeb(TX_STP | TX_ENP, tmdp->u.s.status);
01032     }
01033 
01034 
01035     /* Initialize RMD's with start values */
01036 
01037     p->rmdnum = 0;                   /* First RMD which will be used */
01038  
01039     for (i = 0; i < RMDNUM; i++)     /* Init all RMD's */
01040     {
01041         rmdp = p->rmdhead + i;
01042 
01043         
01044         writel((unsigned long) p->rmdbufs[i], rmdp->u.buffer); /* assign buffer */
01045         
01046         /* 
01047          * LANCE must be owner at beginning so that he can fill in 
01048          * receiving packets, set status and release RMD 
01049          */
01050 
01051         writeb(RX_OWN, rmdp->u.s.status);
01052 
01053         writew(-PKT_BUF_SZ, rmdp->blen); /* Buffer Size (two's complement) */
01054 
01055         writeb(0, rmdp->mlen);           /* init message length */       
01056         
01057     }
01058 
01059     /* Fill LANCE Initialize Block */
01060 
01061     writew(mode, (p->ram)->ib.mode); /* Set operation mode */
01062 
01063     for (i = 0; i < ETH_ALEN; i++)   /* Set physical address */
01064     {
01065         writeb(dev->dev_addr[i], (p->ram)->ib.paddr[i]); 
01066     }
01067 
01068     for (i = 0; i < 8; i++)          /* Set multicast, logical address */
01069     {
01070         writeb(0, (p->ram)->ib.laddr[i]); /* We do not use logical addressing */
01071     } 
01072 
01073     /* Set ring descriptor pointers and set number of descriptors */
01074 
01075     writel((int)p->rmdhead | RMDNUMMASK, (p->ram)->ib.rdrp);
01076     writel((int)p->tmdhead | TMDNUMMASK, (p->ram)->ib.tdrp);
01077 
01078     /* Prepare LANCE Control and Status Registers */
01079 
01080     save_flags(flags);
01081     cli();
01082 
01083     SK_write_reg(CSR3, CSR3_ACON);   /* Ale Control !!!THIS MUST BE SET!!!! */
01084  
01085     /* 
01086      * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
01087      * PC Memory locations.
01088      *
01089      * In structure SK_ram is defined that the first thing in ram
01090      * is the initialization block. So his address is for LANCE always
01091      * 0x0000
01092      *
01093      * CSR1 contains low order bits 15:0 of initialization block address
01094      * CSR2 is built of: 
01095      *    7:0  High order bits 23:16 of initialization block address
01096      *   15:8  reserved, must be 0
01097      */
01098     
01099     /* Set initialization block address (must be on word boundary) */
01100     SK_write_reg(CSR1, 0);          /* Set low order bits 15:0 */
01101     SK_write_reg(CSR2, 0);          /* Set high order bits 23:16 */ 
01102     
01103 
01104     PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n", 
01105            SK_NAME, SK_read_reg(CSR0)));
01106 
01107     /* Initialize LANCE */
01108 
01109     /* 
01110      * INIT = Initialize, when set, causes the LANCE to begin the
01111      * initialization procedure and access the Init Block.
01112      */
01113 
01114     SK_write_reg(CSR0, CSR0_INIT); 
01115 
01116     restore_flags(flags);
01117 
01118     /* Wait until LANCE finished initialization */
01119     
01120     SK_set_RAP(CSR0);              /* Register Address Pointer to CSR0 */
01121 
01122     for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++) 
01123         ; /* Wait until init done or go ahead if problems (i>=100) */
01124 
01125     if (i >= 100) /* Something is wrong ! */
01126     {
01127         printk("%s: can't init am7990, status: %04x "
01128                "init_block: %#08x\n", 
01129                 dev->name, (int) SK_read_reg(CSR0), 
01130                 (unsigned int) &(p->ram)->ib);
01131 
01132 #ifdef SK_DEBUG
01133         SK_print_pos(dev, "LANCE INIT failed");
01134         SK_print_dev(dev,"Device Structure:");
01135 #endif
01136 
01137         return -1;                 /* LANCE init failed */
01138     }
01139 
01140     PRINTK(("## %s: init done after %d ticks\n", SK_NAME, i));
01141 
01142     /* Clear Initialize done, enable Interrupts, start LANCE */
01143 
01144     SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT);
01145 
01146     PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME, 
01147             SK_read_reg(CSR0)));
01148 
01149     return 0;                      /* LANCE is up and running */
01150 
01151 } /* End of SK_lance_init() */
01152 
01153 
01154 
01155 /*-
01156  * Function       : SK_send_packet
01157  * Author         : Patrick J.D. Weichmann
01158  * Date Created   : 94/05/27
01159  *
01160  * Description    : Writes an socket buffer into a transmit descriptor
01161  *                  and starts transmission.
01162  *
01163  * Parameters     : I : struct sk_buff *skb - packet to transfer
01164  *                  I : struct device *dev  - SK_G16 device structure
01165  * Return Value   : 0 - OK
01166  *                  1 - Could not transmit (dev_queue_xmit will queue it)
01167  *                      and try to sent it later
01168  * Globals        : None
01169  * Side Effects   : None
01170  * Update History :
01171  *     YY/MM/DD  uid  Description
01172 -*/
01173 
01174 static int SK_send_packet(struct sk_buff *skb, struct device *dev)
01175 {
01176     struct priv *p = (struct priv *) dev->priv;
01177     struct tmd *tmdp;
01178     static char pad[64];
01179 
01180     if (dev->tbusy)
01181     {
01182         /* if Transmitter more than 150ms busy -> time_out */
01183 
01184         int tickssofar = jiffies - dev->trans_start;
01185         if (tickssofar < 15)
01186         {
01187             return 1;                    /* We have to try transmit later */
01188         }
01189 
01190         printk("%s: xmitter timed out, try to restart!\n", dev->name);
01191 
01192         SK_lance_init(dev, MODE_NORMAL); /* Reinit LANCE */
01193 
01194         dev->tbusy = 0;                  /* Clear Transmitter flag */
01195 
01196         dev->trans_start = jiffies;      /* Mark Start of transmission */
01197 
01198     }
01199 
01200     PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n", 
01201             SK_NAME, SK_read_reg(CSR0)));
01202 
01203 
01204     /* 
01205      * Block a timer-based transmit from overlapping. 
01206      * This means check if we are already in. 
01207      */
01208 
01209     if (test_and_set_bit(0, (void *) &dev->tbusy) != 0) /* dev->tbusy already set ? */ 
01210     {
01211         printk("%s: Transmitter access conflict.\n", dev->name);
01212     }
01213     else
01214     {
01215         /* Evaluate Packet length */
01216         short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; 
01217        
01218         tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */
01219 
01220         /* Fill in Transmit Message Descriptor */
01221 
01222         /* Copy data into dual ported ram */
01223 
01224         memcpy_toio((tmdp->u.buffer & 0x00ffffff), skb->data, skb->len);
01225         if(len != skb->len)
01226                 memcpy_toio((tmdp->u.buffer & 0x00ffffff) + skb->len, pad, len-skb->len);
01227 
01228         writew(-len, tmdp->blen);            /* set length to transmit */
01229 
01230         /* 
01231          * Packet start and end is always set because we use the maximum
01232          * packet length as buffer length.
01233          * Relinquish ownership to LANCE
01234          */
01235 
01236         writeb(TX_OWN | TX_STP | TX_ENP, tmdp->u.s.status);
01237         
01238         /* Start Demand Transmission */
01239         SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA);
01240 
01241         dev->trans_start = jiffies;   /* Mark start of transmission */
01242 
01243         /* Set pointer to next transmit buffer */
01244         p->tmdnum++; 
01245         p->tmdnum &= TMDNUM-1; 
01246 
01247         /* Do we own the next transmit buffer ? */
01248         if (! (readb((p->tmdhead + p->tmdnum)->u.s.status) & TX_OWN) )
01249         {
01250            /* 
01251             * We own next buffer and are ready to transmit, so
01252             * clear busy flag
01253             */
01254            dev->tbusy = 0;
01255         }
01256 
01257         p->stats.tx_bytes += skb->len;
01258     }
01259     dev_kfree_skb(skb);
01260     return 0;  
01261 } /* End of SK_send_packet */
01262 
01263 
01264 /*-
01265  * Function       : SK_interrupt
01266  * Author         : Patrick J.D. Weichmann
01267  * Date Created   : 94/05/27
01268  *
01269  * Description    : SK_G16 interrupt handler which checks for LANCE
01270  *                  Errors, handles transmit and receive interrupts
01271  *
01272  * Parameters     : I : int irq, void *dev_id, struct pt_regs * regs -
01273  * Return Value   : None
01274  * Errors         : None
01275  * Globals        : None
01276  * Side Effects   : None
01277  * Update History :
01278  *     YY/MM/DD  uid  Description
01279 -*/
01280 
01281 static void SK_interrupt(int irq, void *dev_id, struct pt_regs * regs)
01282 {
01283     int csr0;
01284     struct device *dev = dev_id;
01285     struct priv *p = (struct priv *) dev->priv;
01286 
01287 
01288     PRINTK2(("## %s: SK_interrupt(). status: %#06x\n", 
01289             SK_NAME, SK_read_reg(CSR0)));
01290 
01291     if (dev == NULL)
01292     {
01293         printk("SK_interrupt(): IRQ %d for unknown device.\n", irq);
01294     }
01295     
01296 
01297     if (dev->interrupt)
01298     {
01299         printk("%s: Re-entering the interrupt handler.\n", dev->name);
01300     }
01301 
01302     csr0 = SK_read_reg(CSR0);      /* store register for checking */
01303 
01304     dev->interrupt = 1;            /* We are handling an interrupt */
01305 
01306     /* 
01307      * Acknowledge all of the current interrupt sources, disable      
01308      * Interrupts (INEA = 0) 
01309      */
01310 
01311     SK_write_reg(CSR0, csr0 & CSR0_CLRALL); 
01312 
01313     if (csr0 & CSR0_ERR) /* LANCE Error */
01314     {
01315         printk("%s: error: %04x\n", dev->name, csr0);
01316       
01317         if (csr0 & CSR0_MISS)      /* No place to store packet ? */
01318         { 
01319             p->stats.rx_dropped++;
01320         }
01321     }
01322 
01323     if (csr0 & CSR0_RINT)          /* Receive Interrupt (packet arrived) */ 
01324     {
01325         SK_rxintr(dev); 
01326     }
01327 
01328     if (csr0 & CSR0_TINT)          /* Transmit interrupt (packet sent) */
01329     {
01330         SK_txintr(dev);
01331     }
01332 
01333     SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */
01334 
01335     dev->interrupt = 0;            /* We are out */
01336 } /* End of SK_interrupt() */ 
01337 
01338 
01339 /*-
01340  * Function       : SK_txintr
01341  * Author         : Patrick J.D. Weichmann
01342  * Date Created   : 94/05/27
01343  *
01344  * Description    : After sending a packet we check status, update
01345  *                  statistics and relinquish ownership of transmit 
01346  *                  descriptor ring.
01347  *
01348  * Parameters     : I : struct device *dev - SK_G16 device structure
01349  * Return Value   : None
01350  * Errors         : None
01351  * Globals        : None
01352  * Update History :
01353  *     YY/MM/DD  uid  Description
01354 -*/
01355 
01356 static void SK_txintr(struct device *dev)
01357 {
01358     int tmdstat;
01359     struct tmd *tmdp;
01360     struct priv *p = (struct priv *) dev->priv;
01361 
01362 
01363     PRINTK2(("## %s: SK_txintr() status: %#06x\n", 
01364             SK_NAME, SK_read_reg(CSR0)));
01365 
01366     tmdp = p->tmdhead + p->tmdlast;     /* Which buffer we sent at last ? */
01367 
01368     /* Set next buffer */
01369     p->tmdlast++;
01370     p->tmdlast &= TMDNUM-1;
01371 
01372     tmdstat = readb(tmdp->u.s.status);
01373 
01374     /* 
01375      * We check status of transmitted packet.
01376      * see LANCE data-sheet for error explanation
01377      */
01378     if (tmdstat & TX_ERR) /* Error occurred */
01379     {
01380         int stat2 = readw(tmdp->status2);
01381 
01382         printk("%s: TX error: %04x %04x\n", dev->name, tmdstat, stat2);
01383 
01384         if (stat2 & TX_TDR)    /* TDR problems? */
01385         {
01386             printk("%s: tdr-problems \n", dev->name);
01387         }
01388 
01389         if (stat2 & TX_RTRY)   /* Failed in 16 attempts to transmit ? */
01390             p->stats.tx_aborted_errors++;   
01391         if (stat2 & TX_LCOL)   /* Late collision ? */
01392             p->stats.tx_window_errors++; 
01393         if (stat2 & TX_LCAR)   /* Loss of Carrier ? */  
01394             p->stats.tx_carrier_errors++;
01395         if (stat2 & TX_UFLO)   /* Underflow error ? */
01396         {
01397             p->stats.tx_fifo_errors++;
01398 
01399             /* 
01400              * If UFLO error occurs it will turn transmitter of.
01401              * So we must reinit LANCE
01402              */
01403 
01404             SK_lance_init(dev, MODE_NORMAL);
01405         }
01406         
01407         p->stats.tx_errors++;
01408 
01409         writew(0, tmdp->status2);             /* Clear error flags */
01410     }
01411     else if (tmdstat & TX_MORE)        /* Collisions occurred ? */
01412     {
01413         /* 
01414          * Here I have a problem.
01415          * I only know that there must be one or up to 15 collisions.
01416          * That's why TX_MORE is set, because after 16 attempts TX_RTRY
01417          * will be set which means couldn't send packet aborted transfer.
01418          *
01419          * First I did not have this in but then I thought at minimum
01420          * we see that something was not ok.
01421          * If anyone knows something better than this to handle this
01422          * please report it.
01423          */ 
01424 
01425         p->stats.collisions++; 
01426     }
01427     else   /* Packet sent without any problems */
01428     {
01429         p->stats.tx_packets++; 
01430     }
01431 
01432     /* 
01433      * We mark transmitter not busy anymore, because now we have a free
01434      * transmit descriptor which can be filled by SK_send_packet and
01435      * afterwards sent by the LANCE
01436      */
01437 
01438     dev->tbusy = 0; 
01439 
01440     /* 
01441      * mark_bh(NET_BH);
01442      * This will cause net_bh() to run after this interrupt handler.
01443      *
01444      * The function which do handle slow IRQ parts is do_bottom_half()
01445      * which runs at normal kernel priority, that means all interrupt are
01446      * enabled. (see kernel/irq.c)
01447      *  
01448      * net_bh does something like this:
01449      *  - check if already in net_bh
01450      *  - try to transmit something from the send queue
01451      *  - if something is in the receive queue send it up to higher 
01452      *    levels if it is a known protocol
01453      *  - try to transmit something from the send queue
01454      */
01455 
01456     mark_bh(NET_BH); 
01457 
01458 } /* End of SK_txintr() */
01459 
01460 
01461 /*-
01462  * Function       : SK_rxintr
01463  * Author         : Patrick J.D. Weichmann
01464  * Date Created   : 94/05/27
01465  *
01466  * Description    : Buffer sent, check for errors, relinquish ownership
01467  *                  of the receive message descriptor. 
01468  *
01469  * Parameters     : I : SK_G16 device structure
01470  * Return Value   : None
01471  * Globals        : None
01472  * Update History :
01473  *     YY/MM/DD  uid  Description
01474 -*/
01475 
01476 static void SK_rxintr(struct device *dev)
01477 {
01478 
01479     struct rmd *rmdp;
01480     int rmdstat;
01481     struct priv *p = (struct priv *) dev->priv;
01482 
01483     PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n", 
01484             SK_NAME, SK_read_reg(CSR0)));
01485 
01486     rmdp = p->rmdhead + p->rmdnum;
01487 
01488     /* As long as we own the next entry, check status and send
01489      * it up to higher layer 
01490      */
01491 
01492     while (!( (rmdstat = readb(rmdp->u.s.status)) & RX_OWN))
01493     {
01494         /* 
01495          * Start and end of packet must be set, because we use 
01496          * the ethernet maximum packet length (1518) as buffer size.
01497          * 
01498          * Because our buffers are at maximum OFLO and BUFF errors are
01499          * not to be concerned (see Data sheet)
01500          */
01501 
01502         if ((rmdstat & (RX_STP | RX_ENP)) != (RX_STP | RX_ENP))
01503         {
01504             /* Start of a frame > 1518 Bytes ? */
01505 
01506             if (rmdstat & RX_STP) 
01507             {
01508                 p->stats.rx_errors++;        /* bad packet received */
01509                 p->stats.rx_length_errors++; /* packet too long */
01510 
01511                 printk("%s: packet too long\n", dev->name);
01512             }
01513             
01514             /* 
01515              * All other packets will be ignored until a new frame with
01516              * start (RX_STP) set follows.
01517              * 
01518              * What we do is just give descriptor free for new incoming
01519              * packets. 
01520              */
01521 
01522             writeb(RX_OWN, rmdp->u.s.status); /* Relinquish ownership to LANCE */ 
01523 
01524         }
01525         else if (rmdstat & RX_ERR)          /* Receive Error ? */
01526         {
01527             printk("%s: RX error: %04x\n", dev->name, (int) rmdstat);
01528             
01529             p->stats.rx_errors++;
01530 
01531             if (rmdstat & RX_FRAM) p->stats.rx_frame_errors++;
01532             if (rmdstat & RX_CRC)  p->stats.rx_crc_errors++;
01533 
01534             writeb(RX_OWN, rmdp->u.s.status); /* Relinquish ownership to LANCE */
01535 
01536         }
01537         else /* We have a packet which can be queued for the upper layers */
01538         {
01539 
01540             int len = readw(rmdp->mlen) & 0x0fff;  /* extract message length from receive buffer */
01541             struct sk_buff *skb;
01542 
01543             skb = dev_alloc_skb(len+2); /* allocate socket buffer */ 
01544 
01545             if (skb == NULL)                /* Could not get mem ? */
01546             {
01547     
01548                 /* 
01549                  * Couldn't allocate sk_buffer so we give descriptor back
01550                  * t