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);
221 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
223 MLME_DISASSOC_REQ_STRUCT DisReq;
224 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
226 COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
227 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
229 MsgElem->Machine = ASSOC_STATE_MACHINE;
230 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
231 MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
232 NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
234 // Prevent to connect AP again in STAMlmePeriodicExec
235 pAd->MlmeAux.AutoReconnectSsidLen= 32;
236 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
238 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
239 MlmeDisassocReqAction(pAd, MsgElem);
246 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
250 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
253 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
254 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
256 #ifdef WPA_SUPPLICANT_SUPPORT
257 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
259 union iwreq_data wrqu;
260 // send wireless event to wpa_supplicant for infroming interface down.
261 memset(&wrqu, 0, sizeof(wrqu));
262 wrqu.data.flags = RT_INTERFACE_DOWN;
263 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
265 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
266 #endif // WPA_SUPPLICANT_SUPPORT //
270 #endif // CONFIG_STA_SUPPORT //
272 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
274 for (i = 0 ; i < NUM_OF_TX_RING; i++)
276 while (pAd->DeQueueRunning[i] == TRUE)
278 printk("Waiting for TxQueue[%d] done..........\n", i);
284 // ensure there are no more active urbs.
285 add_wait_queue (&unlink_wakeup, &wait);
286 pAd->wait = &unlink_wakeup;
288 // maybe wait for deletions to finish.
290 //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
293 unsigned long IrqFlags;
295 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
296 if (pAd->PendingRx == 0)
298 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
301 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
303 msleep(UNLINK_TIMEOUT_MS); //Time in millisecond
307 remove_wait_queue (&unlink_wakeup, &wait);
310 //RTUSBCleanUpMLMEWaitQueue(pAd); /*not used in RT28xx*/
314 // We need clear timerQ related structure before exits of the timer thread.
315 RT2870_TimerQ_Exit(pAd);
316 // Close kernel threads or tasklets
317 RT28xxThreadTerminate(pAd);
320 // Stop Mlme state machine
323 // Close kernel threads or tasklets
324 kill_thread_task(pAd);
327 #ifdef CONFIG_STA_SUPPORT
328 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
332 #endif // CONFIG_STA_SUPPORT //
335 MeasureReqTabExit(pAd);
341 // Free Ring or USB buffers
342 RTMPFreeTxRxRingMemory(pAd);
344 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
346 #ifdef DOT11_N_SUPPORT
347 // Free BA reorder resource
348 ba_reordering_resource_release(pAd);
349 #endif // DOT11_N_SUPPORT //
353 if (pAd->UsbVendorReqBuf)
354 os_free_mem(pAd, pAd->UsbVendorReqBuf);
355 #endif // INF_AMAZON_SE //
358 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
360 return 0; // close ok
361 } /* End of rt28xx_close */
363 static int rt28xx_init(IN struct net_device *net_dev)
365 PRTMP_ADAPTER pAd = net_dev->ml_priv;
370 // OID_SET_HT_PHYMODE SetHT;
371 // WPDMA_GLO_CFG_STRUC GloCfg;
376 init_MUTEX(&(pAd->UsbVendorReq_semaphore));
377 os_alloc_mem(pAd, (PUCHAR)&pAd->UsbVendorReqBuf, MAX_PARAM_BUFFER_SIZE - 1);
378 if (pAd->UsbVendorReqBuf == NULL)
380 DBGPRINT(RT_DEBUG_ERROR, ("Allocate vendor request temp buffer failed!\n"));
383 #endif // INF_AMAZON_SE //
386 #ifdef DOT11_N_SUPPORT
387 // Allocate BA Reordering memory
388 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
389 #endif // DOT11_N_SUPPORT //
391 // Make sure MAC gets ready.
395 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
396 pAd->MACVersion = MacCsr0;
398 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
402 } while (index++ < 100);
404 DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
405 /*Iverson patch PCIE L1 issue */
408 RT28XXDMADisable(pAd);
411 // Load 8051 firmware
412 Status = NICLoadFirmware(pAd);
413 if (Status != NDIS_STATUS_SUCCESS)
415 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
419 NICLoadRateSwitchingParams(pAd);
421 // Disable interrupts here which is as soon as possible
422 // This statement should never be true. We might consider to remove it later
424 Status = RTMPAllocTxRxRingMemory(pAd);
425 if (Status != NDIS_STATUS_SUCCESS)
427 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
431 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
436 Status = MlmeInit(pAd);
437 if (Status != NDIS_STATUS_SUCCESS)
439 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
443 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
448 // We need init timerQ related structure before create the timer thread.
449 RT2870_TimerQ_Init(pAd);
452 RT28XX_TASK_THREAD_INIT(pAd, Status);
453 if (Status != NDIS_STATUS_SUCCESS)
456 // COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
457 // pAd->bForcePrintTX = TRUE;
461 #ifdef CONFIG_STA_SUPPORT
462 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
463 NdisAllocateSpinLock(&pAd->MacTabLock);
464 #endif // CONFIG_STA_SUPPORT //
466 MeasureReqTabInit(pAd);
470 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
472 Status = NICInitializeAdapter(pAd, TRUE);
473 if (Status != NDIS_STATUS_SUCCESS)
475 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
476 if (Status != NDIS_STATUS_SUCCESS)
480 // Read parameters from Config File
481 Status = RTMPReadParametersHook(pAd);
483 printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
484 if (Status != NDIS_STATUS_SUCCESS)
486 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
491 pAd->CommonCfg.bMultipleIRP = FALSE;
493 if (pAd->CommonCfg.bMultipleIRP)
494 pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
496 pAd->CommonCfg.NumOfBulkInIRP = 1;
500 //Init Ba Capability parameters.
501 // RT28XX_BA_INIT(pAd);
502 #ifdef DOT11_N_SUPPORT
503 pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
504 pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
505 pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
506 pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
508 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
509 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
510 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
511 #endif // DOT11_N_SUPPORT //
513 // after reading Registry, we now know if in AP mode or STA mode
515 // Load 8051 firmware; crash when FW image not existent
516 // Status = NICLoadFirmware(pAd);
517 // if (Status != NDIS_STATUS_SUCCESS)
520 printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
522 // We should read EEPROM for all cases. rt2860b
523 NICReadEEPROMParameters(pAd, mac);
524 #ifdef CONFIG_STA_SUPPORT
525 #endif // CONFIG_STA_SUPPORT //
527 printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
529 NICInitAsicFromEEPROM(pAd); //rt2860b
531 // Set PHY to appropriate mode
532 TmpPhy = pAd->CommonCfg.PhyMode;
533 pAd->CommonCfg.PhyMode = 0xff;
534 RTMPSetPhyMode(pAd, TmpPhy);
535 #ifdef DOT11_N_SUPPORT
537 #endif // DOT11_N_SUPPORT //
539 // No valid channels.
540 if (pAd->ChannelListNum == 0)
542 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
546 #ifdef DOT11_N_SUPPORT
547 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
548 pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
549 pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
550 #endif // DOT11_N_SUPPORT //
553 //Init RT30xx RFRegisters after read RFIC type from EEPROM
554 NICInitRT30xxRFRegisters(pAd);
557 // APInitialize(pAd);
560 VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
561 #endif // IKANOS_VX_1X0 //
564 // Initialize RF register to default value
566 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
567 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
569 if (pAd && (Status != NDIS_STATUS_SUCCESS))
572 // Undo everything if it failed
574 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
576 // NdisMDeregisterInterrupt(&pAd->Interrupt);
577 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
579 // RTMPFreeAdapter(pAd); // we will free it in disconnect()
583 // Microsoft HCT require driver send a disconnect event after driver initialization.
584 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
585 // pAd->IndicateMediaState = NdisMediaStateDisconnected;
586 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
588 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
592 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
593 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
596 // Support multiple BulkIn IRP,
597 // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
599 for(index=0; index<pAd->CommonCfg.NumOfBulkInIRP; index++)
601 RTUSBBulkReceive(pAd);
602 DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n" ));
608 DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
617 RTMPFreeTxRxRingMemory(pAd);
618 // RTMPFreeAdapter(pAd);
621 #ifdef DOT11_N_SUPPORT
622 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
623 #endif // DOT11_N_SUPPORT //
624 RT28XX_IRQ_RELEASE(net_dev);
626 // shall not set priv to NULL here because the priv didn't been free yet.
627 //net_dev->ml_priv = 0;
630 #endif // INF_AMAZON_SE //
631 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
633 } /* End of rt28xx_init */
637 ========================================================================
642 *net_dev the raxx interface pointer
649 ========================================================================
651 int rt28xx_open(IN PNET_DEV dev)
653 struct net_device * net_dev = (struct net_device *)dev;
654 PRTMP_ADAPTER pAd = net_dev->ml_priv;
659 // Sanity check for pAd
662 /* if 1st open fail, pAd will be free;
663 So the net_dev->ml_priv will be NULL in 2rd open */
667 #ifdef CONFIG_STA_SUPPORT
668 #endif // CONFIG_STA_SUPPORT //
671 pObj = (POS_COOKIE)pAd->OS_Cookie;
673 // reset Adapter flags
674 RTMP_CLEAR_FLAGS(pAd);
676 // Request interrupt service routine for PCI device
677 // register the interrupt routine with the os
678 RT28XX_IRQ_REQUEST(net_dev);
681 // Init BssTab & ChannelInfo tabbles for auto channel select.
685 if (rt28xx_init(net_dev) == FALSE)
688 #ifdef CONFIG_STA_SUPPORT
689 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
691 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
692 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
694 #endif // CONFIG_STA_SUPPORT //
696 // Set up the Mac address
697 NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
699 // Init IRQ parameters
700 RT28XX_IRQ_INIT(pAd);
702 // Various AP function init
706 #ifdef CONFIG_STA_SUPPORT
707 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
709 #ifdef WPA_SUPPLICANT_SUPPORT
710 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
712 union iwreq_data wrqu;
713 // send wireless event to wpa_supplicant for infroming interface down.
714 memset(&wrqu, 0, sizeof(wrqu));
715 wrqu.data.flags = RT_INTERFACE_UP;
716 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
718 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
719 #endif // WPA_SUPPLICANT_SUPPORT //
722 #endif // CONFIG_STA_SUPPORT //
725 RT28XX_IRQ_ENABLE(pAd);
729 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
733 RTMP_IO_READ32(pAd, 0x1300, ®); // clear garbage interrupts
734 printk("0x1300 = %08x\n", reg);
742 // RTMP_IO_READ32(pAd, XIFS_TIME_CFG, ®);
745 // reg = (reg & 0xffff0000) | tmp;
746 // RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
750 #ifdef CONFIG_STA_SUPPORT
751 #endif // CONFIG_STA_SUPPORT //
757 } /* End of rt28xx_open */
759 static const struct net_device_ops rt3070_netdev_ops = {
760 .ndo_open = MainVirtualIF_open,
761 .ndo_stop = MainVirtualIF_close,
762 .ndo_do_ioctl = rt28xx_ioctl,
763 .ndo_get_stats = RT28xx_get_ether_stats,
764 .ndo_validate_addr = NULL,
765 .ndo_set_mac_address = eth_mac_addr,
766 .ndo_change_mtu = eth_change_mtu,
768 .ndo_start_xmit = IKANOS_DataFramesTx,
770 .ndo_start_xmit = rt28xx_send_packets,
774 /* Must not be called for mdev and apdev */
775 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
779 CHAR slot_name[IFNAMSIZ];
780 struct net_device *device;
784 // dev->set_multicast_list = ieee80211_set_multicast_list;
785 // dev->change_mtu = ieee80211_change_mtu;
786 #ifdef CONFIG_STA_SUPPORT
787 #if WIRELESS_EXT >= 12
788 if (pAd->OpMode == OPMODE_STA)
790 dev->wireless_handlers = &rt28xx_iw_handler_def;
792 #endif //WIRELESS_EXT >= 12
793 #endif // CONFIG_STA_SUPPORT //
795 #if WIRELESS_EXT < 21
796 dev->get_wireless_stats = rt28xx_get_wireless_stats;
798 // dev->uninit = ieee80211_if_reinit;
799 // dev->destructor = ieee80211_if_free;
800 dev->priv_flags = INT_MAIN;
801 dev->netdev_ops = &rt3070_netdev_ops;
802 // find available device name
803 for (i = 0; i < 8; i++)
805 sprintf(slot_name, "ra%d", i);
807 device = dev_get_by_name(dev_net(dev), slot_name);
817 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
818 Status = NDIS_STATUS_FAILURE;
822 sprintf(dev->name, "ra%d", i);
823 Status = NDIS_STATUS_SUCCESS;
831 ========================================================================
833 Probe RT28XX chipset.
836 _dev_p Point to the PCI or USB device
837 _dev_id_p Point to the PCI or USB device ID
844 ========================================================================
846 INT __devinit rt28xx_probe(
850 OUT PRTMP_ADAPTER *ppAd)
852 struct net_device *net_dev;
853 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
857 struct usb_interface *intf = (struct usb_interface *)_dev_p;
858 struct usb_device *dev_p = interface_to_usbdev(intf);
860 dev_p = usb_get_dev(dev_p);
864 #ifdef CONFIG_STA_SUPPORT
865 DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
866 #endif // CONFIG_STA_SUPPORT //
868 // Check chipset vendor/product ID
869 // if (RT28XXChipsetCheck(_dev_p) == FALSE)
872 net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
875 printk("alloc_netdev failed\n");
881 // if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
884 netif_stop_queue(net_dev);
885 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
886 /* for supporting Network Manager */
887 /* Set the sysfs physical device reference for the network logical device
888 * if set prior to registration will cause a symlink during initialization.
890 SET_NETDEV_DEV(net_dev, &(dev_p->dev));
891 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
893 // Allocate RTMP_ADAPTER miniport adapter structure
894 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
895 RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
897 status = RTMPAllocAdapterBlock(handle, &pAd);
898 if (status != NDIS_STATUS_SUCCESS)
899 goto err_out_free_netdev;
901 net_dev->ml_priv = (PVOID)pAd;
902 pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
904 RT28XXNetDevInit(_dev_p, net_dev, pAd);
906 #ifdef CONFIG_STA_SUPPORT
907 pAd->StaCfg.OriDevType = net_dev->type;
908 #endif // CONFIG_STA_SUPPORT //
910 // Find and assign a free interface name, raxx
911 // RT28XXAvailRANameAssign(net_dev->name);
914 if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
917 #ifdef CONFIG_STA_SUPPORT
918 pAd->OpMode = OPMODE_STA;
919 #endif // CONFIG_STA_SUPPORT //
922 if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
925 // Register this device
926 status = register_netdev(net_dev);
931 RT28XX_DRVDATA_SET(_dev_p);
936 return 0; // probe ok
939 /* --------------------------- ERROR HANDLE --------------------------- */
941 RTMPFreeAdapter(pAd);
945 free_netdev(net_dev);
948 RT28XX_PUT_DEVICE(dev_p);
950 return -ENODEV; /* probe fail */
951 } /* End of rt28xx_probe */
955 ========================================================================
957 The entry point for Linux kernel sent packet to our driver.
960 sk_buff *skb the pointer refer to a sk_buffer.
966 This function is the entry point of Tx Path for Os delivery packet to
967 our driver. You only can put OS-depened & STA/AP common handle procedures
969 ========================================================================
971 int rt28xx_packet_xmit(struct sk_buff *skb)
973 struct net_device *net_dev = skb->dev;
974 PRTMP_ADAPTER pAd = net_dev->ml_priv;
976 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
978 #ifdef CONFIG_STA_SUPPORT
979 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
981 // Drop send request since we are in monitor mode
984 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
988 #endif // CONFIG_STA_SUPPORT //
990 // EapolStart size is 18
993 //printk("bad packet size: %d\n", pkt->len);
994 hex_dump("bad packet", skb->data, skb->len);
995 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
999 RTMP_SET_PACKET_5VT(pPacket, 0);
1000 // MiniportMMRequest(pAd, pkt->data, pkt->len);
1001 #ifdef CONFIG_5VT_ENHANCE
1002 if (*(int*)(skb->cb) == BRIDGE_TAG) {
1003 RTMP_SET_PACKET_5VT(pPacket, 1);
1009 #ifdef CONFIG_STA_SUPPORT
1010 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1013 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
1016 #endif // CONFIG_STA_SUPPORT //
1026 ========================================================================
1027 Routine Description:
1028 Send a packet to WLAN.
1031 skb_p points to our adapter
1032 dev_p which WLAN network interface
1035 0: transmit successfully
1036 otherwise: transmit fail
1039 ========================================================================
1041 INT rt28xx_send_packets(
1042 IN struct sk_buff *skb_p,
1043 IN struct net_device *net_dev)
1045 RTMP_ADAPTER *pAd = net_dev->ml_priv;
1047 if (!(net_dev->flags & IFF_UP))
1049 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
1053 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
1054 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
1056 return rt28xx_packet_xmit(skb_p);
1057 } /* End of MBSS_VirtualIF_PacketSend */
1062 void CfgInitHook(PRTMP_ADAPTER pAd)
1064 pAd->bBroadComHT = TRUE;
1065 } /* End of CfgInitHook */
1068 #if WIRELESS_EXT >= 12
1069 // This function will be called when query /proc
1070 struct iw_statistics *rt28xx_get_wireless_stats(
1071 IN struct net_device *net_dev)
1073 PRTMP_ADAPTER pAd = net_dev->ml_priv;
1076 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
1078 pAd->iw_stats.status = 0; // Status - device dependent for now
1081 pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
1082 if(pAd->iw_stats.qual.qual > 100)
1083 pAd->iw_stats.qual.qual = 100;
1085 #ifdef CONFIG_STA_SUPPORT
1086 if (pAd->OpMode == OPMODE_STA)
1087 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
1088 #endif // CONFIG_STA_SUPPORT //
1090 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
1092 pAd->iw_stats.qual.noise += 256 - 143;
1093 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
1095 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
1096 #endif // IW_QUAL_DBM //
1098 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
1099 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
1101 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
1102 return &pAd->iw_stats;
1103 } /* End of rt28xx_get_wireless_stats */
1104 #endif // WIRELESS_EXT //
1108 void tbtt_tasklet(unsigned long data)
1110 #define MAX_TX_IN_TBTT (16)
1115 IN struct net_device *net_dev,
1116 IN OUT struct ifreq *rq,
1119 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1120 RTMP_ADAPTER *pAd = NULL;
1123 if (net_dev->priv_flags == INT_MAIN)
1125 pAd = net_dev->ml_priv;
1129 pVirtualAd = net_dev->ml_priv;
1130 pAd = pVirtualAd->RtmpDev->ml_priv;
1135 /* if 1st open fail, pAd will be free;
1136 So the net_dev->ml_priv will be NULL in 2rd open */
1141 #ifdef CONFIG_STA_SUPPORT
1142 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1144 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
1146 #endif // CONFIG_STA_SUPPORT //
1152 ========================================================================
1154 Routine Description:
1155 return ethernet statistics counter
1158 net_dev Pointer to net_device
1165 ========================================================================
1167 struct net_device_stats *RT28xx_get_ether_stats(
1168 IN struct net_device *net_dev)
1170 RTMP_ADAPTER *pAd = NULL;
1173 pAd = net_dev->ml_priv;
1178 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1179 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1181 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1182 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1184 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1185 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1187 pAd->stats.rx_dropped = 0;
1188 pAd->stats.tx_dropped = 0;
1190 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
1191 pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
1193 pAd->stats.rx_length_errors = 0;
1194 pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
1195 pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1196 pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
1197 pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
1198 pAd->stats.rx_missed_errors = 0; // receiver missed packet
1200 // detailed tx_errors
1201 pAd->stats.tx_aborted_errors = 0;
1202 pAd->stats.tx_carrier_errors = 0;
1203 pAd->stats.tx_fifo_errors = 0;
1204 pAd->stats.tx_heartbeat_errors = 0;
1205 pAd->stats.tx_window_errors = 0;
1208 pAd->stats.rx_compressed = 0;
1209 pAd->stats.tx_compressed = 0;