]> git.ipfire.org Git - u-boot.git/blob - drivers/lan91c96.c
* Code cleanup:
[u-boot.git] / drivers / lan91c96.c
1 /*------------------------------------------------------------------------
2 * lan91c96.c
3 * This is a driver for SMSC's LAN91C96 single-chip Ethernet device, based
4 * on the SMC91111 driver from U-boot.
5 *
6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Rolf Offermanns <rof@sysgo.de>
9 *
10 * Copyright (C) 2001 Standard Microsystems Corporation (SMSC)
11 * Developed by Simple Network Magic Corporation (SNMC)
12 * Copyright (C) 1996 by Erik Stahlman (ES)
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 * Information contained in this file was obtained from the LAN91C96
29 * manual from SMC. To get a copy, if you really want one, you can find
30 * information under www.smsc.com.
31 *
32 *
33 * "Features" of the SMC chip:
34 * 6144 byte packet memory. ( for the 91C96 )
35 * EEPROM for configuration
36 * AUI/TP selection ( mine has 10Base2/10BaseT select )
37 *
38 * Arguments:
39 * io = for the base address
40 * irq = for the IRQ
41 *
42 * author:
43 * Erik Stahlman ( erik@vt.edu )
44 * Daris A Nevil ( dnevil@snmc.com )
45 *
46 *
47 * Hardware multicast code from Peter Cammaert ( pc@denkart.be )
48 *
49 * Sources:
50 * o SMSC LAN91C96 databook (www.smsc.com)
51 * o smc91111.c (u-boot driver)
52 * o smc9194.c (linux kernel driver)
53 * o lan91c96.c (Intel Diagnostic Manager driver)
54 *
55 * History:
56 * 04/30/03 Mathijs Haarman Modified smc91111.c (u-boot version)
57 * for lan91c96
58 *---------------------------------------------------------------------------
59 */
60
61 #include <common.h>
62 #include <command.h>
63 #include "lan91c96.h"
64 #include <net.h>
65
66 #ifdef CONFIG_DRIVER_LAN91C96
67
68 #if (CONFIG_COMMANDS & CFG_CMD_NET)
69
70 /*------------------------------------------------------------------------
71 *
72 * Configuration options, for the experienced user to change.
73 *
74 -------------------------------------------------------------------------*/
75
76 /* Use power-down feature of the chip */
77 #define POWER_DOWN 0
78
79 /*
80 * Wait time for memory to be free. This probably shouldn't be
81 * tuned that much, as waiting for this means nothing else happens
82 * in the system
83 */
84 #define MEMORY_WAIT_TIME 16
85
86 #define SMC_DEBUG 0
87
88 #if (SMC_DEBUG > 2 )
89 #define PRINTK3(args...) printf(args)
90 #else
91 #define PRINTK3(args...)
92 #endif
93
94 #if SMC_DEBUG > 1
95 #define PRINTK2(args...) printf(args)
96 #else
97 #define PRINTK2(args...)
98 #endif
99
100 #ifdef SMC_DEBUG
101 #define PRINTK(args...) printf(args)
102 #else
103 #define PRINTK(args...)
104 #endif
105
106
107 /*------------------------------------------------------------------------
108 *
109 * The internal workings of the driver. If you are changing anything
110 * here with the SMC stuff, you should have the datasheet and know
111 * what you are doing.
112 *
113 *------------------------------------------------------------------------
114 */
115 #define CARDNAME "LAN91C96"
116
117 #define SMC_BASE_ADDRESS CONFIG_LAN91C96_BASE
118
119 #define SMC_DEV_NAME "LAN91C96"
120 #define SMC_ALLOC_MAX_TRY 5
121 #define SMC_TX_TIMEOUT 30
122
123 #define ETH_ZLEN 60
124
125 #ifdef CONFIG_LAN91C96_USE_32_BIT
126 #define USE_32_BIT 1
127 #else
128 #undef USE_32_BIT
129 #endif
130
131 /*-----------------------------------------------------------------
132 *
133 * The driver can be entered at any of the following entry points.
134 *
135 *-----------------------------------------------------------------
136 */
137
138 extern int eth_init (bd_t * bd);
139 extern void eth_halt (void);
140 extern int eth_rx (void);
141 extern int eth_send (volatile void *packet, int length);
142 static int smc_hw_init (void);
143
144 /*
145 * This is called by register_netdev(). It is responsible for
146 * checking the portlist for the SMC9000 series chipset. If it finds
147 * one, then it will initialize the device, find the hardware information,
148 * and sets up the appropriate device parameters.
149 * NOTE: Interrupts are *OFF* when this procedure is called.
150 *
151 * NB:This shouldn't be static since it is referred to externally.
152 */
153 int smc_init (void);
154
155 /*
156 * This is called by unregister_netdev(). It is responsible for
157 * cleaning up before the driver is finally unregistered and discarded.
158 */
159 void smc_destructor (void);
160
161 /*
162 * The kernel calls this function when someone wants to use the device,
163 * typically 'ifconfig ethX up'.
164 */
165 static int smc_open (void);
166
167
168 /*
169 * This is called by the kernel in response to 'ifconfig ethX down'. It
170 * is responsible for cleaning up everything that the open routine
171 * does, and maybe putting the card into a powerdown state.
172 */
173 static int smc_close (void);
174
175 /*
176 * This is a separate procedure to handle the receipt of a packet, to
177 * leave the interrupt code looking slightly cleaner
178 */
179 static int smc_rcv (void);
180
181
182 /* ------------------------------------------------------------
183 * Internal routines
184 * ------------------------------------------------------------
185 */
186
187 static char smc_mac_addr[] = { 0xc0, 0x00, 0x00, 0x1b, 0x62, 0x9c };
188
189 /*
190 * This function must be called before smc_open() if you want to override
191 * the default mac address.
192 */
193
194 void smc_set_mac_addr (const char *addr)
195 {
196 int i;
197
198 for (i = 0; i < sizeof (smc_mac_addr); i++) {
199 smc_mac_addr[i] = addr[i];
200 }
201 }
202
203 /*
204 * smc_get_macaddr is no longer used. If you want to override the default
205 * mac address, call smc_get_mac_addr as a part of the board initialisation.
206 */
207
208 #if 0
209 void smc_get_macaddr (byte * addr)
210 {
211 /* MAC ADDRESS AT FLASHBLOCK 1 / OFFSET 0x10 */
212 unsigned char *dnp1110_mac = (unsigned char *) (0xE8000000 + 0x20010);
213 int i;
214
215
216 for (i = 0; i < 6; i++) {
217 addr[0] = *(dnp1110_mac + 0);
218 addr[1] = *(dnp1110_mac + 1);
219 addr[2] = *(dnp1110_mac + 2);
220 addr[3] = *(dnp1110_mac + 3);
221 addr[4] = *(dnp1110_mac + 4);
222 addr[5] = *(dnp1110_mac + 5);
223 }
224 }
225 #endif /* 0 */
226
227 /***********************************************
228 * Show available memory *
229 ***********************************************/
230 void dump_memory_info (void)
231 {
232 word mem_info;
233 word old_bank;
234
235 old_bank = SMC_inw (LAN91C96_BANK_SELECT) & 0xF;
236
237 SMC_SELECT_BANK (0);
238 mem_info = SMC_inw (LAN91C96_MIR);
239 PRINTK2 ("Memory: %4d available\n", (mem_info >> 8) * 2048);
240
241 SMC_SELECT_BANK (old_bank);
242 }
243
244 /*
245 * A rather simple routine to print out a packet for debugging purposes.
246 */
247 #if SMC_DEBUG > 2
248 static void print_packet (byte *, int);
249 #endif
250
251 /* #define tx_done(dev) 1 */
252
253
254 /* this does a soft reset on the device */
255 static void smc_reset (void);
256
257 /* Enable Interrupts, Receive, and Transmit */
258 static void smc_enable (void);
259
260 /* this puts the device in an inactive state */
261 static void smc_shutdown (void);
262
263
264 static int poll4int (byte mask, int timeout)
265 {
266 int tmo = get_timer (0) + timeout * CFG_HZ;
267 int is_timeout = 0;
268 word old_bank = SMC_inw (LAN91C96_BANK_SELECT);
269
270 PRINTK2 ("Polling...\n");
271 SMC_SELECT_BANK (2);
272 while ((SMC_inw (LAN91C96_INT_STATS) & mask) == 0) {
273 if (get_timer (0) >= tmo) {
274 is_timeout = 1;
275 break;
276 }
277 }
278
279 /* restore old bank selection */
280 SMC_SELECT_BANK (old_bank);
281
282 if (is_timeout)
283 return 1;
284 else
285 return 0;
286 }
287
288 /*
289 * Function: smc_reset( void )
290 * Purpose:
291 * This sets the SMC91111 chip to its normal state, hopefully from whatever
292 * mess that any other DOS driver has put it in.
293 *
294 * Maybe I should reset more registers to defaults in here? SOFTRST should
295 * do that for me.
296 *
297 * Method:
298 * 1. send a SOFT RESET
299 * 2. wait for it to finish
300 * 3. enable autorelease mode
301 * 4. reset the memory management unit
302 * 5. clear all interrupts
303 *
304 */
305 static void smc_reset (void)
306 {
307 PRINTK2 ("%s:smc_reset\n", SMC_DEV_NAME);
308
309 /* This resets the registers mostly to defaults, but doesn't
310 affect EEPROM. That seems unnecessary */
311 SMC_SELECT_BANK (0);
312 SMC_outw (LAN91C96_RCR_SOFT_RST, LAN91C96_RCR);
313
314 udelay (10);
315
316 /* Disable transmit and receive functionality */
317 SMC_outw (0, LAN91C96_RCR);
318 SMC_outw (0, LAN91C96_TCR);
319
320 /* set the control register */
321 SMC_SELECT_BANK (1);
322 SMC_outw (SMC_inw (LAN91C96_CONTROL) | LAN91C96_CTR_BIT_8,
323 LAN91C96_CONTROL);
324
325 /* Disable all interrupts */
326 SMC_outb (0, LAN91C96_INT_MASK);
327 }
328
329 /*
330 * Function: smc_enable
331 * Purpose: let the chip talk to the outside work
332 * Method:
333 * 1. Initialize the Memory Configuration Register
334 * 2. Enable the transmitter
335 * 3. Enable the receiver
336 */
337 static void smc_enable ()
338 {
339 PRINTK2 ("%s:smc_enable\n", SMC_DEV_NAME);
340 SMC_SELECT_BANK (0);
341
342 /* Initialize the Memory Configuration Register. See page
343 49 of the LAN91C96 data sheet for details. */
344 SMC_outw (LAN91C96_MCR_TRANSMIT_PAGES, LAN91C96_MCR);
345
346 /* Initialize the Transmit Control Register */
347 SMC_outw (LAN91C96_TCR_TXENA, LAN91C96_TCR);
348 /* Initialize the Receive Control Register
349 * FIXME:
350 * The promiscuous bit set because I could not receive ARP reply
351 * packets from the server when I send a ARP request. It only works
352 * when I set the promiscuous bit
353 */
354 SMC_outw (LAN91C96_RCR_RXEN | LAN91C96_RCR_PRMS, LAN91C96_RCR);
355 }
356
357 /*
358 * Function: smc_shutdown
359 * Purpose: closes down the SMC91xxx chip.
360 * Method:
361 * 1. zero the interrupt mask
362 * 2. clear the enable receive flag
363 * 3. clear the enable xmit flags
364 *
365 * TODO:
366 * (1) maybe utilize power down mode.
367 * Why not yet? Because while the chip will go into power down mode,
368 * the manual says that it will wake up in response to any I/O requests
369 * in the register space. Empirical results do not show this working.
370 */
371 static void smc_shutdown ()
372 {
373 PRINTK2 (CARDNAME ":smc_shutdown\n");
374
375 /* no more interrupts for me */
376 SMC_SELECT_BANK (2);
377 SMC_outb (0, LAN91C96_INT_MASK);
378
379 /* and tell the card to stay away from that nasty outside world */
380 SMC_SELECT_BANK (0);
381 SMC_outb (0, LAN91C96_RCR);
382 SMC_outb (0, LAN91C96_TCR);
383 }
384
385
386 /*
387 * Function: smc_hardware_send_packet(struct net_device * )
388 * Purpose:
389 * This sends the actual packet to the SMC9xxx chip.
390 *
391 * Algorithm:
392 * First, see if a saved_skb is available.
393 * ( this should NOT be called if there is no 'saved_skb'
394 * Now, find the packet number that the chip allocated
395 * Point the data pointers at it in memory
396 * Set the length word in the chip's memory
397 * Dump the packet to chip memory
398 * Check if a last byte is needed ( odd length packet )
399 * if so, set the control flag right
400 * Tell the card to send it
401 * Enable the transmit interrupt, so I know if it failed
402 * Free the kernel data if I actually sent it.
403 */
404 static int smc_send_packet (volatile void *packet, int packet_length)
405 {
406 byte packet_no;
407 unsigned long ioaddr;
408 byte *buf;
409 int length;
410 int numPages;
411 int try = 0;
412 int time_out;
413 byte status;
414
415
416 PRINTK3 ("%s:smc_hardware_send_packet\n", SMC_DEV_NAME);
417
418 length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN;
419
420 /* allocate memory
421 ** The MMU wants the number of pages to be the number of 256 bytes
422 ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
423 **
424 ** The 91C111 ignores the size bits, but the code is left intact
425 ** for backwards and future compatibility.
426 **
427 ** Pkt size for allocating is data length +6 (for additional status
428 ** words, length and ctl!)
429 **
430 ** If odd size then last byte is included in this header.
431 */
432 numPages = ((length & 0xfffe) + 6);
433 numPages >>= 8; /* Divide by 256 */
434
435 if (numPages > 7) {
436 printf ("%s: Far too big packet error. \n", SMC_DEV_NAME);
437 return 0;
438 }
439
440 /* now, try to allocate the memory */
441
442 SMC_SELECT_BANK (2);
443 SMC_outw (LAN91C96_MMUCR_ALLOC_TX | numPages, LAN91C96_MMU);
444
445 again:
446 try++;
447 time_out = MEMORY_WAIT_TIME;
448 do {
449 status = SMC_inb (LAN91C96_INT_STATS);
450 if (status & LAN91C96_IST_ALLOC_INT) {
451
452 SMC_outb (LAN91C96_IST_ALLOC_INT, LAN91C96_INT_STATS);
453 break;
454 }
455 } while (--time_out);
456
457 if (!time_out) {
458 PRINTK2 ("%s: memory allocation, try %d failed ...\n",
459 SMC_DEV_NAME, try);
460 if (try < SMC_ALLOC_MAX_TRY)
461 goto again;
462 else
463 return 0;
464 }
465
466 PRINTK2 ("%s: memory allocation, try %d succeeded ...\n",
467 SMC_DEV_NAME, try);
468
469 /* I can send the packet now.. */
470
471 ioaddr = SMC_BASE_ADDRESS;
472
473 buf = (byte *) packet;
474
475 /* If I get here, I _know_ there is a packet slot waiting for me */
476 packet_no = SMC_inb (LAN91C96_ARR);
477 if (packet_no & LAN91C96_ARR_FAILED) {
478 /* or isn't there? BAD CHIP! */
479 printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME);
480 return 0;
481 }
482
483 /* we have a packet address, so tell the card to use it */
484 SMC_outb (packet_no, LAN91C96_PNR);
485
486 /* point to the beginning of the packet */
487 SMC_outw (LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);
488
489 PRINTK3 ("%s: Trying to xmit packet of length %x\n",
490 SMC_DEV_NAME, length);
491
492 #if SMC_DEBUG > 2
493 printf ("Transmitting Packet\n");
494 print_packet (buf, length);
495 #endif
496
497 /* send the packet length ( +6 for status, length and ctl byte )
498 and the status word ( set to zeros ) */
499 #ifdef USE_32_BIT
500 SMC_outl ((length + 6) << 16, LAN91C96_DATA_HIGH);
501 #else
502 SMC_outw (0, LAN91C96_DATA_HIGH);
503 /* send the packet length ( +6 for status words, length, and ctl */
504 SMC_outw ((length + 6), LAN91C96_DATA_HIGH);
505 #endif /* USE_32_BIT */
506
507 /* send the actual data
508 * I _think_ it's faster to send the longs first, and then
509 * mop up by sending the last word. It depends heavily
510 * on alignment, at least on the 486. Maybe it would be
511 * a good idea to check which is optimal? But that could take
512 * almost as much time as is saved?
513 */
514 #ifdef USE_32_BIT
515 SMC_outsl (LAN91C96_DATA_HIGH, buf, length >> 2);
516 if (length & 0x2)
517 SMC_outw (*((word *) (buf + (length & 0xFFFFFFFC))),
518 LAN91C96_DATA_HIGH);
519 #else
520 SMC_outsw (LAN91C96_DATA_HIGH, buf, (length) >> 1);
521 #endif /* USE_32_BIT */
522
523 /* Send the last byte, if there is one. */
524 if ((length & 1) == 0) {
525 SMC_outw (0, LAN91C96_DATA_HIGH);
526 } else {
527 SMC_outw (buf[length - 1] | 0x2000, LAN91C96_DATA_HIGH);
528 }
529
530 /* and let the chipset deal with it */
531 SMC_outw (LAN91C96_MMUCR_ENQUEUE, LAN91C96_MMU);
532
533 /* poll for TX INT */
534 if (poll4int (LAN91C96_MSK_TX_INT, SMC_TX_TIMEOUT)) {
535 /* sending failed */
536 PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME);
537
538 /* release packet */
539 SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);
540
541 /* wait for MMU getting ready (low) */
542 while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) {
543 udelay (10);
544 }
545
546 PRINTK2 ("MMU ready\n");
547
548
549 return 0;
550 } else {
551 /* ack. int */
552 SMC_outw (LAN91C96_IST_TX_INT, LAN91C96_INT_STATS);
553
554 PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME, length);
555
556 /* release packet */
557 SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);
558
559 /* wait for MMU getting ready (low) */
560 while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) {
561 udelay (10);
562 }
563
564 PRINTK2 ("MMU ready\n");
565 }
566
567 return length;
568 }
569
570 /*-------------------------------------------------------------------------
571 * smc_destructor( struct net_device * dev )
572 * Input parameters:
573 * dev, pointer to the device structure
574 *
575 * Output:
576 * None.
577 *--------------------------------------------------------------------------
578 */
579 void smc_destructor ()
580 {
581 PRINTK2 (CARDNAME ":smc_destructor\n");
582 }
583
584
585 /*
586 * Open and Initialize the board
587 *
588 * Set up everything, reset the card, etc ..
589 *
590 */
591 static int smc_open ()
592 {
593 int i; /* used to set hw ethernet address */
594
595 PRINTK2 ("%s:smc_open\n", SMC_DEV_NAME);
596
597 /* reset the hardware */
598
599 smc_reset ();
600 smc_enable ();
601
602 SMC_SELECT_BANK (1);
603
604 for (i = 0; i < 6; i += 2) {
605 word address;
606
607 address = smc_mac_addr[i + 1] << 8;
608 address |= smc_mac_addr[i];
609 SMC_outw (address, LAN91C96_IA0 + i);
610 }
611 return 0;
612 }
613
614 /*-------------------------------------------------------------
615 *
616 * smc_rcv - receive a packet from the card
617 *
618 * There is ( at least ) a packet waiting to be read from
619 * chip-memory.
620 *
621 * o Read the status
622 * o If an error, record it
623 * o otherwise, read in the packet
624 *-------------------------------------------------------------
625 */
626 static int smc_rcv ()
627 {
628 int packet_number;
629 word status;
630 word packet_length;
631 int is_error = 0;
632
633 #ifdef USE_32_BIT
634 dword stat_len;
635 #endif
636
637
638 SMC_SELECT_BANK (2);
639 packet_number = SMC_inw (LAN91C96_FIFO);
640
641 if (packet_number & LAN91C96_FIFO_RXEMPTY) {
642 return 0;
643 }
644
645 PRINTK3 ("%s:smc_rcv\n", SMC_DEV_NAME);
646 /* start reading from the start of the packet */
647 SMC_outw (LAN91C96_PTR_READ | LAN91C96_PTR_RCV |
648 LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);
649
650 /* First two words are status and packet_length */
651 #ifdef USE_32_BIT
652 stat_len = SMC_inl (LAN91C96_DATA_HIGH);
653 status = stat_len & 0xffff;
654 packet_length = stat_len >> 16;
655 #else
656 status = SMC_inw (LAN91C96_DATA_HIGH);
657 packet_length = SMC_inw (LAN91C96_DATA_HIGH);
658 #endif
659
660 packet_length &= 0x07ff; /* mask off top bits */
661
662 PRINTK2 ("RCV: STATUS %4x LENGTH %4x\n", status, packet_length);
663
664 if (!(status & FRAME_FILTER)) {
665 /* Adjust for having already read the first two words */
666 packet_length -= 4; /*4; */
667
668
669 /* set odd length for bug in LAN91C111, */
670 /* which never sets RS_ODDFRAME */
671 /* TODO ? */
672
673
674 #ifdef USE_32_BIT
675 PRINTK3 (" Reading %d dwords (and %d bytes) \n",
676 packet_length >> 2, packet_length & 3);
677 /* QUESTION: Like in the TX routine, do I want
678 to send the DWORDs or the bytes first, or some
679 mixture. A mixture might improve already slow PIO
680 performance */
681 SMC_insl (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 2);
682 /* read the left over bytes */
683 if (packet_length & 3) {
684 int i;
685
686 byte *tail = (byte *) (NetRxPackets[0] + (packet_length & ~3));
687 dword leftover = SMC_inl (LAN91C96_DATA_HIGH);
688
689 for (i = 0; i < (packet_length & 3); i++)
690 *tail++ = (byte) (leftover >> (8 * i)) & 0xff;
691 }
692 #else
693 PRINTK3 (" Reading %d words and %d byte(s) \n",
694 (packet_length >> 1), packet_length & 1);
695 SMC_insw (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 1);
696
697 #endif /* USE_32_BIT */
698
699 #if SMC_DEBUG > 2
700 printf ("Receiving Packet\n");
701 print_packet (NetRxPackets[0], packet_length);
702 #endif
703 } else {
704 /* error ... */
705 /* TODO ? */
706 is_error = 1;
707 }
708
709 while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
710 udelay (1); /* Wait until not busy */
711
712 /* error or good, tell the card to get rid of this packet */
713 SMC_outw (LAN91C96_MMUCR_RELEASE_RX, LAN91C96_MMU);
714
715 while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
716 udelay (1); /* Wait until not busy */
717
718 if (!is_error) {
719 /* Pass the packet up to the protocol layers. */
720 NetReceive (NetRxPackets[0], packet_length);
721 return packet_length;
722 } else {
723 return 0;
724 }
725
726 }
727
728 /*----------------------------------------------------
729 * smc_close
730 *
731 * this makes the board clean up everything that it can
732 * and not talk to the outside world. Caused by
733 * an 'ifconfig ethX down'
734 *
735 -----------------------------------------------------*/
736 static int smc_close ()
737 {
738 PRINTK2 ("%s:smc_close\n", SMC_DEV_NAME);
739
740 /* clear everything */
741 smc_shutdown ();
742
743 return 0;
744 }
745
746 #if SMC_DEBUG > 2
747 static void print_packet (byte * buf, int length)
748 {
749 #if 0
750 int i;
751 int remainder;
752 int lines;
753
754 printf ("Packet of length %d \n", length);
755
756 lines = length / 16;
757 remainder = length % 16;
758
759 for (i = 0; i < lines; i++) {
760 int cur;
761
762 for (cur = 0; cur < 8; cur++) {
763 byte a, b;
764
765 a = *(buf++);
766 b = *(buf++);
767 printf ("%02x%02x ", a, b);
768 }
769 printf ("\n");
770 }
771 for (i = 0; i < remainder / 2; i++) {
772 byte a, b;
773
774 a = *(buf++);
775 b = *(buf++);
776 printf ("%02x%02x ", a, b);
777 }
778 printf ("\n");
779 #endif /* 0 */
780 }
781 #endif /* SMC_DEBUG > 2 */
782
783 int eth_init (bd_t * bd)
784 {
785 smc_open ();
786 return 0;
787 }
788
789 void eth_halt ()
790 {
791 smc_close ();
792 }
793
794 int eth_rx ()
795 {
796 return smc_rcv ();
797 }
798
799 int eth_send (volatile void *packet, int length)
800 {
801 return smc_send_packet (packet, length);
802 }
803
804 int eth_hw_init ()
805 {
806 return smc_hw_init ();
807 }
808
809 /*-------------------------------------------------------------------------
810 * smc_hw_init()
811 *
812 * Function:
813 * Reset and enable the device, check if the I/O space location
814 * is correct
815 *
816 * Input parameters:
817 * None
818 *
819 * Output:
820 * 0 --> success
821 * 1 --> error
822 *--------------------------------------------------------------------------
823 */
824 static int smc_hw_init ()
825 {
826 unsigned short status_test;
827
828 /* The attribute register of the LAN91C96 is located at address
829 0x0e000000 on the lubbock platform */
830 volatile unsigned *attaddr = (unsigned *) (0x0e000000);
831
832 /* first reset, then enable the device. Sequence is critical */
833 attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_SRESET;
834 udelay (100);
835 attaddr[LAN91C96_ECOR] &= ~LAN91C96_ECOR_SRESET;
836 attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_ENABLE;
837
838 /* force 16-bit mode */
839 attaddr[LAN91C96_ECSR] &= ~LAN91C96_ECSR_IOIS8;
840 udelay (100);
841
842 /* check if the I/O address is correct, the upper byte of the
843 bank select register should read 0x33 */
844
845 status_test = SMC_inw (LAN91C96_BANK_SELECT);
846 if ((status_test & 0xFF00) != 0x3300) {
847 printf ("Failed to initialize ethernetchip\n");
848 return 1;
849 }
850 return 0;
851 }
852
853 #endif /* COMMANDS & CFG_NET */
854
855 #endif /* CONFIG_DRIVER_LAN91C96 */