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_DOWNLOAD_DIR ?= $(HOME)/Downloads
25 B := $(DPDK_BUILD_DIR)
26 I := $(DPDK_INSTALL_DIR)
29 DPDK_BASE_URL ?= http://fast.dpdk.org/rel
30 DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.xz
31 DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
32 DPDK_17.05_TARBALL_MD5_CKSUM := 0a68c31cd6a6cabeed0a4331073e4c05
33 DPDK_17.08_TARBALL_MD5_CKSUM := 0641f59ea8ea98afefa7cfa2699f6241
34 DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
35 MACHINE=$(shell uname -m)
41 ISA_L_CRYPTO_VER := 2.18.0
43 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64))
45 # DPDK pre 17.08 depends on ISA-L Crypto library for GCM PMD
46 ifneq ($(firstword $(sort $(DPDK_VERSION), 17.08)), 17.08)
49 $(info Building ISA-L Crypto $(ISA_L_CRYPTO_VER) library)
51 $(info Building IPSec-MB $(IPSEC_MB_VER) library)
54 AESNIMB_LIB_TARBALL := v$(IPSEC_MB_VER).tar.gz
55 AESNIMB_LIB_TARBALL_URL := http://github.com/01org/intel-ipsec-mb/archive/$(AESNIMB_LIB_TARBALL)
56 AESNIMB_LIB_SOURCE := $(B)/intel-ipsec-mb-$(IPSEC_MB_VER)
58 ISA_L_CRYPTO_LIB_TARBALL := v$(ISA_L_CRYPTO_VER).tar.gz
59 ISA_L_CRYPTO_LIB_TARBALL_URL := http://github.com/01org/isa-l_crypto/archive/$(ISA_L_CRYPTO_LIB_TARBALL)
60 ISA_L_CRYPTO_LIB_SOURCE := $(B)/isa-l_crypto-$(ISA_L_CRYPTO_VER)
61 ISA_L_CRYPTO_INSTALL_DIR := $(ISA_L_CRYPTO_LIB_SOURCE)/install
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
78 ##############################################################################
80 ##############################################################################
81 else ifneq (,$(findstring thunder,$(shell cat /sys/bus/pci/devices/0000:00:01.0/uevent | grep cavium)))
83 DPDK_TARGET ?= arm64-thunderx-linuxapp-$(DPDK_CC)
84 DPDK_MACHINE ?= thunderx
87 ##############################################################################
89 ##############################################################################
91 $(error unknown platform)
94 # /proc/cpuinfo does not exist on platforms without a /proc and on some
95 # platforms, notably inside containers, it has no content. In those cases
96 # we assume there's 1 processor; we use 2*ncpu for the -j option.
97 # NB: GNU Make 4.2 will let us use '$(file </proc/cpuinfo)' to both test
98 # for file presence and content; for now this will have to do.
99 JOBS := $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo),\
100 $(shell expr 2 '*' $$(grep -c ^processor /proc/cpuinfo)), 2)
102 # compiler/linker custom arguments
103 DPDK_CPU_CFLAGS := -pie -fPIC
104 DPDK_EXTRA_LDFLAGS := -g
106 ifeq ($(DPDK_DEBUG),n)
107 DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
109 DPDK_EXTRA_CFLAGS := -g -O0
112 ifeq ($(ISA_L_CRYPTO_LIB),y)
113 DPDK_EXTRA_CFLAGS += -I$(ISA_L_CRYPTO_INSTALL_DIR)/include -Wl,-z,muldefs
114 DPDK_EXTRA_LDFLAGS += -L$(I)/lib
116 DPDK_MAKE_EXTRA_ARGS += AESNI_MULTI_BUFFER_LIB_PATH=$(AESNIMB_LIB_SOURCE)
118 # assemble DPDK make arguments
119 DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
121 RTE_CONFIG_TEMPLATE=../custom-config \
122 EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
123 EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
124 CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
126 $(DPDK_MAKE_EXTRA_ARGS)
129 @if grep -q CONFIG_$1 $@ ; \
130 then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
131 else echo CONFIG_$1=$2 >> $@ ; \
137 $(B)/custom-config: $(B)/.patch.ok Makefile
138 @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
139 @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
140 $(call set,RTE_MACHINE,$(DPDK_MACHINE))
142 $(call set,RTE_MAX_LCORE,256)
143 $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
144 $(call set,RTE_LIBEAL_USE_HPET,y)
145 $(call set,RTE_BUILD_COMBINE_LIBS,y)
146 $(call set,RTE_PCI_CONFIG,y)
147 $(call set,RTE_PCI_EXTENDED_TAG,"on")
148 $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
149 @# enable debug init for device drivers
150 $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
151 $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
152 $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
153 $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
154 $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
155 $(call set,RTE_LIBRTE_PMD_BOND,y)
156 $(call set,RTE_LIBRTE_IP_FRAG,y)
157 $(call set,RTE_LIBRTE_PMD_QAT,y)
158 $(call set,RTE_LIBRTE_PMD_AESNI_MB,$(AESNI))
159 $(call set,RTE_LIBRTE_PMD_AESNI_GCM,$(AESNI))
160 $(call set,RTE_LIBRTE_MLX4_PMD,$(DPDK_MLX4_PMD))
161 $(call set,RTE_LIBRTE_MLX5_PMD,$(DPDK_MLX5_PMD))
163 $(call set,RTE_LIBRTE_PMD_TAP,n)
164 $(call set,RTE_LIBRTE_TIMER,n)
165 $(call set,RTE_LIBRTE_CFGFILE,n)
166 $(call set,RTE_LIBRTE_LPM,n)
167 $(call set,RTE_LIBRTE_ACL,n)
168 $(call set,RTE_LIBRTE_POWER,n)
169 $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
170 $(call set,RTE_LIBRTE_PORT,n)
171 $(call set,RTE_LIBRTE_TABLE,n)
172 $(call set,RTE_LIBRTE_PIPELINE,n)
173 $(call set,RTE_KNI_KMOD,n)
174 $(call set,RTE_EAL_IGB_UIO,n)
177 $(CURDIR)/$(DPDK_TARBALL):
178 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
179 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
180 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
182 @rm -f $(B)/.download.ok
184 $(CURDIR)/$(AESNIMB_LIB_TARBALL):
185 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) ] ; \
186 then cp $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) $(CURDIR) ; \
187 else curl -o $@ -LO $(AESNIMB_LIB_TARBALL_URL) ; \
190 $(CURDIR)/$(ISA_L_CRYPTO_LIB_TARBALL):
191 @if [ -e $(DPDK_DOWNLOAD_DIR)/$(ISA_L_CRYPTO_LIB_TARBALL) ] ; \
192 then cp $(DPDK_DOWNLOAD_DIR)/$(ISA_L_CRYPTO_LIB_TARBALL) $(CURDIR) ; \
193 else curl -o $@ -LO $(ISA_L_CRYPTO_LIB_TARBALL_URL) ; \
196 DPDK_DOWNLOADS = $(CURDIR)/$(DPDK_TARBALL)
198 DPDK_DOWNLOADS += $(CURDIR)/$(AESNIMB_LIB_TARBALL)
200 ifeq ($(ISA_L_CRYPTO_LIB),y)
201 DPDK_DOWNLOADS += $(CURDIR)/$(ISA_L_CRYPTO_LIB_TARBALL)
204 $(B)/.download.ok: $(DPDK_DOWNLOADS)
206 @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
207 @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
208 ( echo "Bad Checksum! Please remove $< and retry" && \
209 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
213 download: $(B)/.download.ok
215 $(B)/.extract.ok: $(B)/.download.ok
216 @echo --- extracting $(DPDK_TARBALL) ---
217 @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
219 @echo --- extracting $(AESNIMB_LIB_TARBALL) ---
220 @tar --directory $(B) --extract --file $(CURDIR)/$(AESNIMB_LIB_TARBALL)
222 ifeq ($(ISA_L_CRYPTO_LIB),y)
223 @echo --- extracting $(ISA_L_CRYPTO_LIB_TARBALL) ---
224 @tar --directory $(B) --extract --file $(CURDIR)/$(ISA_L_CRYPTO_LIB_TARBALL)
229 extract: $(B)/.extract.ok
231 $(B)/.patch.ok: $(B)/.extract.ok
232 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
233 @echo --- patching ---
234 @for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
235 echo Applying patch: $$(basename $$f) ; \
236 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
242 patch: $(B)/.patch.ok
244 $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
245 @make $(DPDK_MAKE_ARGS) config
249 config: $(B)/.config.ok
251 .PHONY: build-ipsec-mb
254 # Do not build GCM stuff if we are building ISA_L
255 make -C $(AESNIMB_LIB_SOURCE) -j NO_GCM=$(ISA_L_CRYPTO_LIB)
256 cp $(AESNIMB_LIB_SOURCE)/libIPSec_MB.a $(I)/lib/
258 .PHONY: build-isal-crypto
261 cd $(ISA_L_CRYPTO_LIB_SOURCE) && ./autogen.sh && \
262 ./configure --prefix=$(ISA_L_CRYPTO_INSTALL_DIR) \
263 --libdir=$(ISA_L_CRYPTO_INSTALL_DIR)/lib CFLAGS='-fPIC -DPIC -O2'
264 make -C $(ISA_L_CRYPTO_LIB_SOURCE) -j install
265 cp $(ISA_L_CRYPTO_INSTALL_DIR)/lib/libisal_crypto.a $(I)/lib/
269 @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
270 @make $(DPDK_MAKE_ARGS) install
274 BUILD_TARGETS += build-ipsec-mb
276 ifeq ($(ISA_L_CRYPTO_LIB),y)
277 BUILD_TARGETS += build-isal-crypto
279 BUILD_TARGETS += build-dpdk
281 $(B)/.build.ok: $(BUILD_TARGETS)
285 build: $(B)/.build.ok
288 install: $(B)/.build.ok
294 ##############################################################################
296 ##############################################################################
298 DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
299 DEV_DEB=vpp-dpdk-dev_$(DPDK_VERSION)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
300 INSTALLED_DEB_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-dpdk-dev 2> /dev/null)
302 .PHONY: build-deb install-deb check-deb
304 deb/debian/changelog: Makefile
305 @echo "vpp-dpdk ($(DPDK_VERSION)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
307 @echo " * DPDK Release $(DPDK_VERSION)" >> $@
309 @echo " -- VPP Dev <vpp-dev@lists.fd.io> $(shell date -R)" >> $@
311 $(DEV_DEB): deb/debian/changelog
312 @cd deb && dpkg-buildpackage -b -uc -us
315 build-deb: $(DEV_DEB)
318 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
320 @sudo dpkg -i $(DEV_DEB)
322 @echo "=========================================================="
323 @echo " Up-to-date DPDK package already installed"
324 @echo "=========================================================="
328 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
329 @echo "=========================================================="
330 @echo " Outdated DPDK package detected:"
331 @echo " Installed: vpp-dpdk-dev $(INSTALLED_DEB_VER)"
332 @echo " Current: vpp-dpdk-dev $(DPDK_VERSION)-$(PKG_SUFFIX)"
334 @echo " Please upgrade by invoking 'make dpdk-install-dev'"
335 @echo " from the top level directory."
336 @echo "=========================================================="
339 ##############################################################################
341 ##############################################################################
343 RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
344 DEV_RPM=vpp-dpdk-devel-$(DPDK_VERSION)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
345 INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-dpdk-devel 2> /dev/null | grep -v "not inst")
347 .PHONY: build-rpm install-rpm check-rpm
349 $(DEV_RPM): Makefile rpm/vpp-dpdk.spec
351 --define "_topdir $(CURDIR)/rpm" \
352 --define "_version $(DPDK_VERSION)" \
353 --define "_release $(PKG_SUFFIX)" \
354 $(CURDIR)/rpm/vpp-dpdk.spec
355 mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
358 build-rpm: $(DEV_RPM)
361 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
363 sudo rpm -Uih $(DEV_RPM)
365 @echo "=========================================================="
366 @echo " Up-to-date DPDK package already installed"
367 @echo "=========================================================="
371 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
372 @echo "=========================================================="
373 @echo " Outdated DPDK package detected:"
374 @echo " Installed: vpp-dpdk-devel $(INSTALLED_RPM_VER)"
375 @echo " Current: vpp-dpdk-devel $(DPDK_VERSION)-$(PKG_SUFFIX)"
377 @echo " Please upgrade by invoking 'make dpdk-install-dev'"
378 @echo " from the top level directory."
379 @echo "=========================================================="
382 ##############################################################################
384 ##############################################################################
386 .PHONY: ebuild-build ebuild-install
389 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
390 @echo "=========================================================="
391 @echo "Building DPDK from source. Consider installing development"
392 @echo "package by invoking 'make dpdk-install-dev' from the"
393 @echo "top level directory"
394 @echo "=========================================================="
397 ifneq ($(INSTALLED_DEB_VER),)
400 ifneq ($(INSTALLED_RPM_VER),)
406 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)