/*
	     SIEMENS Semiconductor Group, ICs for Communications
			 Communication Networks
			    Device Driver Module
		       Copyright (c) SIEMENS AG	 1994

    Project		  MUNICH32
    Module		  MUNICH32
    File		  MUNICH32.H

     Description	   Definitions for MUNICH32.C

     Version		   1.0
     Revision		   1.0
     Date		   August 15, 1994
     Tools		   Compiler: 68000
			   Linker  : 68000
     Memory Model

   Department		 SIEMENS AG, HL	EZM D24
   Responsible		 Reinhard Lipfert
			 Thomas	Feiten

*/

/**************************************************************************
 *
 *
 *	SIEMENS	MUNICH DRIVER
 *
 *	This driver is used to control the Munich32 Multichannel HDLC
 *	controller from	Siemens.
 *
 *	These procedures are called from the Spider Hardware abstraction
 *	layer. (HD).
 *
 *
 **************************************************************************/

 /****************************************************************************
 * 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 of	Digi International  *
 * Inc.	 Except	as permitted by	federal	law, 17	USC 117, copying is strictly*
 * prohibited.								    *
 * Copyright 1995, Digi	International Inc.				    *
 * All rights reserved.							    *
 *	 %W%I
 ****************************************************************************/

#include "m32api.h"

/*
 * MUNICH Control Vector Addresses
 */

#define	MUNICH_CTRL_VECTOR_BASE	0xA03FFFF0

#define	MUNICH32_CTRL_VECTOR_1 (uint32 *)(MUNICH_CTRL_VECTOR_BASE + 0xC)
#define	MUNICH32_CTRL_VECTOR_2 (uint32 *)(MUNICH_CTRL_VECTOR_BASE + 0x8)
#define	MUNICH32_CTRL_VECTOR_3 (uint32 *)(MUNICH_CTRL_VECTOR_BASE + 0x4)
#define	MUNICH32_CTRL_VECTOR_4 (uint32 *)(MUNICH_CTRL_VECTOR_BASE + 0x0)

#define	MUNICH32_ACTION_REQ_STROBE_1 (uint32 *)(0xA2070000)
#define	MUNICH32_ACTION_REQ_STROBE_2 (uint32 *)(0xA2070008)
#define	MUNICH32_ACTION_REQ_STROBE_3 (uint32 *)(0x0)
#define	MUNICH32_ACTION_REQ_STROBE_4 (uint32 *)(0x0)

#define	NUM_WAIT_ACTION_TICKS	(2*HZ)
#define	NUM_ABORT_TO_DISC_TICKS	2
#define	IHD_POLL_PERIOD		1
#define	NUM_CTRLS	2

#define	 INT_SPEC_MASK			     0x07FFFFE0L

#define	 INT				     0x80000000L
#define	 V21				     0x08000000L
#define	 FRC				     0x04000000L
#define	 E7				     0x02000000L
#define	 E6				     0x01000000L
#define	 E5				     0x00800000L
#define	 E4				     0x00400000L
#define	 E3				     0x00200000L
#define	 E2				     0x00100000L
#define	 E1				     0x00080000L
#define	 SA				     0x00040000L
#define	 SB				     0x00020000L
#define	 X				     0x00010000L
#define	 ARACK				     0x00008000L
#define	 ARF				     0x00004000L
#define	 HI				     0x00002000L
#define	 FI				     0x00001000L
#define	 IFC				     0x00000800L
#define	 SF				     0x00000400L
#define	 ERR				     0x00000200L
#define	 FO				     0x00000100L
#define	 RT				     0x00000020L


#define	 CLEAR				     0
#define	 SET				     1
#define	 INT_QUEUE_SIZE_MAX		     4096
#define	 MAXIMUM_FRAME_LENGTH_MAX	     8191
#define	 TX_DESC_MAX			     16
#define	 RX_DESC_MAX			     16

#define	 PCM_T1_DS1_24_CHANNELS_1_536M	     0	     /*	PCM highway formats */
#define	 PCM_T1_DS1_24_CHANNELS_1_544M	     4
#define	 PCM_CEPT_32_CHANNELS_2_048M	     5
#define	 PCM_CEPT_32_CHANNELS_4_096M_EVEN    6
#define	 PCM_CEPT_32_CHANNELS_4_096M_ODD     7

#define  BROADCAST_POWER_UP		     1
#define  BROADCAST_POWER_DOWN		     2

/*
 *  MUNICH32 Transmit Descriptor Structures
 */

#define	WORD8	uint8
#define	WORD16	uint16
#define	WORD32	uint32

