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);
215 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
217 MLME_DISASSOC_REQ_STRUCT DisReq;
218 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
220 COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
221 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
223 MsgElem->Machine = ASSOC_STATE_MACHINE;
224 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
225 MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
226 NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
228 // Prevent to connect AP again in STAMlmePeriodicExec
229 pAd->MlmeAux.AutoReconnectSsidLen= 32;
230 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
232 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
233 MlmeDisassocReqAction(pAd, MsgElem);
241 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
244 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
245 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
247 #ifdef WPA_SUPPLICANT_SUPPORT
248 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
250 union iwreq_data wrqu;
251 // send wireless event to wpa_supplicant for infroming interface down.
252 memset(&wrqu, 0, sizeof(wrqu));
253 wrqu.data.flags = RT_INTERFACE_DOWN;
254 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
256 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
257 #endif // WPA_SUPPLICANT_SUPPORT //
260 pAd->bPCIclkOff = FALSE;
262 #endif // CONFIG_STA_SUPPORT //
264 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
266 for (i = 0 ; i < NUM_OF_TX_RING; i++)
268 while (pAd->DeQueueRunning[i] == TRUE)
270 printk("Waiting for TxQueue[%d] done..........\n", i);
275 // Stop Mlme state machine
278 // Close kernel threads or tasklets
279 kill_thread_task(pAd);
282 #ifdef CONFIG_STA_SUPPORT
283 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
287 #endif // CONFIG_STA_SUPPORT //
290 MeasureReqTabExit(pAd);
294 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
296 NICDisableInterrupt(pAd);
299 // Disable Rx, register value supposed will remain after reset
303 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
305 // Deregister interrupt function
306 RT28XX_IRQ_RELEASE(net_dev)
307 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
311 // Free Ring or USB buffers
312 RTMPFreeTxRxRingMemory(pAd);
314 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
316 #ifdef DOT11_N_SUPPORT
317 // Free BA reorder resource
318 ba_reordering_resource_release(pAd);
319 #endif // DOT11_N_SUPPORT //
322 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
324 return 0; // close ok
325 } /* End of rt28xx_close */
327 static int rt28xx_init(IN struct net_device *net_dev)
329 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)net_dev->ml_priv;
336 #ifdef DOT11_N_SUPPORT
337 // Allocate BA Reordering memory
338 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
339 #endif // DOT11_N_SUPPORT //
341 // Make sure MAC gets ready.
345 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
346 pAd->MACVersion = MacCsr0;
348 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
352 } while (index++ < 100);
354 DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
357 RT28XXDMADisable(pAd);
360 // Load 8051 firmware
361 Status = NICLoadFirmware(pAd);
362 if (Status != NDIS_STATUS_SUCCESS)
364 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
368 NICLoadRateSwitchingParams(pAd);
370 // Disable interrupts here which is as soon as possible
371 // This statement should never be true. We might consider to remove it later
372 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
374 NICDisableInterrupt(pAd);
377 Status = RTMPAllocTxRxRingMemory(pAd);
378 if (Status != NDIS_STATUS_SUCCESS)
380 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
384 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
389 Status = MlmeInit(pAd);
390 if (Status != NDIS_STATUS_SUCCESS)
392 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
396 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
401 RT28XX_TASK_THREAD_INIT(pAd, Status);
402 if (Status != NDIS_STATUS_SUCCESS)
407 #ifdef CONFIG_STA_SUPPORT
408 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
409 NdisAllocateSpinLock(&pAd->MacTabLock);
410 #endif // CONFIG_STA_SUPPORT //
412 MeasureReqTabInit(pAd);
416 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
418 Status = NICInitializeAdapter(pAd, TRUE);
419 if (Status != NDIS_STATUS_SUCCESS)
421 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
422 if (Status != NDIS_STATUS_SUCCESS)
426 // Read parameters from Config File
427 Status = RTMPReadParametersHook(pAd);
429 printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
430 if (Status != NDIS_STATUS_SUCCESS)
432 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
438 //Init Ba Capability parameters.
439 #ifdef DOT11_N_SUPPORT
440 pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
441 pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
442 pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
443 pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
445 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
446 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
447 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
448 #endif // DOT11_N_SUPPORT //
450 printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
452 // We should read EEPROM for all cases. rt2860b
453 NICReadEEPROMParameters(pAd, mac);
455 printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
457 NICInitAsicFromEEPROM(pAd); //rt2860b
459 // Set PHY to appropriate mode
460 TmpPhy = pAd->CommonCfg.PhyMode;
461 pAd->CommonCfg.PhyMode = 0xff;
462 RTMPSetPhyMode(pAd, TmpPhy);
463 #ifdef DOT11_N_SUPPORT
465 #endif // DOT11_N_SUPPORT //
467 // No valid channels.
468 if (pAd->ChannelListNum == 0)
470 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
474 #ifdef DOT11_N_SUPPORT
475 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
476 pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
477 pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
478 #endif // DOT11_N_SUPPORT //
481 VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
482 #endif // IKANOS_VX_1X0 //
485 // Initialize RF register to default value
487 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
488 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
490 // 8051 firmware require the signal during booting time.
491 AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00);
493 if (pAd && (Status != NDIS_STATUS_SUCCESS))
496 // Undo everything if it failed
498 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
500 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
505 // Microsoft HCT require driver send a disconnect event after driver initialization.
506 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
507 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
508 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
514 DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
523 RTMPFreeTxRxRingMemory(pAd);
526 #ifdef DOT11_N_SUPPORT
527 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
528 #endif // DOT11_N_SUPPORT //
529 RT28XX_IRQ_RELEASE(net_dev);
531 // shall not set ml_priv to NULL here because the ml_priv didn't been free yet.
532 //net_dev->ml_priv = 0;
534 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
536 } /* End of rt28xx_init */
540 ========================================================================
545 *net_dev the raxx interface pointer
552 ========================================================================
554 int rt28xx_open(IN PNET_DEV dev)
556 struct net_device * net_dev = (struct net_device *)dev;
557 PRTMP_ADAPTER pAd = net_dev->ml_priv;
562 // Sanity check for pAd
565 /* if 1st open fail, pAd will be free;
566 So the net_dev->ml_priv will be NULL in 2rd open */
571 pObj = (POS_COOKIE)pAd->OS_Cookie;
573 // reset Adapter flags
574 RTMP_CLEAR_FLAGS(pAd);
576 // Request interrupt service routine for PCI device
577 // register the interrupt routine with the os
578 RT28XX_IRQ_REQUEST(net_dev);
581 // Init BssTab & ChannelInfo tabbles for auto channel select.
585 if (rt28xx_init(net_dev) == FALSE)
588 #ifdef CONFIG_STA_SUPPORT
589 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
591 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
592 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
594 #endif // CONFIG_STA_SUPPORT //
596 // Set up the Mac address
597 NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
599 // Init IRQ parameters
600 RT28XX_IRQ_INIT(pAd);
602 // Various AP function init
604 #ifdef CONFIG_STA_SUPPORT
605 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
607 #ifdef WPA_SUPPLICANT_SUPPORT
608 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
610 union iwreq_data wrqu;
611 // send wireless event to wpa_supplicant for infroming interface down.
612 memset(&wrqu, 0, sizeof(wrqu));
613 wrqu.data.flags = RT_INTERFACE_UP;
614 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
616 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
617 #endif // WPA_SUPPLICANT_SUPPORT //
620 #endif // CONFIG_STA_SUPPORT //
623 RT28XX_IRQ_ENABLE(pAd);
627 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
631 RTMP_IO_READ32(pAd, 0x1300, ®); // clear garbage interrupts
632 printk("0x1300 = %08x\n", reg);
635 #ifdef CONFIG_STA_SUPPORT
636 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
637 RTMPInitPCIeLinkCtrlValue(pAd);
638 #endif // CONFIG_STA_SUPPORT //
644 } /* End of rt28xx_open */
646 static const struct net_device_ops rt2860_netdev_ops = {
647 .ndo_open = MainVirtualIF_open,
648 .ndo_stop = MainVirtualIF_close,
649 .ndo_do_ioctl = rt28xx_ioctl,
650 .ndo_get_stats = RT28xx_get_ether_stats,
651 .ndo_validate_addr = NULL,
652 .ndo_set_mac_address = eth_mac_addr,
653 .ndo_change_mtu = eth_change_mtu,
655 .ndo_start_xmit = IKANOS_DataFramesTx,
657 .ndo_start_xmit = rt28xx_send_packets,
661 /* Must not be called for mdev and apdev */
662 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
666 CHAR slot_name[IFNAMSIZ];
667 struct net_device *device;
672 #ifdef CONFIG_STA_SUPPORT
673 #if WIRELESS_EXT >= 12
674 if (pAd->OpMode == OPMODE_STA)
676 dev->wireless_handlers = &rt28xx_iw_handler_def;
678 #endif //WIRELESS_EXT >= 12
679 #endif // CONFIG_STA_SUPPORT //
681 #if WIRELESS_EXT < 21
682 dev->get_wireless_stats = rt28xx_get_wireless_stats;
684 dev->priv_flags = INT_MAIN;
685 dev->netdev_ops = &rt2860_netdev_ops;
686 // find available device name
687 for (i = 0; i < 8; i++)
689 sprintf(slot_name, "ra%d", i);
691 device = dev_get_by_name(dev_net(dev), slot_name);
701 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
702 Status = NDIS_STATUS_FAILURE;
706 sprintf(dev->name, "ra%d", i);
707 Status = NDIS_STATUS_SUCCESS;
715 ========================================================================
717 Probe RT28XX chipset.
720 _dev_p Point to the PCI or USB device
721 _dev_id_p Point to the PCI or USB device ID
728 ========================================================================
730 INT __devinit rt28xx_probe(
734 OUT PRTMP_ADAPTER *ppAd)
736 struct net_device *net_dev;
737 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
740 struct pci_dev *dev_p = (struct pci_dev *)_dev_p;
743 #ifdef CONFIG_STA_SUPPORT
744 DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
745 #endif // CONFIG_STA_SUPPORT //
747 net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
750 printk("alloc_netdev failed\n");
755 netif_stop_queue(net_dev);
756 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
757 /* for supporting Network Manager */
758 /* Set the sysfs physical device reference for the network logical device
759 * if set prior to registration will cause a symlink during initialization.
761 SET_NETDEV_DEV(net_dev, &(dev_p->dev));
762 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
764 // Allocate RTMP_ADAPTER miniport adapter structure
765 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
766 RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
768 status = RTMPAllocAdapterBlock(handle, &pAd);
769 if (status != NDIS_STATUS_SUCCESS)
770 goto err_out_free_netdev;
772 net_dev->ml_priv = (PVOID)pAd;
773 pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
775 RT28XXNetDevInit(_dev_p, net_dev, pAd);
777 #ifdef CONFIG_STA_SUPPORT
778 pAd->StaCfg.OriDevType = net_dev->type;
779 #endif // CONFIG_STA_SUPPORT //
782 if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
785 #ifdef CONFIG_STA_SUPPORT
786 pAd->OpMode = OPMODE_STA;
787 #endif // CONFIG_STA_SUPPORT //
790 if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
793 // Register this device
794 status = register_netdev(net_dev);
799 RT28XX_DRVDATA_SET(_dev_p);
802 return 0; // probe ok
805 /* --------------------------- ERROR HANDLE --------------------------- */
807 RTMPFreeAdapter(pAd);
811 free_netdev(net_dev);
814 RT28XX_PUT_DEVICE(dev_p);
816 return -ENODEV; /* probe fail */
817 } /* End of rt28xx_probe */
821 ========================================================================
823 The entry point for Linux kernel sent packet to our driver.
826 sk_buff *skb the pointer refer to a sk_buffer.
832 This function is the entry point of Tx Path for Os delivery packet to
833 our driver. You only can put OS-depened & STA/AP common handle procedures
835 ========================================================================
837 int rt28xx_packet_xmit(struct sk_buff *skb)
839 struct net_device *net_dev = skb->dev;
840 PRTMP_ADAPTER pAd = net_dev->ml_priv;
842 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
844 #ifdef CONFIG_STA_SUPPORT
845 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
847 // Drop send request since we are in monitor mode
850 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
854 #endif // CONFIG_STA_SUPPORT //
856 // EapolStart size is 18
859 //printk("bad packet size: %d\n", pkt->len);
860 hex_dump("bad packet", skb->data, skb->len);
861 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
865 RTMP_SET_PACKET_5VT(pPacket, 0);
866 #ifdef CONFIG_5VT_ENHANCE
867 if (*(int*)(skb->cb) == BRIDGE_TAG) {
868 RTMP_SET_PACKET_5VT(pPacket, 1);
874 #ifdef CONFIG_STA_SUPPORT
875 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
878 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
881 #endif // CONFIG_STA_SUPPORT //
891 ========================================================================
893 Send a packet to WLAN.
896 skb_p points to our adapter
897 dev_p which WLAN network interface
900 0: transmit successfully
901 otherwise: transmit fail
904 ========================================================================
906 INT rt28xx_send_packets(
907 IN struct sk_buff *skb_p,
908 IN struct net_device *net_dev)
910 RTMP_ADAPTER *pAd = net_dev->ml_priv;
911 if (!(net_dev->flags & IFF_UP))
913 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
917 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
918 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
920 return rt28xx_packet_xmit(skb_p);
922 } /* End of MBSS_VirtualIF_PacketSend */
927 void CfgInitHook(PRTMP_ADAPTER pAd)
929 pAd->bBroadComHT = TRUE;
930 } /* End of CfgInitHook */
933 #if WIRELESS_EXT >= 12
934 // This function will be called when query /proc
935 struct iw_statistics *rt28xx_get_wireless_stats(
936 IN struct net_device *net_dev)
938 PRTMP_ADAPTER pAd = net_dev->ml_priv;
941 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
943 pAd->iw_stats.status = 0; // Status - device dependent for now
946 pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
947 if(pAd->iw_stats.qual.qual > 100)
948 pAd->iw_stats.qual.qual = 100;
950 #ifdef CONFIG_STA_SUPPORT
951 if (pAd->OpMode == OPMODE_STA)
952 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
953 #endif // CONFIG_STA_SUPPORT //
955 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
957 pAd->iw_stats.qual.noise += 256 - 143;
958 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
960 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
961 #endif // IW_QUAL_DBM //
963 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
964 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
966 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
967 return &pAd->iw_stats;
968 } /* End of rt28xx_get_wireless_stats */
969 #endif // WIRELESS_EXT //
973 void tbtt_tasklet(unsigned long data)
975 #define MAX_TX_IN_TBTT (16)
980 IN struct net_device *net_dev,
981 IN OUT struct ifreq *rq,
984 VIRTUAL_ADAPTER *pVirtualAd = NULL;
985 RTMP_ADAPTER *pAd = NULL;
988 if (net_dev->priv_flags == INT_MAIN)
990 pAd = net_dev->ml_priv;
994 pVirtualAd = net_dev->ml_priv;
995 pAd = pVirtualAd->RtmpDev->ml_priv;
1000 /* if 1st open fail, pAd will be free;
1001 So the net_dev->ml_priv will be NULL in 2rd open */
1006 #ifdef CONFIG_STA_SUPPORT
1007 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1009 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
1011 #endif // CONFIG_STA_SUPPORT //
1017 ========================================================================
1019 Routine Description:
1020 return ethernet statistics counter
1023 net_dev Pointer to net_device
1030 ========================================================================
1032 struct net_device_stats *RT28xx_get_ether_stats(
1033 IN struct net_device *net_dev)
1035 RTMP_ADAPTER *pAd = NULL;
1038 pAd = net_dev->ml_priv;
1043 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1044 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1046 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1047 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1049 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1050 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1052 pAd->stats.rx_dropped = 0;
1053 pAd->stats.tx_dropped = 0;
1055 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
1056 pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
1058 pAd->stats.rx_length_errors = 0;
1059 pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
1060 pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1061 pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
1062 pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
1063 pAd->stats.rx_missed_errors = 0; // receiver missed packet
1065 // detailed tx_errors
1066 pAd->stats.tx_aborted_errors = 0;
1067 pAd->stats.tx_carrier_errors = 0;
1068 pAd->stats.tx_fifo_errors = 0;
1069 pAd->stats.tx_heartbeat_errors = 0;
1070 pAd->stats.tx_window_errors = 0;
1073 pAd->stats.rx_compressed = 0;
1074 pAd->stats.tx_compressed = 0;