blob: a36c6b3c531851e50ddb2cbd9a34d6bd14b97e7c [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Kiet Lamaa8e15a2014-02-11 23:30:06 -08002 * Copyright (c) 2012-2013 Qualcomm Atheros, Inc.
3 * All Rights Reserved.
4 * Qualcomm Atheros Confidential and Proprietary.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08005 */
Jeff Johnson295189b2012-06-20 16:38:30 -07006/**=============================================================================
7
8 vos_list.c
9
10 \brief
11
12 Description...
13
14
15 Copyright 2008 (c) Qualcomm, Incorporated.
16 All Rights Reserved.
17 Qualcomm Confidential and Proprietary.
18
19 ==============================================================================**/
20/* $HEADER$ */
21
22/**-----------------------------------------------------------------------------
23 Include files
24 ----------------------------------------------------------------------------*/
25#include <vos_list.h>
26#include <vos_trace.h>
27
28/**-----------------------------------------------------------------------------
29 Preprocessor definitions and constants
30 ----------------------------------------------------------------------------*/
31#define VOS_LIST_COOKIE 0xabadfeed
32
33
34/**-----------------------------------------------------------------------------
35 Type declarations
36 ----------------------------------------------------------------------------*/
37
38/**-----------------------------------------------------------------------------
39 Function declarations and documenation
40 ----------------------------------------------------------------------------*/
41VOS_STATUS vos_list_init( vos_list_t *pList )
42{
43 if ( pList == NULL)
44 {
45 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070046 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070047 return VOS_STATUS_E_FAULT;
48 }
49
50 if ( pList->cookie == VOS_LIST_COOKIE )
51 {
52 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070053 "%s: already initialized list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070054 return VOS_STATUS_E_BUSY;
55 }
56
57 mutex_init(&pList->lock);
58
59 INIT_LIST_HEAD( &pList->anchor );
60
61 pList->count = 0;
62 pList->cookie = VOS_LIST_COOKIE;
63
64 return( VOS_STATUS_SUCCESS );
65}
66
67
68VOS_STATUS vos_list_destroy( vos_list_t *pList )
69{
70 int rc;
71 if (pList == NULL)
72 {
73 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070074 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070075 return VOS_STATUS_E_FAULT;
76 }
77
78 if ( pList->cookie != VOS_LIST_COOKIE )
79 {
80 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070081 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070082 return VOS_STATUS_E_INVAL;
83 }
84
85 rc = mutex_lock_interruptible(&pList->lock);
86 if (rc)
87 {
88 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070089 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070090 return VOS_STATUS_E_FAULT;
91 }
92
93 if ( pList->count !=0 )
94 {
95 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070096 "%s: list length not equal to zero", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -070097 mutex_unlock(&pList->lock);
98 return VOS_STATUS_E_BUSY;
99 }
100
101 // clear the cookie. This indicates the list is destroyed.
102 pList->cookie = 0;
103 mutex_unlock(&pList->lock);
104
105 return VOS_STATUS_SUCCESS;
106}
107
108
109VOS_STATUS vos_list_insert_front( vos_list_t *pList, vos_list_node_t *pNode )
110{
111 int rc;
112
113 if ( ( pList == NULL) || ( pNode == NULL) )
114 {
115 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700116 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700117 return VOS_STATUS_E_FAULT;
118 }
119
120 if ( pList->cookie != VOS_LIST_COOKIE )
121 {
122 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700123 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700124 return VOS_STATUS_E_INVAL;
125 }
126
127 rc = mutex_lock_interruptible(&pList->lock);
128 if (rc)
129 {
130 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700131 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700132 return VOS_STATUS_E_FAULT;
133 }
134
135 list_add( pNode, &pList->anchor );
136
137 pList->count++;
138 mutex_unlock(&pList->lock);
139
140 return VOS_STATUS_SUCCESS;
141}
142
143VOS_STATUS vos_list_insert_back( vos_list_t *pList, vos_list_node_t *pNode )
144{
145 int rc;
146
147 if ( ( pList == NULL) || ( pNode == NULL) )
148 {
149 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700150 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700151 return VOS_STATUS_E_FAULT;
152 }
153
154 if ( pList->cookie != VOS_LIST_COOKIE )
155 {
156 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700157 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700158 return VOS_STATUS_E_INVAL;
159 }
160
161 rc = mutex_lock_interruptible(&pList->lock);
162 if (rc)
163 {
164 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700165 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700166 return VOS_STATUS_E_FAULT;
167 }
168
169 list_add_tail( pNode, &pList->anchor );
170
171 pList->count++;
172 mutex_unlock(&pList->lock);
173
174 return VOS_STATUS_SUCCESS;
175}
176
177
178VOS_STATUS vos_list_insert_back_size( vos_list_t *pList, vos_list_node_t *pNode, v_SIZE_t *pSize )
179{
180 int rc;
181 if ( ( pList == NULL) || ( pNode == NULL) || (pSize == NULL) )
182 {
183 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700184 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700185 return VOS_STATUS_E_FAULT;
186 }
187
188 if ( pList->cookie != VOS_LIST_COOKIE )
189 {
190 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700191 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700192 return VOS_STATUS_E_INVAL;
193 }
194
195 rc = mutex_lock_interruptible(&pList->lock);
196 if (rc)
197 {
198 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700199 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700200 return VOS_STATUS_E_FAULT;
201 }
202
203 list_add_tail( pNode, &pList->anchor );
204
205 pList->count++;
206 *pSize = pList->count;
207 mutex_unlock(&pList->lock);
208
209 return VOS_STATUS_SUCCESS;
210}
211
212
213VOS_STATUS vos_list_remove_front( vos_list_t *pList, vos_list_node_t **ppNode )
214{
215 struct list_head * listptr;
216 int rc;
217
218 // the assumption here is that pList is the head of the list (dummy
219 // node) and points to first and last element in circular linked list
220 if ( ( pList == NULL ) || ( ppNode == NULL) )
221 {
222 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700223 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700224 return VOS_STATUS_E_FAULT;
225 }
226
227 if ( pList->cookie != VOS_LIST_COOKIE )
228 {
229 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700230 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700231 return VOS_STATUS_E_INVAL;
232 }
233
234 rc = mutex_lock_interruptible(&pList->lock);
235 if (rc)
236 {
237 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700238 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700239 return VOS_STATUS_E_FAULT;
240 }
241
242 if ( list_empty( &pList->anchor ) )
243 {
Mohit Khanna23863762012-09-11 17:40:09 -0700244 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700245 "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700246 mutex_unlock(&pList->lock);
247 return VOS_STATUS_E_EMPTY;
248 }
249
250 listptr = pList->anchor.next;
251
252 *ppNode = listptr;
253
254 list_del(pList->anchor.next);
255
256 pList->count--;
257 mutex_unlock(&pList->lock);
258 return VOS_STATUS_SUCCESS;
259}
260
261
262
263VOS_STATUS vos_list_remove_back( vos_list_t *pList, vos_list_node_t **ppNode )
264{
265 struct list_head * listptr;
266 int rc;
267
268 // the assumption here is that pList is the head of the list (dummy node) and points to first and
269 // last element in circular linked list
270 if ( ( pList == NULL ) || ( ppNode == NULL) )
271 {
272 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700273 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700274 return VOS_STATUS_E_FAULT;
275 }
276
277 if ( pList->cookie != VOS_LIST_COOKIE )
278 {
279 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700280 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700281 return VOS_STATUS_E_INVAL;
282 }
283
284 rc = mutex_lock_interruptible(&pList->lock);
285 if (rc)
286 {
287 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700288 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700289 return VOS_STATUS_E_FAULT;
290 }
291
292 if ( list_empty( &pList->anchor ) )
293 {
294 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_WARN,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700295 "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700296 mutex_unlock(&pList->lock);
297 return VOS_STATUS_E_EMPTY;
298 }
299
300 listptr = pList->anchor.prev;
301
302 *ppNode = listptr;
303
304 list_del(pList->anchor.prev);
305
306 pList->count--;
307 mutex_unlock(&pList->lock);
308
309 return VOS_STATUS_SUCCESS;
310}
311
312VOS_STATUS vos_list_size( vos_list_t *pList, v_SIZE_t *pSize )
313{
314 int rc;
315 if ( ( pList ==NULL) || ( pSize == NULL) )
316 {
317 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700318 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700319 return VOS_STATUS_E_FAULT;
320 }
321
322 if ( pList->cookie != VOS_LIST_COOKIE )
323 {
324 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700325 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700326 return VOS_STATUS_E_INVAL;
327 }
328
329 rc = mutex_lock_interruptible(&pList->lock);
330 if (rc)
331 {
332 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700333 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700334 return VOS_STATUS_E_FAULT;
335 }
336
337 *pSize = pList->count;
338 mutex_unlock(&pList->lock);
339
340 return VOS_STATUS_SUCCESS;
341}
342
343
344/*----------------------------------------------------------------------------
345
346 \brief vos_list_peek_front() - peek at the node at front of a linked list
347
348 The vos_list_peek_front() API will return a pointer to the node at the
349 front of a properly initialized vOS List object. The node will *not* be
350 removed from the list.
351
352 \param pList - Pointer to list object of the list to be 'peeked'
353
354 \param ppNode - Pointer to a pointer to the list node that exists at
355 the front of the list.
356
357 \return VOS_STATUS_SUCCESS - list node at the front of the list was
358 successfully returned.
359
360 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
361 initialized list object.
362
363 VOS_STATUS_E_EMPTY - The specified is empty so nodes cannot be
364 removed.
365
366 VOS_STATUS_E_FAULT - pList or or ppNode is an invalid pointer.
367
368 \sa vos_list_remove_back()
369
370 --------------------------------------------------------------------------*/
371
372VOS_STATUS vos_list_peek_front( vos_list_t *pList, vos_list_node_t **ppNode )
373{
374 struct list_head * listptr;
375 int rc;
376
377 if ( ( pList == NULL) || ( ppNode == NULL) )
378 {
379 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700380 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700381 return VOS_STATUS_E_FAULT;
382 }
383
384 if ( pList->cookie != VOS_LIST_COOKIE )
385 {
386 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700387 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700388 return VOS_STATUS_E_INVAL;
389 }
390
391 rc = mutex_lock_interruptible(&pList->lock);
392 if (rc)
393 {
394 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700395 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700396 return VOS_STATUS_E_FAULT;
397 }
398
399 if ( list_empty(&pList->anchor) )
400 {
401 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_WARN,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700402 "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700403 mutex_unlock(&pList->lock);
404 return VOS_STATUS_E_EMPTY;
405 }
406 listptr = pList->anchor.next;
407 *ppNode = listptr;
408 mutex_unlock(&pList->lock);
409
410 return VOS_STATUS_SUCCESS;
411}
412
413/*----------------------------------------------------------------------------
414
415 \brief vos_list_peek_back() - peek at the node at back of a linked list
416
417 The vos_list_peek_back() API will return a pointer to the node at the
418 back of a properly initialized vOS List object. The node will *not* be
419 removed from the list.
420
421 \param pList - Pointer to list object of the list to be 'peeked'
422
423 \param ppNode - Pointer to a pointer to the list node that exists at
424 the back of the list.
425
426 \return VOS_STATUS_SUCCESS - list node at the back of the list was
427 successfully returned.
428
429 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
430 initialized list object.
431
432 VOS_STATUS_E_EMPTY - The specified is empty so nodes cannot be
433 removed.
434
435 VOS_STATUS_E_FAULT - pList or or ppNode is an invalid pointer.
436
437 \sa vos_list_peek_back(), vos_list_remove_back(), vos_list_peek_front(),
438 vos_list_remove_front()
439
440 --------------------------------------------------------------------------*/
441
442VOS_STATUS vos_list_peek_back( vos_list_t *pList, vos_list_node_t **ppNode )
443{
444 struct list_head * listptr;
445 int rc;
446
447 if ( ( pList == NULL) || ( ppNode == NULL) )
448 {
449 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700450 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700451 return VOS_STATUS_E_FAULT;
452 }
453
454 if ( pList->cookie != VOS_LIST_COOKIE )
455 {
456 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700457 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700458 return VOS_STATUS_E_INVAL;
459 }
460
461 rc = mutex_lock_interruptible(&pList->lock);
462 if (rc)
463 {
464 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700465 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700466 return VOS_STATUS_E_FAULT;
467 }
468
469 if ( list_empty(&pList->anchor) )
470 {
471 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_WARN,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700472 "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700473 mutex_unlock(&pList->lock);
474 return VOS_STATUS_E_EMPTY;
475 }
476 listptr = pList->anchor.prev;
477 *ppNode = listptr;
478 mutex_unlock(&pList->lock);
479
480 return VOS_STATUS_SUCCESS;
481}
482
483/*----------------------------------------------------------------------------
484
485 \brief vos_list_peek_next() - peek at the node after the specified node
486
487 The vos_list_peek_next() API will return a pointer to the node following the
488 specified node on a properly initialized vOS List object. The node will
489 *not* be removed from the list.
490
491 \param pList - Pointer to list object of the list to be 'peeked'
492
493 \param pNode - Pointer to the node that is being 'peeked'
494
495 \param ppNode - Pointer to a pointer to the list node that follows the
496 pNode node on the list.
497
498 \return VOS_STATUS_SUCCESS - list node following pNode on the properly
499 initialized list is successfully returned.
500
501 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
502 initialized list object.
503
504 VOS_STATUS_E_EMPTY - There is no 'next' node (the input node is
505 at the back of the list).
506
507 VOS_STATUS_E_FAULT - pList, pNode or ppNode is an invalid pointer.
508
509 \sa vos_list_remove_back()
510
511 --------------------------------------------------------------------------*/
512
513VOS_STATUS vos_list_peek_next( vos_list_t *pList, vos_list_node_t *pNode,
514 vos_list_node_t **ppNode )
515{
516 struct list_head * listptr;
517 int rc, found = 0;
518 vos_list_node_t *tmp;
519
520 if ( ( pList == NULL) || ( pNode == NULL) || (ppNode == NULL))
521 {
522 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700523 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700524 return VOS_STATUS_E_FAULT;
525 }
526
527 if ( pList->cookie != VOS_LIST_COOKIE )
528 {
529 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700530 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700531 return VOS_STATUS_E_INVAL;
532 }
533
534 rc = mutex_lock_interruptible(&pList->lock);
535 if (rc)
536 {
537 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700538 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700539 return VOS_STATUS_E_FAULT;
540 }
541
542 if ( list_empty(&pList->anchor) )
543 {
544 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700545 "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700546 mutex_unlock(&pList->lock);
547 return VOS_STATUS_E_EMPTY;
548 }
549
550 // verify that pNode is indeed part of list pList
551 list_for_each(tmp, &pList->anchor)
552 {
553 if (tmp == pNode)
554 {
555 found = 1;
556 break;
557 }
558 }
559 if (found == 0)
560 return VOS_STATUS_E_INVAL;
561
562 listptr = pNode->next;
563 if (listptr == &pList->anchor)
564 {
565 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700566 "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700567 mutex_unlock(&pList->lock);
568 return VOS_STATUS_E_EMPTY;
569 }
570
571 *ppNode = listptr;
572 mutex_unlock(&pList->lock);
573
574 return VOS_STATUS_SUCCESS;
575}
576
577/*----------------------------------------------------------------------------
578
579 \brief vos_list_peek_prev() - peek at the node before the specified node
580
581 The vos_list_peek_prev() API will return a pointer to the node before the
582 specified node on a properly initialized vOS List object. The node will
583 *not* be removed from the list.
584
585 \param pList - Pointer to list object of the list to be 'peeked'
586
587 \param pNode - Pointer to the node that is being 'peeked'
588
589 \param ppNode - Pointer to a pointer to the list node before the
590 pNode node on the list.
591
592 \return VOS_STATUS_SUCCESS - list node before pNode on the properly
593 initialized list is successfully returned.
594
595 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
596 initialized list object.
597
598 VOS_STATUS_E_EMPTY - There is no 'previous' node (the input node is
599 at the front of the list).
600
601 VOS_STATUS_E_FAULT - pList, pNode or ppNode is an invalid pointer.
602
603 \sa vos_list_remove_back()
604
605 --------------------------------------------------------------------------*/
606
607VOS_STATUS vos_list_peek_prev( vos_list_t *pList, vos_list_node_t *pNode,
608 vos_list_node_t **ppNode )
609{
610 struct list_head * listptr;
611 int rc, found = 0;
612 vos_list_node_t *tmp;
613
614 if ( ( pList == NULL) || ( pNode == NULL) || (ppNode == NULL) )
615 {
616 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700617 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700618 return VOS_STATUS_E_FAULT;
619 }
620
621 if ( pList->cookie != VOS_LIST_COOKIE )
622 {
623 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700624 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700625 return VOS_STATUS_E_INVAL;
626 }
627
628 rc = mutex_lock_interruptible(&pList->lock);
629 if (rc)
630 {
631 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700632 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700633 return VOS_STATUS_E_FAULT;
634 }
635
636 if ( list_empty(&pList->anchor) )
637 {
638 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_WARN,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700639 "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700640 mutex_unlock(&pList->lock);
641 return VOS_STATUS_E_EMPTY;
642 }
643
644 // verify that pNode is indeed part of list pList
645 list_for_each(tmp, &pList->anchor)
646 {
647 if (tmp == pNode)
648 {
649 found = 1;
650 break;
651 }
652 }
653 if (found == 0)
654 return VOS_STATUS_E_INVAL;
655
656 listptr = pNode->prev;
657
658 if (listptr == &pList->anchor)
659 {
660 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_WARN,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700661 "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700662 mutex_unlock(&pList->lock);
663 return VOS_STATUS_E_EMPTY;
664 }
665
666 *ppNode = listptr;
667 mutex_unlock(&pList->lock);
668
669 return VOS_STATUS_SUCCESS;
670}
671
672/*----------------------------------------------------------------------------
673
674 \brief vos_list_insert_before() - insert node at front of a specified
675 list node
676
677 The vos_list_insert_before() API will insert a node onto a properly
678 initialized vOS List object in front of the specified list node.
679
680 \param pList - Pointer to list object where the node will be inserted
681
682 \param pNodeToInsert - Pointer to the list node to be inserted into the list.
683
684 \param pNode - Pointer to the list node where pNodeToInsert will be inserted
685 in front of.
686
687 \return VOS_STATUS_SUCCESS - list node was successfully inserted onto
688 the front of the list.
689
690 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
691 initialized list object.
692
693 VOS_STATUS_E_FAULT - pList, pNodeToInsert, or pNode are
694 invalid pointer(s)
695
696 \sa
697
698 --------------------------------------------------------------------------*/
699VOS_STATUS vos_list_insert_before( vos_list_t *pList, vos_list_node_t *pNodeToInsert,
700 vos_list_node_t *pNode )
701{
702 int rc, found = 0;
703 vos_list_node_t *tmp;
704
705 if ( ( pList == NULL) || ( pNode == NULL) || (pNodeToInsert == NULL))
706 {
707 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700708 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700709 return VOS_STATUS_E_FAULT;
710 }
711
712 if ( pList->cookie != VOS_LIST_COOKIE )
713 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700714 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700715 return VOS_STATUS_E_INVAL;
716 }
717
718 rc = mutex_lock_interruptible(&pList->lock);
719 if (rc)
720 {
721 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700722 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700723 return VOS_STATUS_E_FAULT;
724 }
725
726 if ( list_empty(&pList->anchor) )
727 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700728 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700729 mutex_unlock(&pList->lock);
730 return VOS_STATUS_E_EMPTY;
731 }
732
733 // verify that pNode is indeed part of list pList
734 list_for_each(tmp, &pList->anchor)
735 {
736 if (tmp == pNode)
737 {
738 found = 1;
739 break;
740 }
741 }
742 if (found == 0)
743 return VOS_STATUS_E_INVAL;
744
745 list_add(pNodeToInsert, pNode);
746 pList->count++;
747 mutex_unlock(&pList->lock);
748
749 return VOS_STATUS_SUCCESS;
750}
751
752
753/*----------------------------------------------------------------------------
754
755 \brief vos_list_insert_after() - insert node behind a specified list node
756
757 The vos_list_insert_after() API will insert a node onto a properly
758 initialized vOS List object after the specified list node.
759
760 \param pList - Pointer to list object where the node will be inserted
761
762 \param pNodeToInsert - Pointer to the list node to be inserted into the list.
763
764 \param pNode - Pointer to the list node where pNodeToInsert will be inserted
765 after.
766
767 \return VOS_STATUS_SUCCESS - list node was successfully inserted onto
768 the front of the list.
769
770 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
771 initialized list object.
772
773 VOS_STATUS_E_FAULT - pList, pNodeToInsert, or pNode are
774 invalid pointer(s)
775
776 \sa
777
778 --------------------------------------------------------------------------*/
779VOS_STATUS vos_list_insert_after( vos_list_t *pList, vos_list_node_t *pNodeToInsert,
780 vos_list_node_t *pNode )
781{
782 int rc, found = 0;
783 vos_list_node_t *tmp;
784
785 if ( ( pList == NULL) || ( pNode == NULL) || (pNodeToInsert == NULL))
786 {
787 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700788 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700789 return VOS_STATUS_E_FAULT;
790 }
791
792 if ( pList->cookie != VOS_LIST_COOKIE )
793 {
794 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700795 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700796 return VOS_STATUS_E_INVAL;
797 }
798
799 rc = mutex_lock_interruptible(&pList->lock);
800 if (rc)
801 {
802 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700803 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700804 return VOS_STATUS_E_FAULT;
805 }
806
807
808 if ( list_empty(&pList->anchor) )
809 {
810 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700811 "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700812 mutex_unlock(&pList->lock);
813 return VOS_STATUS_E_EMPTY;
814 }
815
816 // verify that pNode is indeed part of list pList
817 list_for_each(tmp, &pList->anchor)
818 {
819 if (tmp == pNode)
820 {
821 found = 1;
822 break;
823 }
824 }
825 if (found == 0)
826 return VOS_STATUS_E_INVAL;
827
828 list_add_tail(pNodeToInsert, pNode);
829 pList->count++;
830 mutex_unlock(&pList->lock);
831
832 return VOS_STATUS_SUCCESS;
833}
834
835/*----------------------------------------------------------------------------
836
837 \brief vos_list_remove_node() - remove specified node from vOS list list
838
839 The vos_list_remove_node() API will remove a specified node from the
840 properly initialized vOS List object.
841
842 \param pList - Pointer to list object where the node will be removed
843
844 \param ppNode - Pointer to the node to be removed from the list.
845
846 \return VOS_STATUS_SUCCESS - list node was successfully removed from
847 the list.
848
849 VOS_STATUS_E_INVAL - The value specified by pList is not a valid,
850 initialized list object.
851
852 VOS_STATUS_E_EMPTY - The specified is empty so nodes cannot be
853 removed.
854
855
856 VOS_STATUS_E_FAULT - pList or pNodeToRemove is not a valid pointer
857
858 \sa
859
860 --------------------------------------------------------------------------*/
861VOS_STATUS vos_list_remove_node( vos_list_t *pList, vos_list_node_t *pNodeToRemove )
862{
863 int rc, found = 0;
864 vos_list_node_t *tmp;
865
866 if ( ( pList == NULL ) || ( pNodeToRemove == NULL) )
867 {
868 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700869 "%s: NULL pointer passed in", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700870 return VOS_STATUS_E_FAULT;
871 }
872
873 if ( pList->cookie != VOS_LIST_COOKIE )
874 {
875 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700876 "%s: list not initialized", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700877 return VOS_STATUS_E_INVAL;
878 }
879
880 rc = mutex_lock_interruptible(&pList->lock);
881 if (rc)
882 {
883 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700884 "%s: unable to lock list", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700885 return VOS_STATUS_E_FAULT;
886 }
887
888 if ( list_empty(&pList->anchor) )
889 {
890 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700891 "%s: list empty", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700892 mutex_unlock(&pList->lock);
893 return VOS_STATUS_E_EMPTY;
894 }
895
896 // verify that pNodeToRemove is indeed part of list pList
897 list_for_each(tmp, &pList->anchor)
898 {
899 if (tmp == pNodeToRemove)
900 {
901 found = 1;
902 break;
903 }
904 }
905 if (found == 0)
906 return VOS_STATUS_E_INVAL;
907
908 list_del(pNodeToRemove);
909 pList->count--;
910 mutex_unlock(&pList->lock);
911
912 return VOS_STATUS_SUCCESS;
913}