OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / system / wlan / ti / wilink_6_1 / TWD / FW_Transfer / txXfer.c
1 /*
2  * txXfer.c
3  *
4  * Copyright(c) 1998 - 2009 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  *   MODULE:  txXfer.c
38  *   
39  *   PURPOSE: Handle Tx frame transfer to the firmware. 
40  * 
41  *   DESCRIPTION:  
42  *   ============
43  *      This module gets the upper driver's Tx packets after FW resources were
44  *        allocated for it, and handles its transfer to the FW via the 
45  *        host slave (indirect) interface, using the TwIf Transaction API.
46  *
47  ****************************************************************************/
48
49 #define __FILE_ID__  FILE_ID_108
50 #include "tidef.h"
51 #include "osApi.h"
52 #include "report.h"
53 #include "TwIf.h"
54 #include "TWDriver.h"
55 #include "FwEvent_api.h"
56 #include "txXfer_api.h"
57
58
59 /* remove workaround when WL6-PG1.0 becomes obsolete */
60 typedef struct 
61 {
62     TTxnStruct              tTxnStruct;
63     TI_UINT32               uPktsCntr; 
64 } TPktsCntrTxn;
65
66
67 /* The TxXfer module object. */
68 typedef struct 
69 {
70     TI_HANDLE               hOs;
71     TI_HANDLE               hReport;
72     TI_HANDLE               hTwIf;
73
74     TSendPacketTranferCb    fSendPacketTransferCb;   /* Upper layer Xfer-Complete callback */
75     TI_HANDLE               hSendPacketTransferHndl; /* Upper layer Xfer-Complete callback handle */
76
77     /* remove workaround when WL6-PG1.0 becomes obsolete */
78     TI_BOOL                 bChipIs1273Pg10;
79     TI_UINT32               uPktsCntr; 
80     TPktsCntrTxn            aPktsCntrTxn[CTRL_BLK_ENTRIES_NUM]; 
81
82 } TTxXferObj;
83
84 static void txXfer_TransferDoneCb (TI_HANDLE hTxXfer, TTxnStruct *pTxn);
85
86
87
88 /****************************************************************************
89  *                      txXfer_Create()
90  ****************************************************************************
91  * DESCRIPTION: Create the Xfer module object 
92  * 
93  * INPUTS:  None
94  * 
95  * OUTPUT:  None
96  * 
97  * RETURNS: The Created object
98  ****************************************************************************/
99 TI_HANDLE txXfer_Create(TI_HANDLE hOs)
100 {
101     TTxXferObj *pTxXfer;
102
103     pTxXfer = os_memoryAlloc (hOs, sizeof(TTxXferObj));
104     if (pTxXfer == NULL)
105     {
106         return NULL;
107     }
108
109     os_memoryZero (hOs, pTxXfer, sizeof(TTxXferObj));
110
111     pTxXfer->hOs = hOs;
112
113     return (TI_HANDLE)pTxXfer;
114 }
115
116
117 /****************************************************************************
118  *                      txXfer_Destroy()
119  ****************************************************************************
120  * DESCRIPTION: Destroy the Xfer module object 
121  * 
122  * INPUTS:  hTxXfer - The object to free
123  * 
124  * OUTPUT:  None
125  * 
126  * RETURNS: TI_OK or TI_NOK
127  ****************************************************************************/
128 TI_STATUS txXfer_Destroy(TI_HANDLE hTxXfer)
129 {
130     TTxXferObj *pTxXfer = (TTxXferObj *)hTxXfer;
131
132     if (pTxXfer)
133     {
134         os_memoryFree (pTxXfer->hOs, pTxXfer, sizeof(TTxXferObj));
135     }
136
137     return TI_OK;
138 }
139
140
141 /****************************************************************************
142  *               txXfer_init()
143  ****************************************************************************
144    DESCRIPTION:  
145    ============
146      Initialize the Xfer module.
147  ****************************************************************************/
148 TI_STATUS txXfer_Init (TI_HANDLE hTxXfer, TI_HANDLE hReport, TI_HANDLE hTwIf)
149 {
150     TTxXferObj *pTxXfer = (TTxXferObj *)hTxXfer;
151     TTxnStruct *pTxn;
152     TI_UINT8    i;
153
154     pTxXfer->hReport = hReport;
155     pTxXfer->hTwIf   = hTwIf;
156     pTxXfer->fSendPacketTransferCb = NULL;
157
158     /* remove workaround when WL6-PG1.0 becomes obsolete */
159     pTxXfer->uPktsCntr = 0;
160     for (i = 0; i < CTRL_BLK_ENTRIES_NUM; i++)
161     {
162         pTxn = &(pTxXfer->aPktsCntrTxn[i].tTxnStruct);
163         TXN_PARAM_SET(pTxn, TXN_LOW_PRIORITY, TXN_FUNC_ID_WLAN, TXN_DIRECTION_WRITE, TXN_INC_ADDR)
164         BUILD_TTxnStruct(pTxn, HOST_WR_ACCESS_REG, &pTxXfer->aPktsCntrTxn[i].uPktsCntr, REGISTER_SIZE, NULL, NULL)
165     }
166
167     return txXfer_Restart(hTxXfer, TI_TRUE);
168 }
169
170
171 /****************************************************************************
172  *               txXfer_Restart()
173  ****************************************************************************
174    DESCRIPTION:  
175    ============
176      Restart the Xfer module.
177  ****************************************************************************/
178 TI_STATUS txXfer_Restart (TI_HANDLE hTxXfer, TI_BOOL bChipIs1273Pg10)
179 {
180     TTxXferObj *pTxXfer = (TTxXferObj *)hTxXfer;
181
182     /* remove the counter transactions workaround when WL6-PG1.0 becomes obsolete */
183     pTxXfer->bChipIs1273Pg10 = bChipIs1273Pg10;
184     pTxXfer->uPktsCntr = 0;
185
186     return TI_OK;
187 }
188
189
190 /****************************************************************************
191  *                  txXfer_sendPacket()
192  ****************************************************************************
193  * DESCRIPTION: 
194    ============
195    Send packet to the transaction queue.
196    Return the transfer status:
197      TXN_STATUS_COMPLETE - if completed, i.e. Synchronous mode.
198      TXN_STATUS_PENDING  - if pending, i.e. Asynchronous mode. 
199    Note that in case of PENDING, a callback function will be called 
200        only if registered (needed for WHA).
201  ****************************************************************************/
202 ETxnStatus txXfer_SendPacket (TI_HANDLE hTxXfer, TTxCtrlBlk *pPktCtrlBlk)
203 {
204     TTxXferObj   *pTxXfer = (TTxXferObj *)hTxXfer;
205     TTxnStruct   *pTxn    = (TTxnStruct *)pPktCtrlBlk;
206     ETxnStatus   eStatus; 
207     TPktsCntrTxn *pPktsCntrTxn; 
208     
209     /* Prepare the Txn fields to the host-slave register (fixed address) */
210     TXN_PARAM_SET(pTxn, TXN_LOW_PRIORITY, TXN_FUNC_ID_WLAN, TXN_DIRECTION_WRITE, TXN_FIXED_ADDR)
211     pTxn->uHwAddr = SLV_MEM_DATA;
212
213     /* Fill the TxnDone CB only if registered by the upper layers */
214     if (pTxXfer->fSendPacketTransferCb == NULL)
215     {
216         pTxn->fTxnDoneCb = NULL;
217     }
218     else 
219     {
220         pTxn->fTxnDoneCb = (TTxnDoneCb)txXfer_TransferDoneCb;
221         pTxn->hCbHandle  = hTxXfer;
222     }
223
224     /* Send the transaction */
225     eStatus = twIf_Transact (pTxXfer->hTwIf, pTxn);
226
227 #ifdef TI_DBG
228
229     TRACE11(pTxXfer->hReport, REPORT_SEVERITY_INFORMATION, ": Status=%d, PktType=%d, Len0=%d, Len1=%d, Length=%d, ExtraBlks=%d, TotalBlks=%d, TxAttr=0x%x, TID=%d, DescID=%d, StartTime=%d\n", eStatus, pPktCtrlBlk->tTxPktParams.uPktType, pPktCtrlBlk->tTxnStruct.aLen[0], pPktCtrlBlk->tTxnStruct.aLen[1], pPktCtrlBlk->tTxDescriptor.length, pPktCtrlBlk->tTxDescriptor.extraMemBlks, pPktCtrlBlk->tTxDescriptor.totalMemBlks, pPktCtrlBlk->tTxDescriptor.txAttr, pPktCtrlBlk->tTxDescriptor.tid, pPktCtrlBlk->tTxDescriptor.descID, pPktCtrlBlk->tTxDescriptor.startTime);
230
231     if (eStatus == TXN_STATUS_ERROR)
232     {
233         TI_UINT32 i;
234         for (i = 0; i < MAX_XFER_BUFS; i++)
235         {
236             if (pPktCtrlBlk->tTxnStruct.aLen[i] == 0)
237             {
238                 break;
239             }
240             TRACE1(pTxXfer->hReport, REPORT_SEVERITY_CONSOLE, "txXfer_SendPacket():  Tx Buffer %d:\n", i);
241             WLAN_OS_REPORT (("txXfer_SendPacket():  Tx Buffer %d:\n", i));
242             report_PrintDump(pPktCtrlBlk->tTxnStruct.aBuf[i], pPktCtrlBlk->tTxnStruct.aLen[i]);
243             return eStatus;
244         }
245     }
246
247 #endif  /* TI_DBG */
248
249     /* remove workaround when WL6-PG1.0 becomes obsolete */
250     if (1) /* restore ->  if (pTxXfer->bChipIs1273Pg10) */
251     {
252         pTxXfer->uPktsCntr++;
253         pPktsCntrTxn = &(pTxXfer->aPktsCntrTxn[pTxXfer->uPktsCntr % CTRL_BLK_ENTRIES_NUM]);
254         pPktsCntrTxn->uPktsCntr = ENDIAN_HANDLE_LONG(pTxXfer->uPktsCntr);
255         pPktsCntrTxn->tTxnStruct.uHwAddr = HOST_WR_ACCESS_REG;
256         twIf_Transact(pTxXfer->hTwIf, &pPktsCntrTxn->tTxnStruct);
257     }
258
259     /* Return the Txn result - COMPLETE or PENDING. */
260     /* Note: For PENDING, a callback function will be called only if registered (needed for WHA) */
261     return eStatus;
262 }
263
264
265 /****************************************************************************
266  *                      txXfer_TransferDoneCb()
267  ****************************************************************************
268  * DESCRIPTION:  Call the upper layers TranferDone callback, providing the TxCtrlBlk
269  ****************************************************************************/
270 static void txXfer_TransferDoneCb (TI_HANDLE hTxXfer, TTxnStruct *pTxn)
271 {
272     TTxXferObj *pTxXfer = (TTxXferObj*)hTxXfer;
273
274     TRACE1(pTxXfer->hReport, REPORT_SEVERITY_INFORMATION, ": pTxn=0x%x\n", pTxn);
275
276     /* Call the upper layers TranferDone callback, providing the TxCtrlBlk. */
277     /* Note: If this CB was called it means that the upper CB exists (see in txXfer_SendPacket) */
278     pTxXfer->fSendPacketTransferCb (pTxXfer->hSendPacketTransferHndl, (TTxCtrlBlk *)pTxn);
279 }
280
281
282 /****************************************************************************
283  *                      txXfer_RegisterCb()
284  ****************************************************************************
285  * DESCRIPTION:  Register the upper driver Xfer callback functions.
286  ****************************************************************************/
287 void txXfer_RegisterCb (TI_HANDLE hTxXfer, TI_UINT32 CallBackID, void *CBFunc, TI_HANDLE CBObj)
288 {
289     TTxXferObj* pTxXfer = (TTxXferObj*)hTxXfer;
290
291     TRACE3(pTxXfer->hReport, REPORT_SEVERITY_INFORMATION, ": CallBackID=%d, CBFunc=0x%x, CBObj=0x%x\n", CallBackID, CBFunc, CBObj);
292
293     switch(CallBackID)
294     {
295         /* Save upper layers Transfer-Done callback */
296         case TWD_INT_SEND_PACKET_TRANSFER:
297             pTxXfer->fSendPacketTransferCb   = (TSendPacketTranferCb)CBFunc;
298             pTxXfer->hSendPacketTransferHndl = CBObj;
299             break;
300
301         default:
302             TRACE0(pTxXfer->hReport, REPORT_SEVERITY_ERROR, " - Illegal value\n");
303             break;
304     }
305 }
306
307
308
309
310