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
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);
72 extern const struct iw_handler_def rt28xx_iw_handler_def;
74 #if WIRELESS_EXT >= 12
75 // This function will be called when query /proc
76 struct iw_statistics *rt28xx_get_wireless_stats(
77 IN struct net_device *net_dev);
80 struct net_device_stats *RT28xx_get_ether_stats(
81 IN struct net_device *net_dev);
84 ========================================================================
89 *net_dev the raxx interface pointer
96 1. if open fail, kernel will not call the close function.
98 (1) Mlme Memory Handler: MlmeHalt()
99 (2) TX & RX: RTMPFreeTxRxRingMemory()
100 (3) BA Reordering: ba_reordering_resource_release()
101 ========================================================================
103 int MainVirtualIF_close(IN struct net_device *net_dev)
105 RTMP_ADAPTER *pAd = net_dev->ml_priv;
107 // Sanity check for pAd
109 return 0; // close ok
111 netif_carrier_off(pAd->net_dev);
112 netif_stop_queue(pAd->net_dev);
116 VIRTUAL_IF_DOWN(pAd);
118 RT_MOD_DEC_USE_COUNT();
120 return 0; // close ok
124 ========================================================================
129 *net_dev the raxx interface pointer
136 1. if open fail, kernel will not call the close function.
138 (1) Mlme Memory Handler: MlmeHalt()
139 (2) TX & RX: RTMPFreeTxRxRingMemory()
140 (3) BA Reordering: ba_reordering_resource_release()
141 ========================================================================
143 int MainVirtualIF_open(IN struct net_device *net_dev)
145 RTMP_ADAPTER *pAd = net_dev->ml_priv;
147 // Sanity check for pAd
149 return 0; // close ok
151 if (VIRTUAL_IF_UP(pAd) != 0)
154 // increase MODULE use count
155 RT_MOD_INC_USE_COUNT();
157 netif_start_queue(net_dev);
158 netif_carrier_on(net_dev);
159 netif_wake_queue(net_dev);
165 ========================================================================
167 Close raxx interface.
170 *net_dev the raxx interface pointer
177 1. if open fail, kernel will not call the close function.
179 (1) Mlme Memory Handler: MlmeHalt()
180 (2) TX & RX: RTMPFreeTxRxRingMemory()
181 (3) BA Reordering: ba_reordering_resource_release()
182 ========================================================================
184 int rt28xx_close(IN PNET_DEV dev)
186 struct net_device * net_dev = (struct net_device *)dev;
187 RTMP_ADAPTER *pAd = net_dev->ml_priv;
188 BOOLEAN Cancelled = FALSE;
191 DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
192 DECLARE_WAITQUEUE(wait, current);
194 //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
198 DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
200 // Sanity check for pAd
202 return 0; // close ok
206 // If dirver doesn't wake up firmware here,
207 // NICLoadFirmware will hang forever when interface is up again.
208 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
210 AsicForceWakeup(pAd, TRUE);
214 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
216 MLME_DISASSOC_REQ_STRUCT DisReq;
217 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
219 COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
220 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
222 MsgElem->Machine = ASSOC_STATE_MACHINE;
223 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
224 MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
225 NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
227 // Prevent to connect AP again in STAMlmePeriodicExec
228 pAd->MlmeAux.AutoReconnectSsidLen= 32;
229 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
231 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
232 MlmeDisassocReqAction(pAd, MsgElem);
239 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
243 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
246 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
247 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
252 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
254 for (i = 0 ; i < NUM_OF_TX_RING; i++)
256 while (pAd->DeQueueRunning[i] == TRUE)
258 printk("Waiting for TxQueue[%d] done..........\n", i);
264 // ensure there are no more active urbs.
265 add_wait_queue (&unlink_wakeup, &wait);
266 pAd->wait = &unlink_wakeup;
268 // maybe wait for deletions to finish.
270 //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
273 unsigned long IrqFlags;
275 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
276 if (pAd->PendingRx == 0)
278 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
281 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
283 msleep(UNLINK_TIMEOUT_MS); //Time in millisecond
287 remove_wait_queue (&unlink_wakeup, &wait);
291 // We need clear timerQ related structure before exits of the timer thread.
292 RT2870_TimerQ_Exit(pAd);
293 // Close kernel threads or tasklets
294 RT28xxThreadTerminate(pAd);
297 // Stop Mlme state machine
300 // Close kernel threads or tasklets
301 kill_thread_task(pAd);
305 MeasureReqTabExit(pAd);
311 // Free Ring or USB buffers
312 RTMPFreeTxRxRingMemory(pAd);
314 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
316 // Free BA reorder resource
317 ba_reordering_resource_release(pAd);
319 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
321 return 0; // close ok
322 } /* End of rt28xx_close */
324 static int rt28xx_init(IN struct net_device *net_dev)
326 PRTMP_ADAPTER pAd = net_dev->ml_priv;
332 // Allocate BA Reordering memory
333 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
335 // Make sure MAC gets ready.
339 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
340 pAd->MACVersion = MacCsr0;
342 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
346 } while (index++ < 100);
348 DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
351 RT28XXDMADisable(pAd);
354 // Load 8051 firmware
355 Status = NICLoadFirmware(pAd);
356 if (Status != NDIS_STATUS_SUCCESS)
358 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
362 NICLoadRateSwitchingParams(pAd);
364 // Disable interrupts here which is as soon as possible
365 // This statement should never be true. We might consider to remove it later
367 Status = RTMPAllocTxRxRingMemory(pAd);
368 if (Status != NDIS_STATUS_SUCCESS)
370 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
374 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
379 Status = MlmeInit(pAd);
380 if (Status != NDIS_STATUS_SUCCESS)
382 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
386 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
391 // We need init timerQ related structure before create the timer thread.
392 RT2870_TimerQ_Init(pAd);
395 RT28XX_TASK_THREAD_INIT(pAd, Status);
396 if (Status != NDIS_STATUS_SUCCESS)
401 NdisAllocateSpinLock(&pAd->MacTabLock);
403 MeasureReqTabInit(pAd);
407 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
409 Status = NICInitializeAdapter(pAd, TRUE);
410 if (Status != NDIS_STATUS_SUCCESS)
412 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
413 if (Status != NDIS_STATUS_SUCCESS)
417 // Read parameters from Config File
418 Status = RTMPReadParametersHook(pAd);
420 printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
421 if (Status != NDIS_STATUS_SUCCESS)
423 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
428 pAd->CommonCfg.bMultipleIRP = FALSE;
430 if (pAd->CommonCfg.bMultipleIRP)
431 pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
433 pAd->CommonCfg.NumOfBulkInIRP = 1;
437 //Init Ba Capability parameters.
438 pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
439 pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
440 pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
441 pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
443 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
444 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
445 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
447 printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
449 // We should read EEPROM for all cases. rt2860b
450 NICReadEEPROMParameters(pAd, mac);
452 printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
454 NICInitAsicFromEEPROM(pAd); //rt2860b
456 // Set PHY to appropriate mode
457 TmpPhy = pAd->CommonCfg.PhyMode;
458 pAd->CommonCfg.PhyMode = 0xff;
459 RTMPSetPhyMode(pAd, TmpPhy);
462 // No valid channels.
463 if (pAd->ChannelListNum == 0)
465 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
469 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
470 pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
471 pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
474 //Init RT30xx RFRegisters after read RFIC type from EEPROM
475 NICInitRT30xxRFRegisters(pAd);
479 VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
480 #endif // IKANOS_VX_1X0 //
483 // Initialize RF register to default value
485 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
486 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
488 // 8051 firmware require the signal during booting time.
489 AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00);
491 if (pAd && (Status != NDIS_STATUS_SUCCESS))
494 // Undo everything if it failed
496 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
498 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
503 // Microsoft HCT require driver send a disconnect event after driver initialization.
504 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
505 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
507 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
511 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
512 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
515 // Support multiple BulkIn IRP,
516 // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
518 for(index=0; index<pAd->CommonCfg.NumOfBulkInIRP; index++)
520 RTUSBBulkReceive(pAd);
521 DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n" ));
527 DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
536 RTMPFreeTxRxRingMemory(pAd);
538 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
539 RT28XX_IRQ_RELEASE(net_dev);
541 // shall not set ml_priv to NULL here because the ml_priv didn't been free yet.
542 //net_dev->ml_priv = 0;
544 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
546 } /* End of rt28xx_init */
550 ========================================================================
555 *net_dev the raxx interface pointer
562 ========================================================================
564 int rt28xx_open(IN PNET_DEV dev)
566 struct net_device * net_dev = (struct net_device *)dev;
567 PRTMP_ADAPTER pAd = net_dev->ml_priv;
572 // Sanity check for pAd
575 /* if 1st open fail, pAd will be free;
576 So the net_dev->ml_priv will be NULL in 2rd open */
581 pObj = (POS_COOKIE)pAd->OS_Cookie;
583 // reset Adapter flags
584 RTMP_CLEAR_FLAGS(pAd);
586 // Request interrupt service routine for PCI device
587 // register the interrupt routine with the os
588 RT28XX_IRQ_REQUEST(net_dev);
591 // Init BssTab & ChannelInfo tabbles for auto channel select.
595 if (rt28xx_init(net_dev) == FALSE)
598 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
599 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
601 // Set up the Mac address
602 NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
604 // Init IRQ parameters
605 RT28XX_IRQ_INIT(pAd);
607 // Various AP function init
610 RT28XX_IRQ_ENABLE(pAd);
614 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
618 RTMP_IO_READ32(pAd, 0x1300, ®); // clear garbage interrupts
619 printk("0x1300 = %08x\n", reg);
626 } /* End of rt28xx_open */
628 static const struct net_device_ops rt2870_netdev_ops = {
629 .ndo_open = MainVirtualIF_open,
630 .ndo_stop = MainVirtualIF_close,
631 .ndo_do_ioctl = rt28xx_ioctl,
632 .ndo_get_stats = RT28xx_get_ether_stats,
633 .ndo_validate_addr = NULL,
634 .ndo_set_mac_address = eth_mac_addr,
635 .ndo_change_mtu = eth_change_mtu,
637 .ndo_start_xmit = IKANOS_DataFramesTx,
639 .ndo_start_xmit = rt28xx_send_packets,
643 /* Must not be called for mdev and apdev */
644 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
648 CHAR slot_name[IFNAMSIZ];
649 struct net_device *device;
651 #if WIRELESS_EXT >= 12
652 if (pAd->OpMode == OPMODE_STA)
654 dev->wireless_handlers = &rt28xx_iw_handler_def;
656 #endif //WIRELESS_EXT >= 12
658 #if WIRELESS_EXT < 21
659 dev->get_wireless_stats = rt28xx_get_wireless_stats;
661 dev->priv_flags = INT_MAIN;
662 dev->netdev_ops = &rt2870_netdev_ops;
663 // find available device name
664 for (i = 0; i < 8; i++)
666 sprintf(slot_name, "ra%d", i);
668 device = dev_get_by_name(dev_net(dev), slot_name);
678 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
679 Status = NDIS_STATUS_FAILURE;
683 sprintf(dev->name, "ra%d", i);
684 Status = NDIS_STATUS_SUCCESS;
692 ========================================================================
694 Probe RT28XX chipset.
697 _dev_p Point to the PCI or USB device
698 _dev_id_p Point to the PCI or USB device ID
705 ========================================================================
707 INT __devinit rt28xx_probe(
711 OUT PRTMP_ADAPTER *ppAd)
713 struct net_device *net_dev;
714 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
718 struct usb_interface *intf = (struct usb_interface *)_dev_p;
719 struct usb_device *dev_p = interface_to_usbdev(intf);
721 dev_p = usb_get_dev(dev_p);
725 DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
727 net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
730 printk("alloc_netdev failed\n");
735 netif_stop_queue(net_dev);
737 /* for supporting Network Manager */
738 /* Set the sysfs physical device reference for the network logical device
739 * if set prior to registration will cause a symlink during initialization.
741 SET_NETDEV_DEV(net_dev, &(dev_p->dev));
743 // Allocate RTMP_ADAPTER miniport adapter structure
744 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
745 RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
747 status = RTMPAllocAdapterBlock(handle, &pAd);
748 if (status != NDIS_STATUS_SUCCESS)
749 goto err_out_free_netdev;
751 net_dev->ml_priv = (PVOID)pAd;
752 pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
754 RT28XXNetDevInit(_dev_p, net_dev, pAd);
756 pAd->StaCfg.OriDevType = net_dev->type;
759 if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
762 pAd->OpMode = OPMODE_STA;
765 if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
768 // Register this device
769 status = register_netdev(net_dev);
774 RT28XX_DRVDATA_SET(_dev_p);
779 return 0; // probe ok
782 /* --------------------------- ERROR HANDLE --------------------------- */
784 RTMPFreeAdapter(pAd);
788 free_netdev(net_dev);
791 RT28XX_PUT_DEVICE(dev_p);
793 return -ENODEV; /* probe fail */
794 } /* End of rt28xx_probe */
798 ========================================================================
800 The entry point for Linux kernel sent packet to our driver.
803 sk_buff *skb the pointer refer to a sk_buffer.
809 This function is the entry point of Tx Path for Os delivery packet to
810 our driver. You only can put OS-depened & STA/AP common handle procedures
812 ========================================================================
814 int rt28xx_packet_xmit(struct sk_buff *skb)
816 struct net_device *net_dev = skb->dev;
817 PRTMP_ADAPTER pAd = net_dev->ml_priv;
819 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
822 // Drop send request since we are in monitor mode
825 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
830 // EapolStart size is 18
833 //printk("bad packet size: %d\n", pkt->len);
834 hex_dump("bad packet", skb->data, skb->len);
835 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
839 RTMP_SET_PACKET_5VT(pPacket, 0);
840 #ifdef CONFIG_5VT_ENHANCE
841 if (*(int*)(skb->cb) == BRIDGE_TAG) {
842 RTMP_SET_PACKET_5VT(pPacket, 1);
846 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
856 ========================================================================
858 Send a packet to WLAN.
861 skb_p points to our adapter
862 dev_p which WLAN network interface
865 0: transmit successfully
866 otherwise: transmit fail
869 ========================================================================
871 INT rt28xx_send_packets(
872 IN struct sk_buff *skb_p,
873 IN struct net_device *net_dev)
875 RTMP_ADAPTER *pAd = net_dev->ml_priv;
877 if (!(net_dev->flags & IFF_UP))
879 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
883 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
884 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
886 return rt28xx_packet_xmit(skb_p);
887 } /* End of MBSS_VirtualIF_PacketSend */
892 void CfgInitHook(PRTMP_ADAPTER pAd)
894 pAd->bBroadComHT = TRUE;
895 } /* End of CfgInitHook */
897 #if WIRELESS_EXT >= 12
898 // This function will be called when query /proc
899 struct iw_statistics *rt28xx_get_wireless_stats(
900 IN struct net_device *net_dev)
902 PRTMP_ADAPTER pAd = net_dev->ml_priv;
905 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
907 pAd->iw_stats.status = 0; // Status - device dependent for now
910 pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
911 if(pAd->iw_stats.qual.qual > 100)
912 pAd->iw_stats.qual.qual = 100;
914 if (pAd->OpMode == OPMODE_STA)
915 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
917 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
919 pAd->iw_stats.qual.noise += 256 - 143;
920 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
922 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
923 #endif // IW_QUAL_DBM //
925 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
926 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
928 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
929 return &pAd->iw_stats;
930 } /* End of rt28xx_get_wireless_stats */
931 #endif // WIRELESS_EXT //
935 void tbtt_tasklet(unsigned long data)
937 #define MAX_TX_IN_TBTT (16)
942 IN struct net_device *net_dev,
943 IN OUT struct ifreq *rq,
946 VIRTUAL_ADAPTER *pVirtualAd = NULL;
947 RTMP_ADAPTER *pAd = NULL;
950 if (net_dev->priv_flags == INT_MAIN)
952 pAd = net_dev->ml_priv;
956 pVirtualAd = net_dev->ml_priv;
957 pAd = pVirtualAd->RtmpDev->ml_priv;
962 /* if 1st open fail, pAd will be free;
963 So the net_dev->ml_priv will be NULL in 2rd open */
967 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
973 ========================================================================
976 return ethernet statistics counter
979 net_dev Pointer to net_device
986 ========================================================================
988 struct net_device_stats *RT28xx_get_ether_stats(
989 IN struct net_device *net_dev)
991 RTMP_ADAPTER *pAd = NULL;
994 pAd = net_dev->ml_priv;
999 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1000 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1002 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1003 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1005 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1006 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1008 pAd->stats.rx_dropped = 0;
1009 pAd->stats.tx_dropped = 0;
1011 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
1012 pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
1014 pAd->stats.rx_length_errors = 0;
1015 pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
1016 pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1017 pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
1018 pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
1019 pAd->stats.rx_missed_errors = 0; // receiver missed packet
1021 // detailed tx_errors
1022 pAd->stats.tx_aborted_errors = 0;
1023 pAd->stats.tx_carrier_errors = 0;
1024 pAd->stats.tx_fifo_errors = 0;
1025 pAd->stats.tx_heartbeat_errors = 0;
1026 pAd->stats.tx_window_errors = 0;
1029 pAd->stats.rx_compressed = 0;
1030 pAd->stats.tx_compressed = 0;