blob: ecdcbd9b32b10c27aba0281c7cfa43d8f4cff487 [file] [log] [blame]
wdenk45219c42003-05-12 21:50:16 +00001/*------------------------------------------------------------------------
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
Jon Loeliger07d38a12007-07-09 17:30:01 -050068#if defined(CONFIG_CMD_NET)
wdenk45219c42003-05-12 21:50:16 +000069
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
138extern int eth_init (bd_t * bd);
139extern void eth_halt (void);
140extern int eth_rx (void);
141extern int eth_send (volatile void *packet, int length);
wdenk39539882004-07-01 16:30:44 +0000142#if 0
wdenk45219c42003-05-12 21:50:16 +0000143static int smc_hw_init (void);
wdenk39539882004-07-01 16:30:44 +0000144#endif
wdenk45219c42003-05-12 21:50:16 +0000145
146/*
147 * This is called by register_netdev(). It is responsible for
148 * checking the portlist for the SMC9000 series chipset. If it finds
149 * one, then it will initialize the device, find the hardware information,
150 * and sets up the appropriate device parameters.
151 * NOTE: Interrupts are *OFF* when this procedure is called.
152 *
153 * NB:This shouldn't be static since it is referred to externally.
154 */
155int smc_init (void);
156
157/*
158 * This is called by unregister_netdev(). It is responsible for
159 * cleaning up before the driver is finally unregistered and discarded.
160 */
161void smc_destructor (void);
162
163/*
164 * The kernel calls this function when someone wants to use the device,
165 * typically 'ifconfig ethX up'.
166 */
wdenk5ca26792004-06-06 22:11:41 +0000167static int smc_open (bd_t *bd);
wdenk45219c42003-05-12 21:50:16 +0000168
169
170/*
171 * This is called by the kernel in response to 'ifconfig ethX down'. It
172 * is responsible for cleaning up everything that the open routine
173 * does, and maybe putting the card into a powerdown state.
174 */
175static int smc_close (void);
176
177/*
178 * This is a separate procedure to handle the receipt of a packet, to
179 * leave the interrupt code looking slightly cleaner
180 */
181static int smc_rcv (void);
182
wdenk5ca26792004-06-06 22:11:41 +0000183/* See if a MAC address is defined in the current environment. If so use it. If not
184 . print a warning and set the environment and other globals with the default.
185 . If an EEPROM is present it really should be consulted.
186*/
187int smc_get_ethaddr(bd_t *bd);
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100188int get_rom_mac(unsigned char *v_rom_mac);
wdenk45219c42003-05-12 21:50:16 +0000189
wdenk45219c42003-05-12 21:50:16 +0000190/* ------------------------------------------------------------
191 * Internal routines
192 * ------------------------------------------------------------
193 */
194
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100195static unsigned char smc_mac_addr[] = { 0xc0, 0x00, 0x00, 0x1b, 0x62, 0x9c };
wdenk45219c42003-05-12 21:50:16 +0000196
197/*
198 * This function must be called before smc_open() if you want to override
199 * the default mac address.
200 */
201
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100202void smc_set_mac_addr (const unsigned char *addr)
wdenk45219c42003-05-12 21:50:16 +0000203{
204 int i;
205
206 for (i = 0; i < sizeof (smc_mac_addr); i++) {
207 smc_mac_addr[i] = addr[i];
208 }
209}
210
211/*
212 * smc_get_macaddr is no longer used. If you want to override the default
213 * mac address, call smc_get_mac_addr as a part of the board initialisation.
214 */
215
216#if 0
217void smc_get_macaddr (byte * addr)
218{
219 /* MAC ADDRESS AT FLASHBLOCK 1 / OFFSET 0x10 */
220 unsigned char *dnp1110_mac = (unsigned char *) (0xE8000000 + 0x20010);
221 int i;
222
223
224 for (i = 0; i < 6; i++) {
225 addr[0] = *(dnp1110_mac + 0);
226 addr[1] = *(dnp1110_mac + 1);
227 addr[2] = *(dnp1110_mac + 2);
228 addr[3] = *(dnp1110_mac + 3);
229 addr[4] = *(dnp1110_mac + 4);
230 addr[5] = *(dnp1110_mac + 5);
231 }
232}
233#endif /* 0 */
234
235/***********************************************
236 * Show available memory *
237 ***********************************************/
238void dump_memory_info (void)
239{
240 word mem_info;
241 word old_bank;
242
243 old_bank = SMC_inw (LAN91C96_BANK_SELECT) & 0xF;
244
245 SMC_SELECT_BANK (0);
246 mem_info = SMC_inw (LAN91C96_MIR);
247 PRINTK2 ("Memory: %4d available\n", (mem_info >> 8) * 2048);
248
249 SMC_SELECT_BANK (old_bank);
250}
251
252/*
253 * A rather simple routine to print out a packet for debugging purposes.
254 */
255#if SMC_DEBUG > 2
256static void print_packet (byte *, int);
257#endif
258
259/* #define tx_done(dev) 1 */
260
261
wdenk45219c42003-05-12 21:50:16 +0000262/* this does a soft reset on the device */
263static void smc_reset (void);
264
265/* Enable Interrupts, Receive, and Transmit */
266static void smc_enable (void);
267
268/* this puts the device in an inactive state */
269static void smc_shutdown (void);
270
271
272static int poll4int (byte mask, int timeout)
273{
274 int tmo = get_timer (0) + timeout * CFG_HZ;
275 int is_timeout = 0;
276 word old_bank = SMC_inw (LAN91C96_BANK_SELECT);
277
278 PRINTK2 ("Polling...\n");
279 SMC_SELECT_BANK (2);
280 while ((SMC_inw (LAN91C96_INT_STATS) & mask) == 0) {
281 if (get_timer (0) >= tmo) {
282 is_timeout = 1;
283 break;
284 }
285 }
286
287 /* restore old bank selection */
288 SMC_SELECT_BANK (old_bank);
289
290 if (is_timeout)
291 return 1;
292 else
293 return 0;
294}
295
296/*
297 * Function: smc_reset( void )
298 * Purpose:
299 * This sets the SMC91111 chip to its normal state, hopefully from whatever
300 * mess that any other DOS driver has put it in.
301 *
302 * Maybe I should reset more registers to defaults in here? SOFTRST should
303 * do that for me.
304 *
305 * Method:
306 * 1. send a SOFT RESET
307 * 2. wait for it to finish
308 * 3. enable autorelease mode
309 * 4. reset the memory management unit
310 * 5. clear all interrupts
311 *
312*/
313static void smc_reset (void)
314{
315 PRINTK2 ("%s:smc_reset\n", SMC_DEV_NAME);
316
317 /* This resets the registers mostly to defaults, but doesn't
318 affect EEPROM. That seems unnecessary */
319 SMC_SELECT_BANK (0);
320 SMC_outw (LAN91C96_RCR_SOFT_RST, LAN91C96_RCR);
321
322 udelay (10);
323
324 /* Disable transmit and receive functionality */
325 SMC_outw (0, LAN91C96_RCR);
326 SMC_outw (0, LAN91C96_TCR);
327
328 /* set the control register */
329 SMC_SELECT_BANK (1);
330 SMC_outw (SMC_inw (LAN91C96_CONTROL) | LAN91C96_CTR_BIT_8,
331 LAN91C96_CONTROL);
332
333 /* Disable all interrupts */
334 SMC_outb (0, LAN91C96_INT_MASK);
335}
336
337/*
338 * Function: smc_enable
339 * Purpose: let the chip talk to the outside work
340 * Method:
341 * 1. Initialize the Memory Configuration Register
342 * 2. Enable the transmitter
343 * 3. Enable the receiver
344*/
345static void smc_enable ()
346{
347 PRINTK2 ("%s:smc_enable\n", SMC_DEV_NAME);
348 SMC_SELECT_BANK (0);
349
350 /* Initialize the Memory Configuration Register. See page
351 49 of the LAN91C96 data sheet for details. */
352 SMC_outw (LAN91C96_MCR_TRANSMIT_PAGES, LAN91C96_MCR);
353
354 /* Initialize the Transmit Control Register */
355 SMC_outw (LAN91C96_TCR_TXENA, LAN91C96_TCR);
356 /* Initialize the Receive Control Register
357 * FIXME:
358 * The promiscuous bit set because I could not receive ARP reply
359 * packets from the server when I send a ARP request. It only works
360 * when I set the promiscuous bit
361 */
362 SMC_outw (LAN91C96_RCR_RXEN | LAN91C96_RCR_PRMS, LAN91C96_RCR);
363}
364
365/*
366 * Function: smc_shutdown
367 * Purpose: closes down the SMC91xxx chip.
368 * Method:
369 * 1. zero the interrupt mask
370 * 2. clear the enable receive flag
371 * 3. clear the enable xmit flags
372 *
373 * TODO:
374 * (1) maybe utilize power down mode.
375 * Why not yet? Because while the chip will go into power down mode,
376 * the manual says that it will wake up in response to any I/O requests
377 * in the register space. Empirical results do not show this working.
378 */
379static void smc_shutdown ()
380{
381 PRINTK2 (CARDNAME ":smc_shutdown\n");
382
383 /* no more interrupts for me */
384 SMC_SELECT_BANK (2);
385 SMC_outb (0, LAN91C96_INT_MASK);
386
387 /* and tell the card to stay away from that nasty outside world */
388 SMC_SELECT_BANK (0);
389 SMC_outb (0, LAN91C96_RCR);
390 SMC_outb (0, LAN91C96_TCR);
391}
392
393
394/*
395 * Function: smc_hardware_send_packet(struct net_device * )
396 * Purpose:
397 * This sends the actual packet to the SMC9xxx chip.
398 *
399 * Algorithm:
400 * First, see if a saved_skb is available.
401 * ( this should NOT be called if there is no 'saved_skb'
402 * Now, find the packet number that the chip allocated
403 * Point the data pointers at it in memory
404 * Set the length word in the chip's memory
405 * Dump the packet to chip memory
406 * Check if a last byte is needed ( odd length packet )
407 * if so, set the control flag right
408 * Tell the card to send it
409 * Enable the transmit interrupt, so I know if it failed
410 * Free the kernel data if I actually sent it.
411 */
412static int smc_send_packet (volatile void *packet, int packet_length)
413{
414 byte packet_no;
415 unsigned long ioaddr;
416 byte *buf;
417 int length;
418 int numPages;
419 int try = 0;
420 int time_out;
421 byte status;
422
423
424 PRINTK3 ("%s:smc_hardware_send_packet\n", SMC_DEV_NAME);
425
426 length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN;
427
428 /* allocate memory
429 ** The MMU wants the number of pages to be the number of 256 bytes
430 ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
431 **
432 ** The 91C111 ignores the size bits, but the code is left intact
433 ** for backwards and future compatibility.
434 **
435 ** Pkt size for allocating is data length +6 (for additional status
436 ** words, length and ctl!)
437 **
438 ** If odd size then last byte is included in this header.
439 */
440 numPages = ((length & 0xfffe) + 6);
441 numPages >>= 8; /* Divide by 256 */
442
443 if (numPages > 7) {
444 printf ("%s: Far too big packet error. \n", SMC_DEV_NAME);
445 return 0;
446 }
447
448 /* now, try to allocate the memory */
449
450 SMC_SELECT_BANK (2);
451 SMC_outw (LAN91C96_MMUCR_ALLOC_TX | numPages, LAN91C96_MMU);
452
453 again:
454 try++;
455 time_out = MEMORY_WAIT_TIME;
456 do {
457 status = SMC_inb (LAN91C96_INT_STATS);
458 if (status & LAN91C96_IST_ALLOC_INT) {
459
460 SMC_outb (LAN91C96_IST_ALLOC_INT, LAN91C96_INT_STATS);
461 break;
462 }
463 } while (--time_out);
464
465 if (!time_out) {
466 PRINTK2 ("%s: memory allocation, try %d failed ...\n",
467 SMC_DEV_NAME, try);
468 if (try < SMC_ALLOC_MAX_TRY)
469 goto again;
470 else
471 return 0;
472 }
473
474 PRINTK2 ("%s: memory allocation, try %d succeeded ...\n",
475 SMC_DEV_NAME, try);
476
477 /* I can send the packet now.. */
478
479 ioaddr = SMC_BASE_ADDRESS;
480
481 buf = (byte *) packet;
482
483 /* If I get here, I _know_ there is a packet slot waiting for me */
484 packet_no = SMC_inb (LAN91C96_ARR);
485 if (packet_no & LAN91C96_ARR_FAILED) {
486 /* or isn't there? BAD CHIP! */
487 printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME);
488 return 0;
489 }
490
491 /* we have a packet address, so tell the card to use it */
492 SMC_outb (packet_no, LAN91C96_PNR);
493
494 /* point to the beginning of the packet */
495 SMC_outw (LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);
496
497 PRINTK3 ("%s: Trying to xmit packet of length %x\n",
498 SMC_DEV_NAME, length);
499
500#if SMC_DEBUG > 2
501 printf ("Transmitting Packet\n");
502 print_packet (buf, length);
503#endif
504
505 /* send the packet length ( +6 for status, length and ctl byte )
506 and the status word ( set to zeros ) */
507#ifdef USE_32_BIT
508 SMC_outl ((length + 6) << 16, LAN91C96_DATA_HIGH);
509#else
510 SMC_outw (0, LAN91C96_DATA_HIGH);
511 /* send the packet length ( +6 for status words, length, and ctl */
512 SMC_outw ((length + 6), LAN91C96_DATA_HIGH);
513#endif /* USE_32_BIT */
514
515 /* send the actual data
516 * I _think_ it's faster to send the longs first, and then
517 * mop up by sending the last word. It depends heavily
518 * on alignment, at least on the 486. Maybe it would be
519 * a good idea to check which is optimal? But that could take
520 * almost as much time as is saved?
521 */
522#ifdef USE_32_BIT
523 SMC_outsl (LAN91C96_DATA_HIGH, buf, length >> 2);
524 if (length & 0x2)
525 SMC_outw (*((word *) (buf + (length & 0xFFFFFFFC))),
526 LAN91C96_DATA_HIGH);
527#else
528 SMC_outsw (LAN91C96_DATA_HIGH, buf, (length) >> 1);
529#endif /* USE_32_BIT */
530
531 /* Send the last byte, if there is one. */
532 if ((length & 1) == 0) {
533 SMC_outw (0, LAN91C96_DATA_HIGH);
534 } else {
535 SMC_outw (buf[length - 1] | 0x2000, LAN91C96_DATA_HIGH);
536 }
537
538 /* and let the chipset deal with it */
539 SMC_outw (LAN91C96_MMUCR_ENQUEUE, LAN91C96_MMU);
540
541 /* poll for TX INT */
542 if (poll4int (LAN91C96_MSK_TX_INT, SMC_TX_TIMEOUT)) {
543 /* sending failed */
544 PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME);
545
546 /* release packet */
547 SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);
548
549 /* wait for MMU getting ready (low) */
550 while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) {
551 udelay (10);
552 }
553
554 PRINTK2 ("MMU ready\n");
555
556
557 return 0;
558 } else {
559 /* ack. int */
560 SMC_outw (LAN91C96_IST_TX_INT, LAN91C96_INT_STATS);
561
562 PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME, length);
563
564 /* release packet */
565 SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);
566
567 /* wait for MMU getting ready (low) */
568 while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) {
569 udelay (10);
570 }
571
572 PRINTK2 ("MMU ready\n");
573 }
574
575 return length;
576}
577
578/*-------------------------------------------------------------------------
579 * smc_destructor( struct net_device * dev )
580 * Input parameters:
581 * dev, pointer to the device structure
582 *
583 * Output:
584 * None.
585 *--------------------------------------------------------------------------
586 */
587void smc_destructor ()
588{
589 PRINTK2 (CARDNAME ":smc_destructor\n");
590}
591
592
593/*
594 * Open and Initialize the board
595 *
596 * Set up everything, reset the card, etc ..
597 *
598 */
wdenk5ca26792004-06-06 22:11:41 +0000599static int smc_open (bd_t *bd)
wdenk45219c42003-05-12 21:50:16 +0000600{
wdenk5ca26792004-06-06 22:11:41 +0000601 int i, err; /* used to set hw ethernet address */
wdenk45219c42003-05-12 21:50:16 +0000602
603 PRINTK2 ("%s:smc_open\n", SMC_DEV_NAME);
604
605 /* reset the hardware */
606
607 smc_reset ();
608 smc_enable ();
609
610 SMC_SELECT_BANK (1);
611
wdenk5ca26792004-06-06 22:11:41 +0000612 err = smc_get_ethaddr (bd); /* set smc_mac_addr, and sync it with u-boot globals */
613 if (err < 0) {
614 memset (bd->bi_enetaddr, 0, 6); /* hack to make error stick! upper code will abort if not set */
615 return (-1); /* upper code ignores this, but NOT bi_enetaddr */
616 }
617#ifdef USE_32_BIT
wdenk45219c42003-05-12 21:50:16 +0000618 for (i = 0; i < 6; i += 2) {
619 word address;
620
621 address = smc_mac_addr[i + 1] << 8;
622 address |= smc_mac_addr[i];
623 SMC_outw (address, LAN91C96_IA0 + i);
624 }
wdenka56bd922004-06-06 23:13:55 +0000625#else
wdenk5ca26792004-06-06 22:11:41 +0000626 for (i = 0; i < 6; i++)
627 SMC_outb (smc_mac_addr[i], LAN91C96_IA0 + i);
628#endif
wdenk45219c42003-05-12 21:50:16 +0000629 return 0;
630}
631
632/*-------------------------------------------------------------
633 *
634 * smc_rcv - receive a packet from the card
635 *
636 * There is ( at least ) a packet waiting to be read from
637 * chip-memory.
638 *
639 * o Read the status
640 * o If an error, record it
641 * o otherwise, read in the packet
642 *-------------------------------------------------------------
643 */
644static int smc_rcv ()
645{
646 int packet_number;
647 word status;
648 word packet_length;
649 int is_error = 0;
650
651#ifdef USE_32_BIT
652 dword stat_len;
653#endif
654
655
656 SMC_SELECT_BANK (2);
657 packet_number = SMC_inw (LAN91C96_FIFO);
658
659 if (packet_number & LAN91C96_FIFO_RXEMPTY) {
660 return 0;
661 }
662
663 PRINTK3 ("%s:smc_rcv\n", SMC_DEV_NAME);
664 /* start reading from the start of the packet */
665 SMC_outw (LAN91C96_PTR_READ | LAN91C96_PTR_RCV |
666 LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);
667
668 /* First two words are status and packet_length */
669#ifdef USE_32_BIT
670 stat_len = SMC_inl (LAN91C96_DATA_HIGH);
671 status = stat_len & 0xffff;
672 packet_length = stat_len >> 16;
673#else
674 status = SMC_inw (LAN91C96_DATA_HIGH);
675 packet_length = SMC_inw (LAN91C96_DATA_HIGH);
676#endif
677
678 packet_length &= 0x07ff; /* mask off top bits */
679
680 PRINTK2 ("RCV: STATUS %4x LENGTH %4x\n", status, packet_length);
681
682 if (!(status & FRAME_FILTER)) {
683 /* Adjust for having already read the first two words */
684 packet_length -= 4; /*4; */
685
686
wdenk45219c42003-05-12 21:50:16 +0000687 /* set odd length for bug in LAN91C111, */
688 /* which never sets RS_ODDFRAME */
689 /* TODO ? */
690
691
692#ifdef USE_32_BIT
693 PRINTK3 (" Reading %d dwords (and %d bytes) \n",
694 packet_length >> 2, packet_length & 3);
695 /* QUESTION: Like in the TX routine, do I want
696 to send the DWORDs or the bytes first, or some
697 mixture. A mixture might improve already slow PIO
698 performance */
699 SMC_insl (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 2);
700 /* read the left over bytes */
701 if (packet_length & 3) {
702 int i;
703
704 byte *tail = (byte *) (NetRxPackets[0] + (packet_length & ~3));
705 dword leftover = SMC_inl (LAN91C96_DATA_HIGH);
706
707 for (i = 0; i < (packet_length & 3); i++)
708 *tail++ = (byte) (leftover >> (8 * i)) & 0xff;
709 }
710#else
711 PRINTK3 (" Reading %d words and %d byte(s) \n",
712 (packet_length >> 1), packet_length & 1);
713 SMC_insw (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 1);
714
715#endif /* USE_32_BIT */
716
717#if SMC_DEBUG > 2
718 printf ("Receiving Packet\n");
719 print_packet (NetRxPackets[0], packet_length);
720#endif
721 } else {
722 /* error ... */
723 /* TODO ? */
724 is_error = 1;
725 }
726
727 while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
728 udelay (1); /* Wait until not busy */
729
730 /* error or good, tell the card to get rid of this packet */
731 SMC_outw (LAN91C96_MMUCR_RELEASE_RX, LAN91C96_MMU);
732
733 while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
734 udelay (1); /* Wait until not busy */
735
736 if (!is_error) {
737 /* Pass the packet up to the protocol layers. */
738 NetReceive (NetRxPackets[0], packet_length);
739 return packet_length;
740 } else {
741 return 0;
742 }
743
744}
745
746/*----------------------------------------------------
747 * smc_close
748 *
749 * this makes the board clean up everything that it can
750 * and not talk to the outside world. Caused by
751 * an 'ifconfig ethX down'
752 *
753 -----------------------------------------------------*/
754static int smc_close ()
755{
756 PRINTK2 ("%s:smc_close\n", SMC_DEV_NAME);
757
758 /* clear everything */
759 smc_shutdown ();
760
761 return 0;
762}
763
764#if SMC_DEBUG > 2
765static void print_packet (byte * buf, int length)
766{
767#if 0
768 int i;
769 int remainder;
770 int lines;
771
772 printf ("Packet of length %d \n", length);
773
774 lines = length / 16;
775 remainder = length % 16;
776
777 for (i = 0; i < lines; i++) {
778 int cur;
779
780 for (cur = 0; cur < 8; cur++) {
781 byte a, b;
782
783 a = *(buf++);
784 b = *(buf++);
785 printf ("%02x%02x ", a, b);
786 }
787 printf ("\n");
788 }
789 for (i = 0; i < remainder / 2; i++) {
790 byte a, b;
791
792 a = *(buf++);
793 b = *(buf++);
794 printf ("%02x%02x ", a, b);
795 }
796 printf ("\n");
797#endif /* 0 */
798}
799#endif /* SMC_DEBUG > 2 */
800
801int eth_init (bd_t * bd)
802{
wdenk5ca26792004-06-06 22:11:41 +0000803 return (smc_open(bd));
wdenk45219c42003-05-12 21:50:16 +0000804}
805
806void eth_halt ()
807{
808 smc_close ();
809}
810
811int eth_rx ()
812{
813 return smc_rcv ();
814}
815
816int eth_send (volatile void *packet, int length)
817{
818 return smc_send_packet (packet, length);
819}
820
wdenk45219c42003-05-12 21:50:16 +0000821
wdenk39539882004-07-01 16:30:44 +0000822#if 0
wdenk45219c42003-05-12 21:50:16 +0000823/*-------------------------------------------------------------------------
824 * smc_hw_init()
825 *
826 * Function:
827 * Reset and enable the device, check if the I/O space location
828 * is correct
829 *
830 * Input parameters:
831 * None
832 *
833 * Output:
834 * 0 --> success
835 * 1 --> error
836 *--------------------------------------------------------------------------
837 */
838static int smc_hw_init ()
839{
840 unsigned short status_test;
841
842 /* The attribute register of the LAN91C96 is located at address
843 0x0e000000 on the lubbock platform */
844 volatile unsigned *attaddr = (unsigned *) (0x0e000000);
845
846 /* first reset, then enable the device. Sequence is critical */
847 attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_SRESET;
848 udelay (100);
849 attaddr[LAN91C96_ECOR] &= ~LAN91C96_ECOR_SRESET;
850 attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_ENABLE;
851
852 /* force 16-bit mode */
853 attaddr[LAN91C96_ECSR] &= ~LAN91C96_ECSR_IOIS8;
854 udelay (100);
855
856 /* check if the I/O address is correct, the upper byte of the
857 bank select register should read 0x33 */
858
859 status_test = SMC_inw (LAN91C96_BANK_SELECT);
860 if ((status_test & 0xFF00) != 0x3300) {
861 printf ("Failed to initialize ethernetchip\n");
862 return 1;
863 }
864 return 0;
865}
wdenk39539882004-07-01 16:30:44 +0000866#endif /* 0 */
wdenk45219c42003-05-12 21:50:16 +0000867
868#endif /* COMMANDS & CFG_NET */
869
wdenk5ca26792004-06-06 22:11:41 +0000870
871/* smc_get_ethaddr (bd_t * bd)
872 *
873 * This checks both the environment and the ROM for an ethernet address. If
874 * found, the environment takes precedence.
875 */
876
877int smc_get_ethaddr (bd_t * bd)
878{
879 int env_size = 0;
880 int rom_valid = 0;
881 int env_present = 0;
882 int reg = 0;
883 char *s = NULL;
884 char *e = NULL;
885 char *v_mac, es[] = "11:22:33:44:55:66";
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100886 char s_env_mac[64];
wdenk5ca26792004-06-06 22:11:41 +0000887 uchar v_env_mac[6];
888 uchar v_rom_mac[6];
889
890 env_size = getenv_r ("ethaddr", s_env_mac, sizeof (s_env_mac));
891 if (env_size != sizeof(es)) { /* Ignore if env is bad or not set */
892 printf ("\n*** Warning: ethaddr is not set properly, ignoring!!\n");
893 } else {
894 env_present = 1;
895 s = s_env_mac;
896
897 for (reg = 0; reg < 6; ++reg) { /* turn string into mac value */
898 v_env_mac[reg] = s ? simple_strtoul (s, &e, 16) : 0;
899 if (s)
900 s = (*e) ? e + 1 : e;
901 }
902 }
903
904 rom_valid = get_rom_mac (v_rom_mac); /* get ROM mac value if any */
905
906 if (!env_present) { /* if NO env */
907 if (rom_valid) { /* but ROM is valid */
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100908 v_mac = (char *)v_rom_mac;
wdenk5ca26792004-06-06 22:11:41 +0000909 sprintf (s_env_mac, "%02X:%02X:%02X:%02X:%02X:%02X",
910 v_mac[0], v_mac[1], v_mac[2], v_mac[3],
911 v_mac[4], v_mac[5]);
912 setenv ("ethaddr", s_env_mac);
913 } else { /* no env, bad ROM */
914 printf ("\n*** ERROR: ethaddr is NOT set !!\n");
915 return (-1);
916 }
917 } else { /* good env, don't care ROM */
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100918 v_mac = (char *)v_env_mac; /* always use a good env over a ROM */
wdenk5ca26792004-06-06 22:11:41 +0000919 }
920
921 if (env_present && rom_valid) { /* if both env and ROM are good */
922 if (memcmp (v_env_mac, v_rom_mac, 6) != 0) {
923 printf ("\nWarning: MAC addresses don't match:\n");
924 printf ("\tHW MAC address: "
925 "%02X:%02X:%02X:%02X:%02X:%02X\n",
926 v_rom_mac[0], v_rom_mac[1],
927 v_rom_mac[2], v_rom_mac[3],
928 v_rom_mac[4], v_rom_mac[5] );
929 printf ("\t\"ethaddr\" value: "
930 "%02X:%02X:%02X:%02X:%02X:%02X\n",
931 v_env_mac[0], v_env_mac[1],
932 v_env_mac[2], v_env_mac[3],
933 v_env_mac[4], v_env_mac[5]) ;
934 debug ("### Set MAC addr from environment\n");
935 }
936 }
937 memcpy (bd->bi_enetaddr, v_mac, 6); /* update global address to match env (allows env changing) */
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100938 smc_set_mac_addr ((unsigned char *)v_mac); /* use old function to update smc default */
wdenk5ca26792004-06-06 22:11:41 +0000939 PRINTK("Using MAC Address %02X:%02X:%02X:%02X:%02X:%02X\n", v_mac[0], v_mac[1],
940 v_mac[2], v_mac[3], v_mac[4], v_mac[5]);
941 return (0);
942}
943
wdenka56bd922004-06-06 23:13:55 +0000944/*
wdenk5ca26792004-06-06 22:11:41 +0000945 * get_rom_mac()
946 * Note, this has omly been tested for the OMAP730 P2.
947 */
948
Wolfgang Denkd52fb7e2006-03-11 22:53:33 +0100949int get_rom_mac (unsigned char *v_rom_mac)
wdenk5ca26792004-06-06 22:11:41 +0000950{
951#ifdef HARDCODE_MAC /* used for testing or to supress run time warnings */
952 char hw_mac_addr[] = { 0x02, 0x80, 0xad, 0x20, 0x31, 0xb8 };
953
954 memcpy (v_rom_mac, hw_mac_addr, 6);
955 return (1);
956#else
957 int i;
958 SMC_SELECT_BANK (1);
959 for (i=0; i<6; i++)
960 {
961 v_rom_mac[i] = SMC_inb (LAN91C96_IA0 + i);
962 }
963 return (1);
964#endif
965}
966
wdenk45219c42003-05-12 21:50:16 +0000967#endif /* CONFIG_DRIVER_LAN91C96 */