Whamcloud - gitweb
LU-17039 build: cleanup ib_dma_map_sg
[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                 AC_MSG_CHECKING([if 'rdma_create_id' wants four args])
319                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 'rdma_create_id' wants five args])
344                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 'struct ib_cq_init_attr' is used])
375                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 'ib_alloc_fast_reg_mr' exists])
400                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 'ib_get_dma_mr' exists])
426                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 'struct ib_rdma_wr' is defined])
456                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 4arg 'ib_map_mr_sg' exists])
482                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 5arg 'ib_map_mr_sg' exists])
508                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 'struct ib_device' has member 'attrs'])
537                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 2arg 'ib_alloc_pd' exists])
563                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if function 'ib_inc_rkey' is defined])
587                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 'ib_post_send() and ib_post_recv()' have const parameters])
615                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if ib_dma_map_sg() is sane])
643                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if struct ib_device_ops is defined])
668                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if ib_sg_dma_address wrapper exists])
692                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 4arg 'rdma_reject' exists])
723                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if FMR pools API available])
743                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 'rdma_connect_locked' exists])
766                 LB2_LINUX_TEST_RESULT([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                 AC_MSG_CHECKING([if 'ethtool_link_settings' exists])
786                 LB2_LINUX_TEST_RESULT([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         AC_MSG_CHECKING([if 'sock_create_kern' first parameter is net])
958         LB2_LINUX_TEST_RESULT([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         AC_MSG_CHECKING([if 'sk_data_ready' takes only one argument])
979         LB2_LINUX_TEST_RESULT([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_EXPORT_KMAP_TO_PAGE
987 #
988 # 3.10 Export kmap_to_page
989 #
990 AC_DEFUN([LN_EXPORT_KMAP_TO_PAGE], [
991 LB_CHECK_EXPORT([kmap_to_page], [mm/highmem.c],
992         [AC_DEFINE(HAVE_KMAP_TO_PAGE, 1,
993                 [kmap_to_page is exported by the kernel])])
994 ]) # LN_EXPORT_KMAP_TO_PAGE
995
996 #
997 # LN_HAVE_HYPERVISOR_IS_TYPE
998 #
999 # 4.14 commit 79cc74155218316b9a5d28577c7077b2adba8e58
1000 # x86/paravirt: Provide a way to check for hypervisors
1001 #
1002 AC_DEFUN([LN_SRC_HAVE_HYPERVISOR_IS_TYPE], [
1003         LB2_LINUX_TEST_SRC([hypervisor_is_type_exists], [
1004                 #include <asm/hypervisor.h>
1005         ],[
1006                 (void)hypervisor_is_type(X86_HYPER_NATIVE);
1007         ],[-Werror])
1008 ])
1009 AC_DEFUN([LN_HAVE_HYPERVISOR_IS_TYPE], [
1010         AC_MSG_CHECKING([if hypervisor_is_type function is available])
1011         LB2_LINUX_TEST_RESULT([hypervisor_is_type_exists], [
1012                 AC_DEFINE(HAVE_HYPERVISOR_IS_TYPE, 1,
1013                         [hypervisor_is_type function exists])
1014         ])
1015 ]) # LN_HAVE_HYPERVISOR_IS_TYPE
1016
1017 #
1018 # LN_HAVE_ORACLE_OFED_EXTENSIONS
1019 #
1020 # Oracle UEK 5
1021 #
1022 AC_DEFUN([LN_SRC_HAVE_ORACLE_OFED_EXTENSIONS], [
1023         LB2_LINUX_TEST_SRC([oracle_ofed_ext], [
1024                 #include <rdma/ib_fmr_pool.h>
1025         ],[
1026                 struct ib_fmr_pool_param param = {
1027                         .relaxed           = 0
1028                 };
1029                 (void)param;
1030         ],[
1031                 AC_DEFINE(HAVE_ORACLE_OFED_EXTENSIONS, 1,
1032                         [if Oracle OFED Extensions are enabled])
1033         ])
1034 ])
1035 AC_DEFUN([LN_HAVE_ORACLE_OFED_EXTENSIONS], [
1036         AC_MSG_CHECKING([if Oracle OFED Extensions are enabled])
1037         LB2_LINUX_TEST_RESULT([oracle_ofed_ext], [
1038                 AC_DEFINE(HAVE_ORACLE_OFED_EXTENSIONS, 1,
1039                         [if Oracle OFED Extensions are enabled])
1040         ])
1041 ]) # LN_HAVE_ORACLE_OFED_EXTENSIONS
1042
1043 #
1044 # LN_CONFIG_SOCK_GETNAME
1045 #
1046 # 4.17 commit 9b2c45d479d0fb8647c9e83359df69162b5fbe5f getname()
1047 # does not take the length *int argument and returns the length
1048 #
1049 AC_DEFUN([LN_SRC_CONFIG_SOCK_GETNAME], [
1050         LB2_LINUX_TEST_SRC([kern_sock_getname_2args], [
1051                 #include <linux/net.h>
1052         ],[
1053                 kernel_getsockname(NULL, NULL);
1054         ],[-Werror])
1055 ])
1056 AC_DEFUN([LN_CONFIG_SOCK_GETNAME], [
1057         AC_MSG_CHECKING([if 'getname' has two args])
1058         LB2_LINUX_TEST_RESULT([kern_sock_getname_2args], [
1059                 AC_DEFINE(HAVE_KERN_SOCK_GETNAME_2ARGS, 1,
1060                         ['getname' has two args])
1061         ])
1062 ]) # LN_CONFIG_SOCK_GETNAME
1063
1064 #
1065 # LN_HAVE_IN_DEV_FOR_EACH_IFA_RTNL
1066 #
1067 # kernel 5.3 commit ef11db3310e272d3d8dbe8739e0770820dd20e52
1068 # and kernel 4.18.0-193.el8:
1069 # added in_dev_for_each_ifa_rtnl and in_dev_for_each_ifa_rcu
1070 # and removed for_ifa and endfor_ifa.
1071 # Use the _rntl variant as the current locking is rtnl.
1072 #
1073 AC_DEFUN([LN_SRC_HAVE_IN_DEV_FOR_EACH_IFA_RTNL], [
1074         LB2_LINUX_TEST_SRC([in_dev_for_each_ifa_rtnl_test], [
1075                 #include <linux/inetdevice.h>
1076         ],[
1077                 const struct in_ifaddr *ifa = NULL;
1078                 struct in_device *in_dev = NULL;
1079
1080                 in_dev_for_each_ifa_rtnl(ifa, in_dev) {}
1081         ],[-Werror])
1082 ])
1083 AC_DEFUN([LN_HAVE_IN_DEV_FOR_EACH_IFA_RTNL], [
1084         AC_MSG_CHECKING([if 'in_dev_for_each_ifa_rtnl' is defined])
1085         LB2_LINUX_TEST_RESULT([in_dev_for_each_ifa_rtnl_test], [
1086                 AC_DEFINE(HAVE_IN_DEV_FOR_EACH_IFA_RTNL, 1,
1087                         ['in_dev_for_each_ifa_rtnl' is defined])
1088         ])
1089 ]) # LN_HAVE_IN_DEV_FOR_EACH_IFA_RTNL
1090
1091 #
1092 # LN_USR_RDMA
1093 #
1094 #
1095 AC_DEFUN([LN_USR_RDMA], [
1096 AC_MSG_CHECKING([if RDMA_PS_TCP exists])
1097 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1098         #include <rdma/rdma_user_cm.h>
1099
1100         int main(void) {
1101                 int x = (int)RDMA_PS_TCP;
1102                 return x;
1103         }
1104 ])],[
1105         AC_DEFINE(HAVE_USRSPC_RDMA_PS_TCP, 1,
1106                 [RDMA_PS_TCP exists])
1107 ])
1108 ]) # LN_USR_RDMA
1109
1110
1111 AC_DEFUN([LN_PROG_LINUX_SRC], [
1112         LN_CONFIG_O2IB_SRC
1113         # 3.15
1114         LN_SRC_CONFIG_SK_DATA_READY
1115         # 4.x
1116         LN_SRC_CONFIG_SOCK_CREATE_KERN
1117         # 4.14
1118         LN_SRC_HAVE_HYPERVISOR_IS_TYPE
1119         LN_SRC_HAVE_ORACLE_OFED_EXTENSIONS
1120         # 4.17
1121         LN_SRC_CONFIG_SOCK_GETNAME
1122         # 5.3 and 4.18.0-193.el8
1123         LN_SRC_HAVE_IN_DEV_FOR_EACH_IFA_RTNL
1124 ])
1125
1126 AC_DEFUN([LN_PROG_LINUX_RESULTS], [
1127         LN_CONFIG_O2IB_RESULTS
1128         # 3.15
1129         LN_CONFIG_SK_DATA_READY
1130         # 4.x
1131         LN_CONFIG_SOCK_CREATE_KERN
1132         # 4.14
1133         LN_HAVE_HYPERVISOR_IS_TYPE
1134         LN_HAVE_ORACLE_OFED_EXTENSIONS
1135         # 4.17
1136         LN_CONFIG_SOCK_GETNAME
1137         # 5.3 and 4.18.0-193.el8
1138         LN_HAVE_IN_DEV_FOR_EACH_IFA_RTNL
1139 ])
1140
1141 #
1142 # LN_PROG_LINUX
1143 #
1144 # LNet linux kernel checks
1145 #
1146 AC_DEFUN([LN_PROG_LINUX], [
1147 AC_MSG_NOTICE([LNet kernel checks
1148 ==============================================================================])
1149
1150 LN_CONFIG_BACKOFF
1151 LN_CONFIG_O2IB
1152 LN_CONFIG_GNILND
1153 LN_CONFIG_KFILND
1154 # 3.10 - Check export
1155 LN_EXPORT_KMAP_TO_PAGE
1156 ]) # LN_PROG_LINUX
1157
1158 #
1159 # LN_PATH_DEFAULTS
1160 #
1161 # default paths for installed files
1162 #
1163 AC_DEFUN([LN_PATH_DEFAULTS], [
1164 ]) # LN_PATH_DEFAULTS
1165
1166 #
1167 # LN_CONFIGURE
1168 #
1169 # other configure checks
1170 #
1171 AC_DEFUN([LN_CONFIGURE], [
1172 AC_MSG_NOTICE([LNet core checks
1173 ==============================================================================])
1174
1175 AC_ARG_WITH([cuda],
1176         AS_HELP_STRING([--with-cuda=path],
1177                         [Use a CUDA sources.]),
1178         [LB_ARG_CANON_PATH([cuda], [CUDA_PATH])],
1179         [CUDA_PATH=`ls -d1 /usr/src/nvidia-*/nvidia/ | tail -1`]
1180 )
1181
1182 AC_ARG_WITH([gds],
1183         AS_HELP_STRING([--with-gds=path],
1184                         [Use a gds sources.]),
1185         [LB_ARG_CANON_PATH([gds], [GDS_PATH])],
1186         [GDS_PATH=`ls -d1 /usr/src/nvidia-fs* | tail -1`]
1187 )
1188
1189 AS_IF([test -n "${CUDA_PATH}" && test -n "${GDS_PATH}"],[
1190 LB_CHECK_FILE([$CUDA_PATH/nv-p2p.h],
1191         [
1192         AC_MSG_RESULT([CUDA path is $CUDA_PATH])
1193         AC_SUBST(CUDA_PATH)
1194         ],
1195         [AC_MSG_ERROR([CUDA sources don't found. nv-p2p.h don't exit])]
1196 )
1197
1198 LB_CHECK_FILE([$GDS_PATH/nvfs-dma.h],
1199         [
1200         LB_CHECK_FILE([$GDS_PATH/config-host.h], [
1201         AC_MSG_RESULT([GDS path is $GDS_PATH])
1202         AC_SUBST(GDS_PATH)
1203         AC_DEFINE(WITH_GDS, 1, "GDS build enabled")
1204         ], [])
1205         ],
1206         [])
1207 ],[
1208         AC_MSG_WARN([CUDA or GDS sources not found. GDS support disabled])
1209 ]
1210 )
1211
1212 # lnet/utils/lnetconfig/liblnetconfig_netlink.c
1213 AS_IF([test "x$PKGCONF" = "x"],
1214         [AC_MSG_ERROR([pkg-config package is required to configure Lustre])])
1215
1216 AS_IF([test "x$enable_dist" = xno], [
1217         PKG_CHECK_MODULES(LIBNL3, [libnl-genl-3.0 >= 3.1])
1218 ])
1219
1220 AC_CHECK_LIB([nl-3], [nla_get_s32], [
1221         AC_DEFINE(HAVE_NLA_GET_S32, 1,
1222                 [libnl3 supports nla_get_s32])
1223         ], [
1224 ])
1225
1226 AC_CHECK_LIB([nl-3], [nla_get_s64], [
1227         AC_DEFINE(HAVE_NLA_GET_S64, 1,
1228                 [libnl3 supports nla_get_s64])
1229         ], [
1230 ])
1231
1232 #
1233 # LN_USR_NLMSGERR
1234 #
1235 AC_DEFUN([LN_USR_NLMSGERR], [
1236 AC_MSG_CHECKING([if 'enum nlmsgerr_attrs' exists])
1237 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1238         #include <linux/netlink.h>
1239
1240         int main(void) {
1241                 int x = (int)NLMSGERR_ATTR_MAX;
1242                 return x;
1243         }
1244 ])],[
1245         AC_DEFINE(HAVE_USRSPC_NLMSGERR, 1,
1246                 ['enum nlmsgerr_attrs' exists])
1247 ])
1248 ]) # LN_USR_NLMGSERR
1249
1250 # lnet/utils/portals.c
1251 AC_CHECK_HEADERS([netdb.h])
1252 AC_CHECK_FUNCS([gethostbyname])
1253
1254 # lnet/utils/wirecheck.c
1255 AC_CHECK_FUNCS([strnlen])
1256
1257 # --------  Check for required packages  --------------
1258
1259 AC_MSG_CHECKING([whether to enable 'efence' debugging support])
1260 AC_ARG_ENABLE(efence,
1261         AS_HELP_STRING([--enable-efence],
1262                 [use efence library]),
1263         [], [enable_efence="no"])
1264 AC_MSG_RESULT([$enable_efence])
1265
1266 LIBEFENCE=""
1267 AS_IF([test "$enable_efence" = yes], [
1268         LIBEFENCE="-lefence"
1269         AC_DEFINE(HAVE_LIBEFENCE, 1,
1270                 [libefence support is requested])
1271         AC_SUBST(ENABLE_EFENCE, yes)
1272 ], [
1273         AC_SUBST(ENABLE_EFENCE, no)
1274 ])
1275 AC_SUBST(LIBEFENCE)
1276
1277 LN_CONFIG_DLC
1278 LN_USR_RDMA
1279 LN_USR_NLMSGERR
1280 ]) # LN_CONFIGURE
1281
1282 #
1283 # LN_CONDITIONALS
1284 #
1285 # AM_CONDITIONAL defines for lnet
1286 #
1287 AC_DEFUN([LN_CONDITIONALS], [
1288 AM_CONDITIONAL(BUILD_O2IBLND,    test x$O2IBLND = "xo2iblnd")
1289 AM_CONDITIONAL(BUILD_GNILND,     test x$GNILND  = "xgnilnd")
1290 AM_CONDITIONAL(BUILD_KFILND,     test x$KFILND  = "xkfilnd")
1291 ]) # LN_CONDITIONALS
1292
1293 #
1294 # LN_CONFIG_FILES
1295 #
1296 # files that should be generated with AC_OUTPUT
1297 #
1298 AC_DEFUN([LN_CONFIG_FILES], [
1299 AC_CONFIG_FILES([
1300 lnet/Makefile
1301 lnet/autoMakefile
1302 lnet/autoconf/Makefile
1303 lnet/doc/Makefile
1304 lnet/include/Makefile
1305 lnet/include/lnet/Makefile
1306 lnet/include/uapi/linux/lnet/Makefile
1307 lnet/klnds/Makefile
1308 lnet/klnds/autoMakefile
1309 lnet/klnds/o2iblnd/Makefile
1310 lnet/klnds/o2iblnd/autoMakefile
1311 lnet/klnds/gnilnd/Makefile
1312 lnet/klnds/gnilnd/autoMakefile
1313 lnet/klnds/socklnd/Makefile
1314 lnet/klnds/socklnd/autoMakefile
1315 lnet/klnds/kfilnd/Makefile
1316 lnet/klnds/kfilnd/autoMakefile
1317 lnet/lnet/Makefile
1318 lnet/lnet/autoMakefile
1319 lnet/selftest/Makefile
1320 lnet/selftest/autoMakefile
1321 lnet/utils/Makefile
1322 lnet/utils/lnetconfig/Makefile
1323 ])
1324 ]) # LN_CONFIG_FILES