2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
31 Create and register network interface.
35 -------- ---------- ----------------------------------------------
36 Sample Mar/21/07 Merge RT2870 and RT2860 drivers.
39 #include "rt_config.h"
41 #define FORTY_MHZ_INTOLERANT_INTERVAL (60*1000) // 1 min
43 /*---------------------------------------------------------------------*/
44 /* Private Variables Used */
45 /*---------------------------------------------------------------------*/
46 //static RALINK_TIMER_STRUCT PeriodicTimer;
48 char *mac
= ""; // default 00:00:00:00:00:00
50 module_param (mac
, charp
, 0);
51 MODULE_PARM_DESC (mac
, "rt28xx: wireless mac addr");
54 /*---------------------------------------------------------------------*/
55 /* Prototypes of Functions Used */
56 /*---------------------------------------------------------------------*/
57 #ifdef DOT11_N_SUPPORT
58 extern BOOLEAN
ba_reordering_resource_init(PRTMP_ADAPTER pAd
, int num
);
59 extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd
);
60 #endif // DOT11_N_SUPPORT //
61 extern NDIS_STATUS
NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd
);
64 // public function prototype
65 INT __devinit
rt28xx_probe(IN
void *_dev_p
, IN
void *_dev_id_p
,
66 IN UINT argc
, OUT PRTMP_ADAPTER
*ppAd
);
68 // private function prototype
69 static int rt28xx_init(IN
struct net_device
*net_dev
);
70 INT
rt28xx_send_packets(IN
struct sk_buff
*skb_p
, IN
struct net_device
*net_dev
);
72 static void CfgInitHook(PRTMP_ADAPTER pAd
);
73 //static BOOLEAN RT28XXAvailRANameAssign(IN CHAR *name_p);
75 #ifdef CONFIG_STA_SUPPORT
76 extern const struct iw_handler_def rt28xx_iw_handler_def
;
77 #endif // CONFIG_STA_SUPPORT //
79 #if WIRELESS_EXT >= 12
80 // This function will be called when query /proc
81 struct iw_statistics
*rt28xx_get_wireless_stats(
82 IN
struct net_device
*net_dev
);
85 struct net_device_stats
*RT28xx_get_ether_stats(
86 IN
struct net_device
*net_dev
);
89 ========================================================================
94 *net_dev the raxx interface pointer
101 1. if open fail, kernel will not call the close function.
103 (1) Mlme Memory Handler: MlmeHalt()
104 (2) TX & RX: RTMPFreeTxRxRingMemory()
105 (3) BA Reordering: ba_reordering_resource_release()
106 ========================================================================
108 int MainVirtualIF_close(IN
struct net_device
*net_dev
)
110 RTMP_ADAPTER
*pAd
= net_dev
->ml_priv
;
112 // Sanity check for pAd
114 return 0; // close ok
116 netif_carrier_off(pAd
->net_dev
);
117 netif_stop_queue(pAd
->net_dev
);
121 VIRTUAL_IF_DOWN(pAd
);
123 RT_MOD_DEC_USE_COUNT();
125 return 0; // close ok
129 ========================================================================
134 *net_dev the raxx interface pointer
141 1. if open fail, kernel will not call the close function.
143 (1) Mlme Memory Handler: MlmeHalt()
144 (2) TX & RX: RTMPFreeTxRxRingMemory()
145 (3) BA Reordering: ba_reordering_resource_release()
146 ========================================================================
148 int MainVirtualIF_open(IN
struct net_device
*net_dev
)
150 RTMP_ADAPTER
*pAd
= net_dev
->ml_priv
;
152 // Sanity check for pAd
154 return 0; // close ok
156 if (VIRTUAL_IF_UP(pAd
) != 0)
159 // increase MODULE use count
160 RT_MOD_INC_USE_COUNT();
162 netif_start_queue(net_dev
);
163 netif_carrier_on(net_dev
);
164 netif_wake_queue(net_dev
);
170 ========================================================================
172 Close raxx interface.
175 *net_dev the raxx interface pointer
182 1. if open fail, kernel will not call the close function.
184 (1) Mlme Memory Handler: MlmeHalt()
185 (2) TX & RX: RTMPFreeTxRxRingMemory()
186 (3) BA Reordering: ba_reordering_resource_release()
187 ========================================================================
189 int rt28xx_close(IN PNET_DEV dev
)
191 struct net_device
* net_dev
= (struct net_device
*)dev
;
192 RTMP_ADAPTER
*pAd
= net_dev
->ml_priv
;
193 BOOLEAN Cancelled
= FALSE
;
196 DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup
);
197 DECLARE_WAITQUEUE(wait
, current
);
199 //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
203 DBGPRINT(RT_DEBUG_TRACE
, ("===> rt28xx_close\n"));
205 // Sanity check for pAd
207 return 0; // close ok
210 #ifdef CONFIG_STA_SUPPORT
211 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
214 // If dirver doesn't wake up firmware here,
215 // NICLoadFirmware will hang forever when interface is up again.
216 if (OPSTATUS_TEST_FLAG(pAd
, fOP_STATUS_DOZE
))
218 AsicForceWakeup(pAd
, TRUE
);
221 #ifdef QOS_DLS_SUPPORT
222 // send DLS-TEAR_DOWN message,
223 if (pAd
->CommonCfg
.bDLSCapable
)
227 // tear down local dls table entry
228 for (i
=0; i
<MAX_NUM_OF_INIT_DLS_ENTRY
; i
++)
230 if (pAd
->StaCfg
.DLSEntry
[i
].Valid
&& (pAd
->StaCfg
.DLSEntry
[i
].Status
== DLS_FINISH
))
232 RTMPSendDLSTearDownFrame(pAd
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
);
233 pAd
->StaCfg
.DLSEntry
[i
].Status
= DLS_NONE
;
234 pAd
->StaCfg
.DLSEntry
[i
].Valid
= FALSE
;
238 // tear down peer dls table entry
239 for (i
=MAX_NUM_OF_INIT_DLS_ENTRY
; i
<MAX_NUM_OF_DLS_ENTRY
; i
++)
241 if (pAd
->StaCfg
.DLSEntry
[i
].Valid
&& (pAd
->StaCfg
.DLSEntry
[i
].Status
== DLS_FINISH
))
243 RTMPSendDLSTearDownFrame(pAd
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
);
244 pAd
->StaCfg
.DLSEntry
[i
].Status
= DLS_NONE
;
245 pAd
->StaCfg
.DLSEntry
[i
].Valid
= FALSE
;
248 RT28XX_MLME_HANDLER(pAd
);
250 #endif // QOS_DLS_SUPPORT //
253 (!RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_NIC_NOT_EXIST
)))
255 MLME_DISASSOC_REQ_STRUCT DisReq
;
256 MLME_QUEUE_ELEM
*MsgElem
= (MLME_QUEUE_ELEM
*) kmalloc(sizeof(MLME_QUEUE_ELEM
), MEM_ALLOC_FLAG
);
258 COPY_MAC_ADDR(DisReq
.Addr
, pAd
->CommonCfg
.Bssid
);
259 DisReq
.Reason
= REASON_DEAUTH_STA_LEAVING
;
261 MsgElem
->Machine
= ASSOC_STATE_MACHINE
;
262 MsgElem
->MsgType
= MT2_MLME_DISASSOC_REQ
;
263 MsgElem
->MsgLen
= sizeof(MLME_DISASSOC_REQ_STRUCT
);
264 NdisMoveMemory(MsgElem
->Msg
, &DisReq
, sizeof(MLME_DISASSOC_REQ_STRUCT
));
266 // Prevent to connect AP again in STAMlmePeriodicExec
267 pAd
->MlmeAux
.AutoReconnectSsidLen
= 32;
268 NdisZeroMemory(pAd
->MlmeAux
.AutoReconnectSsid
, pAd
->MlmeAux
.AutoReconnectSsidLen
);
270 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_OID_DISASSOC
;
271 MlmeDisassocReqAction(pAd
, MsgElem
);
278 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_REMOVE_IN_PROGRESS
);
282 RTMPCancelTimer(&pAd
->StaCfg
.LeapAuthTimer
, &Cancelled
);
285 RTMPCancelTimer(&pAd
->StaCfg
.StaQuickResponeForRateUpTimer
, &Cancelled
);
286 RTMPCancelTimer(&pAd
->StaCfg
.WpaDisassocAndBlockAssocTimer
, &Cancelled
);
288 #ifdef WPA_SUPPLICANT_SUPPORT
289 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
291 union iwreq_data wrqu
;
292 // send wireless event to wpa_supplicant for infroming interface down.
293 memset(&wrqu
, 0, sizeof(wrqu
));
294 wrqu
.data
.flags
= RT_INTERFACE_DOWN
;
295 wireless_send_event(pAd
->net_dev
, IWEVCUSTOM
, &wrqu
, NULL
);
297 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
298 #endif // WPA_SUPPLICANT_SUPPORT //
302 #endif // CONFIG_STA_SUPPORT //
304 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_HALT_IN_PROGRESS
);
306 for (i
= 0 ; i
< NUM_OF_TX_RING
; i
++)
308 while (pAd
->DeQueueRunning
[i
] == TRUE
)
310 printk("Waiting for TxQueue[%d] done..........\n", i
);
316 // ensure there are no more active urbs.
317 add_wait_queue (&unlink_wakeup
, &wait
);
318 pAd
->wait
= &unlink_wakeup
;
320 // maybe wait for deletions to finish.
322 //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
325 unsigned long IrqFlags
;
327 RTMP_IRQ_LOCK(&pAd
->BulkInLock
, IrqFlags
);
328 if (pAd
->PendingRx
== 0)
330 RTMP_IRQ_UNLOCK(&pAd
->BulkInLock
, IrqFlags
);
333 RTMP_IRQ_UNLOCK(&pAd
->BulkInLock
, IrqFlags
);
335 msleep(UNLINK_TIMEOUT_MS
); //Time in millisecond
339 remove_wait_queue (&unlink_wakeup
, &wait
);
342 //RTUSBCleanUpMLMEWaitQueue(pAd); /*not used in RT28xx*/
346 // We need clear timerQ related structure before exits of the timer thread.
347 RT2870_TimerQ_Exit(pAd
);
348 // Close kernel threads or tasklets
349 RT28xxThreadTerminate(pAd
);
352 // Stop Mlme state machine
355 // Close kernel threads or tasklets
356 kill_thread_task(pAd
);
359 #ifdef CONFIG_STA_SUPPORT
360 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
364 #endif // CONFIG_STA_SUPPORT //
367 MeasureReqTabExit(pAd
);
373 // Free Ring or USB buffers
374 RTMPFreeTxRxRingMemory(pAd
);
376 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_HALT_IN_PROGRESS
);
378 #ifdef DOT11_N_SUPPORT
379 // Free BA reorder resource
380 ba_reordering_resource_release(pAd
);
381 #endif // DOT11_N_SUPPORT //
385 if (pAd
->UsbVendorReqBuf
)
386 os_free_mem(pAd
, pAd
->UsbVendorReqBuf
);
387 #endif // INF_AMAZON_SE //
390 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_START_UP
);
392 return 0; // close ok
393 } /* End of rt28xx_close */
395 static int rt28xx_init(IN
struct net_device
*net_dev
)
397 PRTMP_ADAPTER pAd
= net_dev
->ml_priv
;
405 init_MUTEX(&(pAd
->UsbVendorReq_semaphore
));
406 os_alloc_mem(pAd
, (PUCHAR
)&pAd
->UsbVendorReqBuf
, MAX_PARAM_BUFFER_SIZE
- 1);
407 if (pAd
->UsbVendorReqBuf
== NULL
)
409 DBGPRINT(RT_DEBUG_ERROR
, ("Allocate vendor request temp buffer failed!\n"));
412 #endif // INF_AMAZON_SE //
415 #ifdef DOT11_N_SUPPORT
416 // Allocate BA Reordering memory
417 ba_reordering_resource_init(pAd
, MAX_REORDERING_MPDU_NUM
);
418 #endif // DOT11_N_SUPPORT //
420 // Make sure MAC gets ready.
424 RTMP_IO_READ32(pAd
, MAC_CSR0
, &MacCsr0
);
425 pAd
->MACVersion
= MacCsr0
;
427 if ((pAd
->MACVersion
!= 0x00) && (pAd
->MACVersion
!= 0xFFFFFFFF))
431 } while (index
++ < 100);
433 DBGPRINT(RT_DEBUG_TRACE
, ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd
->MACVersion
));
436 RT28XXDMADisable(pAd
);
439 // Load 8051 firmware
440 Status
= NICLoadFirmware(pAd
);
441 if (Status
!= NDIS_STATUS_SUCCESS
)
443 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status
));
447 NICLoadRateSwitchingParams(pAd
);
449 // Disable interrupts here which is as soon as possible
450 // This statement should never be true. We might consider to remove it later
452 Status
= RTMPAllocTxRxRingMemory(pAd
);
453 if (Status
!= NDIS_STATUS_SUCCESS
)
455 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status
));
459 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_INTERRUPT_IN_USE
);
464 Status
= MlmeInit(pAd
);
465 if (Status
!= NDIS_STATUS_SUCCESS
)
467 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status
));
471 // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
476 // We need init timerQ related structure before create the timer thread.
477 RT2870_TimerQ_Init(pAd
);
480 RT28XX_TASK_THREAD_INIT(pAd
, Status
);
481 if (Status
!= NDIS_STATUS_SUCCESS
)
484 // COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
485 // pAd->bForcePrintTX = TRUE;
489 #ifdef CONFIG_STA_SUPPORT
490 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
491 NdisAllocateSpinLock(&pAd
->MacTabLock
);
492 #endif // CONFIG_STA_SUPPORT //
494 MeasureReqTabInit(pAd
);
498 // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
500 Status
= NICInitializeAdapter(pAd
, TRUE
);
501 if (Status
!= NDIS_STATUS_SUCCESS
)
503 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status
));
504 if (Status
!= NDIS_STATUS_SUCCESS
)
508 // Read parameters from Config File
509 Status
= RTMPReadParametersHook(pAd
);
511 printk("1. Phy Mode = %d\n", pAd
->CommonCfg
.PhyMode
);
512 if (Status
!= NDIS_STATUS_SUCCESS
)
514 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status
));
519 pAd
->CommonCfg
.bMultipleIRP
= FALSE
;
521 if (pAd
->CommonCfg
.bMultipleIRP
)
522 pAd
->CommonCfg
.NumOfBulkInIRP
= RX_RING_SIZE
;
524 pAd
->CommonCfg
.NumOfBulkInIRP
= 1;
528 //Init Ba Capability parameters.
529 // RT28XX_BA_INIT(pAd);
530 #ifdef DOT11_N_SUPPORT
531 pAd
->CommonCfg
.DesiredHtPhy
.MpduDensity
= (UCHAR
)pAd
->CommonCfg
.BACapability
.field
.MpduDensity
;
532 pAd
->CommonCfg
.DesiredHtPhy
.AmsduEnable
= (USHORT
)pAd
->CommonCfg
.BACapability
.field
.AmsduEnable
;
533 pAd
->CommonCfg
.DesiredHtPhy
.AmsduSize
= (USHORT
)pAd
->CommonCfg
.BACapability
.field
.AmsduSize
;
534 pAd
->CommonCfg
.DesiredHtPhy
.MimoPs
= (USHORT
)pAd
->CommonCfg
.BACapability
.field
.MMPSmode
;
536 pAd
->CommonCfg
.HtCapability
.HtCapInfo
.MimoPs
= (USHORT
)pAd
->CommonCfg
.BACapability
.field
.MMPSmode
;
537 pAd
->CommonCfg
.HtCapability
.HtCapInfo
.AMsduSize
= (USHORT
)pAd
->CommonCfg
.BACapability
.field
.AmsduSize
;
538 pAd
->CommonCfg
.HtCapability
.HtCapParm
.MpduDensity
= (UCHAR
)pAd
->CommonCfg
.BACapability
.field
.MpduDensity
;
539 #endif // DOT11_N_SUPPORT //
541 // after reading Registry, we now know if in AP mode or STA mode
543 // Load 8051 firmware; crash when FW image not existent
544 // Status = NICLoadFirmware(pAd);
545 // if (Status != NDIS_STATUS_SUCCESS)
548 printk("2. Phy Mode = %d\n", pAd
->CommonCfg
.PhyMode
);
550 // We should read EEPROM for all cases. rt2860b
551 NICReadEEPROMParameters(pAd
, mac
);
552 #ifdef CONFIG_STA_SUPPORT
553 #endif // CONFIG_STA_SUPPORT //
555 printk("3. Phy Mode = %d\n", pAd
->CommonCfg
.PhyMode
);
557 NICInitAsicFromEEPROM(pAd
); //rt2860b
559 // Set PHY to appropriate mode
560 TmpPhy
= pAd
->CommonCfg
.PhyMode
;
561 pAd
->CommonCfg
.PhyMode
= 0xff;
562 RTMPSetPhyMode(pAd
, TmpPhy
);
563 #ifdef DOT11_N_SUPPORT
565 #endif // DOT11_N_SUPPORT //
567 // No valid channels.
568 if (pAd
->ChannelListNum
== 0)
570 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
574 #ifdef DOT11_N_SUPPORT
575 printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd
->CommonCfg
.HtCapability
.MCSSet
[0],
576 pAd
->CommonCfg
.HtCapability
.MCSSet
[1], pAd
->CommonCfg
.HtCapability
.MCSSet
[2],
577 pAd
->CommonCfg
.HtCapability
.MCSSet
[3], pAd
->CommonCfg
.HtCapability
.MCSSet
[4]);
578 #endif // DOT11_N_SUPPORT //
581 //Init RT30xx RFRegisters after read RFIC type from EEPROM
582 NICInitRT30xxRFRegisters(pAd
);
586 // Patch cardbus controller if EEPROM said so.
587 if (pAd
->bTest1
== FALSE
)
588 RTMPPatchCardBus(pAd
);
592 // APInitialize(pAd);
595 VR_IKANOS_FP_Init(pAd
->ApCfg
.BssidNum
, pAd
->PermanentAddress
);
596 #endif // IKANOS_VX_1X0 //
599 // Initialize RF register to default value
601 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.Channel
, FALSE
);
602 AsicLockChannel(pAd
, pAd
->CommonCfg
.Channel
);
604 // 8051 firmware require the signal during booting time.
605 AsicSendCommandToMcu(pAd
, 0x72, 0xFF, 0x00, 0x00);
607 if (pAd
&& (Status
!= NDIS_STATUS_SUCCESS
))
610 // Undo everything if it failed
612 if (RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_INTERRUPT_IN_USE
))
614 // NdisMDeregisterInterrupt(&pAd->Interrupt);
615 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_INTERRUPT_IN_USE
);
617 // RTMPFreeAdapter(pAd); // we will free it in disconnect()
621 // Microsoft HCT require driver send a disconnect event after driver initialization.
622 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_MEDIA_STATE_CONNECTED
);
623 // pAd->IndicateMediaState = NdisMediaStateDisconnected;
624 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_MEDIA_STATE_CHANGE
);
626 DBGPRINT(RT_DEBUG_TRACE
, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
630 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_RESET_IN_PROGRESS
);
631 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_REMOVE_IN_PROGRESS
);
634 // Support multiple BulkIn IRP,
635 // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
637 for(index
=0; index
<pAd
->CommonCfg
.NumOfBulkInIRP
; index
++)
639 RTUSBBulkReceive(pAd
);
640 DBGPRINT(RT_DEBUG_TRACE
, ("RTUSBBulkReceive!\n" ));
646 DBGPRINT_S(Status
, ("<==== RTMPInitialize, Status=%x\n", Status
));
655 RTMPFreeTxRxRingMemory(pAd
);
656 // RTMPFreeAdapter(pAd);
659 #ifdef DOT11_N_SUPPORT
660 os_free_mem(pAd
, pAd
->mpdu_blk_pool
.mem
); // free BA pool
661 #endif // DOT11_N_SUPPORT //
662 RT28XX_IRQ_RELEASE(net_dev
);
664 // shall not set ml_priv to NULL here because the ml_priv didn't been free yet.
665 //net_dev->ml_priv = 0;
668 #endif // INF_AMAZON_SE //
669 printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME
);
671 } /* End of rt28xx_init */
675 ========================================================================
680 *net_dev the raxx interface pointer
687 ========================================================================
689 int rt28xx_open(IN PNET_DEV dev
)
691 struct net_device
* net_dev
= (struct net_device
*)dev
;
692 PRTMP_ADAPTER pAd
= net_dev
->ml_priv
;
697 // Sanity check for pAd
700 /* if 1st open fail, pAd will be free;
701 So the net_dev->ml_priv will be NULL in 2rd open */
705 #ifdef CONFIG_STA_SUPPORT
706 #endif // CONFIG_STA_SUPPORT //
709 pObj
= (POS_COOKIE
)pAd
->OS_Cookie
;
711 // reset Adapter flags
712 RTMP_CLEAR_FLAGS(pAd
);
714 // Request interrupt service routine for PCI device
715 // register the interrupt routine with the os
716 RT28XX_IRQ_REQUEST(net_dev
);
719 // Init BssTab & ChannelInfo tabbles for auto channel select.
723 if (rt28xx_init(net_dev
) == FALSE
)
726 #ifdef CONFIG_STA_SUPPORT
727 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
729 NdisZeroMemory(pAd
->StaCfg
.dev_name
, 16);
730 NdisMoveMemory(pAd
->StaCfg
.dev_name
, net_dev
->name
, strlen(net_dev
->name
));
732 #endif // CONFIG_STA_SUPPORT //
734 // Set up the Mac address
735 NdisMoveMemory(net_dev
->dev_addr
, (void *) pAd
->CurrentAddress
, 6);
737 // Init IRQ parameters
738 RT28XX_IRQ_INIT(pAd
);
740 // Various AP function init
742 #ifdef CONFIG_STA_SUPPORT
743 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
745 #ifdef WPA_SUPPLICANT_SUPPORT
746 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
748 union iwreq_data wrqu
;
749 // send wireless event to wpa_supplicant for infroming interface down.
750 memset(&wrqu
, 0, sizeof(wrqu
));
751 wrqu
.data
.flags
= RT_INTERFACE_UP
;
752 wireless_send_event(pAd
->net_dev
, IWEVCUSTOM
, &wrqu
, NULL
);
754 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
755 #endif // WPA_SUPPLICANT_SUPPORT //
758 #endif // CONFIG_STA_SUPPORT //
761 RT28XX_IRQ_ENABLE(pAd
);
765 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_START_UP
);
769 RTMP_IO_READ32(pAd
, 0x1300, ®
); // clear garbage interrupts
770 printk("0x1300 = %08x\n", reg
);
778 // RTMP_IO_READ32(pAd, XIFS_TIME_CFG, ®);
781 // reg = (reg & 0xffff0000) | tmp;
782 // RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
789 * show the size of main table in Adapter structure
792 * Total -- 385K !!!!! (5/26/2006)
794 printk("sizeof(pAd->MacTab) = %ld\n", sizeof(pAd
->MacTab
));
795 printk("sizeof(pAd->AccessControlList) = %ld\n", sizeof(pAd
->AccessControlList
));
796 printk("sizeof(pAd->ApCfg) = %ld\n", sizeof(pAd
->ApCfg
));
797 printk("sizeof(pAd->BATable) = %ld\n", sizeof(pAd
->BATable
));
801 #ifdef CONFIG_STA_SUPPORT
802 #endif // CONFIG_STA_SUPPORT //
808 } /* End of rt28xx_open */
810 static const struct net_device_ops rt2870_netdev_ops
= {
811 .ndo_open
= MainVirtualIF_open
,
812 .ndo_stop
= MainVirtualIF_close
,
813 .ndo_do_ioctl
= rt28xx_ioctl
,
814 .ndo_get_stats
= RT28xx_get_ether_stats
,
815 .ndo_validate_addr
= NULL
,
816 .ndo_set_mac_address
= eth_mac_addr
,
817 .ndo_change_mtu
= eth_change_mtu
,
819 .ndo_start_xmit
= IKANOS_DataFramesTx
,
821 .ndo_start_xmit
= rt28xx_send_packets
,
825 /* Must not be called for mdev and apdev */
826 static NDIS_STATUS
rt_ieee80211_if_setup(struct net_device
*dev
, PRTMP_ADAPTER pAd
)
830 CHAR slot_name
[IFNAMSIZ
];
831 struct net_device
*device
;
835 // dev->set_multicast_list = ieee80211_set_multicast_list;
836 // dev->change_mtu = ieee80211_change_mtu;
837 #ifdef CONFIG_STA_SUPPORT
838 #if WIRELESS_EXT >= 12
839 if (pAd
->OpMode
== OPMODE_STA
)
841 dev
->wireless_handlers
= &rt28xx_iw_handler_def
;
843 #endif //WIRELESS_EXT >= 12
844 #endif // CONFIG_STA_SUPPORT //
846 #if WIRELESS_EXT < 21
847 dev
->get_wireless_stats
= rt28xx_get_wireless_stats
;
849 // dev->uninit = ieee80211_if_reinit;
850 // dev->destructor = ieee80211_if_free;
851 dev
->priv_flags
= INT_MAIN
;
852 dev
->netdev_ops
= &rt2870_netdev_ops
;
853 // find available device name
854 for (i
= 0; i
< 8; i
++)
856 sprintf(slot_name
, "ra%d", i
);
858 device
= dev_get_by_name(dev_net(dev
), slot_name
);
868 DBGPRINT(RT_DEBUG_ERROR
, ("No available slot name\n"));
869 Status
= NDIS_STATUS_FAILURE
;
873 sprintf(dev
->name
, "ra%d", i
);
874 Status
= NDIS_STATUS_SUCCESS
;
882 ========================================================================
884 Probe RT28XX chipset.
887 _dev_p Point to the PCI or USB device
888 _dev_id_p Point to the PCI or USB device ID
895 ========================================================================
897 INT __devinit
rt28xx_probe(
901 OUT PRTMP_ADAPTER
*ppAd
)
903 struct net_device
*net_dev
;
904 PRTMP_ADAPTER pAd
= (PRTMP_ADAPTER
) NULL
;
908 struct usb_interface
*intf
= (struct usb_interface
*)_dev_p
;
909 struct usb_device
*dev_p
= interface_to_usbdev(intf
);
911 dev_p
= usb_get_dev(dev_p
);
915 #ifdef CONFIG_STA_SUPPORT
916 DBGPRINT(RT_DEBUG_TRACE
, ("STA Driver version-%s\n", STA_DRIVER_VERSION
));
917 #endif // CONFIG_STA_SUPPORT //
919 // Check chipset vendor/product ID
920 // if (RT28XXChipsetCheck(_dev_p) == FALSE)
923 net_dev
= alloc_etherdev(sizeof(PRTMP_ADAPTER
));
926 printk("alloc_netdev failed\n");
932 // if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
935 netif_stop_queue(net_dev
);
936 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
937 /* for supporting Network Manager */
938 /* Set the sysfs physical device reference for the network logical device
939 * if set prior to registration will cause a symlink during initialization.
941 SET_NETDEV_DEV(net_dev
, &(dev_p
->dev
));
942 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
944 // Allocate RTMP_ADAPTER miniport adapter structure
945 handle
= kmalloc(sizeof(struct os_cookie
), GFP_KERNEL
);
946 RT28XX_HANDLE_DEV_ASSIGN(handle
, dev_p
);
948 status
= RTMPAllocAdapterBlock(handle
, &pAd
);
949 if (status
!= NDIS_STATUS_SUCCESS
)
950 goto err_out_free_netdev
;
952 net_dev
->ml_priv
= (PVOID
)pAd
;
953 pAd
->net_dev
= net_dev
; // must be before RT28XXNetDevInit()
955 RT28XXNetDevInit(_dev_p
, net_dev
, pAd
);
957 #ifdef CONFIG_STA_SUPPORT
958 pAd
->StaCfg
.OriDevType
= net_dev
->type
;
959 #endif // CONFIG_STA_SUPPORT //
961 // Find and assign a free interface name, raxx
962 // RT28XXAvailRANameAssign(net_dev->name);
965 if (RT28XXProbePostConfig(_dev_p
, pAd
, 0) == FALSE
)
968 #ifdef CONFIG_STA_SUPPORT
969 pAd
->OpMode
= OPMODE_STA
;
970 #endif // CONFIG_STA_SUPPORT //
973 if (rt_ieee80211_if_setup(net_dev
, pAd
) != NDIS_STATUS_SUCCESS
)
976 // Register this device
977 status
= register_netdev(net_dev
);
982 RT28XX_DRVDATA_SET(_dev_p
);
987 return 0; // probe ok
990 /* --------------------------- ERROR HANDLE --------------------------- */
992 RTMPFreeAdapter(pAd
);
996 free_netdev(net_dev
);
999 RT28XX_PUT_DEVICE(dev_p
);
1001 return -ENODEV
; /* probe fail */
1002 } /* End of rt28xx_probe */
1006 ========================================================================
1007 Routine Description:
1008 The entry point for Linux kernel sent packet to our driver.
1011 sk_buff *skb the pointer refer to a sk_buffer.
1017 This function is the entry point of Tx Path for Os delivery packet to
1018 our driver. You only can put OS-depened & STA/AP common handle procedures
1020 ========================================================================
1022 int rt28xx_packet_xmit(struct sk_buff
*skb
)
1024 struct net_device
*net_dev
= skb
->dev
;
1025 PRTMP_ADAPTER pAd
= net_dev
->ml_priv
;
1027 PNDIS_PACKET pPacket
= (PNDIS_PACKET
) skb
;
1029 #ifdef CONFIG_STA_SUPPORT
1030 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1032 // Drop send request since we are in monitor mode
1033 if (MONITOR_ON(pAd
))
1035 RELEASE_NDIS_PACKET(pAd
, pPacket
, NDIS_STATUS_FAILURE
);
1039 #endif // CONFIG_STA_SUPPORT //
1041 // EapolStart size is 18
1044 //printk("bad packet size: %d\n", pkt->len);
1045 hex_dump("bad packet", skb
->data
, skb
->len
);
1046 RELEASE_NDIS_PACKET(pAd
, pPacket
, NDIS_STATUS_FAILURE
);
1051 // if ((pkt->data[0] & 0x1) == 0)
1053 //hex_dump(__func__, pkt->data, pkt->len);
1054 printk("pPacket = %x\n", pPacket
);
1058 RTMP_SET_PACKET_5VT(pPacket
, 0);
1059 // MiniportMMRequest(pAd, pkt->data, pkt->len);
1060 #ifdef CONFIG_5VT_ENHANCE
1061 if (*(int*)(skb
->cb
) == BRIDGE_TAG
) {
1062 RTMP_SET_PACKET_5VT(pPacket
, 1);
1068 #ifdef CONFIG_STA_SUPPORT
1069 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1072 STASendPackets((NDIS_HANDLE
)pAd
, (PPNDIS_PACKET
) &pPacket
, 1);
1075 #endif // CONFIG_STA_SUPPORT //
1085 ========================================================================
1086 Routine Description:
1087 Send a packet to WLAN.
1090 skb_p points to our adapter
1091 dev_p which WLAN network interface
1094 0: transmit successfully
1095 otherwise: transmit fail
1098 ========================================================================
1100 INT
rt28xx_send_packets(
1101 IN
struct sk_buff
*skb_p
,
1102 IN
struct net_device
*net_dev
)
1104 RTMP_ADAPTER
*pAd
= net_dev
->ml_priv
;
1106 if (!(net_dev
->flags
& IFF_UP
))
1108 RELEASE_NDIS_PACKET(pAd
, (PNDIS_PACKET
)skb_p
, NDIS_STATUS_FAILURE
);
1112 NdisZeroMemory((PUCHAR
)&skb_p
->cb
[CB_OFF
], 15);
1113 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p
, MAIN_MBSSID
);
1115 return rt28xx_packet_xmit(skb_p
);
1116 } /* End of MBSS_VirtualIF_PacketSend */
1121 void CfgInitHook(PRTMP_ADAPTER pAd
)
1123 pAd
->bBroadComHT
= TRUE
;
1124 } /* End of CfgInitHook */
1127 #if 0 // Not used now, should keep it in our source tree??
1129 ========================================================================
1130 Routine Description:
1131 Find and assign a free interface name (raxx).
1134 *name_p the interface name pointer
1141 ========================================================================
1143 static BOOLEAN
RT28XXAvailRANameAssign(
1146 CHAR slot_name
[IFNAMSIZ
];
1147 struct net_device
*device
;
1151 for(if_id
=0; if_id
<8; if_id
++)
1153 sprintf(slot_name
, "ra%d", if_id
);
1155 for(device
=dev_base
; device
!=NULL
; device
=device
->next
)
1157 if (strncmp(device
->name
, slot_name
, 4) == 0)
1167 DBGPRINT(RT_DEBUG_ERROR
, ("No available slot name\n"));
1171 sprintf(name_p
, "ra%d", if_id
);
1173 } /* End of RT28XXAvailRANameAssign */
1176 #if WIRELESS_EXT >= 12
1177 // This function will be called when query /proc
1178 struct iw_statistics
*rt28xx_get_wireless_stats(
1179 IN
struct net_device
*net_dev
)
1181 PRTMP_ADAPTER pAd
= net_dev
->ml_priv
;
1184 DBGPRINT(RT_DEBUG_TRACE
, ("rt28xx_get_wireless_stats --->\n"));
1186 pAd
->iw_stats
.status
= 0; // Status - device dependent for now
1189 pAd
->iw_stats
.qual
.qual
= ((pAd
->Mlme
.ChannelQuality
* 12)/10 + 10);
1190 if(pAd
->iw_stats
.qual
.qual
> 100)
1191 pAd
->iw_stats
.qual
.qual
= 100;
1193 #ifdef CONFIG_STA_SUPPORT
1194 if (pAd
->OpMode
== OPMODE_STA
)
1195 pAd
->iw_stats
.qual
.level
= RTMPMaxRssi(pAd
, pAd
->StaCfg
.RssiSample
.LastRssi0
, pAd
->StaCfg
.RssiSample
.LastRssi1
, pAd
->StaCfg
.RssiSample
.LastRssi2
);
1196 #endif // CONFIG_STA_SUPPORT //
1198 pAd
->iw_stats
.qual
.noise
= pAd
->BbpWriteLatch
[66]; // noise level (dBm)
1200 pAd
->iw_stats
.qual
.noise
+= 256 - 143;
1201 pAd
->iw_stats
.qual
.updated
= 1; // Flags to know if updated
1203 pAd
->iw_stats
.qual
.updated
|= IW_QUAL_DBM
; // Level + Noise are dBm
1204 #endif // IW_QUAL_DBM //
1206 pAd
->iw_stats
.discard
.nwid
= 0; // Rx : Wrong nwid/essid
1207 pAd
->iw_stats
.miss
.beacon
= 0; // Missed beacons/superframe
1209 DBGPRINT(RT_DEBUG_TRACE
, ("<--- rt28xx_get_wireless_stats\n"));
1210 return &pAd
->iw_stats
;
1211 } /* End of rt28xx_get_wireless_stats */
1212 #endif // WIRELESS_EXT //
1216 void tbtt_tasklet(unsigned long data
)
1218 #define MAX_TX_IN_TBTT (16)
1223 IN
struct net_device
*net_dev
,
1224 IN OUT
struct ifreq
*rq
,
1227 VIRTUAL_ADAPTER
*pVirtualAd
= NULL
;
1228 RTMP_ADAPTER
*pAd
= NULL
;
1231 if (net_dev
->priv_flags
== INT_MAIN
)
1233 pAd
= net_dev
->ml_priv
;
1237 pVirtualAd
= net_dev
->ml_priv
;
1238 pAd
= pVirtualAd
->RtmpDev
->ml_priv
;
1243 /* if 1st open fail, pAd will be free;
1244 So the net_dev->ml_priv will be NULL in 2rd open */
1249 #ifdef CONFIG_STA_SUPPORT
1250 IF_DEV_CONFIG_OPMODE_ON_STA(pAd
)
1252 ret
= rt28xx_sta_ioctl(net_dev
, rq
, cmd
);
1254 #endif // CONFIG_STA_SUPPORT //
1260 ========================================================================
1262 Routine Description:
1263 return ethernet statistics counter
1266 net_dev Pointer to net_device
1273 ========================================================================
1275 struct net_device_stats
*RT28xx_get_ether_stats(
1276 IN
struct net_device
*net_dev
)
1278 RTMP_ADAPTER
*pAd
= NULL
;
1281 pAd
= net_dev
->ml_priv
;
1286 pAd
->stats
.rx_packets
= pAd
->WlanCounters
.ReceivedFragmentCount
.QuadPart
;
1287 pAd
->stats
.tx_packets
= pAd
->WlanCounters
.TransmittedFragmentCount
.QuadPart
;
1289 pAd
->stats
.rx_bytes
= pAd
->RalinkCounters
.ReceivedByteCount
;
1290 pAd
->stats
.tx_bytes
= pAd
->RalinkCounters
.TransmittedByteCount
;
1292 pAd
->stats
.rx_errors
= pAd
->Counters8023
.RxErrors
;
1293 pAd
->stats
.tx_errors
= pAd
->Counters8023
.TxErrors
;
1295 pAd
->stats
.rx_dropped
= 0;
1296 pAd
->stats
.tx_dropped
= 0;
1298 pAd
->stats
.multicast
= pAd
->WlanCounters
.MulticastReceivedFrameCount
.QuadPart
; // multicast packets received
1299 pAd
->stats
.collisions
= pAd
->Counters8023
.OneCollision
+ pAd
->Counters8023
.MoreCollisions
; // Collision packets
1301 pAd
->stats
.rx_length_errors
= 0;
1302 pAd
->stats
.rx_over_errors
= pAd
->Counters8023
.RxNoBuffer
; // receiver ring buff overflow
1303 pAd
->stats
.rx_crc_errors
= 0;//pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error
1304 pAd
->stats
.rx_frame_errors
= pAd
->Counters8023
.RcvAlignmentErrors
; // recv'd frame alignment error
1305 pAd
->stats
.rx_fifo_errors
= pAd
->Counters8023
.RxNoBuffer
; // recv'r fifo overrun
1306 pAd
->stats
.rx_missed_errors
= 0; // receiver missed packet
1308 // detailed tx_errors
1309 pAd
->stats
.tx_aborted_errors
= 0;
1310 pAd
->stats
.tx_carrier_errors
= 0;
1311 pAd
->stats
.tx_fifo_errors
= 0;
1312 pAd
->stats
.tx_heartbeat_errors
= 0;
1313 pAd
->stats
.tx_window_errors
= 0;
1316 pAd
->stats
.rx_compressed
= 0;
1317 pAd
->stats
.tx_compressed
= 0;