xref: /illumos-gate/usr/src/uts/common/sys/ser_sync.h (revision bd97c7ce2344fa3252d8785c35895490916bc79b)
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,1997-1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_SYS_SER_SYNC_H
28 #define	_SYS_SER_SYNC_H
29 
30 /*
31  * Initial port setup parameters for sync lines
32  */
33 
34 #include <sys/stream.h>
35 #include <sys/time_impl.h>
36 #include <sys/ioccom.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #define	zIOC	('z' << 8)
43 
44 #define	S_IOCGETMODE	(zIOC|01)	/* return struct scc_mode */
45 #define	S_IOCSETMODE	(zIOC|02)	/* set SCC from struct scc_mode */
46 #define	S_IOCGETSTATS	(zIOC|03)	/* return sync data stats */
47 #define	S_IOCCLRSTATS	(zIOC|04)	/* clear sync stats */
48 #define	S_IOCGETSPEED	(zIOC|05)	/* return int baudrate */
49 #define	S_IOCGETMRU	(zIOC|06)	/* return int max receive unit */
50 #define	S_IOCSETMRU	(zIOC|07)	/* set max receive unit */
51 #define	S_IOCGETMTU	(zIOC|010)	/* return int max transmission unit */
52 #define	S_IOCSETMTU	(zIOC|011)	/* set max transmission unit */
53 #define	S_IOCGETMCTL	(zIOC|012)	/* return current CD/CTS state */
54 #define	S_IOCSETDTR	(zIOC|013)	/* Drive DTR signal */
55 
56 /* reason codes for IOCSETMODE */
57 #define	SMERR_TXC	0x0001		/* transmit clock source not valid */
58 #define	SMERR_RXC	0x0002		/* receive clock source not valid */
59 #define	SMERR_IFLAGS	0x0004		/* inversion flags not valid */
60 #define	SMERR_HDX	0x0008		/* CONN_HDX set without CONN_IBM */
61 #define	SMERR_MPT	0x0010		/* CONN_MPT set without CONN_IBM */
62 #define	SMERR_LPBKS	0x0020		/* invalid loopback/echo combination */
63 #define	SMERR_BAUDRATE	0x0040		/* baudrate translates to 0 timeconst */
64 #define	SMERR_PLL	0x0080		/* PLL set with BRG or w/o NRZI */
65 
66 /*
67  * Definitions for modes of operations of
68  * synchronous lines, both RS-232 and RS-449
69  */
70 struct scc_mode {
71 	char	sm_txclock;	/* enum - transmit clock sources */
72 	char	sm_rxclock;	/* enum - receive clock sources */
73 	char    sm_iflags;	/* data and clock invert flags: see hsparam.h */
74 	uchar_t	sm_config;	/* see CONN defines below */
75 	int	sm_baudrate;
76 	int	sm_retval;	/* SMERR codes go here, query with GETMODE */
77 };
78 
79 /*
80  * defines for txclock
81  */
82 #define	TXC_IS_TXC	0	/* use incoming transmit clock */
83 #define	TXC_IS_RXC	1	/* use incoming receive clock */
84 #define	TXC_IS_BAUD	2	/* use baud rate generator */
85 #define	TXC_IS_PLL	3	/* use phase-lock loop output */
86 
87 /*
88  * defines for rxclock
89  */
90 #define	RXC_IS_RXC	0	/* use incoming receive clock */
91 #define	RXC_IS_TXC	1	/* use incoming transmit clock */
92 #define	RXC_IS_BAUD	2	/* use baud rate - only good for loopback */
93 #define	RXC_IS_PLL	3	/* use phase-lock loop */
94 
95 /*
96  * defines for clock/data inversion: from hsparam.h
97  */
98 #define	TXC_IS_SYSCLK	4
99 #define	RXC_IS_SYSCLK	4
100 #define	TXC_IS_INVERT	5
101 #define	RXC_IS_INVERT	5
102 #define	TRXD_NO_INVERT	0
103 #define	RXD_IS_INVERT	1
104 #define	TXD_IS_INVERT	2
105 #define	TRXD_IS_INVERT	3
106 
107 /*
108  * defines for config
109  */
110 #define	CONN_HDX    0x01    /* half-duplex if set, else full-duplex */
111 #define	CONN_MPT    0x02    /* multipoint if set, else point-point */
112 #define	CONN_IBM    0x04    /* set up in IBM-SDLC mode */
113 #define	CONN_SIGNAL 0x08    /* report modem signal changes asynchronously */
114 #define	CONN_NRZI   0x10    /* boolean - use NRZI */
115 #define	CONN_LPBK   0x20    /* do internal loopback */
116 #define	CONN_ECHO   0x40    /* place in auto echo mode */
117 
118 struct sl_status {
119 	int		type;
120 	int		status;
121 	timestruc_t	tstamp;
122 };
123 
124 #if defined(_SYSCALL32)
125 
126 struct sl_status32 {
127 	int32_t		type;
128 	int32_t		status;
129 	timestruc32_t	tstamp;
130 };
131 
132 #endif	/* _SYSCALL32 */
133 
134 /*
135  * defines for type field in sl_status
136  */
137 #define	SLS_MDMSTAT	0x01	/* Non-IBM modem line status change */
138 #define	SLS_LINKERR	0x02	/* IBM mode Link Error, usually modem line. */
139 
140 /*
141  * defines for status field in sl_status
142  * DO NOT change the values for CS_(DCD|CTS)_(UP|DOWN)!!!
143  */
144 #define	CS_DCD_DOWN   	0x08
145 #define	CS_DCD_UP   	0x0c
146 #define	CS_DCD_DROP   	0x10
147 #define	CS_CTS_DOWN	0x20
148 #define	CS_CTS_UP	0x30
149 #define	CS_CTS_DROP   	0x40
150 #define	CS_CTS_TO   	0x80
151 #define	CS_DCD		CS_DCD_DOWN
152 #define	CS_CTS		CS_CTS_DOWN
153 
154 /*
155  * Event statistics reported by hardware.
156  */
157 struct sl_stats {
158 	int	ipack;		/* input packets */
159 	int	opack;		/* output packets */
160 	int	ichar;		/* input bytes */
161 	int	ochar;		/* output bytes */
162 	int	abort;		/* abort received */
163 	int	crc;		/* CRC error */
164 	int	cts;		/* CTS timeouts */
165 	int	dcd;		/* Carrier drops */
166 	int	overrun;	/* receiver overrun */
167 	int	underrun;	/* xmitter underrun */
168 	int	ierror;		/* input error (rxbad) */
169 	int	oerror;		/* output error (watchdog timeout) */
170 	int	nobuffers;	/* no active receive block available */
171 };
172 
173 
174 
175 /*
176  * Per-stream structure.  Each of these points to only one device instance,
177  * but there may be more than one doing so.  If marked as ST_CLONE, it has
178  * been opened throught the clone device, and cannot have the data path.
179  */
180 struct ser_str {
181 	queue_t		*str_rq;	/* This stream's read queue */
182 	caddr_t		str_com;	/* Back pointer to device struct */
183 	int		str_inst;	/* Device instance (unit) number */
184 	int		str_state;	/* see below */
185 };
186 
187 /*
188  * Synchronous Protocol Private Data Structure
189  */
190 #define	ZSH_MAX_RSTANDBY	6
191 #define	ZSH_RDONE_MAX		20
192 struct syncline {
193 	struct ser_str	sl_stream;	/* data path device points thru here */
194 	struct scc_mode	sl_mode;	/* clock, etc. modes */
195 	struct sl_stats	sl_st;		/* Data and error statistics */
196 	mblk_t		*sl_rhead;	/* receive: head of active message */
197 	mblk_t		*sl_ractb;	/* receive: active message block */
198 	mblk_t		*sl_rstandby[ZSH_MAX_RSTANDBY];
199 					/* receive: standby message blocks */
200 	mblk_t		*sl_xhead;	/* transmit: head of active message */
201 	mblk_t		*sl_xactb;	/* transmit: active message block */
202 	mblk_t		*sl_xstandby;	/* transmit: next available message */
203 	mblk_t		*sl_rdone[ZSH_RDONE_MAX];
204 					/* complete messages to be sent up */
205 	int		sl_rdone_wptr;
206 	int		sl_rdone_rptr;
207 	mblk_t		*sl_mstat;	/* most recent modem status change */
208 	bufcall_id_t	sl_bufcid;	/* pending bufcall ID */
209 	timeout_id_t	sl_wd_id;	/* watchdog timeout ID */
210 	int		sl_wd_count;	/* watchdog counter */
211 	int		sl_ocnt;	/* output message size */
212 	int		sl_mru;		/* Maximum Receive Unit */
213 	int		sl_bad_count_int;
214 	uchar_t		sl_rr0;		/* saved RR0 */
215 	uchar_t		sl_address;	/* station address */
216 	uchar_t		sl_txstate;	/* transmit state */
217 	uchar_t		sl_flags;	/* see below */
218 	uchar_t		sl_m_error;
219 	volatile uchar_t sl_soft_active; /*  */
220 };
221 
222 /*
223  * Bit definitions for sl_txstate.
224  */
225 #define	TX_OFF		0x0		/* Not available */
226 #define	TX_IDLE		0x1		/* Initialized */
227 #define	TX_RTS		0x2		/* IBM: RTS up, okay to transmit */
228 #define	TX_ACTIVE	0x4		/* Transmission in progress */
229 #define	TX_CRC		0x8		/* Sent all Data */
230 #define	TX_FLAG		0x10		/* Sent CRC bytes */
231 #define	TX_LAST		0x20		/* End-Of-Frame, OK to start new msg */
232 #define	TX_ABORTED	0x40		/* Transmit was aborted */
233 
234 /*
235  * Bit definitions for sl_flags.
236  */
237 #define	SF_FDXPTP	0x1	/* Full duplex AND Point-To-Point */
238 #define	SF_XMT_INPROG	0x2	/* Write queue is not empty */
239 #define	SF_LINKERR	0x4	/* Underrun or CTS/DCD drop */
240 #define	SF_FLUSH_WQ	0x8	/*  */
241 #define	SF_INITIALIZED	0x10	/* This channel programmed for this protocol */
242 #define	SF_PHONY	0x20	/* Dummy frame has been sent to close frame */
243 #define	SF_ZSH_START	0x40	/*  */
244 /*
245  * Bit definitions for str_state.
246  */
247 #define	STR_CLONE	1	/* This was opened thru clone device */
248 
249 extern int hz;
250 #define	SIO_WATCHDOG_TICK	(2 * hz)	/* Two second timeout */
251 #define	SIO_WATCHDOG_ON		(zss->sl_wd_id > 0)	/* Is it on? */
252 
253 
254 #ifdef	__cplusplus
255 }
256 #endif
257 
258 #endif	/* !_SYS_SER_SYNC_H */
259