📄 init.c
字号:
/****************************************************************************
** COPYRIGHT (C) 1994-1997 INTEL CORPORATION **
** DEVELOPED FOR MICROSOFT BY INTEL CORP., HILLSBORO, OREGON **
** HTTP://WWW.INTEL.COM/ **
** THIS FILE IS PART OF THE INTEL ETHEREXPRESS PRO/100B(TM) AND **
** ETHEREXPRESS PRO/100+(TM) NDIS 5.0 MINIPORT SAMPLE DRIVER **
****************************************************************************/
/****************************************************************************
Module Name:
init.c
This driver runs on the following hardware:
- 82557/82558 based PCI 10/100Mb ethernet adapters
(aka Intel EtherExpress(TM) PRO Adapters)
Environment:
Kernel Mode - Or whatever is the equivalent on WinNT
Revision History
- JCB 8/14/97 Example Driver Created
*****************************************************************************/
#include "precomp.h"
#pragma hdrstop
#pragma warning (disable: 4514)
//-----------------------------------------------------------------------------
// Procedure: ClaimAdapter
//
// Description: Locates a D100 based adapter and assigns (claims) the
// adapter hardware. This routine also stores the slot, base IO
// Address, base physical memory address of the CSR, and the
// permanent node address of the claimed adapter.
//
// Arguments:
// Adapter - ptr to Adapter object instance.
//
// Returns:
// NDIS_STATUS_SUCCESS - If an adapter is successfully found and claimed
// NDIS_STATUS_FAILURE- If an adapter is not found/claimed
//-----------------------------------------------------------------------------
NDIS_STATUS
ClaimAdapter(
IN OUT PD100_ADAPTER Adapter
)
{
USHORT NumPciBoardsFound;
ULONG Bus;
UINT i,j;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
USHORT VendorID = D100_VENDOR_ID;
USHORT DeviceID = D100_DEVICE_ID;
PCI_CARDS_FOUND_STRUC PciCardsFound;
PNDIS_RESOURCE_LIST AssignedResources;
DEBUGFUNC("ClaimAdapter");
INITSTR(("\n"));
Bus = (ULONG) Adapter->BusNumber;
if (Adapter->AiBusType == PCIBUS)
{
// this is the new case, where the os is fully plug
// and play
// since both NT5 and Win9X all support configuration manager managed
// device installs, find an adapter without
// scanning the bus at all (just depend on the CM to give us resources)
DEBUGSTR(("Finding Adapter with non-invasive check\n"));
NumPciBoardsFound = FindPciDevice50Scan(Adapter,
VendorID,
DeviceID,
&PciCardsFound);
if(NumPciBoardsFound)
{
DEBUGSTR(("\n\n Found the following adapters\n"));
#if DBG
for(i=0; i < NumPciBoardsFound; i++)
DEBUGSTR(("slot=%x, mem_phys=%x, io=%x, irq=%x, node=%.2x %.2x %.2x %.2x %.2x %.2x\n",
PciCardsFound.PciSlotInfo[i].SlotNumber,
PciCardsFound.PciSlotInfo[i].MemPhysAddress,
PciCardsFound.PciSlotInfo[i].BaseIo,
PciCardsFound.PciSlotInfo[i].Irq,
PciCardsFound.PciSlotInfo[i].NodeAddress[0],
PciCardsFound.PciSlotInfo[i].NodeAddress[1],
PciCardsFound.PciSlotInfo[i].NodeAddress[2],
PciCardsFound.PciSlotInfo[i].NodeAddress[3],
PciCardsFound.PciSlotInfo[i].NodeAddress[4],
PciCardsFound.PciSlotInfo[i].NodeAddress[5]));
#endif
}
else
{
DEBUGSTR(("our PCI board was not found!!!!!!\n"));
D100LogError(Adapter,
EVENT_16,
NDIS_ERROR_CODE_ADAPTER_NOT_FOUND,
0);
return NDIS_STATUS_FAILURE;
}
i = 0; // only one adapter in the system
// NOTE: i == the index into PciCardsFound that we want to use.
//------------------------------------------------
// Store our allocated resources in Adapter struct
//------------------------------------------------
// Set the location information
Adapter->AiSlot = PciCardsFound.PciSlotInfo[i].SlotNumber;
// Save IRQ
Adapter->AiInterrupt = PciCardsFound.PciSlotInfo[i].Irq;
// Save our Chip Revision
Adapter->AiRevID = PciCardsFound.PciSlotInfo[i].ChipRevision;
// save our subvendor/subdeviceID for later reference (if needed)
Adapter->AiSubVendor = (USHORT) PciCardsFound.PciSlotInfo[i].SubVendor_DeviceID;
Adapter->AiSubDevice = (USHORT) (PciCardsFound.PciSlotInfo[i].SubVendor_DeviceID >> 16);
// Store the permanent node address
for(j=0; j < 6; j++)
Adapter->AiPermanentNodeAddress[j] =
PciCardsFound.PciSlotInfo[i].NodeAddress[j];
// save the D100 CSR Physical Memory Address
Adapter->CSRPhysicalAddress = PciCardsFound.PciSlotInfo[i].MemPhysAddress;
// save the D100 CSR I/O base address
Adapter->AiBaseIo = (USHORT)PciCardsFound.PciSlotInfo[i].BaseIo;
DEBUGSTR(("Using card type sven=%4X sdev=%4X with slot=%x, mem_phys=%x, io=%x, irq=%x, rev=%d, node=%.2x %.2x %.2x %.2x %.2x %.2x\n",
Adapter->AiSubVendor,
Adapter->AiSubDevice,
Adapter->AiSlot,
Adapter->CSRPhysicalAddress,
Adapter->AiBaseIo,
Adapter->AiInterrupt,
Adapter->AiRevID,
Adapter->AiPermanentNodeAddress[0],
Adapter->AiPermanentNodeAddress[1],
Adapter->AiPermanentNodeAddress[2],
Adapter->AiPermanentNodeAddress[3],
Adapter->AiPermanentNodeAddress[4],
Adapter->AiPermanentNodeAddress[5]));
} // End PCI Adapter
else
//Must be ISA, EISA or MicroChannel (not supported)
return NDIS_STATUS_FAILURE;
return NDIS_STATUS_SUCCESS;
}
//-----------------------------------------------------------------------------
// Procedure: SetupCsrIoMapping
//
// Description: This routine is called by SetupAdapterInfo to setup the D100
// adapter's IO mapping for its CSR registers.
//
// Arguments:
// Adapter - ptr to Adapter object instance
//
// Returns:
// NDIS_STATUS_SUCCESS - If the adapters CSR registers were setup
// not NDIS_STATUS_SUCCESS - If we couldn't register the CSR's I/O range
//-----------------------------------------------------------------------------
NDIS_STATUS
SetupCsrIoMapping(
IN OUT PD100_ADAPTER Adapter
)
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
DEBUGFUNC("SetupCsrIoMapping");
INITSTR(("\n"));
// the IO Space that the adapter uses
// will have to be registered.
// register our I/O space requirements with the OS, exit on error
Adapter->MappedIoRange = sizeof(CSR_STRUC);
Status = NdisMRegisterIoPortRange(
(PVOID *) &Adapter->MappedIoBase,
Adapter->D100AdapterHandle,
(UINT) Adapter->AiBaseIo,
Adapter->MappedIoRange);
DEBUGSTR(("SetupPciRegs: io=%x, map_io=%x, size=%x, stat=%x\n",
Adapter->AiBaseIo, Adapter->MappedIoBase, Adapter->MappedIoRange, Status));
if (Status != NDIS_STATUS_SUCCESS)
{
INITSTR(("NdisMRegisterIoPortRange failed (Status = 0x%x)\n", Status));
return Status;
}
return Status;
}
//-----------------------------------------------------------------------------
// Procedure: SetupAdapterInfo
//
// Description: Sets up the various adapter fields in the specified Adapter
// object.
// Arguments:
// Adapter - ptr to Adapter object instance
//
// Returns:
// NDIS_STATUS_SUCCESS - If an adapter's IO mapping was setup correctly
// not NDIS_STATUS_SUCCESS- If an adapter's IO space could not be registered
//-----------------------------------------------------------------------------
NDIS_STATUS
SetupAdapterInfo(
IN OUT PD100_ADAPTER Adapter
)
{
NDIS_STATUS Status;
DEBUGFUNC("SetupAdapterInfo");
INITSTR(("\n"));
// Setup the I/O mapping of the CSR
Status = SetupCsrIoMapping(Adapter);
Adapter->InterruptMode = NdisInterruptLevelSensitive;
return Status;
}
//-----------------------------------------------------------------------------
// Procedure: SetupSharedAdapterMemory
//
// Description: This routine is responsible for the allocation of the
// data structures inside the Adapter structure.
//
// Arguments:
// Adapter - the adapter structure to allocate for.
//
// Returns:
// NDIS_STATUS_SUCCESS - If the shared memory structures were setup
// not NDIS_STATUS_SUCCESS- If not enough memory or map registers could be
// allocated
//-----------------------------------------------------------------------------
NDIS_STATUS
SetupSharedAdapterMemory(
IN PD100_ADAPTER Adapter
)
{
PUCHAR MemP;
ULONG CbPhys;
NDIS_STATUS Status;
NDIS_PHYSICAL_ADDRESS NdisPhysicalCsrAddress;
DEBUGFUNC("SetupSharedAdapterMemory");
INITSTR(("\n"));
Adapter->NextFreeMapReg = 0;
Adapter->OldestUsedMapReg = 0;
Adapter->MaxPhysicalMappings = MAXIMUM_ETHERNET_PACKET_SIZE;
// Get a virtual address for our CSR structure. So that we can access
// the CSR's registers via memory mapping.
NdisSetPhysicalAddressLow (NdisPhysicalCsrAddress, Adapter->CSRPhysicalAddress);
NdisSetPhysicalAddressHigh (NdisPhysicalCsrAddress, 0);
Status = NdisMMapIoSpace(OUT (PVOID *) &(Adapter->CSRAddress),
Adapter->D100AdapterHandle,
NdisPhysicalCsrAddress,
sizeof (CSR_STRUC));
// If we couldn't get a virtual memory address for our CSR, then error out.
if ((Status != NDIS_STATUS_SUCCESS) || (Adapter->CSRAddress == NULL))
{
INITSTR(("Could not memory map the CSR phys = %x\n", Adapter->CSRPhysicalAddress));
NdisMFreeMapRegisters(Adapter->D100AdapterHandle);
return Status;
}
INITSTR(("D100 CSR phys = %x, D100 CSR virt = %x\n", Adapter->CSRPhysicalAddress,
Adapter->CSRAddress));
// set this up here to make sure we always have enough MAP REGISTERS
// for all the TBDs we have allocated
// we don't have to worry so much about using map registers now
// that NT 3.51 came out with less restrictions on them.
// Total number of TBDs equals number of TCBs * number of TBDs per TCB
Adapter->NumTbd = (Adapter->NumTcb * Adapter->NumTbdPerTcb);
Adapter->NumMapRegisters = Adapter->NumTbd;
// NOTE -- This call MUST be made, even if you don't really want any map
// registers, if you are going to allocate any shared memory.
INITSTR(("Allocating %x map registers\n", Adapter->NumMapRegisters));
Status = NdisMAllocateMapRegisters(Adapter->D100AdapterHandle,
0,
TRUE,
Adapter->NumMapRegisters,
Adapter->MaxPhysicalMappings);
if (Status != NDIS_STATUS_SUCCESS)
{
D100LogError(Adapter, EVENT_11, NDIS_ERROR_CODE_OUT_OF_RESOURCES, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -