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[] = | |
2ad02bdc | 58 | "smc9194.c:v0.14 12/15/00 by Erik Stahlman (erik@vt.edu)"; |
1da177e4 LT |
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 | /* | |
22bedad3 | 419 | . Function: smc_setmulticast( int ioaddr, struct net_device *dev ) |
1da177e4 LT |
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 ]; | |
22bedad3 | 440 | struct netdev_hw_addr *ha; |
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 | ||
22bedad3 | 447 | netdev_for_each_mc_addr(ha, dev) { |
1da177e4 LT |
448 | int position; |
449 | ||
1da177e4 | 450 | /* only use the low order bits */ |
22bedad3 | 451 | position = ether_crc_le(6, ha->addr) & 0x3f; |
1da177e4 LT |
452 | |
453 | /* do some messy swapping to put the bit in the right spot */ | |
454 | multicast_table[invert3[position&7]] |= | |
455 | (1<<invert3[(position>>3)&7]); | |
456 | ||
457 | } | |
458 | /* now, the table can be loaded into the chipset */ | |
459 | SMC_SELECT_BANK( 3 ); | |
460 | ||
461 | for ( i = 0; i < 8 ; i++ ) { | |
462 | outb( multicast_table[i], ioaddr + MULTICAST1 + i ); | |
463 | } | |
464 | } | |
465 | ||
466 | /* | |
467 | . Function: smc_wait_to_send_packet( struct sk_buff * skb, struct net_device * ) | |
468 | . Purpose: | |
469 | . Attempt to allocate memory for a packet, if chip-memory is not | |
470 | . available, then tell the card to generate an interrupt when it | |
471 | . is available. | |
472 | . | |
473 | . Algorithm: | |
474 | . | |
475 | . o if the saved_skb is not currently null, then drop this packet | |
476 | . on the floor. This should never happen, because of TBUSY. | |
477 | . o if the saved_skb is null, then replace it with the current packet, | |
478 | . o See if I can sending it now. | |
479 | . o (NO): Enable interrupts and let the interrupt handler deal with it. | |
480 | . o (YES):Send it now. | |
481 | */ | |
61357325 SH |
482 | static netdev_tx_t smc_wait_to_send_packet(struct sk_buff *skb, |
483 | struct net_device *dev) | |
1da177e4 LT |
484 | { |
485 | struct smc_local *lp = netdev_priv(dev); | |
486 | unsigned int ioaddr = dev->base_addr; | |
487 | word length; | |
488 | unsigned short numPages; | |
489 | word time_out; | |
490 | ||
491 | netif_stop_queue(dev); | |
492 | /* Well, I want to send the packet.. but I don't know | |
493 | if I can send it right now... */ | |
494 | ||
495 | if ( lp->saved_skb) { | |
496 | /* THIS SHOULD NEVER HAPPEN. */ | |
09f75cd7 | 497 | dev->stats.tx_aborted_errors++; |
1da177e4 | 498 | printk(CARDNAME": Bad Craziness - sent packet while busy.\n" ); |
5b548140 | 499 | return NETDEV_TX_BUSY; |
1da177e4 LT |
500 | } |
501 | lp->saved_skb = skb; | |
502 | ||
503 | length = skb->len; | |
504 | ||
505 | if (length < ETH_ZLEN) { | |
5b057c6b | 506 | if (skb_padto(skb, ETH_ZLEN)) { |
1da177e4 | 507 | netif_wake_queue(dev); |
6ed10654 | 508 | return NETDEV_TX_OK; |
1da177e4 LT |
509 | } |
510 | length = ETH_ZLEN; | |
511 | } | |
6aa20a22 | 512 | |
1da177e4 LT |
513 | /* |
514 | ** The MMU wants the number of pages to be the number of 256 bytes | |
515 | ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) ) | |
516 | ** | |
517 | ** Pkt size for allocating is data length +6 (for additional status words, | |
518 | ** length and ctl!) If odd size last byte is included in this header. | |
519 | */ | |
520 | numPages = ((length & 0xfffe) + 6) / 256; | |
521 | ||
522 | if (numPages > 7 ) { | |
84d57bd6 | 523 | printk(CARDNAME": Far too big packet error.\n"); |
1da177e4 LT |
524 | /* freeing the packet is a good thing here... but should |
525 | . any packets of this size get down here? */ | |
526 | dev_kfree_skb (skb); | |
527 | lp->saved_skb = NULL; | |
528 | /* this IS an error, but, i don't want the skb saved */ | |
529 | netif_wake_queue(dev); | |
6ed10654 | 530 | return NETDEV_TX_OK; |
1da177e4 LT |
531 | } |
532 | /* either way, a packet is waiting now */ | |
533 | lp->packets_waiting++; | |
534 | ||
535 | /* now, try to allocate the memory */ | |
536 | SMC_SELECT_BANK( 2 ); | |
537 | outw( MC_ALLOC | numPages, ioaddr + MMU_CMD ); | |
538 | /* | |
539 | . Performance Hack | |
540 | . | |
541 | . wait a short amount of time.. if I can send a packet now, I send | |
542 | . it now. Otherwise, I enable an interrupt and wait for one to be | |
543 | . available. | |
544 | . | |
545 | . I could have handled this a slightly different way, by checking to | |
546 | . see if any memory was available in the FREE MEMORY register. However, | |
547 | . either way, I need to generate an allocation, and the allocation works | |
548 | . no matter what, so I saw no point in checking free memory. | |
549 | */ | |
550 | time_out = MEMORY_WAIT_TIME; | |
551 | do { | |
552 | word status; | |
553 | ||
554 | status = inb( ioaddr + INTERRUPT ); | |
555 | if ( status & IM_ALLOC_INT ) { | |
556 | /* acknowledge the interrupt */ | |
557 | outb( IM_ALLOC_INT, ioaddr + INTERRUPT ); | |
558 | break; | |
559 | } | |
560 | } while ( -- time_out ); | |
561 | ||
562 | if ( !time_out ) { | |
563 | /* oh well, wait until the chip finds memory later */ | |
564 | SMC_ENABLE_INT( IM_ALLOC_INT ); | |
84d57bd6 | 565 | PRINTK2((CARDNAME": memory allocation deferred.\n")); |
1da177e4 | 566 | /* it's deferred, but I'll handle it later */ |
84d57bd6 | 567 | return NETDEV_TX_OK; |
1da177e4 LT |
568 | } |
569 | /* or YES! I can send the packet now.. */ | |
570 | smc_hardware_send_packet(dev); | |
571 | netif_wake_queue(dev); | |
6ed10654 | 572 | return NETDEV_TX_OK; |
1da177e4 LT |
573 | } |
574 | ||
575 | /* | |
576 | . Function: smc_hardware_send_packet(struct net_device * ) | |
577 | . Purpose: | |
578 | . This sends the actual packet to the SMC9xxx chip. | |
579 | . | |
580 | . Algorithm: | |
581 | . First, see if a saved_skb is available. | |
582 | . ( this should NOT be called if there is no 'saved_skb' | |
583 | . Now, find the packet number that the chip allocated | |
584 | . Point the data pointers at it in memory | |
585 | . Set the length word in the chip's memory | |
586 | . Dump the packet to chip memory | |
587 | . Check if a last byte is needed ( odd length packet ) | |
588 | . if so, set the control flag right | |
589 | . Tell the card to send it | |
590 | . Enable the transmit interrupt, so I know if it failed | |
591 | . Free the kernel data if I actually sent it. | |
592 | */ | |
593 | static void smc_hardware_send_packet( struct net_device * dev ) | |
594 | { | |
595 | struct smc_local *lp = netdev_priv(dev); | |
596 | byte packet_no; | |
597 | struct sk_buff * skb = lp->saved_skb; | |
598 | word length; | |
599 | unsigned int ioaddr; | |
600 | byte * buf; | |
601 | ||
602 | ioaddr = dev->base_addr; | |
603 | ||
604 | if ( !skb ) { | |
84d57bd6 | 605 | PRINTK((CARDNAME": In XMIT with no packet to send\n")); |
1da177e4 LT |
606 | return; |
607 | } | |
608 | length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; | |
609 | buf = skb->data; | |
610 | ||
611 | /* If I get here, I _know_ there is a packet slot waiting for me */ | |
612 | packet_no = inb( ioaddr + PNR_ARR + 1 ); | |
613 | if ( packet_no & 0x80 ) { | |
614 | /* or isn't there? BAD CHIP! */ | |
2ad02bdc | 615 | netdev_dbg(dev, CARDNAME": Memory allocation failed.\n"); |
1da177e4 LT |
616 | dev_kfree_skb_any(skb); |
617 | lp->saved_skb = NULL; | |
618 | netif_wake_queue(dev); | |
619 | return; | |
620 | } | |
621 | ||
622 | /* we have a packet address, so tell the card to use it */ | |
623 | outb( packet_no, ioaddr + PNR_ARR ); | |
624 | ||
625 | /* point to the beginning of the packet */ | |
626 | outw( PTR_AUTOINC , ioaddr + POINTER ); | |
627 | ||
2ad02bdc | 628 | PRINTK3((CARDNAME": Trying to xmit packet of length %x\n", length)); |
1da177e4 LT |
629 | #if SMC_DEBUG > 2 |
630 | print_packet( buf, length ); | |
631 | #endif | |
632 | ||
633 | /* send the packet length ( +6 for status, length and ctl byte ) | |
634 | and the status word ( set to zeros ) */ | |
635 | #ifdef USE_32_BIT | |
636 | outl( (length +6 ) << 16 , ioaddr + DATA_1 ); | |
637 | #else | |
638 | outw( 0, ioaddr + DATA_1 ); | |
639 | /* send the packet length ( +6 for status words, length, and ctl*/ | |
640 | outb( (length+6) & 0xFF,ioaddr + DATA_1 ); | |
641 | outb( (length+6) >> 8 , ioaddr + DATA_1 ); | |
642 | #endif | |
643 | ||
644 | /* send the actual data | |
645 | . I _think_ it's faster to send the longs first, and then | |
646 | . mop up by sending the last word. It depends heavily | |
647 | . on alignment, at least on the 486. Maybe it would be | |
648 | . a good idea to check which is optimal? But that could take | |
649 | . almost as much time as is saved? | |
650 | */ | |
651 | #ifdef USE_32_BIT | |
652 | if ( length & 0x2 ) { | |
653 | outsl(ioaddr + DATA_1, buf, length >> 2 ); | |
654 | #if !defined(__H8300H__) && !defined(__H8300S__) | |
655 | outw( *((word *)(buf + (length & 0xFFFFFFFC))),ioaddr +DATA_1); | |
656 | #else | |
657 | ctrl_outw( *((word *)(buf + (length & 0xFFFFFFFC))),ioaddr +DATA_1); | |
658 | #endif | |
659 | } | |
660 | else | |
661 | outsl(ioaddr + DATA_1, buf, length >> 2 ); | |
662 | #else | |
663 | outsw(ioaddr + DATA_1 , buf, (length ) >> 1); | |
664 | #endif | |
665 | /* Send the last byte, if there is one. */ | |
666 | ||
667 | if ( (length & 1) == 0 ) { | |
668 | outw( 0, ioaddr + DATA_1 ); | |
669 | } else { | |
670 | outb( buf[length -1 ], ioaddr + DATA_1 ); | |
671 | outb( 0x20, ioaddr + DATA_1); | |
672 | } | |
673 | ||
674 | /* enable the interrupts */ | |
675 | SMC_ENABLE_INT( (IM_TX_INT | IM_TX_EMPTY_INT) ); | |
676 | ||
677 | /* and let the chipset deal with it */ | |
678 | outw( MC_ENQUEUE , ioaddr + MMU_CMD ); | |
679 | ||
84d57bd6 | 680 | PRINTK2((CARDNAME": Sent packet of length %d\n", length)); |
1da177e4 LT |
681 | |
682 | lp->saved_skb = NULL; | |
683 | dev_kfree_skb_any (skb); | |
684 | ||
685 | dev->trans_start = jiffies; | |
686 | ||
687 | /* we can send another packet */ | |
688 | netif_wake_queue(dev); | |
1da177e4 LT |
689 | } |
690 | ||
691 | /*------------------------------------------------------------------------- | |
692 | | | |
693 | | smc_init(int unit) | |
694 | | Input parameters: | |
695 | | dev->base_addr == 0, try to find all possible locations | |
696 | | dev->base_addr == 1, return failure code | |
697 | | dev->base_addr == 2, always allocate space, and return success | |
698 | | dev->base_addr == <anything else> this is the address to check | |
699 | | | |
700 | | Output: | |
701 | | pointer to net_device or ERR_PTR(error) | |
702 | | | |
703 | --------------------------------------------------------------------------- | |
704 | */ | |
705 | static int io; | |
706 | static int irq; | |
707 | static int ifport; | |
708 | ||
709 | struct net_device * __init smc_init(int unit) | |
710 | { | |
711 | struct net_device *dev = alloc_etherdev(sizeof(struct smc_local)); | |
a2bd2ec8 | 712 | struct devlist *smcdev = smc_devlist; |
1da177e4 LT |
713 | int err = 0; |
714 | ||
1da177e4 LT |
715 | if (!dev) |
716 | return ERR_PTR(-ENODEV); | |
717 | ||
718 | if (unit >= 0) { | |
719 | sprintf(dev->name, "eth%d", unit); | |
720 | netdev_boot_setup_check(dev); | |
721 | io = dev->base_addr; | |
722 | irq = dev->irq; | |
723 | } | |
724 | ||
1da177e4 LT |
725 | if (io > 0x1ff) { /* Check a single specified location. */ |
726 | err = smc_probe(dev, io); | |
727 | } else if (io != 0) { /* Don't probe at all. */ | |
728 | err = -ENXIO; | |
729 | } else { | |
730 | for (;smcdev->port; smcdev++) { | |
731 | if (smc_probe(dev, smcdev->port) == 0) | |
732 | break; | |
733 | } | |
734 | if (!smcdev->port) | |
735 | err = -ENODEV; | |
736 | } | |
737 | if (err) | |
738 | goto out; | |
739 | err = register_netdev(dev); | |
740 | if (err) | |
741 | goto out1; | |
742 | return dev; | |
743 | out1: | |
744 | free_irq(dev->irq, dev); | |
745 | release_region(dev->base_addr, SMC_IO_EXTENT); | |
746 | out: | |
747 | free_netdev(dev); | |
748 | return ERR_PTR(err); | |
749 | } | |
750 | ||
751 | /*---------------------------------------------------------------------- | |
752 | . smc_findirq | |
753 | . | |
754 | . This routine has a simple purpose -- make the SMC chip generate an | |
755 | . interrupt, so an auto-detect routine can detect it, and find the IRQ, | |
756 | ------------------------------------------------------------------------ | |
757 | */ | |
dac499f9 | 758 | static int __init smc_findirq(int ioaddr) |
1da177e4 LT |
759 | { |
760 | #ifndef NO_AUTOPROBE | |
761 | int timeout = 20; | |
762 | unsigned long cookie; | |
763 | ||
764 | ||
765 | cookie = probe_irq_on(); | |
766 | ||
767 | /* | |
768 | * What I try to do here is trigger an ALLOC_INT. This is done | |
769 | * by allocating a small chunk of memory, which will give an interrupt | |
770 | * when done. | |
771 | */ | |
772 | ||
773 | ||
774 | SMC_SELECT_BANK(2); | |
775 | /* enable ALLOCation interrupts ONLY */ | |
776 | outb( IM_ALLOC_INT, ioaddr + INT_MASK ); | |
777 | ||
778 | /* | |
779 | . Allocate 512 bytes of memory. Note that the chip was just | |
780 | . reset so all the memory is available | |
781 | */ | |
782 | outw( MC_ALLOC | 1, ioaddr + MMU_CMD ); | |
783 | ||
784 | /* | |
785 | . Wait until positive that the interrupt has been generated | |
786 | */ | |
787 | while ( timeout ) { | |
788 | byte int_status; | |
789 | ||
790 | int_status = inb( ioaddr + INTERRUPT ); | |
791 | ||
792 | if ( int_status & IM_ALLOC_INT ) | |
793 | break; /* got the interrupt */ | |
794 | timeout--; | |
795 | } | |
796 | /* there is really nothing that I can do here if timeout fails, | |
797 | as probe_irq_off will return a 0 anyway, which is what I | |
798 | want in this case. Plus, the clean up is needed in both | |
799 | cases. */ | |
800 | ||
801 | /* DELAY HERE! | |
802 | On a fast machine, the status might change before the interrupt | |
803 | is given to the processor. This means that the interrupt was | |
804 | never detected, and probe_irq_off fails to report anything. | |
805 | This should fix probe_irq_* problems. | |
806 | */ | |
807 | SMC_DELAY(); | |
808 | SMC_DELAY(); | |
809 | ||
810 | /* and disable all interrupts again */ | |
811 | outb( 0, ioaddr + INT_MASK ); | |
812 | ||
813 | /* and return what I found */ | |
814 | return probe_irq_off(cookie); | |
815 | #else /* NO_AUTOPROBE */ | |
816 | struct devlist *smcdev; | |
817 | for (smcdev = smc_devlist; smcdev->port; smcdev++) { | |
818 | if (smcdev->port == ioaddr) | |
819 | return smcdev->irq; | |
820 | } | |
821 | return 0; | |
822 | #endif | |
823 | } | |
824 | ||
32670c36 SH |
825 | static const struct net_device_ops smc_netdev_ops = { |
826 | .ndo_open = smc_open, | |
827 | .ndo_stop = smc_close, | |
828 | .ndo_start_xmit = smc_wait_to_send_packet, | |
829 | .ndo_tx_timeout = smc_timeout, | |
afc4b13d | 830 | .ndo_set_rx_mode = smc_set_multicast_list, |
32670c36 SH |
831 | .ndo_change_mtu = eth_change_mtu, |
832 | .ndo_set_mac_address = eth_mac_addr, | |
833 | .ndo_validate_addr = eth_validate_addr, | |
834 | }; | |
835 | ||
1da177e4 LT |
836 | /*---------------------------------------------------------------------- |
837 | . Function: smc_probe( int ioaddr ) | |
838 | . | |
839 | . Purpose: | |
840 | . Tests to see if a given ioaddr points to an SMC9xxx chip. | |
841 | . Returns a 0 on success | |
842 | . | |
843 | . Algorithm: | |
844 | . (1) see if the high byte of BANK_SELECT is 0x33 | |
845 | . (2) compare the ioaddr with the base register's address | |
846 | . (3) see if I recognize the chip ID in the appropriate register | |
847 | . | |
848 | .--------------------------------------------------------------------- | |
849 | */ | |
850 | ||
851 | /*--------------------------------------------------------------- | |
852 | . Here I do typical initialization tasks. | |
853 | . | |
854 | . o Initialize the structure if needed | |
855 | . o print out my vanity message if not done so already | |
856 | . o print out what type of hardware is detected | |
857 | . o print out the ethernet address | |
858 | . o find the IRQ | |
859 | . o set up my private data | |
860 | . o configure the dev structure with my subroutines | |
861 | . o actually GRAB the irq. | |
862 | . o GRAB the region | |
863 | .----------------------------------------------------------------- | |
864 | */ | |
865 | static int __init smc_probe(struct net_device *dev, int ioaddr) | |
866 | { | |
867 | int i, memory, retval; | |
1da177e4 LT |
868 | unsigned int bank; |
869 | ||
870 | const char *version_string; | |
871 | const char *if_string; | |
872 | ||
873 | /* registers */ | |
874 | word revision_register; | |
875 | word base_address_register; | |
876 | word configuration_register; | |
877 | word memory_info_register; | |
878 | word memory_cfg_register; | |
879 | ||
880 | /* Grab the region so that no one else tries to probe our ioports. */ | |
881 | if (!request_region(ioaddr, SMC_IO_EXTENT, DRV_NAME)) | |
882 | return -EBUSY; | |
883 | ||
884 | dev->irq = irq; | |
885 | dev->if_port = ifport; | |
886 | ||
887 | /* First, see if the high byte is 0x33 */ | |
888 | bank = inw( ioaddr + BANK_SELECT ); | |
889 | if ( (bank & 0xFF00) != 0x3300 ) { | |
890 | retval = -ENODEV; | |
891 | goto err_out; | |
892 | } | |
893 | /* The above MIGHT indicate a device, but I need to write to further | |
894 | test this. */ | |
895 | outw( 0x0, ioaddr + BANK_SELECT ); | |
896 | bank = inw( ioaddr + BANK_SELECT ); | |
897 | if ( (bank & 0xFF00 ) != 0x3300 ) { | |
898 | retval = -ENODEV; | |
899 | goto err_out; | |
900 | } | |
901 | #if !defined(CONFIG_H8S_EDOSK2674) | |
902 | /* well, we've already written once, so hopefully another time won't | |
903 | hurt. This time, I need to switch the bank register to bank 1, | |
904 | so I can access the base address register */ | |
905 | SMC_SELECT_BANK(1); | |
906 | base_address_register = inw( ioaddr + BASE ); | |
907 | if ( ioaddr != ( base_address_register >> 3 & 0x3E0 ) ) { | |
2450022a | 908 | printk(CARDNAME ": IOADDR %x doesn't match configuration (%x). " |
1da177e4 LT |
909 | "Probably not a SMC chip\n", |
910 | ioaddr, base_address_register >> 3 & 0x3E0 ); | |
911 | /* well, the base address register didn't match. Must not have | |
912 | been a SMC chip after all. */ | |
913 | retval = -ENODEV; | |
914 | goto err_out; | |
915 | } | |
916 | #else | |
917 | (void)base_address_register; /* Warning suppression */ | |
918 | #endif | |
919 | ||
920 | ||
921 | /* check if the revision register is something that I recognize. | |
922 | These might need to be added to later, as future revisions | |
923 | could be added. */ | |
924 | SMC_SELECT_BANK(3); | |
925 | revision_register = inw( ioaddr + REVISION ); | |
926 | if ( !chip_ids[ ( revision_register >> 4 ) & 0xF ] ) { | |
927 | /* I don't recognize this chip, so... */ | |
928 | printk(CARDNAME ": IO %x: Unrecognized revision register:" | |
84d57bd6 | 929 | " %x, Contact author.\n", ioaddr, revision_register); |
1da177e4 LT |
930 | |
931 | retval = -ENODEV; | |
932 | goto err_out; | |
933 | } | |
934 | ||
935 | /* at this point I'll assume that the chip is an SMC9xxx. | |
936 | It might be prudent to check a listing of MAC addresses | |
937 | against the hardware address, or do some other tests. */ | |
938 | ||
2ad02bdc | 939 | pr_info_once("%s\n", version); |
1da177e4 LT |
940 | |
941 | /* fill in some of the fields */ | |
942 | dev->base_addr = ioaddr; | |
943 | ||
944 | /* | |
945 | . Get the MAC address ( bank 1, regs 4 - 9 ) | |
946 | */ | |
947 | SMC_SELECT_BANK( 1 ); | |
948 | for ( i = 0; i < 6; i += 2 ) { | |
949 | word address; | |
950 | ||
951 | address = inw( ioaddr + ADDR0 + i ); | |
952 | dev->dev_addr[ i + 1] = address >> 8; | |
953 | dev->dev_addr[ i ] = address & 0xFF; | |
954 | } | |
955 | ||
956 | /* get the memory information */ | |
957 | ||
958 | SMC_SELECT_BANK( 0 ); | |
959 | memory_info_register = inw( ioaddr + MIR ); | |
960 | memory_cfg_register = inw( ioaddr + MCR ); | |
961 | memory = ( memory_cfg_register >> 9 ) & 0x7; /* multiplier */ | |
962 | memory *= 256 * ( memory_info_register & 0xFF ); | |
963 | ||
964 | /* | |
965 | Now, I want to find out more about the chip. This is sort of | |
966 | redundant, but it's cleaner to have it in both, rather than having | |
967 | one VERY long probe procedure. | |
968 | */ | |
969 | SMC_SELECT_BANK(3); | |
970 | revision_register = inw( ioaddr + REVISION ); | |
971 | version_string = chip_ids[ ( revision_register >> 4 ) & 0xF ]; | |
972 | if ( !version_string ) { | |
973 | /* I shouldn't get here because this call was done before.... */ | |
974 | retval = -ENODEV; | |
975 | goto err_out; | |
976 | } | |
977 | ||
978 | /* is it using AUI or 10BaseT ? */ | |
979 | if ( dev->if_port == 0 ) { | |
980 | SMC_SELECT_BANK(1); | |
981 | configuration_register = inw( ioaddr + CONFIG ); | |
982 | if ( configuration_register & CFG_AUI_SELECT ) | |
983 | dev->if_port = 2; | |
984 | else | |
985 | dev->if_port = 1; | |
986 | } | |
987 | if_string = interfaces[ dev->if_port - 1 ]; | |
988 | ||
989 | /* now, reset the chip, and put it into a known state */ | |
990 | smc_reset( ioaddr ); | |
991 | ||
992 | /* | |
993 | . If dev->irq is 0, then the device has to be banged on to see | |
994 | . what the IRQ is. | |
995 | . | |
996 | . This banging doesn't always detect the IRQ, for unknown reasons. | |
997 | . a workaround is to reset the chip and try again. | |
998 | . | |
999 | . Interestingly, the DOS packet driver *SETS* the IRQ on the card to | |
1000 | . be what is requested on the command line. I don't do that, mostly | |
1001 | . because the card that I have uses a non-standard method of accessing | |
1002 | . the IRQs, and because this _should_ work in most configurations. | |
1003 | . | |
1004 | . Specifying an IRQ is done with the assumption that the user knows | |
1005 | . what (s)he is doing. No checking is done!!!! | |
1006 | . | |
1007 | */ | |
1008 | if ( dev->irq < 2 ) { | |
1009 | int trials; | |
1010 | ||
1011 | trials = 3; | |
1012 | while ( trials-- ) { | |
1013 | dev->irq = smc_findirq( ioaddr ); | |
1014 | if ( dev->irq ) | |
1015 | break; | |
1016 | /* kick the card and try again */ | |
1017 | smc_reset( ioaddr ); | |
1018 | } | |
1019 | } | |
1020 | if (dev->irq == 0 ) { | |
1021 | printk(CARDNAME": Couldn't autodetect your IRQ. Use irq=xx.\n"); | |
1022 | retval = -ENODEV; | |
1023 | goto err_out; | |
1024 | } | |
1025 | ||
1026 | /* now, print out the card info, in a short format.. */ | |
1027 | ||
2ad02bdc BB |
1028 | netdev_info(dev, "%s(r:%d) at %#3x IRQ:%d INTF:%s MEM:%db ", |
1029 | version_string, revision_register & 0xF, ioaddr, dev->irq, | |
1030 | if_string, memory); | |
1da177e4 LT |
1031 | /* |
1032 | . Print the Ethernet address | |
1033 | */ | |
2ad02bdc | 1034 | netdev_info(dev, "ADDR: %pM\n", dev->dev_addr); |
1da177e4 | 1035 | |
1da177e4 | 1036 | /* Grab the IRQ */ |
2ad02bdc BB |
1037 | retval = request_irq(dev->irq, smc_interrupt, 0, DRV_NAME, dev); |
1038 | if (retval) { | |
1039 | netdev_warn(dev, "%s: unable to get IRQ %d (irqval=%d).\n", | |
1040 | DRV_NAME, dev->irq, retval); | |
1041 | goto err_out; | |
1042 | } | |
1da177e4 | 1043 | |
32670c36 | 1044 | dev->netdev_ops = &smc_netdev_ops; |
1da177e4 | 1045 | dev->watchdog_timeo = HZ/20; |
1da177e4 LT |
1046 | |
1047 | return 0; | |
1048 | ||
1049 | err_out: | |
1050 | release_region(ioaddr, SMC_IO_EXTENT); | |
1051 | return retval; | |
1052 | } | |
1053 | ||
1054 | #if SMC_DEBUG > 2 | |
1055 | static void print_packet( byte * buf, int length ) | |
1056 | { | |
1057 | #if 0 | |
1058 | int i; | |
1059 | int remainder; | |
1060 | int lines; | |
1061 | ||
2ad02bdc | 1062 | pr_dbg("Packet of length %d\n", length); |
1da177e4 LT |
1063 | lines = length / 16; |
1064 | remainder = length % 16; | |
1065 | ||
1066 | for ( i = 0; i < lines ; i ++ ) { | |
1067 | int cur; | |
1068 | ||
2ad02bdc | 1069 | printk(KERN_DEBUG); |
1da177e4 LT |
1070 | for ( cur = 0; cur < 8; cur ++ ) { |
1071 | byte a, b; | |
1072 | ||
1073 | a = *(buf ++ ); | |
1074 | b = *(buf ++ ); | |
2ad02bdc | 1075 | pr_cont("%02x%02x ", a, b); |
1da177e4 | 1076 | } |
2ad02bdc | 1077 | pr_cont("\n"); |
1da177e4 | 1078 | } |
2ad02bdc | 1079 | printk(KERN_DEBUG); |
1da177e4 LT |
1080 | for ( i = 0; i < remainder/2 ; i++ ) { |
1081 | byte a, b; | |
1082 | ||
1083 | a = *(buf ++ ); | |
1084 | b = *(buf ++ ); | |
2ad02bdc | 1085 | pr_cont("%02x%02x ", a, b); |
1da177e4 | 1086 | } |
2ad02bdc | 1087 | pr_cont("\n"); |
1da177e4 LT |
1088 | #endif |
1089 | } | |
1090 | #endif | |
1091 | ||
1092 | ||
1093 | /* | |
1094 | * Open and Initialize the board | |
1095 | * | |
1096 | * Set up everything, reset the card, etc .. | |
1097 | * | |
1098 | */ | |
1099 | static int smc_open(struct net_device *dev) | |
1100 | { | |
1101 | int ioaddr = dev->base_addr; | |
1102 | ||
1103 | int i; /* used to set hw ethernet address */ | |
1104 | ||
1105 | /* clear out all the junk that was put here before... */ | |
8f15ea42 | 1106 | memset(netdev_priv(dev), 0, sizeof(struct smc_local)); |
1da177e4 LT |
1107 | |
1108 | /* reset the hardware */ | |
1109 | ||
1110 | smc_reset( ioaddr ); | |
1111 | smc_enable( ioaddr ); | |
1112 | ||
1113 | /* Select which interface to use */ | |
1114 | ||
1115 | SMC_SELECT_BANK( 1 ); | |
1116 | if ( dev->if_port == 1 ) { | |
1117 | outw( inw( ioaddr + CONFIG ) & ~CFG_AUI_SELECT, | |
1118 | ioaddr + CONFIG ); | |
1119 | } | |
1120 | else if ( dev->if_port == 2 ) { | |
1121 | outw( inw( ioaddr + CONFIG ) | CFG_AUI_SELECT, | |
1122 | ioaddr + CONFIG ); | |
1123 | } | |
1124 | ||
1125 | /* | |
1126 | According to Becker, I have to set the hardware address | |
1127 | at this point, because the (l)user can set it with an | |
1128 | ioctl. Easily done... | |
1129 | */ | |
1130 | SMC_SELECT_BANK( 1 ); | |
1131 | for ( i = 0; i < 6; i += 2 ) { | |
1132 | word address; | |
1133 | ||
1134 | address = dev->dev_addr[ i + 1 ] << 8 ; | |
1135 | address |= dev->dev_addr[ i ]; | |
1136 | outw( address, ioaddr + ADDR0 + i ); | |
1137 | } | |
6aa20a22 | 1138 | |
1da177e4 LT |
1139 | netif_start_queue(dev); |
1140 | return 0; | |
1141 | } | |
1142 | ||
1143 | /*-------------------------------------------------------- | |
1144 | . Called by the kernel to send a packet out into the void | |
1145 | . of the net. This routine is largely based on | |
1146 | . skeleton.c, from Becker. | |
1147 | .-------------------------------------------------------- | |
1148 | */ | |
1149 | ||
1150 | static void smc_timeout(struct net_device *dev) | |
1151 | { | |
1152 | /* If we get here, some higher level has decided we are broken. | |
1153 | There should really be a "kick me" function call instead. */ | |
2ad02bdc BB |
1154 | netdev_warn(dev, CARDNAME": transmit timed out, %s?\n", |
1155 | tx_done(dev) ? "IRQ conflict" : "network cable problem"); | |
1da177e4 LT |
1156 | /* "kick" the adaptor */ |
1157 | smc_reset( dev->base_addr ); | |
1158 | smc_enable( dev->base_addr ); | |
1ae5dc34 | 1159 | dev->trans_start = jiffies; /* prevent tx timeout */ |
1da177e4 | 1160 | /* clear anything saved */ |
8f15ea42 | 1161 | ((struct smc_local *)netdev_priv(dev))->saved_skb = NULL; |
1da177e4 LT |
1162 | netif_wake_queue(dev); |
1163 | } | |
1164 | ||
1165 | /*------------------------------------------------------------- | |
1166 | . | |
1167 | . smc_rcv - receive a packet from the card | |
1168 | . | |
1169 | . There is ( at least ) a packet waiting to be read from | |
1170 | . chip-memory. | |
1171 | . | |
1172 | . o Read the status | |
1173 | . o If an error, record it | |
1174 | . o otherwise, read in the packet | |
1175 | -------------------------------------------------------------- | |
1176 | */ | |
1177 | static void smc_rcv(struct net_device *dev) | |
1178 | { | |
1da177e4 LT |
1179 | int ioaddr = dev->base_addr; |
1180 | int packet_number; | |
1181 | word status; | |
1182 | word packet_length; | |
1183 | ||
1184 | /* assume bank 2 */ | |
1185 | ||
1186 | packet_number = inw( ioaddr + FIFO_PORTS ); | |
1187 | ||
1188 | if ( packet_number & FP_RXEMPTY ) { | |
1189 | /* we got called , but nothing was on the FIFO */ | |
84d57bd6 | 1190 | PRINTK((CARDNAME ": WARNING: smc_rcv with nothing on FIFO.\n")); |
1da177e4 LT |
1191 | /* don't need to restore anything */ |
1192 | return; | |
1193 | } | |
1194 | ||
1195 | /* start reading from the start of the packet */ | |
1196 | outw( PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER ); | |
1197 | ||
1198 | /* First two words are status and packet_length */ | |
1199 | status = inw( ioaddr + DATA_1 ); | |
1200 | packet_length = inw( ioaddr + DATA_1 ); | |
1201 | ||
1202 | packet_length &= 0x07ff; /* mask off top bits */ | |
1203 | ||
1204 | PRINTK2(("RCV: STATUS %4x LENGTH %4x\n", status, packet_length )); | |
1205 | /* | |
1206 | . the packet length contains 3 extra words : | |
1207 | . status, length, and an extra word with an odd byte . | |
1208 | */ | |
1209 | packet_length -= 6; | |
1210 | ||
1211 | if ( !(status & RS_ERRORS ) ){ | |
1212 | /* do stuff to make a new packet */ | |
1213 | struct sk_buff * skb; | |
1214 | byte * data; | |
1215 | ||
1216 | /* read one extra byte */ | |
1217 | if ( status & RS_ODDFRAME ) | |
1218 | packet_length++; | |
1219 | ||
1220 | /* set multicast stats */ | |
1221 | if ( status & RS_MULTICAST ) | |
09f75cd7 | 1222 | dev->stats.multicast++; |
1da177e4 | 1223 | |
dae2e9f4 | 1224 | skb = netdev_alloc_skb(dev, packet_length + 5); |
1da177e4 | 1225 | if ( skb == NULL ) { |
09f75cd7 | 1226 | dev->stats.rx_dropped++; |
1da177e4 LT |
1227 | goto done; |
1228 | } | |
1229 | ||
1230 | /* | |
1231 | ! This should work without alignment, but it could be | |
1232 | ! in the worse case | |
1233 | */ | |
1234 | ||
1235 | skb_reserve( skb, 2 ); /* 16 bit alignment */ | |
1236 | ||
1da177e4 LT |
1237 | data = skb_put( skb, packet_length); |
1238 | ||
1239 | #ifdef USE_32_BIT | |
1240 | /* QUESTION: Like in the TX routine, do I want | |
1241 | to send the DWORDs or the bytes first, or some | |
1242 | mixture. A mixture might improve already slow PIO | |
1243 | performance */ | |
84d57bd6 | 1244 | PRINTK3((" Reading %d dwords (and %d bytes)\n", |
1da177e4 LT |
1245 | packet_length >> 2, packet_length & 3 )); |
1246 | insl(ioaddr + DATA_1 , data, packet_length >> 2 ); | |
1247 | /* read the left over bytes */ | |
1248 | insb( ioaddr + DATA_1, data + (packet_length & 0xFFFFFC), | |
1249 | packet_length & 0x3 ); | |
1250 | #else | |
84d57bd6 | 1251 | PRINTK3((" Reading %d words and %d byte(s)\n", |
1da177e4 LT |
1252 | (packet_length >> 1 ), packet_length & 1 )); |
1253 | insw(ioaddr + DATA_1 , data, packet_length >> 1); | |
1254 | if ( packet_length & 1 ) { | |
1255 | data += packet_length & ~1; | |
1256 | *(data++) = inb( ioaddr + DATA_1 ); | |
1257 | } | |
1258 | #endif | |
1259 | #if SMC_DEBUG > 2 | |
1260 | print_packet( data, packet_length ); | |
1261 | #endif | |
1262 | ||
1263 | skb->protocol = eth_type_trans(skb, dev ); | |
1264 | netif_rx(skb); | |
09f75cd7 JG |
1265 | dev->stats.rx_packets++; |
1266 | dev->stats.rx_bytes += packet_length; | |
1da177e4 LT |
1267 | } else { |
1268 | /* error ... */ | |
09f75cd7 | 1269 | dev->stats.rx_errors++; |
1da177e4 | 1270 | |
09f75cd7 | 1271 | if ( status & RS_ALGNERR ) dev->stats.rx_frame_errors++; |
1da177e4 | 1272 | if ( status & (RS_TOOSHORT | RS_TOOLONG ) ) |
09f75cd7 JG |
1273 | dev->stats.rx_length_errors++; |
1274 | if ( status & RS_BADCRC) dev->stats.rx_crc_errors++; | |
1da177e4 LT |
1275 | } |
1276 | ||
1277 | done: | |
1278 | /* error or good, tell the card to get rid of this packet */ | |
1279 | outw( MC_RELEASE, ioaddr + MMU_CMD ); | |
1280 | } | |
1281 | ||
1282 | ||
1283 | /************************************************************************* | |
1284 | . smc_tx | |
1285 | . | |
1286 | . Purpose: Handle a transmit error message. This will only be called | |
1287 | . when an error, because of the AUTO_RELEASE mode. | |
1288 | . | |
1289 | . Algorithm: | |
1290 | . Save pointer and packet no | |
1291 | . Get the packet no from the top of the queue | |
1292 | . check if it's valid ( if not, is this an error??? ) | |
1293 | . read the status word | |
1294 | . record the error | |
1295 | . ( resend? Not really, since we don't want old packets around ) | |
1296 | . Restore saved values | |
1297 | ************************************************************************/ | |
1298 | static void smc_tx( struct net_device * dev ) | |
1299 | { | |
1300 | int ioaddr = dev->base_addr; | |
1301 | struct smc_local *lp = netdev_priv(dev); | |
1302 | byte saved_packet; | |
1303 | byte packet_no; | |
1304 | word tx_status; | |
1305 | ||
1306 | ||
1307 | /* assume bank 2 */ | |
1308 | ||
1309 | saved_packet = inb( ioaddr + PNR_ARR ); | |
1310 | packet_no = inw( ioaddr + FIFO_PORTS ); | |
1311 | packet_no &= 0x7F; | |
1312 | ||
1313 | /* select this as the packet to read from */ | |
1314 | outb( packet_no, ioaddr + PNR_ARR ); | |
1315 | ||
1316 | /* read the first word from this packet */ | |
1317 | outw( PTR_AUTOINC | PTR_READ, ioaddr + POINTER ); | |
1318 | ||
1319 | tx_status = inw( ioaddr + DATA_1 ); | |
84d57bd6 | 1320 | PRINTK3((CARDNAME": TX DONE STATUS: %4x\n", tx_status)); |
1da177e4 | 1321 | |
09f75cd7 JG |
1322 | dev->stats.tx_errors++; |
1323 | if ( tx_status & TS_LOSTCAR ) dev->stats.tx_carrier_errors++; | |
1da177e4 | 1324 | if ( tx_status & TS_LATCOL ) { |
2ad02bdc | 1325 | netdev_dbg(dev, CARDNAME": Late collision occurred on last xmit.\n"); |
09f75cd7 | 1326 | dev->stats.tx_window_errors++; |
1da177e4 LT |
1327 | } |
1328 | #if 0 | |
1329 | if ( tx_status & TS_16COL ) { ... } | |
1330 | #endif | |
1331 | ||
1332 | if ( tx_status & TS_SUCCESS ) { | |
2ad02bdc | 1333 | netdev_info(dev, CARDNAME": Successful packet caused interrupt\n"); |
1da177e4 LT |
1334 | } |
1335 | /* re-enable transmit */ | |
1336 | SMC_SELECT_BANK( 0 ); | |
1337 | outw( inw( ioaddr + TCR ) | TCR_ENABLE, ioaddr + TCR ); | |
1338 | ||
1339 | /* kill the packet */ | |
1340 | SMC_SELECT_BANK( 2 ); | |
1341 | outw( MC_FREEPKT, ioaddr + MMU_CMD ); | |
1342 | ||
1343 | /* one less packet waiting for me */ | |
1344 | lp->packets_waiting--; | |
1345 | ||
1346 | outb( saved_packet, ioaddr + PNR_ARR ); | |
1da177e4 LT |
1347 | } |
1348 | ||
1349 | /*-------------------------------------------------------------------- | |
1350 | . | |
1351 | . This is the main routine of the driver, to handle the device when | |
1352 | . it needs some attention. | |
1353 | . | |
1354 | . So: | |
1355 | . first, save state of the chipset | |
1356 | . branch off into routines to handle each case, and acknowledge | |
1357 | . each to the interrupt register | |
1358 | . and finally restore state. | |
1359 | . | |
1360 | ---------------------------------------------------------------------*/ | |
1361 | ||
7d12e780 | 1362 | static irqreturn_t smc_interrupt(int irq, void * dev_id) |
1da177e4 LT |
1363 | { |
1364 | struct net_device *dev = dev_id; | |
1365 | int ioaddr = dev->base_addr; | |
1366 | struct smc_local *lp = netdev_priv(dev); | |
1367 | ||
1368 | byte status; | |
1369 | word card_stats; | |
1370 | byte mask; | |
1371 | int timeout; | |
1372 | /* state registers */ | |
1373 | word saved_bank; | |
1374 | word saved_pointer; | |
1375 | int handled = 0; | |
1376 | ||
1377 | ||
84d57bd6 | 1378 | PRINTK3((CARDNAME": SMC interrupt started\n")); |
1da177e4 LT |
1379 | |
1380 | saved_bank = inw( ioaddr + BANK_SELECT ); | |
1381 | ||
1382 | SMC_SELECT_BANK(2); | |
1383 | saved_pointer = inw( ioaddr + POINTER ); | |
1384 | ||
1385 | mask = inb( ioaddr + INT_MASK ); | |
1386 | /* clear all interrupts */ | |
1387 | outb( 0, ioaddr + INT_MASK ); | |
1388 | ||
1389 | ||
1390 | /* set a timeout value, so I don't stay here forever */ | |
1391 | timeout = 4; | |
1392 | ||
84d57bd6 | 1393 | PRINTK2((KERN_WARNING CARDNAME ": MASK IS %x\n", mask)); |
1da177e4 LT |
1394 | do { |
1395 | /* read the status flag, and mask it */ | |
1396 | status = inb( ioaddr + INTERRUPT ) & mask; | |
1397 | if (!status ) | |
1398 | break; | |
1399 | ||
1400 | handled = 1; | |
1401 | ||
1402 | PRINTK3((KERN_WARNING CARDNAME | |
84d57bd6 | 1403 | ": Handling interrupt status %x\n", status)); |
1da177e4 LT |
1404 | |
1405 | if (status & IM_RCV_INT) { | |
1406 | /* Got a packet(s). */ | |
1407 | PRINTK2((KERN_WARNING CARDNAME | |
1408 | ": Receive Interrupt\n")); | |
1409 | smc_rcv(dev); | |
1410 | } else if (status & IM_TX_INT ) { | |
1411 | PRINTK2((KERN_WARNING CARDNAME | |
1412 | ": TX ERROR handled\n")); | |
1413 | smc_tx(dev); | |
1414 | outb(IM_TX_INT, ioaddr + INTERRUPT ); | |
1415 | } else if (status & IM_TX_EMPTY_INT ) { | |
1416 | /* update stats */ | |
1417 | SMC_SELECT_BANK( 0 ); | |
1418 | card_stats = inw( ioaddr + COUNTER ); | |
1419 | /* single collisions */ | |
09f75cd7 | 1420 | dev->stats.collisions += card_stats & 0xF; |
1da177e4 LT |
1421 | card_stats >>= 4; |
1422 | /* multiple collisions */ | |
09f75cd7 | 1423 | dev->stats.collisions += card_stats & 0xF; |
1da177e4 LT |
1424 | |
1425 | /* these are for when linux supports these statistics */ | |
1426 | ||
1427 | SMC_SELECT_BANK( 2 ); | |
1428 | PRINTK2((KERN_WARNING CARDNAME | |
1429 | ": TX_BUFFER_EMPTY handled\n")); | |
1430 | outb( IM_TX_EMPTY_INT, ioaddr + INTERRUPT ); | |
1431 | mask &= ~IM_TX_EMPTY_INT; | |
09f75cd7 | 1432 | dev->stats.tx_packets += lp->packets_waiting; |
1da177e4 LT |
1433 | lp->packets_waiting = 0; |
1434 | ||
1435 | } else if (status & IM_ALLOC_INT ) { | |
1436 | PRINTK2((KERN_DEBUG CARDNAME | |
84d57bd6 | 1437 | ": Allocation interrupt\n")); |
1da177e4 LT |
1438 | /* clear this interrupt so it doesn't happen again */ |
1439 | mask &= ~IM_ALLOC_INT; | |
1440 | ||
1441 | smc_hardware_send_packet( dev ); | |
1442 | ||
1443 | /* enable xmit interrupts based on this */ | |
1444 | mask |= ( IM_TX_EMPTY_INT | IM_TX_INT ); | |
1445 | ||
1446 | /* and let the card send more packets to me */ | |
1447 | netif_wake_queue(dev); | |
1448 | ||
1449 | PRINTK2((CARDNAME": Handoff done successfully.\n")); | |
1450 | } else if (status & IM_RX_OVRN_INT ) { | |
09f75cd7 JG |
1451 | dev->stats.rx_errors++; |
1452 | dev->stats.rx_fifo_errors++; | |
1da177e4 LT |
1453 | outb( IM_RX_OVRN_INT, ioaddr + INTERRUPT ); |
1454 | } else if (status & IM_EPH_INT ) { | |
84d57bd6 | 1455 | PRINTK((CARDNAME ": UNSUPPORTED: EPH INTERRUPT\n")); |
1da177e4 | 1456 | } else if (status & IM_ERCV_INT ) { |
84d57bd6 | 1457 | PRINTK((CARDNAME ": UNSUPPORTED: ERCV INTERRUPT\n")); |
1da177e4 LT |
1458 | outb( IM_ERCV_INT, ioaddr + INTERRUPT ); |
1459 | } | |
1460 | } while ( timeout -- ); | |
1461 | ||
1462 | ||
1463 | /* restore state register */ | |
1464 | SMC_SELECT_BANK( 2 ); | |
1465 | outb( mask, ioaddr + INT_MASK ); | |
1466 | ||
84d57bd6 | 1467 | PRINTK3((KERN_WARNING CARDNAME ": MASK is now %x\n", mask)); |
1da177e4 LT |
1468 | outw( saved_pointer, ioaddr + POINTER ); |
1469 | ||
1470 | SMC_SELECT_BANK( saved_bank ); | |
1471 | ||
1472 | PRINTK3((CARDNAME ": Interrupt done\n")); | |
1473 | return IRQ_RETVAL(handled); | |
1474 | } | |
1475 | ||
1476 | ||
1477 | /*---------------------------------------------------- | |
1478 | . smc_close | |
1479 | . | |
1480 | . this makes the board clean up everything that it can | |
1481 | . and not talk to the outside world. Caused by | |
1482 | . an 'ifconfig ethX down' | |
1483 | . | |
1484 | -----------------------------------------------------*/ | |
1485 | static int smc_close(struct net_device *dev) | |
1486 | { | |
1487 | netif_stop_queue(dev); | |
1488 | /* clear everything */ | |
1489 | smc_shutdown( dev->base_addr ); | |
1490 | ||
1491 | /* Update the statistics here. */ | |
1492 | return 0; | |
1493 | } | |
1494 | ||
1da177e4 LT |
1495 | /*----------------------------------------------------------- |
1496 | . smc_set_multicast_list | |
1497 | . | |
1498 | . This routine will, depending on the values passed to it, | |
1499 | . either make it accept multicast packets, go into | |
1500 | . promiscuous mode ( for TCPDUMP and cousins ) or accept | |
1501 | . a select set of multicast packets | |
1502 | */ | |
1503 | static void smc_set_multicast_list(struct net_device *dev) | |
1504 | { | |
1505 | short ioaddr = dev->base_addr; | |
1506 | ||
1507 | SMC_SELECT_BANK(0); | |
1508 | if ( dev->flags & IFF_PROMISC ) | |
1509 | outw( inw(ioaddr + RCR ) | RCR_PROMISC, ioaddr + RCR ); | |
1510 | ||
1511 | /* BUG? I never disable promiscuous mode if multicasting was turned on. | |
1512 | Now, I turn off promiscuous mode, but I don't do anything to multicasting | |
1513 | when promiscuous mode is turned on. | |
1514 | */ | |
1515 | ||
1516 | /* Here, I am setting this to accept all multicast packets. | |
1517 | I don't need to zero the multicast table, because the flag is | |
1518 | checked before the table is | |
1519 | */ | |
1520 | else if (dev->flags & IFF_ALLMULTI) | |
1521 | outw( inw(ioaddr + RCR ) | RCR_ALMUL, ioaddr + RCR ); | |
1522 | ||
1523 | /* We just get all multicast packets even if we only want them | |
1524 | . from one source. This will be changed at some future | |
1525 | . point. */ | |
4cd24eaf | 1526 | else if (!netdev_mc_empty(dev)) { |
1da177e4 LT |
1527 | /* support hardware multicasting */ |
1528 | ||
1529 | /* be sure I get rid of flags I might have set */ | |
1530 | outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL), | |
1531 | ioaddr + RCR ); | |
1532 | /* NOTE: this has to set the bank, so make sure it is the | |
1533 | last thing called. The bank is set to zero at the top */ | |
567ec874 | 1534 | smc_setmulticast(ioaddr, dev); |
1da177e4 LT |
1535 | } |
1536 | else { | |
1537 | outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL), | |
1538 | ioaddr + RCR ); | |
1539 | ||
1540 | /* | |
1541 | since I'm disabling all multicast entirely, I need to | |
1542 | clear the multicast list | |
1543 | */ | |
1544 | SMC_SELECT_BANK( 3 ); | |
1545 | outw( 0, ioaddr + MULTICAST1 ); | |
1546 | outw( 0, ioaddr + MULTICAST2 ); | |
1547 | outw( 0, ioaddr + MULTICAST3 ); | |
1548 | outw( 0, ioaddr + MULTICAST4 ); | |
1549 | } | |
1550 | } | |
1551 | ||
1552 | #ifdef MODULE | |
1553 | ||
1554 | static struct net_device *devSMC9194; | |
1555 | MODULE_LICENSE("GPL"); | |
1556 | ||
1557 | module_param(io, int, 0); | |
1558 | module_param(irq, int, 0); | |
1559 | module_param(ifport, int, 0); | |
1560 | MODULE_PARM_DESC(io, "SMC 99194 I/O base address"); | |
1561 | MODULE_PARM_DESC(irq, "SMC 99194 IRQ number"); | |
1562 | MODULE_PARM_DESC(ifport, "SMC 99194 interface port (0-default, 1-TP, 2-AUI)"); | |
1563 | ||
a2bd2ec8 | 1564 | int __init init_module(void) |
1da177e4 LT |
1565 | { |
1566 | if (io == 0) | |
1567 | printk(KERN_WARNING | |
1568 | CARDNAME": You shouldn't use auto-probing with insmod!\n" ); | |
1569 | ||
1570 | /* copy the parameters from insmod into the device structure */ | |
1571 | devSMC9194 = smc_init(-1); | |
c1fcbaa5 | 1572 | return PTR_ERR_OR_ZERO(devSMC9194); |
1da177e4 LT |
1573 | } |
1574 | ||
afc8eb46 | 1575 | void __exit cleanup_module(void) |
1da177e4 LT |
1576 | { |
1577 | unregister_netdev(devSMC9194); | |
1578 | free_irq(devSMC9194->irq, devSMC9194); | |
1579 | release_region(devSMC9194->base_addr, SMC_IO_EXTENT); | |
1580 | free_netdev(devSMC9194); | |
1581 | } | |
1582 | ||
1583 | #endif /* MODULE */ |