2 /* 3c527.c: 3Com Etherlink/MC32 driver for Linux
4 * (c) Copyright 1998 Red Hat Software Inc
7 * Based on skeleton.c written 1993-94 by Donald Becker and ne2.c
8 * (for the MCA stuff) written by Wim Dumon.
10 * Thanks to 3Com for making this possible by providing me with the
13 * This software may be used and distributed according to the terms
14 * of the GNU Public License, incorporated herein by reference.
18 static const char *version
=
19 "3c527.c:v0.05 1999/09/06 Alan Cox (alan@redhat.com)\n";
25 * Traps for the unwary
27 * The diagram (Figure 1-1) and the POS summary disagree with the
28 * "Interrupt Level" section in the manual.
30 * The documentation in places seems to miss things. In actual fact
31 * I've always eventually found everything is documented, it just
32 * requires careful study.
35 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
39 #include <linux/types.h>
40 #include <linux/fcntl.h>
41 #include <linux/interrupt.h>
42 #include <linux/ptrace.h>
43 #include <linux/mca.h>
44 #include <linux/ioport.h>
46 #include <linux/malloc.h>
47 #include <linux/string.h>
48 #include <asm/system.h>
49 #include <asm/bitops.h>
52 #include <linux/errno.h>
53 #include <linux/init.h>
55 #include <linux/netdevice.h>
56 #include <linux/etherdevice.h>
57 #include <linux/skbuff.h>
62 * The name of the card. Is used for messages and in the requests for
63 * io regions, irqs and dma channels
65 static const char* cardname
= "3c527";
67 /* use 0 for production, 1 for verification, >2 for debug */
71 static unsigned int mc32_debug
= NET_DEBUG
;
73 /* The number of low I/O ports used by the ethercard. */
74 #define NETCARD_IO_EXTENT 8
79 u16 mbox
__attribute((packed
));
80 u16 data
[1] __attribute((packed
));
83 /* Information that need to be kept for each board. */
85 #define TX_RING_MAX 16 /* Typically the card supports 37 */
86 #define RX_RING_MAX 32 /* " " " */
90 struct net_device_stats net_stats
;
92 volatile struct mc32_mailbox
*rx_box
;
93 volatile struct mc32_mailbox
*tx_box
;
94 volatile struct mc32_mailbox
*exec_box
;
104 u16 mc_reload_wait
; /* a multicast load request is pending */
105 atomic_t tx_count
; /* buffers left */
106 wait_queue_head_t event
;
107 struct sk_buff
*tx_skb
[TX_RING_MAX
]; /* Transmit ring */
110 struct sk_buff
*rx_skb
[RX_RING_MAX
]; /* Receive ring */
111 void *rx_ptr
[RX_RING_MAX
]; /* Data pointers */
112 u32 mc_list_valid
; /* True when the mclist is set */
115 /* The station (ethernet) address prefix, used for a sanity check. */
116 #define SA_ADDR0 0x02
117 #define SA_ADDR1 0x60
118 #define SA_ADDR2 0xAC
120 struct mca_adapters_t
{
125 const struct mca_adapters_t mc32_adapters
[] = {
126 { 0x0041, "3COM EtherLink MC/32" },
127 { 0x8EF5, "IBM High Performance Lan Adapter" },
132 /* Index to functions, as function prototypes. */
134 extern int mc32_probe(struct net_device
*dev
);
136 static int mc32_probe1(struct net_device
*dev
, int ioaddr
);
137 static int mc32_open(struct net_device
*dev
);
138 static int mc32_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
139 static void mc32_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
140 static int mc32_close(struct net_device
*dev
);
141 static struct net_device_stats
*mc32_get_stats(struct net_device
*dev
);
142 static void mc32_set_multicast_list(struct net_device
*dev
);
143 static void mc32_reset_multicast_list(struct net_device
*dev
);
147 * Check for a network adaptor of this type, and return '0' iff one exists.
148 * If dev->base_addr == 0, probe all likely locations.
149 * If dev->base_addr == 1, always return failure.
150 * If dev->base_addr == 2, allocate space for the device and return success
151 * (detachable devices only).
154 int __init
mc32_probe(struct net_device
*dev
)
156 static int current_mca_slot
= -1;
158 int adapter_found
= 0;
160 /* Do not check any supplied i/o locations.
161 POS registers usually don't fail :) */
163 /* MCA cards have POS registers.
164 Autodetecting MCA cards is extremely simple.
165 Just search for the card. */
167 for(i
= 0; (mc32_adapters
[i
].name
!= NULL
) && !adapter_found
; i
++) {
169 mca_find_unused_adapter(mc32_adapters
[i
].id
, 0);
171 if((current_mca_slot
!= MCA_NOTFOUND
) && !adapter_found
) {
172 if(!mc32_probe1(dev
, current_mca_slot
))
174 mca_set_adapter_name(current_mca_slot
,
175 mc32_adapters
[i
].name
);
176 mca_mark_as_used(current_mca_slot
);
186 * This is the real probe routine. Linux has a history of friendly device
187 * probes on the ISA bus. A good device probes avoids doing writes, and
188 * verifies that the correct device exists and functions.
190 static int __init
mc32_probe1(struct net_device
*dev
, int slot
)
192 static unsigned version_printed
= 0;
196 struct mc32_local
*lp
;
197 static u16 mca_io_bases
[]={
203 static u32 mca_mem_bases
[]={
213 static char *failures
[]={
214 "Processor instruction",
215 "Processor data bus",
216 "Processor data bus",
217 "Processor data bus",
222 "82586 internal loopback",
223 "82586 initialisation failure",
224 "Adapter list configuration error"
227 /* Time to play MCA games */
229 if (mc32_debug
&& version_printed
++ == 0)
230 printk(KERN_DEBUG
"%s", version
);
232 printk(KERN_INFO
"%s: %s found in slot %d:", dev
->name
, cardname
, slot
);
234 POS
= mca_read_stored_pos(slot
, 2);
238 printk(" disabled.\n");
242 /* Allocate a new 'dev' if needed. */
245 * Don't allocate the private data here, it is done later
246 * This makes it easier to free the memory when this driver
247 * is used as a module.
249 dev
= init_etherdev(0, 0);
254 /* Fill in the 'dev' fields. */
255 dev
->base_addr
= mca_io_bases
[(POS
>>1)&7];
256 dev
->mem_start
= mca_mem_bases
[(POS
>>4)&7];
258 POS
= mca_read_stored_pos(slot
, 4);
261 printk("memory window disabled.\n");
265 POS
= mca_read_stored_pos(slot
, 5);
270 printk("invalid memory window.\n");
277 dev
->mem_end
=dev
->mem_start
+ i
;
279 dev
->irq
= ((POS
>>2)&3)+9;
281 printk("io 0x%3lX irq %d mem 0x%lX (%dK)\n",
282 dev
->base_addr
, dev
->irq
, dev
->mem_start
, i
/1024);
285 /* We ought to set the cache line size here.. */
292 printk("%s: Address ", dev
->name
);
294 /* Retrieve and print the ethernet address. */
295 for (i
= 0; i
< 6; i
++)
297 mca_write_pos(slot
, 6, i
+12);
298 mca_write_pos(slot
, 7, 0);
300 printk(" %2.2x", dev
->dev_addr
[i
] = mca_read_pos(slot
,3));
303 mca_write_pos(slot
, 6, 0);
304 mca_write_pos(slot
, 7, 0);
306 POS
= mca_read_stored_pos(slot
, 4);
309 printk(" : BNC port selected.\n");
311 printk(" : AUI port selected.\n");
313 POS
=inb(dev
->base_addr
+HOST_CTRL
);
314 POS
|=HOST_CTRL_ATTN
|HOST_CTRL_RESET
;
315 POS
&=~HOST_CTRL_INTE
;
316 outb(POS
, dev
->base_addr
+HOST_CTRL
);
320 POS
&=~(HOST_CTRL_ATTN
|HOST_CTRL_RESET
);
321 outb(POS
, dev
->base_addr
+HOST_CTRL
);
329 if(request_irq(dev
->irq
, &mc32_interrupt
, 0, cardname
, dev
))
331 printk("%s: unable to get IRQ %d.\n",
332 dev
->name
, dev
->irq
);
336 /* Initialize the device structure. */
337 if (dev
->priv
== NULL
) {
338 dev
->priv
= kmalloc(sizeof(struct mc32_local
), GFP_KERNEL
);
339 if (dev
->priv
== NULL
)
341 free_irq(dev
->irq
, dev
);
346 memset(dev
->priv
, 0, sizeof(struct mc32_local
));
347 lp
= (struct mc32_local
*)dev
->priv
;
352 base
= inb(dev
->base_addr
);
359 printk("%s: failed to boot adapter.\n", dev
->name
);
360 free_irq(dev
->irq
, dev
);
364 if(inb(dev
->base_addr
+2)&(1<<5))
365 base
= inb(dev
->base_addr
);
371 printk("%s: %s%s.\n", dev
->name
, failures
[base
-1],
372 base
<0x0A?" test failure":"");
374 printk("%s: unknown failure %d.\n", dev
->name
, base
);
375 free_irq(dev
->irq
, dev
);
384 while(!(inb(dev
->base_addr
+2)&(1<<5)))
390 printk(KERN_ERR
"%s: mailbox read fail (%d).\n", dev
->name
, i
);
391 free_irq(dev
->irq
, dev
);
396 base
|=(inb(dev
->base_addr
)<<(8*i
));
399 lp
->exec_box
=bus_to_virt(dev
->mem_start
+base
);
401 base
=lp
->exec_box
->data
[1]<<16|lp
->exec_box
->data
[0];
403 lp
->base
= dev
->mem_start
+base
;
405 lp
->rx_box
=bus_to_virt(lp
->base
+ lp
->exec_box
->data
[2]);
406 lp
->tx_box
=bus_to_virt(lp
->base
+ lp
->exec_box
->data
[3]);
408 lp
->stats
= bus_to_virt(lp
->base
+ lp
->exec_box
->data
[5]);
411 * Descriptor chains (card relative)
414 lp
->tx_chain
= lp
->exec_box
->data
[8];
415 lp
->rx_chain
= lp
->exec_box
->data
[10];
416 lp
->tx_len
= lp
->exec_box
->data
[9];
417 lp
->rx_len
= lp
->exec_box
->data
[11];
418 init_waitqueue_head(&lp
->event
);
420 printk("%s: %d RX buffers, %d TX buffers. Base of 0x%08X.\n",
421 dev
->name
, lp
->rx_len
, lp
->tx_len
, lp
->base
);
423 dev
->open
= mc32_open
;
424 dev
->stop
= mc32_close
;
425 dev
->hard_start_xmit
= mc32_send_packet
;
426 dev
->get_stats
= mc32_get_stats
;
427 dev
->set_multicast_list
= mc32_set_multicast_list
;
432 /* Fill in the fields of the device structure with ethernet values. */
439 * Polled command stuff
442 static void mc32_ring_poll(struct net_device
*dev
)
444 int ioaddr
= dev
->base_addr
;
445 while(!(inb(ioaddr
+HOST_STATUS
)&HOST_STATUS_CRR
));
455 * Send command from interrupt state
458 static int mc32_command_nowait(struct net_device
*dev
, u16 cmd
, void *data
, int len
)
460 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
461 int ioaddr
= dev
->base_addr
;
467 lp
->exec_box
->mbox
=0;
468 lp
->exec_box
->mbox
=cmd
;
469 memcpy((void *)lp
->exec_box
->data
, data
, len
);
470 barrier(); /* the memcpy forgot the volatile so be sure */
472 /* Send the command */
473 while(!(inb(ioaddr
+HOST_STATUS
)&HOST_STATUS_CRR
));
474 outb(1<<6, ioaddr
+HOST_CMD
);
480 * Send command and block for results. On completion spot and reissue
484 static int mc32_command(struct net_device
*dev
, u16 cmd
, void *data
, int len
)
486 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
487 int ioaddr
= dev
->base_addr
;
495 while(lp
->exec_pending
)
496 sleep_on(&lp
->event
);
503 lp
->exec_box
->mbox
=0;
504 lp
->exec_box
->mbox
=cmd
;
505 memcpy((void *)lp
->exec_box
->data
, data
, len
);
506 barrier(); /* the memcpy forgot the volatile so be sure */
508 /* Send the command */
509 while(!(inb(ioaddr
+HOST_STATUS
)&HOST_STATUS_CRR
));
510 outb(1<<6, ioaddr
+HOST_CMD
);
514 while(lp
->exec_pending
!=2)
515 sleep_on(&lp
->event
);
517 restore_flags(flags
);
520 if(lp
->exec_box
->data
[0]&(1<<13))
523 * A multicast set got blocked - do it now
526 if(lp
->mc_reload_wait
)
527 mc32_reset_multicast_list(dev
);
537 static void mc32_rx_abort(struct net_device
*dev
)
539 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
540 int ioaddr
= dev
->base_addr
;
542 while(!(inb(ioaddr
+HOST_STATUS
)&HOST_STATUS_CRR
));
545 outb(3<<3, ioaddr
+HOST_CMD
); /* Suspend reception */
553 static void mc32_rx_begin(struct net_device
*dev
)
555 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
556 int ioaddr
= dev
->base_addr
;
558 while(!(inb(ioaddr
+HOST_STATUS
)&HOST_STATUS_CRR
));
561 outb(1<<3, ioaddr
+HOST_CMD
); /* GO */
567 static void mc32_tx_abort(struct net_device
*dev
)
569 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
570 int ioaddr
= dev
->base_addr
;
572 while(!(inb(ioaddr
+HOST_STATUS
)&HOST_STATUS_CRR
));
575 outb(3, ioaddr
+HOST_CMD
); /* Suspend */
579 atomic_set(&lp
->tx_count
, lp
->tx_len
);
582 if(lp
->tx_skb_top
!=lp
->tx_skb_end
)
585 if(lp
->tx_skb_top
<=lp
->tx_skb_end
)
587 for(i
=lp
->tx_skb_top
;i
<lp
->tx_skb_end
;i
++)
589 dev_kfree_skb(lp
->tx_skb
[i
]);
595 for(i
=lp
->tx_skb_end
;i
<TX_RING_MAX
;i
++)
597 dev_kfree_skb(lp
->tx_skb
[i
]);
600 for(i
=0;i
<lp
->tx_skb_top
;i
++)
602 dev_kfree_skb(lp
->tx_skb
[i
]);
607 lp
->tx_skb_top
=lp
->tx_skb_end
=0;
614 static void mc32_tx_begin(struct net_device
*dev
)
616 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
617 int ioaddr
= dev
->base_addr
;
619 while(!(inb(ioaddr
+HOST_STATUS
)&HOST_STATUS_CRR
));
623 outb(5, ioaddr
+HOST_CMD
); /* GO */
626 if(lp
->tx_box
->mbox
&(1<<13))
627 printk("TX begin error!\n");
637 static int mc32_load_rx_ring(struct net_device
*dev
)
639 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
642 volatile struct skb_header
*p
;
644 base
= lp
->rx_box
->data
[0];
646 /* Fix me - should use card size - also fix flush ! */
648 for(i
=0;i
<RX_RING_MAX
;i
++)
650 lp
->rx_skb
[i
]=alloc_skb(1532, GFP_KERNEL
);
651 if(lp
->rx_skb
[i
]==NULL
)
654 kfree_skb(lp
->rx_skb
[i
]);
657 lp
->rx_ptr
[i
]=lp
->rx_skb
[i
]->data
+18;
659 p
=bus_to_virt(lp
->base
+base
);
661 p
->data
= virt_to_bus(lp
->rx_ptr
[i
]);
667 lp
->rx_box
->mbox
= 0;
671 static void mc32_flush_rx_ring(struct mc32_local
*lp
)
674 for(i
=0;i
<RX_RING_MAX
;i
++)
675 kfree_skb(lp
->rx_skb
[i
]);
678 static void mc32_flush_tx_ring(struct mc32_local
*lp
)
682 if(lp
->tx_skb_top
<= lp
->tx_skb_end
)
684 for(i
=lp
->tx_skb_top
;i
<lp
->tx_skb_end
;i
++)
685 dev_kfree_skb(lp
->tx_skb
[i
]);
689 for(i
=0;i
<lp
->tx_skb_end
;i
++)
690 dev_kfree_skb(lp
->tx_skb
[i
]);
691 for(i
=lp
->tx_skb_top
;i
<TX_RING_MAX
;i
++)
692 dev_kfree_skb(lp
->tx_skb
[i
]);
697 * Open/initialize the board. This is called (in the current kernel)
698 * sometime after booting when the 'ifconfig' program is run.
701 static int mc32_open(struct net_device
*dev
)
703 int ioaddr
= dev
->base_addr
;
716 regs
=inb(ioaddr
+HOST_CTRL
);
717 regs
|=HOST_CTRL_INTE
;
718 outb(regs
, ioaddr
+HOST_CTRL
);
722 * Send the indications on command
725 mc32_command(dev
, 4, &one
, 2);
729 * Send the command sequence "abort, resume" for RX and TX.
730 * The abort cleans up the buffer chains if needed.
736 /* Set Network Address */
737 mc32_command(dev
, 1, dev
->dev_addr
, 6);
739 /* Set the filters */
740 mc32_set_multicast_list(dev
);
742 /* Issue the 82586 workaround command - this is for "busy lans",
743 but basically means for all lans now days - has a performance
746 mc32_command(dev
, 0x0D, &zero_word
, 2); /* 82586 bug workaround on */
748 /* Load the ring we just initialised */
750 if(mc32_load_rx_ring(dev
))
756 /* And the resume command goes last */
766 static int mc32_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
768 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
772 * If we get here, some higher level has decided we are broken.
773 * There should really be a "kick me" function call instead.
775 int tickssofar
= jiffies
- dev
->trans_start
;
778 printk(KERN_WARNING
"%s: transmit timed out?\n", dev
->name
);
779 /* Try to restart the adaptor. */
781 dev
->trans_start
= jiffies
;
785 * Block a timer-based transmit from overlapping. This could better be
786 * done with atomic_swap(1, dev->tbusy), but set_bit() works as well.
788 if (test_and_set_bit(0, (void*)&dev
->tbusy
) != 0)
790 printk(KERN_WARNING
"%s: Transmitter access conflict.\n", dev
->name
);
798 volatile struct skb_header
*p
, *np
;
803 if(atomic_read(&lp
->tx_count
)==0)
806 restore_flags(flags
);
810 tx_head
= lp
->tx_box
->data
[0];
811 atomic_dec(&lp
->tx_count
);
813 /* We will need this to flush the buffer out */
815 lp
->tx_skb
[lp
->tx_skb_end
] = skb
;
817 lp
->tx_skb_end
&=(TX_RING_MAX
-1);
819 /* P is the last sending/sent buffer as a pointer */
820 p
=(struct skb_header
*)bus_to_virt(lp
->base
+tx_head
);
822 /* NP is the buffer we will be loading */
823 np
=(struct skb_header
*)bus_to_virt(lp
->base
+p
->next
);
825 np
->control
|= (1<<6); /* EOL */
828 np
->length
= skb
->len
;
829 np
->data
= virt_to_bus(skb
->data
);
831 np
->control
= (1<<7)|(1<<6); /* EOP EOL */
835 p
->control
&= ~(1<<6);
837 dev
->tbusy
= 0; /* Keep feeding me */
840 restore_flags(flags
);
845 static void mc32_update_stats(struct net_device
*dev
)
850 static void mc32_rx_ring(struct net_device
*dev
)
852 struct mc32_local
*lp
=dev
->priv
;
853 int ioaddr
= dev
->base_addr
;
855 volatile struct skb_header
*p
;
859 top
= base
= lp
->rx_box
->data
[0];
862 p
=(struct skb_header
*)bus_to_virt(base
+lp
->base
);
863 if(!(p
->status
& (1<<7)))
865 if(p
->status
& (1<<6))
867 u16 length
= p
->length
;
868 struct sk_buff
*skb
=dev_alloc_skb(length
+2);
872 /*printk("Frame at %p\n", bus_to_virt(p->data)); */
873 memcpy(skb_put(skb
, length
),
874 bus_to_virt(p
->data
), length
);
875 skb
->protocol
=eth_type_trans(skb
,dev
);
877 lp
->net_stats
.rx_packets
++;
878 lp
->net_stats
.rx_bytes
+=skb
->len
;
882 lp
->net_stats
.rx_dropped
++;
886 lp
->net_stats
.rx_errors
++;
887 switch(p
->status
&0x0F)
890 lp
->net_stats
.rx_crc_errors
++;break;
892 lp
->net_stats
.rx_fifo_errors
++;break;
894 lp
->net_stats
.rx_frame_errors
++;break;
896 lp
->net_stats
.rx_missed_errors
++;break;
898 lp
->net_stats
.rx_length_errors
++;break;
902 p
->control
&= ~(1<<6);
909 * This is curious. It seems the receive stop and receive continue
910 * commands race against each other, even though we poll for
911 * command ready to be issued. The delay is hackish but is a workaround
912 * while I investigate in depth
915 while(!(inb(ioaddr
+HOST_STATUS
)&HOST_STATUS_CRR
));
917 lp
->rx_box
->data
[0] = top
;
918 outb(1<<3, ioaddr
+HOST_CMD
);
923 * The typical workload of the driver:
924 * Handle the network interface interrupts.
926 static void mc32_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
928 struct net_device
*dev
= dev_id
;
929 struct mc32_local
*lp
;
930 int ioaddr
, status
, boguscount
= 0;
934 printk(KERN_WARNING
"%s: irq %d for unknown device.\n", cardname
, irq
);
939 ioaddr
= dev
->base_addr
;
940 lp
= (struct mc32_local
*)dev
->priv
;
942 /* See whats cooking */
944 while((inb(ioaddr
+2)&(1<<5)) && boguscount
++<2000)
946 status
=inb(ioaddr
+HOST_CMD
);
949 printk("Status TX%d RX%d EX%d OV%d\n",
950 (status
&7), (status
>>3)&7, (status
>>6)&1,
958 case 6: /* TX fail */
959 lp
->net_stats
.tx_errors
++;
961 lp
->net_stats
.tx_packets
++;
962 /* Packets are sent in order - this is
963 basically a FIFO queue of buffers matching
965 lp
->net_stats
.tx_bytes
+=lp
->tx_skb
[lp
->tx_skb_top
]->len
;
966 dev_kfree_skb(lp
->tx_skb
[lp
->tx_skb_top
]);
967 lp
->tx_skb
[lp
->tx_skb_top
]=NULL
;
969 lp
->tx_skb_top
&=(TX_RING_MAX
-1);
970 atomic_inc(&lp
->tx_count
);
984 printk("%s: strange tx ack %d\n",
985 dev
->name
, status
&7);
1002 wake_up(&lp
->event
);
1005 /* Out of RX buffers stat */
1007 lp
->net_stats
.rx_dropped
++;
1008 rx_event
= 1; /* To restart */
1011 printk("%s: strange rx ack %d\n",
1012 dev
->name
, status
&7);
1018 /* 0=no 1=yes 2=reply clearing */
1020 wake_up(&lp
->event
);
1025 * Update the stats as soon as
1026 * we have it flagged and can
1027 * send an immediate reply (CRR set)
1030 if(inb(ioaddr
+HOST_STATUS
)&HOST_STATUS_CRR
)
1032 mc32_update_stats(dev
);
1033 outb(0, ioaddr
+HOST_CMD
);
1039 * Process and restart the receive ring.
1049 /* The inverse routine to mc32_open(). */
1051 static int mc32_close(struct net_device
*dev
)
1053 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
1054 int ioaddr
= dev
->base_addr
;
1059 * Send the indications on command (handy debug check)
1062 mc32_command(dev
, 4, &one
, 2);
1064 /* Abort RX and Abort TX */
1069 /* Catch any waiting commands */
1071 while(lp
->exec_pending
==1)
1072 sleep_on(&lp
->event
);
1074 /* Ok the card is now stopping */
1076 regs
=inb(ioaddr
+HOST_CTRL
);
1077 regs
&=~HOST_CTRL_INTE
;
1078 outb(regs
, ioaddr
+HOST_CTRL
);
1080 mc32_flush_rx_ring(lp
);
1081 mc32_flush_tx_ring(lp
);
1086 /* Update the statistics here. */
1095 * Get the current statistics.
1096 * This may be called with the card open or closed.
1099 static struct net_device_stats
*mc32_get_stats(struct net_device
*dev
)
1101 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
1102 return &lp
->net_stats
;
1106 * Set or clear the multicast filter for this adaptor.
1107 * num_addrs == -1 Promiscuous mode, receive all packets
1108 * num_addrs == 0 Normal mode, clear multicast list
1109 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1110 * and do best-effort filtering.
1112 static void do_mc32_set_multicast_list(struct net_device
*dev
, int retry
)
1114 struct mc32_local
*lp
= (struct mc32_local
*)dev
->priv
;
1117 if (dev
->flags
&IFF_PROMISC
)
1118 /* Enable promiscuous mode */
1120 else if((dev
->flags
&IFF_ALLMULTI
) || dev
->mc_count
> 10)
1122 dev
->flags
|=IFF_PROMISC
;
1125 else if(dev
->mc_count
)
1127 unsigned char block
[62];
1129 struct dev_mc_list
*dmc
=dev
->mc_list
;
1136 lp
->mc_list_valid
= 0;
1137 if(!lp
->mc_list_valid
)
1140 block
[0]=dev
->mc_count
;
1143 for(i
=0;i
<dev
->mc_count
;i
++)
1145 memcpy(bp
, dmc
->dmi_addr
, 6);
1149 if(mc32_command_nowait(dev
, 2, block
, 2+6*dev
->mc_count
)==-1)
1151 lp
->mc_reload_wait
= 1;
1154 lp
->mc_list_valid
=1;
1161 if(mc32_command_nowait(dev
, 0, &filt
, 2)==-1)
1163 lp
->mc_reload_wait
= 1;
1167 static void mc32_set_multicast_list(struct net_device
*dev
)
1169 do_mc32_set_multicast_list(dev
,0);
1172 static void mc32_reset_multicast_list(struct net_device
*dev
)
1174 do_mc32_set_multicast_list(dev
,1);
1179 static char devicename
[9] = { 0, };
1180 static struct net_device this_device
= {
1181 devicename
, /* will be inserted by linux/drivers/net/mc32_init.c */
1183 0, 0, /* I/O address, IRQ */
1184 0, 0, 0, NULL
, mc32_probe
};
1186 int init_module(void)
1190 if ((result
= register_netdev(&this_device
)) != 0)
1196 void cleanup_module(void)
1200 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1201 unregister_netdev(&this_device
);
1204 * If we don't do this, we can't re-insmod it later.
1205 * Release irq/dma here, when you have jumpered versions and
1206 * allocate them in mc32_probe1().
1209 if (this_device
.priv
)
1211 struct mc32_local
*lp
=this_device
.priv
;
1213 mca_mark_as_unused(slot
);
1214 mca_set_adapter_name(slot
, NULL
);
1215 kfree_s(this_device
.priv
, sizeof(struct mc32_local
));
1217 free_irq(this_device
.irq
, &this_device
);