| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* ne-h8300.c: A NE2000 clone on H8/300 driver for linux. */ | 
|  | 2 | /* | 
|  | 3 | original ne.c | 
|  | 4 | Written 1992-94 by Donald Becker. | 
|  | 5 |  | 
|  | 6 | Copyright 1993 United States Government as represented by the | 
|  | 7 | Director, National Security Agency. | 
|  | 8 |  | 
|  | 9 | This software may be used and distributed according to the terms | 
|  | 10 | of the GNU General Public License, incorporated herein by reference. | 
|  | 11 |  | 
|  | 12 | The author may be reached as becker@scyld.com, or C/O | 
|  | 13 | Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403 | 
|  | 14 |  | 
|  | 15 | H8/300 modified | 
|  | 16 | Yoshinori Sato <ysato@users.sourceforge.jp> | 
|  | 17 | */ | 
|  | 18 |  | 
|  | 19 | static const char version1[] = | 
|  | 20 | "ne-h8300.c:v1.00 2004/04/11 ysato\n"; | 
|  | 21 |  | 
|  | 22 | #include <linux/module.h> | 
|  | 23 | #include <linux/kernel.h> | 
|  | 24 | #include <linux/errno.h> | 
|  | 25 | #include <linux/init.h> | 
|  | 26 | #include <linux/interrupt.h> | 
|  | 27 | #include <linux/delay.h> | 
|  | 28 | #include <linux/netdevice.h> | 
|  | 29 | #include <linux/etherdevice.h> | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 30 | #include <linux/jiffies.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 |  | 
|  | 32 | #include <asm/system.h> | 
|  | 33 | #include <asm/io.h> | 
|  | 34 | #include <asm/irq.h> | 
|  | 35 |  | 
| Al Viro | 3470cb1 | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 36 | #define EI_SHIFT(x)	(ei_local->reg_offset[x]) | 
|  | 37 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include "8390.h" | 
|  | 39 |  | 
|  | 40 | #define DRV_NAME "ne-h8300" | 
|  | 41 |  | 
|  | 42 | /* Some defines that people can play with if so inclined. */ | 
|  | 43 |  | 
|  | 44 | /* Do we perform extra sanity checks on stuff ? */ | 
|  | 45 | /* #define NE_SANITY_CHECK */ | 
|  | 46 |  | 
|  | 47 | /* Do we implement the read before write bugfix ? */ | 
|  | 48 | /* #define NE_RW_BUGFIX */ | 
|  | 49 |  | 
|  | 50 | /* Do we have a non std. amount of memory? (in units of 256 byte pages) */ | 
|  | 51 | /* #define PACKETBUF_MEMSIZE	0x40 */ | 
|  | 52 |  | 
|  | 53 | /* A zero-terminated list of I/O addresses to be probed at boot. */ | 
|  | 54 |  | 
|  | 55 | /* ---- No user-serviceable parts below ---- */ | 
|  | 56 |  | 
| Al Viro | 3470cb1 | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 57 | static const char version[] = | 
|  | 58 | "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n"; | 
|  | 59 |  | 
|  | 60 | #include "lib8390.c" | 
|  | 61 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #define NE_BASE	 (dev->base_addr) | 
|  | 63 | #define NE_CMD	 	0x00 | 
|  | 64 | #define NE_DATAPORT	(ei_status.word16?0x20:0x10)	/* NatSemi-defined port window offset. */ | 
|  | 65 | #define NE_RESET	(ei_status.word16?0x3f:0x1f)	/* Issue a read to reset, a write to clear. */ | 
|  | 66 | #define NE_IO_EXTENT	(ei_status.word16?0x40:0x20) | 
|  | 67 |  | 
|  | 68 | #define NESM_START_PG	0x40	/* First page of TX buffer */ | 
|  | 69 | #define NESM_STOP_PG	0x80	/* Last page +1 of RX ring */ | 
|  | 70 |  | 
|  | 71 | static int ne_probe1(struct net_device *dev, int ioaddr); | 
|  | 72 |  | 
|  | 73 | static int ne_open(struct net_device *dev); | 
|  | 74 | static int ne_close(struct net_device *dev); | 
|  | 75 |  | 
|  | 76 | static void ne_reset_8390(struct net_device *dev); | 
|  | 77 | static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, | 
|  | 78 | int ring_page); | 
|  | 79 | static void ne_block_input(struct net_device *dev, int count, | 
|  | 80 | struct sk_buff *skb, int ring_offset); | 
|  | 81 | static void ne_block_output(struct net_device *dev, const int count, | 
|  | 82 | const unsigned char *buf, const int start_page); | 
|  | 83 |  | 
|  | 84 |  | 
|  | 85 | static u32 reg_offset[16]; | 
|  | 86 |  | 
|  | 87 | static int __init init_reg_offset(struct net_device *dev,unsigned long base_addr) | 
|  | 88 | { | 
|  | 89 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | 
|  | 90 | int i; | 
|  | 91 | unsigned char bus_width; | 
|  | 92 |  | 
|  | 93 | bus_width = *(volatile unsigned char *)ABWCR; | 
|  | 94 | bus_width &= 1 << ((base_addr >> 21) & 7); | 
|  | 95 |  | 
| Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 96 | for (i = 0; i < ARRAY_SIZE(reg_offset); i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | if (bus_width == 0) | 
|  | 98 | reg_offset[i] = i * 2 + 1; | 
|  | 99 | else | 
|  | 100 | reg_offset[i] = i; | 
|  | 101 |  | 
|  | 102 | ei_local->reg_offset = reg_offset; | 
|  | 103 | return 0; | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 | static int __initdata h8300_ne_count = 0; | 
|  | 107 | #ifdef CONFIG_H8300H_H8MAX | 
|  | 108 | static unsigned long __initdata h8300_ne_base[] = { 0x800600 }; | 
|  | 109 | static int h8300_ne_irq[] = {EXT_IRQ4}; | 
|  | 110 | #endif | 
|  | 111 | #ifdef CONFIG_H8300H_AKI3068NET | 
|  | 112 | static unsigned long __initdata h8300_ne_base[] = { 0x200000 }; | 
|  | 113 | static int h8300_ne_irq[] = {EXT_IRQ5}; | 
|  | 114 | #endif | 
|  | 115 |  | 
|  | 116 | static inline int init_dev(struct net_device *dev) | 
|  | 117 | { | 
| Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 118 | if (h8300_ne_count < ARRAY_SIZE(h8300_ne_base)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | dev->base_addr = h8300_ne_base[h8300_ne_count]; | 
|  | 120 | dev->irq       = h8300_ne_irq[h8300_ne_count]; | 
|  | 121 | h8300_ne_count++; | 
|  | 122 | return 0; | 
|  | 123 | } else | 
|  | 124 | return -ENODEV; | 
|  | 125 | } | 
|  | 126 |  | 
|  | 127 | /*  Probe for various non-shared-memory ethercards. | 
|  | 128 |  | 
|  | 129 | NEx000-clone boards have a Station Address PROM (SAPROM) in the packet | 
|  | 130 | buffer memory space.  NE2000 clones have 0x57,0x57 in bytes 0x0e,0x0f of | 
|  | 131 | the SAPROM, while other supposed NE2000 clones must be detected by their | 
|  | 132 | SA prefix. | 
|  | 133 |  | 
|  | 134 | Reading the SAPROM from a word-wide card with the 8390 set in byte-wide | 
|  | 135 | mode results in doubled values, which can be detected and compensated for. | 
|  | 136 |  | 
|  | 137 | The probe is also responsible for initializing the card and filling | 
|  | 138 | in the 'dev' and 'ei_status' structures. | 
|  | 139 |  | 
|  | 140 | We use the minimum memory size for some ethercard product lines, iff we can't | 
|  | 141 | distinguish models.  You can increase the packet buffer size by setting | 
|  | 142 | PACKETBUF_MEMSIZE.  Reported Cabletron packet buffer locations are: | 
|  | 143 | E1010   starts at 0x100 and ends at 0x2000. | 
|  | 144 | E1010-x starts at 0x100 and ends at 0x8000. ("-x" means "more memory") | 
|  | 145 | E2010	 starts at 0x100 and ends at 0x4000. | 
|  | 146 | E2010-x starts at 0x100 and ends at 0xffff.  */ | 
|  | 147 |  | 
|  | 148 | static int __init do_ne_probe(struct net_device *dev) | 
|  | 149 | { | 
|  | 150 | unsigned int base_addr = dev->base_addr; | 
|  | 151 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* First check any supplied i/o locations. User knows best. <cough> */ | 
|  | 153 | if (base_addr > 0x1ff)	/* Check a single specified location. */ | 
|  | 154 | return ne_probe1(dev, base_addr); | 
|  | 155 | else if (base_addr != 0)	/* Don't probe at all. */ | 
|  | 156 | return -ENXIO; | 
|  | 157 |  | 
|  | 158 | return -ENODEV; | 
|  | 159 | } | 
|  | 160 |  | 
|  | 161 | static void cleanup_card(struct net_device *dev) | 
|  | 162 | { | 
|  | 163 | free_irq(dev->irq, dev); | 
|  | 164 | release_region(dev->base_addr, NE_IO_EXTENT); | 
|  | 165 | } | 
|  | 166 |  | 
|  | 167 | #ifndef MODULE | 
|  | 168 | struct net_device * __init ne_probe(int unit) | 
|  | 169 | { | 
| Al Viro | 3470cb1 | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 170 | struct net_device *dev = ____alloc_ei_netdev(0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | int err; | 
|  | 172 |  | 
|  | 173 | if (!dev) | 
|  | 174 | return ERR_PTR(-ENOMEM); | 
|  | 175 |  | 
|  | 176 | if (init_dev(dev)) | 
|  | 177 | return ERR_PTR(-ENODEV); | 
|  | 178 |  | 
|  | 179 | sprintf(dev->name, "eth%d", unit); | 
|  | 180 | netdev_boot_setup_check(dev); | 
|  | 181 |  | 
|  | 182 | err = init_reg_offset(dev, dev->base_addr); | 
|  | 183 | if (err) | 
|  | 184 | goto out; | 
|  | 185 |  | 
|  | 186 | err = do_ne_probe(dev); | 
|  | 187 | if (err) | 
|  | 188 | goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | out: | 
|  | 191 | free_netdev(dev); | 
|  | 192 | return ERR_PTR(err); | 
|  | 193 | } | 
|  | 194 | #endif | 
|  | 195 |  | 
|  | 196 | static int __init ne_probe1(struct net_device *dev, int ioaddr) | 
|  | 197 | { | 
|  | 198 | int i; | 
|  | 199 | unsigned char SA_prom[16]; | 
|  | 200 | int wordlength = 2; | 
|  | 201 | const char *name = NULL; | 
|  | 202 | int start_page, stop_page; | 
|  | 203 | int reg0, ret; | 
|  | 204 | static unsigned version_printed; | 
|  | 205 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | 
|  | 206 | unsigned char bus_width; | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 207 | DECLARE_MAC_BUF(mac); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 |  | 
|  | 209 | if (!request_region(ioaddr, NE_IO_EXTENT, DRV_NAME)) | 
|  | 210 | return -EBUSY; | 
|  | 211 |  | 
|  | 212 | reg0 = inb_p(ioaddr); | 
|  | 213 | if (reg0 == 0xFF) { | 
|  | 214 | ret = -ENODEV; | 
|  | 215 | goto err_out; | 
|  | 216 | } | 
|  | 217 |  | 
|  | 218 | /* Do a preliminary verification that we have a 8390. */ | 
|  | 219 | { | 
|  | 220 | int regd; | 
|  | 221 | outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD); | 
|  | 222 | regd = inb_p(ioaddr + EI_SHIFT(0x0d)); | 
|  | 223 | outb_p(0xff, ioaddr + EI_SHIFT(0x0d)); | 
|  | 224 | outb_p(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD); | 
|  | 225 | inb_p(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */ | 
|  | 226 | if (inb_p(ioaddr + EN0_COUNTER0) != 0) { | 
|  | 227 | outb_p(reg0, ioaddr + EI_SHIFT(0)); | 
|  | 228 | outb_p(regd, ioaddr + EI_SHIFT(0x0d));	/* Restore the old values. */ | 
|  | 229 | ret = -ENODEV; | 
|  | 230 | goto err_out; | 
|  | 231 | } | 
|  | 232 | } | 
|  | 233 |  | 
|  | 234 | if (ei_debug  &&  version_printed++ == 0) | 
|  | 235 | printk(KERN_INFO "%s", version1); | 
|  | 236 |  | 
|  | 237 | printk(KERN_INFO "NE*000 ethercard probe at %08x:", ioaddr); | 
|  | 238 |  | 
|  | 239 | /* Read the 16 bytes of station address PROM. | 
|  | 240 | We must first initialize registers, similar to NS8390_init(eifdev, 0). | 
|  | 241 | We can't reliably read the SAPROM address without this. | 
|  | 242 | (I learned the hard way!). */ | 
|  | 243 | { | 
|  | 244 | struct {unsigned char value, offset; } program_seq[] = | 
|  | 245 | { | 
|  | 246 | {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/ | 
|  | 247 | {0x48,	EN0_DCFG},	/* Set byte-wide (0x48) access. */ | 
|  | 248 | {0x00,	EN0_RCNTLO},	/* Clear the count regs. */ | 
|  | 249 | {0x00,	EN0_RCNTHI}, | 
|  | 250 | {0x00,	EN0_IMR},	/* Mask completion irq. */ | 
|  | 251 | {0xFF,	EN0_ISR}, | 
|  | 252 | {E8390_RXOFF, EN0_RXCR},	/* 0x20  Set to monitor */ | 
|  | 253 | {E8390_TXOFF, EN0_TXCR},	/* 0x02  and loopback mode. */ | 
|  | 254 | {32,	EN0_RCNTLO}, | 
|  | 255 | {0x00,	EN0_RCNTHI}, | 
|  | 256 | {0x00,	EN0_RSARLO},	/* DMA starting at 0x0000. */ | 
|  | 257 | {0x00,	EN0_RSARHI}, | 
|  | 258 | {E8390_RREAD+E8390_START, E8390_CMD}, | 
|  | 259 | }; | 
|  | 260 |  | 
| Denis Cheng | ff8ac60 | 2007-09-02 18:30:18 +0800 | [diff] [blame] | 261 | for (i = 0; i < ARRAY_SIZE(program_seq); i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | outb_p(program_seq[i].value, ioaddr + program_seq[i].offset); | 
|  | 263 |  | 
|  | 264 | } | 
|  | 265 | bus_width = *(volatile unsigned char *)ABWCR; | 
|  | 266 | bus_width &= 1 << ((ioaddr >> 21) & 7); | 
|  | 267 | ei_status.word16 = (bus_width == 0); /* temporary setting */ | 
|  | 268 | for(i = 0; i < 16 /*sizeof(SA_prom)*/; i++) { | 
|  | 269 | SA_prom[i] = inb_p(ioaddr + NE_DATAPORT); | 
|  | 270 | inb_p(ioaddr + NE_DATAPORT); /* dummy read */ | 
|  | 271 | } | 
|  | 272 |  | 
|  | 273 | start_page = NESM_START_PG; | 
|  | 274 | stop_page = NESM_STOP_PG; | 
|  | 275 |  | 
|  | 276 | if (bus_width) | 
|  | 277 | wordlength = 1; | 
|  | 278 | else | 
|  | 279 | outb_p(0x49, ioaddr + EN0_DCFG); | 
|  | 280 |  | 
|  | 281 | /* Set up the rest of the parameters. */ | 
|  | 282 | name = (wordlength == 2) ? "NE2000" : "NE1000"; | 
|  | 283 |  | 
|  | 284 | if (! dev->irq) { | 
|  | 285 | printk(" failed to detect IRQ line.\n"); | 
|  | 286 | ret = -EAGAIN; | 
|  | 287 | goto err_out; | 
|  | 288 | } | 
|  | 289 |  | 
|  | 290 | /* Snarf the interrupt now.  There's no point in waiting since we cannot | 
|  | 291 | share and the board will usually be enabled. */ | 
| Al Viro | 3470cb1 | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 292 | ret = request_irq(dev->irq, __ei_interrupt, 0, name, dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | if (ret) { | 
|  | 294 | printk (" unable to get IRQ %d (errno=%d).\n", dev->irq, ret); | 
|  | 295 | goto err_out; | 
|  | 296 | } | 
|  | 297 |  | 
|  | 298 | dev->base_addr = ioaddr; | 
|  | 299 |  | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 300 | for(i = 0; i < ETHER_ADDR_LEN; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | dev->dev_addr[i] = SA_prom[i]; | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 302 | printk(" %s\n", print_mac(mac, dev->dev_addr)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 |  | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 304 | printk("%s: %s found at %#x, using IRQ %d.\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | dev->name, name, ioaddr, dev->irq); | 
|  | 306 |  | 
|  | 307 | ei_status.name = name; | 
|  | 308 | ei_status.tx_start_page = start_page; | 
|  | 309 | ei_status.stop_page = stop_page; | 
|  | 310 | ei_status.word16 = (wordlength == 2); | 
|  | 311 |  | 
|  | 312 | ei_status.rx_start_page = start_page + TX_PAGES; | 
|  | 313 | #ifdef PACKETBUF_MEMSIZE | 
|  | 314 | /* Allow the packet buffer size to be overridden by know-it-alls. */ | 
|  | 315 | ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE; | 
|  | 316 | #endif | 
|  | 317 |  | 
|  | 318 | ei_status.reset_8390 = &ne_reset_8390; | 
|  | 319 | ei_status.block_input = &ne_block_input; | 
|  | 320 | ei_status.block_output = &ne_block_output; | 
|  | 321 | ei_status.get_8390_hdr = &ne_get_8390_hdr; | 
|  | 322 | ei_status.priv = 0; | 
|  | 323 | dev->open = &ne_open; | 
|  | 324 | dev->stop = &ne_close; | 
|  | 325 | #ifdef CONFIG_NET_POLL_CONTROLLER | 
| Al Viro | 3470cb1 | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 326 | dev->poll_controller = __ei_poll; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | #endif | 
| Al Viro | 3470cb1 | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 328 | __NS8390_init(dev, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 |  | 
|  | b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 330 | ret = register_netdev(dev); | 
|  | 331 | if (ret) | 
|  | 332 | goto out_irq; | 
|  | 333 | return 0; | 
|  | 334 | out_irq: | 
|  | 335 | free_irq(dev->irq, dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | err_out: | 
|  | 337 | release_region(ioaddr, NE_IO_EXTENT); | 
|  | 338 | return ret; | 
|  | 339 | } | 
|  | 340 |  | 
|  | 341 | static int ne_open(struct net_device *dev) | 
|  | 342 | { | 
| Al Viro | 3470cb1 | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 343 | __ei_open(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | return 0; | 
|  | 345 | } | 
|  | 346 |  | 
|  | 347 | static int ne_close(struct net_device *dev) | 
|  | 348 | { | 
|  | 349 | if (ei_debug > 1) | 
|  | 350 | printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name); | 
| Al Viro | 3470cb1 | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 351 | __ei_close(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return 0; | 
|  | 353 | } | 
|  | 354 |  | 
|  | 355 | /* Hard reset the card.  This used to pause for the same period that a | 
|  | 356 | 8390 reset command required, but that shouldn't be necessary. */ | 
|  | 357 |  | 
|  | 358 | static void ne_reset_8390(struct net_device *dev) | 
|  | 359 | { | 
|  | 360 | unsigned long reset_start_time = jiffies; | 
|  | 361 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | 
|  | 362 |  | 
|  | 363 | if (ei_debug > 1) | 
|  | 364 | printk(KERN_DEBUG "resetting the 8390 t=%ld...", jiffies); | 
|  | 365 |  | 
|  | 366 | /* DON'T change these to inb_p/outb_p or reset will fail on clones. */ | 
|  | 367 | outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET); | 
|  | 368 |  | 
|  | 369 | ei_status.txing = 0; | 
|  | 370 | ei_status.dmaing = 0; | 
|  | 371 |  | 
|  | 372 | /* This check _should_not_ be necessary, omit eventually. */ | 
|  | 373 | while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0) | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 374 | if (time_after(jiffies, reset_start_time + 2*HZ/100)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | printk(KERN_WARNING "%s: ne_reset_8390() did not complete.\n", dev->name); | 
|  | 376 | break; | 
|  | 377 | } | 
|  | 378 | outb_p(ENISR_RESET, NE_BASE + EN0_ISR);	/* Ack intr. */ | 
|  | 379 | } | 
|  | 380 |  | 
|  | 381 | /* Grab the 8390 specific header. Similar to the block_input routine, but | 
|  | 382 | we don't need to be concerned with ring wrap as the header will be at | 
|  | 383 | the start of a page, so we optimize accordingly. */ | 
|  | 384 |  | 
|  | 385 | static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) | 
|  | 386 | { | 
|  | 387 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | 
|  | 388 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ | 
|  | 389 |  | 
|  | 390 | if (ei_status.dmaing) | 
|  | 391 | { | 
|  | 392 | printk(KERN_EMERG "%s: DMAing conflict in ne_get_8390_hdr " | 
|  | 393 | "[DMAstat:%d][irqlock:%d].\n", | 
|  | 394 | dev->name, ei_status.dmaing, ei_status.irqlock); | 
|  | 395 | return; | 
|  | 396 | } | 
|  | 397 |  | 
|  | 398 | ei_status.dmaing |= 0x01; | 
|  | 399 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, NE_BASE + NE_CMD); | 
|  | 400 | outb_p(sizeof(struct e8390_pkt_hdr), NE_BASE + EN0_RCNTLO); | 
|  | 401 | outb_p(0, NE_BASE + EN0_RCNTHI); | 
|  | 402 | outb_p(0, NE_BASE + EN0_RSARLO);		/* On page boundary */ | 
|  | 403 | outb_p(ring_page, NE_BASE + EN0_RSARHI); | 
|  | 404 | outb_p(E8390_RREAD+E8390_START, NE_BASE + NE_CMD); | 
|  | 405 |  | 
|  | 406 | if (ei_status.word16) { | 
|  | 407 | int len; | 
|  | 408 | unsigned short *p = (unsigned short *)hdr; | 
|  | 409 | for (len = sizeof(struct e8390_pkt_hdr)>>1; len > 0; len--) | 
|  | 410 | *p++ = inw(NE_BASE + NE_DATAPORT); | 
|  | 411 | } else | 
|  | 412 | insb(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)); | 
|  | 413 |  | 
|  | 414 | outb_p(ENISR_RDC, NE_BASE + EN0_ISR);	/* Ack intr. */ | 
|  | 415 | ei_status.dmaing &= ~0x01; | 
|  | 416 |  | 
|  | 417 | le16_to_cpus(&hdr->count); | 
|  | 418 | } | 
|  | 419 |  | 
|  | 420 | /* Block input and output, similar to the Crynwr packet driver.  If you | 
|  | 421 | are porting to a new ethercard, look at the packet driver source for hints. | 
|  | 422 | The NEx000 doesn't share the on-board packet memory -- you have to put | 
|  | 423 | the packet out through the "remote DMA" dataport using outb. */ | 
|  | 424 |  | 
|  | 425 | static void ne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset) | 
|  | 426 | { | 
|  | 427 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | 
|  | 428 | #ifdef NE_SANITY_CHECK | 
|  | 429 | int xfer_count = count; | 
|  | 430 | #endif | 
|  | 431 | char *buf = skb->data; | 
|  | 432 |  | 
|  | 433 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ | 
|  | 434 | if (ei_status.dmaing) | 
|  | 435 | { | 
|  | 436 | printk(KERN_EMERG "%s: DMAing conflict in ne_block_input " | 
|  | 437 | "[DMAstat:%d][irqlock:%d].\n", | 
|  | 438 | dev->name, ei_status.dmaing, ei_status.irqlock); | 
|  | 439 | return; | 
|  | 440 | } | 
|  | 441 | ei_status.dmaing |= 0x01; | 
|  | 442 | outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, NE_BASE + NE_CMD); | 
|  | 443 | outb_p(count & 0xff, NE_BASE + EN0_RCNTLO); | 
|  | 444 | outb_p(count >> 8, NE_BASE + EN0_RCNTHI); | 
|  | 445 | outb_p(ring_offset & 0xff, NE_BASE + EN0_RSARLO); | 
|  | 446 | outb_p(ring_offset >> 8, NE_BASE + EN0_RSARHI); | 
|  | 447 | outb_p(E8390_RREAD+E8390_START, NE_BASE + NE_CMD); | 
|  | 448 | if (ei_status.word16) | 
|  | 449 | { | 
|  | 450 | int len; | 
|  | 451 | unsigned short *p = (unsigned short *)buf; | 
|  | 452 | for (len = count>>1; len > 0; len--) | 
|  | 453 | *p++ = inw(NE_BASE + NE_DATAPORT); | 
|  | 454 | if (count & 0x01) | 
|  | 455 | { | 
|  | 456 | buf[count-1] = inb(NE_BASE + NE_DATAPORT); | 
|  | 457 | #ifdef NE_SANITY_CHECK | 
|  | 458 | xfer_count++; | 
|  | 459 | #endif | 
|  | 460 | } | 
|  | 461 | } else { | 
|  | 462 | insb(NE_BASE + NE_DATAPORT, buf, count); | 
|  | 463 | } | 
|  | 464 |  | 
|  | 465 | #ifdef NE_SANITY_CHECK | 
|  | 466 | /* This was for the ALPHA version only, but enough people have | 
|  | 467 | been encountering problems so it is still here.  If you see | 
|  | 468 | this message you either 1) have a slightly incompatible clone | 
|  | 469 | or 2) have noise/speed problems with your bus. */ | 
|  | 470 |  | 
|  | 471 | if (ei_debug > 1) | 
|  | 472 | { | 
|  | 473 | /* DMA termination address check... */ | 
|  | 474 | int addr, tries = 20; | 
|  | 475 | do { | 
|  | 476 | /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here | 
|  | 477 | -- it's broken for Rx on some cards! */ | 
|  | 478 | int high = inb_p(NE_BASE + EN0_RSARHI); | 
|  | 479 | int low = inb_p(NE_BASE + EN0_RSARLO); | 
|  | 480 | addr = (high << 8) + low; | 
|  | 481 | if (((ring_offset + xfer_count) & 0xff) == low) | 
|  | 482 | break; | 
|  | 483 | } while (--tries > 0); | 
|  | 484 | if (tries <= 0) | 
|  | 485 | printk(KERN_WARNING "%s: RX transfer address mismatch," | 
|  | 486 | "%#4.4x (expected) vs. %#4.4x (actual).\n", | 
|  | 487 | dev->name, ring_offset + xfer_count, addr); | 
|  | 488 | } | 
|  | 489 | #endif | 
|  | 490 | outb_p(ENISR_RDC, NE_BASE + EN0_ISR);	/* Ack intr. */ | 
|  | 491 | ei_status.dmaing &= ~0x01; | 
|  | 492 | } | 
|  | 493 |  | 
|  | 494 | static void ne_block_output(struct net_device *dev, int count, | 
|  | 495 | const unsigned char *buf, const int start_page) | 
|  | 496 | { | 
|  | 497 | struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); | 
|  | 498 | unsigned long dma_start; | 
|  | 499 | #ifdef NE_SANITY_CHECK | 
|  | 500 | int retries = 0; | 
|  | 501 | #endif | 
|  | 502 |  | 
|  | 503 | /* Round the count up for word writes.  Do we need to do this? | 
|  | 504 | What effect will an odd byte count have on the 8390? | 
|  | 505 | I should check someday. */ | 
|  | 506 |  | 
|  | 507 | if (ei_status.word16 && (count & 0x01)) | 
|  | 508 | count++; | 
|  | 509 |  | 
|  | 510 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ | 
|  | 511 | if (ei_status.dmaing) | 
|  | 512 | { | 
|  | 513 | printk(KERN_EMERG "%s: DMAing conflict in ne_block_output." | 
|  | 514 | "[DMAstat:%d][irqlock:%d]\n", | 
|  | 515 | dev->name, ei_status.dmaing, ei_status.irqlock); | 
|  | 516 | return; | 
|  | 517 | } | 
|  | 518 | ei_status.dmaing |= 0x01; | 
|  | 519 | /* We should already be in page 0, but to be safe... */ | 
|  | 520 | outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, NE_BASE + NE_CMD); | 
|  | 521 |  | 
|  | 522 | #ifdef NE_SANITY_CHECK | 
|  | 523 | retry: | 
|  | 524 | #endif | 
|  | 525 |  | 
|  | 526 | #ifdef NE8390_RW_BUGFIX | 
|  | 527 | /* Handle the read-before-write bug the same way as the | 
|  | 528 | Crynwr packet driver -- the NatSemi method doesn't work. | 
|  | 529 | Actually this doesn't always work either, but if you have | 
|  | 530 | problems with your NEx000 this is better than nothing! */ | 
|  | 531 |  | 
|  | 532 | outb_p(0x42, NE_BASE + EN0_RCNTLO); | 
|  | 533 | outb_p(0x00, NE_BASE + EN0_RCNTHI); | 
|  | 534 | outb_p(0x42, NE_BASE + EN0_RSARLO); | 
|  | 535 | outb_p(0x00, NE_BASE + EN0_RSARHI); | 
|  | 536 | outb_p(E8390_RREAD+E8390_START, NE_BASE + NE_CMD); | 
|  | 537 | /* Make certain that the dummy read has occurred. */ | 
|  | 538 | udelay(6); | 
|  | 539 | #endif | 
|  | 540 |  | 
|  | 541 | outb_p(ENISR_RDC, NE_BASE + EN0_ISR); | 
|  | 542 |  | 
|  | 543 | /* Now the normal output. */ | 
|  | 544 | outb_p(count & 0xff, NE_BASE + EN0_RCNTLO); | 
|  | 545 | outb_p(count >> 8,   NE_BASE + EN0_RCNTHI); | 
|  | 546 | outb_p(0x00, NE_BASE + EN0_RSARLO); | 
|  | 547 | outb_p(start_page, NE_BASE + EN0_RSARHI); | 
|  | 548 |  | 
|  | 549 | outb_p(E8390_RWRITE+E8390_START, NE_BASE + NE_CMD); | 
|  | 550 | if (ei_status.word16) { | 
|  | 551 | int len; | 
|  | 552 | unsigned short *p = (unsigned short *)buf; | 
|  | 553 | for (len = count>>1; len > 0; len--) | 
|  | 554 | outw(*p++, NE_BASE + NE_DATAPORT); | 
|  | 555 | } else { | 
|  | 556 | outsb(NE_BASE + NE_DATAPORT, buf, count); | 
|  | 557 | } | 
|  | 558 |  | 
|  | 559 | dma_start = jiffies; | 
|  | 560 |  | 
|  | 561 | #ifdef NE_SANITY_CHECK | 
|  | 562 | /* This was for the ALPHA version only, but enough people have | 
|  | 563 | been encountering problems so it is still here. */ | 
|  | 564 |  | 
|  | 565 | if (ei_debug > 1) | 
|  | 566 | { | 
|  | 567 | /* DMA termination address check... */ | 
|  | 568 | int addr, tries = 20; | 
|  | 569 | do { | 
|  | 570 | int high = inb_p(NE_BASE + EN0_RSARHI); | 
|  | 571 | int low = inb_p(NE_BASE + EN0_RSARLO); | 
|  | 572 | addr = (high << 8) + low; | 
|  | 573 | if ((start_page << 8) + count == addr) | 
|  | 574 | break; | 
|  | 575 | } while (--tries > 0); | 
|  | 576 |  | 
|  | 577 | if (tries <= 0) | 
|  | 578 | { | 
|  | 579 | printk(KERN_WARNING "%s: Tx packet transfer address mismatch," | 
|  | 580 | "%#4.4x (expected) vs. %#4.4x (actual).\n", | 
|  | 581 | dev->name, (start_page << 8) + count, addr); | 
|  | 582 | if (retries++ == 0) | 
|  | 583 | goto retry; | 
|  | 584 | } | 
|  | 585 | } | 
|  | 586 | #endif | 
|  | 587 |  | 
|  | 588 | while ((inb_p(NE_BASE + EN0_ISR) & ENISR_RDC) == 0) | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 589 | if (time_after(jiffies, dma_start + 2*HZ/100)) {		/* 20ms */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | printk(KERN_WARNING "%s: timeout waiting for Tx RDC.\n", dev->name); | 
|  | 591 | ne_reset_8390(dev); | 
| Al Viro | 3470cb1 | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 592 | __NS8390_init(dev,1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | break; | 
|  | 594 | } | 
|  | 595 |  | 
|  | 596 | outb_p(ENISR_RDC, NE_BASE + EN0_ISR);	/* Ack intr. */ | 
|  | 597 | ei_status.dmaing &= ~0x01; | 
|  | 598 | return; | 
|  | 599 | } | 
|  | 600 |  | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 601 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | #ifdef MODULE | 
|  | 603 | #define MAX_NE_CARDS	1	/* Max number of NE cards per module */ | 
|  | 604 | static struct net_device *dev_ne[MAX_NE_CARDS]; | 
|  | 605 | static int io[MAX_NE_CARDS]; | 
|  | 606 | static int irq[MAX_NE_CARDS]; | 
|  | 607 | static int bad[MAX_NE_CARDS];	/* 0xbad = bad sig or no reset ack */ | 
|  | 608 |  | 
| Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 609 | module_param_array(io, int, NULL, 0); | 
|  | 610 | module_param_array(irq, int, NULL, 0); | 
|  | 611 | module_param_array(bad, int, NULL, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | MODULE_PARM_DESC(io, "I/O base address(es)"); | 
|  | 613 | MODULE_PARM_DESC(irq, "IRQ number(s)"); | 
|  | 614 | MODULE_DESCRIPTION("H8/300 NE2000 Ethernet driver"); | 
|  | 615 | MODULE_LICENSE("GPL"); | 
|  | 616 |  | 
|  | 617 | /* This is set up so that no ISA autoprobe takes place. We can't guarantee | 
|  | 618 | that the ne2k probe is the last 8390 based probe to take place (as it | 
|  | 619 | is at boot) and so the probe will get confused by any other 8390 cards. | 
|  | 620 | ISA device autoprobes on a running machine are not recommended anyway. */ | 
|  | 621 |  | 
|  | 622 | int init_module(void) | 
|  | 623 | { | 
|  | 624 | int this_dev, found = 0; | 
|  | 625 | int err; | 
|  | 626 |  | 
|  | 627 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { | 
| Al Viro | 3470cb1 | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 628 | struct net_device *dev = ____alloc_ei_netdev(0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | if (!dev) | 
|  | 630 | break; | 
|  | 631 | if (io[this_dev]) { | 
|  | 632 | dev->irq = irq[this_dev]; | 
|  | 633 | dev->mem_end = bad[this_dev]; | 
|  | 634 | dev->base_addr = io[this_dev]; | 
|  | 635 | } else { | 
|  | 636 | dev->base_addr = h8300_ne_base[this_dev]; | 
|  | 637 | dev->irq = h8300_ne_irq[this_dev]; | 
|  | 638 | } | 
|  | 639 | err = init_reg_offset(dev, dev->base_addr); | 
|  | 640 | if (!err) { | 
|  | 641 | if (do_ne_probe(dev) == 0) { | 
|  | b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 642 | dev_ne[found++] = dev; | 
|  | 643 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | } | 
|  | 645 | } | 
|  | 646 | free_netdev(dev); | 
|  | 647 | if (found) | 
|  | 648 | break; | 
|  | 649 | if (io[this_dev] != 0) | 
|  | 650 | printk(KERN_WARNING "ne.c: No NE*000 card found at i/o = %#x\n", dev->base_addr); | 
|  | 651 | else | 
|  | 652 | printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\" value(s) for ISA cards.\n"); | 
|  | 653 | return -ENXIO; | 
|  | 654 | } | 
|  | 655 | if (found) | 
|  | 656 | return 0; | 
|  | 657 | return -ENODEV; | 
|  | 658 | } | 
|  | 659 |  | 
|  | 660 | void cleanup_module(void) | 
|  | 661 | { | 
|  | 662 | int this_dev; | 
|  | 663 |  | 
|  | 664 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { | 
|  | 665 | struct net_device *dev = dev_ne[this_dev]; | 
|  | 666 | if (dev) { | 
|  | 667 | unregister_netdev(dev); | 
|  | 668 | cleanup_card(dev); | 
|  | 669 | free_netdev(dev); | 
|  | 670 | } | 
|  | 671 | } | 
|  | 672 | } | 
|  | 673 | #endif /* MODULE */ |