/*
Bitmap equivalents:
MUNICHTXDESCR_FE	10000000000000000000000000000000b
MUNICHTXDESCR_HOLD	01000000000000000000000000000000b
MUNICHTXDESCR_HI	00100000000000000000000000000000b
MUNICHTXDESCR_NO	00011111111111110000000000000000b
MUNICHTXDESCR_V110	00000000000000001000000000000000b
MUNICHTXDESCR_CSM	00000000000000000000100000000000b
MUNICHTXDESCR_FNUM	00000000000000000000011111111111b
*/
#define	MUNICHTXDESCR_FE	0x80000000
#define	MUNICHTXDESCR_HOLD	0x40000000
#define	MUNICHTXDESCR_HI	0x20000000
#define	MUNICHTXDESCR_NO	0x1FFF0000
#define	MUNICHTXDESCR_V110	0x00008000
#define	MUNICHTXDESCR_CSM	0x00000800
#define	MUNICHTXDESCR_FNUM	0x000007FF

typedef	 struct	     munichTxDescr
{
   uint32			command;
   WORD8			*data;
   struct munichTxDescr		*next;
}
MUNICH_TRANSMIT_DESCRIPTOR;

typedef	MUNICH_TRANSMIT_DESCRIPTOR *MUNICH_TX_DESCR_PTR;

/*
   MUNICH32 Receive Descriptor Structures
*/

/*
Bitmap equivalents:
MUNICHRXDESCR_HOLD	01000000000000000000000000000000b
MUNICHRXDESCR_HI	00100000000000000000000000000000b
MUNICHRXDESCR_NO	00011111111111110000000000000000b
MUNICHRXDESCR_FE	10000000000000000000000000000000b
MUNICHRXDESCR_C		01000000000000000000000000000000b
MUNICHRXDESCR_BNO	00011111111111110000000000000000b
MUNICHRXDESCR_STATUS	00000000000000001111111100000000b
*/
#define	MUNICHRXDESCR_HOLD	0x40000000
#define	MUNICHRXDESCR_HI	0x20000000
#define	MUNICHRXDESCR_NO	0x1FFF0000
#define	MUNICHRXDESCR_FE	0x80000000
#define	MUNICHRXDESCR_C		0x40000000
#define	MUNICHRXDESCR_BNO	0x1FFF0000
/*
 * SF status bit does not imply a corruption of data.
 * Therefore, it shall not be included in the mask.
 */
#define	MUNICHRXDESCR_STATUS	0x0000BF00
#define	MUNICHRXDESCR_SF	0x00004000
#define	MUNICHRXDESCR_LOSS	0x00002000
#define	MUNICHRXDESCR_CRCO	0x00001000
#define	MUNICHRXDESCR_NOB	0x00000800
#define	MUNICHRXDESCR_LFD	0x00000400
#define	MUNICHRXDESCR_RA	0x00000200
#define	MUNICHRXDESCR_ROF	0x00000100

typedef	 struct	     munichRcDescr
{
   uint32			 command ;
   uint32			 status	;
   WORD8			*data;
   struct munichRcDescr		*next;
}
MUNICH_RECEIVE_DESCRIPTOR;

typedef	MUNICH_RECEIVE_DESCRIPTOR *MUNICH_RC_DESCR_PTR;

/*
   MUNICH32 Structures
*/

