# SPDX-License-Identifier: GPL-2.0

ifneq ($(HWSIM), )
	KBUILD_EXTRA_SYMBOLS := $(HWSIM)/Module.symvers
else
	SILICON ?= scm2020_a0
# 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_TWT
#	Enable TWT
#	CONFIG_SCM80211_TWT	?= y
# CONFIG_ALLWINNER_USB
#	Config for usb solution on allwinner cpu the work can not be scheduled
#	in time
#	CONFIG_ALLWINNER_USB	?= y
endif

CONFIG_SCM80211_RC ?= y

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

#
# Errata
#
# ERRATA_TX_RFLIMIT
#	TX NG when rate higher than HE-MCS9
#
# ERRATA_TX_TIMING_GAP
#	TX timing gap out of range in responding HE_TB Qos data
#
# ERRATA_TX_MMSS_4US
#	Set MMSS to 4us for there is some underrun when sending short pkts
#
# ERRATA_RSN_PSIZE_ERROR
#	Entrpted error when some specified data size
#
# ERRATA_SW_WEP
#	In WEP40/104 cipher softap mode  encrypt/decrypt by Software
#
# ERRATA_MAC_PHY_SWITCH
#	In dbdc, mac0 mapping to phy1, disable 11b for 2G, mac1 mapping to phy0 in 5G
#

ccflags-y += -DERRATA_TX_TIMING_GAP
ccflags-y += -DERRATA_TX_MMSS_4US
ccflags-y += -DERRATA_RSN_PSIZE_ERROR
ccflags-y += -DERRATA_HWQ_STUCK
ccflags-y += -DERRATA_SW_WEP
#ccflags-y += -DERRATA_MAC_PHY_SWITCH
#
# 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 += -DSCM80211_RFKILL_POLL
#ccflags-y += -DSCM80211_HOSTAP_AUTO_TEST
ccflags-y += -DSCM80211_WFA_TEST
ccflags-y += -DSCM80211_P2P_DEVICE
#ccflags-y += -DSCM80211_PS
#ccflags-y += -DSCM80211_TXOP_DUMP
#ccflags-y += -DSCM80211_TWT
#ccflags-y += -DSCM80211_SMPS
#ccflags-y += -DSCM80211_WOW
#ccflags-y += -DSCM80211_DFS_CERTIFIED
ccflags-y += -DRDMA
ccflags-y += -DSCM80211_COEX
ccflags-y += -DSCM80211_RX_STATISTICS_DEBUG
ccflags-$(CONFIG_SCM80211_VENDOR_CMD) += -DSCM80211_VENDOR_CMD
ifeq ($(CONFIG_ALLWINNER_USB), y)
	ccflags-y += -DCONFIG_ALLWINNER_USB
	CONFIG_SCM80211_4K_MPDU = y
endif
ccflags-$(CONFIG_SCM80211_4K_MPDU) += -DSCM80211_USE_4K_MPDU
ifneq ($(CONFIG_SCM80211_4K_MPDU), y)
	ccflags-y += -DSCM80211_RX_PAGE_ALLOC
endif
#ccflags-y += -DSCM80211_RX_PAGE_ALLOC
ccflags-y += -I$(M)
ifeq ($(SILICON), scm2020_z1)
	ccflags-y += -DSCM2020_Z1
	ccflags-y += -DSCM80211_MAX_MPDU=32
else ifeq ($(SILICON), scm2020_a0)
	ccflags-y += -DSCM80211_MAX_MPDU=64
	ccflags-y += -DSCM2020_A0
else
	ccflags-y += -DSCM80211_MAX_MPDU=64
endif


LDFLAGS_scm80211-pcie.o += -T$(M)/module.lds
LDFLAGS_scm80211-usb.o += -T$(M)/module.lds
LDFLAGS_scm80211.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 := scm80211
endif
pcie-mod  := scm80211-pcie
usb-mod   := scm80211-usb
usb-dl-mod   := scm80211-usb-dl
usb-bt-mod   := scm-btusb

ifneq ($(HWSIM), )
obj-m += $(hwsim-mod).o
endif
obj-m += $(pcie-mod).o
obj-m += $(usb-mod).o
obj-m += $(usb-dl-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-$(CONFIG_MAC80211_DEBUGFS) += debugfs.o
common-$(CONFIG_SCM80211_VENDOR_CMD) += vendor.o

common-$(CONFIG_SCM80211_RC) += rc.o
ifeq ($(CONFIG_SCM80211_RC), y)
	ccflags-y += -DCONFIG_SCM80211_RC
	common-$(CONFIG_MAC80211_DEBUGFS) += rc_debugfs.o
endif

#dfs
common-y += dfs.o
#wow
common-y += wow.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 += $(common-y) pcie.o
$(usb-mod)-y  += $(common-y) usb.o 
$(usb-dl-mod)-y  += usb_dl.o
$(usb-bt-mod)-y  += scm_btusb.o

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