Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Amiga Linux/m68k and Linux/PPC Zorro NS8390 Ethernet Driver |
| 3 | * |
| 4 | * (C) Copyright 1998-2000 by some Elitist 680x0 Users(TM) |
| 5 | * |
| 6 | * --------------------------------------------------------------------------- |
| 7 | * |
| 8 | * This program is based on all the other NE2000 drivers for Linux |
| 9 | * |
| 10 | * --------------------------------------------------------------------------- |
| 11 | * |
| 12 | * This file is subject to the terms and conditions of the GNU General Public |
| 13 | * License. See the file COPYING in the main directory of the Linux |
| 14 | * distribution for more details. |
| 15 | * |
| 16 | * --------------------------------------------------------------------------- |
| 17 | * |
| 18 | * The Ariadne II and X-Surf are Zorro-II boards containing Realtek RTL8019AS |
| 19 | * Ethernet Controllers. |
| 20 | */ |
| 21 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/module.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <linux/netdevice.h> |
| 30 | #include <linux/etherdevice.h> |
| 31 | #include <linux/zorro.h> |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 32 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/irq.h> |
| 35 | #include <asm/amigaints.h> |
| 36 | #include <asm/amigahw.h> |
| 37 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 38 | #define EI_SHIFT(x) (ei_local->reg_offset[x]) |
| 39 | #define ei_inb(port) in_8(port) |
| 40 | #define ei_outb(val, port) out_8(port, val) |
| 41 | #define ei_inb_p(port) in_8(port) |
| 42 | #define ei_outb_p(val, port) out_8(port, val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 44 | static const char version[] = |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 45 | "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n"; |
Al Viro | 8c6270f | 2006-10-10 00:19:36 +0100 | [diff] [blame] | 46 | |
| 47 | #include "lib8390.c" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define DRV_NAME "zorro8390" |
| 50 | |
| 51 | #define NE_BASE (dev->base_addr) |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 52 | #define NE_CMD (0x00 * 2) |
| 53 | #define NE_DATAPORT (0x10 * 2) /* NatSemi-defined port window offset */ |
| 54 | #define NE_RESET (0x1f * 2) /* Issue a read to reset, |
| 55 | * a write to clear. */ |
| 56 | #define NE_IO_EXTENT (0x20 * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 58 | #define NE_EN0_ISR (0x07 * 2) |
| 59 | #define NE_EN0_DCFG (0x0e * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 61 | #define NE_EN0_RSARLO (0x08 * 2) |
| 62 | #define NE_EN0_RSARHI (0x09 * 2) |
| 63 | #define NE_EN0_RCNTLO (0x0a * 2) |
| 64 | #define NE_EN0_RXCR (0x0c * 2) |
| 65 | #define NE_EN0_TXCR (0x0d * 2) |
| 66 | #define NE_EN0_RCNTHI (0x0b * 2) |
| 67 | #define NE_EN0_IMR (0x0f * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define NESM_START_PG 0x40 /* First page of TX buffer */ |
| 70 | #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */ |
| 71 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 72 | #define WORDSWAP(a) ((((a) >> 8) & 0xff) | ((a) << 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | static struct card_info { |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 75 | zorro_id id; |
| 76 | const char *name; |
| 77 | unsigned int offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } cards[] __devinitdata = { |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 79 | { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE2, "Ariadne II", 0x0600 }, |
| 80 | { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, "X-Surf", 0x8600 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 83 | /* Hard reset the card. This used to pause for the same period that a |
| 84 | * 8390 reset command required, but that shouldn't be necessary. |
| 85 | */ |
| 86 | static void zorro8390_reset_8390(struct net_device *dev) |
| 87 | { |
| 88 | unsigned long reset_start_time = jiffies; |
| 89 | |
| 90 | if (ei_debug > 1) |
| 91 | netdev_dbg(dev, "resetting - t=%ld...\n", jiffies); |
| 92 | |
| 93 | z_writeb(z_readb(NE_BASE + NE_RESET), NE_BASE + NE_RESET); |
| 94 | |
| 95 | ei_status.txing = 0; |
| 96 | ei_status.dmaing = 0; |
| 97 | |
| 98 | /* This check _should_not_ be necessary, omit eventually. */ |
| 99 | while ((z_readb(NE_BASE + NE_EN0_ISR) & ENISR_RESET) == 0) |
| 100 | if (time_after(jiffies, reset_start_time + 2 * HZ / 100)) { |
| 101 | netdev_warn(dev, "%s: did not complete\n", __func__); |
| 102 | break; |
| 103 | } |
| 104 | z_writeb(ENISR_RESET, NE_BASE + NE_EN0_ISR); /* Ack intr */ |
| 105 | } |
| 106 | |
| 107 | /* Grab the 8390 specific header. Similar to the block_input routine, but |
| 108 | * we don't need to be concerned with ring wrap as the header will be at |
| 109 | * the start of a page, so we optimize accordingly. |
| 110 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | static void zorro8390_get_8390_hdr(struct net_device *dev, |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 112 | struct e8390_pkt_hdr *hdr, int ring_page) |
| 113 | { |
| 114 | int nic_base = dev->base_addr; |
| 115 | int cnt; |
| 116 | short *ptrs; |
| 117 | |
| 118 | /* This *shouldn't* happen. |
| 119 | * If it does, it's the last thing you'll see |
| 120 | */ |
| 121 | if (ei_status.dmaing) { |
| 122 | netdev_err(dev, "%s: DMAing conflict [DMAstat:%d][irqlock:%d]\n", |
| 123 | __func__, ei_status.dmaing, ei_status.irqlock); |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | ei_status.dmaing |= 0x01; |
| 128 | z_writeb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD); |
| 129 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); |
| 130 | z_writeb(sizeof(struct e8390_pkt_hdr), nic_base + NE_EN0_RCNTLO); |
| 131 | z_writeb(0, nic_base + NE_EN0_RCNTHI); |
| 132 | z_writeb(0, nic_base + NE_EN0_RSARLO); /* On page boundary */ |
| 133 | z_writeb(ring_page, nic_base + NE_EN0_RSARHI); |
| 134 | z_writeb(E8390_RREAD+E8390_START, nic_base + NE_CMD); |
| 135 | |
| 136 | ptrs = (short *)hdr; |
| 137 | for (cnt = 0; cnt < sizeof(struct e8390_pkt_hdr) >> 1; cnt++) |
| 138 | *ptrs++ = z_readw(NE_BASE + NE_DATAPORT); |
| 139 | |
| 140 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr */ |
| 141 | |
| 142 | hdr->count = WORDSWAP(hdr->count); |
| 143 | |
| 144 | ei_status.dmaing &= ~0x01; |
| 145 | } |
| 146 | |
| 147 | /* Block input and output, similar to the Crynwr packet driver. |
| 148 | * If you are porting to a new ethercard, look at the packet driver source |
| 149 | * for hints. The NEx000 doesn't share the on-board packet memory -- |
| 150 | * you have to put the packet out through the "remote DMA" dataport |
| 151 | * using z_writeb. |
| 152 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | static void zorro8390_block_input(struct net_device *dev, int count, |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 154 | struct sk_buff *skb, int ring_offset) |
| 155 | { |
| 156 | int nic_base = dev->base_addr; |
| 157 | char *buf = skb->data; |
| 158 | short *ptrs; |
| 159 | int cnt; |
| 160 | |
| 161 | /* This *shouldn't* happen. |
| 162 | * If it does, it's the last thing you'll see |
| 163 | */ |
| 164 | if (ei_status.dmaing) { |
| 165 | netdev_err(dev, "%s: DMAing conflict [DMAstat:%d][irqlock:%d]\n", |
| 166 | __func__, ei_status.dmaing, ei_status.irqlock); |
| 167 | return; |
| 168 | } |
| 169 | ei_status.dmaing |= 0x01; |
| 170 | z_writeb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD); |
| 171 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); |
| 172 | z_writeb(count & 0xff, nic_base + NE_EN0_RCNTLO); |
| 173 | z_writeb(count >> 8, nic_base + NE_EN0_RCNTHI); |
| 174 | z_writeb(ring_offset & 0xff, nic_base + NE_EN0_RSARLO); |
| 175 | z_writeb(ring_offset >> 8, nic_base + NE_EN0_RSARHI); |
| 176 | z_writeb(E8390_RREAD+E8390_START, nic_base + NE_CMD); |
| 177 | ptrs = (short *)buf; |
| 178 | for (cnt = 0; cnt < count >> 1; cnt++) |
| 179 | *ptrs++ = z_readw(NE_BASE + NE_DATAPORT); |
| 180 | if (count & 0x01) |
| 181 | buf[count - 1] = z_readb(NE_BASE + NE_DATAPORT); |
| 182 | |
| 183 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr */ |
| 184 | ei_status.dmaing &= ~0x01; |
| 185 | } |
| 186 | |
| 187 | static void zorro8390_block_output(struct net_device *dev, int count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | const unsigned char *buf, |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 189 | const int start_page) |
| 190 | { |
| 191 | int nic_base = NE_BASE; |
| 192 | unsigned long dma_start; |
| 193 | short *ptrs; |
| 194 | int cnt; |
| 195 | |
| 196 | /* Round the count up for word writes. Do we need to do this? |
| 197 | * What effect will an odd byte count have on the 8390? |
| 198 | * I should check someday. |
| 199 | */ |
| 200 | if (count & 0x01) |
| 201 | count++; |
| 202 | |
| 203 | /* This *shouldn't* happen. |
| 204 | * If it does, it's the last thing you'll see |
| 205 | */ |
| 206 | if (ei_status.dmaing) { |
| 207 | netdev_err(dev, "%s: DMAing conflict [DMAstat:%d][irqlock:%d]\n", |
| 208 | __func__, ei_status.dmaing, ei_status.irqlock); |
| 209 | return; |
| 210 | } |
| 211 | ei_status.dmaing |= 0x01; |
| 212 | /* We should already be in page 0, but to be safe... */ |
| 213 | z_writeb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD); |
| 214 | |
| 215 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); |
| 216 | |
| 217 | /* Now the normal output. */ |
| 218 | z_writeb(count & 0xff, nic_base + NE_EN0_RCNTLO); |
| 219 | z_writeb(count >> 8, nic_base + NE_EN0_RCNTHI); |
| 220 | z_writeb(0x00, nic_base + NE_EN0_RSARLO); |
| 221 | z_writeb(start_page, nic_base + NE_EN0_RSARHI); |
| 222 | |
| 223 | z_writeb(E8390_RWRITE + E8390_START, nic_base + NE_CMD); |
| 224 | ptrs = (short *)buf; |
| 225 | for (cnt = 0; cnt < count >> 1; cnt++) |
| 226 | z_writew(*ptrs++, NE_BASE + NE_DATAPORT); |
| 227 | |
| 228 | dma_start = jiffies; |
| 229 | |
| 230 | while ((z_readb(NE_BASE + NE_EN0_ISR) & ENISR_RDC) == 0) |
| 231 | if (time_after(jiffies, dma_start + 2 * HZ / 100)) { |
| 232 | /* 20ms */ |
| 233 | netdev_err(dev, "timeout waiting for Tx RDC\n"); |
| 234 | zorro8390_reset_8390(dev); |
| 235 | __NS8390_init(dev, 1); |
| 236 | break; |
| 237 | } |
| 238 | |
| 239 | z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr */ |
| 240 | ei_status.dmaing &= ~0x01; |
| 241 | } |
| 242 | |
| 243 | static int zorro8390_open(struct net_device *dev) |
| 244 | { |
| 245 | __ei_open(dev); |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static int zorro8390_close(struct net_device *dev) |
| 250 | { |
| 251 | if (ei_debug > 1) |
| 252 | netdev_dbg(dev, "Shutting down ethercard\n"); |
| 253 | __ei_close(dev); |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static void __devexit zorro8390_remove_one(struct zorro_dev *z) |
| 258 | { |
| 259 | struct net_device *dev = zorro_get_drvdata(z); |
| 260 | |
| 261 | unregister_netdev(dev); |
| 262 | free_irq(IRQ_AMIGA_PORTS, dev); |
| 263 | release_mem_region(ZTWO_PADDR(dev->base_addr), NE_IO_EXTENT * 2); |
| 264 | free_netdev(dev); |
| 265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | static struct zorro_device_id zorro8390_zorro_tbl[] __devinitdata = { |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 268 | { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE2, }, |
| 269 | { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, }, |
| 270 | { 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | }; |
Geert Uytterhoeven | bf54a2b | 2008-11-18 21:13:53 +0100 | [diff] [blame] | 272 | MODULE_DEVICE_TABLE(zorro, zorro8390_zorro_tbl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Stephen Hemminger | b611479 | 2008-12-03 22:09:30 -0800 | [diff] [blame] | 274 | static const struct net_device_ops zorro8390_netdev_ops = { |
| 275 | .ndo_open = zorro8390_open, |
| 276 | .ndo_stop = zorro8390_close, |
Geert Uytterhoeven | cf7e032 | 2011-05-12 09:11:38 +0000 | [diff] [blame] | 277 | .ndo_start_xmit = __ei_start_xmit, |
| 278 | .ndo_tx_timeout = __ei_tx_timeout, |
| 279 | .ndo_get_stats = __ei_get_stats, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 280 | .ndo_set_rx_mode = __ei_set_multicast_list, |
Stephen Hemminger | b611479 | 2008-12-03 22:09:30 -0800 | [diff] [blame] | 281 | .ndo_validate_addr = eth_validate_addr, |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 282 | .ndo_set_mac_address = eth_mac_addr, |
Stephen Hemminger | b611479 | 2008-12-03 22:09:30 -0800 | [diff] [blame] | 283 | .ndo_change_mtu = eth_change_mtu, |
| 284 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Geert Uytterhoeven | cf7e032 | 2011-05-12 09:11:38 +0000 | [diff] [blame] | 285 | .ndo_poll_controller = __ei_poll, |
Stephen Hemminger | b611479 | 2008-12-03 22:09:30 -0800 | [diff] [blame] | 286 | #endif |
| 287 | }; |
| 288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | static int __devinit zorro8390_init(struct net_device *dev, |
| 290 | unsigned long board, const char *name, |
| 291 | unsigned long ioaddr) |
| 292 | { |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 293 | int i; |
| 294 | int err; |
| 295 | unsigned char SA_prom[32]; |
| 296 | int start_page, stop_page; |
| 297 | static u32 zorro8390_offsets[16] = { |
| 298 | 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, |
| 299 | 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 302 | /* Reset card. Who knows what dain-bramaged state it was left in. */ |
| 303 | { |
| 304 | unsigned long reset_start_time = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 306 | z_writeb(z_readb(ioaddr + NE_RESET), ioaddr + NE_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 308 | while ((z_readb(ioaddr + NE_EN0_ISR) & ENISR_RESET) == 0) |
| 309 | if (time_after(jiffies, |
| 310 | reset_start_time + 2 * HZ / 100)) { |
| 311 | netdev_warn(dev, "not found (no reset ack)\n"); |
| 312 | return -ENODEV; |
| 313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 315 | z_writeb(0xff, ioaddr + NE_EN0_ISR); /* Ack all intr. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 318 | /* Read the 16 bytes of station address PROM. |
| 319 | * We must first initialize registers, |
| 320 | * similar to NS8390_init(eifdev, 0). |
| 321 | * We can't reliably read the SAPROM address without this. |
| 322 | * (I learned the hard way!). |
| 323 | */ |
| 324 | { |
| 325 | static const struct { |
| 326 | u32 value; |
| 327 | u32 offset; |
| 328 | } program_seq[] = { |
| 329 | {E8390_NODMA + E8390_PAGE0 + E8390_STOP, NE_CMD}, |
| 330 | /* Select page 0 */ |
| 331 | {0x48, NE_EN0_DCFG}, /* 0x48: Set byte-wide access */ |
| 332 | {0x00, NE_EN0_RCNTLO}, /* Clear the count regs */ |
| 333 | {0x00, NE_EN0_RCNTHI}, |
| 334 | {0x00, NE_EN0_IMR}, /* Mask completion irq */ |
| 335 | {0xFF, NE_EN0_ISR}, |
| 336 | {E8390_RXOFF, NE_EN0_RXCR}, /* 0x20 Set to monitor */ |
| 337 | {E8390_TXOFF, NE_EN0_TXCR}, /* 0x02 and loopback mode */ |
| 338 | {32, NE_EN0_RCNTLO}, |
| 339 | {0x00, NE_EN0_RCNTHI}, |
| 340 | {0x00, NE_EN0_RSARLO}, /* DMA starting at 0x0000 */ |
| 341 | {0x00, NE_EN0_RSARHI}, |
| 342 | {E8390_RREAD + E8390_START, NE_CMD}, |
| 343 | }; |
| 344 | for (i = 0; i < ARRAY_SIZE(program_seq); i++) |
| 345 | z_writeb(program_seq[i].value, |
| 346 | ioaddr + program_seq[i].offset); |
| 347 | } |
| 348 | for (i = 0; i < 16; i++) { |
| 349 | SA_prom[i] = z_readb(ioaddr + NE_DATAPORT); |
| 350 | (void)z_readb(ioaddr + NE_DATAPORT); |
| 351 | } |
| 352 | |
| 353 | /* We must set the 8390 for word mode. */ |
| 354 | z_writeb(0x49, ioaddr + NE_EN0_DCFG); |
| 355 | start_page = NESM_START_PG; |
| 356 | stop_page = NESM_STOP_PG; |
| 357 | |
| 358 | dev->base_addr = ioaddr; |
| 359 | dev->irq = IRQ_AMIGA_PORTS; |
| 360 | |
| 361 | /* Install the Interrupt handler */ |
| 362 | i = request_irq(IRQ_AMIGA_PORTS, __ei_interrupt, |
| 363 | IRQF_SHARED, DRV_NAME, dev); |
| 364 | if (i) |
| 365 | return i; |
| 366 | |
Joe Perches | 104bf3f | 2011-11-16 09:38:03 +0000 | [diff] [blame] | 367 | for (i = 0; i < ETH_ALEN; i++) |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 368 | dev->dev_addr[i] = SA_prom[i]; |
| 369 | |
| 370 | pr_debug("Found ethernet address: %pM\n", dev->dev_addr); |
| 371 | |
| 372 | ei_status.name = name; |
| 373 | ei_status.tx_start_page = start_page; |
| 374 | ei_status.stop_page = stop_page; |
| 375 | ei_status.word16 = 1; |
| 376 | |
| 377 | ei_status.rx_start_page = start_page + TX_PAGES; |
| 378 | |
| 379 | ei_status.reset_8390 = zorro8390_reset_8390; |
| 380 | ei_status.block_input = zorro8390_block_input; |
| 381 | ei_status.block_output = zorro8390_block_output; |
| 382 | ei_status.get_8390_hdr = zorro8390_get_8390_hdr; |
| 383 | ei_status.reg_offset = zorro8390_offsets; |
| 384 | |
| 385 | dev->netdev_ops = &zorro8390_netdev_ops; |
| 386 | __NS8390_init(dev, 0); |
| 387 | err = register_netdev(dev); |
| 388 | if (err) { |
| 389 | free_irq(IRQ_AMIGA_PORTS, dev); |
| 390 | return err; |
| 391 | } |
| 392 | |
| 393 | netdev_info(dev, "%s at 0x%08lx, Ethernet Address %pM\n", |
| 394 | name, board, dev->dev_addr); |
| 395 | |
| 396 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 399 | static int __devinit zorro8390_init_one(struct zorro_dev *z, |
| 400 | const struct zorro_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 402 | struct net_device *dev; |
| 403 | unsigned long board, ioaddr; |
| 404 | int err, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 406 | for (i = ARRAY_SIZE(cards) - 1; i >= 0; i--) |
| 407 | if (z->id == cards[i].id) |
| 408 | break; |
| 409 | if (i < 0) |
| 410 | return -ENODEV; |
| 411 | |
| 412 | board = z->resource.start; |
| 413 | ioaddr = board + cards[i].offset; |
| 414 | dev = ____alloc_ei_netdev(0); |
| 415 | if (!dev) |
| 416 | return -ENOMEM; |
| 417 | if (!request_mem_region(ioaddr, NE_IO_EXTENT * 2, DRV_NAME)) { |
| 418 | free_netdev(dev); |
| 419 | return -EBUSY; |
| 420 | } |
| 421 | err = zorro8390_init(dev, board, cards[i].name, ZTWO_VADDR(ioaddr)); |
| 422 | if (err) { |
| 423 | release_mem_region(ioaddr, NE_IO_EXTENT * 2); |
| 424 | free_netdev(dev); |
| 425 | return err; |
| 426 | } |
| 427 | zorro_set_drvdata(z, dev); |
| 428 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 431 | static struct zorro_driver zorro8390_driver = { |
| 432 | .name = "zorro8390", |
| 433 | .id_table = zorro8390_zorro_tbl, |
| 434 | .probe = zorro8390_init_one, |
| 435 | .remove = __devexit_p(zorro8390_remove_one), |
| 436 | }; |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | static int __init zorro8390_init_module(void) |
| 439 | { |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 440 | return zorro_register_driver(&zorro8390_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | static void __exit zorro8390_cleanup_module(void) |
| 444 | { |
Joe Perches | 572404e | 2011-06-22 20:39:00 +0000 | [diff] [blame] | 445 | zorro_unregister_driver(&zorro8390_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | module_init(zorro8390_init_module); |
| 449 | module_exit(zorro8390_cleanup_module); |
| 450 | |
| 451 | MODULE_LICENSE("GPL"); |