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 extern BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
58 extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
59 extern NDIS_STATUS NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd);
62 // public function prototype
63 INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
64 IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
66 // private function prototype
67 static int rt28xx_init(IN struct net_device *net_dev);
68 INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);
70 static void CfgInitHook(PRTMP_ADAPTER pAd);
71 //static BOOLEAN RT28XXAvailRANameAssign(IN CHAR *name_p);
73 extern const struct iw_handler_def rt28xx_iw_handler_def;
75 #if WIRELESS_EXT >= 12
76 // This function will be called when query /proc
77 struct iw_statistics *rt28xx_get_wireless_stats(
78 IN struct net_device *net_dev);
81 struct net_device_stats *RT28xx_get_ether_stats(
82 IN struct net_device *net_dev);
85 ========================================================================
90 *net_dev the raxx interface pointer
97 1. if open fail, kernel will not call the close function.
99 (1) Mlme Memory Handler: MlmeHalt()
100 (2) TX & RX: RTMPFreeTxRxRingMemory()
101 (3) BA Reordering: ba_reordering_resource_release()
102 ========================================================================
104 int MainVirtualIF_close(IN struct net_device *net_dev)
106 RTMP_ADAPTER *pAd = net_dev->ml_priv;
108 // Sanity check for pAd
110 return 0; // close ok
112 netif_carrier_off(pAd->net_dev);
113 netif_stop_queue(pAd->net_dev);
117 VIRTUAL_IF_DOWN(pAd);
119 RT_MOD_DEC_USE_COUNT();
121 return 0; // close ok
125 ========================================================================
130 *net_dev the raxx interface pointer
137 1. if open fail, kernel will not call the close function.
139 (1) Mlme Memory Handler: MlmeHalt()
140 (2) TX & RX: RTMPFreeTxRxRingMemory()
141 (3) BA Reordering: ba_reordering_resource_release()
142 ========================================================================
144 int MainVirtualIF_open(IN struct net_device *net_dev)
146 RTMP_ADAPTER *pAd = net_dev->ml_priv;
148 // Sanity check for pAd
150 return 0; // close ok
152 if (VIRTUAL_IF_UP(pAd) != 0)
155 // increase MODULE use count
156 RT_MOD_INC_USE_COUNT();
158 netif_start_queue(net_dev);
159 netif_carrier_on(net_dev);
160 netif_wake_queue(net_dev);
166 ========================================================================
168 Close raxx interface.
171 *net_dev the raxx interface pointer
178 1. if open fail, kernel will not call the close function.
180 (1) Mlme Memory Handler: MlmeHalt()
181 (2) TX & RX: RTMPFreeTxRxRingMemory()
182 (3) BA Reordering: ba_reordering_resource_release()
183 ========================================================================
185 int rt28xx_close(IN PNET_DEV dev)
187 struct net_device * net_dev = (struct net_device *)dev;
188 RTMP_ADAPTER *pAd = net_dev->ml_priv;
189 BOOLEAN Cancelled = FALSE;
192 DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
193 DECLARE_WAITQUEUE(wait, current);
195 //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
199 DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
201 // Sanity check for pAd
203 return 0; // close ok
205 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
208 // If dirver doesn't wake up firmware here,
209 // NICLoadFirmware will hang forever when interface is up again.
210 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
212 AsicForceWakeup(pAd, TRUE);
216 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
218 MLME_DISASSOC_REQ_STRUCT DisReq;
219 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
221 COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
222 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
224 MsgElem->Machine = ASSOC_STATE_MACHINE;
225 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
226 MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
227 NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
229 // Prevent to connect AP again in STAMlmePeriodicExec
230 pAd->MlmeAux.AutoReconnectSsidLen= 32;
231 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
233 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
234 MlmeDisassocReqAction(pAd, MsgElem);
241 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
245 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
248 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
249 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
254 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
256 for (i = 0 ; i < NUM_OF_TX_RING; i++)
258 while (pAd->DeQueueRunning[i] == TRUE)
260 printk("Waiting for TxQueue[%d] done..........\n", i);
266 // ensure there are no more active urbs.
267 add_wait_queue (&unlink_wakeup, &wait);
268 pAd->wait = &unlink_wakeup;
270 // maybe wait for deletions to finish.
272 //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
275 unsigned long IrqFlags;
277 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
278 if (pAd->PendingRx == 0)
280 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
283 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
285 msleep(UNLINK_TIMEOUT_MS); //Time in millisecond
289 remove_wait_queue (&unlink_wakeup, &wait);
292 //RTUSBCleanUpMLMEWaitQueue(pAd); /*not used in RT28xx*/
296 // We need clear timerQ related structure before exits of the timer thread.
297 RT2870_TimerQ_Exit(pAd);
298 // Close kernel threads or tasklets
299 RT28xxThreadTerminate(pAd);
302 // Stop Mlme state machine
305 // Close kernel threads or tasklets
306 kill_thread_task(pAd);
308 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
314 MeasureReqTabExit(pAd);
320 // Free Ring or USB buffers
321 RTMPFreeTxRxRingMemory(pAd);
323 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
325 // Free BA reorder resource
326 ba_reordering_resource_release(pAd);
328 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
330 return 0; // close ok
331 } /* End of rt28xx_close */
333 static int rt28xx_init(IN struct net_device *net_dev)
335 PRTMP_ADAPTER pAd = net_dev->ml_priv;
340 // OID_SET_HT_PHYMODE SetHT;
341 // WPDMA_GLO_CFG_STRUC GloCfg;
344 // Allocate BA Reordering memory
345 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
347 // Make sure MAC gets ready.
351 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
352 pAd->MACVersion = MacCsr0;
354 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
358 } while (index++ < 100);
360 DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
361 /*Iverson patch PCIE L1 issue */
364 RT28XXDMADisable(pAd);
367 // Load 8051 firmware
368 Status = NICLoadFirmware(pAd);
369 if (Status != NDIS_STATUS_SUCCESS)
371 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
375 NICLoadRateSwitchingParams(pAd);
377 // Disable interrupts here which is as soon as possible
378 // This statement should never be true. We might consider to remove it later
380 Status = RTMPAllocTxRxRingMemory(pAd);
381 if (Status != NDIS_STATUS_SUCCESS)
383 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
387 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
392 Status = MlmeInit(pAd);
393 if (Status != NDIS_STATUS_SUCCESS)
395 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
399 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
404 // We need init timerQ related structure before create the timer thread.
405 RT2870_TimerQ_Init(pAd);
408 RT28XX_TASK_THREAD_INIT(pAd, Status);
409 if (Status != NDIS_STATUS_SUCCESS)
412 // COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
413 // pAd->bForcePrintTX = TRUE;
417 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
418 NdisAllocateSpinLock(&pAd->MacTabLock);
420 MeasureReqTabInit(pAd);
424 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
426 Status = NICInitializeAdapter(pAd, TRUE);
427 if (Status != NDIS_STATUS_SUCCESS)
429 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
430 if (Status != NDIS_STATUS_SUCCESS)
434 // Read parameters from Config File
435 Status = RTMPReadParametersHook(pAd);
437 printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
438 if (Status != NDIS_STATUS_SUCCESS)
440 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
445 pAd->CommonCfg.bMultipleIRP = FALSE;
447 if (pAd->CommonCfg.bMultipleIRP)
448 pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
450 pAd->CommonCfg.NumOfBulkInIRP = 1;
454 //Init Ba Capability parameters.
455 // RT28XX_BA_INIT(pAd);
456 pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
457 pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
458 pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
459 pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
461 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
462 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
463 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
465 // after reading Registry, we now know if in AP mode or STA mode
467 // Load 8051 firmware; crash when FW image not existent
468 // Status = NICLoadFirmware(pAd);
469 // if (Status != NDIS_STATUS_SUCCESS)
472 printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
474 // We should read EEPROM for all cases. rt2860b
475 NICReadEEPROMParameters(pAd, mac);
477 printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
479 NICInitAsicFromEEPROM(pAd); //rt2860b
481 // Set PHY to appropriate mode
482 TmpPhy = pAd->CommonCfg.PhyMode;
483 pAd->CommonCfg.PhyMode = 0xff;
484 RTMPSetPhyMode(pAd, TmpPhy);
487 // No valid channels.
488 if (pAd->ChannelListNum == 0)
490 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
494 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
495 pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
496 pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
499 //Init RT30xx RFRegisters after read RFIC type from EEPROM
500 NICInitRT30xxRFRegisters(pAd);
503 // APInitialize(pAd);
506 VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
507 #endif // IKANOS_VX_1X0 //
510 // Initialize RF register to default value
512 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
513 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
515 if (pAd && (Status != NDIS_STATUS_SUCCESS))
518 // Undo everything if it failed
520 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
522 // NdisMDeregisterInterrupt(&pAd->Interrupt);
523 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
525 // RTMPFreeAdapter(pAd); // we will free it in disconnect()
529 // Microsoft HCT require driver send a disconnect event after driver initialization.
530 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
531 // pAd->IndicateMediaState = NdisMediaStateDisconnected;
532 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
534 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
538 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
539 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
542 // Support multiple BulkIn IRP,
543 // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
545 for(index=0; index<pAd->CommonCfg.NumOfBulkInIRP; index++)
547 RTUSBBulkReceive(pAd);
548 DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n" ));
554 DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
563 RTMPFreeTxRxRingMemory(pAd);
564 // RTMPFreeAdapter(pAd);
566 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
567 RT28XX_IRQ_RELEASE(net_dev);
569 // shall not set priv to NULL here because the priv didn't been free yet.
570 //net_dev->ml_priv = 0;
572 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
574 } /* End of rt28xx_init */
578 ========================================================================
583 *net_dev the raxx interface pointer
590 ========================================================================
592 int rt28xx_open(IN PNET_DEV dev)
594 struct net_device * net_dev = (struct net_device *)dev;
595 PRTMP_ADAPTER pAd = net_dev->ml_priv;
600 // Sanity check for pAd
603 /* if 1st open fail, pAd will be free;
604 So the net_dev->ml_priv will be NULL in 2rd open */
609 pObj = (POS_COOKIE)pAd->OS_Cookie;
611 // reset Adapter flags
612 RTMP_CLEAR_FLAGS(pAd);
614 // Request interrupt service routine for PCI device
615 // register the interrupt routine with the os
616 RT28XX_IRQ_REQUEST(net_dev);
619 // Init BssTab & ChannelInfo tabbles for auto channel select.
623 if (rt28xx_init(net_dev) == FALSE)
626 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
628 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
629 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
632 // Set up the Mac address
633 NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
635 // Init IRQ parameters
636 RT28XX_IRQ_INIT(pAd);
638 // Various AP function init
642 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
647 RT28XX_IRQ_ENABLE(pAd);
651 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
655 RTMP_IO_READ32(pAd, 0x1300, ®); // clear garbage interrupts
656 printk("0x1300 = %08x\n", reg);
664 // RTMP_IO_READ32(pAd, XIFS_TIME_CFG, ®);
667 // reg = (reg & 0xffff0000) | tmp;
668 // RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
676 } /* End of rt28xx_open */
678 static const struct net_device_ops rt3070_netdev_ops = {
679 .ndo_open = MainVirtualIF_open,
680 .ndo_stop = MainVirtualIF_close,
681 .ndo_do_ioctl = rt28xx_ioctl,
682 .ndo_get_stats = RT28xx_get_ether_stats,
683 .ndo_validate_addr = NULL,
684 .ndo_set_mac_address = eth_mac_addr,
685 .ndo_change_mtu = eth_change_mtu,
687 .ndo_start_xmit = IKANOS_DataFramesTx,
689 .ndo_start_xmit = rt28xx_send_packets,
693 /* Must not be called for mdev and apdev */
694 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
698 CHAR slot_name[IFNAMSIZ];
699 struct net_device *device;
703 // dev->set_multicast_list = ieee80211_set_multicast_list;
704 // dev->change_mtu = ieee80211_change_mtu;
705 #if WIRELESS_EXT >= 12
706 if (pAd->OpMode == OPMODE_STA)
708 dev->wireless_handlers = &rt28xx_iw_handler_def;
710 #endif //WIRELESS_EXT >= 12
712 #if WIRELESS_EXT < 21
713 dev->get_wireless_stats = rt28xx_get_wireless_stats;
715 // dev->uninit = ieee80211_if_reinit;
716 // dev->destructor = ieee80211_if_free;
717 dev->priv_flags = INT_MAIN;
718 dev->netdev_ops = &rt3070_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;
774 struct usb_interface *intf = (struct usb_interface *)_dev_p;
775 struct usb_device *dev_p = interface_to_usbdev(intf);
777 dev_p = usb_get_dev(dev_p);
781 DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
783 // Check chipset vendor/product ID
784 // if (RT28XXChipsetCheck(_dev_p) == FALSE)
787 net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
790 printk("alloc_netdev failed\n");
796 // if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
799 netif_stop_queue(net_dev);
801 /* for supporting Network Manager */
802 /* Set the sysfs physical device reference for the network logical device
803 * if set prior to registration will cause a symlink during initialization.
805 SET_NETDEV_DEV(net_dev, &(dev_p->dev));
807 // Allocate RTMP_ADAPTER miniport adapter structure
808 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
809 RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
811 status = RTMPAllocAdapterBlock(handle, &pAd);
812 if (status != NDIS_STATUS_SUCCESS)
813 goto err_out_free_netdev;
815 net_dev->ml_priv = (PVOID)pAd;
816 pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
818 RT28XXNetDevInit(_dev_p, net_dev, pAd);
820 pAd->StaCfg.OriDevType = net_dev->type;
822 // Find and assign a free interface name, raxx
823 // RT28XXAvailRANameAssign(net_dev->name);
826 if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
829 pAd->OpMode = OPMODE_STA;
832 if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
835 // Register this device
836 status = register_netdev(net_dev);
841 RT28XX_DRVDATA_SET(_dev_p);
846 return 0; // probe ok
849 /* --------------------------- ERROR HANDLE --------------------------- */
851 RTMPFreeAdapter(pAd);
855 free_netdev(net_dev);
858 RT28XX_PUT_DEVICE(dev_p);
860 return -ENODEV; /* probe fail */
861 } /* End of rt28xx_probe */
865 ========================================================================
867 The entry point for Linux kernel sent packet to our driver.
870 sk_buff *skb the pointer refer to a sk_buffer.
876 This function is the entry point of Tx Path for Os delivery packet to
877 our driver. You only can put OS-depened & STA/AP common handle procedures
879 ========================================================================
881 int rt28xx_packet_xmit(struct sk_buff *skb)
883 struct net_device *net_dev = skb->dev;
884 PRTMP_ADAPTER pAd = net_dev->ml_priv;
886 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
888 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
890 // Drop send request since we are in monitor mode
893 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
898 // EapolStart size is 18
901 //printk("bad packet size: %d\n", pkt->len);
902 hex_dump("bad packet", skb->data, skb->len);
903 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
907 RTMP_SET_PACKET_5VT(pPacket, 0);
908 // MiniportMMRequest(pAd, pkt->data, pkt->len);
909 #ifdef CONFIG_5VT_ENHANCE
910 if (*(int*)(skb->cb) == BRIDGE_TAG) {
911 RTMP_SET_PACKET_5VT(pPacket, 1);
915 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
918 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
929 ========================================================================
931 Send a packet to WLAN.
934 skb_p points to our adapter
935 dev_p which WLAN network interface
938 0: transmit successfully
939 otherwise: transmit fail
942 ========================================================================
944 INT rt28xx_send_packets(
945 IN struct sk_buff *skb_p,
946 IN struct net_device *net_dev)
948 RTMP_ADAPTER *pAd = net_dev->ml_priv;
950 if (!(net_dev->flags & IFF_UP))
952 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
956 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
957 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
959 return rt28xx_packet_xmit(skb_p);
960 } /* End of MBSS_VirtualIF_PacketSend */
965 void CfgInitHook(PRTMP_ADAPTER pAd)
967 pAd->bBroadComHT = TRUE;
968 } /* End of CfgInitHook */
971 #if WIRELESS_EXT >= 12
972 // This function will be called when query /proc
973 struct iw_statistics *rt28xx_get_wireless_stats(
974 IN struct net_device *net_dev)
976 PRTMP_ADAPTER pAd = net_dev->ml_priv;
979 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
981 pAd->iw_stats.status = 0; // Status - device dependent for now
984 pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
985 if(pAd->iw_stats.qual.qual > 100)
986 pAd->iw_stats.qual.qual = 100;
988 if (pAd->OpMode == OPMODE_STA)
989 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
991 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
993 pAd->iw_stats.qual.noise += 256 - 143;
994 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
996 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
997 #endif // IW_QUAL_DBM //
999 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
1000 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
1002 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
1003 return &pAd->iw_stats;
1004 } /* End of rt28xx_get_wireless_stats */
1005 #endif // WIRELESS_EXT //
1009 void tbtt_tasklet(unsigned long data)
1011 #define MAX_TX_IN_TBTT (16)
1016 IN struct net_device *net_dev,
1017 IN OUT struct ifreq *rq,
1020 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1021 RTMP_ADAPTER *pAd = NULL;
1024 if (net_dev->priv_flags == INT_MAIN)
1026 pAd = net_dev->ml_priv;
1030 pVirtualAd = net_dev->ml_priv;
1031 pAd = pVirtualAd->RtmpDev->ml_priv;
1036 /* if 1st open fail, pAd will be free;
1037 So the net_dev->ml_priv will be NULL in 2rd open */
1041 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1043 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
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;