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