1 # Copyright (c) 2015 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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
14 # Scripts require non-POSIX parts of bash
17 DPDK_BUILD_DIR ?= $(CURDIR)/_build
18 DPDK_INSTALL_DIR ?= $(CURDIR)/_install
19 DPDK_PKTMBUF_HEADROOM ?= 128
20 DPDK_CACHE_LINE_SIZE ?= 64
21 DPDK_DOWNLOAD_DIR ?= $(HOME)/Downloads
26 B := $(DPDK_BUILD_DIR)
27 I := $(DPDK_INSTALL_DIR)
30 DPDK_BASE_URL ?= http://fast.dpdk.org/rel
31 DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.xz
32 DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
33 DPDK_17.11_TARBALL_MD5_CKSUM := 53ee9e054a8797c9e67ffa0eb5d0c701
34 DPDK_18.02_TARBALL_MD5_CKSUM := ca13077a014a2102c6e10153dfa3b920
35 DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
36 MACHINE=$(shell uname -m)
38 NASM_BASE_URL := http://www.nasm.us/pub/nasm/releasebuilds
40 NASM_TARBALL := nasm-$(NASM_VER).tar.xz
41 NASM_TAR_URL := $(NASM_BASE_URL)/$(NASM_VER)/$(NASM_TARBALL)
42 NASM_SOURCE := $(B)/nasm-$(NASM_VER)
44 ifeq ($(DPDK_VERSION),17.11)
50 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64))
52 $(info Building IPSec-MB $(IPSEC_MB_VER) library)
57 AESNIMB_LIB_TARBALL := v$(IPSEC_MB_VER).tar.gz
58 AESNIMB_LIB_TARBALL_URL := http://github.com/01org/intel-ipsec-mb/archive/$(AESNIMB_LIB_TARBALL)
59 AESNIMB_LIB_SOURCE := $(B)/intel-ipsec-mb-$(IPSEC_MB_VER)
61 ifneq (,$(findstring clang,$(CC)))
63 else ifneq (,$(findstring icc,$(CC)))
69 ##############################################################################
71 ##############################################################################
72 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64 i686))
73 DPDK_TARGET ?= $(MACHINE)-native-linuxapp-$(DPDK_CC)
75 DPDK_TUNE ?= core-avx2
77 ##############################################################################
79 ##############################################################################
80 else ifeq ($(MACHINE),aarch64)
82 DPDK_TARGET ?= arm64-armv8a-linuxapp-$(DPDK_CC)
83 DPDK_MACHINE ?= armv8a
89 CPU_PART_ARM_CORTEX_A53 = 0xd03
90 CPU_PART_ARM_CORTEX_A57 = 0xd07
91 CPU_PART_ARM_CORTEX_A72 = 0xd08
92 CPU_PART_ARM_CORTEX_A73 = 0xd09
94 CPU_PART_CAVIUM_THUNDERX = 0x0a1
95 CPU_PART_CAVIUM_THUNDERX_81XX = 0x0a2
96 CPU_PART_CAVIUM_THUNDERX_83XX = 0x0a3
98 MIDR_IMPLEMENTER=$(shell awk '/implementer/ {print $$4;exit}' /proc/cpuinfo)
99 MIDR_PARTNUM=$(shell awk '/part/ {print $$4;exit}' /proc/cpuinfo)
101 ifeq ($(MIDR_IMPLEMENTER),$(CPU_IMP_ARM))
102 ##############################################################################
104 ##############################################################################
105 CPU_PART_ARM_TUNE := $(CPU_PART_ARM_CORTEX_A53)/cortex-a53 \
106 $(CPU_PART_ARM_CORTEX_A57)/cortex-a57 \
107 $(CPU_PART_ARM_CORTEX_A72)/cortex-a72 \
108 $(CPU_PART_ARM_CORTEX_A73)/cortex-a73
109 CPU_TUNE = $(notdir $(filter $(MIDR_PARTNUM)/%,$(CPU_PART_ARM_TUNE)))
111 DPDK_TUNE = $(CPU_TUNE)
113 $(warning Unknown Arm CPU)
116 else ifeq ($(MIDR_IMPLEMENTER),$(CPU_IMP_CAVIUM))
117 ##############################################################################
119 ##############################################################################
120 ifneq (,$(findstring $(MIDR_PARTNUM),$(CPU_PART_CAVIUM_THUNDERX) \
121 $(CPU_PART_CAVIUM_THUNDERX_81XX) $(CPU_PART_CAVIUM_THUNDERX_83XX)))
122 DPDK_TARGET = arm64-thunderx-linuxapp-$(DPDK_CC)
123 DPDK_MACHINE = thunderx
125 $(warning Unknown Cavium CPU)
129 ##############################################################################
131 ##############################################################################
133 $(error Unknown platform)
136 # /proc/cpuinfo does not exist on platforms without a /proc and on some
137 # platforms, notably inside containers, it has no content. In those cases
138 # we assume there's 1 processor; we use 2*ncpu for the -j option.
139 # NB: GNU Make 4.2 will let us use '$(file </proc/cpuinfo)' to both test
140 # for file presence and content; for now this will have to do.
141 JOBS := $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo),\
142 $(shell grep -c ^processor /proc/cpuinfo), 2)
144 # compiler/linker custom arguments
145 DPDK_CPU_CFLAGS := -pie -fPIC
147 ifeq ($(DPDK_DEBUG),n)
148 DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
150 DPDK_EXTRA_CFLAGS := -g -O0
153 DPDK_MAKE_EXTRA_ARGS += AESNI_MULTI_BUFFER_LIB_PATH=$(AESNIMB_LIB_SOURCE)
155 # assemble DPDK make arguments
156 DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
158 RTE_CONFIG_TEMPLATE=../custom-config \
159 EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
160 EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
161 CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
163 $(DPDK_MAKE_EXTRA_ARGS)
166 @if grep -q CONFIG_$1 $@ ; \
167 then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
168 else echo CONFIG_$1=$2 >> $@ ; \
174 $(B)/custom-config: $(B)/.patch.ok Makefile
175 @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
176 @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
177 $(call set,RTE_MACHINE,$(DPDK_MACHINE))
179 $(call set,RTE_MAX_LCORE,256)
180 $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
181 $(call set,RTE_CACHE_LINE_SIZE,$(DPDK_CACHE_LINE_SIZE))
182 $(call set,RTE_LIBEAL_USE_HPET,y)
183 $(call set,RTE_BUILD_COMBINE_LIBS,y)
184 $(call set,RTE_PCI_CONFIG,y)
185 $(call set,RTE_PCI_EXTENDED_TAG,"on")
186 $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
187 @# enable debug init for device drivers
188 $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
189 $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
190 $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
191 $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
192 $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
193 $(call set,RTE_LIBRTE_PMD_BOND,y)
194 $(call set,RTE_LIBRTE_IP_FRAG,y)
195 $(call set,RTE_LIBRTE_PMD_QAT,y)
196 $(call set,RTE_LIBRTE_PMD_AESNI_MB,$(AESNI))
197 $(call set,RTE_LIBRTE_PMD_AESNI_GCM,$(AESNI))
198 $(call set,RTE_LIBRTE_MLX4_PMD,$(DPDK_MLX4_PMD))
199 $(call set,RTE_LIBRTE_MLX5_PMD,$(DPDK_MLX5_PMD))
200 $(call set,RTE_LIBRTE_MLX4_DLOPEN_DEPS,$(DPDK_MLX4_PMD))
201 $(call set,RTE_LIBRTE_MLX5_DLOPEN_DEPS,$(DPDK_MLX5_PMD))
203 $(call set,RTE_LIBRTE_PMD_TAP,n)
204 $(call set,RTE_LIBRTE_TIMER,n)
205 $(call set,RTE_LIBRTE_CFGFILE,n)
206 $(call set,RTE_LIBRTE_LPM,n)
207 $(call set,RTE_LIBRTE_ACL,n)
208 $(call set,RTE_LIBRTE_POWER,n)
209 $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
210 $(call set,RTE_LIBRTE_PORT,n)
211 $(call set,RTE_LIBRTE_TABLE,n)
212 $(call set,RTE_LIBRTE_PIPELINE,n)
213 $(call set,RTE_LIBRTE_FLOW_CLASSIFY,n)
214 $(call set,RTE_KNI_KMOD,n)
215 $(call set,RTE_EAL_IGB_UIO,n)
216 @# currently broken in 18.02
217 $(call set,RTE_LIBRTE_DPAA_BUS,n)
218 $(call set,RTE_LIBRTE_DPAA_MEMPOOL,n)
219 $(call set,RTE_LIBRTE_DPAA_PMD,n)
220 $(call set,RTE_LIBRTE_PMD_DPAA_SEC,n)
221 $(call set,RTE_LIBRTE_PMD_DPAA_EVENTDEV,n)
224 $(CURDIR)/$(DPDK_TARBALL):
225 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
226 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
227 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
229 @rm -f $(B)/.download.ok
231 $(CURDIR)/$(NASM_TARBALL):
232 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(NASM_TARBALL) ] ; \
233 then cp $(DPDK_DOWNLOAD_DIR)/$(NASM_TARBALL) $(CURDIR) ; \
234 else curl -o $(CURDIR)/$(NASM_TARBALL) -LO $(NASM_TAR_URL) ; \
237 $(CURDIR)/$(AESNIMB_LIB_TARBALL):
238 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) ] ; \
239 then cp $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) $(CURDIR) ; \
240 else curl -o $@ -LO $(AESNIMB_LIB_TARBALL_URL) ; \
243 DPDK_DOWNLOADS = $(CURDIR)/$(DPDK_TARBALL)
245 DPDK_DOWNLOADS += $(CURDIR)/$(NASM_TARBALL)
246 DPDK_DOWNLOADS += $(CURDIR)/$(AESNIMB_LIB_TARBALL)
249 $(B)/.download.ok: $(DPDK_DOWNLOADS)
251 @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
252 @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
253 ( echo "Bad Checksum! Please remove $< and retry" && \
254 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
258 download: $(B)/.download.ok
260 $(B)/.extract.ok: $(B)/.download.ok
261 @echo --- extracting $(DPDK_TARBALL) ---
262 @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
264 @echo --- extracting $(NASM_TARBALL) ---
265 @tar --directory $(B) --extract --file $(CURDIR)/$(NASM_TARBALL)
266 @echo --- extracting $(AESNIMB_LIB_TARBALL) ---
267 @tar --directory $(B) --extract --file $(CURDIR)/$(AESNIMB_LIB_TARBALL)
272 extract: $(B)/.extract.ok
274 $(B)/.patch.ok: $(B)/.extract.ok
275 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
276 @echo --- patching ---
277 @for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
278 echo Applying patch: $$(basename $$f) ; \
279 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
285 patch: $(B)/.patch.ok
287 $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
288 @make $(DPDK_MAKE_ARGS) config
292 config: $(B)/.config.ok
296 cd $(NASM_SOURCE) && sh configure && make -j
298 .PHONY: build-ipsec-mb
301 # Do not build GCM stuff if we are building ISA_L
302 make -C $(AESNIMB_LIB_SOURCE) -j \
303 EXTRA_CFLAGS=-fPIC NASM=$(NASM_SOURCE)/nasm
304 cp $(AESNIMB_LIB_SOURCE)/libIPSec_MB.a $(I)/lib/
308 @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
309 @make $(DPDK_MAKE_ARGS) install
313 BUILD_TARGETS += build-nasm
314 BUILD_TARGETS += build-ipsec-mb
316 BUILD_TARGETS += build-dpdk
318 $(B)/.build.ok: $(BUILD_TARGETS)
322 build: $(B)/.build.ok
325 install: $(B)/.build.ok
331 ##############################################################################
333 ##############################################################################
335 DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
336 DEV_DEB=vpp-dpdk-dev_$(DPDK_VERSION)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
337 INSTALLED_DEB_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-dpdk-dev 2> /dev/null)
339 .PHONY: build-deb install-deb check-deb
341 deb/debian/changelog: Makefile
342 @echo "vpp-dpdk ($(DPDK_VERSION)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
344 @echo " * DPDK Release $(DPDK_VERSION)" >> $@
346 @echo " -- VPP Dev <vpp-dev@lists.fd.io> $(shell date -R)" >> $@
348 $(DEV_DEB): deb/debian/changelog
349 @cd deb && dpkg-buildpackage -b -uc -us
352 build-deb: $(DEV_DEB)
355 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
356 @echo "=========================================================="
357 @echo " Out of date DPDK package installed."
358 @echo " Installed: $(INSTALLED_DEB_VER)"
359 @echo " Needed: $(DPDK_VERSION)-$(PKG_SUFFIX)"
360 @echo "=========================================================="
362 @sudo dpkg -i $(DEV_DEB)
364 @echo "=========================================================="
365 @echo " Up-to-date DPDK package already installed"
366 @echo "=========================================================="
370 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
371 @echo "=========================================================="
372 @echo " Outdated DPDK package detected:"
373 @echo " Installed: vpp-dpdk-dev $(INSTALLED_DEB_VER)"
374 @echo " Current: vpp-dpdk-dev $(DPDK_VERSION)-$(PKG_SUFFIX)"
376 @echo " Please upgrade by invoking 'make dpdk-install-dev'"
377 @echo " from the top level directory."
378 @echo "=========================================================="
381 ##############################################################################
383 ##############################################################################
385 RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
386 DEV_RPM=vpp-dpdk-devel-$(DPDK_VERSION)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
387 INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-dpdk-devel 2> /dev/null | grep -v "not inst")
389 .PHONY: build-rpm install-rpm check-rpm
391 $(DEV_RPM): Makefile rpm/vpp-dpdk.spec
393 --define "_topdir $(CURDIR)/rpm" \
394 --define "_version $(DPDK_VERSION)" \
395 --define "_release $(PKG_SUFFIX)" \
396 $(CURDIR)/rpm/vpp-dpdk.spec
397 mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
400 build-rpm: $(DEV_RPM)
403 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
405 sudo rpm -Uih $(DEV_RPM)
407 @echo "=========================================================="
408 @echo " Up-to-date DPDK package already installed"
409 @echo "=========================================================="
413 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
414 @echo "=========================================================="
415 @echo " Outdated DPDK package detected:"
416 @echo " Installed: vpp-dpdk-devel $(INSTALLED_RPM_VER)"
417 @echo " Current: vpp-dpdk-devel $(DPDK_VERSION)-$(PKG_SUFFIX)"
419 @echo " Please upgrade by invoking 'make dpdk-install-dev'"
420 @echo " from the top level directory."
421 @echo "=========================================================="
424 ##############################################################################
426 ##############################################################################
428 .PHONY: ebuild-build ebuild-install
431 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
432 @echo "=========================================================="
433 @echo "Building DPDK from source. Consider installing development"
434 @echo "package by invoking 'make dpdk-install-dev' from the"
435 @echo "top level directory"
436 @echo "=========================================================="
439 ifneq ($(INSTALLED_DEB_VER),)
442 ifneq ($(INSTALLED_RPM_VER),)
448 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)