NAT44: fix setting of flag SNAT_SESSION_FLAG_LOAD_BALANCING (VPP-1235)
[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_CACHE_LINE_SIZE  ?= 64
21 DPDK_DOWNLOAD_DIR     ?= $(HOME)/Downloads
22 DPDK_DEBUG            ?= n
23 DPDK_MLX4_PMD         ?= n
24 DPDK_MLX5_PMD         ?= n
25
26 B := $(DPDK_BUILD_DIR)
27 I := $(DPDK_INSTALL_DIR)
28 DPDK_VERSION ?= 18.02
29 PKG_SUFFIX ?= vpp1
30 DPDK_BASE_URL ?= http://fast.dpdk.org/rel
31 DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.xz
32 DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL)
33 DPDK_17.11_TARBALL_MD5_CKSUM := 53ee9e054a8797c9e67ffa0eb5d0c701
34 DPDK_18.02_TARBALL_MD5_CKSUM := ca13077a014a2102c6e10153dfa3b920
35 DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION)
36 MACHINE=$(shell uname -m)
37
38 NASM_BASE_URL := http://www.nasm.us/pub/nasm/releasebuilds
39 NASM_VER := 2.13.01
40 NASM_TARBALL := nasm-$(NASM_VER).tar.xz
41 NASM_TAR_URL := $(NASM_BASE_URL)/$(NASM_VER)/$(NASM_TARBALL)
42 NASM_SOURCE := $(B)/nasm-$(NASM_VER)
43
44 ifeq ($(DPDK_VERSION),17.11)
45 IPSEC_MB_VER ?= 0.47
46 else
47 IPSEC_MB_VER ?= 0.48
48 endif
49
50 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64))
51   AESNI ?= y
52 $(info Building IPSec-MB $(IPSEC_MB_VER) library)
53 else
54   AESNI ?= N
55 endif
56
57 AESNIMB_LIB_TARBALL := v$(IPSEC_MB_VER).tar.gz
58 AESNIMB_LIB_TARBALL_URL := http://github.com/01org/intel-ipsec-mb/archive/$(AESNIMB_LIB_TARBALL)
59 AESNIMB_LIB_SOURCE := $(B)/intel-ipsec-mb-$(IPSEC_MB_VER)
60
61 ifneq (,$(findstring clang,$(CC)))
62 DPDK_CC=clang
63 else ifneq (,$(findstring icc,$(CC)))
64 DPDK_CC=icc
65 else
66 DPDK_CC=gcc
67 endif
68
69 ##############################################################################
70 # Intel x86
71 ##############################################################################
72 ifeq ($(MACHINE),$(filter $(MACHINE),x86_64 i686))
73 DPDK_TARGET           ?= $(MACHINE)-native-linuxapp-$(DPDK_CC)
74 DPDK_MACHINE          ?= nhm
75 DPDK_TUNE             ?= core-avx2
76
77 ##############################################################################
78 # ARM64
79 ##############################################################################
80 else ifeq ($(MACHINE),aarch64)
81 export CROSS=""
82 DPDK_TARGET           ?= arm64-armv8a-linuxapp-$(DPDK_CC)
83 DPDK_MACHINE          ?= armv8a
84 DPDK_TUNE             ?= generic
85
86 CPU_IMP_ARM                     = 0x41
87 CPU_IMP_CAVIUM                  = 0x43
88
89 CPU_PART_ARM_CORTEX_A53         = 0xd03
90 CPU_PART_ARM_CORTEX_A57         = 0xd07
91 CPU_PART_ARM_CORTEX_A72         = 0xd08
92 CPU_PART_ARM_CORTEX_A73         = 0xd09
93
94 CPU_PART_CAVIUM_THUNDERX        = 0x0a1
95 CPU_PART_CAVIUM_THUNDERX_81XX   = 0x0a2
96 CPU_PART_CAVIUM_THUNDERX_83XX   = 0x0a3
97
98 MIDR_IMPLEMENTER=$(shell awk '/implementer/ {print $$4;exit}' /proc/cpuinfo)
99 MIDR_PARTNUM=$(shell awk '/part/ {print $$4;exit}' /proc/cpuinfo)
100
101 ifeq ($(MIDR_IMPLEMENTER),$(CPU_IMP_ARM))
102 ##############################################################################
103 # Arm Cortex
104 ##############################################################################
105 CPU_PART_ARM_TUNE := $(CPU_PART_ARM_CORTEX_A53)/cortex-a53 \
106                      $(CPU_PART_ARM_CORTEX_A57)/cortex-a57 \
107                      $(CPU_PART_ARM_CORTEX_A72)/cortex-a72 \
108                      $(CPU_PART_ARM_CORTEX_A73)/cortex-a73
109 CPU_TUNE = $(notdir $(filter $(MIDR_PARTNUM)/%,$(CPU_PART_ARM_TUNE)))
110 ifneq ($(CPU_TUNE),)
111 DPDK_TUNE             = $(CPU_TUNE)
112 else
113 $(warning Unknown Arm CPU)
114 endif
115
116 else ifeq ($(MIDR_IMPLEMENTER),$(CPU_IMP_CAVIUM))
117 ##############################################################################
118 # Cavium ThunderX
119 ##############################################################################
120 ifneq (,$(findstring $(MIDR_PARTNUM),$(CPU_PART_CAVIUM_THUNDERX) \
121         $(CPU_PART_CAVIUM_THUNDERX_81XX) $(CPU_PART_CAVIUM_THUNDERX_83XX)))
122 DPDK_TARGET           = arm64-thunderx-linuxapp-$(DPDK_CC)
123 DPDK_MACHINE          = thunderx
124 else
125 $(warning Unknown Cavium CPU)
126 endif
127 endif
128
129 ##############################################################################
130 # Unknown platform
131 ##############################################################################
132 else
133 $(error Unknown platform)
134 endif
135
136 # /proc/cpuinfo does not exist on platforms without a /proc and on some
137 # platforms, notably inside containers, it has no content. In those cases
138 # we assume there's 1 processor; we use 2*ncpu for the -j option.
139 # NB: GNU Make 4.2 will let us use '$(file </proc/cpuinfo)' to both test
140 # for file presence and content; for now this will have to do.
141 JOBS := $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo),\
142         $(shell grep -c ^processor /proc/cpuinfo), 2)
143
144 # compiler/linker custom arguments
145 DPDK_CPU_CFLAGS := -pie -fPIC
146
147 ifeq ($(DPDK_DEBUG),n)
148 DPDK_EXTRA_CFLAGS := -g -mtune=$(DPDK_TUNE)
149 else
150 DPDK_EXTRA_CFLAGS := -g -O0
151 endif
152
153 DPDK_MAKE_EXTRA_ARGS += AESNI_MULTI_BUFFER_LIB_PATH=$(AESNIMB_LIB_SOURCE)
154
155 # assemble DPDK make arguments
156 DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \
157         T=$(DPDK_TARGET) \
158         RTE_CONFIG_TEMPLATE=../custom-config \
159         EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \
160         EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \
161         CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \
162         DESTDIR=$(I) \
163         $(DPDK_MAKE_EXTRA_ARGS)
164
165 define set
166 @if grep -q CONFIG_$1 $@ ; \
167         then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \
168         else echo CONFIG_$1=$2 >> $@ ; \
169 fi
170 endef
171
172 all: build
173
174 $(B)/custom-config: $(B)/.patch.ok Makefile
175         @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) ---
176         @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@
177         $(call set,RTE_MACHINE,$(DPDK_MACHINE))
178         @# modify options
179         $(call set,RTE_MAX_LCORE,256)
180         $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM))
181         $(call set,RTE_CACHE_LINE_SIZE,$(DPDK_CACHE_LINE_SIZE))
182         $(call set,RTE_LIBEAL_USE_HPET,y)
183         $(call set,RTE_BUILD_COMBINE_LIBS,y)
184         $(call set,RTE_PCI_CONFIG,y)
185         $(call set,RTE_PCI_EXTENDED_TAG,"on")
186         $(call set,RTE_PCI_MAX_READ_REQUEST_SIZE,4096)
187         @# enable debug init for device drivers
188         $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG))
189         $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG))
190         $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG))
191         $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG))
192         $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG))
193         $(call set,RTE_LIBRTE_PMD_BOND,y)
194         $(call set,RTE_LIBRTE_IP_FRAG,y)
195         $(call set,RTE_LIBRTE_PMD_QAT,y)
196         $(call set,RTE_LIBRTE_PMD_AESNI_MB,$(AESNI))
197         $(call set,RTE_LIBRTE_PMD_AESNI_GCM,$(AESNI))
198         $(call set,RTE_LIBRTE_MLX4_PMD,$(DPDK_MLX4_PMD))
199         $(call set,RTE_LIBRTE_MLX5_PMD,$(DPDK_MLX5_PMD))
200         $(call set,RTE_LIBRTE_MLX4_DLOPEN_DEPS,$(DPDK_MLX4_PMD))
201         $(call set,RTE_LIBRTE_MLX5_DLOPEN_DEPS,$(DPDK_MLX5_PMD))
202         @# not needed
203         $(call set,RTE_LIBRTE_PMD_TAP,n)
204         $(call set,RTE_LIBRTE_TIMER,n)
205         $(call set,RTE_LIBRTE_CFGFILE,n)
206         $(call set,RTE_LIBRTE_LPM,n)
207         $(call set,RTE_LIBRTE_ACL,n)
208         $(call set,RTE_LIBRTE_POWER,n)
209         $(call set,RTE_LIBRTE_DISTRIBUTOR,n)
210         $(call set,RTE_LIBRTE_PORT,n)
211         $(call set,RTE_LIBRTE_TABLE,n)
212         $(call set,RTE_LIBRTE_PIPELINE,n)
213         $(call set,RTE_LIBRTE_FLOW_CLASSIFY,n)
214         $(call set,RTE_KNI_KMOD,n)
215         $(call set,RTE_EAL_IGB_UIO,n)
216         @# currently broken in 18.02
217         $(call set,RTE_LIBRTE_DPAA_BUS,n)
218         $(call set,RTE_LIBRTE_DPAA_MEMPOOL,n)
219         $(call set,RTE_LIBRTE_DPAA_PMD,n)
220         $(call set,RTE_LIBRTE_PMD_DPAA_SEC,n)
221         $(call set,RTE_LIBRTE_PMD_DPAA_EVENTDEV,n)
222         @rm -f .config.ok
223
224 $(CURDIR)/$(DPDK_TARBALL):
225         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \
226                 then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \
227                 else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \
228         fi
229         @rm -f $(B)/.download.ok
230
231 $(CURDIR)/$(NASM_TARBALL):
232         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(NASM_TARBALL) ] ; \
233                 then cp $(DPDK_DOWNLOAD_DIR)/$(NASM_TARBALL) $(CURDIR) ; \
234                 else curl -o $(CURDIR)/$(NASM_TARBALL) -LO $(NASM_TAR_URL) ; \
235         fi
236
237 $(CURDIR)/$(AESNIMB_LIB_TARBALL):
238         @if [ -e $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) ] ; \
239                 then cp $(DPDK_DOWNLOAD_DIR)/$(AESNIMB_LIB_TARBALL) $(CURDIR) ; \
240                 else curl -o $@ -LO $(AESNIMB_LIB_TARBALL_URL) ; \
241         fi
242
243 DPDK_DOWNLOADS = $(CURDIR)/$(DPDK_TARBALL)
244 ifeq ($(AESNI),y)
245 DPDK_DOWNLOADS += $(CURDIR)/$(NASM_TARBALL)
246 DPDK_DOWNLOADS += $(CURDIR)/$(AESNIMB_LIB_TARBALL)
247 endif
248
249 $(B)/.download.ok: $(DPDK_DOWNLOADS)
250         @mkdir -p $(B)
251         @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum
252         @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \
253         ( echo "Bad Checksum! Please remove $< and retry" && \
254                 rm $(B)/$(DPDK_TARBALL).md5sum && false ))
255         @touch $@
256
257 .PHONY: download
258 download: $(B)/.download.ok
259
260 $(B)/.extract.ok: $(B)/.download.ok
261         @echo --- extracting $(DPDK_TARBALL) ---
262         @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL)
263 ifeq ($(AESNI),y)
264         @echo --- extracting $(NASM_TARBALL) ---
265         @tar --directory $(B) --extract --file $(CURDIR)/$(NASM_TARBALL)
266         @echo --- extracting $(AESNIMB_LIB_TARBALL) ---
267         @tar --directory $(B) --extract --file $(CURDIR)/$(AESNIMB_LIB_TARBALL)
268 endif
269         @touch $@
270
271 .PHONY: extract
272 extract: $(B)/.extract.ok
273
274 $(B)/.patch.ok: $(B)/.extract.ok
275 ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),)
276         @echo --- patching ---
277         @for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \
278                 echo Applying patch: $$(basename $$f) ; \
279                 patch -p1 -d $(DPDK_SOURCE) < $$f ; \
280         done
281 endif
282         @touch $@
283
284 .PHONY: patch
285 patch: $(B)/.patch.ok
286
287 $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config
288         @make $(DPDK_MAKE_ARGS) config
289         @touch $@
290
291 .PHONY: config
292 config: $(B)/.config.ok
293
294 .PHONY: build-nasm
295 build-nasm:
296         cd $(NASM_SOURCE) && sh configure && make -j
297
298 .PHONY: build-ipsec-mb
299 build-ipsec-mb:
300         mkdir -p $(I)/lib/
301         # Do not build GCM stuff if we are building ISA_L
302         make -C $(AESNIMB_LIB_SOURCE) -j \
303           EXTRA_CFLAGS=-fPIC NASM=$(NASM_SOURCE)/nasm
304         cp $(AESNIMB_LIB_SOURCE)/libIPSec_MB.a $(I)/lib/
305
306 .PHONY: build-dpdk
307 build-dpdk:
308         @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi
309         @make $(DPDK_MAKE_ARGS) install
310
311 # Order matters
312 ifeq ($(AESNI),y)
313 BUILD_TARGETS += build-nasm
314 BUILD_TARGETS += build-ipsec-mb
315 endif
316 BUILD_TARGETS += build-dpdk
317
318 $(B)/.build.ok: $(BUILD_TARGETS)
319         @touch $@
320
321 .PHONY: build
322 build: $(B)/.build.ok
323
324 .PHONY: install
325 install: $(B)/.build.ok
326
327 .PHONY: clean
328 clean:
329         @rm -rf $(B) $(I)
330
331 ##############################################################################
332 # .deb packaging
333 ##############################################################################
334
335 DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
336 DEV_DEB=vpp-dpdk-dev_$(DPDK_VERSION)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
337 INSTALLED_DEB_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-dpdk-dev 2> /dev/null)
338
339 .PHONY: build-deb install-deb check-deb
340
341 deb/debian/changelog: Makefile
342         @echo "vpp-dpdk ($(DPDK_VERSION)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
343         @echo "" >> $@
344         @echo "  * DPDK Release $(DPDK_VERSION)" >> $@
345         @echo "" >> $@
346         @echo " -- VPP Dev <vpp-dev@lists.fd.io>  $(shell date -R)" >> $@
347
348 $(DEV_DEB): deb/debian/changelog
349         @cd deb && dpkg-buildpackage -b -uc -us
350         git clean -fdx deb
351
352 build-deb: $(DEV_DEB)
353
354 install-deb:
355 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
356         @echo "=========================================================="
357         @echo " Out of date DPDK package installed."
358         @echo " Installed: $(INSTALLED_DEB_VER)"
359         @echo " Needed: $(DPDK_VERSION)-$(PKG_SUFFIX)"
360         @echo "=========================================================="
361         @make $(DEV_DEB)
362         @sudo dpkg -i $(DEV_DEB)
363 else
364         @echo "=========================================================="
365         @echo " Up-to-date DPDK package already installed"
366         @echo "=========================================================="
367 endif
368
369 check-deb:
370 ifneq ($(INSTALLED_DEB_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
371         @echo "=========================================================="
372         @echo " Outdated DPDK package detected:"
373         @echo "  Installed: vpp-dpdk-dev $(INSTALLED_DEB_VER)"
374         @echo "  Current:   vpp-dpdk-dev $(DPDK_VERSION)-$(PKG_SUFFIX)"
375         @echo ""
376         @echo " Please upgrade by invoking 'make dpdk-install-dev'"
377         @echo " from the top level directory."
378         @echo "=========================================================="
379 endif
380
381 ##############################################################################
382 # .rpm packaging
383 ##############################################################################
384
385 RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
386 DEV_RPM=vpp-dpdk-devel-$(DPDK_VERSION)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
387 INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-dpdk-devel 2> /dev/null | grep -v "not inst")
388
389 .PHONY: build-rpm install-rpm check-rpm
390
391 $(DEV_RPM): Makefile rpm/vpp-dpdk.spec
392         @rpmbuild -bb \
393           --define "_topdir $(CURDIR)/rpm" \
394           --define "_version $(DPDK_VERSION)" \
395           --define "_release $(PKG_SUFFIX)" \
396           $(CURDIR)/rpm/vpp-dpdk.spec
397         mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
398         git clean -fdx rpm
399
400 build-rpm: $(DEV_RPM)
401
402 install-rpm:
403 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
404         @$(MAKE) $(DEV_RPM)
405         sudo rpm -Uih $(DEV_RPM)
406 else
407         @echo "=========================================================="
408         @echo " Up-to-date DPDK package already installed"
409         @echo "=========================================================="
410 endif
411
412 check-rpm:
413 ifneq ($(INSTALLED_RPM_VER),$(DPDK_VERSION)-$(PKG_SUFFIX))
414         @echo "=========================================================="
415         @echo " Outdated DPDK package detected:"
416         @echo "  Installed: vpp-dpdk-devel $(INSTALLED_RPM_VER)"
417         @echo "  Current:   vpp-dpdk-devel $(DPDK_VERSION)-$(PKG_SUFFIX)"
418         @echo ""
419         @echo " Please upgrade by invoking 'make dpdk-install-dev'"
420         @echo " from the top level directory."
421         @echo "=========================================================="
422 endif
423
424 ##############################################################################
425 # ebuild support
426 ##############################################################################
427
428 .PHONY: ebuild-build ebuild-install
429
430 ebuild-build:
431 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
432         @echo "=========================================================="
433         @echo "Building DPDK from source. Consider installing development"
434         @echo "package by invoking 'make dpdk-install-dev' from the"
435         @echo "top level directory"
436         @echo "=========================================================="
437         make config
438 else
439 ifneq ($(INSTALLED_DEB_VER),)
440         make check-deb
441 endif
442 ifneq ($(INSTALLED_RPM_VER),)
443         make check-rpm
444 endif
445 endif
446
447 ebuild-install:
448 ifeq ($(INSTALLED_DEB_VER)$(INSTALLED_RPM_VER),)
449         make install
450 endif