linux-bk/drivers/net/cs89x0.c
<<
>>
Prefs
   1/* cs89x0.c: A Crystal Semiconductor (Now Cirrus Logic) CS89[02]0
   2 *  driver for linux.
   3 */
   4
   5/*
   6        Written 1996 by Russell Nelson, with reference to skeleton.c
   7        written 1993-1994 by Donald Becker.
   8
   9        This software may be used and distributed according to the terms
  10        of the GNU General Public License, incorporated herein by reference.
  11
  12        The author may be reached at nelson@crynwr.com, Crynwr
  13        Software, 521 Pleasant Valley Rd., Potsdam, NY 13676
  14
  15  Changelog:
  16
  17  Mike Cruse        : mcruse@cti-ltd.com
  18                    : Changes for Linux 2.0 compatibility. 
  19                    : Added dev_id parameter in net_interrupt(),
  20                    : request_irq() and free_irq(). Just NULL for now.
  21
  22  Mike Cruse        : Added MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT macros
  23                    : in net_open() and net_close() so kerneld would know
  24                    : that the module is in use and wouldn't eject the 
  25                    : driver prematurely.
  26
  27  Mike Cruse        : Rewrote init_module() and cleanup_module using 8390.c
  28                    : as an example. Disabled autoprobing in init_module(),
  29                    : not a good thing to do to other devices while Linux
  30                    : is running from all accounts.
  31
  32  Russ Nelson       : Jul 13 1998.  Added RxOnly DMA support.
  33
  34  Melody Lee        : Aug 10 1999.  Changes for Linux 2.2.5 compatibility. 
  35                    : email: ethernet@crystal.cirrus.com
  36
  37  Alan Cox          : Removed 1.2 support, added 2.1 extra counters.
  38
  39  Andrew Morton     : andrewm@uow.edu.au
  40                    : Kernel 2.3.48
  41                    : Handle kmalloc() failures
  42                    : Other resource allocation fixes
  43                    : Add SMP locks
  44                    : Integrate Russ Nelson's ALLOW_DMA functionality back in.
  45                    : If ALLOW_DMA is true, make DMA runtime selectable
  46                    : Folded in changes from Cirrus (Melody Lee
  47                    : <klee@crystal.cirrus.com>)
  48                    : Don't call netif_wake_queue() in net_send_packet()
  49                    : Fixed an out-of-mem bug in dma_rx()
  50                    : Updated Documentation/cs89x0.txt
  51
  52  Andrew Morton     : andrewm@uow.edu.au / Kernel 2.3.99-pre1
  53                    : Use skb_reserve to longword align IP header (two places)
  54                    : Remove a delay loop from dma_rx()
  55                    : Replace '100' with HZ
  56                    : Clean up a couple of skb API abuses
  57                    : Added 'cs89x0_dma=N' kernel boot option
  58                    : Correctly initialise lp->lock in non-module compile
  59
  60  Andrew Morton     : andrewm@uow.edu.au / Kernel 2.3.99-pre4-1
  61                    : MOD_INC/DEC race fix (see
  62                    : http://www.uwsg.indiana.edu/hypermail/linux/kernel/0003.3/1532.html)
  63
  64  Andrew Morton     : andrewm@uow.edu.au / Kernel 2.4.0-test7-pre2
  65                    : Enhanced EEPROM support to cover more devices,
  66                    :   abstracted IRQ mapping to support CONFIG_ARCH_CLPS7500 arch
  67                    :   (Jason Gunthorpe <jgg@ualberta.ca>)
  68
  69  Andrew Morton     : Kernel 2.4.0-test11-pre4
  70                    : Use dev->name in request_*() (Andrey Panin)
  71                    : Fix an error-path memleak in init_module()
  72                    : Preserve return value from request_irq()
  73                    : Fix type of `media' module parm (Keith Owens)
  74                    : Use SET_MODULE_OWNER()
  75                    : Tidied up strange request_irq() abuse in net_open().
  76
  77  Andrew Morton     : Kernel 2.4.3-pre1
  78                    : Request correct number of pages for DMA (Hugh Dickens)
  79                    : Select PP_ChipID _after_ unregister_netdev in cleanup_module()
  80                    :  because unregister_netdev() calls get_stats.
  81                    : Make `version[]' __initdata
  82                    : Uninlined the read/write reg/word functions.
  83
  84  Oskar Schirmer    : oskar@scara.com
  85                    : HiCO.SH4 (superh) support added (irq#1, cs89x0_media=)
  86
  87*/
  88
  89/* Always include 'config.h' first in case the user wants to turn on
  90   or override something. */
  91#include <linux/config.h>
  92#include <linux/module.h>
  93
  94/*
  95 * Set this to zero to disable DMA code
  96 *
  97 * Note that even if DMA is turned off we still support the 'dma' and  'use_dma'
  98 * module options so we don't break any startup scripts.
  99 */
 100#define ALLOW_DMA       1
 101
 102/*
 103 * Set this to zero to remove all the debug statements via
 104 * dead code elimination
 105 */
 106#define DEBUGGING       1
 107
 108/*
 109  Sources:
 110
 111        Crynwr packet driver epktisa.
 112
 113        Crystal Semiconductor data sheets.
 114
 115*/
 116
 117#include <linux/errno.h>
 118#include <linux/netdevice.h>
 119#include <linux/etherdevice.h>
 120#include <linux/kernel.h>
 121#include <linux/types.h>
 122#include <linux/fcntl.h>
 123#include <linux/interrupt.h>
 124#include <linux/ioport.h>
 125#include <linux/in.h>
 126#include <linux/skbuff.h>
 127#include <linux/slab.h>
 128#include <linux/spinlock.h>
 129#include <linux/string.h>
 130#include <linux/init.h>
 131
 132#include <asm/system.h>
 133#include <asm/bitops.h>
 134#include <asm/io.h>
 135#if ALLOW_DMA
 136#include <asm/dma.h>
 137#endif
 138
 139#include "cs89x0.h"
 140
 141static char version[] __initdata =
 142"cs89x0.c: v2.4.3-pre1 Russell Nelson <nelson@crynwr.com>, Andrew Morton <andrewm@uow.edu.au>\n";
 143
 144/* First, a few definitions that the brave might change.
 145   A zero-terminated list of I/O addresses to be probed. Some special flags..
 146      Addr & 1 = Read back the address port, look for signature and reset
 147                 the page window before probing 
 148      Addr & 3 = Reset the page window and probe 
 149   The CLPS eval board has the Cirrus chip at 0x80090300, in ARM IO space,
 150   but it is possible that a Cirrus board could be plugged into the ISA
 151   slots. */
 152/* The cs8900 has 4 IRQ pins, software selectable. cs8900_irq_map maps 
 153   them to system IRQ numbers. This mapping is card specific and is set to
 154   the configuration of the Cirrus Eval board for this chip. */
 155#ifdef CONFIG_ARCH_CLPS7500
 156static unsigned int netcard_portlist[] __initdata =
 157   { 0x80090303, 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
 158static unsigned int cs8900_irq_map[] = {12,0,0,0};
 159#elif defined(CONFIG_SH_HICOSH4)
 160static unsigned int netcard_portlist[] __initdata =
 161   { 0x0300, 0};
 162static unsigned int cs8900_irq_map[] = {1,0,0,0};
 163#else
 164static unsigned int netcard_portlist[] __initdata =
 165   { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
 166static unsigned int cs8900_irq_map[] = {10,11,12,5};
 167#endif
 168
 169#if DEBUGGING
 170static unsigned int net_debug = DEBUGGING;
 171#else
 172#define net_debug 0     /* gcc will remove all the debug code for us */
 173#endif
 174
 175/* The number of low I/O ports used by the ethercard. */
 176#define NETCARD_IO_EXTENT       16
 177
 178/* we allow the user to override various values normally set in the EEPROM */
 179#define FORCE_RJ45      0x0001    /* pick one of these three */
 180#define FORCE_AUI       0x0002
 181#define FORCE_BNC       0x0004
 182
 183#define FORCE_AUTO      0x0010    /* pick one of these three */
 184#define FORCE_HALF      0x0020
 185#define FORCE_FULL      0x0030
 186
 187/* Information that need to be kept for each board. */
 188struct net_local {
 189        struct net_device_stats stats;
 190        int chip_type;          /* one of: CS8900, CS8920, CS8920M */
 191        char chip_revision;     /* revision letter of the chip ('A'...) */
 192        int send_cmd;           /* the proper send command: TX_NOW, TX_AFTER_381, or TX_AFTER_ALL */
 193        int auto_neg_cnf;       /* auto-negotiation word from EEPROM */
 194        int adapter_cnf;        /* adapter configuration from EEPROM */
 195        int isa_config;         /* ISA configuration from EEPROM */
 196        int irq_map;            /* IRQ map from EEPROM */
 197        int rx_mode;            /* what mode are we in? 0, RX_MULTCAST_ACCEPT, or RX_ALL_ACCEPT */
 198        int curr_rx_cfg;        /* a copy of PP_RxCFG */
 199        int linectl;            /* either 0 or LOW_RX_SQUELCH, depending on configuration. */
 200        int send_underrun;      /* keep track of how many underruns in a row we get */
 201        int force;              /* force various values; see FORCE* above. */
 202        spinlock_t lock;
 203#if ALLOW_DMA
 204        int use_dma;            /* Flag: we're using dma */
 205        int dma;                /* DMA channel */
 206        int dmasize;            /* 16 or 64 */
 207        unsigned char *dma_buff;        /* points to the beginning of the buffer */
 208        unsigned char *end_dma_buff;    /* points to the end of the buffer */
 209        unsigned char *rx_dma_ptr;      /* points to the next packet  */
 210#endif
 211};
 212
 213/* Index to functions, as function prototypes. */
 214
 215extern int cs89x0_probe(struct net_device *dev);
 216
 217static int cs89x0_probe1(struct net_device *dev, int ioaddr);
 218static int net_open(struct net_device *dev);
 219static int net_send_packet(struct sk_buff *skb, struct net_device *dev);
 220static irqreturn_t net_interrupt(int irq, void *dev_id, struct pt_regs *regs);
 221static void set_multicast_list(struct net_device *dev);
 222static void net_timeout(struct net_device *dev);
 223static void net_rx(struct net_device *dev);
 224static int net_close(struct net_device *dev);
 225static struct net_device_stats *net_get_stats(struct net_device *dev);
 226static void reset_chip(struct net_device *dev);
 227static int get_eeprom_data(struct net_device *dev, int off, int len, int *buffer);
 228static int get_eeprom_cksum(int off, int len, int *buffer);
 229static int set_mac_address(struct net_device *dev, void *addr);
 230static void count_rx_errors(int status, struct net_local *lp);
 231#if ALLOW_DMA
 232static void get_dma_channel(struct net_device *dev);
 233static void release_dma_buff(struct net_local *lp);
 234#endif
 235
 236/* Example routines you must write ;->. */
 237#define tx_done(dev) 1
 238
 239/*
 240 * Permit 'cs89x0_dma=N' in the kernel boot environment
 241 */
 242#if !defined(MODULE) && (ALLOW_DMA != 0)
 243static int g_cs89x0_dma;
 244
 245static int __init dma_fn(char *str)
 246{
 247        g_cs89x0_dma = simple_strtol(str,NULL,0);
 248        return 1;
 249}
 250
 251__setup("cs89x0_dma=", dma_fn);
 252#endif  /* !defined(MODULE) && (ALLOW_DMA != 0) */
 253
 254#ifndef MODULE
 255static int g_cs89x0_media__force;
 256
 257static int __init media_fn(char *str)
 258{
 259        if (!strcmp(str, "rj45")) g_cs89x0_media__force = FORCE_RJ45;
 260        else if (!strcmp(str, "aui")) g_cs89x0_media__force = FORCE_AUI;
 261        else if (!strcmp(str, "bnc")) g_cs89x0_media__force = FORCE_BNC;
 262        return 1;
 263}
 264
 265__setup("cs89x0_media=", media_fn);
 266#endif
 267
 268
 269/* Check for a network adaptor of this type, and return '0' iff one exists.
 270   If dev->base_addr == 0, probe all likely locations.
 271   If dev->base_addr == 1, always return failure.
 272   If dev->base_addr == 2, allocate space for the device and return success
 273   (detachable devices only).
 274   Return 0 on success.
 275   */
 276
 277int __init cs89x0_probe(struct net_device *dev)
 278{
 279        int i;
 280        int base_addr = dev ? dev->base_addr : 0;
 281
 282        SET_MODULE_OWNER(dev);
 283
 284        if (net_debug)
 285                printk("cs89x0:cs89x0_probe(0x%x)\n", base_addr);
 286
 287        if (base_addr > 0x1ff)          /* Check a single specified location. */
 288                return cs89x0_probe1(dev, base_addr);
 289        else if (base_addr != 0)        /* Don't probe at all. */
 290                return -ENXIO;
 291
 292        for (i = 0; netcard_portlist[i]; i++) {
 293                if (cs89x0_probe1(dev, netcard_portlist[i]) == 0)
 294                        return 0;
 295        }
 296        printk(KERN_WARNING "cs89x0: no cs8900 or cs8920 detected.  Be sure to disable PnP with SETUP\n");
 297        return -ENODEV;
 298}
 299
 300static int
 301readreg(struct net_device *dev, int portno)
 302{
 303        outw(portno, dev->base_addr + ADD_PORT);
 304        return inw(dev->base_addr + DATA_PORT);
 305}
 306
 307static void
 308writereg(struct net_device *dev, int portno, int value)
 309{
 310        outw(portno, dev->base_addr + ADD_PORT);
 311        outw(value, dev->base_addr + DATA_PORT);
 312}
 313
 314static int
 315readword(struct net_device *dev, int portno)
 316{
 317        return inw(dev->base_addr + portno);
 318}
 319
 320static void
 321writeword(struct net_device *dev, int portno, int value)
 322{
 323        outw(value, dev->base_addr + portno);
 324}
 325
 326static int __init
 327wait_eeprom_ready(struct net_device *dev)
 328{
 329        int timeout = jiffies;
 330        /* check to see if the EEPROM is ready, a timeout is used -
 331           just in case EEPROM is ready when SI_BUSY in the
 332           PP_SelfST is clear */
 333        while(readreg(dev, PP_SelfST) & SI_BUSY)
 334                if (jiffies - timeout >= 40)
 335                        return -1;
 336        return 0;
 337}
 338
 339static int __init
 340get_eeprom_data(struct net_device *dev, int off, int len, int *buffer)
 341{
 342        int i;
 343
 344        if (net_debug > 3) printk("EEPROM data from %x for %x:\n",off,len);
 345        for (i = 0; i < len; i++) {
 346                if (wait_eeprom_ready(dev) < 0) return -1;
 347                /* Now send the EEPROM read command and EEPROM location to read */
 348                writereg(dev, PP_EECMD, (off + i) | EEPROM_READ_CMD);
 349                if (wait_eeprom_ready(dev) < 0) return -1;
 350                buffer[i] = readreg(dev, PP_EEData);
 351                if (net_debug > 3) printk("%04x ", buffer[i]);
 352        }
 353        if (net_debug > 3) printk("\n");
 354        return 0;
 355}
 356
 357static int  __init
 358get_eeprom_cksum(int off, int len, int *buffer)
 359{
 360        int i, cksum;
 361
 362        cksum = 0;
 363        for (i = 0; i < len; i++)
 364                cksum += buffer[i];
 365        cksum &= 0xffff;
 366        if (cksum == 0)
 367                return 0;
 368        return -1;
 369}
 370
 371/* This is the real probe routine.  Linux has a history of friendly device
 372   probes on the ISA bus.  A good device probes avoids doing writes, and
 373   verifies that the correct device exists and functions.
 374   Return 0 on success.
 375 */
 376
 377static int __init
 378cs89x0_probe1(struct net_device *dev, int ioaddr)
 379{
 380        struct net_local *lp;
 381        static unsigned version_printed;
 382        int i;
 383        unsigned rev_type = 0;
 384        int eeprom_buff[CHKSUM_LEN];
 385        int retval;
 386
 387        /* Initialize the device structure. */
 388        if (dev->priv == NULL) {
 389                dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
 390                if (dev->priv == 0) {
 391                        retval = -ENOMEM;
 392                        goto out;
 393                }
 394                lp = (struct net_local *)dev->priv;
 395                memset(lp, 0, sizeof(*lp));
 396                spin_lock_init(&lp->lock);
 397#if !defined(MODULE) && (ALLOW_DMA != 0)
 398                if (g_cs89x0_dma) {
 399                        lp->use_dma = 1;
 400                        lp->dma = g_cs89x0_dma;
 401                        lp->dmasize = 16;       /* Could make this an option... */
 402                }
 403#endif
 404#ifndef MODULE
 405                lp->force = g_cs89x0_media__force;
 406#endif
 407        }
 408        lp = (struct net_local *)dev->priv;
 409
 410        /* Grab the region so we can find another board if autoIRQ fails. */
 411        if (!request_region(ioaddr & ~3, NETCARD_IO_EXTENT, dev->name)) {
 412                printk(KERN_ERR "%s: request_region(0x%x, 0x%x) failed\n",
 413                                dev->name, ioaddr, NETCARD_IO_EXTENT);
 414                retval = -EBUSY;
 415                goto out1;
 416        }
 417
 418#ifdef CONFIG_SH_HICOSH4
 419        /* truely reset the chip */
 420        outw(0x0114, ioaddr + ADD_PORT);
 421        outw(0x0040, ioaddr + DATA_PORT);
 422#endif
 423
 424        /* if they give us an odd I/O address, then do ONE write to
 425           the address port, to get it back to address zero, where we
 426           expect to find the EISA signature word. An IO with a base of 0x3
 427           will skip the test for the ADD_PORT. */
 428        if (ioaddr & 1) {
 429                if (net_debug > 1)
 430                        printk(KERN_INFO "%s: odd ioaddr 0x%x\n", dev->name, ioaddr);
 431                if ((ioaddr & 2) != 2)
 432                        if ((inw((ioaddr & ~3)+ ADD_PORT) & ADD_MASK) != ADD_SIG) {
 433                                printk(KERN_ERR "%s: bad signature 0x%x\n",
 434                                        dev->name, inw((ioaddr & ~3)+ ADD_PORT));
 435                                retval = -ENODEV;
 436                                goto out2;
 437                        }
 438                ioaddr &= ~3;
 439                outw(PP_ChipID, ioaddr + ADD_PORT);
 440        }
 441printk("PP_addr=0x%x\n", inw(ioaddr + ADD_PORT));
 442
 443        if (inw(ioaddr + DATA_PORT) != CHIP_EISA_ID_SIG) {
 444                printk(KERN_ERR "%s: incorrect signature 0x%x\n",
 445                        dev->name, inw(ioaddr + DATA_PORT));
 446                retval = -ENODEV;
 447                goto out2;
 448        }
 449
 450        /* Fill in the 'dev' fields. */
 451        dev->base_addr = ioaddr;
 452
 453        /* get the chip type */
 454        rev_type = readreg(dev, PRODUCT_ID_ADD);
 455        lp->chip_type = rev_type &~ REVISON_BITS;
 456        lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A';
 457
 458        /* Check the chip type and revision in order to set the correct send command
 459        CS8920 revision C and CS8900 revision F can use the faster send. */
 460        lp->send_cmd = TX_AFTER_381;
 461        if (lp->chip_type == CS8900 && lp->chip_revision >= 'F')
 462                lp->send_cmd = TX_NOW;
 463        if (lp->chip_type != CS8900 && lp->chip_revision >= 'C')
 464                lp->send_cmd = TX_NOW;
 465
 466        if (net_debug  &&  version_printed++ == 0)
 467                printk(version);
 468
 469        printk(KERN_INFO "%s: cs89%c0%s rev %c found at %#3lx ",
 470               dev->name,
 471               lp->chip_type==CS8900?'0':'2',
 472               lp->chip_type==CS8920M?"M":"",
 473               lp->chip_revision,
 474               dev->base_addr);
 475
 476        reset_chip(dev);
 477   
 478        /* Here we read the current configuration of the chip. If there
 479           is no Extended EEPROM then the idea is to not disturb the chip
 480           configuration, it should have been correctly setup by automatic
 481           EEPROM read on reset. So, if the chip says it read the EEPROM
 482           the driver will always do *something* instead of complain that
 483           adapter_cnf is 0. */
 484
 485#ifdef CONFIG_SH_HICOSH4
 486        if (1) {
 487                /* For the HiCO.SH4 board, things are different: we don't
 488                   have EEPROM, but there is some data in flash, so we go
 489                   get it there directly (MAC). */
 490                __u16 *confd;
 491                short cnt;
 492                if (((* (volatile __u32 *) 0xa0013ff0) & 0x00ffffff)
 493                        == 0x006c3000) {
 494                        confd = (__u16*) 0xa0013fc0;
 495                } else {
 496                        confd = (__u16*) 0xa001ffc0;
 497                }
 498                cnt = (*confd++ & 0x00ff) >> 1;
 499                while (--cnt > 0) {
 500                        __u16 j = *confd++;
 501                        
 502                        switch (j & 0x0fff) {
 503                        case PP_IA:
 504                                for (i = 0; i < ETH_ALEN/2; i++) {
 505                                        dev->dev_addr[i*2] = confd[i] & 0xFF;
 506                                        dev->dev_addr[i*2+1] = confd[i] >> 8;
 507                                }
 508                                break;
 509                        }
 510                        j = (j >> 12) + 1;
 511                        confd += j;
 512                        cnt -= j;
 513                }
 514        } else
 515#endif
 516
 517        if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) == 
 518              (EEPROM_OK|EEPROM_PRESENT)) {
 519                /* Load the MAC. */
 520                for (i=0; i < ETH_ALEN/2; i++) {
 521                        unsigned int Addr;
 522                        Addr = readreg(dev, PP_IA+i*2);
 523                        dev->dev_addr[i*2] = Addr & 0xFF;
 524                        dev->dev_addr[i*2+1] = Addr >> 8;
 525                }
 526   
 527                /* Load the Adapter Configuration. 
 528                   Note:  Barring any more specific information from some 
 529                   other source (ie EEPROM+Schematics), we would not know 
 530                   how to operate a 10Base2 interface on the AUI port. 
 531                   However, since we  do read the status of HCB1 and use 
 532                   settings that always result in calls to control_dc_dc(dev,0) 
 533                   a BNC interface should work if the enable pin 
 534                   (dc/dc converter) is on HCB1. It will be called AUI 
 535                   however. */
 536           
 537                lp->adapter_cnf = 0;
 538                i = readreg(dev, PP_LineCTL);
 539                /* Preserve the setting of the HCB1 pin. */
 540                if ((i & (HCB1 | HCB1_ENBL)) ==  (HCB1 | HCB1_ENBL))
 541                        lp->adapter_cnf |= A_CNF_DC_DC_POLARITY;
 542                /* Save the sqelch bit */
 543                if ((i & LOW_RX_SQUELCH) == LOW_RX_SQUELCH)
 544                        lp->adapter_cnf |= A_CNF_EXTND_10B_2 | A_CNF_LOW_RX_SQUELCH;
 545                /* Check if the card is in 10Base-t only mode */
 546                if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == 0)
 547                        lp->adapter_cnf |=  A_CNF_10B_T | A_CNF_MEDIA_10B_T;
 548                /* Check if the card is in AUI only mode */
 549                if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUI_ONLY)
 550                        lp->adapter_cnf |=  A_CNF_AUI | A_CNF_MEDIA_AUI;
 551                /* Check if the card is in Auto mode. */
 552                if ((i & (AUI_ONLY | AUTO_AUI_10BASET)) == AUTO_AUI_10BASET)
 553                        lp->adapter_cnf |=  A_CNF_AUI | A_CNF_10B_T | 
 554                        A_CNF_MEDIA_AUI | A_CNF_MEDIA_10B_T | A_CNF_MEDIA_AUTO;
 555                
 556                if (net_debug > 1)
 557                        printk(KERN_INFO "%s: PP_LineCTL=0x%x, adapter_cnf=0x%x\n",
 558                                        dev->name, i, lp->adapter_cnf);
 559
 560                /* IRQ. Other chips already probe, see below. */
 561                if (lp->chip_type == CS8900) 
 562                        lp->isa_config = readreg(dev, PP_CS8900_ISAINT) & INT_NO_MASK;
 563           
 564                printk( "[Cirrus EEPROM] ");
 565        }
 566
 567        printk("\n");
 568   
 569        /* First check to see if an EEPROM is attached. */
 570#ifdef CONFIG_SH_HICOSH4 /* no EEPROM on HiCO, don't hazzle with it here */
 571        if (1) {
 572                printk(KERN_NOTICE "cs89x0: No EEPROM on HiCO.SH4\n");
 573        } else
 574#endif
 575        if ((readreg(dev, PP_SelfST) & EEPROM_PRESENT) == 0)
 576                printk(KERN_WARNING "cs89x0: No EEPROM, relying on command line....\n");
 577        else if (get_eeprom_data(dev, START_EEPROM_DATA,CHKSUM_LEN,eeprom_buff) < 0) {
 578                printk(KERN_WARNING "\ncs89x0: EEPROM read failed, relying on command line.\n");
 579        } else if (get_eeprom_cksum(START_EEPROM_DATA,CHKSUM_LEN,eeprom_buff) < 0) {
 580                /* Check if the chip was able to read its own configuration starting
 581                   at 0 in the EEPROM*/
 582                if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) !=
 583                    (EEPROM_OK|EEPROM_PRESENT)) 
 584                        printk(KERN_WARNING "cs89x0: Extended EEPROM checksum bad and no Cirrus EEPROM, relying on command line\n");
 585                   
 586        } else {
 587                /* This reads an extended EEPROM that is not documented
 588                   in the CS8900 datasheet. */
 589                
 590                /* get transmission control word  but keep the autonegotiation bits */
 591                if (!lp->auto_neg_cnf) lp->auto_neg_cnf = eeprom_buff[AUTO_NEG_CNF_OFFSET/2];
 592                /* Store adapter configuration */
 593                if (!lp->adapter_cnf) lp->adapter_cnf = eeprom_buff[ADAPTER_CNF_OFFSET/2];
 594                /* Store ISA configuration */
 595                lp->isa_config = eeprom_buff[ISA_CNF_OFFSET/2];
 596                dev->mem_start = eeprom_buff[PACKET_PAGE_OFFSET/2] << 8;
 597
 598                /* eeprom_buff has 32-bit ints, so we can't just memcpy it */
 599                /* store the initial memory base address */
 600                for (i = 0; i < ETH_ALEN/2; i++) {
 601                        dev->dev_addr[i*2] = eeprom_buff[i];
 602                        dev->dev_addr[i*2+1] = eeprom_buff[i] >> 8;
 603                }
 604                if (net_debug > 1)
 605                        printk(KERN_DEBUG "%s: new adapter_cnf: 0x%x\n",
 606                                dev->name, lp->adapter_cnf);
 607        }
 608
 609        /* allow them to force multiple transceivers.  If they force multiple, autosense */
 610        {
 611                int count = 0;
 612                if (lp->force & FORCE_RJ45)     {lp->adapter_cnf |= A_CNF_10B_T; count++; }
 613                if (lp->force & FORCE_AUI)      {lp->adapter_cnf |= A_CNF_AUI; count++; }
 614                if (lp->force & FORCE_BNC)      {lp->adapter_cnf |= A_CNF_10B_2; count++; }
 615                if (count > 1)                  {lp->adapter_cnf |= A_CNF_MEDIA_AUTO; }
 616                else if (lp->force & FORCE_RJ45){lp->adapter_cnf |= A_CNF_MEDIA_10B_T; }
 617                else if (lp->force & FORCE_AUI) {lp->adapter_cnf |= A_CNF_MEDIA_AUI; }
 618                else if (lp->force & FORCE_BNC) {lp->adapter_cnf |= A_CNF_MEDIA_10B_2; }
 619        }
 620
 621        if (net_debug > 1)
 622                printk(KERN_DEBUG "%s: after force 0x%x, adapter_cnf=0x%x\n",
 623                        dev->name, lp->force, lp->adapter_cnf);
 624
 625        /* FIXME: We don't let you set dc-dc polarity or low RX squelch from the command line: add it here */
 626
 627        /* FIXME: We don't let you set the IMM bit from the command line: add it to lp->auto_neg_cnf here */
 628
 629        /* FIXME: we don't set the Ethernet address on the command line.  Use
 630           ifconfig IFACE hw ether AABBCCDDEEFF */
 631
 632        printk(KERN_INFO "cs89x0 media %s%s%s",
 633               (lp->adapter_cnf & A_CNF_10B_T)?"RJ-45,":"",
 634               (lp->adapter_cnf & A_CNF_AUI)?"AUI,":"",
 635               (lp->adapter_cnf & A_CNF_10B_2)?"BNC,":"");
 636
 637        lp->irq_map = 0xffff;
 638
 639        /* If this is a CS8900 then no pnp soft */
 640        if (lp->chip_type != CS8900 &&
 641            /* Check if the ISA IRQ has been set  */
 642                (i = readreg(dev, PP_CS8920_ISAINT) & 0xff,
 643                 (i != 0 && i < CS8920_NO_INTS))) {
 644                if (!dev->irq)
 645                        dev->irq = i;
 646        } else {
 647                i = lp->isa_config & INT_NO_MASK;
 648                if (lp->chip_type == CS8900) {
 649                        /* Translate the IRQ using the IRQ mapping table. */
 650                        if (i >= sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]))
 651                                printk("\ncs89x0: invalid ISA interrupt number %d\n", i);
 652                        else
 653                                i = cs8900_irq_map[i];
 654                        
 655                        lp->irq_map = CS8900_IRQ_MAP; /* fixed IRQ map for CS8900 */
 656                } else {
 657                        int irq_map_buff[IRQ_MAP_LEN/2];
 658
 659                        if (get_eeprom_data(dev, IRQ_MAP_EEPROM_DATA,
 660                                            IRQ_MAP_LEN/2,
 661                                            irq_map_buff) >= 0) {
 662                                if ((irq_map_buff[0] & 0xff) == PNP_IRQ_FRMT)
 663                                        lp->irq_map = (irq_map_buff[0]>>8) | (irq_map_buff[1] << 8);
 664                        }
 665                }
 666                if (!dev->irq)
 667                        dev->irq = i;
 668        }
 669
 670        printk(" IRQ %d", dev->irq);
 671
 672#if ALLOW_DMA
 673        if (lp->use_dma) {
 674                get_dma_channel(dev);
 675                printk(", DMA %d", dev->dma);
 676        }
 677        else
 678#endif
 679        {
 680                printk(", programmed I/O");
 681        }
 682
 683        /* print the ethernet address. */
 684        printk(", MAC");
 685        for (i = 0; i < ETH_ALEN; i++)
 686        {
 687                printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
 688        }
 689
 690        dev->open               = net_open;
 691        dev->stop               = net_close;
 692        dev->tx_timeout         = net_timeout;
 693        dev->watchdog_timeo     = HZ;
 694        dev->hard_start_xmit    = net_send_packet;
 695        dev->get_stats          = net_get_stats;
 696        dev->set_multicast_list = set_multicast_list;
 697        dev->set_mac_address    = set_mac_address;
 698
 699        /* Fill in the fields of the device structure with ethernet values. */
 700        ether_setup(dev);
 701
 702        printk("\n");
 703        if (net_debug)
 704                printk("cs89x0_probe1() successful\n");
 705        return 0;
 706out2:
 707        release_region(ioaddr & ~3, NETCARD_IO_EXTENT);
 708out1:
 709        kfree(dev->priv);
 710        dev->priv = 0;
 711out:
 712        return retval;
 713}
 714
 715
 716/*********************************
 717 * This page contains DMA routines
 718**********************************/
 719
 720#if ALLOW_DMA
 721
 722#define dma_page_eq(ptr1, ptr2) ((long)(ptr1)>>17 == (long)(ptr2)>>17)
 723
 724static void
 725get_dma_channel(struct net_device *dev)
 726{
 727        struct net_local *lp = (struct net_local *)dev->priv;
 728
 729        if (lp->dma) {
 730                dev->dma = lp->dma;
 731                lp->isa_config |= ISA_RxDMA;
 732        } else {
 733                if ((lp->isa_config & ANY_ISA_DMA) == 0)
 734                        return;
 735                dev->dma = lp->isa_config & DMA_NO_MASK;
 736                if (lp->chip_type == CS8900)
 737                        dev->dma += 5;
 738                if (dev->dma < 5 || dev->dma > 7) {
 739                        lp->isa_config &= ~ANY_ISA_DMA;
 740                        return;
 741                }
 742        }
 743        return;
 744}
 745
 746static void
 747write_dma(struct net_device *dev, int chip_type, int dma)
 748{
 749        struct net_local *lp = (struct net_local *)dev->priv;
 750        if ((lp->isa_config & ANY_ISA_DMA) == 0)
 751                return;
 752        if (chip_type == CS8900) {
 753                writereg(dev, PP_CS8900_ISADMA, dma-5);
 754        } else {
 755                writereg(dev, PP_CS8920_ISADMA, dma);
 756        }
 757}
 758
 759static void
 760set_dma_cfg(struct net_device *dev)
 761{
 762        struct net_local *lp = (struct net_local *)dev->priv;
 763
 764        if (lp->use_dma) {
 765                if ((lp->isa_config & ANY_ISA_DMA) == 0) {
 766                        if (net_debug > 3)
 767                                printk("set_dma_cfg(): no DMA\n");
 768                        return;
 769                }
 770                if (lp->isa_config & ISA_RxDMA) {
 771                        lp->curr_rx_cfg |= RX_DMA_ONLY;
 772                        if (net_debug > 3)
 773                                printk("set_dma_cfg(): RX_DMA_ONLY\n");
 774                } else {
 775                        lp->curr_rx_cfg |= AUTO_RX_DMA; /* not that we support it... */
 776                        if (net_debug > 3)
 777                                printk("set_dma_cfg(): AUTO_RX_DMA\n");
 778                }
 779        }
 780}
 781
 782static int
 783dma_bufcfg(struct net_device *dev)
 784{
 785        struct net_local *lp = (struct net_local *)dev->priv;
 786        if (lp->use_dma)
 787                return (lp->isa_config & ANY_ISA_DMA)? RX_DMA_ENBL : 0;
 788        else
 789                return 0;
 790}
 791
 792static int
 793dma_busctl(struct net_device *dev)
 794{
 795        int retval = 0;
 796        struct net_local *lp = (struct net_local *)dev->priv;
 797        if (lp->use_dma) {
 798                if (lp->isa_config & ANY_ISA_DMA)
 799                        retval |= RESET_RX_DMA; /* Reset the DMA pointer */
 800                if (lp->isa_config & DMA_BURST)
 801                        retval |= DMA_BURST_MODE; /* Does ISA config specify DMA burst ? */
 802                if (lp->dmasize == 64)
 803                        retval |= RX_DMA_SIZE_64K; /* did they ask for 64K? */
 804                retval |= MEMORY_ON;    /* we need memory enabled to use DMA. */
 805        }
 806        return retval;
 807}
 808
 809static void
 810dma_rx(struct net_device *dev)
 811{
 812        struct net_local *lp = (struct net_local *)dev->priv;
 813        struct sk_buff *skb;
 814        int status, length;
 815        unsigned char *bp = lp->rx_dma_ptr;
 816
 817        status = bp[0] + (bp[1]<<8);
 818        length = bp[2] + (bp[3]<<8);
 819        bp += 4;
 820        if (net_debug > 5) {
 821                printk( "%s: receiving DMA packet at %lx, status %x, length %x\n",
 822                        dev->name, (unsigned long)bp, status, length);
 823        }
 824        if ((status & RX_OK) == 0) {
 825                count_rx_errors(status, lp);
 826                goto skip_this_frame;
 827        }
 828
 829        /* Malloc up new buffer. */
 830        skb = dev_alloc_skb(length + 2);
 831        if (skb == NULL) {
 832                if (net_debug)  /* I don't think we want to do this to a stressed system */
 833                        printk("%s: Memory squeeze, dropping packet.\n", dev->name);
 834                lp->stats.rx_dropped++;
 835
 836                /* AKPM: advance bp to the next frame */
 837skip_this_frame:
 838                bp += (length + 3) & ~3;
 839                if (bp >= lp->end_dma_buff) bp -= lp->dmasize*1024;
 840                lp->rx_dma_ptr = bp;
 841                return;
 842        }
 843        skb_reserve(skb, 2);    /* longword align L3 header */
 844        skb->dev = dev;
 845
 846        if (bp + length > lp->end_dma_buff) {
 847                int semi_cnt = lp->end_dma_buff - bp;
 848                memcpy(skb_put(skb,semi_cnt), bp, semi_cnt);
 849                memcpy(skb_put(skb,length - semi_cnt), lp->dma_buff,
 850                       length - semi_cnt);
 851        } else {
 852                memcpy(skb_put(skb,length), bp, length);
 853        }
 854        bp += (length + 3) & ~3;
 855        if (bp >= lp->end_dma_buff) bp -= lp->dmasize*1024;
 856        lp->rx_dma_ptr = bp;
 857
 858        if (net_debug > 3) {
 859                printk( "%s: received %d byte DMA packet of type %x\n",
 860                        dev->name, length,
 861                        (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);
 862        }
 863        skb->protocol=eth_type_trans(skb,dev);
 864        netif_rx(skb);
 865        dev->last_rx = jiffies;
 866        lp->stats.rx_packets++;
 867        lp->stats.rx_bytes += length;
 868}
 869
 870#endif  /* ALLOW_DMA */
 871
 872void  __init reset_chip(struct net_device *dev)
 873{
 874        struct net_local *lp = (struct net_local *)dev->priv;
 875        int ioaddr = dev->base_addr;
 876        int reset_start_time;
 877
 878        writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);
 879
 880        /* wait 30 ms */
 881        current->state = TASK_INTERRUPTIBLE;
 882        schedule_timeout(30*HZ/1000);
 883
 884        if (lp->chip_type != CS8900) {
 885                /* Hardware problem requires PNP registers to be reconfigured after a reset */
 886                outw(PP_CS8920_ISAINT, ioaddr + ADD_PORT);
 887                outb(dev->irq, ioaddr + DATA_PORT);
 888                outb(0,      ioaddr + DATA_PORT + 1);
 889
 890                outw(PP_CS8920_ISAMemB, ioaddr + ADD_PORT);
 891                outb((dev->mem_start >> 16) & 0xff, ioaddr + DATA_PORT);
 892                outb((dev->mem_start >> 8) & 0xff,   ioaddr + DATA_PORT + 1);
 893        }
 894        /* Wait until the chip is reset */
 895        reset_start_time = jiffies;
 896        while( (readreg(dev, PP_SelfST) & INIT_DONE) == 0 && jiffies - reset_start_time < 2)
 897                ;
 898}
 899
 900
 901static void
 902control_dc_dc(struct net_device *dev, int on_not_off)
 903{
 904        struct net_local *lp = (struct net_local *)dev->priv;
 905        unsigned int selfcontrol;
 906        int timenow = jiffies;
 907        /* control the DC to DC convertor in the SelfControl register.  
 908           Note: This is hooked up to a general purpose pin, might not
 909           always be a DC to DC convertor. */
 910
 911        selfcontrol = HCB1_ENBL; /* Enable the HCB1 bit as an output */
 912        if (((lp->adapter_cnf & A_CNF_DC_DC_POLARITY) != 0) ^ on_not_off)
 913                selfcontrol |= HCB1;
 914        else
 915                selfcontrol &= ~HCB1;
 916        writereg(dev, PP_SelfCTL, selfcontrol);
 917
 918        /* Wait for the DC/DC converter to power up - 500ms */
 919        while (jiffies - timenow < HZ)
 920                ;
 921}
 922
 923#define DETECTED_NONE  0
 924#define DETECTED_RJ45H 1
 925#define DETECTED_RJ45F 2
 926#define DETECTED_AUI   3
 927#define DETECTED_BNC   4
 928
 929static int
 930detect_tp(struct net_device *dev)
 931{
 932        struct net_local *lp = (struct net_local *)dev->priv;
 933        int timenow = jiffies;
 934        int fdx;
 935
 936        if (net_debug > 1) printk("%s: Attempting TP\n", dev->name);
 937
 938        /* If connected to another full duplex capable 10-Base-T card the link pulses
 939           seem to be lost when the auto detect bit in the LineCTL is set.
 940           To overcome this the auto detect bit will be cleared whilst testing the
 941           10-Base-T interface.  This would not be necessary for the sparrow chip but
 942           is simpler to do it anyway. */
 943        writereg(dev, PP_LineCTL, lp->linectl &~ AUI_ONLY);
 944        control_dc_dc(dev, 0);
 945
 946        /* Delay for the hardware to work out if the TP cable is present - 150ms */
 947        for (timenow = jiffies; jiffies - timenow < 15; )
 948                ;
 949        if ((readreg(dev, PP_LineST) & LINK_OK) == 0)
 950                return DETECTED_NONE;
 951
 952        if (lp->chip_type == CS8900) {
 953                switch (lp->force & 0xf0) {
 954#if 0
 955                case FORCE_AUTO:
 956                        printk("%s: cs8900 doesn't autonegotiate\n",dev->name);
 957                        return DETECTED_NONE;
 958#endif
 959                /* CS8900 doesn't support AUTO, change to HALF*/
 960                case FORCE_AUTO:
 961                        lp->force &= ~FORCE_AUTO;
 962                        lp->force |= FORCE_HALF;
 963                        break;
 964                case FORCE_HALF:
 965                        break;
 966                case FORCE_FULL:
 967                        writereg(dev, PP_TestCTL, readreg(dev, PP_TestCTL) | FDX_8900);
 968                        break;
 969                }
 970                fdx = readreg(dev, PP_TestCTL) & FDX_8900;
 971        } else {
 972                switch (lp->force & 0xf0) {
 973                case FORCE_AUTO:
 974                        lp->auto_neg_cnf = AUTO_NEG_ENABLE;
 975                        break;
 976                case FORCE_HALF:
 977                        lp->auto_neg_cnf = 0;
 978                        break;
 979                case FORCE_FULL:
 980                        lp->auto_neg_cnf = RE_NEG_NOW | ALLOW_FDX;
 981                        break;
 982                }
 983
 984                writereg(dev, PP_AutoNegCTL, lp->auto_neg_cnf & AUTO_NEG_MASK);
 985
 986                if ((lp->auto_neg_cnf & AUTO_NEG_BITS) == AUTO_NEG_ENABLE) {
 987                        printk(KERN_INFO "%s: negotiating duplex...\n",dev->name);
 988                        while (readreg(dev, PP_AutoNegST) & AUTO_NEG_BUSY) {
 989                                if (jiffies - timenow > 4000) {
 990                                        printk(KERN_ERR "**** Full / half duplex auto-negotiation timed out ****\n");
 991                                        break;
 992                                }
 993                        }
 994                }
 995                fdx = readreg(dev, PP_AutoNegST) & FDX_ACTIVE;
 996        }
 997        if (fdx)
 998                return DETECTED_RJ45F;
 999        else
1000                return DETECTED_RJ45H;
1001}
1002
1003/* send a test packet - return true if carrier bits are ok */
1004static int
1005send_test_pkt(struct net_device *dev)
1006{
1007        char test_packet[] = { 0,0,0,0,0,0, 0,0,0,0,0,0,
1008                                 0, 46, /* A 46 in network order */
1009                                 0, 0, /* DSAP=0 & SSAP=0 fields */
1010                                 0xf3, 0 /* Control (Test Req + P bit set) */ };
1011        long timenow = jiffies;
1012
1013        writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_TX_ON);
1014
1015        memcpy(test_packet,          dev->dev_addr, ETH_ALEN);
1016        memcpy(test_packet+ETH_ALEN, dev->dev_addr, ETH_ALEN);
1017
1018        writeword(dev, TX_CMD_PORT, TX_AFTER_ALL);
1019        writeword(dev, TX_LEN_PORT, ETH_ZLEN);
1020
1021        /* Test to see if the chip has allocated memory for the packet */
1022        while (jiffies - timenow < 5)
1023                if (readreg(dev, PP_BusST) & READY_FOR_TX_NOW)
1024                        break;
1025        if (jiffies - timenow >= 5)
1026                return 0;       /* this shouldn't happen */
1027
1028        /* Write the contents of the packet */
1029        outsw(dev->base_addr + TX_FRAME_PORT,test_packet,(ETH_ZLEN+1) >>1);
1030
1031        if (net_debug > 1) printk("Sending test packet ");
1032        /* wait a couple of jiffies for packet to be received */
1033        for (timenow = jiffies; jiffies - timenow < 3; )
1034                ;
1035        if ((readreg(dev, PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) {
1036                if (net_debug > 1) printk("succeeded\n");
1037                return 1;
1038        }
1039        if (net_debug > 1) printk("failed\n");
1040        return 0;
1041}
1042
1043
1044static int
1045detect_aui(struct net_device *dev)
1046{
1047        struct net_local *lp = (struct net_local *)dev->priv;
1048
1049        if (net_debug > 1) printk("%s: Attempting AUI\n", dev->name);
1050        control_dc_dc(dev, 0);
1051
1052        writereg(dev, PP_LineCTL, (lp->linectl &~ AUTO_AUI_10BASET) | AUI_ONLY);
1053
1054        if (send_test_pkt(dev))
1055                return DETECTED_AUI;
1056        else
1057                return DETECTED_NONE;
1058}
1059
1060static int
1061detect_bnc(struct net_device *dev)
1062{
1063        struct net_local *lp = (struct net_local *)dev->priv;
1064
1065        if (net_debug > 1) printk("%s: Attempting BNC\n", dev->name);
1066        control_dc_dc(dev, 1);
1067
1068        writereg(dev, PP_LineCTL, (lp->linectl &~ AUTO_AUI_10BASET) | AUI_ONLY);
1069
1070        if (send_test_pkt(dev))
1071                return DETECTED_BNC;
1072        else
1073                return DETECTED_NONE;
1074}
1075
1076
1077static void
1078write_irq(struct net_device *dev, int chip_type, int irq)
1079{
1080        int i;
1081
1082        if (chip_type == CS8900) {
1083                /* Search the mapping table for the corresponding IRQ pin. */
1084                for (i = 0; i != sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]); i++)
1085                        if (cs8900_irq_map[i] == irq)
1086                                break;
1087                /* Not found */
1088                if (i == sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]))
1089                        i = 3;
1090                writereg(dev, PP_CS8900_ISAINT, i);
1091        } else {
1092                writereg(dev, PP_CS8920_ISAINT, irq);
1093        }
1094}
1095
1096/* Open/initialize the board.  This is called (in the current kernel)
1097   sometime after booting when the 'ifconfig' program is run.
1098
1099   This routine should set everything up anew at each open, even
1100   registers that "should" only need to be set once at boot, so that
1101   there is non-reboot way to recover if something goes wrong.
1102   */
1103
1104/* AKPM: do we need to do any locking here? */
1105
1106static int
1107net_open(struct net_device *dev)
1108{
1109        struct net_local *lp = (struct net_local *)dev->priv;
1110        int result = 0;
1111        int i;
1112        int ret;
1113
1114#ifndef CONFIG_SH_HICOSH4 /* uses irq#1, so this won't work */
1115        if (dev->irq < 2) {
1116                /* Allow interrupts to be generated by the chip */
1117/* Cirrus' release had this: */
1118#if 0
1119                writereg(dev, PP_BusCTL, readreg(dev, PP_BusCTL)|ENABLE_IRQ );
1120#endif
1121/* And 2.3.47 had this: */
1122                writereg(dev, PP_BusCTL, ENABLE_IRQ | MEMORY_ON);
1123
1124                for (i = 2; i < CS8920_NO_INTS; i++) {
1125                        if ((1 << i) & lp->irq_map) {
1126                                if (request_irq(i, net_interrupt, 0, dev->name, dev) == 0) {
1127                                        dev->irq = i;
1128                                        write_irq(dev, lp->chip_type, i);
1129                                        /* writereg(dev, PP_BufCFG, GENERATE_SW_INTERRUPT); */
1130                                        break;
1131                                }
1132                        }
1133                }
1134
1135                if (i >= CS8920_NO_INTS) {
1136                        writereg(dev, PP_BusCTL, 0);    /* disable interrupts. */
1137                        printk(KERN_ERR "cs89x0: can't get an interrupt\n");
1138                        ret = -EAGAIN;
1139                        goto bad_out;
1140                }
1141        }
1142        else
1143#endif
1144        {
1145                if (((1 << dev->irq) & lp->irq_map) == 0) {
1146                        printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x\n",
1147                               dev->name, dev->irq, lp->irq_map);
1148                        ret = -EAGAIN;
1149                        goto bad_out;
1150                }
1151/* FIXME: Cirrus' release had this: */
1152                writereg(dev, PP_BusCTL, readreg(dev, PP_BusCTL)|ENABLE_IRQ );
1153/* And 2.3.47 had this: */
1154#if 0
1155                writereg(dev, PP_BusCTL, ENABLE_IRQ | MEMORY_ON);
1156#endif
1157                write_irq(dev, lp->chip_type, dev->irq);
1158                ret = request_irq(dev->irq, &net_interrupt, 0, dev->name, dev);
1159                if (ret) {
1160                        if (net_debug)
1161                                printk(KERN_DEBUG "cs89x0: request_irq(%d) failed\n", dev->irq);
1162                        goto bad_out;
1163                }
1164        }
1165
1166#if ALLOW_DMA
1167        if (lp->use_dma) {
1168                if (lp->isa_config & ANY_ISA_DMA) {
1169                        unsigned long flags;
1170                        lp->dma_buff = (unsigned char *)__get_dma_pages(GFP_KERNEL,
1171                                                        get_order(lp->dmasize * 1024));
1172
1173                        if (!lp->dma_buff) {
1174                                printk(KERN_ERR "%s: cannot get %dK memory for DMA\n", dev->name, lp->dmasize);
1175                                goto release_irq;
1176                        }
1177                        if (net_debug > 1) {
1178                                printk( "%s: dma %lx %lx\n",
1179                                        dev->name,
1180                                        (unsigned long)lp->dma_buff,
1181                                        (unsigned long)isa_virt_to_bus(lp->dma_buff));
1182                        }
1183                        if ((unsigned long) lp->dma_buff >= MAX_DMA_ADDRESS ||
1184                            !dma_page_eq(lp->dma_buff, lp->dma_buff+lp->dmasize*1024-1)) {
1185                                printk(KERN_ERR "%s: not usable as DMA buffer\n", dev->name);
1186                                goto release_irq;
1187                        }
1188                        memset(lp->dma_buff, 0, lp->dmasize * 1024);    /* Why? */
1189                        if (request_dma(dev->dma, dev->name)) {
1190                                printk(KERN_ERR "%s: cannot get dma channel %d\n", dev->name, dev->dma);
1191                                goto release_irq;
1192                        }
1193                        write_dma(dev, lp->chip_type, dev->dma);
1194                        lp->rx_dma_ptr = lp->dma_buff;
1195                        lp->end_dma_buff = lp->dma_buff + lp->dmasize*1024;
1196                        spin_lock_irqsave(&lp->lock, flags);
1197                        disable_dma(dev->dma);
1198                        clear_dma_ff(dev->dma);
1199                        set_dma_mode(dev->dma, 0x14); /* auto_init as well */
1200                        set_dma_addr(dev->dma, isa_virt_to_bus(lp->dma_buff));
1201                        set_dma_count(dev->dma, lp->dmasize*1024);
1202                        enable_dma(dev->dma);
1203                        spin_unlock_irqrestore(&lp->lock, flags);
1204                }
1205        }
1206#endif  /* ALLOW_DMA */
1207
1208        /* set the Ethernet address */
1209        for (i=0; i < ETH_ALEN/2; i++)
1210                writereg(dev, PP_IA+i*2, dev->dev_addr[i*2] | (dev->dev_addr[i*2+1] << 8));
1211
1212        /* while we're testing the interface, leave interrupts disabled */
1213        writereg(dev, PP_BusCTL, MEMORY_ON);
1214
1215        /* Set the LineCTL quintuplet based on adapter configuration read from EEPROM */
1216        if ((lp->adapter_cnf & A_CNF_EXTND_10B_2) && (lp->adapter_cnf & A_CNF_LOW_RX_SQUELCH))
1217                lp->linectl = LOW_RX_SQUELCH;
1218        else
1219                lp->linectl = 0;
1220
1221        /* check to make sure that they have the "right" hardware available */
1222        switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
1223        case A_CNF_MEDIA_10B_T: result = lp->adapter_cnf & A_CNF_10B_T; break;
1224        case A_CNF_MEDIA_AUI:   result = lp->adapter_cnf & A_CNF_AUI; break;
1225        case A_CNF_MEDIA_10B_2: result = lp->adapter_cnf & A_CNF_10B_2; break;
1226        default: result = lp->adapter_cnf & (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2);
1227        }
1228        if (!result) {
1229                printk(KERN_ERR "%s: EEPROM is configured for unavailable media\n", dev->name);
1230        release_irq:
1231#if ALLOW_DMA
1232                release_dma_buff(lp);
1233#endif
1234                writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) & ~(SERIAL_TX_ON | SERIAL_RX_ON));
1235                free_irq(dev->irq, dev);
1236                ret = -EAGAIN;
1237                goto bad_out;
1238        }
1239
1240        /* set the hardware to the configured choice */
1241        switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
1242        case A_CNF_MEDIA_10B_T:
1243                result = detect_tp(dev);
1244                if (result==DETECTED_NONE) {
1245                        printk(KERN_WARNING "%s: 10Base-T (RJ-45) has no cable\n", dev->name);
1246                        if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
1247                                result = DETECTED_RJ45H; /* Yes! I don't care if I see a link pulse */
1248                }
1249                break;
1250        case A_CNF_MEDIA_AUI:
1251                result = detect_aui(dev);
1252                if (result==DETECTED_NONE) {
1253                        printk(KERN_WARNING "%s: 10Base-5 (AUI) has no cable\n", dev->name);
1254                        if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
1255                                result = DETECTED_AUI; /* Yes! I don't care if I see a carrrier */
1256                }
1257                break;
1258        case A_CNF_MEDIA_10B_2:
1259                result = detect_bnc(dev);
1260                if (result==DETECTED_NONE) {
1261                        printk(KERN_WARNING "%s: 10Base-2 (BNC) has no cable\n", dev->name);
1262                        if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
1263                                result = DETECTED_BNC; /* Yes! I don't care if I can xmit a packet */
1264                }
1265                break;
1266        case A_CNF_MEDIA_AUTO:
1267                writereg(dev, PP_LineCTL, lp->linectl | AUTO_AUI_10BASET);
1268                if (lp->adapter_cnf & A_CNF_10B_T)
1269                        if ((result = detect_tp(dev)) != DETECTED_NONE)
1270                                break;
1271                if (lp->adapter_cnf & A_CNF_AUI)
1272                        if ((result = detect_aui(dev)) != DETECTED_NONE)
1273                                break;
1274                if (lp->adapter_cnf & A_CNF_10B_2)
1275                        if ((result = detect_bnc(dev)) != DETECTED_NONE)
1276                                break;
1277                printk(KERN_ERR "%s: no media detected\n", dev->name);
1278                goto release_irq;
1279        }
1280        switch(result) {
1281        case DETECTED_NONE:
1282                printk(KERN_ERR "%s: no network cable attached to configured media\n", dev->name);
1283                goto release_irq;
1284        case DETECTED_RJ45H:
1285                printk(KERN_INFO "%s: using half-duplex 10Base-T (RJ-45)\n", dev->name);
1286                break;
1287        case DETECTED_RJ45F:
1288                printk(KERN_INFO "%s: using full-duplex 10Base-T (RJ-45)\n", dev->name);
1289                break;
1290        case DETECTED_AUI:
1291                printk(KERN_INFO "%s: using 10Base-5 (AUI)\n", dev->name);
1292                break;
1293        case DETECTED_BNC:
1294                printk(KERN_INFO "%s: using 10Base-2 (BNC)\n", dev->name);
1295                break;
1296        }
1297
1298        /* Turn on both receive and transmit operations */
1299        writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_RX_ON | SERIAL_TX_ON);
1300
1301        /* Receive only error free packets addressed to this card */
1302        lp->rx_mode = 0;
1303        writereg(dev, PP_RxCTL, DEF_RX_ACCEPT);
1304
1305        lp->curr_rx_cfg = RX_OK_ENBL | RX_CRC_ERROR_ENBL;
1306
1307        if (lp->isa_config & STREAM_TRANSFER)
1308                lp->curr_rx_cfg |= RX_STREAM_ENBL;
1309#if ALLOW_DMA
1310        set_dma_cfg(dev);
1311#endif
1312        writereg(dev, PP_RxCFG, lp->curr_rx_cfg);
1313
1314        writereg(dev, PP_TxCFG, TX_LOST_CRS_ENBL | TX_SQE_ERROR_ENBL | TX_OK_ENBL |
1315                TX_LATE_COL_ENBL | TX_JBR_ENBL | TX_ANY_COL_ENBL | TX_16_COL_ENBL);
1316
1317        writereg(dev, PP_BufCFG, READY_FOR_TX_ENBL | RX_MISS_COUNT_OVRFLOW_ENBL |
1318#if ALLOW_DMA
1319                dma_bufcfg(dev) |
1320#endif
1321                TX_COL_COUNT_OVRFLOW_ENBL | TX_UNDERRUN_ENBL);
1322
1323        /* now that we've got our act together, enable everything */
1324        writereg(dev, PP_BusCTL, ENABLE_IRQ
1325                 | (dev->mem_start?MEMORY_ON : 0) /* turn memory on */
1326#if ALLOW_DMA
1327                 | dma_busctl(dev)
1328#endif
1329                 );
1330        netif_start_queue(dev);
1331        if (net_debug > 1)
1332                printk("cs89x0: net_open() succeeded\n");
1333        return 0;
1334bad_out:
1335        return ret;
1336}
1337
1338static void net_timeout(struct net_device *dev)
1339{
1340        /* If we get here, some higher level has decided we are broken.
1341           There should really be a "kick me" function call instead. */
1342        if (net_debug > 0) printk("%s: transmit timed out, %s?\n", dev->name,
1343                   tx_done(dev) ? "IRQ conflict ?" : "network cable problem");
1344        /* Try to restart the adaptor. */
1345        netif_wake_queue(dev);
1346}
1347
1348static int net_send_packet(struct sk_buff *skb, struct net_device *dev)
1349{
1350        struct net_local *lp = (struct net_local *)dev->priv;
1351
1352        if (net_debug > 3) {
1353                printk("%s: sent %d byte packet of type %x\n",
1354                        dev->name, skb->len,
1355                        (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);
1356        }
1357
1358        /* keep the upload from being interrupted, since we
1359                  ask the chip to start transmitting before the
1360                  whole packet has been completely uploaded. */
1361
1362        spin_lock_irq(&lp->lock);
1363        netif_stop_queue(dev);
1364
1365        /* initiate a transmit sequence */
1366        writeword(dev, TX_CMD_PORT, lp->send_cmd);
1367        writeword(dev, TX_LEN_PORT, skb->len);
1368
1369        /* Test to see if the chip has allocated memory for the packet */
1370        if ((readreg(dev, PP_BusST) & READY_FOR_TX_NOW) == 0) {
1371                /*
1372                 * Gasp!  It hasn't.  But that shouldn't happen since
1373                 * we're waiting for TxOk, so return 1 and requeue this packet.
1374                 */
1375                
1376                spin_unlock_irq(&lp->lock);
1377                if (net_debug) printk("cs89x0: Tx buffer not free!\n");
1378                return 1;
1379        }
1380        /* Write the contents of the packet */
1381        outsw(dev->base_addr + TX_FRAME_PORT,skb->data,(skb->len+1) >>1);
1382        spin_unlock_irq(&lp->lock);
1383        dev->trans_start = jiffies;
1384        dev_kfree_skb (skb);
1385
1386        /*
1387         * We DO NOT call netif_wake_queue() here.
1388         * We also DO NOT call netif_start_queue().
1389         *
1390         * Either of these would cause another bottom half run through
1391         * net_send_packet() before this packet has fully gone out.  That causes
1392         * us to hit the "Gasp!" above and the send is rescheduled.  it runs like
1393         * a dog.  We just return and wait for the Tx completion interrupt handler
1394         * to restart the netdevice layer
1395         */
1396
1397        return 0;
1398}
1399
1400/* The typical workload of the driver:
1401   Handle the network interface interrupts. */
1402   
1403static irqreturn_t net_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1404{
1405        struct net_device *dev = dev_id;
1406        struct net_local *lp;
1407        int ioaddr, status;
1408        int handled = 0;
1409
1410        ioaddr = dev->base_addr;
1411        lp = (struct net_local *)dev->priv;
1412
1413        /* we MUST read all the events out of the ISQ, otherwise we'll never
1414           get interrupted again.  As a consequence, we can't have any limit
1415           on the number of times we loop in the interrupt handler.  The
1416           hardware guarantees that eventually we'll run out of events.  Of
1417           course, if you're on a slow machine, and packets are arriving
1418           faster than you can read them off, you're screwed.  Hasta la
1419           vista, baby!  */
1420        while ((status = readword(dev, ISQ_PORT))) {
1421                if (net_debug > 4)printk("%s: event=%04x\n", dev->name, status);
1422                handled = 1;
1423                switch(status & ISQ_EVENT_MASK) {
1424                case ISQ_RECEIVER_EVENT:
1425                        /* Got a packet(s). */
1426                        net_rx(dev);
1427                        break;
1428                case ISQ_TRANSMITTER_EVENT:
1429                        lp->stats.tx_packets++;
1430                        netif_wake_queue(dev);  /* Inform upper layers. */
1431                        if ((status & ( TX_OK |
1432                                        TX_LOST_CRS |
1433                                        TX_SQE_ERROR |
1434                                        TX_LATE_COL |
1435                                        TX_16_COL)) != TX_OK) {
1436                                if ((status & TX_OK) == 0) lp->stats.tx_errors++;
1437                                if (status & TX_LOST_CRS) lp->stats.tx_carrier_errors++;
1438                                if (status & TX_SQE_ERROR) lp->stats.tx_heartbeat_errors++;
1439                                if (status & TX_LATE_COL) lp->stats.tx_window_errors++;
1440                                if (status & TX_16_COL) lp->stats.tx_aborted_errors++;
1441                        }
1442                        break;
1443                case ISQ_BUFFER_EVENT:
1444                        if (status & READY_FOR_TX) {
1445                                /* we tried to transmit a packet earlier,
1446                                   but inexplicably ran out of buffers.
1447                                   That shouldn't happen since we only ever
1448                                   load one packet.  Shrug.  Do the right
1449                                   thing anyway. */
1450                                netif_wake_queue(dev);  /* Inform upper layers. */
1451                        }
1452                        if (status & TX_UNDERRUN) {
1453                                if (net_debug > 0) printk("%s: transmit underrun\n", dev->name);
1454                                lp->send_underrun++;
1455                                if (lp->send_underrun == 3) lp->send_cmd = TX_AFTER_381;
1456                                else if (lp->send_underrun == 6) lp->send_cmd = TX_AFTER_ALL;
1457                                /* transmit cycle is done, although
1458                                   frame wasn't transmitted - this
1459                                   avoids having to wait for the upper
1460                                   layers to timeout on us, in the
1461                                   event of a tx underrun */
1462                                netif_wake_queue(dev);  /* Inform upper layers. */
1463                        }
1464#if ALLOW_DMA
1465                        if (lp->use_dma && (status & RX_DMA)) {
1466                                int count = readreg(dev, PP_DmaFrameCnt);
1467                                while(count) {
1468                                        if (net_debug > 5)
1469                                                printk("%s: receiving %d DMA frames\n", dev->name, count);
1470                                        if (net_debug > 2 && count >1)
1471                                                printk("%s: receiving %d DMA frames\n", dev->name, count);
1472                                        dma_rx(dev);
1473                                        if (--count == 0)
1474                                                count = readreg(dev, PP_DmaFrameCnt);
1475                                        if (net_debug > 2 && count > 0)
1476                                                printk("%s: continuing with %d DMA frames\n", dev->name, count);
1477                                }
1478                        }
1479#endif
1480                        break;
1481                case ISQ_RX_MISS_EVENT:
1482                        lp->stats.rx_missed_errors += (status >>6);
1483                        break;
1484                case ISQ_TX_COL_EVENT:
1485                        lp->stats.collisions += (status >>6);
1486                        break;
1487                }
1488        }
1489        return IRQ_RETVAL(handled);
1490}
1491
1492static void
1493count_rx_errors(int status, struct net_local *lp)
1494{
1495        lp->stats.rx_errors++;
1496        if (status & RX_RUNT) lp->stats.rx_length_errors++;
1497        if (status & RX_EXTRA_DATA) lp->stats.rx_length_errors++;
1498        if (status & RX_CRC_ERROR) if (!(status & (RX_EXTRA_DATA|RX_RUNT)))
1499                /* per str 172 */
1500                lp->stats.rx_crc_errors++;
1501        if (status & RX_DRIBBLE) lp->stats.rx_frame_errors++;
1502        return;
1503}
1504
1505/* We have a good packet(s), get it/them out of the buffers. */
1506static void
1507net_rx(struct net_device *dev)
1508{
1509        struct net_local *lp = (struct net_local *)dev->priv;
1510        struct sk_buff *skb;
1511        int status, length;
1512
1513        int ioaddr = dev->base_addr;
1514        status = inw(ioaddr + RX_FRAME_PORT);
1515        length = inw(ioaddr + RX_FRAME_PORT);
1516
1517        if ((status & RX_OK) == 0) {
1518                count_rx_errors(status, lp);
1519                return;
1520        }
1521
1522        /* Malloc up new buffer. */
1523        skb = dev_alloc_skb(length + 2);
1524        if (skb == NULL) {
1525#if 0           /* Again, this seems a cruel thing to do */
1526                printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
1527#endif
1528                lp->stats.rx_dropped++;
1529                return;
1530        }
1531        skb_reserve(skb, 2);    /* longword align L3 header */
1532        skb->dev = dev;
1533
1534        insw(ioaddr + RX_FRAME_PORT, skb_put(skb, length), length >> 1);
1535        if (length & 1)
1536                skb->data[length-1] = inw(ioaddr + RX_FRAME_PORT);
1537
1538        if (net_debug > 3) {
1539                printk( "%s: received %d byte packet of type %x\n",
1540                        dev->name, length,
1541                        (skb->data[ETH_ALEN+ETH_ALEN] << 8) | skb->data[ETH_ALEN+ETH_ALEN+1]);
1542        }
1543
1544        skb->protocol=eth_type_trans(skb,dev);
1545        netif_rx(skb);
1546        dev->last_rx = jiffies;
1547        lp->stats.rx_packets++;
1548        lp->stats.rx_bytes += length;
1549}
1550
1551#if ALLOW_DMA
1552static void release_dma_buff(struct net_local *lp)
1553{
1554        if (lp->dma_buff) {
1555                free_pages((unsigned long)(lp->dma_buff), get_order(lp->dmasize * 1024));
1556                lp->dma_buff = 0;
1557        }
1558}
1559#endif
1560
1561/* The inverse routine to net_open(). */
1562static int
1563net_close(struct net_device *dev)
1564{
1565        struct net_local *lp = (struct net_local *)dev->priv;
1566
1567        netif_stop_queue(dev);
1568        
1569        writereg(dev, PP_RxCFG, 0);
1570        writereg(dev, PP_TxCFG, 0);
1571        writereg(dev, PP_BufCFG, 0);
1572        writereg(dev, PP_BusCTL, 0);
1573
1574        free_irq(dev->irq, dev);
1575
1576#if ALLOW_DMA
1577        if (lp->use_dma && lp->dma) {
1578                free_dma(dev->dma);
1579                release_dma_buff(lp);
1580        }
1581#endif
1582
1583        /* Update the statistics here. */
1584        return 0;
1585}
1586
1587/* Get the current statistics.  This may be called with the card open or
1588   closed. */
1589static struct net_device_stats *
1590net_get_stats(struct net_device *dev)
1591{
1592        struct net_local *lp = (struct net_local *)dev->priv;
1593        unsigned long flags;
1594
1595        spin_lock_irqsave(&lp->lock, flags);
1596        /* Update the statistics from the device registers. */
1597        lp->stats.rx_missed_errors += (readreg(dev, PP_RxMiss) >> 6);
1598        lp->stats.collisions += (readreg(dev, PP_TxCol) >> 6);
1599        spin_unlock_irqrestore(&lp->lock, flags);
1600
1601        return &lp->stats;
1602}
1603
1604static void set_multicast_list(struct net_device *dev)
1605{
1606        struct net_local *lp = (struct net_local *)dev->priv;
1607        unsigned long flags;
1608
1609        spin_lock_irqsave(&lp->lock, flags);
1610        if(dev->flags&IFF_PROMISC)
1611        {
1612                lp->rx_mode = RX_ALL_ACCEPT;
1613        }
1614        else if((dev->flags&IFF_ALLMULTI)||dev->mc_list)
1615        {
1616                /* The multicast-accept list is initialized to accept-all, and we
1617                   rely on higher-level filtering for now. */
1618                lp->rx_mode = RX_MULTCAST_ACCEPT;
1619        } 
1620        else
1621                lp->rx_mode = 0;
1622
1623        writereg(dev, PP_RxCTL, DEF_RX_ACCEPT | lp->rx_mode);
1624
1625        /* in promiscuous mode, we accept errored packets, so we have to enable interrupts on them also */
1626        writereg(dev, PP_RxCFG, lp->curr_rx_cfg |
1627             (lp->rx_mode == RX_ALL_ACCEPT? (RX_CRC_ERROR_ENBL|RX_RUNT_ENBL|RX_EXTRA_DATA_ENBL) : 0));
1628        spin_unlock_irqrestore(&lp->lock, flags);
1629}
1630
1631
1632static int set_mac_address(struct net_device *dev, void *p)
1633{
1634        int i;
1635        struct sockaddr *addr = p;
1636
1637
1638        if (netif_running(dev))
1639                return -EBUSY;
1640
1641        memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1642
1643        if (net_debug) {
1644                printk("%s: Setting MAC address to ", dev->name);
1645                for (i = 0; i < dev->addr_len; i++)
1646                        printk(" %2.2x", dev->dev_addr[i]);
1647                printk(".\n");
1648        }
1649        /* set the Ethernet address */
1650        for (i=0; i < ETH_ALEN/2; i++)
1651                writereg(dev, PP_IA+i*2, dev->dev_addr[i*2] | (dev->dev_addr[i*2+1] << 8));
1652
1653        return 0;
1654}
1655
1656#ifdef MODULE
1657
1658static struct net_device dev_cs89x0;
1659
1660/*
1661 * Support the 'debug' module parm even if we're compiled for non-debug to 
1662 * avoid breaking someone's startup scripts 
1663 */
1664
1665static int io;
1666static int irq;
1667static int debug;
1668static char media[8];
1669static int duplex=-1;
1670
1671static int use_dma;                     /* These generate unused var warnings if ALLOW_DMA = 0 */
1672static int dma;
1673static int dmasize=16;                  /* or 64 */
1674
1675MODULE_PARM(io, "i");
1676MODULE_PARM(irq, "i");
1677MODULE_PARM(debug, "i");
1678MODULE_PARM(media, "c8");
1679MODULE_PARM(duplex, "i");
1680MODULE_PARM(dma , "i");
1681MODULE_PARM(dmasize , "i");
1682MODULE_PARM(use_dma , "i");
1683MODULE_PARM_DESC(io, "cs89x0 I/O base address");
1684MODULE_PARM_DESC(irq, "cs89x0 IRQ number");
1685#if DEBUGGING
1686MODULE_PARM_DESC(debug, "cs89x0 debug level (0-6)");
1687#else
1688MODULE_PARM_DESC(debug, "(ignored)");
1689#endif
1690MODULE_PARM_DESC(media, "Set cs89x0 adapter(s) media type(s) (rj45,bnc,aui)");
1691/* No other value than -1 for duplex seems to be currently interpreted */
1692MODULE_PARM_DESC(duplex, "(ignored)");
1693#if ALLOW_DMA
1694MODULE_PARM_DESC(dma , "cs89x0 ISA DMA channel; ignored if use_dma=0");
1695MODULE_PARM_DESC(dmasize , "cs89x0 DMA size in kB (16,64); ignored if use_dma=0");
1696MODULE_PARM_DESC(use_dma , "cs89x0 using DMA (0-1)");
1697#else
1698MODULE_PARM_DESC(dma , "(ignored)");
1699MODULE_PARM_DESC(dmasize , "(ignored)");
1700MODULE_PARM_DESC(use_dma , "(ignored)");
1701#endif
1702
1703MODULE_AUTHOR("Mike Cruse, Russwll Nelson <nelson@crynwr.com>, Andrew Morton <andrewm@uow.edu.au>");
1704MODULE_LICENSE("GPL");
1705
1706
1707/*
1708* media=t             - specify media type
1709   or media=2
1710   or media=aui
1711   or medai=auto
1712* duplex=0            - specify forced half/full/autonegotiate duplex
1713* debug=#             - debug level
1714
1715
1716* Default Chip Configuration:
1717  * DMA Burst = enabled
1718  * IOCHRDY Enabled = enabled
1719    * UseSA = enabled
1720    * CS8900 defaults to half-duplex if not specified on command-line
1721    * CS8920 defaults to autoneg if not specified on command-line
1722    * Use reset defaults for other config parameters
1723
1724* Assumptions:
1725  * media type specified is supported (circuitry is present)
1726  * if memory address is > 1MB, then required mem decode hw is present
1727  * if 10B-2, then agent other than driver will enable DC/DC converter
1728    (hw or software util)
1729
1730
1731*/
1732
1733int
1734init_module(void)
1735{
1736        struct net_local *lp;
1737        int ret = 0;
1738
1739#if DEBUGGING
1740        net_debug = debug;
1741#else
1742        debug = 0;
1743#endif
1744
1745        dev_cs89x0.irq = irq;
1746        dev_cs89x0.base_addr = io;
1747
1748        dev_cs89x0.init = cs89x0_probe;
1749        dev_cs89x0.priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
1750        if (dev_cs89x0.priv == 0) {
1751                printk(KERN_ERR "cs89x0.c: Out of memory.\n");
1752                return -ENOMEM;
1753        }
1754        memset(dev_cs89x0.priv, 0, sizeof(struct net_local));
1755        lp = (struct net_local *)dev_cs89x0.priv;
1756
1757#if ALLOW_DMA
1758        if (use_dma) {
1759                lp->use_dma = use_dma;
1760                lp->dma = dma;
1761                lp->dmasize = dmasize;
1762        }
1763#endif
1764
1765        spin_lock_init(&lp->lock);
1766
1767        /* boy, they'd better get these right */
1768        if (!strcmp(media, "rj45"))
1769                lp->adapter_cnf = A_CNF_MEDIA_10B_T | A_CNF_10B_T;
1770        else if (!strcmp(media, "aui"))
1771                lp->adapter_cnf = A_CNF_MEDIA_AUI   | A_CNF_AUI;
1772        else if (!strcmp(media, "bnc"))
1773                lp->adapter_cnf = A_CNF_MEDIA_10B_2 | A_CNF_10B_2;
1774        else
1775                lp->adapter_cnf = A_CNF_MEDIA_10B_T | A_CNF_10B_T;
1776
1777        if (duplex==-1)
1778                lp->auto_neg_cnf = AUTO_NEG_ENABLE;
1779
1780        if (io == 0) {
1781                printk(KERN_ERR "cs89x0.c: Module autoprobing not allowed.\n");
1782                printk(KERN_ERR "cs89x0.c: Append io=0xNNN\n");
1783                ret = -EPERM;
1784                goto out;
1785        }
1786
1787#if ALLOW_DMA
1788        if (use_dma && dmasize != 16 && dmasize != 64) {
1789                printk(KERN_ERR "cs89x0.c: dma size must be either 16K or 64K, not %dK\n", dmasize);
1790                ret = -EPERM;
1791                goto out;
1792        }
1793#endif
1794
1795        if (register_netdev(&dev_cs89x0) != 0) {
1796                printk(KERN_ERR "cs89x0.c: No card found at 0x%x\n", io);
1797                ret = -ENXIO;
1798                goto out;
1799        }
1800out:
1801        if (ret)
1802                kfree(dev_cs89x0.priv);
1803        return ret;
1804}
1805
1806void
1807cleanup_module(void)
1808{
1809        if (dev_cs89x0.priv != NULL) {
1810                /* Free up the private structure, or leak memory :-)  */
1811                unregister_netdev(&dev_cs89x0);
1812                outw(PP_ChipID, dev_cs89x0.base_addr + ADD_PORT);
1813                kfree(dev_cs89x0.priv);
1814                dev_cs89x0.priv = NULL; /* gets re-allocated by cs89x0_probe1 */
1815                /* If we don't do this, we can't re-insmod it later. */
1816                release_region(dev_cs89x0.base_addr, NETCARD_IO_EXTENT);
1817        }
1818}
1819#endif /* MODULE */
1820
1821/*
1822 * Local variables:
1823 *  version-control: t
1824 *  kept-new-versions: 5
1825 *  c-indent-level: 8
1826 *  tab-width: 8
1827 * End:
1828 *
1829 */
1830
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.