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);
63 extern void init_thread_task(PRTMP_ADAPTER pAd);
65 // public function prototype
66 INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
67 IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
69 // private function prototype
70 static int rt28xx_init(IN struct net_device *net_dev);
71 INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);
73 static void CfgInitHook(PRTMP_ADAPTER pAd);
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);
120 VIRTUAL_IF_DOWN(pAd);
122 RT_MOD_DEC_USE_COUNT();
124 return 0; // close ok
128 ========================================================================
133 *net_dev the raxx interface pointer
140 1. if open fail, kernel will not call the close function.
142 (1) Mlme Memory Handler: MlmeHalt()
143 (2) TX & RX: RTMPFreeTxRxRingMemory()
144 (3) BA Reordering: ba_reordering_resource_release()
145 ========================================================================
147 int MainVirtualIF_open(IN struct net_device *net_dev)
149 RTMP_ADAPTER *pAd = net_dev->ml_priv;
151 // Sanity check for pAd
153 return 0; // close ok
155 if (VIRTUAL_IF_UP(pAd) != 0)
158 // increase MODULE use count
159 RT_MOD_INC_USE_COUNT();
161 netif_start_queue(net_dev);
162 netif_carrier_on(net_dev);
163 netif_wake_queue(net_dev);
169 ========================================================================
171 Close raxx interface.
174 *net_dev the raxx interface pointer
181 1. if open fail, kernel will not call the close function.
183 (1) Mlme Memory Handler: MlmeHalt()
184 (2) TX & RX: RTMPFreeTxRxRingMemory()
185 (3) BA Reordering: ba_reordering_resource_release()
186 ========================================================================
188 int rt28xx_close(IN PNET_DEV dev)
190 struct net_device * net_dev = (struct net_device *)dev;
191 RTMP_ADAPTER *pAd = net_dev->ml_priv;
192 BOOLEAN Cancelled = FALSE;
196 DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
198 // Sanity check for pAd
200 return 0; // close ok
202 #ifdef CONFIG_STA_SUPPORT
203 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
205 // If dirver doesn't wake up firmware here,
206 // NICLoadFirmware will hang forever when interface is up again.
207 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) ||
208 RTMP_SET_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND) ||
209 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))
211 AsicForceWakeup(pAd, RTMP_HALT);
214 #ifdef QOS_DLS_SUPPORT
215 // send DLS-TEAR_DOWN message,
216 if (pAd->CommonCfg.bDLSCapable)
220 // tear down local dls table entry
221 for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
223 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
225 RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
226 pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
227 pAd->StaCfg.DLSEntry[i].Valid = FALSE;
231 // tear down peer dls table entry
232 for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
234 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
236 RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
237 pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
238 pAd->StaCfg.DLSEntry[i].Valid = FALSE;
241 RT28XX_MLME_HANDLER(pAd);
243 #endif // QOS_DLS_SUPPORT //
246 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
248 MLME_DISASSOC_REQ_STRUCT DisReq;
249 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
251 COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
252 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
254 MsgElem->Machine = ASSOC_STATE_MACHINE;
255 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
256 MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
257 NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
259 // Prevent to connect AP again in STAMlmePeriodicExec
260 pAd->MlmeAux.AutoReconnectSsidLen= 32;
261 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
263 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
264 MlmeDisassocReqAction(pAd, MsgElem);
272 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
275 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
276 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
278 #ifdef WPA_SUPPLICANT_SUPPORT
279 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
281 union iwreq_data wrqu;
282 // send wireless event to wpa_supplicant for infroming interface down.
283 memset(&wrqu, 0, sizeof(wrqu));
284 wrqu.data.flags = RT_INTERFACE_DOWN;
285 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
287 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
288 #endif // WPA_SUPPLICANT_SUPPORT //
291 pAd->bPCIclkOff = FALSE;
293 #endif // CONFIG_STA_SUPPORT //
295 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
297 for (i = 0 ; i < NUM_OF_TX_RING; i++)
299 while (pAd->DeQueueRunning[i] == TRUE)
301 printk("Waiting for TxQueue[%d] done..........\n", i);
306 // Stop Mlme state machine
309 // Close kernel threads or tasklets
310 kill_thread_task(pAd);
313 #ifdef CONFIG_STA_SUPPORT
314 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
318 #endif // CONFIG_STA_SUPPORT //
321 MeasureReqTabExit(pAd);
325 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
327 NICDisableInterrupt(pAd);
330 // Disable Rx, register value supposed will remain after reset
334 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
336 // Deregister interrupt function
337 RT28XX_IRQ_RELEASE(net_dev)
338 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
342 // Free Ring or USB buffers
343 RTMPFreeTxRxRingMemory(pAd);
345 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
347 #ifdef DOT11_N_SUPPORT
348 // Free BA reorder resource
349 ba_reordering_resource_release(pAd);
350 #endif // DOT11_N_SUPPORT //
353 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
355 return 0; // close ok
356 } /* End of rt28xx_close */
358 static int rt28xx_init(IN struct net_device *net_dev)
360 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)net_dev->ml_priv;
367 #ifdef DOT11_N_SUPPORT
368 // Allocate BA Reordering memory
369 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
370 #endif // DOT11_N_SUPPORT //
372 // Make sure MAC gets ready.
376 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
377 pAd->MACVersion = MacCsr0;
379 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
383 } while (index++ < 100);
385 DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
388 RT28XXDMADisable(pAd);
391 // Load 8051 firmware
392 Status = NICLoadFirmware(pAd);
393 if (Status != NDIS_STATUS_SUCCESS)
395 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
399 NICLoadRateSwitchingParams(pAd);
401 // Disable interrupts here which is as soon as possible
402 // This statement should never be true. We might consider to remove it later
403 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
405 NICDisableInterrupt(pAd);
408 Status = RTMPAllocTxRxRingMemory(pAd);
409 if (Status != NDIS_STATUS_SUCCESS)
411 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
415 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
420 Status = MlmeInit(pAd);
421 if (Status != NDIS_STATUS_SUCCESS)
423 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
427 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
432 RT28XX_TASK_THREAD_INIT(pAd, Status);
433 if (Status != NDIS_STATUS_SUCCESS)
438 #ifdef CONFIG_STA_SUPPORT
439 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
440 NdisAllocateSpinLock(&pAd->MacTabLock);
441 #endif // CONFIG_STA_SUPPORT //
443 MeasureReqTabInit(pAd);
447 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
449 Status = NICInitializeAdapter(pAd, TRUE);
450 if (Status != NDIS_STATUS_SUCCESS)
452 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
453 if (Status != NDIS_STATUS_SUCCESS)
457 // Read parameters from Config File
458 Status = RTMPReadParametersHook(pAd);
460 printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
461 if (Status != NDIS_STATUS_SUCCESS)
463 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
469 //Init Ba Capability parameters.
470 #ifdef DOT11_N_SUPPORT
471 pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
472 pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
473 pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
474 pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
476 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
477 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
478 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
479 #endif // DOT11_N_SUPPORT //
481 printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
483 // We should read EEPROM for all cases. rt2860b
484 NICReadEEPROMParameters(pAd, mac);
486 printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
488 NICInitAsicFromEEPROM(pAd); //rt2860b
490 // Set PHY to appropriate mode
491 TmpPhy = pAd->CommonCfg.PhyMode;
492 pAd->CommonCfg.PhyMode = 0xff;
493 RTMPSetPhyMode(pAd, TmpPhy);
494 #ifdef DOT11_N_SUPPORT
496 #endif // DOT11_N_SUPPORT //
498 // No valid channels.
499 if (pAd->ChannelListNum == 0)
501 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
505 #ifdef DOT11_N_SUPPORT
506 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
507 pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
508 pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
509 #endif // DOT11_N_SUPPORT //
512 VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
513 #endif // IKANOS_VX_1X0 //
516 // Initialize RF register to default value
518 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
519 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
521 // 8051 firmware require the signal during booting time.
522 AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00);
524 if (pAd && (Status != NDIS_STATUS_SUCCESS))
527 // Undo everything if it failed
529 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
531 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
536 // Microsoft HCT require driver send a disconnect event after driver initialization.
537 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
538 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
539 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
545 DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
554 RTMPFreeTxRxRingMemory(pAd);
557 #ifdef DOT11_N_SUPPORT
558 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
559 #endif // DOT11_N_SUPPORT //
560 RT28XX_IRQ_RELEASE(net_dev);
562 // shall not set ml_priv to NULL here because the ml_priv didn't been free yet.
563 //net_dev->ml_priv = 0;
566 #endif // INF_AMAZON_SE //
567 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
569 } /* End of rt28xx_init */
573 ========================================================================
578 *net_dev the raxx interface pointer
585 ========================================================================
587 int rt28xx_open(IN PNET_DEV dev)
589 struct net_device * net_dev = (struct net_device *)dev;
590 PRTMP_ADAPTER pAd = net_dev->ml_priv;
595 // Sanity check for pAd
598 /* if 1st open fail, pAd will be free;
599 So the net_dev->ml_priv will be NULL in 2rd open */
604 pObj = (POS_COOKIE)pAd->OS_Cookie;
606 // reset Adapter flags
607 RTMP_CLEAR_FLAGS(pAd);
609 // Request interrupt service routine for PCI device
610 // register the interrupt routine with the os
611 RT28XX_IRQ_REQUEST(net_dev);
614 // Init BssTab & ChannelInfo tabbles for auto channel select.
618 if (rt28xx_init(net_dev) == FALSE)
621 #ifdef CONFIG_STA_SUPPORT
622 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
624 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
625 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
627 #endif // CONFIG_STA_SUPPORT //
629 // Set up the Mac address
630 NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
632 // Init IRQ parameters
633 RT28XX_IRQ_INIT(pAd);
635 // Various AP function init
637 #ifdef CONFIG_STA_SUPPORT
638 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
640 #ifdef WPA_SUPPLICANT_SUPPORT
641 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
643 union iwreq_data wrqu;
644 // send wireless event to wpa_supplicant for infroming interface down.
645 memset(&wrqu, 0, sizeof(wrqu));
646 wrqu.data.flags = RT_INTERFACE_UP;
647 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
649 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
650 #endif // WPA_SUPPLICANT_SUPPORT //
653 #endif // CONFIG_STA_SUPPORT //
656 RT28XX_IRQ_ENABLE(pAd);
660 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
664 RTMP_IO_READ32(pAd, 0x1300, ®); // clear garbage interrupts
665 printk("0x1300 = %08x\n", reg);
668 #ifdef CONFIG_STA_SUPPORT
669 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
670 RTMPInitPCIeLinkCtrlValue(pAd);
671 #endif // CONFIG_STA_SUPPORT //
677 } /* End of rt28xx_open */
679 static const struct net_device_ops rt2860_netdev_ops = {
680 .ndo_open = MainVirtualIF_open,
681 .ndo_stop = MainVirtualIF_close,
682 .ndo_do_ioctl = rt28xx_ioctl,
683 .ndo_get_stats = RT28xx_get_ether_stats,
684 .ndo_validate_addr = NULL,
685 .ndo_set_mac_address = eth_mac_addr,
686 .ndo_change_mtu = eth_change_mtu,
688 .ndo_start_xmit = IKANOS_DataFramesTx,
690 .ndo_start_xmit = rt28xx_send_packets,
694 /* Must not be called for mdev and apdev */
695 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
699 CHAR slot_name[IFNAMSIZ];
700 struct net_device *device;
705 #ifdef CONFIG_STA_SUPPORT
706 #if WIRELESS_EXT >= 12
707 if (pAd->OpMode == OPMODE_STA)
709 dev->wireless_handlers = &rt28xx_iw_handler_def;
711 #endif //WIRELESS_EXT >= 12
712 #endif // CONFIG_STA_SUPPORT //
714 #if WIRELESS_EXT < 21
715 dev->get_wireless_stats = rt28xx_get_wireless_stats;
717 dev->priv_flags = INT_MAIN;
718 dev->netdev_ops = &rt2860_netdev_ops;
719 // find available device name
720 for (i = 0; i < 8; i++)
722 sprintf(slot_name, "ra%d", i);
724 device = dev_get_by_name(dev_net(dev), slot_name);
734 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
735 Status = NDIS_STATUS_FAILURE;
739 sprintf(dev->name, "ra%d", i);
740 Status = NDIS_STATUS_SUCCESS;
748 ========================================================================
750 Probe RT28XX chipset.
753 _dev_p Point to the PCI or USB device
754 _dev_id_p Point to the PCI or USB device ID
761 ========================================================================
763 INT __devinit rt28xx_probe(
767 OUT PRTMP_ADAPTER *ppAd)
769 struct net_device *net_dev;
770 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
773 struct pci_dev *dev_p = (struct pci_dev *)_dev_p;
776 #ifdef CONFIG_STA_SUPPORT
777 DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
778 #endif // CONFIG_STA_SUPPORT //
780 net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
783 printk("alloc_netdev failed\n");
788 netif_stop_queue(net_dev);
789 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
790 /* for supporting Network Manager */
791 /* Set the sysfs physical device reference for the network logical device
792 * if set prior to registration will cause a symlink during initialization.
794 SET_NETDEV_DEV(net_dev, &(dev_p->dev));
795 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
797 // Allocate RTMP_ADAPTER miniport adapter structure
798 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
799 RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
801 status = RTMPAllocAdapterBlock(handle, &pAd);
802 if (status != NDIS_STATUS_SUCCESS)
803 goto err_out_free_netdev;
805 net_dev->ml_priv = (PVOID)pAd;
806 pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
808 RT28XXNetDevInit(_dev_p, net_dev, pAd);
810 #ifdef CONFIG_STA_SUPPORT
811 pAd->StaCfg.OriDevType = net_dev->type;
812 #endif // CONFIG_STA_SUPPORT //
815 if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
818 #ifdef CONFIG_STA_SUPPORT
819 pAd->OpMode = OPMODE_STA;
820 #endif // CONFIG_STA_SUPPORT //
823 if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
826 // Register this device
827 status = register_netdev(net_dev);
832 RT28XX_DRVDATA_SET(_dev_p);
835 return 0; // probe ok
838 /* --------------------------- ERROR HANDLE --------------------------- */
840 RTMPFreeAdapter(pAd);
844 free_netdev(net_dev);
847 RT28XX_PUT_DEVICE(dev_p);
849 return -ENODEV; /* probe fail */
850 } /* End of rt28xx_probe */
854 ========================================================================
856 The entry point for Linux kernel sent packet to our driver.
859 sk_buff *skb the pointer refer to a sk_buffer.
865 This function is the entry point of Tx Path for Os delivery packet to
866 our driver. You only can put OS-depened & STA/AP common handle procedures
868 ========================================================================
870 int rt28xx_packet_xmit(struct sk_buff *skb)
872 struct net_device *net_dev = skb->dev;
873 PRTMP_ADAPTER pAd = net_dev->ml_priv;
875 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
877 #ifdef CONFIG_STA_SUPPORT
878 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
880 // Drop send request since we are in monitor mode
883 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
887 #endif // CONFIG_STA_SUPPORT //
889 // EapolStart size is 18
892 //printk("bad packet size: %d\n", pkt->len);
893 hex_dump("bad packet", skb->data, skb->len);
894 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
898 RTMP_SET_PACKET_5VT(pPacket, 0);
899 #ifdef CONFIG_5VT_ENHANCE
900 if (*(int*)(skb->cb) == BRIDGE_TAG) {
901 RTMP_SET_PACKET_5VT(pPacket, 1);
907 #ifdef CONFIG_STA_SUPPORT
908 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
911 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
914 #endif // CONFIG_STA_SUPPORT //
924 ========================================================================
926 Send a packet to WLAN.
929 skb_p points to our adapter
930 dev_p which WLAN network interface
933 0: transmit successfully
934 otherwise: transmit fail
937 ========================================================================
939 INT rt28xx_send_packets(
940 IN struct sk_buff *skb_p,
941 IN struct net_device *net_dev)
943 RTMP_ADAPTER *pAd = net_dev->ml_priv;
944 if (!(net_dev->flags & IFF_UP))
946 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
950 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
951 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
953 return rt28xx_packet_xmit(skb_p);
955 } /* End of MBSS_VirtualIF_PacketSend */
960 void CfgInitHook(PRTMP_ADAPTER pAd)
962 pAd->bBroadComHT = TRUE;
963 } /* End of CfgInitHook */
966 #if WIRELESS_EXT >= 12
967 // This function will be called when query /proc
968 struct iw_statistics *rt28xx_get_wireless_stats(
969 IN struct net_device *net_dev)
971 PRTMP_ADAPTER pAd = net_dev->ml_priv;
974 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
976 pAd->iw_stats.status = 0; // Status - device dependent for now
979 pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
980 if(pAd->iw_stats.qual.qual > 100)
981 pAd->iw_stats.qual.qual = 100;
983 #ifdef CONFIG_STA_SUPPORT
984 if (pAd->OpMode == OPMODE_STA)
985 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
986 #endif // CONFIG_STA_SUPPORT //
988 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
990 pAd->iw_stats.qual.noise += 256 - 143;
991 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
993 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
994 #endif // IW_QUAL_DBM //
996 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
997 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
999 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
1000 return &pAd->iw_stats;
1001 } /* End of rt28xx_get_wireless_stats */
1002 #endif // WIRELESS_EXT //
1006 void tbtt_tasklet(unsigned long data)
1008 #define MAX_TX_IN_TBTT (16)
1013 IN struct net_device *net_dev,
1014 IN OUT struct ifreq *rq,
1017 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1018 RTMP_ADAPTER *pAd = NULL;
1021 if (net_dev->priv_flags == INT_MAIN)
1023 pAd = net_dev->ml_priv;
1027 pVirtualAd = net_dev->ml_priv;
1028 pAd = pVirtualAd->RtmpDev->ml_priv;
1033 /* if 1st open fail, pAd will be free;
1034 So the net_dev->ml_priv will be NULL in 2rd open */
1039 #ifdef CONFIG_STA_SUPPORT
1040 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1042 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
1044 #endif // CONFIG_STA_SUPPORT //
1050 ========================================================================
1052 Routine Description:
1053 return ethernet statistics counter
1056 net_dev Pointer to net_device
1063 ========================================================================
1065 struct net_device_stats *RT28xx_get_ether_stats(
1066 IN struct net_device *net_dev)
1068 RTMP_ADAPTER *pAd = NULL;
1071 pAd = net_dev->ml_priv;
1076 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1077 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1079 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1080 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1082 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1083 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1085 pAd->stats.rx_dropped = 0;
1086 pAd->stats.tx_dropped = 0;
1088 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
1089 pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
1091 pAd->stats.rx_length_errors = 0;
1092 pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
1093 pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1094 pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
1095 pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
1096 pAd->stats.rx_missed_errors = 0; // receiver missed packet
1098 // detailed tx_errors
1099 pAd->stats.tx_aborted_errors = 0;
1100 pAd->stats.tx_carrier_errors = 0;
1101 pAd->stats.tx_fifo_errors = 0;
1102 pAd->stats.tx_heartbeat_errors = 0;
1103 pAd->stats.tx_window_errors = 0;
1106 pAd->stats.rx_compressed = 0;
1107 pAd->stats.tx_compressed = 0;