1# Makefile for building ecore as a module.
2AT?=@
3export AT
4
5KVER =
6ifeq ($(KVER),)
7    KVER = $(shell uname -r)
8endif
9
10__ARCH=$(shell uname -m)
11
12# PREFIX may be set by the RPM build to set the effective root.
13PREFIX =
14ifeq ($(shell ls /lib/modules/$(KVER)/build > /dev/null 2>&1 && echo build),)
15# SuSE source RPMs
16    _KVER=$(shell echo $(KVER) | cut -d "-" -f1,2)
17    _KFLA=$(shell echo $(KVER) | cut -d "-" -f3)
18    _ARCH=$(shell file -b /lib/modules/$(shell uname -r)/build | cut -d "/" -f5)
19    ifeq ($(_ARCH),)
20        _ARCH=$(__ARCH)
21    endif
22    ifeq ($(shell ls /usr/src/linux-$(_KVER)-obj > /dev/null 2>&1 && echo linux),)
23      ifeq ($(shell ls /usr/src/kernels/$(KVER)-$(__ARCH) > /dev/null 2>&1 && echo linux),)
24        LINUX=
25      else
26        LINUX=/usr/src/kernels/$(KVER)-$(__ARCH)
27        LINUXSRC=$(LINUX)
28        ifeq ($(KERNEL_DIR),)
29            KERNEL_DIR=$(LINUX)
30        endif
31      endif
32    else
33        ifeq ($(KERNEL_DIR),)
34            KERNEL_DIR=/usr/src/linux-$(_KVER)-obj/$(_ARCH)/$(_KFLA)
35        endif
36        LINUXSRC=/usr/src/linux-$(_KVER)
37    endif
38else
39    BCMPROC := $(__ARCH)
40    BCMCFGS := /lib/modules/$(KVER)/build \
41               /usr/src/kernels/$(KVER)-$(BCMPROC) \
42               /usr/src/linux-$(shell echo $(KVER) | sed "s|\(.*\)-\([a-z]*\)|\1-obj/$(BCMPROC)/\2|") \
43               /usr/src/linux
44
45    # Delete any entries that do not exist.
46    BCMTSTDIR = $(shell if ls $(DIR) > /dev/null 2>&1; then echo $(DIR); fi)
47    BCMCFGS := $(foreach DIR, $(BCMCFGS), $(BCMTSTDIR))
48
49    ifeq ($(BCMCFGS),)
50            $(error Linux kernel config directory not found)
51    else
52        ifeq ($(KERNEL_DIR),)
53            KERNEL_DIR := $(firstword $(BCMCFGS))
54	    ifeq ($(LINUXSRC),)
55	        ifneq ($(shell ls /lib/modules/$(KVER)/source > /dev/null 2>&1 && echo source),)
56		    LINUXSRC=/lib/modules/$(KVER)/source
57	        endif
58	    endif
59        endif
60    endif
61endif
62
63ifeq ($(LINUXSRC),)
64   LINUXSRC=$(KERNEL_DIR)
65endif
66
67# paths
68ifeq ($(shell ls /lib/modules/$(KVER)/updates > /dev/null 2>&1 && echo 1),1)
69    DRV_DIR = updates
70else
71    ifeq ($(shell grep -q "search.*[[:space:]]updates" /etc/depmod.conf > /dev/null 2>&1 && echo 1),1)
72        DRV_DIR = updates
73    else
74        ifeq ($(shell grep -q "search.*[[:space:]]updates" /etc/depmod.d/* > /dev/null 2>&1 && echo 1),1)
75            DRV_DIR = updates
76        else
77            DRV_DIR = kernel/drivers/net
78        endif
79    endif
80endif
81
82sles_distro := $(wildcard /etc/SuSE-release)
83ifneq ($(sles_distro),)
84SLES_VERSION = $(shell cat /etc/SuSE-release | grep VERSION | grep -o -P [0-9]+)
85SLES_PATCHLEVEL = $(shell cat /etc/SuSE-release | grep PATCHLEVEL | grep -o -P [0-9]+)
86PADDED_PATCHLEVEL = $(shell if [ 10 -gt $(SLES_PATCHLEVEL) ]; then echo 0$(SLES_PATCHLEVEL); else echo $(SLES_PATCHLEVEL); fi)
87SLES_DISTRO_VER = "0x$(SLES_VERSION)$(PADDED_PATCHLEVEL)"
88EXTRA_CFLAGS += -DSLES_DISTRO=$(SLES_DISTRO_VER)
89endif
90
91SOURCES = ecore_chain.c ecore_cxt.c ecore_dev.c ecore_dbg_fw_funcs.c ecore_user_dbg_fw_funcs.c ecore_hw.c ecore_init_fw_funcs.c ecore_init_ops.c ecore_int.c ecore_mcp.c ecore_sp_commands.c ecore_spq.c ecore_dcbx.c ecore_phy.c  ecore_selftest.c ecore_mng_tlv.c
92HEADERS_LL2 = ecore_ll2_api.h ecore_ll2.h
93HEADERS_HSI = ecore_hsi_common.h ecore_hsi_iscsi.h ecore_hsi_roce.h ecore_hsi_rdma.h ecore_hsi_iwarp.h ecore_hsi_fcoe.h ecore_hsi_toe.h ecore_hsi_debug_tools.h ecore_hsi_init_func.h ecore_hsi_init_tool.h ../common/include/common_hsi.h ../common/include/eth_common.h ../common/include/fcoe_common.h ../common/include/iscsi_common.h ../common/include/roce_common.h ../common/include/rdma_common.h ../common/include/storage_common.h ../common/include/tcp_common.h ../common/include/iwarp_common.h
94HEADERS = ecore_chain.h ecore_cxt_api.h ecore_cxt.h ecore_dbg_fw_funcs.h ecore_user_dbg_fw_funcs.h ecore_dbg_values.h ecore_dbg_values_user.h ecore_dev_api.h ecore_gtt_reg_addr.h ecore_gtt_values.h ecore.h ecore_hw_defs.h ecore_hw.h ecore_init_fw_funcs.h ecore_init_ops.h ecore_init_values.h ecore_init_values_zipped.h ecore_int_api.h ecore_int.h ecore_iro.h ecore_iro_values.h ecore_mcp.h ecore_phy_api.h ecore_mcp_api.h ecore_proto_if.h ecore_rt_defs.h ecore_sp_api.h ecore_sp_commands.h ecore_spq.h ecore_status.h ecore_utils.h ecore_dcbx.h ecore_dcbx_api.h ecore_selftest_api.h include/bcm_osal.h ../../hsi/hw/pcics_reg_driver.h  ../../hsi/hw/reg_addr.h ../../hsi/mcp/nvm_cfg.h ../../hsi/mcp/mcp_public.h ../../hsi/mcp/spad_layout.h ../../hsi/mfw_hsi.h ../../hsi/mcp/nvm_map.h ecore_tcp_ip.h
95MODULE_NAME = ecore
96obj-m += $(MODULE_NAME).o
97ecore-objs = ecore_cxt.o ecore_dev.o ecore_dbg_fw_funcs.o ecore_user_dbg_fw_funcs.o ecore_hw.o ecore_init_fw_funcs.o ecore_init_ops.o ecore_int.o ecore_mcp.o ecore_phy.o ecore_sp_commands.o ecore_spq.o ecore_dcbx.o ecore_selftest.o ecore_chain.o  ecore_mng_tlv.o
98
99#TODO - we need all HSI [e.g., ecore_cxt.c needs to know the size of all contexts.
100#Either need to carefully revise this, or everyone will need all the HSI files.
101#since both L2 and LL2 require ecore_hsi_eth.h, every flavour needs it
102HEADERS += $(HEADERS_HSI) ecore_hsi_eth.h
103
104# Determine the content of the ecore compilation - on default do everything
105ifneq ($(L2), 1)
106ifneq ($(ROCE), 1)
107ifneq ($(FCOE), 1)
108ifneq ($(ISCSI), 1)
109ifneq ($(PTP), 1)
110ifneq ($(IWARP), 1)
111L2 = 1
112ROCE = 1
113FCOE = 1
114ISCSI = 1
115PTP = 1
116IWARP = 1
117endif
118endif
119endif
120endif
121endif
122endif
123
124HEADERS += ecore_l2_api.h ecore_l2.h
125HEADERS += ecore_roce.h ecore_roce_api.h ecore_hsi_roce.h ecore_hsi_rdma.h
126HEADERS += ecore_fcoe_api.h ecore_fcoe.h ecore_hsi_fcoe.h
127HEADERS += ecore_hsi_iscsi.h ecore_iscsi_api.h ecore_iscsi.h ecore_ooo.h
128HEADERS += $(HEADERS_LL2)
129HEADERS += ecore_iov_api.h ecore_sriov.h ecore_vf_api.h ecore_vf.h ecore_vfpf_if.h
130HEADERS += ecore_ptp_api.h
131
132ifeq ($(L2), 1)
133SRIOV ?= 1
134ecore-objs += ecore_l2.o
135SOURCES += ecore_l2.c
136EXTRA_CFLAGS += -DCONFIG_ECORE_L2
137endif
138ifeq ($(ROCE), 1)
139LL2 = 1
140SOURCES += ecore_roce.c
141ecore-objs += ecore_roce.o
142EXTRA_CFLAGS += -DCONFIG_ECORE_ROCE
143endif
144ifeq ($(FCOE), 1)
145LL2 = 1
146SOURCES += ecore_fcoe.c
147ecore-objs += ecore_fcoe.o
148EXTRA_CFLAGS += -DCONFIG_ECORE_FCOE
149endif
150ifeq ($(ISCSI), 1)
151LL2 = 1
152SOURCES += ecore_iscsi.c ecore_ooo.c
153ecore-objs += ecore_iscsi.o ecore_ooo.o
154EXTRA_CFLAGS += -DCONFIG_ECORE_ISCSI
155endif
156ifeq ($(IWARP), 1)
157LL2 = 1
158EXTRA_CFLAGS += -DCONFIG_ECORE_IWARP
159endif
160
161
162#Derivatives
163ifeq ($(LL2), 1)
164SOURCES += ecore_ll2.c
165ecore-objs += ecore_ll2.o
166EXTRA_CFLAGS += -DCONFIG_ECORE_LL2
167endif
168ifeq ($(SRIOV), 1)
169ecore-objs += ecore_sriov.o ecore_vf.o
170SOURCES += ecore_sriov.c ecore_vf.c
171EXTRA_CFLAGS += -DCONFIG_ECORE_SRIOV
172endif
173ifeq ($(PTP), 1)
174ecore-objs += ecore_ptp.o
175SOURCES += ecore_ptp.c
176EXTRA_CFLAGS += -DCONFIG_ECORE_PTP
177endif
178
179#Add include subdir for both user/module flavours
180EXTRA_CFLAGS += -DECORE_PACKAGE -I$(src)/include -I./include -I$(src)/../common/include/ -I./../common/include/ -I$(src)/../../hsi/hw/ -I./../../hsi/hw -I$(src)/../../hsi/mcp/ -I./../../hsi/mcp -I$(src)/../../hsi/ -I../../hsi/
181
182all default: $(obj-m)
183
184clean:
185	rm -rf *.o *.ko .*.cmd *.mod.c Module.symvers modules.order
186
187$(obj-m): $(SOURCES)
188	$(MAKE) -C $(KERNEL_DIR) M=`pwd` modules
189
190user: $(SOURCES)
191	$(CC) -c $(SOURCES) $(EXTRA_CFLAGS)
192
193tar: $(SOURCES) $(HEADERS)
194	rm -rf /tmp/ecore.tar.gz
195	rm -rf /tmp/ecore*
196	mkdir /tmp/ecore
197	cp -r $(SOURCES) $(HEADERS) release.txt /tmp/ecore/
198	echo "L2 = $(L2)" >> /tmp/ecore/Makefile
199	echo "FCOE = $(FCOE)" >> /tmp/ecore/Makefile
200	echo "ISCSI = $(ISCSI)" >> /tmp/ecore/Makefile
201	echo "ROCE = $(ROCE)" >> /tmp/ecore/Makefile
202	echo "SRIOV = $(SRIOV)" >> /tmp/ecore/Makefile
203	cat Makefile >> /tmp/ecore/Makefile
204	tar czvf /tmp/ecore.tar.gz -C /tmp ecore
205	rm -rf /tmp/ecore
206