isa-skeleton.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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. unsigned long flags;
  379. spin_lock_irqsave(&np->lock, flags);
  380. add_to_tx_ring(np, skb, length);
  381. dev->trans_start = jiffies;
  382. /* If we just used up the very last entry in the
  383. * TX ring on this device, tell the queueing
  384. * layer to send no more.
  385. */
  386. if (tx_full(dev))
  387. netif_stop_queue(dev);
  388. /* When the TX completion hw interrupt arrives, this
  389. * is when the transmit statistics are updated.
  390. */
  391. spin_unlock_irqrestore(&np->lock, flags);
  392. #else
  393. /* This is the case for older hardware which takes
  394. * a single transmit buffer at a time, and it is
  395. * just written to the device via PIO.
  396. *
  397. * No spin locking is needed since there is no TX complete
  398. * event. If by chance your card does have a TX complete
  399. * hardware IRQ then you may need to utilize np->lock here.
  400. */
  401. hardware_send_packet(ioaddr, buf, length);
  402. np->stats.tx_bytes += skb->len;
  403. dev->trans_start = jiffies;
  404. /* You might need to clean up and record Tx statistics here. */
  405. if (inw(ioaddr) == /*RU*/81)
  406. np->stats.tx_aborted_errors++;
  407. dev_kfree_skb (skb);
  408. #endif
  409. return 0;
  410. }
  411. #if TX_RING
  412. /* This handles TX complete events posted by the device
  413. * via interrupts.
  414. */
  415. void net_tx(struct net_device *dev)
  416. {
  417. struct net_local *np = netdev_priv(dev);
  418. int entry;
  419. /* This protects us from concurrent execution of
  420. * our dev->hard_start_xmit function above.
  421. */
  422. spin_lock(&np->lock);
  423. entry = np->tx_old;
  424. while (tx_entry_is_sent(np, entry)) {
  425. struct sk_buff *skb = np->skbs[entry];
  426. np->stats.tx_bytes += skb->len;
  427. dev_kfree_skb_irq (skb);
  428. entry = next_tx_entry(np, entry);
  429. }
  430. np->tx_old = entry;
  431. /* If we had stopped the queue due to a "tx full"
  432. * condition, and space has now been made available,
  433. * wake up the queue.
  434. */
  435. if (netif_queue_stopped(dev) && ! tx_full(dev))
  436. netif_wake_queue(dev);
  437. spin_unlock(&np->lock);
  438. }
  439. #endif
  440. /*
  441. * The typical workload of the driver:
  442. * Handle the network interface interrupts.
  443. */
  444. static irqreturn_t net_interrupt(int irq, void *dev_id)
  445. {
  446. struct net_device *dev = dev_id;
  447. struct net_local *np;
  448. int ioaddr, status;
  449. int handled = 0;
  450. ioaddr = dev->base_addr;
  451. np = netdev_priv(dev);
  452. status = inw(ioaddr + 0);
  453. if (status == 0)
  454. goto out;
  455. handled = 1;
  456. if (status & RX_INTR) {
  457. /* Got a packet(s). */
  458. net_rx(dev);
  459. }
  460. #if TX_RING
  461. if (status & TX_INTR) {
  462. /* Transmit complete. */
  463. net_tx(dev);
  464. np->stats.tx_packets++;
  465. netif_wake_queue(dev);
  466. }
  467. #endif
  468. if (status & COUNTERS_INTR) {
  469. /* Increment the appropriate 'localstats' field. */
  470. np->stats.tx_window_errors++;
  471. }
  472. out:
  473. return IRQ_RETVAL(handled);
  474. }
  475. /* We have a good packet(s), get it/them out of the buffers. */
  476. static void
  477. net_rx(struct net_device *dev)
  478. {
  479. struct net_local *lp = netdev_priv(dev);
  480. int ioaddr = dev->base_addr;
  481. int boguscount = 10;
  482. do {
  483. int status = inw(ioaddr);
  484. int pkt_len = inw(ioaddr);
  485. if (pkt_len == 0) /* Read all the frames? */
  486. break; /* Done for now */
  487. if (status & 0x40) { /* There was an error. */
  488. lp->stats.rx_errors++;
  489. if (status & 0x20) lp->stats.rx_frame_errors++;
  490. if (status & 0x10) lp->stats.rx_over_errors++;
  491. if (status & 0x08) lp->stats.rx_crc_errors++;
  492. if (status & 0x04) lp->stats.rx_fifo_errors++;
  493. } else {
  494. /* Malloc up new buffer. */
  495. struct sk_buff *skb;
  496. lp->stats.rx_bytes+=pkt_len;
  497. skb = dev_alloc_skb(pkt_len);
  498. if (skb == NULL) {
  499. printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n",
  500. dev->name);
  501. lp->stats.rx_dropped++;
  502. break;
  503. }
  504. skb->dev = dev;
  505. /* 'skb->data' points to the start of sk_buff data area. */
  506. memcpy(skb_put(skb,pkt_len), (void*)dev->rmem_start,
  507. pkt_len);
  508. /* or */
  509. insw(ioaddr, skb->data, (pkt_len + 1) >> 1);
  510. netif_rx(skb);
  511. lp->stats.rx_packets++;
  512. lp->stats.rx_bytes += pkt_len;
  513. }
  514. } while (--boguscount);
  515. return;
  516. }
  517. /* The inverse routine to net_open(). */
  518. static int
  519. net_close(struct net_device *dev)
  520. {
  521. struct net_local *lp = netdev_priv(dev);
  522. int ioaddr = dev->base_addr;
  523. lp->open_time = 0;
  524. netif_stop_queue(dev);
  525. /* Flush the Tx and disable Rx here. */
  526. disable_dma(dev->dma);
  527. /* If not IRQ or DMA jumpered, free up the line. */
  528. outw(0x00, ioaddr+0); /* Release the physical interrupt line. */
  529. free_irq(dev->irq, dev);
  530. free_dma(dev->dma);
  531. /* Update the statistics here. */
  532. return 0;
  533. }
  534. /*
  535. * Get the current statistics.
  536. * This may be called with the card open or closed.
  537. */
  538. static struct net_device_stats *net_get_stats(struct net_device *dev)
  539. {
  540. struct net_local *lp = netdev_priv(dev);
  541. short ioaddr = dev->base_addr;
  542. /* Update the statistics from the device registers. */
  543. lp->stats.rx_missed_errors = inw(ioaddr+1);
  544. return &lp->stats;
  545. }
  546. /*
  547. * Set or clear the multicast filter for this adaptor.
  548. * num_addrs == -1 Promiscuous mode, receive all packets
  549. * num_addrs == 0 Normal mode, clear multicast list
  550. * num_addrs > 0 Multicast mode, receive normal and MC packets,
  551. * and do best-effort filtering.
  552. */
  553. static void
  554. set_multicast_list(struct net_device *dev)
  555. {
  556. short ioaddr = dev->base_addr;
  557. if (dev->flags&IFF_PROMISC)
  558. {
  559. /* Enable promiscuous mode */
  560. outw(MULTICAST|PROMISC, ioaddr);
  561. }
  562. else if((dev->flags&IFF_ALLMULTI) || dev->mc_count > HW_MAX_ADDRS)
  563. {
  564. /* Disable promiscuous mode, use normal mode. */
  565. hardware_set_filter(NULL);
  566. outw(MULTICAST, ioaddr);
  567. }
  568. else if(dev->mc_count)
  569. {
  570. /* Walk the address list, and load the filter */
  571. hardware_set_filter(dev->mc_list);
  572. outw(MULTICAST, ioaddr);
  573. }
  574. else
  575. outw(0, ioaddr);
  576. }
  577. #ifdef MODULE
  578. static struct net_device *this_device;
  579. static int io = 0x300;
  580. static int irq;
  581. static int dma;
  582. static int mem;
  583. MODULE_LICENSE("GPL");
  584. int init_module(void)
  585. {
  586. struct net_device *dev;
  587. int result;
  588. if (io == 0)
  589. printk(KERN_WARNING "%s: You shouldn't use auto-probing with insmod!\n",
  590. cardname);
  591. dev = alloc_etherdev(sizeof(struct net_local));
  592. if (!dev)
  593. return -ENOMEM;
  594. /* Copy the parameters from insmod into the device structure. */
  595. dev->base_addr = io;
  596. dev->irq = irq;
  597. dev->dma = dma;
  598. dev->mem_start = mem;
  599. if (do_netcard_probe(dev) == 0) {
  600. this_device = dev;
  601. return 0;
  602. }
  603. free_netdev(dev);
  604. return -ENXIO;
  605. }
  606. void
  607. cleanup_module(void)
  608. {
  609. unregister_netdev(this_device);
  610. cleanup_card(this_device);
  611. free_netdev(this_device);
  612. }
  613. #endif /* MODULE */