ia64/linux-2.6.18-xen.hg

annotate drivers/net/eth16i.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 /* eth16i.c An ICL EtherTeam 16i and 32 EISA ethernet driver for Linux
ian@0 2
ian@0 3 Written 1994-1999 by Mika Kuoppala
ian@0 4
ian@0 5 Copyright (C) 1994-1999 by Mika Kuoppala
ian@0 6 Based on skeleton.c and heavily on at1700.c by Donald Becker
ian@0 7
ian@0 8 This software may be used and distributed according to the terms
ian@0 9 of the GNU General Public License, incorporated herein by reference.
ian@0 10
ian@0 11 The author may be reached as miku@iki.fi
ian@0 12
ian@0 13 This driver supports following cards :
ian@0 14 - ICL EtherTeam 16i
ian@0 15 - ICL EtherTeam 32 EISA
ian@0 16 (Uses true 32 bit transfers rather than 16i compability mode)
ian@0 17
ian@0 18 Example Module usage:
ian@0 19 insmod eth16i.o io=0x2a0 mediatype=bnc
ian@0 20
ian@0 21 mediatype can be one of the following: bnc,tp,dix,auto,eprom
ian@0 22
ian@0 23 'auto' will try to autoprobe mediatype.
ian@0 24 'eprom' will use whatever type defined in eprom.
ian@0 25
ian@0 26 I have benchmarked driver with PII/300Mhz as a ftp client
ian@0 27 and 486/33Mhz as a ftp server. Top speed was 1128.37 kilobytes/sec.
ian@0 28
ian@0 29 Sources:
ian@0 30 - skeleton.c a sample network driver core for linux,
ian@0 31 written by Donald Becker <becker@scyld.com>
ian@0 32 - at1700.c a driver for Allied Telesis AT1700, written
ian@0 33 by Donald Becker.
ian@0 34 - e16iSRV.asm a Netware 3.X Server Driver for ICL EtherTeam16i
ian@0 35 written by Markku Viima
ian@0 36 - The Fujitsu MB86965 databook.
ian@0 37
ian@0 38 Author thanks following persons due to their valueble assistance:
ian@0 39 Markku Viima (ICL)
ian@0 40 Ari Valve (ICL)
ian@0 41 Donald Becker
ian@0 42 Kurt Huwig <kurt@huwig.de>
ian@0 43
ian@0 44 Revision history:
ian@0 45
ian@0 46 Version Date Description
ian@0 47
ian@0 48 0.01 15.12-94 Initial version (card detection)
ian@0 49 0.02 23.01-95 Interrupt is now hooked correctly
ian@0 50 0.03 01.02-95 Rewrote initialization part
ian@0 51 0.04 07.02-95 Base skeleton done...
ian@0 52 Made a few changes to signature checking
ian@0 53 to make it a bit reliable.
ian@0 54 - fixed bug in tx_buf mapping
ian@0 55 - fixed bug in initialization (DLC_EN
ian@0 56 wasn't enabled when initialization
ian@0 57 was done.)
ian@0 58 0.05 08.02-95 If there were more than one packet to send,
ian@0 59 transmit was jammed due to invalid
ian@0 60 register write...now fixed
ian@0 61 0.06 19.02-95 Rewrote interrupt handling
ian@0 62 0.07 13.04-95 Wrote EEPROM read routines
ian@0 63 Card configuration now set according to
ian@0 64 data read from EEPROM
ian@0 65 0.08 23.06-95 Wrote part that tries to probe used interface
ian@0 66 port if AUTO is selected
ian@0 67
ian@0 68 0.09 01.09-95 Added module support
ian@0 69
ian@0 70 0.10 04.09-95 Fixed receive packet allocation to work
ian@0 71 with kernels > 1.3.x
ian@0 72
ian@0 73 0.20 20.09-95 Added support for EtherTeam32 EISA
ian@0 74
ian@0 75 0.21 17.10-95 Removed the unnecessary extern
ian@0 76 init_etherdev() declaration. Some
ian@0 77 other cleanups.
ian@0 78
ian@0 79 0.22 22.02-96 Receive buffer was not flushed
ian@0 80 correctly when faulty packet was
ian@0 81 received. Now fixed.
ian@0 82
ian@0 83 0.23 26.02-96 Made resetting the adapter
ian@0 84 more reliable.
ian@0 85
ian@0 86 0.24 27.02-96 Rewrote faulty packet handling in eth16i_rx
ian@0 87
ian@0 88 0.25 22.05-96 kfree() was missing from cleanup_module.
ian@0 89
ian@0 90 0.26 11.06-96 Sometimes card was not found by
ian@0 91 check_signature(). Now made more reliable.
ian@0 92
ian@0 93 0.27 23.06-96 Oops. 16 consecutive collisions halted
ian@0 94 adapter. Now will try to retransmit
ian@0 95 MAX_COL_16 times before finally giving up.
ian@0 96
ian@0 97 0.28 28.10-97 Added dev_id parameter (NULL) for free_irq
ian@0 98
ian@0 99 0.29 29.10-97 Multiple card support for module users
ian@0 100
ian@0 101 0.30 30.10-97 Fixed irq allocation bug.
ian@0 102 (request_irq moved from probe to open)
ian@0 103
ian@0 104 0.30a 21.08-98 Card detection made more relaxed. Driver
ian@0 105 had problems with some TCP/IP-PROM boots
ian@0 106 to find the card. Suggested by
ian@0 107 Kurt Huwig <kurt@huwig.de>
ian@0 108
ian@0 109 0.31 28.08-98 Media interface port can now be selected
ian@0 110 with module parameters or kernel
ian@0 111 boot parameters.
ian@0 112
ian@0 113 0.32 31.08-98 IRQ was never freed if open/close
ian@0 114 pair wasn't called. Now fixed.
ian@0 115
ian@0 116 0.33 10.09-98 When eth16i_open() was called after
ian@0 117 eth16i_close() chip never recovered.
ian@0 118 Now more shallow reset is made on
ian@0 119 close.
ian@0 120
ian@0 121 0.34 29.06-99 Fixed one bad #ifdef.
ian@0 122 Changed ioaddr -> io for consistency
ian@0 123
ian@0 124 0.35 01.07-99 transmit,-receive bytes were never
ian@0 125 updated in stats.
ian@0 126
ian@0 127 Bugs:
ian@0 128 In some cases the media interface autoprobing code doesn't find
ian@0 129 the correct interface type. In this case you can
ian@0 130 manually choose the interface type in DOS with E16IC.EXE which is
ian@0 131 configuration software for EtherTeam16i and EtherTeam32 cards.
ian@0 132 This is also true for IRQ setting. You cannot use module
ian@0 133 parameter to configure IRQ of the card (yet).
ian@0 134
ian@0 135 To do:
ian@0 136 - Real multicast support
ian@0 137 - Rewrite the media interface autoprobing code. Its _horrible_ !
ian@0 138 - Possibly merge all the MB86965 specific code to external
ian@0 139 module for use by eth16.c and Donald's at1700.c
ian@0 140 - IRQ configuration with module parameter. I will do
ian@0 141 this when i will get enough info about setting
ian@0 142 irq without configuration utility.
ian@0 143 */
ian@0 144
ian@0 145 static char *version =
ian@0 146 "eth16i.c: v0.35 01-Jul-1999 Mika Kuoppala (miku@iki.fi)\n";
ian@0 147
ian@0 148 #include <linux/module.h>
ian@0 149 #include <linux/kernel.h>
ian@0 150 #include <linux/types.h>
ian@0 151 #include <linux/fcntl.h>
ian@0 152 #include <linux/interrupt.h>
ian@0 153 #include <linux/ioport.h>
ian@0 154 #include <linux/in.h>
ian@0 155 #include <linux/slab.h>
ian@0 156 #include <linux/string.h>
ian@0 157 #include <linux/errno.h>
ian@0 158 #include <linux/init.h>
ian@0 159 #include <linux/spinlock.h>
ian@0 160 #include <linux/netdevice.h>
ian@0 161 #include <linux/etherdevice.h>
ian@0 162 #include <linux/skbuff.h>
ian@0 163 #include <linux/bitops.h>
ian@0 164 #include <linux/jiffies.h>
ian@0 165
ian@0 166 #include <asm/system.h>
ian@0 167 #include <asm/io.h>
ian@0 168 #include <asm/dma.h>
ian@0 169
ian@0 170
ian@0 171
ian@0 172 /* Few macros */
ian@0 173 #define BIT(a) ( (1 << (a)) )
ian@0 174 #define BITSET(ioaddr, bnum) ((outb(((inb(ioaddr)) | (bnum)), ioaddr)))
ian@0 175 #define BITCLR(ioaddr, bnum) ((outb(((inb(ioaddr)) & (~(bnum))), ioaddr)))
ian@0 176
ian@0 177 /* This is the I/O address space for Etherteam 16i adapter. */
ian@0 178 #define ETH16I_IO_EXTENT 32
ian@0 179
ian@0 180 /* Ticks before deciding that transmit has timed out */
ian@0 181 #define TX_TIMEOUT (400*HZ/1000)
ian@0 182
ian@0 183 /* Maximum loop count when receiving packets */
ian@0 184 #define MAX_RX_LOOP 20
ian@0 185
ian@0 186 /* Some interrupt masks */
ian@0 187 #define ETH16I_INTR_ON 0xef8a /* Higher is receive mask */
ian@0 188 #define ETH16I_INTR_OFF 0x0000
ian@0 189
ian@0 190 /* Buffers header status byte meanings */
ian@0 191 #define PKT_GOOD BIT(5)
ian@0 192 #define PKT_GOOD_RMT BIT(4)
ian@0 193 #define PKT_SHORT BIT(3)
ian@0 194 #define PKT_ALIGN_ERR BIT(2)
ian@0 195 #define PKT_CRC_ERR BIT(1)
ian@0 196 #define PKT_RX_BUF_OVERFLOW BIT(0)
ian@0 197
ian@0 198 /* Transmit status register (DLCR0) */
ian@0 199 #define TX_STATUS_REG 0
ian@0 200 #define TX_DONE BIT(7)
ian@0 201 #define NET_BUSY BIT(6)
ian@0 202 #define TX_PKT_RCD BIT(5)
ian@0 203 #define CR_LOST BIT(4)
ian@0 204 #define TX_JABBER_ERR BIT(3)
ian@0 205 #define COLLISION BIT(2)
ian@0 206 #define COLLISIONS_16 BIT(1)
ian@0 207
ian@0 208 /* Receive status register (DLCR1) */
ian@0 209 #define RX_STATUS_REG 1
ian@0 210 #define RX_PKT BIT(7) /* Packet received */
ian@0 211 #define BUS_RD_ERR BIT(6)
ian@0 212 #define SHORT_PKT_ERR BIT(3)
ian@0 213 #define ALIGN_ERR BIT(2)
ian@0 214 #define CRC_ERR BIT(1)
ian@0 215 #define RX_BUF_OVERFLOW BIT(0)
ian@0 216
ian@0 217 /* Transmit Interrupt Enable Register (DLCR2) */
ian@0 218 #define TX_INTR_REG 2
ian@0 219 #define TX_INTR_DONE BIT(7)
ian@0 220 #define TX_INTR_COL BIT(2)
ian@0 221 #define TX_INTR_16_COL BIT(1)
ian@0 222
ian@0 223 /* Receive Interrupt Enable Register (DLCR3) */
ian@0 224 #define RX_INTR_REG 3
ian@0 225 #define RX_INTR_RECEIVE BIT(7)
ian@0 226 #define RX_INTR_SHORT_PKT BIT(3)
ian@0 227 #define RX_INTR_CRC_ERR BIT(1)
ian@0 228 #define RX_INTR_BUF_OVERFLOW BIT(0)
ian@0 229
ian@0 230 /* Transmit Mode Register (DLCR4) */
ian@0 231 #define TRANSMIT_MODE_REG 4
ian@0 232 #define LOOPBACK_CONTROL BIT(1)
ian@0 233 #define CONTROL_OUTPUT BIT(2)
ian@0 234
ian@0 235 /* Receive Mode Register (DLCR5) */
ian@0 236 #define RECEIVE_MODE_REG 5
ian@0 237 #define RX_BUFFER_EMPTY BIT(6)
ian@0 238 #define ACCEPT_BAD_PACKETS BIT(5)
ian@0 239 #define RECEIVE_SHORT_ADDR BIT(4)
ian@0 240 #define ACCEPT_SHORT_PACKETS BIT(3)
ian@0 241 #define REMOTE_RESET BIT(2)
ian@0 242
ian@0 243 #define ADDRESS_FILTER_MODE BIT(1) | BIT(0)
ian@0 244 #define REJECT_ALL 0
ian@0 245 #define ACCEPT_ALL 3
ian@0 246 #define MODE_1 1 /* NODE ID, BC, MC, 2-24th bit */
ian@0 247 #define MODE_2 2 /* NODE ID, BC, MC, Hash Table */
ian@0 248
ian@0 249 /* Configuration Register 0 (DLCR6) */
ian@0 250 #define CONFIG_REG_0 6
ian@0 251 #define DLC_EN BIT(7)
ian@0 252 #define SRAM_CYCLE_TIME_100NS BIT(6)
ian@0 253 #define SYSTEM_BUS_WIDTH_8 BIT(5) /* 1 = 8bit, 0 = 16bit */
ian@0 254 #define BUFFER_WIDTH_8 BIT(4) /* 1 = 8bit, 0 = 16bit */
ian@0 255 #define TBS1 BIT(3)
ian@0 256 #define TBS0 BIT(2)
ian@0 257 #define SRAM_BS1 BIT(1) /* 00=8kb, 01=16kb */
ian@0 258 #define SRAM_BS0 BIT(0) /* 10=32kb, 11=64kb */
ian@0 259
ian@0 260 #ifndef ETH16I_TX_BUF_SIZE /* 0 = 2kb, 1 = 4kb */
ian@0 261 #define ETH16I_TX_BUF_SIZE 3 /* 2 = 8kb, 3 = 16kb */
ian@0 262 #endif
ian@0 263 #define TX_BUF_1x2048 0
ian@0 264 #define TX_BUF_2x2048 1
ian@0 265 #define TX_BUF_2x4098 2
ian@0 266 #define TX_BUF_2x8192 3
ian@0 267
ian@0 268 /* Configuration Register 1 (DLCR7) */
ian@0 269 #define CONFIG_REG_1 7
ian@0 270 #define POWERUP BIT(5)
ian@0 271
ian@0 272 /* Transmit start register */
ian@0 273 #define TRANSMIT_START_REG 10
ian@0 274 #define TRANSMIT_START_RB 2
ian@0 275 #define TX_START BIT(7) /* Rest of register bit indicate*/
ian@0 276 /* number of packets in tx buffer*/
ian@0 277 /* Node ID registers (DLCR8-13) */
ian@0 278 #define NODE_ID_0 8
ian@0 279 #define NODE_ID_RB 0
ian@0 280
ian@0 281 /* Hash Table registers (HT8-15) */
ian@0 282 #define HASH_TABLE_0 8
ian@0 283 #define HASH_TABLE_RB 1
ian@0 284
ian@0 285 /* Buffer memory ports */
ian@0 286 #define BUFFER_MEM_PORT_LB 8
ian@0 287 #define DATAPORT BUFFER_MEM_PORT_LB
ian@0 288 #define BUFFER_MEM_PORT_HB 9
ian@0 289
ian@0 290 /* 16 Collision control register (BMPR11) */
ian@0 291 #define COL_16_REG 11
ian@0 292 #define HALT_ON_16 0x00
ian@0 293 #define RETRANS_AND_HALT_ON_16 0x02
ian@0 294
ian@0 295 /* Maximum number of attempts to send after 16 concecutive collisions */
ian@0 296 #define MAX_COL_16 10
ian@0 297
ian@0 298 /* DMA Burst and Transceiver Mode Register (BMPR13) */
ian@0 299 #define TRANSCEIVER_MODE_REG 13
ian@0 300 #define TRANSCEIVER_MODE_RB 2
ian@0 301 #define IO_BASE_UNLOCK BIT(7)
ian@0 302 #define LOWER_SQUELCH_TRESH BIT(6)
ian@0 303 #define LINK_TEST_DISABLE BIT(5)
ian@0 304 #define AUI_SELECT BIT(4)
ian@0 305 #define DIS_AUTO_PORT_SEL BIT(3)
ian@0 306
ian@0 307 /* Filter Self Receive Register (BMPR14) */
ian@0 308 #define FILTER_SELF_RX_REG 14
ian@0 309 #define SKIP_RX_PACKET BIT(2)
ian@0 310 #define FILTER_SELF_RECEIVE BIT(0)
ian@0 311
ian@0 312 /* EEPROM Control Register (BMPR 16) */
ian@0 313 #define EEPROM_CTRL_REG 16
ian@0 314
ian@0 315 /* EEPROM Data Register (BMPR 17) */
ian@0 316 #define EEPROM_DATA_REG 17
ian@0 317
ian@0 318 /* NMC93CSx6 EEPROM Control Bits */
ian@0 319 #define CS_0 0x00
ian@0 320 #define CS_1 0x20
ian@0 321 #define SK_0 0x00
ian@0 322 #define SK_1 0x40
ian@0 323 #define DI_0 0x00
ian@0 324 #define DI_1 0x80
ian@0 325
ian@0 326 /* NMC93CSx6 EEPROM Instructions */
ian@0 327 #define EEPROM_READ 0x80
ian@0 328
ian@0 329 /* NMC93CSx6 EEPROM Addresses */
ian@0 330 #define E_NODEID_0 0x02
ian@0 331 #define E_NODEID_1 0x03
ian@0 332 #define E_NODEID_2 0x04
ian@0 333 #define E_PORT_SELECT 0x14
ian@0 334 #define E_PORT_BNC 0x00
ian@0 335 #define E_PORT_DIX 0x01
ian@0 336 #define E_PORT_TP 0x02
ian@0 337 #define E_PORT_AUTO 0x03
ian@0 338 #define E_PORT_FROM_EPROM 0x04
ian@0 339 #define E_PRODUCT_CFG 0x30
ian@0 340
ian@0 341
ian@0 342 /* Macro to slow down io between EEPROM clock transitions */
ian@0 343 #define eeprom_slow_io() do { int _i = 40; while(--_i > 0) { inb(0x80); }}while(0)
ian@0 344
ian@0 345 /* Jumperless Configuration Register (BMPR19) */
ian@0 346 #define JUMPERLESS_CONFIG 19
ian@0 347
ian@0 348 /* ID ROM registers, writing to them also resets some parts of chip */
ian@0 349 #define ID_ROM_0 24
ian@0 350 #define ID_ROM_7 31
ian@0 351 #define RESET ID_ROM_0
ian@0 352
ian@0 353 /* This is the I/O address list to be probed when seeking the card */
ian@0 354 static unsigned int eth16i_portlist[] __initdata = {
ian@0 355 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300, 0
ian@0 356 };
ian@0 357
ian@0 358 static unsigned int eth32i_portlist[] __initdata = {
ian@0 359 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000, 0x8000,
ian@0 360 0x9000, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, 0
ian@0 361 };
ian@0 362
ian@0 363 /* This is the Interrupt lookup table for Eth16i card */
ian@0 364 static unsigned int eth16i_irqmap[] __initdata = { 9, 10, 5, 15, 0 };
ian@0 365 #define NUM_OF_ISA_IRQS 4
ian@0 366
ian@0 367 /* This is the Interrupt lookup table for Eth32i card */
ian@0 368 static unsigned int eth32i_irqmap[] __initdata = { 3, 5, 7, 9, 10, 11, 12, 15, 0 };
ian@0 369 #define EISA_IRQ_REG 0xc89
ian@0 370 #define NUM_OF_EISA_IRQS 8
ian@0 371
ian@0 372 static unsigned int eth16i_tx_buf_map[] = { 2048, 2048, 4096, 8192 };
ian@0 373
ian@0 374 /* Use 0 for production, 1 for verification, >2 for debug */
ian@0 375 #ifndef ETH16I_DEBUG
ian@0 376 #define ETH16I_DEBUG 0
ian@0 377 #endif
ian@0 378 static unsigned int eth16i_debug = ETH16I_DEBUG;
ian@0 379
ian@0 380 /* Information for each board */
ian@0 381
ian@0 382 struct eth16i_local {
ian@0 383 struct net_device_stats stats;
ian@0 384 unsigned char tx_started;
ian@0 385 unsigned char tx_buf_busy;
ian@0 386 unsigned short tx_queue; /* Number of packets in transmit buffer */
ian@0 387 unsigned short tx_queue_len;
ian@0 388 unsigned int tx_buf_size;
ian@0 389 unsigned long open_time;
ian@0 390 unsigned long tx_buffered_packets;
ian@0 391 unsigned long tx_buffered_bytes;
ian@0 392 unsigned long col_16;
ian@0 393 spinlock_t lock;
ian@0 394 };
ian@0 395
ian@0 396 /* Function prototypes */
ian@0 397
ian@0 398 static int eth16i_probe1(struct net_device *dev, int ioaddr);
ian@0 399 static int eth16i_check_signature(int ioaddr);
ian@0 400 static int eth16i_probe_port(int ioaddr);
ian@0 401 static void eth16i_set_port(int ioaddr, int porttype);
ian@0 402 static int eth16i_send_probe_packet(int ioaddr, unsigned char *b, int l);
ian@0 403 static int eth16i_receive_probe_packet(int ioaddr);
ian@0 404 static int eth16i_get_irq(int ioaddr);
ian@0 405 static int eth16i_read_eeprom(int ioaddr, int offset);
ian@0 406 static int eth16i_read_eeprom_word(int ioaddr);
ian@0 407 static void eth16i_eeprom_cmd(int ioaddr, unsigned char command);
ian@0 408 static int eth16i_open(struct net_device *dev);
ian@0 409 static int eth16i_close(struct net_device *dev);
ian@0 410 static int eth16i_tx(struct sk_buff *skb, struct net_device *dev);
ian@0 411 static void eth16i_rx(struct net_device *dev);
ian@0 412 static void eth16i_timeout(struct net_device *dev);
ian@0 413 static irqreturn_t eth16i_interrupt(int irq, void *dev_id, struct pt_regs *regs);
ian@0 414 static void eth16i_reset(struct net_device *dev);
ian@0 415 static void eth16i_timeout(struct net_device *dev);
ian@0 416 static void eth16i_skip_packet(struct net_device *dev);
ian@0 417 static void eth16i_multicast(struct net_device *dev);
ian@0 418 static void eth16i_select_regbank(unsigned char regbank, int ioaddr);
ian@0 419 static void eth16i_initialize(struct net_device *dev, int boot);
ian@0 420
ian@0 421 #if 0
ian@0 422 static int eth16i_set_irq(struct net_device *dev);
ian@0 423 #endif
ian@0 424
ian@0 425 #ifdef MODULE
ian@0 426 static ushort eth16i_parse_mediatype(const char* s);
ian@0 427 #endif
ian@0 428
ian@0 429 static struct net_device_stats *eth16i_get_stats(struct net_device *dev);
ian@0 430
ian@0 431 static char cardname[] __initdata = "ICL EtherTeam 16i/32";
ian@0 432
ian@0 433 static int __init do_eth16i_probe(struct net_device *dev)
ian@0 434 {
ian@0 435 int i;
ian@0 436 int ioaddr;
ian@0 437 int base_addr = dev->base_addr;
ian@0 438
ian@0 439 SET_MODULE_OWNER(dev);
ian@0 440
ian@0 441 if(eth16i_debug > 4)
ian@0 442 printk(KERN_DEBUG "Probing started for %s\n", cardname);
ian@0 443
ian@0 444 if(base_addr > 0x1ff) /* Check only single location */
ian@0 445 return eth16i_probe1(dev, base_addr);
ian@0 446 else if(base_addr != 0) /* Don't probe at all */
ian@0 447 return -ENXIO;
ian@0 448
ian@0 449 /* Seek card from the ISA io address space */
ian@0 450 for(i = 0; (ioaddr = eth16i_portlist[i]) ; i++)
ian@0 451 if(eth16i_probe1(dev, ioaddr) == 0)
ian@0 452 return 0;
ian@0 453
ian@0 454 /* Seek card from the EISA io address space */
ian@0 455 for(i = 0; (ioaddr = eth32i_portlist[i]) ; i++)
ian@0 456 if(eth16i_probe1(dev, ioaddr) == 0)
ian@0 457 return 0;
ian@0 458
ian@0 459 return -ENODEV;
ian@0 460 }
ian@0 461
ian@0 462 #ifndef MODULE
ian@0 463 struct net_device * __init eth16i_probe(int unit)
ian@0 464 {
ian@0 465 struct net_device *dev = alloc_etherdev(sizeof(struct eth16i_local));
ian@0 466 int err;
ian@0 467
ian@0 468 if (!dev)
ian@0 469 return ERR_PTR(-ENOMEM);
ian@0 470
ian@0 471 sprintf(dev->name, "eth%d", unit);
ian@0 472 netdev_boot_setup_check(dev);
ian@0 473
ian@0 474 err = do_eth16i_probe(dev);
ian@0 475 if (err)
ian@0 476 goto out;
ian@0 477 return dev;
ian@0 478 out:
ian@0 479 free_netdev(dev);
ian@0 480 return ERR_PTR(err);
ian@0 481 }
ian@0 482 #endif
ian@0 483
ian@0 484 static int __init eth16i_probe1(struct net_device *dev, int ioaddr)
ian@0 485 {
ian@0 486 struct eth16i_local *lp = netdev_priv(dev);
ian@0 487 static unsigned version_printed;
ian@0 488 int retval;
ian@0 489
ian@0 490 /* Let's grab the region */
ian@0 491 if (!request_region(ioaddr, ETH16I_IO_EXTENT, cardname))
ian@0 492 return -EBUSY;
ian@0 493
ian@0 494 /*
ian@0 495 The MB86985 chip has on register which holds information in which
ian@0 496 io address the chip lies. First read this register and compare
ian@0 497 it to our current io address and if match then this could
ian@0 498 be our chip.
ian@0 499 */
ian@0 500
ian@0 501 if(ioaddr < 0x1000) {
ian@0 502 if(eth16i_portlist[(inb(ioaddr + JUMPERLESS_CONFIG) & 0x07)]
ian@0 503 != ioaddr) {
ian@0 504 retval = -ENODEV;
ian@0 505 goto out;
ian@0 506 }
ian@0 507 }
ian@0 508
ian@0 509 /* Now we will go a bit deeper and try to find the chip's signature */
ian@0 510
ian@0 511 if(eth16i_check_signature(ioaddr) != 0) {
ian@0 512 retval = -ENODEV;
ian@0 513 goto out;
ian@0 514 }
ian@0 515
ian@0 516 /*
ian@0 517 Now it seems that we have found a ethernet chip in this particular
ian@0 518 ioaddr. The MB86985 chip has this feature, that when you read a
ian@0 519 certain register it will increase it's io base address to next
ian@0 520 configurable slot. Now when we have found the chip, first thing is
ian@0 521 to make sure that the chip's ioaddr will hold still here.
ian@0 522 */
ian@0 523
ian@0 524 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
ian@0 525 outb(0x00, ioaddr + TRANSCEIVER_MODE_REG);
ian@0 526
ian@0 527 outb(0x00, ioaddr + RESET); /* Reset some parts of chip */
ian@0 528 BITSET(ioaddr + CONFIG_REG_0, BIT(7)); /* Disable the data link */
ian@0 529
ian@0 530 if( (eth16i_debug & version_printed++) == 0)
ian@0 531 printk(KERN_INFO "%s", version);
ian@0 532
ian@0 533 dev->base_addr = ioaddr;
ian@0 534 dev->irq = eth16i_get_irq(ioaddr);
ian@0 535
ian@0 536 /* Try to obtain interrupt vector */
ian@0 537
ian@0 538 if ((retval = request_irq(dev->irq, (void *)&eth16i_interrupt, 0, cardname, dev))) {
ian@0 539 printk(KERN_WARNING "%s at %#3x, but is unusable due to conflicting IRQ %d.\n",
ian@0 540 cardname, ioaddr, dev->irq);
ian@0 541 goto out;
ian@0 542 }
ian@0 543
ian@0 544 printk(KERN_INFO "%s: %s at %#3x, IRQ %d, ",
ian@0 545 dev->name, cardname, ioaddr, dev->irq);
ian@0 546
ian@0 547
ian@0 548 /* Now we will have to lock the chip's io address */
ian@0 549 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
ian@0 550 outb(0x38, ioaddr + TRANSCEIVER_MODE_REG);
ian@0 551
ian@0 552 eth16i_initialize(dev, 1); /* Initialize rest of the chip's registers */
ian@0 553
ian@0 554 /* Now let's same some energy by shutting down the chip ;) */
ian@0 555 BITCLR(ioaddr + CONFIG_REG_1, POWERUP);
ian@0 556
ian@0 557 /* Initialize the device structure */
ian@0 558 memset(lp, 0, sizeof(struct eth16i_local));
ian@0 559 dev->open = eth16i_open;
ian@0 560 dev->stop = eth16i_close;
ian@0 561 dev->hard_start_xmit = eth16i_tx;
ian@0 562 dev->get_stats = eth16i_get_stats;
ian@0 563 dev->set_multicast_list = eth16i_multicast;
ian@0 564 dev->tx_timeout = eth16i_timeout;
ian@0 565 dev->watchdog_timeo = TX_TIMEOUT;
ian@0 566 spin_lock_init(&lp->lock);
ian@0 567
ian@0 568 retval = register_netdev(dev);
ian@0 569 if (retval)
ian@0 570 goto out1;
ian@0 571 return 0;
ian@0 572 out1:
ian@0 573 free_irq(dev->irq, dev);
ian@0 574 out:
ian@0 575 release_region(ioaddr, ETH16I_IO_EXTENT);
ian@0 576 return retval;
ian@0 577 }
ian@0 578
ian@0 579
ian@0 580 static void eth16i_initialize(struct net_device *dev, int boot)
ian@0 581 {
ian@0 582 int ioaddr = dev->base_addr;
ian@0 583 int i, node_w = 0;
ian@0 584 unsigned char node_byte = 0;
ian@0 585
ian@0 586 /* Setup station address */
ian@0 587 eth16i_select_regbank(NODE_ID_RB, ioaddr);
ian@0 588 for(i = 0 ; i < 3 ; i++) {
ian@0 589 unsigned short node_val = eth16i_read_eeprom(ioaddr, E_NODEID_0 + i);
ian@0 590 ((unsigned short *)dev->dev_addr)[i] = ntohs(node_val);
ian@0 591 }
ian@0 592
ian@0 593 for(i = 0; i < 6; i++) {
ian@0 594 outb( ((unsigned char *)dev->dev_addr)[i], ioaddr + NODE_ID_0 + i);
ian@0 595 if(boot) {
ian@0 596 printk("%02x", inb(ioaddr + NODE_ID_0 + i));
ian@0 597 if(i != 5)
ian@0 598 printk(":");
ian@0 599 }
ian@0 600 }
ian@0 601
ian@0 602 /* Now we will set multicast addresses to accept none */
ian@0 603 eth16i_select_regbank(HASH_TABLE_RB, ioaddr);
ian@0 604 for(i = 0; i < 8; i++)
ian@0 605 outb(0x00, ioaddr + HASH_TABLE_0 + i);
ian@0 606
ian@0 607 /*
ian@0 608 Now let's disable the transmitter and receiver, set the buffer ram
ian@0 609 cycle time, bus width and buffer data path width. Also we shall
ian@0 610 set transmit buffer size and total buffer size.
ian@0 611 */
ian@0 612
ian@0 613 eth16i_select_regbank(2, ioaddr);
ian@0 614
ian@0 615 node_byte = 0;
ian@0 616 node_w = eth16i_read_eeprom(ioaddr, E_PRODUCT_CFG);
ian@0 617
ian@0 618 if( (node_w & 0xFF00) == 0x0800)
ian@0 619 node_byte |= BUFFER_WIDTH_8;
ian@0 620
ian@0 621 node_byte |= SRAM_BS1;
ian@0 622
ian@0 623 if( (node_w & 0x00FF) == 64)
ian@0 624 node_byte |= SRAM_BS0;
ian@0 625
ian@0 626 node_byte |= DLC_EN | SRAM_CYCLE_TIME_100NS | (ETH16I_TX_BUF_SIZE << 2);
ian@0 627
ian@0 628 outb(node_byte, ioaddr + CONFIG_REG_0);
ian@0 629
ian@0 630 /* We shall halt the transmitting, if 16 collisions are detected */
ian@0 631 outb(HALT_ON_16, ioaddr + COL_16_REG);
ian@0 632
ian@0 633 #ifdef MODULE
ian@0 634 /* if_port already set by init_module() */
ian@0 635 #else
ian@0 636 dev->if_port = (dev->mem_start < E_PORT_FROM_EPROM) ?
ian@0 637 dev->mem_start : E_PORT_FROM_EPROM;
ian@0 638 #endif
ian@0 639
ian@0 640 /* Set interface port type */
ian@0 641 if(boot) {
ian@0 642 char *porttype[] = {"BNC", "DIX", "TP", "AUTO", "FROM_EPROM" };
ian@0 643
ian@0 644 switch(dev->if_port)
ian@0 645 {
ian@0 646
ian@0 647 case E_PORT_FROM_EPROM:
ian@0 648 dev->if_port = eth16i_read_eeprom(ioaddr, E_PORT_SELECT);
ian@0 649 break;
ian@0 650
ian@0 651 case E_PORT_AUTO:
ian@0 652 dev->if_port = eth16i_probe_port(ioaddr);
ian@0 653 break;
ian@0 654
ian@0 655 case E_PORT_BNC:
ian@0 656 case E_PORT_TP:
ian@0 657 case E_PORT_DIX:
ian@0 658 break;
ian@0 659 }
ian@0 660
ian@0 661 printk(" %s interface.\n", porttype[dev->if_port]);
ian@0 662
ian@0 663 eth16i_set_port(ioaddr, dev->if_port);
ian@0 664 }
ian@0 665
ian@0 666 /* Set Receive Mode to normal operation */
ian@0 667 outb(MODE_2, ioaddr + RECEIVE_MODE_REG);
ian@0 668 }
ian@0 669
ian@0 670 static int eth16i_probe_port(int ioaddr)
ian@0 671 {
ian@0 672 int i;
ian@0 673 int retcode;
ian@0 674 unsigned char dummy_packet[64];
ian@0 675
ian@0 676 /* Powerup the chip */
ian@0 677 outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1);
ian@0 678
ian@0 679 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
ian@0 680
ian@0 681 eth16i_select_regbank(NODE_ID_RB, ioaddr);
ian@0 682
ian@0 683 for(i = 0; i < 6; i++) {
ian@0 684 dummy_packet[i] = inb(ioaddr + NODE_ID_0 + i);
ian@0 685 dummy_packet[i+6] = inb(ioaddr + NODE_ID_0 + i);
ian@0 686 }
ian@0 687
ian@0 688 dummy_packet[12] = 0x00;
ian@0 689 dummy_packet[13] = 0x04;
ian@0 690 memset(dummy_packet + 14, 0, sizeof(dummy_packet) - 14);
ian@0 691
ian@0 692 eth16i_select_regbank(2, ioaddr);
ian@0 693
ian@0 694 for(i = 0; i < 3; i++) {
ian@0 695 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
ian@0 696 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
ian@0 697 eth16i_set_port(ioaddr, i);
ian@0 698
ian@0 699 if(eth16i_debug > 1)
ian@0 700 printk(KERN_DEBUG "Set port number %d\n", i);
ian@0 701
ian@0 702 retcode = eth16i_send_probe_packet(ioaddr, dummy_packet, 64);
ian@0 703 if(retcode == 0) {
ian@0 704 retcode = eth16i_receive_probe_packet(ioaddr);
ian@0 705 if(retcode != -1) {
ian@0 706 if(eth16i_debug > 1)
ian@0 707 printk(KERN_DEBUG "Eth16i interface port found at %d\n", i);
ian@0 708 return i;
ian@0 709 }
ian@0 710 }
ian@0 711 else {
ian@0 712 if(eth16i_debug > 1)
ian@0 713 printk(KERN_DEBUG "TRANSMIT_DONE timeout when probing interface port\n");
ian@0 714 }
ian@0 715 }
ian@0 716
ian@0 717 if( eth16i_debug > 1)
ian@0 718 printk(KERN_DEBUG "Using default port\n");
ian@0 719
ian@0 720 return E_PORT_BNC;
ian@0 721 }
ian@0 722
ian@0 723 static void eth16i_set_port(int ioaddr, int porttype)
ian@0 724 {
ian@0 725 unsigned short temp = 0;
ian@0 726
ian@0 727 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
ian@0 728 outb(LOOPBACK_CONTROL, ioaddr + TRANSMIT_MODE_REG);
ian@0 729
ian@0 730 temp |= DIS_AUTO_PORT_SEL;
ian@0 731
ian@0 732 switch(porttype) {
ian@0 733
ian@0 734 case E_PORT_BNC :
ian@0 735 temp |= AUI_SELECT;
ian@0 736 break;
ian@0 737
ian@0 738 case E_PORT_TP :
ian@0 739 break;
ian@0 740
ian@0 741 case E_PORT_DIX :
ian@0 742 temp |= AUI_SELECT;
ian@0 743 BITSET(ioaddr + TRANSMIT_MODE_REG, CONTROL_OUTPUT);
ian@0 744 break;
ian@0 745 }
ian@0 746
ian@0 747 outb(temp, ioaddr + TRANSCEIVER_MODE_REG);
ian@0 748
ian@0 749 if(eth16i_debug > 1) {
ian@0 750 printk(KERN_DEBUG "TRANSMIT_MODE_REG = %x\n", inb(ioaddr + TRANSMIT_MODE_REG));
ian@0 751 printk(KERN_DEBUG "TRANSCEIVER_MODE_REG = %x\n",
ian@0 752 inb(ioaddr+TRANSCEIVER_MODE_REG));
ian@0 753 }
ian@0 754 }
ian@0 755
ian@0 756 static int eth16i_send_probe_packet(int ioaddr, unsigned char *b, int l)
ian@0 757 {
ian@0 758 unsigned long starttime;
ian@0 759
ian@0 760 outb(0xff, ioaddr + TX_STATUS_REG);
ian@0 761
ian@0 762 outw(l, ioaddr + DATAPORT);
ian@0 763 outsw(ioaddr + DATAPORT, (unsigned short *)b, (l + 1) >> 1);
ian@0 764
ian@0 765 starttime = jiffies;
ian@0 766 outb(TX_START | 1, ioaddr + TRANSMIT_START_REG);
ian@0 767
ian@0 768 while( (inb(ioaddr + TX_STATUS_REG) & 0x80) == 0) {
ian@0 769 if( time_after(jiffies, starttime + TX_TIMEOUT)) {
ian@0 770 return -1;
ian@0 771 }
ian@0 772 }
ian@0 773
ian@0 774 return 0;
ian@0 775 }
ian@0 776
ian@0 777 static int eth16i_receive_probe_packet(int ioaddr)
ian@0 778 {
ian@0 779 unsigned long starttime;
ian@0 780
ian@0 781 starttime = jiffies;
ian@0 782
ian@0 783 while((inb(ioaddr + TX_STATUS_REG) & 0x20) == 0) {
ian@0 784 if( time_after(jiffies, starttime + TX_TIMEOUT)) {
ian@0 785
ian@0 786 if(eth16i_debug > 1)
ian@0 787 printk(KERN_DEBUG "Timeout occurred waiting transmit packet received\n");
ian@0 788 starttime = jiffies;
ian@0 789 while((inb(ioaddr + RX_STATUS_REG) & 0x80) == 0) {
ian@0 790 if( time_after(jiffies, starttime + TX_TIMEOUT)) {
ian@0 791 if(eth16i_debug > 1)
ian@0 792 printk(KERN_DEBUG "Timeout occurred waiting receive packet\n");
ian@0 793 return -1;
ian@0 794 }
ian@0 795 }
ian@0 796
ian@0 797 if(eth16i_debug > 1)
ian@0 798 printk(KERN_DEBUG "RECEIVE_PACKET\n");
ian@0 799 return(0); /* Found receive packet */
ian@0 800 }
ian@0 801 }
ian@0 802
ian@0 803 if(eth16i_debug > 1) {
ian@0 804 printk(KERN_DEBUG "TRANSMIT_PACKET_RECEIVED %x\n", inb(ioaddr + TX_STATUS_REG));
ian@0 805 printk(KERN_DEBUG "RX_STATUS_REG = %x\n", inb(ioaddr + RX_STATUS_REG));
ian@0 806 }
ian@0 807
ian@0 808 return(0); /* Return success */
ian@0 809 }
ian@0 810
ian@0 811 #if 0
ian@0 812 static int eth16i_set_irq(struct net_device* dev)
ian@0 813 {
ian@0 814 const int ioaddr = dev->base_addr;
ian@0 815 const int irq = dev->irq;
ian@0 816 int i = 0;
ian@0 817
ian@0 818 if(ioaddr < 0x1000) {
ian@0 819 while(eth16i_irqmap[i] && eth16i_irqmap[i] != irq)
ian@0 820 i++;
ian@0 821
ian@0 822 if(i < NUM_OF_ISA_IRQS) {
ian@0 823 u8 cbyte = inb(ioaddr + JUMPERLESS_CONFIG);
ian@0 824 cbyte = (cbyte & 0x3F) | (i << 6);
ian@0 825 outb(cbyte, ioaddr + JUMPERLESS_CONFIG);
ian@0 826 return 0;
ian@0 827 }
ian@0 828 }
ian@0 829 else {
ian@0 830 printk(KERN_NOTICE "%s: EISA Interrupt cannot be set. Use EISA Configuration utility.\n", dev->name);
ian@0 831 }
ian@0 832
ian@0 833 return -1;
ian@0 834
ian@0 835 }
ian@0 836 #endif
ian@0 837
ian@0 838 static int __init eth16i_get_irq(int ioaddr)
ian@0 839 {
ian@0 840 unsigned char cbyte;
ian@0 841
ian@0 842 if( ioaddr < 0x1000) {
ian@0 843 cbyte = inb(ioaddr + JUMPERLESS_CONFIG);
ian@0 844 return( eth16i_irqmap[ ((cbyte & 0xC0) >> 6) ] );
ian@0 845 } else { /* Oh..the card is EISA so method getting IRQ different */
ian@0 846 unsigned short index = 0;
ian@0 847 cbyte = inb(ioaddr + EISA_IRQ_REG);
ian@0 848 while( (cbyte & 0x01) == 0) {
ian@0 849 cbyte = cbyte >> 1;
ian@0 850 index++;
ian@0 851 }
ian@0 852 return( eth32i_irqmap[ index ] );
ian@0 853 }
ian@0 854 }
ian@0 855
ian@0 856 static int __init eth16i_check_signature(int ioaddr)
ian@0 857 {
ian@0 858 int i;
ian@0 859 unsigned char creg[4] = { 0 };
ian@0 860
ian@0 861 for(i = 0; i < 4 ; i++) {
ian@0 862
ian@0 863 creg[i] = inb(ioaddr + TRANSMIT_MODE_REG + i);
ian@0 864
ian@0 865 if(eth16i_debug > 1)
ian@0 866 printk("eth16i: read signature byte %x at %x\n",
ian@0 867 creg[i],
ian@0 868 ioaddr + TRANSMIT_MODE_REG + i);
ian@0 869 }
ian@0 870
ian@0 871 creg[0] &= 0x0F; /* Mask collision cnr */
ian@0 872 creg[2] &= 0x7F; /* Mask DCLEN bit */
ian@0 873
ian@0 874 #if 0
ian@0 875 /*
ian@0 876 This was removed because the card was sometimes left to state
ian@0 877 from which it couldn't be find anymore. If there is need
ian@0 878 to more strict check still this have to be fixed.
ian@0 879 */
ian@0 880 if( ! ((creg[0] == 0x06) && (creg[1] == 0x41)) ) {
ian@0 881 if(creg[1] != 0x42)
ian@0 882 return -1;
ian@0 883 }
ian@0 884 #endif
ian@0 885
ian@0 886 if( !((creg[2] == 0x36) && (creg[3] == 0xE0)) ) {
ian@0 887 creg[2] &= 0x40;
ian@0 888 creg[3] &= 0x03;
ian@0 889
ian@0 890 if( !((creg[2] == 0x40) && (creg[3] == 0x00)) )
ian@0 891 return -1;
ian@0 892 }
ian@0 893
ian@0 894 if(eth16i_read_eeprom(ioaddr, E_NODEID_0) != 0)
ian@0 895 return -1;
ian@0 896
ian@0 897 if((eth16i_read_eeprom(ioaddr, E_NODEID_1) & 0xFF00) != 0x4B00)
ian@0 898 return -1;
ian@0 899
ian@0 900 return 0;
ian@0 901 }
ian@0 902
ian@0 903 static int eth16i_read_eeprom(int ioaddr, int offset)
ian@0 904 {
ian@0 905 int data = 0;
ian@0 906
ian@0 907 eth16i_eeprom_cmd(ioaddr, EEPROM_READ | offset);
ian@0 908 outb(CS_1, ioaddr + EEPROM_CTRL_REG);
ian@0 909 data = eth16i_read_eeprom_word(ioaddr);
ian@0 910 outb(CS_0 | SK_0, ioaddr + EEPROM_CTRL_REG);
ian@0 911
ian@0 912 return(data);
ian@0 913 }
ian@0 914
ian@0 915 static int eth16i_read_eeprom_word(int ioaddr)
ian@0 916 {
ian@0 917 int i;
ian@0 918 int data = 0;
ian@0 919
ian@0 920 for(i = 16; i > 0; i--) {
ian@0 921 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
ian@0 922 eeprom_slow_io();
ian@0 923 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
ian@0 924 eeprom_slow_io();
ian@0 925 data = (data << 1) |
ian@0 926 ((inb(ioaddr + EEPROM_DATA_REG) & DI_1) ? 1 : 0);
ian@0 927
ian@0 928 eeprom_slow_io();
ian@0 929 }
ian@0 930
ian@0 931 return(data);
ian@0 932 }
ian@0 933
ian@0 934 static void eth16i_eeprom_cmd(int ioaddr, unsigned char command)
ian@0 935 {
ian@0 936 int i;
ian@0 937
ian@0 938 outb(CS_0 | SK_0, ioaddr + EEPROM_CTRL_REG);
ian@0 939 outb(DI_0, ioaddr + EEPROM_DATA_REG);
ian@0 940 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
ian@0 941 outb(DI_1, ioaddr + EEPROM_DATA_REG);
ian@0 942 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
ian@0 943
ian@0 944 for(i = 7; i >= 0; i--) {
ian@0 945 short cmd = ( (command & (1 << i)) ? DI_1 : DI_0 );
ian@0 946 outb(cmd, ioaddr + EEPROM_DATA_REG);
ian@0 947 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
ian@0 948 eeprom_slow_io();
ian@0 949 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
ian@0 950 eeprom_slow_io();
ian@0 951 }
ian@0 952 }
ian@0 953
ian@0 954 static int eth16i_open(struct net_device *dev)
ian@0 955 {
ian@0 956 struct eth16i_local *lp = netdev_priv(dev);
ian@0 957 int ioaddr = dev->base_addr;
ian@0 958
ian@0 959 /* Powerup the chip */
ian@0 960 outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1);
ian@0 961
ian@0 962 /* Initialize the chip */
ian@0 963 eth16i_initialize(dev, 0);
ian@0 964
ian@0 965 /* Set the transmit buffer size */
ian@0 966 lp->tx_buf_size = eth16i_tx_buf_map[ETH16I_TX_BUF_SIZE & 0x03];
ian@0 967
ian@0 968 if(eth16i_debug > 0)
ian@0 969 printk(KERN_DEBUG "%s: transmit buffer size %d\n",
ian@0 970 dev->name, lp->tx_buf_size);
ian@0 971
ian@0 972 /* Now enable Transmitter and Receiver sections */
ian@0 973 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
ian@0 974
ian@0 975 /* Now switch to register bank 2, for run time operation */
ian@0 976 eth16i_select_regbank(2, ioaddr);
ian@0 977
ian@0 978 lp->open_time = jiffies;
ian@0 979 lp->tx_started = 0;
ian@0 980 lp->tx_queue = 0;
ian@0 981 lp->tx_queue_len = 0;
ian@0 982
ian@0 983 /* Turn on interrupts*/
ian@0 984 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
ian@0 985
ian@0 986 netif_start_queue(dev);
ian@0 987 return 0;
ian@0 988 }
ian@0 989
ian@0 990 static int eth16i_close(struct net_device *dev)
ian@0 991 {
ian@0 992 struct eth16i_local *lp = netdev_priv(dev);
ian@0 993 int ioaddr = dev->base_addr;
ian@0 994
ian@0 995 eth16i_reset(dev);
ian@0 996
ian@0 997 /* Turn off interrupts*/
ian@0 998 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
ian@0 999
ian@0 1000 netif_stop_queue(dev);
ian@0 1001
ian@0 1002 lp->open_time = 0;
ian@0 1003
ian@0 1004 /* Disable transmit and receive */
ian@0 1005 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
ian@0 1006
ian@0 1007 /* Reset the chip */
ian@0 1008 /* outb(0xff, ioaddr + RESET); */
ian@0 1009 /* outw(0xffff, ioaddr + TX_STATUS_REG); */
ian@0 1010
ian@0 1011 outb(0x00, ioaddr + CONFIG_REG_1);
ian@0 1012
ian@0 1013 return 0;
ian@0 1014 }
ian@0 1015
ian@0 1016 static void eth16i_timeout(struct net_device *dev)
ian@0 1017 {
ian@0 1018 struct eth16i_local *lp = netdev_priv(dev);
ian@0 1019 int ioaddr = dev->base_addr;
ian@0 1020 /*
ian@0 1021 If we get here, some higher level has decided that
ian@0 1022 we are broken. There should really be a "kick me"
ian@0 1023 function call instead.
ian@0 1024 */
ian@0 1025
ian@0 1026 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
ian@0 1027 printk(KERN_WARNING "%s: transmit timed out with status %04x, %s ?\n",
ian@0 1028 dev->name,
ian@0 1029 inw(ioaddr + TX_STATUS_REG), (inb(ioaddr + TX_STATUS_REG) & TX_DONE) ?
ian@0 1030 "IRQ conflict" : "network cable problem");
ian@0 1031
ian@0 1032 dev->trans_start = jiffies;
ian@0 1033
ian@0 1034 /* Let's dump all registers */
ian@0 1035 if(eth16i_debug > 0) {
ian@0 1036 printk(KERN_DEBUG "%s: timeout: %02x %02x %02x %02x %02x %02x %02x %02x.\n",
ian@0 1037 dev->name, inb(ioaddr + 0),
ian@0 1038 inb(ioaddr + 1), inb(ioaddr + 2),
ian@0 1039 inb(ioaddr + 3), inb(ioaddr + 4),
ian@0 1040 inb(ioaddr + 5),
ian@0 1041 inb(ioaddr + 6), inb(ioaddr + 7));
ian@0 1042
ian@0 1043 printk(KERN_DEBUG "%s: transmit start reg: %02x. collision reg %02x\n",
ian@0 1044 dev->name, inb(ioaddr + TRANSMIT_START_REG),
ian@0 1045 inb(ioaddr + COL_16_REG));
ian@0 1046 printk(KERN_DEBUG "lp->tx_queue = %d\n", lp->tx_queue);
ian@0 1047 printk(KERN_DEBUG "lp->tx_queue_len = %d\n", lp->tx_queue_len);
ian@0 1048 printk(KERN_DEBUG "lp->tx_started = %d\n", lp->tx_started);
ian@0 1049 }
ian@0 1050 lp->stats.tx_errors++;
ian@0 1051 eth16i_reset(dev);
ian@0 1052 dev->trans_start = jiffies;
ian@0 1053 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
ian@0 1054 netif_wake_queue(dev);
ian@0 1055 }
ian@0 1056
ian@0 1057 static int eth16i_tx(struct sk_buff *skb, struct net_device *dev)
ian@0 1058 {
ian@0 1059 struct eth16i_local *lp = netdev_priv(dev);
ian@0 1060 int ioaddr = dev->base_addr;
ian@0 1061 int status = 0;
ian@0 1062 ushort length = skb->len;
ian@0 1063 unsigned char *buf;
ian@0 1064 unsigned long flags;
ian@0 1065
ian@0 1066 if (length < ETH_ZLEN) {
ian@0 1067 if (skb_padto(skb, ETH_ZLEN))
ian@0 1068 return 0;
ian@0 1069 length = ETH_ZLEN;
ian@0 1070 }
ian@0 1071 buf = skb->data;
ian@0 1072
ian@0 1073 netif_stop_queue(dev);
ian@0 1074
ian@0 1075 /* Turn off TX interrupts */
ian@0 1076 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
ian@0 1077
ian@0 1078 /* We would be better doing the disable_irq tricks the 3c509 does,
ian@0 1079 that would make this suck a lot less */
ian@0 1080
ian@0 1081 spin_lock_irqsave(&lp->lock, flags);
ian@0 1082
ian@0 1083 if( (length + 2) > (lp->tx_buf_size - lp->tx_queue_len)) {
ian@0 1084 if(eth16i_debug > 0)
ian@0 1085 printk(KERN_WARNING "%s: Transmit buffer full.\n", dev->name);
ian@0 1086 }
ian@0 1087 else {
ian@0 1088 outw(length, ioaddr + DATAPORT);
ian@0 1089
ian@0 1090 if( ioaddr < 0x1000 )
ian@0 1091 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
ian@0 1092 else {
ian@0 1093 unsigned char frag = length % 4;
ian@0 1094 outsl(ioaddr + DATAPORT, buf, length >> 2);
ian@0 1095 if( frag != 0 ) {
ian@0 1096 outsw(ioaddr + DATAPORT, (buf + (length & 0xFFFC)), 1);
ian@0 1097 if( frag == 3 )
ian@0 1098 outsw(ioaddr + DATAPORT,
ian@0 1099 (buf + (length & 0xFFFC) + 2), 1);
ian@0 1100 }
ian@0 1101 }
ian@0 1102 lp->tx_buffered_packets++;
ian@0 1103 lp->tx_buffered_bytes = length;
ian@0 1104 lp->tx_queue++;
ian@0 1105 lp->tx_queue_len += length + 2;
ian@0 1106 }
ian@0 1107 lp->tx_buf_busy = 0;
ian@0 1108
ian@0 1109 if(lp->tx_started == 0) {
ian@0 1110 /* If the transmitter is idle..always trigger a transmit */
ian@0 1111 outb(TX_START | lp->tx_queue, ioaddr + TRANSMIT_START_REG);
ian@0 1112 lp->tx_queue = 0;
ian@0 1113 lp->tx_queue_len = 0;
ian@0 1114 dev->trans_start = jiffies;
ian@0 1115 lp->tx_started = 1;
ian@0 1116 netif_wake_queue(dev);
ian@0 1117 }
ian@0 1118 else if(lp->tx_queue_len < lp->tx_buf_size - (ETH_FRAME_LEN + 2)) {
ian@0 1119 /* There is still more room for one more packet in tx buffer */
ian@0 1120 netif_wake_queue(dev);
ian@0 1121 }
ian@0 1122
ian@0 1123 spin_unlock_irqrestore(&lp->lock, flags);
ian@0 1124
ian@0 1125 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
ian@0 1126 /* Turn TX interrupts back on */
ian@0 1127 /* outb(TX_INTR_DONE | TX_INTR_16_COL, ioaddr + TX_INTR_REG); */
ian@0 1128 status = 0;
ian@0 1129 dev_kfree_skb(skb);
ian@0 1130 return 0;
ian@0 1131 }
ian@0 1132
ian@0 1133 static void eth16i_rx(struct net_device *dev)
ian@0 1134 {
ian@0 1135 struct eth16i_local *lp = netdev_priv(dev);
ian@0 1136 int ioaddr = dev->base_addr;
ian@0 1137 int boguscount = MAX_RX_LOOP;
ian@0 1138
ian@0 1139 /* Loop until all packets have been read */
ian@0 1140 while( (inb(ioaddr + RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == 0) {
ian@0 1141
ian@0 1142 /* Read status byte from receive buffer */
ian@0 1143 ushort status = inw(ioaddr + DATAPORT);
ian@0 1144
ian@0 1145 /* Get the size of the packet from receive buffer */
ian@0 1146 ushort pkt_len = inw(ioaddr + DATAPORT);
ian@0 1147
ian@0 1148 if(eth16i_debug > 4)
ian@0 1149 printk(KERN_DEBUG "%s: Receiving packet mode %02x status %04x.\n",
ian@0 1150 dev->name,
ian@0 1151 inb(ioaddr + RECEIVE_MODE_REG), status);
ian@0 1152
ian@0 1153 if( !(status & PKT_GOOD) ) {
ian@0 1154 lp->stats.rx_errors++;
ian@0 1155
ian@0 1156 if( (pkt_len < ETH_ZLEN) || (pkt_len > ETH_FRAME_LEN) ) {
ian@0 1157 lp->stats.rx_length_errors++;
ian@0 1158 eth16i_reset(dev);
ian@0 1159 return;
ian@0 1160 }
ian@0 1161 else {
ian@0 1162 eth16i_skip_packet(dev);
ian@0 1163 lp->stats.rx_dropped++;
ian@0 1164 }
ian@0 1165 }
ian@0 1166 else { /* Ok so now we should have a good packet */
ian@0 1167 struct sk_buff *skb;
ian@0 1168
ian@0 1169 skb = dev_alloc_skb(pkt_len + 3);
ian@0 1170 if( skb == NULL ) {
ian@0 1171 printk(KERN_WARNING "%s: Could'n allocate memory for packet (len %d)\n",
ian@0 1172 dev->name, pkt_len);
ian@0 1173 eth16i_skip_packet(dev);
ian@0 1174 lp->stats.rx_dropped++;
ian@0 1175 break;
ian@0 1176 }
ian@0 1177
ian@0 1178 skb->dev = dev;
ian@0 1179 skb_reserve(skb,2);
ian@0 1180
ian@0 1181 /*
ian@0 1182 Now let's get the packet out of buffer.
ian@0 1183 size is (pkt_len + 1) >> 1, cause we are now reading words
ian@0 1184 and it have to be even aligned.
ian@0 1185 */
ian@0 1186
ian@0 1187 if(ioaddr < 0x1000)
ian@0 1188 insw(ioaddr + DATAPORT, skb_put(skb, pkt_len),
ian@0 1189 (pkt_len + 1) >> 1);
ian@0 1190 else {
ian@0 1191 unsigned char *buf = skb_put(skb, pkt_len);
ian@0 1192 unsigned char frag = pkt_len % 4;
ian@0 1193
ian@0 1194 insl(ioaddr + DATAPORT, buf, pkt_len >> 2);
ian@0 1195
ian@0 1196 if(frag != 0) {
ian@0 1197 unsigned short rest[2];
ian@0 1198 rest[0] = inw( ioaddr + DATAPORT );
ian@0 1199 if(frag == 3)
ian@0 1200 rest[1] = inw( ioaddr + DATAPORT );
ian@0 1201
ian@0 1202 memcpy(buf + (pkt_len & 0xfffc), (char *)rest, frag);
ian@0 1203 }
ian@0 1204 }
ian@0 1205
ian@0 1206 skb->protocol=eth_type_trans(skb, dev);
ian@0 1207
ian@0 1208 if( eth16i_debug > 5 ) {
ian@0 1209 int i;
ian@0 1210 printk(KERN_DEBUG "%s: Received packet of length %d.\n",
ian@0 1211 dev->name, pkt_len);
ian@0 1212 for(i = 0; i < 14; i++)
ian@0 1213 printk(KERN_DEBUG " %02x", skb->data[i]);
ian@0 1214 printk(KERN_DEBUG ".\n");
ian@0 1215 }
ian@0 1216 netif_rx(skb);
ian@0 1217 dev->last_rx = jiffies;
ian@0 1218 lp->stats.rx_packets++;
ian@0 1219 lp->stats.rx_bytes += pkt_len;
ian@0 1220
ian@0 1221 } /* else */
ian@0 1222
ian@0 1223 if(--boguscount <= 0)
ian@0 1224 break;
ian@0 1225
ian@0 1226 } /* while */
ian@0 1227 }
ian@0 1228
ian@0 1229 static irqreturn_t eth16i_interrupt(int irq, void *dev_id, struct pt_regs *regs)
ian@0 1230 {
ian@0 1231 struct net_device *dev = dev_id;
ian@0 1232 struct eth16i_local *lp;
ian@0 1233 int ioaddr = 0, status;
ian@0 1234 int handled = 0;
ian@0 1235
ian@0 1236 ioaddr = dev->base_addr;
ian@0 1237 lp = netdev_priv(dev);
ian@0 1238
ian@0 1239 /* Turn off all interrupts from adapter */
ian@0 1240 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
ian@0 1241
ian@0 1242 /* eth16i_tx won't be called */
ian@0 1243 spin_lock(&lp->lock);
ian@0 1244
ian@0 1245 status = inw(ioaddr + TX_STATUS_REG); /* Get the status */
ian@0 1246 outw(status, ioaddr + TX_STATUS_REG); /* Clear status bits */
ian@0 1247
ian@0 1248 if (status)
ian@0 1249 handled = 1;
ian@0 1250
ian@0 1251 if(eth16i_debug > 3)
ian@0 1252 printk(KERN_DEBUG "%s: Interrupt with status %04x.\n", dev->name, status);
ian@0 1253
ian@0 1254 if( status & 0x7f00 ) {
ian@0 1255
ian@0 1256 lp->stats.rx_errors++;
ian@0 1257
ian@0 1258 if(status & (BUS_RD_ERR << 8) )
ian@0 1259 printk(KERN_WARNING "%s: Bus read error.\n",dev->name);
ian@0 1260 if(status & (SHORT_PKT_ERR << 8) ) lp->stats.rx_length_errors++;
ian@0 1261 if(status & (ALIGN_ERR << 8) ) lp->stats.rx_frame_errors++;
ian@0 1262 if(status & (CRC_ERR << 8) ) lp->stats.rx_crc_errors++;
ian@0 1263 if(status & (RX_BUF_OVERFLOW << 8) ) lp->stats.rx_over_errors++;
ian@0 1264 }
ian@0 1265 if( status & 0x001a) {
ian@0 1266
ian@0 1267 lp->stats.tx_errors++;
ian@0 1268
ian@0 1269 if(status & CR_LOST) lp->stats.tx_carrier_errors++;
ian@0 1270 if(status & TX_JABBER_ERR) lp->stats.tx_window_errors++;
ian@0 1271
ian@0 1272 #if 0
ian@0 1273 if(status & COLLISION) {
ian@0 1274 lp->stats.collisions +=
ian@0 1275 ((inb(ioaddr+TRANSMIT_MODE_REG) & 0xF0) >> 4);
ian@0 1276 }
ian@0 1277 #endif
ian@0 1278 if(status & COLLISIONS_16) {
ian@0 1279 if(lp->col_16 < MAX_COL_16) {
ian@0 1280 lp->col_16++;
ian@0 1281 lp->stats.collisions++;
ian@0 1282 /* Resume transmitting, skip failed packet */
ian@0 1283 outb(0x02, ioaddr + COL_16_REG);
ian@0 1284 }
ian@0 1285 else {
ian@0 1286 printk(KERN_WARNING "%s: bailing out due to many consecutive 16-in-a-row collisions. Network cable problem?\n", dev->name);
ian@0 1287 }
ian@0 1288 }
ian@0 1289 }
ian@0 1290
ian@0 1291 if( status & 0x00ff ) { /* Let's check the transmit status reg */
ian@0 1292
ian@0 1293 if(status & TX_DONE) { /* The transmit has been done */
ian@0 1294 lp->stats.tx_packets = lp->tx_buffered_packets;
ian@0 1295 lp->stats.tx_bytes += lp->tx_buffered_bytes;
ian@0 1296 lp->col_16 = 0;
ian@0 1297
ian@0 1298 if(lp->tx_queue) { /* Is there still packets ? */
ian@0 1299 /* There was packet(s) so start transmitting and write also
ian@0 1300 how many packets there is to be sended */
ian@0 1301 outb(TX_START | lp->tx_queue, ioaddr + TRANSMIT_START_REG);
ian@0 1302 lp->tx_queue = 0;
ian@0 1303 lp->tx_queue_len = 0;
ian@0 1304 lp->tx_started = 1;
ian@0 1305 }
ian@0 1306 else {
ian@0 1307 lp->tx_started = 0;
ian@0 1308 }
ian@0 1309 netif_wake_queue(dev);
ian@0 1310 }
ian@0 1311 }
ian@0 1312
ian@0 1313 if( ( status & 0x8000 ) ||
ian@0 1314 ( (inb(ioaddr + RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == 0) ) {
ian@0 1315 eth16i_rx(dev); /* We have packet in receive buffer */
ian@0 1316 }
ian@0 1317
ian@0 1318 /* Turn interrupts back on */
ian@0 1319 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
ian@0 1320
ian@0 1321 if(lp->tx_queue_len < lp->tx_buf_size - (ETH_FRAME_LEN + 2)) {
ian@0 1322 /* There is still more room for one more packet in tx buffer */
ian@0 1323 netif_wake_queue(dev);
ian@0 1324 }
ian@0 1325
ian@0 1326 spin_unlock(&lp->lock);
ian@0 1327
ian@0 1328 return IRQ_RETVAL(handled);
ian@0 1329 }
ian@0 1330
ian@0 1331 static void eth16i_skip_packet(struct net_device *dev)
ian@0 1332 {
ian@0 1333 int ioaddr = dev->base_addr;
ian@0 1334
ian@0 1335 inw(ioaddr + DATAPORT);
ian@0 1336 inw(ioaddr + DATAPORT);
ian@0 1337 inw(ioaddr + DATAPORT);
ian@0 1338
ian@0 1339 outb(SKIP_RX_PACKET, ioaddr + FILTER_SELF_RX_REG);
ian@0 1340 while( inb( ioaddr + FILTER_SELF_RX_REG ) != 0);
ian@0 1341 }
ian@0 1342
ian@0 1343 static void eth16i_reset(struct net_device *dev)
ian@0 1344 {
ian@0 1345 struct eth16i_local *lp = netdev_priv(dev);
ian@0 1346 int ioaddr = dev->base_addr;
ian@0 1347
ian@0 1348 if(eth16i_debug > 1)
ian@0 1349 printk(KERN_DEBUG "%s: Resetting device.\n", dev->name);
ian@0 1350
ian@0 1351 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
ian@0 1352 outw(0xffff, ioaddr + TX_STATUS_REG);
ian@0 1353 eth16i_select_regbank(2, ioaddr);
ian@0 1354
ian@0 1355 lp->tx_started = 0;
ian@0 1356 lp->tx_buf_busy = 0;
ian@0 1357 lp->tx_queue = 0;
ian@0 1358 lp->tx_queue_len = 0;
ian@0 1359 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
ian@0 1360 }
ian@0 1361
ian@0 1362 static void eth16i_multicast(struct net_device *dev)
ian@0 1363 {
ian@0 1364 int ioaddr = dev->base_addr;
ian@0 1365
ian@0 1366 if(dev->mc_count || dev->flags&(IFF_ALLMULTI|IFF_PROMISC))
ian@0 1367 {
ian@0 1368 dev->flags|=IFF_PROMISC; /* Must do this */
ian@0 1369 outb(3, ioaddr + RECEIVE_MODE_REG);
ian@0 1370 } else {
ian@0 1371 outb(2, ioaddr + RECEIVE_MODE_REG);
ian@0 1372 }
ian@0 1373 }
ian@0 1374
ian@0 1375 static struct net_device_stats *eth16i_get_stats(struct net_device *dev)
ian@0 1376 {
ian@0 1377 struct eth16i_local *lp = netdev_priv(dev);
ian@0 1378 return &lp->stats;
ian@0 1379 }
ian@0 1380
ian@0 1381 static void eth16i_select_regbank(unsigned char banknbr, int ioaddr)
ian@0 1382 {
ian@0 1383 unsigned char data;
ian@0 1384
ian@0 1385 data = inb(ioaddr + CONFIG_REG_1);
ian@0 1386 outb( ((data & 0xF3) | ( (banknbr & 0x03) << 2)), ioaddr + CONFIG_REG_1);
ian@0 1387 }
ian@0 1388
ian@0 1389 #ifdef MODULE
ian@0 1390
ian@0 1391 static ushort eth16i_parse_mediatype(const char* s)
ian@0 1392 {
ian@0 1393 if(!s)
ian@0 1394 return E_PORT_FROM_EPROM;
ian@0 1395
ian@0 1396 if (!strncmp(s, "bnc", 3))
ian@0 1397 return E_PORT_BNC;
ian@0 1398 else if (!strncmp(s, "tp", 2))
ian@0 1399 return E_PORT_TP;
ian@0 1400 else if (!strncmp(s, "dix", 3))
ian@0 1401 return E_PORT_DIX;
ian@0 1402 else if (!strncmp(s, "auto", 4))
ian@0 1403 return E_PORT_AUTO;
ian@0 1404 else
ian@0 1405 return E_PORT_FROM_EPROM;
ian@0 1406 }
ian@0 1407
ian@0 1408 #define MAX_ETH16I_CARDS 4 /* Max number of Eth16i cards per module */
ian@0 1409
ian@0 1410 static struct net_device *dev_eth16i[MAX_ETH16I_CARDS];
ian@0 1411 static int io[MAX_ETH16I_CARDS];
ian@0 1412 #if 0
ian@0 1413 static int irq[MAX_ETH16I_CARDS];
ian@0 1414 #endif
ian@0 1415 static char* mediatype[MAX_ETH16I_CARDS];
ian@0 1416 static int debug = -1;
ian@0 1417
ian@0 1418 MODULE_AUTHOR("Mika Kuoppala <miku@iki.fi>");
ian@0 1419 MODULE_DESCRIPTION("ICL EtherTeam 16i/32 driver");
ian@0 1420 MODULE_LICENSE("GPL");
ian@0 1421
ian@0 1422
ian@0 1423 module_param_array(io, int, NULL, 0);
ian@0 1424 MODULE_PARM_DESC(io, "eth16i I/O base address(es)");
ian@0 1425
ian@0 1426 #if 0
ian@0 1427 module_param_array(irq, int, NULL, 0);
ian@0 1428 MODULE_PARM_DESC(irq, "eth16i interrupt request number");
ian@0 1429 #endif
ian@0 1430
ian@0 1431 module_param_array(mediatype, charp, NULL, 0);
ian@0 1432 MODULE_PARM_DESC(mediatype, "eth16i media type of interface(s) (bnc,tp,dix,auto,eprom)");
ian@0 1433
ian@0 1434 module_param(debug, int, 0);
ian@0 1435 MODULE_PARM_DESC(debug, "eth16i debug level (0-6)");
ian@0 1436
ian@0 1437 int __init init_module(void)
ian@0 1438 {
ian@0 1439 int this_dev, found = 0;
ian@0 1440 struct net_device *dev;
ian@0 1441
ian@0 1442 for (this_dev = 0; this_dev < MAX_ETH16I_CARDS; this_dev++) {
ian@0 1443 dev = alloc_etherdev(sizeof(struct eth16i_local));
ian@0 1444 if (!dev)
ian@0 1445 break;
ian@0 1446
ian@0 1447 dev->base_addr = io[this_dev];
ian@0 1448
ian@0 1449 if(debug != -1)
ian@0 1450 eth16i_debug = debug;
ian@0 1451
ian@0 1452 if(eth16i_debug > 1)
ian@0 1453 printk(KERN_NOTICE "eth16i(%d): interface type %s\n", this_dev, mediatype[this_dev] ? mediatype[this_dev] : "none" );
ian@0 1454
ian@0 1455 dev->if_port = eth16i_parse_mediatype(mediatype[this_dev]);
ian@0 1456
ian@0 1457 if(io[this_dev] == 0) {
ian@0 1458 if(this_dev != 0) /* Only autoprobe 1st one */
ian@0 1459 break;
ian@0 1460
ian@0 1461 printk(KERN_NOTICE "eth16i.c: Presently autoprobing (not recommended) for a single card.\n");
ian@0 1462 }
ian@0 1463
ian@0 1464 if (do_eth16i_probe(dev) == 0) {
ian@0 1465 dev_eth16i[found++] = dev;
ian@0 1466 continue;
ian@0 1467 }
ian@0 1468 printk(KERN_WARNING "eth16i.c No Eth16i card found (i/o = 0x%x).\n",
ian@0 1469 io[this_dev]);
ian@0 1470 free_netdev(dev);
ian@0 1471 break;
ian@0 1472 }
ian@0 1473 if (found)
ian@0 1474 return 0;
ian@0 1475 return -ENXIO;
ian@0 1476 }
ian@0 1477
ian@0 1478 void cleanup_module(void)
ian@0 1479 {
ian@0 1480 int this_dev;
ian@0 1481
ian@0 1482 for(this_dev = 0; this_dev < MAX_ETH16I_CARDS; this_dev++) {
ian@0 1483 struct net_device *dev = dev_eth16i[this_dev];
ian@0 1484
ian@0 1485 if(dev->priv) {
ian@0 1486 unregister_netdev(dev);
ian@0 1487 free_irq(dev->irq, dev);
ian@0 1488 release_region(dev->base_addr, ETH16I_IO_EXTENT);
ian@0 1489 free_netdev(dev);
ian@0 1490 }
ian@0 1491 }
ian@0 1492 }
ian@0 1493 #endif /* MODULE */
ian@0 1494
ian@0 1495 /*
ian@0 1496 * Local variables:
ian@0 1497 * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c eth16i.c"
ian@0 1498 * alt-compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict -prototypes -O6 -c eth16i.c"
ian@0 1499 * tab-width: 8
ian@0 1500 * c-basic-offset: 8
ian@0 1501 * c-indent-level: 8
ian@0 1502 * End:
ian@0 1503 */
ian@0 1504
ian@0 1505 /* End of file eth16i.c */