Merge with 2.4.0-test3-pre4.
[linux-2.6/linux-mips.git] / drivers / net / smc9194.c
blob084fd4120e847aaa9de89b8d4020af033740fdbe
1 /*------------------------------------------------------------------------
2 . smc9194.c
3 . This is a driver for SMC's 9000 series of Ethernet cards.
5 . Copyright (C) 1996 by Erik Stahlman
6 . This software may be used and distributed according to the terms
7 . of the GNU Public License, incorporated herein by reference.
9 . "Features" of the SMC chip:
10 . 4608 byte packet memory. ( for the 91C92. Others have more )
11 . EEPROM for configuration
12 . AUI/TP selection ( mine has 10Base2/10BaseT select )
14 . Arguments:
15 . io = for the base address
16 . irq = for the IRQ
17 . ifport = 0 for autodetect, 1 for TP, 2 for AUI ( or 10base2 )
19 . author:
20 . Erik Stahlman ( erik@vt.edu )
22 . Hardware multicast code from Peter Cammaert ( pc@denkart.be )
24 . Sources:
25 . o SMC databook
26 . o skeleton.c by Donald Becker ( becker@cesdis.gsfc.nasa.gov )
27 . o ( a LOT of advice from Becker as well )
29 . History:
30 . 12/07/95 Erik Stahlman written, got receive/xmit handled
31 . 01/03/96 Erik Stahlman worked out some bugs, actually usable!!! :-)
32 . 01/06/96 Erik Stahlman cleaned up some, better testing, etc
33 . 01/29/96 Erik Stahlman fixed autoirq, added multicast
34 . 02/01/96 Erik Stahlman 1. disabled all interrupts in smc_reset
35 . 2. got rid of post-decrementing bug -- UGH.
36 . 02/13/96 Erik Stahlman Tried to fix autoirq failure. Added more
37 . descriptive error messages.
38 . 02/15/96 Erik Stahlman Fixed typo that caused detection failure
39 . 02/23/96 Erik Stahlman Modified it to fit into kernel tree
40 . Added support to change hardware address
41 . Cleared stats on opens
42 . 02/26/96 Erik Stahlman Trial support for Kernel 1.2.13
43 . Kludge for automatic IRQ detection
44 . 03/04/96 Erik Stahlman Fixed kernel 1.3.70 +
45 . Fixed bug reported by Gardner Buchanan in
46 . smc_enable, with outw instead of outb
47 . 03/06/96 Erik Stahlman Added hardware multicast from Peter Cammaert
48 . 04/14/00 Heiko Pruessing (SMA Regelsysteme) Fixed bug in chip memory
49 . allocation
50 ----------------------------------------------------------------------------*/
52 static const char *version =
53 "smc9194.c:v0.13 04/14/00 by Erik Stahlman (erik@vt.edu)\n";
55 #include <linux/module.h>
56 #include <linux/version.h>
57 #include <linux/kernel.h>
58 #include <linux/sched.h>
59 #include <linux/types.h>
60 #include <linux/fcntl.h>
61 #include <linux/interrupt.h>
62 #include <linux/ptrace.h>
63 #include <linux/ioport.h>
64 #include <linux/in.h>
65 #include <linux/malloc.h>
66 #include <linux/string.h>
67 #include <linux/init.h>
68 #include <asm/bitops.h>
69 #include <asm/io.h>
70 #include <linux/errno.h>
72 #include <linux/netdevice.h>
73 #include <linux/etherdevice.h>
74 #include <linux/skbuff.h>
76 #include "smc9194.h"
77 /*------------------------------------------------------------------------
79 . Configuration options, for the experienced user to change.
81 -------------------------------------------------------------------------*/
84 . Do you want to use 32 bit xfers? This should work on all chips, as
85 . the chipset is designed to accommodate them.
87 #define USE_32_BIT 1
90 .the SMC9194 can be at any of the following port addresses. To change,
91 .for a slightly different card, you can add it to the array. Keep in
92 .mind that the array must end in zero.
94 static unsigned int smc_portlist[] __initdata = {
95 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0,
96 0x300, 0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x3E0, 0
100 . Wait time for memory to be free. This probably shouldn't be
101 . tuned that much, as waiting for this means nothing else happens
102 . in the system
104 #define MEMORY_WAIT_TIME 16
107 . DEBUGGING LEVELS
109 . 0 for normal operation
110 . 1 for slightly more details
111 . >2 for various levels of increasingly useless information
112 . 2 for interrupt tracking, status flags
113 . 3 for packet dumps, etc.
115 #define SMC_DEBUG 0
117 #if (SMC_DEBUG > 2 )
118 #define PRINTK3(x) printk x
119 #else
120 #define PRINTK3(x)
121 #endif
123 #if SMC_DEBUG > 1
124 #define PRINTK2(x) printk x
125 #else
126 #define PRINTK2(x)
127 #endif
129 #ifdef SMC_DEBUG
130 #define PRINTK(x) printk x
131 #else
132 #define PRINTK(x)
133 #endif
136 /*------------------------------------------------------------------------
138 . The internal workings of the driver. If you are changing anything
139 . here with the SMC stuff, you should have the datasheet and known
140 . what you are doing.
142 -------------------------------------------------------------------------*/
143 #define CARDNAME "SMC9194"
146 /* store this information for the driver.. */
147 struct smc_local {
149 these are things that the kernel wants me to keep, so users
150 can find out semi-useless statistics of how well the card is
151 performing
153 struct net_device_stats stats;
156 If I have to wait until memory is available to send
157 a packet, I will store the skbuff here, until I get the
158 desired memory. Then, I'll send it out and free it.
160 struct sk_buff * saved_skb;
163 . This keeps track of how many packets that I have
164 . sent out. When an TX_EMPTY interrupt comes, I know
165 . that all of these have been sent.
167 int packets_waiting;
171 /*-----------------------------------------------------------------
173 . The driver can be entered at any of the following entry points.
175 .------------------------------------------------------------------ */
178 . This is called by register_netdev(). It is responsible for
179 . checking the portlist for the SMC9000 series chipset. If it finds
180 . one, then it will initialize the device, find the hardware information,
181 . and sets up the appropriate device parameters.
182 . NOTE: Interrupts are *OFF* when this procedure is called.
184 . NB:This shouldn't be static since it is referred to externally.
186 int smc_init(struct net_device *dev);
189 . The kernel calls this function when someone wants to use the device,
190 . typically 'ifconfig ethX up'.
192 static int smc_open(struct net_device *dev);
195 . Our watchdog timed out. Called by the networking layer
197 static void smc_timeout(struct net_device *dev);
200 . This is called by the kernel to send a packet out into the net. it's
201 . responsible for doing a best-effort send, but if it's simply not possible
202 . to send it, the packet gets dropped.
204 static int smc_send_packet(struct sk_buff *skb, struct net_device *dev);
207 . This is called by the kernel in response to 'ifconfig ethX down'. It
208 . is responsible for cleaning up everything that the open routine
209 . does, and maybe putting the card into a powerdown state.
211 static int smc_close(struct net_device *dev);
214 . This routine allows the proc file system to query the driver's
215 . statistics.
217 static struct net_device_stats * smc_query_statistics( struct net_device *dev);
220 . Finally, a call to set promiscuous mode ( for TCPDUMP and related
221 . programs ) and multicast modes.
223 static void smc_set_multicast_list(struct net_device *dev);
226 . CRC compute
228 static int crc32( char * s, int length );
230 /*---------------------------------------------------------------
232 . Interrupt level calls..
234 ----------------------------------------------------------------*/
237 . Handles the actual interrupt
239 static void smc_interrupt(int irq, void *, struct pt_regs *regs);
241 . This is a separate procedure to handle the receipt of a packet, to
242 . leave the interrupt code looking slightly cleaner
244 inline static void smc_rcv( struct net_device *dev );
246 . This handles a TX interrupt, which is only called when an error
247 . relating to a packet is sent.
249 inline static void smc_tx( struct net_device * dev );
252 ------------------------------------------------------------
254 . Internal routines
256 ------------------------------------------------------------
260 . Test if a given location contains a chip, trying to cause as
261 . little damage as possible if it's not a SMC chip.
263 static int smc_probe( int ioaddr );
266 . this routine initializes the cards hardware, prints out the configuration
267 . to the system log as well as the vanity message, and handles the setup
268 . of a device parameter.
269 . It will give an error if it can't initialize the card.
271 static int smc_initcard( struct net_device *, int ioaddr );
274 . A rather simple routine to print out a packet for debugging purposes.
276 #if SMC_DEBUG > 2
277 static void print_packet( byte *, int );
278 #endif
280 #define tx_done(dev) 1
282 /* this is called to actually send the packet to the chip */
283 static void smc_hardware_send_packet( struct net_device * dev );
285 /* Since I am not sure if I will have enough room in the chip's ram
286 . to store the packet, I call this routine, which either sends it
287 . now, or generates an interrupt when the card is ready for the
288 . packet */
289 static int smc_wait_to_send_packet( struct sk_buff * skb, struct net_device *dev );
291 /* this does a soft reset on the device */
292 static void smc_reset( int ioaddr );
294 /* Enable Interrupts, Receive, and Transmit */
295 static void smc_enable( int ioaddr );
297 /* this puts the device in an inactive state */
298 static void smc_shutdown( int ioaddr );
300 /* This routine will find the IRQ of the driver if one is not
301 . specified in the input to the device. */
302 static int smc_findirq( int ioaddr );
305 . Function: smc_reset( int ioaddr )
306 . Purpose:
307 . This sets the SMC91xx chip to its normal state, hopefully from whatever
308 . mess that any other DOS driver has put it in.
310 . Maybe I should reset more registers to defaults in here? SOFTRESET should
311 . do that for me.
313 . Method:
314 . 1. send a SOFT RESET
315 . 2. wait for it to finish
316 . 3. enable autorelease mode
317 . 4. reset the memory management unit
318 . 5. clear all interrupts
321 static void smc_reset( int ioaddr )
323 /* This resets the registers mostly to defaults, but doesn't
324 affect EEPROM. That seems unnecessary */
325 SMC_SELECT_BANK( 0 );
326 outw( RCR_SOFTRESET, ioaddr + RCR );
328 /* this should pause enough for the chip to be happy */
329 SMC_DELAY( );
331 /* Set the transmit and receive configuration registers to
332 default values */
333 outw( RCR_CLEAR, ioaddr + RCR );
334 outw( TCR_CLEAR, ioaddr + TCR );
336 /* set the control register to automatically
337 release successfully transmitted packets, to make the best
338 use out of our limited memory */
339 SMC_SELECT_BANK( 1 );
340 outw( inw( ioaddr + CONTROL ) | CTL_AUTO_RELEASE , ioaddr + CONTROL );
342 /* Reset the MMU */
343 SMC_SELECT_BANK( 2 );
344 outw( MC_RESET, ioaddr + MMU_CMD );
346 /* Note: It doesn't seem that waiting for the MMU busy is needed here,
347 but this is a place where future chipsets _COULD_ break. Be wary
348 of issuing another MMU command right after this */
350 outb( 0, ioaddr + INT_MASK );
354 . Function: smc_enable
355 . Purpose: let the chip talk to the outside work
356 . Method:
357 . 1. Enable the transmitter
358 . 2. Enable the receiver
359 . 3. Enable interrupts
361 static void smc_enable( int ioaddr )
363 SMC_SELECT_BANK( 0 );
364 /* see the header file for options in TCR/RCR NORMAL*/
365 outw( TCR_NORMAL, ioaddr + TCR );
366 outw( RCR_NORMAL, ioaddr + RCR );
368 /* now, enable interrupts */
369 SMC_SELECT_BANK( 2 );
370 outb( SMC_INTERRUPT_MASK, ioaddr + INT_MASK );
374 . Function: smc_shutdown
375 . Purpose: closes down the SMC91xxx chip.
376 . Method:
377 . 1. zero the interrupt mask
378 . 2. clear the enable receive flag
379 . 3. clear the enable xmit flags
381 . TODO:
382 . (1) maybe utilize power down mode.
383 . Why not yet? Because while the chip will go into power down mode,
384 . the manual says that it will wake up in response to any I/O requests
385 . in the register space. Empirical results do not show this working.
387 static void smc_shutdown( int ioaddr )
389 /* no more interrupts for me */
390 SMC_SELECT_BANK( 2 );
391 outb( 0, ioaddr + INT_MASK );
393 /* and tell the card to stay away from that nasty outside world */
394 SMC_SELECT_BANK( 0 );
395 outb( RCR_CLEAR, ioaddr + RCR );
396 outb( TCR_CLEAR, ioaddr + TCR );
397 #if 0
398 /* finally, shut the chip down */
399 SMC_SELECT_BANK( 1 );
400 outw( inw( ioaddr + CONTROL ), CTL_POWERDOWN, ioaddr + CONTROL );
401 #endif
406 . Function: smc_setmulticast( int ioaddr, int count, dev_mc_list * adds )
407 . Purpose:
408 . This sets the internal hardware table to filter out unwanted multicast
409 . packets before they take up memory.
411 . The SMC chip uses a hash table where the high 6 bits of the CRC of
412 . address are the offset into the table. If that bit is 1, then the
413 . multicast packet is accepted. Otherwise, it's dropped silently.
415 . To use the 6 bits as an offset into the table, the high 3 bits are the
416 . number of the 8 bit register, while the low 3 bits are the bit within
417 . that register.
419 . This routine is based very heavily on the one provided by Peter Cammaert.
423 static void smc_setmulticast( int ioaddr, int count, struct dev_mc_list * addrs ) {
424 int i;
425 unsigned char multicast_table[ 8 ];
426 struct dev_mc_list * cur_addr;
427 /* table for flipping the order of 3 bits */
428 unsigned char invert3[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
430 /* start with a table of all zeros: reject all */
431 memset( multicast_table, 0, sizeof( multicast_table ) );
433 cur_addr = addrs;
434 for ( i = 0; i < count ; i ++, cur_addr = cur_addr->next ) {
435 int position;
437 /* do we have a pointer here? */
438 if ( !cur_addr )
439 break;
440 /* make sure this is a multicast address - shouldn't this
441 be a given if we have it here ? */
442 if ( !( *cur_addr->dmi_addr & 1 ) )
443 continue;
445 /* only use the low order bits */
446 position = crc32( cur_addr->dmi_addr, 6 ) & 0x3f;
448 /* do some messy swapping to put the bit in the right spot */
449 multicast_table[invert3[position&7]] |=
450 (1<<invert3[(position>>3)&7]);
453 /* now, the table can be loaded into the chipset */
454 SMC_SELECT_BANK( 3 );
456 for ( i = 0; i < 8 ; i++ ) {
457 outb( multicast_table[i], ioaddr + MULTICAST1 + i );
462 Finds the CRC32 of a set of bytes.
463 Again, from Peter Cammaert's code.
465 static int crc32( char * s, int length ) {
466 /* indices */
467 int perByte;
468 int perBit;
469 /* crc polynomial for Ethernet */
470 const unsigned long poly = 0xedb88320;
471 /* crc value - preinitialized to all 1's */
472 unsigned long crc_value = 0xffffffff;
474 for ( perByte = 0; perByte < length; perByte ++ ) {
475 unsigned char c;
477 c = *(s++);
478 for ( perBit = 0; perBit < 8; perBit++ ) {
479 crc_value = (crc_value>>1)^
480 (((crc_value^c)&0x01)?poly:0);
481 c >>= 1;
484 return crc_value;
489 . Function: smc_wait_to_send_packet( struct sk_buff * skb, struct net_device * )
490 . Purpose:
491 . Attempt to allocate memory for a packet, if chip-memory is not
492 . available, then tell the card to generate an interrupt when it
493 . is available.
495 . Algorithm:
497 . o if the saved_skb is not currently null, then drop this packet
498 . on the floor. This should never happen, because of TBUSY.
499 . o if the saved_skb is null, then replace it with the current packet,
500 . o See if I can sending it now.
501 . o (NO): Enable interrupts and let the interrupt handler deal with it.
502 . o (YES):Send it now.
504 static int smc_wait_to_send_packet( struct sk_buff * skb, struct net_device * dev )
506 struct smc_local *lp = (struct smc_local *)dev->priv;
507 unsigned short ioaddr = dev->base_addr;
508 word length;
509 unsigned short numPages;
510 word time_out;
512 if ( lp->saved_skb) {
513 /* THIS SHOULD NEVER HAPPEN. */
514 lp->stats.tx_aborted_errors++;
515 printk(CARDNAME": Bad Craziness - sent packet while busy.\n" );
516 return 1;
518 lp->saved_skb = skb;
520 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
524 ** The MMU wants the number of pages to be the number of 256 bytes
525 ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
527 ** Pkt size for allocating is data length +6 (for additional status words,
528 ** length and ctl!) If odd size last byte is included in this header.
530 numPages = ((length & 0xfffe) + 6) / 256;
532 if (numPages > 7 ) {
533 printk(CARDNAME": Far too big packet error. \n");
534 /* freeing the packet is a good thing here... but should
535 . any packets of this size get down here? */
536 dev_kfree_skb (skb);
537 lp->saved_skb = NULL;
538 /* this IS an error, but, i don't want the skb saved */
539 netif_wake_queue(dev);
540 return 0;
542 /* either way, a packet is waiting now */
543 lp->packets_waiting++;
545 /* now, try to allocate the memory */
546 SMC_SELECT_BANK( 2 );
547 outw( MC_ALLOC | numPages, ioaddr + MMU_CMD );
549 . Performance Hack
551 . wait a short amount of time.. if I can send a packet now, I send
552 . it now. Otherwise, I enable an interrupt and wait for one to be
553 . available.
555 . I could have handled this a slightly different way, by checking to
556 . see if any memory was available in the FREE MEMORY register. However,
557 . either way, I need to generate an allocation, and the allocation works
558 . no matter what, so I saw no point in checking free memory.
560 time_out = MEMORY_WAIT_TIME;
561 do {
562 word status;
564 status = inb( ioaddr + INTERRUPT );
565 if ( status & IM_ALLOC_INT ) {
566 /* acknowledge the interrupt */
567 outb( IM_ALLOC_INT, ioaddr + INTERRUPT );
568 break;
570 } while ( -- time_out );
572 if ( !time_out ) {
573 /* oh well, wait until the chip finds memory later */
574 SMC_ENABLE_INT( IM_ALLOC_INT );
575 PRINTK2((CARDNAME": memory allocation deferred. \n"));
576 /* it's deferred, but I'll handle it later */
577 return 0;
579 /* or YES! I can send the packet now.. */
580 smc_hardware_send_packet(dev);
581 netif_wake_queue(dev);
582 return 0;
586 . Function: smc_hardware_send_packet(struct net_device * )
587 . Purpose:
588 . This sends the actual packet to the SMC9xxx chip.
590 . Algorithm:
591 . First, see if a saved_skb is available.
592 . ( this should NOT be called if there is no 'saved_skb'
593 . Now, find the packet number that the chip allocated
594 . Point the data pointers at it in memory
595 . Set the length word in the chip's memory
596 . Dump the packet to chip memory
597 . Check if a last byte is needed ( odd length packet )
598 . if so, set the control flag right
599 . Tell the card to send it
600 . Enable the transmit interrupt, so I know if it failed
601 . Free the kernel data if I actually sent it.
603 static void smc_hardware_send_packet( struct net_device * dev )
605 struct smc_local *lp = (struct smc_local *)dev->priv;
606 byte packet_no;
607 struct sk_buff * skb = lp->saved_skb;
608 word length;
609 unsigned short ioaddr;
610 byte * buf;
612 ioaddr = dev->base_addr;
614 if ( !skb ) {
615 PRINTK((CARDNAME": In XMIT with no packet to send \n"));
616 return;
618 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
619 buf = skb->data;
621 /* If I get here, I _know_ there is a packet slot waiting for me */
622 packet_no = inb( ioaddr + PNR_ARR + 1 );
623 if ( packet_no & 0x80 ) {
624 /* or isn't there? BAD CHIP! */
625 printk(KERN_DEBUG CARDNAME": Memory allocation failed. \n");
626 kfree(skb);
627 lp->saved_skb = NULL;
628 netif_wake_queue(dev);
629 return;
632 /* we have a packet address, so tell the card to use it */
633 outb( packet_no, ioaddr + PNR_ARR );
635 /* point to the beginning of the packet */
636 outw( PTR_AUTOINC , ioaddr + POINTER );
638 PRINTK3((CARDNAME": Trying to xmit packet of length %x\n", length ));
639 #if SMC_DEBUG > 2
640 print_packet( buf, length );
641 #endif
643 /* send the packet length ( +6 for status, length and ctl byte )
644 and the status word ( set to zeros ) */
645 #ifdef USE_32_BIT
646 outl( (length +6 ) << 16 , ioaddr + DATA_1 );
647 #else
648 outw( 0, ioaddr + DATA_1 );
649 /* send the packet length ( +6 for status words, length, and ctl*/
650 outb( (length+6) & 0xFF,ioaddr + DATA_1 );
651 outb( (length+6) >> 8 , ioaddr + DATA_1 );
652 #endif
654 /* send the actual data
655 . I _think_ it's faster to send the longs first, and then
656 . mop up by sending the last word. It depends heavily
657 . on alignment, at least on the 486. Maybe it would be
658 . a good idea to check which is optimal? But that could take
659 . almost as much time as is saved?
661 #ifdef USE_32_BIT
662 if ( length & 0x2 ) {
663 outsl(ioaddr + DATA_1, buf, length >> 2 );
664 outw( *((word *)(buf + (length & 0xFFFFFFFC))),ioaddr +DATA_1);
666 else
667 outsl(ioaddr + DATA_1, buf, length >> 2 );
668 #else
669 outsw(ioaddr + DATA_1 , buf, (length ) >> 1);
670 #endif
671 /* Send the last byte, if there is one. */
673 if ( (length & 1) == 0 ) {
674 outw( 0, ioaddr + DATA_1 );
675 } else {
676 outb( buf[length -1 ], ioaddr + DATA_1 );
677 outb( 0x20, ioaddr + DATA_1);
680 /* enable the interrupts */
681 SMC_ENABLE_INT( (IM_TX_INT | IM_TX_EMPTY_INT) );
683 /* and let the chipset deal with it */
684 outw( MC_ENQUEUE , ioaddr + MMU_CMD );
686 PRINTK2((CARDNAME": Sent packet of length %d \n",length));
688 lp->saved_skb = NULL;
689 dev_kfree_skb (skb);
691 dev->trans_start = jiffies;
693 /* we can send another packet */
694 netif_wake_queue(dev);
696 return;
699 /*-------------------------------------------------------------------------
701 | smc_init( struct net_device * dev )
702 | Input parameters:
703 | dev->base_addr == 0, try to find all possible locations
704 | dev->base_addr == 1, return failure code
705 | dev->base_addr == 2, always allocate space, and return success
706 | dev->base_addr == <anything else> this is the address to check
708 | Output:
709 | 0 --> there is a device
710 | anything else, error
712 ---------------------------------------------------------------------------
714 int __init smc_init(struct net_device *dev)
716 int i;
717 int base_addr = dev ? dev->base_addr : 0;
719 /* try a specific location */
720 if (base_addr > 0x1ff) {
721 int error;
722 error = smc_probe(base_addr);
723 if ( 0 == error ) {
724 return smc_initcard( dev, base_addr );
726 return error;
727 } else {
728 if ( 0 != base_addr ) {
729 return -ENXIO;
733 /* check every ethernet address */
734 for (i = 0; smc_portlist[i]; i++) {
735 int ioaddr = smc_portlist[i];
737 /* check if the area is available */
738 if (check_region( ioaddr , SMC_IO_EXTENT))
739 continue;
741 /* check this specific address */
742 if ( smc_probe( ioaddr ) == 0) {
743 return smc_initcard( dev, ioaddr );
747 /* couldn't find anything */
748 return -ENODEV;
751 /*----------------------------------------------------------------------
752 . smc_findirq
754 . This routine has a simple purpose -- make the SMC chip generate an
755 . interrupt, so an auto-detect routine can detect it, and find the IRQ,
756 ------------------------------------------------------------------------
758 int __init smc_findirq( int ioaddr )
760 int timeout = 20;
763 /* I have to do a STI() here, because this is called from
764 a routine that does an CLI during this process, making it
765 rather difficult to get interrupts for auto detection */
766 sti();
768 autoirq_setup( 0 );
771 * What I try to do here is trigger an ALLOC_INT. This is done
772 * by allocating a small chunk of memory, which will give an interrupt
773 * when done.
777 SMC_SELECT_BANK(2);
778 /* enable ALLOCation interrupts ONLY */
779 outb( IM_ALLOC_INT, ioaddr + INT_MASK );
782 . Allocate 512 bytes of memory. Note that the chip was just
783 . reset so all the memory is available
785 outw( MC_ALLOC | 1, ioaddr + MMU_CMD );
788 . Wait until positive that the interrupt has been generated
790 while ( timeout ) {
791 byte int_status;
793 int_status = inb( ioaddr + INTERRUPT );
795 if ( int_status & IM_ALLOC_INT )
796 break; /* got the interrupt */
797 timeout--;
799 /* there is really nothing that I can do here if timeout fails,
800 as autoirq_report will return a 0 anyway, which is what I
801 want in this case. Plus, the clean up is needed in both
802 cases. */
804 /* DELAY HERE!
805 On a fast machine, the status might change before the interrupt
806 is given to the processor. This means that the interrupt was
807 never detected, and autoirq_report fails to report anything.
808 This should fix autoirq_* problems.
810 SMC_DELAY();
811 SMC_DELAY();
813 /* and disable all interrupts again */
814 outb( 0, ioaddr + INT_MASK );
816 /* clear hardware interrupts again, because that's how it
817 was when I was called... */
818 cli();
820 /* and return what I found */
821 return autoirq_report( 0 );
824 /*----------------------------------------------------------------------
825 . Function: smc_probe( int ioaddr )
827 . Purpose:
828 . Tests to see if a given ioaddr points to an SMC9xxx chip.
829 . Returns a 0 on success
831 . Algorithm:
832 . (1) see if the high byte of BANK_SELECT is 0x33
833 . (2) compare the ioaddr with the base register's address
834 . (3) see if I recognize the chip ID in the appropriate register
836 .---------------------------------------------------------------------
839 static int __init smc_probe( int ioaddr )
841 unsigned int bank;
842 word revision_register;
843 word base_address_register;
845 /* First, see if the high byte is 0x33 */
846 bank = inw( ioaddr + BANK_SELECT );
847 if ( (bank & 0xFF00) != 0x3300 ) {
848 return -ENODEV;
850 /* The above MIGHT indicate a device, but I need to write to further
851 test this. */
852 outw( 0x0, ioaddr + BANK_SELECT );
853 bank = inw( ioaddr + BANK_SELECT );
854 if ( (bank & 0xFF00 ) != 0x3300 ) {
855 return -ENODEV;
857 /* well, we've already written once, so hopefully another time won't
858 hurt. This time, I need to switch the bank register to bank 1,
859 so I can access the base address register */
860 SMC_SELECT_BANK(1);
861 base_address_register = inw( ioaddr + BASE );
862 if ( ioaddr != ( base_address_register >> 3 & 0x3E0 ) ) {
863 printk(CARDNAME ": IOADDR %x doesn't match configuration (%x)."
864 "Probably not a SMC chip\n",
865 ioaddr, base_address_register >> 3 & 0x3E0 );
866 /* well, the base address register didn't match. Must not have
867 been a SMC chip after all. */
868 return -ENODEV;
871 /* check if the revision register is something that I recognize.
872 These might need to be added to later, as future revisions
873 could be added. */
874 SMC_SELECT_BANK(3);
875 revision_register = inw( ioaddr + REVISION );
876 if ( !chip_ids[ ( revision_register >> 4 ) & 0xF ] ) {
877 /* I don't recognize this chip, so... */
878 printk(CARDNAME ": IO %x: Unrecognized revision register:"
879 " %x, Contact author. \n", ioaddr, revision_register );
881 return -ENODEV;
884 /* at this point I'll assume that the chip is an SMC9xxx.
885 It might be prudent to check a listing of MAC addresses
886 against the hardware address, or do some other tests. */
887 return 0;
890 /*---------------------------------------------------------------
891 . Here I do typical initialization tasks.
893 . o Initialize the structure if needed
894 . o print out my vanity message if not done so already
895 . o print out what type of hardware is detected
896 . o print out the ethernet address
897 . o find the IRQ
898 . o set up my private data
899 . o configure the dev structure with my subroutines
900 . o actually GRAB the irq.
901 . o GRAB the region
902 .-----------------------------------------------------------------
904 static int __init smc_initcard(struct net_device *dev, int ioaddr)
906 int i;
908 static unsigned version_printed = 0;
910 /* registers */
911 word revision_register;
912 word configuration_register;
913 word memory_info_register;
914 word memory_cfg_register;
916 const char * version_string;
917 const char * if_string;
918 int memory;
920 int irqval;
922 /* see if I need to initialize the ethernet card structure */
923 if (dev == NULL) {
924 dev = init_etherdev(0, 0);
925 if (dev == NULL)
926 return -ENOMEM;
929 if (version_printed++ == 0)
930 printk("%s", version);
932 /* fill in some of the fields */
933 dev->base_addr = ioaddr;
936 . Get the MAC address ( bank 1, regs 4 - 9 )
938 SMC_SELECT_BANK( 1 );
939 for ( i = 0; i < 6; i += 2 ) {
940 word address;
942 address = inw( ioaddr + ADDR0 + i );
943 dev->dev_addr[ i + 1] = address >> 8;
944 dev->dev_addr[ i ] = address & 0xFF;
947 /* get the memory information */
949 SMC_SELECT_BANK( 0 );
950 memory_info_register = inw( ioaddr + MIR );
951 memory_cfg_register = inw( ioaddr + MCR );
952 memory = ( memory_cfg_register >> 9 ) & 0x7; /* multiplier */
953 memory *= 256 * ( memory_info_register & 0xFF );
956 Now, I want to find out more about the chip. This is sort of
957 redundant, but it's cleaner to have it in both, rather than having
958 one VERY long probe procedure.
960 SMC_SELECT_BANK(3);
961 revision_register = inw( ioaddr + REVISION );
962 version_string = chip_ids[ ( revision_register >> 4 ) & 0xF ];
963 if ( !version_string ) {
964 /* I shouldn't get here because this call was done before.... */
965 return -ENODEV;
968 /* is it using AUI or 10BaseT ? */
969 if ( dev->if_port == 0 ) {
970 SMC_SELECT_BANK(1);
971 configuration_register = inw( ioaddr + CONFIG );
972 if ( configuration_register & CFG_AUI_SELECT )
973 dev->if_port = 2;
974 else
975 dev->if_port = 1;
977 if_string = interfaces[ dev->if_port - 1 ];
979 /* now, reset the chip, and put it into a known state */
980 smc_reset( ioaddr );
983 . If dev->irq is 0, then the device has to be banged on to see
984 . what the IRQ is.
986 . This banging doesn't always detect the IRQ, for unknown reasons.
987 . a workaround is to reset the chip and try again.
989 . Interestingly, the DOS packet driver *SETS* the IRQ on the card to
990 . be what is requested on the command line. I don't do that, mostly
991 . because the card that I have uses a non-standard method of accessing
992 . the IRQs, and because this _should_ work in most configurations.
994 . Specifying an IRQ is done with the assumption that the user knows
995 . what (s)he is doing. No checking is done!!!!
998 if ( dev->irq < 2 ) {
999 int trials;
1001 trials = 3;
1002 while ( trials-- ) {
1003 dev->irq = smc_findirq( ioaddr );
1004 if ( dev->irq )
1005 break;
1006 /* kick the card and try again */
1007 smc_reset( ioaddr );
1010 if (dev->irq == 0 ) {
1011 printk(CARDNAME": Couldn't autodetect your IRQ. Use irq=xx.\n");
1012 return -ENODEV;
1014 if (dev->irq == 2) {
1015 /* Fixup for users that don't know that IRQ 2 is really IRQ 9,
1016 * or don't know which one to set.
1018 dev->irq = 9;
1021 /* now, print out the card info, in a short format.. */
1023 printk(CARDNAME ": %s(r:%d) at %#3x IRQ:%d INTF:%s MEM:%db ",
1024 version_string, revision_register & 0xF, ioaddr, dev->irq,
1025 if_string, memory );
1027 . Print the Ethernet address
1029 printk("ADDR: ");
1030 for (i = 0; i < 5; i++)
1031 printk("%2.2x:", dev->dev_addr[i] );
1032 printk("%2.2x \n", dev->dev_addr[5] );
1035 /* Initialize the private structure. */
1036 if (dev->priv == NULL) {
1037 dev->priv = kmalloc(sizeof(struct smc_local), GFP_KERNEL);
1038 if (dev->priv == NULL)
1039 return -ENOMEM;
1041 /* set the private data to zero by default */
1042 memset(dev->priv, 0, sizeof(struct smc_local));
1044 /* Fill in the fields of the device structure with ethernet values. */
1045 ether_setup(dev);
1047 /* Grab the IRQ */
1048 irqval = request_irq(dev->irq, &smc_interrupt, 0, CARDNAME, dev);
1049 if (irqval) {
1050 printk(CARDNAME": unable to get IRQ %d (irqval=%d).\n",
1051 dev->irq, irqval);
1052 return -EAGAIN;
1055 /* Grab the region so that no one else tries to probe our ioports. */
1056 request_region(ioaddr, SMC_IO_EXTENT, CARDNAME);
1058 dev->open = smc_open;
1059 dev->stop = smc_close;
1060 dev->hard_start_xmit = smc_send_packet;
1061 dev->tx_timeout = smc_timeout;
1062 dev->watchdog_timeo = HZ/20;
1063 dev->get_stats = smc_query_statistics;
1064 dev->set_multicast_list = smc_set_multicast_list;
1066 return 0;
1069 #if SMC_DEBUG > 2
1070 static void print_packet( byte * buf, int length )
1072 #if 0
1073 int i;
1074 int remainder;
1075 int lines;
1077 printk("Packet of length %d \n", length );
1078 lines = length / 16;
1079 remainder = length % 16;
1081 for ( i = 0; i < lines ; i ++ ) {
1082 int cur;
1084 for ( cur = 0; cur < 8; cur ++ ) {
1085 byte a, b;
1087 a = *(buf ++ );
1088 b = *(buf ++ );
1089 printk("%02x%02x ", a, b );
1091 printk("\n");
1093 for ( i = 0; i < remainder/2 ; i++ ) {
1094 byte a, b;
1096 a = *(buf ++ );
1097 b = *(buf ++ );
1098 printk("%02x%02x ", a, b );
1100 printk("\n");
1101 #endif
1103 #endif
1107 * Open and Initialize the board
1109 * Set up everything, reset the card, etc ..
1112 static int smc_open(struct net_device *dev)
1114 int ioaddr = dev->base_addr;
1116 int i; /* used to set hw ethernet address */
1118 /* clear out all the junk that was put here before... */
1119 memset(dev->priv, 0, sizeof(struct smc_local));
1121 MOD_INC_USE_COUNT;
1123 /* reset the hardware */
1125 smc_reset( ioaddr );
1126 smc_enable( ioaddr );
1128 /* Select which interface to use */
1130 SMC_SELECT_BANK( 1 );
1131 if ( dev->if_port == 1 ) {
1132 outw( inw( ioaddr + CONFIG ) & ~CFG_AUI_SELECT,
1133 ioaddr + CONFIG );
1135 else if ( dev->if_port == 2 ) {
1136 outw( inw( ioaddr + CONFIG ) | CFG_AUI_SELECT,
1137 ioaddr + CONFIG );
1141 According to Becker, I have to set the hardware address
1142 at this point, because the (l)user can set it with an
1143 ioctl. Easily done...
1145 SMC_SELECT_BANK( 1 );
1146 for ( i = 0; i < 6; i += 2 ) {
1147 word address;
1149 address = dev->dev_addr[ i + 1 ] << 8 ;
1150 address |= dev->dev_addr[ i ];
1151 outw( address, ioaddr + ADDR0 + i );
1154 netif_start_queue(dev);
1155 return 0;
1158 /*--------------------------------------------------------
1159 . Called by the kernel to send a packet out into the void
1160 . of the net. This routine is largely based on
1161 . skeleton.c, from Becker.
1162 .--------------------------------------------------------
1165 static void smc_timeout(struct net_device *dev)
1167 /* If we get here, some higher level has decided we are broken.
1168 There should really be a "kick me" function call instead. */
1169 printk(KERN_WARNING CARDNAME": transmit timed out, %s?\n",
1170 tx_done(dev) ? "IRQ conflict" :
1171 "network cable problem");
1172 /* "kick" the adaptor */
1173 smc_reset( dev->base_addr );
1174 smc_enable( dev->base_addr );
1175 dev->trans_start = jiffies;
1176 /* clear anything saved */
1177 ((struct smc_local *)dev->priv)->saved_skb = NULL;
1178 netif_wake_queue(dev);
1181 static int smc_send_packet(struct sk_buff *skb, struct net_device *dev)
1183 netif_stop_queue(dev);
1184 /* Well, I want to send the packet.. but I don't know
1185 if I can send it right now... */
1186 return smc_wait_to_send_packet( skb, dev );
1189 /*--------------------------------------------------------------------
1191 . This is the main routine of the driver, to handle the device when
1192 . it needs some attention.
1194 . So:
1195 . first, save state of the chipset
1196 . branch off into routines to handle each case, and acknowledge
1197 . each to the interrupt register
1198 . and finally restore state.
1200 ---------------------------------------------------------------------*/
1202 static void smc_interrupt(int irq, void * dev_id, struct pt_regs * regs)
1204 struct net_device *dev = dev_id;
1205 int ioaddr = dev->base_addr;
1206 struct smc_local *lp = (struct smc_local *)dev->priv;
1208 byte status;
1209 word card_stats;
1210 byte mask;
1211 int timeout;
1212 /* state registers */
1213 word saved_bank;
1214 word saved_pointer;
1218 PRINTK3((CARDNAME": SMC interrupt started \n"));
1220 saved_bank = inw( ioaddr + BANK_SELECT );
1222 SMC_SELECT_BANK(2);
1223 saved_pointer = inw( ioaddr + POINTER );
1225 mask = inb( ioaddr + INT_MASK );
1226 /* clear all interrupts */
1227 outb( 0, ioaddr + INT_MASK );
1230 /* set a timeout value, so I don't stay here forever */
1231 timeout = 4;
1233 PRINTK2((KERN_WARNING CARDNAME ": MASK IS %x \n", mask ));
1234 do {
1235 /* read the status flag, and mask it */
1236 status = inb( ioaddr + INTERRUPT ) & mask;
1237 if (!status )
1238 break;
1240 PRINTK3((KERN_WARNING CARDNAME
1241 ": Handling interrupt status %x \n", status ));
1243 if (status & IM_RCV_INT) {
1244 /* Got a packet(s). */
1245 PRINTK2((KERN_WARNING CARDNAME
1246 ": Receive Interrupt\n"));
1247 smc_rcv(dev);
1248 } else if (status & IM_TX_INT ) {
1249 PRINTK2((KERN_WARNING CARDNAME
1250 ": TX ERROR handled\n"));
1251 smc_tx(dev);
1252 outb(IM_TX_INT, ioaddr + INTERRUPT );
1253 } else if (status & IM_TX_EMPTY_INT ) {
1254 /* update stats */
1255 SMC_SELECT_BANK( 0 );
1256 card_stats = inw( ioaddr + COUNTER );
1257 /* single collisions */
1258 lp->stats.collisions += card_stats & 0xF;
1259 card_stats >>= 4;
1260 /* multiple collisions */
1261 lp->stats.collisions += card_stats & 0xF;
1263 /* these are for when linux supports these statistics */
1265 SMC_SELECT_BANK( 2 );
1266 PRINTK2((KERN_WARNING CARDNAME
1267 ": TX_BUFFER_EMPTY handled\n"));
1268 outb( IM_TX_EMPTY_INT, ioaddr + INTERRUPT );
1269 mask &= ~IM_TX_EMPTY_INT;
1270 lp->stats.tx_packets += lp->packets_waiting;
1271 lp->packets_waiting = 0;
1273 } else if (status & IM_ALLOC_INT ) {
1274 PRINTK2((KERN_DEBUG CARDNAME
1275 ": Allocation interrupt \n"));
1276 /* clear this interrupt so it doesn't happen again */
1277 mask &= ~IM_ALLOC_INT;
1279 smc_hardware_send_packet( dev );
1281 /* enable xmit interrupts based on this */
1282 mask |= ( IM_TX_EMPTY_INT | IM_TX_INT );
1284 /* and let the card send more packets to me */
1285 netif_wake_queue(dev);
1287 PRINTK2((CARDNAME": Handoff done successfully.\n"));
1288 } else if (status & IM_RX_OVRN_INT ) {
1289 lp->stats.rx_errors++;
1290 lp->stats.rx_fifo_errors++;
1291 outb( IM_RX_OVRN_INT, ioaddr + INTERRUPT );
1292 } else if (status & IM_EPH_INT ) {
1293 PRINTK((CARDNAME ": UNSUPPORTED: EPH INTERRUPT \n"));
1294 } else if (status & IM_ERCV_INT ) {
1295 PRINTK((CARDNAME ": UNSUPPORTED: ERCV INTERRUPT \n"));
1296 outb( IM_ERCV_INT, ioaddr + INTERRUPT );
1298 } while ( timeout -- );
1301 /* restore state register */
1302 SMC_SELECT_BANK( 2 );
1303 outb( mask, ioaddr + INT_MASK );
1305 PRINTK3(( KERN_WARNING CARDNAME ": MASK is now %x \n", mask ));
1306 outw( saved_pointer, ioaddr + POINTER );
1308 SMC_SELECT_BANK( saved_bank );
1310 PRINTK3((CARDNAME ": Interrupt done\n"));
1311 return;
1314 /*-------------------------------------------------------------
1316 . smc_rcv - receive a packet from the card
1318 . There is ( at least ) a packet waiting to be read from
1319 . chip-memory.
1321 . o Read the status
1322 . o If an error, record it
1323 . o otherwise, read in the packet
1324 --------------------------------------------------------------
1326 static void smc_rcv(struct net_device *dev)
1328 struct smc_local *lp = (struct smc_local *)dev->priv;
1329 int ioaddr = dev->base_addr;
1330 int packet_number;
1331 word status;
1332 word packet_length;
1334 /* assume bank 2 */
1336 packet_number = inw( ioaddr + FIFO_PORTS );
1338 if ( packet_number & FP_RXEMPTY ) {
1339 /* we got called , but nothing was on the FIFO */
1340 PRINTK((CARDNAME ": WARNING: smc_rcv with nothing on FIFO. \n"));
1341 /* don't need to restore anything */
1342 return;
1345 /* start reading from the start of the packet */
1346 outw( PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER );
1348 /* First two words are status and packet_length */
1349 status = inw( ioaddr + DATA_1 );
1350 packet_length = inw( ioaddr + DATA_1 );
1352 packet_length &= 0x07ff; /* mask off top bits */
1354 PRINTK2(("RCV: STATUS %4x LENGTH %4x\n", status, packet_length ));
1356 . the packet length contains 3 extra words :
1357 . status, length, and an extra word with an odd byte .
1359 packet_length -= 6;
1361 if ( !(status & RS_ERRORS ) ){
1362 /* do stuff to make a new packet */
1363 struct sk_buff * skb;
1364 byte * data;
1366 /* read one extra byte */
1367 if ( status & RS_ODDFRAME )
1368 packet_length++;
1370 /* set multicast stats */
1371 if ( status & RS_MULTICAST )
1372 lp->stats.multicast++;
1374 skb = dev_alloc_skb( packet_length + 5);
1376 if ( skb == NULL ) {
1377 printk(KERN_NOTICE CARDNAME
1378 ": Low memory, packet dropped.\n");
1379 lp->stats.rx_dropped++;
1383 ! This should work without alignment, but it could be
1384 ! in the worse case
1387 skb_reserve( skb, 2 ); /* 16 bit alignment */
1389 skb->dev = dev;
1390 data = skb_put( skb, packet_length);
1392 #ifdef USE_32_BIT
1393 /* QUESTION: Like in the TX routine, do I want
1394 to send the DWORDs or the bytes first, or some
1395 mixture. A mixture might improve already slow PIO
1396 performance */
1397 PRINTK3((" Reading %d dwords (and %d bytes) \n",
1398 packet_length >> 2, packet_length & 3 ));
1399 insl(ioaddr + DATA_1 , data, packet_length >> 2 );
1400 /* read the left over bytes */
1401 insb( ioaddr + DATA_1, data + (packet_length & 0xFFFFFC),
1402 packet_length & 0x3 );
1403 #else
1404 PRINTK3((" Reading %d words and %d byte(s) \n",
1405 (packet_length >> 1 ), packet_length & 1 );
1406 if ( packet_length & 1 )
1407 *(data++) = inb( ioaddr + DATA_1 );
1408 insw(ioaddr + DATA_1 , data, (packet_length + 1 ) >> 1);
1409 if ( packet_length & 1 ) {
1410 data += packet_length & ~1;
1411 *((data++) = inb( ioaddr + DATA_1 );
1413 #endif
1414 #if SMC_DEBUG > 2
1415 print_packet( data, packet_length );
1416 #endif
1418 skb->protocol = eth_type_trans(skb, dev );
1419 netif_rx(skb);
1420 lp->stats.rx_packets++;
1421 } else {
1422 /* error ... */
1423 lp->stats.rx_errors++;
1425 if ( status & RS_ALGNERR ) lp->stats.rx_frame_errors++;
1426 if ( status & (RS_TOOSHORT | RS_TOOLONG ) )
1427 lp->stats.rx_length_errors++;
1428 if ( status & RS_BADCRC) lp->stats.rx_crc_errors++;
1430 /* error or good, tell the card to get rid of this packet */
1431 outw( MC_RELEASE, ioaddr + MMU_CMD );
1434 return;
1438 /*************************************************************************
1439 . smc_tx
1441 . Purpose: Handle a transmit error message. This will only be called
1442 . when an error, because of the AUTO_RELEASE mode.
1444 . Algorithm:
1445 . Save pointer and packet no
1446 . Get the packet no from the top of the queue
1447 . check if it's valid ( if not, is this an error??? )
1448 . read the status word
1449 . record the error
1450 . ( resend? Not really, since we don't want old packets around )
1451 . Restore saved values
1452 ************************************************************************/
1453 static void smc_tx( struct net_device * dev )
1455 int ioaddr = dev->base_addr;
1456 struct smc_local *lp = (struct smc_local *)dev->priv;
1457 byte saved_packet;
1458 byte packet_no;
1459 word tx_status;
1462 /* assume bank 2 */
1464 saved_packet = inb( ioaddr + PNR_ARR );
1465 packet_no = inw( ioaddr + FIFO_PORTS );
1466 packet_no &= 0x7F;
1468 /* select this as the packet to read from */
1469 outb( packet_no, ioaddr + PNR_ARR );
1471 /* read the first word from this packet */
1472 outw( PTR_AUTOINC | PTR_READ, ioaddr + POINTER );
1474 tx_status = inw( ioaddr + DATA_1 );
1475 PRINTK3((CARDNAME": TX DONE STATUS: %4x \n", tx_status ));
1477 lp->stats.tx_errors++;
1478 if ( tx_status & TS_LOSTCAR ) lp->stats.tx_carrier_errors++;
1479 if ( tx_status & TS_LATCOL ) {
1480 printk(KERN_DEBUG CARDNAME
1481 ": Late collision occurred on last xmit.\n");
1482 lp->stats.tx_window_errors++;
1484 #if 0
1485 if ( tx_status & TS_16COL ) { ... }
1486 #endif
1488 if ( tx_status & TS_SUCCESS ) {
1489 printk(CARDNAME": Successful packet caused interrupt \n");
1491 /* re-enable transmit */
1492 SMC_SELECT_BANK( 0 );
1493 outw( inw( ioaddr + TCR ) | TCR_ENABLE, ioaddr + TCR );
1495 /* kill the packet */
1496 SMC_SELECT_BANK( 2 );
1497 outw( MC_FREEPKT, ioaddr + MMU_CMD );
1499 /* one less packet waiting for me */
1500 lp->packets_waiting--;
1502 outb( saved_packet, ioaddr + PNR_ARR );
1503 return;
1506 /*----------------------------------------------------
1507 . smc_close
1509 . this makes the board clean up everything that it can
1510 . and not talk to the outside world. Caused by
1511 . an 'ifconfig ethX down'
1513 -----------------------------------------------------*/
1514 static int smc_close(struct net_device *dev)
1516 netif_stop_queue(dev);
1517 /* clear everything */
1518 smc_shutdown( dev->base_addr );
1520 /* Update the statistics here. */
1521 MOD_DEC_USE_COUNT;
1522 return 0;
1525 /*------------------------------------------------------------
1526 . Get the current statistics.
1527 . This may be called with the card open or closed.
1528 .-------------------------------------------------------------*/
1529 static struct net_device_stats* smc_query_statistics(struct net_device *dev) {
1530 struct smc_local *lp = (struct smc_local *)dev->priv;
1532 return &lp->stats;
1535 /*-----------------------------------------------------------
1536 . smc_set_multicast_list
1538 . This routine will, depending on the values passed to it,
1539 . either make it accept multicast packets, go into
1540 . promiscuous mode ( for TCPDUMP and cousins ) or accept
1541 . a select set of multicast packets
1543 static void smc_set_multicast_list(struct net_device *dev)
1545 short ioaddr = dev->base_addr;
1547 SMC_SELECT_BANK(0);
1548 if ( dev->flags & IFF_PROMISC )
1549 outw( inw(ioaddr + RCR ) | RCR_PROMISC, ioaddr + RCR );
1551 /* BUG? I never disable promiscuous mode if multicasting was turned on.
1552 Now, I turn off promiscuous mode, but I don't do anything to multicasting
1553 when promiscuous mode is turned on.
1556 /* Here, I am setting this to accept all multicast packets.
1557 I don't need to zero the multicast table, because the flag is
1558 checked before the table is
1560 else if (dev->flags & IFF_ALLMULTI)
1561 outw( inw(ioaddr + RCR ) | RCR_ALMUL, ioaddr + RCR );
1563 /* We just get all multicast packets even if we only want them
1564 . from one source. This will be changed at some future
1565 . point. */
1566 else if (dev->mc_count ) {
1567 /* support hardware multicasting */
1569 /* be sure I get rid of flags I might have set */
1570 outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL),
1571 ioaddr + RCR );
1572 /* NOTE: this has to set the bank, so make sure it is the
1573 last thing called. The bank is set to zero at the top */
1574 smc_setmulticast( ioaddr, dev->mc_count, dev->mc_list );
1576 else {
1577 outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL),
1578 ioaddr + RCR );
1581 since I'm disabling all multicast entirely, I need to
1582 clear the multicast list
1584 SMC_SELECT_BANK( 3 );
1585 outw( 0, ioaddr + MULTICAST1 );
1586 outw( 0, ioaddr + MULTICAST2 );
1587 outw( 0, ioaddr + MULTICAST3 );
1588 outw( 0, ioaddr + MULTICAST4 );
1592 #ifdef MODULE
1594 static struct net_device devSMC9194 = {
1595 "", /* device name is inserted by linux/drivers/net/net_init.c */
1596 0, 0, 0, 0,
1597 0, 0, /* I/O address, IRQ */
1598 0, 0, 0, NULL, smc_init };
1600 int io = 0;
1601 int irq = 0;
1602 int ifport = 0;
1604 MODULE_PARM(io, "i");
1605 MODULE_PARM(irq, "i");
1606 MODULE_PARM(ifport, "i");
1608 int init_module(void)
1610 int result;
1612 if (io == 0)
1613 printk(KERN_WARNING
1614 CARDNAME": You shouldn't use auto-probing with insmod!\n" );
1616 /* copy the parameters from insmod into the device structure */
1617 devSMC9194.base_addr = io;
1618 devSMC9194.irq = irq;
1619 devSMC9194.if_port = ifport;
1620 if ((result = register_netdev(&devSMC9194)) != 0)
1621 return result;
1623 return 0;
1626 void cleanup_module(void)
1628 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1629 unregister_netdev(&devSMC9194);
1631 free_irq(devSMC9194.irq, &devSMC9194);
1632 release_region(devSMC9194.base_addr, SMC_IO_EXTENT);
1634 if (devSMC9194.priv)
1635 kfree_s(devSMC9194.priv, sizeof(struct smc_local));
1638 #endif /* MODULE */