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