📄 hsm.c
字号:
*/ for( priIdx = 0; priIdx < pAdapter->TxNumPrio; priIdx++) { pAdapter->PriQue[priIdx].iMaxTxDesc = pAdapter->PriQue[priIdx].iFreeTxDesc = pAdapter->TxDp[priIdx][DESCCNT]; pAdapter->PriQue[priIdx].pTxdArray = (DevDesc *)Start_DescArray; pAdapter->PriQue[priIdx].pTxdArrayPa = (DevDesc *)Start_DescArrayPa;/* * Setup the Txd Ring (linking all the Txds with "link" field in the * descriptor. The "link" field of the last Txd is made to point the first Txd. */ for (TxdIdx =0; TxdIdx< pAdapter->PriQue[priIdx].iMaxTxDesc; TxdIdx++) { idx = (TxdIdx + 1) % pAdapter->PriQue[priIdx].iMaxTxDesc; pAdapter->PriQue[priIdx].pTxdArray[TxdIdx].link = (UINT) (Start_DescArrayPa + (idx * sizeof(DevDesc))); pAdapter->PriQue[priIdx].pTxdArray[TxdIdx].CmdSts = 0; SET_OWN(&pAdapter->PriQue[priIdx].pTxdArray[TxdIdx], 0); } /* end of for(TxdIdx =0; ....) */ Start_DescArray += ( sizeof(DevDesc) * pAdapter->PriQue[priIdx].iMaxTxDesc ) ; Start_DescArrayPa += ( sizeof(DevDesc) * pAdapter->PriQue[priIdx].iMaxTxDesc ) ; pAdapter->TotTxdPhySz += sizeof(DevDesc) * TxdIdx;/* * Assign pTcbListHead, pTcbListNext pointers for this priority to the * first TCB in the TCB ring of the current priority. */ pAdapter->PriQue[priIdx].pTcbArray = (HsmTCB *) Start_TCBarray; pAdapter->PriQue[priIdx].pTcbListHead = pAdapter->PriQue[priIdx].pTcbListNext = pAdapter->PriQue[priIdx].pTcbArray; Start_TCBarray += (sizeof(HsmTCB) * pAdapter->TxDp[priIdx][DESCCNT]);/* * pStartDesc pointer of the First TCB is made point to the First Txd * of the priority queue. */ pAdapter->PriQue[priIdx].pTcbArray[0].pStartDesc = &pAdapter->PriQue[priIdx].pTxdArray[0]; pAdapter->PriQue[priIdx].pTcbArray[0].pStartDescPa = &pAdapter->PriQue[priIdx].pTxdArrayPa[0];/* * Jags... pAdapter->PriQue[priIdx].pTcbArray[0].pEndDesc = NULL; *//* * Setup the TCB Ring (linking all the TCBs with "pNext" field in the TCB. * The "pNext" field of the last TCB is made to point the first TCB. */ for ( TCBidx =0; TCBidx< pAdapter->PriQue[priIdx].iMaxTxDesc; TCBidx++){ idx = (TCBidx + 1) % pAdapter->PriQue[priIdx].iMaxTxDesc; pAdapter->PriQue[priIdx].pTcbArray[TCBidx].pNext = &pAdapter->PriQue[priIdx].pTcbArray[idx];/* * Jags... pAdapter->PriQue[priIdx].pTcbArray[TCBidx].pEndDesc = NULL; */ } } /* End of for (priIdx = 0; priIdx < NumPrio; priIdx++) */ return SUCCESS;} /* End of HsmTxInit() *//*******************************************************************************f** Name: * HsmRxInit** Description: * Create RCB list, Rx buffers and set up Rxd list.* This is called from HsmInitialize().** Parameters: * pAdapter - Pointer to the adapter context.** Return Value: * SUCCESS - RxInit successful.* RCB_ARRAY_ALLOC_FAILURE - RcbArray allocation failure.**f*******************************************************************************/CHARHsmRxInit(AdapterContext *pAdapter){ USHORT RCBidx, retval, Idx; UINT TotRCBsz = 0; AddrStruct Addr; UCHAR *Start_RCBarray, priIdx; UCHAR *Start_DescArray, *Start_DescArrayPa; #ifdef NSCDEBUG NsmDbgMsg("HsmRxInit: Allocating and setting up RCB and Rxd list.\n");#endif/* * Allocate Pool of RCBs */ for(priIdx = 0; priIdx < pAdapter->RxNumPrio; priIdx++) TotRCBsz += sizeof(HsmRCB) * pAdapter->RxDp[priIdx][DESCCNT]; pAdapter->pRcbArray = (PVOID) NsmMalloc(TotRCBsz); if (pAdapter->pRcbArray == NULL) return RCB_ARRAY_ALLOC_FAILURE; Start_RCBarray = (UCHAR *)pAdapter->pRcbArray; Start_DescArray = pAdapter->pDescList.VirtAddr + pAdapter->TotTxdPhySz; Start_DescArrayPa = pAdapter->pDescList.PhysAddr + pAdapter->TotTxdPhySz; for (priIdx = 0; priIdx < pAdapter->NumPrio; priIdx++) {/* * Assign Max number and number of free descriptors for this priority . */ pAdapter->PriQue[priIdx].iMaxRxDesc = pAdapter->PriQue[priIdx].iFreeRxDesc = pAdapter->RxDp[priIdx][DESCCNT]; pAdapter->PriQue[priIdx].pRxdArray = (DevDesc *)Start_DescArray; pAdapter->PriQue[priIdx].pRxdArrayPa = (DevDesc *)Start_DescArrayPa;/* * Assign RCBHead, RCBNext, RCBTail pointers for this priority. */ pAdapter->PriQue[priIdx].pRcbArray = (HsmRCB *)Start_RCBarray; pAdapter->PriQue[priIdx].pRcbListHead = pAdapter->PriQue[priIdx].pRcbListNext = pAdapter->PriQue[priIdx].pRcbArray;/* * Setup the RCB list (linking all the RCBs with "pNext" field in the RCB. * NULL is assigned to the "pNext" field of the last RCB . * Set up the Rxd List linking the "link" field in the descriptor and * set the OWN bit. */ for (RCBidx= 0; RCBidx < pAdapter->PriQue[priIdx].iMaxRxDesc; RCBidx++) { if (RCBidx == (pAdapter->PriQue[priIdx].iMaxRxDesc - 1)) { pAdapter->PriQue[priIdx].pRcbArray[RCBidx].pNext = NULL; pAdapter->PriQue[priIdx].pRxdArray[RCBidx].link = 0; SET_OWN(&pAdapter->PriQue[priIdx].pRxdArray[RCBidx], 1); } else { pAdapter->PriQue[priIdx].pRcbArray[RCBidx].pNext = &pAdapter->PriQue[priIdx].pRcbArray[RCBidx + 1]; pAdapter->PriQue[priIdx].pRxdArray[RCBidx].link = (UINT) (Start_DescArrayPa + ((RCBidx+1) * sizeof(DevDesc))); SET_OWN(&pAdapter->PriQue[priIdx].pRxdArray[RCBidx], 0); } /* * Set the Descriptor pointer in RCB. */ pAdapter->PriQue[priIdx].pRcbArray[RCBidx].pRxDp = &pAdapter->PriQue[priIdx].pRxdArray[RCBidx]; pAdapter->PriQue[priIdx].pRcbArray[RCBidx].pRxDpPa = &pAdapter->PriQue[priIdx].pRxdArrayPa[RCBidx];/* * Populate the Address structure and create the Rx Buffer. If allocation * failed then return the Priority index. */ Addr.BufSize = pAdapter->MaxPktSize; Addr.VirtAddr = Addr.PhysAddr = NULL; retval = NsmAllocatePacket(pAdapter->pNsmContext, &pAdapter->PriQue[priIdx].pRcbArray[RCBidx], &Addr); if (retval != SUCCESS || Addr.VirtAddr == NULL ) { /* * If RxBuffer Allocation failed for the current RCB of the current * priority Q and the number of RCBs allocated is below the * threshold value then free the buffers allocated for the RCBs in * the current priority Q and break the loop. In this case, the NumPrio * field in the Adapter context is set to the current priority value. */ if (RCBidx < pAdapter->RxDp[priIdx][MINDESCCNT] ) { #ifdef NSCDEBUG NsmDbgMsg("HsmRxInit: NsmAllocatePacket() failed and the no. of RCBs allocated is below the threshold value.\n");#endif for ( Idx = 0; Idx < RCBidx ; Idx++) { Addr.BufSize = pAdapter->MaxPktSize; Addr.VirtAddr = pAdapter->PriQue[priIdx].pRcbArray[Idx].pDataBuf; Addr.PhysAddr = (UCHAR *) pAdapter->PriQue[priIdx].pRcbArray[Idx].pRxDp->BufPtr; Addr.pCookie = pAdapter->PriQue[priIdx].pRcbArray[Idx].pOsCtrlBlk; NsmDeAllocatePacket(pAdapter->pNsmContext, &Addr, &pAdapter->PriQue[priIdx].pRcbArray[Idx]); } pAdapter->PriQue[priIdx].iMaxRxDesc = pAdapter->PriQue[priIdx].iFreeRxDesc = 0; break; } /* end of if (RCBidx < RxDp[][] */ pAdapter->PriQue[priIdx].iMaxRxDesc = pAdapter->PriQue[priIdx].iFreeRxDesc = RCBidx; /*Madhu Bug fix*/ pAdapter->PriQue[priIdx].pRcbArray[RCBidx-1].pNext = NULL; pAdapter->PriQue[priIdx].pRxdArray[RCBidx-1].link = 0; SET_OWN(&pAdapter->PriQue[priIdx].pRxdArray[RCBidx-1], 1); Start_RCBarray += (sizeof(HsmRCB) * (pAdapter->PriQue[priIdx].iMaxRxDesc - 1 )); pAdapter->PriQue[priIdx].pRcbListTail = (HsmRCB *)Start_RCBarray; Start_RCBarray += sizeof(HsmRCB); priIdx++; break; } /* if (retval != SUCCESS) */ /* * Fill the fields in the RCB. */ pAdapter->PriQue[priIdx].pRcbArray[RCBidx].pOsCtrlBlk = Addr.pCookie; pAdapter->PriQue[priIdx].pRcbArray[RCBidx].pRxDp->BufPtr = (UINT) Addr.PhysAddr; pAdapter->PriQue[priIdx].pRcbArray[RCBidx].pRxDp->CmdSts |= (Addr.BufSize | INTR); pAdapter->PriQue[priIdx].pRcbArray[RCBidx].pDataBuf = Addr.VirtAddr; } /* end of for(RCBidx = 0; RCBidx < GA622T_MAXRXDESC-1 ; RCBidx++) *//* * Terminate the RCB and Rxd list. */ if (retval != SUCCESS) break; /*Madhu Bug fix*/ Start_RCBarray += (sizeof(HsmRCB) * (pAdapter->PriQue[priIdx].iMaxRxDesc - 1 )); pAdapter->PriQue[priIdx].pRcbListTail = (HsmRCB *)Start_RCBarray; Start_RCBarray += sizeof(HsmRCB); Start_DescArray += ( sizeof(DevDesc) * pAdapter->PriQue[priIdx].iMaxRxDesc ); Start_DescArrayPa += ( sizeof(DevDesc) * pAdapter->PriQue[priIdx].iMaxRxDesc ); } /* end of for (priIdx = 0; priIdx < pAdapter->NumPrio; priIdx++) */ return priIdx;} /* End of HsmRxInit() *//*******************************************************************************f** Name: * HsmUnInitialize** Description: * Un-Initialize the adapter.** Parameters: * pAdapter - Pointer to the adapter context.** Return Value: * NONE.**f*******************************************************************************/VOIDHsmUnInitialize(AdapterContext *pAdapter){#ifdef NSCDEBUG NsmDbgMsg("HsmUnInitialize: UnInitializing the Adapter .\n");#endif NsmAcquireLock(pAdapter->pNsmContext, pAdapter->AdapterLock); if (!(pAdapter->AdapterStatus & ADAPTER_INITIALIZED)) { /*Ramit : Release lock before leaving*/ NsmReleaseLock(pAdapter->pNsmContext, pAdapter->AdapterLock); return ; } pAdapter->AdapterStatus &= ~(ADAPTER_INITIALIZED); NsmReleaseLock(pAdapter->pNsmContext, pAdapter->AdapterLock); HsmFreeResources(pAdapter, UNINITIALIZE);#ifdef NSCDEBUG NsmDbgMsg("HsmUnInitialize: Adapter uninitialized.\n");#endif return ;} /* end of HsmUnInitialize() */ /*******************************************************************************f** Name: * HsmFreeResources** Description: * Free the resources allocated based on the errcode passed.** Parameters: * pAdapter - Pointer to the adapter context.** errcode - UNINITIALIZE / RXINIT_FAILED ...** Return Value: * NONE.**f*******************************************************************************/VOIDHsmFreeResources(AdapterContext *pAdapter, UINT errcode){ AddrStruct Addr; USHORT Idx, RCBidx, priIdx; UINT RCBsz = 0, TCBsz; switch(errcode) { case UNINITIALIZE : case RXINIT_FAILED :/* * Free the Rx buffers allocated for all the priority queues. */ /*Madhu Change NumPrio to RxNumPrio for (Idx = 0; Idx < pAdapter->NumPrio; Idx++) {*/ for (Idx = 0; Idx < pAdapter->RxNumPrio; Idx++) { for (RCBidx = 0; RCBidx < pAdapter->PriQue[Idx].iMaxRxDesc; RCBidx++) { Addr.VirtAddr = pAdapter->PriQue[Idx].pRcbArray[RCBidx].pDataBuf; Addr.PhysAddr = (UCHAR *) pAdapter->PriQue[Idx].pRcbArray[RCBidx].pRxDp->BufPtr; Addr.BufSize = pAdapter->MaxPktSize; Addr.pCookie = pAdapter->PriQue[Idx].pRcbArray[RCBidx].pOsCtrlBlk; NsmDeAllocatePacket(pAdapter->pNsmContext, &Addr, &pAdapter->PriQue[Idx].pRcbArray[RCBidx]); } /* end of for(RCBidx.... ) */ } /* end of for( Idx = 0; Idx < pAdapter->NumPrio; Idx++) */ case RCB_ALLOC_FAILED:/* * Free RCB array */ if (pAdapter->pRcbArray) { RCBsz = 0; for(Idx = 0; Idx < pAdapter->NumPrio; Idx++) /*for(Idx = 0; Idx < pAdapter->RxNumPrio; Idx++) Madhu Bug*/ RCBsz += sizeof(HsmRCB) * pAdapter->RxDp[Idx][DESCCNT]; /* RCBsz += (sizeof(HsmRCB) * pAdapter->PriQue[Idx].iMaxRxDesc);*/ NsmFree((PVOID)pAdapter->pRcbArray, RCBsz); } case TCB_ALLOC_FAILED:/* * Free TCB array */ if (pAdapter->pTcbArray) { /*Madhu NumPrio to TxNumPrio*/ TCBsz = 0; for(Idx = 0; Idx < pAdapter->NumPrio; Idx++) /*TCBsz = (sizeof(HsmTCB) * pAdapter->PriQue[Idx].iMaxTxDesc);*/ TCBsz += (sizeof(HsmTCB) * pAdapter->TxDp[Idx][DESCCNT]); NsmFree(pAdapter->pTcbArray, TCBsz); }/* * Free the Descriptor array. */ if (pAdapter->pDescList.VirtAddr != NULL) { Addr.pCookie = pAdapter->pDescList.pCookie; Addr.VirtAddr = pAdapter->pDescList.VirtAddr; /*Madhu Free proper size*/ Addr.BufSize = pAdapter->pDescList.BufSize; Addr.pCookie = pAdapter->pDescList.pCookie; /*Madhu Add cache flag NsmFreeContiguous(pAdapter->pNsmContext,&Addr);*/ NsmFreeContiguous(pAdapter->pNsmContext,&Addr,0); } case DP_ALLOC_FAILED :/* * Free the priority queue allocated. */ NsmFree(pAdapter->PriQue, sizeof(PriorityQue) * pAdapter->NumPrio ); case PRI_QUE_FAILED :/* * Destroy the locks. */ NsmDestroyLock(pAdapter->pNsmContext, pAdapter->AdapterLock); NsmDestroyLock(pAdapter->pNsmContext, pAdapter->TxLock); break; } /* end of switch() */ return ;} /* End of HsmFreeResources() *//*******************************************************************************f** Name: * HsmInitContext** Description: * Initialize the HSM related fields in the adapter context. ** Parameters: * pAdapter - Pointer to the adapter context.** Return Value: * NONE.**f*******************************************************************************/VOIDHsmInitContext(AdapterContext *pAdapter){ UCHAR AdapterPQ ; UINT Ptscr_val, i;/* * Call HsmGetMacAddr() to read the MAC address from EEPROM and store it in * Adapter context. *//* Ramit : Tunable Parameter#ifdef _GA622T_ TxDp[0][MINDESCCNT] = MinTxDescCnt_0; TxDp[1][MINDESCCNT] = MinTxDescCnt_1; TxDp[2][MINDESCCNT] = MinTxDescCnt_2; TxDp[3][MINDESCCNT] = MinTxDescCnt_3; TxDp[0][DESCCNT] = MaxTxDescCnt_0; TxDp[1][DESCCNT] = MaxTxDescCnt_1; TxDp[2][DESCCNT] = MaxTxDescCnt_2; TxDp[3][DESCCNT] = MaxTxDescCnt_3; RxDp[0][MINDESCCNT] = MinRxDescCnt_0; RxDp[1][MINDESCCNT] = MinRxDescCnt_1; RxDp[2][MINDESCCNT] = MinRxDescCnt_2; RxDp[3][MINDESCCNT] = MinRxDescCnt_3; RxDp[0][DESCCNT] = MaxRxDescCnt_0; RxDp[1][DESCCNT] = MaxRxDescCnt_1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -