# SPDX-License-Identifier: GPL-2.0

ifneq ($(HWSIM), )
	KBUILD_EXTRA_SYMBOLS := $(HWSIM)/Module.symvers
else
	SILICON ?= scm2020_a1
# CONFIG_SCM80211_VENDOR_CMD
#	VENDOR cmd used which could be called by nl80211 vendor
#	CONFIG_SCM80211_VENDOR_CMD ?= y
#
# CONFIG_SCM80211_4K_MPDU
#	Config for the host which has limited memory
#	4K MPDU size will be used instead of 8K
#	Page pre alloc will be not used (can be turned on separately)
#	CONFIG_SCM80211_4K_MPDU ?= y
#
# CONFIG_SCM80211_SHRINK_MEM
#	Config for less memory platform
#	CONFIG_SCM80211_SHRINK_MEM ?= y
#
# CONFIG_SCM80211_PM
#	enable power management
#	CONFIG_SCM80211_PM ?= y
#
# CONFIG_SCM80211_TWT
#	Enable TWT
#	CONFIG_SCM80211_TWT	?= y
#
# CONFIG_GET_SKB_IN_POOL
#	Config for usb solution on cpu the work can not be scheduled
#	in time which cause some OOM
#	CONFIG_GET_SKB_IN_POOL	?= y
#
# CONFIG_WORK_ON_SPEC_CPU
#	config specific cpu for hwq work (don't forget to change the CPU num also)
#	ccflags-$(CONFIG_WORK_ON_SPEC_CPU) += -DSCHEDULE_ON_SPECIFIC_CPU=xx
#	CONFIG_WORK_ON_SPEC_CPU	?= y
#
# CONFIG_TXOP_AMPDU_LEN_LIMIT
#	Config for SCM80211_TXOP_AMPDU_LEN limit which is used for memory limited
#	platforms
#	config SCM80211_TXOP_AMPDU_LEN for usb 0x12000 -> 64K (max 0x24000)
#	CONFIG_TXOP_AMPDU_LEN_LIMIT ?= y
#
# CONFIG_SCM80211_FTM
#	config to enable ftm mode
#	CONFIG_SCM80211_FTM ?= y
#
# CONFIG_RFKILL_POLL
#	config to enable the function of airplane
	CONFIG_RFKILL_POLL ?= y
#
# CONFIG_FW_LOG_UPLOAD
#	config to upload FW log to host driver
#	CONFIG_FW_LOG_UPLOAD ?= y
#
# CONFIG_AMPDU_SIZE_SLIDE
#	CONFIG_AMPDU_SIZE_SLIDE ?= y
#
# CONFIG_31_CLINETS_SUPPORT
#	config to support 31 client mode
#	CONFIG_31_CLINETS_SUPPORT ?= y
#
# CONFIG_SCM80211_WOW
#	CONFIG_SCM80211_WOW ?= y
#
# CONFIG_SCM80211_DFS
#	CONFIG_SCM80211_DFS ?= y
#
# CONFIG_SCM80211_ADAPTIVITY
#	CONFIG_SCM80211_ADAPTIVITY ?= y
#
# CONFIG_BANDSTEERING
#	config bandsteering support
#	CONFIG_BANDSTEERING ?= y
endif

# CONFIG_MAC80211_VERSION
#	config mac80211 version which may be separately updated by host vendor and
#	cause it different from kernel version
#	kernel: means mac80211/cfg80211 is kernel based
#	specific version num: mean mac80211/cfg80211 is updated alone i.e 0x51008 ==> 5.10.8
	CONFIG_MAC80211_VERSION ?= LINUX_VERSION_CODE
#
# CONFIG_LIST_SORT_API
#	callback parameter in list_sort is partially updated in some vendor side
#	so we need to specific the API use, normally it is LINUX_VERSION_CODE
#	make it to be 0x51300 (5.13.0) if want to use
#	int compare(void *, const struct list_head *, const struct list_head *)
#	instead of
#	int compare(void *, struct list_head *, struct list_head *)
#	when you meet build error in list_sort please try to change it
	CONFIG_LIST_SORT_API ?= LINUX_VERSION_CODE
#

M ?= $(srctree)/$(shell echo ${src})

ifeq ($(OLDGCC), 1)
	ccflags-y := -std=gnu99
endif

ccflags-y := -Wno-declaration-after-statement

#
# Errata
#
# ERRATA_SW_WEP
#	In WEP40/104 cipher softap mode  encrypt/decrypt by Software
#

ccflags-y += -DERRATA_SW_WEP
ccflags-y += -DERRATA_HWQ_STUCK

#
# TEST flags
#
ccflags-y += -DTEST_NO_HE_LTF1x_GI0u8s
ccflags-y += -DTEST_INTR_RX_BUF
ccflags-y += -DTEST_MANGO_RF
ccflags-y += -DTEST_MT_LOCAL
ccflags-y += -DTEST_SKB_LINEAR

ccflags-y += -g
ccflags-y += -DRDMA
ccflags-y += -DSCM80211_COEX
ccflags-y += -DWIFI_SYS_EN=22
ccflags-y += -DBT_SYS_EN=23
ccflags-y += -DUSB_BT_LDO_EN=10
ccflags-y += -DEFUSE_ENABLE
ccflags-y += -DCONFIG_HTC_IF
ccflags-y += -DSCM80211_RX_STATISTICS_DEBUG
#ccflags-y += -DSCM80211_HOSTAP_AUTO_TEST
#ccflags-y += -DSCM80211_WFA_TEST
#ccflags-y += -DSCM80211_TXOP_DUMP
ccflags-y += -DMAC80211_BASE=$(CONFIG_MAC80211_VERSION)
ccflags-y += -DLIST_SORT_VERSION=$(CONFIG_LIST_SORT_API)

