Whamcloud - gitweb
1a49733421ed862b9020bff5cea20675dd41e6f6
[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         AC_CHECK_LIB([yaml], [yaml_parser_initialize],
85                      [LIBYAML="libyaml"],
86                      [AC_MSG_ERROR([YAML development libraries not not installed])],
87                      [-lm])
88 ])
89
90 #
91 # LN_CONFIG_O2IB
92 #
93 # If current OFED installed (assume with "ofed_info") and devel
94 # headers are not found, error because we assume OFED infiniband
95 # driver needs to be used and we must configure/build with it.
96 # Current OFED headers detection mechanism allow for non-standard
97 # prefix but relies on "ofed_info" command and on "%prefix/openib"
98 # link (both are ok for 1.5.x and 3.x versions), and should work
99 # for both source and DKMS builds.
100 #
101 AC_DEFUN([LN_CONFIG_O2IB], [
102 AC_MSG_CHECKING([whether to use Compat RDMA])
103 AC_ARG_WITH([o2ib],
104         AC_HELP_STRING([--with-o2ib=[yes|no|<path>]],
105                 [build o2iblnd against path]),
106         [], [with_o2ib="yes"])
107
108 case $with_o2ib in
109         yes)    AS_IF([which ofed_info 2>/dev/null], [
110                         AS_IF([test x$uses_dpkg = xyes], [
111                                 OFED_INFO="ofed_info | awk '{print \[$]2}'"
112                                 LSPKG="dpkg --listfiles"
113                         ], [
114                                 OFED_INFO="ofed_info"
115                                 LSPKG="rpm -ql"
116                         ])
117                         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)
118                         AS_IF([test -z "$O2IBPATHS"], [
119                                 AC_MSG_ERROR([
120 You seem to have an OFED installed but have not installed it's devel package.
121 If you still want to build Lustre for your OFED I/B stack, you need to install its devel headers RPM.
122 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.
123                                              ])
124                         ])
125                         AS_IF([test $(echo $O2IBPATHS | wc -w) -ge 2], [
126                                 AC_MSG_ERROR([
127 It appears that you have multiple OFED versions installed.
128 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.
129 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.
130                                              ])
131                         ])
132                         if test -e $O2IBPATHS/${LINUXRELEASE}; then
133                             O2IBPATHS=$O2IBPATHS/${LINUXRELEASE}
134                         elif test -e $O2IBPATHS/default; then
135                             O2IBPATHS=$O2IBPATHS/default
136                         fi
137                         OFED="yes"
138                 ], [
139                         O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
140                 ])
141                 ENABLEO2IB="yes"
142                 ;;
143         no)     ENABLEO2IB="no"
144                 ;;
145         *)      O2IBPATHS=$with_o2ib
146                 ENABLEO2IB="withpath"
147                 OFED="yes"
148                 ;;
149 esac
150
151 AS_IF([test $ENABLEO2IB = "no"], [
152         AC_MSG_RESULT([no])
153 ], [
154         o2ib_found=false
155         for O2IBPATH in $O2IBPATHS; do
156                 AS_IF([test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
157                            -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
158                            -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
159                            -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \)], [
160                         o2ib_found=true
161                         break
162                 ])
163         done
164         if ! $o2ib_found; then
165                 AC_MSG_RESULT([no])
166                 case $ENABLEO2IB in
167                         "yes") AC_MSG_ERROR([no OFED nor kernel OpenIB gen2 headers present]) ;;
168                         "withpath") AC_MSG_ERROR([bad --with-o2ib path]) ;;
169                         *) AC_MSG_ERROR([internal error]) ;;
170                 esac
171         else
172                 COMPAT_AUTOCONF=""
173                 compatrdma_found=false
174                 if test -f ${O2IBPATH}/include/linux/compat-2.6.h; then
175                         AC_MSG_RESULT([yes])
176                         compatrdma_found=true
177                         AC_DEFINE(HAVE_COMPAT_RDMA, 1, [compat rdma found])
178                         EXTRA_OFED_CONFIG="$EXTRA_OFED_CONFIG -include ${O2IBPATH}/include/linux/compat-2.6.h"
179                         if test -f "$O2IBPATH/include/linux/compat_autoconf.h"; then
180                                 COMPAT_AUTOCONF="$O2IBPATH/include/linux/compat_autoconf.h"
181                         fi
182                 else
183                         AC_MSG_RESULT([no])
184                 fi
185                 if ! $compatrdma_found; then
186                         if test -f "$O2IBPATH/config.mk"; then
187                                 . "$O2IBPATH/config.mk"
188                         elif test -f "$O2IBPATH/ofed_patch.mk"; then
189                                 . "$O2IBPATH/ofed_patch.mk"
190                         fi
191                 elif test -z "$COMPAT_AUTOCONF"; then
192                         # Depreciated checks
193                         if test "x$RHEL_KERNEL" = xyes; then
194                                 RHEL_MAJOR=$(awk '/ RHEL_MAJOR / { print [$]3 }' $LINUX_OBJ/include/$VERSION_HDIR/version.h)
195                                 I=$(awk '/ RHEL_MINOR / { print [$]3 }' $LINUX_OBJ/include/$VERSION_HDIR/version.h)
196                                 while test "$I" -ge 0; do
197                                         EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_RHEL_${RHEL_MAJOR}_$I"
198                                         I=$(($I-1))
199                                 done
200                         elif test "x$SUSE_KERNEL" = xyes; then
201                                 SP=$(grep PATCHLEVEL /etc/SuSE-release | sed -e 's/.*= *//')
202                                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_SLES_11_$SP"
203                         fi
204                 fi
205
206                 AC_MSG_CHECKING([whether to use any OFED backport headers])
207                 if test -n "$BACKPORT_INCLUDES"; then
208                         AC_MSG_RESULT([yes])
209                         OFED_BACKPORT_PATH="$O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
210                         EXTRA_OFED_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_OFED_INCLUDE"
211                 else
212                         AC_MSG_RESULT([no])
213                 fi
214
215                 O2IBLND=""
216                 O2IBPATH=$(readlink --canonicalize $O2IBPATH)
217                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -I$O2IBPATH/include -I$O2IBPATH/include/uapi"
218                 EXTRA_CHECK_INCLUDE="$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE"
219                 LB_CHECK_COMPILE([whether to enable OpenIB gen2 support],
220                 openib_gen2_support, [
221                         #ifdef HAVE_COMPAT_RDMA
222                         #undef PACKAGE_NAME
223                         #undef PACKAGE_TARNAME
224                         #undef PACKAGE_VERSION
225                         #undef PACKAGE_STRING
226                         #undef PACKAGE_BUGREPORT
227                         #undef PACKAGE_URL
228                         #include <linux/compat-2.6.h>
229                         #endif
230                         #include <linux/version.h>
231                         #include <linux/pci.h>
232                         #include <linux/gfp.h>
233                         #include <rdma/rdma_cm.h>
234                         #include <rdma/ib_cm.h>
235                         #include <rdma/ib_verbs.h>
236                         #include <rdma/ib_fmr_pool.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                         struct ib_pool_fmr      pool_fmr __attribute__ ((unused));
243                         enum   ib_cm_rej_reason rej_reason __attribute__ ((unused));
244                         rdma_destroy_id(NULL);
245                 ],[
246                         O2IBLND="o2iblnd"
247                 ],[
248                         case $ENABLEO2IB in
249                         "yes") AC_MSG_ERROR([can't compile with OpenIB gen2 headers]) ;;
250                         "withpath") AC_MSG_ERROR([can't compile with OpenIB gen2 headers under $O2IBPATH]) ;;
251                         *) AC_MSG_ERROR([internal error]) ;;
252                         esac
253                 ])
254                 # we know at this point that the found OFED source is good
255                 O2IB_SYMVER=""
256                 if test $ENABLEO2IB = "withpath" -o "x$OFED" = "xyes" ; then
257                         if test -f $O2IBPATH/Module.symvers; then
258                                 O2IB_SYMVER=$O2IBPATH/Module.symvers;
259                                 break;
260                         fi
261                         if test -n "$O2IB_SYMVER"; then
262                                 AC_MSG_NOTICE([adding $O2IB_SYMVER to Symbol Path])
263                                 EXTRA_SYMBOLS="$EXTRA_SYMBOLS $O2IB_SYMVER"
264                                 AC_SUBST(EXTRA_SYMBOLS)
265                         else
266                                 AC_MSG_ERROR([an external source tree was, either specified or detected, for o2iblnd however I could not find a $O2IBPATH/Module.symvers there])
267                         fi
268                 fi
269
270                 LB_CHECK_COMPILE([if Linux kernel has kthread_worker],
271                 linux_kthread_worker, [
272                         #ifdef HAVE_COMPAT_RDMA
273                         #undef PACKAGE_NAME
274                         #undef PACKAGE_TARNAME
275                         #undef PACKAGE_VERSION
276                         #undef PACKAGE_STRING
277                         #undef PACKAGE_BUGREPORT
278                         #undef PACKAGE_URL
279                         #include <linux/compat-2.6.h>
280                         #endif
281                         #include <linux/kthread.h>
282                 ],[
283                         struct kthread_work *kth_wrk = NULL;
284                         flush_kthread_work(kth_wrk);
285                 ],[
286                         AC_DEFINE(HAVE_KTHREAD_WORK, 1, [kthread_worker found])
287                         if test -z "$COMPAT_AUTOCONF"; then
288                                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_IS_KTHREAD"
289                         fi
290                 ])
291                 EXTRA_CHECK_INCLUDE=""
292         fi
293 ])
294 AC_SUBST(EXTRA_OFED_CONFIG)
295 AC_SUBST(EXTRA_OFED_INCLUDE)
296 AC_SUBST(O2IBLND)
297 AC_SUBST(O2IBPATH)
298 AC_SUBST(ENABLEO2IB)
299
300 AS_IF([test $ENABLEO2IB != "no"], [
301         EXTRA_CHECK_INCLUDE="$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE"
302
303         # In RHEL 6.2, rdma_create_id() takes the queue-pair type as a fourth argument
304         LB_CHECK_COMPILE([if 'rdma_create_id' wants four args],
305         rdma_create_id_4args, [
306                 #ifdef HAVE_COMPAT_RDMA
307                 #undef PACKAGE_NAME
308                 #undef PACKAGE_TARNAME
309                 #undef PACKAGE_VERSION
310                 #undef PACKAGE_STRING
311                 #undef PACKAGE_BUGREPORT
312                 #undef PACKAGE_URL
313                 #include <linux/compat-2.6.h>
314                 #endif
315                 #include <rdma/rdma_cm.h>
316         ],[
317                 rdma_create_id(NULL, NULL, 0, 0);
318         ],[
319                 AC_DEFINE(HAVE_RDMA_CREATE_ID_4ARG, 1,
320                         [rdma_create_id wants 4 args])
321         ])
322
323         # 4.4 added network namespace parameter for rdma_create_id()
324         LB_CHECK_COMPILE([if 'rdma_create_id' wants five args],
325         rdma_create_id_5args, [
326                 #ifdef HAVE_COMPAT_RDMA
327                 #undef PACKAGE_NAME
328                 #undef PACKAGE_TARNAME
329                 #undef PACKAGE_VERSION
330                 #undef PACKAGE_STRING
331                 #undef PACKAGE_BUGREPORT
332                 #undef PACKAGE_URL
333                 #include <linux/compat-2.6.h>
334                 #endif
335                 #include <rdma/rdma_cm.h>
336         ],[
337                 rdma_create_id(NULL, NULL, NULL, 0, 0);
338         ],[
339                 AC_DEFINE(HAVE_RDMA_CREATE_ID_5ARG, 1,
340                         [rdma_create_id wants 5 args])
341         ])
342
343         # 4.2 introduced struct ib_cq_init_attr which is used
344         # by ib_create_cq(). Note some OFED stacks only keep
345         # their headers in sync with latest kernels but not
346         # the functionality which means for infiniband testing
347         # we need to always test functionality testings.
348         LB_CHECK_COMPILE([if 'struct ib_cq_init_attr' is used],
349         ib_cq_init_attr, [
350                 #ifdef HAVE_COMPAT_RDMA
351                 #undef PACKAGE_NAME
352                 #undef PACKAGE_TARNAME
353                 #undef PACKAGE_VERSION
354                 #undef PACKAGE_STRING
355                 #undef PACKAGE_BUGREPORT
356                 #undef PACKAGE_URL
357                 #include <linux/compat-2.6.h>
358                 #endif
359                 #include <rdma/ib_verbs.h>
360         ],[
361                 struct ib_cq_init_attr cq_attr;
362
363                 ib_create_cq(NULL, NULL, NULL, NULL, &cq_attr);
364         ],[
365                 AC_DEFINE(HAVE_IB_CQ_INIT_ATTR, 1,
366                         [struct ib_cq_init_attr is used by ib_create_cq])
367         ])
368
369         # 4.3 removed ib_alloc_fast_reg_mr()
370         LB_CHECK_COMPILE([if 'ib_alloc_fast_reg_mr' exists],
371         ib_alloc_fast_reg_mr, [
372                 #ifdef HAVE_COMPAT_RDMA
373                 #undef PACKAGE_NAME
374                 #undef PACKAGE_TARNAME
375                 #undef PACKAGE_VERSION
376                 #undef PACKAGE_STRING
377                 #undef PACKAGE_BUGREPORT
378                 #undef PACKAGE_URL
379                 #include <linux/compat-2.6.h>
380                 #endif
381                 #include <rdma/ib_verbs.h>
382         ],[
383                 ib_alloc_fast_reg_mr(NULL, 0);
384         ],[
385                 AC_DEFINE(HAVE_IB_ALLOC_FAST_REG_MR, 1,
386                         [ib_alloc_fast_reg_mr is defined])
387         ])
388
389         # 4.9 must stop using ib_get_dma_mr and the global MR
390         # We then have to use FMR/Fastreg for all RDMA.
391         LB_CHECK_COMPILE([if 'ib_get_dma_mr' exists],
392         ib_get_dma_mr, [
393                 #ifdef HAVE_COMPAT_RDMA
394                 #undef PACKAGE_NAME
395                 #undef PACKAGE_TARNAME
396                 #undef PACKAGE_VERSION
397                 #undef PACKAGE_STRING
398                 #undef PACKAGE_BUGREPORT
399                 #undef PACKAGE_URL
400                 #include <linux/compat-2.6.h>
401                 #endif
402                 #include <rdma/ib_verbs.h>
403         ],[
404                 ib_get_dma_mr(NULL, 0);
405         ],[
406                 AC_DEFINE(HAVE_IB_GET_DMA_MR, 1,
407                         [ib_get_dma_mr is defined])
408         ])
409
410         # In v4.4 Linux kernel,
411         # commit e622f2f4ad2142d2a613a57fb85f8cf737935ef5
412         # split up struct ib_send_wr so that all non-trivial verbs
413         # use their own structure which embedds struct ib_send_wr.
414         LB_CHECK_COMPILE([if 'struct ib_rdma_wr' is defined],
415         ib_rdma_wr, [
416                 #ifdef HAVE_COMPAT_RDMA
417                 #undef PACKAGE_NAME
418                 #undef PACKAGE_TARNAME
419                 #undef PACKAGE_VERSION
420                 #undef PACKAGE_STRING
421                 #undef PACKAGE_BUGREPORT
422                 #undef PACKAGE_URL
423                 #include <linux/compat-2.6.h>
424                 #endif
425                 #include <rdma/ib_verbs.h>
426         ],[
427                 struct ib_rdma_wr *wr __attribute__ ((unused));
428
429                 wr = rdma_wr(NULL);
430         ],[
431                 AC_DEFINE(HAVE_IB_RDMA_WR, 1,
432                         [struct ib_rdma_wr is defined])
433         ])
434
435         # new fast registration API introduced in 4.4
436         LB_CHECK_COMPILE([if 4arg 'ib_map_mr_sg' exists],
437         ib_map_mr_sg_4args, [
438                 #ifdef HAVE_COMPAT_RDMA
439                 #undef PACKAGE_NAME
440                 #undef PACKAGE_TARNAME
441                 #undef PACKAGE_VERSION
442                 #undef PACKAGE_STRING
443                 #undef PACKAGE_BUGREPORT
444                 #undef PACKAGE_URL
445                 #include <linux/compat-2.6.h>
446                 #endif
447                 #include <rdma/ib_verbs.h>
448         ],[
449                 ib_map_mr_sg(NULL, NULL, 0, 0);
450         ],[
451                 AC_DEFINE(HAVE_IB_MAP_MR_SG, 1,
452                         [ib_map_mr_sg exists])
453         ])
454
455         # ib_map_mr_sg changes from 4 to 5 args (adding sg_offset_p)
456         # in kernel 4.7 (and RHEL 7.3)
457         LB_CHECK_COMPILE([if 5arg 'ib_map_mr_sg' exists],
458         ib_map_mr_sg_5args, [
459                 #ifdef HAVE_COMPAT_RDMA
460                 #undef PACKAGE_NAME
461                 #undef PACKAGE_TARNAME
462                 #undef PACKAGE_VERSION
463                 #undef PACKAGE_STRING
464                 #undef PACKAGE_BUGREPORT
465                 #undef PACKAGE_URL
466                 #include <linux/compat-2.6.h>
467                 #endif
468                 #include <rdma/ib_verbs.h>
469         ],[
470                 ib_map_mr_sg(NULL, NULL, 0, NULL, 0);
471         ],[
472                 AC_DEFINE(HAVE_IB_MAP_MR_SG, 1,
473                         [ib_map_mr_sg exists])
474                 AC_DEFINE(HAVE_IB_MAP_MR_SG_5ARGS, 1,
475                         [ib_map_mr_sg has 5 arguments])
476         ])
477
478         # ib_query_device() removed in 4.5
479         LB_CHECK_COMPILE([if 'struct ib_device' has member 'attrs'],
480         ib_device.attrs, [
481                 #ifdef HAVE_COMPAT_RDMA
482                 #undef PACKAGE_NAME
483                 #undef PACKAGE_TARNAME
484                 #undef PACKAGE_VERSION
485                 #undef PACKAGE_STRING
486                 #undef PACKAGE_BUGREPORT
487                 #undef PACKAGE_URL
488                 #include <linux/compat-2.6.h>
489                 #endif
490                 #include <rdma/ib_verbs.h>
491         ],[
492                 struct ib_device dev;
493                 struct ib_device_attr dev_attr = {};
494                 dev.attrs = dev_attr;
495         ],[
496                 AC_DEFINE(HAVE_IB_DEVICE_ATTRS, 1,
497                         [struct ib_device.attrs is defined])
498         ])
499
500         # A flags argument was added to ib_alloc_pd() in Linux 4.9,
501         # commit ed082d36a7b2c27d1cda55fdfb28af18040c4a89
502         LB_CHECK_COMPILE([if 2arg 'ib_alloc_pd' exists],
503         ib_alloc_pd, [
504                 #ifdef HAVE_COMPAT_RDMA
505                 #undef PACKAGE_NAME
506                 #undef PACKAGE_TARNAME
507                 #undef PACKAGE_VERSION
508                 #undef PACKAGE_STRING
509                 #undef PACKAGE_BUGREPORT
510                 #undef PACKAGE_URL
511                 #include <linux/compat-2.6.h>
512                 #endif
513                 #include <rdma/ib_verbs.h>
514         ],[
515                 ib_alloc_pd(NULL, 0);
516         ],[
517                 AC_DEFINE(HAVE_IB_ALLOC_PD_2ARGS, 1,
518                         [ib_alloc_pd has 2 arguments])
519         ])
520
521         LB_CHECK_COMPILE([if function 'ib_inc_rkey' is defined],
522         ib_inc_rkey, [
523                 #ifdef HAVE_COMPAT_RDMA
524                 #undef PACKAGE_NAME
525                 #undef PACKAGE_TARNAME
526                 #undef PACKAGE_VERSION
527                 #undef PACKAGE_STRING
528                 #undef PACKAGE_BUGREPORT
529                 #undef PACKAGE_URL
530                 #include <linux/compat-2.6.h>
531                 #endif
532                 #include <rdma/ib_verbs.h>
533         ],[
534                 (void)ib_inc_rkey(0);
535         ],[
536                 AC_DEFINE(HAVE_IB_INC_RKEY, 1,
537                           [function ib_inc_rkey exist])
538         ])
539
540         # In MOFED 4.6, the second and third parameters for
541         # ib_post_send() and ib_post_recv() are declared with
542         # 'const'.
543         tmp_flags="$EXTRA_KCFLAGS"
544         EXTRA_KCFLAGS="-Werror"
545         LB_CHECK_COMPILE([if 'ib_post_send() and ib_post_recv()' have const parameters],
546         ib_post_send_recv_const, [
547                 #ifdef HAVE_COMPAT_RDMA
548                 #undef PACKAGE_NAME
549                 #undef PACKAGE_TARNAME
550                 #undef PACKAGE_VERSION
551                 #undef PACKAGE_STRING
552                 #undef PACKAGE_BUGREPORT
553                 #undef PACKAGE_URL
554                 #include <linux/compat-2.6.h>
555                 #endif
556                 #include <rdma/ib_verbs.h>
557         ],[
558                 ib_post_send(NULL, (const struct ib_send_wr *)NULL,
559                              (const struct ib_send_wr **)NULL);
560         ],[
561                 AC_DEFINE(HAVE_IB_POST_SEND_RECV_CONST, 1,
562                         [ib_post_send and ib_post_recv have const parameters])
563         ])
564         EXTRA_KCFLAGS="$tmp_flags"
565
566         EXTRA_CHECK_INCLUDE=""
567 ]) # ENABLEO2IB != "no"
568 ]) # LN_CONFIG_O2IB
569
570 #
571 # LN_CONFIG_GNILND
572 #
573 # check whether to use the Gemini Network Interface lnd
574 #
575 AC_DEFUN([LN_CONFIG_GNILND], [
576 AC_MSG_CHECKING([whether to enable GNI lnd])
577 AC_ARG_ENABLE([gni],
578         AC_HELP_STRING([--enable-gni],
579                 [enable GNI lnd]),
580         [], [enable_gni="no"])
581 AC_MSG_RESULT([$enable_gni])
582
583 AS_IF([test "x$enable_gni" = xyes], [
584         # GNICPPFLAGS was set in spec file
585         EXTRA_KCFLAGS_save="$EXTRA_KCFLAGS"
586         EXTRA_KCFLAGS="$EXTRA_KCFLAGS $GNICPPFLAGS"
587         LB_CHECK_COMPILE([if GNI kernel headers are present],
588         GNI_header, [
589                 #include <linux/types.h>
590                 #include <gni_pub.h>
591         ],[
592                 gni_cdm_handle_t kgni_domain;
593                 gni_return_t     rc;
594                 int              rrc;
595                 rc = gni_cdm_create(0, 1, 1, 0, &kgni_domain);
596                 rrc = (rc == GNI_RC_SUCCESS) ? 0 : 1;
597                 return rrc;
598         ],[
599                 GNILND="gnilnd"
600         ],[
601                 AC_MSG_ERROR([can't compile gnilnd with given GNICPPFLAGS: $GNICPPFLAGS])
602         ])
603         # at this point, we have gnilnd basic support,
604         # now check for extra features
605         LB_CHECK_COMPILE([to use RCA in gnilnd],
606         RCA_gnilnd, [
607                 #include <linux/types.h>
608                 #include <gni_pub.h>
609                 #include <krca_lib.h>
610         ],[
611                 gni_cdm_handle_t kgni_domain;
612                 gni_return_t     rc;
613                 krca_ticket_t    ticket = KRCA_NULL_TICKET;
614                 int              rrc;
615                 __u32            nid = 0, nic_addr;
616                 rc = gni_cdm_create(0, 1, 1, 0, &kgni_domain);
617                 rrc = (rc == GNI_RC_SUCCESS) ? 0 : 1;
618                 rrc += krca_nid_to_nicaddrs(nid, 1, &nic_addr);
619                 rrc += krca_register(&ticket, RCA_MAKE_SERVICE_INDEX(RCA_IO_CLASS, 9), 99, 0);
620                 return rrc;
621         ],[
622                 GNICPPFLAGS="$GNICPPFLAGS -DGNILND_USE_RCA=1"
623         ])
624         EXTRA_KCFLAGS="$EXTRA_KCFLAGS_save"
625 ])
626 AC_SUBST(GNICPPFLAGS)
627 AC_SUBST(GNILND)
628 ]) # LN_CONFIG_GNILND
629
630 #
631 # LN_CONFIG_SK_SLEEP
632 #
633 # 2.6.35 kernel has sk_sleep function
634 #
635 AC_DEFUN([LN_CONFIG_SK_SLEEP], [
636 LB_CHECK_COMPILE([if Linux kernel has 'sk_sleep'],
637 sk_sleep, [
638         #include <net/sock.h>
639 ],[
640         sk_sleep(NULL);
641 ],[
642         AC_DEFINE(HAVE_SK_SLEEP, 1,
643                   [kernel has sk_sleep])
644 ])
645 ]) # LN_CONFIG_SK_SLEEP
646
647 #
648 # LN_CONFIG_TCP_SENDPAGE
649 #
650 # 2.6.36 tcp_sendpage() first parameter is 'struct sock'
651 # instead of 'struct socket'.
652 #
653 AC_DEFUN([LN_CONFIG_TCP_SENDPAGE], [
654 tmp_flags="$EXTRA_KCFLAGS"
655 EXTRA_KCFLAGS="-Werror"
656 LB_CHECK_COMPILE([if 'tcp_sendpage' first parameter is socket],
657 tcp_sendpage_socket, [
658         #include <linux/net.h>
659         #include <net/tcp.h>
660 ],[
661         tcp_sendpage((struct socket*)0, NULL, 0, 0, 0);
662 ],[
663         AC_DEFINE(HAVE_TCP_SENDPAGE_USE_SOCKET, 1,
664                 [tcp_sendpage use socket as first parameter])
665 ])
666 EXTRA_KCFLAGS="$tmp_flags"
667 ]) # LN_CONFIG_TCP_SENDPAGE
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_CONFIG_SOCK_ACCEPT
724 #
725 # 4.11 commit cdfbabfb2f0ce983fdaa42f20e5f7842178fc01e added a flag
726 # to handle a possible lockdep condition kernel socket accept.
727 #
728 AC_DEFUN([LN_CONFIG_SOCK_ACCEPT], [
729 tmp_flags="$EXTRA_KCFLAGS"
730 EXTRA_KCFLAGS="-Werror"
731 LB_CHECK_COMPILE([if 'struct sock' accept function requires a bool argument],
732 kern_sock_flag, [
733         #include <linux/net.h>
734 ],[
735         ((struct socket *)0)->ops->accept(NULL, NULL, O_NONBLOCK, false);
736 ],[
737         AC_DEFINE(HAVE_KERN_SOCK_ACCEPT_FLAG_ARG, 1,
738                 ['struct sock' accept function requires bool argument])
739 ])
740 EXTRA_KCFLAGS="$tmp_flags"
741 ]) # LN_CONFIG_SOCK_ACCEPT
742
743 #
744 # LN_PROG_LINUX
745 #
746 # LNet linux kernel checks
747 #
748 AC_DEFUN([LN_PROG_LINUX], [
749 AC_MSG_NOTICE([LNet kernel checks
750 ==============================================================================])
751
752 LN_CONFIG_AFFINITY
753 LN_CONFIG_BACKOFF
754 LN_CONFIG_O2IB
755 LN_CONFIG_GNILND
756 # 2.6.35
757 LN_CONFIG_SK_SLEEP
758 # 2.6.36
759 LN_CONFIG_TCP_SENDPAGE
760 # 3.10
761 LN_EXPORT_KMAP_TO_PAGE
762 # 3.15
763 LN_CONFIG_SK_DATA_READY
764 # 4.x
765 LN_CONFIG_SOCK_CREATE_KERN
766 # 4.11
767 LN_CONFIG_SOCK_ACCEPT
768 ]) # LN_PROG_LINUX
769
770 #
771 # LN_PATH_DEFAULTS
772 #
773 # default paths for installed files
774 #
775 AC_DEFUN([LN_PATH_DEFAULTS], [
776 ]) # LN_PATH_DEFAULTS
777
778 #
779 # LN_CONFIGURE
780 #
781 # other configure checks
782 #
783 AC_DEFUN([LN_CONFIGURE], [
784 AC_MSG_NOTICE([LNet core checks
785 ==============================================================================])
786
787 # lnet/utils/portals.c
788 AC_CHECK_HEADERS([netdb.h])
789 AC_CHECK_FUNCS([gethostbyname])
790
791 # lnet/utils/wirecheck.c
792 AC_CHECK_FUNCS([strnlen])
793
794 # --------  Check for required packages  --------------
795
796 AC_MSG_CHECKING([whether to enable 'efence' debugging support])
797 AC_ARG_ENABLE(efence,
798         AC_HELP_STRING([--enable-efence],
799                 [use efence library]),
800         [], [enable_efence="no"])
801 AC_MSG_RESULT([$enable_efence])
802
803 LIBEFENCE=""
804 AS_IF([test "$enable_efence" = yes], [
805         LIBEFENCE="-lefence"
806         AC_DEFINE(HAVE_LIBEFENCE, 1,
807                 [libefence support is requested])
808 ])
809 AC_SUBST(LIBEFENCE)
810
811 LN_CONFIG_DLC
812 ]) # LN_CONFIGURE
813
814 #
815 # LN_CONDITIONALS
816 #
817 # AM_CONDITIONAL defines for lnet
818 #
819 AC_DEFUN([LN_CONDITIONALS], [
820 AM_CONDITIONAL(BUILD_O2IBLND,    test x$O2IBLND = "xo2iblnd")
821 AM_CONDITIONAL(BUILD_GNILND,     test x$GNILND  = "xgnilnd")
822 ]) # LN_CONDITIONALS
823
824 #
825 # LN_CONFIG_FILES
826 #
827 # files that should be generated with AC_OUTPUT
828 #
829 AC_DEFUN([LN_CONFIG_FILES], [
830 AC_CONFIG_FILES([
831 lnet/Makefile
832 lnet/autoMakefile
833 lnet/autoconf/Makefile
834 lnet/doc/Makefile
835 lnet/include/Makefile
836 lnet/include/lnet/Makefile
837 lnet/include/uapi/linux/lnet/Makefile
838 lnet/klnds/Makefile
839 lnet/klnds/autoMakefile
840 lnet/klnds/o2iblnd/Makefile
841 lnet/klnds/o2iblnd/autoMakefile
842 lnet/klnds/gnilnd/Makefile
843 lnet/klnds/gnilnd/autoMakefile
844 lnet/klnds/socklnd/Makefile
845 lnet/klnds/socklnd/autoMakefile
846 lnet/lnet/Makefile
847 lnet/lnet/autoMakefile
848 lnet/selftest/Makefile
849 lnet/selftest/autoMakefile
850 lnet/utils/Makefile
851 lnet/utils/lnetconfig/Makefile
852 ])
853 ]) # LN_CONFIG_FILES