📄 cmd911x.c
字号:
printf("index 3, PHY identifier 2 = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_3]);
printf("index 4, Auto Negotiation Advertisement Reg = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_4]);
printf("index 5, Auto Negotiation Link Partner Ability Reg = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_5]);
printf("index 6, Auto Negotiation Expansion Register = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_6]);
printf("index 16, Silicon Revision Reg = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_16]);
printf("index 17, Mode Control/Status Reg = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_17]);
printf("index 18, Special Modes = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_18]);
printf("index 20, TSTCNTL = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_20]);
printf("index 21, TSTREAD1 = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_21]);
printf("index 22, TSTREAD2 = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_22]);
printf("index 23, TSTWRITE = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_23]);
printf("index 27, Control/Status Indication = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_27]);
printf("index 28, Special internal testability = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_28]);
printf("index 29, Interrupt Source Register = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_29]);
printf("index 30, Interrupt Mask Register = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_30]);
printf("index 31, PHY Special Control/Status Register = 0x%04lX\n",commandData->IoctlData.Data[PHY_REG_31]);
} else {
printf("Failed to DUMP Phy Registers\n");
}
}
void SetDebugMode(PCOMMAND_DATA commandData,
unsigned long debug_mode)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_SET_DEBUG_MODE;
commandData->IoctlData.Data[0]=debug_mode;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature!=SMSC911x_DRIVER_SIGNATURE) {
printf("Failed to set debug mode.\n");
}
}
void SetLinkMode(PCOMMAND_DATA commandData,
unsigned long link_mode)
{
if(link_mode<=0x7F) {
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_SET_LINK_MODE;
commandData->IoctlData.Data[0]=link_mode;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature!=SMSC911x_DRIVER_SIGNATURE) {
printf("Failed to set link mode.\n");
}
} else {
printf("Invalid Link Mode, %ld\n",link_mode);
}
}
void SetPowerMode(PCOMMAND_DATA commandData,
unsigned long power_mode)
{
if(power_mode<4) {
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_SET_POWER_MODE;
commandData->IoctlData.Data[0]=power_mode;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature!=SMSC911x_DRIVER_SIGNATURE) {
printf("Failed to set power mode.\n");
}
} else {
printf("Invalid Power Mode, %ld\n",power_mode);
}
}
void GetLinkMode(PCOMMAND_DATA commandData)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_GET_LINK_MODE;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
unsigned long link_mode=commandData->IoctlData.Data[0];
printf("link_mode == 0x%02lX == %s,%s,%s,%s,%s,%s,%s\n",
link_mode,
(link_mode&0x40)?"ANEG":"",
(link_mode&0x20)?"SYMP":"",
(link_mode&0x10)?"ASYMP":"",
(link_mode&0x08)?"100FD":"",
(link_mode&0x04)?"100HD":"",
(link_mode&0x02)?"10FD":"",
(link_mode&0x01)?"10HD":"");
} else {
printf("Failed to get link mode\n");
}
}
void CheckLink(PCOMMAND_DATA commandData)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_CHECK_LINK;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
printf("Checked link successfully\n");
} else {
printf("Failed to check link\n");
}
}
void GetPowerMode(PCOMMAND_DATA commandData)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_GET_POWER_MODE;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
printf("PMT_CTRL == 0x%08lX, PM_MODE == D%ld\n",
commandData->IoctlData.Data[0],
(((commandData->IoctlData.Data[0])&0x00030000UL)>>16));
} else {
printf("Failed to get power mode\n");
}
}
void GetFlowParams(PCOMMAND_DATA commandData)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_GET_FLOW_PARAMS;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
const unsigned long * data=commandData->IoctlData.Data;
printf("Flow Control Parameters\n");
printf(" RxFlowMeasuredMaxThroughput = 0x%08lX\n",data[0]);
printf(" RxFlowMeasuredMaxPacketCount = 0x%08lX\n",data[1]);
printf(" RxFlowParameters.MaxThroughput = 0x%08lX\n",data[2]);
printf(" RxFlowParameters.MaxPacketCount = 0x%08lX\n",data[3]);
printf(" RxFlowParameters.PacketCost = 0x%08lX\n",data[4]);
printf(" RxFlowParameters.BurstPeriod = 0x%08lX\n",data[5]);
printf(" RxFlowMaxWorkLoad = 0x%08lX\n",data[6]);
printf(" INT_CFG.INT_DEAS = 0x%08lX\n",data[7]);
} else {
printf("Failed to get flow control parameters\n");
}
}
void GetConfiguration(PCOMMAND_DATA commandData)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_GET_CONFIGURATION;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
const unsigned long * data=commandData->IoctlData.Data;
printf("Compiled: %s\n",commandData->IoctlData.Strng1);
printf("Driver Version = %lX.%02lX\n",
data[0]>>8,data[0]&0xFFUL);
printf("Driver Parameters\n");
printf(" lan_base = 0x%08lX\n",data[1]);
printf(" bus_width = 0x%08lX\n",data[2]);
printf(" link_mode = 0x%08lX\n",data[3]);
printf(" irq = 0x%08lX\n",data[4]);
printf(" int_deas = 0x%08lX\n",data[5]);
printf(" irq_pol = 0x%08lX\n",data[6]);
printf(" irq_type = 0x%08lX\n",data[7]);
printf(" rx_dma = 0x%08lX\n",data[8]);
printf(" tx_dma = 0x%08lX\n",data[9]);
printf(" dma_threshold = 0x%08lX\n",data[10]);
printf(" mac_addr_hi16 = 0x%08lX\n",data[11]);
printf(" mac_addr_lo32 = 0x%08lX\n",data[12]);
printf(" debug_mode = 0x%08lX\n",data[13]);
printf(" tx_fif_sz = 0x%08lX\n",data[14]);
printf(" afc_cfg = 0x%08lX\n",data[15]);
printf(" tasklets = 0x%08lX\n",data[16]);
printf(" max_throughput = 0x%08lX\n",data[17]);
printf(" max_packet_count = 0x%08lX\n",data[18]);
printf(" packet_cost = 0x%08lX\n",data[19]);
printf(" burst_period = 0x%08lX\n",data[20]);
printf(" max_work_load = 0x%08lX\n",data[21]);
printf("privateData\n");
printf(" ifName = \"%s\"\n",
commandData->IoctlData.Strng2);
printf(" dwIdRev = 0x%08lX\n",data[22]);
printf(" dwFpgaRev = 0x%08lX\n",data[23]);
printf(" bPhyAddress = 0x%08lX\n",data[24]);
printf(" dwPhyId = 0x%08lX\n",data[25]);
printf(" bPhyModel = 0x%08lX\n",data[26]);
printf(" bPhyRev = 0x%08lX\n",data[27]);
printf(" dwLinkSpeed = 0x%08lX\n",data[28]);
printf(" RxFlowMeasuredMaxThroughput = 0x%08lX\n",data[29]);
printf(" RxFlowMeasuredMaxPacketCount = 0x%08lX\n",data[30]);
printf(" RxFlowMaxThroughput = 0x%08lX\n",data[31]);
printf(" RxFlowMaxPacketCount = 0x%08lX\n",data[32]);
printf(" RxFlowPacketCost = 0x%08lX\n",data[33]);
printf(" RxFlowBurstPeriod = 0x%08lX\n",data[34]);
printf(" RxFlowMaxWorkLoad = 0x%08lX\n",data[35]);
} else {
printf("Failed to get driver configuration\n");
}
}
void ReadByte(PCOMMAND_DATA commandData,unsigned long address)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_READ_BYTE;
commandData->IoctlData.Data[0]=address;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
printf("Memory Address == 0x%08lX, Read Value == 0x%02lX\n",
commandData->IoctlData.Data[0],
commandData->IoctlData.Data[1]&0xFFUL);
} else {
printf("Failed to Read Memory\n");
}
}
void ReadWord(PCOMMAND_DATA commandData, unsigned long address)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_READ_WORD;
commandData->IoctlData.Data[0]=address;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
printf("Memory Address == 0x%08lX, Read Value == 0x%04lX\n",
commandData->IoctlData.Data[0],
commandData->IoctlData.Data[1]&0xFFFFUL);
} else {
printf("Failed to Read Memory\n");
}
}
void ReadDWord(PCOMMAND_DATA commandData,unsigned long address)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_READ_DWORD;
commandData->IoctlData.Data[0]=address;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
printf("Memory Address == 0x%08lX, Read Value == 0x%08lX\n",
commandData->IoctlData.Data[0],
commandData->IoctlData.Data[1]);
} else {
printf("Failed to Read Memory\n");
}
}
void WriteByte(PCOMMAND_DATA commandData,unsigned long address, unsigned long data)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_WRITE_BYTE;
commandData->IoctlData.Data[0]=address;
commandData->IoctlData.Data[1]=data&0xFFUL;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature!=SMSC911x_DRIVER_SIGNATURE) {
printf("Failed to Write Memory\n");
}
}
void WriteWord(PCOMMAND_DATA commandData,unsigned long address, unsigned long data)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_WRITE_WORD;
commandData->IoctlData.Data[0]=address;
commandData->IoctlData.Data[1]=data&0xFFFFUL;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature!=SMSC911x_DRIVER_SIGNATURE) {
printf("Failed to Write Memory\n");
}
}
void WriteDWord(PCOMMAND_DATA commandData,unsigned long address, unsigned long data)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_WRITE_DWORD;
commandData->IoctlData.Data[0]=address;
commandData->IoctlData.Data[1]=data;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature!=SMSC911x_DRIVER_SIGNATURE) {
printf("Failed to Write Memory\n");
}
}
void LanGetReg(PCOMMAND_DATA commandData,unsigned long address)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_LAN_GET_REG;
commandData->IoctlData.Data[0]=address;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
printf("Mem Map Offset == 0x%08lX, Read Value == 0x%08lX\n",
commandData->IoctlData.Data[0],
commandData->IoctlData.Data[1]);
} else {
printf("Failed to Read Register\n");
}
}
void LanSetReg(PCOMMAND_DATA commandData, unsigned long address, unsigned long data)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_LAN_SET_REG;
commandData->IoctlData.Data[0]=address;
commandData->IoctlData.Data[1]=data;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature!=SMSC911x_DRIVER_SIGNATURE) {
printf("Failed to Write Register\n");
}
}
void MacGetReg(PCOMMAND_DATA commandData, unsigned long address)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_MAC_GET_REG;
commandData->IoctlData.Data[0]=address;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
printf("Mac Index == 0x%08lX, Read Value == 0x%08lX\n",
commandData->IoctlData.Data[0],
commandData->IoctlData.Data[1]);
} else {
printf("Failed to read Mac Register\n");
}
}
void MacSetReg(
PCOMMAND_DATA commandData,
unsigned long address, unsigned long data)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_MAC_SET_REG;
commandData->IoctlData.Data[0]=address;
commandData->IoctlData.Data[1]=data;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature!=SMSC911x_DRIVER_SIGNATURE) {
printf("Failed to Write Mac Register\n");
}
}
void PhyGetReg(PCOMMAND_DATA commandData, unsigned long address)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_PHY_GET_REG;
commandData->IoctlData.Data[0]=address;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature==SMSC911x_DRIVER_SIGNATURE) {
printf("Phy Index == 0x%08lX, Read Value == 0x%08lX\n",
commandData->IoctlData.Data[0],
commandData->IoctlData.Data[1]);
} else {
printf("Failed to Read Phy Register\n");
}
}
void PhySetReg(
PCOMMAND_DATA commandData,
unsigned long address, unsigned long data)
{
if(commandData==NULL) return;
commandData->IfReq.ifr_data=(void *)&(commandData->IoctlData);
commandData->IoctlData.dwSignature=SMSC911x_APP_SIGNATURE;
commandData->IoctlData.dwCommand=COMMAND_PHY_SET_REG;
commandData->IoctlData.Data[0]=address;
commandData->IoctlData.Data[1]=data;
ioctl(commandData->hSockFD,SMSC911x_IOCTL,&(commandData->IfReq));
if(commandData->IoctlData.dwSignature!=SMSC911x_DRIVER_SIGNATURE) {
printf("Failed to Write Phy Register\n");
}
}
bool Initialize(PCOMMAND_DATA commandData,const char *ethName) {
if(commandData==NULL) return false;
if(ethName==NULL) return false;
commandData->hSockFD=socket(AF_INET,SOCK_DGRAM,0);
if((commandData->hSockFD) < 0) {
perror("\r\nFailed to create socket !! ->");
return false;
}
commandData->IfReq.ifr_data= (void *)&(commandData->IoctlData);
memset(&(commandData->IoctlData),0,sizeof(SMSC911x_IOCTL_DATA));
if(ethName[0]!=0) {
strncpy(commandData->IfReq.ifr_name,ethName,IFNAMSIZ);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -