?? rtmp_init.c
字號(hào):
if ( NULL != pMLMEContext->pUrb ) { RTUSB_UNLINK_URB(pMLMEContext->pUrb); usb_free_urb(pMLMEContext->pUrb); pMLMEContext->pUrb = NULL; } if ( NULL != pMLMEContext->TransferBuffer ) { kfree( pMLMEContext->TransferBuffer); pMLMEContext->TransferBuffer = NULL; } }out1: for (acidx = 0; acidx < 4; acidx++) { for ( i= 0; i < TX_RING_SIZE; i++ ) { PTX_CONTEXT pTxContext = &(pAd->TxContext[acidx][i]); if ( NULL != pTxContext->pUrb ) { RTUSB_UNLINK_URB(pTxContext->pUrb); usb_free_urb(pTxContext->pUrb); pTxContext->pUrb = NULL; } if ( NULL != pTxContext->TransferBuffer ) { kfree( pTxContext->TransferBuffer); pTxContext->TransferBuffer = NULL; } } }done: return Status;}/* ======================================================================== Routine Description: Initialize receive data structures Arguments: Adapter Pointer to our adapter Return Value: NDIS_STATUS_SUCCESS NDIS_STATUS_RESOURCES Note: Initialize all receive releated private buffer, include those define in RTMP_ADAPTER structure and all private data structures. The mahor work is to allocate buffer for each packet and chain buffer to NDIS packet descriptor. ========================================================================*/NDIS_STATUS NICInitRecv( IN PRTMP_ADAPTER pAd){ UCHAR i; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; DBGPRINT(RT_DEBUG_TRACE,"--> NICInitRecv\n"); pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer pAd->CurRxBulkInIndex = 0; atomic_set( &pAd->PendingRx, 0); for (i = 0; i < RX_RING_SIZE; i++) { PRX_CONTEXT pRxContext = &(pAd->RxContext[i]); pRxContext->pUrb = RT_USB_ALLOC_URB(0); if(pRxContext->pUrb == NULL) { Status = NDIS_STATUS_RESOURCES; DBGPRINT(RT_DEBUG_TRACE,"--> pRxContext->pUrb == NULL\n"); break; } pRxContext->TransferBuffer= (PUCHAR) kmalloc(BUFFER_SIZE, MEM_ALLOC_FLAG); if(!pRxContext->TransferBuffer) { DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n"); Status = NDIS_STATUS_RESOURCES; break; } memset(pRxContext->TransferBuffer, 0, BUFFER_SIZE); pRxContext->pAd = pAd; pRxContext->InUse = FALSE; atomic_set(&pRxContext->IrpLock, IRPLOCK_COMPLETED); pRxContext->IRPPending = FALSE; } if (Status) ReleaseAdapter(pAd, TRUE, FALSE); DBGPRINT(RT_DEBUG_TRACE,"<-- NICInitRecv status=%d\n", Status); return Status;}//////////////////////////////////////////////////////////////////////////////// FUNCTION// ReleaseAdapter//// DESCRIPTION// Frees memory allocated for URBs and transfer buffers.//// INPUT// Adapter Pointer to RTMP_ADAPTER structure//// OUTPUT// -//////////////////////////////////////////////////////////////////////////////VOID ReleaseAdapter( IN PRTMP_ADAPTER pAd, IN BOOLEAN IsFree, IN BOOLEAN IsOnlyTx){ UINT i, acidx; PTX_CONTEXT pNullContext = &pAd->NullContext; PTX_CONTEXT pPsPollContext = &pAd->PsPollContext; PTX_CONTEXT pRTSContext = &pAd->RTSContext; DBGPRINT(RT_DEBUG_TRACE, "---> ReleaseAdapter\n"); if (!IsOnlyTx) { // Free all resources for the RECEIVE buffer queue. for (i = 0; i < RX_RING_SIZE; i++) { PRX_CONTEXT pRxContext = &(pAd->RxContext[i]); if (pRxContext->pUrb != NULL) { RTUSB_UNLINK_URB(pRxContext->pUrb); if (IsFree) usb_free_urb(pRxContext->pUrb); pRxContext->pUrb = NULL; } if (pRxContext->TransferBuffer != NULL) { kfree(pRxContext->TransferBuffer); pRxContext->TransferBuffer = NULL; } } } // Free PsPoll frame resource if (NULL != pPsPollContext->pUrb) { RTUSB_UNLINK_URB(pPsPollContext->pUrb); if (IsFree) usb_free_urb(pPsPollContext->pUrb); pPsPollContext->pUrb = NULL; } if (NULL != pPsPollContext->TransferBuffer) { kfree(pPsPollContext->TransferBuffer); pPsPollContext->TransferBuffer = NULL; } // Free NULL frame resource if (NULL != pNullContext->pUrb) { RTUSB_UNLINK_URB(pNullContext->pUrb); if (IsFree) usb_free_urb(pNullContext->pUrb); pNullContext->pUrb = NULL; } if (NULL != pNullContext->TransferBuffer) { kfree(pNullContext->TransferBuffer); pNullContext->TransferBuffer = NULL; } // Free RTS frame resource if (NULL != pRTSContext->pUrb) { RTUSB_UNLINK_URB(pRTSContext->pUrb); if (IsFree) usb_free_urb(pRTSContext->pUrb); pRTSContext->pUrb = NULL; } if (NULL != pRTSContext->TransferBuffer) { kfree(pRTSContext->TransferBuffer); pRTSContext->TransferBuffer = NULL; } // Free beacon frame resource for (i = 0; i < BEACON_RING_SIZE; i++) { PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]); if ( NULL != pBeaconContext->pUrb ) { RTUSB_UNLINK_URB(pBeaconContext->pUrb); if (IsFree) usb_free_urb(pBeaconContext->pUrb); pBeaconContext->pUrb = NULL; } if ( NULL != pBeaconContext->TransferBuffer ) { kfree( pBeaconContext->TransferBuffer); pBeaconContext->TransferBuffer = NULL; } } // Free Prio frame resource for ( i= 0; i < PRIO_RING_SIZE; i++ ) { PTX_CONTEXT pMLMEContext = &(pAd->MLMEContext[i]); if ( NULL != pMLMEContext->pUrb ) { RTUSB_UNLINK_URB(pMLMEContext->pUrb); if (IsFree) usb_free_urb(pMLMEContext->pUrb); pMLMEContext->pUrb = NULL; } if ( NULL != pMLMEContext->TransferBuffer ) { kfree( pMLMEContext->TransferBuffer); pMLMEContext->TransferBuffer = NULL; } } // Free Tx frame resource for (acidx = 0; acidx < 4; acidx++) { for ( i= 0; i < TX_RING_SIZE; i++ ) { PTX_CONTEXT pTxContext = &(pAd->TxContext[acidx][i]); if ( NULL != pTxContext->pUrb ) { RTUSB_UNLINK_URB(pTxContext->pUrb); if (IsFree) usb_free_urb(pTxContext->pUrb); pTxContext->pUrb = NULL; } if ( NULL != pTxContext->TransferBuffer ) { kfree( pTxContext->TransferBuffer); pTxContext->TransferBuffer = NULL; } } } DBGPRINT(RT_DEBUG_TRACE, "<--- ReleaseAdapter\n");}/* ======================================================================== Routine Description: Allocate DMA memory blocks for send, receive Arguments: Adapter Pointer to our adapter Return Value: None. Note: ========================================================================*/void RTMPInitAdapterBlock( IN PRTMP_ADAPTER pAd){ UINT i; PCmdQElmt cmdqelmt; DBGPRINT(RT_DEBUG_TRACE, "--> RTMPInitAdapterBlock\n"); // init counter pAd->WlanCounters.TransmittedFragmentCount.vv.LowPart = 0; pAd->WlanCounters.MulticastTransmittedFrameCount.vv.LowPart =0; pAd->WlanCounters.FailedCount.vv.LowPart =0; pAd->WlanCounters.NoRetryCount.vv.LowPart =0; pAd->WlanCounters.RetryCount.vv.LowPart =0; pAd->WlanCounters.MultipleRetryCount.vv.LowPart =0; pAd->WlanCounters.RTSSuccessCount.vv.LowPart =0; pAd->WlanCounters.RTSFailureCount.vv.LowPart =0; pAd->WlanCounters.ACKFailureCount.vv.LowPart =0; pAd->WlanCounters.FrameDuplicateCount.vv.LowPart =0; pAd->WlanCounters.ReceivedFragmentCount.vv.LowPart =0; pAd->WlanCounters.MulticastReceivedFrameCount.vv.LowPart =0; pAd->WlanCounters.FCSErrorCount.vv.LowPart =0; pAd->WlanCounters.TransmittedFragmentCount.vv.HighPart = 0; pAd->WlanCounters.MulticastTransmittedFrameCount.vv.HighPart =0; pAd->WlanCounters.FailedCount.vv.HighPart =0; pAd->WlanCounters.NoRetryCount.vv.HighPart =0; pAd->WlanCounters.RetryCount.vv.HighPart =0; pAd->WlanCounters.MultipleRetryCount.vv.HighPart =0; pAd->WlanCounters.RTSSuccessCount.vv.HighPart =0; pAd->WlanCounters.RTSFailureCount.vv.HighPart =0; pAd->WlanCounters.ACKFailureCount.vv.HighPart =0; pAd->WlanCounters.FrameDuplicateCount.vv.HighPart =0; pAd->WlanCounters.ReceivedFragmentCount.vv.HighPart =0; pAd->WlanCounters.MulticastReceivedFrameCount.vv.HighPart =0; pAd->WlanCounters.FCSErrorCount.vv.HighPart =0; do { for (i = 0; i < COMMAND_QUEUE_SIZE; i++) { cmdqelmt = &(pAd->CmdQElements[i]); memset(cmdqelmt, 0, sizeof(CmdQElmt)); cmdqelmt->buffer = NULL; cmdqelmt->CmdFromNdis = FALSE; cmdqelmt->InUse = FALSE; } RTUSBInitializeCmdQ(&pAd->CmdQ); pAd->MLMEThr_pid= -1; pAd->RTUSBCmdThr_pid= -1; init_MUTEX_LOCKED(&(pAd->usbdev_semaphore)); init_MUTEX_LOCKED(&(pAd->mlme_semaphore)); init_MUTEX_LOCKED(&(pAd->RTUSBCmd_semaphore)); init_completion (&pAd->mlmenotify); // event initially non-signalled init_completion (&pAd->cmdnotify); // event initially non-signalled //////////////////////// // Spinlock NdisAllocateSpinLock(&pAd->BulkOutLock[0]); NdisAllocateSpinLock(&pAd->BulkOutLock[1]); NdisAllocateSpinLock(&pAd->BulkOutLock[2]); NdisAllocateSpinLock(&pAd->BulkOutLock[3]); NdisAllocateSpinLock(&pAd->CmdQLock); NdisAllocateSpinLock(&pAd->MLMEWaitQueueLock); NdisAllocateSpinLock(&pAd->MLMEQLock); NdisAllocateSpinLock(&pAd->BulkFlagsLock); } while (FALSE); DBGPRINT(RT_DEBUG_TRACE, "<-- RTMPInitAdapterBlock\n");}NDIS_STATUS RTUSBWriteHWMACAddress( IN PRTMP_ADAPTER pAd){ MAC_CSR2_STRUC StaMacReg0; MAC_CSR3_STRUC StaMacReg1; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; PUCHAR curMAC; int t; if (pAd->bLocalAdminMAC != TRUE) { if (!memcmp(pAd->net_dev->dev_addr, "\x00\x00\x00\x00\x00\x00", 6)) { KPRINT(KERN_INFO, "using permanent MAC addr\n"); DBGPRINT(RT_DEBUG_INFO, "- using permanent MAC addr\n"); curMAC = pAd->PermanentAddress; // Also meets 2.6.24 pre-up requirements - bb memcpy(pAd->net_dev->dev_addr, curMAC, pAd->net_dev->addr_len); } else { KPRINT(KERN_INFO, "using net dev supplied MAC addr\n"); DBGPRINT(RT_DEBUG_INFO, "- using net dev supplied MAC addr\n"); curMAC = pAd->net_dev->dev_addr; } KPRINT(KERN_INFO, "Active MAC addr: %02x:%02x:%02x:%02x:%02x:%02x\n", curMAC[0], curMAC[1], curMAC[2], curMAC[3], curMAC[4], curMAC[5]); for (t=0; t<6; t++) pAd->CurrentAddress[t] = curMAC[t]; } // 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; KPRINT(KERN_INFO, "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]); DBGPRINT(RT_DEBUG_INFO, "- %s: Local MAC = %02x:%02x:%02x:%02x:%02x:%02x\n", __FUNCTION__, pAd->CurrentAddress[0], pAd->CurrentAddress[1], pAd->CurrentAddress[2], pAd->CurrentAddress[3], pAd->CurrentAddress[4], pAd->CurrentAddress[5]); RTUSBWriteMACRegister(pAd, MAC_CSR2, StaMacReg0.word); RTUSBWriteMACRegister(pAd, MAC_CSR3, StaMacReg1.word); return Status;}/* ======================================================================== Routine Description: Read initial parameters from EEPROM Arguments: Adapter Pointer to our adapter Return Value: None Note: ========================================================================*/VOID NICReadEEPROMParameters( IN PRTMP_ADAPTER pAd){ USHORT i, value, value2; EEPROM_ANTENNA_STRUC Antenna; EEPROM_VERSION_STRUC Version; CHAR ChannelTxPower[MAX_NUM_OF_CHANNELS]; EEPROM_LED_STRUC LedSetting; DBGPRINT(RT_DEBUG_TRACE, "--> NICReadEEPROMParameters\n"); //Read MAC address. RTUSBReadEEPROM(pAd, EEPROM_MAC_ADDRESS_BASE_OFFSET, pAd->PermanentAddress, MAC_ADDR_LEN); DBGPRINT(RT_DEBUG_INFO, "- Local MAC = %02x:%02x:%02x:%02x:%02x:%02x\n", pAd->PermanentAddress[0], pAd->PermanentAddress[1], pAd->PermanentAddress[2], pAd->PermanentAddress[3], pAd->PermanentAddress[4], pAd->PermanentAddress[5]); // Init the channel number for TX channel power // 0. 11b/g for (i = 0; i < 14; i++) pAd->TxPower[i].Channel = i + 1; // 1. UNI 36 - 64 for (i = 0; i < 8; i++) pAd->TxPower[i + 14].Channel = 36 + i * 4; // 2. HipperLAN 2 100 - 140 for (i = 0; i < 11; i++) pAd->TxPower[i + 22].Channel = 100 + i * 4; // 3. UNI 140 - 165 for (i = 0; i < 5; i++) pAd->TxPower[i + 33].Channel = 149 + i * 4; // 34/38/42/46 for (i = 0; i < 4; i++) pAd->TxPower[i + 38].Channel = 34 + i * 4; // if E2PROM version mismatch with driver's expectation, then skip // all subsequent E2RPOM retieval and set a system error bit to notify GUI RTUSBReadEEPROM(pAd, EEPROM_VERSION_OFFSET, (PUCHAR)&Version.word, 2); Version.word = le16_to_cpu(Version.word); pAd->EepromVersion = Version.field.Version + Version.field.FaeReleaseNumber * 256; DBGPRINT(RT_DEBUG_INFO, "E2PROM: Version = %d, FAE release #%d\n", Version.field.Version, Version.field.FaeReleaseNumber); // Read BBP default from EEPROM, store to array(EEPROMDefaultValue) in pAd
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -