ia64/linux-2.6.18-xen.hg

annotate drivers/net/3c509.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 /* 3c509.c: A 3c509 EtherLink3 ethernet driver for linux. */
ian@0 2 /*
ian@0 3 Written 1993-2000 by Donald Becker.
ian@0 4
ian@0 5 Copyright 1994-2000 by Donald Becker.
ian@0 6 Copyright 1993 United States Government as represented by the
ian@0 7 Director, National Security Agency. This software may be used and
ian@0 8 distributed according to the terms of the GNU General Public License,
ian@0 9 incorporated herein by reference.
ian@0 10
ian@0 11 This driver is for the 3Com EtherLinkIII series.
ian@0 12
ian@0 13 The author may be reached as becker@scyld.com, or C/O
ian@0 14 Scyld Computing Corporation
ian@0 15 410 Severn Ave., Suite 210
ian@0 16 Annapolis MD 21403
ian@0 17
ian@0 18 Known limitations:
ian@0 19 Because of the way 3c509 ISA detection works it's difficult to predict
ian@0 20 a priori which of several ISA-mode cards will be detected first.
ian@0 21
ian@0 22 This driver does not use predictive interrupt mode, resulting in higher
ian@0 23 packet latency but lower overhead. If interrupts are disabled for an
ian@0 24 unusually long time it could also result in missed packets, but in
ian@0 25 practice this rarely happens.
ian@0 26
ian@0 27
ian@0 28 FIXES:
ian@0 29 Alan Cox: Removed the 'Unexpected interrupt' bug.
ian@0 30 Michael Meskes: Upgraded to Donald Becker's version 1.07.
ian@0 31 Alan Cox: Increased the eeprom delay. Regardless of
ian@0 32 what the docs say some people definitely
ian@0 33 get problems with lower (but in card spec)
ian@0 34 delays
ian@0 35 v1.10 4/21/97 Fixed module code so that multiple cards may be detected,
ian@0 36 other cleanups. -djb
ian@0 37 Andrea Arcangeli: Upgraded to Donald Becker's version 1.12.
ian@0 38 Rick Payne: Fixed SMP race condition
ian@0 39 v1.13 9/8/97 Made 'max_interrupt_work' an insmod-settable variable -djb
ian@0 40 v1.14 10/15/97 Avoided waiting..discard message for fast machines -djb
ian@0 41 v1.15 1/31/98 Faster recovery for Tx errors. -djb
ian@0 42 v1.16 2/3/98 Different ID port handling to avoid sound cards. -djb
ian@0 43 v1.18 12Mar2001 Andrew Morton <andrewm@uow.edu.au>
ian@0 44 - Avoid bogus detect of 3c590's (Andrzej Krzysztofowicz)
ian@0 45 - Reviewed against 1.18 from scyld.com
ian@0 46 v1.18a 17Nov2001 Jeff Garzik <jgarzik@pobox.com>
ian@0 47 - ethtool support
ian@0 48 v1.18b 1Mar2002 Zwane Mwaikambo <zwane@commfireservices.com>
ian@0 49 - Power Management support
ian@0 50 v1.18c 1Mar2002 David Ruggiero <jdr@farfalle.com>
ian@0 51 - Full duplex support
ian@0 52 v1.19 16Oct2002 Zwane Mwaikambo <zwane@linuxpower.ca>
ian@0 53 - Additional ethtool features
ian@0 54 v1.19a 28Oct2002 Davud Ruggiero <jdr@farfalle.com>
ian@0 55 - Increase *read_eeprom udelay to workaround oops with 2 cards.
ian@0 56 v1.19b 08Nov2002 Marc Zyngier <maz@wild-wind.fr.eu.org>
ian@0 57 - Introduce driver model for EISA cards.
ian@0 58 */
ian@0 59
ian@0 60 #define DRV_NAME "3c509"
ian@0 61 #define DRV_VERSION "1.19b"
ian@0 62 #define DRV_RELDATE "08Nov2002"
ian@0 63
ian@0 64 /* A few values that may be tweaked. */
ian@0 65
ian@0 66 /* Time in jiffies before concluding the transmitter is hung. */
ian@0 67 #define TX_TIMEOUT (400*HZ/1000)
ian@0 68 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
ian@0 69 static int max_interrupt_work = 10;
ian@0 70
ian@0 71 #include <linux/module.h>
ian@0 72 #ifdef CONFIG_MCA
ian@0 73 #include <linux/mca.h>
ian@0 74 #endif
ian@0 75 #include <linux/isapnp.h>
ian@0 76 #include <linux/string.h>
ian@0 77 #include <linux/interrupt.h>
ian@0 78 #include <linux/errno.h>
ian@0 79 #include <linux/in.h>
ian@0 80 #include <linux/slab.h>
ian@0 81 #include <linux/ioport.h>
ian@0 82 #include <linux/init.h>
ian@0 83 #include <linux/netdevice.h>
ian@0 84 #include <linux/etherdevice.h>
ian@0 85 #include <linux/pm.h>
ian@0 86 #include <linux/pm_legacy.h>
ian@0 87 #include <linux/skbuff.h>
ian@0 88 #include <linux/delay.h> /* for udelay() */
ian@0 89 #include <linux/spinlock.h>
ian@0 90 #include <linux/ethtool.h>
ian@0 91 #include <linux/device.h>
ian@0 92 #include <linux/eisa.h>
ian@0 93 #include <linux/bitops.h>
ian@0 94
ian@0 95 #include <asm/uaccess.h>
ian@0 96 #include <asm/io.h>
ian@0 97 #include <asm/irq.h>
ian@0 98
ian@0 99 static char versionA[] __initdata = DRV_NAME ".c:" DRV_VERSION " " DRV_RELDATE " becker@scyld.com\n";
ian@0 100 static char versionB[] __initdata = "http://www.scyld.com/network/3c509.html\n";
ian@0 101
ian@0 102 #if defined(CONFIG_PM) && (defined(CONFIG_MCA) || defined(CONFIG_EISA))
ian@0 103 #define EL3_SUSPEND
ian@0 104 #endif
ian@0 105
ian@0 106 #ifdef EL3_DEBUG
ian@0 107 static int el3_debug = EL3_DEBUG;
ian@0 108 #else
ian@0 109 static int el3_debug = 2;
ian@0 110 #endif
ian@0 111
ian@0 112 /* Used to do a global count of all the cards in the system. Must be
ian@0 113 * a global variable so that the mca/eisa probe routines can increment
ian@0 114 * it */
ian@0 115 static int el3_cards = 0;
ian@0 116
ian@0 117 /* To minimize the size of the driver source I only define operating
ian@0 118 constants if they are used several times. You'll need the manual
ian@0 119 anyway if you want to understand driver details. */
ian@0 120 /* Offsets from base I/O address. */
ian@0 121 #define EL3_DATA 0x00
ian@0 122 #define EL3_CMD 0x0e
ian@0 123 #define EL3_STATUS 0x0e
ian@0 124 #define EEPROM_READ 0x80
ian@0 125
ian@0 126 #define EL3_IO_EXTENT 16
ian@0 127
ian@0 128 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
ian@0 129
ian@0 130
ian@0 131 /* The top five bits written to EL3_CMD are a command, the lower
ian@0 132 11 bits are the parameter, if applicable. */
ian@0 133 enum c509cmd {
ian@0 134 TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
ian@0 135 RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11,
ian@0 136 TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
ian@0 137 FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
ian@0 138 SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
ian@0 139 SetTxThreshold = 18<<11, SetTxStart = 19<<11, StatsEnable = 21<<11,
ian@0 140 StatsDisable = 22<<11, StopCoax = 23<<11, PowerUp = 27<<11,
ian@0 141 PowerDown = 28<<11, PowerAuto = 29<<11};
ian@0 142
ian@0 143 enum c509status {
ian@0 144 IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
ian@0 145 TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
ian@0 146 IntReq = 0x0040, StatsFull = 0x0080, CmdBusy = 0x1000, };
ian@0 147
ian@0 148 /* The SetRxFilter command accepts the following classes: */
ian@0 149 enum RxFilter {
ian@0 150 RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
ian@0 151
ian@0 152 /* Register window 1 offsets, the window used in normal operation. */
ian@0 153 #define TX_FIFO 0x00
ian@0 154 #define RX_FIFO 0x00
ian@0 155 #define RX_STATUS 0x08
ian@0 156 #define TX_STATUS 0x0B
ian@0 157 #define TX_FREE 0x0C /* Remaining free bytes in Tx buffer. */
ian@0 158
ian@0 159 #define WN0_CONF_CTRL 0x04 /* Window 0: Configuration control register */
ian@0 160 #define WN0_ADDR_CONF 0x06 /* Window 0: Address configuration register */
ian@0 161 #define WN0_IRQ 0x08 /* Window 0: Set IRQ line in bits 12-15. */
ian@0 162 #define WN4_MEDIA 0x0A /* Window 4: Various transcvr/media bits. */
ian@0 163 #define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
ian@0 164 #define WN4_NETDIAG 0x06 /* Window 4: Net diagnostic */
ian@0 165 #define FD_ENABLE 0x8000 /* Enable full-duplex ("external loopback") */
ian@0 166
ian@0 167 /*
ian@0 168 * Must be a power of two (we use a binary and in the
ian@0 169 * circular queue)
ian@0 170 */
ian@0 171 #define SKB_QUEUE_SIZE 64
ian@0 172
ian@0 173 struct el3_private {
ian@0 174 struct net_device_stats stats;
ian@0 175 struct net_device *next_dev;
ian@0 176 spinlock_t lock;
ian@0 177 /* skb send-queue */
ian@0 178 int head, size;
ian@0 179 struct sk_buff *queue[SKB_QUEUE_SIZE];
ian@0 180 enum {
ian@0 181 EL3_MCA,
ian@0 182 EL3_PNP,
ian@0 183 EL3_EISA,
ian@0 184 } type; /* type of device */
ian@0 185 struct device *dev;
ian@0 186 };
ian@0 187 static int id_port __initdata = 0x110; /* Start with 0x110 to avoid new sound cards.*/
ian@0 188 static struct net_device *el3_root_dev;
ian@0 189
ian@0 190 static ushort id_read_eeprom(int index);
ian@0 191 static ushort read_eeprom(int ioaddr, int index);
ian@0 192 static int el3_open(struct net_device *dev);
ian@0 193 static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev);
ian@0 194 static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs);
ian@0 195 static void update_stats(struct net_device *dev);
ian@0 196 static struct net_device_stats *el3_get_stats(struct net_device *dev);
ian@0 197 static int el3_rx(struct net_device *dev);
ian@0 198 static int el3_close(struct net_device *dev);
ian@0 199 static void set_multicast_list(struct net_device *dev);
ian@0 200 static void el3_tx_timeout (struct net_device *dev);
ian@0 201 static void el3_down(struct net_device *dev);
ian@0 202 static void el3_up(struct net_device *dev);
ian@0 203 static struct ethtool_ops ethtool_ops;
ian@0 204 #ifdef EL3_SUSPEND
ian@0 205 static int el3_suspend(struct device *, pm_message_t);
ian@0 206 static int el3_resume(struct device *);
ian@0 207 #else
ian@0 208 #define el3_suspend NULL
ian@0 209 #define el3_resume NULL
ian@0 210 #endif
ian@0 211
ian@0 212
ian@0 213 /* generic device remove for all device types */
ian@0 214 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
ian@0 215 static int el3_device_remove (struct device *device);
ian@0 216 #endif
ian@0 217 #ifdef CONFIG_NET_POLL_CONTROLLER
ian@0 218 static void el3_poll_controller(struct net_device *dev);
ian@0 219 #endif
ian@0 220
ian@0 221 #ifdef CONFIG_EISA
ian@0 222 static struct eisa_device_id el3_eisa_ids[] = {
ian@0 223 { "TCM5092" },
ian@0 224 { "TCM5093" },
ian@0 225 { "TCM5095" },
ian@0 226 { "" }
ian@0 227 };
ian@0 228
ian@0 229 static int el3_eisa_probe (struct device *device);
ian@0 230
ian@0 231 static struct eisa_driver el3_eisa_driver = {
ian@0 232 .id_table = el3_eisa_ids,
ian@0 233 .driver = {
ian@0 234 .name = "3c509",
ian@0 235 .probe = el3_eisa_probe,
ian@0 236 .remove = __devexit_p (el3_device_remove),
ian@0 237 .suspend = el3_suspend,
ian@0 238 .resume = el3_resume,
ian@0 239 }
ian@0 240 };
ian@0 241 #endif
ian@0 242
ian@0 243 #ifdef CONFIG_MCA
ian@0 244 static int el3_mca_probe(struct device *dev);
ian@0 245
ian@0 246 static short el3_mca_adapter_ids[] __initdata = {
ian@0 247 0x627c,
ian@0 248 0x627d,
ian@0 249 0x62db,
ian@0 250 0x62f6,
ian@0 251 0x62f7,
ian@0 252 0x0000
ian@0 253 };
ian@0 254
ian@0 255 static char *el3_mca_adapter_names[] __initdata = {
ian@0 256 "3Com 3c529 EtherLink III (10base2)",
ian@0 257 "3Com 3c529 EtherLink III (10baseT)",
ian@0 258 "3Com 3c529 EtherLink III (test mode)",
ian@0 259 "3Com 3c529 EtherLink III (TP or coax)",
ian@0 260 "3Com 3c529 EtherLink III (TP)",
ian@0 261 NULL
ian@0 262 };
ian@0 263
ian@0 264 static struct mca_driver el3_mca_driver = {
ian@0 265 .id_table = el3_mca_adapter_ids,
ian@0 266 .driver = {
ian@0 267 .name = "3c529",
ian@0 268 .bus = &mca_bus_type,
ian@0 269 .probe = el3_mca_probe,
ian@0 270 .remove = __devexit_p(el3_device_remove),
ian@0 271 .suspend = el3_suspend,
ian@0 272 .resume = el3_resume,
ian@0 273 },
ian@0 274 };
ian@0 275 #endif /* CONFIG_MCA */
ian@0 276
ian@0 277 #if defined(__ISAPNP__)
ian@0 278 static struct isapnp_device_id el3_isapnp_adapters[] __initdata = {
ian@0 279 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
ian@0 280 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5090),
ian@0 281 (long) "3Com Etherlink III (TP)" },
ian@0 282 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
ian@0 283 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5091),
ian@0 284 (long) "3Com Etherlink III" },
ian@0 285 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
ian@0 286 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5094),
ian@0 287 (long) "3Com Etherlink III (combo)" },
ian@0 288 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
ian@0 289 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5095),
ian@0 290 (long) "3Com Etherlink III (TPO)" },
ian@0 291 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
ian@0 292 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5098),
ian@0 293 (long) "3Com Etherlink III (TPC)" },
ian@0 294 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
ian@0 295 ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_FUNCTION(0x80f7),
ian@0 296 (long) "3Com Etherlink III compatible" },
ian@0 297 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
ian@0 298 ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_FUNCTION(0x80f8),
ian@0 299 (long) "3Com Etherlink III compatible" },
ian@0 300 { } /* terminate list */
ian@0 301 };
ian@0 302
ian@0 303 static u16 el3_isapnp_phys_addr[8][3];
ian@0 304 static int nopnp;
ian@0 305 #endif /* __ISAPNP__ */
ian@0 306
ian@0 307 /* With the driver model introduction for EISA devices, both init
ian@0 308 * and cleanup have been split :
ian@0 309 * - EISA devices probe/remove starts in el3_eisa_probe/el3_device_remove
ian@0 310 * - MCA/ISA still use el3_probe
ian@0 311 *
ian@0 312 * Both call el3_common_init/el3_common_remove. */
ian@0 313
ian@0 314 static int __init el3_common_init(struct net_device *dev)
ian@0 315 {
ian@0 316 struct el3_private *lp = netdev_priv(dev);
ian@0 317 short i;
ian@0 318 int err;
ian@0 319
ian@0 320 spin_lock_init(&lp->lock);
ian@0 321
ian@0 322 if (dev->mem_start & 0x05) { /* xcvr codes 1/3/4/12 */
ian@0 323 dev->if_port = (dev->mem_start & 0x0f);
ian@0 324 } else { /* xcvr codes 0/8 */
ian@0 325 /* use eeprom value, but save user's full-duplex selection */
ian@0 326 dev->if_port |= (dev->mem_start & 0x08);
ian@0 327 }
ian@0 328
ian@0 329 /* The EL3-specific entries in the device structure. */
ian@0 330 dev->open = &el3_open;
ian@0 331 dev->hard_start_xmit = &el3_start_xmit;
ian@0 332 dev->stop = &el3_close;
ian@0 333 dev->get_stats = &el3_get_stats;
ian@0 334 dev->set_multicast_list = &set_multicast_list;
ian@0 335 dev->tx_timeout = el3_tx_timeout;
ian@0 336 dev->watchdog_timeo = TX_TIMEOUT;
ian@0 337 #ifdef CONFIG_NET_POLL_CONTROLLER
ian@0 338 dev->poll_controller = el3_poll_controller;
ian@0 339 #endif
ian@0 340 SET_ETHTOOL_OPS(dev, &ethtool_ops);
ian@0 341
ian@0 342 err = register_netdev(dev);
ian@0 343 if (err) {
ian@0 344 printk(KERN_ERR "Failed to register 3c5x9 at %#3.3lx, IRQ %d.\n",
ian@0 345 dev->base_addr, dev->irq);
ian@0 346 release_region(dev->base_addr, EL3_IO_EXTENT);
ian@0 347 return err;
ian@0 348 }
ian@0 349
ian@0 350 {
ian@0 351 const char *if_names[] = {"10baseT", "AUI", "undefined", "BNC"};
ian@0 352 printk("%s: 3c5x9 found at %#3.3lx, %s port, address ",
ian@0 353 dev->name, dev->base_addr,
ian@0 354 if_names[(dev->if_port & 0x03)]);
ian@0 355 }
ian@0 356
ian@0 357 /* Read in the station address. */
ian@0 358 for (i = 0; i < 6; i++)
ian@0 359 printk(" %2.2x", dev->dev_addr[i]);
ian@0 360 printk(", IRQ %d.\n", dev->irq);
ian@0 361
ian@0 362 if (el3_debug > 0)
ian@0 363 printk(KERN_INFO "%s" KERN_INFO "%s", versionA, versionB);
ian@0 364 return 0;
ian@0 365
ian@0 366 }
ian@0 367
ian@0 368 static void el3_common_remove (struct net_device *dev)
ian@0 369 {
ian@0 370 struct el3_private *lp = netdev_priv(dev);
ian@0 371
ian@0 372 (void) lp; /* Keep gcc quiet... */
ian@0 373 #if defined(__ISAPNP__)
ian@0 374 if (lp->type == EL3_PNP)
ian@0 375 pnp_device_detach(to_pnp_dev(lp->dev));
ian@0 376 #endif
ian@0 377
ian@0 378 unregister_netdev (dev);
ian@0 379 release_region(dev->base_addr, EL3_IO_EXTENT);
ian@0 380 free_netdev (dev);
ian@0 381 }
ian@0 382
ian@0 383 static int __init el3_probe(int card_idx)
ian@0 384 {
ian@0 385 struct net_device *dev;
ian@0 386 struct el3_private *lp;
ian@0 387 short lrs_state = 0xff, i;
ian@0 388 int ioaddr, irq, if_port;
ian@0 389 u16 phys_addr[3];
ian@0 390 static int current_tag;
ian@0 391 int err = -ENODEV;
ian@0 392 #if defined(__ISAPNP__)
ian@0 393 static int pnp_cards;
ian@0 394 struct pnp_dev *idev = NULL;
ian@0 395
ian@0 396 if (nopnp == 1)
ian@0 397 goto no_pnp;
ian@0 398
ian@0 399 for (i=0; el3_isapnp_adapters[i].vendor != 0; i++) {
ian@0 400 int j;
ian@0 401 while ((idev = pnp_find_dev(NULL,
ian@0 402 el3_isapnp_adapters[i].vendor,
ian@0 403 el3_isapnp_adapters[i].function,
ian@0 404 idev))) {
ian@0 405 if (pnp_device_attach(idev) < 0)
ian@0 406 continue;
ian@0 407 if (pnp_activate_dev(idev) < 0) {
ian@0 408 __again:
ian@0 409 pnp_device_detach(idev);
ian@0 410 continue;
ian@0 411 }
ian@0 412 if (!pnp_port_valid(idev, 0) || !pnp_irq_valid(idev, 0))
ian@0 413 goto __again;
ian@0 414 ioaddr = pnp_port_start(idev, 0);
ian@0 415 if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509 PnP")) {
ian@0 416 pnp_device_detach(idev);
ian@0 417 return -EBUSY;
ian@0 418 }
ian@0 419 irq = pnp_irq(idev, 0);
ian@0 420 if (el3_debug > 3)
ian@0 421 printk ("ISAPnP reports %s at i/o 0x%x, irq %d\n",
ian@0 422 (char*) el3_isapnp_adapters[i].driver_data, ioaddr, irq);
ian@0 423 EL3WINDOW(0);
ian@0 424 for (j = 0; j < 3; j++)
ian@0 425 el3_isapnp_phys_addr[pnp_cards][j] =
ian@0 426 phys_addr[j] =
ian@0 427 htons(read_eeprom(ioaddr, j));
ian@0 428 if_port = read_eeprom(ioaddr, 8) >> 14;
ian@0 429 dev = alloc_etherdev(sizeof (struct el3_private));
ian@0 430 if (!dev) {
ian@0 431 release_region(ioaddr, EL3_IO_EXTENT);
ian@0 432 pnp_device_detach(idev);
ian@0 433 return -ENOMEM;
ian@0 434 }
ian@0 435
ian@0 436 SET_MODULE_OWNER(dev);
ian@0 437 SET_NETDEV_DEV(dev, &idev->dev);
ian@0 438 pnp_cards++;
ian@0 439
ian@0 440 netdev_boot_setup_check(dev);
ian@0 441 goto found;
ian@0 442 }
ian@0 443 }
ian@0 444 no_pnp:
ian@0 445 #endif /* __ISAPNP__ */
ian@0 446
ian@0 447 /* Select an open I/O location at 0x1*0 to do contention select. */
ian@0 448 for ( ; id_port < 0x200; id_port += 0x10) {
ian@0 449 if (!request_region(id_port, 1, "3c509"))
ian@0 450 continue;
ian@0 451 outb(0x00, id_port);
ian@0 452 outb(0xff, id_port);
ian@0 453 if (inb(id_port) & 0x01){
ian@0 454 release_region(id_port, 1);
ian@0 455 break;
ian@0 456 } else
ian@0 457 release_region(id_port, 1);
ian@0 458 }
ian@0 459 if (id_port >= 0x200) {
ian@0 460 /* Rare -- do we really need a warning? */
ian@0 461 printk(" WARNING: No I/O port available for 3c509 activation.\n");
ian@0 462 return -ENODEV;
ian@0 463 }
ian@0 464
ian@0 465 /* Next check for all ISA bus boards by sending the ID sequence to the
ian@0 466 ID_PORT. We find cards past the first by setting the 'current_tag'
ian@0 467 on cards as they are found. Cards with their tag set will not
ian@0 468 respond to subsequent ID sequences. */
ian@0 469
ian@0 470 outb(0x00, id_port);
ian@0 471 outb(0x00, id_port);
ian@0 472 for(i = 0; i < 255; i++) {
ian@0 473 outb(lrs_state, id_port);
ian@0 474 lrs_state <<= 1;
ian@0 475 lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;
ian@0 476 }
ian@0 477
ian@0 478 /* For the first probe, clear all board's tag registers. */
ian@0 479 if (current_tag == 0)
ian@0 480 outb(0xd0, id_port);
ian@0 481 else /* Otherwise kill off already-found boards. */
ian@0 482 outb(0xd8, id_port);
ian@0 483
ian@0 484 if (id_read_eeprom(7) != 0x6d50) {
ian@0 485 return -ENODEV;
ian@0 486 }
ian@0 487
ian@0 488 /* Read in EEPROM data, which does contention-select.
ian@0 489 Only the lowest address board will stay "on-line".
ian@0 490 3Com got the byte order backwards. */
ian@0 491 for (i = 0; i < 3; i++) {
ian@0 492 phys_addr[i] = htons(id_read_eeprom(i));
ian@0 493 }
ian@0 494
ian@0 495 #if defined(__ISAPNP__)
ian@0 496 if (nopnp == 0) {
ian@0 497 /* The ISA PnP 3c509 cards respond to the ID sequence.
ian@0 498 This check is needed in order not to register them twice. */
ian@0 499 for (i = 0; i < pnp_cards; i++) {
ian@0 500 if (phys_addr[0] == el3_isapnp_phys_addr[i][0] &&
ian@0 501 phys_addr[1] == el3_isapnp_phys_addr[i][1] &&
ian@0 502 phys_addr[2] == el3_isapnp_phys_addr[i][2])
ian@0 503 {
ian@0 504 if (el3_debug > 3)
ian@0 505 printk("3c509 with address %02x %02x %02x %02x %02x %02x was found by ISAPnP\n",
ian@0 506 phys_addr[0] & 0xff, phys_addr[0] >> 8,
ian@0 507 phys_addr[1] & 0xff, phys_addr[1] >> 8,
ian@0 508 phys_addr[2] & 0xff, phys_addr[2] >> 8);
ian@0 509 /* Set the adaptor tag so that the next card can be found. */
ian@0 510 outb(0xd0 + ++current_tag, id_port);
ian@0 511 goto no_pnp;
ian@0 512 }
ian@0 513 }
ian@0 514 }
ian@0 515 #endif /* __ISAPNP__ */
ian@0 516
ian@0 517 {
ian@0 518 unsigned int iobase = id_read_eeprom(8);
ian@0 519 if_port = iobase >> 14;
ian@0 520 ioaddr = 0x200 + ((iobase & 0x1f) << 4);
ian@0 521 }
ian@0 522 irq = id_read_eeprom(9) >> 12;
ian@0 523
ian@0 524 dev = alloc_etherdev(sizeof (struct el3_private));
ian@0 525 if (!dev)
ian@0 526 return -ENOMEM;
ian@0 527
ian@0 528 SET_MODULE_OWNER(dev);
ian@0 529
ian@0 530 netdev_boot_setup_check(dev);
ian@0 531
ian@0 532 /* Set passed-in IRQ or I/O Addr. */
ian@0 533 if (dev->irq > 1 && dev->irq < 16)
ian@0 534 irq = dev->irq;
ian@0 535
ian@0 536 if (dev->base_addr) {
ian@0 537 if (dev->mem_end == 0x3c509 /* Magic key */
ian@0 538 && dev->base_addr >= 0x200 && dev->base_addr <= 0x3e0)
ian@0 539 ioaddr = dev->base_addr & 0x3f0;
ian@0 540 else if (dev->base_addr != ioaddr)
ian@0 541 goto out;
ian@0 542 }
ian@0 543
ian@0 544 if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509")) {
ian@0 545 err = -EBUSY;
ian@0 546 goto out;
ian@0 547 }
ian@0 548
ian@0 549 /* Set the adaptor tag so that the next card can be found. */
ian@0 550 outb(0xd0 + ++current_tag, id_port);
ian@0 551
ian@0 552 /* Activate the adaptor at the EEPROM location. */
ian@0 553 outb((ioaddr >> 4) | 0xe0, id_port);
ian@0 554
ian@0 555 EL3WINDOW(0);
ian@0 556 if (inw(ioaddr) != 0x6d50)
ian@0 557 goto out1;
ian@0 558
ian@0 559 /* Free the interrupt so that some other card can use it. */
ian@0 560 outw(0x0f00, ioaddr + WN0_IRQ);
ian@0 561
ian@0 562 #if defined(__ISAPNP__)
ian@0 563 found: /* PNP jumps here... */
ian@0 564 #endif /* __ISAPNP__ */
ian@0 565
ian@0 566 memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr));
ian@0 567 dev->base_addr = ioaddr;
ian@0 568 dev->irq = irq;
ian@0 569 dev->if_port = if_port;
ian@0 570 lp = netdev_priv(dev);
ian@0 571 #if defined(__ISAPNP__)
ian@0 572 lp->dev = &idev->dev;
ian@0 573 #endif
ian@0 574 err = el3_common_init(dev);
ian@0 575
ian@0 576 if (err)
ian@0 577 goto out1;
ian@0 578
ian@0 579 el3_cards++;
ian@0 580 lp->next_dev = el3_root_dev;
ian@0 581 el3_root_dev = dev;
ian@0 582 return 0;
ian@0 583
ian@0 584 out1:
ian@0 585 #if defined(__ISAPNP__)
ian@0 586 if (idev)
ian@0 587 pnp_device_detach(idev);
ian@0 588 #endif
ian@0 589 out:
ian@0 590 free_netdev(dev);
ian@0 591 return err;
ian@0 592 }
ian@0 593
ian@0 594 #ifdef CONFIG_MCA
ian@0 595 static int __init el3_mca_probe(struct device *device)
ian@0 596 {
ian@0 597 /* Based on Erik Nygren's (nygren@mit.edu) 3c529 patch,
ian@0 598 * heavily modified by Chris Beauregard
ian@0 599 * (cpbeaure@csclub.uwaterloo.ca) to support standard MCA
ian@0 600 * probing.
ian@0 601 *
ian@0 602 * redone for multi-card detection by ZP Gu (zpg@castle.net)
ian@0 603 * now works as a module */
ian@0 604
ian@0 605 struct el3_private *lp;
ian@0 606 short i;
ian@0 607 int ioaddr, irq, if_port;
ian@0 608 u16 phys_addr[3];
ian@0 609 struct net_device *dev = NULL;
ian@0 610 u_char pos4, pos5;
ian@0 611 struct mca_device *mdev = to_mca_device(device);
ian@0 612 int slot = mdev->slot;
ian@0 613 int err;
ian@0 614
ian@0 615 pos4 = mca_device_read_stored_pos(mdev, 4);
ian@0 616 pos5 = mca_device_read_stored_pos(mdev, 5);
ian@0 617
ian@0 618 ioaddr = ((short)((pos4&0xfc)|0x02)) << 8;
ian@0 619 irq = pos5 & 0x0f;
ian@0 620
ian@0 621
ian@0 622 printk("3c529: found %s at slot %d\n",
ian@0 623 el3_mca_adapter_names[mdev->index], slot + 1);
ian@0 624
ian@0 625 /* claim the slot */
ian@0 626 strncpy(mdev->name, el3_mca_adapter_names[mdev->index],
ian@0 627 sizeof(mdev->name));
ian@0 628 mca_device_set_claim(mdev, 1);
ian@0 629
ian@0 630 if_port = pos4 & 0x03;
ian@0 631
ian@0 632 irq = mca_device_transform_irq(mdev, irq);
ian@0 633 ioaddr = mca_device_transform_ioport(mdev, ioaddr);
ian@0 634 if (el3_debug > 2) {
ian@0 635 printk("3c529: irq %d ioaddr 0x%x ifport %d\n", irq, ioaddr, if_port);
ian@0 636 }
ian@0 637 EL3WINDOW(0);
ian@0 638 for (i = 0; i < 3; i++) {
ian@0 639 phys_addr[i] = htons(read_eeprom(ioaddr, i));
ian@0 640 }
ian@0 641
ian@0 642 dev = alloc_etherdev(sizeof (struct el3_private));
ian@0 643 if (dev == NULL) {
ian@0 644 release_region(ioaddr, EL3_IO_EXTENT);
ian@0 645 return -ENOMEM;
ian@0 646 }
ian@0 647
ian@0 648 SET_MODULE_OWNER(dev);
ian@0 649 netdev_boot_setup_check(dev);
ian@0 650
ian@0 651 memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr));
ian@0 652 dev->base_addr = ioaddr;
ian@0 653 dev->irq = irq;
ian@0 654 dev->if_port = if_port;
ian@0 655 lp = netdev_priv(dev);
ian@0 656 lp->dev = device;
ian@0 657 lp->type = EL3_MCA;
ian@0 658 device->driver_data = dev;
ian@0 659 err = el3_common_init(dev);
ian@0 660
ian@0 661 if (err) {
ian@0 662 device->driver_data = NULL;
ian@0 663 free_netdev(dev);
ian@0 664 return -ENOMEM;
ian@0 665 }
ian@0 666
ian@0 667 el3_cards++;
ian@0 668 return 0;
ian@0 669 }
ian@0 670
ian@0 671 #endif /* CONFIG_MCA */
ian@0 672
ian@0 673 #ifdef CONFIG_EISA
ian@0 674 static int __init el3_eisa_probe (struct device *device)
ian@0 675 {
ian@0 676 struct el3_private *lp;
ian@0 677 short i;
ian@0 678 int ioaddr, irq, if_port;
ian@0 679 u16 phys_addr[3];
ian@0 680 struct net_device *dev = NULL;
ian@0 681 struct eisa_device *edev;
ian@0 682 int err;
ian@0 683
ian@0 684 /* Yeepee, The driver framework is calling us ! */
ian@0 685 edev = to_eisa_device (device);
ian@0 686 ioaddr = edev->base_addr;
ian@0 687
ian@0 688 if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509"))
ian@0 689 return -EBUSY;
ian@0 690
ian@0 691 /* Change the register set to the configuration window 0. */
ian@0 692 outw(SelectWindow | 0, ioaddr + 0xC80 + EL3_CMD);
ian@0 693
ian@0 694 irq = inw(ioaddr + WN0_IRQ) >> 12;
ian@0 695 if_port = inw(ioaddr + 6)>>14;
ian@0 696 for (i = 0; i < 3; i++)
ian@0 697 phys_addr[i] = htons(read_eeprom(ioaddr, i));
ian@0 698
ian@0 699 /* Restore the "Product ID" to the EEPROM read register. */
ian@0 700 read_eeprom(ioaddr, 3);
ian@0 701
ian@0 702 dev = alloc_etherdev(sizeof (struct el3_private));
ian@0 703 if (dev == NULL) {
ian@0 704 release_region(ioaddr, EL3_IO_EXTENT);
ian@0 705 return -ENOMEM;
ian@0 706 }
ian@0 707
ian@0 708 SET_MODULE_OWNER(dev);
ian@0 709
ian@0 710 netdev_boot_setup_check(dev);
ian@0 711
ian@0 712 memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr));
ian@0 713 dev->base_addr = ioaddr;
ian@0 714 dev->irq = irq;
ian@0 715 dev->if_port = if_port;
ian@0 716 lp = netdev_priv(dev);
ian@0 717 lp->dev = device;
ian@0 718 lp->type = EL3_EISA;
ian@0 719 eisa_set_drvdata (edev, dev);
ian@0 720 err = el3_common_init(dev);
ian@0 721
ian@0 722 if (err) {
ian@0 723 eisa_set_drvdata (edev, NULL);
ian@0 724 free_netdev(dev);
ian@0 725 return err;
ian@0 726 }
ian@0 727
ian@0 728 el3_cards++;
ian@0 729 return 0;
ian@0 730 }
ian@0 731 #endif
ian@0 732
ian@0 733 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
ian@0 734 /* This remove works for all device types.
ian@0 735 *
ian@0 736 * The net dev must be stored in the driver_data field */
ian@0 737 static int __devexit el3_device_remove (struct device *device)
ian@0 738 {
ian@0 739 struct net_device *dev;
ian@0 740
ian@0 741 dev = device->driver_data;
ian@0 742
ian@0 743 el3_common_remove (dev);
ian@0 744 return 0;
ian@0 745 }
ian@0 746 #endif
ian@0 747
ian@0 748 /* Read a word from the EEPROM using the regular EEPROM access register.
ian@0 749 Assume that we are in register window zero.
ian@0 750 */
ian@0 751 static ushort read_eeprom(int ioaddr, int index)
ian@0 752 {
ian@0 753 outw(EEPROM_READ + index, ioaddr + 10);
ian@0 754 /* Pause for at least 162 us. for the read to take place.
ian@0 755 Some chips seem to require much longer */
ian@0 756 mdelay(2);
ian@0 757 return inw(ioaddr + 12);
ian@0 758 }
ian@0 759
ian@0 760 /* Read a word from the EEPROM when in the ISA ID probe state. */
ian@0 761 static ushort __init id_read_eeprom(int index)
ian@0 762 {
ian@0 763 int bit, word = 0;
ian@0 764
ian@0 765 /* Issue read command, and pause for at least 162 us. for it to complete.
ian@0 766 Assume extra-fast 16Mhz bus. */
ian@0 767 outb(EEPROM_READ + index, id_port);
ian@0 768
ian@0 769 /* Pause for at least 162 us. for the read to take place. */
ian@0 770 /* Some chips seem to require much longer */
ian@0 771 mdelay(4);
ian@0 772
ian@0 773 for (bit = 15; bit >= 0; bit--)
ian@0 774 word = (word << 1) + (inb(id_port) & 0x01);
ian@0 775
ian@0 776 if (el3_debug > 3)
ian@0 777 printk(" 3c509 EEPROM word %d %#4.4x.\n", index, word);
ian@0 778
ian@0 779 return word;
ian@0 780 }
ian@0 781
ian@0 782
ian@0 783 static int
ian@0 784 el3_open(struct net_device *dev)
ian@0 785 {
ian@0 786 int ioaddr = dev->base_addr;
ian@0 787 int i;
ian@0 788
ian@0 789 outw(TxReset, ioaddr + EL3_CMD);
ian@0 790 outw(RxReset, ioaddr + EL3_CMD);
ian@0 791 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
ian@0 792
ian@0 793 i = request_irq(dev->irq, &el3_interrupt, 0, dev->name, dev);
ian@0 794 if (i)
ian@0 795 return i;
ian@0 796
ian@0 797 EL3WINDOW(0);
ian@0 798 if (el3_debug > 3)
ian@0 799 printk("%s: Opening, IRQ %d status@%x %4.4x.\n", dev->name,
ian@0 800 dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS));
ian@0 801
ian@0 802 el3_up(dev);
ian@0 803
ian@0 804 if (el3_debug > 3)
ian@0 805 printk("%s: Opened 3c509 IRQ %d status %4.4x.\n",
ian@0 806 dev->name, dev->irq, inw(ioaddr + EL3_STATUS));
ian@0 807
ian@0 808 return 0;
ian@0 809 }
ian@0 810
ian@0 811 static void
ian@0 812 el3_tx_timeout (struct net_device *dev)
ian@0 813 {
ian@0 814 struct el3_private *lp = netdev_priv(dev);
ian@0 815 int ioaddr = dev->base_addr;
ian@0 816
ian@0 817 /* Transmitter timeout, serious problems. */
ian@0 818 printk("%s: transmit timed out, Tx_status %2.2x status %4.4x "
ian@0 819 "Tx FIFO room %d.\n",
ian@0 820 dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS),
ian@0 821 inw(ioaddr + TX_FREE));
ian@0 822 lp->stats.tx_errors++;
ian@0 823 dev->trans_start = jiffies;
ian@0 824 /* Issue TX_RESET and TX_START commands. */
ian@0 825 outw(TxReset, ioaddr + EL3_CMD);
ian@0 826 outw(TxEnable, ioaddr + EL3_CMD);
ian@0 827 netif_wake_queue(dev);
ian@0 828 }
ian@0 829
ian@0 830
ian@0 831 static int
ian@0 832 el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
ian@0 833 {
ian@0 834 struct el3_private *lp = netdev_priv(dev);
ian@0 835 int ioaddr = dev->base_addr;
ian@0 836 unsigned long flags;
ian@0 837
ian@0 838 netif_stop_queue (dev);
ian@0 839
ian@0 840 lp->stats.tx_bytes += skb->len;
ian@0 841
ian@0 842 if (el3_debug > 4) {
ian@0 843 printk("%s: el3_start_xmit(length = %u) called, status %4.4x.\n",
ian@0 844 dev->name, skb->len, inw(ioaddr + EL3_STATUS));
ian@0 845 }
ian@0 846 #if 0
ian@0 847 #ifndef final_version
ian@0 848 { /* Error-checking code, delete someday. */
ian@0 849 ushort status = inw(ioaddr + EL3_STATUS);
ian@0 850 if (status & 0x0001 /* IRQ line active, missed one. */
ian@0 851 && inw(ioaddr + EL3_STATUS) & 1) { /* Make sure. */
ian@0 852 printk("%s: Missed interrupt, status then %04x now %04x"
ian@0 853 " Tx %2.2x Rx %4.4x.\n", dev->name, status,
ian@0 854 inw(ioaddr + EL3_STATUS), inb(ioaddr + TX_STATUS),
ian@0 855 inw(ioaddr + RX_STATUS));
ian@0 856 /* Fake interrupt trigger by masking, acknowledge interrupts. */
ian@0 857 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
ian@0 858 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
ian@0 859 ioaddr + EL3_CMD);
ian@0 860 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
ian@0 861 }
ian@0 862 }
ian@0 863 #endif
ian@0 864 #endif
ian@0 865 /*
ian@0 866 * We lock the driver against other processors. Note
ian@0 867 * we don't need to lock versus the IRQ as we suspended
ian@0 868 * that. This means that we lose the ability to take
ian@0 869 * an RX during a TX upload. That sucks a bit with SMP
ian@0 870 * on an original 3c509 (2K buffer)
ian@0 871 *
ian@0 872 * Using disable_irq stops us crapping on other
ian@0 873 * time sensitive devices.
ian@0 874 */
ian@0 875
ian@0 876 spin_lock_irqsave(&lp->lock, flags);
ian@0 877
ian@0 878 /* Put out the doubleword header... */
ian@0 879 outw(skb->len, ioaddr + TX_FIFO);
ian@0 880 outw(0x00, ioaddr + TX_FIFO);
ian@0 881 /* ... and the packet rounded to a doubleword. */
ian@0 882 #ifdef __powerpc__
ian@0 883 outsl_ns(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
ian@0 884 #else
ian@0 885 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
ian@0 886 #endif
ian@0 887
ian@0 888 dev->trans_start = jiffies;
ian@0 889 if (inw(ioaddr + TX_FREE) > 1536)
ian@0 890 netif_start_queue(dev);
ian@0 891 else
ian@0 892 /* Interrupt us when the FIFO has room for max-sized packet. */
ian@0 893 outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
ian@0 894
ian@0 895 spin_unlock_irqrestore(&lp->lock, flags);
ian@0 896
ian@0 897 dev_kfree_skb (skb);
ian@0 898
ian@0 899 /* Clear the Tx status stack. */
ian@0 900 {
ian@0 901 short tx_status;
ian@0 902 int i = 4;
ian@0 903
ian@0 904 while (--i > 0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
ian@0 905 if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
ian@0 906 if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
ian@0 907 if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
ian@0 908 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
ian@0 909 }
ian@0 910 }
ian@0 911 return 0;
ian@0 912 }
ian@0 913
ian@0 914 /* The EL3 interrupt handler. */
ian@0 915 static irqreturn_t
ian@0 916 el3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
ian@0 917 {
ian@0 918 struct net_device *dev = (struct net_device *)dev_id;
ian@0 919 struct el3_private *lp;
ian@0 920 int ioaddr, status;
ian@0 921 int i = max_interrupt_work;
ian@0 922
ian@0 923 if (dev == NULL) {
ian@0 924 printk ("el3_interrupt(): irq %d for unknown device.\n", irq);
ian@0 925 return IRQ_NONE;
ian@0 926 }
ian@0 927
ian@0 928 lp = netdev_priv(dev);
ian@0 929 spin_lock(&lp->lock);
ian@0 930
ian@0 931 ioaddr = dev->base_addr;
ian@0 932
ian@0 933 if (el3_debug > 4) {
ian@0 934 status = inw(ioaddr + EL3_STATUS);
ian@0 935 printk("%s: interrupt, status %4.4x.\n", dev->name, status);
ian@0 936 }
ian@0 937
ian@0 938 while ((status = inw(ioaddr + EL3_STATUS)) &
ian@0 939 (IntLatch | RxComplete | StatsFull)) {
ian@0 940
ian@0 941 if (status & RxComplete)
ian@0 942 el3_rx(dev);
ian@0 943
ian@0 944 if (status & TxAvailable) {
ian@0 945 if (el3_debug > 5)
ian@0 946 printk(" TX room bit was handled.\n");
ian@0 947 /* There's room in the FIFO for a full-sized packet. */
ian@0 948 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
ian@0 949 netif_wake_queue (dev);
ian@0 950 }
ian@0 951 if (status & (AdapterFailure | RxEarly | StatsFull | TxComplete)) {
ian@0 952 /* Handle all uncommon interrupts. */
ian@0 953 if (status & StatsFull) /* Empty statistics. */
ian@0 954 update_stats(dev);
ian@0 955 if (status & RxEarly) { /* Rx early is unused. */
ian@0 956 el3_rx(dev);
ian@0 957 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
ian@0 958 }
ian@0 959 if (status & TxComplete) { /* Really Tx error. */
ian@0 960 struct el3_private *lp = netdev_priv(dev);
ian@0 961 short tx_status;
ian@0 962 int i = 4;
ian@0 963
ian@0 964 while (--i>0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
ian@0 965 if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
ian@0 966 if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
ian@0 967 if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
ian@0 968 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
ian@0 969 }
ian@0 970 }
ian@0 971 if (status & AdapterFailure) {
ian@0 972 /* Adapter failure requires Rx reset and reinit. */
ian@0 973 outw(RxReset, ioaddr + EL3_CMD);
ian@0 974 /* Set the Rx filter to the current state. */
ian@0 975 outw(SetRxFilter | RxStation | RxBroadcast
ian@0 976 | (dev->flags & IFF_ALLMULTI ? RxMulticast : 0)
ian@0 977 | (dev->flags & IFF_PROMISC ? RxProm : 0),
ian@0 978 ioaddr + EL3_CMD);
ian@0 979 outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
ian@0 980 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
ian@0 981 }
ian@0 982 }
ian@0 983
ian@0 984 if (--i < 0) {
ian@0 985 printk("%s: Infinite loop in interrupt, status %4.4x.\n",
ian@0 986 dev->name, status);
ian@0 987 /* Clear all interrupts. */
ian@0 988 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
ian@0 989 break;
ian@0 990 }
ian@0 991 /* Acknowledge the IRQ. */
ian@0 992 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD); /* Ack IRQ */
ian@0 993 }
ian@0 994
ian@0 995 if (el3_debug > 4) {
ian@0 996 printk("%s: exiting interrupt, status %4.4x.\n", dev->name,
ian@0 997 inw(ioaddr + EL3_STATUS));
ian@0 998 }
ian@0 999 spin_unlock(&lp->lock);
ian@0 1000 return IRQ_HANDLED;
ian@0 1001 }
ian@0 1002
ian@0 1003
ian@0 1004 #ifdef CONFIG_NET_POLL_CONTROLLER
ian@0 1005 /*
ian@0 1006 * Polling receive - used by netconsole and other diagnostic tools
ian@0 1007 * to allow network i/o with interrupts disabled.
ian@0 1008 */
ian@0 1009 static void el3_poll_controller(struct net_device *dev)
ian@0 1010 {
ian@0 1011 disable_irq(dev->irq);
ian@0 1012 el3_interrupt(dev->irq, dev, NULL);
ian@0 1013 enable_irq(dev->irq);
ian@0 1014 }
ian@0 1015 #endif
ian@0 1016
ian@0 1017 static struct net_device_stats *
ian@0 1018 el3_get_stats(struct net_device *dev)
ian@0 1019 {
ian@0 1020 struct el3_private *lp = netdev_priv(dev);
ian@0 1021 unsigned long flags;
ian@0 1022
ian@0 1023 /*
ian@0 1024 * This is fast enough not to bother with disable IRQ
ian@0 1025 * stuff.
ian@0 1026 */
ian@0 1027
ian@0 1028 spin_lock_irqsave(&lp->lock, flags);
ian@0 1029 update_stats(dev);
ian@0 1030 spin_unlock_irqrestore(&lp->lock, flags);
ian@0 1031 return &lp->stats;
ian@0 1032 }
ian@0 1033
ian@0 1034 /* Update statistics. We change to register window 6, so this should be run
ian@0 1035 single-threaded if the device is active. This is expected to be a rare
ian@0 1036 operation, and it's simpler for the rest of the driver to assume that
ian@0 1037 window 1 is always valid rather than use a special window-state variable.
ian@0 1038 */
ian@0 1039 static void update_stats(struct net_device *dev)
ian@0 1040 {
ian@0 1041 struct el3_private *lp = netdev_priv(dev);
ian@0 1042 int ioaddr = dev->base_addr;
ian@0 1043
ian@0 1044 if (el3_debug > 5)
ian@0 1045 printk(" Updating the statistics.\n");
ian@0 1046 /* Turn off statistics updates while reading. */
ian@0 1047 outw(StatsDisable, ioaddr + EL3_CMD);
ian@0 1048 /* Switch to the stats window, and read everything. */
ian@0 1049 EL3WINDOW(6);
ian@0 1050 lp->stats.tx_carrier_errors += inb(ioaddr + 0);
ian@0 1051 lp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
ian@0 1052 /* Multiple collisions. */ inb(ioaddr + 2);
ian@0 1053 lp->stats.collisions += inb(ioaddr + 3);
ian@0 1054 lp->stats.tx_window_errors += inb(ioaddr + 4);
ian@0 1055 lp->stats.rx_fifo_errors += inb(ioaddr + 5);
ian@0 1056 lp->stats.tx_packets += inb(ioaddr + 6);
ian@0 1057 /* Rx packets */ inb(ioaddr + 7);
ian@0 1058 /* Tx deferrals */ inb(ioaddr + 8);
ian@0 1059 inw(ioaddr + 10); /* Total Rx and Tx octets. */
ian@0 1060 inw(ioaddr + 12);
ian@0 1061
ian@0 1062 /* Back to window 1, and turn statistics back on. */
ian@0 1063 EL3WINDOW(1);
ian@0 1064 outw(StatsEnable, ioaddr + EL3_CMD);
ian@0 1065 return;
ian@0 1066 }
ian@0 1067
ian@0 1068 static int
ian@0 1069 el3_rx(struct net_device *dev)
ian@0 1070 {
ian@0 1071 struct el3_private *lp = netdev_priv(dev);
ian@0 1072 int ioaddr = dev->base_addr;
ian@0 1073 short rx_status;
ian@0 1074
ian@0 1075 if (el3_debug > 5)
ian@0 1076 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
ian@0 1077 inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
ian@0 1078 while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
ian@0 1079 if (rx_status & 0x4000) { /* Error, update stats. */
ian@0 1080 short error = rx_status & 0x3800;
ian@0 1081
ian@0 1082 outw(RxDiscard, ioaddr + EL3_CMD);
ian@0 1083 lp->stats.rx_errors++;
ian@0 1084 switch (error) {
ian@0 1085 case 0x0000: lp->stats.rx_over_errors++; break;
ian@0 1086 case 0x0800: lp->stats.rx_length_errors++; break;
ian@0 1087 case 0x1000: lp->stats.rx_frame_errors++; break;
ian@0 1088 case 0x1800: lp->stats.rx_length_errors++; break;
ian@0 1089 case 0x2000: lp->stats.rx_frame_errors++; break;
ian@0 1090 case 0x2800: lp->stats.rx_crc_errors++; break;
ian@0 1091 }
ian@0 1092 } else {
ian@0 1093 short pkt_len = rx_status & 0x7ff;
ian@0 1094 struct sk_buff *skb;
ian@0 1095
ian@0 1096 skb = dev_alloc_skb(pkt_len+5);
ian@0 1097 lp->stats.rx_bytes += pkt_len;
ian@0 1098 if (el3_debug > 4)
ian@0 1099 printk("Receiving packet size %d status %4.4x.\n",
ian@0 1100 pkt_len, rx_status);
ian@0 1101 if (skb != NULL) {
ian@0 1102 skb->dev = dev;
ian@0 1103 skb_reserve(skb, 2); /* Align IP on 16 byte */
ian@0 1104
ian@0 1105 /* 'skb->data' points to the start of sk_buff data area. */
ian@0 1106 #ifdef __powerpc__
ian@0 1107 insl_ns(ioaddr+RX_FIFO, skb_put(skb,pkt_len),
ian@0 1108 (pkt_len + 3) >> 2);
ian@0 1109 #else
ian@0 1110 insl(ioaddr + RX_FIFO, skb_put(skb,pkt_len),
ian@0 1111 (pkt_len + 3) >> 2);
ian@0 1112 #endif
ian@0 1113
ian@0 1114 outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
ian@0 1115 skb->protocol = eth_type_trans(skb,dev);
ian@0 1116 netif_rx(skb);
ian@0 1117 dev->last_rx = jiffies;
ian@0 1118 lp->stats.rx_packets++;
ian@0 1119 continue;
ian@0 1120 }
ian@0 1121 outw(RxDiscard, ioaddr + EL3_CMD);
ian@0 1122 lp->stats.rx_dropped++;
ian@0 1123 if (el3_debug)
ian@0 1124 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
ian@0 1125 dev->name, pkt_len);
ian@0 1126 }
ian@0 1127 inw(ioaddr + EL3_STATUS); /* Delay. */
ian@0 1128 while (inw(ioaddr + EL3_STATUS) & 0x1000)
ian@0 1129 printk(KERN_DEBUG " Waiting for 3c509 to discard packet, status %x.\n",
ian@0 1130 inw(ioaddr + EL3_STATUS) );
ian@0 1131 }
ian@0 1132
ian@0 1133 return 0;
ian@0 1134 }
ian@0 1135
ian@0 1136 /*
ian@0 1137 * Set or clear the multicast filter for this adaptor.
ian@0 1138 */
ian@0 1139 static void
ian@0 1140 set_multicast_list(struct net_device *dev)
ian@0 1141 {
ian@0 1142 unsigned long flags;
ian@0 1143 struct el3_private *lp = netdev_priv(dev);
ian@0 1144 int ioaddr = dev->base_addr;
ian@0 1145
ian@0 1146 if (el3_debug > 1) {
ian@0 1147 static int old;
ian@0 1148 if (old != dev->mc_count) {
ian@0 1149 old = dev->mc_count;
ian@0 1150 printk("%s: Setting Rx mode to %d addresses.\n", dev->name, dev->mc_count);
ian@0 1151 }
ian@0 1152 }
ian@0 1153 spin_lock_irqsave(&lp->lock, flags);
ian@0 1154 if (dev->flags&IFF_PROMISC) {
ian@0 1155 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
ian@0 1156 ioaddr + EL3_CMD);
ian@0 1157 }
ian@0 1158 else if (dev->mc_count || (dev->flags&IFF_ALLMULTI)) {
ian@0 1159 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast, ioaddr + EL3_CMD);
ian@0 1160 }
ian@0 1161 else
ian@0 1162 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
ian@0 1163 spin_unlock_irqrestore(&lp->lock, flags);
ian@0 1164 }
ian@0 1165
ian@0 1166 static int
ian@0 1167 el3_close(struct net_device *dev)
ian@0 1168 {
ian@0 1169 int ioaddr = dev->base_addr;
ian@0 1170 struct el3_private *lp = netdev_priv(dev);
ian@0 1171
ian@0 1172 if (el3_debug > 2)
ian@0 1173 printk("%s: Shutting down ethercard.\n", dev->name);
ian@0 1174
ian@0 1175 el3_down(dev);
ian@0 1176
ian@0 1177 free_irq(dev->irq, dev);
ian@0 1178 /* Switching back to window 0 disables the IRQ. */
ian@0 1179 EL3WINDOW(0);
ian@0 1180 if (lp->type != EL3_EISA) {
ian@0 1181 /* But we explicitly zero the IRQ line select anyway. Don't do
ian@0 1182 * it on EISA cards, it prevents the module from getting an
ian@0 1183 * IRQ after unload+reload... */
ian@0 1184 outw(0x0f00, ioaddr + WN0_IRQ);
ian@0 1185 }
ian@0 1186
ian@0 1187 return 0;
ian@0 1188 }
ian@0 1189
ian@0 1190 static int
ian@0 1191 el3_link_ok(struct net_device *dev)
ian@0 1192 {
ian@0 1193 int ioaddr = dev->base_addr;
ian@0 1194 u16 tmp;
ian@0 1195
ian@0 1196 EL3WINDOW(4);
ian@0 1197 tmp = inw(ioaddr + WN4_MEDIA);
ian@0 1198 EL3WINDOW(1);
ian@0 1199 return tmp & (1<<11);
ian@0 1200 }
ian@0 1201
ian@0 1202 static int
ian@0 1203 el3_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
ian@0 1204 {
ian@0 1205 u16 tmp;
ian@0 1206 int ioaddr = dev->base_addr;
ian@0 1207
ian@0 1208 EL3WINDOW(0);
ian@0 1209 /* obtain current transceiver via WN4_MEDIA? */
ian@0 1210 tmp = inw(ioaddr + WN0_ADDR_CONF);
ian@0 1211 ecmd->transceiver = XCVR_INTERNAL;
ian@0 1212 switch (tmp >> 14) {
ian@0 1213 case 0:
ian@0 1214 ecmd->port = PORT_TP;
ian@0 1215 break;
ian@0 1216 case 1:
ian@0 1217 ecmd->port = PORT_AUI;
ian@0 1218 ecmd->transceiver = XCVR_EXTERNAL;
ian@0 1219 break;
ian@0 1220 case 3:
ian@0 1221 ecmd->port = PORT_BNC;
ian@0 1222 default:
ian@0 1223 break;
ian@0 1224 }
ian@0 1225
ian@0 1226 ecmd->duplex = DUPLEX_HALF;
ian@0 1227 ecmd->supported = 0;
ian@0 1228 tmp = inw(ioaddr + WN0_CONF_CTRL);
ian@0 1229 if (tmp & (1<<13))
ian@0 1230 ecmd->supported |= SUPPORTED_AUI;
ian@0 1231 if (tmp & (1<<12))
ian@0 1232 ecmd->supported |= SUPPORTED_BNC;
ian@0 1233 if (tmp & (1<<9)) {
ian@0 1234 ecmd->supported |= SUPPORTED_TP | SUPPORTED_10baseT_Half |
ian@0 1235 SUPPORTED_10baseT_Full; /* hmm... */
ian@0 1236 EL3WINDOW(4);
ian@0 1237 tmp = inw(ioaddr + WN4_NETDIAG);
ian@0 1238 if (tmp & FD_ENABLE)
ian@0 1239 ecmd->duplex = DUPLEX_FULL;
ian@0 1240 }
ian@0 1241
ian@0 1242 ecmd->speed = SPEED_10;
ian@0 1243 EL3WINDOW(1);
ian@0 1244 return 0;
ian@0 1245 }
ian@0 1246
ian@0 1247 static int
ian@0 1248 el3_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
ian@0 1249 {
ian@0 1250 u16 tmp;
ian@0 1251 int ioaddr = dev->base_addr;
ian@0 1252
ian@0 1253 if (ecmd->speed != SPEED_10)
ian@0 1254 return -EINVAL;
ian@0 1255 if ((ecmd->duplex != DUPLEX_HALF) && (ecmd->duplex != DUPLEX_FULL))
ian@0 1256 return -EINVAL;
ian@0 1257 if ((ecmd->transceiver != XCVR_INTERNAL) && (ecmd->transceiver != XCVR_EXTERNAL))
ian@0 1258 return -EINVAL;
ian@0 1259
ian@0 1260 /* change XCVR type */
ian@0 1261 EL3WINDOW(0);
ian@0 1262 tmp = inw(ioaddr + WN0_ADDR_CONF);
ian@0 1263 switch (ecmd->port) {
ian@0 1264 case PORT_TP:
ian@0 1265 tmp &= ~(3<<14);
ian@0 1266 dev->if_port = 0;
ian@0 1267 break;
ian@0 1268 case PORT_AUI:
ian@0 1269 tmp |= (1<<14);
ian@0 1270 dev->if_port = 1;
ian@0 1271 break;
ian@0 1272 case PORT_BNC:
ian@0 1273 tmp |= (3<<14);
ian@0 1274 dev->if_port = 3;
ian@0 1275 break;
ian@0 1276 default:
ian@0 1277 return -EINVAL;
ian@0 1278 }
ian@0 1279
ian@0 1280 outw(tmp, ioaddr + WN0_ADDR_CONF);
ian@0 1281 if (dev->if_port == 3) {
ian@0 1282 /* fire up the DC-DC convertor if BNC gets enabled */
ian@0 1283 tmp = inw(ioaddr + WN0_ADDR_CONF);
ian@0 1284 if (tmp & (3 << 14)) {
ian@0 1285 outw(StartCoax, ioaddr + EL3_CMD);
ian@0 1286 udelay(800);
ian@0 1287 } else
ian@0 1288 return -EIO;
ian@0 1289 }
ian@0 1290
ian@0 1291 EL3WINDOW(4);
ian@0 1292 tmp = inw(ioaddr + WN4_NETDIAG);
ian@0 1293 if (ecmd->duplex == DUPLEX_FULL)
ian@0 1294 tmp |= FD_ENABLE;
ian@0 1295 else
ian@0 1296 tmp &= ~FD_ENABLE;
ian@0 1297 outw(tmp, ioaddr + WN4_NETDIAG);
ian@0 1298 EL3WINDOW(1);
ian@0 1299
ian@0 1300 return 0;
ian@0 1301 }
ian@0 1302
ian@0 1303 static void el3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
ian@0 1304 {
ian@0 1305 strcpy(info->driver, DRV_NAME);
ian@0 1306 strcpy(info->version, DRV_VERSION);
ian@0 1307 }
ian@0 1308
ian@0 1309 static int el3_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
ian@0 1310 {
ian@0 1311 struct el3_private *lp = netdev_priv(dev);
ian@0 1312 int ret;
ian@0 1313
ian@0 1314 spin_lock_irq(&lp->lock);
ian@0 1315 ret = el3_netdev_get_ecmd(dev, ecmd);
ian@0 1316 spin_unlock_irq(&lp->lock);
ian@0 1317 return ret;
ian@0 1318 }
ian@0 1319
ian@0 1320 static int el3_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
ian@0 1321 {
ian@0 1322 struct el3_private *lp = netdev_priv(dev);
ian@0 1323 int ret;
ian@0 1324
ian@0 1325 spin_lock_irq(&lp->lock);
ian@0 1326 ret = el3_netdev_set_ecmd(dev, ecmd);
ian@0 1327 spin_unlock_irq(&lp->lock);
ian@0 1328 return ret;
ian@0 1329 }
ian@0 1330
ian@0 1331 static u32 el3_get_link(struct net_device *dev)
ian@0 1332 {
ian@0 1333 struct el3_private *lp = netdev_priv(dev);
ian@0 1334 u32 ret;
ian@0 1335
ian@0 1336 spin_lock_irq(&lp->lock);
ian@0 1337 ret = el3_link_ok(dev);
ian@0 1338 spin_unlock_irq(&lp->lock);
ian@0 1339 return ret;
ian@0 1340 }
ian@0 1341
ian@0 1342 static u32 el3_get_msglevel(struct net_device *dev)
ian@0 1343 {
ian@0 1344 return el3_debug;
ian@0 1345 }
ian@0 1346
ian@0 1347 static void el3_set_msglevel(struct net_device *dev, u32 v)
ian@0 1348 {
ian@0 1349 el3_debug = v;
ian@0 1350 }
ian@0 1351
ian@0 1352 static struct ethtool_ops ethtool_ops = {
ian@0 1353 .get_drvinfo = el3_get_drvinfo,
ian@0 1354 .get_settings = el3_get_settings,
ian@0 1355 .set_settings = el3_set_settings,
ian@0 1356 .get_link = el3_get_link,
ian@0 1357 .get_msglevel = el3_get_msglevel,
ian@0 1358 .set_msglevel = el3_set_msglevel,
ian@0 1359 };
ian@0 1360
ian@0 1361 static void
ian@0 1362 el3_down(struct net_device *dev)
ian@0 1363 {
ian@0 1364 int ioaddr = dev->base_addr;
ian@0 1365
ian@0 1366 netif_stop_queue(dev);
ian@0 1367
ian@0 1368 /* Turn off statistics ASAP. We update lp->stats below. */
ian@0 1369 outw(StatsDisable, ioaddr + EL3_CMD);
ian@0 1370
ian@0 1371 /* Disable the receiver and transmitter. */
ian@0 1372 outw(RxDisable, ioaddr + EL3_CMD);
ian@0 1373 outw(TxDisable, ioaddr + EL3_CMD);
ian@0 1374
ian@0 1375 if (dev->if_port == 3)
ian@0 1376 /* Turn off thinnet power. Green! */
ian@0 1377 outw(StopCoax, ioaddr + EL3_CMD);
ian@0 1378 else if (dev->if_port == 0) {
ian@0 1379 /* Disable link beat and jabber, if_port may change here next open(). */
ian@0 1380 EL3WINDOW(4);
ian@0 1381 outw(inw(ioaddr + WN4_MEDIA) & ~MEDIA_TP, ioaddr + WN4_MEDIA);
ian@0 1382 }
ian@0 1383
ian@0 1384 outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
ian@0 1385
ian@0 1386 update_stats(dev);
ian@0 1387 }
ian@0 1388
ian@0 1389 static void
ian@0 1390 el3_up(struct net_device *dev)
ian@0 1391 {
ian@0 1392 int i, sw_info, net_diag;
ian@0 1393 int ioaddr = dev->base_addr;
ian@0 1394
ian@0 1395 /* Activating the board required and does no harm otherwise */
ian@0 1396 outw(0x0001, ioaddr + 4);
ian@0 1397
ian@0 1398 /* Set the IRQ line. */
ian@0 1399 outw((dev->irq << 12) | 0x0f00, ioaddr + WN0_IRQ);
ian@0 1400
ian@0 1401 /* Set the station address in window 2 each time opened. */
ian@0 1402 EL3WINDOW(2);
ian@0 1403
ian@0 1404 for (i = 0; i < 6; i++)
ian@0 1405 outb(dev->dev_addr[i], ioaddr + i);
ian@0 1406
ian@0 1407 if ((dev->if_port & 0x03) == 3) /* BNC interface */
ian@0 1408 /* Start the thinnet transceiver. We should really wait 50ms...*/
ian@0 1409 outw(StartCoax, ioaddr + EL3_CMD);
ian@0 1410 else if ((dev->if_port & 0x03) == 0) { /* 10baseT interface */
ian@0 1411 /* Combine secondary sw_info word (the adapter level) and primary
ian@0 1412 sw_info word (duplex setting plus other useless bits) */
ian@0 1413 EL3WINDOW(0);
ian@0 1414 sw_info = (read_eeprom(ioaddr, 0x14) & 0x400f) |
ian@0 1415 (read_eeprom(ioaddr, 0x0d) & 0xBff0);
ian@0 1416
ian@0 1417 EL3WINDOW(4);
ian@0 1418 net_diag = inw(ioaddr + WN4_NETDIAG);
ian@0 1419 net_diag = (net_diag | FD_ENABLE); /* temporarily assume full-duplex will be set */
ian@0 1420 printk("%s: ", dev->name);
ian@0 1421 switch (dev->if_port & 0x0c) {
ian@0 1422 case 12:
ian@0 1423 /* force full-duplex mode if 3c5x9b */
ian@0 1424 if (sw_info & 0x000f) {
ian@0 1425 printk("Forcing 3c5x9b full-duplex mode");
ian@0 1426 break;
ian@0 1427 }
ian@0 1428 case 8:
ian@0 1429 /* set full-duplex mode based on eeprom config setting */
ian@0 1430 if ((sw_info & 0x000f) && (sw_info & 0x8000)) {
ian@0 1431 printk("Setting 3c5x9b full-duplex mode (from EEPROM configuration bit)");
ian@0 1432 break;
ian@0 1433 }
ian@0 1434 default:
ian@0 1435 /* xcvr=(0 || 4) OR user has an old 3c5x9 non "B" model */
ian@0 1436 printk("Setting 3c5x9/3c5x9B half-duplex mode");
ian@0 1437 net_diag = (net_diag & ~FD_ENABLE); /* disable full duplex */
ian@0 1438 }
ian@0 1439
ian@0 1440 outw(net_diag, ioaddr + WN4_NETDIAG);
ian@0 1441 printk(" if_port: %d, sw_info: %4.4x\n", dev->if_port, sw_info);
ian@0 1442 if (el3_debug > 3)
ian@0 1443 printk("%s: 3c5x9 net diag word is now: %4.4x.\n", dev->name, net_diag);
ian@0 1444 /* Enable link beat and jabber check. */
ian@0 1445 outw(inw(ioaddr + WN4_MEDIA) | MEDIA_TP, ioaddr + WN4_MEDIA);
ian@0 1446 }
ian@0 1447
ian@0 1448 /* Switch to the stats window, and clear all stats by reading. */
ian@0 1449 outw(StatsDisable, ioaddr + EL3_CMD);
ian@0 1450 EL3WINDOW(6);
ian@0 1451 for (i = 0; i < 9; i++)
ian@0 1452 inb(ioaddr + i);
ian@0 1453 inw(ioaddr + 10);
ian@0 1454 inw(ioaddr + 12);
ian@0 1455
ian@0 1456 /* Switch to register set 1 for normal use. */
ian@0 1457 EL3WINDOW(1);
ian@0 1458
ian@0 1459 /* Accept b-case and phys addr only. */
ian@0 1460 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
ian@0 1461 outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
ian@0 1462
ian@0 1463 outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
ian@0 1464 outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
ian@0 1465 /* Allow status bits to be seen. */
ian@0 1466 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
ian@0 1467 /* Ack all pending events, and set active indicator mask. */
ian@0 1468 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
ian@0 1469 ioaddr + EL3_CMD);
ian@0 1470 outw(SetIntrEnb | IntLatch|TxAvailable|TxComplete|RxComplete|StatsFull,
ian@0 1471 ioaddr + EL3_CMD);
ian@0 1472
ian@0 1473 netif_start_queue(dev);
ian@0 1474 }
ian@0 1475
ian@0 1476 /* Power Management support functions */
ian@0 1477 #ifdef EL3_SUSPEND
ian@0 1478
ian@0 1479 static int
ian@0 1480 el3_suspend(struct device *pdev, pm_message_t state)
ian@0 1481 {
ian@0 1482 unsigned long flags;
ian@0 1483 struct net_device *dev;
ian@0 1484 struct el3_private *lp;
ian@0 1485 int ioaddr;
ian@0 1486
ian@0 1487 dev = pdev->driver_data;
ian@0 1488 lp = netdev_priv(dev);
ian@0 1489 ioaddr = dev->base_addr;
ian@0 1490
ian@0 1491 spin_lock_irqsave(&lp->lock, flags);
ian@0 1492
ian@0 1493 if (netif_running(dev))
ian@0 1494 netif_device_detach(dev);
ian@0 1495
ian@0 1496 el3_down(dev);
ian@0 1497 outw(PowerDown, ioaddr + EL3_CMD);
ian@0 1498
ian@0 1499 spin_unlock_irqrestore(&lp->lock, flags);
ian@0 1500 return 0;
ian@0 1501 }
ian@0 1502
ian@0 1503 static int
ian@0 1504 el3_resume(struct device *pdev)
ian@0 1505 {
ian@0 1506 unsigned long flags;
ian@0 1507 struct net_device *dev;
ian@0 1508 struct el3_private *lp;
ian@0 1509 int ioaddr;
ian@0 1510
ian@0 1511 dev = pdev->driver_data;
ian@0 1512 lp = netdev_priv(dev);
ian@0 1513 ioaddr = dev->base_addr;
ian@0 1514
ian@0 1515 spin_lock_irqsave(&lp->lock, flags);
ian@0 1516
ian@0 1517 outw(PowerUp, ioaddr + EL3_CMD);
ian@0 1518 el3_up(dev);
ian@0 1519
ian@0 1520 if (netif_running(dev))
ian@0 1521 netif_device_attach(dev);
ian@0 1522
ian@0 1523 spin_unlock_irqrestore(&lp->lock, flags);
ian@0 1524 return 0;
ian@0 1525 }
ian@0 1526
ian@0 1527 #endif /* EL3_SUSPEND */
ian@0 1528
ian@0 1529 /* Parameters that may be passed into the module. */
ian@0 1530 static int debug = -1;
ian@0 1531 static int irq[] = {-1, -1, -1, -1, -1, -1, -1, -1};
ian@0 1532 static int xcvr[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
ian@0 1533
ian@0 1534 module_param(debug,int, 0);
ian@0 1535 module_param_array(irq, int, NULL, 0);
ian@0 1536 module_param_array(xcvr, int, NULL, 0);
ian@0 1537 module_param(max_interrupt_work, int, 0);
ian@0 1538 MODULE_PARM_DESC(debug, "debug level (0-6)");
ian@0 1539 MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)");
ian@0 1540 MODULE_PARM_DESC(xcvr,"transceiver(s) (0=internal, 1=external)");
ian@0 1541 MODULE_PARM_DESC(max_interrupt_work, "maximum events handled per interrupt");
ian@0 1542 #if defined(__ISAPNP__)
ian@0 1543 module_param(nopnp, int, 0);
ian@0 1544 MODULE_PARM_DESC(nopnp, "disable ISA PnP support (0-1)");
ian@0 1545 MODULE_DEVICE_TABLE(isapnp, el3_isapnp_adapters);
ian@0 1546 #endif /* __ISAPNP__ */
ian@0 1547 MODULE_DESCRIPTION("3Com Etherlink III (3c509, 3c509B) ISA/PnP ethernet driver");
ian@0 1548 MODULE_LICENSE("GPL");
ian@0 1549
ian@0 1550 static int __init el3_init_module(void)
ian@0 1551 {
ian@0 1552 int ret = 0;
ian@0 1553 el3_cards = 0;
ian@0 1554
ian@0 1555 if (debug >= 0)
ian@0 1556 el3_debug = debug;
ian@0 1557
ian@0 1558 el3_root_dev = NULL;
ian@0 1559 while (el3_probe(el3_cards) == 0) {
ian@0 1560 if (irq[el3_cards] > 1)
ian@0 1561 el3_root_dev->irq = irq[el3_cards];
ian@0 1562 if (xcvr[el3_cards] >= 0)
ian@0 1563 el3_root_dev->if_port = xcvr[el3_cards];
ian@0 1564 el3_cards++;
ian@0 1565 }
ian@0 1566
ian@0 1567 #ifdef CONFIG_EISA
ian@0 1568 ret = eisa_driver_register(&el3_eisa_driver);
ian@0 1569 #endif
ian@0 1570 #ifdef CONFIG_MCA
ian@0 1571 {
ian@0 1572 int err = mca_register_driver(&el3_mca_driver);
ian@0 1573 if (ret == 0)
ian@0 1574 ret = err;
ian@0 1575 }
ian@0 1576 #endif
ian@0 1577 return ret;
ian@0 1578 }
ian@0 1579
ian@0 1580 static void __exit el3_cleanup_module(void)
ian@0 1581 {
ian@0 1582 struct net_device *next_dev;
ian@0 1583
ian@0 1584 while (el3_root_dev) {
ian@0 1585 struct el3_private *lp = netdev_priv(el3_root_dev);
ian@0 1586
ian@0 1587 next_dev = lp->next_dev;
ian@0 1588 el3_common_remove (el3_root_dev);
ian@0 1589 el3_root_dev = next_dev;
ian@0 1590 }
ian@0 1591
ian@0 1592 #ifdef CONFIG_EISA
ian@0 1593 eisa_driver_unregister (&el3_eisa_driver);
ian@0 1594 #endif
ian@0 1595 #ifdef CONFIG_MCA
ian@0 1596 mca_unregister_driver(&el3_mca_driver);
ian@0 1597 #endif
ian@0 1598 }
ian@0 1599
ian@0 1600 module_init (el3_init_module);
ian@0 1601 module_exit (el3_cleanup_module);
ian@0 1602