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