]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/winbond/wblinux.c
Staging: w35und: remove global struct ieee80211_hw
[linux-2.6-omap-h63xx.git] / 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 <linux/netdevice.h>
12
13 #include "mds_f.h"
14 #include "mto_f.h"
15 #include "os_common.h"
16 #include "wbhal_f.h"
17 #include "wblinux_f.h"
18
19 unsigned char
20 WBLINUX_Initial(struct wbsoft_priv * adapter)
21 {
22         spin_lock_init( &adapter->SpinLock );
23         return true;
24 }
25
26 void
27 WBLINUX_Destroy(struct wbsoft_priv * adapter)
28 {
29         WBLINUX_stop( adapter );
30 #ifdef _PE_USB_INI_DUMP_
31         WBDEBUG(("[w35und] unregister_netdev!\n"));
32 #endif
33 }
34
35 void
36 WBLINUX_stop(  struct wbsoft_priv * adapter )
37 {
38         struct sk_buff *pSkb;
39
40         if (atomic_inc_return(&adapter->ThreadCount) == 1) {
41                 // Shutdown module immediately
42                 adapter->shutdown = 1;
43
44                 while (adapter->skb_array[ adapter->skb_GetIndex ]) {
45                         // Trying to free the un-sending packet
46                         pSkb = adapter->skb_array[ adapter->skb_GetIndex ];
47                         adapter->skb_array[ adapter->skb_GetIndex ] = NULL;
48                         if( in_irq() )
49                                 dev_kfree_skb_irq( pSkb );
50                         else
51                                 dev_kfree_skb( pSkb );
52
53                         adapter->skb_GetIndex++;
54                         adapter->skb_GetIndex %= WBLINUX_PACKET_ARRAY_SIZE;
55                 }
56
57 #ifdef _PE_STATE_DUMP_
58                 WBDEBUG(( "[w35und] SKB_RELEASE OK\n" ));
59 #endif
60         }
61
62         atomic_dec(&adapter->ThreadCount);
63 }
64
65 void
66 WbWlanHalt(  struct wbsoft_priv * adapter )
67 {
68         //---------------------
69         adapter->sLocalPara.ShutDowned = true;
70
71         Mds_Destroy(adapter);
72
73         // Turn off Rx and Tx hardware ability
74         hal_stop(&adapter->sHwData);
75 #ifdef _PE_USB_INI_DUMP_
76         WBDEBUG(("[w35und] Hal_stop O.K.\n"));
77 #endif
78         msleep(100);// Waiting Irp completed
79
80         // Destroy the NDIS module
81         WBLINUX_Destroy(adapter);
82
83         // Halt the HAL
84         hal_halt(&adapter->sHwData, NULL);
85 }
86
87 unsigned char
88 WbWLanInitialize(struct ieee80211_hw *hw)
89 {
90         struct wbsoft_priv *priv = hw->priv;
91         phw_data_t      pHwData;
92         u8              *pMacAddr;
93         u8              *pMacAddr2;
94         u32             InitStep = 0;
95         u8              EEPROM_region;
96         u8              HwRadioOff;
97
98         //
99         // Setting default value for Linux
100         //
101         priv->sLocalPara.region_INF = REGION_AUTO;
102         priv->sLocalPara.TxRateMode = RATE_AUTO;
103         priv->sLocalPara.bMacOperationMode = MODE_802_11_BG;    // B/G mode
104         priv->Mds.TxRTSThreshold = DEFAULT_RTSThreshold;
105         priv->Mds.TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
106         hal_set_phy_type( &priv->sHwData, RF_WB_242_1 );
107         priv->sLocalPara.MTUsize = MAX_ETHERNET_PACKET_SIZE;
108         priv->sLocalPara.bPreambleMode = AUTO_MODE;
109         priv->sLocalPara.RadioOffStatus.boSwRadioOff = false;
110         pHwData = &priv->sHwData;
111         hal_set_phy_type( pHwData, RF_DECIDE_BY_INF );
112
113         //
114         // Initial each module and variable
115         //
116         if (!WBLINUX_Initial(priv)) {
117 #ifdef _PE_USB_INI_DUMP_
118                 WBDEBUG(("[w35und]WBNDIS initialization failed\n"));
119 #endif
120                 goto error;
121         }
122
123         // Initial Software variable
124         priv->sLocalPara.ShutDowned = false;
125
126         //added by ws for wep key error detection
127         priv->sLocalPara.bWepKeyError= false;
128         priv->sLocalPara.bToSelfPacketReceived = false;
129         priv->sLocalPara.WepKeyDetectTimerCount= 2 * 100; /// 2 seconds
130
131         // Initial USB hal
132         InitStep = 1;
133         pHwData = &priv->sHwData;
134         if (!hal_init_hardware(hw))
135                 goto error;
136
137         EEPROM_region = hal_get_region_from_EEPROM( pHwData );
138         if (EEPROM_region != REGION_AUTO)
139                 priv->sLocalPara.region = EEPROM_region;
140         else {
141                 if (priv->sLocalPara.region_INF != REGION_AUTO)
142                         priv->sLocalPara.region = priv->sLocalPara.region_INF;
143                 else
144                         priv->sLocalPara.region = REGION_USA;   //default setting
145         }
146
147         // Get Software setting flag from hal
148         priv->sLocalPara.boAntennaDiversity = false;
149         if (hal_software_set(pHwData) & 0x00000001)
150                 priv->sLocalPara.boAntennaDiversity = true;
151
152         //
153         // For TS module
154         //
155         InitStep = 2;
156
157         // For MDS module
158         InitStep = 3;
159         Mds_initial(priv);
160
161         //=======================================
162         // Initialize the SME, SCAN, MLME, ROAM
163         //=======================================
164         InitStep = 4;
165         InitStep = 5;
166         InitStep = 6;
167
168         // If no user-defined address in the registry, use the addresss "burned" on the NIC instead.
169         pMacAddr = priv->sLocalPara.ThisMacAddress;
170         pMacAddr2 = priv->sLocalPara.PermanentAddress;
171         hal_get_permanent_address( pHwData, priv->sLocalPara.PermanentAddress );// Reading ethernet address from EEPROM
172         if (memcmp(pMacAddr, "\x00\x00\x00\x00\x00\x00", MAC_ADDR_LENGTH) == 0)
173                 memcpy(pMacAddr, pMacAddr2, MAC_ADDR_LENGTH);
174         else {
175                 // Set the user define MAC address
176                 hal_set_ethernet_address(pHwData, priv->sLocalPara.ThisMacAddress);
177         }
178
179         //get current antenna
180         priv->sLocalPara.bAntennaNo = hal_get_antenna_number(pHwData);
181 #ifdef _PE_STATE_DUMP_
182         WBDEBUG(("Driver init, antenna no = %d\n", psLOCAL->bAntennaNo));
183 #endif
184         hal_get_hw_radio_off( pHwData );
185
186         // Waiting for HAL setting OK
187         while (!hal_idle(pHwData))
188                 msleep(10);
189
190         MTO_Init(priv);
191
192         HwRadioOff = hal_get_hw_radio_off( pHwData );
193         priv->sLocalPara.RadioOffStatus.boHwRadioOff = !!HwRadioOff;
194
195         hal_set_radio_mode( pHwData, (unsigned char)(priv->sLocalPara.RadioOffStatus.boSwRadioOff || priv->sLocalPara.RadioOffStatus.boHwRadioOff) );
196
197         hal_driver_init_OK(pHwData) = 1; // Notify hal that the driver is ready now.
198         //set a tx power for reference.....
199 //      sme_set_tx_power_level(priv, 12);       FIXME?
200         return true;
201
202 error:
203         switch (InitStep) {
204         case 5:
205         case 4:
206         case 3: Mds_Destroy( priv );
207         case 2:
208         case 1: WBLINUX_Destroy( priv );
209                 hal_halt( pHwData, NULL );
210         case 0: break;
211         }
212
213         return false;
214 }