/* -*- Mode:C; c-basic-offset:4; -*- */
/*
sis900.c: An SiS 900/7016 PCI Fast Ethernet driver for Etherboot
Copyright (C) 2001 Entity Cyber, Inc.
Revision: 1.0 March 1, 2001
Author: Marty Connor (mdc@thinguin.org)
Adapted from a Linux driver which was written by Donald Becker
and modified by Ollie Lho and Chin-Shan Li of SiS Corporation.
Rewritten for Etherboot by Marty Connor.
This software may be used and distributed according to the terms
of the GNU Public License (GPL), incorporated herein by reference.
References:
SiS 7016 Fast Ethernet PCI Bus 10/100 Mbps LAN Controller with OnNow Support,
preliminary Rev. 1.0 Jan. 14, 1998
SiS 900 Fast Ethernet PCI Bus 10/100 Mbps LAN Single Chip with OnNow Support,
preliminary Rev. 1.0 Nov. 10, 1998
SiS 7014 Single Chip 100BASE-TX/10BASE-T Physical Layer Solution,
preliminary Rev. 1.0 Jan. 18, 1998
/* Revision History */
/*
07 Dec 2003 timlegge - Enabled Multicast Support
06 Dec 2003 timlegge - Fixed relocation issue in 5.2
04 Jan 2002 Chien-Yu Chen, Doug Ambrisko, Marty Connor Patch to Etherboot 5.0.5
Added support for the SiS 630ET plus various bug fixes from linux kernel
source 2.4.17.
01 March 2001 mdc 1.0
Initial Release. Tested with PCI based sis900 card and ThinkNIC
computer.
20 March 2001 P.Koegel
added support for sis630e and PHY ICS1893 and RTL8201
Testet with SIS730S chipset + ICS1893
*/
/* Includes */
#include "etherboot.h"
#include "nic.h"
#include "pci.h"
#include "timer.h"
#include "sis900.h"
/* Globals */
static int sis900_debug = 0;
static unsigned long ioaddr;
static unsigned int cur_phy;
static unsigned int cur_rx;
#if 0
static struct mac_chip_info {
const char *name;
int io_size;
} mac_chip_table[] = {
{0,0,0,0,0} /* 0 terminated list. */
};
#endif
static struct mii_chip_info {
const char * name;
} mii_chip_table[] = {
{0,0,0,0}
};
static struct mii_phy {
int phy_addr;
} mii;
// PCI to ISA bridge for SIS640E access
{ 0x1039, 0x0008,
"SIS 85C503/5513 PCI to ISA bridge"},
};
.type = BRIDGE_DRIVER,
.name = "",
.probe = 0,
.class = 0,
};
/* Function Prototypes */
static void sis900_mdio_reset(long mdio_addr);
static void sis900_mdio_idle(long mdio_addr);
#if 0
#endif
unsigned int t, unsigned int s, const char *p);
/**
* sis900_get_mac_addr: - Get MAC address for stand alone SiS900 model
* @pci_dev: the sis900 pci device
* @net_dev: the net device to get address for
*
* Older SiS900 and friends, use EEPROM to store MAC address.
* MAC address is read from read_eeprom() into @net_dev->dev_addr.
*/
{
int i;
/* check to see if we have sane EEPROM */
return 0;
}
/* get MAC address from EEPROM */
for (i = 0; i < 3; i++)
return 1;
}
/**
* sis96x_get_mac_addr: - Get MAC address for SiS962 or SiS963 model
* @pci_dev: the sis900 pci device
* @net_dev: the net device to get address for
*
* SiS962 or SiS963 model, use EEPROM to store MAC address. And EEPROM
* is shared by
* LAN and 1394. When access EEPROM, send EEREQ signal to hardware first
* and wait for EEGNT. If EEGNT is ON, EEPROM is permitted to be access
* by LAN, otherwise is not. After MAC address is read from EEPROM, send
* EEDONE signal to refuse EEPROM access by LAN.
* The EEPROM map of SiS962 or SiS963 is different to SiS900.
* The signature field in SiS962 or SiS963 spec is meaningless.
* MAC address is read into @net_dev->dev_addr.
*/
{
/* long ioaddr = net_dev->base_addr; */
int i;
printf("Alternate function\n");
while(waittime < 2000) {
/* get MAC address from EEPROM */
for (i = 0; i < 3; i++)
return 1;
} else {
udelay(1);
waittime ++;
}
}
return 0;
}
/**
* sis630e_get_mac_addr: - Get MAC address for SiS630E model
* @pci_dev: the sis900 pci device
* @net_dev: the net device to get address for
*
* SiS630E model, use APC CMOS RAM to store MAC address.
* APC CMOS RAM is accessed through ISA bridge.
* MAC address is read into @net_dev->dev_addr.
*/
{
int i;
struct pci_device p[1];
/* find PCI to ISA bridge */
memset(p, 0, sizeof(p));
do {
find_pci(BRIDGE_DRIVER, p);
/* error on failure */
if (!p->driver)
return 0;
for (i = 0; i < ETH_ALEN; i++)
{
}
return 1;
}
/**
* sis630e_get_mac_addr: - Get MAC address for SiS630E model
* @pci_dev: the sis900 pci device
* @net_dev: the net device to get address for
*
* SiS630E model, use APC CMOS RAM to store MAC address.
* APC CMOS RAM is accessed through ISA bridge.
* MAC address is read into @net_dev->dev_addr.
*/
{
u32 i;
/* disable packet filtering before setting filter */
/* load MAC addr to filter data register */
for (i = 0 ; i < 3 ; i++) {
}
/* enable packet filitering */
return 1;
}
/*
* Function: sis900_probe
*
* Description: initializes initializes the NIC, retrieves the
* MAC address of the card, and sets up some globals required by
* other routines.
*
* Side effects:
* leaves the ioaddress of the sis900 chip in the variable ioaddr.
* leaves the sis900 initialized, and ready to recieve packets.
*
* Returns: struct nic *: pointer to NIC data structure
*/
{
int i;
int found=0;
int phy_addr;
int ret;
return 0;
/* wakeup chip */
/* get MAC address */
ret = 0;
/* save for use later in sis900_reset() */
if (revision == SIS630E_900_REV)
else if (revision == SIS96x_900_REV)
else
if (ret == 0)
{
printf ("sis900_probe: Error MAC address not found\n");
return 0;
}
/* 630ET : set the mii access mode as software-mode */
if (revision == SIS630ET_900_REV)
printf("\nsis900_probe: MAC addr %! at ioaddr %#hX\n",
/* probe for mii transceiver */
/* search for total of 32 possible mii phy addresses */
found = 0;
/* the mii is not accessable, try next one */
continue;
/* search our mii table for the current mii */
for (i = 0; mii_chip_table[i].phy_id1; i++) {
printf("sis900_probe: %s transceiver found at address %d.\n",
found=1;
break;
}
}
}
if (found == 0) {
printf("sis900_probe: No MII transceivers found!\n");
return 0;
}
/* Arbitrarily select the last PHY found as current PHY */
/* initialize device */
return 1;
}
/*
* EEPROM Routines: These functions read and write to EEPROM for
* retrieving the MAC address and other configuration information about
* the card.
*/
/* Delay between EEPROM clock transitions. */
/* Function: sis900_read_eeprom
*
* Description: reads and returns a given location from EEPROM
*
* Arguments: int location: requested EEPROM location
*
* Returns: u16: contents of requested EEPROM location
*
*/
/* Read Serial EEPROM through EEPROM Access Register, Note that location is
in word (16 bits) unit */
{
int i;
eeprom_delay();
eeprom_delay();
/* Shift the read command (9) bits out. */
for (i = 8; i >= 0; i--) {
eeprom_delay();
eeprom_delay();
}
eeprom_delay();
/* read the 16-bits data in */
for (i = 16; i > 0; i--) {
eeprom_delay();
eeprom_delay();
eeprom_delay();
}
/* Terminate the EEPROM access. */
eeprom_delay();
return (retval);
}
/*
Read and write the MII management registers using software-generated
serial MDIO protocol. Note that the command bits and data bits are
send out seperately
*/
{
}
/* Syncronize the MII management interface by shifting 32 one bits out. */
{
int i;
for (i = 31; i >= 0; i--) {
}
return;
}
{
int i;
for (i = 15; i >= 0; i--) {
}
/* Read the 16 data bits. */
for (i = 16; i > 0; i--) {
}
return retval;
}
#if 0
{
int i;
/* Shift the command bits out. */
for (i = 15; i >= 0; i--) {
}
/* Shift the value bits out. */
for (i = 15; i >= 0; i--) {
}
/* Clear out extra bits. */
for (i = 2; i > 0; i--) {
}
return;
}
#endif
/* Function: sis900_init
*
* Description: resets the ethernet controller chip and various
* data structures required for sending and receiving packets.
*
* Arguments: struct nic *nic: NIC data structure
*
* returns: void.
*/
static void
{
/* Soft reset the chip. */
}
/*
* Function: sis900_reset
*
* Description: disables interrupts and soft resets the controller chip
*
* Arguments: struct nic *nic: NIC data structure
*
* Returns: void.
*/
static void
{
int i = 0;
/* Check that the chip has finished the reset. */
while (status && (i++ < 1000)) {
}
else
}
/* Function: sis_init_rxfilter
*
* Description: sets receive filter address to our MAC address
*
* Arguments: struct nic *nic: NIC data structure
*
* returns: void.
*/
static void
{
int i;
/* disable packet filtering before setting filter */
/* load MAC addr to filter data register */
for (i = 0 ; i < 3 ; i++) {
u32 w;
if (sis900_debug > 0)
printf("sis900_init_rxfilter: Receive Filter Addrss[%d]=%X\n",
}
/* enable packet filitering */
}
/*
* Function: sis_init_txd
*
* Description: initializes the Tx descriptor
*
* Arguments: struct nic *nic: NIC data structure
*
* returns: void.
*/
static void
{
/* load Transmit Descriptor Register */
if (sis900_debug > 0)
printf("sis900_init_txd: TX descriptor register loaded with: %X\n",
}
/* Function: sis_init_rxd
*
* Description: initializes the Rx descriptor ring
*
* Arguments: struct nic *nic: NIC data structure
*
* Returns: void.
*/
static void
{
int i;
cur_rx = 0;
/* init RX descriptor */
for (i = 0; i < NUM_RX_DESC; i++) {
if (sis900_debug > 0)
printf("sis900_init_rxd: rxd[%d]=%X link=%X cmdsts=%X bufptr=%X\n",
}
/* load Receive Descriptor Register */
if (sis900_debug > 0)
printf("sis900_init_rxd: RX descriptor register loaded with: %X\n",
}
/* Function: sis_init_rxd
*
* Description:
* sets the receive mode to accept all broadcast packets and packets
* with our MAC address, and reject all multicast packets.
*
* Arguments: struct nic *nic: NIC data structure
*
* Returns: void.
*/
{
int i, table_entries;
table_entries = 16;
else
table_entries = 8;
/* accept all multicast packet */
for (i = 0; i < table_entries; i++)
mc_filter[i] = 0xffff;
/* update Multicast Hash Table in Receive Filter */
for (i = 0; i < table_entries; i++) {
/* why plus 0x04? That makes the correct value for hash table. */
}
/* Accept Broadcast and multicast packets, destination addresses that match
our MAC address */
return;
}
/* Function: sis900_check_mode
*
* Description: checks the state of transmit and receive
* parameters on the NIC, and updates NIC registers to match
*
* Arguments: struct nic *nic: NIC data structure
*
* Returns: void.
*/
static void
{
}
else {
}
}
else {
}
if (duplex == FDX_CAPABLE_FULL_SELECTED) {
}
}
/* Function: sis900_read_mode
*
* Description: retrieves and displays speed and duplex
* parameters from the NIC
*
* Arguments: struct nic *nic: NIC data structure
*
* Returns: void.
*/
static void
{
int i = 0;
/* STSOUT register is Latched on Transition, read operation updates it */
while (i++ < 2)
/* Workaround for Realtek RTL8201 PHY issue */
}
if (status & MII_STSOUT_LINK_FAIL)
printf("sis900_read_mode: Media Link Off\n");
else
printf("sis900_read_mode: Media Link On %s %s-duplex \n",
*speed == HW_SPEED_100_MBPS ?
"100mbps" : "10mbps",
"full" : "half");
}
/* Function: amd79c901_read_mode
*
* Description: retrieves and displays speed and duplex
* parameters from the NIC
*
* Arguments: struct nic *nic: NIC data structure
*
* Returns: void.
*/
static void
{
int i;
for (i = 0; i < 2; i++)
if (status & MII_STAT_CAN_AUTO) {
/* 10BASE-T PHY */
for (i = 0; i < 2; i++)
if (status & MII_STSSUM_SPD)
else
if (status & MII_STSSUM_DPLX)
else
if (status & MII_STSSUM_LINK)
printf("amd79c901_read_mode: Media Link On %s %s-duplex \n",
*speed == HW_SPEED_100_MBPS ?
"100mbps" : "10mbps",
"full" : "half");
else
printf("amd79c901_read_mode: Media Link Off\n");
}
else {
/* HomePNA */
*speed = HW_SPEED_HOME;
if (status & MII_STAT_LINK)
printf("amd79c901_read_mode:Media Link On 1mbps half-duplex \n");
else
printf("amd79c901_read_mode: Media Link Off\n");
}
}
/**
* ics1893_read_mode: - read media mode for ICS1893 PHY
* @net_dev: the net device to read mode for
* @phy_addr: mii phy address
* @speed: the transmit speed to be determined
* @duplex: the duplex mode to be determined
*
* ICS1893 PHY use Quick Poll Detailed Status register
* to determine the speed and duplex mode for sis900
*/
{
int i = 0;
/* MII_QPDSTS is Latched, read twice in succession will reflect the current state */
for (i = 0; i < 2; i++)
if (status & MII_STSICS_SPD)
else
if (status & MII_STSICS_DPLX)
else
if (status & MII_STSICS_LINKSTS)
printf("ics1893_read_mode: Media Link On %s %s-duplex \n",
*speed == HW_SPEED_100_MBPS ?
"100mbps" : "10mbps",
"full" : "half");
else
printf("ics1893_read_mode: Media Link Off\n");
}
/**
* rtl8201_read_mode: - read media mode for rtl8201 phy
* @nic: the net device to read mode for
* @phy_addr: mii phy address
* @speed: the transmit speed to be determined
* @duplex: the duplex mode to be determined
*
* read MII_STATUS register from rtl8201 phy
* to determine the speed and duplex mode for sis900
*/
{
if (status & MII_STAT_CAN_TX_FDX) {
}
else if (status & MII_STAT_CAN_TX) {
}
else if (status & MII_STAT_CAN_T_FDX) {
}
else if (status & MII_STAT_CAN_T) {
}
if (status & MII_STAT_LINK)
printf("rtl8201_read_mode: Media Link On %s %s-duplex \n",
*speed == HW_SPEED_100_MBPS ?
"100mbps" : "10mbps",
"full" : "half");
else
printf("rtl8201_read_config_mode: Media Link Off\n");
}
/**
* vt6103_read_mode: - read media mode for vt6103 phy
* @nic: the net device to read mode for
* @phy_addr: mii phy address
* @speed: the transmit speed to be determined
* @duplex: the duplex mode to be determined
*
* read MII_STATUS register from rtl8201 phy
* to determine the speed and duplex mode for sis900
*/
{
if (status & MII_STAT_CAN_TX_FDX) {
}
else if (status & MII_STAT_CAN_TX) {
}
else if (status & MII_STAT_CAN_T_FDX) {
}
else if (status & MII_STAT_CAN_T) {
}
if (status & MII_STAT_LINK)
printf("vt6103_read_mode: Media Link On %s %s-duplex \n",
*speed == HW_SPEED_100_MBPS ?
"100mbps" : "10mbps",
"full" : "half");
else
printf("vt6103_read_config_mode: Media Link Off\n");
}
/* Function: sis900_transmit
*
* Description: transmits a packet and waits for completion or timeout.
*
* Arguments: char d[6]: destination ethernet address.
* unsigned short t: ethernet protocol type.
* unsigned short s: size of the data-part of the packet.
* char *p: the data for the packet.
*
* Returns: void.
*/
static void
const char *d, /* Destination */
unsigned int t, /* Type */
unsigned int s, /* size */
const char *p) /* Packet */
{
/* Stop the transmitter */
/* load Transmit Descriptor Register */
if (sis900_debug > 1)
printf("sis900_transmit: TX descriptor register loaded with: %X\n",
s += ETH_HLEN;
s &= DSIZE;
if (sis900_debug > 1)
printf("sis900_transmit: sending %d bytes ethtype %hX\n", (int) s, t);
/* pad to minimum packet size */
while (s < ETH_ZLEN)
txb[s++] = '\0';
/* set the transmit buffer descriptor and enable Transmit State Machine */
/* restart the transmitter */
if (sis900_debug > 1)
printf("sis900_transmit: Queued Tx packet size %d.\n", (int) s);
/* wait */ ;
}
/* packet unsuccessfully transmited */
}
/* Disable interrupts by clearing the interrupt mask. */
}
/* Function: sis900_poll
*
* Description: checks for a received packet and returns it if found.
*
* Arguments: struct nic *nic: NIC data structure
*
* Returns: 1 if a packet was recieved.
* 0 if no pacet was recieved.
*
* Side effects:
* Returns (copies) the packet to the array nic->packet.
* Returns the length of the packet in nic->packetlen.
*/
static int
{
int retstat = 0;
if (sis900_debug > 2)
return retstat;
if (sis900_debug > 1)
printf("sis900_poll: got a packet: cur_rx:%d, status:%X\n",
if ( ! retrieve ) return 1;
/* corrupted packet received */
printf("sis900_poll: Corrupted packet received, buffer status = %X\n",
retstat = 0;
} else {
/* give packet to higher level routine */
retstat = 1;
}
/* return the descriptor and buffer to receive ring */
if (++cur_rx == NUM_RX_DESC)
cur_rx = 0;
/* re-enable the potentially idle receive state machine */
return retstat;
}
/* Function: sis900_disable
*
* Description: Turns off interrupts and stops Tx and Rx engines
*
* Arguments: struct nic *nic: NIC data structure
*
* Returns: void.
*/
static void
{
/* merge reset and disable */
/* Disable interrupts by clearing the interrupt mask. */
/* Stop the chip's Tx and Rx Status Machine */
}
/* Function: sis900_irq
*
* Description: Enable, Disable, or Force, interrupts
*
* Arguments: struct nic *nic: NIC data structure
* irq_action_t action: Requested action
*
* Returns: void.
*/
static void
{
switch ( action ) {
case DISABLE :
break;
case ENABLE :
break;
case FORCE :
break;
}
}
};
.type = NIC_DRIVER,
.name = "SIS900",
.probe = sis900_probe,
.ids = sis900_nics,
.class = 0,
};