
/*M*                     
//                    INTEL CORPORATION PROPRIETARY INFORMATION
//      This software is supplied under the terms of a license agreement or
//      nondisclosure agreement with Intel Corporation and may not be copied
//      or disclosed except in accordance with the terms of that agreement.
//            Copyright (c) 1995-2000 Intel Corporation.  All Rights Reserved.
//
*M*/
/*
 * $Log:   //cospublic004/shareddata/isc/ISC2x/NTWORK/SRC/ImbApi/imbapi.h.v  $
 * 
 *    Rev 1.11   30 Aug 1999 09:42:34   spoolax
 * gcc complains about the redefinition of
 * ImbAsyncSeq. Kept this in #ifndef LINUX
 * 
 *    Rev 1.10   18 Aug 1999 18:10:14   sganeshx
 * fixed DPC over NetWare bug.
 * 1. Modified function 'UnRegisterForImbAsyncMessageNotification'
 *     in file IMB_NW.C to accept a second parameter
 *     which will indicate source of NLM unload.
 * 2. Modified function prototype in IMBAPI.H
 * 3. Modified call to function 'UnRegisterForImbAsyncMessageNotification'
 *     in DPCTHD.C
 * 
 *    Rev 1.9   27 Jul 1999 09:52:36   jpaiasno
 *  
 * 
 *    Rev 1.8   May 07 1999 12:04:36   sganeshx
 * 1. added new constant for response length
 *     from Get Device ID command (IPMI v1.0)
 *     IPMI10_GET_DEVICE_ID_RESP_LENGTH
 * 
 * 2. use (IPMI10_GET_DEVICE_ID_RESP_LENGTH-1)
 *     to check for IPMI version.
 * 
 *    Rev 1.7   04 May 1999 16:14:14   jpaiasno
 * Changed the channel numbers back to their
 * original values.
 * 
 *    Rev 1.6   04 May 1999 15:47:52   jpaiasno
 *  
 * 
 *    Rev 1.5   27 Apr 1999 14:15:18   jpaiasno
 * Added code to support IPMI 1.0 for IPMB
 * requests.
 * 
 *    Rev 1.4   Apr 16 1999 10:49:08   sganeshx
 * removed two (2) members from the 
 * IMBPREQUEST structure
 * 1. ucIPMIVer
 * 2. ulReserved
 * since these are no longer required.
 * 
 *    Rev 1.3   09 Jan 1999 20:16:26   sganeshx
 * added IPMI version field into IMBPREQUEST structure
 * 
 *    Rev 1.2   15 Dec 1998 14:44:26   jpaiasno
 * fixed netware compilation issues
 * 
 *    Rev 1.1   08 Dec 1998 11:19:10   jpaiasno
 * Added new APIs to support DPC related async.
 * events from EMP console
 * 
 *    Rev 1.6   03 Apr 1998 15:13:06   HMAHADEX
 * Added Ioctl for Async poller
 * 
 *    Rev 1.5   25 Mar 1998 14:29:08   fkhanx
 * Added copyright header
*/
#ifndef IMBAPI_H__
#define IMBAPI_H__

#if defined( _WINDOWS)
	#include <windows.h>
#endif


#ifndef UNIX
#include "intrface.h"
#else
#include <sys/types.h>
#include "../ntio/inc/windows.h"
#include "../sensorn/intrface.h"
#endif

#define	WRITE_READ_I2C				0x52
#define	WRITE_EMP_BUFFER			0x7a
#define	GET_DEVICE_ID				0x1
#define SEND_MESSAGE				0x34

#define BMC_SA				0x20
#define BMC_LUN				0
#define APP_NETFN			0x06
#define	IPMI_09_VERSION		0x90
#define	IPMI_10_VERSION		0x01

// IPMI 1.0 response length to Get Device ID command
#ifndef IPMI10_GET_DEVICE_ID_RESP_LENGTH
	#define IPMI10_GET_DEVICE_ID_RESP_LENGTH	12
#endif
//channel numbers for sending and receiving Async Messages
#define IPMB_CHANNEL						0x0
#define	EMP_CHANNEL							0x1
#define LAN_CHANNEL							0x2

#define	RESERVED_LUN						0x3
#define		IPMB_LUN						0x2
#define		EMP_LUN							0x0

//api related structure definitions

#define		PUBLIC_BUS			0

//definitions to support older code done during DPC additions
#define BMC_CONTROLLER			0x20
#define FPC_CONTROLLER			0x22

typedef enum {

	ACCESN_OK,

	ACCESN_ERROR,

	ACCESN_OUT_OF_RANGE,

	ACCESN_END_OF_DATA,

	ACCESN_UNSUPPORTED,

	ACCESN_INVALID_TRANSACTION,

	ACCESN_TIMED_OUT

} ACCESN_STATUS;



