📄 8019.c
字号:
/* +++=>>> * %n Edition: %v Last changed: %f By: %w */
/* ne2000.c Edition: 12 Last changed: 22-Jun-00,16:23:36 By: BRIANS
RTL8019.C -- Novell Standard Ethernet Driver for USNET
*/
#include <string.h>
#include <stdio.h>
/* #include "net.h"
#include "local.h"
#include "driver.h"
#include "support.h"
#include "ethernet.h" */
#define RO 0x00 /* offset to registers */
#include "..\inc\rtl8019.h"
#include "..\inc\44b.h"
//int ussCRCHash(char *macaddr);
void page(uint32 tportbase, uint8 pageno); //select pag e
#define _inb(addr) ussIn8( ((uint32)(addr)) )
#define _outb(addr,val) ussOut8( ((uint32)(addr)), ((uint8)(val)) )
#define SM_TSTART_PG 0x040 /* First page of TX buffer */
#define SM_RSTART_PG 0x46 /* Starting page of RX ring */
#define SM_RSTOP_PG 0x80 /* Last page +1 of RX ring */
#define SHAPAGE 256 /* shared memory page size */
#define MAXSIZ (MAXBUF - MESSH_SZ)
static unsigned long loopc;
static unsigned char MARImage[ 64 ];
unsigned char mac_buffer[6] = {0x00, 0x20,0x4a,0x64,0x00,0x00};
/*
mac_buffer[0] = 0x00;
mac_buffer[1] = 0x20;
mac_buffer[2] = 0x4A;
mac_buffer[3] = 0x64;
mac_buffer[4] = 0x00;
mac_buffer[5] = 0x00;
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
**
** init() Initialize controller
**
** int init(int netno, char *params);
**
** PARAMETERS:
** (in) netno Index into nets[] array
** (in) params Pointer to parameter list
**
** RETURNS:
** 0 Initialization successful
** NE_PARAM Bad parameters
**
** DESCRIPTION:
** Configure and start up the ethernet controller. Process the
** user-level text parameters and store the values into the net
** table. Read the address from the Ethernet board and set up the
** board. Store the interrupt address and enable the interrupt.
**
** USAGE/COMMENTS:
** Called indirectly using pointer defined in PTABLE
**
** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
**
** MODIFICATION HISTORY:
**
** 22-JUN-2000 BTS Only enable MC when MC support is included
** 19-JAN-1999 SCD Add function header
**
** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
//s3c44b0x init for RTL8019 chip
void S3c44b0x_init_for_RTL8019(void)
{
uint i = 0;
//PCONB PB7 = 1 select nGCS2
rPCONB |= (0x01<<7);
//PCONG PG3->7:6 = 11 select EINT3
rPCONG |= (0x03<<6);
//rPUPG PG3->3 = 1 pull up enable
rPUPG |= (0x01<<3);
//rEXTINT EINT3->14:12 = 000 low
rEXTINT |= (0x01<<14);
rEXTINT &= ~(0x01<<13);
rEXTINT &= ~(0x01<<12);
//nGCS2 16BIT no nWBE no wait
//11:ST2 =0 , 10: WS2 =0 , 9.8: DW2 = 01
rBWSCON |= (0x01<<11);
rBWSCON &= ~(0x01<<10);
rBWSCON &= ~(0x01<<9);
rBWSCON |= (0x01<<8);
//B2_Tacs EQU 0x3 ;4clk
//B2_Tcos EQU 0x3 ;4clk
//B2_Tacc EQU 0x7 ;14clk
//B2_Tcoh EQU 0x3 ;4clk
//B2_Tah EQU 0x3 ;4clk
//B2_Tacp EQU 0x3 ;6clk
//B2_PMC EQU 0x0 ;normal(1data)
rBANKCON2 = 0x0700;
//rPCONE PE3->7:6 = 01 output
rPCONE &= ~(0x01<<7);
rPCONE |= (0x01<<6);
//rPUPE PE3->3 = 1 pull up enable
rPUPE |= (0x01<<3);
//rPDATE PE3 = 1 -> 0 => rst 8019
rPDATE |= (0x01<<3);
for(i=0;i<200000;i++);
rPDATE &= ~(0x01<<3);
for(i=0;i<200000;i++);
}
int init8019()
{
int i1;
int i2;
int i3;
int tport;
short *spt;
char *cp1;
char par[16];
char val[16];
unsigned long ul1;
//struct NET *netp;
// Nprintf( "NE2000.Init\n" );
/*
netp = &nets[ netno ];
for( cp1=params; *cp1; )
{
Nsscanf(cp1, "%[^=]=%s %n", par, val, &i1);
cp1 += i1;
if( strcmp( par, "IRNO" ) == 0 )
Nsscanf( val, "%i", &netp->irno[0] );
else if( strcmp( par, "PORT" ) == 0 )
Nsscanf( val, "%i", &netp->port );
else if (strcmp(par, "ENA") == 0) //Lin added according YuanFen
Nsscanf(val, "%i", &netp->base[0]);
}
i1 = netp->protoc[2]->init(netno, params);
if( i1 < 0 )
return i1;
tport = netp->port;
netp->bps = 10000000;
*/
tport = 0x02000000;
S3c44b0x_init_for_RTL8019();
//-----------------------------------------------------------------
//Stop the controller
_outb(tport+CMDR, MSK_STP + MSK_RD2); /* stop the controller */
i1 = _inb( tport + RESET ); /* reset the board */
_outb( tport + RESET, i1 );
for (i2=0; i2<9000; i2++); /* delay */
uss_printf("1) ID CMDR=0x%02x,ISR=0x%02x,ID=0x%02x,0x%02x\n",
_inb(tport+CMDR), _inb(tport+ISR),_inb(tport+ 0x0a), _inb(tport+0x0b) );
page(tport, 1);
//read curr
uss_printf("CMDR=0x%02x,CURR=0x%02x\n",
_inb(tport+CMDR), _inb(tport+CURR));
page(tport, 0);
_outb(tport+ISR, 0xff); /* clear and mask interrupts */
_outb(tport+IMR, 0);
_outb(tport+DCR, MSK_BMS+MSK_FT10); /* configure */
// read page0
uss_printf("CMDR=0x%02x,ISR=0x%02x,ID=0x%02x,0x%02x\n", _inb(tport+CMDR), _inb(tport+ISR),_inb(tport+ 0x0a), _inb(tport+0x0b) );
/* get Ethernet address */
// NE2000_ussGetMACAddress( netno, &netp->id.c[ 0 ] );
// spt = (short *)&netp->id; /* get Ethernet address */
//if ((spt[0] | spt[1] | spt[2]) == 0) /* unless configured */
// memcpy(netp->id.c, (char *)netp->base[0], Eid_SZ);
_outb(tport+CMDR, MSK_PG1+MSK_RD2); /* initial physical addr */
for (i1=0; i1<Eid_SZ; i1++)
_outb(tport+PAR+i1, mac_buffer[i1]);
for (i1=0; i1<MARsize; i1++) /* clear multicast */
_outb(tport+MAR+i1, 0);
_outb(tport+CURR, SM_RSTART_PG); /* current RX page */
//read page1
uss_printf("CMDR= 0X%02x, CURR= 0x%02x", _inb(tport+CMDR) , _inb(tport+CURR));
//mac 00 20 4a 64 00 00
for( i1 = 0; i1 < Eid_SZ; i1++ )
{
Nprintf( "0x%02x, ", _inb(tport + PAR + i1));
}
Nprintf( "\n multicase addr");
//multicase
for (i1=0; i1<MARsize; i1++) /* clear multicast */
{
Nprintf( "0x%02x, ", _inb(tport + MAR + i1));
}
Nprintf("\n");
// page(tport, 2);
//read IMR, DCR
// Nprintf("CMDR = 0x%02x, DCR = 0x%02x, IMR = 0x%02x ", _inb(tport+CMDR) , _inb(tport+DCR), _inb(tport+IMR) );
page(tport, 0);
uss_printf("CMDR=0x%02x,ISR=0x%02x,ID=0x%02x,0x%02x\n",
_inb(tport+CMDR), _inb(tport+ISR),_inb(tport+ 0x0a), _inb(tport+0x0b) );
_outb(tport+CMDR, MSK_PG0+MSK_RD2);
_outb(tport+PSTART, SM_RSTART_PG);
_outb(tport+BNRY, SM_RSTART_PG-1);
_outb(tport+PSTOP, SM_RSTOP_PG);
_outb(tport+IMR, 0x17); /* enable interrupts */
_outb(tport+RCR, MSK_MON); /* disable the rxer */
_outb(tport+TCR, 0); /* normal operation */
// page(tport, 0);
_outb(tport+CMDR, MSK_STA+MSK_RD2); /* put 8390 on line */
_outb(tport+RCR, MSK_AB + MSK_PRO + MSK_AM); //softmcu modifed here with question of mac addr /* accept broadcast */
//delay
for (i1=0; i1<2000; i1++);
//read page 0 new set
page(tport, 2);
Nprintf("CMDR = 0x%02x, PSTART = 0x%02x, PSTOP = 0x%02x, IMR = 0x%02x, RCR = 0x%02x, TCR= 0x%02x\n",
_inb(tport+CMDR) , _inb(tport+PSTART), _inb(tport+PSTOP), _inb(tport+IMR), _inb(tport+RCR),_inb(tport+TCR));
Nprintf("CMDR = 0x%02x, PSTART = 0x%02x, PSTOP = 0x%02x, IMR = 0x%02x, RCR = 0x%02x, TCR= 0x%02x\n",
_inb(tport+CMDR) , _inb(tport+PSTART), _inb(tport+PSTOP), _inb(tport+IMR), _inb(tport+RCR),_inb(tport+TCR));
page(tport, 0);
_outb(tport + ISR, 0xff);
uss_printf("CMDR=0x%02x,ISR=0x%02x,ID=0x%02x,0x%02x\n",
_inb(tport+CMDR), _inb(tport+ISR),_inb(tport+ 0x0a), _inb(tport+0x0b) );
/*
page(tport, 2);
Nprintf("CMDR = 0x%02x, RCR = 0x%02x", _inb(tport+CMDR) , _inb(tport+RCR));
*/
page(tport, 0);
/* calibrate a delay loop for 2 milliseconds */
loopc = 1024;
for (i1=0; i1<8092; i1++)
{
}
// for (i1=(int)TimeMS(); i1==(i2=(int)TimeMS()); ) ;
// for (i3=0; i2==(i1=(int)TimeMS()); i3++)
// for (ul1=0; ul1<loopc; ul1++) ;
loopc = (unsigned long)i3 * (unsigned long)(2048/(i1-i2));
// IRinstall(netp->irno[0], netno, irhan);
/*
DISABLE();
rINTMSK=~(BIT_EINT3 |BIT_TIMER0|BIT_ZDMA0|BIT_URXD0|BIT_URXD1 |BIT_GLOBAL); //Default value=0x7ffffff
pISR_EINT3= (unsigned)Rtl8019_IsrHandle; //modified by softmcu
rI_ISPC = BIT_EINT3;
ENABLE();
*/
#if NTRACE >= 1
page(tport, 1);
page(tport, 1);
uss_printf("CMDR= 0x%02x, CURR= 0x%02x" , _inb(tport+CMDR) , _inb(tport+CURR) );
//mac 00 20 4a 64 00 00
Nprintf( "RTL8019 MAC ");
for( i1 = 0; i1 < Eid_SZ; i1++ )
{
Nprintf( "0x%02x, ", _inb(tport + PAR + i1));
}
Nprintf( "\n multicase addr");
//multicase
for (i1=0; i1<MARsize; i1++) /* clear multicast */
{
Nprintf( "0x%02x, ", _inb(tport + MAR + i1));
}
Nprintf("\n");
#endif
return 0;
/*
// Nprintf("page3 9346CR=0x%02x, CONFIG3=0x%02x, CONFIG1=0x%02x\n " ,
// _inb(tport + 0x01), _inb(tport + CONFIG3), _inb(tport + CONFIG1));
// _outb(tport + 0x01, 0x00 ); //set 9346CR EEM1=EEM0=0
// Nprintf("page3 9346CR=0x%02x, CONFIG3=0x%02x, CONFIG1=0x%02x\n " ,
// _inb(tport + 0x01), _inb(tport + CONFIG3), _inb(tport + CONFIG1));
for(i1=0; i1<2000; i1++); //delay
for( i1 = 0; i1 < Eid_SZ; i1++ )
{
_outb( tport + PAR + i1, netp->id.c[i1] );
}
for(i1=0; i1<2000; i1++); //delay
//print out mac
Nprintf( "RTL8019 MAC ");
for( i1 = 0; i1 < Eid_SZ; i1++ )
{
Nprintf( "0x%02x, ", _inb(tport + PAR + i1));
}
Nprintf( "\n");
IRinstall( netp->irno[0], netno, irhan );
page(tport, 0);
Nprintf( "RTL8019 Chip Id 0x%02x:0x%02x\n", _inb( tport + 0x0a ), _inb( tport + 0x0b ) );
*/
//-----------------------------------------------------------------
}
void page(uint32 tportbase, uint8 pageno)
{
uint8 temp1,temp2;
temp1=0x3f&_inb(tportbase + CMDR);
temp1=temp1|(pageno<<6)|0x20;
_outb(tportbase + CMDR,temp1);
temp2=((uint8)_inb(tportbase + CMDR))>>6;
if (pageno==temp2)
Nprintf("\tSelect page %d, CMDR=0x%02x, ",temp2, _inb(tportbase+CMDR));
else Nprintf("Select page ERROR");
}
//unsigned int _inb( unsigned int port)
uint ussIn8(uint port)
{
unsigned int val;
val = *( (volatile unsigned char *) (port<<1) );
return val;
}
void ussOut8( uint32 port, uint8 val)
{
*(volatile unsigned char *)(port<<1) = ((unsigned char)(val));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -