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

Language C Lines 401
MD5 Hash 6ae375c60c23ee2cd976d22c6f2f6316 Estimated Cost $3,918 (why?)
Repository git://github.com/CyanogenMod/cm-kernel.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
/****************************************************************************
**+-----------------------------------------------------------------------+**
**|                                                                       |**
**| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
**| All rights reserved.                                                  |**
**|                                                                       |**
**| Redistribution and use in source and binary forms, with or without    |**
**| modification, are permitted provided that the following conditions    |**
**| are met:                                                              |**
**|                                                                       |**
**|  * Redistributions of source code must retain the above copyright     |**
**|    notice, this list of conditions and the following disclaimer.      |**
**|  * Redistributions in binary form must reproduce the above copyright  |**
**|    notice, this list of conditions and the following disclaimer in    |**
**|    the documentation and/or other materials provided with the         |**
**|    distribution.                                                      |**
**|  * Neither the name Texas Instruments nor the names of its            |**
**|    contributors may be used to endorse or promote products derived    |**
**|    from this software without specific prior written permission.      |**
**|                                                                       |**
**| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
**| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
**| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
**| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
**| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
**| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
**| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
**| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
**| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
**| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
**| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
**|                                                                       |**
**+-----------------------------------------------------------------------+**
****************************************************************************/


#include "commonTypes.h"
#include "memMngrEx.h" /* MSDU */
#include "report.h"

#include "TNETWArb_buffer.h"
#include "TNETWArb.h"
#include "TNETWIF.h"


/* Each module has its own buffer in the TNETW Arbiter synchronizer */

/*******************************************************************************
**
** Function         TNETWArb_init_q
**
** Description      Called by an application to initialize a buffer queue.
**
** Returns          void
**
*******************************************************************************/
void TNETWArb_init_q (BUFFER_Q *p_q)
{
    p_q->p_first = p_q->p_last = NULL;
    p_q->count = 0;
}



/*******************************************************************************
**
** Function         TNETWArb_getfirst
**
** Description      Return a pointer to the first buffer in a queue
**
** Returns          NULL if queue is empty, else buffer address
**
*******************************************************************************/
void *TNETWArb_getfirst (BUFFER_Q *p_q)
{
    return (p_q->p_first);
}

/*******************************************************************************
**
** Function         TNETWArb_getnext
**
** Description      Return a pointer to the next buffer in a queue
**
** Returns          NULL if no more buffers in the queue, else next buffer address
**
*******************************************************************************/
void *TNETWArb_getnext (void *p_buf)
{
    BUFFER_HDR_T    *p_hdr;

    p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);

	 if (p_hdr->p_next)
	{
        return ((UINT8 *)p_hdr->p_next + BUFFER_HDR_SIZE);
	}
    else
	{
		return (NULL);
	}
}


/*******************************************************************************
**
** Function         TNETWArb_remove_from_queue
**
** Description      Dequeue a buffer from the middle of the queue
**
** Returns          NULL if queue is empty, else buffer
**
*******************************************************************************/
void *TNETWArb_remove_from_queue (BUFFER_Q *p_q, void *p_buf)
{
    BUFFER_HDR_T *p_hdr;

    if (!p_q->count)
        return (NULL);

    p_hdr = (BUFFER_HDR_T *)(p_q->p_first) - 1;

    if ((void *)(p_hdr + 1) == p_buf)
        return (TNETWArb_Dequeue (p_q));

	for ( ; p_hdr; p_hdr = p_hdr->p_next)
    {
        if ((void *)(p_hdr->p_next + 1) == p_buf)
        {
            p_hdr->p_next = ((BUFFER_HDR_T *)p_buf - 1)->p_next;
            p_q->count--;

            /* Unlink the buffer since it has been removed from the queue */
            ((BUFFER_HDR_T *)p_buf - 1)->status = BUF_STATUS_UNLINKED;	
		
            return (p_buf);
        }
    }

    return (NULL);
}



/*******************************************************************************
**
** Function         TNETWArb_Dequeue
**
** Description      Dequeue a buffer from the head of a queue
**                  CAUTION This function Is not protected againt reentrance : see GKI_dequeue
**
** Returns          NULL if queue is empty, else buffer that is dequeued
**
*******************************************************************************/
void *TNETWArb_Dequeue (BUFFER_Q *p_q)
{
    BUFFER_HDR_T    *p_hdr;

	/*WLAN_OS_REPORT(("\n TNETWArb_Dequeue  p_q %x  !!!!  \n", p_q));*/

    if (!p_q->count)
        return (NULL);

    p_hdr = (BUFFER_HDR_T *)((UINT8 *)p_q->p_first - BUFFER_HDR_SIZE);


	if (p_hdr->status != BUF_STATUS_QUEUED)
    {
		WLAN_OS_REPORT(("\n GKI_Dequeue ==>  ERROR  p_q->p_first %x BUF_STATUS_QUEUED NOT QUEUED!!!!  %x\n", p_q->p_first));
        return NULL;
    }


    /* Keep buffers such that GKI header is invisible
    */
	if (p_hdr->p_next)
	{
        p_q->p_first = ((UINT8 *)p_hdr->p_next + BUFFER_HDR_SIZE);
	}
    else
    {
        p_q->p_first = NULL;
        p_q->p_last  = NULL;
    }

    p_q->count--;

    p_hdr->p_next = NULL;
	p_hdr->status = BUF_STATUS_UNLINKED;

    return ((UINT8 *)p_hdr + BUFFER_HDR_SIZE);
}


