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 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 extern const struct iw_handler_def rt28xx_iw_handler_def;
77 #if WIRELESS_EXT >= 12
78 // This function will be called when query /proc
79 struct iw_statistics *rt28xx_get_wireless_stats(
80 IN struct net_device *net_dev);
83 struct net_device_stats *RT28xx_get_ether_stats(
84 IN struct net_device *net_dev);
87 ========================================================================
92 *net_dev the raxx interface pointer
99 1. if open fail, kernel will not call the close function.
101 (1) Mlme Memory Handler: MlmeHalt()
102 (2) TX & RX: RTMPFreeTxRxRingMemory()
103 (3) BA Reordering: ba_reordering_resource_release()
104 ========================================================================
106 int MainVirtualIF_close(IN struct net_device *net_dev)
108 RTMP_ADAPTER *pAd = net_dev->ml_priv;
110 // Sanity check for pAd
112 return 0; // close ok
114 netif_carrier_off(pAd->net_dev);
115 netif_stop_queue(pAd->net_dev);
118 VIRTUAL_IF_DOWN(pAd);
120 RT_MOD_DEC_USE_COUNT();
122 return 0; // close ok
126 ========================================================================
131 *net_dev the raxx interface pointer
138 1. if open fail, kernel will not call the close function.
140 (1) Mlme Memory Handler: MlmeHalt()
141 (2) TX & RX: RTMPFreeTxRxRingMemory()
142 (3) BA Reordering: ba_reordering_resource_release()
143 ========================================================================
145 int MainVirtualIF_open(IN struct net_device *net_dev)
147 RTMP_ADAPTER *pAd = net_dev->ml_priv;
149 // Sanity check for pAd
151 return 0; // close ok
153 if (VIRTUAL_IF_UP(pAd) != 0)
156 // increase MODULE use count
157 RT_MOD_INC_USE_COUNT();
159 netif_start_queue(net_dev);
160 netif_carrier_on(net_dev);
161 netif_wake_queue(net_dev);
167 ========================================================================
169 Close raxx interface.
172 *net_dev the raxx interface pointer
179 1. if open fail, kernel will not call the close function.
181 (1) Mlme Memory Handler: MlmeHalt()
182 (2) TX & RX: RTMPFreeTxRxRingMemory()
183 (3) BA Reordering: ba_reordering_resource_release()
184 ========================================================================
186 int rt28xx_close(IN PNET_DEV dev)
188 struct net_device * net_dev = (struct net_device *)dev;
189 RTMP_ADAPTER *pAd = net_dev->ml_priv;
190 BOOLEAN Cancelled = FALSE;
193 DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
194 DECLARE_WAITQUEUE(wait, current);
196 //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
200 DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
202 // Sanity check for pAd
204 return 0; // close ok
207 // If dirver doesn't wake up firmware here,
208 // NICLoadFirmware will hang forever when interface is up again.
210 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) ||
211 RTMP_SET_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND) ||
212 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))
215 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
219 AsicForceWakeup(pAd, RTMP_HALT);
222 AsicForceWakeup(pAd, TRUE);
227 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
229 MLME_DISASSOC_REQ_STRUCT DisReq;
230 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
232 COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
233 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
235 MsgElem->Machine = ASSOC_STATE_MACHINE;
236 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
237 MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
238 NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
240 // Prevent to connect AP again in STAMlmePeriodicExec
241 pAd->MlmeAux.AutoReconnectSsidLen= 32;
242 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
244 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
245 MlmeDisassocReqAction(pAd, MsgElem);
252 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
256 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
259 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
260 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
264 pAd->bPCIclkOff = FALSE;
268 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
270 for (i = 0 ; i < NUM_OF_TX_RING; i++)
272 while (pAd->DeQueueRunning[i] == TRUE)
274 printk("Waiting for TxQueue[%d] done..........\n", i);
280 // ensure there are no more active urbs.
281 add_wait_queue (&unlink_wakeup, &wait);
282 pAd->wait = &unlink_wakeup;
284 // maybe wait for deletions to finish.
286 //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
289 unsigned long IrqFlags;
291 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
292 if (pAd->PendingRx == 0)
294 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
297 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
299 msleep(UNLINK_TIMEOUT_MS); //Time in millisecond
303 remove_wait_queue (&unlink_wakeup, &wait);
307 // We need clear timerQ related structure before exits of the timer thread.
308 RT2870_TimerQ_Exit(pAd);
309 // Close kernel threads or tasklets
310 RT28xxThreadTerminate(pAd);
313 // Stop Mlme state machine
316 // Close kernel threads or tasklets
317 kill_thread_task(pAd);
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 // Free BA reorder resource
348 ba_reordering_resource_release(pAd);
350 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
352 return 0; // close ok
353 } /* End of rt28xx_close */
355 static int rt28xx_init(IN struct net_device *net_dev)
358 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)net_dev->ml_priv;
361 PRTMP_ADAPTER pAd = net_dev->ml_priv;
368 // Allocate BA Reordering memory
369 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
371 // Make sure MAC gets ready.
375 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
376 pAd->MACVersion = MacCsr0;
378 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
382 } while (index++ < 100);
384 DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
385 /*Iverson patch PCIE L1 issue */
388 RT28XXDMADisable(pAd);
390 // Load 8051 firmware
391 Status = NICLoadFirmware(pAd);
392 if (Status != NDIS_STATUS_SUCCESS)
394 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
398 NICLoadRateSwitchingParams(pAd);
400 // Disable interrupts here which is as soon as possible
401 // 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);
409 Status = RTMPAllocTxRxRingMemory(pAd);
410 if (Status != NDIS_STATUS_SUCCESS)
412 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
416 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
421 Status = MlmeInit(pAd);
422 if (Status != NDIS_STATUS_SUCCESS)
424 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
428 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
433 // We need init timerQ related structure before create the timer thread.
434 RT2870_TimerQ_Init(pAd);
437 RT28XX_TASK_THREAD_INIT(pAd, Status);
438 if (Status != NDIS_STATUS_SUCCESS)
443 NdisAllocateSpinLock(&pAd->MacTabLock);
445 MeasureReqTabInit(pAd);
449 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
451 Status = NICInitializeAdapter(pAd, TRUE);
452 if (Status != NDIS_STATUS_SUCCESS)
454 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
455 if (Status != NDIS_STATUS_SUCCESS)
459 // Read parameters from Config File
460 Status = RTMPReadParametersHook(pAd);
462 printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
463 if (Status != NDIS_STATUS_SUCCESS)
465 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
470 pAd->CommonCfg.bMultipleIRP = FALSE;
472 if (pAd->CommonCfg.bMultipleIRP)
473 pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
475 pAd->CommonCfg.NumOfBulkInIRP = 1;
479 //Init Ba Capability parameters.
480 pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
481 pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
482 pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
483 pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
485 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
486 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
487 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
489 printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
491 // We should read EEPROM for all cases. rt2860b
492 NICReadEEPROMParameters(pAd, mac);
494 printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
496 NICInitAsicFromEEPROM(pAd); //rt2860b
498 // Set PHY to appropriate mode
499 TmpPhy = pAd->CommonCfg.PhyMode;
500 pAd->CommonCfg.PhyMode = 0xff;
501 RTMPSetPhyMode(pAd, TmpPhy);
504 // No valid channels.
505 if (pAd->ChannelListNum == 0)
507 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
511 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
512 pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
513 pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
516 //Init RT30xx RFRegisters after read RFIC type from EEPROM
517 NICInitRT30xxRFRegisters(pAd);
521 VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
522 #endif // IKANOS_VX_1X0 //
525 // Initialize RF register to default value
527 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
528 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
531 // 8051 firmware require the signal during booting time.
532 AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00);
535 if (pAd && (Status != NDIS_STATUS_SUCCESS))
538 // Undo everything if it failed
540 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
542 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
547 // Microsoft HCT require driver send a disconnect event after driver initialization.
548 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
549 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
551 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
555 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
556 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
559 // Support multiple BulkIn IRP,
560 // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
562 for(index=0; index<pAd->CommonCfg.NumOfBulkInIRP; index++)
564 RTUSBBulkReceive(pAd);
565 DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n" ));
571 DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
580 RTMPFreeTxRxRingMemory(pAd);
582 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
583 RT28XX_IRQ_RELEASE(net_dev);
585 // shall not set ml_priv to NULL here because the ml_priv didn't been free yet.
586 //net_dev->ml_priv = 0;
588 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
590 } /* End of rt28xx_init */
594 ========================================================================
599 *net_dev the raxx interface pointer
606 ========================================================================
608 int rt28xx_open(IN PNET_DEV dev)
610 struct net_device * net_dev = (struct net_device *)dev;
611 PRTMP_ADAPTER pAd = net_dev->ml_priv;
616 // Sanity check for pAd
619 /* if 1st open fail, pAd will be free;
620 So the net_dev->ml_priv will be NULL in 2rd open */
625 pObj = (POS_COOKIE)pAd->OS_Cookie;
627 // reset Adapter flags
628 RTMP_CLEAR_FLAGS(pAd);
630 // Request interrupt service routine for PCI device
631 // register the interrupt routine with the os
632 RT28XX_IRQ_REQUEST(net_dev);
635 // Init BssTab & ChannelInfo tabbles for auto channel select.
639 if (rt28xx_init(net_dev) == FALSE)
642 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
643 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
645 // Set up the Mac address
646 NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
648 // Init IRQ parameters
649 RT28XX_IRQ_INIT(pAd);
651 // Various AP function init
654 RT28XX_IRQ_ENABLE(pAd);
658 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
662 RTMP_IO_READ32(pAd, 0x1300, ®); // clear garbage interrupts
663 printk("0x1300 = %08x\n", reg);
667 RTMPInitPCIeLinkCtrlValue(pAd);
673 } /* End of rt28xx_open */
675 static const struct net_device_ops rt2860_netdev_ops = {
676 .ndo_open = MainVirtualIF_open,
677 .ndo_stop = MainVirtualIF_close,
678 .ndo_do_ioctl = rt28xx_ioctl,
679 .ndo_get_stats = RT28xx_get_ether_stats,
680 .ndo_validate_addr = NULL,
681 .ndo_set_mac_address = eth_mac_addr,
682 .ndo_change_mtu = eth_change_mtu,
684 .ndo_start_xmit = IKANOS_DataFramesTx,
686 .ndo_start_xmit = rt28xx_send_packets,
690 /* Must not be called for mdev and apdev */
691 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
695 CHAR slot_name[IFNAMSIZ];
696 struct net_device *device;
698 #if WIRELESS_EXT >= 12
699 if (pAd->OpMode == OPMODE_STA)
701 dev->wireless_handlers = &rt28xx_iw_handler_def;
703 #endif //WIRELESS_EXT >= 12
705 #if WIRELESS_EXT < 21
706 dev->get_wireless_stats = rt28xx_get_wireless_stats;
708 dev->priv_flags = INT_MAIN;
709 dev->netdev_ops = &rt2860_netdev_ops;
710 // find available device name
711 for (i = 0; i < 8; i++)
713 sprintf(slot_name, "ra%d", i);
715 device = dev_get_by_name(dev_net(dev), slot_name);
725 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
726 Status = NDIS_STATUS_FAILURE;
730 sprintf(dev->name, "ra%d", i);
731 Status = NDIS_STATUS_SUCCESS;
739 ========================================================================
741 Probe RT28XX chipset.
744 _dev_p Point to the PCI or USB device
745 _dev_id_p Point to the PCI or USB device ID
752 ========================================================================
754 INT __devinit rt28xx_probe(
758 OUT PRTMP_ADAPTER *ppAd)
760 struct net_device *net_dev;
761 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
765 struct pci_dev *dev_p = (struct pci_dev *)_dev_p;
768 struct usb_interface *intf = (struct usb_interface *)_dev_p;
769 struct usb_device *dev_p = interface_to_usbdev(intf);
771 dev_p = usb_get_dev(dev_p);
774 DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
776 net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
779 printk("alloc_netdev failed\n");
784 netif_stop_queue(net_dev);
786 /* for supporting Network Manager */
787 /* Set the sysfs physical device reference for the network logical device
788 * if set prior to registration will cause a symlink during initialization.
790 SET_NETDEV_DEV(net_dev, &(dev_p->dev));
792 // Allocate RTMP_ADAPTER miniport adapter structure
793 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
794 RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
796 status = RTMPAllocAdapterBlock(handle, &pAd);
797 if (status != NDIS_STATUS_SUCCESS)
798 goto err_out_free_netdev;
800 net_dev->ml_priv = (PVOID)pAd;
801 pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
803 RT28XXNetDevInit(_dev_p, net_dev, pAd);
805 pAd->StaCfg.OriDevType = net_dev->type;
808 if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
811 pAd->OpMode = OPMODE_STA;
814 if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
817 // Register this device
818 status = register_netdev(net_dev);
823 RT28XX_DRVDATA_SET(_dev_p);
826 return 0; // probe ok
829 /* --------------------------- ERROR HANDLE --------------------------- */
831 RTMPFreeAdapter(pAd);
835 free_netdev(net_dev);
838 RT28XX_PUT_DEVICE(dev_p);
840 return -ENODEV; /* probe fail */
841 } /* End of rt28xx_probe */
845 ========================================================================
847 The entry point for Linux kernel sent packet to our driver.
850 sk_buff *skb the pointer refer to a sk_buffer.
856 This function is the entry point of Tx Path for Os delivery packet to
857 our driver. You only can put OS-depened & STA/AP common handle procedures
859 ========================================================================
861 int rt28xx_packet_xmit(struct sk_buff *skb)
863 struct net_device *net_dev = skb->dev;
864 PRTMP_ADAPTER pAd = net_dev->ml_priv;
865 int status = NETDEV_TX_OK;
866 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
869 // Drop send request since we are in monitor mode
872 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
877 // EapolStart size is 18
880 //printk("bad packet size: %d\n", pkt->len);
881 hex_dump("bad packet", skb->data, skb->len);
882 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
886 RTMP_SET_PACKET_5VT(pPacket, 0);
887 #ifdef CONFIG_5VT_ENHANCE
888 if (*(int*)(skb->cb) == BRIDGE_TAG) {
889 RTMP_SET_PACKET_5VT(pPacket, 1);
893 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
895 status = NETDEV_TX_OK;
903 ========================================================================
905 Send a packet to WLAN.
908 skb_p points to our adapter
909 dev_p which WLAN network interface
912 0: transmit successfully
913 otherwise: transmit fail
916 ========================================================================
918 INT rt28xx_send_packets(
919 IN struct sk_buff *skb_p,
920 IN struct net_device *net_dev)
922 RTMP_ADAPTER *pAd = net_dev->ml_priv;
923 if (!(net_dev->flags & IFF_UP))
925 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
929 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
930 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
932 return rt28xx_packet_xmit(skb_p);
934 } /* End of MBSS_VirtualIF_PacketSend */
939 void CfgInitHook(PRTMP_ADAPTER pAd)
941 pAd->bBroadComHT = TRUE;
942 } /* End of CfgInitHook */
945 #if WIRELESS_EXT >= 12
946 // This function will be called when query /proc
947 struct iw_statistics *rt28xx_get_wireless_stats(
948 IN struct net_device *net_dev)
950 PRTMP_ADAPTER pAd = net_dev->ml_priv;
953 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
955 pAd->iw_stats.status = 0; // Status - device dependent for now
958 pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
959 if(pAd->iw_stats.qual.qual > 100)
960 pAd->iw_stats.qual.qual = 100;
962 if (pAd->OpMode == OPMODE_STA)
963 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
965 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
967 pAd->iw_stats.qual.noise += 256 - 143;
968 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
970 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
971 #endif // IW_QUAL_DBM //
973 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
974 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
976 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
977 return &pAd->iw_stats;
978 } /* End of rt28xx_get_wireless_stats */
979 #endif // WIRELESS_EXT //
983 void tbtt_tasklet(unsigned long data)
985 #define MAX_TX_IN_TBTT (16)
990 IN struct net_device *net_dev,
991 IN OUT struct ifreq *rq,
994 VIRTUAL_ADAPTER *pVirtualAd = NULL;
995 RTMP_ADAPTER *pAd = NULL;
998 if (net_dev->priv_flags == INT_MAIN)
1000 pAd = net_dev->ml_priv;
1004 pVirtualAd = net_dev->ml_priv;
1005 pAd = pVirtualAd->RtmpDev->ml_priv;
1010 /* if 1st open fail, pAd will be free;
1011 So the net_dev->ml_priv will be NULL in 2rd open */
1015 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
1021 ========================================================================
1023 Routine Description:
1024 return ethernet statistics counter
1027 net_dev Pointer to net_device
1034 ========================================================================
1036 struct net_device_stats *RT28xx_get_ether_stats(
1037 IN struct net_device *net_dev)
1039 RTMP_ADAPTER *pAd = NULL;
1042 pAd = net_dev->ml_priv;
1047 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1048 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1050 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1051 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1053 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1054 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1056 pAd->stats.rx_dropped = 0;
1057 pAd->stats.tx_dropped = 0;
1059 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
1060 pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
1062 pAd->stats.rx_length_errors = 0;
1063 pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
1064 pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1065 pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
1066 pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
1067 pAd->stats.rx_missed_errors = 0; // receiver missed packet
1069 // detailed tx_errors
1070 pAd->stats.tx_aborted_errors = 0;
1071 pAd->stats.tx_carrier_errors = 0;
1072 pAd->stats.tx_fifo_errors = 0;
1073 pAd->stats.tx_heartbeat_errors = 0;
1074 pAd->stats.tx_window_errors = 0;
1077 pAd->stats.rx_compressed = 0;
1078 pAd->stats.tx_compressed = 0;