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 spin_lock_irq( &pWbLinux->AtomicSpinLock );
32 spin_unlock_irq( &pWbLinux->AtomicSpinLock );
37 EncapAtomicDec(PADAPTER Adapter, void* pAtomic)
39 PWBLINUX pWbLinux = &Adapter->WbLinux;
41 u32 * pltmp = (u32 *)pAtomic;
42 spin_lock_irq( &pWbLinux->AtomicSpinLock );
45 spin_unlock_irq( &pWbLinux->AtomicSpinLock );
50 WBLINUX_Initial(PADAPTER Adapter)
52 PWBLINUX pWbLinux = &Adapter->WbLinux;
54 spin_lock_init( &pWbLinux->SpinLock );
55 spin_lock_init( &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 #ifdef _PE_USB_INI_DUMP_
83 WBDEBUG(("[w35und] unregister_netdev!\n"));
88 WBLINUX_stop( PADAPTER Adapter )
90 PWBLINUX pWbLinux = &Adapter->WbLinux;
93 if (OS_ATOMIC_INC( Adapter, &pWbLinux->ThreadCount ) == 1) {
94 // Shutdown module immediately
95 pWbLinux->shutdown = 1;
97 while (pWbLinux->skb_array[ pWbLinux->skb_GetIndex ]) {
98 // Trying to free the un-sending packet
99 pSkb = pWbLinux->skb_array[ pWbLinux->skb_GetIndex ];
100 pWbLinux->skb_array[ pWbLinux->skb_GetIndex ] = NULL;
102 dev_kfree_skb_irq( pSkb );
104 dev_kfree_skb( pSkb );
106 pWbLinux->skb_GetIndex++;
107 pWbLinux->skb_GetIndex %= WBLINUX_PACKET_ARRAY_SIZE;
110 #ifdef _PE_STATE_DUMP_
111 WBDEBUG(( "[w35und] SKB_RELEASE OK\n" ));
115 OS_ATOMIC_DEC( Adapter, &pWbLinux->ThreadCount );
119 WbWlanHalt( PADAPTER Adapter )
121 //---------------------
122 Adapter->sLocalPara.ShutDowned = TRUE;
124 Mds_Destroy( Adapter );
126 // Turn off Rx and Tx hardware ability
127 hal_stop( &Adapter->sHwData );
128 #ifdef _PE_USB_INI_DUMP_
129 WBDEBUG(("[w35und] Hal_stop O.K.\n"));
131 OS_SLEEP(100000);// Waiting Irp completed
133 // Destroy the NDIS module
134 WBLINUX_Destroy( Adapter );
137 hal_halt(&Adapter->sHwData, NULL);
141 WbWLanInitialize(PADAPTER Adapter)
151 // Setting default value for Linux
153 Adapter->sLocalPara.region_INF = REGION_AUTO;
154 Adapter->sLocalPara.TxRateMode = RATE_AUTO;
155 psLOCAL->bMacOperationMode = MODE_802_11_BG; // B/G mode
156 Adapter->Mds.TxRTSThreshold = DEFAULT_RTSThreshold;
157 Adapter->Mds.TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
158 hal_set_phy_type( &Adapter->sHwData, RF_WB_242_1 );
159 Adapter->sLocalPara.MTUsize = MAX_ETHERNET_PACKET_SIZE;
160 psLOCAL->bPreambleMode = AUTO_MODE;
161 Adapter->sLocalPara.RadioOffStatus.boSwRadioOff = FALSE;
162 pHwData = &Adapter->sHwData;
163 hal_set_phy_type( pHwData, RF_DECIDE_BY_INF );
166 // Initial each module and variable
168 if (!WBLINUX_Initial(Adapter)) {
169 #ifdef _PE_USB_INI_DUMP_
170 WBDEBUG(("[w35und]WBNDIS initialization failed\n"));
175 // Initial Software variable
176 Adapter->sLocalPara.ShutDowned = FALSE;
178 //added by ws for wep key error detection
179 Adapter->sLocalPara.bWepKeyError= FALSE;
180 Adapter->sLocalPara.bToSelfPacketReceived = FALSE;
181 Adapter->sLocalPara.WepKeyDetectTimerCount= 2 * 100; /// 2 seconds
185 pHwData = &Adapter->sHwData;
186 if (!hal_init_hardware(pHwData, Adapter))
189 EEPROM_region = hal_get_region_from_EEPROM( pHwData );
190 if (EEPROM_region != REGION_AUTO)
191 psLOCAL->region = EEPROM_region;
193 if (psLOCAL->region_INF != REGION_AUTO)
194 psLOCAL->region = psLOCAL->region_INF;
196 psLOCAL->region = REGION_USA; //default setting
199 // Get Software setting flag from hal
200 Adapter->sLocalPara.boAntennaDiversity = FALSE;
201 if (hal_software_set(pHwData) & 0x00000001)
202 Adapter->sLocalPara.boAntennaDiversity = TRUE;
211 Mds_initial(Adapter);
213 //=======================================
214 // Initialize the SME, SCAN, MLME, ROAM
215 //=======================================
220 // If no user-defined address in the registry, use the addresss "burned" on the NIC instead.
221 pMacAddr = Adapter->sLocalPara.ThisMacAddress;
222 pMacAddr2 = Adapter->sLocalPara.PermanentAddress;
223 hal_get_permanent_address( pHwData, Adapter->sLocalPara.PermanentAddress );// Reading ethernet address from EEPROM
224 if (OS_MEMORY_COMPARE(pMacAddr, "\x00\x00\x00\x00\x00\x00", MAC_ADDR_LENGTH )) // Is equal
226 memcpy( pMacAddr, pMacAddr2, MAC_ADDR_LENGTH );
228 // Set the user define MAC address
229 hal_set_ethernet_address( pHwData, Adapter->sLocalPara.ThisMacAddress );
232 //get current antenna
233 psLOCAL->bAntennaNo = hal_get_antenna_number(pHwData);
234 #ifdef _PE_STATE_DUMP_
235 WBDEBUG(("Driver init, antenna no = %d\n", psLOCAL->bAntennaNo));
237 hal_get_hw_radio_off( pHwData );
239 // Waiting for HAL setting OK
240 while (!hal_idle(pHwData))
245 HwRadioOff = hal_get_hw_radio_off( pHwData );
246 psLOCAL->RadioOffStatus.boHwRadioOff = !!HwRadioOff;
248 hal_set_radio_mode( pHwData, (unsigned char)(psLOCAL->RadioOffStatus.boSwRadioOff || psLOCAL->RadioOffStatus.boHwRadioOff) );
250 hal_driver_init_OK(pHwData) = 1; // Notify hal that the driver is ready now.
251 //set a tx power for reference.....
252 // sme_set_tx_power_level(Adapter, 12); FIXME?
259 case 3: Mds_Destroy( Adapter );
261 case 1: WBLINUX_Destroy( Adapter );
262 hal_halt( pHwData, NULL );
269 void WBLINUX_ConnectStatus(PADAPTER Adapter, u32 flag)
271 PWBLINUX pWbLinux = &Adapter->WbLinux;
273 pWbLinux->LinkStatus = flag; // OS_DISCONNECTED or OS_CONNECTED