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 General Public License, incorporated herein by reference.
11 The author may be reached as miku@iki.fi
13 This driver supports following cards :
15 - ICL EtherTeam 32 EISA
16 (Uses true 32 bit transfers rather than 16i compability mode)
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.
30 - skeleton.c a sample network driver core for linux,
31 written by Donald Becker <becker@scyld.com>
32 - at1700.c a driver for Allied Telesis AT1700, written
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:
42 Kurt Huwig <kurt@huwig.de>
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
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
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
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
79 0.22 22.02-96 Receive buffer was not flushed
80 correctly when faulty packet was
83 0.23 26.02-96 Made resetting the adapter
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
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
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
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).
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>
149 #include <linux/kernel.h>
150 #include <linux/types.h>
151 #include <linux/fcntl.h>
152 #include <linux/interrupt.h>
153 #include <linux/ioport.h>
154 #include <linux/in.h>
155 #include <linux/slab.h>
156 #include <linux/string.h>
157 #include <linux/errno.h>
158 #include <linux/init.h>
159 #include <linux/spinlock.h>
160 #include <linux/netdevice.h>
161 #include <linux/etherdevice.h>
162 #include <linux/skbuff.h>
163 #include <linux/bitops.h>
164 #include <linux/jiffies.h>
165 #include <linux/io.h>
167 #include <asm/system.h>
173 #define BIT(a) ( (1 << (a)) )
174 #define BITSET(ioaddr, bnum) ((outb(((inb(ioaddr)) | (bnum)), ioaddr)))
175 #define BITCLR(ioaddr, bnum) ((outb(((inb(ioaddr)) & (~(bnum))), ioaddr)))
177 /* This is the I/O address space for Etherteam 16i adapter. */
178 #define ETH16I_IO_EXTENT 32
180 /* Ticks before deciding that transmit has timed out */
181 #define TX_TIMEOUT (400*HZ/1000)
183 /* Maximum loop count when receiving packets */
184 #define MAX_RX_LOOP 20
186 /* Some interrupt masks */
187 #define ETH16I_INTR_ON 0xef8a /* Higher is receive mask */
188 #define ETH16I_INTR_OFF 0x0000
190 /* Buffers header status byte meanings */
191 #define PKT_GOOD BIT(5)
192 #define PKT_GOOD_RMT BIT(4)
193 #define PKT_SHORT BIT(3)
194 #define PKT_ALIGN_ERR BIT(2)
195 #define PKT_CRC_ERR BIT(1)
196 #define PKT_RX_BUF_OVERFLOW BIT(0)
198 /* Transmit status register (DLCR0) */
199 #define TX_STATUS_REG 0
200 #define TX_DONE BIT(7)
201 #define NET_BUSY BIT(6)
202 #define TX_PKT_RCD BIT(5)
203 #define CR_LOST BIT(4)
204 #define TX_JABBER_ERR BIT(3)
205 #define COLLISION BIT(2)
206 #define COLLISIONS_16 BIT(1)
208 /* Receive status register (DLCR1) */
209 #define RX_STATUS_REG 1
210 #define RX_PKT BIT(7) /* Packet received */
211 #define BUS_RD_ERR BIT(6)
212 #define SHORT_PKT_ERR BIT(3)
213 #define ALIGN_ERR BIT(2)
214 #define CRC_ERR BIT(1)
215 #define RX_BUF_OVERFLOW BIT(0)
217 /* Transmit Interrupt Enable Register (DLCR2) */
218 #define TX_INTR_REG 2
219 #define TX_INTR_DONE BIT(7)
220 #define TX_INTR_COL BIT(2)
221 #define TX_INTR_16_COL BIT(1)
223 /* Receive Interrupt Enable Register (DLCR3) */
224 #define RX_INTR_REG 3
225 #define RX_INTR_RECEIVE BIT(7)
226 #define RX_INTR_SHORT_PKT BIT(3)
227 #define RX_INTR_CRC_ERR BIT(1)
228 #define RX_INTR_BUF_OVERFLOW BIT(0)
230 /* Transmit Mode Register (DLCR4) */
231 #define TRANSMIT_MODE_REG 4
232 #define LOOPBACK_CONTROL BIT(1)
233 #define CONTROL_OUTPUT BIT(2)
235 /* Receive Mode Register (DLCR5) */
236 #define RECEIVE_MODE_REG 5
237 #define RX_BUFFER_EMPTY BIT(6)
238 #define ACCEPT_BAD_PACKETS BIT(5)
239 #define RECEIVE_SHORT_ADDR BIT(4)
240 #define ACCEPT_SHORT_PACKETS BIT(3)
241 #define REMOTE_RESET BIT(2)
243 #define ADDRESS_FILTER_MODE BIT(1) | BIT(0)
246 #define MODE_1 1 /* NODE ID, BC, MC, 2-24th bit */
247 #define MODE_2 2 /* NODE ID, BC, MC, Hash Table */
249 /* Configuration Register 0 (DLCR6) */
250 #define CONFIG_REG_0 6
251 #define DLC_EN BIT(7)
252 #define SRAM_CYCLE_TIME_100NS BIT(6)
253 #define SYSTEM_BUS_WIDTH_8 BIT(5) /* 1 = 8bit, 0 = 16bit */
254 #define BUFFER_WIDTH_8 BIT(4) /* 1 = 8bit, 0 = 16bit */
257 #define SRAM_BS1 BIT(1) /* 00=8kb, 01=16kb */
258 #define SRAM_BS0 BIT(0) /* 10=32kb, 11=64kb */
260 #ifndef ETH16I_TX_BUF_SIZE /* 0 = 2kb, 1 = 4kb */
261 #define ETH16I_TX_BUF_SIZE 3 /* 2 = 8kb, 3 = 16kb */
263 #define TX_BUF_1x2048 0
264 #define TX_BUF_2x2048 1
265 #define TX_BUF_2x4098 2
266 #define TX_BUF_2x8192 3
268 /* Configuration Register 1 (DLCR7) */
269 #define CONFIG_REG_1 7
270 #define POWERUP BIT(5)
272 /* Transmit start register */
273 #define TRANSMIT_START_REG 10
274 #define TRANSMIT_START_RB 2
275 #define TX_START BIT(7) /* Rest of register bit indicate*/
276 /* number of packets in tx buffer*/
277 /* Node ID registers (DLCR8-13) */
281 /* Hash Table registers (HT8-15) */
282 #define HASH_TABLE_0 8
283 #define HASH_TABLE_RB 1
285 /* Buffer memory ports */
286 #define BUFFER_MEM_PORT_LB 8
287 #define DATAPORT BUFFER_MEM_PORT_LB
288 #define BUFFER_MEM_PORT_HB 9
290 /* 16 Collision control register (BMPR11) */
291 #define COL_16_REG 11
292 #define HALT_ON_16 0x00
293 #define RETRANS_AND_HALT_ON_16 0x02
295 /* Maximum number of attempts to send after 16 concecutive collisions */
296 #define MAX_COL_16 10
298 /* DMA Burst and Transceiver Mode Register (BMPR13) */
299 #define TRANSCEIVER_MODE_REG 13
300 #define TRANSCEIVER_MODE_RB 2
301 #define IO_BASE_UNLOCK BIT(7)
302 #define LOWER_SQUELCH_TRESH BIT(6)
303 #define LINK_TEST_DISABLE BIT(5)
304 #define AUI_SELECT BIT(4)
305 #define DIS_AUTO_PORT_SEL BIT(3)
307 /* Filter Self Receive Register (BMPR14) */
308 #define FILTER_SELF_RX_REG 14
309 #define SKIP_RX_PACKET BIT(2)
310 #define FILTER_SELF_RECEIVE BIT(0)
312 /* EEPROM Control Register (BMPR 16) */
313 #define EEPROM_CTRL_REG 16
315 /* EEPROM Data Register (BMPR 17) */
316 #define EEPROM_DATA_REG 17
318 /* NMC93CSx6 EEPROM Control Bits */
326 /* NMC93CSx6 EEPROM Instructions */
327 #define EEPROM_READ 0x80
329 /* NMC93CSx6 EEPROM Addresses */
330 #define E_NODEID_0 0x02
331 #define E_NODEID_1 0x03
332 #define E_NODEID_2 0x04
333 #define E_PORT_SELECT 0x14
334 #define E_PORT_BNC 0x00
335 #define E_PORT_DIX 0x01
336 #define E_PORT_TP 0x02
337 #define E_PORT_AUTO 0x03
338 #define E_PORT_FROM_EPROM 0x04
339 #define E_PRODUCT_CFG 0x30
342 /* Macro to slow down io between EEPROM clock transitions */
343 #define eeprom_slow_io() do { int _i = 40; while(--_i > 0) { inb(0x80); }}while(0)
345 /* Jumperless Configuration Register (BMPR19) */
346 #define JUMPERLESS_CONFIG 19
348 /* ID ROM registers, writing to them also resets some parts of chip */
351 #define RESET ID_ROM_0
353 /* This is the I/O address list to be probed when seeking the card */
354 static unsigned int eth16i_portlist[] __initdata = {
355 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300, 0
358 static unsigned int eth32i_portlist[] __initdata = {
359 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000, 0x8000,
360 0x9000, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, 0
363 /* This is the Interrupt lookup table for Eth16i card */
364 static unsigned int eth16i_irqmap[] __initdata = { 9, 10, 5, 15, 0 };
365 #define NUM_OF_ISA_IRQS 4
367 /* This is the Interrupt lookup table for Eth32i card */
368 static unsigned int eth32i_irqmap[] __initdata = { 3, 5, 7, 9, 10, 11, 12, 15, 0 };
369 #define EISA_IRQ_REG 0xc89
370 #define NUM_OF_EISA_IRQS 8
372 static unsigned int eth16i_tx_buf_map[] = { 2048, 2048, 4096, 8192 };
374 /* Use 0 for production, 1 for verification, >2 for debug */
376 #define ETH16I_DEBUG 0
378 static unsigned int eth16i_debug = ETH16I_DEBUG;
380 /* Information for each board */
382 struct eth16i_local {
383 struct net_device_stats stats;
384 unsigned char tx_started;
385 unsigned char tx_buf_busy;
386 unsigned short tx_queue; /* Number of packets in transmit buffer */
387 unsigned short tx_queue_len;
388 unsigned int tx_buf_size;
389 unsigned long open_time;
390 unsigned long tx_buffered_packets;
391 unsigned long tx_buffered_bytes;
392 unsigned long col_16;
396 /* Function prototypes */
398 static int eth16i_probe1(struct net_device *dev, int ioaddr);
399 static int eth16i_check_signature(int ioaddr);
400 static int eth16i_probe_port(int ioaddr);
401 static void eth16i_set_port(int ioaddr, int porttype);
402 static int eth16i_send_probe_packet(int ioaddr, unsigned char *b, int l);
403 static int eth16i_receive_probe_packet(int ioaddr);
404 static int eth16i_get_irq(int ioaddr);
405 static int eth16i_read_eeprom(int ioaddr, int offset);
406 static int eth16i_read_eeprom_word(int ioaddr);
407 static void eth16i_eeprom_cmd(int ioaddr, unsigned char command);
408 static int eth16i_open(struct net_device *dev);
409 static int eth16i_close(struct net_device *dev);
410 static int eth16i_tx(struct sk_buff *skb, struct net_device *dev);
411 static void eth16i_rx(struct net_device *dev);
412 static void eth16i_timeout(struct net_device *dev);
413 static irqreturn_t eth16i_interrupt(int irq, void *dev_id);
414 static void eth16i_reset(struct net_device *dev);
415 static void eth16i_timeout(struct net_device *dev);
416 static void eth16i_skip_packet(struct net_device *dev);
417 static void eth16i_multicast(struct net_device *dev);
418 static void eth16i_select_regbank(unsigned char regbank, int ioaddr);
419 static void eth16i_initialize(struct net_device *dev, int boot);
422 static int eth16i_set_irq(struct net_device *dev);
426 static ushort eth16i_parse_mediatype(const char* s);
429 static struct net_device_stats *eth16i_get_stats(struct net_device *dev);
431 static char cardname[] __initdata = "ICL EtherTeam 16i/32";
433 static int __init do_eth16i_probe(struct net_device *dev)
437 int base_addr = dev->base_addr;
439 SET_MODULE_OWNER(dev);
442 printk(KERN_DEBUG "Probing started for %s\n", cardname);
444 if(base_addr > 0x1ff) /* Check only single location */
445 return eth16i_probe1(dev, base_addr);
446 else if(base_addr != 0) /* Don't probe at all */
449 /* Seek card from the ISA io address space */
450 for(i = 0; (ioaddr = eth16i_portlist[i]) ; i++)
451 if(eth16i_probe1(dev, ioaddr) == 0)
454 /* Seek card from the EISA io address space */
455 for(i = 0; (ioaddr = eth32i_portlist[i]) ; i++)
456 if(eth16i_probe1(dev, ioaddr) == 0)
463 struct net_device * __init eth16i_probe(int unit)
465 struct net_device *dev = alloc_etherdev(sizeof(struct eth16i_local));
469 return ERR_PTR(-ENOMEM);
471 sprintf(dev->name, "eth%d", unit);
472 netdev_boot_setup_check(dev);
474 err = do_eth16i_probe(dev);
484 static int __init eth16i_probe1(struct net_device *dev, int ioaddr)
486 struct eth16i_local *lp = netdev_priv(dev);
487 static unsigned version_printed;
490 /* Let's grab the region */
491 if (!request_region(ioaddr, ETH16I_IO_EXTENT, cardname))
495 The MB86985 chip has on register which holds information in which
496 io address the chip lies. First read this register and compare
497 it to our current io address and if match then this could
501 if(ioaddr < 0x1000) {
502 if(eth16i_portlist[(inb(ioaddr + JUMPERLESS_CONFIG) & 0x07)]
509 /* Now we will go a bit deeper and try to find the chip's signature */
511 if(eth16i_check_signature(ioaddr) != 0) {
517 Now it seems that we have found a ethernet chip in this particular
518 ioaddr. The MB86985 chip has this feature, that when you read a
519 certain register it will increase it's io base address to next
520 configurable slot. Now when we have found the chip, first thing is
521 to make sure that the chip's ioaddr will hold still here.
524 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
525 outb(0x00, ioaddr + TRANSCEIVER_MODE_REG);
527 outb(0x00, ioaddr + RESET); /* Reset some parts of chip */
528 BITSET(ioaddr + CONFIG_REG_0, BIT(7)); /* Disable the data link */
530 if( (eth16i_debug & version_printed++) == 0)
531 printk(KERN_INFO "%s", version);
533 dev->base_addr = ioaddr;
534 dev->irq = eth16i_get_irq(ioaddr);
536 /* Try to obtain interrupt vector */
538 if ((retval = request_irq(dev->irq, (void *)ð16i_interrupt, 0, cardname, dev))) {
539 printk(KERN_WARNING "%s at %#3x, but is unusable due to conflicting IRQ %d.\n",
540 cardname, ioaddr, dev->irq);
544 printk(KERN_INFO "%s: %s at %#3x, IRQ %d, ",
545 dev->name, cardname, ioaddr, dev->irq);
548 /* Now we will have to lock the chip's io address */
549 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
550 outb(0x38, ioaddr + TRANSCEIVER_MODE_REG);
552 eth16i_initialize(dev, 1); /* Initialize rest of the chip's registers */
554 /* Now let's same some energy by shutting down the chip ;) */
555 BITCLR(ioaddr + CONFIG_REG_1, POWERUP);
557 /* Initialize the device structure */
558 memset(lp, 0, sizeof(struct eth16i_local));
559 dev->open = eth16i_open;
560 dev->stop = eth16i_close;
561 dev->hard_start_xmit = eth16i_tx;
562 dev->get_stats = eth16i_get_stats;
563 dev->set_multicast_list = eth16i_multicast;
564 dev->tx_timeout = eth16i_timeout;
565 dev->watchdog_timeo = TX_TIMEOUT;
566 spin_lock_init(&lp->lock);
568 retval = register_netdev(dev);
573 free_irq(dev->irq, dev);
575 release_region(ioaddr, ETH16I_IO_EXTENT);
580 static void eth16i_initialize(struct net_device *dev, int boot)
582 int ioaddr = dev->base_addr;
584 unsigned char node_byte = 0;
586 /* Setup station address */
587 eth16i_select_regbank(NODE_ID_RB, ioaddr);
588 for(i = 0 ; i < 3 ; i++) {
589 unsigned short node_val = eth16i_read_eeprom(ioaddr, E_NODEID_0 + i);
590 ((unsigned short *)dev->dev_addr)[i] = ntohs(node_val);
593 for(i = 0; i < 6; i++) {
594 outb( ((unsigned char *)dev->dev_addr)[i], ioaddr + NODE_ID_0 + i);
596 printk("%02x", inb(ioaddr + NODE_ID_0 + i));
602 /* Now we will set multicast addresses to accept none */
603 eth16i_select_regbank(HASH_TABLE_RB, ioaddr);
604 for(i = 0; i < 8; i++)
605 outb(0x00, ioaddr + HASH_TABLE_0 + i);
608 Now let's disable the transmitter and receiver, set the buffer ram
609 cycle time, bus width and buffer data path width. Also we shall
610 set transmit buffer size and total buffer size.
613 eth16i_select_regbank(2, ioaddr);
616 node_w = eth16i_read_eeprom(ioaddr, E_PRODUCT_CFG);
618 if( (node_w & 0xFF00) == 0x0800)
619 node_byte |= BUFFER_WIDTH_8;
621 node_byte |= SRAM_BS1;
623 if( (node_w & 0x00FF) == 64)
624 node_byte |= SRAM_BS0;
626 node_byte |= DLC_EN | SRAM_CYCLE_TIME_100NS | (ETH16I_TX_BUF_SIZE << 2);
628 outb(node_byte, ioaddr + CONFIG_REG_0);
630 /* We shall halt the transmitting, if 16 collisions are detected */
631 outb(HALT_ON_16, ioaddr + COL_16_REG);
634 /* if_port already set by init_module() */
636 dev->if_port = (dev->mem_start < E_PORT_FROM_EPROM) ?
637 dev->mem_start : E_PORT_FROM_EPROM;
640 /* Set interface port type */
642 char *porttype[] = {"BNC", "DIX", "TP", "AUTO", "FROM_EPROM" };
647 case E_PORT_FROM_EPROM:
648 dev->if_port = eth16i_read_eeprom(ioaddr, E_PORT_SELECT);
652 dev->if_port = eth16i_probe_port(ioaddr);
661 printk(" %s interface.\n", porttype[dev->if_port]);
663 eth16i_set_port(ioaddr, dev->if_port);
666 /* Set Receive Mode to normal operation */
667 outb(MODE_2, ioaddr + RECEIVE_MODE_REG);
670 static int eth16i_probe_port(int ioaddr)
674 unsigned char dummy_packet[64];
676 /* Powerup the chip */
677 outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1);
679 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
681 eth16i_select_regbank(NODE_ID_RB, ioaddr);
683 for(i = 0; i < 6; i++) {
684 dummy_packet[i] = inb(ioaddr + NODE_ID_0 + i);
685 dummy_packet[i+6] = inb(ioaddr + NODE_ID_0 + i);
688 dummy_packet[12] = 0x00;
689 dummy_packet[13] = 0x04;
690 memset(dummy_packet + 14, 0, sizeof(dummy_packet) - 14);
692 eth16i_select_regbank(2, ioaddr);
694 for(i = 0; i < 3; i++) {
695 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
696 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
697 eth16i_set_port(ioaddr, i);
700 printk(KERN_DEBUG "Set port number %d\n", i);
702 retcode = eth16i_send_probe_packet(ioaddr, dummy_packet, 64);
704 retcode = eth16i_receive_probe_packet(ioaddr);
707 printk(KERN_DEBUG "Eth16i interface port found at %d\n", i);
713 printk(KERN_DEBUG "TRANSMIT_DONE timeout when probing interface port\n");
717 if( eth16i_debug > 1)
718 printk(KERN_DEBUG "Using default port\n");
723 static void eth16i_set_port(int ioaddr, int porttype)
725 unsigned short temp = 0;
727 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
728 outb(LOOPBACK_CONTROL, ioaddr + TRANSMIT_MODE_REG);
730 temp |= DIS_AUTO_PORT_SEL;
743 BITSET(ioaddr + TRANSMIT_MODE_REG, CONTROL_OUTPUT);
747 outb(temp, ioaddr + TRANSCEIVER_MODE_REG);
749 if(eth16i_debug > 1) {
750 printk(KERN_DEBUG "TRANSMIT_MODE_REG = %x\n", inb(ioaddr + TRANSMIT_MODE_REG));
751 printk(KERN_DEBUG "TRANSCEIVER_MODE_REG = %x\n",
752 inb(ioaddr+TRANSCEIVER_MODE_REG));
756 static int eth16i_send_probe_packet(int ioaddr, unsigned char *b, int l)
758 unsigned long starttime;
760 outb(0xff, ioaddr + TX_STATUS_REG);
762 outw(l, ioaddr + DATAPORT);
763 outsw(ioaddr + DATAPORT, (unsigned short *)b, (l + 1) >> 1);
766 outb(TX_START | 1, ioaddr + TRANSMIT_START_REG);
768 while( (inb(ioaddr + TX_STATUS_REG) & 0x80) == 0) {
769 if( time_after(jiffies, starttime + TX_TIMEOUT)) {
777 static int eth16i_receive_probe_packet(int ioaddr)
779 unsigned long starttime;
783 while((inb(ioaddr + TX_STATUS_REG) & 0x20) == 0) {
784 if( time_after(jiffies, starttime + TX_TIMEOUT)) {
787 printk(KERN_DEBUG "Timeout occurred waiting transmit packet received\n");
789 while((inb(ioaddr + RX_STATUS_REG) & 0x80) == 0) {
790 if( time_after(jiffies, starttime + TX_TIMEOUT)) {
792 printk(KERN_DEBUG "Timeout occurred waiting receive packet\n");
798 printk(KERN_DEBUG "RECEIVE_PACKET\n");
799 return(0); /* Found receive packet */
803 if(eth16i_debug > 1) {
804 printk(KERN_DEBUG "TRANSMIT_PACKET_RECEIVED %x\n", inb(ioaddr + TX_STATUS_REG));
805 printk(KERN_DEBUG "RX_STATUS_REG = %x\n", inb(ioaddr + RX_STATUS_REG));
808 return(0); /* Return success */
812 static int eth16i_set_irq(struct net_device* dev)
814 const int ioaddr = dev->base_addr;
815 const int irq = dev->irq;
818 if(ioaddr < 0x1000) {
819 while(eth16i_irqmap[i] && eth16i_irqmap[i] != irq)
822 if(i < NUM_OF_ISA_IRQS) {
823 u8 cbyte = inb(ioaddr + JUMPERLESS_CONFIG);
824 cbyte = (cbyte & 0x3F) | (i << 6);
825 outb(cbyte, ioaddr + JUMPERLESS_CONFIG);
830 printk(KERN_NOTICE "%s: EISA Interrupt cannot be set. Use EISA Configuration utility.\n", dev->name);
838 static int __init eth16i_get_irq(int ioaddr)
842 if( ioaddr < 0x1000) {
843 cbyte = inb(ioaddr + JUMPERLESS_CONFIG);
844 return( eth16i_irqmap[ ((cbyte & 0xC0) >> 6) ] );
845 } else { /* Oh..the card is EISA so method getting IRQ different */
846 unsigned short index = 0;
847 cbyte = inb(ioaddr + EISA_IRQ_REG);
848 while( (cbyte & 0x01) == 0) {
852 return( eth32i_irqmap[ index ] );
856 static int __init eth16i_check_signature(int ioaddr)
859 unsigned char creg[4] = { 0 };
861 for(i = 0; i < 4 ; i++) {
863 creg[i] = inb(ioaddr + TRANSMIT_MODE_REG + i);
866 printk("eth16i: read signature byte %x at %x\n",
868 ioaddr + TRANSMIT_MODE_REG + i);
871 creg[0] &= 0x0F; /* Mask collision cnr */
872 creg[2] &= 0x7F; /* Mask DCLEN bit */
876 This was removed because the card was sometimes left to state
877 from which it couldn't be find anymore. If there is need
878 to more strict check still this have to be fixed.
880 if( ! ((creg[0] == 0x06) && (creg[1] == 0x41)) ) {
886 if( !((creg[2] == 0x36) && (creg[3] == 0xE0)) ) {
890 if( !((creg[2] == 0x40) && (creg[3] == 0x00)) )
894 if(eth16i_read_eeprom(ioaddr, E_NODEID_0) != 0)
897 if((eth16i_read_eeprom(ioaddr, E_NODEID_1) & 0xFF00) != 0x4B00)
903 static int eth16i_read_eeprom(int ioaddr, int offset)
907 eth16i_eeprom_cmd(ioaddr, EEPROM_READ | offset);
908 outb(CS_1, ioaddr + EEPROM_CTRL_REG);
909 data = eth16i_read_eeprom_word(ioaddr);
910 outb(CS_0 | SK_0, ioaddr + EEPROM_CTRL_REG);
915 static int eth16i_read_eeprom_word(int ioaddr)
920 for(i = 16; i > 0; i--) {
921 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
923 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
926 ((inb(ioaddr + EEPROM_DATA_REG) & DI_1) ? 1 : 0);
934 static void eth16i_eeprom_cmd(int ioaddr, unsigned char command)
938 outb(CS_0 | SK_0, ioaddr + EEPROM_CTRL_REG);
939 outb(DI_0, ioaddr + EEPROM_DATA_REG);
940 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
941 outb(DI_1, ioaddr + EEPROM_DATA_REG);
942 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
944 for(i = 7; i >= 0; i--) {
945 short cmd = ( (command & (1 << i)) ? DI_1 : DI_0 );
946 outb(cmd, ioaddr + EEPROM_DATA_REG);
947 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
949 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
954 static int eth16i_open(struct net_device *dev)
956 struct eth16i_local *lp = netdev_priv(dev);
957 int ioaddr = dev->base_addr;
959 /* Powerup the chip */
960 outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1);
962 /* Initialize the chip */
963 eth16i_initialize(dev, 0);
965 /* Set the transmit buffer size */
966 lp->tx_buf_size = eth16i_tx_buf_map[ETH16I_TX_BUF_SIZE & 0x03];
969 printk(KERN_DEBUG "%s: transmit buffer size %d\n",
970 dev->name, lp->tx_buf_size);
972 /* Now enable Transmitter and Receiver sections */
973 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
975 /* Now switch to register bank 2, for run time operation */
976 eth16i_select_regbank(2, ioaddr);
978 lp->open_time = jiffies;
981 lp->tx_queue_len = 0;
983 /* Turn on interrupts*/
984 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
986 netif_start_queue(dev);
990 static int eth16i_close(struct net_device *dev)
992 struct eth16i_local *lp = netdev_priv(dev);
993 int ioaddr = dev->base_addr;
997 /* Turn off interrupts*/
998 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
1000 netif_stop_queue(dev);
1004 /* Disable transmit and receive */
1005 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
1007 /* Reset the chip */
1008 /* outb(0xff, ioaddr + RESET); */
1009 /* outw(0xffff, ioaddr + TX_STATUS_REG); */
1011 outb(0x00, ioaddr + CONFIG_REG_1);
1016 static void eth16i_timeout(struct net_device *dev)
1018 struct eth16i_local *lp = netdev_priv(dev);
1019 int ioaddr = dev->base_addr;
1021 If we get here, some higher level has decided that
1022 we are broken. There should really be a "kick me"
1023 function call instead.
1026 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
1027 printk(KERN_WARNING "%s: transmit timed out with status %04x, %s ?\n",
1029 inw(ioaddr + TX_STATUS_REG), (inb(ioaddr + TX_STATUS_REG) & TX_DONE) ?
1030 "IRQ conflict" : "network cable problem");
1032 dev->trans_start = jiffies;
1034 /* Let's dump all registers */
1035 if(eth16i_debug > 0) {
1036 printk(KERN_DEBUG "%s: timeout: %02x %02x %02x %02x %02x %02x %02x %02x.\n",
1037 dev->name, inb(ioaddr + 0),
1038 inb(ioaddr + 1), inb(ioaddr + 2),
1039 inb(ioaddr + 3), inb(ioaddr + 4),
1041 inb(ioaddr + 6), inb(ioaddr + 7));
1043 printk(KERN_DEBUG "%s: transmit start reg: %02x. collision reg %02x\n",
1044 dev->name, inb(ioaddr + TRANSMIT_START_REG),
1045 inb(ioaddr + COL_16_REG));
1046 printk(KERN_DEBUG "lp->tx_queue = %d\n", lp->tx_queue);
1047 printk(KERN_DEBUG "lp->tx_queue_len = %d\n", lp->tx_queue_len);
1048 printk(KERN_DEBUG "lp->tx_started = %d\n", lp->tx_started);
1050 lp->stats.tx_errors++;
1052 dev->trans_start = jiffies;
1053 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
1054 netif_wake_queue(dev);
1057 static int eth16i_tx(struct sk_buff *skb, struct net_device *dev)
1059 struct eth16i_local *lp = netdev_priv(dev);
1060 int ioaddr = dev->base_addr;
1062 ushort length = skb->len;
1064 unsigned long flags;
1066 if (length < ETH_ZLEN) {
1067 if (skb_padto(skb, ETH_ZLEN))
1073 netif_stop_queue(dev);
1075 /* Turn off TX interrupts */
1076 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
1078 /* We would be better doing the disable_irq tricks the 3c509 does,
1079 that would make this suck a lot less */
1081 spin_lock_irqsave(&lp->lock, flags);
1083 if( (length + 2) > (lp->tx_buf_size - lp->tx_queue_len)) {
1084 if(eth16i_debug > 0)
1085 printk(KERN_WARNING "%s: Transmit buffer full.\n", dev->name);
1088 outw(length, ioaddr + DATAPORT);
1090 if( ioaddr < 0x1000 )
1091 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
1093 unsigned char frag = length % 4;
1094 outsl(ioaddr + DATAPORT, buf, length >> 2);
1096 outsw(ioaddr + DATAPORT, (buf + (length & 0xFFFC)), 1);
1098 outsw(ioaddr + DATAPORT,
1099 (buf + (length & 0xFFFC) + 2), 1);
1102 lp->tx_buffered_packets++;
1103 lp->tx_buffered_bytes = length;
1105 lp->tx_queue_len += length + 2;
1107 lp->tx_buf_busy = 0;
1109 if(lp->tx_started == 0) {
1110 /* If the transmitter is idle..always trigger a transmit */
1111 outb(TX_START | lp->tx_queue, ioaddr + TRANSMIT_START_REG);
1113 lp->tx_queue_len = 0;
1114 dev->trans_start = jiffies;
1116 netif_wake_queue(dev);
1118 else if(lp->tx_queue_len < lp->tx_buf_size - (ETH_FRAME_LEN + 2)) {
1119 /* There is still more room for one more packet in tx buffer */
1120 netif_wake_queue(dev);
1123 spin_unlock_irqrestore(&lp->lock, flags);
1125 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
1126 /* Turn TX interrupts back on */
1127 /* outb(TX_INTR_DONE | TX_INTR_16_COL, ioaddr + TX_INTR_REG); */
1133 static void eth16i_rx(struct net_device *dev)
1135 struct eth16i_local *lp = netdev_priv(dev);
1136 int ioaddr = dev->base_addr;
1137 int boguscount = MAX_RX_LOOP;
1139 /* Loop until all packets have been read */
1140 while( (inb(ioaddr + RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == 0) {
1142 /* Read status byte from receive buffer */
1143 ushort status = inw(ioaddr + DATAPORT);
1145 /* Get the size of the packet from receive buffer */
1146 ushort pkt_len = inw(ioaddr + DATAPORT);
1148 if(eth16i_debug > 4)
1149 printk(KERN_DEBUG "%s: Receiving packet mode %02x status %04x.\n",
1151 inb(ioaddr + RECEIVE_MODE_REG), status);
1153 if( !(status & PKT_GOOD) ) {
1154 lp->stats.rx_errors++;
1156 if( (pkt_len < ETH_ZLEN) || (pkt_len > ETH_FRAME_LEN) ) {
1157 lp->stats.rx_length_errors++;
1162 eth16i_skip_packet(dev);
1163 lp->stats.rx_dropped++;
1166 else { /* Ok so now we should have a good packet */
1167 struct sk_buff *skb;
1169 skb = dev_alloc_skb(pkt_len + 3);
1171 printk(KERN_WARNING "%s: Could'n allocate memory for packet (len %d)\n",
1172 dev->name, pkt_len);
1173 eth16i_skip_packet(dev);
1174 lp->stats.rx_dropped++;
1182 Now let's get the packet out of buffer.
1183 size is (pkt_len + 1) >> 1, cause we are now reading words
1184 and it have to be even aligned.
1188 insw(ioaddr + DATAPORT, skb_put(skb, pkt_len),
1189 (pkt_len + 1) >> 1);
1191 unsigned char *buf = skb_put(skb, pkt_len);
1192 unsigned char frag = pkt_len % 4;
1194 insl(ioaddr + DATAPORT, buf, pkt_len >> 2);
1197 unsigned short rest[2];
1198 rest[0] = inw( ioaddr + DATAPORT );
1200 rest[1] = inw( ioaddr + DATAPORT );
1202 memcpy(buf + (pkt_len & 0xfffc), (char *)rest, frag);
1206 skb->protocol=eth_type_trans(skb, dev);
1208 if( eth16i_debug > 5 ) {
1210 printk(KERN_DEBUG "%s: Received packet of length %d.\n",
1211 dev->name, pkt_len);
1212 for(i = 0; i < 14; i++)
1213 printk(KERN_DEBUG " %02x", skb->data[i]);
1214 printk(KERN_DEBUG ".\n");
1217 dev->last_rx = jiffies;
1218 lp->stats.rx_packets++;
1219 lp->stats.rx_bytes += pkt_len;
1223 if(--boguscount <= 0)
1229 static irqreturn_t eth16i_interrupt(int irq, void *dev_id)
1231 struct net_device *dev = dev_id;
1232 struct eth16i_local *lp;
1233 int ioaddr = 0, status;
1236 ioaddr = dev->base_addr;
1237 lp = netdev_priv(dev);
1239 /* Turn off all interrupts from adapter */
1240 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
1242 /* eth16i_tx won't be called */
1243 spin_lock(&lp->lock);
1245 status = inw(ioaddr + TX_STATUS_REG); /* Get the status */
1246 outw(status, ioaddr + TX_STATUS_REG); /* Clear status bits */
1251 if(eth16i_debug > 3)
1252 printk(KERN_DEBUG "%s: Interrupt with status %04x.\n", dev->name, status);
1254 if( status & 0x7f00 ) {
1256 lp->stats.rx_errors++;
1258 if(status & (BUS_RD_ERR << 8) )
1259 printk(KERN_WARNING "%s: Bus read error.\n",dev->name);
1260 if(status & (SHORT_PKT_ERR << 8) ) lp->stats.rx_length_errors++;
1261 if(status & (ALIGN_ERR << 8) ) lp->stats.rx_frame_errors++;
1262 if(status & (CRC_ERR << 8) ) lp->stats.rx_crc_errors++;
1263 if(status & (RX_BUF_OVERFLOW << 8) ) lp->stats.rx_over_errors++;
1265 if( status & 0x001a) {
1267 lp->stats.tx_errors++;
1269 if(status & CR_LOST) lp->stats.tx_carrier_errors++;
1270 if(status & TX_JABBER_ERR) lp->stats.tx_window_errors++;
1273 if(status & COLLISION) {
1274 lp->stats.collisions +=
1275 ((inb(ioaddr+TRANSMIT_MODE_REG) & 0xF0) >> 4);
1278 if(status & COLLISIONS_16) {
1279 if(lp->col_16 < MAX_COL_16) {
1281 lp->stats.collisions++;
1282 /* Resume transmitting, skip failed packet */
1283 outb(0x02, ioaddr + COL_16_REG);
1286 printk(KERN_WARNING "%s: bailing out due to many consecutive 16-in-a-row collisions. Network cable problem?\n", dev->name);
1291 if( status & 0x00ff ) { /* Let's check the transmit status reg */
1293 if(status & TX_DONE) { /* The transmit has been done */
1294 lp->stats.tx_packets = lp->tx_buffered_packets;
1295 lp->stats.tx_bytes += lp->tx_buffered_bytes;
1298 if(lp->tx_queue) { /* Is there still packets ? */
1299 /* There was packet(s) so start transmitting and write also
1300 how many packets there is to be sended */
1301 outb(TX_START | lp->tx_queue, ioaddr + TRANSMIT_START_REG);
1303 lp->tx_queue_len = 0;
1309 netif_wake_queue(dev);
1313 if( ( status & 0x8000 ) ||
1314 ( (inb(ioaddr + RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == 0) ) {
1315 eth16i_rx(dev); /* We have packet in receive buffer */
1318 /* Turn interrupts back on */
1319 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
1321 if(lp->tx_queue_len < lp->tx_buf_size - (ETH_FRAME_LEN + 2)) {
1322 /* There is still more room for one more packet in tx buffer */
1323 netif_wake_queue(dev);
1326 spin_unlock(&lp->lock);
1328 return IRQ_RETVAL(handled);
1331 static void eth16i_skip_packet(struct net_device *dev)
1333 int ioaddr = dev->base_addr;
1335 inw(ioaddr + DATAPORT);
1336 inw(ioaddr + DATAPORT);
1337 inw(ioaddr + DATAPORT);
1339 outb(SKIP_RX_PACKET, ioaddr + FILTER_SELF_RX_REG);
1340 while( inb( ioaddr + FILTER_SELF_RX_REG ) != 0);
1343 static void eth16i_reset(struct net_device *dev)
1345 struct eth16i_local *lp = netdev_priv(dev);
1346 int ioaddr = dev->base_addr;
1348 if(eth16i_debug > 1)
1349 printk(KERN_DEBUG "%s: Resetting device.\n", dev->name);
1351 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
1352 outw(0xffff, ioaddr + TX_STATUS_REG);
1353 eth16i_select_regbank(2, ioaddr);
1356 lp->tx_buf_busy = 0;
1358 lp->tx_queue_len = 0;
1359 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
1362 static void eth16i_multicast(struct net_device *dev)
1364 int ioaddr = dev->base_addr;
1366 if(dev->mc_count || dev->flags&(IFF_ALLMULTI|IFF_PROMISC))
1368 dev->flags|=IFF_PROMISC; /* Must do this */
1369 outb(3, ioaddr + RECEIVE_MODE_REG);
1371 outb(2, ioaddr + RECEIVE_MODE_REG);
1375 static struct net_device_stats *eth16i_get_stats(struct net_device *dev)
1377 struct eth16i_local *lp = netdev_priv(dev);
1381 static void eth16i_select_regbank(unsigned char banknbr, int ioaddr)
1385 data = inb(ioaddr + CONFIG_REG_1);
1386 outb( ((data & 0xF3) | ( (banknbr & 0x03) << 2)), ioaddr + CONFIG_REG_1);
1391 static ushort eth16i_parse_mediatype(const char* s)
1394 return E_PORT_FROM_EPROM;
1396 if (!strncmp(s, "bnc", 3))
1398 else if (!strncmp(s, "tp", 2))
1400 else if (!strncmp(s, "dix", 3))
1402 else if (!strncmp(s, "auto", 4))
1405 return E_PORT_FROM_EPROM;
1408 #define MAX_ETH16I_CARDS 4 /* Max number of Eth16i cards per module */
1410 static struct net_device *dev_eth16i[MAX_ETH16I_CARDS];
1411 static int io[MAX_ETH16I_CARDS];
1413 static int irq[MAX_ETH16I_CARDS];
1415 static char* mediatype[MAX_ETH16I_CARDS];
1416 static int debug = -1;
1418 MODULE_AUTHOR("Mika Kuoppala <miku@iki.fi>");
1419 MODULE_DESCRIPTION("ICL EtherTeam 16i/32 driver");
1420 MODULE_LICENSE("GPL");
1423 module_param_array(io, int, NULL, 0);
1424 MODULE_PARM_DESC(io, "eth16i I/O base address(es)");
1427 module_param_array(irq, int, NULL, 0);
1428 MODULE_PARM_DESC(irq, "eth16i interrupt request number");
1431 module_param_array(mediatype, charp, NULL, 0);
1432 MODULE_PARM_DESC(mediatype, "eth16i media type of interface(s) (bnc,tp,dix,auto,eprom)");
1434 module_param(debug, int, 0);
1435 MODULE_PARM_DESC(debug, "eth16i debug level (0-6)");
1437 int __init init_module(void)
1439 int this_dev, found = 0;
1440 struct net_device *dev;
1442 for (this_dev = 0; this_dev < MAX_ETH16I_CARDS; this_dev++) {
1443 dev = alloc_etherdev(sizeof(struct eth16i_local));
1447 dev->base_addr = io[this_dev];
1450 eth16i_debug = debug;
1452 if(eth16i_debug > 1)
1453 printk(KERN_NOTICE "eth16i(%d): interface type %s\n", this_dev, mediatype[this_dev] ? mediatype[this_dev] : "none" );
1455 dev->if_port = eth16i_parse_mediatype(mediatype[this_dev]);
1457 if(io[this_dev] == 0) {
1458 if(this_dev != 0) /* Only autoprobe 1st one */
1461 printk(KERN_NOTICE "eth16i.c: Presently autoprobing (not recommended) for a single card.\n");
1464 if (do_eth16i_probe(dev) == 0) {
1465 dev_eth16i[found++] = dev;
1468 printk(KERN_WARNING "eth16i.c No Eth16i card found (i/o = 0x%x).\n",
1478 void __exit cleanup_module(void)
1482 for(this_dev = 0; this_dev < MAX_ETH16I_CARDS; this_dev++) {
1483 struct net_device *dev = dev_eth16i[this_dev];
1486 unregister_netdev(dev);
1487 free_irq(dev->irq, dev);
1488 release_region(dev->base_addr, ETH16I_IO_EXTENT);
1497 * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c eth16i.c"
1498 * alt-compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict -prototypes -O6 -c eth16i.c"
1505 /* End of file eth16i.c */