1321936Shselasky/* 2321936Shselasky * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved. 3321936Shselasky * Copyright (c) 2002-2010 Mellanox Technologies LTD. All rights reserved. 4321936Shselasky * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. 5321936Shselasky * 6321936Shselasky * This software is available to you under a choice of one of two 7321936Shselasky * licenses. You may choose to be licensed under the terms of the GNU 8321936Shselasky * General Public License (GPL) Version 2, available from the file 9321936Shselasky * COPYING in the main directory of this source tree, or the 10321936Shselasky * OpenIB.org BSD license below: 11321936Shselasky * 12321936Shselasky * Redistribution and use in source and binary forms, with or 13321936Shselasky * without modification, are permitted provided that the following 14321936Shselasky * conditions are met: 15321936Shselasky * 16321936Shselasky * - Redistributions of source code must retain the above 17321936Shselasky * copyright notice, this list of conditions and the following 18321936Shselasky * disclaimer. 19321936Shselasky * 20321936Shselasky * - Redistributions in binary form must reproduce the above 21321936Shselasky * copyright notice, this list of conditions and the following 22321936Shselasky * disclaimer in the documentation and/or other materials 23321936Shselasky * provided with the distribution. 24321936Shselasky * 25321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32321936Shselasky * SOFTWARE. 33321936Shselasky * 34321936Shselasky */ 35321936Shselasky 36321936Shselasky/* 37321936Shselasky * Abstract: 38321936Shselasky * Defines standard return codes, keywords, macros, and debug levels. 39321936Shselasky */ 40321936Shselasky 41321936Shselasky#ifdef __WIN__ 42321936Shselasky#pragma warning(disable : 4996) 43321936Shselasky#endif 44321936Shselasky 45321936Shselasky#ifndef _CL_TYPES_H_ 46321936Shselasky#define _CL_TYPES_H_ 47321936Shselasky 48321936Shselasky#ifdef __cplusplus 49321936Shselasky# define BEGIN_C_DECLS extern "C" { 50321936Shselasky# define END_C_DECLS } 51321936Shselasky#else /* !__cplusplus */ 52321936Shselasky# define BEGIN_C_DECLS 53321936Shselasky# define END_C_DECLS 54321936Shselasky#endif /* __cplusplus */ 55321936Shselasky 56321936ShselaskyBEGIN_C_DECLS 57321936Shselasky#include <complib/cl_types_osd.h> 58321936Shselasky#include <stddef.h> 59321936Shselaskytypedef uint16_t net16_t; 60321936Shselaskytypedef uint32_t net32_t; 61321936Shselaskytypedef uint64_t net64_t; 62321936Shselasky 63321936Shselasky/* explicit cast of void* to uint32_t */ 64321936Shselasky#ifndef ASSERT_VOIDP2UINTN 65321936Shselasky#if __WORDSIZE == 64 66321936Shselasky#define ASSERT_VOIDP2UINTN(var) \ 67321936Shselasky CL_ASSERT( (intptr_t)var <= 0xffffffffffffffffL ) 68321936Shselasky#else /* __WORDSIZE == 64 */ 69321936Shselasky#if __WORDSIZE == 32 70321936Shselasky /* need to cast carefully to avoid the warining of un-needed check */ 71321936Shselasky#define ASSERT_VOIDP2UINTN(var) \ 72321936Shselasky CL_ASSERT( (intptr_t)var <= 0x100000000ULL ) 73321936Shselasky#else /* __WORDSIZE == 32 */ 74321936Shselasky#error "Need to know WORDSIZE to tell how to cast to unsigned long int" 75321936Shselasky#endif /* __WORDSIZE == 32 */ 76321936Shselasky#endif /* __WORDSIZE == 64 */ 77321936Shselasky#endif 78321936Shselasky 79321936Shselasky/* explicit casting of void* to long */ 80321936Shselasky#ifndef CAST_P2LONG 81321936Shselasky#define CAST_P2LONG(var) ((intptr_t)(var)) 82321936Shselasky#endif 83321936Shselasky 84321936Shselasky/****d* Component Library: Pointer Manipulation/offsetof 85321936Shselasky* NAME 86321936Shselasky* offsetof 87321936Shselasky* 88321936Shselasky* DESCRIPTION 89321936Shselasky* The offsetof macro returns the offset of a member within a structure. 90321936Shselasky* 91321936Shselasky* SYNOPSIS 92321936Shselasky* uintptr_t 93321936Shselasky* offsetof( 94321936Shselasky* IN TYPE, 95321936Shselasky* IN MEMBER ); 96321936Shselasky* 97321936Shselasky* PARAMETERS 98321936Shselasky* TYPE 99321936Shselasky* [in] Name of the structure containing the specified member. 100321936Shselasky* 101321936Shselasky* MEMBER 102321936Shselasky* [in] Name of the member whose offset in the specified structure 103321936Shselasky* is to be returned. 104321936Shselasky* 105321936Shselasky* RETURN VALUE 106321936Shselasky* Number of bytes from the beginning of the structure to the 107321936Shselasky* specified member. 108321936Shselasky* 109321936Shselasky* SEE ALSO 110321936Shselasky* PARENT_STRUCT 111321936Shselasky*********/ 112321936Shselasky#ifndef offsetof 113321936Shselasky#define offsetof(TYPE, MEMBER) ((uintptr_t) &((TYPE *)0)->MEMBER) 114321936Shselasky#endif 115321936Shselasky 116321936Shselasky/****d* Component Library: Pointer Manipulation/PARENT_STRUCT 117321936Shselasky* NAME 118321936Shselasky* PARENT_STRUCT 119321936Shselasky* 120321936Shselasky* DESCRIPTION 121321936Shselasky* The PARENT_STRUCT macro returns a pointer to a structure 122321936Shselasky* given a name and pointer to one of its members. 123321936Shselasky* 124321936Shselasky* SYNOPSIS 125321936Shselasky* PARENT_TYPE* 126321936Shselasky* PARENT_STRUCT( 127321936Shselasky* IN void* const p_member, 128321936Shselasky* IN PARENT_TYPE, 129321936Shselasky* IN MEMBER_NAME ); 130321936Shselasky* 131321936Shselasky* PARAMETERS 132321936Shselasky* p_member 133321936Shselasky* [in] Pointer to the MEMBER_NAME member of a PARENT_TYPE structure. 134321936Shselasky* 135321936Shselasky* PARENT_TYPE 136321936Shselasky* [in] Name of the structure containing the specified member. 137321936Shselasky* 138321936Shselasky* MEMBER_NAME 139321936Shselasky* [in] Name of the member whose address is passed in the p_member 140321936Shselasky* parameter. 141321936Shselasky* 142321936Shselasky* RETURN VALUE 143321936Shselasky* Pointer to a structure of type PARENT_TYPE whose MEMBER_NAME member is 144321936Shselasky* located at p_member. 145321936Shselasky* 146321936Shselasky* SEE ALSO 147321936Shselasky* offsetof 148321936Shselasky*********/ 149321936Shselasky#define PARENT_STRUCT(p_member, PARENT_TYPE, MEMBER_NAME) \ 150321936Shselasky ((PARENT_TYPE*)((uint8_t*)(p_member) - offsetof(PARENT_TYPE, MEMBER_NAME))) 151321936Shselasky 152321936Shselasky/****d* Component Library/Parameter Keywords 153321936Shselasky* NAME 154321936Shselasky* Parameter Keywords 155321936Shselasky* 156321936Shselasky* DESCRIPTION 157321936Shselasky* The Parameter Keywords can be used to clarify the usage of function 158321936Shselasky* parameters to users. 159321936Shselasky* 160321936Shselasky* VALUES 161321936Shselasky* IN 162321936Shselasky* Designates that the parameter is used as input to a function. 163321936Shselasky* 164321936Shselasky* OUT 165321936Shselasky* Designates that the parameter's value will be set by the function. 166321936Shselasky* 167321936Shselasky* OPTIONAL 168321936Shselasky* Designates that the parameter is optional, and may be NULL. 169321936Shselasky* The OPTIONAL keyword, if used, follows the parameter name. 170321936Shselasky* 171321936Shselasky* EXAMPLE 172321936Shselasky* // Function declaration. 173321936Shselasky* void* 174321936Shselasky* my_func( 175321936Shselasky* IN void* const p_param1, 176321936Shselasky* OUT void** const p_handle OPTIONAL ); 177321936Shselasky* 178321936Shselasky* NOTES 179321936Shselasky* Multiple keywords can apply to a single parameter. The IN and OUT 180321936Shselasky* keywords precede the parameter type. The OPTIONAL 181321936Shselasky* keyword, if used, follows the parameter name. 182321936Shselasky*********/ 183321936Shselasky#ifndef IN 184321936Shselasky#define IN /* Function input parameter */ 185321936Shselasky#endif 186321936Shselasky#ifndef OUT 187321936Shselasky#define OUT /* Function output parameter */ 188321936Shselasky#endif 189321936Shselasky#ifndef OPTIONAL 190321936Shselasky#define OPTIONAL /* Optional function parameter - NULL if not used */ 191321936Shselasky#endif 192321936Shselasky 193321936Shselasky/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 194321936Shselasky%% Function Returns And Completion Codes %% 195321936Shselasky%% %% 196321936Shselasky%% The text for any addition to this enumerated type must be added to the %% 197321936Shselasky%% string array defined in <cl_statustext.c>. %% 198321936Shselasky%% %% 199321936Shselasky%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 200321936Shselasky 201321936Shselasky/****d* Component Library/Data Types 202321936Shselasky* NAME 203321936Shselasky* Data Types 204321936Shselasky* 205321936Shselasky* DESCRIPTION 206321936Shselasky* The component library provides and uses explicitly sized types. 207321936Shselasky* 208321936Shselasky* VALUES 209321936Shselasky* char 210321936Shselasky* 8-bit, defined by compiler. 211321936Shselasky* 212321936Shselasky* void 213321936Shselasky* 0-bit, defined by compiler. 214321936Shselasky* 215321936Shselasky* int8_t 216321936Shselasky* 8-bit signed integer. 217321936Shselasky* 218321936Shselasky* uint8_t 219321936Shselasky* 8-bit unsigned integer. 220321936Shselasky* 221321936Shselasky* int16_t 222321936Shselasky* 16-bit signed integer. 223321936Shselasky* 224321936Shselasky* uint16_t 225321936Shselasky* 16-bit unsigned integer. 226321936Shselasky* 227321936Shselasky* net16_t 228321936Shselasky* 16-bit network byte order value. 229321936Shselasky* 230321936Shselasky* int32_t 231321936Shselasky* 32-bit signed integer. 232321936Shselasky* 233321936Shselasky* uint32_t 234321936Shselasky* 32-bit unsigned integer. 235321936Shselasky* 236321936Shselasky* net32_t 237321936Shselasky* 32-bit network byte order value. 238321936Shselasky* 239321936Shselasky* int64_t 240321936Shselasky* 64-bit signed integer. 241321936Shselasky* 242321936Shselasky* uint64_t 243321936Shselasky* 64-bit unsigned integer. 244321936Shselasky* 245321936Shselasky* net64_t 246321936Shselasky* 64-bit network byte order value. 247321936Shselasky* 248321936Shselasky* boolean_t 249321936Shselasky* integral sized. Set to TRUE or FALSE and used in logical expressions. 250321936Shselasky* 251321936Shselasky* NOTES 252321936Shselasky* Pointer types are not defined as these provide no value and can potentially 253321936Shselasky* lead to naming confusion. 254321936Shselasky*********/ 255321936Shselasky 256321936Shselasky/****d* Component Library: Data Types/cl_status_t 257321936Shselasky* NAME 258321936Shselasky* cl_status_t 259321936Shselasky* 260321936Shselasky* DESCRIPTION 261321936Shselasky* The cl_status_t return types are used by the component library to 262321936Shselasky* provide detailed function return values. 263321936Shselasky* 264321936Shselasky* SYNOPSIS 265321936Shselasky*/ 266321936Shselasky#define CL_SUCCESS 0 267321936Shselasky#define CL_ERROR 1 268321936Shselasky#define CL_INVALID_STATE 2 269321936Shselasky#define CL_INVALID_OPERATION 3 270321936Shselasky#define CL_INVALID_SETTING 4 271321936Shselasky#define CL_INVALID_PARAMETER 5 272321936Shselasky#define CL_INSUFFICIENT_RESOURCES 6 273321936Shselasky#define CL_INSUFFICIENT_MEMORY 7 274321936Shselasky#define CL_INVALID_PERMISSION 8 275321936Shselasky#define CL_COMPLETED 9 276321936Shselasky#define CL_NOT_DONE 10 277321936Shselasky#define CL_PENDING 11 278321936Shselasky#define CL_TIMEOUT 12 279321936Shselasky#define CL_CANCELED 13 280321936Shselasky#define CL_REJECT 14 281321936Shselasky#define CL_OVERRUN 15 282321936Shselasky#define CL_NOT_FOUND 16 283321936Shselasky#define CL_UNAVAILABLE 17 284321936Shselasky#define CL_BUSY 18 285321936Shselasky#define CL_DISCONNECT 19 286321936Shselasky#define CL_DUPLICATE 20 287321936Shselasky#define CL_STATUS_COUNT 21 /* should be the last value */ 288321936Shselasky 289321936Shselaskytypedef int cl_status_t; 290321936Shselasky/* 291321936Shselasky* SEE ALSO 292321936Shselasky* Data Types, CL_STATUS_MSG 293321936Shselasky*********/ 294321936Shselasky 295321936Shselasky/* Status values above converted to text for easier printing. */ 296321936Shselaskyextern const char *cl_status_text[]; 297321936Shselasky 298321936Shselasky#ifndef cl_panic 299321936Shselasky/****f* Component Library: Error Trapping/cl_panic 300321936Shselasky* NAME 301321936Shselasky* cl_panic 302321936Shselasky* 303321936Shselasky* DESCRIPTION 304321936Shselasky* Halts execution of the current process. Halts the system if called in 305321936Shselasky* from the kernel. 306321936Shselasky* 307321936Shselasky* SYNOPSIS 308321936Shselasky*/ 309321936Shselaskyvoid cl_panic(IN const char *const message, IN ...); 310321936Shselasky/* 311321936Shselasky* PARAMETERS 312321936Shselasky* message 313321936Shselasky* [in] ANSI string formatted identically as for a call to the standard C 314321936Shselasky* function printf describing the cause for the panic. 315321936Shselasky* 316321936Shselasky* ... 317321936Shselasky* [in] Extra parameters for string formatting, as defined for the 318321936Shselasky* standard C function printf. 319321936Shselasky* 320321936Shselasky* RETURN VALUE 321321936Shselasky* This function does not return. 322321936Shselasky* 323321936Shselasky* NOTES 324321936Shselasky* The formatting of the message string is the same as for printf 325321936Shselasky* 326321936Shselasky* cl_panic sends the message to the current message logging target. 327321936Shselasky*********/ 328321936Shselasky#endif /* cl_panic */ 329321936Shselasky 330321936Shselasky/****d* Component Library: Data Types/CL_STATUS_MSG 331321936Shselasky* NAME 332321936Shselasky* CL_STATUS_MSG 333321936Shselasky* 334321936Shselasky* DESCRIPTION 335321936Shselasky* The CL_STATUS_MSG macro returns a textual representation of 336321936Shselasky* an cl_status_t code. 337321936Shselasky* 338321936Shselasky* SYNOPSIS 339321936Shselasky* const char* 340321936Shselasky* CL_STATUS_MSG( 341321936Shselasky* IN cl_status_t errcode ); 342321936Shselasky* 343321936Shselasky* PARAMETERS 344321936Shselasky* errcode 345321936Shselasky* [in] cl_status_t code for which to return a text representation. 346321936Shselasky* 347321936Shselasky* RETURN VALUE 348321936Shselasky* Pointer to a string containing a textual representation of the errcode 349321936Shselasky* parameter. 350321936Shselasky* 351321936Shselasky* NOTES 352321936Shselasky* This function performs boundary checking on the cl_status_t value, 353321936Shselasky* masking off the upper 24-bits. If the value is out of bounds, the string 354321936Shselasky* "invalid status code" is returned. 355321936Shselasky* 356321936Shselasky* SEE ALSO 357321936Shselasky* cl_status_t 358321936Shselasky*********/ 359321936Shselasky#define CL_STATUS_MSG( errcode ) \ 360321936Shselasky ((errcode < CL_STATUS_COUNT)?cl_status_text[errcode]:"invalid status code") 361321936Shselasky 362321936Shselasky#if !defined( FALSE ) 363321936Shselasky#define FALSE 0 364321936Shselasky#endif /* !defined( FALSE ) */ 365321936Shselasky 366321936Shselasky#if !defined( TRUE ) 367321936Shselasky#define TRUE (!FALSE) 368321936Shselasky#endif /* !defined( TRUE ) */ 369321936Shselasky 370321936Shselasky/****d* Component Library: Unreferenced Parameters/UNUSED_PARAM 371321936Shselasky* NAME 372321936Shselasky* UNUSED_PARAM 373321936Shselasky* 374321936Shselasky* DESCRIPTION 375321936Shselasky* The UNUSED_PARAM macro can be used to eliminates compiler warnings related 376321936Shselasky* to intentionally unused formal parameters in function implementations. 377321936Shselasky* 378321936Shselasky* SYNOPSIS 379321936Shselasky* UNUSED_PARAM( P ) 380321936Shselasky* 381321936Shselasky* EXAMPLE 382321936Shselasky* void my_func( int32_t value ) 383321936Shselasky* { 384321936Shselasky* UNUSED_PARAM( value ); 385321936Shselasky* } 386321936Shselasky*********/ 387321936Shselasky 388321936Shselasky/****d* Component Library/Object States 389321936Shselasky* NAME 390321936Shselasky* Object States 391321936Shselasky* 392321936Shselasky* DESCRIPTION 393321936Shselasky* The object states enumerated type defines the valid states of components. 394321936Shselasky* 395321936Shselasky* SYNOPSIS 396321936Shselasky*/ 397321936Shselaskytypedef enum _cl_state { 398321936Shselasky CL_UNINITIALIZED = 1, 399321936Shselasky CL_INITIALIZED, 400321936Shselasky CL_DESTROYING, 401321936Shselasky CL_DESTROYED 402321936Shselasky} cl_state_t; 403321936Shselasky/* 404321936Shselasky* VALUES 405321936Shselasky* CL_UNINITIALIZED 406321936Shselasky* Indicates that initialization was not invoked successfully. 407321936Shselasky* 408321936Shselasky* CL_INITIALIZED 409321936Shselasky* Indicates initialization was successful. 410321936Shselasky* 411321936Shselasky* CL_DESTROYING 412321936Shselasky* Indicates that the object is undergoing destruction. 413321936Shselasky* 414321936Shselasky* CL_DESTROYED 415321936Shselasky* Indicates that the object's destructor has already been called. Most 416321936Shselasky* objects set their final state to CL_DESTROYED before freeing the 417321936Shselasky* memory associated with the object. 418321936Shselasky*********/ 419321936Shselasky 420321936Shselasky/****d* Component Library: Object States/cl_is_state_valid 421321936Shselasky* NAME 422321936Shselasky* cl_is_state_valid 423321936Shselasky* 424321936Shselasky* DESCRIPTION 425321936Shselasky* The cl_is_state_valid function returns whether a state has a valid value. 426321936Shselasky* 427321936Shselasky* SYNOPSIS 428321936Shselasky*/ 429321936Shselaskystatic inline boolean_t cl_is_state_valid(IN const cl_state_t state) 430321936Shselasky{ 431321936Shselasky return ((state == CL_UNINITIALIZED) || (state == CL_INITIALIZED) || 432321936Shselasky (state == CL_DESTROYING) || (state == CL_DESTROYED)); 433321936Shselasky} 434321936Shselasky 435321936Shselasky/* 436321936Shselasky* PARAMETERS 437321936Shselasky* state 438321936Shselasky* State whose value to validate. 439321936Shselasky* 440321936Shselasky* RETURN VALUES 441321936Shselasky* TRUE if the specified state has a valid value. 442321936Shselasky* 443321936Shselasky* FALSE otherwise. 444321936Shselasky* 445321936Shselasky* NOTES 446321936Shselasky* This function is used in debug builds to check for valid states. If an 447321936Shselasky* uninitialized object is passed, the memory for the state may cause the 448321936Shselasky* state to have an invalid value. 449321936Shselasky* 450321936Shselasky* SEE ALSO 451321936Shselasky* Object States 452321936Shselasky*********/ 453321936Shselasky 454321936ShselaskyEND_C_DECLS 455321936Shselasky#endif /* _DATA_TYPES_H_ */ 456