classmate-laptop: Added some keys present in other devices
[linux-kbuild.git] / drivers / net / smc9194.c
blob8371b82323ac68795b6f6199142eb3a2243589ca
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 General 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 )
21 . contributors:
22 . Arnaldo Carvalho de Melo <acme@conectiva.com.br>
24 . Hardware multicast code from Peter Cammaert ( pc@denkart.be )
26 . Sources:
27 . o SMC databook
28 . o skeleton.c by Donald Becker ( becker@scyld.com )
29 . o ( a LOT of advice from Becker as well )
31 . History:
32 . 12/07/95 Erik Stahlman written, got receive/xmit handled
33 . 01/03/96 Erik Stahlman worked out some bugs, actually usable!!! :-)
34 . 01/06/96 Erik Stahlman cleaned up some, better testing, etc
35 . 01/29/96 Erik Stahlman fixed autoirq, added multicast
36 . 02/01/96 Erik Stahlman 1. disabled all interrupts in smc_reset
37 . 2. got rid of post-decrementing bug -- UGH.
38 . 02/13/96 Erik Stahlman Tried to fix autoirq failure. Added more
39 . descriptive error messages.
40 . 02/15/96 Erik Stahlman Fixed typo that caused detection failure
41 . 02/23/96 Erik Stahlman Modified it to fit into kernel tree
42 . Added support to change hardware address
43 . Cleared stats on opens
44 . 02/26/96 Erik Stahlman Trial support for Kernel 1.2.13
45 . Kludge for automatic IRQ detection
46 . 03/04/96 Erik Stahlman Fixed kernel 1.3.70 +
47 . Fixed bug reported by Gardner Buchanan in
48 . smc_enable, with outw instead of outb
49 . 03/06/96 Erik Stahlman Added hardware multicast from Peter Cammaert
50 . 04/14/00 Heiko Pruessing (SMA Regelsysteme) Fixed bug in chip memory
51 . allocation
52 . 08/20/00 Arnaldo Melo fix kfree(skb) in smc_hardware_send_packet
53 . 12/15/00 Christian Jullien fix "Warning: kfree_skb on hard IRQ"
54 . 11/08/01 Matt Domsch Use common crc32 function
55 ----------------------------------------------------------------------------*/
57 static const char version[] =
58 "smc9194.c:v0.14 12/15/00 by Erik Stahlman (erik@vt.edu)\n";
60 #include <linux/module.h>
61 #include <linux/kernel.h>
62 #include <linux/types.h>
63 #include <linux/fcntl.h>
64 #include <linux/interrupt.h>
65 #include <linux/ioport.h>
66 #include <linux/in.h>
67 #include <linux/slab.h>
68 #include <linux/string.h>
69 #include <linux/init.h>
70 #include <linux/crc32.h>
71 #include <linux/errno.h>
72 #include <linux/netdevice.h>
73 #include <linux/etherdevice.h>
74 #include <linux/skbuff.h>
75 #include <linux/bitops.h>
77 #include <asm/io.h>
79 #include "smc9194.h"
81 #define DRV_NAME "smc9194"
83 /*------------------------------------------------------------------------
85 . Configuration options, for the experienced user to change.
87 -------------------------------------------------------------------------*/
90 . Do you want to use 32 bit xfers? This should work on all chips, as
91 . the chipset is designed to accommodate them.
93 #ifdef __sh__
94 #undef USE_32_BIT
95 #else
96 #define USE_32_BIT 1
97 #endif
99 #if defined(__H8300H__) || defined(__H8300S__)
100 #define NO_AUTOPROBE
101 #undef insl
102 #undef outsl
103 #define insl(a,b,l) io_insl_noswap(a,b,l)
104 #define outsl(a,b,l) io_outsl_noswap(a,b,l)
105 #endif
108 .the SMC9194 can be at any of the following port addresses. To change,
109 .for a slightly different card, you can add it to the array. Keep in
110 .mind that the array must end in zero.
113 struct devlist {
114 unsigned int port;
115 unsigned int irq;
118 #if defined(CONFIG_H8S_EDOSK2674)
119 static struct devlist smc_devlist[] __initdata = {
120 {.port = 0xf80000, .irq = 16},
121 {.port = 0, .irq = 0 },
123 #else
124 static struct devlist smc_devlist[] __initdata = {
125 {.port = 0x200, .irq = 0},
126 {.port = 0x220, .irq = 0},
127 {.port = 0x240, .irq = 0},
128 {.port = 0x260, .irq = 0},
129 {.port = 0x280, .irq = 0},
130 {.port = 0x2A0, .irq = 0},
131 {.port = 0x2C0, .irq = 0},
132 {.port = 0x2E0, .irq = 0},
133 {.port = 0x300, .irq = 0},
134 {.port = 0x320, .irq = 0},
135 {.port = 0x340, .irq = 0},
136 {.port = 0x360, .irq = 0},
137 {.port = 0x380, .irq = 0},
138 {.port = 0x3A0, .irq = 0},
139 {.port = 0x3C0, .irq = 0},
140 {.port = 0x3E0, .irq = 0},
141 {.port = 0, .irq = 0},
143 #endif
145 . Wait time for memory to be free. This probably shouldn't be
146 . tuned that much, as waiting for this means nothing else happens
147 . in the system
149 #define MEMORY_WAIT_TIME 16
152 . DEBUGGING LEVELS
154 . 0 for normal operation
155 . 1 for slightly more details
156 . >2 for various levels of increasingly useless information
157 . 2 for interrupt tracking, status flags
158 . 3 for packet dumps, etc.
160 #define SMC_DEBUG 0
162 #if (SMC_DEBUG > 2 )
163 #define PRINTK3(x) printk x
164 #else
165 #define PRINTK3(x)
166 #endif
168 #if SMC_DEBUG > 1
169 #define PRINTK2(x) printk x
170 #else
171 #define PRINTK2(x)
172 #endif
174 #ifdef SMC_DEBUG
175 #define PRINTK(x) printk x
176 #else
177 #define PRINTK(x)
178 #endif
181 /*------------------------------------------------------------------------
183 . The internal workings of the driver. If you are changing anything
184 . here with the SMC stuff, you should have the datasheet and known
185 . what you are doing.
187 -------------------------------------------------------------------------*/
188 #define CARDNAME "SMC9194"
191 /* store this information for the driver.. */
192 struct smc_local {
194 If I have to wait until memory is available to send
195 a packet, I will store the skbuff here, until I get the
196 desired memory. Then, I'll send it out and free it.
198 struct sk_buff * saved_skb;
201 . This keeps track of how many packets that I have
202 . sent out. When an TX_EMPTY interrupt comes, I know
203 . that all of these have been sent.
205 int packets_waiting;
209 /*-----------------------------------------------------------------
211 . The driver can be entered at any of the following entry points.
213 .------------------------------------------------------------------ */
216 . This is called by register_netdev(). It is responsible for
217 . checking the portlist for the SMC9000 series chipset. If it finds
218 . one, then it will initialize the device, find the hardware information,
219 . and sets up the appropriate device parameters.
220 . NOTE: Interrupts are *OFF* when this procedure is called.
222 . NB:This shouldn't be static since it is referred to externally.
224 struct net_device *smc_init(int unit);
227 . The kernel calls this function when someone wants to use the device,
228 . typically 'ifconfig ethX up'.
230 static int smc_open(struct net_device *dev);
233 . Our watchdog timed out. Called by the networking layer
235 static void smc_timeout(struct net_device *dev);
238 . This is called by the kernel in response to 'ifconfig ethX down'. It
239 . is responsible for cleaning up everything that the open routine
240 . does, and maybe putting the card into a powerdown state.
242 static int smc_close(struct net_device *dev);
245 . Finally, a call to set promiscuous mode ( for TCPDUMP and related
246 . programs ) and multicast modes.
248 static void smc_set_multicast_list(struct net_device *dev);
251 /*---------------------------------------------------------------
253 . Interrupt level calls..
255 ----------------------------------------------------------------*/
258 . Handles the actual interrupt
260 static irqreturn_t smc_interrupt(int irq, void *);
262 . This is a separate procedure to handle the receipt of a packet, to
263 . leave the interrupt code looking slightly cleaner
265 static inline void smc_rcv( struct net_device *dev );
267 . This handles a TX interrupt, which is only called when an error
268 . relating to a packet is sent.
270 static inline void smc_tx( struct net_device * dev );
273 ------------------------------------------------------------
275 . Internal routines
277 ------------------------------------------------------------
281 . Test if a given location contains a chip, trying to cause as
282 . little damage as possible if it's not a SMC chip.
284 static int smc_probe(struct net_device *dev, int ioaddr);
287 . A rather simple routine to print out a packet for debugging purposes.
289 #if SMC_DEBUG > 2
290 static void print_packet( byte *, int );
291 #endif
293 #define tx_done(dev) 1
295 /* this is called to actually send the packet to the chip */
296 static void smc_hardware_send_packet( struct net_device * dev );
298 /* Since I am not sure if I will have enough room in the chip's ram
299 . to store the packet, I call this routine, which either sends it
300 . now, or generates an interrupt when the card is ready for the
301 . packet */
302 static netdev_tx_t smc_wait_to_send_packet( struct sk_buff * skb,
303 struct net_device *dev );
305 /* this does a soft reset on the device */
306 static void smc_reset( int ioaddr );
308 /* Enable Interrupts, Receive, and Transmit */
309 static void smc_enable( int ioaddr );
311 /* this puts the device in an inactive state */
312 static void smc_shutdown( int ioaddr );
314 /* This routine will find the IRQ of the driver if one is not
315 . specified in the input to the device. */
316 static int smc_findirq( int ioaddr );
319 . Function: smc_reset( int ioaddr )
320 . Purpose:
321 . This sets the SMC91xx chip to its normal state, hopefully from whatever
322 . mess that any other DOS driver has put it in.
324 . Maybe I should reset more registers to defaults in here? SOFTRESET should
325 . do that for me.
327 . Method:
328 . 1. send a SOFT RESET
329 . 2. wait for it to finish
330 . 3. enable autorelease mode
331 . 4. reset the memory management unit
332 . 5. clear all interrupts
335 static void smc_reset( int ioaddr )
337 /* This resets the registers mostly to defaults, but doesn't
338 affect EEPROM. That seems unnecessary */
339 SMC_SELECT_BANK( 0 );
340 outw( RCR_SOFTRESET, ioaddr + RCR );
342 /* this should pause enough for the chip to be happy */
343 SMC_DELAY( );
345 /* Set the transmit and receive configuration registers to
346 default values */
347 outw( RCR_CLEAR, ioaddr + RCR );
348 outw( TCR_CLEAR, ioaddr + TCR );
350 /* set the control register to automatically
351 release successfully transmitted packets, to make the best
352 use out of our limited memory */
353 SMC_SELECT_BANK( 1 );
354 outw( inw( ioaddr + CONTROL ) | CTL_AUTO_RELEASE , ioaddr + CONTROL );
356 /* Reset the MMU */
357 SMC_SELECT_BANK( 2 );
358 outw( MC_RESET, ioaddr + MMU_CMD );
360 /* Note: It doesn't seem that waiting for the MMU busy is needed here,
361 but this is a place where future chipsets _COULD_ break. Be wary
362 of issuing another MMU command right after this */
364 outb( 0, ioaddr + INT_MASK );
368 . Function: smc_enable
369 . Purpose: let the chip talk to the outside work
370 . Method:
371 . 1. Enable the transmitter
372 . 2. Enable the receiver
373 . 3. Enable interrupts
375 static void smc_enable( int ioaddr )
377 SMC_SELECT_BANK( 0 );
378 /* see the header file for options in TCR/RCR NORMAL*/
379 outw( TCR_NORMAL, ioaddr + TCR );
380 outw( RCR_NORMAL, ioaddr + RCR );
382 /* now, enable interrupts */
383 SMC_SELECT_BANK( 2 );
384 outb( SMC_INTERRUPT_MASK, ioaddr + INT_MASK );
388 . Function: smc_shutdown
389 . Purpose: closes down the SMC91xxx chip.
390 . Method:
391 . 1. zero the interrupt mask
392 . 2. clear the enable receive flag
393 . 3. clear the enable xmit flags
395 . TODO:
396 . (1) maybe utilize power down mode.
397 . Why not yet? Because while the chip will go into power down mode,
398 . the manual says that it will wake up in response to any I/O requests
399 . in the register space. Empirical results do not show this working.
401 static void smc_shutdown( int ioaddr )
403 /* no more interrupts for me */
404 SMC_SELECT_BANK( 2 );
405 outb( 0, ioaddr + INT_MASK );
407 /* and tell the card to stay away from that nasty outside world */
408 SMC_SELECT_BANK( 0 );
409 outb( RCR_CLEAR, ioaddr + RCR );
410 outb( TCR_CLEAR, ioaddr + TCR );
411 #if 0
412 /* finally, shut the chip down */
413 SMC_SELECT_BANK( 1 );
414 outw( inw( ioaddr + CONTROL ), CTL_POWERDOWN, ioaddr + CONTROL );
415 #endif
420 . Function: smc_setmulticast( int ioaddr, int count, dev_mc_list * adds )
421 . Purpose:
422 . This sets the internal hardware table to filter out unwanted multicast
423 . packets before they take up memory.
425 . The SMC chip uses a hash table where the high 6 bits of the CRC of
426 . address are the offset into the table. If that bit is 1, then the
427 . multicast packet is accepted. Otherwise, it's dropped silently.
429 . To use the 6 bits as an offset into the table, the high 3 bits are the
430 . number of the 8 bit register, while the low 3 bits are the bit within
431 . that register.
433 . This routine is based very heavily on the one provided by Peter Cammaert.
437 static void smc_setmulticast( int ioaddr, int count, struct dev_mc_list * addrs ) {
438 int i;
439 unsigned char multicast_table[ 8 ];
440 struct dev_mc_list * cur_addr;
441 /* table for flipping the order of 3 bits */
442 unsigned char invert3[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
444 /* start with a table of all zeros: reject all */
445 memset( multicast_table, 0, sizeof( multicast_table ) );
447 cur_addr = addrs;
448 for ( i = 0; i < count ; i ++, cur_addr = cur_addr->next ) {
449 int position;
451 /* do we have a pointer here? */
452 if ( !cur_addr )
453 break;
454 /* make sure this is a multicast address - shouldn't this
455 be a given if we have it here ? */
456 if ( !( *cur_addr->dmi_addr & 1 ) )
457 continue;
459 /* only use the low order bits */
460 position = ether_crc_le(6, cur_addr->dmi_addr) & 0x3f;
462 /* do some messy swapping to put the bit in the right spot */
463 multicast_table[invert3[position&7]] |=
464 (1<<invert3[(position>>3)&7]);
467 /* now, the table can be loaded into the chipset */
468 SMC_SELECT_BANK( 3 );
470 for ( i = 0; i < 8 ; i++ ) {
471 outb( multicast_table[i], ioaddr + MULTICAST1 + i );
476 . Function: smc_wait_to_send_packet( struct sk_buff * skb, struct net_device * )
477 . Purpose:
478 . Attempt to allocate memory for a packet, if chip-memory is not
479 . available, then tell the card to generate an interrupt when it
480 . is available.
482 . Algorithm:
484 . o if the saved_skb is not currently null, then drop this packet
485 . on the floor. This should never happen, because of TBUSY.
486 . o if the saved_skb is null, then replace it with the current packet,
487 . o See if I can sending it now.
488 . o (NO): Enable interrupts and let the interrupt handler deal with it.
489 . o (YES):Send it now.
491 static netdev_tx_t smc_wait_to_send_packet(struct sk_buff *skb,
492 struct net_device *dev)
494 struct smc_local *lp = netdev_priv(dev);
495 unsigned int ioaddr = dev->base_addr;
496 word length;
497 unsigned short numPages;
498 word time_out;
500 netif_stop_queue(dev);
501 /* Well, I want to send the packet.. but I don't know
502 if I can send it right now... */
504 if ( lp->saved_skb) {
505 /* THIS SHOULD NEVER HAPPEN. */
506 dev->stats.tx_aborted_errors++;
507 printk(CARDNAME": Bad Craziness - sent packet while busy.\n" );
508 return NETDEV_TX_BUSY;
510 lp->saved_skb = skb;
512 length = skb->len;
514 if (length < ETH_ZLEN) {
515 if (skb_padto(skb, ETH_ZLEN)) {
516 netif_wake_queue(dev);
517 return NETDEV_TX_OK;
519 length = ETH_ZLEN;
523 ** The MMU wants the number of pages to be the number of 256 bytes
524 ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
526 ** Pkt size for allocating is data length +6 (for additional status words,
527 ** length and ctl!) If odd size last byte is included in this header.
529 numPages = ((length & 0xfffe) + 6) / 256;
531 if (numPages > 7 ) {
532 printk(CARDNAME": Far too big packet error. \n");
533 /* freeing the packet is a good thing here... but should
534 . any packets of this size get down here? */
535 dev_kfree_skb (skb);
536 lp->saved_skb = NULL;
537 /* this IS an error, but, i don't want the skb saved */
538 netif_wake_queue(dev);
539 return NETDEV_TX_OK;
541 /* either way, a packet is waiting now */
542 lp->packets_waiting++;
544 /* now, try to allocate the memory */
545 SMC_SELECT_BANK( 2 );
546 outw( MC_ALLOC | numPages, ioaddr + MMU_CMD );
548 . Performance Hack
550 . wait a short amount of time.. if I can send a packet now, I send
551 . it now. Otherwise, I enable an interrupt and wait for one to be
552 . available.
554 . I could have handled this a slightly different way, by checking to
555 . see if any memory was available in the FREE MEMORY register. However,
556 . either way, I need to generate an allocation, and the allocation works
557 . no matter what, so I saw no point in checking free memory.
559 time_out = MEMORY_WAIT_TIME;
560 do {
561 word status;
563 status = inb( ioaddr + INTERRUPT );
564 if ( status & IM_ALLOC_INT ) {
565 /* acknowledge the interrupt */
566 outb( IM_ALLOC_INT, ioaddr + INTERRUPT );
567 break;
569 } while ( -- time_out );
571 if ( !time_out ) {
572 /* oh well, wait until the chip finds memory later */
573 SMC_ENABLE_INT( IM_ALLOC_INT );
574 PRINTK2((CARDNAME": memory allocation deferred. \n"));
575 /* it's deferred, but I'll handle it later */
576 return NETDEV_TX_OK;
578 /* or YES! I can send the packet now.. */
579 smc_hardware_send_packet(dev);
580 netif_wake_queue(dev);
581 return NETDEV_TX_OK;
585 . Function: smc_hardware_send_packet(struct net_device * )
586 . Purpose:
587 . This sends the actual packet to the SMC9xxx chip.
589 . Algorithm:
590 . First, see if a saved_skb is available.
591 . ( this should NOT be called if there is no 'saved_skb'
592 . Now, find the packet number that the chip allocated
593 . Point the data pointers at it in memory
594 . Set the length word in the chip's memory
595 . Dump the packet to chip memory
596 . Check if a last byte is needed ( odd length packet )
597 . if so, set the control flag right
598 . Tell the card to send it
599 . Enable the transmit interrupt, so I know if it failed
600 . Free the kernel data if I actually sent it.
602 static void smc_hardware_send_packet( struct net_device * dev )
604 struct smc_local *lp = netdev_priv(dev);
605 byte packet_no;
606 struct sk_buff * skb = lp->saved_skb;
607 word length;
608 unsigned int ioaddr;
609 byte * buf;
611 ioaddr = dev->base_addr;
613 if ( !skb ) {
614 PRINTK((CARDNAME": In XMIT with no packet to send \n"));
615 return;
617 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
618 buf = skb->data;
620 /* If I get here, I _know_ there is a packet slot waiting for me */
621 packet_no = inb( ioaddr + PNR_ARR + 1 );
622 if ( packet_no & 0x80 ) {
623 /* or isn't there? BAD CHIP! */
624 printk(KERN_DEBUG CARDNAME": Memory allocation failed. \n");
625 dev_kfree_skb_any(skb);
626 lp->saved_skb = NULL;
627 netif_wake_queue(dev);
628 return;
631 /* we have a packet address, so tell the card to use it */
632 outb( packet_no, ioaddr + PNR_ARR );
634 /* point to the beginning of the packet */
635 outw( PTR_AUTOINC , ioaddr + POINTER );
637 PRINTK3((CARDNAME": Trying to xmit packet of length %x\n", length ));
638 #if SMC_DEBUG > 2
639 print_packet( buf, length );
640 #endif
642 /* send the packet length ( +6 for status, length and ctl byte )
643 and the status word ( set to zeros ) */
644 #ifdef USE_32_BIT
645 outl( (length +6 ) << 16 , ioaddr + DATA_1 );
646 #else
647 outw( 0, ioaddr + DATA_1 );
648 /* send the packet length ( +6 for status words, length, and ctl*/
649 outb( (length+6) & 0xFF,ioaddr + DATA_1 );
650 outb( (length+6) >> 8 , ioaddr + DATA_1 );
651 #endif
653 /* send the actual data
654 . I _think_ it's faster to send the longs first, and then
655 . mop up by sending the last word. It depends heavily
656 . on alignment, at least on the 486. Maybe it would be
657 . a good idea to check which is optimal? But that could take
658 . almost as much time as is saved?
660 #ifdef USE_32_BIT
661 if ( length & 0x2 ) {
662 outsl(ioaddr + DATA_1, buf, length >> 2 );
663 #if !defined(__H8300H__) && !defined(__H8300S__)
664 outw( *((word *)(buf + (length & 0xFFFFFFFC))),ioaddr +DATA_1);
665 #else
666 ctrl_outw( *((word *)(buf + (length & 0xFFFFFFFC))),ioaddr +DATA_1);
667 #endif
669 else
670 outsl(ioaddr + DATA_1, buf, length >> 2 );
671 #else
672 outsw(ioaddr + DATA_1 , buf, (length ) >> 1);
673 #endif
674 /* Send the last byte, if there is one. */
676 if ( (length & 1) == 0 ) {
677 outw( 0, ioaddr + DATA_1 );
678 } else {
679 outb( buf[length -1 ], ioaddr + DATA_1 );
680 outb( 0x20, ioaddr + DATA_1);
683 /* enable the interrupts */
684 SMC_ENABLE_INT( (IM_TX_INT | IM_TX_EMPTY_INT) );
686 /* and let the chipset deal with it */
687 outw( MC_ENQUEUE , ioaddr + MMU_CMD );
689 PRINTK2((CARDNAME": Sent packet of length %d \n",length));
691 lp->saved_skb = NULL;
692 dev_kfree_skb_any (skb);
694 dev->trans_start = jiffies;
696 /* we can send another packet */
697 netif_wake_queue(dev);
699 return;
702 /*-------------------------------------------------------------------------
704 | smc_init(int unit)
705 | Input parameters:
706 | dev->base_addr == 0, try to find all possible locations
707 | dev->base_addr == 1, return failure code
708 | dev->base_addr == 2, always allocate space, and return success
709 | dev->base_addr == <anything else> this is the address to check
711 | Output:
712 | pointer to net_device or ERR_PTR(error)
714 ---------------------------------------------------------------------------
716 static int io;
717 static int irq;
718 static int ifport;
720 struct net_device * __init smc_init(int unit)
722 struct net_device *dev = alloc_etherdev(sizeof(struct smc_local));
723 struct devlist *smcdev = smc_devlist;
724 int err = 0;
726 if (!dev)
727 return ERR_PTR(-ENODEV);
729 if (unit >= 0) {
730 sprintf(dev->name, "eth%d", unit);
731 netdev_boot_setup_check(dev);
732 io = dev->base_addr;
733 irq = dev->irq;
736 if (io > 0x1ff) { /* Check a single specified location. */
737 err = smc_probe(dev, io);
738 } else if (io != 0) { /* Don't probe at all. */
739 err = -ENXIO;
740 } else {
741 for (;smcdev->port; smcdev++) {
742 if (smc_probe(dev, smcdev->port) == 0)
743 break;
745 if (!smcdev->port)
746 err = -ENODEV;
748 if (err)
749 goto out;
750 err = register_netdev(dev);
751 if (err)
752 goto out1;
753 return dev;
754 out1:
755 free_irq(dev->irq, dev);
756 release_region(dev->base_addr, SMC_IO_EXTENT);
757 out:
758 free_netdev(dev);
759 return ERR_PTR(err);
762 /*----------------------------------------------------------------------
763 . smc_findirq
765 . This routine has a simple purpose -- make the SMC chip generate an
766 . interrupt, so an auto-detect routine can detect it, and find the IRQ,
767 ------------------------------------------------------------------------
769 static int __init smc_findirq(int ioaddr)
771 #ifndef NO_AUTOPROBE
772 int timeout = 20;
773 unsigned long cookie;
776 cookie = probe_irq_on();
779 * What I try to do here is trigger an ALLOC_INT. This is done
780 * by allocating a small chunk of memory, which will give an interrupt
781 * when done.
785 SMC_SELECT_BANK(2);
786 /* enable ALLOCation interrupts ONLY */
787 outb( IM_ALLOC_INT, ioaddr + INT_MASK );
790 . Allocate 512 bytes of memory. Note that the chip was just
791 . reset so all the memory is available
793 outw( MC_ALLOC | 1, ioaddr + MMU_CMD );
796 . Wait until positive that the interrupt has been generated
798 while ( timeout ) {
799 byte int_status;
801 int_status = inb( ioaddr + INTERRUPT );
803 if ( int_status & IM_ALLOC_INT )
804 break; /* got the interrupt */
805 timeout--;
807 /* there is really nothing that I can do here if timeout fails,
808 as probe_irq_off will return a 0 anyway, which is what I
809 want in this case. Plus, the clean up is needed in both
810 cases. */
812 /* DELAY HERE!
813 On a fast machine, the status might change before the interrupt
814 is given to the processor. This means that the interrupt was
815 never detected, and probe_irq_off fails to report anything.
816 This should fix probe_irq_* problems.
818 SMC_DELAY();
819 SMC_DELAY();
821 /* and disable all interrupts again */
822 outb( 0, ioaddr + INT_MASK );
824 /* and return what I found */
825 return probe_irq_off(cookie);
826 #else /* NO_AUTOPROBE */
827 struct devlist *smcdev;
828 for (smcdev = smc_devlist; smcdev->port; smcdev++) {
829 if (smcdev->port == ioaddr)
830 return smcdev->irq;
832 return 0;
833 #endif
836 static const struct net_device_ops smc_netdev_ops = {
837 .ndo_open = smc_open,
838 .ndo_stop = smc_close,
839 .ndo_start_xmit = smc_wait_to_send_packet,
840 .ndo_tx_timeout = smc_timeout,
841 .ndo_set_multicast_list = smc_set_multicast_list,
842 .ndo_change_mtu = eth_change_mtu,
843 .ndo_set_mac_address = eth_mac_addr,
844 .ndo_validate_addr = eth_validate_addr,
847 /*----------------------------------------------------------------------
848 . Function: smc_probe( int ioaddr )
850 . Purpose:
851 . Tests to see if a given ioaddr points to an SMC9xxx chip.
852 . Returns a 0 on success
854 . Algorithm:
855 . (1) see if the high byte of BANK_SELECT is 0x33
856 . (2) compare the ioaddr with the base register's address
857 . (3) see if I recognize the chip ID in the appropriate register
859 .---------------------------------------------------------------------
862 /*---------------------------------------------------------------
863 . Here I do typical initialization tasks.
865 . o Initialize the structure if needed
866 . o print out my vanity message if not done so already
867 . o print out what type of hardware is detected
868 . o print out the ethernet address
869 . o find the IRQ
870 . o set up my private data
871 . o configure the dev structure with my subroutines
872 . o actually GRAB the irq.
873 . o GRAB the region
874 .-----------------------------------------------------------------
876 static int __init smc_probe(struct net_device *dev, int ioaddr)
878 int i, memory, retval;
879 static unsigned version_printed;
880 unsigned int bank;
882 const char *version_string;
883 const char *if_string;
885 /* registers */
886 word revision_register;
887 word base_address_register;
888 word configuration_register;
889 word memory_info_register;
890 word memory_cfg_register;
892 /* Grab the region so that no one else tries to probe our ioports. */
893 if (!request_region(ioaddr, SMC_IO_EXTENT, DRV_NAME))
894 return -EBUSY;
896 dev->irq = irq;
897 dev->if_port = ifport;
899 /* First, see if the high byte is 0x33 */
900 bank = inw( ioaddr + BANK_SELECT );
901 if ( (bank & 0xFF00) != 0x3300 ) {
902 retval = -ENODEV;
903 goto err_out;
905 /* The above MIGHT indicate a device, but I need to write to further
906 test this. */
907 outw( 0x0, ioaddr + BANK_SELECT );
908 bank = inw( ioaddr + BANK_SELECT );
909 if ( (bank & 0xFF00 ) != 0x3300 ) {
910 retval = -ENODEV;
911 goto err_out;
913 #if !defined(CONFIG_H8S_EDOSK2674)
914 /* well, we've already written once, so hopefully another time won't
915 hurt. This time, I need to switch the bank register to bank 1,
916 so I can access the base address register */
917 SMC_SELECT_BANK(1);
918 base_address_register = inw( ioaddr + BASE );
919 if ( ioaddr != ( base_address_register >> 3 & 0x3E0 ) ) {
920 printk(CARDNAME ": IOADDR %x doesn't match configuration (%x). "
921 "Probably not a SMC chip\n",
922 ioaddr, base_address_register >> 3 & 0x3E0 );
923 /* well, the base address register didn't match. Must not have
924 been a SMC chip after all. */
925 retval = -ENODEV;
926 goto err_out;
928 #else
929 (void)base_address_register; /* Warning suppression */
930 #endif
933 /* check if the revision register is something that I recognize.
934 These might need to be added to later, as future revisions
935 could be added. */
936 SMC_SELECT_BANK(3);
937 revision_register = inw( ioaddr + REVISION );
938 if ( !chip_ids[ ( revision_register >> 4 ) & 0xF ] ) {
939 /* I don't recognize this chip, so... */
940 printk(CARDNAME ": IO %x: Unrecognized revision register:"
941 " %x, Contact author. \n", ioaddr, revision_register );
943 retval = -ENODEV;
944 goto err_out;
947 /* at this point I'll assume that the chip is an SMC9xxx.
948 It might be prudent to check a listing of MAC addresses
949 against the hardware address, or do some other tests. */
951 if (version_printed++ == 0)
952 printk("%s", version);
954 /* fill in some of the fields */
955 dev->base_addr = ioaddr;
958 . Get the MAC address ( bank 1, regs 4 - 9 )
960 SMC_SELECT_BANK( 1 );
961 for ( i = 0; i < 6; i += 2 ) {
962 word address;
964 address = inw( ioaddr + ADDR0 + i );
965 dev->dev_addr[ i + 1] = address >> 8;
966 dev->dev_addr[ i ] = address & 0xFF;
969 /* get the memory information */
971 SMC_SELECT_BANK( 0 );
972 memory_info_register = inw( ioaddr + MIR );
973 memory_cfg_register = inw( ioaddr + MCR );
974 memory = ( memory_cfg_register >> 9 ) & 0x7; /* multiplier */
975 memory *= 256 * ( memory_info_register & 0xFF );
978 Now, I want to find out more about the chip. This is sort of
979 redundant, but it's cleaner to have it in both, rather than having
980 one VERY long probe procedure.
982 SMC_SELECT_BANK(3);
983 revision_register = inw( ioaddr + REVISION );
984 version_string = chip_ids[ ( revision_register >> 4 ) & 0xF ];
985 if ( !version_string ) {
986 /* I shouldn't get here because this call was done before.... */
987 retval = -ENODEV;
988 goto err_out;
991 /* is it using AUI or 10BaseT ? */
992 if ( dev->if_port == 0 ) {
993 SMC_SELECT_BANK(1);
994 configuration_register = inw( ioaddr + CONFIG );
995 if ( configuration_register & CFG_AUI_SELECT )
996 dev->if_port = 2;
997 else
998 dev->if_port = 1;
1000 if_string = interfaces[ dev->if_port - 1 ];
1002 /* now, reset the chip, and put it into a known state */
1003 smc_reset( ioaddr );
1006 . If dev->irq is 0, then the device has to be banged on to see
1007 . what the IRQ is.
1009 . This banging doesn't always detect the IRQ, for unknown reasons.
1010 . a workaround is to reset the chip and try again.
1012 . Interestingly, the DOS packet driver *SETS* the IRQ on the card to
1013 . be what is requested on the command line. I don't do that, mostly
1014 . because the card that I have uses a non-standard method of accessing
1015 . the IRQs, and because this _should_ work in most configurations.
1017 . Specifying an IRQ is done with the assumption that the user knows
1018 . what (s)he is doing. No checking is done!!!!
1021 if ( dev->irq < 2 ) {
1022 int trials;
1024 trials = 3;
1025 while ( trials-- ) {
1026 dev->irq = smc_findirq( ioaddr );
1027 if ( dev->irq )
1028 break;
1029 /* kick the card and try again */
1030 smc_reset( ioaddr );
1033 if (dev->irq == 0 ) {
1034 printk(CARDNAME": Couldn't autodetect your IRQ. Use irq=xx.\n");
1035 retval = -ENODEV;
1036 goto err_out;
1039 /* now, print out the card info, in a short format.. */
1041 printk("%s: %s(r:%d) at %#3x IRQ:%d INTF:%s MEM:%db ", dev->name,
1042 version_string, revision_register & 0xF, ioaddr, dev->irq,
1043 if_string, memory );
1045 . Print the Ethernet address
1047 printk("ADDR: %pM\n", dev->dev_addr);
1049 /* set the private data to zero by default */
1050 memset(netdev_priv(dev), 0, sizeof(struct smc_local));
1052 /* Grab the IRQ */
1053 retval = request_irq(dev->irq, smc_interrupt, 0, DRV_NAME, dev);
1054 if (retval) {
1055 printk("%s: unable to get IRQ %d (irqval=%d).\n", DRV_NAME,
1056 dev->irq, retval);
1057 goto err_out;
1060 dev->netdev_ops = &smc_netdev_ops;
1061 dev->watchdog_timeo = HZ/20;
1063 return 0;
1065 err_out:
1066 release_region(ioaddr, SMC_IO_EXTENT);
1067 return retval;
1070 #if SMC_DEBUG > 2
1071 static void print_packet( byte * buf, int length )
1073 #if 0
1074 int i;
1075 int remainder;
1076 int lines;
1078 printk("Packet of length %d \n", length );
1079 lines = length / 16;
1080 remainder = length % 16;
1082 for ( i = 0; i < lines ; i ++ ) {
1083 int cur;
1085 for ( cur = 0; cur < 8; cur ++ ) {
1086 byte a, b;
1088 a = *(buf ++ );
1089 b = *(buf ++ );
1090 printk("%02x%02x ", a, b );
1092 printk("\n");
1094 for ( i = 0; i < remainder/2 ; i++ ) {
1095 byte a, b;
1097 a = *(buf ++ );
1098 b = *(buf ++ );
1099 printk("%02x%02x ", a, b );
1101 printk("\n");
1102 #endif
1104 #endif
1108 * Open and Initialize the board
1110 * Set up everything, reset the card, etc ..
1113 static int smc_open(struct net_device *dev)
1115 int ioaddr = dev->base_addr;
1117 int i; /* used to set hw ethernet address */
1119 /* clear out all the junk that was put here before... */
1120 memset(netdev_priv(dev), 0, sizeof(struct smc_local));
1122 /* reset the hardware */
1124 smc_reset( ioaddr );
1125 smc_enable( ioaddr );
1127 /* Select which interface to use */
1129 SMC_SELECT_BANK( 1 );
1130 if ( dev->if_port == 1 ) {
1131 outw( inw( ioaddr + CONFIG ) & ~CFG_AUI_SELECT,
1132 ioaddr + CONFIG );
1134 else if ( dev->if_port == 2 ) {
1135 outw( inw( ioaddr + CONFIG ) | CFG_AUI_SELECT,
1136 ioaddr + CONFIG );
1140 According to Becker, I have to set the hardware address
1141 at this point, because the (l)user can set it with an
1142 ioctl. Easily done...
1144 SMC_SELECT_BANK( 1 );
1145 for ( i = 0; i < 6; i += 2 ) {
1146 word address;
1148 address = dev->dev_addr[ i + 1 ] << 8 ;
1149 address |= dev->dev_addr[ i ];
1150 outw( address, ioaddr + ADDR0 + i );
1153 netif_start_queue(dev);
1154 return 0;
1157 /*--------------------------------------------------------
1158 . Called by the kernel to send a packet out into the void
1159 . of the net. This routine is largely based on
1160 . skeleton.c, from Becker.
1161 .--------------------------------------------------------
1164 static void smc_timeout(struct net_device *dev)
1166 /* If we get here, some higher level has decided we are broken.
1167 There should really be a "kick me" function call instead. */
1168 printk(KERN_WARNING CARDNAME": transmit timed out, %s?\n",
1169 tx_done(dev) ? "IRQ conflict" :
1170 "network cable problem");
1171 /* "kick" the adaptor */
1172 smc_reset( dev->base_addr );
1173 smc_enable( dev->base_addr );
1174 dev->trans_start = jiffies;
1175 /* clear anything saved */
1176 ((struct smc_local *)netdev_priv(dev))->saved_skb = NULL;
1177 netif_wake_queue(dev);
1180 /*-------------------------------------------------------------
1182 . smc_rcv - receive a packet from the card
1184 . There is ( at least ) a packet waiting to be read from
1185 . chip-memory.
1187 . o Read the status
1188 . o If an error, record it
1189 . o otherwise, read in the packet
1190 --------------------------------------------------------------
1192 static void smc_rcv(struct net_device *dev)
1194 int ioaddr = dev->base_addr;
1195 int packet_number;
1196 word status;
1197 word packet_length;
1199 /* assume bank 2 */
1201 packet_number = inw( ioaddr + FIFO_PORTS );
1203 if ( packet_number & FP_RXEMPTY ) {
1204 /* we got called , but nothing was on the FIFO */
1205 PRINTK((CARDNAME ": WARNING: smc_rcv with nothing on FIFO. \n"));
1206 /* don't need to restore anything */
1207 return;
1210 /* start reading from the start of the packet */
1211 outw( PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER );
1213 /* First two words are status and packet_length */
1214 status = inw( ioaddr + DATA_1 );
1215 packet_length = inw( ioaddr + DATA_1 );
1217 packet_length &= 0x07ff; /* mask off top bits */
1219 PRINTK2(("RCV: STATUS %4x LENGTH %4x\n", status, packet_length ));
1221 . the packet length contains 3 extra words :
1222 . status, length, and an extra word with an odd byte .
1224 packet_length -= 6;
1226 if ( !(status & RS_ERRORS ) ){
1227 /* do stuff to make a new packet */
1228 struct sk_buff * skb;
1229 byte * data;
1231 /* read one extra byte */
1232 if ( status & RS_ODDFRAME )
1233 packet_length++;
1235 /* set multicast stats */
1236 if ( status & RS_MULTICAST )
1237 dev->stats.multicast++;
1239 skb = dev_alloc_skb( packet_length + 5);
1241 if ( skb == NULL ) {
1242 printk(KERN_NOTICE CARDNAME ": Low memory, packet dropped.\n");
1243 dev->stats.rx_dropped++;
1244 goto done;
1248 ! This should work without alignment, but it could be
1249 ! in the worse case
1252 skb_reserve( skb, 2 ); /* 16 bit alignment */
1254 data = skb_put( skb, packet_length);
1256 #ifdef USE_32_BIT
1257 /* QUESTION: Like in the TX routine, do I want
1258 to send the DWORDs or the bytes first, or some
1259 mixture. A mixture might improve already slow PIO
1260 performance */
1261 PRINTK3((" Reading %d dwords (and %d bytes) \n",
1262 packet_length >> 2, packet_length & 3 ));
1263 insl(ioaddr + DATA_1 , data, packet_length >> 2 );
1264 /* read the left over bytes */
1265 insb( ioaddr + DATA_1, data + (packet_length & 0xFFFFFC),
1266 packet_length & 0x3 );
1267 #else
1268 PRINTK3((" Reading %d words and %d byte(s) \n",
1269 (packet_length >> 1 ), packet_length & 1 ));
1270 insw(ioaddr + DATA_1 , data, packet_length >> 1);
1271 if ( packet_length & 1 ) {
1272 data += packet_length & ~1;
1273 *(data++) = inb( ioaddr + DATA_1 );
1275 #endif
1276 #if SMC_DEBUG > 2
1277 print_packet( data, packet_length );
1278 #endif
1280 skb->protocol = eth_type_trans(skb, dev );
1281 netif_rx(skb);
1282 dev->stats.rx_packets++;
1283 dev->stats.rx_bytes += packet_length;
1284 } else {
1285 /* error ... */
1286 dev->stats.rx_errors++;
1288 if ( status & RS_ALGNERR ) dev->stats.rx_frame_errors++;
1289 if ( status & (RS_TOOSHORT | RS_TOOLONG ) )
1290 dev->stats.rx_length_errors++;
1291 if ( status & RS_BADCRC) dev->stats.rx_crc_errors++;
1294 done:
1295 /* error or good, tell the card to get rid of this packet */
1296 outw( MC_RELEASE, ioaddr + MMU_CMD );
1300 /*************************************************************************
1301 . smc_tx
1303 . Purpose: Handle a transmit error message. This will only be called
1304 . when an error, because of the AUTO_RELEASE mode.
1306 . Algorithm:
1307 . Save pointer and packet no
1308 . Get the packet no from the top of the queue
1309 . check if it's valid ( if not, is this an error??? )
1310 . read the status word
1311 . record the error
1312 . ( resend? Not really, since we don't want old packets around )
1313 . Restore saved values
1314 ************************************************************************/
1315 static void smc_tx( struct net_device * dev )
1317 int ioaddr = dev->base_addr;
1318 struct smc_local *lp = netdev_priv(dev);
1319 byte saved_packet;
1320 byte packet_no;
1321 word tx_status;
1324 /* assume bank 2 */
1326 saved_packet = inb( ioaddr + PNR_ARR );
1327 packet_no = inw( ioaddr + FIFO_PORTS );
1328 packet_no &= 0x7F;
1330 /* select this as the packet to read from */
1331 outb( packet_no, ioaddr + PNR_ARR );
1333 /* read the first word from this packet */
1334 outw( PTR_AUTOINC | PTR_READ, ioaddr + POINTER );
1336 tx_status = inw( ioaddr + DATA_1 );
1337 PRINTK3((CARDNAME": TX DONE STATUS: %4x \n", tx_status ));
1339 dev->stats.tx_errors++;
1340 if ( tx_status & TS_LOSTCAR ) dev->stats.tx_carrier_errors++;
1341 if ( tx_status & TS_LATCOL ) {
1342 printk(KERN_DEBUG CARDNAME
1343 ": Late collision occurred on last xmit.\n");
1344 dev->stats.tx_window_errors++;
1346 #if 0
1347 if ( tx_status & TS_16COL ) { ... }
1348 #endif
1350 if ( tx_status & TS_SUCCESS ) {
1351 printk(CARDNAME": Successful packet caused interrupt \n");
1353 /* re-enable transmit */
1354 SMC_SELECT_BANK( 0 );
1355 outw( inw( ioaddr + TCR ) | TCR_ENABLE, ioaddr + TCR );
1357 /* kill the packet */
1358 SMC_SELECT_BANK( 2 );
1359 outw( MC_FREEPKT, ioaddr + MMU_CMD );
1361 /* one less packet waiting for me */
1362 lp->packets_waiting--;
1364 outb( saved_packet, ioaddr + PNR_ARR );
1365 return;
1368 /*--------------------------------------------------------------------
1370 . This is the main routine of the driver, to handle the device when
1371 . it needs some attention.
1373 . So:
1374 . first, save state of the chipset
1375 . branch off into routines to handle each case, and acknowledge
1376 . each to the interrupt register
1377 . and finally restore state.
1379 ---------------------------------------------------------------------*/
1381 static irqreturn_t smc_interrupt(int irq, void * dev_id)
1383 struct net_device *dev = dev_id;
1384 int ioaddr = dev->base_addr;
1385 struct smc_local *lp = netdev_priv(dev);
1387 byte status;
1388 word card_stats;
1389 byte mask;
1390 int timeout;
1391 /* state registers */
1392 word saved_bank;
1393 word saved_pointer;
1394 int handled = 0;
1397 PRINTK3((CARDNAME": SMC interrupt started \n"));
1399 saved_bank = inw( ioaddr + BANK_SELECT );
1401 SMC_SELECT_BANK(2);
1402 saved_pointer = inw( ioaddr + POINTER );
1404 mask = inb( ioaddr + INT_MASK );
1405 /* clear all interrupts */
1406 outb( 0, ioaddr + INT_MASK );
1409 /* set a timeout value, so I don't stay here forever */
1410 timeout = 4;
1412 PRINTK2((KERN_WARNING CARDNAME ": MASK IS %x \n", mask ));
1413 do {
1414 /* read the status flag, and mask it */
1415 status = inb( ioaddr + INTERRUPT ) & mask;
1416 if (!status )
1417 break;
1419 handled = 1;
1421 PRINTK3((KERN_WARNING CARDNAME
1422 ": Handling interrupt status %x \n", status ));
1424 if (status & IM_RCV_INT) {
1425 /* Got a packet(s). */
1426 PRINTK2((KERN_WARNING CARDNAME
1427 ": Receive Interrupt\n"));
1428 smc_rcv(dev);
1429 } else if (status & IM_TX_INT ) {
1430 PRINTK2((KERN_WARNING CARDNAME
1431 ": TX ERROR handled\n"));
1432 smc_tx(dev);
1433 outb(IM_TX_INT, ioaddr + INTERRUPT );
1434 } else if (status & IM_TX_EMPTY_INT ) {
1435 /* update stats */
1436 SMC_SELECT_BANK( 0 );
1437 card_stats = inw( ioaddr + COUNTER );
1438 /* single collisions */
1439 dev->stats.collisions += card_stats & 0xF;
1440 card_stats >>= 4;
1441 /* multiple collisions */
1442 dev->stats.collisions += card_stats & 0xF;
1444 /* these are for when linux supports these statistics */
1446 SMC_SELECT_BANK( 2 );
1447 PRINTK2((KERN_WARNING CARDNAME
1448 ": TX_BUFFER_EMPTY handled\n"));
1449 outb( IM_TX_EMPTY_INT, ioaddr + INTERRUPT );
1450 mask &= ~IM_TX_EMPTY_INT;
1451 dev->stats.tx_packets += lp->packets_waiting;
1452 lp->packets_waiting = 0;
1454 } else if (status & IM_ALLOC_INT ) {
1455 PRINTK2((KERN_DEBUG CARDNAME
1456 ": Allocation interrupt \n"));
1457 /* clear this interrupt so it doesn't happen again */
1458 mask &= ~IM_ALLOC_INT;
1460 smc_hardware_send_packet( dev );
1462 /* enable xmit interrupts based on this */
1463 mask |= ( IM_TX_EMPTY_INT | IM_TX_INT );
1465 /* and let the card send more packets to me */
1466 netif_wake_queue(dev);
1468 PRINTK2((CARDNAME": Handoff done successfully.\n"));
1469 } else if (status & IM_RX_OVRN_INT ) {
1470 dev->stats.rx_errors++;
1471 dev->stats.rx_fifo_errors++;
1472 outb( IM_RX_OVRN_INT, ioaddr + INTERRUPT );
1473 } else if (status & IM_EPH_INT ) {
1474 PRINTK((CARDNAME ": UNSUPPORTED: EPH INTERRUPT \n"));
1475 } else if (status & IM_ERCV_INT ) {
1476 PRINTK((CARDNAME ": UNSUPPORTED: ERCV INTERRUPT \n"));
1477 outb( IM_ERCV_INT, ioaddr + INTERRUPT );
1479 } while ( timeout -- );
1482 /* restore state register */
1483 SMC_SELECT_BANK( 2 );
1484 outb( mask, ioaddr + INT_MASK );
1486 PRINTK3(( KERN_WARNING CARDNAME ": MASK is now %x \n", mask ));
1487 outw( saved_pointer, ioaddr + POINTER );
1489 SMC_SELECT_BANK( saved_bank );
1491 PRINTK3((CARDNAME ": Interrupt done\n"));
1492 return IRQ_RETVAL(handled);
1496 /*----------------------------------------------------
1497 . smc_close
1499 . this makes the board clean up everything that it can
1500 . and not talk to the outside world. Caused by
1501 . an 'ifconfig ethX down'
1503 -----------------------------------------------------*/
1504 static int smc_close(struct net_device *dev)
1506 netif_stop_queue(dev);
1507 /* clear everything */
1508 smc_shutdown( dev->base_addr );
1510 /* Update the statistics here. */
1511 return 0;
1514 /*-----------------------------------------------------------
1515 . smc_set_multicast_list
1517 . This routine will, depending on the values passed to it,
1518 . either make it accept multicast packets, go into
1519 . promiscuous mode ( for TCPDUMP and cousins ) or accept
1520 . a select set of multicast packets
1522 static void smc_set_multicast_list(struct net_device *dev)
1524 short ioaddr = dev->base_addr;
1526 SMC_SELECT_BANK(0);
1527 if ( dev->flags & IFF_PROMISC )
1528 outw( inw(ioaddr + RCR ) | RCR_PROMISC, ioaddr + RCR );
1530 /* BUG? I never disable promiscuous mode if multicasting was turned on.
1531 Now, I turn off promiscuous mode, but I don't do anything to multicasting
1532 when promiscuous mode is turned on.
1535 /* Here, I am setting this to accept all multicast packets.
1536 I don't need to zero the multicast table, because the flag is
1537 checked before the table is
1539 else if (dev->flags & IFF_ALLMULTI)
1540 outw( inw(ioaddr + RCR ) | RCR_ALMUL, ioaddr + RCR );
1542 /* We just get all multicast packets even if we only want them
1543 . from one source. This will be changed at some future
1544 . point. */
1545 else if (dev->mc_count ) {
1546 /* support hardware multicasting */
1548 /* be sure I get rid of flags I might have set */
1549 outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL),
1550 ioaddr + RCR );
1551 /* NOTE: this has to set the bank, so make sure it is the
1552 last thing called. The bank is set to zero at the top */
1553 smc_setmulticast( ioaddr, dev->mc_count, dev->mc_list );
1555 else {
1556 outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL),
1557 ioaddr + RCR );
1560 since I'm disabling all multicast entirely, I need to
1561 clear the multicast list
1563 SMC_SELECT_BANK( 3 );
1564 outw( 0, ioaddr + MULTICAST1 );
1565 outw( 0, ioaddr + MULTICAST2 );
1566 outw( 0, ioaddr + MULTICAST3 );
1567 outw( 0, ioaddr + MULTICAST4 );
1571 #ifdef MODULE
1573 static struct net_device *devSMC9194;
1574 MODULE_LICENSE("GPL");
1576 module_param(io, int, 0);
1577 module_param(irq, int, 0);
1578 module_param(ifport, int, 0);
1579 MODULE_PARM_DESC(io, "SMC 99194 I/O base address");
1580 MODULE_PARM_DESC(irq, "SMC 99194 IRQ number");
1581 MODULE_PARM_DESC(ifport, "SMC 99194 interface port (0-default, 1-TP, 2-AUI)");
1583 int __init init_module(void)
1585 if (io == 0)
1586 printk(KERN_WARNING
1587 CARDNAME": You shouldn't use auto-probing with insmod!\n" );
1589 /* copy the parameters from insmod into the device structure */
1590 devSMC9194 = smc_init(-1);
1591 if (IS_ERR(devSMC9194))
1592 return PTR_ERR(devSMC9194);
1593 return 0;
1596 void __exit cleanup_module(void)
1598 unregister_netdev(devSMC9194);
1599 free_irq(devSMC9194->irq, devSMC9194);
1600 release_region(devSMC9194->base_addr, SMC_IO_EXTENT);
1601 free_netdev(devSMC9194);
1604 #endif /* MODULE */