PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/net/wireless/tiwlan1251/common/src/core/data_ctrl/Tx/MsduList.c

http://github.com/CyanogenMod/cm-kernel
C | 487 lines | 234 code | 81 blank | 172 comment | 43 complexity | 08c282a8b9bfb119b64d423a7316ce66 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  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. /* MODULE: envList.c */
  38. /* PURPOSE: Envelope list implementation */
  39. /* */
  40. /***************************************************************************/
  41. #include "MsduList.h"
  42. #include "osTIType.h"
  43. #include "paramIn.h"
  44. #include "osApi.h"
  45. /*************************************************************************
  46. * msduList_CreateNewMsduList *
  47. *************************************************************************
  48. DESCRIPTION: This function creates new Msdu list.
  49. INPUT: maxNumOfElements : The maximum number of elements allowd
  50. pOs : Pointer to os abstraction layer
  51. OUTPUT:
  52. RETURN: MsduList_T
  53. *************************************************************************/
  54. MsduList_t* msduList_CreateNewMsduList( TI_HANDLE hOs )
  55. {
  56. MsduList_t* msduList = (MsduList_t*) os_memoryAlloc(hOs,sizeof(MsduList_t));
  57. if( msduList == NULL )
  58. return NULL;
  59. if(( msduList->hCriticalSectionProtect = os_protectCreate(hOs)) == NULL)
  60. {
  61. WLAN_OS_REPORT(("FATAL ERROR: Could not Create Critical Section Protection for Msdu List - Aborting\n"));
  62. /* free Msdu List Control Block */
  63. os_memoryFree(hOs, msduList, sizeof(MsduList_t));
  64. return NULL;
  65. }
  66. msduList->hOs = hOs;
  67. msduList->first = NULL;
  68. msduList->last = NULL;
  69. msduList->maxNumOfMsdu = 0;
  70. msduList->CurrNumOfMsdu = 0;
  71. msduList->ovFlowPolicy = DROP_NEW_PACKET;
  72. msduList->numOfOverFlow = 0;
  73. msduList->maxCurrOfMsdu =0;
  74. return msduList;
  75. }
  76. /*************************************************************************
  77. * msduList_ConfigMsduList *
  78. *************************************************************************
  79. DESCRIPTION: This function configure the Msdu list.
  80. INPUT: *this : A pointer to the list to configure
  81. msduListConfig : Pointer to the Msdu list configuration
  82. structure.
  83. OUTPUT:
  84. RETURN: TI_STATUS: OK/NOK
  85. *************************************************************************/
  86. TI_STATUS msduList_ConfigMsduList( MsduList_t* this, TI_HANDLE hMemMgr,
  87. TI_HANDLE hReport, TI_HANDLE hOs,INT16 maxNumOfElements)
  88. {
  89. if( hOs == NULL || hReport == NULL ||
  90. this == NULL || hMemMgr == NULL)
  91. return NOK;
  92. this->hReport = hReport;
  93. this->hMemMgr = hMemMgr;
  94. this->hOs = hOs;
  95. this->maxNumOfMsdu = maxNumOfElements;
  96. this->useAdmissionAlgo = FALSE;
  97. this->credit = 0;
  98. this->enableTransmissionTime = 0;
  99. this->lastTimeStamp = 0;
  100. this->mediumTime = 0;
  101. this->totalUsedTime = 0;
  102. this->highMediumUsageThreshold = 0;
  103. this->lowMediumUsageThreshold = 0;
  104. return OK;
  105. }
  106. /*************************************************************************
  107. * msduList_SetMsduListNumOfElements *
  108. *************************************************************************
  109. DESCRIPTION: This function configure the Msdu list max num of elements.
  110. INPUT: *this : A pointer to the list to configure
  111. maxNumOfElements: max num of elements.
  112. OUTPUT:
  113. RETURN: TI_STATUS: OK/NOK
  114. *************************************************************************/
  115. TI_STATUS msduList_SetMsduListNumOfElements( MsduList_t* this, UINT16 maxNumOfElements)
  116. {
  117. if(this == NULL)
  118. return NOK;
  119. this->maxNumOfMsdu = maxNumOfElements;
  120. return OK;
  121. }
  122. /*************************************************************************
  123. * msduList_SetMsduListOverFlowPolicy *
  124. *************************************************************************
  125. DESCRIPTION: This function configure the Msdu list policy in case of over flow .
  126. INPUT: *this : A pointer to the list to configure
  127. QueueOvFlowPolicy: over flow polict - new packet drop or old packet drop.
  128. OUTPUT:
  129. RETURN: TI_STATUS: OK/NOK
  130. *************************************************************************/
  131. TI_STATUS msduList_SetMsduListOverFlowPolicy( MsduList_t* this, qOvFlowPolicy_e QueueOvFlowPolicy)
  132. {
  133. if(this == NULL)
  134. return NOK;
  135. this->ovFlowPolicy = QueueOvFlowPolicy;
  136. return OK;
  137. }
  138. /*************************************************************************
  139. * msduList_FreeMsduList *
  140. *************************************************************************
  141. DESCRIPTION: This function free the Msdu list.
  142. INPUT: *this : A pointer to the list to free
  143. pOs : Pointer to os abstraction layer
  144. OUTPUT:
  145. RETURN: TI_STATUS: OK/NOK
  146. *************************************************************************/
  147. TI_STATUS msduList_FreeMsduList( MsduList_t* this)
  148. {
  149. if( this->CurrNumOfMsdu != 0 )
  150. {
  151. if( msduList_EmptyMsduList( this ) != OK )
  152. {
  153. WLAN_REPORT_ERROR(this->hReport, TX_DATA_MODULE_LOG,
  154. (" msduList_FreeMsduList() : failed \n"));
  155. return NOK;
  156. }
  157. }
  158. /* free protection */
  159. os_protectDestroy(this->hOs,this->hCriticalSectionProtect);
  160. /* free msdu control block */
  161. os_memoryFree(this->hOs, this, sizeof(MsduList_t));
  162. return OK;
  163. }
  164. /*************************************************************************
  165. * msduList_EmptyMsduList *
  166. *************************************************************************
  167. DESCRIPTION: This function free all the MSDUs from the Msdu list.
  168. INPUT: *this : A pointer to the list to empty
  169. pOs : Pointer to os abstraction layer
  170. OUTPUT:
  171. RETURN: TI_STATUS: OK/NOK
  172. *************************************************************************/
  173. TI_STATUS msduList_EmptyMsduList( MsduList_t* this)
  174. {
  175. UINT32 count;
  176. mem_MSDU_T* pTempMsdu;
  177. os_protectLock(this->hOs, this->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  178. if( this->CurrNumOfMsdu == 0 )
  179. {
  180. WLAN_REPORT_INFORMATION(this->hReport, TX_DATA_MODULE_LOG,
  181. (" msduList_EmptyMsduList() : List is empty \n"));
  182. os_protectUnlock(this->hOs, this->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  183. return OK;
  184. }
  185. /* update Tx status to NOK for all msdu in list */
  186. pTempMsdu = this->first;
  187. for(count = 0 ; count < this->CurrNumOfMsdu ; count++)
  188. {
  189. memMgr_MsduFreeArg2Get(pTempMsdu) = NOK;
  190. pTempMsdu = pTempMsdu->nextMSDUinList;
  191. }
  192. os_protectUnlock(this->hOs, this->hCriticalSectionProtect);
  193. /* free all msdu back to the memMngr */
  194. if ((wlan_memMngrFreeListOfMSDU(this->hMemMgr, memMgr_MsduHandle( this->first))) != OK)
  195. {
  196. WLAN_REPORT_ERROR(this->hReport, TX_DATA_MODULE_LOG,
  197. (" msduList_EmptyMsduList() : Msdu free failed \n"));
  198. }
  199. os_protectLock(this->hOs, this->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  200. this->first = NULL;
  201. this->last = NULL;
  202. this->CurrNumOfMsdu = 0;
  203. this->numOfOverFlow = 0;
  204. this->maxCurrOfMsdu = 0;
  205. this->useAdmissionAlgo = FALSE;
  206. this->credit = 0;
  207. this->enableTransmissionTime = 0;
  208. this->lastTimeStamp = 0;
  209. this->mediumTime = 0;
  210. this->totalUsedTime = 0;
  211. os_protectUnlock(this->hOs, this->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  212. return OK;
  213. }
  214. /*************************************************************************
  215. * msduList_MsduListIns *
  216. *************************************************************************
  217. DESCRIPTION: This function insert MSDU to the list pointed by this.
  218. INPUT: *this : A pointer to the list to insert.
  219. *pMsdu : Pointer to the MSDU to insert, the MSDU
  220. is inserted to be the last in the list. If the
  221. list is full the first MSDU will be taken
  222. out and will be returned in this pointer.
  223. OUTPUT: *pMsdu : In case the list is full,this poiter will hold
  224. the dropt MSDU's.
  225. RETURN: OK : The MSDU has been inserted, there was enough
  226. place in the list.
  227. NOK: The list was full, the first MSDU is dropt, and
  228. returned by *pMsdu.
  229. ************************************************************************/
  230. TI_STATUS msduList_Insert( MsduList_t* this , mem_MSDU_T **pMsdu )
  231. {
  232. os_protectLock(this->hOs, this->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  233. if( this->CurrNumOfMsdu == 0 )
  234. {
  235. this->last = *pMsdu;
  236. this->first = *pMsdu;
  237. (*pMsdu)->nextMSDUinList = NULL;
  238. (*pMsdu)->prevMSDUinList = NULL;
  239. this->CurrNumOfMsdu++;
  240. os_protectUnlock(this->hOs, this->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  241. /* for debug */
  242. if( this->CurrNumOfMsdu > this->maxCurrOfMsdu )
  243. this->maxCurrOfMsdu = this->CurrNumOfMsdu;
  244. return OK;
  245. }
  246. else
  247. {
  248. if( this->CurrNumOfMsdu == this->maxNumOfMsdu )
  249. {
  250. this->numOfOverFlow++;
  251. if(this->ovFlowPolicy == DROP_NEW_PACKET)
  252. {
  253. /* The list is full, remove the new coming msdu*/
  254. WLAN_REPORT_INFORMATION(this->hReport, TX_DATA_MODULE_LOG,
  255. (" msduList_MsduListIns() : New Msdu has to be removed \n"));
  256. os_protectUnlock(this->hOs, this->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  257. /* for debug */
  258. if( this->CurrNumOfMsdu > this->maxCurrOfMsdu )
  259. this->maxCurrOfMsdu = this->CurrNumOfMsdu;
  260. return NOK;
  261. }else
  262. {
  263. /* The list is full, insert the new msdu and remove the first msdu*/
  264. this->last->nextMSDUinList = *pMsdu;
  265. (*pMsdu)->prevMSDUinList = this->last;
  266. (*pMsdu)->nextMSDUinList = NULL;
  267. this->last = *pMsdu;
  268. /* remove the first msdu from list */
  269. (*pMsdu) = this->first;
  270. this->first = this->first->nextMSDUinList;
  271. this->first->prevMSDUinList = NULL;
  272. (*pMsdu)->nextMSDUinList = NULL;
  273. WLAN_REPORT_INFORMATION(this->hReport, TX_DATA_MODULE_LOG,
  274. (" msduList_MsduListIns() : First Msdu was removed \n"));
  275. os_protectUnlock(this->hOs, this->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  276. /* indicate that the first msdu has removed */
  277. /* for debug */
  278. if( this->CurrNumOfMsdu > this->maxCurrOfMsdu )
  279. this->maxCurrOfMsdu = this->CurrNumOfMsdu;
  280. return NOK;
  281. }
  282. }
  283. else
  284. { /* insert the MSDU to be the last. */
  285. this->last->nextMSDUinList = *pMsdu;
  286. (*pMsdu)->prevMSDUinList = this->last;
  287. (*pMsdu)->nextMSDUinList = NULL;
  288. this->last = *pMsdu;
  289. }
  290. this->CurrNumOfMsdu++;
  291. os_protectUnlock(this->hOs, this->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  292. /* for debug */
  293. if( this->CurrNumOfMsdu > this->maxCurrOfMsdu )
  294. this->maxCurrOfMsdu = this->CurrNumOfMsdu;
  295. return OK;
  296. }
  297. }
  298. /*************************************************************************
  299. * msduList_MsduListGetFirst *
  300. *************************************************************************
  301. DESCRIPTION: This function get MSDU to the list pointed by this.
  302. INPUT: *this : A pointer to the list to get.
  303. OUTPUT: *pMsdu : A pointer to the first MSDU in the list.
  304. RETURN: OK : There was an MSDU in the list, and it is assigned
  305. to the *pMsdu.
  306. NOK: The list was empty, *pMsdu is trush.
  307. ************************************************************************/
  308. TI_STATUS msduList_GetFirst( MsduList_t *this, mem_MSDU_T **pMsdu)
  309. {
  310. os_protectLock(this->hOs, this->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  311. if( this->CurrNumOfMsdu == 0 )
  312. {
  313. os_protectUnlock(this->hOs, this->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  314. return NOK;
  315. }
  316. *pMsdu = this->first;
  317. this->first = this->first->nextMSDUinList;
  318. if (this->first != NULL)
  319. this->first->prevMSDUinList = NULL;
  320. this->CurrNumOfMsdu--;
  321. (*pMsdu)->nextMSDUinList = NULL;
  322. os_protectUnlock(this->hOs, this->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  323. return OK;
  324. }
  325. /*************************************************************************
  326. * msduList_MsduListWatchFirst *
  327. *************************************************************************
  328. DESCRIPTION: This function watch at the first SDU in the list. The
  329. MSDU is not removed yet from the list.
  330. INPUT: *this : A pointer to the list to watch.
  331. OUTPUT: *pMsdu : A pointer to the first MSDU in the list.
  332. RETURN: OK : There was an MSDU in the list, and it is assigned
  333. to the *pMsdu.
  334. NOK: The list was empty, *pMsdu is trush.
  335. ************************************************************************/
  336. TI_STATUS msduList_WatchFirst( MsduList_t *this, mem_MSDU_T **pMsdu)
  337. {
  338. os_protectLock(this->hOs, this->hCriticalSectionProtect); /* START OF CRITICAL SECTION */
  339. if( this->CurrNumOfMsdu == 0 )
  340. {
  341. os_protectUnlock(this->hOs, this->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  342. return NOK;
  343. }
  344. *pMsdu = this->first;
  345. os_protectUnlock(this->hOs, this->hCriticalSectionProtect); /* END OF CRITICAL SECTION */
  346. return OK;
  347. }
  348. UINT32 msduList_getCurrNumOfMsdu(MsduList_t *this)
  349. {
  350. return this->CurrNumOfMsdu;
  351. }
  352. /* Debug functions */
  353. /*-----------------*/
  354. void printMsduList(MsduList_t *this)
  355. {
  356. WLAN_OS_REPORT(("Msdu List : \n"));
  357. WLAN_OS_REPORT(("first = %X\n", this->first));
  358. WLAN_OS_REPORT(("last = %X\n", this->last));
  359. WLAN_OS_REPORT(("maxNumOfMsdu = %d\n", this->maxNumOfMsdu));
  360. WLAN_OS_REPORT(("CurrNumOfMsdu = %d\n", this->CurrNumOfMsdu));
  361. WLAN_OS_REPORT(("numOfOverFlow = %d\n", this->numOfOverFlow));
  362. WLAN_OS_REPORT(("maxCurrOfMsdu = %d\n", this->maxCurrOfMsdu));
  363. WLAN_OS_REPORT(("useAdmissionAlgo = %d\n", this->useAdmissionAlgo));
  364. WLAN_OS_REPORT(("credit = %d\n", this->credit));
  365. WLAN_OS_REPORT(("enableTransmissionTime = %d\n", this->enableTransmissionTime));
  366. WLAN_OS_REPORT(("lastTimeStamp = %d\n", this->lastTimeStamp));
  367. WLAN_OS_REPORT(("mediumTime = %d\n", this->mediumTime));
  368. WLAN_OS_REPORT(("totalUsedTime = %d\n", this->totalUsedTime));
  369. }
  370. void printFullMsduList(MsduList_t *this)
  371. {
  372. mem_MSDU_T* tmpMSDU;
  373. UINT32 i=0;
  374. printMsduList(this);
  375. tmpMSDU = this->first;
  376. while (++i, tmpMSDU != NULL)
  377. {
  378. WLAN_OS_REPORT(("tmpMSDU %d = %X handle=%d tmpMSDU->nextMSDU=%X\n", i, tmpMSDU, tmpMSDU->handle, tmpMSDU->nextMSDUinList));
  379. tmpMSDU = tmpMSDU->nextMSDUinList;
  380. }
  381. }