dpdk: updated build to automatically download Intel(R) Multi-Buffer Crypto for IPsec...
[vpp.git] / dpdk / Makefile
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:
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 # Scripts require non-POSIX parts of bash
15 SHELL := /bin/bash
16
17 DPDK_BUILD_DIR        ?= $(CURDIR)/_build
18 DPDK_INSTALL_DIR      ?= $(CURDIR)/_install
19 DPDK_PKTMBUF_HEADROOM ?= 128
20 DPDK_DOWNLOAD_DIR     ?= $(HOME)/Downloads
21 DPDK_DEBUG            ?= n
22 DPDK_CRYPTO_SW_PMD    ?= n
23 DPDK_MLX5_PMD         ?= n
24
25 B := $(DPDK_BUILD_DIR)
26 I := $(DPDK_INSTALL_DIR)
27 DPDK_VERSION ?= 17.02
28 PKG_SUFFIX ?= vpp1
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_16.07_TARBALL_MD5_CKSUM := 690a2bb570103e58d12f9806e8bf21be
33 DPDK_16.11_TARBALL_MD5_CKSUM := 06c1c577795360719d0b4fafaeee21e9
34 DPDK_17.02_TARBALL_MD5_CKSUM := 6b9f7387c35641f4e8dbba3e528f2376
35 DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
36 ifeq ($(DPDK_CRYPTO_SW_PMD),y)
37 AESNIMB_LIB_TARBALL := v0.44.tar.gz
38 AESNIMB_LIB_TARBALL_URL := http://github.com/01org/intel-ipsec-mb/archive/$(AESNIMB_LIB_TARBALL)
39 AESNIMB_LIB_SOURCE := $(B)/intel-ipsec-mb-0.44
40 export AESNI_MULTI_BUFFER_LIB_PATH=$(AESNIMB_LIB_SOURCE)
41 endif
42
43 ifneq (,$(findstring clang,$(CC)))
44 DPDK_CC=clang
45 else ifneq (,$(findstring icc,$(CC)))
46 DPDK_CC=icc
47 else
48 DPDK_CC=gcc
49 endif
50
51 ##############################################################################
52 # Intel x86_64
53 ##############################################################################
54 ifeq ($(shell uname -m),x86_64)
55 DPDK_TARGET           ?= x86_64-native-linuxapp-$(DPDK_CC)
56 DPDK_MACHINE          ?= nhm
57 DPDK_TUNE             ?= core-avx2
58
59 ##############################################################################
60 # Cavium ThunderX
61 ##############################################################################
62 else ifneq (,$(findstring thunder,$(shell cat /sys/bus/pci/devices/0000:00:01.0/uevent | grep cavium)))
63 export CROSS=""
64 DPDK_TARGET           ?= arm64-thunderx-linuxapp-$(DPDK_CC)
65 DPDK_MACHINE          ?= thunderx
66 DPDK_TUNE             ?= generic
67
68 ##############################################################################
69 # Unknown platofrm
70 ##############################################################################
71 else
72 $(error unknown platform)
73 endif
74
75 JOBS := $(shell grep processor /proc/cpuinfo | wc -l)
76
77 # compiler/linker custom arguments
78 DPDK_CPU_CFLAGS := -pie -fPIC
79 DPDK_EXTRA_LDFLAGS := -g
80
81 ifeq ($(DPDK_DEBUG),n)
82 DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
83 else
84 DPDK_EXTRA_CFLAGS := -g -O0
85 endif
86
87 # assemble DPDK make arguments
88 DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
89         T=$(DPDK_TARGET) \
90         RTE_CONFIG_TEMPLATE=../custom-config \
91         EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
92         EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
93         CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
94         DESTDIR=$(I) \
95         $(DPDK_MAKE_EXTRA_ARGS)
96
97 DPDK_SOURCE_FILES := $(shell  [ -e $(DPDK_SOURCE) ] && find $(DPDK_SOURCE) -name "*.[chS]")
98
99 define set
100 @if grep -q CONFIG_$1 $@ ; \
101         then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
102         else echo CONFIG_$1=$2 >> $@ ; \
103 fi
104 endef
105
106 all: build
107
108 $(B)/custom-config: $(B)/.patch.ok Makefile
109         @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
110         @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
111         $(call set,RTE_MACHINE,$(DPDK_MACHINE))
112         @# modify options
113         $(call set,RTE_MAX_LCORE,256)
114         $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
115         $(call set,RTE_LIBEAL_USE_HPET,y)
116         $(call set,RTE_BUILD_COMBINE_LIBS,y)
117         $(call set,RTE_LIBRTE_I40E_16BYTE_RX_DESC,y)
118         $(call set,RTE_PCI_CONFIG,y)
119         $(call set,RTE_PCI_EXTENDED_TAG,"on")
120         $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
121         @# enable debug init for device drivers
122         $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
123         $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
124         $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
125         $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
126         $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
127         $(call set,RTE_LIBRTE_PMD_BOND,y)
128         $(call set,RTE_LIBRTE_IP_FRAG,y)
129         $(call set,RTE_LIBRTE_PMD_QAT,y)
130         $(call set,RTE_LIBRTE_PMD_AESNI_MB,$(DPDK_CRYPTO_SW_PMD))
131         $(call set,RTE_LIBRTE_PMD_AESNI_GCM,$(DPDK_CRYPTO_SW_PMD))
132         $(call set,RTE_LIBRTE_MLX5_PMD,$(DPDK_MLX5_PMD))
133         @# not needed
134         $(call set,RTE_LIBRTE_TIMER,n)
135         $(call set,RTE_LIBRTE_CFGFILE,n)
136         $(call set,RTE_LIBRTE_LPM,n)
137         $(call set,RTE_LIBRTE_ACL,n)
138         $(call set,RTE_LIBRTE_POWER,n)
139         $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
140         $(call set,RTE_LIBRTE_REORDER,n)
141         $(call set,RTE_LIBRTE_PORT,n)
142         $(call set,RTE_LIBRTE_TABLE,n)
143         $(call set,RTE_LIBRTE_PIPELINE,n)
144         $(call set,RTE_KNI_KMOD,n)
145         $(call set,RTE_EAL_IGB_UIO,n)
146         @rm -f .config.ok
147
148 $(CURDIR)/$(DPDK_TARBALL):
149         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
150                 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
151                 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
152         fi
153 ifeq ($(DPDK_CRYPTO_SW_PMD),y)
154         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) ] ; \
155                 then cp $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) $(CURDIR) ; \
156                 else curl -o $(CURDIR)/$(AESNIMB_LIB_TARBALL) -LO $(AESNIMB_LIB_TARBALL_URL) ; \
157         fi
158 endif
159         @rm -f $(B)/.download.ok
160
161 $(B)/.download.ok: $(CURDIR)/$(DPDK_TARBALL)
162         @mkdir -p $(B)
163         @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
164         @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
165         ( echo "Bad Checksum! Please remove $< and retry" && \
166                 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
167         @touch $@
168
169 .PHONY: download
170 download: $(B)/.download.ok
171
172 $(B)/.extract.ok: $(B)/.download.ok
173         @echo --- extracting $(DPDK_TARBALL) ---
174         @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
175 ifeq ($(DPDK_CRYPTO_SW_PMD),y)
176         @echo --- extracting $(AESNIMB_LIB_TARBALL) ---
177         @tar --directory $(B) --extract --file $(CURDIR)/$(AESNIMB_LIB_TARBALL)
178 endif
179         @touch $@
180
181 .PHONY: extract
182 extract: $(B)/.extract.ok
183
184 $(B)/.patch.ok: $(B)/.extract.ok
185 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
186         @echo --- patching ---
187         @for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
188                 echo Applying patch: $$(basename $$f) ; \
189                 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
190         done
191 endif
192         @touch $@
193
194 .PHONY: patch
195 patch: $(B)/.patch.ok
196
197 $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
198 ifeq ($(DPDK_CRYPTO_SW_PMD),y)
199         @make -C $(AESNIMB_LIB_SOURCE)
200 endif
201         @make $(DPDK_MAKE_ARGS) config
202         @touch $@
203
204 .PHONY: config
205 config: $(B)/.config.ok
206
207 $(B)/.build.ok: $(DPDK_SOURCE_FILES)
208         @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
209         @make $(DPDK_MAKE_ARGS) install
210 ifeq ($(DPDK_CRYPTO_SW_PMD),y)
211         @cp $(AESNIMB_LIB_SOURCE)/libIPSec_MB.a $(I)/lib/
212 endif
213         @touch $@
214
215 .PHONY: build
216 build: $(B)/.build.ok
217
218 .PHONY: install
219 install: $(B)/.build.ok
220
221 .PHONY: clean
222 clean:
223         @rm -rf $(B) $(I)
224
225 ##############################################################################
226 # .deb packaging
227 ##############################################################################
228
229 DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
230 DEV_DEB=vpp-dpdk-dev_$(DPDK_VERSION)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
231 INSTALLED_DEB_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-dpdk-dev 2> /dev/null)
232
233 .PHONY: build-deb install-deb check-deb
234
235 deb/debian/changelog: Makefile
236         @echo "vpp-dpdk ($(DPDK_VERSION)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
237         @echo "" >> $@
238         @echo "  * DPDK Release $(DPDK_VERSION)" >> $@
239         @echo "" >> $@
240         @echo " -- VPP Dev <vpp-dev@lists.fd.io>  $(shell date -R)" >> $@
241
242 $(DEV_DEB): deb/debian/changelog
243         @cd deb && dpkg-buildpackage -b -uc -us
244         git clean -fdx deb
245
246 build-deb: $(DEV_DEB)
247
248 install-deb:
249 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
250         @make $(DEV_DEB)
251         @sudo dpkg -i $(DEV_DEB)
252 else
253         @echo "=========================================================="
254         @echo " Up-to-date DPDK package already installed"
255         @echo "=========================================================="
256 endif
257
258 check-deb:
259 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
260         @echo "=========================================================="
261         @echo " Outdated DPDK package detected:"
262         @echo "  Installed: vpp-dpdk-dev $(INSTALLED_DEB_VER)"
263         @echo "  Current:   vpp-dpdk-dev $(DPDK_VERSION)-$(PKG_SUFFIX)"
264         @echo ""
265         @echo " Please upgrade by invoking 'make dpdk-install-dev'"
266         @echo " from the top level directory."
267         @echo "=========================================================="
268 endif
269
270 ##############################################################################
271 # .rpm packaging
272 ##############################################################################
273
274 RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
275 DEV_RPM=vpp-dpdk-devel-$(DPDK_VERSION)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
276 INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-dpdk-devel 2> /dev/null | grep -v "not inst")
277
278 .PHONY: build-rpm install-rpm check-rpm
279
280 $(DEV_RPM): Makefile rpm/vpp-dpdk.spec
281         @rpmbuild -bb \
282           --define "_topdir $(CURDIR)/rpm" \
283           --define "_version $(DPDK_VERSION)" \
284           --define "_release $(PKG_SUFFIX)" \
285           $(CURDIR)/rpm/vpp-dpdk.spec
286         mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
287         git clean -fdx rpm
288
289 build-rpm: $(DEV_RPM)
290
291 install-rpm:
292 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
293         @make $(DEV_RPM)
294         sudo rpm -Uih $(DEV_RPM)
295 else
296         @echo "=========================================================="
297         @echo " Up-to-date DPDK package already installed"
298         @echo "=========================================================="
299 endif
300
301 check-rpm:
302 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
303         @echo "=========================================================="
304         @echo " Outdated DPDK package detected:"
305         @echo "  Installed: vpp-dpdk-devel $(INSTALLED_RPM_VER)"
306         @echo "  Current:   vpp-dpdk-devel $(DPDK_VERSION)-$(PKG_SUFFIX)"
307         @echo ""
308         @echo " Please upgrade by invoking 'make dpdk-install-dev'"
309         @echo " from the top level directory."
310         @echo "=========================================================="
311 endif
312
313 ##############################################################################
314 # ebuild support
315 ##############################################################################
316
317 .PHONY: ebuild-build ebuild-install
318
319 ebuild-build:
320 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
321         @echo "=========================================================="
322         @echo "Building DPDK from source. Consider installing development"
323         @echo "package by invoking 'make dpdk-install-dev' from the"
324         @echo "top level directory"
325         @echo "=========================================================="
326         make config
327 else
328 ifneq ($(INSTALLED_DEB_VER),)
329         make check-deb
330 endif
331 ifneq ($(INSTALLED_RPM_VER),)
332         make check-rpm
333 endif
334 endif
335
336 ebuild-install:
337 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
338         make install
339 endif