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