root/drivers/net/sk_g16.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. SK_init
  2. SK_probe
  3. SK_open
  4. SK_lance_init
  5. SK_send_packet
  6. SK_interrupt
  7. SK_txintr
  8. SK_rxintr
  9. SK_close
  10. SK_get_stats
  11. set_multicast_list
  12. SK_rom_addr
  13. SK_reset_board
  14. SK_set_RAP
  15. SK_read_reg
  16. SK_rread_reg
  17. SK_write_reg
  18. SK_print_pos
  19. SK_print_dev
  20. SK_print_ram

   1 /*-
   2  * Copyright (C) 1994 by PJD Weichmann & SWS Bern, Switzerland
   3  *
   4  * This software may be used and distributed according to the terms
   5  * of the GNU Public License, incorporated herein by reference.
   6  *
   7  * Module         : sk_g16.c
   8  *
   9  * Version        : $Revision: 1.1 $
  10  *
  11  * Author         : Patrick J.D. Weichmann
  12  *
  13  * Date Created   : 94/05/26
  14  * Last Updated   : $Date: 1994/06/30 16:25:15 $
  15  *
  16  * Description    : Schneider & Koch G16 Ethernet Device Driver for
  17  *                  Linux Kernel >= 1.1.22
  18  * Update History :
  19  *
  20 -*/
  21 
  22 static char *rcsid = "$Id: sk_g16.c,v 1.1 1994/06/30 16:25:15 root Exp $";
  23 
  24 /*
  25  * The Schneider & Koch (SK) G16 Network device driver is based
  26  * on the 'ni6510' driver from Michael Hipp which can be found at
  27  * ftp://sunsite.unc.edu/pub/Linux/system/Network/drivers/nidrivers.tar.gz
  28  * 
  29  * Sources: 1) ni6510.c by M. Hipp
  30  *          2) depca.c  by D.C. Davies
  31  *          3) skeleton.c by D. Becker
  32  *          4) Am7990 Local Area Network Controller for Ethernet (LANCE),
  33  *             AMD, Pub. #05698, June 1989
  34  *
  35  * Many Thanks for helping me to get things working to: 
  36  *                 
  37  *                 A. Cox (A.Cox@swansea.ac.uk)
  38  *                 M. Hipp (mhipp@student.uni-tuebingen.de)
  39  *                 R. Bolz (Schneider & Koch, Germany)
  40  *
  41  * See README.sk_g16 for details about limitations and bugs for the
  42  * current version.
  43  *
  44  * To Do: 
  45  *        - Support of SK_G8 and other SK Network Cards.
  46  *        - Autoset memory mapped RAM. Check for free memory and then
  47  *          configure RAM correctly. 
  48  *        - SK_close should really set card in to initial state.
  49  *        - Test if IRQ 3 is not switched off. Use autoirq() functionality.
  50  *          (as in /drivers/net/skeleton.c)
  51  *        - Implement Multicast addressing. At minimum something like
  52  *          in depca.c. 
  53  *        - Redo the statistics part.
  54  *        - Try to find out if the board is in 8 Bit or 16 Bit slot.
  55  *          If in 8 Bit mode don't use IRQ 11.
  56  *        - (Try to make it slightly faster.) 
  57  */
  58 
  59 #include <linux/config.h>
  60 #include <linux/kernel.h>
  61 #include <linux/sched.h>
  62 #include <linux/ptrace.h>
  63 #include <linux/fcntl.h>
  64 #include <linux/ioport.h>
  65 #include <linux/interrupt.h>
  66 #include <linux/malloc.h>
  67 #include <linux/ioport.h>
  68 #include <linux/string.h> 
  69 #include <asm/system.h>
  70 #include <asm/io.h>
  71 #include <asm/bitops.h> 
  72 #include <errno.h>
  73 
  74 #include <linux/netdevice.h>
  75 #include <linux/etherdevice.h>
  76 #include <linux/skbuff.h>
  77 
  78 #include "sk_g16.h"
  79 
  80 /* 
  81  * Schneider & Koch Card Definitions 
  82  * =================================
  83  */  
  84 
  85 #define SK_NAME   "SK_G16"
  86 
  87 /*
  88  * SK_G16 Configuration
  89  * --------------------
  90  */ 
  91 
  92 /* 
  93  * Abbreviations
  94  * -------------
  95  *  
  96  * RAM - used for the 16KB shared memory 
  97  * Boot_ROM, ROM - are used for referencing the BootEPROM
  98  *
  99  * SK_BOOT_ROM and SK_ADDR are symbolic constants used to configure
 100  * the behaviour of the driver and the SK_G16.
 101  *
 102  * ! See sk_g16.install on how to install and configure the driver !   
 103  *
 104  * SK_BOOT_ROM defines if the Boot_ROM should be switched off or not.
 105  *
 106  * SK_ADDR defines the address where the RAM will be mapped into the real
 107  *         host memory.
 108  *         valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps.
 109  */  
 110  
 111 #define SK_BOOT_ROM     1              /* 1=BootROM on 0=off */
 112 
 113 #define SK_ADDR         0xcc000
 114 
 115 /* 
 116  * In POS3 are bits A14-A19 of the address bus. These bits can be set
 117  * to choose the RAM address. Thats why we only can choose the RAM address
 118  * in 16KB steps.
 119  */
 120 
 121 #define POS_ADDR       (rom_addr>>14)  /* Do not change this line */
 122 
 123 /* 
 124  * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations
 125  * ----------------------------------------------
 126  */
 127 
 128 /* 
 129  * As nearly every card has also SK_G16 a specified I/O Port region and
 130  * only a few possible IRQ's.
 131  * In the Installation Guide from Schneider & Koch is listed a possible
 132  * Interrupt IRQ2. IRQ2 is always IRQ9 in boards with two cascaded interrupt
 133  * controllers. So we use in SK_IRQS IRQ9.
 134  */
 135 
 136 /* Don't touch any of the following #defines. */
 137 
 138 #define SK_IO_PORTS     { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 }
 139 
 140 #define SK_IRQS         { 3, 5, 9, 11, 0 }
 141 
 142 #define SK_BOOT_ROM_LOCATIONS { 0xc0000, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000, 0 }
 143 
 144 #define SK_BOOT_ROM_ID  { 0x55, 0xaa, 0x10, 0x50, 0x06, 0x33 }
 145 
 146 /* 
 147  * SK_G16 POS REGISTERS 
 148  * --------------------
 149  */
 150 
 151 /*
 152  * SK_G16 has a Programmable Option Select (POS) Register.
 153  * The POS is composed of 8 separate registers (POS0-7) which 
 154  * are I/O mapped on an address set by the W1 switch.                    
 155  *
 156  */
 157 
 158 #define SK_POS_SIZE 8           /* 8 I/O Ports are used by SK_G16 */
 159 
 160 #define SK_POS0     ioaddr      /* Card-ID Low (R) */
 161 #define SK_POS1     ioaddr+1    /* Card-ID High (R) */
 162 #define SK_POS2     ioaddr+2    /* Card-Enable, Boot-ROM Disable (RW) */
 163 #define SK_POS3     ioaddr+3    /* Base address of RAM */
 164 #define SK_POS4     ioaddr+4    /* IRQ */
 165 
 166 /* POS5 - POS7 are unused */
 167 
 168 /* 
 169  * SK_G16 MAC PREFIX 
 170  * -----------------
 171  */
 172 
 173 /* 
 174  * Scheider & Koch manufactorer code (00:00:a5).
 175  * This must be checked, that we are sure it is a SK card.
 176  */
 177 
 178 #define SK_MAC0         0x00
 179 #define SK_MAC1         0x00
 180 #define SK_MAC2         0x5a
 181 
 182 /* 
 183  * SK_G16 ID 
 184  * ---------
 185  */ 
 186 
 187 /* 
 188  * If POS0,POS1 contain the following ID, then we know
 189  * at which I/O Port Address we are. 
 190  */
 191 
 192 #define SK_IDLOW  0xfd 
 193 #define SK_IDHIGH 0x6a
 194 
 195 
 196 /* 
 197  * LANCE POS Bit definitions 
 198  * -------------------------
 199  */
 200 
 201 #define SK_ROM_RAM_ON  (POS2_CARD)
 202 #define SK_ROM_RAM_OFF (POS2_EPROM)
 203 #define SK_ROM_ON      (inb(SK_POS2) & POS2_CARD)
 204 #define SK_ROM_OFF     (inb(SK_POS2) | POS2_EPROM)
 205 #define SK_RAM_ON      (inb(SK_POS2) | POS2_CARD)
 206 #define SK_RAM_OFF     (inb(SK_POS2) & POS2_EPROM) 
 207 
 208 #define POS2_CARD  0x0001              /* 1 = SK_G16 on      0 = off */
 209 #define POS2_EPROM 0x0002              /* 1 = Boot EPROM off 0 = on */ 
 210 
 211 /* 
 212  * SK_G16 Memory mapped Registers
 213  * ------------------------------
 214  *
 215  */ 
 216 
 217 #define SK_IOREG        (board->ioreg) /* LANCE data registers.     */ 
 218 #define SK_PORT         (board->port)  /* Control, Status register  */
 219 #define SK_IOCOM        (board->iocom) /* I/O Command               */
 220 
 221 /* 
 222  * SK_G16 Status/Control Register bits
 223  * -----------------------------------
 224  *
 225  * (C) Controlreg (S) Statusreg 
 226  */
 227 
 228 /* 
 229  * Register transfer: 0 = no transfer
 230  *                    1 = transfering data between LANCE and I/O reg 
 231  */
 232 #define SK_IORUN        0x20   
 233 
 234 /* 
 235  * LANCE interrupt: 0 = LANCE interrupt occured 
 236  *                  1 = no LANCE interrupt occured
 237  */
 238 #define SK_IRQ          0x10   
 239                         
 240 #define SK_RESET        0x08   /* Reset SK_CARD: 0 = RESET 1 = normal */
 241 #define SK_RW           0x02   /* 0 = write to 1 = read from */
 242 #define SK_ADR          0x01   /* 0 = REG DataPort 1 = RAP Reg addr port */
 243 
 244   
 245 #define SK_RREG         SK_RW  /* Transferdirection to read from lance */
 246 #define SK_WREG         0      /* Transferdirection to write to lance */
 247 #define SK_RAP          SK_ADR /* Destination Register RAP */
 248 #define SK_RDATA        0      /* Destination Register REG DataPort */
 249 
 250 /* 
 251  * SK_G16 I/O Command 
 252  * ------------------
 253  */
 254 
 255 /* 
 256  * Any bitcombination sets the internal I/O bit (transfer will start) 
 257  * when written to I/O Command
 258  */
 259 
 260 #define SK_DOIO         0x80   /* Do Transfer */ 
 261  
 262 /* 
 263  * LANCE RAP (Register Adress Port). 
 264  * ---------------------------------
 265  */
 266 
 267 /*   
 268  * The LANCE internal registers are selected through the RAP. 
 269  * The Registers are:
 270  *
 271  * CSR0 - Status and Control flags 
 272  * CSR1 - Low order bits of initialize block (bits 15:00)
 273  * CSR2 - High order bits of initialize block (bits 07:00, 15:08 are reserved)
 274  * CSR3 - Allows redifinition of the Bus Master Interface.
 275  *        This register must be set to 0x0002, which means BSWAP = 0,
 276  *        ACON = 1, BCON = 0;
 277  *
 278  */
 279  
 280 #define CSR0            0x00   
 281 #define CSR1            0x01  
 282 #define CSR2            0x02 
 283 #define CSR3            0x03
 284 
 285 /* 
 286  * General Definitions 
 287  * ===================
 288  */
 289 
 290 /* 
 291  * Set the number of Tx and Rx buffers, using Log_2(# buffers).
 292  * We have 16KB RAM which can be accessed by the LANCE. In the 
 293  * memory are not only the buffers but also the ring descriptors and
 294  * the initialize block. 
 295  * Don't change anything unless you really know what you do.
 296  */
 297 
 298 #define LC_LOG_TX_BUFFERS 1               /* (2 == 2^^1) 2 Transmit buffers */
 299 #define LC_LOG_RX_BUFFERS 3               /* (8 == 2^^3) 8 Receive buffers */
 300 
 301 /* Descriptor ring sizes */
 302 
 303 #define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */
 304 #define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers */
 305 
 306 /* Define Mask for setting RMD, TMD length in the LANCE init_block */
 307 
 308 #define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29)
 309 #define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29)
 310 
 311 /*
 312  * Data Buffer size is set to maximum packet length.
 313  */
 314 
 315 #define PKT_BUF_SZ              1518 
 316 
 317 /* 
 318  * The number of low I/O ports used by the ethercard. 
 319  */
 320 
 321 #define ETHERCARD_TOTAL_SIZE    SK_POS_SIZE
 322 
 323 /* 
 324  * Portreserve is there to mark the Card I/O Port region as used. 
 325  * Check_region is to check if the region at ioaddr with the size "size" 
 326  * is free or not.
 327  * Snarf_region allocates the I/O Port region.
 328  */
 329 
 330 #ifndef HAVE_PORTRESERVE
 331 
 332 #define check_region(ioaddr, size)              0
 333 #define snarf_region(ioaddr, size);             do ; while (0)
 334 
 335 #endif
 336 
 337 /* 
 338  * SK_DEBUG
 339  *
 340  * Here you can choose what level of debugging wanted.
 341  *
 342  * If SK_DEBUG and SK_DEBUG2 are undefined, then only the
 343  *  necessary messages will be printed.
 344  *
 345  * If SK_DEBUG is defined, there will be many debugging prints
 346  *  which can help to find some mistakes in configuration or even
 347  *  in the driver code.
 348  *
 349  * If SK_DEBUG2 is defined, many many messages will be printed 
 350  *  which normally you don't need. I used this to check the interrupt
 351  *  routine. 
 352  *
 353  * (If you define only SK_DEBUG2 then only the messages for 
 354  *  checking interrupts will be printed!)
 355  *
 356  * Normal way of live is: 
 357  *
 358  * For the whole thing get going let both symbolic constants
 359  * undefined. If you face any problems and you know whats going
 360  * on (you know something about the card and you can interpret some
 361  * hex LANCE register output) then define SK_DEBUG
 362  * 
 363  */
 364 
 365 #undef  SK_DEBUG        /* debugging */
 366 #undef  SK_DEBUG2       /* debugging with more verbose report */
 367 
 368 #ifdef SK_DEBUG
 369 #define PRINTK(x) printk x
 370 #else
 371 #define PRINTK(x) /**/
 372 #endif
 373 
 374 #ifdef SK_DEBUG2
 375 #define PRINTK2(x) printk x
 376 #else
 377 #define PRINTK2(x) /**/
 378 #endif
 379 
 380 /* 
 381  * SK_G16 RAM
 382  *
 383  * The components are memory mapped and can be set in a region from
 384  * 0x00000 through 0xfc000 in 16KB steps. 
 385  *
 386  * The Network components are: dual ported RAM, Prom, I/O Reg, Status-,
 387  * Controlregister and I/O Command.
 388  *
 389  * dual ported RAM: This is the only memory region which the LANCE chip
 390  *      has access to. From the Lance it is addressed from 0x0000 to
 391  *      0x3fbf. The host accesses it normaly.
 392  *
 393  * PROM: The PROM obtains the ETHERNET-MAC-Address. It is realised as a
 394  *       8-Bit PROM, this means only the 16 even addresses are used of the
 395  *       32 Byte Address region. Access to a odd address results in invalid
 396  *       data.
 397  * 
 398  * LANCE I/O Reg: The I/O Reg is build of 4 single Registers, Low-Byte Write,
 399  *       Hi-Byte Write, Low-Byte Read, Hi-Byte Read.
 400  *       Transfer from or to the LANCE is always in 16Bit so Low and High
 401  *       registers are always relevant.
 402  *
 403  *       The Data from the Readregister is not the data in the Writeregister!!
 404  *       
 405  * Port: Status- and Controlregister. 
 406  *       Two different registers which share the same address, Status is 
 407  *       read-only, Control is write-only.
 408  *    
 409  * I/O Command: 
 410  *       Any bitcombination written in here starts the transmission between
 411  *       Host and LANCE.
 412  */
 413 
 414 typedef struct
 415 {
 416         unsigned char  ram[0x3fc0];   /* 16KB dual ported ram */
 417         unsigned char  rom[0x0020];   /* 32Byte PROM containing 6Byte MAC */
 418         unsigned char  res1[0x0010];  /* reserved */
 419         unsigned volatile short ioreg;/* LANCE I/O Register */
 420         unsigned volatile char  port; /* Statusregister and Controlregister */
 421         unsigned char  iocom;         /* I/O Command Register */
 422 } SK_RAM;
 423 
 424 /* struct  */
 425 
 426 /* 
 427  * This is the structure for the dual ported ram. We
 428  * have exactly 16 320 Bytes. In here there must be:
 429  *
 430  *     - Initialize Block   (starting at a word boundary)
 431  *     - Receive and Transmit Descriptor Rings (quadword boundary)
 432  *     - Data Buffers (arbitrary boundary)
 433  *
 434  * This is because LANCE has on SK_G16 only access to the dual ported
 435  * RAM and nowhere else.
 436  */
 437 
 438 struct SK_ram
 439 {
 440     struct init_block ib;
 441     struct tmd tmde[TMDNUM];
 442     struct rmd rmde[RMDNUM];
 443     char tmdbuf[TMDNUM][PKT_BUF_SZ];
 444     char rmdbuf[RMDNUM][PKT_BUF_SZ];
 445 };
 446 
 447 /* 
 448  * Structure where all necessary information is for ring buffer 
 449  * management and statistics.
 450  */
 451 
 452 struct priv
 453 {
 454     struct SK_ram *ram;  /* dual ported ram structure */
 455     struct rmd *rmdhead; /* start of receive ring descriptors */
 456     struct tmd *tmdhead; /* start of transmit ring descriptors */
 457     int        rmdnum;   /* actual used ring descriptor */
 458     int        tmdnum;   /* actual transmit descriptor for transmitting data */
 459     int        tmdlast;  /* last sent descriptor used for error handling, etc */
 460     void       *rmdbufs[RMDNUM]; /* pointer to the receive buffers */
 461     void       *tmdbufs[TMDNUM]; /* pointer to the transmit buffers */
 462     struct enet_statistics stats; /* Device driver statistics */
 463 };
 464 
 465 /* global variable declaration */
 466 
 467 /* IRQ map used to reserve a IRQ (see SK_open()) */
 468 
 469 extern void *irq2dev_map[16]; 
 470 
 471 /* static variables */
 472 
 473 static SK_RAM *board;  /* pointer to our memory mapped board components */
 474 
 475 /* Macros */
 476 
 477 
 478 /* Function Prototypes */
 479 
 480 /*
 481  * Device Driver functions
 482  * -----------------------
 483  * See for short explanation of each function its definitions header.
 484  */
 485 
 486 int          SK_init(struct device *dev);
 487 static int   SK_probe(struct device *dev, short ioaddr);
 488 
 489 static int   SK_open(struct device *dev);
 490 static int   SK_send_packet(struct sk_buff *skb, struct device *dev);
 491 static void  SK_interrupt(int reg_ptr);
 492 static void  SK_rxintr(struct device *dev);
 493 static void  SK_txintr(struct device *dev);
 494 static int   SK_close(struct device *dev);
 495 
 496 static struct enet_statistics *SK_get_stats(struct device *dev);
 497 
 498 unsigned int SK_rom_addr(void);
 499 
 500 #ifdef HAVE_MULTICAST
 501 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
 502 #endif
 503 
 504 /*
 505  * LANCE Functions
 506  * ---------------
 507  */
 508 
 509 static int SK_lance_init(struct device *dev, unsigned short mode);
 510 void   SK_reset_board(void);
 511 void   SK_set_RAP(int reg_number);
 512 int    SK_read_reg(int reg_number);
 513 int    SK_rread_reg(void);
 514 void   SK_write_reg(int reg_number, int value);
 515 
 516 /* 
 517  * Debuging functions
 518  * ------------------
 519  */
 520 
 521 void SK_print_pos(struct device *dev, char *text);
 522 void SK_print_dev(struct device *dev, char *text);
 523 void SK_print_ram(struct device *dev);
 524 
 525 
 526 /*-
 527  * Function       : SK_init
 528  * Author         : Patrick J.D. Weichmann
 529  * Date Created   : 94/05/26
 530  *
 531  * Description    : Check for a SK_G16 network adaptor and initialize it.
 532  *                  This function gets called by dev_init which initializes
 533  *                  all Network devices.
 534  *
 535  * Parameters     : I : struct device *dev - structure preconfigured 
 536  *                                           from Space.c
 537  * Return Value   : 0 = Driver Found and initialized 
 538  * Errors         : ENODEV - no device found
 539  *                  ENXIO  - not probed
 540  * Globals        : None
 541  * Update History :
 542  *     YY/MM/DD  uid  Description
 543 -*/
 544 
 545 /* 
 546  * Check for a network adaptor of this type, and return '0' if one exists.
 547  * If dev->base_addr == 0, probe all likely locations.
 548  * If dev->base_addr == 1, always return failure.
 549  * If dev->base_addr == 2, alloate space for the device and return success
 550  *                         (detachable devices only).
 551  */
 552 
 553 int SK_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 554 {
 555         int ioaddr         = 0;            /* I/O port address used for POS regs */
 556         int *port, ports[] = SK_IO_PORTS;  /* SK_G16 supported ports */
 557 
 558         /* get preconfigured base_addr from dev which is done in Space.c */
 559         int base_addr = dev->base_addr; 
 560 
 561         PRINTK(("%s: %s", SK_NAME, rcsid));
 562         rcsid = NULL;                 /* We do not want to use this further */
 563 
 564         if (base_addr > 0x0ff)        /* Check a single specified address */
 565         {
 566             /* Check if on specified address is a SK_G16 */
 567 
 568             if ( (inb(SK_POS0) == SK_IDLOW) ||
 569                  (inb(SK_POS1) == SK_IDHIGH) )  
 570             {
 571                 return SK_probe(dev, base_addr);  
 572             }
 573 
 574             return ENODEV;            /* Sorry, but on specified address NO SK_G16 */
 575         }
 576         else if (base_addr > 0)       /* Don't probe at all */
 577         {
 578                 return ENXIO;
 579         }
 580 
 581         /* Autoprobe base_addr */
 582 
 583         for (port = &ports[0]; *port; port++) 
 584         {
 585             ioaddr = *port;           /* we need ioaddr for accessing POS regs */
 586 
 587             /* Check if I/O Port region is used by another board */
 588 
 589             if (check_region(ioaddr, ETHERCARD_TOTAL_SIZE))
 590             {
 591                 continue;             /* Try next Port address */
 592             }
 593 
 594             /* Check if at ioaddr is a SK_G16 */
 595 
 596             if ( !(inb(SK_POS0) == SK_IDLOW) ||
 597                  !(inb(SK_POS1) == SK_IDHIGH) )
 598             {
 599                 continue;             /* Try next Port address */
 600             }
 601 
 602             dev->base_addr = ioaddr;  /* Set I/O Port Address */
 603 
 604             if (SK_probe(dev, ioaddr) == 0)  
 605             {
 606                 return 0; /* Card found and initialized */
 607             }
 608         }
 609 
 610         dev->base_addr = base_addr;   /* Write back original base_addr */
 611 
 612         return ENODEV;                /* Failed to find or init driver */
 613 
 614 } /* End of SK_init */
 615 
 616 
 617 /*-
 618  * Function       : SK_probe
 619  * Author         : Patrick J.D. Weichmann
 620  * Date Created   : 94/05/26
 621  *
 622  * Description    : This function is called by SK_init and 
 623  *                  does the main part of initialization.
 624  *                  
 625  * Parameters     : I : struct device *dev - SK_G16 device structure
 626  *                  I : short ioaddr       - I/O Port address where POS is.
 627  * Return Value   : 0 = Initilization done             
 628  * Errors         : ENODEV - No SK_G16 found
 629  *                  -1     - Configuration problem
 630  * Globals        : irq2dev_map - Which device uses which IRQ
 631  *                : board       - pointer to SK_RAM
 632  * Update History :
 633  *     YY/MM/DD  uid  Description
 634  *     94/06/30  pwe  SK_ADDR now checked and at the correct place
 635 -*/
 636 
 637 int SK_probe(struct device *dev, short ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 638 {
 639     int i,j;                /* Counters */
 640     int sk_addr_flag = 0;   /* SK ADDR correct? 1 - no, 0 - yes */
 641     unsigned int rom_addr;  /* used to store RAM address used for POS_ADDR */
 642 
 643     struct priv *p;         /* SK_G16 private structure */
 644 
 645     if (SK_ADDR & 0x3fff || SK_ADDR < 0xa0000)
 646     {
 647       
 648        sk_addr_flag = 1;
 649 
 650        /* 
 651         * Now here we could use a routine which searches for a free
 652         * place in the ram and set SK_ADDR if found. TODO. 
 653         */
 654     }
 655 
 656     if (SK_BOOT_ROM)            /* Shall we keep Boot_ROM on ? */
 657     {
 658         PRINTK(("## %s: SK_BOOT_ROM is set.\n", SK_NAME));
 659 
 660         rom_addr = SK_rom_addr();
 661 
 662         if (rom_addr == 0)      /* No Boot_ROM found */
 663         {
 664             if (sk_addr_flag)   /* No or Invalid SK_ADDR is defined */ 
 665             {
 666                 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
 667                        dev->name, SK_ADDR);
 668                 return -1;
 669             }
 670 
 671             rom_addr = SK_ADDR; /* assign predefined address */
 672 
 673             PRINTK(("## %s: NO Bootrom found \n", SK_NAME));
 674 
 675             outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */
 676             outb(POS_ADDR, SK_POS3);       /* Set RAM address */
 677             outb(SK_RAM_ON, SK_POS2);      /* enable RAM */
 678         }
 679         else if (rom_addr == SK_ADDR) 
 680         {
 681             printk("%s: RAM + ROM are set to the same address %#08x\n"
 682                    "   Check configuration. Now switching off Boot_ROM\n",
 683                    SK_NAME, rom_addr);
 684 
 685             outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off*/
 686             outb(POS_ADDR, SK_POS3);       /* Set RAM address */
 687             outb(SK_RAM_ON, SK_POS2);      /* enable RAM */
 688         }
 689         else
 690         {
 691             PRINTK(("## %s: Found ROM at %#08x\n", SK_NAME, rom_addr));
 692             PRINTK(("## %s: Keeping Boot_ROM on\n", SK_NAME));
 693 
 694             if (sk_addr_flag)       /* No or Invalid SK_ADDR is defined */ 
 695             {
 696                 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
 697                        dev->name, SK_ADDR);
 698                 return -1;
 699             }
 700 
 701             rom_addr = SK_ADDR;
 702 
 703             outb(SK_ROM_RAM_OFF, SK_POS2); /* Boot_ROM + RAM off */ 
 704             outb(POS_ADDR, SK_POS3);       /* Set RAM address */
 705             outb(SK_ROM_RAM_ON, SK_POS2);  /* RAM on, BOOT_ROM on */
 706         }
 707     }
 708     else /* Don't keep Boot_ROM */
 709     {
 710         PRINTK(("## %s: SK_BOOT_ROM is not set.\n", SK_NAME));
 711 
 712         if (sk_addr_flag)           /* No or Invalid SK_ADDR is defined */ 
 713         {
 714             printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
 715                    dev->name, SK_ADDR);
 716             return -1;
 717         }
 718 
 719         rom_addr = SK_rom_addr();          /* Try to find a Boot_ROM */
 720 
 721         /* IF we find a Boot_ROM disable it */
 722 
 723         outb(SK_ROM_RAM_OFF, SK_POS2);     /* Boot_ROM + RAM off */  
 724 
 725         /* We found a Boot_ROM and its gone. Set RAM address on
 726          * Boot_ROM address. 
 727          */ 
 728 
 729         if (rom_addr) 
 730         {
 731             printk("%s: We found Boot_ROM at %#08x. Now setting RAM on"
 732                    "that address\n", SK_NAME, rom_addr);
 733 
 734             outb(POS_ADDR, SK_POS3);       /* Set RAM on Boot_ROM address */
 735         }
 736         else /* We did not find a Boot_ROM, use predefined SK_ADDR for ram */
 737         {
 738             if (sk_addr_flag)       /* No or Invalid SK_ADDR is defined */ 
 739             {
 740                 printk("%s: SK_ADDR %#08x is not valid. Check configuration.\n",
 741                        dev->name, SK_ADDR);
 742                 return -1;
 743             }
 744 
 745             rom_addr = SK_ADDR;
 746 
 747             outb(POS_ADDR, SK_POS3);       /* Set RAM address */ 
 748         }
 749         outb(SK_RAM_ON, SK_POS2);          /* enable RAM */
 750     }
 751 
 752 #ifdef SK_DEBUG
 753     SK_print_pos(dev, "POS registers after ROM, RAM config");
 754 #endif
 755 
 756     board = (SK_RAM *) rom_addr; 
 757 
 758     /* Read in station address */
 759     for (i = 0, j = 0; i < ETH_ALEN; i++, j+=2)
 760     {
 761         dev->dev_addr[i] = board->rom[j];          
 762     }
 763 
 764     /* Check for manufactorer code */
 765     if (!(dev->dev_addr[0] == SK_MAC0 &&
 766           dev->dev_addr[1] == SK_MAC1 &&
 767           dev->dev_addr[2] == SK_MAC2) )
 768     {
 769         PRINTK(("## %s: We did not find SK_G16 at RAM location.\n",
 770                 SK_NAME)); 
 771         return ENODEV;                     /* NO SK_G16 found */
 772     }
 773 
 774     printk("%s: %s found at %#3x, HW addr: %#04x:%02x:%02x:%02x:%02x:%02x\n",
 775             dev->name,
 776             "Schneider & Koch Netcard",
 777             (unsigned int) dev->base_addr,
 778             dev->dev_addr[0],
 779             dev->dev_addr[1],
 780             dev->dev_addr[2],
 781             dev->dev_addr[3],
 782             dev->dev_addr[4],
 783             dev->dev_addr[5]);
 784 
 785     /* Grap the I/O Port region */
 786     snarf_region(ioaddr, ETHERCARD_TOTAL_SIZE);
 787 
 788     /* Initialize device structure */
 789 
 790     /* Allocate memory for private structure */
 791     p = dev->priv = (void *) kmalloc(sizeof(struct priv), GFP_KERNEL);
 792     memset((char *) dev->priv, 0, sizeof(struct priv)); /* clear memory */
 793 
 794     /* Assign our Device Driver functions */
 795 
 796     dev->open                   = &SK_open;
 797     dev->stop                   = &SK_close;
 798     dev->hard_start_xmit        = &SK_send_packet;
 799     dev->get_stats              = &SK_get_stats;
 800 
 801 #ifdef HAVE_MULTICAST
 802     dev->set_multicast_list     = &set_multicast_list;
 803 #endif
 804 
 805 
 806     /* Set the generic fields of the device structure */
 807 
 808     ether_setup(dev);
 809 
 810     /* Initialize private structure */
 811 
 812     p->ram = (struct SK_ram *) rom_addr; /* Set dual ported RAM addr */
 813     p->tmdhead = &(p->ram)->tmde[0];     /* Set TMD head */
 814     p->rmdhead = &(p->ram)->rmde[0];     /* Set RMD head */
 815 
 816     /* Initialize buffer pointers */
 817 
 818     for (i = 0; i < TMDNUM; i++)
 819     {
 820         p->tmdbufs[i] = &(p->ram)->tmdbuf[i];
 821     }
 822 
 823     for (i = 0; i < RMDNUM; i++)
 824     {
 825         p->rmdbufs[i] = &(p->ram)->rmdbuf[i]; 
 826     }
 827 
 828 #ifdef SK_DEBUG
 829     SK_print_pos(dev, "End of SK_probe");
 830     SK_print_ram(dev);
 831 #endif 
 832 
 833     return 0;                            /* Initialization done */
 834 
 835 } /* End of SK_probe() */
 836 
 837 
 838 /*- 
 839  * Function       : SK_open
 840  * Author         : Patrick J.D. Weichmann
 841  * Date Created   : 94/05/26
 842  *
 843  * Description    : This function is called sometimes after booting 
 844  *                  when ifconfig programm is run.
 845  *
 846  *                  This function requests an IRQ, sets the correct
 847  *                  IRQ in the card. Then calls SK_lance_init() to 
 848  *                  init and start the LANCE chip. Then if everthing is 
 849  *                  ok returns with 0 (OK), which means SK_G16 is now
 850  *                  opened and operational.
 851  *
 852  *                  (Called by dev_open() /net/inet/dev.c)
 853  *
 854  * Parameters     : I : struct device *dev - SK_G16 device structure
 855  * Return Value   : 0 - Device opened
 856  * Errors         : -EAGAIN - Open failed
 857  * Globals        : irq2dev_map - which device uses which irq
 858  * Side Effects   : None
 859  * Update History :
 860  *     YY/MM/DD  uid  Description
 861 -*/
 862 
 863 static int SK_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 864 {
 865     int i = 0;
 866     int irqval = 0;
 867     int ioaddr = dev->base_addr;
 868 
 869     int irqtab[] = SK_IRQS; 
 870 
 871     struct priv *p = (struct priv *)dev->priv;
 872 
 873     PRINTK(("## %s: At beginning of SK_open(). CSR0: %#06x\n", 
 874            SK_NAME, SK_read_reg(CSR0)));
 875 
 876     if (dev->irq == 0) /* Autoirq */
 877     {
 878         i = 0;
 879 
 880         /* 
 881          * Check if one IRQ out of SK_IRQS is free and install 
 882          * interrupt handler.
 883          * Most done by request_irq(). 
 884          * irqval: 0       - interrupt handler installed for IRQ irqtab[i]
 885          *         -EBUSY  - interrupt busy 
 886          *         -EINVAL - irq > 15 or handler = NULL
 887          */
 888 
 889         do
 890         {
 891           irqval = request_irq(irqtab[i], &SK_interrupt);
 892           i++;
 893         } while (irqval && irqtab[i]);
 894 
 895         if (irqval) /* We tried every possible IRQ but no success */
 896         {
 897             printk("%s: unable to get an IRQ\n", dev->name);
 898             return -EAGAIN;
 899         }
 900 
 901         dev->irq = irqtab[--i]; 
 902         
 903         outb(i<<2, SK_POS4);           /* Set Card on probed IRQ */
 904 
 905     }
 906     else if (dev->irq == 2) /* IRQ2 is always IRQ9 */
 907     {
 908         if (request_irq(9, &SK_interrupt))
 909         {
 910             printk("%s: unable to get IRQ 9\n", dev->name);
 911             return -EAGAIN;
 912         } 
 913         dev->irq = 9;
 914         
 915         /* 
 916          * Now we set card on IRQ2.
 917          * This can be confusing, but remember that IRQ2 on the network
 918          * card is in reality IRQ9
 919          */
 920         outb(0x08, SK_POS4);           /* set card to IRQ2 */
 921 
 922     }
 923     else  /* Check IRQ as defined in Space.c */
 924     {
 925         int i = 0;
 926 
 927         /* check if IRQ free and valid. Then install Interrupt handler */
 928 
 929         if (request_irq(dev->irq, &SK_interrupt))
 930         {
 931             printk("%s: unable to get selected IRQ\n", dev->name);
 932             return -EAGAIN;
 933         }
 934 
 935         switch(dev->irq)
 936         {
 937             case 3: i = 0;
 938                     break;
 939             case 5: i = 1;
 940                     break;
 941             case 2: i = 2;
 942                     break;
 943             case 11:i = 3;
 944                     break;
 945             default: 
 946                 printk("%s: Preselected IRQ %d is invalid for %s boards",
 947                        dev->name,
 948                        dev->irq,
 949                        SK_NAME);
 950                 return -EAGAIN;
 951         }      
 952   
 953         outb(i<<2, SK_POS4);           /* Set IRQ on card */
 954     }
 955 
 956     irq2dev_map[dev->irq] = dev;       /* Set IRQ as used by us */
 957     
 958     printk("%s: Schneider & Koch G16 at %#3x, IRQ %d, shared mem at %#08x\n",
 959             dev->name, (unsigned int)dev->base_addr, 
 960             (int) dev->irq, (unsigned int) p->ram);
 961 
 962     if (!(i = SK_lance_init(dev, 0)))  /* LANCE init OK? */
 963     {
 964 
 965 
 966         dev->tbusy = 0;
 967         dev->interrupt = 0;
 968         dev->start = 1;
 969 
 970 #ifdef SK_DEBUG
 971 
 972         /* 
 973          * This debug block tries to stop LANCE,
 974          * reinit LANCE with transmitter and receiver disabled,
 975          * then stop again and reinit with NORMAL_MODE
 976          */
 977 
 978         printk("## %s: After lance init. CSR0: %#06x\n", 
 979                SK_NAME, SK_read_reg(CSR0));
 980         SK_write_reg(CSR0, CSR0_STOP);
 981         printk("## %s: LANCE stopped. CSR0: %#06x\n", 
 982                SK_NAME, SK_read_reg(CSR0));
 983         SK_lance_init(dev, MODE_DTX | MODE_DRX);
 984         printk("## %s: Reinit with DTX + DRX off. CSR0: %#06x\n", 
 985                SK_NAME, SK_read_reg(CSR0));
 986         SK_write_reg(CSR0, CSR0_STOP);
 987         printk("## %s: LANCE stopped. CSR0: %#06x\n", 
 988                SK_NAME, SK_read_reg(CSR0));
 989         SK_lance_init(dev, MODE_NORMAL);
 990         printk("## %s: LANCE back to normal mode. CSR0: %#06x\n", 
 991                SK_NAME, SK_read_reg(CSR0));
 992         SK_print_pos(dev, "POS regs before returning OK");
 993 
 994 #endif /* SK_DEBUG */
 995        
 996         return 0;              /* SK_open() is successful */
 997     }
 998     else /* LANCE init failed */
 999     {
1000 
1001         PRINTK(("## %s: LANCE init failed: CSR0: %#06x\n", 
1002                SK_NAME, SK_read_reg(CSR0)));
1003 
1004         dev->start = 0;        /* Device not ready */
1005         return -EAGAIN;
1006     }
1007 
1008 } /* End of SK_open() */
1009 
1010 
1011 /*-
1012  * Function       : SK_lance_init
1013  * Author         : Patrick J.D. Weichmann
1014  * Date Created   : 94/05/26
1015  *
1016  * Description    : Reset LANCE chip, fill RMD, TMD structures with
1017  *                  start values and Start LANCE.
1018  *
1019  * Parameters     : I : struct device *dev - SK_G16 device structure
1020  *                  I : int mode - put LANCE into "mode" see data-sheet for
1021  *                                 more info.
1022  * Return Value   : 0  - Init done
1023  * Errors         : -1 - Init failed
1024  * Update History :
1025  *     YY/MM/DD  uid  Description
1026 -*/
1027 
1028 static int SK_lance_init(struct device *dev, unsigned short mode)
     /* [previous][next][first][last][top][bottom][index][help] */
