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