virtio: Add RX queue full statisitics
[vpp.git] / src / plugins / dpdk / CMakeLists.txt
1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 ##############################################################################
15 # Check if we want to use the system DPDK
16 ##############################################################################
17 option(VPP_USE_SYSTEM_DPDK "Use the system installation of DPDK." OFF)
18 if(VPP_USE_SYSTEM_DPDK)
19     find_package(PkgConfig REQUIRED)
20     pkg_check_modules(DPDK REQUIRED libdpdk)
21     message(WARNING "-- linking dpdk plugin against system libdpdk, version ${DPDK_VERSION}")
22     set(DPDK_LINK_FLAGS ${DPDK_LDFLAGS})
23     include_directories (${DPDK_INCLUDE_DIRS})
24 else()
25     ##############################################################################
26     # Find lib and include files
27     ##############################################################################
28     vpp_find_path(DPDK_INCLUDE_DIR PATH_SUFFIXES dpdk NAMES rte_config.h)
29     vpp_plugin_find_library(dpdk DPDK_LIB "libdpdk.a")
30
31     if (NOT DPDK_INCLUDE_DIR)
32       message(WARNING "-- DPDK headers not found - dpdk plugin disabled")
33       return()
34     endif()
35
36     if (NOT DPDK_LIB)
37       vpp_plugin_find_library(dpdk DPDK_SHLIB "libdpdk.so")
38       set(DPDK_IS_SHARED_LIB 1)
39       message(WARNING "-- linking dpdk plugin against DPDK shared libs")
40     endif()
41
42     ##############################################################################
43     # Parse DPDK config and version header files
44     ##############################################################################
45     file(STRINGS ${DPDK_INCLUDE_DIR}/rte_config.h rte_config)
46     file(STRINGS ${DPDK_INCLUDE_DIR}/rte_version.h rte_version)
47     file(STRINGS ${DPDK_INCLUDE_DIR}/rte_build_config.h rte_build_config)
48
49     foreach(l ${rte_config} ${rte_build_config} ${rte_version}})
50       if (l MATCHES "^#define[\t ]*RTE_")
51         STRING(REGEX REPLACE "^#define[\t ]*([A-Z1-9_]+)[\t ]*(.+)" "\\1;\\2" v "${l}")
52         list(GET v 0 name)
53         list(GET v 1 value)
54         set(DPDK_${name} ${value})
55       endif()
56     endforeach()
57
58     set(DPDK_VERSION
59         "${DPDK_RTE_VER_YEAR}.${DPDK_RTE_VER_MONTH}.${DPDK_RTE_VER_MINOR}")
60
61     ##############################################################################
62     # verify headroom size
63     ##############################################################################
64     if(NOT ${DPDK_RTE_PKTMBUF_HEADROOM} EQUAL ${PRE_DATA_SIZE})
65       message(
66         FATAL_ERROR
67         "DPDK RTE_PKTMBUF_HEADROOM (${DPDK_RTE_PKTMBUF_HEADROOM}) "
68          "must be equal to PRE_DATA_SIZE (${PRE_DATA_SIZE})"
69       )
70     endif()
71
72     ##############################################################################
73     # static or dynamic linking
74     ##############################################################################
75     unset(DPDK_LINK_LIBRARIES)
76     unset(DPDK_LINK_FLAGS)
77     message(STATUS "Found DPDK ${DPDK_VERSION} in ${DPDK_INCLUDE_DIR}")
78     include_directories (${DPDK_INCLUDE_DIR})
79
80     if(DPDK_IS_SHARED_LIB)
81       get_filename_component(DPDK_LIB_DIR ${DPDK_SHLIB} DIRECTORY)
82       string_append(DPDK_LINK_FLAGS "-L${DPDK_LIB_DIR}")
83       list(APPEND DPDK_LINK_LIBRARIES ${DPDK_SHLIB})
84     else()
85       get_filename_component(DPDK_LIB_DIR ${DPDK_LIB} DIRECTORY)
86       string_append(DPDK_LINK_FLAGS "-L${DPDK_LIB_DIR}")
87       string_append(DPDK_LINK_FLAGS "-Wl,--whole-archive,${DPDK_LIB},--no-whole-archive")
88     endif()
89
90     ##############################################################################
91     # libnuma
92     ##############################################################################
93     if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
94       vpp_plugin_find_library(dpdk NUMA_LIB "numa")
95       list(APPEND DPDK_LINK_LIBRARIES ${NUMA_LIB})
96     endif()
97
98     ##############################################################################
99     # Mellanox libraries
100     ##############################################################################
101     if(DPDK_RTE_NET_MLX4 OR DPDK_RTE_NET_MLX5)
102       if (DPDK_RTE_IBVERBS_LINK_DLOPEN)
103         message(STATUS "DPDK depends on libmnl (Mellanox PMD requirement)")
104         vpp_plugin_find_library(dpdk MNL_LIB "mnl")
105         list(APPEND DPDK_LINK_LIBRARIES "${MNL_LIB}")
106       else()
107         message(WARNING "EXPERIMENTAL: DPDK plugin without dlopen mode")
108         vpp_plugin_find_library(dpdk IBVERBS_LIB "libibverbs.a")
109         vpp_plugin_find_library(dpdk MLX5_LIB "libmlx5.a")
110         vpp_plugin_find_library(dpdk MLX4_LIB "libmlx4.a")
111         string_append(DPDK_LINK_FLAGS "-Wl,--whole-archive,${IBVERBS_LIB},${MLX5_LIB},${MLX4_LIB} -Wl,--no-whole-archive,--exclude-libs,ALL")
112       endif()
113     endif()
114 endif()
115
116 ##############################################################################
117 # DPDK plugin
118 ##############################################################################
119
120 if(OPENSSL_FOUND)
121   include_directories(${OPENSSL_INCLUDE_DIR})
122
123   set(DPDK_CRYPTODEV_OP_SOURCE cryptodev/cryptodev_op_data_path.c)
124   set(DPDK_CRYPTODEV_SOURCE cryptodev/cryptodev.c)
125   if (${DPDK_VERSION} VERSION_GREATER_EQUAL "20.8.0")
126     set(DPDK_CRYPTODEV_RAW_SOURCE cryptodev/cryptodev_raw_data_path.c)
127   endif()
128 endif()
129
130 add_vpp_plugin(dpdk
131   SOURCES
132   buffer.c
133   main.c
134   device/cli.c
135   device/common.c
136   device/device.c
137   device/driver.c
138   device/flow.c
139   device/format.c
140   device/init.c
141   device/node.c
142   ${DPDK_CRYPTODEV_OP_SOURCE}
143   ${DPDK_CRYPTODEV_SOURCE}
144   ${DPDK_CRYPTODEV_RAW_SOURCE}
145
146   MULTIARCH_SOURCES
147   buffer.c
148   device/device.c
149   device/node.c
150
151   INSTALL_HEADERS
152   device/dpdk.h
153
154   LINK_FLAGS
155   "${DPDK_LINK_FLAGS}"
156
157   LINK_LIBRARIES
158   ${DPDK_LINK_LIBRARIES}
159
160   LINK_LIBRARIES
161   ${OPENSSL_CRYPTO_LIBRARIES}
162
163   COMPONENT
164   vpp-plugin-dpdk
165 )