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