11991Sheppo /* 21991Sheppo * CDDL HEADER START 31991Sheppo * 41991Sheppo * The contents of this file are subject to the terms of the 51991Sheppo * Common Development and Distribution License (the "License"). 61991Sheppo * You may not use this file except in compliance with the License. 71991Sheppo * 81991Sheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91991Sheppo * or http://www.opensolaris.org/os/licensing. 101991Sheppo * See the License for the specific language governing permissions 111991Sheppo * and limitations under the License. 121991Sheppo * 131991Sheppo * When distributing Covered Code, include this CDDL HEADER in each 141991Sheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151991Sheppo * If applicable, add the following below this CDDL HEADER, with the 161991Sheppo * fields enclosed by brackets "[]" replaced with your own identifying 171991Sheppo * information: Portions Copyright [yyyy] [name of copyright owner] 181991Sheppo * 191991Sheppo * CDDL HEADER END 201991Sheppo */ 211991Sheppo 221991Sheppo /* 231991Sheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 241991Sheppo * Use is subject to license terms. 251991Sheppo */ 261991Sheppo 271991Sheppo #ifndef _VLDC_IMPL_H 281991Sheppo #define _VLDC_IMPL_H 291991Sheppo 301991Sheppo #pragma ident "%Z%%M% %I% %E% SMI" 311991Sheppo 321991Sheppo #ifdef __cplusplus 331991Sheppo extern "C" { 341991Sheppo #endif 351991Sheppo 361991Sheppo #include <sys/stream.h> 371991Sheppo #include <sys/ddi.h> 381991Sheppo #include <sys/sunddi.h> 391991Sheppo #include <sys/ldc.h> 401991Sheppo #include <sys/vldc.h> 411991Sheppo 421991Sheppo /* default values */ 431991Sheppo #define VLDC_DEFAULT_MTU 0x800 /* default mtu size */ 441991Sheppo 451991Sheppo /* VLDC limits */ 461991Sheppo #define VLDC_MAX_COOKIE 0x40000 /* max. size of xfer to/from HV */ 471991Sheppo #define VLDC_MAX_MTU 0x40000 /* 256K */ 481991Sheppo #define VLDC_MAX_PORTS 0x800 491991Sheppo #define VLDC_MAX_MINORS VLDC_MAX_PORTS 501991Sheppo #define VLDC_QUEUE_LEN 0x80 511991Sheppo 521991Sheppo #define VLDC_MINOR_MASK (VLDC_MAX_PORTS - 1) 531991Sheppo #define VLDC_INST_SHIFT 11 541991Sheppo 55*2336Snarayan #define VLDC_HVCTL_SVCNAME "hvctl" 56*2336Snarayan 571991Sheppo /* get port number from minor number */ 581991Sheppo #define VLDCPORT(vldcp, minor) \ 591991Sheppo ((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK].portno) 601991Sheppo 611991Sheppo /* get minor table entry from minor number */ 621991Sheppo #define VLDCMINOR(vldcp, minor) \ 631991Sheppo (&((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK])) 641991Sheppo 651991Sheppo /* get instance number from minor number */ 661991Sheppo #define VLDCINST(minor) ((minor) >> VLDC_INST_SHIFT) 671991Sheppo 681991Sheppo /* indicates an invalid port number */ 691991Sheppo #define VLDC_INVALID_PORTNO ((uint_t)-1) 701991Sheppo 711991Sheppo /* 721991Sheppo * Minor node number to port number mapping table. 731991Sheppo * 741991Sheppo * The lock field in the vldc_minor structure is used to serialize operations 751991Sheppo * on the port associated with the minor node. It also protects the minor node 761991Sheppo * in_use field which is used to track the number of active users of the minor 771991Sheppo * node. Driver ops will either hold the lock over the whole operation or 781991Sheppo * will increment (and then decrement) the in use count if they need to 791991Sheppo * release and re-acquire the lock, e.g. when copying data in from or out to 801991Sheppo * userland. When the MDEG framework calls into the driver via the callback to 811991Sheppo * remove a port, the driver must wait until the in use count for the minor 821991Sheppo * node associated with the port drops to zero, before it can remove the 831991Sheppo * port. 841991Sheppo */ 851991Sheppo typedef struct vldc_minor { 861991Sheppo kmutex_t lock; /* protects port/in_use count */ 871991Sheppo kcondvar_t cv; /* for waiting on in use */ 881991Sheppo uint_t in_use; /* in use counter */ 891991Sheppo uint_t portno; /* port number */ 901991Sheppo char sname[MAXPATHLEN]; /* service name */ 911991Sheppo } vldc_minor_t; 921991Sheppo 931991Sheppo typedef struct vldc_port { 941991Sheppo uint_t number; /* port number */ 951991Sheppo uint32_t status; /* port status */ 961991Sheppo vldc_minor_t *minorp; /* minor table entry pointer */ 971991Sheppo uint32_t mtu; /* port mtu */ 981991Sheppo caddr_t send_buf; /* send buffer */ 991991Sheppo caddr_t recv_buf; /* receive buffer */ 100*2336Snarayan caddr_t cookie_buf; /* rd/wr cookie buffer */ 1011991Sheppo 1021991Sheppo uint64_t ldc_id; /* Channel number */ 1031991Sheppo ldc_handle_t ldc_handle; /* Channel handle */ 1041991Sheppo ldc_mode_t ldc_mode; /* Channel mode */ 1051991Sheppo 1061991Sheppo boolean_t is_stream; /* streaming mode */ 1071991Sheppo boolean_t hanged_up; /* port hanged up */ 1081991Sheppo 1091991Sheppo struct pollhead poll; /* for poll */ 1101991Sheppo } vldc_port_t; 1111991Sheppo 1121991Sheppo /* 1131991Sheppo * vldc driver's soft state structure 1141991Sheppo */ 1151991Sheppo typedef struct vldc { 1161991Sheppo kmutex_t lock; /* serializes detach and MDEG */ 1171991Sheppo boolean_t detaching; /* true iff busy detaching */ 1181991Sheppo dev_info_t *dip; /* dev_info */ 1191991Sheppo mdeg_node_spec_t *inst_spec; /* vldc instance specifier */ 1201991Sheppo mdeg_handle_t mdeg_hdl; /* MD event handle */ 1211991Sheppo 1221991Sheppo uint_t num_ports; 1231991Sheppo vldc_port_t port[VLDC_MAX_PORTS]; 1241991Sheppo 1251991Sheppo /* table for assigned minors */ 1261991Sheppo vldc_minor_t minor_tbl[VLDC_MAX_MINORS]; 1271991Sheppo 1281991Sheppo /* number of minors already assigned */ 1291991Sheppo uint_t minors_assigned; 1301991Sheppo } vldc_t; 1311991Sheppo 1321991Sheppo #ifdef __cplusplus 1331991Sheppo } 1341991Sheppo #endif 1351991Sheppo 1361991Sheppo #endif /* _VLDC_IMPL_H */ 137