📄 ether.c
字号:
UINT8 uByte;
UINT32 SlotAddress = 0;
volatile MAINSTONEII_BLR_REGS *pBLRegs = (volatile MAINSTONEII_BLR_REGS *) OALPAtoVA(MAINSTONEII_BASE_REG_PA_FPGA, FALSE);
// Determine the NIC's address.
//
switch (BootDevice)
{
case ETH_DEVICE_PCMCIA0:
SlotAddress = (UINT32) OALPAtoVA(BULVERDE_BASE_REG_PA_PCMCIA_S0_ATTR, FALSE);
KITLOutputDebugString("INFO: Trying to locate/initialize PCMCIA NIC in slot 0...\r\n");
break;
case ETH_DEVICE_PCMCIA1:
SlotAddress = (UINT32) OALPAtoVA(BULVERDE_BASE_REG_PA_PCMCIA_S1_ATTR, FALSE);
KITLOutputDebugString("INFO: Trying to locate/initialize PCMCIA NIC in slot 1...\r\n");
break;
case ETH_DEVICE_USB:
KITLOutputDebugString("INFO: Trying to initialize USB RNDIS...\r\n");
break;
case SER_DEVICE_USB:
KITLOutputDebugString("INFO: Trying to initialize USB SERIAL...\r\n");
break;
case ETH_DEVICE_SMSC:
default:
SlotAddress = (UINT32) OALPAtoVA(MAINSTONEII_BASE_REG_PA_SMSC_ETHERNET, FALSE);
KITLOutputDebugString("INFO: Trying to initialize the built-in SMSC NIC...\r\n");
break;
}
if (BootDevice == ETH_DEVICE_USB)
{
// Set address
EbootDeviceAddress = (UINT32)OALPAtoVA(BULVERDE_BASE_REG_PA_UDC, FALSE); // Base Address for USB Client
pKITLArgs->mac[0] = g_EbootCFG.RNDISMac[0];
pKITLArgs->mac[1] = g_EbootCFG.RNDISMac[1];
pKITLArgs->mac[2] = g_EbootCFG.RNDISMac[2];
// init USB registers
if (HostMiniInit((PCHAR) NULL, 1, pKITLArgs->mac))
{
pfnEDbgInit = RndisInit;
pfnEDbgEnableInts = RndisEnableInts;
pfnEDbgDisableInts = RndisDisableInts;
pfnEDbgGetFrame = RndisEDbgGetFrame;
pfnEDbgSendFrame = RndisEDbgSendFrame;
pfnEDbgReadEEPROM = NULL;
pfnEDbgWriteEEPROM = NULL;
// TODO: These two functons are provided in \oak\drivers\ethdbg\rne_mdd but not in \oak\drivers\netcard\rndismini
pfnEDbgGetPendingInts = RndisGetPendingInts; // TODO: This is called in OEMEthISR - what to do
pfnEDbgSetOptions = RndisSetOptions; // TODO: This function does nothing
#ifdef IMGSHAREETH
pfnCurrentPacketFilter = RndisCurrentPacketFilter;
pfnMulticastList = RndisMulticastList;
#endif
pKITLArgs->flags |= OAL_KITL_FLAGS_POLL;
// Save the device location information for later use.
//
pKITLArgs->devLoc.IfcType = Internal;
pKITLArgs->devLoc.BusNumber = 0;
pKITLArgs->devLoc.PhysicalLoc = (PVOID)BULVERDE_BASE_REG_PA_UDC; // not a real Ethernet card
pKITLArgs->devLoc.LogicalLoc = (DWORD)pKITLArgs->devLoc.PhysicalLoc;
return (EDBG_USB_RNDIS);
}
else
{
KITLOutputDebugString("ERROR: Failed to initialize Bulverde Rndis USB Ethernet controller.\n");
}
}
else
// USB SERIAL?
//
if (BootDevice == SER_DEVICE_USB)
{
// Save off the MAC address so we can at least have a device name
pKITLArgs->mac[0] = g_EbootCFG.RNDISMac[0];
pKITLArgs->mac[1] = g_EbootCFG.RNDISMac[1];
pKITLArgs->mac[2] = g_EbootCFG.RNDISMac[2];
// Save the device location information for later use.
pKITLArgs->devLoc.IfcType = Internal;
pKITLArgs->devLoc.BusNumber = 0;
pKITLArgs->devLoc.PhysicalLoc = (PVOID)BULVERDE_BASE_REG_PA_USBH; // Just has to be different than RNDIS
pKITLArgs->devLoc.LogicalLoc = (DWORD)pKITLArgs->devLoc.PhysicalLoc;
return (SDBG_USB_SERIAL);
}
else
// PCMCIA NIC?
//
if ((BootDevice == ETH_DEVICE_PCMCIA0) || (BootDevice == ETH_DEVICE_PCMCIA1))
{
// Locate the NIC card in the specified slot.
//
if (LocatePCMCIACard(BootDevice, SlotAddress))
{
// Determine the PCMCIA card type.
//
if (VerifyEthernetPCMCIACard(SlotAddress))
{
if ((((pBLRegs->pcmcia0_srcr & PCMCIA_POWER) == PCMCIA_VCC5V_VPP0V) && (BootDevice == ETH_DEVICE_PCMCIA0)) ||
(((pBLRegs->pcmcia1_srcr & PCMCIA_POWER) == PCMCIA_VCC5V_VPP0V) && (BootDevice == ETH_DEVICE_PCMCIA1)))
{
KITLOutputDebugString("INFO: 5.0V Card detected in slot %d.\r\n", ((BootDevice == ETH_DEVICE_PCMCIA0)?0:1));
uByte = 0x21;
Offset = CIS_R0;
pAttribute = (UINT8 *) SlotAddress;
pAttribute += Offset;
*pAttribute = uByte;
uByte = 0x1;
Offset = CIS_R0 + 2;
pAttribute = (UINT8 *) SlotAddress;
pAttribute += Offset;
*pAttribute = uByte;
}
else
{
KITLOutputDebugString("INFO: 3.3V Card detected in slot %d.\r\n", ((BootDevice == ETH_DEVICE_PCMCIA0)?0:1));
uByte = 0x20;
Offset = CIS_R0;
pAttribute = (UINT8 *) SlotAddress;
pAttribute += Offset;
*pAttribute = uByte;
}
EbootDeviceAddress = (BootDevice == ETH_DEVICE_PCMCIA0) ? (UINT32) OALPAtoVA(BULVERDE_BASE_REG_PA_PCMCIA_S0_IO, FALSE) + 0x300 : \
(UINT32) OALPAtoVA(BULVERDE_BASE_REG_PA_PCMCIA_S1_IO, FALSE) + 0x300;
// Only supported PCMCIA NIC is an NE2000-compatible NIC. Initialize it.
//
if (NE2000Init((BYTE *) EbootDeviceAddress, 1, pKITLArgs->mac))
{
pfnEDbgInit = NE2000Init;
pfnEDbgGetFrame = NE2000GetFrame;
pfnEDbgSendFrame = NE2000SendFrame;
pfnEDbgEnableInts = NE2000EnableInts;
pfnEDbgDisableInts = NE2000DisableInts;
#ifdef IMGSHAREETH
pfnCurrentPacketFilter = NULL;
pfnMulticastList = NULL;
#endif
// Save the device location information for later use.
//
pKITLArgs->devLoc.IfcType = Internal;
pKITLArgs->devLoc.BusNumber = 0;
pKITLArgs->devLoc.PhysicalLoc = (PVOID)((BootDevice == ETH_DEVICE_PCMCIA0) ? (BULVERDE_BASE_REG_PA_PCMCIA_S0_IO + 0x300) : (BULVERDE_BASE_REG_PA_PCMCIA_S1_IO + 0x300));
pKITLArgs->devLoc.LogicalLoc = (DWORD)pKITLArgs->devLoc.PhysicalLoc;
KITLOutputDebugString("INFO: NE2000 Ethernet controller initialized.\n");
return(EDBG_ADAPTER_NE2000);
}
else
{
KITLOutputDebugString("ERROR: Failed to initialize NE2000 Ethernet controller.\n");
}
}
}
return (-1);
}
else
{
// Use the SMSC LAN91C111 NIC.
//
EbootDeviceAddress = (SlotAddress + 0x300);
if (LAN91CInit((UINT8 *) EbootDeviceAddress, 0, pKITLArgs->mac))
{
pfnEDbgInit = (PFN_EDBG_INIT) LAN91CInit;
pfnEDbgGetFrame = (PFN_EDBG_GET_FRAME) LAN91CGetFrame;
pfnEDbgSendFrame = (PFN_EDBG_SEND_FRAME) LAN91CSendFrame;
pfnEDbgEnableInts = (PFN_EDBG_ENABLE_INTS) LAN91CEnableInts;
pfnEDbgDisableInts = (PFN_EDBG_DISABLE_INTS)LAN91CDisableInts;
#ifdef IMGSHAREETH
pfnCurrentPacketFilter = (PFN_EDBG_CURRENT_PACKET_FILTER) LAN91CCurrentPacketFilter;
pfnMulticastList = (PFN_EDBG_MULTICAST_LIST) LAN91CMulticastList;
#endif
// Save the device location information for later use.
//
pKITLArgs->devLoc.IfcType = Internal;
pKITLArgs->devLoc.BusNumber = 0;
pKITLArgs->devLoc.PhysicalLoc = (PVOID)(MAINSTONEII_BASE_REG_PA_SMSC_ETHERNET + 0x300);
pKITLArgs->devLoc.LogicalLoc = (DWORD)pKITLArgs->devLoc.PhysicalLoc;
KITLOutputDebugString("INFO: SMSC LAN91C111 Ethernet controller initialized.\r\n");
return(EDBG_ADAPTER_SMC9000);
}
else
{
KITLOutputDebugString("ERROR: Failed to initialize SMSC LAN91C111 Ethernet controller.\n");
}
}
return (-1);
}
BOOL OEMEthGetFrame(BYTE *pData, // OUT - Receives frame data
UINT16 *pwLength) // IN - Length of Rx buffer
{
return (pfnEDbgGetFrame(pData, pwLength));
}
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);
KITLOutputDebugString("!OEMEthSendFrame failure, retry %u\n",retries);
}
return (FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -