1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _VLDC_IMPL_H 28 #define _VLDC_IMPL_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #include <sys/stream.h> 37 #include <sys/ddi.h> 38 #include <sys/sunddi.h> 39 #include <sys/ldc.h> 40 #include <sys/vldc.h> 41 42 /* default values */ 43 #define VLDC_DEFAULT_MTU 0x1000 /* default mtu size 4K */ 44 45 /* VLDC limits */ 46 #define VLDC_MAX_COOKIE 0x40000 /* max. size of xfer to/from HV */ 47 #define VLDC_MAX_MTU 0x40000 /* 256K */ 48 #define VLDC_MAX_PORTS 0x800 49 #define VLDC_MAX_MINORS VLDC_MAX_PORTS 50 51 #define VLDC_MINOR_MASK (VLDC_MAX_PORTS - 1) 52 #define VLDC_INST_SHIFT 11 53 54 #define VLDC_HVCTL_SVCNAME "hvctl" 55 56 /* get port number from minor number */ 57 #define VLDCPORT(vldcp, minor) \ 58 ((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK].portno) 59 60 /* get minor table entry from minor number */ 61 #define VLDCMINOR(vldcp, minor) \ 62 (&((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK])) 63 64 /* get instance number from minor number */ 65 #define VLDCINST(minor) ((minor) >> VLDC_INST_SHIFT) 66 67 /* indicates an invalid port number */ 68 #define VLDC_INVALID_PORTNO ((uint_t)-1) 69 70 /* 71 * Minor node number to port number mapping table. 72 * 73 * The lock field in the vldc_minor structure is used to serialize operations 74 * on the port associated with the minor node. It also protects the minor node 75 * in_use field which is used to track the number of active users of the minor 76 * node. Driver ops will either hold the lock over the whole operation or 77 * will increment (and then decrement) the in use count if they need to 78 * release and re-acquire the lock, e.g. when copying data in from or out to 79 * userland. When the MDEG framework calls into the driver via the callback to 80 * remove a port, the driver must wait until the in use count for the minor 81 * node associated with the port drops to zero, before it can remove the 82 * port. 83 */ 84 typedef struct vldc_minor { 85 kmutex_t lock; /* protects port/in_use count */ 86 kcondvar_t cv; /* for waiting on in use */ 87 uint_t in_use; /* in use counter */ 88 uint_t portno; /* port number */ 89 char sname[MAXPATHLEN]; /* service name */ 90 } vldc_minor_t; 91 92 typedef struct vldc_port { 93 uint_t number; /* port number */ 94 uint32_t status; /* port status */ 95 uint_t inst; /* vldc instance */ 96 vldc_minor_t *minorp; /* minor table entry pointer */ 97 uint32_t mtu; /* port mtu */ 98 caddr_t send_buf; /* send buffer */ 99 caddr_t recv_buf; /* receive buffer */ 100 caddr_t cookie_buf; /* rd/wr cookie buffer */ 101 102 uint64_t ldc_id; /* Channel number */ 103 ldc_handle_t ldc_handle; /* Channel handle */ 104 ldc_mode_t ldc_mode; /* Channel mode */ 105 106 boolean_t is_stream; /* streaming mode */ 107 boolean_t hanged_up; /* port hanged up */ 108 109 struct pollhead poll; /* for poll */ 110 } vldc_port_t; 111 112 /* 113 * vldc driver's soft state structure 114 */ 115 typedef struct vldc { 116 kmutex_t lock; /* serializes detach and MDEG */ 117 boolean_t detaching; /* true iff busy detaching */ 118 dev_info_t *dip; /* dev_info */ 119 mdeg_node_spec_t *inst_spec; /* vldc instance specifier */ 120 mdeg_handle_t mdeg_hdl; /* MD event handle */ 121 122 uint_t num_ports; 123 vldc_port_t port[VLDC_MAX_PORTS]; 124 125 /* table for assigned minors */ 126 vldc_minor_t minor_tbl[VLDC_MAX_MINORS]; 127 128 /* number of minors already assigned */ 129 uint_t minors_assigned; 130 } vldc_t; 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif /* _VLDC_IMPL_H */ 137