/*******************************************************************************
**
** Function         TNETWArb_Enqueue
**
** Description      Enqueue a buffer at the tail of the queue.
**                  CAUTION This function Is not protected againt reentrance 
**
** Returns          void
**
*******************************************************************************/
void TNETWArb_Enqueue (BUFFER_Q *p_q, void *p_buf)
{
    BUFFER_HDR_T    *p_hdr;

    p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);


	if (p_hdr->status != BUF_STATUS_UNLINKED)
    {
		WLAN_OS_REPORT(("\n GKI_Enqueue ==>  ERROR  p_buf %x BUF_STATUS_UNLINKED!!!!  %x\n", p_buf));
        return;
    }

    /* Since the queue is exposed (C vs C++), keep the pointers in exposed format */
    if (p_q->p_first)
    {
		BUFFER_HDR_T *p_last_hdr = (BUFFER_HDR_T *)((UINT8 *)p_q->p_last - BUFFER_HDR_SIZE);
        
		p_last_hdr->p_next = p_hdr;

    }
    else
	{
        p_q->p_first = p_buf;
	}

    p_q->p_last = p_buf;
    p_q->count++;
    
	p_hdr->p_next = NULL;
	p_hdr->status = BUF_STATUS_QUEUED;


}


/*******************************************************************************
**
** Function         TNETWArb_Enqueue_head
**
** Description      Enqueue a buffer at the head of the queue
**
** Returns          void
**
*******************************************************************************/
void TNETWArb_Enqueue_head (BUFFER_Q *p_q, void *p_buf)
{
    BUFFER_HDR_T    *p_hdr;


    p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);

	if (p_hdr->status != BUF_STATUS_UNLINKED)	
    {
		WLAN_OS_REPORT(("\n GKI_Enqueue ==>  ERROR  p_buf %x BUF_STATUS_UNLINKED!!!!  %x\n", p_buf));
        return;
    }

    if (p_q->p_first)
    {

        p_hdr->p_next = (BUFFER_HDR_T *)((UINT8 *)p_q->p_first - BUFFER_HDR_SIZE);
        p_q->p_first = p_buf;
    }
    else
    {
        p_q->p_first = p_buf;
        p_q->p_last  = p_buf;
        p_hdr->p_next = NULL;


    }

    p_q->count++;

	p_hdr->status = BUF_STATUS_QUEUED;

}









/************************* NEW GKI FOR WLAN ***********************************/

/*******************************************************************************
**
** Function         TNETWArb_buffer_init
**
** Description      Called once internally by GKI at startup to initialize all
**                  buffers and free buffer pools.
**
** Returns          void
**
*******************************************************************************/
void TNETWArb_buffer_init(UINT8 *pTNETWArb_Client_Array)
{
    BUFFER_HDR_T  *p_hdr;
	void		  *p_buf;
	UINT8			module_id;


	/*
	** Resetting the buffer to STATUS_FREE
	*/
    for (module_id = 0; module_id < NUM_OF_TNETWIF_MODULES; module_id++)
    {
		/* Pick up corresponding buffer */
		p_buf = (void *)(&(pTNETWArb_Client_Array[module_id*(BUFFER_HDR_SIZE+TNETWARB_INSTANCE_SIZE)]) + BUFFER_HDR_SIZE);
		p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);

		p_hdr->p_next  = NULL;   /* There is no next buffer of the last one*/
		p_hdr->status  = BUF_STATUS_FREE; /* Update the status of the released buffer*/
	}

}




/*******************BUFFER ALLOCATION******************************************/

/*******************************************************************************
**
** Function         TNETWArb_getpoolbuf
**
** Description      Called by an application to get a free buffer from
**                  a specific buffer pool should be used in sections which no interrupts 
**					protection is needed.
**
** Returns          A pointer to the buffer, or NULL if none available
**
*******************************************************************************/
void *TNETWArb_getpoolbuf (TI_HANDLE hTNETWArb,UINT8 module_id)
{
	/* Handle to TNETW Arbiter struct */
	TNETWArb_t	  *pTNETWArb = (TNETWArb_t *)hTNETWArb;	
    BUFFER_HDR_T  *p_hdr;
	void		  *p_buf;

	p_buf = (void *)((&(pTNETWArb->TNETWArb_Client_Instance_Array[module_id][0])) + BUFFER_HDR_SIZE);

    p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);

	if (p_hdr->status != BUF_STATUS_FREE)	
	{	
		/*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));*/
		return NULL;
	}

    p_hdr->status  = BUF_STATUS_UNLINKED;
    p_hdr->p_next  = NULL;
		
	return ((void *) ((UINT8 *)p_hdr + BUFFER_HDR_SIZE));

}


/*******************************************************************************
**
** Function         TNETWArb_freebuf
**
** Description      Called by an application to return a buffer to the free pool.
**					To be used in sections which no interrupts protection is needed. 
**
** Returns          void
**
*******************************************************************************/
void TNETWArb_freebuf(void *bptr)
{
	BUFFER_HDR_T	*p_hdr;


	p_hdr = (BUFFER_HDR_T *) ((UINT8 *)bptr - BUFFER_HDR_SIZE);

	if (p_hdr->status != BUF_STATUS_UNLINKED)	
	{	
		WLAN_OS_REPORT(("\n GKI_freebuf ==>  ERROR  bptr %x BUF_STATUS_UNLINKED!!!!  %x\n", bptr));
		return;
	}

	/*
	** Resetting the buffer to STATUS_FREE
	*/
	p_hdr->p_next  = NULL;   /* There is no next buffer of the last one*/
	p_hdr->status  = BUF_STATUS_FREE; /* Update the status of the released buffer*/
		
}
Back to Top