📄 cmm_mac_usb.c
字号:
// Here we didn't have any pre-allocated memory need to free. return Status; }/*========================================================================Routine Description: Allocate DMA memory blocks for send, receive.Arguments: pAd Pointer to our adapterReturn Value: NDIS_STATUS_SUCCESS NDIS_STATUS_FAILURE NDIS_STATUS_RESOURCESNote:========================================================================*/NDIS_STATUS RTMPAllocTxRxRingMemory( IN PRTMP_ADAPTER pAd){// COUNTER_802_11 pCounter = &pAd->WlanCounters; NDIS_STATUS Status; INT num; DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocTxRxRingMemory\n")); do { // Init the CmdQ and CmdQLock NdisAllocateSpinLock(&pAd->CmdQLock); NdisAcquireSpinLock(&pAd->CmdQLock); RTUSBInitializeCmdQ(&pAd->CmdQ); NdisReleaseSpinLock(&pAd->CmdQLock); NdisAllocateSpinLock(&pAd->MLMEBulkOutLock); //NdisAllocateSpinLock(&pAd->MLMEWaitQueueLock); NdisAllocateSpinLock(&pAd->BulkOutLock[0]); NdisAllocateSpinLock(&pAd->BulkOutLock[1]); NdisAllocateSpinLock(&pAd->BulkOutLock[2]); NdisAllocateSpinLock(&pAd->BulkOutLock[3]); NdisAllocateSpinLock(&pAd->BulkOutLock[4]); NdisAllocateSpinLock(&pAd->BulkOutLock[5]); NdisAllocateSpinLock(&pAd->BulkInLock); for (num = 0; num < NUM_OF_TX_RING; num++) { NdisAllocateSpinLock(&pAd->TxContextQueueLock[num]); } #ifdef RALINK_ATE NdisAllocateSpinLock(&pAd->GenericLock);#endif // RALINK_ATE //// NdisAllocateSpinLock(&pAd->MemLock); // Not used in RT28XX// NdisAllocateSpinLock(&pAd->MacTabLock); // init it in UserCfgInit()// NdisAllocateSpinLock(&pAd->BATabLock); // init it in BATableInit()// for(num=0; num<MAX_LEN_OF_BA_REC_TABLE; num++)// {// NdisAllocateSpinLock(&pAd->BATable.BARecEntry[num].RxReRingLock);// } // // Init Mac Table //// MacTableInitialize(pAd); // // Init send data structures and related parameters // Status = NICInitTransmit(pAd); if (Status != NDIS_STATUS_SUCCESS) break; // // Init receive data structures and related parameters // Status = NICInitRecv(pAd); if (Status != NDIS_STATUS_SUCCESS) break; pAd->PendingIoCount = 1; } while (FALSE); NdisZeroMemory(&pAd->FragFrame, sizeof(FRAGMENT_FRAME)); pAd->FragFrame.pFragPacket = RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE); if (pAd->FragFrame.pFragPacket == NULL) { Status = NDIS_STATUS_RESOURCES; } DBGPRINT_S(Status, ("<-- RTMPAllocTxRxRingMemory, Status=%x\n", Status)); return Status;}/*========================================================================Routine Description: Calls USB_InterfaceStop and frees memory allocated for the URBs calls NdisMDeregisterDevice and frees the memory allocated in VNetInitialize for the Adapter ObjectArguments: *pAd the raxx interface data pointerReturn Value: NoneNote:========================================================================*/VOID RTMPFreeTxRxRingMemory( IN PRTMP_ADAPTER pAd){#define LM_URB_FREE(pObj, Context, BufferSize) \ if (NULL != Context->pUrb) { \ RTUSB_UNLINK_URB(Context->pUrb); \ RTUSB_FREE_URB(Context->pUrb); \ Context->pUrb = NULL; } \ if (NULL != Context->TransferBuffer) { \ RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, BufferSize, \ Context->TransferBuffer, \ Context->data_dma); \ Context->TransferBuffer = NULL; } UINT i, acidx; PTX_CONTEXT pNullContext = &pAd->NullContext; PTX_CONTEXT pPsPollContext = &pAd->PsPollContext; PTX_CONTEXT pRTSContext = &pAd->RTSContext;// PHT_TX_CONTEXT pHTTXContext; //PRTMP_REORDERBUF pReorderBuf; POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;// RTMP_TX_RING *pTxRing; DBGPRINT(RT_DEBUG_ERROR, ("---> RTMPFreeTxRxRingMemory\n")); pObj = pObj; // Free all resources for the RECEIVE buffer queue. for(i=0; i<(RX_RING_SIZE); i++) { PRX_CONTEXT pRxContext = &(pAd->RxContext[i]); if (pRxContext) LM_URB_FREE(pObj, pRxContext, MAX_RXBULK_SIZE); } // Free PsPoll frame resource LM_URB_FREE(pObj, pPsPollContext, sizeof(TX_BUFFER)); // Free NULL frame resource LM_URB_FREE(pObj, pNullContext, sizeof(TX_BUFFER)); // Free RTS frame resource LM_URB_FREE(pObj, pRTSContext, sizeof(TX_BUFFER)); // Free beacon frame resource for(i=0; i<BEACON_RING_SIZE; i++) { PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]); if (pBeaconContext) LM_URB_FREE(pObj, pBeaconContext, sizeof(TX_BUFFER)); } // Free mgmt frame resource for(i = 0; i < MGMT_RING_SIZE; i++) { PTX_CONTEXT pMLMEContext = (PTX_CONTEXT)pAd->MgmtRing.Cell[i].AllocVa; //LM_URB_FREE(pObj, pMLMEContext, sizeof(TX_BUFFER)); if (NULL != pAd->MgmtRing.Cell[i].pNdisPacket) { RTMPFreeNdisPacket(pAd, pAd->MgmtRing.Cell[i].pNdisPacket); pAd->MgmtRing.Cell[i].pNdisPacket = NULL; pMLMEContext->TransferBuffer = NULL; } if (pMLMEContext) { if (NULL != pMLMEContext->pUrb) { RTUSB_UNLINK_URB(pMLMEContext->pUrb); RTUSB_FREE_URB(pMLMEContext->pUrb); pMLMEContext->pUrb = NULL; } } } if (pAd->MgmtDescRing.AllocVa) os_free_mem(pAd, pAd->MgmtDescRing.AllocVa); // Free Tx frame resource for (acidx = 0; acidx < 4; acidx++) { PHT_TX_CONTEXT pHTTXContext = &(pAd->TxContext[acidx]); if (pHTTXContext) LM_URB_FREE(pObj, pHTTXContext, sizeof(HTTX_BUFFER)); } if (pAd->FragFrame.pFragPacket) RELEASE_NDIS_PACKET(pAd, pAd->FragFrame.pFragPacket, NDIS_STATUS_SUCCESS); for(i=0; i<6; i++) { NdisFreeSpinLock(&pAd->BulkOutLock[i]); } NdisFreeSpinLock(&pAd->BulkInLock); NdisFreeSpinLock(&pAd->MLMEBulkOutLock); NdisFreeSpinLock(&pAd->CmdQLock);#ifdef RALINK_ATE NdisFreeSpinLock(&pAd->GenericLock);#endif // RALINK_ATE // // Clear all pending bulk-out request flags. RTUSB_CLEAR_BULK_FLAG(pAd, 0xffffffff); // NdisFreeSpinLock(&pAd->MacTabLock);// for(i=0; i<MAX_LEN_OF_BA_REC_TABLE; i++)// {// NdisFreeSpinLock(&pAd->BATable.BARecEntry[i].RxReRingLock);// } DBGPRINT(RT_DEBUG_ERROR, ("<--- RTMPFreeTxRxRingMemory\n"));}/*========================================================================Routine Description: Write WLAN MAC address to USB 2870.Arguments: pAd Pointer to our adapterReturn Value: NDIS_STATUS_SUCCESSNote:========================================================================*/NDIS_STATUS RTUSBWriteHWMACAddress( IN PRTMP_ADAPTER pAd){ MAC_DW0_STRUC StaMacReg0; MAC_DW1_STRUC StaMacReg1; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; LARGE_INTEGER NOW; // initialize the random number generator RTMP_GetCurrentSystemTime(&NOW); if (pAd->bLocalAdminMAC != TRUE) { pAd->CurrentAddress[0] = pAd->PermanentAddress[0]; pAd->CurrentAddress[1] = pAd->PermanentAddress[1]; pAd->CurrentAddress[2] = pAd->PermanentAddress[2]; pAd->CurrentAddress[3] = pAd->PermanentAddress[3]; pAd->CurrentAddress[4] = pAd->PermanentAddress[4]; pAd->CurrentAddress[5] = pAd->PermanentAddress[5]; } // Write New MAC address to MAC_CSR2 & MAC_CSR3 & let ASIC know our new MAC StaMacReg0.field.Byte0 = pAd->CurrentAddress[0]; StaMacReg0.field.Byte1 = pAd->CurrentAddress[1]; StaMacReg0.field.Byte2 = pAd->CurrentAddress[2]; StaMacReg0.field.Byte3 = pAd->CurrentAddress[3]; StaMacReg1.field.Byte4 = pAd->CurrentAddress[4]; StaMacReg1.field.Byte5 = pAd->CurrentAddress[5]; StaMacReg1.field.U2MeMask = 0xff; DBGPRINT_RAW(RT_DEBUG_TRACE, ("Local MAC = %02x:%02x:%02x:%02x:%02x:%02x\n", pAd->CurrentAddress[0], pAd->CurrentAddress[1], pAd->CurrentAddress[2], pAd->CurrentAddress[3], pAd->CurrentAddress[4], pAd->CurrentAddress[5])); RTUSBWriteMACRegister(pAd, MAC_ADDR_DW0, StaMacReg0.word); RTUSBWriteMACRegister(pAd, MAC_ADDR_DW1, StaMacReg1.word); return Status;}/*========================================================================Routine Description: Disable DMA.Arguments: *pAd the raxx interface data pointerReturn Value: NoneNote:========================================================================*/VOID RT28XXDMADisable( IN RTMP_ADAPTER *pAd){ // no use}/*========================================================================Routine Description: Enable DMA.Arguments: *pAd the raxx interface data pointerReturn Value: NoneNote:========================================================================*/VOID RT28XXDMAEnable( IN RTMP_ADAPTER *pAd){ WPDMA_GLO_CFG_STRUC GloCfg; USB_DMA_CFG_STRUC UsbCfg; int i = 0; RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4); do { RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0)) break; DBGPRINT(RT_DEBUG_TRACE, ("==> DMABusy\n")); RTMPusecDelay(1000); i++; }while ( i <200); RTMPusecDelay(50); GloCfg.field.EnTXWriteBackDDONE = 1; GloCfg.field.EnableRxDMA = 1; GloCfg.field.EnableTxDMA = 1; DBGPRINT(RT_DEBUG_TRACE, ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word)); RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word); UsbCfg.word = 0; UsbCfg.field.phyclear = 0; /* usb version is 1.1,do not use bulk in aggregation */ if (pAd->BulkInMaxPacketSize == 512) UsbCfg.field.RxBulkAggEn = 1; /* for last packet, PBF might use more than limited, so minus 2 to prevent from error */ UsbCfg.field.RxBulkAggLmt = (MAX_RXBULK_SIZE /1024)-3; UsbCfg.field.RxBulkAggTOut = 0x80; /* 2006-10-18 */ UsbCfg.field.RxBulkEn = 1; UsbCfg.field.TxBulkEn = 1; RTUSBWriteMACRegister(pAd, USB_DMA_CFG, UsbCfg.word);}/******************************************************************** * * 2870 Beacon Update Related functions. * ********************************************************************/ /*========================================================================Routine Description: Write Beacon buffer to Asic.Arguments: *pAd the raxx interface data pointerReturn Value: NoneNote:========================================================================*/VOID RT28xx_UpdateBeaconToAsic( IN RTMP_ADAPTER *pAd, IN INT apidx, IN ULONG FrameLen, IN ULONG UpdatePos){ PUCHAR pBeaconFrame = NULL; UCHAR *ptr; UINT i, padding; BEACON_SYNC_STRUCT *pBeaconSync = pAd->CommonCfg.pBeaconSync; UINT32 longValue;// USHORT shortValue; BOOLEAN bBcnReq = FALSE; UCHAR bcn_idx = 0; if (pBeaconFrame == NULL) { DBGPRINT(RT_DEBUG_ERROR,("pBeaconFrame is NULL!\n")); return; } if (pBeaconSync == NULL) { DBGPRINT(RT_DEBUG_ERROR,("pBeaconSync is NULL!\n")); return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -