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