/*
Bitmap equivalents:
MUNICHINTQUEUE_INTFLAG	 10000000000000000000000000000000b
MUNICHINTQUEUE_VN	 00111000000000000000000000000000b
MUNICHINTQUEUE_FRC	 00000100000000000000000000000000b
MUNICHINTQUEUE_E7	 00000010000000000000000000000000b
MUNICHINTQUEUE_E6	 00000001000000000000000000000000b
MUNICHINTQUEUE_E5	 00000000100000000000000000000000b
MUNICHINTQUEUE_E4	 00000000010000000000000000000000b
MUNICHINTQUEUE_E3	 00000000001000000000000000000000b
MUNICHINTQUEUE_E2	 00000000000100000000000000000000b
MUNICHINTQUEUE_E1	 00000000000010000000000000000000b
MUNICHINTQUEUE_SA	 00000000000001000000000000000000b
MUNICHINTQUEUE_SB	 00000000000000100000000000000000b
MUNICHINTQUEUE_X	 00000000000000010000000000000000b
MUNICHINTQUEUE_ARACK	 00000000000000001000000000000000b
MUNICHINTQUEUE_ARF	 00000000000000000100000000000000b
MUNICHINTQUEUE_HI	 00000000000000000010000000000000b
MUNICHINTQUEUE_FI	 00000000000000000001000000000000b
MUNICHINTQUEUE_IFC	 00000000000000000000100000000000b
MUNICHINTQUEUE_SF	 00000000000000000000010000000000b
MUNICHINTQUEUE_ERR	 00000000000000000000001000000000b
MUNICHINTQUEUE_FO	 00000000000000000000000100000000b
MUNICHINTQUEUE_RT	 00000000000000000000000000100000b
MUNICHINTQUEUE_CHNUM	 00000000000000000000000000011111b
*/
#define	MUNICHINTQUEUE_INTFLAG	 0x80000000
#define	MUNICHINTQUEUE_VN	 0x38000000
#define	MUNICHINTQUEUE_FRC	 0x04000000
#define	MUNICHINTQUEUE_E7	 0x02000000
#define	MUNICHINTQUEUE_E6	 0x01000000
#define	MUNICHINTQUEUE_E5	 0x00800000
#define	MUNICHINTQUEUE_E4	 0x00400000
#define	MUNICHINTQUEUE_E3	 0x00200000
#define	MUNICHINTQUEUE_E2	 0x00100000
#define	MUNICHINTQUEUE_E1	 0x00080000
#define	MUNICHINTQUEUE_SA	 0x00040000
#define	MUNICHINTQUEUE_SB	 0x00020000
#define	MUNICHINTQUEUE_X	 0x00010000
#define	MUNICHINTQUEUE_ARACK	 0x00008000
#define	MUNICHINTQUEUE_ARF	 0x00004000
#define	MUNICHINTQUEUE_HI	 0x00002000
#define	MUNICHINTQUEUE_FI	 0x00001000
#define	MUNICHINTQUEUE_IFC	 0x00000800
#define	MUNICHINTQUEUE_SF	 0x00000400
#define	MUNICHINTQUEUE_ERR	 0x00000200
#define	MUNICHINTQUEUE_FO	 0x00000100
#define	MUNICHINTQUEUE_RT	 0x00000020
#define	MUNICHINTQUEUE_CHNUM	 0x0000001F

#define	MUNICHINTQUEUE_ESXBITS	 MUNICHINTQUEUE_E7 + MUNICHINTQUEUE_E6 + \
				 MUNICHINTQUEUE_E5 + MUNICHINTQUEUE_E4 + \
				 MUNICHINTQUEUE_E3 + MUNICHINTQUEUE_E2 + \
				 MUNICHINTQUEUE_E1 + \
				 MUNICHINTQUEUE_SA + MUNICHINTQUEUE_SB + \
				 MUNICHINTQUEUE_X

typedef	 struct
{
	uint32		command	;
}
MUNICH32_INTERRUPT_QUEUE;


typedef	 struct
{
   MUNICH32_INTERRUPT_QUEUE  *addr;
   uint32		      n	;
}
INTERRUPT_QUEUE_SPECIFICATION;

/*
Bitmap equivalents:
MUNICHTIMESLOTASSIGNMENT_TTI	     00100000000000000000000000000000b
MUNICHTIMESLOTASSIGNMENT_TXCHANNUM   00011111000000000000000000000000b
MUNICHTIMESLOTASSIGNMENT_TXFILLMASK  00000000111111110000000000000000b
MUNICHTIMESLOTASSIGNMENT_RTI	     00000000000000000010000000000000b
MUNICHTIMESLOTASSIGNMENT_RXCHANNUM   00000000000000000001111100000000b
MUNICHTIMESLOTASSIGNMENT_RXFILLMASK  00000000000000000000000011111111b
*/
#define	MUNICHTIMESLOTASSIGNMENT_TTI	     0x20000000
#define	MUNICHTIMESLOTASSIGNMENT_TXCHANNUM   0x1F000000
#define	MUNICHTIMESLOTASSIGNMENT_TXFILLMASK  0x00FF0000
#define	MUNICHTIMESLOTASSIGNMENT_RTI	     0x00002000
#define	MUNICHTIMESLOTASSIGNMENT_RXCHANNUM   0x00001F00
#define	MUNICHTIMESLOTASSIGNMENT_RXFILLMASK  0x000000FF

typedef	 struct
{
	uint32		command	;
}
TIME_SLOT_ASSIGNMENT;

