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