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
->ml_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
->ml_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
->ml_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
= net_dev
->ml_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 ml_priv to NULL here because the ml_priv didn't been free yet.
692 //net_dev->ml_priv = 0;
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
= net_dev
->ml_priv
;
724 // Sanity check for pAd
727 /* if 1st open fail, pAd will be free;
728 So the net_dev->ml_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 */
858 static const struct net_device_ops rt2870_netdev_ops
= {
859 .ndo_open
= MainVirtualIF_open
,
860 .ndo_stop
= MainVirtualIF_close
,
861 .ndo_do_ioctl
= rt28xx_ioctl
,
862 .ndo_get_stats
= RT28xx_get_ether_stats
,
863 .ndo_validate_addr
= NULL
,
864 .ndo_set_mac_address
= eth_mac_addr
,
865 .ndo_change_mtu
= eth_change_mtu
,
867 .ndo_start_xmit
= IKANOS_DataFramesTx
,
869 .ndo_start_xmit
= rt28xx_send_packets
,
873 /* Must not be called for mdev and apdev */
874 static NDIS_STATUS
rt_ieee80211_if_setup(struct net_device
*dev
, PRTMP_ADAPTER pAd
)
878 CHAR slot_name
[IFNAMSIZ
];
879 struct net_device
*device
;
883 // dev->set_multicast_list = ieee80211_set_multicast_list;
884 // dev->change_mtu = ieee80211_change_mtu;
885 #ifdef CONFIG_STA_SUPPORT
886 #if WIRELESS_EXT >= 12
887 if (pAd
->OpMode
== OPMODE_STA
)
889 dev
->wireless_handlers
= &rt28xx_iw_handler_def
;
891 #endif //WIRELESS_EXT >= 12
892 #endif // CONFIG_STA_SUPPORT //
894 #ifdef CONFIG_APSTA_MIXED_SUPPORT
895 #if WIRELESS_EXT >= 12
896 if (pAd
->OpMode
== OPMODE_AP
)
898 dev
->wireless_handlers
= &rt28xx_ap_iw_handler_def
;
900 #endif //WIRELESS_EXT >= 12
901 #endif // CONFIG_APSTA_MIXED_SUPPORT //
903 #if WIRELESS_EXT < 21
904 dev
->get_wireless_stats
= rt28xx_get_wireless_stats
;
906 // dev->uninit = ieee80211_if_reinit;
907 // dev->destructor = ieee80211_if_free;
908 dev
->priv_flags
= INT_MAIN
;
909 dev
->netdev_ops
= &rt2870_netdev_ops
;
910 // find available device name
911 for (i
= 0; i
< 8; i
++)
913 #ifdef MULTIPLE_CARD_SUPPORT
914 if (pAd
->MC_RowID
>= 0)
915 sprintf(slot_name
, "ra%02d_%d", pAd
->MC_RowID
, i
);
917 #endif // MULTIPLE_CARD_SUPPORT //
918 sprintf(slot_name
, "ra%d", i
);
920 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
921 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
922 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
923 device
= dev_get_by_name(dev_net(dev
), slot_name
);
925 device
= dev_get_by_name(dev
->nd_net
, slot_name
);
928 device
= dev_get_by_name(slot_name
);
930 if (device
!= NULL
) dev_put(device
);
932 for (device
= dev_base
; device
!= NULL
; device
= device
->next
)
934 if (strncmp(device
->name
, slot_name
, 4) == 0)
944 DBGPRINT(RT_DEBUG_ERROR
, ("No available slot name\n"));
945 Status
= NDIS_STATUS_FAILURE
;
949 #ifdef MULTIPLE_CARD_SUPPORT
950 if (pAd
->MC_RowID
>= 0)
951 sprintf(dev
->name
, "ra%02d_%d", pAd
->MC_RowID
, i
);
953 #endif // MULTIPLE_CARD_SUPPORT //
954 sprintf(dev
->name
, "ra%d", i
);
955 Status
= NDIS_STATUS_SUCCESS
;
963 #ifdef MULTIPLE_CARD_SUPPORT
965 ========================================================================
967 Get card profile path.
973 TRUE - Find a card profile
974 FALSE - use default profile
977 ========================================================================
979 extern INT
RTMPGetKeyParameter(
985 BOOLEAN
RTMP_CardInfoRead(
986 IN PRTMP_ADAPTER pAd
)
988 #define MC_SELECT_CARDID 0 /* use CARD ID (0 ~ 31) to identify different cards */
989 #define MC_SELECT_MAC 1 /* use CARD MAC to identify different cards */
990 #define MC_SELECT_CARDTYPE 2 /* use CARD type (abgn or bgn) to identify different cards */
992 #define LETTER_CASE_TRANSLATE(txt_p, card_id) \
993 { UINT32 _len; char _char; \
994 for(_len=0; _len<strlen(card_id); _len++) { \
995 _char = *(txt_p + _len); \
996 if (('A' <= _char) && (_char <= 'Z')) \
997 *(txt_p+_len) = 'a'+(_char-'A'); \
1001 INT retval
, orgfsuid
, orgfsgid
;
1003 CHAR
*buffer
, *tmpbuf
, card_id_buf
[30], RFIC_word
[30];
1004 BOOLEAN flg_match_ok
= FALSE
;
1005 INT32 card_select_method
;
1006 INT32 card_free_id
, card_nouse_id
, card_same_mac_id
, card_match_id
;
1007 EEPROM_ANTENNA_STRUC antenna
;
1008 USHORT addr01
, addr23
, addr45
;
1010 UINT32 data
, card_index
;
1015 buffer
= kmalloc(MAX_INI_BUFFER_SIZE
, MEM_ALLOC_FLAG
);
1019 tmpbuf
= kmalloc(MAX_PARAM_BUFFER_SIZE
, MEM_ALLOC_FLAG
);
1023 return NDIS_STATUS_FAILURE
;
1026 orgfsuid
= current
->fsuid
;
1027 orgfsgid
= current
->fsgid
;
1028 current
->fsuid
= current
->fsgid
= 0;
1033 RTMP_IO_READ32(pAd
, E2PROM_CSR
, &data
);
1035 if ((data
& 0x30) == 0)
1036 pAd
->EEPROMAddressNum
= 6; // 93C46
1037 else if ((data
& 0x30) == 0x10)
1038 pAd
->EEPROMAddressNum
= 8; // 93C66
1040 pAd
->EEPROMAddressNum
= 8; // 93C86
1042 //antenna.word = RTMP_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET);
1043 RT28xx_EEPROM_READ16(pAd
, EEPROM_NIC1_OFFSET
, antenna
.word
);
1045 if ((antenna
.field
.RfIcType
== RFIC_2850
) ||
1046 (antenna
.field
.RfIcType
== RFIC_2750
))
1049 strcpy(RFIC_word
, "abgn");
1054 strcpy(RFIC_word
, "bgn");
1058 //addr01 = RTMP_EEPROM_READ16(pAd, 0x04);
1059 //addr23 = RTMP_EEPROM_READ16(pAd, 0x06);
1060 //addr45 = RTMP_EEPROM_READ16(pAd, 0x08);
1061 RT28xx_EEPROM_READ16(pAd
, 0x04, addr01
);
1062 RT28xx_EEPROM_READ16(pAd
, 0x06, addr23
);
1063 RT28xx_EEPROM_READ16(pAd
, 0x08, addr45
);
1065 mac
[0] = (UCHAR
)(addr01
& 0xff);
1066 mac
[1] = (UCHAR
)(addr01
>> 8);
1067 mac
[2] = (UCHAR
)(addr23
& 0xff);
1068 mac
[3] = (UCHAR
)(addr23
>> 8);
1069 mac
[4] = (UCHAR
)(addr45
& 0xff);
1070 mac
[5] = (UCHAR
)(addr45
>> 8);
1072 // open card information file
1073 srcf
= filp_open(CARD_INFO_PATH
, O_RDONLY
, 0);
1076 /* card information file does not exist */
1077 DBGPRINT(RT_DEBUG_TRACE
,
1078 ("--> Error %ld opening %s\n", -PTR_ERR(srcf
), CARD_INFO_PATH
));
1082 if (srcf
->f_op
&& srcf
->f_op
->read
)
1084 /* card information file exists so reading the card information */
1085 memset(buffer
, 0x00, MAX_INI_BUFFER_SIZE
);
1086 retval
= srcf
->f_op
->read(srcf
, buffer
, MAX_INI_BUFFER_SIZE
, &srcf
->f_pos
);
1090 DBGPRINT(RT_DEBUG_TRACE
,
1091 ("--> Read %s error %d\n", CARD_INFO_PATH
, -retval
));
1095 /* get card selection method */
1096 memset(tmpbuf
, 0x00, MAX_PARAM_BUFFER_SIZE
);
1097 card_select_method
= MC_SELECT_CARDTYPE
; // default
1099 if (RTMPGetKeyParameter("SELECT", tmpbuf
, 256, buffer
))
1101 if (strcmp(tmpbuf
, "CARDID") == 0)
1102 card_select_method
= MC_SELECT_CARDID
;
1103 else if (strcmp(tmpbuf
, "MAC") == 0)
1104 card_select_method
= MC_SELECT_MAC
;
1105 else if (strcmp(tmpbuf
, "CARDTYPE") == 0)
1106 card_select_method
= MC_SELECT_CARDTYPE
;
1109 DBGPRINT(RT_DEBUG_TRACE
,
1110 ("MC> Card Selection = %d\n", card_select_method
));
1115 card_same_mac_id
= -1;
1118 // search current card information records
1120 card_index
<MAX_NUM_OF_MULTIPLE_CARD
;
1123 if ((*(UINT32
*)&MC_CardMac
[card_index
][0] == 0) &&
1124 (*(UINT16
*)&MC_CardMac
[card_index
][4] == 0))
1126 // MAC is all-0 so the entry is available
1127 MC_CardUsed
[card_index
] = 0;
1129 if (card_free_id
< 0)
1130 card_free_id
= card_index
; // 1st free entry
1134 if (memcmp(MC_CardMac
[card_index
], mac
, 6) == 0)
1136 // we find the entry with same MAC
1137 if (card_same_mac_id
< 0)
1138 card_same_mac_id
= card_index
; // 1st same entry
1142 // MAC is not all-0 but used flag == 0
1143 if ((MC_CardUsed
[card_index
] == 0) &&
1144 (card_nouse_id
< 0))
1146 card_nouse_id
= card_index
; // 1st available entry
1152 DBGPRINT(RT_DEBUG_TRACE
,
1153 ("MC> Free = %d, Same = %d, NOUSE = %d\n",
1154 card_free_id
, card_same_mac_id
, card_nouse_id
));
1156 if ((card_same_mac_id
>= 0) &&
1157 ((card_select_method
== MC_SELECT_CARDID
) ||
1158 (card_select_method
== MC_SELECT_CARDTYPE
)))
1160 // same MAC entry is found
1161 card_match_id
= card_same_mac_id
;
1163 if (card_select_method
== MC_SELECT_CARDTYPE
)
1166 sprintf(card_id_buf
, "%02dCARDTYPE%s",
1167 card_match_id
, RFIC_word
);
1169 if ((start_ptr
=rtstrstruncasecmp(buffer
, card_id_buf
)) != NULL
)
1171 // we found the card ID
1172 LETTER_CASE_TRANSLATE(start_ptr
, card_id_buf
);
1178 // the card is 1st plug-in, try to find the match card profile
1179 switch(card_select_method
)
1181 case MC_SELECT_CARDID
: // CARDID
1183 if (card_free_id
>= 0)
1184 card_match_id
= card_free_id
;
1186 card_match_id
= card_nouse_id
;
1189 case MC_SELECT_MAC
: // MAC
1190 sprintf(card_id_buf
, "MAC%02x:%02x:%02x:%02x:%02x:%02x",
1191 mac
[0], mac
[1], mac
[2],
1192 mac
[3], mac
[4], mac
[5]);
1194 /* try to find the key word in the card file */
1195 if ((start_ptr
=rtstrstruncasecmp(buffer
, card_id_buf
)) != NULL
)
1197 LETTER_CASE_TRANSLATE(start_ptr
, card_id_buf
);
1199 /* get the row ID (2 ASCII characters) */
1201 card_id_buf
[0] = *(start_ptr
);
1202 card_id_buf
[1] = *(start_ptr
+1);
1203 card_id_buf
[2] = 0x00;
1205 card_match_id
= simple_strtol(card_id_buf
, 0, 10);
1209 case MC_SELECT_CARDTYPE
: // CARDTYPE
1213 card_index
<MAX_NUM_OF_MULTIPLE_CARD
;
1216 sprintf(card_id_buf
, "%02dCARDTYPE%s",
1217 card_index
, RFIC_word
);
1219 if ((start_ptr
=rtstrstruncasecmp(buffer
,
1220 card_id_buf
)) != NULL
)
1222 LETTER_CASE_TRANSLATE(start_ptr
, card_id_buf
);
1224 if (MC_CardUsed
[card_index
] == 0)
1226 /* current the card profile is not used */
1227 if ((*(UINT32
*)&MC_CardMac
[card_index
][0] == 0) &&
1228 (*(UINT16
*)&MC_CardMac
[card_index
][4] == 0))
1230 // find it and no previous card use it
1231 card_match_id
= card_index
;
1236 // ever a card use it
1237 if (card_nouse_id
< 0)
1238 card_nouse_id
= card_index
;
1244 // if not find a free one, use the available one
1245 if (card_match_id
< 0)
1246 card_match_id
= card_nouse_id
;
1251 if (card_match_id
>= 0)
1253 // make up search keyword
1254 switch(card_select_method
)
1256 case MC_SELECT_CARDID
: // CARDID
1257 sprintf(card_id_buf
, "%02dCARDID", card_match_id
);
1260 case MC_SELECT_MAC
: // MAC
1261 sprintf(card_id_buf
,
1262 "%02dmac%02x:%02x:%02x:%02x:%02x:%02x",
1264 mac
[0], mac
[1], mac
[2],
1265 mac
[3], mac
[4], mac
[5]);
1268 case MC_SELECT_CARDTYPE
: // CARDTYPE
1270 sprintf(card_id_buf
, "%02dcardtype%s",
1271 card_match_id
, RFIC_word
);
1275 DBGPRINT(RT_DEBUG_TRACE
, ("Search Keyword = %s\n", card_id_buf
));
1277 // read card file path
1278 if (RTMPGetKeyParameter(card_id_buf
, tmpbuf
, 256, buffer
))
1280 if (strlen(tmpbuf
) < sizeof(pAd
->MC_FileName
))
1282 // backup card information
1283 pAd
->MC_RowID
= card_match_id
; /* base 0 */
1284 MC_CardUsed
[card_match_id
] = 1;
1285 memcpy(MC_CardMac
[card_match_id
], mac
, sizeof(mac
));
1287 // backup card file path
1288 NdisMoveMemory(pAd
->MC_FileName
, tmpbuf
, strlen(tmpbuf
));
1289 pAd
->MC_FileName
[strlen(tmpbuf
)] = '\0';
1290 flg_match_ok
= TRUE
;
1292 DBGPRINT(RT_DEBUG_TRACE
,
1293 ("Card Profile Name = %s\n", pAd
->MC_FileName
));
1297 DBGPRINT(RT_DEBUG_ERROR
,
1298 ("Card Profile Name length too large!\n"));
1303 DBGPRINT(RT_DEBUG_ERROR
,
1304 ("Can not find search key word in card.dat!\n"));
1307 if ((flg_match_ok
!= TRUE
) &&
1308 (card_match_id
< MAX_NUM_OF_MULTIPLE_CARD
))
1310 MC_CardUsed
[card_match_id
] = 0;
1311 memset(MC_CardMac
[card_match_id
], 0, sizeof(mac
));
1313 } // if (card_match_id >= 0)
1318 retval
= filp_close(srcf
, NULL
);
1320 current
->fsuid
= orgfsuid
;
1321 current
->fsgid
= orgfsgid
;
1324 return flg_match_ok
;
1326 #endif // MULTIPLE_CARD_SUPPORT //
1330 ========================================================================
1331 Routine Description:
1332 Probe RT28XX chipset.
1335 _dev_p Point to the PCI or USB device
1336 _dev_id_p Point to the PCI or USB device ID
1343 ========================================================================
1345 INT __devinit
rt28xx_probe(
1349 OUT PRTMP_ADAPTER
*ppAd
)
1351 struct net_device
*net_dev
;
1352 PRTMP_ADAPTER pAd
= (PRTMP_ADAPTER
) NULL
;
1356 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */
1357 struct usb_device
*dev_p
= (struct usb_device
*)_dev_p
;
1359 struct usb_interface
*intf
= (struct usb_interface
*)_dev_p
;
1360 struct usb_device
*dev_p
= interface_to_usbdev(intf
);
1362 dev_p
= usb_get_dev(dev_p
);
1363 #endif // LINUX_VERSION_CODE //
1367 #ifdef CONFIG_STA_SUPPORT
1368 DBGPRINT(RT_DEBUG_TRACE
, ("STA Driver version-%s\n", STA_DRIVER_VERSION
));
1369 #endif // CONFIG_STA_SUPPORT //
1371 // Check chipset vendor/product ID
1372 // if (RT28XXChipsetCheck(_dev_p) == FALSE)
1375 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
1376 net_dev
= alloc_netdev(sizeof(PRTMP_ADAPTER
), "eth%d", ether_setup
);
1378 net_dev
= alloc_etherdev(sizeof(PRTMP_ADAPTER
));
1380 if (net_dev
== NULL
)
1382 printk("alloc_netdev failed\n");
1384 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1385 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1386 module_put(THIS_MODULE
);
1387 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1395 // if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
1398 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1399 SET_MODULE_OWNER(net_dev
);
1402 netif_stop_queue(net_dev
);
1403 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
1404 /* for supporting Network Manager */
1405 /* Set the sysfs physical device reference for the network logical device
1406 * if set prior to registration will cause a symlink during initialization.
1408 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
1409 SET_NETDEV_DEV(net_dev
, &(dev_p
->dev
));
1411 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
1413 // Allocate RTMP_ADAPTER miniport adapter structure
1414 handle
= kmalloc(sizeof(struct os_cookie
), GFP_KERNEL
);
1415 RT28XX_HANDLE_DEV_ASSIGN(handle
, dev_p
);
1417 status
= RTMPAllocAdapterBlock(handle
, &pAd
);
1418 if (status
!= NDIS_STATUS_SUCCESS
)
1419 goto err_out_free_netdev
;
1421 net_dev
->ml_priv
= (PVOID
)pAd
;
1422 pAd
->net_dev
= net_dev
; // must be before RT28XXNetDevInit()
1424 RT28XXNetDevInit(_dev_p
, net_dev
, pAd
);
1426 #ifdef CONFIG_STA_SUPPORT
1427 pAd
->StaCfg
.OriDevType
= net_dev
->type
;
1428 #endif // CONFIG_STA_SUPPORT //
1430 // Find and assign a free interface name, raxx
1431 // RT28XXAvailRANameAssign(net_dev->name);
1434 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1435 if (RT28XXProbePostConfig(_dev_p
, pAd
, argc
) == FALSE
)
1438 if (RT28XXProbePostConfig(_dev_p
, pAd
, 0) == FALSE
)
1440 #endif // LINUX_VERSION_CODE //
1442 #ifdef CONFIG_STA_SUPPORT
1443 pAd
->OpMode
= OPMODE_STA
;
1444 #endif // CONFIG_STA_SUPPORT //
1447 #ifdef MULTIPLE_CARD_SUPPORT
1448 // find its profile path
1449 pAd
->MC_RowID
= -1; // use default profile path
1450 RTMP_CardInfoRead(pAd
);
1452 if (pAd
->MC_RowID
== -1)
1453 #ifdef CONFIG_STA_SUPPORT
1454 strcpy(pAd
->MC_FileName
, STA_PROFILE_PATH
);
1455 #endif // CONFIG_STA_SUPPORT //
1457 DBGPRINT(RT_DEBUG_TRACE
,
1458 ("MC> ROW = %d, PATH = %s\n", pAd
->MC_RowID
, pAd
->MC_FileName
));
1459 #endif // MULTIPLE_CARD_SUPPORT //
1462 if (rt_ieee80211_if_setup(net_dev
, pAd
) != NDIS_STATUS_SUCCESS
)
1465 // Register this device
1466 status
= register_netdev(net_dev
);
1471 RT28XX_DRVDATA_SET(_dev_p
);
1476 return 0; // probe ok
1479 /* --------------------------- ERROR HANDLE --------------------------- */
1481 RTMPFreeAdapter(pAd
);
1484 err_out_free_netdev
:
1485 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1486 free_netdev(net_dev
);
1492 RT28XX_PUT_DEVICE(dev_p
);
1494 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1497 return -ENODEV
; /* probe fail */
1498 #endif // LINUX_VERSION_CODE //
1499 } /* End of rt28xx_probe */
1503 ========================================================================
1504 Routine Description:
1505 The entry point for Linux kernel sent packet to our driver.
1508 sk_buff *skb the pointer refer to a sk_buffer.
1514 This function is the entry point of Tx Path for Os delivery packet to
1515 our driver. You only can put OS-depened & STA/AP common handle procedures
1517 ========================================================================
1519 int rt28xx_packet_xmit(struct sk_buff
*skb
)
1521 struct net_device
*net_dev
= skb
->dev
;
1522 PRTMP_ADAPTER pAd
= net_dev
->ml_priv
;
1524 PNDIS_PACKET pPacket
= (PNDIS_PACKET
) skb
;
1526 /* RT2870STA does this in RTMPSendPackets() */
1530 RELEASE_NDIS_PACKET(pAd
, pPacket
, NDIS_STATUS_RESOURCES
);
1533 #endif // RALINK_ATE //
1535 #ifdef CONFIG_STA_SUPPORT
1536 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1538 // Drop send request since we are in monitor mode
1539 if (MONITOR_ON(pAd
))
1541 RELEASE_NDIS_PACKET(pAd
, pPacket
, NDIS_STATUS_FAILURE
);
1545 #endif // CONFIG_STA_SUPPORT //
1547 // EapolStart size is 18
1550 //printk("bad packet size: %d\n", pkt->len);
1551 hex_dump("bad packet", skb
->data
, skb
->len
);
1552 RELEASE_NDIS_PACKET(pAd
, pPacket
, NDIS_STATUS_FAILURE
);
1557 // if ((pkt->data[0] & 0x1) == 0)
1559 //hex_dump(__func__, pkt->data, pkt->len);
1560 printk("pPacket = %x\n", pPacket
);
1564 RTMP_SET_PACKET_5VT(pPacket
, 0);
1565 // MiniportMMRequest(pAd, pkt->data, pkt->len);
1566 #ifdef CONFIG_5VT_ENHANCE
1567 if (*(int*)(skb
->cb
) == BRIDGE_TAG
) {
1568 RTMP_SET_PACKET_5VT(pPacket
, 1);
1574 #ifdef CONFIG_STA_SUPPORT
1575 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1578 STASendPackets((NDIS_HANDLE
)pAd
, (PPNDIS_PACKET
) &pPacket
, 1);
1581 #endif // CONFIG_STA_SUPPORT //
1591 ========================================================================
1592 Routine Description:
1593 Send a packet to WLAN.
1596 skb_p points to our adapter
1597 dev_p which WLAN network interface
1600 0: transmit successfully
1601 otherwise: transmit fail
1604 ========================================================================
1606 INT
rt28xx_send_packets(
1607 IN
struct sk_buff
*skb_p
,
1608 IN
struct net_device
*net_dev
)
1610 RTMP_ADAPTER
*pAd
= net_dev
->ml_priv
;
1612 if (!(net_dev
->flags
& IFF_UP
))
1614 RELEASE_NDIS_PACKET(pAd
, (PNDIS_PACKET
)skb_p
, NDIS_STATUS_FAILURE
);
1618 NdisZeroMemory((PUCHAR
)&skb_p
->cb
[CB_OFF
], 15);
1619 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p
, MAIN_MBSSID
);
1621 return rt28xx_packet_xmit(skb_p
);
1622 } /* End of MBSS_VirtualIF_PacketSend */
1627 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
1628 //static struct net_device *alloc_netdev(int sizeof_priv, const char *mask, void (*setup)(struct net_device *)) //sample
1629 struct net_device
*alloc_netdev(
1632 void (*setup
)(struct net_device
*))
1634 struct net_device
*dev
;
1638 /* ensure 32-byte alignment of the private area */
1639 alloc_size
= sizeof (*dev
) + sizeof_priv
+ 31;
1641 dev
= (struct net_device
*) kmalloc(alloc_size
, GFP_KERNEL
);
1644 DBGPRINT(RT_DEBUG_ERROR
,
1645 ("alloc_netdev: Unable to allocate device memory.\n"));
1649 memset(dev
, 0, alloc_size
);
1652 dev
->priv
= (void *) (((long)(dev
+ 1) + 31) & ~31);
1655 strcpy(dev
->name
, mask
);
1659 #endif // LINUX_VERSION_CODE //
1662 void CfgInitHook(PRTMP_ADAPTER pAd
)
1664 pAd
->bBroadComHT
= TRUE
;
1665 } /* End of CfgInitHook */
1668 #if 0 // Not used now, should keep it in our source tree??
1670 ========================================================================
1671 Routine Description:
1672 Find and assign a free interface name (raxx).
1675 *name_p the interface name pointer
1682 ========================================================================
1684 static BOOLEAN
RT28XXAvailRANameAssign(
1687 CHAR slot_name
[IFNAMSIZ
];
1688 struct net_device
*device
;
1692 for(if_id
=0; if_id
<8; if_id
++)
1694 sprintf(slot_name
, "ra%d", if_id
);
1696 for(device
=dev_base
; device
!=NULL
; device
=device
->next
)
1698 if (strncmp(device
->name
, slot_name
, 4) == 0)
1708 DBGPRINT(RT_DEBUG_ERROR
, ("No available slot name\n"));
1712 sprintf(name_p
, "ra%d", if_id
);
1714 } /* End of RT28XXAvailRANameAssign */
1717 #if WIRELESS_EXT >= 12
1718 // This function will be called when query /proc
1719 struct iw_statistics
*rt28xx_get_wireless_stats(
1720 IN
struct net_device
*net_dev
)
1722 PRTMP_ADAPTER pAd
= net_dev
->ml_priv
;
1725 DBGPRINT(RT_DEBUG_TRACE
, ("rt28xx_get_wireless_stats --->\n"));
1727 pAd
->iw_stats
.status
= 0; // Status - device dependent for now
1730 pAd
->iw_stats
.qual
.qual
= ((pAd
->Mlme
.ChannelQuality
* 12)/10 + 10);
1731 if(pAd
->iw_stats
.qual
.qual
> 100)
1732 pAd
->iw_stats
.qual
.qual
= 100;
1734 #ifdef CONFIG_STA_SUPPORT
1735 if (pAd
->OpMode
== OPMODE_STA
)
1736 pAd
->iw_stats
.qual
.level
= RTMPMaxRssi(pAd
, pAd
->StaCfg
.RssiSample
.LastRssi0
, pAd
->StaCfg
.RssiSample
.LastRssi1
, pAd
->StaCfg
.RssiSample
.LastRssi2
);
1737 #endif // CONFIG_STA_SUPPORT //
1739 pAd
->iw_stats
.qual
.noise
= pAd
->BbpWriteLatch
[66]; // noise level (dBm)
1741 pAd
->iw_stats
.qual
.noise
+= 256 - 143;
1742 pAd
->iw_stats
.qual
.updated
= 1; // Flags to know if updated
1744 pAd
->iw_stats
.qual
.updated
|= IW_QUAL_DBM
; // Level + Noise are dBm
1745 #endif // IW_QUAL_DBM //
1747 pAd
->iw_stats
.discard
.nwid
= 0; // Rx : Wrong nwid/essid
1748 pAd
->iw_stats
.miss
.beacon
= 0; // Missed beacons/superframe
1750 DBGPRINT(RT_DEBUG_TRACE
, ("<--- rt28xx_get_wireless_stats\n"));
1751 return &pAd
->iw_stats
;
1752 } /* End of rt28xx_get_wireless_stats */
1753 #endif // WIRELESS_EXT //
1757 void tbtt_tasklet(unsigned long data
)
1759 #define MAX_TX_IN_TBTT (16)
1764 IN
struct net_device
*net_dev
,
1765 IN OUT
struct ifreq
*rq
,
1768 VIRTUAL_ADAPTER
*pVirtualAd
= NULL
;
1769 RTMP_ADAPTER
*pAd
= NULL
;
1772 if (net_dev
->priv_flags
== INT_MAIN
)
1774 pAd
= net_dev
->ml_priv
;
1778 pVirtualAd
= net_dev
->ml_priv
;
1779 pAd
= pVirtualAd
->RtmpDev
->ml_priv
;
1784 /* if 1st open fail, pAd will be free;
1785 So the net_dev->ml_priv will be NULL in 2rd open */
1790 #ifdef CONFIG_STA_SUPPORT
1791 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1793 ret
= rt28xx_sta_ioctl(net_dev
, rq
, cmd
);
1795 #endif // CONFIG_STA_SUPPORT //
1801 ========================================================================
1803 Routine Description:
1804 return ethernet statistics counter
1807 net_dev Pointer to net_device
1814 ========================================================================
1816 struct net_device_stats
*RT28xx_get_ether_stats(
1817 IN
struct net_device
*net_dev
)
1819 RTMP_ADAPTER
*pAd
= NULL
;
1822 pAd
= net_dev
->ml_priv
;
1827 pAd
->stats
.rx_packets
= pAd
->WlanCounters
.ReceivedFragmentCount
.QuadPart
;
1828 pAd
->stats
.tx_packets
= pAd
->WlanCounters
.TransmittedFragmentCount
.QuadPart
;
1830 pAd
->stats
.rx_bytes
= pAd
->RalinkCounters
.ReceivedByteCount
;
1831 pAd
->stats
.tx_bytes
= pAd
->RalinkCounters
.TransmittedByteCount
;
1833 pAd
->stats
.rx_errors
= pAd
->Counters8023
.RxErrors
;
1834 pAd
->stats
.tx_errors
= pAd
->Counters8023
.TxErrors
;
1836 pAd
->stats
.rx_dropped
= 0;
1837 pAd
->stats
.tx_dropped
= 0;
1839 pAd
->stats
.multicast
= pAd
->WlanCounters
.MulticastReceivedFrameCount
.QuadPart
; // multicast packets received
1840 pAd
->stats
.collisions
= pAd
->Counters8023
.OneCollision
+ pAd
->Counters8023
.MoreCollisions
; // Collision packets
1842 pAd
->stats
.rx_length_errors
= 0;
1843 pAd
->stats
.rx_over_errors
= pAd
->Counters8023
.RxNoBuffer
; // receiver ring buff overflow
1844 pAd
->stats
.rx_crc_errors
= 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1845 pAd
->stats
.rx_frame_errors
= pAd
->Counters8023
.RcvAlignmentErrors
; // recv'd frame alignment error
1846 pAd
->stats
.rx_fifo_errors
= pAd
->Counters8023
.RxNoBuffer
; // recv'r fifo overrun
1847 pAd
->stats
.rx_missed_errors
= 0; // receiver missed packet
1849 // detailed tx_errors
1850 pAd
->stats
.tx_aborted_errors
= 0;
1851 pAd
->stats
.tx_carrier_errors
= 0;
1852 pAd
->stats
.tx_fifo_errors
= 0;
1853 pAd
->stats
.tx_heartbeat_errors
= 0;
1854 pAd
->stats
.tx_window_errors
= 0;
1857 pAd
->stats
.rx_compressed
= 0;
1858 pAd
->stats
.tx_compressed
= 0;