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