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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lnet/klnds/o2iblnd/o2iblnd.c
33 * Author: Eric Barton <eric@bartonsoftware.com>
37 #include <linux/ethtool.h>
38 #include <linux/inetdevice.h>
42 static const struct lnet_lnd the_o2iblnd;
44 struct kib_data kiblnd_data;
47 kiblnd_cksum (void *ptr, int nob)
53 sum = ((sum << 1) | (sum >> 31)) + *c++;
55 /* ensure I don't return 0 (== no checksum) */
56 return (sum == 0) ? 1 : sum;
60 kiblnd_msgtype2str(int type)
63 case IBLND_MSG_CONNREQ:
66 case IBLND_MSG_CONNACK:
72 case IBLND_MSG_IMMEDIATE:
75 case IBLND_MSG_PUT_REQ:
78 case IBLND_MSG_PUT_NAK:
81 case IBLND_MSG_PUT_ACK:
84 case IBLND_MSG_PUT_DONE:
87 case IBLND_MSG_GET_REQ:
90 case IBLND_MSG_GET_DONE:
99 kiblnd_msgtype2size(int type)
101 const int hdr_size = offsetof(struct kib_msg, ibm_u);
104 case IBLND_MSG_CONNREQ:
105 case IBLND_MSG_CONNACK:
106 return hdr_size + sizeof(struct kib_connparams);
111 case IBLND_MSG_IMMEDIATE:
112 return offsetof(struct kib_msg, ibm_u.immediate.ibim_payload[0]);
114 case IBLND_MSG_PUT_REQ:
115 return hdr_size + sizeof(struct kib_putreq_msg);
117 case IBLND_MSG_PUT_ACK:
118 return hdr_size + sizeof(struct kib_putack_msg);
120 case IBLND_MSG_GET_REQ:
121 return hdr_size + sizeof(struct kib_get_msg);
123 case IBLND_MSG_PUT_NAK:
124 case IBLND_MSG_PUT_DONE:
125 case IBLND_MSG_GET_DONE:
126 return hdr_size + sizeof(struct kib_completion_msg);
132 static int kiblnd_unpack_rd(struct kib_msg *msg, bool flip)
134 struct kib_rdma_desc *rd;
139 LASSERT(msg->ibm_type == IBLND_MSG_GET_REQ ||
140 msg->ibm_type == IBLND_MSG_PUT_ACK);
142 rd = msg->ibm_type == IBLND_MSG_GET_REQ ?
143 &msg->ibm_u.get.ibgm_rd :
144 &msg->ibm_u.putack.ibpam_rd;
147 __swab32s(&rd->rd_key);
148 __swab32s(&rd->rd_nfrags);
153 if (n <= 0 || n > IBLND_MAX_RDMA_FRAGS) {
154 CERROR("Bad nfrags: %d, should be 0 < n <= %d\n",
155 n, IBLND_MAX_RDMA_FRAGS);
159 nob = offsetof(struct kib_msg, ibm_u) +
160 kiblnd_rd_msg_size(rd, msg->ibm_type, n);
162 if (msg->ibm_nob < nob) {
163 CERROR("Short %s: %d(%d)\n",
164 kiblnd_msgtype2str(msg->ibm_type), msg->ibm_nob, nob);
171 for (i = 0; i < n; i++) {
172 __swab32s(&rd->rd_frags[i].rf_nob);
173 __swab64s(&rd->rd_frags[i].rf_addr);
179 void kiblnd_pack_msg(struct lnet_ni *ni, struct kib_msg *msg, int version,
180 int credits, lnet_nid_t dstnid, __u64 dststamp)
182 struct kib_net *net = ni->ni_data;
184 /* CAVEAT EMPTOR! all message fields not set here should have been
185 * initialised previously.
187 msg->ibm_magic = IBLND_MSG_MAGIC;
188 msg->ibm_version = version;
190 msg->ibm_credits = credits;
193 msg->ibm_srcnid = lnet_nid_to_nid4(&ni->ni_nid);
194 msg->ibm_srcstamp = net->ibn_incarnation;
195 msg->ibm_dstnid = dstnid;
196 msg->ibm_dststamp = dststamp;
198 if (*kiblnd_tunables.kib_cksum) {
199 /* NB ibm_cksum zero while computing cksum */
200 msg->ibm_cksum = kiblnd_cksum(msg, msg->ibm_nob);
204 int kiblnd_unpack_msg(struct kib_msg *msg, int nob)
206 const int hdr_size = offsetof(struct kib_msg, ibm_u);
212 /* 6 bytes are enough to have received magic + version */
214 CERROR("Short message: %d\n", nob);
218 if (msg->ibm_magic == IBLND_MSG_MAGIC) {
220 } else if (msg->ibm_magic == __swab32(IBLND_MSG_MAGIC)) {
223 CERROR("Bad magic: %08x\n", msg->ibm_magic);
227 version = flip ? __swab16(msg->ibm_version) : msg->ibm_version;
228 if (version != IBLND_MSG_VERSION &&
229 version != IBLND_MSG_VERSION_1) {
230 CERROR("Bad version: %x\n", version);
234 if (nob < hdr_size) {
235 CERROR("Short message: %d\n", nob);
239 msg_nob = flip ? __swab32(msg->ibm_nob) : msg->ibm_nob;
241 CERROR("Short message: got %d, wanted %d\n", nob, msg_nob);
245 /* checksum must be computed with ibm_cksum zero and BEFORE anything
248 msg_cksum = flip ? __swab32(msg->ibm_cksum) : msg->ibm_cksum;
250 if (msg_cksum != 0 &&
251 msg_cksum != kiblnd_cksum(msg, msg_nob)) {
252 CERROR("Bad checksum\n");
256 msg->ibm_cksum = msg_cksum;
259 /* leave magic unflipped as a clue to peer_ni endianness */
260 msg->ibm_version = version;
261 BUILD_BUG_ON(sizeof(msg->ibm_type) != 1);
262 BUILD_BUG_ON(sizeof(msg->ibm_credits) != 1);
263 msg->ibm_nob = msg_nob;
264 __swab64s(&msg->ibm_srcnid);
265 __swab64s(&msg->ibm_srcstamp);
266 __swab64s(&msg->ibm_dstnid);
267 __swab64s(&msg->ibm_dststamp);
270 if (msg->ibm_srcnid == LNET_NID_ANY) {
271 CERROR("Bad src nid: %s\n", libcfs_nid2str(msg->ibm_srcnid));
275 if (msg_nob < kiblnd_msgtype2size(msg->ibm_type)) {
276 CERROR("Short %s: %d(%d)\n", kiblnd_msgtype2str(msg->ibm_type),
277 msg_nob, kiblnd_msgtype2size(msg->ibm_type));
281 switch (msg->ibm_type) {
283 CERROR("Unknown message type %x\n", msg->ibm_type);
287 case IBLND_MSG_IMMEDIATE:
288 case IBLND_MSG_PUT_REQ:
291 case IBLND_MSG_PUT_ACK:
292 case IBLND_MSG_GET_REQ:
293 if (kiblnd_unpack_rd(msg, flip))
297 case IBLND_MSG_PUT_NAK:
298 case IBLND_MSG_PUT_DONE:
299 case IBLND_MSG_GET_DONE:
301 __swab32s(&msg->ibm_u.completion.ibcm_status);
304 case IBLND_MSG_CONNREQ:
305 case IBLND_MSG_CONNACK:
307 __swab16s(&msg->ibm_u.connparams.ibcp_queue_depth);
308 __swab16s(&msg->ibm_u.connparams.ibcp_max_frags);
309 __swab32s(&msg->ibm_u.connparams.ibcp_max_msg_size);
317 kiblnd_create_peer(struct lnet_ni *ni, struct kib_peer_ni **peerp,
320 struct kib_peer_ni *peer_ni;
321 struct kib_net *net = ni->ni_data;
322 int cpt = lnet_cpt_of_nid(nid, ni);
325 LASSERT(net != NULL);
326 LASSERT(nid != LNET_NID_ANY);
328 LIBCFS_CPT_ALLOC(peer_ni, lnet_cpt_table(), cpt, sizeof(*peer_ni));
330 CERROR("Cannot allocate peer_ni\n");
334 peer_ni->ibp_ni = ni;
335 peer_ni->ibp_nid = nid;
336 peer_ni->ibp_error = 0;
337 peer_ni->ibp_last_alive = 0;
338 peer_ni->ibp_max_frags = IBLND_MAX_RDMA_FRAGS;
339 peer_ni->ibp_queue_depth = ni->ni_net->net_tunables.lct_peer_tx_credits;
340 peer_ni->ibp_queue_depth_mod = 0; /* try to use the default */
341 kref_init(&peer_ni->ibp_kref);
343 INIT_HLIST_NODE(&peer_ni->ibp_list);
344 INIT_LIST_HEAD(&peer_ni->ibp_conns);
345 INIT_LIST_HEAD(&peer_ni->ibp_tx_queue);
347 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
349 /* always called with a ref on ni, which prevents ni being shutdown */
350 LASSERT(net->ibn_shutdown == 0);
352 /* npeers only grows with the global lock held */
353 atomic_inc(&net->ibn_npeers);
355 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
362 kiblnd_destroy_peer(struct kref *kref)
364 struct kib_peer_ni *peer_ni = container_of(kref, struct kib_peer_ni,
366 struct kib_net *net = peer_ni->ibp_ni->ni_data;
368 LASSERT(net != NULL);
369 LASSERT(!kiblnd_peer_active(peer_ni));
370 LASSERT(kiblnd_peer_idle(peer_ni));
371 LASSERT(list_empty(&peer_ni->ibp_tx_queue));
373 LIBCFS_FREE(peer_ni, sizeof(*peer_ni));
375 /* NB a peer_ni's connections keep a reference on their peer_ni until
376 * they are destroyed, so we can be assured that _all_ state to do
377 * with this peer_ni has been cleaned up when its refcount drops to
380 if (atomic_dec_and_test(&net->ibn_npeers))
381 wake_up_var(&net->ibn_npeers);
385 kiblnd_find_peer_locked(struct lnet_ni *ni, lnet_nid_t nid)
387 /* the caller is responsible for accounting the additional reference
390 struct kib_peer_ni *peer_ni;
392 hash_for_each_possible(kiblnd_data.kib_peers, peer_ni,
394 LASSERT(!kiblnd_peer_idle(peer_ni));
397 * Match a peer if its NID and the NID of the local NI it
398 * communicates over are the same. Otherwise don't match
399 * the peer, which will result in a new lnd peer being
402 if (peer_ni->ibp_nid != nid ||
403 !nid_same(&peer_ni->ibp_ni->ni_nid, &ni->ni_nid))
406 CDEBUG(D_NET, "got peer_ni [%p] -> %s (%d) version: %x\n",
407 peer_ni, libcfs_nid2str(nid),
408 kref_read(&peer_ni->ibp_kref),
409 peer_ni->ibp_version);
416 kiblnd_unlink_peer_locked(struct kib_peer_ni *peer_ni)
418 LASSERT(list_empty(&peer_ni->ibp_conns));
420 LASSERT(kiblnd_peer_active(peer_ni));
421 hlist_del_init(&peer_ni->ibp_list);
422 /* lose peerlist's ref */
423 kiblnd_peer_decref(peer_ni);
427 kiblnd_get_peer_info(struct lnet_ni *ni, int index,
428 lnet_nid_t *nidp, int *count)
430 struct kib_peer_ni *peer_ni;
434 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
436 hash_for_each(kiblnd_data.kib_peers, i, peer_ni, ibp_list) {
437 LASSERT(!kiblnd_peer_idle(peer_ni));
439 if (peer_ni->ibp_ni != ni)
445 *nidp = peer_ni->ibp_nid;
446 *count = kref_read(&peer_ni->ibp_kref);
448 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
452 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
457 kiblnd_del_peer_locked(struct kib_peer_ni *peer_ni)
459 struct kib_conn *cnxt;
460 struct kib_conn *conn;
462 if (list_empty(&peer_ni->ibp_conns)) {
463 kiblnd_unlink_peer_locked(peer_ni);
465 list_for_each_entry_safe(conn, cnxt, &peer_ni->ibp_conns,
467 kiblnd_close_conn_locked(conn, 0);
468 /* NB closing peer_ni's last conn unlinked it. */
470 /* NB peer_ni now unlinked; might even be freed if the peer_ni table had the
475 kiblnd_del_peer(struct lnet_ni *ni, lnet_nid_t nid)
478 struct hlist_node *pnxt;
479 struct kib_peer_ni *peer_ni;
486 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
488 if (nid != LNET_NID_ANY) {
489 lo = hash_min(nid, HASH_BITS(kiblnd_data.kib_peers));
493 hi = HASH_SIZE(kiblnd_data.kib_peers) - 1;
496 for (i = lo; i <= hi; i++) {
497 hlist_for_each_entry_safe(peer_ni, pnxt,
498 &kiblnd_data.kib_peers[i], ibp_list) {
499 LASSERT(!kiblnd_peer_idle(peer_ni));
501 if (peer_ni->ibp_ni != ni)
504 if (!(nid == LNET_NID_ANY || peer_ni->ibp_nid == nid))
507 if (!list_empty(&peer_ni->ibp_tx_queue)) {
508 LASSERT(list_empty(&peer_ni->ibp_conns));
510 list_splice_init(&peer_ni->ibp_tx_queue,
514 kiblnd_del_peer_locked(peer_ni);
515 rc = 0; /* matched something */
519 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
521 kiblnd_txlist_done(&zombies, -EIO, LNET_MSG_STATUS_LOCAL_ERROR);
526 static struct kib_conn *
527 kiblnd_get_conn_by_idx(struct lnet_ni *ni, int index)
529 struct kib_peer_ni *peer_ni;
530 struct kib_conn *conn;
534 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
536 hash_for_each(kiblnd_data.kib_peers, i, peer_ni, ibp_list) {
537 LASSERT(!kiblnd_peer_idle(peer_ni));
539 if (peer_ni->ibp_ni != ni)
542 list_for_each_entry(conn, &peer_ni->ibp_conns,
547 kiblnd_conn_addref(conn);
548 read_unlock_irqrestore(&kiblnd_data.kib_global_lock,
554 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
559 kiblnd_debug_rx(struct kib_rx *rx)
561 CDEBUG(D_CONSOLE, " %p msg_type %x cred %d\n",
562 rx, rx->rx_msg->ibm_type,
563 rx->rx_msg->ibm_credits);
567 kiblnd_debug_tx(struct kib_tx *tx)
569 CDEBUG(D_CONSOLE, " %p snd %d q %d w %d rc %d dl %lld "
570 "cookie %#llx msg %s%s type %x cred %d\n",
571 tx, tx->tx_sending, tx->tx_queued, tx->tx_waiting,
572 tx->tx_status, ktime_to_ns(tx->tx_deadline), tx->tx_cookie,
573 tx->tx_lntmsg[0] == NULL ? "-" : "!",
574 tx->tx_lntmsg[1] == NULL ? "-" : "!",
575 tx->tx_msg->ibm_type, tx->tx_msg->ibm_credits);
579 kiblnd_debug_conn(struct kib_conn *conn)
581 struct list_head *tmp;
584 spin_lock(&conn->ibc_lock);
586 CDEBUG(D_CONSOLE, "conn[%d] %p [version %x] -> %s:\n",
587 atomic_read(&conn->ibc_refcount), conn,
588 conn->ibc_version, libcfs_nid2str(conn->ibc_peer->ibp_nid));
589 CDEBUG(D_CONSOLE, " state %d nposted %d/%d cred %d o_cred %d "
590 " r_cred %d\n", conn->ibc_state, conn->ibc_noops_posted,
591 conn->ibc_nsends_posted, conn->ibc_credits,
592 conn->ibc_outstanding_credits, conn->ibc_reserved_credits);
593 CDEBUG(D_CONSOLE, " comms_err %d\n", conn->ibc_comms_error);
595 CDEBUG(D_CONSOLE, " early_rxs:\n");
596 list_for_each(tmp, &conn->ibc_early_rxs)
597 kiblnd_debug_rx(list_entry(tmp, struct kib_rx, rx_list));
599 CDEBUG(D_CONSOLE, " tx_noops:\n");
600 list_for_each(tmp, &conn->ibc_tx_noops)
601 kiblnd_debug_tx(list_entry(tmp, struct kib_tx, tx_list));
603 CDEBUG(D_CONSOLE, " tx_queue_nocred:\n");
604 list_for_each(tmp, &conn->ibc_tx_queue_nocred)
605 kiblnd_debug_tx(list_entry(tmp, struct kib_tx, tx_list));
607 CDEBUG(D_CONSOLE, " tx_queue_rsrvd:\n");
608 list_for_each(tmp, &conn->ibc_tx_queue_rsrvd)
609 kiblnd_debug_tx(list_entry(tmp, struct kib_tx, tx_list));
611 CDEBUG(D_CONSOLE, " tx_queue:\n");
612 list_for_each(tmp, &conn->ibc_tx_queue)
613 kiblnd_debug_tx(list_entry(tmp, struct kib_tx, tx_list));
615 CDEBUG(D_CONSOLE, " active_txs:\n");
616 list_for_each(tmp, &conn->ibc_active_txs)
617 kiblnd_debug_tx(list_entry(tmp, struct kib_tx, tx_list));
619 CDEBUG(D_CONSOLE, " rxs:\n");
620 for (i = 0; i < IBLND_RX_MSGS(conn); i++)
621 kiblnd_debug_rx(&conn->ibc_rxs[i]);
623 spin_unlock(&conn->ibc_lock);
627 kiblnd_setup_mtu_locked(struct rdma_cm_id *cmid)
629 /* XXX There is no path record for iWARP, set by netdev->change_mtu? */
630 if (cmid->route.path_rec == NULL)
633 if (*kiblnd_tunables.kib_ib_mtu)
634 cmid->route.path_rec->mtu =
635 ib_mtu_int_to_enum(*kiblnd_tunables.kib_ib_mtu);
639 kiblnd_get_completion_vector(struct kib_conn *conn, int cpt)
647 vectors = conn->ibc_cmid->device->num_comp_vectors;
651 mask = cfs_cpt_cpumask(lnet_cpt_table(), cpt);
653 /* hash NID to CPU id in this partition... */
654 ibp_nid = conn->ibc_peer->ibp_nid;
655 off = do_div(ibp_nid, cpumask_weight(*mask));
656 for_each_cpu(i, *mask) {
666 * Get the scheduler bound to this CPT. If the scheduler has no
667 * threads, which means that the CPT has no CPUs, then grab the
668 * next scheduler that we can use.
670 * This case would be triggered if a NUMA node is configured with
671 * no associated CPUs.
673 static struct kib_sched_info *
674 kiblnd_get_scheduler(int cpt)
676 struct kib_sched_info *sched;
679 sched = kiblnd_data.kib_scheds[cpt];
681 if (sched->ibs_nthreads > 0)
684 cfs_percpt_for_each(sched, i, kiblnd_data.kib_scheds) {
685 if (sched->ibs_nthreads > 0) {
686 CDEBUG(D_NET, "scheduler[%d] has no threads. selected scheduler[%d]\n",
687 cpt, sched->ibs_cpt);
695 static unsigned int kiblnd_send_wrs(struct kib_conn *conn)
698 * One WR for the LNet message
699 * And ibc_max_frags for the transfer WRs
702 int multiplier = 1 + conn->ibc_max_frags;
704 /* FastReg needs two extra WRs for map and invalidate */
705 if (IS_FAST_REG_DEV(conn->ibc_hdev->ibh_dev))
708 /* account for a maximum of ibc_queue_depth in-flight transfers */
709 ret = multiplier * conn->ibc_queue_depth;
711 if (ret > conn->ibc_hdev->ibh_max_qp_wr) {
712 CDEBUG(D_NET, "peer_credits %u will result in send work "
713 "request size %d larger than maximum %d device "
714 "can handle\n", conn->ibc_queue_depth, ret,
715 conn->ibc_hdev->ibh_max_qp_wr);
716 conn->ibc_queue_depth =
717 conn->ibc_hdev->ibh_max_qp_wr / multiplier;
720 /* don't go beyond the maximum the device can handle */
721 return min(ret, conn->ibc_hdev->ibh_max_qp_wr);
725 kiblnd_create_conn(struct kib_peer_ni *peer_ni, struct rdma_cm_id *cmid,
726 int state, int version)
729 * If the new conn is created successfully it takes over the caller's
730 * ref on 'peer_ni'. It also "owns" 'cmid' and destroys it when it itself
731 * is destroyed. On failure, the caller's ref on 'peer_ni' remains and
732 * she must dispose of 'cmid'. (Actually I'd block forever if I tried
733 * to destroy 'cmid' here since I'm called from the CM which still has
734 * its ref on 'cmid'). */
735 rwlock_t *glock = &kiblnd_data.kib_global_lock;
736 struct kib_net *net = peer_ni->ibp_ni->ni_data;
738 struct ib_qp_init_attr init_qp_attr = {};
739 struct kib_sched_info *sched;
740 #ifdef HAVE_IB_CQ_INIT_ATTR
741 struct ib_cq_init_attr cq_attr = {};
743 struct kib_conn *conn;
750 LASSERT(net != NULL);
751 LASSERT(!in_interrupt());
755 cpt = lnet_cpt_of_nid(peer_ni->ibp_nid, peer_ni->ibp_ni);
756 sched = kiblnd_get_scheduler(cpt);
759 CERROR("no schedulers available. node is unhealthy\n");
764 * The cpt might have changed if we ended up selecting a non cpt
765 * native scheduler. So use the scheduler's cpt instead.
767 cpt = sched->ibs_cpt;
769 LIBCFS_CPT_ALLOC(conn, lnet_cpt_table(), cpt, sizeof(*conn));
771 CERROR("Can't allocate connection for %s\n",
772 libcfs_nid2str(peer_ni->ibp_nid));
776 conn->ibc_state = IBLND_CONN_INIT;
777 conn->ibc_version = version;
778 conn->ibc_peer = peer_ni; /* I take the caller's ref */
779 cmid->context = conn; /* for future CM callbacks */
780 conn->ibc_cmid = cmid;
781 conn->ibc_max_frags = peer_ni->ibp_max_frags;
782 conn->ibc_queue_depth = peer_ni->ibp_queue_depth;
783 conn->ibc_rxs = NULL;
784 conn->ibc_rx_pages = NULL;
786 INIT_LIST_HEAD(&conn->ibc_early_rxs);
787 INIT_LIST_HEAD(&conn->ibc_tx_noops);
788 INIT_LIST_HEAD(&conn->ibc_tx_queue);
789 INIT_LIST_HEAD(&conn->ibc_tx_queue_rsrvd);
790 INIT_LIST_HEAD(&conn->ibc_tx_queue_nocred);
791 INIT_LIST_HEAD(&conn->ibc_active_txs);
792 INIT_LIST_HEAD(&conn->ibc_zombie_txs);
793 spin_lock_init(&conn->ibc_lock);
795 LIBCFS_CPT_ALLOC(conn->ibc_connvars, lnet_cpt_table(), cpt,
796 sizeof(*conn->ibc_connvars));
797 if (conn->ibc_connvars == NULL) {
798 CERROR("Can't allocate in-progress connection state\n");
802 write_lock_irqsave(glock, flags);
803 if (dev->ibd_failover) {
804 write_unlock_irqrestore(glock, flags);
805 CERROR("%s: failover in progress\n", dev->ibd_ifname);
809 if (dev->ibd_hdev->ibh_ibdev != cmid->device) {
810 /* wakeup failover thread and teardown connection */
811 if (kiblnd_dev_can_failover(dev)) {
812 list_add_tail(&dev->ibd_fail_list,
813 &kiblnd_data.kib_failed_devs);
814 wake_up(&kiblnd_data.kib_failover_waitq);
817 write_unlock_irqrestore(glock, flags);
818 CERROR("cmid HCA(%s), kib_dev(%s) need failover\n",
819 cmid->device->name, dev->ibd_ifname);
823 kiblnd_hdev_addref_locked(dev->ibd_hdev);
824 conn->ibc_hdev = dev->ibd_hdev;
826 kiblnd_setup_mtu_locked(cmid);
828 write_unlock_irqrestore(glock, flags);
830 #ifdef HAVE_IB_CQ_INIT_ATTR
831 cq_attr.cqe = IBLND_CQ_ENTRIES(conn);
832 cq_attr.comp_vector = kiblnd_get_completion_vector(conn, cpt);
833 cq = ib_create_cq(cmid->device,
834 kiblnd_cq_completion, kiblnd_cq_event, conn,
837 cq = ib_create_cq(cmid->device,
838 kiblnd_cq_completion, kiblnd_cq_event, conn,
839 IBLND_CQ_ENTRIES(conn),
840 kiblnd_get_completion_vector(conn, cpt));
844 * on MLX-5 (possibly MLX-4 as well) this error could be
845 * hit if the concurrent_sends and/or peer_tx_credits is set
846 * too high. Or due to an MLX-5 bug which tries to
847 * allocate 256kb via kmalloc for WR cookie array
849 CERROR("Failed to create CQ with %d CQEs: %ld\n",
850 IBLND_CQ_ENTRIES(conn), PTR_ERR(cq));
856 rc = ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
858 CERROR("Can't request completion notification: %d\n", rc);
862 init_qp_attr.event_handler = kiblnd_qp_event;
863 init_qp_attr.qp_context = conn;
864 init_qp_attr.cap.max_send_sge = *kiblnd_tunables.kib_wrq_sge;
865 init_qp_attr.cap.max_recv_sge = 1;
866 init_qp_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
867 init_qp_attr.qp_type = IB_QPT_RC;
868 init_qp_attr.send_cq = cq;
869 init_qp_attr.recv_cq = cq;
871 if (peer_ni->ibp_queue_depth_mod &&
872 peer_ni->ibp_queue_depth_mod < peer_ni->ibp_queue_depth) {
873 conn->ibc_queue_depth = peer_ni->ibp_queue_depth_mod;
874 CDEBUG(D_NET, "Use reduced queue depth %u (from %u)\n",
875 peer_ni->ibp_queue_depth_mod,
876 peer_ni->ibp_queue_depth);
880 /* kiblnd_send_wrs() can change the connection's queue depth if
881 * the maximum work requests for the device is maxed out
883 init_qp_attr.cap.max_send_wr = kiblnd_send_wrs(conn);
884 init_qp_attr.cap.max_recv_wr = IBLND_RECV_WRS(conn);
885 rc = rdma_create_qp(cmid, conn->ibc_hdev->ibh_pd,
887 if (rc != -ENOMEM || conn->ibc_queue_depth < 2)
889 conn->ibc_queue_depth--;
893 CERROR("Can't create QP: %d, send_wr: %d, recv_wr: %d, "
894 "send_sge: %d, recv_sge: %d\n",
895 rc, init_qp_attr.cap.max_send_wr,
896 init_qp_attr.cap.max_recv_wr,
897 init_qp_attr.cap.max_send_sge,
898 init_qp_attr.cap.max_recv_sge);
902 conn->ibc_sched = sched;
904 if (!peer_ni->ibp_queue_depth_mod &&
905 conn->ibc_queue_depth != peer_ni->ibp_queue_depth) {
906 CWARN("peer %s - queue depth reduced from %u to %u"
907 " to allow for qp creation\n",
908 libcfs_nid2str(peer_ni->ibp_nid),
909 peer_ni->ibp_queue_depth,
910 conn->ibc_queue_depth);
911 peer_ni->ibp_queue_depth_mod = conn->ibc_queue_depth;
914 LIBCFS_CPT_ALLOC(conn->ibc_rxs, lnet_cpt_table(), cpt,
915 IBLND_RX_MSGS(conn) * sizeof(struct kib_rx));
916 if (conn->ibc_rxs == NULL) {
917 CERROR("Cannot allocate RX buffers\n");
921 rc = kiblnd_alloc_pages(&conn->ibc_rx_pages, cpt,
922 IBLND_RX_MSG_PAGES(conn));
926 kiblnd_map_rx_descs(conn);
928 /* 1 ref for caller and each rxmsg */
929 atomic_set(&conn->ibc_refcount, 1 + IBLND_RX_MSGS(conn));
930 conn->ibc_nrx = IBLND_RX_MSGS(conn);
933 for (i = 0; i < IBLND_RX_MSGS(conn); i++) {
934 rc = kiblnd_post_rx(&conn->ibc_rxs[i], IBLND_POSTRX_NO_CREDIT);
936 CERROR("Can't post rxmsg: %d\n", rc);
938 /* Make posted receives complete */
939 kiblnd_abort_receives(conn);
941 /* correct # of posted buffers
942 * NB locking needed now I'm racing with completion */
943 spin_lock_irqsave(&sched->ibs_lock, flags);
944 conn->ibc_nrx -= IBLND_RX_MSGS(conn) - i;
945 spin_unlock_irqrestore(&sched->ibs_lock, flags);
947 /* cmid will be destroyed by CM(ofed) after cm_callback
948 * returned, so we can't refer it anymore
949 * (by kiblnd_connd()->kiblnd_destroy_conn) */
950 rdma_destroy_qp(conn->ibc_cmid);
951 conn->ibc_cmid = NULL;
953 /* Drop my own and unused rxbuffer refcounts */
954 while (i++ <= IBLND_RX_MSGS(conn))
955 kiblnd_conn_decref(conn);
961 /* Init successful! */
962 LASSERT (state == IBLND_CONN_ACTIVE_CONNECT ||
963 state == IBLND_CONN_PASSIVE_WAIT);
964 conn->ibc_state = state;
967 atomic_inc(&net->ibn_nconns);
971 kiblnd_destroy_conn(conn);
972 LIBCFS_FREE(conn, sizeof(*conn));
978 kiblnd_destroy_conn(struct kib_conn *conn)
980 struct rdma_cm_id *cmid = conn->ibc_cmid;
981 struct kib_peer_ni *peer_ni = conn->ibc_peer;
983 LASSERT (!in_interrupt());
984 LASSERT (atomic_read(&conn->ibc_refcount) == 0);
985 LASSERT(list_empty(&conn->ibc_early_rxs));
986 LASSERT(list_empty(&conn->ibc_tx_noops));
987 LASSERT(list_empty(&conn->ibc_tx_queue));
988 LASSERT(list_empty(&conn->ibc_tx_queue_rsrvd));
989 LASSERT(list_empty(&conn->ibc_tx_queue_nocred));
990 LASSERT(list_empty(&conn->ibc_active_txs));
991 LASSERT (conn->ibc_noops_posted == 0);
992 LASSERT (conn->ibc_nsends_posted == 0);
994 switch (conn->ibc_state) {
996 /* conn must be completely disengaged from the network */
999 case IBLND_CONN_DISCONNECTED:
1000 /* connvars should have been freed already */
1001 LASSERT (conn->ibc_connvars == NULL);
1004 case IBLND_CONN_INIT:
1008 /* conn->ibc_cmid might be destroyed by CM already */
1009 if (cmid != NULL && cmid->qp != NULL)
1010 rdma_destroy_qp(cmid);
1013 ib_destroy_cq(conn->ibc_cq);
1015 kiblnd_txlist_done(&conn->ibc_zombie_txs, -ECONNABORTED,
1016 LNET_MSG_STATUS_OK);
1018 if (conn->ibc_rx_pages != NULL)
1019 kiblnd_unmap_rx_descs(conn);
1021 if (conn->ibc_rxs != NULL)
1022 CFS_FREE_PTR_ARRAY(conn->ibc_rxs, IBLND_RX_MSGS(conn));
1024 if (conn->ibc_connvars != NULL)
1025 LIBCFS_FREE(conn->ibc_connvars, sizeof(*conn->ibc_connvars));
1027 if (conn->ibc_hdev != NULL)
1028 kiblnd_hdev_decref(conn->ibc_hdev);
1030 /* See CAVEAT EMPTOR above in kiblnd_create_conn */
1031 if (conn->ibc_state != IBLND_CONN_INIT) {
1032 struct kib_net *net = peer_ni->ibp_ni->ni_data;
1034 kiblnd_peer_decref(peer_ni);
1035 rdma_destroy_id(cmid);
1036 atomic_dec(&net->ibn_nconns);
1041 kiblnd_close_peer_conns_locked(struct kib_peer_ni *peer_ni, int why)
1043 struct kib_conn *conn;
1044 struct kib_conn *cnxt;
1047 list_for_each_entry_safe(conn, cnxt, &peer_ni->ibp_conns,
1049 CDEBUG(D_NET, "Closing conn -> %s, "
1050 "version: %x, reason: %d\n",
1051 libcfs_nid2str(peer_ni->ibp_nid),
1052 conn->ibc_version, why);
1054 kiblnd_close_conn_locked(conn, why);
1062 kiblnd_close_stale_conns_locked(struct kib_peer_ni *peer_ni,
1063 int version, __u64 incarnation)
1065 struct kib_conn *conn;
1066 struct kib_conn *cnxt;
1069 list_for_each_entry_safe(conn, cnxt, &peer_ni->ibp_conns,
1071 if (conn->ibc_version == version &&
1072 conn->ibc_incarnation == incarnation)
1075 CDEBUG(D_NET, "Closing stale conn -> %s version: %x, "
1076 "incarnation:%#llx(%x, %#llx)\n",
1077 libcfs_nid2str(peer_ni->ibp_nid),
1078 conn->ibc_version, conn->ibc_incarnation,
1079 version, incarnation);
1081 kiblnd_close_conn_locked(conn, -ESTALE);
1089 kiblnd_close_matching_conns(struct lnet_ni *ni, lnet_nid_t nid)
1091 struct kib_peer_ni *peer_ni;
1092 struct hlist_node *pnxt;
1096 unsigned long flags;
1099 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
1101 if (nid != LNET_NID_ANY) {
1102 lo = hash_min(nid, HASH_BITS(kiblnd_data.kib_peers));
1106 hi = HASH_SIZE(kiblnd_data.kib_peers) - 1;
1109 for (i = lo; i <= hi; i++) {
1110 hlist_for_each_entry_safe(peer_ni, pnxt,
1111 &kiblnd_data.kib_peers[i], ibp_list) {
1112 LASSERT(!kiblnd_peer_idle(peer_ni));
1114 if (peer_ni->ibp_ni != ni)
1117 if (!(nid == LNET_NID_ANY || nid == peer_ni->ibp_nid))
1120 count += kiblnd_close_peer_conns_locked(peer_ni, 0);
1124 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
1126 /* wildcards always succeed */
1127 if (nid == LNET_NID_ANY)
1130 return (count == 0) ? -ENOENT : 0;
1134 kiblnd_ctl(struct lnet_ni *ni, unsigned int cmd, void *arg)
1136 struct libcfs_ioctl_data *data = arg;
1140 case IOC_LIBCFS_GET_PEER: {
1144 rc = kiblnd_get_peer_info(ni, data->ioc_count,
1146 data->ioc_nid = nid;
1147 data->ioc_count = count;
1151 case IOC_LIBCFS_DEL_PEER: {
1152 rc = kiblnd_del_peer(ni, data->ioc_nid);
1155 case IOC_LIBCFS_GET_CONN: {
1156 struct kib_conn *conn;
1159 conn = kiblnd_get_conn_by_idx(ni, data->ioc_count);
1165 LASSERT(conn->ibc_cmid != NULL);
1166 data->ioc_nid = conn->ibc_peer->ibp_nid;
1167 if (conn->ibc_cmid->route.path_rec == NULL)
1168 data->ioc_u32[0] = 0; /* iWarp has no path MTU */
1171 ib_mtu_enum_to_int(conn->ibc_cmid->route.path_rec->mtu);
1172 kiblnd_conn_decref(conn);
1175 case IOC_LIBCFS_CLOSE_CONNECTION: {
1176 rc = kiblnd_close_matching_conns(ni, data->ioc_nid);
1188 kiblnd_free_pages(struct kib_pages *p)
1190 int npages = p->ibp_npages;
1193 for (i = 0; i < npages; i++) {
1194 if (p->ibp_pages[i] != NULL)
1195 __free_page(p->ibp_pages[i]);
1198 LIBCFS_FREE(p, offsetof(struct kib_pages, ibp_pages[npages]));
1202 kiblnd_alloc_pages(struct kib_pages **pp, int cpt, int npages)
1204 struct kib_pages *p;
1207 LIBCFS_CPT_ALLOC(p, lnet_cpt_table(), cpt,
1208 offsetof(struct kib_pages, ibp_pages[npages]));
1210 CERROR("Can't allocate descriptor for %d pages\n", npages);
1214 memset(p, 0, offsetof(struct kib_pages, ibp_pages[npages]));
1215 p->ibp_npages = npages;
1217 for (i = 0; i < npages; i++) {
1218 p->ibp_pages[i] = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1220 if (p->ibp_pages[i] == NULL) {
1221 CERROR("Can't allocate page %d of %d\n", i, npages);
1222 kiblnd_free_pages(p);
1232 kiblnd_unmap_rx_descs(struct kib_conn *conn)
1237 LASSERT (conn->ibc_rxs != NULL);
1238 LASSERT (conn->ibc_hdev != NULL);
1240 for (i = 0; i < IBLND_RX_MSGS(conn); i++) {
1241 rx = &conn->ibc_rxs[i];
1243 LASSERT(rx->rx_nob >= 0); /* not posted */
1245 kiblnd_dma_unmap_single(conn->ibc_hdev->ibh_ibdev,
1246 KIBLND_UNMAP_ADDR(rx, rx_msgunmap,
1248 IBLND_MSG_SIZE, DMA_FROM_DEVICE);
1251 kiblnd_free_pages(conn->ibc_rx_pages);
1253 conn->ibc_rx_pages = NULL;
1257 kiblnd_map_rx_descs(struct kib_conn *conn)
1265 for (pg_off = ipg = i = 0; i < IBLND_RX_MSGS(conn); i++) {
1266 pg = conn->ibc_rx_pages->ibp_pages[ipg];
1267 rx = &conn->ibc_rxs[i];
1270 rx->rx_msg = (struct kib_msg *)(((char *)page_address(pg)) + pg_off);
1273 kiblnd_dma_map_single(conn->ibc_hdev->ibh_ibdev,
1274 rx->rx_msg, IBLND_MSG_SIZE,
1276 LASSERT(!kiblnd_dma_mapping_error(conn->ibc_hdev->ibh_ibdev,
1278 KIBLND_UNMAP_ADDR_SET(rx, rx_msgunmap, rx->rx_msgaddr);
1280 CDEBUG(D_NET, "rx %d: %p %#llx(%#llx)\n",
1281 i, rx->rx_msg, rx->rx_msgaddr,
1282 (__u64)(page_to_phys(pg) + pg_off));
1284 pg_off += IBLND_MSG_SIZE;
1285 LASSERT(pg_off <= PAGE_SIZE);
1287 if (pg_off == PAGE_SIZE) {
1290 LASSERT(ipg <= IBLND_RX_MSG_PAGES(conn));
1296 kiblnd_unmap_tx_pool(struct kib_tx_pool *tpo)
1298 struct kib_hca_dev *hdev = tpo->tpo_hdev;
1302 LASSERT (tpo->tpo_pool.po_allocated == 0);
1307 for (i = 0; i < tpo->tpo_pool.po_size; i++) {
1308 tx = &tpo->tpo_tx_descs[i];
1309 kiblnd_dma_unmap_single(hdev->ibh_ibdev,
1310 KIBLND_UNMAP_ADDR(tx, tx_msgunmap,
1312 IBLND_MSG_SIZE, DMA_TO_DEVICE);
1315 kiblnd_hdev_decref(hdev);
1316 tpo->tpo_hdev = NULL;
1319 static struct kib_hca_dev *
1320 kiblnd_current_hdev(struct kib_dev *dev)
1322 struct kib_hca_dev *hdev;
1323 unsigned long flags;
1326 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
1327 while (dev->ibd_failover) {
1328 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
1330 CDEBUG(D_NET, "%s: Wait for failover\n",
1332 schedule_timeout_interruptible(cfs_time_seconds(1) / 100);
1334 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
1337 kiblnd_hdev_addref_locked(dev->ibd_hdev);
1338 hdev = dev->ibd_hdev;
1340 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
1346 kiblnd_map_tx_pool(struct kib_tx_pool *tpo)
1348 struct kib_pages *txpgs = tpo->tpo_tx_pages;
1349 struct kib_pool *pool = &tpo->tpo_pool;
1350 struct kib_net *net = pool->po_owner->ps_net;
1351 struct kib_dev *dev;
1358 LASSERT (net != NULL);
1362 /* pre-mapped messages are not bigger than 1 page */
1363 BUILD_BUG_ON(IBLND_MSG_SIZE > PAGE_SIZE);
1365 /* No fancy arithmetic when we do the buffer calculations */
1366 BUILD_BUG_ON(PAGE_SIZE % IBLND_MSG_SIZE != 0);
1368 tpo->tpo_hdev = kiblnd_current_hdev(dev);
1370 for (ipage = page_offset = i = 0; i < pool->po_size; i++) {
1371 page = txpgs->ibp_pages[ipage];
1372 tx = &tpo->tpo_tx_descs[i];
1374 tx->tx_msg = (struct kib_msg *)(((char *)page_address(page)) +
1377 tx->tx_msgaddr = kiblnd_dma_map_single(tpo->tpo_hdev->ibh_ibdev,
1381 LASSERT(!kiblnd_dma_mapping_error(tpo->tpo_hdev->ibh_ibdev,
1383 KIBLND_UNMAP_ADDR_SET(tx, tx_msgunmap, tx->tx_msgaddr);
1385 list_add(&tx->tx_list, &pool->po_free_list);
1387 page_offset += IBLND_MSG_SIZE;
1388 LASSERT(page_offset <= PAGE_SIZE);
1390 if (page_offset == PAGE_SIZE) {
1393 LASSERT(ipage <= txpgs->ibp_npages);
1399 kiblnd_destroy_fmr_pool(struct kib_fmr_pool *fpo)
1401 LASSERT(fpo->fpo_map_count == 0);
1403 #ifdef HAVE_FMR_POOL_API
1404 if (fpo->fpo_is_fmr && fpo->fmr.fpo_fmr_pool) {
1405 ib_destroy_fmr_pool(fpo->fmr.fpo_fmr_pool);
1407 #endif /* HAVE_FMR_POOL_API */
1409 struct kib_fast_reg_descriptor *frd, *tmp;
1412 list_for_each_entry_safe(frd, tmp, &fpo->fast_reg.fpo_pool_list,
1414 list_del(&frd->frd_list);
1415 #ifndef HAVE_IB_MAP_MR_SG
1416 ib_free_fast_reg_page_list(frd->frd_frpl);
1418 ib_dereg_mr(frd->frd_mr);
1419 LIBCFS_FREE(frd, sizeof(*frd));
1422 if (i < fpo->fast_reg.fpo_pool_size)
1423 CERROR("FastReg pool still has %d regions registered\n",
1424 fpo->fast_reg.fpo_pool_size - i);
1428 kiblnd_hdev_decref(fpo->fpo_hdev);
1430 LIBCFS_FREE(fpo, sizeof(*fpo));
1434 kiblnd_destroy_fmr_pool_list(struct list_head *head)
1436 struct kib_fmr_pool *fpo, *tmp;
1438 list_for_each_entry_safe(fpo, tmp, head, fpo_list) {
1439 list_del(&fpo->fpo_list);
1440 kiblnd_destroy_fmr_pool(fpo);
1445 kiblnd_fmr_pool_size(struct lnet_ioctl_config_o2iblnd_tunables *tunables,
1448 int size = tunables->lnd_fmr_pool_size / ncpts;
1450 return max(IBLND_FMR_POOL, size);
1454 kiblnd_fmr_flush_trigger(struct lnet_ioctl_config_o2iblnd_tunables *tunables,
1457 int size = tunables->lnd_fmr_flush_trigger / ncpts;
1459 return max(IBLND_FMR_POOL_FLUSH, size);
1462 #ifdef HAVE_FMR_POOL_API
1463 static int kiblnd_alloc_fmr_pool(struct kib_fmr_poolset *fps,
1464 struct kib_fmr_pool *fpo)
1466 struct ib_fmr_pool_param param = {
1467 .max_pages_per_fmr = IBLND_MAX_RDMA_FRAGS,
1468 .page_shift = PAGE_SHIFT,
1469 .access = (IB_ACCESS_LOCAL_WRITE |
1470 IB_ACCESS_REMOTE_WRITE),
1471 .pool_size = fps->fps_pool_size,
1472 .dirty_watermark = fps->fps_flush_trigger,
1473 .flush_function = NULL,
1475 .cache = !!fps->fps_cache };
1478 fpo->fmr.fpo_fmr_pool = ib_create_fmr_pool(fpo->fpo_hdev->ibh_pd,
1480 if (IS_ERR(fpo->fmr.fpo_fmr_pool)) {
1481 rc = PTR_ERR(fpo->fmr.fpo_fmr_pool);
1483 CERROR("Failed to create FMR pool: %d\n", rc);
1485 CERROR("FMRs are not supported\n");
1487 fpo->fpo_is_fmr = true;
1491 #endif /* HAVE_FMR_POOL_API */
1493 static int kiblnd_alloc_freg_pool(struct kib_fmr_poolset *fps,
1494 struct kib_fmr_pool *fpo,
1495 enum kib_dev_caps dev_caps)
1497 struct kib_fast_reg_descriptor *frd, *tmp;
1500 #ifdef HAVE_FMR_POOL_API
1501 fpo->fpo_is_fmr = false;
1504 INIT_LIST_HEAD(&fpo->fast_reg.fpo_pool_list);
1505 fpo->fast_reg.fpo_pool_size = 0;
1506 for (i = 0; i < fps->fps_pool_size; i++) {
1507 LIBCFS_CPT_ALLOC(frd, lnet_cpt_table(), fps->fps_cpt,
1510 CERROR("Failed to allocate a new fast_reg descriptor\n");
1516 #ifndef HAVE_IB_MAP_MR_SG
1517 frd->frd_frpl = ib_alloc_fast_reg_page_list(fpo->fpo_hdev->ibh_ibdev,
1518 IBLND_MAX_RDMA_FRAGS);
1519 if (IS_ERR(frd->frd_frpl)) {
1520 rc = PTR_ERR(frd->frd_frpl);
1521 CERROR("Failed to allocate ib_fast_reg_page_list: %d\n",
1523 frd->frd_frpl = NULL;
1528 #ifdef HAVE_IB_ALLOC_FAST_REG_MR
1529 frd->frd_mr = ib_alloc_fast_reg_mr(fpo->fpo_hdev->ibh_pd,
1530 IBLND_MAX_RDMA_FRAGS);
1533 * it is expected to get here if this is an MLX-5 card.
1534 * MLX-4 cards will always use FMR and MLX-5 cards will
1535 * always use fast_reg. It turns out that some MLX-5 cards
1536 * (possibly due to older FW versions) do not natively support
1537 * gaps. So we will need to track them here.
1539 frd->frd_mr = ib_alloc_mr(fpo->fpo_hdev->ibh_pd,
1540 #ifdef IB_MR_TYPE_SG_GAPS
1541 ((*kiblnd_tunables.kib_use_fastreg_gaps == 1) &&
1542 (dev_caps & IBLND_DEV_CAPS_FASTREG_GAPS_SUPPORT)) ?
1543 IB_MR_TYPE_SG_GAPS :
1548 IBLND_MAX_RDMA_FRAGS);
1549 if ((*kiblnd_tunables.kib_use_fastreg_gaps == 1) &&
1550 (dev_caps & IBLND_DEV_CAPS_FASTREG_GAPS_SUPPORT))
1551 CWARN("using IB_MR_TYPE_SG_GAPS, expect a performance drop\n");
1553 if (IS_ERR(frd->frd_mr)) {
1554 rc = PTR_ERR(frd->frd_mr);
1555 CERROR("Failed to allocate ib_fast_reg_mr: %d\n", rc);
1560 /* There appears to be a bug in MLX5 code where you must
1561 * invalidate the rkey of a new FastReg pool before first
1562 * using it. Thus, I am marking the FRD invalid here. */
1563 frd->frd_valid = false;
1565 list_add_tail(&frd->frd_list, &fpo->fast_reg.fpo_pool_list);
1566 fpo->fast_reg.fpo_pool_size++;
1573 ib_dereg_mr(frd->frd_mr);
1574 #ifndef HAVE_IB_MAP_MR_SG
1576 ib_free_fast_reg_page_list(frd->frd_frpl);
1578 LIBCFS_FREE(frd, sizeof(*frd));
1581 list_for_each_entry_safe(frd, tmp, &fpo->fast_reg.fpo_pool_list,
1583 list_del(&frd->frd_list);
1584 #ifndef HAVE_IB_MAP_MR_SG
1585 ib_free_fast_reg_page_list(frd->frd_frpl);
1587 ib_dereg_mr(frd->frd_mr);
1588 LIBCFS_FREE(frd, sizeof(*frd));
1594 static int kiblnd_create_fmr_pool(struct kib_fmr_poolset *fps,
1595 struct kib_fmr_pool **pp_fpo)
1597 struct kib_dev *dev = fps->fps_net->ibn_dev;
1598 struct kib_fmr_pool *fpo;
1601 LIBCFS_CPT_ALLOC(fpo, lnet_cpt_table(), fps->fps_cpt, sizeof(*fpo));
1605 memset(fpo, 0, sizeof(*fpo));
1607 fpo->fpo_hdev = kiblnd_current_hdev(dev);
1609 #ifdef HAVE_FMR_POOL_API
1610 if (dev->ibd_dev_caps & IBLND_DEV_CAPS_FMR_ENABLED)
1611 rc = kiblnd_alloc_fmr_pool(fps, fpo);
1613 #endif /* HAVE_FMR_POOL_API */
1614 rc = kiblnd_alloc_freg_pool(fps, fpo, dev->ibd_dev_caps);
1618 fpo->fpo_deadline = ktime_get_seconds() + IBLND_POOL_DEADLINE;
1619 fpo->fpo_owner = fps;
1625 kiblnd_hdev_decref(fpo->fpo_hdev);
1626 LIBCFS_FREE(fpo, sizeof(*fpo));
1631 kiblnd_fail_fmr_poolset(struct kib_fmr_poolset *fps, struct list_head *zombies)
1633 struct kib_fmr_pool *fpo;
1635 if (fps->fps_net == NULL) /* intialized? */
1638 spin_lock(&fps->fps_lock);
1640 while ((fpo = list_first_entry_or_null(&fps->fps_pool_list,
1641 struct kib_fmr_pool,
1642 fpo_list)) != NULL) {
1643 fpo->fpo_failed = 1;
1644 if (fpo->fpo_map_count == 0)
1645 list_move(&fpo->fpo_list, zombies);
1647 list_move(&fpo->fpo_list, &fps->fps_failed_pool_list);
1650 spin_unlock(&fps->fps_lock);
1654 kiblnd_fini_fmr_poolset(struct kib_fmr_poolset *fps)
1656 if (fps->fps_net != NULL) { /* initialized? */
1657 kiblnd_destroy_fmr_pool_list(&fps->fps_failed_pool_list);
1658 kiblnd_destroy_fmr_pool_list(&fps->fps_pool_list);
1663 kiblnd_init_fmr_poolset(struct kib_fmr_poolset *fps, int cpt, int ncpts,
1664 struct kib_net *net,
1665 struct lnet_ioctl_config_o2iblnd_tunables *tunables)
1667 struct kib_fmr_pool *fpo;
1670 memset(fps, 0, sizeof(struct kib_fmr_poolset));
1675 fps->fps_pool_size = kiblnd_fmr_pool_size(tunables, ncpts);
1676 fps->fps_flush_trigger = kiblnd_fmr_flush_trigger(tunables, ncpts);
1677 fps->fps_cache = tunables->lnd_fmr_cache;
1679 spin_lock_init(&fps->fps_lock);
1680 INIT_LIST_HEAD(&fps->fps_pool_list);
1681 INIT_LIST_HEAD(&fps->fps_failed_pool_list);
1683 rc = kiblnd_create_fmr_pool(fps, &fpo);
1685 list_add_tail(&fpo->fpo_list, &fps->fps_pool_list);
1691 kiblnd_fmr_pool_is_idle(struct kib_fmr_pool *fpo, time64_t now)
1693 if (fpo->fpo_map_count != 0) /* still in use */
1695 if (fpo->fpo_failed)
1697 return now >= fpo->fpo_deadline;
1700 #if defined(HAVE_FMR_POOL_API) || !defined(HAVE_IB_MAP_MR_SG)
1702 kiblnd_map_tx_pages(struct kib_tx *tx, struct kib_rdma_desc *rd)
1704 struct kib_hca_dev *hdev;
1705 __u64 *pages = tx->tx_pages;
1710 hdev = tx->tx_pool->tpo_hdev;
1712 for (i = 0, npages = 0; i < rd->rd_nfrags; i++) {
1713 for (size = 0; size < rd->rd_frags[i].rf_nob;
1714 size += hdev->ibh_page_size) {
1715 pages[npages++] = (rd->rd_frags[i].rf_addr &
1716 hdev->ibh_page_mask) + size;
1725 kiblnd_fmr_pool_unmap(struct kib_fmr *fmr, int status)
1728 struct kib_fmr_pool *fpo = fmr->fmr_pool;
1729 struct kib_fmr_poolset *fps;
1730 time64_t now = ktime_get_seconds();
1731 struct kib_fmr_pool *tmp;
1736 fps = fpo->fpo_owner;
1738 #ifdef HAVE_FMR_POOL_API
1739 if (fpo->fpo_is_fmr) {
1740 if (fmr->fmr_pfmr) {
1741 ib_fmr_pool_unmap(fmr->fmr_pfmr);
1742 fmr->fmr_pfmr = NULL;
1746 int rc = ib_flush_fmr_pool(fpo->fmr.fpo_fmr_pool);
1750 #endif /* HAVE_FMR_POOL_API */
1752 struct kib_fast_reg_descriptor *frd = fmr->fmr_frd;
1755 frd->frd_valid = false;
1756 frd->frd_posted = false;
1757 fmr->fmr_frd = NULL;
1758 spin_lock(&fps->fps_lock);
1759 list_add_tail(&frd->frd_list, &fpo->fast_reg.fpo_pool_list);
1760 spin_unlock(&fps->fps_lock);
1763 fmr->fmr_pool = NULL;
1765 spin_lock(&fps->fps_lock);
1766 fpo->fpo_map_count--; /* decref the pool */
1768 list_for_each_entry_safe(fpo, tmp, &fps->fps_pool_list, fpo_list) {
1769 /* the first pool is persistent */
1770 if (fps->fps_pool_list.next == &fpo->fpo_list)
1773 if (kiblnd_fmr_pool_is_idle(fpo, now)) {
1774 list_move(&fpo->fpo_list, &zombies);
1778 spin_unlock(&fps->fps_lock);
1780 if (!list_empty(&zombies))
1781 kiblnd_destroy_fmr_pool_list(&zombies);
1784 int kiblnd_fmr_pool_map(struct kib_fmr_poolset *fps, struct kib_tx *tx,
1785 struct kib_rdma_desc *rd, u32 nob, u64 iov,
1786 struct kib_fmr *fmr)
1788 struct kib_fmr_pool *fpo;
1790 bool is_rx = (rd != tx->tx_rd);
1791 #ifdef HAVE_FMR_POOL_API
1792 __u64 *pages = tx->tx_pages;
1793 bool tx_pages_mapped = false;
1799 spin_lock(&fps->fps_lock);
1800 version = fps->fps_version;
1801 list_for_each_entry(fpo, &fps->fps_pool_list, fpo_list) {
1802 fpo->fpo_deadline = ktime_get_seconds() + IBLND_POOL_DEADLINE;
1803 fpo->fpo_map_count++;
1805 #ifdef HAVE_FMR_POOL_API
1806 fmr->fmr_pfmr = NULL;
1807 if (fpo->fpo_is_fmr) {
1808 struct ib_pool_fmr *pfmr;
1810 spin_unlock(&fps->fps_lock);
1812 if (!tx_pages_mapped) {
1813 npages = kiblnd_map_tx_pages(tx, rd);
1814 tx_pages_mapped = true;
1817 pfmr = kib_fmr_pool_map(fpo->fmr.fpo_fmr_pool,
1818 pages, npages, iov);
1819 if (likely(!IS_ERR(pfmr))) {
1820 fmr->fmr_key = is_rx ? pfmr->fmr->rkey
1822 fmr->fmr_frd = NULL;
1823 fmr->fmr_pfmr = pfmr;
1824 fmr->fmr_pool = fpo;
1829 #endif /* HAVE_FMR_POOL_API */
1831 if (!list_empty(&fpo->fast_reg.fpo_pool_list)) {
1832 struct kib_fast_reg_descriptor *frd;
1833 #ifdef HAVE_IB_MAP_MR_SG
1834 struct ib_reg_wr *wr;
1837 struct ib_rdma_wr *wr;
1838 struct ib_fast_reg_page_list *frpl;
1842 frd = list_first_entry(
1843 &fpo->fast_reg.fpo_pool_list,
1844 struct kib_fast_reg_descriptor,
1846 list_del(&frd->frd_list);
1847 spin_unlock(&fps->fps_lock);
1849 #ifndef HAVE_IB_MAP_MR_SG
1850 frpl = frd->frd_frpl;
1854 if (!frd->frd_valid) {
1855 struct ib_rdma_wr *inv_wr;
1856 __u32 key = is_rx ? mr->rkey : mr->lkey;
1858 inv_wr = &frd->frd_inv_wr;
1859 memset(inv_wr, 0, sizeof(*inv_wr));
1861 inv_wr->wr.opcode = IB_WR_LOCAL_INV;
1862 inv_wr->wr.wr_id = IBLND_WID_MR;
1863 inv_wr->wr.ex.invalidate_rkey = key;
1866 key = ib_inc_rkey(key);
1867 ib_update_fast_reg_key(mr, key);
1870 #ifdef HAVE_IB_MAP_MR_SG
1871 #ifdef HAVE_IB_MAP_MR_SG_5ARGS
1872 n = ib_map_mr_sg(mr, tx->tx_frags,
1873 rd->rd_nfrags, NULL, PAGE_SIZE);
1875 n = ib_map_mr_sg(mr, tx->tx_frags,
1876 rd->rd_nfrags, PAGE_SIZE);
1877 #endif /* HAVE_IB_MAP_MR_SG_5ARGS */
1878 if (unlikely(n != rd->rd_nfrags)) {
1879 CERROR("Failed to map mr %d/%d elements\n",
1881 return n < 0 ? n : -EINVAL;
1884 wr = &frd->frd_fastreg_wr;
1885 memset(wr, 0, sizeof(*wr));
1887 wr->wr.opcode = IB_WR_REG_MR;
1888 wr->wr.wr_id = IBLND_WID_MR;
1890 wr->wr.send_flags = 0;
1892 wr->key = is_rx ? mr->rkey : mr->lkey;
1893 wr->access = (IB_ACCESS_LOCAL_WRITE |
1894 IB_ACCESS_REMOTE_WRITE);
1895 #else /* HAVE_IB_MAP_MR_SG */
1896 if (!tx_pages_mapped) {
1897 npages = kiblnd_map_tx_pages(tx, rd);
1898 tx_pages_mapped = true;
1901 LASSERT(npages <= frpl->max_page_list_len);
1902 memcpy(frpl->page_list, pages,
1903 sizeof(*pages) * npages);
1905 /* Prepare FastReg WR */
1906 wr = &frd->frd_fastreg_wr;
1907 memset(wr, 0, sizeof(*wr));
1909 wr->wr.opcode = IB_WR_FAST_REG_MR;
1910 wr->wr.wr_id = IBLND_WID_MR;
1912 wr->wr.wr.fast_reg.iova_start = iov;
1913 wr->wr.wr.fast_reg.page_list = frpl;
1914 wr->wr.wr.fast_reg.page_list_len = npages;
1915 wr->wr.wr.fast_reg.page_shift = PAGE_SHIFT;
1916 wr->wr.wr.fast_reg.length = nob;
1917 wr->wr.wr.fast_reg.rkey =
1918 is_rx ? mr->rkey : mr->lkey;
1919 wr->wr.wr.fast_reg.access_flags =
1920 (IB_ACCESS_LOCAL_WRITE |
1921 IB_ACCESS_REMOTE_WRITE);
1922 #endif /* HAVE_IB_MAP_MR_SG */
1924 fmr->fmr_key = is_rx ? mr->rkey : mr->lkey;
1926 fmr->fmr_pool = fpo;
1927 frd->frd_posted = false;
1930 spin_unlock(&fps->fps_lock);
1934 spin_lock(&fps->fps_lock);
1935 fpo->fpo_map_count--;
1936 if (rc != -EAGAIN) {
1937 spin_unlock(&fps->fps_lock);
1941 /* EAGAIN and ... */
1942 if (version != fps->fps_version) {
1943 spin_unlock(&fps->fps_lock);
1948 if (fps->fps_increasing) {
1949 spin_unlock(&fps->fps_lock);
1950 CDEBUG(D_NET, "Another thread is allocating new "
1951 "FMR pool, waiting for her to complete\n");
1952 wait_var_event(fps, !fps->fps_increasing);
1957 if (ktime_get_seconds() < fps->fps_next_retry) {
1958 /* someone failed recently */
1959 spin_unlock(&fps->fps_lock);
1963 fps->fps_increasing = 1;
1964 spin_unlock(&fps->fps_lock);
1966 CDEBUG(D_NET, "Allocate new FMR pool\n");
1967 rc = kiblnd_create_fmr_pool(fps, &fpo);
1968 spin_lock(&fps->fps_lock);
1969 fps->fps_increasing = 0;
1973 list_add_tail(&fpo->fpo_list, &fps->fps_pool_list);
1975 fps->fps_next_retry = ktime_get_seconds() + IBLND_POOL_RETRY;
1977 spin_unlock(&fps->fps_lock);
1983 kiblnd_fini_pool(struct kib_pool *pool)
1985 LASSERT(list_empty(&pool->po_free_list));
1986 LASSERT(pool->po_allocated == 0);
1988 CDEBUG(D_NET, "Finalize %s pool\n", pool->po_owner->ps_name);
1992 kiblnd_init_pool(struct kib_poolset *ps, struct kib_pool *pool, int size)
1994 CDEBUG(D_NET, "Initialize %s pool\n", ps->ps_name);
1996 memset(pool, 0, sizeof(struct kib_pool));
1997 INIT_LIST_HEAD(&pool->po_free_list);
1998 pool->po_deadline = ktime_get_seconds() + IBLND_POOL_DEADLINE;
1999 pool->po_owner = ps;
2000 pool->po_size = size;
2004 kiblnd_destroy_pool_list(struct list_head *head)
2006 struct kib_pool *pool;
2008 while ((pool = list_first_entry_or_null(head,
2010 po_list)) != NULL) {
2011 list_del(&pool->po_list);
2013 LASSERT(pool->po_owner != NULL);
2014 pool->po_owner->ps_pool_destroy(pool);
2019 kiblnd_fail_poolset(struct kib_poolset *ps, struct list_head *zombies)
2021 struct kib_pool *po;
2023 if (ps->ps_net == NULL) /* intialized? */
2026 spin_lock(&ps->ps_lock);
2027 while ((po = list_first_entry_or_null(&ps->ps_pool_list,
2029 po_list)) != NULL) {
2031 if (po->po_allocated == 0)
2032 list_move(&po->po_list, zombies);
2034 list_move(&po->po_list, &ps->ps_failed_pool_list);
2036 spin_unlock(&ps->ps_lock);
2040 kiblnd_fini_poolset(struct kib_poolset *ps)
2042 if (ps->ps_net != NULL) { /* initialized? */
2043 kiblnd_destroy_pool_list(&ps->ps_failed_pool_list);
2044 kiblnd_destroy_pool_list(&ps->ps_pool_list);
2049 kiblnd_init_poolset(struct kib_poolset *ps, int cpt,
2050 struct kib_net *net, char *name, int size,
2051 kib_ps_pool_create_t po_create,
2052 kib_ps_pool_destroy_t po_destroy,
2053 kib_ps_node_init_t nd_init,
2054 kib_ps_node_fini_t nd_fini)
2056 struct kib_pool *pool;
2059 memset(ps, 0, sizeof(struct kib_poolset));
2063 ps->ps_pool_create = po_create;
2064 ps->ps_pool_destroy = po_destroy;
2065 ps->ps_node_init = nd_init;
2066 ps->ps_node_fini = nd_fini;
2067 ps->ps_pool_size = size;
2068 if (strlcpy(ps->ps_name, name, sizeof(ps->ps_name))
2069 >= sizeof(ps->ps_name))
2071 spin_lock_init(&ps->ps_lock);
2072 INIT_LIST_HEAD(&ps->ps_pool_list);
2073 INIT_LIST_HEAD(&ps->ps_failed_pool_list);
2075 rc = ps->ps_pool_create(ps, size, &pool);
2077 list_add(&pool->po_list, &ps->ps_pool_list);
2079 CERROR("Failed to create the first pool for %s\n", ps->ps_name);
2085 kiblnd_pool_is_idle(struct kib_pool *pool, time64_t now)
2087 if (pool->po_allocated != 0) /* still in use */
2089 if (pool->po_failed)
2091 return now >= pool->po_deadline;
2095 kiblnd_pool_free_node(struct kib_pool *pool, struct list_head *node)
2098 struct kib_poolset *ps = pool->po_owner;
2099 struct kib_pool *tmp;
2100 time64_t now = ktime_get_seconds();
2102 spin_lock(&ps->ps_lock);
2104 if (ps->ps_node_fini != NULL)
2105 ps->ps_node_fini(pool, node);
2107 LASSERT(pool->po_allocated > 0);
2108 list_add(node, &pool->po_free_list);
2109 pool->po_allocated--;
2111 list_for_each_entry_safe(pool, tmp, &ps->ps_pool_list, po_list) {
2112 /* the first pool is persistent */
2113 if (ps->ps_pool_list.next == &pool->po_list)
2116 if (kiblnd_pool_is_idle(pool, now))
2117 list_move(&pool->po_list, &zombies);
2119 spin_unlock(&ps->ps_lock);
2121 if (!list_empty(&zombies))
2122 kiblnd_destroy_pool_list(&zombies);
2126 kiblnd_pool_alloc_node(struct kib_poolset *ps)
2128 struct list_head *node;
2129 struct kib_pool *pool;
2131 unsigned int interval = 1;
2132 ktime_t time_before;
2133 unsigned int trips = 0;
2136 spin_lock(&ps->ps_lock);
2137 list_for_each_entry(pool, &ps->ps_pool_list, po_list) {
2138 if (list_empty(&pool->po_free_list))
2141 pool->po_allocated++;
2142 pool->po_deadline = ktime_get_seconds() +
2143 IBLND_POOL_DEADLINE;
2144 node = pool->po_free_list.next;
2147 if (ps->ps_node_init != NULL) {
2148 /* still hold the lock */
2149 ps->ps_node_init(pool, node);
2151 spin_unlock(&ps->ps_lock);
2155 /* no available tx pool and ... */
2156 if (ps->ps_increasing) {
2157 /* another thread is allocating a new pool */
2158 spin_unlock(&ps->ps_lock);
2161 "Another thread is allocating new %s pool, waiting %d jiffies for her to complete. trips = %d\n",
2162 ps->ps_name, interval, trips);
2164 schedule_timeout_interruptible(interval);
2165 if (interval < cfs_time_seconds(1))
2171 if (ktime_get_seconds() < ps->ps_next_retry) {
2172 /* someone failed recently */
2173 spin_unlock(&ps->ps_lock);
2177 ps->ps_increasing = 1;
2178 spin_unlock(&ps->ps_lock);
2180 CDEBUG(D_NET, "%s pool exhausted, allocate new pool\n", ps->ps_name);
2181 time_before = ktime_get();
2182 rc = ps->ps_pool_create(ps, ps->ps_pool_size, &pool);
2183 CDEBUG(D_NET, "ps_pool_create took %lld ms to complete\n",
2184 ktime_ms_delta(ktime_get(), time_before));
2186 spin_lock(&ps->ps_lock);
2187 ps->ps_increasing = 0;
2189 list_add_tail(&pool->po_list, &ps->ps_pool_list);
2191 ps->ps_next_retry = ktime_get_seconds() + IBLND_POOL_RETRY;
2192 CERROR("Can't allocate new %s pool because out of memory\n",
2195 spin_unlock(&ps->ps_lock);
2201 kiblnd_destroy_tx_pool(struct kib_pool *pool)
2203 struct kib_tx_pool *tpo = container_of(pool, struct kib_tx_pool,
2207 LASSERT (pool->po_allocated == 0);
2209 if (tpo->tpo_tx_pages != NULL) {
2210 kiblnd_unmap_tx_pool(tpo);
2211 kiblnd_free_pages(tpo->tpo_tx_pages);
2214 if (tpo->tpo_tx_descs == NULL)
2217 for (i = 0; i < pool->po_size; i++) {
2218 struct kib_tx *tx = &tpo->tpo_tx_descs[i];
2219 int wrq_sge = *kiblnd_tunables.kib_wrq_sge;
2221 list_del(&tx->tx_list);
2222 if (tx->tx_pages != NULL)
2223 CFS_FREE_PTR_ARRAY(tx->tx_pages, LNET_MAX_IOV);
2224 if (tx->tx_frags != NULL)
2225 CFS_FREE_PTR_ARRAY(tx->tx_frags,
2226 IBLND_MAX_RDMA_FRAGS);
2227 if (tx->tx_wrq != NULL)
2228 CFS_FREE_PTR_ARRAY(tx->tx_wrq,
2229 IBLND_MAX_RDMA_FRAGS);
2230 if (tx->tx_sge != NULL) {
2231 /* +1 is for the lnet header/message itself */
2232 CFS_FREE_PTR_ARRAY(tx->tx_sge,
2233 (IBLND_MAX_RDMA_FRAGS *
2236 if (tx->tx_rd != NULL)
2237 LIBCFS_FREE(tx->tx_rd,
2238 offsetof(struct kib_rdma_desc,
2239 rd_frags[IBLND_MAX_RDMA_FRAGS]));
2242 CFS_FREE_PTR_ARRAY(tpo->tpo_tx_descs, pool->po_size);
2244 kiblnd_fini_pool(pool);
2248 static int kiblnd_tx_pool_size(struct lnet_ni *ni, int ncpts)
2250 struct lnet_ioctl_config_o2iblnd_tunables *tunables;
2253 tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib;
2254 ntx = tunables->lnd_ntx / ncpts;
2256 return max(IBLND_TX_POOL, ntx);
2260 kiblnd_create_tx_pool(struct kib_poolset *ps, int size, struct kib_pool **pp_po)
2264 struct kib_pool *pool;
2265 struct kib_tx_pool *tpo;
2267 LIBCFS_CPT_ALLOC(tpo, lnet_cpt_table(), ps->ps_cpt, sizeof(*tpo));
2269 CERROR("Failed to allocate TX pool\n");
2273 pool = &tpo->tpo_pool;
2274 kiblnd_init_pool(ps, pool, size);
2275 tpo->tpo_tx_descs = NULL;
2276 tpo->tpo_tx_pages = NULL;
2278 npg = (size * IBLND_MSG_SIZE + PAGE_SIZE - 1) / PAGE_SIZE;
2279 if (kiblnd_alloc_pages(&tpo->tpo_tx_pages, ps->ps_cpt, npg) != 0) {
2280 CERROR("Can't allocate tx pages: %d\n", npg);
2285 LIBCFS_CPT_ALLOC(tpo->tpo_tx_descs, lnet_cpt_table(), ps->ps_cpt,
2286 size * sizeof(struct kib_tx));
2287 if (tpo->tpo_tx_descs == NULL) {
2288 CERROR("Can't allocate %d tx descriptors\n", size);
2289 ps->ps_pool_destroy(pool);
2293 memset(tpo->tpo_tx_descs, 0, size * sizeof(struct kib_tx));
2295 for (i = 0; i < size; i++) {
2296 struct kib_tx *tx = &tpo->tpo_tx_descs[i];
2297 int wrq_sge = *kiblnd_tunables.kib_wrq_sge;
2300 if (ps->ps_net->ibn_fmr_ps != NULL) {
2301 LIBCFS_CPT_ALLOC(tx->tx_pages,
2302 lnet_cpt_table(), ps->ps_cpt,
2303 LNET_MAX_IOV * sizeof(*tx->tx_pages));
2304 if (tx->tx_pages == NULL)
2308 LIBCFS_CPT_ALLOC(tx->tx_frags, lnet_cpt_table(), ps->ps_cpt,
2309 IBLND_MAX_RDMA_FRAGS *
2310 sizeof(*tx->tx_frags));
2311 if (tx->tx_frags == NULL)
2314 sg_init_table(tx->tx_frags, IBLND_MAX_RDMA_FRAGS);
2316 LIBCFS_CPT_ALLOC(tx->tx_wrq, lnet_cpt_table(), ps->ps_cpt,
2317 IBLND_MAX_RDMA_FRAGS *
2318 sizeof(*tx->tx_wrq));
2319 if (tx->tx_wrq == NULL)
2322 /* +1 is for the lnet header/message itself */
2323 LIBCFS_CPT_ALLOC(tx->tx_sge, lnet_cpt_table(), ps->ps_cpt,
2324 (IBLND_MAX_RDMA_FRAGS * wrq_sge + 1) *
2325 sizeof(*tx->tx_sge));
2326 if (tx->tx_sge == NULL)
2329 LIBCFS_CPT_ALLOC(tx->tx_rd, lnet_cpt_table(), ps->ps_cpt,
2330 offsetof(struct kib_rdma_desc,
2331 rd_frags[IBLND_MAX_RDMA_FRAGS]));
2332 if (tx->tx_rd == NULL)
2337 kiblnd_map_tx_pool(tpo);
2342 ps->ps_pool_destroy(pool);
2347 kiblnd_tx_init(struct kib_pool *pool, struct list_head *node)
2349 struct kib_tx_poolset *tps = container_of(pool->po_owner,
2350 struct kib_tx_poolset,
2352 struct kib_tx *tx = list_entry(node, struct kib_tx, tx_list);
2354 tx->tx_cookie = tps->tps_next_tx_cookie++;
2358 kiblnd_net_fini_pools(struct kib_net *net)
2362 cfs_cpt_for_each(i, lnet_cpt_table()) {
2363 struct kib_tx_poolset *tps;
2364 struct kib_fmr_poolset *fps;
2366 if (net->ibn_tx_ps != NULL) {
2367 tps = net->ibn_tx_ps[i];
2368 kiblnd_fini_poolset(&tps->tps_poolset);
2371 if (net->ibn_fmr_ps != NULL) {
2372 fps = net->ibn_fmr_ps[i];
2373 kiblnd_fini_fmr_poolset(fps);
2377 if (net->ibn_tx_ps != NULL) {
2378 cfs_percpt_free(net->ibn_tx_ps);
2379 net->ibn_tx_ps = NULL;
2382 if (net->ibn_fmr_ps != NULL) {
2383 cfs_percpt_free(net->ibn_fmr_ps);
2384 net->ibn_fmr_ps = NULL;
2389 kiblnd_net_init_pools(struct kib_net *net, struct lnet_ni *ni, __u32 *cpts,
2392 struct lnet_ioctl_config_o2iblnd_tunables *tunables;
2393 #ifdef HAVE_IB_GET_DMA_MR
2394 unsigned long flags;
2400 tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib;
2402 #ifdef HAVE_IB_GET_DMA_MR
2403 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2405 * if lnd_map_on_demand is zero then we have effectively disabled
2406 * FMR or FastReg and we're using global memory regions
2409 if (!tunables->lnd_map_on_demand) {
2410 read_unlock_irqrestore(&kiblnd_data.kib_global_lock,
2412 goto create_tx_pool;
2415 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2418 if (tunables->lnd_fmr_pool_size < tunables->lnd_ntx / 4) {
2419 CERROR("Can't set fmr pool size (%d) < ntx / 4(%d)\n",
2420 tunables->lnd_fmr_pool_size,
2421 tunables->lnd_ntx / 4);
2426 /* TX pool must be created later than FMR, see LU-2268
2428 LASSERT(net->ibn_tx_ps == NULL);
2430 /* premapping can fail if ibd_nmr > 1, so we always create
2431 * FMR pool and map-on-demand if premapping failed */
2433 net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
2434 sizeof(struct kib_fmr_poolset));
2435 if (net->ibn_fmr_ps == NULL) {
2436 CERROR("Failed to allocate FMR pool array\n");
2441 for (i = 0; i < ncpts; i++) {
2442 cpt = (cpts == NULL) ? i : cpts[i];
2443 rc = kiblnd_init_fmr_poolset(net->ibn_fmr_ps[cpt], cpt, ncpts,
2446 CERROR("Can't initialize FMR pool for CPT %d: %d\n",
2453 LASSERT(i == ncpts);
2455 #ifdef HAVE_IB_GET_DMA_MR
2458 net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
2459 sizeof(struct kib_tx_poolset));
2460 if (net->ibn_tx_ps == NULL) {
2461 CERROR("Failed to allocate tx pool array\n");
2466 for (i = 0; i < ncpts; i++) {
2467 cpt = (cpts == NULL) ? i : cpts[i];
2468 rc = kiblnd_init_poolset(&net->ibn_tx_ps[cpt]->tps_poolset,
2470 kiblnd_tx_pool_size(ni, ncpts),
2471 kiblnd_create_tx_pool,
2472 kiblnd_destroy_tx_pool,
2473 kiblnd_tx_init, NULL);
2475 CERROR("Can't initialize TX pool for CPT %d: %d\n",
2483 kiblnd_net_fini_pools(net);
2489 kiblnd_port_get_attr(struct kib_hca_dev *hdev)
2491 struct ib_port_attr *port_attr;
2493 unsigned long flags;
2494 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
2496 LIBCFS_ALLOC(port_attr, sizeof(*port_attr));
2497 if (port_attr == NULL) {
2498 CDEBUG(D_NETERROR, "Out of memory\n");
2502 rc = ib_query_port(hdev->ibh_ibdev, hdev->ibh_port, port_attr);
2504 write_lock_irqsave(g_lock, flags);
2507 hdev->ibh_state = port_attr->state == IB_PORT_ACTIVE
2508 ? IBLND_DEV_PORT_ACTIVE
2509 : IBLND_DEV_PORT_DOWN;
2511 write_unlock_irqrestore(g_lock, flags);
2512 LIBCFS_FREE(port_attr, sizeof(*port_attr));
2515 CDEBUG(D_NETERROR, "Failed to query IB port: %d\n", rc);
2522 kiblnd_set_ni_fatal_on(struct kib_hca_dev *hdev, int val)
2524 struct kib_net *net;
2526 /* for health check */
2527 list_for_each_entry(net, &hdev->ibh_dev->ibd_nets, ibn_list) {
2529 CDEBUG(D_NETERROR, "Fatal device error for NI %s\n",
2530 libcfs_nidstr(&net->ibn_ni->ni_nid));
2531 atomic_set(&net->ibn_ni->ni_fatal_error_on, val);
2536 kiblnd_event_handler(struct ib_event_handler *handler, struct ib_event *event)
2538 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
2539 struct kib_hca_dev *hdev;
2540 unsigned long flags;
2542 hdev = container_of(handler, struct kib_hca_dev, ibh_event_handler);
2544 write_lock_irqsave(g_lock, flags);
2546 switch (event->event) {
2547 case IB_EVENT_DEVICE_FATAL:
2548 CDEBUG(D_NET, "IB device fatal\n");
2549 hdev->ibh_state = IBLND_DEV_FATAL;
2550 kiblnd_set_ni_fatal_on(hdev, 1);
2552 case IB_EVENT_PORT_ACTIVE:
2553 CDEBUG(D_NET, "IB port active\n");
2554 if (event->element.port_num == hdev->ibh_port) {
2555 hdev->ibh_state = IBLND_DEV_PORT_ACTIVE;
2556 kiblnd_set_ni_fatal_on(hdev, 0);
2559 case IB_EVENT_PORT_ERR:
2560 CDEBUG(D_NET, "IB port err\n");
2561 if (event->element.port_num == hdev->ibh_port) {
2562 hdev->ibh_state = IBLND_DEV_PORT_DOWN;
2563 kiblnd_set_ni_fatal_on(hdev, 1);
2569 write_unlock_irqrestore(g_lock, flags);
2573 kiblnd_hdev_get_attr(struct kib_hca_dev *hdev)
2575 struct ib_device_attr *dev_attr;
2579 /* It's safe to assume a HCA can handle a page size
2580 * matching that of the native system */
2581 hdev->ibh_page_shift = PAGE_SHIFT;
2582 hdev->ibh_page_size = 1 << PAGE_SHIFT;
2583 hdev->ibh_page_mask = ~((__u64)hdev->ibh_page_size - 1);
2585 #ifndef HAVE_IB_DEVICE_ATTRS
2586 LIBCFS_ALLOC(dev_attr, sizeof(*dev_attr));
2587 if (dev_attr == NULL) {
2588 CERROR("Out of memory\n");
2592 rc = ib_query_device(hdev->ibh_ibdev, dev_attr);
2594 CERROR("Failed to query IB device: %d\n", rc);
2595 goto out_clean_attr;
2598 dev_attr = &hdev->ibh_ibdev->attrs;
2601 hdev->ibh_mr_size = dev_attr->max_mr_size;
2602 hdev->ibh_max_qp_wr = dev_attr->max_qp_wr;
2604 /* Setup device Memory Registration capabilities */
2605 #ifdef HAVE_FMR_POOL_API
2606 #ifdef HAVE_IB_DEVICE_OPS
2607 if (hdev->ibh_ibdev->ops.alloc_fmr &&
2608 hdev->ibh_ibdev->ops.dealloc_fmr &&
2609 hdev->ibh_ibdev->ops.map_phys_fmr &&
2610 hdev->ibh_ibdev->ops.unmap_fmr) {
2612 if (hdev->ibh_ibdev->alloc_fmr &&
2613 hdev->ibh_ibdev->dealloc_fmr &&
2614 hdev->ibh_ibdev->map_phys_fmr &&
2615 hdev->ibh_ibdev->unmap_fmr) {
2617 LCONSOLE_INFO("Using FMR for registration\n");
2618 hdev->ibh_dev->ibd_dev_caps |= IBLND_DEV_CAPS_FMR_ENABLED;
2620 #endif /* HAVE_FMR_POOL_API */
2621 if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS) {
2622 LCONSOLE_INFO("Using FastReg for registration\n");
2623 hdev->ibh_dev->ibd_dev_caps |= IBLND_DEV_CAPS_FASTREG_ENABLED;
2624 #ifndef HAVE_IB_ALLOC_FAST_REG_MR
2625 #ifdef IB_DEVICE_SG_GAPS_REG
2626 if (dev_attr->device_cap_flags & IB_DEVICE_SG_GAPS_REG)
2627 hdev->ibh_dev->ibd_dev_caps |= IBLND_DEV_CAPS_FASTREG_GAPS_SUPPORT;
2634 rc2 = kiblnd_port_get_attr(hdev);
2641 #ifndef HAVE_IB_DEVICE_ATTRS
2643 LIBCFS_FREE(dev_attr, sizeof(*dev_attr));
2647 CERROR("IB device does not support FMRs nor FastRegs, can't "
2648 "register memory: %d\n", rc);
2649 else if (rc == -EINVAL)
2650 CERROR("Invalid mr size: %#llx\n", hdev->ibh_mr_size);
2654 #ifdef HAVE_IB_GET_DMA_MR
2656 kiblnd_hdev_cleanup_mrs(struct kib_hca_dev *hdev)
2658 if (hdev->ibh_mrs == NULL)
2661 ib_dereg_mr(hdev->ibh_mrs);
2663 hdev->ibh_mrs = NULL;
2668 kiblnd_hdev_destroy(struct kib_hca_dev *hdev)
2670 if (hdev->ibh_event_handler.device != NULL)
2671 ib_unregister_event_handler(&hdev->ibh_event_handler);
2673 #ifdef HAVE_IB_GET_DMA_MR
2674 kiblnd_hdev_cleanup_mrs(hdev);
2677 if (hdev->ibh_pd != NULL)
2678 ib_dealloc_pd(hdev->ibh_pd);
2680 if (hdev->ibh_cmid != NULL)
2681 rdma_destroy_id(hdev->ibh_cmid);
2683 LIBCFS_FREE(hdev, sizeof(*hdev));
2686 #ifdef HAVE_IB_GET_DMA_MR
2688 kiblnd_hdev_setup_mrs(struct kib_hca_dev *hdev)
2691 int acflags = IB_ACCESS_LOCAL_WRITE |
2692 IB_ACCESS_REMOTE_WRITE;
2694 mr = ib_get_dma_mr(hdev->ibh_pd, acflags);
2696 CERROR("Failed ib_get_dma_mr: %ld\n", PTR_ERR(mr));
2697 kiblnd_hdev_cleanup_mrs(hdev);
2708 kiblnd_dummy_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
2713 static int kiblnd_get_link_status(struct net_device *dev)
2719 if (!netif_running(dev))
2721 /* Some devices may not be providing link settings */
2722 else if (dev->ethtool_ops->get_link)
2723 ret = dev->ethtool_ops->get_link(dev);
2729 kiblnd_dev_need_failover(struct kib_dev *dev, struct net *ns)
2731 struct rdma_cm_id *cmid;
2732 struct sockaddr_in srcaddr;
2733 struct sockaddr_in dstaddr;
2736 if (dev->ibd_hdev == NULL || /* initializing */
2737 dev->ibd_hdev->ibh_cmid == NULL || /* listener is dead */
2738 *kiblnd_tunables.kib_dev_failover > 1) /* debugging */
2741 /* XXX: it's UGLY, but I don't have better way to find
2742 * ib-bonding HCA failover because:
2744 * a. no reliable CM event for HCA failover...
2745 * b. no OFED API to get ib_device for current net_device...
2747 * We have only two choices at this point:
2749 * a. rdma_bind_addr(), it will conflict with listener cmid
2750 * b. rdma_resolve_addr() to zero addr */
2751 cmid = kiblnd_rdma_create_id(ns, kiblnd_dummy_callback, dev,
2752 RDMA_PS_TCP, IB_QPT_RC);
2755 CERROR("Failed to create cmid for failover: %d\n", rc);
2759 memset(&srcaddr, 0, sizeof(srcaddr));
2760 srcaddr.sin_family = AF_INET;
2761 srcaddr.sin_addr.s_addr = (__force u32)htonl(dev->ibd_ifip);
2763 memset(&dstaddr, 0, sizeof(dstaddr));
2764 dstaddr.sin_family = AF_INET;
2765 rc = rdma_resolve_addr(cmid, (struct sockaddr *)&srcaddr,
2766 (struct sockaddr *)&dstaddr, 1);
2767 if (rc != 0 || cmid->device == NULL) {
2768 CERROR("Failed to bind %s:%pI4h to device(%p): %d\n",
2769 dev->ibd_ifname, &dev->ibd_ifip,
2771 rdma_destroy_id(cmid);
2775 rc = dev->ibd_hdev->ibh_ibdev != cmid->device; /* true for failover */
2776 rdma_destroy_id(cmid);
2781 kiblnd_dev_failover(struct kib_dev *dev, struct net *ns)
2783 LIST_HEAD(zombie_tpo);
2784 LIST_HEAD(zombie_ppo);
2785 LIST_HEAD(zombie_fpo);
2786 struct rdma_cm_id *cmid = NULL;
2787 struct kib_hca_dev *hdev = NULL;
2788 struct kib_hca_dev *old;
2790 struct kib_net *net;
2791 struct sockaddr_in addr;
2792 struct net_device *netdev;
2793 unsigned long flags;
2796 bool set_fatal = true;
2798 LASSERT(*kiblnd_tunables.kib_dev_failover > 1 ||
2799 dev->ibd_can_failover ||
2800 dev->ibd_hdev == NULL);
2802 rc = kiblnd_dev_need_failover(dev, ns);
2806 if (dev->ibd_hdev != NULL &&
2807 dev->ibd_hdev->ibh_cmid != NULL) {
2808 /* XXX it's not good to close old listener at here,
2809 * because we can fail to create new listener.
2810 * But we have to close it now, otherwise rdma_bind_addr
2811 * will return EADDRINUSE... How crap! */
2812 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2814 cmid = dev->ibd_hdev->ibh_cmid;
2815 /* make next schedule of kiblnd_dev_need_failover()
2816 * return 1 for me */
2817 dev->ibd_hdev->ibh_cmid = NULL;
2818 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2820 rdma_destroy_id(cmid);
2823 cmid = kiblnd_rdma_create_id(ns, kiblnd_cm_callback, dev, RDMA_PS_TCP,
2827 CERROR("Failed to create cmid for failover: %d\n", rc);
2831 memset(&addr, 0, sizeof(addr));
2832 addr.sin_family = AF_INET;
2833 addr.sin_addr.s_addr = (__force u32)htonl(dev->ibd_ifip);
2834 addr.sin_port = htons(*kiblnd_tunables.kib_service);
2836 /* Bind to failover device or port */
2837 rc = rdma_bind_addr(cmid, (struct sockaddr *)&addr);
2838 if (rc != 0 || cmid->device == NULL) {
2839 CERROR("Failed to bind %s:%pI4h to device(%p): %d\n",
2840 dev->ibd_ifname, &dev->ibd_ifip,
2842 if (!rc && !cmid->device)
2844 rdma_destroy_id(cmid);
2848 LIBCFS_ALLOC(hdev, sizeof(*hdev));
2850 CERROR("Failed to allocate kib_hca_dev\n");
2851 rdma_destroy_id(cmid);
2856 atomic_set(&hdev->ibh_ref, 1);
2857 hdev->ibh_dev = dev;
2858 hdev->ibh_cmid = cmid;
2859 hdev->ibh_ibdev = cmid->device;
2860 hdev->ibh_port = cmid->port_num;
2862 #ifdef HAVE_IB_ALLOC_PD_2ARGS
2863 pd = ib_alloc_pd(cmid->device, 0);
2865 pd = ib_alloc_pd(cmid->device);
2869 CERROR("Can't allocate PD: %d\n", rc);
2875 rc = rdma_listen(cmid, 0);
2877 CERROR("Can't start new listener: %d\n", rc);
2881 rc = kiblnd_hdev_get_attr(hdev);
2883 CERROR("Can't get device attributes: %d\n", rc);
2887 #ifdef HAVE_IB_GET_DMA_MR
2888 rc = kiblnd_hdev_setup_mrs(hdev);
2890 CERROR("Can't setup device: %d\n", rc);
2895 INIT_IB_EVENT_HANDLER(&hdev->ibh_event_handler,
2896 hdev->ibh_ibdev, kiblnd_event_handler);
2897 ib_register_event_handler(&hdev->ibh_event_handler);
2899 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2901 old = dev->ibd_hdev;
2902 dev->ibd_hdev = hdev; /* take over the refcount */
2905 list_for_each_entry(net, &dev->ibd_nets, ibn_list) {
2906 cfs_cpt_for_each(i, lnet_cpt_table()) {
2907 kiblnd_fail_poolset(&net->ibn_tx_ps[i]->tps_poolset,
2910 if (net->ibn_fmr_ps != NULL)
2911 kiblnd_fail_fmr_poolset(net->ibn_fmr_ps[i],
2916 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2918 if (!list_empty(&zombie_tpo))
2919 kiblnd_destroy_pool_list(&zombie_tpo);
2920 if (!list_empty(&zombie_ppo))
2921 kiblnd_destroy_pool_list(&zombie_ppo);
2922 if (!list_empty(&zombie_fpo))
2923 kiblnd_destroy_fmr_pool_list(&zombie_fpo);
2925 kiblnd_hdev_decref(hdev);
2928 dev->ibd_failed_failover++;
2930 dev->ibd_failed_failover = 0;
2934 netdev = dev_get_by_name_rcu(ns, dev->ibd_ifname);
2935 if (netdev && (kiblnd_get_link_status(netdev) == 1))
2936 kiblnd_set_ni_fatal_on(dev->ibd_hdev, 0);
2945 kiblnd_destroy_dev(struct kib_dev *dev)
2947 LASSERT(dev->ibd_nnets == 0);
2948 LASSERT(list_empty(&dev->ibd_nets));
2950 list_del(&dev->ibd_fail_list);
2951 list_del(&dev->ibd_list);
2953 if (dev->ibd_hdev != NULL)
2954 kiblnd_hdev_decref(dev->ibd_hdev);
2956 LIBCFS_FREE(dev, sizeof(*dev));
2960 kiblnd_base_shutdown(void)
2962 struct kib_sched_info *sched;
2963 struct kib_peer_ni *peer_ni;
2966 LASSERT(list_empty(&kiblnd_data.kib_devs));
2968 CDEBUG(D_MALLOC, "before LND base cleanup: kmem %lld\n",
2969 libcfs_kmem_read());
2971 switch (kiblnd_data.kib_init) {
2975 case IBLND_INIT_ALL:
2976 case IBLND_INIT_DATA:
2977 hash_for_each(kiblnd_data.kib_peers, i, peer_ni, ibp_list)
2979 LASSERT(list_empty(&kiblnd_data.kib_connd_zombies));
2980 LASSERT(list_empty(&kiblnd_data.kib_connd_conns));
2981 LASSERT(list_empty(&kiblnd_data.kib_reconn_list));
2982 LASSERT(list_empty(&kiblnd_data.kib_reconn_wait));
2984 /* flag threads to terminate; wake and wait for them to die */
2985 kiblnd_data.kib_shutdown = 1;
2987 /* NB: we really want to stop scheduler threads net by net
2988 * instead of the whole module, this should be improved
2989 * with dynamic configuration LNet.
2991 cfs_percpt_for_each(sched, i, kiblnd_data.kib_scheds)
2992 wake_up_all(&sched->ibs_waitq);
2994 wake_up(&kiblnd_data.kib_connd_waitq);
2995 wake_up(&kiblnd_data.kib_failover_waitq);
2997 wait_var_event_warning(&kiblnd_data.kib_nthreads,
2998 !atomic_read(&kiblnd_data.kib_nthreads),
2999 "Waiting for %d threads to terminate\n",
3000 atomic_read(&kiblnd_data.kib_nthreads));
3003 case IBLND_INIT_NOTHING:
3007 if (kiblnd_data.kib_scheds != NULL)
3008 cfs_percpt_free(kiblnd_data.kib_scheds);
3010 CDEBUG(D_MALLOC, "after LND base cleanup: kmem %lld\n",
3011 libcfs_kmem_read());
3013 kiblnd_data.kib_init = IBLND_INIT_NOTHING;
3014 module_put(THIS_MODULE);
3018 kiblnd_shutdown(struct lnet_ni *ni)
3020 struct kib_net *net = ni->ni_data;
3021 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
3022 unsigned long flags;
3024 LASSERT(kiblnd_data.kib_init == IBLND_INIT_ALL);
3029 CDEBUG(D_MALLOC, "before LND net cleanup: kmem %lld\n",
3030 libcfs_kmem_read());
3032 write_lock_irqsave(g_lock, flags);
3033 net->ibn_shutdown = 1;
3034 write_unlock_irqrestore(g_lock, flags);
3036 switch (net->ibn_init) {
3040 case IBLND_INIT_ALL:
3041 /* nuke all existing peers within this net */
3042 kiblnd_del_peer(ni, LNET_NID_ANY);
3044 /* Wait for all peer_ni state to clean up */
3045 wait_var_event_warning(&net->ibn_npeers,
3046 atomic_read(&net->ibn_npeers) == 0,
3047 "%s: waiting for %d peers to disconnect\n",
3048 libcfs_nidstr(&ni->ni_nid),
3049 atomic_read(&net->ibn_npeers));
3051 kiblnd_net_fini_pools(net);
3053 write_lock_irqsave(g_lock, flags);
3054 LASSERT(net->ibn_dev->ibd_nnets > 0);
3055 net->ibn_dev->ibd_nnets--;
3056 list_del(&net->ibn_list);
3057 write_unlock_irqrestore(g_lock, flags);
3059 wake_up_all(&kiblnd_data.kib_connd_waitq);
3060 wait_var_event_warning(&net->ibn_nconns,
3061 atomic_read(&net->ibn_nconns) == 0,
3062 "%s: waiting for %d conns to clean\n",
3063 libcfs_nidstr(&ni->ni_nid),
3064 atomic_read(&net->ibn_nconns));
3067 case IBLND_INIT_NOTHING:
3068 LASSERT (atomic_read(&net->ibn_nconns) == 0);
3070 if (net->ibn_dev != NULL &&
3071 net->ibn_dev->ibd_nnets == 0)
3072 kiblnd_destroy_dev(net->ibn_dev);
3077 CDEBUG(D_MALLOC, "after LND net cleanup: kmem %lld\n",
3078 libcfs_kmem_read());
3080 net->ibn_init = IBLND_INIT_NOTHING;
3083 LIBCFS_FREE(net, sizeof(*net));
3086 if (list_empty(&kiblnd_data.kib_devs))
3087 kiblnd_base_shutdown();
3091 kiblnd_base_startup(struct net *ns)
3093 struct kib_sched_info *sched;
3097 LASSERT(kiblnd_data.kib_init == IBLND_INIT_NOTHING);
3099 if (!try_module_get(THIS_MODULE))
3102 memset(&kiblnd_data, 0, sizeof(kiblnd_data)); /* zero pointers, flags etc */
3104 rwlock_init(&kiblnd_data.kib_global_lock);
3106 INIT_LIST_HEAD(&kiblnd_data.kib_devs);
3107 INIT_LIST_HEAD(&kiblnd_data.kib_failed_devs);
3109 hash_init(kiblnd_data.kib_peers);
3111 spin_lock_init(&kiblnd_data.kib_connd_lock);
3112 INIT_LIST_HEAD(&kiblnd_data.kib_connd_conns);
3113 INIT_LIST_HEAD(&kiblnd_data.kib_connd_waits);
3114 INIT_LIST_HEAD(&kiblnd_data.kib_connd_zombies);
3115 INIT_LIST_HEAD(&kiblnd_data.kib_reconn_list);
3116 INIT_LIST_HEAD(&kiblnd_data.kib_reconn_wait);
3118 init_waitqueue_head(&kiblnd_data.kib_connd_waitq);
3119 init_waitqueue_head(&kiblnd_data.kib_failover_waitq);
3121 kiblnd_data.kib_scheds = cfs_percpt_alloc(lnet_cpt_table(),
3123 if (kiblnd_data.kib_scheds == NULL)
3126 cfs_percpt_for_each(sched, i, kiblnd_data.kib_scheds) {
3129 spin_lock_init(&sched->ibs_lock);
3130 INIT_LIST_HEAD(&sched->ibs_conns);
3131 init_waitqueue_head(&sched->ibs_waitq);
3133 nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
3134 if (*kiblnd_tunables.kib_nscheds > 0) {
3135 nthrs = min(nthrs, *kiblnd_tunables.kib_nscheds);
3137 /* max to half of CPUs, another half is reserved for
3138 * upper layer modules */
3139 nthrs = min(max(IBLND_N_SCHED, nthrs >> 1), nthrs);
3142 sched->ibs_nthreads_max = nthrs;
3146 kiblnd_data.kib_error_qpa.qp_state = IB_QPS_ERR;
3148 /* lists/ptrs/locks initialised */
3149 kiblnd_data.kib_init = IBLND_INIT_DATA;
3150 /*****************************************************/
3152 rc = kiblnd_thread_start(kiblnd_connd, NULL, "kiblnd_connd");
3154 CERROR("Can't spawn o2iblnd connd: %d\n", rc);
3158 if (*kiblnd_tunables.kib_dev_failover != 0)
3159 rc = kiblnd_thread_start(kiblnd_failover_thread, ns,
3163 CERROR("Can't spawn o2iblnd failover thread: %d\n", rc);
3167 /* flag everything initialised */
3168 kiblnd_data.kib_init = IBLND_INIT_ALL;
3169 /*****************************************************/
3174 kiblnd_base_shutdown();
3179 kiblnd_start_schedulers(struct kib_sched_info *sched)
3185 if (sched->ibs_nthreads == 0) {
3186 if (*kiblnd_tunables.kib_nscheds > 0) {
3187 nthrs = sched->ibs_nthreads_max;
3189 nthrs = cfs_cpt_weight(lnet_cpt_table(),
3191 nthrs = min(max(IBLND_N_SCHED, nthrs >> 1), nthrs);
3192 nthrs = min(IBLND_N_SCHED_HIGH, nthrs);
3195 LASSERT(sched->ibs_nthreads <= sched->ibs_nthreads_max);
3196 /* increase one thread if there is new interface */
3197 nthrs = (sched->ibs_nthreads < sched->ibs_nthreads_max);
3200 for (i = 0; i < nthrs; i++) {
3201 long id = KIB_THREAD_ID(sched->ibs_cpt, sched->ibs_nthreads + i);
3203 rc = kiblnd_thread_start(kiblnd_scheduler, (void *)id,
3204 "kiblnd_sd_%02ld_%02ld",
3205 KIB_THREAD_CPT(id), KIB_THREAD_TID(id));
3209 CERROR("Can't spawn thread %d for scheduler[%d]: %d\n",
3210 sched->ibs_cpt, sched->ibs_nthreads + i, rc);
3214 sched->ibs_nthreads += i;
3218 static int kiblnd_dev_start_threads(struct kib_dev *dev, bool newdev, u32 *cpts,
3225 for (i = 0; i < ncpts; i++) {
3226 struct kib_sched_info *sched;
3228 cpt = (cpts == NULL) ? i : cpts[i];
3229 sched = kiblnd_data.kib_scheds[cpt];
3231 if (!newdev && sched->ibs_nthreads > 0)
3234 rc = kiblnd_start_schedulers(kiblnd_data.kib_scheds[cpt]);
3236 CERROR("Failed to start scheduler threads for %s\n",
3244 static struct kib_dev *
3245 kiblnd_dev_search(char *ifname)
3247 struct kib_dev *alias = NULL;
3248 struct kib_dev *dev;
3252 colon = strchr(ifname, ':');
3253 list_for_each_entry(dev, &kiblnd_data.kib_devs, ibd_list) {
3254 if (strcmp(&dev->ibd_ifname[0], ifname) == 0)
3260 colon2 = strchr(dev->ibd_ifname, ':');
3266 if (strcmp(&dev->ibd_ifname[0], ifname) == 0)
3278 kiblnd_startup(struct lnet_ni *ni)
3280 char *ifname = NULL;
3281 struct lnet_inetdev *ifaces = NULL;
3282 struct kib_dev *ibdev = NULL;
3283 struct kib_net *net = NULL;
3284 unsigned long flags;
3289 LASSERT(ni->ni_net->net_lnd == &the_o2iblnd);
3291 if (kiblnd_data.kib_init == IBLND_INIT_NOTHING) {
3292 rc = kiblnd_base_startup(ni->ni_net_ns);
3297 LIBCFS_ALLOC(net, sizeof(*net));
3305 net->ibn_incarnation = ktime_get_real_ns() / NSEC_PER_USEC;
3307 kiblnd_tunables_setup(ni);
3310 * Multi-Rail wants each secondary
3311 * IP to be treated as an unique 'struct ni' interface.
3313 if (ni->ni_interface != NULL) {
3314 /* Use the IPoIB interface specified in 'networks=' */
3315 ifname = ni->ni_interface;
3317 ifname = *kiblnd_tunables.kib_default_ipif;
3320 if (strlen(ifname) >= sizeof(ibdev->ibd_ifname)) {
3321 CERROR("IPoIB interface name too long: %s\n", ifname);
3326 rc = lnet_inet_enumerate(&ifaces, ni->ni_net_ns);
3330 for (i = 0; i < rc; i++) {
3331 if (strcmp(ifname, ifaces[i].li_name) == 0)
3336 CERROR("ko2iblnd: No matching interfaces\n");
3341 ibdev = kiblnd_dev_search(ifname);
3342 newdev = ibdev == NULL;
3343 /* hmm...create kib_dev even for alias */
3344 if (ibdev == NULL || strcmp(&ibdev->ibd_ifname[0], ifname) != 0) {
3345 LIBCFS_ALLOC(ibdev, sizeof(*ibdev));
3351 ibdev->ibd_ifip = ifaces[i].li_ipaddr;
3352 strlcpy(ibdev->ibd_ifname, ifaces[i].li_name,
3353 sizeof(ibdev->ibd_ifname));
3354 ibdev->ibd_can_failover = !!(ifaces[i].li_flags & IFF_MASTER);
3356 INIT_LIST_HEAD(&ibdev->ibd_nets);
3357 INIT_LIST_HEAD(&ibdev->ibd_list); /* not yet in kib_devs */
3358 INIT_LIST_HEAD(&ibdev->ibd_fail_list);
3360 /* initialize the device */
3361 rc = kiblnd_dev_failover(ibdev, ni->ni_net_ns);
3363 CERROR("ko2iblnd: Can't initialize device: rc = %d\n",
3368 list_add_tail(&ibdev->ibd_list, &kiblnd_data.kib_devs);
3371 net->ibn_dev = ibdev;
3372 ni->ni_nid.nid_addr[0] = cpu_to_be32(ibdev->ibd_ifip);
3374 ni->ni_dev_cpt = ifaces[i].li_cpt;
3376 rc = kiblnd_dev_start_threads(ibdev, newdev, ni->ni_cpts, ni->ni_ncpts);
3380 rc = kiblnd_net_init_pools(net, ni, ni->ni_cpts, ni->ni_ncpts);
3382 CERROR("Failed to initialize NI pools: %d\n", rc);
3386 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
3388 list_add_tail(&net->ibn_list, &ibdev->ibd_nets);
3389 /* for health check */
3390 if (ibdev->ibd_hdev->ibh_state == IBLND_DEV_PORT_DOWN)
3391 kiblnd_set_ni_fatal_on(ibdev->ibd_hdev, 1);
3392 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
3394 net->ibn_init = IBLND_INIT_ALL;
3399 if (net != NULL && net->ibn_dev == NULL && ibdev != NULL)
3400 kiblnd_destroy_dev(ibdev);
3403 kiblnd_shutdown(ni);
3405 CDEBUG(D_NET, "Configuration of device %s failed: rc = %d\n",
3406 ifname ? ifname : "", rc);
3411 static const struct lnet_lnd the_o2iblnd = {
3412 .lnd_type = O2IBLND,
3413 .lnd_startup = kiblnd_startup,
3414 .lnd_shutdown = kiblnd_shutdown,
3415 .lnd_ctl = kiblnd_ctl,
3416 .lnd_send = kiblnd_send,
3417 .lnd_recv = kiblnd_recv,
3418 .lnd_get_dev_prio = kiblnd_get_dev_prio,
3421 static void ko2inlnd_assert_wire_constants(void)
3423 BUILD_BUG_ON(IBLND_MSG_MAGIC != 0x0be91b91);
3424 BUILD_BUG_ON(IBLND_MSG_VERSION_1 != 0x11);
3425 BUILD_BUG_ON(IBLND_MSG_VERSION_2 != 0x12);
3426 BUILD_BUG_ON(IBLND_MSG_VERSION != IBLND_MSG_VERSION_2);
3428 BUILD_BUG_ON(IBLND_MSG_CONNREQ != 0xc0);
3429 BUILD_BUG_ON(IBLND_MSG_CONNACK != 0xc1);
3430 BUILD_BUG_ON(IBLND_MSG_NOOP != 0xd0);
3431 BUILD_BUG_ON(IBLND_MSG_IMMEDIATE != 0xd1);
3432 BUILD_BUG_ON(IBLND_MSG_PUT_REQ != 0xd2);
3433 BUILD_BUG_ON(IBLND_MSG_PUT_NAK != 0xd3);
3434 BUILD_BUG_ON(IBLND_MSG_PUT_ACK != 0xd4);
3435 BUILD_BUG_ON(IBLND_MSG_PUT_DONE != 0xd5);
3436 BUILD_BUG_ON(IBLND_MSG_GET_REQ != 0xd6);
3437 BUILD_BUG_ON(IBLND_MSG_GET_DONE != 0xd7);
3439 BUILD_BUG_ON(IBLND_REJECT_CONN_RACE != 1);
3440 BUILD_BUG_ON(IBLND_REJECT_NO_RESOURCES != 2);
3441 BUILD_BUG_ON(IBLND_REJECT_FATAL != 3);
3442 BUILD_BUG_ON(IBLND_REJECT_CONN_UNCOMPAT != 4);
3443 BUILD_BUG_ON(IBLND_REJECT_CONN_STALE != 5);
3444 BUILD_BUG_ON(IBLND_REJECT_RDMA_FRAGS != 6);
3445 BUILD_BUG_ON(IBLND_REJECT_MSG_QUEUE_SIZE != 7);
3446 BUILD_BUG_ON(IBLND_REJECT_INVALID_SRV_ID != 8);
3448 BUILD_BUG_ON((int)sizeof(struct kib_connparams) != 8);
3449 BUILD_BUG_ON((int)offsetof(struct kib_connparams, ibcp_queue_depth) != 0);
3450 BUILD_BUG_ON((int)sizeof(((struct kib_connparams *)0)->ibcp_queue_depth) != 2);
3451 BUILD_BUG_ON((int)offsetof(struct kib_connparams, ibcp_max_frags) != 2);
3452 BUILD_BUG_ON((int)sizeof(((struct kib_connparams *)0)->ibcp_max_frags) != 2);
3453 BUILD_BUG_ON((int)offsetof(struct kib_connparams, ibcp_max_msg_size) != 4);
3454 BUILD_BUG_ON((int)sizeof(((struct kib_connparams *)0)->ibcp_max_msg_size) != 4);
3456 BUILD_BUG_ON((int)sizeof(struct kib_immediate_msg) != 72);
3457 BUILD_BUG_ON((int)offsetof(struct kib_immediate_msg, ibim_hdr) != 0);
3458 BUILD_BUG_ON((int)sizeof(((struct kib_immediate_msg *)0)->ibim_hdr) != 72);
3459 BUILD_BUG_ON((int)offsetof(struct kib_immediate_msg, ibim_payload) != 72);
3460 BUILD_BUG_ON((int)sizeof(((struct kib_immediate_msg *)0)->ibim_payload) != 0);
3462 BUILD_BUG_ON((int)sizeof(struct kib_rdma_frag) != 12);
3463 BUILD_BUG_ON((int)offsetof(struct kib_rdma_frag, rf_nob) != 0);
3464 BUILD_BUG_ON((int)sizeof(((struct kib_rdma_frag *)0)->rf_nob) != 4);
3465 BUILD_BUG_ON((int)offsetof(struct kib_rdma_frag, rf_addr) != 4);
3466 BUILD_BUG_ON((int)sizeof(((struct kib_rdma_frag *)0)->rf_addr) != 8);
3468 BUILD_BUG_ON((int)sizeof(struct kib_rdma_desc) != 8);
3469 BUILD_BUG_ON((int)offsetof(struct kib_rdma_desc, rd_key) != 0);
3470 BUILD_BUG_ON((int)sizeof(((struct kib_rdma_desc *)0)->rd_key) != 4);
3471 BUILD_BUG_ON((int)offsetof(struct kib_rdma_desc, rd_nfrags) != 4);
3472 BUILD_BUG_ON((int)sizeof(((struct kib_rdma_desc *)0)->rd_nfrags) != 4);
3473 BUILD_BUG_ON((int)offsetof(struct kib_rdma_desc, rd_frags) != 8);
3474 BUILD_BUG_ON((int)sizeof(((struct kib_rdma_desc *)0)->rd_frags) != 0);
3476 BUILD_BUG_ON((int)sizeof(struct kib_putreq_msg) != 80);
3477 BUILD_BUG_ON((int)offsetof(struct kib_putreq_msg, ibprm_hdr) != 0);
3478 BUILD_BUG_ON((int)sizeof(((struct kib_putreq_msg *)0)->ibprm_hdr) != 72);
3479 BUILD_BUG_ON((int)offsetof(struct kib_putreq_msg, ibprm_cookie) != 72);
3480 BUILD_BUG_ON((int)sizeof(((struct kib_putreq_msg *)0)->ibprm_cookie) != 8);
3482 BUILD_BUG_ON((int)sizeof(struct kib_putack_msg) != 24);
3483 BUILD_BUG_ON((int)offsetof(struct kib_putack_msg, ibpam_src_cookie) != 0);
3484 BUILD_BUG_ON((int)sizeof(((struct kib_putack_msg *)0)->ibpam_src_cookie) != 8);
3485 BUILD_BUG_ON((int)offsetof(struct kib_putack_msg, ibpam_dst_cookie) != 8);
3486 BUILD_BUG_ON((int)sizeof(((struct kib_putack_msg *)0)->ibpam_dst_cookie) != 8);
3487 BUILD_BUG_ON((int)offsetof(struct kib_putack_msg, ibpam_rd) != 16);
3488 BUILD_BUG_ON((int)sizeof(((struct kib_putack_msg *)0)->ibpam_rd) != 8);
3490 BUILD_BUG_ON((int)sizeof(struct kib_get_msg) != 88);
3491 BUILD_BUG_ON((int)offsetof(struct kib_get_msg, ibgm_hdr) != 0);
3492 BUILD_BUG_ON((int)sizeof(((struct kib_get_msg *)0)->ibgm_hdr) != 72);
3493 BUILD_BUG_ON((int)offsetof(struct kib_get_msg, ibgm_cookie) != 72);
3494 BUILD_BUG_ON((int)sizeof(((struct kib_get_msg *)0)->ibgm_cookie) != 8);
3495 BUILD_BUG_ON((int)offsetof(struct kib_get_msg, ibgm_rd) != 80);
3496 BUILD_BUG_ON((int)sizeof(((struct kib_get_msg *)0)->ibgm_rd) != 8);
3498 BUILD_BUG_ON((int)sizeof(struct kib_completion_msg) != 12);
3499 BUILD_BUG_ON((int)offsetof(struct kib_completion_msg, ibcm_cookie) != 0);
3500 BUILD_BUG_ON((int)sizeof(((struct kib_completion_msg *)0)->ibcm_cookie) != 8);
3501 BUILD_BUG_ON((int)offsetof(struct kib_completion_msg, ibcm_status) != 8);
3502 BUILD_BUG_ON((int)sizeof(((struct kib_completion_msg *)0)->ibcm_status) != 4);
3504 /* Checks for struct kib_msg */
3505 //BUILD_BUG_ON((int)sizeof(struct kib_msg) != 12);
3506 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_magic) != 0);
3507 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_magic) != 4);
3508 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_version) != 4);
3509 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_version) != 2);
3510 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_type) != 6);
3511 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_type) != 1);
3512 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_credits) != 7);
3513 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_credits) != 1);
3514 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_nob) != 8);
3515 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_nob) != 4);
3516 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_cksum) != 12);
3517 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_cksum) != 4);
3518 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_srcnid) != 16);
3519 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_srcnid) != 8);
3520 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_srcstamp) != 24);
3521 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_srcstamp) != 8);
3522 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_dstnid) != 32);
3523 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_dstnid) != 8);
3524 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_dststamp) != 40);
3525 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_dststamp) != 8);
3528 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.connparams.ibcp_queue_depth) != 48);
3529 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.connparams.ibcp_queue_depth) != 2);
3530 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.connparams.ibcp_max_frags) != 50);
3531 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.connparams.ibcp_max_frags) != 2);
3532 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.connparams.ibcp_max_msg_size) != 52);
3533 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.connparams.ibcp_max_msg_size) != 4);
3535 /* Immediate message */
3536 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.immediate.ibim_hdr) != 48);
3537 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.immediate.ibim_hdr) != 72);
3538 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.immediate.ibim_payload) != 120);
3539 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.immediate.ibim_payload) != 0);
3541 /* PUT req message */
3542 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putreq.ibprm_hdr) != 48);
3543 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.putreq.ibprm_hdr) != 72);
3544 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putreq.ibprm_cookie) != 120);
3545 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.putreq.ibprm_cookie) != 8);
3548 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putack.ibpam_src_cookie) != 48);
3549 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.putack.ibpam_src_cookie) != 8);
3550 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putack.ibpam_dst_cookie) != 56);
3551 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.putack.ibpam_dst_cookie) != 8);
3552 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putack.ibpam_rd) != 64);
3553 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.putack.ibpam_rd) != 8);
3556 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.get.ibgm_hdr) != 48);
3557 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.get.ibgm_hdr) != 72);
3558 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.get.ibgm_cookie) != 120);
3559 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.get.ibgm_cookie) != 8);
3560 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.get.ibgm_rd) != 128);
3561 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.get.ibgm_rd) != 8);
3563 /* Completion message */
3564 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.completion.ibcm_cookie) != 48);
3565 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.completion.ibcm_cookie) != 8);
3566 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.completion.ibcm_status) != 56);
3567 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.completion.ibcm_status) != 4);
3570 BUILD_BUG_ON(sizeof(struct kib_msg) > IBLND_MSG_SIZE);
3571 BUILD_BUG_ON(offsetof(struct kib_msg,
3572 ibm_u.get.ibgm_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) >
3574 BUILD_BUG_ON(offsetof(struct kib_msg,
3575 ibm_u.putack.ibpam_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) >
3579 static void __exit ko2iblnd_exit(void)
3581 lnet_unregister_lnd(&the_o2iblnd);
3584 static int __init ko2iblnd_init(void)
3588 ko2inlnd_assert_wire_constants();
3590 rc = kiblnd_tunables_init();
3594 lnet_register_lnd(&the_o2iblnd);
3599 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3600 MODULE_DESCRIPTION("OpenIB gen2 LNet Network Driver");
3601 MODULE_VERSION("2.8.0");
3602 MODULE_LICENSE("GPL");
3604 module_init(ko2iblnd_init);
3605 module_exit(ko2iblnd_exit);