1 /****************************************************************************
2 * Copyright 2002-2005: Level 5 Networks Inc.
3 * Copyright 2005-2008: Solarflare Communications Inc,
4 * 9501 Jeronimo Road, Suite 250,
5 * Irvine, CA 92618, USA
7 * Maintained by Solarflare Communications
8 * <linux-xen-drivers@solarflare.com>
9 * <onload-dev@solarflare.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published
13 * by the Free Software Foundation, incorporated herein by reference.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 ****************************************************************************
28 * \brief Really-and-truely-honestly internal stuff for libef.
32 /*! \cidoxg_include_ci_ul */
33 #ifndef __CI_EF_VI_INTERNAL_H__
34 #define __CI_EF_VI_INTERNAL_H__
37 /* These flags share space with enum ef_vi_flags. */
38 #define EF_VI_BUG5692_WORKAROUND 0x10000
41 /* ***********************************************************************
42 * COMPILATION CONTROL FLAGS (see ef_vi.h for "workaround" controls)
45 #define EF_VI_DO_MAGIC_CHECKS 1
48 /**********************************************************************
52 #include <etherfabric/ef_vi.h>
54 #include "ef_vi_falcon.h"
57 /**********************************************************************
63 # define _ef_assert(exp, file, line) BUG_ON(!(exp));
65 # define _ef_assert2(exp, x, y, file, line) do { \
66 if (unlikely(!(exp))) \
72 # define _ef_assert(exp, file, line)
73 # define _ef_assert2(e, x, y, file, line)
77 #define ef_assert(a) do{ _ef_assert((a),__FILE__,__LINE__); } while(0)
78 #define ef_assert_equal(a,b) _ef_assert2((a)==(b),(a),(b),__FILE__,__LINE__)
79 #define ef_assert_eq ef_assert_equal
80 #define ef_assert_lt(a,b) _ef_assert2((a)<(b),(a),(b),__FILE__,__LINE__)
81 #define ef_assert_le(a,b) _ef_assert2((a)<=(b),(a),(b),__FILE__,__LINE__)
82 #define ef_assert_nequal(a,b) _ef_assert2((a)!=(b),(a),(b),__FILE__,__LINE__)
83 #define ef_assert_ne ef_assert_nequal
84 #define ef_assert_ge(a,b) _ef_assert2((a)>=(b),(a),(b),__FILE__,__LINE__)
85 #define ef_assert_gt(a,b) _ef_assert2((a)>(b),(a),(b),__FILE__,__LINE__)
87 /**********************************************************************
88 * Debug checks. ******************************************************
89 **********************************************************************/
92 # define EF_VI_MAGIC_SET(p, type)
93 # define EF_VI_CHECK_VI(p)
94 # define EF_VI_CHECK_EVENT_Q(p)
95 # define EF_VI_CHECK_IOBUFSET(p)
96 # define EF_VI_CHECK_FILTER(p)
97 # define EF_VI_CHECK_SHMBUF(p)
98 # define EF_VI_CHECK_PT_EP(p)
101 # define EF_EPLOCK 0x6
102 # define EF_IOBUFSET 0x9
103 # define EF_FILTER 0xa
104 # define EF_SHMBUF 0x11
106 # define EF_VI_MAGIC(p, type) \
107 (((unsigned)(type) << 28) | \
108 (((unsigned)(intptr_t)(p)) & 0x0fffffffu))
110 # if !EF_VI_DO_MAGIC_CHECKS
111 # define EF_VI_MAGIC_SET(p, type)
112 # define EF_VI_MAGIC_CHECK(p, type)
114 # define EF_VI_MAGIC_SET(p, type) \
116 (p)->magic = EF_VI_MAGIC((p), (type)); \
119 # define EF_VI_MAGIC_OKAY(p, type) \
120 ((p)->magic == EF_VI_MAGIC((p), (type)))
122 # define EF_VI_MAGIC_CHECK(p, type) \
123 ef_assert(EF_VI_MAGIC_OKAY((p), (type)))
125 #endif /* EF_VI_DO_MAGIC_CHECKS */
127 # define EF_VI_CHECK_VI(p) \
129 EF_VI_MAGIC_CHECK((p), EF_VI);
131 # define EF_VI_CHECK_EVENT_Q(p) \
133 EF_VI_MAGIC_CHECK((p), EF_VI); \
134 ef_assert((p)->evq_base); \
135 ef_assert((p)->evq_mask);
137 # define EF_VI_CHECK_PT_EP(p) \
139 EF_VI_MAGIC_CHECK((p), EF_VI); \
140 ef_assert((p)->ep_state);
142 # define EF_VI_CHECK_IOBUFSET(p) \
144 EF_VI_MAGIC_CHECK((p), EF_IOBUFSET)
146 # define EF_VI_CHECK_FILTER(p) \
148 EF_VI_MAGIC_CHECK((p), EF_FILTER);
150 # define EF_VI_CHECK_SHMBUF(p) \
152 EF_VI_MAGIC_CHECK((p), EF_SHMBUF);
157 # define EF_DRIVER_MAGIC 0x00f00ba4
158 # define EF_ASSERT_THIS_DRIVER_VALID(driver) \
159 do{ ef_assert(driver); \
160 EF_VI_MAGIC_CHECK((driver), EF_DRIVER_MAGIC); \
161 ef_assert((driver)->init); }while(0)
163 # define EF_ASSERT_DRIVER_VALID() EF_ASSERT_THIS_DRIVER_VALID(&ci_driver)
165 # define EF_ASSERT_THIS_DRIVER_VALID(driver)
166 # define EF_ASSERT_DRIVER_VALID()
170 /* *************************************
174 #define EF_VI_FIFO2_M(f, x) ((x) & ((f)->fifo_mask))
175 #define ef_vi_fifo2_valid(f) ((f) && (f)->fifo && (f)->fifo_mask > 0 && \
176 (f)->fifo_rd_i <= (f)->fifo_mask && \
177 (f)->fifo_wr_i <= (f)->fifo_mask && \
178 EF_VI_IS_POW2((f)->fifo_mask+1u))
180 #define ef_vi_fifo2_init(f, cap) \
181 do{ ef_assert(EF_VI_IS_POW2((cap) + 1)); \
182 (f)->fifo_rd_i = (f)->fifo_wr_i = 0u; \
183 (f)->fifo_mask = (cap); \
186 #define ef_vi_fifo2_is_empty(f) ((f)->fifo_rd_i == (f)->fifo_wr_i)
187 #define ef_vi_fifo2_capacity(f) ((f)->fifo_mask)
188 #define ef_vi_fifo2_buf_size(f) ((f)->fifo_mask + 1u)
189 #define ef_vi_fifo2_end(f) ((f)->fifo + ef_vi_fifo2_buf_size(f))
190 #define ef_vi_fifo2_peek(f) ((f)->fifo[(f)->fifo_rd_i])
191 #define ef_vi_fifo2_poke(f) ((f)->fifo[(f)->fifo_wr_i])
192 #define ef_vi_fifo2_num(f) EF_VI_FIFO2_M((f),(f)->fifo_wr_i-(f)->fifo_rd_i)
194 #define ef_vi_fifo2_wr_prev(f) \
195 do{ (f)->fifo_wr_i = EF_VI_FIFO2_M((f), (f)->fifo_wr_i - 1u); }while(0)
196 #define ef_vi_fifo2_wr_next(f) \
197 do{ (f)->fifo_wr_i = EF_VI_FIFO2_M((f), (f)->fifo_wr_i + 1u); }while(0)
198 #define ef_vi_fifo2_rd_adv(f, n) \
199 do{ (f)->fifo_rd_i = EF_VI_FIFO2_M((f), (f)->fifo_rd_i + (n)); }while(0)
200 #define ef_vi_fifo2_rd_prev(f) \
201 do{ (f)->fifo_rd_i = EF_VI_FIFO2_M((f), (f)->fifo_rd_i - 1u); }while(0)
202 #define ef_vi_fifo2_rd_next(f) \
203 do{ (f)->fifo_rd_i = EF_VI_FIFO2_M((f), (f)->fifo_rd_i + 1u); }while(0)
205 #define ef_vi_fifo2_put(f, v) \
206 do{ ef_vi_fifo2_poke(f) = (v); ef_vi_fifo2_wr_next(f); }while(0)
207 #define ef_vi_fifo2_get(f, pv) \
208 do{ *(pv) = ef_vi_fifo2_peek(f); ef_vi_fifo2_rd_next(f); }while(0)
211 /* *********************************************************************
224 #define EF_VI_EVENT_OFFSET(q, i) \
225 (((q)->evq_state->evq_ptr - (i) * sizeof(ef_vi_event)) & (q)->evq_mask)
227 #define EF_VI_EVENT_PTR(q, i) \
228 ((ef_vi_event*) ((q)->evq_base + EF_VI_EVENT_OFFSET((q), (i))))
230 /* *********************************************************************
231 * Miscellaneous goodies
234 # define EF_VI_DEBUG(x)
236 # define EF_VI_DEBUG(x) x
239 #define EF_VI_ROUND_UP(i, align) (((i)+(align)-1u) & ~((align)-1u))
240 #define EF_VI_ALIGN_FWD(p, align) (((p)+(align)-1u) & ~((align)-1u))
241 #define EF_VI_ALIGN_BACK(p, align) ((p) & ~((align)-1u))
242 #define EF_VI_PTR_ALIGN_BACK(p, align) \
243 ((char*)EF_VI_ALIGN_BACK(((intptr_t)(p)), ((intptr_t)(align))))
244 #define EF_VI_IS_POW2(x) ((x) && ! ((x) & ((x) - 1)))
247 /* ********************************************************************
250 extern void falcon_vi_init(ef_vi*, void* vvis ) EF_VI_HF;
251 extern void ef_eventq_state_init(ef_vi* evq) EF_VI_HF;
252 extern void __ef_init(void) EF_VI_HF;
255 #endif /* __CI_EF_VI_INTERNAL_H__ */