#define EB51
#ifdef EB50
#endif
/**************************************************************************
*
* tlan.c -- Etherboot device driver for the Texas Instruments ThunderLAN
* Written 2003-2003 by Timothy Legge <tlegge@rogers.com>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Portions of this code based on:
* lan.c: Linux ThunderLan Driver:
*
* by James Banks
*
* (C) 1997-1998 Caldera, Inc.
* (C) 1998 James Banks
* (C) 1999-2001 Torben Mathiasen
* (C) 2002 Samuel Chessman
*
* REVISION HISTORY:
* ================
* v1.0 07-08-2003 timlegge Initial not quite working version
* v1.1 07-27-2003 timlegge Sync 5.0 and 5.1 versions
* v1.2 08-19-2003 timlegge Implement Multicast Support
* v1.3 08-23-2003 timlegge Fix the transmit Function
* v1.4 01-17-2004 timlegge Initial driver output cleanup
*
* Indent Options: indent -kr -i8
***************************************************************************/
/* to get some global routines like printf */
#include "etherboot.h"
/* to get the interface to the body of the program */
#include "nic.h"
/* to get the PCI support functions, if this is a PCI NIC */
#include "pci.h"
#include "timer.h"
#include "tlan.h"
/* NIC specific static variables go here */
#ifdef EB50
#define virt_to_bus(x) ((unsigned long) x)
#define bus_to_virt(x) ((unsigned long) x)
#endif
/* Condensed operations for readability. */
static void TLan_EeSendStart(u16);
#ifdef MONITOR
#endif
static void TLan_MiiSync(u16);
const char *media[] = {
"10BaseT-HD ", "10BaseT-FD ", "100baseTx-HD ",
"100baseTx-FD", "100baseT4", 0
};
/* This much match tlan_pci_tbl[]! */
enum tlan_nics {
};
struct pci_id_info {
const char *name;
int nic_id;
struct match_info {
} id;
};
{"Compaq Netelligent 10 T PCI UTP", NETEL10,
{0xae340e11, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_ACTIVITY_LED, 0x83},
{"Compaq Netelligent 10/100 TX PCI UTP", NETEL100,
{0xae320e11, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_ACTIVITY_LED, 0x83},
{"Compaq Integrated NetFlex-3/P", NETFLEX3I,
{0xae350e11, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_NONE, 0x83},
{"Compaq NetFlex-3/P", THUNDER,
{0xf1300e11, 0xffffffff, 0, 0, 0, 0},
{"Compaq NetFlex-3/P", NETFLEX3B,
{0xf1500e11, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_NONE, 0x83},
{"Compaq Netelligent Integrated 10/100 TX UTP", NETEL100PI,
{0xae430e11, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_ACTIVITY_LED, 0x83},
{"Compaq Netelligent Dual 10/100 TX PCI UTP", NETEL100D,
{0xae400e11, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_NONE, 0x83},
{"Compaq Netelligent 10/100 TX Embedded UTP", NETEL100I,
{0xb0110e11, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_NONE, 0x83},
{"Olicom OC-2183/2185", OC2183,
{0x0013108d, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_USE_INTERN_10, 0x83},
{"Olicom OC-2325", OC2325,
{0x0012108d, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_UNMANAGED_PHY, 0xF8},
{"Olicom OC-2326", OC2326,
{0x0014108d, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_USE_INTERN_10, 0xF8},
{"Compaq Netelligent 10/100 TX UTP", NETELLIGENT_10_100_WS_5100,
{0xb0300e11, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_ACTIVITY_LED, 0x83},
{"Compaq Netelligent 10 T/2 PCI UTP/Coax", NETELLIGENT_10_T2,
{0xb0120e11, 0xffffffff, 0, 0, 0, 0},
TLAN_ADAPTER_NONE, 0x83},
{"Compaq NetFlex-3/E", 0, /* EISA card */
{0, 0, 0, 0, 0, 0},
TLAN_ADAPTER_BIT_RATE_PHY, 0x83},
{"Compaq NetFlex-3/E", 0, /* EISA card */
{0, 0, 0, 0, 0, 0},
TLAN_ADAPTER_ACTIVITY_LED, 0x83},
{0, 0,
{0, 0, 0, 0, 0, 0},
0, 0},
};
struct TLanList {
struct {
};
int chip_idx;
/*****************************************************************
* TLAN Private Information Structure
*
****************************************************************/
struct tlan_private {
const char *nic_name;
int eoc;
/***************************************************************
* TLan_ResetLists
*
* Returns:
* Nothing
* Parms:
* dev The device structure with the list
* stuctures to be reset.
*
* This routine sets the variables associated with managing
* the TLAN lists to their initial values.
*
**************************************************************/
{
int i;
for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
/* list->buffer[0].address = 0; */
(i * TLAN_MAX_FRAME_SIZE));
/* list->forward = 0; */
}
/* Initialize all the Rx descriptors */
for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
}
/* Mark the last entry as wrapping the ring */
} /* TLan_ResetLists */
/***************************************************************
* TLan_Reset
*
* Returns:
* 0
* Parms:
* dev Pointer to device structure of adapter
* to be reset.
*
* This function resets the adapter and it's physical
* device. See Chap. 3, pp. 9-10 of the "ThunderLAN
* Programmer's Guide" for details. The routine tries to
* implement what is detailed there, though adjustments
* have been made.
*
**************************************************************/
{
int i;
/* 1. Assert reset bit. */
data |= TLAN_HC_AD_RST;
udelay(1000);
/* 2. Turn off interrupts. ( Probably isn't necessary ) */
data |= TLAN_HC_INT_OFF;
/* 3. Clear AREGs and HASHs. */
}
/* 4. Setup NetConfig register. */
data =
/* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
/* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
/* 7. Setup the remaining registers. */
}
data |= TLAN_NET_CFG_BIT;
} else {
}
}
}
} else {
}
} /* TLan_ResetAdapter */
{
int i;
if (priv->tlanFullDuplex) {
}
}
} else {
udelay(1000);
(tlphy_id1 == NAT_SEM_ID1)
&& (tlphy_id2 == NAT_SEM_ID2)) {
&tlphy_par);
printf("TLAN: %s: Link active with ",
if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
printf("forced 10%sMbps %s-Duplex\n",
: "0",
"Full" : "Half");
} else {
("AutoNegotiation enabled, at 10%sMbps %s-Duplex\n",
"0",
"Full" : "Half");
printf("TLAN: Partner capability: ");
for (i = 5; i <= 10; i++)
if (partner & (1 << i))
printf("\n");
}
#ifdef MONITOR
/* We have link beat..for now anyway */
/*Enabling link beat monitoring */
/* TLan_SetTimer( nic, (10*HZ), TLAN_TIMER_LINK_BEAT ); */
mdelay(10000);
#endif
} else if (status & MII_GS_LINK) {
}
}
}
if (status & MII_GS_LINK) {
/* if ( debug >= 1 && debug != TLAN_DEBUG_PROBE ) {
outb( ( TLAN_HC_REQ_INT >> 8 ), BASE + TLAN_HOST_CMD + 1 );
}
*/
} else {
("TLAN: %s: Link inactive, will retry in 10 secs...\n",
/* TLan_SetTimer( nic, (10*HZ), TLAN_TIMER_FINISH_RESET ); */
mdelay(10000);
return;
}
} /* TLan_FinishReset */
/**************************************************************************
POLL - Wait for a frame
***************************************************************************/
{
/* return true if there's an ethernet packet ready to read */
/* nic->packet should contain data on return */
/* nic->packetlen should contain length of data */
int eoc = 0;
return 1;
if (!(tmpCStat & TLAN_CSTAT_FRM_CMP))
return 0;
/* printf("PI-1: 0x%hX\n", host_int); */
if (tmpCStat & TLAN_CSTAT_EOC)
eoc = 1;
#ifdef EBDEBUG
#endif
#ifdef EBDEBUG
#endif
if (eoc) {
}
} else {
#ifdef EBDEBUG
#endif
}
return (1); /* initially as this is called to flush the input */
}
{
int entry = 0;
for (;
TLAN_NUM_RX_LISTS) % TLAN_NUM_RX_LISTS > 0;
}
}
/* #define EBDEBUG */
/**************************************************************************
TRANSMIT - Transmit a frame
***************************************************************************/
unsigned int t, /* Type */
unsigned int s, /* size */
const char *p)
{ /* Packet */
int eoc = 0;
#ifdef EBDEBUG
#endif
int entry = 0;
#ifdef EBDEBUG
#endif
return;
}
printf("TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
priv->txBusyCount++;
return;
}
/* send the packet to destination */
s += ETH_HLEN;
s &= 0x0FFF;
while (s < ETH_ZLEN)
tail_buffer[s++] = '\0';
/*=====================================================*/
/* Receive
* 0000 0000 0001 1100
* 0000 0000 0000 1100
* 0000 0000 0000 0011 = 0x0003
*
* 0000 0000 0000 0000 0000 0000 0000 0011
* 0000 0000 0000 1100 0000 0000 0000 0000 = 0x000C0000
*
* Transmit
* 0000 0000 0001 1100
* 0000 0000 0000 0100
* 0000 0000 0000 0001 = 0x0001
*
* 0000 0000 0000 0000 0000 0000 0000 0001
* 0000 0000 0000 0100 0000 0000 0000 0000 = 0x00040000
* */
/* Setup the transmit descriptor */
#ifdef EBDEBUG
#endif
if (!priv->txInProgress) {
} else {
#ifdef EBDEBUG
printf("Out buffer\n");
#endif
} else {
#ifdef EBDEBUG
printf("Fix this \n");
#endif
}
}
#ifdef EBDEBUG
#endif
&& (ack < 255)) {
ack++;
if(tmpCStat & TLAN_CSTAT_EOC)
eoc =1;
}
if(!ack)
printf("Incomplete TX Frame\n");
if(eoc) {
ack |= TLAN_HC_GO;
} else {
priv->txInProgress = 0;
}
}
if(ack) {
}
ack = 1;
ack |= TLAN_HC_GO;
} else {
priv->txInProgress = 0;
}
}
printf("TX Time Out");
}
}
/**************************************************************************
DISABLE - Turn off ethernet interface
***************************************************************************/
#ifdef EB51
#else
#endif
{
/* put the card in its initial state */
/* This function serves 3 purposes.
* This disables DMA and interrupts so we don't receive
* unexpected packets or interrupts from the card after
* etherboot has finished.
* This frees resources so etherboot may use
* this driver on another interface
* This allows etherboot to reinitialize the interface
* if something is something goes wrong.
*
*/
}
/**************************************************************************
IRQ - Enable, Disable, or Force interrupts
***************************************************************************/
{
switch ( action ) {
case DISABLE :
break;
case ENABLE :
break;
case FORCE :
break;
}
}
int i;
/* !IFF_PROMISC */
/* IFF_ALLMULTI */
for(i = 0; i< 3; i++)
}
/**************************************************************************
PROBE - Look for an adapter, this routine's visible to the outside
***************************************************************************/
#define valid_link 0
#ifdef EB51
{
#else
{
#endif
int err;
int i;
return 0;
printf("\n");
printf("%s: Probing for Vendor 0x%hX, Device 0x%hX",
/* I really must find out what this does */
/* Point to private storage */
priv = &TLanPrivateInfo;
/* Figure out which chip we're dealing with */
i = 0;
chip_idx = -1;
while (tlan_pci_tbl[i].name) {
chip_idx = i;
break;
}
i++;
}
err = 0;
for (i = 0; i < 6; i++)
addrOfs + i,
if (err) {
printf("TLAN: %s: Error reading MAC from eeprom: %d\n",
} else
/*
data = inl(BASE + TLAN_HOST_CMD);
data |= TLAN_HC_EOC;
outw(data, BASE + TLAN_HOST_CMD);
*/
data |= TLAN_HC_INT_OFF;
udelay(100);
/* if (board_found && valid_link)
{*/
/* point to NIC specific routines */
#ifdef EB51
return 1;
#else
return nic;
#endif
}
/*****************************************************************************
******************************************************************************
ThunderLAN Driver Eeprom routines
The Compaq Netelligent 10 and 10/100 cards use a Microchip 24C02A
EEPROM. These functions are based on information in Microchip's
data sheet. I don't know how well this functions will work with
other EEPROMs.
******************************************************************************
*****************************************************************************/
/***************************************************************
* TLan_EeSendStart
*
* Returns:
* Nothing
* Parms:
* io_base The IO port base address for the
* TLAN device with the EEPROM to
* use.
*
* This function sends a start cycle to an EEPROM attached
* to a TLAN chip.
*
**************************************************************/
{
} /* TLan_EeSendStart */
/***************************************************************
* TLan_EeSendByte
*
* Returns:
* If the correct ack was received, 0, otherwise 1
* Parms: io_base The IO port base address for the
* TLAN device with the EEPROM to
* use.
* data The 8 bits of information to
* send to the EEPROM.
* stop If TLAN_EEPROM_STOP is passed, a
* stop cycle is sent after the
* byte is sent after the ack is
* read.
*
* This function sends a byte on the serial EEPROM line,
* driving the clock to send each bit. The function then
* reverses transmission direction and reads an acknowledge
* bit.
*
**************************************************************/
{
int err;
/* Assume clock is low, tx is enabled; */
else
}
}
return (err);
} /* TLan_EeSendByte */
/***************************************************************
* TLan_EeReceiveByte
*
* Returns:
* Nothing
* Parms:
* io_base The IO port base address for the
* TLAN device with the EEPROM to
* use.
* data An address to a char to hold the
* data sent from the EEPROM.
* stop If TLAN_EEPROM_STOP is passed, a
* stop cycle is sent after the
* byte is received, and no ack is
* sent.
*
* This function receives 8 bits of data from the EEPROM
* over the serial link. It then sends and ack bit, or no
* ack and a stop bit. This function is used to retrieve
* data after the address of a byte in the EEPROM has been
* sent.
*
**************************************************************/
{
*data = 0;
/* Assume clock is low, tx is enabled; */
}
if (!stop) {
} else {
}
} /* TLan_EeReceiveByte */
/***************************************************************
* TLan_EeReadByte
*
* Returns:
* No error = 0, else, the stage at which the error
* occurred.
* Parms:
* io_base The IO port base address for the
* TLAN device with the EEPROM to
* use.
* ee_addr The address of the byte in the
* EEPROM whose contents are to be
* retrieved.
* data An address to a char to hold the
* data obtained from the EEPROM.
*
* This function reads a byte of information from an byte
* cell in the EEPROM.
*
**************************************************************/
{
int err;
int ret = 0;
if (err) {
ret = 1;
goto fail;
}
if (err) {
ret = 2;
goto fail;
}
if (err) {
ret = 3;
goto fail;
}
fail:
return ret;
} /* TLan_EeReadByte */
/*****************************************************************************
******************************************************************************
ThunderLAN Driver MII Routines
These routines are based on the information in Chap. 2 of the
"ThunderLAN Programmer's Guide", pp. 15-24.
******************************************************************************
*****************************************************************************/
/***************************************************************
* TLan_MiiReadReg
*
* Returns:
* 0 if ack received ok
* 1 otherwise.
*
* Parms:
* dev The device structure containing
* The io address and interrupt count
* for this device.
* phy The address of the PHY to be queried.
* reg The register whose contents are to be
* retreived.
* val A pointer to a variable to store the
* retrieved value.
*
* This function uses the TLAN's MII bus to retreive the contents
* of a given register on a PHY. It sends the appropriate info
* and then reads the 16-bit register value from the MII bus via
* the TLAN SIO register.
*
**************************************************************/
{
u32 i;
int err;
int minten;
if (minten)
if (nack) { /* No ACK, so fake it */
for (i = 0; i < 16; i++) {
}
tmp = 0xffff;
} else { /* ACK, so read data */
tmp |= i;
}
}
if (minten)
return err;
} /* TLan_MiiReadReg */
/***************************************************************
* TLan_MiiSendData
*
* Returns:
* Nothing
* Parms:
* base_port The base IO port of the adapter in
* question.
* dev The address of the PHY to be queried.
* data The value to be placed on the MII bus.
* num_bits The number of bits in data that are to
* be placed on the MII bus.
*
* This function sends on sequence of bits on the MII
* configuration bus.
*
**************************************************************/
{
u32 i;
if (num_bits == 0)
return;
if (data & i)
else
}
} /* TLan_MiiSendData */
/***************************************************************
* TLan_MiiSync
*
* Returns:
* Nothing
* Parms:
* base_port The base IO port of the adapter in
* question.
*
* This functions syncs all PHYs in terms of the MII configuration
* bus.
*
**************************************************************/
{
int i;
for (i = 0; i < 32; i++) {
}
} /* TLan_MiiSync */
/***************************************************************
* TLan_MiiWriteReg
*
* Returns:
* Nothing
* Parms:
* dev The device structure for the device
* to write to.
* phy The address of the PHY to be written to.
* reg The register whose contents are to be
* written.
* val The value to be written to the register.
*
* This function uses the TLAN's MII bus to write the contents of a
* given register on a PHY. It sends the appropriate info and then
* writes the 16-bit register value from the MII configuration bus
* via the TLAN SIO register.
*
**************************************************************/
{
int minten;
if (minten)
if (minten)
} /* TLan_MiiWriteReg */
/***************************************************************
* TLan_SetMac
*
* Returns:
* Nothing
* Parms:
* dev Pointer to device structure of adapter
* on which to change the AREG.
* areg The AREG to set the address in (0 - 3).
* mac A pointer to an array of chars. Each
* element stores one byte of the address.
* IE, it isn't in ascii.
*
* This function transfers a MAC address to one of the
* TLAN AREGs (address registers). The TLAN chip locks
* the register on writing to offset 0 and unlocks the
* register after writing to offset 5. If NULL is passed
* in mac, then the AREG is filled with 0's.
*
**************************************************************/
{
int i;
areg *= 6;
for (i = 0; i < 6; i++)
mac[i]);
} else {
for (i = 0; i < 6; i++)
}
} /* TLan_SetMac */
/*********************************************************************
* TLan_PhyDetect
*
* Returns:
* Nothing
* Parms:
* dev A pointer to the device structure of the adapter
* for which the PHY needs determined.
*
* So far I've found that adapters which have external PHYs
* may also use the internal PHY for part of the functionality.
* chip has an internal PHY, and then finds the first external
* PHY (starting from address 0) if it exists).
*
********************************************************************/
{
return;
}
if (hi != 0xFFFF) {
} else {
}
|| (lo != 0xFFFF)) {
&& (phy != TLAN_PHY_MAX_ADDR)) {
}
}
}
} else {
("TLAN: Cannot initialize device, no PHY was found!\n");
}
} /* TLan_PhyDetect */
{
&&
(!(tlan_pci_tbl[chip_idx].
flags & TLAN_ADAPTER_USE_INTERN_10))) {
}
/* Wait for 50 ms and powerup
* This is abitrary. It is intended to make sure the
* tranceiver settles.
*/
/* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_PUP ); */
mdelay(50);
} /* TLan_PhyPowerDown */
{
/* Wait for 500 ms and reset the
* tranceiver. The TLAN docs say both 50 ms and
* 500 ms, so do the longer, just in case.
*/
mdelay(500);
/* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_RESET ); */
} /* TLan_PhyPowerUp */
{
while (value & MII_GC_RESET) {
}
/* Wait for 500 ms and initialize.
* I don't remember why I wait this long.
* I've changed this to 50ms, as it seems long enough.
*/
/* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_START_LINK ); */
mdelay(50);
} /* TLan_PhyReset */
{
} else {
/* Set Auto-Neg advertisement */
/* Enablee Auto-Neg */
/* Restart Auto-Neg */
/* Wait for 4 sec for autonegotiation
* to complete. The max spec time is less than this
* but the card need additional time to start AN.
* .5 sec should be plenty extra.
*/
printf("TLAN: %s: Starting autonegotiation.\n",
mdelay(4000);
/* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN ); */
return;
}
}
data =
mdelay(50);
/* TLan_SetTimer( dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN ); */
return;
control = 0;
tctl |= TLAN_TC_AUISEL;
} else {
tctl &= ~TLAN_TC_AUISEL;
control |= MII_GC_DUPLEX;
}
}
}
}
/* Wait for 2 sec to give the tranceiver time
* to establish link.
*/
/* TLan_SetTimer( dev, (4*HZ), TLAN_TIMER_FINISH_RESET ); */
mdelay(2000);
} /* TLan_PhyStartLink */
{
udelay(1000);
if (!(status & MII_GS_AUTOCMPLT)) {
/* Wait for 8 sec to give the process
* more time. Perhaps we should fail after a while.
*/
if (!priv->neg_be_verbose++) {
("TLAN: Giving autonegotiation more time.\n");
("TLAN: Please check that your adapter has\n");
("TLAN: been properly connected to a HUB or Switch.\n");
("TLAN: Trying to establish link in the background...\n");
}
mdelay(8000);
/* TLan_SetTimer( dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN ); */
return;
}
if (mode & 0x0100) {
printf("Full Duplex\n");
printf("Full Duplex\n");
}
if ((!(mode & 0x0180))
data =
/* TLan_SetTimer( nic, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN ); */
mdelay(400);
return;
}
("TLAN: Starting internal PHY with FULL-DUPLEX\n");
} else {
("TLAN: Starting internal PHY with HALF-DUPLEX\n");
}
}
/* Wait for 100 ms. No reason in partiticular.
*/
/* TLan_SetTimer( dev, (HZ/10), TLAN_TIMER_FINISH_RESET ); */
mdelay(100);
} /* TLan_PhyFinishAutoNeg */
#ifdef MONITOR
/*********************************************************************
*
* TLan_phyMonitor
*
* Returns:
* None
*
* Params:
* dev The device structure of this device.
*
*
* This function monitors PHY condition by reading the status
* register via the MII bus. This can be used to give info
* media.
*
* ******************************************************************/
{
/* Get PHY status register */
/* Check if link has been lost */
if (!(phy_status & MII_GS_LINK)) {
mdelay(2000);
/* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT ); */
return;
}
}
/* Link restablished? */
printf("TLAN: %s has reestablished link\n",
}
/* Setup a new monitor */
/* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT ); */
mdelay(2000);
}
#endif /* MONITOR */
#ifdef EB51
};
.type = NIC_DRIVER,
.probe = tlan_probe,
.class = 0,
};
#endif