/**	 @(#)imcrpu.h	13.2 (RC International) 91/03/07	 */

/*
 * This file includes all definitions for the IMC-interface on the RPU. 
 */

#ifndef __IMCRPU
#define __IMCRPU

/***************************************\
 * Include files...		       *
\***************************************/

#include <rte/queue.h>			/* struct queue */
#include <rte/lan.h>			/* MAX_LAN_NAME */

/***************************************\
 * Some global constants...	       *
\***************************************/

/*
 * IMCportname_size 
 *
 * The maximum lenght of a name of a IMC-port. 
 */

#define IMCportname_size		12

/*
 * IMCmax_buffer_size 
 *
 * The maximum size of a buffer sent by IMC. 
 */

#define IMCmax_buffer_size		NBPG

/*
 * The different scopes used in IMCopenport. 
 */
#define IMCscope_anonymous		((u_char)0)
#define IMCscope_local			((u_char)1)
#define IMCscope_regional		((u_char)2)
#define IMCscope_global			((u_char)3)
#define IMCscope_max			IMCscope_global

/*
 * The different event-kinds. 
 */
#define IMCevent_port_closed		((u_char)0)
#define IMCevent_local_connect		((u_char)1)
#define IMCevent_remote_connect		((u_char)2)
#define IMCevent_disconnected		((u_char)3)
#define IMCevent_reset_indication	((u_char)4)
#define IMCevent_reset_completion	((u_char)5)
#define IMCevent_credit			((u_char)6)
#define IMCevent_data_sent		((u_char)7)
#define IMCevent_data_arrived		((u_char)8)
#define IMCevent_data_overrun		((u_char)9)

#define IMCevent_dummy			((u_char)10)

/*
 * The different reasons. 
 */
#define IMCreason_ok			((u_char)0)
#define IMCreason_name			((u_char)1)
#define IMCreason_resource		((u_char)2)
#define IMCreason_closed		((u_char)3)
#define IMCreason_network		((u_char)4)
#define IMCreason_protocol_error	((u_char)5)

/*
 * Result from IMC procedures: 
 */
#define IMCok				(0)
#define IMCnocredit			(1)

#define IMCerror_max			(10)

/***************************************\
 * Structures...		       *
\***************************************/

/*
 * struct IMCmessage 
 *
 * The structure used for all messages to the IMC-functions and to the
 * events. 
 */

struct IMCmessage
{

    /*
     * Internal used by IMC - Link to next message 
     */
    MSG			    *im_messagelink;

    /*
     * Internally used by IMC - Pointer to a process to be waken if
     * im_IMCcomp is NIL. 
     */
    struct process	    *im_process;

    /*
     * Internally used by IMC - Some flags. 
     */
    volatile int	     im_flags;

    /*
     * Used by IMCbuffer_wait() and IMCbuffer_return() to signal if a
     * process IS waiting for this buffer to be returned. 
     */
#define IM_WAITING	0x01

    /*
     * Used by IMCbuffer_return() to signal if a message is ALREADY
     * returned. 
     */
#define IM_RETURNED	0x02

    /*
     * Used by d2r_data() to signal if more data is received than
     * specified in the message. 
     */
#define IM_OVERRUN	0x04

    /*
     * User completion routine 
     */
    void		     (*im_comp) ();

    /*
     * User specified field 
     */
    char		    *im_dataptr;

    /*
     * User specified field 
     */
    short		     im_datasize;

    /*
     * IMC return value 
     */
    short		     im_bytecount;

    /*
     * IMC return value 
     */
    u_char		     im_eventkind;

    /*
     * IMC return value 
     */
    u_char		     im_reason;

    /*
     * User field - not used by IMC. 
     */
    short		     im_user_short;

    /*
     * User field - not used by IMC. 
     */
    caddr_t		     im_user_ptr;
};

/*
 * 'struct IMCnametable_entry' and 'struct IMCsysinfo' are used to
 * implement the IMC nametable on the RPU. The sole purpose of the
 * nametable on the RPU is to allow users to retrieve information
 * on IMC ports (via sysinfo).
 *
 * The information is updated by the functions IMCport_attach
 * and IMCport_detach. 
 */

struct IMCnametable_entry
{
    char			ine_portname[IMCportname_size+1];
    u_char			ine_scope;	/* LOCAL/REGIONAL/GLOBAL */
    bool_t			ine_portopen;	/* state: closed/open */
};

struct IMCsysinfo
{
    u_short			isi_numports;	/* # entries in nametable */
    struct IMCnametable_entry	*isi_nametab;	/* nametable for this LAN */
};

#endif /* __IMCRPU */
