⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.c

📁 网络驱动开发
💻 C
📖 第 1 页 / 共 4 页
字号:
               ("Unable to allocate information for the SAR_INFO\n"));

           break;
       }

       ZERO_MEMORY(pSar, sizeof(SAR_INFO));
	
       NdisAllocateSpinLock(&pSar->lockFreeXmitSegment);
	

       //
       //	Initialize the transmit DMA queue.
       //
       tbAtm155InitializePacketQueue(&pSar->XmitDmaQ.DmaWait);

       NdisAllocateSpinLock(&pSar->XmitDmaQ.lock);

		Status = NdisMInitializeScatterGatherDma(
					pAdapter->MiniportAdapterHandle,
					FALSE,
                   BLOCK_15K);

		if (NDIS_STATUS_SUCCESS != Status)
		{
			DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
				("Unable to allocate scatter gather list\n"));

			break;
		}

#if (WINVER >= 0x0501)
       //
       //   Get the DMA alignment that we need.
       //
       gDmaAlignmentRequired = NdisMGetDmaAlignment(pAdapter->MiniportAdapterHandle);
       if (gDmaAlignmentRequired < TBATM155_MIN_DMA_ALIGNMENT)
       {
           gDmaAlignmentRequired = TBATM155_MIN_DMA_ALIGNMENT;
       }
#endif

       //
       //	Initialize the receive DMA queue.
       //
       NdisAllocateSpinLock(&pSar->RecvDmaQ.lock);

       //
       //	Initialize the waiting receive buffer queues.
       //
       tbAtm155InitializeReceiveBufferQueue(&pSar->RecvDmaQ.CompletingSmallBufQ);
       tbAtm155InitializeReceiveBufferQueue(&pSar->RecvDmaQ.CompletingBigBufQ);

       //
       //	Initialize the free receive buffer queues.
       //
       tbAtm155InitializeReceiveBufferQueue(&pSar->FreeSmallBufferQ);
       tbAtm155InitializeReceiveBufferQueue(&pSar->FreeBigBufferQ);

       pRegistryParameter = pAdapter->RegistryParameters;
       pSar->MaxRecvBufferCount = (USHORT)pRegistryParameter[TbAtm155TotalRxBuffs].Value;

       pHwInfo->SarInfo = pSar;
       tbAtm155InitSarParameters(pAdapter);    
       
       Status = NDIS_STATUS_SUCCESS;
   } while (FALSE);

   //
   //	If we failed somewhere above then we need to cleanup....
   //
   if (NDIS_STATUS_SUCCESS != Status)
   {

       if (NULL != pSar)
       {
           NdisFreeSpinLock(&pSar->lockFreeXmitSegment);
           FREE_MEMORY(pSar, sizeof(SAR_INFO));
       }

   }

   DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_INFO,
       ("<==tbAtm155InitSarSegment\n"));

   return(Status);
}


NDIS_STATUS
TbAtm155Initialize(
   OUT PNDIS_STATUS    OpenErrorStatus,
   OUT PUINT           SelectedMediumIndex,
   IN  PNDIS_MEDIUM    MediumArray,
   IN  UINT            MediumArraySize,
   IN  NDIS_HANDLE     MiniportAdapterHandle,
   IN  NDIS_HANDLE     ConfigurationHandle
   )
