📄 rtmp_init.c
字号:
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:
NDIS_STATUS_SUCCESS
NDIS_STATUS_FAILURE
NDIS_STATUS_RESOURCES
Note:
========================================================================
*/
NDIS_STATUS RTMPInitAdapterBlock(
IN PRTMP_ADAPTER pAd)
{
NDIS_STATUS Status=NDIS_STATUS_SUCCESS;
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]);
NdisZeroMemory(cmdqelmt, sizeof(CmdQElmt));
cmdqelmt->buffer = NULL;
cmdqelmt->CmdFromNdis = FALSE;
cmdqelmt->InUse = FALSE;
}
RTUSBInitializeCmdQ(&pAd->CmdQ);
init_MUTEX(&(pAd->usbdev_semaphore));
init_MUTEX_LOCKED(&(pAd->mlme_semaphore));
init_MUTEX_LOCKED(&(pAd->RTUSBCmd_semaphore));
init_completion (&pAd->notify); // event initially non-signalled
////////////////////////
// Spinlock
NdisAllocateSpinLock(&pAd->MLMEQLock);
NdisAllocateSpinLock(&pAd->BulkOutLock[0]);
NdisAllocateSpinLock(&pAd->BulkOutLock[1]);
NdisAllocateSpinLock(&pAd->BulkOutLock[2]);
NdisAllocateSpinLock(&pAd->BulkOutLock[3]);
NdisAllocateSpinLock(&pAd->CmdQLock);
NdisAllocateSpinLock(&pAd->SendTxWaitQueueLock[0]);
NdisAllocateSpinLock(&pAd->SendTxWaitQueueLock[1]);
NdisAllocateSpinLock(&pAd->SendTxWaitQueueLock[2]);
NdisAllocateSpinLock(&pAd->SendTxWaitQueueLock[3]);
NdisAllocateSpinLock(&pAd->DeQueueLock[0]);
NdisAllocateSpinLock(&pAd->DeQueueLock[1]);
NdisAllocateSpinLock(&pAd->DeQueueLock[2]);
NdisAllocateSpinLock(&pAd->DeQueueLock[3]);
NdisAllocateSpinLock(&pAd->DataQLock[0]);
NdisAllocateSpinLock(&pAd->DataQLock[1]);
NdisAllocateSpinLock(&pAd->DataQLock[2]);
NdisAllocateSpinLock(&pAd->DataQLock[3]);
NdisAllocateSpinLock(&pAd->MLMEWaitQueueLock);
} while (FALSE);
DBGPRINT(RT_DEBUG_TRACE, "<-- RTMPInitAdapterBlock\n");
return Status;
}
NDIS_STATUS RTUSBWriteHWMACAddress(
IN PRTMP_ADAPTER pAd)
{
MAC_CSR2_STRUC StaMacReg0;
MAC_CSR3_STRUC StaMacReg1;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
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_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;
USHORT mac_tmp1,mac_tmp2,mac_tmp3,mac_tmp4;
DBGPRINT(RT_DEBUG_TRACE, "--> NICReadEEPROMParameters\n");
//Read MAC address.
RTUSBReadEEPROM(pAd, EEPROM_MAC_ADDRESS_BASE_OFFSET,pAd->PermanentAddress, MAC_ADDR_LEN);
//Local MAC = 1400:1178:fd5:00:00:00
pAd->PermanentAddress[3]= pAd->PermanentAddress[0]>>8;
pAd->PermanentAddress[4]= pAd->PermanentAddress[1]>>8;
pAd->PermanentAddress[5]= pAd->PermanentAddress[2]>>8;
pAd->PermanentAddress[0] &= 0xff;
pAd->PermanentAddress[1] &= 0xff;
pAd->PermanentAddress[2] &= 0xff;
mac_tmp1 = pAd->PermanentAddress[1];
mac_tmp2 = pAd->PermanentAddress[2];
mac_tmp3 = pAd->PermanentAddress[3];
mac_tmp4 = pAd->PermanentAddress[4];
pAd->PermanentAddress[1] = mac_tmp3;
pAd->PermanentAddress[2] = mac_tmp1;
pAd->PermanentAddress[3] = mac_tmp4;
pAd->PermanentAddress[4] = mac_tmp2;
DBGPRINT_RAW(RT_DEBUG_TRACE, "Local MAC = %x:%x:%x:%x:%x:%x\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);
pAd->EepromVersion = Version.field.Version + Version.field.FaeReleaseNumber * 256;
DBGPRINT(RT_DEBUG_TRACE, "E2PROM: Version = %d, FAE release #%d\n", Version.field.Version, Version.field.FaeReleaseNumber);
// Read BBP default value from EEPROM and store to array(EEPROMDefaultValue) in pAd
RTUSBReadEEPROM(pAd, EEPROM_BBP_BASE_OFFSET, (PUCHAR)(pAd->EEPROMDefaultValue), 2 * NUM_EEPROM_BBP_PARMS);
// We have to parse NIC configuration 0 at here.
// If TSSI did not have preloaded value, it should reset the TxAutoAgc to false
// Therefore, we have to read TxAutoAgc control beforehand.
// Read Tx AGC control bit
Antenna.word = pAd->EEPROMDefaultValue[0];
if (Antenna.field.DynamicTxAgcControl == 1)
pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE;
else
pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE;
//
// Reset PhyMode if we don't support 802.11a
//
if ((pAd->PortCfg.PhyMode == PHY_11ABG_MIXED) || (pAd->PortCfg.PhyMode == PHY_11A))
{
//
// Only RFIC_5226, RFIC_5225 suport 11a
//
if ((Antenna.field.RfIcType == RFIC_2528) || (Antenna.field.RfIcType == RFIC_2527))
pAd->PortCfg.PhyMode = PHY_11BG_MIXED;
//
// Reset Adhoc Mode if we don't support 802.11a
//
if ((pAd->PortCfg.AdhocMode == ADHOC_11A) || (pAd->PortCfg.AdhocMode == ADHOC_11ABG_MIXED))
{
//
// Only RFIC_5226, RFIC_5225 suport 11a
//
if ((Antenna.field.RfIcType == RFIC_2528) || (Antenna.field.RfIcType == RFIC_2527))
pAd->PortCfg.AdhocMode = ADHOC_11BG_MIXED;
}
}
// Read Tx power value for all 14 channels
// Value from 1 - 0x7f. Default value is 24.
// 0. 11b/g
// Power value 0xFA (-6) ~ 0x24 (36)
RTUSBReadEEPROM(pAd, EEPROM_G_TX_PWR_OFFSET, ChannelTxPower, 2 * NUM_EEPROM_TX_G_PARMS);
for (i = 0; i < 2 * NUM_EEPROM_TX_G_PARMS; i++)
{
if ((ChannelTxPower[i] > 36) || (ChannelTxPower[i] < -6))
pAd->TxPower[i].Power = 24;
else
pAd->TxPower[i].Power = ChannelTxPower[i];
DBGPRINT_RAW(RT_DEBUG_INFO, "Tx power for channel %d : %0x\n", pAd->TxPower[i].Channel, pAd->TxPower[i].Power);
}
// 1. UNI 36 - 64, HipperLAN 2 100 - 140, UNI 140 - 165
// Power value 0xFA (-6) ~ 0x24 (36)
RTUSBReadEEPROM(pAd, EEPROM_A_TX_PWR_OFFSET, ChannelTxPower, MAX_NUM_OF_A_CHANNELS);
for (i = 0; i < MAX_NUM_OF_A_CHANNELS; i++)
{
if ((ChannelTxPower[i] > 36) || (ChannelTxPower[i] < -6))
pAd->TxPower[i + 14].Power = 24;
else
pAd->TxPower[i + 14].Power = ChannelTxPower[i];
DBGPRINT_RAW(RT_DEBUG_INFO, "Tx power for channel %d : %0x\n", pAd->TxPower[i + 14].Channel, pAd->TxPower[i + 14].Power);
}
//
// Please note, we must skip frist value, so we get TxPower as ChannelTxPower[i + 1];
// because the TxPower was stored from 0x7D, but we need to read EEPROM from 0x7C. (Word alignment)
//
// for J52, 34/38/42/46
RTUSBReadEEPROM(pAd, EEPROM_J52_TX_PWR_OFFSET, ChannelTxPower, 6); //must Read even valuse
for (i = 0; i < 4; i++)
{
ASSERT(pAd->TxPower[J52_CHANNEL_START_OFFSET + i].Channel == 34 + i * 4);
if ((ChannelTxPower[i] > 36) || (ChannelTxPower[i] < -6))
pAd->TxPower[J52_CHANNEL_START_OFFSET + i].Power = 24;
else
pAd->TxPower[J52_CHANNEL_START_OFFSET + i].Power = ChannelTxPower[i + 1];
DBGPRINT_RAW(RT_DEBUG_INFO, "Tx power for channel %d : %0x\n", pAd->TxPower[J52_CHANNEL_START_OFFSET + i].Channel, pAd->TxPower[J52_CHANNEL_START_OFFSET + i].Power);
}
// Read TSSI reference and TSSI boundary for temperature compensation.
// 0. 11b/g
{
RTUSBReadEEPROM(pAd, EEPROM_BG_TSSI_CALIBRAION, ChannelTxPower, 10);
pAd->TssiMinusBoundaryG[4] = ChannelTxPower[0];
pAd->TssiMinusBoundaryG[3] = ChannelTxPower[1];
pAd->TssiMinusBoundaryG[2] = ChannelTxPower[2];
pAd->TssiMinusBoundaryG[1] = ChannelTxPower[3];
pAd->TssiPlusBoundaryG[1] = ChannelTxPower[4];
pAd->TssiPlusBoundaryG[2] = ChannelTxPower[5];
pAd->TssiPlusBoundaryG[3] = ChannelTxPower[6];
pAd->TssiPlusBoundaryG[4] = ChannelTxPower[7];
pAd->TssiRefG = ChannelTxPower[8];
pAd->TxAgcStepG = ChannelTxPower[9];
pAd->TxAgcCompensateG = 0;
pAd->TssiMinusBoundaryG[0] = pAd->TssiRefG;
pAd->TssiPlusBoundaryG[0] = pAd->TssiRefG;
// Disable TxAgc if the based value is not right
if (pAd->TssiRefG == 0xff)
pAd->bAutoTxAgcG = FALSE;
DBGPRINT(RT_DEBUG_TRACE,"E2PROM: G Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
pAd->TssiMinusBoundaryG[4], pAd->TssiMinusBoundaryG[3], pAd->TssiMinusBoundaryG[2], pAd->TssiMinusBoundaryG[1],
pAd->TssiRefG,
pAd->TssiPlusBoundaryG[1], pAd->TssiPlusBoundaryG[2], pAd->TssiPlusBoundaryG[3], pAd->TssiPlusBoundaryG[4],
pAd->TxAgcStepG, pAd->bAutoTxAgcG);
}
// 1. 11a
{
RTUSBReadEEPROM(pAd, EEPROM_A_TSSI_CALIBRAION, ChannelTxPower, 10);
pAd->TssiMinusBoundaryA[4] = ChannelTxPower[0];
pAd->TssiMinusBoundaryA[3] = ChannelTxPower[1];
pAd->TssiMinusBoundaryA[2] = ChannelTxPower[2];
pAd->TssiMinusBoundaryA[1] = ChannelTxPower[3];
pAd->TssiPlusBoundaryA[1] = ChannelTxPower[4];
pAd->TssiPlusBoundaryA[2] = ChannelTxPower[5];
pAd->TssiPlusBoundaryA[3] = ChannelTxPower[6];
pAd->TssiPlusBoundaryA[4] = ChannelTxPower[7];
pAd->TssiRefA = ChannelTxPower[8];
pAd->TxAgcStepA = ChannelTxPower[9];
pAd->TxAgcCompensateA = 0;
pAd->TssiMinusBoundaryA[0] = pAd->TssiRefA;
pAd->TssiPlusBoundaryA[0] = pAd->TssiRefA;
// Disable TxAgc if the based value is not right
if (pAd->TssiRefA == 0xff)
pAd->bAutoTxAgcA = FALSE;
DBGPRINT(RT_DEBUG_TRACE,"E2PROM: A Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
pAd->TssiMinusBoundaryA[4], pAd->TssiMinusBoundaryA[3], pAd->TssiMinusBoundaryA[2], pAd->TssiMinusBoundaryA[1],
pAd->TssiRefA,
pAd->TssiPlusBoundaryA[1], pAd->TssiPlusBoundaryA[2], pAd->TssiPlusBoundaryA[3], pAd->TssiPlusBoundaryA[4],
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -