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