2 * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38 * Defines standard return codes, keywords, macros, and debug levels.
42 #pragma warning(disable : 4996)
49 # define BEGIN_C_DECLS extern "C" {
50 # define END_C_DECLS }
51 #else /* !__cplusplus */
52 # define BEGIN_C_DECLS
54 #endif /* __cplusplus */
57 #include <complib/cl_types_osd.h>
59 typedef uint16_t net16_t;
60 typedef uint32_t net32_t;
61 typedef uint64_t net64_t;
71 /* explicit cast of void* to uint32_t */
72 #ifndef ASSERT_VOIDP2UINTN
74 #define ASSERT_VOIDP2UINTN(var) \
75 CL_ASSERT( (intptr_t)var <= 0xffffffffffffffffL )
76 #else /* __WORDSIZE == 64 */
78 /* need to cast carefully to avoid the warining of un-needed check */
79 #define ASSERT_VOIDP2UINTN(var) \
80 CL_ASSERT( (intptr_t)var <= 0x100000000ULL )
81 #else /* __WORDSIZE == 32 */
82 #error "Need to know WORDSIZE to tell how to cast to unsigned long int"
83 #endif /* __WORDSIZE == 32 */
84 #endif /* __WORDSIZE == 64 */
87 /* explicit casting of void* to long */
89 #define CAST_P2LONG(var) ((intptr_t)(var))
92 /****d* Component Library: Pointer Manipulation/offsetof
97 * The offsetof macro returns the offset of a member within a structure.
107 * [in] Name of the structure containing the specified member.
110 * [in] Name of the member whose offset in the specified structure
114 * Number of bytes from the beginning of the structure to the
121 #define offsetof(TYPE, MEMBER) ((uintn_t) &((TYPE *)0)->MEMBER)
124 /****d* Component Library: Pointer Manipulation/PARENT_STRUCT
129 * The PARENT_STRUCT macro returns a pointer to a structure
130 * given a name and pointer to one of its members.
135 * IN void* const p_member,
141 * [in] Pointer to the MEMBER_NAME member of a PARENT_TYPE structure.
144 * [in] Name of the structure containing the specified member.
147 * [in] Name of the member whose address is passed in the p_member
151 * Pointer to a structure of type PARENT_TYPE whose MEMBER_NAME member is
152 * located at p_member.
157 #define PARENT_STRUCT(p_member, PARENT_TYPE, MEMBER_NAME) \
158 ((PARENT_TYPE*)((uint8_t*)(p_member) - offsetof(PARENT_TYPE, MEMBER_NAME)))
160 /****d* Component Library/Parameter Keywords
165 * The Parameter Keywords can be used to clarify the usage of function
166 * parameters to users.
170 * Designates that the parameter is used as input to a function.
173 * Designates that the parameter's value will be set by the function.
176 * Designates that the parameter is optional, and may be NULL.
177 * The OPTIONAL keyword, if used, follows the parameter name.
180 * // Function declaration.
183 * IN void* const p_param1,
184 * OUT void** const p_handle OPTIONAL );
187 * Multiple keywords can apply to a single parameter. The IN and OUT
188 * keywords precede the parameter type. The OPTIONAL
189 * keyword, if used, follows the parameter name.
192 #define IN /* Function input parameter */
195 #define OUT /* Function output parameter */
198 #define OPTIONAL /* Optional function parameter - NULL if not used */
201 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 %% Function Returns And Completion Codes %%
204 %% The text for any addition to this enumerated type must be added to the %%
205 %% string array defined in <cl_statustext.c>. %%
207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
209 /****d* Component Library/Data Types
214 * The component library provides and uses explicitly sized types.
218 * 8-bit, defined by compiler.
221 * 0-bit, defined by compiler.
224 * 8-bit signed integer.
227 * 8-bit unsigned integer.
230 * 16-bit signed integer.
233 * 16-bit unsigned integer.
236 * 16-bit network byte order value.
239 * 32-bit signed integer.
242 * 32-bit unsigned integer.
245 * 32-bit network byte order value.
248 * 64-bit signed integer.
251 * 64-bit unsigned integer.
254 * 64-bit network byte order value.
257 * Signed natural sized integer. 32-bit on a 32-bit platform, 64-bit on
261 * Unsigned natural sized integer. 32-bit on a 32-bit platform, 64-bit on
265 * integral sized. Set to TRUE or FALSE and used in logical expressions.
268 * Pointer types are not defined as these provide no value and can potentially
269 * lead to naming confusion.
272 /****d* Component Library: Data Types/cl_status_t
277 * The cl_status_t return types are used by the component library to
278 * provide detailed function return values.
282 typedef enum _cl_status {
286 CL_INVALID_OPERATION,
288 CL_INVALID_PARAMETER,
289 CL_INSUFFICIENT_RESOURCES,
290 CL_INSUFFICIENT_MEMORY,
291 CL_INVALID_PERMISSION,
305 CL_STATUS_COUNT /* should be the last value */
309 * Data Types, CL_STATUS_MSG
312 /* Status values above converted to text for easier printing. */
313 extern const char *cl_status_text[];
316 /****f* Component Library: Error Trapping/cl_panic
321 * Halts execution of the current process. Halts the system if called in
326 void cl_panic(IN const char *const message, IN ...);
330 * [in] ANSI string formatted identically as for a call to the standard C
331 * function printf describing the cause for the panic.
334 * [in] Extra parameters for string formatting, as defined for the
335 * standard C function printf.
338 * This function does not return.
341 * The formatting of the message string is the same as for printf
343 * cl_panic sends the message to the current message logging target.
345 #endif /* cl_panic */
347 /****d* Component Library: Data Types/CL_STATUS_MSG
352 * The CL_STATUS_MSG macro returns a textual representation of
353 * an cl_status_t code.
358 * IN cl_status_t errcode );
362 * [in] cl_status_t code for which to return a text representation.
365 * Pointer to a string containing a textual representation of the errcode
369 * This function performs boundary checking on the cl_status_t value,
370 * masking off the upper 24-bits. If the value is out of bounds, the string
371 * "invalid status code" is returned.
376 #define CL_STATUS_MSG( errcode ) \
377 ((errcode < CL_STATUS_COUNT)?cl_status_text[errcode]:"invalid status code")
379 #if !defined( FALSE )
381 #endif /* !defined( FALSE ) */
384 #define TRUE (!FALSE)
385 #endif /* !defined( TRUE ) */
387 /****d* Component Library: Unreferenced Parameters/UNUSED_PARAM
392 * The UNUSED_PARAM macro can be used to eliminates compiler warnings related
393 * to intentionally unused formal parameters in function implementations.
399 * void my_func( int32_t value )
401 * UNUSED_PARAM( value );
405 /****d* Component Library/Object States
410 * The object states enumerated type defines the valid states of components.
414 typedef enum _cl_state {
415 CL_UNINITIALIZED = 1,
423 * Indicates that initialization was not invoked successfully.
426 * Indicates initialization was successful.
429 * Indicates that the object is undergoing destruction.
432 * Indicates that the object's destructor has already been called. Most
433 * objects set their final state to CL_DESTROYED before freeing the
434 * memory associated with the object.
437 /****d* Component Library: Object States/cl_is_state_valid
442 * The cl_is_state_valid function returns whether a state has a valid value.
446 static inline boolean_t cl_is_state_valid(IN const cl_state_t state)
448 return ((state == CL_UNINITIALIZED) || (state == CL_INITIALIZED) ||
449 (state == CL_DESTROYING) || (state == CL_DESTROYED));
455 * State whose value to validate.
458 * TRUE if the specified state has a valid value.
463 * This function is used in debug builds to check for valid states. If an
464 * uninitialized object is passed, the memory for the state may cause the
465 * state to have an invalid value.
472 #endif /* _DATA_TYPES_H_ */