Home | History | Annotate | Download | only in Tx_Ctrl_Blk
      1 /****************************************************************************
      2 **+-----------------------------------------------------------------------+**
      3 **|                                                                       |**
      4 **| Copyright(c) 1998 - 2008 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 
     36 /****************************************************************************
     37  *
     38  *   MODULE:    TNETW_Driver.c
     39  *   PURPOSE:   TNETW_Driver layer used to handle the MAC Services
     40  *              and the HAL Modules
     41  *
     42  ****************************************************************************/
     43 
     44 #include "commonTypes.h"
     45 #include "report.h"
     46 #include "TNETW_Driver_api.h"
     47 #include "MacServices_api.h"
     48 #include "txCtrlBlk_api.h"
     49 #include "txHwQueue_api.h"
     50 #include "txXfer_api.h"
     51 #include "txResult_api.h"
     52 #include "rxXfer_api.h"
     53 #include "TNETWIF.h"
     54 #include "FwEvent_api.h"
     55 #include "CmdMBox_api.h"
     56 #include "CmdQueue_api.h"
     57 #include "eventMbox_api.h"
     58 #ifdef TI_DBG
     59 #include "DebugTraceXfer_api.h"
     60 #endif /* TI_DBG */
     61 #include "osApi.h"
     62 #include "TNETW_Driver.h"
     63 #include "recoveryCtrl_API.h"
     64 #include "HwInit_api.h"
     65 
     66 static TI_STATUS TnetwDrv_SetInitParams (TI_HANDLE hTnetwDrv, TnetwDrv_InitParams_t* pInitParams);
     67 
     68 #ifdef GWSI_LIB
     69 void GWSI_FinalizeDownload(TI_HANDLE hGwsiMgr, TI_STATUS eStatus);
     70 #endif
     71 
     72 void TnetwDrv_TxXferDone (TI_HANDLE hTnetwDrv, txCtrlBlkEntry_t *pPktCtrlBlk);
     73 void TnetwDrv_TxComplete (TI_HANDLE hTnetwDrv, TxResultDescriptor_t *pTxResultInfo);
     74 void TnetwDrv_TxXferDebug (TI_HANDLE hTnetwDrv, txCtrlBlkEntry_t *pPktCtrlBlk, UINT32 uDebugInfo);
     75 static void TnetwDrv_ConfigureCb (TI_HANDLE hTnetwDrv);
     76 static void TnetwDrv_ConfigureCb1 (TI_HANDLE hTnetwDrv);
     77 
     78 
     79 /****************************************************************************/
     80 
     81 
     82 /****************************************************************************/
     83 /*                      TnetwDrv_Create()
     84  ****************************************************************************
     85  * DESCRIPTION: Create the Module
     86  *
     87  * INPUTS:  Handle to the OS
     88  *
     89  * OUTPUT:
     90  *
     91  * RETURNS: Handle to the module on success or NULL on failure
     92  ****************************************************************************/
     93 TI_HANDLE TnetwDrv_Create (TI_HANDLE hOs)
     94 {
     95     TnetwDrv_t *pTnetwDrv;
     96 
     97     /* Allocate the TNETW_Driver module */
     98     pTnetwDrv = (TnetwDrv_t *)os_memoryAlloc (hOs, sizeof(TnetwDrv_t));
     99     if (pTnetwDrv == NULL)
    100         return NULL;
    101 
    102     os_memoryZero (hOs, pTnetwDrv, sizeof(TnetwDrv_t));
    103 
    104     pTnetwDrv->hOs = hOs;
    105 
    106     /* Create the HAL Ctrl module */
    107     pTnetwDrv->hHalCtrl = whalCtrl_Create(hOs);
    108     if (pTnetwDrv->hHalCtrl == NULL)
    109     {
    110         WLAN_OS_REPORT(("TnetwDrv whalCtrl_Create failed!!!\n"));
    111         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    112         return NULL;
    113     }
    114 
    115     pTnetwDrv->hTNETWIF = whalCtrl_GetTnetwifHandle (pTnetwDrv->hHalCtrl);
    116 
    117     /* Create the MAC Services module */
    118     pTnetwDrv->hMacServices = MacServices_create(hOs);
    119     if (pTnetwDrv->hMacServices == NULL)
    120     {
    121         WLAN_OS_REPORT(("TnetwDrv MacServices_create failed!!!\n"));
    122         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    123         return NULL;
    124     }
    125 
    126     /* Create the Ctrl module */
    127     pTnetwDrv->hCmdQueue = CmdQueue_Create(hOs);
    128     if (pTnetwDrv->hCmdQueue == NULL)
    129     {
    130         WLAN_OS_REPORT(("TnetwDrv CmdQueue_Create failed!!!\n"));
    131         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    132         return NULL;
    133     }
    134 
    135     /*
    136      * Create the FW-Transfer modules:
    137      */
    138 
    139     pTnetwDrv->hTxXfer = txXfer_Create(hOs);
    140     if (pTnetwDrv->hTxXfer == NULL)
    141     {
    142         WLAN_OS_REPORT(("TnetwDrv txXfer_Create failed!!!\n"));
    143         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    144         return NULL;
    145     }
    146 
    147     pTnetwDrv->hTxResult = txResult_Create(hOs);
    148     if (pTnetwDrv->hTxResult == NULL)
    149     {
    150         WLAN_OS_REPORT(("TnetwDrv txResult_Create failed!!!\n"));
    151         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    152         return NULL;
    153     }
    154 
    155     pTnetwDrv->hRxXfer = rxXfer_Create(hOs);
    156     if (pTnetwDrv->hRxXfer == NULL)
    157     {
    158         WLAN_OS_REPORT(("TnetwDrv rxXfer_Create failed!!!\n"));
    159         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    160         return NULL;
    161     }
    162 
    163     pTnetwDrv->hFwEvent = FwEvent_Create(hOs);
    164     if (pTnetwDrv->hFwEvent == NULL)
    165     {
    166         WLAN_OS_REPORT(("TnetwDrv FwEvent_Create failed!!!\n"));
    167         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    168         return NULL;
    169     }
    170 
    171     pTnetwDrv->hEventMbox = eventMbox_Create(hOs);
    172     if (pTnetwDrv->hEventMbox == NULL)
    173     {
    174         WLAN_OS_REPORT(("TnetwDrv eventMbox_Create failed!!!\n"));
    175         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    176         return NULL;
    177     }
    178 
    179 #ifdef TI_DBG
    180     pTnetwDrv->hDebugTrace = debugTrace_Create(hOs);
    181     if (pTnetwDrv->hDebugTrace == NULL)
    182     {
    183         WLAN_OS_REPORT(("TnetwDrv debugTrace_Create failed!!!\n"));
    184         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    185         return NULL;
    186     }
    187 #endif /* TI_DBG */
    188 
    189     pTnetwDrv->hCmdMBox = CmdMBox_Create(hOs);
    190     if (pTnetwDrv->hCmdMBox == NULL)
    191     {
    192         WLAN_OS_REPORT(("TnetwDrv CmdMBox_Create failed!!!\n"));
    193         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    194         return NULL;
    195     }
    196 
    197     /*
    198      * Create the Data-Services modules:
    199      */
    200 
    201     pTnetwDrv->hTxCtrlBlk = txCtrlBlk_Create(hOs);
    202     if (pTnetwDrv->hTxCtrlBlk == NULL)
    203     {
    204         WLAN_OS_REPORT(("TnetwDrv txCtrlBlk_Create failed!!!\n"));
    205         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    206         return NULL;
    207     }
    208 
    209     pTnetwDrv->hTxHwQueue = txHwQueue_Create(hOs);
    210     if (pTnetwDrv->hTxHwQueue == NULL)
    211     {
    212         WLAN_OS_REPORT(("TnetwDrv txHwQueue_Create failed!!!\n"));
    213         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    214         return NULL;
    215     }
    216 
    217 #if !defined(GWSI_DRIVER) && !defined(GWSI_LIB)
    218     pTnetwDrv->hRecoveryCtrl = recoveryCtrl_create(hOs);
    219 #ifdef USE_RECOVERY
    220     if (pTnetwDrv->hRecoveryCtrl == NULL)
    221     {
    222         WLAN_OS_REPORT(("TnetwDrv recoveryCtrl_create failed!!!\n"));
    223         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    224         return NULL;
    225     }
    226 #endif /* USE_RECOVERY */
    227     pTnetwDrv->hHwInit = hwInit_create(hOs);
    228 #ifdef USE_RECOVERY
    229     if (pTnetwDrv->hHwInit == NULL)
    230     {
    231         WLAN_OS_REPORT(("TnetwDrv hwInit_create failed!!!\n"));
    232         TnetwDrv_Destroy((TI_HANDLE)pTnetwDrv);
    233         return NULL;
    234     }
    235 #endif /* USE_RECOVERY */
    236     pTnetwDrv->bRecoveryFlag = FALSE; /* init value is not Recovery */
    237 #endif
    238     WLAN_INIT_REPORT (("TnetwDrv_Create: CREATED !!!\n"));
    239 
    240     return (TI_HANDLE)pTnetwDrv;
    241 }
    242 
    243 
    244 
    245 /****************************************************************************/
    246 /*                      TnetwDrv_Destroy()
    247  ****************************************************************************
    248  * DESCRIPTION: Clear The module
    249  *
    250  * INPUTS:  Handle to the module
    251  *
    252  * OUTPUT:
    253  *
    254  * RETURNS:
    255  ****************************************************************************/
    256 void TnetwDrv_Destroy (TI_HANDLE hTnetwDrv)
    257 {
    258 
    259     TnetwDrv_t *pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    260 
    261     WLAN_INIT_REPORT(("TnetwDrv_Destroy !!!\n"));
    262     if (pTnetwDrv == NULL)
    263     {
    264         return;
    265     }
    266 
    267     /* free the hal ctrl */
    268     if (pTnetwDrv->hHalCtrl != NULL)
    269     {
    270         whalCtrl_Destroy(pTnetwDrv->hHalCtrl);
    271         pTnetwDrv->hHalCtrl = NULL;
    272     }
    273     WLAN_INIT_REPORT(("TNETW_Driver_Destroy hHalCtrl released!!!\n"));
    274 
    275     /* free the MAC Services */
    276     if (pTnetwDrv->hMacServices != NULL)
    277     {
    278         MacServices_destroy(pTnetwDrv->hMacServices);
    279         pTnetwDrv->hMacServices = NULL;
    280     }
    281     WLAN_INIT_REPORT(("TNETW_Driver_Destroy hMacServices released!!!\n"));
    282 
    283     /*
    284      * Free the Ctrl modules
    285      */
    286     if (pTnetwDrv->hCmdQueue != NULL)
    287     {
    288         CmdQueue_Destroy(pTnetwDrv->hCmdQueue);
    289         pTnetwDrv->hCmdQueue = NULL;
    290     }
    291 
    292     /*
    293      * Free the FW-Transfer modules:
    294      */
    295 
    296     if (pTnetwDrv->hTxXfer != NULL)
    297     {
    298         txXfer_Destroy(pTnetwDrv->hTxXfer);
    299         pTnetwDrv->hTxXfer = NULL;
    300     }
    301 
    302     if (pTnetwDrv->hTxResult != NULL)
    303     {
    304         txResult_Destroy(pTnetwDrv->hTxResult);
    305         pTnetwDrv->hTxResult = NULL;
    306     }
    307 
    308     if (pTnetwDrv->hRxXfer != NULL)
    309     {
    310         rxXfer_Destroy(pTnetwDrv->hRxXfer);
    311         pTnetwDrv->hRxXfer = NULL;
    312     }
    313 
    314     if (pTnetwDrv->hEventMbox != NULL)
    315     {
    316         eventMbox_Destroy(pTnetwDrv->hEventMbox);
    317         pTnetwDrv->hEventMbox = NULL;
    318     }
    319 
    320 #ifdef TI_DBG
    321     if (pTnetwDrv->hDebugTrace != NULL)
    322     {
    323         debugTrace_Destroy(pTnetwDrv->hDebugTrace);
    324         pTnetwDrv->hDebugTrace = NULL;
    325     }
    326 #endif /* TI_DBG */
    327 
    328     if (pTnetwDrv->hFwEvent != NULL)
    329     {
    330         FwEvent_Destroy(pTnetwDrv->hFwEvent);
    331         pTnetwDrv->hFwEvent = NULL;
    332     }
    333 
    334     if (pTnetwDrv->hCmdMBox != NULL)
    335     {
    336         CmdMBox_Destroy(pTnetwDrv->hCmdMBox);
    337         pTnetwDrv->hCmdMBox = NULL;
    338     }
    339 
    340     /*
    341      * Free the Data-Services modules:
    342      */
    343 
    344     if (pTnetwDrv->hTxCtrlBlk != NULL)
    345     {
    346         txCtrlBlk_Destroy(pTnetwDrv->hTxCtrlBlk);
    347         pTnetwDrv->hTxCtrlBlk = NULL;
    348     }
    349 
    350     if (pTnetwDrv->hTxHwQueue != NULL)
    351     {
    352         txHwQueue_Destroy(pTnetwDrv->hTxHwQueue);
    353         pTnetwDrv->hTxHwQueue = NULL;
    354     }
    355 
    356 #if !defined(GWSI_DRIVER) && !defined(GWSI_LIB)
    357     if (pTnetwDrv->hRecoveryCtrl != NULL)
    358     {
    359         recoveryCtrl_destroy(pTnetwDrv->hRecoveryCtrl);
    360         pTnetwDrv->hRecoveryCtrl = NULL;
    361     }
    362 
    363     if (pTnetwDrv->hHwInit != NULL)
    364     {
    365         hwInit_destroy(pTnetwDrv->hHwInit);
    366         pTnetwDrv->hHwInit = NULL;
    367     }
    368 #endif
    369 
    370     /* free the TNETW driver */
    371     if ( NULL != pTnetwDrv->pInitTableCopy )
    372     {
    373         os_memoryFree( pTnetwDrv->hOs, pTnetwDrv->pInitTableCopy, sizeof(TnetwDrv_InitParams_t) );
    374         pTnetwDrv->pInitTableCopy = NULL;
    375     }
    376 
    377     os_memoryFree(pTnetwDrv->hOs, (TI_HANDLE)pTnetwDrv, sizeof(TnetwDrv_t));
    378     pTnetwDrv = NULL;
    379 
    380     WLAN_INIT_REPORT(("TNETW_Driver_Destroy pTNETW_Driver released!!!\n"));
    381 
    382     return;
    383 }
    384 
    385 
    386 /****************************************************************************/
    387 /*                      TnetwDrv_Init()
    388  ****************************************************************************
    389  * DESCRIPTION: TNETW Driver Init
    390  *
    391  * INPUTS:
    392  *
    393  * OUTPUT:
    394  *
    395  * RETURNS:
    396  ****************************************************************************/
    397 TI_STATUS TnetwDrv_Init (TI_HANDLE hTnetwDrv, TI_HANDLE hReport, TI_HANDLE hMemMgr, TI_HANDLE hUser, UINT32 *pFWImage, TnetwDrv_InitParams_t* pInitParams, TnetDrv_callback_t fUserConf)
    398 {
    399     TnetwDrv_t *pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    400     whalCtrl_config_t       whalCtrl_config;
    401     TI_STATUS               status;
    402 
    403     pTnetwDrv->bInitSuccess = FALSE;
    404     pTnetwDrv->hUser = hUser;
    405     pTnetwDrv->fUserConf = fUserConf;
    406     pTnetwDrv->hReport = hReport;
    407     pTnetwDrv->hMemMgr = hMemMgr;
    408     pTnetwDrv->hWhalParams = whalCtrl_GetWhalParams (pTnetwDrv->hHalCtrl);
    409 
    410     WLAN_REPORT_INIT(pTnetwDrv->hReport, HAL_CTRL_MODULE_LOG,
    411         ("TnetwDrv_Init %x\n",hReport));
    412 
    413     if (NULL != pInitParams)
    414     {
    415         if (OK != TnetwDrv_SetInitParams (hTnetwDrv, (TnetwDrv_InitParams_t *)pInitParams))
    416         {
    417             TnetwDrv_Destroy (hTnetwDrv);
    418             return NOK;
    419         }
    420     }
    421 
    422     /*
    423      * Configure the HAL Ctrl
    424      */
    425     whalCtrl_config.hMemMgr             = hMemMgr;
    426     whalCtrl_config.hReport             = hReport;
    427     whalCtrl_config.hFwEvent            = pTnetwDrv->hFwEvent;
    428     whalCtrl_config.hRxXfer             = pTnetwDrv->hRxXfer;
    429     whalCtrl_config.hTxXfer             = pTnetwDrv->hTxXfer;
    430     whalCtrl_config.hTxHwQueue          = pTnetwDrv->hTxHwQueue;
    431     whalCtrl_config.hTxResult           = pTnetwDrv->hTxResult;
    432     whalCtrl_config.hEventMbox          = pTnetwDrv->hEventMbox;
    433 
    434         /* CB at the end of TnetwDrv_Configure(). not called if no registration was done */
    435         pTnetwDrv->fConfigureCmplteteCB     = NULL;
    436         pTnetwDrv->hConfigureCompleteOBj    = NULL;
    437     pTnetwDrv->fConfigureEndCB = TnetwDrv_ConfigureCb1;
    438     pTnetwDrv->fConfigureEndObj= hTnetwDrv;
    439 
    440     whalCtrl_config.hCmdQueue           = pTnetwDrv->hCmdQueue;
    441 #ifdef TI_DBG
    442     whalCtrl_config.hDebugTrace         = pTnetwDrv->hDebugTrace;
    443 #endif /* TI_DBG */
    444 
    445     /* Call the config func */
    446     if ((status = whalCtrl_Config (pTnetwDrv->hHalCtrl, hTnetwDrv, &whalCtrl_config, pFWImage)) == TNETWIF_ERROR)
    447     {
    448         WLAN_OS_REPORT(("TNETW_Driver whalCtrl_Config failed!!!\n"));
    449         TnetwDrv_Destroy (hTnetwDrv);
    450         return NOK;
    451     }
    452 
    453     return status;
    454 }
    455 
    456 
    457 /****************************************************************************
    458  * DESCRIPTION: Configure the TNET Driver Module callback
    459  *
    460  * INPUTS:
    461  *
    462  * OUTPUT:
    463  *
    464  * RETURNS: OK if succeeded, NOK if failed in HW configuration.
    465  ****************************************************************************/
    466 void TnetwDrv_ConfigureCb (TI_HANDLE hTnetwDrv)
    467 {
    468     TnetwDrv_t *pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    469 
    470     /* Configure the Tx-HW-Queue module */
    471     txHwQueue_Config (pTnetwDrv->hTxHwQueue, pTnetwDrv->pInitTableCopy);
    472 
    473     /* Configure the TX XFER module */
    474     txXfer_config(pTnetwDrv->hTxXfer, pTnetwDrv->pInitTableCopy);
    475 
    476     /* Configure the MAC services */
    477     MacServices_config (pTnetwDrv->hMacServices, pTnetwDrv->pInitTableCopy);
    478 
    479 #if !defined(GWSI_DRIVER) && !defined(GWSI_LIB)
    480     recoveryCtrl_config(pTnetwDrv->hRecoveryCtrl,
    481                         pTnetwDrv->hReport,
    482                         pTnetwDrv->hTNETWIF,
    483                         pTnetwDrv->hTxXfer,
    484                         pTnetwDrv->hRxXfer,
    485                         pTnetwDrv->hTxResult,
    486                         pTnetwDrv->hMacServices,
    487                         pTnetwDrv->hTxCtrlBlk,
    488                         pTnetwDrv->hTxHwQueue,
    489                         pTnetwDrv->hHalCtrl,
    490                         pTnetwDrv->hHwIntr,
    491                         pTnetwDrv->hWhalParams,
    492                         pTnetwDrv->hCmdQueue,
    493                         pTnetwDrv->hFwEvent,
    494                         pTnetwDrv->hCmdMBox,
    495                         pTnetwDrv->hHwInit);
    496 
    497     hwInit_config(pTnetwDrv->hHwInit, pTnetwDrv->hReport, pTnetwDrv->hTNETWIF);
    498 #endif
    499     /* Register the Data Path callback functions */
    500     TnetwDrv_Register_CB (pTnetwDrv, TNETW_DRIVER_TX_XFER_SEND_PKT_TRANSFER, (void *)TnetwDrv_TxXferDone, hTnetwDrv);
    501 
    502     /* Register the send packet debug callback */
    503   #ifdef TI_DBG
    504     TnetwDrv_Register_CB (pTnetwDrv, TNETW_DRIVER_TX_XFER_SEND_PKT_DEBUG, (void *)TnetwDrv_TxXferDebug, hTnetwDrv);
    505   #endif
    506 
    507     /* Register the send packet complete callback */
    508     TnetwDrv_Register_CB (pTnetwDrv, TNETW_DRIVER_TX_RESULT_SEND_PKT_COMPLETE, (void *)TnetwDrv_TxComplete, hTnetwDrv);
    509 
    510     /* Call user application configuration callback */
    511     if (pTnetwDrv->fUserConf)
    512         (*pTnetwDrv->fUserConf) (pTnetwDrv->hUser);
    513 
    514 }
    515 
    516 /****************************************************************************
    517  * DESCRIPTION: Configure the TNET Driver Module callback
    518  *
    519  * INPUTS:
    520  *
    521  * OUTPUT:
    522  *
    523  * RETURNS: OK if succeeded, NOK if failed in HW configuration.
    524  ****************************************************************************/
    525 void TnetwDrv_ConfigureCb1 (TI_HANDLE hTnetwDrv)
    526 {
    527     TnetwDrv_t *pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    528 
    529         /* if the configure complete function was registered, we call it here - end of TnetwDrv_Configure stage */
    530     if (pTnetwDrv->fConfigureCmplteteCB)
    531     {
    532         pTnetwDrv->fConfigureCmplteteCB(pTnetwDrv->hConfigureCompleteOBj);
    533     }
    534 
    535 #ifndef GWSI_LIB
    536     /*
    537         * This will be the last thing that will be done here so all the download
    538         * will go back down to HALto send FINISH to TNETWIF where it began
    539         */
    540         os_Complete (pTnetwDrv->hOs);
    541 #endif
    542 
    543 }
    544 
    545 
    546 
    547 /****************************************************************************
    548  * DESCRIPTION: Configure the TNET Driver Module
    549  *
    550  * INPUTS:
    551  *
    552  * OUTPUT:
    553  *
    554  * RETURNS: OK if succeeded, NOK if failed in HW configuration.
    555  ****************************************************************************/
    556 TI_STATUS TnetwDrv_Configure (TI_HANDLE hTnetwDrv, TnetwDrv_InitParams_t* pInitParams)
    557 {
    558     TnetwDrv_t *pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    559     TnetwDrv_InitParams_t* pInitParam;
    560     if (pTnetwDrv->bInitSuccess)
    561     {
    562         /* If called with init params as null - it means that this is a recovery */
    563         if (NULL != pInitParams)
    564         {
    565             if (OK != TnetwDrv_SetInitParams (hTnetwDrv, pInitParams))
    566             {
    567                 return NOK;
    568             }
    569         }
    570 
    571 #if !defined(GWSI_DRIVER) && !defined(GWSI_LIB)
    572         if(pTnetwDrv->bRecoveryFlag == TRUE)
    573             pInitParam = NULL;
    574         else
    575 #endif
    576             pInitParam = pTnetwDrv->pInitTableCopy;
    577 
    578 
    579         /* If it's recovery call function with NULL instead of ini-file params */
    580         if (whalCtrl_ConfigHw (pTnetwDrv->hHalCtrl,
    581                                pInitParam,
    582                                (void *)TnetwDrv_ConfigureCb,
    583                                hTnetwDrv) != OK)
    584         {
    585             WLAN_REPORT_ERROR(pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG,("\n.....WhalCtrl configuration failure \n"));
    586             return NOK;
    587         }
    588 
    589         return OK;
    590     }
    591 
    592     return NOK;
    593 }
    594 
    595 
    596 /****************************************************************************
    597  *                      TnetwDrv_FinalizeDownload()
    598  ****************************************************************************
    599  * DESCRIPTION: Finalize all the remaining initialization after the downloaD HAS FINISHED
    600                 Register the ERRORS indications events to the FW
    601  *
    602  * INPUTS:
    603  *
    604  * OUTPUT:  None
    605  *
    606  * RETURNS: OK or NOK
    607  ****************************************************************************/
    608 TI_STATUS TnetwDrv_FinalizeDownload (TI_HANDLE hTnetwDrv)
    609 {
    610     TnetwDrv_t *pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    611 
    612     /* Here at the end call the Initialize Complete callback that will release the user Init semaphore */
    613     WLAN_REPORT_INIT(pTnetwDrv->hReport, HAL_CTRL_MODULE_LOG,
    614                 ("hTNETW_Driver %x!!!!!\n", hTnetwDrv));
    615 
    616     /* Here at the end call the Initialize Complete callback that will release the user Init semaphore */
    617     WLAN_REPORT_INIT(pTnetwDrv->hReport, HAL_CTRL_MODULE_LOG,
    618         ("Call MacServices_init!!!!!\n"));
    619 
    620     /*
    621      * Initialize the FW-Transfer modules
    622      */
    623     txXfer_init (pTnetwDrv->hTxXfer, pTnetwDrv->hReport, pTnetwDrv->hTNETWIF, pTnetwDrv->hTxResult);
    624     txResult_init (pTnetwDrv->hTxResult, pTnetwDrv->hReport, pTnetwDrv->hTNETWIF, pTnetwDrv->hFwEvent);
    625     rxXfer_Config (pTnetwDrv->hRxXfer, pTnetwDrv->hFwEvent, pTnetwDrv->hMemMgr, pTnetwDrv->hReport,pTnetwDrv->hTNETWIF);
    626 
    627 #ifdef TI_DBG
    628     debugTrace_Config (pTnetwDrv->hDebugTrace,
    629                        pTnetwDrv->hWhalParams,
    630                        pTnetwDrv->hReport,
    631                        pTnetwDrv->hMemMgr,
    632                        pTnetwDrv->hTNETWIF,
    633                        pTnetwDrv->hFwEvent);
    634 #endif /* TI_DBG */
    635 
    636     /*
    637      * Initialize the MAC Services
    638      */
    639     MacServices_init (pTnetwDrv->hMacServices,
    640                       pTnetwDrv->hReport,
    641                       pTnetwDrv->hHalCtrl);
    642 
    643     /*
    644      * Initialize the Data-Services modules
    645      */
    646     txCtrlBlk_init (pTnetwDrv->hTxCtrlBlk, pTnetwDrv->hReport);
    647     txHwQueue_init (pTnetwDrv->hTxHwQueue, pTnetwDrv->hReport, pTnetwDrv->hWhalParams);
    648 
    649     /* Here at the end call the Initialize Complete callback that will release the user Init semaphore */
    650     WLAN_REPORT_INIT(pTnetwDrv->hReport, HAL_CTRL_MODULE_LOG,
    651         ("Before sending the Init Complet callback !!!!!\n"));
    652 
    653     /* Sign that init has succeeded */
    654     pTnetwDrv->bInitSuccess = TRUE;
    655 
    656     /* When working with GWSI Call the Init Complete callback */
    657 #ifdef GWSI_LIB
    658     /*
    659      * The callback function does not need the handle of the GWSI
    660      * since it takes it from the global handle
    661      */
    662     GWSI_FinalizeDownload (pTnetwDrv->hUser, OK);
    663     /*
    664      * When working with CORE call the os_Init_Complete
    665      * that will release the OS semaphore that the
    666      * user is lock on it in the esta_drb to go on call the next stage
    667      */
    668 #else
    669     /* Here at the end call the Initialize Complete callback that will release the user Init semaphore */
    670     WLAN_REPORT_INIT(pTnetwDrv->hReport, HAL_CTRL_MODULE_LOG,
    671         ("Call os_Complete !!!!!\n"));
    672 
    673     /* Start configuring driver */
    674     if (TnetwDrv_Configure (hTnetwDrv, NULL) != OK)
    675     {
    676         WLAN_REPORT_ERROR (pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG,
    677                            ("TnetwDrv_FinalizeDownload: configuration failure!\n"));
    678     }
    679 
    680 #endif
    681 
    682     return TNETWIF_COMPLETE;
    683 }
    684 
    685 
    686 /****************************************************************************
    687  *                      TnetwDrv_FinalizeOnFailue()
    688  ****************************************************************************
    689  * DESCRIPTION: Finalize all the initialization upon failure
    690  *
    691  * INPUTS:
    692  *
    693  * OUTPUT:  None
    694  *
    695  * RETURNS: OK or NOK
    696  ****************************************************************************/
    697 TI_STATUS TnetwDrv_FinalizeOnFailure (TI_HANDLE hTNETW_Driver)
    698 {
    699     TnetwDrv_t  *pTnetwDrv = (TnetwDrv_t *)hTNETW_Driver;
    700 
    701 #ifdef GWSI_LIB
    702 
    703     /* Stop Init phase of GWSI and return TNETWIF_ERROR */
    704     GWSI_FinalizeDownload (pTnetwDrv->hUser, TNETWIF_ERROR);
    705 
    706     /* When working with CORE call the os_Init_Complete that will release the OS semaphore taht the
    707     user is lock on it in the esta_drb to go on call the next stage */
    708 
    709 #else
    710 
    711     /* Here at the end call the Initialize Complete callback that will release the user Init semaphore */
    712     WLAN_REPORT_INIT (pTnetwDrv->hReport, HAL_CTRL_MODULE_LOG, ("Call os_Complete !!!!!\n"));
    713 
    714     /*
    715      * This will be the last thing that will be done here so all the download
    716      * will go back down to HAL to send FINISH to TNETWIF where it began
    717      */
    718     os_Complete (pTnetwDrv->hOs);
    719 
    720 #endif
    721 
    722     return TNETWIF_COMPLETE;
    723 }
    724 
    725 
    726 /****************************************************************************/
    727 /*                      TNETW_Driver_Register_CB()
    728  ****************************************************************************
    729  * DESCRIPTION: Register the MAC Services and the HAL modules callbacks
    730  *
    731  * INPUTS:
    732  *
    733  * OUTPUT:
    734  *
    735  * RETURNS:
    736  ****************************************************************************/
    737 void TnetwDrv_Register_CB (TI_HANDLE hTnetwDrv,tiUINT32 EventID,void *CBFunc, void *pData)
    738 {
    739 
    740     TnetwDrv_t * pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    741 
    742     WLAN_REPORT_INFORMATION(pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG, ("TnetwDrv_Register_CB (Value = 0x%x)\n", EventID));
    743 
    744     /* First detect which module is the owner */
    745     switch((tiUINT16)(EventID & TNETW_DRIVER_CB_MODULE_OWNER_MASK))
    746     {
    747 
    748     case  TNETW_DRIVER_TX_XFER_OWNER:
    749         EventID &= TNETW_DRIVER_CB_TYPE_MASK;
    750         WLAN_REPORT_INFORMATION(pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG,("TnetwDrv_Register_CB: TNETW_DRIVER_TX_XFER_OWNER\n"));
    751         txXfer_RegisterCB(pTnetwDrv->hTxXfer, EventID, CBFunc, pData);
    752         break;
    753 
    754     case  TNETW_DRIVER_TX_RESULT_OWNER:
    755         EventID &= TNETW_DRIVER_CB_TYPE_MASK;
    756         WLAN_REPORT_INFORMATION(pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG,("TnetwDrv_Register_CB: TNETW_DRIVER_TX_RESULT_OWNER\n"));
    757         txResult_RegisterCB(pTnetwDrv->hTxResult, EventID, CBFunc, pData);
    758         break;
    759 
    760     case TNETW_DRIVER_RX_XFER_OWNER:
    761         EventID &= TNETW_DRIVER_CB_TYPE_MASK;
    762         WLAN_REPORT_INFORMATION(pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG,("TnetwDrv_Register_CB: TNETW_DRIVER_RX_XFER_OWNER\n"));
    763         rxXfer_Register_CB(pTnetwDrv->hRxXfer, EventID,CBFunc,pData);
    764         break;
    765 
    766     case TNETW_DRIVER_HAL_CTRL_OWNER:
    767         EventID &= TNETW_DRIVER_CB_TYPE_MASK;
    768         whalCtrl_Register_CB(pTnetwDrv->hHalCtrl, EventID,CBFunc,pData);
    769         break;
    770 
    771     case TNETW_DRIVER_MAC_SERVICES_OWNER:
    772         switch (EventID & TNETW_DRIVER_CB_TYPE_MASK)
    773         {
    774         case HAL_EVENT_SCAN_CMPLT:
    775             MacServices_scanSRV_registerScanCompleteCB(pTnetwDrv->hMacServices, (scan_srvCompleteCB_t)CBFunc, pData);
    776             break;
    777         default:
    778             WLAN_REPORT_WARNING(pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG,("TNETW_DRIVER_MAC_SERVICES_OWNER - Illegal value\n"));
    779         }
    780         break;
    781 
    782     case TNETW_DRIVER_TWD_OWNER:
    783         WLAN_REPORT_INFORMATION(pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG,("TnetwDrv_Register_CB: TNETW_DRIVER_TWD_OWNER\n"));
    784         pTnetwDrv->fConfigureCmplteteCB  = (TnetDrv_callback_t)CBFunc;
    785         pTnetwDrv->hConfigureCompleteOBj = (TI_HANDLE)pData;
    786         break;
    787 
    788     default:
    789         if (EventID == HAL_INTERNAL_EVENT_FAILURE)
    790         {
    791 
    792 
    793             /* register the Hal failure event callback  including the RX
    794                  in the Hal Cttl the errors are :
    795                 MBOX_FAILURE,
    796                     BUS_ERROR,
    797                 DEVICE_ERROR,
    798                 DISCONNECT_TIMEOUT,*/
    799 
    800 
    801 
    802             EventID &= TNETW_DRIVER_CB_TYPE_MASK;
    803             whalCtrl_Register_CB(pTnetwDrv->hHalCtrl, EventID,CBFunc,pData);
    804 
    805             /* register the Elp controller failure event callback to the TNET interface
    806                 HW_AWAKE_FAILURE*/
    807             TNETWIF_RegisterFailureEventCB(pTnetwDrv->hTNETWIF,CBFunc,pData);
    808 
    809             /* register the Mac services failure events callbacks
    810                 POWER_SAVE_FAILURE,
    811                 MEASUREMENT_FAILURE,
    812                 NO_SCAN_COMPLETE_FAILURE,*/
    813             MacServices_registerFailureEventCB(pTnetwDrv->hMacServices, CBFunc, pData);
    814 
    815 
    816             /* register the TX failure call back in the  Xfer
    817                 TX_STUCK,*/
    818             txXfer_RegisterFailureEventCB(pTnetwDrv->hTxXfer, CBFunc, pData);
    819 
    820 
    821         }
    822         else
    823         WLAN_REPORT_WARNING(pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG,("TnetwDrv_Register_CB - Illegal value\n"));
    824 
    825     }
    826     return;
    827 }
    828 
    829 /****************************************************************************/
    830 /*                      TnetwDrv_SetInitParams()
    831  ****************************************************************************/
    832 static TI_STATUS TnetwDrv_SetInitParams (TI_HANDLE hTnetwDrv, TnetwDrv_InitParams_t* pInitParams)
    833 {
    834     TnetwDrv_t * pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    835     TnetwDrv_InitParams_t *pInitTableCopy;
    836     UINT32       index;
    837 
    838     pInitTableCopy = pTnetwDrv->pInitTableCopy = os_memoryAlloc (pTnetwDrv->hOs, sizeof(TnetwDrv_InitParams_t));
    839     if (pTnetwDrv->pInitTableCopy != NULL)
    840     {
    841         os_memoryZero (pTnetwDrv->hOs, pTnetwDrv->pInitTableCopy, sizeof(TnetwDrv_InitParams_t));
    842         /* Copy the init info to the buffer */
    843         os_memoryCopy (pTnetwDrv->hOs, pTnetwDrv->pInitTableCopy, pInitParams, sizeof(TnetwDrv_InitParams_t));
    844         /* Change the Severity table to character */
    845         for (index = 0; index < sizeof(((report_t *)pTnetwDrv->hReport)->SeverityTable); index++)
    846         {
    847             pInitTableCopy->reportParams.SeverityTable[index] += '0';
    848         }
    849         /* Change the module table to character */
    850         for (index = 0; index < sizeof(((report_t *)pTnetwDrv->hReport)->ModuleTable); index++)
    851         {
    852             pInitTableCopy->reportParams.ModuleTable[index] += '0';
    853         }
    854     }
    855     else
    856     {
    857         WLAN_REPORT_ERROR(pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG,
    858                           ("TnetwDrv_SetInitParams: unable to allocate init params buffer!\n") );
    859         return NOK;
    860     }
    861 
    862     return OK;
    863 }
    864 
    865 /****************************************************************************/
    866 /*                      TnetwDrv_GetInitParams()
    867  ****************************************************************************/
    868 void TnetwDrv_GetInitParams (TI_HANDLE hTnetwDrv, UINT8 *pcommand, UINT16 *OutBufLen)
    869 {
    870     TnetwDrv_t * pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    871 
    872     if (pTnetwDrv->pInitTableCopy)
    873     {
    874         *(UINT32 *)pcommand = sizeof(TnetwDrv_InitParams_t);
    875         pcommand += sizeof(UINT32);
    876         os_memoryCopy(NULL, (void *)pcommand, (void *)pTnetwDrv->pInitTableCopy, sizeof(TnetwDrv_InitParams_t));
    877     }
    878     else
    879     {
    880         /* The table information is not available */
    881         *(UINT32 *)pcommand = 0;
    882         WLAN_OS_REPORT(("TNETW_Driver_GetInitParams :ERROR Getting Buffer for the INI File !!!\n"));
    883     }
    884 
    885     *OutBufLen = (sizeof(TnetwDrv_InitParams_t) + sizeof(UINT32));
    886 }
    887 
    888 
    889 
    890 /****************************************************************************/
    891 /*                      TnetwDrv_PrintInfo()
    892  ****************************************************************************
    893  * DESCRIPTION:  Call the requested print function.
    894  ****************************************************************************/
    895 void  TnetwDrv_PrintInfo (TI_HANDLE hTnetwDrv, TnetwDrv_PrintInfoType_e printInfo)
    896 {
    897     TnetwDrv_t *pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    898 
    899     switch(printInfo)
    900     {
    901         case TNETW_DRV_PRINT_TX_CTRL_BLK_TBL:
    902             txCtrlBlk_printTable(pTnetwDrv->hTxCtrlBlk);
    903             break;
    904 
    905         case TNETW_DRV_PRINT_TX_HW_QUEUE_INFO:
    906             txHwQueue_printInfo(pTnetwDrv->hTxHwQueue);
    907             break;
    908 
    909         case TNETW_DRV_PRINT_TX_XFER_INFO:
    910             txXfer_printInfo(pTnetwDrv->hTxXfer);
    911             break;
    912 
    913         case TNETW_DRV_PRINT_TX_RESULT_INFO:
    914             txResult_printInfo(pTnetwDrv->hTxResult);
    915             break;
    916 
    917         case TNETW_DRV_CLEAR_TX_RESULT_INFO:
    918             txResult_clearInfo(pTnetwDrv->hTxResult);
    919             break;
    920 
    921         default:
    922             WLAN_REPORT_ERROR( pTnetwDrv->hReport, TNETW_DRV_MODULE_LOG,
    923                                ("$s: invalid print info request code: %d\n", __FUNCTION__, printInfo) );
    924     }
    925 }
    926 
    927 
    928 
    929 
    930 /****************************************************************************/
    931 /*                      TnetwDrv_TEMP_GetHandles()
    932  ****************************************************************************
    933  * DESCRIPTION:
    934 
    935        TEMPORARY!! - untill the new TNETW-Driver architecture is completed!!
    936 
    937        In the new architecture all external calls to the driver will be through
    938          the hTnetwDrv handle.
    939 
    940        Called by the driver creation process.
    941        Gets the TNETW-Driver modules handles needed externally.
    942 
    943 ****************************************************************************/
    944 void  TnetwDrv_TEMP_GetHandles(TI_HANDLE hTnetwDrv, TI_HANDLE *pHalCtrl, TI_HANDLE *pMacServices)
    945 {
    946     TnetwDrv_t *pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    947 
    948     *pHalCtrl       = pTnetwDrv->hHalCtrl;
    949     *pMacServices   = pTnetwDrv->hMacServices;
    950 }
    951 
    952 #if !defined(GWSI_DRIVER) && !defined(GWSI_LIB)
    953 /****************************************************************************/
    954 /*                      TnetwDrv_StartRecovery()
    955  ****************************************************************************
    956  * DESCRIPTION:
    957           API function called by RecoverMgr to start TWD recovery process
    958 ****************************************************************************/
    959 void TnetwDrv_StartRecovery(TI_HANDLE hTnetwDrv, void *endOfRecoveryCB, TI_HANDLE hRecoveryMgr)
    960 {
    961     TnetwDrv_t *pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    962     pTnetwDrv->bRecoveryFlag = TRUE;
    963     recoveryCtrl_restartTWD(pTnetwDrv->hRecoveryCtrl, endOfRecoveryCB, hRecoveryMgr);
    964 
    965 }
    966 
    967 /****************************************************************************/
    968 /*                      TnetwDrv_InitHw_FinalizeDownload()
    969  ****************************************************************************
    970  * DESCRIPTION:
    971           API function called by RecoverMgr to start TWD recovery process
    972 ****************************************************************************/
    973 TI_STATUS TnetwDrv_InitHw_FinalizeDownload(TI_HANDLE hTnetwDrv)
    974 {
    975     TnetwDrv_t *pTnetwDrv = (TnetwDrv_t *)hTnetwDrv;
    976 
    977     if (pTnetwDrv->bRecoveryFlag)
    978     {
    979         pTnetwDrv->bRecoveryFlag = FALSE;
    980         return InitHw_FinalizeDownload(pTnetwDrv->hHwInit);
    981     }
    982     else
    983     {
    984         return TnetwDrv_FinalizeDownload(hTnetwDrv);
    985     }
    986 }
    987 #endif
    988 
    989 #ifdef GWSI_SPI_TEST
    990 
    991 TI_HANDLE TnetwDrv_GetTnetwifHandle (TI_HANDLE hTnetwDrv)
    992 {
    993 	return ((TnetwDrv_t *)hTnetwDrv)->hTNETWIF;
    994 }
    995 
    996 #endif /* GWSI_SPI_TEST */
    997