isci: merge smp request substates into primary state machine
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / isci / pool.h
blob016ec832f74f7d8c651032da8c72c9f6537bb3c3
1 /*
2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
5 * GPL LICENSE SUMMARY
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
24 * BSD LICENSE
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
38 * distribution.
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 /**
57 * This file contains the interface to the pool class. This class allows two
58 * different two different priority tasks to insert and remove items from
59 * the free pool. The user of the pool is expected to evaluate the pool
60 * condition empty before a get operation and pool condition full before a
61 * put operation. Methods Provided: - sci_pool_create() -
62 * sci_pool_initialize() - sci_pool_empty() - sci_pool_full() -
63 * sci_pool_get() - sci_pool_put()
68 #ifndef _SCI_POOL_H_
69 #define _SCI_POOL_H_
71 /**
72 * SCI_POOL_INCREMENT() -
74 * Private operation for the pool
76 #define SCI_POOL_INCREMENT(pool, index) \
77 (((index) + 1) == (pool).size ? 0 : (index) + 1)
79 /**
80 * SCI_POOL_CREATE() -
82 * This creates a pool structure of pool_name. The members in the pool are of
83 * type with number of elements equal to size.
85 #define SCI_POOL_CREATE(pool_name, type, pool_size) \
86 struct \
87 { \
88 u32 size; \
89 u32 get; \
90 u32 put; \
91 type array[(pool_size) + 1]; \
92 } pool_name
95 /**
96 * sci_pool_empty() -
98 * This macro evaluates the pool and returns true if the pool is empty. If the
99 * pool is empty the user should not perform any get operation on the pool.
101 #define sci_pool_empty(pool) \
102 ((pool).get == (pool).put)
105 * sci_pool_full() -
107 * This macro evaluates the pool and returns true if the pool is full. If the
108 * pool is full the user should not perform any put operation.
110 #define sci_pool_full(pool) \
111 (SCI_POOL_INCREMENT(pool, (pool).put) == (pool).get)
114 * sci_pool_size() -
116 * This macro returns the size of the pool created. The internal size of the
117 * pool is actually 1 larger then necessary in order to ensure get and put
118 * pointers can be written simultaneously by different users. As a result,
119 * this macro subtracts 1 from the internal size
121 #define sci_pool_size(pool) \
122 ((pool).size - 1)
125 * sci_pool_count() -
127 * This macro indicates the number of elements currently contained in the pool.
129 #define sci_pool_count(pool) \
131 sci_pool_empty((pool)) \
132 ? 0 \
133 : (\
134 sci_pool_full((pool)) \
135 ? sci_pool_size((pool)) \
136 : (\
137 (pool).get > (pool).put \
138 ? ((pool).size - (pool).get + (pool).put) \
139 : ((pool).put - (pool).get) \
145 * sci_pool_initialize() -
147 * This macro initializes the pool to an empty condition.
149 #define sci_pool_initialize(pool) \
151 (pool).size = (sizeof((pool).array) / sizeof((pool).array[0])); \
152 (pool).get = 0; \
153 (pool).put = 0; \
157 * sci_pool_get() -
159 * This macro will get the next free element from the pool. This should only be
160 * called if the pool is not empty.
162 #define sci_pool_get(pool, my_value) \
164 (my_value) = (pool).array[(pool).get]; \
165 (pool).get = SCI_POOL_INCREMENT((pool), (pool).get); \
169 * sci_pool_put() -
171 * This macro will put the value into the pool. This should only be called if
172 * the pool is not full.
174 #define sci_pool_put(pool, value) \
176 (pool).array[(pool).put] = (value); \
177 (pool).put = SCI_POOL_INCREMENT((pool), (pool).put); \
181 * sci_pool_erase() -
183 * This macro will search the pool and remove any elements in the pool matching
184 * the supplied value. This method can only be utilized on pools
186 #define sci_pool_erase(pool, type, value) \
188 type tmp_value; \
189 u32 index; \
190 u32 element_count = sci_pool_count((pool)); \
192 for (index = 0; index < element_count; index++) { \
193 sci_pool_get((pool), tmp_value); \
194 if (tmp_value != (value)) \
195 sci_pool_put((pool), tmp_value); \
199 #endif /* _SCI_POOL_H_ */