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