ccflags-$(CONFIG_RFKILL_POLL) += -DSCM80211_RFKILL_POLL
ccflags-$(CONFIG_FW_LOG_UPLOAD) += -DFW_LOG_UPLOAD
ccflags-$(CONFIG_AMPDU_SIZE_SLIDE) += -DAMPDU_SZ_SLIDE
ccflags-$(CONFIG_SCM80211_PM) += -DSCM80211_PS
ccflags-$(CONFIG_SCM80211_TWT) += -DSCM80211_TWT
ccflags-$(CONFIG_31_CLINETS_SUPPORT) += -DSCM80211_SAP_31_CLIENT
ccflags-$(CONFIG_SCM80211_VENDOR_CMD) += -DSCM80211_VENDOR_CMD
ccflags-$(CONFIG_WORK_ON_SPEC_CPU) += -DSCHEDULE_ON_SPECIFIC_CPU=1
ccflags-$(CONFIG_TXOP_AMPDU_LEN_LIMIT) += -DSCM80211_TXOP_AMPDU_LEN=0x12000
ccflags-$(CONFIG_SCM80211_4K_MPDU) += -DSCM80211_USE_4K_MPDU
ccflags-$(CONFIG_SCM80211_WOW) += -DSCM80211_WOW
ccflags-$(CONFIG_SCM80211_DFS) += -DSCM80211_DFS_CERTIFIED
ccflags-$(CONFIG_SCM80211_ADAPTIVITY) += -DSCM80211_ADAPTIVITY_CERTIFIED
ccflags-$(CONFIG_BANDSTEERING) += -DSCM80211_CONFIG_BANDSTEERING


ifeq ($(CONFIG_SCM80211_FTM), y)
	ccflags-y += -DSCM80211_FTM
else
	ccflags-y += -DSCM80211_IWPRIV_DEBUG
endif

ifeq ($(CONFIG_GET_SKB_IN_POOL), y)
	ccflags-y += -DONLY_GET_SKB_IN_POOL
	CONFIG_SCM80211_4K_MPDU = y
endif

ifeq ($(CONFIG_SCM80211_SHRINK_MEM), y)
	ccflags-y += -DSCM80211_SHRINK_MEM
	CONFIG_SCM80211_4K_MPDU = y
	ccflags-y += -DSCM80211_MAX_MPDU=8
else ifeq ($(SILICON), scm2020_z1)
	ccflags-y += -DSCM80211_MAX_MPDU=32
else
	ccflags-y += -DSCM80211_MAX_MPDU=64
endif

ifneq ($(CONFIG_SCM80211_4K_MPDU), y)
	ccflags-y += -DSCM80211_RX_PAGE_ALLOC
endif

ifeq ($(SILICON), scm2020_z1)
	ccflags-y += -DSCM2020_Z1
else ifeq ($(SILICON), scm2020_a0)
	ccflags-y += -DSCM2020_A0
else ifeq ($(SILICON), scm2020_a1)
	ccflags-y += -DSCM2020_A0
	ccflags-y += -DSCM2020_A1
endif

ccflags-y += -I$(M)

LDFLAGS_scm2625-pcie.o += -T$(M)/module.lds
LDFLAGS_scm2625-usb.o += -T$(M)/module.lds
LDFLAGS_scm2625.o += -T$(M)/module.lds

CFLAGS_rf-mango.o += -Wno-unused-function
CFLAGS_rf-adveos.o += -Wno-unused-function
CFLAGS_trace.o := -I$(src) -Wno-unused-function -Wno-unused-variable

ifneq ($(HWSIM), )
	hwsim-mod := scm2625
	obj-m += $(hwsim-mod).o
endif
pcie-mod  := scm2625-pcie
usb-mod   := scm2625-usb
usb-bt-mod   := scm-btusb

obj-m += $(pcie-mod).o
obj-m += $(usb-mod).o
obj-m += $(usb-bt-mod).o

common-y += main.o
common-y += util.o
common-y += chan.o
common-y += phy.o
common-y += tx.o rx.o
common-y += debug.o
common-y += trace.o
common-y += ps.o
common-y += ftm.o iw_cmd.o
common-y += efuse.o
common-y += notifier.o
common-y += rfkill.o
common-$(CONFIG_MAC80211_DEBUGFS) += debugfs.o
common-$(CONFIG_SCM80211_VENDOR_CMD) += vendor.o

ccflags-y += -DCONFIG_SCM80211_RC
common-y += rc.o
common-$(CONFIG_MAC80211_DEBUGFS) += rc_debugfs.o

common-$(CONFIG_BANDSTEERING) += bandsteer.o

#dfs
common-$(CONFIG_SCM80211_DFS) += dfs.o
#wow
common-$(CONFIG_SCM80211_WOW) += wow.o

#coex
common-y += coex.o

# chip
common-y += scm2020.o

# rf
common-y += rf.o

ifneq ($(HWSIM), )
	common-y += rf-hwsim.o
endif

ifneq ($(SILICON), )
	common-y += rf-scm2020.o
else
	common-y += rf-mango.o
	common-y += rf-adveos.o
endif


ifneq ($(HWSIM), )
	$(hwsim-mod)-y += $(common-y) hwsim.o
endif

$(pcie-mod)-y += htc.o

$(pcie-mod)-y += $(common-y) pcie.o
$(usb-mod)-y  += $(common-y) usb.o usb_dl.o
$(usb-bt-mod)-y  += scm_btusb.o

$(M)/module.lds: $(M)/module.ldS