1029 {
1030     int i;
1031     struct priv *p = (struct priv *) dev->priv; 
1032     struct tmd  *tmdp;
1033     struct rmd  *rmdp;
1034 
1035     PRINTK(("## %s: At beginning of LANCE init. CSR0: %#06x\n", 
1036            SK_NAME, SK_read_reg(CSR0)));
1037 
1038     /* Reset LANCE */
1039     SK_reset_board();
1040 
1041     /* Initialize TMD's with start values */
1042     p->tmdnum = 0;                   /* First descriptor for transmitting */ 
1043     p->tmdlast = 0;                  /* First descriptor for reading stats */
1044 
1045     for (i = 0; i < TMDNUM; i++)     /* Init all TMD's */
1046     {
1047         tmdp = p->tmdhead + i; 
1048    
1049         tmdp->u.buffer = (unsigned long) p->tmdbufs[i]; /* assign buffer */
1050         
1051         /* Mark TMD as start and end of packet */
1052         tmdp->u.s.status = TX_STP | TX_ENP;
1053     }
1054 
1055 
1056     /* Initialize RMD's with start values */
1057 
1058     p->rmdnum = 0;                   /* First RMD which will be used */
1059  
1060     for (i = 0; i < RMDNUM; i++)     /* Init all RMD's */
1061     {
1062         rmdp = p->rmdhead + i;
1063 
1064         
1065         rmdp->u.buffer = (unsigned long) p->rmdbufs[i]; /* assign buffer */
1066         
1067         /* 
1068          * LANCE must be owner at beginning so that he can fill in 
1069          * receiving packets, set status and release RMD 
1070          */
1071 
1072         rmdp->u.s.status = RX_OWN;  
1073 
1074         rmdp->blen = -PKT_BUF_SZ;    /* Buffer Size in a two's comliment */
1075 
1076         rmdp->mlen = 0;              /* init message length */       
1077         
1078     }
1079 
1080     /* Fill LANCE Initialize Block */
1081 
1082     (p->ram)->ib.mode = mode;        /* Set operation mode */
1083 
1084     for (i = 0; i < ETH_ALEN; i++)   /* Set physical address */
1085     {
1086         (p->ram)->ib.paddr[i] = dev->dev_addr[i]; 
1087     }
1088 
1089     for (i = 0; i < 8; i++)          /* Set multicast, logical adress */
1090     {
1091         (p->ram)->ib.laddr[i] = 0;   /* We do not use logical addressing */
1092     } 
1093 
1094     /* Set ring descriptor pointers and set number of descriptors */
1095 
1096     (p->ram)->ib.rdrp = (int)  p->rmdhead | RMDNUMMASK;
1097     (p->ram)->ib.tdrp = (int)  p->tmdhead | TMDNUMMASK;
1098 
1099     /* Prepare LANCE Controll and Status Registers */
1100 
1101     cli();
1102 
1103     SK_write_reg(CSR3, CSR3_ACON);   /* Ale Control !!!THIS MUST BE SET!!!! */
1104  
1105     /* 
1106      * LANCE addresses the RAM from 0x0000 to 0x3fbf and has no access to
1107      * PC Memory locations.
1108      *
1109      * In structure SK_ram is defined that the first thing in ram
1110      * is the initalization block. So his address is for LANCE always
1111      * 0x0000
1112      *
1113      * CSR1 contains low order bits 15:0 of initialization block address
1114      * CSR2 is built of: 
1115      *    7:0  High order bits 23:16 of initialization block address
1116      *   15:8  reserved, must be 0
1117      */
1118     
1119     /* Set initialization block address (must be on word boundary) */
1120     SK_write_reg(CSR1, 0);          /* Set low order bits 15:0 */
1121     SK_write_reg(CSR2, 0);          /* Set high order bits 23:16 */ 
1122     
1123 
1124     PRINTK(("## %s: After setting CSR1-3. CSR0: %#06x\n", 
1125            SK_NAME, SK_read_reg(CSR0)));
1126 
1127     /* Initialize LANCE */
1128 
1129     /* 
1130      * INIT = Initialize, when set, cuases the LANCE to begin the
1131      * initialization procedure and access the Init Block.
1132      */
1133 
1134     SK_write_reg(CSR0, CSR0_INIT); 
1135 
1136     sti();
1137 
1138     /* Wait until LANCE finished initialization */
1139     
1140     SK_set_RAP(CSR0);              /* Register Address Pointer to CSR0 */
1141 
1142     for (i = 0; (i < 100) && !(SK_rread_reg() & CSR0_IDON); i++) 
1143         ; /* Wait until init done or go ahead if problems (i>=100) */
1144 
1145     if (i >= 100) /* Something is wrong ! */
1146     {
1147         printk("%s: can't init am7990, status: %04x "
1148                "init_block: %#08x\n", 
1149                 dev->name, (int) SK_read_reg(CSR0), 
1150                 (unsigned int) &(p->ram)->ib);
1151 
1152 #ifdef SK_DEBUG
1153         SK_print_pos(dev, "LANCE INIT failed");
1154         SK_print_dev(dev,"Device Structure:");
1155 #endif
1156 
1157         return -1;                 /* LANCE init failed */
1158     }
1159 
1160     PRINTK(("## %s: init done after %d ticks\n", SK_NAME, i));
1161 
1162     /* Clear Initialize done, enable Interrupts, start LANCE */
1163 
1164     SK_write_reg(CSR0, CSR0_IDON | CSR0_INEA | CSR0_STRT);
1165 
1166     PRINTK(("## %s: LANCE started. CSR0: %#06x\n", SK_NAME, 
1167             SK_read_reg(CSR0)));
1168 
1169     return 0;                      /* LANCE is up and running */
1170 
1171 } /* End of SK_lance_init() */
1172 
1173 
1174 
1175 /*-
1176  * Function       : SK_send_packet
1177  * Author         : Patrick J.D. Weichmann
1178  * Date Created   : 94/05/27
1179  *
1180  * Description    : Writes an socket buffer into a transmit descriptor
1181  *                  and starts transmission.
1182  *
1183  * Parameters     : I : struct sk_buff *skb - packet to transfer
1184  *                  I : struct device *dev  - SK_G16 device structure
1185  * Return Value   : 0 - OK
1186  *                  1 - Could not transmit (dev_queue_xmit will queue it)
1187  *                      and try to sent it later
1188  * Globals        : None
1189  * Side Effects   : None
1190  * Update History :
1191  *     YY/MM/DD  uid  Description
1192 -*/
1193 
1194 static int SK_send_packet(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1195 {
1196     struct priv *p = (struct priv *) dev->priv;
1197     struct tmd *tmdp;
1198 
1199     if (dev->tbusy)
1200     {
1201         /* if Transmitter more than 150ms busy -> time_out */
1202 
1203         int tickssofar = jiffies - dev->trans_start;
1204         if (tickssofar < 15)
1205         {
1206             return 1;                    /* We have to try transmit later */
1207         }
1208 
1209         printk("%s: xmitter timed out, try to restart!\n", dev->name);
1210 
1211         SK_lance_init(dev, MODE_NORMAL); /* Reinit LANCE */
1212 
1213         dev->tbusy = 0;                  /* Clear Transmitter flag */
1214 
1215         dev->trans_start = jiffies;      /* Mark Start of transmission */
1216 
1217     }
1218 
1219     /* 
1220      * If some upper Layer thinks we missed a transmit done interrupt
1221      * we are passed NULL.
1222      * (dev_queue_xmit net/inet/dev.c 
1223      */
1224 
1225     if (skb == NULL)
1226     {
1227         /* 
1228          * Dequeue packets from transmit queue and send them.
1229          */
1230         dev_tint(dev); 
1231                     
1232         return 0;
1233     }
1234     
1235     PRINTK2(("## %s: SK_send_packet() called, CSR0 %#04x.\n", 
1236             SK_NAME, SK_read_reg(CSR0)));
1237 
1238 
1239     /* 
1240      * Block a timer-based transmit from overlapping. 
1241      * This means check if we are already in. 
1242      */
1243 
1244     if (set_bit(0, (void *) &dev->tbusy) != 0) /* dev->tbusy already set ? */ 
1245     {
1246         printk("%s: Transmitter access conflict.\n", dev->name);
1247     }
1248     else
1249     {
1250         /* Evaluate Packet length */
1251         short len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; 
1252        
1253         tmdp = p->tmdhead + p->tmdnum; /* Which descriptor for transmitting */
1254 
1255         /* Fill in Transmit Message Descriptor */
1256 
1257         /* Copy data into dual ported ram */
1258 
1259         memcpy((char *) (tmdp->u.buffer & 0x00ffffff), (char *)skb->data,
1260                skb->len);
1261 
1262         tmdp->blen = -len;            /* set length to transmit */
1263 
1264         /* 
1265          * Packet start and end is always set because we use the maximum
1266          * packet length as buffer length.
1267          * Relinquish ownership to LANCE
1268          */
1269 
1270         tmdp->u.s.status = TX_OWN | TX_STP | TX_ENP;
1271         
1272         /* Start Demand Transmission */
1273         SK_write_reg(CSR0, CSR0_TDMD | CSR0_INEA);
1274 
1275         dev->trans_start = jiffies;   /* Mark start of transmission */
1276 
1277         /* Set pointer to next transmit buffer */
1278         p->tmdnum++; 
1279         p->tmdnum &= TMDNUM-1; 
1280 
1281         /* Do we own the next transmit buffer ? */
1282         if (! ((p->tmdhead + p->tmdnum)->u.s.status & TX_OWN) )
1283         {
1284            /* 
1285             * We own next buffer and are ready to transmit, so
1286             * clear busy flag
1287             */
1288            dev->tbusy = 0;
1289         }
1290     }
1291     dev_kfree_skb(skb, FREE_WRITE);
1292     return 0;  
1293 } /* End of SK_send_packet */
1294 
1295 
1296 /*-
1297  * Function       : SK_interrupt
1298  * Author         : Patrick J.D. Weichmann
1299  * Date Created   : 94/05/27
1300  *
1301  * Description    : SK_G16 interrupt handler which checks for LANCE
1302  *                  Errors, handles transmit and receive interrupts
1303  *
1304  * Parameters     : I : int reg_ptr -
1305  * Return Value   : None
1306  * Errors         : None
1307  * Globals        : None
1308  * Side Effects   : None
1309  * Update History :
1310  *     YY/MM/DD  uid  Description
1311 -*/
1312 
1313 static void SK_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
1314 {
1315     int irq = - (((struct pt_regs *)reg_ptr)->orig_eax+2);
1316     int csr0;
1317     struct device *dev = (struct device *) irq2dev_map[irq];
1318     struct priv *p = (struct priv *) dev->priv;
1319 
1320 
1321     PRINTK2(("## %s: SK_interrupt(). status: %#06x\n", 
1322             SK_NAME, SK_read_reg(CSR0)));
1323 
1324     if (dev == NULL)
1325     {
1326         printk("SK_interrupt(): IRQ %d for unknown device.\n", irq);
1327     }
1328     
1329 
1330     if (dev->interrupt)
1331     {
1332         printk("%s: Re-entering the interrupt handler.\n", dev->name);
1333     }
1334 
1335     csr0 = SK_read_reg(CSR0);      /* store register for checking */
1336 
1337     dev->interrupt = 1;            /* We are handling an interrupt */
1338 
1339     /* 
1340      * Acknowledge all of the current interrupt sources, disable      
1341      * Interrupts (INEA = 0) 
1342      */
1343 
1344     SK_write_reg(CSR0, csr0 & CSR0_CLRALL); 
1345 
1346     if (csr0 & CSR0_ERR) /* LANCE Error */
1347     {
1348         printk("%s: error: %04x\n", dev->name, csr0);
1349       
1350         if (csr0 & CSR0_MISS)      /* No place to store packet ? */
1351         { 
1352             p->stats.rx_dropped++;
1353         }
1354     }
1355 
1356     if (csr0 & CSR0_RINT)          /* Receive Interrupt (packet arrived) */ 
1357     {
1358         SK_rxintr(dev); 
1359     }
1360 
1361     if (csr0 & CSR0_TINT)          /* Transmit interrupt (packet sent) */
1362     {
1363         SK_txintr(dev);
1364     }
1365 
1366     SK_write_reg(CSR0, CSR0_INEA); /* Enable Interrupts */
1367 
1368     dev->interrupt = 0;            /* We are out */
1369 } /* End of SK_interrupt() */ 
1370 
1371 
1372 /*-
1373  * Function       : SK_txintr
1374  * Author         : Patrick J.D. Weichmann
1375  * Date Created   : 94/05/27
1376  *
1377  * Description    : After sending a packet we check status, update
1378  *                  statistics and relinquish ownership of transmit 
1379  *                  descriptor ring.
1380  *
1381  * Parameters     : I : struct device *dev - SK_G16 device structure
1382  * Return Value   : None
1383  * Errors         : None
1384  * Globals        : None
1385  * Update History :
1386  *     YY/MM/DD  uid  Description
1387 -*/
1388 
1389 static void SK_txintr(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1390 {
1391     int tmdstat;
1392     struct tmd *tmdp;
1393     struct priv *p = (struct priv *) dev->priv;
1394 
1395 
1396     PRINTK2(("## %s: SK_txintr() status: %#06x\n", 
1397             SK_NAME, SK_read_reg(CSR0)));
1398 
1399     tmdp = p->tmdhead + p->tmdlast;     /* Which buffer we sent at last ? */
1400 
1401     /* Set next buffer */
1402     p->tmdlast++;
1403     p->tmdlast &= TMDNUM-1;
1404 
1405     tmdstat = tmdp->u.s.status & 0xff00; /* filter out status bits 15:08 */
1406 
1407     /* 
1408      * We check status of transmitted packet.
1409      * see LANCE data-sheet for error explanation
1410      */
1411     if (tmdstat & TX_ERR) /* Error occured */
1412     {
1413         printk("%s: TX error: %04x %04x\n", dev->name, (int) tmdstat,
1414                 (int) tmdp->status2);
1415 
1416         if (tmdp->status2 & TX_TDR)    /* TDR problems? */
1417         {
1418             printk("%s: tdr-problems \n", dev->name);
1419         }
1420 
1421         if (tmdp->status2 & TX_RTRY)   /* Failed in 16 attempts to transmit ? */
1422             p->stats.tx_aborted_errors++;   
1423         if (tmdp->status2 & TX_LCOL)   /* Late collision ? */
1424             p->stats.tx_window_errors++; 
1425         if (tmdp->status2 & TX_LCAR)   /* Loss of Carrier ? */  
1426             p->stats.tx_carrier_errors++;
1427         if (tmdp->status2 & TX_UFLO)   /* Underflow error ? */
1428         {
1429             p->stats.tx_fifo_errors++;
1430 
1431             /* 
1432              * If UFLO error occurs it will turn tranmitter of.
1433              * So we must reinit LANCE
1434              */
1435 
1436             SK_lance_init(dev, MODE_NORMAL);
1437         }
1438         
1439         p->stats.tx_errors++;
1440 
1441         tmdp->status2 = 0;             /* Clear error flags */
1442     }
1443     else if (tmdstat & TX_MORE)        /* Collisions occured ? */
1444     {
1445         /* 
1446          * Here I have a problem.
1447          * I only know that there must be one or up to 15 collisions.
1448          * Thats why TX_MORE is set, because after 16 attempts TX_RTRY
1449          * will be set which means couldn't send packet aborted transfer.
1450          *
1451          * First I did not have this in but then I thought at minimum
1452          * we see that something was not ok.
1453          * If anyone knows something better than this to handle this
1454          * please report it. (see Email addresses in the README file)
1455          */ 
1456 
1457         p->stats.collisions++; 
1458     }
1459     else   /* Packet sent without any problems */
1460     {
1461         p->stats.tx_packets++; 
1462     }
1463 
1464     /* 
1465      * We mark transmitter not busy anymore, because now we have a free
1466      * transmit descriptor which can be filled by SK_send_packet and
1467      * afterwards sent by the LANCE
1468      */
1469 
1470     dev->tbusy = 0; 
1471 
1472     /* 
1473      * mark_bh(NET_BH);
1474      * This will cause net_bh() to run after this interrupt handler.
1475      *
1476      * The function which do handle slow IRQ parts is do_bottom_half()
1477      * which runs at normal kernel priority, that means all interrupt are
1478      * enabled. (see kernel/irq.c)
1479      *  
1480      * net_bh does something like this:
1481      *  - check if already in net_bh
1482      *  - try to transmit something from the send queue
1483      *  - if something is in the receive queue send it up to higher 
1484      *    levels if it is a known protocol
1485      *  - try to transmit something from the send queue
1486      */
1487 
1488     mark_bh(NET_BH); 
1489 
1490 } /* End of SK_txintr() */
1491 
1492 
1493 /*-
1494  * Function       : SK_rxintr
1495  * Author         : Patrick J.D. Weichmann
1496  * Date Created   : 94/05/27
1497  *
1498  * Description    : Buffer sent, check for errors, relinquish ownership
1499  *                  of the receive message descriptor. 
1500  *
1501  * Parameters     : I : SK_G16 device structure
1502  * Return Value   : None
1503  * Globals        : None
1504  * Update History :
1505  *     YY/MM/DD  uid  Description
1506 -*/
1507 
1508 static void SK_rxintr(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1509 {
1510 
1511     struct rmd *rmdp;
1512     int rmdstat;
1513     struct priv *p = (struct priv *) dev->priv;
1514 
1515     PRINTK2(("## %s: SK_rxintr(). CSR0: %#06x\n", 
1516             SK_NAME, SK_read_reg(CSR0)));
1517 
1518     rmdp = p->rmdhead + p->rmdnum;
1519 
1520     /* As long as we own the next entry, check status and send
1521      * it up to higher layer 
1522      */
1523 
1524     while (!( (rmdstat = rmdp->u.s.status) & RX_OWN))
1525     {
1526         /* 
1527          * Start and end of packet must be set, because we use 
1528          * the ethernet maximum packet length (1518) as buffer size.
1529          * 
1530          * Because our buffers are at maximum OFLO and BUFF errors are
1531          * not to be concerned (see Data sheet)
1532          */
1533 
1534         if (rmdstat & (RX_STP | RX_ENP) != (RX_STP | RX_ENP))
1535         {
1536             /* Start of a frame > 1518 Bytes ? */
1537 
1538             if (rmdstat & RX_STP) 
1539             {
1540                 p->stats.rx_errors++;        /* bad packet received */
1541                 p->stats.rx_length_errors++; /* packet to long */
1542 
1543                 printk("%s: packet too long\n", dev->name);
1544             }
1545             
1546             /* 
1547              * All other packets will be ignored until a new frame with
1548              * start (RX_STP) set follows.
1549              * 
1550              * What we do is just give descriptor free for new incoming
1551              * packets. 
1552              */
1553 
1554             rmdp->u.s.status = RX_OWN;      /* Relinquish ownership to LANCE */ 
1555 
1556         }
1557         else if (rmdstat & RX_ERR)          /* Receive Error ? */
1558         {
1559             printk("%s: RX error: %04x\n", dev->name, (int) rmdstat);
1560             
1561             p->stats.rx_errors++;
1562 
1563             if (rmdstat & RX_FRAM) p->stats.rx_frame_errors++;
1564             if (rmdstat & RX_CRC)  p->stats.rx_crc_errors++;
1565 
1566             rmdp->u.s.status = RX_OWN;      /* Relinquish ownership to LANCE */
1567 
1568         }
1569         else /* We have a packet which can be queued for the upper layers */
1570         {
1571 
1572             int len = (rmdp->mlen & 0x0fff);  /* extract message length from receive buffer */
1573             struct sk_buff *skb;
1574 
1575             skb = alloc_skb(len, GFP_ATOMIC); /* allocate socket buffer */ 
1576 
1577             if (skb == NULL)                /* Could not get mem ? */
1578             {
1579     
1580                 /* 
1581                  * Couldn't allocate sk_buffer so we give descriptor back
1582                  * to Lance, update statistics and go ahead.
1583                  */
1584 
1585                 rmdp->u.s.status = RX_OWN;  /* Reliquish ownershipt to LANCE */
1586                 printk("%s: Couldn't allocate sk_buff, deferring packet.\n",
1587                        dev->name);
1588                 p->stats.rx_dropped++;
1589 
1590                 break;                      /* Jump out */
1591             }
1592             
1593             /* Prepare sk_buff to queue for upper layers */
1594 
1595             skb->len = len;
1596             skb->dev = dev;
1597             
1598             /* 
1599              * Copy data out of our receive descriptor into sk_buff.
1600              *
1601              * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and 
1602              * ignore status fields) 
1603              */
1604 
1605             memcpy(skb->data, (unsigned char *) (rmdp->u.buffer & 0x00ffffff),
1606                    len);
1607 
1608 
1609             /* 
1610              * Notify the upper protocol layers that there is another packet
1611              * to handle
1612              *
1613              * netif_rx() always succeeds. see /net/inet/dev.c for more.
1614              */
1615 
1616             netif_rx(skb);                 /* queue packet and mark it for processing */
1617            
1618             /* 
1619              * Packet is queued and marked for processing so we
1620              * free our descriptor and update statistics 
1621              */
1622 
1623             rmdp->u.s.status = RX_OWN;
1624             p->stats.rx_packets++;
1625 
1626 
1627             p->rmdnum++;
1628             p->rmdnum %= RMDNUM;
1629 
1630             rmdp = p->rmdhead + p->rmdnum;
1631         }
1632     }
1633 } /* End of SK_rxintr() */
1634 
1635 
1636 /*-
1637  * Function       : SK_close
1638  * Author         : Patrick J.D. Weichmann
1639  * Date Created   : 94/05/26
1640  *
1641  * Description    : close gets called from dev_close() and should
1642  *                  deinstall the card (free_irq, mem etc).
1643  *
1644  * Parameters     : I : struct device *dev - our device structure
1645  * Return Value   : 0 - closed device driver
1646  * Errors         : None
1647  * Globals        : None
1648  * Update History :
1649  *     YY/MM/DD  uid  Description
1650 -*/
1651 
1652 /* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig
1653  * down' the system stops. So I don't shut set card to init state.
1654  */
1655 
1656 static int SK_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1657 {
1658 
1659     PRINTK(("## %s: SK_close(). CSR0: %#06x\n", 
1660            SK_NAME, SK_read_reg(CSR0)));
1661 
1662     dev->tbusy = 1;                /* Transmitter busy */
1663     dev->start = 0;                /* Card down */
1664 
1665     printk("%s: Shuting %s down CSR0 %#06x\n", dev->name, SK_NAME, 
1666            (int) SK_read_reg(CSR0));
1667 
1668     SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */
1669 
1670     free_irq(dev->irq);            /* Free IRQ */
1671     irq2dev_map[dev->irq] = 0;     /* Mark IRQ as unused */
1672 
1673     return 0; /* always succed */
1674     
1675 } /* End of SK_close() */
1676 
1677 
1678 /*-
1679  * Function       : SK_get_stats
1680  * Author         : Patrick J.D. Weichmann
1681  * Date Created   : 94/05/26
1682  *
1683  * Description    : Return current status structure to upper layers.
1684  *                  It is called by sprintf_stats (dev.c).
1685  *
1686  * Parameters     : I : struct device *dev   - our device structure
1687  * Return Value   : struct enet_statistics * - our current statistics
1688  * Errors         : None
1689  * Side Effects   : None
1690  * Update History :
1691  *     YY/MM/DD  uid  Description
1692 -*/
1693 
1694 static struct enet_statistics *SK_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1695 {
1696 
1697     struct priv *p = (struct priv *) dev->priv;
1698 
1699     PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n", 
1700            SK_NAME, SK_read_reg(CSR0)));
1701 
1702     return &p->stats;             /* Return Device status */
1703 
1704 } /* End of SK_get_stats() */
1705 
1706 #ifdef HAVE_MULTICAST
1707 
1708 /*-
1709  * Function       : set_multicast_list
1710  * Author         : Patrick J.D. Weichmann
1711  * Date Created   : 94/05/26
1712  *
1713  * Description    : This function gets called when a programm performs
1714  *                  a SIOCSIFFLAGS call. Ifconfig does this if you call
1715  *                  'ifconfig [-]allmultie' which enables or disables the
1716  *                  Promiscous mode.
1717  *                  Promiscous mode is when the Network card accepts all
1718  *                  packets, not only the packets which match our MAC 
1719  *                  Address. It is useful for writing a network monitor,
1720  *                  but it is also a security problem. You have to remeber
1721  *                  that all information on the net is not encrypted.
1722  *
1723  * Parameters     : I : struct device *dev - SK_G16 device Structure
1724  *                  I : int num_addrs      - explanation further down
1725  *                  I : void *addrs        - 
1726  * Return Value   : None
1727  * Errors         : None
1728  * Globals        : None
1729  * Update History :
1730  *     YY/MM/DD  uid  Description
1731 -*/
1732 
1733 
1734 /* Set or clear the multicast filter for SK_G16.
1735  *
1736  * num_addrs == -1      Promiscous mode, receive all packets
1737  * num_addrs == 0       Normal mode, clear multicast list
1738  * num_addrs > 0        Multicast mode, receive normal and MC packets
1739  */
1740 
1741 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
1742 {
1743 
1744     if (num_addrs == -1)
1745     {
1746         /* Reinitialize LANCE with MODE_PROM set */
1747         SK_lance_init(dev, MODE_PROM);
1748     }
1749     else if (num_addrs == 0)
1750     {
1751         /* Reinitialize LANCE without MODE_PROM */
1752         SK_lance_init(dev, MODE_NORMAL);
1753     }
1754     else
1755     {
1756         /* Multicast with logical address filter on */
1757         
1758         /* Not implemented yet. */
1759     }
1760 } /* End of set_multicast_list() */
1761 
1762 #endif     
1763 
1764 
1765 
1766 /*-
1767  * Function       : SK_rom_addr
1768  * Author         : Patrick J.D. Weichmann
1769  * Date Created   : 94/06/01
1770  *
1771  * Description    : Try to find a Boot_ROM at all possible locations
1772  *
1773  * Parameters     : None
1774  * Return Value   : Address where Boot_ROM is
1775  * Errors         : 0 - Did not find Boot_ROM
1776  * Globals        : None
1777  * Update History :
1778  *     YY/MM/DD  uid  Description
1779 -*/
1780 
1781 unsigned int SK_rom_addr(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1782 {
1783     int i,j;
1784     int rom_found = 0;
1785     unsigned int rom_location[] = SK_BOOT_ROM_LOCATIONS;
1786     unsigned char rom_id[] = SK_BOOT_ROM_ID;
1787     unsigned char *test_byte;
1788 
1789     /* Autodetect Boot_ROM */
1790     PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME));
1791 
1792     for (i = 0; (rom_location[i] != 0) && (rom_found == 0); i++)
1793     {
1794         
1795         PRINTK(("##   Trying ROM location %#08x", rom_location[i]));
1796         
1797         rom_found = 1; 
1798         for (j = 0; j < 6; j++)
1799         {
1800             test_byte = (unsigned char *) (rom_location[i]+j);
1801             PRINTK((" %02x ", *test_byte));
1802 
1803             if(!(*test_byte == rom_id[j]))
1804             {
1805                 rom_found = 0;
1806             } 
1807         }
1808         PRINTK(("\n"));
1809     }
1810 
1811     if (rom_found == 1)
1812     {
1813         PRINTK(("## %s: Boot_ROM found at %#08x\n", 
1814                SK_NAME, rom_location[(i-1)]));
1815 
1816         return (rom_location[--i]);
1817     }
1818     else
1819     {
1820         PRINTK(("%s: No Boot_ROM found\n", SK_NAME));
1821         return 0;
1822     }
1823 } /* End of SK_rom_addr() */
1824 
1825 
1826 
1827 /* LANCE access functions 
1828  *
1829  * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set !
1830  */
1831 
1832 
1833 /*-
1834  * Function       : SK_reset_board
1835  *
1836  * Author         : Patrick J.D. Weichmann
1837  *
1838  * Date Created   : 94/05/25
1839  *
1840  * Description    : This function resets SK_G16 and all components, but
1841  *                  POS registers are not changed
1842  *
1843  * Parameters     : None
1844  * Return Value   : None
1845  * Errors         : None
1846  * Globals        : SK_RAM *board - SK_RAM structure pointer
1847  *
1848  * Update History :
1849  *     YY/MM/DD  uid  Description
1850 -*/
1851 
1852 void SK_reset_board(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1853 {
1854     int i;
1855 
1856     SK_PORT = 0x00;           /* Reset aktiv */
1857     for (i = 0; i < 10 ; i++) /* Delay min 5ms */
1858         ;
1859     SK_PORT = SK_RESET;       /* Set back to normal operation */
1860 
1861 } /* End of SK_reset_board() */
1862 
1863 
1864 /*-
1865  * Function       : SK_set_RAP
1866  * Author         : Patrick J.D. Weichmann
1867  * Date Created   : 94/05/25
1868  *
1869  * Description    : Set LANCE Register Address Port to register
1870  *                  for later data trasfer.
1871  *
1872  * Parameters     : I : reg_number - which CSR to read/write from/to
1873  * Return Value   : None
1874  * Errors         : None
1875  * Globals        : SK_RAM *board - SK_RAM structure pointer
1876  * Update History :
1877  *     YY/MM/DD  uid  Description
1878 -*/
1879 
1880 void SK_set_RAP(int reg_number)
     /* [previous][next][first][last][top][bottom][index][help] */
1881 {
1882     SK_IOREG = reg_number;
1883     SK_PORT  = SK_RESET | SK_RAP | SK_WREG;
1884     SK_IOCOM = SK_DOIO;
1885 
1886     while (SK_PORT & SK_IORUN) 
1887         ;
1888 } /* End of SK_set_RAP() */
1889 
1890 
1891 /*-
1892  * Function       : SK_read_reg
1893  * Author         : Patrick J.D. Weichmann
1894  * Date Created   : 94/05/25
1895  *
1896  * Description    : Set RAP and read data from a LANCE CSR register
1897  *
1898  * Parameters     : I : reg_number - which CSR to read from
1899  * Return Value   : Register contents
1900  * Errors         : None
1901  * Globals        : SK_RAM *board - SK_RAM structure pointer
1902  * Update History :
1903  *     YY/MM/DD  uid  Description
1904 -*/
1905 
1906 int SK_read_reg(int reg_number)
     /* [previous][next][first][last][top][bottom][index][help] */
1907 {
1908     SK_set_RAP(reg_number);
1909 
1910     SK_PORT  = SK_RESET | SK_RDATA | SK_RREG;
1911     SK_IOCOM = SK_DOIO;
1912 
1913     while (SK_PORT & SK_IORUN)
1914         ;
1915     return (SK_IOREG);
1916 
1917 } /* End of SK_read_reg() */
1918 
1919 
1920 /*-
1921  * Function       : SK_rread_reg
1922  * Author         : Patrick J.D. Weichmann
1923  * Date Created   : 94/05/28
1924  *
1925  * Description    : Read data from preseted register.
1926  *                  This function requires that you know which
1927  *                  Register is actually set. Be aware that CSR1-3
1928  *                  can only be accessed when in CSR0 STOP is set.
1929  *
1930  * Return Value   : Register contents
1931  * Errors         : None
1932  * Globals        : SK_RAM *board - SK_RAM structure pointer
1933  * Update History :
1934  *     YY/MM/DD  uid  Description
1935 -*/
1936 
1937 int SK_rread_reg(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1938 {
1939     SK_PORT  = SK_RESET | SK_RDATA | SK_RREG;
1940 
1941     SK_IOCOM = SK_DOIO;
1942 
1943     while (SK_PORT & SK_IORUN)
1944         ;
1945     return (SK_IOREG);
1946 
1947 } /* End of SK_rread_reg() */
1948 
1949 
1950 /*-
1951  * Function       : SK_write_reg
1952  * Author         : Patrick J.D. Weichmann
1953  * Date Created   : 94/05/25
1954  *
1955  * Description    : This function sets the RAP then fills in the
1956  *                  LANCE I/O Reg and starts Transfer to LANCE.
1957  *                  It waits until transfer has ended which is max. 7 ms
1958  *                  and then it returns.
1959  *
1960  * Parameters     : I : reg_number - which CSR to write to
1961  *                  I : value      - what value to fill into register 
1962  * Return Value   : None
1963  * Errors         : None
1964  * Globals        : SK_RAM *board - SK_RAM structure pointer
1965  * Update History :
1966  *     YY/MM/DD  uid  Description
1967 -*/
1968 
1969 void SK_write_reg(int reg_number, int value)
     /* [previous][next][first][last][top][bottom][index][help] */
1970 {
1971     SK_set_RAP(reg_number);
1972 
1973     SK_IOREG = value;
1974     SK_PORT  = SK_RESET | SK_RDATA | SK_WREG;
1975     SK_IOCOM = SK_DOIO;
1976 
1977     while (SK_PORT & SK_IORUN)
1978         ;
1979 } /* End of SK_write_reg */
1980 
1981 
1982 
1983 /* 
1984  * Debugging functions
1985  * -------------------
1986  */
1987 
1988 /*-
1989  * Function       : SK_print_pos
1990  * Author         : Patrick J.D. Weichmann
1991  * Date Created   : 94/05/25
1992  *
1993  * Description    : This function prints out the 4 POS (Programmable
1994  *                  Option Select) Registers. Used mainly to debug operation.
1995  *
1996  * Parameters     : I : struct device *dev - SK_G16 device structure
1997  *                  I : char * - Text which will be printed as title
1998  * Return Value   : None
1999  * Errors         : None
2000  * Update History :
2001  *     YY/MM/DD  uid  Description
2002 -*/
2003 
2004 void SK_print_pos(struct device *dev, char *text)
     /* [previous][next][first][last][top][bottom][index][help] */
2005 {
2006     int ioaddr = dev->base_addr;
2007 
2008     unsigned char pos0 = inb(SK_POS0),
2009                   pos1 = inb(SK_POS1),
2010                   pos2 = inb(SK_POS2),
2011                   pos3 = inb(SK_POS3),
2012                   pos4 = inb(SK_POS4);
2013 
2014 
2015     printk("## %s: %s.\n"
2016            "##   pos0=%#4x pos1=%#4x pos2=%#04x pos3=%#08x pos4=%#04x\n",
2017            SK_NAME, text, pos0, pos1, pos2, (pos3<<14), pos4);
2018 
2019 } /* End of SK_print_pos() */
2020 
2021 
2022 
2023 /*-
2024  * Function       : SK_print_dev
2025  * Author         : Patrick J.D. Weichmann
2026  * Date Created   : 94/05/25
2027  *
2028  * Description    : This function simply prints out the important fields
2029  *                  of the device structure.
2030  *
2031  * Parameters     : I : struct device *dev  - SK_G16 device structure
2032  *                  I : char *text - Title for printing
2033  * Return Value   : None
2034  * Errors         : None
2035  * Update History :
2036  *     YY/MM/DD  uid  Description
2037 -*/
2038 
2039 void SK_print_dev(struct device *dev, char *text)
     /* [previous][next][first][last][top][bottom][index][help] */
2040 {
2041     if (dev == NULL)
2042     {
2043         printk("## %s: Device Structure. %s\n", SK_NAME, text);
2044         printk("## DEVICE == NULL\n");
2045     }
2046     else
2047     {
2048         printk("## %s: Device Structure. %s\n", SK_NAME, text);
2049         printk("## Device Name: %s Base Address: %#06x IRQ: %d\n", 
2050                dev->name, dev->base_addr, dev->irq);
2051                
2052         printk("##   FLAGS: start: %d tbusy: %d int: %d\n", 
2053                dev->start, dev->tbusy, dev->interrupt);
2054 
2055         printk("## next device: %#08x init function: %#08x\n", 
2056               (int) dev->next, (int) dev->init);
2057     }
2058 
2059 } /* End of SK_print_dev() */
2060 
2061 
2062 
2063 /*-
2064  * Function       : SK_print_ram
2065  * Author         : Patrick J.D. Weichmann
2066  * Date Created   : 94/06/02
2067  *
2068  * Description    : This function is used to check how are things set up
2069  *                  in the 16KB RAM. Also the pointers to the receive and 
2070  *                  transmit descriptor rings and rx und tx buffers locations.
2071  *                  It contains a minor bug in printing, but has no effect to the values
2072  *                  only newlines are not correct.
2073  *
2074  * Parameters     : I : struct device *dev - SK_G16 device structure
2075  * Return Value   : None
2076  * Errors         : None
2077  * Globals        : None
2078  * Update History :
2079  *     YY/MM/DD  uid  Description
2080 -*/
2081 
2082 void SK_print_ram(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
2083 {
2084 
2085     int i;    
2086     struct priv *p = (struct priv *) dev->priv;
2087 
2088     printk("## %s: RAM Details.\n"
2089            "##   RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n",
2090            SK_NAME, 
2091            (unsigned int) p->ram,
2092            (unsigned int) p->tmdhead, 
2093            (unsigned int) p->rmdhead, 
2094            (unsigned int) &(p->ram)->ib);
2095            
2096     printk("##   ");
2097 
2098     for(i = 0; i < TMDNUM; i++)
2099     {
2100            if (!(i % 3)) /* Every third line do a newline */
2101            {
2102                printk("\n##   ");
2103            }
2104         printk("tmdbufs%d: %#08x ", (i+1), (int) p->tmdbufs[i]);
2105     }
2106     printk("##   ");
2107 
2108     for(i = 0; i < RMDNUM; i++)
2109     {
2110          if (!(i % 3)) /* Every third line do a newline */
2111            {
2112                printk("\n##   ");
2113            }
2114         printk("rmdbufs%d: %#08x ", (i+1), (int) p->rmdbufs[i]);
2115     } 
2116     printk("\n");
2117 
2118 } /* End of SK_print_ram() */
2119 

/* [previous][next][first][last][top][bottom][index][help] */