dpdk: only build SW crypto for x86_64 platforms
[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_MLX4_PMD         ?= n
23 DPDK_MLX5_PMD         ?= n
24
25 B := $(DPDK_BUILD_DIR)
26 I := $(DPDK_INSTALL_DIR)
27 DPDK_VERSION ?= 17.05
28 PKG_SUFFIX ?= vpp6
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.02_TARBALL_MD5_CKSUM := 6b9f7387c35641f4e8dbba3e528f2376
33 DPDK_17.05_TARBALL_MD5_CKSUM := 0a68c31cd6a6cabeed0a4331073e4c05
34 DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
35
36 IPSEC_MB_VER := 0.45
37 AESNIMB_LIB_TARBALL := v$(IPSEC_MB_VER).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-$(IPSEC_MB_VER)
40 ISA_L_CRYPTO_VER := 2.18.0
41 ISA_L_CRYPTO_LIB_TARBALL := v$(ISA_L_CRYPTO_VER).tar.gz
42 ISA_L_CRYPTO_LIB_TARBALL_URL := http://github.com/01org/isa-l_crypto/archive/$(ISA_L_CRYPTO_LIB_TARBALL)
43 ISA_L_CRYPTO_LIB_SOURCE := $(B)/isa-l_crypto-$(ISA_L_CRYPTO_VER)
44 ISA_L_CRYPTO_INSTALL_DIR := $(ISA_L_CRYPTO_LIB_SOURCE)/install
45
46 ifneq (,$(findstring clang,$(CC)))
47 DPDK_CC=clang
48 else ifneq (,$(findstring icc,$(CC)))
49 DPDK_CC=icc
50 else
51 DPDK_CC=gcc
52 endif
53
54 MACHINE=$(shell uname -m)
55
56 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64))
57 AESNI := y
58 else
59 AESNI := n
60 endif
61
62 ##############################################################################
63 # Intel x86
64 ##############################################################################
65 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64 i686))
66 DPDK_TARGET           ?= $(MACHINE)-native-linuxapp-$(DPDK_CC)
67 DPDK_MACHINE          ?= nhm
68 DPDK_TUNE             ?= core-avx2
69 ##############################################################################
70 # Cavium ThunderX
71 ##############################################################################
72 else ifneq (,$(findstring thunder,$(shell cat /sys/bus/pci/devices/0000:00:01.0/uevent | grep cavium)))
73 export CROSS=""
74 DPDK_TARGET           ?= arm64-thunderx-linuxapp-$(DPDK_CC)
75 DPDK_MACHINE          ?= thunderx
76 DPDK_TUNE             ?= generic
77
78 ##############################################################################
79 # Unknown platofrm
80 ##############################################################################
81 else
82 $(error unknown platform)
83 endif
84
85 # /proc/cpuinfo does not exist on platforms without a /proc and on some
86 # platforms, notably inside containers, it has no content. In those cases
87 # we assume there's 1 processor; we use 2*ncpu for the -j option.
88 # NB: GNU Make 4.2 will let us use '$(file </proc/cpuinfo)' to both test
89 # for file presence and content; for now this will have to do.
90 JOBS := $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo),\
91         $(shell expr 2 '*' $$(grep -c ^processor /proc/cpuinfo)), 2)
92
93 # compiler/linker custom arguments
94 DPDK_CPU_CFLAGS := -pie -fPIC
95 DPDK_EXTRA_LDFLAGS := -g
96
97 ifeq ($(DPDK_DEBUG),n)
98 DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
99 else
100 DPDK_EXTRA_CFLAGS := -g -O0
101 endif
102
103 DPDK_EXTRA_CFLAGS += -I$(ISA_L_CRYPTO_INSTALL_DIR)/include -Wl,-z,muldefs
104 DPDK_EXTRA_LDFLAGS += -L$(I)/lib
105 DPDK_MAKE_EXTRA_ARGS += AESNI_MULTI_BUFFER_LIB_PATH=$(AESNIMB_LIB_SOURCE)
106
107 # assemble DPDK make arguments
108 DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
109         T=$(DPDK_TARGET) \
110         RTE_CONFIG_TEMPLATE=../custom-config \
111         EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
112         EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
113         CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
114         DESTDIR=$(I) \
115         $(DPDK_MAKE_EXTRA_ARGS)
116
117 define set
118 @if grep -q CONFIG_$1 $@ ; \
119         then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
120         else echo CONFIG_$1=$2 >> $@ ; \
121 fi
122 endef
123
124 all: build
125
126 $(B)/custom-config: $(B)/.patch.ok Makefile
127         @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
128         @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
129         $(call set,RTE_MACHINE,$(DPDK_MACHINE))
130         @# modify options
131         $(call set,RTE_MAX_LCORE,256)
132         $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
133         $(call set,RTE_LIBEAL_USE_HPET,y)
134         $(call set,RTE_BUILD_COMBINE_LIBS,y)
135         $(call set,RTE_PCI_CONFIG,y)
136         $(call set,RTE_PCI_EXTENDED_TAG,"on")
137         $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
138         @# enable debug init for device drivers
139         $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
140         $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
141         $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
142         $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
143         $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
144         $(call set,RTE_LIBRTE_PMD_BOND,y)
145         $(call set,RTE_LIBRTE_IP_FRAG,y)
146         $(call set,RTE_LIBRTE_PMD_QAT,y)
147         $(call set,RTE_LIBRTE_PMD_AESNI_MB,$(AESNI))
148         $(call set,RTE_LIBRTE_PMD_AESNI_GCM,$(AESNI))
149         $(call set,RTE_LIBRTE_MLX4_PMD,$(DPDK_MLX4_PMD))
150         $(call set,RTE_LIBRTE_MLX5_PMD,$(DPDK_MLX5_PMD))
151         @# not needed
152         $(call set,RTE_LIBRTE_TIMER,n)
153         $(call set,RTE_LIBRTE_CFGFILE,n)
154         $(call set,RTE_LIBRTE_LPM,n)
155         $(call set,RTE_LIBRTE_ACL,n)
156         $(call set,RTE_LIBRTE_POWER,n)
157         $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
158         $(call set,RTE_LIBRTE_PORT,n)
159         $(call set,RTE_LIBRTE_TABLE,n)
160         $(call set,RTE_LIBRTE_PIPELINE,n)
161         $(call set,RTE_KNI_KMOD,n)
162         $(call set,RTE_EAL_IGB_UIO,n)
163         @rm -f .config.ok
164
165 $(CURDIR)/$(DPDK_TARBALL):
166         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
167                 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
168                 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
169         fi
170         @rm -f $(B)/.download.ok
171
172 $(CURDIR)/$(AESNIMB_LIB_TARBALL):
173         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) ] ; \
174                 then cp $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) $(CURDIR) ; \
175                 else curl -o $@ -LO $(AESNIMB_LIB_TARBALL_URL) ; \
176         fi
177
178 $(CURDIR)/$(ISA_L_CRYPTO_LIB_TARBALL):
179         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(ISA_L_CRYPTO_LIB_TARBALL) ] ; \
180                 then cp $(DPDK_DOWNLOAD_DIR)/$(ISA_L_CRYPTO_LIB_TARBALL) $(CURDIR) ; \
181                 else curl -o $@ -LO $(ISA_L_CRYPTO_LIB_TARBALL_URL) ; \
182         fi
183
184 DPDK_DOWNLOADS = $(CURDIR)/$(DPDK_TARBALL)
185 ifeq ($(AESNI),y)
186 DPDK_DOWNLOADS += $(CURDIR)/$(AESNIMB_LIB_TARBALL)
187 DPDK_DOWNLOADS += $(CURDIR)/$(ISA_L_CRYPTO_LIB_TARBALL)
188 endif
189
190 $(B)/.download.ok: $(DPDK_DOWNLOADS)
191         @mkdir -p $(B)
192         @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
193         @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
194         ( echo "Bad Checksum! Please remove $< and retry" && \
195                 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
196         @touch $@
197
198 .PHONY: download
199 download: $(B)/.download.ok
200
201 $(B)/.extract.ok: $(B)/.download.ok
202         @echo --- extracting $(DPDK_TARBALL) ---
203         @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
204         @echo --- extracting $(AESNIMB_LIB_TARBALL) ---
205         @tar --directory $(B) --extract --file $(CURDIR)/$(AESNIMB_LIB_TARBALL)
206         @echo --- extracting $(ISA_L_CRYPTO_LIB_TARBALL) ---
207         @tar --directory $(B) --extract --file $(CURDIR)/$(ISA_L_CRYPTO_LIB_TARBALL)
208         @touch $@
209
210 .PHONY: extract
211 extract: $(B)/.extract.ok
212
213 $(B)/.patch.ok: $(B)/.extract.ok
214 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
215         @echo --- patching ---
216         @for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
217                 echo Applying patch: $$(basename $$f) ; \
218                 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
219         done
220 endif
221         @touch $@
222
223 .PHONY: patch
224 patch: $(B)/.patch.ok
225
226 $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
227         @make $(DPDK_MAKE_ARGS) config
228         @touch $@
229
230 .PHONY: config
231 config: $(B)/.config.ok
232
233 # Order matters
234 BUILD_TARGETS += build-ipsec-mb build-isal-crypto build-dpdk
235
236 .PHONY: build-ipsec-mb
237 build-ipsec-mb:
238         mkdir -p $(I)/lib/
239         make -C $(AESNIMB_LIB_SOURCE) -j NO_GCM=y
240         cp $(AESNIMB_LIB_SOURCE)/libIPSec_MB.a $(I)/lib/
241
242 .PHONY: build-isal-crypto
243 build-isal-crypto:
244         mkdir -p $(I)/lib/
245         cd $(ISA_L_CRYPTO_LIB_SOURCE) && ./autogen.sh && \
246           ./configure --prefix=$(ISA_L_CRYPTO_INSTALL_DIR) CFLAGS='-fPIC -DPIC -O2'
247         make -C $(ISA_L_CRYPTO_LIB_SOURCE) -j install
248         cp $(ISA_L_CRYPTO_INSTALL_DIR)/lib/libisal_crypto.a $(I)/lib/
249
250 .PHONY: build-dpdk
251 build-dpdk:
252         @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
253         @make $(DPDK_MAKE_ARGS) install
254
255 $(B)/.build.ok: $(BUILD_TARGETS)
256         @touch $@
257
258 .PHONY: build
259 build: $(B)/.build.ok
260
261 .PHONY: install
262 install: $(B)/.build.ok
263
264 .PHONY: clean
265 clean:
266         @rm -rf $(B) $(I)
267
268 ##############################################################################
269 # .deb packaging
270 ##############################################################################
271
272 DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
273 DEV_DEB=vpp-dpdk-dev_$(DPDK_VERSION)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
274 INSTALLED_DEB_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-dpdk-dev 2> /dev/null)
275
276 .PHONY: build-deb install-deb check-deb
277
278 deb/debian/changelog: Makefile
279         @echo "vpp-dpdk ($(DPDK_VERSION)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
280         @echo "" >> $@
281         @echo "  * DPDK Release $(DPDK_VERSION)" >> $@
282         @echo "" >> $@
283         @echo " -- VPP Dev <vpp-dev@lists.fd.io>  $(shell date -R)" >> $@
284
285 $(DEV_DEB): deb/debian/changelog
286         @cd deb && dpkg-buildpackage -b -uc -us
287         git clean -fdx deb
288
289 build-deb: $(DEV_DEB)
290
291 install-deb:
292 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
293         @make $(DEV_DEB)
294         @sudo dpkg -i $(DEV_DEB)
295 else
296         @echo "=========================================================="
297         @echo " Up-to-date DPDK package already installed"
298         @echo "=========================================================="
299 endif
300
301 check-deb:
302 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
303         @echo "=========================================================="
304         @echo " Outdated DPDK package detected:"
305         @echo "  Installed: vpp-dpdk-dev $(INSTALLED_DEB_VER)"
306         @echo "  Current:   vpp-dpdk-dev $(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 # .rpm packaging
315 ##############################################################################
316
317 RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
318 DEV_RPM=vpp-dpdk-devel-$(DPDK_VERSION)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
319 INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-dpdk-devel 2> /dev/null | grep -v "not inst")
320
321 .PHONY: build-rpm install-rpm check-rpm
322
323 $(DEV_RPM): Makefile rpm/vpp-dpdk.spec
324         @rpmbuild -bb \
325           --define "_topdir $(CURDIR)/rpm" \
326           --define "_version $(DPDK_VERSION)" \
327           --define "_release $(PKG_SUFFIX)" \
328           $(CURDIR)/rpm/vpp-dpdk.spec
329         mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
330         git clean -fdx rpm
331
332 build-rpm: $(DEV_RPM)
333
334 install-rpm:
335 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
336         @$(MAKE) $(DEV_RPM)
337         sudo rpm -Uih $(DEV_RPM)
338 else
339         @echo "=========================================================="
340         @echo " Up-to-date DPDK package already installed"
341         @echo "=========================================================="
342 endif
343
344 check-rpm:
345 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
346         @echo "=========================================================="
347         @echo " Outdated DPDK package detected:"
348         @echo "  Installed: vpp-dpdk-devel $(INSTALLED_RPM_VER)"
349         @echo "  Current:   vpp-dpdk-devel $(DPDK_VERSION)-$(PKG_SUFFIX)"
350         @echo ""
351         @echo " Please upgrade by invoking 'make dpdk-install-dev'"
352         @echo " from the top level directory."
353         @echo "=========================================================="
354 endif
355
356 ##############################################################################
357 # ebuild support
358 ##############################################################################
359
360 .PHONY: ebuild-build ebuild-install
361
362 ebuild-build:
363 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
364         @echo "=========================================================="
365         @echo "Building DPDK from source. Consider installing development"
366         @echo "package by invoking 'make dpdk-install-dev' from the"
367         @echo "top level directory"
368         @echo "=========================================================="
369         make config
370 else
371 ifneq ($(INSTALLED_DEB_VER),)
372         make check-deb
373 endif
374 ifneq ($(INSTALLED_RPM_VER),)
375         make check-rpm
376 endif
377 endif
378
379 ebuild-install:
380 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
381         make install
382 endif