📄 eprom.c
字号:
#include "vxWorks.h"
#include "lite5200b.h"
#include "stdio.h"
#include "stdlib.h"
#include "eprom.h"
/*this file only for 8139 access 93c46*/
#define EEPROM_CLOCK_DELAY 100 /* 10us */
/* static char vendorMac[3] = {0x00, 0xd0, 0xd0}; */ /*the first 3 MAC addr, vendor ID of ZHAO */
#define DEFAULT_93C46_NUM 0x3f /*default93c46cfg's counts in char unit*/
static char default93c46cfg[DEFAULT_93C46_NUM * 2]=
{0x00,0xd0,0xd0,0xd0,0x09,0x12,0x00,0x00,0x00,0x00,0x01,0x02,0x01,0x47,0x00,0x00,
0x80,0x66,0x02,0x81,0x01,0x44,0x01,0x00,0x86,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
ethPciInfo endDevices[NUM_ENET] =
{
{PCI_IDSEL_82559, MPC5200_IRQ_82559, 0},
{PCI_IDSEL_82559, MPC5200_IRQ_82559, 0},
{PCI_IDSEL_82559, MPC5200_IRQ_82559, 0},
{PCI_IDSEL_82559, MPC5200_IRQ_82559, 0}
};
#define BYTE_TO_WORD(b1, b2) \
((UINT16)b1 | (UINT16)b2 << 8)
#define DL_LOG(a)
static void WriteEEprom( ethPciInfo *bdp, ushort_t reg, ushort_t data );
static void ShiftOutBits( ethPciInfo *bdp, ushort_t data, ushort_t count );
static ushort_t ShiftInBits( ethPciInfo *bdp );
static void RaiseClock( ethPciInfo *bdp, ushort_t *x );
static void LowerClock( ethPciInfo *bdp, ushort_t *x );
static ushort_t WaitEEPROMCmdDone( ethPciInfo *bdp );
static void StandBy( ethPciInfo *bdp );
static void EEpromCleanup( ethPciInfo *bdp );
static void eeEUpdateChecksum( ethPciInfo *bdp );
static void dumpEeprom( ethPciInfo *eth );
void ExportFromEeprom (int i)
{
pciConfigInLong (0, endDevices[i].deviceNum, 0,
PCI_CFG_BASE_ADDRESS_0, &endDevices[i].memBase);
endDevices[i].memBase &= PCI_MEMBASE_MASK;
dumpEeprom (&endDevices[i]);
}
/* fill the eeprom with the default values. */
void ImportToEeprom (int i)
{
int j;
ethPciInfo *eth = &endDevices[i];
pciConfigInLong (0, eth -> deviceNum, 0,
PCI_CFG_BASE_ADDRESS_0, & (eth -> memBase));
eth -> memBase &= PCI_MEMBASE_MASK;
/*fill the default values*/
for (j = 0; j < (DEFAULT_93C46_NUM * 2); j+=2)
WriteEEprom (eth, j/2, BYTE_TO_WORD(default93c46cfg[j],default93c46cfg[j+1]));
/*recalculate the checksum and update it*/
eeEUpdateChecksum (eth);
}
/* write eeprom, eaddr contains 6 byte mac address */
void WriteMacToEeprom (int i, char *eaddr)
{
ethPciInfo *eth = &endDevices[i];
pciConfigInLong (0, eth -> deviceNum, 0,
PCI_CFG_BASE_ADDRESS_0, & (eth -> memBase));
eth -> memBase &= PCI_MEMBASE_MASK;
/* write ethernet address passed in*/
WriteEEprom (eth, (0x0/2) , BYTE_TO_WORD(eaddr[0], eaddr[1]));
WriteEEprom (eth, (0x2/2), BYTE_TO_WORD(eaddr[2], eaddr[3]));
WriteEEprom (eth, (0x4/2), BYTE_TO_WORD(eaddr[4], eaddr[5]));
/*recalculate the checksum and update it*/
eeEUpdateChecksum (eth);
}
void ReadMacFromEeprom (int ii, char *eaddr)
{
int i=0;
ushort_t EepromWordValue;
ethPciInfo *eth = &endDevices[ii];
pciConfigInLong (0, eth -> deviceNum, 0,
PCI_CFG_BASE_ADDRESS_0, & (eth -> memBase));
eth -> memBase &= PCI_MEMBASE_MASK;
/* Read our node address from the EEPROM. We Must use
* I/O do this, because have not yet memory mapped the CSR
*/
for (i = 0 ; i < 6 ; i +=2) {
EepromWordValue = ReadEEprom( eth, (i /2));
/* Ronch 4-18-97 - added code to set the perm_address in bddp */
eaddr[i] = (uchar_t) EepromWordValue;
eaddr[i+1] = (uchar_t) (EepromWordValue >> 8);
}
}
STATUS EepromCheckSum (int i)
{
ushort_t checkSum = 0;
ushort_t checkSum1 = 0, tempData;
int j;
int err_flag=0;
pciConfigInLong (0, endDevices[i].deviceNum, 0,
PCI_CFG_BASE_ADDRESS_0, &endDevices[i].memBase);
endDevices[i].memBase &= PCI_MEMBASE_MASK;
checkSum = 0;
for (j = 0; j < (DEFAULT_93C46_NUM); j++)
{
tempData = ReadEEprom (&endDevices[i], j);
if (j == 0xc)
if (BYTE_TO_WORD((char)0x86, (char)0x80) != tempData)
{
err_flag = 1;
};
checkSum += tempData;
default93c46cfg[2*j] = (unsigned char)(tempData & 0xff);
default93c46cfg[2*j+1] = (unsigned char)((tempData >> 8) & 0xff);
};
if(err_flag == 1)
return ERROR;
checkSum = (ushort_t)0 - checkSum;
checkSum1 = ReadEEprom (&endDevices[i], DEFAULT_93C46_NUM);
/* printf ("check sum 1:0x%x, 2:0x%x\n", checkSum, checkSum1); */
return (checkSum == checkSum1)? OK:ERROR;
}
void getFeiBandMac(char *macAddr)
{
macAddr[0] = 0x00;
macAddr[1] = 0xd0;
macAddr[2] = 0xd0;
macAddr[3] = 0xdd;
macAddr[4] = 0xdd;
macAddr[5] = 0x88;
}
void getFeiMac(int unit, char *macAddr)
{
if(unit == 0)
getFeiBandMac(macAddr);
}
void correctionEeprom(int unit)
{
getFeiMac(unit, default93c46cfg);
ImportToEeprom (unit);
}
/*
* Procedure: WriteEEprom
*
* Description: This routine writes a word to a specific EEPROM location.
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
* reg - The EEPROM word that we are going to write to.
* data - The data (word) that we are going to write to the EEPROM.
*
* Hari: Modified for 82559 extended eeprom. May 5, 1998.
*
* Returns: (none)
*/
static void
WriteEEprom( ethPciInfo *bdp, ushort_t reg, ushort_t data )
{
ushort_t x;
/* select EEPROM, mask off ASIC and reset bits, set EECS */
x = ( ushort_t )inb( bdp->memBase + CSR_EEPROM_CONTROL_REG );
x &= ~(EEDI | EEDO | EESK);
x |= (EECS | PROGRAM_93C46_MODE);
outb((bdp->memBase + CSR_EEPROM_CONTROL_REG), x);
ShiftOutBits(bdp, EEPROM_EWEN_OPCODE, 5 );
ShiftOutBits(bdp, reg, (6 - 2) ); /* Hari: Changed 4 to bits - 2 */
StandBy(bdp );
/* Erase this particular word. Write the erase opcode and register
* number in that order. The opcode is 3bits in length; reg is 'bits'
* bits long.
*/
ShiftOutBits(bdp, EEPROM_ERASE_OPCODE, 3 );
ShiftOutBits(bdp, reg, 6 ); /* Hari: Changed 6 to bits */
WaitEEPROMCmdDone( bdp );
StandBy( bdp );
/* write the new word to the EEPROM */
/* send the write opcode the EEPORM */
ShiftOutBits( bdp, EEPROM_WRITE_OPCODE, 3 );
/* select which word in the EEPROM that we are writing to. */
ShiftOutBits( bdp, reg, 6 ); /* Hari: Changed 6 to bits */
/* write the data to the selected EEPROM word. */
ShiftOutBits(bdp, data, 16 );
WaitEEPROMCmdDone( bdp );
StandBy( bdp );
ShiftOutBits( bdp, EEPROM_EWDS_OPCODE, 5 );
ShiftOutBits( bdp, reg, (6 - 2) ); /* Hari: Changed 4 to bits - 2 */
EEpromCleanup( bdp );
return;
}
/*
* Procedure: ReadEEprom
*
* Description: This routine serially reads one word out of the EEPROM.
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
* Reg - EEPROM word to read.
*
* Hari: Modified for 82559 extended eeprom. May 5, 1998.
*
* Returns:
* Contents of EEPROM word (Reg).
*/
ushort_t
ReadEEprom( ethPciInfo *bdp, ushort_t Reg )
{
ushort_t x;
ushort_t data;
/* select EEPROM, reset bits, set EECS */
x = ( ushort_t )inb(bdp->memBase + CSR_EEPROM_CONTROL_REG);
x &= ~(EEDI | EEDO | EESK);
x |= EECS;
outb((bdp->memBase + CSR_EEPROM_CONTROL_REG), x);
/* write the read opcode and register number in that order */
/* The opcode is 3bits in length, reg is 'bits' bits long */
ShiftOutBits(bdp, EEPROM_READ_OPCODE, 3 );
ShiftOutBits(bdp, Reg, 6 ); /* Hari: Changed 6 to bits */
/* Now read the data (16 bits) in from the selected EEPROM word */
data = ShiftInBits( bdp );
EEpromCleanup( bdp );
return data;
}
/*
* Procedure: ShiftOutBits
*
* Description: This routine shifts data bits out to the EEPROM.
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
* data - data to send to the EEPROM.
* count - number of data bits to shift out.
*
* Returns: (none)
*/
static void
ShiftOutBits( ethPciInfo *bdp, ushort_t data, ushort_t count )
{
ushort_t x, mask;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -