isa-skeleton.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /* isa-skeleton.c: A network driver outline for linux.
  2. *
  3. * Written 1993-94 by Donald Becker.
  4. *
  5. * Copyright 1993 United States Government as represented by the
  6. * Director, National Security Agency.
  7. *
  8. * This software may be used and distributed according to the terms
  9. * of the GNU General Public License, incorporated herein by reference.
  10. *
  11. * The author may be reached as becker@scyld.com, or C/O
  12. * Scyld Computing Corporation
  13. * 410 Severn Ave., Suite 210
  14. * Annapolis MD 21403
  15. *
  16. * This file is an outline for writing a network device driver for the
  17. * the Linux operating system.
  18. *
  19. * To write (or understand) a driver, have a look at the "loopback.c" file to
  20. * get a feel of what is going on, and then use the code below as a skeleton
  21. * for the new driver.
  22. *
  23. */
  24. static const char *version =
  25. "isa-skeleton.c:v1.51 9/24/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  26. /*
  27. * Sources:
  28. * List your sources of programming information to document that
  29. * the driver is your own creation, and give due credit to others
  30. * that contributed to the work. Remember that GNU project code
  31. * cannot use proprietary or trade secret information. Interface
  32. * definitions are generally considered non-copyrightable to the
  33. * extent that the same names and structures must be used to be
  34. * compatible.
  35. *
  36. * Finally, keep in mind that the Linux kernel is has an API, not
  37. * ABI. Proprietary object-code-only distributions are not permitted
  38. * under the GPL.
  39. */
  40. #include <linux/module.h>
  41. #include <linux/kernel.h>
  42. #include <linux/types.h>
  43. #include <linux/fcntl.h>
  44. #include <linux/interrupt.h>
  45. #include <linux/ioport.h>
  46. #include <linux/in.h>
  47. #include <linux/slab.h>
  48. #include <linux/string.h>
  49. #include <linux/spinlock.h>
  50. #include <linux/errno.h>
  51. #include <linux/init.h>
  52. #include <linux/netdevice.h>
  53. #include <linux/etherdevice.h>
  54. #include <linux/skbuff.h>
  55. #include <linux/bitops.h>
  56. #include <asm/system.h>
  57. #include <asm/io.h>
  58. #include <asm/dma.h>
  59. /*
  60. * The name of the card. Is used for messages and in the requests for
  61. * io regions, irqs and dma channels
  62. */
  63. static const char* cardname = "netcard";
  64. /* First, a few definitions that the brave might change. */
  65. /* A zero-terminated list of I/O addresses to be probed. */
  66. static unsigned int netcard_portlist[] __initdata =
  67. { 0x200, 0x240, 0x280, 0x2C0, 0x300, 0x320, 0x340, 0};
  68. /* use 0 for production, 1 for verification, >2 for debug */
  69. #ifndef NET_DEBUG
  70. #define NET_DEBUG 2
  71. #endif
  72. static unsigned int net_debug = NET_DEBUG;
  73. /* The number of low I/O ports used by the ethercard. */
  74. #define NETCARD_IO_EXTENT 32
  75. #define MY_TX_TIMEOUT ((400*HZ)/1000)
  76. /* Information that need to be kept for each board. */
  77. struct net_local {
  78. struct net_device_stats stats;
  79. long open_time; /* Useless example local info. */
  80. /* Tx control lock. This protects the transmit buffer ring
  81. * state along with the "tx full" state of the driver. This
  82. * means all netif_queue flow control actions are protected
  83. * by this lock as well.
  84. */
  85. spinlock_t lock;
  86. };
  87. /* The station (ethernet) address prefix, used for IDing the board. */
  88. #define SA_ADDR0 0x00
  89. #define SA_ADDR1 0x42
  90. #define SA_ADDR2 0x65
  91. /* Index to functions, as function prototypes. */
  92. static int netcard_probe1(struct net_device *dev, int ioaddr);
  93. static int net_open(struct net_device *dev);
  94. static int net_send_packet(struct sk_buff *skb, struct net_device *dev);
  95. static irqreturn_t net_interrupt(int irq, void *dev_id);
  96. static void net_rx(struct net_device *dev);
  97. static int net_close(struct net_device *dev);
  98. static struct net_device_stats *net_get_stats(struct net_device *dev);
  99. static void set_multicast_list(struct net_device *dev);
  100. static void net_tx_timeout(struct net_device *dev);
  101. /* Example routines you must write ;->. */
  102. #define tx_done(dev) 1
  103. static void hardware_send_packet(short ioaddr, char *buf, int length);
  104. static void chipset_init(struct net_device *dev, int startp);
  105. /*
  106. * Check for a network adaptor of this type, and return '0' iff one exists.
  107. * If dev->base_addr == 0, probe all likely locations.
  108. * If dev->base_addr == 1, always return failure.
  109. * If dev->base_addr == 2, allocate space for the device and return success
  110. * (detachable devices only).
  111. */
  112. static int __init do_netcard_probe(struct net_device *dev)
  113. {
  114. int i;
  115. int base_addr = dev->base_addr;
  116. int irq = dev->irq;
  117. if (base_addr > 0x1ff) /* Check a single specified location. */
  118. return netcard_probe1(dev, base_addr);
  119. else if (base_addr != 0) /* Don't probe at all. */
  120. return -ENXIO;
  121. for (i = 0; netcard_portlist[i]; i++) {
  122. int ioaddr = netcard_portlist[i];
  123. if (netcard_probe1(dev, ioaddr) == 0)
  124. return 0;
  125. dev->irq = irq;
  126. }
  127. return -ENODEV;
  128. }
  129. static void cleanup_card(struct net_device *dev)
  130. {
  131. #ifdef jumpered_dma
  132. free_dma(dev->dma);
  133. #endif
  134. #ifdef jumpered_interrupts
  135. free_irq(dev->irq, dev);
  136. #endif
  137. release_region(dev->base_addr, NETCARD_IO_EXTENT);
  138. }
  139. #ifndef MODULE
  140. struct net_device * __init netcard_probe(int unit)
  141. {
  142. struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
  143. int err;
  144. if (!dev)
  145. return ERR_PTR(-ENOMEM);
  146. sprintf(dev->name, "eth%d", unit);
  147. netdev_boot_setup_check(dev);
  148. err = do_netcard_probe(dev);
  149. if (err)
  150. goto out;
  151. return dev;
  152. out:
  153. free_netdev(dev);
  154. return ERR_PTR(err);
  155. }
  156. #endif
  157. static const struct net_device_ops netcard_netdev_ops = {
  158. .ndo_open = net_open,
  159. .ndo_stop = net_close,
  160. .ndo_start_xmit = net_send_packet,
  161. .ndo_get_stats = net_get_stats,
  162. .ndo_set_multicast_list = set_multicast_list,
  163. .ndo_tx_timeout = net_tx_timeout,
  164. .ndo_validate_addr = eth_validate_addr,
  165. .ndo_set_mac_address = eth_mac_addr,
  166. .ndo_change_mtu = eth_change_mtu,
  167. };
  168. /*
  169. * This is the real probe routine. Linux has a history of friendly device
  170. * probes on the ISA bus. A good device probes avoids doing writes, and
  171. * verifies that the correct device exists and functions.
  172. */
  173. static int __init netcard_probe1(struct net_device *dev, int ioaddr)
  174. {
  175. struct net_local *np;
  176. static unsigned version_printed;
  177. int i;
  178. int err = -ENODEV;
  179. /* Grab the region so that no one else tries to probe our ioports. */
  180. if (!request_region(ioaddr, NETCARD_IO_EXTENT, cardname))
  181. return -EBUSY;
  182. /*
  183. * For ethernet adaptors the first three octets of the station address
  184. * contains the manufacturer's unique code. That might be a good probe
  185. * method. Ideally you would add additional checks.
  186. */
  187. if (inb(ioaddr + 0) != SA_ADDR0
  188. || inb(ioaddr + 1) != SA_ADDR1
  189. || inb(ioaddr + 2) != SA_ADDR2)
  190. goto out;
  191. if (net_debug && version_printed++ == 0)
  192. printk(KERN_DEBUG "%s", version);
  193. printk(KERN_INFO "%s: %s found at %#3x, ", dev->name, cardname, ioaddr);
  194. /* Fill in the 'dev' fields. */
  195. dev->base_addr = ioaddr;
  196. /* Retrieve and print the ethernet address. */
  197. for (i = 0; i < 6; i++)
  198. dev->dev_addr[i] = inb(ioaddr + i);
  199. printk("%pM", dev->dev_addr);
  200. err = -EAGAIN;
  201. #ifdef jumpered_interrupts
  202. /*
  203. * If this board has jumpered interrupts, allocate the interrupt
  204. * vector now. There is no point in waiting since no other device
  205. * can use the interrupt, and this marks the irq as busy. Jumpered
  206. * interrupts are typically not reported by the boards, and we must
  207. * used autoIRQ to find them.
  208. */
  209. if (dev->irq == -1)
  210. ; /* Do nothing: a user-level program will set it. */
  211. else if (dev->irq < 2) { /* "Auto-IRQ" */
  212. unsigned long irq_mask = probe_irq_on();
  213. /* Trigger an interrupt here. */
  214. dev->irq = probe_irq_off(irq_mask);
  215. if (net_debug >= 2)
  216. printk(" autoirq is %d", dev->irq);
  217. } else if (dev->irq == 2)
  218. /*
  219. * Fixup for users that don't know that IRQ 2 is really
  220. * IRQ9, or don't know which one to set.
  221. */
  222. dev->irq = 9;
  223. {
  224. int irqval = request_irq(dev->irq, &net_interrupt, 0, cardname, dev);
  225. if (irqval) {
  226. printk("%s: unable to get IRQ %d (irqval=%d).\n",
  227. dev->name, dev->irq, irqval);
  228. goto out;
  229. }
  230. }
  231. #endif /* jumpered interrupt */
  232. #ifdef jumpered_dma
  233. /*
  234. * If we use a jumpered DMA channel, that should be probed for and
  235. * allocated here as well. See lance.c for an example.
  236. */
  237. if (dev->dma == 0) {
  238. if (request_dma(dev->dma, cardname)) {
  239. printk("DMA %d allocation failed.\n", dev->dma);
  240. goto out1;
  241. } else
  242. printk(", assigned DMA %d.\n", dev->dma);
  243. } else {
  244. short dma_status, new_dma_status;
  245. /* Read the DMA channel status registers. */
  246. dma_status = ((inb(DMA1_STAT_REG) >> 4) & 0x0f) |
  247. (inb(DMA2_STAT_REG) & 0xf0);
  248. /* Trigger a DMA request, perhaps pause a bit. */
  249. outw(0x1234, ioaddr + 8);
  250. /* Re-read the DMA status registers. */
  251. new_dma_status = ((inb(DMA1_STAT_REG) >> 4) & 0x0f) |
  252. (inb(DMA2_STAT_REG) & 0xf0);
  253. /*
  254. * Eliminate the old and floating requests,
  255. * and DMA4 the cascade.
  256. */
  257. new_dma_status ^= dma_status;
  258. new_dma_status &= ~0x10;
  259. for (i = 7; i > 0; i--)
  260. if (test_bit(i, &new_dma_status)) {
  261. dev->dma = i;
  262. break;
  263. }
  264. if (i <= 0) {
  265. printk("DMA probe failed.\n");
  266. goto out1;
  267. }
  268. if (request_dma(dev->dma, cardname)) {
  269. printk("probed DMA %d allocation failed.\n", dev->dma);
  270. goto out1;
  271. }
  272. }
  273. #endif /* jumpered DMA */
  274. np = netdev_priv(dev);
  275. spin_lock_init(&np->lock);
  276. dev->netdev_ops = &netcard_netdev_ops;
  277. dev->watchdog_timeo = MY_TX_TIMEOUT;
  278. err = register_netdev(dev);
  279. if (err)
  280. goto out2;
  281. return 0;
  282. out2:
  283. #ifdef jumpered_dma
  284. free_dma(dev->dma);
  285. #endif
  286. out1:
  287. #ifdef jumpered_interrupts
  288. free_irq(dev->irq, dev);
  289. #endif
  290. out:
  291. release_region(base_addr, NETCARD_IO_EXTENT);
  292. return err;
  293. }
  294. static void net_tx_timeout(struct net_device *dev)
  295. {
  296. struct net_local *np = netdev_priv(dev);
  297. printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
  298. tx_done(dev) ? "IRQ conflict" : "network cable problem");
  299. /* Try to restart the adaptor. */
  300. chipset_init(dev, 1);
  301. np->stats.tx_errors++;
  302. /* If we have space available to accept new transmit
  303. * requests, wake up the queueing layer. This would
  304. * be the case if the chipset_init() call above just
  305. * flushes out the tx queue and empties it.
  306. *
  307. * If instead, the tx queue is retained then the
  308. * netif_wake_queue() call should be placed in the
  309. * TX completion interrupt handler of the driver instead
  310. * of here.
  311. */
  312. if (!tx_full(dev))
  313. netif_wake_queue(dev);
  314. }
  315. /*
  316. * Open/initialize the board. This is called (in the current kernel)
  317. * sometime after booting when the 'ifconfig' program is run.
  318. *
  319. * This routine should set everything up anew at each open, even
  320. * registers that "should" only need to be set once at boot, so that
  321. * there is non-reboot way to recover if something goes wrong.
  322. */
  323. static int
  324. net_open(struct net_device *dev)
  325. {
  326. struct net_local *np = netdev_priv(dev);
  327. int ioaddr = dev->base_addr;
  328. /*
  329. * This is used if the interrupt line can turned off (shared).
  330. * See 3c503.c for an example of selecting the IRQ at config-time.
  331. */
  332. if (request_irq(dev->irq, &net_interrupt, 0, cardname, dev)) {
  333. return -EAGAIN;
  334. }
  335. /*
  336. * Always allocate the DMA channel after the IRQ,
  337. * and clean up on failure.
  338. */
  339. if (request_dma(dev->dma, cardname)) {
  340. free_irq(dev->irq, dev);
  341. return -EAGAIN;
  342. }
  343. /* Reset the hardware here. Don't forget to set the station address. */
  344. chipset_init(dev, 1);
  345. outb(0x00, ioaddr);
  346. np->open_time = jiffies;
  347. /* We are now ready to accept transmit requeusts from
  348. * the queueing layer of the networking.
  349. */
  350. netif_start_queue(dev);
  351. return 0;
  352. }
  353. /* This will only be invoked if your driver is _not_ in XOFF state.
  354. * What this means is that you need not check it, and that this
  355. * invariant will hold if you make sure that the netif_*_queue()
  356. * calls are done at the proper times.
  357. */
  358. static int net_send_packet(struct sk_buff *skb, struct net_device *dev)
  359. {
  360. struct net_local *np = netdev_priv(dev);
  361. int ioaddr = dev->base_addr;
  362. short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
  363. unsigned char *buf = skb->data;
  364. /* If some error occurs while trying to transmit this
  365. * packet, you should return '1' from this function.
  366. * In such a case you _may not_ do anything to the
  367. * SKB, it is still owned by the network queueing
  368. * layer when an error is returned. This means you
  369. * may not modify any SKB fields, you may not free
  370. * the SKB, etc.
  371. */
  372. #if TX_RING
  373. /* This is the most common case for modern hardware.
  374. * The spinlock protects this code from the TX complete
  375. * hardware interrupt handler. Queue flow control is
  376. * thus managed under this lock as well.
  377. */
  378. spin_lock_irq(&np->lock);
  379. add_to_tx_ring(np, skb, length);
  380. dev->trans_start = jiffies;
  381. /* If we just used up the very last entry in the
  382. * TX ring on this device, tell the queueing
  383. * layer to send no more.
  384. */
  385. if (tx_full(dev))
  386. netif_stop_queue(dev);
  387. /* When the TX completion hw interrupt arrives, this
  388. * is when the transmit statistics are updated.
  389. */
  390. spin_unlock_irq(&np->lock);
  391. #else
  392. /* This is the case for older hardware which takes
  393. * a single transmit buffer at a time, and it is
  394. * just written to the device via PIO.
  395. *
  396. * No spin locking is needed since there is no TX complete
  397. * event. If by chance your card does have a TX complete
  398. * hardware IRQ then you may need to utilize np->lock here.
  399. */
  400. hardware_send_packet(ioaddr, buf, length);
  401. np->stats.tx_bytes += skb->len;
  402. dev->trans_start = jiffies;
  403. /* You might need to clean up and record Tx statistics here. */
  404. if (inw(ioaddr) == /*RU*/81)
  405. np->stats.tx_aborted_errors++;
  406. dev_kfree_skb (skb);
  407. #endif
  408. return 0;
  409. }
  410. #if TX_RING
  411. /* This handles TX complete events posted by the device
  412. * via interrupts.
  413. */
  414. void net_tx(struct net_device *dev)
  415. {
  416. struct net_local *np = netdev_priv(dev);
  417. int entry;
  418. /* This protects us from concurrent execution of
  419. * our dev->hard_start_xmit function above.
  420. */
  421. spin_lock(&np->lock);
  422. entry = np->tx_old;
  423. while (tx_entry_is_sent(np, entry)) {
  424. struct sk_buff *skb = np->skbs[entry];
  425. np->stats.tx_bytes += skb->len;
  426. dev_kfree_skb_irq (skb);
  427. entry = next_tx_entry(np, entry);
  428. }
  429. np->tx_old = entry;
  430. /* If we had stopped the queue due to a "tx full"
  431. * condition, and space has now been made available,
  432. * wake up the queue.
  433. */
  434. if (netif_queue_stopped(dev) && ! tx_full(dev))
  435. netif_wake_queue(dev);
  436. spin_unlock(&np->lock);
  437. }
  438. #endif
  439. /*
  440. * The typical workload of the driver:
  441. * Handle the network interface interrupts.
  442. */
  443. static irqreturn_t net_interrupt(int irq, void *dev_id)
  444. {
  445. struct net_device *dev = dev_id;
  446. struct net_local *np;
  447. int ioaddr, status;
  448. int handled = 0;
  449. ioaddr = dev->base_addr;
  450. np = netdev_priv(dev);
  451. status = inw(ioaddr + 0);
  452. if (status == 0)
  453. goto out;
  454. handled = 1;
  455. if (status & RX_INTR) {
  456. /* Got a packet(s). */
  457. net_rx(dev);
  458. }
  459. #if TX_RING
  460. if (status & TX_INTR) {
  461. /* Transmit complete. */
  462. net_tx(dev);
  463. np->stats.tx_packets++;
  464. netif_wake_queue(dev);
  465. }
  466. #endif
  467. if (status & COUNTERS_INTR) {
  468. /* Increment the appropriate 'localstats' field. */
  469. np->stats.tx_window_errors++;
  470. }
  471. out:
  472. return IRQ_RETVAL(handled);
  473. }
  474. /* We have a good packet(s), get it/them out of the buffers. */
  475. static void
  476. net_rx(struct net_device *dev)
  477. {
  478. struct net_local *lp = netdev_priv(dev);
  479. int ioaddr = dev->base_addr;
  480. int boguscount = 10;
  481. do {
  482. int status = inw(ioaddr);
  483. int pkt_len = inw(ioaddr);
  484. if (pkt_len == 0) /* Read all the frames? */
  485. break; /* Done for now */
  486. if (status & 0x40) { /* There was an error. */
  487. lp->stats.rx_errors++;
  488. if (status & 0x20) lp->stats.rx_frame_errors++;
  489. if (status & 0x10) lp->stats.rx_over_errors++;
  490. if (status & 0x08) lp->stats.rx_crc_errors++;
  491. if (status & 0x04) lp->stats.rx_fifo_errors++;
  492. } else {
  493. /* Malloc up new buffer. */
  494. struct sk_buff *skb;
  495. lp->stats.rx_bytes+=pkt_len;
  496. skb = dev_alloc_skb(pkt_len);
  497. if (skb == NULL) {
  498. printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n",
  499. dev->name);
  500. lp->stats.rx_dropped++;
  501. break;
  502. }
  503. skb->dev = dev;
  504. /* 'skb->data' points to the start of sk_buff data area. */
  505. memcpy(skb_put(skb,pkt_len), (void*)dev->rmem_start,
  506. pkt_len);
  507. /* or */
  508. insw(ioaddr, skb->data, (pkt_len + 1) >> 1);
  509. netif_rx(skb);
  510. lp->stats.rx_packets++;
  511. lp->stats.rx_bytes += pkt_len;
  512. }
  513. } while (--boguscount);
  514. return;
  515. }
  516. /* The inverse routine to net_open(). */
  517. static int
  518. net_close(struct net_device *dev)
  519. {
  520. struct net_local *lp = netdev_priv(dev);
  521. int ioaddr = dev->base_addr;
  522. lp->open_time = 0;
  523. netif_stop_queue(dev);
  524. /* Flush the Tx and disable Rx here. */
  525. disable_dma(dev->dma);
  526. /* If not IRQ or DMA jumpered, free up the line. */
  527. outw(0x00, ioaddr+0); /* Release the physical interrupt line. */
  528. free_irq(dev->irq, dev);
  529. free_dma(dev->dma);
  530. /* Update the statistics here. */
  531. return 0;
  532. }
  533. /*
  534. * Get the current statistics.
  535. * This may be called with the card open or closed.
  536. */
  537. static struct net_device_stats *net_get_stats(struct net_device *dev)
  538. {
  539. struct net_local *lp = netdev_priv(dev);
  540. short ioaddr = dev->base_addr;
  541. /* Update the statistics from the device registers. */
  542. lp->stats.rx_missed_errors = inw(ioaddr+1);
  543. return &lp->stats;
  544. }
  545. /*
  546. * Set or clear the multicast filter for this adaptor.
  547. * num_addrs == -1 Promiscuous mode, receive all packets
  548. * num_addrs == 0 Normal mode, clear multicast list
  549. * num_addrs > 0 Multicast mode, receive normal and MC packets,
  550. * and do best-effort filtering.
  551. */
  552. static void
  553. set_multicast_list(struct net_device *dev)
  554. {
  555. short ioaddr = dev->base_addr;
  556. if (dev->flags&IFF_PROMISC)
  557. {
  558. /* Enable promiscuous mode */
  559. outw(MULTICAST|PROMISC, ioaddr);
  560. }
  561. else if((dev->flags&IFF_ALLMULTI) || dev->mc_count > HW_MAX_ADDRS)
  562. {
  563. /* Disable promiscuous mode, use normal mode. */
  564. hardware_set_filter(NULL);
  565. outw(MULTICAST, ioaddr);
  566. }
  567. else if(dev->mc_count)
  568. {
  569. /* Walk the address list, and load the filter */
  570. hardware_set_filter(dev->mc_list);
  571. outw(MULTICAST, ioaddr);
  572. }
  573. else
  574. outw(0, ioaddr);
  575. }
  576. #ifdef MODULE
  577. static struct net_device *this_device;
  578. static int io = 0x300;
  579. static int irq;
  580. static int dma;
  581. static int mem;
  582. MODULE_LICENSE("GPL");
  583. int init_module(void)
  584. {
  585. struct net_device *dev;
  586. int result;
  587. if (io == 0)
  588. printk(KERN_WARNING "%s: You shouldn't use auto-probing with insmod!\n",
  589. cardname);
  590. dev = alloc_etherdev(sizeof(struct net_local));
  591. if (!dev)
  592. return -ENOMEM;
  593. /* Copy the parameters from insmod into the device structure. */
  594. dev->base_addr = io;
  595. dev->irq = irq;
  596. dev->dma = dma;
  597. dev->mem_start = mem;
  598. if (do_netcard_probe(dev) == 0) {
  599. this_device = dev;
  600. return 0;
  601. }
  602. free_netdev(dev);
  603. return -ENXIO;
  604. }
  605. void
  606. cleanup_module(void)
  607. {
  608. unregister_netdev(this_device);
  609. cleanup_card(this_device);
  610. free_netdev(this_device);
  611. }
  612. #endif /* MODULE */