/*
Bitmap equivalents:
MUNICHHANNELSPEC_INTMASK 11111111000000000000000000000000b
MUNICHHANNELSPEC_MSK_SFE 01000000000000000000000000000000b
MUNICHHANNELSPEC_MSK_IFC 00100000000000000000000000000000b
MUNICHHANNELSPEC_MSK_CH  00010000000000000000000000000000b
MUNICHHANNELSPEC_MSK_TE  00001000000000000000000000000000b
MUNICHHANNELSPEC_MSK_RE  00000100000000000000000000000000b
MUNICHHANNELSPEC_MSK_FIR 00000010000000000000000000000000b
MUNICHHANNELSPEC_MSK_FIT 00000001000000000000000000000000b
MUNICHHANNELSPEC_NITBS	 00000000100000000000000000000000b
MUNICHHANNELSPEC_RI	 00000000010000000000000000000000b
MUNICHHANNELSPEC_TI	 00000000001000000000000000000000b
MUNICHHANNELSPEC_TO	 00000000000100000000000000000000b
MUNICHHANNELSPEC_TA	 00000000000010000000000000000000b
MUNICHHANNELSPEC_TH	 00000000000001000000000000000000b
MUNICHHANNELSPEC_RO	 00000000000000100000000000000000b
MUNICHHANNELSPEC_RA	 00000000000000010000000000000000b
MUNICHHANNELSPEC_TFLAG	 00000000000000001111111000000000b
MUNICHHANNELSPEC_TFLAGCS 00000000000000000000000100000000b
MUNICHHANNELSPEC_INV	 00000000000000000000000010000000b
MUNICHHANNELSPEC_CRC	 00000000000000000000000001000000b
MUNICHHANNELSPEC_TRV	 00000000000000000000000000110000b
MUNICHHANNELSPEC_FA	 00000000000000000000000000001000b
MUNICHHANNELSPEC_MODE	 00000000000000000000000000000110b
MUNICHHANNELSPEC_IFTF	 00000000000000000000000000000001b
MUNICHHANNELSPEC_ITBS	 00000000000000000000000000111111b
*/
#define	MUNICHHANNELSPEC_INTMASK 0xFF000000
#define MUNICHHANNELSPEC_MSK_SFE 0x40000000
#define MUNICHHANNELSPEC_MSK_IFC 0x20000000
#define MUNICHHANNELSPEC_MSK_CH  0x10000000
#define MUNICHHANNELSPEC_MSK_TE  0x08000000
#define MUNICHHANNELSPEC_MSK_RE  0x04000000
#define MUNICHHANNELSPEC_MSK_FIR 0x02000000
#define MUNICHHANNELSPEC_MSK_FIT 0x01000000
#define	MUNICHHANNELSPEC_NITBS	 0x00800000
#define	MUNICHHANNELSPEC_RI	 0x00400000
#define	MUNICHHANNELSPEC_TI	 0x00200000
#define	MUNICHHANNELSPEC_TO	 0x00100000
#define	MUNICHHANNELSPEC_TA	 0x00080000
#define	MUNICHHANNELSPEC_TH	 0x00040000
#define	MUNICHHANNELSPEC_RO	 0x00020000
#define	MUNICHHANNELSPEC_RA	 0x00010000
#define	MUNICHHANNELSPEC_TFLAG	 0x0000FE00
#define	MUNICHHANNELSPEC_TFLAGCS 0x00000100
#define	MUNICHHANNELSPEC_INV	 0x00000080
#define	MUNICHHANNELSPEC_CRC	 0x00000040
#define	MUNICHHANNELSPEC_TRV	 0x00000030
#define	MUNICHHANNELSPEC_FA	 0x0000000F
#define	MUNICHHANNELSPEC_MODE	 0x00000006
#define	MUNICHHANNELSPEC_IFTF	 0x00000001
#define	MUNICHHANNELSPEC_ITBS	 0x0000003F

typedef	 struct
{
   uint32		   command ;
   MUNICH_RC_DESCR_PTR	   frda	;
   MUNICH_TX_DESCR_PTR	   ftda	;
   uint32		   itbs	;
}
CHANNEL_SPECIFICATION;

typedef	 struct
{
   WORD32			    *currentReceiveDescriptorAddrCh;
}
CURRENT_RC_DESCR_ADDR;

typedef	 struct
{
   WORD32			    *currentTransmitDescriptorAddrCh;
}
CURRENT_TX_DESCR_ADDR;

