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(struct wb35_adapter * adapter, void* pAtomic)
27 u32 * pltmp = (u32 *)pAtomic;
28 spin_lock_irq( &adapter->AtomicSpinLock );
31 spin_unlock_irq( &adapter->AtomicSpinLock );
36 EncapAtomicDec(struct wb35_adapter * adapter, void* pAtomic)
39 u32 * pltmp = (u32 *)pAtomic;
40 spin_lock_irq( &adapter->AtomicSpinLock );
43 spin_unlock_irq( &adapter->AtomicSpinLock );
48 WBLINUX_Initial(struct wb35_adapter * adapter)
50 spin_lock_init( &adapter->SpinLock );
51 spin_lock_init( &adapter->AtomicSpinLock );
56 WBLinux_ReceivePacket(struct wb35_adapter * adapter, PRXLAYER1 pRxLayer1)
63 WBLINUX_GetNextPacket(struct wb35_adapter * adapter, PDESCRIPTOR pDes)
69 WBLINUX_GetNextPacketCompleted(struct wb35_adapter * adapter, PDESCRIPTOR pDes)
75 WBLINUX_Destroy(struct wb35_adapter * adapter)
77 WBLINUX_stop( adapter );
78 #ifdef _PE_USB_INI_DUMP_
79 WBDEBUG(("[w35und] unregister_netdev!\n"));
84 WBLINUX_stop( struct wb35_adapter * adapter )
88 if (OS_ATOMIC_INC( adapter, &adapter->ThreadCount ) == 1) {
89 // Shutdown module immediately
90 adapter->shutdown = 1;
92 while (adapter->skb_array[ adapter->skb_GetIndex ]) {
93 // Trying to free the un-sending packet
94 pSkb = adapter->skb_array[ adapter->skb_GetIndex ];
95 adapter->skb_array[ adapter->skb_GetIndex ] = NULL;
97 dev_kfree_skb_irq( pSkb );
99 dev_kfree_skb( pSkb );
101 adapter->skb_GetIndex++;
102 adapter->skb_GetIndex %= WBLINUX_PACKET_ARRAY_SIZE;
105 #ifdef _PE_STATE_DUMP_
106 WBDEBUG(( "[w35und] SKB_RELEASE OK\n" ));
110 OS_ATOMIC_DEC(adapter, &adapter->ThreadCount);
114 WbWlanHalt(struct wb35_adapter *adapter)
116 //---------------------
117 adapter->sLocalPara.ShutDowned = TRUE;
119 Mds_Destroy(adapter);
121 // Turn off Rx and Tx hardware ability
122 hal_stop(&adapter->sHwData);
123 #ifdef _PE_USB_INI_DUMP_
124 WBDEBUG(("[w35und] Hal_stop O.K.\n"));
126 msleep(100);// Waiting Irp completed
128 // Destroy the NDIS module
129 WBLINUX_Destroy(adapter);
132 hal_halt(&adapter->sHwData, NULL);
136 WbWLanInitialize(struct wb35_adapter *adapter)
146 // Setting default value for Linux
148 adapter->sLocalPara.region_INF = REGION_AUTO;
149 adapter->sLocalPara.TxRateMode = RATE_AUTO;
150 psLOCAL->bMacOperationMode = MODE_802_11_BG; // B/G mode
151 adapter->Mds.TxRTSThreshold = DEFAULT_RTSThreshold;
152 adapter->Mds.TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
153 hal_set_phy_type( &adapter->sHwData, RF_WB_242_1 );
154 adapter->sLocalPara.MTUsize = MAX_ETHERNET_PACKET_SIZE;
155 psLOCAL->bPreambleMode = AUTO_MODE;
156 adapter->sLocalPara.RadioOffStatus.boSwRadioOff = FALSE;
157 pHwData = &adapter->sHwData;
158 hal_set_phy_type( pHwData, RF_DECIDE_BY_INF );
161 // Initial each module and variable
163 if (!WBLINUX_Initial(adapter)) {
164 #ifdef _PE_USB_INI_DUMP_
165 WBDEBUG(("[w35und]WBNDIS initialization failed\n"));
170 // Initial Software variable
171 adapter->sLocalPara.ShutDowned = FALSE;
173 //added by ws for wep key error detection
174 adapter->sLocalPara.bWepKeyError= FALSE;
175 adapter->sLocalPara.bToSelfPacketReceived = FALSE;
176 adapter->sLocalPara.WepKeyDetectTimerCount= 2 * 100; /// 2 seconds
180 pHwData = &adapter->sHwData;
181 if (!hal_init_hardware(pHwData, adapter))
184 EEPROM_region = hal_get_region_from_EEPROM( pHwData );
185 if (EEPROM_region != REGION_AUTO)
186 psLOCAL->region = EEPROM_region;
188 if (psLOCAL->region_INF != REGION_AUTO)
189 psLOCAL->region = psLOCAL->region_INF;
191 psLOCAL->region = REGION_USA; //default setting
194 // Get Software setting flag from hal
195 adapter->sLocalPara.boAntennaDiversity = FALSE;
196 if (hal_software_set(pHwData) & 0x00000001)
197 adapter->sLocalPara.boAntennaDiversity = TRUE;
206 Mds_initial(adapter);
208 //=======================================
209 // Initialize the SME, SCAN, MLME, ROAM
210 //=======================================
215 // If no user-defined address in the registry, use the addresss "burned" on the NIC instead.
216 pMacAddr = adapter->sLocalPara.ThisMacAddress;
217 pMacAddr2 = adapter->sLocalPara.PermanentAddress;
218 hal_get_permanent_address( pHwData, adapter->sLocalPara.PermanentAddress );// Reading ethernet address from EEPROM
219 if (OS_MEMORY_COMPARE(pMacAddr, "\x00\x00\x00\x00\x00\x00", MAC_ADDR_LENGTH )) // Is equal
221 memcpy( pMacAddr, pMacAddr2, MAC_ADDR_LENGTH );
223 // Set the user define MAC address
224 hal_set_ethernet_address( pHwData, adapter->sLocalPara.ThisMacAddress );
227 //get current antenna
228 psLOCAL->bAntennaNo = hal_get_antenna_number(pHwData);
229 #ifdef _PE_STATE_DUMP_
230 WBDEBUG(("Driver init, antenna no = %d\n", psLOCAL->bAntennaNo));
232 hal_get_hw_radio_off( pHwData );
234 // Waiting for HAL setting OK
235 while (!hal_idle(pHwData))
240 HwRadioOff = hal_get_hw_radio_off( pHwData );
241 psLOCAL->RadioOffStatus.boHwRadioOff = !!HwRadioOff;
243 hal_set_radio_mode( pHwData, (unsigned char)(psLOCAL->RadioOffStatus.boSwRadioOff || psLOCAL->RadioOffStatus.boHwRadioOff) );
245 hal_driver_init_OK(pHwData) = 1; // Notify hal that the driver is ready now.
246 //set a tx power for reference.....
247 // sme_set_tx_power_level(adapter, 12); FIXME?
254 case 3: Mds_Destroy( adapter );
256 case 1: WBLINUX_Destroy( adapter );
257 hal_halt( pHwData, NULL );
264 void WBLINUX_ConnectStatus(struct wb35_adapter * adapter, u32 flag)
266 adapter->LinkStatus = flag; // OS_DISCONNECTED or OS_CONNECTED