1 /* 2 * mr_sas_list.h: header for mr_sas 3 * 4 * Solaris MegaRAID driver for SAS2.0 controllers 5 * Copyright (c) 2008-2012, LSI Logic Corporation. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright notice, 15 * this list of conditions and the following disclaimer in the documentation 16 * and/or other materials provided with the distribution. 17 * 18 * 3. Neither the name of the author nor the names of its contributors may be 19 * used to endorse or promote products derived from this software without 20 * specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 33 * DAMAGE. 34 */ 35 36 #ifndef _MR_SAS_LIST_H_ 37 #define _MR_SAS_LIST_H_ 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /* 44 * Simple doubly linked list implementation. 45 * 46 * Some of the internal functions ("__xxx") are useful when 47 * manipulating whole lists rather than single entries, as 48 * sometimes we already know the next/prev entries and we can 49 * generate better code by using them directly rather than 50 * using the generic single-entry routines. 51 */ 52 53 struct mlist_head { 54 struct mlist_head *next, *prev; 55 }; 56 57 typedef struct mlist_head mlist_t; 58 59 #define LIST_HEAD_INIT(name) { &(name), &(name) } 60 61 #define LIST_HEAD(name) \ 62 struct mlist_head name = LIST_HEAD_INIT(name) 63 64 #define INIT_LIST_HEAD(ptr) { \ 65 (ptr)->next = (ptr); (ptr)->prev = (ptr); \ 66 } 67 68 69 void mlist_add(struct mlist_head *, struct mlist_head *); 70 void mlist_add_tail(struct mlist_head *, struct mlist_head *); 71 void mlist_del_init(struct mlist_head *); 72 int mlist_empty(struct mlist_head *); 73 void mlist_splice(struct mlist_head *, struct mlist_head *); 74 75 /* 76 * mlist_entry - get the struct for this entry 77 * @ptr: the &struct mlist_head pointer. 78 * @type: the type of the struct this is embedded in. 79 * @member: the name of the list_struct within the struct. 80 */ 81 #define mlist_entry(ptr, type, member) \ 82 ((type *)((size_t)(ptr) - offsetof(type, member))) 83 84 85 /* 86 * mlist_for_each - iterate over a list 87 * @pos: the &struct mlist_head to use as a loop counter. 88 * @head: the head for your list. 89 */ 90 #define mlist_for_each(pos, head) \ 91 for (pos = (head)->next, prefetch(pos->next); pos != (head); \ 92 pos = pos->next, prefetch(pos->next)) 93 94 95 /* 96 * mlist_for_each_safe - iterate over a list safe against removal of list entry 97 * @pos: the &struct mlist_head to use as a loop counter. 98 * @n: another &struct mlist_head to use as temporary storage 99 * @head: the head for your list. 100 */ 101 #define mlist_for_each_safe(pos, n, head) \ 102 for (pos = (head)->next, n = pos->next; pos != (head); \ 103 pos = n, n = pos->next) 104 105 #ifdef __cplusplus 106 } 107 #endif 108 109 #endif /* _MR_SAS_LIST_H_ */ 110