#!/bin/sh /etc/rc.common
#
# Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

START=19

qca_nss_ppe_bridge_mgr_dependency() {
	count=0
	while [ -e /lib/modules/$(uname -r)/qca-nss-ppe-bridge-mgr.ko ] && [ ! -d /sys/module/qca_nss_ppe_bridge_mgr ]
	do
		count=$((count+1))
		sleep 1
		if [ $count -ge 30 ]
		then
			echo "qca-nss-ppe-bridge-mgr.ko module is not loaded" > /dev/kmsg
			exit 0
		fi
	done
}

enable_fdb() {
	#Enable fdb learning for PON RDPs
	echo 0 > /proc/sys/ppe/bridge_mgr/fdb_disabled
}

start() {
	qca_nss_ppe_bridge_mgr_dependency
	local board_type=`cat /tmp/sysinfo/board_name  | cut -d '-' -f 3`
	#echo "board_type: $board_type"
	local chip_type=`cat /tmp/sysinfo/board_name  | cut -d '-' -f 4`
	#echo "chip_type: $chip_type"
	if [ "$board_type" == "al06" ] || [ $board_type == "al05" ]; then
		enable_fdb
	elif [ "$board_type" == "mi01.2" ] && [ $chip_type == "c2" ]; then
		enable_fdb
	fi
}
