Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Amiga Linux/68k 8390 based PCMCIA Ethernet Driver for the Amiga 1200 |
| 3 | * |
| 4 | * (C) Copyright 1997 Alain Malek |
| 5 | * (Alain.Malek@cryogen.com) |
| 6 | * |
| 7 | * ---------------------------------------------------------------------------- |
| 8 | * |
| 9 | * This program is based on |
| 10 | * |
| 11 | * ne.c: A general non-shared-memory NS8390 ethernet driver for linux |
| 12 | * Written 1992-94 by Donald Becker. |
| 13 | * |
| 14 | * 8390.c: A general NS8390 ethernet driver core for linux. |
| 15 | * Written 1992-94 by Donald Becker. |
| 16 | * |
| 17 | * cnetdevice: A Sana-II ethernet driver for AmigaOS |
| 18 | * Written by Bruce Abbott (bhabbott@inhb.co.nz) |
| 19 | * |
| 20 | * ---------------------------------------------------------------------------- |
| 21 | * |
| 22 | * This file is subject to the terms and conditions of the GNU General Public |
| 23 | * License. See the file COPYING in the main directory of the Linux |
| 24 | * distribution for more details. |
| 25 | * |
| 26 | * ---------------------------------------------------------------------------- |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/errno.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/netdevice.h> |
| 38 | #include <linux/etherdevice.h> |
Geert Uytterhoeven | ac75227 | 2011-06-11 14:58:17 -0700 | [diff] [blame] | 39 | #include <linux/interrupt.h> |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 40 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/io.h> |
| 43 | #include <asm/setup.h> |
| 44 | #include <asm/amigaints.h> |
| 45 | #include <asm/amigahw.h> |
| 46 | #include <asm/amigayle.h> |
| 47 | #include <asm/amipcmcia.h> |
| 48 | |
| 49 | #include "8390.h" |
| 50 | |
| 51 | /* ---- No user-serviceable parts below ---- */ |
| 52 | |
| 53 | #define DRV_NAME "apne" |
| 54 | |
| 55 | #define NE_BASE (dev->base_addr) |
| 56 | #define NE_CMD 0x00 |
| 57 | #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */ |
| 58 | #define NE_RESET 0x1f /* Issue a read to reset, a write to clear. */ |
| 59 | #define NE_IO_EXTENT 0x20 |
| 60 | |
| 61 | #define NE_EN0_ISR 0x07 |
| 62 | #define NE_EN0_DCFG 0x0e |
| 63 | |
| 64 | #define NE_EN0_RSARLO 0x08 |
| 65 | #define NE_EN0_RSARHI 0x09 |
| 66 | #define NE_EN0_RCNTLO 0x0a |
| 67 | #define NE_EN0_RXCR 0x0c |
| 68 | #define NE_EN0_TXCR 0x0d |
| 69 | #define NE_EN0_RCNTHI 0x0b |
| 70 | #define NE_EN0_IMR 0x0f |
| 71 | |
| 72 | #define NE1SM_START_PG 0x20 /* First page of TX buffer */ |
| 73 | #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */ |
| 74 | #define NESM_START_PG 0x40 /* First page of TX buffer */ |
| 75 | #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */ |
| 76 | |
| 77 | |
| 78 | struct net_device * __init apne_probe(int unit); |
| 79 | static int apne_probe1(struct net_device *dev, int ioaddr); |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | static void apne_reset_8390(struct net_device *dev); |
| 82 | static void apne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, |
| 83 | int ring_page); |
| 84 | static void apne_block_input(struct net_device *dev, int count, |
| 85 | struct sk_buff *skb, int ring_offset); |
| 86 | static void apne_block_output(struct net_device *dev, const int count, |
| 87 | const unsigned char *buf, const int start_page); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 88 | static irqreturn_t apne_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | static int init_pcmcia(void); |
| 91 | |
| 92 | /* IO base address used for nic */ |
| 93 | |
| 94 | #define IOBASE 0x300 |
| 95 | |
| 96 | /* |
| 97 | use MANUAL_CONFIG and MANUAL_OFFSET for enabling IO by hand |
| 98 | you can find the values to use by looking at the cnet.device |
| 99 | config file example (the default values are for the CNET40BC card) |
| 100 | */ |
| 101 | |
| 102 | /* |
| 103 | #define MANUAL_CONFIG 0x20 |
| 104 | #define MANUAL_OFFSET 0x3f8 |
| 105 | |
| 106 | #define MANUAL_HWADDR0 0x00 |
| 107 | #define MANUAL_HWADDR1 0x12 |
| 108 | #define MANUAL_HWADDR2 0x34 |
| 109 | #define MANUAL_HWADDR3 0x56 |
| 110 | #define MANUAL_HWADDR4 0x78 |
| 111 | #define MANUAL_HWADDR5 0x9a |
| 112 | */ |
| 113 | |
| 114 | static const char version[] = |
| 115 | "apne.c:v1.1 7/10/98 Alain Malek (Alain.Malek@cryogen.ch)\n"; |
| 116 | |
| 117 | static int apne_owned; /* signal if card already owned */ |
| 118 | |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 119 | static u32 apne_msg_enable; |
| 120 | module_param_named(msg_enable, apne_msg_enable, uint, (S_IRUSR|S_IRGRP|S_IROTH)); |
| 121 | MODULE_PARM_DESC(msg_enable, "Debug message level (see linux/netdevice.h for bitmap)"); |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | struct net_device * __init apne_probe(int unit) |
| 124 | { |
| 125 | struct net_device *dev; |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 126 | struct ei_device *ei_local; |
| 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | #ifndef MANUAL_CONFIG |
| 129 | char tuple[8]; |
| 130 | #endif |
| 131 | int err; |
| 132 | |
Geert Uytterhoeven | 0f73448 | 2008-05-18 20:47:16 +0200 | [diff] [blame] | 133 | if (!MACH_IS_AMIGA) |
| 134 | return ERR_PTR(-ENODEV); |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | if (apne_owned) |
| 137 | return ERR_PTR(-ENODEV); |
| 138 | |
| 139 | if ( !(AMIGAHW_PRESENT(PCMCIA)) ) |
| 140 | return ERR_PTR(-ENODEV); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 141 | |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 142 | pr_info("Looking for PCMCIA ethernet card : "); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* check if a card is inserted */ |
| 145 | if (!(PCMCIA_INSERTED)) { |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 146 | pr_cont("NO PCMCIA card inserted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | return ERR_PTR(-ENODEV); |
| 148 | } |
| 149 | |
| 150 | dev = alloc_ei_netdev(); |
| 151 | if (!dev) |
| 152 | return ERR_PTR(-ENOMEM); |
| 153 | if (unit >= 0) { |
| 154 | sprintf(dev->name, "eth%d", unit); |
| 155 | netdev_boot_setup_check(dev); |
| 156 | } |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 157 | ei_local = netdev_priv(dev); |
| 158 | ei_local->msg_enable = apne_msg_enable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | /* disable pcmcia irq for readtuple */ |
| 161 | pcmcia_disable_irq(); |
| 162 | |
| 163 | #ifndef MANUAL_CONFIG |
| 164 | if ((pcmcia_copy_tuple(CISTPL_FUNCID, tuple, 8) < 3) || |
| 165 | (tuple[2] != CISTPL_FUNCID_NETWORK)) { |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 166 | pr_cont("not an ethernet card\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* XXX: shouldn't we re-enable irq here? */ |
| 168 | free_netdev(dev); |
| 169 | return ERR_PTR(-ENODEV); |
| 170 | } |
| 171 | #endif |
| 172 | |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 173 | pr_cont("ethernet PCMCIA card inserted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | if (!init_pcmcia()) { |
| 176 | /* XXX: shouldn't we re-enable irq here? */ |
| 177 | free_netdev(dev); |
| 178 | return ERR_PTR(-ENODEV); |
| 179 | } |
| 180 | |
| 181 | if (!request_region(IOBASE, 0x20, DRV_NAME)) { |
| 182 | free_netdev(dev); |
| 183 | return ERR_PTR(-EBUSY); |
| 184 | } |
| 185 | |
| 186 | err = apne_probe1(dev, IOBASE); |
| 187 | if (err) { |
| 188 | release_region(IOBASE, 0x20); |
| 189 | free_netdev(dev); |
| 190 | return ERR_PTR(err); |
| 191 | } |
| 192 | err = register_netdev(dev); |
| 193 | if (!err) |
| 194 | return dev; |
| 195 | |
| 196 | pcmcia_disable_irq(); |
| 197 | free_irq(IRQ_AMIGA_PORTS, dev); |
| 198 | pcmcia_reset(); |
| 199 | release_region(IOBASE, 0x20); |
| 200 | free_netdev(dev); |
| 201 | return ERR_PTR(err); |
| 202 | } |
| 203 | |
| 204 | static int __init apne_probe1(struct net_device *dev, int ioaddr) |
| 205 | { |
| 206 | int i; |
| 207 | unsigned char SA_prom[32]; |
| 208 | int wordlength = 2; |
| 209 | const char *name = NULL; |
| 210 | int start_page, stop_page; |
| 211 | #ifndef MANUAL_HWADDR0 |
| 212 | int neX000, ctron; |
| 213 | #endif |
| 214 | static unsigned version_printed; |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 215 | struct ei_device *ei_local = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 216 | |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 217 | if ((apne_msg_enable & NETIF_MSG_DRV) && (version_printed++ == 0)) |
| 218 | netdev_info(dev, version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 220 | netdev_info(dev, "PCMCIA NE*000 ethercard probe"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | /* Reset card. Who knows what dain-bramaged state it was left in. */ |
| 223 | { unsigned long reset_start_time = jiffies; |
| 224 | |
| 225 | outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET); |
| 226 | |
| 227 | while ((inb(ioaddr + NE_EN0_ISR) & ENISR_RESET) == 0) |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 228 | if (time_after(jiffies, reset_start_time + 2*HZ/100)) { |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 229 | pr_cont(" not found (no reset ack).\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return -ENODEV; |
| 231 | } |
| 232 | |
| 233 | outb(0xff, ioaddr + NE_EN0_ISR); /* Ack all intr. */ |
| 234 | } |
| 235 | |
| 236 | #ifndef MANUAL_HWADDR0 |
| 237 | |
| 238 | /* Read the 16 bytes of station address PROM. |
| 239 | We must first initialize registers, similar to NS8390_init(eifdev, 0). |
| 240 | We can't reliably read the SAPROM address without this. |
| 241 | (I learned the hard way!). */ |
| 242 | { |
| 243 | struct {unsigned long value, offset; } program_seq[] = { |
| 244 | {E8390_NODMA+E8390_PAGE0+E8390_STOP, NE_CMD}, /* Select page 0*/ |
| 245 | {0x48, NE_EN0_DCFG}, /* Set byte-wide (0x48) access. */ |
| 246 | {0x00, NE_EN0_RCNTLO}, /* Clear the count regs. */ |
| 247 | {0x00, NE_EN0_RCNTHI}, |
| 248 | {0x00, NE_EN0_IMR}, /* Mask completion irq. */ |
| 249 | {0xFF, NE_EN0_ISR}, |
| 250 | {E8390_RXOFF, NE_EN0_RXCR}, /* 0x20 Set to monitor */ |
| 251 | {E8390_TXOFF, NE_EN0_TXCR}, /* 0x02 and loopback mode. */ |
| 252 | {32, NE_EN0_RCNTLO}, |
| 253 | {0x00, NE_EN0_RCNTHI}, |
| 254 | {0x00, NE_EN0_RSARLO}, /* DMA starting at 0x0000. */ |
| 255 | {0x00, NE_EN0_RSARHI}, |
| 256 | {E8390_RREAD+E8390_START, NE_CMD}, |
| 257 | }; |
Denis Cheng | ff8ac60 | 2007-09-02 18:30:18 +0800 | [diff] [blame] | 258 | for (i = 0; i < ARRAY_SIZE(program_seq); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | outb(program_seq[i].value, ioaddr + program_seq[i].offset); |
| 260 | } |
| 261 | |
| 262 | } |
| 263 | for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) { |
| 264 | SA_prom[i] = inb(ioaddr + NE_DATAPORT); |
| 265 | SA_prom[i+1] = inb(ioaddr + NE_DATAPORT); |
| 266 | if (SA_prom[i] != SA_prom[i+1]) |
| 267 | wordlength = 1; |
| 268 | } |
| 269 | |
| 270 | /* At this point, wordlength *only* tells us if the SA_prom is doubled |
| 271 | up or not because some broken PCI cards don't respect the byte-wide |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 272 | request in program_seq above, and hence don't have doubled up values. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | These broken cards would otherwise be detected as an ne1000. */ |
| 274 | |
| 275 | if (wordlength == 2) |
| 276 | for (i = 0; i < 16; i++) |
| 277 | SA_prom[i] = SA_prom[i+i]; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | if (wordlength == 2) { |
| 280 | /* We must set the 8390 for word mode. */ |
| 281 | outb(0x49, ioaddr + NE_EN0_DCFG); |
| 282 | start_page = NESM_START_PG; |
| 283 | stop_page = NESM_STOP_PG; |
| 284 | } else { |
| 285 | start_page = NE1SM_START_PG; |
| 286 | stop_page = NE1SM_STOP_PG; |
| 287 | } |
| 288 | |
| 289 | neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57); |
| 290 | ctron = (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d); |
| 291 | |
| 292 | /* Set up the rest of the parameters. */ |
| 293 | if (neX000) { |
| 294 | name = (wordlength == 2) ? "NE2000" : "NE1000"; |
| 295 | } else if (ctron) { |
| 296 | name = (wordlength == 2) ? "Ctron-8" : "Ctron-16"; |
| 297 | start_page = 0x01; |
| 298 | stop_page = (wordlength == 2) ? 0x40 : 0x20; |
| 299 | } else { |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 300 | pr_cont(" not found.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | return -ENXIO; |
| 302 | |
| 303 | } |
| 304 | |
| 305 | #else |
| 306 | wordlength = 2; |
| 307 | /* We must set the 8390 for word mode. */ |
| 308 | outb(0x49, ioaddr + NE_EN0_DCFG); |
| 309 | start_page = NESM_START_PG; |
| 310 | stop_page = NESM_STOP_PG; |
| 311 | |
| 312 | SA_prom[0] = MANUAL_HWADDR0; |
| 313 | SA_prom[1] = MANUAL_HWADDR1; |
| 314 | SA_prom[2] = MANUAL_HWADDR2; |
| 315 | SA_prom[3] = MANUAL_HWADDR3; |
| 316 | SA_prom[4] = MANUAL_HWADDR4; |
| 317 | SA_prom[5] = MANUAL_HWADDR5; |
| 318 | name = "NE2000"; |
| 319 | #endif |
| 320 | |
| 321 | dev->base_addr = ioaddr; |
Kars de Jong | d8a53b3 | 2006-12-09 10:51:03 +0100 | [diff] [blame] | 322 | dev->irq = IRQ_AMIGA_PORTS; |
Stephen Hemminger | 7d359da | 2008-11-25 18:25:32 -0800 | [diff] [blame] | 323 | dev->netdev_ops = &ei_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | /* Install the Interrupt handler */ |
Kars de Jong | d8a53b3 | 2006-12-09 10:51:03 +0100 | [diff] [blame] | 326 | i = request_irq(dev->irq, apne_interrupt, IRQF_SHARED, DRV_NAME, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | if (i) return i; |
| 328 | |
Joe Perches | 104bf3f | 2011-11-16 09:38:03 +0000 | [diff] [blame] | 329 | for (i = 0; i < ETH_ALEN; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | dev->dev_addr[i] = SA_prom[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 332 | pr_cont(" %pM\n", dev->dev_addr); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 333 | |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 334 | netdev_info(dev, "%s found.\n", name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | ei_status.name = name; |
| 337 | ei_status.tx_start_page = start_page; |
| 338 | ei_status.stop_page = stop_page; |
| 339 | ei_status.word16 = (wordlength == 2); |
| 340 | |
| 341 | ei_status.rx_start_page = start_page + TX_PAGES; |
| 342 | |
| 343 | ei_status.reset_8390 = &apne_reset_8390; |
| 344 | ei_status.block_input = &apne_block_input; |
| 345 | ei_status.block_output = &apne_block_output; |
| 346 | ei_status.get_8390_hdr = &apne_get_8390_hdr; |
Stephen Hemminger | 7d359da | 2008-11-25 18:25:32 -0800 | [diff] [blame] | 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | NS8390_init(dev, 0); |
| 349 | |
| 350 | pcmcia_ack_int(pcmcia_get_intreq()); /* ack PCMCIA int req */ |
| 351 | pcmcia_enable_irq(); |
| 352 | |
| 353 | apne_owned = 1; |
| 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | /* Hard reset the card. This used to pause for the same period that a |
| 359 | 8390 reset command required, but that shouldn't be necessary. */ |
| 360 | static void |
| 361 | apne_reset_8390(struct net_device *dev) |
| 362 | { |
| 363 | unsigned long reset_start_time = jiffies; |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 364 | struct ei_device *ei_local = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | init_pcmcia(); |
| 367 | |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 368 | netif_dbg(ei_local, hw, dev, "resetting the 8390 t=%ld...\n", jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET); |
| 371 | |
| 372 | ei_status.txing = 0; |
| 373 | ei_status.dmaing = 0; |
| 374 | |
| 375 | /* This check _should_not_ be necessary, omit eventually. */ |
| 376 | while ((inb(NE_BASE+NE_EN0_ISR) & ENISR_RESET) == 0) |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 377 | if (time_after(jiffies, reset_start_time + 2*HZ/100)) { |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 378 | netdev_err(dev, "ne_reset_8390() did not complete.\n"); |
| 379 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | outb(ENISR_RESET, NE_BASE + NE_EN0_ISR); /* Ack intr. */ |
| 382 | } |
| 383 | |
| 384 | /* Grab the 8390 specific header. Similar to the block_input routine, but |
| 385 | we don't need to be concerned with ring wrap as the header will be at |
| 386 | the start of a page, so we optimize accordingly. */ |
| 387 | |
| 388 | static void |
| 389 | apne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) |
| 390 | { |
| 391 | |
| 392 | int nic_base = dev->base_addr; |
| 393 | int cnt; |
| 394 | char *ptrc; |
| 395 | short *ptrs; |
| 396 | |
| 397 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ |
| 398 | if (ei_status.dmaing) { |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 399 | netdev_err(dev, "DMAing conflict in ne_get_8390_hdr " |
| 400 | "[DMAstat:%d][irqlock:%d][intr:%d].\n", |
| 401 | ei_status.dmaing, ei_status.irqlock, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | |
| 405 | ei_status.dmaing |= 0x01; |
| 406 | outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); |
| 407 | outb(ENISR_RDC, nic_base + NE_EN0_ISR); |
| 408 | outb(sizeof(struct e8390_pkt_hdr), nic_base + NE_EN0_RCNTLO); |
| 409 | outb(0, nic_base + NE_EN0_RCNTHI); |
| 410 | outb(0, nic_base + NE_EN0_RSARLO); /* On page boundary */ |
| 411 | outb(ring_page, nic_base + NE_EN0_RSARHI); |
| 412 | outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); |
| 413 | |
| 414 | if (ei_status.word16) { |
| 415 | ptrs = (short*)hdr; |
| 416 | for(cnt = 0; cnt < (sizeof(struct e8390_pkt_hdr)>>1); cnt++) |
| 417 | *ptrs++ = inw(NE_BASE + NE_DATAPORT); |
| 418 | } else { |
| 419 | ptrc = (char*)hdr; |
| 420 | for(cnt = 0; cnt < sizeof(struct e8390_pkt_hdr); cnt++) |
| 421 | *ptrc++ = inb(NE_BASE + NE_DATAPORT); |
| 422 | } |
| 423 | |
| 424 | outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */ |
| 425 | ei_status.dmaing &= ~0x01; |
| 426 | |
| 427 | le16_to_cpus(&hdr->count); |
| 428 | } |
| 429 | |
| 430 | /* Block input and output, similar to the Crynwr packet driver. If you |
| 431 | are porting to a new ethercard, look at the packet driver source for hints. |
| 432 | The NEx000 doesn't share the on-board packet memory -- you have to put |
| 433 | the packet out through the "remote DMA" dataport using outb. */ |
| 434 | |
| 435 | static void |
| 436 | apne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset) |
| 437 | { |
| 438 | int nic_base = dev->base_addr; |
| 439 | char *buf = skb->data; |
| 440 | char *ptrc; |
| 441 | short *ptrs; |
| 442 | int cnt; |
| 443 | |
| 444 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ |
| 445 | if (ei_status.dmaing) { |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 446 | netdev_err(dev, "DMAing conflict in ne_block_input " |
| 447 | "[DMAstat:%d][irqlock:%d][intr:%d].\n", |
| 448 | ei_status.dmaing, ei_status.irqlock, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | return; |
| 450 | } |
| 451 | ei_status.dmaing |= 0x01; |
| 452 | outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); |
| 453 | outb(ENISR_RDC, nic_base + NE_EN0_ISR); |
| 454 | outb(count & 0xff, nic_base + NE_EN0_RCNTLO); |
| 455 | outb(count >> 8, nic_base + NE_EN0_RCNTHI); |
| 456 | outb(ring_offset & 0xff, nic_base + NE_EN0_RSARLO); |
| 457 | outb(ring_offset >> 8, nic_base + NE_EN0_RSARHI); |
| 458 | outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); |
| 459 | if (ei_status.word16) { |
| 460 | ptrs = (short*)buf; |
| 461 | for (cnt = 0; cnt < (count>>1); cnt++) |
| 462 | *ptrs++ = inw(NE_BASE + NE_DATAPORT); |
| 463 | if (count & 0x01) { |
| 464 | buf[count-1] = inb(NE_BASE + NE_DATAPORT); |
| 465 | } |
| 466 | } else { |
Joe Perches | 6469933 | 2012-06-04 12:44:16 +0000 | [diff] [blame] | 467 | ptrc = buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | for (cnt = 0; cnt < count; cnt++) |
| 469 | *ptrc++ = inb(NE_BASE + NE_DATAPORT); |
| 470 | } |
| 471 | |
| 472 | outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */ |
| 473 | ei_status.dmaing &= ~0x01; |
| 474 | } |
| 475 | |
| 476 | static void |
| 477 | apne_block_output(struct net_device *dev, int count, |
| 478 | const unsigned char *buf, const int start_page) |
| 479 | { |
| 480 | int nic_base = NE_BASE; |
| 481 | unsigned long dma_start; |
| 482 | char *ptrc; |
| 483 | short *ptrs; |
| 484 | int cnt; |
| 485 | |
| 486 | /* Round the count up for word writes. Do we need to do this? |
| 487 | What effect will an odd byte count have on the 8390? |
| 488 | I should check someday. */ |
| 489 | if (ei_status.word16 && (count & 0x01)) |
| 490 | count++; |
| 491 | |
| 492 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ |
| 493 | if (ei_status.dmaing) { |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 494 | netdev_err(dev, "DMAing conflict in ne_block_output." |
| 495 | "[DMAstat:%d][irqlock:%d][intr:%d]\n", |
| 496 | ei_status.dmaing, ei_status.irqlock, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | ei_status.dmaing |= 0x01; |
| 500 | /* We should already be in page 0, but to be safe... */ |
| 501 | outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD); |
| 502 | |
| 503 | outb(ENISR_RDC, nic_base + NE_EN0_ISR); |
| 504 | |
| 505 | /* Now the normal output. */ |
| 506 | outb(count & 0xff, nic_base + NE_EN0_RCNTLO); |
| 507 | outb(count >> 8, nic_base + NE_EN0_RCNTHI); |
| 508 | outb(0x00, nic_base + NE_EN0_RSARLO); |
| 509 | outb(start_page, nic_base + NE_EN0_RSARHI); |
| 510 | |
| 511 | outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD); |
| 512 | if (ei_status.word16) { |
| 513 | ptrs = (short*)buf; |
| 514 | for (cnt = 0; cnt < count>>1; cnt++) |
| 515 | outw(*ptrs++, NE_BASE+NE_DATAPORT); |
| 516 | } else { |
| 517 | ptrc = (char*)buf; |
| 518 | for (cnt = 0; cnt < count; cnt++) |
| 519 | outb(*ptrc++, NE_BASE + NE_DATAPORT); |
| 520 | } |
| 521 | |
| 522 | dma_start = jiffies; |
| 523 | |
| 524 | while ((inb(NE_BASE + NE_EN0_ISR) & ENISR_RDC) == 0) |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 525 | if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */ |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 526 | netdev_warn(dev, "timeout waiting for Tx RDC.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | apne_reset_8390(dev); |
| 528 | NS8390_init(dev,1); |
| 529 | break; |
| 530 | } |
| 531 | |
| 532 | outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */ |
| 533 | ei_status.dmaing &= ~0x01; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 536 | static irqreturn_t apne_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | { |
| 538 | unsigned char pcmcia_intreq; |
| 539 | |
| 540 | if (!(gayle.inten & GAYLE_IRQ_IRQ)) |
| 541 | return IRQ_NONE; |
| 542 | |
| 543 | pcmcia_intreq = pcmcia_get_intreq(); |
| 544 | |
| 545 | if (!(pcmcia_intreq & GAYLE_IRQ_IRQ)) { |
| 546 | pcmcia_ack_int(pcmcia_intreq); |
| 547 | return IRQ_NONE; |
| 548 | } |
Matthew Whitehead | c45f812 | 2013-12-11 17:00:59 -0500 | [diff] [blame^] | 549 | if (apne_msg_enable & NETIF_MSG_INTR) |
| 550 | pr_debug("pcmcia intreq = %x\n", pcmcia_intreq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | pcmcia_disable_irq(); /* to get rid of the sti() within ei_interrupt */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 552 | ei_interrupt(irq, dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | pcmcia_ack_int(pcmcia_get_intreq()); |
| 554 | pcmcia_enable_irq(); |
| 555 | return IRQ_HANDLED; |
| 556 | } |
| 557 | |
| 558 | #ifdef MODULE |
| 559 | static struct net_device *apne_dev; |
| 560 | |
Jon Schindler | 3cfbb67 | 2008-03-05 18:50:16 -0800 | [diff] [blame] | 561 | static int __init apne_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | { |
| 563 | apne_dev = apne_probe(-1); |
| 564 | if (IS_ERR(apne_dev)) |
| 565 | return PTR_ERR(apne_dev); |
| 566 | return 0; |
| 567 | } |
| 568 | |
Jon Schindler | 3cfbb67 | 2008-03-05 18:50:16 -0800 | [diff] [blame] | 569 | static void __exit apne_module_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
| 571 | unregister_netdev(apne_dev); |
| 572 | |
| 573 | pcmcia_disable_irq(); |
| 574 | |
| 575 | free_irq(IRQ_AMIGA_PORTS, apne_dev); |
| 576 | |
| 577 | pcmcia_reset(); |
| 578 | |
| 579 | release_region(IOBASE, 0x20); |
| 580 | |
| 581 | free_netdev(apne_dev); |
| 582 | } |
Jon Schindler | 3cfbb67 | 2008-03-05 18:50:16 -0800 | [diff] [blame] | 583 | module_init(apne_module_init); |
| 584 | module_exit(apne_module_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | #endif |
| 586 | |
| 587 | static int init_pcmcia(void) |
| 588 | { |
| 589 | u_char config; |
| 590 | #ifndef MANUAL_CONFIG |
| 591 | u_char tuple[32]; |
| 592 | int offset_len; |
| 593 | #endif |
| 594 | u_long offset; |
| 595 | |
| 596 | pcmcia_reset(); |
| 597 | pcmcia_program_voltage(PCMCIA_0V); |
| 598 | pcmcia_access_speed(PCMCIA_SPEED_250NS); |
| 599 | pcmcia_write_enable(); |
| 600 | |
| 601 | #ifdef MANUAL_CONFIG |
| 602 | config = MANUAL_CONFIG; |
| 603 | #else |
| 604 | /* get and write config byte to enable IO port */ |
| 605 | |
| 606 | if (pcmcia_copy_tuple(CISTPL_CFTABLE_ENTRY, tuple, 32) < 3) |
| 607 | return 0; |
| 608 | |
| 609 | config = tuple[2] & 0x3f; |
| 610 | #endif |
| 611 | #ifdef MANUAL_OFFSET |
| 612 | offset = MANUAL_OFFSET; |
| 613 | #else |
| 614 | if (pcmcia_copy_tuple(CISTPL_CONFIG, tuple, 32) < 6) |
| 615 | return 0; |
| 616 | |
| 617 | offset_len = (tuple[2] & 0x3) + 1; |
| 618 | offset = 0; |
| 619 | while(offset_len--) { |
| 620 | offset = (offset << 8) | tuple[4+offset_len]; |
| 621 | } |
| 622 | #endif |
| 623 | |
| 624 | out_8(GAYLE_ATTRIBUTE+offset, config); |
| 625 | |
| 626 | return 1; |
| 627 | } |
| 628 | |
| 629 | MODULE_LICENSE("GPL"); |