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