📄 ether.c
字号:
/*
* The content of this file or document is CONFIDENTIAL and PROPRIETARY
* to Jade Technologies Co., Ltd. It is subjected to the terms of a
* License Agreement between Licensee and Jade Technologies Co., Ltd.
* restricting among other things, the use, reproduction, distribution
* and transfer. Each of the embodiments, including this information
* and any derivative work shall retain this copyright notice.
*
* Copyright (c) 2004 - 2005 Jade Technologies Co., Ltd.
* All rights reserved.
*/
// ----------------------------------------------------------------
// File: ether.c,v
// Revision: 1.0
// ----------------------------------------------------------------
// $
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <halether.h>
#include <ceddk.h>
#include <ethdbg.h>
#include <nkintr.h>
#include <armintboot.h>
#include <platform.h>
#include <pl031.h>
#include <oalintr.h>
#include "eboot.h"
// Must match config.bib setting for bootargs
#define BOOTARGS_BASE_ADDR 0x00008000
static PFN_EDBG_INIT pfnEDbgInit;
static PFN_EDBG_GET_FRAME pfnEDbgGetFrame;
static PFN_EDBG_SEND_FRAME pfnEDbgSendFrame;
typedef struct vendorid
{
DWORD dwUpperMAC; // first 3 bytes of ethernet address
char *szAbbrev;
} VENDORID;
static const VENDORID VendorIds[] =
{
{0x00006E, "AE" }, // Artisoft
{0x000094, "AS" }, // ASANTE
{0x0000E8, "AC" }, // Accton Technology
{0x004005, "LS" }, // LinkSys
{0x004033, "AD" }, // Addtron Technology
{0x004092, "ASP"}, // ASP Computer Products
{0x00800F, "SMC"}, // SMC
{0x008048, "CPX"}, // Compex
{0x0080AD, "CN" }, // CNET Technologies
{0x0080C8, "DL" }, // D-Link
{0x00A0D2, "AT" }, // Allied TeleSyn
{0x00C00D, "ALR"}, // Advanced Logic Research
{0x00C06D, "BR" }, // Boca Research
{0x00C0DF, "GE" }, // Kye International GENIUS GE2000 series
{0x00C0F0, "KS" }, // Kingston
{0x4854E8, "WB" } // WinBond Electronics Corp
};
#define NUM_VENDORIDS (sizeof(VendorIds)/sizeof(VENDORID))
BOOL
OEMEthGetFrame(
BYTE *pData, // OUT - Receives frame data
UINT16 *pwLength) // IN - Length of Rx buffer
// OUT - Number of bytes received
{
if (pfnEDbgGetFrame)
return(pfnEDbgGetFrame(pData, pwLength));
EdbgOutputDebugString("ERROR: OEMEthGetFrame return false******************\r\n");
return(FALSE);
}
BOOL
OEMEthSendFrame(
BYTE *pData, // IN - Data buffer
DWORD dwLength) // IN - Length of buffer
{
int retries = 0;
// Let's be persistant here
while (retries++ < 4) {
if (!pfnEDbgSendFrame(pData, dwLength))
return TRUE;
else
EdbgOutputDebugString("ERROR: OEMEthSendFrame failure, retry %u\r\n", retries);
}
return(FALSE);
}
BOOL OEMEthHardwareInit(ETH_HARDWARE_INIT_ARGS *pInitArgs, EDBG_ADDR *pMyAddr)
{
HARP_BOOT_ARGS *pBootArgs = NULL;
pvstRTCRegs pRTC = (pvstRTCRegs) PHYS_RTC_BASE;
// Make sure RTC is enabled as OEMEthGetSecs() uses it
pRTC->CR = 1;
// Form platform name string...
strncpy(pInitArgs->szPlatformString, PLATFORM_STRING, EDBG_MAX_DEV_NAMELEN);
//------------------------------------------------------------------
// This value should agree with DRIVER_GLOBALS_PHYSICAL_MEMORY_START
// in drv_glob.h PLUS DRIVER_GLOBALS_ZEROINIT_SIZE, because that's
// where we put the ethernet debug info from Eboot for the OS to read.
// It should also match config.bib and match eboot.bib value of DRV_GLB.
//------------------------------------------------------------------
pInitArgs->pBootArgs = (HARP_BOOT_ARGS *)(BOOTARGS_BASE_ADDR + 0x800);
pBootArgs = pInitArgs->pBootArgs;
EdbgOutputDebugString("Boot Args @ 0x%x\r\n", pInitArgs->pBootArgs);
pBootArgs->dwEdbgBaseAddr = PHYS_ETHERNET_BASE;
pBootArgs->ucEdbgIRQ = LOGINTR_EDBG;
pBootArgs->ucEdbgAdapterType = EDBG_ADAPTER_OEM;
// Assign controller-specific callbacks.
switch (pBootArgs->ucEdbgAdapterType)
{
case EDBG_ADAPTER_OEM:
pfnEDbgInit = SMCInit;
pfnEDbgGetFrame = SMCGetFrame;
pfnEDbgSendFrame = SMCSendFrame;
break;
default:
EdbgOutputDebugString("ERROR: Unable to find network card.\r\n");
EdbgOutputDebugString("ERROR: Card Type = %d, Address = 0x%s.\r\n", pBootArgs->ucEdbgAdapterType, pBootArgs->dwEdbgBaseAddr);
return(FALSE);
}
// call driver specific initialization
if (!pfnEDbgInit((BYTE *)(pBootArgs->dwEdbgBaseAddr), 1, pMyAddr->wMAC))
{
EdbgOutputDebugString("ERROR: Failed to initialize NIC.\r\n");
return(FALSE);
}
EdbgOutputDebugString("NIC initialized\r\n");
return(TRUE);
}
DWORD OEMEthGetSecs(void)
{
// Returning counter value for RTC.
// WARNING: this assumes RTC CLK1HZ signal is
// set for 1 Hz = 1 tick/second.
return(*(DWORD *)PHYS_RTC_BASE);
}
// Stub LED display routine - called by NE2000 ethdbg driver (although not
// used for SMSC driver.
VOID SC_WriteDebugLED(WORD wIndex, DWORD dwPattern)
{
return;
}
static void
itoa10(
int n,
char s[]
)
{
int i = 0;
// Get absolute value of number
unsigned int val = (unsigned int)((n < 0) ? -n : n);
// Extract digits in reverse order
do {
s[i++] = (val % 10) + '0';
} while (val /= 10);
// Add sign if number negative
if (n < 0) s[i++] = '-';
s[i--] = '\0';
// Reverse string
for (n = 0; n < i; n++, i--) {
char swap = s[n];
s[n] = s[i];
s[i] = swap;
}
}
static DWORD UpperDWFromMAC(EDBG_ADDR *pAddr)
{
DWORD ret;
//
// The WORDs in wMAC field are in net order, so we need to do some
// serious shifting around.
// A hex ethernet address of 12 34 56 78 9a bc is stored in wMAC array as
// wMAC[0] = 3412, wMAC[1] = 7856, wMAC[2] = bc9a.
// The 4 byte return value should look like 0x00123456
//
ret = (pAddr->wMAC[0] & 0x00ff) << 16;
ret |= pAddr->wMAC[0] & 0xff00;
ret |= pAddr->wMAC[1] & 0x00ff;
return ret;
}
void CreateDeviceName(EDBG_ADDR *pMyAddr, char *szBuf,
LPSTR szPlatformString)
{
int i;
DWORD dwUpperMAC;
EdbgOutputDebugString("CreateDeviceName\r\n");
dwUpperMAC = UpperDWFromMAC(pMyAddr);
EdbgOutputDebugString("UpperDWORD = 0x%X\r\n", dwUpperMAC);
strcpy(szBuf, szPlatformString);
szBuf += strlen(szBuf);
for (i = 0; i < NUM_VENDORIDS; i++)
{
if (dwUpperMAC == VendorIds[i].dwUpperMAC)
{
strcat(szBuf,VendorIds[i].szAbbrev);
szBuf += strlen(szBuf);
break;
}
}
itoa10(((pMyAddr->wMAC[2]>>8) | ((pMyAddr->wMAC[2] & 0x00ff) << 8)),
szBuf);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -