blob: 06537157dc8a1d18ef2adcb5effb74f6396b36fb [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Jeff Johnson32d95a32012-09-10 13:15:23 -07002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -07003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 *
24 * Airgo Networks, Inc proprietary. All rights reserved.
25 * macInitApi.c - This file has all the mac level init functions
26 * for all the defined threads at system level.
27 * Author: Dinesh Upadhyay
28 * Date: 04/23/2007
29 * History:-
30 * Date: 04/08/2008 Modified by: Santosh Mandiganal
31 * Modification Information: Code to allocate and free the memory for DumpTable entry.
32 * --------------------------------------------------------------------------
33 *
34 */
35/* Standard include files */
36#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
37
38/* Application Specific include files */
39#include "halInternal.h"
40#include "halHddApis.h"
41#include "halDebug.h"
42#include "halMTU.h"
43#include "halRxp.h"
44#include "halPhyApi.h"
45
46//#ifdef ANI_OS_TYPE_LINUX
47#include "halCommonApi.h" // halCleanup
48#endif
49#include "cfgApi.h" // cfgCleanup
50#include "limApi.h" // limCleanup
51#include "sirTypes.h"
52#include "sysDebug.h"
53#include "sysEntryFunc.h"
54#include "macInitApi.h"
55#if defined(ANI_LOGDUMP)
56#include "logDump.h"
57#endif //#if defined(ANI_LOGDUMP)
58
59#ifdef TRACE_RECORD
60#include "macTrace.h"
61#endif
62
63extern tSirRetStatus halDoCfgInit(tpAniSirGlobal pMac);
64extern tSirRetStatus halProcessStartEvent(tpAniSirGlobal pMac);
65
66
67
68
69tSirRetStatus macReset(tpAniSirGlobal pMac, tANI_U32 rc);
70
71#ifdef FEATURE_WLAN_INTEGRATED_SOC
72tSirRetStatus macPreStart(tHalHandle hHal)
73{
74 tSirRetStatus status = eSIR_SUCCESS;
75 tANI_BOOLEAN memAllocFailed = eANI_BOOLEAN_FALSE;
76 tpAniSirGlobal pMac = (tpAniSirGlobal) hHal;
77 tANI_U8 i;
78
79 for(i=0; i<MAX_DUMP_TABLE_ENTRY; i++)
80 {
81 if(palAllocateMemory(pMac->hHdd, ((void *)&pMac->dumpTableEntry[i]), sizeof(tDumpModuleEntry))
82 != eHAL_STATUS_SUCCESS)
83 {
84 memAllocFailed = eANI_BOOLEAN_TRUE;
85 break;
86 }
87 else
88 {
89 palZeroMemory(pMac->hHdd, pMac->dumpTableEntry[i], sizeof(tSirMbMsg));
90 }
91 }
92 if( memAllocFailed )
93 {
94 while(i>0)
95 {
96 i--;
97 palFreeMemory(pMac, pMac->dumpTableEntry[i]);
98 }
99 sysLog(pMac, LOGE, FL("pMac->dumpTableEntry is NULL\n"));
100 status = eSIR_FAILURE;
101 }
102
103#if defined(ANI_LOGDUMP)
104 //logDumpInit must be called before any module starts
105 logDumpInit(pMac);
106#endif //#if defined(ANI_LOGDUMP)
107
108 return status;
109}
110
111tSirRetStatus macStart(tHalHandle hHal, void* pHalMacStartParams)
112{
113 tSirRetStatus status = eSIR_SUCCESS;
114 tpAniSirGlobal pMac = (tpAniSirGlobal) hHal;
115
116 if (NULL == pMac)
117 {
118 VOS_ASSERT(0);
119 status = eSIR_FAILURE;
120 return status;
121 }
122
123 pMac->gDriverType = ((tHalMacStartParameters*)pHalMacStartParams)->driverType;
124
125 sysLog(pMac, LOG2, FL("called\n"));
126
127 do
128 {
129
130#if defined(TRACE_RECORD)
131 //Enable Tracing
132 macTraceInit(pMac);
133#endif
134
135 if (!HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, ((void *)&pMac->pResetMsg), sizeof(tSirMbMsg))))
136 {
137 sysLog(pMac, LOGE, FL("pMac->pResetMsg is NULL\n"));
138 status = eSIR_FAILURE;
139 break;
140 }
141 else
142 {
143 palZeroMemory(pMac->hHdd, pMac->pResetMsg, sizeof(tSirMbMsg));
144 }
145
146 if (pMac->gDriverType != eDRIVER_TYPE_MFG)
147 {
148 status = peStart(pMac);
149 }
150
151 } while(0);
152 pMac->sys.abort = false;
153
154 return status;
155}
156
157#else /* FEATURE_WLAN_INTEGRATED_SOC */
158tSirRetStatus macStart(tHalHandle hHal, void* pHalMacStartParams)
159{
160 tANI_U8 i;
161 tSirRetStatus status = eSIR_SUCCESS;
162 eHalStatus halStatus;
163 tpAniSirGlobal pMac = (tpAniSirGlobal) hHal;
164 tANI_BOOLEAN memAllocFailed = eANI_BOOLEAN_FALSE;
165
166 if(NULL == pMac)
167 {
168 VOS_ASSERT(0);
169 status = eSIR_FAILURE;
170 return status;
171 }
172
173 pMac->gDriverType = ((tHalMacStartParameters *)pHalMacStartParams)->driverType;
174
175 sysLog(pMac, LOG2, FL("called\n"));
176
177 do
178 {
179 for(i=0; i<MAX_DUMP_TABLE_ENTRY; i++)
180 {
181 if(palAllocateMemory(pMac->hHdd, ((void **)&pMac->dumpTableEntry[i]), sizeof(tDumpModuleEntry))
182 != eHAL_STATUS_SUCCESS)
183 {
184 memAllocFailed = eANI_BOOLEAN_TRUE;
185 break;
186 }
187 else
188 {
189 palZeroMemory(pMac->hHdd, pMac->dumpTableEntry[i], sizeof(tSirMbMsg));
190 }
191 }
192 if( memAllocFailed )
193 {
194 while(i>0)
195 {
196 i--;
197 palFreeMemory(pMac, pMac->dumpTableEntry[i]);
198 }
199 sysLog(pMac, LOGE, FL("pMac->dumpTableEntry is NULL\n"));
200 status = eSIR_FAILURE;
201 break;
202 }
203 else
204 {
205#if defined(ANI_LOGDUMP)
206 logDumpInit(pMac);
207#endif //#if defined(ANI_LOGDUMP)
208 }
209
210#if defined(TRACE_RECORD)
211 //Enable Tracing
212 macTraceInit(pMac);
213#endif
214 if (!HAL_STATUS_SUCCESS(palAllocateMemory(pMac->hHdd, ((void **)&pMac->pResetMsg), sizeof(tSirMbMsg))))
215 {
216 sysLog(pMac, LOGE, FL("pMac->pResetMsg is NULL\n"));
217 status = eSIR_FAILURE;
218 break;
219 }
220 else
221 {
222 palZeroMemory(pMac->hHdd, pMac->pResetMsg, sizeof(tSirMbMsg));
223 }
224
225 halStatus = halStart(hHal, (tHalMacStartParameters*)pHalMacStartParams );
226
227 if ( !HAL_STATUS_SUCCESS(halStatus) )
228 {
229 sysLog(pMac,LOGE, FL("halStart failed with error code = %d\n"), halStatus);
230 status = eSIR_FAILURE;
231 }
232 else if(pMac->gDriverType != eDRIVER_TYPE_MFG)
233 {
234 peStart(pMac);
235 }
236
237 }while(0);
238 pMac->sys.abort = false;
239
240 return status;
241}
242#endif /* FEATURE_WLAN_INTEGRATED_SOC */
243
244/** -------------------------------------------------------------
245\fn macStop
246\brief this function will be called from HDD to stop MAC. This function will stop all the mac modules.
247\ memory with global context will only be initialized not freed here.
248\param tHalHandle hHal
249\param tHalStopType
250\return tSirRetStatus
251 -------------------------------------------------------------*/
252
253tSirRetStatus macStop(tHalHandle hHal, tHalStopType stopType)
254{
255 tANI_U8 i;
256 tpAniSirGlobal pMac = (tpAniSirGlobal) hHal;
257#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
258 halStop(hHal, stopType);
259#endif
260 peStop(pMac);
261 cfgCleanup( pMac );
262 // need to free memory if not called in reset context.
263 // in reset context this memory will be freed by HDD.
264 if(false == pMac->sys.abort)
265 {
266 palFreeMemory(pMac->hHdd, pMac->pResetMsg);
267 pMac->pResetMsg = NULL;
268 }
269 /* Free the DumpTableEntry */
270 for(i=0; i<MAX_DUMP_TABLE_ENTRY; i++)
271 {
272 palFreeMemory(pMac, pMac->dumpTableEntry[i]);
273 }
274
275 return eSIR_SUCCESS;
276}
277
278/** -------------------------------------------------------------
279\fn macOpen
280\brief this function will be called during init. This function is suppose to allocate all the
281\ memory with the global context will be allocated here.
282\param tHalHandle pHalHandle
283\param tHddHandle hHdd
284\param tHalOpenParameters* pHalOpenParams
285\return tSirRetStatus
286 -------------------------------------------------------------*/
287
288tSirRetStatus macOpen(tHalHandle *pHalHandle, tHddHandle hHdd, tMacOpenParameters *pMacOpenParms)
289{
290 tpAniSirGlobal pMac = NULL;
291
292 if(pHalHandle == NULL)
293 return eSIR_FAILURE;
294
295 /*
Jeff Johnsona8a1a482012-12-12 16:49:33 -0800296 * Make sure this adapter is not already opened. (Compare pAdapter pointer in already
Jeff Johnson295189b2012-06-20 16:38:30 -0700297 * allocated pMac structures.)
298 * If it is opened just return pointer to previously allocated pMac pointer.
299 * Or should this result in error?
300 */
301
302 /* Allocate pMac */
303 if (palAllocateMemory(hHdd, ((void **)&pMac), sizeof(tAniSirGlobal)) != eHAL_STATUS_SUCCESS)
304 return eSIR_FAILURE;
305
306 /* Initialize the pMac structure */
307 palZeroMemory(hHdd, pMac, sizeof(tAniSirGlobal));
308
309 /** Store the Driver type in pMac Global.*/
310 //pMac->gDriverType = pMacOpenParms->driverType;
311
312#ifndef GEN6_ONWARDS
313#ifdef RTL8652
314 {
315 //Leverage 8651c's on-chip data scratchpad memory to lock all HAL DxE data there
316 extern void * rtlglue_alloc_data_scratchpad_memory(unsigned int size, char *);
317 pMac->hal.pHalDxe = (tpAniHalDxe) rtlglue_alloc_data_scratchpad_memory(sizeof(tAniHalDxe), "halDxe");
318 }
319 if(pMac->hal.pHalDxe){
320 ;
321 }else
322#endif
323 /* Allocate HalDxe */
324 if (palAllocateMemory(hHdd, ((void **)&pMac->hal.pHalDxe), sizeof(tAniHalDxe)) != eHAL_STATUS_SUCCESS){
325 palFreeMemory(hHdd, pMac);
326 return eSIR_FAILURE;
327 }
328 /* Initialize the HalDxe structure */
329 palZeroMemory(hHdd, pMac->hal.pHalDxe, sizeof(tAniHalDxe));
330#endif //GEN6_ONWARDS
331
332 /*
333 * Set various global fields of pMac here
334 * (Could be platform dependant as some variables in pMac are platform
335 * dependant)
336 */
337 pMac->hHdd = hHdd;
338 pMac->pAdapter = hHdd; //This line wil be removed
339 *pHalHandle = (tHalHandle)pMac;
340
341 {
342 /* Call various PE (and other layer init here) */
Jeff Johnson43971f52012-07-17 12:26:56 -0700343 if( eSIR_SUCCESS != logInit(pMac))
Jeff Johnson295189b2012-06-20 16:38:30 -0700344 return eSIR_FAILURE;
345
346 /* Call routine to initialize CFG data structures */
347 if( eSIR_SUCCESS != cfgInit(pMac) )
348 return eSIR_FAILURE;
349
350 sysInitGlobals(pMac);
351
352#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
353 // This decides whether HW needs to translate the 802.3 frames
354 // from the host OS to the 802.11 frames. When set HW does the
355 // translation from 802.3 to 802.11 and vice versa
356 if(pMacOpenParms->frameTransRequired) {
357 pMac->hal.halMac.frameTransEnabled = 1;
358 } else {
359 pMac->hal.halMac.frameTransEnabled = 0;
360 }
361#endif
362
363 //Need to do it here in case halOpen fails later on.
364#if defined( VOSS_ENABLED )
365 tx_voss_wrapper_init(pMac, hHdd);
366#endif
367 }
368
369#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
370 if (eHAL_STATUS_SUCCESS != halOpen(pMac, pHalHandle, hHdd, pMacOpenParms))
371 return eSIR_FAILURE;
372#endif
373
374 return peOpen(pMac, pMacOpenParms);
375}
376
377/** -------------------------------------------------------------
378\fn macClose
379\brief this function will be called in shutdown sequence from HDD. All the
380\ allocated memory with global context will be freed here.
381\param tpAniSirGlobal pMac
382\return none
383 -------------------------------------------------------------*/
384
385tSirRetStatus macClose(tHalHandle hHal)
386{
387
388 tpAniSirGlobal pMac = (tpAniSirGlobal) hHal;
389
390#ifndef GEN6_ONWARDS
391 if(pMac->hal.pHalDxe){
392#ifdef RTL8652
393 extern void * rtlglue_is_data_scratchpad_memory(void *);
394 if(rtlglue_is_data_scratchpad_memory(pMac->hal.pHalDxe))
395 ;
396 else
397#endif
398 palFreeMemory(pMac, pMac->hal.pHalDxe);
399 }
400#endif //GEN6_ONWARDS
401
402 peClose(pMac);
403#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
404 halClose(hHal);
405#endif
406
407 /* Call routine to free-up all CFG data structures */
408 cfgDeInit(pMac);
409
410 logDeinit(pMac);
411
412 // Finally, de-allocate the global MAC datastructure:
413 palFreeMemory( pMac->hHdd, pMac );
414
415 return eSIR_SUCCESS;
416}
417
418/** -------------------------------------------------------------
419\fn macReset
420\brief this function is called to send Reset message to HDD. Then HDD will start the reset process.
421\param tpAniSirGlobal pMac
422\param tANI_U32 rc
423\return tSirRetStatus.
424 -------------------------------------------------------------*/
425
426tSirRetStatus macReset(tpAniSirGlobal pMac, tANI_U32 rc)
427{
428 tSirRetStatus status = eSIR_SUCCESS;
429#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
430 if(eHAL_STATUS_SUCCESS != halReset((tHalHandle)pMac, rc))
431 status = eSIR_FAILURE;
432#else
433 sysLog(pMac, LOGE, FL("*************No-op. Need to call WDA reset function \n"));
434#endif
435 return status;
436}
437
438// ----------------------------------------------------------------------
439/**
440 * macSysResetReq
441 *
442 * FUNCTION:
443 * All MAC modules use this interface in case of an exception.
444 *
445 * LOGIC:
446 *
447 * ASSUMPTIONS:
448 *
449 *
450 * NOTE:
451 *
452 * @param tpAniSirGlobal MAC parameters structure
453 * @param tANI_U32 reset reason code
454 * @return tANI_U16 - returs the status.
455 */
456
457void
458macSysResetReq(tpAniSirGlobal pMac, tANI_U32 rc)
459{
460 sysLog(pMac, LOGE, FL("Reason Code = 0x%X\n"),rc);
461
462 switch (rc)
463 {
464 case eSIR_STOP_BSS:
465 case eSIR_SME_BSS_RESTART:
466 case eSIR_RADIO_HW_SWITCH_STATUS_IS_OFF:
467 case eSIR_CFB_FLAG_STUCK_EXCEPTION:
468 // FIXME
469 //macReset(pMac, rc);
470 break;
471
472 case eSIR_EOF_SOF_EXCEPTION:
473 case eSIR_BMU_EXCEPTION:
474 case eSIR_CP_EXCEPTION:
475 case eSIR_LOW_PDU_EXCEPTION:
476 case eSIR_USER_TRIG_RESET:
477 case eSIR_AHB_HANG_EXCEPTION:
478 default:
479 macReset(pMac, rc);
480 break;
481
482 }
483}
484
485// -------------------------------------------------------------
486/**
487 * macSysResetReqFromHDD
488 *
489 * FUNCTION:
490 * This reset function gets invoked from the HDD to request a reset.
491 *
492 * LOGIC:
493 *
494 * ASSUMPTIONS:
495 *
496 *
497 * NOTE:
498 *
499 * @param tpAniSirGlobal MAC parameters structure
500 * @return tANI_U16 - returs the status.
501 */
502
503void
504macSysResetReqFromHDD(void *pMac, tANI_U32 rc)
505{
506 macSysResetReq( (tpAniSirGlobal)pMac, rc );
507}
508