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 #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");
64 module_param (mac
, charp
, 0);
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(
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
);
111 struct net_device_stats
*RT28xx_get_ether_stats(
112 IN
struct net_device
*net_dev
);
115 ========================================================================
117 Close raxx interface.
120 *net_dev the raxx interface pointer
127 1. if open fail, kernel will not call the close function.
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
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 ========================================================================
160 *net_dev the raxx interface pointer
167 1. if open fail, kernel will not call the close function.
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
180 return 0; // close ok
182 if (VIRTUAL_IF_UP(pAd
) != 0)
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
);
196 ========================================================================
198 Close raxx interface.
201 *net_dev the raxx interface pointer
208 1. if open fail, kernel will not call the close function.
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
;
222 DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup
);
223 DECLARE_WAITQUEUE(wait
, current
);
225 //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
229 DBGPRINT(RT_DEBUG_TRACE
, ("===> rt28xx_close\n"));
231 // Sanity check for pAd
233 return 0; // close ok
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
)
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 //
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
);
308 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_REMOVE_IN_PROGRESS
);
312 RTMPCancelTimer(&pAd
->StaCfg
.LeapAuthTimer
, &Cancelled
);
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 //
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
);
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.
352 //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
355 unsigned long IrqFlags
;
357 RTMP_IRQ_LOCK(&pAd
->BulkInLock
, IrqFlags
);
358 if (pAd
->PendingRx
== 0)
360 RTMP_IRQ_UNLOCK(&pAd
->BulkInLock
, IrqFlags
);
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
368 RTMPusecDelay(UNLINK_TIMEOUT_MS
*1000); //Time in microsecond
373 remove_wait_queue (&unlink_wakeup
, &wait
);
376 //RTUSBCleanUpMLMEWaitQueue(pAd); /*not used in RT28xx*/
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
);
386 // Stop Mlme state machine
389 // Close kernel threads or tasklets
390 kill_thread_task(pAd
);
393 #ifdef CONFIG_STA_SUPPORT
394 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
398 #endif // CONFIG_STA_SUPPORT //
401 MeasureReqTabExit(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 //
419 if (pAd
->UsbVendorReqBuf
)
420 os_free_mem(pAd
, pAd
->UsbVendorReqBuf
);
421 #endif // INF_AMAZON_SE //
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
;
436 // OID_SET_HT_PHYMODE SetHT;
437 // WPDMA_GLO_CFG_STRUC GloCfg;
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"));
450 #endif // INF_AMAZON_SE //
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.
462 RTMP_IO_READ32(pAd
, MAC_CSR0
, &MacCsr0
);
463 pAd
->MACVersion
= MacCsr0
;
465 if ((pAd
->MACVersion
!= 0x00) && (pAd
->MACVersion
!= 0xFFFFFFFF))
469 } while (index
++ < 100);
471 DBGPRINT(RT_DEBUG_TRACE
, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd
->MACVersion
));
472 /*Iverson patch PCIE L1 issue */
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
));
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
));
498 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_INTERRUPT_IN_USE
);
503 Status
= MlmeInit(pAd
);
504 if (Status
!= NDIS_STATUS_SUCCESS
)
506 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status
));
510 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
515 // We need init timerQ related structure before create the timer thread.
516 RT2870_TimerQ_Init(pAd
);
519 RT28XX_TASK_THREAD_INIT(pAd
, Status
);
520 if (Status
!= NDIS_STATUS_SUCCESS
)
523 // COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
524 // pAd->bForcePrintTX = TRUE;
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
);
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
)
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
));
563 pAd
->CommonCfg
.bMultipleIRP
= FALSE
;
565 if (pAd
->CommonCfg
.bMultipleIRP
)
566 pAd
->CommonCfg
.NumOfBulkInIRP
= RX_RING_SIZE
;
568 pAd
->CommonCfg
.NumOfBulkInIRP
= 1;
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
;
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)
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
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");
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 //
625 //Init RT30xx RFRegisters after read RFIC type from EEPROM
626 NICInitRT30xxRFRegisters(pAd
);
629 // APInitialize(pAd);
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()
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"));
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" ));
680 DBGPRINT_S(Status
, ("<==== RTMPInitialize, Status=%x\n", Status
));
689 RTMPFreeTxRxRingMemory(pAd
);
690 // RTMPFreeAdapter(pAd);
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;
702 #endif // INF_AMAZON_SE //
703 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME
);
705 } /* End of rt28xx_init */
709 ========================================================================
714 *net_dev the raxx interface pointer
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
;
731 // Sanity check for pAd
734 /* if 1st open fail, pAd will be free;
735 So the net_dev->ml_priv will be NULL in 2rd open */
739 #ifdef CONFIG_APSTA_MIXED_SUPPORT
740 if (pAd
->OpMode
== OPMODE_AP
)
744 else if (pAd
->OpMode
== OPMODE_STA
)
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 //
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.
778 if (rt28xx_init(net_dev
) == FALSE
)
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 //
818 RT28XX_IRQ_ENABLE(pAd
);
822 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_START_UP
);
826 RTMP_IO_READ32(pAd
, 0x1300, ®
); // clear garbage interrupts
827 printk("0x1300 = %08x\n", reg
);
835 // RTMP_IO_READ32(pAd, XIFS_TIME_CFG, ®);
838 // reg = (reg & 0xffff0000) | tmp;
839 // RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
843 #ifdef CONFIG_STA_SUPPORT
844 #endif // CONFIG_STA_SUPPORT //
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
)
858 CHAR slot_name
[IFNAMSIZ
];
859 struct net_device
*device
;
863 dev
->hard_start_xmit
= rt28xx_send_packets
;
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
;
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
;
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
);
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
);
917 device
= dev_get_by_name(dev
->nd_net
, slot_name
);
920 device
= dev_get_by_name(slot_name
);
922 if (device
!= NULL
) dev_put(device
);
924 for (device
= dev_base
; device
!= NULL
; device
= device
->next
)
926 if (strncmp(device
->name
, slot_name
, 4) == 0)
936 DBGPRINT(RT_DEBUG_ERROR
, ("No available slot name\n"));
937 Status
= NDIS_STATUS_FAILURE
;
941 #ifdef MULTIPLE_CARD_SUPPORT
942 if (pAd
->MC_RowID
>= 0)
943 sprintf(dev
->name
, "ra%02d_%d", pAd
->MC_RowID
, i
);
945 #endif // MULTIPLE_CARD_SUPPORT //
946 sprintf(dev
->name
, "ra%d", i
);
947 Status
= NDIS_STATUS_SUCCESS
;
955 #ifdef MULTIPLE_CARD_SUPPORT
957 ========================================================================
959 Get card profile path.
965 TRUE - Find a card profile
966 FALSE - use default profile
969 ========================================================================
971 extern INT
RTMPGetKeyParameter(
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'); \
993 INT retval
, orgfsuid
, orgfsgid
;
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
;
1002 UINT32 data
, card_index
;
1007 buffer
= kmalloc(MAX_INI_BUFFER_SIZE
, MEM_ALLOC_FLAG
);
1011 tmpbuf
= kmalloc(MAX_PARAM_BUFFER_SIZE
, MEM_ALLOC_FLAG
);
1015 return NDIS_STATUS_FAILURE
;
1018 orgfsuid
= current
->fsuid
;
1019 orgfsgid
= current
->fsgid
;
1020 current
->fsuid
= current
->fsgid
= 0;
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
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
))
1041 strcpy(RFIC_word
, "abgn");
1046 strcpy(RFIC_word
, "bgn");
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);
1068 /* card information file does not exist */
1069 DBGPRINT(RT_DEBUG_TRACE
,
1070 ("--> Error %ld opening %s\n", -PTR_ERR(srcf
), CARD_INFO_PATH
));
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
);
1082 DBGPRINT(RT_DEBUG_TRACE
,
1083 ("--> Read %s error %d\n", CARD_INFO_PATH
, -retval
));
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
));
1107 card_same_mac_id
= -1;
1110 // search current card information records
1112 card_index
<MAX_NUM_OF_MULTIPLE_CARD
;
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
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
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
)
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
);
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
1175 if (card_free_id
>= 0)
1176 card_match_id
= card_free_id
;
1178 card_match_id
= card_nouse_id
;
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) */
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);
1201 case MC_SELECT_CARDTYPE
: // CARDTYPE
1205 card_index
<MAX_NUM_OF_MULTIPLE_CARD
;
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
;
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
;
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
);
1252 case MC_SELECT_MAC
: // MAC
1253 sprintf(card_id_buf
,
1254 "%02dmac%02x:%02x:%02x:%02x:%02x:%02x",
1256 mac
[0], mac
[1], mac
[2],
1257 mac
[3], mac
[4], mac
[5]);
1260 case MC_SELECT_CARDTYPE
: // CARDTYPE
1262 sprintf(card_id_buf
, "%02dcardtype%s",
1263 card_match_id
, RFIC_word
);
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
));
1289 DBGPRINT(RT_DEBUG_ERROR
,
1290 ("Card Profile Name length too large!\n"));
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)
1310 retval
= filp_close(srcf
, NULL
);
1312 current
->fsuid
= orgfsuid
;
1313 current
->fsgid
= orgfsgid
;
1316 return flg_match_ok
;
1318 #endif // MULTIPLE_CARD_SUPPORT //
1322 ========================================================================
1323 Routine Description:
1324 Probe RT28XX chipset.
1327 _dev_p Point to the PCI or USB device
1328 _dev_id_p Point to the PCI or USB device ID
1335 ========================================================================
1337 INT __devinit
rt28xx_probe(
1341 OUT PRTMP_ADAPTER
*ppAd
)
1343 struct net_device
*net_dev
;
1344 PRTMP_ADAPTER pAd
= (PRTMP_ADAPTER
) NULL
;
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
;
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 //
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)
1367 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
1368 net_dev
= alloc_netdev(sizeof(PRTMP_ADAPTER
), "eth%d", ether_setup
);
1370 net_dev
= alloc_etherdev(sizeof(PRTMP_ADAPTER
));
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)
1387 // if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
1390 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1391 SET_MODULE_OWNER(net_dev
);
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
));
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);
1426 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1427 if (RT28XXProbePostConfig(_dev_p
, pAd
, argc
) == FALSE
)
1430 if (RT28XXProbePostConfig(_dev_p
, pAd
, 0) == FALSE
)
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 //
1454 if (rt_ieee80211_if_setup(net_dev
, pAd
) != NDIS_STATUS_SUCCESS
)
1457 // Register this device
1458 status
= register_netdev(net_dev
);
1463 RT28XX_DRVDATA_SET(_dev_p
);
1468 return 0; // probe ok
1471 /* --------------------------- ERROR HANDLE --------------------------- */
1473 RTMPFreeAdapter(pAd
);
1476 err_out_free_netdev
:
1477 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1478 free_netdev(net_dev
);
1484 RT28XX_PUT_DEVICE(dev_p
);
1486 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
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.
1500 sk_buff *skb the pointer refer to a sk_buffer.
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
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
;
1516 PNDIS_PACKET pPacket
= (PNDIS_PACKET
) skb
;
1518 /* RT2870STA does this in RTMPSendPackets() */
1522 RELEASE_NDIS_PACKET(pAd
, pPacket
, NDIS_STATUS_RESOURCES
);
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
);
1537 #endif // CONFIG_STA_SUPPORT //
1539 // EapolStart size is 18
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
);
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);
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 //
1575 ========================================================================
1576 Routine Description:
1577 Send a packet to WLAN.
1580 skb_p points to our adapter
1581 dev_p which WLAN network interface
1584 0: transmit successfully
1585 otherwise: transmit fail
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
);
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(
1616 void (*setup
)(struct net_device
*))
1618 struct net_device
*dev
;
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
);
1628 DBGPRINT(RT_DEBUG_ERROR
,
1629 ("alloc_netdev: Unable to allocate device memory.\n"));
1633 memset(dev
, 0, alloc_size
);
1636 dev
->ml_priv
= (void *) (((long)(dev
+ 1) + 31) & ~31);
1639 strcpy(dev
->name
, mask
);
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
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
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)
1699 IN
struct net_device
*net_dev
,
1700 IN OUT
struct ifreq
*rq
,
1703 VIRTUAL_ADAPTER
*pVirtualAd
= NULL
;
1704 RTMP_ADAPTER
*pAd
= NULL
;
1707 if (net_dev
->priv_flags
== INT_MAIN
)
1709 pAd
= net_dev
->ml_priv
;
1713 pVirtualAd
= net_dev
->ml_priv
;
1714 pAd
= pVirtualAd
->RtmpDev
->ml_priv
;
1719 /* if 1st open fail, pAd will be free;
1720 So the net_dev->ml_priv will be NULL in 2rd open */
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 //
1736 ========================================================================
1738 Routine Description:
1739 return ethernet statistics counter
1742 net_dev Pointer to net_device
1749 ========================================================================
1751 struct net_device_stats
*RT28xx_get_ether_stats(
1752 IN
struct net_device
*net_dev
)
1754 RTMP_ADAPTER
*pAd
= NULL
;
1757 pAd
= net_dev
->ml_priv
;
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;
1792 pAd
->stats
.rx_compressed
= 0;
1793 pAd
->stats
.tx_compressed
= 0;