Merge branch 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6/x86.git] / drivers / staging / rt3070 / rt_main_dev.c
blobc000646286e62c6e860854adcbc697f5cb8ad5c0
1 /*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
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. *
14 * *
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. *
19 * *
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. *
24 * *
25 *************************************************************************
27 Module Name:
28 rt_main_dev.c
30 Abstract:
31 Create and register network interface.
33 Revision History:
34 Who When What
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 #ifdef MULTIPLE_CARD_SUPPORT
44 // record whether the card in the card list is used in the card file
45 UINT8 MC_CardUsed[MAX_NUM_OF_MULTIPLE_CARD];
46 // record used card mac address in the card list
47 static UINT8 MC_CardMac[MAX_NUM_OF_MULTIPLE_CARD][6];
48 #endif // MULTIPLE_CARD_SUPPORT //
50 #ifdef CONFIG_APSTA_MIXED_SUPPORT
51 UINT32 CW_MAX_IN_BITS;
52 #endif // CONFIG_APSTA_MIXED_SUPPORT //
54 /*---------------------------------------------------------------------*/
55 /* Private Variables Used */
56 /*---------------------------------------------------------------------*/
57 //static RALINK_TIMER_STRUCT PeriodicTimer;
59 char *mac = ""; // default 00:00:00:00:00:00
60 char *hostname = ""; // default CMPC
61 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)
62 MODULE_PARM (mac, "s");
63 #else
64 module_param (mac, charp, 0);
65 #endif
66 MODULE_PARM_DESC (mac, "rt28xx: wireless mac addr");
69 /*---------------------------------------------------------------------*/
70 /* Prototypes of Functions Used */
71 /*---------------------------------------------------------------------*/
72 #ifdef DOT11_N_SUPPORT
73 extern BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
74 extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
75 #endif // DOT11_N_SUPPORT //
76 extern NDIS_STATUS NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd);
79 // public function prototype
80 INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
81 IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
83 // private function prototype
84 static int rt28xx_init(IN struct net_device *net_dev);
85 INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);
87 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
88 struct net_device *alloc_netdev(
89 int sizeof_priv,
90 const char *mask,
91 void (*setup)(struct net_device *));
92 #endif // LINUX_VERSION_CODE //
94 static void CfgInitHook(PRTMP_ADAPTER pAd);
95 //static BOOLEAN RT28XXAvailRANameAssign(IN CHAR *name_p);
97 #ifdef CONFIG_STA_SUPPORT
98 extern const struct iw_handler_def rt28xx_iw_handler_def;
99 #endif // CONFIG_STA_SUPPORT //
101 #ifdef CONFIG_APSTA_MIXED_SUPPORT
102 extern const struct iw_handler_def rt28xx_ap_iw_handler_def;
103 #endif // CONFIG_APSTA_MIXED_SUPPORT //
105 #if WIRELESS_EXT >= 12
106 // This function will be called when query /proc
107 struct iw_statistics *rt28xx_get_wireless_stats(
108 IN struct net_device *net_dev);
109 #endif
111 struct net_device_stats *RT28xx_get_ether_stats(
112 IN struct net_device *net_dev);
115 ========================================================================
116 Routine Description:
117 Close raxx interface.
119 Arguments:
120 *net_dev the raxx interface pointer
122 Return Value:
123 0 Open OK
124 otherwise Open Fail
126 Note:
127 1. if open fail, kernel will not call the close function.
128 2. Free memory for
129 (1) Mlme Memory Handler: MlmeHalt()
130 (2) TX & RX: RTMPFreeTxRxRingMemory()
131 (3) BA Reordering: ba_reordering_resource_release()
132 ========================================================================
134 int MainVirtualIF_close(IN struct net_device *net_dev)
136 RTMP_ADAPTER *pAd = net_dev->ml_priv;
138 // Sanity check for pAd
139 if (pAd == NULL)
140 return 0; // close ok
142 netif_carrier_off(pAd->net_dev);
143 netif_stop_queue(pAd->net_dev);
147 VIRTUAL_IF_DOWN(pAd);
149 RT_MOD_DEC_USE_COUNT();
151 return 0; // close ok
155 ========================================================================
156 Routine Description:
157 Open raxx interface.
159 Arguments:
160 *net_dev the raxx interface pointer
162 Return Value:
163 0 Open OK
164 otherwise Open Fail
166 Note:
167 1. if open fail, kernel will not call the close function.
168 2. Free memory for
169 (1) Mlme Memory Handler: MlmeHalt()
170 (2) TX & RX: RTMPFreeTxRxRingMemory()
171 (3) BA Reordering: ba_reordering_resource_release()
172 ========================================================================
174 int MainVirtualIF_open(IN struct net_device *net_dev)
176 RTMP_ADAPTER *pAd = net_dev->ml_priv;
178 // Sanity check for pAd
179 if (pAd == NULL)
180 return 0; // close ok
182 if (VIRTUAL_IF_UP(pAd) != 0)
183 return -1;
185 // increase MODULE use count
186 RT_MOD_INC_USE_COUNT();
188 netif_start_queue(net_dev);
189 netif_carrier_on(net_dev);
190 netif_wake_queue(net_dev);
192 return 0;
196 ========================================================================
197 Routine Description:
198 Close raxx interface.
200 Arguments:
201 *net_dev the raxx interface pointer
203 Return Value:
204 0 Open OK
205 otherwise Open Fail
207 Note:
208 1. if open fail, kernel will not call the close function.
209 2. Free memory for
210 (1) Mlme Memory Handler: MlmeHalt()
211 (2) TX & RX: RTMPFreeTxRxRingMemory()
212 (3) BA Reordering: ba_reordering_resource_release()
213 ========================================================================
215 int rt28xx_close(IN PNET_DEV dev)
217 struct net_device * net_dev = (struct net_device *)dev;
218 RTMP_ADAPTER *pAd = net_dev->ml_priv;
219 BOOLEAN Cancelled = FALSE;
220 UINT32 i = 0;
221 #ifdef RT2870
222 DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
223 DECLARE_WAITQUEUE(wait, current);
225 //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
226 #endif // RT2870 //
229 DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
231 // Sanity check for pAd
232 if (pAd == NULL)
233 return 0; // close ok
236 #ifdef WDS_SUPPORT
237 WdsDown(pAd);
238 #endif // WDS_SUPPORT //
240 #ifdef CONFIG_STA_SUPPORT
241 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
244 // If dirver doesn't wake up firmware here,
245 // NICLoadFirmware will hang forever when interface is up again.
246 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
248 AsicForceWakeup(pAd, TRUE);
251 #ifdef QOS_DLS_SUPPORT
252 // send DLS-TEAR_DOWN message,
253 if (pAd->CommonCfg.bDLSCapable)
255 UCHAR i;
257 // tear down local dls table entry
258 for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
260 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
262 RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
263 pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
264 pAd->StaCfg.DLSEntry[i].Valid = FALSE;
268 // tear down peer dls table entry
269 for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
271 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
273 RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
274 pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
275 pAd->StaCfg.DLSEntry[i].Valid = FALSE;
278 RT28XX_MLME_HANDLER(pAd);
280 #endif // QOS_DLS_SUPPORT //
282 if (INFRA_ON(pAd) &&
283 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
285 MLME_DISASSOC_REQ_STRUCT DisReq;
286 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
288 COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
289 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
291 MsgElem->Machine = ASSOC_STATE_MACHINE;
292 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
293 MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
294 NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
296 // Prevent to connect AP again in STAMlmePeriodicExec
297 pAd->MlmeAux.AutoReconnectSsidLen= 32;
298 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
300 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
301 MlmeDisassocReqAction(pAd, MsgElem);
302 kfree(MsgElem);
304 RTMPusecDelay(1000);
307 #ifdef RT2870
308 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
309 #endif // RT2870 //
311 #ifdef CCX_SUPPORT
312 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
313 #endif
315 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
316 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
318 #ifdef WPA_SUPPLICANT_SUPPORT
319 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
321 union iwreq_data wrqu;
322 // send wireless event to wpa_supplicant for infroming interface down.
323 memset(&wrqu, 0, sizeof(wrqu));
324 wrqu.data.flags = RT_INTERFACE_DOWN;
325 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
327 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
328 #endif // WPA_SUPPLICANT_SUPPORT //
330 MlmeRadioOff(pAd);
332 #endif // CONFIG_STA_SUPPORT //
334 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
336 for (i = 0 ; i < NUM_OF_TX_RING; i++)
338 while (pAd->DeQueueRunning[i] == TRUE)
340 printk("Waiting for TxQueue[%d] done..........\n", i);
341 RTMPusecDelay(1000);
345 #ifdef RT2870
346 // ensure there are no more active urbs.
347 add_wait_queue (&unlink_wakeup, &wait);
348 pAd->wait = &unlink_wakeup;
350 // maybe wait for deletions to finish.
351 i = 0;
352 //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
353 while(i < 25)
355 unsigned long IrqFlags;
357 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
358 if (pAd->PendingRx == 0)
360 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
361 break;
363 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
365 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
366 msleep(UNLINK_TIMEOUT_MS); //Time in millisecond
367 #else
368 RTMPusecDelay(UNLINK_TIMEOUT_MS*1000); //Time in microsecond
369 #endif
370 i++;
372 pAd->wait = NULL;
373 remove_wait_queue (&unlink_wakeup, &wait);
374 #endif // RT2870 //
376 //RTUSBCleanUpMLMEWaitQueue(pAd); /*not used in RT28xx*/
379 #ifdef RT2870
380 // We need clear timerQ related structure before exits of the timer thread.
381 RT2870_TimerQ_Exit(pAd);
382 // Close kernel threads or tasklets
383 RT28xxThreadTerminate(pAd);
384 #endif // RT2870 //
386 // Stop Mlme state machine
387 MlmeHalt(pAd);
389 // Close kernel threads or tasklets
390 kill_thread_task(pAd);
393 #ifdef CONFIG_STA_SUPPORT
394 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
396 MacTableReset(pAd);
398 #endif // CONFIG_STA_SUPPORT //
401 MeasureReqTabExit(pAd);
402 TpcReqTabExit(pAd);
407 // Free Ring or USB buffers
408 RTMPFreeTxRxRingMemory(pAd);
410 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
412 #ifdef DOT11_N_SUPPORT
413 // Free BA reorder resource
414 ba_reordering_resource_release(pAd);
415 #endif // DOT11_N_SUPPORT //
417 #ifdef RT2870
418 #ifdef INF_AMAZON_SE
419 if (pAd->UsbVendorReqBuf)
420 os_free_mem(pAd, pAd->UsbVendorReqBuf);
421 #endif // INF_AMAZON_SE //
422 #endif // RT2870 //
424 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
426 return 0; // close ok
427 } /* End of rt28xx_close */
429 static int rt28xx_init(IN struct net_device *net_dev)
431 PRTMP_ADAPTER pAd = net_dev->ml_priv;
432 UINT index;
433 UCHAR TmpPhy;
434 // ULONG Value=0;
435 NDIS_STATUS Status;
436 // OID_SET_HT_PHYMODE SetHT;
437 // WPDMA_GLO_CFG_STRUC GloCfg;
438 UINT32 MacCsr0 = 0;
439 UINT32 MacValue = 0;
441 #ifdef RT2870
442 #ifdef INF_AMAZON_SE
443 init_MUTEX(&(pAd->UsbVendorReq_semaphore));
444 os_alloc_mem(pAd, (PUCHAR)&pAd->UsbVendorReqBuf, MAX_PARAM_BUFFER_SIZE - 1);
445 if (pAd->UsbVendorReqBuf == NULL)
447 DBGPRINT(RT_DEBUG_ERROR, ("Allocate vendor request temp buffer failed!\n"));
448 goto err0;
450 #endif // INF_AMAZON_SE //
451 #endif // RT2870 //
453 #ifdef DOT11_N_SUPPORT
454 // Allocate BA Reordering memory
455 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
456 #endif // DOT11_N_SUPPORT //
458 // Make sure MAC gets ready.
459 index = 0;
462 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
463 pAd->MACVersion = MacCsr0;
465 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
466 break;
468 RTMPusecDelay(10);
469 } while (index++ < 100);
471 DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
472 /*Iverson patch PCIE L1 issue */
474 // Disable DMA
475 RT28XXDMADisable(pAd);
478 // Load 8051 firmware
479 Status = NICLoadFirmware(pAd);
480 if (Status != NDIS_STATUS_SUCCESS)
482 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
483 goto err1;
486 NICLoadRateSwitchingParams(pAd);
488 // Disable interrupts here which is as soon as possible
489 // This statement should never be true. We might consider to remove it later
491 Status = RTMPAllocTxRxRingMemory(pAd);
492 if (Status != NDIS_STATUS_SUCCESS)
494 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
495 goto err1;
498 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
500 // initialize MLME
503 Status = MlmeInit(pAd);
504 if (Status != NDIS_STATUS_SUCCESS)
506 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
507 goto err2;
510 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
512 UserCfgInit(pAd);
514 #ifdef RT2870
515 // We need init timerQ related structure before create the timer thread.
516 RT2870_TimerQ_Init(pAd);
517 #endif // RT2870 //
519 RT28XX_TASK_THREAD_INIT(pAd, Status);
520 if (Status != NDIS_STATUS_SUCCESS)
521 goto err1;
523 // COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
524 // pAd->bForcePrintTX = TRUE;
526 CfgInitHook(pAd);
529 #ifdef BLOCK_NET_IF
530 initblockQueueTab(pAd);
531 #endif // BLOCK_NET_IF //
533 #ifdef CONFIG_STA_SUPPORT
534 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
535 NdisAllocateSpinLock(&pAd->MacTabLock);
536 #endif // CONFIG_STA_SUPPORT //
538 MeasureReqTabInit(pAd);
539 TpcReqTabInit(pAd);
542 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
544 Status = NICInitializeAdapter(pAd, TRUE);
545 if (Status != NDIS_STATUS_SUCCESS)
547 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
548 if (Status != NDIS_STATUS_SUCCESS)
549 goto err3;
552 // Read parameters from Config File
553 Status = RTMPReadParametersHook(pAd);
555 printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
556 if (Status != NDIS_STATUS_SUCCESS)
558 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
559 goto err4;
562 #ifdef RT2870
563 pAd->CommonCfg.bMultipleIRP = FALSE;
565 if (pAd->CommonCfg.bMultipleIRP)
566 pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
567 else
568 pAd->CommonCfg.NumOfBulkInIRP = 1;
569 #endif // RT2870 //
572 //Init Ba Capability parameters.
573 // RT28XX_BA_INIT(pAd);
574 #ifdef DOT11_N_SUPPORT
575 pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
576 pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
577 pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
578 pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
579 // UPdata to HT IE
580 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
581 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
582 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
583 #endif // DOT11_N_SUPPORT //
585 // after reading Registry, we now know if in AP mode or STA mode
587 // Load 8051 firmware; crash when FW image not existent
588 // Status = NICLoadFirmware(pAd);
589 // if (Status != NDIS_STATUS_SUCCESS)
590 // break;
592 printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
594 // We should read EEPROM for all cases. rt2860b
595 NICReadEEPROMParameters(pAd, mac);
596 #ifdef CONFIG_STA_SUPPORT
597 #endif // CONFIG_STA_SUPPORT //
599 printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
601 NICInitAsicFromEEPROM(pAd); //rt2860b
603 // Set PHY to appropriate mode
604 TmpPhy = pAd->CommonCfg.PhyMode;
605 pAd->CommonCfg.PhyMode = 0xff;
606 RTMPSetPhyMode(pAd, TmpPhy);
607 #ifdef DOT11_N_SUPPORT
608 SetCommonHT(pAd);
609 #endif // DOT11_N_SUPPORT //
611 // No valid channels.
612 if (pAd->ChannelListNum == 0)
614 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
615 goto err4;
618 #ifdef DOT11_N_SUPPORT
619 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
620 pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
621 pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
622 #endif // DOT11_N_SUPPORT //
624 #ifdef RT30xx
625 //Init RT30xx RFRegisters after read RFIC type from EEPROM
626 NICInitRT30xxRFRegisters(pAd);
627 #endif // RT30xx //
629 // APInitialize(pAd);
631 #ifdef IKANOS_VX_1X0
632 VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
633 #endif // IKANOS_VX_1X0 //
636 // Initialize RF register to default value
638 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
639 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
641 if (pAd && (Status != NDIS_STATUS_SUCCESS))
644 // Undo everything if it failed
646 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
648 // NdisMDeregisterInterrupt(&pAd->Interrupt);
649 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
651 // RTMPFreeAdapter(pAd); // we will free it in disconnect()
653 else if (pAd)
655 // Microsoft HCT require driver send a disconnect event after driver initialization.
656 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
657 // pAd->IndicateMediaState = NdisMediaStateDisconnected;
658 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
660 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
663 #ifdef RT2870
664 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
665 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
668 // Support multiple BulkIn IRP,
669 // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
671 for(index=0; index<pAd->CommonCfg.NumOfBulkInIRP; index++)
673 RTUSBBulkReceive(pAd);
674 DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n" ));
676 #endif // RT2870 //
677 }// end of else
680 DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
682 return TRUE;
685 err4:
686 err3:
687 MlmeHalt(pAd);
688 err2:
689 RTMPFreeTxRxRingMemory(pAd);
690 // RTMPFreeAdapter(pAd);
691 err1:
693 #ifdef DOT11_N_SUPPORT
694 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
695 #endif // DOT11_N_SUPPORT //
696 RT28XX_IRQ_RELEASE(net_dev);
698 // shall not set priv to NULL here because the priv didn't been free yet.
699 //net_dev->ml_priv = 0;
700 #ifdef INF_AMAZON_SE
701 err0:
702 #endif // INF_AMAZON_SE //
703 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
704 return FALSE;
705 } /* End of rt28xx_init */
709 ========================================================================
710 Routine Description:
711 Open raxx interface.
713 Arguments:
714 *net_dev the raxx interface pointer
716 Return Value:
717 0 Open OK
718 otherwise Open Fail
720 Note:
721 ========================================================================
723 int rt28xx_open(IN PNET_DEV dev)
725 struct net_device * net_dev = (struct net_device *)dev;
726 PRTMP_ADAPTER pAd = net_dev->ml_priv;
727 int retval = 0;
728 POS_COOKIE pObj;
731 // Sanity check for pAd
732 if (pAd == NULL)
734 /* if 1st open fail, pAd will be free;
735 So the net_dev->ml_priv will be NULL in 2rd open */
736 return -1;
739 #ifdef CONFIG_APSTA_MIXED_SUPPORT
740 if (pAd->OpMode == OPMODE_AP)
742 CW_MAX_IN_BITS = 6;
744 else if (pAd->OpMode == OPMODE_STA)
746 CW_MAX_IN_BITS = 10;
749 #if WIRELESS_EXT >= 12
750 if (net_dev->ml_priv_flags == INT_MAIN)
752 if (pAd->OpMode == OPMODE_AP)
753 net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_ap_iw_handler_def;
754 else if (pAd->OpMode == OPMODE_STA)
755 net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_iw_handler_def;
757 #endif // WIRELESS_EXT >= 12 //
758 #endif // CONFIG_APSTA_MIXED_SUPPORT //
760 #ifdef CONFIG_STA_SUPPORT
761 #endif // CONFIG_STA_SUPPORT //
763 // Init
764 pObj = (POS_COOKIE)pAd->OS_Cookie;
766 // reset Adapter flags
767 RTMP_CLEAR_FLAGS(pAd);
769 // Request interrupt service routine for PCI device
770 // register the interrupt routine with the os
771 RT28XX_IRQ_REQUEST(net_dev);
774 // Init BssTab & ChannelInfo tabbles for auto channel select.
777 // Chip & other init
778 if (rt28xx_init(net_dev) == FALSE)
779 goto err;
781 #ifdef CONFIG_STA_SUPPORT
782 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
784 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
785 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
787 #endif // CONFIG_STA_SUPPORT //
789 // Set up the Mac address
790 NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
792 // Init IRQ parameters
793 RT28XX_IRQ_INIT(pAd);
795 // Various AP function init
799 #ifdef CONFIG_STA_SUPPORT
800 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
802 #ifdef WPA_SUPPLICANT_SUPPORT
803 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
805 union iwreq_data wrqu;
806 // send wireless event to wpa_supplicant for infroming interface down.
807 memset(&wrqu, 0, sizeof(wrqu));
808 wrqu.data.flags = RT_INTERFACE_UP;
809 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
811 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
812 #endif // WPA_SUPPLICANT_SUPPORT //
815 #endif // CONFIG_STA_SUPPORT //
817 // Enable Interrupt
818 RT28XX_IRQ_ENABLE(pAd);
820 // Now Enable RxTx
821 RTMPEnableRxTx(pAd);
822 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
825 UINT32 reg = 0;
826 RTMP_IO_READ32(pAd, 0x1300, &reg); // clear garbage interrupts
827 printk("0x1300 = %08x\n", reg);
831 // u32 reg;
832 // u8 byte;
833 // u16 tmp;
835 // RTMP_IO_READ32(pAd, XIFS_TIME_CFG, &reg);
837 // tmp = 0x0805;
838 // reg = (reg & 0xffff0000) | tmp;
839 // RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
843 #ifdef CONFIG_STA_SUPPORT
844 #endif // CONFIG_STA_SUPPORT //
846 return (retval);
848 err:
849 return (-1);
850 } /* End of rt28xx_open */
853 /* Must not be called for mdev and apdev */
854 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
856 NDIS_STATUS Status;
857 INT i=0;
858 CHAR slot_name[IFNAMSIZ];
859 struct net_device *device;
862 //ether_setup(dev);
863 dev->hard_start_xmit = rt28xx_send_packets;
865 #ifdef IKANOS_VX_1X0
866 dev->hard_start_xmit = IKANOS_DataFramesTx;
867 #endif // IKANOS_VX_1X0 //
869 // dev->set_multicast_list = ieee80211_set_multicast_list;
870 // dev->change_mtu = ieee80211_change_mtu;
871 #ifdef CONFIG_STA_SUPPORT
872 #if WIRELESS_EXT >= 12
873 if (pAd->OpMode == OPMODE_STA)
875 dev->wireless_handlers = &rt28xx_iw_handler_def;
877 #endif //WIRELESS_EXT >= 12
878 #endif // CONFIG_STA_SUPPORT //
880 #ifdef CONFIG_APSTA_MIXED_SUPPORT
881 #if WIRELESS_EXT >= 12
882 if (pAd->OpMode == OPMODE_AP)
884 dev->wireless_handlers = &rt28xx_ap_iw_handler_def;
886 #endif //WIRELESS_EXT >= 12
887 #endif // CONFIG_APSTA_MIXED_SUPPORT //
889 #if WIRELESS_EXT < 21
890 dev->get_wireless_stats = rt28xx_get_wireless_stats;
891 #endif
892 dev->get_stats = RT28xx_get_ether_stats;
893 dev->open = MainVirtualIF_open; //rt28xx_open;
894 dev->stop = MainVirtualIF_close; //rt28xx_close;
895 // dev->uninit = ieee80211_if_reinit;
896 // dev->destructor = ieee80211_if_free;
897 dev->priv_flags = INT_MAIN;
898 dev->do_ioctl = rt28xx_ioctl;
899 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
900 dev->validate_addr = NULL;
901 #endif
902 // find available device name
903 for (i = 0; i < 8; i++)
905 #ifdef MULTIPLE_CARD_SUPPORT
906 if (pAd->MC_RowID >= 0)
907 sprintf(slot_name, "ra%02d_%d", pAd->MC_RowID, i);
908 else
909 #endif // MULTIPLE_CARD_SUPPORT //
910 sprintf(slot_name, "ra%d", i);
912 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
913 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
914 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
915 device = dev_get_by_name(dev_net(dev), slot_name);
916 #else
917 device = dev_get_by_name(dev->nd_net, slot_name);
918 #endif
919 #else
920 device = dev_get_by_name(slot_name);
921 #endif
922 if (device != NULL) dev_put(device);
923 #else
924 for (device = dev_base; device != NULL; device = device->next)
926 if (strncmp(device->name, slot_name, 4) == 0)
927 break;
929 #endif
930 if(device == NULL)
931 break;
934 if(i == 8)
936 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
937 Status = NDIS_STATUS_FAILURE;
939 else
941 #ifdef MULTIPLE_CARD_SUPPORT
942 if (pAd->MC_RowID >= 0)
943 sprintf(dev->name, "ra%02d_%d", pAd->MC_RowID, i);
944 else
945 #endif // MULTIPLE_CARD_SUPPORT //
946 sprintf(dev->name, "ra%d", i);
947 Status = NDIS_STATUS_SUCCESS;
950 return Status;
955 #ifdef MULTIPLE_CARD_SUPPORT
957 ========================================================================
958 Routine Description:
959 Get card profile path.
961 Arguments:
964 Return Value:
965 TRUE - Find a card profile
966 FALSE - use default profile
968 Note:
969 ========================================================================
971 extern INT RTMPGetKeyParameter(
972 IN PCHAR key,
973 OUT PCHAR dest,
974 IN INT destsize,
975 IN PCHAR buffer);
977 BOOLEAN RTMP_CardInfoRead(
978 IN PRTMP_ADAPTER pAd)
980 #define MC_SELECT_CARDID 0 /* use CARD ID (0 ~ 31) to identify different cards */
981 #define MC_SELECT_MAC 1 /* use CARD MAC to identify different cards */
982 #define MC_SELECT_CARDTYPE 2 /* use CARD type (abgn or bgn) to identify different cards */
984 #define LETTER_CASE_TRANSLATE(txt_p, card_id) \
985 { UINT32 _len; char _char; \
986 for(_len=0; _len<strlen(card_id); _len++) { \
987 _char = *(txt_p + _len); \
988 if (('A' <= _char) && (_char <= 'Z')) \
989 *(txt_p+_len) = 'a'+(_char-'A'); \
992 struct file *srcf;
993 INT retval, orgfsuid, orgfsgid;
994 mm_segment_t orgfs;
995 CHAR *buffer, *tmpbuf, card_id_buf[30], RFIC_word[30];
996 BOOLEAN flg_match_ok = FALSE;
997 INT32 card_select_method;
998 INT32 card_free_id, card_nouse_id, card_same_mac_id, card_match_id;
999 EEPROM_ANTENNA_STRUC antenna;
1000 USHORT addr01, addr23, addr45;
1001 UINT8 mac[6];
1002 UINT32 data, card_index;
1003 UCHAR *start_ptr;
1006 // init
1007 buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
1008 if (buffer == NULL)
1009 return FALSE;
1011 tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
1012 if(tmpbuf == NULL)
1014 kfree(buffer);
1015 return NDIS_STATUS_FAILURE;
1018 orgfsuid = current->fsuid;
1019 orgfsgid = current->fsgid;
1020 current->fsuid = current->fsgid = 0;
1021 orgfs = get_fs();
1022 set_fs(KERNEL_DS);
1024 // get RF IC type
1025 RTMP_IO_READ32(pAd, E2PROM_CSR, &data);
1027 if ((data & 0x30) == 0)
1028 pAd->EEPROMAddressNum = 6; // 93C46
1029 else if ((data & 0x30) == 0x10)
1030 pAd->EEPROMAddressNum = 8; // 93C66
1031 else
1032 pAd->EEPROMAddressNum = 8; // 93C86
1034 //antenna.word = RTMP_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET);
1035 RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, antenna.word);
1037 if ((antenna.field.RfIcType == RFIC_2850) ||
1038 (antenna.field.RfIcType == RFIC_2750))
1040 /* ABGN card */
1041 strcpy(RFIC_word, "abgn");
1043 else
1045 /* BGN card */
1046 strcpy(RFIC_word, "bgn");
1049 // get MAC address
1050 //addr01 = RTMP_EEPROM_READ16(pAd, 0x04);
1051 //addr23 = RTMP_EEPROM_READ16(pAd, 0x06);
1052 //addr45 = RTMP_EEPROM_READ16(pAd, 0x08);
1053 RT28xx_EEPROM_READ16(pAd, 0x04, addr01);
1054 RT28xx_EEPROM_READ16(pAd, 0x06, addr23);
1055 RT28xx_EEPROM_READ16(pAd, 0x08, addr45);
1057 mac[0] = (UCHAR)(addr01 & 0xff);
1058 mac[1] = (UCHAR)(addr01 >> 8);
1059 mac[2] = (UCHAR)(addr23 & 0xff);
1060 mac[3] = (UCHAR)(addr23 >> 8);
1061 mac[4] = (UCHAR)(addr45 & 0xff);
1062 mac[5] = (UCHAR)(addr45 >> 8);
1064 // open card information file
1065 srcf = filp_open(CARD_INFO_PATH, O_RDONLY, 0);
1066 if (IS_ERR(srcf))
1068 /* card information file does not exist */
1069 DBGPRINT(RT_DEBUG_TRACE,
1070 ("--> Error %ld opening %s\n", -PTR_ERR(srcf), CARD_INFO_PATH));
1071 return FALSE;
1074 if (srcf->f_op && srcf->f_op->read)
1076 /* card information file exists so reading the card information */
1077 memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
1078 retval = srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
1079 if (retval < 0)
1081 /* read fail */
1082 DBGPRINT(RT_DEBUG_TRACE,
1083 ("--> Read %s error %d\n", CARD_INFO_PATH, -retval));
1085 else
1087 /* get card selection method */
1088 memset(tmpbuf, 0x00, MAX_PARAM_BUFFER_SIZE);
1089 card_select_method = MC_SELECT_CARDTYPE; // default
1091 if (RTMPGetKeyParameter("SELECT", tmpbuf, 256, buffer))
1093 if (strcmp(tmpbuf, "CARDID") == 0)
1094 card_select_method = MC_SELECT_CARDID;
1095 else if (strcmp(tmpbuf, "MAC") == 0)
1096 card_select_method = MC_SELECT_MAC;
1097 else if (strcmp(tmpbuf, "CARDTYPE") == 0)
1098 card_select_method = MC_SELECT_CARDTYPE;
1101 DBGPRINT(RT_DEBUG_TRACE,
1102 ("MC> Card Selection = %d\n", card_select_method));
1104 // init
1105 card_free_id = -1;
1106 card_nouse_id = -1;
1107 card_same_mac_id = -1;
1108 card_match_id = -1;
1110 // search current card information records
1111 for(card_index=0;
1112 card_index<MAX_NUM_OF_MULTIPLE_CARD;
1113 card_index++)
1115 if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
1116 (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
1118 // MAC is all-0 so the entry is available
1119 MC_CardUsed[card_index] = 0;
1121 if (card_free_id < 0)
1122 card_free_id = card_index; // 1st free entry
1124 else
1126 if (memcmp(MC_CardMac[card_index], mac, 6) == 0)
1128 // we find the entry with same MAC
1129 if (card_same_mac_id < 0)
1130 card_same_mac_id = card_index; // 1st same entry
1132 else
1134 // MAC is not all-0 but used flag == 0
1135 if ((MC_CardUsed[card_index] == 0) &&
1136 (card_nouse_id < 0))
1138 card_nouse_id = card_index; // 1st available entry
1144 DBGPRINT(RT_DEBUG_TRACE,
1145 ("MC> Free = %d, Same = %d, NOUSE = %d\n",
1146 card_free_id, card_same_mac_id, card_nouse_id));
1148 if ((card_same_mac_id >= 0) &&
1149 ((card_select_method == MC_SELECT_CARDID) ||
1150 (card_select_method == MC_SELECT_CARDTYPE)))
1152 // same MAC entry is found
1153 card_match_id = card_same_mac_id;
1155 if (card_select_method == MC_SELECT_CARDTYPE)
1157 // for CARDTYPE
1158 sprintf(card_id_buf, "%02dCARDTYPE%s",
1159 card_match_id, RFIC_word);
1161 if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
1163 // we found the card ID
1164 LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1168 else
1170 // the card is 1st plug-in, try to find the match card profile
1171 switch(card_select_method)
1173 case MC_SELECT_CARDID: // CARDID
1174 default:
1175 if (card_free_id >= 0)
1176 card_match_id = card_free_id;
1177 else
1178 card_match_id = card_nouse_id;
1179 break;
1181 case MC_SELECT_MAC: // MAC
1182 sprintf(card_id_buf, "MAC%02x:%02x:%02x:%02x:%02x:%02x",
1183 mac[0], mac[1], mac[2],
1184 mac[3], mac[4], mac[5]);
1186 /* try to find the key word in the card file */
1187 if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
1189 LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1191 /* get the row ID (2 ASCII characters) */
1192 start_ptr -= 2;
1193 card_id_buf[0] = *(start_ptr);
1194 card_id_buf[1] = *(start_ptr+1);
1195 card_id_buf[2] = 0x00;
1197 card_match_id = simple_strtol(card_id_buf, 0, 10);
1199 break;
1201 case MC_SELECT_CARDTYPE: // CARDTYPE
1202 card_nouse_id = -1;
1204 for(card_index=0;
1205 card_index<MAX_NUM_OF_MULTIPLE_CARD;
1206 card_index++)
1208 sprintf(card_id_buf, "%02dCARDTYPE%s",
1209 card_index, RFIC_word);
1211 if ((start_ptr=rtstrstruncasecmp(buffer,
1212 card_id_buf)) != NULL)
1214 LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1216 if (MC_CardUsed[card_index] == 0)
1218 /* current the card profile is not used */
1219 if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
1220 (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
1222 // find it and no previous card use it
1223 card_match_id = card_index;
1224 break;
1226 else
1228 // ever a card use it
1229 if (card_nouse_id < 0)
1230 card_nouse_id = card_index;
1236 // if not find a free one, use the available one
1237 if (card_match_id < 0)
1238 card_match_id = card_nouse_id;
1239 break;
1243 if (card_match_id >= 0)
1245 // make up search keyword
1246 switch(card_select_method)
1248 case MC_SELECT_CARDID: // CARDID
1249 sprintf(card_id_buf, "%02dCARDID", card_match_id);
1250 break;
1252 case MC_SELECT_MAC: // MAC
1253 sprintf(card_id_buf,
1254 "%02dmac%02x:%02x:%02x:%02x:%02x:%02x",
1255 card_match_id,
1256 mac[0], mac[1], mac[2],
1257 mac[3], mac[4], mac[5]);
1258 break;
1260 case MC_SELECT_CARDTYPE: // CARDTYPE
1261 default:
1262 sprintf(card_id_buf, "%02dcardtype%s",
1263 card_match_id, RFIC_word);
1264 break;
1267 DBGPRINT(RT_DEBUG_TRACE, ("Search Keyword = %s\n", card_id_buf));
1269 // read card file path
1270 if (RTMPGetKeyParameter(card_id_buf, tmpbuf, 256, buffer))
1272 if (strlen(tmpbuf) < sizeof(pAd->MC_FileName))
1274 // backup card information
1275 pAd->MC_RowID = card_match_id; /* base 0 */
1276 MC_CardUsed[card_match_id] = 1;
1277 memcpy(MC_CardMac[card_match_id], mac, sizeof(mac));
1279 // backup card file path
1280 NdisMoveMemory(pAd->MC_FileName, tmpbuf , strlen(tmpbuf));
1281 pAd->MC_FileName[strlen(tmpbuf)] = '\0';
1282 flg_match_ok = TRUE;
1284 DBGPRINT(RT_DEBUG_TRACE,
1285 ("Card Profile Name = %s\n", pAd->MC_FileName));
1287 else
1289 DBGPRINT(RT_DEBUG_ERROR,
1290 ("Card Profile Name length too large!\n"));
1293 else
1295 DBGPRINT(RT_DEBUG_ERROR,
1296 ("Can not find search key word in card.dat!\n"));
1299 if ((flg_match_ok != TRUE) &&
1300 (card_match_id < MAX_NUM_OF_MULTIPLE_CARD))
1302 MC_CardUsed[card_match_id] = 0;
1303 memset(MC_CardMac[card_match_id], 0, sizeof(mac));
1305 } // if (card_match_id >= 0)
1309 // close file
1310 retval = filp_close(srcf, NULL);
1311 set_fs(orgfs);
1312 current->fsuid = orgfsuid;
1313 current->fsgid = orgfsgid;
1314 kfree(buffer);
1315 kfree(tmpbuf);
1316 return flg_match_ok;
1318 #endif // MULTIPLE_CARD_SUPPORT //
1322 ========================================================================
1323 Routine Description:
1324 Probe RT28XX chipset.
1326 Arguments:
1327 _dev_p Point to the PCI or USB device
1328 _dev_id_p Point to the PCI or USB device ID
1330 Return Value:
1331 0 Probe OK
1332 -ENODEV Probe Fail
1334 Note:
1335 ========================================================================
1337 INT __devinit rt28xx_probe(
1338 IN void *_dev_p,
1339 IN void *_dev_id_p,
1340 IN UINT argc,
1341 OUT PRTMP_ADAPTER *ppAd)
1343 struct net_device *net_dev;
1344 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) NULL;
1345 INT status;
1346 PVOID handle;
1347 #ifdef RT2870
1348 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1349 struct usb_device *dev_p = (struct usb_device *)_dev_p;
1350 #else
1351 struct usb_interface *intf = (struct usb_interface *)_dev_p;
1352 struct usb_device *dev_p = interface_to_usbdev(intf);
1354 dev_p = usb_get_dev(dev_p);
1355 #endif // LINUX_VERSION_CODE //
1356 #endif // RT2870 //
1359 #ifdef CONFIG_STA_SUPPORT
1360 DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
1361 #endif // CONFIG_STA_SUPPORT //
1363 // Check chipset vendor/product ID
1364 // if (RT28XXChipsetCheck(_dev_p) == FALSE)
1365 // goto err_out;
1367 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
1368 net_dev = alloc_netdev(sizeof(PRTMP_ADAPTER), "eth%d", ether_setup);
1369 #else
1370 net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
1371 #endif
1372 if (net_dev == NULL)
1374 printk("alloc_netdev failed\n");
1376 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1377 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1378 module_put(THIS_MODULE);
1379 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1380 #else
1381 MOD_DEC_USE_COUNT;
1382 #endif
1383 goto err_out;
1386 // sample
1387 // if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
1388 // goto err_out;
1390 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1391 SET_MODULE_OWNER(net_dev);
1392 #endif
1394 netif_stop_queue(net_dev);
1395 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
1396 /* for supporting Network Manager */
1397 /* Set the sysfs physical device reference for the network logical device
1398 * if set prior to registration will cause a symlink during initialization.
1400 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
1401 SET_NETDEV_DEV(net_dev, &(dev_p->dev));
1402 #endif
1403 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
1405 // Allocate RTMP_ADAPTER miniport adapter structure
1406 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
1407 RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
1409 status = RTMPAllocAdapterBlock(handle, &pAd);
1410 if (status != NDIS_STATUS_SUCCESS)
1411 goto err_out_free_netdev;
1413 net_dev->ml_priv = (PVOID)pAd;
1414 pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
1416 RT28XXNetDevInit(_dev_p, net_dev, pAd);
1418 #ifdef CONFIG_STA_SUPPORT
1419 pAd->StaCfg.OriDevType = net_dev->type;
1420 #endif // CONFIG_STA_SUPPORT //
1422 // Find and assign a free interface name, raxx
1423 // RT28XXAvailRANameAssign(net_dev->name);
1425 // Post config
1426 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1427 if (RT28XXProbePostConfig(_dev_p, pAd, argc) == FALSE)
1428 goto err_out_unmap;
1429 #else
1430 if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
1431 goto err_out_unmap;
1432 #endif // LINUX_VERSION_CODE //
1434 #ifdef CONFIG_STA_SUPPORT
1435 pAd->OpMode = OPMODE_STA;
1436 #endif // CONFIG_STA_SUPPORT //
1439 #ifdef MULTIPLE_CARD_SUPPORT
1440 // find its profile path
1441 pAd->MC_RowID = -1; // use default profile path
1442 RTMP_CardInfoRead(pAd);
1444 if (pAd->MC_RowID == -1)
1445 #ifdef CONFIG_STA_SUPPORT
1446 strcpy(pAd->MC_FileName, STA_PROFILE_PATH);
1447 #endif // CONFIG_STA_SUPPORT //
1449 DBGPRINT(RT_DEBUG_TRACE,
1450 ("MC> ROW = %d, PATH = %s\n", pAd->MC_RowID, pAd->MC_FileName));
1451 #endif // MULTIPLE_CARD_SUPPORT //
1453 // sample move
1454 if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
1455 goto err_out_unmap;
1457 // Register this device
1458 status = register_netdev(net_dev);
1459 if (status)
1460 goto err_out_unmap;
1462 // Set driver data
1463 RT28XX_DRVDATA_SET(_dev_p);
1467 *ppAd = pAd;
1468 return 0; // probe ok
1471 /* --------------------------- ERROR HANDLE --------------------------- */
1472 err_out_unmap:
1473 RTMPFreeAdapter(pAd);
1474 RT28XX_UNMAP();
1476 err_out_free_netdev:
1477 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1478 free_netdev(net_dev);
1479 #else
1480 kfree(net_dev);
1481 #endif
1483 err_out:
1484 RT28XX_PUT_DEVICE(dev_p);
1486 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1487 return (LONG)NULL;
1488 #else
1489 return -ENODEV; /* probe fail */
1490 #endif // LINUX_VERSION_CODE //
1491 } /* End of rt28xx_probe */
1495 ========================================================================
1496 Routine Description:
1497 The entry point for Linux kernel sent packet to our driver.
1499 Arguments:
1500 sk_buff *skb the pointer refer to a sk_buffer.
1502 Return Value:
1505 Note:
1506 This function is the entry point of Tx Path for Os delivery packet to
1507 our driver. You only can put OS-depened & STA/AP common handle procedures
1508 in here.
1509 ========================================================================
1511 int rt28xx_packet_xmit(struct sk_buff *skb)
1513 struct net_device *net_dev = skb->dev;
1514 PRTMP_ADAPTER pAd = net_dev->ml_priv;
1515 int status = 0;
1516 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
1518 /* RT2870STA does this in RTMPSendPackets() */
1519 #ifdef RALINK_ATE
1520 if (ATE_ON(pAd))
1522 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_RESOURCES);
1523 return 0;
1525 #endif // RALINK_ATE //
1527 #ifdef CONFIG_STA_SUPPORT
1528 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1530 // Drop send request since we are in monitor mode
1531 if (MONITOR_ON(pAd))
1533 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1534 goto done;
1537 #endif // CONFIG_STA_SUPPORT //
1539 // EapolStart size is 18
1540 if (skb->len < 14)
1542 //printk("bad packet size: %d\n", pkt->len);
1543 hex_dump("bad packet", skb->data, skb->len);
1544 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1545 goto done;
1548 RTMP_SET_PACKET_5VT(pPacket, 0);
1549 // MiniportMMRequest(pAd, pkt->data, pkt->len);
1550 #ifdef CONFIG_5VT_ENHANCE
1551 if (*(int*)(skb->cb) == BRIDGE_TAG) {
1552 RTMP_SET_PACKET_5VT(pPacket, 1);
1554 #endif
1558 #ifdef CONFIG_STA_SUPPORT
1559 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1562 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
1565 #endif // CONFIG_STA_SUPPORT //
1567 status = 0;
1568 done:
1570 return status;
1575 ========================================================================
1576 Routine Description:
1577 Send a packet to WLAN.
1579 Arguments:
1580 skb_p points to our adapter
1581 dev_p which WLAN network interface
1583 Return Value:
1584 0: transmit successfully
1585 otherwise: transmit fail
1587 Note:
1588 ========================================================================
1590 INT rt28xx_send_packets(
1591 IN struct sk_buff *skb_p,
1592 IN struct net_device *net_dev)
1594 RTMP_ADAPTER *pAd = net_dev->ml_priv;
1596 if (!(net_dev->flags & IFF_UP))
1598 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
1599 return 0;
1602 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
1603 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
1605 return rt28xx_packet_xmit(skb_p);
1606 } /* End of MBSS_VirtualIF_PacketSend */
1611 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
1612 //static struct net_device *alloc_netdev(int sizeof_priv, const char *mask, void (*setup)(struct net_device *)) //sample
1613 struct net_device *alloc_netdev(
1614 int sizeof_priv,
1615 const char *mask,
1616 void (*setup)(struct net_device *))
1618 struct net_device *dev;
1619 INT alloc_size;
1622 /* ensure 32-byte alignment of the private area */
1623 alloc_size = sizeof (*dev) + sizeof_priv + 31;
1625 dev = (struct net_device *) kmalloc(alloc_size, GFP_KERNEL);
1626 if (dev == NULL)
1628 DBGPRINT(RT_DEBUG_ERROR,
1629 ("alloc_netdev: Unable to allocate device memory.\n"));
1630 return NULL;
1633 memset(dev, 0, alloc_size);
1635 if (sizeof_priv)
1636 dev->ml_priv = (void *) (((long)(dev + 1) + 31) & ~31);
1638 setup(dev);
1639 strcpy(dev->name, mask);
1641 return dev;
1643 #endif // LINUX_VERSION_CODE //
1646 void CfgInitHook(PRTMP_ADAPTER pAd)
1648 pAd->bBroadComHT = TRUE;
1649 } /* End of CfgInitHook */
1652 #if WIRELESS_EXT >= 12
1653 // This function will be called when query /proc
1654 struct iw_statistics *rt28xx_get_wireless_stats(
1655 IN struct net_device *net_dev)
1657 PRTMP_ADAPTER pAd = net_dev->ml_priv;
1660 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
1662 pAd->iw_stats.status = 0; // Status - device dependent for now
1664 // link quality
1665 pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
1666 if(pAd->iw_stats.qual.qual > 100)
1667 pAd->iw_stats.qual.qual = 100;
1669 #ifdef CONFIG_STA_SUPPORT
1670 if (pAd->OpMode == OPMODE_STA)
1671 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
1672 #endif // CONFIG_STA_SUPPORT //
1674 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
1676 pAd->iw_stats.qual.noise += 256 - 143;
1677 pAd->iw_stats.qual.updated = 1; // Flags to know if updated
1678 #ifdef IW_QUAL_DBM
1679 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; // Level + Noise are dBm
1680 #endif // IW_QUAL_DBM //
1682 pAd->iw_stats.discard.nwid = 0; // Rx : Wrong nwid/essid
1683 pAd->iw_stats.miss.beacon = 0; // Missed beacons/superframe
1685 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
1686 return &pAd->iw_stats;
1687 } /* End of rt28xx_get_wireless_stats */
1688 #endif // WIRELESS_EXT //
1692 void tbtt_tasklet(unsigned long data)
1694 #define MAX_TX_IN_TBTT (16)
1698 INT rt28xx_ioctl(
1699 IN struct net_device *net_dev,
1700 IN OUT struct ifreq *rq,
1701 IN INT cmd)
1703 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1704 RTMP_ADAPTER *pAd = NULL;
1705 INT ret = 0;
1707 if (net_dev->priv_flags == INT_MAIN)
1709 pAd = net_dev->ml_priv;
1711 else
1713 pVirtualAd = net_dev->ml_priv;
1714 pAd = pVirtualAd->RtmpDev->ml_priv;
1717 if (pAd == NULL)
1719 /* if 1st open fail, pAd will be free;
1720 So the net_dev->ml_priv will be NULL in 2rd open */
1721 return -ENETDOWN;
1725 #ifdef CONFIG_STA_SUPPORT
1726 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1728 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
1730 #endif // CONFIG_STA_SUPPORT //
1732 return ret;
1736 ========================================================================
1738 Routine Description:
1739 return ethernet statistics counter
1741 Arguments:
1742 net_dev Pointer to net_device
1744 Return Value:
1745 net_device_stats*
1747 Note:
1749 ========================================================================
1751 struct net_device_stats *RT28xx_get_ether_stats(
1752 IN struct net_device *net_dev)
1754 RTMP_ADAPTER *pAd = NULL;
1756 if (net_dev)
1757 pAd = net_dev->ml_priv;
1759 if (pAd)
1762 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1763 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1765 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1766 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1768 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1769 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1771 pAd->stats.rx_dropped = 0;
1772 pAd->stats.tx_dropped = 0;
1774 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; // multicast packets received
1775 pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; // Collision packets
1777 pAd->stats.rx_length_errors = 0;
1778 pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; // receiver ring buff overflow
1779 pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1780 pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; // recv'd frame alignment error
1781 pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; // recv'r fifo overrun
1782 pAd->stats.rx_missed_errors = 0; // receiver missed packet
1784 // detailed tx_errors
1785 pAd->stats.tx_aborted_errors = 0;
1786 pAd->stats.tx_carrier_errors = 0;
1787 pAd->stats.tx_fifo_errors = 0;
1788 pAd->stats.tx_heartbeat_errors = 0;
1789 pAd->stats.tx_window_errors = 0;
1791 // for cslip etc
1792 pAd->stats.rx_compressed = 0;
1793 pAd->stats.tx_compressed = 0;
1795 return &pAd->stats;
1797 else
1798 return NULL;