Whamcloud - gitweb
7c7764a3918fd4e5b4b8b3a149dc679deb7d7e71
[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 -a \
161                            -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \)], [
162                         o2ib_found=true
163                         break
164                 ])
165         done
166         if ! $o2ib_found; then
167                 AC_MSG_RESULT([no])
168                 case $ENABLEO2IB in
169                         "yes") AC_MSG_ERROR([no OFED nor kernel OpenIB gen2 headers present]) ;;
170                         "withpath") AC_MSG_ERROR([bad --with-o2ib path]) ;;
171                         *) AC_MSG_ERROR([internal error]) ;;
172                 esac
173         else
174                 COMPAT_AUTOCONF=""
175                 compatrdma_found=false
176                 if test -f ${O2IBPATH}/include/linux/compat-2.6.h; then
177                         AC_MSG_RESULT([yes])
178                         compatrdma_found=true
179                         AC_DEFINE(HAVE_COMPAT_RDMA, 1, [compat rdma found])
180                         EXTRA_OFED_CONFIG="$EXTRA_OFED_CONFIG -include ${O2IBPATH}/include/linux/compat-2.6.h"
181                         if test -f "$O2IBPATH/include/linux/compat_autoconf.h"; then
182                                 COMPAT_AUTOCONF="$O2IBPATH/include/linux/compat_autoconf.h"
183                         fi
184                 else
185                         AC_MSG_RESULT([no])
186                 fi
187                 if ! $compatrdma_found; then
188                         if test -f "$O2IBPATH/config.mk"; then
189                                 . "$O2IBPATH/config.mk"
190                         elif test -f "$O2IBPATH/ofed_patch.mk"; then
191                                 . "$O2IBPATH/ofed_patch.mk"
192                         fi
193                 elif test -z "$COMPAT_AUTOCONF"; then
194                         # Depreciated checks
195                         if test "x$RHEL_KERNEL" = xyes; then
196                                 RHEL_MAJOR=$(awk '/ RHEL_MAJOR / { print [$]3 }' $LINUX_OBJ/include/$VERSION_HDIR/version.h)
197                                 I=$(awk '/ RHEL_MINOR / { print [$]3 }' $LINUX_OBJ/include/$VERSION_HDIR/version.h)
198                                 while test "$I" -ge 0; do
199                                         EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_RHEL_${RHEL_MAJOR}_$I"
200                                         I=$(($I-1))
201                                 done
202                         elif test "x$SUSE_KERNEL" = xyes; then
203                                 SP=$(grep PATCHLEVEL /etc/SuSE-release | sed -e 's/.*= *//')
204                                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_SLES_11_$SP"
205                         fi
206                 fi
207
208                 AC_MSG_CHECKING([whether to use any OFED backport headers])
209                 if test -n "$BACKPORT_INCLUDES"; then
210                         AC_MSG_RESULT([yes])
211                         OFED_BACKPORT_PATH="$O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
212                         EXTRA_OFED_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_OFED_INCLUDE"
213                 else
214                         AC_MSG_RESULT([no])
215                 fi
216
217                 O2IBLND=""
218                 O2IBPATH=$(readlink --canonicalize $O2IBPATH)
219                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -I$O2IBPATH/include -I$O2IBPATH/include/uapi"
220                 EXTRA_CHECK_INCLUDE="$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE"
221                 LB_CHECK_COMPILE([whether to enable OpenIB gen2 support],
222                 openib_gen2_support, [
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/version.h>
233                         #include <linux/pci.h>
234                         #include <linux/gfp.h>
235                         #include <rdma/rdma_cm.h>
236                         #include <rdma/ib_cm.h>
237                         #include <rdma/ib_verbs.h>
238                         #include <rdma/ib_fmr_pool.h>
239                 ],[
240                         struct rdma_cm_id      *cm_idi __attribute__ ((unused));
241                         struct rdma_conn_param  conn_param __attribute__ ((unused));
242                         struct ib_device_attr   device_attr __attribute__ ((unused));
243                         struct ib_qp_attr       qp_attr __attribute__ ((unused));
244                         struct ib_pool_fmr      pool_fmr __attribute__ ((unused));
245                         enum   ib_cm_rej_reason rej_reason __attribute__ ((unused));
246                         rdma_destroy_id(NULL);
247                 ],[
248                         O2IBLND="o2iblnd"
249                 ],[
250                         case $ENABLEO2IB in
251                         "yes") AC_MSG_ERROR([can't compile with OpenIB gen2 headers]) ;;
252                         "withpath") AC_MSG_ERROR([can't compile with OpenIB gen2 headers under $O2IBPATH]) ;;
253                         *) AC_MSG_ERROR([internal error]) ;;
254                         esac
255                 ])
256                 # we know at this point that the found OFED source is good
257                 O2IB_SYMVER=""
258                 if test $ENABLEO2IB = "withpath" -o "x$OFED" = "xyes" ; then
259                         if test -f $O2IBPATH/Module.symvers; then
260                                 O2IB_SYMVER=$O2IBPATH/Module.symvers;
261                                 break;
262                         fi
263                         if test -n "$O2IB_SYMVER"; then
264                                 AC_MSG_NOTICE([adding $O2IB_SYMVER to Symbol Path])
265                                 EXTRA_SYMBOLS="$EXTRA_SYMBOLS $O2IB_SYMVER"
266                                 AC_SUBST(EXTRA_SYMBOLS)
267                         else
268                                 AC_MSG_ERROR([an external source tree was, either specified or detected, for o2iblnd however I could not find a $O2IBPATH/Module.symvers there])
269                         fi
270                 fi
271
272                 LB_CHECK_COMPILE([if Linux kernel has kthread_worker],
273                 linux_kthread_worker, [
274                         #ifdef HAVE_COMPAT_RDMA
275                         #undef PACKAGE_NAME
276                         #undef PACKAGE_TARNAME
277                         #undef PACKAGE_VERSION
278                         #undef PACKAGE_STRING
279                         #undef PACKAGE_BUGREPORT
280                         #undef PACKAGE_URL
281                         #include <linux/compat-2.6.h>
282                         #endif
283                         #include <linux/kthread.h>
284                 ],[
285                         struct kthread_work *kth_wrk = NULL;
286                         flush_kthread_work(kth_wrk);
287                 ],[
288                         AC_DEFINE(HAVE_KTHREAD_WORK, 1, [kthread_worker found])
289                         if test -z "$COMPAT_AUTOCONF"; then
290                                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_IS_KTHREAD"
291                         fi
292                 ])
293                 EXTRA_CHECK_INCLUDE=""
294         fi
295 ])
296 AC_SUBST(EXTRA_OFED_CONFIG)
297 AC_SUBST(EXTRA_OFED_INCLUDE)
298 AC_SUBST(O2IBLND)
299 AC_SUBST(O2IBPATH)
300 AC_SUBST(ENABLEO2IB)
301
302 AS_IF([test $ENABLEO2IB != "no"], [
303         EXTRA_CHECK_INCLUDE="$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE"
304
305         # In RHEL 6.2, rdma_create_id() takes the queue-pair type as a fourth argument
306         LB_CHECK_COMPILE([if 'rdma_create_id' wants four args],
307         rdma_create_id_4args, [
308                 #ifdef HAVE_COMPAT_RDMA
309                 #undef PACKAGE_NAME
310                 #undef PACKAGE_TARNAME
311                 #undef PACKAGE_VERSION
312                 #undef PACKAGE_STRING
313                 #undef PACKAGE_BUGREPORT
314                 #undef PACKAGE_URL
315                 #include <linux/compat-2.6.h>
316                 #endif
317                 #include <rdma/rdma_cm.h>
318         ],[
319                 rdma_create_id(NULL, NULL, 0, 0);
320         ],[
321                 AC_DEFINE(HAVE_RDMA_CREATE_ID_4ARG, 1,
322                         [rdma_create_id wants 4 args])
323         ])
324
325         # 4.4 added network namespace parameter for rdma_create_id()
326         LB_CHECK_COMPILE([if 'rdma_create_id' wants five args],
327         rdma_create_id_5args, [
328                 #ifdef HAVE_COMPAT_RDMA
329                 #undef PACKAGE_NAME
330                 #undef PACKAGE_TARNAME
331                 #undef PACKAGE_VERSION
332                 #undef PACKAGE_STRING
333                 #undef PACKAGE_BUGREPORT
334                 #undef PACKAGE_URL
335                 #include <linux/compat-2.6.h>
336                 #endif
337                 #include <rdma/rdma_cm.h>
338         ],[
339                 rdma_create_id(NULL, NULL, NULL, 0, 0);
340         ],[
341                 AC_DEFINE(HAVE_RDMA_CREATE_ID_5ARG, 1,
342                         [rdma_create_id wants 5 args])
343         ])
344
345         # 4.2 introduced struct ib_cq_init_attr which is used
346         # by ib_create_cq(). Note some OFED stacks only keep
347         # their headers in sync with latest kernels but not
348         # the functionality which means for infiniband testing
349         # we need to always test functionality testings.
350         LB_CHECK_COMPILE([if 'struct ib_cq_init_attr' is used],
351         ib_cq_init_attr, [
352                 #ifdef HAVE_COMPAT_RDMA
353                 #undef PACKAGE_NAME
354                 #undef PACKAGE_TARNAME
355                 #undef PACKAGE_VERSION
356                 #undef PACKAGE_STRING
357                 #undef PACKAGE_BUGREPORT
358                 #undef PACKAGE_URL
359                 #include <linux/compat-2.6.h>
360                 #endif
361                 #include <rdma/ib_verbs.h>
362         ],[
363                 struct ib_cq_init_attr cq_attr;
364
365                 ib_create_cq(NULL, NULL, NULL, NULL, &cq_attr);
366         ],[
367                 AC_DEFINE(HAVE_IB_CQ_INIT_ATTR, 1,
368                         [struct ib_cq_init_attr is used by ib_create_cq])
369         ])
370
371         # 4.3 removed ib_alloc_fast_reg_mr()
372         LB_CHECK_COMPILE([if 'ib_alloc_fast_reg_mr' exists],
373         ib_alloc_fast_reg_mr, [
374                 #ifdef HAVE_COMPAT_RDMA
375                 #undef PACKAGE_NAME
376                 #undef PACKAGE_TARNAME
377                 #undef PACKAGE_VERSION
378                 #undef PACKAGE_STRING
379                 #undef PACKAGE_BUGREPORT
380                 #undef PACKAGE_URL
381                 #include <linux/compat-2.6.h>
382                 #endif
383                 #include <rdma/ib_verbs.h>
384         ],[
385                 ib_alloc_fast_reg_mr(NULL, 0);
386         ],[
387                 AC_DEFINE(HAVE_IB_ALLOC_FAST_REG_MR, 1,
388                         [ib_alloc_fast_reg_mr is defined])
389         ])
390
391         # 4.9 must stop using ib_get_dma_mr and the global MR
392         # We then have to use FMR/Fastreg for all RDMA.
393         LB_CHECK_COMPILE([if 'ib_get_dma_mr' exists],
394         ib_get_dma_mr, [
395                 #ifdef HAVE_COMPAT_RDMA
396                 #undef PACKAGE_NAME
397                 #undef PACKAGE_TARNAME
398                 #undef PACKAGE_VERSION
399                 #undef PACKAGE_STRING
400                 #undef PACKAGE_BUGREPORT
401                 #undef PACKAGE_URL
402                 #include <linux/compat-2.6.h>
403                 #endif
404                 #include <rdma/ib_verbs.h>
405         ],[
406                 ib_get_dma_mr(NULL, 0);
407         ],[
408                 AC_DEFINE(HAVE_IB_GET_DMA_MR, 1,
409                         [ib_get_dma_mr is defined])
410         ])
411
412         # In v4.4 Linux kernel,
413         # commit e622f2f4ad2142d2a613a57fb85f8cf737935ef5
414         # split up struct ib_send_wr so that all non-trivial verbs
415         # use their own structure which embedds struct ib_send_wr.
416         LB_CHECK_COMPILE([if 'struct ib_rdma_wr' is defined],
417         ib_rdma_wr, [
418                 #ifdef HAVE_COMPAT_RDMA
419                 #undef PACKAGE_NAME
420                 #undef PACKAGE_TARNAME
421                 #undef PACKAGE_VERSION
422                 #undef PACKAGE_STRING
423                 #undef PACKAGE_BUGREPORT
424                 #undef PACKAGE_URL
425                 #include <linux/compat-2.6.h>
426                 #endif
427                 #include <rdma/ib_verbs.h>
428         ],[
429                 struct ib_rdma_wr *wr __attribute__ ((unused));
430
431                 wr = rdma_wr(NULL);
432         ],[
433                 AC_DEFINE(HAVE_IB_RDMA_WR, 1,
434                         [struct ib_rdma_wr is defined])
435         ])
436
437         # new fast registration API introduced in 4.4
438         LB_CHECK_COMPILE([if 4arg 'ib_map_mr_sg' exists],
439         ib_map_mr_sg_4args, [
440                 #ifdef HAVE_COMPAT_RDMA
441                 #undef PACKAGE_NAME
442                 #undef PACKAGE_TARNAME
443                 #undef PACKAGE_VERSION
444                 #undef PACKAGE_STRING
445                 #undef PACKAGE_BUGREPORT
446                 #undef PACKAGE_URL
447                 #include <linux/compat-2.6.h>
448                 #endif
449                 #include <rdma/ib_verbs.h>
450         ],[
451                 ib_map_mr_sg(NULL, NULL, 0, 0);
452         ],[
453                 AC_DEFINE(HAVE_IB_MAP_MR_SG, 1,
454                         [ib_map_mr_sg exists])
455         ])
456
457         # ib_map_mr_sg changes from 4 to 5 args (adding sg_offset_p)
458         # in kernel 4.7 (and RHEL 7.3)
459         LB_CHECK_COMPILE([if 5arg 'ib_map_mr_sg' exists],
460         ib_map_mr_sg_5args, [
461                 #ifdef HAVE_COMPAT_RDMA
462                 #undef PACKAGE_NAME
463                 #undef PACKAGE_TARNAME
464                 #undef PACKAGE_VERSION
465                 #undef PACKAGE_STRING
466                 #undef PACKAGE_BUGREPORT
467                 #undef PACKAGE_URL
468                 #include <linux/compat-2.6.h>
469                 #endif
470                 #include <rdma/ib_verbs.h>
471         ],[
472                 ib_map_mr_sg(NULL, NULL, 0, NULL, 0);
473         ],[
474                 AC_DEFINE(HAVE_IB_MAP_MR_SG, 1,
475                         [ib_map_mr_sg exists])
476                 AC_DEFINE(HAVE_IB_MAP_MR_SG_5ARGS, 1,
477                         [ib_map_mr_sg has 5 arguments])
478         ])
479
480         # ib_query_device() removed in 4.5
481         LB_CHECK_COMPILE([if 'struct ib_device' has member 'attrs'],
482         ib_device.attrs, [
483                 #ifdef HAVE_COMPAT_RDMA
484                 #undef PACKAGE_NAME
485                 #undef PACKAGE_TARNAME
486                 #undef PACKAGE_VERSION
487                 #undef PACKAGE_STRING
488                 #undef PACKAGE_BUGREPORT
489                 #undef PACKAGE_URL
490                 #include <linux/compat-2.6.h>
491                 #endif
492                 #include <rdma/ib_verbs.h>
493         ],[
494                 struct ib_device dev;
495                 struct ib_device_attr dev_attr = {};
496                 dev.attrs = dev_attr;
497         ],[
498                 AC_DEFINE(HAVE_IB_DEVICE_ATTRS, 1,
499                         [struct ib_device.attrs is defined])
500         ])
501
502         # A flags argument was added to ib_alloc_pd() in Linux 4.9,
503         # commit ed082d36a7b2c27d1cda55fdfb28af18040c4a89
504         LB_CHECK_COMPILE([if 2arg 'ib_alloc_pd' exists],
505         ib_alloc_pd, [
506                 #ifdef HAVE_COMPAT_RDMA
507                 #undef PACKAGE_NAME
508                 #undef PACKAGE_TARNAME
509                 #undef PACKAGE_VERSION
510                 #undef PACKAGE_STRING
511                 #undef PACKAGE_BUGREPORT
512                 #undef PACKAGE_URL
513                 #include <linux/compat-2.6.h>
514                 #endif
515                 #include <rdma/ib_verbs.h>
516         ],[
517                 ib_alloc_pd(NULL, 0);
518         ],[
519                 AC_DEFINE(HAVE_IB_ALLOC_PD_2ARGS, 1,
520                         [ib_alloc_pd has 2 arguments])
521         ])
522
523         LB_CHECK_COMPILE([if function 'ib_inc_rkey' is defined],
524         ib_inc_rkey, [
525                 #ifdef HAVE_COMPAT_RDMA
526                 #undef PACKAGE_NAME
527                 #undef PACKAGE_TARNAME
528                 #undef PACKAGE_VERSION
529                 #undef PACKAGE_STRING
530                 #undef PACKAGE_BUGREPORT
531                 #undef PACKAGE_URL
532                 #include <linux/compat-2.6.h>
533                 #endif
534                 #include <rdma/ib_verbs.h>
535         ],[
536                 (void)ib_inc_rkey(0);
537         ],[
538                 AC_DEFINE(HAVE_IB_INC_RKEY, 1,
539                           [function ib_inc_rkey exist])
540         ])
541
542         # In MOFED 4.6, the second and third parameters for
543         # ib_post_send() and ib_post_recv() are declared with
544         # 'const'.
545         tmp_flags="$EXTRA_KCFLAGS"
546         EXTRA_KCFLAGS="-Werror"
547         LB_CHECK_COMPILE([if 'ib_post_send() and ib_post_recv()' have const parameters],
548         ib_post_send_recv_const, [
549                 #ifdef HAVE_COMPAT_RDMA
550                 #undef PACKAGE_NAME
551                 #undef PACKAGE_TARNAME
552                 #undef PACKAGE_VERSION
553                 #undef PACKAGE_STRING
554                 #undef PACKAGE_BUGREPORT
555                 #undef PACKAGE_URL
556                 #include <linux/compat-2.6.h>
557                 #endif
558                 #include <rdma/ib_verbs.h>
559         ],[
560                 ib_post_send(NULL, (const struct ib_send_wr *)NULL,
561                              (const struct ib_send_wr **)NULL);
562         ],[
563                 AC_DEFINE(HAVE_IB_POST_SEND_RECV_CONST, 1,
564                         [ib_post_send and ib_post_recv have const parameters])
565         ])
566         EXTRA_KCFLAGS="$tmp_flags"
567
568         # 5.0
569         LN_IB_DEVICE_OPS_EXISTS
570         # 5.1
571         LN_IB_SG_DMA_ADDRESS_EXISTS
572
573         EXTRA_CHECK_INCLUDE=""
574 ]) # ENABLEO2IB != "no"
575 ]) # LN_CONFIG_O2IB
576
577 #
578 # LN_CONFIG_GNILND
579 #
580 # check whether to use the Gemini Network Interface lnd
581 #
582 AC_DEFUN([LN_CONFIG_GNILND], [
583 AC_MSG_CHECKING([whether to enable GNI lnd])
584 AC_ARG_ENABLE([gni],
585         AC_HELP_STRING([--enable-gni],
586                 [enable GNI lnd]),
587         [], [enable_gni="no"])
588 AC_MSG_RESULT([$enable_gni])
589
590 AS_IF([test "x$enable_gni" = xyes], [
591         # GNICPPFLAGS was set in spec file
592         EXTRA_KCFLAGS_save="$EXTRA_KCFLAGS"
593         EXTRA_KCFLAGS="$EXTRA_KCFLAGS $GNICPPFLAGS"
594         LB_CHECK_COMPILE([if GNI kernel headers are present],
595         GNI_header, [
596                 #include <linux/types.h>
597                 #include <gni_pub.h>
598         ],[
599                 gni_cdm_handle_t kgni_domain;
600                 gni_return_t     rc;
601                 int              rrc;
602                 rc = gni_cdm_create(0, 1, 1, 0, &kgni_domain);
603                 rrc = (rc == GNI_RC_SUCCESS) ? 0 : 1;
604                 return rrc;
605         ],[
606                 GNILND="gnilnd"
607         ],[
608                 AC_MSG_ERROR([can't compile gnilnd with given GNICPPFLAGS: $GNICPPFLAGS])
609         ])
610         # at this point, we have gnilnd basic support,
611         # now check for extra features
612         LB_CHECK_COMPILE([to use RCA in gnilnd],
613         RCA_gnilnd, [
614                 #include <linux/types.h>
615                 #include <gni_pub.h>
616                 #include <krca_lib.h>
617         ],[
618                 gni_cdm_handle_t kgni_domain;
619                 gni_return_t     rc;
620                 krca_ticket_t    ticket = KRCA_NULL_TICKET;
621                 int              rrc;
622                 __u32            nid = 0, nic_addr;
623                 rc = gni_cdm_create(0, 1, 1, 0, &kgni_domain);
624                 rrc = (rc == GNI_RC_SUCCESS) ? 0 : 1;
625                 rrc += krca_nid_to_nicaddrs(nid, 1, &nic_addr);
626                 rrc += krca_register(&ticket, RCA_MAKE_SERVICE_INDEX(RCA_IO_CLASS, 9), 99, 0);
627                 return rrc;
628         ],[
629                 GNICPPFLAGS="$GNICPPFLAGS -DGNILND_USE_RCA=1"
630         ])
631         EXTRA_KCFLAGS="$EXTRA_KCFLAGS_save"
632 ])
633 AC_SUBST(GNICPPFLAGS)
634 AC_SUBST(GNILND)
635 ]) # LN_CONFIG_GNILND
636
637 #
638 # LN_CONFIG_SK_SLEEP
639 #
640 # 2.6.35 kernel has sk_sleep function
641 #
642 AC_DEFUN([LN_CONFIG_SK_SLEEP], [
643 LB_CHECK_COMPILE([if Linux kernel has 'sk_sleep'],
644 sk_sleep, [
645         #include <net/sock.h>
646 ],[
647         sk_sleep(NULL);
648 ],[
649         AC_DEFINE(HAVE_SK_SLEEP, 1,
650                   [kernel has sk_sleep])
651 ])
652 ]) # LN_CONFIG_SK_SLEEP
653
654 #
655 # LN_CONFIG_TCP_SENDPAGE
656 #
657 # 2.6.36 tcp_sendpage() first parameter is 'struct sock'
658 # instead of 'struct socket'.
659 #
660 AC_DEFUN([LN_CONFIG_TCP_SENDPAGE], [
661 tmp_flags="$EXTRA_KCFLAGS"
662 EXTRA_KCFLAGS="-Werror"
663 LB_CHECK_COMPILE([if 'tcp_sendpage' first parameter is socket],
664 tcp_sendpage_socket, [
665         #include <linux/net.h>
666         #include <net/tcp.h>
667 ],[
668         tcp_sendpage((struct socket*)0, NULL, 0, 0, 0);
669 ],[
670         AC_DEFINE(HAVE_TCP_SENDPAGE_USE_SOCKET, 1,
671                 [tcp_sendpage use socket as first parameter])
672 ])
673 EXTRA_KCFLAGS="$tmp_flags"
674 ]) # LN_CONFIG_TCP_SENDPAGE
675
676 # LN_CONFIG_SOCK_CREATE_KERN
677 #
678 # 4.x sock_create_kern() added a first parameter as 'struct net *'
679 # instead of int.
680 #
681 AC_DEFUN([LN_CONFIG_SOCK_CREATE_KERN], [
682 tmp_flags="$EXTRA_KCFLAGS"
683 EXTRA_KCFLAGS="-Werror"
684 LB_CHECK_COMPILE([if 'sock_create_kern' first parameter is net],
685 sock_create_kern_net, [
686         #include <linux/net.h>
687         #include <net/net_namespace.h>
688 ],[
689         sock_create_kern((struct net*)0, 0, 0, 0, NULL);
690 ],[
691         AC_DEFINE(HAVE_SOCK_CREATE_KERN_USE_NET, 1,
692                 [sock_create_kern use net as first parameter])
693 ])
694 EXTRA_KCFLAGS="$tmp_flags"
695 ]) # LN_CONFIG_SOCK_CREATE_KERN
696
697 #
698 # LN_CONFIG_SK_DATA_READY
699 #
700 # 3.15 for struct sock the *sk_data_ready() field only takes one argument now
701 #
702 AC_DEFUN([LN_CONFIG_SK_DATA_READY], [
703 tmp_flags="$EXTRA_KCFLAGS"
704 EXTRA_KCFLAGS="-Werror"
705 LB_CHECK_COMPILE([if 'sk_data_ready' takes only one argument],
706 sk_data_ready, [
707         #include <linux/net.h>
708         #include <net/sock.h>
709 ],[
710         ((struct sock *)0)->sk_data_ready(NULL);
711 ],[
712         AC_DEFINE(HAVE_SK_DATA_READY_ONE_ARG, 1,
713                 [sk_data_ready uses only one argument])
714 ])
715 EXTRA_KCFLAGS="$tmp_flags"
716 ]) # LN_CONFIG_SK_DATA_READY
717
718 #
719 # LN_EXPORT_KMAP_TO_PAGE
720 #
721 # 3.10 Export kmap_to_page
722 #
723 AC_DEFUN([LN_EXPORT_KMAP_TO_PAGE], [
724 LB_CHECK_EXPORT([kmap_to_page], [mm/highmem.c],
725         [AC_DEFINE(HAVE_KMAP_TO_PAGE, 1,
726                 [kmap_to_page is exported by the kernel])])
727 ]) # LN_EXPORT_KMAP_TO_PAG
728
729 #
730 # LN_CONFIG_SOCK_ACCEPT
731 #
732 # 4.11 commit cdfbabfb2f0ce983fdaa42f20e5f7842178fc01e added a flag
733 # to handle a possible lockdep condition kernel socket accept.
734 #
735 AC_DEFUN([LN_CONFIG_SOCK_ACCEPT], [
736 tmp_flags="$EXTRA_KCFLAGS"
737 EXTRA_KCFLAGS="-Werror"
738 LB_CHECK_COMPILE([if 'struct sock' accept function requires a bool argument],
739 kern_sock_flag, [
740         #include <linux/net.h>
741 ],[
742         ((struct socket *)0)->ops->accept(NULL, NULL, O_NONBLOCK, false);
743 ],[
744         AC_DEFINE(HAVE_KERN_SOCK_ACCEPT_FLAG_ARG, 1,
745                 ['struct sock' accept function requires bool argument])
746 ])
747 EXTRA_KCFLAGS="$tmp_flags"
748 ]) # LN_CONFIG_SOCK_ACCEPT
749
750 #
751 # LN_HAVE_ORACLE_OFED_EXTENSIONS
752 #
753 # Oracle UEK 5
754 #
755 AC_DEFUN([LN_HAVE_ORACLE_OFED_EXTENSIONS], [
756 LB_CHECK_COMPILE([if Oracle OFED Extensions are enabled],
757 oracle_ofed_ext, [
758         #include <rdma/ib_fmr_pool.h>
759 ],[
760         struct ib_fmr_pool_param param = {
761                 .relaxed           = 0
762         };
763         (void)param;
764 ],[
765         AC_DEFINE(HAVE_ORACLE_OFED_EXTENSIONS, 1,
766                 [if Oracle OFED Extensions are enabled])
767 ])
768 ]) # LN_HAVE_ORACLE_OFED_EXTENSIONS
769
770 #
771 # LN_CONFIG_SOCK_GETNAME
772 #
773 # 4.17 commit 9b2c45d479d0fb8647c9e83359df69162b5fbe5f getname()
774 # does not take the length *int argument and returns the length
775 #
776 AC_DEFUN([LN_CONFIG_SOCK_GETNAME], [
777 tmp_flags="$EXTRA_KCFLAGS"
778 EXTRA_KCFLAGS="-Werror"
779 LB_CHECK_COMPILE([if 'getname' has two args],
780 kern_sock_getname_2args, [
781         #include <linux/net.h>
782 ],[
783         kernel_getsockname(NULL, NULL);
784 ],[
785         AC_DEFINE(HAVE_KERN_SOCK_GETNAME_2ARGS, 1,
786                 ['getname' has two args])
787 ])
788 EXTRA_KCFLAGS="$tmp_flags"
789 ]) # LN_CONFIG_SOCK_GETNAME
790
791 #
792 # LN_IB_DEVICE_OPS_EXISTS
793 #
794 # kernel 5.0 commit 521ed0d92ab0db3edd17a5f4716b7f698f4fce61
795 # RDMA/core: Introduce ib_device_ops
796 # ... introduces the ib_device_ops structure that defines all the
797 # InfiniBand device operations in one place ...
798 #
799 AC_DEFUN([LN_IB_DEVICE_OPS_EXISTS], [
800 tmp_flags="$EXTRA_KCFLAGS"
801 EXTRA_KCFLAGS="-Werror"
802 LB_CHECK_COMPILE([if struct ib_device_ops is defined],
803 ib_device_ops_test, [
804         #include <rdma/ib_verbs.h>
805 ],[
806         int x = offsetof(struct ib_device_ops, unmap_fmr);
807         x = x;
808         (void)x;
809 ],[
810         AC_DEFINE(HAVE_IB_DEVICE_OPS, 1,
811                 [if struct ib_device_ops is defined])
812 ])
813 EXTRA_KCFLAGS="$tmp_flags"
814 ]) # LN_IB_DEVICE_OPS_EXISTS
815
816 #
817 # LN_IB_SG_DMA_ADDRESS_EXISTS
818 #
819 # kernel 5.1 commit a163afc88556e099271a7b423295bc5176fcecce
820 # IB/core: Remove ib_sg_dma_address() and ib_sg_dma_len()
821 # ... when dma_ops existed (3.6) ib_sg_dma_address() was not trivial ...
822 #
823 AC_DEFUN([LN_IB_SG_DMA_ADDRESS_EXISTS], [
824 tmp_flags="$EXTRA_KCFLAGS"
825 EXTRA_KCFLAGS="-Werror"
826 LB_CHECK_COMPILE([if ib_sg_dma_address wrapper exists],
827 ib_sg_dma_address_test, [
828         #include <rdma/ib_verbs.h>
829 ],[
830         u64 x = ib_sg_dma_address(NULL, NULL);
831         x = x;
832         (void)x;
833 ],[
834         AC_DEFINE(HAVE_IB_SG_DMA_ADDRESS, 1,
835                 [if ib_sg_dma_address wrapper exists])
836 ])
837 EXTRA_KCFLAGS="$tmp_flags"
838 ]) # LN_IB_SG_DMA_ADDRESS_EXISTS
839
840 #
841 # LN_PROG_LINUX
842 #
843 # LNet linux kernel checks
844 #
845 AC_DEFUN([LN_PROG_LINUX], [
846 AC_MSG_NOTICE([LNet kernel checks
847 ==============================================================================])
848
849 LN_CONFIG_AFFINITY
850 LN_CONFIG_BACKOFF
851 LN_CONFIG_O2IB
852 LN_CONFIG_GNILND
853 # 2.6.35
854 LN_CONFIG_SK_SLEEP
855 # 2.6.36
856 LN_CONFIG_TCP_SENDPAGE
857 # 3.10
858 LN_EXPORT_KMAP_TO_PAGE
859 # 3.15
860 LN_CONFIG_SK_DATA_READY
861 # 4.x
862 LN_CONFIG_SOCK_CREATE_KERN
863 # 4.11
864 LN_CONFIG_SOCK_ACCEPT
865 # 4.14
866 LN_HAVE_ORACLE_OFED_EXTENSIONS
867 # 4.17
868 LN_CONFIG_SOCK_GETNAME
869 ]) # LN_PROG_LINUX
870
871 #
872 # LN_PATH_DEFAULTS
873 #
874 # default paths for installed files
875 #
876 AC_DEFUN([LN_PATH_DEFAULTS], [
877 ]) # LN_PATH_DEFAULTS
878
879 #
880 # LN_CONFIGURE
881 #
882 # other configure checks
883 #
884 AC_DEFUN([LN_CONFIGURE], [
885 AC_MSG_NOTICE([LNet core checks
886 ==============================================================================])
887
888 # lnet/utils/portals.c
889 AC_CHECK_HEADERS([netdb.h])
890 AC_CHECK_FUNCS([gethostbyname])
891
892 # lnet/utils/wirecheck.c
893 AC_CHECK_FUNCS([strnlen])
894
895 # --------  Check for required packages  --------------
896
897 AC_MSG_CHECKING([whether to enable 'efence' debugging support])
898 AC_ARG_ENABLE(efence,
899         AC_HELP_STRING([--enable-efence],
900                 [use efence library]),
901         [], [enable_efence="no"])
902 AC_MSG_RESULT([$enable_efence])
903
904 LIBEFENCE=""
905 AS_IF([test "$enable_efence" = yes], [
906         LIBEFENCE="-lefence"
907         AC_DEFINE(HAVE_LIBEFENCE, 1,
908                 [libefence support is requested])
909 ])
910 AC_SUBST(LIBEFENCE)
911
912 LN_CONFIG_DLC
913 ]) # LN_CONFIGURE
914
915 #
916 # LN_CONDITIONALS
917 #
918 # AM_CONDITIONAL defines for lnet
919 #
920 AC_DEFUN([LN_CONDITIONALS], [
921 AM_CONDITIONAL(BUILD_O2IBLND,    test x$O2IBLND = "xo2iblnd")
922 AM_CONDITIONAL(BUILD_GNILND,     test x$GNILND  = "xgnilnd")
923 ]) # LN_CONDITIONALS
924
925 #
926 # LN_CONFIG_FILES
927 #
928 # files that should be generated with AC_OUTPUT
929 #
930 AC_DEFUN([LN_CONFIG_FILES], [
931 AC_CONFIG_FILES([
932 lnet/Makefile
933 lnet/autoMakefile
934 lnet/autoconf/Makefile
935 lnet/doc/Makefile
936 lnet/include/Makefile
937 lnet/include/lnet/Makefile
938 lnet/include/uapi/linux/lnet/Makefile
939 lnet/klnds/Makefile
940 lnet/klnds/autoMakefile
941 lnet/klnds/o2iblnd/Makefile
942 lnet/klnds/o2iblnd/autoMakefile
943 lnet/klnds/gnilnd/Makefile
944 lnet/klnds/gnilnd/autoMakefile
945 lnet/klnds/socklnd/Makefile
946 lnet/klnds/socklnd/autoMakefile
947 lnet/lnet/Makefile
948 lnet/lnet/autoMakefile
949 lnet/selftest/Makefile
950 lnet/selftest/autoMakefile
951 lnet/utils/Makefile
952 lnet/utils/lnetconfig/Makefile
953 ])
954 ]) # LN_CONFIG_FILES