a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* tlan.c -- Etherboot device driver for the Texas Instruments ThunderLAN
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* Written 2003-2003 by Timothy Legge <tlegge@rogers.com>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* This program is free software; you can redistribute it and/or modify
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* it under the terms of the GNU General Public License as published by
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* the Free Software Foundation; either version 2 of the License, or
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* (at your option) any later version.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* This program is distributed in the hope that it will be useful,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* but WITHOUT ANY WARRANTY; without even the implied warranty of
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* GNU General Public License for more details.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* You should have received a copy of the GNU General Public License
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* along with this program; if not, write to the Free Software
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* Portions of this code (almost all) based on:
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* tlan.c: Linux ThunderLan Driver:
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* by James Banks
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* (C) 1997-1998 Caldera, Inc.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* (C) 1998 James Banks
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* (C) 1999-2001 Torben Mathiasen
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* (C) 2002 Samuel Chessman
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* REVISION HISTORY:
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* ================
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* v1.0 07-08-2003 timlegge Initial not quite working version
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* Indent Style: indent -kr -i8
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * the General Public License version 2 (GPLv2) at this time for any software where
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * a choice of GPL license versions is made available with the language indicating
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * that GPLv2 or any later version may be used, or where a choice of which version
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * of the GPL is applied is otherwise unspecified.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/*****************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync* TLan Definitions
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync****************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define TLAN_DBG(lvl, format, args...) if (debug&lvl) printf("TLAN: " format, ##args );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define TX_TIMEOUT (10*HZ) /* We need time for auto-neg */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define MAX_TLAN_BOARDS 8 /* Max number of boards installed at a time */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /*****************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Device Identification Definitions
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ****************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100 0xB030
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /*****************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * EISA Definitions
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ****************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define EISA_REG0 0xc88 /* EISA Configuration Register 0 */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define EISA_REG1 0xc89 /* EISA Configuration Register 1 */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define EISA_REG2 0xc8a /* EISA Configuration Register 2 */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define EISA_REG3 0xc8f /* EISA Configuration Register 3 */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define EISA_APROM 0xc90 /* Ethernet Address PROM */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /*****************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Rx/Tx List Definitions
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ****************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /*****************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * PHY definitions
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ****************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /*****************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * TLan Driver Timer Definitions
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ****************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /*****************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * TLan Driver Eeprom Definitions
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ****************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /*****************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Host Register Offsets and Contents
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync ****************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* ThunderLAN Internal Register DIO Offsets */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* ThunderLAN Interrupt Codes */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* ThunderLAN MII Registers */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* ThunderLAN Specific MII/PHY Registers */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* National Sem. & Level1 PHY id's */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* Routines to access internal registers. */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic inline u8 TLan_DioRead8(u16 base_addr, u16 internal_addr)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return (inb((base_addr + TLAN_DIO_DATA) + (internal_addr & 0x3)));
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync} /* TLan_DioRead8 */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic inline u16 TLan_DioRead16(u16 base_addr, u16 internal_addr)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return (inw((base_addr + TLAN_DIO_DATA) + (internal_addr & 0x2)));
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync} /* TLan_DioRead16 */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic inline u32 TLan_DioRead32(u16 base_addr, u16 internal_addr)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync} /* TLan_DioRead32 */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic inline void TLan_DioWrite8(u16 base_addr, u16 internal_addr, u8 data)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync outb(data, base_addr + TLAN_DIO_DATA + (internal_addr & 0x3));
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic inline void TLan_DioWrite16(u16 base_addr, u16 internal_addr, u16 data)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync outw(data, base_addr + TLAN_DIO_DATA + (internal_addr & 0x2));
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic inline void TLan_DioWrite32(u16 base_addr, u16 internal_addr, u32 data)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync outl(data, base_addr + TLAN_DIO_DATA + (internal_addr & 0x2));
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define TLan_ClearBit( bit, port ) outb_p(inb_p(port) & ~bit, port)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define TLan_GetBit( bit, port ) ((int) (inb_p(port) & bit))
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define TLan_SetBit( bit, port ) outb_p(inb_p(port) | bit, port)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* given 6 bytes, view them as 8 6-bit numbers and return the XOR of those */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* the code below is about seven times as fast as the original code */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#else /* original code */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return ((a && !b) || (!a && b));
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define XOR8( a, b, c, d, e, f, g, h ) xor( a, xor( b, xor( c, xor( d, xor( e, xor( f, xor( g, h ) ) ) ) ) ) )
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#define DA( a, bit ) ( ( (u8) a[bit/8] ) & ( (u8) ( 1 << bit%8 ) ) )
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync XOR8(DA(a, 0), DA(a, 6), DA(a, 12), DA(a, 18), DA(a, 24),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync XOR8(DA(a, 1), DA(a, 7), DA(a, 13), DA(a, 19), DA(a, 25),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync XOR8(DA(a, 2), DA(a, 8), DA(a, 14), DA(a, 20), DA(a, 26),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync XOR8(DA(a, 3), DA(a, 9), DA(a, 15), DA(a, 21), DA(a, 27),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync XOR8(DA(a, 4), DA(a, 10), DA(a, 16), DA(a, 22), DA(a, 28),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync XOR8(DA(a, 5), DA(a, 11), DA(a, 17), DA(a, 23), DA(a, 29),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#endif /* I_LIKE_A_FAST_HASH_FUNCTION */