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 DPDK_FAILSAFE_PMD ?= n
28 B := $(DPDK_BUILD_DIR)
29 I := $(DPDK_INSTALL_DIR)
30 DPDK_VERSION ?= 18.02.1
32 DPDK_BASE_URL ?= http://fast.dpdk.org/rel
33 DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.xz
34 DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
35 DPDK_17.11_TARBALL_MD5_CKSUM := 53ee9e054a8797c9e67ffa0eb5d0c701
36 DPDK_18.02.1_TARBALL_MD5_CKSUM := 3bbb5468f662e1f7472d4abc5c4cf08e
37 DPDK_SOURCE := $(B)/dpdk-stable-$(DPDK_VERSION)
38 MACHINE=$(shell uname -m)
40 NASM_BASE_URL := http://www.nasm.us/pub/nasm/releasebuilds
42 NASM_TARBALL := nasm-$(NASM_VER).tar.xz
43 NASM_TAR_URL := $(NASM_BASE_URL)/$(NASM_VER)/$(NASM_TARBALL)
44 NASM_SOURCE := $(B)/nasm-$(NASM_VER)
46 ifeq ($(DPDK_VERSION),17.11)
52 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64))
54 $(info Building IPSec-MB $(IPSEC_MB_VER) library)
59 AESNIMB_LIB_TARBALL := v$(IPSEC_MB_VER).tar.gz
60 AESNIMB_LIB_TARBALL_URL := http://github.com/01org/intel-ipsec-mb/archive/$(AESNIMB_LIB_TARBALL)
61 AESNIMB_LIB_SOURCE := $(B)/intel-ipsec-mb-$(IPSEC_MB_VER)
63 ifneq (,$(findstring clang,$(CC)))
65 else ifneq (,$(findstring icc,$(CC)))
71 ##############################################################################
73 ##############################################################################
74 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64 i686))
75 DPDK_TARGET ?= $(MACHINE)-native-linuxapp-$(DPDK_CC)
77 DPDK_TUNE ?= core-avx2
79 ##############################################################################
81 ##############################################################################
82 else ifeq ($(MACHINE),aarch64)
85 DPDK_TARGET ?= arm64-armv8a-linuxapp-$(DPDK_CC)
86 DPDK_MACHINE ?= armv8a
92 CPU_PART_ARM_CORTEX_A53 = 0xd03
93 CPU_PART_ARM_CORTEX_A57 = 0xd07
94 CPU_PART_ARM_CORTEX_A72 = 0xd08
95 CPU_PART_ARM_CORTEX_A73 = 0xd09
97 CPU_PART_CAVIUM_THUNDERX = 0x0a1
98 CPU_PART_CAVIUM_THUNDERX_81XX = 0x0a2
99 CPU_PART_CAVIUM_THUNDERX_83XX = 0x0a3
101 MIDR_IMPLEMENTER=$(shell awk '/implementer/ {print $$4;exit}' /proc/cpuinfo)
102 MIDR_PARTNUM=$(shell awk '/part/ {print $$4;exit}' /proc/cpuinfo)
104 ifeq ($(MIDR_IMPLEMENTER),$(CPU_IMP_ARM))
105 ##############################################################################
107 ##############################################################################
108 CPU_PART_ARM_TUNE := $(CPU_PART_ARM_CORTEX_A53)/cortex-a53 \
109 $(CPU_PART_ARM_CORTEX_A57)/cortex-a57 \
110 $(CPU_PART_ARM_CORTEX_A72)/cortex-a72 \
111 $(CPU_PART_ARM_CORTEX_A73)/cortex-a73
112 CPU_TUNE = $(notdir $(filter $(MIDR_PARTNUM)/%,$(CPU_PART_ARM_TUNE)))
114 DPDK_TUNE = $(CPU_TUNE)
116 $(warning Unknown Arm CPU)
119 else ifeq ($(MIDR_IMPLEMENTER),$(CPU_IMP_CAVIUM))
120 ##############################################################################
122 ##############################################################################
123 ifneq (,$(findstring $(MIDR_PARTNUM),$(CPU_PART_CAVIUM_THUNDERX) \
124 $(CPU_PART_CAVIUM_THUNDERX_81XX) $(CPU_PART_CAVIUM_THUNDERX_83XX)))
125 DPDK_TARGET = arm64-thunderx-linuxapp-$(DPDK_CC)
126 DPDK_MACHINE = thunderx
127 DPDK_CACHE_LINE_SIZE := 128
129 $(warning Unknown Cavium CPU)
133 ##############################################################################
135 ##############################################################################
137 $(error Unknown platform)
140 # /proc/cpuinfo does not exist on platforms without a /proc and on some
141 # platforms, notably inside containers, it has no content. In those cases
142 # we assume there's 1 processor; we use 2*ncpu for the -j option.
143 # NB: GNU Make 4.2 will let us use '$(file </proc/cpuinfo)' to both test
144 # for file presence and content; for now this will have to do.
145 JOBS := $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo),\
146 $(shell grep -c ^processor /proc/cpuinfo), 2)
148 # compiler/linker custom arguments
149 ifeq ($(DPDK_CC),clang)
150 DPDK_CPU_CFLAGS := -fPIE -fPIC
152 DPDK_CPU_CFLAGS := -pie -fPIC
155 ifeq ($(DPDK_DEBUG),n)
156 DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
158 DPDK_EXTRA_CFLAGS := -g -O0
161 DPDK_MAKE_EXTRA_ARGS += AESNI_MULTI_BUFFER_LIB_PATH=$(AESNIMB_LIB_SOURCE)
163 # assemble DPDK make arguments
164 DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
166 RTE_CONFIG_TEMPLATE=../custom-config \
167 EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
168 EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
169 CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
171 $(DPDK_MAKE_EXTRA_ARGS)
174 @if grep -q CONFIG_$1 $@ ; \
175 then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
176 else echo CONFIG_$1=$2 >> $@ ; \
182 $(B)/custom-config: $(B)/.patch.ok Makefile
183 @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
184 @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
185 $(call set,RTE_MACHINE,$(DPDK_MACHINE))
187 $(call set,RTE_MAX_LCORE,256)
188 $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
189 $(call set,RTE_CACHE_LINE_SIZE,$(DPDK_CACHE_LINE_SIZE))
190 $(call set,RTE_LIBEAL_USE_HPET,y)
191 $(call set,RTE_BUILD_COMBINE_LIBS,y)
192 $(call set,RTE_PCI_CONFIG,y)
193 $(call set,RTE_PCI_EXTENDED_TAG,"on")
194 $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
195 @# enable debug init for device drivers
196 $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
197 $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
198 $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
199 $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
200 $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
201 $(call set,RTE_LIBRTE_PMD_BOND,y)
202 $(call set,RTE_LIBRTE_IP_FRAG,y)
203 $(call set,RTE_LIBRTE_PMD_QAT,y)
204 $(call set,RTE_LIBRTE_PMD_AESNI_MB,$(AESNI))
205 $(call set,RTE_LIBRTE_PMD_AESNI_GCM,$(AESNI))
206 $(call set,RTE_LIBRTE_MLX4_PMD,$(DPDK_MLX4_PMD))
207 $(call set,RTE_LIBRTE_MLX5_PMD,$(DPDK_MLX5_PMD))
208 $(call set,RTE_LIBRTE_MLX4_DLOPEN_DEPS,$(DPDK_MLX4_PMD))
209 $(call set,RTE_LIBRTE_MLX5_DLOPEN_DEPS,$(DPDK_MLX5_PMD))
210 $(call set,RTE_LIBRTE_PMD_TAP,$(DPDK_TAP_PMD))
211 $(call set,RTE_LIBRTE_PMD_FAILSAFE,$(DPDK_FAILSAFE_PMD))
213 $(call set,RTE_LIBRTE_TIMER,n)
214 $(call set,RTE_LIBRTE_CFGFILE,n)
215 $(call set,RTE_LIBRTE_LPM,n)
216 $(call set,RTE_LIBRTE_ACL,n)
217 $(call set,RTE_LIBRTE_POWER,n)
218 $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
219 $(call set,RTE_LIBRTE_PORT,n)
220 $(call set,RTE_LIBRTE_TABLE,n)
221 $(call set,RTE_LIBRTE_PIPELINE,n)
222 $(call set,RTE_LIBRTE_FLOW_CLASSIFY,n)
223 $(call set,RTE_KNI_KMOD,n)
224 $(call set,RTE_EAL_IGB_UIO,n)
225 @# currently broken in 18.02
226 $(call set,RTE_LIBRTE_DPAA_BUS,n)
227 $(call set,RTE_LIBRTE_DPAA_MEMPOOL,n)
228 $(call set,RTE_LIBRTE_DPAA_PMD,n)
229 $(call set,RTE_LIBRTE_PMD_DPAA_SEC,n)
230 $(call set,RTE_LIBRTE_PMD_DPAA_EVENTDEV,n)
233 $(CURDIR)/$(DPDK_TARBALL):
234 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
235 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
236 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
238 @rm -f $(B)/.download.ok
240 $(CURDIR)/$(NASM_TARBALL):
241 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(NASM_TARBALL) ] ; \
242 then cp $(DPDK_DOWNLOAD_DIR)/$(NASM_TARBALL) $(CURDIR) ; \
243 else curl -o $(CURDIR)/$(NASM_TARBALL) -LO $(NASM_TAR_URL) ; \
246 $(CURDIR)/$(AESNIMB_LIB_TARBALL):
247 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) ] ; \
248 then cp $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) $(CURDIR) ; \
249 else curl -o $@ -LO $(AESNIMB_LIB_TARBALL_URL) ; \
252 DPDK_DOWNLOADS = $(CURDIR)/$(DPDK_TARBALL)
254 DPDK_DOWNLOADS += $(CURDIR)/$(NASM_TARBALL)
255 DPDK_DOWNLOADS += $(CURDIR)/$(AESNIMB_LIB_TARBALL)
258 $(B)/.download.ok: $(DPDK_DOWNLOADS)
260 @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
261 @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
262 ( echo "Bad Checksum! Please remove $< and retry" && \
263 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
267 download: $(B)/.download.ok
269 $(B)/.extract.ok: $(B)/.download.ok
270 @echo --- extracting $(DPDK_TARBALL) ---
271 @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
273 @echo --- extracting $(NASM_TARBALL) ---
274 @tar --directory $(B) --extract --file $(CURDIR)/$(NASM_TARBALL)
275 @echo --- extracting $(AESNIMB_LIB_TARBALL) ---
276 @tar --directory $(B) --extract --file $(CURDIR)/$(AESNIMB_LIB_TARBALL)
281 extract: $(B)/.extract.ok
283 $(B)/.patch.ok: $(B)/.extract.ok
284 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
285 @echo --- patching ---
286 @for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
287 echo Applying patch: $$(basename $$f) ; \
288 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
294 patch: $(B)/.patch.ok
296 $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
297 @make $(DPDK_MAKE_ARGS) config
301 config: $(B)/.config.ok
305 cd $(NASM_SOURCE) && sh configure && make -j
307 .PHONY: build-ipsec-mb
310 # Do not build GCM stuff if we are building ISA_L
311 make -C $(AESNIMB_LIB_SOURCE) -j \
312 EXTRA_CFLAGS=-fPIC NASM=$(NASM_SOURCE)/nasm
313 cp $(AESNIMB_LIB_SOURCE)/libIPSec_MB.a $(I)/lib/
317 @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
318 @make $(DPDK_MAKE_ARGS) install
322 BUILD_TARGETS += build-nasm
323 BUILD_TARGETS += build-ipsec-mb
325 BUILD_TARGETS += build-dpdk
327 $(B)/.build.ok: $(BUILD_TARGETS)
331 build: $(B)/.build.ok
334 install: $(B)/.build.ok
340 ##############################################################################
342 ##############################################################################
344 DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
345 DEV_DEB=vpp-dpdk-dev_$(DPDK_VERSION)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
346 INSTALLED_DEB_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-dpdk-dev 2> /dev/null)
348 .PHONY: build-deb install-deb check-deb
350 deb/debian/changelog: Makefile
351 @echo "vpp-dpdk ($(DPDK_VERSION)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
353 @echo " * DPDK Release $(DPDK_VERSION)" >> $@
355 @echo " -- VPP Dev <vpp-dev@lists.fd.io> $(shell date -R)" >> $@
357 $(DEV_DEB): deb/debian/changelog
358 @cd deb && dpkg-buildpackage -b -uc -us
361 build-deb: $(DEV_DEB)
364 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
365 @echo "=========================================================="
366 @echo " Out of date DPDK package installed."
367 @echo " Installed: $(INSTALLED_DEB_VER)"
368 @echo " Needed: $(DPDK_VERSION)-$(PKG_SUFFIX)"
369 @echo "=========================================================="
371 @sudo dpkg -i $(DEV_DEB)
373 @echo "=========================================================="
374 @echo " Up-to-date DPDK package already installed"
375 @echo "=========================================================="
379 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
380 @echo "=========================================================="
381 @echo " Outdated DPDK package detected:"
382 @echo " Installed: vpp-dpdk-dev $(INSTALLED_DEB_VER)"
383 @echo " Current: vpp-dpdk-dev $(DPDK_VERSION)-$(PKG_SUFFIX)"
385 @echo " Please upgrade by invoking 'make dpdk-install-dev'"
386 @echo " from the top level directory."
387 @echo "=========================================================="
390 ##############################################################################
392 ##############################################################################
394 RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
395 DEV_RPM=vpp-dpdk-devel-$(DPDK_VERSION)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
396 INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-dpdk-devel 2> /dev/null | grep -v "not inst")
398 .PHONY: build-rpm install-rpm check-rpm
400 $(DEV_RPM): Makefile rpm/vpp-dpdk.spec
402 --define "_topdir $(CURDIR)/rpm" \
403 --define "_version $(DPDK_VERSION)" \
404 --define "_release $(PKG_SUFFIX)" \
405 $(CURDIR)/rpm/vpp-dpdk.spec
406 mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
409 build-rpm: $(DEV_RPM)
412 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
414 sudo rpm -Uih $(DEV_RPM)
416 @echo "=========================================================="
417 @echo " Up-to-date DPDK package already installed"
418 @echo "=========================================================="
422 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
423 @echo "=========================================================="
424 @echo " Outdated DPDK package detected:"
425 @echo " Installed: vpp-dpdk-devel $(INSTALLED_RPM_VER)"
426 @echo " Current: vpp-dpdk-devel $(DPDK_VERSION)-$(PKG_SUFFIX)"
428 @echo " Please upgrade by invoking 'make dpdk-install-dev'"
429 @echo " from the top level directory."
430 @echo "=========================================================="
433 ##############################################################################
435 ##############################################################################
437 .PHONY: ebuild-build ebuild-install
440 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
441 @echo "=========================================================="
442 @echo "Building DPDK from source. Consider installing development"
443 @echo "package by invoking 'make dpdk-install-dev' from the"
444 @echo "top level directory"
445 @echo "=========================================================="
448 ifneq ($(INSTALLED_DEB_VER),)
451 ifneq ($(INSTALLED_RPM_VER),)
457 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)