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 int ne3210_probe(struct net_device
*dev
);
47 int ne3210_probe1(struct net_device
*dev
, int ioaddr
);
49 static int ne3210_open(struct net_device
*dev
);
50 static int ne3210_close(struct net_device
*dev
);
52 static void ne3210_reset_8390(struct net_device
*dev
);
54 static void ne3210_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
, int ring_page
);
55 static void ne3210_block_input(struct net_device
*dev
, int count
, struct sk_buff
*skb
, int ring_offset
);
56 static void ne3210_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 if (ioaddr
> 0x1ff) /* Check a single specified location. */
103 return ne3210_probe1(dev
, ioaddr
);
104 else if (ioaddr
> 0) /* Don't probe at all. */
108 #if NE3210_DEBUG & NE3210_D_PROBE
109 printk("ne3210-debug: Not an EISA bus. Not probing high ports.\n");
114 /* EISA spec allows for up to 16 slots, but 8 is typical. */
115 for (ioaddr
= 0x1000; ioaddr
< 0x9000; ioaddr
+= 0x1000) {
116 if (check_region(ioaddr
, NE3210_IO_EXTENT
))
118 if (ne3210_probe1(dev
, ioaddr
) == 0)
125 int __init
ne3210_probe1(struct net_device
*dev
, int ioaddr
)
128 unsigned long eisa_id
;
129 const char *ifmap
[] = {"UTP", "?", "BNC", "AUI"};
131 if (inb_p(ioaddr
+ NE3210_ID_PORT
) == 0xff) return -ENODEV
;
133 #if NE3210_DEBUG & NE3210_D_PROBE
134 printk("ne3210-debug: probe at %#x, ID %#8x\n", ioaddr
, inl(ioaddr
+ NE3210_ID_PORT
));
135 printk("ne3210-debug: config regs: %#x %#x\n",
136 inb(ioaddr
+ NE3210_CFG1
), inb(ioaddr
+ NE3210_CFG2
));
140 /* Check the EISA ID of the card. */
141 eisa_id
= inl(ioaddr
+ NE3210_ID_PORT
);
142 if (eisa_id
!= NE3210_ID
) {
148 /* Check the vendor ID as well. Not really required. */
149 if (inb(ioaddr
+ NE3210_SA_PROM
+ 0) != NE3210_ADDR0
150 || inb(ioaddr
+ NE3210_SA_PROM
+ 1) != NE3210_ADDR1
151 || inb(ioaddr
+ NE3210_SA_PROM
+ 2) != NE3210_ADDR2
) {
152 printk("ne3210.c: card not found");
153 for(i
= 0; i
< ETHER_ADDR_LEN
; i
++)
154 printk(" %02x", inb(ioaddr
+ NE3210_SA_PROM
+ i
));
155 printk(" (invalid prefix).\n");
160 if (load_8390_module("ne3210.c"))
163 /* We should have a "dev" from Space.c or the static module table. */
165 printk("ne3210.c: Passed a NULL device.\n");
166 dev
= init_etherdev(0, 0);
169 /* Allocate dev->priv and fill in 8390 specific dev fields. */
170 if (ethdev_init(dev
)) {
171 printk ("ne3210.c: unable to allocate memory for dev->priv!\n");
175 printk("ne3210.c: NE3210 in EISA slot %d, media: %s, addr:",
176 ioaddr
/0x1000, ifmap
[inb(ioaddr
+ NE3210_CFG2
) >> 6]);
177 for(i
= 0; i
< ETHER_ADDR_LEN
; i
++)
178 printk(" %02x", (dev
->dev_addr
[i
] = inb(ioaddr
+ NE3210_SA_PROM
+ i
)));
179 printk(".\nne3210.c: ");
181 /* Snarf the interrupt now. CFG file has them all listed as `edge' with share=NO */
183 unsigned char irq_reg
= inb(ioaddr
+ NE3210_CFG2
) >> 3;
184 dev
->irq
= irq_map
[irq_reg
& 0x07];
187 /* This is useless unless we reprogram the card here too */
188 if (dev
->irq
== 2) dev
->irq
= 9; /* Doh! */
191 printk(" IRQ %d,", dev
->irq
);
193 if (request_irq(dev
->irq
, ei_interrupt
, 0, "ne3210", dev
)) {
194 printk (" unable to get IRQ %d.\n", dev
->irq
);
200 if (dev
->mem_start
== 0) {
201 unsigned char mem_reg
= inb(ioaddr
+ NE3210_CFG2
) & 0x07;
202 dev
->mem_start
= shmem_map
[mem_reg
] * 0x1000;
205 /* Should check for value in shmem_map and reprogram the card to use it */
206 dev
->mem_start
&= 0xfff8000;
207 printk(" assigning ");
210 printk("%dkB memory at physical address %#lx\n",
211 NE3210_STOP_PG
/4, dev
->mem_start
);
214 BEWARE!! Some dain-bramaged EISA SCUs will allow you to put
215 the card mem within the region covered by `normal' RAM !!!
217 if (dev
->mem_start
> 1024*1024) { /* phys addr > 1MB */
218 if (dev
->mem_start
< virt_to_bus(high_memory
)) {
219 printk(KERN_CRIT
"ne3210.c: Card RAM overlaps with normal memory!!!\n");
220 printk(KERN_CRIT
"ne3210.c: Use EISA SCU to set card memory below 1MB,\n");
221 printk(KERN_CRIT
"ne3210.c: or to an address above 0x%lx.\n", virt_to_bus(high_memory
));
222 printk(KERN_CRIT
"ne3210.c: Driver NOT installed.\n");
223 free_irq(dev
->irq
, dev
);
228 dev
->mem_start
= (unsigned long)ioremap(dev
->mem_start
, NE3210_STOP_PG
*0x100);
229 if (dev
->mem_start
== 0) {
230 printk(KERN_ERR
"ne3210.c: Unable to remap card memory above 1MB !!\n");
231 printk(KERN_ERR
"ne3210.c: Try using EISA SCU to set memory below 1MB.\n");
232 printk(KERN_ERR
"ne3210.c: Driver NOT installed.\n");
233 free_irq(dev
->irq
, dev
);
238 ei_status
.reg0
= 1; /* Use as remap flag */
239 printk("ne3210.c: remapped %dkB card memory to virtual address %#lx\n",
240 NE3210_STOP_PG
/4, dev
->mem_start
);
243 dev
->mem_end
= dev
->rmem_end
= dev
->mem_start
244 + (NE3210_STOP_PG
- NE3210_START_PG
)*256;
245 dev
->rmem_start
= dev
->mem_start
+ TX_PAGES
*256;
247 /* The 8390 offset is zero for the NE3210 */
248 dev
->base_addr
= ioaddr
;
249 request_region(dev
->base_addr
, NE3210_IO_EXTENT
, "ne3210");
251 ei_status
.name
= "NE3210";
252 ei_status
.tx_start_page
= NE3210_START_PG
;
253 ei_status
.rx_start_page
= NE3210_START_PG
+ TX_PAGES
;
254 ei_status
.stop_page
= NE3210_STOP_PG
;
255 ei_status
.word16
= 1;
260 ei_status
.reset_8390
= &ne3210_reset_8390
;
261 ei_status
.block_input
= &ne3210_block_input
;
262 ei_status
.block_output
= &ne3210_block_output
;
263 ei_status
.get_8390_hdr
= &ne3210_get_8390_hdr
;
265 dev
->open
= &ne3210_open
;
266 dev
->stop
= &ne3210_close
;
272 * Reset by toggling the "Board Enable" bits (bit 2 and 0).
275 static void ne3210_reset_8390(struct net_device
*dev
)
277 unsigned short ioaddr
= dev
->base_addr
;
279 outb(0x04, ioaddr
+ NE3210_RESET_PORT
);
280 if (ei_debug
> 1) printk("%s: resetting the NE3210...", dev
->name
);
285 outb(0x01, ioaddr
+ NE3210_RESET_PORT
);
286 if (ei_debug
> 1) printk("reset done\n");
292 * Note: In the following three functions is the implicit assumption
293 * that the associated memcpy will only use "rep; movsl" as long as
294 * we keep the counts as some multiple of doublewords. This is a
295 * requirement of the hardware, and also prevents us from using
296 * eth_io_copy_and_sum() since we can't guarantee it will limit
297 * itself to doubleword access.
301 * Grab the 8390 specific header. Similar to the block_input routine, but
302 * we don't need to be concerned with ring wrap as the header will be at
303 * the start of a page, so we optimize accordingly. (A single doubleword.)
307 ne3210_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
, int ring_page
)
309 unsigned long hdr_start
= dev
->mem_start
+ ((ring_page
- NE3210_START_PG
)<<8);
310 memcpy_fromio(hdr
, hdr_start
, sizeof(struct e8390_pkt_hdr
));
311 hdr
->count
= (hdr
->count
+ 3) & ~3; /* Round up allocation. */
315 * Block input and output are easy on shared memory ethercards, the only
316 * complication is when the ring buffer wraps. The count will already
317 * be rounded up to a doubleword value via ne3210_get_8390_hdr() above.
320 static void ne3210_block_input(struct net_device
*dev
, int count
, struct sk_buff
*skb
,
323 unsigned long xfer_start
= dev
->mem_start
+ ring_offset
- (NE3210_START_PG
<<8);
325 if (xfer_start
+ count
> dev
->rmem_end
) {
326 /* Packet wraps over end of ring buffer. */
327 int semi_count
= dev
->rmem_end
- xfer_start
;
328 memcpy_fromio(skb
->data
, xfer_start
, semi_count
);
330 memcpy_fromio(skb
->data
+ semi_count
, dev
->rmem_start
, count
);
332 /* Packet is in one chunk. */
333 memcpy_fromio(skb
->data
, xfer_start
, count
);
337 static void ne3210_block_output(struct net_device
*dev
, int count
,
338 const unsigned char *buf
, int start_page
)
340 unsigned long shmem
= dev
->mem_start
+ ((start_page
- NE3210_START_PG
)<<8);
342 count
= (count
+ 3) & ~3; /* Round up to doubleword */
343 memcpy_toio(shmem
, buf
, count
);
346 static int ne3210_open(struct net_device
*dev
)
353 static int ne3210_close(struct net_device
*dev
)
357 printk("%s: Shutting down ethercard.\n", dev
->name
);
365 #define MAX_NE3210_CARDS 4 /* Max number of NE3210 cards per module */
366 #define NAMELEN 8 /* # of chars for storing dev->name */
367 static char namelist
[NAMELEN
* MAX_NE3210_CARDS
] = { 0, };
368 static struct net_device dev_ne3210
[MAX_NE3210_CARDS
] = {
370 NULL
, /* assign a chunk of namelist[] below */
377 static int io
[MAX_NE3210_CARDS
] = { 0, };
378 static int irq
[MAX_NE3210_CARDS
] = { 0, };
379 static int mem
[MAX_NE3210_CARDS
] = { 0, };
381 MODULE_PARM(io
, "1-" __MODULE_STRING(MAX_NE3210_CARDS
) "i");
382 MODULE_PARM(irq
, "1-" __MODULE_STRING(MAX_NE3210_CARDS
) "i");
383 MODULE_PARM(mem
, "1-" __MODULE_STRING(MAX_NE3210_CARDS
) "i");
385 int init_module(void)
387 int this_dev
, found
= 0;
389 for (this_dev
= 0; this_dev
< MAX_NE3210_CARDS
; this_dev
++) {
390 struct net_device
*dev
= &dev_ne3210
[this_dev
];
391 dev
->name
= namelist
+(NAMELEN
*this_dev
);
392 dev
->irq
= irq
[this_dev
];
393 dev
->base_addr
= io
[this_dev
];
394 dev
->mem_start
= mem
[this_dev
];
395 dev
->init
= ne3210_probe
;
396 /* Default is to only install one card. */
397 if (io
[this_dev
] == 0 && this_dev
!= 0) break;
398 if (register_netdev(dev
) != 0) {
399 printk(KERN_WARNING
"ne3210.c: No NE3210 card found (i/o = 0x%x).\n", io
[this_dev
]);
400 if (found
!= 0) { /* Got at least one. */
412 void cleanup_module(void)
416 for (this_dev
= 0; this_dev
< MAX_NE3210_CARDS
; this_dev
++) {
417 struct net_device
*dev
= &dev_ne3210
[this_dev
];
418 if (dev
->priv
!= NULL
) {
419 void *priv
= dev
->priv
;
420 free_irq(dev
->irq
, dev
);
421 release_region(dev
->base_addr
, NE3210_IO_EXTENT
);
423 iounmap((void *)dev
->mem_start
);
424 unregister_netdev(dev
);
428 unlock_8390_module();