Browse Source

Add the RTL8169 and sundance NIC driver MAC modify function using the unit interface.

master
root 16 years ago
parent
commit
25add4244e
  1. 2
      Targets/Bonito2fdev/conf/Bonito.2fdev.via
  2. 2
      pmon/cmds/mycmd.c
  3. 6
      sys/dev/pci/em/e1000_hw.c
  4. 3
      sys/dev/pci/em/e1000_pmon.c
  5. 10
      sys/dev/pci/em/if_em.c
  6. 8
      sys/dev/pci/if_fxp.c
  7. 18
      sys/dev/pci/rtl8139.c
  8. 105
      sys/dev/pci/rtl8169.c
  9. 429
      sys/dev/pci/sundance.c

2
Targets/Bonito2fdev/conf/Bonito.2fdev.via

@ -135,6 +135,8 @@ em* at pci? dev ? function ? #intel 82541 E1000 Device
fxp* at pci? dev ? function ? # Intel 82559 Device
#inphy* at mii? phy ? # Intel 82555 PHYs
rtl* at pci? dev ? function ?
rtk* at pci? dev ? function ?
ste* at pci? dev ? function ?
#uhci* at pci? dev ? function ?
#ohci0 at pci? dev ? function ?
#usb* at usbbus ?

2
pmon/cmds/mycmd.c

