com90xx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  2. * Linux ARCnet driver - COM90xx chipset (memory-mapped buffers)
  3. *
  4. * Written 1994-1999 by Avery Pennarun.
  5. * Written 1999 by Martin Mares <mj@ucw.cz>.
  6. * Derived from skeleton.c by Donald Becker.
  7. *
  8. * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
  9. * for sponsoring the further development of this driver.
  10. *
  11. * **********************
  12. *
  13. * The original copyright of skeleton.c was as follows:
  14. *
  15. * skeleton.c Written 1993 by Donald Becker.
  16. * Copyright 1993 United States Government as represented by the
  17. * Director, National Security Agency. This software may only be used
  18. * and distributed according to the terms of the GNU General Public License as
  19. * modified by SRC, incorporated herein by reference.
  20. *
  21. * **********************
  22. *
  23. * For more details, see drivers/net/arcnet.c
  24. *
  25. * **********************
  26. */
  27. #include <linux/module.h>
  28. #include <linux/moduleparam.h>
  29. #include <linux/init.h>
  30. #include <linux/ioport.h>
  31. #include <linux/delay.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/slab.h>
  34. #include <asm/io.h>
  35. #include <linux/arcdevice.h>
  36. #define VERSION "arcnet: COM90xx chipset support\n"
  37. /* Define this to speed up the autoprobe by assuming if only one io port and
  38. * shmem are left in the list at Stage 5, they must correspond to each
  39. * other.
  40. *
  41. * This is undefined by default because it might not always be true, and the
  42. * extra check makes the autoprobe even more careful. Speed demons can turn
  43. * it on - I think it should be fine if you only have one ARCnet card
  44. * installed.
  45. *
  46. * If no ARCnet cards are installed, this delay never happens anyway and thus
  47. * the option has no effect.
  48. */
  49. #undef FAST_PROBE
  50. /* Internal function declarations */
  51. static int com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *);
  52. static void com90xx_command(struct net_device *dev, int command);
  53. static int com90xx_status(struct net_device *dev);
  54. static void com90xx_setmask(struct net_device *dev, int mask);
  55. static int com90xx_reset(struct net_device *dev, int really_reset);
  56. static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
  57. void *buf, int count);
  58. static void com90xx_copy_from_card(struct net_device *dev, int bufnum, int offset,
  59. void *buf, int count);
  60. /* Known ARCnet cards */
  61. static struct net_device *cards[16];
  62. static int numcards;
  63. /* Handy defines for ARCnet specific stuff */
  64. /* The number of low I/O ports used by the card */
  65. #define ARCNET_TOTAL_SIZE 16
  66. /* Amount of I/O memory used by the card */
  67. #define BUFFER_SIZE (512)
  68. #define MIRROR_SIZE (BUFFER_SIZE*4)
  69. /* COM 9026 controller chip --> ARCnet register addresses */
  70. #define _INTMASK (ioaddr+0) /* writable */
  71. #define _STATUS (ioaddr+0) /* readable */
  72. #define _COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
  73. #define _CONFIG (ioaddr+2) /* Configuration register */
  74. #define _RESET (ioaddr+8) /* software reset (on read) */
  75. #define _MEMDATA (ioaddr+12) /* Data port for IO-mapped memory */
  76. #define _ADDR_HI (ioaddr+15) /* Control registers for said */
  77. #define _ADDR_LO (ioaddr+14)
  78. #undef ASTATUS
  79. #undef ACOMMAND
  80. #undef AINTMASK
  81. #define ASTATUS() inb(_STATUS)
  82. #define ACOMMAND(cmd) outb((cmd),_COMMAND)
  83. #define AINTMASK(msk) outb((msk),_INTMASK)
  84. static int com90xx_skip_probe __initdata = 0;
  85. /* Module parameters */
  86. static int io; /* use the insmod io= irq= shmem= options */
  87. static int irq;
  88. static int shmem;
  89. static char device[9]; /* use eg. device=arc1 to change name */
  90. module_param(io, int, 0);
  91. module_param(irq, int, 0);
  92. module_param(shmem, int, 0);
  93. module_param_string(device, device, sizeof(device), 0);
  94. static void __init com90xx_probe(void)
  95. {
  96. int count, status, ioaddr, numprint, airq, openparen = 0;
  97. unsigned long airqmask;
  98. int ports[(0x3f0 - 0x200) / 16 + 1] =
  99. {0};
  100. unsigned long *shmems;
  101. void __iomem **iomem;
  102. int numports, numshmems, *port;
  103. u_long *p;
  104. int index;
  105. if (!io && !irq && !shmem && !*device && com90xx_skip_probe)
  106. return;
  107. shmems = kzalloc(((0x100000-0xa0000) / 0x800) * sizeof(unsigned long),
  108. GFP_KERNEL);
  109. if (!shmems)
  110. return;
  111. iomem = kzalloc(((0x100000-0xa0000) / 0x800) * sizeof(void __iomem *),
  112. GFP_KERNEL);
  113. if (!iomem) {
  114. kfree(shmems);
  115. return;
  116. }
  117. BUGLVL(D_NORMAL) printk(VERSION);
  118. /* set up the arrays where we'll store the possible probe addresses */
  119. numports = numshmems = 0;
  120. if (io)
  121. ports[numports++] = io;
  122. else
  123. for (count = 0x200; count <= 0x3f0; count += 16)
  124. ports[numports++] = count;
  125. if (shmem)
  126. shmems[numshmems++] = shmem;
  127. else
  128. for (count = 0xA0000; count <= 0xFF800; count += 2048)
  129. shmems[numshmems++] = count;
  130. /* Stage 1: abandon any reserved ports, or ones with status==0xFF
  131. * (empty), and reset any others by reading the reset port.
  132. */
  133. numprint = -1;
  134. for (port = &ports[0]; port - ports < numports; port++) {
  135. numprint++;
  136. numprint %= 8;
  137. if (!numprint) {
  138. BUGMSG2(D_INIT, "\n");
  139. BUGMSG2(D_INIT, "S1: ");
  140. }
  141. BUGMSG2(D_INIT, "%Xh ", *port);
  142. ioaddr = *port;
  143. if (!request_region(*port, ARCNET_TOTAL_SIZE, "arcnet (90xx)")) {
  144. BUGMSG2(D_INIT_REASONS, "(request_region)\n");
  145. BUGMSG2(D_INIT_REASONS, "S1: ");
  146. BUGLVL(D_INIT_REASONS) numprint = 0;
  147. *port-- = ports[--numports];
  148. continue;
  149. }
  150. if (ASTATUS() == 0xFF) {
  151. BUGMSG2(D_INIT_REASONS, "(empty)\n");
  152. BUGMSG2(D_INIT_REASONS, "S1: ");
  153. BUGLVL(D_INIT_REASONS) numprint = 0;
  154. release_region(*port, ARCNET_TOTAL_SIZE);
  155. *port-- = ports[--numports];
  156. continue;
  157. }
  158. inb(_RESET); /* begin resetting card */
  159. BUGMSG2(D_INIT_REASONS, "\n");
  160. BUGMSG2(D_INIT_REASONS, "S1: ");
  161. BUGLVL(D_INIT_REASONS) numprint = 0;
  162. }
  163. BUGMSG2(D_INIT, "\n");
  164. if (!numports) {
  165. BUGMSG2(D_NORMAL, "S1: No ARCnet cards found.\n");
  166. kfree(shmems);
  167. kfree(iomem);
  168. return;
  169. }
  170. /* Stage 2: we have now reset any possible ARCnet cards, so we can't
  171. * do anything until they finish. If D_INIT, print the list of
  172. * cards that are left.
  173. */
  174. numprint = -1;
  175. for (port = &ports[0]; port < ports + numports; port++) {
  176. numprint++;
  177. numprint %= 8;
  178. if (!numprint) {
  179. BUGMSG2(D_INIT, "\n");
  180. BUGMSG2(D_INIT, "S2: ");
  181. }
  182. BUGMSG2(D_INIT, "%Xh ", *port);
  183. }
  184. BUGMSG2(D_INIT, "\n");
  185. mdelay(RESETtime);
  186. /* Stage 3: abandon any shmem addresses that don't have the signature
  187. * 0xD1 byte in the right place, or are read-only.
  188. */
  189. numprint = -1;
  190. for (index = 0, p = &shmems[0]; index < numshmems; p++, index++) {
  191. void __iomem *base;
  192. numprint++;
  193. numprint %= 8;
  194. if (!numprint) {
  195. BUGMSG2(D_INIT, "\n");
  196. BUGMSG2(D_INIT, "S3: ");
  197. }
  198. BUGMSG2(D_INIT, "%lXh ", *p);
  199. if (!request_mem_region(*p, MIRROR_SIZE, "arcnet (90xx)")) {
  200. BUGMSG2(D_INIT_REASONS, "(request_mem_region)\n");
  201. BUGMSG2(D_INIT_REASONS, "Stage 3: ");
  202. BUGLVL(D_INIT_REASONS) numprint = 0;
  203. goto out;
  204. }
  205. base = ioremap(*p, MIRROR_SIZE);
  206. if (!base) {
  207. BUGMSG2(D_INIT_REASONS, "(ioremap)\n");
  208. BUGMSG2(D_INIT_REASONS, "Stage 3: ");
  209. BUGLVL(D_INIT_REASONS) numprint = 0;
  210. goto out1;
  211. }
  212. if (readb(base) != TESTvalue) {
  213. BUGMSG2(D_INIT_REASONS, "(%02Xh != %02Xh)\n",
  214. readb(base), TESTvalue);
  215. BUGMSG2(D_INIT_REASONS, "S3: ");
  216. BUGLVL(D_INIT_REASONS) numprint = 0;
  217. goto out2;
  218. }
  219. /* By writing 0x42 to the TESTvalue location, we also make
  220. * sure no "mirror" shmem areas show up - if they occur
  221. * in another pass through this loop, they will be discarded
  222. * because *cptr != TESTvalue.
  223. */
  224. writeb(0x42, base);
  225. if (readb(base) != 0x42) {
  226. BUGMSG2(D_INIT_REASONS, "(read only)\n");
  227. BUGMSG2(D_INIT_REASONS, "S3: ");
  228. goto out2;
  229. }
  230. BUGMSG2(D_INIT_REASONS, "\n");
  231. BUGMSG2(D_INIT_REASONS, "S3: ");
  232. BUGLVL(D_INIT_REASONS) numprint = 0;
  233. iomem[index] = base;
  234. continue;
  235. out2:
  236. iounmap(base);
  237. out1:
  238. release_mem_region(*p, MIRROR_SIZE);
  239. out:
  240. *p-- = shmems[--numshmems];
  241. index--;
  242. }
  243. BUGMSG2(D_INIT, "\n");
  244. if (!numshmems) {
  245. BUGMSG2(D_NORMAL, "S3: No ARCnet cards found.\n");
  246. for (port = &ports[0]; port < ports + numports; port++)
  247. release_region(*port, ARCNET_TOTAL_SIZE);
  248. kfree(shmems);
  249. kfree(iomem);
  250. return;
  251. }
  252. /* Stage 4: something of a dummy, to report the shmems that are
  253. * still possible after stage 3.
  254. */
  255. numprint = -1;
  256. for (p = &shmems[0]; p < shmems + numshmems; p++) {
  257. numprint++;
  258. numprint %= 8;
  259. if (!numprint) {
  260. BUGMSG2(D_INIT, "\n");
  261. BUGMSG2(D_INIT, "S4: ");
  262. }
  263. BUGMSG2(D_INIT, "%lXh ", *p);
  264. }
  265. BUGMSG2(D_INIT, "\n");
  266. /* Stage 5: for any ports that have the correct status, can disable
  267. * the RESET flag, and (if no irq is given) generate an autoirq,
  268. * register an ARCnet device.
  269. *
  270. * Currently, we can only register one device per probe, so quit
  271. * after the first one is found.
  272. */
  273. numprint = -1;
  274. for (port = &ports[0]; port < ports + numports; port++) {
  275. int found = 0;
  276. numprint++;
  277. numprint %= 8;
  278. if (!numprint) {
  279. BUGMSG2(D_INIT, "\n");
  280. BUGMSG2(D_INIT, "S5: ");
  281. }
  282. BUGMSG2(D_INIT, "%Xh ", *port);
  283. ioaddr = *port;
  284. status = ASTATUS();
  285. if ((status & 0x9D)
  286. != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
  287. BUGMSG2(D_INIT_REASONS, "(status=%Xh)\n", status);
  288. BUGMSG2(D_INIT_REASONS, "S5: ");
  289. BUGLVL(D_INIT_REASONS) numprint = 0;
  290. release_region(*port, ARCNET_TOTAL_SIZE);
  291. *port-- = ports[--numports];
  292. continue;
  293. }
  294. ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
  295. status = ASTATUS();
  296. if (status & RESETflag) {
  297. BUGMSG2(D_INIT_REASONS, " (eternal reset, status=%Xh)\n",
  298. status);
  299. BUGMSG2(D_INIT_REASONS, "S5: ");
  300. BUGLVL(D_INIT_REASONS) numprint = 0;
  301. release_region(*port, ARCNET_TOTAL_SIZE);
  302. *port-- = ports[--numports];
  303. continue;
  304. }
  305. /* skip this completely if an IRQ was given, because maybe
  306. * we're on a machine that locks during autoirq!
  307. */
  308. if (!irq) {
  309. /* if we do this, we're sure to get an IRQ since the
  310. * card has just reset and the NORXflag is on until
  311. * we tell it to start receiving.
  312. */
  313. airqmask = probe_irq_on();
  314. AINTMASK(NORXflag);
  315. udelay(1);
  316. AINTMASK(0);
  317. airq = probe_irq_off(airqmask);
  318. if (airq <= 0) {
  319. BUGMSG2(D_INIT_REASONS, "(airq=%d)\n", airq);
  320. BUGMSG2(D_INIT_REASONS, "S5: ");
  321. BUGLVL(D_INIT_REASONS) numprint = 0;
  322. release_region(*port, ARCNET_TOTAL_SIZE);
  323. *port-- = ports[--numports];
  324. continue;
  325. }
  326. } else {
  327. airq = irq;
  328. }
  329. BUGMSG2(D_INIT, "(%d,", airq);
  330. openparen = 1;
  331. /* Everything seems okay. But which shmem, if any, puts
  332. * back its signature byte when the card is reset?
  333. *
  334. * If there are multiple cards installed, there might be
  335. * multiple shmems still in the list.
  336. */
  337. #ifdef FAST_PROBE
  338. if (numports > 1 || numshmems > 1) {
  339. inb(_RESET);
  340. mdelay(RESETtime);
  341. } else {
  342. /* just one shmem and port, assume they match */
  343. writeb(TESTvalue, iomem[0]);
  344. }
  345. #else
  346. inb(_RESET);
  347. mdelay(RESETtime);
  348. #endif
  349. for (index = 0; index < numshmems; index++) {
  350. u_long ptr = shmems[index];
  351. void __iomem *base = iomem[index];
  352. if (readb(base) == TESTvalue) { /* found one */
  353. BUGMSG2(D_INIT, "%lXh)\n", *p);
  354. openparen = 0;
  355. /* register the card */
  356. if (com90xx_found(*port, airq, ptr, base) == 0)
  357. found = 1;
  358. numprint = -1;
  359. /* remove shmem from the list */
  360. shmems[index] = shmems[--numshmems];
  361. iomem[index] = iomem[numshmems];
  362. break; /* go to the next I/O port */
  363. } else {
  364. BUGMSG2(D_INIT_REASONS, "%Xh-", readb(base));
  365. }
  366. }
  367. if (openparen) {
  368. BUGLVL(D_INIT) printk("no matching shmem)\n");
  369. BUGLVL(D_INIT_REASONS) printk("S5: ");
  370. BUGLVL(D_INIT_REASONS) numprint = 0;
  371. }
  372. if (!found)
  373. release_region(*port, ARCNET_TOTAL_SIZE);
  374. *port-- = ports[--numports];
  375. }
  376. BUGLVL(D_INIT_REASONS) printk("\n");
  377. /* Now put back TESTvalue on all leftover shmems. */
  378. for (index = 0; index < numshmems; index++) {
  379. writeb(TESTvalue, iomem[index]);
  380. iounmap(iomem[index]);
  381. release_mem_region(shmems[index], MIRROR_SIZE);
  382. }
  383. kfree(shmems);
  384. kfree(iomem);
  385. }
  386. static int check_mirror(unsigned long addr, size_t size)
  387. {
  388. void __iomem *p;
  389. int res = -1;
  390. if (!request_mem_region(addr, size, "arcnet (90xx)"))
  391. return -1;
  392. p = ioremap(addr, size);
  393. if (p) {
  394. if (readb(p) == TESTvalue)
  395. res = 1;
  396. else
  397. res = 0;
  398. iounmap(p);
  399. }
  400. release_mem_region(addr, size);
  401. return res;
  402. }
  403. /* Set up the struct net_device associated with this card. Called after
  404. * probing succeeds.
  405. */
  406. static int __init com90xx_found(int ioaddr, int airq, u_long shmem, void __iomem *p)
  407. {
  408. struct net_device *dev = NULL;
  409. struct arcnet_local *lp;
  410. u_long first_mirror, last_mirror;
  411. int mirror_size;
  412. /* allocate struct net_device */
  413. dev = alloc_arcdev(device);
  414. if (!dev) {
  415. BUGMSG2(D_NORMAL, "com90xx: Can't allocate device!\n");
  416. iounmap(p);
  417. release_mem_region(shmem, MIRROR_SIZE);
  418. return -ENOMEM;
  419. }
  420. lp = netdev_priv(dev);
  421. /* find the real shared memory start/end points, including mirrors */
  422. /* guess the actual size of one "memory mirror" - the number of
  423. * bytes between copies of the shared memory. On most cards, it's
  424. * 2k (or there are no mirrors at all) but on some, it's 4k.
  425. */
  426. mirror_size = MIRROR_SIZE;
  427. if (readb(p) == TESTvalue &&
  428. check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 &&
  429. check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1)
  430. mirror_size = 2 * MIRROR_SIZE;
  431. first_mirror = shmem - mirror_size;
  432. while (check_mirror(first_mirror, mirror_size) == 1)
  433. first_mirror -= mirror_size;
  434. first_mirror += mirror_size;
  435. last_mirror = shmem + mirror_size;
  436. while (check_mirror(last_mirror, mirror_size) == 1)
  437. last_mirror += mirror_size;
  438. last_mirror -= mirror_size;
  439. dev->mem_start = first_mirror;
  440. dev->mem_end = last_mirror + MIRROR_SIZE - 1;
  441. iounmap(p);
  442. release_mem_region(shmem, MIRROR_SIZE);
  443. if (!request_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1, "arcnet (90xx)"))
  444. goto err_free_dev;
  445. /* reserve the irq */
  446. if (request_irq(airq, arcnet_interrupt, 0, "arcnet (90xx)", dev)) {
  447. BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", airq);
  448. goto err_release_mem;
  449. }
  450. dev->irq = airq;
  451. /* Initialize the rest of the device structure. */
  452. lp->card_name = "COM90xx";
  453. lp->hw.command = com90xx_command;
  454. lp->hw.status = com90xx_status;
  455. lp->hw.intmask = com90xx_setmask;
  456. lp->hw.reset = com90xx_reset;
  457. lp->hw.owner = THIS_MODULE;
  458. lp->hw.copy_to_card = com90xx_copy_to_card;
  459. lp->hw.copy_from_card = com90xx_copy_from_card;
  460. lp->mem_start = ioremap(dev->mem_start, dev->mem_end - dev->mem_start + 1);
  461. if (!lp->mem_start) {
  462. BUGMSG(D_NORMAL, "Can't remap device memory!\n");
  463. goto err_free_irq;
  464. }
  465. /* get and check the station ID from offset 1 in shmem */
  466. dev->dev_addr[0] = readb(lp->mem_start + 1);
  467. dev->base_addr = ioaddr;
  468. BUGMSG(D_NORMAL, "COM90xx station %02Xh found at %03lXh, IRQ %d, "
  469. "ShMem %lXh (%ld*%xh).\n",
  470. dev->dev_addr[0],
  471. dev->base_addr, dev->irq, dev->mem_start,
  472. (dev->mem_end - dev->mem_start + 1) / mirror_size, mirror_size);
  473. if (register_netdev(dev))
  474. goto err_unmap;
  475. cards[numcards++] = dev;
  476. return 0;
  477. err_unmap:
  478. iounmap(lp->mem_start);
  479. err_free_irq:
  480. free_irq(dev->irq, dev);
  481. err_release_mem:
  482. release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
  483. err_free_dev:
  484. free_netdev(dev);
  485. return -EIO;
  486. }
  487. static void com90xx_command(struct net_device *dev, int cmd)
  488. {
  489. short ioaddr = dev->base_addr;
  490. ACOMMAND(cmd);
  491. }
  492. static int com90xx_status(struct net_device *dev)
  493. {
  494. short ioaddr = dev->base_addr;
  495. return ASTATUS();
  496. }
  497. static void com90xx_setmask(struct net_device *dev, int mask)
  498. {
  499. short ioaddr = dev->base_addr;
  500. AINTMASK(mask);
  501. }
  502. /*
  503. * Do a hardware reset on the card, and set up necessary registers.
  504. *
  505. * This should be called as little as possible, because it disrupts the
  506. * token on the network (causes a RECON) and requires a significant delay.
  507. *
  508. * However, it does make sure the card is in a defined state.
  509. */
  510. static int com90xx_reset(struct net_device *dev, int really_reset)
  511. {
  512. struct arcnet_local *lp = netdev_priv(dev);
  513. short ioaddr = dev->base_addr;
  514. BUGMSG(D_INIT, "Resetting (status=%02Xh)\n", ASTATUS());
  515. if (really_reset) {
  516. /* reset the card */
  517. inb(_RESET);
  518. mdelay(RESETtime);
  519. }
  520. ACOMMAND(CFLAGScmd | RESETclear); /* clear flags & end reset */
  521. ACOMMAND(CFLAGScmd | CONFIGclear);
  522. /* don't do this until we verify that it doesn't hurt older cards! */
  523. /* outb(inb(_CONFIG) | ENABLE16flag, _CONFIG); */
  524. /* verify that the ARCnet signature byte is present */
  525. if (readb(lp->mem_start) != TESTvalue) {
  526. if (really_reset)
  527. BUGMSG(D_NORMAL, "reset failed: TESTvalue not present.\n");
  528. return 1;
  529. }
  530. /* enable extended (512-byte) packets */
  531. ACOMMAND(CONFIGcmd | EXTconf);
  532. /* clean out all the memory to make debugging make more sense :) */
  533. BUGLVL(D_DURING)
  534. memset_io(lp->mem_start, 0x42, 2048);
  535. /* done! return success. */
  536. return 0;
  537. }
  538. static void com90xx_copy_to_card(struct net_device *dev, int bufnum, int offset,
  539. void *buf, int count)
  540. {
  541. struct arcnet_local *lp = netdev_priv(dev);
  542. void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
  543. TIME("memcpy_toio", count, memcpy_toio(memaddr, buf, count));
  544. }
  545. static void com90xx_copy_from_card(struct net_device *dev, int bufnum, int offset,
  546. void *buf, int count)
  547. {
  548. struct arcnet_local *lp = netdev_priv(dev);
  549. void __iomem *memaddr = lp->mem_start + bufnum * 512 + offset;
  550. TIME("memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
  551. }
  552. MODULE_LICENSE("GPL");
  553. static int __init com90xx_init(void)
  554. {
  555. if (irq == 2)
  556. irq = 9;
  557. com90xx_probe();
  558. if (!numcards)
  559. return -EIO;
  560. return 0;
  561. }
  562. static void __exit com90xx_exit(void)
  563. {
  564. struct net_device *dev;
  565. struct arcnet_local *lp;
  566. int count;
  567. for (count = 0; count < numcards; count++) {
  568. dev = cards[count];
  569. lp = netdev_priv(dev);
  570. unregister_netdev(dev);
  571. free_irq(dev->irq, dev);
  572. iounmap(lp->mem_start);
  573. release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
  574. release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
  575. free_netdev(dev);
  576. }
  577. }
  578. module_init(com90xx_init);
  579. module_exit(com90xx_exit);
  580. #ifndef MODULE
  581. static int __init com90xx_setup(char *s)
  582. {
  583. int ints[8];
  584. s = get_options(s, 8, ints);
  585. if (!ints[0] && !*s) {
  586. printk("com90xx: Disabled.\n");
  587. return 1;
  588. }
  589. switch (ints[0]) {
  590. default: /* ERROR */
  591. printk("com90xx: Too many arguments.\n");
  592. case 3: /* Mem address */
  593. shmem = ints[3];
  594. case 2: /* IRQ */
  595. irq = ints[2];
  596. case 1: /* IO address */
  597. io = ints[1];
  598. }
  599. if (*s)
  600. snprintf(device, sizeof(device), "%s", s);
  601. return 1;
  602. }
  603. __setup("com90xx=", com90xx_setup);
  604. #endif