#pragma pack(1)
//
// Request structure provided to SendTimedImbpRequest()
//
typedef struct {
	unsigned char	cmdType;	// IMB command
	unsigned char	rsSa;		// command destination address
	unsigned char	busType;	// not used
	unsigned char	netFn;		// IMB command class (network function)
	unsigned char	rsLun;		// subsystem on destination
	unsigned char *	data;		// command body
	int				dataLength;	// body size

} IMBPREQUESTDATA;

//
// Request structure provided to SendTimedI2cRequest()
//
typedef struct {
	unsigned char	rsSa;				// device address
	unsigned char	busType;			// which I2C bus
	unsigned char	numberOfBytesToRead;// how much data to return
	unsigned char *	data;				// write data
	int				dataLength;			// write data size

} I2CREQUESTDATA;

#pragma pack()

//#ifdef IMB_API
//
// This section is provided to be able to compile using imb_if.h
//

//
// function return type. This is also defined in the local instrumentation
// so we ifdef here to avoid conflict.
//

//
// This is needed to construct the IOCTL values in imb_if.h
//
#define CTL_CODE( DeviceType, Function, Method, Access ) (DWORD)(                 \
		((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
	)
#define METHOD_BUFFERED		0
#define FILE_ANY_ACCESS		0
typedef DWORD NTSTATUS;
//
// This is necessary to compile using memIf.h
//
typedef enum _INTERFACE_TYPE
{
    Internal,
    Isa,
    Eisa,
    MicroChannel,
    TurboChannel,
    MaximumInterfaceType
} INTERFACE_TYPE, * PINTERFACE_TYPE;

//#else	// not IMB_API
//
// These are defined in imb_if.h but are needed by users of the imbapi library
//
#ifndef LINUX
// Note that this redefinition causes gcc to complain.
typedef DWORD	ImbAsyncSeq;
#endif // LINUX

#define ASYNC_SEQ_START		0	// starting sequence number
//
// This is the generic IMB packet format, the final checksum can't be
// represented in this structure and will show up as the last data byte
//


#define MIN_IMB_PACKET_SIZE		7	// ImbPacket w/o data, but w/trailing checksum
#define MAX_IMB_PACKET_SIZE		33	// as per spec
#define	MAX_BUFFER_SIZE			64

//#endif // IMB_API

/////////////////////////////////////////////////////////////////////////////////////////
//  FUNCTION PROTOTYPES
/////////////////////////////////////////////////////////////////////////////////////////

ACCESN_STATUS
SendTimedImbpRequest (
		IMBPREQUESTDATA *reqPtr,		// request info and data
		int				timeOut,		// how long to wait, in mSec units
		BYTE *			respDataPtr,	// where to put response data
		int *			respDataLen,	// how much response data there is
		BYTE *			completionCode	// request status from dest controller
	);

ACCESN_STATUS
SendTimedI2cRequest (
		I2CREQUESTDATA *reqPtr,			// I2C request
		int				timeOut,		// how long to wait, mSec units
		BYTE *			respDataPtr,	// where to put response data
		int *			respDataLen,	// size of response buffer/size of returned data
		BYTE *			completionCode	// request status from BMC
	);

ACCESN_STATUS
SendAsyncImbpRequest (
		IMBPREQUESTDATA *reqPtr,		// request info and data
		BYTE *			 seqNo			// IMB sequence number used when creating IMB msg
	);

ACCESN_STATUS
GetAsyncImbpMessage (
		ImbPacket *		msgPtr,		// request info and data
		DWORD *			msgLen,		// IN - length of buffer, OUT - msg len
		DWORD			timeOut,	// how long to wait for a message, mSec units
		ImbAsyncSeq *	seqNo,		// previously returned seq number (or ASYNC_SEQ_START)
		DWORD			channelNumber //the channel number on which the expected message
									 //  arrives	
	);

#ifndef UNIX

ACCESN_STATUS
UnmapPhysicalMemory (
		int virtualAddress	// what memory to unmap
	);

#else // UNIX

ACCESN_STATUS
UnmapPhysicalMemory( int virtualAddress, int Length );

ACCESN_STATUS
StartAsyncMesgPoll();

#endif	// UNIX

ACCESN_STATUS
MapPhysicalMemory (
		int startAddress,	// physical address to map in
		int addressLength,	// how much to map
		int *virtualAddress	// where it got mapped to
	);

ACCESN_STATUS
SetShutDownCode (
		int delayTime,	// time to delay in 100ms units
		int code		// what to do when time expires
	);


ACCESN_STATUS
SendTimedEmpMessageResponse (

		ImbPacket *	 ptr,		// pointer to the original request from EMP
		char      *responseDataBuf,
		int		  responseDataLen,
		int 	  timeOut		// how long to wait, in mSec units
	);


ACCESN_STATUS
IsAsyncMessageAvailable (unsigned int   eventId	);

ACCESN_STATUS
RegisterForImbAsyncMessageNotification (unsigned int *handleId);


ACCESN_STATUS
UnRegisterForImbAsyncMessageNotification (unsigned int handleId,int iFlag);



#endif // IMBAPI_H__
