📄 rtmp_init.c
字号:
/*************************************************************************** * RT2x00 SourceForge Project - http://rt2x00.serialmonkey.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * * Licensed under the GNU GPL * * Original code supplied under license from RaLink Inc, 2004. * ***************************************************************************//*************************************************************************** * Module Name: rtmp_init.c * * Abstract: Miniport generic portion header file * * Revision History: * Who When What * -------- ---------- ----------------------------- * Paul Lin 2002-08-01 created * John Chang 2004-08-20 RT2561/2661 use scatter-gather scheme * Olivier Cornu 2007-05-14 Remove .dat file code ***************************************************************************/#include "rt_config.h"#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)#define RT_USB_ALLOC_URB(iso) usb_alloc_urb(iso, GFP_KERNEL);#else#define RT_USB_ALLOC_URB(iso) usb_alloc_urb(iso);#endifUCHAR BIT8[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};ULONG BIT32[] = {0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020, 0x00000040, 0x00000080, 0x00000100, 0x00000200, 0x00000400, 0x00000800, 0x00001000, 0x00002000, 0x00004000, 0x00008000, 0x00010000, 0x00020000, 0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000, 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000};char* CipherName[] = {"none","wep64","wep128","TKIP","AES","CKIP64","CKIP128"};const unsigned short ccitt_16Table[] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0};#define ByteCRC16(v, crc) \ (unsigned short)((crc << 8) ^ ccitt_16Table[((crc >> 8) ^ (v)) & 255])//// BBP register initialization set//BBP_REG_PAIR BBPRegTable[] = { {3, 0x80}, {15, 0x30}, {17, 0x20}, {21, 0xc8}, {22, 0x38}, {23, 0x06}, {24, 0xfe}, {25, 0x0a}, {26, 0x0d}, {32, 0x0b}, {34, 0x12}, {37, 0x07}, {39, 0xf8}, // 2005-09-02 by Gary, Atheros 11b issue {41, 0x60}, // 03-09 gary {53, 0x10}, // 03-09 gary {54, 0x18}, // 03-09 gary {60, 0x10}, {61, 0x04}, {62, 0x04}, {75, 0xfe}, {86, 0xfe}, {88, 0xfe}, {90, 0x0f}, {99, 0x00}, {102, 0x16}, {107, 0x04},};#define NUM_BBP_REG_PARMS (sizeof(BBPRegTable) / sizeof(BBP_REG_PAIR))//// ASIC register initialization sets//RTMP_REG_PAIR MACRegTable[] = { {TXRX_CSR0, 0x025fb032}, // 0x3040, RX control, default Disable RX {TXRX_CSR1, 0x9eaa9eaf}, // 0x3044, BBP 30:Ant-A RSSI, R51:Ant-B RSSI, R42:OFDM rate, R47:CCK SIGNAL {TXRX_CSR2, 0x8a8b8c8d}, // 0x3048, CCK TXD BBP registers {TXRX_CSR3, 0x00858687}, // 0x304c, OFDM TXD BBP registers {TXRX_CSR7, 0x2E31353B}, // 0x305c, ACK/CTS payload consume time for 18/12/9/6 mbps {TXRX_CSR8, 0x2a2a2a2c}, // 0x3060, ACK/CTS payload consume time for 54/48/36/24 mbps {TXRX_CSR15, 0x0000000f}, // 0x307c, TKIP MIC priority byte "AND" mask {MAC_CSR6, 0x00000fff}, // 0x3018, MAX frame length {MAC_CSR8, 0x016c030a}, // 0x3020, SIFS/EIFS time, set SIFS delay time. {MAC_CSR10, 0x00000718}, // 0x3028, ASIC PIN control in various power states {MAC_CSR12, 0x00000004}, // 0x3030, power state control, set to AWAKE state {MAC_CSR13, 0x00007f00}, // 0x3034, GPIO pin#7 as bHwRadio (input:0), otherwise (output:1) {SEC_CSR0, 0x00000000}, // 0x30a0, invalidate all shared key entries {SEC_CSR1, 0x00000000}, // 0x30a4, reset all shared key algorithm to "none" {SEC_CSR5, 0x00000000}, // 0x30b4, reset all shared key algorithm to "none" {PHY_CSR1, 0x000023b0}, // 0x3084, BBP Register R/W mode set to "Parallel mode" {PHY_CSR5, 0x00040a06}, // 0x060a100c {PHY_CSR6, 0x00080606}, {PHY_CSR7, 0x00000408}, {AIFSN_CSR, 0x00002273}, {CWMIN_CSR, 0x00002344}, {CWMAX_CSR, 0x000034aa},};#define NUM_MAC_REG_PARMS (sizeof(MACRegTable) / sizeof(RTMP_REG_PAIR))VOID CreateThreads(PRTMP_ADAPTER pAd){ // Creat MLME Thread pAd->MLMEThr_pid = kernel_thread(MlmeThread, pAd, CLONE_VM); if (pAd->MLMEThr_pid < 0) { DBGPRINT(RT_DEBUG_ERROR, "%s: unable to start mlme thread for %s\n", __FUNCTION__, pAd->net_dev->name); KPRINT(KERN_WARNING, "%s: unable to start mlme thread\n", pAd->net_dev->name); } // Creat Command Thread pAd->RTUSBCmdThr_pid = kernel_thread(RTUSBCmdThread, pAd, CLONE_VM); if (pAd->RTUSBCmdThr_pid < 0) { DBGPRINT(RT_DEBUG_ERROR, "%s: unable to start Cmd thread for %s\n", __FUNCTION__, pAd->net_dev->name); KPRINT(KERN_WARNING, "%s: unable to start Cmd thread\n", pAd->net_dev->name); } DBGPRINT(RT_DEBUG_INFO, "- (%s) Mlme pid=%d, Cmd pid=%d\n", __FUNCTION__, pAd->MLMEThr_pid, pAd->RTUSBCmdThr_pid);}void KillThreads(PRTMP_ADAPTER pAd){ int ret; if (pAd->MLMEThr_pid > 0) { ret = kill_proc (pAd->MLMEThr_pid, SIGTERM, 1); if (ret) { DBGPRINT(RT_DEBUG_ERROR, "%s(%s): unable to signal mlme thread" " (pid=%d, err=%d)\n", __FUNCTION__, pAd->net_dev->name, pAd->MLMEThr_pid, ret); KPRINT(KERN_ERR, "(%s) unable to signal mlme thread" " (pid=%d, err=%d)\n", pAd->net_dev->name, pAd->MLMEThr_pid, ret); //return ret; Fix process killing } else wait_for_completion (&pAd->mlmenotify); } if (pAd->RTUSBCmdThr_pid> 0) { ret = kill_proc (pAd->RTUSBCmdThr_pid, SIGTERM, 1); if (ret) { DBGPRINT(RT_DEBUG_ERROR, "%s(%s): unable to signal cmd thread" " (pid=%d, err=%d)\n", __FUNCTION__, pAd->net_dev->name, pAd->MLMEThr_pid, ret); KPRINT(KERN_ERR, "(%s) unable to signal cmd thread" " (pid=%d, err=%d)\n", pAd->net_dev->name, pAd->RTUSBCmdThr_pid, ret); //return ret; Fix process killing } else wait_for_completion (&pAd->cmdnotify); } // reset mlme & command thread pAd->MLMEThr_pid = -1; pAd->RTUSBCmdThr_pid = -1;} /* End KillThreads () */NDIS_STATUS NICInitTransmit( IN PRTMP_ADAPTER pAd ){ UCHAR i, acidx; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; PTX_CONTEXT pPsPollContext = &(pAd->PsPollContext); PTX_CONTEXT pNullContext = &(pAd->NullContext); PTX_CONTEXT pRTSContext = &(pAd->RTSContext); DBGPRINT(RT_DEBUG_TRACE,"--> NICInitTransmit\n"); // Init 4 set of Tx parameters for (i = 0; i < 4; i++) { // Initialize all Transmit releated queues skb_queue_head_init(&pAd->SendTxWaitQueue[i]); pAd->NextTxIndex[i] = 0; // Next Free local Tx ring pointer pAd->TxRingTotalNumber[i] = 0; pAd->NextBulkOutIndex[i] = 0; // Next Local tx ring pointer waiting for buck out pAd->BulkOutPending[i] = FALSE; // Buck Out control flag } pAd->PrivateInfo.TxRingFullCnt = 0; pAd->NextMLMEIndex = 0; pAd->PushMgmtIndex = 0; pAd->PopMgmtIndex = 0; atomic_set(&pAd->MgmtQueueSize, 0); pAd->PrioRingFirstIndex = 0; pAd->PrioRingTxCnt = 0; do { // // TX_RING_SIZE // for (acidx = 0; acidx < 4; acidx++) { for ( i= 0; i < TX_RING_SIZE; i++ ) { PTX_CONTEXT pTxContext = &(pAd->TxContext[acidx][i]); //Allocate URB pTxContext->pUrb = RT_USB_ALLOC_URB(0); if(pTxContext->pUrb == NULL){ Status = NDIS_STATUS_RESOURCES; goto done; } pTxContext->TransferBuffer= (PTX_BUFFER) kmalloc(sizeof(TX_BUFFER), GFP_KERNEL); Status = NDIS_STATUS_SUCCESS; if(!pTxContext->TransferBuffer){ DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n"); Status = NDIS_STATUS_RESOURCES; goto out1; } memset(pTxContext->TransferBuffer, 0, sizeof(TX_BUFFER)); pTxContext->pAd = pAd; pTxContext->InUse = FALSE; pTxContext->IRPPending = FALSE; } } // // PRIO_RING_SIZE // for ( i= 0; i < PRIO_RING_SIZE; i++ ) { PTX_CONTEXT pMLMEContext = &(pAd->MLMEContext[i]); pMLMEContext->pUrb = RT_USB_ALLOC_URB(0); if(pMLMEContext->pUrb == NULL){ Status = NDIS_STATUS_RESOURCES; goto out1; } pMLMEContext->TransferBuffer= (PTX_BUFFER) kmalloc(sizeof(TX_BUFFER), GFP_KERNEL); if(!pMLMEContext->TransferBuffer){ DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n"); Status = NDIS_STATUS_RESOURCES; goto out2; } memset(pMLMEContext->TransferBuffer, 0, sizeof(TX_BUFFER)); pMLMEContext->pAd = pAd ; pMLMEContext->InUse = FALSE; pMLMEContext->IRPPending = FALSE; } // // BEACON_RING_SIZE // for (i = 0; i < BEACON_RING_SIZE; i++) { PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]); pBeaconContext->pUrb = RT_USB_ALLOC_URB(0); if(pBeaconContext->pUrb == NULL){ Status = NDIS_STATUS_RESOURCES; goto out2; } pBeaconContext->TransferBuffer= (PTX_BUFFER) kmalloc(sizeof(TX_BUFFER), GFP_KERNEL); if(!pBeaconContext->TransferBuffer){ DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n"); Status = NDIS_STATUS_RESOURCES; goto out3; } memset(pBeaconContext->TransferBuffer, 0, sizeof(TX_BUFFER)); pBeaconContext->pAd = pAd; pBeaconContext->InUse = FALSE; pBeaconContext->IRPPending = FALSE; } // // NullContext // pNullContext->pUrb = RT_USB_ALLOC_URB(0); if(pNullContext->pUrb == NULL){ Status = NDIS_STATUS_RESOURCES; goto out3; } pNullContext->TransferBuffer= (PTX_BUFFER) kmalloc(sizeof(TX_BUFFER), GFP_KERNEL); if(!pNullContext->TransferBuffer){ DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n"); Status = NDIS_STATUS_RESOURCES; goto out4; } memset(pNullContext->TransferBuffer, 0, sizeof(TX_BUFFER)); pNullContext->pAd = pAd; pNullContext->InUse = FALSE; pNullContext->IRPPending = FALSE; // // RTSContext // pRTSContext->pUrb = RT_USB_ALLOC_URB(0); if(pRTSContext->pUrb == NULL){ Status = NDIS_STATUS_RESOURCES; goto out4; } pRTSContext->TransferBuffer= (PTX_BUFFER) kmalloc(sizeof(TX_BUFFER), GFP_KERNEL); if(!pRTSContext->TransferBuffer){ DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n"); Status = NDIS_STATUS_RESOURCES; goto out5; } memset(pRTSContext->TransferBuffer, 0, sizeof(TX_BUFFER)); pRTSContext->pAd = pAd; pRTSContext->InUse = FALSE; pRTSContext->IRPPending = FALSE; // // PsPollContext // pPsPollContext->pUrb = RT_USB_ALLOC_URB(0); if(pPsPollContext->pUrb == NULL){ Status = NDIS_STATUS_RESOURCES; goto out5; } pPsPollContext->TransferBuffer= (PTX_BUFFER) kmalloc(sizeof(TX_BUFFER), GFP_KERNEL); if(!pPsPollContext->TransferBuffer){ DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n"); Status = NDIS_STATUS_RESOURCES; goto out6; } memset(pPsPollContext->TransferBuffer, 0, sizeof(TX_BUFFER)); pPsPollContext->pAd = pAd; pPsPollContext->InUse = FALSE; pPsPollContext->IRPPending = FALSE; } while (FALSE); return Status;out6: if (NULL != pPsPollContext->pUrb) { RTUSB_UNLINK_URB(pPsPollContext->pUrb); usb_free_urb(pPsPollContext->pUrb); pPsPollContext->pUrb = NULL; } if (NULL != pPsPollContext->TransferBuffer) { kfree(pPsPollContext->TransferBuffer); pPsPollContext->TransferBuffer = NULL; }out5: if (NULL != pRTSContext->pUrb) { RTUSB_UNLINK_URB(pRTSContext->pUrb); usb_free_urb(pRTSContext->pUrb); pRTSContext->pUrb = NULL; } if (NULL != pRTSContext->TransferBuffer) { kfree(pRTSContext->TransferBuffer); pRTSContext->TransferBuffer = NULL; }out4: if (NULL != pNullContext->pUrb) { RTUSB_UNLINK_URB(pNullContext->pUrb); usb_free_urb(pNullContext->pUrb); pNullContext->pUrb = NULL; } if (NULL != pNullContext->TransferBuffer) { kfree(pNullContext->TransferBuffer); pNullContext->TransferBuffer = NULL; }out3: for (i = 0; i < BEACON_RING_SIZE; i++) { PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]); if ( NULL != pBeaconContext->pUrb ) { RTUSB_UNLINK_URB(pBeaconContext->pUrb); usb_free_urb(pBeaconContext->pUrb); pBeaconContext->pUrb = NULL; } if ( NULL != pBeaconContext->TransferBuffer ) { kfree( pBeaconContext->TransferBuffer); pBeaconContext->TransferBuffer = NULL; } }out2: for ( i= 0; i < PRIO_RING_SIZE; i++ ) { PTX_CONTEXT pMLMEContext = &(pAd->MLMEContext[i]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -