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 (c) 2002-2003, Network Appliance, Inc. All rights reserved. 24 */ 25 26 /* 27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 31 /* 32 * 33 * MODULE: dapl_psp_create.c 34 * 35 * PURPOSE: Connection management 36 * Description: Interfaces in this file are completely described in 37 * the DAPL 1.1 API, Chapter 6, section 4 38 * 39 * $Id: dapl_psp_create.c,v 1.16 2003/07/25 19:24:11 sjs2 Exp $ 40 */ 41 42 #include "dapl.h" 43 #include "dapl_sp_util.h" 44 #include "dapl_ia_util.h" 45 #include "dapl_adapter_util.h" 46 47 /* 48 * dapl_psp_create 49 * 50 * uDAPL: User Direct Access Program Library Version 1.1, 6.4.1.1 51 * 52 * Create a persistent Public Service Point that can recieve multiple 53 * requests for connections and generate multiple connection request 54 * instances that wil be delivered to the specified Event Dispatcher 55 * in a notification event. 56 * 57 * Input: 58 * ia_handle 59 * conn_qual 60 * evd_handle 61 * psp_flags 62 * 63 * Output: 64 * psp_handle 65 * 66 * Returns: 67 * DAT_SUCCESS 68 * DAT_INSUFFICIENT_RESOURCES 69 * DAT_INVALID_PARAMETER 70 * DAT_CONN_QUAL_IN_USE 71 * DAT_MODEL_NOT_SUPPORTED 72 */ 73 DAT_RETURN 74 dapl_psp_create( 75 IN DAT_IA_HANDLE ia_handle, 76 IN DAT_CONN_QUAL conn_qual, 77 IN DAT_EVD_HANDLE evd_handle, 78 IN DAT_PSP_FLAGS psp_flags, 79 OUT DAT_PSP_HANDLE *psp_handle) 80 { 81 DAPL_IA *ia_ptr; 82 DAPL_SP *sp_ptr; 83 DAPL_EVD *evd_ptr; 84 DAT_BOOLEAN sp_found; 85 DAT_RETURN dat_status; 86 87 ia_ptr = (DAPL_IA *)ia_handle; 88 dat_status = DAT_SUCCESS; 89 90 if (DAPL_BAD_HANDLE(ia_ptr, DAPL_MAGIC_IA)) { 91 dat_status = DAT_ERROR(DAT_INVALID_HANDLE, 92 DAT_INVALID_HANDLE_IA); 93 goto bail; 94 } 95 96 if (DAPL_BAD_HANDLE(evd_handle, DAPL_MAGIC_EVD)) { 97 dat_status = DAT_ERROR(DAT_INVALID_HANDLE, 98 DAT_INVALID_HANDLE_EVD_CR); 99 goto bail; 100 } 101 102 if (psp_handle == NULL) { 103 dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG5); 104 goto bail; 105 } 106 107 /* check for invalid psp flags */ 108 if ((psp_flags != DAT_PSP_CONSUMER_FLAG) && 109 (psp_flags != DAT_PSP_PROVIDER_FLAG)) { 110 dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG4); 111 goto bail; 112 } 113 114 evd_ptr = (DAPL_EVD *)evd_handle; 115 if (!(evd_ptr->evd_flags & DAT_EVD_CR_FLAG)) { 116 dat_status = DAT_ERROR(DAT_INVALID_HANDLE, 117 DAT_INVALID_HANDLE_EVD_CR); 118 goto bail; 119 } 120 121 /* 122 * check for connection qualifier eq 0 123 * in IB this is called Null Service ID, use of it in CM is invalid. 124 * in tcp/udp, port number 0 is reserved. 125 */ 126 if (!conn_qual) { 127 dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG2); 128 goto bail; 129 } 130 131 /* 132 * See if we have a quiescent listener to use for this PSP, else 133 * create one and set it listening 134 */ 135 sp_ptr = dapls_ia_sp_search(ia_ptr, conn_qual, DAT_TRUE); 136 sp_found = DAT_TRUE; 137 if (sp_ptr == NULL) { 138 /* Allocate PSP */ 139 sp_found = DAT_FALSE; 140 sp_ptr = dapls_sp_alloc(ia_ptr, DAT_TRUE); 141 142 if (sp_ptr == NULL) { 143 dat_status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES, 144 DAT_RESOURCE_MEMORY); 145 goto bail; 146 } 147 } else if (sp_ptr->listening == DAT_TRUE) { 148 dat_status = DAT_ERROR(DAT_CONN_QUAL_IN_USE, 0); 149 goto bail; 150 } 151 152 /* 153 * Fill out the args for a PSP 154 */ 155 sp_ptr->ia_handle = ia_handle; 156 sp_ptr->conn_qual = conn_qual; 157 sp_ptr->evd_handle = evd_handle; 158 sp_ptr->psp_flags = psp_flags; 159 sp_ptr->ep_handle = NULL; 160 161 /* 162 * Take a reference on the EVD handle 163 */ 164 (void) dapl_os_atomic_inc(&((DAPL_EVD *)evd_handle)->evd_ref_count); 165 166 /* 167 * Set up a listener for a connection. Connections can arrive 168 * even before this call returns! 169 */ 170 sp_ptr->state = DAPL_SP_STATE_PSP_LISTENING; 171 sp_ptr->listening = DAT_TRUE; 172 173 /* 174 * If this is a new sp we need to add it to the IA queue, and set up 175 * a conn_listener. 176 */ 177 if (sp_found == DAT_FALSE) { 178 179 /* Link it onto the IA */ 180 dapl_ia_link_psp(ia_ptr, sp_ptr); 181 182 dat_status = dapls_ib_setup_conn_listener(ia_ptr, conn_qual, 183 sp_ptr); 184 185 if (dat_status != DAT_SUCCESS) { 186 /* 187 * Have a problem setting up the connection, something 188 * wrong! The psp_free decrements the EVD refcount for 189 * us; we don't * need to do that. 190 * But we want to set the listener bits to false, 191 * as we know that call failed. 192 */ 193 sp_ptr->state = DAPL_SP_STATE_FREE; 194 sp_ptr->listening = DAT_FALSE; 195 (void) dapl_psp_free((DAT_PSP_HANDLE) sp_ptr); 196 197 dapl_dbg_log(DAPL_DBG_TYPE_CM, 198 "--> dapl_psp_create setup_conn_listener failed: " 199 "%x\n", 200 dat_status); 201 202 goto bail; 203 } 204 } 205 206 /* 207 * Return handle to the user 208 */ 209 *psp_handle = (DAT_PSP_HANDLE)sp_ptr; 210 211 bail: 212 return (dat_status); 213 } 214