xref: /onnv-gate/usr/src/uts/sun/sys/ser_async.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1991-1998 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_SYS_SER_ASYNC_H
28*0Sstevel@tonic-gate #define	_SYS_SER_ASYNC_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate /*
33*0Sstevel@tonic-gate  * Initial port setup parameters for async lines
34*0Sstevel@tonic-gate  */
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include <sys/ksynch.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #ifdef	__cplusplus
39*0Sstevel@tonic-gate extern "C" {
40*0Sstevel@tonic-gate #endif
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate  * The following macro can be used to generate the baud rate generator's
44*0Sstevel@tonic-gate  * time constants.  The parameters are the input clock to the BRG (eg,
45*0Sstevel@tonic-gate  * 5000000 for 5MHz) and the desired baud rate.  This macro assumes that
46*0Sstevel@tonic-gate  * the clock needed is 16x the desired baud rate.
47*0Sstevel@tonic-gate  */
48*0Sstevel@tonic-gate #define	ZSTimeConst(InputClock, BaudRate) \
49*0Sstevel@tonic-gate 	(ushort_t)((((int)InputClock+(BaudRate*16)) \
50*0Sstevel@tonic-gate 	/ (2*(int)(BaudRate*16))) - 2)
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate #define	ZSDelayConst(Hertz, FifoSize, BitsByte, BaudRate) \
53*0Sstevel@tonic-gate 	(ushort_t)((((int)(Hertz)*(FifoSize)*(BitsByte)) \
54*0Sstevel@tonic-gate 	/ (int)(BaudRate)) + 1)
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate #define	ZSPEED(n)	ZSTimeConst(PCLK, n)
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate #define	ZFIFOSZ		3
59*0Sstevel@tonic-gate /*
60*0Sstevel@tonic-gate  * this macro needs a constant Hertz, but we can now have a hires_tick.
61*0Sstevel@tonic-gate  * ztdelay in zs_async.c converts to a true delay based on hz so we
62*0Sstevel@tonic-gate  * can use 100 for Hertz here.
63*0Sstevel@tonic-gate  */
64*0Sstevel@tonic-gate #define	ZDELAY(n)	ZSDelayConst(100, ZFIFOSZ, NBBY, n)
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate #define	ISPEED		B9600
67*0Sstevel@tonic-gate #define	ISPEED_SVID	B300
68*0Sstevel@tonic-gate #define	IFLAGS		(CS7|CREAD|PARENB)
69*0Sstevel@tonic-gate #define	IFLAGS_SVID	(CS8|CREAD|HUPCL)
70*0Sstevel@tonic-gate #define	I_IFLAGS	0
71*0Sstevel@tonic-gate #define	I_CFLAGS	((ISPEED << IBSHIFT) | ISPEED | CS8 | CREAD | HUPCL)
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate /*
74*0Sstevel@tonic-gate  * Ring buffer and async line management definitions for CPU lines:
75*0Sstevel@tonic-gate  */
76*0Sstevel@tonic-gate #ifdef  _KERNEL
77*0Sstevel@tonic-gate #ifndef _ASM
78*0Sstevel@tonic-gate #define	RINGBITS	8		/* # of bits in ring ptrs */
79*0Sstevel@tonic-gate #define	RINGSIZE	(1<<RINGBITS)	/* size of ring */
80*0Sstevel@tonic-gate #define	RINGMASK	(RINGSIZE-1)
81*0Sstevel@tonic-gate #define	RINGFRAC	2		/* fraction of ring to force flush */
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate #define	RING_INIT(zap)	((zap)->za_rput = (zap)->za_rget = 0)
84*0Sstevel@tonic-gate #define	RING_CNT(zap)	(((zap)->za_rput - (zap)->za_rget) & RINGMASK)
85*0Sstevel@tonic-gate #define	RING_FRAC(zap)	((int)RING_CNT(zap) >= (int)(RINGSIZE/RINGFRAC))
86*0Sstevel@tonic-gate #define	RING_POK(zap, n) ((int)RING_CNT(zap) < (int)(RINGSIZE-(n)))
87*0Sstevel@tonic-gate #define	RING_PUT(zap, c) \
88*0Sstevel@tonic-gate 	((zap)->za_ring[(zap)->za_rput++ & RINGMASK] =  (uchar_t)(c))
89*0Sstevel@tonic-gate #define	RING_UNPUT(zap)	((zap)->za_rput--)
90*0Sstevel@tonic-gate #define	RING_GOK(zap, n) ((int)RING_CNT(zap) >= (int)(n))
91*0Sstevel@tonic-gate #define	RING_GET(zap)	((zap)->za_ring[(zap)->za_rget++ & RINGMASK])
92*0Sstevel@tonic-gate #define	RING_EAT(zap, n) ((zap)->za_rget += (n))
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate /*
95*0Sstevel@tonic-gate  *  To process parity errors/breaks in-band
96*0Sstevel@tonic-gate  */
97*0Sstevel@tonic-gate #define	SBITS		8
98*0Sstevel@tonic-gate #define	S_UNMARK	0x00FF
99*0Sstevel@tonic-gate #define	S_PARERR	(0x01<<SBITS)
100*0Sstevel@tonic-gate #define	S_BREAK		(0x02<<SBITS)
101*0Sstevel@tonic-gate #define	RING_MARK(zap, c, s) \
102*0Sstevel@tonic-gate 	((zap)->za_ring[(zap)->za_rput++ & RINGMASK] = ((uchar_t)(c)|(s)))
103*0Sstevel@tonic-gate #define	RING_UNMARK(zap) \
104*0Sstevel@tonic-gate 	((zap)->za_ring[((zap)->za_rget) & RINGMASK] &= S_UNMARK)
105*0Sstevel@tonic-gate #define	RING_ERR(zap, c) \
106*0Sstevel@tonic-gate 	((zap)->za_ring[((zap)->za_rget) & RINGMASK] & (c))
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate /*
110*0Sstevel@tonic-gate  * These flags are shared with mcp_async.c and should be kept in sync.
111*0Sstevel@tonic-gate  */
112*0Sstevel@tonic-gate #define	ZAS_WOPEN	0x00000001	/* waiting for open to complete */
113*0Sstevel@tonic-gate #define	ZAS_ISOPEN	0x00000002	/* open is complete */
114*0Sstevel@tonic-gate #define	ZAS_OUT		0x00000004	/* line being used for dialout */
115*0Sstevel@tonic-gate #define	ZAS_CARR_ON	0x00000008	/* carrier on last time we looked */
116*0Sstevel@tonic-gate #define	ZAS_STOPPED	0x00000010	/* output is stopped */
117*0Sstevel@tonic-gate #define	ZAS_DELAY	0x00000020	/* waiting for delay to finish */
118*0Sstevel@tonic-gate #define	ZAS_BREAK	0x00000040	/* waiting for break to finish */
119*0Sstevel@tonic-gate #define	ZAS_BUSY	0x00000080	/* waiting for transmission to finish */
120*0Sstevel@tonic-gate #define	ZAS_DRAINING	0x00000100	/* waiting for output to drain */
121*0Sstevel@tonic-gate 					/* from chip */
122*0Sstevel@tonic-gate #define	ZAS_SERVICEIMM	0x00000200	/* queue soft interrupt as soon as */
123*0Sstevel@tonic-gate 					/* receiver interrupt occurs */
124*0Sstevel@tonic-gate #define	ZAS_SOFTC_ATTN	0x00000400	/* check soft carrier state in close */
125*0Sstevel@tonic-gate #define	ZAS_PAUSED	0x00000800	/* MCP: dma interrupted and pending */
126*0Sstevel@tonic-gate #define	ZAS_LNEXT	0x00001000	/* MCP: next input char is quoted */
127*0Sstevel@tonic-gate #define	ZAS_XMIT_ACTIVE	0x00002000	/* MCP: Transmit dma running */
128*0Sstevel@tonic-gate #define	ZAS_DMA_DONE	0x00004000	/* MCP: DMA done interrupt received */
129*0Sstevel@tonic-gate #define	ZAS_ZSA_START	0x00010000	/* MCP: DMA done interrupt received */
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate /*
133*0Sstevel@tonic-gate  * Asynchronous protocol private data structure for ZS and MCP/ALM2
134*0Sstevel@tonic-gate  */
135*0Sstevel@tonic-gate #define	ZSA_MIN_RSTANDBY	12
136*0Sstevel@tonic-gate #define	ZSA_MAX_RSTANDBY	256
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate #define	ZSA_RDONE_MIN		60
139*0Sstevel@tonic-gate #define	ZSA_RDONE_MAX		350
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate struct asyncline {
142*0Sstevel@tonic-gate 	int		za_flags;	/* random flags */
143*0Sstevel@tonic-gate 	kcondvar_t	za_flags_cv;	/* condition variable for flags */
144*0Sstevel@tonic-gate 	dev_t		za_dev;		/* device major/minor numbers */
145*0Sstevel@tonic-gate 	mblk_t		*za_xmitblk;	/* transmit: active msg block */
146*0Sstevel@tonic-gate 	mblk_t		*za_rcvblk;	/* receive: active msg block */
147*0Sstevel@tonic-gate 	struct zscom	*za_common;	/* device common data */
148*0Sstevel@tonic-gate 	tty_common_t	za_ttycommon;	/* tty driver common data */
149*0Sstevel@tonic-gate 	bufcall_id_t	za_wbufcid;	/* id of pending write-side bufcall */
150*0Sstevel@tonic-gate 	timeout_id_t	za_polltid;	/* softint poll timeout id */
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate 	/*
153*0Sstevel@tonic-gate 	 * The following fields are protected by the zs_excl_hi lock.
154*0Sstevel@tonic-gate 	 * Some, such as za_flowc, are set only at the base level and
155*0Sstevel@tonic-gate 	 * cleared (without the lock) only by the interrupt level.
156*0Sstevel@tonic-gate 	 */
157*0Sstevel@tonic-gate 	uchar_t		*za_optr;	/* output pointer */
158*0Sstevel@tonic-gate 	int		za_ocnt;	/* output count */
159*0Sstevel@tonic-gate 	uchar_t		za_rput;	/* producing pointer for input */
160*0Sstevel@tonic-gate 	uchar_t		za_rget;	/* consuming pointer for input */
161*0Sstevel@tonic-gate 	uchar_t		za_flowc;	/* flow control char to send */
162*0Sstevel@tonic-gate 	uchar_t		za_rr0;		/* status latch for break detection */
163*0Sstevel@tonic-gate 	/*
164*0Sstevel@tonic-gate 	 * Each character stuffed into the ring has two bytes associated
165*0Sstevel@tonic-gate 	 * with it.  The first byte is used to indicate special conditions
166*0Sstevel@tonic-gate 	 * and the second byte is the actual data.  The ring buffer
167*0Sstevel@tonic-gate 	 * needs to be defined as ushort_t to accomodate this.
168*0Sstevel@tonic-gate 	 */
169*0Sstevel@tonic-gate 	ushort_t 	za_ring[RINGSIZE];
170*0Sstevel@tonic-gate 	timeout_id_t	za_kick_rcv_id;
171*0Sstevel@tonic-gate 	int 		za_kick_rcv_count;
172*0Sstevel@tonic-gate 	timeout_id_t	za_zsa_restart_id;
173*0Sstevel@tonic-gate 	bufcall_id_t	za_bufcid;
174*0Sstevel@tonic-gate 	mblk_t		*za_rstandby[ZSA_MAX_RSTANDBY];
175*0Sstevel@tonic-gate 					/* receive: standby message blocks */
176*0Sstevel@tonic-gate 	mblk_t		*za_rdone[ZSA_RDONE_MAX];
177*0Sstevel@tonic-gate 					/* complete messages to be sent up */
178*0Sstevel@tonic-gate 	int		za_rdone_wptr;
179*0Sstevel@tonic-gate 	int		za_rdone_rptr;
180*0Sstevel@tonic-gate 	int		za_bad_count_int;
181*0Sstevel@tonic-gate 	uint_t		za_rcv_flags_mask;
182*0Sstevel@tonic-gate #ifdef ZSA_DEBUG
183*0Sstevel@tonic-gate 	int		za_wr;
184*0Sstevel@tonic-gate 	int		za_rd;
185*0Sstevel@tonic-gate #endif
186*0Sstevel@tonic-gate 	volatile uchar_t za_soft_active;
187*0Sstevel@tonic-gate 	volatile uchar_t za_kick_active;
188*0Sstevel@tonic-gate #define	DO_STOPC	(1<<8)
189*0Sstevel@tonic-gate #define	DO_ESC		(1<<9)
190*0Sstevel@tonic-gate #define	DO_SERVICEIMM	(1<<10)
191*0Sstevel@tonic-gate #define	DO_TRANSMIT	(1<<11)
192*0Sstevel@tonic-gate #define	DO_RETRANSMIT	(1<<12)
193*0Sstevel@tonic-gate /*
194*0Sstevel@tonic-gate  * ZS exclusive stuff.
195*0Sstevel@tonic-gate  */
196*0Sstevel@tonic-gate 	short		za_break;	/* break count */
197*0Sstevel@tonic-gate 	union {
198*0Sstevel@tonic-gate 		struct {
199*0Sstevel@tonic-gate 			uchar_t  _hw;    /* overrun (hw) */
200*0Sstevel@tonic-gate 			uchar_t  _sw;    /* overrun (sw) */
201*0Sstevel@tonic-gate 		} _z;
202*0Sstevel@tonic-gate 		ushort_t uover_overrun;
203*0Sstevel@tonic-gate 	} za_uover;
204*0Sstevel@tonic-gate #define	za_overrun	za_uover.uover_overrun
205*0Sstevel@tonic-gate #define	za_hw_overrun	za_uover._z._hw
206*0Sstevel@tonic-gate #define	za_sw_overrun	za_uover._z._sw
207*0Sstevel@tonic-gate 	short		za_ext;		/* modem status change count */
208*0Sstevel@tonic-gate 	short		za_work;	/* work to do flag */
209*0Sstevel@tonic-gate 	short		za_grace_flow_control;
210*0Sstevel@tonic-gate 	uchar_t		za_do_kick_rcv_in_softint;
211*0Sstevel@tonic-gate 	uchar_t		za_m_error;
212*0Sstevel@tonic-gate /*
213*0Sstevel@tonic-gate  * MCP exclusive stuff.
214*0Sstevel@tonic-gate  * These should all be protected by a high priority lock.
215*0Sstevel@tonic-gate  */
216*0Sstevel@tonic-gate 	uchar_t		*za_xoff;	/* xoff char in h/w XOFF buffer */
217*0Sstevel@tonic-gate 	uchar_t		za_lnext;	/* treat next char as literal */
218*0Sstevel@tonic-gate 	uchar_t		*za_devctl;	/* device control reg for this port */
219*0Sstevel@tonic-gate 	uchar_t		*za_dmabuf;	/* dma ram buffer for this port */
220*0Sstevel@tonic-gate 	int		za_breakoff;	/* SLAVIO */
221*0Sstevel@tonic-gate 	int		za_slav_break;	/* SLAVIO */
222*0Sstevel@tonic-gate /*
223*0Sstevel@tonic-gate  * NTP PPS exclusive stuff.
224*0Sstevel@tonic-gate  */
225*0Sstevel@tonic-gate 	short		za_pps;		/* PPS on? */
226*0Sstevel@tonic-gate };
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate #endif /* _ASM */
229*0Sstevel@tonic-gate #endif /* _KERNEL */
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate #ifdef	__cplusplus
232*0Sstevel@tonic-gate }
233*0Sstevel@tonic-gate #endif
234*0Sstevel@tonic-gate 
235*0Sstevel@tonic-gate #endif	/* !_SYS_SER_ASYNC_H */
236