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