/* API - Any Device - Any OS */
/* $Workfile: gsc_common.h $ */
/* $Revision: 1 $ */
/* $Date: 11/15/07 11:13a $ */
/*
*	This file contains components common across all GSC product SDK.
*/
/* $Log: /NEW SOURCESAFE DATABASE/SDK/common/api/gsc_common.h $
 * 
 * 4     11/15/07 11:13a Dnewbold
 * Added PLDA references.
 * 
 * 3     11/02/07 7:39a Dnewbold
 * Include gsc_types.h rather than gsc_os_common.h.
 * 
 * 2     3/01/07 5:23p Dnewbold
 * Added #include of gsc_os_common.h and moved some code there.
 *
 * 1     8/22/05 11:47a Dnewbold
*/

#ifndef __GSC_COMMON_H__
#define __GSC_COMMON_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "gsc_types.h"



/* #defines	*****************************************************************/

#define	GSC_PROCESS_OPEN_MAX		8

#define	GSC_NO_CHANGE				0xFFFFFFFFUL
#define	GSC_DEFAULT					0xFFFFFFFEUL

#define	GSC_IO_STATUS_TX			0x80000000
#define	GSC_IO_STATUS_MASK			0x70000000	/* Current status */
#define	GSC_IO_STATUS_COUNT_MASK	0x0FFFFFFF	/* 256MB */

#define	GSC_IO_STATUS_ERROR			0x40000000	/* 4 */
#define	GSC_IO_STATUS_ABORTED		0x30000000	/* 3 */
#define	GSC_IO_STATUS_TIMEOUT		0x20000000	/* 2 */
#define	GSC_IO_STATUS_ACTIVE		0x10000000	/* 1 */
#define	GSC_IO_STATUS_SUCCESS		0x00000000	/* 0 */


#define	GSC_REG_PCI					0x8000
#define	GSC_REG_PLX					0x4000
#define	GSC_REG_PLDA				0x4000
#define	GSC_REG_GSC					0x0000

/*
*	Encoding and decoding of registers.
*	r = register value to decode
*	v = field value to encode
*	b = beginning bit (most significant bit position, 31 is the upper most bit).
*	e = ending bit (least significant bit position, 0 is the lower most bit).
*/
#define	GSC_FIELD_DECODE(r,b,e)		(((r)>>(e)) & (0xFFFFFFFFUL >> (31-((b)-(e)))))
#define	GSC_FIELD_ENCODE(v,b,e)		(((v) << (e)) & ((0xFFFFFFFF << (e)) & (0xFFFFFFFF >> (31 - (b)))))

/*
*	Register definitions:
*	bits 15-14:	register type (PCI, PLX, PLDA, or GSC product specific)
*	bits 13-12:	register size (1, 2 or 4 bytes)
*	bits 11-0:	register offset (0 to 0xFFF)
*/
#define	GSC_REG_ENCODE(t,s,o)		(((t) & 0xC000) | \
									GSC_FIELD_ENCODE((s) - 1,13,12) | \
									GSC_FIELD_ENCODE((o),11,0))

#define	GSC_REG_OFFSET(r)			GSC_FIELD_DECODE((r),11,0)
#define	GSC_REG_SIZE(r)				(GSC_FIELD_DECODE((r),13,12) + 1)
#define	GSC_REG_TYPE(r)				((r) & 0xC000)



/* Predefined version indexes. */
#define	GSC_VERSION_LIBRARY			0	/* API Library Version */
#define	GSC_VERSION_DRIVER			1	/* Device Driver Version */



/* typedefs	*****************************************************************/

#ifdef GSC_DATA_TYPES_CHECK

	/* Some compilers do not support preprocessing of sizeof(). */

	#if (sizeof(S8) != 1)
		#error S8 is ill defined.
	#endif

	#if (sizeof(U8) != 1)
		#error U8 is ill defined.
	#endif

	#if (sizeof(S16) != 2)
		#error S16 is ill defined.
	#endif

	#if (sizeof(U16) != 2)
		#error U16 is ill defined.
	#endif

	#if (sizeof(S32) != 4)
		#error S32 is ill defined.
	#endif

	#if (sizeof(U32) != 4)
		#error U32 is ill defined.
	#endif

#endif

