4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/klnds/o2iblnd/o2iblnd_cb.c
38 * Author: Eric Barton <eric@bartonsoftware.com>
43 static void kiblnd_peer_alive(kib_peer_t *peer);
44 static void kiblnd_peer_connect_failed(kib_peer_t *peer, int active, int error);
45 static void kiblnd_check_sends(kib_conn_t *conn);
46 static void kiblnd_init_tx_msg(lnet_ni_t *ni, kib_tx_t *tx,
47 int type, int body_nob);
48 static int kiblnd_init_rdma(kib_conn_t *conn, kib_tx_t *tx, int type,
49 int resid, kib_rdma_desc_t *dstrd, __u64 dstcookie);
50 static void kiblnd_queue_tx_locked(kib_tx_t *tx, kib_conn_t *conn);
51 static void kiblnd_queue_tx(kib_tx_t *tx, kib_conn_t *conn);
52 static void kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx);
55 kiblnd_tx_done (lnet_ni_t *ni, kib_tx_t *tx)
57 lnet_msg_t *lntmsg[2];
58 kib_net_t *net = ni->ni_data;
62 LASSERT (net != NULL);
63 LASSERT (!in_interrupt());
64 LASSERT (!tx->tx_queued); /* mustn't be queued for sending */
65 LASSERT (tx->tx_sending == 0); /* mustn't be awaiting sent callback */
66 LASSERT (!tx->tx_waiting); /* mustn't be awaiting peer response */
67 LASSERT (tx->tx_pool != NULL);
69 kiblnd_unmap_tx(ni, tx);
71 /* tx may have up to 2 lnet msgs to finalise */
72 lntmsg[0] = tx->tx_lntmsg[0]; tx->tx_lntmsg[0] = NULL;
73 lntmsg[1] = tx->tx_lntmsg[1]; tx->tx_lntmsg[1] = NULL;
76 if (tx->tx_conn != NULL) {
77 LASSERT (ni == tx->tx_conn->ibc_peer->ibp_ni);
79 kiblnd_conn_decref(tx->tx_conn);
86 kiblnd_pool_free_node(&tx->tx_pool->tpo_pool, &tx->tx_list);
88 /* delay finalize until my descs have been freed */
89 for (i = 0; i < 2; i++) {
90 if (lntmsg[i] == NULL)
93 lnet_finalize(ni, lntmsg[i], rc);
98 kiblnd_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int status)
102 while (!list_empty(txlist)) {
103 tx = list_entry(txlist->next, kib_tx_t, tx_list);
105 list_del(&tx->tx_list);
108 tx->tx_status = status;
109 kiblnd_tx_done(ni, tx);
114 kiblnd_get_idle_tx(lnet_ni_t *ni, lnet_nid_t target)
116 kib_net_t *net = (kib_net_t *)ni->ni_data;
117 struct list_head *node;
119 kib_tx_poolset_t *tps;
121 tps = net->ibn_tx_ps[lnet_cpt_of_nid(target)];
122 node = kiblnd_pool_alloc_node(&tps->tps_poolset);
125 tx = container_of(node, kib_tx_t, tx_list);
127 LASSERT (tx->tx_nwrq == 0);
128 LASSERT (!tx->tx_queued);
129 LASSERT (tx->tx_sending == 0);
130 LASSERT (!tx->tx_waiting);
131 LASSERT (tx->tx_status == 0);
132 LASSERT (tx->tx_conn == NULL);
133 LASSERT (tx->tx_lntmsg[0] == NULL);
134 LASSERT (tx->tx_lntmsg[1] == NULL);
135 LASSERT (tx->tx_nfrags == 0);
141 kiblnd_drop_rx(kib_rx_t *rx)
143 kib_conn_t *conn = rx->rx_conn;
144 struct kib_sched_info *sched = conn->ibc_sched;
147 spin_lock_irqsave(&sched->ibs_lock, flags);
148 LASSERT(conn->ibc_nrx > 0);
150 spin_unlock_irqrestore(&sched->ibs_lock, flags);
152 kiblnd_conn_decref(conn);
156 kiblnd_post_rx (kib_rx_t *rx, int credit)
158 kib_conn_t *conn = rx->rx_conn;
159 kib_net_t *net = conn->ibc_peer->ibp_ni->ni_data;
160 struct ib_recv_wr *bad_wrq = NULL;
161 struct ib_mr *mr = conn->ibc_hdev->ibh_mrs;
164 LASSERT (net != NULL);
165 LASSERT (!in_interrupt());
166 LASSERT (credit == IBLND_POSTRX_NO_CREDIT ||
167 credit == IBLND_POSTRX_PEER_CREDIT ||
168 credit == IBLND_POSTRX_RSRVD_CREDIT);
171 rx->rx_sge.lkey = mr->lkey;
172 rx->rx_sge.addr = rx->rx_msgaddr;
173 rx->rx_sge.length = IBLND_MSG_SIZE;
175 rx->rx_wrq.next = NULL;
176 rx->rx_wrq.sg_list = &rx->rx_sge;
177 rx->rx_wrq.num_sge = 1;
178 rx->rx_wrq.wr_id = kiblnd_ptr2wreqid(rx, IBLND_WID_RX);
180 LASSERT (conn->ibc_state >= IBLND_CONN_INIT);
181 LASSERT (rx->rx_nob >= 0); /* not posted */
183 if (conn->ibc_state > IBLND_CONN_ESTABLISHED) {
184 kiblnd_drop_rx(rx); /* No more posts for this rx */
188 rx->rx_nob = -1; /* flag posted */
190 /* NB: need an extra reference after ib_post_recv because we don't
191 * own this rx (and rx::rx_conn) anymore, LU-5678.
193 kiblnd_conn_addref(conn);
194 rc = ib_post_recv(conn->ibc_cmid->qp, &rx->rx_wrq, &bad_wrq);
195 if (unlikely(rc != 0)) {
196 CERROR("Can't post rx for %s: %d, bad_wrq: %p\n",
197 libcfs_nid2str(conn->ibc_peer->ibp_nid), rc, bad_wrq);
201 if (conn->ibc_state < IBLND_CONN_ESTABLISHED) /* Initial post */
204 if (unlikely(rc != 0)) {
205 kiblnd_close_conn(conn, rc);
206 kiblnd_drop_rx(rx); /* No more posts for this rx */
210 if (credit == IBLND_POSTRX_NO_CREDIT)
213 spin_lock(&conn->ibc_lock);
214 if (credit == IBLND_POSTRX_PEER_CREDIT)
215 conn->ibc_outstanding_credits++;
217 conn->ibc_reserved_credits++;
218 spin_unlock(&conn->ibc_lock);
220 kiblnd_check_sends(conn);
222 kiblnd_conn_decref(conn);
227 kiblnd_find_waiting_tx_locked(kib_conn_t *conn, int txtype, __u64 cookie)
229 struct list_head *tmp;
231 list_for_each(tmp, &conn->ibc_active_txs) {
232 kib_tx_t *tx = list_entry(tmp, kib_tx_t, tx_list);
234 LASSERT(!tx->tx_queued);
235 LASSERT(tx->tx_sending != 0 || tx->tx_waiting);
237 if (tx->tx_cookie != cookie)
240 if (tx->tx_waiting &&
241 tx->tx_msg->ibm_type == txtype)
244 CWARN("Bad completion: %swaiting, type %x (wanted %x)\n",
245 tx->tx_waiting ? "" : "NOT ",
246 tx->tx_msg->ibm_type, txtype);
252 kiblnd_handle_completion(kib_conn_t *conn, int txtype, int status, __u64 cookie)
255 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
258 spin_lock(&conn->ibc_lock);
260 tx = kiblnd_find_waiting_tx_locked(conn, txtype, cookie);
262 spin_unlock(&conn->ibc_lock);
264 CWARN("Unmatched completion type %x cookie "LPX64" from %s\n",
265 txtype, cookie, libcfs_nid2str(conn->ibc_peer->ibp_nid));
266 kiblnd_close_conn(conn, -EPROTO);
270 if (tx->tx_status == 0) { /* success so far */
271 if (status < 0) { /* failed? */
272 tx->tx_status = status;
273 } else if (txtype == IBLND_MSG_GET_REQ) {
274 lnet_set_reply_msg_len(ni, tx->tx_lntmsg[1], status);
280 idle = !tx->tx_queued && (tx->tx_sending == 0);
282 list_del(&tx->tx_list);
284 spin_unlock(&conn->ibc_lock);
287 kiblnd_tx_done(ni, tx);
291 kiblnd_send_completion(kib_conn_t *conn, int type, int status, __u64 cookie)
293 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
294 kib_tx_t *tx = kiblnd_get_idle_tx(ni, conn->ibc_peer->ibp_nid);
297 CERROR("Can't get tx for completion %x for %s\n",
298 type, libcfs_nid2str(conn->ibc_peer->ibp_nid));
302 tx->tx_msg->ibm_u.completion.ibcm_status = status;
303 tx->tx_msg->ibm_u.completion.ibcm_cookie = cookie;
304 kiblnd_init_tx_msg(ni, tx, type, sizeof(kib_completion_msg_t));
306 kiblnd_queue_tx(tx, conn);
310 kiblnd_handle_rx (kib_rx_t *rx)
312 kib_msg_t *msg = rx->rx_msg;
313 kib_conn_t *conn = rx->rx_conn;
314 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
315 int credits = msg->ibm_credits;
321 LASSERT (conn->ibc_state >= IBLND_CONN_ESTABLISHED);
323 CDEBUG (D_NET, "Received %x[%d] from %s\n",
324 msg->ibm_type, credits,
325 libcfs_nid2str(conn->ibc_peer->ibp_nid));
328 /* Have I received credits that will let me send? */
329 spin_lock(&conn->ibc_lock);
331 if (conn->ibc_credits + credits >
332 conn->ibc_queue_depth) {
333 rc2 = conn->ibc_credits;
334 spin_unlock(&conn->ibc_lock);
336 CERROR("Bad credits from %s: %d + %d > %d\n",
337 libcfs_nid2str(conn->ibc_peer->ibp_nid),
339 conn->ibc_queue_depth);
341 kiblnd_close_conn(conn, -EPROTO);
342 kiblnd_post_rx(rx, IBLND_POSTRX_NO_CREDIT);
346 conn->ibc_credits += credits;
348 /* This ensures the credit taken by NOOP can be returned */
349 if (msg->ibm_type == IBLND_MSG_NOOP &&
350 !IBLND_OOB_CAPABLE(conn->ibc_version)) /* v1 only */
351 conn->ibc_outstanding_credits++;
353 spin_unlock(&conn->ibc_lock);
354 kiblnd_check_sends(conn);
357 switch (msg->ibm_type) {
359 CERROR("Bad IBLND message type %x from %s\n",
360 msg->ibm_type, libcfs_nid2str(conn->ibc_peer->ibp_nid));
361 post_credit = IBLND_POSTRX_NO_CREDIT;
366 if (IBLND_OOB_CAPABLE(conn->ibc_version)) {
367 post_credit = IBLND_POSTRX_NO_CREDIT;
371 if (credits != 0) /* credit already posted */
372 post_credit = IBLND_POSTRX_NO_CREDIT;
373 else /* a keepalive NOOP */
374 post_credit = IBLND_POSTRX_PEER_CREDIT;
377 case IBLND_MSG_IMMEDIATE:
378 post_credit = IBLND_POSTRX_DONT_POST;
379 rc = lnet_parse(ni, &msg->ibm_u.immediate.ibim_hdr,
380 msg->ibm_srcnid, rx, 0);
381 if (rc < 0) /* repost on error */
382 post_credit = IBLND_POSTRX_PEER_CREDIT;
385 case IBLND_MSG_PUT_REQ:
386 post_credit = IBLND_POSTRX_DONT_POST;
387 rc = lnet_parse(ni, &msg->ibm_u.putreq.ibprm_hdr,
388 msg->ibm_srcnid, rx, 1);
389 if (rc < 0) /* repost on error */
390 post_credit = IBLND_POSTRX_PEER_CREDIT;
393 case IBLND_MSG_PUT_NAK:
394 CWARN ("PUT_NACK from %s\n",
395 libcfs_nid2str(conn->ibc_peer->ibp_nid));
396 post_credit = IBLND_POSTRX_RSRVD_CREDIT;
397 kiblnd_handle_completion(conn, IBLND_MSG_PUT_REQ,
398 msg->ibm_u.completion.ibcm_status,
399 msg->ibm_u.completion.ibcm_cookie);
402 case IBLND_MSG_PUT_ACK:
403 post_credit = IBLND_POSTRX_RSRVD_CREDIT;
405 spin_lock(&conn->ibc_lock);
406 tx = kiblnd_find_waiting_tx_locked(conn, IBLND_MSG_PUT_REQ,
407 msg->ibm_u.putack.ibpam_src_cookie);
409 list_del(&tx->tx_list);
410 spin_unlock(&conn->ibc_lock);
413 CERROR("Unmatched PUT_ACK from %s\n",
414 libcfs_nid2str(conn->ibc_peer->ibp_nid));
419 LASSERT (tx->tx_waiting);
420 /* CAVEAT EMPTOR: I could be racing with tx_complete, but...
421 * (a) I can overwrite tx_msg since my peer has received it!
422 * (b) tx_waiting set tells tx_complete() it's not done. */
424 tx->tx_nwrq = 0; /* overwrite PUT_REQ */
426 rc2 = kiblnd_init_rdma(conn, tx, IBLND_MSG_PUT_DONE,
427 kiblnd_rd_size(&msg->ibm_u.putack.ibpam_rd),
428 &msg->ibm_u.putack.ibpam_rd,
429 msg->ibm_u.putack.ibpam_dst_cookie);
431 CERROR("Can't setup rdma for PUT to %s: %d\n",
432 libcfs_nid2str(conn->ibc_peer->ibp_nid), rc2);
434 spin_lock(&conn->ibc_lock);
435 tx->tx_waiting = 0; /* clear waiting and queue atomically */
436 kiblnd_queue_tx_locked(tx, conn);
437 spin_unlock(&conn->ibc_lock);
440 case IBLND_MSG_PUT_DONE:
441 post_credit = IBLND_POSTRX_PEER_CREDIT;
442 kiblnd_handle_completion(conn, IBLND_MSG_PUT_ACK,
443 msg->ibm_u.completion.ibcm_status,
444 msg->ibm_u.completion.ibcm_cookie);
447 case IBLND_MSG_GET_REQ:
448 post_credit = IBLND_POSTRX_DONT_POST;
449 rc = lnet_parse(ni, &msg->ibm_u.get.ibgm_hdr,
450 msg->ibm_srcnid, rx, 1);
451 if (rc < 0) /* repost on error */
452 post_credit = IBLND_POSTRX_PEER_CREDIT;
455 case IBLND_MSG_GET_DONE:
456 post_credit = IBLND_POSTRX_RSRVD_CREDIT;
457 kiblnd_handle_completion(conn, IBLND_MSG_GET_REQ,
458 msg->ibm_u.completion.ibcm_status,
459 msg->ibm_u.completion.ibcm_cookie);
463 if (rc < 0) /* protocol error */
464 kiblnd_close_conn(conn, rc);
466 if (post_credit != IBLND_POSTRX_DONT_POST)
467 kiblnd_post_rx(rx, post_credit);
471 kiblnd_rx_complete (kib_rx_t *rx, int status, int nob)
473 kib_msg_t *msg = rx->rx_msg;
474 kib_conn_t *conn = rx->rx_conn;
475 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
476 kib_net_t *net = ni->ni_data;
480 LASSERT (net != NULL);
481 LASSERT (rx->rx_nob < 0); /* was posted */
482 rx->rx_nob = 0; /* isn't now */
484 if (conn->ibc_state > IBLND_CONN_ESTABLISHED)
487 if (status != IB_WC_SUCCESS) {
488 CNETERR("Rx from %s failed: %d\n",
489 libcfs_nid2str(conn->ibc_peer->ibp_nid), status);
496 rc = kiblnd_unpack_msg(msg, rx->rx_nob);
498 CERROR ("Error %d unpacking rx from %s\n",
499 rc, libcfs_nid2str(conn->ibc_peer->ibp_nid));
503 if (msg->ibm_srcnid != conn->ibc_peer->ibp_nid ||
504 msg->ibm_dstnid != ni->ni_nid ||
505 msg->ibm_srcstamp != conn->ibc_incarnation ||
506 msg->ibm_dststamp != net->ibn_incarnation) {
507 CERROR ("Stale rx from %s\n",
508 libcfs_nid2str(conn->ibc_peer->ibp_nid));
513 /* set time last known alive */
514 kiblnd_peer_alive(conn->ibc_peer);
516 /* racing with connection establishment/teardown! */
518 if (conn->ibc_state < IBLND_CONN_ESTABLISHED) {
519 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
522 write_lock_irqsave(g_lock, flags);
523 /* must check holding global lock to eliminate race */
524 if (conn->ibc_state < IBLND_CONN_ESTABLISHED) {
525 list_add_tail(&rx->rx_list, &conn->ibc_early_rxs);
526 write_unlock_irqrestore(g_lock, flags);
529 write_unlock_irqrestore(g_lock, flags);
531 kiblnd_handle_rx(rx);
535 CDEBUG(D_NET, "rx %p conn %p\n", rx, conn);
536 kiblnd_close_conn(conn, err);
538 kiblnd_drop_rx(rx); /* Don't re-post rx. */
542 kiblnd_kvaddr_to_page (unsigned long vaddr)
546 if (is_vmalloc_addr((void *)vaddr)) {
547 page = vmalloc_to_page ((void *)vaddr);
548 LASSERT (page != NULL);
551 #ifdef CONFIG_HIGHMEM
552 if (vaddr >= PKMAP_BASE &&
553 vaddr < (PKMAP_BASE + LAST_PKMAP * PAGE_SIZE)) {
554 /* No highmem pages only used for bulk (kiov) I/O */
555 CERROR("find page for address in highmem\n");
559 page = virt_to_page (vaddr);
560 LASSERT (page != NULL);
565 kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob)
568 __u64 *pages = tx->tx_pages;
569 kib_fmr_poolset_t *fps;
576 LASSERT(tx->tx_pool != NULL);
577 LASSERT(tx->tx_pool->tpo_pool.po_owner != NULL);
579 hdev = tx->tx_pool->tpo_hdev;
581 for (i = 0, npages = 0; i < rd->rd_nfrags; i++) {
582 for (size = 0; size < rd->rd_frags[i].rf_nob;
583 size += hdev->ibh_page_size) {
584 pages[npages ++] = (rd->rd_frags[i].rf_addr &
585 hdev->ibh_page_mask) + size;
589 cpt = tx->tx_pool->tpo_pool.po_owner->ps_cpt;
591 fps = net->ibn_fmr_ps[cpt];
592 rc = kiblnd_fmr_pool_map(fps, pages, npages, 0, &tx->fmr);
594 CERROR ("Can't map %d pages: %d\n", npages, rc);
598 /* If rd is not tx_rd, it's going to get sent to a peer, who will need
600 rd->rd_key = (rd != tx->tx_rd) ? tx->fmr.fmr_pfmr->fmr->rkey :
601 tx->fmr.fmr_pfmr->fmr->lkey;
602 rd->rd_frags[0].rf_addr &= ~hdev->ibh_page_mask;
603 rd->rd_frags[0].rf_nob = nob;
610 kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx)
612 kib_net_t *net = ni->ni_data;
614 LASSERT(net != NULL);
616 if (net->ibn_fmr_ps != NULL && tx->fmr.fmr_pfmr != NULL) {
617 kiblnd_fmr_pool_unmap(&tx->fmr, tx->tx_status);
618 tx->fmr.fmr_pfmr = NULL;
621 if (tx->tx_nfrags != 0) {
622 kiblnd_dma_unmap_sg(tx->tx_pool->tpo_hdev->ibh_ibdev,
623 tx->tx_frags, tx->tx_nfrags, tx->tx_dmadir);
629 kiblnd_map_tx(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd, int nfrags)
631 kib_hca_dev_t *hdev = tx->tx_pool->tpo_hdev;
632 kib_net_t *net = ni->ni_data;
633 struct ib_mr *mr = NULL;
637 /* If rd is not tx_rd, it's going to get sent to a peer and I'm the
639 tx->tx_dmadir = (rd != tx->tx_rd) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
640 tx->tx_nfrags = nfrags;
642 rd->rd_nfrags = kiblnd_dma_map_sg(hdev->ibh_ibdev, tx->tx_frags,
643 tx->tx_nfrags, tx->tx_dmadir);
645 for (i = 0, nob = 0; i < rd->rd_nfrags; i++) {
646 rd->rd_frags[i].rf_nob = kiblnd_sg_dma_len(
647 hdev->ibh_ibdev, &tx->tx_frags[i]);
648 rd->rd_frags[i].rf_addr = kiblnd_sg_dma_address(
649 hdev->ibh_ibdev, &tx->tx_frags[i]);
650 nob += rd->rd_frags[i].rf_nob;
653 mr = kiblnd_find_rd_dma_mr(hdev, rd,
654 (tx->tx_conn != NULL) ?
655 tx->tx_conn->ibc_max_frags : -1);
657 /* found pre-mapping MR */
658 rd->rd_key = (rd != tx->tx_rd) ? mr->rkey : mr->lkey;
662 if (net->ibn_fmr_ps != NULL)
663 return kiblnd_fmr_map_tx(net, tx, rd, nob);
670 kiblnd_setup_rd_iov(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd,
671 unsigned int niov, struct kvec *iov, int offset, int nob)
673 kib_net_t *net = ni->ni_data;
675 struct scatterlist *sg;
682 LASSERT (net != NULL);
684 while (offset >= iov->iov_len) {
685 offset -= iov->iov_len;
695 vaddr = ((unsigned long)iov->iov_base) + offset;
696 page_offset = vaddr & (PAGE_SIZE - 1);
697 page = kiblnd_kvaddr_to_page(vaddr);
699 CERROR ("Can't find page\n");
703 fragnob = min((int)(iov->iov_len - offset), nob);
704 fragnob = min(fragnob, (int)PAGE_SIZE - page_offset);
706 sg_set_page(sg, page, fragnob, page_offset);
709 if (offset + fragnob < iov->iov_len) {
719 return kiblnd_map_tx(ni, tx, rd, sg - tx->tx_frags);
723 kiblnd_setup_rd_kiov (lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd,
724 int nkiov, lnet_kiov_t *kiov, int offset, int nob)
726 kib_net_t *net = ni->ni_data;
727 struct scatterlist *sg;
730 CDEBUG(D_NET, "niov %d offset %d nob %d\n", nkiov, offset, nob);
734 LASSERT (net != NULL);
736 while (offset >= kiov->kiov_len) {
737 offset -= kiov->kiov_len;
747 fragnob = min((int)(kiov->kiov_len - offset), nob);
749 sg_set_page(sg, kiov->kiov_page, fragnob,
750 kiov->kiov_offset + offset);
759 return kiblnd_map_tx(ni, tx, rd, sg - tx->tx_frags);
763 kiblnd_post_tx_locked (kib_conn_t *conn, kib_tx_t *tx, int credit)
764 __must_hold(&conn->ibc_lock)
766 kib_msg_t *msg = tx->tx_msg;
767 kib_peer_t *peer = conn->ibc_peer;
768 int ver = conn->ibc_version;
772 LASSERT(tx->tx_queued);
773 /* We rely on this for QP sizing */
774 LASSERT(tx->tx_nwrq > 0);
775 LASSERT(tx->tx_nwrq <= 1 + conn->ibc_max_frags);
777 LASSERT(credit == 0 || credit == 1);
778 LASSERT(conn->ibc_outstanding_credits >= 0);
779 LASSERT(conn->ibc_outstanding_credits <= conn->ibc_queue_depth);
780 LASSERT(conn->ibc_credits >= 0);
781 LASSERT(conn->ibc_credits <= conn->ibc_queue_depth);
783 if (conn->ibc_nsends_posted == IBLND_CONCURRENT_SENDS(ver)) {
784 /* tx completions outstanding... */
785 CDEBUG(D_NET, "%s: posted enough\n",
786 libcfs_nid2str(peer->ibp_nid));
790 if (credit != 0 && conn->ibc_credits == 0) { /* no credits */
791 CDEBUG(D_NET, "%s: no credits\n",
792 libcfs_nid2str(peer->ibp_nid));
796 if (credit != 0 && !IBLND_OOB_CAPABLE(ver) &&
797 conn->ibc_credits == 1 && /* last credit reserved */
798 msg->ibm_type != IBLND_MSG_NOOP) { /* for NOOP */
799 CDEBUG(D_NET, "%s: not using last credit\n",
800 libcfs_nid2str(peer->ibp_nid));
804 /* NB don't drop ibc_lock before bumping tx_sending */
805 list_del(&tx->tx_list);
808 if (msg->ibm_type == IBLND_MSG_NOOP &&
809 (!kiblnd_need_noop(conn) || /* redundant NOOP */
810 (IBLND_OOB_CAPABLE(ver) && /* posted enough NOOP */
811 conn->ibc_noops_posted == IBLND_OOB_MSGS(ver)))) {
812 /* OK to drop when posted enough NOOPs, since
813 * kiblnd_check_sends will queue NOOP again when
814 * posted NOOPs complete */
815 spin_unlock(&conn->ibc_lock);
816 kiblnd_tx_done(peer->ibp_ni, tx);
817 spin_lock(&conn->ibc_lock);
818 CDEBUG(D_NET, "%s(%d): redundant or enough NOOP\n",
819 libcfs_nid2str(peer->ibp_nid),
820 conn->ibc_noops_posted);
824 kiblnd_pack_msg(peer->ibp_ni, msg, ver, conn->ibc_outstanding_credits,
825 peer->ibp_nid, conn->ibc_incarnation);
827 conn->ibc_credits -= credit;
828 conn->ibc_outstanding_credits = 0;
829 conn->ibc_nsends_posted++;
830 if (msg->ibm_type == IBLND_MSG_NOOP)
831 conn->ibc_noops_posted++;
833 /* CAVEAT EMPTOR! This tx could be the PUT_DONE of an RDMA
834 * PUT. If so, it was first queued here as a PUT_REQ, sent and
835 * stashed on ibc_active_txs, matched by an incoming PUT_ACK,
836 * and then re-queued here. It's (just) possible that
837 * tx_sending is non-zero if we've not done the tx_complete()
838 * from the first send; hence the ++ rather than = below. */
840 list_add(&tx->tx_list, &conn->ibc_active_txs);
842 /* I'm still holding ibc_lock! */
843 if (conn->ibc_state != IBLND_CONN_ESTABLISHED) {
845 } else if (tx->tx_pool->tpo_pool.po_failed ||
846 conn->ibc_hdev != tx->tx_pool->tpo_hdev) {
847 /* close_conn will launch failover */
850 struct ib_send_wr *wrq = &tx->tx_wrq[tx->tx_nwrq - 1];
852 LASSERTF(wrq->wr_id == kiblnd_ptr2wreqid(tx, IBLND_WID_TX),
853 "bad wr_id "LPX64", opc %d, flags %d, peer: %s\n",
854 wrq->wr_id, wrq->opcode, wrq->send_flags,
855 libcfs_nid2str(conn->ibc_peer->ibp_nid));
857 rc = ib_post_send(conn->ibc_cmid->qp, tx->tx_wrq, &wrq);
860 conn->ibc_last_send = jiffies;
865 /* NB credits are transferred in the actual
866 * message, which can only be the last work item */
867 conn->ibc_credits += credit;
868 conn->ibc_outstanding_credits += msg->ibm_credits;
869 conn->ibc_nsends_posted--;
870 if (msg->ibm_type == IBLND_MSG_NOOP)
871 conn->ibc_noops_posted--;
877 done = (tx->tx_sending == 0);
879 list_del(&tx->tx_list);
881 spin_unlock(&conn->ibc_lock);
883 if (conn->ibc_state == IBLND_CONN_ESTABLISHED)
884 CERROR("Error %d posting transmit to %s\n",
885 rc, libcfs_nid2str(peer->ibp_nid));
887 CDEBUG(D_NET, "Error %d posting transmit to %s\n",
888 rc, libcfs_nid2str(peer->ibp_nid));
890 kiblnd_close_conn(conn, rc);
893 kiblnd_tx_done(peer->ibp_ni, tx);
895 spin_lock(&conn->ibc_lock);
901 kiblnd_check_sends (kib_conn_t *conn)
903 int ver = conn->ibc_version;
904 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
907 /* Don't send anything until after the connection is established */
908 if (conn->ibc_state < IBLND_CONN_ESTABLISHED) {
909 CDEBUG(D_NET, "%s too soon\n",
910 libcfs_nid2str(conn->ibc_peer->ibp_nid));
914 spin_lock(&conn->ibc_lock);
916 LASSERT (conn->ibc_nsends_posted <= IBLND_CONCURRENT_SENDS(ver));
917 LASSERT (!IBLND_OOB_CAPABLE(ver) ||
918 conn->ibc_noops_posted <= IBLND_OOB_MSGS(ver));
919 LASSERT (conn->ibc_reserved_credits >= 0);
921 while (conn->ibc_reserved_credits > 0 &&
922 !list_empty(&conn->ibc_tx_queue_rsrvd)) {
923 tx = list_entry(conn->ibc_tx_queue_rsrvd.next,
925 list_del(&tx->tx_list);
926 list_add_tail(&tx->tx_list, &conn->ibc_tx_queue);
927 conn->ibc_reserved_credits--;
930 if (kiblnd_need_noop(conn)) {
931 spin_unlock(&conn->ibc_lock);
933 tx = kiblnd_get_idle_tx(ni, conn->ibc_peer->ibp_nid);
935 kiblnd_init_tx_msg(ni, tx, IBLND_MSG_NOOP, 0);
937 spin_lock(&conn->ibc_lock);
939 kiblnd_queue_tx_locked(tx, conn);
945 if (!list_empty(&conn->ibc_tx_queue_nocred)) {
947 tx = list_entry(conn->ibc_tx_queue_nocred.next,
949 } else if (!list_empty(&conn->ibc_tx_noops)) {
950 LASSERT (!IBLND_OOB_CAPABLE(ver));
952 tx = list_entry(conn->ibc_tx_noops.next,
954 } else if (!list_empty(&conn->ibc_tx_queue)) {
956 tx = list_entry(conn->ibc_tx_queue.next,
961 if (kiblnd_post_tx_locked(conn, tx, credit) != 0)
965 spin_unlock(&conn->ibc_lock);
969 kiblnd_tx_complete (kib_tx_t *tx, int status)
971 int failed = (status != IB_WC_SUCCESS);
972 kib_conn_t *conn = tx->tx_conn;
975 LASSERT (tx->tx_sending > 0);
978 if (conn->ibc_state == IBLND_CONN_ESTABLISHED)
979 CNETERR("Tx -> %s cookie "LPX64
980 " sending %d waiting %d: failed %d\n",
981 libcfs_nid2str(conn->ibc_peer->ibp_nid),
982 tx->tx_cookie, tx->tx_sending, tx->tx_waiting,
985 kiblnd_close_conn(conn, -EIO);
987 kiblnd_peer_alive(conn->ibc_peer);
990 spin_lock(&conn->ibc_lock);
992 /* I could be racing with rdma completion. Whoever makes 'tx' idle
993 * gets to free it, which also drops its ref on 'conn'. */
996 conn->ibc_nsends_posted--;
997 if (tx->tx_msg->ibm_type == IBLND_MSG_NOOP)
998 conn->ibc_noops_posted--;
1001 tx->tx_waiting = 0; /* don't wait for peer */
1002 tx->tx_status = -EIO;
1005 idle = (tx->tx_sending == 0) && /* This is the final callback */
1006 !tx->tx_waiting && /* Not waiting for peer */
1007 !tx->tx_queued; /* Not re-queued (PUT_DONE) */
1009 list_del(&tx->tx_list);
1011 kiblnd_conn_addref(conn); /* 1 ref for me.... */
1013 spin_unlock(&conn->ibc_lock);
1016 kiblnd_tx_done(conn->ibc_peer->ibp_ni, tx);
1018 kiblnd_check_sends(conn);
1020 kiblnd_conn_decref(conn); /* ...until here */
1024 kiblnd_init_tx_msg (lnet_ni_t *ni, kib_tx_t *tx, int type, int body_nob)
1026 kib_hca_dev_t *hdev = tx->tx_pool->tpo_hdev;
1027 struct ib_sge *sge = &tx->tx_sge[tx->tx_nwrq];
1028 struct ib_send_wr *wrq = &tx->tx_wrq[tx->tx_nwrq];
1029 int nob = offsetof (kib_msg_t, ibm_u) + body_nob;
1030 struct ib_mr *mr = hdev->ibh_mrs;
1032 LASSERT(tx->tx_nwrq >= 0);
1033 LASSERT(tx->tx_nwrq < IBLND_MAX_RDMA_FRAGS + 1);
1034 LASSERT(nob <= IBLND_MSG_SIZE);
1035 LASSERT(mr != NULL);
1037 kiblnd_init_msg(tx->tx_msg, type, body_nob);
1039 sge->lkey = mr->lkey;
1040 sge->addr = tx->tx_msgaddr;
1043 memset(wrq, 0, sizeof(*wrq));
1046 wrq->wr_id = kiblnd_ptr2wreqid(tx, IBLND_WID_TX);
1049 wrq->opcode = IB_WR_SEND;
1050 wrq->send_flags = IB_SEND_SIGNALED;
1056 kiblnd_init_rdma(kib_conn_t *conn, kib_tx_t *tx, int type,
1057 int resid, kib_rdma_desc_t *dstrd, __u64 dstcookie)
1059 kib_msg_t *ibmsg = tx->tx_msg;
1060 kib_rdma_desc_t *srcrd = tx->tx_rd;
1061 struct ib_sge *sge = &tx->tx_sge[0];
1062 struct ib_send_wr *wrq = &tx->tx_wrq[0];
1068 LASSERT (!in_interrupt());
1069 LASSERT (tx->tx_nwrq == 0);
1070 LASSERT (type == IBLND_MSG_GET_DONE ||
1071 type == IBLND_MSG_PUT_DONE);
1073 srcidx = dstidx = 0;
1076 if (srcidx >= srcrd->rd_nfrags) {
1077 CERROR("Src buffer exhausted: %d frags\n", srcidx);
1082 if (dstidx == dstrd->rd_nfrags) {
1083 CERROR("Dst buffer exhausted: %d frags\n", dstidx);
1088 if (tx->tx_nwrq >= conn->ibc_max_frags) {
1089 CERROR("RDMA has too many fragments for peer %s (%d), "
1090 "src idx/frags: %d/%d dst idx/frags: %d/%d\n",
1091 libcfs_nid2str(conn->ibc_peer->ibp_nid),
1092 conn->ibc_max_frags,
1093 srcidx, srcrd->rd_nfrags,
1094 dstidx, dstrd->rd_nfrags);
1099 wrknob = MIN(MIN(kiblnd_rd_frag_size(srcrd, srcidx),
1100 kiblnd_rd_frag_size(dstrd, dstidx)), resid);
1102 sge = &tx->tx_sge[tx->tx_nwrq];
1103 sge->addr = kiblnd_rd_frag_addr(srcrd, srcidx);
1104 sge->lkey = kiblnd_rd_frag_key(srcrd, srcidx);
1105 sge->length = wrknob;
1107 wrq = &tx->tx_wrq[tx->tx_nwrq];
1109 wrq->next = wrq + 1;
1110 wrq->wr_id = kiblnd_ptr2wreqid(tx, IBLND_WID_RDMA);
1113 wrq->opcode = IB_WR_RDMA_WRITE;
1114 wrq->send_flags = 0;
1116 wrq->wr.rdma.remote_addr = kiblnd_rd_frag_addr(dstrd, dstidx);
1117 wrq->wr.rdma.rkey = kiblnd_rd_frag_key(dstrd, dstidx);
1119 srcidx = kiblnd_rd_consume_frag(srcrd, srcidx, wrknob);
1120 dstidx = kiblnd_rd_consume_frag(dstrd, dstidx, wrknob);
1129 if (rc < 0) /* no RDMA if completing with failure */
1132 ibmsg->ibm_u.completion.ibcm_status = rc;
1133 ibmsg->ibm_u.completion.ibcm_cookie = dstcookie;
1134 kiblnd_init_tx_msg(conn->ibc_peer->ibp_ni, tx,
1135 type, sizeof (kib_completion_msg_t));
1141 kiblnd_queue_tx_locked(kib_tx_t *tx, kib_conn_t *conn)
1143 struct list_head *q;
1145 LASSERT(tx->tx_nwrq > 0); /* work items set up */
1146 LASSERT(!tx->tx_queued); /* not queued for sending already */
1147 LASSERT(conn->ibc_state >= IBLND_CONN_ESTABLISHED);
1150 tx->tx_deadline = jiffies +
1151 msecs_to_jiffies(*kiblnd_tunables.kib_timeout *
1154 if (tx->tx_conn == NULL) {
1155 kiblnd_conn_addref(conn);
1157 LASSERT (tx->tx_msg->ibm_type != IBLND_MSG_PUT_DONE);
1159 /* PUT_DONE first attached to conn as a PUT_REQ */
1160 LASSERT (tx->tx_conn == conn);
1161 LASSERT (tx->tx_msg->ibm_type == IBLND_MSG_PUT_DONE);
1164 switch (tx->tx_msg->ibm_type) {
1168 case IBLND_MSG_PUT_REQ:
1169 case IBLND_MSG_GET_REQ:
1170 q = &conn->ibc_tx_queue_rsrvd;
1173 case IBLND_MSG_PUT_NAK:
1174 case IBLND_MSG_PUT_ACK:
1175 case IBLND_MSG_PUT_DONE:
1176 case IBLND_MSG_GET_DONE:
1177 q = &conn->ibc_tx_queue_nocred;
1180 case IBLND_MSG_NOOP:
1181 if (IBLND_OOB_CAPABLE(conn->ibc_version))
1182 q = &conn->ibc_tx_queue_nocred;
1184 q = &conn->ibc_tx_noops;
1187 case IBLND_MSG_IMMEDIATE:
1188 q = &conn->ibc_tx_queue;
1192 list_add_tail(&tx->tx_list, q);
1196 kiblnd_queue_tx (kib_tx_t *tx, kib_conn_t *conn)
1198 spin_lock(&conn->ibc_lock);
1199 kiblnd_queue_tx_locked(tx, conn);
1200 spin_unlock(&conn->ibc_lock);
1202 kiblnd_check_sends(conn);
1205 static int kiblnd_resolve_addr(struct rdma_cm_id *cmid,
1206 struct sockaddr_in *srcaddr,
1207 struct sockaddr_in *dstaddr,
1210 unsigned short port;
1213 /* allow the port to be reused */
1214 rc = rdma_set_reuseaddr(cmid, 1);
1216 CERROR("Unable to set reuse on cmid: %d\n", rc);
1220 /* look for a free privileged port */
1221 for (port = PROT_SOCK-1; port > 0; port--) {
1222 srcaddr->sin_port = htons(port);
1223 rc = rdma_resolve_addr(cmid,
1224 (struct sockaddr *)srcaddr,
1225 (struct sockaddr *)dstaddr,
1228 CDEBUG(D_NET, "bound to port %hu\n", port);
1230 } else if (rc == -EADDRINUSE || rc == -EADDRNOTAVAIL) {
1231 CDEBUG(D_NET, "bind to port %hu failed: %d\n",
1238 CERROR("Failed to bind to a free privileged port\n");
1243 kiblnd_connect_peer (kib_peer_t *peer)
1245 struct rdma_cm_id *cmid;
1247 kib_net_t *net = peer->ibp_ni->ni_data;
1248 struct sockaddr_in srcaddr;
1249 struct sockaddr_in dstaddr;
1252 LASSERT (net != NULL);
1253 LASSERT (peer->ibp_connecting > 0);
1255 cmid = kiblnd_rdma_create_id(kiblnd_cm_callback, peer, RDMA_PS_TCP,
1259 CERROR("Can't create CMID for %s: %ld\n",
1260 libcfs_nid2str(peer->ibp_nid), PTR_ERR(cmid));
1266 memset(&srcaddr, 0, sizeof(srcaddr));
1267 srcaddr.sin_family = AF_INET;
1268 srcaddr.sin_addr.s_addr = htonl(dev->ibd_ifip);
1270 memset(&dstaddr, 0, sizeof(dstaddr));
1271 dstaddr.sin_family = AF_INET;
1272 dstaddr.sin_port = htons(*kiblnd_tunables.kib_service);
1273 dstaddr.sin_addr.s_addr = htonl(LNET_NIDADDR(peer->ibp_nid));
1275 kiblnd_peer_addref(peer); /* cmid's ref */
1277 if (*kiblnd_tunables.kib_use_priv_port) {
1278 rc = kiblnd_resolve_addr(cmid, &srcaddr, &dstaddr,
1279 *kiblnd_tunables.kib_timeout * 1000);
1281 rc = rdma_resolve_addr(cmid,
1282 (struct sockaddr *)&srcaddr,
1283 (struct sockaddr *)&dstaddr,
1284 *kiblnd_tunables.kib_timeout * 1000);
1287 /* Can't initiate address resolution: */
1288 CERROR("Can't resolve addr for %s: %d\n",
1289 libcfs_nid2str(peer->ibp_nid), rc);
1293 LASSERT (cmid->device != NULL);
1294 CDEBUG(D_NET, "%s: connection bound to %s:%pI4h:%s\n",
1295 libcfs_nid2str(peer->ibp_nid), dev->ibd_ifname,
1296 &dev->ibd_ifip, cmid->device->name);
1301 kiblnd_peer_connect_failed(peer, 1, rc);
1302 kiblnd_peer_decref(peer); /* cmid's ref */
1303 rdma_destroy_id(cmid);
1306 kiblnd_peer_connect_failed(peer, 1, rc);
1310 kiblnd_launch_tx (lnet_ni_t *ni, kib_tx_t *tx, lnet_nid_t nid)
1315 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
1316 unsigned long flags;
1319 /* If I get here, I've committed to send, so I complete the tx with
1320 * failure on any problems */
1322 LASSERT (tx == NULL || tx->tx_conn == NULL); /* only set when assigned a conn */
1323 LASSERT (tx == NULL || tx->tx_nwrq > 0); /* work items have been set up */
1325 /* First time, just use a read lock since I expect to find my peer
1327 read_lock_irqsave(g_lock, flags);
1329 peer = kiblnd_find_peer_locked(nid);
1330 if (peer != NULL && !list_empty(&peer->ibp_conns)) {
1331 /* Found a peer with an established connection */
1332 conn = kiblnd_get_conn_locked(peer);
1333 kiblnd_conn_addref(conn); /* 1 ref for me... */
1335 read_unlock_irqrestore(g_lock, flags);
1338 kiblnd_queue_tx(tx, conn);
1339 kiblnd_conn_decref(conn); /* ...to here */
1343 read_unlock(g_lock);
1344 /* Re-try with a write lock */
1347 peer = kiblnd_find_peer_locked(nid);
1349 if (list_empty(&peer->ibp_conns)) {
1350 /* found a peer, but it's still connecting... */
1351 LASSERT (peer->ibp_connecting != 0 ||
1352 peer->ibp_accepting != 0);
1354 list_add_tail(&tx->tx_list,
1355 &peer->ibp_tx_queue);
1356 write_unlock_irqrestore(g_lock, flags);
1358 conn = kiblnd_get_conn_locked(peer);
1359 kiblnd_conn_addref(conn); /* 1 ref for me... */
1361 write_unlock_irqrestore(g_lock, flags);
1364 kiblnd_queue_tx(tx, conn);
1365 kiblnd_conn_decref(conn); /* ...to here */
1370 write_unlock_irqrestore(g_lock, flags);
1372 /* Allocate a peer ready to add to the peer table and retry */
1373 rc = kiblnd_create_peer(ni, &peer, nid);
1375 CERROR("Can't create peer %s\n", libcfs_nid2str(nid));
1377 tx->tx_status = -EHOSTUNREACH;
1379 kiblnd_tx_done(ni, tx);
1384 write_lock_irqsave(g_lock, flags);
1386 peer2 = kiblnd_find_peer_locked(nid);
1387 if (peer2 != NULL) {
1388 if (list_empty(&peer2->ibp_conns)) {
1389 /* found a peer, but it's still connecting... */
1390 LASSERT (peer2->ibp_connecting != 0 ||
1391 peer2->ibp_accepting != 0);
1393 list_add_tail(&tx->tx_list,
1394 &peer2->ibp_tx_queue);
1395 write_unlock_irqrestore(g_lock, flags);
1397 conn = kiblnd_get_conn_locked(peer2);
1398 kiblnd_conn_addref(conn); /* 1 ref for me... */
1400 write_unlock_irqrestore(g_lock, flags);
1403 kiblnd_queue_tx(tx, conn);
1404 kiblnd_conn_decref(conn); /* ...to here */
1407 kiblnd_peer_decref(peer);
1411 /* Brand new peer */
1412 LASSERT (peer->ibp_connecting == 0);
1413 peer->ibp_connecting = 1;
1415 /* always called with a ref on ni, which prevents ni being shutdown */
1416 LASSERT (((kib_net_t *)ni->ni_data)->ibn_shutdown == 0);
1419 list_add_tail(&tx->tx_list, &peer->ibp_tx_queue);
1421 kiblnd_peer_addref(peer);
1422 list_add_tail(&peer->ibp_list, kiblnd_nid2peerlist(nid));
1424 write_unlock_irqrestore(g_lock, flags);
1426 kiblnd_connect_peer(peer);
1427 kiblnd_peer_decref(peer);
1431 kiblnd_send (lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1433 lnet_hdr_t *hdr = &lntmsg->msg_hdr;
1434 int type = lntmsg->msg_type;
1435 lnet_process_id_t target = lntmsg->msg_target;
1436 int target_is_router = lntmsg->msg_target_is_router;
1437 int routing = lntmsg->msg_routing;
1438 unsigned int payload_niov = lntmsg->msg_niov;
1439 struct kvec *payload_iov = lntmsg->msg_iov;
1440 lnet_kiov_t *payload_kiov = lntmsg->msg_kiov;
1441 unsigned int payload_offset = lntmsg->msg_offset;
1442 unsigned int payload_nob = lntmsg->msg_len;
1444 kib_rdma_desc_t *rd;
1449 /* NB 'private' is different depending on what we're sending.... */
1451 CDEBUG(D_NET, "sending %d bytes in %d frags to %s\n",
1452 payload_nob, payload_niov, libcfs_id2str(target));
1454 LASSERT (payload_nob == 0 || payload_niov > 0);
1455 LASSERT (payload_niov <= LNET_MAX_IOV);
1457 /* Thread context */
1458 LASSERT (!in_interrupt());
1459 /* payload is either all vaddrs or all pages */
1460 LASSERT (!(payload_kiov != NULL && payload_iov != NULL));
1468 LASSERT (payload_nob == 0);
1472 if (routing || target_is_router)
1473 break; /* send IMMEDIATE */
1475 /* is the REPLY message too small for RDMA? */
1476 nob = offsetof(kib_msg_t, ibm_u.immediate.ibim_payload[lntmsg->msg_md->md_length]);
1477 if (nob <= IBLND_MSG_SIZE)
1478 break; /* send IMMEDIATE */
1480 tx = kiblnd_get_idle_tx(ni, target.nid);
1482 CERROR("Can't allocate txd for GET to %s\n",
1483 libcfs_nid2str(target.nid));
1488 rd = &ibmsg->ibm_u.get.ibgm_rd;
1489 if ((lntmsg->msg_md->md_options & LNET_MD_KIOV) == 0)
1490 rc = kiblnd_setup_rd_iov(ni, tx, rd,
1491 lntmsg->msg_md->md_niov,
1492 lntmsg->msg_md->md_iov.iov,
1493 0, lntmsg->msg_md->md_length);
1495 rc = kiblnd_setup_rd_kiov(ni, tx, rd,
1496 lntmsg->msg_md->md_niov,
1497 lntmsg->msg_md->md_iov.kiov,
1498 0, lntmsg->msg_md->md_length);
1500 CERROR("Can't setup GET sink for %s: %d\n",
1501 libcfs_nid2str(target.nid), rc);
1502 kiblnd_tx_done(ni, tx);
1506 nob = offsetof(kib_get_msg_t, ibgm_rd.rd_frags[rd->rd_nfrags]);
1507 ibmsg->ibm_u.get.ibgm_cookie = tx->tx_cookie;
1508 ibmsg->ibm_u.get.ibgm_hdr = *hdr;
1510 kiblnd_init_tx_msg(ni, tx, IBLND_MSG_GET_REQ, nob);
1512 tx->tx_lntmsg[1] = lnet_create_reply_msg(ni, lntmsg);
1513 if (tx->tx_lntmsg[1] == NULL) {
1514 CERROR("Can't create reply for GET -> %s\n",
1515 libcfs_nid2str(target.nid));
1516 kiblnd_tx_done(ni, tx);
1520 tx->tx_lntmsg[0] = lntmsg; /* finalise lntmsg[0,1] on completion */
1521 tx->tx_waiting = 1; /* waiting for GET_DONE */
1522 kiblnd_launch_tx(ni, tx, target.nid);
1525 case LNET_MSG_REPLY:
1527 /* Is the payload small enough not to need RDMA? */
1528 nob = offsetof(kib_msg_t, ibm_u.immediate.ibim_payload[payload_nob]);
1529 if (nob <= IBLND_MSG_SIZE)
1530 break; /* send IMMEDIATE */
1532 tx = kiblnd_get_idle_tx(ni, target.nid);
1534 CERROR("Can't allocate %s txd for %s\n",
1535 type == LNET_MSG_PUT ? "PUT" : "REPLY",
1536 libcfs_nid2str(target.nid));
1540 if (payload_kiov == NULL)
1541 rc = kiblnd_setup_rd_iov(ni, tx, tx->tx_rd,
1542 payload_niov, payload_iov,
1543 payload_offset, payload_nob);
1545 rc = kiblnd_setup_rd_kiov(ni, tx, tx->tx_rd,
1546 payload_niov, payload_kiov,
1547 payload_offset, payload_nob);
1549 CERROR("Can't setup PUT src for %s: %d\n",
1550 libcfs_nid2str(target.nid), rc);
1551 kiblnd_tx_done(ni, tx);
1556 ibmsg->ibm_u.putreq.ibprm_hdr = *hdr;
1557 ibmsg->ibm_u.putreq.ibprm_cookie = tx->tx_cookie;
1558 kiblnd_init_tx_msg(ni, tx, IBLND_MSG_PUT_REQ, sizeof(kib_putreq_msg_t));
1560 tx->tx_lntmsg[0] = lntmsg; /* finalise lntmsg on completion */
1561 tx->tx_waiting = 1; /* waiting for PUT_{ACK,NAK} */
1562 kiblnd_launch_tx(ni, tx, target.nid);
1566 /* send IMMEDIATE */
1568 LASSERT (offsetof(kib_msg_t, ibm_u.immediate.ibim_payload[payload_nob])
1571 tx = kiblnd_get_idle_tx(ni, target.nid);
1573 CERROR ("Can't send %d to %s: tx descs exhausted\n",
1574 type, libcfs_nid2str(target.nid));
1579 ibmsg->ibm_u.immediate.ibim_hdr = *hdr;
1581 if (payload_kiov != NULL)
1582 lnet_copy_kiov2flat(IBLND_MSG_SIZE, ibmsg,
1583 offsetof(kib_msg_t, ibm_u.immediate.ibim_payload),
1584 payload_niov, payload_kiov,
1585 payload_offset, payload_nob);
1587 lnet_copy_iov2flat(IBLND_MSG_SIZE, ibmsg,
1588 offsetof(kib_msg_t, ibm_u.immediate.ibim_payload),
1589 payload_niov, payload_iov,
1590 payload_offset, payload_nob);
1592 nob = offsetof(kib_immediate_msg_t, ibim_payload[payload_nob]);
1593 kiblnd_init_tx_msg(ni, tx, IBLND_MSG_IMMEDIATE, nob);
1595 tx->tx_lntmsg[0] = lntmsg; /* finalise lntmsg on completion */
1596 kiblnd_launch_tx(ni, tx, target.nid);
1601 kiblnd_reply (lnet_ni_t *ni, kib_rx_t *rx, lnet_msg_t *lntmsg)
1603 lnet_process_id_t target = lntmsg->msg_target;
1604 unsigned int niov = lntmsg->msg_niov;
1605 struct kvec *iov = lntmsg->msg_iov;
1606 lnet_kiov_t *kiov = lntmsg->msg_kiov;
1607 unsigned int offset = lntmsg->msg_offset;
1608 unsigned int nob = lntmsg->msg_len;
1612 tx = kiblnd_get_idle_tx(ni, rx->rx_conn->ibc_peer->ibp_nid);
1614 CERROR("Can't get tx for REPLY to %s\n",
1615 libcfs_nid2str(target.nid));
1621 else if (kiov == NULL)
1622 rc = kiblnd_setup_rd_iov(ni, tx, tx->tx_rd,
1623 niov, iov, offset, nob);
1625 rc = kiblnd_setup_rd_kiov(ni, tx, tx->tx_rd,
1626 niov, kiov, offset, nob);
1629 CERROR("Can't setup GET src for %s: %d\n",
1630 libcfs_nid2str(target.nid), rc);
1634 rc = kiblnd_init_rdma(rx->rx_conn, tx,
1635 IBLND_MSG_GET_DONE, nob,
1636 &rx->rx_msg->ibm_u.get.ibgm_rd,
1637 rx->rx_msg->ibm_u.get.ibgm_cookie);
1639 CERROR("Can't setup rdma for GET from %s: %d\n",
1640 libcfs_nid2str(target.nid), rc);
1645 /* No RDMA: local completion may happen now! */
1646 lnet_finalize(ni, lntmsg, 0);
1648 /* RDMA: lnet_finalize(lntmsg) when it
1650 tx->tx_lntmsg[0] = lntmsg;
1653 kiblnd_queue_tx(tx, rx->rx_conn);
1657 kiblnd_tx_done(ni, tx);
1659 lnet_finalize(ni, lntmsg, -EIO);
1663 kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
1664 unsigned int niov, struct kvec *iov, lnet_kiov_t *kiov,
1665 unsigned int offset, unsigned int mlen, unsigned int rlen)
1667 kib_rx_t *rx = private;
1668 kib_msg_t *rxmsg = rx->rx_msg;
1669 kib_conn_t *conn = rx->rx_conn;
1672 int post_credit = IBLND_POSTRX_PEER_CREDIT;
1675 LASSERT (mlen <= rlen);
1676 LASSERT (!in_interrupt());
1677 /* Either all pages or all vaddrs */
1678 LASSERT (!(kiov != NULL && iov != NULL));
1680 switch (rxmsg->ibm_type) {
1684 case IBLND_MSG_IMMEDIATE:
1685 nob = offsetof(kib_msg_t, ibm_u.immediate.ibim_payload[rlen]);
1686 if (nob > rx->rx_nob) {
1687 CERROR ("Immediate message from %s too big: %d(%d)\n",
1688 libcfs_nid2str(rxmsg->ibm_u.immediate.ibim_hdr.src_nid),
1695 lnet_copy_flat2kiov(niov, kiov, offset,
1696 IBLND_MSG_SIZE, rxmsg,
1697 offsetof(kib_msg_t, ibm_u.immediate.ibim_payload),
1700 lnet_copy_flat2iov(niov, iov, offset,
1701 IBLND_MSG_SIZE, rxmsg,
1702 offsetof(kib_msg_t, ibm_u.immediate.ibim_payload),
1704 lnet_finalize (ni, lntmsg, 0);
1707 case IBLND_MSG_PUT_REQ: {
1709 kib_rdma_desc_t *rd;
1712 lnet_finalize(ni, lntmsg, 0);
1713 kiblnd_send_completion(rx->rx_conn, IBLND_MSG_PUT_NAK, 0,
1714 rxmsg->ibm_u.putreq.ibprm_cookie);
1718 tx = kiblnd_get_idle_tx(ni, conn->ibc_peer->ibp_nid);
1720 CERROR("Can't allocate tx for %s\n",
1721 libcfs_nid2str(conn->ibc_peer->ibp_nid));
1722 /* Not replying will break the connection */
1728 rd = &txmsg->ibm_u.putack.ibpam_rd;
1730 rc = kiblnd_setup_rd_iov(ni, tx, rd,
1731 niov, iov, offset, mlen);
1733 rc = kiblnd_setup_rd_kiov(ni, tx, rd,
1734 niov, kiov, offset, mlen);
1736 CERROR("Can't setup PUT sink for %s: %d\n",
1737 libcfs_nid2str(conn->ibc_peer->ibp_nid), rc);
1738 kiblnd_tx_done(ni, tx);
1739 /* tell peer it's over */
1740 kiblnd_send_completion(rx->rx_conn, IBLND_MSG_PUT_NAK, rc,
1741 rxmsg->ibm_u.putreq.ibprm_cookie);
1745 nob = offsetof(kib_putack_msg_t, ibpam_rd.rd_frags[rd->rd_nfrags]);
1746 txmsg->ibm_u.putack.ibpam_src_cookie = rxmsg->ibm_u.putreq.ibprm_cookie;
1747 txmsg->ibm_u.putack.ibpam_dst_cookie = tx->tx_cookie;
1749 kiblnd_init_tx_msg(ni, tx, IBLND_MSG_PUT_ACK, nob);
1751 tx->tx_lntmsg[0] = lntmsg; /* finalise lntmsg on completion */
1752 tx->tx_waiting = 1; /* waiting for PUT_DONE */
1753 kiblnd_queue_tx(tx, conn);
1755 /* reposted buffer reserved for PUT_DONE */
1756 post_credit = IBLND_POSTRX_NO_CREDIT;
1760 case IBLND_MSG_GET_REQ:
1761 if (lntmsg != NULL) {
1762 /* Optimized GET; RDMA lntmsg's payload */
1763 kiblnd_reply(ni, rx, lntmsg);
1765 /* GET didn't match anything */
1766 kiblnd_send_completion(rx->rx_conn, IBLND_MSG_GET_DONE,
1768 rxmsg->ibm_u.get.ibgm_cookie);
1773 kiblnd_post_rx(rx, post_credit);
1778 kiblnd_thread_start(int (*fn)(void *arg), void *arg, char *name)
1780 struct task_struct *task = kthread_run(fn, arg, name);
1783 return PTR_ERR(task);
1785 atomic_inc(&kiblnd_data.kib_nthreads);
1790 kiblnd_thread_fini (void)
1792 atomic_dec (&kiblnd_data.kib_nthreads);
1796 kiblnd_peer_alive (kib_peer_t *peer)
1798 /* This is racy, but everyone's only writing cfs_time_current() */
1799 peer->ibp_last_alive = cfs_time_current();
1804 kiblnd_peer_notify (kib_peer_t *peer)
1807 cfs_time_t last_alive = 0;
1808 unsigned long flags;
1810 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
1812 if (list_empty(&peer->ibp_conns) &&
1813 peer->ibp_accepting == 0 &&
1814 peer->ibp_connecting == 0 &&
1815 peer->ibp_error != 0) {
1816 error = peer->ibp_error;
1817 peer->ibp_error = 0;
1819 last_alive = peer->ibp_last_alive;
1822 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
1825 lnet_notify(peer->ibp_ni,
1826 peer->ibp_nid, 0, last_alive);
1830 kiblnd_close_conn_locked (kib_conn_t *conn, int error)
1832 /* This just does the immediate housekeeping. 'error' is zero for a
1833 * normal shutdown which can happen only after the connection has been
1834 * established. If the connection is established, schedule the
1835 * connection to be finished off by the connd. Otherwise the connd is
1836 * already dealing with it (either to set it up or tear it down).
1837 * Caller holds kib_global_lock exclusively in irq context */
1838 kib_peer_t *peer = conn->ibc_peer;
1840 unsigned long flags;
1842 LASSERT (error != 0 || conn->ibc_state >= IBLND_CONN_ESTABLISHED);
1844 if (error != 0 && conn->ibc_comms_error == 0)
1845 conn->ibc_comms_error = error;
1847 if (conn->ibc_state != IBLND_CONN_ESTABLISHED)
1848 return; /* already being handled */
1851 list_empty(&conn->ibc_tx_noops) &&
1852 list_empty(&conn->ibc_tx_queue) &&
1853 list_empty(&conn->ibc_tx_queue_rsrvd) &&
1854 list_empty(&conn->ibc_tx_queue_nocred) &&
1855 list_empty(&conn->ibc_active_txs)) {
1856 CDEBUG(D_NET, "closing conn to %s\n",
1857 libcfs_nid2str(peer->ibp_nid));
1859 CNETERR("Closing conn to %s: error %d%s%s%s%s%s\n",
1860 libcfs_nid2str(peer->ibp_nid), error,
1861 list_empty(&conn->ibc_tx_queue) ? "" : "(sending)",
1862 list_empty(&conn->ibc_tx_noops) ? "" : "(sending_noops)",
1863 list_empty(&conn->ibc_tx_queue_rsrvd) ?
1864 "" : "(sending_rsrvd)",
1865 list_empty(&conn->ibc_tx_queue_nocred) ?
1866 "" : "(sending_nocred)",
1867 list_empty(&conn->ibc_active_txs) ? "" : "(waiting)");
1870 dev = ((kib_net_t *)peer->ibp_ni->ni_data)->ibn_dev;
1871 list_del(&conn->ibc_list);
1872 /* connd (see below) takes over ibc_list's ref */
1874 if (list_empty(&peer->ibp_conns) && /* no more conns */
1875 kiblnd_peer_active(peer)) { /* still in peer table */
1876 kiblnd_unlink_peer_locked(peer);
1878 /* set/clear error on last conn */
1879 peer->ibp_error = conn->ibc_comms_error;
1882 kiblnd_set_conn_state(conn, IBLND_CONN_CLOSING);
1885 kiblnd_dev_can_failover(dev)) {
1886 list_add_tail(&dev->ibd_fail_list,
1887 &kiblnd_data.kib_failed_devs);
1888 wake_up(&kiblnd_data.kib_failover_waitq);
1891 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);
1893 list_add_tail(&conn->ibc_list, &kiblnd_data.kib_connd_conns);
1894 wake_up(&kiblnd_data.kib_connd_waitq);
1896 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags);
1900 kiblnd_close_conn(kib_conn_t *conn, int error)
1902 unsigned long flags;
1904 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
1906 kiblnd_close_conn_locked(conn, error);
1908 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
1912 kiblnd_handle_early_rxs(kib_conn_t *conn)
1914 unsigned long flags;
1917 LASSERT(!in_interrupt());
1918 LASSERT(conn->ibc_state >= IBLND_CONN_ESTABLISHED);
1920 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
1921 while (!list_empty(&conn->ibc_early_rxs)) {
1922 rx = list_entry(conn->ibc_early_rxs.next,
1924 list_del(&rx->rx_list);
1925 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
1927 kiblnd_handle_rx(rx);
1929 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
1931 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
1935 kiblnd_abort_txs(kib_conn_t *conn, struct list_head *txs)
1937 struct list_head zombies = LIST_HEAD_INIT(zombies);
1938 struct list_head *tmp;
1939 struct list_head *nxt;
1942 spin_lock(&conn->ibc_lock);
1944 list_for_each_safe(tmp, nxt, txs) {
1945 tx = list_entry(tmp, kib_tx_t, tx_list);
1947 if (txs == &conn->ibc_active_txs) {
1948 LASSERT(!tx->tx_queued);
1949 LASSERT(tx->tx_waiting ||
1950 tx->tx_sending != 0);
1952 LASSERT(tx->tx_queued);
1955 tx->tx_status = -ECONNABORTED;
1958 if (tx->tx_sending == 0) {
1960 list_del(&tx->tx_list);
1961 list_add(&tx->tx_list, &zombies);
1965 spin_unlock(&conn->ibc_lock);
1967 kiblnd_txlist_done(conn->ibc_peer->ibp_ni, &zombies, -ECONNABORTED);
1971 kiblnd_finalise_conn (kib_conn_t *conn)
1973 LASSERT (!in_interrupt());
1974 LASSERT (conn->ibc_state > IBLND_CONN_INIT);
1976 kiblnd_set_conn_state(conn, IBLND_CONN_DISCONNECTED);
1978 /* abort_receives moves QP state to IB_QPS_ERR. This is only required
1979 * for connections that didn't get as far as being connected, because
1980 * rdma_disconnect() does this for free. */
1981 kiblnd_abort_receives(conn);
1983 /* Complete all tx descs not waiting for sends to complete.
1984 * NB we should be safe from RDMA now that the QP has changed state */
1986 kiblnd_abort_txs(conn, &conn->ibc_tx_noops);
1987 kiblnd_abort_txs(conn, &conn->ibc_tx_queue);
1988 kiblnd_abort_txs(conn, &conn->ibc_tx_queue_rsrvd);
1989 kiblnd_abort_txs(conn, &conn->ibc_tx_queue_nocred);
1990 kiblnd_abort_txs(conn, &conn->ibc_active_txs);
1992 kiblnd_handle_early_rxs(conn);
1996 kiblnd_peer_connect_failed(kib_peer_t *peer, int active, int error)
1998 struct list_head zombies = LIST_HEAD_INIT(zombies);
1999 unsigned long flags;
2001 LASSERT (error != 0);
2002 LASSERT (!in_interrupt());
2004 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2007 LASSERT (peer->ibp_connecting > 0);
2008 peer->ibp_connecting--;
2010 LASSERT (peer->ibp_accepting > 0);
2011 peer->ibp_accepting--;
2014 if (peer->ibp_connecting != 0 ||
2015 peer->ibp_accepting != 0) {
2016 /* another connection attempt under way... */
2017 write_unlock_irqrestore(&kiblnd_data.kib_global_lock,
2022 if (list_empty(&peer->ibp_conns)) {
2023 /* Take peer's blocked transmits to complete with error */
2024 list_add(&zombies, &peer->ibp_tx_queue);
2025 list_del_init(&peer->ibp_tx_queue);
2027 if (kiblnd_peer_active(peer))
2028 kiblnd_unlink_peer_locked(peer);
2030 peer->ibp_error = error;
2032 /* Can't have blocked transmits if there are connections */
2033 LASSERT(list_empty(&peer->ibp_tx_queue));
2036 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2038 kiblnd_peer_notify(peer);
2040 if (list_empty(&zombies))
2043 CNETERR("Deleting messages for %s: connection failed\n",
2044 libcfs_nid2str(peer->ibp_nid));
2046 kiblnd_txlist_done(peer->ibp_ni, &zombies, -EHOSTUNREACH);
2050 kiblnd_connreq_done(kib_conn_t *conn, int status)
2052 kib_peer_t *peer = conn->ibc_peer;
2054 struct list_head txs;
2055 unsigned long flags;
2058 active = (conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT);
2060 CDEBUG(D_NET,"%s: active(%d), version(%x), status(%d)\n",
2061 libcfs_nid2str(peer->ibp_nid), active,
2062 conn->ibc_version, status);
2064 LASSERT (!in_interrupt());
2065 LASSERT ((conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT &&
2066 peer->ibp_connecting > 0) ||
2067 (conn->ibc_state == IBLND_CONN_PASSIVE_WAIT &&
2068 peer->ibp_accepting > 0));
2070 LIBCFS_FREE(conn->ibc_connvars, sizeof(*conn->ibc_connvars));
2071 conn->ibc_connvars = NULL;
2074 /* failed to establish connection */
2075 kiblnd_peer_connect_failed(peer, active, status);
2076 kiblnd_finalise_conn(conn);
2080 /* connection established */
2081 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2083 conn->ibc_last_send = jiffies;
2084 kiblnd_set_conn_state(conn, IBLND_CONN_ESTABLISHED);
2085 kiblnd_peer_alive(peer);
2087 /* Add conn to peer's list and nuke any dangling conns from a different
2088 * peer instance... */
2089 kiblnd_conn_addref(conn); /* +1 ref for ibc_list */
2090 list_add(&conn->ibc_list, &peer->ibp_conns);
2092 peer->ibp_connecting--;
2094 peer->ibp_accepting--;
2096 if (peer->ibp_version == 0) {
2097 peer->ibp_version = conn->ibc_version;
2098 peer->ibp_incarnation = conn->ibc_incarnation;
2101 if (peer->ibp_version != conn->ibc_version ||
2102 peer->ibp_incarnation != conn->ibc_incarnation) {
2103 kiblnd_close_stale_conns_locked(peer, conn->ibc_version,
2104 conn->ibc_incarnation);
2105 peer->ibp_version = conn->ibc_version;
2106 peer->ibp_incarnation = conn->ibc_incarnation;
2109 /* grab pending txs while I have the lock */
2110 list_add(&txs, &peer->ibp_tx_queue);
2111 list_del_init(&peer->ibp_tx_queue);
2113 if (!kiblnd_peer_active(peer) || /* peer has been deleted */
2114 conn->ibc_comms_error != 0) { /* error has happened already */
2115 lnet_ni_t *ni = peer->ibp_ni;
2117 /* start to shut down connection */
2118 kiblnd_close_conn_locked(conn, -ECONNABORTED);
2119 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2121 kiblnd_txlist_done(ni, &txs, -ECONNABORTED);
2126 /* refcount taken by cmid is not reliable after I released the glock
2127 * because this connection is visible to other threads now, another
2128 * thread can find and close this connection right after I released
2129 * the glock, if kiblnd_cm_callback for RDMA_CM_EVENT_DISCONNECTED is
2130 * called, it can release the connection refcount taken by cmid.
2131 * It means the connection could be destroyed before I finish my
2134 kiblnd_conn_addref(conn);
2135 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2137 /* Schedule blocked txs */
2138 spin_lock(&conn->ibc_lock);
2139 while (!list_empty(&txs)) {
2140 tx = list_entry(txs.next, kib_tx_t, tx_list);
2141 list_del(&tx->tx_list);
2143 kiblnd_queue_tx_locked(tx, conn);
2145 spin_unlock(&conn->ibc_lock);
2147 kiblnd_check_sends(conn);
2149 /* schedule blocked rxs */
2150 kiblnd_handle_early_rxs(conn);
2152 kiblnd_conn_decref(conn);
2156 kiblnd_reject(struct rdma_cm_id *cmid, kib_rej_t *rej)
2160 rc = rdma_reject(cmid, rej, sizeof(*rej));
2163 CWARN("Error %d sending reject\n", rc);
2167 kiblnd_passive_connect(struct rdma_cm_id *cmid, void *priv, int priv_nob)
2169 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
2170 kib_msg_t *reqmsg = priv;
2176 lnet_ni_t *ni = NULL;
2177 kib_net_t *net = NULL;
2179 struct rdma_conn_param cp;
2181 int version = IBLND_MSG_VERSION;
2182 unsigned long flags;
2184 struct sockaddr_in *peer_addr;
2185 LASSERT (!in_interrupt());
2187 /* cmid inherits 'context' from the corresponding listener id */
2188 ibdev = (kib_dev_t *)cmid->context;
2189 LASSERT (ibdev != NULL);
2191 memset(&rej, 0, sizeof(rej));
2192 rej.ibr_magic = IBLND_MSG_MAGIC;
2193 rej.ibr_why = IBLND_REJECT_FATAL;
2194 rej.ibr_cp.ibcp_max_msg_size = IBLND_MSG_SIZE;
2196 peer_addr = (struct sockaddr_in *)&(cmid->route.addr.dst_addr);
2197 if (*kiblnd_tunables.kib_require_priv_port &&
2198 ntohs(peer_addr->sin_port) >= PROT_SOCK) {
2199 __u32 ip = ntohl(peer_addr->sin_addr.s_addr);
2200 CERROR("Peer's port (%pI4h:%hu) is not privileged\n",
2201 &ip, ntohs(peer_addr->sin_port));
2205 if (priv_nob < offsetof(kib_msg_t, ibm_type)) {
2206 CERROR("Short connection request\n");
2210 /* Future protocol version compatibility support! If the
2211 * o2iblnd-specific protocol changes, or when LNET unifies
2212 * protocols over all LNDs, the initial connection will
2213 * negotiate a protocol version. I trap this here to avoid
2214 * console errors; the reject tells the peer which protocol I
2216 if (reqmsg->ibm_magic == LNET_PROTO_MAGIC ||
2217 reqmsg->ibm_magic == __swab32(LNET_PROTO_MAGIC))
2219 if (reqmsg->ibm_magic == IBLND_MSG_MAGIC &&
2220 reqmsg->ibm_version != IBLND_MSG_VERSION &&
2221 reqmsg->ibm_version != IBLND_MSG_VERSION_1)
2223 if (reqmsg->ibm_magic == __swab32(IBLND_MSG_MAGIC) &&
2224 reqmsg->ibm_version != __swab16(IBLND_MSG_VERSION) &&
2225 reqmsg->ibm_version != __swab16(IBLND_MSG_VERSION_1))
2228 rc = kiblnd_unpack_msg(reqmsg, priv_nob);
2230 CERROR("Can't parse connection request: %d\n", rc);
2234 nid = reqmsg->ibm_srcnid;
2235 ni = lnet_net2ni(LNET_NIDNET(reqmsg->ibm_dstnid));
2238 net = (kib_net_t *)ni->ni_data;
2239 rej.ibr_incarnation = net->ibn_incarnation;
2242 if (ni == NULL || /* no matching net */
2243 ni->ni_nid != reqmsg->ibm_dstnid || /* right NET, wrong NID! */
2244 net->ibn_dev != ibdev) { /* wrong device */
2245 CERROR("Can't accept conn from %s on %s (%s:%d:%pI4h): "
2246 "bad dst nid %s\n", libcfs_nid2str(nid),
2247 ni == NULL ? "NA" : libcfs_nid2str(ni->ni_nid),
2248 ibdev->ibd_ifname, ibdev->ibd_nnets,
2250 libcfs_nid2str(reqmsg->ibm_dstnid));
2255 /* check time stamp as soon as possible */
2256 if (reqmsg->ibm_dststamp != 0 &&
2257 reqmsg->ibm_dststamp != net->ibn_incarnation) {
2258 CWARN("Stale connection request\n");
2259 rej.ibr_why = IBLND_REJECT_CONN_STALE;
2263 /* I can accept peer's version */
2264 version = reqmsg->ibm_version;
2266 if (reqmsg->ibm_type != IBLND_MSG_CONNREQ) {
2267 CERROR("Unexpected connreq msg type: %x from %s\n",
2268 reqmsg->ibm_type, libcfs_nid2str(nid));
2272 if (reqmsg->ibm_u.connparams.ibcp_queue_depth >
2273 IBLND_MSG_QUEUE_SIZE(version)) {
2274 CERROR("Can't accept conn from %s, queue depth too large: "
2275 " %d (<=%d wanted)\n",
2276 libcfs_nid2str(nid),
2277 reqmsg->ibm_u.connparams.ibcp_queue_depth,
2278 IBLND_MSG_QUEUE_SIZE(version));
2280 if (version == IBLND_MSG_VERSION)
2281 rej.ibr_why = IBLND_REJECT_MSG_QUEUE_SIZE;
2286 if (reqmsg->ibm_u.connparams.ibcp_max_frags >
2287 IBLND_RDMA_FRAGS(version)) {
2288 CWARN("Can't accept conn from %s (version %x): "
2289 "max_frags %d too large (%d wanted)\n",
2290 libcfs_nid2str(nid), version,
2291 reqmsg->ibm_u.connparams.ibcp_max_frags,
2292 IBLND_RDMA_FRAGS(version));
2294 if (version >= IBLND_MSG_VERSION)
2295 rej.ibr_why = IBLND_REJECT_RDMA_FRAGS;
2298 } else if (reqmsg->ibm_u.connparams.ibcp_max_frags <
2299 IBLND_RDMA_FRAGS(version) && net->ibn_fmr_ps == NULL) {
2300 CWARN("Can't accept conn from %s (version %x): "
2301 "max_frags %d incompatible without FMR pool "
2303 libcfs_nid2str(nid), version,
2304 reqmsg->ibm_u.connparams.ibcp_max_frags,
2305 IBLND_RDMA_FRAGS(version));
2307 if (version >= IBLND_MSG_VERSION)
2308 rej.ibr_why = IBLND_REJECT_RDMA_FRAGS;
2313 if (reqmsg->ibm_u.connparams.ibcp_max_msg_size > IBLND_MSG_SIZE) {
2314 CERROR("Can't accept %s: message size %d too big (%d max)\n",
2315 libcfs_nid2str(nid),
2316 reqmsg->ibm_u.connparams.ibcp_max_msg_size,
2321 /* assume 'nid' is a new peer; create */
2322 rc = kiblnd_create_peer(ni, &peer, nid);
2324 CERROR("Can't create peer for %s\n", libcfs_nid2str(nid));
2325 rej.ibr_why = IBLND_REJECT_NO_RESOURCES;
2329 /* We have validated the peer's parameters so use those */
2330 peer->ibp_max_frags = reqmsg->ibm_u.connparams.ibcp_max_frags;
2331 peer->ibp_queue_depth = reqmsg->ibm_u.connparams.ibcp_queue_depth;
2333 write_lock_irqsave(g_lock, flags);
2335 peer2 = kiblnd_find_peer_locked(nid);
2336 if (peer2 != NULL) {
2337 if (peer2->ibp_version == 0) {
2338 peer2->ibp_version = version;
2339 peer2->ibp_incarnation = reqmsg->ibm_srcstamp;
2342 /* not the guy I've talked with */
2343 if (peer2->ibp_incarnation != reqmsg->ibm_srcstamp ||
2344 peer2->ibp_version != version) {
2345 kiblnd_close_peer_conns_locked(peer2, -ESTALE);
2346 write_unlock_irqrestore(g_lock, flags);
2348 CWARN("Conn stale %s [old ver: %x, new ver: %x]\n",
2349 libcfs_nid2str(nid), peer2->ibp_version, version);
2351 kiblnd_peer_decref(peer);
2352 rej.ibr_why = IBLND_REJECT_CONN_STALE;
2356 /* tie-break connection race in favour of the higher NID */
2357 if (peer2->ibp_connecting != 0 &&
2359 write_unlock_irqrestore(g_lock, flags);
2361 CWARN("Conn race %s\n", libcfs_nid2str(peer2->ibp_nid));
2363 kiblnd_peer_decref(peer);
2364 rej.ibr_why = IBLND_REJECT_CONN_RACE;
2368 peer2->ibp_accepting++;
2369 kiblnd_peer_addref(peer2);
2371 /* Race with kiblnd_launch_tx (active connect) to create peer
2372 * so copy validated parameters since we now know what the
2373 * peer's limits are */
2374 peer2->ibp_max_frags = peer->ibp_max_frags;
2375 peer2->ibp_queue_depth = peer->ibp_queue_depth;
2377 write_unlock_irqrestore(g_lock, flags);
2378 kiblnd_peer_decref(peer);
2381 /* Brand new peer */
2382 LASSERT (peer->ibp_accepting == 0);
2383 LASSERT (peer->ibp_version == 0 &&
2384 peer->ibp_incarnation == 0);
2386 peer->ibp_accepting = 1;
2387 peer->ibp_version = version;
2388 peer->ibp_incarnation = reqmsg->ibm_srcstamp;
2390 /* I have a ref on ni that prevents it being shutdown */
2391 LASSERT (net->ibn_shutdown == 0);
2393 kiblnd_peer_addref(peer);
2394 list_add_tail(&peer->ibp_list, kiblnd_nid2peerlist(nid));
2396 write_unlock_irqrestore(g_lock, flags);
2399 conn = kiblnd_create_conn(peer, cmid, IBLND_CONN_PASSIVE_WAIT, version);
2401 kiblnd_peer_connect_failed(peer, 0, -ENOMEM);
2402 kiblnd_peer_decref(peer);
2403 rej.ibr_why = IBLND_REJECT_NO_RESOURCES;
2407 /* conn now "owns" cmid, so I return success from here on to ensure the
2408 * CM callback doesn't destroy cmid. */
2409 conn->ibc_incarnation = reqmsg->ibm_srcstamp;
2410 conn->ibc_credits = conn->ibc_queue_depth;
2411 conn->ibc_reserved_credits = conn->ibc_queue_depth;
2412 LASSERT(conn->ibc_credits + conn->ibc_reserved_credits +
2413 IBLND_OOB_MSGS(version) <= IBLND_RX_MSGS(conn));
2415 ackmsg = &conn->ibc_connvars->cv_msg;
2416 memset(ackmsg, 0, sizeof(*ackmsg));
2418 kiblnd_init_msg(ackmsg, IBLND_MSG_CONNACK,
2419 sizeof(ackmsg->ibm_u.connparams));
2420 ackmsg->ibm_u.connparams.ibcp_queue_depth = conn->ibc_queue_depth;
2421 ackmsg->ibm_u.connparams.ibcp_max_frags = conn->ibc_max_frags;
2422 ackmsg->ibm_u.connparams.ibcp_max_msg_size = IBLND_MSG_SIZE;
2424 kiblnd_pack_msg(ni, ackmsg, version, 0, nid, reqmsg->ibm_srcstamp);
2426 memset(&cp, 0, sizeof(cp));
2427 cp.private_data = ackmsg;
2428 cp.private_data_len = ackmsg->ibm_nob;
2429 cp.responder_resources = 0; /* No atomic ops or RDMA reads */
2430 cp.initiator_depth = 0;
2431 cp.flow_control = 1;
2432 cp.retry_count = *kiblnd_tunables.kib_retry_count;
2433 cp.rnr_retry_count = *kiblnd_tunables.kib_rnr_retry_count;
2435 CDEBUG(D_NET, "Accept %s\n", libcfs_nid2str(nid));
2437 rc = rdma_accept(cmid, &cp);
2439 CERROR("Can't accept %s: %d\n", libcfs_nid2str(nid), rc);
2440 rej.ibr_version = version;
2441 rej.ibr_why = IBLND_REJECT_FATAL;
2443 kiblnd_reject(cmid, &rej);
2444 kiblnd_connreq_done(conn, rc);
2445 kiblnd_conn_decref(conn);
2455 rej.ibr_version = version;
2456 rej.ibr_cp.ibcp_queue_depth = IBLND_MSG_QUEUE_SIZE(version);
2457 rej.ibr_cp.ibcp_max_frags = IBLND_RDMA_FRAGS(version);
2458 kiblnd_reject(cmid, &rej);
2460 return -ECONNREFUSED;
2464 kiblnd_reconnect (kib_conn_t *conn, int version,
2465 __u64 incarnation, int why, kib_connparams_t *cp)
2467 kib_peer_t *peer = conn->ibc_peer;
2470 unsigned long flags;
2472 LASSERT (conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT);
2473 LASSERT (peer->ibp_connecting > 0); /* 'conn' at least */
2475 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2477 /* retry connection if it's still needed and no other connection
2478 * attempts (active or passive) are in progress
2479 * NB: reconnect is still needed even when ibp_tx_queue is
2480 * empty if ibp_version != version because reconnect may be
2481 * initiated by kiblnd_query() */
2482 if ((!list_empty(&peer->ibp_tx_queue) ||
2483 peer->ibp_version != version) &&
2484 peer->ibp_connecting == 1 &&
2485 peer->ibp_accepting == 0) {
2487 peer->ibp_connecting++;
2488 peer->ibp_version = version;
2489 peer->ibp_incarnation = incarnation;
2492 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2502 case IBLND_REJECT_RDMA_FRAGS:
2506 if (conn->ibc_max_frags <= cp->ibcp_max_frags) {
2507 CNETERR("Unsupported max frags, peer supports %d\n",
2508 cp->ibcp_max_frags);
2510 } else if (*kiblnd_tunables.kib_map_on_demand == 0) {
2511 CNETERR("map_on_demand must be enabled to support "
2512 "map_on_demand peers\n");
2516 peer->ibp_max_frags = cp->ibcp_max_frags;
2517 reason = "rdma fragments";
2520 case IBLND_REJECT_MSG_QUEUE_SIZE:
2524 if (conn->ibc_queue_depth <= cp->ibcp_queue_depth) {
2525 CNETERR("Unsupported queue depth, peer supports %d\n",
2526 cp->ibcp_queue_depth);
2530 peer->ibp_queue_depth = cp->ibcp_queue_depth;
2531 reason = "queue depth";
2534 case IBLND_REJECT_CONN_STALE:
2538 case IBLND_REJECT_CONN_RACE:
2539 reason = "conn race";
2542 case IBLND_REJECT_CONN_UNCOMPAT:
2543 reason = "version negotiation";
2547 CNETERR("%s: retrying (%s), %x, %x, "
2548 "queue_depth: %d, max_frags: %d, msg_size: %d\n",
2549 libcfs_nid2str(peer->ibp_nid),
2550 reason, IBLND_MSG_VERSION, version,
2551 conn->ibc_queue_depth, conn->ibc_max_frags,
2552 cp != NULL ? cp->ibcp_max_msg_size : IBLND_MSG_SIZE);
2554 kiblnd_connect_peer(peer);
2558 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2559 peer->ibp_connecting--;
2560 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2566 kiblnd_rejected (kib_conn_t *conn, int reason, void *priv, int priv_nob)
2568 kib_peer_t *peer = conn->ibc_peer;
2570 LASSERT (!in_interrupt());
2571 LASSERT (conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT);
2574 case IB_CM_REJ_STALE_CONN:
2575 kiblnd_reconnect(conn, IBLND_MSG_VERSION, 0,
2576 IBLND_REJECT_CONN_STALE, NULL);
2579 case IB_CM_REJ_INVALID_SERVICE_ID:
2580 CNETERR("%s rejected: no listener at %d\n",
2581 libcfs_nid2str(peer->ibp_nid),
2582 *kiblnd_tunables.kib_service);
2585 case IB_CM_REJ_CONSUMER_DEFINED:
2586 if (priv_nob >= offsetof(kib_rej_t, ibr_padding)) {
2587 kib_rej_t *rej = priv;
2588 kib_connparams_t *cp = NULL;
2590 __u64 incarnation = -1;
2592 /* NB. default incarnation is -1 because:
2593 * a) V1 will ignore dst incarnation in connreq.
2594 * b) V2 will provide incarnation while rejecting me,
2595 * -1 will be overwrote.
2597 * if I try to connect to a V1 peer with V2 protocol,
2598 * it rejected me then upgrade to V2, I have no idea
2599 * about the upgrading and try to reconnect with V1,
2600 * in this case upgraded V2 can find out I'm trying to
2601 * talk to the old guy and reject me(incarnation is -1).
2604 if (rej->ibr_magic == __swab32(IBLND_MSG_MAGIC) ||
2605 rej->ibr_magic == __swab32(LNET_PROTO_MAGIC)) {
2606 __swab32s(&rej->ibr_magic);
2607 __swab16s(&rej->ibr_version);
2611 if (priv_nob >= sizeof(kib_rej_t) &&
2612 rej->ibr_version > IBLND_MSG_VERSION_1) {
2613 /* priv_nob is always 148 in current version
2614 * of OFED, so we still need to check version.
2615 * (define of IB_CM_REJ_PRIVATE_DATA_SIZE) */
2619 __swab64s(&rej->ibr_incarnation);
2620 __swab16s(&cp->ibcp_queue_depth);
2621 __swab16s(&cp->ibcp_max_frags);
2622 __swab32s(&cp->ibcp_max_msg_size);
2625 incarnation = rej->ibr_incarnation;
2628 if (rej->ibr_magic != IBLND_MSG_MAGIC &&
2629 rej->ibr_magic != LNET_PROTO_MAGIC) {
2630 CERROR("%s rejected: consumer defined fatal error\n",
2631 libcfs_nid2str(peer->ibp_nid));
2635 if (rej->ibr_version != IBLND_MSG_VERSION &&
2636 rej->ibr_version != IBLND_MSG_VERSION_1) {
2637 CERROR("%s rejected: o2iblnd version %x error\n",
2638 libcfs_nid2str(peer->ibp_nid),
2643 if (rej->ibr_why == IBLND_REJECT_FATAL &&
2644 rej->ibr_version == IBLND_MSG_VERSION_1) {
2645 CDEBUG(D_NET, "rejected by old version peer %s: %x\n",
2646 libcfs_nid2str(peer->ibp_nid), rej->ibr_version);
2648 if (conn->ibc_version != IBLND_MSG_VERSION_1)
2649 rej->ibr_why = IBLND_REJECT_CONN_UNCOMPAT;
2652 switch (rej->ibr_why) {
2653 case IBLND_REJECT_CONN_RACE:
2654 case IBLND_REJECT_CONN_STALE:
2655 case IBLND_REJECT_CONN_UNCOMPAT:
2656 case IBLND_REJECT_MSG_QUEUE_SIZE:
2657 case IBLND_REJECT_RDMA_FRAGS:
2658 kiblnd_reconnect(conn, rej->ibr_version,
2659 incarnation, rej->ibr_why, cp);
2662 case IBLND_REJECT_NO_RESOURCES:
2663 CERROR("%s rejected: o2iblnd no resources\n",
2664 libcfs_nid2str(peer->ibp_nid));
2667 case IBLND_REJECT_FATAL:
2668 CERROR("%s rejected: o2iblnd fatal error\n",
2669 libcfs_nid2str(peer->ibp_nid));
2673 CERROR("%s rejected: o2iblnd reason %d\n",
2674 libcfs_nid2str(peer->ibp_nid),
2682 CNETERR("%s rejected: reason %d, size %d\n",
2683 libcfs_nid2str(peer->ibp_nid), reason, priv_nob);
2687 kiblnd_connreq_done(conn, -ECONNREFUSED);
2691 kiblnd_check_connreply (kib_conn_t *conn, void *priv, int priv_nob)
2693 kib_peer_t *peer = conn->ibc_peer;
2694 lnet_ni_t *ni = peer->ibp_ni;
2695 kib_net_t *net = ni->ni_data;
2696 kib_msg_t *msg = priv;
2697 int ver = conn->ibc_version;
2698 int rc = kiblnd_unpack_msg(msg, priv_nob);
2699 unsigned long flags;
2701 LASSERT (net != NULL);
2704 CERROR("Can't unpack connack from %s: %d\n",
2705 libcfs_nid2str(peer->ibp_nid), rc);
2709 if (msg->ibm_type != IBLND_MSG_CONNACK) {
2710 CERROR("Unexpected message %d from %s\n",
2711 msg->ibm_type, libcfs_nid2str(peer->ibp_nid));
2716 if (ver != msg->ibm_version) {
2717 CERROR("%s replied version %x is different with "
2718 "requested version %x\n",
2719 libcfs_nid2str(peer->ibp_nid), msg->ibm_version, ver);
2724 if (msg->ibm_u.connparams.ibcp_queue_depth >
2725 conn->ibc_queue_depth) {
2726 CERROR("%s has incompatible queue depth %d (<=%d wanted)\n",
2727 libcfs_nid2str(peer->ibp_nid),
2728 msg->ibm_u.connparams.ibcp_queue_depth,
2729 conn->ibc_queue_depth);
2734 if (msg->ibm_u.connparams.ibcp_max_frags >
2735 conn->ibc_max_frags) {
2736 CERROR("%s has incompatible max_frags %d (<=%d wanted)\n",
2737 libcfs_nid2str(peer->ibp_nid),
2738 msg->ibm_u.connparams.ibcp_max_frags,
2739 conn->ibc_max_frags);
2744 if (msg->ibm_u.connparams.ibcp_max_msg_size > IBLND_MSG_SIZE) {
2745 CERROR("%s max message size %d too big (%d max)\n",
2746 libcfs_nid2str(peer->ibp_nid),
2747 msg->ibm_u.connparams.ibcp_max_msg_size,
2753 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2754 if (msg->ibm_dstnid == ni->ni_nid &&
2755 msg->ibm_dststamp == net->ibn_incarnation)
2759 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2762 CERROR("Bad connection reply from %s, rc = %d, "
2763 "version: %x max_frags: %d\n",
2764 libcfs_nid2str(peer->ibp_nid), rc,
2765 msg->ibm_version, msg->ibm_u.connparams.ibcp_max_frags);
2769 conn->ibc_incarnation = msg->ibm_srcstamp;
2770 conn->ibc_credits = msg->ibm_u.connparams.ibcp_queue_depth;
2771 conn->ibc_reserved_credits = msg->ibm_u.connparams.ibcp_queue_depth;
2772 conn->ibc_queue_depth = msg->ibm_u.connparams.ibcp_queue_depth;
2773 conn->ibc_max_frags = msg->ibm_u.connparams.ibcp_max_frags;
2774 LASSERT(conn->ibc_credits + conn->ibc_reserved_credits +
2775 IBLND_OOB_MSGS(ver) <= IBLND_RX_MSGS(conn));
2777 kiblnd_connreq_done(conn, 0);
2781 /* NB My QP has already established itself, so I handle anything going
2782 * wrong here by setting ibc_comms_error.
2783 * kiblnd_connreq_done(0) moves the conn state to ESTABLISHED, but then
2784 * immediately tears it down. */
2787 conn->ibc_comms_error = rc;
2788 kiblnd_connreq_done(conn, 0);
2792 kiblnd_active_connect (struct rdma_cm_id *cmid)
2794 kib_peer_t *peer = (kib_peer_t *)cmid->context;
2797 struct rdma_conn_param cp;
2800 unsigned long flags;
2803 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2805 incarnation = peer->ibp_incarnation;
2806 version = (peer->ibp_version == 0) ? IBLND_MSG_VERSION :
2809 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2811 conn = kiblnd_create_conn(peer, cmid, IBLND_CONN_ACTIVE_CONNECT,
2814 kiblnd_peer_connect_failed(peer, 1, -ENOMEM);
2815 kiblnd_peer_decref(peer); /* lose cmid's ref */
2819 /* conn "owns" cmid now, so I return success from here on to ensure the
2820 * CM callback doesn't destroy cmid. conn also takes over cmid's ref
2823 msg = &conn->ibc_connvars->cv_msg;
2825 memset(msg, 0, sizeof(*msg));
2826 kiblnd_init_msg(msg, IBLND_MSG_CONNREQ, sizeof(msg->ibm_u.connparams));
2827 msg->ibm_u.connparams.ibcp_queue_depth = conn->ibc_queue_depth;
2828 msg->ibm_u.connparams.ibcp_max_frags = conn->ibc_max_frags;
2829 msg->ibm_u.connparams.ibcp_max_msg_size = IBLND_MSG_SIZE;
2831 kiblnd_pack_msg(peer->ibp_ni, msg, version,
2832 0, peer->ibp_nid, incarnation);
2834 memset(&cp, 0, sizeof(cp));
2835 cp.private_data = msg;
2836 cp.private_data_len = msg->ibm_nob;
2837 cp.responder_resources = 0; /* No atomic ops or RDMA reads */
2838 cp.initiator_depth = 0;
2839 cp.flow_control = 1;
2840 cp.retry_count = *kiblnd_tunables.kib_retry_count;
2841 cp.rnr_retry_count = *kiblnd_tunables.kib_rnr_retry_count;
2843 LASSERT(cmid->context == (void *)conn);
2844 LASSERT(conn->ibc_cmid == cmid);
2846 rc = rdma_connect(cmid, &cp);
2848 CERROR("Can't connect to %s: %d\n",
2849 libcfs_nid2str(peer->ibp_nid), rc);
2850 kiblnd_connreq_done(conn, rc);
2851 kiblnd_conn_decref(conn);
2858 kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
2864 switch (event->event) {
2866 CERROR("Unexpected event: %d, status: %d\n",
2867 event->event, event->status);
2870 case RDMA_CM_EVENT_CONNECT_REQUEST:
2871 /* destroy cmid on failure */
2872 rc = kiblnd_passive_connect(cmid,
2873 (void *)KIBLND_CONN_PARAM(event),
2874 KIBLND_CONN_PARAM_LEN(event));
2875 CDEBUG(D_NET, "connreq: %d\n", rc);
2878 case RDMA_CM_EVENT_ADDR_ERROR:
2879 peer = (kib_peer_t *)cmid->context;
2880 CNETERR("%s: ADDR ERROR %d\n",
2881 libcfs_nid2str(peer->ibp_nid), event->status);
2882 kiblnd_peer_connect_failed(peer, 1, -EHOSTUNREACH);
2883 kiblnd_peer_decref(peer);
2884 return -EHOSTUNREACH; /* rc != 0 destroys cmid */
2886 case RDMA_CM_EVENT_ADDR_RESOLVED:
2887 peer = (kib_peer_t *)cmid->context;
2889 CDEBUG(D_NET,"%s Addr resolved: %d\n",
2890 libcfs_nid2str(peer->ibp_nid), event->status);
2892 if (event->status != 0) {
2893 CNETERR("Can't resolve address for %s: %d\n",
2894 libcfs_nid2str(peer->ibp_nid), event->status);
2897 rc = rdma_resolve_route(
2898 cmid, *kiblnd_tunables.kib_timeout * 1000);
2901 /* Can't initiate route resolution */
2902 CERROR("Can't resolve route for %s: %d\n",
2903 libcfs_nid2str(peer->ibp_nid), rc);
2905 kiblnd_peer_connect_failed(peer, 1, rc);
2906 kiblnd_peer_decref(peer);
2907 return rc; /* rc != 0 destroys cmid */
2909 case RDMA_CM_EVENT_ROUTE_ERROR:
2910 peer = (kib_peer_t *)cmid->context;
2911 CNETERR("%s: ROUTE ERROR %d\n",
2912 libcfs_nid2str(peer->ibp_nid), event->status);
2913 kiblnd_peer_connect_failed(peer, 1, -EHOSTUNREACH);
2914 kiblnd_peer_decref(peer);
2915 return -EHOSTUNREACH; /* rc != 0 destroys cmid */
2917 case RDMA_CM_EVENT_ROUTE_RESOLVED:
2918 peer = (kib_peer_t *)cmid->context;
2919 CDEBUG(D_NET,"%s Route resolved: %d\n",
2920 libcfs_nid2str(peer->ibp_nid), event->status);
2922 if (event->status == 0)
2923 return kiblnd_active_connect(cmid);
2925 CNETERR("Can't resolve route for %s: %d\n",
2926 libcfs_nid2str(peer->ibp_nid), event->status);
2927 kiblnd_peer_connect_failed(peer, 1, event->status);
2928 kiblnd_peer_decref(peer);
2929 return event->status; /* rc != 0 destroys cmid */
2931 case RDMA_CM_EVENT_UNREACHABLE:
2932 conn = (kib_conn_t *)cmid->context;
2933 LASSERT(conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT ||
2934 conn->ibc_state == IBLND_CONN_PASSIVE_WAIT);
2935 CNETERR("%s: UNREACHABLE %d\n",
2936 libcfs_nid2str(conn->ibc_peer->ibp_nid), event->status);
2937 kiblnd_connreq_done(conn, -ENETDOWN);
2938 kiblnd_conn_decref(conn);
2941 case RDMA_CM_EVENT_CONNECT_ERROR:
2942 conn = (kib_conn_t *)cmid->context;
2943 LASSERT(conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT ||
2944 conn->ibc_state == IBLND_CONN_PASSIVE_WAIT);
2945 CNETERR("%s: CONNECT ERROR %d\n",
2946 libcfs_nid2str(conn->ibc_peer->ibp_nid), event->status);
2947 kiblnd_connreq_done(conn, -ENOTCONN);
2948 kiblnd_conn_decref(conn);
2951 case RDMA_CM_EVENT_REJECTED:
2952 conn = (kib_conn_t *)cmid->context;
2953 switch (conn->ibc_state) {
2957 case IBLND_CONN_PASSIVE_WAIT:
2958 CERROR ("%s: REJECTED %d\n",
2959 libcfs_nid2str(conn->ibc_peer->ibp_nid),
2961 kiblnd_connreq_done(conn, -ECONNRESET);
2964 case IBLND_CONN_ACTIVE_CONNECT:
2965 kiblnd_rejected(conn, event->status,
2966 (void *)KIBLND_CONN_PARAM(event),
2967 KIBLND_CONN_PARAM_LEN(event));
2970 kiblnd_conn_decref(conn);
2973 case RDMA_CM_EVENT_ESTABLISHED:
2974 conn = (kib_conn_t *)cmid->context;
2975 switch (conn->ibc_state) {
2979 case IBLND_CONN_PASSIVE_WAIT:
2980 CDEBUG(D_NET, "ESTABLISHED (passive): %s\n",
2981 libcfs_nid2str(conn->ibc_peer->ibp_nid));
2982 kiblnd_connreq_done(conn, 0);
2985 case IBLND_CONN_ACTIVE_CONNECT:
2986 CDEBUG(D_NET, "ESTABLISHED(active): %s\n",
2987 libcfs_nid2str(conn->ibc_peer->ibp_nid));
2988 kiblnd_check_connreply(conn,
2989 (void *)KIBLND_CONN_PARAM(event),
2990 KIBLND_CONN_PARAM_LEN(event));
2993 /* net keeps its ref on conn! */
2996 case RDMA_CM_EVENT_TIMEWAIT_EXIT:
2997 CDEBUG(D_NET, "Ignore TIMEWAIT_EXIT event\n");
3000 case RDMA_CM_EVENT_DISCONNECTED:
3001 conn = (kib_conn_t *)cmid->context;
3002 if (conn->ibc_state < IBLND_CONN_ESTABLISHED) {
3003 CERROR("%s DISCONNECTED\n",
3004 libcfs_nid2str(conn->ibc_peer->ibp_nid));
3005 kiblnd_connreq_done(conn, -ECONNRESET);
3007 kiblnd_close_conn(conn, 0);
3009 kiblnd_conn_decref(conn);
3010 cmid->context = NULL;
3013 case RDMA_CM_EVENT_DEVICE_REMOVAL:
3014 LCONSOLE_ERROR_MSG(0x131,
3015 "Received notification of device removal\n"
3016 "Please shutdown LNET to allow this to proceed\n");
3017 /* Can't remove network from underneath LNET for now, so I have
3021 case RDMA_CM_EVENT_ADDR_CHANGE:
3022 LCONSOLE_INFO("Physical link changed (eg hca/port)\n");
3028 kiblnd_check_txs_locked(kib_conn_t *conn, struct list_head *txs)
3031 struct list_head *ttmp;
3033 list_for_each(ttmp, txs) {
3034 tx = list_entry(ttmp, kib_tx_t, tx_list);
3036 if (txs != &conn->ibc_active_txs) {
3037 LASSERT(tx->tx_queued);
3039 LASSERT(!tx->tx_queued);
3040 LASSERT(tx->tx_waiting || tx->tx_sending != 0);
3043 if (cfs_time_aftereq(jiffies, tx->tx_deadline)) {
3044 CERROR("Timed out tx: %s, %lu seconds\n",
3045 kiblnd_queue2str(conn, txs),
3046 cfs_duration_sec(jiffies - tx->tx_deadline));
3055 kiblnd_conn_timed_out_locked(kib_conn_t *conn)
3057 return kiblnd_check_txs_locked(conn, &conn->ibc_tx_queue) ||
3058 kiblnd_check_txs_locked(conn, &conn->ibc_tx_noops) ||
3059 kiblnd_check_txs_locked(conn, &conn->ibc_tx_queue_rsrvd) ||
3060 kiblnd_check_txs_locked(conn, &conn->ibc_tx_queue_nocred) ||
3061 kiblnd_check_txs_locked(conn, &conn->ibc_active_txs);
3065 kiblnd_check_conns (int idx)
3067 struct list_head closes = LIST_HEAD_INIT(closes);
3068 struct list_head checksends = LIST_HEAD_INIT(checksends);
3069 struct list_head *peers = &kiblnd_data.kib_peers[idx];
3070 struct list_head *ptmp;
3073 struct list_head *ctmp;
3074 unsigned long flags;
3076 /* NB. We expect to have a look at all the peers and not find any
3077 * RDMAs to time out, so we just use a shared lock while we
3079 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
3081 list_for_each(ptmp, peers) {
3082 peer = list_entry(ptmp, kib_peer_t, ibp_list);
3084 list_for_each(ctmp, &peer->ibp_conns) {
3088 conn = list_entry(ctmp, kib_conn_t, ibc_list);
3090 LASSERT(conn->ibc_state == IBLND_CONN_ESTABLISHED);
3092 spin_lock(&conn->ibc_lock);
3094 sendnoop = kiblnd_need_noop(conn);
3095 timedout = kiblnd_conn_timed_out_locked(conn);
3096 if (!sendnoop && !timedout) {
3097 spin_unlock(&conn->ibc_lock);
3102 CERROR("Timed out RDMA with %s (%lu): "
3103 "c: %u, oc: %u, rc: %u\n",
3104 libcfs_nid2str(peer->ibp_nid),
3105 cfs_duration_sec(cfs_time_current() -
3106 peer->ibp_last_alive),
3108 conn->ibc_outstanding_credits,
3109 conn->ibc_reserved_credits);
3110 list_add(&conn->ibc_connd_list, &closes);
3112 list_add(&conn->ibc_connd_list, &checksends);
3114 /* +ref for 'closes' or 'checksends' */
3115 kiblnd_conn_addref(conn);
3117 spin_unlock(&conn->ibc_lock);
3121 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
3123 /* Handle timeout by closing the whole
3124 * connection. We can only be sure RDMA activity
3125 * has ceased once the QP has been modified. */
3126 while (!list_empty(&closes)) {
3127 conn = list_entry(closes.next,
3128 kib_conn_t, ibc_connd_list);
3129 list_del(&conn->ibc_connd_list);
3130 kiblnd_close_conn(conn, -ETIMEDOUT);
3131 kiblnd_conn_decref(conn);
3134 /* In case we have enough credits to return via a
3135 * NOOP, but there were no non-blocking tx descs
3136 * free to do it last time... */
3137 while (!list_empty(&checksends)) {
3138 conn = list_entry(checksends.next,
3139 kib_conn_t, ibc_connd_list);
3140 list_del(&conn->ibc_connd_list);
3141 kiblnd_check_sends(conn);
3142 kiblnd_conn_decref(conn);
3147 kiblnd_disconnect_conn (kib_conn_t *conn)
3149 LASSERT (!in_interrupt());
3150 LASSERT (current == kiblnd_data.kib_connd);
3151 LASSERT (conn->ibc_state == IBLND_CONN_CLOSING);
3153 rdma_disconnect(conn->ibc_cmid);
3154 kiblnd_finalise_conn(conn);
3156 kiblnd_peer_notify(conn->ibc_peer);
3160 kiblnd_connd (void *arg)
3163 unsigned long flags;
3169 unsigned long deadline = jiffies;
3171 cfs_block_allsigs();
3173 init_waitqueue_entry(&wait, current);
3174 kiblnd_data.kib_connd = current;
3176 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);
3178 while (!kiblnd_data.kib_shutdown) {
3182 if (!list_empty(&kiblnd_data.kib_connd_zombies)) {
3183 conn = list_entry(kiblnd_data. \
3184 kib_connd_zombies.next,
3185 kib_conn_t, ibc_list);
3186 list_del(&conn->ibc_list);
3188 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock,
3192 kiblnd_destroy_conn(conn);
3194 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);
3197 if (!list_empty(&kiblnd_data.kib_connd_conns)) {
3198 conn = list_entry(kiblnd_data.kib_connd_conns.next,
3199 kib_conn_t, ibc_list);
3200 list_del(&conn->ibc_list);
3202 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock,
3206 kiblnd_disconnect_conn(conn);
3207 kiblnd_conn_decref(conn);
3209 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);
3212 /* careful with the jiffy wrap... */
3213 timeout = (int)(deadline - jiffies);
3217 int chunk = kiblnd_data.kib_peer_hash_size;
3219 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags);
3222 /* Time to check for RDMA timeouts on a few more
3223 * peers: I do checks every 'p' seconds on a
3224 * proportion of the peer table and I need to check
3225 * every connection 'n' times within a timeout
3226 * interval, to ensure I detect a timeout on any
3227 * connection within (n+1)/n times the timeout
3230 if (*kiblnd_tunables.kib_timeout > n * p)
3231 chunk = (chunk * n * p) /
3232 *kiblnd_tunables.kib_timeout;
3236 for (i = 0; i < chunk; i++) {
3237 kiblnd_check_conns(peer_index);
3238 peer_index = (peer_index + 1) %
3239 kiblnd_data.kib_peer_hash_size;
3242 deadline += msecs_to_jiffies(p * MSEC_PER_SEC);
3243 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);
3249 /* Nothing to do for 'timeout' */
3250 set_current_state(TASK_INTERRUPTIBLE);
3251 add_wait_queue(&kiblnd_data.kib_connd_waitq, &wait);
3252 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags);
3254 schedule_timeout(timeout);
3256 set_current_state(TASK_RUNNING);
3257 remove_wait_queue(&kiblnd_data.kib_connd_waitq, &wait);
3258 spin_lock_irqsave(&kiblnd_data.kib_connd_lock, flags);
3261 spin_unlock_irqrestore(&kiblnd_data.kib_connd_lock, flags);
3263 kiblnd_thread_fini();
3268 kiblnd_qp_event(struct ib_event *event, void *arg)
3270 kib_conn_t *conn = arg;
3272 switch (event->event) {
3273 case IB_EVENT_COMM_EST:
3274 CDEBUG(D_NET, "%s established\n",
3275 libcfs_nid2str(conn->ibc_peer->ibp_nid));
3279 CERROR("%s: Async QP event type %d\n",
3280 libcfs_nid2str(conn->ibc_peer->ibp_nid), event->event);
3286 kiblnd_complete (struct ib_wc *wc)
3288 switch (kiblnd_wreqid2type(wc->wr_id)) {
3292 case IBLND_WID_RDMA:
3293 /* We only get RDMA completion notification if it fails. All
3294 * subsequent work items, including the final SEND will fail
3295 * too. However we can't print out any more info about the
3296 * failing RDMA because 'tx' might be back on the idle list or
3297 * even reused already if we didn't manage to post all our work
3299 CNETERR("RDMA (tx: %p) failed: %d\n",
3300 kiblnd_wreqid2ptr(wc->wr_id), wc->status);
3304 kiblnd_tx_complete(kiblnd_wreqid2ptr(wc->wr_id), wc->status);
3308 kiblnd_rx_complete(kiblnd_wreqid2ptr(wc->wr_id), wc->status,
3315 kiblnd_cq_completion(struct ib_cq *cq, void *arg)
3317 /* NB I'm not allowed to schedule this conn once its refcount has
3318 * reached 0. Since fundamentally I'm racing with scheduler threads
3319 * consuming my CQ I could be called after all completions have
3320 * occurred. But in this case, ibc_nrx == 0 && ibc_nsends_posted == 0
3321 * and this CQ is about to be destroyed so I NOOP. */
3322 kib_conn_t *conn = (kib_conn_t *)arg;
3323 struct kib_sched_info *sched = conn->ibc_sched;
3324 unsigned long flags;
3326 LASSERT(cq == conn->ibc_cq);
3328 spin_lock_irqsave(&sched->ibs_lock, flags);
3330 conn->ibc_ready = 1;
3332 if (!conn->ibc_scheduled &&
3333 (conn->ibc_nrx > 0 ||
3334 conn->ibc_nsends_posted > 0)) {
3335 kiblnd_conn_addref(conn); /* +1 ref for sched_conns */
3336 conn->ibc_scheduled = 1;
3337 list_add_tail(&conn->ibc_sched_list, &sched->ibs_conns);
3339 if (waitqueue_active(&sched->ibs_waitq))
3340 wake_up(&sched->ibs_waitq);
3343 spin_unlock_irqrestore(&sched->ibs_lock, flags);
3347 kiblnd_cq_event(struct ib_event *event, void *arg)
3349 kib_conn_t *conn = arg;
3351 CERROR("%s: async CQ event type %d\n",
3352 libcfs_nid2str(conn->ibc_peer->ibp_nid), event->event);
3356 kiblnd_scheduler(void *arg)
3358 long id = (long)arg;
3359 struct kib_sched_info *sched;
3362 unsigned long flags;
3368 cfs_block_allsigs();
3370 init_waitqueue_entry(&wait, current);
3372 sched = kiblnd_data.kib_scheds[KIB_THREAD_CPT(id)];
3374 rc = cfs_cpt_bind(lnet_cpt_table(), sched->ibs_cpt);
3376 CWARN("Failed to bind on CPT %d, please verify whether "
3377 "all CPUs are healthy and reload modules if necessary, "
3378 "otherwise your system might under risk of low "
3379 "performance\n", sched->ibs_cpt);
3382 spin_lock_irqsave(&sched->ibs_lock, flags);
3384 while (!kiblnd_data.kib_shutdown) {
3385 if (busy_loops++ >= IBLND_RESCHED) {
3386 spin_unlock_irqrestore(&sched->ibs_lock, flags);
3391 spin_lock_irqsave(&sched->ibs_lock, flags);
3396 if (!list_empty(&sched->ibs_conns)) {
3397 conn = list_entry(sched->ibs_conns.next,
3398 kib_conn_t, ibc_sched_list);
3399 /* take over kib_sched_conns' ref on conn... */
3400 LASSERT(conn->ibc_scheduled);
3401 list_del(&conn->ibc_sched_list);
3402 conn->ibc_ready = 0;
3404 spin_unlock_irqrestore(&sched->ibs_lock, flags);
3406 wc.wr_id = IBLND_WID_INVAL;
3408 rc = ib_poll_cq(conn->ibc_cq, 1, &wc);
3410 rc = ib_req_notify_cq(conn->ibc_cq,
3413 CWARN("%s: ib_req_notify_cq failed: %d, "
3414 "closing connection\n",
3415 libcfs_nid2str(conn->ibc_peer->ibp_nid), rc);
3416 kiblnd_close_conn(conn, -EIO);
3417 kiblnd_conn_decref(conn);
3418 spin_lock_irqsave(&sched->ibs_lock,
3423 rc = ib_poll_cq(conn->ibc_cq, 1, &wc);
3426 if (unlikely(rc > 0 && wc.wr_id == IBLND_WID_INVAL)) {
3428 "ib_poll_cq (rc: %d) returned invalid "
3429 "wr_id, opcode %d, status: %d, "
3430 "vendor_err: %d, conn: %s status: %d\n"
3431 "please upgrade firmware and OFED or "
3432 "contact vendor.\n", rc,
3433 wc.opcode, wc.status, wc.vendor_err,
3434 libcfs_nid2str(conn->ibc_peer->ibp_nid),
3440 CWARN("%s: ib_poll_cq failed: %d, "
3441 "closing connection\n",
3442 libcfs_nid2str(conn->ibc_peer->ibp_nid),
3444 kiblnd_close_conn(conn, -EIO);
3445 kiblnd_conn_decref(conn);
3446 spin_lock_irqsave(&sched->ibs_lock, flags);
3450 spin_lock_irqsave(&sched->ibs_lock, flags);
3452 if (rc != 0 || conn->ibc_ready) {
3453 /* There may be another completion waiting; get
3454 * another scheduler to check while I handle
3456 /* +1 ref for sched_conns */
3457 kiblnd_conn_addref(conn);
3458 list_add_tail(&conn->ibc_sched_list,
3460 if (waitqueue_active(&sched->ibs_waitq))
3461 wake_up(&sched->ibs_waitq);
3463 conn->ibc_scheduled = 0;
3467 spin_unlock_irqrestore(&sched->ibs_lock, flags);
3468 kiblnd_complete(&wc);
3470 spin_lock_irqsave(&sched->ibs_lock, flags);
3473 kiblnd_conn_decref(conn); /* ...drop my ref from above */
3480 set_current_state(TASK_INTERRUPTIBLE);
3481 add_wait_queue_exclusive(&sched->ibs_waitq, &wait);
3482 spin_unlock_irqrestore(&sched->ibs_lock, flags);
3487 remove_wait_queue(&sched->ibs_waitq, &wait);
3488 set_current_state(TASK_RUNNING);
3489 spin_lock_irqsave(&sched->ibs_lock, flags);
3492 spin_unlock_irqrestore(&sched->ibs_lock, flags);
3494 kiblnd_thread_fini();
3499 kiblnd_failover_thread(void *arg)
3501 rwlock_t *glock = &kiblnd_data.kib_global_lock;
3504 unsigned long flags;
3507 LASSERT(*kiblnd_tunables.kib_dev_failover != 0);
3509 cfs_block_allsigs();
3511 init_waitqueue_entry(&wait, current);
3512 write_lock_irqsave(glock, flags);
3514 while (!kiblnd_data.kib_shutdown) {
3515 int do_failover = 0;
3518 list_for_each_entry(dev, &kiblnd_data.kib_failed_devs,
3520 if (cfs_time_before(cfs_time_current(),
3521 dev->ibd_next_failover))
3528 list_del_init(&dev->ibd_fail_list);
3529 dev->ibd_failover = 1;
3530 write_unlock_irqrestore(glock, flags);
3532 rc = kiblnd_dev_failover(dev);
3534 write_lock_irqsave(glock, flags);
3536 LASSERT (dev->ibd_failover);
3537 dev->ibd_failover = 0;
3538 if (rc >= 0) { /* Device is OK or failover succeed */
3539 dev->ibd_next_failover = cfs_time_shift(3);
3543 /* failed to failover, retry later */
3544 dev->ibd_next_failover =
3545 cfs_time_shift(min(dev->ibd_failed_failover, 10));
3546 if (kiblnd_dev_can_failover(dev)) {
3547 list_add_tail(&dev->ibd_fail_list,
3548 &kiblnd_data.kib_failed_devs);
3554 /* long sleep if no more pending failover */
3555 long_sleep = list_empty(&kiblnd_data.kib_failed_devs);
3557 set_current_state(TASK_INTERRUPTIBLE);
3558 add_wait_queue(&kiblnd_data.kib_failover_waitq, &wait);
3559 write_unlock_irqrestore(glock, flags);
3561 rc = schedule_timeout(long_sleep ? cfs_time_seconds(10) :
3562 cfs_time_seconds(1));
3563 set_current_state(TASK_RUNNING);
3564 remove_wait_queue(&kiblnd_data.kib_failover_waitq, &wait);
3565 write_lock_irqsave(glock, flags);
3567 if (!long_sleep || rc != 0)
3570 /* have a long sleep, routine check all active devices,
3571 * we need checking like this because if there is not active
3572 * connection on the dev and no SEND from local, we may listen
3573 * on wrong HCA for ever while there is a bonding failover */
3574 list_for_each_entry(dev, &kiblnd_data.kib_devs, ibd_list) {
3575 if (kiblnd_dev_can_failover(dev)) {
3576 list_add_tail(&dev->ibd_fail_list,
3577 &kiblnd_data.kib_failed_devs);
3582 write_unlock_irqrestore(glock, flags);
3584 kiblnd_thread_fini();