Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / lnet / autoconf / lustre-lnet.m4
1 # SPDX-License-Identifier: GPL-2.0
2
3 #
4 # This file is part of Lustre, http://www.lustre.org/
5 #
6
7 # LN_CONFIG_BACKOFF
8 #
9 # check if tunable tcp backoff is available/wanted
10 #
11 AC_DEFUN([LN_CONFIG_BACKOFF], [
12 AC_MSG_CHECKING([whether to enable tunable backoff TCP support])
13 AC_ARG_ENABLE([backoff],
14         AS_HELP_STRING([--disable-backoff],
15                 [disable socknal tunable backoff]),
16         [], [enable_backoff="yes"])
17 AC_MSG_RESULT([$enable_backoff])
18 AS_IF([test "x$enable_backoff" = xyes], [
19         AC_MSG_CHECKING([if Linux kernel has tunable backoff TCP support])
20         AS_IF([grep -c TCP_BACKOFF $LINUX/include/linux/tcp.h >/dev/null], [
21                 AC_MSG_RESULT([yes])
22                 AC_DEFINE(SOCKNAL_BACKOFF, 1, [use tunable backoff TCP])
23                 AS_IF([grep rto_max $LINUX/include/linux/tcp.h | grep -q __u16 >/dev/null],
24                         [AC_DEFINE(SOCKNAL_BACKOFF_MS, 1,
25                                 [tunable backoff TCP in ms])])
26         ], [
27                 AC_MSG_RESULT([no])
28         ])
29
30         AC_SUBST(ENABLE_BACKOFF, yes)
31 ], [
32         AC_SUBST(ENABLE_BACKOFF, no)
33
34 ])
35 ]) # LN_CONFIG_BACKOFF
36
37 #
38 # LN_CONFIG_DLC
39 #
40 # Configure dlc
41 #
42 # fail to build if libyaml is not installed
43 #
44 AC_DEFUN([LN_CONFIG_DLC], [
45         AS_IF([test "x$enable_dist" = xno], [
46                 AC_CHECK_LIB([yaml], [yaml_parser_initialize],
47                              [LIBYAML="libyaml"],
48                              [AC_MSG_ERROR([YAML development libraries not not installed])],
49                              [-lm])
50         ])
51 ]) # LN_CONFIG_DLC
52
53 #
54 # LN_CONFIG_O2IB
55 #
56 # If current OFED installed (assume with "ofed_info") and devel
57 # headers are not found, error because we assume OFED infiniband
58 # driver needs to be used and we must configure/build with it.
59 # Current OFED headers detection mechanism allow for non-standard
60 # prefix but relies on "ofed_info" command and on "%prefix/openib"
61 # link (both are ok for 1.5.x and 3.x versions), and should work
62 # for both source and DKMS builds.
63 #
64 AC_DEFUN([LN_CONFIG_O2IB], [
65 AC_ARG_ENABLE([multiple-lnds],
66         [AS_HELP_STRING([--enable-multiple-lnds],
67                 [enable multiple lnds to build in-kernel and external o2iblnd])],
68         [AS_IF([test x$enable_multiple_lnds != xyes -a x$enable_multiple_lnds != xno],
69                 [AC_MSG_ERROR([multiple-lnds valid options are "yes" or "no"])])],
70         [enable_multiple_lnds="no"])
71         ENABLE_MULTIPLE_LNDS="$enable_multiple_lnds"
72
73 AC_MSG_CHECKING([if external o2iblnd needs to use Compat RDMA])
74 AC_ARG_WITH([o2ib],
75         AS_HELP_STRING([--with-o2ib=[yes|no|<path>]],
76                 [build o2iblnd against path]),
77         [], [with_o2ib="yes"])
78
79 case $with_o2ib in
80         yes)    INT_O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
81                 BUILT_IN_KO2IBLND="yes"
82                 # Use ofed_info to find external driver
83                 AS_IF([which ofed_info 2>/dev/null], [
84                         AS_IF([test x$uses_dpkg = xyes], [
85                                 LIST_ALL_PKG="dpkg -l | awk '{print \[$]2}'"
86                                 LSPKG="dpkg --listfiles"
87                         ], [
88                                 LIST_ALL_PKG="rpm -qa"
89                                 LSPKG="rpm -ql"
90                         ])
91
92                         O2IBPKG="mlnx-ofed-kernel-dkms"
93                         O2IBPKG+="|mlnx-ofed-kernel-modules"
94                         O2IBPKG+="|mlnx-ofa_kernel-devel"
95                         O2IBPKG+="|compat-rdma-devel"
96                         O2IBPKG+="|kernel-ib-devel"
97                         O2IBPKG+="|ofa_kernel-devel"
98
99                         O2IBDIR="/ofa_kernel"
100                         O2IBDIR+="|/ofa_kernel/default"
101                         O2IBDIR+="|/openib"
102
103                         O2IBDIR_PATH=$(eval $LIST_ALL_PKG |
104                                        egrep -w "$O2IBPKG" | xargs $LSPKG |
105                                        egrep "${O2IBDIR}$" | head -n1)
106
107                         if test -n "$O2IBDIR_PATH"; then
108                                 EXT_O2IBPATHS=$(find $O2IBDIR_PATH -name rdma_cm.h |
109                                         grep -F -e "$(uname -r)" -e default |
110                                         sed -e 's/\/include\/rdma\/rdma_cm.h//')
111                         fi
112
113                         # When ofed-scripts are installed and either the devel
114                         # package is missing or multiple devel packages are
115                         # installed. Give the user a warning
116                         # The in-kernel ofed stack can be built .. so we can
117                         # proceed.
118
119                         EXTERNAL_KO2IBLND="yes"
120                         AS_IF([test -z "$EXT_O2IBPATHS"], [
121                                 EXTERNAL_KO2IBLND="no"
122                                 AC_MSG_WARN([
123 * You seem to have an OFED installed but have not installed the associated
124 * devel package.
125 * If you still want to build Lustre for your External OFED I/B stack,
126 * you need to install its devel headers RPM.
127 * Only the kernel built-in I/B stack support will be built.
128                                              ])
129                         ])
130                         AS_IF([test $(echo $EXT_O2IBPATHS | wc -w) -ge 2], [
131                                 BUILT_IN_KO2IBLND="no"
132                                 AC_MSG_WARN([
133 * It appears that you have multiple OFED versions installed.
134 * If you still want to build Lustre for your External OFED I/B stack, you
135 * need to install a single version with the associated devel package.
136 * Only the kernel built-in I/B stack support will be built.
137                                      ])
138                         ])
139                         if test x$EXTERNAL_KO2IBLND != "xno" ; then
140                                 if test -e $EXT_O2IBPATHS/${LINUXRELEASE}; then
141                                     EXT_O2IBPATHS=$EXT_O2IBPATHS/${LINUXRELEASE}
142                                 elif test -e $EXT_O2IBPATHS/default; then
143                                     EXT_O2IBPATHS=$EXT_O2IBPATHS/default
144                                 fi
145                         fi
146                 ])
147                 ENABLEO2IB="yes"
148                 ;;
149         no)     ENABLEO2IB="no"
150                 EXTERNAL_KO2IBLND="no"
151                 BUILT_IN_KO2IBLND="no"
152                 ;;
153         *)      ENABLEO2IB="withpath"
154                 EXT_O2IBPATHS=$with_o2ib
155                 EXTERNAL_KO2IBLND="yes"
156                 INT_O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
157                 BUILT_IN_KO2IBLND="yes"
158                 ;;
159 esac
160
161 AS_IF([test $ENABLEO2IB = "no"], [
162         AC_MSG_RESULT([no])
163         AC_DEFUN([LN_CONFIG_O2IB_SRC], [])
164         AC_DEFUN([LN_CONFIG_O2IB_RESULTS], [])
165         EXT_O2IB_SYMBOLS=""
166         INT_O2IB_SYMBOLS=""
167 ], [
168         # Verify in-kernel O2IB can be built (headers exist) ... or disable it.
169         int_o2ib_found=false
170         for INT_O2IBPATH in $INT_O2IBPATHS; do
171                 AS_IF([test \( -f ${INT_O2IBPATH}/include/rdma/rdma_cm.h -a \
172                            -f ${INT_O2IBPATH}/include/rdma/ib_cm.h -a \
173                            -f ${INT_O2IBPATH}/include/rdma/ib_verbs.h \)], [
174                         int_o2ib_found=true
175                         break
176                 ])
177         done
178         if ! $int_o2ib_found; then
179                 AC_MSG_WARN([kernel does not support in-kernel o2ib, it will not be built])
180                 BUILT_IN_KO2IBLND="no"
181         fi
182
183         # Verify external O2IB can be built (headers exist), or abort
184         ext_o2ib_found=false
185         for EXT_O2IBPATH in $EXT_O2IBPATHS; do
186                 AS_IF([test \( -f ${EXT_O2IBPATH}/include/rdma/rdma_cm.h -a \
187                            -f ${EXT_O2IBPATH}/include/rdma/ib_cm.h -a \
188                            -f ${EXT_O2IBPATH}/include/rdma/ib_verbs.h \)], [
189                         ext_o2ib_found=true
190                         break
191                 ])
192         done
193         if ! $ext_o2ib_found; then
194                 case $EXT_ENABLEO2IB in
195                         "withpath") AC_MSG_ERROR([bad --with-o2ib path]) ;;
196                         *)      AC_MSG_WARN([
197 Auto detection of external O2IB failed. Build of external o2ib disabled.])
198                                 EXTERNAL_KO2IBLND="no"
199                                 ;;
200                 esac
201         fi
202
203         if test "x$EXTERNAL_KO2IBLND" != no ; then
204                 # Additional checks for external O2IB
205                 COMPAT_AUTOCONF=""
206                 compatrdma_found=false
207                 if test -f ${EXT_O2IBPATH}/include/linux/compat-2.6.h; then
208                         AC_MSG_RESULT([yes])
209                         compatrdma_found=true
210                         AC_DEFINE(HAVE_OFED_COMPAT_RDMA, 1, [compat rdma found])
211                         EXTRA_OFED_CONFIG="$EXTRA_OFED_CONFIG -include ${EXT_O2IBPATH}/include/linux/compat-2.6.h"
212                         if test -f "$EXT_O2IBPATH/include/linux/compat_autoconf.h"; then
213                                 COMPAT_AUTOCONF="$EXT_O2IBPATH/include/linux/compat_autoconf.h"
214                         fi
215                 else
216                         AC_MSG_RESULT([no])
217                 fi
218                 if ! $compatrdma_found; then
219                         if test -f "$EXT_O2IBPATH/config.mk"; then
220                                 . "$EXT_O2IBPATH/config.mk"
221                         elif test -f "$EXT_O2IBPATH/ofed_patch.mk"; then
222                                 . "$EXT_O2IBPATH/ofed_patch.mk"
223                         fi
224                 elif test -z "$COMPAT_AUTOCONF"; then
225                         # Depreciated checks
226                         if test "x$RHEL_KERNEL" = xyes; then
227                                 RHEL_MAJOR=$(awk '/ RHEL_MAJOR / { print [$]3 }' $LINUX_OBJ/include/$VERSION_HDIR/version.h)
228                                 I=$(awk '/ RHEL_MINOR / { print [$]3 }' $LINUX_OBJ/include/$VERSION_HDIR/version.h)
229                                 while test "$I" -ge 0; do
230                                         EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_RHEL_${RHEL_MAJOR}_$I"
231                                         I=$(($I-1))
232                                 done
233                         elif test "x$SUSE_KERNEL" = xyes; then
234                                 SP=$(grep PATCHLEVEL /etc/SuSE-release | sed -e 's/.*= *//')
235                                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_SLES_11_$SP"
236                         fi
237                 fi
238
239                 AC_MSG_CHECKING([whether to use any OFED backport headers])
240                 if test -n "$BACKPORT_INCLUDES"; then
241                         AC_MSG_RESULT([yes])
242                         OFED_BACKPORT_PATH="$EXT_O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
243                         EXTRA_OFED_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_OFED_INCLUDE"
244                 else
245                         AC_MSG_RESULT([no])
246                 fi
247
248                 EXT_O2IBLND=""
249                 EXT_O2IBPATH=$(readlink --canonicalize $EXT_O2IBPATH)
250                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -I$EXT_O2IBPATH/include"
251                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -I$EXT_O2IBPATH/include/uapi"
252                 EXTRA_CHECK_INCLUDE="$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE"
253                 LB_CHECK_COMPILE([whether to enable OpenIB gen2 support],
254                 openib_gen2_support, [
255                         #ifdef HAVE_OFED_COMPAT_RDMA
256                         #undef PACKAGE_NAME
257                         #undef PACKAGE_TARNAME
258                         #undef PACKAGE_VERSION
259                         #undef PACKAGE_STRING
260                         #undef PACKAGE_BUGREPORT
261                         #undef PACKAGE_URL
262                         #include <linux/compat-2.6.h>
263                         #endif
264                         #include <linux/version.h>
265                         #include <linux/pci.h>
266                         #include <linux/gfp.h>
267                         #include <rdma/rdma_cm.h>
268                         #include <rdma/ib_cm.h>
269                         #include <rdma/ib_verbs.h>
270                 ],[
271                         struct rdma_cm_id *cm_idi __attribute__ ((unused));
272                         struct rdma_conn_param conn_param __attribute__ ((unused));
273                         struct ib_device_attr device_attr __attribute__ ((unused));
274                         struct ib_qp_attr qp_attr __attribute__ ((unused));
275                         enum ib_cm_rej_reason rej_reason __attribute__ ((unused));
276
277                         rdma_destroy_id(NULL);
278                 ],[
279                         EXT_O2IBLND="o2iblnd"
280                 ],[
281                         case $ENABLEO2IB in
282                         "yes") AC_MSG_ERROR([cannot compile with OpenIB gen2 headers]) ;;
283                         "withpath") AC_MSG_ERROR([cannot compile with OpenIB gen2 headers under $EXT_O2IBPATH]) ;;
284                         *) AC_MSG_ERROR([internal error]) ;;
285                         esac
286                 ])
287                 # we know that the found external OFED source+headers are good
288                 EXT_O2IB_SYMBOLS=""
289                 CHECK_SYMBOLS=""
290                 if test -f $EXT_O2IBPATH/Module.symvers ; then
291                         CHECK_SYMBOLS=$EXT_O2IBPATH/Module.symvers
292                 fi
293                 if test -n "$CHECK_SYMBOLS"; then
294                         if test ! "$CHECK_SYMBOLS" -ef "$LINUX_OBJ/Module.symvers"; then
295                                 AC_MSG_NOTICE([adding $CHECK_SYMBOLS to external o2ib symbols])
296                                 EXT_O2IB_SYMBOLS="${CHECK_SYMBOLS}"
297                         else
298                                 EXTERNAL_KO2IBLND="no"
299                         fi
300                 elif test "x$EXTERNAL_KO2IBLND" != "xno" ; then
301                         AC_MSG_WARN([
302         * Module.symvers for external o2iblnd was not found.
303         * Expected: $EXT_O2IBPATH/Module.symvers
304         * ko2iblnd.ko for external OFED will not be built.
305                                     ])
306                         EXTERNAL_KO2IBLND="no"
307                 fi
308         fi
309
310         # we suspect that the found in-kernel OFED source+headers are good
311         # the above compile test *could* be repeated with in-kernel paths ... 
312         INT_O2IB_SYMBOLS=""
313         CHECK_SYMBOLS=""
314         if test -f $INT_O2IBPATH/Module.symvers; then
315                 CHECK_SYMBOLS=$INT_O2IBPATH/Module.symvers
316         elif test "x$SUSE_KERNEL" = "xyes"; then
317                 CHECK_SYMBOLS=$(find ${INT_O2IBPATH}* -name Module.symvers)
318                 # Select only the current 'flavor' if there is more than 1
319                 NUM_AVAIL=$(find ${INT_O2IBPATH}* -name Module.symvers | wc -l)
320                 if test ${NUM_AVAIL} -gt 1; then
321                         PREFER=$(basename ${LINUX_OBJ})
322                         for F in $(find ${O2IBPATH}-obj -name Module.symvers)
323                         do
324                                 maybe=$(echo $F | grep "/${PREFER}")
325                                 if test "x$maybe" != "x"; then
326                                         CHECK_SYMBOLS=$F
327                                 fi
328                         done
329                 fi
330         elif test -f $LINUX_OBJ/Module.symvers; then
331                 # Debian symvers is in the arch tree
332                 CHECK_SYMBOLS=$LINUX_OBJ/Module.symvers
333         fi
334
335         if test -n "$CHECK_SYMBOLS"; then
336                 if test ! "$CHECK_SYMBOLS" -ef "$LINUX_OBJ/Module.symvers"; then
337                         AC_MSG_NOTICE([adding $CHECK_SYMBOLS to o2ib in-kernel symbols])
338                         INT_O2IB_SYMBOLS="${CHECK_SYMBOLS}"
339                 fi
340         else
341                 AC_MSG_WARN([Module.symvers for in-kernel o2iblnd was not found, in-kernel ofed will not be built])
342                 BUILT_IN_KO2IBLND="no"
343         fi
344
345         if test "x$EXTERNAL_KO2IBLND" = "xno" -a "x$BUILT_IN_KO2IBLND" = "xno" ; then
346                 AC_MSG_ERROR([No o2iblnd can be built])
347         elif test "x$ENABLE_MULTIPLE_LNDS" = "xno" -a \
348                   "x$EXTERNAL_KO2IBLND" != "xno" -a "x$BUILT_IN_KO2IBLND" != "xno"; then
349                 AC_MSG_WARN([
350 NOTE: --enable-multiple-lnds is needed to enable both o2iblnd drivers.
351 * Disabling in-kernel o2iblnd in favor of external o2iblnd driver.
352 * There can be only one in this configuration
353                             ])
354                 BUILT_IN_KO2IBLND="no"
355         fi
356
357         LB_CHECK_COMPILE([if Linux kernel has kthread_worker],
358         linux_kthread_worker, [
359                 #ifdef HAVE_OFED_COMPAT_RDMA
360                 #undef PACKAGE_NAME
361                 #undef PACKAGE_TARNAME
362                 #undef PACKAGE_VERSION
363                 #undef PACKAGE_STRING
364                 #undef PACKAGE_BUGREPORT
365                 #undef PACKAGE_URL
366                 #include <linux/compat-2.6.h>
367                 #endif
368                 #include <linux/kthread.h>
369         ],[
370                 struct kthread_work *kth_wrk = NULL;
371                 flush_kthread_work(kth_wrk);
372         ],[
373                 AC_DEFINE(HAVE_KTHREAD_WORK, 1, [kthread_worker found])
374                 if test -z "$COMPAT_AUTOCONF"; then
375                         EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_IS_KTHREAD"
376                 fi
377         ])
378         EXTRA_CHECK_INCLUDE=""
379 ])
380 AC_SUBST(EXTRA_OFED_CONFIG)
381 AC_SUBST(EXTRA_OFED_INCLUDE)
382 AC_SUBST(EXT_O2IBLND)
383 AC_SUBST(EXT_O2IB_SYMBOLS)
384 AC_SUBST(INT_O2IB_SYMBOLS)
385
386 # Passed down to deb packaging via autoMakefile.am
387 AC_SUBST(EXT_O2IBPATH)
388 AC_SUBST(ENABLEO2IB)
389 AC_SUBST(ENABLE_MULTIPLE_LNDS)
390
391 AS_IF([test $ENABLEO2IB != "no"], [
392         EXTRA_CHECK_INCLUDE="$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE"
393         if test ! $EXT_O2IBPATH -ef $LINUX_OBJ; then
394                 EXTERNAL_KO2IBLND="yes"
395         fi
396
397         # In RHEL 6.2, rdma_create_id() takes the queue-pair type as a fourth argument
398         AC_DEFUN([LN_SRC_O2IB_RDMA_CREATE_ID_4A], [
399                 LB2_OFED_TEST_SRC([rdma_create_id_4args], [
400                         #ifdef HAVE_OFED_COMPAT_RDMA
401                         #undef PACKAGE_NAME
402                         #undef PACKAGE_TARNAME
403                         #undef PACKAGE_VERSION
404                         #undef PACKAGE_STRING
405                         #undef PACKAGE_BUGREPORT
406                         #undef PACKAGE_URL
407                         #include <linux/compat-2.6.h>
408                         #endif
409                         #include <rdma/rdma_cm.h>
410                 ],[
411                         rdma_create_id(NULL, NULL, 0, 0);
412                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
413         ])
414         AC_DEFUN([LN_O2IB_RDMA_CREATE_ID_4A], [
415                 LB2_OFED_TEST_RESULTS(
416                         ['rdma_create_id' wants four args],
417                         [rdma_create_id_4args],
418                         [HAVE_OFED_RDMA_CREATE_ID_4ARG])
419         ])
420
421         # 4.4 added network namespace parameter for rdma_create_id()
422         AC_DEFUN([LN_SRC_O2IB_RDMA_CREATE_ID_5A], [
423                 LB2_OFED_TEST_SRC([rdma_create_id_5args], [
424                         #ifdef HAVE_OFED_COMPAT_RDMA
425                         #undef PACKAGE_NAME
426                         #undef PACKAGE_TARNAME
427                         #undef PACKAGE_VERSION
428                         #undef PACKAGE_STRING
429                         #undef PACKAGE_BUGREPORT
430                         #undef PACKAGE_URL
431                         #include <linux/compat-2.6.h>
432                         #endif
433                         #include <rdma/rdma_cm.h>
434                 ],[
435                         rdma_create_id(NULL, NULL, NULL, 0, 0);
436                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
437         ])
438         AC_DEFUN([LN_O2IB_RDMA_CREATE_ID_5A], [
439                 LB2_OFED_TEST_RESULTS(
440                         ['rdma_create_id' wants five args],
441                         [rdma_create_id_5args],
442                         [HAVE_OFED_RDMA_CREATE_ID_5ARG])
443         ])
444
445         # 4.2 introduced struct ib_cq_init_attr which is used
446         # by ib_create_cq(). Note some OFED stacks only keep
447         # their headers in sync with latest kernels but not
448         # the functionality which means for infiniband testing
449         # we need to always test functionality testings.
450         AC_DEFUN([LN_SRC_O2IB_IB_CQ_INIT_ATTR], [
451                 LB2_OFED_TEST_SRC([ib_cq_init_attr], [
452                         #ifdef HAVE_OFED_COMPAT_RDMA
453                         #undef PACKAGE_NAME
454                         #undef PACKAGE_TARNAME
455                         #undef PACKAGE_VERSION
456                         #undef PACKAGE_STRING
457                         #undef PACKAGE_BUGREPORT
458                         #undef PACKAGE_URL
459                         #include <linux/compat-2.6.h>
460                         #endif
461                         #include <rdma/ib_verbs.h>
462                 ],[
463                         struct ib_cq_init_attr cq_attr;
464
465                         ib_create_cq(NULL, NULL, NULL, NULL, &cq_attr);
466                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
467         ])
468         AC_DEFUN([LN_O2IB_IB_CQ_INIT_ATTR], [
469                 LB2_OFED_TEST_RESULTS(
470                         ['struct ib_cq_init_attr' is used by ib_create_cq],
471                         [ib_cq_init_attr],
472                         [HAVE_OFED_IB_CQ_INIT_ATTR])
473         ])
474
475         # 4.3 removed ib_alloc_fast_reg_mr()
476         AC_DEFUN([LN_SRC_O2IB_IB_ALLOC_FAST_REG_MR], [
477                 LB2_OFED_TEST_SRC([ib_alloc_fast_reg_mr], [
478                         #ifdef HAVE_OFED_COMPAT_RDMA
479                         #undef PACKAGE_NAME
480                         #undef PACKAGE_TARNAME
481                         #undef PACKAGE_VERSION
482                         #undef PACKAGE_STRING
483                         #undef PACKAGE_BUGREPORT
484                         #undef PACKAGE_URL
485                         #include <linux/compat-2.6.h>
486                         #endif
487                         #include <rdma/ib_verbs.h>
488                 ],[
489                         ib_alloc_fast_reg_mr(NULL, 0);
490                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
491         ])
492         AC_DEFUN([LN_O2IB_IB_ALLOC_FAST_REG_MR], [
493                 LB2_OFED_TEST_RESULTS(
494                         ['ib_alloc_fast_reg_mr' exists],
495                         [ib_alloc_fast_reg_mr],
496                         [HAVE_OFED_IB_ALLOC_FAST_REG_MR])
497         ])
498
499         # 4.9 must stop using ib_get_dma_mr and the global MR
500         # We then have to use FMR/Fastreg for all RDMA.
501         AC_DEFUN([LN_SRC_O2IB_IB_GET_DMA_MR], [
502                 LB2_OFED_TEST_SRC([ib_get_dma_mr], [
503                         #ifdef HAVE_OFED_COMPAT_RDMA
504                         #undef PACKAGE_NAME
505                         #undef PACKAGE_TARNAME
506                         #undef PACKAGE_VERSION
507                         #undef PACKAGE_STRING
508                         #undef PACKAGE_BUGREPORT
509                         #undef PACKAGE_URL
510                         #include <linux/compat-2.6.h>
511                         #endif
512                         #include <rdma/ib_verbs.h>
513                 ],[
514                         ib_get_dma_mr(NULL, 0);
515                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
516         ])
517         AC_DEFUN([LN_O2IB_IB_GET_DMA_MR], [
518                 LB2_OFED_TEST_RESULTS(
519                         ['ib_get_dma_mr' exists],
520                         [ib_get_dma_mr],
521                         [HAVE_OFED_IB_GET_DMA_MR])
522         ])
523
524         # In v4.4 Linux kernel,
525         # commit e622f2f4ad2142d2a613a57fb85f8cf737935ef5
526         # split up struct ib_send_wr so that all non-trivial verbs
527         # use their own structure which embedds struct ib_send_wr.
528         AC_DEFUN([LN_SRC_O2IB_IB_RDMA_WR], [
529                 LB2_OFED_TEST_SRC([ib_rdma_wr], [
530                         #ifdef HAVE_OFED_COMPAT_RDMA
531                         #undef PACKAGE_NAME
532                         #undef PACKAGE_TARNAME
533                         #undef PACKAGE_VERSION
534                         #undef PACKAGE_STRING
535                         #undef PACKAGE_BUGREPORT
536                         #undef PACKAGE_URL
537                         #include <linux/compat-2.6.h>
538                         #endif
539                         #include <rdma/ib_verbs.h>
540                 ],[
541                         const struct ib_rdma_wr *wr __attribute__ ((unused));
542
543                         wr = rdma_wr(NULL);
544                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
545         ])
546         AC_DEFUN([LN_O2IB_IB_RDMA_WR], [
547                 LB2_OFED_TEST_RESULTS(
548                         ['struct ib_rdma_wr' is defined],
549                         [ib_rdma_wr],
550                         [HAVE_OFED_IB_RDMA_WR])
551         ])
552
553         # new fast registration API introduced in 4.4
554         AC_DEFUN([LN_SRC_O2IB_IB_MAP_MR_SG_4A], [
555                 LB2_OFED_TEST_SRC([ib_map_mr_sg_4args], [
556                         #ifdef HAVE_OFED_COMPAT_RDMA
557                         #undef PACKAGE_NAME
558                         #undef PACKAGE_TARNAME
559                         #undef PACKAGE_VERSION
560                         #undef PACKAGE_STRING
561                         #undef PACKAGE_BUGREPORT
562                         #undef PACKAGE_URL
563                         #include <linux/compat-2.6.h>
564                         #endif
565                         #include <rdma/ib_verbs.h>
566                 ],[
567                         ib_map_mr_sg(NULL, NULL, 0, 0);
568                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
569         ])
570         # new fast registration API introduced in 4.4
571         AC_DEFUN([LN_O2IB_IB_MAP_MR_SG_4A], [
572                 LB2_OFED_TEST_RESULTS(
573                         ['ib_map_mr_sg' with 4 args exists],
574                         [ib_map_mr_sg_4args],
575                         [HAVE_OFED_IB_MAP_MR_SG])
576         ])
577
578         # ib_map_mr_sg changes from 4 to 5 args (adding sg_offset_p)
579         # in kernel 4.7 (and RHEL 7.3)
580         AC_DEFUN([LN_SRC_O2IB_IB_MAP_MR_SG_5A], [
581                 LB2_OFED_TEST_SRC([ib_map_mr_sg_5args], [
582                         #ifdef HAVE_OFED_COMPAT_RDMA
583                         #undef PACKAGE_NAME
584                         #undef PACKAGE_TARNAME
585                         #undef PACKAGE_VERSION
586                         #undef PACKAGE_STRING
587                         #undef PACKAGE_BUGREPORT
588                         #undef PACKAGE_URL
589                         #include <linux/compat-2.6.h>
590                         #endif
591                         #include <rdma/ib_verbs.h>
592                 ],[
593                         ib_map_mr_sg(NULL, NULL, 0, NULL, 0);
594                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
595         ])
596         AC_DEFUN([LN_O2IB_IB_MAP_MR_SG_5A], [
597                 LB2_OFED_TEST_RESULTS(
598                         [struct ib_reg_wr exists],
599                         [ib_map_mr_sg_5args],
600                         [HAVE_OFED_IB_MAP_MR_SG])
601                 LB2_OFED_TEST_RESULTS(
602                         ['ib_map_mr_sg()' with 5 args exists],
603                         [ib_map_mr_sg_5args],
604                         [HAVE_OFED_IB_MAP_MR_SG_5ARGS])
605         ])
606
607         # ib_query_device() removed in 4.5
608         AC_DEFUN([LN_SRC_O2IB_IB_DEVICE_ATTRS], [
609                 LB2_OFED_TEST_SRC([ib_device_attrs], [
610                         #ifdef HAVE_OFED_COMPAT_RDMA
611                         #undef PACKAGE_NAME
612                         #undef PACKAGE_TARNAME
613                         #undef PACKAGE_VERSION
614                         #undef PACKAGE_STRING
615                         #undef PACKAGE_BUGREPORT
616                         #undef PACKAGE_URL
617                         #include <linux/compat-2.6.h>
618                         #endif
619                         #include <rdma/ib_verbs.h>
620                 ],[
621                         struct ib_device dev;
622                         struct ib_device_attr dev_attr = {};
623                         dev.attrs = dev_attr;
624                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
625         ])
626         AC_DEFUN([LN_O2IB_IB_DEVICE_ATTRS], [
627                 LB2_OFED_TEST_RESULTS(
628                         ['struct ib_device' has member 'attrs'],
629                         [ib_device_attrs],
630                         [HAVE_OFED_IB_DEVICE_ATTRS])
631         ])
632
633         # A flags argument was added to ib_alloc_pd() in Linux 4.9,
634         # commit ed082d36a7b2c27d1cda55fdfb28af18040c4a89
635         AC_DEFUN([LN_SRC_O2IB_IB_ALLOC_PD], [
636                 LB2_OFED_TEST_SRC([ib_alloc_pd], [
637                         #ifdef HAVE_OFED_COMPAT_RDMA
638                         #undef PACKAGE_NAME
639                         #undef PACKAGE_TARNAME
640                         #undef PACKAGE_VERSION
641                         #undef PACKAGE_STRING
642                         #undef PACKAGE_BUGREPORT
643                         #undef PACKAGE_URL
644                         #include <linux/compat-2.6.h>
645                         #endif
646                         #include <rdma/ib_verbs.h>
647                 ],[
648                         ib_alloc_pd(NULL, 0);
649                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
650         ])
651         AC_DEFUN([LN_O2IB_IB_ALLOC_PD], [
652                 LB2_OFED_TEST_RESULTS(
653                         [2arg 'ib_alloc_pd' exists],
654                         [ib_alloc_pd],
655                         [HAVE_OFED_IB_ALLOC_PD_2ARGS])
656         ])
657
658         AC_DEFUN([LN_SRC_O2IB_IB_INC_RKEY], [
659                 LB2_OFED_TEST_SRC([ib_inc_rkey], [
660                         #ifdef HAVE_OFED_COMPAT_RDMA
661                         #undef PACKAGE_NAME
662                         #undef PACKAGE_TARNAME
663                         #undef PACKAGE_VERSION
664                         #undef PACKAGE_STRING
665                         #undef PACKAGE_BUGREPORT
666                         #undef PACKAGE_URL
667                         #include <linux/compat-2.6.h>
668                         #endif
669                         #include <rdma/ib_verbs.h>
670                 ],[
671                         (void)ib_inc_rkey(0);
672                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
673         ])
674         AC_DEFUN([LN_O2IB_IB_INC_RKEY], [
675                 LB2_OFED_TEST_RESULTS(
676                         [function 'ib_inc_rkey' is defined],
677                         [ib_inc_rkey],
678                         [HAVE_OFED_IB_INC_RKEY])
679         ])
680
681         # In MOFED 4.6, the second and third parameters for
682         # ib_post_send() and ib_post_recv() are declared with
683         # 'const'.
684         AC_DEFUN([LN_SRC_O2IB_IB_POST_SEND_CONST], [
685                 LB2_OFED_TEST_SRC([ib_post_send_recv_const], [
686                         #ifdef HAVE_OFED_COMPAT_RDMA
687                         #undef PACKAGE_NAME
688                         #undef PACKAGE_TARNAME
689                         #undef PACKAGE_VERSION
690                         #undef PACKAGE_STRING
691                         #undef PACKAGE_BUGREPORT
692                         #undef PACKAGE_URL
693                         #include <linux/compat-2.6.h>
694                         #endif
695                         #include <rdma/ib_verbs.h>
696                 ],[
697                         ib_post_send(NULL, (const struct ib_send_wr *)NULL,
698                                      (const struct ib_send_wr **)NULL);
699                 ],[-Werror],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
700         ])
701         AC_DEFUN([LN_O2IB_IB_POST_SEND_CONST], [
702                 LB2_OFED_TEST_RESULTS(
703                         ['ib_post_send() and ib_post_recv()' have const parameters],
704                         [ib_post_send_recv_const],
705                         [HAVE_OFED_IB_POST_SEND_RECV_CONST])
706         ])
707
708         # MOFED 5.5 fails with:
709         #   ERROR: "ib_dma_virt_map_sg" [.../ko2iblnd.ko] undefined!
710         # See if we have a broken ib_dma_map_sg()
711         AC_DEFUN([LN_SRC_SANE_IB_DMA_MAP_SG], [
712                 LB2_OFED_TEST_SRC([sane_ib_dma_map_sg], [
713                         #ifdef HAVE_OFED_COMPAT_RDMA
714                         #undef PACKAGE_NAME
715                         #undef PACKAGE_TARNAME
716                         #undef PACKAGE_VERSION
717                         #undef PACKAGE_STRING
718                         #undef PACKAGE_BUGREPORT
719                         #undef PACKAGE_URL
720                         #include <linux/compat-2.6.h>
721                         #endif
722                         #include <rdma/ib_verbs.h>
723                 ],[
724                         ib_dma_map_sg((struct ib_device *)NULL,
725                                       (struct scatterlist *)NULL, 1, 0);
726                 ],[-Werror],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
727         ])
728         AC_DEFUN([LN_SANE_IB_DMA_MAP_SG], [
729                 LB2_OFED_TEST_RESULTS(
730                         [if ib_dma_map_sg() is sane],
731                         [sane_ib_dma_map_sg],
732                         [HAVE_OFED_IB_DMA_MAP_SG_SANE],[module])
733         ])
734
735         #
736         # LN_IB_DEVICE_OPS_EXISTS
737         #
738         # kernel 5.0 commit 521ed0d92ab0db3edd17a5f4716b7f698f4fce61
739         # RDMA/core: Introduce ib_device_ops
740         # ... introduces the ib_device_ops structure that defines all the
741         # InfiniBand device operations in one place ...
742         #
743         AC_DEFUN([LN_SRC_O2IB_IB_DEVICE_OPS_EXISTS], [
744                 LB2_OFED_TEST_SRC([ib_device_ops_test], [
745                         #include <rdma/ib_verbs.h>
746                 ],[
747                         int x = offsetof(struct ib_device_ops, unmap_fmr);
748                         x = x;
749                         (void)x;
750                 ],[-Werror],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
751         ])
752         AC_DEFUN([LN_O2IB_IB_DEVICE_OPS_EXISTS], [
753                 LB2_OFED_TEST_RESULTS(
754                         [struct ib_device_ops is defined],
755                         [ib_device_ops_test],
756                         [HAVE_OFED_IB_DEVICE_OPS])
757         ]) # LN_IB_DEVICE_OPS_EXISTS
758
759         #
760         # LN_O2IB_IB_SG_DMA_ADDRESS_EXISTS
761         #
762         # kernel 5.1 commit a163afc88556e099271a7b423295bc5176fcecce
763         # IB/core: Remove ib_sg_dma_address() and ib_sg_dma_len()
764         # ... when dma_ops existed (3.6) ib_sg_dma_address() was not trivial ...
765         #
766         AC_DEFUN([LN_SRC_O2IB_IB_SG_DMA_ADDRESS_EXISTS], [
767                 LB2_OFED_TEST_SRC([ib_sg_dma_address_test], [
768                         #include <rdma/ib_verbs.h>
769                 ],[
770                         u64 x = ib_sg_dma_address(NULL, NULL);
771                         x = x;
772                         (void)x;
773                 ],[-Werror],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
774         ])
775         AC_DEFUN([LN_O2IB_IB_SG_DMA_ADDRESS_EXISTS], [
776                 LB2_OFED_TEST_RESULTS(
777                         [ib_sg_dma_address wrapper exists],
778                         [ib_sg_dma_address_test],
779                         [HAVE_OFED_IB_SG_DMA_ADDRESS])
780         ]) # LN_O2IB_IB_SG_DMA_ADDRESS_EXISTS
781
782         #
783         # LN_O2IB_RDMA_REJECT
784         #
785         # A reason argument was added to rdma_reject() in Linux 5.8,
786         # commit 8094ba0ace7f6cd1e31ea8b151fba3594cadfa9a
787         AC_DEFUN([LN_SRC_O2IB_RDMA_REJECT], [
788                 LB2_OFED_TEST_SRC([rdma_reject], [
789                         #ifdef HAVE_OFED_COMPAT_RDMA
790                         #undef PACKAGE_NAME
791                         #undef PACKAGE_TARNAME
792                         #undef PACKAGE_VERSION
793                         #undef PACKAGE_STRING
794                         #undef PACKAGE_BUGREPORT
795                         #undef PACKAGE_URL
796                         #include <linux/compat-2.6.h>
797                         #endif
798                         #include <rdma/ib_verbs.h>
799                         #include <rdma/ib_cm.h>
800                         #include <rdma/rdma_cm.h>
801                 ],[
802                         rdma_reject(NULL, NULL, 0, 0);
803                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
804         ])
805         AC_DEFUN([LN_O2IB_RDMA_REJECT], [
806                 LB2_OFED_TEST_RESULTS(
807                         [4arg 'rdma_reject' exists],
808                         [rdma_reject],
809                         [HAVE_OFED_RDMA_REJECT_4ARGS])
810         ]) # LN_O2IB_RDMA_REJECT
811
812         #
813         # LN_O2IB_IB_FMR
814         #
815         # The FMR pool API was removed in Linux 5.8,
816         # commit 4e373d5417ecbb4f438a8500f0379a2fc29c2643
817         AC_DEFUN([LN_SRC_O2IB_IB_FMR], [
818                 LB2_OFED_TEST_SRC([ib_fmr], [
819                         #include <rdma/ib_verbs.h>
820                 ],[
821                         struct ib_fmr fmr = {};
822                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
823         ])
824         AC_DEFUN([LN_O2IB_IB_FMR], [
825                 LB2_OFED_TEST_RESULTS(
826                         [FMR pools API available],
827                         [ib_fmr],
828                         [HAVE_OFED_FMR_POOL_API])
829         ]) # LN_O2IB_IB_FMR
830
831         #
832         # LN_O2IB_RDMA_CONNECT_LOCKED
833         #
834         # rdma_connect_locked() was added in Linux 5.10,
835         # commit 071ba4cc559de47160761b9500b72e8fa09d923d
836         # and in MOFED-5.2-2. rdma_connect_locked() must
837         # be called instead of rdma_connect() in
838         # RDMA_CM_EVENT_ROUTE_RESOLVED handler.
839         AC_DEFUN([LN_SRC_O2IB_RDMA_CONNECT_LOCKED], [
840                 LB2_OFED_TEST_SRC([rdma_connect_locked], [
841                         #include <rdma/rdma_cm.h>
842                 ],[
843                         rdma_connect_locked(NULL, NULL);
844                 ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
845         ])
846         AC_DEFUN([LN_O2IB_RDMA_CONNECT_LOCKED], [
847                 LB2_OFED_TEST_RESULTS(
848                         ['rdma_connect_locked' exists],
849                         [rdma_connect_locked],
850                         [HAVE_OFED_RDMA_CONNECT_LOCKED])
851         ]) # LN_O2IB_RDMA_CONNECT_LOCKED
852
853         EXTRA_CHECK_INCLUDE=""
854
855         AC_DEFUN([LN_CONFIG_O2IB_SRC], [
856                 LN_SRC_O2IB_RDMA_CREATE_ID_4A
857                 LN_SRC_O2IB_RDMA_CREATE_ID_5A
858                 LN_SRC_O2IB_IB_CQ_INIT_ATTR
859                 LN_SRC_O2IB_IB_ALLOC_FAST_REG_MR
860                 LN_SRC_O2IB_IB_GET_DMA_MR
861                 LN_SRC_O2IB_IB_RDMA_WR
862                 LN_SRC_O2IB_IB_MAP_MR_SG_4A
863                 LN_SRC_O2IB_IB_MAP_MR_SG_5A
864                 LN_SRC_O2IB_IB_DEVICE_ATTRS
865                 LN_SRC_O2IB_IB_ALLOC_PD
866                 LN_SRC_O2IB_IB_INC_RKEY
867                 LN_SRC_O2IB_IB_POST_SEND_CONST
868                 LN_SRC_SANE_IB_DMA_MAP_SG
869                 LN_SRC_O2IB_IB_DEVICE_OPS_EXISTS
870                 LN_SRC_O2IB_IB_SG_DMA_ADDRESS_EXISTS
871                 LN_SRC_O2IB_RDMA_REJECT
872                 LN_SRC_O2IB_IB_FMR
873                 LN_SRC_O2IB_RDMA_CONNECT_LOCKED
874         ])
875         AC_DEFUN([LN_CONFIG_O2IB_RESULTS], [
876                 LN_O2IB_RDMA_CREATE_ID_4A
877                 LN_O2IB_RDMA_CREATE_ID_5A
878                 LN_O2IB_IB_CQ_INIT_ATTR
879                 LN_O2IB_IB_ALLOC_FAST_REG_MR
880                 LN_O2IB_IB_GET_DMA_MR
881                 LN_O2IB_IB_RDMA_WR
882                 LN_O2IB_IB_MAP_MR_SG_4A
883                 LN_O2IB_IB_MAP_MR_SG_5A
884                 LN_O2IB_IB_DEVICE_ATTRS
885                 LN_O2IB_IB_ALLOC_PD
886                 LN_O2IB_IB_INC_RKEY
887                 LN_O2IB_IB_POST_SEND_CONST
888                 LN_SANE_IB_DMA_MAP_SG
889                 LN_O2IB_IB_DEVICE_OPS_EXISTS
890                 LN_O2IB_IB_SG_DMA_ADDRESS_EXISTS
891                 LN_O2IB_RDMA_REJECT
892                 LN_O2IB_IB_FMR
893                 LN_O2IB_RDMA_CONNECT_LOCKED
894         ])
895 ]) # ENABLEO2IB != "no"
896 ]) # LN_CONFIG_O2IB
897
898 #
899 # LN_CONFIG_GNILND
900 #
901 # check whether to use the Gemini Network Interface lnd
902 #
903 AC_DEFUN([LN_CONFIG_GNILND], [
904 AC_MSG_CHECKING([whether to enable GNI lnd])
905 AC_ARG_ENABLE([gni],
906         AS_HELP_STRING([--enable-gni],
907                 [enable GNI lnd]),
908         [], [enable_gni="no"])
909 AC_MSG_RESULT([$enable_gni])
910
911 AS_IF([test "x$enable_gni" = xyes], [
912         # GNICPPFLAGS was set in spec file
913         EXTRA_KCFLAGS_save="$EXTRA_KCFLAGS"
914         EXTRA_KCFLAGS="$EXTRA_KCFLAGS $GNICPPFLAGS"
915         LB_CHECK_COMPILE([if GNI kernel headers are present],
916         GNI_header, [
917                 #include <linux/types.h>
918                 #include <gni_pub.h>
919         ],[
920                 gni_cdm_handle_t kgni_domain;
921                 gni_return_t     rc;
922                 int              rrc;
923                 rc = gni_cdm_create(0, 1, 1, 0, &kgni_domain);
924                 rrc = (rc == GNI_RC_SUCCESS) ? 0 : 1;
925                 return rrc;
926         ],[
927                 GNILND="gnilnd"
928         ],[
929                 AC_MSG_ERROR([cannot compile gnilnd with given GNICPPFLAGS: $GNICPPFLAGS])
930         ])
931         # at this point, we have gnilnd basic support,
932         # now check for extra features
933         LB_CHECK_COMPILE([to use RCA in gnilnd],
934         RCA_gnilnd, [
935                 #include <linux/types.h>
936                 #include <gni_pub.h>
937                 #include <krca_lib.h>
938         ],[
939                 gni_cdm_handle_t kgni_domain;
940                 gni_return_t     rc;
941                 krca_ticket_t    ticket = KRCA_NULL_TICKET;
942                 int              rrc;
943                 __u32            nid = 0, nic_addr;
944                 rc = gni_cdm_create(0, 1, 1, 0, &kgni_domain);
945                 rrc = (rc == GNI_RC_SUCCESS) ? 0 : 1;
946                 rrc += krca_nid_to_nicaddrs(nid, 1, &nic_addr);
947                 rrc += krca_register(&ticket, RCA_MAKE_SERVICE_INDEX(RCA_IO_CLASS, 9), 99, 0);
948                 return rrc;
949         ],[
950                 GNICPPFLAGS="$GNICPPFLAGS -DGNILND_USE_RCA=1"
951         ])
952         EXTRA_KCFLAGS="$EXTRA_KCFLAGS_save"
953
954         AC_SUBST(ENABLE_GNI, yes)
955 ], [
956         AC_SUBST(ENABLE_GNI, no)
957 ])
958 AC_SUBST(GNICPPFLAGS)
959 AC_SUBST(GNILND)
960 ]) # LN_CONFIG_GNILND
961
962 #
963 # LN_CONFIG_KFILND
964 #
965 # check whether to use the kfabric Network Interface lnd
966 #
967 AC_DEFUN([LN_CONFIG_KFILND], [
968 AC_ARG_WITH([kfi],
969         AS_HELP_STRING([--with-kfi=<path>], [Kfabric build path for kfilnd]),
970         [
971                 AC_CHECK_FILE([$with_kfi/Module.symvers],
972                 [
973                         # KFICPPFLAGS was set in spec file
974                         KFICPPFLAGS="-I$with_kfi/include"
975                         EXTRA_KCFLAGS_save="$EXTRA_KCFLAGS"
976                         EXTRA_KCFLAGS="$EXTRA_KCFLAGS $KFICPPFLAGS"
977                         KBUILD_EXTRA_SYMBOLS="$KBUILD_EXTRA_SYMBOLS $with_kfi/Module.symvers"
978                         LB_CHECK_COMPILE([if kfabric headers are present], KFI_header,
979                         [
980                                 #include <kfi_endpoint.h>
981                         ],[
982                                 struct kfi_info *hints;
983                                 hints = kfi_allocinfo();
984                         ],[
985                                 KFILND="kfilnd"
986                                 AC_MSG_NOTICE([adding $with_kfi/Module.symvers to Symbol Path])
987                                 EXTRA_SYMBOLS="$EXTRA_SYMBOLS $with_kfi/Module.symvers"
988                         ],[
989                                 AC_MSG_ERROR([cannot compile kfilnd with given KFICPPFLAGS: $KFICPPFLAGS])
990                         ])
991                 ],[
992                         AC_MSG_ERROR(["$with_kfi/Module.symvers does not exist"])
993                 ])
994         ],[])
995 AC_DEFINE(HAVE_KFILND, 1, [support kfabric LND])
996 AC_SUBST(KFICPPFLAGS)
997 AC_SUBST(KFILND)
998 AC_SUBST(EXTRA_SYMBOLS)
999 ]) # LN_CONFIG_KFILND
1000
1001 #
1002 # LN_CONFIG_SOCK_CREATE_KERN
1003 #
1004 # 4.x sock_create_kern() added a first parameter as 'struct net *'
1005 # instead of int.
1006 #
1007 AC_DEFUN([LN_SRC_CONFIG_SOCK_CREATE_KERN], [
1008         LB2_LINUX_TEST_SRC([sock_create_kern_net], [
1009                 #include <linux/net.h>
1010                 #include <net/net_namespace.h>
1011         ],[
1012                 sock_create_kern((struct net*)0, 0, 0, 0, NULL);
1013         ],[-Werror])
1014 ])
1015 AC_DEFUN([LN_CONFIG_SOCK_CREATE_KERN], [
1016         LB2_MSG_LINUX_TEST_RESULT([if 'sock_create_kern' first parameter is net],
1017         [sock_create_kern_net], [
1018                 AC_DEFINE(HAVE_SOCK_CREATE_KERN_USE_NET, 1,
1019                         [sock_create_kern use net as first parameter])
1020         ])
1021 ]) # LN_CONFIG_SOCK_CREATE_KERN
1022
1023 #
1024 # LN_CONFIG_SK_DATA_READY
1025 #
1026 # 3.15 for struct sock the *sk_data_ready() field only takes one argument now
1027 #
1028 AC_DEFUN([LN_SRC_CONFIG_SK_DATA_READY], [
1029         LB2_LINUX_TEST_SRC([sk_data_ready], [
1030                 #include <linux/net.h>
1031                 #include <net/sock.h>
1032         ],[
1033                 ((struct sock *)0)->sk_data_ready(NULL);
1034         ],[-Werror])
1035 ])
1036 AC_DEFUN([LN_CONFIG_SK_DATA_READY], [
1037         LB2_MSG_LINUX_TEST_RESULT([if 'sk_data_ready' takes only one argument],
1038         [sk_data_ready], [
1039         AC_DEFINE(HAVE_SK_DATA_READY_ONE_ARG, 1,
1040                 [sk_data_ready uses only one argument])
1041         ])
1042 ]) # LN_CONFIG_SK_DATA_READY
1043
1044 #
1045 # LN_ETHTOOL_LINK_SETTINGS
1046 #
1047 # ethtool_link_settings was added in Linux 4.6
1048 #
1049 AC_DEFUN([LN_SRC_ETHTOOL_LINK_SETTINGS], [
1050         LB2_LINUX_TEST_SRC([ethtool_link_settings], [
1051                 #include <linux/ethtool.h>
1052         ],[
1053                 struct ethtool_link_ksettings cmd;
1054         ],[],[$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE])
1055 ])
1056 AC_DEFUN([LN_ETHTOOL_LINK_SETTINGS], [
1057         LB2_MSG_LINUX_TEST_RESULT([if 'ethtool_link_settings' exists],
1058         [ethtool_link_settings], [
1059                 AC_DEFINE(HAVE_ETHTOOL_LINK_SETTINGS, 1,
1060                         [ethtool_link_settings is defined])
1061         ])
1062 ]) # LN_ETHTOOL_LINK_SETTINGS
1063
1064 #
1065 # LN_HAVE_HYPERVISOR_IS_TYPE
1066 #
1067 # 4.14 commit 79cc74155218316b9a5d28577c7077b2adba8e58
1068 # x86/paravirt: Provide a way to check for hypervisors
1069 #
1070 AC_DEFUN([LN_SRC_HAVE_HYPERVISOR_IS_TYPE], [
1071         LB2_LINUX_TEST_SRC([hypervisor_is_type_exists], [
1072                 #include <asm/hypervisor.h>
1073         ],[
1074                 (void)hypervisor_is_type(X86_HYPER_NATIVE);
1075         ],[-Werror])
1076 ])
1077 AC_DEFUN([LN_HAVE_HYPERVISOR_IS_TYPE], [
1078         LB2_MSG_LINUX_TEST_RESULT([if hypervisor_is_type function is available],
1079         [hypervisor_is_type_exists], [
1080                 AC_DEFINE(HAVE_HYPERVISOR_IS_TYPE, 1,
1081                         [hypervisor_is_type function exists])
1082         ])
1083 ]) # LN_HAVE_HYPERVISOR_IS_TYPE
1084
1085 #
1086 # LN_HAVE_ORACLE_OFED_EXTENSIONS
1087 #
1088 # Oracle UEK 5
1089 #
1090 AC_DEFUN([LN_SRC_HAVE_ORACLE_OFED_EXTENSIONS], [
1091         LB2_LINUX_TEST_SRC([oracle_ofed_ext], [
1092                 #include <rdma/ib_fmr_pool.h>
1093         ],[
1094                 struct ib_fmr_pool_param param = {
1095                         .relaxed           = 0
1096                 };
1097                 (void)param;
1098         ])
1099 ])
1100 AC_DEFUN([LN_HAVE_ORACLE_OFED_EXTENSIONS], [
1101         LB2_MSG_LINUX_TEST_RESULT([if Oracle OFED Extensions are enabled],
1102         [oracle_ofed_ext], [
1103                 AC_DEFINE(HAVE_ORACLE_OFED_EXTENSIONS, 1,
1104                         [if Oracle OFED Extensions are enabled])
1105         ])
1106 ]) # LN_HAVE_ORACLE_OFED_EXTENSIONS
1107
1108 #
1109 # LN_CONFIG_SOCK_GETNAME
1110 #
1111 # 4.17 commit 9b2c45d479d0fb8647c9e83359df69162b5fbe5f getname()
1112 # does not take the length *int argument and returns the length
1113 #
1114 AC_DEFUN([LN_SRC_CONFIG_SOCK_GETNAME], [
1115         LB2_LINUX_TEST_SRC([kern_sock_getname_2args], [
1116                 #include <linux/net.h>
1117         ],[
1118                 kernel_getsockname(NULL, NULL);
1119         ],[-Werror])
1120 ])
1121 AC_DEFUN([LN_CONFIG_SOCK_GETNAME], [
1122         LB2_MSG_LINUX_TEST_RESULT([if 'getname' has two args],
1123         [kern_sock_getname_2args], [
1124                 AC_DEFINE(HAVE_KERN_SOCK_GETNAME_2ARGS, 1,
1125                         ['getname' has two args])
1126         ])
1127 ]) # LN_CONFIG_SOCK_GETNAME
1128
1129 #
1130 # LN_HAVE_IN_DEV_FOR_EACH_IFA_RTNL
1131 #
1132 # kernel 5.3 commit ef11db3310e272d3d8dbe8739e0770820dd20e52
1133 # and kernel 4.18.0-193.el8:
1134 # added in_dev_for_each_ifa_rtnl and in_dev_for_each_ifa_rcu
1135 # and removed for_ifa and endfor_ifa.
1136 # Use the _rntl variant as the current locking is rtnl.
1137 #
1138 AC_DEFUN([LN_SRC_HAVE_IN_DEV_FOR_EACH_IFA_RTNL], [
1139         LB2_LINUX_TEST_SRC([in_dev_for_each_ifa_rtnl_test], [
1140                 #include <linux/inetdevice.h>
1141         ],[
1142                 const struct in_ifaddr *ifa = NULL;
1143                 struct in_device *in_dev = NULL;
1144
1145                 in_dev_for_each_ifa_rtnl(ifa, in_dev) {}
1146         ],[-Werror])
1147 ])
1148 AC_DEFUN([LN_HAVE_IN_DEV_FOR_EACH_IFA_RTNL], [
1149         LB2_MSG_LINUX_TEST_RESULT([if 'in_dev_for_each_ifa_rtnl' is defined],
1150         [in_dev_for_each_ifa_rtnl_test], [
1151                 AC_DEFINE(HAVE_IN_DEV_FOR_EACH_IFA_RTNL, 1,
1152                         ['in_dev_for_each_ifa_rtnl' is defined])
1153         ])
1154 ]) # LN_HAVE_IN_DEV_FOR_EACH_IFA_RTNL
1155
1156 #
1157 # LN_USR_RDMA
1158 #
1159 #
1160 AC_DEFUN([LN_USR_RDMA], [
1161 AC_MSG_CHECKING([if RDMA_PS_TCP exists])
1162 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1163         #include <rdma/rdma_user_cm.h>
1164
1165         int main(void) {
1166                 int x = (int)RDMA_PS_TCP;
1167                 return x;
1168         }
1169 ])],[
1170         AC_DEFINE(HAVE_USRSPC_RDMA_PS_TCP, 1,
1171                 [RDMA_PS_TCP exists])
1172 ])
1173 ]) # LN_USR_RDMA
1174
1175 AC_DEFUN([LN_PROG_LINUX_SRC], [
1176         LN_CONFIG_O2IB_SRC
1177         # 3.15
1178         LN_SRC_CONFIG_SK_DATA_READY
1179         # 4.x
1180         LN_SRC_CONFIG_SOCK_CREATE_KERN
1181         # 4.6
1182         LN_SRC_ETHTOOL_LINK_SETTINGS
1183         # 4.14
1184         LN_SRC_HAVE_HYPERVISOR_IS_TYPE
1185         LN_SRC_HAVE_ORACLE_OFED_EXTENSIONS
1186         # 4.17
1187         LN_SRC_CONFIG_SOCK_GETNAME
1188         # 5.3 and 4.18.0-193.el8
1189         LN_SRC_HAVE_IN_DEV_FOR_EACH_IFA_RTNL
1190 ])
1191
1192 AC_DEFUN([LN_PROG_LINUX_RESULTS], [
1193         LN_CONFIG_O2IB_RESULTS
1194         # 3.15
1195         LN_CONFIG_SK_DATA_READY
1196         # 4.x
1197         LN_CONFIG_SOCK_CREATE_KERN
1198         # 4.6
1199         LN_ETHTOOL_LINK_SETTINGS
1200         # 4.14
1201         LN_HAVE_HYPERVISOR_IS_TYPE
1202         LN_HAVE_ORACLE_OFED_EXTENSIONS
1203         # 4.17
1204         LN_CONFIG_SOCK_GETNAME
1205         # 5.3 and 4.18.0-193.el8
1206         LN_HAVE_IN_DEV_FOR_EACH_IFA_RTNL
1207 ])
1208
1209 #
1210 # LN_PROG_LINUX
1211 #
1212 # LNet linux kernel checks
1213 #
1214 AC_DEFUN([LN_PROG_LINUX], [
1215 AC_MSG_NOTICE([LNet kernel checks
1216 ==============================================================================])
1217
1218 LN_CONFIG_BACKOFF
1219 LN_CONFIG_O2IB
1220 LN_CONFIG_GNILND
1221 LN_CONFIG_KFILND
1222 ]) # LN_PROG_LINUX
1223
1224 #
1225 # LN_PATH_DEFAULTS
1226 #
1227 # default paths for installed files
1228 #
1229 AC_DEFUN([LN_PATH_DEFAULTS], [
1230 ]) # LN_PATH_DEFAULTS
1231
1232 #
1233 # LN_CONFIGURE
1234 #
1235 # other configure checks
1236 #
1237 AC_DEFUN([LN_CONFIGURE], [
1238 AC_MSG_NOTICE([LNet core checks
1239 ==============================================================================])
1240
1241 AC_ARG_WITH([cuda],
1242         AS_HELP_STRING([--with-cuda=path],
1243                         [Path to the CUDA sources. Set to 'no' to disable.]),
1244                         [cudapath="$withval"],
1245                         [cudapath1=`ls -d1 /usr/src/nvidia-*/nvidia/ 2>/dev/null | tail -1`])
1246
1247 AC_ARG_WITH([gds],
1248         AS_HELP_STRING([--with-gds=path],
1249                         [Path to the GDS sources. Set to 'no' to disable.]),
1250                         [gdspath="$withval"],
1251                         [gdspath1=`ls -d1 /usr/src/nvidia-fs*/ 2>/dev/null | tail -1`])
1252
1253 AC_MSG_CHECKING([cuda source directory])
1254         AS_IF([test -z "${cudapath}"], [
1255                 AS_IF([test -e "${cudapath1}/nv-p2p.h"], [
1256                         cudapath=${cudapath1}
1257                 ], [
1258                         cudapath="[Not found]"
1259                 ])
1260         ])
1261 AC_MSG_RESULT([$cudapath])
1262
1263 AC_MSG_CHECKING([gds source directory])
1264         AS_IF([test -z "${gdspath}"], [
1265                 AS_IF([test -e "${gdspath1}/nvfs-dma.h"], [
1266                         gdspath=${gdspath1}
1267                 ], [
1268                         gdspath="[Not found]"
1269                 ])
1270         ])
1271 AC_MSG_RESULT([$gdspath])
1272
1273 AS_IF([test -e "${cudapath}" && test -e "${gdspath}"],[
1274         LB_CHECK_FILE([$cudapath/nv-p2p.h], [
1275                 AC_MSG_RESULT([CUDA path is $cudapath])
1276                 [CUDA_PATH=${cudapath}]
1277                 AC_SUBST(CUDA_PATH)
1278         ],[
1279                 AC_MSG_RESULT([CUDA sources not found: nv-p2p.h does not exist])
1280         ])
1281
1282         LB_CHECK_FILE([$gdspath/nvfs-dma.h], [
1283                 LB_CHECK_FILE([$gdspath/config-host.h], [
1284                         AC_MSG_RESULT([GDS path is ${gdspath}])
1285                         [GDS_PATH=${gdspath}]
1286                         AC_SUBST(GDS_PATH)
1287                         AC_DEFINE(WITH_GDS, 1, "GDS build enabled")
1288                 ], [
1289                     AC_MSG_RESULT([GDS sources not found: config-host.h does not exist])
1290         ])
1291         ], [
1292                 AC_MSG_RESULT([GDS sources not found: nvfs-dma.h does not exist])
1293     ])
1294 ],[
1295         AC_MSG_WARN([CUDA or GDS sources not found. GDS support disabled])
1296 ])
1297
1298 # lnet/utils/lnetconfig/liblnetconfig_netlink.c
1299 AS_IF([test "x$PKGCONF" = "x"],
1300         [AC_MSG_ERROR([pkg-config package is required to configure Lustre])])
1301
1302 AS_IF([test "x$enable_dist" = xno], [
1303         PKG_CHECK_MODULES(LIBNL3, [libnl-genl-3.0 >= 3.1])
1304 ])
1305
1306 AC_CHECK_LIB([nl-3], [nla_get_s32], [
1307         AC_DEFINE(HAVE_NLA_GET_S32, 1,
1308                 [libnl3 supports nla_get_s32])
1309         ], [
1310 ])
1311
1312 AC_CHECK_LIB([nl-3], [nla_get_s64], [
1313         AC_DEFINE(HAVE_NLA_GET_S64, 1,
1314                 [libnl3 supports nla_get_s64])
1315         ], [
1316 ])
1317
1318 #
1319 # LN_USR_NLMSGERR
1320 #
1321 AC_DEFUN([LN_USR_NLMSGERR], [
1322 AC_MSG_CHECKING([if 'enum nlmsgerr_attrs' exists])
1323 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1324         #include <linux/netlink.h>
1325
1326         int main(void) {
1327                 int x = (int)NLMSGERR_ATTR_MAX;
1328                 return x;
1329         }
1330 ])],[
1331         AC_DEFINE(HAVE_USRSPC_NLMSGERR, 1,
1332                 ['enum nlmsgerr_attrs' exists])
1333 ])
1334 ]) # LN_USR_NLMGSERR
1335
1336 # lnet/utils/portals.c
1337 AC_CHECK_HEADERS([netdb.h])
1338
1339 # lnet/utils/wirecheck.c
1340 AC_CHECK_FUNCS([strnlen])
1341
1342 # --------  Check for required packages  --------------
1343
1344 AC_MSG_CHECKING([whether to enable 'efence' debugging support])
1345 AC_ARG_ENABLE(efence,
1346         AS_HELP_STRING([--enable-efence],
1347                 [use efence library]),
1348         [], [enable_efence="no"])
1349 AC_MSG_RESULT([$enable_efence])
1350
1351 LIBEFENCE=""
1352 AS_IF([test "$enable_efence" = yes], [
1353         LIBEFENCE="-lefence"
1354         AC_DEFINE(HAVE_LIBEFENCE, 1,
1355                 [libefence support is requested])
1356         AC_SUBST(ENABLE_EFENCE, yes)
1357 ], [
1358         AC_SUBST(ENABLE_EFENCE, no)
1359 ])
1360 AC_SUBST(LIBEFENCE)
1361
1362 LN_CONFIG_DLC
1363 LN_USR_RDMA
1364 LN_USR_NLMSGERR
1365 ]) # LN_CONFIGURE
1366
1367 #
1368 # LN_CONDITIONALS
1369 #
1370 # AM_CONDITIONAL defines for lnet
1371 #
1372 AC_DEFUN([LN_CONDITIONALS], [
1373 AM_CONDITIONAL(EXTERNAL_KO2IBLND,  test x$EXTERNAL_KO2IBLND = "xyes")
1374 AM_CONDITIONAL(BUILT_IN_KO2IBLND,  test x$BUILT_IN_KO2IBLND = "xyes")
1375 AM_CONDITIONAL(BUILD_GNILND,       test x$GNILND  = "xgnilnd")
1376 AM_CONDITIONAL(BUILD_KFILND,       test x$KFILND  = "xkfilnd")
1377 ]) # LN_CONDITIONALS
1378
1379 #
1380 # LN_CONFIG_FILES
1381 #
1382 # files that should be generated with AC_OUTPUT
1383 #
1384 AC_DEFUN([LN_CONFIG_FILES], [
1385 AC_CONFIG_FILES([
1386 lnet/Makefile
1387 lnet/autoMakefile
1388 lnet/autoconf/Makefile
1389 lnet/doc/Makefile
1390 lnet/include/Makefile
1391 lnet/include/lnet/Makefile
1392 lnet/include/uapi/linux/lnet/Makefile
1393 lnet/klnds/Makefile
1394 lnet/klnds/autoMakefile
1395 lnet/klnds/o2iblnd/Makefile
1396 lnet/klnds/o2iblnd/autoMakefile
1397 lnet/klnds/in-kernel-o2iblnd/Makefile
1398 lnet/klnds/in-kernel-o2iblnd/autoMakefile
1399 lnet/klnds/gnilnd/Makefile
1400 lnet/klnds/gnilnd/autoMakefile
1401 lnet/klnds/socklnd/Makefile
1402 lnet/klnds/socklnd/autoMakefile
1403 lnet/klnds/kfilnd/Makefile
1404 lnet/klnds/kfilnd/autoMakefile
1405 lnet/lnet/Makefile
1406 lnet/lnet/autoMakefile
1407 lnet/selftest/Makefile
1408 lnet/selftest/autoMakefile
1409 lnet/utils/Makefile
1410 lnet/utils/lnetconfig/Makefile
1411 ])
1412 ]) # LN_CONFIG_FILES