/*++

Routine Description:

   This routine is the MiniportIntialize handler.  This is called by the
   NDIS wrapper to initialize the adapter.

Arguments:

   OpenErrorStatus         -   Not used.
   SelectedMediumIndex     -   On exit this will contain the media that the
                               driver supports.
   MediumArray             -   Array of media types that the adapter can
                               choose to support.
   MediumArraySize         -   Number of elements in the above array.
   MiniportAdapterHandle   -   Handle that NDIS needs to process requests
                               made by this driver.
   ConfigHandle            -   Configuration handle that is used to read
                               registry information.

Return Value:

   NDIS_STATUS_SUCCESS     if we successfully initialize the adapter.
   Failure code            otherwise.

--*/
{
   UINT                            c;
   PADAPTER_BLOCK                  pAdapter;
   PHARDWARE_INFO                  pHwInfo;
   NDIS_STATUS                     Status;
   PTBATM155_REGISTRY_PARAMETER    pRegistryParameters;
   ULONG                           i;
	UCHAR	                        CurrentAddress[ATM_ADDRESS_LENGTH];

   DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_INFO, ("==>TbAtm155Initialize\n"));

   //
   //	We don't use the OpenErrorStatus.
   //
   *OpenErrorStatus = NDIS_STATUS_SUCCESS;

   do
   {
       //
       //	Initialize for clean-up.
       //
       pAdapter = NULL;

       //
       //	Do we support any of the given media types?
       //
       for (c = 0; c < MediumArraySize; c++)
       {
           if (MediumArray[c] == NdisMediumAtm)
           {
               break;
           }
       }
	
       //
       //	If we went through the whole media list without finding
       //	a supported media type let the wrapper know.
       //
       if (c == MediumArraySize)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Media not supported by version of ndis\n"));

           Status = NDIS_STATUS_UNSUPPORTED_MEDIA;

           break;
       }
	
       *SelectedMediumIndex = c;

       //
       //	Allocate memory for the registry parameters.
       //
       ALLOCATE_MEMORY(
           &Status,
           &pRegistryParameters,
           sizeof(TBATM155_REGISTRY_PARAMETER) * TbAtm155MaxRegistryEntry,
           '30DA');
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Unable to allocate memroy for the registry parameters\n"));

           break;
       }

       //
       //	Will initialize the default registry paramters.
       //
       tbAtm155InitConfigurationInformation(pRegistryParameters);

       ZERO_MEMORY(CurrentAddress, ATM_ADDRESS_LENGTH);

       //
       //	Read our parameters out of the registry.
       //
       Status = tbAtm155ReadConfigurationInformation(
                   ConfigurationHandle,
                   pRegistryParameters,
                   CurrentAddress);

       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to read the configuration information from the registry\n"));

           break;
       }

       //
       //	Allocate memory for our adapter block and initialize it.
       //
       ALLOCATE_MEMORY(
           &Status,
           &pAdapter,
           sizeof(ADAPTER_BLOCK) +
           (pRegistryParameters[TbAtm155VcHashTableSize].Value * sizeof(PVC_BLOCK)),
           '40DA');
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to allocate memory for the adapter block\n"));
           break;
       }

       ZERO_MEMORY(
           pAdapter,
           sizeof(ADAPTER_BLOCK) +
           (pRegistryParameters[TbAtm155VcHashTableSize].Value * sizeof(PVC_BLOCK)));

       //
       //	Attempt to allocate storage for the debug logs.
       //
       dbgInitializeDebugInformation(&pAdapter->DebugInfo);

       //
       //	Save the Wrapper's context information with our adapter block.
       //
       pAdapter->MiniportAdapterHandle = MiniportAdapterHandle;

       //
       //	Save the registry paramters.
       //
       pAdapter->RegistryParameters = pRegistryParameters;

       //
       //	Initialize the adapter spin lock.
       //
       NdisAllocateSpinLock(&pAdapter->lock);
       NdisAllocateSpinLock(&pAdapter->VcHashLock);

       //
       //	Spin lock and other odd allocations/initializations.
       //
       InitializeListHead(&pAdapter->ActiveVcList);
       InitializeListHead(&pAdapter->InactiveVcList);

       //
       //	Mark the adapter block as initializing.
       //
       ADAPTER_SET_FLAG(pAdapter, fADAPTER_INITIALIZING);


       //
       //   Allocate memory for the hardware information.
       //
       ALLOCATE_MEMORY(
           &Status,
           &pAdapter->HardwareInfo,
           sizeof(HARDWARE_INFO),
           '50DA');
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to allocate memory for the hardware information\n"));

           break;
       }

       ZERO_MEMORY(pAdapter->HardwareInfo, sizeof(HARDWARE_INFO));
		
       pHwInfo = pAdapter->HardwareInfo;

       NdisAllocateSpinLock(&pHwInfo->Lock);

       //
       //	Save whatever content into the station address by default.
       //
       NdisMoveMemory(
           pHwInfo->StationAddress,
           CurrentAddress,
           ATM_MAC_ADDRESS_LENGTH);

       //
       //	Get the registry parameters.
       //
       //  Make sure the number of receive buffers is not over 
       //  the thresholds.
       //
       if (pRegistryParameters[TbAtm155TotalRxBuffs].fPresent)
       {
           i = pRegistryParameters[TbAtm155TotalRxBuffs].Value;
           if (i > MAXIMUM_RECEIVE_BUFFERS)
           {
               i = MAXIMUM_RECEIVE_BUFFERS;
           }
           else if (i < MINIMUM_RECEIVE_BUFFERS)
           {
               i = MINIMUM_RECEIVE_BUFFERS;
           }
           pRegistryParameters[TbAtm155TotalRxBuffs].Value = i;
       }

       //
       //	Set the atributes for the adapter.
       //
       NdisMSetAttributesEx(
           MiniportAdapterHandle,
           (NDIS_HANDLE)pAdapter,
           0,
           NDIS_ATTRIBUTE_BUS_MASTER | NDIS_ATTRIBUTE_USES_SAFE_BUFFER_APIS,
           NdisInterfacePci);

       //
       //	Assign the PCI resources.
       //
       Status = tbAtm155ReadPciConfiguration(pAdapter, ConfigurationHandle);
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to read the PCI configuration information\n"));
           break;
       }

       //
       //	Register the Port addresses.
       //
       Status = NdisMRegisterIoPortRange(
                       &pHwInfo->PortOffset,
                       pAdapter->MiniportAdapterHandle,
                       pHwInfo->InitialPort,
                       pHwInfo->NumberOfPorts);
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to register the I/O port range\n"));
           break;
       }
       else
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_INFO,
           	    ("Mapped memory pHwInfo->PortOffset:0x%x\n", pHwInfo->PortOffset));
       }

       //
       //	Get the Hardware Information 
       //  including reading in manufacturer address for the NIC.
       //
       Status = tbAtm155GetHardwareInformation(pAdapter);
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to read the EEPROM information from the adapter\n"));
           break;										
       }

       //
       //	Detect Meteor type.
       //
       Status = tbAtm155IsIt4KVc(pAdapter);
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to detect Meteor type..\n"));

           break;
       }

       //
       //	Initialize the SAR
       //
       Status = tbAtm155InitSarSegment(pAdapter);
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to initialize the SAR information buffer.\n"));

           break;
       }

       //
       // Allocate receive & transmit report queues.
       //
       Status = tbAtm155AllocateReportQueues(pAdapter);
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT,DBG_LEVEL_ERR,
               ("tbAtm155AllocateReportQueues failed! Status: 0x%x\n", Status));
           break;
       }


       Status = tbAtm155DetectPhyType(pAdapter);
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to detect the PHY chip.\n"));

           break;
       }

       //
       //	Initialize the SAR registers including soft reset
       //  the controller.
       //
       Status = tbAtm155InitRegisters(pAdapter);
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to initialize the 155 SAR registers\n"));

           break;
       }

       //
       //	Register the interrupt.
       //
       Status = NdisMRegisterInterrupt(
                   &pHwInfo->Interrupt,
                   pAdapter->MiniportAdapterHandle,
                   pHwInfo->InterruptVector,
                   pHwInfo->InterruptLevel,
                   TRUE,
                   TRUE,
                   NdisInterruptLevelSensitive);
       if (NDIS_STATUS_SUCCESS != Status)
       {
           DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
               ("Failed to register the interrupt with ndis\n"));
           break;
       }

       // set up our link indication variable
       // it doesn't matter what this is right now because it will be
       // set correctly if link fails
       pAdapter->MediaConnectStatus = NdisMediaStateConnected;

       HW_SET_FLAG(pHwInfo, fHARDWARE_INFO_INTERRUPT_REGISTERED);

       //
       //	Return success.
       //
       Status = NDIS_STATUS_SUCCESS;

       // 
       // Pass the initialization. 
       // Initially, the LED_LNKUP_ON_ORANGE should be set
       // to indicate passing the initialization, then 
       // the LED_LNKUP_ON_GREEN will be set after PLC-2 detected
       // media connected interrupt. 
       // Somehow, the interrupt won't be generated on some 
       // systems. Instead of confusing users, set the LED
       // to be LED_LNKUP_ON_GREEN.
       // 
       pHwInfo->LedVal |= LED_LNKUP_ON_GREEN;

       //
       //	Register a shutdown handler for the adapter.
       //
       NdisMRegisterAdapterShutdownHandler(
           pAdapter->MiniportAdapterHandle,
           pAdapter,
           TbAtm155Shutdown);


#if DBG_USING_LED
       
       pHwInfo->dbgLedVal = pHwInfo->LedVal;

       TBATM155_PH_WRITE_DEV(
           pAdapter,
           LED_OFFSET,
           pHwInfo->dbgLedVal,
           &Status);

#endif // end of DBG_USING_LED


       //
       //	Enable interrupts on the adapter.
       //
       TBATM155_WRITE_PORT(
           &pHwInfo->TbAtm155_SAR->Intr_Enb,
           pHwInfo->InterruptMask);


       //
       //	Clear the adapter initializing flag.
       //
       ADAPTER_CLEAR_FLAG(pAdapter, fADAPTER_INITIALIZING);

   } while (FALSE);

   //
   //	Should we clean up?
   //
   if (NDIS_STATUS_SUCCESS != Status)
   {
       tbAtm155FreeResources(pAdapter);
   }

   DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_INFO, ("<==TbAtm155Initialize\n"));

   return(Status);
}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -