148 #include <linux/module.h>
149 #include <linux/kernel.h>
150 #include <linux/types.h>
151 #include <linux/fcntl.h>
154 #include <linux/in.h>
155 #include <linux/string.h>
156 #include <linux/errno.h>
159 #include <linux/netdevice.h>
162 #include <linux/bitops.h>
171 #define BITSET(ioaddr, bnum) ((outb(((inb(ioaddr)) | (bnum)), ioaddr)))
172 #define BITCLR(ioaddr, bnum) ((outb(((inb(ioaddr)) & (~(bnum))), ioaddr)))
175 #define ETH16I_IO_EXTENT 32
178 #define TX_TIMEOUT (400*HZ/1000)
181 #define MAX_RX_LOOP 20
184 #define ETH16I_INTR_ON 0xef8a
185 #define ETH16I_INTR_OFF 0x0000
188 #define PKT_GOOD BIT(5)
189 #define PKT_GOOD_RMT BIT(4)
190 #define PKT_SHORT BIT(3)
191 #define PKT_ALIGN_ERR BIT(2)
192 #define PKT_CRC_ERR BIT(1)
193 #define PKT_RX_BUF_OVERFLOW BIT(0)
196 #define TX_STATUS_REG 0
197 #define TX_DONE BIT(7)
198 #define NET_BUSY BIT(6)
199 #define TX_PKT_RCD BIT(5)
200 #define CR_LOST BIT(4)
201 #define TX_JABBER_ERR BIT(3)
202 #define COLLISION BIT(2)
203 #define COLLISIONS_16 BIT(1)
206 #define RX_STATUS_REG 1
207 #define RX_PKT BIT(7)
208 #define BUS_RD_ERR BIT(6)
209 #define SHORT_PKT_ERR BIT(3)
210 #define ALIGN_ERR BIT(2)
211 #define CRC_ERR BIT(1)
212 #define RX_BUF_OVERFLOW BIT(0)
215 #define TX_INTR_REG 2
216 #define TX_INTR_DONE BIT(7)
217 #define TX_INTR_COL BIT(2)
218 #define TX_INTR_16_COL BIT(1)
221 #define RX_INTR_REG 3
222 #define RX_INTR_RECEIVE BIT(7)
223 #define RX_INTR_SHORT_PKT BIT(3)
224 #define RX_INTR_CRC_ERR BIT(1)
225 #define RX_INTR_BUF_OVERFLOW BIT(0)
228 #define TRANSMIT_MODE_REG 4
229 #define LOOPBACK_CONTROL BIT(1)
230 #define CONTROL_OUTPUT BIT(2)
233 #define RECEIVE_MODE_REG 5
234 #define RX_BUFFER_EMPTY BIT(6)
235 #define ACCEPT_BAD_PACKETS BIT(5)
236 #define RECEIVE_SHORT_ADDR BIT(4)
237 #define ACCEPT_SHORT_PACKETS BIT(3)
238 #define REMOTE_RESET BIT(2)
240 #define ADDRESS_FILTER_MODE BIT(1) | BIT(0)
247 #define CONFIG_REG_0 6
248 #define DLC_EN BIT(7)
249 #define SRAM_CYCLE_TIME_100NS BIT(6)
250 #define SYSTEM_BUS_WIDTH_8 BIT(5)
251 #define BUFFER_WIDTH_8 BIT(4)
254 #define SRAM_BS1 BIT(1)
255 #define SRAM_BS0 BIT(0)
257 #ifndef ETH16I_TX_BUF_SIZE
258 #define ETH16I_TX_BUF_SIZE 3
260 #define TX_BUF_1x2048 0
261 #define TX_BUF_2x2048 1
262 #define TX_BUF_2x4098 2
263 #define TX_BUF_2x8192 3
266 #define CONFIG_REG_1 7
267 #define POWERUP BIT(5)
270 #define TRANSMIT_START_REG 10
271 #define TRANSMIT_START_RB 2
272 #define TX_START BIT(7)
279 #define HASH_TABLE_0 8
280 #define HASH_TABLE_RB 1
283 #define BUFFER_MEM_PORT_LB 8
284 #define DATAPORT BUFFER_MEM_PORT_LB
285 #define BUFFER_MEM_PORT_HB 9
288 #define COL_16_REG 11
289 #define HALT_ON_16 0x00
290 #define RETRANS_AND_HALT_ON_16 0x02
293 #define MAX_COL_16 10
296 #define TRANSCEIVER_MODE_REG 13
297 #define TRANSCEIVER_MODE_RB 2
298 #define IO_BASE_UNLOCK BIT(7)
299 #define LOWER_SQUELCH_TRESH BIT(6)
300 #define LINK_TEST_DISABLE BIT(5)
301 #define AUI_SELECT BIT(4)
302 #define DIS_AUTO_PORT_SEL BIT(3)
305 #define FILTER_SELF_RX_REG 14
306 #define SKIP_RX_PACKET BIT(2)
307 #define FILTER_SELF_RECEIVE BIT(0)
310 #define EEPROM_CTRL_REG 16
313 #define EEPROM_DATA_REG 17
324 #define EEPROM_READ 0x80
327 #define E_NODEID_0 0x02
328 #define E_NODEID_1 0x03
329 #define E_NODEID_2 0x04
330 #define E_PORT_SELECT 0x14
331 #define E_PORT_BNC 0x00
332 #define E_PORT_DIX 0x01
333 #define E_PORT_TP 0x02
334 #define E_PORT_AUTO 0x03
335 #define E_PORT_FROM_EPROM 0x04
336 #define E_PRODUCT_CFG 0x30
340 #define eeprom_slow_io() do { int _i = 40; while(--_i > 0) { inb(0x80); }}while(0)
343 #define JUMPERLESS_CONFIG 19
348 #define RESET ID_ROM_0
351 static unsigned int eth16i_portlist[]
__initdata = {
352 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300, 0
355 static unsigned int eth32i_portlist[]
__initdata = {
356 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000, 0x8000,
357 0x9000, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, 0
361 static unsigned int eth16i_irqmap[]
__initdata = { 9, 10, 5, 15, 0 };
362 #define NUM_OF_ISA_IRQS 4
365 static unsigned int eth32i_irqmap[]
__initdata = { 3, 5, 7, 9, 10, 11, 12, 15, 0 };
366 #define EISA_IRQ_REG 0xc89
367 #define NUM_OF_EISA_IRQS 8
369 static unsigned int eth16i_tx_buf_map[] = { 2048, 2048, 4096, 8192 };
373 #define ETH16I_DEBUG 0
394 static int eth16i_probe1(
struct net_device *
dev,
int ioaddr);
395 static int eth16i_check_signature(
int ioaddr);
396 static int eth16i_probe_port(
int ioaddr);
397 static void eth16i_set_port(
int ioaddr,
int porttype);
398 static int eth16i_send_probe_packet(
int ioaddr,
unsigned char *
b,
int l);
399 static int eth16i_receive_probe_packet(
int ioaddr);
400 static int eth16i_get_irq(
int ioaddr);
401 static int eth16i_read_eeprom(
int ioaddr,
int offset);
402 static int eth16i_read_eeprom_word(
int ioaddr);
403 static void eth16i_eeprom_cmd(
int ioaddr,
unsigned char command);
414 static void eth16i_select_regbank(
unsigned char regbank,
int ioaddr);
415 static void eth16i_initialize(
struct net_device *
dev,
int boot);
422 static ushort eth16i_parse_mediatype(
const char*
s);
425 static char cardname[]
__initdata =
"ICL EtherTeam 16i/32";
436 if(base_addr > 0x1ff)
437 return eth16i_probe1(dev, base_addr);
438 else if(base_addr != 0)
442 for(i = 0; (ioaddr = eth16i_portlist[
i]) ; i++)
443 if(eth16i_probe1(dev, ioaddr) == 0)
447 for(i = 0; (ioaddr = eth32i_portlist[
i]) ; i++)
448 if(eth16i_probe1(dev, ioaddr) == 0)
466 err = do_eth16i_probe(dev);
477 .ndo_open = eth16i_open,
478 .ndo_stop = eth16i_close,
479 .ndo_start_xmit = eth16i_tx,
480 .ndo_set_rx_mode = eth16i_multicast,
481 .ndo_tx_timeout = eth16i_timeout,
490 static unsigned version_printed;
504 if(ioaddr < 0x1000) {
514 if(eth16i_check_signature(ioaddr) != 0) {
533 if( (eth16i_debug & version_printed++) == 0)
537 dev->
irq = eth16i_get_irq(ioaddr);
541 if ((retval =
request_irq(dev->
irq, (
void *)ð16i_interrupt, 0, cardname, dev))) {
543 cardname, ioaddr, dev->
irq);
548 dev->
name, cardname, ioaddr, dev->
irq);
555 eth16i_initialize(dev, 1);
577 static void eth16i_initialize(
struct net_device *dev,
int boot)
581 unsigned char node_byte = 0;
585 for(i = 0 ; i < 3 ; i++) {
586 unsigned short node_val = eth16i_read_eeprom(ioaddr,
E_NODEID_0 + i);
590 for(i = 0; i < 6; i++) {
601 for(i = 0; i < 8; i++)
610 eth16i_select_regbank(2, ioaddr);
615 if( (node_w & 0xFF00) == 0x0800)
620 if( (node_w & 0x00FF) == 64)
639 static const char *
const porttype[] = {
640 "BNC",
"DIX",
"TP",
"AUTO",
"FROM_EPROM"
651 dev->
if_port = eth16i_probe_port(ioaddr);
662 eth16i_set_port(ioaddr, dev->
if_port);
669 static int eth16i_probe_port(
int ioaddr)
673 unsigned char dummy_packet[64];
682 for(i = 0; i < 6; i++) {
687 dummy_packet[12] = 0x00;
688 dummy_packet[13] = 0x04;
689 memset(dummy_packet + 14, 0,
sizeof(dummy_packet) - 14);
691 eth16i_select_regbank(2, ioaddr);
693 for(i = 0; i < 3; i++) {
696 eth16i_set_port(ioaddr, i);
701 retcode = eth16i_send_probe_packet(ioaddr, dummy_packet, 64);
703 retcode = eth16i_receive_probe_packet(ioaddr);
716 if( eth16i_debug > 1)
722 static void eth16i_set_port(
int ioaddr,
int porttype)
724 unsigned short temp = 0;
748 if(eth16i_debug > 1) {
755 static int eth16i_send_probe_packet(
int ioaddr,
unsigned char *
b,
int l)
757 unsigned long starttime;
776 static int eth16i_receive_probe_packet(
int ioaddr)
778 unsigned long starttime;
802 if(eth16i_debug > 1) {
811 static int eth16i_set_irq(
struct net_device* dev)
817 if(ioaddr < 0x1000) {
818 while(eth16i_irqmap[i] && eth16i_irqmap[i] != irq)
823 cbyte = (cbyte & 0x3F) | (i << 6);
829 printk(
KERN_NOTICE "%s: EISA Interrupt cannot be set. Use EISA Configuration utility.\n", dev->
name);
837 static int __init eth16i_get_irq(
int ioaddr)
841 if( ioaddr < 0x1000) {
843 return eth16i_irqmap[((cbyte & 0xC0) >> 6)];
845 unsigned short index = 0;
847 while( (cbyte & 0x01) == 0) {
851 return eth32i_irqmap[
index];
855 static int __init eth16i_check_signature(
int ioaddr)
858 unsigned char creg[4] = { 0 };
860 for(i = 0; i < 4 ; i++) {
865 printk(
"eth16i: read signature byte %x at %x\n",
879 if( ! ((creg[0] == 0x06) && (creg[1] == 0x41)) ) {
885 if( !((creg[2] == 0x36) && (creg[3] == 0xE0)) ) {
889 if( !((creg[2] == 0x40) && (creg[3] == 0x00)) )
893 if(eth16i_read_eeprom(ioaddr,
E_NODEID_0) != 0)
896 if((eth16i_read_eeprom(ioaddr,
E_NODEID_1) & 0xFF00) != 0x4B00)
902 static int eth16i_read_eeprom(
int ioaddr,
int offset)
908 data = eth16i_read_eeprom_word(ioaddr);
914 static int eth16i_read_eeprom_word(
int ioaddr)
919 for(i = 16; i > 0; i--) {
933 static void eth16i_eeprom_cmd(
int ioaddr,
unsigned char command)
943 for(i = 7; i >= 0; i--) {
953 static int eth16i_open(
struct net_device *dev)
962 eth16i_initialize(dev, 0);
975 eth16i_select_regbank(2, ioaddr);
985 netif_start_queue(dev);
989 static int eth16i_close(
struct net_device *dev)
999 netif_stop_queue(dev);
1015 static void eth16i_timeout(
struct net_device *dev)
1029 "IRQ conflict" :
"network cable problem");
1034 if(eth16i_debug > 0) {
1035 printk(
KERN_DEBUG "%s: timeout: %02x %02x %02x %02x %02x %02x %02x %02x.\n",
1037 inb(ioaddr + 1),
inb(ioaddr + 2),
1038 inb(ioaddr + 3),
inb(ioaddr + 4),
1040 inb(ioaddr + 6),
inb(ioaddr + 7));
1049 dev->
stats.tx_errors++;
1053 netif_wake_queue(dev);
1063 unsigned long flags;
1072 netif_stop_queue(dev);
1083 if(eth16i_debug > 0)
1089 if( ioaddr < 0x1000 )
1092 unsigned char frag = length % 4;
1098 (buf + (length & 0xFFFC) + 2), 1);
1114 netif_wake_queue(dev);
1118 netif_wake_queue(dev);
1121 spin_unlock_irqrestore(&lp->
lock, flags);
1131 static void eth16i_rx(
struct net_device *dev)
1145 if(eth16i_debug > 4)
1151 dev->
stats.rx_errors++;
1154 dev->
stats.rx_length_errors++;
1159 eth16i_skip_packet(dev);
1160 dev->
stats.rx_dropped++;
1166 skb = netdev_alloc_skb(dev, pkt_len + 3);
1169 dev->
name, pkt_len);
1170 eth16i_skip_packet(dev);
1171 dev->
stats.rx_dropped++;
1185 (pkt_len + 1) >> 1);
1187 unsigned char *buf =
skb_put(skb, pkt_len);
1188 unsigned char frag = pkt_len % 4;
1193 unsigned short rest[2];
1198 memcpy(buf + (pkt_len & 0xfffc), (
char *)rest, frag);
1204 if( eth16i_debug > 5 ) {
1207 dev->
name, pkt_len);
1208 for(i = 0; i < 14; i++)
1213 dev->
stats.rx_packets++;
1218 if(--boguscount <= 0)
1232 lp = netdev_priv(dev);
1238 spin_lock(&lp->
lock);
1246 if(eth16i_debug > 3)
1249 if( status & 0x7f00 ) {
1251 dev->
stats.rx_errors++;
1257 if(status & (
CRC_ERR << 8) ) dev->
stats.rx_crc_errors++;
1260 if( status & 0x001a) {
1262 dev->
stats.tx_errors++;
1269 dev->
stats.collisions +=
1276 dev->
stats.collisions++;
1281 printk(
KERN_WARNING "%s: bailing out due to many consecutive 16-in-a-row collisions. Network cable problem?\n", dev->
name);
1286 if( status & 0x00ff ) {
1304 netif_wake_queue(dev);
1308 if( ( status & 0x8000 ) ||
1318 netif_wake_queue(dev);
1321 spin_unlock(&lp->
lock);
1326 static void eth16i_skip_packet(
struct net_device *dev)
1338 static void eth16i_reset(
struct net_device *dev)
1343 if(eth16i_debug > 1)
1348 eth16i_select_regbank(2, ioaddr);
1357 static void eth16i_multicast(
struct net_device *dev)
1369 static void eth16i_select_regbank(
unsigned char banknbr,
int ioaddr)
1379 static ushort eth16i_parse_mediatype(
const char*
s)
1386 else if (!
strncmp(s,
"tp", 2))
1388 else if (!
strncmp(s,
"dix", 3))
1390 else if (!
strncmp(s,
"auto", 4))
1396 #define MAX_ETH16I_CARDS 4
1398 static struct net_device *dev_eth16i[MAX_ETH16I_CARDS];
1399 static int io[MAX_ETH16I_CARDS];
1401 static int irq[MAX_ETH16I_CARDS];
1403 static char* mediatype[MAX_ETH16I_CARDS];
1404 static int debug = -1;
1420 MODULE_PARM_DESC(mediatype,
"eth16i media type of interface(s) (bnc,tp,dix,auto,eprom)");
1427 int this_dev, found = 0;
1430 for (this_dev = 0; this_dev < MAX_ETH16I_CARDS; this_dev++) {
1438 eth16i_debug =
debug;
1440 if(eth16i_debug > 1)
1441 printk(
KERN_NOTICE "eth16i(%d): interface type %s\n", this_dev, mediatype[this_dev] ? mediatype[this_dev] :
"none" );
1443 dev->
if_port = eth16i_parse_mediatype(mediatype[this_dev]);
1445 if(io[this_dev] == 0) {
1446 if (this_dev != 0) {
1451 printk(
KERN_NOTICE "eth16i.c: Presently autoprobing (not recommended) for a single card.\n");
1454 if (do_eth16i_probe(dev) == 0) {
1455 dev_eth16i[found++] =
dev;
1472 for(this_dev = 0; this_dev < MAX_ETH16I_CARDS; this_dev++) {
1473 struct net_device *dev = dev_eth16i[this_dev];
1475 if (netdev_priv(dev)) {