📄 rtusb_init.c
字号:
Routine Description: Reset NIC from error Arguments: Adapter Pointer to our adapter Return Value: None IRQL = PASSIVE_LEVEL Note: Reset NIC from error state ========================================================================*/VOID NICResetFromError( IN PRT2570ADAPTER pAdapter){ RT2570InitializeAsic(pAdapter);#ifdef INIT_FROM_EEPROM NICInitAsicFromEEPROM(pAdapter);#endif RTUSBWriteHWMACAddress(pAdapter); // Switch to current channel, since during reset process, the connection should remains on. AsicSwitchChannel(pAdapter, pAdapter->PortCfg.Channel); AsicLockChannel(pAdapter, pAdapter->PortCfg.Channel);}VOID CreateThreads( struct net_device *net_dev ){ PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) net_dev->priv; // Creat MLME Thread#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) // Creat MLME Thread pAdapter->MLMEThr_pid= -1; pAdapter->MLMEThr_pid = kernel_thread(MlmeThread, pAdapter, CLONE_VM); if (pAdapter->MLMEThr_pid < 0) printk(KERN_WARNING "%s: unable to start mlme thread\n",pAdapter->net->name); // Creat Command Thread pAdapter->RTUSBCmdThr_pid= -1; pAdapter->RTUSBCmdThr_pid = kernel_thread(RTUSBCmdThread, pAdapter, CLONE_VM); if (pAdapter->RTUSBCmdThr_pid < 0) printk(KERN_WARNING "%s: unable to start RTUSBCmd thread\n",pAdapter->net->name);#else // Creat MLME Thread pAdapter->MLMEThr = kthread_run(MlmeThread, pAdapter, "rtusb-mlme"); if (IS_ERR(pAdapter->MLMEThr)) printk(KERN_WARNING "%s: unable to start mlme thread\n",pAdapter->net->name); // Creat Command Thread pAdapter->RTUSBCmdThr = kthread_run(RTUSBCmdThread, pAdapter, "rtusb-usbcmd"); if (IS_ERR(pAdapter->RTUSBCmdThr)) printk(KERN_WARNING "%s: unable to start RTUSBCmd thread\n",pAdapter->net->name);#endif}NDIS_STATUS RTMPAllocAdapterBlock( PRT2570ADAPTER *ppAdapter ){ NDIS_STATUS Status=NDIS_STATUS_SUCCESS;#if 0 PRT2570ADAPTER pAdapter; DBGPRINT(RT_DEBUG_TRACE,"--> RTMPAllocAdapterBlock\n"); *ppAdapter = NULL; do { pAdapter = (PRT2570ADAPTER) kmalloc(sizeof(RT2570ADAPTER), GFP_KERNEL); if (!pAdapter) { DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n"); Status = NDIS_STATUS_RESOURCES; break; } memset((PUCHAR) pAdapter, 0, sizeof(RT2570ADAPTER)); } while (FALSE); *ppAdapter = pAdapter; DBGPRINT(RT_DEBUG_ERROR,"<-- RTMPAllocAdapterBlock, Status=%x\n", Status);#endif return Status;}NDIS_STATUS NICInitTransmit( PRT2570ADAPTER pAdapter ){ UCHAR i; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; PTX_CONTEXT pPsPollContext = &(pAdapter->PsPollContext); PTX_CONTEXT pNullContext = &(pAdapter->NullContext); DBGPRINT(RT_DEBUG_TRACE,"--> NICInitTransmit\n"); // Initialize all Transmit releated queues skb_queue_head_init(&pAdapter->SendTxWaitQueue); // Init Ring index pointer pAdapter->NextRxBulkInIndex = 0; pAdapter->NextTxIndex = 0; pAdapter->NextBulkOutIndex = 0; // Next Local tx ring pointer waiting for buck out pAdapter->NextMLMEIndex = 0; pAdapter->PushMgmtIndex = 0; pAdapter->PopMgmtIndex = 0; atomic_set(&pAdapter->MgmtQueueSize,0); pAdapter->BulkOutPending = FALSE; pAdapter->PrioRingFirstIndex = 0; pAdapter->PrioRingTxCnt = 0; do { for ( i= 0; i < TX_RING_SIZE; i++ ) { PTX_CONTEXT pTxContext = &(pAdapter->TxContext[i]); //Allocate URB pTxContext->pUrb = RT2570_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->pAdapter = pAdapter; pTxContext->InUse = FALSE; pTxContext->IRPPending = FALSE; } for ( i= 0; i < PRIO_RING_SIZE; i++ ) { PTX_CONTEXT pMLMEContext = &(pAdapter->MLMEContext[i]); pMLMEContext->pUrb = RT2570_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->pAdapter = pAdapter; pMLMEContext->InUse = FALSE; pMLMEContext->IRPPending = FALSE; } for (i = 0; i < BEACON_RING_SIZE; i++) { PTX_CONTEXT pBeaconContext = &(pAdapter->BeaconContext[i]); pBeaconContext->pUrb = RT2570_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->pAdapter = pAdapter; pBeaconContext->InUse = FALSE; pBeaconContext->IRPPending = FALSE; } pNullContext->pUrb = RT2570_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->pAdapter = pAdapter; pNullContext->InUse = FALSE; pNullContext->IRPPending = FALSE; pPsPollContext->pUrb = RT2570_USB_ALLOC_URB(0); if(pPsPollContext->pUrb == NULL){ Status = NDIS_STATUS_RESOURCES; goto out4; } 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 out5; } memset(pPsPollContext->TransferBuffer, 0, sizeof(TX_BUFFER)); pPsPollContext->pAdapter = pAdapter; pPsPollContext->InUse = FALSE; pPsPollContext->IRPPending = FALSE;#if 0 //Allocate URB pWpaPskContext->pUrb = RT2570_USB_ALLOC_URB(0); if(pWpaPskContext->pUrb == NULL){ Status = NDIS_STATUS_RESOURCES; goto done; } pWpaPskContext->TransferBuffer= (PWPAPSK_BUFFER) kmalloc(sizeof(WPAPSK_BUFFER), GFP_KERNEL); Status = NDIS_STATUS_SUCCESS; if(!pWpaPskContext->TransferBuffer){ DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n"); Status = NDIS_STATUS_RESOURCES; goto done; } memset(pWpaPskContext->TransferBuffer, 0, sizeof(WPAPSK_BUFFER)); pWpaPskContext->pAdapter = pAdapter; pWpaPskContext->InUse = FALSE; pWpaPskContext->IRPPending = FALSE;#endif#ifdef TEST_MODE_SUPPORT Status = RT2570AllocateMemory(&(pAdapter->pTxUrb), sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER)); if ((Status != NDIS_STATUS_SUCCESS) || (pAdapter->pTxUrb == NULL)) { Status = NDIS_STATUS_RESOURCES; goto done; } Status = RT2570AllocateMemory(&(pAdapter->TxBuffer), BUFFER_SIZE); if ((Status != NDIS_STATUS_SUCCESS) || (pAdapter->TxBuffer == NULL)) { Status = NDIS_STATUS_RESOURCES; goto done; } memset(pAdapter->TxBuffer, 0, BUFFER_SIZE); stackSize = pAdapter->pNextDeviceObject->StackSize + 1; pAdapter->pTxIrp = IoAllocateIrp(stackSize, FALSE);#endif } while (FALSE); return Status;out5: if (NULL != pPsPollContext->pUrb) { usb_kill_urb(pPsPollContext->pUrb); usb_free_urb(pPsPollContext->pUrb); pPsPollContext->pUrb = NULL; } if (NULL != pPsPollContext->TransferBuffer) { FreeMemory(pPsPollContext->TransferBuffer); pPsPollContext->TransferBuffer = NULL; }out4: if (NULL != pNullContext->pUrb) { usb_kill_urb(pNullContext->pUrb); usb_free_urb(pNullContext->pUrb); pNullContext->pUrb = NULL; } if (NULL != pNullContext->TransferBuffer) { FreeMemory(pNullContext->TransferBuffer); pNullContext->TransferBuffer = NULL; }out3: // Free beacon frame resource for (i = 0; i < BEACON_RING_SIZE; i++) { PTX_CONTEXT pBeaconContext = &(pAdapter->BeaconContext[i]); if ( NULL != pBeaconContext->pUrb ) { usb_kill_urb(pBeaconContext->pUrb); usb_free_urb(pBeaconContext->pUrb); pBeaconContext->pUrb = NULL; } if ( NULL != pBeaconContext->TransferBuffer ) { FreeMemory( pBeaconContext->TransferBuffer); pBeaconContext->TransferBuffer = NULL; } }out2: for ( i= 0; i < PRIO_RING_SIZE; i++ ) { PTX_CONTEXT pMLMEContext = &(pAdapter->MLMEContext[i]); if ( NULL != pMLMEContext->pUrb ) { usb_kill_urb(pMLMEContext->pUrb); usb_free_urb(pMLMEContext->pUrb); pMLMEContext->pUrb = NULL; } if ( NULL != pMLMEContext->TransferBuffer ) { FreeMemory( pMLMEContext->TransferBuffer); pMLMEContext->TransferBuffer = NULL; } } // forout1: for ( i= 0; i < TX_RING_SIZE; i++ ) { PTX_CONTEXT pTxContext = &(pAdapter->TxContext[i]); if ( NULL != pTxContext->pUrb ) { usb_kill_urb(pTxContext->pUrb); usb_free_urb(pTxContext->pUrb); pTxContext->pUrb = NULL; } if ( NULL != pTxContext->TransferBuffer ) { FreeMemory( pTxContext->TransferBuffer); pTxContext->TransferBuffer = NULL; } } // fordone: DBGPRINT(RT_DEBUG_TRACE,"<-- NICInitTransmit\n"); 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( PRT2570ADAPTER pAdapter){ UCHAR i; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; DBGPRINT(RT_DEBUG_TRACE,"--> NICInitRecv\n"); pAdapter->NextRxBulkInIndex = 0; atomic_set( &pAdapter->PendingRx, 0); for (i = 0; i < RX_RING_SIZE; i++) { PRX_CONTEXT pRxContext = &(pAdapter->RxContext[i]); pRxContext->pUrb = RT2570_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, GFP_KERNEL); if(!pRxContext->TransferBuffer) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -