com90xx.c 19 KB

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