]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/winbond/wblinux.c
Staging: w35und: remove some dead code
[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 wb35_adapter * adapter)
21 {
22         spin_lock_init( &adapter->SpinLock );
23         return true;
24 }
25
26 void
27 WBLINUX_Destroy(struct wb35_adapter * 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 wb35_adapter * 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 wb35_adapter *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 wb35_adapter *adapter)
89 {
90         phw_data_t      pHwData;
91         u8              *pMacAddr;
92         u8              *pMacAddr2;
93         u32             InitStep = 0;
94         u8              EEPROM_region;
95         u8              HwRadioOff;
96
97         //
98         // Setting default value for Linux
99         //
100         adapter->sLocalPara.region_INF = REGION_AUTO;
101         adapter->sLocalPara.TxRateMode = RATE_AUTO;
102         psLOCAL->bMacOperationMode = MODE_802_11_BG;    // B/G mode
103         adapter->Mds.TxRTSThreshold = DEFAULT_RTSThreshold;
104         adapter->Mds.TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
105         hal_set_phy_type( &adapter->sHwData, RF_WB_242_1 );
106         adapter->sLocalPara.MTUsize = MAX_ETHERNET_PACKET_SIZE;
107         psLOCAL->bPreambleMode = AUTO_MODE;
108         adapter->sLocalPara.RadioOffStatus.boSwRadioOff = false;
109         pHwData = &adapter->sHwData;
110         hal_set_phy_type( pHwData, RF_DECIDE_BY_INF );
111
112         //
113         // Initial each module and variable
114         //
115         if (!WBLINUX_Initial(adapter)) {
116 #ifdef _PE_USB_INI_DUMP_
117                 WBDEBUG(("[w35und]WBNDIS initialization failed\n"));
118 #endif
119                 goto error;
120         }
121
122         // Initial Software variable
123         adapter->sLocalPara.ShutDowned = false;
124
125         //added by ws for wep key error detection
126         adapter->sLocalPara.bWepKeyError= false;
127         adapter->sLocalPara.bToSelfPacketReceived = false;
128         adapter->sLocalPara.WepKeyDetectTimerCount= 2 * 100; /// 2 seconds
129
130         // Initial USB hal
131         InitStep = 1;
132         pHwData = &adapter->sHwData;
133         if (!hal_init_hardware(pHwData, adapter))
134                 goto error;
135
136         EEPROM_region = hal_get_region_from_EEPROM( pHwData );
137         if (EEPROM_region != REGION_AUTO)
138                 psLOCAL->region = EEPROM_region;
139         else {
140                 if (psLOCAL->region_INF != REGION_AUTO)
141                         psLOCAL->region = psLOCAL->region_INF;
142                 else
143                         psLOCAL->region = REGION_USA;   //default setting
144         }
145
146         // Get Software setting flag from hal
147         adapter->sLocalPara.boAntennaDiversity = false;
148         if (hal_software_set(pHwData) & 0x00000001)
149                 adapter->sLocalPara.boAntennaDiversity = true;
150
151         //
152         // For TS module
153         //
154         InitStep = 2;
155
156         // For MDS module
157         InitStep = 3;
158         Mds_initial(adapter);
159
160         //=======================================
161         // Initialize the SME, SCAN, MLME, ROAM
162         //=======================================
163         InitStep = 4;
164         InitStep = 5;
165         InitStep = 6;
166
167         // If no user-defined address in the registry, use the addresss "burned" on the NIC instead.
168         pMacAddr = adapter->sLocalPara.ThisMacAddress;
169         pMacAddr2 = adapter->sLocalPara.PermanentAddress;
170         hal_get_permanent_address( pHwData, adapter->sLocalPara.PermanentAddress );// Reading ethernet address from EEPROM
171         if (memcmp(pMacAddr, "\x00\x00\x00\x00\x00\x00", MAC_ADDR_LENGTH) == 0)
172                 memcpy(pMacAddr, pMacAddr2, MAC_ADDR_LENGTH);
173         else {
174                 // Set the user define MAC address
175                 hal_set_ethernet_address(pHwData, adapter->sLocalPara.ThisMacAddress);
176         }
177
178         //get current antenna
179         psLOCAL->bAntennaNo = hal_get_antenna_number(pHwData);
180 #ifdef _PE_STATE_DUMP_
181         WBDEBUG(("Driver init, antenna no = %d\n", psLOCAL->bAntennaNo));
182 #endif
183         hal_get_hw_radio_off( pHwData );
184
185         // Waiting for HAL setting OK
186         while (!hal_idle(pHwData))
187                 msleep(10);
188
189         MTO_Init(adapter);
190
191         HwRadioOff = hal_get_hw_radio_off( pHwData );
192         psLOCAL->RadioOffStatus.boHwRadioOff = !!HwRadioOff;
193
194         hal_set_radio_mode( pHwData, (unsigned char)(psLOCAL->RadioOffStatus.boSwRadioOff || psLOCAL->RadioOffStatus.boHwRadioOff) );
195
196         hal_driver_init_OK(pHwData) = 1; // Notify hal that the driver is ready now.
197         //set a tx power for reference.....
198 //      sme_set_tx_power_level(adapter, 12);    FIXME?
199         return true;
200
201 error:
202         switch (InitStep) {
203         case 5:
204         case 4:
205         case 3: Mds_Destroy( adapter );
206         case 2:
207         case 1: WBLINUX_Destroy( adapter );
208                 hal_halt( pHwData, NULL );
209         case 0: break;
210         }
211
212         return false;
213 }