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