📄 reset.c
字号:
//
pVc = CONTAINING_RECORD(Link, VC_BLOCK, Link);
ASSERT(NULL != pVc);
#if DBG
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_INFO,
("pVc:0x%lx, VC:%lx\n", pVc, pVc->VpiVci.Vci));
#endif // end of DBG
if (VC_TEST_FLAG(pVc, fVC_TRANSMIT))
{
//
// 1. Clean up the queue of packets that are waiting
// for transmit resources.
// 2. Unlock the transmit segment of this VC, so it can
// be re-used.
//
pXmitSegInfo = pVc->XmitSegInfo;
tbAtm155CompletePacketQueue(&pXmitSegInfo->SegWait);
tbAtm155CompletePacketQueue(&pXmitSegInfo->DmaCompleting);
}
if (VC_TEST_FLAG(pVc, fVC_RECEIVE))
{
pSegCompleting = &pVc->RecvSegInfo->SegCompleting;
if (NULL == pSegCompleting->BufListHead)
{
continue;
}
//
// Return the packet and it's resources back to it's receive
// buffer queue.
//
TbAtm155ReturnPacket(
(NDIS_HANDLE)pAdapter,
pSegCompleting->BufListHead->Packet);
//
// Initialize the queue.
//
pSegCompleting->BufListHead = NULL;
pSegCompleting->BufListTail = NULL;
pSegCompleting->BufferCount = 0;
}
}
//
// Clean up any packets waiting for DMA resources
// and initialize the PadTrailer counters.
//
tbAtm155CompletePacketQueue(&pXmitDmaQ->DmaWait);
NdisAcquireSpinLock(&pXmitDmaQ->lock);
pXmitDmaQ->RemainingTransmitSlots = pXmitDmaQ->MaximumTransmitSlots;
NdisReleaseSpinLock(&pXmitDmaQ->lock);
//
// 1. Return the buffers in the 'Big' buffer queue which wait for
// receiving data on network
// 2. Initialize the index for Rx Big Slot FIFO
//
tbAtm155MergeRecvBuffers2FreeBufferQueue(
pAdapter,
&pSar->FreeBigBufferQ,
&pRecvDmaQ->CompletingBigBufQ);
pRecvDmaQ->RemainingReceiveBigSlots = pRecvDmaQ->MaximumReceiveBigSlots;
//
// 1. Return the buffers in the 'Small' buffer queue which wait for
// receiving data on network
// 2. Initialize the index for Rx Small Slot FIFO
//
tbAtm155MergeRecvBuffers2FreeBufferQueue(
pAdapter,
&pSar->FreeSmallBufferQ,
&pRecvDmaQ->CompletingSmallBufQ);
pRecvDmaQ->RemainingReceiveSmallSlots = pRecvDmaQ->MaximumReceiveSmallSlots;
pRecvDmaQ->PrevRxReportQIndex = 0;
pXmitDmaQ->PrevTxReportQIndex = 0;
//
// re-initialize the SAR and related parameters.
//
tbAtm155InitSarParameters(pAdapter);
Status = tbAtm155InitRegisters(pAdapter);
#if DBG
if (NDIS_STATUS_SUCCESS != Status)
{
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_ERR,
("Failed to Reset the registers\n"));
}
#endif // end of DBG
//
// Walk through the VC's that are opened on this adapter and mark
// them out of resetting. Also check to see if any VCs need to
// be deactivated.
//
Link = pAdapter->ActiveVcList.Flink;
while (Link != &pAdapter->ActiveVcList)
{
NextLink = Link->Flink;
//
// Get a pointer to the VC that link represents.
//
pVc = CONTAINING_RECORD(Link, VC_BLOCK, Link);
//
// Get the next.
//
Link = Link->Flink;
NdisAcquireSpinLock(&pVc->lock);
VC_CLEAR_FLAG(pVc, fVC_RESET_IN_PROGRESS);
//
// Check to see if we need to deactivate the VC.
//
if ((VC_TEST_FLAG(pVc, fVC_DEACTIVATING)) && (1 == pVc->References))
{
NdisReleaseSpinLock(&pVc->lock);
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_ERR, ("pVc:"PTR_FORMAT"\n", pVc));
//
// Finish VC deactivation.
//
TbAtm155DeactivateVcComplete(pVc->Adapter, pVc);
}
else
{
#if DBG
if (1 != (pVc->References - pVc->PktsHoldsByNdis))
{
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_ERR,
("pVc->References: 0x%x, pVc->PktsHoldsByNdis: 0x%x, pVc:"PTR_FORMAT"\n",
pVc->References, pVc->PktsHoldsByNdis, pVc));
}
else if (pVc->References <= pVc->PktsHoldsByNdis)
{
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_ERR,
("pVc->References: 0x%x, pVc->PktsHoldsByNdis: 0x%x, pVc:"PTR_FORMAT"\n",
pVc->References, pVc->PktsHoldsByNdis, pVc));
DBGBREAK(DBG_COMP_RESET, DBG_LEVEL_ERR);
}
#endif // end of DBG
Status = tbAtm155OpenVcChannels(pAdapter, pVc);
if (VC_TEST_FLAG(pVc, fVC_TRANSMIT))
{
pXmitSegInfo = pVc->XmitSegInfo;
pXmitSegInfo->BeOrBeingUsedPadTrailerBufs = 0;
pXmitSegInfo->FreePadTrailerBuffers = TBATM155_MAX_PADTRAILER_BUFFERS;
pXmitSegInfo->PadTrailerBufferIndex = 0;
}
#if DBG
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_INFO,
("After OpenVCChannel .. pVc:0x%lx, VC:%lx\n", pVc, pVc->VpiVci.Vci));
#endif // end of DBG
NdisReleaseSpinLock(&pVc->lock);
}
Link = NextLink;
}
NdisAcquireSpinLock(&pAdapter->lock);
ADAPTER_CLEAR_FLAG(pAdapter, fADAPTER_RESET_IN_PROGRESS);
ADAPTER_CLEAR_FLAG(pAdapter, fADAPTER_HARDWARE_FAILURE);
#if TB_CHK4HANG
ADAPTER_CLEAR_FLAG(pAdapter, fADAPTER_EXPECT_TXIOC);
#endif // end of TB_CHK4HANG
NdisReleaseSpinLock(&pAdapter->lock);
//
// Post receive buffers from both pools.
//
tbAtm155QueueRecvBuffersToReceiveSlots(pAdapter, RECV_SMALL_BUFFER);
tbAtm155QueueRecvBuffersToReceiveSlots(pAdapter, RECV_BIG_BUFFER);
//
// Start Transmitter and Receiver new.
//
TBATM155_READ_PORT(
&pHwInfo->TbAtm155_SAR->SAR_Cntrl1,
®Control1.reg);
regControl1.Tx_Enb = 1;
regControl1.Rx_Enb = 1;
TBATM155_WRITE_PORT(
&pHwInfo->TbAtm155_SAR->SAR_Cntrl1,
regControl1.reg);
} while (FALSE);
//
// Enable interrupts.
//
NdisMSynchronizeWithInterrupt(
&pAdapter->HardwareInfo->Interrupt,
(PVOID)TbAtm155EnableInterrupt,
pAdapter);
DBGPRINT(DBG_COMP_HALT, DBG_LEVEL_INFO,
("<==tbAtm155ProcessReset\n"));
}
NDIS_STATUS
TbAtm155Reset(
OUT PBOOLEAN AddressingReset,
IN NDIS_HANDLE MiniportAdapterContext
)
/*++
Routine Description:
This routine will either reset the adapter or schedule a reset to happen.
Arguments:
AddressingReset - Not used.
MiniportAdapterContext - Pointer to the ADAPTER_BLOCK.
Return Value:
--*/
{
PADAPTER_BLOCK pAdapter = (PADAPTER_BLOCK)MiniportAdapterContext;
*AddressingReset = FALSE;
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_INFO,
("==>TbAtm155Reset\n"));
NdisAcquireSpinLock(&pAdapter->lock);
//
// Are we currently processing a reset? Or is there a reset
// already requested? Or are we shutting down the adapter?
//
if (ADAPTER_TEST_FLAG(pAdapter, fADAPTER_RESET_IN_PROGRESS) ||
ADAPTER_TEST_FLAG(pAdapter, fADAPTER_SHUTTING_DOWN) ||
ADAPTER_TEST_FLAG(pAdapter, fADAPTER_RESET_REQUESTED))
{
//
// Don't do it twice.
//
NdisReleaseSpinLock(&pAdapter->lock);
#if DBG
if (ADAPTER_TEST_FLAG(pAdapter, fADAPTER_SHUTTING_DOWN))
{
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_ERR,
("Skipping reset cuz Adapter %x is shutting down\n", pAdapter));
}
#endif
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_INFO,
("<==TbAtm155Reset (NDIS_STATUS_RESET_IN_PROGRESS)\n"));
return(NDIS_STATUS_RESET_IN_PROGRESS);
}
//
// Walk the active VC list and mark them as resetting.
//
if (!IsListEmpty(&pAdapter->ActiveVcList))
{
PLIST_ENTRY Link;
PVC_BLOCK pVc;
//
// Mark all active VC's as resetting.
//
for (Link = pAdapter->ActiveVcList.Flink;
Link != &pAdapter->ActiveVcList;
Link = Link->Flink)
{
//
// Get a pointer to the VC that this link represents.
//
pVc = CONTAINING_RECORD(Link, VC_BLOCK, Link);
NdisDprAcquireSpinLock(&pVc->lock);
VC_SET_FLAG(pVc, fVC_RESET_IN_PROGRESS);
NdisDprReleaseSpinLock(&pVc->lock);
}
}
//
// Are we currently processing an interrupt?
//
if (ADAPTER_TEST_FLAG(pAdapter, fADAPTER_PROCESSING_INTERRUPTS) ||
ADAPTER_TEST_FLAG(pAdapter, fADAPTER_PROCESSING_SENDPACKETS))
{
//
// Request a reset to happen when the interrupt processing is done.
//
ADAPTER_SET_FLAG(pAdapter, fADAPTER_RESET_REQUESTED);
NdisReleaseSpinLock(&pAdapter->lock);
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_INFO,
("<==TbAtm155Reset\n"));
return(NDIS_STATUS_PENDING);
}
//
// Ok we can process the reset.
//
ADAPTER_SET_FLAG(pAdapter, fADAPTER_RESET_IN_PROGRESS);
NdisMSynchronizeWithInterrupt(
&pAdapter->HardwareInfo->Interrupt,
(PVOID)TbAtm155DisableInterrupt,
pAdapter);
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_ERR,
("Calling tbAtm155ProcessReset in TbAtm155Reset\n"));
NdisReleaseSpinLock(&pAdapter->lock);
//
// this routine does the actual resetting.
//
tbAtm155ProcessReset(pAdapter);
DBGPRINT(DBG_COMP_RESET, DBG_LEVEL_INFO,
("<==TbAtm155Reset\n"));
return(NDIS_STATUS_SUCCESS);
}
VOID
TbAtm155Halt(
IN NDIS_HANDLE MiniportAdapterContext
)
/*++
Routine Description:
This routine is called when the adapter is being stopped.
We can assume that there are no open VCs. we just need to clean up our
software and hardware state.
Arguments:
MiniportAdapterContext - Pointer to the ADAPTER_BLOCK.
Return Value:
None.
--*/
{
PADAPTER_BLOCK pAdapter = (PADAPTER_BLOCK)MiniportAdapterContext;
PHARDWARE_INFO pHwInfo = pAdapter->HardwareInfo;
PSAR_INFO pSar = pHwInfo->SarInfo;
PXMIT_DMA_QUEUE pXmitDmaQ = &pSar->XmitDmaQ;
PRECV_DMA_QUEUE pRecvDmaQ = &pSar->RecvDmaQ;
DBGPRINT(DBG_COMP_HALT, DBG_LEVEL_INFO,
("==>TbAtm155Halt\n"));
NdisAcquireSpinLock(&pAdapter->lock);
//
// Let's do soft reset.
//
tbAtm155SoftresetNIC(pHwInfo);
NdisDprAcquireSpinLock(&pXmitDmaQ->lock);
NdisDprAcquireSpinLock(&pRecvDmaQ->lock);
//
// Turn off the interrupts
//
pHwInfo->InterruptMask = 0;
NdisMSynchronizeWithInterrupt(
&pHwInfo->Interrupt,
(PVOID)TbAtm155DisableInterrupt,
pAdapter);
NdisDprReleaseSpinLock(&pRecvDmaQ->lock);
NdisDprReleaseSpinLock(&pXmitDmaQ->lock);
NdisReleaseSpinLock(&pAdapter->lock);
//
// Free the adapter resources.
//
tbAtm155FreeResources((PADAPTER_BLOCK)MiniportAdapterContext);
DBGPRINT(DBG_COMP_HALT, DBG_LEVEL_INFO,
("<==TbAtm155Halt\n"));
}
VOID
TbAtm155Shutdown(
IN PVOID ShutdownContext
)
/*++
Routine Description:
This routine will stop the adapter. We do NOT free any resources in this
routine since we don't know what the state of the system is (it could be
crashing). So all we do is make sure that the adapter is stopped.
Arguments:
ShutdownContext - Pointer to the adapter block.
Return Value:
None.
--*/
{
PADAPTER_BLOCK pAdapter = (PADAPTER_BLOCK)ShutdownContext;
PHARDWARE_INFO pHwInfo = pAdapter->HardwareInfo;
DBGPRINT(DBG_COMP_HALT, DBG_LEVEL_INFO,
("==>TbAtm155Shutdown\n"));
ADAPTER_SET_FLAG(pAdapter, fADAPTER_SHUTTING_DOWN);
tbAtm155SoftresetNIC(pHwInfo);
//
// Turn off the interrupts
//
pHwInfo->InterruptMask = 0;
TbAtm155DisableInterrupt(pAdapter);
DBGPRINT(DBG_COMP_HALT, DBG_LEVEL_INFO,
("<==TbAtm155Shutdown\n"));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -