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