Print this page
8368 remove warlock leftovers from usr/src/uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/ib/clients/rdsv3/ib_cm.c
+++ new/usr/src/uts/common/io/ib/clients/rdsv3/ib_cm.c
1 1 /*
2 2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 3 */
4 4
5 5 /*
6 6 * This file contains code imported from the OFED rds source file ib_cm.c
7 7 * Oracle elects to have and use the contents of ib_cm.c under and governed
8 8 * by the OpenIB.org BSD license (see below for full license text). However,
9 9 * the following notice accompanied the original version of this file:
10 10 */
11 11
12 12 /*
13 13 * Copyright (c) 2006 Oracle. All rights reserved.
14 14 *
15 15 * This software is available to you under a choice of one of two
16 16 * licenses. You may choose to be licensed under the terms of the GNU
17 17 * General Public License (GPL) Version 2, available from the file
18 18 * COPYING in the main directory of this source tree, or the
19 19 * OpenIB.org BSD license below:
20 20 *
21 21 * Redistribution and use in source and binary forms, with or
22 22 * without modification, are permitted provided that the following
23 23 * conditions are met:
24 24 *
25 25 * - Redistributions of source code must retain the above
26 26 * copyright notice, this list of conditions and the following
27 27 * disclaimer.
28 28 *
29 29 * - Redistributions in binary form must reproduce the above
30 30 * copyright notice, this list of conditions and the following
31 31 * disclaimer in the documentation and/or other materials
32 32 * provided with the distribution.
33 33 *
34 34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35 35 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36 36 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37 37 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
38 38 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
39 39 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40 40 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41 41 * SOFTWARE.
42 42 *
43 43 */
44 44 #include <sys/rds.h>
45 45
46 46 #include <sys/ib/clients/of/ofed_kernel.h>
47 47 #include <sys/ib/clients/of/rdma/ib_addr.h>
48 48 #include <sys/ib/clients/of/rdma/rdma_cm.h>
49 49
50 50 #include <sys/ib/clients/rdsv3/rdsv3.h>
51 51 #include <sys/ib/clients/rdsv3/ib.h>
52 52 #include <sys/ib/clients/rdsv3/rdsv3_debug.h>
53 53
54 54 extern int rdsv3_enable_snd_cq;
55 55
56 56 /*
57 57 * Set the selected protocol version
58 58 */
59 59 static void
60 60 rdsv3_ib_set_protocol(struct rdsv3_connection *conn, unsigned int version)
61 61 {
62 62 RDSV3_DPRINTF4("rdsv3_ib_set_protocol", "conn: %p version: %d",
63 63 conn, version);
64 64 conn->c_version = version;
65 65 }
66 66
67 67 /*
68 68 * Set up flow control
69 69 */
70 70 static void
71 71 rdsv3_ib_set_flow_control(struct rdsv3_connection *conn, uint32_t credits)
72 72 {
73 73 struct rdsv3_ib_connection *ic = conn->c_transport_data;
74 74
75 75 RDSV3_DPRINTF2("rdsv3_ib_set_flow_control",
76 76 "Enter: conn: %p credits: %d", conn, credits);
77 77
78 78 if (rdsv3_ib_sysctl_flow_control && credits != 0) {
79 79 /* We're doing flow control */
80 80 ic->i_flowctl = 1;
81 81 rdsv3_ib_send_add_credits(conn, credits);
82 82 } else {
83 83 ic->i_flowctl = 0;
84 84 }
85 85
86 86 RDSV3_DPRINTF2("rdsv3_ib_set_flow_control",
87 87 "Return: conn: %p credits: %d",
88 88 conn, credits);
89 89 }
90 90
91 91 /*
92 92 * Tune RNR behavior. Without flow control, we use a rather
93 93 * low timeout, but not the absolute minimum - this should
94 94 * be tunable.
95 95 *
96 96 * We already set the RNR retry count to 7 (which is the
97 97 * smallest infinite number :-) above.
98 98 * If flow control is off, we want to change this back to 0
99 99 * so that we learn quickly when our credit accounting is
100 100 * buggy.
101 101 *
102 102 * Caller passes in a qp_attr pointer - don't waste stack spacv
103 103 * by allocation this twice.
104 104 */
105 105 static void
106 106 rdsv3_ib_tune_rnr(struct rdsv3_ib_connection *ic, struct ib_qp_attr *attr)
107 107 {
108 108 int ret;
109 109
110 110 RDSV3_DPRINTF2("rdsv3_ib_tune_rnr", "Enter ic: %p attr: %p",
111 111 ic, attr);
112 112
113 113 attr->min_rnr_timer = IB_RNR_TIMER_000_32;
114 114 ret = ib_modify_qp(ic->i_cm_id->qp, attr, IB_QP_MIN_RNR_TIMER);
115 115 if (ret)
116 116 RDSV3_DPRINTF2("rdsv3_ib_tune_rnr",
117 117 "ib_modify_qp(IB_QP_MIN_RNR_TIMER): err=%d", -ret);
118 118 }
119 119
120 120 /*
121 121 * Connection established.
122 122 * We get here for both outgoing and incoming connection.
123 123 */
124 124 void
125 125 rdsv3_ib_cm_connect_complete(struct rdsv3_connection *conn,
126 126 struct rdma_cm_event *event)
127 127 {
128 128 const struct rdsv3_ib_connect_private *dp = NULL;
129 129 struct rdsv3_ib_connection *ic = conn->c_transport_data;
130 130 struct rdsv3_ib_device *rds_ibdev =
131 131 ib_get_client_data(ic->i_cm_id->device, &rdsv3_ib_client);
132 132 struct ib_qp_attr qp_attr;
133 133 int err;
134 134
135 135 RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
136 136 "Enter conn: %p event: %p", conn, event);
137 137
138 138 if (event->param.conn.private_data_len >= sizeof (*dp)) {
139 139 dp = event->param.conn.private_data;
140 140
141 141 /* make sure it isn't empty data */
142 142 if (dp->dp_protocol_major) {
143 143 rdsv3_ib_set_protocol(conn,
144 144 RDS_PROTOCOL(dp->dp_protocol_major,
145 145 dp->dp_protocol_minor));
146 146 rdsv3_ib_set_flow_control(conn,
147 147 ntohl(dp->dp_credit));
148 148 }
149 149 }
150 150
151 151 if (conn->c_version < RDS_PROTOCOL(3, 1)) {
152 152 RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
153 153 "RDS/IB: Connection to %u.%u.%u.%u version %u.%u failed",
154 154 NIPQUAD(conn->c_faddr),
155 155 RDS_PROTOCOL_MAJOR(conn->c_version),
156 156 RDS_PROTOCOL_MINOR(conn->c_version));
157 157 rdsv3_conn_destroy(conn);
158 158 return;
159 159 } else {
160 160 RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
161 161 "RDS/IB: connected to %u.%u.%u.%u version %u.%u%s",
162 162 NIPQUAD(conn->c_faddr),
163 163 RDS_PROTOCOL_MAJOR(conn->c_version),
164 164 RDS_PROTOCOL_MINOR(conn->c_version),
165 165 ic->i_flowctl ? ", flow control" : "");
166 166 }
167 167
168 168 ASSERT(ic->i_soft_cq == NULL);
169 169 ic->i_soft_cq = rdsv3_af_intr_thr_create(rdsv3_ib_tasklet_fn,
170 170 (void *)ic, SCQ_INTR_BIND_CPU, rds_ibdev->aft_hcagp,
171 171 ic->i_cq->ibt_cq);
172 172 if (rdsv3_enable_snd_cq) {
173 173 ic->i_snd_soft_cq = rdsv3_af_intr_thr_create(
174 174 rdsv3_ib_snd_tasklet_fn,
175 175 (void *)ic, SCQ_INTR_BIND_CPU, rds_ibdev->aft_hcagp,
176 176 ic->i_snd_cq->ibt_cq);
177 177 }
178 178 /* rdsv3_ib_refill_fn is expecting i_max_recv_alloc set */
179 179 ic->i_max_recv_alloc = rdsv3_ib_sysctl_max_recv_allocation;
180 180 ic->i_refill_rq = rdsv3_af_thr_create(rdsv3_ib_refill_fn, (void *)conn,
181 181 SCQ_WRK_BIND_CPU, rds_ibdev->aft_hcagp);
182 182 rdsv3_af_grp_draw(rds_ibdev->aft_hcagp);
183 183
184 184 (void) ib_req_notify_cq(ic->i_cq, IB_CQ_SOLICITED);
185 185 if (rdsv3_enable_snd_cq) {
186 186 (void) ib_req_notify_cq(ic->i_snd_cq, IB_CQ_NEXT_COMP);
187 187 }
188 188
189 189 /*
190 190 * Init rings and fill recv. this needs to wait until protocol
191 191 * negotiation
192 192 * is complete, since ring layout is different from 3.0 to 3.1.
193 193 */
194 194 rdsv3_ib_send_init_ring(ic);
195 195 rdsv3_ib_recv_init_ring(ic);
196 196 /*
197 197 * Post receive buffers - as a side effect, this will update
198 198 * the posted credit count.
199 199 */
200 200 (void) rdsv3_ib_recv_refill(conn, 1);
201 201
202 202 /* Tune RNR behavior */
203 203 rdsv3_ib_tune_rnr(ic, &qp_attr);
204 204
205 205 qp_attr.qp_state = IB_QPS_RTS;
206 206 err = ib_modify_qp(ic->i_cm_id->qp, &qp_attr, IB_QP_STATE);
207 207 if (err)
208 208 RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
209 209 "ib_modify_qp(IB_QP_STATE, RTS): err=%d", err);
210 210
211 211 /* update ib_device with this local ipaddr & conn */
212 212 err = rdsv3_ib_update_ipaddr(rds_ibdev, conn->c_laddr);
213 213 if (err)
214 214 RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
215 215 "rdsv3_ib_update_ipaddr failed (%d)", err);
216 216 rdsv3_ib_add_conn(rds_ibdev, conn);
217 217
218 218 /*
219 219 * If the peer gave us the last packet it saw, process this as if
220 220 * we had received a regular ACK.
221 221 */
222 222 if (dp && dp->dp_ack_seq)
223 223 rdsv3_send_drop_acked(conn, ntohll(dp->dp_ack_seq), NULL);
224 224
225 225 rdsv3_connect_complete(conn);
226 226
227 227 RDSV3_DPRINTF2("rdsv3_ib_cm_connect_complete",
228 228 "Return conn: %p event: %p",
229 229 conn, event);
230 230 }
231 231
232 232 static void
233 233 rdsv3_ib_cm_fill_conn_param(struct rdsv3_connection *conn,
234 234 struct rdma_conn_param *conn_param,
235 235 struct rdsv3_ib_connect_private *dp,
236 236 uint32_t protocol_version,
237 237 uint32_t max_responder_resources,
238 238 uint32_t max_initiator_depth)
239 239 {
240 240 struct rdsv3_ib_connection *ic = conn->c_transport_data;
241 241 struct rdsv3_ib_device *rds_ibdev;
242 242
243 243 RDSV3_DPRINTF2("rdsv3_ib_cm_fill_conn_param",
244 244 "Enter conn: %p conn_param: %p private: %p version: %d",
245 245 conn, conn_param, dp, protocol_version);
246 246
247 247 (void) memset(conn_param, 0, sizeof (struct rdma_conn_param));
248 248
249 249 rds_ibdev = ib_get_client_data(ic->i_cm_id->device, &rdsv3_ib_client);
250 250
251 251 conn_param->responder_resources =
252 252 MIN(rds_ibdev->max_responder_resources, max_responder_resources);
253 253 conn_param->initiator_depth =
254 254 MIN(rds_ibdev->max_initiator_depth, max_initiator_depth);
255 255 conn_param->retry_count = min(rdsv3_ib_retry_count, 7);
256 256 conn_param->rnr_retry_count = 7;
257 257
258 258 if (dp) {
259 259 (void) memset(dp, 0, sizeof (*dp));
260 260 dp->dp_saddr = conn->c_laddr;
261 261 dp->dp_daddr = conn->c_faddr;
262 262 dp->dp_protocol_major = RDS_PROTOCOL_MAJOR(protocol_version);
263 263 dp->dp_protocol_minor = RDS_PROTOCOL_MINOR(protocol_version);
264 264 dp->dp_protocol_minor_mask =
265 265 htons(RDSV3_IB_SUPPORTED_PROTOCOLS);
266 266 dp->dp_ack_seq = rdsv3_ib_piggyb_ack(ic);
267 267
268 268 /* Advertise flow control */
269 269 if (ic->i_flowctl) {
270 270 unsigned int credits;
271 271
272 272 credits = IB_GET_POST_CREDITS(
273 273 atomic_get(&ic->i_credits));
274 274 dp->dp_credit = htonl(credits);
275 275 atomic_add_32(&ic->i_credits,
276 276 -IB_SET_POST_CREDITS(credits));
277 277 }
278 278
279 279 conn_param->private_data = dp;
280 280 conn_param->private_data_len = sizeof (*dp);
281 281 }
282 282
283 283 RDSV3_DPRINTF2("rdsv3_ib_cm_fill_conn_param",
284 284 "Return conn: %p conn_param: %p private: %p version: %d",
285 285 conn, conn_param, dp, protocol_version);
286 286 }
287 287
288 288 static void
289 289 rdsv3_ib_cq_event_handler(struct ib_event *event, void *data)
290 290 {
291 291 RDSV3_DPRINTF3("rdsv3_ib_cq_event_handler", "event %u data %p",
292 292 event->event, data);
293 293 }
294 294
295 295 static void
296 296 rdsv3_ib_snd_cq_comp_handler(struct ib_cq *cq, void *context)
297 297 {
298 298 struct rdsv3_connection *conn = context;
299 299 struct rdsv3_ib_connection *ic = conn->c_transport_data;
300 300
301 301 RDSV3_DPRINTF4("rdsv3_ib_snd_cq_comp_handler",
302 302 "Enter(conn: %p ic: %p cq: %p)", conn, ic, cq);
303 303
304 304 rdsv3_af_thr_fire(ic->i_snd_soft_cq);
305 305 }
306 306
307 307 void
308 308 rdsv3_ib_snd_tasklet_fn(void *data)
309 309 {
310 310 struct rdsv3_ib_connection *ic = (struct rdsv3_ib_connection *)data;
311 311 struct rdsv3_connection *conn = ic->conn;
312 312 struct rdsv3_ib_ack_state ack_state = { 0, };
313 313 ibt_wc_t wc;
314 314 uint_t polled;
315 315
316 316 RDSV3_DPRINTF4("rdsv3_ib_snd_tasklet_fn",
317 317 "Enter(conn: %p ic: %p)", conn, ic);
318 318
319 319 /*
320 320 * Poll in a loop before and after enabling the next event
321 321 */
322 322 while (ibt_poll_cq(RDSV3_CQ2CQHDL(ic->i_snd_cq), &wc, 1, &polled) ==
323 323 IBT_SUCCESS) {
324 324 RDSV3_DPRINTF4("rdsv3_ib_snd_tasklet_fn",
325 325 "wc_id 0x%llx type %d status %u byte_len %u imm_data %u\n",
326 326 (unsigned long long)wc.wc_id, wc.wc_type, wc.wc_status,
327 327 wc.wc_bytes_xfer, ntohl(wc.wc_immed_data));
328 328
329 329 ASSERT(wc.wc_id & RDSV3_IB_SEND_OP);
330 330 rdsv3_ib_send_cqe_handler(ic, &wc);
331 331 }
332 332 (void) ibt_enable_cq_notify(RDSV3_CQ2CQHDL(ic->i_snd_cq),
333 333 IBT_NEXT_COMPLETION);
334 334 while (ibt_poll_cq(RDSV3_CQ2CQHDL(ic->i_snd_cq), &wc, 1, &polled) ==
335 335 IBT_SUCCESS) {
336 336 RDSV3_DPRINTF4("rdsv3_ib_snd_tasklet_fn",
337 337 "wc_id 0x%llx type %d status %u byte_len %u imm_data %u\n",
338 338 (unsigned long long)wc.wc_id, wc.wc_type, wc.wc_status,
339 339 wc.wc_bytes_xfer, ntohl(wc.wc_immed_data));
340 340
341 341 ASSERT(wc.wc_id & RDSV3_IB_SEND_OP);
342 342 rdsv3_ib_send_cqe_handler(ic, &wc);
343 343 }
344 344 }
345 345
346 346 static void
347 347 rdsv3_ib_cq_comp_handler(struct ib_cq *cq, void *context)
348 348 {
349 349 struct rdsv3_connection *conn = context;
350 350 struct rdsv3_ib_connection *ic = conn->c_transport_data;
351 351
352 352 RDSV3_DPRINTF4("rdsv3_ib_cq_comp_handler",
353 353 "Enter(conn: %p cq: %p)", conn, cq);
354 354
355 355 rdsv3_ib_stats_inc(s_ib_evt_handler_call);
356 356
357 357 rdsv3_af_thr_fire(ic->i_soft_cq);
358 358 }
359 359
360 360 void
361 361 rdsv3_ib_refill_fn(void *data)
362 362 {
363 363 struct rdsv3_connection *conn = (struct rdsv3_connection *)data;
364 364
365 365 (void) rdsv3_ib_recv_refill(conn, 0);
366 366 }
367 367
368 368 void
369 369 rdsv3_ib_tasklet_fn(void *data)
370 370 {
371 371 struct rdsv3_ib_connection *ic = (struct rdsv3_ib_connection *)data;
372 372 struct rdsv3_connection *conn = ic->conn;
373 373 struct rdsv3_ib_ack_state ack_state = { 0, };
374 374 ibt_wc_t wc[RDSV3_IB_WC_POLL_SIZE];
375 375 uint_t polled;
376 376 int i;
377 377
378 378 RDSV3_DPRINTF4("rdsv3_ib_tasklet_fn",
379 379 "Enter(conn: %p ic: %p)", conn, ic);
380 380
381 381 rdsv3_ib_stats_inc(s_ib_tasklet_call);
382 382
383 383 /*
384 384 * Poll in a loop before and after enabling the next event
385 385 */
386 386 while (ibt_poll_cq(RDSV3_CQ2CQHDL(ic->i_cq), &wc[0],
387 387 RDSV3_IB_WC_POLL_SIZE, &polled) == IBT_SUCCESS) {
388 388 for (i = 0; i < polled; i++) {
389 389 RDSV3_DPRINTF4("rdsv3_ib_tasklet_fn",
390 390 "wc_id 0x%llx type %d status %u byte_len %u \
391 391 imm_data %u\n",
392 392 (unsigned long long)wc[i].wc_id, wc[i].wc_type,
393 393 wc[i].wc_status, wc[i].wc_bytes_xfer,
394 394 ntohl(wc[i].wc_immed_data));
395 395
396 396 if (wc[i].wc_id & RDSV3_IB_SEND_OP) {
397 397 rdsv3_ib_send_cqe_handler(ic, &wc[i]);
398 398 } else {
399 399 rdsv3_ib_recv_cqe_handler(ic, &wc[i],
400 400 &ack_state);
401 401 }
402 402 }
403 403 }
404 404 (void) ibt_enable_cq_notify(RDSV3_CQ2CQHDL(ic->i_cq),
405 405 IBT_NEXT_SOLICITED);
406 406 while (ibt_poll_cq(RDSV3_CQ2CQHDL(ic->i_cq), &wc[0],
407 407 RDSV3_IB_WC_POLL_SIZE, &polled) == IBT_SUCCESS) {
408 408 for (i = 0; i < polled; i++) {
409 409 RDSV3_DPRINTF4("rdsv3_ib_tasklet_fn",
410 410 "wc_id 0x%llx type %d status %u byte_len %u \
411 411 imm_data %u\n",
412 412 (unsigned long long)wc[i].wc_id, wc[i].wc_type,
413 413 wc[i].wc_status, wc[i].wc_bytes_xfer,
414 414 ntohl(wc[i].wc_immed_data));
415 415
416 416 if (wc[i].wc_id & RDSV3_IB_SEND_OP) {
417 417 rdsv3_ib_send_cqe_handler(ic, &wc[i]);
418 418 } else {
419 419 rdsv3_ib_recv_cqe_handler(ic, &wc[i],
420 420 &ack_state);
421 421 }
422 422 }
423 423 }
424 424
425 425 if (ack_state.ack_next_valid) {
426 426 rdsv3_ib_set_ack(ic, ack_state.ack_next,
427 427 ack_state.ack_required);
428 428 }
429 429 if (ack_state.ack_recv_valid && ack_state.ack_recv > ic->i_ack_recv) {
430 430 rdsv3_send_drop_acked(conn, ack_state.ack_recv, NULL);
431 431 ic->i_ack_recv = ack_state.ack_recv;
432 432 }
433 433 if (rdsv3_conn_up(conn)) {
434 434 if (!test_bit(RDSV3_LL_SEND_FULL, &conn->c_flags))
435 435 (void) rdsv3_send_xmit(ic->conn);
436 436 rdsv3_ib_attempt_ack(ic);
437 437 }
438 438 }
439 439
440 440 static void
441 441 rdsv3_ib_qp_event_handler(struct ib_event *event, void *data)
442 442 {
443 443 struct rdsv3_connection *conn = data;
444 444 struct rdsv3_ib_connection *ic = conn->c_transport_data;
445 445
446 446 RDSV3_DPRINTF2("rdsv3_ib_qp_event_handler", "conn %p ic %p event %u",
447 447 conn, ic, event->event);
448 448
449 449 switch (event->event) {
450 450 case IB_EVENT_COMM_EST:
451 451 (void) rdma_notify(ic->i_cm_id, IB_EVENT_COMM_EST);
452 452 break;
453 453 default:
454 454 if (conn) {
455 455 RDSV3_DPRINTF2("rdsv3_ib_qp_event_handler",
456 456 "RDS/IB: Fatal QP Event %u - "
457 457 "connection %u.%u.%u.%u ->%u.%u.%u.%u "
458 458 "...reconnecting",
459 459 event->event, NIPQUAD(conn->c_laddr),
460 460 NIPQUAD(conn->c_faddr));
461 461 rdsv3_conn_drop(conn);
462 462 } else {
463 463 RDSV3_DPRINTF2("rdsv3_ib_qp_event_handler",
464 464 "RDS/IB: Fatal QP Event %u - connection"
465 465 "...reconnecting", event->event);
466 466 }
467 467 break;
468 468 }
469 469
470 470 RDSV3_DPRINTF2("rdsv3_ib_qp_event_handler", "Return conn: %p event: %p",
471 471 conn, event);
472 472 }
473 473
474 474 extern int rdsv3_ib_alloc_hdrs(ib_device_t *dev,
475 475 struct rdsv3_ib_connection *ic);
476 476 extern void rdsv3_ib_free_hdrs(ib_device_t *dev,
477 477 struct rdsv3_ib_connection *ic);
478 478
479 479 /*
480 480 * This needs to be very careful to not leave IS_ERR pointers around for
481 481 * cleanup to trip over.
482 482 */
483 483 static int
484 484 rdsv3_ib_setup_qp(struct rdsv3_connection *conn)
485 485 {
486 486 struct rdsv3_ib_connection *ic = conn->c_transport_data;
487 487 struct ib_device *dev = ic->i_cm_id->device;
488 488 struct ib_qp_init_attr attr;
489 489 struct rdsv3_ib_device *rds_ibdev;
490 490 ibt_send_wr_t *wrp;
491 491 ibt_wr_ds_t *sgl;
492 492 int ret, i;
493 493
494 494 RDSV3_DPRINTF2("rdsv3_ib_setup_qp", "Enter conn: %p", conn);
495 495
496 496 /*
497 497 * rdsv3_ib_add_one creates a rdsv3_ib_device object per IB device,
498 498 * and allocates a protection domain, memory range and FMR pool
499 499 * for each. If that fails for any reason, it will not register
500 500 * the rds_ibdev at all.
501 501 */
502 502 rds_ibdev = ib_get_client_data(dev, &rdsv3_ib_client);
503 503 if (!rds_ibdev) {
504 504 RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
505 505 "RDS/IB: No client_data for device %s", dev->name);
506 506 return (-EOPNOTSUPP);
507 507 }
508 508 ic->rds_ibdev = rds_ibdev;
509 509
510 510 if (rds_ibdev->max_wrs < ic->i_send_ring.w_nr + 1)
511 511 rdsv3_ib_ring_resize(&ic->i_send_ring, rds_ibdev->max_wrs - 1);
512 512 if (rds_ibdev->max_wrs < ic->i_recv_ring.w_nr + 1)
513 513 rdsv3_ib_ring_resize(&ic->i_recv_ring, rds_ibdev->max_wrs - 1);
514 514
515 515 /* Protection domain and memory range */
516 516 ic->i_pd = rds_ibdev->pd;
517 517
518 518 /*
519 519 * IB_CQ_VECTOR_LEAST_ATTACHED and/or the corresponding feature is
520 520 * not implmeneted in Hermon yet, but we can pass it to ib_create_cq()
521 521 * anyway.
522 522 */
523 523 ic->i_cq = ib_create_cq(dev, rdsv3_ib_cq_comp_handler,
524 524 rdsv3_ib_cq_event_handler, conn,
525 525 ic->i_recv_ring.w_nr + ic->i_send_ring.w_nr + 1,
526 526 rdsv3_af_grp_get_sched(ic->rds_ibdev->aft_hcagp));
527 527 if (IS_ERR(ic->i_cq)) {
528 528 ret = PTR_ERR(ic->i_cq);
529 529 ic->i_cq = NULL;
530 530 RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
531 531 "ib_create_cq failed: %d", ret);
532 532 goto out;
533 533 }
534 534 if (rdsv3_enable_snd_cq) {
535 535 ic->i_snd_cq = ib_create_cq(dev, rdsv3_ib_snd_cq_comp_handler,
536 536 rdsv3_ib_cq_event_handler, conn, ic->i_send_ring.w_nr + 1,
537 537 rdsv3_af_grp_get_sched(ic->rds_ibdev->aft_hcagp));
538 538 if (IS_ERR(ic->i_snd_cq)) {
539 539 ret = PTR_ERR(ic->i_snd_cq);
540 540 (void) ib_destroy_cq(ic->i_cq);
541 541 ic->i_cq = NULL;
542 542 ic->i_snd_cq = NULL;
543 543 RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
544 544 "ib_create_cq send cq failed: %d", ret);
545 545 goto out;
546 546 }
547 547 }
548 548
549 549 /* XXX negotiate max send/recv with remote? */
550 550 (void) memset(&attr, 0, sizeof (attr));
551 551 attr.event_handler = rdsv3_ib_qp_event_handler;
552 552 attr.qp_context = conn;
553 553 /* + 1 to allow for the single ack message */
554 554 attr.cap.max_send_wr = ic->i_send_ring.w_nr + 1;
555 555 attr.cap.max_recv_wr = ic->i_recv_ring.w_nr + 1;
556 556 attr.cap.max_send_sge = rds_ibdev->max_sge;
557 557 attr.cap.max_recv_sge = RDSV3_IB_RECV_SGE;
558 558 attr.sq_sig_type = IB_SIGNAL_REQ_WR;
559 559 attr.qp_type = IB_QPT_RC;
560 560 if (rdsv3_enable_snd_cq) {
561 561 attr.send_cq = ic->i_snd_cq;
562 562 } else {
563 563 attr.send_cq = ic->i_cq;
564 564 }
565 565 attr.recv_cq = ic->i_cq;
566 566
567 567 /*
568 568 * XXX this can fail if max_*_wr is too large? Are we supposed
569 569 * to back off until we get a value that the hardware can support?
570 570 */
571 571 ret = rdma_create_qp(ic->i_cm_id, ic->i_pd, &attr);
572 572 if (ret) {
573 573 RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
574 574 "rdma_create_qp failed: %d", ret);
575 575 goto out;
576 576 }
577 577
578 578 ret = rdsv3_ib_alloc_hdrs(dev, ic);
579 579 if (ret != 0) {
580 580 ret = -ENOMEM;
581 581 RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
582 582 "rdsv3_ib_alloc_hdrs failed: %d", ret);
583 583 goto out;
584 584 }
585 585
586 586 ic->i_sends = kmem_alloc(ic->i_send_ring.w_nr *
587 587 sizeof (struct rdsv3_ib_send_work), KM_NOSLEEP);
588 588 if (ic->i_sends == NULL) {
589 589 ret = -ENOMEM;
590 590 RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
591 591 "send allocation failed: %d", ret);
592 592 goto out;
593 593 }
594 594 (void) memset(ic->i_sends, 0, ic->i_send_ring.w_nr *
595 595 sizeof (struct rdsv3_ib_send_work));
596 596
597 597 ic->i_send_wrs =
598 598 kmem_alloc(ic->i_send_ring.w_nr * (sizeof (ibt_send_wr_t) +
599 599 RDSV3_IB_MAX_SGE * sizeof (ibt_wr_ds_t)), KM_NOSLEEP);
600 600 if (ic->i_send_wrs == NULL) {
601 601 ret = -ENOMEM;
602 602 RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
603 603 "Send WR allocation failed: %d", ret);
604 604 goto out;
605 605 }
606 606 sgl = (ibt_wr_ds_t *)((uint8_t *)ic->i_send_wrs +
607 607 (ic->i_send_ring.w_nr * sizeof (ibt_send_wr_t)));
608 608 for (i = 0; i < ic->i_send_ring.w_nr; i++) {
609 609 wrp = &ic->i_send_wrs[i];
610 610 wrp->wr_sgl = &sgl[i * RDSV3_IB_MAX_SGE];
611 611 }
612 612
613 613 ic->i_recvs = kmem_alloc(ic->i_recv_ring.w_nr *
614 614 sizeof (struct rdsv3_ib_recv_work), KM_NOSLEEP);
615 615 if (ic->i_recvs == NULL) {
616 616 ret = -ENOMEM;
617 617 RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
618 618 "recv allocation failed: %d", ret);
619 619 goto out;
620 620 }
621 621 (void) memset(ic->i_recvs, 0, ic->i_recv_ring.w_nr *
622 622 sizeof (struct rdsv3_ib_recv_work));
623 623
624 624 ic->i_recv_wrs =
625 625 kmem_alloc(ic->i_recv_ring.w_nr * sizeof (ibt_recv_wr_t),
626 626 KM_NOSLEEP);
627 627 if (ic->i_recv_wrs == NULL) {
628 628 ret = -ENOMEM;
629 629 RDSV3_DPRINTF2("rdsv3_ib_setup_qp",
630 630 "Recv WR allocation failed: %d", ret);
631 631 goto out;
632 632 }
633 633
634 634 rdsv3_ib_recv_init_ack(ic);
635 635
636 636 RDSV3_DPRINTF2("rdsv3_ib_setup_qp", "conn %p pd %p mr %p cq %p",
637 637 conn, ic->i_pd, ic->i_mr, ic->i_cq);
638 638
639 639 out:
640 640 return (ret);
641 641 }
642 642
643 643 static uint32_t
644 644 rdsv3_ib_protocol_compatible(struct rdma_cm_event *event)
645 645 {
646 646 const struct rdsv3_ib_connect_private *dp =
647 647 event->param.conn.private_data;
648 648 uint16_t common;
649 649 uint32_t version = 0;
650 650
651 651 RDSV3_DPRINTF2("rdsv3_ib_protocol_compatible", "Enter event: %p",
652 652 event);
653 653
654 654 /*
655 655 * rdma_cm private data is odd - when there is any private data in the
656 656 * request, we will be given a pretty large buffer without telling us
657 657 * the
658 658 * original size. The only way to tell the difference is by looking at
659 659 * the contents, which are initialized to zero.
660 660 * If the protocol version fields aren't set,
661 661 * this is a connection attempt
662 662 * from an older version. This could could be 3.0 or 2.0 -
663 663 * we can't tell.
664 664 * We really should have changed this for OFED 1.3 :-(
665 665 */
666 666
667 667 /* Be paranoid. RDS always has privdata */
668 668 if (!event->param.conn.private_data_len) {
669 669 RDSV3_DPRINTF2("rdsv3_ib_protocol_compatible",
670 670 "RDS incoming connection has no private data, rejecting");
671 671 return (0);
672 672 }
673 673
674 674 /* Even if len is crap *now* I still want to check it. -ASG */
675 675 if (event->param.conn.private_data_len < sizeof (*dp) ||
676 676 dp->dp_protocol_major == 0)
677 677 return (RDS_PROTOCOL_3_0);
678 678
679 679 common = ntohs(dp->dp_protocol_minor_mask) &
680 680 RDSV3_IB_SUPPORTED_PROTOCOLS;
681 681 if (dp->dp_protocol_major == 3 && common) {
682 682 version = RDS_PROTOCOL_3_0;
683 683 while ((common >>= 1) != 0)
684 684 version++;
685 685 } else {
686 686 RDSV3_DPRINTF2("rdsv3_ib_protocol_compatible",
687 687 "RDS: Connection from %u.%u.%u.%u using "
688 688 "incompatible protocol version %u.%u\n",
689 689 NIPQUAD(dp->dp_saddr),
690 690 dp->dp_protocol_major,
691 691 dp->dp_protocol_minor);
692 692 }
693 693
694 694 RDSV3_DPRINTF2("rdsv3_ib_protocol_compatible", "Return event: %p",
695 695 event);
696 696
697 697 return (version);
698 698 }
699 699
700 700 int
701 701 rdsv3_ib_cm_handle_connect(struct rdma_cm_id *cm_id,
702 702 struct rdma_cm_event *event)
703 703 {
704 704 uint64_be_t lguid = cm_id->route.path_rec->sgid.global.interface_id;
705 705 uint64_be_t fguid = cm_id->route.path_rec->dgid.global.interface_id;
706 706 const struct rdsv3_ib_connect_private *dp =
707 707 event->param.conn.private_data;
708 708 struct rdsv3_ib_connect_private dp_rep;
709 709 struct rdsv3_connection *conn = NULL;
710 710 struct rdsv3_ib_connection *ic = NULL;
711 711 struct rdma_conn_param conn_param;
712 712 uint32_t version;
713 713 int err, destroy = 1;
714 714 boolean_t conn_created = B_FALSE;
715 715
716 716 RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
717 717 "Enter cm_id: %p event: %p", cm_id, event);
718 718
719 719 /* Check whether the remote protocol version matches ours. */
720 720 version = rdsv3_ib_protocol_compatible(event);
721 721 if (!version) {
722 722 RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
723 723 "version mismatch");
724 724 goto out;
725 725 }
726 726
727 727 RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
728 728 "saddr %u.%u.%u.%u daddr %u.%u.%u.%u RDSv%d.%d lguid 0x%llx fguid "
729 729 "0x%llx", NIPQUAD(dp->dp_saddr), NIPQUAD(dp->dp_daddr),
730 730 RDS_PROTOCOL_MAJOR(version), RDS_PROTOCOL_MINOR(version),
731 731 (unsigned long long)ntohll(lguid),
732 732 (unsigned long long)ntohll(fguid));
733 733
734 734 conn = rdsv3_conn_create(dp->dp_daddr, dp->dp_saddr,
735 735 &rdsv3_ib_transport, KM_NOSLEEP);
736 736 if (IS_ERR(conn)) {
737 737 RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
738 738 "rdsv3_conn_create failed (%ld)", PTR_ERR(conn));
739 739 conn = NULL;
740 740 goto out;
741 741 }
742 742
743 743 /*
744 744 * The connection request may occur while the
745 745 * previous connection exist, e.g. in case of failover.
746 746 * But as connections may be initiated simultaneously
747 747 * by both hosts, we have a random backoff mechanism -
748 748 * see the comment above rdsv3_queue_reconnect()
749 749 */
750 750 mutex_enter(&conn->c_cm_lock);
751 751 if (!rdsv3_conn_transition(conn, RDSV3_CONN_DOWN,
752 752 RDSV3_CONN_CONNECTING)) {
753 753 if (rdsv3_conn_state(conn) == RDSV3_CONN_UP) {
754 754 RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
755 755 "incoming connect when connected: %p",
756 756 conn);
757 757 rdsv3_conn_drop(conn);
758 758 rdsv3_ib_stats_inc(s_ib_listen_closed_stale);
759 759 mutex_exit(&conn->c_cm_lock);
760 760 goto out;
761 761 } else if (rdsv3_conn_state(conn) == RDSV3_CONN_CONNECTING) {
762 762 /* Wait and see - our connect may still be succeeding */
763 763 RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
764 764 "peer-to-peer connection request: %p, "
765 765 "lguid: 0x%llx fguid: 0x%llx",
766 766 conn, lguid, fguid);
767 767 rdsv3_ib_stats_inc(s_ib_connect_raced);
768 768 }
769 769 mutex_exit(&conn->c_cm_lock);
770 770 goto out;
771 771 }
772 772
773 773 ic = conn->c_transport_data;
774 774
775 775 rdsv3_ib_set_protocol(conn, version);
776 776 rdsv3_ib_set_flow_control(conn, ntohl(dp->dp_credit));
777 777
778 778 /*
779 779 * If the peer gave us the last packet it saw, process this as if
780 780 * we had received a regular ACK.
781 781 */
782 782 if (dp->dp_ack_seq)
783 783 rdsv3_send_drop_acked(conn, ntohll(dp->dp_ack_seq), NULL);
784 784
785 785 ASSERT(!cm_id->context);
786 786 ASSERT(!ic->i_cm_id);
787 787
788 788 if (ic->i_cm_id != NULL)
789 789 RDSV3_PANIC();
790 790
791 791 ic->i_cm_id = cm_id;
792 792 cm_id->context = conn;
793 793
794 794 /*
795 795 * We got halfway through setting up the ib_connection, if we
796 796 * fail now, we have to take the long route out of this mess.
797 797 */
798 798 destroy = 0;
799 799
800 800 err = rdsv3_ib_setup_qp(conn);
801 801 if (err) {
802 802 RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
803 803 "rdsv3_ib_setup_qp failed (%d)", err);
804 804 mutex_exit(&conn->c_cm_lock);
805 805 rdsv3_conn_drop(conn);
806 806 goto out;
807 807 }
808 808
809 809 rdsv3_ib_cm_fill_conn_param(conn, &conn_param, &dp_rep, version,
810 810 event->param.conn.responder_resources,
811 811 event->param.conn.initiator_depth);
812 812
813 813 /* rdma_accept() calls rdma_reject() internally if it fails */
814 814 err = rdma_accept(cm_id, &conn_param);
815 815 mutex_exit(&conn->c_cm_lock);
816 816 if (err) {
817 817 RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
818 818 "rdma_accept failed (%d)", err);
819 819 rdsv3_conn_drop(conn);
820 820 goto out;
821 821 }
822 822
823 823 RDSV3_DPRINTF2("rdsv3_ib_cm_handle_connect",
824 824 "Return cm_id: %p event: %p", cm_id, event);
825 825
826 826 return (0);
827 827
828 828 out:
829 829 (void) rdma_reject(cm_id, NULL, 0);
830 830 return (destroy);
831 831 }
832 832
833 833
834 834 int
835 835 rdsv3_ib_cm_initiate_connect(struct rdma_cm_id *cm_id)
836 836 {
837 837 struct rdsv3_connection *conn = cm_id->context;
838 838 struct rdsv3_ib_connection *ic = conn->c_transport_data;
839 839 struct rdma_conn_param conn_param;
840 840 struct rdsv3_ib_connect_private dp;
841 841 int ret;
842 842
843 843 RDSV3_DPRINTF2("rdsv3_ib_cm_initiate_connect", "Enter: cm_id: %p",
844 844 cm_id);
845 845
846 846 /*
847 847 * If the peer doesn't do protocol negotiation, we must
848 848 * default to RDSv3.0
849 849 */
850 850 rdsv3_ib_set_protocol(conn, RDS_PROTOCOL_3_0);
851 851 ic->i_flowctl =
852 852 rdsv3_ib_sysctl_flow_control; /* advertise flow control */
853 853
854 854 ret = rdsv3_ib_setup_qp(conn);
855 855 if (ret) {
856 856 RDSV3_DPRINTF2("rdsv3_ib_cm_initiate_connect",
857 857 "rdsv3_ib_setup_qp failed (%d)", ret);
858 858 rdsv3_conn_drop(conn);
859 859 goto out;
860 860 }
861 861
862 862 rdsv3_ib_cm_fill_conn_param(conn, &conn_param, &dp,
863 863 RDS_PROTOCOL_VERSION, UINT_MAX, UINT_MAX);
864 864
865 865 ret = rdma_connect(cm_id, &conn_param);
866 866 if (ret) {
867 867 RDSV3_DPRINTF2("rdsv3_ib_cm_initiate_connect",
868 868 "rdma_connect failed (%d)", ret);
869 869 rdsv3_conn_drop(conn);
870 870 }
871 871
872 872 RDSV3_DPRINTF2("rdsv3_ib_cm_initiate_connect",
873 873 "Return: cm_id: %p", cm_id);
874 874
875 875 out:
876 876 /*
877 877 * Beware - returning non-zero tells the rdma_cm to destroy
878 878 * the cm_id. We should certainly not do it as long as we still
879 879 * "own" the cm_id.
880 880 */
881 881 if (ret) {
882 882 if (ic->i_cm_id == cm_id)
883 883 ret = 0;
884 884 }
885 885 return (ret);
886 886 }
887 887
888 888 int
889 889 rdsv3_ib_conn_connect(struct rdsv3_connection *conn)
890 890 {
891 891 struct rdsv3_ib_connection *ic = conn->c_transport_data;
892 892 struct sockaddr_in src, dest;
893 893 ipaddr_t laddr, faddr;
894 894 int ret;
895 895
896 896 RDSV3_DPRINTF2("rdsv3_ib_conn_connect", "Enter: conn: %p", conn);
897 897
898 898 /*
899 899 * XXX I wonder what affect the port space has
900 900 */
901 901 /* delegate cm event handler to rdma_transport */
902 902 ic->i_cm_id = rdma_create_id(rdsv3_rdma_cm_event_handler, conn,
903 903 RDMA_PS_TCP);
904 904 if (IS_ERR(ic->i_cm_id)) {
905 905 ret = PTR_ERR(ic->i_cm_id);
906 906 ic->i_cm_id = NULL;
907 907 RDSV3_DPRINTF2("rdsv3_ib_conn_connect",
908 908 "rdma_create_id() failed: %d", ret);
909 909 goto out;
910 910 }
911 911
912 912 RDSV3_DPRINTF3("rdsv3_ib_conn_connect",
913 913 "created cm id %p for conn %p", ic->i_cm_id, conn);
914 914
915 915 /* The ipaddr should be in the network order */
916 916 laddr = conn->c_laddr;
917 917 faddr = conn->c_faddr;
918 918 ret = rdsv3_sc_path_lookup(&laddr, &faddr);
919 919 if (ret == 0) {
920 920 RDSV3_DPRINTF2(LABEL, "Path not found (0x%x 0x%x)",
921 921 ntohl(laddr), ntohl(faddr));
922 922 }
923 923
924 924 src.sin_family = AF_INET;
925 925 src.sin_addr.s_addr = (uint32_t)laddr;
926 926 src.sin_port = (uint16_t)htons(0);
927 927
928 928 dest.sin_family = AF_INET;
929 929 dest.sin_addr.s_addr = (uint32_t)faddr;
930 930 dest.sin_port = (uint16_t)htons(RDSV3_PORT);
931 931
932 932 ret = rdma_resolve_addr(ic->i_cm_id, (struct sockaddr *)&src,
933 933 (struct sockaddr *)&dest,
934 934 RDSV3_RDMA_RESOLVE_TIMEOUT_MS);
935 935 if (ret) {
936 936 RDSV3_DPRINTF2("rdsv3_ib_conn_connect",
937 937 "addr resolve failed for cm id %p: %d", ic->i_cm_id, ret);
938 938 rdma_destroy_id(ic->i_cm_id);
939 939 ic->i_cm_id = NULL;
940 940 }
941 941
942 942 RDSV3_DPRINTF2("rdsv3_ib_conn_connect", "Return: conn: %p", conn);
943 943
944 944 out:
945 945 return (ret);
946 946 }
947 947
948 948 /*
949 949 * This is so careful about only cleaning up resources that were built up
950 950 * so that it can be called at any point during startup. In fact it
951 951 * can be called multiple times for a given connection.
952 952 */
953 953 void
954 954 rdsv3_ib_conn_shutdown(struct rdsv3_connection *conn)
955 955 {
956 956 struct rdsv3_ib_connection *ic = conn->c_transport_data;
957 957 int err = 0;
958 958
959 959 RDSV3_DPRINTF2("rdsv3_ib_conn_shutdown",
960 960 "cm %p pd %p cq %p qp %p", ic->i_cm_id,
961 961 ic->i_pd, ic->i_cq, ic->i_cm_id ? ic->i_cm_id->qp : NULL);
962 962
963 963 if (ic->i_cm_id) {
964 964 struct ib_device *dev = ic->i_cm_id->device;
965 965
966 966 RDSV3_DPRINTF2("rdsv3_ib_conn_shutdown",
967 967 "disconnecting cm %p", ic->i_cm_id);
968 968 err = rdma_disconnect(ic->i_cm_id);
969 969 if (err) {
970 970 /*
971 971 * Actually this may happen quite frequently, when
972 972 * an outgoing connect raced with an incoming connect.
973 973 */
974 974 RDSV3_DPRINTF2("rdsv3_ib_conn_shutdown",
975 975 "failed to disconnect, cm: %p err %d",
976 976 ic->i_cm_id, err);
977 977 }
978 978
979 979 if (ic->i_cm_id->qp) {
980 980 (void) ibt_flush_qp(
981 981 ib_get_ibt_channel_hdl(ic->i_cm_id));
982 982 /*
983 983 * Don't wait for the send ring to be empty -- there
984 984 * may be completed non-signaled entries sitting on
985 985 * there. We unmap these below.
986 986 */
987 987 rdsv3_wait_event(&ic->i_recv_ring.w_empty_wait,
988 988 rdsv3_ib_ring_empty(&ic->i_recv_ring));
989 989 /*
990 990 * Note that Linux original code calls
991 991 * rdma_destroy_qp() after rdsv3_ib_recv_clear_ring(ic).
992 992 */
993 993 rdma_destroy_qp(ic->i_cm_id);
994 994 }
995 995
996 996 if (rdsv3_enable_snd_cq) {
997 997 if (ic->i_snd_soft_cq) {
998 998 rdsv3_af_thr_destroy(ic->i_snd_soft_cq);
999 999 ic->i_snd_soft_cq = NULL;
1000 1000 }
1001 1001 if (ic->i_snd_cq)
1002 1002 (void) ib_destroy_cq(ic->i_snd_cq);
1003 1003 }
1004 1004 if (ic->i_soft_cq) {
1005 1005 rdsv3_af_thr_destroy(ic->i_soft_cq);
1006 1006 ic->i_soft_cq = NULL;
1007 1007 }
1008 1008 if (ic->i_refill_rq) {
1009 1009 rdsv3_af_thr_destroy(ic->i_refill_rq);
1010 1010 ic->i_refill_rq = NULL;
1011 1011 }
1012 1012 if (ic->i_cq)
1013 1013 (void) ib_destroy_cq(ic->i_cq);
1014 1014
1015 1015 if (ic->i_mr)
1016 1016 rdsv3_ib_free_hdrs(dev, ic);
1017 1017
1018 1018 if (ic->i_sends)
1019 1019 rdsv3_ib_send_clear_ring(ic);
1020 1020 if (ic->i_recvs)
1021 1021 rdsv3_ib_recv_clear_ring(ic);
1022 1022
1023 1023 rdma_destroy_id(ic->i_cm_id);
1024 1024
1025 1025 /*
1026 1026 * Move connection back to the nodev list.
1027 1027 */
1028 1028 if (ic->i_on_dev_list)
1029 1029 rdsv3_ib_remove_conn(ic->rds_ibdev, conn);
1030 1030
1031 1031 ic->i_cm_id = NULL;
1032 1032 ic->i_pd = NULL;
1033 1033 ic->i_mr = NULL;
1034 1034 ic->i_cq = NULL;
1035 1035 ic->i_snd_cq = NULL;
1036 1036 ic->i_send_hdrs = NULL;
1037 1037 ic->i_recv_hdrs = NULL;
1038 1038 ic->i_ack = NULL;
1039 1039 }
1040 1040 ASSERT(!ic->i_on_dev_list);
1041 1041
1042 1042 /* Clear pending transmit */
1043 1043 if (ic->i_rm) {
1044 1044 rdsv3_message_put(ic->i_rm);
1045 1045 ic->i_rm = NULL;
1046 1046 }
1047 1047
1048 1048 /* Clear the ACK state */
1049 1049 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
1050 1050 ic->i_ack_next = 0;
1051 1051 ic->i_ack_recv = 0;
1052 1052
1053 1053 /* Clear flow control state */
1054 1054 ic->i_flowctl = 0;
1055 1055 ic->i_credits = 0;
1056 1056
1057 1057 rdsv3_ib_ring_init(&ic->i_send_ring, rdsv3_ib_sysctl_max_send_wr);
1058 1058 rdsv3_ib_ring_init(&ic->i_recv_ring, rdsv3_ib_sysctl_max_recv_wr);
1059 1059
1060 1060 if (ic->i_ibinc) {
1061 1061 rdsv3_inc_put(&ic->i_ibinc->ii_inc);
1062 1062 ic->i_ibinc = NULL;
1063 1063 }
1064 1064
1065 1065 if (ic->i_sends) {
1066 1066 kmem_free(ic->i_sends,
1067 1067 ic->i_send_ring.w_nr * sizeof (struct rdsv3_ib_send_work));
1068 1068 ic->i_sends = NULL;
1069 1069 }
1070 1070 if (ic->i_send_wrs) {
1071 1071 kmem_free(ic->i_send_wrs, ic->i_send_ring.w_nr *
1072 1072 (sizeof (ibt_send_wr_t) +
1073 1073 RDSV3_IB_MAX_SGE * sizeof (ibt_wr_ds_t)));
1074 1074 ic->i_send_wrs = NULL;
1075 1075 }
1076 1076 if (ic->i_recvs) {
1077 1077 kmem_free(ic->i_recvs,
1078 1078 ic->i_recv_ring.w_nr * sizeof (struct rdsv3_ib_recv_work));
1079 1079 ic->i_recvs = NULL;
1080 1080 }
1081 1081 if (ic->i_recv_wrs) {
1082 1082 kmem_free(ic->i_recv_wrs, ic->i_recv_ring.w_nr *
1083 1083 (sizeof (ibt_recv_wr_t)));
1084 1084 ic->i_recv_wrs = NULL;
1085 1085 }
1086 1086
1087 1087 RDSV3_DPRINTF2("rdsv3_ib_conn_shutdown", "Return conn: %p", conn);
1088 1088 }
1089 1089
1090 1090 /* ARGSUSED */
1091 1091 int
1092 1092 rdsv3_ib_conn_alloc(struct rdsv3_connection *conn, int gfp)
1093 1093 {
1094 1094 struct rdsv3_ib_connection *ic;
1095 1095
1096 1096 RDSV3_DPRINTF2("rdsv3_ib_conn_alloc", "conn: %p", conn);
1097 1097
1098 1098 /* XXX too lazy? */
1099 1099 ic = kmem_zalloc(sizeof (struct rdsv3_ib_connection), gfp);
1100 1100 if (!ic)
1101 1101 return (-ENOMEM);
1102 1102
1103 1103 list_link_init(&ic->ib_node);
1104 1104
1105 1105 mutex_init(&ic->i_recv_mutex, NULL, MUTEX_DRIVER, NULL);
1106 1106 mutex_init(&ic->i_ack_lock, NULL, MUTEX_DRIVER, NULL);
1107 1107
1108 1108 /*
1109 1109 * rdsv3_ib_conn_shutdown() waits for these to be emptied so they
1110 1110 * must be initialized before it can be called.
1111 1111 */
1112 1112 rdsv3_ib_ring_init(&ic->i_send_ring, rdsv3_ib_sysctl_max_send_wr);
1113 1113 rdsv3_ib_ring_init(&ic->i_recv_ring, rdsv3_ib_sysctl_max_recv_wr);
1114 1114
1115 1115 ic->conn = conn;
1116 1116 conn->c_transport_data = ic;
1117 1117
1118 1118 mutex_enter(&ib_nodev_conns_lock);
1119 1119 list_insert_tail(&ib_nodev_conns, ic);
1120 1120 mutex_exit(&ib_nodev_conns_lock);
1121 1121
1122 1122 RDSV3_DPRINTF2("rdsv3_ib_conn_alloc", "conn %p conn ic %p",
1123 1123 conn, conn->c_transport_data);
1124 1124 return (0);
1125 1125 }
1126 1126
1127 1127 /*
↓ open down ↓ |
1127 lines elided |
↑ open up ↑ |
1128 1128 * Free a connection. Connection must be shut down and not set for reconnect.
1129 1129 */
1130 1130 void
1131 1131 rdsv3_ib_conn_free(void *arg)
1132 1132 {
1133 1133 struct rdsv3_ib_connection *ic = arg;
1134 1134 kmutex_t *lock_ptr;
1135 1135
1136 1136 RDSV3_DPRINTF2("rdsv3_ib_conn_free", "ic %p\n", ic);
1137 1137
1138 -#ifndef __lock_lint
1139 1138 /*
1140 1139 * Conn is either on a dev's list or on the nodev list.
1141 1140 * A race with shutdown() or connect() would cause problems
1142 1141 * (since rds_ibdev would change) but that should never happen.
1143 1142 */
1144 1143 lock_ptr = ic->i_on_dev_list ?
1145 1144 &ic->rds_ibdev->spinlock : &ib_nodev_conns_lock;
1146 1145
1147 1146 mutex_enter(lock_ptr);
1148 1147 list_remove_node(&ic->ib_node);
1149 1148 mutex_exit(lock_ptr);
1150 -#endif
1151 1149 kmem_free(ic, sizeof (*ic));
1152 1150 }
1153 1151
1154 1152 /*
1155 1153 * An error occurred on the connection
1156 1154 */
1157 1155 void
1158 1156 __rdsv3_ib_conn_error(struct rdsv3_connection *conn)
1159 1157 {
1160 1158 rdsv3_conn_drop(conn);
1161 1159 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX