xref: /openbmc/u-boot/drivers/net/lan91c96.c (revision 83d290c5)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
22439e4bfSJean-Christophe PLAGNIOL-VILLARD /*------------------------------------------------------------------------
32439e4bfSJean-Christophe PLAGNIOL-VILLARD  * lan91c96.c
42439e4bfSJean-Christophe PLAGNIOL-VILLARD  * This is a driver for SMSC's LAN91C96 single-chip Ethernet device, based
5a187559eSBin Meng  * on the SMC91111 driver from U-Boot.
62439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
72439e4bfSJean-Christophe PLAGNIOL-VILLARD  * (C) Copyright 2002
82439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
92439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Rolf Offermanns <rof@sysgo.de>
102439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
112439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Copyright (C) 2001 Standard Microsystems Corporation (SMSC)
122439e4bfSJean-Christophe PLAGNIOL-VILLARD  *       Developed by Simple Network Magic Corporation (SNMC)
132439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Copyright (C) 1996 by Erik Stahlman (ES)
142439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
152439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Information contained in this file was obtained from the LAN91C96
162439e4bfSJean-Christophe PLAGNIOL-VILLARD  * manual from SMC.  To get a copy, if you really want one, you can find
172439e4bfSJean-Christophe PLAGNIOL-VILLARD  * information under www.smsc.com.
182439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
192439e4bfSJean-Christophe PLAGNIOL-VILLARD  * "Features" of the SMC chip:
202439e4bfSJean-Christophe PLAGNIOL-VILLARD  *   6144 byte packet memory. ( for the 91C96 )
212439e4bfSJean-Christophe PLAGNIOL-VILLARD  *   EEPROM for configuration
222439e4bfSJean-Christophe PLAGNIOL-VILLARD  *   AUI/TP selection  ( mine has 10Base2/10BaseT select )
232439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
242439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Arguments:
252439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	io	= for the base address
262439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	irq	= for the IRQ
272439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
282439e4bfSJean-Christophe PLAGNIOL-VILLARD  * author:
292439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Erik Stahlman				( erik@vt.edu )
302439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Daris A Nevil				( dnevil@snmc.com )
312439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
322439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
332439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Hardware multicast code from Peter Cammaert ( pc@denkart.be )
342439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
352439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Sources:
362439e4bfSJean-Christophe PLAGNIOL-VILLARD  *    o   SMSC LAN91C96 databook (www.smsc.com)
372439e4bfSJean-Christophe PLAGNIOL-VILLARD  *    o   smc91111.c (u-boot driver)
382439e4bfSJean-Christophe PLAGNIOL-VILLARD  *    o   smc9194.c (linux kernel driver)
392439e4bfSJean-Christophe PLAGNIOL-VILLARD  *    o   lan91c96.c (Intel Diagnostic Manager driver)
402439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
412439e4bfSJean-Christophe PLAGNIOL-VILLARD  * History:
422439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	04/30/03  Mathijs Haarman	Modified smc91111.c (u-boot version)
432439e4bfSJean-Christophe PLAGNIOL-VILLARD  *					for lan91c96
442439e4bfSJean-Christophe PLAGNIOL-VILLARD  *---------------------------------------------------------------------------
452439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
462439e4bfSJean-Christophe PLAGNIOL-VILLARD 
472439e4bfSJean-Christophe PLAGNIOL-VILLARD #include <common.h>
482439e4bfSJean-Christophe PLAGNIOL-VILLARD #include <command.h>
49b7ad4109SNishanth Menon #include <malloc.h>
502439e4bfSJean-Christophe PLAGNIOL-VILLARD #include "lan91c96.h"
512439e4bfSJean-Christophe PLAGNIOL-VILLARD #include <net.h>
52dffc0ae8SAnatolij Gustschin #include <linux/compiler.h>
532439e4bfSJean-Christophe PLAGNIOL-VILLARD 
542439e4bfSJean-Christophe PLAGNIOL-VILLARD /*------------------------------------------------------------------------
552439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
562439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Configuration options, for the experienced user to change.
572439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
582439e4bfSJean-Christophe PLAGNIOL-VILLARD  -------------------------------------------------------------------------*/
592439e4bfSJean-Christophe PLAGNIOL-VILLARD 
602439e4bfSJean-Christophe PLAGNIOL-VILLARD /* Use power-down feature of the chip */
612439e4bfSJean-Christophe PLAGNIOL-VILLARD #define POWER_DOWN	0
622439e4bfSJean-Christophe PLAGNIOL-VILLARD 
632439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
642439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Wait time for memory to be free.  This probably shouldn't be
652439e4bfSJean-Christophe PLAGNIOL-VILLARD  * tuned that much, as waiting for this means nothing else happens
662439e4bfSJean-Christophe PLAGNIOL-VILLARD  * in the system
672439e4bfSJean-Christophe PLAGNIOL-VILLARD */
682439e4bfSJean-Christophe PLAGNIOL-VILLARD #define MEMORY_WAIT_TIME 16
692439e4bfSJean-Christophe PLAGNIOL-VILLARD 
702439e4bfSJean-Christophe PLAGNIOL-VILLARD #define SMC_DEBUG 0
712439e4bfSJean-Christophe PLAGNIOL-VILLARD 
722439e4bfSJean-Christophe PLAGNIOL-VILLARD #if (SMC_DEBUG > 2 )
732439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK3(args...) printf(args)
742439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
752439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK3(args...)
762439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
772439e4bfSJean-Christophe PLAGNIOL-VILLARD 
782439e4bfSJean-Christophe PLAGNIOL-VILLARD #if SMC_DEBUG > 1
792439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK2(args...) printf(args)
802439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
812439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK2(args...)
822439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
832439e4bfSJean-Christophe PLAGNIOL-VILLARD 
842439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef SMC_DEBUG
852439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK(args...) printf(args)
862439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
872439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK(args...)
882439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
892439e4bfSJean-Christophe PLAGNIOL-VILLARD 
902439e4bfSJean-Christophe PLAGNIOL-VILLARD 
912439e4bfSJean-Christophe PLAGNIOL-VILLARD /*------------------------------------------------------------------------
922439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
932439e4bfSJean-Christophe PLAGNIOL-VILLARD  * The internal workings of the driver.  If you are changing anything
942439e4bfSJean-Christophe PLAGNIOL-VILLARD  * here with the SMC stuff, you should have the datasheet and know
952439e4bfSJean-Christophe PLAGNIOL-VILLARD  * what you are doing.
962439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
972439e4bfSJean-Christophe PLAGNIOL-VILLARD  *------------------------------------------------------------------------
982439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
99b7ad4109SNishanth Menon #define DRIVER_NAME "LAN91C96"
1002439e4bfSJean-Christophe PLAGNIOL-VILLARD #define SMC_ALLOC_MAX_TRY 5
1012439e4bfSJean-Christophe PLAGNIOL-VILLARD #define SMC_TX_TIMEOUT 30
1022439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1032439e4bfSJean-Christophe PLAGNIOL-VILLARD #define ETH_ZLEN 60
1042439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1052439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef  CONFIG_LAN91C96_USE_32_BIT
1062439e4bfSJean-Christophe PLAGNIOL-VILLARD #define USE_32_BIT  1
1072439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
1082439e4bfSJean-Christophe PLAGNIOL-VILLARD #undef USE_32_BIT
1092439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
1102439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1112439e4bfSJean-Christophe PLAGNIOL-VILLARD /* See if a MAC address is defined in the current environment. If so use it. If not
1122439e4bfSJean-Christophe PLAGNIOL-VILLARD  . print a warning and set the environment and other globals with the default.
1132439e4bfSJean-Christophe PLAGNIOL-VILLARD  . If an EEPROM is present it really should be consulted.
1142439e4bfSJean-Christophe PLAGNIOL-VILLARD */
115b7ad4109SNishanth Menon static int smc_get_ethaddr(bd_t *bd, struct eth_device *dev);
116b7ad4109SNishanth Menon static int get_rom_mac(struct eth_device *dev, unsigned char *v_rom_mac);
1172439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1182439e4bfSJean-Christophe PLAGNIOL-VILLARD /* ------------------------------------------------------------
1192439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Internal routines
1202439e4bfSJean-Christophe PLAGNIOL-VILLARD  * ------------------------------------------------------------
1212439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
1222439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1232439e4bfSJean-Christophe PLAGNIOL-VILLARD static unsigned char smc_mac_addr[] = { 0xc0, 0x00, 0x00, 0x1b, 0x62, 0x9c };
1242439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1252439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
1262439e4bfSJean-Christophe PLAGNIOL-VILLARD  * This function must be called before smc_open() if you want to override
1272439e4bfSJean-Christophe PLAGNIOL-VILLARD  * the default mac address.
1282439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
1292439e4bfSJean-Christophe PLAGNIOL-VILLARD 
130b7ad4109SNishanth Menon static void smc_set_mac_addr(const unsigned char *addr)
1312439e4bfSJean-Christophe PLAGNIOL-VILLARD {
1322439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int i;
1332439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1342439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i = 0; i < sizeof (smc_mac_addr); i++) {
1352439e4bfSJean-Christophe PLAGNIOL-VILLARD 		smc_mac_addr[i] = addr[i];
1362439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
1372439e4bfSJean-Christophe PLAGNIOL-VILLARD }
1382439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1392439e4bfSJean-Christophe PLAGNIOL-VILLARD /***********************************************
1402439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Show available memory                       *
1412439e4bfSJean-Christophe PLAGNIOL-VILLARD  ***********************************************/
142b7ad4109SNishanth Menon void dump_memory_info(struct eth_device *dev)
1432439e4bfSJean-Christophe PLAGNIOL-VILLARD {
144dffc0ae8SAnatolij Gustschin 	__maybe_unused word mem_info;
1452439e4bfSJean-Christophe PLAGNIOL-VILLARD 	word old_bank;
1462439e4bfSJean-Christophe PLAGNIOL-VILLARD 
147b7ad4109SNishanth Menon 	old_bank = SMC_inw(dev, LAN91C96_BANK_SELECT) & 0xF;
1482439e4bfSJean-Christophe PLAGNIOL-VILLARD 
149b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 0);
150b7ad4109SNishanth Menon 	mem_info = SMC_inw(dev, LAN91C96_MIR);
1512439e4bfSJean-Christophe PLAGNIOL-VILLARD 	PRINTK2 ("Memory: %4d available\n", (mem_info >> 8) * 2048);
1522439e4bfSJean-Christophe PLAGNIOL-VILLARD 
153b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, old_bank);
1542439e4bfSJean-Christophe PLAGNIOL-VILLARD }
1552439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1562439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
1572439e4bfSJean-Christophe PLAGNIOL-VILLARD  * A rather simple routine to print out a packet for debugging purposes.
1582439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
1592439e4bfSJean-Christophe PLAGNIOL-VILLARD #if SMC_DEBUG > 2
1602439e4bfSJean-Christophe PLAGNIOL-VILLARD static void print_packet (byte *, int);
1612439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
1622439e4bfSJean-Christophe PLAGNIOL-VILLARD 
163b7ad4109SNishanth Menon static int poll4int (struct eth_device *dev, byte mask, int timeout)
1642439e4bfSJean-Christophe PLAGNIOL-VILLARD {
1656d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	int tmo = get_timer (0) + timeout * CONFIG_SYS_HZ;
1662439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int is_timeout = 0;
167b7ad4109SNishanth Menon 	word old_bank = SMC_inw(dev, LAN91C96_BANK_SELECT);
1682439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1692439e4bfSJean-Christophe PLAGNIOL-VILLARD 	PRINTK2 ("Polling...\n");
170b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 2);
171b7ad4109SNishanth Menon 	while ((SMC_inw(dev, LAN91C96_INT_STATS) & mask) == 0) {
1722439e4bfSJean-Christophe PLAGNIOL-VILLARD 		if (get_timer (0) >= tmo) {
1732439e4bfSJean-Christophe PLAGNIOL-VILLARD 			is_timeout = 1;
1742439e4bfSJean-Christophe PLAGNIOL-VILLARD 			break;
1752439e4bfSJean-Christophe PLAGNIOL-VILLARD 		}
1762439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
1772439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1782439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* restore old bank selection */
179b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, old_bank);
1802439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1812439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (is_timeout)
1822439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 1;
1832439e4bfSJean-Christophe PLAGNIOL-VILLARD 	else
1842439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
1852439e4bfSJean-Christophe PLAGNIOL-VILLARD }
1862439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1872439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
188b7ad4109SNishanth Menon  * Function: smc_reset
1892439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Purpose:
1902439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	This sets the SMC91111 chip to its normal state, hopefully from whatever
1912439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	mess that any other DOS driver has put it in.
1922439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
1932439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Maybe I should reset more registers to defaults in here?  SOFTRST  should
1942439e4bfSJean-Christophe PLAGNIOL-VILLARD  * do that for me.
1952439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
1962439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Method:
1972439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	1.  send a SOFT RESET
1982439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	2.  wait for it to finish
1992439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	3.  enable autorelease mode
2002439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	4.  reset the memory management unit
2012439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	5.  clear all interrupts
2022439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
2032439e4bfSJean-Christophe PLAGNIOL-VILLARD */
204b7ad4109SNishanth Menon static void smc_reset(struct eth_device *dev)
2052439e4bfSJean-Christophe PLAGNIOL-VILLARD {
206b7ad4109SNishanth Menon 	PRINTK2("%s:smc_reset\n", dev->name);
2072439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2082439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* This resets the registers mostly to defaults, but doesn't
2092439e4bfSJean-Christophe PLAGNIOL-VILLARD 	   affect EEPROM.  That seems unnecessary */
210b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 0);
211b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_RCR_SOFT_RST, LAN91C96_RCR);
2122439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2132439e4bfSJean-Christophe PLAGNIOL-VILLARD 	udelay (10);
2142439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2152439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Disable transmit and receive functionality */
216b7ad4109SNishanth Menon 	SMC_outw(dev, 0, LAN91C96_RCR);
217b7ad4109SNishanth Menon 	SMC_outw(dev, 0, LAN91C96_TCR);
2182439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2192439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* set the control register */
220b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 1);
221b7ad4109SNishanth Menon 	SMC_outw(dev, SMC_inw(dev, LAN91C96_CONTROL) | LAN91C96_CTR_BIT_8,
2222439e4bfSJean-Christophe PLAGNIOL-VILLARD 			  LAN91C96_CONTROL);
2232439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2242439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Disable all interrupts */
225b7ad4109SNishanth Menon 	SMC_outb(dev, 0, LAN91C96_INT_MASK);
2262439e4bfSJean-Christophe PLAGNIOL-VILLARD }
2272439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2282439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
2292439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Function: smc_enable
2302439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Purpose: let the chip talk to the outside work
2312439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Method:
2322439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	1.  Initialize the Memory Configuration Register
2332439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	2.  Enable the transmitter
2342439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	3.  Enable the receiver
2352439e4bfSJean-Christophe PLAGNIOL-VILLARD */
236b7ad4109SNishanth Menon static void smc_enable(struct eth_device *dev)
2372439e4bfSJean-Christophe PLAGNIOL-VILLARD {
238b7ad4109SNishanth Menon 	PRINTK2("%s:smc_enable\n", dev->name);
239b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 0);
2402439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2412439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Initialize the Memory Configuration Register. See page
2422439e4bfSJean-Christophe PLAGNIOL-VILLARD 	   49 of the LAN91C96 data sheet for details. */
243b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_MCR_TRANSMIT_PAGES, LAN91C96_MCR);
2442439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2452439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Initialize the Transmit Control Register */
246b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_TCR_TXENA, LAN91C96_TCR);
2472439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Initialize the Receive Control Register
2482439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * FIXME:
2492439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * The promiscuous bit set because I could not receive ARP reply
2502439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * packets from the server when I send a ARP request. It only works
2512439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * when I set the promiscuous bit
2522439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 */
253b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_RCR_RXEN | LAN91C96_RCR_PRMS, LAN91C96_RCR);
2542439e4bfSJean-Christophe PLAGNIOL-VILLARD }
2552439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2562439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
2572439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Function: smc_shutdown
2582439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Purpose:  closes down the SMC91xxx chip.
2592439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Method:
2602439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	1. zero the interrupt mask
2612439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	2. clear the enable receive flag
2622439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	3. clear the enable xmit flags
2632439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
2642439e4bfSJean-Christophe PLAGNIOL-VILLARD  * TODO:
2652439e4bfSJean-Christophe PLAGNIOL-VILLARD  *   (1) maybe utilize power down mode.
2662439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Why not yet?  Because while the chip will go into power down mode,
2672439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	the manual says that it will wake up in response to any I/O requests
2682439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	in the register space.   Empirical results do not show this working.
2692439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
270b7ad4109SNishanth Menon static void smc_shutdown(struct eth_device *dev)
2712439e4bfSJean-Christophe PLAGNIOL-VILLARD {
272b7ad4109SNishanth Menon 	PRINTK2("%s:smc_shutdown\n", dev->name);
2732439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2742439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* no more interrupts for me */
275b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 2);
276b7ad4109SNishanth Menon 	SMC_outb(dev, 0, LAN91C96_INT_MASK);
2772439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2782439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* and tell the card to stay away from that nasty outside world */
279b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 0);
280b7ad4109SNishanth Menon 	SMC_outb(dev, 0, LAN91C96_RCR);
281b7ad4109SNishanth Menon 	SMC_outb(dev, 0, LAN91C96_TCR);
2822439e4bfSJean-Christophe PLAGNIOL-VILLARD }
2832439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2842439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2852439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
2862439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Function:  smc_hardware_send_packet(struct net_device * )
2872439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Purpose:
2882439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	This sends the actual packet to the SMC9xxx chip.
2892439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
2902439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Algorithm:
2912439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	First, see if a saved_skb is available.
2922439e4bfSJean-Christophe PLAGNIOL-VILLARD  *		( this should NOT be called if there is no 'saved_skb'
2932439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Now, find the packet number that the chip allocated
2942439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Point the data pointers at it in memory
2952439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Set the length word in the chip's memory
2962439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Dump the packet to chip memory
2972439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Check if a last byte is needed ( odd length packet )
2982439e4bfSJean-Christophe PLAGNIOL-VILLARD  *		if so, set the control flag right
2992439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Tell the card to send it
3002439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Enable the transmit interrupt, so I know if it failed
3012439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Free the kernel data if I actually sent it.
3022439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
30330934b3eSJoe Hershberger static int smc_send_packet(struct eth_device *dev, void *packet,
304b7ad4109SNishanth Menon 		int packet_length)
3052439e4bfSJean-Christophe PLAGNIOL-VILLARD {
3062439e4bfSJean-Christophe PLAGNIOL-VILLARD 	byte packet_no;
3072439e4bfSJean-Christophe PLAGNIOL-VILLARD 	byte *buf;
3082439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int length;
3092439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int numPages;
3102439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int try = 0;
3112439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int time_out;
3122439e4bfSJean-Christophe PLAGNIOL-VILLARD 	byte status;
3132439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3142439e4bfSJean-Christophe PLAGNIOL-VILLARD 
315b7ad4109SNishanth Menon 	PRINTK3("%s:smc_hardware_send_packet\n", dev->name);
3162439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3172439e4bfSJean-Christophe PLAGNIOL-VILLARD 	length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN;
3182439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3192439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* allocate memory
3202439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** The MMU wants the number of pages to be the number of 256 bytes
3212439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
3222439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 **
3232439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** The 91C111 ignores the size bits, but the code is left intact
3242439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** for backwards and future compatibility.
3252439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 **
3262439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** Pkt size for allocating is data length +6 (for additional status
3272439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** words, length and ctl!)
3282439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 **
3292439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** If odd size then last byte is included in this header.
3302439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 */
3312439e4bfSJean-Christophe PLAGNIOL-VILLARD 	numPages = ((length & 0xfffe) + 6);
3322439e4bfSJean-Christophe PLAGNIOL-VILLARD 	numPages >>= 8;				/* Divide by 256 */
3332439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3342439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (numPages > 7) {
335b7ad4109SNishanth Menon 		printf("%s: Far too big packet error. \n", dev->name);
3362439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
3372439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
3382439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3392439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* now, try to allocate the memory */
3402439e4bfSJean-Christophe PLAGNIOL-VILLARD 
341b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 2);
342b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_MMUCR_ALLOC_TX | numPages, LAN91C96_MMU);
3432439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3442439e4bfSJean-Christophe PLAGNIOL-VILLARD   again:
3452439e4bfSJean-Christophe PLAGNIOL-VILLARD 	try++;
3462439e4bfSJean-Christophe PLAGNIOL-VILLARD 	time_out = MEMORY_WAIT_TIME;
3472439e4bfSJean-Christophe PLAGNIOL-VILLARD 	do {
348b7ad4109SNishanth Menon 		status = SMC_inb(dev, LAN91C96_INT_STATS);
3492439e4bfSJean-Christophe PLAGNIOL-VILLARD 		if (status & LAN91C96_IST_ALLOC_INT) {
3502439e4bfSJean-Christophe PLAGNIOL-VILLARD 
351b7ad4109SNishanth Menon 			SMC_outb(dev, LAN91C96_IST_ALLOC_INT,
352b7ad4109SNishanth Menon 					LAN91C96_INT_STATS);
3532439e4bfSJean-Christophe PLAGNIOL-VILLARD 			break;
3542439e4bfSJean-Christophe PLAGNIOL-VILLARD 		}
3552439e4bfSJean-Christophe PLAGNIOL-VILLARD 	} while (--time_out);
3562439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3572439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (!time_out) {
3582439e4bfSJean-Christophe PLAGNIOL-VILLARD 		PRINTK2 ("%s: memory allocation, try %d failed ...\n",
359b7ad4109SNishanth Menon 				 dev->name, try);
3602439e4bfSJean-Christophe PLAGNIOL-VILLARD 		if (try < SMC_ALLOC_MAX_TRY)
3612439e4bfSJean-Christophe PLAGNIOL-VILLARD 			goto again;
3622439e4bfSJean-Christophe PLAGNIOL-VILLARD 		else
3632439e4bfSJean-Christophe PLAGNIOL-VILLARD 			return 0;
3642439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
3652439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3662439e4bfSJean-Christophe PLAGNIOL-VILLARD 	PRINTK2 ("%s: memory allocation, try %d succeeded ...\n",
367b7ad4109SNishanth Menon 			 dev->name, try);
3682439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3692439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* I can send the packet now.. */
3702439e4bfSJean-Christophe PLAGNIOL-VILLARD 	buf = (byte *) packet;
3712439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3722439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* If I get here, I _know_ there is a packet slot waiting for me */
373b7ad4109SNishanth Menon 	packet_no = SMC_inb(dev, LAN91C96_ARR);
3742439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (packet_no & LAN91C96_ARR_FAILED) {
3752439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* or isn't there?  BAD CHIP! */
376b7ad4109SNishanth Menon 		printf("%s: Memory allocation failed. \n", dev->name);
3772439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
3782439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
3792439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3802439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* we have a packet address, so tell the card to use it */
381b7ad4109SNishanth Menon 	SMC_outb(dev, packet_no, LAN91C96_PNR);
3822439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3832439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* point to the beginning of the packet */
384b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);
3852439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3862439e4bfSJean-Christophe PLAGNIOL-VILLARD 	PRINTK3("%s: Trying to xmit packet of length %x\n",
387b7ad4109SNishanth Menon 			 dev->name, length);
3882439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3892439e4bfSJean-Christophe PLAGNIOL-VILLARD #if SMC_DEBUG > 2
3902439e4bfSJean-Christophe PLAGNIOL-VILLARD 	printf ("Transmitting Packet\n");
3912439e4bfSJean-Christophe PLAGNIOL-VILLARD 	print_packet (buf, length);
3922439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
3932439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3942439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* send the packet length ( +6 for status, length and ctl byte )
3952439e4bfSJean-Christophe PLAGNIOL-VILLARD 	   and the status word ( set to zeros ) */
3962439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
397b7ad4109SNishanth Menon 	SMC_outl(dev, (length + 6) << 16, LAN91C96_DATA_HIGH);
3982439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
399b7ad4109SNishanth Menon 	SMC_outw(dev, 0, LAN91C96_DATA_HIGH);
4002439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* send the packet length ( +6 for status words, length, and ctl */
401b7ad4109SNishanth Menon 	SMC_outw(dev, (length + 6), LAN91C96_DATA_HIGH);
4022439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif /* USE_32_BIT */
4032439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4042439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* send the actual data
4052439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * I _think_ it's faster to send the longs first, and then
4062439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * mop up by sending the last word.  It depends heavily
4072439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * on alignment, at least on the 486.  Maybe it would be
4082439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * a good idea to check which is optimal?  But that could take
4092439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * almost as much time as is saved?
4102439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 */
4112439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
412b7ad4109SNishanth Menon 	SMC_outsl(dev, LAN91C96_DATA_HIGH, buf, length >> 2);
4132439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (length & 0x2)
414b7ad4109SNishanth Menon 		SMC_outw(dev, *((word *) (buf + (length & 0xFFFFFFFC))),
4152439e4bfSJean-Christophe PLAGNIOL-VILLARD 				  LAN91C96_DATA_HIGH);
4162439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
417b7ad4109SNishanth Menon 	SMC_outsw(dev, LAN91C96_DATA_HIGH, buf, (length) >> 1);
4182439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif /* USE_32_BIT */
4192439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4202439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Send the last byte, if there is one.   */
4212439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if ((length & 1) == 0) {
422b7ad4109SNishanth Menon 		SMC_outw(dev, 0, LAN91C96_DATA_HIGH);
4232439e4bfSJean-Christophe PLAGNIOL-VILLARD 	} else {
424b7ad4109SNishanth Menon 		SMC_outw(dev, buf[length - 1] | 0x2000, LAN91C96_DATA_HIGH);
4252439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
4262439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4272439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* and let the chipset deal with it */
428b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_MMUCR_ENQUEUE, LAN91C96_MMU);
4292439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4302439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* poll for TX INT */
431b7ad4109SNishanth Menon 	if (poll4int (dev, LAN91C96_MSK_TX_INT, SMC_TX_TIMEOUT)) {
4322439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* sending failed */
433b7ad4109SNishanth Menon 		PRINTK2("%s: TX timeout, sending failed...\n", dev->name);
4342439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4352439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* release packet */
436b7ad4109SNishanth Menon 		SMC_outw(dev, LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);
4372439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4382439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* wait for MMU getting ready (low) */
439b7ad4109SNishanth Menon 		while (SMC_inw(dev, LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
4402439e4bfSJean-Christophe PLAGNIOL-VILLARD 			udelay (10);
4412439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4422439e4bfSJean-Christophe PLAGNIOL-VILLARD 		PRINTK2("MMU ready\n");
4432439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4442439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4452439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
4462439e4bfSJean-Christophe PLAGNIOL-VILLARD 	} else {
4472439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* ack. int */
448b7ad4109SNishanth Menon 		SMC_outw(dev, LAN91C96_IST_TX_INT, LAN91C96_INT_STATS);
4492439e4bfSJean-Christophe PLAGNIOL-VILLARD 
450b7ad4109SNishanth Menon 		PRINTK2("%s: Sent packet of length %d \n", dev->name, length);
4512439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4522439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* release packet */
453b7ad4109SNishanth Menon 		SMC_outw(dev, LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);
4542439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4552439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* wait for MMU getting ready (low) */
456b7ad4109SNishanth Menon 		while (SMC_inw(dev, LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
4572439e4bfSJean-Christophe PLAGNIOL-VILLARD 			udelay (10);
4582439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4592439e4bfSJean-Christophe PLAGNIOL-VILLARD 		PRINTK2 ("MMU ready\n");
4602439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
4612439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4622439e4bfSJean-Christophe PLAGNIOL-VILLARD 	return length;
4632439e4bfSJean-Christophe PLAGNIOL-VILLARD }
4642439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4652439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4662439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
4672439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Open and Initialize the board
4682439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
4692439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Set up everything, reset the card, etc ..
4702439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
4712439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
472b7ad4109SNishanth Menon static int smc_open(bd_t *bd, struct eth_device *dev)
4732439e4bfSJean-Christophe PLAGNIOL-VILLARD {
4742439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int i, err;			/* used to set hw ethernet address */
4752439e4bfSJean-Christophe PLAGNIOL-VILLARD 
476b7ad4109SNishanth Menon 	PRINTK2("%s:smc_open\n", dev->name);
4772439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4782439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* reset the hardware */
4792439e4bfSJean-Christophe PLAGNIOL-VILLARD 
480b7ad4109SNishanth Menon 	smc_reset(dev);
481b7ad4109SNishanth Menon 	smc_enable(dev);
4822439e4bfSJean-Christophe PLAGNIOL-VILLARD 
483b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 1);
484b7ad4109SNishanth Menon 	/* set smc_mac_addr, and sync it with u-boot globals */
485b7ad4109SNishanth Menon 	err = smc_get_ethaddr(bd, dev);
48603f3d8d3SMike Frysinger 	if (err < 0)
48703f3d8d3SMike Frysinger 		return -1;
4882439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
4892439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i = 0; i < 6; i += 2) {
4902439e4bfSJean-Christophe PLAGNIOL-VILLARD 		word address;
4912439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4922439e4bfSJean-Christophe PLAGNIOL-VILLARD 		address = smc_mac_addr[i + 1] << 8;
4932439e4bfSJean-Christophe PLAGNIOL-VILLARD 		address |= smc_mac_addr[i];
494b7ad4109SNishanth Menon 		SMC_outw(dev, address, LAN91C96_IA0 + i);
4952439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
4962439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
4972439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i = 0; i < 6; i++)
498b7ad4109SNishanth Menon 		SMC_outb(dev, smc_mac_addr[i], LAN91C96_IA0 + i);
4992439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
5002439e4bfSJean-Christophe PLAGNIOL-VILLARD 	return 0;
5012439e4bfSJean-Christophe PLAGNIOL-VILLARD }
5022439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5032439e4bfSJean-Christophe PLAGNIOL-VILLARD /*-------------------------------------------------------------
5042439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
5052439e4bfSJean-Christophe PLAGNIOL-VILLARD  * smc_rcv -  receive a packet from the card
5062439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
5072439e4bfSJean-Christophe PLAGNIOL-VILLARD  * There is ( at least ) a packet waiting to be read from
5082439e4bfSJean-Christophe PLAGNIOL-VILLARD  * chip-memory.
5092439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
5102439e4bfSJean-Christophe PLAGNIOL-VILLARD  * o Read the status
5112439e4bfSJean-Christophe PLAGNIOL-VILLARD  * o If an error, record it
5122439e4bfSJean-Christophe PLAGNIOL-VILLARD  * o otherwise, read in the packet
5132439e4bfSJean-Christophe PLAGNIOL-VILLARD  *-------------------------------------------------------------
5142439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
515b7ad4109SNishanth Menon static int smc_rcv(struct eth_device *dev)
5162439e4bfSJean-Christophe PLAGNIOL-VILLARD {
5172439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int packet_number;
5182439e4bfSJean-Christophe PLAGNIOL-VILLARD 	word status;
5192439e4bfSJean-Christophe PLAGNIOL-VILLARD 	word packet_length;
5202439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int is_error = 0;
5212439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5222439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
5232439e4bfSJean-Christophe PLAGNIOL-VILLARD 	dword stat_len;
5242439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
5252439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5262439e4bfSJean-Christophe PLAGNIOL-VILLARD 
527b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 2);
528b7ad4109SNishanth Menon 	packet_number = SMC_inw(dev, LAN91C96_FIFO);
5292439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5302439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (packet_number & LAN91C96_FIFO_RXEMPTY) {
5312439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
5322439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
5332439e4bfSJean-Christophe PLAGNIOL-VILLARD 
534b7ad4109SNishanth Menon 	PRINTK3("%s:smc_rcv\n", dev->name);
5352439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/*  start reading from the start of the packet */
536b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_PTR_READ | LAN91C96_PTR_RCV |
5372439e4bfSJean-Christophe PLAGNIOL-VILLARD 			  LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);
5382439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5392439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* First two words are status and packet_length */
5402439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
541b7ad4109SNishanth Menon 	stat_len = SMC_inl(dev, LAN91C96_DATA_HIGH);
5422439e4bfSJean-Christophe PLAGNIOL-VILLARD 	status = stat_len & 0xffff;
5432439e4bfSJean-Christophe PLAGNIOL-VILLARD 	packet_length = stat_len >> 16;
5442439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
545b7ad4109SNishanth Menon 	status = SMC_inw(dev, LAN91C96_DATA_HIGH);
546b7ad4109SNishanth Menon 	packet_length = SMC_inw(dev, LAN91C96_DATA_HIGH);
5472439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
5482439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5492439e4bfSJean-Christophe PLAGNIOL-VILLARD 	packet_length &= 0x07ff;	/* mask off top bits */
5502439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5512439e4bfSJean-Christophe PLAGNIOL-VILLARD 	PRINTK2 ("RCV: STATUS %4x LENGTH %4x\n", status, packet_length);
5522439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5532439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (!(status & FRAME_FILTER)) {
5542439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* Adjust for having already read the first two words */
5552439e4bfSJean-Christophe PLAGNIOL-VILLARD 		packet_length -= 4;		/*4; */
5562439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5572439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5582439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* set odd length for bug in LAN91C111, */
5592439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* which never sets RS_ODDFRAME */
5602439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* TODO ? */
5612439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5622439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5632439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
5642439e4bfSJean-Christophe PLAGNIOL-VILLARD 		PRINTK3 (" Reading %d dwords (and %d bytes) \n",
5652439e4bfSJean-Christophe PLAGNIOL-VILLARD 			 packet_length >> 2, packet_length & 3);
5662439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* QUESTION:  Like in the TX routine, do I want
5672439e4bfSJean-Christophe PLAGNIOL-VILLARD 		   to send the DWORDs or the bytes first, or some
5682439e4bfSJean-Christophe PLAGNIOL-VILLARD 		   mixture.  A mixture might improve already slow PIO
5692439e4bfSJean-Christophe PLAGNIOL-VILLARD 		   performance  */
5701fd92db8SJoe Hershberger 		SMC_insl(dev, LAN91C96_DATA_HIGH, net_rx_packets[0],
571b7ad4109SNishanth Menon 			 packet_length >> 2);
5722439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* read the left over bytes */
5732439e4bfSJean-Christophe PLAGNIOL-VILLARD 		if (packet_length & 3) {
5742439e4bfSJean-Christophe PLAGNIOL-VILLARD 			int i;
5752439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5761fd92db8SJoe Hershberger 			byte *tail = (byte *)(net_rx_packets[0] +
5771fd92db8SJoe Hershberger 				(packet_length & ~3));
578b7ad4109SNishanth Menon 			dword leftover = SMC_inl(dev, LAN91C96_DATA_HIGH);
5792439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5802439e4bfSJean-Christophe PLAGNIOL-VILLARD 			for (i = 0; i < (packet_length & 3); i++)
5812439e4bfSJean-Christophe PLAGNIOL-VILLARD 				*tail++ = (byte) (leftover >> (8 * i)) & 0xff;
5822439e4bfSJean-Christophe PLAGNIOL-VILLARD 		}
5832439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
5842439e4bfSJean-Christophe PLAGNIOL-VILLARD 		PRINTK3(" Reading %d words and %d byte(s)\n",
5852439e4bfSJean-Christophe PLAGNIOL-VILLARD 			(packet_length >> 1), packet_length & 1);
5861fd92db8SJoe Hershberger 		SMC_insw(dev, LAN91C96_DATA_HIGH, net_rx_packets[0],
587b7ad4109SNishanth Menon 			 packet_length >> 1);
5882439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5892439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif /* USE_32_BIT */
5902439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5912439e4bfSJean-Christophe PLAGNIOL-VILLARD #if	SMC_DEBUG > 2
5922439e4bfSJean-Christophe PLAGNIOL-VILLARD 		printf ("Receiving Packet\n");
5931fd92db8SJoe Hershberger 		print_packet((byte *)net_rx_packets[0], packet_length);
5942439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
5952439e4bfSJean-Christophe PLAGNIOL-VILLARD 	} else {
5962439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* error ... */
5972439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* TODO ? */
5982439e4bfSJean-Christophe PLAGNIOL-VILLARD 		is_error = 1;
5992439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
6002439e4bfSJean-Christophe PLAGNIOL-VILLARD 
601b7ad4109SNishanth Menon 	while (SMC_inw(dev, LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
6022439e4bfSJean-Christophe PLAGNIOL-VILLARD 		udelay (1);		/* Wait until not busy */
6032439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6042439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/*  error or good, tell the card to get rid of this packet */
605b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_MMUCR_RELEASE_RX, LAN91C96_MMU);
6062439e4bfSJean-Christophe PLAGNIOL-VILLARD 
607b7ad4109SNishanth Menon 	while (SMC_inw(dev, LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
6082439e4bfSJean-Christophe PLAGNIOL-VILLARD 		udelay (1);		/* Wait until not busy */
6092439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6102439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (!is_error) {
6112439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* Pass the packet up to the protocol layers. */
6121fd92db8SJoe Hershberger 		net_process_received_packet(net_rx_packets[0], packet_length);
6132439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return packet_length;
6142439e4bfSJean-Christophe PLAGNIOL-VILLARD 	} else {
6152439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
6162439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
6172439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6182439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6192439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6202439e4bfSJean-Christophe PLAGNIOL-VILLARD /*----------------------------------------------------
6212439e4bfSJean-Christophe PLAGNIOL-VILLARD  * smc_close
6222439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
6232439e4bfSJean-Christophe PLAGNIOL-VILLARD  * this makes the board clean up everything that it can
6242439e4bfSJean-Christophe PLAGNIOL-VILLARD  * and not talk to the outside world.   Caused by
6252439e4bfSJean-Christophe PLAGNIOL-VILLARD  * an 'ifconfig ethX down'
6262439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
6272439e4bfSJean-Christophe PLAGNIOL-VILLARD  -----------------------------------------------------*/
628b7ad4109SNishanth Menon static int smc_close(struct eth_device *dev)
6292439e4bfSJean-Christophe PLAGNIOL-VILLARD {
630b7ad4109SNishanth Menon 	PRINTK2("%s:smc_close\n", dev->name);
6312439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6322439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* clear everything */
633b7ad4109SNishanth Menon 	smc_shutdown(dev);
6342439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6352439e4bfSJean-Christophe PLAGNIOL-VILLARD 	return 0;
6362439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6372439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6382439e4bfSJean-Christophe PLAGNIOL-VILLARD #if SMC_DEBUG > 2
6392439e4bfSJean-Christophe PLAGNIOL-VILLARD static void print_packet(byte *buf, int length)
6402439e4bfSJean-Christophe PLAGNIOL-VILLARD {
6412439e4bfSJean-Christophe PLAGNIOL-VILLARD #if 0
6422439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int i;
6432439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int remainder;
6442439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int lines;
6452439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6462439e4bfSJean-Christophe PLAGNIOL-VILLARD 	printf ("Packet of length %d \n", length);
6472439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6482439e4bfSJean-Christophe PLAGNIOL-VILLARD 	lines = length / 16;
6492439e4bfSJean-Christophe PLAGNIOL-VILLARD 	remainder = length % 16;
6502439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6512439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i = 0; i < lines; i++) {
6522439e4bfSJean-Christophe PLAGNIOL-VILLARD 		int cur;
6532439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6542439e4bfSJean-Christophe PLAGNIOL-VILLARD 		for (cur = 0; cur < 8; cur++) {
6552439e4bfSJean-Christophe PLAGNIOL-VILLARD 			byte a, b;
6562439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6572439e4bfSJean-Christophe PLAGNIOL-VILLARD 			a = *(buf++);
6582439e4bfSJean-Christophe PLAGNIOL-VILLARD 			b = *(buf++);
6592439e4bfSJean-Christophe PLAGNIOL-VILLARD 			printf ("%02x%02x ", a, b);
6602439e4bfSJean-Christophe PLAGNIOL-VILLARD 		}
6612439e4bfSJean-Christophe PLAGNIOL-VILLARD 		printf ("\n");
6622439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
6632439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i = 0; i < remainder / 2; i++) {
6642439e4bfSJean-Christophe PLAGNIOL-VILLARD 		byte a, b;
6652439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6662439e4bfSJean-Christophe PLAGNIOL-VILLARD 		a = *(buf++);
6672439e4bfSJean-Christophe PLAGNIOL-VILLARD 		b = *(buf++);
6682439e4bfSJean-Christophe PLAGNIOL-VILLARD 		printf ("%02x%02x ", a, b);
6692439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
6702439e4bfSJean-Christophe PLAGNIOL-VILLARD 	printf ("\n");
6712439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif /* 0 */
6722439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6732439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif /* SMC_DEBUG > 2 */
6742439e4bfSJean-Christophe PLAGNIOL-VILLARD 
675b7ad4109SNishanth Menon static int  lan91c96_init(struct eth_device *dev, bd_t *bd)
6762439e4bfSJean-Christophe PLAGNIOL-VILLARD {
677b7ad4109SNishanth Menon 	return smc_open(bd, dev);
6782439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6792439e4bfSJean-Christophe PLAGNIOL-VILLARD 
680b7ad4109SNishanth Menon static void lan91c96_halt(struct eth_device *dev)
6812439e4bfSJean-Christophe PLAGNIOL-VILLARD {
682b7ad4109SNishanth Menon 	smc_close(dev);
6832439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6842439e4bfSJean-Christophe PLAGNIOL-VILLARD 
685b7ad4109SNishanth Menon static int lan91c96_recv(struct eth_device *dev)
6862439e4bfSJean-Christophe PLAGNIOL-VILLARD {
687b7ad4109SNishanth Menon 	return smc_rcv(dev);
6882439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6892439e4bfSJean-Christophe PLAGNIOL-VILLARD 
69030934b3eSJoe Hershberger static int lan91c96_send(struct eth_device *dev, void *packet,
691b7ad4109SNishanth Menon 		int length)
6922439e4bfSJean-Christophe PLAGNIOL-VILLARD {
693b7ad4109SNishanth Menon 	return smc_send_packet(dev, packet, length);
6942439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6952439e4bfSJean-Christophe PLAGNIOL-VILLARD 
696b7ad4109SNishanth Menon /* smc_get_ethaddr
6972439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
6982439e4bfSJean-Christophe PLAGNIOL-VILLARD  * This checks both the environment and the ROM for an ethernet address. If
6992439e4bfSJean-Christophe PLAGNIOL-VILLARD  * found, the environment takes precedence.
7002439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
7012439e4bfSJean-Christophe PLAGNIOL-VILLARD 
702b7ad4109SNishanth Menon static int smc_get_ethaddr(bd_t *bd, struct eth_device *dev)
7032439e4bfSJean-Christophe PLAGNIOL-VILLARD {
70403f3d8d3SMike Frysinger 	uchar v_mac[6];
7052439e4bfSJean-Christophe PLAGNIOL-VILLARD 
70635affd7aSSimon Glass 	if (!eth_env_get_enetaddr("ethaddr", v_mac)) {
70703f3d8d3SMike Frysinger 		/* get ROM mac value if any */
708b7ad4109SNishanth Menon 		if (!get_rom_mac(dev, v_mac)) {
7092439e4bfSJean-Christophe PLAGNIOL-VILLARD 			printf("\n*** ERROR: ethaddr is NOT set !!\n");
71003f3d8d3SMike Frysinger 			return -1;
7112439e4bfSJean-Christophe PLAGNIOL-VILLARD 		}
712fd1e959eSSimon Glass 		eth_env_set_enetaddr("ethaddr", v_mac);
7132439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
7142439e4bfSJean-Christophe PLAGNIOL-VILLARD 
71503f3d8d3SMike Frysinger 	smc_set_mac_addr(v_mac); /* use old function to update smc default */
71603f3d8d3SMike Frysinger 	PRINTK("Using MAC Address %pM\n", v_mac);
71703f3d8d3SMike Frysinger 	return 0;
7182439e4bfSJean-Christophe PLAGNIOL-VILLARD }
7192439e4bfSJean-Christophe PLAGNIOL-VILLARD 
7202439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
7212439e4bfSJean-Christophe PLAGNIOL-VILLARD  * get_rom_mac()
7222439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Note, this has omly been tested for the OMAP730 P2.
7232439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
7242439e4bfSJean-Christophe PLAGNIOL-VILLARD 
725b7ad4109SNishanth Menon static int get_rom_mac(struct eth_device *dev, unsigned char *v_rom_mac)
7262439e4bfSJean-Christophe PLAGNIOL-VILLARD {
7272439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int i;
728b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 1);
7292439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i=0; i<6; i++)
7302439e4bfSJean-Christophe PLAGNIOL-VILLARD 	{
731b7ad4109SNishanth Menon 		v_rom_mac[i] = SMC_inb(dev, LAN91C96_IA0 + i);
7322439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
7332439e4bfSJean-Christophe PLAGNIOL-VILLARD 	return (1);
7342439e4bfSJean-Christophe PLAGNIOL-VILLARD }
735b7ad4109SNishanth Menon 
736b7ad4109SNishanth Menon /* Structure to detect the device IDs */
737b7ad4109SNishanth Menon struct id_type {
738b7ad4109SNishanth Menon 	u8 id;
739b7ad4109SNishanth Menon 	char *name;
740b7ad4109SNishanth Menon };
741b7ad4109SNishanth Menon static struct id_type supported_chips[] = {
742b7ad4109SNishanth Menon 	{0, ""}, /* Dummy entry to prevent id check failure */
743b7ad4109SNishanth Menon 	{9, "LAN91C110"},
744b7ad4109SNishanth Menon 	{8, "LAN91C100FD"},
745b7ad4109SNishanth Menon 	{7, "LAN91C100"},
746b7ad4109SNishanth Menon 	{5, "LAN91C95"},
7470e7790d4SYanjun Yang 	{4, "LAN91C94/96"},
7480e7790d4SYanjun Yang 	{3, "LAN91C90/92"},
749b7ad4109SNishanth Menon };
750b7ad4109SNishanth Menon /* lan91c96_detect_chip
751b7ad4109SNishanth Menon  * See:
752b7ad4109SNishanth Menon  * http://www.embeddedsys.com/subpages/resources/images/documents/LAN91C96_datasheet.pdf
753b7ad4109SNishanth Menon  * page 71 - that is the closest we get to detect this device
754b7ad4109SNishanth Menon  */
755b7ad4109SNishanth Menon static int lan91c96_detect_chip(struct eth_device *dev)
756b7ad4109SNishanth Menon {
757b7ad4109SNishanth Menon 	u8 chip_id;
758b7ad4109SNishanth Menon 	int r;
759b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 3);
76016721715SYanjun Yang 	chip_id = (SMC_inw(dev, 0xA) & LAN91C96_REV_CHIPID) >> 4;
761b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 0);
762a62cd29cSAxel Lin 	for (r = 0; r < ARRAY_SIZE(supported_chips); r++)
763b7ad4109SNishanth Menon 		if (chip_id == supported_chips[r].id)
764b7ad4109SNishanth Menon 			return r;
765b7ad4109SNishanth Menon 	return 0;
766b7ad4109SNishanth Menon }
767b7ad4109SNishanth Menon 
768b7ad4109SNishanth Menon int lan91c96_initialize(u8 dev_num, int base_addr)
769b7ad4109SNishanth Menon {
770b7ad4109SNishanth Menon 	struct eth_device *dev;
771b7ad4109SNishanth Menon 	int r = 0;
772b7ad4109SNishanth Menon 
773b7ad4109SNishanth Menon 	dev = malloc(sizeof(*dev));
774b7ad4109SNishanth Menon 	if (!dev) {
775b7ad4109SNishanth Menon 		return 0;
776b7ad4109SNishanth Menon 	}
777b7ad4109SNishanth Menon 	memset(dev, 0, sizeof(*dev));
778b7ad4109SNishanth Menon 
779b7ad4109SNishanth Menon 	dev->iobase = base_addr;
780b7ad4109SNishanth Menon 
781b7ad4109SNishanth Menon 	/* Try to detect chip. Will fail if not present. */
782b7ad4109SNishanth Menon 	r = lan91c96_detect_chip(dev);
783b7ad4109SNishanth Menon 	if (!r) {
784b7ad4109SNishanth Menon 		free(dev);
785b7ad4109SNishanth Menon 		return 0;
786b7ad4109SNishanth Menon 	}
787b7ad4109SNishanth Menon 	get_rom_mac(dev, dev->enetaddr);
788b7ad4109SNishanth Menon 
789b7ad4109SNishanth Menon 	dev->init = lan91c96_init;
790b7ad4109SNishanth Menon 	dev->halt = lan91c96_halt;
791b7ad4109SNishanth Menon 	dev->send = lan91c96_send;
792b7ad4109SNishanth Menon 	dev->recv = lan91c96_recv;
793b7ad4109SNishanth Menon 	sprintf(dev->name, "%s-%hu", supported_chips[r].name, dev_num);
794b7ad4109SNishanth Menon 
795b7ad4109SNishanth Menon 	eth_register(dev);
796b7ad4109SNishanth Menon 	return 0;
797b7ad4109SNishanth Menon }
798