11ae08745Sheppo /* 21ae08745Sheppo * CDDL HEADER START 31ae08745Sheppo * 41ae08745Sheppo * The contents of this file are subject to the terms of the 51ae08745Sheppo * Common Development and Distribution License (the "License"). 61ae08745Sheppo * You may not use this file except in compliance with the License. 71ae08745Sheppo * 81ae08745Sheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91ae08745Sheppo * or http://www.opensolaris.org/os/licensing. 101ae08745Sheppo * See the License for the specific language governing permissions 111ae08745Sheppo * and limitations under the License. 121ae08745Sheppo * 131ae08745Sheppo * When distributing Covered Code, include this CDDL HEADER in each 141ae08745Sheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151ae08745Sheppo * If applicable, add the following below this CDDL HEADER, with the 161ae08745Sheppo * fields enclosed by brackets "[]" replaced with your own identifying 171ae08745Sheppo * information: Portions Copyright [yyyy] [name of copyright owner] 181ae08745Sheppo * 191ae08745Sheppo * CDDL HEADER END 201ae08745Sheppo */ 211ae08745Sheppo 221ae08745Sheppo /* 233ef557bfSMike Christensen * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 241ae08745Sheppo * Use is subject to license terms. 251ae08745Sheppo */ 261ae08745Sheppo 271ae08745Sheppo #ifndef _DS_IMPL_H 281ae08745Sheppo #define _DS_IMPL_H 291ae08745Sheppo 301ae08745Sheppo #ifdef __cplusplus 311ae08745Sheppo extern "C" { 321ae08745Sheppo #endif 331ae08745Sheppo 343ef557bfSMike Christensen #include <sys/bitmap.h> 353ef557bfSMike Christensen #include <sys/ldoms.h> 3630588217SMike Christensen 3730588217SMike Christensen 381ae08745Sheppo /* 391ae08745Sheppo * The Domain Services Protocol 401ae08745Sheppo * 411ae08745Sheppo * The DS protocol is divided into two parts. The first is fixed and 421ae08745Sheppo * must remain exactly the same for *all* versions of the DS protocol. 431ae08745Sheppo * The only messages supported by the fixed portion of the protocol are 441ae08745Sheppo * to negotiate a version to use for the rest of the protocol. 451ae08745Sheppo */ 461ae08745Sheppo 471ae08745Sheppo /* 481ae08745Sheppo * Domain Services Header 491ae08745Sheppo */ 501ae08745Sheppo typedef struct ds_hdr { 511ae08745Sheppo uint32_t msg_type; /* message type */ 521ae08745Sheppo uint32_t payload_len; /* payload length */ 531ae08745Sheppo } ds_hdr_t; 541ae08745Sheppo 551ae08745Sheppo #define DS_HDR_SZ (sizeof (ds_hdr_t)) 561ae08745Sheppo 571ae08745Sheppo /* 581ae08745Sheppo * DS Fixed Message Types 591ae08745Sheppo */ 601ae08745Sheppo #define DS_INIT_REQ 0x0 /* initiate DS connection */ 6130588217SMike Christensen #define DS_INIT_ACK 0x1 /* initiation acknowledgement */ 621ae08745Sheppo #define DS_INIT_NACK 0x2 /* initiation negative acknowledgment */ 631ae08745Sheppo 641ae08745Sheppo /* 651ae08745Sheppo * DS Fixed Initialization Messages 661ae08745Sheppo */ 671ae08745Sheppo typedef struct ds_init_req { 681ae08745Sheppo uint16_t major_vers; /* requested major version */ 691ae08745Sheppo uint16_t minor_vers; /* requested minor version */ 701ae08745Sheppo } ds_init_req_t; 711ae08745Sheppo 721ae08745Sheppo typedef struct ds_init_ack { 731ae08745Sheppo uint16_t minor_vers; /* highest supported minor version */ 741ae08745Sheppo } ds_init_ack_t; 751ae08745Sheppo 761ae08745Sheppo typedef struct ds_init_nack { 771ae08745Sheppo uint16_t major_vers; /* alternate supported major version */ 781ae08745Sheppo } ds_init_nack_t; 791ae08745Sheppo 801ae08745Sheppo /* 811ae08745Sheppo * DS Message Types for Version 1.0 821ae08745Sheppo */ 831ae08745Sheppo #define DS_REG_REQ 0x3 /* register a service */ 8430588217SMike Christensen #define DS_REG_ACK 0x4 /* register acknowledgement */ 851ae08745Sheppo #define DS_REG_NACK 0x5 /* register failed */ 861ae08745Sheppo #define DS_UNREG 0x6 /* unregister a service */ 8730588217SMike Christensen #define DS_UNREG_ACK 0x7 /* unregister acknowledgement */ 881ae08745Sheppo #define DS_UNREG_NACK 0x8 /* unregister failed */ 891ae08745Sheppo #define DS_DATA 0x9 /* data message */ 901ae08745Sheppo #define DS_NACK 0xa /* data error */ 911ae08745Sheppo 921ae08745Sheppo /* result codes */ 931ae08745Sheppo #define DS_OK 0x0 /* success */ 941ae08745Sheppo #define DS_REG_VER_NACK 0x1 /* unsupported major version */ 951ae08745Sheppo #define DS_REG_DUP 0x2 /* duplicate registration attempted */ 961ae08745Sheppo #define DS_INV_HDL 0x3 /* service handle not valid */ 971ae08745Sheppo #define DS_TYPE_UNKNOWN 0x4 /* unknown message type received */ 981ae08745Sheppo 991ae08745Sheppo /* 1001ae08745Sheppo * Service Register Messages 1011ae08745Sheppo */ 1021ae08745Sheppo typedef struct ds_reg_req { 1031ae08745Sheppo uint64_t svc_handle; /* service handle to register */ 1041ae08745Sheppo uint16_t major_vers; /* requested major version */ 1051ae08745Sheppo uint16_t minor_vers; /* requested minor version */ 1061ae08745Sheppo char svc_id[1]; /* service identifier string */ 1071ae08745Sheppo } ds_reg_req_t; 1081ae08745Sheppo 1091ae08745Sheppo typedef struct ds_reg_ack { 1101ae08745Sheppo uint64_t svc_handle; /* service handle sent in register */ 1111ae08745Sheppo uint16_t minor_vers; /* highest supported minor version */ 1121ae08745Sheppo } ds_reg_ack_t; 1131ae08745Sheppo 1141ae08745Sheppo typedef struct ds_reg_nack { 1151ae08745Sheppo uint64_t svc_handle; /* service handle sent in register */ 1161ae08745Sheppo uint64_t result; /* reason for the failure */ 1171ae08745Sheppo uint16_t major_vers; /* alternate supported major version */ 1181ae08745Sheppo } ds_reg_nack_t; 1191ae08745Sheppo 1201ae08745Sheppo /* 1211ae08745Sheppo * Service Unregister Messages 1221ae08745Sheppo */ 1231ae08745Sheppo typedef struct ds_unreg_req { 1241ae08745Sheppo uint64_t svc_handle; /* service handle to unregister */ 1251ae08745Sheppo } ds_unreg_req_t; 1261ae08745Sheppo 1271ae08745Sheppo typedef struct ds_unreg_ack { 1281ae08745Sheppo uint64_t svc_handle; /* service handle sent in unregister */ 1291ae08745Sheppo } ds_unreg_ack_t; 1301ae08745Sheppo 1311ae08745Sheppo typedef struct ds_unreg_nack { 1321ae08745Sheppo uint64_t svc_handle; /* service handle sent in unregister */ 1331ae08745Sheppo } ds_unreg_nack_t; 1341ae08745Sheppo 1351ae08745Sheppo /* 1361ae08745Sheppo * Data Transfer Messages 1371ae08745Sheppo */ 1381ae08745Sheppo typedef struct ds_data_handle { 1391ae08745Sheppo uint64_t svc_handle; /* service handle for data */ 1401ae08745Sheppo } ds_data_handle_t; 1411ae08745Sheppo 1421ae08745Sheppo typedef struct ds_data_nack { 1431ae08745Sheppo uint64_t svc_handle; /* service handle sent in data msg */ 1441ae08745Sheppo uint64_t result; /* reason for failure */ 1451ae08745Sheppo } ds_data_nack_t; 1461ae08745Sheppo 1471ae08745Sheppo /* 1481ae08745Sheppo * Message Processing Utilities 1491ae08745Sheppo */ 1501ae08745Sheppo #define DS_MSG_TYPE_VALID(type) ((type) <= DS_NACK) 1511ae08745Sheppo #define DS_MSG_LEN(ds_type) (sizeof (ds_hdr_t) + sizeof (ds_type)) 1521ae08745Sheppo 1531ae08745Sheppo 1541ae08745Sheppo /* 1551ae08745Sheppo * Domain Service Port 1561ae08745Sheppo * 1571ae08745Sheppo * A DS port is a logical representation of an LDC dedicated to 1581ae08745Sheppo * communication between DS endpoints. The ds_port_t maintains state 1591ae08745Sheppo * associated with a connection to a remote endpoint. This includes 1601ae08745Sheppo * the state of the port, the LDC state, the current version of the 1611ae08745Sheppo * DS protocol in use on the port, and other port properties. 1621ae08745Sheppo * 1631ae08745Sheppo * Locking: The port is protected by a single mutex. It must be held 1641ae08745Sheppo * while the port structure is being accessed and also when data is 1651ae08745Sheppo * being read or written using the port 1661ae08745Sheppo */ 1671ae08745Sheppo typedef enum { 1681ae08745Sheppo DS_PORT_FREE, /* port structure not in use */ 1691ae08745Sheppo DS_PORT_INIT, /* port structure created */ 1701ae08745Sheppo DS_PORT_LDC_INIT, /* ldc successfully initialized */ 1711ae08745Sheppo DS_PORT_INIT_REQ, /* initialization handshake sent */ 1721ae08745Sheppo DS_PORT_READY /* init handshake completed */ 1731ae08745Sheppo } ds_port_state_t; 1741ae08745Sheppo 1751ae08745Sheppo typedef struct ds_ldc { 1761ae08745Sheppo uint64_t id; /* LDC id */ 1771ae08745Sheppo ldc_handle_t hdl; /* LDC handle */ 1781ae08745Sheppo ldc_status_t state; /* current LDC state */ 1791ae08745Sheppo } ds_ldc_t; 1801ae08745Sheppo 18130588217SMike Christensen typedef uint64_t ds_domain_hdl_t; 18230588217SMike Christensen 18330588217SMike Christensen #define DS_DHDL_INVALID ((ds_domain_hdl_t)0xffffffff) 18430588217SMike Christensen 18530588217SMike Christensen /* port flags */ 18630588217SMike Christensen #define DS_PORT_MUTEX_INITED 0x1 /* mutexes inited? */ 18730588217SMike Christensen 1881ae08745Sheppo typedef struct ds_port { 18930588217SMike Christensen uint32_t flags; /* port flags */ 19030588217SMike Christensen kmutex_t lock; /* port and service state lock */ 19130588217SMike Christensen kmutex_t tx_lock; /* tx port lock */ 19230588217SMike Christensen kmutex_t rcv_lock; /* rcv port lock */ 1931ae08745Sheppo uint64_t id; /* port id from MD */ 1941ae08745Sheppo ds_port_state_t state; /* state of the port */ 1951ae08745Sheppo ds_ver_t ver; /* DS protocol version in use */ 1961ae08745Sheppo uint32_t ver_idx; /* index of version during handshake */ 1971ae08745Sheppo ds_ldc_t ldc; /* LDC for this port */ 19830588217SMike Christensen ds_domain_hdl_t domain_hdl; /* LDOMs domain hdl assoc. with port */ 19930588217SMike Christensen char *domain_name; /* LDOMs domain name assoc. with port */ 2001ae08745Sheppo } ds_port_t; 2011ae08745Sheppo 20230588217SMike Christensen #define IS_DS_PORT(port) 1 /* VBSC code compatability */ 20330588217SMike Christensen #define PORTID(port) ((ulong_t)((port)->id)) 20430588217SMike Christensen #define PTR_TO_LONG(ptr) ((uint64_t)(ptr)) 20530588217SMike Christensen 2061ae08745Sheppo /* 2071ae08745Sheppo * A DS portset is a bitmap that represents a collection of DS 2083ef557bfSMike Christensen * ports. Each bit represent a particular port id. We need 2093ef557bfSMike Christensen * to allocate for the max. number of domains supported, 2103ef557bfSMike Christensen * plus a small number (e.g. for the SP connection). 2111ae08745Sheppo */ 2123ef557bfSMike Christensen #define DS_EXTRA_PORTS 16 2133ef557bfSMike Christensen #define DS_MAX_PORTS (LDOMS_MAX_DOMAINS + DS_EXTRA_PORTS) 2143ef557bfSMike Christensen #define DS_PORTSET_SIZE BT_BITOUL(DS_MAX_PORTS) 2151ae08745Sheppo 2163ef557bfSMike Christensen typedef ulong_t ds_portset_t[DS_PORTSET_SIZE]; 2173ef557bfSMike Christensen 2183ef557bfSMike Christensen extern ds_portset_t ds_nullport; 2193ef557bfSMike Christensen 22040c61268SMike Christensen #define DS_PORTID_INVALID ((uint64_t)-1) 22140c61268SMike Christensen 22240c61268SMike Christensen /* DS SP Port ID */ 22340c61268SMike Christensen extern uint64_t ds_sp_port_id; 22440c61268SMike Christensen 2251ae08745Sheppo #define DS_MAX_PORT_ID (DS_MAX_PORTS - 1) 2261ae08745Sheppo 2273ef557bfSMike Christensen #define DS_PORT_IN_SET(set, port) BT_TEST((set), (port)) 2283ef557bfSMike Christensen #define DS_PORTSET_ADD(set, port) BT_SET((set), (port)) 2293ef557bfSMike Christensen #define DS_PORTSET_DEL(set, port) BT_CLEAR((set), (port)) 2303ef557bfSMike Christensen #define DS_PORTSET_ISNULL(set) (memcmp((set), ds_nullport, \ 2313ef557bfSMike Christensen sizeof (set)) == 0) 2323ef557bfSMike Christensen #define DS_PORTSET_SETNULL(set) ((void)memset((set), 0, sizeof (set))) 2333ef557bfSMike Christensen #define DS_PORTSET_DUP(set1, set2) ((void)memcpy((set1), (set2), \ 2343ef557bfSMike Christensen sizeof (set1))) 23530588217SMike Christensen 23630588217SMike Christensen /* 23730588217SMike Christensen * A DS event consists of a buffer on a port. We explictly use a link to 23830588217SMike Christensen * enequeue/dequeue on non-Solaris environments. On Solaris we use taskq. 23930588217SMike Christensen */ 24030588217SMike Christensen typedef struct ds_event { 24130588217SMike Christensen ds_port_t *port; 24230588217SMike Christensen char *buf; 24330588217SMike Christensen size_t buflen; 24430588217SMike Christensen } ds_event_t; 2451ae08745Sheppo 2461ae08745Sheppo /* 2471ae08745Sheppo * LDC Information 2481ae08745Sheppo */ 249e1ebb9ecSlm66018 #define DS_STREAM_MTU 4096 2501ae08745Sheppo 2511ae08745Sheppo /* 2521ae08745Sheppo * Machine Description Constants 2531ae08745Sheppo */ 2543af08d82Slm66018 #define DS_MD_ROOT_NAME "domain-services" 2551ae08745Sheppo #define DS_MD_PORT_NAME "domain-services-port" 2561ae08745Sheppo #define DS_MD_CHAN_NAME "channel-endpoint" 2571ae08745Sheppo 2581ae08745Sheppo /* 2591ae08745Sheppo * DS Services 2601ae08745Sheppo * 2611ae08745Sheppo * A DS Service is a mapping between a DS capability and a client 2621ae08745Sheppo * of the DS framework that provides that capability. It includes 2631ae08745Sheppo * information on the state of the service, the currently negotiated 2641ae08745Sheppo * version of the capability specific protocol, the port that is 2651ae08745Sheppo * currently in use by the capability, etc. 2661ae08745Sheppo */ 2671ae08745Sheppo 2681ae08745Sheppo typedef enum { 2691ae08745Sheppo DS_SVC_INVAL, /* svc structure uninitialized */ 2701ae08745Sheppo DS_SVC_FREE, /* svc structure not in use */ 2711ae08745Sheppo DS_SVC_INACTIVE, /* svc not registered */ 2721ae08745Sheppo DS_SVC_REG_PENDING, /* register message sent */ 27330588217SMike Christensen DS_SVC_ACTIVE, /* register message acknowledged */ 27430588217SMike Christensen DS_SVC_UNREG_PENDING /* unregister is pending */ 2751ae08745Sheppo } ds_svc_state_t; 2761ae08745Sheppo 27730588217SMike Christensen /* ds_svc flags bits */ 27830588217SMike Christensen #define DSSF_ISCLIENT 0x0001 /* client service */ 27930588217SMike Christensen #define DSSF_ISUSER 0x0002 /* user land service */ 28030588217SMike Christensen #define DSSF_REGCB_VALID 0x0004 /* ops register callback is valid */ 28130588217SMike Christensen #define DSSF_UNREGCB_VALID 0x0008 /* ops unregister callback is valid */ 28230588217SMike Christensen #define DSSF_DATACB_VALID 0x0010 /* ops data callback is valid */ 28330588217SMike Christensen #define DSSF_LOOPBACK 0x0020 /* loopback */ 28430588217SMike Christensen #define DSSF_PEND_UNREG 0x0040 /* pending unregister */ 28530588217SMike Christensen #define DSSF_ANYCB_VALID (DSSF_REGCB_VALID | DSSF_UNREGCB_VALID | \ 28630588217SMike Christensen DSSF_DATACB_VALID) 28730588217SMike Christensen #define DSSF_USERFLAGS (DSSF_ISCLIENT | DSSF_ISUSER | DSSF_ANYCB_VALID) 28830588217SMike Christensen 2891ae08745Sheppo typedef struct ds_svc { 2901ae08745Sheppo ds_capability_t cap; /* capability information */ 2911ae08745Sheppo ds_clnt_ops_t ops; /* client ops vector */ 2921ae08745Sheppo ds_svc_hdl_t hdl; /* handle assigned by DS */ 29330588217SMike Christensen ds_svc_hdl_t svc_hdl; /* remote svc hdl if client svc */ 2941ae08745Sheppo ds_svc_state_t state; /* current service state */ 2951ae08745Sheppo ds_ver_t ver; /* svc protocol version in use */ 2961ae08745Sheppo uint_t ver_idx; /* index into client version array */ 2971ae08745Sheppo ds_port_t *port; /* port for this service */ 2981ae08745Sheppo ds_portset_t avail; /* ports available to this service */ 29930588217SMike Christensen ds_portset_t tried; /* ports tried by this service */ 30030588217SMike Christensen int fixed; /* is svc fixed to port */ 30130588217SMike Christensen uint_t flags; /* service flags */ 30230588217SMike Christensen ds_cb_arg_t uarg; /* user arg for user callbacks */ 30330588217SMike Christensen uint_t drvi; /* driver instance */ 30430588217SMike Christensen void *drv_psp; /* driver per svc ptr */ 3051ae08745Sheppo } ds_svc_t; 3061ae08745Sheppo 30730588217SMike Christensen typedef struct ds_svcs { 30830588217SMike Christensen ds_svc_t **tbl; /* ptr to table */ 30930588217SMike Christensen kmutex_t lock; 31030588217SMike Christensen uint_t maxsvcs; /* size of the table */ 31130588217SMike Christensen uint_t nsvcs; /* current number of items */ 31230588217SMike Christensen } ds_svcs_t; 31330588217SMike Christensen 3141ae08745Sheppo #define DS_SVC_ISFREE(svc) ((svc == NULL) || (svc->state == DS_SVC_FREE)) 31530588217SMike Christensen #ifndef DS_MAXSVCS_INIT 31630588217SMike Christensen #define DS_MAXSVCS_INIT 32 31730588217SMike Christensen #endif 3181ae08745Sheppo 3191ae08745Sheppo /* 32030588217SMike Christensen * A service handle is a 64 bit value with three pieces of information 3211ae08745Sheppo * encoded in it. The upper 32 bits is the index into the table of 32230588217SMike Christensen * a particular service structure. Bit 31 indicates whether the handle 32330588217SMike Christensen * represents a service privider or service client. The lower 31 bits is 32430588217SMike Christensen * a counter that is incremented each time a service structure is reused. 3251ae08745Sheppo */ 3261ae08745Sheppo #define DS_IDX_SHIFT 32 32730588217SMike Christensen #define DS_COUNT_MASK 0x7fffffffull 32830588217SMike Christensen #define DS_HDL_ISCLIENT_BIT 0x80000000ull 3291ae08745Sheppo 3301ae08745Sheppo #define DS_ALLOC_HDL(_idx, _count) (((uint64_t)_idx << DS_IDX_SHIFT) | \ 3311ae08745Sheppo ((uint64_t)(_count + 1) & \ 3321ae08745Sheppo DS_COUNT_MASK)) 3331ae08745Sheppo #define DS_HDL2IDX(hdl) (hdl >> DS_IDX_SHIFT) 3341ae08745Sheppo #define DS_HDL2COUNT(hdl) (hdl & DS_COUNT_MASK) 33530588217SMike Christensen #define DS_HDL_ISCLIENT(hdl) ((hdl) & DS_HDL_ISCLIENT_BIT) 33630588217SMike Christensen #define DS_HDL_SET_ISCLIENT(hdl) ((hdl) |= DS_HDL_ISCLIENT_BIT) 33730588217SMike Christensen 33830588217SMike Christensen #define DS_INVALID_INSTANCE (-1) 33930588217SMike Christensen 34030588217SMike Christensen /* enable/disable taskq processing */ 34130588217SMike Christensen extern boolean_t ds_enabled; 3421ae08745Sheppo 3431ae08745Sheppo /* 3441ae08745Sheppo * DS Message Logging 3451ae08745Sheppo * 3461ae08745Sheppo * The DS framework logs all incoming and outgoing messages to a 3471ae08745Sheppo * ring buffer. This provides the ability to reconstruct a trace 3481ae08745Sheppo * of DS activity for use in debugging. In addition to the message 3491ae08745Sheppo * data, each log entry contains a timestamp and the destination 3501ae08745Sheppo * of the message. The destination is based on the port number the 3511ae08745Sheppo * message passed through (port number + 1). The sign of the dest 3521ae08745Sheppo * field distinguishes incoming messages from outgoing messages. 3531ae08745Sheppo * Incoming messages have a negative destination field. 3541ae08745Sheppo */ 3551ae08745Sheppo 3561ae08745Sheppo typedef struct ds_log_entry { 3571ae08745Sheppo struct ds_log_entry *next; /* next in log or free list */ 3581ae08745Sheppo struct ds_log_entry *prev; /* previous in log */ 3591ae08745Sheppo time_t timestamp; /* time message added to log */ 3601ae08745Sheppo size_t datasz; /* size of the data */ 3611ae08745Sheppo void *data; /* the data itself */ 3621ae08745Sheppo int32_t dest; /* message destination */ 3631ae08745Sheppo } ds_log_entry_t; 3641ae08745Sheppo 3651ae08745Sheppo #define DS_LOG_IN(pid) (-(pid + 1)) 3661ae08745Sheppo #define DS_LOG_OUT(pid) (pid + 1) 3671ae08745Sheppo 3681ae08745Sheppo /* 3691ae08745Sheppo * DS Log Limits: 3701ae08745Sheppo * 3711ae08745Sheppo * The size of the log is controlled by two limits. The first is 3721ae08745Sheppo * a soft limit that is configurable by the user (via the global 3731ae08745Sheppo * variable ds_log_sz). When this limit is exceeded, each new 3741ae08745Sheppo * message that is added to the log replaces the oldest message. 3751ae08745Sheppo * 3761ae08745Sheppo * The second is a hard limit that is calculated based on the soft 3771ae08745Sheppo * limit (DS_LOG_LIMIT). It is defined to be ~3% above the soft limit. 3781ae08745Sheppo * Once this limit is exceeded, a thread is scheduled to delete old 3791ae08745Sheppo * messages until the size of the log is below the soft limit. 3801ae08745Sheppo */ 381f4b91457Srsmaeda #define DS_LOG_DEFAULT_SZ (4 * 1024 * 1024) /* 4 MB */ 3821ae08745Sheppo 3831ae08745Sheppo #define DS_LOG_LIMIT (ds_log_sz + (ds_log_sz >> 5)) 3841ae08745Sheppo 3851ae08745Sheppo #define DS_LOG_ENTRY_SZ(ep) (sizeof (ds_log_entry_t) + (ep)->datasz) 3861ae08745Sheppo 3871ae08745Sheppo /* 3881ae08745Sheppo * DS Log Memory Usage: 3891ae08745Sheppo * 3901ae08745Sheppo * The log free list is initialized from a pre-allocated pool of entry 3911ae08745Sheppo * structures (the global ds_log_entry_pool). The number of entries 3921ae08745Sheppo * in the pool (DS_LOG_NPOOL) is the number of entries that would 3931ae08745Sheppo * take up half the default size of the log. 3941ae08745Sheppo * 3951ae08745Sheppo * As messages are added to the log, entry structures are pulled from 3961ae08745Sheppo * the free list. If the free list is empty, memory is allocated for 3971ae08745Sheppo * the entry. When entries are removed from the log, they are placed 3981ae08745Sheppo * on the free list. Allocated memory is only deallocated when the 3991ae08745Sheppo * entire log is destroyed. 4001ae08745Sheppo */ 4011ae08745Sheppo #define DS_LOG_NPOOL ((DS_LOG_DEFAULT_SZ >> 1) / \ 4021ae08745Sheppo sizeof (ds_log_entry_t)) 4031ae08745Sheppo 4041ae08745Sheppo #define DS_LOG_POOL_END (ds_log_entry_pool + DS_LOG_NPOOL) 4051ae08745Sheppo 4061ae08745Sheppo #define DS_IS_POOL_ENTRY(ep) (((ep) >= ds_log_entry_pool) && \ 4071ae08745Sheppo ((ep) <= &(ds_log_entry_pool[DS_LOG_NPOOL]))) 4081ae08745Sheppo 40930588217SMike Christensen /* VBSC code compatability related defines */ 41030588217SMike Christensen 41130588217SMike Christensen /* VBSC malloc/free are similar to user malloc/free */ 41230588217SMike Christensen #define DS_MALLOC(size) kmem_zalloc(size, KM_SLEEP) 41330588217SMike Christensen #define DS_FREE(ptr, size) kmem_free(ptr, size) 41430588217SMike Christensen 41530588217SMike Christensen /* VBSC debug print needs newline, Solaris cmn_err doesn't */ 41630588217SMike Christensen #define DS_EOL 41730588217SMike Christensen 41830588217SMike Christensen /* 41930588217SMike Christensen * Results of checking version array with ds_vers_isvalid() 42030588217SMike Christensen */ 42130588217SMike Christensen typedef enum { 42230588217SMike Christensen DS_VERS_OK, 42330588217SMike Christensen DS_VERS_INCREASING_MAJOR_ERR, 42430588217SMike Christensen DS_VERS_INCREASING_MINOR_ERR 42530588217SMike Christensen } ds_vers_check_t; 42630588217SMike Christensen 42730588217SMike Christensen /* System specific interfaces */ 42830588217SMike Christensen extern void ds_sys_port_init(ds_port_t *port); 42930588217SMike Christensen extern void ds_sys_port_fini(ds_port_t *port); 43030588217SMike Christensen extern void ds_sys_drain_events(ds_port_t *port); 43130588217SMike Christensen extern int ds_sys_dispatch_func(void (func)(void *), void *arg); 43230588217SMike Christensen extern void ds_sys_ldc_init(ds_port_t *port); 43330588217SMike Christensen 43430588217SMike Christensen /* vlds cb access to svc structure */ 43530588217SMike Christensen void ds_cbarg_get_hdl(ds_cb_arg_t arg, ds_svc_hdl_t *hdlp); 43630588217SMike Christensen void ds_cbarg_get_flags(ds_cb_arg_t arg, uint32_t *flagsp); 43730588217SMike Christensen void ds_cbarg_get_drv_info(ds_cb_arg_t arg, int *drvip); 43830588217SMike Christensen void ds_cbarg_get_drv_per_svc_ptr(ds_cb_arg_t arg, void **dpspp); 43930588217SMike Christensen void ds_cbarg_get_domain(ds_cb_arg_t arg, ds_domain_hdl_t *dhdlp); 44030588217SMike Christensen void ds_cbarg_get_service_id(ds_cb_arg_t arg, char **servicep); 44130588217SMike Christensen void ds_cbarg_set_drv_per_svc_ptr(ds_cb_arg_t arg, void *dpsp); 44230588217SMike Christensen int ds_hdl_get_cbarg(ds_svc_hdl_t hdl, ds_cb_arg_t *cbargp); 44330588217SMike Christensen void ds_cbarg_set_cookie(ds_svc_t *svc); 44430588217SMike Christensen int ds_is_my_hdl(ds_svc_hdl_t hdl, int instance); 445a600f50dSMike Christensen void ds_set_my_dom_hdl_name(ds_domain_hdl_t dhdl, char *name); 44630588217SMike Christensen 44730588217SMike Christensen /* initialization functions */ 44830588217SMike Christensen void ds_common_init(void); 44930588217SMike Christensen int ds_ldc_fini(ds_port_t *port); 45030588217SMike Christensen void ds_init_svcs_tbl(uint_t nentries); 45130588217SMike Christensen 45230588217SMike Christensen /* message sending functions */ 45330588217SMike Christensen void ds_send_init_req(ds_port_t *port); 45430588217SMike Christensen int ds_send_unreg_req(ds_svc_t *svc); 45530588217SMike Christensen 45630588217SMike Christensen /* walker functions */ 45730588217SMike Christensen typedef int (*svc_cb_t)(ds_svc_t *svc, void *arg); 45830588217SMike Christensen int ds_walk_svcs(svc_cb_t svc_cb, void *arg); 45930588217SMike Christensen int ds_svc_ismatch(ds_svc_t *svc, void *arg); 46030588217SMike Christensen int ds_svc_free(ds_svc_t *svc, void *arg); 46130588217SMike Christensen int ds_svc_register(ds_svc_t *svc, void *arg); 46230588217SMike Christensen 46330588217SMike Christensen /* service utilities */ 46430588217SMike Christensen ds_svc_t *ds_alloc_svc(void); 46530588217SMike Christensen ds_svc_t *ds_sys_find_svc_by_id_port(char *svc_id, ds_port_t *port, 46630588217SMike Christensen int is_client); 46730588217SMike Christensen ds_svc_t *ds_get_svc(ds_svc_hdl_t hdl); 46830588217SMike Christensen 46930588217SMike Christensen /* port utilities */ 47030588217SMike Christensen void ds_port_common_init(ds_port_t *port); 471*beba1dd8SMike Christensen void ds_port_common_fini(ds_port_t *port); 47230588217SMike Christensen 47330588217SMike Christensen /* misc utilities */ 47430588217SMike Christensen ds_vers_check_t ds_vers_isvalid(ds_ver_t *vers, int nvers); 47530588217SMike Christensen char *ds_errno_to_str(int ds_errno, char *ebuf); 47630588217SMike Christensen char *ds_strdup(char *str); 47730588217SMike Christensen boolean_t negotiate_version(int num_versions, ds_ver_t *sup_versionsp, 47830588217SMike Christensen uint16_t req_major, uint16_t *new_majorp, uint16_t *new_minorp); 47930588217SMike Christensen 48030588217SMike Christensen /* log functions */ 48130588217SMike Christensen int ds_log_add_msg(int32_t dest, uint8_t *msg, size_t sz); 48230588217SMike Christensen 48330588217SMike Christensen /* vlds driver interfaces to ds module */ 48430588217SMike Christensen int ds_ucap_init(ds_capability_t *cap, ds_clnt_ops_t *ops, uint_t flags, 48530588217SMike Christensen int instance, ds_svc_hdl_t *hdlp); 48630588217SMike Christensen int ds_unreg_hdl(ds_svc_hdl_t hdl); 48730588217SMike Christensen int ds_hdl_lookup(char *service, uint_t is_client, ds_svc_hdl_t *hdlp, 48830588217SMike Christensen uint_t maxhdls, uint_t *nhdlsp); 48930588217SMike Christensen int ds_service_lookup(ds_svc_hdl_t hdl, char **servicep, uint_t *is_client); 49030588217SMike Christensen int ds_domain_lookup(ds_svc_hdl_t hdl, ds_domain_hdl_t *dhdlp); 49130588217SMike Christensen int ds_hdl_isready(ds_svc_hdl_t hdl, uint_t *is_ready); 49230588217SMike Christensen void ds_unreg_all(int instance); 49330588217SMike Christensen int ds_dom_name_to_hdl(char *domain_name, ds_domain_hdl_t *dhdlp); 49430588217SMike Christensen int ds_dom_hdl_to_name(ds_domain_hdl_t dhdl, char **domain_namep); 49530588217SMike Christensen int ds_add_port(uint64_t port_id, uint64_t ldc_id, ds_domain_hdl_t dhdl, 49630588217SMike Christensen char *dom_name, int verbose); 49730588217SMike Christensen int ds_remove_port(uint64_t portid, int is_fini); 49830588217SMike Christensen 49930588217SMike Christensen /* ds_ucap_init flags */ 50030588217SMike Christensen #define DS_UCAP_CLNT 0x0 /* Service is Client */ 50130588217SMike Christensen #define DS_UCAP_SVC 0x1 /* Service is Server */ 50230588217SMike Christensen 50330588217SMike Christensen /* 50430588217SMike Christensen * Error buffer size for ds_errno_to_str 50530588217SMike Christensen */ 50630588217SMike Christensen #define DS_EBUFSIZE 80 50730588217SMike Christensen 50830588217SMike Christensen /* 50930588217SMike Christensen * Debugging Features 51030588217SMike Christensen */ 51130588217SMike Christensen #ifdef DEBUG 51230588217SMike Christensen 51330588217SMike Christensen #define DS_DBG_BASIC 0x001 51430588217SMike Christensen #define DS_DBG_FLAG_LDC 0x002 51530588217SMike Christensen #define DS_DBG_FLAG_LOG 0x004 51630588217SMike Christensen #define DS_DBG_DUMP_LDC_MSG 0x008 51730588217SMike Christensen #define DS_DBG_FLAG_MD 0x010 51830588217SMike Christensen #define DS_DBG_FLAG_USR 0x020 51930588217SMike Christensen #define DS_DBG_FLAG_VLDS 0x040 52030588217SMike Christensen #define DS_DBG_FLAG_PRCL 0x080 52130588217SMike Christensen #define DS_DBG_FLAG_RCVQ 0x100 52230588217SMike Christensen #define DS_DBG_FLAG_LOOP 0x200 52330588217SMike Christensen 52430588217SMike Christensen #define DS_DBG if (ds_debug & DS_DBG_BASIC) cmn_err 52530588217SMike Christensen #define DS_DBG_LDC if (ds_debug & DS_DBG_FLAG_LDC) cmn_err 52630588217SMike Christensen #define DS_DBG_LOG if (ds_debug & DS_DBG_FLAG_LOG) cmn_err 52730588217SMike Christensen #define DS_DBG_MD if (ds_debug & DS_DBG_FLAG_MD) cmn_err 52830588217SMike Christensen #define DS_DBG_USR if (ds_debug & DS_DBG_FLAG_USR) cmn_err 52930588217SMike Christensen #define DS_DBG_VLDS if (ds_debug & DS_DBG_FLAG_VLDS) cmn_err 53030588217SMike Christensen #define DS_DBG_PRCL if (ds_debug & DS_DBG_FLAG_PRCL) cmn_err 53130588217SMike Christensen #define DS_DBG_RCVQ if (ds_debug & DS_DBG_FLAG_RCVQ) cmn_err 53230588217SMike Christensen #define DS_DBG_LOOP if (ds_debug & DS_DBG_FLAG_LOOP) cmn_err 53330588217SMike Christensen 53430588217SMike Christensen #define DS_DUMP_MSG(flags, buf, len) if (ds_debug & (flags)) \ 53530588217SMike Christensen ds_dump_msg(buf, len) 53630588217SMike Christensen 53730588217SMike Christensen extern uint_t ds_debug; 53830588217SMike Christensen void ds_dump_msg(void *buf, size_t len); 53930588217SMike Christensen 54030588217SMike Christensen #define DS_BADHDL1 (ds_svc_hdl_t)(0xdeadbed1deadbed1ull) 54130588217SMike Christensen #define DS_BADHDL2 (ds_svc_hdl_t)(0x2deadbed2deadbedull) 54230588217SMike Christensen 54330588217SMike Christensen #else /* DEBUG */ 54430588217SMike Christensen 54530588217SMike Christensen #define DS_DBG if (0) cmn_err 54630588217SMike Christensen #define DS_DBG_LDC DS_DBG 54730588217SMike Christensen #define DS_DBG_LOG DS_DBG 54830588217SMike Christensen #define DS_DBG_MD DS_DBG 54930588217SMike Christensen #define DS_DBG_USR DS_DBG 55030588217SMike Christensen #define DS_DBG_VLDS DS_DBG 55130588217SMike Christensen #define DS_DBG_PRCL DS_DBG 55230588217SMike Christensen #define DS_DBG_RCVQ DS_DBG 55330588217SMike Christensen #define DS_DBG_LOOP DS_DBG 55430588217SMike Christensen #define DS_DUMP_MSG(flags, buf, len) 55530588217SMike Christensen #define DS_DUMP_LDC_MSG(buf, len) 55630588217SMike Christensen 55730588217SMike Christensen #define DS_BADHDL1 NULL 55830588217SMike Christensen #define DS_BADHDL2 NULL 55930588217SMike Christensen 56030588217SMike Christensen #endif /* DEBUG */ 56130588217SMike Christensen 5621ae08745Sheppo #ifdef __cplusplus 5631ae08745Sheppo } 5641ae08745Sheppo #endif 5651ae08745Sheppo 5661ae08745Sheppo #endif /* _DS_IMPL_H */ 567