Staging: w35und: remove some typedefs
[linux-2.6] / drivers / staging / winbond / wblinux.c
1 //============================================================================
2 //  Copyright (c) 1996-2005 Winbond Electronic Corporation
3 //
4 //  Module Name:
5 //    wblinux.c
6 //
7 //  Abstract:
8 //    Linux releated routines
9 //
10 //============================================================================
11 #include "os_common.h"
12
13 u32
14 WBLINUX_MemoryAlloc(void* *VirtualAddress, u32 Length)
15 {
16         *VirtualAddress = kzalloc( Length, GFP_ATOMIC ); //GFP_KERNEL is not suitable
17
18         if (*VirtualAddress == NULL)
19                 return 0;
20         return 1;
21 }
22
23 s32
24 EncapAtomicInc(PADAPTER Adapter, void* pAtomic)
25 {
26         PWBLINUX pWbLinux = &Adapter->WbLinux;
27         u32     ltmp;
28         u32 *   pltmp = (u32 *)pAtomic;
29         OS_SPIN_LOCK_ACQUIRED( &pWbLinux->AtomicSpinLock );
30         (*pltmp)++;
31         ltmp = (*pltmp);
32         OS_SPIN_LOCK_RELEASED( &pWbLinux->AtomicSpinLock );
33         return ltmp;
34 }
35
36 s32
37 EncapAtomicDec(PADAPTER Adapter, void* pAtomic)
38 {
39         PWBLINUX pWbLinux = &Adapter->WbLinux;
40         u32     ltmp;
41         u32 *   pltmp = (u32 *)pAtomic;
42         OS_SPIN_LOCK_ACQUIRED( &pWbLinux->AtomicSpinLock );
43         (*pltmp)--;
44         ltmp = (*pltmp);
45         OS_SPIN_LOCK_RELEASED( &pWbLinux->AtomicSpinLock );
46         return ltmp;
47 }
48
49 unsigned char
50 WBLINUX_Initial(PADAPTER Adapter)
51 {
52         PWBLINUX pWbLinux = &Adapter->WbLinux;
53
54         OS_SPIN_LOCK_ALLOCATE( &pWbLinux->SpinLock );
55         OS_SPIN_LOCK_ALLOCATE( &pWbLinux->AtomicSpinLock );
56         return TRUE;
57 }
58
59 void
60 WBLinux_ReceivePacket(PADAPTER Adapter, PRXLAYER1 pRxLayer1)
61 {
62         BUG();
63 }
64
65
66 void
67 WBLINUX_GetNextPacket(PADAPTER Adapter,  PDESCRIPTOR pDes)
68 {
69         BUG();
70 }
71
72 void
73 WBLINUX_GetNextPacketCompleted(PADAPTER Adapter, PDESCRIPTOR pDes)
74 {
75         BUG();
76 }
77
78 void
79 WBLINUX_Destroy(PADAPTER Adapter)
80 {
81         WBLINUX_stop( Adapter );
82         OS_SPIN_LOCK_FREE( &pWbNdis->SpinLock );
83 #ifdef _PE_USB_INI_DUMP_
84         WBDEBUG(("[w35und] unregister_netdev!\n"));
85 #endif
86 }
87
88 void
89 WBLINUX_stop(  PADAPTER Adapter )
90 {
91         PWBLINUX        pWbLinux = &Adapter->WbLinux;
92         struct sk_buff *pSkb;
93
94         if (OS_ATOMIC_INC( Adapter, &pWbLinux->ThreadCount ) == 1) {
95                 // Shutdown module immediately
96                 pWbLinux->shutdown = 1;
97
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;
102                         if( in_irq() )
103                                 dev_kfree_skb_irq( pSkb );
104                         else
105                                 dev_kfree_skb( pSkb );
106
107                         pWbLinux->skb_GetIndex++;
108                         pWbLinux->skb_GetIndex %= WBLINUX_PACKET_ARRAY_SIZE;
109                 }
110
111 #ifdef _PE_STATE_DUMP_
112                 WBDEBUG(( "[w35und] SKB_RELEASE OK\n" ));
113 #endif
114         }
115
116         OS_ATOMIC_DEC( Adapter, &pWbLinux->ThreadCount );
117 }
118
119 void
120 WbWlanHalt(  PADAPTER Adapter )
121 {
122         //---------------------
123         Adapter->sLocalPara.ShutDowned = TRUE;
124
125         Mds_Destroy( Adapter );
126
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"));
131 #endif
132         OS_SLEEP(100000);// Waiting Irp completed
133
134         // Destroy the NDIS module
135         WBLINUX_Destroy( Adapter );
136
137         // Halt the HAL
138         hal_halt(&Adapter->sHwData, NULL);
139 }
140
141 unsigned char
142 WbWLanInitialize(PADAPTER Adapter)
143 {
144         phw_data_t      pHwData;
145         u8              *pMacAddr;
146         u8              *pMacAddr2;
147         u32             InitStep = 0;
148         u8              EEPROM_region;
149         u8              HwRadioOff;
150
151         do {
152                 //
153                 // Setting default value for Linux
154                 //
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 );
166
167                 //
168                 // Initial each module and variable
169                 //
170                 if (!WBLINUX_Initial(Adapter)) {
171 #ifdef _PE_USB_INI_DUMP_
172                         WBDEBUG(("[w35und]WBNDIS initialization failed\n"));
173 #endif
174                         break;
175                 }
176
177                 // Initial Software variable
178                 Adapter->sLocalPara.ShutDowned = FALSE;
179
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
184
185                 // Initial USB hal
186                 InitStep = 1;
187                 pHwData = &Adapter->sHwData;
188                 if (!hal_init_hardware(pHwData, Adapter))
189                         break;
190
191                 EEPROM_region = hal_get_region_from_EEPROM( pHwData );
192                 if (EEPROM_region != REGION_AUTO)
193                         psLOCAL->region = EEPROM_region;
194                 else {
195                         if (psLOCAL->region_INF != REGION_AUTO)
196                                 psLOCAL->region = psLOCAL->region_INF;
197                         else
198                                 psLOCAL->region = REGION_USA;   //default setting
199                 }
200
201                 // Get Software setting flag from hal
202                 Adapter->sLocalPara.boAntennaDiversity = FALSE;
203                 if (hal_software_set(pHwData) & 0x00000001)
204                         Adapter->sLocalPara.boAntennaDiversity = TRUE;
205
206                 //
207                 // For TS module
208                 //
209                 InitStep = 2;
210
211                 // For MDS module
212                 InitStep = 3;
213                 Mds_initial(Adapter);
214
215                 //=======================================
216                 // Initialize the SME, SCAN, MLME, ROAM
217                 //=======================================
218                 InitStep = 4;
219                 InitStep = 5;
220                 InitStep = 6;
221
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
227                 {
228                         memcpy( pMacAddr, pMacAddr2, MAC_ADDR_LENGTH );
229                 } else {
230                         // Set the user define MAC address
231                         hal_set_ethernet_address( pHwData, Adapter->sLocalPara.ThisMacAddress );
232                 }
233
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));
238 #endif
239                 hal_get_hw_radio_off( pHwData );
240
241                 // Waiting for HAL setting OK
242                 while (!hal_idle(pHwData))
243                         OS_SLEEP(10000);
244
245                 MTO_Init(Adapter);
246
247                 HwRadioOff = hal_get_hw_radio_off( pHwData );
248                 psLOCAL->RadioOffStatus.boHwRadioOff = !!HwRadioOff;
249
250                 hal_set_radio_mode( pHwData, (unsigned char)(psLOCAL->RadioOffStatus.boSwRadioOff || psLOCAL->RadioOffStatus.boHwRadioOff) );
251
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?
255                 return TRUE;
256         }
257         while(FALSE);
258
259         switch (InitStep) {
260         case 5:
261         case 4:
262         case 3: Mds_Destroy( Adapter );
263         case 2:
264         case 1: WBLINUX_Destroy( Adapter );
265                 hal_halt( pHwData, NULL );
266         case 0: break;
267         }
268
269         return FALSE;
270 }
271
272 void WBLINUX_ConnectStatus(PADAPTER Adapter, u32 flag)
273 {
274         PWBLINUX        pWbLinux = &Adapter->WbLinux;
275
276         pWbLinux->LinkStatus = flag; // OS_DISCONNECTED or  OS_CONNECTED
277 }
278