/* API Return Code Values */
typedef enum
{
    GSC_SUCCESS	= 0x200,				/* 0x200	512 */
    GSC_FAILED,							/* 0x201	513 */
    GSC_ACCESS_DENIED,					/* 0x202	514 */
    GSC_DMA_CHANNEL_UNAVAILABLE,		/* 0x203	515 */
    GSC_DMA_CHANNEL_INVALID,			/* 0x204	516 */
    GSC_DMA_CHANNEL_TYPE_ERROR,			/* 0x205	517 */
    GSC_DMA_IN_PROGRESS,				/* 0x206	518 */
    GSC_DMA_DONE,						/* 0x207	519 */
    GSC_DMA_PAUSED,						/* 0x208	520 */
    GSC_DMA_NOT_PAUSED,					/* 0x209	521 */
    GSC_DMA_CHANNEL_COMMAND_INVALID,	/* 0x20A	522 */
    GSC_DMA_MAN_READY,					/* 0x20B	523 */
    GSC_DMA_MAN_NOT_READY,				/* 0x20C	524 */
    GSC_DMA_INVALID_CHANNEL_PRIORITY,	/* 0x20D	525 */
    GSC_DMA_MAN_CORRUPTED,				/* 0x20E	526 */
    GSC_DMA_INVALID_ELEMENT_INDEX,		/* 0x20F	527 */
    GSC_DMA_NO_MORE_ELEMENTS,			/* 0x210	528 */
    GSC_DMA_SGL_INVALID,				/* 0x211	529 */
    GSC_DMA_SGL_QUEUE_FULL,				/* 0x212	530 */
    GSC_NULL_PARAM,						/* 0x213	531 */
    GSC_INVALID_BUS_INDEX,				/* 0x214	532 */
    GSC_UNSUPPORTED_FUNCTION,			/* 0x215	533 */
    GSC_INVALID_PCI_SPACE,				/* 0x216	534 */
    GSC_INVALID_IOP_SPACE,				/* 0x217	535 */
    GSC_INVALID_SIZE,					/* 0x218	536 */
    GSC_INVALID_ADDRESS,				/* 0x219	537 */
    GSC_INVALID_ADDRESS_TYPE,			/* 0x21A	538 */
    GSC_INVALID_INDEX,					/* 0x21B	539 */
    GSC_MU_NOT_READY,					/* 0x21C	540 */
    GSC_MU_FIFO_EMPTY,					/* 0x21D	541 */
    GSC_MU_FIFO_FULL,					/* 0x21E	542 */
    GSC_INVALID_REGISTER,				/* 0x21F	543 */
    GSC_DOORBELL_CLEAR_FAILED,			/* 0x220	544 */
    GSC_INVALID_USER_PIN,				/* 0x221	545 */
    GSC_INVALID_USER_STATE,				/* 0x222	546 */
    GSC_EEPROM_NOT_PRESENT,				/* 0x223	547 */
    GSC_EEPROMP_TYPE_NOT_SUPPORTED,		/* 0x224	548 */
    GSC_EEPROM_BLANK,					/* 0x225	549 */
    GSC_CONFIG_ACCESS_FAILED,			/* 0x226	550 */
    GSC_INVALID_DEVICE_INFO,			/* 0x227	551 */
    GSC_NO_ACTIVE_DRIVER,				/* 0x228	552 */
    GSC_INSUFFICIENT_RESOURCES,			/* 0x229	553 */
    GSC_OBJECT_ALREADY_ALLOCATED,		/* 0x22A	554 */
    GSC_ALREADY_INITIALIZED,			/* 0x22B	555 */
    GSC_NOT_INITIALIZED,				/* 0x22C	556 */
    GSC_BAD_CONFIG_REG_ENDIAN_MODE,		/* 0x22D	557 */
    GSC_INVALID_POWER_STATE,			/* 0x22E	558 */
    GSC_POWER_DOWN,						/* 0x22F	559 */
    GSC_FLYBY_NOT_SUPPORTED,			/* 0x230	560 */
    GSC_CHANNEL_NOT_SUPPORTED,			/* 0x231	561 */
    GSC_NO_ACTION,						/* 0x232	562 */
    GSC_HS_NOT_SUPPORTED,				/* 0x233	563 */
    GSC_VP_NOT_SUPPORTED,				/* 0x234	564 */
    GSC_VPD_NOT_ENABLED,				/* 0x235	565 */
    GSC_NO_MORE_CAP,					/* 0x236	566 */
    GSC_INVALID_OFFSET,					/* 0x237	567 */
    GSC_BAD_PIN_DIRECTION,				/* 0x238	568 */
    GSC_PCI_TIMEOUT,					/* 0x239	569 */
    GSC_DMA_CHANNEL_CLOSED,				/* 0x23A	570 */
    GSC_DMA_CHANNEL_ERROR,				/* 0x23B	571 */
    GSC_INVALID_HANDLE,					/* 0x23C	572 */
    GSC_BUFFER_NOT_READY,				/* 0x23D	573 */
    GSC_INVALID_DATA,					/* 0x23E	574 */
    GSC_DO_NOTHING,						/* 0x23F	575 */
    GSC_DMA_SGL_BUILD_FAILED,			/* 0x240	576 */
    GSC_PM_NOT_SUPPORTED,				/* 0x241	577 */
    GSC_INVALID_VERSION_DRIVER,			/* 0x242	578 */
    GSC_WAIT_TIMEOUT,					/* 0x243	579 */
    GSC_WAIT_CANCELED,					/* 0x244	580 */

	GSC_LIB_LOAD_FAILURE	= 0x800,	/* 0x800	2048 */
	GSC_RESERVED2,						/* 0x801	2049 */
    GSC_INIT_FAILURE,					/* 0x802	2050 */
    GSC_INVALID_VERSION_API,			/* 0x803	2051 */
    GSC_RESERVED,						/* 0x804	2052 */
	GSC_INTERNAL_ERROR,					/* 0x805	2053 */
	GSC_TOO_MANY_OPEN_HANDLES,			/* 0x806	2054 */
	GSC_INVALID_API_HANDLE,				/* 0x807	2055 */
	GSC_THREAD_FAILURE,					/* 0x808	2056 */
	GSC_ABORTED							/* 0x809	2057 */
} gsc_status_t;



#ifdef __cplusplus
}
#endif

#endif
