1 //============================================================================
2 // Copyright (c) 1996-2005 Winbond Electronic Corporation
8 // Linux releated routines
10 //============================================================================
11 #include "os_common.h"
14 WBLINUX_MemoryAlloc(void* *VirtualAddress, u32 Length)
16 *VirtualAddress = kzalloc( Length, GFP_ATOMIC ); //GFP_KERNEL is not suitable
18 if (*VirtualAddress == NULL)
24 EncapAtomicInc(PADAPTER Adapter, void* pAtomic)
26 PWBLINUX pWbLinux = &Adapter->WbLinux;
28 u32 * pltmp = (u32 *)pAtomic;
29 OS_SPIN_LOCK_ACQUIRED( &pWbLinux->AtomicSpinLock );
32 OS_SPIN_LOCK_RELEASED( &pWbLinux->AtomicSpinLock );
37 EncapAtomicDec(PADAPTER Adapter, void* pAtomic)
39 PWBLINUX pWbLinux = &Adapter->WbLinux;
41 u32 * pltmp = (u32 *)pAtomic;
42 OS_SPIN_LOCK_ACQUIRED( &pWbLinux->AtomicSpinLock );
45 OS_SPIN_LOCK_RELEASED( &pWbLinux->AtomicSpinLock );
50 WBLINUX_Initial(PADAPTER Adapter)
52 PWBLINUX pWbLinux = &Adapter->WbLinux;
54 OS_SPIN_LOCK_ALLOCATE( &pWbLinux->SpinLock );
55 OS_SPIN_LOCK_ALLOCATE( &pWbLinux->AtomicSpinLock );
60 WBLinux_ReceivePacket(PADAPTER Adapter, PRXLAYER1 pRxLayer1)
67 WBLINUX_GetNextPacket(PADAPTER Adapter, PDESCRIPTOR pDes)
73 WBLINUX_GetNextPacketCompleted(PADAPTER Adapter, PDESCRIPTOR pDes)
79 WBLINUX_Destroy(PADAPTER Adapter)
81 WBLINUX_stop( Adapter );
82 OS_SPIN_LOCK_FREE( &pWbNdis->SpinLock );
83 #ifdef _PE_USB_INI_DUMP_
84 WBDEBUG(("[w35und] unregister_netdev!\n"));
89 WBLINUX_stop( PADAPTER Adapter )
91 PWBLINUX pWbLinux = &Adapter->WbLinux;
94 if (OS_ATOMIC_INC( Adapter, &pWbLinux->ThreadCount ) == 1) {
95 // Shutdown module immediately
96 pWbLinux->shutdown = 1;
98 while (pWbLinux->skb_array[ pWbLinux->skb_GetIndex ]) {
99 // Trying to free the un-sending packet
100 pSkb = pWbLinux->skb_array[ pWbLinux->skb_GetIndex ];
101 pWbLinux->skb_array[ pWbLinux->skb_GetIndex ] = NULL;
103 dev_kfree_skb_irq( pSkb );
105 dev_kfree_skb( pSkb );
107 pWbLinux->skb_GetIndex++;
108 pWbLinux->skb_GetIndex %= WBLINUX_PACKET_ARRAY_SIZE;
111 #ifdef _PE_STATE_DUMP_
112 WBDEBUG(( "[w35und] SKB_RELEASE OK\n" ));
116 OS_ATOMIC_DEC( Adapter, &pWbLinux->ThreadCount );
120 WbWlanHalt( PADAPTER Adapter )
122 //---------------------
123 Adapter->sLocalPara.ShutDowned = TRUE;
125 Mds_Destroy( Adapter );
127 // Turn off Rx and Tx hardware ability
128 hal_stop( &Adapter->sHwData );
129 #ifdef _PE_USB_INI_DUMP_
130 WBDEBUG(("[w35und] Hal_stop O.K.\n"));
132 OS_SLEEP(100000);// Waiting Irp completed
134 // Destroy the NDIS module
135 WBLINUX_Destroy( Adapter );
138 hal_halt(&Adapter->sHwData, NULL);
142 WbWLanInitialize(PADAPTER Adapter)
153 // Setting default value for Linux
155 Adapter->sLocalPara.region_INF = REGION_AUTO;
156 Adapter->sLocalPara.TxRateMode = RATE_AUTO;
157 psLOCAL->bMacOperationMode = MODE_802_11_BG; // B/G mode
158 Adapter->Mds.TxRTSThreshold = DEFAULT_RTSThreshold;
159 Adapter->Mds.TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
160 hal_set_phy_type( &Adapter->sHwData, RF_WB_242_1 );
161 Adapter->sLocalPara.MTUsize = MAX_ETHERNET_PACKET_SIZE;
162 psLOCAL->bPreambleMode = AUTO_MODE;
163 Adapter->sLocalPara.RadioOffStatus.boSwRadioOff = FALSE;
164 pHwData = &Adapter->sHwData;
165 hal_set_phy_type( pHwData, RF_DECIDE_BY_INF );
168 // Initial each module and variable
170 if (!WBLINUX_Initial(Adapter)) {
171 #ifdef _PE_USB_INI_DUMP_
172 WBDEBUG(("[w35und]WBNDIS initialization failed\n"));
177 // Initial Software variable
178 Adapter->sLocalPara.ShutDowned = FALSE;
180 //added by ws for wep key error detection
181 Adapter->sLocalPara.bWepKeyError= FALSE;
182 Adapter->sLocalPara.bToSelfPacketReceived = FALSE;
183 Adapter->sLocalPara.WepKeyDetectTimerCount= 2 * 100; /// 2 seconds
187 pHwData = &Adapter->sHwData;
188 if (!hal_init_hardware(pHwData, Adapter))
191 EEPROM_region = hal_get_region_from_EEPROM( pHwData );
192 if (EEPROM_region != REGION_AUTO)
193 psLOCAL->region = EEPROM_region;
195 if (psLOCAL->region_INF != REGION_AUTO)
196 psLOCAL->region = psLOCAL->region_INF;
198 psLOCAL->region = REGION_USA; //default setting
201 // Get Software setting flag from hal
202 Adapter->sLocalPara.boAntennaDiversity = FALSE;
203 if (hal_software_set(pHwData) & 0x00000001)
204 Adapter->sLocalPara.boAntennaDiversity = TRUE;
213 Mds_initial(Adapter);
215 //=======================================
216 // Initialize the SME, SCAN, MLME, ROAM
217 //=======================================
222 // If no user-defined address in the registry, use the addresss "burned" on the NIC instead.
223 pMacAddr = Adapter->sLocalPara.ThisMacAddress;
224 pMacAddr2 = Adapter->sLocalPara.PermanentAddress;
225 hal_get_permanent_address( pHwData, Adapter->sLocalPara.PermanentAddress );// Reading ethernet address from EEPROM
226 if (OS_MEMORY_COMPARE(pMacAddr, "\x00\x00\x00\x00\x00\x00", MAC_ADDR_LENGTH )) // Is equal
228 memcpy( pMacAddr, pMacAddr2, MAC_ADDR_LENGTH );
230 // Set the user define MAC address
231 hal_set_ethernet_address( pHwData, Adapter->sLocalPara.ThisMacAddress );
234 //get current antenna
235 psLOCAL->bAntennaNo = hal_get_antenna_number(pHwData);
236 #ifdef _PE_STATE_DUMP_
237 WBDEBUG(("Driver init, antenna no = %d\n", psLOCAL->bAntennaNo));
239 hal_get_hw_radio_off( pHwData );
241 // Waiting for HAL setting OK
242 while (!hal_idle(pHwData))
247 HwRadioOff = hal_get_hw_radio_off( pHwData );
248 psLOCAL->RadioOffStatus.boHwRadioOff = !!HwRadioOff;
250 hal_set_radio_mode( pHwData, (unsigned char)(psLOCAL->RadioOffStatus.boSwRadioOff || psLOCAL->RadioOffStatus.boHwRadioOff) );
252 hal_driver_init_OK(pHwData) = 1; // Notify hal that the driver is ready now.
253 //set a tx power for reference.....
254 // sme_set_tx_power_level(Adapter, 12); FIXME?
262 case 3: Mds_Destroy( Adapter );
264 case 1: WBLINUX_Destroy( Adapter );
265 hal_halt( pHwData, NULL );
272 void WBLINUX_ConnectStatus(PADAPTER Adapter, u32 flag)
274 PWBLINUX pWbLinux = &Adapter->WbLinux;
276 pWbLinux->LinkStatus = flag; // OS_DISCONNECTED or OS_CONNECTED