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