2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
31 main initialization routines
35 -------- ---------- ----------------------------------------------
36 Name Date Modification logs
37 Jan Lee 01-10-2005 modified
38 Sample Jun/01/07 Merge RT2870 and RT2860 drivers.
41 #include "rt_config.h"
44 // Following information will be show when you run 'modinfo'
45 // *** If you have a solution for the bug in current version of driver, please mail to me.
46 // Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. ***
47 MODULE_AUTHOR("Paul Lin <paul_lin@ralinktech.com>");
48 MODULE_DESCRIPTION(RT28xx_CHIP_NAME " Wireless LAN Linux Driver");
49 MODULE_LICENSE("GPL");
51 MODULE_VERSION(STA_DRIVER_VERSION);
54 /* Kernel thread and vars, which handles packets that are completed. Only
55 * packets that have a "complete" function are sent here. This way, the
56 * completion is run out of kernel context, and doesn't block the rest of
59 extern INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
60 IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
64 struct usb_device_id rtusb_usb_id[] = RT2870_USB_DEVICES;
65 INT const rtusb_usb_id_len = sizeof(rtusb_usb_id) / sizeof(struct usb_device_id);
66 MODULE_DEVICE_TABLE(usb, rtusb_usb_id);
74 static int rt2870_suspend(struct usb_interface *intf, pm_message_t state);
75 static int rt2870_resume(struct usb_interface *intf);
76 #endif // CONFIG_PM //
78 /**************************************************************************/
79 /**************************************************************************/
80 //tested for kernel 2.6series
81 /**************************************************************************/
82 /**************************************************************************/
83 static int rtusb_probe (struct usb_interface *intf,
84 const struct usb_device_id *id);
85 static void rtusb_disconnect(struct usb_interface *intf);
87 struct usb_driver rtusb_driver = {
90 .disconnect=rtusb_disconnect,
91 .id_table=rtusb_usb_id,
94 suspend: rt2870_suspend,
95 resume: rt2870_resume,
101 VOID RT2860RejectPendingPackets(
102 IN PRTMP_ADAPTER pAd)
105 // clear TxSw packets
108 static int rt2870_suspend(
109 struct usb_interface *intf,
112 struct net_device *net_dev;
113 PRTMP_ADAPTER pAd = usb_get_intfdata(intf);
116 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_suspend()\n"));
117 net_dev = pAd->net_dev;
118 netif_device_detach (net_dev);
120 pAd->PM_FlgSuspend = 1;
121 if (netif_running(net_dev)) {
122 RTUSBCancelPendingBulkInIRP(pAd);
123 RTUSBCancelPendingBulkOutIRP(pAd);
125 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_suspend()\n"));
129 static int rt2870_resume(
130 struct usb_interface *intf)
132 struct net_device *net_dev;
133 PRTMP_ADAPTER pAd = usb_get_intfdata(intf);
136 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_resume()\n"));
138 pAd->PM_FlgSuspend = 0;
139 net_dev = pAd->net_dev;
140 netif_device_attach (net_dev);
141 netif_start_queue(net_dev);
142 netif_carrier_on(net_dev);
143 netif_wake_queue(net_dev);
145 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_resume()\n"));
148 #endif // CONFIG_PM //
151 // Init driver module
152 INT __init rtusb_init(void)
154 printk("rtusb init --->\n");
155 return usb_register(&rtusb_driver);
158 // Deinit driver module
159 VOID __exit rtusb_exit(void)
161 usb_deregister(&rtusb_driver);
162 printk("<--- rtusb exit\n");
165 module_init(rtusb_init);
166 module_exit(rtusb_exit);
171 /*--------------------------------------------------------------------- */
172 /* function declarations */
173 /*--------------------------------------------------------------------- */
176 ========================================================================
181 *Context the pAd, driver control block pointer
187 ========================================================================
192 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)Context;
196 pObj = (POS_COOKIE)pAd->OS_Cookie;
198 rtmp_os_thread_init("rt2870MlmeThread", (PVOID)&(pAd->mlmeComplete));
200 while (pAd->mlme_kill == 0)
202 /* lock the device pointers */
203 //down(&(pAd->mlme_semaphore));
204 status = down_interruptible(&(pAd->mlme_semaphore));
206 /* lock the device pointers , need to check if required*/
207 //down(&(pAd->usbdev_semaphore));
209 if (!pAd->PM_FlgSuspend)
212 /* unlock the device pointers */
213 //up(&(pAd->usbdev_semaphore));
216 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
221 /* notify the exit routine that we're actually exiting now
223 * complete()/wait_for_completion() is similar to up()/down(),
224 * except that complete() is safe in the case where the structure
225 * is getting deleted in a parallel mode of execution (i.e. just
226 * after the down() -- that's necessary for the thread-shutdown
229 * complete_and_exit() goes even further than this -- it is safe in
230 * the case that the thread of the caller is going away (not just
231 * the structure) -- this is necessary for the module-remove case.
232 * This is important in preemption kernels, which transfer the flow
233 * of execution immediately upon a complete().
235 DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__func__));
238 pObj->MLMEThr_pid = THREAD_PID_INIT_VALUE;
241 pObj->MLMEThr_pid = NULL;
244 complete_and_exit (&pAd->mlmeComplete, 0);
251 ========================================================================
253 USB command kernel thread.
256 *Context the pAd, driver control block pointer
262 ========================================================================
267 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)Context;
271 pObj = (POS_COOKIE)pAd->OS_Cookie;
273 rtmp_os_thread_init("rt2870CmdThread", (PVOID)&(pAd->CmdQComplete));
275 NdisAcquireSpinLock(&pAd->CmdQLock);
276 pAd->CmdQ.CmdQState = RT2870_THREAD_RUNNING;
277 NdisReleaseSpinLock(&pAd->CmdQLock);
279 while (pAd->CmdQ.CmdQState == RT2870_THREAD_RUNNING)
281 /* lock the device pointers */
282 //down(&(pAd->RTUSBCmd_semaphore));
283 status = down_interruptible(&(pAd->RTUSBCmd_semaphore));
285 if (pAd->CmdQ.CmdQState == RT2870_THREAD_STOPED)
290 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
293 /* lock the device pointers , need to check if required*/
294 //down(&(pAd->usbdev_semaphore));
296 if (!pAd->PM_FlgSuspend)
299 /* unlock the device pointers */
300 //up(&(pAd->usbdev_semaphore));
303 if (!pAd->PM_FlgSuspend)
304 { // Clear the CmdQElements.
305 CmdQElmt *pCmdQElmt = NULL;
307 NdisAcquireSpinLock(&pAd->CmdQLock);
308 pAd->CmdQ.CmdQState = RT2870_THREAD_STOPED;
309 while(pAd->CmdQ.size)
311 RTUSBDequeueCmd(&pAd->CmdQ, &pCmdQElmt);
314 if (pCmdQElmt->CmdFromNdis == TRUE)
316 if (pCmdQElmt->buffer != NULL)
317 NdisFreeMemory(pCmdQElmt->buffer, pCmdQElmt->bufferlength, 0);
319 NdisFreeMemory(pCmdQElmt, sizeof(CmdQElmt), 0);
323 if ((pCmdQElmt->buffer != NULL) && (pCmdQElmt->bufferlength != 0))
324 NdisFreeMemory(pCmdQElmt->buffer, pCmdQElmt->bufferlength, 0);
326 NdisFreeMemory(pCmdQElmt, sizeof(CmdQElmt), 0);
332 NdisReleaseSpinLock(&pAd->CmdQLock);
334 /* notify the exit routine that we're actually exiting now
336 * complete()/wait_for_completion() is similar to up()/down(),
337 * except that complete() is safe in the case where the structure
338 * is getting deleted in a parallel mode of execution (i.e. just
339 * after the down() -- that's necessary for the thread-shutdown
342 * complete_and_exit() goes even further than this -- it is safe in
343 * the case that the thread of the caller is going away (not just
344 * the structure) -- this is necessary for the module-remove case.
345 * This is important in preemption kernels, which transfer the flow
346 * of execution immediately upon a complete().
348 DBGPRINT(RT_DEBUG_TRACE,( "<---RTUSBCmdThread\n"));
351 pObj->RTUSBCmdThr_pid = THREAD_PID_INIT_VALUE;
354 pObj->RTUSBCmdThr_pid = NULL;
357 complete_and_exit (&pAd->CmdQComplete, 0);
363 static void RT2870_TimerQ_Handle(RTMP_ADAPTER *pAd)
366 RALINK_TIMER_STRUCT *pTimer;
367 RT2870_TIMER_ENTRY *pEntry;
368 unsigned long irqFlag;
370 while(!pAd->TimerFunc_kill)
372 // printk("waiting for event!\n");
375 status = down_interruptible(&(pAd->RTUSBTimer_semaphore));
377 if (pAd->TimerQ.status == RT2870_THREAD_STOPED)
381 while(pAd->TimerQ.pQHead)
383 RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlag);
384 pEntry = pAd->TimerQ.pQHead;
387 pTimer = pEntry->pRaTimer;
390 pAd->TimerQ.pQHead = pEntry->pNext;
391 if (pEntry == pAd->TimerQ.pQTail)
392 pAd->TimerQ.pQTail = NULL;
394 // return this queue entry to timerQFreeList.
395 pEntry->pNext = pAd->TimerQ.pQPollFreeList;
396 pAd->TimerQ.pQPollFreeList = pEntry;
398 RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlag);
402 if (pTimer->handle != NULL)
403 if (!pAd->PM_FlgSuspend)
404 pTimer->handle(NULL, (PVOID) pTimer->cookie, NULL, pTimer);
405 if ((pTimer->Repeat) && (pTimer->State == FALSE))
406 RTMP_OS_Add_Timer(&pTimer->TimerObj, pTimer->TimerValue);
412 pAd->TimerQ.status = RT2870_THREAD_STOPED;
413 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
421 IN OUT PVOID Context)
426 pAd = (PRTMP_ADAPTER)Context;
427 pObj = (POS_COOKIE) pAd->OS_Cookie;
429 rtmp_os_thread_init("rt2870TimerQHandle", (PVOID)&(pAd->TimerQComplete));
431 RT2870_TimerQ_Handle(pAd);
433 /* notify the exit routine that we're actually exiting now
435 * complete()/wait_for_completion() is similar to up()/down(),
436 * except that complete() is safe in the case where the structure
437 * is getting deleted in a parallel mode of execution (i.e. just
438 * after the down() -- that's necessary for the thread-shutdown
441 * complete_and_exit() goes even further than this -- it is safe in
442 * the case that the thread of the caller is going away (not just
443 * the structure) -- this is necessary for the module-remove case.
444 * This is important in preemption kernels, which transfer the flow
445 * of execution immediately upon a complete().
447 DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__func__));
450 pObj->TimerQThr_pid = THREAD_PID_INIT_VALUE;
453 pObj->TimerQThr_pid = NULL;
455 complete_and_exit(&pAd->TimerQComplete, 0);
461 RT2870_TIMER_ENTRY *RT2870_TimerQ_Insert(
462 IN RTMP_ADAPTER *pAd,
463 IN RALINK_TIMER_STRUCT *pTimer)
465 RT2870_TIMER_ENTRY *pQNode = NULL, *pQTail;
466 unsigned long irqFlags;
469 RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
470 if (pAd->TimerQ.status & RT2870_THREAD_CAN_DO_INSERT)
472 if(pAd->TimerQ.pQPollFreeList)
474 pQNode = pAd->TimerQ.pQPollFreeList;
475 pAd->TimerQ.pQPollFreeList = pQNode->pNext;
477 pQNode->pRaTimer = pTimer;
478 pQNode->pNext = NULL;
480 pQTail = pAd->TimerQ.pQTail;
481 if (pAd->TimerQ.pQTail != NULL)
482 pQTail->pNext = pQNode;
483 pAd->TimerQ.pQTail = pQNode;
484 if (pAd->TimerQ.pQHead == NULL)
485 pAd->TimerQ.pQHead = pQNode;
487 RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
490 up(&pAd->RTUSBTimer_semaphore);
491 //wake_up(&timerWaitQ);
495 RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
501 BOOLEAN RT2870_TimerQ_Remove(
502 IN RTMP_ADAPTER *pAd,
503 IN RALINK_TIMER_STRUCT *pTimer)
505 RT2870_TIMER_ENTRY *pNode, *pPrev = NULL;
506 unsigned long irqFlags;
508 RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
509 if (pAd->TimerQ.status >= RT2870_THREAD_INITED)
511 pNode = pAd->TimerQ.pQHead;
514 if (pNode->pRaTimer == pTimer)
517 pNode = pNode->pNext;
520 // Now move it to freeList queue.
523 if (pNode == pAd->TimerQ.pQHead)
524 pAd->TimerQ.pQHead = pNode->pNext;
525 if (pNode == pAd->TimerQ.pQTail)
526 pAd->TimerQ.pQTail = pPrev;
528 pPrev->pNext = pNode->pNext;
530 // return this queue entry to timerQFreeList.
531 pNode->pNext = pAd->TimerQ.pQPollFreeList;
532 pAd->TimerQ.pQPollFreeList = pNode;
535 RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
541 void RT2870_TimerQ_Exit(RTMP_ADAPTER *pAd)
543 RT2870_TIMER_ENTRY *pTimerQ;
544 unsigned long irqFlags;
546 RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
547 while (pAd->TimerQ.pQHead)
549 pTimerQ = pAd->TimerQ.pQHead;
550 pAd->TimerQ.pQHead = pTimerQ->pNext;
553 pAd->TimerQ.pQPollFreeList = NULL;
554 os_free_mem(pAd, pAd->TimerQ.pTimerQPoll);
555 pAd->TimerQ.pQTail = NULL;
556 pAd->TimerQ.pQHead = NULL;
557 pAd->TimerQ.status = RT2870_THREAD_STOPED;
558 RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
563 void RT2870_TimerQ_Init(RTMP_ADAPTER *pAd)
566 RT2870_TIMER_ENTRY *pQNode, *pEntry;
567 unsigned long irqFlags;
569 NdisAllocateSpinLock(&pAd->TimerQLock);
571 RTMP_IRQ_LOCK(&pAd->TimerQLock, irqFlags);
572 NdisZeroMemory(&pAd->TimerQ, sizeof(pAd->TimerQ));
573 //InterlockedExchange(&pAd->TimerQ.count, 0);
575 /* Initialise the wait q head */
576 //init_waitqueue_head(&timerWaitQ);
578 os_alloc_mem(pAd, &pAd->TimerQ.pTimerQPoll, sizeof(RT2870_TIMER_ENTRY) * TIMER_QUEUE_SIZE_MAX);
579 if (pAd->TimerQ.pTimerQPoll)
582 pQNode = (RT2870_TIMER_ENTRY *)pAd->TimerQ.pTimerQPoll;
583 for (i = 0 ;i <TIMER_QUEUE_SIZE_MAX; i++)
585 pQNode->pNext = pEntry;
589 pAd->TimerQ.pQPollFreeList = pEntry;
590 pAd->TimerQ.pQHead = NULL;
591 pAd->TimerQ.pQTail = NULL;
592 pAd->TimerQ.status = RT2870_THREAD_INITED;
594 RTMP_IRQ_UNLOCK(&pAd->TimerQLock, irqFlags);
598 VOID RT2870_WatchDog(IN RTMP_ADAPTER *pAd)
600 PHT_TX_CONTEXT pHTTXContext;
604 BOOLEAN needDumpSeq = FALSE;
609 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
610 if ((MACValue & 0xff) !=0 )
612 DBGPRINT(RT_DEBUG_TRACE, ("TX QUEUE 0 Not EMPTY(Value=0x%0x). !!!!!!!!!!!!!!!\n", MACValue));
613 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40012);
614 while((MACValue &0xff) != 0 && (idx++ < 10))
616 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
619 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006);
622 //PS packets use HCCA queue when dequeue from PS unicast queue (WiFi WPA2 MA9_DT1 for Marvell B STA)
624 if ((MACValue & 0xff00) !=0 )
626 DBGPRINT(RT_DEBUG_TRACE, ("TX QUEUE 1 Not EMPTY(Value=0x%0x). !!!!!!!!!!!!!!!\n", MACValue));
627 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf4000a);
628 while((MACValue &0xff00) != 0 && (idx++ < 10))
630 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
633 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006);
636 if (pAd->watchDogRxOverFlowCnt >= 2)
638 DBGPRINT(RT_DEBUG_TRACE, ("Maybe the Rx Bulk-In hanged! Cancel the pending Rx bulks request!\n"));
639 if ((!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
640 fRTMP_ADAPTER_BULKIN_RESET |
641 fRTMP_ADAPTER_HALT_IN_PROGRESS |
642 fRTMP_ADAPTER_NIC_NOT_EXIST))))
644 DBGPRINT(RT_DEBUG_TRACE, ("Call CMDTHREAD_RESET_BULK_IN to cancel the pending Rx Bulk!\n"));
645 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
646 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN, NULL, 0);
649 pAd->watchDogRxOverFlowCnt = 0;
653 for (idx = 0; idx < NUM_OF_TX_RING; idx++)
657 RTMP_IRQ_LOCK(&pAd->BulkOutLock[idx], irqFlags);
658 if ((pAd->BulkOutPending[idx] == TRUE) && pAd->watchDogTxPendingCnt)
660 pAd->watchDogTxPendingCnt[idx]++;
662 if ((pAd->watchDogTxPendingCnt[idx] > 2) &&
663 (!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_BULKOUT_RESET)))
666 // FIXME: Following code just support single bulk out. If you wanna support multiple bulk out. Modify it!
667 pHTTXContext = (PHT_TX_CONTEXT)(&pAd->TxContext[idx]);
668 if (pHTTXContext->IRPPending)
669 { // Check TxContext.
670 pUrb = pHTTXContext->pUrb;
672 else if (idx == MGMTPIPEIDX)
674 PTX_CONTEXT pMLMEContext, pNULLContext, pPsPollContext;
677 pMLMEContext = (PTX_CONTEXT)(pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa);
678 pPsPollContext = (PTX_CONTEXT)(&pAd->PsPollContext);
679 pNULLContext = (PTX_CONTEXT)(&pAd->NullContext);
681 if (pMLMEContext->IRPPending)
683 ASSERT(pMLMEContext->IRPPending);
684 pUrb = pMLMEContext->pUrb;
686 else if (pNULLContext->IRPPending)
688 ASSERT(pNULLContext->IRPPending);
689 pUrb = pNULLContext->pUrb;
691 else if (pPsPollContext->IRPPending)
693 ASSERT(pPsPollContext->IRPPending);
694 pUrb = pPsPollContext->pUrb;
698 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
700 DBGPRINT(RT_DEBUG_TRACE, ("Maybe the Tx Bulk-Out hanged! Cancel the pending Tx bulks request of idx(%d)!\n", idx));
703 DBGPRINT(RT_DEBUG_TRACE, ("Unlink the pending URB!\n"));
705 RTUSB_UNLINK_URB(pUrb);
706 // Sleep 200 microseconds to give cancellation time to work
712 DBGPRINT(RT_DEBUG_ERROR, ("Unkonw bulkOut URB maybe hanged!!!!!!!!!!!!\n"));
717 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
722 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
726 // For Sigma debug, dump the ba_reordering sequence.
727 if((needDumpSeq == TRUE) && (pAd->CommonCfg.bDisableReordering == 0))
730 PBA_REC_ENTRY pBAEntry = NULL;
732 struct reordering_mpdu *mpdu_blk;
734 Idx = pAd->MacTab.Content[BSSID_WCID].BARecWcidArray[0];
736 pBAEntry = &pAd->BATable.BARecEntry[Idx];
737 if((pBAEntry->list.qlen > 0) && (pBAEntry->list.next != NULL))
739 DBGPRINT(RT_DEBUG_TRACE, ("NICUpdateRawCounters():The Queueing pkt in reordering buffer:\n"));
740 NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
741 mpdu_blk = pBAEntry->list.next;
744 DBGPRINT(RT_DEBUG_TRACE, ("\t%d:Seq-%d, bAMSDU-%d!\n", count, mpdu_blk->Sequence, mpdu_blk->bAMSDU));
745 mpdu_blk = mpdu_blk->next;
749 DBGPRINT(RT_DEBUG_TRACE, ("\npBAEntry->LastIndSeq=%d!\n", pBAEntry->LastIndSeq));
750 NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
756 ========================================================================
758 Release allocated resources.
761 *dev Point to the PCI or USB device
762 pAd driver control block pointer
768 ========================================================================
770 static void _rtusb_disconnect(struct usb_device *dev, PRTMP_ADAPTER pAd)
772 struct net_device *net_dev = NULL;
775 DBGPRINT(RT_DEBUG_ERROR, ("rtusb_disconnect: unregister usbnet usb-%s-%s\n",
776 dev->bus->bus_name, dev->devpath));
781 printk("rtusb_disconnect: pAd == NULL!\n");
784 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
788 // for debug, wait to show some messages to /proc system
794 net_dev = pAd->net_dev;
795 if (pAd->net_dev != NULL)
797 printk("rtusb_disconnect: unregister_netdev(), dev->name=%s!\n", net_dev->name);
798 unregister_netdev (pAd->net_dev);
801 flush_scheduled_work();
804 // free net_device memory
805 free_netdev(net_dev);
807 // free adapter memory
808 RTMPFreeAdapter(pAd);
810 // release a use of the usb device structure
814 DBGPRINT(RT_DEBUG_ERROR, (" RTUSB disconnect successfully\n"));
819 ========================================================================
821 Probe RT28XX chipset.
824 *dev Point to the PCI or USB device
826 *id_table Point to the PCI or USB device ID
832 ========================================================================
834 static int rtusb_probe (struct usb_interface *intf,
835 const struct usb_device_id *id)
838 return (int)rt28xx_probe((void *)intf, (void *)id, 0, &pAd);
842 static void rtusb_disconnect(struct usb_interface *intf)
844 struct usb_device *dev = interface_to_usbdev(intf);
848 pAd = usb_get_intfdata(intf);
849 usb_set_intfdata(intf, NULL);
851 _rtusb_disconnect(dev, pAd);
856 ========================================================================
858 Close kernel threads.
861 *pAd the raxx interface data pointer
867 ========================================================================
869 VOID RT28xxThreadTerminate(
870 IN RTMP_ADAPTER *pAd)
872 POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;
876 // Sleep 50 milliseconds so pending io might finish normally
877 RTMPusecDelay(50000);
879 // We want to wait until all pending receives and sends to the
880 // device object. We cancel any
881 // irps. Wait until sends and receives have stopped.
882 RTUSBCancelPendingIRPs(pAd);
886 CHECK_PID_LEGALITY(pObj->TimerQThr_pid)
888 POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;
890 printk("Terminate the TimerQThr_pid=%d!\n", GET_PID_NUMBER(pObj->TimerQThr_pid));
892 pAd->TimerFunc_kill = 1;
894 ret = KILL_THREAD_PID(pObj->TimerQThr_pid, SIGTERM, 1);
897 printk(KERN_WARNING "%s: unable to stop TimerQThread, pid=%d, ret=%d!\n",
898 pAd->net_dev->name, GET_PID_NUMBER(pObj->TimerQThr_pid), ret);
902 wait_for_completion(&pAd->TimerQComplete);
903 pObj->TimerQThr_pid = THREAD_PID_INIT_VALUE;
907 CHECK_PID_LEGALITY(pObj->MLMEThr_pid)
909 printk("Terminate the MLMEThr_pid=%d!\n", GET_PID_NUMBER(pObj->MLMEThr_pid));
912 //RT28XX_MLME_HANDLER(pAd);
914 ret = KILL_THREAD_PID(pObj->MLMEThr_pid, SIGTERM, 1);
917 printk (KERN_WARNING "%s: unable to Mlme thread, pid=%d, ret=%d!\n",
918 pAd->net_dev->name, GET_PID_NUMBER(pObj->MLMEThr_pid), ret);
922 //wait_for_completion (&pAd->notify);
923 wait_for_completion (&pAd->mlmeComplete);
924 pObj->MLMEThr_pid = THREAD_PID_INIT_VALUE;
928 CHECK_PID_LEGALITY(pObj->RTUSBCmdThr_pid)
930 printk("Terminate the RTUSBCmdThr_pid=%d!\n", GET_PID_NUMBER(pObj->RTUSBCmdThr_pid));
932 NdisAcquireSpinLock(&pAd->CmdQLock);
933 pAd->CmdQ.CmdQState = RT2870_THREAD_STOPED;
934 NdisReleaseSpinLock(&pAd->CmdQLock);
937 ret = KILL_THREAD_PID(pObj->RTUSBCmdThr_pid, SIGTERM, 1);
940 printk(KERN_WARNING "%s: unable to RTUSBCmd thread, pid=%d, ret=%d!\n",
941 pAd->net_dev->name, GET_PID_NUMBER(pObj->RTUSBCmdThr_pid), ret);
945 //wait_for_completion (&pAd->notify);
946 wait_for_completion (&pAd->CmdQComplete);
947 pObj->RTUSBCmdThr_pid = THREAD_PID_INIT_VALUE;
952 if (pObj->MLMEThr_pid)
954 printk("Terminate the MLMEThr_pid=%d!\n", pid_nr(pObj->MLMEThr_pid));
957 //RT28XX_MLME_HANDLER(pAd);
959 ret = kill_pid(pObj->MLMEThr_pid, SIGTERM, 1);
962 printk (KERN_WARNING "%s: unable to Mlme thread, pid=%d, ret=%d!\n",
963 pAd->net_dev->name, pid_nr(pObj->MLMEThr_pid), ret);
967 //wait_for_completion (&pAd->notify);
968 wait_for_completion (&pAd->mlmeComplete);
969 pObj->MLMEThr_pid = NULL;
973 if (pObj->RTUSBCmdThr_pid >= 0)
975 printk("Terminate the RTUSBCmdThr_pid=%d!\n", pid_nr(pObj->RTUSBCmdThr_pid));
977 NdisAcquireSpinLock(&pAd->CmdQLock);
978 pAd->CmdQ.CmdQState = RT2870_THREAD_STOPED;
979 NdisReleaseSpinLock(&pAd->CmdQLock);
982 ret = kill_pid(pObj->RTUSBCmdThr_pid, SIGTERM, 1);
985 printk(KERN_WARNING "%s: unable to RTUSBCmd thread, pid=%d, ret=%d!\n",
986 pAd->net_dev->name, pid_nr(pObj->RTUSBCmdThr_pid), ret);
990 //wait_for_completion (&pAd->notify);
991 wait_for_completion (&pAd->CmdQComplete);
992 pObj->RTUSBCmdThr_pid = NULL;
995 if (pObj->TimerQThr_pid >= 0)
997 POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;
998 printk("Terminate the TimerQThr_pid=%d!\n", pid_nr(pObj->TimerQThr_pid));
1000 pAd->TimerFunc_kill = 1;
1002 ret = kill_pid(pObj->TimerQThr_pid, SIGTERM, 1);
1005 printk(KERN_WARNING "%s: unable to stop TimerQThread, pid=%d, ret=%d!\n",
1006 pAd->net_dev->name, pid_nr(pObj->TimerQThr_pid), ret);
1010 printk("wait_for_completion TimerQThr\n");
1011 wait_for_completion(&pAd->TimerQComplete);
1012 pObj->TimerQThr_pid = NULL;
1019 pAd->CmdQ.CmdQState = RT2870_THREAD_UNKNOWN;
1020 pAd->TimerFunc_kill = 0;
1024 void kill_thread_task(IN PRTMP_ADAPTER pAd)
1028 pObj = (POS_COOKIE) pAd->OS_Cookie;
1030 tasklet_kill(&pObj->rx_done_task);
1031 tasklet_kill(&pObj->mgmt_dma_done_task);
1032 tasklet_kill(&pObj->ac0_dma_done_task);
1033 tasklet_kill(&pObj->ac1_dma_done_task);
1034 tasklet_kill(&pObj->ac2_dma_done_task);
1035 tasklet_kill(&pObj->ac3_dma_done_task);
1036 tasklet_kill(&pObj->hcca_dma_done_task);
1037 tasklet_kill(&pObj->tbtt_task);
1043 ========================================================================
1044 Routine Description:
1045 Check the chipset vendor/product ID.
1048 _dev_p Point to the PCI or USB device
1055 ========================================================================
1057 BOOLEAN RT28XXChipsetCheck(
1060 struct usb_interface *intf = (struct usb_interface *)_dev_p;
1061 struct usb_device *dev_p = interface_to_usbdev(intf);
1065 for(i=0; i<rtusb_usb_id_len; i++)
1067 if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor &&
1068 dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct)
1071 printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
1074 printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
1076 dev_p->descriptor.idVendor, dev_p->descriptor.idProduct);
1081 if (i == rtusb_usb_id_len)
1083 printk("rt2870: Error! Device Descriptor not matching!\n");
1092 ========================================================================
1093 Routine Description:
1094 Init net device structure.
1097 _dev_p Point to the PCI or USB device
1098 *net_dev Point to the net device
1099 *pAd the raxx interface data pointer
1106 ========================================================================
1108 BOOLEAN RT28XXNetDevInit(
1110 IN struct net_device *net_dev,
1111 IN RTMP_ADAPTER *pAd)
1113 struct usb_interface *intf = (struct usb_interface *)_dev_p;
1114 struct usb_device *dev_p = interface_to_usbdev(intf);
1117 pAd->config = &dev_p->config->desc;
1123 ========================================================================
1124 Routine Description:
1125 Init net device structure.
1128 _dev_p Point to the PCI or USB device
1129 *pAd the raxx interface data pointer
1136 ========================================================================
1138 BOOLEAN RT28XXProbePostConfig(
1140 IN RTMP_ADAPTER *pAd,
1143 struct usb_interface *intf = (struct usb_interface *)_dev_p;
1144 struct usb_host_interface *iface_desc;
1149 /* get the active interface descriptor */
1150 iface_desc = intf->cur_altsetting;
1152 /* get # of enpoints */
1153 pAd->NumberOfPipes = iface_desc->desc.bNumEndpoints;
1154 DBGPRINT(RT_DEBUG_TRACE,
1155 ("NumEndpoints=%d\n", iface_desc->desc.bNumEndpoints));
1157 /* Configure Pipes */
1160 for(i=0; i<pAd->NumberOfPipes; i++)
1162 if ((iface_desc->endpoint[i].desc.bmAttributes ==
1163 USB_ENDPOINT_XFER_BULK) &&
1164 ((iface_desc->endpoint[i].desc.bEndpointAddress &
1165 USB_ENDPOINT_DIR_MASK) == USB_DIR_IN))
1167 pAd->BulkInEpAddr = iface_desc->endpoint[i].desc.bEndpointAddress;
1168 pAd->BulkInMaxPacketSize = iface_desc->endpoint[i].desc.wMaxPacketSize;
1170 DBGPRINT_RAW(RT_DEBUG_TRACE,
1171 ("BULK IN MaximumPacketSize = %d\n", pAd->BulkInMaxPacketSize));
1172 DBGPRINT_RAW(RT_DEBUG_TRACE,
1173 ("EP address = 0x%2x\n", iface_desc->endpoint[i].desc.bEndpointAddress));
1175 else if ((iface_desc->endpoint[i].desc.bmAttributes ==
1176 USB_ENDPOINT_XFER_BULK) &&
1177 ((iface_desc->endpoint[i].desc.bEndpointAddress &
1178 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT))
1180 // there are 6 bulk out EP. EP6 highest priority.
1181 // EP1-4 is EDCA. EP5 is HCCA.
1182 pAd->BulkOutEpAddr[BulkOutIdx++] = iface_desc->endpoint[i].desc.bEndpointAddress;
1183 pAd->BulkOutMaxPacketSize = iface_desc->endpoint[i].desc.wMaxPacketSize;
1185 DBGPRINT_RAW(RT_DEBUG_TRACE,
1186 ("BULK OUT MaximumPacketSize = %d\n", pAd->BulkOutMaxPacketSize));
1187 DBGPRINT_RAW(RT_DEBUG_TRACE,
1188 ("EP address = 0x%2x \n", iface_desc->endpoint[i].desc.bEndpointAddress));
1192 if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0]))
1194 printk("%s: Could not find both bulk-in and bulk-out endpoints\n", __func__);
1203 ========================================================================
1204 Routine Description:
1208 *pAd the raxx interface data pointer
1214 ========================================================================
1216 VOID RT28XXDMADisable(
1217 IN RTMP_ADAPTER *pAd)
1225 ========================================================================
1226 Routine Description:
1230 *pAd the raxx interface data pointer
1236 ========================================================================
1238 VOID RT28XXDMAEnable(
1239 IN RTMP_ADAPTER *pAd)
1241 WPDMA_GLO_CFG_STRUC GloCfg;
1242 USB_DMA_CFG_STRUC UsbCfg;
1246 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4);
1249 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1250 if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0))
1253 DBGPRINT(RT_DEBUG_TRACE, ("==> DMABusy\n"));
1254 RTMPusecDelay(1000);
1260 GloCfg.field.EnTXWriteBackDDONE = 1;
1261 GloCfg.field.EnableRxDMA = 1;
1262 GloCfg.field.EnableTxDMA = 1;
1263 DBGPRINT(RT_DEBUG_TRACE, ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word));
1264 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1267 UsbCfg.field.phyclear = 0;
1268 /* usb version is 1.1,do not use bulk in aggregation */
1269 if (pAd->BulkInMaxPacketSize == 512)
1270 UsbCfg.field.RxBulkAggEn = 1;
1271 /* for last packet, PBF might use more than limited, so minus 2 to prevent from error */
1272 UsbCfg.field.RxBulkAggLmt = (MAX_RXBULK_SIZE /1024)-3;
1273 UsbCfg.field.RxBulkAggTOut = 0x80; /* 2006-10-18 */
1274 UsbCfg.field.RxBulkEn = 1;
1275 UsbCfg.field.TxBulkEn = 1;
1277 RTUSBWriteMACRegister(pAd, USB_DMA_CFG, UsbCfg.word);
1282 ========================================================================
1283 Routine Description:
1284 Write Beacon buffer to Asic.
1287 *pAd the raxx interface data pointer
1293 ========================================================================
1295 VOID RT28xx_UpdateBeaconToAsic(
1296 IN RTMP_ADAPTER *pAd,
1301 PUCHAR pBeaconFrame = NULL;
1304 BEACON_SYNC_STRUCT *pBeaconSync = pAd->CommonCfg.pBeaconSync;
1306 BOOLEAN bBcnReq = FALSE;
1310 if (pBeaconFrame == NULL)
1312 DBGPRINT(RT_DEBUG_ERROR,("pBeaconFrame is NULL!\n"));
1316 if (pBeaconSync == NULL)
1318 DBGPRINT(RT_DEBUG_ERROR,("pBeaconSync is NULL!\n"));
1322 //if ((pAd->WdsTab.Mode == WDS_BRIDGE_MODE) ||
1323 // ((pAd->ApCfg.MBSSID[apidx].MSSIDDev == NULL) || !(pAd->ApCfg.MBSSID[apidx].MSSIDDev->flags & IFF_UP))
1325 if (bBcnReq == FALSE)
1327 /* when the ra interface is down, do not send its beacon frame */
1328 /* clear all zero */
1329 for(i=0; i<TXWI_SIZE; i+=4) {
1330 RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, 0x00);
1332 pBeaconSync->BeaconBitMap &= (~(BEACON_BITMAP_MASK & (1 << bcn_idx)));
1333 NdisZeroMemory(pBeaconSync->BeaconTxWI[bcn_idx], TXWI_SIZE);
1337 ptr = (PUCHAR)&pAd->BeaconTxWI;
1339 if (NdisEqualMemory(pBeaconSync->BeaconTxWI[bcn_idx], &pAd->BeaconTxWI, TXWI_SIZE) == FALSE)
1340 { // If BeaconTxWI changed, we need to rewrite the TxWI for the Beacon frames.
1341 pBeaconSync->BeaconBitMap &= (~(BEACON_BITMAP_MASK & (1 << bcn_idx)));
1342 NdisMoveMemory(pBeaconSync->BeaconTxWI[bcn_idx], &pAd->BeaconTxWI, TXWI_SIZE);
1345 if ((pBeaconSync->BeaconBitMap & (1 << bcn_idx)) != (1 << bcn_idx))
1347 for (i=0; i<TXWI_SIZE; i+=4) // 16-byte TXWI field
1349 longValue = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);
1350 RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, longValue);
1355 ptr = pBeaconSync->BeaconBuf[bcn_idx];
1356 padding = (FrameLen & 0x01);
1357 NdisZeroMemory((PUCHAR)(pBeaconFrame + FrameLen), padding);
1358 FrameLen += padding;
1359 for (i = 0 ; i < FrameLen /*HW_BEACON_OFFSET*/; i += 2)
1361 if (NdisEqualMemory(ptr, pBeaconFrame, 2) == FALSE)
1363 NdisMoveMemory(ptr, pBeaconFrame, 2);
1364 //shortValue = *ptr + (*(ptr+1)<<8);
1365 //RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, shortValue);
1366 RTUSBMultiWrite(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, ptr, 2);
1372 pBeaconSync->BeaconBitMap |= (1 << bcn_idx);
1374 // For AP interface, set the DtimBitOn so that we can send Bcast/Mcast frame out after this beacon frame.
1380 VOID RT2870_BssBeaconStop(
1381 IN RTMP_ADAPTER *pAd)
1383 BEACON_SYNC_STRUCT *pBeaconSync;
1385 BOOLEAN Cancelled = TRUE;
1387 pBeaconSync = pAd->CommonCfg.pBeaconSync;
1388 if (pBeaconSync && pBeaconSync->EnableBeacon)
1392 NumOfBcn = MAX_MESH_NUM;
1394 RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled);
1396 for(i=0; i<NumOfBcn; i++)
1398 NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);
1399 NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
1401 for (offset=0; offset<HW_BEACON_OFFSET; offset+=4)
1402 RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[i] + offset, 0x00);
1404 pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
1405 pBeaconSync->TimIELocationInBeacon[i] = 0;
1407 pBeaconSync->BeaconBitMap = 0;
1408 pBeaconSync->DtimBitOn = 0;
1413 VOID RT2870_BssBeaconStart(
1414 IN RTMP_ADAPTER *pAd)
1417 BEACON_SYNC_STRUCT *pBeaconSync;
1418 // LARGE_INTEGER tsfTime, deltaTime;
1420 pBeaconSync = pAd->CommonCfg.pBeaconSync;
1421 if (pBeaconSync && pBeaconSync->EnableBeacon)
1425 NumOfBcn = MAX_MESH_NUM;
1427 for(apidx=0; apidx<NumOfBcn; apidx++)
1429 UCHAR CapabilityInfoLocationInBeacon = 0;
1430 UCHAR TimIELocationInBeacon = 0;
1432 NdisZeroMemory(pBeaconSync->BeaconBuf[apidx], HW_BEACON_OFFSET);
1433 pBeaconSync->CapabilityInfoLocationInBeacon[apidx] = CapabilityInfoLocationInBeacon;
1434 pBeaconSync->TimIELocationInBeacon[apidx] = TimIELocationInBeacon;
1435 NdisZeroMemory(pBeaconSync->BeaconTxWI[apidx], TXWI_SIZE);
1437 pBeaconSync->BeaconBitMap = 0;
1438 pBeaconSync->DtimBitOn = 0;
1439 pAd->CommonCfg.BeaconUpdateTimer.Repeat = TRUE;
1441 pAd->CommonCfg.BeaconAdjust = 0;
1442 pAd->CommonCfg.BeaconFactor = 0xffffffff / (pAd->CommonCfg.BeaconPeriod << 10);
1443 pAd->CommonCfg.BeaconRemain = (0xffffffff % (pAd->CommonCfg.BeaconPeriod << 10)) + 1;
1444 printk(RT28xx_CHIP_NAME "_BssBeaconStart:BeaconFactor=%d, BeaconRemain=%d!\n", pAd->CommonCfg.BeaconFactor, pAd->CommonCfg.BeaconRemain);
1445 RTMPSetTimer(&pAd->CommonCfg.BeaconUpdateTimer, pAd->CommonCfg.BeaconPeriod);
1451 VOID RT2870_BssBeaconInit(
1452 IN RTMP_ADAPTER *pAd)
1454 BEACON_SYNC_STRUCT *pBeaconSync;
1457 NdisAllocMemory(pAd->CommonCfg.pBeaconSync, sizeof(BEACON_SYNC_STRUCT), MEM_ALLOC_FLAG);
1458 if (pAd->CommonCfg.pBeaconSync)
1460 pBeaconSync = pAd->CommonCfg.pBeaconSync;
1461 NdisZeroMemory(pBeaconSync, sizeof(BEACON_SYNC_STRUCT));
1462 for(i=0; i < HW_BEACON_MAX_COUNT; i++)
1464 NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);
1465 pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
1466 pBeaconSync->TimIELocationInBeacon[i] = 0;
1467 NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
1469 pBeaconSync->BeaconBitMap = 0;
1471 //RTMPInitTimer(pAd, &pAd->CommonCfg.BeaconUpdateTimer, GET_TIMER_FUNCTION(BeaconUpdateExec), pAd, TRUE);
1472 pBeaconSync->EnableBeacon = TRUE;
1477 VOID RT2870_BssBeaconExit(
1478 IN RTMP_ADAPTER *pAd)
1480 BEACON_SYNC_STRUCT *pBeaconSync;
1481 BOOLEAN Cancelled = TRUE;
1484 if (pAd->CommonCfg.pBeaconSync)
1486 pBeaconSync = pAd->CommonCfg.pBeaconSync;
1487 pBeaconSync->EnableBeacon = FALSE;
1488 RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled);
1489 pBeaconSync->BeaconBitMap = 0;
1491 for(i=0; i<HW_BEACON_MAX_COUNT; i++)
1493 NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);
1494 pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
1495 pBeaconSync->TimIELocationInBeacon[i] = 0;
1496 NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
1499 NdisFreeMemory(pAd->CommonCfg.pBeaconSync, HW_BEACON_OFFSET * HW_BEACON_MAX_COUNT, 0);
1500 pAd->CommonCfg.pBeaconSync = NULL;
1504 VOID BeaconUpdateExec(
1505 IN PVOID SystemSpecific1,
1506 IN PVOID FunctionContext,
1507 IN PVOID SystemSpecific2,
1508 IN PVOID SystemSpecific3)
1510 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)FunctionContext;
1511 LARGE_INTEGER tsfTime_a;//, tsfTime_b, deltaTime_exp, deltaTime_ab;
1512 UINT32 delta, remain, remain_low, remain_high;
1513 // BOOLEAN positive;
1515 ReSyncBeaconTime(pAd);
1519 RTMP_IO_READ32(pAd, TSF_TIMER_DW0, &tsfTime_a.u.LowPart);
1520 RTMP_IO_READ32(pAd, TSF_TIMER_DW1, &tsfTime_a.u.HighPart);
1523 //positive=getDeltaTime(tsfTime_a, expectedTime, &deltaTime_exp);
1524 remain_high = pAd->CommonCfg.BeaconRemain * tsfTime_a.u.HighPart;
1525 remain_low = tsfTime_a.u.LowPart % (pAd->CommonCfg.BeaconPeriod << 10);
1526 remain = (remain_high + remain_low)%(pAd->CommonCfg.BeaconPeriod << 10);
1527 delta = (pAd->CommonCfg.BeaconPeriod << 10) - remain;
1529 pAd->CommonCfg.BeaconUpdateTimer.TimerValue = (delta >> 10) + 10;