apne.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/errno.h>
  32. #include <linux/pci.h>
  33. #include <linux/init.h>
  34. #include <linux/delay.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/etherdevice.h>
  37. #include <linux/jiffies.h>
  38. #include <asm/system.h>
  39. #include <asm/io.h>
  40. #include <asm/setup.h>
  41. #include <asm/amigaints.h>
  42. #include <asm/amigahw.h>
  43. #include <asm/amigayle.h>
  44. #include <asm/amipcmcia.h>
  45. #include "8390.h"
  46. /* ---- No user-serviceable parts below ---- */
  47. #define DRV_NAME "apne"
  48. #define NE_BASE (dev->base_addr)
  49. #define NE_CMD 0x00
  50. #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */
  51. #define NE_RESET 0x1f /* Issue a read to reset, a write to clear. */
  52. #define NE_IO_EXTENT 0x20
  53. #define NE_EN0_ISR 0x07
  54. #define NE_EN0_DCFG 0x0e
  55. #define NE_EN0_RSARLO 0x08
  56. #define NE_EN0_RSARHI 0x09
  57. #define NE_EN0_RCNTLO 0x0a
  58. #define NE_EN0_RXCR 0x0c
  59. #define NE_EN0_TXCR 0x0d
  60. #define NE_EN0_RCNTHI 0x0b
  61. #define NE_EN0_IMR 0x0f
  62. #define NE1SM_START_PG 0x20 /* First page of TX buffer */
  63. #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
  64. #define NESM_START_PG 0x40 /* First page of TX buffer */
  65. #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
  66. struct net_device * __init apne_probe(int unit);
  67. static int apne_probe1(struct net_device *dev, int ioaddr);
  68. static int apne_open(struct net_device *dev);
  69. static int apne_close(struct net_device *dev);
  70. static void apne_reset_8390(struct net_device *dev);
  71. static void apne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  72. int ring_page);
  73. static void apne_block_input(struct net_device *dev, int count,
  74. struct sk_buff *skb, int ring_offset);
  75. static void apne_block_output(struct net_device *dev, const int count,
  76. const unsigned char *buf, const int start_page);
  77. static irqreturn_t apne_interrupt(int irq, void *dev_id);
  78. static int init_pcmcia(void);
  79. /* IO base address used for nic */
  80. #define IOBASE 0x300
  81. /*
  82. use MANUAL_CONFIG and MANUAL_OFFSET for enabling IO by hand
  83. you can find the values to use by looking at the cnet.device
  84. config file example (the default values are for the CNET40BC card)
  85. */
  86. /*
  87. #define MANUAL_CONFIG 0x20
  88. #define MANUAL_OFFSET 0x3f8
  89. #define MANUAL_HWADDR0 0x00
  90. #define MANUAL_HWADDR1 0x12
  91. #define MANUAL_HWADDR2 0x34
  92. #define MANUAL_HWADDR3 0x56
  93. #define MANUAL_HWADDR4 0x78
  94. #define MANUAL_HWADDR5 0x9a
  95. */
  96. static const char version[] =
  97. "apne.c:v1.1 7/10/98 Alain Malek (Alain.Malek@cryogen.ch)\n";
  98. static int apne_owned; /* signal if card already owned */
  99. struct net_device * __init apne_probe(int unit)
  100. {
  101. struct net_device *dev;
  102. #ifndef MANUAL_CONFIG
  103. char tuple[8];
  104. #endif
  105. int err;
  106. if (apne_owned)
  107. return ERR_PTR(-ENODEV);
  108. if ( !(AMIGAHW_PRESENT(PCMCIA)) )
  109. return ERR_PTR(-ENODEV);
  110. printk("Looking for PCMCIA ethernet card : ");
  111. /* check if a card is inserted */
  112. if (!(PCMCIA_INSERTED)) {
  113. printk("NO PCMCIA card inserted\n");
  114. return ERR_PTR(-ENODEV);
  115. }
  116. dev = alloc_ei_netdev();
  117. if (!dev)
  118. return ERR_PTR(-ENOMEM);
  119. if (unit >= 0) {
  120. sprintf(dev->name, "eth%d", unit);
  121. netdev_boot_setup_check(dev);
  122. }
  123. SET_MODULE_OWNER(dev);
  124. /* disable pcmcia irq for readtuple */
  125. pcmcia_disable_irq();
  126. #ifndef MANUAL_CONFIG
  127. if ((pcmcia_copy_tuple(CISTPL_FUNCID, tuple, 8) < 3) ||
  128. (tuple[2] != CISTPL_FUNCID_NETWORK)) {
  129. printk("not an ethernet card\n");
  130. /* XXX: shouldn't we re-enable irq here? */
  131. free_netdev(dev);
  132. return ERR_PTR(-ENODEV);
  133. }
  134. #endif
  135. printk("ethernet PCMCIA card inserted\n");
  136. if (!init_pcmcia()) {
  137. /* XXX: shouldn't we re-enable irq here? */
  138. free_netdev(dev);
  139. return ERR_PTR(-ENODEV);
  140. }
  141. if (!request_region(IOBASE, 0x20, DRV_NAME)) {
  142. free_netdev(dev);
  143. return ERR_PTR(-EBUSY);
  144. }
  145. err = apne_probe1(dev, IOBASE);
  146. if (err) {
  147. release_region(IOBASE, 0x20);
  148. free_netdev(dev);
  149. return ERR_PTR(err);
  150. }
  151. err = register_netdev(dev);
  152. if (!err)
  153. return dev;
  154. pcmcia_disable_irq();
  155. free_irq(IRQ_AMIGA_PORTS, dev);
  156. pcmcia_reset();
  157. release_region(IOBASE, 0x20);
  158. free_netdev(dev);
  159. return ERR_PTR(err);
  160. }
  161. static int __init apne_probe1(struct net_device *dev, int ioaddr)
  162. {
  163. int i;
  164. unsigned char SA_prom[32];
  165. int wordlength = 2;
  166. const char *name = NULL;
  167. int start_page, stop_page;
  168. #ifndef MANUAL_HWADDR0
  169. int neX000, ctron;
  170. #endif
  171. static unsigned version_printed;
  172. if (ei_debug && version_printed++ == 0)
  173. printk(version);
  174. printk("PCMCIA NE*000 ethercard probe");
  175. /* Reset card. Who knows what dain-bramaged state it was left in. */
  176. { unsigned long reset_start_time = jiffies;
  177. outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
  178. while ((inb(ioaddr + NE_EN0_ISR) & ENISR_RESET) == 0)
  179. if (time_after(jiffies, reset_start_time + 2*HZ/100)) {
  180. printk(" not found (no reset ack).\n");
  181. return -ENODEV;
  182. }
  183. outb(0xff, ioaddr + NE_EN0_ISR); /* Ack all intr. */
  184. }
  185. #ifndef MANUAL_HWADDR0
  186. /* Read the 16 bytes of station address PROM.
  187. We must first initialize registers, similar to NS8390_init(eifdev, 0).
  188. We can't reliably read the SAPROM address without this.
  189. (I learned the hard way!). */
  190. {
  191. struct {unsigned long value, offset; } program_seq[] = {
  192. {E8390_NODMA+E8390_PAGE0+E8390_STOP, NE_CMD}, /* Select page 0*/
  193. {0x48, NE_EN0_DCFG}, /* Set byte-wide (0x48) access. */
  194. {0x00, NE_EN0_RCNTLO}, /* Clear the count regs. */
  195. {0x00, NE_EN0_RCNTHI},
  196. {0x00, NE_EN0_IMR}, /* Mask completion irq. */
  197. {0xFF, NE_EN0_ISR},
  198. {E8390_RXOFF, NE_EN0_RXCR}, /* 0x20 Set to monitor */
  199. {E8390_TXOFF, NE_EN0_TXCR}, /* 0x02 and loopback mode. */
  200. {32, NE_EN0_RCNTLO},
  201. {0x00, NE_EN0_RCNTHI},
  202. {0x00, NE_EN0_RSARLO}, /* DMA starting at 0x0000. */
  203. {0x00, NE_EN0_RSARHI},
  204. {E8390_RREAD+E8390_START, NE_CMD},
  205. };
  206. for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++) {
  207. outb(program_seq[i].value, ioaddr + program_seq[i].offset);
  208. }
  209. }
  210. for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
  211. SA_prom[i] = inb(ioaddr + NE_DATAPORT);
  212. SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
  213. if (SA_prom[i] != SA_prom[i+1])
  214. wordlength = 1;
  215. }
  216. /* At this point, wordlength *only* tells us if the SA_prom is doubled
  217. up or not because some broken PCI cards don't respect the byte-wide
  218. request in program_seq above, and hence don't have doubled up values.
  219. These broken cards would otherwise be detected as an ne1000. */
  220. if (wordlength == 2)
  221. for (i = 0; i < 16; i++)
  222. SA_prom[i] = SA_prom[i+i];
  223. if (wordlength == 2) {
  224. /* We must set the 8390 for word mode. */
  225. outb(0x49, ioaddr + NE_EN0_DCFG);
  226. start_page = NESM_START_PG;
  227. stop_page = NESM_STOP_PG;
  228. } else {
  229. start_page = NE1SM_START_PG;
  230. stop_page = NE1SM_STOP_PG;
  231. }
  232. neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57);
  233. ctron = (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
  234. /* Set up the rest of the parameters. */
  235. if (neX000) {
  236. name = (wordlength == 2) ? "NE2000" : "NE1000";
  237. } else if (ctron) {
  238. name = (wordlength == 2) ? "Ctron-8" : "Ctron-16";
  239. start_page = 0x01;
  240. stop_page = (wordlength == 2) ? 0x40 : 0x20;
  241. } else {
  242. printk(" not found.\n");
  243. return -ENXIO;
  244. }
  245. #else
  246. wordlength = 2;
  247. /* We must set the 8390 for word mode. */
  248. outb(0x49, ioaddr + NE_EN0_DCFG);
  249. start_page = NESM_START_PG;
  250. stop_page = NESM_STOP_PG;
  251. SA_prom[0] = MANUAL_HWADDR0;
  252. SA_prom[1] = MANUAL_HWADDR1;
  253. SA_prom[2] = MANUAL_HWADDR2;
  254. SA_prom[3] = MANUAL_HWADDR3;
  255. SA_prom[4] = MANUAL_HWADDR4;
  256. SA_prom[5] = MANUAL_HWADDR5;
  257. name = "NE2000";
  258. #endif
  259. dev->base_addr = ioaddr;
  260. dev->irq = IRQ_AMIGA_PORTS;
  261. /* Install the Interrupt handler */
  262. i = request_irq(dev->irq, apne_interrupt, IRQF_SHARED, DRV_NAME, dev);
  263. if (i) return i;
  264. for(i = 0; i < ETHER_ADDR_LEN; i++) {
  265. printk(" %2.2x", SA_prom[i]);
  266. dev->dev_addr[i] = SA_prom[i];
  267. }
  268. printk("\n%s: %s found.\n", dev->name, name);
  269. ei_status.name = name;
  270. ei_status.tx_start_page = start_page;
  271. ei_status.stop_page = stop_page;
  272. ei_status.word16 = (wordlength == 2);
  273. ei_status.rx_start_page = start_page + TX_PAGES;
  274. ei_status.reset_8390 = &apne_reset_8390;
  275. ei_status.block_input = &apne_block_input;
  276. ei_status.block_output = &apne_block_output;
  277. ei_status.get_8390_hdr = &apne_get_8390_hdr;
  278. dev->open = &apne_open;
  279. dev->stop = &apne_close;
  280. #ifdef CONFIG_NET_POLL_CONTROLLER
  281. dev->poll_controller = ei_poll;
  282. #endif
  283. NS8390_init(dev, 0);
  284. pcmcia_ack_int(pcmcia_get_intreq()); /* ack PCMCIA int req */
  285. pcmcia_enable_irq();
  286. apne_owned = 1;
  287. return 0;
  288. }
  289. static int
  290. apne_open(struct net_device *dev)
  291. {
  292. ei_open(dev);
  293. return 0;
  294. }
  295. static int
  296. apne_close(struct net_device *dev)
  297. {
  298. if (ei_debug > 1)
  299. printk("%s: Shutting down ethercard.\n", dev->name);
  300. ei_close(dev);
  301. return 0;
  302. }
  303. /* Hard reset the card. This used to pause for the same period that a
  304. 8390 reset command required, but that shouldn't be necessary. */
  305. static void
  306. apne_reset_8390(struct net_device *dev)
  307. {
  308. unsigned long reset_start_time = jiffies;
  309. init_pcmcia();
  310. if (ei_debug > 1) printk("resetting the 8390 t=%ld...", jiffies);
  311. outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
  312. ei_status.txing = 0;
  313. ei_status.dmaing = 0;
  314. /* This check _should_not_ be necessary, omit eventually. */
  315. while ((inb(NE_BASE+NE_EN0_ISR) & ENISR_RESET) == 0)
  316. if (time_after(jiffies, reset_start_time + 2*HZ/100)) {
  317. printk("%s: ne_reset_8390() did not complete.\n", dev->name);
  318. break;
  319. }
  320. outb(ENISR_RESET, NE_BASE + NE_EN0_ISR); /* Ack intr. */
  321. }
  322. /* Grab the 8390 specific header. Similar to the block_input routine, but
  323. we don't need to be concerned with ring wrap as the header will be at
  324. the start of a page, so we optimize accordingly. */
  325. static void
  326. apne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  327. {
  328. int nic_base = dev->base_addr;
  329. int cnt;
  330. char *ptrc;
  331. short *ptrs;
  332. /* This *shouldn't* happen. If it does, it's the last thing you'll see */
  333. if (ei_status.dmaing) {
  334. printk("%s: DMAing conflict in ne_get_8390_hdr "
  335. "[DMAstat:%d][irqlock:%d][intr:%d].\n",
  336. dev->name, ei_status.dmaing, ei_status.irqlock, dev->irq);
  337. return;
  338. }
  339. ei_status.dmaing |= 0x01;
  340. outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
  341. outb(ENISR_RDC, nic_base + NE_EN0_ISR);
  342. outb(sizeof(struct e8390_pkt_hdr), nic_base + NE_EN0_RCNTLO);
  343. outb(0, nic_base + NE_EN0_RCNTHI);
  344. outb(0, nic_base + NE_EN0_RSARLO); /* On page boundary */
  345. outb(ring_page, nic_base + NE_EN0_RSARHI);
  346. outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
  347. if (ei_status.word16) {
  348. ptrs = (short*)hdr;
  349. for(cnt = 0; cnt < (sizeof(struct e8390_pkt_hdr)>>1); cnt++)
  350. *ptrs++ = inw(NE_BASE + NE_DATAPORT);
  351. } else {
  352. ptrc = (char*)hdr;
  353. for(cnt = 0; cnt < sizeof(struct e8390_pkt_hdr); cnt++)
  354. *ptrc++ = inb(NE_BASE + NE_DATAPORT);
  355. }
  356. outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */
  357. ei_status.dmaing &= ~0x01;
  358. le16_to_cpus(&hdr->count);
  359. }
  360. /* Block input and output, similar to the Crynwr packet driver. If you
  361. are porting to a new ethercard, look at the packet driver source for hints.
  362. The NEx000 doesn't share the on-board packet memory -- you have to put
  363. the packet out through the "remote DMA" dataport using outb. */
  364. static void
  365. apne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  366. {
  367. int nic_base = dev->base_addr;
  368. char *buf = skb->data;
  369. char *ptrc;
  370. short *ptrs;
  371. int cnt;
  372. /* This *shouldn't* happen. If it does, it's the last thing you'll see */
  373. if (ei_status.dmaing) {
  374. printk("%s: DMAing conflict in ne_block_input "
  375. "[DMAstat:%d][irqlock:%d][intr:%d].\n",
  376. dev->name, ei_status.dmaing, ei_status.irqlock, dev->irq);
  377. return;
  378. }
  379. ei_status.dmaing |= 0x01;
  380. outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
  381. outb(ENISR_RDC, nic_base + NE_EN0_ISR);
  382. outb(count & 0xff, nic_base + NE_EN0_RCNTLO);
  383. outb(count >> 8, nic_base + NE_EN0_RCNTHI);
  384. outb(ring_offset & 0xff, nic_base + NE_EN0_RSARLO);
  385. outb(ring_offset >> 8, nic_base + NE_EN0_RSARHI);
  386. outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
  387. if (ei_status.word16) {
  388. ptrs = (short*)buf;
  389. for (cnt = 0; cnt < (count>>1); cnt++)
  390. *ptrs++ = inw(NE_BASE + NE_DATAPORT);
  391. if (count & 0x01) {
  392. buf[count-1] = inb(NE_BASE + NE_DATAPORT);
  393. }
  394. } else {
  395. ptrc = (char*)buf;
  396. for (cnt = 0; cnt < count; cnt++)
  397. *ptrc++ = inb(NE_BASE + NE_DATAPORT);
  398. }
  399. outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */
  400. ei_status.dmaing &= ~0x01;
  401. }
  402. static void
  403. apne_block_output(struct net_device *dev, int count,
  404. const unsigned char *buf, const int start_page)
  405. {
  406. int nic_base = NE_BASE;
  407. unsigned long dma_start;
  408. char *ptrc;
  409. short *ptrs;
  410. int cnt;
  411. /* Round the count up for word writes. Do we need to do this?
  412. What effect will an odd byte count have on the 8390?
  413. I should check someday. */
  414. if (ei_status.word16 && (count & 0x01))
  415. count++;
  416. /* This *shouldn't* happen. If it does, it's the last thing you'll see */
  417. if (ei_status.dmaing) {
  418. printk("%s: DMAing conflict in ne_block_output."
  419. "[DMAstat:%d][irqlock:%d][intr:%d]\n",
  420. dev->name, ei_status.dmaing, ei_status.irqlock, dev->irq);
  421. return;
  422. }
  423. ei_status.dmaing |= 0x01;
  424. /* We should already be in page 0, but to be safe... */
  425. outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
  426. outb(ENISR_RDC, nic_base + NE_EN0_ISR);
  427. /* Now the normal output. */
  428. outb(count & 0xff, nic_base + NE_EN0_RCNTLO);
  429. outb(count >> 8, nic_base + NE_EN0_RCNTHI);
  430. outb(0x00, nic_base + NE_EN0_RSARLO);
  431. outb(start_page, nic_base + NE_EN0_RSARHI);
  432. outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
  433. if (ei_status.word16) {
  434. ptrs = (short*)buf;
  435. for (cnt = 0; cnt < count>>1; cnt++)
  436. outw(*ptrs++, NE_BASE+NE_DATAPORT);
  437. } else {
  438. ptrc = (char*)buf;
  439. for (cnt = 0; cnt < count; cnt++)
  440. outb(*ptrc++, NE_BASE + NE_DATAPORT);
  441. }
  442. dma_start = jiffies;
  443. while ((inb(NE_BASE + NE_EN0_ISR) & ENISR_RDC) == 0)
  444. if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */
  445. printk("%s: timeout waiting for Tx RDC.\n", dev->name);
  446. apne_reset_8390(dev);
  447. NS8390_init(dev,1);
  448. break;
  449. }
  450. outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */
  451. ei_status.dmaing &= ~0x01;
  452. return;
  453. }
  454. static irqreturn_t apne_interrupt(int irq, void *dev_id)
  455. {
  456. unsigned char pcmcia_intreq;
  457. if (!(gayle.inten & GAYLE_IRQ_IRQ))
  458. return IRQ_NONE;
  459. pcmcia_intreq = pcmcia_get_intreq();
  460. if (!(pcmcia_intreq & GAYLE_IRQ_IRQ)) {
  461. pcmcia_ack_int(pcmcia_intreq);
  462. return IRQ_NONE;
  463. }
  464. if (ei_debug > 3)
  465. printk("pcmcia intreq = %x\n", pcmcia_intreq);
  466. pcmcia_disable_irq(); /* to get rid of the sti() within ei_interrupt */
  467. ei_interrupt(irq, dev_id);
  468. pcmcia_ack_int(pcmcia_get_intreq());
  469. pcmcia_enable_irq();
  470. return IRQ_HANDLED;
  471. }
  472. #ifdef MODULE
  473. static struct net_device *apne_dev;
  474. int __init init_module(void)
  475. {
  476. apne_dev = apne_probe(-1);
  477. if (IS_ERR(apne_dev))
  478. return PTR_ERR(apne_dev);
  479. return 0;
  480. }
  481. void __exit cleanup_module(void)
  482. {
  483. unregister_netdev(apne_dev);
  484. pcmcia_disable_irq();
  485. free_irq(IRQ_AMIGA_PORTS, apne_dev);
  486. pcmcia_reset();
  487. release_region(IOBASE, 0x20);
  488. free_netdev(apne_dev);
  489. }
  490. #endif
  491. static int init_pcmcia(void)
  492. {
  493. u_char config;
  494. #ifndef MANUAL_CONFIG
  495. u_char tuple[32];
  496. int offset_len;
  497. #endif
  498. u_long offset;
  499. pcmcia_reset();
  500. pcmcia_program_voltage(PCMCIA_0V);
  501. pcmcia_access_speed(PCMCIA_SPEED_250NS);
  502. pcmcia_write_enable();
  503. #ifdef MANUAL_CONFIG
  504. config = MANUAL_CONFIG;
  505. #else
  506. /* get and write config byte to enable IO port */
  507. if (pcmcia_copy_tuple(CISTPL_CFTABLE_ENTRY, tuple, 32) < 3)
  508. return 0;
  509. config = tuple[2] & 0x3f;
  510. #endif
  511. #ifdef MANUAL_OFFSET
  512. offset = MANUAL_OFFSET;
  513. #else
  514. if (pcmcia_copy_tuple(CISTPL_CONFIG, tuple, 32) < 6)
  515. return 0;
  516. offset_len = (tuple[2] & 0x3) + 1;
  517. offset = 0;
  518. while(offset_len--) {
  519. offset = (offset << 8) | tuple[4+offset_len];
  520. }
  521. #endif
  522. out_8(GAYLE_ATTRIBUTE+offset, config);
  523. return 1;
  524. }
  525. MODULE_LICENSE("GPL");