/* ======================================================================== Routine Description: Process TX Rings DMA Done interrupt, running in DPC level Arguments: Adapter Pointer to our adapter Return Value: None IRQL = DISPATCH_LEVEL ======================================================================== */ BOOLEAN RTMPHandleTxRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd, INT_SOURCE_CSR_STRUC TxRingBitmap) { /* u8 Count = 0; */ unsigned long IrqFlags; BOOLEAN bReschedule = FALSE; /* Make sure Tx ring resource won't be used by other threads */ /*NdisAcquireSpinLock(&pAd->TxRingLock); */ RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); if (TxRingBitmap.field.Ac0DmaDone) bReschedule = RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_BE); if (TxRingBitmap.field.Ac3DmaDone) bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_VO); if (TxRingBitmap.field.Ac2DmaDone) bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_VI); if (TxRingBitmap.field.Ac1DmaDone) bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_BK); /* Make sure to release Tx ring resource */ /*NdisReleaseSpinLock(&pAd->TxRingLock); */ RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); /* Dequeue outgoing frames from TxSwQueue[] and process it */ RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); return bReschedule; }
BOOLEAN RTMPHandleTxRingDmaDoneInterrupt( IN PRTMP_ADAPTER pAd, IN INT_SOURCE_CSR_STRUC TxRingBitmap) { unsigned long IrqFlags; BOOLEAN bReschedule = FALSE; RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); if (TxRingBitmap.field.Ac0DmaDone) bReschedule = RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_BE); if (TxRingBitmap.field.Ac3DmaDone) bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_VO); if (TxRingBitmap.field.Ac2DmaDone) bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_VI); if (TxRingBitmap.field.Ac1DmaDone) bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_BK); RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); return bReschedule; }
static void rtusb_null_frame_done_tasklet(unsigned long data) { PRTMP_ADAPTER pAd; PTX_CONTEXT pNullContext; purbb_t pUrb; NTSTATUS Status; unsigned long irqFlag; pUrb = (purbb_t)data; /* pNullContext = (PTX_CONTEXT)pUrb->context; */ pNullContext = (PTX_CONTEXT)RTMP_USB_URB_DATA_GET(pUrb); Status = RTMP_USB_URB_STATUS_GET(pUrb); pAd = pNullContext->pAd; /* Status = pUrb->status; */ /* Reset Null frame context flags */ RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], irqFlag); pNullContext->IRPPending = FALSE; pNullContext->InUse = FALSE; pAd->BulkOutPending[0] = FALSE; pAd->watchDogTxPendingCnt[0] = 0; if (Status == USB_ST_NOERROR) { RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); } else /* STATUS_OTHER */ { if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out Null Frame Failed, ReasonCode=%d!\n", Status)); RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG); RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); RTEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0); } else { RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); } } /* Always call Bulk routine, even reset bulk. */ /* The protectioon of rest bulk should be in BulkOut routine */ RTUSBKickBulkOut(pAd); }
static void rt2870_rts_frame_complete_tasklet(unsigned long data) { PRTMP_ADAPTER pAd; PTX_CONTEXT pRTSContext; purbb_t pUrb; NTSTATUS Status; unsigned long irqFlag; pUrb = (purbb_t)data; pRTSContext = (PTX_CONTEXT)pUrb->context; pAd = pRTSContext->pAd; Status = pUrb->status; // Reset RTS frame context flags RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], irqFlag); pRTSContext->IRPPending = FALSE; pRTSContext->InUse = FALSE; if (Status == USB_ST_NOERROR) { RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); } else // STATUS_OTHER { if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { DBGPRINT_RAW(RT_DEBUG_ERROR, ("Bulk Out RTS Frame Failed\n")); RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); pAd->bulkResetPipeid = (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG); RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0); } else { RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); } } RTMP_SEM_LOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]); pAd->BulkOutPending[pRTSContext->BulkOutPipeId] = FALSE; RTMP_SEM_UNLOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]); // Always call Bulk routine, even reset bulk. // The protectioon of rest bulk should be in BulkOut routine RTUSBKickBulkOut(pAd); }
// RTS frame use BulkOutPipeId = PipeID VOID RTUSBBulkOutRTSFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs) { PRTMP_ADAPTER pAd; PTX_CONTEXT pRTSContext; NTSTATUS status; unsigned long IrqFlags; pRTSContext= (PTX_CONTEXT)pUrb->context; pAd = pRTSContext->pAd; DBGPRINT_RAW(RT_DEBUG_INFO, "--->RTUSBBulkOutRTSFrameComplete\n"); // Reset RTS frame context flags pRTSContext->IRPPending = FALSE; pRTSContext->InUse = FALSE; status = pUrb->status; if (status == USB_ST_NOERROR) { // Don't worry about the queue is empty or not, this function will check itself RTMPDeQueuePacket(pAd, pRTSContext->BulkOutPipeId); } #if 1 // STATUS_OTHER else { if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { DBGPRINT_RAW(RT_DEBUG_ERROR, "Bulk Out RTS Frame Failed\n"); RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); RTUSBEnqueueInternalCmd(pAd, RT_OID_USB_RESET_BULK_OUT); } } #endif NdisAcquireSpinLock(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId], IrqFlags); pAd->BulkOutPending[pRTSContext->BulkOutPipeId] = FALSE; NdisReleaseSpinLock(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId], IrqFlags); // Always call Bulk routine, even reset bulk. // The protectioon of rest bulk should be in BulkOut routine RTUSBKickBulkOut(pAd); DBGPRINT_RAW(RT_DEBUG_INFO, "<---RTUSBBulkOutRTSFrameComplete\n"); }
static void rtusb_hcca_dma_done_tasklet(unsigned long data) { PRTMP_ADAPTER pAd; PHT_TX_CONTEXT pHTTXContext; UCHAR BulkOutPipeId = 4; purbb_t pUrb; DBGPRINT_RAW(RT_DEBUG_ERROR, ("--->hcca_dma_done_tasklet\n")); pUrb = (purbb_t)data; /* pHTTXContext = (PHT_TX_CONTEXT)pUrb->context; */ pHTTXContext = (PHT_TX_CONTEXT)RTMP_USB_URB_DATA_GET(pUrb); pAd = pHTTXContext->pAd; rtusb_dataout_complete((unsigned long)pUrb); if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)))) { /* do nothing and return directly. */ } else { if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) { RTEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0); } else { pHTTXContext = &pAd->TxContext[BulkOutPipeId]; if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) && /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */ (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) && (pHTTXContext->bCurWriting == FALSE)) { RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS); } RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL); RTUSBKickBulkOut(pAd); } } DBGPRINT_RAW(RT_DEBUG_ERROR, ("<---hcca_dma_done_tasklet\n")); return; }
static void rt2870_ac1_dma_done_tasklet(unsigned long data) { PRTMP_ADAPTER pAd; PHT_TX_CONTEXT pHTTXContext; UCHAR BulkOutPipeId = 1; purbb_t pUrb; pUrb = (purbb_t)data; pHTTXContext = (PHT_TX_CONTEXT)pUrb->context; pAd = pHTTXContext->pAd; rt2870_dataout_complete_tasklet((unsigned long)pUrb); if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)))) { // do nothing and return directly. } else { if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) { RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, NULL, 0); } else { pHTTXContext = &pAd->TxContext[BulkOutPipeId]; if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) && /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */ (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) && (pHTTXContext->bCurWriting == FALSE)) { RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, MAX_TX_PROCESS); } RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL<<1); RTUSBKickBulkOut(pAd); } } return; }
VOID RTMPQueueAckPeriodicExec( IN PVOID SystemSpecific1, IN PVOID FunctionContext, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3) { MAC_TABLE_ENTRY *pEntry = (MAC_TABLE_ENTRY *)FunctionContext; PNDIS_PACKET pPacket; UINT cnt= 0; if (pEntry) { PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pEntry->pAd; cnt = flush_tcp_ack_queue(pAd, pEntry, FALSE); pAd->CommonCfg.AckTimeout += cnt; if (cnt <= TCP_ACK_BURST_LEVEL) pAd->CommonCfg.TcpAck[cnt]++; else printk("TcpAck: cnt not range=%d\n", cnt); RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); } }
/* ======================================================================== Routine Description: Process TX Rings DMA Done interrupt, running in DPC level Arguments: Adapter Pointer to our adapter Return Value: None IRQL = DISPATCH_LEVEL ======================================================================== */ BOOLEAN RTMPHandleTxRingDmaDoneInterrupt( IN PRTMP_ADAPTER pAd, IN INT_SOURCE_CSR_STRUC TxRingBitmap) { // UCHAR Count = 0; unsigned long IrqFlags; BOOLEAN bReschedule = FALSE; // Make sure Tx ring resource won't be used by other threads //NdisAcquireSpinLock(&pAd->TxRingLock); RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); if (TxRingBitmap.field.Ac0DmaDone) bReschedule = RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_BE); if (TxRingBitmap.field.HccaDmaDone) bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_HCCA); if (TxRingBitmap.field.Ac3DmaDone) bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_VO); if (TxRingBitmap.field.Ac2DmaDone) bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_VI); if (TxRingBitmap.field.Ac1DmaDone) bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_BK); // Make sure to release Tx ring resource //NdisReleaseSpinLock(&pAd->TxRingLock); RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); // Dequeue outgoing frames from TxSwQueue[] and process it RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); return bReschedule; }
// ************************ Completion Func ************************ // VOID RTUSBBulkOutDataPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs) { PTX_CONTEXT pTxContext; PRTMP_ADAPTER pAd; NTSTATUS status; UCHAR BulkOutPipeId; unsigned long IrqFlags; DBGPRINT_RAW(RT_DEBUG_INFO, "--->RTUSBBulkOutDataPacketComplete\n"); pTxContext= (PTX_CONTEXT)pUrb->context; pAd = pTxContext->pAd; status = pUrb->status; // Store BulkOut PipeId BulkOutPipeId = pTxContext->BulkOutPipeId; pAd->BulkOutDataOneSecCount++; if (status == USB_ST_NOERROR) { DBGPRINT_RAW(RT_DEBUG_INFO, "BulkOutDataPacketComplete %d (STATUS_SUCCESS)\n", BulkOutPipeId); if (pTxContext->LastOne == TRUE) { pAd->Counters.GoodTransmits++; FREE_TX_RING(pAd, BulkOutPipeId, pTxContext); pAd->TxRingTotalNumber[BulkOutPipeId]--; // sync. to TxCount if (pAd->SendTxWaitQueue[BulkOutPipeId].Number > 0) { RTMPDeQueuePacket(pAd, BulkOutPipeId); } } else { if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { FREE_TX_RING(pAd, BulkOutPipeId, pTxContext); pAd->TxRingTotalNumber[BulkOutPipeId]--; // sync. to TxCount // Indicate next one is frag data which has highest priority RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId)); } else { while (pTxContext->LastOne != TRUE) { FREE_TX_RING(pAd, BulkOutPipeId, pTxContext); pAd->TxRingTotalNumber[BulkOutPipeId]--; // sync. to TxCount pTxContext = &(pAd->TxContext[BulkOutPipeId][pAd->NextBulkOutIndex[BulkOutPipeId]]); } FREE_TX_RING(pAd, BulkOutPipeId, pTxContext); pAd->TxRingTotalNumber[BulkOutPipeId]--; // sync. to TxCount } } } #if 1 // STATUS_OTHER else { DBGPRINT_RAW(RT_DEBUG_ERROR, "BulkOutDataPacketComplete %d (STATUS_OTHER)\n", BulkOutPipeId); while (pTxContext->LastOne != TRUE) { FREE_TX_RING(pAd, BulkOutPipeId, pTxContext); pAd->TxRingTotalNumber[BulkOutPipeId]--; // sync. to TxCount pTxContext = &(pAd->TxContext[BulkOutPipeId][pAd->NextBulkOutIndex[BulkOutPipeId]]); } FREE_TX_RING(pAd, BulkOutPipeId, pTxContext); pAd->TxRingTotalNumber[BulkOutPipeId]--; // sync. to TxCount if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); RTUSBEnqueueInternalCmd(pAd, RT_OID_USB_RESET_BULK_OUT); } } #endif pTxContext = &(pAd->TxContext[BulkOutPipeId][pAd->NextBulkOutIndex[BulkOutPipeId]]); // // bInUse = TRUE, means some process are filling TX data, after that must turn on bWaitingBulkOut // bWaitingBulkOut = TRUE, means the TX data are waiting for bulk out. // if ((pTxContext->bWaitingBulkOut == TRUE) && !RTUSB_TEST_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId))) { // Indicate There is data avaliable RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId)); } NdisAcquireSpinLock(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); pAd->BulkOutPending[BulkOutPipeId] = FALSE; NdisReleaseSpinLock(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); // Always call Bulk routine, even reset bulk. // The protectioon of rest bulk should be in BulkOut routine RTUSBKickBulkOut(pAd); }
VOID ATE_RTUSBBulkOutDataPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs) { PRTMP_ADAPTER pAd; PTX_CONTEXT pNullContext; NTSTATUS status; unsigned long IrqFlags; ULONG OldValue; pNullContext= (PTX_CONTEXT)pUrb->context; pAd = pNullContext->pAd; DBGPRINT_RAW(RT_DEBUG_INFO, "--->ATE_RTUSBBulkOutDataPacketComplete\n"); // Reset Null frame context flags pNullContext->IRPPending = FALSE; pNullContext->InUse = FALSE; status = pUrb->status; if (status == USB_ST_NOERROR) { // Don't worry about the queue is empty or not, this function will check itself RTMPDeQueuePacket(pAd, 0); } #if 1 // STATUS_OTHER else { if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { DBGPRINT_RAW(RT_DEBUG_ERROR, "Bulk Out Null Frame Failed\n"); RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); RTUSBEnqueueInternalCmd(pAd, RT_OID_USB_RESET_BULK_OUT); } } #endif if (atomic_read(&pAd->BulkOutRemained) > 0) { atomic_dec(&pAd->BulkOutRemained); DBGPRINT(RT_DEBUG_INFO, "Bulk Out Remained = %d\n", atomic_read(&pAd->BulkOutRemained)); } // 1st - Transmit Success OldValue = pAd->WlanCounters.TransmittedFragmentCount.vv.LowPart; pAd->WlanCounters.TransmittedFragmentCount.vv.LowPart++; if (pAd->WlanCounters.TransmittedFragmentCount.vv.LowPart < OldValue) { pAd->WlanCounters.TransmittedFragmentCount.vv.HighPart++; } if(((pAd->ContinBulkOut == TRUE ) ||(atomic_read(&pAd->BulkOutRemained) > 0)) && (pAd->ate.Mode != ATE_STASTART)) { DBGPRINT(RT_DEBUG_INFO, "ContinBulkOut = TRUE \n"); RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE); } else { RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_ATE); } NdisAcquireSpinLock(&pAd->BulkOutLock[0], IrqFlags); pAd->BulkOutPending[0] = FALSE; NdisReleaseSpinLock(&pAd->BulkOutLock[0], IrqFlags); // Always call Bulk routine, even reset bulk. // The protectioon of rest bulk should be in BulkOut routine RTUSBKickBulkOut(pAd); DBGPRINT_RAW(RT_DEBUG_INFO, "<---ATE_RTUSBBulkOutDataPacketComplete\n"); }
VOID CMDHandler( IN PRTMP_ADAPTER pAd) { PCmdQElmt cmdqelmt; PUCHAR pData; NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS; // ULONG Now = 0; NTSTATUS ntStatus; // unsigned long IrqFlags; while (pAd->CmdQ.size > 0) { NdisStatus = NDIS_STATUS_SUCCESS; NdisAcquireSpinLock(&pAd->CmdQLock); RTUSBDequeueCmd(&pAd->CmdQ, &cmdqelmt); NdisReleaseSpinLock(&pAd->CmdQLock); if (cmdqelmt == NULL) break; pData = cmdqelmt->buffer; if(!(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { switch (cmdqelmt->command) { case CMDTHREAD_CHECK_GPIO: { UINT32 data; { // Read GPIO pin2 as Hardware controlled radio state RTUSBReadMACRegister( pAd, GPIO_CTRL_CFG, &data); if (data & 0x04) { pAd->StaCfg.bHwRadio = TRUE; } else { pAd->StaCfg.bHwRadio = FALSE; } if(pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio)) { pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio); if(pAd->StaCfg.bRadio == TRUE) { DBGPRINT_RAW(RT_DEBUG_ERROR, ("!!! Radio On !!!\n")); MlmeRadioOn(pAd); // Update extra information pAd->ExtraInfo = EXTRA_INFO_CLEAR; } else { DBGPRINT_RAW(RT_DEBUG_ERROR, ("!!! Radio Off !!!\n")); MlmeRadioOff(pAd); // Update extra information pAd->ExtraInfo = HW_RADIO_OFF; } } } } break; case CMDTHREAD_QKERIODIC_EXECUT: { StaQuickResponeForRateUpExec(NULL, pAd, NULL, NULL); } break; case CMDTHREAD_RESET_BULK_OUT: { UINT32 MACValue; UCHAR Index; int ret=0; PHT_TX_CONTEXT pHTTXContext; // RTMP_TX_RING *pTxRing; unsigned long IrqFlags; DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_OUT(ResetPipeid=0x%0x)===>\n", pAd->bulkResetPipeid)); // All transfers must be aborted or cancelled before attempting to reset the pipe. //RTUSBCancelPendingBulkOutIRP(pAd); // Wait 10ms to let previous packet that are already in HW FIFO to clear. by MAXLEE 12-25-2007 Index = 0; do { RTUSBReadMACRegister(pAd, TXRXQ_PCNT, &MACValue); if ((MACValue & 0xf00000/*0x800000*/) == 0) break; Index++; RTMPusecDelay(10000); }while(Index < 100); MACValue = 0; RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue); // To prevent Read Register error, we 2nd check the validity. if ((MACValue & 0xc00000) == 0) RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue); // To prevent Read Register error, we 3rd check the validity. if ((MACValue & 0xc00000) == 0) RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue); MACValue |= 0x80000; RTUSBWriteMACRegister(pAd, USB_DMA_CFG, MACValue); // Wait 1ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007 RTMPusecDelay(1000); MACValue &= (~0x80000); RTUSBWriteMACRegister(pAd, USB_DMA_CFG, MACValue); DBGPRINT_RAW(RT_DEBUG_TRACE, ("\tSet 0x2a0 bit19. Clear USB DMA TX path\n")); // Wait 5ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007 //RTMPusecDelay(5000); if ((pAd->bulkResetPipeid & BULKOUT_MGMT_RESET_FLAG) == BULKOUT_MGMT_RESET_FLAG) { RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); if (pAd->MgmtRing.TxSwFreeIdx < MGMT_RING_SIZE /* pMLMEContext->bWaitingBulkOut == TRUE */) { RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME); } RTUSBKickBulkOut(pAd); DBGPRINT_RAW(RT_DEBUG_TRACE, ("\tTX MGMT RECOVER Done!\n")); } else { pHTTXContext = &(pAd->TxContext[pAd->bulkResetPipeid]); //NdisAcquireSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); RTMP_INT_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); if ( pAd->BulkOutPending[pAd->bulkResetPipeid] == FALSE) { pAd->BulkOutPending[pAd->bulkResetPipeid] = TRUE; pHTTXContext->IRPPending = TRUE; pAd->watchDogTxPendingCnt[pAd->bulkResetPipeid] = 1; // no matter what, clean the flag RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); //NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); /*-----------------------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------------------*/ { RTUSBInitHTTxDesc(pAd, pHTTXContext, pAd->bulkResetPipeid, pHTTXContext->BulkOutSize, (usb_complete_t)RTUSBBulkOutDataPacketComplete); if((ret = RTUSB_SUBMIT_URB(pHTTXContext->pUrb))!=0) { RTMP_INT_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); pAd->BulkOutPending[pAd->bulkResetPipeid] = FALSE; pHTTXContext->IRPPending = FALSE; pAd->watchDogTxPendingCnt[pAd->bulkResetPipeid] = 0; RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); DBGPRINT(RT_DEBUG_ERROR, ("CmdThread : CMDTHREAD_RESET_BULK_OUT: Submit Tx URB failed %d\n", ret)); } else { RTMP_IRQ_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); DBGPRINT_RAW(RT_DEBUG_TRACE,("\tCMDTHREAD_RESET_BULK_OUT: TxContext[%d]:CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, pending=%d!\n", pAd->bulkResetPipeid, pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad, pAd->BulkOutPending[pAd->bulkResetPipeid])); DBGPRINT_RAW(RT_DEBUG_TRACE,("\t\tBulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n", pAd->BulkOutReq, pAd->BulkOutComplete, pAd->BulkOutCompleteOther)); RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); DBGPRINT_RAW(RT_DEBUG_TRACE, ("\tCMDTHREAD_RESET_BULK_OUT: Submit Tx DATA URB for failed BulkReq(0x%lx) Done, status=%d!\n", pAd->bulkResetReq[pAd->bulkResetPipeid], pHTTXContext->pUrb->status)); } } } else { //NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); //RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); DBGPRINT_RAW(RT_DEBUG_ERROR, ("CmdThread : TX DATA RECOVER FAIL for BulkReq(0x%lx) because BulkOutPending[%d] is TRUE!\n", pAd->bulkResetReq[pAd->bulkResetPipeid], pAd->bulkResetPipeid)); if (pAd->bulkResetPipeid == 0) { UCHAR pendingContext = 0; PHT_TX_CONTEXT pHTTXContext = (PHT_TX_CONTEXT)(&pAd->TxContext[pAd->bulkResetPipeid ]); PTX_CONTEXT pMLMEContext = (PTX_CONTEXT)(pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa); PTX_CONTEXT pNULLContext = (PTX_CONTEXT)(&pAd->PsPollContext); PTX_CONTEXT pPsPollContext = (PTX_CONTEXT)(&pAd->NullContext); if (pHTTXContext->IRPPending) pendingContext |= 1; else if (pMLMEContext->IRPPending) pendingContext |= 2; else if (pNULLContext->IRPPending) pendingContext |= 4; else if (pPsPollContext->IRPPending) pendingContext |= 8; else pendingContext = 0; DBGPRINT_RAW(RT_DEBUG_ERROR, ("\tTX Occupied by %d!\n", pendingContext)); } // no matter what, clean the flag RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << pAd->bulkResetPipeid)); } RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); //RTUSBKickBulkOut(pAd); } } /* // Don't cancel BULKIN. while ((atomic_read(&pAd->PendingRx) > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { if (atomic_read(&pAd->PendingRx) > 0) { DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!cancel it!\n")); RTUSBCancelPendingBulkInIRP(pAd); } RTMPusecDelay(100000); } if ((atomic_read(&pAd->PendingRx) == 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { UCHAR i; RTUSBRxPacket(pAd); pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer for (i = 0; i < (RX_RING_SIZE); i++) { PRX_CONTEXT pRxContext = &(pAd->RxContext[i]); pRxContext->pAd = pAd; pRxContext->InUse = FALSE; pRxContext->IRPPending = FALSE; pRxContext->Readable = FALSE; pRxContext->ReorderInUse = FALSE; } RTUSBBulkReceive(pAd); DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTUSBBulkReceive\n")); }*/ DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_OUT<===\n")); break; case CMDTHREAD_RESET_BULK_IN: DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_IN === >\n")); // All transfers must be aborted or cancelled before attempting to reset the pipe. { UINT32 MACValue; /*-----------------------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------------------*/ { //while ((atomic_read(&pAd->PendingRx) > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) if((pAd->PendingRx > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!!\n")); RTUSBCancelPendingBulkInIRP(pAd); RTMPusecDelay(100000); pAd->PendingRx = 0; } } // Wait 10ms before reading register. RTMPusecDelay(10000); ntStatus = RTUSBReadMACRegister(pAd, MAC_CSR0, &MACValue); if ((NT_SUCCESS(ntStatus) == TRUE) && (!(RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))))) { UCHAR i; if (RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))) break; pAd->NextRxBulkInPosition = pAd->RxContext[pAd->NextRxBulkInIndex].BulkInOffset; DBGPRINT(RT_DEBUG_TRACE, ("BULK_IN_RESET: NBIIdx=0x%x,NBIRIdx=0x%x, BIRPos=0x%lx. BIReq=x%lx, BIComplete=0x%lx, BICFail0x%lx\n", pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex, pAd->NextRxBulkInPosition, pAd->BulkInReq, pAd->BulkInComplete, pAd->BulkInCompleteFail)); for (i = 0; i < RX_RING_SIZE; i++) { DBGPRINT(RT_DEBUG_TRACE, ("\tRxContext[%d]: IRPPending=%d, InUse=%d, Readable=%d!\n" , i, pAd->RxContext[i].IRPPending, pAd->RxContext[i].InUse, pAd->RxContext[i].Readable)); } /* DBGPRINT_RAW(RT_DEBUG_ERROR, ("==========================================\n")); pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer for (i = 0; i < (RX_RING_SIZE); i++) { PRX_CONTEXT pRxContext = &(pAd->RxContext[i]); pRxContext->pAd = pAd; pRxContext->InUse = FALSE; pRxContext->IRPPending = FALSE; pRxContext->Readable = FALSE; pRxContext->ReorderInUse = FALSE; }*/ RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET); for (i = 0; i < pAd->CommonCfg.NumOfBulkInIRP; i++) { //RTUSBBulkReceive(pAd); PRX_CONTEXT pRxContext; PURB pUrb; int ret = 0; unsigned long IrqFlags; RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); pRxContext = &(pAd->RxContext[pAd->NextRxBulkInIndex]); if ((pAd->PendingRx > 0) || (pRxContext->Readable == TRUE) || (pRxContext->InUse == TRUE)) { RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); break; } pRxContext->InUse = TRUE; pRxContext->IRPPending = TRUE; pAd->PendingRx++; pAd->BulkInReq++; RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); // Init Rx context descriptor RTUSBInitRxDesc(pAd, pRxContext); pUrb = pRxContext->pUrb; if ((ret = RTUSB_SUBMIT_URB(pUrb))!=0) { // fail RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); pRxContext->InUse = FALSE; pRxContext->IRPPending = FALSE; pAd->PendingRx--; pAd->BulkInReq--; RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); DBGPRINT(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB failed(%d), status=%d\n", ret, pUrb->status)); } else { // success DBGPRINT_RAW(RT_DEBUG_TRACE, ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB Done, status=%d!\n", pUrb->status)); ASSERT((pRxContext->InUse == pRxContext->IRPPending)); } } } else { // Card must be removed if (NT_SUCCESS(ntStatus) != TRUE) { RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST); DBGPRINT_RAW(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Read Register Failed!Card must be removed!!\n\n")); } else { DBGPRINT_RAW(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Cannot do bulk in because flags(0x%lx) on !\n", pAd->Flags)); } } } DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_IN <===\n")); break; case CMDTHREAD_SET_ASIC_WCID: { RT_SET_ASIC_WCID SetAsicWcid; USHORT offset; UINT32 MACValue, MACRValue = 0; SetAsicWcid = *((PRT_SET_ASIC_WCID)(pData)); if (SetAsicWcid.WCID >= MAX_LEN_OF_MAC_TABLE) return; offset = MAC_WCID_BASE + ((UCHAR)SetAsicWcid.WCID)*HW_WCID_ENTRY_SIZE; DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_SET_ASIC_WCID : WCID = %ld, SetTid = %lx, DeleteTid = %lx.\n", SetAsicWcid.WCID, SetAsicWcid.SetTid, SetAsicWcid.DeleteTid)); MACValue = (pAd->MacTab.Content[SetAsicWcid.WCID].Addr[3]<<24)+(pAd->MacTab.Content[SetAsicWcid.WCID].Addr[2]<<16)+(pAd->MacTab.Content[SetAsicWcid.WCID].Addr[1]<<8)+(pAd->MacTab.Content[SetAsicWcid.WCID].Addr[0]); DBGPRINT_RAW(RT_DEBUG_TRACE, ("1-MACValue= %x,\n", MACValue)); RTUSBWriteMACRegister(pAd, offset, MACValue); // Read bitmask RTUSBReadMACRegister(pAd, offset+4, &MACRValue); if ( SetAsicWcid.DeleteTid != 0xffffffff) MACRValue &= (~SetAsicWcid.DeleteTid); if (SetAsicWcid.SetTid != 0xffffffff) MACRValue |= (SetAsicWcid.SetTid); MACRValue &= 0xffff0000; MACValue = (pAd->MacTab.Content[SetAsicWcid.WCID].Addr[5]<<8)+pAd->MacTab.Content[SetAsicWcid.WCID].Addr[4]; MACValue |= MACRValue; RTUSBWriteMACRegister(pAd, offset+4, MACValue); DBGPRINT_RAW(RT_DEBUG_TRACE, ("2-MACValue= %x,\n", MACValue)); } break; case CMDTHREAD_SET_ASIC_WCID_CIPHER: { RT_SET_ASIC_WCID_ATTRI SetAsicWcidAttri; USHORT offset; UINT32 MACRValue = 0; SHAREDKEY_MODE_STRUC csr1; SetAsicWcidAttri = *((PRT_SET_ASIC_WCID_ATTRI)(pData)); if (SetAsicWcidAttri.WCID >= MAX_LEN_OF_MAC_TABLE) return; offset = MAC_WCID_ATTRIBUTE_BASE + ((UCHAR)SetAsicWcidAttri.WCID)*HW_WCID_ATTRI_SIZE; DBGPRINT_RAW(RT_DEBUG_TRACE, ("Cmd : CMDTHREAD_SET_ASIC_WCID_CIPHER : WCID = %ld, Cipher = %lx.\n", SetAsicWcidAttri.WCID, SetAsicWcidAttri.Cipher)); // Read bitmask RTUSBReadMACRegister(pAd, offset, &MACRValue); MACRValue = 0; MACRValue |= (((UCHAR)SetAsicWcidAttri.Cipher) << 1); RTUSBWriteMACRegister(pAd, offset, MACRValue); DBGPRINT_RAW(RT_DEBUG_TRACE, ("2-offset = %x , MACValue= %x,\n", offset, MACRValue)); offset = PAIRWISE_IVEIV_TABLE_BASE + ((UCHAR)SetAsicWcidAttri.WCID)*HW_IVEIV_ENTRY_SIZE; MACRValue = 0; if ( (SetAsicWcidAttri.Cipher <= CIPHER_WEP128)) MACRValue |= ( pAd->StaCfg.DefaultKeyId << 30); else MACRValue |= (0x20000000); RTUSBWriteMACRegister(pAd, offset, MACRValue); DBGPRINT_RAW(RT_DEBUG_TRACE, ("2-offset = %x , MACValue= %x,\n", offset, MACRValue)); // // Update cipher algorithm. WSTA always use BSS0 // // for adhoc mode only ,because wep status slow than add key, when use zero config if (pAd->StaCfg.BssType == BSS_ADHOC ) { offset = MAC_WCID_ATTRIBUTE_BASE; RTUSBReadMACRegister(pAd, offset, &MACRValue); MACRValue &= (~0xe); MACRValue |= (((UCHAR)SetAsicWcidAttri.Cipher) << 1); RTUSBWriteMACRegister(pAd, offset, MACRValue); //Update group key cipher,,because wep status slow than add key, when use zero config RTUSBReadMACRegister(pAd, SHARED_KEY_MODE_BASE+4*(0/2), &csr1.word); csr1.field.Bss0Key0CipherAlg = SetAsicWcidAttri.Cipher; csr1.field.Bss0Key1CipherAlg = SetAsicWcidAttri.Cipher; RTUSBWriteMACRegister(pAd, SHARED_KEY_MODE_BASE+4*(0/2), csr1.word); } } break; #ifdef RT30xx //Benson modified for USB interface, avoid in interrupt when write key, 20080724 --> case RT_CMD_SET_KEY_TABLE: //General call for AsicAddPairwiseKeyEntry() { RT_ADD_PAIRWISE_KEY_ENTRY KeyInfo; KeyInfo = *((PRT_ADD_PAIRWISE_KEY_ENTRY)(pData)); AsicAddPairwiseKeyEntry(pAd, KeyInfo.MacAddr, (UCHAR)KeyInfo.MacTabMatchWCID, &KeyInfo.CipherKey); } break; case RT_CMD_SET_RX_WCID_TABLE: //General call for RTMPAddWcidAttributeEntry() { PMAC_TABLE_ENTRY pEntry; UCHAR KeyIdx; UCHAR CipherAlg; UCHAR ApIdx; pEntry = (PMAC_TABLE_ENTRY)(pData); RTMPAddWcidAttributeEntry( pAd, ApIdx, KeyIdx, CipherAlg, pEntry); } break; //Benson modified for USB interface, avoid in interrupt when write key, 20080724 <-- #endif case CMDTHREAD_SET_CLIENT_MAC_ENTRY: { MAC_TABLE_ENTRY *pEntry; pEntry = (MAC_TABLE_ENTRY *)pData; { AsicRemovePairwiseKeyEntry(pAd, pEntry->apidx, (UCHAR)pEntry->Aid); if ((pEntry->AuthMode <= Ndis802_11AuthModeAutoSwitch) && (pEntry->WepStatus == Ndis802_11Encryption1Enabled)) { UINT32 uIV = 0; PUCHAR ptr; ptr = (PUCHAR) &uIV; *(ptr + 3) = (pAd->StaCfg.DefaultKeyId << 6); AsicUpdateWCIDIVEIV(pAd, pEntry->Aid, uIV, 0); AsicUpdateWCIDAttribute(pAd, pEntry->Aid, BSS0, pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg, FALSE); } else if (pEntry->AuthMode == Ndis802_11AuthModeWPANone) { UINT32 uIV = 0; PUCHAR ptr; ptr = (PUCHAR) &uIV; *(ptr + 3) = (pAd->StaCfg.DefaultKeyId << 6); AsicUpdateWCIDIVEIV(pAd, pEntry->Aid, uIV, 0); AsicUpdateWCIDAttribute(pAd, pEntry->Aid, BSS0, pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg, FALSE); } else { // // Other case, disable engine. // Don't worry WPA key, we will add WPA Key after 4-Way handshaking. // USHORT offset; offset = MAC_WCID_ATTRIBUTE_BASE + (pEntry->Aid * HW_WCID_ATTRI_SIZE); // RX_PKEY_MODE:0 for no security; RX_KEY_TAB:0 for shared key table; BSS_IDX:0 RTUSBWriteMACRegister(pAd, offset, 0); } } AsicUpdateRxWCIDTable(pAd, pEntry->Aid, pEntry->Addr); printk("UpdateRxWCIDTable(): Aid=%d, Addr=%02x:%02x:%02x:%02x:%02x:%02x!\n", pEntry->Aid, pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2], pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]); } break; #ifdef RT30xx // add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet case CMDTHREAD_UPDATE_PROTECT: { AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT), TRUE, 0); } break; // end johnli #endif case OID_802_11_ADD_WEP: { UINT i; UINT32 KeyIdx; PNDIS_802_11_WEP pWepKey; DBGPRINT(RT_DEBUG_TRACE, ("CmdThread::OID_802_11_ADD_WEP \n")); pWepKey = (PNDIS_802_11_WEP)pData; KeyIdx = pWepKey->KeyIndex & 0x0fffffff; // it is a shared key if ((KeyIdx >= 4) || ((pWepKey->KeyLength != 5) && (pWepKey->KeyLength != 13))) { NdisStatus = NDIS_STATUS_INVALID_DATA; DBGPRINT(RT_DEBUG_ERROR, ("CmdThread::OID_802_11_ADD_WEP, INVALID_DATA!!\n")); } else { UCHAR CipherAlg; pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength; NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength); CipherAlg = (pAd->SharedKey[BSS0][KeyIdx].KeyLen == 5)? CIPHER_WEP64 : CIPHER_WEP128; // // Change the WEP cipher to CKIP cipher if CKIP KP on. // Funk UI or Meetinghouse UI will add ckip key from this path. // if (pAd->OpMode == OPMODE_STA) { pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg; pAd->MacTab.Content[BSSID_WCID].PairwiseKey.KeyLen = pAd->SharedKey[BSS0][KeyIdx].KeyLen; } pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg; if (pWepKey->KeyIndex & 0x80000000) { // Default key for tx (shared key) UCHAR IVEIV[8]; UINT32 WCIDAttri, Value; USHORT offset, offset2; NdisZeroMemory(IVEIV, 8); pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx; // Add BSSID to WCTable. because this is Tx wep key. // WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:1=PAIRWISE KEY, BSSIdx is 0 WCIDAttri = (CipherAlg<<1)|SHAREDKEYTABLE; offset = MAC_WCID_ATTRIBUTE_BASE + (BSSID_WCID* HW_WCID_ATTRI_SIZE); RTUSBWriteMACRegister(pAd, offset, WCIDAttri); // 1. IV/EIV // Specify key index to find shared key. IVEIV[3] = (UCHAR)(KeyIdx<< 6); //WEP Eiv bit off. groupkey index is not 0 offset = PAIRWISE_IVEIV_TABLE_BASE + (BSS0Mcast_WCID * HW_IVEIV_ENTRY_SIZE); offset2 = PAIRWISE_IVEIV_TABLE_BASE + (BSSID_WCID* HW_IVEIV_ENTRY_SIZE); for (i=0; i<8;) { Value = IVEIV[i]; Value += (IVEIV[i+1]<<8); Value += (IVEIV[i+2]<<16); Value += (IVEIV[i+3]<<24); RTUSBWriteMACRegister(pAd, offset+i, Value); RTUSBWriteMACRegister(pAd, offset2+i, Value); i+=4; } // 2. WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:use share key, BSSIdx is 0 WCIDAttri = (pAd->SharedKey[BSS0][KeyIdx].CipherAlg<<1)|SHAREDKEYTABLE; offset = MAC_WCID_ATTRIBUTE_BASE + (BSS0Mcast_WCID* HW_WCID_ATTRI_SIZE); DBGPRINT(RT_DEBUG_TRACE, ("BSS0Mcast_WCID : offset = %x, WCIDAttri = %x\n", offset, WCIDAttri)); RTUSBWriteMACRegister(pAd, offset, WCIDAttri); } AsicAddSharedKeyEntry(pAd, BSS0, (UCHAR)KeyIdx, CipherAlg, pWepKey->KeyMaterial, NULL, NULL); DBGPRINT(RT_DEBUG_TRACE, ("CmdThread::OID_802_11_ADD_WEP (KeyIdx=%d, Len=%d-byte)\n", KeyIdx, pWepKey->KeyLength)); } } break; case CMDTHREAD_802_11_COUNTER_MEASURE: break; default: DBGPRINT(RT_DEBUG_ERROR, ("--> Control Thread !! ERROR !! Unknown(cmdqelmt->command=0x%x) !! \n", cmdqelmt->command)); break; } } if (cmdqelmt->CmdFromNdis == TRUE) { if (cmdqelmt->buffer != NULL) NdisFreeMemory(cmdqelmt->buffer, cmdqelmt->bufferlength, 0); NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0); } else { if ((cmdqelmt->buffer != NULL) && (cmdqelmt->bufferlength != 0)) NdisFreeMemory(cmdqelmt->buffer, cmdqelmt->bufferlength, 0); { NdisFreeMemory(cmdqelmt, sizeof(CmdQElmt), 0); } } } /* end of while */ }
/* ======================================================================== Description: This routine frees all packets in PSQ that's destined to a specific DA. BCAST/MCAST in DTIMCount=0 case is also handled here, just like a PS-POLL is received from a WSTA which has MAC address FF:FF:FF:FF:FF:FF ======================================================================== */ VOID RtmpHandleRxPsPoll(RTMP_ADAPTER *pAd, UCHAR *pAddr, USHORT wcid, BOOLEAN isActive) { QUEUE_ENTRY *pQEntry; MAC_TABLE_ENTRY *pMacEntry; unsigned long IrqFlags; /* DBGPRINT(RT_DEBUG_TRACE, ("rcv PS-POLL (AID=%d) from %02x:%02x:%02x:%02x:%02x:%02x\n", Aid, PRINT_MAC(pAddr))); */ pMacEntry = &pAd->MacTab.Content[wcid]; if (RTMPEqualMemory(pMacEntry->Addr, pAddr, MAC_ADDR_LEN)) { #ifdef DROP_MASK_SUPPORT /* Disable Drop Mask */ set_drop_mask_per_client(pAd, pMacEntry, 2, 0); #endif /* DROP_MASK_SUPPORT */ #ifdef PS_ENTRY_MAITENANCE pMacEntry->continuous_ps_count = 0; #endif /* PS_ENTRY_MAITENANCE */ /* Sta is change to Power Active stat. Reset ContinueTxFailCnt */ pMacEntry->ContinueTxFailCnt = 0; #ifdef UAPSD_SUPPORT if (UAPSD_MR_IS_ALL_AC_UAPSD(isActive, pMacEntry)) { /* IEEE802.11e spec. 11.2.1.7 Receive operation for STAs in PS mode during the CP When a non-AP QSTA that is using U-APSD and has all ACs delivery-enabled detects that the bit corresponding to its AID is set in the TIM, the non-AP QSTA shall issue a trigger frame or a PS-Poll frame to retrieve the buffered MSDU or management frames. WMM Spec. v1.1a 070601 3.6.2 U-APSD STA Operation 3.6.2.3 In case one or more ACs are not delivery-enabled ACs, the WMM STA may retrieve MSDUs and MMPDUs belonging to those ACs by sending PS-Polls to the WMM AP. In case all ACs are delivery enabled ACs, WMM STA should only use trigger frames to retrieve MSDUs and MMPDUs belonging to those ACs, and it should not send PS-Poll frames. Different definitions in IEEE802.11e and WMM spec. But we follow the WiFi WMM Spec. */ DBGPRINT(RT_DEBUG_TRACE, ("All AC are UAPSD, can not use PS-Poll\n")); return; /* all AC are U-APSD, can not use PS-Poll */ } #endif /* UAPSD_SUPPORT */ RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); if (isActive == FALSE) { if (pMacEntry->PsQueue.Head) { #ifdef UAPSD_SUPPORT UINT32 NumOfOldPsPkt; NumOfOldPsPkt = pAd->TxSwQueue[QID_AC_BE].Number; #endif /* UAPSD_SUPPORT */ pQEntry = RemoveHeadQueue(&pMacEntry->PsQueue); if ( pMacEntry->PsQueue.Number >=1 ) RTMP_SET_PACKET_MOREDATA(RTPKT_TO_OSPKT(pQEntry), TRUE); InsertTailQueueAc(pAd, pMacEntry, &pAd->TxSwQueue[QID_AC_BE], pQEntry); #ifdef UAPSD_SUPPORT /* we need to call RTMPDeQueuePacket() immediately as below */ if (NumOfOldPsPkt != pAd->TxSwQueue[QID_AC_BE].Number) { if (RTMP_GET_PACKET_DHCP(RTPKT_TO_OSPKT(pQEntry)) || RTMP_GET_PACKET_EAPOL(RTPKT_TO_OSPKT(pQEntry)) || RTMP_GET_PACKET_WAI(RTPKT_TO_OSPKT(pQEntry))) { /* These packets will use 1M/6M rate to send. If you use 1M(2.4G)/6M(5G) to send, no statistics count in NICUpdateFifoStaCounters(). So we can not count it for UAPSD; Or the SP will not closed until timeout. */ } else UAPSD_MR_MIX_PS_POLL_RCV(pAd, pMacEntry); } #endif /* UAPSD_SUPPORT */ } else { /* or transmit a (QoS) Null Frame; In addtion, in Station Keep Alive mechanism, we need to send a QoS Null frame to detect the station live status. */ BOOLEAN bQosNull = FALSE; if (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE)) bQosNull = TRUE; RtmpEnqueueNullFrame(pAd, pMacEntry->Addr, pMacEntry->CurrTxRate, pMacEntry->Aid, pMacEntry->apidx, bQosNull, TRUE, 0); } } else { #ifdef UAPSD_SUPPORT /* deliver all queued UAPSD packets */ UAPSD_AllPacketDeliver(pAd, pMacEntry); /* end the SP if exists */ UAPSD_MR_ENTRY_RESET(pAd, pMacEntry); #endif /* UAPSD_SUPPORT */ while(pMacEntry->PsQueue.Head) { pQEntry = RemoveHeadQueue(&pMacEntry->PsQueue); InsertTailQueueAc(pAd, pMacEntry, &pAd->TxSwQueue[QID_AC_BE], pQEntry); } } if ((pMacEntry->Aid > 0) && (pMacEntry->Aid < MAX_LEN_OF_MAC_TABLE) && (pMacEntry->PsQueue.Number == 0)) { /* clear corresponding TIM bit because no any PS packet */ #ifdef CONFIG_AP_SUPPORT if(pMacEntry->wdev->wdev_type == WDEV_TYPE_AP) { WLAN_MR_TIM_BIT_CLEAR(pAd, pMacEntry->apidx, pMacEntry->Aid); } #endif /* CONFIG_AP_SUPPORT */ pMacEntry->PsQIdleCount = 0; } RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); /* Dequeue outgoing frames from TxSwQueue0..3 queue and process it TODO: 2004-12-27 it's not a good idea to handle "More Data" bit here. because the RTMPDeQueue process doesn't guarantee to de-queue the desired MSDU from the corresponding TxSwQueue/PsQueue when QOS in-used. We should consider "HardTransmt" this MPDU using MGMT queue or things like that. */ RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); } else { DBGPRINT(RT_DEBUG_ERROR,("rcv PS-POLL (AID=%d not match) from %02x:%02x:%02x:%02x:%02x:%02x\n", pMacEntry->Aid, PRINT_MAC(pAddr))); } }
VOID CMDHandler( IN PRTMP_ADAPTER pAd) { PCmdQElmt cmdqelmt; PUCHAR pData; NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS; // ULONG Now = 0; NTSTATUS ntStatus; // unsigned long IrqFlags; while (pAd && pAd->CmdQ.size > 0) { NdisStatus = NDIS_STATUS_SUCCESS; NdisAcquireSpinLock(&pAd->CmdQLock); RTThreadDequeueCmd(&pAd->CmdQ, &cmdqelmt); NdisReleaseSpinLock(&pAd->CmdQLock); if (cmdqelmt == NULL) break; pData = cmdqelmt->buffer; if(!(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { switch (cmdqelmt->command) { case CMDTHREAD_CHECK_GPIO: { #ifdef CONFIG_STA_SUPPORT UINT32 data; #endif // CONFIG_STA_SUPPORT // #ifdef RALINK_ATE if(ATE_ON(pAd)) { ATEDBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n")); break; } #endif // RALINK_ATE // #ifdef CONFIG_STA_SUPPORT IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { // Read GPIO pin2 as Hardware controlled radio state RTUSBReadMACRegister( pAd, GPIO_CTRL_CFG, &data); if (data & 0x04) { pAd->StaCfg.bHwRadio = TRUE; } else { pAd->StaCfg.bHwRadio = FALSE; } if(pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio)) { pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio); if(pAd->StaCfg.bRadio == TRUE) { DBGPRINT_RAW(RT_DEBUG_ERROR, ("!!! Radio On !!!\n")); MlmeRadioOn(pAd); // Update extra information pAd->ExtraInfo = EXTRA_INFO_CLEAR; } else { DBGPRINT_RAW(RT_DEBUG_ERROR, ("!!! Radio Off !!!\n")); MlmeRadioOff(pAd); // Update extra information pAd->ExtraInfo = HW_RADIO_OFF; } } } #endif // CONFIG_STA_SUPPORT // } break; #ifdef CONFIG_STA_SUPPORT case CMDTHREAD_QKERIODIC_EXECUT: { StaQuickResponeForRateUpExec(NULL, pAd, NULL, NULL); } break; #endif // CONFIG_STA_SUPPORT // case CMDTHREAD_RESET_BULK_OUT: { UINT32 MACValue; UCHAR Index; int ret=0; PHT_TX_CONTEXT pHTTXContext; // RTMP_TX_RING *pTxRing; unsigned long IrqFlags; DBGPRINT(RT_DEBUG_TRACE, ("CMDTHREAD_RESET_BULK_OUT(ResetPipeid=0x%0x)===>\n", pAd->bulkResetPipeid)); // All transfers must be aborted or cancelled before attempting to reset the pipe. //RTUSBCancelPendingBulkOutIRP(pAd); // Wait 10ms to let previous packet that are already in HW FIFO to clear. by MAXLEE 12-25-2007 Index = 0; do { if(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) break; RTUSBReadMACRegister(pAd, TXRXQ_PCNT, &MACValue); if ((MACValue & 0xf00000/*0x800000*/) == 0) break; Index++; RTMPusecDelay(10000); }while(Index < 100); MACValue = 0; RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue); // 2nd, to prevent Read Register error, we check the validity. if ((MACValue & 0xc00000) == 0) RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue); // 3rd, to prevent Read Register error, we check the validity. if ((MACValue & 0xc00000) == 0) RTUSBReadMACRegister(pAd, USB_DMA_CFG, &MACValue); MACValue |= 0x80000; RTUSBWriteMACRegister(pAd, USB_DMA_CFG, MACValue); // Wait 1ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007 RTMPusecDelay(1000); MACValue &= (~0x80000); RTUSBWriteMACRegister(pAd, USB_DMA_CFG, MACValue); DBGPRINT(RT_DEBUG_TRACE, ("\tSet 0x2a0 bit19. Clear USB DMA TX path\n")); // Wait 5ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007 //RTMPusecDelay(5000); if ((pAd->bulkResetPipeid & BULKOUT_MGMT_RESET_FLAG) == BULKOUT_MGMT_RESET_FLAG) { RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); if (pAd->MgmtRing.TxSwFreeIdx < MGMT_RING_SIZE /* pMLMEContext->bWaitingBulkOut == TRUE */) { RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME); } RTUSBKickBulkOut(pAd); DBGPRINT(RT_DEBUG_TRACE, ("\tTX MGMT RECOVER Done!\n")); } else { pHTTXContext = &(pAd->TxContext[pAd->bulkResetPipeid]); //NdisAcquireSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); RTMP_INT_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); if ( pAd->BulkOutPending[pAd->bulkResetPipeid] == FALSE) { pAd->BulkOutPending[pAd->bulkResetPipeid] = TRUE; pHTTXContext->IRPPending = TRUE; pAd->watchDogTxPendingCnt[pAd->bulkResetPipeid] = 1; // no matter what, clean the flag RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); //NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); #ifdef RALINK_ATE if(ATE_ON(pAd)) { ret = ATEResetBulkOut(pAd); } else #endif // RALINK_ATE // { RTUSBInitHTTxDesc(pAd, pHTTXContext, pAd->bulkResetPipeid, pHTTXContext->BulkOutSize, (usb_complete_t)RTUSBBulkOutDataPacketComplete); if((ret = RTUSB_SUBMIT_URB(pHTTXContext->pUrb))!=0) { RTMP_INT_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); pAd->BulkOutPending[pAd->bulkResetPipeid] = FALSE; pHTTXContext->IRPPending = FALSE; pAd->watchDogTxPendingCnt[pAd->bulkResetPipeid] = 0; RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); DBGPRINT(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_OUT:Submit Tx URB failed %d\n", ret)); } else { RTMP_INT_LOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); DBGPRINT(RT_DEBUG_TRACE,("\tCMDTHREAD_RESET_BULK_OUT: TxContext[%d]:CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, pending=%d!\n", pAd->bulkResetPipeid, pHTTXContext->CurWritePosition, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad, pAd->BulkOutPending[pAd->bulkResetPipeid])); DBGPRINT(RT_DEBUG_TRACE,("\t\tBulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n", pAd->BulkOutReq, pAd->BulkOutComplete, pAd->BulkOutCompleteOther)); RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); DBGPRINT(RT_DEBUG_TRACE, ("\tCMDTHREAD_RESET_BULK_OUT: Submit Tx DATA URB for failed BulkReq(0x%lx) Done, status=%d!\n", pAd->bulkResetReq[pAd->bulkResetPipeid], pHTTXContext->pUrb->rtusb_urb_status)); } } } else { //NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); //RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); DBGPRINT(RT_DEBUG_ERROR, ("CmdThread : TX DATA RECOVER FAIL for BulkReq(0x%lx) because BulkOutPending[%d] is TRUE!\n", pAd->bulkResetReq[pAd->bulkResetPipeid], pAd->bulkResetPipeid)); if (pAd->bulkResetPipeid == 0) { UCHAR pendingContext = 0; PHT_TX_CONTEXT pHTTXContext = (PHT_TX_CONTEXT)(&pAd->TxContext[pAd->bulkResetPipeid ]); PTX_CONTEXT pMLMEContext = (PTX_CONTEXT)(pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa); PTX_CONTEXT pNULLContext = (PTX_CONTEXT)(&pAd->PsPollContext); PTX_CONTEXT pPsPollContext = (PTX_CONTEXT)(&pAd->NullContext); if (pHTTXContext->IRPPending) pendingContext |= 1; else if (pMLMEContext->IRPPending) pendingContext |= 2; else if (pNULLContext->IRPPending) pendingContext |= 4; else if (pPsPollContext->IRPPending) pendingContext |= 8; else pendingContext = 0; DBGPRINT(RT_DEBUG_ERROR, ("\tTX Occupied by %d!\n", pendingContext)); } // no matter what, clean the flag RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << pAd->bulkResetPipeid)); } RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); //RTUSBKickBulkOut(pAd); } } /* // Don't cancel BULKIN. while ((atomic_read(&pAd->PendingRx) > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { if (atomic_read(&pAd->PendingRx) > 0) { DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!cancel it!\n")); RTUSBCancelPendingBulkInIRP(pAd); } RTMPusecDelay(100000); } if ((atomic_read(&pAd->PendingRx) == 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { UCHAR i; RTUSBRxPacket(pAd); pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer for (i = 0; i < (RX_RING_SIZE); i++) { PRX_CONTEXT pRxContext = &(pAd->RxContext[i]); pRxContext->pAd = pAd; pRxContext->InUse = FALSE; pRxContext->IRPPending = FALSE; pRxContext->Readable = FALSE; pRxContext->ReorderInUse = FALSE; } RTUSBBulkReceive(pAd); DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTUSBBulkReceive\n")); }*/ DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_OUT<===\n")); break; case CMDTHREAD_RESET_BULK_IN: DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_IN === >\n")); // All transfers must be aborted or cancelled before attempting to reset the pipe. { UINT32 MACValue; #ifdef RALINK_ATE if (ATE_ON(pAd)) { ATEResetBulkIn(pAd); } else #endif // RALINK_ATE // { //while ((atomic_read(&pAd->PendingRx) > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) if((pAd->PendingRx > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!!\n")); RTUSBCancelPendingBulkInIRP(pAd); RTMPusecDelay(100000); pAd->PendingRx = 0; } } // Wait 10ms before reading register. RTMPusecDelay(10000); ntStatus = RTUSBReadMACRegister(pAd, MAC_CSR0, &MACValue); if ((NT_SUCCESS(ntStatus) == TRUE) && (!(RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))))) { UCHAR i; if (RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))) break; pAd->NextRxBulkInPosition = pAd->RxContext[pAd->NextRxBulkInIndex].BulkInOffset; DBGPRINT(RT_DEBUG_TRACE, ("BULK_IN_RESET: NBIIdx=0x%x,NBIRIdx=0x%x, BIRPos=0x%lx. BIReq=x%lx, BIComplete=0x%lx, BICFail0x%lx\n", pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex, pAd->NextRxBulkInPosition, pAd->BulkInReq, pAd->BulkInComplete, pAd->BulkInCompleteFail)); for (i = 0; i < RX_RING_SIZE; i++) { DBGPRINT(RT_DEBUG_TRACE, ("\tRxContext[%d]: IRPPending=%d, InUse=%d, Readable=%d!\n" , i, pAd->RxContext[i].IRPPending, pAd->RxContext[i].InUse, pAd->RxContext[i].Readable)); } /* DBGPRINT_RAW(RT_DEBUG_ERROR, ("==========================================\n")); pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer for (i = 0; i < (RX_RING_SIZE); i++) { PRX_CONTEXT pRxContext = &(pAd->RxContext[i]); pRxContext->pAd = pAd; pRxContext->InUse = FALSE; pRxContext->IRPPending = FALSE; pRxContext->Readable = FALSE; pRxContext->ReorderInUse = FALSE; }*/ RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET); for (i = 0; i < pAd->CommonCfg.NumOfBulkInIRP; i++) { //RTUSBBulkReceive(pAd); PRX_CONTEXT pRxContext; PURB pUrb; int ret = 0; unsigned long IrqFlags; RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); pRxContext = &(pAd->RxContext[pAd->NextRxBulkInIndex]); if ((pAd->PendingRx > 0) || (pRxContext->Readable == TRUE) || (pRxContext->InUse == TRUE)) { RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); break; } pRxContext->InUse = TRUE; pRxContext->IRPPending = TRUE; pAd->PendingRx++; pAd->BulkInReq++; RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); // Init Rx context descriptor RTUSBInitRxDesc(pAd, pRxContext); pUrb = pRxContext->pUrb; if ((ret = RTUSB_SUBMIT_URB(pUrb))!=0) { // fail RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); pRxContext->InUse = FALSE; pRxContext->IRPPending = FALSE; pAd->PendingRx--; pAd->BulkInReq--; RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); DBGPRINT(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB failed(%d), status=%d\n", ret, pUrb->rtusb_urb_status)); } else { // success //DBGPRINT(RT_DEBUG_TRACE, ("BIDone, Pend=%d,BIIdx=%d,BIRIdx=%d!\n", // pAd->PendingRx, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex)); DBGPRINT_RAW(RT_DEBUG_TRACE, ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB Done, status=%d!\n", pUrb->rtusb_urb_status)); ASSERT((pRxContext->InUse == pRxContext->IRPPending)); } } } else { // Card must be removed if (NT_SUCCESS(ntStatus) != TRUE) { RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST); DBGPRINT_RAW(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Read Register Failed!Card must be removed!!\n\n")); } else { DBGPRINT_RAW(RT_DEBUG_ERROR, ("CMDTHREAD_RESET_BULK_IN: Cannot do bulk in because flags(0x%lx) on !\n", pAd->Flags)); } } } DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_RESET_BULK_IN <===\n")); break; case CMDTHREAD_SET_ASIC_WCID: { RT_SET_ASIC_WCID SetAsicWcid; USHORT offset; UINT32 MACValue, MACRValue = 0; SetAsicWcid = *((PRT_SET_ASIC_WCID)(pData)); if (SetAsicWcid.WCID >= MAX_LEN_OF_MAC_TABLE) return; offset = MAC_WCID_BASE + ((UCHAR)SetAsicWcid.WCID)*HW_WCID_ENTRY_SIZE; DBGPRINT_RAW(RT_DEBUG_TRACE, ("CmdThread : CMDTHREAD_SET_ASIC_WCID : WCID = %ld, SetTid = %lx, DeleteTid = %lx.\n", SetAsicWcid.WCID, SetAsicWcid.SetTid, SetAsicWcid.DeleteTid)); MACValue = (pAd->MacTab.Content[SetAsicWcid.WCID].Addr[3]<<24)+(pAd->MacTab.Content[SetAsicWcid.WCID].Addr[2]<<16)+(pAd->MacTab.Content[SetAsicWcid.WCID].Addr[1]<<8)+(pAd->MacTab.Content[SetAsicWcid.WCID].Addr[0]); DBGPRINT_RAW(RT_DEBUG_TRACE, ("1-MACValue= %x,\n", MACValue)); RTUSBWriteMACRegister(pAd, offset, MACValue); // Read bitmask RTUSBReadMACRegister(pAd, offset+4, &MACRValue); if ( SetAsicWcid.DeleteTid != 0xffffffff) MACRValue &= (~SetAsicWcid.DeleteTid); if (SetAsicWcid.SetTid != 0xffffffff) MACRValue |= (SetAsicWcid.SetTid); MACRValue &= 0xffff0000; MACValue = (pAd->MacTab.Content[SetAsicWcid.WCID].Addr[5]<<8)+pAd->MacTab.Content[SetAsicWcid.WCID].Addr[4]; MACValue |= MACRValue; RTUSBWriteMACRegister(pAd, offset+4, MACValue); DBGPRINT_RAW(RT_DEBUG_TRACE, ("2-MACValue= %x,\n", MACValue)); } break; /* Security Related for Asic command */ case CMDTHREAD_SET_WCID_SEC_INFO: { PRT_ASIC_WCID_SEC_INFO pInfo; pInfo = (PRT_ASIC_WCID_SEC_INFO)pData; RTMPSetWcidSecurityInfo(pAd, pInfo->BssIdx, pInfo->KeyIdx, pInfo->CipherAlg, pInfo->Wcid, pInfo->KeyTabFlag); } break; case CMDTHREAD_SET_ASIC_WCID_IVEIV: { PRT_ASIC_WCID_IVEIV_ENTRY pInfo; pInfo = (PRT_ASIC_WCID_IVEIV_ENTRY)pData; AsicUpdateWCIDIVEIV(pAd, pInfo->Wcid, pInfo->Iv, pInfo->Eiv); } break; case CMDTHREAD_SET_ASIC_WCID_ATTR: { PRT_ASIC_WCID_ATTR_ENTRY pInfo; pInfo = (PRT_ASIC_WCID_ATTR_ENTRY)pData; AsicUpdateWcidAttributeEntry(pAd, pInfo->BssIdx, pInfo->KeyIdx, pInfo->CipherAlg, pInfo->Wcid, pInfo->KeyTabFlag); } break; case CMDTHREAD_SET_ASIC_SHARED_KEY: { PRT_ASIC_SHARED_KEY pInfo; pInfo = (PRT_ASIC_SHARED_KEY)pData; AsicAddSharedKeyEntry(pAd, pInfo->BssIndex, pInfo->KeyIdx, &pInfo->CipherKey); } break; case CMDTHREAD_SET_ASIC_PAIRWISE_KEY: { PRT_ASIC_PAIRWISE_KEY pInfo; pInfo = (PRT_ASIC_PAIRWISE_KEY)pData; AsicAddPairwiseKeyEntry(pAd, pInfo->WCID, &pInfo->CipherKey); } break; case CMDTHREAD_SET_PORT_SECURED: { #ifdef CONFIG_STA_SUPPORT STA_PORT_SECURED(pAd); #endif // CONFIG_STA_SUPPORT // } break; case CMDTHREAD_REMOVE_PAIRWISE_KEY: { UCHAR Wcid = *((PUCHAR)(pData)); AsicRemovePairwiseKeyEntry(pAd, Wcid); } break; case CMDTHREAD_SET_CLIENT_MAC_ENTRY: { PRT_SET_ASIC_WCID pInfo; pInfo = (PRT_SET_ASIC_WCID)pData; AsicUpdateRxWCIDTable(pAd, pInfo->WCID, pInfo->Addr); } break; // add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet case CMDTHREAD_UPDATE_PROTECT: { AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT), TRUE, 0); } break; // end johnli case CMDTHREAD_802_11_COUNTER_MEASURE: break; #ifdef CONFIG_STA_SUPPORT case CMDTHREAD_SET_PSM_BIT: IF_DEV_CONFIG_OPMODE_ON_STA(pAd) { USHORT *pPsm = (USHORT *)pData; MlmeSetPsmBit(pAd, *pPsm); } break; case CMDTHREAD_FORCE_WAKE_UP: IF_DEV_CONFIG_OPMODE_ON_STA(pAd) AsicForceWakeup(pAd, TRUE); break; case CMDTHREAD_FORCE_SLEEP_AUTO_WAKEUP: { USHORT TbttNumToNextWakeUp; USHORT NextDtim = pAd->StaCfg.DtimPeriod; ULONG Now; NdisGetSystemUpTime(&Now); NextDtim -= (USHORT)(Now - pAd->StaCfg.LastBeaconRxTime)/pAd->CommonCfg.BeaconPeriod; TbttNumToNextWakeUp = pAd->StaCfg.DefaultListenCount; if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM) && (TbttNumToNextWakeUp > NextDtim)) TbttNumToNextWakeUp = NextDtim; RTMP_SET_PSM_BIT(pAd, PWR_SAVE); // if WMM-APSD is failed, try to disable following line AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp); } break; #endif // CONFIG_STA_SUPPORT // default: DBGPRINT(RT_DEBUG_ERROR, ("--> Control Thread !! ERROR !! Unknown(cmdqelmt->command=0x%x) !! \n", cmdqelmt->command)); break; } } if (cmdqelmt->CmdFromNdis == TRUE) { if (cmdqelmt->buffer != NULL) os_free_mem(pAd, cmdqelmt->buffer); os_free_mem(pAd, cmdqelmt); } else { if ((cmdqelmt->buffer != NULL) && (cmdqelmt->bufferlength != 0)) os_free_mem(pAd, cmdqelmt->buffer); os_free_mem(pAd, cmdqelmt); } } /* end of while */ }
/* ======================================================================== Description: This routine frees all packets in PSQ that's destined to a specific DA. BCAST/MCAST in DTIMCount=0 case is also handled here, just like a PS-POLL is received from a WSTA which has MAC address FF:FF:FF:FF:FF:FF ======================================================================== */ VOID MtHandleRxPsPoll(RTMP_ADAPTER *pAd, UCHAR *pAddr, USHORT wcid, BOOLEAN isActive) { #ifdef CONFIG_AP_SUPPORT #if defined(MT_PS) || defined(UAPSD_SUPPORT) MAC_TABLE_ENTRY *pMacEntry; #endif STA_TR_ENTRY *tr_entry; BOOLEAN IsDequeu= FALSE; INT DequeuAC = QID_AC_BE; INT DequeuCOUNT; #ifdef MT_PS INT i, Total_Packet_Number = 0; #endif /* MT_PS */ //struct tx_swq_fifo *fifo_swq; ASSERT(wcid < MAX_LEN_OF_MAC_TABLE); #if defined(MT_PS) || defined(UAPSD_SUPPORT) pMacEntry = &pAd->MacTab.Content[wcid]; #endif tr_entry = &pAd->MacTab.tr_entry[wcid]; if (isActive == FALSE) /* ps poll */ { #ifdef MT_PS if (tr_entry->ps_state == APPS_RETRIEVE_DONE) /*state is finish(sleep)*/ { if (pMacEntry->i_psm == I_PSM_DISABLE) { MT_SET_IGNORE_PSM(pAd, pMacEntry, I_PSM_ENABLE); } } if(tr_entry->ps_state == APPS_RETRIEVE_DONE || tr_entry->ps_state == APPS_RETRIEVE_IDLE) { for (i = 0; i < WMM_QUE_NUM; i++) Total_Packet_Number = Total_Packet_Number + tr_entry->tx_queue[i].Number; if (Total_Packet_Number > 0) { { DBGPRINT(RT_DEBUG_TRACE | DBG_FUNC_PS, ("RtmpHandleRxPsPoll fetch tx queue tr_entry->ps_queue.Number= %x tr_entry->tx_queue[0].Number=%x Total_Packet_Number=%x\n", tr_entry->ps_queue.Number, tr_entry->tx_queue[QID_AC_BE].Number, Total_Packet_Number)); for (i = (WMM_QUE_NUM - 1); i >=0; i--) { if (tr_entry->tx_queue[i].Head) { if (Total_Packet_Number > 1) { RTMP_SET_PACKET_MOREDATA(RTPKT_TO_OSPKT(tr_entry->tx_queue[i].Head), TRUE); } RTMP_SET_PACKET_TXTYPE(RTPKT_TO_OSPKT(tr_entry->tx_queue[i].Head), TX_LEGACY_FRAME); DequeuAC = i; IsDequeu = TRUE; DequeuCOUNT = 1; tr_entry->PsQIdleCount = 0; break; } } } } else /* Recieve ps_poll but no packet==>send NULL Packet */ { BOOLEAN bQosNull = FALSE; DBGPRINT(RT_DEBUG_INFO | DBG_FUNC_PS, ("RtmpHandleRxPsPoll no packet tr_entry->ps_queue.Number= %x tr_entry->tx_queue[0].Number=%x Total_Packet_Number=%x\n" ,tr_entry->ps_queue.Number, tr_entry->tx_queue[QID_AC_BE].Number, Total_Packet_Number)); if (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE)) bQosNull = TRUE; RtmpEnqueueNullFrame(pAd, pMacEntry->Addr, tr_entry->CurrTxRate, pMacEntry->Aid, pMacEntry->func_tb_idx, bQosNull, TRUE, 0); } if (Total_Packet_Number >1) { WLAN_MR_TIM_BIT_SET(pAd, tr_entry->func_tb_idx, tr_entry->wcid); } else { WLAN_MR_TIM_BIT_CLEAR(pAd, tr_entry->func_tb_idx, tr_entry->wcid); } } else tr_entry->PsDeQWaitCnt = 0; #else /* Need to check !! @20140212 New architecture has per AC sw-Q for per entry. We should check packets by ACs priority --> 1. VO, 2. VI, 3. BE, 4. BK */ DequeuAC = QID_AC_BE; IsDequeu = TRUE; DequeuCOUNT = 1; tr_entry->PsQIdleCount = 0; #endif /* Ps_poll and ifndef MT_PS */ } else /* Receive Power bit 0 frame */ { WLAN_MR_TIM_BIT_CLEAR(pAd, tr_entry->func_tb_idx, tr_entry->wcid); #ifdef MT_PS if (pMacEntry->i_psm == I_PSM_ENABLE) { MT_SET_IGNORE_PSM(pAd, pMacEntry, I_PSM_DISABLE); } #endif /*Power bit is 1 and ifndef MT_PS */ DBGPRINT(RT_DEBUG_INFO | DBG_FUNC_PS, ("RtmpHandleRxPsPoll null0/1 wcid = %x mt_ps_queue.Number = %d\n", tr_entry->wcid, tr_entry->ps_queue.Number)); DBGPRINT(RT_DEBUG_INFO | DBG_FUNC_PS, ("%s(%d) tx_queue.Number = BE:%d, BK:%d, VI:%d, VO:%d, ps_state:%x, tx_queue.TokenCount = BE:%d, BK:%d, VI:%d, VO:%d\n", __FUNCTION__, __LINE__, tr_entry->tx_queue[QID_AC_BE].Number, tr_entry->tx_queue[QID_AC_BK].Number, tr_entry->tx_queue[QID_AC_VI].Number, tr_entry->tx_queue[QID_AC_VO].Number, tr_entry->ps_state, tr_entry->TokenCount[QID_AC_BE], tr_entry->TokenCount[QID_AC_BK], tr_entry->TokenCount[QID_AC_VI], tr_entry->TokenCount[QID_AC_VO])); #ifdef UAPSD_SUPPORT if (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_APSD_CAPABLE)) { /* deliver all queued UAPSD packets */ UAPSD_AllPacketDeliver(pAd, pMacEntry); /* end the SP if exists */ UAPSD_MR_ENTRY_RESET(pAd, pMacEntry); } #endif /* UAPSD_SUPPORT */ if (tr_entry->enqCount > 0) { IsDequeu = TRUE; DequeuAC = NUM_OF_TX_RING; if (tr_entry->enqCount > MAX_TX_PROCESS) { DequeuCOUNT = MAX_TX_PROCESS; rtmp_ps_enq(pAd,tr_entry); } else { DequeuCOUNT = tr_entry->enqCount; } } } if (IsDequeu == TRUE) { RTMPDeQueuePacket(pAd, FALSE, DequeuAC, tr_entry->wcid, DequeuCOUNT); DBGPRINT(RT_DEBUG_INFO | DBG_FUNC_PS, ("RtmpHandleRxPsPoll IsDequeu == TRUE tr_entry->wcid=%x DequeuCOUNT=%d, ps_state=%d\n",tr_entry->wcid, DequeuCOUNT, tr_entry->ps_state)); } return; #endif /* CONFIG_AP_SUPPORT */ }
void tbtt_tasklet(unsigned long data) { //#define MAX_TX_IN_TBTT (16) #ifdef CONFIG_AP_SUPPORT PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data; #ifdef RTMP_MAC_PCI if (pAd->OpMode == OPMODE_AP) { #ifdef AP_QLOAD_SUPPORT /* update channel utilization */ QBSS_LoadUpdate(pAd, 0); #endif // AP_QLOAD_SUPPORT // } #endif // RTMP_MAC_PCI // if (pAd->OpMode == OPMODE_AP) { // // step 7 - if DTIM, then move backlogged bcast/mcast frames from PSQ to TXQ whenever DtimCount==0 #ifdef RTMP_MAC_PCI // NOTE: This updated BEACON frame will be sent at "next" TBTT instead of at cureent TBTT. The reason is // because ASIC already fetch the BEACON content down to TX FIFO before driver can make any // modification. To compenstate this effect, the actual time to deilver PSQ frames will be // at the time that we wrapping around DtimCount from 0 to DtimPeriod-1 if (pAd->ApCfg.DtimCount == 0) #endif // RTMP_MAC_PCI // { PQUEUE_ENTRY pEntry; BOOLEAN bPS = FALSE; UINT count = 0; unsigned long IrqFlags; // NdisAcquireSpinLock(&pAd->MacTabLock); // NdisAcquireSpinLock(&pAd->TxSwQueueLock); RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); while (pAd->MacTab.McastPsQueue.Head) { bPS = TRUE; if (pAd->TxSwQueue[QID_AC_BE].Number <= (MAX_PACKETS_IN_QUEUE + MAX_PACKETS_IN_MCAST_PS_QUEUE)) { pEntry = RemoveHeadQueue(&pAd->MacTab.McastPsQueue); //if(pAd->MacTab.McastPsQueue.Number) if (count) { RTMP_SET_PACKET_MOREDATA(pEntry, TRUE); } InsertHeadQueue(&pAd->TxSwQueue[QID_AC_BE], pEntry); count++; } else { break; } } RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); // NdisReleaseSpinLock(&pAd->TxSwQueueLock); // NdisReleaseSpinLock(&pAd->MacTabLock); if (pAd->MacTab.McastPsQueue.Number == 0) { UINT bss_index; /* clear MCAST/BCAST backlog bit for all BSS */ for(bss_index=BSS0; bss_index<pAd->ApCfg.BssidNum; bss_index++) WLAN_MR_TIM_BCMC_CLEAR(bss_index); /* End of for */ } pAd->MacTab.PsQIdleCount = 0; // Dequeue outgoing framea from TxSwQueue0..3 queue and process it if (bPS == TRUE) { RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, /*MAX_TX_IN_TBTT*/MAX_PACKETS_IN_MCAST_PS_QUEUE); } } } #endif // CONFIG_AP_SUPPORT // }
/* ======================================================================== Routine Description: Early checking and OS-depened parsing for Tx packet to AP device. Arguments: NDIS_HANDLE MiniportAdapterContext Pointer refer to the device handle, i.e., the pAd. PPNDIS_PACKET ppPacketArray The packet array need to do transmission. UINT NumberOfPackets Number of packet in packet array. Return Value: NONE Note: This function do early checking and classification for send-out packet. You only can put OS-depened & AP related code in here. ======================================================================== */ INT wdev_tx_pkts(NDIS_HANDLE dev_hnd, PPNDIS_PACKET pkt_list, UINT pkt_cnt, struct wifi_dev *wdev) { RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)dev_hnd; PNDIS_PACKET pPacket; BOOLEAN allowToSend; UCHAR wcid = MAX_LEN_OF_MAC_TABLE; UINT Index; #ifdef CONFIG_FPGA_MODE BOOLEAN force_tx; #endif /* CONFIG_FPGA_MODE */ for (Index = 0; Index < pkt_cnt; Index++) { pPacket = pkt_list[Index]; if (RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))) { /* Drop send request since hardware is in reset state */ RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); continue; } #ifdef CONFIG_FPGA_MODE force_tx = FALSE; if (pAd->fpga_ctl.fpga_on & 0x1) { if (pAd->fpga_ctl.tx_kick_cnt > 0) { if (pAd->fpga_ctl.tx_kick_cnt < 0xffff) { pAd->fpga_ctl.tx_kick_cnt--; } force_tx = TRUE; } } #endif /* CONFIG_FPGA_MODE */ if (((wdev->allow_data_tx == TRUE) #ifdef CONFIG_FPGA_MODE || (force_tx == TRUE) #endif /* CONFIG_FPGA_MODE */ ) && (wdev->tx_pkt_allowed)) { allowToSend = wdev->tx_pkt_allowed(pAd, wdev, pPacket, &wcid); } else { allowToSend = FALSE; //RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } #ifdef CONFIG_FPGA_MODE if (force_tx == TRUE && allowToSend == TRUE) { //int dump_len = GET_OS_PKT_LEN(pPacket); DBGPRINT(RT_DEBUG_INFO, ("%s():send Packet!wcid=%d, wdev_idx=%d, pktLen=%d\n", __FUNCTION__, wcid, wdev->wdev_idx, GET_OS_PKT_LEN(pPacket))); //hex_dump("wdev_tx_pkts():802.3 packet", GET_OS_PKT_DATAPTR(pPacket), dump_len > 255 ? 255 : dump_len); } #endif /* CONFIG_FPGA_MODE */ if (allowToSend == TRUE) { RTMP_SET_PACKET_WCID(pPacket, wcid); RTMP_SET_PACKET_WDEV(pPacket, wdev->wdev_idx); NDIS_SET_PACKET_STATUS(pPacket, NDIS_STATUS_PENDING); pAd->RalinkCounters.PendingNdisPacketCount++; if (wdev->tx_pkt_handle) wdev->tx_pkt_handle(pAd, pPacket); else { DBGPRINT(RT_DEBUG_ERROR, ("%s():tx_pkt_handle not assigned!\n", __FUNCTION__)); RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } } else RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); } RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, WCID_ALL, MAX_TX_PROCESS); return 0; }