xref: /openbmc/u-boot/drivers/net/lan91c96.c (revision a187559e)
12439e4bfSJean-Christophe PLAGNIOL-VILLARD /*------------------------------------------------------------------------
22439e4bfSJean-Christophe PLAGNIOL-VILLARD  * lan91c96.c
32439e4bfSJean-Christophe PLAGNIOL-VILLARD  * This is a driver for SMSC's LAN91C96 single-chip Ethernet device, based
4*a187559eSBin Meng  * on the SMC91111 driver from U-Boot.
52439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
62439e4bfSJean-Christophe PLAGNIOL-VILLARD  * (C) Copyright 2002
72439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
82439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Rolf Offermanns <rof@sysgo.de>
92439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
102439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Copyright (C) 2001 Standard Microsystems Corporation (SMSC)
112439e4bfSJean-Christophe PLAGNIOL-VILLARD  *       Developed by Simple Network Magic Corporation (SNMC)
122439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Copyright (C) 1996 by Erik Stahlman (ES)
132439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
141a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
152439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
162439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Information contained in this file was obtained from the LAN91C96
172439e4bfSJean-Christophe PLAGNIOL-VILLARD  * manual from SMC.  To get a copy, if you really want one, you can find
182439e4bfSJean-Christophe PLAGNIOL-VILLARD  * information under www.smsc.com.
192439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
202439e4bfSJean-Christophe PLAGNIOL-VILLARD  * "Features" of the SMC chip:
212439e4bfSJean-Christophe PLAGNIOL-VILLARD  *   6144 byte packet memory. ( for the 91C96 )
222439e4bfSJean-Christophe PLAGNIOL-VILLARD  *   EEPROM for configuration
232439e4bfSJean-Christophe PLAGNIOL-VILLARD  *   AUI/TP selection  ( mine has 10Base2/10BaseT select )
242439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
252439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Arguments:
262439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	io	= for the base address
272439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	irq	= for the IRQ
282439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
292439e4bfSJean-Christophe PLAGNIOL-VILLARD  * author:
302439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Erik Stahlman				( erik@vt.edu )
312439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Daris A Nevil				( dnevil@snmc.com )
322439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
332439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
342439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Hardware multicast code from Peter Cammaert ( pc@denkart.be )
352439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
362439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Sources:
372439e4bfSJean-Christophe PLAGNIOL-VILLARD  *    o   SMSC LAN91C96 databook (www.smsc.com)
382439e4bfSJean-Christophe PLAGNIOL-VILLARD  *    o   smc91111.c (u-boot driver)
392439e4bfSJean-Christophe PLAGNIOL-VILLARD  *    o   smc9194.c (linux kernel driver)
402439e4bfSJean-Christophe PLAGNIOL-VILLARD  *    o   lan91c96.c (Intel Diagnostic Manager driver)
412439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
422439e4bfSJean-Christophe PLAGNIOL-VILLARD  * History:
432439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	04/30/03  Mathijs Haarman	Modified smc91111.c (u-boot version)
442439e4bfSJean-Christophe PLAGNIOL-VILLARD  *					for lan91c96
452439e4bfSJean-Christophe PLAGNIOL-VILLARD  *---------------------------------------------------------------------------
462439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
472439e4bfSJean-Christophe PLAGNIOL-VILLARD 
482439e4bfSJean-Christophe PLAGNIOL-VILLARD #include <common.h>
492439e4bfSJean-Christophe PLAGNIOL-VILLARD #include <command.h>
50b7ad4109SNishanth Menon #include <malloc.h>
512439e4bfSJean-Christophe PLAGNIOL-VILLARD #include "lan91c96.h"
522439e4bfSJean-Christophe PLAGNIOL-VILLARD #include <net.h>
53dffc0ae8SAnatolij Gustschin #include <linux/compiler.h>
542439e4bfSJean-Christophe PLAGNIOL-VILLARD 
552439e4bfSJean-Christophe PLAGNIOL-VILLARD /*------------------------------------------------------------------------
562439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
572439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Configuration options, for the experienced user to change.
582439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
592439e4bfSJean-Christophe PLAGNIOL-VILLARD  -------------------------------------------------------------------------*/
602439e4bfSJean-Christophe PLAGNIOL-VILLARD 
612439e4bfSJean-Christophe PLAGNIOL-VILLARD /* Use power-down feature of the chip */
622439e4bfSJean-Christophe PLAGNIOL-VILLARD #define POWER_DOWN	0
632439e4bfSJean-Christophe PLAGNIOL-VILLARD 
642439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
652439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Wait time for memory to be free.  This probably shouldn't be
662439e4bfSJean-Christophe PLAGNIOL-VILLARD  * tuned that much, as waiting for this means nothing else happens
672439e4bfSJean-Christophe PLAGNIOL-VILLARD  * in the system
682439e4bfSJean-Christophe PLAGNIOL-VILLARD */
692439e4bfSJean-Christophe PLAGNIOL-VILLARD #define MEMORY_WAIT_TIME 16
702439e4bfSJean-Christophe PLAGNIOL-VILLARD 
712439e4bfSJean-Christophe PLAGNIOL-VILLARD #define SMC_DEBUG 0
722439e4bfSJean-Christophe PLAGNIOL-VILLARD 
732439e4bfSJean-Christophe PLAGNIOL-VILLARD #if (SMC_DEBUG > 2 )
742439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK3(args...) printf(args)
752439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
762439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK3(args...)
772439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
782439e4bfSJean-Christophe PLAGNIOL-VILLARD 
792439e4bfSJean-Christophe PLAGNIOL-VILLARD #if SMC_DEBUG > 1
802439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK2(args...) printf(args)
812439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
822439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK2(args...)
832439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
842439e4bfSJean-Christophe PLAGNIOL-VILLARD 
852439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef SMC_DEBUG
862439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK(args...) printf(args)
872439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
882439e4bfSJean-Christophe PLAGNIOL-VILLARD #define PRINTK(args...)
892439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
902439e4bfSJean-Christophe PLAGNIOL-VILLARD 
912439e4bfSJean-Christophe PLAGNIOL-VILLARD 
922439e4bfSJean-Christophe PLAGNIOL-VILLARD /*------------------------------------------------------------------------
932439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
942439e4bfSJean-Christophe PLAGNIOL-VILLARD  * The internal workings of the driver.  If you are changing anything
952439e4bfSJean-Christophe PLAGNIOL-VILLARD  * here with the SMC stuff, you should have the datasheet and know
962439e4bfSJean-Christophe PLAGNIOL-VILLARD  * what you are doing.
972439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
982439e4bfSJean-Christophe PLAGNIOL-VILLARD  *------------------------------------------------------------------------
992439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
100b7ad4109SNishanth Menon #define DRIVER_NAME "LAN91C96"
1012439e4bfSJean-Christophe PLAGNIOL-VILLARD #define SMC_ALLOC_MAX_TRY 5
1022439e4bfSJean-Christophe PLAGNIOL-VILLARD #define SMC_TX_TIMEOUT 30
1032439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1042439e4bfSJean-Christophe PLAGNIOL-VILLARD #define ETH_ZLEN 60
1052439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1062439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef  CONFIG_LAN91C96_USE_32_BIT
1072439e4bfSJean-Christophe PLAGNIOL-VILLARD #define USE_32_BIT  1
1082439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
1092439e4bfSJean-Christophe PLAGNIOL-VILLARD #undef USE_32_BIT
1102439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
1112439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1122439e4bfSJean-Christophe PLAGNIOL-VILLARD /* See if a MAC address is defined in the current environment. If so use it. If not
1132439e4bfSJean-Christophe PLAGNIOL-VILLARD  . print a warning and set the environment and other globals with the default.
1142439e4bfSJean-Christophe PLAGNIOL-VILLARD  . If an EEPROM is present it really should be consulted.
1152439e4bfSJean-Christophe PLAGNIOL-VILLARD */
116b7ad4109SNishanth Menon static int smc_get_ethaddr(bd_t *bd, struct eth_device *dev);
117b7ad4109SNishanth Menon static int get_rom_mac(struct eth_device *dev, unsigned char *v_rom_mac);
1182439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1192439e4bfSJean-Christophe PLAGNIOL-VILLARD /* ------------------------------------------------------------
1202439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Internal routines
1212439e4bfSJean-Christophe PLAGNIOL-VILLARD  * ------------------------------------------------------------
1222439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
1232439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1242439e4bfSJean-Christophe PLAGNIOL-VILLARD static unsigned char smc_mac_addr[] = { 0xc0, 0x00, 0x00, 0x1b, 0x62, 0x9c };
1252439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1262439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
1272439e4bfSJean-Christophe PLAGNIOL-VILLARD  * This function must be called before smc_open() if you want to override
1282439e4bfSJean-Christophe PLAGNIOL-VILLARD  * the default mac address.
1292439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
1302439e4bfSJean-Christophe PLAGNIOL-VILLARD 
131b7ad4109SNishanth Menon static void smc_set_mac_addr(const unsigned char *addr)
1322439e4bfSJean-Christophe PLAGNIOL-VILLARD {
1332439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int i;
1342439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1352439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i = 0; i < sizeof (smc_mac_addr); i++) {
1362439e4bfSJean-Christophe PLAGNIOL-VILLARD 		smc_mac_addr[i] = addr[i];
1372439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
1382439e4bfSJean-Christophe PLAGNIOL-VILLARD }
1392439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1402439e4bfSJean-Christophe PLAGNIOL-VILLARD /***********************************************
1412439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Show available memory                       *
1422439e4bfSJean-Christophe PLAGNIOL-VILLARD  ***********************************************/
143b7ad4109SNishanth Menon void dump_memory_info(struct eth_device *dev)
1442439e4bfSJean-Christophe PLAGNIOL-VILLARD {
145dffc0ae8SAnatolij Gustschin 	__maybe_unused word mem_info;
1462439e4bfSJean-Christophe PLAGNIOL-VILLARD 	word old_bank;
1472439e4bfSJean-Christophe PLAGNIOL-VILLARD 
148b7ad4109SNishanth Menon 	old_bank = SMC_inw(dev, LAN91C96_BANK_SELECT) & 0xF;
1492439e4bfSJean-Christophe PLAGNIOL-VILLARD 
150b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 0);
151b7ad4109SNishanth Menon 	mem_info = SMC_inw(dev, LAN91C96_MIR);
1522439e4bfSJean-Christophe PLAGNIOL-VILLARD 	PRINTK2 ("Memory: %4d available\n", (mem_info >> 8) * 2048);
1532439e4bfSJean-Christophe PLAGNIOL-VILLARD 
154b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, old_bank);
1552439e4bfSJean-Christophe PLAGNIOL-VILLARD }
1562439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1572439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
1582439e4bfSJean-Christophe PLAGNIOL-VILLARD  * A rather simple routine to print out a packet for debugging purposes.
1592439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
1602439e4bfSJean-Christophe PLAGNIOL-VILLARD #if SMC_DEBUG > 2
1612439e4bfSJean-Christophe PLAGNIOL-VILLARD static void print_packet (byte *, int);
1622439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
1632439e4bfSJean-Christophe PLAGNIOL-VILLARD 
164b7ad4109SNishanth Menon static int poll4int (struct eth_device *dev, byte mask, int timeout)
1652439e4bfSJean-Christophe PLAGNIOL-VILLARD {
1666d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	int tmo = get_timer (0) + timeout * CONFIG_SYS_HZ;
1672439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int is_timeout = 0;
168b7ad4109SNishanth Menon 	word old_bank = SMC_inw(dev, LAN91C96_BANK_SELECT);
1692439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1702439e4bfSJean-Christophe PLAGNIOL-VILLARD 	PRINTK2 ("Polling...\n");
171b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 2);
172b7ad4109SNishanth Menon 	while ((SMC_inw(dev, LAN91C96_INT_STATS) & mask) == 0) {
1732439e4bfSJean-Christophe PLAGNIOL-VILLARD 		if (get_timer (0) >= tmo) {
1742439e4bfSJean-Christophe PLAGNIOL-VILLARD 			is_timeout = 1;
1752439e4bfSJean-Christophe PLAGNIOL-VILLARD 			break;
1762439e4bfSJean-Christophe PLAGNIOL-VILLARD 		}
1772439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
1782439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1792439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* restore old bank selection */
180b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, old_bank);
1812439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1822439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (is_timeout)
1832439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 1;
1842439e4bfSJean-Christophe PLAGNIOL-VILLARD 	else
1852439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
1862439e4bfSJean-Christophe PLAGNIOL-VILLARD }
1872439e4bfSJean-Christophe PLAGNIOL-VILLARD 
1882439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
189b7ad4109SNishanth Menon  * Function: smc_reset
1902439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Purpose:
1912439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	This sets the SMC91111 chip to its normal state, hopefully from whatever
1922439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	mess that any other DOS driver has put it in.
1932439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
1942439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Maybe I should reset more registers to defaults in here?  SOFTRST  should
1952439e4bfSJean-Christophe PLAGNIOL-VILLARD  * do that for me.
1962439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
1972439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Method:
1982439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	1.  send a SOFT RESET
1992439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	2.  wait for it to finish
2002439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	3.  enable autorelease mode
2012439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	4.  reset the memory management unit
2022439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	5.  clear all interrupts
2032439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
2042439e4bfSJean-Christophe PLAGNIOL-VILLARD */
205b7ad4109SNishanth Menon static void smc_reset(struct eth_device *dev)
2062439e4bfSJean-Christophe PLAGNIOL-VILLARD {
207b7ad4109SNishanth Menon 	PRINTK2("%s:smc_reset\n", dev->name);
2082439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2092439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* This resets the registers mostly to defaults, but doesn't
2102439e4bfSJean-Christophe PLAGNIOL-VILLARD 	   affect EEPROM.  That seems unnecessary */
211b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 0);
212b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_RCR_SOFT_RST, LAN91C96_RCR);
2132439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2142439e4bfSJean-Christophe PLAGNIOL-VILLARD 	udelay (10);
2152439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2162439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Disable transmit and receive functionality */
217b7ad4109SNishanth Menon 	SMC_outw(dev, 0, LAN91C96_RCR);
218b7ad4109SNishanth Menon 	SMC_outw(dev, 0, LAN91C96_TCR);
2192439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2202439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* set the control register */
221b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 1);
222b7ad4109SNishanth Menon 	SMC_outw(dev, SMC_inw(dev, LAN91C96_CONTROL) | LAN91C96_CTR_BIT_8,
2232439e4bfSJean-Christophe PLAGNIOL-VILLARD 			  LAN91C96_CONTROL);
2242439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2252439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Disable all interrupts */
226b7ad4109SNishanth Menon 	SMC_outb(dev, 0, LAN91C96_INT_MASK);
2272439e4bfSJean-Christophe PLAGNIOL-VILLARD }
2282439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2292439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
2302439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Function: smc_enable
2312439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Purpose: let the chip talk to the outside work
2322439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Method:
2332439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	1.  Initialize the Memory Configuration Register
2342439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	2.  Enable the transmitter
2352439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	3.  Enable the receiver
2362439e4bfSJean-Christophe PLAGNIOL-VILLARD */
237b7ad4109SNishanth Menon static void smc_enable(struct eth_device *dev)
2382439e4bfSJean-Christophe PLAGNIOL-VILLARD {
239b7ad4109SNishanth Menon 	PRINTK2("%s:smc_enable\n", dev->name);
240b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 0);
2412439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2422439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Initialize the Memory Configuration Register. See page
2432439e4bfSJean-Christophe PLAGNIOL-VILLARD 	   49 of the LAN91C96 data sheet for details. */
244b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_MCR_TRANSMIT_PAGES, LAN91C96_MCR);
2452439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2462439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Initialize the Transmit Control Register */
247b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_TCR_TXENA, LAN91C96_TCR);
2482439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Initialize the Receive Control Register
2492439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * FIXME:
2502439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * The promiscuous bit set because I could not receive ARP reply
2512439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * packets from the server when I send a ARP request. It only works
2522439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * when I set the promiscuous bit
2532439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 */
254b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_RCR_RXEN | LAN91C96_RCR_PRMS, LAN91C96_RCR);
2552439e4bfSJean-Christophe PLAGNIOL-VILLARD }
2562439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2572439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
2582439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Function: smc_shutdown
2592439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Purpose:  closes down the SMC91xxx chip.
2602439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Method:
2612439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	1. zero the interrupt mask
2622439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	2. clear the enable receive flag
2632439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	3. clear the enable xmit flags
2642439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
2652439e4bfSJean-Christophe PLAGNIOL-VILLARD  * TODO:
2662439e4bfSJean-Christophe PLAGNIOL-VILLARD  *   (1) maybe utilize power down mode.
2672439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Why not yet?  Because while the chip will go into power down mode,
2682439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	the manual says that it will wake up in response to any I/O requests
2692439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	in the register space.   Empirical results do not show this working.
2702439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
271b7ad4109SNishanth Menon static void smc_shutdown(struct eth_device *dev)
2722439e4bfSJean-Christophe PLAGNIOL-VILLARD {
273b7ad4109SNishanth Menon 	PRINTK2("%s:smc_shutdown\n", dev->name);
2742439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2752439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* no more interrupts for me */
276b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 2);
277b7ad4109SNishanth Menon 	SMC_outb(dev, 0, LAN91C96_INT_MASK);
2782439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2792439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* and tell the card to stay away from that nasty outside world */
280b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 0);
281b7ad4109SNishanth Menon 	SMC_outb(dev, 0, LAN91C96_RCR);
282b7ad4109SNishanth Menon 	SMC_outb(dev, 0, LAN91C96_TCR);
2832439e4bfSJean-Christophe PLAGNIOL-VILLARD }
2842439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2852439e4bfSJean-Christophe PLAGNIOL-VILLARD 
2862439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
2872439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Function:  smc_hardware_send_packet(struct net_device * )
2882439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Purpose:
2892439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	This sends the actual packet to the SMC9xxx chip.
2902439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
2912439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Algorithm:
2922439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	First, see if a saved_skb is available.
2932439e4bfSJean-Christophe PLAGNIOL-VILLARD  *		( this should NOT be called if there is no 'saved_skb'
2942439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Now, find the packet number that the chip allocated
2952439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Point the data pointers at it in memory
2962439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Set the length word in the chip's memory
2972439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Dump the packet to chip memory
2982439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Check if a last byte is needed ( odd length packet )
2992439e4bfSJean-Christophe PLAGNIOL-VILLARD  *		if so, set the control flag right
3002439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Tell the card to send it
3012439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Enable the transmit interrupt, so I know if it failed
3022439e4bfSJean-Christophe PLAGNIOL-VILLARD  *	Free the kernel data if I actually sent it.
3032439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
30430934b3eSJoe Hershberger static int smc_send_packet(struct eth_device *dev, void *packet,
305b7ad4109SNishanth Menon 		int packet_length)
3062439e4bfSJean-Christophe PLAGNIOL-VILLARD {
3072439e4bfSJean-Christophe PLAGNIOL-VILLARD 	byte packet_no;
3082439e4bfSJean-Christophe PLAGNIOL-VILLARD 	byte *buf;
3092439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int length;
3102439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int numPages;
3112439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int try = 0;
3122439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int time_out;
3132439e4bfSJean-Christophe PLAGNIOL-VILLARD 	byte status;
3142439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3152439e4bfSJean-Christophe PLAGNIOL-VILLARD 
316b7ad4109SNishanth Menon 	PRINTK3("%s:smc_hardware_send_packet\n", dev->name);
3172439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3182439e4bfSJean-Christophe PLAGNIOL-VILLARD 	length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN;
3192439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3202439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* allocate memory
3212439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** The MMU wants the number of pages to be the number of 256 bytes
3222439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
3232439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 **
3242439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** The 91C111 ignores the size bits, but the code is left intact
3252439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** for backwards and future compatibility.
3262439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 **
3272439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** Pkt size for allocating is data length +6 (for additional status
3282439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** words, length and ctl!)
3292439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 **
3302439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 ** If odd size then last byte is included in this header.
3312439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 */
3322439e4bfSJean-Christophe PLAGNIOL-VILLARD 	numPages = ((length & 0xfffe) + 6);
3332439e4bfSJean-Christophe PLAGNIOL-VILLARD 	numPages >>= 8;				/* Divide by 256 */
3342439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3352439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (numPages > 7) {
336b7ad4109SNishanth Menon 		printf("%s: Far too big packet error. \n", dev->name);
3372439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
3382439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
3392439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3402439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* now, try to allocate the memory */
3412439e4bfSJean-Christophe PLAGNIOL-VILLARD 
342b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 2);
343b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_MMUCR_ALLOC_TX | numPages, LAN91C96_MMU);
3442439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3452439e4bfSJean-Christophe PLAGNIOL-VILLARD   again:
3462439e4bfSJean-Christophe PLAGNIOL-VILLARD 	try++;
3472439e4bfSJean-Christophe PLAGNIOL-VILLARD 	time_out = MEMORY_WAIT_TIME;
3482439e4bfSJean-Christophe PLAGNIOL-VILLARD 	do {
349b7ad4109SNishanth Menon 		status = SMC_inb(dev, LAN91C96_INT_STATS);
3502439e4bfSJean-Christophe PLAGNIOL-VILLARD 		if (status & LAN91C96_IST_ALLOC_INT) {
3512439e4bfSJean-Christophe PLAGNIOL-VILLARD 
352b7ad4109SNishanth Menon 			SMC_outb(dev, LAN91C96_IST_ALLOC_INT,
353b7ad4109SNishanth Menon 					LAN91C96_INT_STATS);
3542439e4bfSJean-Christophe PLAGNIOL-VILLARD 			break;
3552439e4bfSJean-Christophe PLAGNIOL-VILLARD 		}
3562439e4bfSJean-Christophe PLAGNIOL-VILLARD 	} while (--time_out);
3572439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3582439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (!time_out) {
3592439e4bfSJean-Christophe PLAGNIOL-VILLARD 		PRINTK2 ("%s: memory allocation, try %d failed ...\n",
360b7ad4109SNishanth Menon 				 dev->name, try);
3612439e4bfSJean-Christophe PLAGNIOL-VILLARD 		if (try < SMC_ALLOC_MAX_TRY)
3622439e4bfSJean-Christophe PLAGNIOL-VILLARD 			goto again;
3632439e4bfSJean-Christophe PLAGNIOL-VILLARD 		else
3642439e4bfSJean-Christophe PLAGNIOL-VILLARD 			return 0;
3652439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
3662439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3672439e4bfSJean-Christophe PLAGNIOL-VILLARD 	PRINTK2 ("%s: memory allocation, try %d succeeded ...\n",
368b7ad4109SNishanth Menon 			 dev->name, try);
3692439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3702439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* I can send the packet now.. */
3712439e4bfSJean-Christophe PLAGNIOL-VILLARD 	buf = (byte *) packet;
3722439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3732439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* If I get here, I _know_ there is a packet slot waiting for me */
374b7ad4109SNishanth Menon 	packet_no = SMC_inb(dev, LAN91C96_ARR);
3752439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (packet_no & LAN91C96_ARR_FAILED) {
3762439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* or isn't there?  BAD CHIP! */
377b7ad4109SNishanth Menon 		printf("%s: Memory allocation failed. \n", dev->name);
3782439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
3792439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
3802439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3812439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* we have a packet address, so tell the card to use it */
382b7ad4109SNishanth Menon 	SMC_outb(dev, packet_no, LAN91C96_PNR);
3832439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3842439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* point to the beginning of the packet */
385b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);
3862439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3872439e4bfSJean-Christophe PLAGNIOL-VILLARD 	PRINTK3("%s: Trying to xmit packet of length %x\n",
388b7ad4109SNishanth Menon 			 dev->name, length);
3892439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3902439e4bfSJean-Christophe PLAGNIOL-VILLARD #if SMC_DEBUG > 2
3912439e4bfSJean-Christophe PLAGNIOL-VILLARD 	printf ("Transmitting Packet\n");
3922439e4bfSJean-Christophe PLAGNIOL-VILLARD 	print_packet (buf, length);
3932439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
3942439e4bfSJean-Christophe PLAGNIOL-VILLARD 
3952439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* send the packet length ( +6 for status, length and ctl byte )
3962439e4bfSJean-Christophe PLAGNIOL-VILLARD 	   and the status word ( set to zeros ) */
3972439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
398b7ad4109SNishanth Menon 	SMC_outl(dev, (length + 6) << 16, LAN91C96_DATA_HIGH);
3992439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
400b7ad4109SNishanth Menon 	SMC_outw(dev, 0, LAN91C96_DATA_HIGH);
4012439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* send the packet length ( +6 for status words, length, and ctl */
402b7ad4109SNishanth Menon 	SMC_outw(dev, (length + 6), LAN91C96_DATA_HIGH);
4032439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif /* USE_32_BIT */
4042439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4052439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* send the actual data
4062439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * I _think_ it's faster to send the longs first, and then
4072439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * mop up by sending the last word.  It depends heavily
4082439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * on alignment, at least on the 486.  Maybe it would be
4092439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * a good idea to check which is optimal?  But that could take
4102439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 * almost as much time as is saved?
4112439e4bfSJean-Christophe PLAGNIOL-VILLARD 	 */
4122439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
413b7ad4109SNishanth Menon 	SMC_outsl(dev, LAN91C96_DATA_HIGH, buf, length >> 2);
4142439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (length & 0x2)
415b7ad4109SNishanth Menon 		SMC_outw(dev, *((word *) (buf + (length & 0xFFFFFFFC))),
4162439e4bfSJean-Christophe PLAGNIOL-VILLARD 				  LAN91C96_DATA_HIGH);
4172439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
418b7ad4109SNishanth Menon 	SMC_outsw(dev, LAN91C96_DATA_HIGH, buf, (length) >> 1);
4192439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif /* USE_32_BIT */
4202439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4212439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* Send the last byte, if there is one.   */
4222439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if ((length & 1) == 0) {
423b7ad4109SNishanth Menon 		SMC_outw(dev, 0, LAN91C96_DATA_HIGH);
4242439e4bfSJean-Christophe PLAGNIOL-VILLARD 	} else {
425b7ad4109SNishanth Menon 		SMC_outw(dev, buf[length - 1] | 0x2000, LAN91C96_DATA_HIGH);
4262439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
4272439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4282439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* and let the chipset deal with it */
429b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_MMUCR_ENQUEUE, LAN91C96_MMU);
4302439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4312439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* poll for TX INT */
432b7ad4109SNishanth Menon 	if (poll4int (dev, LAN91C96_MSK_TX_INT, SMC_TX_TIMEOUT)) {
4332439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* sending failed */
434b7ad4109SNishanth Menon 		PRINTK2("%s: TX timeout, sending failed...\n", dev->name);
4352439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4362439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* release packet */
437b7ad4109SNishanth Menon 		SMC_outw(dev, LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);
4382439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4392439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* wait for MMU getting ready (low) */
440b7ad4109SNishanth Menon 		while (SMC_inw(dev, LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
4412439e4bfSJean-Christophe PLAGNIOL-VILLARD 			udelay (10);
4422439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4432439e4bfSJean-Christophe PLAGNIOL-VILLARD 		PRINTK2("MMU ready\n");
4442439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4452439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4462439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
4472439e4bfSJean-Christophe PLAGNIOL-VILLARD 	} else {
4482439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* ack. int */
449b7ad4109SNishanth Menon 		SMC_outw(dev, LAN91C96_IST_TX_INT, LAN91C96_INT_STATS);
4502439e4bfSJean-Christophe PLAGNIOL-VILLARD 
451b7ad4109SNishanth Menon 		PRINTK2("%s: Sent packet of length %d \n", dev->name, length);
4522439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4532439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* release packet */
454b7ad4109SNishanth Menon 		SMC_outw(dev, LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);
4552439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4562439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* wait for MMU getting ready (low) */
457b7ad4109SNishanth Menon 		while (SMC_inw(dev, LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
4582439e4bfSJean-Christophe PLAGNIOL-VILLARD 			udelay (10);
4592439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4602439e4bfSJean-Christophe PLAGNIOL-VILLARD 		PRINTK2 ("MMU ready\n");
4612439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
4622439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4632439e4bfSJean-Christophe PLAGNIOL-VILLARD 	return length;
4642439e4bfSJean-Christophe PLAGNIOL-VILLARD }
4652439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4662439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4672439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
4682439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Open and Initialize the board
4692439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
4702439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Set up everything, reset the card, etc ..
4712439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
4722439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
473b7ad4109SNishanth Menon static int smc_open(bd_t *bd, struct eth_device *dev)
4742439e4bfSJean-Christophe PLAGNIOL-VILLARD {
4752439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int i, err;			/* used to set hw ethernet address */
4762439e4bfSJean-Christophe PLAGNIOL-VILLARD 
477b7ad4109SNishanth Menon 	PRINTK2("%s:smc_open\n", dev->name);
4782439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4792439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* reset the hardware */
4802439e4bfSJean-Christophe PLAGNIOL-VILLARD 
481b7ad4109SNishanth Menon 	smc_reset(dev);
482b7ad4109SNishanth Menon 	smc_enable(dev);
4832439e4bfSJean-Christophe PLAGNIOL-VILLARD 
484b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 1);
485b7ad4109SNishanth Menon 	/* set smc_mac_addr, and sync it with u-boot globals */
486b7ad4109SNishanth Menon 	err = smc_get_ethaddr(bd, dev);
48703f3d8d3SMike Frysinger 	if (err < 0)
48803f3d8d3SMike Frysinger 		return -1;
4892439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
4902439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i = 0; i < 6; i += 2) {
4912439e4bfSJean-Christophe PLAGNIOL-VILLARD 		word address;
4922439e4bfSJean-Christophe PLAGNIOL-VILLARD 
4932439e4bfSJean-Christophe PLAGNIOL-VILLARD 		address = smc_mac_addr[i + 1] << 8;
4942439e4bfSJean-Christophe PLAGNIOL-VILLARD 		address |= smc_mac_addr[i];
495b7ad4109SNishanth Menon 		SMC_outw(dev, address, LAN91C96_IA0 + i);
4962439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
4972439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
4982439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i = 0; i < 6; i++)
499b7ad4109SNishanth Menon 		SMC_outb(dev, smc_mac_addr[i], LAN91C96_IA0 + i);
5002439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
5012439e4bfSJean-Christophe PLAGNIOL-VILLARD 	return 0;
5022439e4bfSJean-Christophe PLAGNIOL-VILLARD }
5032439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5042439e4bfSJean-Christophe PLAGNIOL-VILLARD /*-------------------------------------------------------------
5052439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
5062439e4bfSJean-Christophe PLAGNIOL-VILLARD  * smc_rcv -  receive a packet from the card
5072439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
5082439e4bfSJean-Christophe PLAGNIOL-VILLARD  * There is ( at least ) a packet waiting to be read from
5092439e4bfSJean-Christophe PLAGNIOL-VILLARD  * chip-memory.
5102439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
5112439e4bfSJean-Christophe PLAGNIOL-VILLARD  * o Read the status
5122439e4bfSJean-Christophe PLAGNIOL-VILLARD  * o If an error, record it
5132439e4bfSJean-Christophe PLAGNIOL-VILLARD  * o otherwise, read in the packet
5142439e4bfSJean-Christophe PLAGNIOL-VILLARD  *-------------------------------------------------------------
5152439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
516b7ad4109SNishanth Menon static int smc_rcv(struct eth_device *dev)
5172439e4bfSJean-Christophe PLAGNIOL-VILLARD {
5182439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int packet_number;
5192439e4bfSJean-Christophe PLAGNIOL-VILLARD 	word status;
5202439e4bfSJean-Christophe PLAGNIOL-VILLARD 	word packet_length;
5212439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int is_error = 0;
5222439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5232439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
5242439e4bfSJean-Christophe PLAGNIOL-VILLARD 	dword stat_len;
5252439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
5262439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5272439e4bfSJean-Christophe PLAGNIOL-VILLARD 
528b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 2);
529b7ad4109SNishanth Menon 	packet_number = SMC_inw(dev, LAN91C96_FIFO);
5302439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5312439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (packet_number & LAN91C96_FIFO_RXEMPTY) {
5322439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
5332439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
5342439e4bfSJean-Christophe PLAGNIOL-VILLARD 
535b7ad4109SNishanth Menon 	PRINTK3("%s:smc_rcv\n", dev->name);
5362439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/*  start reading from the start of the packet */
537b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_PTR_READ | LAN91C96_PTR_RCV |
5382439e4bfSJean-Christophe PLAGNIOL-VILLARD 			  LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);
5392439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5402439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* First two words are status and packet_length */
5412439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
542b7ad4109SNishanth Menon 	stat_len = SMC_inl(dev, LAN91C96_DATA_HIGH);
5432439e4bfSJean-Christophe PLAGNIOL-VILLARD 	status = stat_len & 0xffff;
5442439e4bfSJean-Christophe PLAGNIOL-VILLARD 	packet_length = stat_len >> 16;
5452439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
546b7ad4109SNishanth Menon 	status = SMC_inw(dev, LAN91C96_DATA_HIGH);
547b7ad4109SNishanth Menon 	packet_length = SMC_inw(dev, LAN91C96_DATA_HIGH);
5482439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
5492439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5502439e4bfSJean-Christophe PLAGNIOL-VILLARD 	packet_length &= 0x07ff;	/* mask off top bits */
5512439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5522439e4bfSJean-Christophe PLAGNIOL-VILLARD 	PRINTK2 ("RCV: STATUS %4x LENGTH %4x\n", status, packet_length);
5532439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5542439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (!(status & FRAME_FILTER)) {
5552439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* Adjust for having already read the first two words */
5562439e4bfSJean-Christophe PLAGNIOL-VILLARD 		packet_length -= 4;		/*4; */
5572439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5582439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5592439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* set odd length for bug in LAN91C111, */
5602439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* which never sets RS_ODDFRAME */
5612439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* TODO ? */
5622439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5632439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5642439e4bfSJean-Christophe PLAGNIOL-VILLARD #ifdef USE_32_BIT
5652439e4bfSJean-Christophe PLAGNIOL-VILLARD 		PRINTK3 (" Reading %d dwords (and %d bytes) \n",
5662439e4bfSJean-Christophe PLAGNIOL-VILLARD 			 packet_length >> 2, packet_length & 3);
5672439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* QUESTION:  Like in the TX routine, do I want
5682439e4bfSJean-Christophe PLAGNIOL-VILLARD 		   to send the DWORDs or the bytes first, or some
5692439e4bfSJean-Christophe PLAGNIOL-VILLARD 		   mixture.  A mixture might improve already slow PIO
5702439e4bfSJean-Christophe PLAGNIOL-VILLARD 		   performance  */
5711fd92db8SJoe Hershberger 		SMC_insl(dev, LAN91C96_DATA_HIGH, net_rx_packets[0],
572b7ad4109SNishanth Menon 			 packet_length >> 2);
5732439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* read the left over bytes */
5742439e4bfSJean-Christophe PLAGNIOL-VILLARD 		if (packet_length & 3) {
5752439e4bfSJean-Christophe PLAGNIOL-VILLARD 			int i;
5762439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5771fd92db8SJoe Hershberger 			byte *tail = (byte *)(net_rx_packets[0] +
5781fd92db8SJoe Hershberger 				(packet_length & ~3));
579b7ad4109SNishanth Menon 			dword leftover = SMC_inl(dev, LAN91C96_DATA_HIGH);
5802439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5812439e4bfSJean-Christophe PLAGNIOL-VILLARD 			for (i = 0; i < (packet_length & 3); i++)
5822439e4bfSJean-Christophe PLAGNIOL-VILLARD 				*tail++ = (byte) (leftover >> (8 * i)) & 0xff;
5832439e4bfSJean-Christophe PLAGNIOL-VILLARD 		}
5842439e4bfSJean-Christophe PLAGNIOL-VILLARD #else
5852439e4bfSJean-Christophe PLAGNIOL-VILLARD 		PRINTK3(" Reading %d words and %d byte(s)\n",
5862439e4bfSJean-Christophe PLAGNIOL-VILLARD 			(packet_length >> 1), packet_length & 1);
5871fd92db8SJoe Hershberger 		SMC_insw(dev, LAN91C96_DATA_HIGH, net_rx_packets[0],
588b7ad4109SNishanth Menon 			 packet_length >> 1);
5892439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5902439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif /* USE_32_BIT */
5912439e4bfSJean-Christophe PLAGNIOL-VILLARD 
5922439e4bfSJean-Christophe PLAGNIOL-VILLARD #if	SMC_DEBUG > 2
5932439e4bfSJean-Christophe PLAGNIOL-VILLARD 		printf ("Receiving Packet\n");
5941fd92db8SJoe Hershberger 		print_packet((byte *)net_rx_packets[0], packet_length);
5952439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif
5962439e4bfSJean-Christophe PLAGNIOL-VILLARD 	} else {
5972439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* error ... */
5982439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* TODO ? */
5992439e4bfSJean-Christophe PLAGNIOL-VILLARD 		is_error = 1;
6002439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
6012439e4bfSJean-Christophe PLAGNIOL-VILLARD 
602b7ad4109SNishanth Menon 	while (SMC_inw(dev, LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
6032439e4bfSJean-Christophe PLAGNIOL-VILLARD 		udelay (1);		/* Wait until not busy */
6042439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6052439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/*  error or good, tell the card to get rid of this packet */
606b7ad4109SNishanth Menon 	SMC_outw(dev, LAN91C96_MMUCR_RELEASE_RX, LAN91C96_MMU);
6072439e4bfSJean-Christophe PLAGNIOL-VILLARD 
608b7ad4109SNishanth Menon 	while (SMC_inw(dev, LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
6092439e4bfSJean-Christophe PLAGNIOL-VILLARD 		udelay (1);		/* Wait until not busy */
6102439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6112439e4bfSJean-Christophe PLAGNIOL-VILLARD 	if (!is_error) {
6122439e4bfSJean-Christophe PLAGNIOL-VILLARD 		/* Pass the packet up to the protocol layers. */
6131fd92db8SJoe Hershberger 		net_process_received_packet(net_rx_packets[0], packet_length);
6142439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return packet_length;
6152439e4bfSJean-Christophe PLAGNIOL-VILLARD 	} else {
6162439e4bfSJean-Christophe PLAGNIOL-VILLARD 		return 0;
6172439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
6182439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6192439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6202439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6212439e4bfSJean-Christophe PLAGNIOL-VILLARD /*----------------------------------------------------
6222439e4bfSJean-Christophe PLAGNIOL-VILLARD  * smc_close
6232439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
6242439e4bfSJean-Christophe PLAGNIOL-VILLARD  * this makes the board clean up everything that it can
6252439e4bfSJean-Christophe PLAGNIOL-VILLARD  * and not talk to the outside world.   Caused by
6262439e4bfSJean-Christophe PLAGNIOL-VILLARD  * an 'ifconfig ethX down'
6272439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
6282439e4bfSJean-Christophe PLAGNIOL-VILLARD  -----------------------------------------------------*/
629b7ad4109SNishanth Menon static int smc_close(struct eth_device *dev)
6302439e4bfSJean-Christophe PLAGNIOL-VILLARD {
631b7ad4109SNishanth Menon 	PRINTK2("%s:smc_close\n", dev->name);
6322439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6332439e4bfSJean-Christophe PLAGNIOL-VILLARD 	/* clear everything */
634b7ad4109SNishanth Menon 	smc_shutdown(dev);
6352439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6362439e4bfSJean-Christophe PLAGNIOL-VILLARD 	return 0;
6372439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6382439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6392439e4bfSJean-Christophe PLAGNIOL-VILLARD #if SMC_DEBUG > 2
6402439e4bfSJean-Christophe PLAGNIOL-VILLARD static void print_packet(byte *buf, int length)
6412439e4bfSJean-Christophe PLAGNIOL-VILLARD {
6422439e4bfSJean-Christophe PLAGNIOL-VILLARD #if 0
6432439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int i;
6442439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int remainder;
6452439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int lines;
6462439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6472439e4bfSJean-Christophe PLAGNIOL-VILLARD 	printf ("Packet of length %d \n", length);
6482439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6492439e4bfSJean-Christophe PLAGNIOL-VILLARD 	lines = length / 16;
6502439e4bfSJean-Christophe PLAGNIOL-VILLARD 	remainder = length % 16;
6512439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6522439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i = 0; i < lines; i++) {
6532439e4bfSJean-Christophe PLAGNIOL-VILLARD 		int cur;
6542439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6552439e4bfSJean-Christophe PLAGNIOL-VILLARD 		for (cur = 0; cur < 8; cur++) {
6562439e4bfSJean-Christophe PLAGNIOL-VILLARD 			byte a, b;
6572439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6582439e4bfSJean-Christophe PLAGNIOL-VILLARD 			a = *(buf++);
6592439e4bfSJean-Christophe PLAGNIOL-VILLARD 			b = *(buf++);
6602439e4bfSJean-Christophe PLAGNIOL-VILLARD 			printf ("%02x%02x ", a, b);
6612439e4bfSJean-Christophe PLAGNIOL-VILLARD 		}
6622439e4bfSJean-Christophe PLAGNIOL-VILLARD 		printf ("\n");
6632439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
6642439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i = 0; i < remainder / 2; i++) {
6652439e4bfSJean-Christophe PLAGNIOL-VILLARD 		byte a, b;
6662439e4bfSJean-Christophe PLAGNIOL-VILLARD 
6672439e4bfSJean-Christophe PLAGNIOL-VILLARD 		a = *(buf++);
6682439e4bfSJean-Christophe PLAGNIOL-VILLARD 		b = *(buf++);
6692439e4bfSJean-Christophe PLAGNIOL-VILLARD 		printf ("%02x%02x ", a, b);
6702439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
6712439e4bfSJean-Christophe PLAGNIOL-VILLARD 	printf ("\n");
6722439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif /* 0 */
6732439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6742439e4bfSJean-Christophe PLAGNIOL-VILLARD #endif /* SMC_DEBUG > 2 */
6752439e4bfSJean-Christophe PLAGNIOL-VILLARD 
676b7ad4109SNishanth Menon static int  lan91c96_init(struct eth_device *dev, bd_t *bd)
6772439e4bfSJean-Christophe PLAGNIOL-VILLARD {
678b7ad4109SNishanth Menon 	return smc_open(bd, dev);
6792439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6802439e4bfSJean-Christophe PLAGNIOL-VILLARD 
681b7ad4109SNishanth Menon static void lan91c96_halt(struct eth_device *dev)
6822439e4bfSJean-Christophe PLAGNIOL-VILLARD {
683b7ad4109SNishanth Menon 	smc_close(dev);
6842439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6852439e4bfSJean-Christophe PLAGNIOL-VILLARD 
686b7ad4109SNishanth Menon static int lan91c96_recv(struct eth_device *dev)
6872439e4bfSJean-Christophe PLAGNIOL-VILLARD {
688b7ad4109SNishanth Menon 	return smc_rcv(dev);
6892439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6902439e4bfSJean-Christophe PLAGNIOL-VILLARD 
69130934b3eSJoe Hershberger static int lan91c96_send(struct eth_device *dev, void *packet,
692b7ad4109SNishanth Menon 		int length)
6932439e4bfSJean-Christophe PLAGNIOL-VILLARD {
694b7ad4109SNishanth Menon 	return smc_send_packet(dev, packet, length);
6952439e4bfSJean-Christophe PLAGNIOL-VILLARD }
6962439e4bfSJean-Christophe PLAGNIOL-VILLARD 
697b7ad4109SNishanth Menon /* smc_get_ethaddr
6982439e4bfSJean-Christophe PLAGNIOL-VILLARD  *
6992439e4bfSJean-Christophe PLAGNIOL-VILLARD  * This checks both the environment and the ROM for an ethernet address. If
7002439e4bfSJean-Christophe PLAGNIOL-VILLARD  * found, the environment takes precedence.
7012439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
7022439e4bfSJean-Christophe PLAGNIOL-VILLARD 
703b7ad4109SNishanth Menon static int smc_get_ethaddr(bd_t *bd, struct eth_device *dev)
7042439e4bfSJean-Christophe PLAGNIOL-VILLARD {
70503f3d8d3SMike Frysinger 	uchar v_mac[6];
7062439e4bfSJean-Christophe PLAGNIOL-VILLARD 
70703f3d8d3SMike Frysinger 	if (!eth_getenv_enetaddr("ethaddr", v_mac)) {
70803f3d8d3SMike Frysinger 		/* get ROM mac value if any */
709b7ad4109SNishanth Menon 		if (!get_rom_mac(dev, v_mac)) {
7102439e4bfSJean-Christophe PLAGNIOL-VILLARD 			printf("\n*** ERROR: ethaddr is NOT set !!\n");
71103f3d8d3SMike Frysinger 			return -1;
7122439e4bfSJean-Christophe PLAGNIOL-VILLARD 		}
71303f3d8d3SMike Frysinger 		eth_setenv_enetaddr("ethaddr", v_mac);
7142439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
7152439e4bfSJean-Christophe PLAGNIOL-VILLARD 
71603f3d8d3SMike Frysinger 	smc_set_mac_addr(v_mac); /* use old function to update smc default */
71703f3d8d3SMike Frysinger 	PRINTK("Using MAC Address %pM\n", v_mac);
71803f3d8d3SMike Frysinger 	return 0;
7192439e4bfSJean-Christophe PLAGNIOL-VILLARD }
7202439e4bfSJean-Christophe PLAGNIOL-VILLARD 
7212439e4bfSJean-Christophe PLAGNIOL-VILLARD /*
7222439e4bfSJean-Christophe PLAGNIOL-VILLARD  * get_rom_mac()
7232439e4bfSJean-Christophe PLAGNIOL-VILLARD  * Note, this has omly been tested for the OMAP730 P2.
7242439e4bfSJean-Christophe PLAGNIOL-VILLARD  */
7252439e4bfSJean-Christophe PLAGNIOL-VILLARD 
726b7ad4109SNishanth Menon static int get_rom_mac(struct eth_device *dev, unsigned char *v_rom_mac)
7272439e4bfSJean-Christophe PLAGNIOL-VILLARD {
7282439e4bfSJean-Christophe PLAGNIOL-VILLARD 	int i;
729b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 1);
7302439e4bfSJean-Christophe PLAGNIOL-VILLARD 	for (i=0; i<6; i++)
7312439e4bfSJean-Christophe PLAGNIOL-VILLARD 	{
732b7ad4109SNishanth Menon 		v_rom_mac[i] = SMC_inb(dev, LAN91C96_IA0 + i);
7332439e4bfSJean-Christophe PLAGNIOL-VILLARD 	}
7342439e4bfSJean-Christophe PLAGNIOL-VILLARD 	return (1);
7352439e4bfSJean-Christophe PLAGNIOL-VILLARD }
736b7ad4109SNishanth Menon 
737b7ad4109SNishanth Menon /* Structure to detect the device IDs */
738b7ad4109SNishanth Menon struct id_type {
739b7ad4109SNishanth Menon 	u8 id;
740b7ad4109SNishanth Menon 	char *name;
741b7ad4109SNishanth Menon };
742b7ad4109SNishanth Menon static struct id_type supported_chips[] = {
743b7ad4109SNishanth Menon 	{0, ""}, /* Dummy entry to prevent id check failure */
744b7ad4109SNishanth Menon 	{9, "LAN91C110"},
745b7ad4109SNishanth Menon 	{8, "LAN91C100FD"},
746b7ad4109SNishanth Menon 	{7, "LAN91C100"},
747b7ad4109SNishanth Menon 	{5, "LAN91C95"},
7480e7790d4SYanjun Yang 	{4, "LAN91C94/96"},
7490e7790d4SYanjun Yang 	{3, "LAN91C90/92"},
750b7ad4109SNishanth Menon };
751b7ad4109SNishanth Menon /* lan91c96_detect_chip
752b7ad4109SNishanth Menon  * See:
753b7ad4109SNishanth Menon  * http://www.embeddedsys.com/subpages/resources/images/documents/LAN91C96_datasheet.pdf
754b7ad4109SNishanth Menon  * page 71 - that is the closest we get to detect this device
755b7ad4109SNishanth Menon  */
756b7ad4109SNishanth Menon static int lan91c96_detect_chip(struct eth_device *dev)
757b7ad4109SNishanth Menon {
758b7ad4109SNishanth Menon 	u8 chip_id;
759b7ad4109SNishanth Menon 	int r;
760b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 3);
76116721715SYanjun Yang 	chip_id = (SMC_inw(dev, 0xA) & LAN91C96_REV_CHIPID) >> 4;
762b7ad4109SNishanth Menon 	SMC_SELECT_BANK(dev, 0);
763a62cd29cSAxel Lin 	for (r = 0; r < ARRAY_SIZE(supported_chips); r++)
764b7ad4109SNishanth Menon 		if (chip_id == supported_chips[r].id)
765b7ad4109SNishanth Menon 			return r;
766b7ad4109SNishanth Menon 	return 0;
767b7ad4109SNishanth Menon }
768b7ad4109SNishanth Menon 
769b7ad4109SNishanth Menon int lan91c96_initialize(u8 dev_num, int base_addr)
770b7ad4109SNishanth Menon {
771b7ad4109SNishanth Menon 	struct eth_device *dev;
772b7ad4109SNishanth Menon 	int r = 0;
773b7ad4109SNishanth Menon 
774b7ad4109SNishanth Menon 	dev = malloc(sizeof(*dev));
775b7ad4109SNishanth Menon 	if (!dev) {
776b7ad4109SNishanth Menon 		return 0;
777b7ad4109SNishanth Menon 	}
778b7ad4109SNishanth Menon 	memset(dev, 0, sizeof(*dev));
779b7ad4109SNishanth Menon 
780b7ad4109SNishanth Menon 	dev->iobase = base_addr;
781b7ad4109SNishanth Menon 
782b7ad4109SNishanth Menon 	/* Try to detect chip. Will fail if not present. */
783b7ad4109SNishanth Menon 	r = lan91c96_detect_chip(dev);
784b7ad4109SNishanth Menon 	if (!r) {
785b7ad4109SNishanth Menon 		free(dev);
786b7ad4109SNishanth Menon 		return 0;
787b7ad4109SNishanth Menon 	}
788b7ad4109SNishanth Menon 	get_rom_mac(dev, dev->enetaddr);
789b7ad4109SNishanth Menon 
790b7ad4109SNishanth Menon 	dev->init = lan91c96_init;
791b7ad4109SNishanth Menon 	dev->halt = lan91c96_halt;
792b7ad4109SNishanth Menon 	dev->send = lan91c96_send;
793b7ad4109SNishanth Menon 	dev->recv = lan91c96_recv;
794b7ad4109SNishanth Menon 	sprintf(dev->name, "%s-%hu", supported_chips[r].name, dev_num);
795b7ad4109SNishanth Menon 
796b7ad4109SNishanth Menon 	eth_register(dev);
797b7ad4109SNishanth Menon 	return 0;
798b7ad4109SNishanth Menon }
799