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 Create and register network interface.
35 -------- ---------- ----------------------------------------------
36 Sample Mar/21/07 Merge RT2870 and RT2860 drivers.
39 #include "rt_config.h"
41 #define FORTY_MHZ_INTOLERANT_INTERVAL (60*1000) // 1 min
43 #ifdef MULTIPLE_CARD_SUPPORT
44 // record whether the card in the card list is used in the card file
45 UINT8 MC_CardUsed[MAX_NUM_OF_MULTIPLE_CARD];
46 // record used card mac address in the card list
47 static UINT8 MC_CardMac[MAX_NUM_OF_MULTIPLE_CARD][6];
48 #endif // MULTIPLE_CARD_SUPPORT //
50 #ifdef CONFIG_APSTA_MIXED_SUPPORT
51 UINT32 CW_MAX_IN_BITS;
52 #endif // CONFIG_APSTA_MIXED_SUPPORT //
54 /*---------------------------------------------------------------------*/
55 /* Private Variables Used */
56 /*---------------------------------------------------------------------*/
57 //static RALINK_TIMER_STRUCT PeriodicTimer;
59 char *mac = ""; // default 00:00:00:00:00:00
60 char *hostname = ""; // default CMPC
61 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)
62 MODULE_PARM (mac, "s");
64 module_param (mac, charp, 0);
66 MODULE_PARM_DESC (mac, "rt28xx: wireless mac addr");
69 /*---------------------------------------------------------------------*/
70 /* Prototypes of Functions Used */
71 /*---------------------------------------------------------------------*/
72 #ifdef DOT11_N_SUPPORT
73 extern BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
74 extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
75 #endif // DOT11_N_SUPPORT //
76 extern NDIS_STATUS NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd);
79 extern void init_thread_task(PRTMP_ADAPTER pAd);
82 // public function prototype
83 INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
84 IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
86 // private function prototype
87 static int rt28xx_init(IN struct net_device *net_dev);
88 INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);
90 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
91 struct net_device *alloc_netdev(
94 void (*setup)(struct net_device *));
95 #endif // LINUX_VERSION_CODE //
97 static void CfgInitHook(PRTMP_ADAPTER pAd);
99 #ifdef CONFIG_STA_SUPPORT
100 extern const struct iw_handler_def rt28xx_iw_handler_def;
101 #endif // CONFIG_STA_SUPPORT //
103 #ifdef CONFIG_APSTA_MIXED_SUPPORT
104 extern const struct iw_handler_def rt28xx_ap_iw_handler_def;
105 #endif // CONFIG_APSTA_MIXED_SUPPORT //
107 #if WIRELESS_EXT >= 12
108 // This function will be called when query /proc
109 struct iw_statistics *rt28xx_get_wireless_stats(
110 IN struct net_device *net_dev);
113 struct net_device_stats *RT28xx_get_ether_stats(
114 IN struct net_device *net_dev);
117 ========================================================================
119 Close raxx interface.
122 *net_dev the raxx interface pointer
129 1. if open fail, kernel will not call the close function.
131 (1) Mlme Memory Handler: MlmeHalt()
132 (2) TX & RX: RTMPFreeTxRxRingMemory()
133 (3) BA Reordering: ba_reordering_resource_release()
134 ========================================================================
136 int MainVirtualIF_close(IN struct net_device *net_dev)
138 RTMP_ADAPTER *pAd = net_dev->ml_priv;
140 // Sanity check for pAd
142 return 0; // close ok
144 netif_carrier_off(pAd->net_dev);
145 netif_stop_queue(pAd->net_dev);
148 VIRTUAL_IF_DOWN(pAd);
150 RT_MOD_DEC_USE_COUNT();
152 return 0; // close ok
156 ========================================================================
161 *net_dev the raxx interface pointer
168 1. if open fail, kernel will not call the close function.
170 (1) Mlme Memory Handler: MlmeHalt()
171 (2) TX & RX: RTMPFreeTxRxRingMemory()
172 (3) BA Reordering: ba_reordering_resource_release()
173 ========================================================================
175 int MainVirtualIF_open(IN struct net_device *net_dev)
177 RTMP_ADAPTER *pAd = net_dev->ml_priv;
179 // Sanity check for pAd
181 return 0; // close ok
183 if (VIRTUAL_IF_UP(pAd) != 0)
186 // increase MODULE use count
187 RT_MOD_INC_USE_COUNT();
189 netif_start_queue(net_dev);
190 netif_carrier_on(net_dev);
191 netif_wake_queue(net_dev);
197 ========================================================================
199 Close raxx interface.
202 *net_dev the raxx interface pointer
209 1. if open fail, kernel will not call the close function.
211 (1) Mlme Memory Handler: MlmeHalt()
212 (2) TX & RX: RTMPFreeTxRxRingMemory()
213 (3) BA Reordering: ba_reordering_resource_release()
214 ========================================================================
216 int rt28xx_close(IN PNET_DEV dev)
218 struct net_device * net_dev = (struct net_device *)dev;
219 RTMP_ADAPTER *pAd = net_dev->ml_priv;
220 BOOLEAN Cancelled = FALSE;
224 DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
226 // Sanity check for pAd
228 return 0; // close ok
233 #endif // WDS_SUPPORT //
235 #ifdef CONFIG_STA_SUPPORT
236 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
239 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_CLOSE);
242 // If dirver doesn't wake up firmware here,
243 // NICLoadFirmware will hang forever when interface is up again.
244 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
246 AsicForceWakeup(pAd, TRUE);
249 #ifdef QOS_DLS_SUPPORT
250 // send DLS-TEAR_DOWN message,
251 if (pAd->CommonCfg.bDLSCapable)
255 // tear down local dls table entry
256 for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
258 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
260 RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
261 pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
262 pAd->StaCfg.DLSEntry[i].Valid = FALSE;
266 // tear down peer dls table entry
267 for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
269 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
271 RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
272 pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
273 pAd->StaCfg.DLSEntry[i].Valid = FALSE;
276 RT28XX_MLME_HANDLER(pAd);
278 #endif // QOS_DLS_SUPPORT //
281 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
283 MLME_DISASSOC_REQ_STRUCT DisReq;
284 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
286 COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
287 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
289 MsgElem->Machine = ASSOC_STATE_MACHINE;
290 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
291 MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
292 NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
294 // Prevent to connect AP again in STAMlmePeriodicExec
295 pAd->MlmeAux.AutoReconnectSsidLen= 32;
296 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
298 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
299 MlmeDisassocReqAction(pAd, MsgElem);
307 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
310 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
311 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
313 #ifdef WPA_SUPPLICANT_SUPPORT
314 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
316 union iwreq_data wrqu;
317 // send wireless event to wpa_supplicant for infroming interface down.
318 memset(&wrqu, 0, sizeof(wrqu));
319 wrqu.data.flags = RT_INTERFACE_DOWN;
320 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
322 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
323 #endif // WPA_SUPPLICANT_SUPPORT //
327 pAd->bPCIclkOff = FALSE;
330 #endif // CONFIG_STA_SUPPORT //
332 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
334 for (i = 0 ; i < NUM_OF_TX_RING; i++)
336 while (pAd->DeQueueRunning[i] == TRUE)
338 printk("Waiting for TxQueue[%d] done..........\n", i);
343 // Stop Mlme state machine
346 // Close kernel threads or tasklets
347 kill_thread_task(pAd);
350 #ifdef CONFIG_STA_SUPPORT
351 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
355 #endif // CONFIG_STA_SUPPORT //
358 MeasureReqTabExit(pAd);
363 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
365 NICDisableInterrupt(pAd);
368 // Disable Rx, register value supposed will remain after reset
372 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
374 // Deregister interrupt function
375 RT28XX_IRQ_RELEASE(net_dev)
376 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
381 // Free Ring or USB buffers
382 RTMPFreeTxRxRingMemory(pAd);
384 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
386 #ifdef DOT11_N_SUPPORT
387 // Free BA reorder resource
388 ba_reordering_resource_release(pAd);
389 #endif // DOT11_N_SUPPORT //
392 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
394 return 0; // close ok
395 } /* End of rt28xx_close */
397 static int rt28xx_init(IN struct net_device *net_dev)
399 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)net_dev->ml_priv;
406 #ifdef DOT11_N_SUPPORT
407 // Allocate BA Reordering memory
408 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
409 #endif // DOT11_N_SUPPORT //
411 // Make sure MAC gets ready.
415 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
416 pAd->MACVersion = MacCsr0;
418 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
422 } while (index++ < 100);
424 DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
427 RT28XXDMADisable(pAd);
430 // Load 8051 firmware
431 Status = NICLoadFirmware(pAd);
432 if (Status != NDIS_STATUS_SUCCESS)
434 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
438 NICLoadRateSwitchingParams(pAd);
440 // Disable interrupts here which is as soon as possible
441 // This statement should never be true. We might consider to remove it later
443 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
445 NICDisableInterrupt(pAd);
449 Status = RTMPAllocTxRxRingMemory(pAd);
450 if (Status != NDIS_STATUS_SUCCESS)
452 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
456 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
461 Status = MlmeInit(pAd);
462 if (Status != NDIS_STATUS_SUCCESS)
464 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
468 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
473 RT28XX_TASK_THREAD_INIT(pAd, Status);
474 if (Status != NDIS_STATUS_SUCCESS)
481 initblockQueueTab(pAd);
482 #endif // BLOCK_NET_IF //
484 #ifdef CONFIG_STA_SUPPORT
485 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
486 NdisAllocateSpinLock(&pAd->MacTabLock);
487 #endif // CONFIG_STA_SUPPORT //
489 MeasureReqTabInit(pAd);
493 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
495 Status = NICInitializeAdapter(pAd, TRUE);
496 if (Status != NDIS_STATUS_SUCCESS)
498 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
499 if (Status != NDIS_STATUS_SUCCESS)
503 // Read parameters from Config File
504 Status = RTMPReadParametersHook(pAd);
506 printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
507 if (Status != NDIS_STATUS_SUCCESS)
509 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
515 //Init Ba Capability parameters.
516 #ifdef DOT11_N_SUPPORT
517 pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
518 pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
519 pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
520 pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
522 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
523 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
524 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
525 #endif // DOT11_N_SUPPORT //
527 printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
529 // We should read EEPROM for all cases. rt2860b
530 NICReadEEPROMParameters(pAd, mac);
532 printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
534 NICInitAsicFromEEPROM(pAd); //rt2860b
536 // Set PHY to appropriate mode
537 TmpPhy = pAd->CommonCfg.PhyMode;
538 pAd->CommonCfg.PhyMode = 0xff;
539 RTMPSetPhyMode(pAd, TmpPhy);
540 #ifdef DOT11_N_SUPPORT
542 #endif // DOT11_N_SUPPORT //
544 // No valid channels.
545 if (pAd->ChannelListNum == 0)
547 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
551 #ifdef DOT11_N_SUPPORT
552 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
553 pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
554 pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
555 #endif // DOT11_N_SUPPORT //
558 VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
559 #endif // IKANOS_VX_1X0 //
562 // Initialize RF register to default value
564 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
565 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
567 // 8051 firmware require the signal during booting time.
568 AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00);
570 if (pAd && (Status != NDIS_STATUS_SUCCESS))
573 // Undo everything if it failed
575 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
577 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
582 // Microsoft HCT require driver send a disconnect event after driver initialization.
583 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
584 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
585 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
591 DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
600 RTMPFreeTxRxRingMemory(pAd);
603 #ifdef DOT11_N_SUPPORT
604 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
605 #endif // DOT11_N_SUPPORT //
606 RT28XX_IRQ_RELEASE(net_dev);
608 // shall not set ml_priv to NULL here because the ml_priv didn't been free yet.
609 //net_dev->ml_priv = 0;
612 #endif // INF_AMAZON_SE //
613 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
615 } /* End of rt28xx_init */
619 ========================================================================
624 *net_dev the raxx interface pointer
631 ========================================================================
633 int rt28xx_open(IN PNET_DEV dev)
635 struct net_device * net_dev = (struct net_device *)dev;
636 PRTMP_ADAPTER pAd = net_dev->ml_priv;
641 // Sanity check for pAd
644 /* if 1st open fail, pAd will be free;
645 So the net_dev->ml_priv will be NULL in 2rd open */
649 #ifdef CONFIG_APSTA_MIXED_SUPPORT
650 if (pAd->OpMode == OPMODE_AP)
654 else if (pAd->OpMode == OPMODE_STA)
659 #if WIRELESS_EXT >= 12
660 if (net_dev->priv_flags == INT_MAIN)
662 if (pAd->OpMode == OPMODE_AP)
663 net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_ap_iw_handler_def;
664 else if (pAd->OpMode == OPMODE_STA)
665 net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_iw_handler_def;
667 #endif // WIRELESS_EXT >= 12 //
668 #endif // CONFIG_APSTA_MIXED_SUPPORT //
670 #ifdef CONFIG_STA_SUPPORT
672 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
674 // If dirver doesn't wake up firmware here,
675 // NICLoadFirmware will hang forever when interface is up again.
677 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) &&
678 OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE))
680 AUTO_WAKEUP_STRUC AutoWakeupCfg;
681 AsicForceWakeup(pAd, TRUE);
682 AutoWakeupCfg.word = 0;
683 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
684 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
688 #endif // CONFIG_STA_SUPPORT //
691 pObj = (POS_COOKIE)pAd->OS_Cookie;
693 // reset Adapter flags
694 RTMP_CLEAR_FLAGS(pAd);
696 // Request interrupt service routine for PCI device
697 // register the interrupt routine with the os
698 RT28XX_IRQ_REQUEST(net_dev);
701 // Init BssTab & ChannelInfo tabbles for auto channel select.
705 if (rt28xx_init(net_dev) == FALSE)
708 #ifdef CONFIG_STA_SUPPORT
709 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
711 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
712 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
714 #endif // CONFIG_STA_SUPPORT //
716 // Set up the Mac address
717 NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
719 // Init IRQ parameters
720 RT28XX_IRQ_INIT(pAd);
722 // Various AP function init
724 #ifdef CONFIG_STA_SUPPORT
725 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
727 #ifdef WPA_SUPPLICANT_SUPPORT
728 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
730 union iwreq_data wrqu;
731 // send wireless event to wpa_supplicant for infroming interface down.
732 memset(&wrqu, 0, sizeof(wrqu));
733 wrqu.data.flags = RT_INTERFACE_UP;
734 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
736 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
737 #endif // WPA_SUPPLICANT_SUPPORT //
740 #endif // CONFIG_STA_SUPPORT //
743 RT28XX_IRQ_ENABLE(pAd);
747 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
751 RTMP_IO_READ32(pAd, 0x1300, ®); // clear garbage interrupts
752 printk("0x1300 = %08x\n", reg);
755 #ifdef CONFIG_STA_SUPPORT
757 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
758 RTMPInitPCIeLinkCtrlValue(pAd);
760 #endif // CONFIG_STA_SUPPORT //
766 } /* End of rt28xx_open */
769 /* Must not be called for mdev and apdev */
770 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
774 CHAR slot_name[IFNAMSIZ];
775 struct net_device *device;
779 dev->hard_start_xmit = rt28xx_send_packets;
782 dev->hard_start_xmit = IKANOS_DataFramesTx;
783 #endif // IKANOS_VX_1X0 //
785 #ifdef CONFIG_STA_SUPPORT
786 #if WIRELESS_EXT >= 12
787 if (pAd->OpMode == OPMODE_STA)
789 dev->wireless_handlers = &rt28xx_iw_handler_def;
791 #endif //WIRELESS_EXT >= 12
792 #endif // CONFIG_STA_SUPPORT //
794 #ifdef CONFIG_APSTA_MIXED_SUPPORT
795 #if WIRELESS_EXT >= 12
796 if (pAd->OpMode == OPMODE_AP)
798 dev->wireless_handlers = &rt28xx_ap_iw_handler_def;
800 #endif //WIRELESS_EXT >= 12
801 #endif // CONFIG_APSTA_MIXED_SUPPORT //
803 #if WIRELESS_EXT < 21
804 dev->get_wireless_stats = rt28xx_get_wireless_stats;
806 dev->get_stats = RT28xx_get_ether_stats;
807 dev->open = MainVirtualIF_open; //rt28xx_open;
808 dev->stop = MainVirtualIF_close; //rt28xx_close;
809 dev->priv_flags = INT_MAIN;
810 dev->do_ioctl = rt28xx_ioctl;
811 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
812 dev->validate_addr = NULL;
814 // find available device name
815 for (i = 0; i < 8; i++)
817 #ifdef MULTIPLE_CARD_SUPPORT
818 if (pAd->MC_RowID >= 0)
819 sprintf(slot_name, "ra%02d_%d", pAd->MC_RowID, i);
821 #endif // MULTIPLE_CARD_SUPPORT //
822 sprintf(slot_name, "ra%d", i);
824 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
825 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
826 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
827 device = dev_get_by_name(dev_net(dev), slot_name);
829 device = dev_get_by_name(dev->nd_net, slot_name);
832 device = dev_get_by_name(slot_name);
834 if (device != NULL) dev_put(device);
836 for (device = dev_base; device != NULL; device = device->next)
838 if (strncmp(device->name, slot_name, 4) == 0)
848 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
849 Status = NDIS_STATUS_FAILURE;
853 #ifdef MULTIPLE_CARD_SUPPORT
854 if (pAd->MC_RowID >= 0)
855 sprintf(dev->name, "ra%02d_%d", pAd->MC_RowID, i);
857 #endif // MULTIPLE_CARD_SUPPORT //
858 sprintf(dev->name, "ra%d", i);
859 Status = NDIS_STATUS_SUCCESS;
867 #ifdef MULTIPLE_CARD_SUPPORT
869 ========================================================================
871 Get card profile path.
877 TRUE - Find a card profile
878 FALSE - use default profile
881 ========================================================================
883 extern INT RTMPGetKeyParameter(
889 BOOLEAN RTMP_CardInfoRead(
890 IN PRTMP_ADAPTER pAd)
892 #define MC_SELECT_CARDID 0 /* use CARD ID (0 ~ 31) to identify different cards */
893 #define MC_SELECT_MAC 1 /* use CARD MAC to identify different cards */
894 #define MC_SELECT_CARDTYPE 2 /* use CARD type (abgn or bgn) to identify different cards */
896 #define LETTER_CASE_TRANSLATE(txt_p, card_id) \
897 { UINT32 _len; char _char; \
898 for(_len=0; _len<strlen(card_id); _len++) { \
899 _char = *(txt_p + _len); \
900 if (('A' <= _char) && (_char <= 'Z')) \
901 *(txt_p+_len) = 'a'+(_char-'A'); \
905 INT retval, orgfsuid, orgfsgid;
907 CHAR *buffer, *tmpbuf, card_id_buf[30], RFIC_word[30];
908 BOOLEAN flg_match_ok = FALSE;
909 INT32 card_select_method;
910 INT32 card_free_id, card_nouse_id, card_same_mac_id, card_match_id;
911 EEPROM_ANTENNA_STRUC antenna;
912 USHORT addr01, addr23, addr45;
914 UINT32 data, card_index;
919 buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
923 tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
927 return NDIS_STATUS_FAILURE;
930 orgfsuid = current->fsuid;
931 orgfsgid = current->fsgid;
932 current->fsuid = current->fsgid = 0;
937 RTMP_IO_READ32(pAd, E2PROM_CSR, &data);
939 if ((data & 0x30) == 0)
940 pAd->EEPROMAddressNum = 6; // 93C46
941 else if ((data & 0x30) == 0x10)
942 pAd->EEPROMAddressNum = 8; // 93C66
944 pAd->EEPROMAddressNum = 8; // 93C86
946 RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, antenna.word);
948 if ((antenna.field.RfIcType == RFIC_2850) ||
949 (antenna.field.RfIcType == RFIC_2750))
952 strcpy(RFIC_word, "abgn");
957 strcpy(RFIC_word, "bgn");
961 RT28xx_EEPROM_READ16(pAd, 0x04, addr01);
962 RT28xx_EEPROM_READ16(pAd, 0x06, addr23);
963 RT28xx_EEPROM_READ16(pAd, 0x08, addr45);
965 mac[0] = (UCHAR)(addr01 & 0xff);
966 mac[1] = (UCHAR)(addr01 >> 8);
967 mac[2] = (UCHAR)(addr23 & 0xff);
968 mac[3] = (UCHAR)(addr23 >> 8);
969 mac[4] = (UCHAR)(addr45 & 0xff);
970 mac[5] = (UCHAR)(addr45 >> 8);
972 // open card information file
973 srcf = filp_open(CARD_INFO_PATH, O_RDONLY, 0);
976 /* card information file does not exist */
977 DBGPRINT(RT_DEBUG_TRACE,
978 ("--> Error %ld opening %s\n", -PTR_ERR(srcf), CARD_INFO_PATH));
982 if (srcf->f_op && srcf->f_op->read)
984 /* card information file exists so reading the card information */
985 memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
986 retval = srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
990 DBGPRINT(RT_DEBUG_TRACE,
991 ("--> Read %s error %d\n", CARD_INFO_PATH, -retval));
995 /* get card selection method */
996 memset(tmpbuf, 0x00, MAX_PARAM_BUFFER_SIZE);
997 card_select_method = MC_SELECT_CARDTYPE; // default
999 if (RTMPGetKeyParameter("SELECT", tmpbuf, 256, buffer))
1001 if (strcmp(tmpbuf, "CARDID") == 0)
1002 card_select_method = MC_SELECT_CARDID;
1003 else if (strcmp(tmpbuf, "MAC") == 0)
1004 card_select_method = MC_SELECT_MAC;
1005 else if (strcmp(tmpbuf, "CARDTYPE") == 0)
1006 card_select_method = MC_SELECT_CARDTYPE;
1009 DBGPRINT(RT_DEBUG_TRACE,
1010 ("MC> Card Selection = %d\n", card_select_method));
1015 card_same_mac_id = -1;
1018 // search current card information records
1020 card_index<MAX_NUM_OF_MULTIPLE_CARD;
1023 if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
1024 (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
1026 // MAC is all-0 so the entry is available
1027 MC_CardUsed[card_index] = 0;
1029 if (card_free_id < 0)
1030 card_free_id = card_index; // 1st free entry
1034 if (memcmp(MC_CardMac[card_index], mac, 6) == 0)
1036 // we find the entry with same MAC
1037 if (card_same_mac_id < 0)
1038 card_same_mac_id = card_index; // 1st same entry
1042 // MAC is not all-0 but used flag == 0
1043 if ((MC_CardUsed[card_index] == 0) &&
1044 (card_nouse_id < 0))
1046 card_nouse_id = card_index; // 1st available entry
1052 DBGPRINT(RT_DEBUG_TRACE,
1053 ("MC> Free = %d, Same = %d, NOUSE = %d\n",
1054 card_free_id, card_same_mac_id, card_nouse_id));
1056 if ((card_same_mac_id >= 0) &&
1057 ((card_select_method == MC_SELECT_CARDID) ||
1058 (card_select_method == MC_SELECT_CARDTYPE)))
1060 // same MAC entry is found
1061 card_match_id = card_same_mac_id;
1063 if (card_select_method == MC_SELECT_CARDTYPE)
1066 sprintf(card_id_buf, "%02dCARDTYPE%s",
1067 card_match_id, RFIC_word);
1069 if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
1071 // we found the card ID
1072 LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1078 // the card is 1st plug-in, try to find the match card profile
1079 switch(card_select_method)
1081 case MC_SELECT_CARDID: // CARDID
1083 if (card_free_id >= 0)
1084 card_match_id = card_free_id;
1086 card_match_id = card_nouse_id;
1089 case MC_SELECT_MAC: // MAC
1090 sprintf(card_id_buf, "MAC%02x:%02x:%02x:%02x:%02x:%02x",
1091 mac[0], mac[1], mac[2],
1092 mac[3], mac[4], mac[5]);
1094 /* try to find the key word in the card file */
1095 if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
1097 LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1099 /* get the row ID (2 ASCII characters) */
1101 card_id_buf[0] = *(start_ptr);
1102 card_id_buf[1] = *(start_ptr+1);
1103 card_id_buf[2] = 0x00;
1105 card_match_id = simple_strtol(card_id_buf, 0, 10);
1109 case MC_SELECT_CARDTYPE: // CARDTYPE
1113 card_index<MAX_NUM_OF_MULTIPLE_CARD;
1116 sprintf(card_id_buf, "%02dCARDTYPE%s",
1117 card_index, RFIC_word);
1119 if ((start_ptr=rtstrstruncasecmp(buffer,
1120 card_id_buf)) != NULL)
1122 LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1124 if (MC_CardUsed[card_index] == 0)
1126 /* current the card profile is not used */
1127 if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
1128 (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
1130 // find it and no previous card use it
1131 card_match_id = card_index;
1136 // ever a card use it
1137 if (card_nouse_id < 0)
1138 card_nouse_id = card_index;
1144 // if not find a free one, use the available one
1145 if (card_match_id < 0)
1146 card_match_id = card_nouse_id;
1151 if (card_match_id >= 0)
1153 // make up search keyword
1154 switch(card_select_method)
1156 case MC_SELECT_CARDID: // CARDID
1157 sprintf(card_id_buf, "%02dCARDID", card_match_id);
1160 case MC_SELECT_MAC: // MAC
1161 sprintf(card_id_buf,
1162 "%02dmac%02x:%02x:%02x:%02x:%02x:%02x",
1164 mac[0], mac[1], mac[2],
1165 mac[3], mac[4], mac[5]);
1168 case MC_SELECT_CARDTYPE: // CARDTYPE
1170 sprintf(card_id_buf, "%02dcardtype%s",
1171 card_match_id, RFIC_word);
1175 DBGPRINT(RT_DEBUG_TRACE, ("Search Keyword = %s\n", card_id_buf));
1177 // read card file path
1178 if (RTMPGetKeyParameter(card_id_buf, tmpbuf, 256, buffer))
1180 if (strlen(tmpbuf) < sizeof(pAd->MC_FileName))
1182 // backup card information
1183 pAd->MC_RowID = card_match_id; /* base 0 */
1184 MC_CardUsed[card_match_id] = 1;
1185 memcpy(MC_CardMac[card_match_id], mac, sizeof(mac));
1187 // backup card file path
1188 NdisMoveMemory(pAd->MC_FileName, tmpbuf , strlen(tmpbuf));
1189 pAd->MC_FileName[strlen(tmpbuf)] = '\0';
1190 flg_match_ok = TRUE;
1192 DBGPRINT(RT_DEBUG_TRACE,
1193 ("Card Profile Name = %s\n", pAd->MC_FileName));
1197 DBGPRINT(RT_DEBUG_ERROR,
1198 ("Card Profile Name length too large!\n"));
1203 DBGPRINT(RT_DEBUG_ERROR,
1204 ("Can not find search key word in card.dat!\n"));
1207 if ((flg_match_ok != TRUE) &&
1208 (card_match_id < MAX_NUM_OF_MULTIPLE_CARD))
1210 MC_CardUsed[card_match_id] = 0;
1211 memset(MC_CardMac[card_match_id], 0, sizeof(mac));
1213 } // if (card_match_id >= 0)
1218 retval = filp_close(srcf, NULL);
1220 current->fsuid = orgfsuid;
1221 current->fsgid = orgfsgid;
1224 return flg_match_ok;
1226 #endif // MULTIPLE_CARD_SUPPORT //
1230 ========================================================================
1231 Routine Description:
1232 Probe RT28XX chipset.
1235 _dev_p Point to the PCI or USB device
1236 _dev_id_p Point to the PCI or USB device ID
1243 ========================================================================
1245 INT __devinit rt28xx_probe(
1249 OUT PRTMP_ADAPTER *ppAd)
1251 struct net_device *net_dev;
1252 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
1256 struct pci_dev *dev_p = (struct pci_dev *)_dev_p;
1260 #ifdef CONFIG_STA_SUPPORT
1261 DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
1262 #endif // CONFIG_STA_SUPPORT //
1264 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
1265 net_dev = alloc_netdev(sizeof(PRTMP_ADAPTER), "eth%d", ether_setup);
1267 net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
1269 if (net_dev == NULL)
1271 printk("alloc_netdev failed\n");
1273 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1274 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1275 module_put(THIS_MODULE);
1276 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1283 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1284 SET_MODULE_OWNER(net_dev);
1287 netif_stop_queue(net_dev);
1288 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
1289 /* for supporting Network Manager */
1290 /* Set the sysfs physical device reference for the network logical device
1291 * if set prior to registration will cause a symlink during initialization.
1293 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
1294 SET_NETDEV_DEV(net_dev, &(dev_p->dev));
1296 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
1298 // Allocate RTMP_ADAPTER miniport adapter structure
1299 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
1300 RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
1302 status = RTMPAllocAdapterBlock(handle, &pAd);
1303 if (status != NDIS_STATUS_SUCCESS)
1304 goto err_out_free_netdev;
1306 net_dev->ml_priv = (PVOID)pAd;
1307 pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
1309 RT28XXNetDevInit(_dev_p, net_dev, pAd);
1311 #ifdef CONFIG_STA_SUPPORT
1312 pAd->StaCfg.OriDevType = net_dev->type;
1313 #endif // CONFIG_STA_SUPPORT //
1316 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1317 if (RT28XXProbePostConfig(_dev_p, pAd, argc) == FALSE)
1320 if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
1322 #endif // LINUX_VERSION_CODE //
1324 #ifdef CONFIG_STA_SUPPORT
1325 pAd->OpMode = OPMODE_STA;
1326 #endif // CONFIG_STA_SUPPORT //
1329 #ifdef MULTIPLE_CARD_SUPPORT
1330 // find its profile path
1331 pAd->MC_RowID = -1; // use default profile path
1332 RTMP_CardInfoRead(pAd);
1334 if (pAd->MC_RowID == -1)
1335 #ifdef CONFIG_STA_SUPPORT
1336 strcpy(pAd->MC_FileName, STA_PROFILE_PATH);
1337 #endif // CONFIG_STA_SUPPORT //
1339 DBGPRINT(RT_DEBUG_TRACE,
1340 ("MC> ROW = %d, PATH = %s\n", pAd->MC_RowID, pAd->MC_FileName));
1341 #endif // MULTIPLE_CARD_SUPPORT //
1344 if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
1347 // Register this device
1348 status = register_netdev(net_dev);
1353 RT28XX_DRVDATA_SET(_dev_p);
1356 return 0; // probe ok
1359 /* --------------------------- ERROR HANDLE --------------------------- */
1361 RTMPFreeAdapter(pAd);
1364 err_out_free_netdev:
1365 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1366 free_netdev(net_dev);
1372 RT28XX_PUT_DEVICE(dev_p);
1374 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1377 return -ENODEV; /* probe fail */
1378 #endif // LINUX_VERSION_CODE //
1379 } /* End of rt28xx_probe */
1383 ========================================================================
1384 Routine Description:
1385 The entry point for Linux kernel sent packet to our driver.
1388 sk_buff *skb the pointer refer to a sk_buffer.
1394 This function is the entry point of Tx Path for Os delivery packet to
1395 our driver. You only can put OS-depened & STA/AP common handle procedures
1397 ========================================================================
1399 int rt28xx_packet_xmit(struct sk_buff *skb)
1401 struct net_device *net_dev = skb->dev;
1402 PRTMP_ADAPTER pAd = net_dev->ml_priv;
1404 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
1406 /* RT2870STA does this in RTMPSendPackets() */
1410 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_RESOURCES);
1413 #endif // RALINK_ATE //
1415 #ifdef CONFIG_STA_SUPPORT
1416 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1418 // Drop send request since we are in monitor mode
1419 if (MONITOR_ON(pAd))
1421 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1425 #endif // CONFIG_STA_SUPPORT //
1427 // EapolStart size is 18
1430 //printk("bad packet size: %d\n", pkt->len);
1431 hex_dump("bad packet", skb->data, skb->len);
1432 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1436 RTMP_SET_PACKET_5VT(pPacket, 0);
1437 #ifdef CONFIG_5VT_ENHANCE
1438 if (*(int*)(skb->cb) == BRIDGE_TAG) {
1439 RTMP_SET_PACKET_5VT(pPacket, 1);
1445 #ifdef CONFIG_STA_SUPPORT
1446 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1449 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
1452 #endif // CONFIG_STA_SUPPORT //
1462 ========================================================================
1463 Routine Description:
1464 Send a packet to WLAN.
1467 skb_p points to our adapter
1468 dev_p which WLAN network interface
1471 0: transmit successfully
1472 otherwise: transmit fail
1475 ========================================================================
1477 INT rt28xx_send_packets(
1478 IN struct sk_buff *skb_p,
1479 IN struct net_device *net_dev)
1481 RTMP_ADAPTER *pAd = net_dev->ml_priv;
1482 if (!(net_dev->flags & IFF_UP))
1484 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
1488 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
1489 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
1491 return rt28xx_packet_xmit(skb_p);
1493 } /* End of MBSS_VirtualIF_PacketSend */
1498 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
1499 struct net_device *alloc_netdev(
1502 void (*setup)(struct net_device *))
1504 struct net_device *dev;
1508 /* ensure 32-byte alignment of the private area */
1509 alloc_size = sizeof (*dev) + sizeof_priv + 31;
1511 dev = (struct net_device *) kmalloc(alloc_size, GFP_KERNEL);
1514 DBGPRINT(RT_DEBUG_ERROR,
1515 ("alloc_netdev: Unable to allocate device memory.\n"));
1519 memset(dev, 0, alloc_size);
1522 dev->priv = (void *) (((long)(dev + 1) + 31) & ~31);
1525 strcpy(dev->name, mask);
1529 #endif // LINUX_VERSION_CODE //
1532 void CfgInitHook(PRTMP_ADAPTER pAd)
1534 pAd->bBroadComHT = TRUE;
1535 } /* End of CfgInitHook */
1538 #if WIRELESS_EXT >= 12
1539 // This function will be called when query /proc
1540 struct iw_statistics *rt28xx_get_wireless_stats(
1541 IN struct net_device *net_dev)
1543 PRTMP_ADAPTER pAd = net_dev->ml_priv;
1546 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
1548 pAd->iw_stats.status = 0; // Status - device dependent for now
1551 pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
1552 if(pAd->iw_stats.qual.qual > 100)
1553 pAd->iw_stats.qual.qual = 100;
1555 #ifdef CONFIG_STA_SUPPORT
1556 if (pAd->OpMode == OPMODE_STA)
1557 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
1558 #endif // CONFIG_STA_SUPPORT //
1560 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
1562 pAd->iw_stats.qual.noise += 256 - 143;
1563 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
1565 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
1566 #endif // IW_QUAL_DBM //
1568 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
1569 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
1571 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
1572 return &pAd->iw_stats;
1573 } /* End of rt28xx_get_wireless_stats */
1574 #endif // WIRELESS_EXT //
1578 void tbtt_tasklet(unsigned long data)
1580 #define MAX_TX_IN_TBTT (16)
1585 IN struct net_device *net_dev,
1586 IN OUT struct ifreq *rq,
1589 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1590 RTMP_ADAPTER *pAd = NULL;
1593 if (net_dev->priv_flags == INT_MAIN)
1595 pAd = net_dev->ml_priv;
1599 pVirtualAd = net_dev->ml_priv;
1600 pAd = pVirtualAd->RtmpDev->ml_priv;
1605 /* if 1st open fail, pAd will be free;
1606 So the net_dev->ml_priv will be NULL in 2rd open */
1611 #ifdef CONFIG_STA_SUPPORT
1612 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1614 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
1616 #endif // CONFIG_STA_SUPPORT //
1622 ========================================================================
1624 Routine Description:
1625 return ethernet statistics counter
1628 net_dev Pointer to net_device
1635 ========================================================================
1637 struct net_device_stats *RT28xx_get_ether_stats(
1638 IN struct net_device *net_dev)
1640 RTMP_ADAPTER *pAd = NULL;
1643 pAd = net_dev->ml_priv;
1648 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1649 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1651 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1652 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1654 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1655 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1657 pAd->stats.rx_dropped = 0;
1658 pAd->stats.tx_dropped = 0;
1660 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
1661 pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
1663 pAd->stats.rx_length_errors = 0;
1664 pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
1665 pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1666 pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
1667 pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
1668 pAd->stats.rx_missed_errors = 0; // receiver missed packet
1670 // detailed tx_errors
1671 pAd->stats.tx_aborted_errors = 0;
1672 pAd->stats.tx_carrier_errors = 0;
1673 pAd->stats.tx_fifo_errors = 0;
1674 pAd->stats.tx_heartbeat_errors = 0;
1675 pAd->stats.tx_window_errors = 0;
1678 pAd->stats.rx_compressed = 0;
1679 pAd->stats.tx_compressed = 0;