~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/net/3c527.c

Version: ~ [ 2.2.5 ] ~ [ 2.4.1 ] ~ [ 2.4.9 ] ~ [ 2.6.17.10 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* 3c527.c: 3Com Etherlink/MC32 driver for Linux
  2  *
  3  *      (c) Copyright 1998 Red Hat Software Inc
  4  *      Written by Alan Cox.
  5  *      Further debugging by Carl Drougge.
  6  *
  7  *      Based on skeleton.c written 1993-94 by Donald Becker and ne2.c
  8  *      (for the MCA stuff) written by Wim Dumon.
  9  *
 10  *      Thanks to 3Com for making this possible by providing me with the
 11  *      documentation.
 12  *
 13  *      This software may be used and distributed according to the terms
 14  *      of the GNU Public License, incorporated herein by reference.
 15  *
 16  */
 17 
 18 static const char *version =
 19         "3c527.c:v0.08 2000/02/22 Alan Cox (alan@redhat.com)\n";
 20 
 21 /**
 22  * DOC: Traps for the unwary
 23  *
 24  *      The diagram (Figure 1-1) and the POS summary disagree with the
 25  *      "Interrupt Level" section in the manual.
 26  *
 27  *      The documentation in places seems to miss things. In actual fact
 28  *      I've always eventually found everything is documented, it just
 29  *      requires careful study.
 30  *
 31  * DOC: Theory Of Operation
 32  *
 33  *      The 3com 3c527 is a 32bit MCA bus mastering adapter with a large
 34  *      amount of on board intelligence that housekeeps a somewhat dumber
 35  *      Intel NIC. For performance we want to keep the transmit queue deep
 36  *      as the card can transmit packets while fetching others from main
 37  *      memory by bus master DMA. Transmission and reception are driven by
 38  *      ring buffers. When updating the ring we are required to do some
 39  *      housekeeping work using the mailboxes and the command register.
 40  *
 41  *      The mailboxes provide a method for sending control requests to the
 42  *      card. The transmit mail box is used to update the transmit ring 
 43  *      pointers and the receive mail box to update the receive ring
 44  *      pointers. The exec mailbox allows a variety of commands to be
 45  *      executed. Each command must complete before the next is executed.
 46  *      Primarily we use the exec mailbox for controlling the multicast lists.
 47  *      We have to do a certain amount of interesting hoop jumping as the 
 48  *      multicast list changes can occur in interrupt state when the card
 49  *      has an exec command pending. We defer such events until the command
 50  *      completion interrupt.
 51  *
 52  *      The control register is used to pass status information. It tells us
 53  *      the transmit and receive status for packets and allows us to control
 54  *      the card operation mode. You must stop the card when emptying the
 55  *      receive ring, or you will race with the ring buffer and lose packets.
 56  */
 57 
 58 #include <linux/module.h>
 59 
 60 #include <linux/kernel.h>
 61 #include <linux/sched.h>
 62 #include <linux/types.h>
 63 #include <linux/fcntl.h>
 64 #include <linux/interrupt.h>
 65 #include <linux/ptrace.h>
 66 #include <linux/mca.h>
 67 #include <linux/ioport.h>
 68 #include <linux/in.h>
 69 #include <linux/malloc.h>
 70 #include <linux/string.h>
 71 #include <asm/system.h>
 72 #include <asm/bitops.h>
 73 #include <asm/io.h>
 74 #include <asm/dma.h>
 75 #include <linux/errno.h>
 76 #include <linux/init.h>
 77 
 78 #include <linux/netdevice.h>
 79 #include <linux/etherdevice.h>
 80 #include <linux/skbuff.h>
 81 
 82 #include "3c527.h"
 83 
 84 /*
 85  * The name of the card. Is used for messages and in the requests for
 86  * io regions, irqs and dma channels
 87  */
 88 static const char* cardname = "3c527";
 89 
 90 /* use 0 for production, 1 for verification, >2 for debug */
 91 #ifndef NET_DEBUG
 92 #define NET_DEBUG 2
 93 #endif
 94 static unsigned int mc32_debug = NET_DEBUG;
 95 
 96 /* The number of low I/O ports used by the ethercard. */
 97 #define NETCARD_IO_EXTENT       8
 98 
 99 
100 struct mc32_mailbox
101 {
102         u16     mbox __attribute((packed));
103         u16     data[1] __attribute((packed));
104 };
105 
106 /* Information that need to be kept for each board. */
107 
108 #define TX_RING_MAX     16      /* Typically the card supports 37 */
109 #define RX_RING_MAX     32      /*        "     "       "         */
110 
111 struct mc32_local 
112 {
113         struct net_device_stats net_stats;
114         int slot;
115         volatile struct mc32_mailbox *rx_box;
116         volatile struct mc32_mailbox *tx_box;
117         volatile struct mc32_mailbox *exec_box;
118         volatile u16 *stats;
119         u16 tx_chain;
120         u16 rx_chain;
121         u16 tx_len;
122         u16 rx_len;
123         u32 base;
124         u16 rx_halted;
125         u16 tx_halted;
126         u16 rx_pending;
127         u16 exec_pending;
128         u16 mc_reload_wait;     /* a multicast load request is pending */
129         atomic_t tx_count;              /* buffers left */
130         wait_queue_head_t event;
131         struct sk_buff *tx_skb[TX_RING_MAX];    /* Transmit ring */
132         u16 tx_skb_top;
133         u16 tx_skb_end;
134         struct sk_buff *rx_skb[RX_RING_MAX];    /* Receive ring */
135         void *rx_ptr[RX_RING_MAX];              /* Data pointers */
136         u32 mc_list_valid;                      /* True when the mclist is set */
137 };
138 
139 /* The station (ethernet) address prefix, used for a sanity check. */
140 #define SA_ADDR0 0x02
141 #define SA_ADDR1 0x60
142 #define SA_ADDR2 0xAC
143 
144 struct mca_adapters_t {
145         unsigned int    id;
146         char            *name;
147 };
148 
149 static struct mca_adapters_t mc32_adapters[] __initdata = {
150         { 0x0041, "3COM EtherLink MC/32" },
151         { 0x8EF5, "IBM High Performance Lan Adapter" },
152         { 0x0000, NULL }
153 };
154 
155 
156 /* Index to functions, as function prototypes. */
157 
158 extern int mc32_probe(struct net_device *dev);
159 
160 static int      mc32_probe1(struct net_device *dev, int ioaddr);
161 static int      mc32_open(struct net_device *dev);
162 static void     mc32_timeout(struct net_device *dev);
163 static int      mc32_send_packet(struct sk_buff *skb, struct net_device *dev);
164 static void     mc32_interrupt(int irq, void *dev_id, struct pt_regs *regs);
165 static int      mc32_close(struct net_device *dev);
166 static struct   net_device_stats *mc32_get_stats(struct net_device *dev);
167 static void     mc32_set_multicast_list(struct net_device *dev);
168 static void     mc32_reset_multicast_list(struct net_device *dev);
169 
170 
171 /**
172  * mc32_probe:
173  * @dev: device to probe
174  *
175  * Because MCA bus is a real bus and we can scan for cards we could do a
176  * single scan for all boards here. Right now we use the passed in device
177  * structure and scan for only one board. This needs fixing for modules
178  * in paticular.
179  */
180 
181 int __init mc32_probe(struct net_device *dev)
182 {
183         static int current_mca_slot = -1;
184         int i;
185         int adapter_found = 0;
186 
187         SET_MODULE_OWNER(dev);
188 
189         /* Do not check any supplied i/o locations. 
190            POS registers usually don't fail :) */
191 
192         /* MCA cards have POS registers.  
193            Autodetecting MCA cards is extremely simple. 
194            Just search for the card. */
195 
196         for(i = 0; (mc32_adapters[i].name != NULL) && !adapter_found; i++) {
197                 current_mca_slot = 
198                         mca_find_unused_adapter(mc32_adapters[i].id, 0);
199 
200                 if((current_mca_slot != MCA_NOTFOUND) && !adapter_found) {
201                         if(!mc32_probe1(dev, current_mca_slot))
202                         {
203                                 mca_set_adapter_name(current_mca_slot, 
204                                                 mc32_adapters[i].name);
205                                 mca_mark_as_used(current_mca_slot);
206                                 return 0;
207                         }
208                         
209                 }
210         }
211         return -ENODEV;
212 }
213 
214 /**
215  * mc32_probe1:
216  * @dev:  Device structure to fill in
217  * @slot: The MCA bus slot being used by this card
218  *
219  * Decode the slot data and configure the card structures. Having done this we
220  * can reset the card and configure it. The card does a full self test cycle
221  * in firmware so we have to wait for it to return and post us either a 
222  * failure case or some addresses we use to find the board internals.
223  */
224  
225 static int __init mc32_probe1(struct net_device *dev, int slot)
226 {
227         static unsigned version_printed = 0;
228         int i;
229         u8 POS;
230         u32 base;
231         struct mc32_local *lp;
232         static u16 mca_io_bases[]={
233                 0x7280,0x7290,
234                 0x7680,0x7690,
235                 0x7A80,0x7A90,
236                 0x7E80,0x7E90
237         };
238         static u32 mca_mem_bases[]={
239                 0x00C0000,
240                 0x00C4000,
241                 0x00C8000,
242                 0x00CC000,
243                 0x00D0000,
244                 0x00D4000,
245                 0x00D8000,
246                 0x00DC000
247         };
248         static char *failures[]={
249                 "Processor instruction",
250                 "Processor data bus",
251                 "Processor data bus",
252                 "Processor data bus",
253                 "Adapter bus",
254                 "ROM checksum",
255                 "Base RAM",
256                 "Extended RAM",
257                 "82586 internal loopback",
258                 "82586 initialisation failure",
259                 "Adapter list configuration error"
260         };
261         
262         /* Time to play MCA games */
263 
264         if (mc32_debug  &&  version_printed++ == 0)
265                 printk(KERN_DEBUG "%s", version);
266 
267         printk(KERN_INFO "%s: %s found in slot %d:", dev->name, cardname, slot);
268 
269         POS = mca_read_stored_pos(slot, 2);
270         
271         if(!(POS&1))
272         {
273                 printk(" disabled.\n");
274                 return -ENODEV;
275         }
276 
277         /* Fill in the 'dev' fields. */
278         dev->base_addr = mca_io_bases[(POS>>1)&7];
279         dev->mem_start = mca_mem_bases[(POS>>4)&7];
280         
281         POS = mca_read_stored_pos(slot, 4);
282         if(!(POS&1))
283         {
284                 printk("memory window disabled.\n");
285                 return -ENODEV;
286         }
287 
288         POS = mca_read_stored_pos(slot, 5);
289         
290         i=(POS>>4)&3;
291         if(i==3)
292         {
293                 printk("invalid memory window.\n");
294                 return -ENODEV;
295         }
296         
297         i*=16384;
298         i+=16384;
299         
300         dev->mem_end=dev->mem_start + i;
301         
302         dev->irq = ((POS>>2)&3)+9;
303         
304         printk("io 0x%3lX irq %d mem 0x%lX (%dK)\n",
305                 dev->base_addr, dev->irq, dev->mem_start, i/1024);
306         
307         
308         /* We ought to set the cache line size here.. */
309         
310         
311         /*
312          *      Go PROM browsing
313          */
314          
315         printk("%s: Address ", dev->name);
316          
317         /* Retrieve and print the ethernet address. */
318         for (i = 0; i < 6; i++)
319         {
320                 mca_write_pos(slot, 6, i+12);
321                 mca_write_pos(slot, 7, 0);
322         
323                 printk(" %2.2x", dev->dev_addr[i] = mca_read_pos(slot,3));
324         }
325 
326         mca_write_pos(slot, 6, 0);
327         mca_write_pos(slot, 7, 0);
328 
329         POS = mca_read_stored_pos(slot, 4);
330         
331         if(POS&2)
332                 printk(" : BNC port selected.\n");
333         else 
334                 printk(" : AUI port selected.\n");
335                 
336         POS=inb(dev->base_addr+HOST_CTRL);
337         POS|=HOST_CTRL_ATTN|HOST_CTRL_RESET;
338         POS&=~HOST_CTRL_INTE;
339         outb(POS, dev->base_addr+HOST_CTRL);
340         /* Reset adapter */
341         udelay(100);
342         /* Reset off */
343         POS&=~(HOST_CTRL_ATTN|HOST_CTRL_RESET);
344         outb(POS, dev->base_addr+HOST_CTRL);
345         
346         udelay(300);
347         
348         /*
349          *      Grab the IRQ
350          */
351 
352         i = request_irq(dev->irq, &mc32_interrupt, 0, dev->name, dev);
353         if (i) {
354                 printk("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
355                 return i;
356         }
357 
358         /* Initialize the device structure. */
359         dev->priv = kmalloc(sizeof(struct mc32_local), GFP_KERNEL);
360         if (dev->priv == NULL)
361         {
362                 free_irq(dev->irq, dev);
363                 return -ENOMEM;
364         }
365 
366         memset(dev->priv, 0, sizeof(struct mc32_local));
367         lp = dev->priv;
368         lp->slot = slot;
369 
370         i=0;
371 
372         base = inb(dev->base_addr);
373         
374         while(base==0xFF)
375         {
376                 i++;
377                 if(i==1000)
378                 {
379                         printk("%s: failed to boot adapter.\n", dev->name);
380                         free_irq(dev->irq, dev);
381                         return -ENODEV;
382                 }
383                 udelay(1000);
384                 if(inb(dev->base_addr+2)&(1<<5))
385                         base = inb(dev->base_addr);
386         }
387 
388         if(base>0)
389         {
390                 if(base < 0x0C)
391                         printk("%s: %s%s.\n", dev->name, failures[base-1],
392                                 base<0x0A?" test failure":"");
393                 else
394                         printk("%s: unknown failure %d.\n", dev->name, base);
395                 free_irq(dev->irq, dev);
396                 return -ENODEV;
397         }
398         
399         base=0;
400         for(i=0;i<4;i++)
401         {
402                 int n=0;
403         
404                 while(!(inb(dev->base_addr+2)&(1<<5)))
405                 {
406                         n++;
407                         udelay(50);
408                         if(n>100)
409                         {
410                                 printk(KERN_ERR "%s: mailbox read fail (%d).\n", dev->name, i);
411                                 free_irq(dev->irq, dev);
412                                 return -ENODEV;
413                         }
414                 }
415 
416                 base|=(inb(dev->base_addr)<<(8*i));
417         }
418         
419         lp->exec_box=bus_to_virt(dev->mem_start+base);
420         
421         base=lp->exec_box->data[1]<<16|lp->exec_box->data[0];
422         
423         lp->base = dev->mem_start+base;
424         
425         lp->rx_box=bus_to_virt(lp->base + lp->exec_box->data[2]);
426         lp->tx_box=bus_to_virt(lp->base + lp->exec_box->data[3]);
427         
428         lp->stats = bus_to_virt(lp->base + lp->exec_box->data[5]);
429 
430         /*
431          *      Descriptor chains (card relative)
432          */
433          
434         lp->tx_chain            = lp->exec_box->data[8];
435         lp->rx_chain            = lp->exec_box->data[10];
436         lp->tx_len              = lp->exec_box->data[9];
437         lp->rx_len              = lp->exec_box->data[11];
438         init_waitqueue_head(&lp->event);
439         
440         printk("%s: %d RX buffers, %d TX buffers. Base of 0x%08X.\n",
441                 dev->name, lp->rx_len, lp->tx_len, lp->base);
442                 
443         if(lp->tx_len > TX_RING_MAX)
444                 lp->tx_len = TX_RING_MAX;
445         
446         dev->open               = mc32_open;
447         dev->stop               = mc32_close;
448         dev->hard_start_xmit    = mc32_send_packet;
449         dev->get_stats          = mc32_get_stats;
450         dev->set_multicast_list = mc32_set_multicast_list;
451         dev->tx_timeout         = mc32_timeout;
452         dev->watchdog_timeo     = HZ*5; /* Board does all the work */
453         
454         lp->rx_halted           = 1;
455         lp->tx_halted           = 1;
456         lp->rx_pending          = 0;
457 
458         /* Fill in the fields of the device structure with ethernet values. */
459         ether_setup(dev);
460         return 0;
461 }
462 
463 
464 /**
465  *      mc32_ring_poll:
466  *      @dev:   The device to wait for
467  *      
468  *      Wait until a command we issues to the control register is completed.
469  *      This actually takes very little time at all, which is fortunate as
470  *      we often have to busy wait it.
471  */
472  
473 static void mc32_ring_poll(struct net_device *dev)
474 {
475         int ioaddr = dev->base_addr;
476         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
477 }
478 
479 
480 
481 /**
482  *      mc32_command_nowait:
483  *      @dev: The 3c527 to issue the command to
484  *      @cmd: The command word to write to the mailbox
485  *      @data: A data block if the command expects one
486  *      @len: Length of the data block
487  *
488  *      Send a command from interrupt state. If there is a command currently
489  *      being executed then we return an error of -1. It simply isnt viable
490  *      to wait around as commands may be slow. Providing we get in then
491  *      we send the command and busy wait for the board to acknowledge that
492  *      a command request is pending. We do not wait for the command to 
493  *      complete, just for the card to admit to noticing it.  
494  */
495 
496 static int mc32_command_nowait(struct net_device *dev, u16 cmd, void *data, int len)
497 {
498         struct mc32_local *lp = (struct mc32_local *)dev->priv;
499         int ioaddr = dev->base_addr;
500         
501         if(lp->exec_pending)
502                 return -1;
503                 
504         lp->exec_pending=3;
505         lp->exec_box->mbox=0;
506         lp->exec_box->mbox=cmd;
507         memcpy((void *)lp->exec_box->data, data, len);
508         barrier();      /* the memcpy forgot the volatile so be sure */
509 
510         /* Send the command */
511         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
512         outb(1<<6, ioaddr+HOST_CMD);    
513         return 0;
514 }
515 
516 
517 /**
518  *      mc32_command: 
519  *      @dev: The 3c527 card to issue the command to
520  *      @cmd: The command word to write to the mailbox
521  *      @data: A data block if the command expects one
522  *      @len: Length of the data block
523  *
524  *      Sends exec commands in a user context. This permits us to wait around
525  *      for the replies and also to wait for the command buffer to complete
526  *      from a previous command before we execute our command. After our 
527  *      command completes we will complete any pending multicast reload
528  *      we blocked off by hogging the exec buffer.
529  *
530  *      You feed the card a command, you wait, it interrupts you get a 
531  *      reply. All well and good. The complication arises because you use
532  *      commands for filter list changes which come in at bh level from things
533  *      like IPV6 group stuff.
534  *
535  *      We have a simple state machine
536  *
537  *      0       - nothing issued
538  *
539  *      1       - command issued, wait reply
540  *
541  *      2       - reply waiting - reader then goes to state 0
542  *
543  *      3       - command issued, trash reply. In which case the irq
544  *                takes it back to state 0
545  *
546  *      Send command and block for results. On completion spot and reissue
547  *      multicasts
548  */
549   
550 static int mc32_command(struct net_device *dev, u16 cmd, void *data, int len)
551 {
552         struct mc32_local *lp = (struct mc32_local *)dev->priv;
553         int ioaddr = dev->base_addr;
554         unsigned long flags;
555         int ret = 0;
556         
557         /*
558          *      Wait for a command
559          */
560          
561         save_flags(flags);
562         cli();
563          
564         while(lp->exec_pending)
565                 sleep_on(&lp->event);
566                 
567         /*
568          *      Issue mine
569          */
570 
571         lp->exec_pending=1;
572         
573         restore_flags(flags);
574         
575         lp->exec_box->mbox=0;
576         lp->exec_box->mbox=cmd;
577         memcpy((void *)lp->exec_box->data, data, len);
578         barrier();      /* the memcpy forgot the volatile so be sure */
579 
580         /* Send the command */
581         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
582         outb(1<<6, ioaddr+HOST_CMD);    
583         
584         save_flags(flags);
585         cli();
586         while(lp->exec_pending!=2)
587                 sleep_on(&lp->event);
588         lp->exec_pending=0;
589         restore_flags(flags);
590         
591          
592         if(lp->exec_box->data[0]&(1<<13))
593                 ret = -1;
594         /*
595          *      A multicast set got blocked - do it now
596          */
597                 
598         if(lp->mc_reload_wait)
599                 mc32_reset_multicast_list(dev);
600 
601         return ret;
602 }
603 
604 
605 /**
606  *      mc32_rx_abort:
607  *      @dev: 3c527 to abort
608  *
609  *      Peforms a receive abort sequence on the card. In fact after some
610  *      experimenting we now simply tell the card to suspend reception. When
611  *      issuing aborts occasionally odd things happened.
612  */
613  
614 static void mc32_rx_abort(struct net_device *dev)
615 {
616         struct mc32_local *lp = (struct mc32_local *)dev->priv;
617         int ioaddr = dev->base_addr;
618 
619         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
620         
621         lp->rx_box->mbox=0;
622         outb(3<<3, ioaddr+HOST_CMD);    /* Suspend reception */
623 }
624 
625  
626 /**
627  *      mc32_rx_begin:
628  *      @dev: 3c527 to enable
629  *
630  *      We wait for any pending command to complete and then issue 
631  *      a start reception command to the board itself. At this point 
632  *      receive handling continues as it was before.
633  */
634  
635 static void mc32_rx_begin(struct net_device *dev)
636 {
637         struct mc32_local *lp = (struct mc32_local *)dev->priv;
638         int ioaddr = dev->base_addr;
639         
640         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
641         
642         lp->rx_box->mbox=0;
643         outb(1<<3, ioaddr+HOST_CMD);    /* GO */
644         mc32_ring_poll(dev);    
645         
646         lp->rx_halted=0;
647         lp->rx_pending=0;
648 }
649 
650 /**
651  *      mc32_tx_abort:
652  *      @dev: 3c527 to abort
653  *
654  *      Peforms a receive abort sequence on the card. In fact after some
655  *      experimenting we now simply tell the card to suspend transmits . When
656  *      issuing aborts occasionally odd things happened. In theory we want
657  *      an abort to be sure we can recycle our buffers. As it happens we
658  *      just have to be careful to shut the card down on close, and
659  *      boot it carefully from scratch on setup.
660  */
661  
662 static void mc32_tx_abort(struct net_device *dev)
663 {
664         struct mc32_local *lp = (struct mc32_local *)dev->priv;
665         int ioaddr = dev->base_addr;
666         
667         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
668         
669         lp->tx_box->mbox=0;
670         outb(3, ioaddr+HOST_CMD);       /* Suspend */
671         
672         /* Ring empty */
673         
674         atomic_set(&lp->tx_count, lp->tx_len);
675         
676         /* Flush */
677         if(lp->tx_skb_top!=lp->tx_skb_end)
678         {
679                 int i;
680                 if(lp->tx_skb_top<=lp->tx_skb_end)
681                 {
682                         for(i=lp->tx_skb_top;i<lp->tx_skb_end;i++)
683                         {
684                                 dev_kfree_skb(lp->tx_skb[i]);
685                                 lp->tx_skb[i]=NULL;
686                         }
687                 }
688                 else
689                 {
690                         for(i=lp->tx_skb_end;i<TX_RING_MAX;i++)
691                         {
692                                 dev_kfree_skb(lp->tx_skb[i]);
693                                 lp->tx_skb[i]=NULL;
694                         }
695                         for(i=0;i<lp->tx_skb_top;i++)
696                         {
697                                 dev_kfree_skb(lp->tx_skb[i]);
698                                 lp->tx_skb[i]=NULL;
699                         }
700                 }
701         }
702         lp->tx_skb_top=lp->tx_skb_end=0;
703 }
704 
705 /**
706  *      mc32_tx_begin:
707  *      @dev: 3c527 to enable
708  *
709  *      We wait for any pending command to complete and then issue 
710  *      a start transmit command to the board itself. At this point 
711  *      transmit handling continues as it was before. The ring must
712  *      be setup before you do this and must have an end marker in it.
713  *      It turns out we can avoid issuing this specific command when
714  *      doing our setup so we avoid it.
715  */
716  
717 static void mc32_tx_begin(struct net_device *dev)
718 {
719         struct mc32_local *lp = (struct mc32_local *)dev->priv;
720         int ioaddr = dev->base_addr;
721         
722         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
723         
724         lp->tx_box->mbox=0;
725 #if 0   
726         outb(5, ioaddr+HOST_CMD);       /* GO */
727         printk("TX=>5\n");
728         mc32_ring_poll(dev);    
729         if(lp->tx_box->mbox&(1<<13))
730                 printk("TX begin error!\n");
731 #endif          
732         lp->tx_halted=0;
733 }
734 
735         
736 /**
737  *      mc32_load_rx_ring:
738  *      @dev: 3c527 to build the ring for
739  *
740  *      The card setups up the receive ring for us. We are required to
741  *      use the ring it provides although we can change the size of the
742  *      ring.
743  *
744  *      We allocate an sk_buff for each ring entry in turn and set the entry
745  *      up for a single non s/g buffer. The first buffer we mark with the
746  *      end marker bits. Finally we clear the rx mailbox.
747  */
748  
749 static int mc32_load_rx_ring(struct net_device *dev)
750 {
751         struct mc32_local *lp = (struct mc32_local *)dev->priv;
752         int i;
753         u16 base;
754         volatile struct skb_header *p;
755         
756         base = lp->rx_box->data[0];
757         
758         /* Fix me - should use card size - also fix flush ! */ 
759 
760         for(i=0;i<RX_RING_MAX;i++)
761         {
762                 lp->rx_skb[i]=alloc_skb(1532, GFP_KERNEL);
763                 if(lp->rx_skb[i]==NULL)
764                 {
765                         for(;i>=0;i--)
766                                 kfree_skb(lp->rx_skb[i]);
767                         return -ENOBUFS;
768                 }
769                 lp->rx_ptr[i]=lp->rx_skb[i]->data+18;
770                 
771                 p=bus_to_virt(lp->base+base);
772                 p->control=0;
773                 p->data = virt_to_bus(lp->rx_ptr[i]);
774                 p->status=0;
775                 p->length = 1532;
776                 base = p->next;
777         }
778         p->control = (1<<6);
779         lp->rx_box->mbox = 0;
780         return 0;
781 }       
782 
783 /**
784  *      mc32_flush_rx_ring:
785  *      @lp: Local data of 3c527 to flush the rx ring of
786  *
787  *      Free the buffer for each ring slot. Because of the receive 
788  *      algorithm we use the ring will always be loaded will a full set
789  *      of buffers.
790  */
791 
792 static void mc32_flush_rx_ring(struct mc32_local *lp)
793 {
794         int i;
795         for(i=0;i<RX_RING_MAX;i++)
796                 kfree_skb(lp->rx_skb[i]);
797 }
798 
799 /**
800  *      mc32_flush_tx_ring:
801  *      @lp: Local data of 3c527 to flush the tx ring of
802  *
803  *      We have to consider two cases here. We want to free the pending
804  *      buffers only. If the ring buffer head is past the start then the
805  *      ring segment we wish to free wraps through zero.
806  */
807 
808 static void mc32_flush_tx_ring(struct mc32_local *lp)
809 {
810         int i;
811         
812         if(lp->tx_skb_top <= lp->tx_skb_end)
813         {
814                 for(i=lp->tx_skb_top;i<lp->tx_skb_end;i++)
815                         dev_kfree_skb(lp->tx_skb[i]);
816         }
817         else
818         {
819                 for(i=0;i<lp->tx_skb_end;i++)
820                         dev_kfree_skb(lp->tx_skb[i]);
821                 for(i=lp->tx_skb_top;i<TX_RING_MAX;i++)
822                         dev_kfree_skb(lp->tx_skb[i]);
823         }
824 }
825         
826 /**
827  *      mc32_open
828  *      @dev: device to open
829  *
830  *      The user is trying to bring the card into ready state. This requires
831  *      a brief dialogue with the card. Firstly we enable interrupts and then
832  *      'indications'. Without these enabled the card doesn't bother telling
833  *      us what it has done. This had me puzzled for a week.
834  *
835  *      We then load the network address and multicast filters. Turn on the
836  *      workaround mode. This works around a bug in the 82586 - it asks the
837  *      firmware to do so. It has a performance hit but is needed on busy
838  *      [read most] lans. We load the ring with buffers then we kick it
839  *      all off.
840  */
841 
842 static int mc32_open(struct net_device *dev)
843 {
844         int ioaddr = dev->base_addr;
845         u16 zero_word=0;
846         u8 one=1;
847         u8 regs;
848         
849         /*
850          *      Interrupts enabled
851          */
852 
853         regs=inb(ioaddr+HOST_CTRL);
854         regs|=HOST_CTRL_INTE;
855         outb(regs, ioaddr+HOST_CTRL);
856         
857 
858         /*
859          *      Send the indications on command
860          */
861 
862         mc32_command(dev, 4, &one, 2);
863 
864                 
865         /*
866          *      Send the command sequence "abort, resume" for RX and TX.
867          *      The abort cleans up the buffer chains if needed.
868          */
869 
870         mc32_rx_abort(dev);
871         mc32_tx_abort(dev);
872         
873         /* Set Network Address */
874         mc32_command(dev, 1, dev->dev_addr, 6);
875         
876         /* Set the filters */
877         mc32_set_multicast_list(dev);
878         
879         /* Issue the 82586 workaround command - this is for "busy lans",
880            but basically means for all lans now days - has a performance
881            cost but best set */
882            
883         mc32_command(dev, 0x0D, &zero_word, 2); /* 82586 bug workaround on */
884         
885         /* Load the ring we just initialised */
886         
887         if(mc32_load_rx_ring(dev))
888         {
889                 mc32_close(dev);
890                 return -ENOBUFS;
891         }
892         
893         /* And the resume command goes last */
894         
895         mc32_rx_begin(dev);
896         mc32_tx_begin(dev);
897 
898         netif_start_queue(dev); 
899         return 0;
900 }
901 
902 /**
903  *      mc32_timeout:
904  *      @dev: 3c527 that timed out
905  *
906  *      Handle a timeout on transmit from the 3c527. This normally means
907  *      bad things as the hardware handles cable timeouts and mess for
908  *      us.
909  *
910  */
911 
912 static void mc32_timeout(struct net_device *dev)
913 {
914         printk(KERN_WARNING "%s: transmit timed out?\n", dev->name);
915         /* Try to restart the adaptor. */
916         netif_wake_queue(dev);
917 }
918  
919 /**
920  *      mc32_send_packet:
921  *      @skb: buffer to transmit
922  *      @dev: 3c527 to send it out of
923  *
924  *      Transmit a buffer. This normally means throwing the buffer onto
925  *      the transmit queue as the queue is quite large. If the queue is
926  *      full then we set tx_busy and return. Once the interrupt handler
927  *      gets messages telling it to reclaim transmit queue entries we will
928  *      clear tx_busy and the kernel will start calling this again.
929  *
930  *      We use cli rather than spinlocks. Since I have no access to an SMP
931  *      MCA machine I don't plan to change it. It is probably the top 
932  *      performance hit for this driver on SMP however.
933  */
934  
935 static int mc32_send_packet(struct sk_buff *skb, struct net_device *dev)
936 {
937         struct mc32_local *lp = (struct mc32_local *)dev->priv;
938         int ioaddr = dev->base_addr;
939         unsigned long flags;
940                 
941         u16 tx_head;
942         volatile struct skb_header *p, *np;
943 
944         netif_stop_queue(dev);
945         
946         save_flags(flags);
947         cli();
948                 
949         if(atomic_read(&lp->tx_count)==0)
950         {
951                 restore_flags(flags);
952                 return 1;
953         }
954 
955         tx_head = lp->tx_box->data[0];
956         atomic_dec(&lp->tx_count);
957         /* We will need this to flush the buffer out */
958         
959         lp->tx_skb[lp->tx_skb_end] = skb;
960         lp->tx_skb_end++;
961         lp->tx_skb_end&=(TX_RING_MAX-1);
962 
963         /* TX suspend - shouldnt be needed but apparently is.
964            This is a research item ... */
965                    
966         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
967         lp->tx_box->mbox=0;
968         outb(3, ioaddr+HOST_CMD);
969         
970         /* Transmit now stopped */
971 
972         /* P is the last sending/sent buffer as a pointer */
973         p=(struct skb_header *)bus_to_virt(lp->base+tx_head);
974         
975         /* NP is the buffer we will be loading */
976         np=(struct skb_header *)bus_to_virt(lp->base+p->next);
977                 
978         np->control     |= (1<<6);      /* EOL */
979         wmb();
980                 
981         np->length      = skb->len;
982                 
983         if(np->length < 60)
984                 np->length = 60;
985                         
986         np->data        = virt_to_bus(skb->data);
987         np->status      = 0;
988         np->control     = (1<<7)|(1<<6);        /* EOP EOL */
989         wmb();
990                 
991         p->status       = 0;
992         p->control      &= ~(1<<6);
993         
994         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
995         lp->tx_box->mbox=0;
996         outb(5, ioaddr+HOST_CMD);               /* Restart TX */
997         restore_flags(flags);
998         
999         netif_wake_queue(dev);
1000         return 0;
1001 }
1002 
1003 /**
1004  *      mc32_update_stats:
1005  *      @dev: 3c527 to service
1006  *
1007  *      When the board signals us that its statistics need attention we
1008  *      should query the table and clear it. In actual fact we currently
1009  *      track all our statistics in software and I haven't implemented it yet.
1010  */
1011  
1012 static void mc32_update_stats(struct net_device *dev)
1013 {
1014 }
1015 
1016 /**
1017  *      mc32_rx_ring:
1018  *      @dev: 3c527 that needs its receive ring processing
1019  *
1020  *      We have received one or more indications from the card that
1021  *      a receive has completed. The ring buffer thus contains dirty
1022  *      entries. Firstly we tell the card to stop receiving, then We walk 
1023  *      the ring from the first filled entry, which is pointed to by the 
1024  *      card rx mailbox and for each completed packet we will either copy 
1025  *      it and pass it up the stack or if the packet is near MTU sized we 
1026  *      allocate another buffer and flip the old one up the stack.
1027  *
1028  *      We must succeed in keeping a buffer on the ring. If neccessary we
1029  *      will toss a received packet rather than lose a ring entry. Once the
1030  *      first packet that is unused is found we reload the mailbox with the
1031  *      buffer so that the card knows it can use the buffers again. Finally
1032  *      we set it receiving again. 
1033  *
1034  *      We must stop reception during the ring walk. I thought it would be
1035  *      neat to avoid it by clever tricks, but it turns out the event order
1036  *      on the card means you have to play by the manual.
1037  */
1038  
1039 static void mc32_rx_ring(struct net_device *dev)
1040 {
1041         struct mc32_local *lp=dev->priv;
1042         int ioaddr = dev->base_addr;
1043         int x=0;
1044         volatile struct skb_header *p;
1045         u16 base;
1046         u16 top;
1047 
1048         /* Halt RX before walking the ring */
1049         
1050         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
1051         outb(3<<3, ioaddr+HOST_CMD);
1052         while(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR);
1053         
1054         top = base = lp->rx_box->data[0];
1055         do
1056         {
1057                 p=(struct skb_header *)bus_to_virt(base+lp->base);
1058                 if(!(p->status & (1<<7)))
1059                         break;
1060                 if(p->status & (1<<6))
1061                 {
1062                         u16 length = p->length;
1063                         struct sk_buff *skb=dev_alloc_skb(length+2);
1064                         if(skb!=NULL)
1065                         {
1066                                 skb_reserve(skb,2);
1067                                 /*printk("Frame at %p\n", bus_to_virt(p->data)); */
1068                                 memcpy(skb_put(skb, length),
1069                                         bus_to_virt(p->data), length);
1070                                 skb->protocol=eth_type_trans(skb,dev);
1071                                 skb->dev=dev;
1072                                 lp->net_stats.rx_packets++;
1073                                 lp->net_stats.rx_bytes+=skb->len;
1074                                 netif_rx(skb);
1075                         }
1076                         else
1077                                 lp->net_stats.rx_dropped++;
1078                 }
1079                 else
1080                 {
1081                         lp->net_stats.rx_errors++;
1082                         switch(p->status&0x0F)
1083                         {
1084                                 case 1:
1085                                         lp->net_stats.rx_crc_errors++;break;
1086                                 case 2:
1087                                         lp->net_stats.rx_fifo_errors++;break;
1088                                 case 3:
1089                                         lp->net_stats.rx_frame_errors++;break;
1090                                 case 4:
1091                                         lp->net_stats.rx_missed_errors++;break;
1092                                 case 5:
1093                                         lp->net_stats.rx_length_errors++;break;
1094                         }
1095                 }
1096                 p->length = 1532;
1097                 p->control &= ~(1<<6);
1098                 p->status = 0;
1099                 base = p->next;
1100         }
1101         while(x++<48);
1102 
1103         /*
1104          *      Restart ring processing
1105          */     
1106         
1107         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
1108         lp->rx_box->mbox=0;
1109         lp->rx_box->data[0] = top;
1110         outb(1<<3, ioaddr+HOST_CMD);    
1111         lp->rx_halted=0;
1112 }
1113 
1114 
1115 /**
1116  *      mc32_interrupt:
1117  *      @irq: Interrupt number
1118  *      @dev_id: 3c527 that requires servicing
1119  *      @regs: Registers (unused)
1120  *
1121  *      The 3c527 interrupts us for four reasons. The command register 
1122  *      contains the message it wishes to send us packed into a single
1123  *      byte field. We keep reading status entries until we have processed
1124  *      all the transmit and control items, but simply count receive
1125  *      reports. When the receive reports are in we can call the mc32_rx_ring
1126  *      and empty the ring. This saves the overhead of multiple command requests
1127  */
1128  
1129 static void mc32_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1130 {
1131         struct net_device *dev = dev_id;
1132         struct mc32_local *lp;
1133         int ioaddr, status, boguscount = 0;
1134         
1135         if (dev == NULL) {
1136                 printk(KERN_WARNING "%s: irq %d for unknown device.\n", cardname, irq);
1137                 return;
1138         }
1139         ioaddr = dev->base_addr;
1140         lp = (struct mc32_local *)dev->priv;
1141 
1142         /* See whats cooking */
1143         
1144         while((inb(ioaddr+2)&(1<<5)) && boguscount++<2000)
1145         {
1146                 status=inb(ioaddr+HOST_CMD);
1147 
1148 #ifdef DEBUG_IRQ                
1149                 printk("Status TX%d RX%d EX%d OV%d\n",
1150                         (status&7), (status>>3)&7, (status>>6)&1,
1151                         (status>>7)&1);
1152 #endif
1153                         
1154                 switch(status&7)
1155                 {
1156                         case 0:
1157                                 break;
1158                         case 6: /* TX fail */
1159                                 lp->net_stats.tx_errors++;
1160                         case 2: /* TX ok */
1161                                 lp->net_stats.tx_packets++;
1162                                 /* Packets are sent in order - this is
1163                                    basically a FIFO queue of buffers matching
1164                                    the card ring */
1165                                 lp->net_stats.tx_bytes+=lp->tx_skb[lp->tx_skb_top]->len;
1166                                 dev_kfree_skb_irq(lp->tx_skb[lp->tx_skb_top]);
1167                                 lp->tx_skb[lp->tx_skb_top]=NULL;
1168                                 lp->tx_skb_top++;
1169                                 lp->tx_skb_top&=(TX_RING_MAX-1);
1170                                 atomic_inc(&lp->tx_count);
1171                                 netif_wake_queue(dev);
1172                                 break;
1173                         case 3: /* Halt */
1174                         case 4: /* Abort */
1175                                 lp->tx_halted=1;
1176                                 wake_up(&lp->event);
1177                                 break;
1178                         case 5:
1179                                 lp->tx_halted=0;
1180                                 wake_up(&lp->event);
1181                                 break;
1182                         default:
1183                                 printk("%s: strange tx ack %d\n", 
1184                                         dev->name, status&7);
1185                 }
1186                 status>>=3;
1187                 switch(status&7)
1188                 {
1189                         case 0:
1190                                 break;
1191                         case 2: /* RX */
1192                                 lp->rx_pending=1;
1193                                 if(!lp->rx_halted)
1194                                 {
1195                                         /*
1196                                          *      Halt ring receive
1197                                          */
1198                                         while(!(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR));
1199                                         outb(3<<3, ioaddr+HOST_CMD);
1200                                 }
1201                                 break;
1202                         case 3:
1203                         case 4:
1204                                 lp->rx_halted=1;
1205                                 wake_up(&lp->event);
1206                                 break;
1207                         case 5:
1208                                 lp->rx_halted=0;
1209                                 wake_up(&lp->event);
1210                                 break;
1211                         case 6:
1212                                 /* Out of RX buffers stat */
1213                                 lp->net_stats.rx_dropped++;
1214                                 lp->rx_pending=1;
1215                                 /* Must restart */
1216                                 lp->rx_halted=1;
1217                                 break;
1218                         default:
1219                                 printk("%s: strange rx ack %d\n", 
1220                                         dev->name, status&7);
1221                         
1222                 }
1223                 status>>=3;
1224                 if(status&1)
1225                 {
1226                         /* 0=no 1=yes 2=replied, get cmd, 3 = wait reply & dump it */
1227                         if(lp->exec_pending!=3)
1228                                 lp->exec_pending=2;
1229                         else
1230                                 lp->exec_pending=0;
1231                         wake_up(&lp->event);
1232                 }
1233                 if(status&2)
1234                 {
1235                         /*
1236                          *      Update the stats as soon as
1237                          *      we have it flagged and can 
1238                          *      send an immediate reply (CRR set)
1239                          */
1240                          
1241                         if(inb(ioaddr+HOST_STATUS)&HOST_STATUS_CRR)
1242                         {
1243                                 mc32_update_stats(dev);
1244                                 outb(0, ioaddr+HOST_CMD);
1245                         }
1246                 }
1247         }
1248         
1249         /*
1250          *      Process and restart the receive ring. This has some state
1251          *      as we must halt the ring to process it and halting the ring
1252          *      might not occur in the same IRQ handling loop as we issue
1253          *      the halt.
1254          */
1255          
1256         if(lp->rx_pending && lp->rx_halted)
1257         {
1258                 mc32_rx_ring(dev);
1259                 lp->rx_pending = 0;
1260         }
1261         return;
1262 }
1263 
1264 
1265 /**
1266  *      mc32_close:
1267  *      @dev: 3c527 card to shut down
1268  *
1269  *      The 3c527 is a bus mastering device. We must be careful how we
1270  *      shut it down. It may also be running shared interrupt so we have
1271  *      to be sure to silence it properly
1272  *
1273  *      We abort any receive and transmits going on and then wait until
1274  *      any pending exec commands have completed in other code threads.
1275  *      In theory we can't get here while that is true, in practice I am
1276  *      paranoid
1277  *
1278  *      We turn off the interrupt enable for the board to be sure it can't
1279  *      intefere with other devices.
1280  */
1281  
1282 static int mc32_close(struct net_device *dev)
1283 {
1284         struct mc32_local *lp = (struct mc32_local *)dev->priv;
1285         int ioaddr = dev->base_addr;
1286         u8 regs;
1287         u16 one=1;
1288 
1289         netif_stop_queue(dev);
1290         
1291         /*
1292          *      Send the indications on command (handy debug check)
1293          */
1294 
1295         mc32_command(dev, 4, &one, 2);
1296 
1297         /* Abort RX and Abort TX */
1298         
1299         mc32_rx_abort(dev);     
1300         mc32_tx_abort(dev);
1301         
1302         /* Catch any waiting commands */
1303         
1304         while(lp->exec_pending==1)
1305                 sleep_on(&lp->event);
1306                 
1307         /* Ok the card is now stopping */       
1308         
1309         regs=inb(ioaddr+HOST_CTRL);
1310         regs&=~HOST_CTRL_INTE;
1311         outb(regs, ioaddr+HOST_CTRL);
1312 
1313         mc32_flush_rx_ring(lp);
1314         mc32_flush_tx_ring(lp);
1315         
1316         /* Update the statistics here. */
1317 
1318         return 0;
1319 
1320 }
1321 
1322 /**
1323  *      mc32_get_stats:
1324  *      @dev: The 3c527 card to handle
1325  *
1326  *      As we currently handle our statistics in software this one is
1327  *      easy to handle. With hardware statistics it will get messy
1328  *      as the get_stats call will need to send exec mailbox messages and
1329  *      need to lock out the multicast reloads.
1330  */
1331 
1332 static struct net_device_stats *mc32_get_stats(struct net_device *dev)
1333 {
1334         struct mc32_local *lp = (struct mc32_local *)dev->priv;
1335         return &lp->net_stats;
1336 }
1337 
1338 /**
1339  *      do_mc32_set_multicast_list:
1340  *      @dev: 3c527 device to load the list on
1341  *      @retry: indicates this is not the first call. 
1342  *
1343  * Actually set or clear the multicast filter for this adaptor. The locking
1344  * issues are handled by this routine. We have to track state as it may take
1345  * multiple calls to get the command sequence completed. We just keep trying
1346  * to schedule the loads until we manage to process them all.
1347  *
1348  * num_addrs == -1      Promiscuous mode, receive all packets
1349  *
1350  * num_addrs == 0       Normal mode, clear multicast list
1351  *
1352  * num_addrs > 0        Multicast mode, receive normal and MC packets,
1353  *                      and do best-effort filtering.
1354  */
1355 
1356 static void do_mc32_set_multicast_list(struct net_device *dev, int retry)
1357 {
1358         struct mc32_local *lp = (struct mc32_local *)dev->priv;
1359         u16 filt;
1360 
1361         if (dev->flags&IFF_PROMISC)
1362                 /* Enable promiscuous mode */
1363                 filt = 1;
1364         else if((dev->flags&IFF_ALLMULTI) || dev->mc_count > 10)
1365         {
1366                 dev->flags|=IFF_PROMISC;
1367                 filt = 1;
1368         }
1369         else if(dev->mc_count)
1370         {
1371                 unsigned char block[62];
1372                 unsigned char *bp;
1373                 struct dev_mc_list *dmc=dev->mc_list;
1374                 
1375                 int i;
1376                 
1377                 filt = 0;
1378                 
1379                 if(retry==0)
1380                         lp->mc_list_valid = 0;
1381                 if(!lp->mc_list_valid)
1382                 {
1383                         block[1]=0;
1384                         block[0]=dev->mc_count;
1385                         bp=block+2;
1386                 
1387                         for(i=0;i<dev->mc_count;i++)
1388                         {
1389                                 memcpy(bp, dmc->dmi_addr, 6);
1390                                 bp+=6;
1391                                 dmc=dmc->next;
1392                         }
1393                         if(mc32_command_nowait(dev, 2, block, 2+6*dev->mc_count)==-1)
1394                         {
1395                                 lp->mc_reload_wait = 1;
1396                                 return;
1397                         }
1398                         lp->mc_list_valid=1;
1399                 }
1400         }
1401         else 
1402         {
1403                 filt = 0;
1404         }
1405         if(mc32_command_nowait(dev, 0, &filt, 2)==-1)
1406         {
1407                 lp->mc_reload_wait = 1;
1408         }
1409 }
1410 
1411 /**
1412  *      mc32_set_multicast_list:
1413  *      @dev: The 3c527 to use
1414  *
1415  *      Commence loading the multicast list. This is called when the kernel
1416  *      changes the lists. It will override any pending list we are trying to
1417  *      load.
1418  */
1419  
1420 static void mc32_set_multicast_list(struct net_device *dev)
1421 {
1422         do_mc32_set_multicast_list(dev,0);
1423 }
1424 
1425 /**
1426  *      mc32_reset_multicast_list:
1427  *      @dev: The 3c527 to use
1428  *
1429  *      Attempt the next step in loading the multicast lists. If this attempt
1430  *      fails to complete then it will be scheduled and this function called
1431  *      again later from elsewhere.
1432  */
1433  
1434 
1435 static void mc32_reset_multicast_list(struct net_device *dev)
1436 {
1437         do_mc32_set_multicast_list(dev,1);
1438 }
1439 
1440 #ifdef MODULE
1441 
1442 static struct net_device this_device;
1443 
1444 
1445 /**
1446  *      init_module:
1447  *
1448  *      Probe and locate a 3c527 card. This really should probe and locate
1449  *      all the 3c527 cards in the machine not just one of them. Yes you can
1450  *      insmod multiple modules for now but its a hack.
1451  */
1452  
1453 int init_module(void)
1454 {
1455         int result;
1456 
1457         this_device.init = mc32_probe;
1458         if ((result = register_netdev(&this_device)) != 0)
1459                 return result;
1460 
1461         return 0;
1462 }
1463 
1464 /**
1465  *      cleanup_module:
1466  *
1467  *      Unloading time. We release the MCA bus resources and the interrupt
1468  *      at which point everything is ready to unload. The card must be stopped
1469  *      at this point or we would not have been called. When we unload we
1470  *      leave the card stopped but not totally shut down. When the card is
1471  *      initialized it must be rebooted or the rings reloaded before any
1472  *      transmit operations are allowed to start scribbling into memory.
1473  */
1474  
1475 void cleanup_module(void)
1476 {
1477         int slot;
1478         
1479         /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1480         unregister_netdev(&this_device);
1481 
1482         /*
1483          * If we don't do this, we can't re-insmod it later.
1484          */
1485          
1486         if (this_device.priv)
1487         {
1488                 struct mc32_local *lp=this_device.priv;
1489                 slot = lp->slot;
1490                 mca_mark_as_unused(slot);
1491                 mca_set_adapter_name(slot, NULL);
1492                 kfree(this_device.priv);
1493         }
1494         free_irq(this_device.irq, &this_device);
1495 }
1496 
1497 #endif /* MODULE */
1498 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.