aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging/winbond/wblinux.c
blob: 03458bcd827b130e6efb07a620770ef4115832c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//============================================================================
//  Copyright (c) 1996-2005 Winbond Electronic Corporation
//
//  Module Name:
//    wblinux.c
//
//  Abstract:
//    Linux releated routines
//
//============================================================================
#include <linux/netdevice.h>

#include "mds_f.h"
#include "mto_f.h"
#include "os_common.h"
#include "wbhal_f.h"
#include "wblinux_f.h"

unsigned char
WBLINUX_Initial(struct wbsoft_priv * adapter)
{
	spin_lock_init( &adapter->SpinLock );
	return true;
}

void
WBLINUX_Destroy(struct wbsoft_priv * adapter)
{
	WBLINUX_stop( adapter );
#ifdef _PE_USB_INI_DUMP_
	WBDEBUG(("[w35und] unregister_netdev!\n"));
#endif
}

void
WBLINUX_stop(  struct wbsoft_priv * adapter )
{
	struct sk_buff *pSkb;

	if (atomic_inc_return(&adapter->ThreadCount) == 1) {
		// Shutdown module immediately
		adapter->shutdown = 1;

		while (adapter->skb_array[ adapter->skb_GetIndex ]) {
			// Trying to free the un-sending packet
			pSkb = adapter->skb_array[ adapter->skb_GetIndex ];
			adapter->skb_array[ adapter->skb_GetIndex ] = NULL;
			if( in_irq() )
				dev_kfree_skb_irq( pSkb );
			else
				dev_kfree_skb( pSkb );

			adapter->skb_GetIndex++;
			adapter->skb_GetIndex %= WBLINUX_PACKET_ARRAY_SIZE;
		}

#ifdef _PE_STATE_DUMP_
		WBDEBUG(( "[w35und] SKB_RELEASE OK\n" ));
#endif
	}

	atomic_dec(&adapter->ThreadCount);
}

void
WbWlanHalt(  struct wbsoft_priv * adapter )
{
	//---------------------
	adapter->sLocalPara.ShutDowned = true;

	Mds_Destroy(adapter);

	// Turn off Rx and Tx hardware ability
	hal_stop(&adapter->sHwData);
#ifdef _PE_USB_INI_DUMP_
	WBDEBUG(("[w35und] Hal_stop O.K.\n"));
#endif
	msleep(100);// Waiting Irp completed

	// Destroy the NDIS module
	WBLINUX_Destroy(adapter);

	// Halt the HAL
	hal_halt(&adapter->sHwData, NULL);
}

unsigned char
WbWLanInitialize(struct ieee80211_hw *hw)
{
	struct wbsoft_priv *priv = hw->priv;
	phw_data_t	pHwData;
	u8		*pMacAddr;
	u8		*pMacAddr2;
	u32		InitStep = 0;
	u8		EEPROM_region;
	u8		HwRadioOff;

	//
	// Setting default value for Linux
	//
	priv->sLocalPara.region_INF = REGION_AUTO;
	priv->sLocalPara.TxRateMode = RATE_AUTO;
	priv->sLocalPara.bMacOperationMode = MODE_802_11_BG;	// B/G mode
	priv->Mds.TxRTSThreshold = DEFAULT_RTSThreshold;
	priv->Mds.TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
	hal_set_phy_type( &priv->sHwData, RF_WB_242_1 );
	priv->sLocalPara.MTUsize = MAX_ETHERNET_PACKET_SIZE;
	priv->sLocalPara.bPreambleMode = AUTO_MODE;
	priv->sLocalPara.RadioOffStatus.boSwRadioOff = false;
	pHwData = &priv->sHwData;
	hal_set_phy_type( pHwData, RF_DECIDE_BY_INF );

	//
	// Initial each module and variable
	//
	if (!WBLINUX_Initial(priv)) {
#ifdef _PE_USB_INI_DUMP_
		WBDEBUG(("[w35und]WBNDIS initialization failed\n"));
#endif
		goto error;
	}

	// Initial Software variable
	priv->sLocalPara.ShutDowned = false;

	//added by ws for wep key error detection
	priv->sLocalPara.bWepKeyError= false;
	priv->sLocalPara.bToSelfPacketReceived = false;
	priv->sLocalPara.WepKeyDetectTimerCount= 2 * 100; /// 2 seconds

	// Initial USB hal
	InitStep = 1;
	pHwData = &priv->sHwData;
	if (!hal_init_hardware(hw))
		goto error;

	EEPROM_region = hal_get_region_from_EEPROM( pHwData );
	if (EEPROM_region != REGION_AUTO)
		priv->sLocalPara.region = EEPROM_region;
	else {
		if (priv->sLocalPara.region_INF != REGION_AUTO)
			priv->sLocalPara.region = priv->sLocalPara.region_INF;
		else
			priv->sLocalPara.region = REGION_USA;	//default setting
	}

	// Get Software setting flag from hal
	priv->sLocalPara.boAntennaDiversity = false;
	if (hal_software_set(pHwData) & 0x00000001)
		priv->sLocalPara.boAntennaDiversity = true;

	//
	// For TS module
	//
	InitStep = 2;

	// For MDS module
	InitStep = 3;
	Mds_initial(priv);

	//=======================================
	// Initialize the SME, SCAN, MLME, ROAM
	//=======================================
	InitStep = 4;
	InitStep = 5;
	InitStep = 6;

	// If no user-defined address in the registry, use the addresss "burned" on the NIC instead.
	pMacAddr = priv->sLocalPara.ThisMacAddress;
	pMacAddr2 = priv->sLocalPara.PermanentAddress;
	hal_get_permanent_address( pHwData, priv->sLocalPara.PermanentAddress );// Reading ethernet address from EEPROM
	if (memcmp(pMacAddr, "\x00\x00\x00\x00\x00\x00", MAC_ADDR_LENGTH) == 0)
		memcpy(pMacAddr, pMacAddr2, MAC_ADDR_LENGTH);
	else {
		// Set the user define MAC address
		hal_set_ethernet_address(pHwData, priv->sLocalPara.ThisMacAddress);
	}

	//get current antenna
	priv->sLocalPara.bAntennaNo = hal_get_antenna_number(pHwData);
#ifdef _PE_STATE_DUMP_
	WBDEBUG(("Driver init, antenna no = %d\n", psLOCAL->bAntennaNo));
#endif
	hal_get_hw_radio_off( pHwData );

	// Waiting for HAL setting OK
	while (!hal_idle(pHwData))
		msleep(10);

	MTO_Init(priv);

	HwRadioOff = hal_get_hw_radio_off( pHwData );
	priv->sLocalPara.RadioOffStatus.boHwRadioOff = !!HwRadioOff;

	hal_set_radio_mode( pHwData, (unsigned char)(priv->sLocalPara.RadioOffStatus.boSwRadioOff || priv->sLocalPara.RadioOffStatus.boHwRadioOff) );

	hal_driver_init_OK(pHwData) = 1; // Notify hal that the driver is ready now.
	//set a tx power for reference.....
//	sme_set_tx_power_level(priv, 12);	FIXME?
	return true;

error:
	switch (InitStep) {
	case 5:
	case 4:
	case 3: Mds_Destroy( priv );
	case 2:
	case 1: WBLINUX_Destroy( priv );
		hal_halt( pHwData, NULL );
	case 0: break;
	}

	return false;
}