1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff *
34219820Sjeff */
35219820Sjeff
36219820Sjeff/*
37219820Sjeff * Abstract:
38219820Sjeff *	Defines standard return codes, keywords, macros, and debug levels.
39219820Sjeff */
40219820Sjeff
41219820Sjeff#ifdef __WIN__
42219820Sjeff#pragma warning(disable : 4996)
43219820Sjeff#endif
44219820Sjeff
45219820Sjeff#ifndef _CL_TYPES_H_
46219820Sjeff#define _CL_TYPES_H_
47219820Sjeff
48219820Sjeff#ifdef __cplusplus
49219820Sjeff#  define BEGIN_C_DECLS extern "C" {
50219820Sjeff#  define END_C_DECLS   }
51219820Sjeff#else				/* !__cplusplus */
52219820Sjeff#  define BEGIN_C_DECLS
53219820Sjeff#  define END_C_DECLS
54219820Sjeff#endif				/* __cplusplus */
55219820Sjeff
56219820SjeffBEGIN_C_DECLS
57219820Sjeff#include <complib/cl_types_osd.h>
58219820Sjeff#include <stddef.h>
59219820Sjefftypedef uint16_t net16_t;
60219820Sjefftypedef uint32_t net32_t;
61219820Sjefftypedef uint64_t net64_t;
62219820Sjeff
63219820Sjeff#ifndef __WORDSIZE
64219820Sjeff#ifdef	__LP64__
65219820Sjeff#define	__WORDSIZE	64
66219820Sjeff#else
67219820Sjeff#define	__WORDSIZE	32
68219820Sjeff#endif
69219820Sjeff#endif
70219820Sjeff
71219820Sjeff/* explicit cast of void* to uint32_t */
72219820Sjeff#ifndef ASSERT_VOIDP2UINTN
73219820Sjeff#if __WORDSIZE == 64
74219820Sjeff#define ASSERT_VOIDP2UINTN(var) \
75219820Sjeff	CL_ASSERT( (intptr_t)var <= 0xffffffffffffffffL )
76219820Sjeff#else				/*  __WORDSIZE == 64 */
77219820Sjeff#if __WORDSIZE == 32
78219820Sjeff  /* need to cast carefully to avoid the warining of un-needed check */
79219820Sjeff#define ASSERT_VOIDP2UINTN(var) \
80219820Sjeff	CL_ASSERT( (intptr_t)var <= 0x100000000ULL )
81219820Sjeff#else				/*  __WORDSIZE == 32 */
82219820Sjeff#error "Need to know WORDSIZE to tell how to cast to unsigned long int"
83219820Sjeff#endif				/*  __WORDSIZE == 32 */
84219820Sjeff#endif				/*  __WORDSIZE == 64 */
85219820Sjeff#endif
86219820Sjeff
87219820Sjeff/* explicit casting of void* to long */
88219820Sjeff#ifndef CAST_P2LONG
89219820Sjeff#define CAST_P2LONG(var) ((intptr_t)(var))
90219820Sjeff#endif
91219820Sjeff
92219820Sjeff/****d* Component Library: Pointer Manipulation/offsetof
93219820Sjeff* NAME
94219820Sjeff*	offsetof
95219820Sjeff*
96219820Sjeff* DESCRIPTION
97219820Sjeff*	The offsetof macro returns the offset of a member within a structure.
98219820Sjeff*
99219820Sjeff* SYNOPSIS
100219820Sjeff*	uintn_t
101219820Sjeff*	offsetof(
102219820Sjeff*		IN TYPE,
103219820Sjeff*		IN MEMBER );
104219820Sjeff*
105219820Sjeff* PARAMETERS
106219820Sjeff*	TYPE
107219820Sjeff*		[in] Name of the structure containing the specified member.
108219820Sjeff*
109219820Sjeff*	MEMBER
110219820Sjeff*		[in] Name of the member whose offset in the specified structure
111219820Sjeff*		is to be returned.
112219820Sjeff*
113219820Sjeff* RETURN VALUE
114219820Sjeff*	Number of bytes from the beginning of the structure to the
115219820Sjeff*	specified member.
116219820Sjeff*
117219820Sjeff* SEE ALSO
118219820Sjeff*	PARENT_STRUCT
119219820Sjeff*********/
120219820Sjeff#ifndef offsetof
121219820Sjeff#define offsetof(TYPE, MEMBER) ((uintn_t) &((TYPE *)0)->MEMBER)
122219820Sjeff#endif
123219820Sjeff
124219820Sjeff/****d* Component Library: Pointer Manipulation/PARENT_STRUCT
125219820Sjeff* NAME
126219820Sjeff*	PARENT_STRUCT
127219820Sjeff*
128219820Sjeff* DESCRIPTION
129219820Sjeff*	The PARENT_STRUCT macro returns a pointer to a structure
130219820Sjeff*	given a name and pointer to one of its members.
131219820Sjeff*
132219820Sjeff* SYNOPSIS
133219820Sjeff*	PARENT_TYPE*
134219820Sjeff*	PARENT_STRUCT(
135219820Sjeff*		IN void* const p_member,
136219820Sjeff*		IN PARENT_TYPE,
137219820Sjeff*		IN MEMBER_NAME );
138219820Sjeff*
139219820Sjeff* PARAMETERS
140219820Sjeff*	p_member
141219820Sjeff*		[in] Pointer to the MEMBER_NAME member of a PARENT_TYPE structure.
142219820Sjeff*
143219820Sjeff*	PARENT_TYPE
144219820Sjeff*		[in] Name of the structure containing the specified member.
145219820Sjeff*
146219820Sjeff*	MEMBER_NAME
147219820Sjeff*		[in] Name of the member whose address is passed in the p_member
148219820Sjeff*		parameter.
149219820Sjeff*
150219820Sjeff* RETURN VALUE
151219820Sjeff*	Pointer to a structure of type PARENT_TYPE whose MEMBER_NAME member is
152219820Sjeff*	located at p_member.
153219820Sjeff*
154219820Sjeff* SEE ALSO
155219820Sjeff*	offsetof
156219820Sjeff*********/
157219820Sjeff#define PARENT_STRUCT(p_member, PARENT_TYPE, MEMBER_NAME) \
158219820Sjeff	((PARENT_TYPE*)((uint8_t*)(p_member) - offsetof(PARENT_TYPE, MEMBER_NAME)))
159219820Sjeff
160219820Sjeff/****d* Component Library/Parameter Keywords
161219820Sjeff* NAME
162219820Sjeff*	Parameter Keywords
163219820Sjeff*
164219820Sjeff* DESCRIPTION
165219820Sjeff*	The Parameter Keywords can be used to clarify the usage of function
166219820Sjeff*	parameters to users.
167219820Sjeff*
168219820Sjeff* VALUES
169219820Sjeff*	IN
170219820Sjeff*		Designates that the parameter is used as input to a function.
171219820Sjeff*
172219820Sjeff*	OUT
173219820Sjeff*		Designates that the parameter's value will be set by the function.
174219820Sjeff*
175219820Sjeff*	OPTIONAL
176219820Sjeff*		Designates that the parameter is optional, and may be NULL.
177219820Sjeff*		The OPTIONAL keyword, if used, follows the parameter name.
178219820Sjeff*
179219820Sjeff* EXAMPLE
180219820Sjeff*	// Function declaration.
181219820Sjeff*	void*
182219820Sjeff*	my_func(
183219820Sjeff*	    IN void* const p_param1,
184219820Sjeff*	    OUT void** const p_handle OPTIONAL );
185219820Sjeff*
186219820Sjeff* NOTES
187219820Sjeff*	Multiple keywords can apply to a single parameter. The IN and OUT
188219820Sjeff*	keywords precede the parameter type. The OPTIONAL
189219820Sjeff*	keyword, if used, follows the parameter name.
190219820Sjeff*********/
191219820Sjeff#ifndef		IN
192219820Sjeff#define		IN		/* Function input parameter */
193219820Sjeff#endif
194219820Sjeff#ifndef		OUT
195219820Sjeff#define		OUT		/* Function output parameter */
196219820Sjeff#endif
197219820Sjeff#ifndef		OPTIONAL
198219820Sjeff#define		OPTIONAL	/* Optional function parameter - NULL if not used */
199219820Sjeff#endif
200219820Sjeff
201219820Sjeff/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202219820Sjeff%%                  Function Returns And Completion Codes					 %%
203219820Sjeff%%																			 %%
204219820Sjeff%% The text for any addition to this enumerated type must be added to the	 %%
205219820Sjeff%% string array defined in <cl_statustext.c>.								 %%
206219820Sjeff%%																			 %%
207219820Sjeff%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
208219820Sjeff
209219820Sjeff/****d* Component Library/Data Types
210219820Sjeff* NAME
211219820Sjeff*	Data Types
212219820Sjeff*
213219820Sjeff* DESCRIPTION
214219820Sjeff*	The component library provides and uses explicitly sized types.
215219820Sjeff*
216219820Sjeff* VALUES
217219820Sjeff*	char
218219820Sjeff*		8-bit, defined by compiler.
219219820Sjeff*
220219820Sjeff*	void
221219820Sjeff*		0-bit, defined by compiler.
222219820Sjeff*
223219820Sjeff*	int8_t
224219820Sjeff*		8-bit signed integer.
225219820Sjeff*
226219820Sjeff*	uint8_t
227219820Sjeff*		8-bit unsigned integer.
228219820Sjeff*
229219820Sjeff*	int16_t
230219820Sjeff*		16-bit signed integer.
231219820Sjeff*
232219820Sjeff*	uint16_t
233219820Sjeff*		16-bit unsigned integer.
234219820Sjeff*
235219820Sjeff*	net16_t
236219820Sjeff*		16-bit network byte order value.
237219820Sjeff*
238219820Sjeff*	int32_t
239219820Sjeff*		32-bit signed integer.
240219820Sjeff*
241219820Sjeff*	uint32_t
242219820Sjeff*		32-bit unsigned integer.
243219820Sjeff*
244219820Sjeff*	net32_t
245219820Sjeff*		32-bit network byte order value.
246219820Sjeff*
247219820Sjeff*	int64_t
248219820Sjeff*		64-bit signed integer.
249219820Sjeff*
250219820Sjeff*	uint64_t
251219820Sjeff*		64-bit unsigned integer.
252219820Sjeff*
253219820Sjeff*	net64_t
254219820Sjeff*		64-bit network byte order value.
255219820Sjeff*
256219820Sjeff*	intn_t
257219820Sjeff*		Signed natural sized integer.  32-bit on a 32-bit platform, 64-bit on
258219820Sjeff*		a 64-bit platform.
259219820Sjeff*
260219820Sjeff*	uintn_t
261219820Sjeff*		Unsigned natural sized integer.  32-bit on a 32-bit platform, 64-bit on
262219820Sjeff*		a 64-bit platform.
263219820Sjeff*
264219820Sjeff*	boolean_t
265219820Sjeff*		integral sized.  Set to TRUE or FALSE and used in logical expressions.
266219820Sjeff*
267219820Sjeff* NOTES
268219820Sjeff*	Pointer types are not defined as these provide no value and can potentially
269219820Sjeff*	lead to naming confusion.
270219820Sjeff*********/
271219820Sjeff
272219820Sjeff/****d* Component Library: Data Types/cl_status_t
273219820Sjeff* NAME
274219820Sjeff*	cl_status_t
275219820Sjeff*
276219820Sjeff* DESCRIPTION
277219820Sjeff*	The cl_status_t return types are used by the component library to
278219820Sjeff*	provide detailed function return values.
279219820Sjeff*
280219820Sjeff* SYNOPSIS
281219820Sjeff*/
282219820Sjefftypedef enum _cl_status {
283219820Sjeff	CL_SUCCESS = 0,
284219820Sjeff	CL_ERROR,
285219820Sjeff	CL_INVALID_STATE,
286219820Sjeff	CL_INVALID_OPERATION,
287219820Sjeff	CL_INVALID_SETTING,
288219820Sjeff	CL_INVALID_PARAMETER,
289219820Sjeff	CL_INSUFFICIENT_RESOURCES,
290219820Sjeff	CL_INSUFFICIENT_MEMORY,
291219820Sjeff	CL_INVALID_PERMISSION,
292219820Sjeff	CL_COMPLETED,
293219820Sjeff	CL_NOT_DONE,
294219820Sjeff	CL_PENDING,
295219820Sjeff	CL_TIMEOUT,
296219820Sjeff	CL_CANCELED,
297219820Sjeff	CL_REJECT,
298219820Sjeff	CL_OVERRUN,
299219820Sjeff	CL_NOT_FOUND,
300219820Sjeff	CL_UNAVAILABLE,
301219820Sjeff	CL_BUSY,
302219820Sjeff	CL_DISCONNECT,
303219820Sjeff	CL_DUPLICATE,
304219820Sjeff
305219820Sjeff	CL_STATUS_COUNT		/* should be the last value */
306219820Sjeff} cl_status_t;
307219820Sjeff/*
308219820Sjeff* SEE ALSO
309219820Sjeff*	Data Types, CL_STATUS_MSG
310219820Sjeff*********/
311219820Sjeff
312219820Sjeff/* Status values above converted to text for easier printing. */
313219820Sjeffextern const char *cl_status_text[];
314219820Sjeff
315219820Sjeff#ifndef cl_panic
316219820Sjeff/****f* Component Library: Error Trapping/cl_panic
317219820Sjeff* NAME
318219820Sjeff*	cl_panic
319219820Sjeff*
320219820Sjeff* DESCRIPTION
321219820Sjeff*	Halts execution of the current process.  Halts the system if called in
322219820Sjeff*	from the kernel.
323219820Sjeff*
324219820Sjeff* SYNOPSIS
325219820Sjeff*/
326219820Sjeffvoid cl_panic(IN const char *const message, IN ...);
327219820Sjeff/*
328219820Sjeff* PARAMETERS
329219820Sjeff*	message
330219820Sjeff*		[in] ANSI string formatted identically as for a call to the standard C
331219820Sjeff*		function printf describing the cause for the panic.
332219820Sjeff*
333219820Sjeff*	...
334219820Sjeff*		[in] Extra parameters for string formatting, as defined for the
335219820Sjeff*		standard C function printf.
336219820Sjeff*
337219820Sjeff* RETURN VALUE
338219820Sjeff*	This function does not return.
339219820Sjeff*
340219820Sjeff* NOTES
341219820Sjeff*	The formatting of the message string is the same as for printf
342219820Sjeff*
343219820Sjeff*	cl_panic sends the message to the current message logging target.
344219820Sjeff*********/
345219820Sjeff#endif				/* cl_panic */
346219820Sjeff
347219820Sjeff/****d* Component Library: Data Types/CL_STATUS_MSG
348219820Sjeff* NAME
349219820Sjeff*	CL_STATUS_MSG
350219820Sjeff*
351219820Sjeff* DESCRIPTION
352219820Sjeff*	The CL_STATUS_MSG macro returns a textual representation of
353219820Sjeff*	an cl_status_t code.
354219820Sjeff*
355219820Sjeff* SYNOPSIS
356219820Sjeff*	const char*
357219820Sjeff*	CL_STATUS_MSG(
358219820Sjeff*		IN cl_status_t errcode );
359219820Sjeff*
360219820Sjeff* PARAMETERS
361219820Sjeff*	errcode
362219820Sjeff*		[in] cl_status_t code for which to return a text representation.
363219820Sjeff*
364219820Sjeff* RETURN VALUE
365219820Sjeff*	Pointer to a string containing a textual representation of the errcode
366219820Sjeff*	parameter.
367219820Sjeff*
368219820Sjeff* NOTES
369219820Sjeff*	This function performs boundary checking on the cl_status_t value,
370219820Sjeff*	masking off the upper 24-bits. If the value is out of bounds, the string
371219820Sjeff*	"invalid status code" is returned.
372219820Sjeff*
373219820Sjeff* SEE ALSO
374219820Sjeff*	cl_status_t
375219820Sjeff*********/
376219820Sjeff#define CL_STATUS_MSG( errcode ) \
377219820Sjeff	((errcode < CL_STATUS_COUNT)?cl_status_text[errcode]:"invalid status code")
378219820Sjeff
379219820Sjeff#if !defined( FALSE )
380219820Sjeff#define FALSE	0
381219820Sjeff#endif				/* !defined( FALSE ) */
382219820Sjeff
383219820Sjeff#if !defined( TRUE )
384219820Sjeff#define TRUE	(!FALSE)
385219820Sjeff#endif				/* !defined( TRUE ) */
386219820Sjeff
387219820Sjeff/****d* Component Library: Unreferenced Parameters/UNUSED_PARAM
388219820Sjeff* NAME
389219820Sjeff*	UNUSED_PARAM
390219820Sjeff*
391219820Sjeff* DESCRIPTION
392219820Sjeff*	The UNUSED_PARAM macro can be used to eliminates compiler warnings related
393219820Sjeff*	to intentionally unused formal parameters in function implementations.
394219820Sjeff*
395219820Sjeff* SYNOPSIS
396219820Sjeff*	UNUSED_PARAM( P )
397219820Sjeff*
398219820Sjeff* EXAMPLE
399219820Sjeff*	void my_func( int32_t value )
400219820Sjeff*	{
401219820Sjeff*		UNUSED_PARAM( value );
402219820Sjeff*	}
403219820Sjeff*********/
404219820Sjeff
405219820Sjeff/****d* Component Library/Object States
406219820Sjeff* NAME
407219820Sjeff*	Object States
408219820Sjeff*
409219820Sjeff* DESCRIPTION
410219820Sjeff*	The object states enumerated type defines the valid states of components.
411219820Sjeff*
412219820Sjeff* SYNOPSIS
413219820Sjeff*/
414219820Sjefftypedef enum _cl_state {
415219820Sjeff	CL_UNINITIALIZED = 1,
416219820Sjeff	CL_INITIALIZED,
417219820Sjeff	CL_DESTROYING,
418219820Sjeff	CL_DESTROYED
419219820Sjeff} cl_state_t;
420219820Sjeff/*
421219820Sjeff* VALUES
422219820Sjeff*	CL_UNINITIALIZED
423219820Sjeff*		Indicates that initialization was not invoked successfully.
424219820Sjeff*
425219820Sjeff*	CL_INITIALIZED
426219820Sjeff*		Indicates initialization was successful.
427219820Sjeff*
428219820Sjeff*	CL_DESTROYING
429219820Sjeff*		Indicates that the object is undergoing destruction.
430219820Sjeff*
431219820Sjeff*	CL_DESTROYED
432219820Sjeff*		Indicates that the object's destructor has already been called.  Most
433219820Sjeff*		objects set their final state to CL_DESTROYED before freeing the
434219820Sjeff*		memory associated with the object.
435219820Sjeff*********/
436219820Sjeff
437219820Sjeff/****d* Component Library: Object States/cl_is_state_valid
438219820Sjeff* NAME
439219820Sjeff*	cl_is_state_valid
440219820Sjeff*
441219820Sjeff* DESCRIPTION
442219820Sjeff*	The cl_is_state_valid function returns whether a state has a valid value.
443219820Sjeff*
444219820Sjeff* SYNOPSIS
445219820Sjeff*/
446219820Sjeffstatic inline boolean_t cl_is_state_valid(IN const cl_state_t state)
447219820Sjeff{
448219820Sjeff	return ((state == CL_UNINITIALIZED) || (state == CL_INITIALIZED) ||
449219820Sjeff		(state == CL_DESTROYING) || (state == CL_DESTROYED));
450219820Sjeff}
451219820Sjeff
452219820Sjeff/*
453219820Sjeff* PARAMETERS
454219820Sjeff*	state
455219820Sjeff*		State whose value to validate.
456219820Sjeff*
457219820Sjeff* RETURN VALUES
458219820Sjeff*	TRUE if the specified state has a valid value.
459219820Sjeff*
460219820Sjeff*	FALSE otherwise.
461219820Sjeff*
462219820Sjeff* NOTES
463219820Sjeff*	This function is used in debug builds to check for valid states.  If an
464219820Sjeff*	uninitialized object is passed, the memory for the state may cause the
465219820Sjeff*	state to have an invalid value.
466219820Sjeff*
467219820Sjeff* SEE ALSO
468219820Sjeff*	Object States
469219820Sjeff*********/
470219820Sjeff
471219820SjeffEND_C_DECLS
472219820Sjeff#endif				/* _DATA_TYPES_H_ */
473