xref: /illumos-gate/usr/src/uts/sun/sys/ser_async.h (revision d96925c4)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright (c) 1991-1998 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_SER_ASYNC_H
287c478bd9Sstevel@tonic-gate #define	_SYS_SER_ASYNC_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * Initial port setup parameters for async lines
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/ksynch.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * The following macro can be used to generate the baud rate generator's
427c478bd9Sstevel@tonic-gate  * time constants.  The parameters are the input clock to the BRG (eg,
437c478bd9Sstevel@tonic-gate  * 5000000 for 5MHz) and the desired baud rate.  This macro assumes that
447c478bd9Sstevel@tonic-gate  * the clock needed is 16x the desired baud rate.
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate #define	ZSTimeConst(InputClock, BaudRate) \
477c478bd9Sstevel@tonic-gate 	(ushort_t)((((int)InputClock+(BaudRate*16)) \
487c478bd9Sstevel@tonic-gate 	/ (2*(int)(BaudRate*16))) - 2)
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	ZSDelayConst(Hertz, FifoSize, BitsByte, BaudRate) \
517c478bd9Sstevel@tonic-gate 	(ushort_t)((((int)(Hertz)*(FifoSize)*(BitsByte)) \
527c478bd9Sstevel@tonic-gate 	/ (int)(BaudRate)) + 1)
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #define	ZSPEED(n)	ZSTimeConst(PCLK, n)
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	ZFIFOSZ		3
577c478bd9Sstevel@tonic-gate /*
58*d96925c4SRichard Lowe  * This macro needs a constant 100 Hz, but hires_tick or hz may change that.
597c478bd9Sstevel@tonic-gate  * ztdelay in zs_async.c converts to a true delay based on hz so we
60*d96925c4SRichard Lowe  * can use 100 Hz here.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate #define	ZDELAY(n)	ZSDelayConst(100, ZFIFOSZ, NBBY, n)
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define	ISPEED		B9600
657c478bd9Sstevel@tonic-gate #define	ISPEED_SVID	B300
667c478bd9Sstevel@tonic-gate #define	IFLAGS		(CS7|CREAD|PARENB)
677c478bd9Sstevel@tonic-gate #define	IFLAGS_SVID	(CS8|CREAD|HUPCL)
687c478bd9Sstevel@tonic-gate #define	I_IFLAGS	0
697c478bd9Sstevel@tonic-gate #define	I_CFLAGS	((ISPEED << IBSHIFT) | ISPEED | CS8 | CREAD | HUPCL)
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * Ring buffer and async line management definitions for CPU lines:
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate #ifdef  _KERNEL
757c478bd9Sstevel@tonic-gate #ifndef _ASM
767c478bd9Sstevel@tonic-gate #define	RINGBITS	8		/* # of bits in ring ptrs */
777c478bd9Sstevel@tonic-gate #define	RINGSIZE	(1<<RINGBITS)	/* size of ring */
787c478bd9Sstevel@tonic-gate #define	RINGMASK	(RINGSIZE-1)
797c478bd9Sstevel@tonic-gate #define	RINGFRAC	2		/* fraction of ring to force flush */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	RING_INIT(zap)	((zap)->za_rput = (zap)->za_rget = 0)
827c478bd9Sstevel@tonic-gate #define	RING_CNT(zap)	(((zap)->za_rput - (zap)->za_rget) & RINGMASK)
837c478bd9Sstevel@tonic-gate #define	RING_FRAC(zap)	((int)RING_CNT(zap) >= (int)(RINGSIZE/RINGFRAC))
847c478bd9Sstevel@tonic-gate #define	RING_POK(zap, n) ((int)RING_CNT(zap) < (int)(RINGSIZE-(n)))
857c478bd9Sstevel@tonic-gate #define	RING_PUT(zap, c) \
867c478bd9Sstevel@tonic-gate 	((zap)->za_ring[(zap)->za_rput++ & RINGMASK] =  (uchar_t)(c))
877c478bd9Sstevel@tonic-gate #define	RING_UNPUT(zap)	((zap)->za_rput--)
887c478bd9Sstevel@tonic-gate #define	RING_GOK(zap, n) ((int)RING_CNT(zap) >= (int)(n))
897c478bd9Sstevel@tonic-gate #define	RING_GET(zap)	((zap)->za_ring[(zap)->za_rget++ & RINGMASK])
907c478bd9Sstevel@tonic-gate #define	RING_EAT(zap, n) ((zap)->za_rget += (n))
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  *  To process parity errors/breaks in-band
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate #define	SBITS		8
967c478bd9Sstevel@tonic-gate #define	S_UNMARK	0x00FF
977c478bd9Sstevel@tonic-gate #define	S_PARERR	(0x01<<SBITS)
987c478bd9Sstevel@tonic-gate #define	S_BREAK		(0x02<<SBITS)
997c478bd9Sstevel@tonic-gate #define	RING_MARK(zap, c, s) \
1007c478bd9Sstevel@tonic-gate 	((zap)->za_ring[(zap)->za_rput++ & RINGMASK] = ((uchar_t)(c)|(s)))
1017c478bd9Sstevel@tonic-gate #define	RING_UNMARK(zap) \
1027c478bd9Sstevel@tonic-gate 	((zap)->za_ring[((zap)->za_rget) & RINGMASK] &= S_UNMARK)
1037c478bd9Sstevel@tonic-gate #define	RING_ERR(zap, c) \
1047c478bd9Sstevel@tonic-gate 	((zap)->za_ring[((zap)->za_rget) & RINGMASK] & (c))
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * These flags are shared with mcp_async.c and should be kept in sync.
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate #define	ZAS_WOPEN	0x00000001	/* waiting for open to complete */
1117c478bd9Sstevel@tonic-gate #define	ZAS_ISOPEN	0x00000002	/* open is complete */
1127c478bd9Sstevel@tonic-gate #define	ZAS_OUT		0x00000004	/* line being used for dialout */
1137c478bd9Sstevel@tonic-gate #define	ZAS_CARR_ON	0x00000008	/* carrier on last time we looked */
1147c478bd9Sstevel@tonic-gate #define	ZAS_STOPPED	0x00000010	/* output is stopped */
1157c478bd9Sstevel@tonic-gate #define	ZAS_DELAY	0x00000020	/* waiting for delay to finish */
1167c478bd9Sstevel@tonic-gate #define	ZAS_BREAK	0x00000040	/* waiting for break to finish */
1177c478bd9Sstevel@tonic-gate #define	ZAS_BUSY	0x00000080	/* waiting for transmission to finish */
1187c478bd9Sstevel@tonic-gate #define	ZAS_DRAINING	0x00000100	/* waiting for output to drain */
1197c478bd9Sstevel@tonic-gate 					/* from chip */
1207c478bd9Sstevel@tonic-gate #define	ZAS_SERVICEIMM	0x00000200	/* queue soft interrupt as soon as */
1217c478bd9Sstevel@tonic-gate 					/* receiver interrupt occurs */
1227c478bd9Sstevel@tonic-gate #define	ZAS_SOFTC_ATTN	0x00000400	/* check soft carrier state in close */
1237c478bd9Sstevel@tonic-gate #define	ZAS_PAUSED	0x00000800	/* MCP: dma interrupted and pending */
1247c478bd9Sstevel@tonic-gate #define	ZAS_LNEXT	0x00001000	/* MCP: next input char is quoted */
1257c478bd9Sstevel@tonic-gate #define	ZAS_XMIT_ACTIVE	0x00002000	/* MCP: Transmit dma running */
1267c478bd9Sstevel@tonic-gate #define	ZAS_DMA_DONE	0x00004000	/* MCP: DMA done interrupt received */
1277c478bd9Sstevel@tonic-gate #define	ZAS_ZSA_START	0x00010000	/* MCP: DMA done interrupt received */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate /*
1317c478bd9Sstevel@tonic-gate  * Asynchronous protocol private data structure for ZS and MCP/ALM2
1327c478bd9Sstevel@tonic-gate  */
1337c478bd9Sstevel@tonic-gate #define	ZSA_MIN_RSTANDBY	12
1347c478bd9Sstevel@tonic-gate #define	ZSA_MAX_RSTANDBY	256
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #define	ZSA_RDONE_MIN		60
1377c478bd9Sstevel@tonic-gate #define	ZSA_RDONE_MAX		350
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate struct asyncline {
1407c478bd9Sstevel@tonic-gate 	int		za_flags;	/* random flags */
1417c478bd9Sstevel@tonic-gate 	kcondvar_t	za_flags_cv;	/* condition variable for flags */
1427c478bd9Sstevel@tonic-gate 	dev_t		za_dev;		/* device major/minor numbers */
1437c478bd9Sstevel@tonic-gate 	mblk_t		*za_xmitblk;	/* transmit: active msg block */
1447c478bd9Sstevel@tonic-gate 	mblk_t		*za_rcvblk;	/* receive: active msg block */
1457c478bd9Sstevel@tonic-gate 	struct zscom	*za_common;	/* device common data */
1467c478bd9Sstevel@tonic-gate 	tty_common_t	za_ttycommon;	/* tty driver common data */
1477c478bd9Sstevel@tonic-gate 	bufcall_id_t	za_wbufcid;	/* id of pending write-side bufcall */
1487c478bd9Sstevel@tonic-gate 	timeout_id_t	za_polltid;	/* softint poll timeout id */
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	/*
1517c478bd9Sstevel@tonic-gate 	 * The following fields are protected by the zs_excl_hi lock.
1527c478bd9Sstevel@tonic-gate 	 * Some, such as za_flowc, are set only at the base level and
1537c478bd9Sstevel@tonic-gate 	 * cleared (without the lock) only by the interrupt level.
1547c478bd9Sstevel@tonic-gate 	 */
1557c478bd9Sstevel@tonic-gate 	uchar_t		*za_optr;	/* output pointer */
1567c478bd9Sstevel@tonic-gate 	int		za_ocnt;	/* output count */
1577c478bd9Sstevel@tonic-gate 	uchar_t		za_rput;	/* producing pointer for input */
1587c478bd9Sstevel@tonic-gate 	uchar_t		za_rget;	/* consuming pointer for input */
1597c478bd9Sstevel@tonic-gate 	uchar_t		za_flowc;	/* flow control char to send */
1607c478bd9Sstevel@tonic-gate 	uchar_t		za_rr0;		/* status latch for break detection */
1617c478bd9Sstevel@tonic-gate 	/*
1627c478bd9Sstevel@tonic-gate 	 * Each character stuffed into the ring has two bytes associated
1637c478bd9Sstevel@tonic-gate 	 * with it.  The first byte is used to indicate special conditions
1647c478bd9Sstevel@tonic-gate 	 * and the second byte is the actual data.  The ring buffer
1657c478bd9Sstevel@tonic-gate 	 * needs to be defined as ushort_t to accomodate this.
1667c478bd9Sstevel@tonic-gate 	 */
167*d96925c4SRichard Lowe 	ushort_t	za_ring[RINGSIZE];
1687c478bd9Sstevel@tonic-gate 	timeout_id_t	za_kick_rcv_id;
169*d96925c4SRichard Lowe 	int		za_kick_rcv_count;
1707c478bd9Sstevel@tonic-gate 	timeout_id_t	za_zsa_restart_id;
1717c478bd9Sstevel@tonic-gate 	bufcall_id_t	za_bufcid;
1727c478bd9Sstevel@tonic-gate 	mblk_t		*za_rstandby[ZSA_MAX_RSTANDBY];
1737c478bd9Sstevel@tonic-gate 					/* receive: standby message blocks */
1747c478bd9Sstevel@tonic-gate 	mblk_t		*za_rdone[ZSA_RDONE_MAX];
1757c478bd9Sstevel@tonic-gate 					/* complete messages to be sent up */
1767c478bd9Sstevel@tonic-gate 	int		za_rdone_wptr;
1777c478bd9Sstevel@tonic-gate 	int		za_rdone_rptr;
1787c478bd9Sstevel@tonic-gate 	int		za_bad_count_int;
1797c478bd9Sstevel@tonic-gate 	uint_t		za_rcv_flags_mask;
1807c478bd9Sstevel@tonic-gate #ifdef ZSA_DEBUG
1817c478bd9Sstevel@tonic-gate 	int		za_wr;
1827c478bd9Sstevel@tonic-gate 	int		za_rd;
1837c478bd9Sstevel@tonic-gate #endif
1847c478bd9Sstevel@tonic-gate 	volatile uchar_t za_soft_active;
1857c478bd9Sstevel@tonic-gate 	volatile uchar_t za_kick_active;
1867c478bd9Sstevel@tonic-gate #define	DO_STOPC	(1<<8)
1877c478bd9Sstevel@tonic-gate #define	DO_ESC		(1<<9)
1887c478bd9Sstevel@tonic-gate #define	DO_SERVICEIMM	(1<<10)
1897c478bd9Sstevel@tonic-gate #define	DO_TRANSMIT	(1<<11)
1907c478bd9Sstevel@tonic-gate #define	DO_RETRANSMIT	(1<<12)
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * ZS exclusive stuff.
1937c478bd9Sstevel@tonic-gate  */
1947c478bd9Sstevel@tonic-gate 	short		za_break;	/* break count */
1957c478bd9Sstevel@tonic-gate 	union {
1967c478bd9Sstevel@tonic-gate 		struct {
1977c478bd9Sstevel@tonic-gate 			uchar_t  _hw;    /* overrun (hw) */
1987c478bd9Sstevel@tonic-gate 			uchar_t  _sw;    /* overrun (sw) */
1997c478bd9Sstevel@tonic-gate 		} _z;
2007c478bd9Sstevel@tonic-gate 		ushort_t uover_overrun;
2017c478bd9Sstevel@tonic-gate 	} za_uover;
2027c478bd9Sstevel@tonic-gate #define	za_overrun	za_uover.uover_overrun
2037c478bd9Sstevel@tonic-gate #define	za_hw_overrun	za_uover._z._hw
2047c478bd9Sstevel@tonic-gate #define	za_sw_overrun	za_uover._z._sw
2057c478bd9Sstevel@tonic-gate 	short		za_ext;		/* modem status change count */
2067c478bd9Sstevel@tonic-gate 	short		za_work;	/* work to do flag */
2077c478bd9Sstevel@tonic-gate 	short		za_grace_flow_control;
2087c478bd9Sstevel@tonic-gate 	uchar_t		za_do_kick_rcv_in_softint;
2097c478bd9Sstevel@tonic-gate 	uchar_t		za_m_error;
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate  * MCP exclusive stuff.
2127c478bd9Sstevel@tonic-gate  * These should all be protected by a high priority lock.
2137c478bd9Sstevel@tonic-gate  */
2147c478bd9Sstevel@tonic-gate 	uchar_t		*za_xoff;	/* xoff char in h/w XOFF buffer */
2157c478bd9Sstevel@tonic-gate 	uchar_t		za_lnext;	/* treat next char as literal */
2167c478bd9Sstevel@tonic-gate 	uchar_t		*za_devctl;	/* device control reg for this port */
2177c478bd9Sstevel@tonic-gate 	uchar_t		*za_dmabuf;	/* dma ram buffer for this port */
2187c478bd9Sstevel@tonic-gate 	int		za_breakoff;	/* SLAVIO */
2197c478bd9Sstevel@tonic-gate 	int		za_slav_break;	/* SLAVIO */
2207c478bd9Sstevel@tonic-gate /*
2217c478bd9Sstevel@tonic-gate  * NTP PPS exclusive stuff.
2227c478bd9Sstevel@tonic-gate  */
2237c478bd9Sstevel@tonic-gate 	short		za_pps;		/* PPS on? */
2247c478bd9Sstevel@tonic-gate };
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate #endif /* _ASM */
2277c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate #endif
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate #endif	/* !_SYS_SER_ASYNC_H */
234