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