4 Linux driver for Novell NE3210 EISA Network Adapter 6 Copyright (C) 1998, Paul Gortmaker. 8 This software may be used and distributed according to the terms 9 of the GNU Public License, incorporated herein by reference. 11 Information and Code Sources: 13 1) Based upon my other EISA 8390 drivers (lne390, es3210, smc-ultra32) 14 2) The existing myriad of other Linux 8390 drivers by Donald Becker. 15 3) Info for getting IRQ and sh-mem gleaned from the EISA cfg file 17 The NE3210 is an EISA shared memory NS8390 implementation. Shared 18 memory address > 1MB should work with this driver. 20 Note that the .cfg file (3/11/93, v1.0) has AUI and BNC switched 21 around (or perhaps there are some defective/backwards cards ???) 23 This driver WILL NOT WORK FOR THE NE3200 - it is completely different 24 and does not use an 8390 at all. 28 static const char*version
= 29 "ne3210.c: Driver revision v0.03, 30/09/98\n"; 31 #include <linux/module.h> 32 #include <linux/kernel.h> 33 #include <linux/sched.h> 34 #include <linux/errno.h> 35 #include <linux/string.h> 36 #include <linux/delay.h> 37 #include <linux/init.h> 40 #include <asm/system.h> 42 #include <linux/netdevice.h> 43 #include <linux/etherdevice.h> 46 intne3210_probe(struct net_device
*dev
); 47 static intne3210_probe1(struct net_device
*dev
,int ioaddr
); 49 static intne3210_open(struct net_device
*dev
); 50 static intne3210_close(struct net_device
*dev
); 52 static voidne3210_reset_8390(struct net_device
*dev
); 54 static voidne3210_get_8390_hdr(struct net_device
*dev
,struct e8390_pkt_hdr
*hdr
,int ring_page
); 55 static voidne3210_block_input(struct net_device
*dev
,int count
,struct sk_buff
*skb
,int ring_offset
); 56 static voidne3210_block_output(struct net_device
*dev
,int count
,const unsigned char*buf
,const int start_page
); 58 #define NE3210_START_PG 0x00/* First page of TX buffer */ 59 #define NE3210_STOP_PG 0x80/* Last page +1 of RX ring */ 61 #define NE3210_ID_PORT 0xc80/* Same for all EISA cards */ 62 #define NE3210_IO_EXTENT 0x20 63 #define NE3210_SA_PROM 0x16/* Start of e'net addr. */ 64 #define NE3210_RESET_PORT 0xc84 65 #define NE3210_NIC_OFFSET 0x00/* Hello, the 8390 is *here* */ 67 #define NE3210_ADDR0 0x00/* 3 byte vendor prefix */ 68 #define NE3210_ADDR1 0x00 69 #define NE3210_ADDR2 0x1b 71 #define NE3210_ID 0x0118cc3a/* 0x3acc = 1110 10110 01100 = nvl */ 73 #define NE3210_CFG1 0xc84/* NB: 0xc84 is also "reset" port. */ 74 #define NE3210_CFG2 0xc90 77 * You can OR any of the following bits together and assign it 78 * to NE3210_DEBUG to get verbose driver info during operation. 79 * Currently only the probe one is implemented. 82 #define NE3210_D_PROBE 0x01 83 #define NE3210_D_RX_PKT 0x02 84 #define NE3210_D_TX_PKT 0x04 85 #define NE3210_D_IRQ 0x08 87 #define NE3210_DEBUG 0x0 89 static unsigned char irq_map
[] __initdata
= {15,12,11,10,9,7,5,3}; 90 static unsigned int shmem_map
[] __initdata
= {0xff0,0xfe0,0xfff0,0xd8,0xffe0,0xffc0,0xd0,0x0}; 93 * Probe for the card. The best way is to read the EISA ID if it 94 * is known. Then we can check the prefix of the station address 95 * PROM for a match against the value assigned to Novell. 98 int __init
ne3210_probe(struct net_device
*dev
) 100 unsigned short ioaddr
= dev
->base_addr
; 102 SET_MODULE_OWNER(dev
); 104 if(ioaddr
>0x1ff)/* Check a single specified location. */ 105 returnne3210_probe1(dev
, ioaddr
); 106 else if(ioaddr
>0)/* Don't probe at all. */ 110 #if NE3210_DEBUG & NE3210_D_PROBE 111 printk("ne3210-debug: Not an EISA bus. Not probing high ports.\n"); 116 /* EISA spec allows for up to 16 slots, but 8 is typical. */ 117 for(ioaddr
=0x1000; ioaddr
<0x9000; ioaddr
+=0x1000) 118 if(ne3210_probe1(dev
, ioaddr
) ==0) 124 static int __init
ne3210_probe1(struct net_device
*dev
,int ioaddr
) 127 unsigned long eisa_id
; 128 const char*ifmap
[] = {"UTP","?","BNC","AUI"}; 130 if(!request_region(dev
->base_addr
, NE3210_IO_EXTENT
, dev
->name
)) 133 if(inb_p(ioaddr
+ NE3210_ID_PORT
) ==0xff) { 138 #if NE3210_DEBUG & NE3210_D_PROBE 139 printk("ne3210-debug: probe at %#x, ID %#8x\n", ioaddr
,inl(ioaddr
+ NE3210_ID_PORT
)); 140 printk("ne3210-debug: config regs: %#x %#x\n", 141 inb(ioaddr
+ NE3210_CFG1
),inb(ioaddr
+ NE3210_CFG2
)); 145 /* Check the EISA ID of the card. */ 146 eisa_id
=inl(ioaddr
+ NE3210_ID_PORT
); 147 if(eisa_id
!= NE3210_ID
) { 154 /* Check the vendor ID as well. Not really required. */ 155 if(inb(ioaddr
+ NE3210_SA_PROM
+0) != NE3210_ADDR0
156 ||inb(ioaddr
+ NE3210_SA_PROM
+1) != NE3210_ADDR1
157 ||inb(ioaddr
+ NE3210_SA_PROM
+2) != NE3210_ADDR2
) { 158 printk("ne3210.c: card not found"); 159 for(i
=0; i
< ETHER_ADDR_LEN
; i
++) 160 printk(" %02x",inb(ioaddr
+ NE3210_SA_PROM
+ i
)); 161 printk(" (invalid prefix).\n"); 167 /* Allocate dev->priv and fill in 8390 specific dev fields. */ 168 if(ethdev_init(dev
)) { 169 printk("ne3210.c: unable to allocate memory for dev->priv!\n"); 174 printk("ne3210.c: NE3210 in EISA slot %d, media: %s, addr:", 175 ioaddr
/0x1000, ifmap
[inb(ioaddr
+ NE3210_CFG2
) >>6]); 176 for(i
=0; i
< ETHER_ADDR_LEN
; i
++) 177 printk(" %02x", (dev
->dev_addr
[i
] =inb(ioaddr
+ NE3210_SA_PROM
+ i
))); 178 printk(".\nne3210.c: "); 180 /* Snarf the interrupt now. CFG file has them all listed as `edge' with share=NO */ 182 unsigned char irq_reg
=inb(ioaddr
+ NE3210_CFG2
) >>3; 183 dev
->irq
= irq_map
[irq_reg
&0x07]; 186 /* This is useless unless we reprogram the card here too */ 187 if(dev
->irq
==2) dev
->irq
=9;/* Doh! */ 190 printk(" IRQ %d,", dev
->irq
); 192 retval
=request_irq(dev
->irq
, ei_interrupt
,0, dev
->name
, dev
); 194 printk(" unable to get IRQ %d.\n", dev
->irq
); 198 if(dev
->mem_start
==0) { 199 unsigned char mem_reg
=inb(ioaddr
+ NE3210_CFG2
) &0x07; 200 dev
->mem_start
= shmem_map
[mem_reg
] *0x1000; 203 /* Should check for value in shmem_map and reprogram the card to use it */ 204 dev
->mem_start
&=0xfff8000; 205 printk(" assigning "); 208 printk("%dkB memory at physical address %#lx\n", 209 NE3210_STOP_PG
/4, dev
->mem_start
); 212 BEWARE!! Some dain-bramaged EISA SCUs will allow you to put 213 the card mem within the region covered by `normal' RAM !!! 215 if(dev
->mem_start
>1024*1024) {/* phys addr > 1MB */ 216 if(dev
->mem_start
<virt_to_bus(high_memory
)) { 217 printk(KERN_CRIT
"ne3210.c: Card RAM overlaps with normal memory!!!\n"); 218 printk(KERN_CRIT
"ne3210.c: Use EISA SCU to set card memory below 1MB,\n"); 219 printk(KERN_CRIT
"ne3210.c: or to an address above 0x%lx.\n",virt_to_bus(high_memory
)); 220 printk(KERN_CRIT
"ne3210.c: Driver NOT installed.\n"); 224 dev
->mem_start
= (unsigned long)ioremap(dev
->mem_start
, NE3210_STOP_PG
*0x100); 225 if(dev
->mem_start
==0) { 226 printk(KERN_ERR
"ne3210.c: Unable to remap card memory above 1MB !!\n"); 227 printk(KERN_ERR
"ne3210.c: Try using EISA SCU to set memory below 1MB.\n"); 228 printk(KERN_ERR
"ne3210.c: Driver NOT installed.\n"); 232 ei_status
.reg0
=1;/* Use as remap flag */ 233 printk("ne3210.c: remapped %dkB card memory to virtual address %#lx\n", 234 NE3210_STOP_PG
/4, dev
->mem_start
); 237 dev
->mem_end
= dev
->rmem_end
= dev
->mem_start
238 + (NE3210_STOP_PG
- NE3210_START_PG
)*256; 239 dev
->rmem_start
= dev
->mem_start
+ TX_PAGES
*256; 241 /* The 8390 offset is zero for the NE3210 */ 242 dev
->base_addr
= ioaddr
; 244 ei_status
.name
="NE3210"; 245 ei_status
.tx_start_page
= NE3210_START_PG
; 246 ei_status
.rx_start_page
= NE3210_START_PG
+ TX_PAGES
; 247 ei_status
.stop_page
= NE3210_STOP_PG
; 253 ei_status
.reset_8390
= &ne3210_reset_8390
; 254 ei_status
.block_input
= &ne3210_block_input
; 255 ei_status
.block_output
= &ne3210_block_output
; 256 ei_status
.get_8390_hdr
= &ne3210_get_8390_hdr
; 258 dev
->open
= &ne3210_open
; 259 dev
->stop
= &ne3210_close
; 263 free_irq(dev
->irq
, dev
); 268 release_region(ioaddr
, NE3210_IO_EXTENT
); 273 * Reset by toggling the "Board Enable" bits (bit 2 and 0). 276 static voidne3210_reset_8390(struct net_device
*dev
) 278 unsigned short ioaddr
= dev
->base_addr
; 280 outb(0x04, ioaddr
+ NE3210_RESET_PORT
); 281 if(ei_debug
>1)printk("%s: resetting the NE3210...", dev
->name
); 286 outb(0x01, ioaddr
+ NE3210_RESET_PORT
); 287 if(ei_debug
>1)printk("reset done\n"); 293 * Note: In the following three functions is the implicit assumption 294 * that the associated memcpy will only use "rep; movsl" as long as 295 * we keep the counts as some multiple of doublewords. This is a 296 * requirement of the hardware, and also prevents us from using 297 * eth_io_copy_and_sum() since we can't guarantee it will limit 298 * itself to doubleword access. 302 * Grab the 8390 specific header. Similar to the block_input routine, but 303 * we don't need to be concerned with ring wrap as the header will be at 304 * the start of a page, so we optimize accordingly. (A single doubleword.) 308 ne3210_get_8390_hdr(struct net_device
*dev
,struct e8390_pkt_hdr
*hdr
,int ring_page
) 310 unsigned long hdr_start
= dev
->mem_start
+ ((ring_page
- NE3210_START_PG
)<<8); 311 isa_memcpy_fromio(hdr
, hdr_start
,sizeof(struct e8390_pkt_hdr
)); 312 hdr
->count
= (hdr
->count
+3) & ~3;/* Round up allocation. */ 316 * Block input and output are easy on shared memory ethercards, the only 317 * complication is when the ring buffer wraps. The count will already 318 * be rounded up to a doubleword value via ne3210_get_8390_hdr() above. 321 static voidne3210_block_input(struct net_device
*dev
,int count
,struct sk_buff
*skb
, 324 unsigned long xfer_start
= dev
->mem_start
+ ring_offset
- (NE3210_START_PG
<<8); 326 if(xfer_start
+ count
> dev
->rmem_end
) { 327 /* Packet wraps over end of ring buffer. */ 328 int semi_count
= dev
->rmem_end
- xfer_start
; 329 isa_memcpy_fromio(skb
->data
, xfer_start
, semi_count
); 331 isa_memcpy_fromio(skb
->data
+ semi_count
, dev
->rmem_start
, count
); 333 /* Packet is in one chunk. */ 334 isa_memcpy_fromio(skb
->data
, xfer_start
, count
); 338 static voidne3210_block_output(struct net_device
*dev
,int count
, 339 const unsigned char*buf
,int start_page
) 341 unsigned long shmem
= dev
->mem_start
+ ((start_page
- NE3210_START_PG
)<<8); 343 count
= (count
+3) & ~3;/* Round up to doubleword */ 344 isa_memcpy_toio(shmem
, buf
, count
); 347 static intne3210_open(struct net_device
*dev
) 353 static intne3210_close(struct net_device
*dev
) 357 printk("%s: Shutting down ethercard.\n", dev
->name
); 364 #define MAX_NE3210_CARDS 4/* Max number of NE3210 cards per module */ 365 static struct net_device dev_ne3210
[MAX_NE3210_CARDS
]; 366 static int io
[MAX_NE3210_CARDS
]; 367 static int irq
[MAX_NE3210_CARDS
]; 368 static int mem
[MAX_NE3210_CARDS
]; 370 MODULE_PARM(io
,"1-"__MODULE_STRING(MAX_NE3210_CARDS
)"i"); 371 MODULE_PARM(irq
,"1-"__MODULE_STRING(MAX_NE3210_CARDS
)"i"); 372 MODULE_PARM(mem
,"1-"__MODULE_STRING(MAX_NE3210_CARDS
)"i"); 376 int this_dev
, found
=0; 378 for(this_dev
=0; this_dev
< MAX_NE3210_CARDS
; this_dev
++) { 379 struct net_device
*dev
= &dev_ne3210
[this_dev
]; 380 dev
->irq
= irq
[this_dev
]; 381 dev
->base_addr
= io
[this_dev
]; 382 dev
->mem_start
= mem
[this_dev
]; 383 dev
->init
= ne3210_probe
; 384 /* Default is to only install one card. */ 385 if(io
[this_dev
] ==0&& this_dev
!=0)break; 386 if(register_netdev(dev
) !=0) { 387 printk(KERN_WARNING
"ne3210.c: No NE3210 card found (i/o = 0x%x).\n", io
[this_dev
]); 388 if(found
!=0) {/* Got at least one. */ 398 voidcleanup_module(void) 402 for(this_dev
=0; this_dev
< MAX_NE3210_CARDS
; this_dev
++) { 403 struct net_device
*dev
= &dev_ne3210
[this_dev
]; 404 if(dev
->priv
!= NULL
) { 405 free_irq(dev
->irq
, dev
); 406 release_region(dev
->base_addr
, NE3210_IO_EXTENT
); 408 iounmap((void*)dev
->mem_start
); 409 unregister_netdev(dev
);