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 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 . 22 . Hardware multicast code from Peter Cammaert ( pc@denkart.be ) 23 . 24 . Sources: 25 . o SMC databook 26 . o skeleton.c by Donald Becker ( becker@cesdis.gsfc.nasa.gov ) 27 . o ( a LOT of advice from Becker as well ) 28 . 29 . History: 30 . 12/07/95 Erik Stahlman written, got recieve/xmit handled 31 . 01/03/96 Erik Stahlman worked out some bugs, actually useable!!! :-) 32 . 01/06/96 Erik Stahlman cleaned up some, better testing, etc 33 . 01/29/96 Erik Stahlman fixed autoirq, added multicast 34 . 02/01/96 Erik Stahlman 1. disabled all interrupts in smc_reset 35 . 2. got rid of post-decrementing bug -- UGH. 36 . 02/13/96 Erik Stahlman Tried to fix autoirq failure. Added more 37 . descriptive error messages. 38 . 02/15/96 Erik Stahlman Fixed typo that caused detection failure 39 . 02/23/96 Erik Stahlman Modified it to fit into kernel tree 40 . Added support to change hardware address 41 . Cleared stats on opens 42 . 02/26/96 Erik Stahlman Trial support for Kernel 1.2.13 43 . Kludge for automatic IRQ detection 44 . 03/04/96 Erik Stahlman Fixed kernel 1.3.70 + 45 . Fixed bug reported by Gardner Buchanan in 46 . smc_enable, with outw instead of outb 47 . 03/06/96 Erik Stahlman Added hardware multicast from Peter Cammaert 48 ----------------------------------------------------------------------------*/ 49
50 staticconstchar *version =
51 "smc9194.c:v0.12 03/06/96 by Erik Stahlman (erik@vt.edu)\n";
52
53 #ifdefMODULE 54 #include <linux/module.h>
55 #include <linux/version.h>
56 #endif 57
58 #include <linux/kernel.h>
59 #include <linux/sched.h>
60 #include <linux/types.h>
61 #include <linux/fcntl.h>
62 #include <linux/interrupt.h>
63 #include <linux/ptrace.h>
64 #include <linux/ioport.h>
65 #include <linux/in.h>
66 #include <linux/malloc.h>
67 #include <linux/string.h>
68 #include <linux/ioport.h>
69 #include <asm/bitops.h>
70 #include <asm/io.h>
71 #include <linux/errno.h>
72
73 #include <linux/netdevice.h>
74 #include <linux/etherdevice.h>
75 #include <linux/skbuff.h>
76
77 #include "smc9194.h"
78 /*------------------------------------------------------------------------ 79 . 80 . Configuration options, for the experienced user to change. 81 . 82 -------------------------------------------------------------------------*/ 83
84 /* 85 . this is for kernels > 1.2.70 86 */ 87 #defineREALLY_NEW_KERNEL 88 #ifndefREALLY_NEW_KERNEL 89 #definefree_irq( x, y ) free_irq( x )
90 #definerequest_irq( x, y, z, u, v ) request_irq( x, y, z, u )
91 #endif 92
93 /* 94 . Do you want to use this with old kernels. 95 . WARNING: this is not well tested. 96 #define SUPPORT_OLD_KERNEL 97 */ 98
99
100 /* 101 . Do you want to use 32 bit xfers? This should work on all chips, as 102 . the chipset is designed to accomodate them. 103 */ 104 #defineUSE_32_BIT 1
105
106 /* 107 .the SMC9194 can be at any of the following port addresses. To change, 108 .for a slightly different card, you can add it to the array. Keep in 109 .mind that the array must end in zero. 110 */ 111 staticunsignedintsmc_portlist[] =
112 { 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0,
113 0x300, 0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x3E0, 0};
114
115 /* 116 . Wait time for memory to be free. This probably shouldn't be 117 . tuned that much, as waiting for this means nothing else happens 118 . in the system 119 */ 120 #defineMEMORY_WAIT_TIME 16
121
122 /* 123 . DEBUGGING LEVELS 124 . 125 . 0 for normal operation 126 . 1 for slightly more details 127 . >2 for various levels of increasingly useless information 128 . 2 for interrupt tracking, status flags 129 . 3 for packet dumps, etc. 130 */ 131 #defineSMC_DEBUG 0
132
133 #if (SMC_DEBUG > 2 )
134 #definePRINTK3(x) printkx 135 #else 136 #definePRINTK3(x)
137 #endif 138
139 #ifSMC_DEBUG > 1
140 #definePRINTK2(x) printkx 141 #else 142 #definePRINTK2(x)
143 #endif 144
145 #ifdefSMC_DEBUG 146 #definePRINTK(x) printkx 147 #else 148 #definePRINTK(x)
149 #endif 150
151
152 /* the older versions of the kernel cannot support autoprobing */ 153 #ifdefSUPPORT_OLD_KERNEL 154 #defineNO_AUTOPROBE 155 #endif 156
157
158 /*------------------------------------------------------------------------ 159 . 160 . The internal workings of the driver. If you are changing anything 161 . here with the SMC stuff, you should have the datasheet and known 162 . what you are doing. 163 . 164 -------------------------------------------------------------------------*/ 165 #defineCARDNAME "SMC9194"
166
167 #ifdefSUPPORT_OLD_KERNEL 168 charkernel_version[] = UTS_RELEASE;
169 #endif 170
171 /* store this information for the driver.. */ 172 structsmc_local{ 173 /* 174 these are things that the kernel wants me to keep, so users 175 can find out semi-useless statistics of how well the card is 176 performing 177 */ 178 structenet_statisticsstats;
179
180 /* 181 If I have to wait until memory is available to send 182 a packet, I will store the skbuff here, until I get the 183 desired memory. Then, I'll send it out and free it. 184 */ 185 structsk_buff * saved_skb;
186
187 /* 188 . This keeps track of how many packets that I have 189 . sent out. When an TX_EMPTY interrupt comes, I know 190 . that all of these have been sent. 191 */ 192 intpackets_waiting;
193 };
194
195
196 /*----------------------------------------------------------------- 197 . 198 . The driver can be entered at any of the following entry points. 199 . 200 .------------------------------------------------------------------ */ 201
202 /* 203 . This is called by register_netdev(). It is responsible for 204 . checking the portlist for the SMC9000 series chipset. If it finds 205 . one, then it will initialize the device, find the hardware information, 206 . and sets up the appropriate device parameters. 207 . NOTE: Interrupts are *OFF* when this procedure is called. 208 . 209 . NB:This shouldn't be static since it is refered to externally. 210 */ 211 intsmc_init(structdevice *dev);
212
213 /* 214 . The kernel calls this function when someone wants to use the device, 215 . typically 'ifconfig ethX up'. 216 */ 217 staticintsmc_open(structdevice *dev);
218
219 /* 220 . This is called by the kernel to send a packet out into the net. it's 221 . responsible for doing a best-effort send, but if it's simply not possible 222 . to send it, the packet gets dropped. 223 */ 224 staticintsmc_send_packet(structsk_buff *skb, structdevice *dev);
225
226 /* 227 . This is called by the kernel in response to 'ifconfig ethX down'. It 228 . is responsible for cleaning up everything that the open routine 229 . does, and maybe putting the card into a powerdown state. 230 */ 231 staticintsmc_close(structdevice *dev);
232
233 /* 234 . This routine allows the proc file system to query the driver's 235 . statistics. 236 */ 237 staticstructenet_statistics * smc_query_statistics( structdevice *dev);
238
239 /* 240 . Finally, a call to set promiscuous mode ( for TCPDUMP and related 241 . programs ) and multicast modes. 242 */ 243 #ifdefSUPPORT_OLD_KERNEL 244 staticvoidsmc_set_multicast_list(structdevice *dev, intnum_addrs,
245 void *addrs);
246 #else 247 staticvoidsmc_set_multicast_list(structdevice *dev);
248 #endif 249
250 /*--------------------------------------------------------------- 251 . 252 . Interrupt level calls.. 253 . 254 ----------------------------------------------------------------*/ 255
256 /* 257 . Handles the actual interrupt 258 */ 259 #ifdefREALLY_NEW_KERNEL 260 staticvoidsmc_interrupt(intirq, void *, structpt_regs *regs);
261 #else 262 staticvoidsmc_interrupt(intirq, structpt_regs *regs);
263 #endif 264 /* 265 . This is a seperate procedure to handle the receipt of a packet, to 266 . leave the interrupt code looking slightly cleaner 267 */ 268 inlinestaticvoidsmc_rcv( structdevice *dev );
269 /* 270 . This handles a TX interrupt, which is only called when an error 271 . relating to a packet is sent. 272 */ 273 inlinestaticvoidsmc_tx( structdevice * dev );
274
275 /* 276 ------------------------------------------------------------ 277 . 278 . Internal routines 279 . 280 ------------------------------------------------------------ 281 */ 282
283 /* 284 . Test if a given location contains a chip, trying to cause as 285 . little damage as possible if it's not a SMC chip. 286 */ 287 staticintsmc_probe( intioaddr );
288
289 /* 290 . this routine initializes the cards hardware, prints out the configuration 291 . to the system log as well as the vanity message, and handles the setup 292 . of a device parameter. 293 . It will give an error if it can't initialize the card. 294 */ 295 staticintsmc_initcard( structdevice *, intioaddr );
296
297 /* 298 . A rather simple routine to print out a packet for debugging purposes. 299 */ 300 #ifSMC_DEBUG > 2
301 staticvoidprint_packet( byte *, int );
302 #endif 303
304 #definetx_done(dev) 1
305
306 /* this is called to actually send the packet to the chip */ 307 staticvoidsmc_hardware_send_packet( structdevice * dev );
308
309 /* Since I am not sure if I will have enough room in the chip's ram 310 . to store the packet, I call this routine, which either sends it 311 . now, or generates an interrupt when the card is ready for the 312 . packet */ 313 staticintsmc_wait_to_send_packet( structsk_buff * skb, structdevice *dev );
314
315 /* this does a soft reset on the device */ 316 staticvoidsmc_reset( intioaddr );
317
318 /* Enable Interrupts, Receive, and Transmit */ 319 staticvoidsmc_enable( intioaddr );
320
321 /* this puts the device in an inactve state */ 322 staticvoidsmc_shutdown( intioaddr );
323
324 #ifndefNO_AUTOPROBE 325 /* This routine will find the IRQ of the driver if one is not 326 . specified in the input to the device. */ 327 staticintsmc_findirq( intioaddr );
328 #endif 329
330 /* 331 this routine will set the hardware multicast table to the specified 332 values given it by the higher level routines 333 */ 334 #ifndefSUPPORT_OLD_KERNEL 335 staticvoidsmc_setmulticast( intioaddr, intcount, structdev_mc_list * );
336 staticintcrc32( char *, int );
337 #endif 338
339 #ifdefSUPPORT_OLD_KERNEL 340 externstructdevice *init_etherdev(structdevice *dev, int sizeof_private,
341 unsignedlong *mem_startp );
342 #endif 343
344 /* 345 . Function: smc_reset( int ioaddr ) 346 . Purpose: 347 . This sets the SMC91xx chip to its normal state, hopefully from whatever 348 . mess that any other DOS driver has put it in. 349 . 350 . Maybe I should reset more registers to defaults in here? SOFTRESET should 351 . do that for me. 352 . 353 . Method: 354 . 1. send a SOFT RESET 355 . 2. wait for it to finish 356 . 3. enable autorelease mode 357 . 4. reset the memory management unit 358 . 5. clear all interrupts 359 . 360 */ 361 staticvoidsmc_reset( intioaddr )
/* */ 362 { 363 /* This resets the registers mostly to defaults, but doesn't 364 affect EEPROM. That seems unnecessary */ 365 SMC_SELECT_BANK( 0 );
366 outw( RCR_SOFTRESET, ioaddr + RCR );
367
368 /* this should pause enough for the chip to be happy */ 369 SMC_DELAY( );
370
371 /* Set the transmit and receive configuration registers to 372 default values */ 373 outw( RCR_CLEAR, ioaddr + RCR );
374 outw( TCR_CLEAR, ioaddr + TCR );
375
376 /* set the control register to automatically 377 release succesfully transmitted packets, to make the best 378 use out of our limitted memory */ 379 SMC_SELECT_BANK( 1 );
380 outw( inw( ioaddr + CONTROL ) | CTL_AUTO_RELEASE , ioaddr + CONTROL );
381
382 /* Reset the MMU */ 383 SMC_SELECT_BANK( 2 );
384 outw( MC_RESET, ioaddr + MMU_CMD );
385
386 /* Note: It doesn't seem that waiting for the MMU busy is needed here, 387 but this is a place where future chipsets _COULD_ break. Be wary 388 of issuing another MMU command right after this */ 389
390 outb( 0, ioaddr + INT_MASK );
391 } 392
393 /* 394 . Function: smc_enable 395 . Purpose: let the chip talk to the outside work 396 . Method: 397 . 1. Enable the transmitter 398 . 2. Enable the receiver 399 . 3. Enable interrupts 400 */ 401 staticvoidsmc_enable( intioaddr )
/* */ 402 { 403 SMC_SELECT_BANK( 0 );
404 /* see the header file for options in TCR/RCR NORMAL*/ 405 outw( TCR_NORMAL, ioaddr + TCR );
406 outw( RCR_NORMAL, ioaddr + RCR );
407
408 /* now, enable interrupts */ 409 SMC_SELECT_BANK( 2 );
410 outb( SMC_INTERRUPT_MASK, ioaddr + INT_MASK );
411 } 412
413 /* 414 . Function: smc_shutdown 415 . Purpose: closes down the SMC91xxx chip. 416 . Method: 417 . 1. zero the interrupt mask 418 . 2. clear the enable recieve flag 419 . 3. clear the enable xmit flags 420 . 421 . TODO: 422 . (1) maybe utilize power down mode. 423 . Why not yet? Because while the chip will go into power down mode, 424 . the manual says that it will wake up in response to any I/O requests 425 . in the register space. Empirical results do not show this working. 426 */ 427 staticvoidsmc_shutdown( intioaddr )
/* */ 428 { 429 /* no more interrupts for me */ 430 SMC_SELECT_BANK( 2 );
431 outb( 0, ioaddr + INT_MASK );
432
433 /* and tell the card to stay away from that nasty outside world */ 434 SMC_SELECT_BANK( 0 );
435 outb( RCR_CLEAR, ioaddr + RCR );
436 outb( TCR_CLEAR, ioaddr + TCR );
437 #if 0
438 /* finally, shut the chip down */ 439 SMC_SELECT_BANK( 1 );
440 outw( inw( ioaddr + CONTROL ), CTL_POWERDOWN, ioaddr + CONTROL );
441 #endif 442 } 443
444
445 #ifndefSUPPORT_OLD_KERNEL 446 /* 447 . Function: smc_setmulticast( int ioaddr, int count, dev_mc_list * adds ) 448 . Purpose: 449 . This sets the internal hardware table to filter out unwanted multicast 450 . packets before they take up memory. 451 . 452 . The SMC chip uses a hash table where the high 6 bits of the CRC of 453 . address are the offset into the table. If that bit is 1, then the 454 . multicast packet is accepted. Otherwise, it's dropped silently. 455 . 456 . To use the 6 bits as an offset into the table, the high 3 bits are the 457 . number of the 8 bit register, while the low 3 bits are the bit within 458 . that register. 459 . 460 . This routine is based very heavily on the one provided by Peter Cammaert. 461 */ 462
463
464 staticvoidsmc_setmulticast( intioaddr, intcount, structdev_mc_list * addrs ) {/* */ 465 inti;
466 unsignedcharmulticast_table[ 8 ];
467 structdev_mc_list * cur_addr;
468 /* table for flipping the order of 3 bits */ 469 unsignedcharinvert3[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
470
471 /* start with a table of all zeros: reject all */ 472 memset( multicast_table, 0, sizeof( multicast_table ) );
473
474 cur_addr = addrs;
475 for ( i = 0; i < count ; i ++, cur_addr = cur_addr->next ) { 476 intposition;
477
478 /* do we have a pointer here? */ 479 if ( !cur_addr )
480 break;
481 /* make sure this is a multicast address - shouldn't this 482 be a given if we have it here ? */ 483 if ( !( *cur_addr->dmi_addr & 1 ) )
484 continue;
485
486 /* only use the low order bits */ 487 position = crc32( cur_addr->dmi_addr, 6 ) & 0x3f;
488
489 /* do some messy swapping to put the bit in the right spot */ 490 multicast_table[invert3[position&7]] |=
491 (1<<invert3[(position>>3)&7]);
492
493 } 494 /* now, the table can be loaded into the chipset */ 495 SMC_SELECT_BANK( 3 );
496
497 for ( i = 0; i < 8 ; i++ ) { 498 outb( multicast_table[i], ioaddr + MULTICAST1 + i );
499 } 500 } 501
502 /* 503 Finds the CRC32 of a set of bytes. 504 Again, from Peter Cammaert's code. 505 */ 506 staticintcrc32( char * s, intlength ) {/* */ 507 /* indices */ 508 intperByte;
509 intperBit;
510 /* crc polynomial for Ethernet */ 511 constunsignedlongpoly = 0xedb88320;
512 /* crc value - preinitialized to all 1's */ 513 unsignedlongcrc_value = 0xffffffff;
514
515 for ( perByte = 0; perByte < length; perByte ++ ) { 516 unsignedcharc;
517
518 c = *(s++);
519 for ( perBit = 0; perBit < 8; perBit++ ) { 520 crc_value = (crc_value>>1)^
521 (((crc_value^c)&0x01)?poly:0);
522 c >>= 1;
523 } 524 } 525 returncrc_value;
526 } 527
528 #endif 529
530
531 /* 532 . Function: smc_wait_to_send_packet( struct sk_buff * skb, struct device * ) 533 . Purpose: 534 . Attempt to allocate memory for a packet, if chip-memory is not 535 . available, then tell the card to generate an interrupt when it 536 . is available. 537 . 538 . Algorithm: 539 . 540 . o if the saved_skb is not currently null, then drop this packet 541 . on the floor. This should never happen, because of TBUSY. 542 . o if the saved_skb is null, then replace it with the current packet, 543 . o See if I can sending it now. 544 . o (NO): Enable interrupts and let the interrupt handler deal with it. 545 . o (YES):Send it now. 546 */ 547 staticintsmc_wait_to_send_packet( structsk_buff * skb, structdevice * dev )
/* */ 548 { 549 structsmc_local *lp = (structsmc_local *)dev->priv;
550 unsignedshortioaddr = dev->base_addr;
551 wordlength;
552 unsignedshortnumPages;
553 wordtime_out;
554
555 if ( lp->saved_skb) { 556 /* THIS SHOULD NEVER HAPPEN. */ 557 lp->stats.tx_aborted_errors++;
558 printk(CARDNAME": Bad Craziness - sent packet while busy.\n" );
559 return 1;
560 } 561 lp->saved_skb = skb;
562
563 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
564
565 /* 566 . the MMU wants the number of pages to be the number of 256 bytes 567 . 'pages', minus 1 ( since a packet can't ever have 0 pages :) ) 568 */ 569 numPages = length / 256;
570
571 if (numPages > 7 ) { 572 printk(CARDNAME": Far too big packet error. \n");
573 /* freeing the packet is a good thing here... but should 574 . any packets of this size get down here? */ 575 dev_kfree_skb (skb, FREE_WRITE);
576 lp->saved_skb = NULL;
577 /* this IS an error, but, i don't want the skb saved */ 578 return 0;
579 } 580 /* either way, a packet is waiting now */ 581 lp->packets_waiting++;
582
583 /* now, try to allocate the memory */ 584 SMC_SELECT_BANK( 2 );
585 outw( MC_ALLOC | numPages, ioaddr + MMU_CMD );
586 /* 587 . Performance Hack 588 . 589 . wait a short amount of time.. if I can send a packet now, I send 590 . it now. Otherwise, I enable an interrupt and wait for one to be 591 . available. 592 . 593 . I could have handled this a slightly different way, by checking to 594 . see if any memory was available in the FREE MEMORY register. However, 595 . either way, I need to generate an allocation, and the allocation works 596 . no matter what, so I saw no point in checking free memory. 597 */ 598 time_out = MEMORY_WAIT_TIME;
599 do{ 600 wordstatus;
601
602 status = inb( ioaddr + INTERRUPT );
603 if ( status & IM_ALLOC_INT ) { 604 /* acknowledge the interrupt */ 605 outb( IM_ALLOC_INT, ioaddr + INTERRUPT );
606 break;
607 } 608 }while ( -- time_out );
609
610 if ( !time_out ) { 611 /* oh well, wait until the chip finds memory later */ 612 SMC_ENABLE_INT( IM_ALLOC_INT );
613 PRINTK2((CARDNAME": memory allocation deferred. \n"));
614 /* it's deferred, but I'll handle it later */ 615 return 0;
616 } 617 /* or YES! I can send the packet now.. */ 618 smc_hardware_send_packet(dev);
619
620 return 0;
621 } 622
623 /* 624 . Function: smc_hardware_send_packet(struct device * ) 625 . Purpose: 626 . This sends the actual packet to the SMC9xxx chip. 627 . 628 . Algorithm: 629 . First, see if a saved_skb is available. 630 . ( this should NOT be called if there is no 'saved_skb' 631 . Now, find the packet number that the chip allocated 632 . Point the data pointers at it in memory 633 . Set the length word in the chip's memory 634 . Dump the packet to chip memory 635 . Check if a last byte is needed ( odd length packet ) 636 . if so, set the control flag right 637 . Tell the card to send it 638 . Enable the transmit interrupt, so I know if it failed 639 . Free the kernel data if I actually sent it. 640 */ 641 staticvoidsmc_hardware_send_packet( structdevice * dev )
/* */ 642 { 643 structsmc_local *lp = (structsmc_local *)dev->priv;
644 bytepacket_no;
645 structsk_buff * skb = lp->saved_skb;
646 wordlength;
647 unsignedshortioaddr;
648 byte * buf;
649
650 ioaddr = dev->base_addr;
651
652 if ( !skb ) { 653 PRINTK((CARDNAME": In XMIT with no packet to send \n"));
654 return;
655 } 656 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
657 buf = skb->data;
658
659 /* If I get here, I _know_ there is a packet slot waiting for me */ 660 packet_no = inb( ioaddr + PNR_ARR + 1 );
661 if ( packet_no & 0x80 ) { 662 /* or isn't there? BAD CHIP! */ 663 printk(KERN_DEBUGCARDNAME": Memory allocation failed. \n");
664 kfree(skb);
665 lp->saved_skb = NULL;
666 dev->tbusy = 0;
667 return;
668 } 669
670 /* we have a packet address, so tell the card to use it */ 671 outb( packet_no, ioaddr + PNR_ARR );
672
673 /* point to the beginning of the packet */ 674 outw( PTR_AUTOINC , ioaddr + POINTER );
675
676 PRINTK3((CARDNAME": Trying to xmit packet of length %x\n", length ));
677 #ifSMC_DEBUG > 2
678 print_packet( buf, length );
679 #endif 680
681 /* send the packet length ( +6 for status, length and ctl byte ) 682 and the status word ( set to zeros ) */ 683 #ifdefUSE_32_BIT 684 outl( (length +6 ) << 16 , ioaddr + DATA_1 );
685 #else 686 outw( 0, ioaddr + DATA_1 );
687 /* send the packet length ( +6 for status words, length, and ctl*/ 688 outb( (length+6) & 0xFF,ioaddr + DATA_1 );
689 outb( (length+6) >> 8 , ioaddr + DATA_1 );
690 #endif 691
692 /* send the actual data 693 . I _think_ it's faster to send the longs first, and then 694 . mop up by sending the last word. It depends heavily 695 . on alignment, at least on the 486. Maybe it would be 696 . a good idea to check which is optimal? But that could take 697 . almost as much time as is saved? 698 */ 699 #ifdefUSE_32_BIT 700 if ( length & 0x2 ) { 701 outsl(ioaddr + DATA_1, buf, length >> 2 );
702 outw( *((word *)(buf + (length & 0xFFFFFFFC))),ioaddr +DATA_1);
703 } 704 else 705 outsl(ioaddr + DATA_1, buf, length >> 2 );
706 #else 707 outsw(ioaddr + DATA_1 , buf, (length ) >> 1);
708 #endif 709 /* Send the last byte, if there is one. */ 710
711 if ( (length & 1) == 0 ) { 712 outw( 0, ioaddr + DATA_1 );
713 }else{ 714 outb( buf[length -1 ], ioaddr + DATA_1 );
715 outb( 0x20, ioaddr + DATA_1);
716 } 717
718 /* enable the interrupts */ 719 SMC_ENABLE_INT( (IM_TX_INT | IM_TX_EMPTY_INT) );
720
721 /* and let the chipset deal with it */ 722 outw( MC_ENQUEUE , ioaddr + MMU_CMD );
723
724 PRINTK2((CARDNAME": Sent packet of length %d \n",length));
725
726 lp->saved_skb = NULL;
727 dev_kfree_skb (skb, FREE_WRITE);
728
729 dev->trans_start = jiffies;
730
731 /* we can send another packet */ 732 dev->tbusy = 0;
733
734
735 return;
736 } 737
738 /*------------------------------------------------------------------------- 739 | 740 | smc_init( struct device * dev ) 741 | Input parameters: 742 | dev->base_addr == 0, try to find all possible locations 743 | dev->base_addr == 1, return failure code 744 | dev->base_addr == 2, always allocate space, and return sucess 745 | dev->base_addr == <anything else> this is the address to check 746 | 747 | Output: 748 | 0 --> there is a device 749 | anything else, error 750 | 751 --------------------------------------------------------------------------- 752 */ 753 intsmc_init(structdevice *dev)
/* */ 754 { 755 inti;
756 intbase_addr = dev ? dev->base_addr : 0;
757
758 /* try a specific location */ 759 if (base_addr > 0x1ff) { 760 interror;
761 error = smc_probe(base_addr);
762 if ( 0 == error ) { 763 returnsmc_initcard( dev, base_addr );
764 } 765 returnerror;
766 }else{ 767 if ( 0 != base_addr ) { 768 return -ENXIO;
769 } 770 } 771
772 /* check every ethernet address */ 773 for (i = 0; smc_portlist[i]; i++) { 774 intioaddr = smc_portlist[i];
775
776 /* check if the area is available */ 777 if (check_region( ioaddr , SMC_IO_EXTENT))
778 continue;
779
780 /* check this specific address */ 781 if ( smc_probe( ioaddr ) == 0) { 782 returnsmc_initcard( dev, ioaddr );
783 } 784 } 785
786 /* couldn't find anything */ 787 return -ENODEV;
788 } 789
790 #ifndefNO_AUTOPROBE 791 /*---------------------------------------------------------------------- 792 . smc_findirq 793 . 794 . This routine has a simple purpose -- make the SMC chip generate an 795 . interrupt, so an auto-detect routine can detect it, and find the IRQ, 796 ------------------------------------------------------------------------ 797 */ 798 intsmc_findirq( intioaddr )
/* */ 799 { 800 inttimeout = 20;
801
802
803 /* I have to do a STI() here, because this is called from 804 a routine that does an CLI during this process, making it 805 rather difficult to get interrupts for auto detection */ 806 sti();
807
808 autoirq_setup( 0 );
809
810 /* 811 * What I try to do here is trigger an ALLOC_INT. This is done 812 * by allocating a small chunk of memory, which will give an interrupt 813 * when done. 814 */ 815
816
817 SMC_SELECT_BANK(2);
818 /* enable ALLOCation interrupts ONLY */ 819 outb( IM_ALLOC_INT, ioaddr + INT_MASK );
820
821 /* 822 . Allocate 512 bytes of memory. Note that the chip was just 823 . reset so all the memory is available 824 */ 825 outw( MC_ALLOC | 1, ioaddr + MMU_CMD );
826
827 /* 828 . Wait until positive that the interrupt has been generated 829 */ 830 while ( timeout ) { 831 byteint_status;
832
833 int_status = inb( ioaddr + INTERRUPT );
834
835 if ( int_status & IM_ALLOC_INT )
836 break; /* got the interrupt */ 837 timeout--;
838 } 839 /* there is really nothing that I can do here if timeout fails, 840 as autoirq_report will return a 0 anyway, which is what I 841 want in this case. Plus, the clean up is needed in both 842 cases. */ 843
844 /* DELAY HERE! 845 On a fast machine, the status might change before the interrupt 846 is given to the processor. This means that the interrupt was 847 never detected, and autoirq_report fails to report anything. 848 This should fix autoirq_* problems. 849 */ 850 SMC_DELAY();
851 SMC_DELAY();
852
853 /* and disable all interrupts again */ 854 outb( 0, ioaddr + INT_MASK );
855
856 /* clear hardware interrupts again, because that's how it 857 was when I was called... */ 858 cli();
859
860 /* and return what I found */ 861 returnautoirq_report( 0 );
862 } 863 #endif 864
865 /*---------------------------------------------------------------------- 866 . Function: smc_probe( int ioaddr ) 867 . 868 . Purpose: 869 . Tests to see if a given ioaddr points to an SMC9xxx chip. 870 . Returns a 0 on success 871 . 872 . Algorithm: 873 . (1) see if the high byte of BANK_SELECT is 0x33 874 . (2) compare the ioaddr with the base register's address 875 . (3) see if I recognize the chip ID in the appropriate register 876 . 877 .--------------------------------------------------------------------- 878 */ 879
880 staticintsmc_probe( intioaddr )
/* */ 881 { 882 unsignedintbank;
883 wordrevision_register;
884 wordbase_address_register;
885
886 /* First, see if the high byte is 0x33 */ 887 bank = inw( ioaddr + BANK_SELECT );
888 if ( (bank & 0xFF00) != 0x3300 ) { 889 return -ENODEV;
890 } 891 /* The above MIGHT indicate a device, but I need to write to further 892 test this. */ 893 outw( 0x0, ioaddr + BANK_SELECT );
894 bank = inw( ioaddr + BANK_SELECT );
895 if ( (bank & 0xFF00 ) != 0x3300 ) { 896 return -ENODEV;
897 } 898 /* well, we've already written once, so hopefully another time won't 899 hurt. This time, I need to switch the bank register to bank 1, 900 so I can access the base address register */ 901 SMC_SELECT_BANK(1);
902 base_address_register = inw( ioaddr + BASE );
903 if ( ioaddr != ( base_address_register >> 3 & 0x3E0 ) ) { 904 printk(CARDNAME ": IOADDR %x doesn't match configuration (%x)."
905 "Probably not a SMC chip\n",
906 ioaddr, base_address_register >> 3 & 0x3E0 );
907 /* well, the base address register didn't match. Must not have 908 been a SMC chip after all. */ 909 return -ENODEV;
910 } 911
912 /* check if the revision register is something that I recognize. 913 These might need to be added to later, as future revisions 914 could be added. */ 915 SMC_SELECT_BANK(3);
916 revision_register = inw( ioaddr + REVISION );
917 if ( !chip_ids[ ( revision_register >> 4 ) & 0xF ] ) { 918 /* I don't regonize this chip, so... */ 919 printk(CARDNAME ": IO %x: Unrecognized revision register:"
920 " %x, Contact author. \n", ioaddr, revision_register );
921
922 return -ENODEV;
923 } 924
925 /* at this point I'll assume that the chip is an SMC9xxx. 926 It might be prudent to check a listing of MAC addresses 927 against the hardware address, or do some other tests. */ 928 return 0;
929 } 930
931 /*--------------------------------------------------------------- 932 . Here I do typical initialization tasks. 933 . 934 . o Initialize the structure if needed 935 . o print out my vanity message if not done so already 936 . o print out what type of hardware is detected 937 . o print out the ethernet address 938 . o find the IRQ 939 . o set up my private data 940 . o configure the dev structure with my subroutines 941 . o actually GRAB the irq. 942 . o GRAB the region 943 .----------------------------------------------------------------- 944 */ 945 staticintsmc_initcard(structdevice *dev, intioaddr)
/* */ 946 { 947 inti;
948
949 staticunsignedversion_printed = 0;
950
951 /* registers */ 952 wordrevision_register;
953 wordconfiguration_register;
954 wordmemory_info_register;
955 wordmemory_cfg_register;
956
957 constchar * version_string;
958 constchar * if_string;
959 intmemory;
960
961 intirqval;
962
963 /* see if I need to initialize the ethernet card structure */ 964 if (dev == NULL) { 965 #ifdefSUPPORT_OLD_KERNEL 966 #ifndefMODULE 967 /* note: the old module interface does not support this call */ 968 dev = init_etherdev( 0, sizeof( structsmc_local ), 0 );
969 #endif 970 #else 971 dev = init_etherdev(0, 0);
972 #endif 973 if (dev == NULL)
974 return -ENOMEM;
975 } 976
977 if (version_printed++ == 0)
978 printk("%s", version);
979
980 /* fill in some of the fields */ 981 dev->base_addr = ioaddr;
982
983 /* 984 . Get the MAC address ( bank 1, regs 4 - 9 ) 985 */ 986 SMC_SELECT_BANK( 1 );
987 for ( i = 0; i < 6; i += 2 ) { 988 wordaddress;
989
990 address = inw( ioaddr + ADDR0 + i );
991 dev->dev_addr[ i + 1] = address >> 8;
992 dev->dev_addr[ i ] = address & 0xFF;
993 } 994
995 /* get the memory information */ 996
997 SMC_SELECT_BANK( 0 );
998 memory_info_register = inw( ioaddr + MIR );
999 memory_cfg_register = inw( ioaddr + MCR );
1000 memory = ( memory_cfg_register >> 9 ) & 0x7; /* multiplier */1001 memory *= 256 * ( memory_info_register & 0xFF );
1002
1003 /* 1004 Now, I want to find out more about the chip. This is sort of1005 redundant, but it's cleaner to have it in both, rather than having1006 one VERY long probe procedure.1007 */1008 SMC_SELECT_BANK(3);
1009 revision_register = inw( ioaddr + REVISION );
1010 version_string = chip_ids[ ( revision_register >> 4 ) & 0xF ];
1011 if ( !version_string ) {1012 /* I shouldnt' get here because this call was done before.... */1013 return -ENODEV;
1014 }1015
1016 /* is it using AUI or 10BaseT ? */1017 if ( dev->if_port == 0 ) {1018 SMC_SELECT_BANK(1);
1019 configuration_register = inw( ioaddr + CONFIG );
1020 if ( configuration_register & CFG_AUI_SELECT )
1021 dev->if_port = 2;
1022 else1023 dev->if_port = 1;
1024 }1025 if_string = interfaces[ dev->if_port - 1 ];
1026
1027 /* now, reset the chip, and put it into a known state */1028 smc_reset( ioaddr );
1029
1030 /*1031 . If dev->irq is 0, then the device has to be banged on to see1032 . what the IRQ is. 1033 . 1034 . This banging doesn't always detect the IRQ, for unknown reasons.1035 . a workaround is to reset the chip and try again. 1036 . 1037 . Interestingly, the DOS packet driver *SETS* the IRQ on the card to1038 . be what is requested on the command line. I don't do that, mostly1039 . because the card that I have uses a non-standard method of accessing1040 . the IRQs, and because this _should_ work in most configurations.1041 .1042 . Specifying an IRQ is done with the assumption that the user knows 1043 . what (s)he is doing. No checking is done!!!!1044 .1045 */1046 #ifndefNO_AUTOPROBE1047 if ( dev->irq < 2 ) {1048 inttrials;
1049
1050 trials = 3;
1051 while ( trials-- ) {1052 dev->irq = smc_findirq( ioaddr );
1053 if ( dev->irq )
1054 break;
1055 /* kick the card and try again */1056 smc_reset( ioaddr );
1057 }1058 }1059 if (dev->irq == 0 ) {1060 printk(CARDNAME": Couldn't autodetect your IRQ. Use irq=xx.\n");
1061 return -ENODEV;
1062 }1063 #else1064 if (dev->irq == 0 ) {1065 printk(CARDNAME1066 ": Autoprobing IRQs is not supported for old kernels.\n");
1067 return -ENODEV;
1068 }1069 #endif1070 if (dev->irq == 2) {1071 /* Fixup for users that don't know that IRQ 2 is really IRQ 9,1072 * or don't know which one to set.1073 */1074 dev->irq = 9;
1075 }1076
1077 /* now, print out the card info, in a short format.. */1078
1079 printk(CARDNAME ": %s(r:%d) at %#3x IRQ:%d INTF:%s MEM:%db ",
1080 version_string, revision_register & 0xF, ioaddr, dev->irq,
1081 if_string, memory );
1082 /*1083 . Print the Ethernet address 1084 */1085 printk("ADDR: ");
1086 for (i = 0; i < 5; i++)
1087 printk("%2.2x:", dev->dev_addr[i] );
1088 printk("%2.2x \n", dev->dev_addr[5] );
1089
1090
1091 /* Initialize the private structure. */1092 if (dev->priv == NULL) {1093 dev->priv = kmalloc(sizeof(structsmc_local), GFP_KERNEL);
1094 if (dev->priv == NULL)
1095 return -ENOMEM;
1096 }1097 /* set the private data to zero by default */1098 memset(dev->priv, 0, sizeof(structsmc_local));
1099
1100 /* Fill in the fields of the device structure with ethernet values. */1101 ether_setup(dev);
1102
1103 /* Grab the IRQ */1104 irqval = request_irq(dev->irq, &smc_interrupt, 0, CARDNAME, NULL);
1105 if (irqval) {1106 printk(CARDNAME": unable to get IRQ %d (irqval=%d).\n",
1107 dev->irq, irqval);
1108 return -EAGAIN;
1109 }1110 irq2dev_map[dev->irq] = dev;
1111
1112 /* Grab the region so that no one else tries to probe our ioports. */1113 request_region(ioaddr, SMC_IO_EXTENT, CARDNAME);
1114
1115 dev->open = smc_open;
1116 dev->stop = smc_close;
1117 dev->hard_start_xmit = smc_send_packet;
1118 dev->get_stats = smc_query_statistics;
1119 #ifdefHAVE_MULTICAST1120 dev->set_multicast_list = &smc_set_multicast_list;
1121 #endif1122
1123 return 0;
1124 }1125
1126 #ifSMC_DEBUG > 2
1127 staticvoidprint_packet( byte * buf, intlength )
/* */1128 {1129 #if 0
1130 inti;
1131 intremainder;
1132 intlines;
1133
1134 printk("Packet of length %d \n", length );
1135 lines = length / 16;
1136 remainder = length % 16;
1137
1138 for ( i = 0; i < lines ; i ++ ) {1139 intcur;
1140
1141 for ( cur = 0; cur < 8; cur ++ ) {1142 bytea, b;
1143
1144 a = *(buf ++ );
1145 b = *(buf ++ );
1146 printk("%02x%02x ", a, b );
1147 }1148 printk("\n");
1149 }1150 for ( i = 0; i < remainder/2 ; i++ ) {1151 bytea, b;
1152
1153 a = *(buf ++ );
1154 b = *(buf ++ );
1155 printk("%02x%02x ", a, b );
1156 }1157 printk("\n");
1158 #endif1159 }1160 #endif1161
1162
1163 /*1164 * Open and Initialize the board1165 * 1166 * Set up everything, reset the card, etc ..1167 *1168 */1169 staticintsmc_open(structdevice *dev)
/* */1170 {1171 intioaddr = dev->base_addr;
1172
1173 inti; /* used to set hw ethernet address */1174
1175 /* clear out all the junk that was put here before... */1176 memset(dev->priv, 0, sizeof(structsmc_local));
1177
1178 dev->tbusy = 0;
1179 dev->interrupt = 0;
1180 dev->start = 1;
1181 #ifdefMODULE1182 MOD_INC_USE_COUNT;
1183 #endif1184
1185 /* reset the hardware */1186
1187 smc_reset( ioaddr );
1188 smc_enable( ioaddr );
1189
1190 /* Select which interface to use */1191
1192 SMC_SELECT_BANK( 1 );
1193 if ( dev->if_port == 1 ) {1194 outw( inw( ioaddr + CONFIG ) & ~CFG_AUI_SELECT,
1195 ioaddr + CONFIG );
1196 }1197 elseif ( dev->if_port == 2 ) {1198 outw( inw( ioaddr + CONFIG ) | CFG_AUI_SELECT,
1199 ioaddr + CONFIG );
1200 }1201
1202 /*1203 According to Becker, I have to set the hardware address1204 at this point, because the (l)user can set it with an1205 ioctl. Easily done... 1206 */1207 SMC_SELECT_BANK( 1 );
1208 for ( i = 0; i < 6; i += 2 ) {1209 wordaddress;
1210
1211 address = dev->dev_addr[ i + 1 ] << 8 ;
1212 address |= dev->dev_addr[ i ];
1213 outw( address, ioaddr + ADDR0 + i );
1214 }1215 return 0;
1216 }1217
1218 /*--------------------------------------------------------1219 . Called by the kernel to send a packet out into the void1220 . of the net. This routine is largely based on 1221 . skeleton.c, from Becker. 1222 .--------------------------------------------------------1223 */1224 staticintsmc_send_packet(structsk_buff *skb, structdevice *dev)
/* */1225 {1226 if (dev->tbusy) {1227 /* If we get here, some higher level has decided we are broken.1228 There should really be a "kick me" function call instead. */1229 inttickssofar = jiffies - dev->trans_start;
1230 if (tickssofar < 5)
1231 return 1;
1232 printk(KERN_WARNINGCARDNAME": transmit timed out, %s?\n",
1233 tx_done(dev) ? "IRQ conflict" :
1234 "network cable problem");
1235 /* "kick" the adaptor */1236 smc_reset( dev->base_addr );
1237 smc_enable( dev->base_addr );
1238
1239 dev->tbusy = 0;
1240 dev->trans_start = jiffies;
1241 /* clear anything saved */1242 ((structsmc_local *)dev->priv)->saved_skb = NULL;
1243 }1244
1245 /* If some higher layer thinks we've missed an tx-done interrupt1246 we are passed NULL. Caution: dev_tint() handles the cli()/sti()1247 itself. */1248 if (skb == NULL) {1249 dev_tint(dev);
1250 return 0;
1251 }1252
1253 /* Block a timer-based transmit from overlapping. This could better be1254 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */1255 if (set_bit(0, (void*)&dev->tbusy) != 0) {1256 printk(KERN_WARNINGCARDNAME": Transmitter access conflict.\n");
1257 dev_kfree_skb (skb, FREE_WRITE);
1258 }else{1259 /* Well, I want to send the packet.. but I don't know 1260 if I can send it right now... */1261 returnsmc_wait_to_send_packet( skb, dev );
1262 }1263 return 0;
1264 }1265
1266 /*--------------------------------------------------------------------1267 .1268 . This is the main routine of the driver, to handle the device when1269 . it needs some attention.1270 .1271 . So:1272 . first, save state of the chipset1273 . branch off into routines to handle each case, and acknowledge 1274 . each to the interrupt register1275 . and finally restore state. 1276 . 1277 ---------------------------------------------------------------------*/1278 #ifdefREALLY_NEW_KERNEL1279 staticvoidsmc_interrupt(intirq, void * dev_id, structpt_regs * regs)
/* */1280 #else1281 staticvoidsmc_interrupt(intirq, structpt_regs * regs)
1282 #endif1283 {1284 structdevice *dev = (structdevice *)(irq2dev_map[irq]);
1285 intioaddr = dev->base_addr;
1286 structsmc_local *lp = (structsmc_local *)dev->priv;
1287
1288 bytestatus;
1289 wordcard_stats;
1290 bytemask;
1291 inttimeout;
1292 /* state registers */1293 wordsaved_bank;
1294 wordsaved_pointer;
1295
1296
1297
1298 PRINTK3((CARDNAME": SMC interrupt started \n"));
1299
1300 if (dev == NULL) {1301 printk(KERN_WARNINGCARDNAME": irq %d for unknown device.\n",
1302 irq);
1303 return;
1304 }1305
1306 /* will Linux let this happen ?? If not, this costs some speed */1307 if ( dev->interrupt ) {1308 printk(KERN_WARNINGCARDNAME": interrupt inside interrupt.\n");
1309 return;
1310 }1311
1312 dev->interrupt = 1;
1313
1314 saved_bank = inw( ioaddr + BANK_SELECT );
1315
1316 SMC_SELECT_BANK(2);
1317 saved_pointer = inw( ioaddr + POINTER );
1318
1319 mask = inb( ioaddr + INT_MASK );
1320 /* clear all interrupts */1321 outb( 0, ioaddr + INT_MASK );
1322
1323
1324 /* set a timeout value, so I don't stay here forever */1325 timeout = 4;
1326
1327 PRINTK2((KERN_WARNINGCARDNAME ": MASK IS %x \n", mask ));
1328 do{1329 /* read the status flag, and mask it */1330 status = inb( ioaddr + INTERRUPT ) & mask;
1331 if (!status )
1332 break;
1333
1334 PRINTK3((KERN_WARNINGCARDNAME1335 ": Handling interrupt status %x \n", status ));
1336
1337 if (status & IM_RCV_INT) {1338 /* Got a packet(s). */1339 PRINTK2((KERN_WARNINGCARDNAME1340 ": Recieve Interrupt\n"));
1341 smc_rcv(dev);
1342 }elseif (status & IM_TX_INT ) {1343 PRINTK2((KERN_WARNINGCARDNAME1344 ": TX ERROR handled\n"));
1345 smc_tx(dev);
1346 outb(IM_TX_INT, ioaddr + INTERRUPT );
1347 }elseif (status & IM_TX_EMPTY_INT ) {1348 /* update stats */1349 SMC_SELECT_BANK( 0 );
1350 card_stats = inw( ioaddr + COUNTER );
1351 /* single collisions */1352 lp->stats.collisions += card_stats & 0xF;
1353 card_stats >>= 4;
1354 /* multiple collisions */1355 lp->stats.collisions += card_stats & 0xF;
1356
1357 /* these are for when linux supports these statistics */1358 #if 0
1359 card_stats >>= 4;
1360 /* deferred */1361 card_stats >>= 4;
1362 /* excess deferred */1363 #endif1364 SMC_SELECT_BANK( 2 );
1365 PRINTK2((KERN_WARNINGCARDNAME1366 ": TX_BUFFER_EMPTY handled\n"));
1367 outb( IM_TX_EMPTY_INT, ioaddr + INTERRUPT );
1368 mask &= ~IM_TX_EMPTY_INT;
1369 lp->stats.tx_packets += lp->packets_waiting;
1370 lp->packets_waiting = 0;
1371
1372 }elseif (status & IM_ALLOC_INT ) {1373 PRINTK2((KERN_DEBUGCARDNAME1374 ": Allocation interrupt \n"));
1375 /* clear this interrupt so it doesn't happen again */1376 mask &= ~IM_ALLOC_INT;
1377
1378 smc_hardware_send_packet( dev );
1379
1380 /* enable xmit interrupts based on this */1381 mask |= ( IM_TX_EMPTY_INT | IM_TX_INT );
1382
1383 /* and let the card send more packets to me */1384 mark_bh( NET_BH );
1385
1386 PRINTK2((CARDNAME": Handoff done successfully.\n"));
1387 }elseif (status & IM_RX_OVRN_INT ) {1388 lp->stats.rx_errors++;
1389 lp->stats.rx_fifo_errors++;
1390 outb( IM_RX_OVRN_INT, ioaddr + INTERRUPT );
1391 }elseif (status & IM_EPH_INT ) {1392 PRINTK((CARDNAME ": UNSUPPORTED: EPH INTERRUPT \n"));
1393 }elseif (status & IM_ERCV_INT ) {1394 PRINTK((CARDNAME ": UNSUPPORTED: ERCV INTERRUPT \n"));
1395 outb( IM_ERCV_INT, ioaddr + INTERRUPT );
1396 }1397 }while ( timeout -- );
1398
1399
1400 /* restore state register */1401 SMC_SELECT_BANK( 2 );
1402 outb( mask, ioaddr + INT_MASK );
1403
1404 PRINTK3(( KERN_WARNINGCARDNAME ": MASK is now %x \n", mask ));
1405 outw( saved_pointer, ioaddr + POINTER );
1406
1407 SMC_SELECT_BANK( saved_bank );
1408
1409 dev->interrupt = 0;
1410 PRINTK3((CARDNAME ": Interrupt done\n"));
1411 return;
1412 }1413
1414 /*-------------------------------------------------------------1415 .1416 . smc_rcv - receive a packet from the card1417 .1418 . There is ( at least ) a packet waiting to be read from1419 . chip-memory.1420 . 1421 . o Read the status 1422 . o If an error, record it 1423 . o otherwise, read in the packet 1424 --------------------------------------------------------------1425 */1426 staticvoidsmc_rcv(structdevice *dev)
/* */1427 {1428 structsmc_local *lp = (structsmc_local *)dev->priv;
1429 intioaddr = dev->base_addr;
1430 intpacket_number;
1431 wordstatus;
1432 wordpacket_length;
1433
1434 /* assume bank 2 */1435
1436 packet_number = inw( ioaddr + FIFO_PORTS );
1437
1438 if ( packet_number & FP_RXEMPTY ) {1439 /* we got called , but nothing was on the FIFO */1440 PRINTK((CARDNAME ": WARNING: smc_rcv with nothing on FIFO. \n"));
1441 /* don't need to restore anything */1442 return;
1443 }1444
1445 /* start reading from the start of the packet */1446 outw( PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER );
1447
1448 /* First two words are status and packet_length */1449 status = inw( ioaddr + DATA_1 );
1450 packet_length = inw( ioaddr + DATA_1 );
1451
1452 packet_length &= 0x07ff; /* mask off top bits */1453
1454 PRINTK2(("RCV: STATUS %4x LENGTH %4x\n", status, packet_length ));
1455 /* 1456 . the packet length contains 3 extra words : 1457 . status, length, and a extra word with an odd byte .1458 */1459 packet_length -= 6;
1460
1461 if ( !(status & RS_ERRORS ) ){1462 /* do stuff to make a new packet */1463 structsk_buff * skb;
1464 byte * data;
1465
1466 /* read one extra byte */1467 if ( status & RS_ODDFRAME )
1468 packet_length++;
1469
1470 /* set multicast stats */1471 if ( status & RS_MULTICAST )
1472 lp->stats.multicast++;
1473
1474 #ifdefSUPPORT_OLD_KERNEL1475 skb = alloc_skb( packet_length + 5, GFP_ATOMIC );
1476 #else1477 skb = dev_alloc_skb( packet_length + 5);
1478 #endif1479
1480 if ( skb == NULL ) {1481 printk(KERN_NOTICECARDNAME1482 ": Low memory, packet dropped.\n");
1483 lp->stats.rx_dropped++;
1484 }1485
1486 /* 1487 ! This should work without alignment, but it could be1488 ! in the worse case 1489 */1490 #ifndefSUPPORT_OLD_KERNEL1491 /* TODO: Should I use 32bit alignment here ? */1492 skb_reserve( skb, 2 ); /* 16 bit alignment */1493 #endif1494
1495 skb->dev = dev;
1496 #ifdefSUPPORT_OLD_KERNEL1497 skb->len = packet_length;
1498 data = skb->data;
1499 #else1500 data = skb_put( skb, packet_length);
1501 #endif1502 #ifdefUSE_32_BIT1503 /* QUESTION: Like in the TX routine, do I want 1504 to send the DWORDs or the bytes first, or some1505 mixture. A mixture might improve already slow PIO1506 performance */1507 PRINTK3((" Reading %d dwords (and %d bytes) \n",
1508 packet_length >> 2, packet_length & 3 ));
1509 insl(ioaddr + DATA_1 , data, packet_length >> 2 );
1510 /* read the left over bytes */1511 insb( ioaddr + DATA_1, data + (packet_length & 0xFFFFFC),
1512 packet_length & 0x3 );
1513 #else1514 PRINTK3((" Reading %d words and %d byte(s) \n",
1515 (packet_length >> 1 ), packet_length & 1 );
1516 if ( packet_length & 1 )
1517 *(data++) = inb( ioaddr + DATA_1 );
1518 insw(ioaddr + DATA_1 , data, (packet_length + 1 ) >> 1);
1519 if ( packet_length & 1 ) {1520 data += packet_length & ~1;
1521 *((data++) = inb( ioaddr + DATA_1 );
1522 }1523 #endif1524 #ifSMC_DEBUG > 2
1525 print_packet( data, packet_length );
1526 #endif1527
1528 #ifndefSUPPORT_OLD_KERNEL1529 skb->protocol = eth_type_trans(skb, dev );
1530 #endif1531 netif_rx(skb);
1532 lp->stats.rx_packets++;
1533 }else{1534 /* error ... */1535 lp->stats.rx_errors++;
1536
1537 if ( status & RS_ALGNERR ) lp->stats.rx_frame_errors++;
1538 if ( status & (RS_TOOSHORT | RS_TOOLONG ) )
1539 lp->stats.rx_length_errors++;
1540 if ( status & RS_BADCRC) lp->stats.rx_crc_errors++;
1541 }1542 /* error or good, tell the card to get rid of this packet */1543 outw( MC_RELEASE, ioaddr + MMU_CMD );
1544
1545
1546 return;
1547 }1548
1549
1550 /************************************************************************* 1551 . smc_tx1552 . 1553 . Purpose: Handle a transmit error message. This will only be called1554 . when an error, because of the AUTO_RELEASE mode. 1555 . 1556 . Algorithm:1557 . Save pointer and packet no1558 . Get the packet no from the top of the queue1559 . check if it's valid ( if not, is this an error??? )1560 . read the status word 1561 . record the error1562 . ( resend? Not really, since we don't want old packets around )1563 . Restore saved values 1564 ************************************************************************/1565 staticvoidsmc_tx( structdevice * dev )
/* */1566 {1567 intioaddr = dev->base_addr;
1568 structsmc_local *lp = (structsmc_local *)dev->priv;
1569 bytesaved_packet;
1570 bytepacket_no;
1571 wordtx_status;
1572
1573
1574 /* assume bank 2 */1575
1576 saved_packet = inb( ioaddr + PNR_ARR );
1577 packet_no = inw( ioaddr + FIFO_PORTS );
1578 packet_no &= 0x7F;
1579
1580 /* select this as the packet to read from */1581 outb( packet_no, ioaddr + PNR_ARR );
1582
1583 /* read the first word from this packet */1584 outw( PTR_AUTOINC | PTR_READ, ioaddr + POINTER );
1585
1586 tx_status = inw( ioaddr + DATA_1 );
1587 PRINTK3((CARDNAME": TX DONE STATUS: %4x \n", tx_status ));
1588
1589 lp->stats.tx_errors++;
1590 if ( tx_status & TS_LOSTCAR ) lp->stats.tx_carrier_errors++;
1591 if ( tx_status & TS_LATCOL ) {1592 printk(KERN_DEBUGCARDNAME1593 ": Late collision occured on last xmit.\n");
1594 lp->stats.tx_window_errors++;
1595 }1596 #if 0
1597 if ( tx_status & TS_16COL ) { ... }1598 #endif1599
1600 if ( tx_status & TS_SUCCESS ) {1601 printk(CARDNAME": Successful packet caused interrupt \n");
1602 }1603 /* re-enable transmit */1604 SMC_SELECT_BANK( 0 );
1605 outw( inw( ioaddr + TCR ) | TCR_ENABLE, ioaddr + TCR );
1606
1607 /* kill the packet */1608 SMC_SELECT_BANK( 2 );
1609 outw( MC_FREEPKT, ioaddr + MMU_CMD );
1610
1611 /* one less packet waiting for me */1612 lp->packets_waiting--;
1613
1614 outb( saved_packet, ioaddr + PNR_ARR );
1615 return;
1616 }1617
1618 /*----------------------------------------------------1619 . smc_close1620 . 1621 . this makes the board clean up everything that it can1622 . and not talk to the outside world. Caused by1623 . an 'ifconfig ethX down'1624 .1625 -----------------------------------------------------*/1626 staticintsmc_close(structdevice *dev)
/* */1627 {1628 dev->tbusy = 1;
1629 dev->start = 0;
1630
1631 /* clear everything */1632 smc_shutdown( dev->base_addr );
1633
1634 /* Update the statistics here. */1635 #ifdefMODULE1636 MOD_DEC_USE_COUNT;
1637 #endif1638
1639 return 0;
1640 }1641
1642 /*------------------------------------------------------------1643 . Get the current statistics. 1644 . This may be called with the card open or closed. 1645 .-------------------------------------------------------------*/1646 staticstructenet_statistics * smc_query_statistics(structdevice *dev) {/* */1647 structsmc_local *lp = (structsmc_local *)dev->priv;
1648
1649 return &lp->stats;
1650 }1651
1652 /*-----------------------------------------------------------1653 . smc_set_multicast_list1654 . 1655 . This routine will, depending on the values passed to it,1656 . either make it accept multicast packets, go into 1657 . promiscuous mode ( for TCPDUMP and cousins ) or accept1658 . a select set of multicast packets 1659 */1660 #ifdefSUPPORT_OLD_KERNEL1661 staticvoidsmc_set_multicast_list( structdevice * dev,
/* */1662 intnum_addrs, void * addrs )
1663 #else1664 staticvoidsmc_set_multicast_list(structdevice *dev)
1665 #endif1666 {1667 shortioaddr = dev->base_addr;
1668
1669 SMC_SELECT_BANK(0);
1670 #ifdefSUPPORT_OLD_KERNEL1671 if ( num_addrs < 0 )
1672 #else1673 if ( dev->flags & IFF_PROMISC )
1674 #endif1675 outw( inw(ioaddr + RCR ) | RCR_PROMISC, ioaddr + RCR );
1676
1677 /* BUG? I never disable promiscuous mode if multicasting was turned on. 1678 Now, I turn off promiscouos mode, but I don't do anything to multicasting1679 when promiscuous mode is turned on. 1680 */1681
1682 /* Here, I am setting this to accept all multicast packets. 1683 I don't need to zero the multicast table, because the flag is1684 checked before the table is 1685 */1686 #ifdefSUPPORT_OLD_KERNEL1687 elseif ( num_addrs > 20 ) /* arbitrary constant */1688 #else1689 elseif (dev->flags & IFF_ALLMULTI)
1690 #endif1691 outw( inw(ioaddr + RCR ) | RCR_ALMUL, ioaddr + RCR );
1692
1693 /* We just get all multicast packets even if we only want them1694 . from one source. This will be changed at some future1695 . point. */1696 #ifdefSUPPORT_OLD_KERNEL1697 elseif (num_addrs > 0 ) {1698 /* the old kernel support will not have hardware multicast support. It would1699 involve more kludges, and make the multicast setting code even worse. 1700 Instead, just use the ALMUL method. This is reasonable, considering that1701 it is seldom used1702 */1703 outw( inw( ioaddr + RCR ) & ~RCR_PROMISC, ioaddr + RCR );
1704 outw( inw( ioadddr + RCR ) | RCR_ALMUL, ioadddr + RCR );
1705 }1706 #else1707 elseif (dev->mc_count ) {1708 /* support hardware multicasting */1709
1710 /* be sure I get rid of flags I might have set */1711 outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL),
1712 ioaddr + RCR );
1713 /* NOTE: this has to set the bank, so make sure it is the1714 last thing called. The bank is set to zero at the top */1715 smc_setmulticast( ioaddr, dev->mc_count, dev->mc_list );
1716 }1717 #endif1718 else{1719 outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL),
1720 ioaddr + RCR );
1721
1722 /* 1723 since I'm disabling all multicast entirely, I need to 1724 clear the multicast list 1725 */1726 SMC_SELECT_BANK( 3 );
1727 outw( 0, ioaddr + MULTICAST1 );
1728 outw( 0, ioaddr + MULTICAST2 );
1729 outw( 0, ioaddr + MULTICAST3 );
1730 outw( 0, ioaddr + MULTICAST4 );
1731 }1732 }1733
1734 #ifdefMODULE1735
1736 staticchardevicename[9] = { 0, };
1737 staticstructdevicedevSMC9194 = {1738 devicename, /* device name is inserted by linux/drivers/net/net_init.c */1739 0, 0, 0, 0,
1740 0, 0, /* I/O address, IRQ */1741 0, 0, 0, NULL, smc_init};
1742
1743 intio = 0;
1744 intirq = 0;
1745 intifport = 0;
1746
1747 intinit_module(void)
/* */1748 {1749 intresult;
1750
1751 if (io == 0)
1752 printk(KERN_WARNING1753 CARDNAME": You shouldn't use auto-probing with insmod!\n" );
1754
1755 /* copy the parameters from insmod into the device structure */1756 devSMC9194.base_addr = io;
1757 devSMC9194.irq = irq;
1758 devSMC9194.if_port = ifport;
1759 if ((result = register_netdev(&devSMC9194)) != 0)
1760 returnresult;
1761
1762 return 0;
1763 }1764
1765 voidcleanup_module(void)
/* */1766 {1767 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */1768 unregister_netdev(&devSMC9194);
1769
1770 free_irq(devSMC9194.irq, NULL );
1771 irq2dev_map[devSMC9194.irq] = NULL;
1772 release_region(devSMC9194.base_addr, SMC_IO_EXTENT);
1773
1774 if (devSMC9194.priv)
1775 kfree_s(devSMC9194.priv, sizeof(structsmc_local));
1776 }1777
1778 #endif/* MODULE */1779