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