1*1991Sheppo /* 2*1991Sheppo * CDDL HEADER START 3*1991Sheppo * 4*1991Sheppo * The contents of this file are subject to the terms of the 5*1991Sheppo * Common Development and Distribution License (the "License"). 6*1991Sheppo * You may not use this file except in compliance with the License. 7*1991Sheppo * 8*1991Sheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*1991Sheppo * or http://www.opensolaris.org/os/licensing. 10*1991Sheppo * See the License for the specific language governing permissions 11*1991Sheppo * and limitations under the License. 12*1991Sheppo * 13*1991Sheppo * When distributing Covered Code, include this CDDL HEADER in each 14*1991Sheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*1991Sheppo * If applicable, add the following below this CDDL HEADER, with the 16*1991Sheppo * fields enclosed by brackets "[]" replaced with your own identifying 17*1991Sheppo * information: Portions Copyright [yyyy] [name of copyright owner] 18*1991Sheppo * 19*1991Sheppo * CDDL HEADER END 20*1991Sheppo */ 21*1991Sheppo 22*1991Sheppo /* 23*1991Sheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24*1991Sheppo * Use is subject to license terms. 25*1991Sheppo */ 26*1991Sheppo 27*1991Sheppo #ifndef _VCC_IMPL_H 28*1991Sheppo #define _VCC_IMPL_H 29*1991Sheppo 30*1991Sheppo #pragma ident "%Z%%M% %I% %E% SMI" 31*1991Sheppo 32*1991Sheppo #ifdef __cplusplus 33*1991Sheppo extern "C" { 34*1991Sheppo #endif 35*1991Sheppo 36*1991Sheppo #include <sys/types.h> 37*1991Sheppo #include <sys/stream.h> 38*1991Sheppo #include <sys/ddi.h> 39*1991Sheppo #include <sys/sunddi.h> 40*1991Sheppo #include <sys/ioctl.h> 41*1991Sheppo #include <sys/vcc.h> 42*1991Sheppo 43*1991Sheppo #define VCC_DEV_TO_INST(dev) (getminor(dev)) 44*1991Sheppo #define VCC_INST_TO_DEV(instance) (instance) 45*1991Sheppo 46*1991Sheppo #define VCC_DRIVER_NAME "vcc" 47*1991Sheppo #define VCC_NAME VCC_DRIVER_NAME 48*1991Sheppo 49*1991Sheppo /* 50*1991Sheppo * VCC Port States 51*1991Sheppo */ 52*1991Sheppo 53*1991Sheppo /* 54*1991Sheppo * There is one lock in port structure to protect the states of the port. 55*1991Sheppo * States of the port are: 56*1991Sheppo * 1. VCC_PORT_AVAIL 57*1991Sheppo * 2. VCC_PORT_OPEN 58*1991Sheppo * 3. VCC_PORT_USE_READ_LDC - There is a thread doing vcc_read. 59*1991Sheppo * 4. VCC_PORT_USE_WRITE_LDC - There is a thread doing vcc_write. 60*1991Sheppo * 6. VCC_PORT_LDC_DATA_READY - Data is ready from ldc. 61*1991Sheppo * 5. VCC_PORT_LDC_WRITE_READY - Ldc has space to receive data. 62*1991Sheppo * 7. VCC_PORT_LDC_CHANNEL_READY - Ldc channel is up. 63*1991Sheppo * 8. VCC_PORT_ADDED - A new port was added. 64*1991Sheppo * 9. VCC_PORT_TERM_RD - Terminal read is enabled vs suspended 65*1991Sheppo * 10. VCC_PORT_TERM_WR - Terminal write is enabled vc suspended 66*1991Sheppo * 11. VCC_PORT_NONBLOCK - A port was opened with non blocking flag. 67*1991Sheppo * 12. VCC_PORT_LDC_LINK_DOWN 68*1991Sheppo * 69*1991Sheppo * 70*1991Sheppo * Code flow for port to transit from one state to another is as the follows: 71*1991Sheppo * 72*1991Sheppo * 1. VCC_PORT_AVAIL 73*1991Sheppo * 74*1991Sheppo * Transition from unavailable to available 75*1991Sheppo * - obtain port lock 76*1991Sheppo * Transit port to available and added states 77*1991Sheppo * - release port lock 78*1991Sheppo * - obtain softstate lock 79*1991Sheppo * Increase total number of ports 80*1991Sheppo * - release softsate lock 81*1991Sheppo * 82*1991Sheppo * after download added port to vntsd 83*1991Sheppo * - obtain port lock 84*1991Sheppo * Transit port to not added state 85*1991Sheppo * - release port lock 86*1991Sheppo * 87*1991Sheppo * Transition from available to unavailable 88*1991Sheppo * - obtain port lock 89*1991Sheppo * - cv_wait read available 90*1991Sheppo * Transit port to read unavailable 91*1991Sheppo * - cv_wait write available 92*1991Sheppo * Transit port to write unavailable 93*1991Sheppo * Transit port to not ready. (close ldc channel) 94*1991Sheppo * Transit port to deleted state 95*1991Sheppo * Transit port to read and write available 96*1991Sheppo * - cv_broadcast 97*1991Sheppo * - release lock 98*1991Sheppo * 99*1991Sheppo * vntsd close the deleted port 100*1991Sheppo * - obtained port lock 101*1991Sheppo * Transit port to close and deleted state 102*1991Sheppo * - release port lock 103*1991Sheppo * 104*1991Sheppo * after vntsd deletion of the port 105*1991Sheppo * - obtain softstate lock 106*1991Sheppo * - cv_wait port table unlocked 107*1991Sheppo * Transit softstate to port table locked 108*1991Sheppo * - release softstate lock 109*1991Sheppo * - obtain port lock 110*1991Sheppo * Transit port to unavailable 111*1991Sheppo * destroy port lock 112*1991Sheppo * - obtain softstate lock 113*1991Sheppo * Transit softstate to port table unlocked 114*1991Sheppo * - cv_broadcast 115*1991Sheppo * - release softsate lock 116*1991Sheppo * 117*1991Sheppo * 2. VCC_PORT_OPEN 118*1991Sheppo * 119*1991Sheppo * Transition from close to open 120*1991Sheppo * - obtain port lock 121*1991Sheppo * transit port to open 122*1991Sheppo * - release port lock 123*1991Sheppo * 124*1991Sheppo * Transition from open to close 125*1991Sheppo * - obtain port lock 126*1991Sheppo * - cv_wait read available 127*1991Sheppo * Transit port to read unavailable 128*1991Sheppo * - cv_wait write available 129*1991Sheppo * Transit port to write unavailable 130*1991Sheppo * Transit port to not ready. (close ldc channel) 131*1991Sheppo * Transit port to close state 132*1991Sheppo * Transit port to read and write available 133*1991Sheppo * - cv_broadcast 134*1991Sheppo * - release lock 135*1991Sheppo * 136*1991Sheppo * 3. VCC_PORT_USE_READ_LDC/VCC_PORT_USE_WRITE_LDC 137*1991Sheppo * Transition from read availale/write available 138*1991Sheppo * to read unavailable/write unavailable 139*1991Sheppo * - obtain port lock 140*1991Sheppo * - cv_wait read available 141*1991Sheppo * Transit to read/write unavailable 142*1991Sheppo * - release port lock 143*1991Sheppo * 144*1991Sheppo * Transition from read unavailale/write unavailable 145*1991Sheppo * to read available/write available 146*1991Sheppo * - obtain port lock 147*1991Sheppo * Transit to read/write available 148*1991Sheppo * - cv_broadcast 149*1991Sheppo * - release port lock 150*1991Sheppo * 151*1991Sheppo * 4. VCC_PORT_LDC_CHANNEL_READY 152*1991Sheppo * Transition from data not ready to data ready 153*1991Sheppo * - obtain port lock 154*1991Sheppo * Transit to data ready 155*1991Sheppo * - cv_broadcast 156*1991Sheppo * - release port lock 157*1991Sheppo * 158*1991Sheppo * Transition from data ready to data not ready 159*1991Sheppo * - obtain port lock 160*1991Sheppo * Transit to data not ready 161*1991Sheppo * - release port lock 162*1991Sheppo */ 163*1991Sheppo 164*1991Sheppo #define VCC_PORT_AVAIL 0x1 /* port is configured */ 165*1991Sheppo #define VCC_PORT_OPEN 0x2 /* port is opened */ 166*1991Sheppo #define VCC_PORT_LDC_CHANNEL_READY 0x4 /* ready for data transfer */ 167*1991Sheppo #define VCC_PORT_USE_READ_LDC 0x8 /* read lock */ 168*1991Sheppo #define VCC_PORT_USE_WRITE_LDC 0x10 /* write lock */ 169*1991Sheppo #define VCC_PORT_LDC_DATA_READY 0x20 /* data ready */ 170*1991Sheppo #define VCC_PORT_LDC_WRITE_READY 0x40 /* ldc ready receive data */ 171*1991Sheppo #define VCC_PORT_ADDED 0x80 /* added, no ack from vntsd */ 172*1991Sheppo #define VCC_PORT_UPDATED 0x100 /* updated, no ack from vntsd */ 173*1991Sheppo #define VCC_PORT_TERM_RD 0x200 /* suspend write */ 174*1991Sheppo #define VCC_PORT_TERM_WR 0x400 /* suspend read */ 175*1991Sheppo #define VCC_PORT_NONBLOCK 0x800 /* open with non block flag */ 176*1991Sheppo #define VCC_PORT_LDC_LINK_DOWN 0x1000 /* ldc link down */ 177*1991Sheppo 178*1991Sheppo /* Poll Flags */ 179*1991Sheppo #define VCC_POLL_CONFIG 0x1 /* poll configuration change */ 180*1991Sheppo 181*1991Sheppo /* Poll evnets */ 182*1991Sheppo #define VCC_POLL_ADD_PORT 0x10 /* add a console port */ 183*1991Sheppo #define VCC_POLL_UPDATE_PORT 0x20 /* update a console port */ 184*1991Sheppo 185*1991Sheppo /* softstate port table state */ 186*1991Sheppo #define VCC_LOCK_PORT_TBL 0x1 187*1991Sheppo 188*1991Sheppo /* VCC limits */ 189*1991Sheppo #define VCC_MAX_PORTS 0x800 /* number of domains */ 190*1991Sheppo #define VCC_MAX_MINORS VCC_MAX_PORTS /* number of minors */ 191*1991Sheppo 192*1991Sheppo 193*1991Sheppo #define VCC_MAX_PORT_MINORS (VCC_MAX_MINORS - 1) 194*1991Sheppo #define VCC_CONTROL_MINOR_IDX (VCC_MAX_MINORS - 1) 195*1991Sheppo 196*1991Sheppo /* size of vcc message data */ 197*1991Sheppo #define VCC_MTU_SZ 56 198*1991Sheppo 199*1991Sheppo /* Default values */ 200*1991Sheppo #define VCC_HDR_SZ 8 /* header size */ 201*1991Sheppo #define VCC_BUF_SZ (VCC_HDR_SZ + VCC_MTU_SZ) 202*1991Sheppo 203*1991Sheppo #define VCC_CONTROL_PORT 0x7ff /* port 2047 is control port */ 204*1991Sheppo #define VCC_INST_SHIFT 11 205*1991Sheppo #define VCC_INVALID_CHANNEL -1 206*1991Sheppo #define VCC_NO_PID_BLOCKING -1 207*1991Sheppo 208*1991Sheppo #define VCC_MINOR_NAME_PREFIX "ldom-" /* device name prefix */ 209*1991Sheppo 210*1991Sheppo /* HV message data type */ 211*1991Sheppo #define LDC_CONSOLE_CTRL 0x1 /* ctrl msg */ 212*1991Sheppo #define LDC_CONSOLE_DATA 0x2 /* data msg */ 213*1991Sheppo 214*1991Sheppo /* HV control messages */ 215*1991Sheppo #define LDC_CONSOLE_BREAK -1 /* brk */ 216*1991Sheppo #define LDC_CONSOLE_HUP -2 /* hup */ 217*1991Sheppo 218*1991Sheppo /* minor number to port number */ 219*1991Sheppo #define VCCPORT(p, minor) (p->minor_tbl[(minor & \ 220*1991Sheppo VCC_CONTROL_PORT)].portno) 221*1991Sheppo 222*1991Sheppo /* minor number to minor pointer */ 223*1991Sheppo #define VCCMINORP(p, minor) (&(p->minor_tbl[(minor & \ 224*1991Sheppo VCC_CONTROL_PORT)])) 225*1991Sheppo 226*1991Sheppo /* minor number to instance */ 227*1991Sheppo #define VCCINST(minor) ((minor) >> VCC_INST_SHIFT) 228*1991Sheppo 229*1991Sheppo 230*1991Sheppo /* hv console packet format */ 231*1991Sheppo typedef struct vcc_msg { 232*1991Sheppo uint8_t type; /* type - data or ctrl */ 233*1991Sheppo uint8_t size; /* data size */ 234*1991Sheppo uint16_t unused; /* not used */ 235*1991Sheppo int32_t ctrl_msg; /* data if type is ctrl */ 236*1991Sheppo uint8_t data[VCC_MTU_SZ]; /* data if type is data */ 237*1991Sheppo } vcc_msg_t; 238*1991Sheppo 239*1991Sheppo /* 240*1991Sheppo * minor node to port mapping table 241*1991Sheppo */ 242*1991Sheppo typedef struct vcc_minor { 243*1991Sheppo uint_t portno; /* port number */ 244*1991Sheppo char domain_name[MAXPATHLEN]; /* doman name */ 245*1991Sheppo } vcc_minor_t; 246*1991Sheppo 247*1991Sheppo /* console port structure */ 248*1991Sheppo typedef struct vcc_port { 249*1991Sheppo 250*1991Sheppo kmutex_t lock; /* protects port */ 251*1991Sheppo kcondvar_t read_cv; /* cv to sleep for reads */ 252*1991Sheppo kcondvar_t write_cv; /* cv to sleep for writes */ 253*1991Sheppo 254*1991Sheppo uint_t number; /* port number */ 255*1991Sheppo uint32_t status; /* port status */ 256*1991Sheppo 257*1991Sheppo char group_name[MAXPATHLEN]; 258*1991Sheppo uint64_t tcp_port; /* tcp port num */ 259*1991Sheppo 260*1991Sheppo struct termios term; /* terminal emulation */ 261*1991Sheppo 262*1991Sheppo vcc_minor_t *minorp; /* pointer to minor table entry */ 263*1991Sheppo 264*1991Sheppo uint64_t ldc_id; /* Channel number */ 265*1991Sheppo ldc_handle_t ldc_handle; /* Channel handle */ 266*1991Sheppo ldc_status_t ldc_status; /* Channel Status */ 267*1991Sheppo 268*1991Sheppo uint_t pollflag; /* indicated poll status */ 269*1991Sheppo struct pollhead poll; 270*1991Sheppo uint32_t pollevent; 271*1991Sheppo pid_t valid_pid; /* pid that allows cb_ops */ 272*1991Sheppo 273*1991Sheppo } vcc_port_t; 274*1991Sheppo 275*1991Sheppo /* 276*1991Sheppo * vcc driver's soft state structure 277*1991Sheppo */ 278*1991Sheppo typedef struct vcc { 279*1991Sheppo 280*1991Sheppo /* protects vcc_t (soft state) */ 281*1991Sheppo kmutex_t lock; 282*1991Sheppo 283*1991Sheppo uint_t status; 284*1991Sheppo 285*1991Sheppo dev_info_t *dip; /* dev_info */ 286*1991Sheppo 287*1991Sheppo mdeg_node_spec_t *md_ispecp; /* mdeg prop spec */ 288*1991Sheppo mdeg_handle_t mdeg_hdl; /* mdeg handle */ 289*1991Sheppo 290*1991Sheppo vcc_port_t port[VCC_MAX_PORTS]; /* port table */ 291*1991Sheppo uint_t num_ports; /* avail ports */ 292*1991Sheppo 293*1991Sheppo vcc_minor_t minor_tbl[VCC_MAX_PORTS]; /* minor table */ 294*1991Sheppo uint_t minors_assigned; /* assigned minors */ 295*1991Sheppo } vcc_t; 296*1991Sheppo 297*1991Sheppo #ifdef __cplusplus 298*1991Sheppo } 299*1991Sheppo #endif 300*1991Sheppo 301*1991Sheppo #endif /* _VCC_IMPL_H */ 302