/* epic100.c: A SMC 83c170 EPIC/100 fast ethernet driver for Etherboot */
/* 05/06/2003 timlegge Fixed relocation and implemented Multicast */
#define LINUX_OUT_MACROS
#include "etherboot.h"
#include "pci.h"
#include "nic.h"
#include "timer.h"
#include "epic100.h"
/* Condensed operations for readability */
/*
#define DEBUG_RX
#define DEBUG_TX
#define DEBUG_EEPROM
*/
/* The EPIC100 Rx and Tx buffer descriptors. */
struct epic_rx_desc {
unsigned long status;
unsigned long bufaddr;
unsigned long buflength;
unsigned long next;
};
/* description of the tx descriptors control bits commonly used */
struct epic_tx_desc {
unsigned long status;
unsigned long bufaddr;
unsigned long buflength;
unsigned long next;
};
{ __SLOW_DOWN_IO; }} while (0)
static void epic100_open(void);
static void epic100_init_ring(void);
#ifdef DEBUG_EEPROM
static int read_eeprom(int location);
#endif
static int ioaddr;
static int command;
static int intstat;
static int intmask;
static int genctl ;
static int eectl ;
static int test ;
static int mmctl ;
static int mmdata ;
static int lan0 ;
static int mc0 ;
static int rxcon ;
static int txcon ;
static int prcdar ;
static int ptcdar ;
static int eththr ;
#ifdef DEBUG_EEPROM
#endif
/***********************************************************************/
/* Externally visible functions */
/***********************************************************************/
static int
{
int i;
unsigned short* ap;
return 0;
/* Ideally we would detect all network cards in slot order. That would
be best done a central PCI probe dispatch, which wouldn't work
well with the current structure. So instead we detect just the
Epic cards in slot order. */
/* compute all used static epic100 registers address */
/* Reset the chip & bring it out of low-power mode. */
/* Disable ALL interrupts by setting the interrupt mask. */
/*
* set the internal clocks:
* Application Note 7.15 says:
* In order to set the CLOCK TEST bit in the TEST register,
* perform the following:
*
* Write 0x0008 to the test register at least sixteen
* consecutive times.
*
* The CLOCK TEST bit is Write-Only. Writing it several times
* consecutively insures a successful write to the bit...
*/
for (i = 0; i < 16; i++) {
}
#ifdef DEBUG_EEPROM
{
unsigned short sum = 0;
unsigned short value;
for (i = 0; i < 64; i++) {
value = read_eeprom(i);
}
}
#if (EPIC_DEBUG > 1)
printf("EEPROM contents\n");
for (i = 0; i < 64; i++) {
}
#endif
#endif
/* This could also be read from the EEPROM. */
for (i = 0; i < 3; i++)
/* Find the connected MII xcvrs. */
#if (EPIC_DEBUG > 1)
#endif
}
}
if (phy_idx == 0) {
#if (EPIC_DEBUG > 1)
printf("***WARNING***: No MII transceiver found!\n");
#endif
/* Use the known PHY address of the EPII. */
phys[0] = 3;
}
epic100_open();
return 1;
}
static void set_rx_mode(void)
{
int i;
for(i = 0; i < 4; i++)
return;
}
static void
epic100_open(void)
{
int mii_reg5;
int full_duplex = 0;
unsigned long tmp;
/* Pull the chip out of low-power mode, and set for PCI read multiple. */
full_duplex = 1;
printf(" full-duplex mode");
tmp |= TC_LM_FULL_DPX;
} else
tmp |= TC_LM_NORMAL;
/* Give adress of RX and TX ring to the chip */
/* Start the chip's Rx process: receive unicast and broadcast */
set_rx_mode();
putchar('\n');
}
/* Initialize the Rx and Tx rings. */
static void
epic100_init_ring(void)
{
int i;
for (i = 0; i < RX_RING_SIZE; i++) {
}
/* Mark the last entry as wrapping the ring. */
/*
*The Tx buffer descriptor is filled in as needed,
* but we do need to clear the ownership bit.
*/
for (i = 0; i < TX_RING_SIZE; i++) {
}
}
/* function: epic100_transmit
* This transmits a packet.
*
* 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
{
unsigned short nstype;
unsigned char *txp;
int entry;
/* Calculate the next Tx descriptor entry. */
printf("eth_transmit: Unable to transmit. status=%hX. Resetting...\n",
epic100_open();
return;
}
len &= 0x0FFF;
/*
* Caution: the write order is important here,
* set the base address with the "ownership"
* bits last.
*/
cur_tx++;
/* Trigger an immediate transmit demand. */
/* Wait */;
printf("Oops, transmitter timeout, status=%hX\n",
}
/* function: epic100_poll / eth_poll
* This receives a packet from the network.
*
* Arguments: none
*
* returns: 1 if a packet was received.
* 0 if no pacet was received.
* side effects:
* returns the packet in the array nic->packet.
* returns the length of the packet in nic->packetlen.
*/
static int
{
int entry;
int retcode;
int status;
return (0);
if ( ! retrieve ) return 1;
/* We own the next entry, it's a new packet. Send it up. */
#if (EPIC_DEBUG > 4)
#endif
cur_rx++;
if (status & 0x2000) {
printf("epic_poll: Giant packet\n");
retcode = 0;
} else if (status & 0x0006) {
/* Rx Frame errors are counted in hardware. */
printf("epic_poll: Frame received with errors\n");
retcode = 0;
} else {
/* Omit the four octet CRC from the length. */
retcode = 1;
}
/* Clear all error sources. */
/* Give the descriptor back to the chip */
/* Restart Receiver */
return retcode;
}
static void
{
/* Soft reset the chip. */
}
{
switch ( action ) {
case DISABLE :
break;
case ENABLE :
break;
case FORCE :
break;
}
}
#ifdef DEBUG_EEPROM
/* Serial EEPROM section. */
/* EEPROM_Ctrl bits. */
/* The EEPROM commands include the alway-set leading bit. */
static int
{
int i;
int retval = 0;
/* Shift the read command bits out. */
for (i = 10; i >= 0; i--) {
eeprom_delay(100);
eeprom_delay(150);
eeprom_delay(250);
}
for (i = 16; i > 0; i--) {
eeprom_delay(100);
eeprom_delay(100);
}
/* Terminate the EEPROM access. */
return retval;
}
#endif
static int
{
int i;
/* Typical operation takes < 50 ticks. */
for (i = 4000; i > 0; i--)
break;
}
};
.type = NIC_DRIVER,
.name = "EPIC100",
.probe = epic100_probe,
.ids = epic100_nics,
.class = 0,
};