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

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