• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * TWDriver.c
3  *
4  * Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  *  * Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *  * Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *  * Neither the name Texas Instruments nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 
35 /** \file  TWDriver.c
36  *  \brief TI WLAN Hardware Access Driver
37  *
38  *  \see   TWDriver.h
39  */
40 
41 #define __FILE_ID__  FILE_ID_117
42 #include "report.h"
43 #include "TWDriver.h"
44 #include "MacServices_api.h"
45 #include "txCtrlBlk_api.h"
46 #include "txHwQueue_api.h"
47 #include "txXfer_api.h"
48 #include "txResult_api.h"
49 #include "rxXfer_api.h"
50 #include "TwIf.h"
51 #include "FwEvent_api.h"
52 #include "CmdMBox_api.h"
53 #include "CmdQueue_api.h"
54 #include "eventMbox_api.h"
55 #include "fwDebug_api.h"
56 #include "osApi.h"
57 #include "TWDriverInternal.h"
58 #include "HwInit_api.h"
59 #include "CmdBld.h"
60 #include "RxQueue_api.h"
61 
62 
63 
64 #define TWD_CB_MODULE_OWNER_MASK    0xff00
65 #define TWD_CB_TYPE_MASK            0x00ff
66 
67 
68 
69 
TWD_Create(TI_HANDLE hOs)70 TI_HANDLE TWD_Create (TI_HANDLE hOs)
71 {
72     TTwd *pTWD;
73 
74     /* Allocate the TNETW_Driver module */
75     pTWD = (TTwd *)os_memoryAlloc (hOs, sizeof(TTwd));
76     if (pTWD == NULL)
77     {
78         return NULL;
79     }
80 
81     os_memoryZero (hOs, pTWD, sizeof(TTwd));
82 
83     pTWD->hOs = hOs;
84 
85     /* Create TwIf module */
86     pTWD->hTwIf = twIf_Create (hOs);
87     if (pTWD->hTwIf == NULL)
88     {
89         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"twIf_Create failed\n");
90         WLAN_OS_REPORT(("twIf_Create failed\n"));
91         TWD_Destroy ((TI_HANDLE)pTWD);
92         return NULL;
93     }
94 
95     /* Create command builder module */
96     pTWD->hCmdBld = cmdBld_Create (hOs);
97     if (pTWD->hCmdBld == NULL)
98     {
99         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"cmdBld_Create failed\n");
100         WLAN_OS_REPORT(("cmdBld_Create failed\n"));
101         TWD_Destroy ((TI_HANDLE)pTWD);
102         return NULL;
103     }
104 
105     /* Create the MAC Services module */
106     pTWD->hMacServices = MacServices_create (hOs);
107     if (pTWD->hMacServices == NULL)
108     {
109         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD MacServices_create failed!!!\n");
110         WLAN_OS_REPORT(("TWD MacServices_create failed!!!\n"));
111         TWD_Destroy ((TI_HANDLE)pTWD);
112         return NULL;
113     }
114 
115     /* Create the Ctrl module */
116     pTWD->hCmdQueue = cmdQueue_Create (hOs);
117     if (pTWD->hCmdQueue == NULL)
118     {
119         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD cmdQueue_Create failed!!!\n");
120         WLAN_OS_REPORT(("TWD cmdQueue_Create failed!!!\n"));
121         TWD_Destroy ((TI_HANDLE)pTWD);
122         return NULL;
123     }
124 
125     /*
126      * Create the FW-Transfer modules:
127      */
128 
129     pTWD->hTxXfer = txXfer_Create (hOs);
130     if (pTWD->hTxXfer == NULL)
131     {
132         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"TWD txXfer_Create failed!!!\n");
133         WLAN_OS_REPORT(("TWD txXfer_Create failed!!!\n"));
134         TWD_Destroy ((TI_HANDLE)pTWD);
135         return NULL;
136     }
137 
138     pTWD->hTxResult = txResult_Create (hOs);
139     if (pTWD->hTxResult == NULL)
140     {
141         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"TWD txResult_Create failed!!!\n");
142         WLAN_OS_REPORT(("TWD txResult_Create failed!!!\n"));
143         TWD_Destroy ((TI_HANDLE)pTWD);
144         return NULL;
145     }
146 
147     pTWD->hRxXfer = rxXfer_Create (hOs);
148     if (pTWD->hRxXfer == NULL)
149     {
150         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"TWD rxXfer_Create failed!!!\n");
151         WLAN_OS_REPORT(("TWD rxXfer_Create failed!!!\n"));
152         TWD_Destroy ((TI_HANDLE)pTWD);
153         return NULL;
154     }
155 
156     pTWD->hFwEvent = fwEvent_Create (hOs);
157     if (pTWD->hFwEvent == NULL)
158     {
159         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD fwEvent_Create failed!!!\n");
160         WLAN_OS_REPORT(("TWD fwEvent_Create failed!!!\n"));
161         TWD_Destroy ((TI_HANDLE)pTWD);
162         return NULL;
163     }
164 
165     pTWD->hEventMbox = eventMbox_Create (hOs);
166     if (pTWD->hEventMbox == NULL)
167     {
168         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD eventMbox_Create failed!!!\n");
169         WLAN_OS_REPORT(("TWD eventMbox_Create failed!!!\n"));
170         TWD_Destroy ((TI_HANDLE)pTWD);
171         return NULL;
172     }
173 
174 #ifdef TI_DBG
175     pTWD->hFwDbg = fwDbg_Create (hOs);
176     if (pTWD->hFwDbg == NULL)
177     {
178         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"TWD fwDbg_Create failed!!!\n");
179         WLAN_OS_REPORT(("TWD fwDbg_Create failed!!!\n"));
180         TWD_Destroy ((TI_HANDLE)pTWD);
181         return NULL;
182     }
183 #endif /* TI_DBG */
184 
185     pTWD->hCmdMbox = cmdMbox_Create (hOs);
186     if (pTWD->hCmdMbox == NULL)
187     {
188         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"TWD cmdMbox_Create failed!!!\n");
189         WLAN_OS_REPORT(("TWD cmdMbox_Create failed!!!\n"));
190         TWD_Destroy ((TI_HANDLE)pTWD);
191         return NULL;
192     }
193 
194     pTWD->hRxQueue = RxQueue_Create (hOs);
195     if (pTWD->hRxQueue == NULL)
196     {
197         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD RxQueue_Create failed!!!\n");
198         WLAN_OS_REPORT(("TWD RxQueue_Create failed!!!\n"));
199         TWD_Destroy ((TI_HANDLE)pTWD);
200         return NULL;
201     }
202 
203 
204     /*
205      * Create the Data-Services modules:
206      */
207 
208     pTWD->hTxCtrlBlk = txCtrlBlk_Create (hOs);
209     if (pTWD->hTxCtrlBlk == NULL)
210     {
211         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD txCtrlBlk_Create failed!!!\n");
212         WLAN_OS_REPORT(("TWD txCtrlBlk_Create failed!!!\n"));
213         TWD_Destroy ((TI_HANDLE)pTWD);
214         return NULL;
215     }
216 
217     pTWD->hTxHwQueue = txHwQueue_Create (hOs);
218     if (pTWD->hTxHwQueue == NULL)
219     {
220         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE, "TWD txHwQueue_Create failed!!!\n");
221         WLAN_OS_REPORT(("TWD txHwQueue_Create failed!!!\n"));
222         TWD_Destroy ((TI_HANDLE)pTWD);
223         return NULL;
224     }
225 
226     pTWD->hHwInit = hwInit_Create (hOs);
227     if (pTWD->hHwInit == NULL)
228     {
229         TRACE0(pTWD->hReport, REPORT_SEVERITY_CONSOLE,"wInit_Create failed!\n");
230         WLAN_OS_REPORT (("wInit_Create failed!\n"));
231         TWD_Destroy ((TI_HANDLE)pTWD);
232         return NULL;
233     }
234 
235     WLAN_INIT_REPORT (("TWD_Create: CREATED !!!\n"));
236 
237     return (TI_HANDLE)pTWD;
238 }
239 
TWD_Destroy(TI_HANDLE hTWD)240 TI_STATUS TWD_Destroy (TI_HANDLE hTWD)
241 {
242     TTwd *pTWD = (TTwd *)hTWD;
243 
244     WLAN_INIT_REPORT(("TWD_Destroy: called\n"));
245     if (pTWD == NULL)
246     {
247         return TI_NOK;
248     }
249 
250     if (pTWD->hTwIf != NULL)
251     {
252         twIf_Destroy (pTWD->hTwIf);
253         pTWD->hTwIf = NULL;
254     }
255 
256     /* Free the Command Builder */
257     if (pTWD->hCmdBld != NULL)
258     {
259         cmdBld_Destroy (pTWD->hCmdBld);
260         pTWD->hCmdBld = NULL;
261     }
262     WLAN_INIT_REPORT(("TWD_Destroy: Command Builder released\n"));
263 
264     /* Free the MAC Services */
265     if (pTWD->hMacServices != NULL)
266     {
267         MacServices_destroy(pTWD->hMacServices);
268         pTWD->hMacServices = NULL;
269     }
270     WLAN_INIT_REPORT(("TWD_Destroy: Mac Services released\n"));
271 
272     /*
273      * Free the Ctrl modules
274      */
275     if (pTWD->hCmdQueue != NULL)
276     {
277         cmdQueue_Destroy(pTWD->hCmdQueue);
278         pTWD->hCmdQueue = NULL;
279     }
280 
281     /*
282      * Free the FW-Transfer modules:
283      */
284     if (pTWD->hTxXfer != NULL)
285     {
286         txXfer_Destroy (pTWD->hTxXfer);
287         pTWD->hTxXfer = NULL;
288     }
289 
290     if (pTWD->hTxResult != NULL)
291     {
292         txResult_Destroy (pTWD->hTxResult);
293         pTWD->hTxResult = NULL;
294     }
295 
296     if (pTWD->hRxXfer != NULL)
297     {
298         rxXfer_Destroy (pTWD->hRxXfer);
299         pTWD->hRxXfer = NULL;
300     }
301 
302     if (pTWD->hEventMbox != NULL)
303     {
304         eventMbox_Destroy (pTWD->hEventMbox);
305         pTWD->hEventMbox = NULL;
306     }
307 
308 #ifdef TI_DBG
309     if (pTWD->hFwDbg != NULL)
310     {
311         fwDbg_Destroy (pTWD->hFwDbg);
312         pTWD->hFwDbg = NULL;
313     }
314 #endif /* TI_DBG */
315 
316     if (pTWD->hFwEvent != NULL)
317     {
318         fwEvent_Destroy (pTWD->hFwEvent);
319         pTWD->hFwEvent = NULL;
320     }
321 
322     if (pTWD->hCmdMbox != NULL)
323     {
324         cmdMbox_Destroy (pTWD->hCmdMbox);
325         pTWD->hCmdMbox = NULL;
326     }
327 
328     if (pTWD->hRxQueue != NULL)
329     {
330         RxQueue_Destroy (pTWD->hRxQueue);
331 		pTWD->hRxQueue = NULL;
332     }
333 
334     /*
335      * Free the Data-Services modules:
336      */
337 
338     if (pTWD->hTxCtrlBlk != NULL)
339     {
340         txCtrlBlk_Destroy (pTWD->hTxCtrlBlk);
341         pTWD->hTxCtrlBlk = NULL;
342     }
343 
344     if (pTWD->hTxHwQueue != NULL)
345     {
346         txHwQueue_Destroy (pTWD->hTxHwQueue);
347         pTWD->hTxHwQueue = NULL;
348     }
349 
350     if (pTWD->hHwInit != NULL)
351     {
352         hwInit_Destroy (pTWD->hHwInit);
353         pTWD->hHwInit = NULL;
354     }
355 
356     os_memoryFree (pTWD->hOs, (TI_HANDLE)pTWD, sizeof(TTwd));
357 
358     WLAN_INIT_REPORT(("TWD_Destroy pTNETW_Driver released!!!\n"));
359 
360     return TI_OK;
361 }
362 
363 
364 /**
365  * \brief HW Init Callback
366  *
367  * \param  hTWD         - TWD module object handle
368  * \return void
369  *
370  * \par Description
371  * Static CB function
372  * Called during TWD Module Init by hwInit_Init in order to complete the HW Configuration init
373  *
374  * \sa     TWD_InitHw
375  */
TWD_InitHwCb(TI_HANDLE hTWD)376 static void TWD_InitHwCb (TI_HANDLE hTWD)
377 {
378     TTwd *pTWD = (TTwd *)hTWD;
379 
380     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_InitHwCb: call fInitHwCb CB. In std drvMain_InitHwCb()\n");
381 
382     hwInit_InitPolarity(pTWD->hHwInit);
383 
384 }
385 
TWD_Init(TI_HANDLE hTWD,TI_HANDLE hReport,TI_HANDLE hUser,TI_HANDLE hTimer,TI_HANDLE hContext,TI_HANDLE hTxnQ,TTwdCallback fInitHwCb,TTwdCallback fInitFwCb,TTwdCallback fConfigFwCb,TTwdCallback fStopCb,TTwdCallback fInitFailCb)386 void TWD_Init (TI_HANDLE    hTWD,
387 			   TI_HANDLE 	hReport,
388                TI_HANDLE 	hUser,
389 			   TI_HANDLE 	hTimer,
390 			   TI_HANDLE 	hContext,
391 			   TI_HANDLE 	hTxnQ,
392                TTwdCallback fInitHwCb,
393                TTwdCallback fInitFwCb,
394                TTwdCallback fConfigFwCb,
395 			   TTwdCallback	fStopCb,
396 			   TTwdCallback fInitFailCb)
397 {
398     TTwd *pTWD 				= (TTwd *)hTWD;
399     pTWD->bInitSuccess 		= TI_FALSE;
400     pTWD->bRecoveryEnabled 	= TI_FALSE;
401     pTWD->hReport           = hReport;
402     pTWD->hUser 			= hUser;
403     pTWD->hTimer            = hTimer;
404     pTWD->hContext          = hContext;
405     pTWD->hTxnQ             = hTxnQ;
406     pTWD->fInitHwCb 		= fInitHwCb;
407     pTWD->fInitFwCb 		= fInitFwCb;
408     pTWD->fConfigFwCb 		= fConfigFwCb;
409     pTWD->fStopCb 			= fStopCb;
410     pTWD->fInitFailCb       = fInitFailCb;
411 
412     TRACE1(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_Init: %x\n", hTWD);
413 
414     /* FwEvent should be configured first */
415     fwEvent_Init (pTWD->hFwEvent, hTWD);
416 
417     eventMbox_Config (pTWD->hEventMbox, pTWD->hTwIf, pTWD->hReport, pTWD->hFwEvent, pTWD->hCmdBld);
418 
419     cmdQueue_Init (pTWD->hCmdQueue,
420                      pTWD->hCmdMbox,
421                      pTWD->hReport,
422                      pTWD->hTwIf,
423                      pTWD->hTimer);
424 
425     /* Configure Command Builder */
426     cmdBld_Config (pTWD->hCmdBld,
427                    pTWD->hReport,
428                    (void *)TWD_FinalizeDownload,
429                    hTWD,
430                    pTWD->hEventMbox,
431                    pTWD->hCmdQueue,
432                    pTWD->hTwIf);
433 
434     hwInit_Init (pTWD->hHwInit,
435                  pTWD->hReport,
436                  pTWD->hTimer,
437                  hTWD,
438 	             hTWD,
439 		         (TFinalizeCb)TWD_FinalizeDownload,
440                  TWD_InitHwCb);
441 
442     /*
443      * Initialize the FW-Transfer modules
444      */
445     txXfer_Init (pTWD->hTxXfer, pTWD->hReport, pTWD->hTwIf);
446 
447     txResult_Init (pTWD->hTxResult, pTWD->hReport, pTWD->hTwIf);
448 
449     rxXfer_Init (pTWD->hRxXfer, pTWD->hFwEvent, pTWD->hReport, pTWD->hTwIf, pTWD->hRxQueue);
450 
451     RxQueue_Init (pTWD->hRxQueue, pTWD->hReport, pTWD->hTimer);
452 
453 #ifdef TI_DBG
454     fwDbg_Init (pTWD->hFwDbg, pTWD->hReport, pTWD->hTwIf);
455 #endif /* TI_DBG */
456 
457     /* Initialize the MAC Services */
458     MacServices_init (pTWD->hMacServices,
459                       pTWD->hReport,
460                       hTWD,
461                       pTWD->hCmdBld,
462                       pTWD->hEventMbox,
463                       pTWD->hTimer);
464 
465     /*
466      * Initialize the Data-Services modules
467      */
468     txCtrlBlk_Init (pTWD->hTxCtrlBlk, pTWD->hReport, pTWD->hContext);
469     txHwQueue_Init (pTWD->hTxHwQueue, pTWD->hReport);
470 
471     /* Initialize the TwIf module */
472     twIf_Init (pTWD->hTwIf,
473                pTWD->hReport,
474                pTWD->hContext,
475                pTWD->hTimer,
476                pTWD->hTxnQ,
477                (TRecoveryCb)TWD_StopComplete,
478                hTWD);
479 }
480 
TWD_InitHw(TI_HANDLE hTWD,TI_UINT8 * pbuf,TI_UINT32 length,TI_UINT32 uRxDmaBufLen,TI_UINT32 uTxDmaBufLen)481  TI_STATUS TWD_InitHw (TI_HANDLE hTWD,
482 					   TI_UINT8  *pbuf,
483 					   TI_UINT32 length,
484                        TI_UINT32 uRxDmaBufLen,
485                        TI_UINT32 uTxDmaBufLen)
486 {
487     TTwd *pTWD = (TTwd *)hTWD;
488     TI_STATUS eStatus;
489 
490     TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_InitHw: called\n");
491 
492     /* Provide bus related parameters to Xfer modules before any usage of the bus! */
493     rxXfer_SetBusParams (pTWD->hRxXfer, uRxDmaBufLen);
494     txXfer_SetBusParams (pTWD->hTxXfer, uTxDmaBufLen);
495 
496     hwInit_SetNvsImage (pTWD->hHwInit, pbuf, length);
497 
498     /*
499      * Update the TwIf that the HW is awake
500      * This will protect the initialization process from going to sleep
501      * After the firmware initializations completed (TWD_EnableExternalEvents), the sleep will be enabled
502      */
503     twIf_Awake (pTWD->hTwIf);
504     twIf_HwAvailable (pTWD->hTwIf);
505 
506     /* This initiates the HW init sequence */
507     eStatus = hwInit_Boot(pTWD->hHwInit);
508     if (eStatus == TXN_STATUS_ERROR)
509     {
510         TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR , "TWD_InitHw: hwInit_Boot failed\n");
511         return TI_NOK;
512     }
513 
514     return TI_OK;
515 }
516 
TWD_BusOpen(TI_HANDLE hTWD,void * pParams)517 TI_STATUS TWD_BusOpen (TI_HANDLE hTWD, void* pParams)
518 {
519 	TTwd *pTWD = (TTwd *)hTWD;
520 	TI_STATUS uStatus;
521 
522     TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_BusOpen: called\n");
523 
524     /*uStatus = TNETWIF_Open(pTWD->hTNETWIF, pParams);*/
525     uStatus = TI_OK;
526 
527 	return uStatus;
528 }
529 
TWD_BusClose(TI_HANDLE hTWD)530 TI_STATUS TWD_BusClose (TI_HANDLE hTWD)
531 {
532 	TTwd *pTWD = (TTwd *)hTWD;
533 	TI_STATUS uStatus;
534 
535     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_BusClose: called\n");
536 
537 	/*uStatus = TNETWIF_Close(pTWD->hTNETWIF);*/
538     uStatus = TI_OK;
539 
540 	return uStatus;
541 }
542 
TWD_InitFw(TI_HANDLE hTWD,TFileInfo * pFileInfo)543 TI_STATUS TWD_InitFw (TI_HANDLE hTWD, TFileInfo *pFileInfo)
544 {
545     TTwd *pTWD = (TTwd *)hTWD;
546     TI_STATUS status;
547 
548     /* check Parameters */
549     if (( pTWD == NULL ) || ( pFileInfo == NULL ))
550     {
551         return (TI_NOK);
552     }
553 
554 	TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_InitFw: called\n");
555 
556     hwInit_SetFwImage (pTWD->hHwInit, pFileInfo);
557 
558     /* This will initiate the download to the FW */
559     status = hwInit_LoadFw(pTWD->hHwInit);
560 
561     if (status == TXN_STATUS_ERROR)
562     {
563         TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR , "TWD_InitFw: failed to initialize FW\n");
564 
565         return TI_NOK;
566     }
567 
568     return TI_OK;
569 }
570 
571 /**
572  * \brief  Propagate interrogate results
573  *
574  * \param  hTWD         - TWD module object handle
575  * \param  status       - callback status
576  * \return TI_OK on success or TI_NOK on failure
577  *
578  * \par Description
579  * Static CB function
580  * Propagate interrogate results between TX and RX modules
581  * Called by TWD_ConfigFw
582  *
583  * \sa
584  */
TWD_ConfigFwCb(TI_HANDLE hTWD,TI_STATUS status)585 static TI_STATUS TWD_ConfigFwCb (TI_HANDLE hTWD, TI_STATUS status)
586 {
587     TTwd        *pTWD = (TTwd *)hTWD;
588     TDmaParams  *pDmaParams = &DB_DMA(pTWD->hCmdBld);
589 
590     /*
591      * Store the addresses of the cyclic buffer (Rx/Tx)
592      * and the path status and control (Tx/Rx) in the corresponding modules
593      */
594     txResult_setHwInfo (pTWD->hTxResult, pDmaParams);
595 
596     rxXfer_Restart (pTWD->hRxXfer);
597     txXfer_Restart (pTWD->hTxXfer);
598 
599     rxXfer_SetRxDirectAccessParams (pTWD->hRxXfer, pDmaParams);
600 
601     /* Provide number of HW Tx-blocks and descriptors to Tx-HW-Queue module */
602     txHwQueue_SetHwInfo (pTWD->hTxHwQueue, pDmaParams);
603 
604     /* If the configure complete function was registered, we call it here - end of TWD_Configure stage */
605     if (pTWD->fConfigFwCb)
606     {
607         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_ConfigFwCb: call TWD_OWNER_SELF_CONFIG CB. In std drvMain_ConfigFwCb()\n");
608 
609         pTWD->fConfigFwCb (pTWD->hUser, TI_OK);
610     }
611 
612     return TI_OK;
613 }
614 
615 
TWD_SetDefaults(TI_HANDLE hTWD,TTwdInitParams * pInitParams)616 TI_STATUS TWD_SetDefaults (TI_HANDLE hTWD, TTwdInitParams *pInitParams)
617 {
618     TTwd         *pTWD = (TTwd *)hTWD;
619 
620     TWlanParams         		*pWlanParams = &DB_WLAN(pTWD->hCmdBld);
621     TKeepAliveList      		*pKlvParams = &DB_KLV(pTWD->hCmdBld);
622     IniFileRadioParam   		*pRadioParams = &DB_RADIO(pTWD->hCmdBld);
623 	IniFileExtendedRadioParam   *pExtRadioParams = &DB_EXT_RADIO(pTWD->hCmdBld);
624     IniFileGeneralParam 		*pGenParams = &DB_GEN(pTWD->hCmdBld);
625 	TRateMngParams      		*pRateMngParams = &DB_RM(pTWD->hCmdBld);
626     TDmaParams          		*pDmaParams = &DB_DMA(pTWD->hCmdBld);
627 
628     TI_UINT32            k, uIndex;
629     int iParam;
630 
631     TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_SetDefaults: called\n");
632 
633     pTWD->bRecoveryEnabled = pInitParams->tGeneral.halCtrlRecoveryEnable;
634 
635     pWlanParams->PacketDetectionThreshold   = pInitParams->tGeneral.packetDetectionThreshold;
636     pWlanParams->qosNullDataTemplateSize    = pInitParams->tGeneral.qosNullDataTemplateSize;
637     pWlanParams->PsPollTemplateSize         = pInitParams->tGeneral.PsPollTemplateSize;
638     pWlanParams->probeResponseTemplateSize  = pInitParams->tGeneral.probeResponseTemplateSize;
639     pWlanParams->probeRequestTemplateSize   = pInitParams->tGeneral.probeRequestTemplateSize;
640     pWlanParams->beaconTemplateSize         = pInitParams->tGeneral.beaconTemplateSize;
641     pWlanParams->nullTemplateSize           = pInitParams->tGeneral.nullTemplateSize;
642     pWlanParams->disconnTemplateSize        = pInitParams->tGeneral.disconnTemplateSize;
643     pWlanParams->ArpRspTemplateSize         = pInitParams->tGeneral.ArpRspTemplateSize;
644 
645     /* Beacon broadcast options */
646     pWlanParams->BcnBrcOptions.BeaconRxTimeout      = pInitParams->tGeneral.BeaconRxTimeout;
647     pWlanParams->BcnBrcOptions.BroadcastRxTimeout   = pInitParams->tGeneral.BroadcastRxTimeout;
648     pWlanParams->BcnBrcOptions.RxBroadcastInPs      = pInitParams->tGeneral.RxBroadcastInPs;
649     pWlanParams->ConsecutivePsPollDeliveryFailureThreshold = pInitParams->tGeneral.ConsecutivePsPollDeliveryFailureThreshold;
650 
651     pWlanParams->RxDisableBroadcast         = pInitParams->tGeneral.halCtrlRxDisableBroadcast;
652     pWlanParams->calibrationChannel2_4      = pInitParams->tGeneral.halCtrlCalibrationChannel2_4;
653     pWlanParams->calibrationChannel5_0      = pInitParams->tGeneral.halCtrlCalibrationChannel5_0;
654 
655     /* Not used but need by Palau */
656     pWlanParams->RtsThreshold               = pInitParams->tGeneral.halCtrlRtsThreshold;
657     pWlanParams->CtsToSelf                  = CTS_TO_SELF_DISABLE;
658 
659     pWlanParams->WiFiWmmPS                  = pInitParams->tGeneral.WiFiWmmPS;
660 
661     pWlanParams->MaxTxMsduLifetime          = pInitParams->tGeneral.halCtrlMaxTxMsduLifetime;
662     pWlanParams->MaxRxMsduLifetime          = pInitParams->tGeneral.halCtrlMaxRxMsduLifetime;
663 
664     pWlanParams->rxTimeOut.psPoll           = pInitParams->tGeneral.rxTimeOut.psPoll;
665     pWlanParams->rxTimeOut.UPSD             = pInitParams->tGeneral.rxTimeOut.UPSD;
666 
667     /* RSSI/SNR Weights for Average calculations */
668     pWlanParams->tRssiSnrWeights.rssiBeaconAverageWeight = pInitParams->tGeneral.uRssiBeaconAverageWeight;
669     pWlanParams->tRssiSnrWeights.rssiPacketAverageWeight = pInitParams->tGeneral.uRssiPacketAverageWeight;
670     pWlanParams->tRssiSnrWeights.snrBeaconAverageWeight  = pInitParams->tGeneral.uSnrBeaconAverageWeight ;
671     pWlanParams->tRssiSnrWeights.snrPacketAverageWeight  = pInitParams->tGeneral.uSnrPacketAverageWeight ;
672 
673     /* PM config params */
674     pWlanParams->uHostClkSettlingTime       = pInitParams->tGeneral.uHostClkSettlingTime;
675     pWlanParams->uHostFastWakeupSupport     = pInitParams->tGeneral.uHostFastWakeupSupport;
676 
677     /* No used */
678     pWlanParams->FragmentThreshold          = pInitParams->tGeneral.halCtrlFragThreshold;
679     pWlanParams->ListenInterval             = (TI_UINT8)pInitParams->tGeneral.halCtrlListenInterval;
680     pWlanParams->RateFallback               = pInitParams->tGeneral.halCtrlRateFallbackRetry;
681     pWlanParams->MacClock                   = pInitParams->tGeneral.halCtrlMacClock;
682     pWlanParams->ArmClock                   = pInitParams->tGeneral.halCtrlArmClock;
683 
684 	pWlanParams->ch14TelecCca = pInitParams->tGeneral.halCtrlCh14TelecCca;
685 
686     /* Data interrupts pacing */
687     pWlanParams->TxCompletePacingThreshold  = pInitParams->tGeneral.TxCompletePacingThreshold;
688     pWlanParams->TxCompletePacingTimeout    = pInitParams->tGeneral.TxCompletePacingTimeout;
689     pWlanParams->RxIntrPacingThreshold      = pInitParams->tGeneral.RxIntrPacingThreshold;
690     pWlanParams->RxIntrPacingTimeout        = pInitParams->tGeneral.RxIntrPacingTimeout;
691 
692     /* Number of Rx mem-blocks to allocate in FW */
693     pDmaParams->NumRxBlocks                 = pInitParams->tGeneral.uRxMemBlksNum;
694 
695 
696     /* Configure ARP IP */
697     pWlanParams->arpFilterType    = pInitParams->tArpIpFilter.filterType;
698     IP_COPY (pWlanParams->arp_IP_addr, pInitParams->tArpIpFilter.addr);
699 
700     /* Configure address group */
701     pWlanParams->numGroupAddrs = pInitParams->tMacAddrFilter.numOfMacAddresses;
702     pWlanParams->isMacAddrFilteringnabled = pInitParams->tMacAddrFilter.isFilterEnabled;
703 
704     for (k = 0; k < pWlanParams->numGroupAddrs; k++)
705     {
706         MAC_COPY (pWlanParams->aGroupAddr[k], pInitParams->tMacAddrFilter.macAddrTable[k]);
707     }
708 
709 
710     /* CoexActivity Table */
711     TRACE1(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_SetDefaults: coex numOfElements %d\n", pInitParams->tGeneral.halCoexActivityTable.numOfElements);
712 
713     pWlanParams->tWlanParamsCoexActivityTable.numOfElements = 0;
714     for (iParam=0; iParam < (int)pInitParams->tGeneral.halCoexActivityTable.numOfElements; iParam++)
715     {
716         TCoexActivity *pSaveCoex = &pWlanParams->tWlanParamsCoexActivityTable.entry[0];
717         TCoexActivity *pParmCoex = &pInitParams->tGeneral.halCoexActivityTable.entry[0];
718         int i, saveIndex;
719 
720         /* Check if to overwrite existing entry or put on last index */
721         for (i=0; i<iParam; i++)
722         {
723             if ((pSaveCoex[i].activityId == pParmCoex[iParam].activityId) && (pSaveCoex[i].coexIp == pParmCoex[iParam].coexIp))
724             {
725                 break;
726             }
727         }
728 
729         if (i == iParam)
730         {
731             /* new entry */
732             saveIndex = pWlanParams->tWlanParamsCoexActivityTable.numOfElements;
733             pWlanParams->tWlanParamsCoexActivityTable.numOfElements++;
734         }
735         else
736         {
737             /* overwrite existing */
738             saveIndex = i;
739         }
740 
741         TRACE4(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_SetDefaults: save coex Param %d in index %d, %d %d\n", iParam, saveIndex, pParmCoex[iParam].coexIp, pParmCoex[iParam].activityId);
742 
743         pSaveCoex[saveIndex].coexIp          = pParmCoex[iParam].coexIp;
744         pSaveCoex[saveIndex].activityId      = pParmCoex[iParam].activityId;
745         pSaveCoex[saveIndex].defaultPriority = pParmCoex[iParam].defaultPriority;
746         pSaveCoex[saveIndex].raisedPriority  = pParmCoex[iParam].raisedPriority;
747         pSaveCoex[saveIndex].minService      = pParmCoex[iParam].minService;
748         pSaveCoex[saveIndex].maxService      = pParmCoex[iParam].maxService;
749     }
750 
751     /* configure keep-alive default mode to enabled */
752     pKlvParams->enaDisFlag = TI_TRUE;
753     for (uIndex = 0; uIndex < KLV_MAX_TMPL_NUM; uIndex++)
754     {
755         pKlvParams->keepAliveParams[ uIndex ].enaDisFlag = TI_FALSE;
756     }
757 
758     /* Configure the TWD modules */
759     rxXfer_SetDefaults (pTWD->hRxXfer, pInitParams);
760     txXfer_SetDefaults (pTWD->hTxXfer, pInitParams);
761     txHwQueue_Config (pTWD->hTxHwQueue, pInitParams);
762     MacServices_config (pTWD->hMacServices, pInitParams);
763 
764     /*
765      * 802.11n
766      */
767     pWlanParams->tTwdHtCapabilities.b11nEnable =            pInitParams->tGeneral.b11nEnable;
768 
769     /* Configure HT capabilities setting */
770     pWlanParams->tTwdHtCapabilities.uChannelWidth = CHANNEL_WIDTH_20MHZ;
771     pWlanParams->tTwdHtCapabilities.uRxSTBC       = RXSTBC_NOT_SUPPORTED;
772     pWlanParams->tTwdHtCapabilities.uMaxAMSDU     = MAX_MSDU_3839_OCTETS;
773     pWlanParams->tTwdHtCapabilities.uMaxAMPDU     = pInitParams->tGeneral.uMaxAMPDU;
774 
775     pWlanParams->tTwdHtCapabilities.uAMPDUSpacing =         AMPDU_SPC_8_MICROSECONDS;
776     pWlanParams->tTwdHtCapabilities.aRxMCS[0] =             (MCS_SUPPORT_MCS_0 |
777                                                              MCS_SUPPORT_MCS_1 |
778                                                              MCS_SUPPORT_MCS_2 |
779                                                              MCS_SUPPORT_MCS_3 |
780                                                              MCS_SUPPORT_MCS_4 |
781                                                              MCS_SUPPORT_MCS_5 |
782                                                              MCS_SUPPORT_MCS_6 |
783                                                              MCS_SUPPORT_MCS_7);
784     os_memoryZero (pTWD->hOs, pWlanParams->tTwdHtCapabilities.aRxMCS + 1, RX_TX_MCS_BITMASK_SIZE - 1);
785     pWlanParams->tTwdHtCapabilities.aTxMCS[0]  =             (MCS_SUPPORT_MCS_0 |
786                                                               MCS_SUPPORT_MCS_1 |
787                                                               MCS_SUPPORT_MCS_2 |
788                                                               MCS_SUPPORT_MCS_3 |
789                                                               MCS_SUPPORT_MCS_4 |
790                                                               MCS_SUPPORT_MCS_5 |
791                                                               MCS_SUPPORT_MCS_6 |
792                                                               MCS_SUPPORT_MCS_7);
793     os_memoryZero (pTWD->hOs, pWlanParams->tTwdHtCapabilities.aTxMCS + 1, RX_TX_MCS_BITMASK_SIZE - 1);
794     pWlanParams->tTwdHtCapabilities.uRxMaxDataRate =         MCS_HIGHEST_SUPPORTED_RECEPTION_DATA_RATE_IN_MBIT_S;
795     pWlanParams->tTwdHtCapabilities.uPCOTransTime =          PCO_TRANS_TIME_NO_TRANSITION;
796     pWlanParams->tTwdHtCapabilities.uHTCapabilitiesBitMask = (CAP_BIT_MASK_GREENFIELD_FRAME_FORMAT |
797                                                               CAP_BIT_MASK_SHORT_GI_FOR_20MHZ_PACKETS);
798     pWlanParams->tTwdHtCapabilities.uMCSFeedback =           MCS_FEEDBACK_NO;
799 
800     os_memoryCopy(pTWD->hOs, (void*)pRadioParams, (void*)&pInitParams->tIniFileRadioParams, sizeof(IniFileRadioParam));
801 	os_memoryCopy(pTWD->hOs, (void*)pExtRadioParams, (void*)&pInitParams->tIniFileExtRadioParams, sizeof(IniFileExtendedRadioParam));
802     os_memoryCopy(pTWD->hOs, (void*)pGenParams, (void*)&pInitParams->tPlatformGenParams, sizeof(IniFileGeneralParam));
803 
804     os_memoryCopy (pTWD->hOs,
805                    (void*)&(pWlanParams->tFmCoexParams),
806                    (void*)&(pInitParams->tGeneral.tFmCoexParams),
807                    sizeof(TFmCoexParams));
808 
809 	/* Rate management params */
810 	pRateMngParams->rateMngParams.InverseCuriosityFactor = pInitParams->tRateMngParams.InverseCuriosityFactor;
811 	pRateMngParams->rateMngParams.MaxPer = pInitParams->tRateMngParams.MaxPer;
812 	pRateMngParams->rateMngParams.PerAdd = pInitParams->tRateMngParams.PerAdd;
813 	pRateMngParams->rateMngParams.PerAddShift = pInitParams->tRateMngParams.PerAddShift;
814 	pRateMngParams->rateMngParams.PerAlphaShift = pInitParams->tRateMngParams.PerAlphaShift;
815 	pRateMngParams->rateMngParams.PerBeta1Shift = pInitParams->tRateMngParams.PerBeta1Shift;
816 	pRateMngParams->rateMngParams.PerBeta2Shift = pInitParams->tRateMngParams.PerBeta2Shift;
817 	pRateMngParams->rateMngParams.PerTh1 = pInitParams->tRateMngParams.PerTh1;
818 	pRateMngParams->rateMngParams.PerTh2 = pInitParams->tRateMngParams.PerTh2;
819 	pRateMngParams->rateMngParams.RateCheckDown = pInitParams->tRateMngParams.RateCheckDown;
820 	pRateMngParams->rateMngParams.RateCheckUp = pInitParams->tRateMngParams.RateCheckUp;
821 	pRateMngParams->rateMngParams.RateRetryScore = pInitParams->tRateMngParams.RateRetryScore;
822 	pRateMngParams->rateMngParams.TxFailHighTh = pInitParams->tRateMngParams.TxFailHighTh;
823 	pRateMngParams->rateMngParams.TxFailLowTh = pInitParams->tRateMngParams.TxFailLowTh;
824 
825 	/* RATE_MNG_MAX_RETRY_POLICY_PARAMS_LEN */
826 	for (uIndex = 0; uIndex < 13; uIndex++)
827 	{
828         pRateMngParams->rateMngParams.RateRetryPolicy[uIndex] = pInitParams->tRateMngParams.RateRetryPolicy[uIndex];
829 	}
830 
831 	/* DCO Itrim params */
832     pWlanParams->dcoItrimEnabled = pInitParams->tDcoItrimParams.enable;
833     pWlanParams->dcoItrimModerationTimeoutUsec = pInitParams->tDcoItrimParams.moderationTimeoutUsec;
834 
835     return TI_OK;
836 }
837 
TWD_ConfigFw(TI_HANDLE hTWD)838 TI_STATUS TWD_ConfigFw (TI_HANDLE hTWD)
839 {
840     TTwd *pTWD = (TTwd *)hTWD;
841 
842     TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_ConfigFw: called\n");
843 
844     /*
845      * Configure the WLAN firmware after config all the hardware objects
846      */
847     if (cmdBld_ConfigFw (pTWD->hCmdBld, (void *)TWD_ConfigFwCb, hTWD) != TI_OK)
848     {
849         return TI_NOK;
850     }
851 
852     return TI_OK;
853 }
854 
TWD_FinalizeDownload(TI_HANDLE hTWD)855 void TWD_FinalizeDownload (TI_HANDLE hTWD)
856 {
857     TTwd *pTWD = (TTwd *)hTWD;
858 
859     TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT , "TWD_FinalizeDownload: called\n");
860 
861 	if ( pTWD == NULL )
862 	{
863 		return;
864 	}
865     /* Here at the end call the Initialize Complete callback that will release the user Init semaphore */
866     TRACE0(pTWD->hReport, REPORT_SEVERITY_INIT, "Before sending the Init Complet callback !!!!!\n");
867 
868     /* Sign that init has succeeded */
869     pTWD->bInitSuccess = TI_TRUE;
870 
871     /* Call user application configuration callback */
872     if (pTWD->fInitFwCb)
873     {
874         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_FinalizeDownload: call fInitFwCb CB. In std drvMain_InitFwCb()\n");
875 
876         (*pTWD->fInitFwCb) (pTWD->hUser, TI_OK);
877     }
878 }
879 
TWD_FinalizeOnFailure(TI_HANDLE hTWD)880 void TWD_FinalizeOnFailure (TI_HANDLE hTWD)
881 {
882     TTwd  *pTWD = (TTwd *)hTWD;
883 
884     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_FinalizeOnFailure: called\n");
885 
886 	/* Call the upper layer callback for init failure case */
887     if (pTWD->fInitFailCb)
888     {
889         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_FinalizeOnFailure: call fInitFailCb CB. In std drvMain_InitFailCb()\n");
890 
891         pTWD->fInitFailCb (pTWD->hUser, TI_OK);
892     }
893 }
894 
TWD_CheckMailboxCb(TI_HANDLE hTWD,TI_UINT16 uMboxStatus,void * pItrParamBuf)895 TI_STATUS TWD_CheckMailboxCb (TI_HANDLE hTWD, TI_UINT16 uMboxStatus, void *pItrParamBuf)
896 {
897     TTwd *pTWD = (TTwd *)hTWD;
898 
899     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_CheckMailboxCb: called\n");
900 
901     if (uMboxStatus != TI_OK)
902     {
903         ++pTWD->uNumMboxFailures;
904         TRACE1(pTWD->hReport, REPORT_SEVERITY_WARNING, "TWD_CheckMailboxCb: Periodic intorregate check - Command mailbox failure was occur \n errors failure # %d", pTWD->uNumMboxFailures);
905 
906         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_CheckMailboxCb: call TWD_INT_EVENT_FAILURE CB. In std healthMonitor_sendFailureEvent()\n");
907 
908         /* Indicating Upper Layer about Mbox Error */
909         pTWD->fFailureEventCb (pTWD->hFailureEventCb, MBOX_FAILURE);
910     }
911 
912     return TI_OK;
913 }
914 #ifdef RS_OVER_TWD
915 extern	void (*gBusTxn_ErrorCb)(TI_HANDLE , int);
916 extern  void *gBusTxn_ErrorHndle;
917 #endif
918 
919 /**
920  * \brief Registers TWD Module Callbacks
921  *
922  * \param  hTWD         - TWD module object handle
923  * \param  uCallBackID  - Registered Callback ID
924  * \param  fCb 	        - Pointer to Input Registered CB function
925  * \param  hCb 	        - Handle to Input Registered CB parameters
926  * \return void
927  *
928  * \par Description
929  * Static CB function
930  * This CB Registers TWD CB functions for future use:
931  * CB which handles failure to the CMD Queue, MAC Service and TwIf
932  * CB which handles Command Complete for the CMD Queue
933  * Called by TWD_RegisterCb
934  *
935  * \sa TWD_RegisterCb
936  */
TWD_RegisterOwnCb(TI_HANDLE hTWD,TI_UINT32 uCallBackID,void * fCb,TI_HANDLE hCb)937 static void TWD_RegisterOwnCb (TI_HANDLE hTWD, TI_UINT32 uCallBackID, void *fCb, TI_HANDLE hCb)
938 {
939     TTwd *pTWD = (TTwd *)hTWD;
940 
941     TRACE1(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_RegisterOwnCB: callback ID=0x%x\n", uCallBackID);
942 
943     switch (uCallBackID)
944     {
945     case TWD_INT_EVENT_FAILURE:
946         /* Save Health-Moitor callback */
947         pTWD->fFailureEventCb = (TFailureEventCb)fCb;
948         pTWD->hFailureEventCb = hCb;
949 
950         /* Register For Error Of Mailbox in case of timeout */
951         cmdQueue_RegisterForErrorCb (pTWD->hCmdQueue, (void *)TWD_CheckMailboxCb, hTWD);
952 
953         /* Forward the Health-Moitor callback to the MAC-Services modules */
954         MacServices_registerFailureEventCB(pTWD->hMacServices, fCb, hCb);
955 
956         /* Forward the Health-Moitor callback to the TwIf for bus errors */
957         twIf_RegisterErrCb (pTWD->hTwIf, fCb, hCb);
958 
959         /* Forward the Health-Moitor callback to the RxXfer for Rx packet errors */
960         rxXfer_RegisterErrCb (pTWD->hRxXfer, fCb, hCb);
961         break;
962 
963     case TWD_INT_COMMAND_COMPLETE:
964         cmdQueue_RegisterCmdCompleteGenericCb (pTWD->hCmdQueue, fCb, hCb);
965         break;
966 
967     default:
968         TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_RegisterOwnCb - Illegal value\n");
969     }
970 }
971 
TWD_RegisterCb(TI_HANDLE hTWD,TI_UINT32 event,TTwdCB * fCb,void * pData)972 TI_STATUS TWD_RegisterCb (TI_HANDLE hTWD, TI_UINT32 event, TTwdCB *fCb, void *pData)
973 {
974     TTwd *pTWD = (TTwd *)hTWD;
975     TI_UINT32 uModuleId    = event & TWD_CB_MODULE_OWNER_MASK;
976     TI_UINT32 uCallbackId  = event & TWD_CB_TYPE_MASK;
977 
978 	if ((fCb == NULL) || (pData == NULL))
979 	{
980 TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_Register_CB: Invalid NULL Parameter\n");
981 
982 	}
983 
984     TRACE1(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: (Value = 0x%x)\n", event);
985 
986    /* First detect which module is the owner */
987 
988     switch (uModuleId)
989     {
990     case TWD_OWNER_TX_HW_QUEUE:
991         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_TX_HW_QUEUE\n");
992         txHwQueue_RegisterCb (pTWD->hTxHwQueue, uCallbackId, fCb, pData);
993         break;
994 
995     case TWD_OWNER_DRIVER_TX_XFER:
996         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_DRIVER_TX_XFER\n");
997         txXfer_RegisterCb (pTWD->hTxXfer, uCallbackId, fCb, pData);
998         break;
999 
1000     case TWD_OWNER_TX_RESULT:
1001         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_TX_RESULT\n");
1002         txResult_RegisterCb (pTWD->hTxResult, uCallbackId, fCb, pData);
1003         break;
1004 
1005     case TWD_OWNER_RX_XFER:
1006         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_RX_XFER\n");
1007         rxXfer_Register_CB(pTWD->hRxXfer, uCallbackId, fCb, pData);
1008         break;
1009 
1010     case TWD_OWNER_RX_QUEUE:
1011         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_RX_QUEUE\n");
1012         RxQueue_Register_CB(pTWD->hRxQueue, uCallbackId, fCb, pData);
1013         break;
1014 
1015     case TWD_OWNER_SELF:
1016         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_SELF\n");
1017         TWD_RegisterOwnCb (hTWD, uCallbackId, fCb, pData);
1018         break;
1019 
1020     case TWD_OWNER_MAC_SERVICES:
1021         switch (uCallbackId)
1022         {
1023         case TWD_OWN_EVENT_SCAN_CMPLT:
1024             MacServices_scanSRV_registerScanCompleteCB (pTWD->hMacServices, (TScanSrvCompleteCb)fCb, pData);
1025             break;
1026         default:
1027             TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_Register_CB: TWD_OWNER_MAC_SERVICES - Illegal value\n");
1028         }
1029         break;
1030 
1031     case TWD_OWNER_SELF_CONFIG:
1032         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_Register_CB: TWD_OWNER_SELF_CONFIG\n");
1033         pTWD->fConfigFwCb  = (TTwdCallback)fCb;
1034         break;
1035 
1036     default:
1037         TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_Register_CB - Illegal value\n");
1038     }
1039 
1040     return TI_OK;
1041 }
1042 
TWD_ExitFromInitMode(TI_HANDLE hTWD)1043 TI_STATUS TWD_ExitFromInitMode (TI_HANDLE hTWD)
1044 {
1045     TTwd    *pTWD = (TTwd *)hTWD;
1046 
1047     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_ExitFromInitMode: called\n");
1048 
1049     /* Notify Event MailBox about init complete */
1050     eventMbox_InitComplete (pTWD->hEventMbox);
1051 
1052     /* Enable Mailbox */
1053     cmdQueue_EnableMbox (pTWD->hCmdQueue);
1054 
1055     return TI_OK;
1056 }
1057 
1058 
1059 #ifdef TI_DBG
TWD_PrintTxInfo(TI_HANDLE hTWD,ETwdPrintInfoType ePrintInfo)1060 TI_STATUS TWD_PrintTxInfo (TI_HANDLE hTWD, ETwdPrintInfoType ePrintInfo)
1061 {
1062     TTwd *pTWD = (TTwd *)hTWD;
1063 
1064     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_PrintTxInfo: called\n");
1065 
1066     switch (ePrintInfo)
1067     {
1068         case TWD_PRINT_TX_CTRL_BLK_TBL:
1069             txCtrlBlk_PrintTable (pTWD->hTxCtrlBlk);
1070             break;
1071 
1072         case TWD_PRINT_TX_HW_QUEUE_INFO:
1073             txHwQueue_PrintInfo (pTWD->hTxHwQueue);
1074             break;
1075 
1076         case TWD_PRINT_TX_XFER_INFO:
1077             txXfer_PrintStats (pTWD->hTxXfer);
1078             break;
1079 
1080         case TWD_PRINT_TX_RESULT_INFO:
1081             txResult_PrintInfo (pTWD->hTxResult);
1082             break;
1083 
1084         case TWD_CLEAR_TX_RESULT_INFO:
1085             txResult_ClearInfo (pTWD->hTxResult);
1086             break;
1087 
1088         case TWD_CLEAR_TX_XFER_INFO:
1089             txXfer_ClearStats (pTWD->hTxXfer);
1090             break;
1091 
1092         default:
1093             TRACE1(pTWD->hReport, REPORT_SEVERITY_ERROR, ": invalid print info request code: %d\n", ePrintInfo);
1094     }
1095 
1096     return TI_OK;
1097 }
1098 
1099 #endif /* TI_DBG */
1100 
TWD_InterruptRequest(TI_HANDLE hTWD)1101 TI_STATUS TWD_InterruptRequest (TI_HANDLE hTWD)
1102 {
1103     TTwd *pTWD = (TTwd *)hTWD;
1104 
1105     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_InterruptRequest: called\n");
1106 
1107     fwEvent_InterruptRequest (pTWD->hFwEvent);
1108 
1109     return TI_OK;
1110 }
1111 
TWD_RegisterEvent(TI_HANDLE hTWD,TI_UINT32 event,void * fCb,TI_HANDLE hCb)1112 TI_STATUS TWD_RegisterEvent (TI_HANDLE hTWD, TI_UINT32 event, void *fCb, TI_HANDLE hCb)
1113 {
1114     TTwd  *pTWD = (TTwd *)hTWD;
1115 
1116     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_RegisterEvent: called\n");
1117 
1118     return eventMbox_RegisterEvent (pTWD->hEventMbox, event, fCb, hCb);
1119 }
1120 
TWD_DisableEvent(TI_HANDLE hTWD,TI_UINT32 event)1121 TI_STATUS TWD_DisableEvent (TI_HANDLE hTWD, TI_UINT32 event)
1122 {
1123     TTwd  *pTWD = (TTwd *)hTWD;
1124 
1125     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_DisableEvent: called\n");
1126 
1127     return eventMbox_MaskEvent (pTWD->hEventMbox, event, NULL, NULL);
1128 }
1129 
TWD_EnableEvent(TI_HANDLE hTWD,TI_UINT32 event)1130 TI_STATUS TWD_EnableEvent (TI_HANDLE hTWD, TI_UINT32 event)
1131 {
1132     TTwd  *pTWD = (TTwd *)hTWD;
1133 
1134     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_EnableEvent: called\n");
1135 
1136     return eventMbox_UnMaskEvent (pTWD->hEventMbox, event, NULL, NULL);
1137 }
1138 
TWD_StopComplete(TI_HANDLE hTWD)1139 void TWD_StopComplete (TI_HANDLE hTWD)
1140 {
1141     TTwd  *pTWD = (TTwd *)hTWD;
1142 
1143     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopComplete: called\n");
1144 
1145 
1146     /* reinit last ELP mode flag in recovery */
1147     cmdBld_Restart(pTWD->hCmdBld);
1148 
1149     /* Call upper layer callback */
1150     if (pTWD->fStopCb)
1151     {
1152         TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopComplete: call fStopCb CB. In std drvMain_TwdStopCb()\n");
1153 
1154         (*pTWD->fStopCb) (pTWD->hUser, TI_OK);
1155     }
1156 }
1157 
TWD_Stop(TI_HANDLE hTWD)1158 TI_STATUS TWD_Stop (TI_HANDLE hTWD)
1159 {
1160     TTwd        *pTWD = (TTwd *)hTWD;
1161     ETxnStatus   status;
1162 
1163     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_Stop: called\n");
1164 
1165     fwEvent_Stop (pTWD->hFwEvent);
1166 
1167 
1168     /* close all BA sessions */
1169     TWD_CloseAllBaSessions(hTWD);
1170 
1171     cmdMbox_Restart (pTWD->hCmdMbox);
1172     cmdQueue_Restart (pTWD->hCmdQueue);
1173     cmdQueue_DisableMbox (pTWD->hCmdQueue);
1174     eventMbox_Stop (pTWD->hEventMbox);
1175     MacServices_restart (pTWD->hMacServices);
1176 
1177     status = twIf_Restart(pTWD->hTwIf);
1178 
1179     /* Call user stop callback */
1180     if (status != TXN_STATUS_PENDING)
1181     {
1182         TWD_StopComplete (hTWD);
1183     }
1184 
1185     return TI_OK;
1186 }
1187 
TWD_EnableExternalEvents(TI_HANDLE hTWD)1188 void TWD_EnableExternalEvents (TI_HANDLE hTWD)
1189 {
1190     TTwd        *pTWD = (TTwd *)hTWD;
1191 
1192     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_EnableExternalEvents: called\n");
1193 
1194     /*
1195      * Enable sleep after all firmware initializations completed
1196      * The awake was in the TWD_initHw phase
1197      */
1198     twIf_Sleep (pTWD->hTwIf);
1199 
1200     fwEvent_EnableExternalEvents (pTWD->hFwEvent);
1201 }
1202 
TWD_RecoveryEnabled(TI_HANDLE hTWD)1203 TI_BOOL TWD_RecoveryEnabled (TI_HANDLE hTWD)
1204 {
1205     TTwd  *pTWD = (TTwd *)hTWD;
1206 
1207     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_RecoveryEnabled: called\n");
1208 
1209     return pTWD->bRecoveryEnabled;
1210 }
1211 
TWD_GetMaxNumberOfCommandsInQueue(TI_HANDLE hTWD)1212 TI_UINT32 TWD_GetMaxNumberOfCommandsInQueue (TI_HANDLE hTWD)
1213 {
1214     TTwd *pTWD = (TTwd *)hTWD;
1215 
1216     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_GetMaxNumberOfCommandsInQueue: called\n");
1217 
1218     return cmdQueue_GetMaxNumberOfCommands (pTWD->hCmdQueue);
1219 }
1220 
TWD_SetPsMode(TI_HANDLE hTWD,E80211PsMode ePsMode,TI_BOOL bSendNullDataOnExit,TI_HANDLE hPowerSaveCompleteCb,TPowerSaveCompleteCb fPowerSaveCompleteCb,TPowerSaveResponseCb fPowerSaveResponseCb)1221 TI_STATUS TWD_SetPsMode (TI_HANDLE                   hTWD,
1222 						 E80211PsMode ePsMode,
1223 						 TI_BOOL bSendNullDataOnExit,
1224                          TI_HANDLE                   hPowerSaveCompleteCb,
1225                          TPowerSaveCompleteCb        fPowerSaveCompleteCb,
1226                          TPowerSaveResponseCb        fPowerSaveResponseCb)
1227 {
1228     TTwd *pTWD = (TTwd *)hTWD;
1229 
1230     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_SetPsMode: called\n");
1231 
1232     return MacServices_powerSrv_SetPsMode (pTWD->hMacServices,
1233                                            ePsMode,
1234                                            bSendNullDataOnExit,
1235                                            hPowerSaveCompleteCb,
1236                                            fPowerSaveCompleteCb,
1237                                            fPowerSaveResponseCb);
1238 }
1239 
TWD_GetPsStatus(TI_HANDLE hTWD)1240 TI_BOOL TWD_GetPsStatus (TI_HANDLE hTWD)
1241 {
1242     TTwd *pTWD = (TTwd *)hTWD;
1243 
1244     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_GetPsStatus: called\n");
1245 
1246     return MacServices_powerSrv_getPsStatus (pTWD->hMacServices);
1247 }
1248 
TWD_SetNullRateModulation(TI_HANDLE hTWD,TI_UINT16 rate)1249 TI_STATUS TWD_SetNullRateModulation (TI_HANDLE hTWD, TI_UINT16 rate)
1250 {
1251     TTwd *pTWD = (TTwd *)hTWD;
1252 
1253     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_SetRateModulation: called\n");
1254 
1255     MacServices_powerSrv_SetRateModulation (pTWD->hMacServices, rate);
1256 
1257     return TI_OK;
1258 }
1259 
TWD_UpdateDtimTbtt(TI_HANDLE hTWD,TI_UINT8 uDtimPeriod,TI_UINT16 uBeaconInterval)1260 void TWD_UpdateDtimTbtt (TI_HANDLE hTWD, TI_UINT8 uDtimPeriod, TI_UINT16 uBeaconInterval)
1261 {
1262     TTwd *pTWD = (TTwd *)hTWD;
1263 
1264     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_UpdateDtimTbtt: called\n");
1265 
1266     MacServices_scanSrv_UpdateDtimTbtt (pTWD->hMacServices, uDtimPeriod, uBeaconInterval);
1267 }
1268 
TWD_StartMeasurement(TI_HANDLE hTWD,TMeasurementRequest * pMsrRequest,TI_UINT32 uTimeToRequestExpiryMs,TCmdResponseCb fResponseCb,TI_HANDLE hResponseCb,TMeasurementSrvCompleteCb fCompleteCb,TI_HANDLE hCompleteCb)1269 TI_STATUS TWD_StartMeasurement (TI_HANDLE                   hTWD,
1270                                 TMeasurementRequest        *pMsrRequest,
1271                                 TI_UINT32                   uTimeToRequestExpiryMs,
1272                                 TCmdResponseCb              fResponseCb,
1273                                 TI_HANDLE                   hResponseCb,
1274                                 TMeasurementSrvCompleteCb   fCompleteCb,
1275                                 TI_HANDLE                   hCompleteCb)
1276 {
1277     TTwd *pTWD = (TTwd *)hTWD;
1278 
1279     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StartMeasurement: called\n");
1280 
1281     return MacServices_measurementSRV_startMeasurement (pTWD->hMacServices,
1282                                                         pMsrRequest,
1283                                                         uTimeToRequestExpiryMs,
1284                                                         fResponseCb,
1285                                                         hResponseCb,
1286                                                         fCompleteCb,
1287                                                         hCompleteCb);
1288 }
1289 
TWD_StopMeasurement(TI_HANDLE hTWD,TI_BOOL bSendNullData,TCmdResponseCb fResponseCb,TI_HANDLE hResponseCb)1290 TI_STATUS TWD_StopMeasurement (TI_HANDLE       	hTWD,
1291                                TI_BOOL        	bSendNullData,
1292                                TCmdResponseCb  	fResponseCb,
1293                                TI_HANDLE       	hResponseCb)
1294 {
1295     TTwd *pTWD = (TTwd *)hTWD;
1296 
1297     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopMeasurement: called\n");
1298 
1299     return MacServices_measurementSRV_stopMeasurement (pTWD->hMacServices,
1300                                                        bSendNullData,
1301                                                        fResponseCb,
1302                                                        hResponseCb);
1303 }
1304 
TWD_RegisterScanCompleteCb(TI_HANDLE hTWD,TScanSrvCompleteCb fScanCompleteCb,TI_HANDLE hScanCompleteCb)1305 TI_STATUS TWD_RegisterScanCompleteCb (TI_HANDLE            hTWD,
1306                                       TScanSrvCompleteCb   fScanCompleteCb,
1307                                       TI_HANDLE            hScanCompleteCb)
1308 {
1309     TTwd *pTWD = (TTwd *)hTWD;
1310 
1311     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_RegisterScanCompleteCb: called\n");
1312 
1313     MacServices_scanSRV_registerScanCompleteCB (pTWD->hMacServices,
1314                                                 fScanCompleteCb,
1315                                                 hScanCompleteCb);
1316 
1317     return TI_OK;
1318 }
1319 
1320 #ifdef TI_DBG
TWD_PrintMacServDebugStatus(TI_HANDLE hTWD)1321 TI_STATUS TWD_PrintMacServDebugStatus (TI_HANDLE hTWD)
1322 {
1323     TTwd *pTWD = (TTwd *)hTWD;
1324 
1325     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_PrintMacServDebugStatus: called\n");
1326 
1327     MacServices_scanSrv_printDebugStatus (pTWD->hMacServices);
1328 
1329     return TI_OK;
1330 }
1331 #endif
1332 
TWD_Scan(TI_HANDLE hTWD,TScanParams * pScanParams,EScanResultTag eScanTag,TI_BOOL bHighPriority,TI_BOOL bDriverMode,TI_BOOL bScanOnDriverModeError,E80211PsMode ePsRequest,TI_BOOL bSendNullData,TCmdResponseCb fResponseCb,TI_HANDLE hResponseCb)1333 TI_STATUS TWD_Scan (TI_HANDLE       hTWD,
1334                     TScanParams    	*pScanParams,
1335                     EScanResultTag 	eScanTag,
1336                     TI_BOOL        	bHighPriority,
1337                     TI_BOOL        	bDriverMode,
1338                     TI_BOOL        	bScanOnDriverModeError,
1339                     E80211PsMode   	ePsRequest,
1340                     TI_BOOL        	bSendNullData,
1341                     TCmdResponseCb 	fResponseCb,
1342                     TI_HANDLE      	hResponseCb)
1343 {
1344     TTwd *pTWD = (TTwd *)hTWD;
1345 
1346     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_Scan: called\n");
1347 
1348     return MacServices_scanSRV_scan (pTWD->hMacServices,
1349                                      pScanParams,
1350                                      eScanTag,
1351                                      bHighPriority,
1352                                      bDriverMode,
1353                                      bScanOnDriverModeError,
1354                                      ePsRequest,
1355                                      bSendNullData,
1356                                      fResponseCb,
1357                                      hResponseCb);
1358 }
1359 
TWD_StopScan(TI_HANDLE hTWD,EScanResultTag eScanTag,TI_BOOL bSendNullData,TCmdResponseCb fScanCommandResponseCb,TI_HANDLE hCb)1360 TI_STATUS TWD_StopScan (TI_HANDLE       hTWD,
1361                         EScanResultTag  eScanTag,
1362                         TI_BOOL         bSendNullData,
1363                         TCmdResponseCb  fScanCommandResponseCb,
1364                         TI_HANDLE       hCb)
1365 {
1366     TTwd *pTWD = (TTwd *)hTWD;
1367 
1368     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopScan: called\n");
1369 
1370     return MacServices_scanSRV_stopScan (pTWD->hMacServices,
1371                                          eScanTag,
1372                                          bSendNullData,
1373                                          fScanCommandResponseCb,
1374                                          hCb);
1375 }
1376 
TWD_StopScanOnFWReset(TI_HANDLE hTWD)1377 TI_STATUS TWD_StopScanOnFWReset (TI_HANDLE hTWD)
1378 {
1379     TTwd *pTWD = (TTwd *)hTWD;
1380 
1381     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopScanOnFWReset: called\n");
1382 
1383     return MacServices_scanSRV_stopOnFWReset (pTWD->hMacServices);
1384 }
1385 
TWD_StartConnectionScan(TI_HANDLE hTWD,TPeriodicScanParams * pPeriodicScanParams,EScanResultTag eScanTag,TI_UINT32 uPassiveScanDfsDwellTimeMs,TCmdResponseCb fResponseCb,TI_HANDLE hResponseCb)1386 TI_STATUS TWD_StartConnectionScan (TI_HANDLE              hTWD,
1387                                  TPeriodicScanParams    *pPeriodicScanParams,
1388                                  EScanResultTag         eScanTag,
1389                                  TI_UINT32              uPassiveScanDfsDwellTimeMs,
1390                                  TCmdResponseCb         fResponseCb,
1391                                  TI_HANDLE              hResponseCb)
1392 {
1393     TTwd *pTWD = (TTwd *)hTWD;
1394 
1395     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StartConnectionScan: called\n");
1396 
1397     return cmdBld_StartPeriodicScan (pTWD->hCmdBld, pPeriodicScanParams, eScanTag, uPassiveScanDfsDwellTimeMs,
1398                                      (void*)fResponseCb, hResponseCb);
1399 }
1400 
TWD_StopPeriodicScan(TI_HANDLE hTWD,EScanResultTag eScanTag,TCmdResponseCb fResponseCb,TI_HANDLE hResponseCb)1401 TI_STATUS TWD_StopPeriodicScan  (TI_HANDLE              hTWD,
1402                                  EScanResultTag         eScanTag,
1403                                  TCmdResponseCb         fResponseCb,
1404                                  TI_HANDLE              hResponseCb)
1405 {
1406     TTwd *pTWD = (TTwd *)hTWD;
1407 
1408     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_StopPeriodicScan: called\n");
1409 
1410     return cmdBld_StopPeriodicScan (pTWD->hCmdBld, eScanTag, (void*)fResponseCb, hResponseCb);
1411 }
1412 
TWD_readMem(TI_HANDLE hTWD,TFwDebugParams * pMemDebug,void * fCb,TI_HANDLE hCb)1413 TI_STATUS TWD_readMem (TI_HANDLE hTWD, TFwDebugParams* pMemDebug, void* fCb, TI_HANDLE hCb)
1414 {
1415     if (hTWD == NULL || pMemDebug == NULL)
1416 	{
1417 		return (TI_NOK);
1418 	}
1419 
1420 	TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_INFORMATION , "TWD_readMem: called\n");
1421 
1422 	if (fwDbg_ReadAddr(((TTwd *)hTWD)->hFwDbg,pMemDebug->addr,pMemDebug->length,pMemDebug->UBuf.buf8,(TFwDubCallback)fCb,hCb) == TI_NOK)
1423 	{
1424         TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_CONSOLE ,"TWD_readMem Error: fwDbg_handleCommand failed\n");
1425 		WLAN_OS_REPORT(("TWD_readMem Error: fwDbg_handleCommand failed\n"));
1426 		return TI_NOK;
1427 	}
1428 
1429 	return (TI_OK);
1430 }
1431 
TWD_writeMem(TI_HANDLE hTWD,TFwDebugParams * pMemDebug,void * fCb,TI_HANDLE hCb)1432 TI_STATUS TWD_writeMem (TI_HANDLE hTWD, TFwDebugParams* pMemDebug, void* fCb, TI_HANDLE hCb)
1433 {
1434     if (hTWD == NULL || pMemDebug == NULL)
1435 	{
1436 		return (TI_NOK);
1437 	}
1438 
1439 	TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_INFORMATION , "TWD_writeMem: called\n");
1440 
1441 	if (fwDbg_WriteAddr(((TTwd *)hTWD)->hFwDbg,pMemDebug->addr,pMemDebug->length,pMemDebug->UBuf.buf8,(TFwDubCallback)fCb,hCb) == TI_NOK)
1442 	{
1443         TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_CONSOLE ,"TWD_writeMem Error: fwDbg_handleCommand failed\n");
1444 		WLAN_OS_REPORT(("TWD_writeMem Error: fwDbg_handleCommand failed\n"));
1445 		return TI_NOK;
1446 	}
1447 
1448 	return(TI_OK);
1449 }
1450 
TWD_isValidMemoryAddr(TI_HANDLE hTWD,TFwDebugParams * pMemDebug)1451 TI_BOOL TWD_isValidMemoryAddr (TI_HANDLE hTWD, TFwDebugParams* pMemDebug)
1452 {
1453 	if (hTWD == NULL || pMemDebug == NULL)
1454 	{
1455 		return TI_FALSE;
1456 	}
1457 
1458 	TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_INFORMATION , "TWD_isValidMemoryAddr: called\n");
1459 
1460 	return fwDbg_isValidMemoryAddr(((TTwd *)hTWD)->hFwDbg,pMemDebug->addr,pMemDebug->length);
1461 }
1462 
TWD_isValidRegAddr(TI_HANDLE hTWD,TFwDebugParams * pMemDebug)1463 TI_BOOL TWD_isValidRegAddr (TI_HANDLE hTWD, TFwDebugParams* pMemDebug)
1464 {
1465     if (hTWD == NULL || pMemDebug == NULL )
1466 	{
1467 		return TI_FALSE;
1468 	}
1469 
1470 	TRACE0(((TTwd *)hTWD)->hReport, REPORT_SEVERITY_INFORMATION , "TWD_isValidRegAddr: called\n");
1471 
1472 	return fwDbg_isValidRegAddr(((TTwd *)hTWD)->hFwDbg,pMemDebug->addr,pMemDebug->length);
1473 }
1474 
1475 /**
1476  * \brief Set Template Frame
1477  *
1478  * \param hTWD 				- TWD module object handle
1479  * \param pMib      		- Pointer to Input MIB Structure
1480  * \return TI_OK on success or TI_NOK on failure
1481  *
1482  * \par Description
1483  * Static function
1484  * Configure/Interrogate/Modulate the Frame Rate if needed (according to Templete Type)
1485  * and then write the MIB TemplateFrame to the FW
1486  *
1487  * \sa
1488  */
TWD_WriteMibTemplateFrame(TI_HANDLE hTWD,TMib * pMib)1489 static TI_STATUS TWD_WriteMibTemplateFrame (TI_HANDLE hTWD, TMib* pMib)
1490 {
1491     TTwd  *pTWD = (TTwd *)hTWD;
1492     TSetTemplate  tSetTemplate;
1493     TI_UINT32  uRateMask = RATE_TO_MASK(pMib->aData.TemplateFrame.Rate);
1494 
1495     /*
1496      * Construct the template MIB element
1497      */
1498     switch(pMib->aData.TemplateFrame.FrameType)
1499     {
1500     case TEMPLATE_TYPE_BEACON:
1501         tSetTemplate.type = BEACON_TEMPLATE;
1502         break;
1503 
1504     case TEMPLATE_TYPE_PROBE_REQUEST:
1505         tSetTemplate.type = PROBE_REQUEST_TEMPLATE;
1506         tSetTemplate.eBand = RADIO_BAND_2_4_GHZ; /* needed for GWSI, if so band must also be passed to choose correct template (G or A) */
1507         break;
1508 
1509     case TEMPLATE_TYPE_NULL_FRAME:
1510         tSetTemplate.type = NULL_DATA_TEMPLATE;
1511         MacServices_powerSrv_SetRateModulation (pTWD->hMacServices, (TI_UINT16)uRateMask);
1512         break;
1513 
1514     case TEMPLATE_TYPE_PROBE_RESPONSE:
1515         tSetTemplate.type = PROBE_RESPONSE_TEMPLATE;
1516         break;
1517 
1518     case TEMPLATE_TYPE_QOS_NULL_FRAME:
1519         tSetTemplate.type = QOS_NULL_DATA_TEMPLATE;
1520         break;
1521 
1522     case TEMPLATE_TYPE_PS_POLL:
1523         tSetTemplate.type = PS_POLL_TEMPLATE;
1524         break;
1525 
1526     default:
1527         TRACE1(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_WriteMibTemplateFrame - ERROR - template is not supported, %d\n", pMib->aData.TemplateFrame.FrameType);
1528         return PARAM_NOT_SUPPORTED;
1529     }
1530 
1531     tSetTemplate.len = pMib->aData.TemplateFrame.Length;
1532     tSetTemplate.ptr = (TI_UINT8 *) &(pMib->aData.TemplateFrame.Data);
1533     tSetTemplate.uRateMask = uRateMask;
1534 
1535     return TWD_CmdTemplate (hTWD, &tSetTemplate, NULL, NULL);
1536 }
1537 
1538 /**
1539  * \brief Set Beacon Filter IE Table
1540  *
1541  * \param hTWD 				- TWD module object handle
1542  * \param pMib      		- Pointer to Input MIB Structure
1543  * \return TI_OK on success or TI_NOK on failure
1544  *
1545  * \par Description
1546  * Static function
1547  * Configure the MIB Beacon Filter IE table
1548  *
1549  * \sa
1550  */
TWD_WriteMibBeaconFilterIETable(TI_HANDLE hTWD,TMib * pMib)1551 static TI_STATUS TWD_WriteMibBeaconFilterIETable (TI_HANDLE hTWD, TMib *pMib)
1552 {
1553     TTwd  *pTWD = (TTwd *)hTWD;
1554     TI_UINT8 numOf221IE = 0;
1555     TI_UINT8 i = 0;
1556     TI_UINT8 IETableLen = 0;
1557     TI_UINT8 numOfIEs = 0;
1558     TI_UINT8 *IETable = NULL;
1559 
1560     numOfIEs = pMib->aData.BeaconFilter.iNumberOfIEs;
1561     IETable = pMib->aData.BeaconFilter.iIETable;
1562     /* Find the actual IETableLen */
1563     for (i = 0; i < numOfIEs; i++)
1564     {
1565         if (IETable[IETableLen] == 0xdd)
1566         {
1567              IETableLen += 8;
1568              numOf221IE++;
1569         }
1570         else
1571         {
1572             IETableLen += 2;
1573         }
1574     }
1575 
1576     TRACE4(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_WriteMibBeaconFilterIETable: IETable=0x%x Num Of IE=%d ( including %d 221 ) - Table Len=%d\n", IETable, numOfIEs, numOf221IE, IETableLen);
1577 
1578     return TWD_CfgBeaconFilterTable (hTWD, numOfIEs, IETable, IETableLen);
1579 }
1580 
1581 /**
1582  * \brief Set Tx Rate Policy
1583  *
1584  * \param hTWD 				- TWD module object handle
1585  * \param pMib      		- Pointer to Input MIB Structure
1586  * \return TI_OK on success or TI_NOK on failure
1587  *
1588  * \par Description
1589  * Static function
1590  * Coordinates between legacy TxRatePolicy implementation and the MIB format:
1591  * Converts the pGwsi_txRatePolicy back to command builder commands.
1592  * Activates the TWD_set function.
1593  *
1594  * \sa
1595  */
TWD_WriteMibTxRatePolicy(TI_HANDLE hTWD,TMib * pMib)1596 static TI_STATUS TWD_WriteMibTxRatePolicy (TI_HANDLE hTWD, TMib* pMib)
1597 {
1598     TTwd   *pTWD = (TTwd *)hTWD;
1599 
1600 #ifdef TI_DBG
1601     if (NULL == pMib)
1602     {
1603         TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "ERROR: TWD_WriteMibTxRatePolicy pMib=NULL !!!");
1604 		return TI_NOK;
1605     }
1606 #endif /* TI_DBG */
1607 
1608     return cmdBld_CfgTxRatePolicy (pTWD->hCmdBld, &pMib->aData.txRatePolicy, NULL, NULL);
1609 }
1610 
TWD_WriteMib(TI_HANDLE hTWD,TMib * pMib)1611 TI_STATUS TWD_WriteMib (TI_HANDLE hTWD, TMib *pMib)
1612 {
1613     TTwd *pTWD = (TTwd *)hTWD;
1614 
1615 #ifdef TI_DBG
1616     TRACE1(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_WriteMib :pMib %p:\n",pMib);
1617 
1618     TRACE1(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_WriteMib :aMib %x:\n",pMib->aMib);
1619 
1620     TRACE_INFO_HEX(pTWD->hReport, (TI_UINT8*)pMib, TI_MIN (sizeof(TMib), pMib->Length));
1621 #endif /* TI_DBG */
1622 
1623     if (NULL == pMib)
1624     {
1625         TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_WriteMib :pMib = NULL !!\n");
1626         return PARAM_VALUE_NOT_VALID;
1627     }
1628 
1629     switch (pMib->aMib)
1630     {
1631     case MIB_dot11MaxReceiveLifetime:
1632         return cmdBld_CfgRxMsduLifeTime (pTWD->hCmdBld, pMib->aData.MaxReceiveLifeTime * 1024, (void *)NULL, (void *)NULL);
1633 
1634     case MIB_ctsToSelf:
1635         return cmdBld_CfgCtsProtection (pTWD->hCmdBld, (TI_UINT8)pMib->aData.CTSToSelfEnable, (void *)NULL, (TI_HANDLE)NULL);
1636 
1637     case MIB_dot11GroupAddressesTable:
1638         {
1639             if (NULL == pMib->aData.GroupAddressTable.aGroupTable)
1640             {
1641                 TRACE0(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_WriteMib(MIB_dot11GroupAddressesTable) :GroupTable = NULL !!\n");
1642                 return PARAM_VALUE_NOT_VALID;
1643             }
1644 
1645             return TWD_CfgGroupAddressTable (hTWD,
1646                                              pMib->aData.GroupAddressTable.nNumberOfAddresses,
1647                                              pMib->aData.GroupAddressTable.aGroupTable,
1648                                              pMib->aData.GroupAddressTable.bFilteringEnable);
1649         }
1650 
1651     case MIB_arpIpAddressesTable:
1652         {
1653             TIpAddr IpAddress;
1654 
1655             IP_COPY (IpAddress, pMib->aData.ArpIpAddressesTable.addr);
1656 
1657             TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "TWD_WriteMib(MIB_arpIpAddressesTable) IpAddress:\n");
1658             TRACE_INFO_HEX(pTWD->hReport, (TI_UINT8*)&IpAddress, 4);
1659 
1660             return cmdBld_CfgArpIpAddrTable (pTWD->hCmdBld,
1661                                              IpAddress,
1662                                              (TI_BOOL)pMib->aData.ArpIpAddressesTable.FilteringEnable,
1663                                              IP_VER_4,
1664                                              NULL,
1665                                              NULL);
1666         }
1667 
1668     case MIB_templateFrame:
1669         return TWD_WriteMibTemplateFrame (hTWD, pMib);
1670 
1671     case MIB_beaconFilterIETable:
1672         return TWD_WriteMibBeaconFilterIETable (hTWD, pMib);
1673 
1674     case MIB_rxFilter:
1675         {
1676             TI_UINT32  uRxFilter = 0;
1677             TI_UINT8   uMibRxFilter = pMib->aData.RxFilter;
1678 
1679             if (uMibRxFilter & MIB_RX_FILTER_PROMISCOUS_SET)
1680             {
1681                 TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "\n TWD_WriteMib MIB_rxFilter - RX_CFG_ENABLE_ANY_DEST_MAC\n");
1682                 uRxFilter = RX_CFG_ENABLE_ANY_DEST_MAC;
1683             }
1684             else
1685             {
1686                 uRxFilter = RX_CFG_ENABLE_ONLY_MY_DEST_MAC;
1687                 TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "\n halCtrl_WriteMib MIB_rxFilter - RX_CFG_ENABLE_ONLY_MY_DEST_MAC\n");
1688             }
1689 
1690             if ((uMibRxFilter & MIB_RX_FILTER_BSSID_SET) != 0)
1691             {
1692                 uRxFilter = uRxFilter | RX_CFG_ENABLE_ONLY_MY_BSSID;
1693                 TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "\n halCtrl_WriteMib MIB_rxFilter - RX_CFG_ENABLE_ONLY_MY_BSSID\n");
1694             }
1695             else
1696             {
1697                 uRxFilter = uRxFilter | RX_CFG_ENABLE_ANY_BSSID;
1698                 TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION, "\n halCtrl_WriteMib MIB_rxFilter - RX_CFG_ENABLE_ANY_BSSID\n");
1699             }
1700 
1701             /*
1702              * Activates the TWD_setRxFilters function
1703              */
1704             return TWD_CfgRx (hTWD, uRxFilter, RX_FILTER_OPTION_DEF);
1705         }
1706 
1707     case MIB_txRatePolicy:
1708         return TWD_WriteMibTxRatePolicy (hTWD, pMib);
1709 
1710     default:
1711         TRACE1(pTWD->hReport, REPORT_SEVERITY_ERROR, "TWD_WriteMib - ERROR - MIB element not supported, %d\n", pMib->aMib);
1712 
1713         return TI_NOK;
1714 
1715     } /* switch */
1716 }
1717 
TWD_ReadMib(TI_HANDLE hTWD,TI_HANDLE hCb,void * fCb,void * pCb)1718 TI_STATUS TWD_ReadMib (TI_HANDLE hTWD, TI_HANDLE hCb, void* fCb, void* pCb)
1719 {
1720     TTwd *pTWD = (TTwd *)hTWD;
1721 
1722     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_ReadMib: called\n");
1723 
1724     return cmdBld_ReadMib (pTWD->hCmdBld, hCb, fCb, pCb);
1725 }
1726 
TWD_DisableInterrupts(TI_HANDLE hTWD)1727 void TWD_DisableInterrupts(TI_HANDLE hTWD)
1728 {
1729     TTwd    *pTWD = (TTwd *)hTWD;
1730 
1731     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_DisableInterrupts: called\n");
1732 
1733     fwEvent_DisableInterrupts(pTWD->hFwEvent);
1734 }
1735 
TWD_EnableInterrupts(TI_HANDLE hTWD)1736 void TWD_EnableInterrupts(TI_HANDLE hTWD)
1737 {
1738     TTwd    *pTWD = (TTwd *)hTWD;
1739 
1740     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_EnableInterrupts: called\n");
1741 
1742     fwEvent_EnableInterrupts(pTWD->hFwEvent);
1743 }
1744 
TWD_TranslateToFwTime(TI_HANDLE hTWD,TI_UINT32 uHostTime)1745 TI_UINT32 TWD_TranslateToFwTime (TI_HANDLE hTWD, TI_UINT32 uHostTime)
1746 {
1747     TTwd    *pTWD = (TTwd *)hTWD;
1748 
1749     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_TranslateToFwTime: called\n");
1750 
1751     return fwEvent_TranslateToFwTime (pTWD->hFwEvent, uHostTime);
1752 }
1753 
TWD_GetTwdHtCapabilities(TI_HANDLE hTWD,TTwdHtCapabilities ** pTwdHtCapabilities)1754 void TWD_GetTwdHtCapabilities (TI_HANDLE hTWD, TTwdHtCapabilities **pTwdHtCapabilities)
1755 {
1756     TTwd        *pTWD        = (TTwd *)hTWD;
1757     TWlanParams *pWlanParams = &DB_WLAN(pTWD->hCmdBld);
1758 
1759     TRACE0(pTWD->hReport, REPORT_SEVERITY_INFORMATION , "TWD_GetTwdHtCapabilities: called\n");
1760 
1761     *pTwdHtCapabilities = &(pWlanParams->tTwdHtCapabilities);
1762 }
1763 
1764 /**
1765  *  \brief TWD get FEM type
1766  *  *
1767  * \param  Handle        	- handle to object
1768  * \return uint8
1769  *
1770  * \par Description
1771  * The function return the Front end module that was read frm FW register *
1772  * \sa
1773  */
TWD_GetFEMType(TI_HANDLE hTWD)1774 TI_UINT8 TWD_GetFEMType (TI_HANDLE hTWD)
1775 {
1776   TTwd        *pTWD        = (TTwd *)hTWD;
1777   IniFileGeneralParam *pGenParams = &DB_GEN(pTWD->hCmdBld);
1778 
1779   return pGenParams->TXBiPFEMManufacturer;
1780 
1781 }
1782 
1783 /**
1784  *  \brief TWD end function of read radio state machine
1785  *  *  *
1786  * \param  Handle        	- handle to object
1787  * \return void
1788  *
1789  * \par Description
1790  * The function calling to HwInit call back function, after finish reading FEM registers *
1791  * \sa
1792  */
TWD_FinalizeFEMRead(TI_HANDLE hTWD)1793 void TWD_FinalizeFEMRead(TI_HANDLE hTWD)
1794 {
1795   TTwd *pTWD = (TTwd *)hTWD;
1796 
1797   (*pTWD->fInitHwCb) (pTWD->hUser, TI_OK);
1798 }
1799 
1800 
1801 
1802 
TWD_FinalizePolarityRead(TI_HANDLE hTWD)1803 void TWD_FinalizePolarityRead(TI_HANDLE hTWD)
1804 {
1805   TTwd *pTWD = (TTwd *)hTWD;
1806   /*  allways read FEM type from Radio Registers */
1807    hwInit_ReadRadioParams(pTWD->hHwInit);
1808 }
1809