ia64/linux-2.6.18-xen.hg

annotate drivers/net/cs89x0.c @ 897:329ea0ccb344

balloon: try harder to balloon up under memory pressure.

Currently if the balloon driver is unable to increase the guest's
reservation it assumes the failure was due to reaching its full
allocation, gives up on the ballooning operation and records the limit
it reached as the "hard limit". The driver will not try again until
the target is set again (even to the same value).

However it is possible that ballooning has in fact failed due to
memory pressure in the host and therefore it is desirable to keep
attempting to reach the target in case memory becomes available. The
most likely scenario is that some guests are ballooning down while
others are ballooning up and therefore there is temporary memory
pressure while things stabilise. You would not expect a well behaved
toolstack to ask a domain to balloon to more than its allocation nor
would you expect it to deliberately over-commit memory by setting
balloon targets which exceed the total host memory.

This patch drops the concept of a hard limit and causes the balloon
driver to retry increasing the reservation on a timer in the same
manner as when decreasing the reservation.

Also if we partially succeed in increasing the reservation
(i.e. receive less pages than we asked for) then we may as well keep
those pages rather than returning them to Xen.

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