VOL-3011: Make NNI port speed configurable while building openolt
Change-Id: I6f029005358b8c0e48a4adbe3fd3d3874801f0f7
diff --git a/BUILDING.md b/BUILDING.md
index ac1a2fa..ef0cc54 100644
--- a/BUILDING.md
+++ b/BUILDING.md
@@ -155,6 +155,29 @@
 [voltha-protos](https://gerrit.opencord.org/gitweb?p=voltha-protos.git;a=summary)
 repo.
 
+Optionally, for the NNI port default setting, the options could make the default setting of the NNI port speed.
+
+* 100G port change to 40Gbps speed
+```shell
+make OPENOLTDEVICE=asfvolt16 PORT_100G_SPEED=40000
+```
+* 100G port change to 10Gbps speed (use Break-out cable)
+```shell
+make OPENOLTDEVICE=asfvolt16 PORT_100G_SPEED=10000
+```
+* 25G port change to 20Gbps speed (Accton/Edgecore ASGvOLT64)
+```shell
+make OPENOLTDEVICE=asgvolt64 PORT_100G_SPEED=100000 PORT_25G_SPEED=20000
+```
+* 25G port change to 10Gbps speed (Accton/Edgecore ASGvOLT64)
+```shell
+make OPENOLTDEVICE=asgvolt64 PORT_100G_SPEED=100000 PORT_25G_SPEED=10000
+```
+* 25G port change to 1Gbps speed (Accton/Edgecore ASGvOLT64)
+```shell
+make OPENOLTDEVICE=asgvolt64 PORT_100G_SPEED=100000 PORT_25G_SPEED=1000
+```
+
 If the build process succeeds, libraries and executables will be created in the
 *openolt/agent/build* directory.
 
diff --git a/README.md b/README.md
index 9c16df4..0ec5692 100644
--- a/README.md
+++ b/README.md
@@ -123,6 +123,34 @@
 ./dev_mgmt_daemon -d -pcie
 ```
 
+Perform `dev_mgmt_daemon` and change NNI port speed:
+
+* 100G port change to 40Gbps speed
+```shell
+cd /broadcom
+./dev_mgmt_daemon -d -pcie -port_100g_speed 40000
+```
+* 100G port change to 10Gbps speed (use Break-out cable)
+```shell
+cd /broadcom
+./dev_mgmt_daemon -d -pcie -port_100g_speed 10000 topology_config_file ./topology_config_16_ports.ini
+```
+* 25G port change to 20Gbps speed (Accton/Edgecore ASGvOLT64)
+```shell
+cd /broadcom
+./dev_mgmt_daemon -d -pcie -port_25g_speed 20000
+```
+* 25G port change to 10Gbps speed (Accton/Edgecore ASGvOLT64)
+```shell
+cd /broadcom
+./dev_mgmt_daemon -d -pcie -port_25g_speed 10000
+```
+* 25G port change to 1Gbps speed (Accton/Edgecore ASGvOLT64)
+```shell
+cd /broadcom
+./dev_mgmt_daemon -d -pcie -port_25g_speed 1000
+```
+
 The `dev_mgmt_daemon` executable presents the CLI for Broadcom's BAL when run
 in the foreground which is useful for debugging.
 
diff --git a/agent/Makefile.in b/agent/Makefile.in
index 18da811..9ec04a6 100644
--- a/agent/Makefile.in
+++ b/agent/Makefile.in
@@ -48,7 +48,10 @@
 INBAND = "n"
 VLAN_ID = 4093
 
-#
+# NNI ports speed setting
+PORT_100G_SPEED ?= 100000
+PORT_25G_SPEED ?= 25000
+
 # Build directory
 BUILD_DIR = build
 
@@ -176,6 +179,7 @@
           -I$(BAL_API_DIR)/include/object_model
 CXXFLAGS += $(BAL_INC) -I $(BAL_DIR)/lib/cmdline
 CXXFLAGS += -DBCMOS_MSG_QUEUE_DOMAIN_SOCKET -DBCMOS_MSG_QUEUE_UDP_SOCKET -DBCMOS_MEM_CHECK -DBCMOS_SYS_UNITTEST -DENABLE_LOG -DENABLE_CLI
+PORT_SPEED_FILE = $(BAL_DIR)/switch_sdk/$(SDK_VER)/rc/$(OPENOLTDEVICE)/board_files/broadcom/port_speed.soc
 
 sdk: onl bal-api-$(BAL_API_VER)
 ifeq ("$(wildcard $(BAL_DIR))","")
@@ -184,6 +188,12 @@
 	cp download/$(SDK_ZIP) $(BCM_SDK)
 	chmod -R 744 $(BAL_DIR)
 	cat download/$(ACCTON_PATCH) | patch -p1 -d $(BAL_DIR)
+ifeq ("$(strip $(OPENOLTDEVICE))","asfvolt16")
+	echo "setenv port_speed_for_100 $(PORT_100G_SPEED)" > $(PORT_SPEED_FILE)
+else ifeq ("$(strip $(OPENOLTDEVICE))","asgvolt64")
+	echo "setenv port_speed_for_100 $(PORT_100G_SPEED)" > $(PORT_SPEED_FILE)
+	echo "setenv port_speed_for_25 $(PORT_25G_SPEED)" >> $(PORT_SPEED_FILE)
+endif
 	make -C $(BAL_DIR) BOARD=$(OPENOLTDEVICE) ONL_DIR=$(TOP_DIR)/$(ONL_DIR)/OpenNetworkLinux OPEN_SOURCE=y
 	make -C $(BAL_DIR) BOARD=$(OPENOLTDEVICE) release_board
 endif
diff --git a/agent/scripts/init.d/dev_mgmt_daemon b/agent/scripts/init.d/dev_mgmt_daemon
index 7637c6d..109e34f 100755
--- a/agent/scripts/init.d/dev_mgmt_daemon
+++ b/agent/scripts/init.d/dev_mgmt_daemon
@@ -14,9 +14,25 @@
 PATH="/broadcom:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
 APPDIR="/broadcom"
 APPBIN="dev_mgmt_daemon"
-APPARGS="-pcie -d"
 USER="root"
 GROUP="root"
+PORT_SPEED_FILE="$APPDIR/port_speed.soc"
+TOPOLOGY_CONFIG_FILE="$APPDIR/topology_config.ini"
+OLT_MODEL=`cat /sys/devices/virtual/dmi/id/board_name`
+if [ $OLT_MODEL = "ASXvOLT16" ]; then
+    Port_100G_SPEED=`cat $PORT_SPEED_FILE | awk -F "port_speed_for_100 " '{print $2}'`
+    [ $Port_100G_SPEED = "10000" ] && TOPOLOGY_CONFIG_FILE="$APPDIR/topology_config_16_ports.ini"
+    APPARGS="-pcie -d -port_100g_speed $Port_100G_SPEED -topology_config_file $TOPOLOGY_CONFIG_FILE"
+elif [ $OLT_MODEL = "ASGvOLT64" ]; then
+    Port_100G_SPEED=`cat $PORT_SPEED_FILE | awk -F "port_speed_for_100 " '{print $2}'`
+    [ $Port_100G_SPEED = "10000" ] && TOPOLOGY_CONFIG_FILE="$APPDIR/topology_config_16_ports.ini"
+    Port_25G_SPEED=`cat $PORT_SPEED_FILE | awk -F "port_speed_for_25 " '{print $2}'`
+    APPARGS="-pcie -d -port_100g_speed $Port_100G_SPEED -pcie -port_25g_speed $Port_25G_SPEED -topology_config_file $TOPOLOGY_CONFIG_FILE"
+else
+    Port_100G_SPEED="100000"
+    Port_25G_SPEED="25000"
+    APPARGS="-pcie -d -port_100g_speed $Port_100G_SPEED -pcie -port_25g_speed $Port_25G_SPEED -topology_config_file $TOPOLOGY_CONFIG_FILE"
+fi
 
 # Include functions
 set -e