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