| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* ne2.c: A NE/2 Ethernet Driver for Linux. */ | 
|  | 2 | /* | 
|  | 3 | Based on the NE2000 driver written by Donald Becker (1992-94). | 
|  | 4 | modified by Wim Dumon (Apr 1996) | 
|  | 5 |  | 
|  | 6 | This software may be used and distributed according to the terms | 
|  | 7 | of the GNU General Public License, incorporated herein by reference. | 
|  | 8 |  | 
|  | 9 | The author may be reached as wimpie@linux.cc.kuleuven.ac.be | 
|  | 10 |  | 
|  | 11 | Currently supported: NE/2 | 
|  | 12 | This patch was never tested on other MCA-ethernet adapters, but it | 
|  | 13 | might work. Just give it a try and let me know if you have problems. | 
|  | 14 | Also mail me if it really works, please! | 
|  | 15 |  | 
|  | 16 | Changelog: | 
|  | 17 | Mon Feb  3 16:26:02 MET 1997 | 
|  | 18 | - adapted the driver to work with the 2.1.25 kernel | 
|  | 19 | - multiple ne2 support (untested) | 
|  | 20 | - module support (untested) | 
|  | 21 |  | 
|  | 22 | Fri Aug 28 00:18:36 CET 1998 (David Weinehall) | 
|  | 23 | - fixed a few minor typos | 
|  | 24 | - made the MODULE_PARM conditional (it only works with the v2.1.x kernels) | 
|  | 25 | - fixed the module support (Now it's working...) | 
|  | 26 |  | 
|  | 27 | Mon Sep  7 19:01:44 CET 1998 (David Weinehall) | 
|  | 28 | - added support for Arco Electronics AE/2-card (experimental) | 
|  | 29 |  | 
|  | 30 | Mon Sep 14 09:53:42 CET 1998 (David Weinehall) | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 31 | - added support for Compex ENET-16MC/P (experimental) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 |  | 
|  | 33 | Tue Sep 15 16:21:12 CET 1998 (David Weinehall, Magnus Jonsson, Tomas Ogren) | 
|  | 34 | - Miscellaneous bugfixes | 
|  | 35 |  | 
|  | 36 | Tue Sep 19 16:21:12 CET 1998 (Magnus Jonsson) | 
|  | 37 | - Cleanup | 
|  | 38 |  | 
|  | 39 | Wed Sep 23 14:33:34 CET 1998 (David Weinehall) | 
|  | 40 | - Restructuring and rewriting for v2.1.x compliance | 
|  | 41 |  | 
|  | 42 | Wed Oct 14 17:19:21 CET 1998 (David Weinehall) | 
|  | 43 | - Added code that unregisters irq and proc-info | 
|  | 44 | - Version# bump | 
|  | 45 |  | 
|  | 46 | Mon Nov 16 15:28:23 CET 1998 (Wim Dumon) | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 47 | - pass 'dev' as last parameter of request_irq in stead of 'NULL' | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 |  | 
|  | 49 | Wed Feb  7 21:24:00 CET 2001 (Alfred Arnold) | 
|  | 50 | - added support for the D-Link DE-320CT | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 51 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | *    WARNING | 
|  | 53 | ------- | 
|  | 54 | This is alpha-test software.  It is not guaranteed to work. As a | 
|  | 55 | matter of fact, I'm quite sure there are *LOTS* of bugs in here. I | 
|  | 56 | would like to hear from you if you use this driver, even if it works. | 
|  | 57 | If it doesn't work, be sure to send me a mail with the problems ! | 
|  | 58 | */ | 
|  | 59 |  | 
|  | 60 | static const char *version = "ne2.c:v0.91 Nov 16 1998 Wim Dumon <wimpie@kotnet.org>\n"; | 
|  | 61 |  | 
|  | 62 | #include <linux/module.h> | 
|  | 63 | #include <linux/kernel.h> | 
|  | 64 | #include <linux/types.h> | 
|  | 65 | #include <linux/fcntl.h> | 
|  | 66 | #include <linux/interrupt.h> | 
|  | 67 | #include <linux/ioport.h> | 
|  | 68 | #include <linux/in.h> | 
|  | 69 | #include <linux/slab.h> | 
|  | 70 | #include <linux/string.h> | 
|  | 71 | #include <linux/errno.h> | 
|  | 72 | #include <linux/init.h> | 
|  | 73 | #include <linux/mca-legacy.h> | 
|  | 74 | #include <linux/netdevice.h> | 
|  | 75 | #include <linux/etherdevice.h> | 
|  | 76 | #include <linux/skbuff.h> | 
|  | 77 | #include <linux/bitops.h> | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 78 | #include <linux/jiffies.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 |  | 
|  | 80 | #include <asm/system.h> | 
|  | 81 | #include <asm/io.h> | 
|  | 82 | #include <asm/dma.h> | 
|  | 83 |  | 
|  | 84 | #include "8390.h" | 
|  | 85 |  | 
|  | 86 | #define DRV_NAME "ne2" | 
|  | 87 |  | 
|  | 88 | /* Some defines that people can play with if so inclined. */ | 
|  | 89 |  | 
|  | 90 | /* Do we perform extra sanity checks on stuff ? */ | 
|  | 91 | /* #define NE_SANITY_CHECK */ | 
|  | 92 |  | 
|  | 93 | /* Do we implement the read before write bugfix ? */ | 
|  | 94 | /* #define NE_RW_BUGFIX */ | 
|  | 95 |  | 
|  | 96 | /* Do we have a non std. amount of memory? (in units of 256 byte pages) */ | 
|  | 97 | /* #define PACKETBUF_MEMSIZE	0x40 */ | 
|  | 98 |  | 
|  | 99 |  | 
|  | 100 | /* ---- No user-serviceable parts below ---- */ | 
|  | 101 |  | 
|  | 102 | #define NE_BASE	 (dev->base_addr) | 
|  | 103 | #define NE_CMD	 	0x00 | 
|  | 104 | #define NE_DATAPORT	0x10	/* NatSemi-defined port window offset. */ | 
|  | 105 | #define NE_RESET	0x20	/* Issue a read to reset, a write to clear. */ | 
|  | 106 | #define NE_IO_EXTENT	0x30 | 
|  | 107 |  | 
|  | 108 | #define NE1SM_START_PG	0x20	/* First page of TX buffer */ | 
|  | 109 | #define NE1SM_STOP_PG 	0x40	/* Last page +1 of RX ring */ | 
|  | 110 | #define NESM_START_PG	0x40	/* First page of TX buffer */ | 
|  | 111 | #define NESM_STOP_PG	0x80	/* Last page +1 of RX ring */ | 
|  | 112 |  | 
|  | 113 | /* From the .ADF file: */ | 
|  | 114 | static unsigned int addresses[7] __initdata = | 
|  | 115 | {0x1000, 0x2020, 0x8020, 0xa0a0, 0xb0b0, 0xc0c0, 0xc3d0}; | 
|  | 116 | static int irqs[4] __initdata = {3, 4, 5, 9}; | 
|  | 117 |  | 
|  | 118 | /* From the D-Link ADF file: */ | 
|  | 119 | static unsigned int dlink_addresses[4] __initdata = | 
|  | 120 | {0x300, 0x320, 0x340, 0x360}; | 
|  | 121 | static int dlink_irqs[8] __initdata = {3, 4, 5, 9, 10, 11, 14, 15}; | 
|  | 122 |  | 
|  | 123 | struct ne2_adapters_t { | 
|  | 124 | unsigned int	id; | 
|  | 125 | char		*name; | 
|  | 126 | }; | 
|  | 127 |  | 
|  | 128 | static struct ne2_adapters_t ne2_adapters[] __initdata = { | 
|  | 129 | { 0x6354, "Arco Ethernet Adapter AE/2" }, | 
|  | 130 | { 0x70DE, "Compex ENET-16 MC/P" }, | 
|  | 131 | { 0x7154, "Novell Ethernet Adapter NE/2" }, | 
|  | 132 | { 0x56ea, "D-Link DE-320CT" }, | 
|  | 133 | { 0x0000, NULL } | 
|  | 134 | }; | 
|  | 135 |  | 
|  | 136 | extern int netcard_probe(struct net_device *dev); | 
|  | 137 |  | 
|  | 138 | static int ne2_probe1(struct net_device *dev, int slot); | 
|  | 139 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | static void ne_reset_8390(struct net_device *dev); | 
|  | 141 | static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, | 
|  | 142 | int ring_page); | 
|  | 143 | static void ne_block_input(struct net_device *dev, int count, | 
|  | 144 | struct sk_buff *skb, int ring_offset); | 
|  | 145 | static void ne_block_output(struct net_device *dev, const int count, | 
|  | 146 | const unsigned char *buf, const int start_page); | 
|  | 147 |  | 
|  | 148 |  | 
|  | 149 | /* | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 150 | * special code to read the DE-320's MAC address EEPROM.  In contrast to a | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | * standard NE design, this is a serial EEPROM (93C46) that has to be read | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 152 | * bit by bit.  The EEPROM cotrol port at base + 0x1e has the following | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | * layout: | 
|  | 154 | * | 
|  | 155 | * Bit 0 = Data out (read from EEPROM) | 
|  | 156 | * Bit 1 = Data in  (write to EEPROM) | 
|  | 157 | * Bit 2 = Clock | 
|  | 158 | * Bit 3 = Chip Select | 
|  | 159 | * Bit 7 = ~50 kHz clock for defined delays | 
|  | 160 | * | 
|  | 161 | */ | 
|  | 162 |  | 
|  | 163 | static void __init dlink_put_eeprom(unsigned char value, unsigned int addr) | 
|  | 164 | { | 
|  | 165 | int z; | 
|  | 166 | unsigned char v1, v2; | 
|  | 167 |  | 
|  | 168 | /* write the value to the NIC EEPROM register */ | 
|  | 169 |  | 
|  | 170 | outb(value, addr + 0x1e); | 
|  | 171 |  | 
|  | 172 | /* now wait the clock line to toggle twice.  Effectively, we are | 
|  | 173 | waiting (at least) for one clock cycle */ | 
|  | 174 |  | 
|  | 175 | for (z = 0; z < 2; z++) { | 
|  | 176 | do { | 
|  | 177 | v1 = inb(addr + 0x1e); | 
|  | 178 | v2 = inb(addr + 0x1e); | 
|  | 179 | } | 
|  | 180 | while (!((v1 ^ v2) & 0x80)); | 
|  | 181 | } | 
|  | 182 | } | 
|  | 183 |  | 
|  | 184 | static void __init dlink_send_eeprom_bit(unsigned int bit, unsigned int addr) | 
|  | 185 | { | 
|  | 186 | /* shift data bit into correct position */ | 
|  | 187 |  | 
|  | 188 | bit = bit << 1; | 
|  | 189 |  | 
|  | 190 | /* write value, keep clock line high for two cycles */ | 
|  | 191 |  | 
|  | 192 | dlink_put_eeprom(0x09 | bit, addr); | 
|  | 193 | dlink_put_eeprom(0x0d | bit, addr); | 
|  | 194 | dlink_put_eeprom(0x0d | bit, addr); | 
|  | 195 | dlink_put_eeprom(0x09 | bit, addr); | 
|  | 196 | } | 
|  | 197 |  | 
|  | 198 | static void __init dlink_send_eeprom_word(unsigned int value, unsigned int len, unsigned int addr) | 
|  | 199 | { | 
|  | 200 | int z; | 
|  | 201 |  | 
|  | 202 | /* adjust bits so that they are left-aligned in a 16-bit-word */ | 
|  | 203 |  | 
|  | 204 | value = value << (16 - len); | 
|  | 205 |  | 
|  | 206 | /* shift bits out to the EEPROM */ | 
|  | 207 |  | 
|  | 208 | for (z = 0; z < len; z++) { | 
|  | 209 | dlink_send_eeprom_bit((value & 0x8000) >> 15, addr); | 
|  | 210 | value = value << 1; | 
|  | 211 | } | 
|  | 212 | } | 
|  | 213 |  | 
|  | 214 | static unsigned int __init dlink_get_eeprom(unsigned int eeaddr, unsigned int addr) | 
|  | 215 | { | 
|  | 216 | int z; | 
|  | 217 | unsigned int value = 0; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 218 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | /* pull the CS line low for a moment.  This resets the EEPROM- | 
|  | 220 | internal logic, and makes it ready for a new command. */ | 
|  | 221 |  | 
|  | 222 | dlink_put_eeprom(0x01, addr); | 
|  | 223 | dlink_put_eeprom(0x09, addr); | 
|  | 224 |  | 
|  | 225 | /* send one start bit, read command (1 - 0), plus the address to | 
|  | 226 | the EEPROM */ | 
|  | 227 |  | 
|  | 228 | dlink_send_eeprom_word(0x0180 | (eeaddr & 0x3f), 9, addr); | 
|  | 229 |  | 
|  | 230 | /* get the data word.  We clock by sending 0s to the EEPROM, which | 
|  | 231 | get ignored during the read process */ | 
|  | 232 |  | 
|  | 233 | for (z = 0; z < 16; z++) { | 
|  | 234 | dlink_send_eeprom_bit(0, addr); | 
|  | 235 | value = (value << 1) | (inb(addr + 0x1e) & 0x01); | 
|  | 236 | } | 
|  | 237 |  | 
|  | 238 | return value; | 
|  | 239 | } | 
|  | 240 |  | 
|  | 241 | /* | 
|  | 242 | * Note that at boot, this probe only picks up one card at a time. | 
|  | 243 | */ | 
|  | 244 |  | 
|  | 245 | static int __init do_ne2_probe(struct net_device *dev) | 
|  | 246 | { | 
|  | 247 | static int current_mca_slot = -1; | 
|  | 248 | int i; | 
|  | 249 | int adapter_found = 0; | 
|  | 250 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 251 | /* Do not check any supplied i/o locations. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | POS registers usually don't fail :) */ | 
|  | 253 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 254 | /* MCA cards have POS registers. | 
|  | 255 | Autodetecting MCA cards is extremely simple. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | Just search for the card. */ | 
|  | 257 |  | 
|  | 258 | for(i = 0; (ne2_adapters[i].name != NULL) && !adapter_found; i++) { | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 259 | current_mca_slot = | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | mca_find_unused_adapter(ne2_adapters[i].id, 0); | 
|  | 261 |  | 
|  | 262 | if((current_mca_slot != MCA_NOTFOUND) && !adapter_found) { | 
|  | 263 | int res; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 264 | mca_set_adapter_name(current_mca_slot, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | ne2_adapters[i].name); | 
|  | 266 | mca_mark_as_used(current_mca_slot); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 267 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | res = ne2_probe1(dev, current_mca_slot); | 
|  | 269 | if (res) | 
|  | 270 | mca_mark_as_unused(current_mca_slot); | 
|  | 271 | return res; | 
|  | 272 | } | 
|  | 273 | } | 
|  | 274 | return -ENODEV; | 
|  | 275 | } | 
|  | 276 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | #ifndef MODULE | 
|  | 278 | struct net_device * __init ne2_probe(int unit) | 
|  | 279 | { | 
| Alan Cox | 055e511 | 2008-07-03 23:43:12 -0700 | [diff] [blame] | 280 | struct net_device *dev = alloc_eip_netdev(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | int err; | 
|  | 282 |  | 
|  | 283 | if (!dev) | 
|  | 284 | return ERR_PTR(-ENOMEM); | 
|  | 285 |  | 
|  | 286 | sprintf(dev->name, "eth%d", unit); | 
|  | 287 | netdev_boot_setup_check(dev); | 
|  | 288 |  | 
|  | 289 | err = do_ne2_probe(dev); | 
|  | 290 | if (err) | 
|  | 291 | goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | return dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | out: | 
|  | 294 | free_netdev(dev); | 
|  | 295 | return ERR_PTR(err); | 
|  | 296 | } | 
|  | 297 | #endif | 
|  | 298 |  | 
|  | 299 | static int ne2_procinfo(char *buf, int slot, struct net_device *dev) | 
|  | 300 | { | 
|  | 301 | int len=0; | 
|  | 302 |  | 
|  | 303 | len += sprintf(buf+len, "The NE/2 Ethernet Adapter\n" ); | 
|  | 304 | len += sprintf(buf+len, "Driver written by Wim Dumon "); | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 305 | len += sprintf(buf+len, "<wimpie@kotnet.org>\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | len += sprintf(buf+len, "Modified by "); | 
|  | 307 | len += sprintf(buf+len, "David Weinehall <tao@acc.umu.se>\n"); | 
|  | 308 | len += sprintf(buf+len, "and by Magnus Jonsson <bigfoot@acc.umu.se>\n"); | 
|  | 309 | len += sprintf(buf+len, "Based on the original NE2000 drivers\n" ); | 
|  | 310 | len += sprintf(buf+len, "Base IO: %#x\n", (unsigned int)dev->base_addr); | 
|  | 311 | len += sprintf(buf+len, "IRQ    : %d\n", dev->irq); | 
| Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 312 | len += sprintf(buf+len, "HW addr : %pM\n", dev->dev_addr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 |  | 
|  | 314 | return len; | 
|  | 315 | } | 
|  | 316 |  | 
|  | 317 | static int __init ne2_probe1(struct net_device *dev, int slot) | 
|  | 318 | { | 
|  | 319 | int i, base_addr, irq, retval; | 
|  | 320 | unsigned char POS; | 
|  | 321 | unsigned char SA_prom[32]; | 
|  | 322 | const char *name = "NE/2"; | 
|  | 323 | int start_page, stop_page; | 
|  | 324 | static unsigned version_printed; | 
|  | 325 |  | 
|  | 326 | if (ei_debug && version_printed++ == 0) | 
|  | 327 | printk(version); | 
|  | 328 |  | 
|  | 329 | printk("NE/2 ethercard found in slot %d:", slot); | 
|  | 330 |  | 
|  | 331 | /* Read base IO and IRQ from the POS-registers */ | 
|  | 332 | POS = mca_read_stored_pos(slot, 2); | 
|  | 333 | if(!(POS % 2)) { | 
|  | 334 | printk(" disabled.\n"); | 
|  | 335 | return -ENODEV; | 
|  | 336 | } | 
|  | 337 |  | 
|  | 338 | /* handle different POS register structure for D-Link card */ | 
|  | 339 |  | 
|  | 340 | if (mca_read_stored_pos(slot, 0) == 0xea) { | 
|  | 341 | base_addr = dlink_addresses[(POS >> 5) & 0x03]; | 
|  | 342 | irq = dlink_irqs[(POS >> 2) & 0x07]; | 
|  | 343 | } | 
|  | 344 | else { | 
|  | 345 | i = (POS & 0xE)>>1; | 
|  | 346 | /* printk("Halleluja sdog, als er na de pijl een 1 staat is 1 - 1 == 0" | 
|  | 347 | " en zou het moeten werken -> %d\n", i); | 
|  | 348 | The above line was for remote testing, thanx to sdog ... */ | 
|  | 349 | base_addr = addresses[i - 1]; | 
|  | 350 | irq = irqs[(POS & 0x60)>>5]; | 
|  | 351 | } | 
|  | 352 |  | 
|  | 353 | if (!request_region(base_addr, NE_IO_EXTENT, DRV_NAME)) | 
|  | 354 | return -EBUSY; | 
|  | 355 |  | 
|  | 356 | #ifdef DEBUG | 
|  | 357 | printk("POS info : pos 2 = %#x ; base = %#x ; irq = %ld\n", POS, | 
|  | 358 | base_addr, irq); | 
|  | 359 | #endif | 
|  | 360 |  | 
|  | 361 | #ifndef CRYNWR_WAY | 
|  | 362 | /* Reset the card the way they do it in the Crynwr packet driver */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 363 | for (i=0; i<8; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | outb(0x0, base_addr + NE_RESET); | 
|  | 365 | inb(base_addr + NE_RESET); | 
|  | 366 | outb(0x21, base_addr + NE_CMD); | 
|  | 367 | if (inb(base_addr + NE_CMD) != 0x21) { | 
|  | 368 | printk("NE/2 adapter not responding\n"); | 
|  | 369 | retval = -ENODEV; | 
|  | 370 | goto out; | 
|  | 371 | } | 
|  | 372 |  | 
|  | 373 | /* In the crynwr sources they do a RAM-test here. I skip it. I suppose | 
|  | 374 | my RAM is okay.  Suppose your memory is broken.  Then this test | 
|  | 375 | should fail and you won't be able to use your card.  But if I do not | 
|  | 376 | test, you won't be able to use your card, neither.  So this test | 
|  | 377 | won't help you. */ | 
|  | 378 |  | 
|  | 379 | #else  /* _I_ never tested it this way .. Go ahead and try ...*/ | 
|  | 380 | /* Reset card. Who knows what dain-bramaged state it was left in. */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 381 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | unsigned long reset_start_time = jiffies; | 
|  | 383 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 384 | /* DON'T change these to inb_p/outb_p or reset will fail on | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | clones.. */ | 
|  | 386 | outb(inb(base_addr + NE_RESET), base_addr + NE_RESET); | 
|  | 387 |  | 
|  | 388 | while ((inb_p(base_addr + EN0_ISR) & ENISR_RESET) == 0) | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 389 | if (time_after(jiffies, reset_start_time + 2*HZ/100)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | printk(" not found (no reset ack).\n"); | 
|  | 391 | retval = -ENODEV; | 
|  | 392 | goto out; | 
|  | 393 | } | 
|  | 394 |  | 
|  | 395 | outb_p(0xff, base_addr + EN0_ISR);         /* Ack all intr. */ | 
|  | 396 | } | 
|  | 397 | #endif | 
|  | 398 |  | 
|  | 399 |  | 
|  | 400 | /* Read the 16 bytes of station address PROM. | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 401 | We must first initialize registers, similar to | 
| Ingo Molnar | f0084a3 | 2008-07-22 09:23:34 +0200 | [diff] [blame] | 402 | NS8390p_init(eifdev, 0). | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | We can't reliably read the SAPROM address without this. | 
|  | 404 | (I learned the hard way!). */ | 
|  | 405 | { | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 406 | struct { | 
|  | 407 | unsigned char value, offset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } program_seq[] = { | 
|  | 409 | /* Select page 0 */ | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 410 | {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | {0x49,	EN0_DCFG},  /* Set WORD-wide (0x49) access. */ | 
|  | 412 | {0x00,	EN0_RCNTLO},  /* Clear the count regs. */ | 
|  | 413 | {0x00,	EN0_RCNTHI}, | 
|  | 414 | {0x00,	EN0_IMR},  /* Mask completion irq. */ | 
|  | 415 | {0xFF,	EN0_ISR}, | 
|  | 416 | {E8390_RXOFF, EN0_RXCR},  /* 0x20  Set to monitor */ | 
|  | 417 | {E8390_TXOFF, EN0_TXCR},  /* 0x02  and loopback mode. */ | 
|  | 418 | {32,	EN0_RCNTLO}, | 
|  | 419 | {0x00,	EN0_RCNTHI}, | 
|  | 420 | {0x00,	EN0_RSARLO},  /* DMA starting at 0x0000. */ | 
|  | 421 | {0x00,	EN0_RSARHI}, | 
|  | 422 | {E8390_RREAD+E8390_START, E8390_CMD}, | 
|  | 423 | }; | 
|  | 424 |  | 
| Denis Cheng | ff8ac60 | 2007-09-02 18:30:18 +0800 | [diff] [blame] | 425 | for (i = 0; i < ARRAY_SIZE(program_seq); i++) | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 426 | outb_p(program_seq[i].value, base_addr + | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | program_seq[i].offset); | 
|  | 428 |  | 
|  | 429 | } | 
|  | 430 | for(i = 0; i < 6 /*sizeof(SA_prom)*/; i+=1) { | 
|  | 431 | SA_prom[i] = inb(base_addr + NE_DATAPORT); | 
|  | 432 | } | 
|  | 433 |  | 
|  | 434 | /* I don't know whether the previous sequence includes the general | 
|  | 435 | board reset procedure, so better don't omit it and just overwrite | 
|  | 436 | the garbage read from a DE-320 with correct stuff. */ | 
|  | 437 |  | 
|  | 438 | if (mca_read_stored_pos(slot, 0) == 0xea) { | 
|  | 439 | unsigned int v; | 
|  | 440 |  | 
|  | 441 | for (i = 0; i < 3; i++) { | 
|  | 442 | v = dlink_get_eeprom(i, base_addr); | 
|  | 443 | SA_prom[(i << 1)    ] = v & 0xff; | 
|  | 444 | SA_prom[(i << 1) + 1] = (v >> 8) & 0xff; | 
|  | 445 | } | 
|  | 446 | } | 
|  | 447 |  | 
|  | 448 | start_page = NESM_START_PG; | 
|  | 449 | stop_page = NESM_STOP_PG; | 
|  | 450 |  | 
|  | 451 | dev->irq=irq; | 
|  | 452 |  | 
|  | 453 | /* Snarf the interrupt now.  There's no point in waiting since we cannot | 
|  | 454 | share and the board will usually be enabled. */ | 
| Alan Cox | 055e511 | 2008-07-03 23:43:12 -0700 | [diff] [blame] | 455 | retval = request_irq(dev->irq, eip_interrupt, 0, DRV_NAME, dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | if (retval) { | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 457 | printk (" unable to get IRQ %d (irqval=%d).\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | dev->irq, retval); | 
|  | 459 | goto out; | 
|  | 460 | } | 
|  | 461 |  | 
|  | 462 | dev->base_addr = base_addr; | 
|  | 463 |  | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 464 | for(i = 0; i < ETHER_ADDR_LEN; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | dev->dev_addr[i] = SA_prom[i]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 |  | 
| Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 467 | printk(" %pM\n", dev->dev_addr); | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 468 |  | 
|  | 469 | printk("%s: %s found at %#x, using IRQ %d.\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | dev->name, name, base_addr, dev->irq); | 
|  | 471 |  | 
|  | 472 | mca_set_adapter_procfn(slot, (MCA_ProcFn) ne2_procinfo, dev); | 
|  | 473 |  | 
|  | 474 | ei_status.name = name; | 
|  | 475 | ei_status.tx_start_page = start_page; | 
|  | 476 | ei_status.stop_page = stop_page; | 
|  | 477 | ei_status.word16 = (2 == 2); | 
|  | 478 |  | 
|  | 479 | ei_status.rx_start_page = start_page + TX_PAGES; | 
|  | 480 | #ifdef PACKETBUF_MEMSIZE | 
|  | 481 | /* Allow the packet buffer size to be overridden by know-it-alls. */ | 
|  | 482 | ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE; | 
|  | 483 | #endif | 
|  | 484 |  | 
|  | 485 | ei_status.reset_8390 = &ne_reset_8390; | 
|  | 486 | ei_status.block_input = &ne_block_input; | 
|  | 487 | ei_status.block_output = &ne_block_output; | 
|  | 488 | ei_status.get_8390_hdr = &ne_get_8390_hdr; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 489 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | ei_status.priv = slot; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 491 |  | 
| Stephen Hemminger | 50014f1 | 2008-11-25 18:25:14 -0800 | [diff] [blame] | 492 | dev->netdev_ops = &eip_netdev_ops; | 
| Alan Cox | 055e511 | 2008-07-03 23:43:12 -0700 | [diff] [blame] | 493 | NS8390p_init(dev, 0); | 
|  | b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 494 |  | 
|  | 495 | retval = register_netdev(dev); | 
|  | 496 | if (retval) | 
|  | 497 | goto out1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | return 0; | 
|  | b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 499 | out1: | 
|  | 500 | mca_set_adapter_procfn( ei_status.priv, NULL, NULL); | 
|  | 501 | free_irq(dev->irq, dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | out: | 
|  | 503 | release_region(base_addr, NE_IO_EXTENT); | 
|  | 504 | return retval; | 
|  | 505 | } | 
|  | 506 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | /* Hard reset the card.  This used to pause for the same period that a | 
|  | 508 | 8390 reset command required, but that shouldn't be necessary. */ | 
|  | 509 | static void ne_reset_8390(struct net_device *dev) | 
|  | 510 | { | 
|  | 511 | unsigned long reset_start_time = jiffies; | 
|  | 512 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 513 | if (ei_debug > 1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | printk("resetting the 8390 t=%ld...", jiffies); | 
|  | 515 |  | 
|  | 516 | /* DON'T change these to inb_p/outb_p or reset will fail on clones. */ | 
|  | 517 | outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET); | 
|  | 518 |  | 
|  | 519 | ei_status.txing = 0; | 
|  | 520 | ei_status.dmaing = 0; | 
|  | 521 |  | 
|  | 522 | /* This check _should_not_ be necessary, omit eventually. */ | 
|  | 523 | while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0) | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 524 | if (time_after(jiffies, reset_start_time + 2*HZ/100)) { | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 525 | printk("%s: ne_reset_8390() did not complete.\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | dev->name); | 
|  | 527 | break; | 
|  | 528 | } | 
|  | 529 | outb_p(ENISR_RESET, NE_BASE + EN0_ISR);	/* Ack intr. */ | 
|  | 530 | } | 
|  | 531 |  | 
|  | 532 | /* Grab the 8390 specific header. Similar to the block_input routine, but | 
|  | 533 | we don't need to be concerned with ring wrap as the header will be at | 
|  | 534 | the start of a page, so we optimize accordingly. */ | 
|  | 535 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 536 | static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | int ring_page) | 
|  | 538 | { | 
|  | 539 |  | 
|  | 540 | int nic_base = dev->base_addr; | 
|  | 541 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 542 | /* This *shouldn't* happen. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | If it does, it's the last thing you'll see */ | 
|  | 544 | if (ei_status.dmaing) { | 
|  | 545 | printk("%s: DMAing conflict in ne_get_8390_hdr " | 
|  | 546 | "[DMAstat:%d][irqlock:%d].\n", | 
|  | 547 | dev->name, ei_status.dmaing, ei_status.irqlock); | 
|  | 548 | return; | 
|  | 549 | } | 
|  | 550 |  | 
|  | 551 | ei_status.dmaing |= 0x01; | 
|  | 552 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); | 
|  | 553 | outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO); | 
|  | 554 | outb_p(0, nic_base + EN0_RCNTHI); | 
|  | 555 | outb_p(0, nic_base + EN0_RSARLO);		/* On page boundary */ | 
|  | 556 | outb_p(ring_page, nic_base + EN0_RSARHI); | 
|  | 557 | outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD); | 
|  | 558 |  | 
|  | 559 | if (ei_status.word16) | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 560 | insw(NE_BASE + NE_DATAPORT, hdr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | sizeof(struct e8390_pkt_hdr)>>1); | 
|  | 562 | else | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 563 | insb(NE_BASE + NE_DATAPORT, hdr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | sizeof(struct e8390_pkt_hdr)); | 
|  | 565 |  | 
|  | 566 | outb_p(ENISR_RDC, nic_base + EN0_ISR);	/* Ack intr. */ | 
|  | 567 | ei_status.dmaing &= ~0x01; | 
|  | 568 | } | 
|  | 569 |  | 
|  | 570 | /* Block input and output, similar to the Crynwr packet driver.  If you | 
|  | 571 | are porting to a new ethercard, look at the packet driver source for | 
|  | 572 | hints. The NEx000 doesn't share the on-board packet memory -- you have | 
|  | 573 | to put the packet out through the "remote DMA" dataport using outb. */ | 
|  | 574 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 575 | static void ne_block_input(struct net_device *dev, int count, struct sk_buff *skb, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | int ring_offset) | 
|  | 577 | { | 
|  | 578 | #ifdef NE_SANITY_CHECK | 
|  | 579 | int xfer_count = count; | 
|  | 580 | #endif | 
|  | 581 | int nic_base = dev->base_addr; | 
|  | 582 | char *buf = skb->data; | 
|  | 583 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 584 | /* This *shouldn't* happen. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | If it does, it's the last thing you'll see */ | 
|  | 586 | if (ei_status.dmaing) { | 
|  | 587 | printk("%s: DMAing conflict in ne_block_input " | 
|  | 588 | "[DMAstat:%d][irqlock:%d].\n", | 
|  | 589 | dev->name, ei_status.dmaing, ei_status.irqlock); | 
|  | 590 | return; | 
|  | 591 | } | 
|  | 592 | ei_status.dmaing |= 0x01; | 
|  | 593 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); | 
|  | 594 | outb_p(count & 0xff, nic_base + EN0_RCNTLO); | 
|  | 595 | outb_p(count >> 8, nic_base + EN0_RCNTHI); | 
|  | 596 | outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO); | 
|  | 597 | outb_p(ring_offset >> 8, nic_base + EN0_RSARHI); | 
|  | 598 | outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD); | 
|  | 599 | if (ei_status.word16) { | 
|  | 600 | insw(NE_BASE + NE_DATAPORT,buf,count>>1); | 
|  | 601 | if (count & 0x01) { | 
|  | 602 | buf[count-1] = inb(NE_BASE + NE_DATAPORT); | 
|  | 603 | #ifdef NE_SANITY_CHECK | 
|  | 604 | xfer_count++; | 
|  | 605 | #endif | 
|  | 606 | } | 
|  | 607 | } else { | 
|  | 608 | insb(NE_BASE + NE_DATAPORT, buf, count); | 
|  | 609 | } | 
|  | 610 |  | 
|  | 611 | #ifdef NE_SANITY_CHECK | 
|  | 612 | /* This was for the ALPHA version only, but enough people have | 
|  | 613 | been encountering problems so it is still here.  If you see | 
|  | 614 | this message you either 1) have a slightly incompatible clone | 
|  | 615 | or 2) have noise/speed problems with your bus. */ | 
|  | 616 | if (ei_debug > 1) {	/* DMA termination address check... */ | 
|  | 617 | int addr, tries = 20; | 
|  | 618 | do { | 
|  | 619 | /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here | 
|  | 620 | -- it's broken for Rx on some cards! */ | 
|  | 621 | int high = inb_p(nic_base + EN0_RSARHI); | 
|  | 622 | int low = inb_p(nic_base + EN0_RSARLO); | 
|  | 623 | addr = (high << 8) + low; | 
|  | 624 | if (((ring_offset + xfer_count) & 0xff) == low) | 
|  | 625 | break; | 
|  | 626 | } while (--tries > 0); | 
|  | 627 | if (tries <= 0) | 
|  | 628 | printk("%s: RX transfer address mismatch," | 
|  | 629 | "%#4.4x (expected) vs. %#4.4x (actual).\n", | 
|  | 630 | dev->name, ring_offset + xfer_count, addr); | 
|  | 631 | } | 
|  | 632 | #endif | 
|  | 633 | outb_p(ENISR_RDC, nic_base + EN0_ISR);	/* Ack intr. */ | 
|  | 634 | ei_status.dmaing &= ~0x01; | 
|  | 635 | } | 
|  | 636 |  | 
|  | 637 | static void ne_block_output(struct net_device *dev, int count, | 
|  | 638 | const unsigned char *buf, const int start_page) | 
|  | 639 | { | 
|  | 640 | int nic_base = NE_BASE; | 
|  | 641 | unsigned long dma_start; | 
|  | 642 | #ifdef NE_SANITY_CHECK | 
|  | 643 | int retries = 0; | 
|  | 644 | #endif | 
|  | 645 |  | 
|  | 646 | /* Round the count up for word writes. Do we need to do this? | 
|  | 647 | What effect will an odd byte count have on the 8390? | 
|  | 648 | I should check someday. */ | 
|  | 649 | if (ei_status.word16 && (count & 0x01)) | 
|  | 650 | count++; | 
|  | 651 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 652 | /* This *shouldn't* happen. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | If it does, it's the last thing you'll see */ | 
|  | 654 | if (ei_status.dmaing) { | 
|  | 655 | printk("%s: DMAing conflict in ne_block_output." | 
|  | 656 | "[DMAstat:%d][irqlock:%d]\n", | 
|  | 657 | dev->name, ei_status.dmaing, ei_status.irqlock); | 
|  | 658 | return; | 
|  | 659 | } | 
|  | 660 | ei_status.dmaing |= 0x01; | 
|  | 661 | /* We should already be in page 0, but to be safe... */ | 
|  | 662 | outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD); | 
|  | 663 |  | 
|  | 664 | #ifdef NE_SANITY_CHECK | 
|  | 665 | retry: | 
|  | 666 | #endif | 
|  | 667 |  | 
|  | 668 | #ifdef NE8390_RW_BUGFIX | 
|  | 669 | /* Handle the read-before-write bug the same way as the | 
|  | 670 | Crynwr packet driver -- the NatSemi method doesn't work. | 
|  | 671 | Actually this doesn't always work either, but if you have | 
|  | 672 | problems with your NEx000 this is better than nothing! */ | 
|  | 673 | outb_p(0x42, nic_base + EN0_RCNTLO); | 
|  | 674 | outb_p(0x00, nic_base + EN0_RCNTHI); | 
|  | 675 | outb_p(0x42, nic_base + EN0_RSARLO); | 
|  | 676 | outb_p(0x00, nic_base + EN0_RSARHI); | 
|  | 677 | outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD); | 
|  | 678 | /* Make certain that the dummy read has occurred. */ | 
|  | 679 | SLOW_DOWN_IO; | 
|  | 680 | SLOW_DOWN_IO; | 
|  | 681 | SLOW_DOWN_IO; | 
|  | 682 | #endif | 
|  | 683 |  | 
|  | 684 | outb_p(ENISR_RDC, nic_base + EN0_ISR); | 
|  | 685 |  | 
|  | 686 | /* Now the normal output. */ | 
|  | 687 | outb_p(count & 0xff, nic_base + EN0_RCNTLO); | 
|  | 688 | outb_p(count >> 8,   nic_base + EN0_RCNTHI); | 
|  | 689 | outb_p(0x00, nic_base + EN0_RSARLO); | 
|  | 690 | outb_p(start_page, nic_base + EN0_RSARHI); | 
|  | 691 |  | 
|  | 692 | outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD); | 
|  | 693 | if (ei_status.word16) { | 
|  | 694 | outsw(NE_BASE + NE_DATAPORT, buf, count>>1); | 
|  | 695 | } else { | 
|  | 696 | outsb(NE_BASE + NE_DATAPORT, buf, count); | 
|  | 697 | } | 
|  | 698 |  | 
|  | 699 | dma_start = jiffies; | 
|  | 700 |  | 
|  | 701 | #ifdef NE_SANITY_CHECK | 
|  | 702 | /* This was for the ALPHA version only, but enough people have | 
|  | 703 | been encountering problems so it is still here. */ | 
|  | 704 |  | 
|  | 705 | if (ei_debug > 1) {		/* DMA termination address check... */ | 
|  | 706 | int addr, tries = 20; | 
|  | 707 | do { | 
|  | 708 | int high = inb_p(nic_base + EN0_RSARHI); | 
|  | 709 | int low = inb_p(nic_base + EN0_RSARLO); | 
|  | 710 | addr = (high << 8) + low; | 
|  | 711 | if ((start_page << 8) + count == addr) | 
|  | 712 | break; | 
|  | 713 | } while (--tries > 0); | 
|  | 714 | if (tries <= 0) { | 
|  | 715 | printk("%s: Tx packet transfer address mismatch," | 
|  | 716 | "%#4.4x (expected) vs. %#4.4x (actual).\n", | 
|  | 717 | dev->name, (start_page << 8) + count, addr); | 
|  | 718 | if (retries++ == 0) | 
|  | 719 | goto retry; | 
|  | 720 | } | 
|  | 721 | } | 
|  | 722 | #endif | 
|  | 723 |  | 
|  | 724 | while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0) | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 725 | if (time_after(jiffies, dma_start + 2*HZ/100)) {		/* 20ms */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | printk("%s: timeout waiting for Tx RDC.\n", dev->name); | 
|  | 727 | ne_reset_8390(dev); | 
| Alan Cox | 055e511 | 2008-07-03 23:43:12 -0700 | [diff] [blame] | 728 | NS8390p_init(dev, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | break; | 
|  | 730 | } | 
|  | 731 |  | 
|  | 732 | outb_p(ENISR_RDC, nic_base + EN0_ISR);	/* Ack intr. */ | 
|  | 733 | ei_status.dmaing &= ~0x01; | 
|  | 734 | return; | 
|  | 735 | } | 
|  | 736 |  | 
|  | 737 |  | 
|  | 738 | #ifdef MODULE | 
|  | 739 | #define MAX_NE_CARDS	4	/* Max number of NE cards per module */ | 
|  | 740 | static struct net_device *dev_ne[MAX_NE_CARDS]; | 
|  | 741 | static int io[MAX_NE_CARDS]; | 
|  | 742 | static int irq[MAX_NE_CARDS]; | 
|  | 743 | static int bad[MAX_NE_CARDS];	/* 0xbad = bad sig or no reset ack */ | 
|  | 744 | MODULE_LICENSE("GPL"); | 
|  | 745 |  | 
|  | 746 | module_param_array(io, int, NULL, 0); | 
|  | 747 | module_param_array(irq, int, NULL, 0); | 
|  | 748 | module_param_array(bad, int, NULL, 0); | 
|  | 749 | MODULE_PARM_DESC(io, "(ignored)"); | 
|  | 750 | MODULE_PARM_DESC(irq, "(ignored)"); | 
|  | 751 | MODULE_PARM_DESC(bad, "(ignored)"); | 
|  | 752 |  | 
|  | 753 | /* Module code fixed by David Weinehall */ | 
|  | 754 |  | 
| Randy.Dunlap | 5d1f16c | 2006-06-10 12:13:35 -0700 | [diff] [blame] | 755 | int __init init_module(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | { | 
|  | 757 | struct net_device *dev; | 
|  | 758 | int this_dev, found = 0; | 
|  | 759 |  | 
|  | 760 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { | 
| Alan Cox | 055e511 | 2008-07-03 23:43:12 -0700 | [diff] [blame] | 761 | dev = alloc_eip_netdev(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | if (!dev) | 
|  | 763 | break; | 
|  | 764 | dev->irq = irq[this_dev]; | 
|  | 765 | dev->mem_end = bad[this_dev]; | 
|  | 766 | dev->base_addr = io[this_dev]; | 
|  | 767 | if (do_ne2_probe(dev) == 0) { | 
|  | b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 768 | dev_ne[found++] = dev; | 
|  | 769 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } | 
|  | 771 | free_netdev(dev); | 
|  | 772 | break; | 
|  | 773 | } | 
|  | 774 | if (found) | 
|  | 775 | return 0; | 
|  | 776 | printk(KERN_WARNING "ne2.c: No NE/2 card found\n"); | 
|  | 777 | return -ENXIO; | 
|  | 778 | } | 
|  | 779 |  | 
| Denis Vlasenko | 64916f1 | 2006-01-05 22:45:47 -0800 | [diff] [blame] | 780 | static void cleanup_card(struct net_device *dev) | 
|  | 781 | { | 
|  | 782 | mca_mark_as_unused(ei_status.priv); | 
|  | 783 | mca_set_adapter_procfn( ei_status.priv, NULL, NULL); | 
|  | 784 | free_irq(dev->irq, dev); | 
|  | 785 | release_region(dev->base_addr, NE_IO_EXTENT); | 
|  | 786 | } | 
|  | 787 |  | 
| Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 788 | void __exit cleanup_module(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | { | 
|  | 790 | int this_dev; | 
|  | 791 |  | 
|  | 792 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { | 
|  | 793 | struct net_device *dev = dev_ne[this_dev]; | 
|  | 794 | if (dev) { | 
|  | 795 | unregister_netdev(dev); | 
|  | 796 | cleanup_card(dev); | 
|  | 797 | free_netdev(dev); | 
|  | 798 | } | 
|  | 799 | } | 
|  | 800 | } | 
|  | 801 | #endif /* MODULE */ |