summaryrefslogtreecommitdiff
path: root/drivers/staging/winbond/wblinux.c
blob: 2eade5a47b198aa61e671b1085b7fde258f5e4c4 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//============================================================================
//  Copyright (c) 1996-2005 Winbond Electronic Corporation
//
//  Module Name:
//    wblinux.c
//
//  Abstract:
//    Linux releated routines
//
//============================================================================
#include "os_common.h"

u32
WBLINUX_MemoryAlloc(void* *VirtualAddress, u32 Length)
{
	*VirtualAddress = kzalloc( Length, GFP_ATOMIC ); //GFP_KERNEL is not suitable

	if (*VirtualAddress == NULL)
		return 0;
	return 1;
}

s32
EncapAtomicInc(PADAPTER Adapter, void* pAtomic)
{
	PWBLINUX pWbLinux = &Adapter->WbLinux;
	u32	ltmp;
	PULONG	pltmp = (PULONG)pAtomic;
	OS_SPIN_LOCK_ACQUIRED( &pWbLinux->AtomicSpinLock );
	(*pltmp)++;
	ltmp = (*pltmp);
	OS_SPIN_LOCK_RELEASED( &pWbLinux->AtomicSpinLock );
	return ltmp;
}

s32
EncapAtomicDec(PADAPTER Adapter, void* pAtomic)
{
	PWBLINUX pWbLinux = &Adapter->WbLinux;
	u32	ltmp;
	PULONG	pltmp = (PULONG)pAtomic;
	OS_SPIN_LOCK_ACQUIRED( &pWbLinux->AtomicSpinLock );
	(*pltmp)--;
	ltmp = (*pltmp);
	OS_SPIN_LOCK_RELEASED( &pWbLinux->AtomicSpinLock );
	return ltmp;
}

unsigned char
WBLINUX_Initial(PADAPTER Adapter)
{
	PWBLINUX pWbLinux = &Adapter->WbLinux;

	OS_SPIN_LOCK_ALLOCATE( &pWbLinux->SpinLock );
	OS_SPIN_LOCK_ALLOCATE( &pWbLinux->AtomicSpinLock );
	return TRUE;
}

void
WBLinux_ReceivePacket(PADAPTER Adapter, PRXLAYER1 pRxLayer1)
{
	BUG();
}


void
WBLINUX_GetNextPacket(PADAPTER Adapter,  PDESCRIPTOR pDes)
{
	BUG();
}

void
WBLINUX_GetNextPacketCompleted(PADAPTER Adapter, PDESCRIPTOR pDes)
{
	BUG();
}

void
WBLINUX_Destroy(PADAPTER Adapter)
{
	WBLINUX_stop( Adapter );
	OS_SPIN_LOCK_FREE( &pWbNdis->SpinLock );
#ifdef _PE_USB_INI_DUMP_
	WBDEBUG(("[w35und] unregister_netdev!\n"));
#endif
}

void
WBLINUX_stop(  PADAPTER Adapter )
{
	PWBLINUX	pWbLinux = &Adapter->WbLinux;
	struct sk_buff *pSkb;

	if (OS_ATOMIC_INC( Adapter, &pWbLinux->ThreadCount ) == 1) {
		// Shutdown module immediately
		pWbLinux->shutdown = 1;

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

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

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

	OS_ATOMIC_DEC( Adapter, &pWbLinux->ThreadCount );
}

void
WbWlanHalt(  PADAPTER 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
	OS_SLEEP(100000);// Waiting Irp completed

	// Destroy the NDIS module
	WBLINUX_Destroy( Adapter );

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

unsigned char
WbWLanInitialize(PADAPTER Adapter)
{
	phw_data_t	pHwData;
	PUCHAR		pMacAddr, pMacAddr2;
	u32		InitStep = 0;
	u8		EEPROM_region;
	u8		HwRadioOff;

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

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

		// Initial Software variable
		Adapter->sLocalPara.ShutDowned = FALSE;

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

		// Initial USB hal
		InitStep = 1;
		pHwData = &Adapter->sHwData;
		if (!hal_init_hardware(pHwData, Adapter))
			break;

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

		// Get Software setting flag from hal
		Adapter->sLocalPara.boAntennaDiversity = FALSE;
		if (hal_software_set(pHwData) & 0x00000001)
			Adapter->sLocalPara.boAntennaDiversity = TRUE;

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

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

		//=======================================
		// 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 = Adapter->sLocalPara.ThisMacAddress;
		pMacAddr2 = Adapter->sLocalPara.PermanentAddress;
		hal_get_permanent_address( pHwData, Adapter->sLocalPara.PermanentAddress );// Reading ethernet address from EEPROM
		if (OS_MEMORY_COMPARE(pMacAddr, "\x00\x00\x00\x00\x00\x00", MAC_ADDR_LENGTH )) // Is equal
		{
			memcpy( pMacAddr, pMacAddr2, MAC_ADDR_LENGTH );
		} else {
			// Set the user define MAC address
			hal_set_ethernet_address( pHwData, Adapter->sLocalPara.ThisMacAddress );
		}

		//get current antenna
		psLOCAL->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))
			OS_SLEEP(10000);

		MTO_Init(Adapter);

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

		hal_set_radio_mode( pHwData, (unsigned char)(psLOCAL->RadioOffStatus.boSwRadioOff || psLOCAL->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(Adapter, 12);	FIXME?
		return TRUE;
	}
	while(FALSE);

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

	return FALSE;
}

void WBLINUX_ConnectStatus(PADAPTER Adapter, u32 flag)
{
	PWBLINUX	pWbLinux = &Adapter->WbLinux;

	pWbLinux->LinkStatus = flag; // OS_DISCONNECTED	or  OS_CONNECTED
}