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 /*---------------------------------------------------------------------*/
51 /* Private Variables Used */
52 /*---------------------------------------------------------------------*/
53 //static RALINK_TIMER_STRUCT PeriodicTimer;
55 char *mac
= ""; // default 00:00:00:00:00:00
57 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)
58 MODULE_PARM (mac
, "s");
60 module_param (mac
, charp
, 0);
62 MODULE_PARM_DESC (mac
, "rt28xx: wireless mac addr");
65 /*---------------------------------------------------------------------*/
66 /* Prototypes of Functions Used */
67 /*---------------------------------------------------------------------*/
68 #ifdef DOT11_N_SUPPORT
69 extern BOOLEAN
ba_reordering_resource_init(PRTMP_ADAPTER pAd
, int num
);
70 extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd
);
71 #endif // DOT11_N_SUPPORT //
72 extern NDIS_STATUS
NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd
);
75 // public function prototype
76 INT __devinit
rt28xx_probe(IN
void *_dev_p
, IN
void *_dev_id_p
,
77 IN UINT argc
, OUT PRTMP_ADAPTER
*ppAd
);
79 // private function prototype
80 static int rt28xx_init(IN
struct net_device
*net_dev
);
81 INT
rt28xx_send_packets(IN
struct sk_buff
*skb_p
, IN
struct net_device
*net_dev
);
83 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
84 struct net_device
*alloc_netdev(
87 void (*setup
)(struct net_device
*));
88 #endif // LINUX_VERSION_CODE //
90 static void CfgInitHook(PRTMP_ADAPTER pAd
);
91 //static BOOLEAN RT28XXAvailRANameAssign(IN CHAR *name_p);
93 #ifdef CONFIG_STA_SUPPORT
94 extern const struct iw_handler_def rt28xx_iw_handler_def
;
95 #endif // CONFIG_STA_SUPPORT //
97 #if WIRELESS_EXT >= 12
98 // This function will be called when query /proc
99 struct iw_statistics
*rt28xx_get_wireless_stats(
100 IN
struct net_device
*net_dev
);
103 struct net_device_stats
*RT28xx_get_ether_stats(
104 IN
struct net_device
*net_dev
);
107 ========================================================================
109 Close raxx interface.
112 *net_dev the raxx interface pointer
119 1. if open fail, kernel will not call the close function.
121 (1) Mlme Memory Handler: MlmeHalt()
122 (2) TX & RX: RTMPFreeTxRxRingMemory()
123 (3) BA Reordering: ba_reordering_resource_release()
124 ========================================================================
126 int MainVirtualIF_close(IN
struct net_device
*net_dev
)
128 RTMP_ADAPTER
*pAd
= net_dev
->priv
;
130 // Sanity check for pAd
132 return 0; // close ok
134 netif_carrier_off(pAd
->net_dev
);
135 netif_stop_queue(pAd
->net_dev
);
139 VIRTUAL_IF_DOWN(pAd
);
141 RT_MOD_DEC_USE_COUNT();
143 return 0; // close ok
147 ========================================================================
152 *net_dev the raxx interface pointer
159 1. if open fail, kernel will not call the close function.
161 (1) Mlme Memory Handler: MlmeHalt()
162 (2) TX & RX: RTMPFreeTxRxRingMemory()
163 (3) BA Reordering: ba_reordering_resource_release()
164 ========================================================================
166 int MainVirtualIF_open(IN
struct net_device
*net_dev
)
168 RTMP_ADAPTER
*pAd
= net_dev
->priv
;
170 // Sanity check for pAd
172 return 0; // close ok
174 if (VIRTUAL_IF_UP(pAd
) != 0)
177 // increase MODULE use count
178 RT_MOD_INC_USE_COUNT();
180 netif_start_queue(net_dev
);
181 netif_carrier_on(net_dev
);
182 netif_wake_queue(net_dev
);
188 ========================================================================
190 Close raxx interface.
193 *net_dev the raxx interface pointer
200 1. if open fail, kernel will not call the close function.
202 (1) Mlme Memory Handler: MlmeHalt()
203 (2) TX & RX: RTMPFreeTxRxRingMemory()
204 (3) BA Reordering: ba_reordering_resource_release()
205 ========================================================================
207 int rt28xx_close(IN PNET_DEV dev
)
209 struct net_device
* net_dev
= (struct net_device
*)dev
;
210 RTMP_ADAPTER
*pAd
= net_dev
->priv
;
211 BOOLEAN Cancelled
= FALSE
;
214 DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup
);
215 DECLARE_WAITQUEUE(wait
, current
);
217 //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
221 DBGPRINT(RT_DEBUG_TRACE
, ("===> rt28xx_close\n"));
223 // Sanity check for pAd
225 return 0; // close ok
228 #ifdef CONFIG_STA_SUPPORT
229 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
232 // If dirver doesn't wake up firmware here,
233 // NICLoadFirmware will hang forever when interface is up again.
234 if (OPSTATUS_TEST_FLAG(pAd
, fOP_STATUS_DOZE
))
236 AsicForceWakeup(pAd
, TRUE
);
239 #ifdef QOS_DLS_SUPPORT
240 // send DLS-TEAR_DOWN message,
241 if (pAd
->CommonCfg
.bDLSCapable
)
245 // tear down local dls table entry
246 for (i
=0; i
<MAX_NUM_OF_INIT_DLS_ENTRY
; i
++)
248 if (pAd
->StaCfg
.DLSEntry
[i
].Valid
&& (pAd
->StaCfg
.DLSEntry
[i
].Status
== DLS_FINISH
))
250 RTMPSendDLSTearDownFrame(pAd
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
);
251 pAd
->StaCfg
.DLSEntry
[i
].Status
= DLS_NONE
;
252 pAd
->StaCfg
.DLSEntry
[i
].Valid
= FALSE
;
256 // tear down peer dls table entry
257 for (i
=MAX_NUM_OF_INIT_DLS_ENTRY
; i
<MAX_NUM_OF_DLS_ENTRY
; i
++)
259 if (pAd
->StaCfg
.DLSEntry
[i
].Valid
&& (pAd
->StaCfg
.DLSEntry
[i
].Status
== DLS_FINISH
))
261 RTMPSendDLSTearDownFrame(pAd
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
);
262 pAd
->StaCfg
.DLSEntry
[i
].Status
= DLS_NONE
;
263 pAd
->StaCfg
.DLSEntry
[i
].Valid
= FALSE
;
266 RT28XX_MLME_HANDLER(pAd
);
268 #endif // QOS_DLS_SUPPORT //
271 (!RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)))
273 MLME_DISASSOC_REQ_STRUCT DisReq
;
274 MLME_QUEUE_ELEM
*MsgElem
= (MLME_QUEUE_ELEM
*) kmalloc(sizeof(MLME_QUEUE_ELEM
), MEM_ALLOC_FLAG
);
276 COPY_MAC_ADDR(DisReq
.Addr
, pAd
->CommonCfg
.Bssid
);
277 DisReq
.Reason
= REASON_DEAUTH_STA_LEAVING
;
279 MsgElem
->Machine
= ASSOC_STATE_MACHINE
;
280 MsgElem
->MsgType
= MT2_MLME_DISASSOC_REQ
;
281 MsgElem
->MsgLen
= sizeof(MLME_DISASSOC_REQ_STRUCT
);
282 NdisMoveMemory(MsgElem
->Msg
, &DisReq
, sizeof(MLME_DISASSOC_REQ_STRUCT
));
284 // Prevent to connect AP again in STAMlmePeriodicExec
285 pAd
->MlmeAux
.AutoReconnectSsidLen
= 32;
286 NdisZeroMemory(pAd
->MlmeAux
.AutoReconnectSsid
, pAd
->MlmeAux
.AutoReconnectSsidLen
);
288 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_OID_DISASSOC
;
289 MlmeDisassocReqAction(pAd
, MsgElem
);
296 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_REMOVE_IN_PROGRESS
);
300 RTMPCancelTimer(&pAd
->StaCfg
.LeapAuthTimer
, &Cancelled
);
303 RTMPCancelTimer(&pAd
->StaCfg
.StaQuickResponeForRateUpTimer
, &Cancelled
);
304 RTMPCancelTimer(&pAd
->StaCfg
.WpaDisassocAndBlockAssocTimer
, &Cancelled
);
306 #ifdef WPA_SUPPLICANT_SUPPORT
307 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
309 union iwreq_data wrqu
;
310 // send wireless event to wpa_supplicant for infroming interface down.
311 memset(&wrqu
, 0, sizeof(wrqu
));
312 wrqu
.data
.flags
= RT_INTERFACE_DOWN
;
313 wireless_send_event(pAd
->net_dev
, IWEVCUSTOM
, &wrqu
, NULL
);
315 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
316 #endif // WPA_SUPPLICANT_SUPPORT //
320 #endif // CONFIG_STA_SUPPORT //
322 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_HALT_IN_PROGRESS
);
324 for (i
= 0 ; i
< NUM_OF_TX_RING
; i
++)
326 while (pAd
->DeQueueRunning
[i
] == TRUE
)
328 printk("Waiting for TxQueue[%d] done..........\n", i
);
334 // ensure there are no more active urbs.
335 add_wait_queue (&unlink_wakeup
, &wait
);
336 pAd
->wait
= &unlink_wakeup
;
338 // maybe wait for deletions to finish.
340 //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
343 unsigned long IrqFlags
;
345 RTMP_IRQ_LOCK(&pAd
->BulkInLock
, IrqFlags
);
346 if (pAd
->PendingRx
== 0)
348 RTMP_IRQ_UNLOCK(&pAd
->BulkInLock
, IrqFlags
);
351 RTMP_IRQ_UNLOCK(&pAd
->BulkInLock
, IrqFlags
);
353 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
354 msleep(UNLINK_TIMEOUT_MS
); //Time in millisecond
356 RTMPusecDelay(UNLINK_TIMEOUT_MS
*1000); //Time in microsecond
361 remove_wait_queue (&unlink_wakeup
, &wait
);
364 //RTUSBCleanUpMLMEWaitQueue(pAd); /*not used in RT28xx*/
368 // We need clear timerQ related structure before exits of the timer thread.
369 RT2870_TimerQ_Exit(pAd
);
370 // Close kernel threads or tasklets
371 RT28xxThreadTerminate(pAd
);
374 // Stop Mlme state machine
377 // Close kernel threads or tasklets
378 kill_thread_task(pAd
);
381 #ifdef CONFIG_STA_SUPPORT
382 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
386 #endif // CONFIG_STA_SUPPORT //
389 MeasureReqTabExit(pAd
);
395 // Free Ring or USB buffers
396 RTMPFreeTxRxRingMemory(pAd
);
398 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_HALT_IN_PROGRESS
);
400 #ifdef DOT11_N_SUPPORT
401 // Free BA reorder resource
402 ba_reordering_resource_release(pAd
);
403 #endif // DOT11_N_SUPPORT //
407 if (pAd
->UsbVendorReqBuf
)
408 os_free_mem(pAd
, pAd
->UsbVendorReqBuf
);
409 #endif // INF_AMAZON_SE //
412 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_START_UP
);
414 return 0; // close ok
415 } /* End of rt28xx_close */
417 static int rt28xx_init(IN
struct net_device
*net_dev
)
419 PRTMP_ADAPTER pAd
= (PRTMP_ADAPTER
)net_dev
->priv
;
427 init_MUTEX(&(pAd
->UsbVendorReq_semaphore
));
428 os_alloc_mem(pAd
, (PUCHAR
)&pAd
->UsbVendorReqBuf
, MAX_PARAM_BUFFER_SIZE
- 1);
429 if (pAd
->UsbVendorReqBuf
== NULL
)
431 DBGPRINT(RT_DEBUG_ERROR
, ("Allocate vendor request temp buffer failed!\n"));
434 #endif // INF_AMAZON_SE //
437 #ifdef DOT11_N_SUPPORT
438 // Allocate BA Reordering memory
439 ba_reordering_resource_init(pAd
, MAX_REORDERING_MPDU_NUM
);
440 #endif // DOT11_N_SUPPORT //
442 // Make sure MAC gets ready.
446 RTMP_IO_READ32(pAd
, MAC_CSR0
, &MacCsr0
);
447 pAd
->MACVersion
= MacCsr0
;
449 if ((pAd
->MACVersion
!= 0x00) && (pAd
->MACVersion
!= 0xFFFFFFFF))
453 } while (index
++ < 100);
455 DBGPRINT(RT_DEBUG_TRACE
, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd
->MACVersion
));
458 RT28XXDMADisable(pAd
);
461 // Load 8051 firmware
462 Status
= NICLoadFirmware(pAd
);
463 if (Status
!= NDIS_STATUS_SUCCESS
)
465 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status
));
469 NICLoadRateSwitchingParams(pAd
);
471 // Disable interrupts here which is as soon as possible
472 // This statement should never be true. We might consider to remove it later
474 Status
= RTMPAllocTxRxRingMemory(pAd
);
475 if (Status
!= NDIS_STATUS_SUCCESS
)
477 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status
));
481 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_INTERRUPT_IN_USE
);
486 Status
= MlmeInit(pAd
);
487 if (Status
!= NDIS_STATUS_SUCCESS
)
489 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status
));
493 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
498 // We need init timerQ related structure before create the timer thread.
499 RT2870_TimerQ_Init(pAd
);
502 RT28XX_TASK_THREAD_INIT(pAd
, Status
);
503 if (Status
!= NDIS_STATUS_SUCCESS
)
506 // COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
507 // pAd->bForcePrintTX = TRUE;
513 initblockQueueTab(pAd
);
514 #endif // BLOCK_NET_IF //
516 #ifdef CONFIG_STA_SUPPORT
517 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
518 NdisAllocateSpinLock(&pAd
->MacTabLock
);
519 #endif // CONFIG_STA_SUPPORT //
521 MeasureReqTabInit(pAd
);
525 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
527 Status
= NICInitializeAdapter(pAd
, TRUE
);
528 if (Status
!= NDIS_STATUS_SUCCESS
)
530 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status
));
531 if (Status
!= NDIS_STATUS_SUCCESS
)
535 // Read parameters from Config File
536 Status
= RTMPReadParametersHook(pAd
);
538 printk("1. Phy Mode = %d\n", pAd
->CommonCfg
.PhyMode
);
539 if (Status
!= NDIS_STATUS_SUCCESS
)
541 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status
));
546 pAd
->CommonCfg
.bMultipleIRP
= FALSE
;
548 if (pAd
->CommonCfg
.bMultipleIRP
)
549 pAd
->CommonCfg
.NumOfBulkInIRP
= RX_RING_SIZE
;
551 pAd
->CommonCfg
.NumOfBulkInIRP
= 1;
555 //Init Ba Capability parameters.
556 // RT28XX_BA_INIT(pAd);
557 #ifdef DOT11_N_SUPPORT
558 pAd
->CommonCfg
.DesiredHtPhy
.MpduDensity
= (UCHAR
)pAd
->CommonCfg
.BACapability
.field
.MpduDensity
;
559 pAd
->CommonCfg
.DesiredHtPhy
.AmsduEnable
= (USHORT
)pAd
->CommonCfg
.BACapability
.field
.AmsduEnable
;
560 pAd
->CommonCfg
.DesiredHtPhy
.AmsduSize
= (USHORT
)pAd
->CommonCfg
.BACapability
.field
.AmsduSize
;
561 pAd
->CommonCfg
.DesiredHtPhy
.MimoPs
= (USHORT
)pAd
->CommonCfg
.BACapability
.field
.MMPSmode
;
563 pAd
->CommonCfg
.HtCapability
.HtCapInfo
.MimoPs
= (USHORT
)pAd
->CommonCfg
.BACapability
.field
.MMPSmode
;
564 pAd
->CommonCfg
.HtCapability
.HtCapInfo
.AMsduSize
= (USHORT
)pAd
->CommonCfg
.BACapability
.field
.AmsduSize
;
565 pAd
->CommonCfg
.HtCapability
.HtCapParm
.MpduDensity
= (UCHAR
)pAd
->CommonCfg
.BACapability
.field
.MpduDensity
;
566 #endif // DOT11_N_SUPPORT //
568 // after reading Registry, we now know if in AP mode or STA mode
570 // Load 8051 firmware; crash when FW image not existent
571 // Status = NICLoadFirmware(pAd);
572 // if (Status != NDIS_STATUS_SUCCESS)
575 printk("2. Phy Mode = %d\n", pAd
->CommonCfg
.PhyMode
);
577 // We should read EEPROM for all cases. rt2860b
578 NICReadEEPROMParameters(pAd
, mac
);
579 #ifdef CONFIG_STA_SUPPORT
580 #endif // CONFIG_STA_SUPPORT //
582 printk("3. Phy Mode = %d\n", pAd
->CommonCfg
.PhyMode
);
584 NICInitAsicFromEEPROM(pAd
); //rt2860b
586 // Set PHY to appropriate mode
587 TmpPhy
= pAd
->CommonCfg
.PhyMode
;
588 pAd
->CommonCfg
.PhyMode
= 0xff;
589 RTMPSetPhyMode(pAd
, TmpPhy
);
590 #ifdef DOT11_N_SUPPORT
592 #endif // DOT11_N_SUPPORT //
594 // No valid channels.
595 if (pAd
->ChannelListNum
== 0)
597 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
601 #ifdef DOT11_N_SUPPORT
602 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd
->CommonCfg
.HtCapability
.MCSSet
[0],
603 pAd
->CommonCfg
.HtCapability
.MCSSet
[1], pAd
->CommonCfg
.HtCapability
.MCSSet
[2],
604 pAd
->CommonCfg
.HtCapability
.MCSSet
[3], pAd
->CommonCfg
.HtCapability
.MCSSet
[4]);
605 #endif // DOT11_N_SUPPORT //
608 //Init RT30xx RFRegisters after read RFIC type from EEPROM
609 NICInitRT30xxRFRegisters(pAd
);
613 // Patch cardbus controller if EEPROM said so.
614 if (pAd
->bTest1
== FALSE
)
615 RTMPPatchCardBus(pAd
);
619 // APInitialize(pAd);
622 VR_IKANOS_FP_Init(pAd
->ApCfg
.BssidNum
, pAd
->PermanentAddress
);
623 #endif // IKANOS_VX_1X0 //
626 // Initialize RF register to default value
628 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.Channel
, FALSE
);
629 AsicLockChannel(pAd
, pAd
->CommonCfg
.Channel
);
631 // 8051 firmware require the signal during booting time.
632 AsicSendCommandToMcu(pAd
, 0x72, 0xFF, 0x00, 0x00);
634 if (pAd
&& (Status
!= NDIS_STATUS_SUCCESS
))
637 // Undo everything if it failed
639 if (RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_INTERRUPT_IN_USE
))
641 // NdisMDeregisterInterrupt(&pAd->Interrupt);
642 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_INTERRUPT_IN_USE
);
644 // RTMPFreeAdapter(pAd); // we will free it in disconnect()
648 // Microsoft HCT require driver send a disconnect event after driver initialization.
649 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_MEDIA_STATE_CONNECTED
);
650 // pAd->IndicateMediaState = NdisMediaStateDisconnected;
651 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_MEDIA_STATE_CHANGE
);
653 DBGPRINT(RT_DEBUG_TRACE
, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
657 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_RESET_IN_PROGRESS
);
658 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_REMOVE_IN_PROGRESS
);
661 // Support multiple BulkIn IRP,
662 // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
664 for(index
=0; index
<pAd
->CommonCfg
.NumOfBulkInIRP
; index
++)
666 RTUSBBulkReceive(pAd
);
667 DBGPRINT(RT_DEBUG_TRACE
, ("RTUSBBulkReceive!\n" ));
673 DBGPRINT_S(Status
, ("<==== RTMPInitialize, Status=%x\n", Status
));
682 RTMPFreeTxRxRingMemory(pAd
);
683 // RTMPFreeAdapter(pAd);
686 #ifdef DOT11_N_SUPPORT
687 os_free_mem(pAd
, pAd
->mpdu_blk_pool
.mem
); // free BA pool
688 #endif // DOT11_N_SUPPORT //
689 RT28XX_IRQ_RELEASE(net_dev
);
691 // shall not set priv to NULL here because the priv didn't been free yet.
695 #endif // INF_AMAZON_SE //
696 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME
);
698 } /* End of rt28xx_init */
702 ========================================================================
707 *net_dev the raxx interface pointer
714 ========================================================================
716 int rt28xx_open(IN PNET_DEV dev
)
718 struct net_device
* net_dev
= (struct net_device
*)dev
;
719 PRTMP_ADAPTER pAd
= (PRTMP_ADAPTER
)net_dev
->priv
;
724 // Sanity check for pAd
727 /* if 1st open fail, pAd will be free;
728 So the net_dev->priv will be NULL in 2rd open */
732 #ifdef CONFIG_APSTA_MIXED_SUPPORT
733 if (pAd
->OpMode
== OPMODE_AP
)
737 else if (pAd
->OpMode
== OPMODE_STA
)
742 #if WIRELESS_EXT >= 12
743 if (net_dev
->priv_flags
== INT_MAIN
)
745 if (pAd
->OpMode
== OPMODE_AP
)
746 net_dev
->wireless_handlers
= (struct iw_handler_def
*) &rt28xx_ap_iw_handler_def
;
747 else if (pAd
->OpMode
== OPMODE_STA
)
748 net_dev
->wireless_handlers
= (struct iw_handler_def
*) &rt28xx_iw_handler_def
;
750 #endif // WIRELESS_EXT >= 12 //
751 #endif // CONFIG_APSTA_MIXED_SUPPORT //
753 #ifdef CONFIG_STA_SUPPORT
754 #endif // CONFIG_STA_SUPPORT //
757 pObj
= (POS_COOKIE
)pAd
->OS_Cookie
;
759 // reset Adapter flags
760 RTMP_CLEAR_FLAGS(pAd
);
762 // Request interrupt service routine for PCI device
763 // register the interrupt routine with the os
764 RT28XX_IRQ_REQUEST(net_dev
);
767 // Init BssTab & ChannelInfo tabbles for auto channel select.
771 if (rt28xx_init(net_dev
) == FALSE
)
774 #ifdef CONFIG_STA_SUPPORT
775 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
777 NdisZeroMemory(pAd
->StaCfg
.dev_name
, 16);
778 NdisMoveMemory(pAd
->StaCfg
.dev_name
, net_dev
->name
, strlen(net_dev
->name
));
780 #endif // CONFIG_STA_SUPPORT //
782 // Set up the Mac address
783 NdisMoveMemory(net_dev
->dev_addr
, (void *) pAd
->CurrentAddress
, 6);
785 // Init IRQ parameters
786 RT28XX_IRQ_INIT(pAd
);
788 // Various AP function init
790 #ifdef CONFIG_STA_SUPPORT
791 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
793 #ifdef WPA_SUPPLICANT_SUPPORT
794 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
796 union iwreq_data wrqu
;
797 // send wireless event to wpa_supplicant for infroming interface down.
798 memset(&wrqu
, 0, sizeof(wrqu
));
799 wrqu
.data
.flags
= RT_INTERFACE_UP
;
800 wireless_send_event(pAd
->net_dev
, IWEVCUSTOM
, &wrqu
, NULL
);
802 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
803 #endif // WPA_SUPPLICANT_SUPPORT //
806 #endif // CONFIG_STA_SUPPORT //
809 RT28XX_IRQ_ENABLE(pAd
);
813 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_START_UP
);
817 RTMP_IO_READ32(pAd
, 0x1300, ®
); // clear garbage interrupts
818 printk("0x1300 = %08x\n", reg
);
826 // RTMP_IO_READ32(pAd, XIFS_TIME_CFG, ®);
829 // reg = (reg & 0xffff0000) | tmp;
830 // RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
837 * show the size of main table in Adapter structure
840 * Total -- 385K !!!!! (5/26/2006)
842 printk("sizeof(pAd->MacTab) = %ld\n", sizeof(pAd
->MacTab
));
843 printk("sizeof(pAd->AccessControlList) = %ld\n", sizeof(pAd
->AccessControlList
));
844 printk("sizeof(pAd->ApCfg) = %ld\n", sizeof(pAd
->ApCfg
));
845 printk("sizeof(pAd->BATable) = %ld\n", sizeof(pAd
->BATable
));
849 #ifdef CONFIG_STA_SUPPORT
850 #endif // CONFIG_STA_SUPPORT //
856 } /* End of rt28xx_open */
859 /* Must not be called for mdev and apdev */
860 static NDIS_STATUS
rt_ieee80211_if_setup(struct net_device
*dev
, PRTMP_ADAPTER pAd
)
864 CHAR slot_name
[IFNAMSIZ
];
865 struct net_device
*device
;
869 dev
->hard_start_xmit
= rt28xx_send_packets
;
872 dev
->hard_start_xmit
= IKANOS_DataFramesTx
;
873 #endif // IKANOS_VX_1X0 //
875 // dev->set_multicast_list = ieee80211_set_multicast_list;
876 // dev->change_mtu = ieee80211_change_mtu;
877 #ifdef CONFIG_STA_SUPPORT
878 #if WIRELESS_EXT >= 12
879 if (pAd
->OpMode
== OPMODE_STA
)
881 dev
->wireless_handlers
= &rt28xx_iw_handler_def
;
883 #endif //WIRELESS_EXT >= 12
884 #endif // CONFIG_STA_SUPPORT //
886 #ifdef CONFIG_APSTA_MIXED_SUPPORT
887 #if WIRELESS_EXT >= 12
888 if (pAd
->OpMode
== OPMODE_AP
)
890 dev
->wireless_handlers
= &rt28xx_ap_iw_handler_def
;
892 #endif //WIRELESS_EXT >= 12
893 #endif // CONFIG_APSTA_MIXED_SUPPORT //
895 #if WIRELESS_EXT < 21
896 dev
->get_wireless_stats
= rt28xx_get_wireless_stats
;
898 dev
->get_stats
= RT28xx_get_ether_stats
;
899 dev
->open
= MainVirtualIF_open
; //rt28xx_open;
900 dev
->stop
= MainVirtualIF_close
; //rt28xx_close;
901 // dev->uninit = ieee80211_if_reinit;
902 // dev->destructor = ieee80211_if_free;
903 dev
->priv_flags
= INT_MAIN
;
904 dev
->do_ioctl
= rt28xx_ioctl
;
905 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
906 dev
->validate_addr
= NULL
;
908 // find available device name
909 for (i
= 0; i
< 8; i
++)
911 #ifdef MULTIPLE_CARD_SUPPORT
912 if (pAd
->MC_RowID
>= 0)
913 sprintf(slot_name
, "ra%02d_%d", pAd
->MC_RowID
, i
);
915 #endif // MULTIPLE_CARD_SUPPORT //
916 sprintf(slot_name
, "ra%d", i
);
918 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
919 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
920 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
921 device
= dev_get_by_name(dev_net(dev
), slot_name
);
923 device
= dev_get_by_name(dev
->nd_net
, slot_name
);
926 device
= dev_get_by_name(slot_name
);
928 if (device
!= NULL
) dev_put(device
);
930 for (device
= dev_base
; device
!= NULL
; device
= device
->next
)
932 if (strncmp(device
->name
, slot_name
, 4) == 0)
942 DBGPRINT(RT_DEBUG_ERROR
, ("No available slot name\n"));
943 Status
= NDIS_STATUS_FAILURE
;
947 #ifdef MULTIPLE_CARD_SUPPORT
948 if (pAd
->MC_RowID
>= 0)
949 sprintf(dev
->name
, "ra%02d_%d", pAd
->MC_RowID
, i
);
951 #endif // MULTIPLE_CARD_SUPPORT //
952 sprintf(dev
->name
, "ra%d", i
);
953 Status
= NDIS_STATUS_SUCCESS
;
961 #ifdef MULTIPLE_CARD_SUPPORT
963 ========================================================================
965 Get card profile path.
971 TRUE - Find a card profile
972 FALSE - use default profile
975 ========================================================================
977 extern INT
RTMPGetKeyParameter(
983 BOOLEAN
RTMP_CardInfoRead(
984 IN PRTMP_ADAPTER pAd
)
986 #define MC_SELECT_CARDID 0 /* use CARD ID (0 ~ 31) to identify different cards */
987 #define MC_SELECT_MAC 1 /* use CARD MAC to identify different cards */
988 #define MC_SELECT_CARDTYPE 2 /* use CARD type (abgn or bgn) to identify different cards */
990 #define LETTER_CASE_TRANSLATE(txt_p, card_id) \
991 { UINT32 _len; char _char; \
992 for(_len=0; _len<strlen(card_id); _len++) { \
993 _char = *(txt_p + _len); \
994 if (('A' <= _char) && (_char <= 'Z')) \
995 *(txt_p+_len) = 'a'+(_char-'A'); \
999 INT retval
, orgfsuid
, orgfsgid
;
1001 CHAR
*buffer
, *tmpbuf
, card_id_buf
[30], RFIC_word
[30];
1002 BOOLEAN flg_match_ok
= FALSE
;
1003 INT32 card_select_method
;
1004 INT32 card_free_id
, card_nouse_id
, card_same_mac_id
, card_match_id
;
1005 EEPROM_ANTENNA_STRUC antenna
;
1006 USHORT addr01
, addr23
, addr45
;
1008 UINT32 data
, card_index
;
1013 buffer
= kmalloc(MAX_INI_BUFFER_SIZE
, MEM_ALLOC_FLAG
);
1017 tmpbuf
= kmalloc(MAX_PARAM_BUFFER_SIZE
, MEM_ALLOC_FLAG
);
1021 return NDIS_STATUS_FAILURE
;
1024 orgfsuid
= current
->fsuid
;
1025 orgfsgid
= current
->fsgid
;
1026 current
->fsuid
= current
->fsgid
= 0;
1031 RTMP_IO_READ32(pAd
, E2PROM_CSR
, &data
);
1033 if ((data
& 0x30) == 0)
1034 pAd
->EEPROMAddressNum
= 6; // 93C46
1035 else if ((data
& 0x30) == 0x10)
1036 pAd
->EEPROMAddressNum
= 8; // 93C66
1038 pAd
->EEPROMAddressNum
= 8; // 93C86
1040 //antenna.word = RTMP_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET);
1041 RT28xx_EEPROM_READ16(pAd
, EEPROM_NIC1_OFFSET
, antenna
.word
);
1043 if ((antenna
.field
.RfIcType
== RFIC_2850
) ||
1044 (antenna
.field
.RfIcType
== RFIC_2750
))
1047 strcpy(RFIC_word
, "abgn");
1052 strcpy(RFIC_word
, "bgn");
1056 //addr01 = RTMP_EEPROM_READ16(pAd, 0x04);
1057 //addr23 = RTMP_EEPROM_READ16(pAd, 0x06);
1058 //addr45 = RTMP_EEPROM_READ16(pAd, 0x08);
1059 RT28xx_EEPROM_READ16(pAd
, 0x04, addr01
);
1060 RT28xx_EEPROM_READ16(pAd
, 0x06, addr23
);
1061 RT28xx_EEPROM_READ16(pAd
, 0x08, addr45
);
1063 mac
[0] = (UCHAR
)(addr01
& 0xff);
1064 mac
[1] = (UCHAR
)(addr01
>> 8);
1065 mac
[2] = (UCHAR
)(addr23
& 0xff);
1066 mac
[3] = (UCHAR
)(addr23
>> 8);
1067 mac
[4] = (UCHAR
)(addr45
& 0xff);
1068 mac
[5] = (UCHAR
)(addr45
>> 8);
1070 // open card information file
1071 srcf
= filp_open(CARD_INFO_PATH
, O_RDONLY
, 0);
1074 /* card information file does not exist */
1075 DBGPRINT(RT_DEBUG_TRACE
,
1076 ("--> Error %ld opening %s\n", -PTR_ERR(srcf
), CARD_INFO_PATH
));
1080 if (srcf
->f_op
&& srcf
->f_op
->read
)
1082 /* card information file exists so reading the card information */
1083 memset(buffer
, 0x00, MAX_INI_BUFFER_SIZE
);
1084 retval
= srcf
->f_op
->read(srcf
, buffer
, MAX_INI_BUFFER_SIZE
, &srcf
->f_pos
);
1088 DBGPRINT(RT_DEBUG_TRACE
,
1089 ("--> Read %s error %d\n", CARD_INFO_PATH
, -retval
));
1093 /* get card selection method */
1094 memset(tmpbuf
, 0x00, MAX_PARAM_BUFFER_SIZE
);
1095 card_select_method
= MC_SELECT_CARDTYPE
; // default
1097 if (RTMPGetKeyParameter("SELECT", tmpbuf
, 256, buffer
))
1099 if (strcmp(tmpbuf
, "CARDID") == 0)
1100 card_select_method
= MC_SELECT_CARDID
;
1101 else if (strcmp(tmpbuf
, "MAC") == 0)
1102 card_select_method
= MC_SELECT_MAC
;
1103 else if (strcmp(tmpbuf
, "CARDTYPE") == 0)
1104 card_select_method
= MC_SELECT_CARDTYPE
;
1107 DBGPRINT(RT_DEBUG_TRACE
,
1108 ("MC> Card Selection = %d\n", card_select_method
));
1113 card_same_mac_id
= -1;
1116 // search current card information records
1118 card_index
<MAX_NUM_OF_MULTIPLE_CARD
;
1121 if ((*(UINT32
*)&MC_CardMac
[card_index
][0] == 0) &&
1122 (*(UINT16
*)&MC_CardMac
[card_index
][4] == 0))
1124 // MAC is all-0 so the entry is available
1125 MC_CardUsed
[card_index
] = 0;
1127 if (card_free_id
< 0)
1128 card_free_id
= card_index
; // 1st free entry
1132 if (memcmp(MC_CardMac
[card_index
], mac
, 6) == 0)
1134 // we find the entry with same MAC
1135 if (card_same_mac_id
< 0)
1136 card_same_mac_id
= card_index
; // 1st same entry
1140 // MAC is not all-0 but used flag == 0
1141 if ((MC_CardUsed
[card_index
] == 0) &&
1142 (card_nouse_id
< 0))
1144 card_nouse_id
= card_index
; // 1st available entry
1150 DBGPRINT(RT_DEBUG_TRACE
,
1151 ("MC> Free = %d, Same = %d, NOUSE = %d\n",
1152 card_free_id
, card_same_mac_id
, card_nouse_id
));
1154 if ((card_same_mac_id
>= 0) &&
1155 ((card_select_method
== MC_SELECT_CARDID
) ||
1156 (card_select_method
== MC_SELECT_CARDTYPE
)))
1158 // same MAC entry is found
1159 card_match_id
= card_same_mac_id
;
1161 if (card_select_method
== MC_SELECT_CARDTYPE
)
1164 sprintf(card_id_buf
, "%02dCARDTYPE%s",
1165 card_match_id
, RFIC_word
);
1167 if ((start_ptr
=rtstrstruncasecmp(buffer
, card_id_buf
)) != NULL
)
1169 // we found the card ID
1170 LETTER_CASE_TRANSLATE(start_ptr
, card_id_buf
);
1176 // the card is 1st plug-in, try to find the match card profile
1177 switch(card_select_method
)
1179 case MC_SELECT_CARDID
: // CARDID
1181 if (card_free_id
>= 0)
1182 card_match_id
= card_free_id
;
1184 card_match_id
= card_nouse_id
;
1187 case MC_SELECT_MAC
: // MAC
1188 sprintf(card_id_buf
, "MAC%02x:%02x:%02x:%02x:%02x:%02x",
1189 mac
[0], mac
[1], mac
[2],
1190 mac
[3], mac
[4], mac
[5]);
1192 /* try to find the key word in the card file */
1193 if ((start_ptr
=rtstrstruncasecmp(buffer
, card_id_buf
)) != NULL
)
1195 LETTER_CASE_TRANSLATE(start_ptr
, card_id_buf
);
1197 /* get the row ID (2 ASCII characters) */
1199 card_id_buf
[0] = *(start_ptr
);
1200 card_id_buf
[1] = *(start_ptr
+1);
1201 card_id_buf
[2] = 0x00;
1203 card_match_id
= simple_strtol(card_id_buf
, 0, 10);
1207 case MC_SELECT_CARDTYPE
: // CARDTYPE
1211 card_index
<MAX_NUM_OF_MULTIPLE_CARD
;
1214 sprintf(card_id_buf
, "%02dCARDTYPE%s",
1215 card_index
, RFIC_word
);
1217 if ((start_ptr
=rtstrstruncasecmp(buffer
,
1218 card_id_buf
)) != NULL
)
1220 LETTER_CASE_TRANSLATE(start_ptr
, card_id_buf
);
1222 if (MC_CardUsed
[card_index
] == 0)
1224 /* current the card profile is not used */
1225 if ((*(UINT32
*)&MC_CardMac
[card_index
][0] == 0) &&
1226 (*(UINT16
*)&MC_CardMac
[card_index
][4] == 0))
1228 // find it and no previous card use it
1229 card_match_id
= card_index
;
1234 // ever a card use it
1235 if (card_nouse_id
< 0)
1236 card_nouse_id
= card_index
;
1242 // if not find a free one, use the available one
1243 if (card_match_id
< 0)
1244 card_match_id
= card_nouse_id
;
1249 if (card_match_id
>= 0)
1251 // make up search keyword
1252 switch(card_select_method
)
1254 case MC_SELECT_CARDID
: // CARDID
1255 sprintf(card_id_buf
, "%02dCARDID", card_match_id
);
1258 case MC_SELECT_MAC
: // MAC
1259 sprintf(card_id_buf
,
1260 "%02dmac%02x:%02x:%02x:%02x:%02x:%02x",
1262 mac
[0], mac
[1], mac
[2],
1263 mac
[3], mac
[4], mac
[5]);
1266 case MC_SELECT_CARDTYPE
: // CARDTYPE
1268 sprintf(card_id_buf
, "%02dcardtype%s",
1269 card_match_id
, RFIC_word
);
1273 DBGPRINT(RT_DEBUG_TRACE
, ("Search Keyword = %s\n", card_id_buf
));
1275 // read card file path
1276 if (RTMPGetKeyParameter(card_id_buf
, tmpbuf
, 256, buffer
))
1278 if (strlen(tmpbuf
) < sizeof(pAd
->MC_FileName
))
1280 // backup card information
1281 pAd
->MC_RowID
= card_match_id
; /* base 0 */
1282 MC_CardUsed
[card_match_id
] = 1;
1283 memcpy(MC_CardMac
[card_match_id
], mac
, sizeof(mac
));
1285 // backup card file path
1286 NdisMoveMemory(pAd
->MC_FileName
, tmpbuf
, strlen(tmpbuf
));
1287 pAd
->MC_FileName
[strlen(tmpbuf
)] = '\0';
1288 flg_match_ok
= TRUE
;
1290 DBGPRINT(RT_DEBUG_TRACE
,
1291 ("Card Profile Name = %s\n", pAd
->MC_FileName
));
1295 DBGPRINT(RT_DEBUG_ERROR
,
1296 ("Card Profile Name length too large!\n"));
1301 DBGPRINT(RT_DEBUG_ERROR
,
1302 ("Can not find search key word in card.dat!\n"));
1305 if ((flg_match_ok
!= TRUE
) &&
1306 (card_match_id
< MAX_NUM_OF_MULTIPLE_CARD
))
1308 MC_CardUsed
[card_match_id
] = 0;
1309 memset(MC_CardMac
[card_match_id
], 0, sizeof(mac
));
1311 } // if (card_match_id >= 0)
1316 retval
= filp_close(srcf
, NULL
);
1318 current
->fsuid
= orgfsuid
;
1319 current
->fsgid
= orgfsgid
;
1322 return flg_match_ok
;
1324 #endif // MULTIPLE_CARD_SUPPORT //
1328 ========================================================================
1329 Routine Description:
1330 Probe RT28XX chipset.
1333 _dev_p Point to the PCI or USB device
1334 _dev_id_p Point to the PCI or USB device ID
1341 ========================================================================
1343 INT __devinit
rt28xx_probe(
1347 OUT PRTMP_ADAPTER
*ppAd
)
1349 struct net_device
*net_dev
;
1350 PRTMP_ADAPTER pAd
= (PRTMP_ADAPTER
) NULL
;
1354 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1355 struct usb_device
*dev_p
= (struct usb_device
*)_dev_p
;
1357 struct usb_interface
*intf
= (struct usb_interface
*)_dev_p
;
1358 struct usb_device
*dev_p
= interface_to_usbdev(intf
);
1360 dev_p
= usb_get_dev(dev_p
);
1361 #endif // LINUX_VERSION_CODE //
1365 #ifdef CONFIG_STA_SUPPORT
1366 DBGPRINT(RT_DEBUG_TRACE
, ("STA Driver version-%s\n", STA_DRIVER_VERSION
));
1367 #endif // CONFIG_STA_SUPPORT //
1369 // Check chipset vendor/product ID
1370 // if (RT28XXChipsetCheck(_dev_p) == FALSE)
1373 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
1374 net_dev
= alloc_netdev(sizeof(PRTMP_ADAPTER
), "eth%d", ether_setup
);
1376 net_dev
= alloc_etherdev(sizeof(PRTMP_ADAPTER
));
1378 if (net_dev
== NULL
)
1380 printk("alloc_netdev failed\n");
1382 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1383 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1384 module_put(THIS_MODULE
);
1385 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1393 // if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
1396 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1397 SET_MODULE_OWNER(net_dev
);
1400 netif_stop_queue(net_dev
);
1401 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
1402 /* for supporting Network Manager */
1403 /* Set the sysfs physical device reference for the network logical device
1404 * if set prior to registration will cause a symlink during initialization.
1406 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
1407 SET_NETDEV_DEV(net_dev
, &(dev_p
->dev
));
1409 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
1411 // Allocate RTMP_ADAPTER miniport adapter structure
1412 handle
= kmalloc(sizeof(struct os_cookie
), GFP_KERNEL
);
1413 RT28XX_HANDLE_DEV_ASSIGN(handle
, dev_p
);
1415 status
= RTMPAllocAdapterBlock(handle
, &pAd
);
1416 if (status
!= NDIS_STATUS_SUCCESS
)
1417 goto err_out_free_netdev
;
1419 net_dev
->priv
= (PVOID
)pAd
;
1420 pAd
->net_dev
= net_dev
; // must be before RT28XXNetDevInit()
1422 RT28XXNetDevInit(_dev_p
, net_dev
, pAd
);
1424 #ifdef CONFIG_STA_SUPPORT
1425 pAd
->StaCfg
.OriDevType
= net_dev
->type
;
1426 #endif // CONFIG_STA_SUPPORT //
1428 // Find and assign a free interface name, raxx
1429 // RT28XXAvailRANameAssign(net_dev->name);
1432 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1433 if (RT28XXProbePostConfig(_dev_p
, pAd
, argc
) == FALSE
)
1436 if (RT28XXProbePostConfig(_dev_p
, pAd
, 0) == FALSE
)
1438 #endif // LINUX_VERSION_CODE //
1440 #ifdef CONFIG_STA_SUPPORT
1441 pAd
->OpMode
= OPMODE_STA
;
1442 #endif // CONFIG_STA_SUPPORT //
1445 #ifdef MULTIPLE_CARD_SUPPORT
1446 // find its profile path
1447 pAd
->MC_RowID
= -1; // use default profile path
1448 RTMP_CardInfoRead(pAd
);
1450 if (pAd
->MC_RowID
== -1)
1451 #ifdef CONFIG_STA_SUPPORT
1452 strcpy(pAd
->MC_FileName
, STA_PROFILE_PATH
);
1453 #endif // CONFIG_STA_SUPPORT //
1455 DBGPRINT(RT_DEBUG_TRACE
,
1456 ("MC> ROW = %d, PATH = %s\n", pAd
->MC_RowID
, pAd
->MC_FileName
));
1457 #endif // MULTIPLE_CARD_SUPPORT //
1460 if (rt_ieee80211_if_setup(net_dev
, pAd
) != NDIS_STATUS_SUCCESS
)
1463 // Register this device
1464 status
= register_netdev(net_dev
);
1469 RT28XX_DRVDATA_SET(_dev_p
);
1474 return 0; // probe ok
1477 /* --------------------------- ERROR HANDLE --------------------------- */
1479 RTMPFreeAdapter(pAd
);
1482 err_out_free_netdev
:
1483 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1484 free_netdev(net_dev
);
1490 RT28XX_PUT_DEVICE(dev_p
);
1492 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1495 return -ENODEV
; /* probe fail */
1496 #endif // LINUX_VERSION_CODE //
1497 } /* End of rt28xx_probe */
1501 ========================================================================
1502 Routine Description:
1503 The entry point for Linux kernel sent packet to our driver.
1506 sk_buff *skb the pointer refer to a sk_buffer.
1512 This function is the entry point of Tx Path for Os delivery packet to
1513 our driver. You only can put OS-depened & STA/AP common handle procedures
1515 ========================================================================
1517 int rt28xx_packet_xmit(struct sk_buff
*skb
)
1519 struct net_device
*net_dev
= skb
->dev
;
1520 PRTMP_ADAPTER pAd
= (PRTMP_ADAPTER
) net_dev
->priv
;
1522 PNDIS_PACKET pPacket
= (PNDIS_PACKET
) skb
;
1524 /* RT2870STA does this in RTMPSendPackets() */
1528 RELEASE_NDIS_PACKET(pAd
, pPacket
, NDIS_STATUS_RESOURCES
);
1531 #endif // RALINK_ATE //
1533 #ifdef CONFIG_STA_SUPPORT
1534 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1536 // Drop send request since we are in monitor mode
1537 if (MONITOR_ON(pAd
))
1539 RELEASE_NDIS_PACKET(pAd
, pPacket
, NDIS_STATUS_FAILURE
);
1543 #endif // CONFIG_STA_SUPPORT //
1545 // EapolStart size is 18
1548 //printk("bad packet size: %d\n", pkt->len);
1549 hex_dump("bad packet", skb
->data
, skb
->len
);
1550 RELEASE_NDIS_PACKET(pAd
, pPacket
, NDIS_STATUS_FAILURE
);
1555 // if ((pkt->data[0] & 0x1) == 0)
1557 //hex_dump(__FUNCTION__, pkt->data, pkt->len);
1558 printk("pPacket = %x\n", pPacket
);
1562 RTMP_SET_PACKET_5VT(pPacket
, 0);
1563 // MiniportMMRequest(pAd, pkt->data, pkt->len);
1564 #ifdef CONFIG_5VT_ENHANCE
1565 if (*(int*)(skb
->cb
) == BRIDGE_TAG
) {
1566 RTMP_SET_PACKET_5VT(pPacket
, 1);
1572 #ifdef CONFIG_STA_SUPPORT
1573 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1576 STASendPackets((NDIS_HANDLE
)pAd
, (PPNDIS_PACKET
) &pPacket
, 1);
1579 #endif // CONFIG_STA_SUPPORT //
1589 ========================================================================
1590 Routine Description:
1591 Send a packet to WLAN.
1594 skb_p points to our adapter
1595 dev_p which WLAN network interface
1598 0: transmit successfully
1599 otherwise: transmit fail
1602 ========================================================================
1604 INT
rt28xx_send_packets(
1605 IN
struct sk_buff
*skb_p
,
1606 IN
struct net_device
*net_dev
)
1608 RTMP_ADAPTER
*pAd
= net_dev
->priv
;
1610 if (!(net_dev
->flags
& IFF_UP
))
1612 RELEASE_NDIS_PACKET(pAd
, (PNDIS_PACKET
)skb_p
, NDIS_STATUS_FAILURE
);
1616 NdisZeroMemory((PUCHAR
)&skb_p
->cb
[CB_OFF
], 15);
1617 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p
, MAIN_MBSSID
);
1619 return rt28xx_packet_xmit(skb_p
);
1620 } /* End of MBSS_VirtualIF_PacketSend */
1625 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
1626 //static struct net_device *alloc_netdev(int sizeof_priv, const char *mask, void (*setup)(struct net_device *)) //sample
1627 struct net_device
*alloc_netdev(
1630 void (*setup
)(struct net_device
*))
1632 struct net_device
*dev
;
1636 /* ensure 32-byte alignment of the private area */
1637 alloc_size
= sizeof (*dev
) + sizeof_priv
+ 31;
1639 dev
= (struct net_device
*) kmalloc(alloc_size
, GFP_KERNEL
);
1642 DBGPRINT(RT_DEBUG_ERROR
,
1643 ("alloc_netdev: Unable to allocate device memory.\n"));
1647 memset(dev
, 0, alloc_size
);
1650 dev
->priv
= (void *) (((long)(dev
+ 1) + 31) & ~31);
1653 strcpy(dev
->name
, mask
);
1657 #endif // LINUX_VERSION_CODE //
1660 void CfgInitHook(PRTMP_ADAPTER pAd
)
1662 pAd
->bBroadComHT
= TRUE
;
1663 } /* End of CfgInitHook */
1666 #if 0 // Not used now, should keep it in our source tree??
1668 ========================================================================
1669 Routine Description:
1670 Find and assign a free interface name (raxx).
1673 *name_p the interface name pointer
1680 ========================================================================
1682 static BOOLEAN
RT28XXAvailRANameAssign(
1685 CHAR slot_name
[IFNAMSIZ
];
1686 struct net_device
*device
;
1690 for(if_id
=0; if_id
<8; if_id
++)
1692 sprintf(slot_name
, "ra%d", if_id
);
1694 for(device
=dev_base
; device
!=NULL
; device
=device
->next
)
1696 if (strncmp(device
->name
, slot_name
, 4) == 0)
1706 DBGPRINT(RT_DEBUG_ERROR
, ("No available slot name\n"));
1710 sprintf(name_p
, "ra%d", if_id
);
1712 } /* End of RT28XXAvailRANameAssign */
1715 #if WIRELESS_EXT >= 12
1716 // This function will be called when query /proc
1717 struct iw_statistics
*rt28xx_get_wireless_stats(
1718 IN
struct net_device
*net_dev
)
1720 PRTMP_ADAPTER pAd
= (PRTMP_ADAPTER
) net_dev
->priv
;
1723 DBGPRINT(RT_DEBUG_TRACE
, ("rt28xx_get_wireless_stats --->\n"));
1725 pAd
->iw_stats
.status
= 0; // Status - device dependent for now
1728 pAd
->iw_stats
.qual
.qual
= ((pAd
->Mlme
.ChannelQuality
* 12)/10 + 10);
1729 if(pAd
->iw_stats
.qual
.qual
> 100)
1730 pAd
->iw_stats
.qual
.qual
= 100;
1732 #ifdef CONFIG_STA_SUPPORT
1733 if (pAd
->OpMode
== OPMODE_STA
)
1734 pAd
->iw_stats
.qual
.level
= RTMPMaxRssi(pAd
, pAd
->StaCfg
.RssiSample
.LastRssi0
, pAd
->StaCfg
.RssiSample
.LastRssi1
, pAd
->StaCfg
.RssiSample
.LastRssi2
);
1735 #endif // CONFIG_STA_SUPPORT //
1737 pAd
->iw_stats
.qual
.noise
= pAd
->BbpWriteLatch
[66]; // noise level (dBm)
1739 pAd
->iw_stats
.qual
.noise
+= 256 - 143;
1740 pAd
->iw_stats
.qual
.updated
= 1; // Flags to know if updated
1742 pAd
->iw_stats
.qual
.updated
|= IW_QUAL_DBM
; // Level + Noise are dBm
1743 #endif // IW_QUAL_DBM //
1745 pAd
->iw_stats
.discard
.nwid
= 0; // Rx : Wrong nwid/essid
1746 pAd
->iw_stats
.miss
.beacon
= 0; // Missed beacons/superframe
1748 DBGPRINT(RT_DEBUG_TRACE
, ("<--- rt28xx_get_wireless_stats\n"));
1749 return &pAd
->iw_stats
;
1750 } /* End of rt28xx_get_wireless_stats */
1751 #endif // WIRELESS_EXT //
1755 void tbtt_tasklet(unsigned long data
)
1757 #define MAX_TX_IN_TBTT (16)
1762 IN
struct net_device
*net_dev
,
1763 IN OUT
struct ifreq
*rq
,
1766 VIRTUAL_ADAPTER
*pVirtualAd
= NULL
;
1767 RTMP_ADAPTER
*pAd
= NULL
;
1770 if (net_dev
->priv_flags
== INT_MAIN
)
1772 pAd
= net_dev
->priv
;
1776 pVirtualAd
= net_dev
->priv
;
1777 pAd
= pVirtualAd
->RtmpDev
->priv
;
1782 /* if 1st open fail, pAd will be free;
1783 So the net_dev->priv will be NULL in 2rd open */
1788 #ifdef CONFIG_STA_SUPPORT
1789 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1791 ret
= rt28xx_sta_ioctl(net_dev
, rq
, cmd
);
1793 #endif // CONFIG_STA_SUPPORT //
1799 ========================================================================
1801 Routine Description:
1802 return ethernet statistics counter
1805 net_dev Pointer to net_device
1812 ========================================================================
1814 struct net_device_stats
*RT28xx_get_ether_stats(
1815 IN
struct net_device
*net_dev
)
1817 RTMP_ADAPTER
*pAd
= NULL
;
1820 pAd
= net_dev
->priv
;
1825 pAd
->stats
.rx_packets
= pAd
->WlanCounters
.ReceivedFragmentCount
.QuadPart
;
1826 pAd
->stats
.tx_packets
= pAd
->WlanCounters
.TransmittedFragmentCount
.QuadPart
;
1828 pAd
->stats
.rx_bytes
= pAd
->RalinkCounters
.ReceivedByteCount
;
1829 pAd
->stats
.tx_bytes
= pAd
->RalinkCounters
.TransmittedByteCount
;
1831 pAd
->stats
.rx_errors
= pAd
->Counters8023
.RxErrors
;
1832 pAd
->stats
.tx_errors
= pAd
->Counters8023
.TxErrors
;
1834 pAd
->stats
.rx_dropped
= 0;
1835 pAd
->stats
.tx_dropped
= 0;
1837 pAd
->stats
.multicast
= pAd
->WlanCounters
.MulticastReceivedFrameCount
.QuadPart
; // multicast packets received
1838 pAd
->stats
.collisions
= pAd
->Counters8023
.OneCollision
+ pAd
->Counters8023
.MoreCollisions
; // Collision packets
1840 pAd
->stats
.rx_length_errors
= 0;
1841 pAd
->stats
.rx_over_errors
= pAd
->Counters8023
.RxNoBuffer
; // receiver ring buff overflow
1842 pAd
->stats
.rx_crc_errors
= 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1843 pAd
->stats
.rx_frame_errors
= pAd
->Counters8023
.RcvAlignmentErrors
; // recv'd frame alignment error
1844 pAd
->stats
.rx_fifo_errors
= pAd
->Counters8023
.RxNoBuffer
; // recv'r fifo overrun
1845 pAd
->stats
.rx_missed_errors
= 0; // receiver missed packet
1847 // detailed tx_errors
1848 pAd
->stats
.tx_aborted_errors
= 0;
1849 pAd
->stats
.tx_carrier_errors
= 0;
1850 pAd
->stats
.tx_fifo_errors
= 0;
1851 pAd
->stats
.tx_heartbeat_errors
= 0;
1852 pAd
->stats
.tx_window_errors
= 0;
1855 pAd
->stats
.rx_compressed
= 0;
1856 pAd
->stats
.tx_compressed
= 0;