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