bf27d8aa73168e2a7b5c87d9c4f7f4e0ae7845b8
[vpp.git] / build / external / packages / dpdk.mk
1 # Copyright (c) 2020 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 DPDK_PKTMBUF_HEADROOM        ?= 128
15 DPDK_USE_LIBBSD              ?= n
16 DPDK_DEBUG                   ?= n
17 DPDK_TAP_PMD                 ?= n
18 DPDK_FAILSAFE_PMD            ?= n
19 DPDK_MACHINE                 ?= default
20 DPDK_MLX_IBV_LINK            ?= static
21
22 dpdk_version                 ?= 22.07
23 dpdk_base_url                ?= http://fast.dpdk.org/rel
24 dpdk_tarball                 := dpdk-$(dpdk_version).tar.xz
25 dpdk_tarball_md5sum_22.07    := fb73b58b80b1349cd05fe9cf6984afd4
26 dpdk_tarball_md5sum_22.03    := a07ca8839f98062f46e1cc359735cce8
27 dpdk_tarball_md5sum_21.11    := 58660bbbe9e95abce86e47692b196555
28 dpdk_tarball_md5sum_21.08    := de33433a1806280996a0ecbe66e3642f
29 dpdk_tarball_md5sum_21.05    := a78bba290b11d9717d1272cc6bfaf7c3
30 dpdk_tarball_md5sum          := $(dpdk_tarball_md5sum_$(dpdk_version))
31 dpdk_url                     := $(dpdk_base_url)/$(dpdk_tarball)
32 dpdk_tarball_strip_dirs      := 1
33 dpdk_depends                 := rdma-core $(if $(ARCH_X86_64), ipsec-mb)
34
35 DPDK_MLX_DEFAULT             := $(shell if grep -q "rdma=$(rdma-core_version) dpdk=$(dpdk_version)" mlx_rdma_dpdk_matrix.txt; then echo 'y'; else echo 'n'; fi)
36 DPDK_MLX4_PMD                ?= $(DPDK_MLX_DEFAULT)
37 DPDK_MLX5_PMD                ?= $(DPDK_MLX_DEFAULT)
38 DPDK_MLX5_COMMON_PMD         ?= $(DPDK_MLX_DEFAULT)
39 # Debug or release
40
41 DPDK_BUILD_TYPE:=release
42 ifeq ($(DPDK_DEBUG), y)
43 DPDK_BUILD_TYPE:=debug
44 endif
45
46 DPDK_DRIVERS_DISABLED := baseband/\*,   \
47         bus/dpaa,                                                       \
48         bus/ifpga,                                                      \
49         common/cnxk,                                            \
50         compress/isal,                                          \
51         compress/octeontx,                                      \
52         compress/zlib,                                          \
53         crypto/ccp,                                                     \
54         crypto/cnxk,                                            \
55         crypto/dpaa_sec,                                        \
56         crypto/openssl,                                         \
57         crypto/aesni_mb,                                                \
58         crypto/aesni_gcm,                                               \
59         crypto/kasumi,                                          \
60         crypto/snow3g,                                          \
61         crypto/zuc,                                             \
62         event/\*,                                                       \
63         mempool/dpaa,                                           \
64         mempool/cnxk,                                           \
65         net/af_packet,                                          \
66         net/bnx2x,                                                      \
67         net/bonding,                                            \
68         net/cnxk,                                                       \
69         net/ipn3ke,                                                     \
70         net/liquidio,                                           \
71         net/pcap,                                                       \
72         net/pfe,                                                        \
73         net/sfc,                                                        \
74         net/softnic,                                            \
75         net/thunderx,                                           \
76         raw/ifpga,                                                      \
77         net/af_xdp
78
79 DPDK_LIBS_DISABLED := acl,                              \
80         bbdev,                                                          \
81         bitratestats,                                           \
82         bpf,                                                            \
83         cfgfile,                                                        \
84         cnxk,                                                   \
85         distributor,                                            \
86         efd,                                                            \
87         fib,                                                            \
88         flow_classify,                                          \
89         graph,                                                          \
90         gro,                                                            \
91         gso,                                                            \
92         jobstats,                                                       \
93         kni,                                                            \
94         latencystats,                                           \
95         lpm,                                                            \
96         member,                                                         \
97         node,                                                           \
98         pipeline,                                                       \
99         port,                                                           \
100         power,                                                          \
101         rawdev,                                                         \
102         rib,                                                            \
103         table
104
105 DPDK_MLX_CONFIG_FLAG :=
106
107 # Adjust disabled pmd and libs depending on user provided variables
108 ifeq ($(DPDK_MLX4_PMD), n)
109         DPDK_DRIVERS_DISABLED += ,net/mlx4
110 else
111         DPDK_MLX_CONFIG_FLAG := -Dibverbs_link=${DPDK_MLX_IBV_LINK}
112 endif
113 ifeq ($(DPDK_MLX5_PMD), n)
114         DPDK_DRIVERS_DISABLED += ,net/mlx5
115 else
116         DPDK_MLX_CONFIG_FLAG := -Dibverbs_link=${DPDK_MLX_IBV_LINK}
117 endif
118 ifeq ($(DPDK_MLX5_COMMON_PMD), n)
119         DPDK_DRIVERS_DISABLED += ,common/mlx5
120 else
121         DPDK_MLX_CONFIG_FLAG := -Dibverbs_link=${DPDK_MLX_IBV_LINK}
122 endif
123 ifeq ($(DPDK_TAP_PMD), n)
124         DPDK_DRIVERS_DISABLED += ,net/tap
125 endif
126 ifeq ($(DPDK_FAILSAFE_PMD), n)
127         DPDK_DRIVERS_DISABLED += ,net/failsafe
128 endif
129
130 # Sanitize DPDK_DRIVERS_DISABLED and DPDK_LIBS_DISABLED
131 DPDK_DRIVERS_DISABLED := $(shell echo $(DPDK_DRIVERS_DISABLED) | tr -d '\\\t ')
132 DPDK_LIBS_DISABLED := $(shell echo $(DPDK_LIBS_DISABLED) | tr -d '\\\t ')
133
134 HASH := \#
135 # post-meson-setup snippet to alter rte_build_config.h
136 define dpdk_config
137 if grep -q RTE_$(1) $(dpdk_src_dir)/config/rte_config.h ; then  \
138 sed -i -e 's/$(HASH)define RTE_$(1).*/$(HASH)define RTE_$(1) $(DPDK_$(1))/' \
139         $(dpdk_src_dir)/config/rte_config.h; \
140 elif grep -q RTE_$(1) $(dpdk_build_dir)/rte_build_config.h ; then \
141 sed -i -e 's/$(HASH)define RTE_$(1).*/$(HASH)define RTE_$(1) $(DPDK_$(1))/' \
142         $(dpdk_build_dir)/rte_build_config.h; \
143 else \
144 echo '$(HASH)define RTE_$(1) $(DPDK_$(1))' \
145         >> $(dpdk_build_dir)/rte_build_config.h ; \
146 fi
147 endef
148
149 define dpdk_config_def
150 if [[ "$(DPDK_$(1))" == "y" ]]; then \
151     if ! grep -q "RTE_$(1)" $(dpdk_build_dir)/rte_build_config.h \
152       $(dpdk_src_dir)/config/rte_config.h ; then \
153         echo '$(HASH)define RTE_$(1) 1' \
154           >> $(dpdk_build_dir)/rte_build_config.h ; \
155     fi; \
156 elif [[ "$(DPDK_$(1))" == "n" ]]; then \
157     sed -i '/$(HASH)define RTE_$(1) .*/d' $(dpdk_build_dir)/rte_build_config.h \
158       $(dpdk_src_dir)/config/rte_config.h ; \
159 fi
160 endef
161
162 DPDK_MESON_ARGS = \
163         --default-library static \
164         --libdir lib \
165         --prefix $(dpdk_install_dir) \
166         -Dtests=false \
167         "-Ddisable_drivers=$(DPDK_DRIVERS_DISABLED)" \
168         "-Ddisable_libs=$(DPDK_LIBS_DISABLED)" \
169         -Db_pie=true \
170         -Dmachine=$(DPDK_MACHINE) \
171         --buildtype=$(DPDK_BUILD_TYPE) \
172         ${DPDK_MLX_CONFIG_FLAG}
173
174 PIP_DOWNLOAD_DIR = $(CURDIR)/downloads/
175
176 define dpdk_config_cmds
177         cd $(dpdk_build_dir) && \
178         echo "DPDK_MLX_DEFAULT=$(DPDK_MLX_DEFAULT)" > dpdk_mlx_default.sh && \
179         rm -rf ../dpdk-meson-venv && \
180         mkdir -p ../dpdk-meson-venv && \
181         python3 -m venv ../dpdk-meson-venv && \
182         source ../dpdk-meson-venv/bin/activate && \
183         (if ! ls $(PIP_DOWNLOAD_DIR)meson* ; then pip3 download -d $(PIP_DOWNLOAD_DIR) -f $(DL_CACHE_DIR) meson==0.55 setuptools wheel pyelftools; fi) && \
184         pip3 install --no-index --find-links=$(PIP_DOWNLOAD_DIR) meson==0.55 pyelftools && \
185         PKG_CONFIG_PATH=$(dpdk_install_dir)/lib/pkgconfig meson setup $(dpdk_src_dir) \
186                 $(dpdk_build_dir) \
187                 $(DPDK_MESON_ARGS) \
188                         | tee $(dpdk_config_log) && \
189         deactivate && \
190         echo "DPDK post meson configuration" && \
191         echo "Altering rte_build_config.h" && \
192         $(call dpdk_config,PKTMBUF_HEADROOM) && \
193         $(call dpdk_config_def,USE_LIBBSD)
194 endef
195
196 ifeq ("$(DPDK_VERBOSE)","1")
197 DPDK_VERBOSE_BUILD = --verbose
198 endif
199
200 define dpdk_build_cmds
201         cd $(dpdk_build_dir) && \
202         source ../dpdk-meson-venv/bin/activate && \
203         meson compile $(DPDK_VERBOSE_BUILD) -C . | tee $(dpdk_build_log) && \
204         deactivate
205 endef
206
207 define dpdk_install_cmds
208         cd $(dpdk_build_dir) && \
209         source ../dpdk-meson-venv/bin/activate && \
210         meson install && \
211         cd $(dpdk_install_dir)/lib && \
212         echo "GROUP ( $$(ls librte*.a ) )" > libdpdk.a && \
213         rm -rf librte*.so librte*.so.* dpdk/*/librte*.so dpdk/*/librte*.so.* && \
214         deactivate
215 endef
216
217 $(eval $(call package,dpdk))