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