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