1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _TTYMUX_IMPL_H 28*0Sstevel@tonic-gate #define _TTYMUX_IMPL_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #ifdef __cplusplus 33*0Sstevel@tonic-gate extern "C" { 34*0Sstevel@tonic-gate #endif 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #include <sys/types32.h> 37*0Sstevel@tonic-gate #include <sys/param.h> 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate /* 40*0Sstevel@tonic-gate * Local definitions. 41*0Sstevel@tonic-gate */ 42*0Sstevel@tonic-gate #define SM_TRBIT(code) (1 << (code)-'@') 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate extern uint_t sm_max_units; 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate #define MAX_LQS (sm_max_units) 47*0Sstevel@tonic-gate #define NLUNITS (MAX_LQS + 2) 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate /* 50*0Sstevel@tonic-gate * Re-use minor device encoding used by the se(7D) driver. 51*0Sstevel@tonic-gate */ 52*0Sstevel@tonic-gate #define ASYNC_DEVICE (0) 53*0Sstevel@tonic-gate #define OUTLINE (1 << (NBITSMINOR32 - 1)) 54*0Sstevel@tonic-gate #define NULL_PROTOCOL 0 55*0Sstevel@tonic-gate #define ASYN_PROTOCOL 1 56*0Sstevel@tonic-gate #define OUTD_PROTOCOL 2 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate #define DEV_TO_UNIT(dev) (getminor(dev) & ~OUTLINE) 59*0Sstevel@tonic-gate #define DEV_TO_PROTOBITS(dev) (getminor(dev) & OUTLINE) 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate /* 62*0Sstevel@tonic-gate * Driver id 63*0Sstevel@tonic-gate */ 64*0Sstevel@tonic-gate #define SM_MOD_ID 0x534d 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate /* 67*0Sstevel@tonic-gate * Access modes of the two halves to each others flags 68*0Sstevel@tonic-gate * Q uq->flags lq->flags 69*0Sstevel@tonic-gate * uq rw r 70*0Sstevel@tonic-gate * lq - rw 71*0Sstevel@tonic-gate */ 72*0Sstevel@tonic-gate /* 73*0Sstevel@tonic-gate * A lower queue is associated with an upper queue 74*0Sstevel@tonic-gate * (used for synchronising dissasociate reqests with the lower half) 75*0Sstevel@tonic-gate * A lower q will not forward messages if SM_UQVALID is set in uqflags. 76*0Sstevel@tonic-gate */ 77*0Sstevel@tonic-gate #define SM_UQVALID (0x1) /* written by an upper q read by a lower q */ 78*0Sstevel@tonic-gate #define SM_OBPCNDEV (0x2) /* set when this device is an OBP console */ 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate /* 81*0Sstevel@tonic-gate * unused flags 82*0Sstevel@tonic-gate */ 83*0Sstevel@tonic-gate #define FLUSHR_PEND (0x1) /* M_FLUSH is expected on all the lr q's */ 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate /* 86*0Sstevel@tonic-gate * An open has completed on this stream. 87*0Sstevel@tonic-gate */ 88*0Sstevel@tonic-gate #define FULLY_OPEN (0x2) 89*0Sstevel@tonic-gate #define EXCL_OPEN (0x4) 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate #define SM_CARON (0x8) 92*0Sstevel@tonic-gate /* 93*0Sstevel@tonic-gate * Flags to disable queues controlled from below. 94*0Sstevel@tonic-gate */ 95*0Sstevel@tonic-gate #define HANGUP_MODE (0x10) /* not used (sets WERROR_MODE instead) */ 96*0Sstevel@tonic-gate #define RERROR_MODE (0x20) /* read error on stream (unset by closing) */ 97*0Sstevel@tonic-gate #define WERROR_MODE (0x40) /* write side error on the stream (set by */ 98*0Sstevel@tonic-gate /* M_HANGUP/M_ERROR */ 99*0Sstevel@tonic-gate /* unset by M_UNHANGUP/M_ERROR) */ 100*0Sstevel@tonic-gate #define ERROR_MODE (0x60) /* read error on stream (unset by M_ERROR) */ 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate /* 103*0Sstevel@tonic-gate * Flags to disable queues controlled from above. 104*0Sstevel@tonic-gate * Also used by set on queues which are OBP consoles 105*0Sstevel@tonic-gate */ 106*0Sstevel@tonic-gate #define SM_STOPPED (0x080) /* M_STOP has been seen */ 107*0Sstevel@tonic-gate #define SM_ISTOPPED (0x100) /* M_STOPI has been seen */ 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate /* 110*0Sstevel@tonic-gate * A stream wants something. 111*0Sstevel@tonic-gate */ 112*0Sstevel@tonic-gate #define WANT_SC (0x200) /* carrier status of a stream required */ 113*0Sstevel@tonic-gate #define WANT_CL (0x400) /* CLOCAL status of a stream required */ 114*0Sstevel@tonic-gate #define WANT_CD (0x800) /* CD modem status of a line required */ 115*0Sstevel@tonic-gate #define WANT_CDSTAT (0xe00) 116*0Sstevel@tonic-gate #define WANT_TCSET (0x20000) /* send down initial termios settings */ 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate #define WANT_RENB (0x40000) /* read q is flowcontrolled */ 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate #define SM_IOCPENDING (0x80000) 121*0Sstevel@tonic-gate #define SM_CLOSE (0x100000) 122*0Sstevel@tonic-gate #define SM_INTERNALIOC (0x200000) 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate #define SM_LOGINREQ (0x400000) 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate #define LOCK_UNIT(u) (mutex_enter(u->sm_umutex)) /* Lock per-stream data */ 127*0Sstevel@tonic-gate #define UNLOCK_UNIT(u) (mutex_exit(u->sm_umutex)) /* Unlock per-stream data */ 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate /* 130*0Sstevel@tonic-gate * Checks whether an open could potentially block. 131*0Sstevel@tonic-gate */ 132*0Sstevel@tonic-gate #define BLOCKING(unitp, proto, flag) \ 133*0Sstevel@tonic-gate (!(flag & (FNDELAY|FNONBLOCK)) && \ 134*0Sstevel@tonic-gate !(proto == OUTLINE) && \ 135*0Sstevel@tonic-gate unitp->sm_lqs && \ 136*0Sstevel@tonic-gate (unitp->sm_flags & SM_CARON) == 0) 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate /* 139*0Sstevel@tonic-gate * Update termios style control flag with a termio style flag. 140*0Sstevel@tonic-gate */ 141*0Sstevel@tonic-gate #define SM_SETCFLAG(qi, tc) \ 142*0Sstevel@tonic-gate qi->sm_ttycommon->t_cflag = \ 143*0Sstevel@tonic-gate (qi->sm_ttycommon->t_cflag & 0xffff0000 | (tc)->c_cflag) 144*0Sstevel@tonic-gate #define SM_SETLFLAG(qi, tc) \ 145*0Sstevel@tonic-gate qi->sm_ttycommon->t_iflag = \ 146*0Sstevel@tonic-gate (qi->sm_ttycommon->t_iflag & 0xffff0000 | (tc)->c_iflag) 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate #define SM_WQ(qi) (qi->sm_ttycommon->t_writeq) 149*0Sstevel@tonic-gate #define SM_RQ(qi) (qi->sm_ttycommon->t_readq) 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate /* 152*0Sstevel@tonic-gate * 153*0Sstevel@tonic-gate */ 154*0Sstevel@tonic-gate struct sm_iocinfo { 155*0Sstevel@tonic-gate int sm_id; 156*0Sstevel@tonic-gate int sm_cmd; 157*0Sstevel@tonic-gate void *sm_data; 158*0Sstevel@tonic-gate }; 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate /* 161*0Sstevel@tonic-gate * Perform a per instance search for a specified per stream structure. 162*0Sstevel@tonic-gate */ 163*0Sstevel@tonic-gate #define get_lqi(ssp, unit) \ 164*0Sstevel@tonic-gate ((unit < MAX_LQS) ? &ssp->sm_lqs[unit] : 0) 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate #define get_uqi(ssp, unit) \ 167*0Sstevel@tonic-gate ((unit < NLUNITS) ? &ssp->sm_uqs[unit] : NULL) 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate #define CNTRL(c) ((c)&037) 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate #define sm_allocb(size, pri) allocb(size, pri) 172*0Sstevel@tonic-gate #define sm_copymsg(mp) ((DB_TYPE(mp) == M_DATA) ? dupmsg(mp) : copymsg(mp)) 173*0Sstevel@tonic-gate #define sm_freemsg(mp) freemsg(mp) 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate /* 176*0Sstevel@tonic-gate * macro to improve performance. The cond is checked before deciding whether 177*0Sstevel@tonic-gate * to create a new stack frame for the debug call 178*0Sstevel@tonic-gate * Calls to sm_dbg should not occur in hanging statements - alternatively 179*0Sstevel@tonic-gate * bracket SM_CMD with a do .... while (0) 180*0Sstevel@tonic-gate */ 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate #define SM_CMD(cond, stmt) { if (cond) stmt; } 183*0Sstevel@tonic-gate #define sm_dbg(lvl, args) SM_CMD(sm_ssp->sm_trflag & SM_TRBIT(lvl), \ 184*0Sstevel@tonic-gate sm_debug args) 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate #define SM_SLOT_RED 3 187*0Sstevel@tonic-gate #define SM_MAX_SLOT_WAIT 3 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate #define sm_dev2unit(dev) (getminor(dev) & ~OUTLINE) 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate #define LQI2ASSOC(a, l) \ 192*0Sstevel@tonic-gate (a)->ttymux_linkid = (l)->sm_linkid; \ 193*0Sstevel@tonic-gate (a)->ttymux_tag = (l)->sm_tag; \ 194*0Sstevel@tonic-gate (a)->ttymux_ioflag = (l)->sm_ioflag; \ 195*0Sstevel@tonic-gate (a)->ttymux_ldev = (l)->sm_dev; \ 196*0Sstevel@tonic-gate (a)->ttymux_udev = ((l)->sm_uqi == 0) ? NODEV : \ 197*0Sstevel@tonic-gate makedevice(ddi_driver_major(sm_ssp->sm_dip), \ 198*0Sstevel@tonic-gate (l)->sm_uqi->sm_lunit); \ 199*0Sstevel@tonic-gate (void) strncpy((a)->ttymux_path, (l)->sm_path, MAXPATHLEN) 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate #define LQI2ASSOC32(a, l) \ 202*0Sstevel@tonic-gate (a)->ttymux32_linkid = (l)->sm_linkid; \ 203*0Sstevel@tonic-gate (a)->ttymux32_tag = (uint32_t)(l)->sm_tag; \ 204*0Sstevel@tonic-gate (a)->ttymux32_ioflag = (l)->sm_ioflag; \ 205*0Sstevel@tonic-gate (void) cmpldev(&(a)->ttymux32_ldev, (l)->sm_dev);\ 206*0Sstevel@tonic-gate (a)->ttymux32_udev = ((l)->sm_uqi == 0) ? NODEV32 : \ 207*0Sstevel@tonic-gate ((void) cmpldev(&(a)->ttymux32_udev, \ 208*0Sstevel@tonic-gate makedevice(ddi_driver_major(sm_ssp->sm_dip), \ 209*0Sstevel@tonic-gate (l)->sm_uqi->sm_lunit)), \ 210*0Sstevel@tonic-gate (a)->ttymux32_udev); \ 211*0Sstevel@tonic-gate (void) strncpy((a)->ttymux32_path, (l)->sm_path, MAXPATHLEN) 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate #define CNTRL(c) ((c)&037) 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate /* 216*0Sstevel@tonic-gate * 32 bit eqivalents of structures defined in sys/ttymuxuser.h 217*0Sstevel@tonic-gate */ 218*0Sstevel@tonic-gate typedef struct ttymux_association32 { 219*0Sstevel@tonic-gate 220*0Sstevel@tonic-gate dev32_t ttymux32_udev; /* the upper device to be associated */ 221*0Sstevel@tonic-gate dev32_t ttymux32_ldev; 222*0Sstevel@tonic-gate /* the device type of a linked lower stream */ 223*0Sstevel@tonic-gate int ttymux32_linkid; 224*0Sstevel@tonic-gate /* the linkid of a linked lower stream */ 225*0Sstevel@tonic-gate uint32_t ttymux32_tag; /* tagged association */ 226*0Sstevel@tonic-gate uint_t ttymux32_ioflag; /* FORINPUT FOROUTPUT FORIO */ 227*0Sstevel@tonic-gate char ttymux32_path[MAXPATHLEN]; /* device path */ 228*0Sstevel@tonic-gate } ttymux_assoc32_t; 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate typedef struct ttymux_associations32 { 231*0Sstevel@tonic-gate uint32_t ttymux32_nlinks; 232*0Sstevel@tonic-gate caddr32_t ttymux32_assocs; 233*0Sstevel@tonic-gate } ttymux_assocs32_t; 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate #ifdef __cplusplus 236*0Sstevel@tonic-gate } 237*0Sstevel@tonic-gate #endif 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate #endif /* _TTYMUX_IMPL_H */ 240