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