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