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 2008 Sun Microsystems, Inc.  All rights reserved.
28 * Use is subject to license terms.
29 */
30
31/*
32 *
33 * MODULE: dapl_evd_modify_cno.c
34 *
35 * PURPOSE: Event Management
36 *
37 * Description: Interfaces in this file are completely described in
38 * 		the DAPL 1.1 API, Chapter 6, section 3
39 *
40 * $Id: dapl_evd_modify_cno.c,v 1.10 2003/07/14 17:50:32 sjs2 Exp $
41 */
42
43#include "dapl.h"
44#include "dapl_adapter_util.h"
45
46/*
47 * dapl_evd_modify_cno
48 *
49 * DAPL Requirements Version xxx, 6.3.2.4
50 *
51 * Modify the CNO associated with the EVD
52 *
53 * Input:
54 * 	evd_handle
55 * 	cno_handle
56 *
57 * Output:
58 * 	none
59 *
60 * Returns:
61 * 	DAT_SUCCSSS
62 * 	DAT_INVALID_HANDLE
63 */
64
65DAT_RETURN
66dapl_evd_modify_cno(
67	IN	DAT_EVD_HANDLE		evd_handle,
68	IN	DAT_CNO_HANDLE		cno_handle)
69{
70	DAPL_EVD	*evd_ptr;
71	DAPL_CNO	*cno_ptr;
72	DAPL_CNO	*old_cno_ptr;
73	DAT_RETURN	dat_status;
74
75	evd_ptr = (DAPL_EVD *)evd_handle;
76	cno_ptr = (DAPL_CNO *)cno_handle;
77	dat_status = DAT_SUCCESS;
78
79	if (DAPL_BAD_HANDLE(evd_handle, DAPL_MAGIC_EVD)) {
80		dat_status = DAT_ERROR(DAT_INVALID_HANDLE, 0);
81		goto bail;
82	}
83
84	/* cno_handle of DAT_HANDLE_NULL disassociated the EVD with any CNO */
85	if ((cno_handle != DAT_HANDLE_NULL) &&
86	    DAPL_BAD_HANDLE(cno_handle, DAPL_MAGIC_CNO)) {
87		dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
88		    DAT_INVALID_HANDLE_CNO);
89		goto bail;
90	}
91
92	/* nothing to change */
93	if (cno_ptr == evd_ptr->cno_ptr) {
94		dat_status = DAT_SUCCESS;
95		goto bail;
96	}
97
98	if (dapls_ib_modify_cno(evd_ptr, cno_ptr) != DAT_SUCCESS) {
99		dat_status = DAT_ERROR(DAT_INVALID_HANDLE, 0);
100		goto bail;
101	}
102
103	dapl_os_lock(&evd_ptr->header.lock);
104	old_cno_ptr = evd_ptr->cno_ptr;
105	evd_ptr->cno_ptr = cno_ptr;
106	dapl_os_unlock(&evd_ptr->header.lock);
107
108	/*
109	 * We need to first remove the evd from the old CNO's list before
110	 * adding it to the new CNO's list
111	 */
112	if (old_cno_ptr) {
113		dapl_os_lock(&(old_cno_ptr->header.lock));
114		(void) dapl_llist_remove_entry(&old_cno_ptr->evd_list_head,
115		    &evd_ptr->cno_list_entry);
116		dapl_os_atomic_dec(&(old_cno_ptr->cno_ref_count));
117		dapl_os_unlock(&(old_cno_ptr->header.lock));
118
119	}
120
121	if (cno_ptr) {
122		dapl_os_lock(&(cno_ptr->header.lock));
123		dapl_llist_add_head(&cno_ptr->evd_list_head,
124		    &evd_ptr->cno_list_entry, evd_ptr);
125		/* Take a reference count on the CNO */
126		dapl_os_atomic_inc(&(cno_ptr->cno_ref_count));
127		dapl_os_unlock(&cno_ptr->header.lock);
128	}
129
130	/*
131	 * We need to enable the callback handler if the EVD has a CQ associated
132	 * to it and is enabled.
133	 */
134	if ((evd_ptr->evd_flags & (DAT_EVD_DTO_FLAG | DAT_EVD_RMR_BIND_FLAG)) &&
135	    evd_ptr->evd_enabled && cno_handle != DAT_HANDLE_NULL) {
136		dat_status = DAPL_NOTIFY(evd_ptr)(
137		    evd_ptr->ib_cq_handle, IB_NOTIFY_ON_NEXT_COMP, 0);
138
139		/* FIXME report error */
140		dapl_os_assert(dat_status == DAT_SUCCESS);
141	}
142
143bail:
144	return (dat_status);
145}
146