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