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/inetdevice.h>
41 static const struct lnet_lnd the_o2iblnd;
43 struct kib_data kiblnd_data;
46 kiblnd_cksum (void *ptr, int nob)
52 sum = ((sum << 1) | (sum >> 31)) + *c++;
54 /* ensure I don't return 0 (== no checksum) */
55 return (sum == 0) ? 1 : sum;
59 kiblnd_msgtype2str(int type)
62 case IBLND_MSG_CONNREQ:
65 case IBLND_MSG_CONNACK:
71 case IBLND_MSG_IMMEDIATE:
74 case IBLND_MSG_PUT_REQ:
77 case IBLND_MSG_PUT_NAK:
80 case IBLND_MSG_PUT_ACK:
83 case IBLND_MSG_PUT_DONE:
86 case IBLND_MSG_GET_REQ:
89 case IBLND_MSG_GET_DONE:
98 kiblnd_msgtype2size(int type)
100 const int hdr_size = offsetof(struct kib_msg, ibm_u);
103 case IBLND_MSG_CONNREQ:
104 case IBLND_MSG_CONNACK:
105 return hdr_size + sizeof(struct kib_connparams);
110 case IBLND_MSG_IMMEDIATE:
111 return offsetof(struct kib_msg, ibm_u.immediate.ibim_payload[0]);
113 case IBLND_MSG_PUT_REQ:
114 return hdr_size + sizeof(struct kib_putreq_msg);
116 case IBLND_MSG_PUT_ACK:
117 return hdr_size + sizeof(struct kib_putack_msg);
119 case IBLND_MSG_GET_REQ:
120 return hdr_size + sizeof(struct kib_get_msg);
122 case IBLND_MSG_PUT_NAK:
123 case IBLND_MSG_PUT_DONE:
124 case IBLND_MSG_GET_DONE:
125 return hdr_size + sizeof(struct kib_completion_msg);
131 static int kiblnd_unpack_rd(struct kib_msg *msg, bool flip)
133 struct kib_rdma_desc *rd;
138 LASSERT(msg->ibm_type == IBLND_MSG_GET_REQ ||
139 msg->ibm_type == IBLND_MSG_PUT_ACK);
141 rd = msg->ibm_type == IBLND_MSG_GET_REQ ?
142 &msg->ibm_u.get.ibgm_rd :
143 &msg->ibm_u.putack.ibpam_rd;
146 __swab32s(&rd->rd_key);
147 __swab32s(&rd->rd_nfrags);
152 if (n <= 0 || n > IBLND_MAX_RDMA_FRAGS) {
153 CERROR("Bad nfrags: %d, should be 0 < n <= %d\n",
154 n, IBLND_MAX_RDMA_FRAGS);
158 nob = offsetof(struct kib_msg, ibm_u) +
159 kiblnd_rd_msg_size(rd, msg->ibm_type, n);
161 if (msg->ibm_nob < nob) {
162 CERROR("Short %s: %d(%d)\n",
163 kiblnd_msgtype2str(msg->ibm_type), msg->ibm_nob, nob);
170 for (i = 0; i < n; i++) {
171 __swab32s(&rd->rd_frags[i].rf_nob);
172 __swab64s(&rd->rd_frags[i].rf_addr);
178 void kiblnd_pack_msg(struct lnet_ni *ni, struct kib_msg *msg, int version,
179 int credits, lnet_nid_t dstnid, __u64 dststamp)
181 struct kib_net *net = ni->ni_data;
183 /* CAVEAT EMPTOR! all message fields not set here should have been
184 * initialised previously.
186 msg->ibm_magic = IBLND_MSG_MAGIC;
187 msg->ibm_version = version;
189 msg->ibm_credits = credits;
192 msg->ibm_srcnid = lnet_nid_to_nid4(&ni->ni_nid);
193 msg->ibm_srcstamp = net->ibn_incarnation;
194 msg->ibm_dstnid = dstnid;
195 msg->ibm_dststamp = dststamp;
197 if (*kiblnd_tunables.kib_cksum) {
198 /* NB ibm_cksum zero while computing cksum */
199 msg->ibm_cksum = kiblnd_cksum(msg, msg->ibm_nob);
203 int kiblnd_unpack_msg(struct kib_msg *msg, int nob)
205 const int hdr_size = offsetof(struct kib_msg, ibm_u);
211 /* 6 bytes are enough to have received magic + version */
213 CERROR("Short message: %d\n", nob);
217 if (msg->ibm_magic == IBLND_MSG_MAGIC) {
219 } else if (msg->ibm_magic == __swab32(IBLND_MSG_MAGIC)) {
222 CERROR("Bad magic: %08x\n", msg->ibm_magic);
226 version = flip ? __swab16(msg->ibm_version) : msg->ibm_version;
227 if (version != IBLND_MSG_VERSION &&
228 version != IBLND_MSG_VERSION_1) {
229 CERROR("Bad version: %x\n", version);
233 if (nob < hdr_size) {
234 CERROR("Short message: %d\n", nob);
238 msg_nob = flip ? __swab32(msg->ibm_nob) : msg->ibm_nob;
240 CERROR("Short message: got %d, wanted %d\n", nob, msg_nob);
244 /* checksum must be computed with ibm_cksum zero and BEFORE anything
247 msg_cksum = flip ? __swab32(msg->ibm_cksum) : msg->ibm_cksum;
249 if (msg_cksum != 0 &&
250 msg_cksum != kiblnd_cksum(msg, msg_nob)) {
251 CERROR("Bad checksum\n");
255 msg->ibm_cksum = msg_cksum;
258 /* leave magic unflipped as a clue to peer_ni endianness */
259 msg->ibm_version = version;
260 BUILD_BUG_ON(sizeof(msg->ibm_type) != 1);
261 BUILD_BUG_ON(sizeof(msg->ibm_credits) != 1);
262 msg->ibm_nob = msg_nob;
263 __swab64s(&msg->ibm_srcnid);
264 __swab64s(&msg->ibm_srcstamp);
265 __swab64s(&msg->ibm_dstnid);
266 __swab64s(&msg->ibm_dststamp);
269 if (msg->ibm_srcnid == LNET_NID_ANY) {
270 CERROR("Bad src nid: %s\n", libcfs_nid2str(msg->ibm_srcnid));
274 if (msg_nob < kiblnd_msgtype2size(msg->ibm_type)) {
275 CERROR("Short %s: %d(%d)\n", kiblnd_msgtype2str(msg->ibm_type),
276 msg_nob, kiblnd_msgtype2size(msg->ibm_type));
280 switch (msg->ibm_type) {
282 CERROR("Unknown message type %x\n", msg->ibm_type);
286 case IBLND_MSG_IMMEDIATE:
287 case IBLND_MSG_PUT_REQ:
290 case IBLND_MSG_PUT_ACK:
291 case IBLND_MSG_GET_REQ:
292 if (kiblnd_unpack_rd(msg, flip))
296 case IBLND_MSG_PUT_NAK:
297 case IBLND_MSG_PUT_DONE:
298 case IBLND_MSG_GET_DONE:
300 __swab32s(&msg->ibm_u.completion.ibcm_status);
303 case IBLND_MSG_CONNREQ:
304 case IBLND_MSG_CONNACK:
306 __swab16s(&msg->ibm_u.connparams.ibcp_queue_depth);
307 __swab16s(&msg->ibm_u.connparams.ibcp_max_frags);
308 __swab32s(&msg->ibm_u.connparams.ibcp_max_msg_size);
316 kiblnd_create_peer(struct lnet_ni *ni, struct kib_peer_ni **peerp,
319 struct kib_peer_ni *peer_ni;
320 struct kib_net *net = ni->ni_data;
321 int cpt = lnet_cpt_of_nid(nid, ni);
324 LASSERT(net != NULL);
325 LASSERT(nid != LNET_NID_ANY);
327 LIBCFS_CPT_ALLOC(peer_ni, lnet_cpt_table(), cpt, sizeof(*peer_ni));
329 CERROR("Cannot allocate peer_ni\n");
333 peer_ni->ibp_ni = ni;
334 peer_ni->ibp_nid = nid;
335 peer_ni->ibp_error = 0;
336 peer_ni->ibp_last_alive = 0;
337 peer_ni->ibp_max_frags = IBLND_MAX_RDMA_FRAGS;
338 peer_ni->ibp_queue_depth = ni->ni_net->net_tunables.lct_peer_tx_credits;
339 peer_ni->ibp_queue_depth_mod = 0; /* try to use the default */
340 atomic_set(&peer_ni->ibp_refcount, 1); /* 1 ref for caller */
342 INIT_HLIST_NODE(&peer_ni->ibp_list);
343 INIT_LIST_HEAD(&peer_ni->ibp_conns);
344 INIT_LIST_HEAD(&peer_ni->ibp_tx_queue);
346 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
348 /* always called with a ref on ni, which prevents ni being shutdown */
349 LASSERT(net->ibn_shutdown == 0);
351 /* npeers only grows with the global lock held */
352 atomic_inc(&net->ibn_npeers);
354 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
361 kiblnd_destroy_peer(struct kib_peer_ni *peer_ni)
363 struct kib_net *net = peer_ni->ibp_ni->ni_data;
365 LASSERT(net != NULL);
366 LASSERT (atomic_read(&peer_ni->ibp_refcount) == 0);
367 LASSERT(!kiblnd_peer_active(peer_ni));
368 LASSERT(kiblnd_peer_idle(peer_ni));
369 LASSERT(list_empty(&peer_ni->ibp_tx_queue));
371 LIBCFS_FREE(peer_ni, sizeof(*peer_ni));
373 /* NB a peer_ni's connections keep a reference on their peer_ni until
374 * they are destroyed, so we can be assured that _all_ state to do
375 * with this peer_ni has been cleaned up when its refcount drops to
378 if (atomic_dec_and_test(&net->ibn_npeers))
379 wake_up_var(&net->ibn_npeers);
383 kiblnd_find_peer_locked(struct lnet_ni *ni, lnet_nid_t nid)
385 /* the caller is responsible for accounting the additional reference
388 struct kib_peer_ni *peer_ni;
390 hash_for_each_possible(kiblnd_data.kib_peers, peer_ni,
392 LASSERT(!kiblnd_peer_idle(peer_ni));
395 * Match a peer if its NID and the NID of the local NI it
396 * communicates over are the same. Otherwise don't match
397 * the peer, which will result in a new lnd peer being
400 if (peer_ni->ibp_nid != nid ||
401 !nid_same(&peer_ni->ibp_ni->ni_nid, &ni->ni_nid))
404 CDEBUG(D_NET, "got peer_ni [%p] -> %s (%d) version: %x\n",
405 peer_ni, libcfs_nid2str(nid),
406 atomic_read(&peer_ni->ibp_refcount),
407 peer_ni->ibp_version);
414 kiblnd_unlink_peer_locked(struct kib_peer_ni *peer_ni)
416 LASSERT(list_empty(&peer_ni->ibp_conns));
418 LASSERT(kiblnd_peer_active(peer_ni));
419 hlist_del_init(&peer_ni->ibp_list);
420 /* lose peerlist's ref */
421 kiblnd_peer_decref(peer_ni);
425 kiblnd_get_peer_info(struct lnet_ni *ni, int index,
426 lnet_nid_t *nidp, int *count)
428 struct kib_peer_ni *peer_ni;
432 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
434 hash_for_each(kiblnd_data.kib_peers, i, peer_ni, ibp_list) {
435 LASSERT(!kiblnd_peer_idle(peer_ni));
437 if (peer_ni->ibp_ni != ni)
443 *nidp = peer_ni->ibp_nid;
444 *count = atomic_read(&peer_ni->ibp_refcount);
446 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
450 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
455 kiblnd_del_peer_locked(struct kib_peer_ni *peer_ni)
457 struct kib_conn *cnxt;
458 struct kib_conn *conn;
460 if (list_empty(&peer_ni->ibp_conns)) {
461 kiblnd_unlink_peer_locked(peer_ni);
463 list_for_each_entry_safe(conn, cnxt, &peer_ni->ibp_conns,
465 kiblnd_close_conn_locked(conn, 0);
466 /* NB closing peer_ni's last conn unlinked it. */
468 /* NB peer_ni now unlinked; might even be freed if the peer_ni table had the
473 kiblnd_del_peer(struct lnet_ni *ni, lnet_nid_t nid)
476 struct hlist_node *pnxt;
477 struct kib_peer_ni *peer_ni;
484 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
486 if (nid != LNET_NID_ANY) {
487 lo = hash_min(nid, HASH_BITS(kiblnd_data.kib_peers));
491 hi = HASH_SIZE(kiblnd_data.kib_peers) - 1;
494 for (i = lo; i <= hi; i++) {
495 hlist_for_each_entry_safe(peer_ni, pnxt,
496 &kiblnd_data.kib_peers[i], ibp_list) {
497 LASSERT(!kiblnd_peer_idle(peer_ni));
499 if (peer_ni->ibp_ni != ni)
502 if (!(nid == LNET_NID_ANY || peer_ni->ibp_nid == nid))
505 if (!list_empty(&peer_ni->ibp_tx_queue)) {
506 LASSERT(list_empty(&peer_ni->ibp_conns));
508 list_splice_init(&peer_ni->ibp_tx_queue,
512 kiblnd_del_peer_locked(peer_ni);
513 rc = 0; /* matched something */
517 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
519 kiblnd_txlist_done(&zombies, -EIO, LNET_MSG_STATUS_LOCAL_ERROR);
524 static struct kib_conn *
525 kiblnd_get_conn_by_idx(struct lnet_ni *ni, int index)
527 struct kib_peer_ni *peer_ni;
528 struct kib_conn *conn;
532 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
534 hash_for_each(kiblnd_data.kib_peers, i, peer_ni, ibp_list) {
535 LASSERT(!kiblnd_peer_idle(peer_ni));
537 if (peer_ni->ibp_ni != ni)
540 list_for_each_entry(conn, &peer_ni->ibp_conns,
545 kiblnd_conn_addref(conn);
546 read_unlock_irqrestore(&kiblnd_data.kib_global_lock,
552 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
557 kiblnd_debug_rx(struct kib_rx *rx)
559 CDEBUG(D_CONSOLE, " %p msg_type %x cred %d\n",
560 rx, rx->rx_msg->ibm_type,
561 rx->rx_msg->ibm_credits);
565 kiblnd_debug_tx(struct kib_tx *tx)
567 CDEBUG(D_CONSOLE, " %p snd %d q %d w %d rc %d dl %lld "
568 "cookie %#llx msg %s%s type %x cred %d\n",
569 tx, tx->tx_sending, tx->tx_queued, tx->tx_waiting,
570 tx->tx_status, ktime_to_ns(tx->tx_deadline), tx->tx_cookie,
571 tx->tx_lntmsg[0] == NULL ? "-" : "!",
572 tx->tx_lntmsg[1] == NULL ? "-" : "!",
573 tx->tx_msg->ibm_type, tx->tx_msg->ibm_credits);
577 kiblnd_debug_conn(struct kib_conn *conn)
579 struct list_head *tmp;
582 spin_lock(&conn->ibc_lock);
584 CDEBUG(D_CONSOLE, "conn[%d] %p [version %x] -> %s:\n",
585 atomic_read(&conn->ibc_refcount), conn,
586 conn->ibc_version, libcfs_nid2str(conn->ibc_peer->ibp_nid));
587 CDEBUG(D_CONSOLE, " state %d nposted %d/%d cred %d o_cred %d "
588 " r_cred %d\n", conn->ibc_state, conn->ibc_noops_posted,
589 conn->ibc_nsends_posted, conn->ibc_credits,
590 conn->ibc_outstanding_credits, conn->ibc_reserved_credits);
591 CDEBUG(D_CONSOLE, " comms_err %d\n", conn->ibc_comms_error);
593 CDEBUG(D_CONSOLE, " early_rxs:\n");
594 list_for_each(tmp, &conn->ibc_early_rxs)
595 kiblnd_debug_rx(list_entry(tmp, struct kib_rx, rx_list));
597 CDEBUG(D_CONSOLE, " tx_noops:\n");
598 list_for_each(tmp, &conn->ibc_tx_noops)
599 kiblnd_debug_tx(list_entry(tmp, struct kib_tx, tx_list));
601 CDEBUG(D_CONSOLE, " tx_queue_nocred:\n");
602 list_for_each(tmp, &conn->ibc_tx_queue_nocred)
603 kiblnd_debug_tx(list_entry(tmp, struct kib_tx, tx_list));
605 CDEBUG(D_CONSOLE, " tx_queue_rsrvd:\n");
606 list_for_each(tmp, &conn->ibc_tx_queue_rsrvd)
607 kiblnd_debug_tx(list_entry(tmp, struct kib_tx, tx_list));
609 CDEBUG(D_CONSOLE, " tx_queue:\n");
610 list_for_each(tmp, &conn->ibc_tx_queue)
611 kiblnd_debug_tx(list_entry(tmp, struct kib_tx, tx_list));
613 CDEBUG(D_CONSOLE, " active_txs:\n");
614 list_for_each(tmp, &conn->ibc_active_txs)
615 kiblnd_debug_tx(list_entry(tmp, struct kib_tx, tx_list));
617 CDEBUG(D_CONSOLE, " rxs:\n");
618 for (i = 0; i < IBLND_RX_MSGS(conn); i++)
619 kiblnd_debug_rx(&conn->ibc_rxs[i]);
621 spin_unlock(&conn->ibc_lock);
625 kiblnd_setup_mtu_locked(struct rdma_cm_id *cmid)
627 /* XXX There is no path record for iWARP, set by netdev->change_mtu? */
628 if (cmid->route.path_rec == NULL)
631 if (*kiblnd_tunables.kib_ib_mtu)
632 cmid->route.path_rec->mtu =
633 ib_mtu_int_to_enum(*kiblnd_tunables.kib_ib_mtu);
637 kiblnd_get_completion_vector(struct kib_conn *conn, int cpt)
645 vectors = conn->ibc_cmid->device->num_comp_vectors;
649 mask = cfs_cpt_cpumask(lnet_cpt_table(), cpt);
651 /* hash NID to CPU id in this partition... */
652 ibp_nid = conn->ibc_peer->ibp_nid;
653 off = do_div(ibp_nid, cpumask_weight(*mask));
654 for_each_cpu(i, *mask) {
664 * Get the scheduler bound to this CPT. If the scheduler has no
665 * threads, which means that the CPT has no CPUs, then grab the
666 * next scheduler that we can use.
668 * This case would be triggered if a NUMA node is configured with
669 * no associated CPUs.
671 static struct kib_sched_info *
672 kiblnd_get_scheduler(int cpt)
674 struct kib_sched_info *sched;
677 sched = kiblnd_data.kib_scheds[cpt];
679 if (sched->ibs_nthreads > 0)
682 cfs_percpt_for_each(sched, i, kiblnd_data.kib_scheds) {
683 if (sched->ibs_nthreads > 0) {
684 CDEBUG(D_NET, "scheduler[%d] has no threads. selected scheduler[%d]\n",
685 cpt, sched->ibs_cpt);
693 static unsigned int kiblnd_send_wrs(struct kib_conn *conn)
696 * One WR for the LNet message
697 * And ibc_max_frags for the transfer WRs
700 int multiplier = 1 + conn->ibc_max_frags;
701 enum kib_dev_caps dev_caps = conn->ibc_hdev->ibh_dev->ibd_dev_caps;
703 /* FastReg needs two extra WRs for map and invalidate */
704 if (dev_caps & IBLND_DEV_CAPS_FASTREG_ENABLED)
707 /* account for a maximum of ibc_queue_depth in-flight transfers */
708 ret = multiplier * conn->ibc_queue_depth;
710 if (ret > conn->ibc_hdev->ibh_max_qp_wr) {
711 CDEBUG(D_NET, "peer_credits %u will result in send work "
712 "request size %d larger than maximum %d device "
713 "can handle\n", conn->ibc_queue_depth, ret,
714 conn->ibc_hdev->ibh_max_qp_wr);
715 conn->ibc_queue_depth =
716 conn->ibc_hdev->ibh_max_qp_wr / multiplier;
719 /* don't go beyond the maximum the device can handle */
720 return min(ret, conn->ibc_hdev->ibh_max_qp_wr);
724 kiblnd_create_conn(struct kib_peer_ni *peer_ni, struct rdma_cm_id *cmid,
725 int state, int version)
728 * If the new conn is created successfully it takes over the caller's
729 * ref on 'peer_ni'. It also "owns" 'cmid' and destroys it when it itself
730 * is destroyed. On failure, the caller's ref on 'peer_ni' remains and
731 * she must dispose of 'cmid'. (Actually I'd block forever if I tried
732 * to destroy 'cmid' here since I'm called from the CM which still has
733 * its ref on 'cmid'). */
734 rwlock_t *glock = &kiblnd_data.kib_global_lock;
735 struct kib_net *net = peer_ni->ibp_ni->ni_data;
737 struct ib_qp_init_attr init_qp_attr = {};
738 struct kib_sched_info *sched;
739 #ifdef HAVE_IB_CQ_INIT_ATTR
740 struct ib_cq_init_attr cq_attr = {};
742 struct kib_conn *conn;
749 LASSERT(net != NULL);
750 LASSERT(!in_interrupt());
754 cpt = lnet_cpt_of_nid(peer_ni->ibp_nid, peer_ni->ibp_ni);
755 sched = kiblnd_get_scheduler(cpt);
758 CERROR("no schedulers available. node is unhealthy\n");
763 * The cpt might have changed if we ended up selecting a non cpt
764 * native scheduler. So use the scheduler's cpt instead.
766 cpt = sched->ibs_cpt;
768 LIBCFS_CPT_ALLOC(conn, lnet_cpt_table(), cpt, sizeof(*conn));
770 CERROR("Can't allocate connection for %s\n",
771 libcfs_nid2str(peer_ni->ibp_nid));
775 conn->ibc_state = IBLND_CONN_INIT;
776 conn->ibc_version = version;
777 conn->ibc_peer = peer_ni; /* I take the caller's ref */
778 cmid->context = conn; /* for future CM callbacks */
779 conn->ibc_cmid = cmid;
780 conn->ibc_max_frags = peer_ni->ibp_max_frags;
781 conn->ibc_queue_depth = peer_ni->ibp_queue_depth;
782 conn->ibc_rxs = NULL;
783 conn->ibc_rx_pages = NULL;
785 INIT_LIST_HEAD(&conn->ibc_early_rxs);
786 INIT_LIST_HEAD(&conn->ibc_tx_noops);
787 INIT_LIST_HEAD(&conn->ibc_tx_queue);
788 INIT_LIST_HEAD(&conn->ibc_tx_queue_rsrvd);
789 INIT_LIST_HEAD(&conn->ibc_tx_queue_nocred);
790 INIT_LIST_HEAD(&conn->ibc_active_txs);
791 INIT_LIST_HEAD(&conn->ibc_zombie_txs);
792 spin_lock_init(&conn->ibc_lock);
794 LIBCFS_CPT_ALLOC(conn->ibc_connvars, lnet_cpt_table(), cpt,
795 sizeof(*conn->ibc_connvars));
796 if (conn->ibc_connvars == NULL) {
797 CERROR("Can't allocate in-progress connection state\n");
801 write_lock_irqsave(glock, flags);
802 if (dev->ibd_failover) {
803 write_unlock_irqrestore(glock, flags);
804 CERROR("%s: failover in progress\n", dev->ibd_ifname);
808 if (dev->ibd_hdev->ibh_ibdev != cmid->device) {
809 /* wakeup failover thread and teardown connection */
810 if (kiblnd_dev_can_failover(dev)) {
811 list_add_tail(&dev->ibd_fail_list,
812 &kiblnd_data.kib_failed_devs);
813 wake_up(&kiblnd_data.kib_failover_waitq);
816 write_unlock_irqrestore(glock, flags);
817 CERROR("cmid HCA(%s), kib_dev(%s) need failover\n",
818 cmid->device->name, dev->ibd_ifname);
822 kiblnd_hdev_addref_locked(dev->ibd_hdev);
823 conn->ibc_hdev = dev->ibd_hdev;
825 kiblnd_setup_mtu_locked(cmid);
827 write_unlock_irqrestore(glock, flags);
829 #ifdef HAVE_IB_CQ_INIT_ATTR
830 cq_attr.cqe = IBLND_CQ_ENTRIES(conn);
831 cq_attr.comp_vector = kiblnd_get_completion_vector(conn, cpt);
832 cq = ib_create_cq(cmid->device,
833 kiblnd_cq_completion, kiblnd_cq_event, conn,
836 cq = ib_create_cq(cmid->device,
837 kiblnd_cq_completion, kiblnd_cq_event, conn,
838 IBLND_CQ_ENTRIES(conn),
839 kiblnd_get_completion_vector(conn, cpt));
843 * on MLX-5 (possibly MLX-4 as well) this error could be
844 * hit if the concurrent_sends and/or peer_tx_credits is set
845 * too high. Or due to an MLX-5 bug which tries to
846 * allocate 256kb via kmalloc for WR cookie array
848 CERROR("Failed to create CQ with %d CQEs: %ld\n",
849 IBLND_CQ_ENTRIES(conn), PTR_ERR(cq));
855 rc = ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
857 CERROR("Can't request completion notification: %d\n", rc);
861 init_qp_attr.event_handler = kiblnd_qp_event;
862 init_qp_attr.qp_context = conn;
863 init_qp_attr.cap.max_send_sge = *kiblnd_tunables.kib_wrq_sge;
864 init_qp_attr.cap.max_recv_sge = 1;
865 init_qp_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
866 init_qp_attr.qp_type = IB_QPT_RC;
867 init_qp_attr.send_cq = cq;
868 init_qp_attr.recv_cq = cq;
870 if (peer_ni->ibp_queue_depth_mod &&
871 peer_ni->ibp_queue_depth_mod < peer_ni->ibp_queue_depth) {
872 conn->ibc_queue_depth = peer_ni->ibp_queue_depth_mod;
873 CDEBUG(D_NET, "Use reduced queue depth %u (from %u)\n",
874 peer_ni->ibp_queue_depth_mod,
875 peer_ni->ibp_queue_depth);
879 /* kiblnd_send_wrs() can change the connection's queue depth if
880 * the maximum work requests for the device is maxed out
882 init_qp_attr.cap.max_send_wr = kiblnd_send_wrs(conn);
883 init_qp_attr.cap.max_recv_wr = IBLND_RECV_WRS(conn);
884 rc = rdma_create_qp(cmid, conn->ibc_hdev->ibh_pd,
886 if (rc != -ENOMEM || conn->ibc_queue_depth < 2)
888 conn->ibc_queue_depth--;
892 CERROR("Can't create QP: %d, send_wr: %d, recv_wr: %d, "
893 "send_sge: %d, recv_sge: %d\n",
894 rc, init_qp_attr.cap.max_send_wr,
895 init_qp_attr.cap.max_recv_wr,
896 init_qp_attr.cap.max_send_sge,
897 init_qp_attr.cap.max_recv_sge);
901 conn->ibc_sched = sched;
903 if (!peer_ni->ibp_queue_depth_mod &&
904 conn->ibc_queue_depth != peer_ni->ibp_queue_depth) {
905 CWARN("peer %s - queue depth reduced from %u to %u"
906 " to allow for qp creation\n",
907 libcfs_nid2str(peer_ni->ibp_nid),
908 peer_ni->ibp_queue_depth,
909 conn->ibc_queue_depth);
910 peer_ni->ibp_queue_depth_mod = conn->ibc_queue_depth;
913 LIBCFS_CPT_ALLOC(conn->ibc_rxs, lnet_cpt_table(), cpt,
914 IBLND_RX_MSGS(conn) * sizeof(struct kib_rx));
915 if (conn->ibc_rxs == NULL) {
916 CERROR("Cannot allocate RX buffers\n");
920 rc = kiblnd_alloc_pages(&conn->ibc_rx_pages, cpt,
921 IBLND_RX_MSG_PAGES(conn));
925 kiblnd_map_rx_descs(conn);
927 /* 1 ref for caller and each rxmsg */
928 atomic_set(&conn->ibc_refcount, 1 + IBLND_RX_MSGS(conn));
929 conn->ibc_nrx = IBLND_RX_MSGS(conn);
932 for (i = 0; i < IBLND_RX_MSGS(conn); i++) {
933 rc = kiblnd_post_rx(&conn->ibc_rxs[i], IBLND_POSTRX_NO_CREDIT);
935 CERROR("Can't post rxmsg: %d\n", rc);
937 /* Make posted receives complete */
938 kiblnd_abort_receives(conn);
940 /* correct # of posted buffers
941 * NB locking needed now I'm racing with completion */
942 spin_lock_irqsave(&sched->ibs_lock, flags);
943 conn->ibc_nrx -= IBLND_RX_MSGS(conn) - i;
944 spin_unlock_irqrestore(&sched->ibs_lock, flags);
946 /* cmid will be destroyed by CM(ofed) after cm_callback
947 * returned, so we can't refer it anymore
948 * (by kiblnd_connd()->kiblnd_destroy_conn) */
949 rdma_destroy_qp(conn->ibc_cmid);
950 conn->ibc_cmid = NULL;
952 /* Drop my own and unused rxbuffer refcounts */
953 while (i++ <= IBLND_RX_MSGS(conn))
954 kiblnd_conn_decref(conn);
960 /* Init successful! */
961 LASSERT (state == IBLND_CONN_ACTIVE_CONNECT ||
962 state == IBLND_CONN_PASSIVE_WAIT);
963 conn->ibc_state = state;
966 atomic_inc(&net->ibn_nconns);
970 kiblnd_destroy_conn(conn);
971 LIBCFS_FREE(conn, sizeof(*conn));
977 kiblnd_destroy_conn(struct kib_conn *conn)
979 struct rdma_cm_id *cmid = conn->ibc_cmid;
980 struct kib_peer_ni *peer_ni = conn->ibc_peer;
982 LASSERT (!in_interrupt());
983 LASSERT (atomic_read(&conn->ibc_refcount) == 0);
984 LASSERT(list_empty(&conn->ibc_early_rxs));
985 LASSERT(list_empty(&conn->ibc_tx_noops));
986 LASSERT(list_empty(&conn->ibc_tx_queue));
987 LASSERT(list_empty(&conn->ibc_tx_queue_rsrvd));
988 LASSERT(list_empty(&conn->ibc_tx_queue_nocred));
989 LASSERT(list_empty(&conn->ibc_active_txs));
990 LASSERT (conn->ibc_noops_posted == 0);
991 LASSERT (conn->ibc_nsends_posted == 0);
993 switch (conn->ibc_state) {
995 /* conn must be completely disengaged from the network */
998 case IBLND_CONN_DISCONNECTED:
999 /* connvars should have been freed already */
1000 LASSERT (conn->ibc_connvars == NULL);
1003 case IBLND_CONN_INIT:
1007 /* conn->ibc_cmid might be destroyed by CM already */
1008 if (cmid != NULL && cmid->qp != NULL)
1009 rdma_destroy_qp(cmid);
1012 ib_destroy_cq(conn->ibc_cq);
1014 kiblnd_txlist_done(&conn->ibc_zombie_txs, -ECONNABORTED,
1015 LNET_MSG_STATUS_OK);
1017 if (conn->ibc_rx_pages != NULL)
1018 kiblnd_unmap_rx_descs(conn);
1020 if (conn->ibc_rxs != NULL)
1021 CFS_FREE_PTR_ARRAY(conn->ibc_rxs, IBLND_RX_MSGS(conn));
1023 if (conn->ibc_connvars != NULL)
1024 LIBCFS_FREE(conn->ibc_connvars, sizeof(*conn->ibc_connvars));
1026 if (conn->ibc_hdev != NULL)
1027 kiblnd_hdev_decref(conn->ibc_hdev);
1029 /* See CAVEAT EMPTOR above in kiblnd_create_conn */
1030 if (conn->ibc_state != IBLND_CONN_INIT) {
1031 struct kib_net *net = peer_ni->ibp_ni->ni_data;
1033 kiblnd_peer_decref(peer_ni);
1034 rdma_destroy_id(cmid);
1035 atomic_dec(&net->ibn_nconns);
1040 kiblnd_close_peer_conns_locked(struct kib_peer_ni *peer_ni, int why)
1042 struct kib_conn *conn;
1043 struct kib_conn *cnxt;
1046 list_for_each_entry_safe(conn, cnxt, &peer_ni->ibp_conns,
1048 CDEBUG(D_NET, "Closing conn -> %s, "
1049 "version: %x, reason: %d\n",
1050 libcfs_nid2str(peer_ni->ibp_nid),
1051 conn->ibc_version, why);
1053 kiblnd_close_conn_locked(conn, why);
1061 kiblnd_close_stale_conns_locked(struct kib_peer_ni *peer_ni,
1062 int version, __u64 incarnation)
1064 struct kib_conn *conn;
1065 struct kib_conn *cnxt;
1068 list_for_each_entry_safe(conn, cnxt, &peer_ni->ibp_conns,
1070 if (conn->ibc_version == version &&
1071 conn->ibc_incarnation == incarnation)
1074 CDEBUG(D_NET, "Closing stale conn -> %s version: %x, "
1075 "incarnation:%#llx(%x, %#llx)\n",
1076 libcfs_nid2str(peer_ni->ibp_nid),
1077 conn->ibc_version, conn->ibc_incarnation,
1078 version, incarnation);
1080 kiblnd_close_conn_locked(conn, -ESTALE);
1088 kiblnd_close_matching_conns(struct lnet_ni *ni, lnet_nid_t nid)
1090 struct kib_peer_ni *peer_ni;
1091 struct hlist_node *pnxt;
1095 unsigned long flags;
1098 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
1100 if (nid != LNET_NID_ANY) {
1101 lo = hash_min(nid, HASH_BITS(kiblnd_data.kib_peers));
1105 hi = HASH_SIZE(kiblnd_data.kib_peers) - 1;
1108 for (i = lo; i <= hi; i++) {
1109 hlist_for_each_entry_safe(peer_ni, pnxt,
1110 &kiblnd_data.kib_peers[i], ibp_list) {
1111 LASSERT(!kiblnd_peer_idle(peer_ni));
1113 if (peer_ni->ibp_ni != ni)
1116 if (!(nid == LNET_NID_ANY || nid == peer_ni->ibp_nid))
1119 count += kiblnd_close_peer_conns_locked(peer_ni, 0);
1123 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
1125 /* wildcards always succeed */
1126 if (nid == LNET_NID_ANY)
1129 return (count == 0) ? -ENOENT : 0;
1133 kiblnd_ctl(struct lnet_ni *ni, unsigned int cmd, void *arg)
1135 struct libcfs_ioctl_data *data = arg;
1139 case IOC_LIBCFS_GET_PEER: {
1143 rc = kiblnd_get_peer_info(ni, data->ioc_count,
1145 data->ioc_nid = nid;
1146 data->ioc_count = count;
1150 case IOC_LIBCFS_DEL_PEER: {
1151 rc = kiblnd_del_peer(ni, data->ioc_nid);
1154 case IOC_LIBCFS_GET_CONN: {
1155 struct kib_conn *conn;
1158 conn = kiblnd_get_conn_by_idx(ni, data->ioc_count);
1164 LASSERT(conn->ibc_cmid != NULL);
1165 data->ioc_nid = conn->ibc_peer->ibp_nid;
1166 if (conn->ibc_cmid->route.path_rec == NULL)
1167 data->ioc_u32[0] = 0; /* iWarp has no path MTU */
1170 ib_mtu_enum_to_int(conn->ibc_cmid->route.path_rec->mtu);
1171 kiblnd_conn_decref(conn);
1174 case IOC_LIBCFS_CLOSE_CONNECTION: {
1175 rc = kiblnd_close_matching_conns(ni, data->ioc_nid);
1187 kiblnd_free_pages(struct kib_pages *p)
1189 int npages = p->ibp_npages;
1192 for (i = 0; i < npages; i++) {
1193 if (p->ibp_pages[i] != NULL)
1194 __free_page(p->ibp_pages[i]);
1197 LIBCFS_FREE(p, offsetof(struct kib_pages, ibp_pages[npages]));
1201 kiblnd_alloc_pages(struct kib_pages **pp, int cpt, int npages)
1203 struct kib_pages *p;
1206 LIBCFS_CPT_ALLOC(p, lnet_cpt_table(), cpt,
1207 offsetof(struct kib_pages, ibp_pages[npages]));
1209 CERROR("Can't allocate descriptor for %d pages\n", npages);
1213 memset(p, 0, offsetof(struct kib_pages, ibp_pages[npages]));
1214 p->ibp_npages = npages;
1216 for (i = 0; i < npages; i++) {
1217 p->ibp_pages[i] = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1219 if (p->ibp_pages[i] == NULL) {
1220 CERROR("Can't allocate page %d of %d\n", i, npages);
1221 kiblnd_free_pages(p);
1231 kiblnd_unmap_rx_descs(struct kib_conn *conn)
1236 LASSERT (conn->ibc_rxs != NULL);
1237 LASSERT (conn->ibc_hdev != NULL);
1239 for (i = 0; i < IBLND_RX_MSGS(conn); i++) {
1240 rx = &conn->ibc_rxs[i];
1242 LASSERT(rx->rx_nob >= 0); /* not posted */
1244 kiblnd_dma_unmap_single(conn->ibc_hdev->ibh_ibdev,
1245 KIBLND_UNMAP_ADDR(rx, rx_msgunmap,
1247 IBLND_MSG_SIZE, DMA_FROM_DEVICE);
1250 kiblnd_free_pages(conn->ibc_rx_pages);
1252 conn->ibc_rx_pages = NULL;
1256 kiblnd_map_rx_descs(struct kib_conn *conn)
1264 for (pg_off = ipg = i = 0; i < IBLND_RX_MSGS(conn); i++) {
1265 pg = conn->ibc_rx_pages->ibp_pages[ipg];
1266 rx = &conn->ibc_rxs[i];
1269 rx->rx_msg = (struct kib_msg *)(((char *)page_address(pg)) + pg_off);
1272 kiblnd_dma_map_single(conn->ibc_hdev->ibh_ibdev,
1273 rx->rx_msg, IBLND_MSG_SIZE,
1275 LASSERT(!kiblnd_dma_mapping_error(conn->ibc_hdev->ibh_ibdev,
1277 KIBLND_UNMAP_ADDR_SET(rx, rx_msgunmap, rx->rx_msgaddr);
1279 CDEBUG(D_NET, "rx %d: %p %#llx(%#llx)\n",
1280 i, rx->rx_msg, rx->rx_msgaddr,
1281 (__u64)(page_to_phys(pg) + pg_off));
1283 pg_off += IBLND_MSG_SIZE;
1284 LASSERT(pg_off <= PAGE_SIZE);
1286 if (pg_off == PAGE_SIZE) {
1289 LASSERT(ipg <= IBLND_RX_MSG_PAGES(conn));
1295 kiblnd_unmap_tx_pool(struct kib_tx_pool *tpo)
1297 struct kib_hca_dev *hdev = tpo->tpo_hdev;
1301 LASSERT (tpo->tpo_pool.po_allocated == 0);
1306 for (i = 0; i < tpo->tpo_pool.po_size; i++) {
1307 tx = &tpo->tpo_tx_descs[i];
1308 kiblnd_dma_unmap_single(hdev->ibh_ibdev,
1309 KIBLND_UNMAP_ADDR(tx, tx_msgunmap,
1311 IBLND_MSG_SIZE, DMA_TO_DEVICE);
1314 kiblnd_hdev_decref(hdev);
1315 tpo->tpo_hdev = NULL;
1318 static struct kib_hca_dev *
1319 kiblnd_current_hdev(struct kib_dev *dev)
1321 struct kib_hca_dev *hdev;
1322 unsigned long flags;
1325 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
1326 while (dev->ibd_failover) {
1327 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
1329 CDEBUG(D_NET, "%s: Wait for failover\n",
1331 schedule_timeout_interruptible(cfs_time_seconds(1) / 100);
1333 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
1336 kiblnd_hdev_addref_locked(dev->ibd_hdev);
1337 hdev = dev->ibd_hdev;
1339 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
1345 kiblnd_map_tx_pool(struct kib_tx_pool *tpo)
1347 struct kib_pages *txpgs = tpo->tpo_tx_pages;
1348 struct kib_pool *pool = &tpo->tpo_pool;
1349 struct kib_net *net = pool->po_owner->ps_net;
1350 struct kib_dev *dev;
1357 LASSERT (net != NULL);
1361 /* pre-mapped messages are not bigger than 1 page */
1362 BUILD_BUG_ON(IBLND_MSG_SIZE > PAGE_SIZE);
1364 /* No fancy arithmetic when we do the buffer calculations */
1365 BUILD_BUG_ON(PAGE_SIZE % IBLND_MSG_SIZE != 0);
1367 tpo->tpo_hdev = kiblnd_current_hdev(dev);
1369 for (ipage = page_offset = i = 0; i < pool->po_size; i++) {
1370 page = txpgs->ibp_pages[ipage];
1371 tx = &tpo->tpo_tx_descs[i];
1373 tx->tx_msg = (struct kib_msg *)(((char *)page_address(page)) +
1376 tx->tx_msgaddr = kiblnd_dma_map_single(tpo->tpo_hdev->ibh_ibdev,
1380 LASSERT(!kiblnd_dma_mapping_error(tpo->tpo_hdev->ibh_ibdev,
1382 KIBLND_UNMAP_ADDR_SET(tx, tx_msgunmap, tx->tx_msgaddr);
1384 list_add(&tx->tx_list, &pool->po_free_list);
1386 page_offset += IBLND_MSG_SIZE;
1387 LASSERT(page_offset <= PAGE_SIZE);
1389 if (page_offset == PAGE_SIZE) {
1392 LASSERT(ipage <= txpgs->ibp_npages);
1398 kiblnd_destroy_fmr_pool(struct kib_fmr_pool *fpo)
1400 LASSERT(fpo->fpo_map_count == 0);
1402 #ifdef HAVE_FMR_POOL_API
1403 if (fpo->fpo_is_fmr && fpo->fmr.fpo_fmr_pool) {
1404 ib_destroy_fmr_pool(fpo->fmr.fpo_fmr_pool);
1406 #endif /* HAVE_FMR_POOL_API */
1408 struct kib_fast_reg_descriptor *frd, *tmp;
1411 list_for_each_entry_safe(frd, tmp, &fpo->fast_reg.fpo_pool_list,
1413 list_del(&frd->frd_list);
1414 #ifndef HAVE_IB_MAP_MR_SG
1415 ib_free_fast_reg_page_list(frd->frd_frpl);
1417 ib_dereg_mr(frd->frd_mr);
1418 LIBCFS_FREE(frd, sizeof(*frd));
1421 if (i < fpo->fast_reg.fpo_pool_size)
1422 CERROR("FastReg pool still has %d regions registered\n",
1423 fpo->fast_reg.fpo_pool_size - i);
1427 kiblnd_hdev_decref(fpo->fpo_hdev);
1429 LIBCFS_FREE(fpo, sizeof(*fpo));
1433 kiblnd_destroy_fmr_pool_list(struct list_head *head)
1435 struct kib_fmr_pool *fpo, *tmp;
1437 list_for_each_entry_safe(fpo, tmp, head, fpo_list) {
1438 list_del(&fpo->fpo_list);
1439 kiblnd_destroy_fmr_pool(fpo);
1444 kiblnd_fmr_pool_size(struct lnet_ioctl_config_o2iblnd_tunables *tunables,
1447 int size = tunables->lnd_fmr_pool_size / ncpts;
1449 return max(IBLND_FMR_POOL, size);
1453 kiblnd_fmr_flush_trigger(struct lnet_ioctl_config_o2iblnd_tunables *tunables,
1456 int size = tunables->lnd_fmr_flush_trigger / ncpts;
1458 return max(IBLND_FMR_POOL_FLUSH, size);
1461 #ifdef HAVE_FMR_POOL_API
1462 static int kiblnd_alloc_fmr_pool(struct kib_fmr_poolset *fps,
1463 struct kib_fmr_pool *fpo)
1465 struct ib_fmr_pool_param param = {
1466 .max_pages_per_fmr = LNET_MAX_IOV,
1467 .page_shift = PAGE_SHIFT,
1468 .access = (IB_ACCESS_LOCAL_WRITE |
1469 IB_ACCESS_REMOTE_WRITE),
1470 .pool_size = fps->fps_pool_size,
1471 .dirty_watermark = fps->fps_flush_trigger,
1472 .flush_function = NULL,
1474 .cache = !!fps->fps_cache };
1477 fpo->fmr.fpo_fmr_pool = ib_create_fmr_pool(fpo->fpo_hdev->ibh_pd,
1479 if (IS_ERR(fpo->fmr.fpo_fmr_pool)) {
1480 rc = PTR_ERR(fpo->fmr.fpo_fmr_pool);
1482 CERROR("Failed to create FMR pool: %d\n", rc);
1484 CERROR("FMRs are not supported\n");
1486 fpo->fpo_is_fmr = true;
1490 #endif /* HAVE_FMR_POOL_API */
1492 static int kiblnd_alloc_freg_pool(struct kib_fmr_poolset *fps,
1493 struct kib_fmr_pool *fpo,
1494 enum kib_dev_caps dev_caps)
1496 struct kib_fast_reg_descriptor *frd, *tmp;
1499 #ifdef HAVE_FMR_POOL_API
1500 fpo->fpo_is_fmr = false;
1503 INIT_LIST_HEAD(&fpo->fast_reg.fpo_pool_list);
1504 fpo->fast_reg.fpo_pool_size = 0;
1505 for (i = 0; i < fps->fps_pool_size; i++) {
1506 LIBCFS_CPT_ALLOC(frd, lnet_cpt_table(), fps->fps_cpt,
1509 CERROR("Failed to allocate a new fast_reg descriptor\n");
1515 #ifndef HAVE_IB_MAP_MR_SG
1516 frd->frd_frpl = ib_alloc_fast_reg_page_list(fpo->fpo_hdev->ibh_ibdev,
1518 if (IS_ERR(frd->frd_frpl)) {
1519 rc = PTR_ERR(frd->frd_frpl);
1520 CERROR("Failed to allocate ib_fast_reg_page_list: %d\n",
1522 frd->frd_frpl = NULL;
1527 #ifdef HAVE_IB_ALLOC_FAST_REG_MR
1528 frd->frd_mr = ib_alloc_fast_reg_mr(fpo->fpo_hdev->ibh_pd,
1532 * it is expected to get here if this is an MLX-5 card.
1533 * MLX-4 cards will always use FMR and MLX-5 cards will
1534 * always use fast_reg. It turns out that some MLX-5 cards
1535 * (possibly due to older FW versions) do not natively support
1536 * gaps. So we will need to track them here.
1538 frd->frd_mr = ib_alloc_mr(fpo->fpo_hdev->ibh_pd,
1539 #ifdef IB_MR_TYPE_SG_GAPS
1540 ((*kiblnd_tunables.kib_use_fastreg_gaps == 1) &&
1541 (dev_caps & IBLND_DEV_CAPS_FASTREG_GAPS_SUPPORT)) ?
1542 IB_MR_TYPE_SG_GAPS :
1548 if ((*kiblnd_tunables.kib_use_fastreg_gaps == 1) &&
1549 (dev_caps & IBLND_DEV_CAPS_FASTREG_GAPS_SUPPORT))
1550 CWARN("using IB_MR_TYPE_SG_GAPS, expect a performance drop\n");
1552 if (IS_ERR(frd->frd_mr)) {
1553 rc = PTR_ERR(frd->frd_mr);
1554 CERROR("Failed to allocate ib_fast_reg_mr: %d\n", rc);
1559 /* There appears to be a bug in MLX5 code where you must
1560 * invalidate the rkey of a new FastReg pool before first
1561 * using it. Thus, I am marking the FRD invalid here. */
1562 frd->frd_valid = false;
1564 list_add_tail(&frd->frd_list, &fpo->fast_reg.fpo_pool_list);
1565 fpo->fast_reg.fpo_pool_size++;
1572 ib_dereg_mr(frd->frd_mr);
1573 #ifndef HAVE_IB_MAP_MR_SG
1575 ib_free_fast_reg_page_list(frd->frd_frpl);
1577 LIBCFS_FREE(frd, sizeof(*frd));
1580 list_for_each_entry_safe(frd, tmp, &fpo->fast_reg.fpo_pool_list,
1582 list_del(&frd->frd_list);
1583 #ifndef HAVE_IB_MAP_MR_SG
1584 ib_free_fast_reg_page_list(frd->frd_frpl);
1586 ib_dereg_mr(frd->frd_mr);
1587 LIBCFS_FREE(frd, sizeof(*frd));
1593 static int kiblnd_create_fmr_pool(struct kib_fmr_poolset *fps,
1594 struct kib_fmr_pool **pp_fpo)
1596 struct kib_dev *dev = fps->fps_net->ibn_dev;
1597 struct kib_fmr_pool *fpo;
1600 LIBCFS_CPT_ALLOC(fpo, lnet_cpt_table(), fps->fps_cpt, sizeof(*fpo));
1604 memset(fpo, 0, sizeof(*fpo));
1606 fpo->fpo_hdev = kiblnd_current_hdev(dev);
1608 #ifdef HAVE_FMR_POOL_API
1609 if (dev->ibd_dev_caps & IBLND_DEV_CAPS_FMR_ENABLED)
1610 rc = kiblnd_alloc_fmr_pool(fps, fpo);
1612 #endif /* HAVE_FMR_POOL_API */
1613 rc = kiblnd_alloc_freg_pool(fps, fpo, dev->ibd_dev_caps);
1617 fpo->fpo_deadline = ktime_get_seconds() + IBLND_POOL_DEADLINE;
1618 fpo->fpo_owner = fps;
1624 kiblnd_hdev_decref(fpo->fpo_hdev);
1625 LIBCFS_FREE(fpo, sizeof(*fpo));
1630 kiblnd_fail_fmr_poolset(struct kib_fmr_poolset *fps, struct list_head *zombies)
1632 struct kib_fmr_pool *fpo;
1634 if (fps->fps_net == NULL) /* intialized? */
1637 spin_lock(&fps->fps_lock);
1639 while ((fpo = list_first_entry_or_null(&fps->fps_pool_list,
1640 struct kib_fmr_pool,
1641 fpo_list)) != NULL) {
1642 fpo->fpo_failed = 1;
1643 if (fpo->fpo_map_count == 0)
1644 list_move(&fpo->fpo_list, zombies);
1646 list_move(&fpo->fpo_list, &fps->fps_failed_pool_list);
1649 spin_unlock(&fps->fps_lock);
1653 kiblnd_fini_fmr_poolset(struct kib_fmr_poolset *fps)
1655 if (fps->fps_net != NULL) { /* initialized? */
1656 kiblnd_destroy_fmr_pool_list(&fps->fps_failed_pool_list);
1657 kiblnd_destroy_fmr_pool_list(&fps->fps_pool_list);
1662 kiblnd_init_fmr_poolset(struct kib_fmr_poolset *fps, int cpt, int ncpts,
1663 struct kib_net *net,
1664 struct lnet_ioctl_config_o2iblnd_tunables *tunables)
1666 struct kib_fmr_pool *fpo;
1669 memset(fps, 0, sizeof(struct kib_fmr_poolset));
1674 fps->fps_pool_size = kiblnd_fmr_pool_size(tunables, ncpts);
1675 fps->fps_flush_trigger = kiblnd_fmr_flush_trigger(tunables, ncpts);
1676 fps->fps_cache = tunables->lnd_fmr_cache;
1678 spin_lock_init(&fps->fps_lock);
1679 INIT_LIST_HEAD(&fps->fps_pool_list);
1680 INIT_LIST_HEAD(&fps->fps_failed_pool_list);
1682 rc = kiblnd_create_fmr_pool(fps, &fpo);
1684 list_add_tail(&fpo->fpo_list, &fps->fps_pool_list);
1690 kiblnd_fmr_pool_is_idle(struct kib_fmr_pool *fpo, time64_t now)
1692 if (fpo->fpo_map_count != 0) /* still in use */
1694 if (fpo->fpo_failed)
1696 return now >= fpo->fpo_deadline;
1699 #if defined(HAVE_FMR_POOL_API) || !defined(HAVE_IB_MAP_MR_SG)
1701 kiblnd_map_tx_pages(struct kib_tx *tx, struct kib_rdma_desc *rd)
1703 struct kib_hca_dev *hdev;
1704 __u64 *pages = tx->tx_pages;
1709 hdev = tx->tx_pool->tpo_hdev;
1711 for (i = 0, npages = 0; i < rd->rd_nfrags; i++) {
1712 for (size = 0; size < rd->rd_frags[i].rf_nob;
1713 size += hdev->ibh_page_size) {
1714 pages[npages++] = (rd->rd_frags[i].rf_addr &
1715 hdev->ibh_page_mask) + size;
1724 kiblnd_fmr_pool_unmap(struct kib_fmr *fmr, int status)
1727 struct kib_fmr_pool *fpo = fmr->fmr_pool;
1728 struct kib_fmr_poolset *fps;
1729 time64_t now = ktime_get_seconds();
1730 struct kib_fmr_pool *tmp;
1735 fps = fpo->fpo_owner;
1737 #ifdef HAVE_FMR_POOL_API
1738 if (fpo->fpo_is_fmr) {
1739 if (fmr->fmr_pfmr) {
1740 ib_fmr_pool_unmap(fmr->fmr_pfmr);
1741 fmr->fmr_pfmr = NULL;
1745 int rc = ib_flush_fmr_pool(fpo->fmr.fpo_fmr_pool);
1749 #endif /* HAVE_FMR_POOL_API */
1751 struct kib_fast_reg_descriptor *frd = fmr->fmr_frd;
1754 frd->frd_valid = false;
1755 frd->frd_posted = false;
1756 fmr->fmr_frd = NULL;
1757 spin_lock(&fps->fps_lock);
1758 list_add_tail(&frd->frd_list, &fpo->fast_reg.fpo_pool_list);
1759 spin_unlock(&fps->fps_lock);
1762 fmr->fmr_pool = NULL;
1764 spin_lock(&fps->fps_lock);
1765 fpo->fpo_map_count--; /* decref the pool */
1767 list_for_each_entry_safe(fpo, tmp, &fps->fps_pool_list, fpo_list) {
1768 /* the first pool is persistent */
1769 if (fps->fps_pool_list.next == &fpo->fpo_list)
1772 if (kiblnd_fmr_pool_is_idle(fpo, now)) {
1773 list_move(&fpo->fpo_list, &zombies);
1777 spin_unlock(&fps->fps_lock);
1779 if (!list_empty(&zombies))
1780 kiblnd_destroy_fmr_pool_list(&zombies);
1783 int kiblnd_fmr_pool_map(struct kib_fmr_poolset *fps, struct kib_tx *tx,
1784 struct kib_rdma_desc *rd, u32 nob, u64 iov,
1785 struct kib_fmr *fmr)
1787 struct kib_fmr_pool *fpo;
1789 bool is_rx = (rd != tx->tx_rd);
1790 #ifdef HAVE_FMR_POOL_API
1791 __u64 *pages = tx->tx_pages;
1792 bool tx_pages_mapped = false;
1798 spin_lock(&fps->fps_lock);
1799 version = fps->fps_version;
1800 list_for_each_entry(fpo, &fps->fps_pool_list, fpo_list) {
1801 fpo->fpo_deadline = ktime_get_seconds() + IBLND_POOL_DEADLINE;
1802 fpo->fpo_map_count++;
1804 #ifdef HAVE_FMR_POOL_API
1805 fmr->fmr_pfmr = NULL;
1806 if (fpo->fpo_is_fmr) {
1807 struct ib_pool_fmr *pfmr;
1809 spin_unlock(&fps->fps_lock);
1811 if (!tx_pages_mapped) {
1812 npages = kiblnd_map_tx_pages(tx, rd);
1813 tx_pages_mapped = true;
1816 pfmr = kib_fmr_pool_map(fpo->fmr.fpo_fmr_pool,
1817 pages, npages, iov);
1818 if (likely(!IS_ERR(pfmr))) {
1819 fmr->fmr_key = is_rx ? pfmr->fmr->rkey
1821 fmr->fmr_frd = NULL;
1822 fmr->fmr_pfmr = pfmr;
1823 fmr->fmr_pool = fpo;
1828 #endif /* HAVE_FMR_POOL_API */
1830 if (!list_empty(&fpo->fast_reg.fpo_pool_list)) {
1831 struct kib_fast_reg_descriptor *frd;
1832 #ifdef HAVE_IB_MAP_MR_SG
1833 struct ib_reg_wr *wr;
1836 struct ib_rdma_wr *wr;
1837 struct ib_fast_reg_page_list *frpl;
1841 frd = list_first_entry(
1842 &fpo->fast_reg.fpo_pool_list,
1843 struct kib_fast_reg_descriptor,
1845 list_del(&frd->frd_list);
1846 spin_unlock(&fps->fps_lock);
1848 #ifndef HAVE_IB_MAP_MR_SG
1849 frpl = frd->frd_frpl;
1853 if (!frd->frd_valid) {
1854 struct ib_rdma_wr *inv_wr;
1855 __u32 key = is_rx ? mr->rkey : mr->lkey;
1857 inv_wr = &frd->frd_inv_wr;
1858 memset(inv_wr, 0, sizeof(*inv_wr));
1860 inv_wr->wr.opcode = IB_WR_LOCAL_INV;
1861 inv_wr->wr.wr_id = IBLND_WID_MR;
1862 inv_wr->wr.ex.invalidate_rkey = key;
1865 key = ib_inc_rkey(key);
1866 ib_update_fast_reg_key(mr, key);
1869 #ifdef HAVE_IB_MAP_MR_SG
1870 #ifdef HAVE_IB_MAP_MR_SG_5ARGS
1871 n = ib_map_mr_sg(mr, tx->tx_frags,
1872 rd->rd_nfrags, NULL, PAGE_SIZE);
1874 n = ib_map_mr_sg(mr, tx->tx_frags,
1875 rd->rd_nfrags, PAGE_SIZE);
1876 #endif /* HAVE_IB_MAP_MR_SG_5ARGS */
1877 if (unlikely(n != rd->rd_nfrags)) {
1878 CERROR("Failed to map mr %d/%d elements\n",
1880 return n < 0 ? n : -EINVAL;
1883 wr = &frd->frd_fastreg_wr;
1884 memset(wr, 0, sizeof(*wr));
1886 wr->wr.opcode = IB_WR_REG_MR;
1887 wr->wr.wr_id = IBLND_WID_MR;
1889 wr->wr.send_flags = 0;
1891 wr->key = is_rx ? mr->rkey : mr->lkey;
1892 wr->access = (IB_ACCESS_LOCAL_WRITE |
1893 IB_ACCESS_REMOTE_WRITE);
1894 #else /* HAVE_IB_MAP_MR_SG */
1895 if (!tx_pages_mapped) {
1896 npages = kiblnd_map_tx_pages(tx, rd);
1897 tx_pages_mapped = true;
1900 LASSERT(npages <= frpl->max_page_list_len);
1901 memcpy(frpl->page_list, pages,
1902 sizeof(*pages) * npages);
1904 /* Prepare FastReg WR */
1905 wr = &frd->frd_fastreg_wr;
1906 memset(wr, 0, sizeof(*wr));
1908 wr->wr.opcode = IB_WR_FAST_REG_MR;
1909 wr->wr.wr_id = IBLND_WID_MR;
1911 wr->wr.wr.fast_reg.iova_start = iov;
1912 wr->wr.wr.fast_reg.page_list = frpl;
1913 wr->wr.wr.fast_reg.page_list_len = npages;
1914 wr->wr.wr.fast_reg.page_shift = PAGE_SHIFT;
1915 wr->wr.wr.fast_reg.length = nob;
1916 wr->wr.wr.fast_reg.rkey =
1917 is_rx ? mr->rkey : mr->lkey;
1918 wr->wr.wr.fast_reg.access_flags =
1919 (IB_ACCESS_LOCAL_WRITE |
1920 IB_ACCESS_REMOTE_WRITE);
1921 #endif /* HAVE_IB_MAP_MR_SG */
1923 fmr->fmr_key = is_rx ? mr->rkey : mr->lkey;
1925 fmr->fmr_pool = fpo;
1926 frd->frd_posted = false;
1929 spin_unlock(&fps->fps_lock);
1933 spin_lock(&fps->fps_lock);
1934 fpo->fpo_map_count--;
1935 if (rc != -EAGAIN) {
1936 spin_unlock(&fps->fps_lock);
1940 /* EAGAIN and ... */
1941 if (version != fps->fps_version) {
1942 spin_unlock(&fps->fps_lock);
1947 if (fps->fps_increasing) {
1948 spin_unlock(&fps->fps_lock);
1949 CDEBUG(D_NET, "Another thread is allocating new "
1950 "FMR pool, waiting for her to complete\n");
1951 wait_var_event(fps, !fps->fps_increasing);
1956 if (ktime_get_seconds() < fps->fps_next_retry) {
1957 /* someone failed recently */
1958 spin_unlock(&fps->fps_lock);
1962 fps->fps_increasing = 1;
1963 spin_unlock(&fps->fps_lock);
1965 CDEBUG(D_NET, "Allocate new FMR pool\n");
1966 rc = kiblnd_create_fmr_pool(fps, &fpo);
1967 spin_lock(&fps->fps_lock);
1968 fps->fps_increasing = 0;
1972 list_add_tail(&fpo->fpo_list, &fps->fps_pool_list);
1974 fps->fps_next_retry = ktime_get_seconds() + IBLND_POOL_RETRY;
1976 spin_unlock(&fps->fps_lock);
1982 kiblnd_fini_pool(struct kib_pool *pool)
1984 LASSERT(list_empty(&pool->po_free_list));
1985 LASSERT(pool->po_allocated == 0);
1987 CDEBUG(D_NET, "Finalize %s pool\n", pool->po_owner->ps_name);
1991 kiblnd_init_pool(struct kib_poolset *ps, struct kib_pool *pool, int size)
1993 CDEBUG(D_NET, "Initialize %s pool\n", ps->ps_name);
1995 memset(pool, 0, sizeof(struct kib_pool));
1996 INIT_LIST_HEAD(&pool->po_free_list);
1997 pool->po_deadline = ktime_get_seconds() + IBLND_POOL_DEADLINE;
1998 pool->po_owner = ps;
1999 pool->po_size = size;
2003 kiblnd_destroy_pool_list(struct list_head *head)
2005 struct kib_pool *pool;
2007 while ((pool = list_first_entry_or_null(head,
2009 po_list)) != NULL) {
2010 list_del(&pool->po_list);
2012 LASSERT(pool->po_owner != NULL);
2013 pool->po_owner->ps_pool_destroy(pool);
2018 kiblnd_fail_poolset(struct kib_poolset *ps, struct list_head *zombies)
2020 struct kib_pool *po;
2022 if (ps->ps_net == NULL) /* intialized? */
2025 spin_lock(&ps->ps_lock);
2026 while ((po = list_first_entry_or_null(&ps->ps_pool_list,
2028 po_list)) != NULL) {
2030 if (po->po_allocated == 0)
2031 list_move(&po->po_list, zombies);
2033 list_move(&po->po_list, &ps->ps_failed_pool_list);
2035 spin_unlock(&ps->ps_lock);
2039 kiblnd_fini_poolset(struct kib_poolset *ps)
2041 if (ps->ps_net != NULL) { /* initialized? */
2042 kiblnd_destroy_pool_list(&ps->ps_failed_pool_list);
2043 kiblnd_destroy_pool_list(&ps->ps_pool_list);
2048 kiblnd_init_poolset(struct kib_poolset *ps, int cpt,
2049 struct kib_net *net, char *name, int size,
2050 kib_ps_pool_create_t po_create,
2051 kib_ps_pool_destroy_t po_destroy,
2052 kib_ps_node_init_t nd_init,
2053 kib_ps_node_fini_t nd_fini)
2055 struct kib_pool *pool;
2058 memset(ps, 0, sizeof(struct kib_poolset));
2062 ps->ps_pool_create = po_create;
2063 ps->ps_pool_destroy = po_destroy;
2064 ps->ps_node_init = nd_init;
2065 ps->ps_node_fini = nd_fini;
2066 ps->ps_pool_size = size;
2067 if (strlcpy(ps->ps_name, name, sizeof(ps->ps_name))
2068 >= sizeof(ps->ps_name))
2070 spin_lock_init(&ps->ps_lock);
2071 INIT_LIST_HEAD(&ps->ps_pool_list);
2072 INIT_LIST_HEAD(&ps->ps_failed_pool_list);
2074 rc = ps->ps_pool_create(ps, size, &pool);
2076 list_add(&pool->po_list, &ps->ps_pool_list);
2078 CERROR("Failed to create the first pool for %s\n", ps->ps_name);
2084 kiblnd_pool_is_idle(struct kib_pool *pool, time64_t now)
2086 if (pool->po_allocated != 0) /* still in use */
2088 if (pool->po_failed)
2090 return now >= pool->po_deadline;
2094 kiblnd_pool_free_node(struct kib_pool *pool, struct list_head *node)
2097 struct kib_poolset *ps = pool->po_owner;
2098 struct kib_pool *tmp;
2099 time64_t now = ktime_get_seconds();
2101 spin_lock(&ps->ps_lock);
2103 if (ps->ps_node_fini != NULL)
2104 ps->ps_node_fini(pool, node);
2106 LASSERT(pool->po_allocated > 0);
2107 list_add(node, &pool->po_free_list);
2108 pool->po_allocated--;
2110 list_for_each_entry_safe(pool, tmp, &ps->ps_pool_list, po_list) {
2111 /* the first pool is persistent */
2112 if (ps->ps_pool_list.next == &pool->po_list)
2115 if (kiblnd_pool_is_idle(pool, now))
2116 list_move(&pool->po_list, &zombies);
2118 spin_unlock(&ps->ps_lock);
2120 if (!list_empty(&zombies))
2121 kiblnd_destroy_pool_list(&zombies);
2125 kiblnd_pool_alloc_node(struct kib_poolset *ps)
2127 struct list_head *node;
2128 struct kib_pool *pool;
2130 unsigned int interval = 1;
2131 ktime_t time_before;
2132 unsigned int trips = 0;
2135 spin_lock(&ps->ps_lock);
2136 list_for_each_entry(pool, &ps->ps_pool_list, po_list) {
2137 if (list_empty(&pool->po_free_list))
2140 pool->po_allocated++;
2141 pool->po_deadline = ktime_get_seconds() +
2142 IBLND_POOL_DEADLINE;
2143 node = pool->po_free_list.next;
2146 if (ps->ps_node_init != NULL) {
2147 /* still hold the lock */
2148 ps->ps_node_init(pool, node);
2150 spin_unlock(&ps->ps_lock);
2154 /* no available tx pool and ... */
2155 if (ps->ps_increasing) {
2156 /* another thread is allocating a new pool */
2157 spin_unlock(&ps->ps_lock);
2160 "Another thread is allocating new %s pool, waiting %d jiffies for her to complete. trips = %d\n",
2161 ps->ps_name, interval, trips);
2163 schedule_timeout_interruptible(interval);
2164 if (interval < cfs_time_seconds(1))
2170 if (ktime_get_seconds() < ps->ps_next_retry) {
2171 /* someone failed recently */
2172 spin_unlock(&ps->ps_lock);
2176 ps->ps_increasing = 1;
2177 spin_unlock(&ps->ps_lock);
2179 CDEBUG(D_NET, "%s pool exhausted, allocate new pool\n", ps->ps_name);
2180 time_before = ktime_get();
2181 rc = ps->ps_pool_create(ps, ps->ps_pool_size, &pool);
2182 CDEBUG(D_NET, "ps_pool_create took %lld ms to complete",
2183 ktime_ms_delta(ktime_get(), time_before));
2185 spin_lock(&ps->ps_lock);
2186 ps->ps_increasing = 0;
2188 list_add_tail(&pool->po_list, &ps->ps_pool_list);
2190 ps->ps_next_retry = ktime_get_seconds() + IBLND_POOL_RETRY;
2191 CERROR("Can't allocate new %s pool because out of memory\n",
2194 spin_unlock(&ps->ps_lock);
2200 kiblnd_destroy_tx_pool(struct kib_pool *pool)
2202 struct kib_tx_pool *tpo = container_of(pool, struct kib_tx_pool,
2206 LASSERT (pool->po_allocated == 0);
2208 if (tpo->tpo_tx_pages != NULL) {
2209 kiblnd_unmap_tx_pool(tpo);
2210 kiblnd_free_pages(tpo->tpo_tx_pages);
2213 if (tpo->tpo_tx_descs == NULL)
2216 for (i = 0; i < pool->po_size; i++) {
2217 struct kib_tx *tx = &tpo->tpo_tx_descs[i];
2218 int wrq_sge = *kiblnd_tunables.kib_wrq_sge;
2220 list_del(&tx->tx_list);
2221 if (tx->tx_pages != NULL)
2222 CFS_FREE_PTR_ARRAY(tx->tx_pages, LNET_MAX_IOV);
2223 if (tx->tx_frags != NULL)
2224 CFS_FREE_PTR_ARRAY(tx->tx_frags,
2225 (1 + IBLND_MAX_RDMA_FRAGS));
2226 if (tx->tx_wrq != NULL)
2227 CFS_FREE_PTR_ARRAY(tx->tx_wrq,
2228 (1 + IBLND_MAX_RDMA_FRAGS));
2229 if (tx->tx_sge != NULL)
2230 CFS_FREE_PTR_ARRAY(tx->tx_sge,
2231 (1 + IBLND_MAX_RDMA_FRAGS) *
2233 if (tx->tx_rd != NULL)
2234 LIBCFS_FREE(tx->tx_rd,
2235 offsetof(struct kib_rdma_desc,
2236 rd_frags[IBLND_MAX_RDMA_FRAGS]));
2239 CFS_FREE_PTR_ARRAY(tpo->tpo_tx_descs, pool->po_size);
2241 kiblnd_fini_pool(pool);
2245 static int kiblnd_tx_pool_size(struct lnet_ni *ni, int ncpts)
2247 struct lnet_ioctl_config_o2iblnd_tunables *tunables;
2250 tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib;
2251 ntx = tunables->lnd_ntx / ncpts;
2253 return max(IBLND_TX_POOL, ntx);
2257 kiblnd_create_tx_pool(struct kib_poolset *ps, int size, struct kib_pool **pp_po)
2261 struct kib_pool *pool;
2262 struct kib_tx_pool *tpo;
2264 LIBCFS_CPT_ALLOC(tpo, lnet_cpt_table(), ps->ps_cpt, sizeof(*tpo));
2266 CERROR("Failed to allocate TX pool\n");
2270 pool = &tpo->tpo_pool;
2271 kiblnd_init_pool(ps, pool, size);
2272 tpo->tpo_tx_descs = NULL;
2273 tpo->tpo_tx_pages = NULL;
2275 npg = (size * IBLND_MSG_SIZE + PAGE_SIZE - 1) / PAGE_SIZE;
2276 if (kiblnd_alloc_pages(&tpo->tpo_tx_pages, ps->ps_cpt, npg) != 0) {
2277 CERROR("Can't allocate tx pages: %d\n", npg);
2282 LIBCFS_CPT_ALLOC(tpo->tpo_tx_descs, lnet_cpt_table(), ps->ps_cpt,
2283 size * sizeof(struct kib_tx));
2284 if (tpo->tpo_tx_descs == NULL) {
2285 CERROR("Can't allocate %d tx descriptors\n", size);
2286 ps->ps_pool_destroy(pool);
2290 memset(tpo->tpo_tx_descs, 0, size * sizeof(struct kib_tx));
2292 for (i = 0; i < size; i++) {
2293 struct kib_tx *tx = &tpo->tpo_tx_descs[i];
2294 int wrq_sge = *kiblnd_tunables.kib_wrq_sge;
2297 if (ps->ps_net->ibn_fmr_ps != NULL) {
2298 LIBCFS_CPT_ALLOC(tx->tx_pages,
2299 lnet_cpt_table(), ps->ps_cpt,
2300 LNET_MAX_IOV * sizeof(*tx->tx_pages));
2301 if (tx->tx_pages == NULL)
2305 LIBCFS_CPT_ALLOC(tx->tx_frags, lnet_cpt_table(), ps->ps_cpt,
2306 (1 + IBLND_MAX_RDMA_FRAGS) *
2307 sizeof(*tx->tx_frags));
2308 if (tx->tx_frags == NULL)
2311 sg_init_table(tx->tx_frags, IBLND_MAX_RDMA_FRAGS + 1);
2313 LIBCFS_CPT_ALLOC(tx->tx_wrq, lnet_cpt_table(), ps->ps_cpt,
2314 (1 + IBLND_MAX_RDMA_FRAGS) *
2315 sizeof(*tx->tx_wrq));
2316 if (tx->tx_wrq == NULL)
2319 LIBCFS_CPT_ALLOC(tx->tx_sge, lnet_cpt_table(), ps->ps_cpt,
2320 (1 + IBLND_MAX_RDMA_FRAGS) * wrq_sge *
2321 sizeof(*tx->tx_sge));
2322 if (tx->tx_sge == NULL)
2325 LIBCFS_CPT_ALLOC(tx->tx_rd, lnet_cpt_table(), ps->ps_cpt,
2326 offsetof(struct kib_rdma_desc,
2327 rd_frags[IBLND_MAX_RDMA_FRAGS]));
2328 if (tx->tx_rd == NULL)
2333 kiblnd_map_tx_pool(tpo);
2338 ps->ps_pool_destroy(pool);
2343 kiblnd_tx_init(struct kib_pool *pool, struct list_head *node)
2345 struct kib_tx_poolset *tps = container_of(pool->po_owner,
2346 struct kib_tx_poolset,
2348 struct kib_tx *tx = list_entry(node, struct kib_tx, tx_list);
2350 tx->tx_cookie = tps->tps_next_tx_cookie++;
2354 kiblnd_net_fini_pools(struct kib_net *net)
2358 cfs_cpt_for_each(i, lnet_cpt_table()) {
2359 struct kib_tx_poolset *tps;
2360 struct kib_fmr_poolset *fps;
2362 if (net->ibn_tx_ps != NULL) {
2363 tps = net->ibn_tx_ps[i];
2364 kiblnd_fini_poolset(&tps->tps_poolset);
2367 if (net->ibn_fmr_ps != NULL) {
2368 fps = net->ibn_fmr_ps[i];
2369 kiblnd_fini_fmr_poolset(fps);
2373 if (net->ibn_tx_ps != NULL) {
2374 cfs_percpt_free(net->ibn_tx_ps);
2375 net->ibn_tx_ps = NULL;
2378 if (net->ibn_fmr_ps != NULL) {
2379 cfs_percpt_free(net->ibn_fmr_ps);
2380 net->ibn_fmr_ps = NULL;
2385 kiblnd_net_init_pools(struct kib_net *net, struct lnet_ni *ni, __u32 *cpts,
2388 struct lnet_ioctl_config_o2iblnd_tunables *tunables;
2389 #ifdef HAVE_IB_GET_DMA_MR
2390 unsigned long flags;
2396 tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_o2ib;
2398 #ifdef HAVE_IB_GET_DMA_MR
2399 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2401 * if lnd_map_on_demand is zero then we have effectively disabled
2402 * FMR or FastReg and we're using global memory regions
2405 if (!tunables->lnd_map_on_demand) {
2406 read_unlock_irqrestore(&kiblnd_data.kib_global_lock,
2408 goto create_tx_pool;
2411 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2414 if (tunables->lnd_fmr_pool_size < tunables->lnd_ntx / 4) {
2415 CERROR("Can't set fmr pool size (%d) < ntx / 4(%d)\n",
2416 tunables->lnd_fmr_pool_size,
2417 tunables->lnd_ntx / 4);
2422 /* TX pool must be created later than FMR, see LU-2268
2424 LASSERT(net->ibn_tx_ps == NULL);
2426 /* premapping can fail if ibd_nmr > 1, so we always create
2427 * FMR pool and map-on-demand if premapping failed */
2429 net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
2430 sizeof(struct kib_fmr_poolset));
2431 if (net->ibn_fmr_ps == NULL) {
2432 CERROR("Failed to allocate FMR pool array\n");
2437 for (i = 0; i < ncpts; i++) {
2438 cpt = (cpts == NULL) ? i : cpts[i];
2439 rc = kiblnd_init_fmr_poolset(net->ibn_fmr_ps[cpt], cpt, ncpts,
2442 CERROR("Can't initialize FMR pool for CPT %d: %d\n",
2449 LASSERT(i == ncpts);
2451 #ifdef HAVE_IB_GET_DMA_MR
2454 net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
2455 sizeof(struct kib_tx_poolset));
2456 if (net->ibn_tx_ps == NULL) {
2457 CERROR("Failed to allocate tx pool array\n");
2462 for (i = 0; i < ncpts; i++) {
2463 cpt = (cpts == NULL) ? i : cpts[i];
2464 rc = kiblnd_init_poolset(&net->ibn_tx_ps[cpt]->tps_poolset,
2466 kiblnd_tx_pool_size(ni, ncpts),
2467 kiblnd_create_tx_pool,
2468 kiblnd_destroy_tx_pool,
2469 kiblnd_tx_init, NULL);
2471 CERROR("Can't initialize TX pool for CPT %d: %d\n",
2479 kiblnd_net_fini_pools(net);
2485 kiblnd_port_get_attr(struct kib_hca_dev *hdev)
2487 struct ib_port_attr *port_attr;
2489 unsigned long flags;
2490 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
2492 LIBCFS_ALLOC(port_attr, sizeof(*port_attr));
2493 if (port_attr == NULL) {
2494 CDEBUG(D_NETERROR, "Out of memory\n");
2498 rc = ib_query_port(hdev->ibh_ibdev, hdev->ibh_port, port_attr);
2500 write_lock_irqsave(g_lock, flags);
2503 hdev->ibh_state = port_attr->state == IB_PORT_ACTIVE
2504 ? IBLND_DEV_PORT_ACTIVE
2505 : IBLND_DEV_PORT_DOWN;
2507 write_unlock_irqrestore(g_lock, flags);
2508 LIBCFS_FREE(port_attr, sizeof(*port_attr));
2511 CDEBUG(D_NETERROR, "Failed to query IB port: %d\n", rc);
2518 kiblnd_set_ni_fatal_on(struct kib_hca_dev *hdev, int val)
2520 struct kib_net *net;
2522 /* for health check */
2523 list_for_each_entry(net, &hdev->ibh_dev->ibd_nets, ibn_list) {
2525 CDEBUG(D_NETERROR, "Fatal device error for NI %s\n",
2526 libcfs_nidstr(&net->ibn_ni->ni_nid));
2527 atomic_set(&net->ibn_ni->ni_fatal_error_on, val);
2532 kiblnd_event_handler(struct ib_event_handler *handler, struct ib_event *event)
2534 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
2535 struct kib_hca_dev *hdev;
2536 unsigned long flags;
2538 hdev = container_of(handler, struct kib_hca_dev, ibh_event_handler);
2540 write_lock_irqsave(g_lock, flags);
2542 switch (event->event) {
2543 case IB_EVENT_DEVICE_FATAL:
2544 CDEBUG(D_NET, "IB device fatal\n");
2545 hdev->ibh_state = IBLND_DEV_FATAL;
2546 kiblnd_set_ni_fatal_on(hdev, 1);
2548 case IB_EVENT_PORT_ACTIVE:
2549 CDEBUG(D_NET, "IB port active\n");
2550 if (event->element.port_num == hdev->ibh_port) {
2551 hdev->ibh_state = IBLND_DEV_PORT_ACTIVE;
2552 kiblnd_set_ni_fatal_on(hdev, 0);
2555 case IB_EVENT_PORT_ERR:
2556 CDEBUG(D_NET, "IB port err\n");
2557 if (event->element.port_num == hdev->ibh_port) {
2558 hdev->ibh_state = IBLND_DEV_PORT_DOWN;
2559 kiblnd_set_ni_fatal_on(hdev, 1);
2565 write_unlock_irqrestore(g_lock, flags);
2569 kiblnd_hdev_get_attr(struct kib_hca_dev *hdev)
2571 struct ib_device_attr *dev_attr;
2575 /* It's safe to assume a HCA can handle a page size
2576 * matching that of the native system */
2577 hdev->ibh_page_shift = PAGE_SHIFT;
2578 hdev->ibh_page_size = 1 << PAGE_SHIFT;
2579 hdev->ibh_page_mask = ~((__u64)hdev->ibh_page_size - 1);
2581 #ifndef HAVE_IB_DEVICE_ATTRS
2582 LIBCFS_ALLOC(dev_attr, sizeof(*dev_attr));
2583 if (dev_attr == NULL) {
2584 CERROR("Out of memory\n");
2588 rc = ib_query_device(hdev->ibh_ibdev, dev_attr);
2590 CERROR("Failed to query IB device: %d\n", rc);
2591 goto out_clean_attr;
2594 dev_attr = &hdev->ibh_ibdev->attrs;
2597 hdev->ibh_mr_size = dev_attr->max_mr_size;
2598 hdev->ibh_max_qp_wr = dev_attr->max_qp_wr;
2600 /* Setup device Memory Registration capabilities */
2601 #ifdef HAVE_FMR_POOL_API
2602 #ifdef HAVE_IB_DEVICE_OPS
2603 if (hdev->ibh_ibdev->ops.alloc_fmr &&
2604 hdev->ibh_ibdev->ops.dealloc_fmr &&
2605 hdev->ibh_ibdev->ops.map_phys_fmr &&
2606 hdev->ibh_ibdev->ops.unmap_fmr) {
2608 if (hdev->ibh_ibdev->alloc_fmr &&
2609 hdev->ibh_ibdev->dealloc_fmr &&
2610 hdev->ibh_ibdev->map_phys_fmr &&
2611 hdev->ibh_ibdev->unmap_fmr) {
2613 LCONSOLE_INFO("Using FMR for registration\n");
2614 hdev->ibh_dev->ibd_dev_caps |= IBLND_DEV_CAPS_FMR_ENABLED;
2616 #endif /* HAVE_FMR_POOL_API */
2617 if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS) {
2618 LCONSOLE_INFO("Using FastReg for registration\n");
2619 hdev->ibh_dev->ibd_dev_caps |= IBLND_DEV_CAPS_FASTREG_ENABLED;
2620 #ifndef HAVE_IB_ALLOC_FAST_REG_MR
2621 #ifdef IB_DEVICE_SG_GAPS_REG
2622 if (dev_attr->device_cap_flags & IB_DEVICE_SG_GAPS_REG)
2623 hdev->ibh_dev->ibd_dev_caps |= IBLND_DEV_CAPS_FASTREG_GAPS_SUPPORT;
2630 rc2 = kiblnd_port_get_attr(hdev);
2637 #ifndef HAVE_IB_DEVICE_ATTRS
2639 LIBCFS_FREE(dev_attr, sizeof(*dev_attr));
2643 CERROR("IB device does not support FMRs nor FastRegs, can't "
2644 "register memory: %d\n", rc);
2645 else if (rc == -EINVAL)
2646 CERROR("Invalid mr size: %#llx\n", hdev->ibh_mr_size);
2650 #ifdef HAVE_IB_GET_DMA_MR
2652 kiblnd_hdev_cleanup_mrs(struct kib_hca_dev *hdev)
2654 if (hdev->ibh_mrs == NULL)
2657 ib_dereg_mr(hdev->ibh_mrs);
2659 hdev->ibh_mrs = NULL;
2664 kiblnd_hdev_destroy(struct kib_hca_dev *hdev)
2666 if (hdev->ibh_event_handler.device != NULL)
2667 ib_unregister_event_handler(&hdev->ibh_event_handler);
2669 #ifdef HAVE_IB_GET_DMA_MR
2670 kiblnd_hdev_cleanup_mrs(hdev);
2673 if (hdev->ibh_pd != NULL)
2674 ib_dealloc_pd(hdev->ibh_pd);
2676 if (hdev->ibh_cmid != NULL)
2677 rdma_destroy_id(hdev->ibh_cmid);
2679 LIBCFS_FREE(hdev, sizeof(*hdev));
2682 #ifdef HAVE_IB_GET_DMA_MR
2684 kiblnd_hdev_setup_mrs(struct kib_hca_dev *hdev)
2687 int acflags = IB_ACCESS_LOCAL_WRITE |
2688 IB_ACCESS_REMOTE_WRITE;
2690 mr = ib_get_dma_mr(hdev->ibh_pd, acflags);
2692 CERROR("Failed ib_get_dma_mr: %ld\n", PTR_ERR(mr));
2693 kiblnd_hdev_cleanup_mrs(hdev);
2704 kiblnd_dummy_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
2709 static int kiblnd_get_link_status(struct net_device *dev)
2715 if (!netif_running(dev))
2717 /* Some devices may not be providing link settings */
2718 else if (dev->ethtool_ops->get_link)
2719 ret = dev->ethtool_ops->get_link(dev);
2725 kiblnd_dev_need_failover(struct kib_dev *dev, struct net *ns)
2727 struct rdma_cm_id *cmid;
2728 struct sockaddr_in srcaddr;
2729 struct sockaddr_in dstaddr;
2732 if (dev->ibd_hdev == NULL || /* initializing */
2733 dev->ibd_hdev->ibh_cmid == NULL || /* listener is dead */
2734 *kiblnd_tunables.kib_dev_failover > 1) /* debugging */
2737 /* XXX: it's UGLY, but I don't have better way to find
2738 * ib-bonding HCA failover because:
2740 * a. no reliable CM event for HCA failover...
2741 * b. no OFED API to get ib_device for current net_device...
2743 * We have only two choices at this point:
2745 * a. rdma_bind_addr(), it will conflict with listener cmid
2746 * b. rdma_resolve_addr() to zero addr */
2747 cmid = kiblnd_rdma_create_id(ns, kiblnd_dummy_callback, dev,
2748 RDMA_PS_TCP, IB_QPT_RC);
2751 CERROR("Failed to create cmid for failover: %d\n", rc);
2755 memset(&srcaddr, 0, sizeof(srcaddr));
2756 srcaddr.sin_family = AF_INET;
2757 srcaddr.sin_addr.s_addr = (__force u32)htonl(dev->ibd_ifip);
2759 memset(&dstaddr, 0, sizeof(dstaddr));
2760 dstaddr.sin_family = AF_INET;
2761 rc = rdma_resolve_addr(cmid, (struct sockaddr *)&srcaddr,
2762 (struct sockaddr *)&dstaddr, 1);
2763 if (rc != 0 || cmid->device == NULL) {
2764 CERROR("Failed to bind %s:%pI4h to device(%p): %d\n",
2765 dev->ibd_ifname, &dev->ibd_ifip,
2767 rdma_destroy_id(cmid);
2771 rc = dev->ibd_hdev->ibh_ibdev != cmid->device; /* true for failover */
2772 rdma_destroy_id(cmid);
2777 kiblnd_dev_failover(struct kib_dev *dev, struct net *ns)
2779 LIST_HEAD(zombie_tpo);
2780 LIST_HEAD(zombie_ppo);
2781 LIST_HEAD(zombie_fpo);
2782 struct rdma_cm_id *cmid = NULL;
2783 struct kib_hca_dev *hdev = NULL;
2784 struct kib_hca_dev *old;
2786 struct kib_net *net;
2787 struct sockaddr_in addr;
2788 struct net_device *netdev;
2789 unsigned long flags;
2793 LASSERT(*kiblnd_tunables.kib_dev_failover > 1 ||
2794 dev->ibd_can_failover ||
2795 dev->ibd_hdev == NULL);
2797 rc = kiblnd_dev_need_failover(dev, ns);
2801 if (dev->ibd_hdev != NULL &&
2802 dev->ibd_hdev->ibh_cmid != NULL) {
2803 /* XXX it's not good to close old listener at here,
2804 * because we can fail to create new listener.
2805 * But we have to close it now, otherwise rdma_bind_addr
2806 * will return EADDRINUSE... How crap! */
2807 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2809 cmid = dev->ibd_hdev->ibh_cmid;
2810 /* make next schedule of kiblnd_dev_need_failover()
2811 * return 1 for me */
2812 dev->ibd_hdev->ibh_cmid = NULL;
2813 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2815 rdma_destroy_id(cmid);
2818 cmid = kiblnd_rdma_create_id(ns, kiblnd_cm_callback, dev, RDMA_PS_TCP,
2822 CERROR("Failed to create cmid for failover: %d\n", rc);
2826 memset(&addr, 0, sizeof(addr));
2827 addr.sin_family = AF_INET;
2828 addr.sin_addr.s_addr = (__force u32)htonl(dev->ibd_ifip);
2829 addr.sin_port = htons(*kiblnd_tunables.kib_service);
2831 /* Bind to failover device or port */
2832 rc = rdma_bind_addr(cmid, (struct sockaddr *)&addr);
2833 if (rc != 0 || cmid->device == NULL) {
2834 CERROR("Failed to bind %s:%pI4h to device(%p): %d\n",
2835 dev->ibd_ifname, &dev->ibd_ifip,
2837 rdma_destroy_id(cmid);
2841 LIBCFS_ALLOC(hdev, sizeof(*hdev));
2843 CERROR("Failed to allocate kib_hca_dev\n");
2844 rdma_destroy_id(cmid);
2849 atomic_set(&hdev->ibh_ref, 1);
2850 hdev->ibh_dev = dev;
2851 hdev->ibh_cmid = cmid;
2852 hdev->ibh_ibdev = cmid->device;
2853 hdev->ibh_port = cmid->port_num;
2855 #ifdef HAVE_IB_ALLOC_PD_2ARGS
2856 pd = ib_alloc_pd(cmid->device, 0);
2858 pd = ib_alloc_pd(cmid->device);
2862 CERROR("Can't allocate PD: %d\n", rc);
2868 rc = rdma_listen(cmid, 0);
2870 CERROR("Can't start new listener: %d\n", rc);
2874 rc = kiblnd_hdev_get_attr(hdev);
2876 CERROR("Can't get device attributes: %d\n", rc);
2880 #ifdef HAVE_IB_GET_DMA_MR
2881 rc = kiblnd_hdev_setup_mrs(hdev);
2883 CERROR("Can't setup device: %d\n", rc);
2888 INIT_IB_EVENT_HANDLER(&hdev->ibh_event_handler,
2889 hdev->ibh_ibdev, kiblnd_event_handler);
2890 ib_register_event_handler(&hdev->ibh_event_handler);
2892 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
2894 old = dev->ibd_hdev;
2895 dev->ibd_hdev = hdev; /* take over the refcount */
2898 list_for_each_entry(net, &dev->ibd_nets, ibn_list) {
2899 cfs_cpt_for_each(i, lnet_cpt_table()) {
2900 kiblnd_fail_poolset(&net->ibn_tx_ps[i]->tps_poolset,
2903 if (net->ibn_fmr_ps != NULL)
2904 kiblnd_fail_fmr_poolset(net->ibn_fmr_ps[i],
2909 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2911 if (!list_empty(&zombie_tpo))
2912 kiblnd_destroy_pool_list(&zombie_tpo);
2913 if (!list_empty(&zombie_ppo))
2914 kiblnd_destroy_pool_list(&zombie_ppo);
2915 if (!list_empty(&zombie_fpo))
2916 kiblnd_destroy_fmr_pool_list(&zombie_fpo);
2918 kiblnd_hdev_decref(hdev);
2921 dev->ibd_failed_failover++;
2923 dev->ibd_failed_failover = 0;
2926 netdev = dev_get_by_name_rcu(ns, dev->ibd_ifname);
2927 if (netdev && (kiblnd_get_link_status(netdev) == 1))
2928 kiblnd_set_ni_fatal_on(dev->ibd_hdev, 0);
2936 kiblnd_destroy_dev(struct kib_dev *dev)
2938 LASSERT(dev->ibd_nnets == 0);
2939 LASSERT(list_empty(&dev->ibd_nets));
2941 list_del(&dev->ibd_fail_list);
2942 list_del(&dev->ibd_list);
2944 if (dev->ibd_hdev != NULL)
2945 kiblnd_hdev_decref(dev->ibd_hdev);
2947 LIBCFS_FREE(dev, sizeof(*dev));
2951 kiblnd_base_shutdown(void)
2953 struct kib_sched_info *sched;
2954 struct kib_peer_ni *peer_ni;
2957 LASSERT(list_empty(&kiblnd_data.kib_devs));
2959 CDEBUG(D_MALLOC, "before LND base cleanup: kmem %lld\n",
2960 libcfs_kmem_read());
2962 switch (kiblnd_data.kib_init) {
2966 case IBLND_INIT_ALL:
2967 case IBLND_INIT_DATA:
2968 hash_for_each(kiblnd_data.kib_peers, i, peer_ni, ibp_list)
2970 LASSERT(list_empty(&kiblnd_data.kib_connd_zombies));
2971 LASSERT(list_empty(&kiblnd_data.kib_connd_conns));
2972 LASSERT(list_empty(&kiblnd_data.kib_reconn_list));
2973 LASSERT(list_empty(&kiblnd_data.kib_reconn_wait));
2975 /* flag threads to terminate; wake and wait for them to die */
2976 kiblnd_data.kib_shutdown = 1;
2978 /* NB: we really want to stop scheduler threads net by net
2979 * instead of the whole module, this should be improved
2980 * with dynamic configuration LNet.
2982 cfs_percpt_for_each(sched, i, kiblnd_data.kib_scheds)
2983 wake_up_all(&sched->ibs_waitq);
2985 wake_up(&kiblnd_data.kib_connd_waitq);
2986 wake_up(&kiblnd_data.kib_failover_waitq);
2988 wait_var_event_warning(&kiblnd_data.kib_nthreads,
2989 !atomic_read(&kiblnd_data.kib_nthreads),
2990 "Waiting for %d threads to terminate\n",
2991 atomic_read(&kiblnd_data.kib_nthreads));
2994 case IBLND_INIT_NOTHING:
2998 if (kiblnd_data.kib_scheds != NULL)
2999 cfs_percpt_free(kiblnd_data.kib_scheds);
3001 CDEBUG(D_MALLOC, "after LND base cleanup: kmem %lld\n",
3002 libcfs_kmem_read());
3004 kiblnd_data.kib_init = IBLND_INIT_NOTHING;
3005 module_put(THIS_MODULE);
3009 kiblnd_shutdown(struct lnet_ni *ni)
3011 struct kib_net *net = ni->ni_data;
3012 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
3013 unsigned long flags;
3015 LASSERT(kiblnd_data.kib_init == IBLND_INIT_ALL);
3020 CDEBUG(D_MALLOC, "before LND net cleanup: kmem %lld\n",
3021 libcfs_kmem_read());
3023 write_lock_irqsave(g_lock, flags);
3024 net->ibn_shutdown = 1;
3025 write_unlock_irqrestore(g_lock, flags);
3027 switch (net->ibn_init) {
3031 case IBLND_INIT_ALL:
3032 /* nuke all existing peers within this net */
3033 kiblnd_del_peer(ni, LNET_NID_ANY);
3035 /* Wait for all peer_ni state to clean up */
3036 wait_var_event_warning(&net->ibn_npeers,
3037 atomic_read(&net->ibn_npeers) == 0,
3038 "%s: waiting for %d peers to disconnect\n",
3039 libcfs_nidstr(&ni->ni_nid),
3040 atomic_read(&net->ibn_npeers));
3042 kiblnd_net_fini_pools(net);
3044 write_lock_irqsave(g_lock, flags);
3045 LASSERT(net->ibn_dev->ibd_nnets > 0);
3046 net->ibn_dev->ibd_nnets--;
3047 list_del(&net->ibn_list);
3048 write_unlock_irqrestore(g_lock, flags);
3052 case IBLND_INIT_NOTHING:
3053 LASSERT (atomic_read(&net->ibn_nconns) == 0);
3055 if (net->ibn_dev != NULL &&
3056 net->ibn_dev->ibd_nnets == 0)
3057 kiblnd_destroy_dev(net->ibn_dev);
3062 CDEBUG(D_MALLOC, "after LND net cleanup: kmem %lld\n",
3063 libcfs_kmem_read());
3065 net->ibn_init = IBLND_INIT_NOTHING;
3068 LIBCFS_FREE(net, sizeof(*net));
3071 if (list_empty(&kiblnd_data.kib_devs))
3072 kiblnd_base_shutdown();
3076 kiblnd_base_startup(struct net *ns)
3078 struct kib_sched_info *sched;
3082 LASSERT(kiblnd_data.kib_init == IBLND_INIT_NOTHING);
3084 if (!try_module_get(THIS_MODULE))
3087 memset(&kiblnd_data, 0, sizeof(kiblnd_data)); /* zero pointers, flags etc */
3089 rwlock_init(&kiblnd_data.kib_global_lock);
3091 INIT_LIST_HEAD(&kiblnd_data.kib_devs);
3092 INIT_LIST_HEAD(&kiblnd_data.kib_failed_devs);
3094 hash_init(kiblnd_data.kib_peers);
3096 spin_lock_init(&kiblnd_data.kib_connd_lock);
3097 INIT_LIST_HEAD(&kiblnd_data.kib_connd_conns);
3098 INIT_LIST_HEAD(&kiblnd_data.kib_connd_waits);
3099 INIT_LIST_HEAD(&kiblnd_data.kib_connd_zombies);
3100 INIT_LIST_HEAD(&kiblnd_data.kib_reconn_list);
3101 INIT_LIST_HEAD(&kiblnd_data.kib_reconn_wait);
3103 init_waitqueue_head(&kiblnd_data.kib_connd_waitq);
3104 init_waitqueue_head(&kiblnd_data.kib_failover_waitq);
3106 kiblnd_data.kib_scheds = cfs_percpt_alloc(lnet_cpt_table(),
3108 if (kiblnd_data.kib_scheds == NULL)
3111 cfs_percpt_for_each(sched, i, kiblnd_data.kib_scheds) {
3114 spin_lock_init(&sched->ibs_lock);
3115 INIT_LIST_HEAD(&sched->ibs_conns);
3116 init_waitqueue_head(&sched->ibs_waitq);
3118 nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
3119 if (*kiblnd_tunables.kib_nscheds > 0) {
3120 nthrs = min(nthrs, *kiblnd_tunables.kib_nscheds);
3122 /* max to half of CPUs, another half is reserved for
3123 * upper layer modules */
3124 nthrs = min(max(IBLND_N_SCHED, nthrs >> 1), nthrs);
3127 sched->ibs_nthreads_max = nthrs;
3131 kiblnd_data.kib_error_qpa.qp_state = IB_QPS_ERR;
3133 /* lists/ptrs/locks initialised */
3134 kiblnd_data.kib_init = IBLND_INIT_DATA;
3135 /*****************************************************/
3137 rc = kiblnd_thread_start(kiblnd_connd, NULL, "kiblnd_connd");
3139 CERROR("Can't spawn o2iblnd connd: %d\n", rc);
3143 if (*kiblnd_tunables.kib_dev_failover != 0)
3144 rc = kiblnd_thread_start(kiblnd_failover_thread, ns,
3148 CERROR("Can't spawn o2iblnd failover thread: %d\n", rc);
3152 /* flag everything initialised */
3153 kiblnd_data.kib_init = IBLND_INIT_ALL;
3154 /*****************************************************/
3159 kiblnd_base_shutdown();
3164 kiblnd_start_schedulers(struct kib_sched_info *sched)
3170 if (sched->ibs_nthreads == 0) {
3171 if (*kiblnd_tunables.kib_nscheds > 0) {
3172 nthrs = sched->ibs_nthreads_max;
3174 nthrs = cfs_cpt_weight(lnet_cpt_table(),
3176 nthrs = min(max(IBLND_N_SCHED, nthrs >> 1), nthrs);
3177 nthrs = min(IBLND_N_SCHED_HIGH, nthrs);
3180 LASSERT(sched->ibs_nthreads <= sched->ibs_nthreads_max);
3181 /* increase one thread if there is new interface */
3182 nthrs = (sched->ibs_nthreads < sched->ibs_nthreads_max);
3185 for (i = 0; i < nthrs; i++) {
3186 long id = KIB_THREAD_ID(sched->ibs_cpt, sched->ibs_nthreads + i);
3188 rc = kiblnd_thread_start(kiblnd_scheduler, (void *)id,
3189 "kiblnd_sd_%02ld_%02ld",
3190 KIB_THREAD_CPT(id), KIB_THREAD_TID(id));
3194 CERROR("Can't spawn thread %d for scheduler[%d]: %d\n",
3195 sched->ibs_cpt, sched->ibs_nthreads + i, rc);
3199 sched->ibs_nthreads += i;
3203 static int kiblnd_dev_start_threads(struct kib_dev *dev, bool newdev, u32 *cpts,
3210 for (i = 0; i < ncpts; i++) {
3211 struct kib_sched_info *sched;
3213 cpt = (cpts == NULL) ? i : cpts[i];
3214 sched = kiblnd_data.kib_scheds[cpt];
3216 if (!newdev && sched->ibs_nthreads > 0)
3219 rc = kiblnd_start_schedulers(kiblnd_data.kib_scheds[cpt]);
3221 CERROR("Failed to start scheduler threads for %s\n",
3229 static struct kib_dev *
3230 kiblnd_dev_search(char *ifname)
3232 struct kib_dev *alias = NULL;
3233 struct kib_dev *dev;
3237 colon = strchr(ifname, ':');
3238 list_for_each_entry(dev, &kiblnd_data.kib_devs, ibd_list) {
3239 if (strcmp(&dev->ibd_ifname[0], ifname) == 0)
3245 colon2 = strchr(dev->ibd_ifname, ':');
3251 if (strcmp(&dev->ibd_ifname[0], ifname) == 0)
3263 kiblnd_startup(struct lnet_ni *ni)
3265 char *ifname = NULL;
3266 struct lnet_inetdev *ifaces = NULL;
3267 struct kib_dev *ibdev = NULL;
3268 struct kib_net *net = NULL;
3269 unsigned long flags;
3274 LASSERT(ni->ni_net->net_lnd == &the_o2iblnd);
3276 if (kiblnd_data.kib_init == IBLND_INIT_NOTHING) {
3277 rc = kiblnd_base_startup(ni->ni_net_ns);
3282 LIBCFS_ALLOC(net, sizeof(*net));
3290 net->ibn_incarnation = ktime_get_real_ns() / NSEC_PER_USEC;
3292 kiblnd_tunables_setup(ni);
3295 * Multi-Rail wants each secondary
3296 * IP to be treated as an unique 'struct ni' interface.
3298 if (ni->ni_interface != NULL) {
3299 /* Use the IPoIB interface specified in 'networks=' */
3300 ifname = ni->ni_interface;
3302 ifname = *kiblnd_tunables.kib_default_ipif;
3305 if (strlen(ifname) >= sizeof(ibdev->ibd_ifname)) {
3306 CERROR("IPoIB interface name too long: %s\n", ifname);
3311 rc = lnet_inet_enumerate(&ifaces, ni->ni_net_ns);
3315 for (i = 0; i < rc; i++) {
3316 if (strcmp(ifname, ifaces[i].li_name) == 0)
3321 CERROR("ko2iblnd: No matching interfaces\n");
3326 ibdev = kiblnd_dev_search(ifname);
3327 newdev = ibdev == NULL;
3328 /* hmm...create kib_dev even for alias */
3329 if (ibdev == NULL || strcmp(&ibdev->ibd_ifname[0], ifname) != 0) {
3330 LIBCFS_ALLOC(ibdev, sizeof(*ibdev));
3336 ibdev->ibd_ifip = ifaces[i].li_ipaddr;
3337 strlcpy(ibdev->ibd_ifname, ifaces[i].li_name,
3338 sizeof(ibdev->ibd_ifname));
3339 ibdev->ibd_can_failover = !!(ifaces[i].li_flags & IFF_MASTER);
3341 INIT_LIST_HEAD(&ibdev->ibd_nets);
3342 INIT_LIST_HEAD(&ibdev->ibd_list); /* not yet in kib_devs */
3343 INIT_LIST_HEAD(&ibdev->ibd_fail_list);
3345 /* initialize the device */
3346 rc = kiblnd_dev_failover(ibdev, ni->ni_net_ns);
3348 CERROR("ko2iblnd: Can't initialize device: rc = %d\n",
3353 list_add_tail(&ibdev->ibd_list, &kiblnd_data.kib_devs);
3356 net->ibn_dev = ibdev;
3357 ni->ni_nid.nid_addr[0] = cpu_to_be32(ibdev->ibd_ifip);
3359 ni->ni_dev_cpt = ifaces[i].li_cpt;
3361 rc = kiblnd_dev_start_threads(ibdev, newdev, ni->ni_cpts, ni->ni_ncpts);
3365 rc = kiblnd_net_init_pools(net, ni, ni->ni_cpts, ni->ni_ncpts);
3367 CERROR("Failed to initialize NI pools: %d\n", rc);
3371 write_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
3373 list_add_tail(&net->ibn_list, &ibdev->ibd_nets);
3374 /* for health check */
3375 if (ibdev->ibd_hdev->ibh_state == IBLND_DEV_PORT_DOWN)
3376 kiblnd_set_ni_fatal_on(ibdev->ibd_hdev, 1);
3377 write_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
3379 net->ibn_init = IBLND_INIT_ALL;
3384 if (net != NULL && net->ibn_dev == NULL && ibdev != NULL)
3385 kiblnd_destroy_dev(ibdev);
3388 kiblnd_shutdown(ni);
3390 CDEBUG(D_NET, "Configuration of device %s failed: rc = %d\n",
3391 ifname ? ifname : "", rc);
3396 static const struct lnet_lnd the_o2iblnd = {
3397 .lnd_type = O2IBLND,
3398 .lnd_startup = kiblnd_startup,
3399 .lnd_shutdown = kiblnd_shutdown,
3400 .lnd_ctl = kiblnd_ctl,
3401 .lnd_send = kiblnd_send,
3402 .lnd_recv = kiblnd_recv,
3403 .lnd_get_dev_prio = kiblnd_get_dev_prio,
3406 static void ko2inlnd_assert_wire_constants(void)
3408 BUILD_BUG_ON(IBLND_MSG_MAGIC != 0x0be91b91);
3409 BUILD_BUG_ON(IBLND_MSG_VERSION_1 != 0x11);
3410 BUILD_BUG_ON(IBLND_MSG_VERSION_2 != 0x12);
3411 BUILD_BUG_ON(IBLND_MSG_VERSION != IBLND_MSG_VERSION_2);
3413 BUILD_BUG_ON(IBLND_MSG_CONNREQ != 0xc0);
3414 BUILD_BUG_ON(IBLND_MSG_CONNACK != 0xc1);
3415 BUILD_BUG_ON(IBLND_MSG_NOOP != 0xd0);
3416 BUILD_BUG_ON(IBLND_MSG_IMMEDIATE != 0xd1);
3417 BUILD_BUG_ON(IBLND_MSG_PUT_REQ != 0xd2);
3418 BUILD_BUG_ON(IBLND_MSG_PUT_NAK != 0xd3);
3419 BUILD_BUG_ON(IBLND_MSG_PUT_ACK != 0xd4);
3420 BUILD_BUG_ON(IBLND_MSG_PUT_DONE != 0xd5);
3421 BUILD_BUG_ON(IBLND_MSG_GET_REQ != 0xd6);
3422 BUILD_BUG_ON(IBLND_MSG_GET_DONE != 0xd7);
3424 BUILD_BUG_ON(IBLND_REJECT_CONN_RACE != 1);
3425 BUILD_BUG_ON(IBLND_REJECT_NO_RESOURCES != 2);
3426 BUILD_BUG_ON(IBLND_REJECT_FATAL != 3);
3427 BUILD_BUG_ON(IBLND_REJECT_CONN_UNCOMPAT != 4);
3428 BUILD_BUG_ON(IBLND_REJECT_CONN_STALE != 5);
3429 BUILD_BUG_ON(IBLND_REJECT_RDMA_FRAGS != 6);
3430 BUILD_BUG_ON(IBLND_REJECT_MSG_QUEUE_SIZE != 7);
3431 BUILD_BUG_ON(IBLND_REJECT_INVALID_SRV_ID != 8);
3433 BUILD_BUG_ON((int)sizeof(struct kib_connparams) != 8);
3434 BUILD_BUG_ON((int)offsetof(struct kib_connparams, ibcp_queue_depth) != 0);
3435 BUILD_BUG_ON((int)sizeof(((struct kib_connparams *)0)->ibcp_queue_depth) != 2);
3436 BUILD_BUG_ON((int)offsetof(struct kib_connparams, ibcp_max_frags) != 2);
3437 BUILD_BUG_ON((int)sizeof(((struct kib_connparams *)0)->ibcp_max_frags) != 2);
3438 BUILD_BUG_ON((int)offsetof(struct kib_connparams, ibcp_max_msg_size) != 4);
3439 BUILD_BUG_ON((int)sizeof(((struct kib_connparams *)0)->ibcp_max_msg_size) != 4);
3441 BUILD_BUG_ON((int)sizeof(struct kib_immediate_msg) != 72);
3442 BUILD_BUG_ON((int)offsetof(struct kib_immediate_msg, ibim_hdr) != 0);
3443 BUILD_BUG_ON((int)sizeof(((struct kib_immediate_msg *)0)->ibim_hdr) != 72);
3444 BUILD_BUG_ON((int)offsetof(struct kib_immediate_msg, ibim_payload) != 72);
3445 BUILD_BUG_ON((int)sizeof(((struct kib_immediate_msg *)0)->ibim_payload) != 0);
3447 BUILD_BUG_ON((int)sizeof(struct kib_rdma_frag) != 12);
3448 BUILD_BUG_ON((int)offsetof(struct kib_rdma_frag, rf_nob) != 0);
3449 BUILD_BUG_ON((int)sizeof(((struct kib_rdma_frag *)0)->rf_nob) != 4);
3450 BUILD_BUG_ON((int)offsetof(struct kib_rdma_frag, rf_addr) != 4);
3451 BUILD_BUG_ON((int)sizeof(((struct kib_rdma_frag *)0)->rf_addr) != 8);
3453 BUILD_BUG_ON((int)sizeof(struct kib_rdma_desc) != 8);
3454 BUILD_BUG_ON((int)offsetof(struct kib_rdma_desc, rd_key) != 0);
3455 BUILD_BUG_ON((int)sizeof(((struct kib_rdma_desc *)0)->rd_key) != 4);
3456 BUILD_BUG_ON((int)offsetof(struct kib_rdma_desc, rd_nfrags) != 4);
3457 BUILD_BUG_ON((int)sizeof(((struct kib_rdma_desc *)0)->rd_nfrags) != 4);
3458 BUILD_BUG_ON((int)offsetof(struct kib_rdma_desc, rd_frags) != 8);
3459 BUILD_BUG_ON((int)sizeof(((struct kib_rdma_desc *)0)->rd_frags) != 0);
3461 BUILD_BUG_ON((int)sizeof(struct kib_putreq_msg) != 80);
3462 BUILD_BUG_ON((int)offsetof(struct kib_putreq_msg, ibprm_hdr) != 0);
3463 BUILD_BUG_ON((int)sizeof(((struct kib_putreq_msg *)0)->ibprm_hdr) != 72);
3464 BUILD_BUG_ON((int)offsetof(struct kib_putreq_msg, ibprm_cookie) != 72);
3465 BUILD_BUG_ON((int)sizeof(((struct kib_putreq_msg *)0)->ibprm_cookie) != 8);
3467 BUILD_BUG_ON((int)sizeof(struct kib_putack_msg) != 24);
3468 BUILD_BUG_ON((int)offsetof(struct kib_putack_msg, ibpam_src_cookie) != 0);
3469 BUILD_BUG_ON((int)sizeof(((struct kib_putack_msg *)0)->ibpam_src_cookie) != 8);
3470 BUILD_BUG_ON((int)offsetof(struct kib_putack_msg, ibpam_dst_cookie) != 8);
3471 BUILD_BUG_ON((int)sizeof(((struct kib_putack_msg *)0)->ibpam_dst_cookie) != 8);
3472 BUILD_BUG_ON((int)offsetof(struct kib_putack_msg, ibpam_rd) != 16);
3473 BUILD_BUG_ON((int)sizeof(((struct kib_putack_msg *)0)->ibpam_rd) != 8);
3475 BUILD_BUG_ON((int)sizeof(struct kib_get_msg) != 88);
3476 BUILD_BUG_ON((int)offsetof(struct kib_get_msg, ibgm_hdr) != 0);
3477 BUILD_BUG_ON((int)sizeof(((struct kib_get_msg *)0)->ibgm_hdr) != 72);
3478 BUILD_BUG_ON((int)offsetof(struct kib_get_msg, ibgm_cookie) != 72);
3479 BUILD_BUG_ON((int)sizeof(((struct kib_get_msg *)0)->ibgm_cookie) != 8);
3480 BUILD_BUG_ON((int)offsetof(struct kib_get_msg, ibgm_rd) != 80);
3481 BUILD_BUG_ON((int)sizeof(((struct kib_get_msg *)0)->ibgm_rd) != 8);
3483 BUILD_BUG_ON((int)sizeof(struct kib_completion_msg) != 12);
3484 BUILD_BUG_ON((int)offsetof(struct kib_completion_msg, ibcm_cookie) != 0);
3485 BUILD_BUG_ON((int)sizeof(((struct kib_completion_msg *)0)->ibcm_cookie) != 8);
3486 BUILD_BUG_ON((int)offsetof(struct kib_completion_msg, ibcm_status) != 8);
3487 BUILD_BUG_ON((int)sizeof(((struct kib_completion_msg *)0)->ibcm_status) != 4);
3489 /* Checks for struct kib_msg */
3490 //BUILD_BUG_ON((int)sizeof(struct kib_msg) != 12);
3491 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_magic) != 0);
3492 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_magic) != 4);
3493 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_version) != 4);
3494 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_version) != 2);
3495 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_type) != 6);
3496 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_type) != 1);
3497 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_credits) != 7);
3498 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_credits) != 1);
3499 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_nob) != 8);
3500 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_nob) != 4);
3501 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_cksum) != 12);
3502 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_cksum) != 4);
3503 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_srcnid) != 16);
3504 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_srcnid) != 8);
3505 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_srcstamp) != 24);
3506 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_srcstamp) != 8);
3507 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_dstnid) != 32);
3508 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_dstnid) != 8);
3509 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_dststamp) != 40);
3510 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_dststamp) != 8);
3513 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.connparams.ibcp_queue_depth) != 48);
3514 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.connparams.ibcp_queue_depth) != 2);
3515 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.connparams.ibcp_max_frags) != 50);
3516 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.connparams.ibcp_max_frags) != 2);
3517 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.connparams.ibcp_max_msg_size) != 52);
3518 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.connparams.ibcp_max_msg_size) != 4);
3520 /* Immediate message */
3521 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.immediate.ibim_hdr) != 48);
3522 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.immediate.ibim_hdr) != 72);
3523 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.immediate.ibim_payload) != 120);
3524 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.immediate.ibim_payload) != 0);
3526 /* PUT req message */
3527 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putreq.ibprm_hdr) != 48);
3528 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.putreq.ibprm_hdr) != 72);
3529 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putreq.ibprm_cookie) != 120);
3530 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.putreq.ibprm_cookie) != 8);
3533 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putack.ibpam_src_cookie) != 48);
3534 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.putack.ibpam_src_cookie) != 8);
3535 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putack.ibpam_dst_cookie) != 56);
3536 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.putack.ibpam_dst_cookie) != 8);
3537 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.putack.ibpam_rd) != 64);
3538 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.putack.ibpam_rd) != 8);
3541 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.get.ibgm_hdr) != 48);
3542 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.get.ibgm_hdr) != 72);
3543 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.get.ibgm_cookie) != 120);
3544 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.get.ibgm_cookie) != 8);
3545 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.get.ibgm_rd) != 128);
3546 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.get.ibgm_rd) != 8);
3548 /* Completion message */
3549 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.completion.ibcm_cookie) != 48);
3550 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.completion.ibcm_cookie) != 8);
3551 BUILD_BUG_ON((int)offsetof(struct kib_msg, ibm_u.completion.ibcm_status) != 56);
3552 BUILD_BUG_ON((int)sizeof(((struct kib_msg *)0)->ibm_u.completion.ibcm_status) != 4);
3555 BUILD_BUG_ON(sizeof(struct kib_msg) > IBLND_MSG_SIZE);
3556 BUILD_BUG_ON(offsetof(struct kib_msg,
3557 ibm_u.get.ibgm_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) >
3559 BUILD_BUG_ON(offsetof(struct kib_msg,
3560 ibm_u.putack.ibpam_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) >
3564 static void __exit ko2iblnd_exit(void)
3566 lnet_unregister_lnd(&the_o2iblnd);
3569 static int __init ko2iblnd_init(void)
3573 ko2inlnd_assert_wire_constants();
3575 rc = kiblnd_tunables_init();
3579 lnet_register_lnd(&the_o2iblnd);
3584 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3585 MODULE_DESCRIPTION("OpenIB gen2 LNet Network Driver");
3586 MODULE_VERSION("2.8.0");
3587 MODULE_LICENSE("GPL");
3589 module_init(ko2iblnd_init);
3590 module_exit(ko2iblnd_exit);