PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/common/src/TNETW_Driver/TNETWIF/TNETWArbiter/TNETWArb_buffer.c

https://bitbucket.org/cyanogenmod/cm-kernel
C | 400 lines | 159 code | 94 blank | 147 comment | 22 complexity | 6ae375c60c23ee2cd976d22c6f2f6316 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.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. #include "commonTypes.h"
  36. #include "memMngrEx.h" /* MSDU */
  37. #include "report.h"
  38. #include "TNETWArb_buffer.h"
  39. #include "TNETWArb.h"
  40. #include "TNETWIF.h"
  41. /* Each module has its own buffer in the TNETW Arbiter synchronizer */
  42. /*******************************************************************************
  43. **
  44. ** Function TNETWArb_init_q
  45. **
  46. ** Description Called by an application to initialize a buffer queue.
  47. **
  48. ** Returns void
  49. **
  50. *******************************************************************************/
  51. void TNETWArb_init_q (BUFFER_Q *p_q)
  52. {
  53. p_q->p_first = p_q->p_last = NULL;
  54. p_q->count = 0;
  55. }
  56. /*******************************************************************************
  57. **
  58. ** Function TNETWArb_getfirst
  59. **
  60. ** Description Return a pointer to the first buffer in a queue
  61. **
  62. ** Returns NULL if queue is empty, else buffer address
  63. **
  64. *******************************************************************************/
  65. void *TNETWArb_getfirst (BUFFER_Q *p_q)
  66. {
  67. return (p_q->p_first);
  68. }
  69. /*******************************************************************************
  70. **
  71. ** Function TNETWArb_getnext
  72. **
  73. ** Description Return a pointer to the next buffer in a queue
  74. **
  75. ** Returns NULL if no more buffers in the queue, else next buffer address
  76. **
  77. *******************************************************************************/
  78. void *TNETWArb_getnext (void *p_buf)
  79. {
  80. BUFFER_HDR_T *p_hdr;
  81. p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
  82. if (p_hdr->p_next)
  83. {
  84. return ((UINT8 *)p_hdr->p_next + BUFFER_HDR_SIZE);
  85. }
  86. else
  87. {
  88. return (NULL);
  89. }
  90. }
  91. /*******************************************************************************
  92. **
  93. ** Function TNETWArb_remove_from_queue
  94. **
  95. ** Description Dequeue a buffer from the middle of the queue
  96. **
  97. ** Returns NULL if queue is empty, else buffer
  98. **
  99. *******************************************************************************/
  100. void *TNETWArb_remove_from_queue (BUFFER_Q *p_q, void *p_buf)
  101. {
  102. BUFFER_HDR_T *p_hdr;
  103. if (!p_q->count)
  104. return (NULL);
  105. p_hdr = (BUFFER_HDR_T *)(p_q->p_first) - 1;
  106. if ((void *)(p_hdr + 1) == p_buf)
  107. return (TNETWArb_Dequeue (p_q));
  108. for ( ; p_hdr; p_hdr = p_hdr->p_next)
  109. {
  110. if ((void *)(p_hdr->p_next + 1) == p_buf)
  111. {
  112. p_hdr->p_next = ((BUFFER_HDR_T *)p_buf - 1)->p_next;
  113. p_q->count--;
  114. /* Unlink the buffer since it has been removed from the queue */
  115. ((BUFFER_HDR_T *)p_buf - 1)->status = BUF_STATUS_UNLINKED;
  116. return (p_buf);
  117. }
  118. }
  119. return (NULL);
  120. }
  121. /*******************************************************************************
  122. **
  123. ** Function TNETWArb_Dequeue
  124. **
  125. ** Description Dequeue a buffer from the head of a queue
  126. ** CAUTION This function Is not protected againt reentrance : see GKI_dequeue
  127. **
  128. ** Returns NULL if queue is empty, else buffer that is dequeued
  129. **
  130. *******************************************************************************/
  131. void *TNETWArb_Dequeue (BUFFER_Q *p_q)
  132. {
  133. BUFFER_HDR_T *p_hdr;
  134. /*WLAN_OS_REPORT(("\n TNETWArb_Dequeue p_q %x !!!! \n", p_q));*/
  135. if (!p_q->count)
  136. return (NULL);
  137. p_hdr = (BUFFER_HDR_T *)((UINT8 *)p_q->p_first - BUFFER_HDR_SIZE);
  138. if (p_hdr->status != BUF_STATUS_QUEUED)
  139. {
  140. WLAN_OS_REPORT(("\n GKI_Dequeue ==> ERROR p_q->p_first %x BUF_STATUS_QUEUED NOT QUEUED!!!! %x\n", p_q->p_first));
  141. return NULL;
  142. }
  143. /* Keep buffers such that GKI header is invisible
  144. */
  145. if (p_hdr->p_next)
  146. {
  147. p_q->p_first = ((UINT8 *)p_hdr->p_next + BUFFER_HDR_SIZE);
  148. }
  149. else
  150. {
  151. p_q->p_first = NULL;
  152. p_q->p_last = NULL;
  153. }
  154. p_q->count--;
  155. p_hdr->p_next = NULL;
  156. p_hdr->status = BUF_STATUS_UNLINKED;
  157. return ((UINT8 *)p_hdr + BUFFER_HDR_SIZE);
  158. }
  159. /*******************************************************************************
  160. **
  161. ** Function TNETWArb_Enqueue
  162. **
  163. ** Description Enqueue a buffer at the tail of the queue.
  164. ** CAUTION This function Is not protected againt reentrance
  165. **
  166. ** Returns void
  167. **
  168. *******************************************************************************/
  169. void TNETWArb_Enqueue (BUFFER_Q *p_q, void *p_buf)
  170. {
  171. BUFFER_HDR_T *p_hdr;
  172. p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
  173. if (p_hdr->status != BUF_STATUS_UNLINKED)
  174. {
  175. WLAN_OS_REPORT(("\n GKI_Enqueue ==> ERROR p_buf %x BUF_STATUS_UNLINKED!!!! %x\n", p_buf));
  176. return;
  177. }
  178. /* Since the queue is exposed (C vs C++), keep the pointers in exposed format */
  179. if (p_q->p_first)
  180. {
  181. BUFFER_HDR_T *p_last_hdr = (BUFFER_HDR_T *)((UINT8 *)p_q->p_last - BUFFER_HDR_SIZE);
  182. p_last_hdr->p_next = p_hdr;
  183. }
  184. else
  185. {
  186. p_q->p_first = p_buf;
  187. }
  188. p_q->p_last = p_buf;
  189. p_q->count++;
  190. p_hdr->p_next = NULL;
  191. p_hdr->status = BUF_STATUS_QUEUED;
  192. }
  193. /*******************************************************************************
  194. **
  195. ** Function TNETWArb_Enqueue_head
  196. **
  197. ** Description Enqueue a buffer at the head of the queue
  198. **
  199. ** Returns void
  200. **
  201. *******************************************************************************/
  202. void TNETWArb_Enqueue_head (BUFFER_Q *p_q, void *p_buf)
  203. {
  204. BUFFER_HDR_T *p_hdr;
  205. p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
  206. if (p_hdr->status != BUF_STATUS_UNLINKED)
  207. {
  208. WLAN_OS_REPORT(("\n GKI_Enqueue ==> ERROR p_buf %x BUF_STATUS_UNLINKED!!!! %x\n", p_buf));
  209. return;
  210. }
  211. if (p_q->p_first)
  212. {
  213. p_hdr->p_next = (BUFFER_HDR_T *)((UINT8 *)p_q->p_first - BUFFER_HDR_SIZE);
  214. p_q->p_first = p_buf;
  215. }
  216. else
  217. {
  218. p_q->p_first = p_buf;
  219. p_q->p_last = p_buf;
  220. p_hdr->p_next = NULL;
  221. }
  222. p_q->count++;
  223. p_hdr->status = BUF_STATUS_QUEUED;
  224. }
  225. /************************* NEW GKI FOR WLAN ***********************************/
  226. /*******************************************************************************
  227. **
  228. ** Function TNETWArb_buffer_init
  229. **
  230. ** Description Called once internally by GKI at startup to initialize all
  231. ** buffers and free buffer pools.
  232. **
  233. ** Returns void
  234. **
  235. *******************************************************************************/
  236. void TNETWArb_buffer_init(UINT8 *pTNETWArb_Client_Array)
  237. {
  238. BUFFER_HDR_T *p_hdr;
  239. void *p_buf;
  240. UINT8 module_id;
  241. /*
  242. ** Resetting the buffer to STATUS_FREE
  243. */
  244. for (module_id = 0; module_id < NUM_OF_TNETWIF_MODULES; module_id++)
  245. {
  246. /* Pick up corresponding buffer */
  247. p_buf = (void *)(&(pTNETWArb_Client_Array[module_id*(BUFFER_HDR_SIZE+TNETWARB_INSTANCE_SIZE)]) + BUFFER_HDR_SIZE);
  248. p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
  249. p_hdr->p_next = NULL; /* There is no next buffer of the last one*/
  250. p_hdr->status = BUF_STATUS_FREE; /* Update the status of the released buffer*/
  251. }
  252. }
  253. /*******************BUFFER ALLOCATION******************************************/
  254. /*******************************************************************************
  255. **
  256. ** Function TNETWArb_getpoolbuf
  257. **
  258. ** Description Called by an application to get a free buffer from
  259. ** a specific buffer pool should be used in sections which no interrupts
  260. ** protection is needed.
  261. **
  262. ** Returns A pointer to the buffer, or NULL if none available
  263. **
  264. *******************************************************************************/
  265. void *TNETWArb_getpoolbuf (TI_HANDLE hTNETWArb,UINT8 module_id)
  266. {
  267. /* Handle to TNETW Arbiter struct */
  268. TNETWArb_t *pTNETWArb = (TNETWArb_t *)hTNETWArb;
  269. BUFFER_HDR_T *p_hdr;
  270. void *p_buf;
  271. p_buf = (void *)((&(pTNETWArb->TNETWArb_Client_Instance_Array[module_id][0])) + BUFFER_HDR_SIZE);
  272. p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
  273. if (p_hdr->status != BUF_STATUS_FREE)
  274. {
  275. /*WLAN_OS_REPORT(("\n GKI_getpoolbuf ==> ERROR p_hdr %x NOT FREE Status %d module_id %d !!!\n", p_hdr,p_hdr->status,module_id));*/
  276. return NULL;
  277. }
  278. p_hdr->status = BUF_STATUS_UNLINKED;
  279. p_hdr->p_next = NULL;
  280. return ((void *) ((UINT8 *)p_hdr + BUFFER_HDR_SIZE));
  281. }
  282. /*******************************************************************************
  283. **
  284. ** Function TNETWArb_freebuf
  285. **
  286. ** Description Called by an application to return a buffer to the free pool.
  287. ** To be used in sections which no interrupts protection is needed.
  288. **
  289. ** Returns void
  290. **
  291. *******************************************************************************/
  292. void TNETWArb_freebuf(void *bptr)
  293. {
  294. BUFFER_HDR_T *p_hdr;
  295. p_hdr = (BUFFER_HDR_T *) ((UINT8 *)bptr - BUFFER_HDR_SIZE);
  296. if (p_hdr->status != BUF_STATUS_UNLINKED)
  297. {
  298. WLAN_OS_REPORT(("\n GKI_freebuf ==> ERROR bptr %x BUF_STATUS_UNLINKED!!!! %x\n", bptr));
  299. return;
  300. }
  301. /*
  302. ** Resetting the buffer to STATUS_FREE
  303. */
  304. p_hdr->p_next = NULL; /* There is no next buffer of the last one*/
  305. p_hdr->status = BUF_STATUS_FREE; /* Update the status of the released buffer*/
  306. }