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