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