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