1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate * This file implements the IBMF message related functions.
29*7c478bd9Sstevel@tonic-gate */
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibmf/ibmf_impl.h>
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate extern int ibmf_trace_level;
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gate /*
36*7c478bd9Sstevel@tonic-gate * ibmf_i_client_add_msg():
37*7c478bd9Sstevel@tonic-gate * Add the message to the client message list
38*7c478bd9Sstevel@tonic-gate */
39*7c478bd9Sstevel@tonic-gate void
ibmf_i_client_add_msg(ibmf_client_t * clientp,ibmf_msg_impl_t * msgimplp)40*7c478bd9Sstevel@tonic-gate ibmf_i_client_add_msg(ibmf_client_t *clientp, ibmf_msg_impl_t *msgimplp)
41*7c478bd9Sstevel@tonic-gate {
42*7c478bd9Sstevel@tonic-gate IBMF_TRACE_2(IBMF_TNF_DEBUG, DPRINT_L4,
43*7c478bd9Sstevel@tonic-gate ibmf_i_client_add_msg_start, IBMF_TNF_TRACE, "",
44*7c478bd9Sstevel@tonic-gate "ibmf_i_client_add_msg(): clientp = 0x%p, msgp = 0x%p\n",
45*7c478bd9Sstevel@tonic-gate tnf_opaque, clientp, clientp, tnf_opaque, msg, msgimplp);
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate ASSERT(MUTEX_NOT_HELD(&msgimplp->im_mutex));
48*7c478bd9Sstevel@tonic-gate
49*7c478bd9Sstevel@tonic-gate mutex_enter(&clientp->ic_msg_mutex);
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate /*
52*7c478bd9Sstevel@tonic-gate * If this is a termination message, add the message to
53*7c478bd9Sstevel@tonic-gate * the termination message list else add the message
54*7c478bd9Sstevel@tonic-gate * to the regular message list.
55*7c478bd9Sstevel@tonic-gate */
56*7c478bd9Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
57*7c478bd9Sstevel@tonic-gate if (msgimplp->im_flags & IBMF_MSG_FLAGS_TERMINATION) {
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
60*7c478bd9Sstevel@tonic-gate /* Put the message on the list */
61*7c478bd9Sstevel@tonic-gate if (clientp->ic_term_msg_list == NULL) {
62*7c478bd9Sstevel@tonic-gate clientp->ic_term_msg_list = clientp->ic_term_msg_last =
63*7c478bd9Sstevel@tonic-gate msgimplp;
64*7c478bd9Sstevel@tonic-gate } else {
65*7c478bd9Sstevel@tonic-gate msgimplp->im_msg_prev = clientp->ic_term_msg_last;
66*7c478bd9Sstevel@tonic-gate clientp->ic_term_msg_last->im_msg_next = msgimplp;
67*7c478bd9Sstevel@tonic-gate clientp->ic_term_msg_last = msgimplp;
68*7c478bd9Sstevel@tonic-gate }
69*7c478bd9Sstevel@tonic-gate } else {
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
72*7c478bd9Sstevel@tonic-gate /*
73*7c478bd9Sstevel@tonic-gate * Increment the counter and kstats for active messages
74*7c478bd9Sstevel@tonic-gate */
75*7c478bd9Sstevel@tonic-gate clientp->ic_msgs_active++;
76*7c478bd9Sstevel@tonic-gate mutex_enter(&clientp->ic_kstat_mutex);
77*7c478bd9Sstevel@tonic-gate IBMF_ADD32_KSTATS(clientp, msgs_active, 1);
78*7c478bd9Sstevel@tonic-gate mutex_exit(&clientp->ic_kstat_mutex);
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gate /* Put the message on the list */
81*7c478bd9Sstevel@tonic-gate if (clientp->ic_msg_list == NULL) {
82*7c478bd9Sstevel@tonic-gate clientp->ic_msg_list = clientp->ic_msg_last = msgimplp;
83*7c478bd9Sstevel@tonic-gate } else {
84*7c478bd9Sstevel@tonic-gate msgimplp->im_msg_prev = clientp->ic_msg_last;
85*7c478bd9Sstevel@tonic-gate clientp->ic_msg_last->im_msg_next = msgimplp;
86*7c478bd9Sstevel@tonic-gate clientp->ic_msg_last = msgimplp;
87*7c478bd9Sstevel@tonic-gate }
88*7c478bd9Sstevel@tonic-gate }
89*7c478bd9Sstevel@tonic-gate
90*7c478bd9Sstevel@tonic-gate msgimplp->im_msg_next = NULL;
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate /* Set the message flags to indicate the message is on the list */
93*7c478bd9Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
94*7c478bd9Sstevel@tonic-gate msgimplp->im_flags |= IBMF_MSG_FLAGS_ON_LIST;
95*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate mutex_exit(&clientp->ic_msg_mutex);
98*7c478bd9Sstevel@tonic-gate
99*7c478bd9Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
100*7c478bd9Sstevel@tonic-gate ibmf_i_client_add_msg_end, IBMF_TNF_TRACE, "",
101*7c478bd9Sstevel@tonic-gate "ibmf_i_client_add_msg() exit\n");
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate /*
105*7c478bd9Sstevel@tonic-gate * ibmf_i_client_rem_msg():
106*7c478bd9Sstevel@tonic-gate * Remove the message from the client's message list
107*7c478bd9Sstevel@tonic-gate * The refcnt will hold the message reference count at the time
108*7c478bd9Sstevel@tonic-gate * the message was removed from the message list. Any packets
109*7c478bd9Sstevel@tonic-gate * arriving after this point for the message will be dropped.
110*7c478bd9Sstevel@tonic-gate * The message reference count is used by the threads processing
111*7c478bd9Sstevel@tonic-gate * the message to decide which one should notify the client
112*7c478bd9Sstevel@tonic-gate * (the one that decrements the reference count to zero).
113*7c478bd9Sstevel@tonic-gate */
114*7c478bd9Sstevel@tonic-gate void
ibmf_i_client_rem_msg(ibmf_client_t * clientp,ibmf_msg_impl_t * msgimplp,uint_t * refcnt)115*7c478bd9Sstevel@tonic-gate ibmf_i_client_rem_msg(ibmf_client_t *clientp, ibmf_msg_impl_t *msgimplp,
116*7c478bd9Sstevel@tonic-gate uint_t *refcnt)
117*7c478bd9Sstevel@tonic-gate {
118*7c478bd9Sstevel@tonic-gate ibmf_msg_impl_t *tmpmsg, *prevmsg = NULL;
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate ASSERT(MUTEX_NOT_HELD(&msgimplp->im_mutex));
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate IBMF_TRACE_2(IBMF_TNF_DEBUG, DPRINT_L4,
123*7c478bd9Sstevel@tonic-gate ibmf_i_client_rem_msg_start, IBMF_TNF_TRACE, "",
124*7c478bd9Sstevel@tonic-gate "ibmf_i_client_rem_msg(): clientp = 0x%p, msgp = 0x%p\n",
125*7c478bd9Sstevel@tonic-gate tnf_opaque, clientp, clientp, tnf_opaque, msg, msgimplp);
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate mutex_enter(&clientp->ic_msg_mutex);
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate /*
130*7c478bd9Sstevel@tonic-gate * If this is a termination message, remove the message from
131*7c478bd9Sstevel@tonic-gate * the termination message list else remove the message
132*7c478bd9Sstevel@tonic-gate * from the regular message list.
133*7c478bd9Sstevel@tonic-gate */
134*7c478bd9Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
135*7c478bd9Sstevel@tonic-gate if (msgimplp->im_flags & IBMF_MSG_FLAGS_TERMINATION) {
136*7c478bd9Sstevel@tonic-gate
137*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
138*7c478bd9Sstevel@tonic-gate tmpmsg = clientp->ic_term_msg_list;
139*7c478bd9Sstevel@tonic-gate
140*7c478bd9Sstevel@tonic-gate while (tmpmsg != NULL) {
141*7c478bd9Sstevel@tonic-gate if (tmpmsg == msgimplp)
142*7c478bd9Sstevel@tonic-gate break;
143*7c478bd9Sstevel@tonic-gate prevmsg = tmpmsg;
144*7c478bd9Sstevel@tonic-gate tmpmsg = tmpmsg->im_msg_next;
145*7c478bd9Sstevel@tonic-gate }
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate ASSERT(tmpmsg != NULL);
148*7c478bd9Sstevel@tonic-gate
149*7c478bd9Sstevel@tonic-gate if (tmpmsg->im_msg_next == NULL)
150*7c478bd9Sstevel@tonic-gate clientp->ic_term_msg_last = prevmsg;
151*7c478bd9Sstevel@tonic-gate else
152*7c478bd9Sstevel@tonic-gate tmpmsg->im_msg_next->im_msg_prev = prevmsg;
153*7c478bd9Sstevel@tonic-gate
154*7c478bd9Sstevel@tonic-gate if (prevmsg != NULL)
155*7c478bd9Sstevel@tonic-gate prevmsg->im_msg_next = tmpmsg->im_msg_next;
156*7c478bd9Sstevel@tonic-gate else
157*7c478bd9Sstevel@tonic-gate clientp->ic_term_msg_list = tmpmsg->im_msg_next;
158*7c478bd9Sstevel@tonic-gate } else {
159*7c478bd9Sstevel@tonic-gate
160*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
161*7c478bd9Sstevel@tonic-gate /*
162*7c478bd9Sstevel@tonic-gate * Decrement the counter and kstats for active messages
163*7c478bd9Sstevel@tonic-gate */
164*7c478bd9Sstevel@tonic-gate ASSERT(clientp->ic_msgs_active != 0);
165*7c478bd9Sstevel@tonic-gate clientp->ic_msgs_active--;
166*7c478bd9Sstevel@tonic-gate mutex_enter(&clientp->ic_kstat_mutex);
167*7c478bd9Sstevel@tonic-gate IBMF_SUB32_KSTATS(clientp, msgs_active, 1);
168*7c478bd9Sstevel@tonic-gate mutex_exit(&clientp->ic_kstat_mutex);
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate tmpmsg = clientp->ic_msg_list;
171*7c478bd9Sstevel@tonic-gate
172*7c478bd9Sstevel@tonic-gate while (tmpmsg != NULL) {
173*7c478bd9Sstevel@tonic-gate if (tmpmsg == msgimplp)
174*7c478bd9Sstevel@tonic-gate break;
175*7c478bd9Sstevel@tonic-gate prevmsg = tmpmsg;
176*7c478bd9Sstevel@tonic-gate tmpmsg = tmpmsg->im_msg_next;
177*7c478bd9Sstevel@tonic-gate }
178*7c478bd9Sstevel@tonic-gate
179*7c478bd9Sstevel@tonic-gate ASSERT(tmpmsg != NULL);
180*7c478bd9Sstevel@tonic-gate
181*7c478bd9Sstevel@tonic-gate if (tmpmsg->im_msg_next == NULL)
182*7c478bd9Sstevel@tonic-gate clientp->ic_msg_last = prevmsg;
183*7c478bd9Sstevel@tonic-gate else
184*7c478bd9Sstevel@tonic-gate tmpmsg->im_msg_next->im_msg_prev = prevmsg;
185*7c478bd9Sstevel@tonic-gate
186*7c478bd9Sstevel@tonic-gate if (prevmsg != NULL)
187*7c478bd9Sstevel@tonic-gate prevmsg->im_msg_next = tmpmsg->im_msg_next;
188*7c478bd9Sstevel@tonic-gate else
189*7c478bd9Sstevel@tonic-gate clientp->ic_msg_list = tmpmsg->im_msg_next;
190*7c478bd9Sstevel@tonic-gate }
191*7c478bd9Sstevel@tonic-gate
192*7c478bd9Sstevel@tonic-gate /* Save away the message reference count and clear the list flag */
193*7c478bd9Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
194*7c478bd9Sstevel@tonic-gate *refcnt = msgimplp->im_ref_count;
195*7c478bd9Sstevel@tonic-gate msgimplp->im_flags &= ~IBMF_MSG_FLAGS_ON_LIST;
196*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
197*7c478bd9Sstevel@tonic-gate
198*7c478bd9Sstevel@tonic-gate mutex_exit(&clientp->ic_msg_mutex);
199*7c478bd9Sstevel@tonic-gate
200*7c478bd9Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
201*7c478bd9Sstevel@tonic-gate ibmf_i_client_rem_msg_end, IBMF_TNF_TRACE, "",
202*7c478bd9Sstevel@tonic-gate "ibmf_i_client_rem_msg() exit\n");
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate
205*7c478bd9Sstevel@tonic-gate /*
206*7c478bd9Sstevel@tonic-gate * ibmf_i_find_msg():
207*7c478bd9Sstevel@tonic-gate * Walk the client message list for the message corresponding to
208*7c478bd9Sstevel@tonic-gate * the parameters specified
209*7c478bd9Sstevel@tonic-gate * The msg_list parameter should be either IBMF_REG_MSG_LIST
210*7c478bd9Sstevel@tonic-gate * or IBMF_TERM_MSG_LIST for the termination message list.
211*7c478bd9Sstevel@tonic-gate */
212*7c478bd9Sstevel@tonic-gate ibmf_msg_impl_t *
ibmf_i_find_msg(ibmf_client_t * clientp,uint64_t tid,uint8_t mgt_class,uint8_t r_method,ib_lid_t lid,ib_gid_t * gid,boolean_t gid_pr,ibmf_rmpp_hdr_t * rmpp_hdr,boolean_t msg_list)213*7c478bd9Sstevel@tonic-gate ibmf_i_find_msg(ibmf_client_t *clientp, uint64_t tid, uint8_t mgt_class,
214*7c478bd9Sstevel@tonic-gate uint8_t r_method, ib_lid_t lid, ib_gid_t *gid, boolean_t gid_pr,
215*7c478bd9Sstevel@tonic-gate ibmf_rmpp_hdr_t *rmpp_hdr, boolean_t msg_list)
216*7c478bd9Sstevel@tonic-gate {
217*7c478bd9Sstevel@tonic-gate ibmf_msg_impl_t *msgimplp;
218*7c478bd9Sstevel@tonic-gate ib_gid_t *ctx_gidp;
219*7c478bd9Sstevel@tonic-gate int msg_found;
220*7c478bd9Sstevel@tonic-gate
221*7c478bd9Sstevel@tonic-gate IBMF_TRACE_5(IBMF_TNF_DEBUG, DPRINT_L4,
222*7c478bd9Sstevel@tonic-gate ibmf_i_find_msg_start, IBMF_TNF_TRACE, "",
223*7c478bd9Sstevel@tonic-gate "ibmf_i_find_msg(): clientp = 0x%p, tid = 0x%p, mgmt_class = 0x%x, "
224*7c478bd9Sstevel@tonic-gate "lid = 0x%x, gidp = 0x%p\n", tnf_opaque, clientp, clientp,
225*7c478bd9Sstevel@tonic-gate tnf_opaque, tid, tid, tnf_opaque, mgt_class, mgt_class,
226*7c478bd9Sstevel@tonic-gate tnf_opaque, lid, lid, tnf_opaque, gid, gid);
227*7c478bd9Sstevel@tonic-gate
228*7c478bd9Sstevel@tonic-gate msg_found = B_FALSE;
229*7c478bd9Sstevel@tonic-gate
230*7c478bd9Sstevel@tonic-gate mutex_enter(&clientp->ic_msg_mutex);
231*7c478bd9Sstevel@tonic-gate
232*7c478bd9Sstevel@tonic-gate if (msg_list == IBMF_REG_MSG_LIST)
233*7c478bd9Sstevel@tonic-gate msgimplp = clientp->ic_msg_list;
234*7c478bd9Sstevel@tonic-gate else
235*7c478bd9Sstevel@tonic-gate msgimplp = clientp->ic_term_msg_list;
236*7c478bd9Sstevel@tonic-gate
237*7c478bd9Sstevel@tonic-gate /*
238*7c478bd9Sstevel@tonic-gate * Look for a transaction (message) context that matches the
239*7c478bd9Sstevel@tonic-gate * transaction ID, gid or lid, and management class of the
240*7c478bd9Sstevel@tonic-gate * incoming packet.
241*7c478bd9Sstevel@tonic-gate *
242*7c478bd9Sstevel@tonic-gate * If the client decides to do a non-rmpp or rmpp send only,
243*7c478bd9Sstevel@tonic-gate * despite expecting a response, then the response should check
244*7c478bd9Sstevel@tonic-gate * if the message context for the send still exists.
245*7c478bd9Sstevel@tonic-gate * If it does, it should be skipped.
246*7c478bd9Sstevel@tonic-gate */
247*7c478bd9Sstevel@tonic-gate while (msgimplp != NULL) {
248*7c478bd9Sstevel@tonic-gate
249*7c478bd9Sstevel@tonic-gate if (gid_pr == B_TRUE) {
250*7c478bd9Sstevel@tonic-gate
251*7c478bd9Sstevel@tonic-gate ctx_gidp = &msgimplp->im_global_addr.ig_sender_gid;
252*7c478bd9Sstevel@tonic-gate
253*7c478bd9Sstevel@tonic-gate /* first match gid */
254*7c478bd9Sstevel@tonic-gate if ((ctx_gidp->gid_prefix != gid->gid_prefix) ||
255*7c478bd9Sstevel@tonic-gate (ctx_gidp->gid_guid != gid->gid_guid)) {
256*7c478bd9Sstevel@tonic-gate
257*7c478bd9Sstevel@tonic-gate msgimplp = msgimplp->im_msg_next;
258*7c478bd9Sstevel@tonic-gate continue;
259*7c478bd9Sstevel@tonic-gate }
260*7c478bd9Sstevel@tonic-gate } else {
261*7c478bd9Sstevel@tonic-gate
262*7c478bd9Sstevel@tonic-gate IBMF_TRACE_5(IBMF_TNF_DEBUG, DPRINT_L3,
263*7c478bd9Sstevel@tonic-gate ibmf_i_find_msg, IBMF_TNF_TRACE, "",
264*7c478bd9Sstevel@tonic-gate "ibmf_i_find_msg(): %s, msgp = 0x%p, tid = 0x%p, "
265*7c478bd9Sstevel@tonic-gate "remote_lid = 0x%x, mgmt_class = 0x%x\n",
266*7c478bd9Sstevel@tonic-gate tnf_string, msg, "Comparing to msg",
267*7c478bd9Sstevel@tonic-gate tnf_opaque, msg, msgimplp,
268*7c478bd9Sstevel@tonic-gate tnf_opaque, tid, msgimplp->im_tid,
269*7c478bd9Sstevel@tonic-gate tnf_opaque, remote_lid,
270*7c478bd9Sstevel@tonic-gate msgimplp->im_local_addr.ia_remote_lid,
271*7c478bd9Sstevel@tonic-gate tnf_opaque, class, msgimplp->im_mgt_class);
272*7c478bd9Sstevel@tonic-gate
273*7c478bd9Sstevel@tonic-gate /* first match lid */
274*7c478bd9Sstevel@tonic-gate if (msgimplp->im_local_addr.ia_remote_lid != lid) {
275*7c478bd9Sstevel@tonic-gate msgimplp = msgimplp->im_msg_next;
276*7c478bd9Sstevel@tonic-gate continue;
277*7c478bd9Sstevel@tonic-gate }
278*7c478bd9Sstevel@tonic-gate }
279*7c478bd9Sstevel@tonic-gate
280*7c478bd9Sstevel@tonic-gate /* next match tid and class */
281*7c478bd9Sstevel@tonic-gate if ((msgimplp->im_tid != tid) ||
282*7c478bd9Sstevel@tonic-gate (msgimplp->im_mgt_class != mgt_class)) {
283*7c478bd9Sstevel@tonic-gate
284*7c478bd9Sstevel@tonic-gate msgimplp = msgimplp->im_msg_next;
285*7c478bd9Sstevel@tonic-gate continue;
286*7c478bd9Sstevel@tonic-gate }
287*7c478bd9Sstevel@tonic-gate
288*7c478bd9Sstevel@tonic-gate /*
289*7c478bd9Sstevel@tonic-gate * For unsolicited transactions, the message is found
290*7c478bd9Sstevel@tonic-gate * if the method matches, but,
291*7c478bd9Sstevel@tonic-gate * If the response is an ACK, and the transaction is
292*7c478bd9Sstevel@tonic-gate * in RMPP receiver mode, then skip this message.
293*7c478bd9Sstevel@tonic-gate */
294*7c478bd9Sstevel@tonic-gate if (msgimplp->im_unsolicited == B_TRUE) {
295*7c478bd9Sstevel@tonic-gate ibmf_rmpp_ctx_t *rmpp_ctx;
296*7c478bd9Sstevel@tonic-gate ibmf_msg_bufs_t *msgbufp;
297*7c478bd9Sstevel@tonic-gate
298*7c478bd9Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
299*7c478bd9Sstevel@tonic-gate rmpp_ctx = &msgimplp->im_rmpp_ctx;
300*7c478bd9Sstevel@tonic-gate
301*7c478bd9Sstevel@tonic-gate if ((msgimplp->im_flags & IBMF_MSG_FLAGS_RECV_RMPP) &&
302*7c478bd9Sstevel@tonic-gate ((rmpp_ctx->rmpp_state ==
303*7c478bd9Sstevel@tonic-gate IBMF_RMPP_STATE_RECEVR_ACTIVE) ||
304*7c478bd9Sstevel@tonic-gate (rmpp_ctx->rmpp_state ==
305*7c478bd9Sstevel@tonic-gate IBMF_RMPP_STATE_RECEVR_TERMINATE))) {
306*7c478bd9Sstevel@tonic-gate /* Continue if ACK packet */
307*7c478bd9Sstevel@tonic-gate if (rmpp_hdr->rmpp_type == IBMF_RMPP_TYPE_ACK) {
308*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
309*7c478bd9Sstevel@tonic-gate msgimplp = msgimplp->im_msg_next;
310*7c478bd9Sstevel@tonic-gate continue;
311*7c478bd9Sstevel@tonic-gate }
312*7c478bd9Sstevel@tonic-gate }
313*7c478bd9Sstevel@tonic-gate
314*7c478bd9Sstevel@tonic-gate if (msgimplp->im_trans_state_flags ==
315*7c478bd9Sstevel@tonic-gate IBMF_TRANS_STATE_FLAG_RECV_ACTIVE) {
316*7c478bd9Sstevel@tonic-gate msgbufp = &msgimplp->im_msgbufs_recv;
317*7c478bd9Sstevel@tonic-gate if (msgbufp->im_bufs_mad_hdr->R_Method ==
318*7c478bd9Sstevel@tonic-gate r_method) {
319*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
320*7c478bd9Sstevel@tonic-gate msg_found = B_TRUE;
321*7c478bd9Sstevel@tonic-gate break;
322*7c478bd9Sstevel@tonic-gate }
323*7c478bd9Sstevel@tonic-gate }
324*7c478bd9Sstevel@tonic-gate
325*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
326*7c478bd9Sstevel@tonic-gate }
327*7c478bd9Sstevel@tonic-gate
328*7c478bd9Sstevel@tonic-gate /*
329*7c478bd9Sstevel@tonic-gate * if this was an unsequenced, non-RMPP transaction there should
330*7c478bd9Sstevel@tonic-gate * be no incoming packets
331*7c478bd9Sstevel@tonic-gate */
332*7c478bd9Sstevel@tonic-gate if ((!(msgimplp->im_transp_op_flags &
333*7c478bd9Sstevel@tonic-gate IBMF_MSG_TRANS_FLAG_RMPP)) &&
334*7c478bd9Sstevel@tonic-gate (!(msgimplp->im_transp_op_flags &
335*7c478bd9Sstevel@tonic-gate IBMF_MSG_TRANS_FLAG_SEQ))) {
336*7c478bd9Sstevel@tonic-gate
337*7c478bd9Sstevel@tonic-gate msgimplp = msgimplp->im_msg_next;
338*7c478bd9Sstevel@tonic-gate continue;
339*7c478bd9Sstevel@tonic-gate }
340*7c478bd9Sstevel@tonic-gate
341*7c478bd9Sstevel@tonic-gate
342*7c478bd9Sstevel@tonic-gate /*
343*7c478bd9Sstevel@tonic-gate * if this is a sequenced transaction,
344*7c478bd9Sstevel@tonic-gate * (the send and response may or may not be RMPP)
345*7c478bd9Sstevel@tonic-gate * and the method of the incoming MAD is the same as the
346*7c478bd9Sstevel@tonic-gate * method in the send message context with the response bit
347*7c478bd9Sstevel@tonic-gate * set then this message matches.
348*7c478bd9Sstevel@tonic-gate */
349*7c478bd9Sstevel@tonic-gate if (msgimplp->im_transp_op_flags & IBMF_MSG_TRANS_FLAG_SEQ) {
350*7c478bd9Sstevel@tonic-gate ibmf_msg_bufs_t *msgbufp;
351*7c478bd9Sstevel@tonic-gate
352*7c478bd9Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
353*7c478bd9Sstevel@tonic-gate
354*7c478bd9Sstevel@tonic-gate msgbufp = &msgimplp->im_msgbufs_send;
355*7c478bd9Sstevel@tonic-gate
356*7c478bd9Sstevel@tonic-gate if ((msgbufp->im_bufs_mad_hdr->R_Method |
357*7c478bd9Sstevel@tonic-gate IBMF_RMPP_METHOD_RESP_BIT) == r_method) {
358*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
359*7c478bd9Sstevel@tonic-gate msg_found = B_TRUE;
360*7c478bd9Sstevel@tonic-gate break;
361*7c478bd9Sstevel@tonic-gate }
362*7c478bd9Sstevel@tonic-gate
363*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
364*7c478bd9Sstevel@tonic-gate }
365*7c478bd9Sstevel@tonic-gate
366*7c478bd9Sstevel@tonic-gate /*
367*7c478bd9Sstevel@tonic-gate * if this is an RMPP SEND transaction there should only
368*7c478bd9Sstevel@tonic-gate * be ACK, STOP, and ABORTS RMPP packets.
369*7c478bd9Sstevel@tonic-gate * The response data packets would have been detected in
370*7c478bd9Sstevel@tonic-gate * the check above.
371*7c478bd9Sstevel@tonic-gate */
372*7c478bd9Sstevel@tonic-gate if (msgimplp->im_transp_op_flags & IBMF_MSG_TRANS_FLAG_RMPP) {
373*7c478bd9Sstevel@tonic-gate ibmf_rmpp_ctx_t *rmpp_ctx = &msgimplp->im_rmpp_ctx;
374*7c478bd9Sstevel@tonic-gate ibmf_msg_bufs_t *msgbufp;
375*7c478bd9Sstevel@tonic-gate
376*7c478bd9Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*rmpp_ctx))
377*7c478bd9Sstevel@tonic-gate
378*7c478bd9Sstevel@tonic-gate if ((rmpp_hdr != NULL) &&
379*7c478bd9Sstevel@tonic-gate (rmpp_hdr->rmpp_flags & IBMF_RMPP_FLAGS_ACTIVE)) {
380*7c478bd9Sstevel@tonic-gate
381*7c478bd9Sstevel@tonic-gate /*
382*7c478bd9Sstevel@tonic-gate * If non-sequenced, then there should be
383*7c478bd9Sstevel@tonic-gate * no DATA packets incoming for this transaction
384*7c478bd9Sstevel@tonic-gate */
385*7c478bd9Sstevel@tonic-gate if (!(msgimplp->im_transp_op_flags &
386*7c478bd9Sstevel@tonic-gate IBMF_MSG_TRANS_FLAG_SEQ)) {
387*7c478bd9Sstevel@tonic-gate /* Continue if DATA packet */
388*7c478bd9Sstevel@tonic-gate if (rmpp_hdr->rmpp_type ==
389*7c478bd9Sstevel@tonic-gate IBMF_RMPP_TYPE_DATA) {
390*7c478bd9Sstevel@tonic-gate msgimplp =
391*7c478bd9Sstevel@tonic-gate msgimplp->im_msg_next;
392*7c478bd9Sstevel@tonic-gate continue;
393*7c478bd9Sstevel@tonic-gate }
394*7c478bd9Sstevel@tonic-gate }
395*7c478bd9Sstevel@tonic-gate
396*7c478bd9Sstevel@tonic-gate
397*7c478bd9Sstevel@tonic-gate /* Skip if R_Method does not match */
398*7c478bd9Sstevel@tonic-gate if ((rmpp_ctx->rmpp_state ==
399*7c478bd9Sstevel@tonic-gate IBMF_RMPP_STATE_SENDER_ACTIVE) ||
400*7c478bd9Sstevel@tonic-gate (rmpp_ctx->rmpp_state ==
401*7c478bd9Sstevel@tonic-gate IBMF_RMPP_STATE_SENDER_SWITCH)) {
402*7c478bd9Sstevel@tonic-gate /* Continue if DATA packet */
403*7c478bd9Sstevel@tonic-gate if (rmpp_hdr->rmpp_type ==
404*7c478bd9Sstevel@tonic-gate IBMF_RMPP_TYPE_DATA) {
405*7c478bd9Sstevel@tonic-gate msgimplp =
406*7c478bd9Sstevel@tonic-gate msgimplp->im_msg_next;
407*7c478bd9Sstevel@tonic-gate continue;
408*7c478bd9Sstevel@tonic-gate }
409*7c478bd9Sstevel@tonic-gate
410*7c478bd9Sstevel@tonic-gate /*
411*7c478bd9Sstevel@tonic-gate * Continue if method does not match
412*7c478bd9Sstevel@tonic-gate * Ignore response bit during match.
413*7c478bd9Sstevel@tonic-gate */
414*7c478bd9Sstevel@tonic-gate msgbufp = &msgimplp->im_msgbufs_send;
415*7c478bd9Sstevel@tonic-gate if ((msgbufp->im_bufs_mad_hdr->
416*7c478bd9Sstevel@tonic-gate R_Method & MAD_METHOD_MASK) !=
417*7c478bd9Sstevel@tonic-gate (r_method & MAD_METHOD_MASK)) {
418*7c478bd9Sstevel@tonic-gate msgimplp = msgimplp->
419*7c478bd9Sstevel@tonic-gate im_msg_next;
420*7c478bd9Sstevel@tonic-gate continue;
421*7c478bd9Sstevel@tonic-gate }
422*7c478bd9Sstevel@tonic-gate }
423*7c478bd9Sstevel@tonic-gate
424*7c478bd9Sstevel@tonic-gate /* Skip if R_Method does not match */
425*7c478bd9Sstevel@tonic-gate if ((rmpp_ctx->rmpp_state ==
426*7c478bd9Sstevel@tonic-gate IBMF_RMPP_STATE_RECEVR_ACTIVE) ||
427*7c478bd9Sstevel@tonic-gate (rmpp_ctx->rmpp_state ==
428*7c478bd9Sstevel@tonic-gate IBMF_RMPP_STATE_RECEVR_TERMINATE)) {
429*7c478bd9Sstevel@tonic-gate /* Continue if ACK packet */
430*7c478bd9Sstevel@tonic-gate if (rmpp_hdr->rmpp_type ==
431*7c478bd9Sstevel@tonic-gate IBMF_RMPP_TYPE_ACK) {
432*7c478bd9Sstevel@tonic-gate msgimplp =
433*7c478bd9Sstevel@tonic-gate msgimplp->im_msg_next;
434*7c478bd9Sstevel@tonic-gate continue;
435*7c478bd9Sstevel@tonic-gate }
436*7c478bd9Sstevel@tonic-gate
437*7c478bd9Sstevel@tonic-gate /* Continue if method does not match */
438*7c478bd9Sstevel@tonic-gate msgbufp = &msgimplp->im_msgbufs_recv;
439*7c478bd9Sstevel@tonic-gate if (msgbufp->im_bufs_mad_hdr->
440*7c478bd9Sstevel@tonic-gate R_Method != r_method) {
441*7c478bd9Sstevel@tonic-gate msgimplp = msgimplp->
442*7c478bd9Sstevel@tonic-gate im_msg_next;
443*7c478bd9Sstevel@tonic-gate continue;
444*7c478bd9Sstevel@tonic-gate }
445*7c478bd9Sstevel@tonic-gate }
446*7c478bd9Sstevel@tonic-gate }
447*7c478bd9Sstevel@tonic-gate }
448*7c478bd9Sstevel@tonic-gate
449*7c478bd9Sstevel@tonic-gate /*
450*7c478bd9Sstevel@tonic-gate * For a sequenced non-RMPP transaction, if the
451*7c478bd9Sstevel@tonic-gate * TID/LID/MgtClass are the same, and if the method
452*7c478bd9Sstevel@tonic-gate * of the incoming MAD and the message context are the
453*7c478bd9Sstevel@tonic-gate * same, then the MAD is likely to be a new request from
454*7c478bd9Sstevel@tonic-gate * the remote entity, so skip this message.
455*7c478bd9Sstevel@tonic-gate */
456*7c478bd9Sstevel@tonic-gate if ((msgimplp->im_transp_op_flags & IBMF_MSG_TRANS_FLAG_SEQ) &&
457*7c478bd9Sstevel@tonic-gate !(msgimplp->im_transp_op_flags &
458*7c478bd9Sstevel@tonic-gate IBMF_MSG_TRANS_FLAG_RMPP)) {
459*7c478bd9Sstevel@tonic-gate ibmf_msg_bufs_t *msgbufp;
460*7c478bd9Sstevel@tonic-gate
461*7c478bd9Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
462*7c478bd9Sstevel@tonic-gate
463*7c478bd9Sstevel@tonic-gate msgbufp = &msgimplp->im_msgbufs_send;
464*7c478bd9Sstevel@tonic-gate
465*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
466*7c478bd9Sstevel@tonic-gate
467*7c478bd9Sstevel@tonic-gate /* Continue if method is the same */
468*7c478bd9Sstevel@tonic-gate if (msgbufp->im_bufs_mad_hdr->
469*7c478bd9Sstevel@tonic-gate R_Method == r_method) {
470*7c478bd9Sstevel@tonic-gate msgimplp = msgimplp-> im_msg_next;
471*7c478bd9Sstevel@tonic-gate continue;
472*7c478bd9Sstevel@tonic-gate }
473*7c478bd9Sstevel@tonic-gate }
474*7c478bd9Sstevel@tonic-gate
475*7c478bd9Sstevel@tonic-gate /* everything matches, found the correct message */
476*7c478bd9Sstevel@tonic-gate msg_found = B_TRUE;
477*7c478bd9Sstevel@tonic-gate break;
478*7c478bd9Sstevel@tonic-gate }
479*7c478bd9Sstevel@tonic-gate
480*7c478bd9Sstevel@tonic-gate if (msg_found == B_TRUE) {
481*7c478bd9Sstevel@tonic-gate
482*7c478bd9Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
483*7c478bd9Sstevel@tonic-gate
484*7c478bd9Sstevel@tonic-gate IBMF_MSG_INCR_REFCNT(msgimplp);
485*7c478bd9Sstevel@tonic-gate
486*7c478bd9Sstevel@tonic-gate IBMF_TRACE_3(IBMF_TNF_DEBUG, DPRINT_L3,
487*7c478bd9Sstevel@tonic-gate ibmf_i_find_msg, IBMF_TNF_TRACE, "",
488*7c478bd9Sstevel@tonic-gate "ibmf_i_find_msg(): %s, msgp = 0x%p, ref_cnt = 0x%d\n",
489*7c478bd9Sstevel@tonic-gate tnf_string, msg, "Found message. Inc ref count",
490*7c478bd9Sstevel@tonic-gate tnf_opaque, msgimplp, msgimplp,
491*7c478bd9Sstevel@tonic-gate tnf_uint, ref_count, msgimplp->im_ref_count);
492*7c478bd9Sstevel@tonic-gate
493*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
494*7c478bd9Sstevel@tonic-gate }
495*7c478bd9Sstevel@tonic-gate
496*7c478bd9Sstevel@tonic-gate mutex_exit(&clientp->ic_msg_mutex);
497*7c478bd9Sstevel@tonic-gate
498*7c478bd9Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_DEBUG, DPRINT_L4,
499*7c478bd9Sstevel@tonic-gate ibmf_i_find_msg_end, IBMF_TNF_TRACE, "",
500*7c478bd9Sstevel@tonic-gate "ibmf_i_find_msg() exit, msgp = 0x%p\n", tnf_opaque, msg, msgimplp);
501*7c478bd9Sstevel@tonic-gate
502*7c478bd9Sstevel@tonic-gate return (msgimplp);
503*7c478bd9Sstevel@tonic-gate }
504*7c478bd9Sstevel@tonic-gate
505*7c478bd9Sstevel@tonic-gate /*
506*7c478bd9Sstevel@tonic-gate * ibmf_i_find_msg_client():
507*7c478bd9Sstevel@tonic-gate * Walk the client message list to find the specified message
508*7c478bd9Sstevel@tonic-gate */
509*7c478bd9Sstevel@tonic-gate boolean_t
ibmf_i_find_msg_client(ibmf_client_t * clp,ibmf_msg_impl_t * msgimplp,boolean_t inc_refcnt)510*7c478bd9Sstevel@tonic-gate ibmf_i_find_msg_client(ibmf_client_t *clp, ibmf_msg_impl_t *msgimplp,
511*7c478bd9Sstevel@tonic-gate boolean_t inc_refcnt)
512*7c478bd9Sstevel@tonic-gate {
513*7c478bd9Sstevel@tonic-gate ibmf_msg_impl_t *msgp;
514*7c478bd9Sstevel@tonic-gate boolean_t found = B_FALSE;
515*7c478bd9Sstevel@tonic-gate
516*7c478bd9Sstevel@tonic-gate IBMF_TRACE_2(IBMF_TNF_DEBUG, DPRINT_L4,
517*7c478bd9Sstevel@tonic-gate ibmf_i_find_msg_client_start, IBMF_TNF_TRACE, "",
518*7c478bd9Sstevel@tonic-gate "ibmf_i_find_msg_client(): clientp = 0x%p, msgp = 0x%p\n",
519*7c478bd9Sstevel@tonic-gate tnf_opaque, clientp, clp, tnf_opaque, msg, msgimplp);
520*7c478bd9Sstevel@tonic-gate
521*7c478bd9Sstevel@tonic-gate mutex_enter(&clp->ic_msg_mutex);
522*7c478bd9Sstevel@tonic-gate
523*7c478bd9Sstevel@tonic-gate msgp = clp->ic_msg_list;
524*7c478bd9Sstevel@tonic-gate while (msgp != NULL) {
525*7c478bd9Sstevel@tonic-gate
526*7c478bd9Sstevel@tonic-gate if (msgp == msgimplp) {
527*7c478bd9Sstevel@tonic-gate
528*7c478bd9Sstevel@tonic-gate /* grab the mutex */
529*7c478bd9Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
530*7c478bd9Sstevel@tonic-gate
531*7c478bd9Sstevel@tonic-gate if (inc_refcnt == B_TRUE)
532*7c478bd9Sstevel@tonic-gate IBMF_MSG_INCR_REFCNT(msgimplp);
533*7c478bd9Sstevel@tonic-gate
534*7c478bd9Sstevel@tonic-gate IBMF_TRACE_3(IBMF_TNF_DEBUG, DPRINT_L3,
535*7c478bd9Sstevel@tonic-gate ibmf_i_find_msg_client, IBMF_TNF_TRACE, "",
536*7c478bd9Sstevel@tonic-gate "ibmf_i_find_msg_client(): %s, msgp = 0x%p, "
537*7c478bd9Sstevel@tonic-gate "ref_cnt = 0x%d\n",
538*7c478bd9Sstevel@tonic-gate tnf_string, msg, "Found message. Inc ref count",
539*7c478bd9Sstevel@tonic-gate tnf_opaque, msgimplp, msgimplp,
540*7c478bd9Sstevel@tonic-gate tnf_uint, ref_count, msgimplp->im_ref_count);
541*7c478bd9Sstevel@tonic-gate
542*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
543*7c478bd9Sstevel@tonic-gate
544*7c478bd9Sstevel@tonic-gate found = B_TRUE;
545*7c478bd9Sstevel@tonic-gate
546*7c478bd9Sstevel@tonic-gate break;
547*7c478bd9Sstevel@tonic-gate }
548*7c478bd9Sstevel@tonic-gate msgp = msgp->im_msg_next;
549*7c478bd9Sstevel@tonic-gate }
550*7c478bd9Sstevel@tonic-gate
551*7c478bd9Sstevel@tonic-gate /*
552*7c478bd9Sstevel@tonic-gate * If not found on the regular message list,
553*7c478bd9Sstevel@tonic-gate * look in the termination list.
554*7c478bd9Sstevel@tonic-gate */
555*7c478bd9Sstevel@tonic-gate if (found == B_FALSE) {
556*7c478bd9Sstevel@tonic-gate msgp = clp->ic_term_msg_list;
557*7c478bd9Sstevel@tonic-gate while (msgp != NULL) {
558*7c478bd9Sstevel@tonic-gate if (msgp == msgimplp) {
559*7c478bd9Sstevel@tonic-gate
560*7c478bd9Sstevel@tonic-gate /* grab the mutex */
561*7c478bd9Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
562*7c478bd9Sstevel@tonic-gate
563*7c478bd9Sstevel@tonic-gate if (inc_refcnt == B_TRUE)
564*7c478bd9Sstevel@tonic-gate IBMF_MSG_INCR_REFCNT(msgimplp);
565*7c478bd9Sstevel@tonic-gate
566*7c478bd9Sstevel@tonic-gate IBMF_TRACE_3(IBMF_TNF_DEBUG, DPRINT_L3,
567*7c478bd9Sstevel@tonic-gate ibmf_i_find_msg_client, IBMF_TNF_TRACE, "",
568*7c478bd9Sstevel@tonic-gate "ibmf_i_find_msg_client(): %s, "
569*7c478bd9Sstevel@tonic-gate "msgp = 0x%p, ref_cnt = 0x%d\n", tnf_string,
570*7c478bd9Sstevel@tonic-gate msg, "Found message. Inc ref count",
571*7c478bd9Sstevel@tonic-gate tnf_opaque, msgimplp, msgimplp, tnf_uint,
572*7c478bd9Sstevel@tonic-gate ref_count, msgimplp->im_ref_count);
573*7c478bd9Sstevel@tonic-gate
574*7c478bd9Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
575*7c478bd9Sstevel@tonic-gate found = B_TRUE;
576*7c478bd9Sstevel@tonic-gate break;
577*7c478bd9Sstevel@tonic-gate }
578*7c478bd9Sstevel@tonic-gate msgp = msgp->im_msg_next;
579*7c478bd9Sstevel@tonic-gate }
580*7c478bd9Sstevel@tonic-gate }
581*7c478bd9Sstevel@tonic-gate
582*7c478bd9Sstevel@tonic-gate mutex_exit(&clp->ic_msg_mutex);
583*7c478bd9Sstevel@tonic-gate
584*7c478bd9Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
585*7c478bd9Sstevel@tonic-gate ibmf_i_find_msg_client_end, IBMF_TNF_TRACE, "",
586*7c478bd9Sstevel@tonic-gate "ibmf_i_find_msg_client() exit\n");
587*7c478bd9Sstevel@tonic-gate
588*7c478bd9Sstevel@tonic-gate return (found);
589*7c478bd9Sstevel@tonic-gate }
590*7c478bd9Sstevel@tonic-gate
591*7c478bd9Sstevel@tonic-gate /*
592*7c478bd9Sstevel@tonic-gate * ibmf_setup_recvbuf_on_error():
593*7c478bd9Sstevel@tonic-gate *
594*7c478bd9Sstevel@tonic-gate * This function is used to set up the receive buffers to provide
595*7c478bd9Sstevel@tonic-gate * a context for sending ABORT MADs in cases where the protocol
596*7c478bd9Sstevel@tonic-gate * fails before the receive buffers have been setup. This can happen
597*7c478bd9Sstevel@tonic-gate * if the initial receive MAD has a bad version, or an unexpected
598*7c478bd9Sstevel@tonic-gate * segment number, for example.
599*7c478bd9Sstevel@tonic-gate * We allocate IBMF_MAD_SIZE memory as we only need the information
600*7c478bd9Sstevel@tonic-gate * stored in the MAD header and the class header to be able to send
601*7c478bd9Sstevel@tonic-gate * the ABORT.
602*7c478bd9Sstevel@tonic-gate */
603*7c478bd9Sstevel@tonic-gate int
ibmf_setup_recvbuf_on_error(ibmf_msg_impl_t * msgimplp,uchar_t * mad)604*7c478bd9Sstevel@tonic-gate ibmf_setup_recvbuf_on_error(ibmf_msg_impl_t *msgimplp, uchar_t *mad)
605*7c478bd9Sstevel@tonic-gate {
606*7c478bd9Sstevel@tonic-gate size_t offset;
607*7c478bd9Sstevel@tonic-gate uint32_t cl_hdr_sz, cl_hdr_off;
608*7c478bd9Sstevel@tonic-gate ib_mad_hdr_t *mad_hdr;
609*7c478bd9Sstevel@tonic-gate uchar_t *msgbufp;
610*7c478bd9Sstevel@tonic-gate ibmf_client_t *clientp = (ibmf_client_t *)msgimplp->im_client;
611*7c478bd9Sstevel@tonic-gate
612*7c478bd9Sstevel@tonic-gate ASSERT(msgimplp->im_msgbufs_recv.im_bufs_mad_hdr == NULL);
613*7c478bd9Sstevel@tonic-gate
614*7c478bd9Sstevel@tonic-gate /*
615*7c478bd9Sstevel@tonic-gate * Allocate enough memory for the MAD headers only.
616*7c478bd9Sstevel@tonic-gate */
617*7c478bd9Sstevel@tonic-gate msgimplp->im_msgbufs_recv.im_bufs_mad_hdr =
618*7c478bd9Sstevel@tonic-gate (ib_mad_hdr_t *)kmem_zalloc(IBMF_MAD_SIZE, KM_NOSLEEP);
619*7c478bd9Sstevel@tonic-gate if (msgimplp->im_msgbufs_recv.im_bufs_mad_hdr == NULL) {
620*7c478bd9Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_NODEBUG, DPRINT_L1,
621*7c478bd9Sstevel@tonic-gate ibmf_setup_recvbuf_on_error, IBMF_TNF_ERROR, "",
622*7c478bd9Sstevel@tonic-gate "ibmf_setup_recvbuf_on_error(): %s\n", tnf_string, msg,
623*7c478bd9Sstevel@tonic-gate "recv buf mem allocation failure");
624*7c478bd9Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
625*7c478bd9Sstevel@tonic-gate ibmf_setup_recvbuf_on_error_end, IBMF_TNF_TRACE, "",
626*7c478bd9Sstevel@tonic-gate "ibmf_setup_recvbuf_on_error() exit\n");
627*7c478bd9Sstevel@tonic-gate return (IBMF_NO_RESOURCES);
628*7c478bd9Sstevel@tonic-gate }
629*7c478bd9Sstevel@tonic-gate
630*7c478bd9Sstevel@tonic-gate mutex_enter(&clientp->ic_kstat_mutex);
631*7c478bd9Sstevel@tonic-gate IBMF_ADD32_KSTATS(clientp, recv_bufs_alloced, 1);
632*7c478bd9Sstevel@tonic-gate mutex_exit(&clientp->ic_kstat_mutex);
633*7c478bd9Sstevel@tonic-gate
634*7c478bd9Sstevel@tonic-gate mad_hdr = (ib_mad_hdr_t *)mad;
635*7c478bd9Sstevel@tonic-gate
636*7c478bd9Sstevel@tonic-gate /* Get the class header size and offset */
637*7c478bd9Sstevel@tonic-gate ibmf_i_mgt_class_to_hdr_sz_off(mad_hdr->MgmtClass, &cl_hdr_sz,
638*7c478bd9Sstevel@tonic-gate &cl_hdr_off);
639*7c478bd9Sstevel@tonic-gate
640*7c478bd9Sstevel@tonic-gate msgbufp = (uchar_t *)msgimplp->im_msgbufs_recv.im_bufs_mad_hdr;
641*7c478bd9Sstevel@tonic-gate
642*7c478bd9Sstevel@tonic-gate /* copy the MAD and class header */
643*7c478bd9Sstevel@tonic-gate bcopy((const void *)mad, (void *)msgbufp,
644*7c478bd9Sstevel@tonic-gate sizeof (ib_mad_hdr_t) + cl_hdr_off + cl_hdr_sz);
645*7c478bd9Sstevel@tonic-gate
646*7c478bd9Sstevel@tonic-gate /* offset of the class header */
647*7c478bd9Sstevel@tonic-gate offset = sizeof (ib_mad_hdr_t) + cl_hdr_off;
648*7c478bd9Sstevel@tonic-gate
649*7c478bd9Sstevel@tonic-gate /* initialize class header pointer */
650*7c478bd9Sstevel@tonic-gate if (cl_hdr_sz == 0) {
651*7c478bd9Sstevel@tonic-gate msgimplp->im_msgbufs_recv.im_bufs_cl_hdr = NULL;
652*7c478bd9Sstevel@tonic-gate } else {
653*7c478bd9Sstevel@tonic-gate msgimplp->im_msgbufs_recv.im_bufs_cl_hdr =
654*7c478bd9Sstevel@tonic-gate (void *)(msgbufp + offset);
655*7c478bd9Sstevel@tonic-gate }
656*7c478bd9Sstevel@tonic-gate
657*7c478bd9Sstevel@tonic-gate /* Set the class header length */
658*7c478bd9Sstevel@tonic-gate msgimplp->im_msgbufs_recv.im_bufs_cl_hdr_len = cl_hdr_sz;
659*7c478bd9Sstevel@tonic-gate
660*7c478bd9Sstevel@tonic-gate /* offset of the class data */
661*7c478bd9Sstevel@tonic-gate offset += cl_hdr_sz;
662*7c478bd9Sstevel@tonic-gate
663*7c478bd9Sstevel@tonic-gate /* initialize data area pointer */
664*7c478bd9Sstevel@tonic-gate msgimplp->im_msgbufs_recv.im_bufs_cl_data = (void *)(msgbufp + offset);
665*7c478bd9Sstevel@tonic-gate msgimplp->im_msgbufs_recv.im_bufs_cl_data_len = IBMF_MAD_SIZE -
666*7c478bd9Sstevel@tonic-gate sizeof (ib_mad_hdr_t) - cl_hdr_off - cl_hdr_sz;
667*7c478bd9Sstevel@tonic-gate
668*7c478bd9Sstevel@tonic-gate return (IBMF_SUCCESS);
669*7c478bd9Sstevel@tonic-gate }
670