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 /*---------------------------------------------------------------------*/
44 /* Private Variables Used */
45 /*---------------------------------------------------------------------*/
46 //static RALINK_TIMER_STRUCT PeriodicTimer;
48 char *mac = ""; // default 00:00:00:00:00:00
49 char *hostname = ""; // default CMPC
50 module_param (mac, charp, 0);
51 MODULE_PARM_DESC (mac, "rt28xx: wireless mac addr");
54 /*---------------------------------------------------------------------*/
55 /* Prototypes of Functions Used */
56 /*---------------------------------------------------------------------*/
57 #ifdef DOT11_N_SUPPORT
58 extern BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
59 extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
60 #endif // DOT11_N_SUPPORT //
61 extern NDIS_STATUS NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd);
64 // public function prototype
65 INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
66 IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
68 // private function prototype
69 static int rt28xx_init(IN struct net_device *net_dev);
70 INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);
72 static void CfgInitHook(PRTMP_ADAPTER pAd);
73 //static BOOLEAN RT28XXAvailRANameAssign(IN CHAR *name_p);
75 #ifdef CONFIG_STA_SUPPORT
76 extern const struct iw_handler_def rt28xx_iw_handler_def;
77 #endif // CONFIG_STA_SUPPORT //
79 #if WIRELESS_EXT >= 12
80 // This function will be called when query /proc
81 struct iw_statistics *rt28xx_get_wireless_stats(
82 IN struct net_device *net_dev);
85 struct net_device_stats *RT28xx_get_ether_stats(
86 IN struct net_device *net_dev);
89 ========================================================================
94 *net_dev the raxx interface pointer
101 1. if open fail, kernel will not call the close function.
103 (1) Mlme Memory Handler: MlmeHalt()
104 (2) TX & RX: RTMPFreeTxRxRingMemory()
105 (3) BA Reordering: ba_reordering_resource_release()
106 ========================================================================
108 int MainVirtualIF_close(IN struct net_device *net_dev)
110 RTMP_ADAPTER *pAd = net_dev->ml_priv;
112 // Sanity check for pAd
114 return 0; // close ok
116 netif_carrier_off(pAd->net_dev);
117 netif_stop_queue(pAd->net_dev);
121 VIRTUAL_IF_DOWN(pAd);
123 RT_MOD_DEC_USE_COUNT();
125 return 0; // close ok
129 ========================================================================
134 *net_dev the raxx interface pointer
141 1. if open fail, kernel will not call the close function.
143 (1) Mlme Memory Handler: MlmeHalt()
144 (2) TX & RX: RTMPFreeTxRxRingMemory()
145 (3) BA Reordering: ba_reordering_resource_release()
146 ========================================================================
148 int MainVirtualIF_open(IN struct net_device *net_dev)
150 RTMP_ADAPTER *pAd = net_dev->ml_priv;
152 // Sanity check for pAd
154 return 0; // close ok
156 if (VIRTUAL_IF_UP(pAd) != 0)
159 // increase MODULE use count
160 RT_MOD_INC_USE_COUNT();
162 netif_start_queue(net_dev);
163 netif_carrier_on(net_dev);
164 netif_wake_queue(net_dev);
170 ========================================================================
172 Close raxx interface.
175 *net_dev the raxx interface pointer
182 1. if open fail, kernel will not call the close function.
184 (1) Mlme Memory Handler: MlmeHalt()
185 (2) TX & RX: RTMPFreeTxRxRingMemory()
186 (3) BA Reordering: ba_reordering_resource_release()
187 ========================================================================
189 int rt28xx_close(IN PNET_DEV dev)
191 struct net_device * net_dev = (struct net_device *)dev;
192 RTMP_ADAPTER *pAd = net_dev->ml_priv;
193 BOOLEAN Cancelled = FALSE;
196 DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
197 DECLARE_WAITQUEUE(wait, current);
199 //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
203 DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
205 // Sanity check for pAd
207 return 0; // close ok
209 #ifdef CONFIG_STA_SUPPORT
210 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
213 // If dirver doesn't wake up firmware here,
214 // NICLoadFirmware will hang forever when interface is up again.
215 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
217 AsicForceWakeup(pAd, TRUE);
220 #ifdef QOS_DLS_SUPPORT
221 // send DLS-TEAR_DOWN message,
222 if (pAd->CommonCfg.bDLSCapable)
226 // tear down local dls table entry
227 for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
229 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
231 RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
232 pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
233 pAd->StaCfg.DLSEntry[i].Valid = FALSE;
237 // tear down peer dls table entry
238 for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
240 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
242 RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
243 pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
244 pAd->StaCfg.DLSEntry[i].Valid = FALSE;
247 RT28XX_MLME_HANDLER(pAd);
249 #endif // QOS_DLS_SUPPORT //
252 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
254 MLME_DISASSOC_REQ_STRUCT DisReq;
255 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
257 COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
258 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
260 MsgElem->Machine = ASSOC_STATE_MACHINE;
261 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
262 MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
263 NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
265 // Prevent to connect AP again in STAMlmePeriodicExec
266 pAd->MlmeAux.AutoReconnectSsidLen= 32;
267 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
269 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
270 MlmeDisassocReqAction(pAd, MsgElem);
277 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
281 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
284 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
285 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
287 #ifdef WPA_SUPPLICANT_SUPPORT
288 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
290 union iwreq_data wrqu;
291 // send wireless event to wpa_supplicant for infroming interface down.
292 memset(&wrqu, 0, sizeof(wrqu));
293 wrqu.data.flags = RT_INTERFACE_DOWN;
294 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
296 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
297 #endif // WPA_SUPPLICANT_SUPPORT //
301 #endif // CONFIG_STA_SUPPORT //
303 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
305 for (i = 0 ; i < NUM_OF_TX_RING; i++)
307 while (pAd->DeQueueRunning[i] == TRUE)
309 printk("Waiting for TxQueue[%d] done..........\n", i);
315 // ensure there are no more active urbs.
316 add_wait_queue (&unlink_wakeup, &wait);
317 pAd->wait = &unlink_wakeup;
319 // maybe wait for deletions to finish.
321 //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
324 unsigned long IrqFlags;
326 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
327 if (pAd->PendingRx == 0)
329 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
332 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
334 msleep(UNLINK_TIMEOUT_MS); //Time in millisecond
338 remove_wait_queue (&unlink_wakeup, &wait);
341 //RTUSBCleanUpMLMEWaitQueue(pAd); /*not used in RT28xx*/
345 // We need clear timerQ related structure before exits of the timer thread.
346 RT2870_TimerQ_Exit(pAd);
347 // Close kernel threads or tasklets
348 RT28xxThreadTerminate(pAd);
351 // Stop Mlme state machine
354 // Close kernel threads or tasklets
355 kill_thread_task(pAd);
358 #ifdef CONFIG_STA_SUPPORT
359 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
363 #endif // CONFIG_STA_SUPPORT //
366 MeasureReqTabExit(pAd);
372 // Free Ring or USB buffers
373 RTMPFreeTxRxRingMemory(pAd);
375 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
377 #ifdef DOT11_N_SUPPORT
378 // Free BA reorder resource
379 ba_reordering_resource_release(pAd);
380 #endif // DOT11_N_SUPPORT //
384 if (pAd->UsbVendorReqBuf)
385 os_free_mem(pAd, pAd->UsbVendorReqBuf);
386 #endif // INF_AMAZON_SE //
389 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
391 return 0; // close ok
392 } /* End of rt28xx_close */
394 static int rt28xx_init(IN struct net_device *net_dev)
396 PRTMP_ADAPTER pAd = net_dev->ml_priv;
401 // OID_SET_HT_PHYMODE SetHT;
402 // WPDMA_GLO_CFG_STRUC GloCfg;
407 init_MUTEX(&(pAd->UsbVendorReq_semaphore));
408 os_alloc_mem(pAd, (PUCHAR)&pAd->UsbVendorReqBuf, MAX_PARAM_BUFFER_SIZE - 1);
409 if (pAd->UsbVendorReqBuf == NULL)
411 DBGPRINT(RT_DEBUG_ERROR, ("Allocate vendor request temp buffer failed!\n"));
414 #endif // INF_AMAZON_SE //
417 #ifdef DOT11_N_SUPPORT
418 // Allocate BA Reordering memory
419 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
420 #endif // DOT11_N_SUPPORT //
422 // Make sure MAC gets ready.
426 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
427 pAd->MACVersion = MacCsr0;
429 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
433 } while (index++ < 100);
435 DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
436 /*Iverson patch PCIE L1 issue */
439 RT28XXDMADisable(pAd);
442 // Load 8051 firmware
443 Status = NICLoadFirmware(pAd);
444 if (Status != NDIS_STATUS_SUCCESS)
446 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
450 NICLoadRateSwitchingParams(pAd);
452 // Disable interrupts here which is as soon as possible
453 // This statement should never be true. We might consider to remove it later
455 Status = RTMPAllocTxRxRingMemory(pAd);
456 if (Status != NDIS_STATUS_SUCCESS)
458 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
462 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
467 Status = MlmeInit(pAd);
468 if (Status != NDIS_STATUS_SUCCESS)
470 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
474 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
479 // We need init timerQ related structure before create the timer thread.
480 RT2870_TimerQ_Init(pAd);
483 RT28XX_TASK_THREAD_INIT(pAd, Status);
484 if (Status != NDIS_STATUS_SUCCESS)
487 // COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
488 // pAd->bForcePrintTX = TRUE;
492 #ifdef CONFIG_STA_SUPPORT
493 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
494 NdisAllocateSpinLock(&pAd->MacTabLock);
495 #endif // CONFIG_STA_SUPPORT //
497 MeasureReqTabInit(pAd);
501 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
503 Status = NICInitializeAdapter(pAd, TRUE);
504 if (Status != NDIS_STATUS_SUCCESS)
506 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
507 if (Status != NDIS_STATUS_SUCCESS)
511 // Read parameters from Config File
512 Status = RTMPReadParametersHook(pAd);
514 printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
515 if (Status != NDIS_STATUS_SUCCESS)
517 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
522 pAd->CommonCfg.bMultipleIRP = FALSE;
524 if (pAd->CommonCfg.bMultipleIRP)
525 pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
527 pAd->CommonCfg.NumOfBulkInIRP = 1;
531 //Init Ba Capability parameters.
532 // RT28XX_BA_INIT(pAd);
533 #ifdef DOT11_N_SUPPORT
534 pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
535 pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
536 pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
537 pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
539 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
540 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
541 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
542 #endif // DOT11_N_SUPPORT //
544 // after reading Registry, we now know if in AP mode or STA mode
546 // Load 8051 firmware; crash when FW image not existent
547 // Status = NICLoadFirmware(pAd);
548 // if (Status != NDIS_STATUS_SUCCESS)
551 printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
553 // We should read EEPROM for all cases. rt2860b
554 NICReadEEPROMParameters(pAd, mac);
555 #ifdef CONFIG_STA_SUPPORT
556 #endif // CONFIG_STA_SUPPORT //
558 printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
560 NICInitAsicFromEEPROM(pAd); //rt2860b
562 // Set PHY to appropriate mode
563 TmpPhy = pAd->CommonCfg.PhyMode;
564 pAd->CommonCfg.PhyMode = 0xff;
565 RTMPSetPhyMode(pAd, TmpPhy);
566 #ifdef DOT11_N_SUPPORT
568 #endif // DOT11_N_SUPPORT //
570 // No valid channels.
571 if (pAd->ChannelListNum == 0)
573 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
577 #ifdef DOT11_N_SUPPORT
578 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
579 pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
580 pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
581 #endif // DOT11_N_SUPPORT //
584 //Init RT30xx RFRegisters after read RFIC type from EEPROM
585 NICInitRT30xxRFRegisters(pAd);
588 // APInitialize(pAd);
591 VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
592 #endif // IKANOS_VX_1X0 //
595 // Initialize RF register to default value
597 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
598 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
600 if (pAd && (Status != NDIS_STATUS_SUCCESS))
603 // Undo everything if it failed
605 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
607 // NdisMDeregisterInterrupt(&pAd->Interrupt);
608 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
610 // RTMPFreeAdapter(pAd); // we will free it in disconnect()
614 // Microsoft HCT require driver send a disconnect event after driver initialization.
615 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
616 // pAd->IndicateMediaState = NdisMediaStateDisconnected;
617 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
619 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
623 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
624 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
627 // Support multiple BulkIn IRP,
628 // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
630 for(index=0; index<pAd->CommonCfg.NumOfBulkInIRP; index++)
632 RTUSBBulkReceive(pAd);
633 DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n" ));
639 DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
648 RTMPFreeTxRxRingMemory(pAd);
649 // RTMPFreeAdapter(pAd);
652 #ifdef DOT11_N_SUPPORT
653 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
654 #endif // DOT11_N_SUPPORT //
655 RT28XX_IRQ_RELEASE(net_dev);
657 // shall not set priv to NULL here because the priv didn't been free yet.
658 //net_dev->ml_priv = 0;
661 #endif // INF_AMAZON_SE //
662 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
664 } /* End of rt28xx_init */
668 ========================================================================
673 *net_dev the raxx interface pointer
680 ========================================================================
682 int rt28xx_open(IN PNET_DEV dev)
684 struct net_device * net_dev = (struct net_device *)dev;
685 PRTMP_ADAPTER pAd = net_dev->ml_priv;
690 // Sanity check for pAd
693 /* if 1st open fail, pAd will be free;
694 So the net_dev->ml_priv will be NULL in 2rd open */
698 #ifdef CONFIG_STA_SUPPORT
699 #endif // CONFIG_STA_SUPPORT //
702 pObj = (POS_COOKIE)pAd->OS_Cookie;
704 // reset Adapter flags
705 RTMP_CLEAR_FLAGS(pAd);
707 // Request interrupt service routine for PCI device
708 // register the interrupt routine with the os
709 RT28XX_IRQ_REQUEST(net_dev);
712 // Init BssTab & ChannelInfo tabbles for auto channel select.
716 if (rt28xx_init(net_dev) == FALSE)
719 #ifdef CONFIG_STA_SUPPORT
720 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
722 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
723 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
725 #endif // CONFIG_STA_SUPPORT //
727 // Set up the Mac address
728 NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
730 // Init IRQ parameters
731 RT28XX_IRQ_INIT(pAd);
733 // Various AP function init
737 #ifdef CONFIG_STA_SUPPORT
738 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
740 #ifdef WPA_SUPPLICANT_SUPPORT
741 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
743 union iwreq_data wrqu;
744 // send wireless event to wpa_supplicant for infroming interface down.
745 memset(&wrqu, 0, sizeof(wrqu));
746 wrqu.data.flags = RT_INTERFACE_UP;
747 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
749 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
750 #endif // WPA_SUPPLICANT_SUPPORT //
753 #endif // CONFIG_STA_SUPPORT //
756 RT28XX_IRQ_ENABLE(pAd);
760 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
764 RTMP_IO_READ32(pAd, 0x1300, ®); // clear garbage interrupts
765 printk("0x1300 = %08x\n", reg);
773 // RTMP_IO_READ32(pAd, XIFS_TIME_CFG, ®);
776 // reg = (reg & 0xffff0000) | tmp;
777 // RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
781 #ifdef CONFIG_STA_SUPPORT
782 #endif // CONFIG_STA_SUPPORT //
788 } /* End of rt28xx_open */
790 static const struct net_device_ops rt3070_netdev_ops = {
791 .ndo_open = MainVirtualIF_open,
792 .ndo_stop = MainVirtualIF_close,
793 .ndo_do_ioctl = rt28xx_ioctl,
794 .ndo_get_stats = RT28xx_get_ether_stats,
795 .ndo_validate_addr = NULL,
796 .ndo_set_mac_address = eth_mac_addr,
797 .ndo_change_mtu = eth_change_mtu,
799 .ndo_start_xmit = IKANOS_DataFramesTx,
801 .ndo_start_xmit = rt28xx_send_packets,
805 /* Must not be called for mdev and apdev */
806 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
810 CHAR slot_name[IFNAMSIZ];
811 struct net_device *device;
815 // dev->set_multicast_list = ieee80211_set_multicast_list;
816 // dev->change_mtu = ieee80211_change_mtu;
817 #ifdef CONFIG_STA_SUPPORT
818 #if WIRELESS_EXT >= 12
819 if (pAd->OpMode == OPMODE_STA)
821 dev->wireless_handlers = &rt28xx_iw_handler_def;
823 #endif //WIRELESS_EXT >= 12
824 #endif // CONFIG_STA_SUPPORT //
826 #if WIRELESS_EXT < 21
827 dev->get_wireless_stats = rt28xx_get_wireless_stats;
829 // dev->uninit = ieee80211_if_reinit;
830 // dev->destructor = ieee80211_if_free;
831 dev->priv_flags = INT_MAIN;
832 dev->netdev_ops = &rt3070_netdev_ops;
833 // find available device name
834 for (i = 0; i < 8; i++)
836 sprintf(slot_name, "ra%d", i);
838 device = dev_get_by_name(dev_net(dev), slot_name);
848 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
849 Status = NDIS_STATUS_FAILURE;
853 sprintf(dev->name, "ra%d", i);
854 Status = NDIS_STATUS_SUCCESS;
862 ========================================================================
864 Probe RT28XX chipset.
867 _dev_p Point to the PCI or USB device
868 _dev_id_p Point to the PCI or USB device ID
875 ========================================================================
877 INT __devinit rt28xx_probe(
881 OUT PRTMP_ADAPTER *ppAd)
883 struct net_device *net_dev;
884 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
888 struct usb_interface *intf = (struct usb_interface *)_dev_p;
889 struct usb_device *dev_p = interface_to_usbdev(intf);
891 dev_p = usb_get_dev(dev_p);
895 #ifdef CONFIG_STA_SUPPORT
896 DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
897 #endif // CONFIG_STA_SUPPORT //
899 // Check chipset vendor/product ID
900 // if (RT28XXChipsetCheck(_dev_p) == FALSE)
903 net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
906 printk("alloc_netdev failed\n");
912 // if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
915 netif_stop_queue(net_dev);
916 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
917 /* for supporting Network Manager */
918 /* Set the sysfs physical device reference for the network logical device
919 * if set prior to registration will cause a symlink during initialization.
921 SET_NETDEV_DEV(net_dev, &(dev_p->dev));
922 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
924 // Allocate RTMP_ADAPTER miniport adapter structure
925 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
926 RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
928 status = RTMPAllocAdapterBlock(handle, &pAd);
929 if (status != NDIS_STATUS_SUCCESS)
930 goto err_out_free_netdev;
932 net_dev->ml_priv = (PVOID)pAd;
933 pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
935 RT28XXNetDevInit(_dev_p, net_dev, pAd);
937 #ifdef CONFIG_STA_SUPPORT
938 pAd->StaCfg.OriDevType = net_dev->type;
939 #endif // CONFIG_STA_SUPPORT //
941 // Find and assign a free interface name, raxx
942 // RT28XXAvailRANameAssign(net_dev->name);
945 if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
948 #ifdef CONFIG_STA_SUPPORT
949 pAd->OpMode = OPMODE_STA;
950 #endif // CONFIG_STA_SUPPORT //
953 if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
956 // Register this device
957 status = register_netdev(net_dev);
962 RT28XX_DRVDATA_SET(_dev_p);
967 return 0; // probe ok
970 /* --------------------------- ERROR HANDLE --------------------------- */
972 RTMPFreeAdapter(pAd);
976 free_netdev(net_dev);
979 RT28XX_PUT_DEVICE(dev_p);
981 return -ENODEV; /* probe fail */
982 } /* End of rt28xx_probe */
986 ========================================================================
988 The entry point for Linux kernel sent packet to our driver.
991 sk_buff *skb the pointer refer to a sk_buffer.
997 This function is the entry point of Tx Path for Os delivery packet to
998 our driver. You only can put OS-depened & STA/AP common handle procedures
1000 ========================================================================
1002 int rt28xx_packet_xmit(struct sk_buff *skb)
1004 struct net_device *net_dev = skb->dev;
1005 PRTMP_ADAPTER pAd = net_dev->ml_priv;
1007 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
1009 #ifdef CONFIG_STA_SUPPORT
1010 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1012 // Drop send request since we are in monitor mode
1013 if (MONITOR_ON(pAd))
1015 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1019 #endif // CONFIG_STA_SUPPORT //
1021 // EapolStart size is 18
1024 //printk("bad packet size: %d\n", pkt->len);
1025 hex_dump("bad packet", skb->data, skb->len);
1026 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1030 RTMP_SET_PACKET_5VT(pPacket, 0);
1031 // MiniportMMRequest(pAd, pkt->data, pkt->len);
1032 #ifdef CONFIG_5VT_ENHANCE
1033 if (*(int*)(skb->cb) == BRIDGE_TAG) {
1034 RTMP_SET_PACKET_5VT(pPacket, 1);
1040 #ifdef CONFIG_STA_SUPPORT
1041 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1044 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
1047 #endif // CONFIG_STA_SUPPORT //
1057 ========================================================================
1058 Routine Description:
1059 Send a packet to WLAN.
1062 skb_p points to our adapter
1063 dev_p which WLAN network interface
1066 0: transmit successfully
1067 otherwise: transmit fail
1070 ========================================================================
1072 INT rt28xx_send_packets(
1073 IN struct sk_buff *skb_p,
1074 IN struct net_device *net_dev)
1076 RTMP_ADAPTER *pAd = net_dev->ml_priv;
1078 if (!(net_dev->flags & IFF_UP))
1080 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
1084 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
1085 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
1087 return rt28xx_packet_xmit(skb_p);
1088 } /* End of MBSS_VirtualIF_PacketSend */
1093 void CfgInitHook(PRTMP_ADAPTER pAd)
1095 pAd->bBroadComHT = TRUE;
1096 } /* End of CfgInitHook */
1099 #if WIRELESS_EXT >= 12
1100 // This function will be called when query /proc
1101 struct iw_statistics *rt28xx_get_wireless_stats(
1102 IN struct net_device *net_dev)
1104 PRTMP_ADAPTER pAd = net_dev->ml_priv;
1107 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
1109 pAd->iw_stats.status = 0; // Status - device dependent for now
1112 pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
1113 if(pAd->iw_stats.qual.qual > 100)
1114 pAd->iw_stats.qual.qual = 100;
1116 #ifdef CONFIG_STA_SUPPORT
1117 if (pAd->OpMode == OPMODE_STA)
1118 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
1119 #endif // CONFIG_STA_SUPPORT //
1121 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
1123 pAd->iw_stats.qual.noise += 256 - 143;
1124 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
1126 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
1127 #endif // IW_QUAL_DBM //
1129 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
1130 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
1132 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
1133 return &pAd->iw_stats;
1134 } /* End of rt28xx_get_wireless_stats */
1135 #endif // WIRELESS_EXT //
1139 void tbtt_tasklet(unsigned long data)
1141 #define MAX_TX_IN_TBTT (16)
1146 IN struct net_device *net_dev,
1147 IN OUT struct ifreq *rq,
1150 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1151 RTMP_ADAPTER *pAd = NULL;
1154 if (net_dev->priv_flags == INT_MAIN)
1156 pAd = net_dev->ml_priv;
1160 pVirtualAd = net_dev->ml_priv;
1161 pAd = pVirtualAd->RtmpDev->ml_priv;
1166 /* if 1st open fail, pAd will be free;
1167 So the net_dev->ml_priv will be NULL in 2rd open */
1172 #ifdef CONFIG_STA_SUPPORT
1173 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1175 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
1177 #endif // CONFIG_STA_SUPPORT //
1183 ========================================================================
1185 Routine Description:
1186 return ethernet statistics counter
1189 net_dev Pointer to net_device
1196 ========================================================================
1198 struct net_device_stats *RT28xx_get_ether_stats(
1199 IN struct net_device *net_dev)
1201 RTMP_ADAPTER *pAd = NULL;
1204 pAd = net_dev->ml_priv;
1209 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1210 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1212 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1213 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1215 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1216 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1218 pAd->stats.rx_dropped = 0;
1219 pAd->stats.tx_dropped = 0;
1221 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
1222 pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
1224 pAd->stats.rx_length_errors = 0;
1225 pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
1226 pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1227 pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
1228 pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
1229 pAd->stats.rx_missed_errors = 0; // receiver missed packet
1231 // detailed tx_errors
1232 pAd->stats.tx_aborted_errors = 0;
1233 pAd->stats.tx_carrier_errors = 0;
1234 pAd->stats.tx_fifo_errors = 0;
1235 pAd->stats.tx_heartbeat_errors = 0;
1236 pAd->stats.tx_window_errors = 0;
1239 pAd->stats.rx_compressed = 0;
1240 pAd->stats.tx_compressed = 0;