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