/*****************************************************************************
 * Copyright (c) 1988-95 Digi International Inc., All Rights Reserved
 * 
 * This  software  contains  proprietary  and  confidential   information   of
 * Digi International  Inc.   By  accepting  transfer  of this copy, Recipient
 * agrees to retain this software in  confidence,  to  prevent  disclosure  to
 * others,  and  to make no  use of this software other than that for which it
 * was delivered.  This is an unpublished copyright work  Digi   International
 * Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is
 * strictly prohibited.
 * 
 * Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc.
 * Confidential  when   combined   with   the   aggregated  modules  for  this
 * product) OBJECT CODE ONLY SOURCE MATERIALS
 * 
 * (C) COPYRIGHT Digi International Inc. 1995
 * 
 * All Rights Reserved
 * 
 * US   Government   Users   Restricted   Rights   -   Use,   duplication   or
 * disclosure  restricted by GSA ADP Schedule Contract with Digi International
 * Inc.
 * 
 *****************************************************************************/

/*
 * $Id: sxbus.h,v 1.8 1997/08/05 15:01:50 gary Exp $
 */

/******************************************************************
 *
 *  SpiderNET - Network Board Streams Driver
 *
 *  Copyright 1990  Spider Systems Limited
 *
 *  SXBUS.H
 *
 *    Board end code: streams headers.
 *
 ******************************************************************/

#ifdef M68030
#define FLUSHCACHE()     dcachclr()
#endif /* M68030 */

#define NDPTR	4		/* Number of data buffers allowed across the bus */
#ifdef  VIRTUAL
#define MAXPAGES        2               /* The maximum number of times a buffercan cross a page boundary 2 for 2K buffers and 1K pages */
#endif  /* VIRTUAL */

#define NPPTR	16		/* Should be enough */
#define NPOOLS	8		/* Ditto */
#define	NSTREAMHDS	270	/* maximum number of streams */

typedef uint32 memptr_t;
typedef uint32 memlen_t;

struct xbus_init {
	int8		board_ctl;
	int8		board_rsp;
	uint8		brd_intr;
	int8		pad_1;
	memptr_t	rdy_addr;	/* Address of ready struct */
	memptr_t	atn_addr;	/* Address of attention struct */
	memptr_t	board_addr;	/* Board's view of shared store addr */
	memptr_t	pool_addr;	/* Board's ptr to shared buf pool */
	memptr_t	xstr_addr;	/* Board's ptr to shared streams  */
	struct alloc	alloc_info;	/* Alloc_info goes here !	*/
        uint32		poll_host;      /* SW interrupt for board       */
	uint8		board_counter;  /* Board watchdog counter       */
	uint8		host_counter;   /* Host watchdog counter        */
};

struct t_info
{
	int32 t_task_id;
	int32 t_slotid;
	int32 t_queue_strm;
	int32 t_ext1;
	int32 t_ext2;
	int32 t_fd_flags;
	int32 t_flags;
	int32 t_act_type;
	int32 t_ioc_timeid;
};

struct xbus_stream {
	uint32		command;	/* Stream command		*/
	memptr_t	dataptr[NDPTR];	/* Pointer to data buffers	*/
	memlen_t	datalen[NDPTR];	/* Length of data buffers	*/
	int8		ctltype;	/* Type of control buffer	*/
	int8		blocked;	/* Stream is blocked		*/
	int8		wanted;		/* Access attempted while busy	*/
	int8		in_use;		/* Stream allocated		*/
	int8		notify;		/* Notify on completion?	*/
	int8		sleeping;
	int8		bufwant;	/* We want a buffer from this pool */
	int8		error;		/* Error return */
        int8		*queue_strm;	/* pointer to ms withg the queues */
        struct t_info	*task_ptr;	/* pointer to task specific info from ipcb */
        int8		flags;		/* flags associated with command */
};

struct xbus_bufpool {
	uint32		size;		/* Size of this buffer pool */
	int8		usedptr;
	int8		freeptr;
	int8		wanted;
	int8		recharge;
	memptr_t	poolptr[NPPTR];	/* Ptr to start of each buffer */
	uint32		poolpvt[NPPTR];	/* Private ptr for each buffer */
	int8		poolbusy[NPPTR]; /* Set when evsrvr done */

};


#define NRDY 16				/* Max no of ready streams	*/
					/* Must be 2^n 			*/

struct ready_list {
	uint8		write_ptr;		/* The slave updates this */
	uint8		read_ptr;		/* The host updates this  */
	uint8		oflow;			/* Set by slave if no room */
	uint8		pad;			/* Unused */
	uint16		rdylist[NRDY];		/* List of ready streams */
};

#define NATTN 300			/* Max no of down attentions */

struct attention_list {
	uint16	write_ptr;	/* The host updates this */
	uint16  read_ptr;	/* The slave updates this */
	uint16	attnlist[NATTN]; /* list of ready streams */
};
	

struct open_ctl {
	uint16	uid, gid;	/* From user area		*/
	uint16	ruid, rgid;	/* From user area		*/
	uint16	error;		/* To user area if != 0		*/
	uint16	pid, pgrp;	/* From proc structure		*/
	uint16	ttyval;		/* Returned *u.u_ttyp */
        int8 module[20];		/* module name for auto push */
};

/*
 * Commands
 */
#define	STE_OPEN	1
#define	STE_CLOSE	2
#define	STE_SEND	3
#define STE_MSG		4
#define STE_PUSH	5
#define STE_LINK	6
#define STE_REQ		7
#define STE_FLUSH	8
#define STE_FIND	9
#define STE_END_LINK	10
#define STE_PRINTF	11
#define STE_STRLOG	12
#define STE_CMNERR	13
#define STE_NOTIFY      95L
#define STE_READY       96L
#define STE_RETURN      97L
#define STE_DUMMY	98
#define	STE_CLEANUP	99

/*
 * Errors - these are mapped on the host side into something appropriate
 */

#define	DEV_NOT_FOUND	1000

/*
 * Ioctl values - these probably belong in another file, but never mind
 */


#define		IS_PREFIX 	106 << 8    /* NOT a printable character! */
#define		IS_LINK		(IS_PREFIX | 1)
#define		IS_PUSH		(IS_PREFIX | 2)
#define		IS_GETID	(IS_PREFIX | 3)



/*
 * Misc constants
 */

#define ASYNCHRONOUS	0
#define SYNCHRONOUS	1

#define	UNBROKEN	0
#define	BROKEN		1


extern struct xbus_bufpool *xbus_pools;

/* Macro to encode a (ring, mblk) pair */

#define FEP_BPTR(r, b) ((((r) - xbus_pools) << 8) | ((b) + 1))
#define FEP_POOL(p)  (xbus_pools + ((p) >> 8))
#define FEP_BLK(p) (((p) & 0xFF) - 1)

/* Address mapping for segmented addressing schemes */

#ifdef SEGMENTED
#define FLATTEN(x)	(((long)(x) & 0xFFFF) +\
				 ((((long)(x)) >>12) & 0xFFFF0))
#else /* SEGMENTED */
#if (PRI|POWERPC)
#define FLATTEN(x)   (0x003FFFFF & (unsigned long)x)
#else
#ifdef TWOMEG
#define FLATTEN(x)   (0x001FFFFF & (unsigned long)x)
#else
#define FLATTEN(x)   (0x000FFFFF & (unsigned long)x)
#endif /* TWOMEG */
#endif /* PRI */
#endif /*SEGMENTED */

