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
)
152 // Setting default value for Linux
154 Adapter
->sLocalPara
.region_INF
= REGION_AUTO
;
155 Adapter
->sLocalPara
.TxRateMode
= RATE_AUTO
;
156 psLOCAL
->bMacOperationMode
= MODE_802_11_BG
; // B/G mode
157 Adapter
->Mds
.TxRTSThreshold
= DEFAULT_RTSThreshold
;
158 Adapter
->Mds
.TxFragmentThreshold
= DEFAULT_FRAGMENT_THRESHOLD
;
159 hal_set_phy_type( &Adapter
->sHwData
, RF_WB_242_1
);
160 Adapter
->sLocalPara
.MTUsize
= MAX_ETHERNET_PACKET_SIZE
;
161 psLOCAL
->bPreambleMode
= AUTO_MODE
;
162 Adapter
->sLocalPara
.RadioOffStatus
.boSwRadioOff
= FALSE
;
163 pHwData
= &Adapter
->sHwData
;
164 hal_set_phy_type( pHwData
, RF_DECIDE_BY_INF
);
167 // Initial each module and variable
169 if (!WBLINUX_Initial(Adapter
)) {
170 #ifdef _PE_USB_INI_DUMP_
171 WBDEBUG(("[w35und]WBNDIS initialization failed\n"));
176 // Initial Software variable
177 Adapter
->sLocalPara
.ShutDowned
= FALSE
;
179 //added by ws for wep key error detection
180 Adapter
->sLocalPara
.bWepKeyError
= FALSE
;
181 Adapter
->sLocalPara
.bToSelfPacketReceived
= FALSE
;
182 Adapter
->sLocalPara
.WepKeyDetectTimerCount
= 2 * 100; /// 2 seconds
186 pHwData
= &Adapter
->sHwData
;
187 if (!hal_init_hardware(pHwData
, Adapter
))
190 EEPROM_region
= hal_get_region_from_EEPROM( pHwData
);
191 if (EEPROM_region
!= REGION_AUTO
)
192 psLOCAL
->region
= EEPROM_region
;
194 if (psLOCAL
->region_INF
!= REGION_AUTO
)
195 psLOCAL
->region
= psLOCAL
->region_INF
;
197 psLOCAL
->region
= REGION_USA
; //default setting
200 // Get Software setting flag from hal
201 Adapter
->sLocalPara
.boAntennaDiversity
= FALSE
;
202 if (hal_software_set(pHwData
) & 0x00000001)
203 Adapter
->sLocalPara
.boAntennaDiversity
= TRUE
;
212 Mds_initial(Adapter
);
214 //=======================================
215 // Initialize the SME, SCAN, MLME, ROAM
216 //=======================================
221 // If no user-defined address in the registry, use the addresss "burned" on the NIC instead.
222 pMacAddr
= Adapter
->sLocalPara
.ThisMacAddress
;
223 pMacAddr2
= Adapter
->sLocalPara
.PermanentAddress
;
224 hal_get_permanent_address( pHwData
, Adapter
->sLocalPara
.PermanentAddress
);// Reading ethernet address from EEPROM
225 if (OS_MEMORY_COMPARE(pMacAddr
, "\x00\x00\x00\x00\x00\x00", MAC_ADDR_LENGTH
)) // Is equal
227 memcpy( pMacAddr
, pMacAddr2
, MAC_ADDR_LENGTH
);
229 // Set the user define MAC address
230 hal_set_ethernet_address( pHwData
, Adapter
->sLocalPara
.ThisMacAddress
);
233 //get current antenna
234 psLOCAL
->bAntennaNo
= hal_get_antenna_number(pHwData
);
235 #ifdef _PE_STATE_DUMP_
236 WBDEBUG(("Driver init, antenna no = %d\n", psLOCAL
->bAntennaNo
));
238 hal_get_hw_radio_off( pHwData
);
240 // Waiting for HAL setting OK
241 while (!hal_idle(pHwData
))
246 HwRadioOff
= hal_get_hw_radio_off( pHwData
);
247 psLOCAL
->RadioOffStatus
.boHwRadioOff
= !!HwRadioOff
;
249 hal_set_radio_mode( pHwData
, (unsigned char)(psLOCAL
->RadioOffStatus
.boSwRadioOff
|| psLOCAL
->RadioOffStatus
.boHwRadioOff
) );
251 hal_driver_init_OK(pHwData
) = 1; // Notify hal that the driver is ready now.
252 //set a tx power for reference.....
253 // sme_set_tx_power_level(Adapter, 12); FIXME?
261 case 3: Mds_Destroy( Adapter
);
263 case 1: WBLINUX_Destroy( Adapter
);
264 hal_halt( pHwData
, NULL
);
271 void WBLINUX_ConnectStatus(PADAPTER Adapter
, u32 flag
)
273 PWBLINUX pWbLinux
= &Adapter
->WbLinux
;
275 pWbLinux
->LinkStatus
= flag
; // OS_DISCONNECTED or OS_CONNECTED