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