ia64/linux-2.6.18-xen.hg

annotate drivers/net/smc9194.c @ 897:329ea0ccb344

balloon: try harder to balloon up under memory pressure.

Currently if the balloon driver is unable to increase the guest's
reservation it assumes the failure was due to reaching its full
allocation, gives up on the ballooning operation and records the limit
it reached as the "hard limit". The driver will not try again until
the target is set again (even to the same value).

However it is possible that ballooning has in fact failed due to
memory pressure in the host and therefore it is desirable to keep
attempting to reach the target in case memory becomes available. The
most likely scenario is that some guests are ballooning down while
others are ballooning up and therefore there is temporary memory
pressure while things stabilise. You would not expect a well behaved
toolstack to ask a domain to balloon to more than its allocation nor
would you expect it to deliberately over-commit memory by setting
balloon targets which exceed the total host memory.

This patch drops the concept of a hard limit and causes the balloon
driver to retry increasing the reservation on a timer in the same
manner as when decreasing the reservation.

Also if we partially succeed in increasing the reservation
(i.e. receive less pages than we asked for) then we may as well keep
those pages rather than returning them to Xen.

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