/*
Bitmap equivalents:
MUNICHACTIONSPEC_PCM	11100000000000000000000000000000b
MUNICHACTIONSPEC_MFL	00011111111111110000000000000000b
MUNICHACTIONSPEC_IN	00000000000000001000000000000000b
MUNICHACTIONSPEC_ICO	00000000000000000100000000000000b
MUNICHACTIONSPEC_CHNUM	00000000000000000001111100000000b
MUNICHACTIONSPEC_IM	00000000000000000000000010000000b
MUNICHACTIONSPEC_RES	00000000000000000000000001000000b
MUNICHACTIONSPEC_LOC	00000000000000000000000000100000b
MUNICHACTIONSPEC_LOOP	00000000000000000000000000010000b
MUNICHACTIONSPEC_LOOPI	00000000000000000000000000001000b
MUNICHACTIONSPEC_IA	00000000000000000000000000000100b
*/
#define	MUNICHACTIONSPEC_PCM	0xE0000000
#define	MUNICHACTIONSPEC_MFL	0x1FFF0000
#define	MUNICHACTIONSPEC_IN	0x00008000
#define	MUNICHACTIONSPEC_ICO	0x00004000
#define	MUNICHACTIONSPEC_CHNUM	0x00001F00
#define	MUNICHACTIONSPEC_IM	0x00000080
#define	MUNICHACTIONSPEC_RES	0x00000040
#define	MUNICHACTIONSPEC_LOC	0x00000020
#define	MUNICHACTIONSPEC_LOOP	0x00000010
#define	MUNICHACTIONSPEC_LOOPI	0x00000008
#define	MUNICHACTIONSPEC_IA	0x00000004

typedef	 struct
{
	uint32		command	;
}
ACTION_SPECIFICATION;




/*
   MUNICH32 Control Block
*/

typedef	 struct
{
   ACTION_SPECIFICATION		    actionSpec;
   INTERRUPT_QUEUE_SPECIFICATION    intQueueSpec;
   TIME_SLOT_ASSIGNMENT		    timeSlot	    [ MUNICH32_CHANNELS_MAX ];
   CHANNEL_SPECIFICATION	    channelSpec	    [ MUNICH32_CHANNELS_MAX ];
   MUNICH_RC_DESCR_PTR		    currRcDescrAddr [ MUNICH32_CHANNELS_MAX ];
   MUNICH_TX_DESCR_PTR		    currTxDescrAddr [ MUNICH32_CHANNELS_MAX ];
}
MUNICH32_CTRL_CFG_SECTION;

/*
   Munich32 coniguration structure
*/

typedef	 struct
{
   WORD16		pcm;
   WORD16		mfl;
}
M32_CFG;


#define	RX_IWAN_MAX		32

/*
 * State values
 */

#define	TX_ACTIVE		0x0001
#define	RX_ACTIVE		0x0002
#define	RX_REFRESH_REQ		0x0004
#define	RX_INITIALIZING		0x0008
#define	TX_BLOCKED		0x0010

/*
 * Descriptor States
 */

#define	VALID_MESSAGE_BLOCK	4

typedef	struct hd_rx {
	mblk_t *rr_mp ;
	int	rr_v110_rx_esx ;
} hd_rx_t ;

typedef	struct rx_desc_array {
	mblk_t		*mp ;
	MUNICH_RECEIVE_DESCRIPTOR	*desc_p	;
	int		 desc_state ;
} rx_desc_array_t ;

typedef	struct tx_desc_array {
	mblk_t		*mp ;
	MUNICH_TRANSMIT_DESCRIPTOR	*desc_p	;
	int		 count ;
	int		 v110_data ;
	int		 state ;
} tx_desc_array_t ;

typedef	struct iwan_channel_struct {
	int state ;
	int ctrl_num ;
	int channel ;
	MUNICH32_CTRL_CFG_SECTION *munich_cfg ;
	int v110_rx_esx	;
	caddr_t wanp;

	int hd_head ;
	int hd_tail ;

	hd_rx_t	hd_rx_array[RX_IWAN_MAX] ;

	int rx_tail ;
	int rx_chan_num_mask ;
	uint32 default_rx_desc ;
	uint32 default_buf_len ;
	uint32 max_frame_len ;
	uint32 timeslot_mask ;
	int refresh_rx_desc ;

	rx_desc_array_t	rx_desc_array_s[RX_DESC_MAX] ;

	int tx_head ;
	int tx_tail ;

	tx_desc_array_t	 tx_desc_array_s[TX_DESC_MAX] ;

	connect_cfg_t connect_cfg;
	iwan_channel_stats_t stats ;

} iwan_channel_t ;

#define	V110_DATA	2

typedef	struct	int_stats {
	int	command_err ;
	int	command_success	;
	int	command_timeout	;
} interrupt_stats_t ;

typedef struct intptr_info {
	MUNICH32_INTERRUPT_QUEUE *current;
	MUNICH32_INTERRUPT_QUEUE *first;
	MUNICH32_INTERRUPT_QUEUE *last;
} intptr_info_t;