@ -1151,7 +1151,7 @@ printf("status:%s %s\n",ifr->ifr_flags&IFF_UP?"up":"down",ifr->ifr_flags&IFF_RUN
}
else if(argc>=3)
{
char *cmds[]={"down","up","remove","stat","setmac","reprom","wrprom"};
char *cmds[]={"down","up","remove","stat","setmac","readrom","writerom"};
int i;
for(i=0;i<sizeof(cmds)/sizeof(char *);i++)
if(!strcmp(argv[2],cmds[i]))break;

6
sys/dev/pci/em/e1000_hw.c

@ -3204,12 +3204,14 @@ e1000_update_eeprom_checksum(struct e1000_hw *hw)
for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
printf("%d EEPROM Read Error\n",i);
DEBUGOUT("EEPROM Read Error\n");
return -E1000_ERR_EEPROM;
}
checksum += eeprom_data;
}
checksum = (uint16_t) EEPROM_SUM - checksum;
printf("The em1000 checksum is the 0x%4x \n",checksum);
if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
DEBUGOUT("EEPROM Write Error\n");
return -E1000_ERR_EEPROM;
@ -3238,7 +3240,6 @@ e1000_write_eeprom(struct e1000_hw *hw,
int32_t status = 0;
DEBUGFUNC("e1000_write_eeprom");
/* A check for invalid values: offset too large, too many words, and not
* enough words.
*/
@ -3348,8 +3349,7 @@ e1000_write_eeprom_microwire(struct e1000_hw *hw,
uint32_t eecd;
uint16_t words_written = 0;
uint16_t i = 0;
DEBUGFUNC("e1000_write_eeprom_microwire");
DEBUGFUNC("e1000_write_eeprom_microwire \n");
/* Send the write enable command to the EEPROM (3-bit opcode plus
* 6/8-bit dummy address beginning with 11). It's less work to include

3
sys/dev/pci/em/e1000_pmon.c

@ -995,7 +995,8 @@ static inline void pci_disable_device(struct pci_dev *dev) { }
void wmb(void){}
void mdelay(int ms){}
void udelay(int us){}
//void udelay(int us){}
#define udelay delay
#define MODULE_PARM(...)
#define MODULE_PARM_DESC(...)

10
sys/dev/pci/em/if_em.c

@ -617,7 +617,7 @@ int cmd_wrprom_em0(int ac,char *av)
printf("write the whole eeprom\n");
#if 1
clocks_num =CPU_GetCOUNT(); // clock();
clocks_num =CPU_GetCOUNT();
mysrand(clocks_num);
for( i = 0; i < 4;i++ )
{
@ -674,12 +674,12 @@ static const Optdesc netdmp_opts[] =
static const Cmd Cmds[] =
{
{"em0"},
{"setmac_em0", "", NULL,
{"em"},
{"setmac_em", "", NULL,
"Set mac address into E1000 eeprom", cmd_setmac_em0, 1, 5, 0},
{"reprom_em0", "", NULL,
{"readrom_em", "", NULL,
"dump E1000 eprom content", cmd_reprom_em0, 1, 2, 0},
{"wrprom_em0", "", NULL,
{"writerom_em", "", NULL,
"write E1000 eprom content", cmd_wrprom_em0, 1, 2, 0},
{0, 0}
};

8
sys/dev/pci/if_fxp.c

@ -2296,12 +2296,12 @@ static const Optdesc netdmp_opts[] =
static const Cmd Cmds[] =
{
{"fxp0"},
{"setmac_fxp0", "", NULL,
{"fxp"},
{"setmac_fxp", "", NULL,
"Set mac address into E100 eeprom", cmd_setmac_fxp0, 1, 5, 0},
{"reprom_fxp0", "", NULL,
{"readrom_fxp", "", NULL,
"dump E100 eprom content", cmd_reprom_fxp0, 1, 2, 0},
{"wrprom_fxp0", "", NULL,
{"writerom_fxp", "", NULL,
"write E100 eprom content", cmd_wrprom_fxp0, 1, 2, 0},
{0, 0}
};

18
sys/dev/pci/rtl8139.c

@ -1734,11 +1734,6 @@ int cmd_wrprom(int ac,char *av)
printf("Now beginningwrite whole eprom\n");
for(i=0; i< 64; i++)
{
eeprom_data = rom[i];
write_eeprom(ioaddr, i, eeprom_data);
}
#if 1
clocks_num =CPU_GetCOUNT(); // clock();
mysrand(clocks_num);
@ -1748,12 +1743,17 @@ int cmd_wrprom(int ac,char *av)
printf( " tmp[%d]=02x%x\n", i,tmp[i]);
}
eeprom_data =tmp[1] |( tmp[0]<<8);
rom[8] = eeprom_data;
printf("eeprom_data [8] = 0x%4x\n",eeprom_data);
write_eeprom(ioaddr, 8, eeprom_data) ;
eeprom_data =tmp[3] |( tmp[2]<<8);
rom[9] = eeprom_data;
printf("eeprom_data [9] = 0x%4x\n",eeprom_data);
write_eeprom(ioaddr, 9, eeprom_data) ;
#endif
for(i=0; i< 64; i++)
{
eeprom_data = rom[i];
write_eeprom(ioaddr, i, eeprom_data);
}
printf("Write the whole eeprom OK!\n");
return 0;
@ -1816,9 +1816,9 @@ static const Cmd Cmds[] =
"Set 8139 interface mode", cmd_ifm, 1, 2, 0},
{"setmac", "", NULL,
"Set mac address into 8139 eeprom", cmd_setmac, 1, 5, 0},
{"reprom", "", NULL,
{"readrom", "", NULL,
"dump rtl8139 eprom content", cmd_reprom, 1, 1,0},
{"wrprom", "", NULL,
{"writerom", "", NULL,
"write the whole rtl8139 eprom content", cmd_wrprom, 1, 1,0},
{0, 0}
};

105
sys/dev/pci/rtl8169.c

@ -1632,6 +1632,7 @@ rtl8169_init_board(struct rtl8169_private *tp, struct pci_attach_args *pa)
}
static struct rtl8169_private* myRTL = NULL;
static int rtl8169_open(struct rtl8169_private *tp);
static int
@ -1688,6 +1689,27 @@ rtl8169_ether_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data)
}
break;
case SIOCETHTOOL:
{
long *p=data;
myRTL = sc;
cmd_setmac(p[0],p[1]);
}
break;
case SIOCRDEEPROM:
{
long *p=data;
myRTL = sc;
cmd_reprom(p[0],p[1]);
}
break;
case SIOCWREEPROM:
{
long *p=data;
myRTL = sc;
cmd_wrprom(p[0],p[1]);
}
break;
default:
RTLDBG;
error = EINVAL;
@ -1739,7 +1761,6 @@ static int rtl8169_set_hard_speed(struct rtl8169_private *tp,
}
static struct rtl8169_private* myRTL = NULL;
static void
r8169_attach(struct device * parent, struct device * self, void *aux)
@ -2982,7 +3003,7 @@ rtl8169_set_rx_mode(struct rtl8169_private *tp)
#if 1
#include <pmon.h>
int cmd_ifm(int ac, char *av[])
static int cmd_ifm(int ac, char *av[])
{
unsigned short fullduplex = 0;
unsigned short speed1000 = 0;
@ -3046,7 +3067,73 @@ REMIND:
return 0;
}
int cmd_setmac(int ac, char *av[])
#if 1
static unsigned long next = 1;
/* RAND_MAX assumed to be 32767 */
static int myrand(void) {
next = next * 1103515245 + 12345;
return((unsigned)(next/65536) % 32768);
}
static void mysrand(unsigned int seed) {
next = seed;
}
#endif
static int cmd_wrprom(int ac, char *av[])
{
int i;
unsigned long clocks_num=0;
unsigned short data;
static unsigned char rom[]={
/*00000000:*/0x29,0x81,0xec,0x10,0x69,0x81,0xec,0x10,0x69,0x81,0x20,0x40,0x01,0xa1,0x00,0xe0,
/*00000010:*/0x4c,0x67,0x10,0x51,0x15,0xcd,0xc2,0xf7,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x13,
/*00000020:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*00000030:*/0x00,0x00,0xd7,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,
/*00000040:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*00000050:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*00000060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*00000070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
if(!myRTL){
printf("8169 interface not initialized\n");
return 0;
}
#if 1
clocks_num =CPU_GetCOUNT();
mysrand(clocks_num);
for( i = 0; i < 4;i++ )
{
rom[0x8*2 + i]=myrand()%256;
printf( " rom[%d]=02x%x\n", (0x8*2+i),rom[0x8*2+i]);
}
#endif
for(i=0;i<0x40;i++)
{
while(1){
#ifndef EPLC46
data = read_eeprom(myRTL, i);
#else
data = read_eeprom(myRTL, 2*i);
data = data | (read_eeprom(myRTL,2*i+1)) << 8;
#endif
if(data==((rom[2*i+1]<<8)|rom[2*i]))break;
printf("program %02x:%04x\n",2*i,(rom[2*i+1]<<8)|rom[2*i]);
#ifndef EPLC46
rtl8169_write_eeprom(myRTL->ioaddr, i, (rom[2*i+1]<<8)|rom[2*i]);
#else
rtl8169_write_eeprom8(myRTL->ioaddr, i*2, rom[2*i] );
rtl8169_write_eeprom8(myRTL->ioaddr, i*2+1, rom[2*i+1]);
#endif
};
}
printf("The whole eeprom have been programmed!\n");
}
static int cmd_setmac(int ac, char *av[])
{
int i;
unsigned short val = 0, v;
@ -3113,7 +3200,7 @@ printf("program %02x:%04x\n",2*i,(rom[2*i+1]<<8)|rom[2*i]);
return 0;
}
int cmd_reprom(int ac, char *av)
static int cmd_reprom(int ac, char *av)
{
int i;
unsigned short data;
@ -3133,7 +3220,7 @@ int cmd_reprom(int ac, char *av)
}
return 0;
}
void cmd_set_frequency(int ac, char *av[])
static void cmd_set_frequency(int ac, char *av[])
{
char* par[] = {"1000", "100","1","0",};
@ -3161,7 +3248,7 @@ void cmd_set_frequency(int ac, char *av[])
return;
}
int cmd_set_8110()
static int cmd_set_8110()
{
int auto_nego, giga_ctrl;
@ -3206,7 +3293,7 @@ int cmd_set_8110()
}
int db8169 = 0;
int netdmp_cmd (int ac, char *av[])
static int netdmp_cmd (int ac, char *av[])
{
struct ifnet *ifp;
int i;
@ -3266,8 +3353,10 @@ static const Cmd Cmds[] =
"Set 8169 interface mode", cmd_ifm, 1, 2, 0},
{"setmac", "", NULL,
"Set mac address into 8169 eeprom", cmd_setmac, 1, 5, 0},
{"reprom", "", NULL,
{"readrom", "", NULL,
"dump rtl8169 eprom content", cmd_reprom, 1, 1,0},
{"writerom", "", NULL,
"dump rtl8169 eprom content", cmd_wrprom, 1, 1,0},
{"r8169dump", "", NULL, "dump rtl8169 parameters", netdmp_cmd, 1, 2, 0},
{"r8110_reneo","",NULL, "set re-auto xx of rtl 8110 phy", cmd_set_8110,1,2,0},
{"r8110_speed","",NULL, "disable/enable 8110 ifaddr config retry for 1000M/100M", cmd_set_frequency,1,3,0},

429
sys/dev/pci/sundance.c

@ -166,6 +166,19 @@ static int mysleep(int ms)
return 0;
}
#define RTL_W8(tp, reg, val8) iowrite8 ((val8), tp->base_addr + (reg))
#define RTL_W16(tp, reg, val16) iowrite16 ((val16), tp->base_addr + (reg))
#define RTL_W32(tp, reg, val32) iowrite32 ((val32), tp->base_addr + (reg))
#define RTL_R8(tp, reg) ioread8 (tp->base_addr + (reg))
#define RTL_R16(tp, reg) ioread16 (tp->base_addr + (reg))
#define RTL_R32(tp, reg) ((unsigned long) ioread32 (tp->base_addr + (reg)))
#define EEPROMDATA 0x34
#define EEPROMCTRL 0x36
#define EEP_BUSY 0x8000
#define EEP_WRITE 0x0100
#define EEP_READ 0x0200
#define MII_BMCR 0x00 /* Basic mode control register */
#define MII_BMSR 0x01 /* Basic mode status register */
@ -342,7 +355,7 @@ char name[IFNAMSIZ];
unsigned char perm_addr[6]; /* permanent hw address */
};
const static struct pci_device_id *
pci_match_device(const struct pci_device_id *ids, struct pci_attach_args *pa )
pci_match_device(const struct pci_device_id *ids, struct pci_attach_args *pa )
{
unsigned short vendor;
unsigned short device,class;
@ -370,8 +383,7 @@ pci_match_device(const struct pci_device_id *ids, struct pci_attach_args *pa )
}
void
pci_free_consistent(struct pci_dev *pdev, size_t size, void *cpu_addr,
static void pci_free_consistent(struct pci_dev *pdev, size_t size, void *cpu_addr,
dma_addr_t dma_addr)
{
kfree(cpu_addr);
@ -391,6 +403,8 @@ void *buf;
return (void *)buf;
}
static unsigned short read_eeprom(unsigned long ioaddr,unsigned int eep_addr);
static void write_eeprom(unsigned long ioaddr, unsigned int eep_addr, unsigned short writedata);
struct sk_buff {
unsigned int len; /* Length of actual data */
@ -489,7 +503,7 @@ static struct mbuf * getmbuf()
return m;
}
inline int netif_rx(struct sk_buff *skb)
static inline int netif_rx(struct sk_buff *skb)
{
struct mbuf *m;
struct ether_header *eh;
@ -734,6 +748,10 @@ enum mac_ctrl0_bits {
EnbFullDuplex=0x20, EnbRcvLargeFrame=0x40,
EnbFlowCtrl=0x100, EnbPassRxCRC=0x200,
};
/*Bits in the PHY-CTRL registers*/
enum phy_ctrl_bits{
PhyDuplexStatus=0x20,PhySpeedStatus=0x40,PhyLinkStatus=0x80,
};
enum mac_ctrl1_bits {
StatsEnable=0x0020, StatsDisable=0x0040, StatsEnabled=0x0080,
TxEnable=0x0100, TxDisable=0x0200, TxEnabled=0x0400,
@ -844,6 +862,86 @@ static struct net_device_stats *get_stats(struct net_device *dev);
static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
static int netdev_close(struct net_device *dev);
void delay10us(void)
{
volatile int i = 0;
for(i = 0; i<1000 ;)
i++;
// usleep(10);
}
#if 0
void mdelay(int ii)
{
volatile int j;
for(;ii>0;ii--)
for(j=0;j<100000;)
j++;
}
#endif
unsigned short outpw(unsigned long WR_ADDR,unsigned short WR_VAL)
{
*( (volatile unsigned short *) WR_ADDR ) = WR_VAL ;
return WR_VAL;
}
unsigned short inpw(unsigned long RD_ADDR)
{
unsigned short RD_VAL;
RD_VAL = *( (volatile unsigned short *) RD_ADDR ) ;
return RD_VAL;
}
static void write_eeprom(unsigned long ioaddr_1, unsigned int eep_addr, unsigned short writedata)
{
unsigned short v = 0;
unsigned long uIOBase=ioaddr_1;
int i = 0;
v=outpw (uIOBase + EEPROMDATA, writedata );
while ( (inpw(uIOBase + EEPROMCTRL) & EEP_BUSY ) &&(i<20000) )
{
i++;
}
v=outpw (uIOBase + EEPROMCTRL, 0xC0 );
while ( (inpw(uIOBase + EEPROMCTRL) & EEP_BUSY ) &&(i<20000) )
{
i++;
}
v=outpw (uIOBase + EEPROMCTRL, EEP_WRITE | (eep_addr & 0xff) );
while ( (inpw(uIOBase + EEPROMCTRL) & EEP_BUSY ) &&(i<20000) )
{
i++;
}
for( i = 0; i < 400; i++ )
{
delay10us();
}
}
static unsigned short read_eeprom(unsigned long ioaddr_1, unsigned int eep_addr)
{
unsigned int v = 0;
int i = 10000;
unsigned long uIOBase=ioaddr_1;
v=outpw (uIOBase + EEPROMCTRL, EEP_READ | (eep_addr & 0xff));
while (i-- > 0) {
delay10us();
if (!(inpw(uIOBase + EEPROMCTRL) & EEP_BUSY)) {
return inpw(uIOBase + EEPROMDATA);
}
}
return 0;
}
static void sundance_reset(struct net_device *dev, unsigned long reset_cmd)
{
struct netdev_private *np = netdev_priv(dev);
@ -862,6 +960,7 @@ static void sundance_reset(struct net_device *dev, unsigned long reset_cmd)
udelay(100);
}
}
int phys[4];
static int sundance_probe1 (struct net_device *dev,struct pci_dev *pdev,
const struct pci_device_id *ent)
{
@ -961,6 +1060,7 @@ static int sundance_probe1 (struct net_device *dev,struct pci_dev *pdev,
}
np->mii_if.phy_id = np->phys[0];
phys[0] = ( np->phys[0]& 0x1f ); //zgj
/* Parse override configuration */
np->an_enable = 1;
@ -1852,7 +1952,7 @@ static int netdev_close(struct net_device *dev)
//----------------------------------------------------------
void netdev_init(struct net_device *netdev,struct pci_attach_args *pa)
static void netdev_init(struct net_device *netdev,struct pci_attach_args *pa)
{
unsigned short vendor;
unsigned short device,class;
@ -1923,7 +2023,7 @@ struct ifnet *ifp = &netdev->arpcom.ac_if;
return 0;
}
struct net_device *mynic_ste;
static void
ste_attach(parent, self, aux)
struct device *parent, *self;
@ -1941,6 +2041,8 @@ ste_attach(parent, self, aux)
//bus_size_t iosize;
#endif
mynic_ste = sc;
/*
* Allocate our interrupt.
*/
@ -2138,6 +2240,27 @@ ste_ether_ioctl(ifp, cmd, data)
}
break;
case SIOCETHTOOL:
{
long *p=data;
mynic_ste = sc;
cmd_setmac_ste(p[0],p[1]);
}
break;
case SIOCRDEEPROM:
{
long *p=data;
mynic_ste = sc;
cmd_reprom_ste(p[0],p[1]);
}
break;
case SIOCWREEPROM:
{
long *p=data;
mynic_ste = sc;
cmd_wrprom_ste(p[0],p[1]);
}
break;
default:
error = EINVAL;
}
@ -2153,3 +2276,297 @@ struct cfattach ste_ca = {
struct cfdriver ste_cd = {
NULL, "ste", DV_IFNET
};
#if 1
#include <pmon.h>
int cmd_ifm_ste(int ac, char *av[])
{
int speed100=0, fullduplex=0, mii_ctrl = 0x0;
struct netdev_private *np = netdev_priv(mynic_ste);
struct net_device *nic_ifm = mynic_ste;
printf("np->phys[0] : %d \n",phys[0]);
if(nic_ifm == NULL){
printf("IP100A interface not initialized\n");
return 0;
}
if(ac !=1 && ac!=2 && ac!=3){
printf("usage: ifm_ip100a [100|10|auto] [full|half]\n");
return 0;
}
if(ac == 1){
speed100 = RTL_R8(nic_ifm , MIICtrl) & PhySpeedStatus ;
fullduplex = RTL_R8(nic_ifm , MIICtrl) & PhyDuplexStatus ;
printf(" %sMbps %s-DUPLEX.\n", speed100 ? "100" : "10",
fullduplex ? "FULL" : "HALF");
return 0;
}
if(strcmp("100", av[1]) == 0){
mii_ctrl = 0;
mii_ctrl |= BMCR_SPEED100;
if(strcmp("full", av[2]) == 0)
mii_ctrl |= BMCR_FULLDPLX ;
else
mii_ctrl &= ~BMCR_FULLDPLX;
printf("mii_ctrl_100 or : 0x%x\n",mii_ctrl);
mdio_write (nic_ifm , phys[0] , MII_BMCR, mii_ctrl);
printf("mii_ctrl_100 write : 0x%x\n",mii_ctrl);
mdelay(10);
mii_ctrl= mdio_read(nic_ifm, phys[0], MII_BMCR);
printf("mii_ctrl_100 read status : 0x%x\n",mii_ctrl);
} else if(strcmp("10", av[1]) ==0){
mii_ctrl = 0x0;
mii_ctrl &= ~BMCR_SPEED100 ;
if(strcmp("full", av[2]) == 0)
mii_ctrl |= BMCR_FULLDPLX ;
else
mii_ctrl &= ~BMCR_FULLDPLX;
printf("mii_ctrl_10 and : 0x%x\n",mii_ctrl);
mdio_write (nic_ifm , phys[0] , MII_BMCR, mii_ctrl);
printf("mii_ctrl_10 write : 0x%x\n",mii_ctrl);
mdelay(10);
mii_ctrl= mdio_read(nic_ifm, phys[0], MII_BMCR);
printf("mii_ctrl_10 read status : 0x%x\n",mii_ctrl);
} else if(strcmp("auto", av[1])==0){
mii_ctrl = 0x0;
mii_ctrl |= BMCR_ANENABLE|BMCR_ANRESTART ;
mdio_write (nic_ifm, phys[0] , MII_BMCR, mii_ctrl);
printf("mii_ctrl_auto write : 0x%x\n",mii_ctrl);
mdelay(10);
mii_ctrl= mdio_read(nic_ifm, phys[0], MII_BMCR);
printf("mii_ctrl_auto read status : 0x%x\n",mii_ctrl);
}
else{
printf("usage: ifm_ip100a [100|10|auto|full|half]\n");
}
return 0;
}
static long long ste_read_mac(struct net_device *nic)
{
int i;
long long mac_tmp = 0;
unsigned short u16tmp;
struct netdev_private *np = netdev_priv(mynic_ste);
struct net_device *nic = mynic_ste;
void *ioaddr = np->base;
for (i = 0; i < 3; i++) {
#if 1
//#ifndef EPLC46
u16tmp = read_eeprom( ioaddr, EEPROM_SA_OFFSET + i);
#else
u16tmp = read_eeprom(nic, ioaddr, (EEPROM_SA_OFFSET + i*2));
u16tmp = u16tmp | (read_eeprom(nic, ioaddr, (EEPROM_SA_OFFSET + i*2 +1)) << 8);
#endif
mac_tmp <<= 16;
mac_tmp |= ((u16tmp & 0xff) << 8) | ((u16tmp >> 8) & 0xff);
printf("ip100a_read_mac 1 : 0x%4x \n",mac_tmp);
}
printf("ip100a_read_mac all : 0x%12x \n",mac_tmp);
return mac_tmp;
}
int cmd_setmac_ste(int ac, char *av[])
{
int i;
unsigned short val = 0, v;
struct netdev_private *np = netdev_priv(mynic_ste);
struct net_device *nic = mynic_ste;
void *ioaddr = np->base;
if(nic == NULL){
printf("IP100A interface not initialized\n");
return 0;
}
#if 0
if (ac != 4) {
printf("MAC ADDRESS ");
for(i=0; i<6; i++){
printf("%02x",nic->arpcom.ac_enaddr[i]);
if(i==5)
printf("\n");
else
printf(":");
}
printf("Use \"setmac word1(16bit) word2 word3\"\n");
return 0;
}
printf("set mac to ");
for (i = 0; i < 3; i++) {
val = strtoul(av[i+1],0,0);
printf("%04x ", val);
write_eeprom(ioaddr, 0x7 + i, val);
}
printf("\n");
printf("The machine should be restarted to make the mac change to take effect!!\n");
#else
if(ac != 2){
long long macaddr;
u_int8_t *paddr;
u_int8_t enaddr[6];
macaddr=ste_read_mac(nic);
paddr=(uint8_t*)&macaddr;
enaddr[0] = paddr[5- 0];
enaddr[1] = paddr[5- 1];
enaddr[2] = paddr[5- 2];
enaddr[3] = paddr[5- 3];
enaddr[4] = paddr[5- 4];
enaddr[5] = paddr[5- 5];
printf("MAC ADDRESS ");
for(i=0; i<6; i++){
printf("%02x",enaddr[i]);
if(i==5)
printf("\n");
else
printf(":");
}
printf("Use \"setmac <mac> \" to set mac address\n");
return 0;
}
for (i = 0; i < 3; i++) {
val = 0;
gethex(&v, av[1], 2);
val = v ;
av[1]+=3;
gethex(&v, av[1], 2);
val = val | (v << 8);
av[1] += 3;
#if 1
//#ifndef EPLC46
iowrite16(val, ioaddr + StationAddr + 2*i); //zgj
write_eeprom(ioaddr, EEPROM_SA_OFFSET + i, val);
#else
write_eeprom8(ioaddr, (EEPROM_SA_OFFSET + i*2 ), val & 0xff);
write_eeprom8(ioaddr, (EEPROM_SA_OFFSET + i*2 + 1), (val >> 8) & 0xff);
#endif
}
#endif
return 0;
}
int cmd_reprom_ste(int ac, char *av)
{
int i;
unsigned short data;
struct netdev_private *np = netdev_priv(mynic_ste);
struct net_device *nic = mynic_ste;
void *ioaddr = np->base;
printf("dump eprom:\n");
for(i=0; i< 64;){
#if 1
//#ifndef EPLC46
data = read_eeprom(ioaddr, i);
#else
data = read_eeprom(mynic_ste, ioaddr, 2*i);
data = data | (read_eeprom(mynic_ste, ioaddr, 2*i+1)) << 8;
#endif
printf("%04x ", data);
++i;
if( i%8 == 0 )
printf("\n");
}
return 0;
}
#if 1
static unsigned long next = 1;
/* RAND_MAX assumed to be 32767 */
static int myrand(void) {
next = next * 1103515245 + 12345;
return((unsigned)(next/65536) % 32768);
}
static void mysrand(unsigned int seed) {
next = seed;
}
#endif
int cmd_wrprom_ste(int ac, char *av)
{
int i=0;
struct netdev_private *np = netdev_priv(mynic_ste);
struct net_device *nic = mynic_ste;
void *ioaddr = np->base;
unsigned long clocks_num=0;
unsigned char tmp[4];
unsigned short eeprom_data;
unsigned short rom[] = {
0x2af8 ,0x8061 ,0x13f0 ,0x0201 ,0x0000 ,0x0000 ,0x0000 ,0x0000,
0x0000 ,0x0000 ,0x8003 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000,
0x0500 ,0x0000 ,0x0400 ,0x0064 ,0x0000 ,0x0000 ,0x0000 ,0x0000,
0x3400 ,0x0100 ,0x3702 ,0x0300 ,0x803a ,0x3f04 ,0x0303 ,0x0103,
0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000,
0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000,
0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000,
0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000 ,0x0000};
printf("Now beginningwrite whole eprom\n");
#if 1
clocks_num =CPU_GetCOUNT();
mysrand(clocks_num);
for( i = 0; i < 4;i++ )
{
tmp[i]=myrand()%256;
printf( " tmp[%d]=02x%x\n", i,tmp[i]);
}
eeprom_data =tmp[1] |( tmp[0]<<8);
printf("eeprom_data [17] = 0x%4x\n",eeprom_data);
rom[17] = eeprom_data;
eeprom_data =tmp[3] |( tmp[2]<<8);
printf("eeprom_data [18] = 0x%4x\n",eeprom_data);
rom[18] = eeprom_data;
#endif
for (i = 0; i < 64; i++)
{
#ifndef EPLC46
write_eeprom(ioaddr, i, rom[i]);
#else
write_eeprom8(ioaddr, 2*i, ((unsigned char *)rom)[2*i]);
write_eeprom8(ioaddr, 2*i+1, ((unsigned char *)rom)[2*i+1]);
#endif
}
}
static const Optdesc netdmp_opts[] =
{
{"<interface>", "Interface name"},
{"<netdmp>", "IP Address"},
{0}
};
static const Cmd Cmds[] =
{
{"IP100A"},
{"ifm_ste", "", NULL,
"Set IP100A interface mode: Usage: ifm_ip100a [100|10|auto] [full|half] ", cmd_ifm_ste, 1, 3, 0},
{"setmac_ste", "", NULL,
"Set mac address into IP100A eeprom", cmd_setmac_ste, 1, 5, 0},
{"readrom_ste", "", NULL,
"dump ip100a eprom content", cmd_reprom_ste, 1, 1,0},
{"writeprom_ste", "", NULL,
"write the whole ip100a eprom content", cmd_wrprom_ste, 1, 1,0},
{0, 0}
};
static void init_cmd __P((void)) __attribute__ ((constructor));
static void
init_cmd()
{
cmdlist_expand(Cmds, 1);
}
#endif

Loading…
Cancel
Save