xref: /titanic_50/usr/src/uts/common/sys/asy.h (revision cd43c54a778f7a542d9523e64ebc27ac5d439b80)
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
556001103Smyers  * Common Development and Distribution License (the "License").
656001103Smyers  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved 	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*cd43c54aSZach Kissel  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_SYS_ASY_H
307c478bd9Sstevel@tonic-gate #define	_SYS_ASY_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef __cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/tty.h>
377c478bd9Sstevel@tonic-gate #include <sys/ksynch.h>
387c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
397c478bd9Sstevel@tonic-gate 
4056001103Smyers /*
4156001103Smyers  * internal bus type naming
4256001103Smyers  */
4356001103Smyers #define	ASY_BUS_PCI	(0)
4456001103Smyers #define	ASY_BUS_ISA	(1)
4556001103Smyers #define	ASY_BUS_UNKNOWN	(-1)
4656001103Smyers 
4756001103Smyers #define	ASY_MINOR_LEN	(40)
4856001103Smyers 
497c478bd9Sstevel@tonic-gate #define	COM1_IOADDR	0x3f8
507c478bd9Sstevel@tonic-gate #define	COM2_IOADDR	0x2f8
517c478bd9Sstevel@tonic-gate #define	COM3_IOADDR	0x3e8
527c478bd9Sstevel@tonic-gate #define	COM4_IOADDR	0x2e8
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Definitions for INS8250 / 16550  chips
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /* defined as offsets from the data register */
597c478bd9Sstevel@tonic-gate #define	DAT		0 	/* receive/transmit data */
607c478bd9Sstevel@tonic-gate #define	ICR		1  	/* interrupt control register */
617c478bd9Sstevel@tonic-gate #define	ISR		2   	/* interrupt status register */
627c478bd9Sstevel@tonic-gate #define	LCR		3   	/* line control register */
637c478bd9Sstevel@tonic-gate #define	MCR		4   	/* modem control register */
647c478bd9Sstevel@tonic-gate #define	LSR		5   	/* line status register */
657c478bd9Sstevel@tonic-gate #define	MSR		6   	/* modem status register */
667c478bd9Sstevel@tonic-gate #define	SCR		7   	/* scratch register */
677c478bd9Sstevel@tonic-gate #define	DLL		0   	/* divisor latch (lsb) */
687c478bd9Sstevel@tonic-gate #define	DLH		1   	/* divisor latch (msb) */
697c478bd9Sstevel@tonic-gate #define	FIFOR		ISR	/* FIFO register for 16550 */
707c478bd9Sstevel@tonic-gate #define	EFR		ISR	/* Enhanced feature register for 16650 */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * INTEL 8210-A/B & 16450/16550 Registers Structure.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /* Line Control Register */
777c478bd9Sstevel@tonic-gate #define	WLS0		0x01	/* word length select bit 0 */
787c478bd9Sstevel@tonic-gate #define	WLS1		0x02	/* word length select bit 2 */
797c478bd9Sstevel@tonic-gate #define	STB		0x04	/* number of stop bits */
807c478bd9Sstevel@tonic-gate #define	PEN		0x08	/* parity enable */
817c478bd9Sstevel@tonic-gate #define	EPS		0x10	/* even parity select */
827c478bd9Sstevel@tonic-gate #define	SETBREAK 	0x40	/* break key */
837c478bd9Sstevel@tonic-gate #define	DLAB		0x80	/* divisor latch access bit */
847c478bd9Sstevel@tonic-gate #define	RXLEN   	0x03   	/* # of data bits per received/xmitted char */
857c478bd9Sstevel@tonic-gate #define	STOP1   	0x00
867c478bd9Sstevel@tonic-gate #define	STOP2   	0x04
877c478bd9Sstevel@tonic-gate #define	PAREN   	0x08
887c478bd9Sstevel@tonic-gate #define	PAREVN  	0x10
897c478bd9Sstevel@tonic-gate #define	PARMARK 	0x20
907c478bd9Sstevel@tonic-gate #define	SNDBRK  	0x40
917c478bd9Sstevel@tonic-gate #define	EFRACCESS	0xBF	/* magic value for 16650 EFR access */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #define	BITS5		0x00	/* 5 bits per char */
947c478bd9Sstevel@tonic-gate #define	BITS6		0x01	/* 6 bits per char */
957c478bd9Sstevel@tonic-gate #define	BITS7		0x02	/* 7 bits per char */
967c478bd9Sstevel@tonic-gate #define	BITS8		0x03	/* 8 bits per char */
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /* Line Status Register */
997c478bd9Sstevel@tonic-gate #define	RCA		0x01	/* data ready */
1007c478bd9Sstevel@tonic-gate #define	OVRRUN		0x02	/* overrun error */
1017c478bd9Sstevel@tonic-gate #define	PARERR		0x04	/* parity error */
1027c478bd9Sstevel@tonic-gate #define	FRMERR		0x08	/* framing error */
1037c478bd9Sstevel@tonic-gate #define	BRKDET  	0x10	/* a break has arrived */
1047c478bd9Sstevel@tonic-gate #define	XHRE		0x20	/* tx hold reg is now empty */
1057c478bd9Sstevel@tonic-gate #define	XSRE		0x40	/* tx shift reg is now empty */
1067c478bd9Sstevel@tonic-gate #define	RFBE		0x80	/* rx FIFO Buffer error */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /* Interrupt Id Regisger */
1097c478bd9Sstevel@tonic-gate #define	MSTATUS		0x00	/* modem status changed */
1107c478bd9Sstevel@tonic-gate #define	NOINTERRUPT	0x01	/* no interrupt pending */
1117c478bd9Sstevel@tonic-gate #define	TxRDY		0x02	/* Transmitter Holding Register Empty */
1127c478bd9Sstevel@tonic-gate #define	RxRDY		0x04	/* Receiver Data Available */
1137c478bd9Sstevel@tonic-gate #define	FFTMOUT 	0x0c	/* FIFO timeout - 16550AF */
1147c478bd9Sstevel@tonic-gate #define	RSTATUS 	0x06	/* Receiver Line Status */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /* Interrupt Enable Register */
1177c478bd9Sstevel@tonic-gate #define	RIEN		0x01	/* Received Data Ready */
1187c478bd9Sstevel@tonic-gate #define	TIEN		0x02	/* Tx Hold Register Empty */
1197c478bd9Sstevel@tonic-gate #define	SIEN		0x04	/* Receiver Line Status */
1207c478bd9Sstevel@tonic-gate #define	MIEN		0x08	/* Modem Status */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /* Modem Control Register */
1237c478bd9Sstevel@tonic-gate #define	DTR		0x01	/* Data Terminal Ready */
1247c478bd9Sstevel@tonic-gate #define	RTS		0x02	/* Request To Send */
1257c478bd9Sstevel@tonic-gate #define	OUT1		0x04	/* Aux output - not used */
1267c478bd9Sstevel@tonic-gate #define	OUT2		0x08	/* turns intr to 386 on/off */
1277c478bd9Sstevel@tonic-gate #define	ASY_LOOP	0x10	/* loopback for diagnostics */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /* Modem Status Register */
1307c478bd9Sstevel@tonic-gate #define	DCTS		0x01	/* Delta Clear To Send */
1317c478bd9Sstevel@tonic-gate #define	DDSR		0x02	/* Delta Data Set Ready */
1327c478bd9Sstevel@tonic-gate #define	DRI		0x04	/* Trail Edge Ring Indicator */
1337c478bd9Sstevel@tonic-gate #define	DDCD		0x08	/* Delta Data Carrier Detect */
1347c478bd9Sstevel@tonic-gate #define	CTS		0x10	/* Clear To Send */
1357c478bd9Sstevel@tonic-gate #define	DSR		0x20	/* Data Set Ready */
1367c478bd9Sstevel@tonic-gate #define	RI		0x40	/* Ring Indicator */
1377c478bd9Sstevel@tonic-gate #define	DCD		0x80	/* Data Carrier Detect */
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #define	DELTAS(x)	((x)&(DCTS|DDSR|DRI|DDCD))
1407c478bd9Sstevel@tonic-gate #define	STATES(x)	((x)&(CTS|DSR|RI|DCD))
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /* flags for FCR (FIFO Control register) */
1437c478bd9Sstevel@tonic-gate #define	FIFO_OFF	0x00	/* fifo disabled */
1447c478bd9Sstevel@tonic-gate #define	FIFO_ON		0x01	/* fifo enabled */
1457c478bd9Sstevel@tonic-gate #define	FIFORXFLSH	0x02	/* flush receiver FIFO */
1467c478bd9Sstevel@tonic-gate #define	FIFOTXFLSH	0x04	/* flush transmitter FIFO */
1477c478bd9Sstevel@tonic-gate #define	FIFODMA		0x08	/* DMA mode 1 */
1487c478bd9Sstevel@tonic-gate #define	FIFOEXTRA1	0x10	/* Longer fifos on some 16650's */
1497c478bd9Sstevel@tonic-gate #define	FIFOEXTRA2	0x20	/* Longer fifos on some 16650's and 16750 */
1507c478bd9Sstevel@tonic-gate #define	FIFO_TRIG_1	0x00	/* 1 byte trigger level */
1517c478bd9Sstevel@tonic-gate #define	FIFO_TRIG_4	0x40	/* 4 byte trigger level */
1527c478bd9Sstevel@tonic-gate #define	FIFO_TRIG_8	0x80	/* 8 byte trigger level */
1537c478bd9Sstevel@tonic-gate #define	FIFO_TRIG_14	0xC0	/* 14 byte trigger level */
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /* Serial in/out requests */
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #define	OVERRUN		040000
1587c478bd9Sstevel@tonic-gate #define	FRERROR		020000
1597c478bd9Sstevel@tonic-gate #define	PERROR		010000
1607c478bd9Sstevel@tonic-gate #define	S_ERRORS	(PERROR|OVERRUN|FRERROR)
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate /* EFR - Enhanced feature register for 16650 */
1637c478bd9Sstevel@tonic-gate #define	ENHENABLE	0x10
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /* SCR - scratch register */
1667c478bd9Sstevel@tonic-gate #define	SCRTEST		0x5a	/* arbritrary value for testing SCR register */
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * Ring buffer and async line management definitions.
1707c478bd9Sstevel@tonic-gate  */
171*cd43c54aSZach Kissel #define	RINGBITS	16		/* # of bits in ring ptrs */
1727c478bd9Sstevel@tonic-gate #define	RINGSIZE	(1<<RINGBITS)   /* size of ring */
1737c478bd9Sstevel@tonic-gate #define	RINGMASK	(RINGSIZE-1)
174*cd43c54aSZach Kissel #define	RINGFRAC	12		/* fraction of ring to force flush */
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate #define	RING_INIT(ap)  ((ap)->async_rput = (ap)->async_rget = 0)
1777c478bd9Sstevel@tonic-gate #define	RING_CNT(ap)   (((ap)->async_rput >= (ap)->async_rget) ? \
1787c478bd9Sstevel@tonic-gate 	((ap)->async_rput - (ap)->async_rget):\
1797c478bd9Sstevel@tonic-gate 	((0x10000 - (ap)->async_rget) + (ap)->async_rput))
1807c478bd9Sstevel@tonic-gate #define	RING_FRAC(ap)  ((int)RING_CNT(ap) >= (int)(RINGSIZE/RINGFRAC))
1817c478bd9Sstevel@tonic-gate #define	RING_POK(ap, n) ((int)RING_CNT(ap) < (int)(RINGSIZE-(n)))
1827c478bd9Sstevel@tonic-gate #define	RING_PUT(ap, c) \
1837c478bd9Sstevel@tonic-gate 	((ap)->async_ring[(ap)->async_rput++ & RINGMASK] =  (uchar_t)(c))
1847c478bd9Sstevel@tonic-gate #define	RING_UNPUT(ap) ((ap)->async_rput--)
1857c478bd9Sstevel@tonic-gate #define	RING_GOK(ap, n) ((int)RING_CNT(ap) >= (int)(n))
1867c478bd9Sstevel@tonic-gate #define	RING_GET(ap)   ((ap)->async_ring[(ap)->async_rget++ & RINGMASK])
1877c478bd9Sstevel@tonic-gate #define	RING_EAT(ap, n) ((ap)->async_rget += (n))
1887c478bd9Sstevel@tonic-gate #define	RING_MARK(ap, c, s) \
1897c478bd9Sstevel@tonic-gate 	((ap)->async_ring[(ap)->async_rput++ & RINGMASK] = ((uchar_t)(c)|(s)))
1907c478bd9Sstevel@tonic-gate #define	RING_UNMARK(ap) \
1917c478bd9Sstevel@tonic-gate 	((ap)->async_ring[((ap)->async_rget) & RINGMASK] &= ~S_ERRORS)
1927c478bd9Sstevel@tonic-gate #define	RING_ERR(ap, c) \
1937c478bd9Sstevel@tonic-gate 	((ap)->async_ring[((ap)->async_rget) & RINGMASK] & (c))
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * Asy tracing macros.  These are a bit similar to some macros in sys/vtrace.h .
1977c478bd9Sstevel@tonic-gate  *
1987c478bd9Sstevel@tonic-gate  * XXX - Needs review:  would it be better to use the macros in sys/vtrace.h ?
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate #ifdef DEBUG
2017c478bd9Sstevel@tonic-gate #define	DEBUGWARN0(fac, format) \
2027c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2037c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, format)
2047c478bd9Sstevel@tonic-gate #define	DEBUGNOTE0(fac, format) \
2057c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2067c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, format)
2077c478bd9Sstevel@tonic-gate #define	DEBUGNOTE1(fac, format, arg1) \
2087c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2097c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, format, arg1)
2107c478bd9Sstevel@tonic-gate #define	DEBUGNOTE2(fac, format, arg1, arg2) \
2117c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2127c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, format, arg1, arg2)
2137c478bd9Sstevel@tonic-gate #define	DEBUGNOTE3(fac, format, arg1, arg2, arg3) \
2147c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2157c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, format, arg1, arg2, arg3)
2167c478bd9Sstevel@tonic-gate #define	DEBUGCONT0(fac, format) \
2177c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2187c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, format)
2197c478bd9Sstevel@tonic-gate #define	DEBUGCONT1(fac, format, arg1) \
2207c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2217c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, format, arg1)
2227c478bd9Sstevel@tonic-gate #define	DEBUGCONT2(fac, format, arg1, arg2) \
2237c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2247c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, format, arg1, arg2)
2257c478bd9Sstevel@tonic-gate #define	DEBUGCONT3(fac, format, arg1, arg2, arg3) \
2267c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2277c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, format, arg1, arg2, arg3)
2287c478bd9Sstevel@tonic-gate #define	DEBUGCONT4(fac, format, arg1, arg2, arg3, arg4) \
2297c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2307c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, format, arg1, arg2, arg3, arg4)
2317c478bd9Sstevel@tonic-gate #define	DEBUGCONT10(fac, format, \
2327c478bd9Sstevel@tonic-gate 	arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) \
2337c478bd9Sstevel@tonic-gate 	if (debug & (fac)) \
2347c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, format, \
2357c478bd9Sstevel@tonic-gate 		arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)
2367c478bd9Sstevel@tonic-gate #else
2377c478bd9Sstevel@tonic-gate #define	DEBUGWARN0(fac, format)
2387c478bd9Sstevel@tonic-gate #define	DEBUGNOTE0(fac, format)
2397c478bd9Sstevel@tonic-gate #define	DEBUGNOTE1(fac, format, arg1)
2407c478bd9Sstevel@tonic-gate #define	DEBUGNOTE2(fac, format, arg1, arg2)
2417c478bd9Sstevel@tonic-gate #define	DEBUGNOTE3(fac, format, arg1, arg2, arg3)
2427c478bd9Sstevel@tonic-gate #define	DEBUGCONT0(fac, format)
2437c478bd9Sstevel@tonic-gate #define	DEBUGCONT1(fac, format, arg1)
2447c478bd9Sstevel@tonic-gate #define	DEBUGCONT2(fac, format, arg1, arg2)
2457c478bd9Sstevel@tonic-gate #define	DEBUGCONT3(fac, format, arg1, arg2, arg3)
2467c478bd9Sstevel@tonic-gate #define	DEBUGCONT4(fac, format, arg1, arg2, arg3, arg4)
2477c478bd9Sstevel@tonic-gate #define	DEBUGCONT10(fac, format, \
2487c478bd9Sstevel@tonic-gate 	arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)
2497c478bd9Sstevel@tonic-gate #endif
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate  * Hardware channel common data. One structure per port.
2537c478bd9Sstevel@tonic-gate  * Each of the fields in this structure is required to be protected by a
2547c478bd9Sstevel@tonic-gate  * mutex lock at the highest priority at which it can be altered.
2557c478bd9Sstevel@tonic-gate  * The asy_flags, and asy_next fields can be altered by interrupt
2567c478bd9Sstevel@tonic-gate  * handling code that must be protected by the mutex whose handle is
2577c478bd9Sstevel@tonic-gate  * stored in asy_excl_hi.  All others can be protected by the asy_excl
2587c478bd9Sstevel@tonic-gate  * mutex, which is lower priority and adaptive.
2597c478bd9Sstevel@tonic-gate  */
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate struct asycom {
2627c478bd9Sstevel@tonic-gate 	int		asy_flags;	/* random flags  */
2637c478bd9Sstevel@tonic-gate 					/* protected by asy_excl_hi lock */
2647c478bd9Sstevel@tonic-gate 	uint_t		asy_hwtype;	/* HW type: ASY16550A, etc. */
2657c478bd9Sstevel@tonic-gate 	uint_t		asy_use_fifo;	/* HW FIFO use it or not ?? */
2667c478bd9Sstevel@tonic-gate 	uint_t		asy_fifo_buf;	/* With FIFO = 16, otherwise = 1 */
2677c478bd9Sstevel@tonic-gate 	uint_t		asy_flags2;	/* flags which don't change, no lock */
2687c478bd9Sstevel@tonic-gate 	uint8_t		*asy_ioaddr;	/* i/o address of ASY port */
2697c478bd9Sstevel@tonic-gate 	struct asyncline *asy_priv;	/* protocol private data -- asyncline */
2707c478bd9Sstevel@tonic-gate 	dev_info_t	*asy_dip;	/* dev_info */
2717c478bd9Sstevel@tonic-gate 	int		asy_unit;	/* which port */
2727c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t asy_iblock;
2737c478bd9Sstevel@tonic-gate 	kmutex_t	asy_excl;	/* asy adaptive mutex */
2747c478bd9Sstevel@tonic-gate 	kmutex_t	asy_excl_hi;	/* asy spinlock mutex */
275*cd43c54aSZach Kissel 	kmutex_t	asy_soft_lock;	/* soft lock for guarding softpend. */
276*cd43c54aSZach Kissel 	int		asysoftpend;	/* Flag indicating soft int pending. */
277*cd43c54aSZach Kissel 	ddi_softintr_t	asy_softintr_id;
278*cd43c54aSZach Kissel 	ddi_iblock_cookie_t asy_soft_iblock;
2792df1fe9cSrandyf 
2802df1fe9cSrandyf 	/*
2812df1fe9cSrandyf 	 * The asy_soft_sr mutex should only be taken by the soft interrupt
2822df1fe9cSrandyf 	 * handler and the driver DDI_SUSPEND/DDI_RESUME code.  It
2832df1fe9cSrandyf 	 * shouldn't be taken by any code that may get called indirectly
2842df1fe9cSrandyf 	 * by the soft interrupt handler (e.g. as a result of a put or
2852df1fe9cSrandyf 	 * putnext call).
2862df1fe9cSrandyf 	 */
2872df1fe9cSrandyf 	kmutex_t	asy_soft_sr;	/* soft int suspend/resume mutex */
2887c478bd9Sstevel@tonic-gate 	uchar_t		asy_msr;	/* saved modem status */
2897c478bd9Sstevel@tonic-gate 	uchar_t		asy_mcr;	/* soft carrier bits */
2907c478bd9Sstevel@tonic-gate 	uchar_t		asy_lcr;	/* console lcr bits */
2917c478bd9Sstevel@tonic-gate 	uchar_t		asy_bidx;	/* console baud rate index */
2927c478bd9Sstevel@tonic-gate 	tcflag_t	asy_cflag;	/* console mode bits */
2937c478bd9Sstevel@tonic-gate 	struct cons_polledio	polledio;	/* polled I/O functions */
2947c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	asy_iohandle;	/* Data access handle */
2957c478bd9Sstevel@tonic-gate 	tcflag_t	asy_ocflag;	/* old console mode bits */
2967c478bd9Sstevel@tonic-gate 	uchar_t		asy_com_port;	/* COM port number, or zero */
2977c478bd9Sstevel@tonic-gate 	uchar_t		asy_fifor;	/* FIFOR register setting */
2987c478bd9Sstevel@tonic-gate #ifdef DEBUG
2997c478bd9Sstevel@tonic-gate 	int		asy_msint_cnt;	/* number of times in async_msint */
3007c478bd9Sstevel@tonic-gate #endif
3017c478bd9Sstevel@tonic-gate };
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate /*
3047c478bd9Sstevel@tonic-gate  * Asychronous protocol private data structure for ASY.
3057c478bd9Sstevel@tonic-gate  * Each of the fields in the structure is required to be protected by
3067c478bd9Sstevel@tonic-gate  * the lower priority lock except the fields that are set only at
3077c478bd9Sstevel@tonic-gate  * base level but cleared (with out lock) at interrupt level.
3087c478bd9Sstevel@tonic-gate  */
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate struct asyncline {
3117c478bd9Sstevel@tonic-gate 	int		async_flags;	/* random flags */
3127c478bd9Sstevel@tonic-gate 	kcondvar_t	async_flags_cv; /* condition variable for flags */
3132df1fe9cSrandyf 	kcondvar_t	async_ops_cv;	/* condition variable for async_ops */
3147c478bd9Sstevel@tonic-gate 	dev_t		async_dev;	/* device major/minor numbers */
3157c478bd9Sstevel@tonic-gate 	mblk_t		*async_xmitblk;	/* transmit: active msg block */
3167c478bd9Sstevel@tonic-gate 	struct asycom	*async_common;	/* device common data */
3177c478bd9Sstevel@tonic-gate 	tty_common_t 	async_ttycommon; /* tty driver common data */
3187c478bd9Sstevel@tonic-gate 	bufcall_id_t	async_wbufcid;	/* id for pending write-side bufcall */
3192df1fe9cSrandyf 	size_t		async_wbufcds;	/* Buffer size requested in bufcall */
3207c478bd9Sstevel@tonic-gate 	timeout_id_t	async_polltid;	/* softint poll timeout id */
3217c478bd9Sstevel@tonic-gate 	timeout_id_t    async_dtrtid;   /* delaying DTR turn on */
3227c478bd9Sstevel@tonic-gate 	timeout_id_t    async_utbrktid; /* hold minimum untimed break time id */
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	/*
3257c478bd9Sstevel@tonic-gate 	 * The following fields are protected by the asy_excl_hi lock.
3267c478bd9Sstevel@tonic-gate 	 * Some, such as async_flowc, are set only at the base level and
3277c478bd9Sstevel@tonic-gate 	 * cleared (without the lock) only by the interrupt level.
3287c478bd9Sstevel@tonic-gate 	 */
3297c478bd9Sstevel@tonic-gate 	uchar_t		*async_optr;	/* output pointer */
3307c478bd9Sstevel@tonic-gate 	int		async_ocnt;	/* output count */
331*cd43c54aSZach Kissel 	uint_t		async_rput;	/* producing pointer for input */
332*cd43c54aSZach Kissel 	uint_t		async_rget;	/* consuming pointer for input */
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	/*
3357c478bd9Sstevel@tonic-gate 	 * Each character stuffed into the ring has two bytes associated
3367c478bd9Sstevel@tonic-gate 	 * with it.  The first byte is used to indicate special conditions
3377c478bd9Sstevel@tonic-gate 	 * and the second byte is the actual data.  The ring buffer
3387c478bd9Sstevel@tonic-gate 	 * needs to be defined as ushort_t to accomodate this.
3397c478bd9Sstevel@tonic-gate 	 */
3407c478bd9Sstevel@tonic-gate 	ushort_t	async_ring[RINGSIZE];
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	short		async_break;	/* break count */
3437c478bd9Sstevel@tonic-gate 	int		async_inflow_source; /* input flow control type */
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	union {
3467c478bd9Sstevel@tonic-gate 		struct {
3477c478bd9Sstevel@tonic-gate 			uchar_t _hw;	/* overrun (hw) */
3487c478bd9Sstevel@tonic-gate 			uchar_t _sw;	/* overrun (sw) */
3497c478bd9Sstevel@tonic-gate 		} _a;
3507c478bd9Sstevel@tonic-gate 		ushort_t uover_overrun;
3517c478bd9Sstevel@tonic-gate 	} async_uover;
3527c478bd9Sstevel@tonic-gate #define	async_overrun		async_uover._a.uover_overrun
3537c478bd9Sstevel@tonic-gate #define	async_hw_overrun	async_uover._a._hw
3547c478bd9Sstevel@tonic-gate #define	async_sw_overrun	async_uover._a._sw
3557c478bd9Sstevel@tonic-gate 	short		async_ext;	/* modem status change count */
3567c478bd9Sstevel@tonic-gate 	short		async_work;	/* work to do flag */
3577c478bd9Sstevel@tonic-gate 	timeout_id_t	async_timer;	/* close drain progress timer */
3582df1fe9cSrandyf 
3592df1fe9cSrandyf 	mblk_t		*async_suspqf;	/* front of suspend queue */
3602df1fe9cSrandyf 	mblk_t		*async_suspqb;	/* back of suspend queue */
3612df1fe9cSrandyf 	int		async_ops;	/* active operations counter */
3627c478bd9Sstevel@tonic-gate };
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate /* definitions for async_flags field */
3657c478bd9Sstevel@tonic-gate #define	ASYNC_EXCL_OPEN	 0x10000000	/* exclusive open */
3667c478bd9Sstevel@tonic-gate #define	ASYNC_WOPEN	 0x00000001	/* waiting for open to complete */
3677c478bd9Sstevel@tonic-gate #define	ASYNC_ISOPEN	 0x00000002	/* open is complete */
3687c478bd9Sstevel@tonic-gate #define	ASYNC_OUT	 0x00000004	/* line being used for dialout */
3697c478bd9Sstevel@tonic-gate #define	ASYNC_CARR_ON	 0x00000008	/* carrier on last time we looked */
3707c478bd9Sstevel@tonic-gate #define	ASYNC_STOPPED	 0x00000010	/* output is stopped */
3717c478bd9Sstevel@tonic-gate #define	ASYNC_DELAY	 0x00000020	/* waiting for delay to finish */
3727c478bd9Sstevel@tonic-gate #define	ASYNC_BREAK	 0x00000040	/* waiting for break to finish */
3737c478bd9Sstevel@tonic-gate #define	ASYNC_BUSY	 0x00000080	/* waiting for transmission to finish */
3747c478bd9Sstevel@tonic-gate #define	ASYNC_DRAINING	 0x00000100	/* waiting for output to drain */
3757c478bd9Sstevel@tonic-gate #define	ASYNC_SERVICEIMM 0x00000200	/* queue soft interrupt as soon as */
3767c478bd9Sstevel@tonic-gate #define	ASYNC_HW_IN_FLOW 0x00000400	/* input flow control in effect */
3777c478bd9Sstevel@tonic-gate #define	ASYNC_HW_OUT_FLW 0x00000800	/* output flow control in effect */
3787c478bd9Sstevel@tonic-gate #define	ASYNC_PROGRESS	 0x00001000	/* made progress on output effort */
3797c478bd9Sstevel@tonic-gate #define	ASYNC_CLOSING	 0x00002000	/* processing close on stream */
3807c478bd9Sstevel@tonic-gate #define	ASYNC_OUT_SUSPEND 0x00004000    /* waiting for TIOCSBRK to finish */
3817c478bd9Sstevel@tonic-gate #define	ASYNC_HOLD_UTBRK 0x00008000	/* waiting for untimed break hold */
3827c478bd9Sstevel@tonic-gate 					/* the minimum time */
3837c478bd9Sstevel@tonic-gate #define	ASYNC_DTR_DELAY  0x00010000	/* delaying DTR turn on */
3847c478bd9Sstevel@tonic-gate #define	ASYNC_SW_IN_FLOW 0x00020000	/* sw input flow control in effect */
3857c478bd9Sstevel@tonic-gate #define	ASYNC_SW_OUT_FLW 0x00040000	/* sw output flow control in effect */
3867c478bd9Sstevel@tonic-gate #define	ASYNC_SW_IN_NEEDED 0x00080000	/* sw input flow control char is */
3877c478bd9Sstevel@tonic-gate 					/* needed to be sent */
3887c478bd9Sstevel@tonic-gate #define	ASYNC_OUT_FLW_RESUME 0x00100000 /* output need to be resumed */
3897c478bd9Sstevel@tonic-gate 					/* because of transition of flow */
3907c478bd9Sstevel@tonic-gate 					/* control from stop to start */
3912df1fe9cSrandyf #define	ASYNC_DDI_SUSPENDED  0x00200000	/* suspended by DDI */
3922df1fe9cSrandyf #define	ASYNC_RESUME_BUFCALL 0x00400000	/* call bufcall when resumed by DDI */
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate /* asy_hwtype definitions */
3957c478bd9Sstevel@tonic-gate #define	ASY8250A	0x2		/* 8250A or 16450 */
3967c478bd9Sstevel@tonic-gate #define	ASY16550	0x3		/* broken FIFO which must not be used */
3977c478bd9Sstevel@tonic-gate #define	ASY16550A	0x4		/* usable FIFO */
3987c478bd9Sstevel@tonic-gate #define	ASY16650	0x5
3997c478bd9Sstevel@tonic-gate #define	ASY16750	0x6
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate /* definitions for asy_flags field */
4027c478bd9Sstevel@tonic-gate #define	ASY_NEEDSOFT	0x00000001
4037c478bd9Sstevel@tonic-gate #define	ASY_DOINGSOFT	0x00000002
4047c478bd9Sstevel@tonic-gate #define	ASY_PPS		0x00000004
4057c478bd9Sstevel@tonic-gate #define	ASY_PPS_EDGE	0x00000008
4067c478bd9Sstevel@tonic-gate #define	ASY_DOINGSOFT_RETRY	0x00000010
4077c478bd9Sstevel@tonic-gate #define	ASY_RTS_DTR_OFF	0x00000020
4087c478bd9Sstevel@tonic-gate #define	ASY_IGNORE_CD	0x00000040
4097c478bd9Sstevel@tonic-gate #define	ASY_CONSOLE	0x00000080
4102df1fe9cSrandyf #define	ASY_DDI_SUSPENDED	0x00000100 /* suspended by DDI */
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate /* definitions for asy_flags2 field */
4137c478bd9Sstevel@tonic-gate #define	ASY2_NO_LOOPBACK 0x00000001	/* Device doesn't support loopback */
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate /* definitions for async_inflow_source field in struct asyncline */
4167c478bd9Sstevel@tonic-gate #define	IN_FLOW_NULL	0x00000000
4177c478bd9Sstevel@tonic-gate #define	IN_FLOW_RINGBUFF	0x00000001
4187c478bd9Sstevel@tonic-gate #define	IN_FLOW_STREAMS	0x00000002
4197c478bd9Sstevel@tonic-gate #define	IN_FLOW_USER	0x00000004
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate /*
4227c478bd9Sstevel@tonic-gate  * OUTLINE defines the high-order flag bit in the minor device number that
4237c478bd9Sstevel@tonic-gate  * controls use of a tty line for dialin and dialout simultaneously.
4247c478bd9Sstevel@tonic-gate  */
4257c478bd9Sstevel@tonic-gate #ifdef _LP64
4267c478bd9Sstevel@tonic-gate #define	OUTLINE		(1 << (NBITSMINOR32 - 1))
4277c478bd9Sstevel@tonic-gate #else
4287c478bd9Sstevel@tonic-gate #define	OUTLINE		(1 << (NBITSMINOR - 1))
4297c478bd9Sstevel@tonic-gate #endif
4307c478bd9Sstevel@tonic-gate #define	UNIT(x)		(getminor(x) & ~OUTLINE)
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate  * ASYSETSOFT macro to pend a soft interrupt if one isn't already pending.
4347c478bd9Sstevel@tonic-gate  */
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate #define	ASYSETSOFT(asy)	{			\
437*cd43c54aSZach Kissel 	if (mutex_tryenter(&asy->asy_soft_lock)) {	\
4387c478bd9Sstevel@tonic-gate 		asy->asy_flags |= ASY_NEEDSOFT;		\
439*cd43c54aSZach Kissel 		if (!asy->asysoftpend) {		\
440*cd43c54aSZach Kissel 			asy->asysoftpend = 1;		\
441*cd43c54aSZach Kissel 			mutex_exit(&asy->asy_soft_lock);	\
442*cd43c54aSZach Kissel 			ddi_trigger_softintr(asy->asy_softintr_id);	\
4437c478bd9Sstevel@tonic-gate 		}					\
4447c478bd9Sstevel@tonic-gate 		else					\
445*cd43c54aSZach Kissel 			mutex_exit(&asy->asy_soft_lock);	\
446*cd43c54aSZach Kissel 	}							\
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate #ifdef __cplusplus
4507c478bd9Sstevel@tonic-gate }
4517c478bd9Sstevel@tonic-gate #endif
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate #endif	/* _SYS_ASY_H */
454