From 09be087a6865f2dfc0b3b814a5118ec44f89db1d Mon Sep 17 00:00:00 2001
From: Roman Azarenko <roman.azarenko@iopsys.eu>
Date: Fri, 21 Jan 2022 17:04:22 +0100
Subject: [PATCH] brcm63xx-arm: fix media type setting with autonegotiation
 disabled

Commit 7d1285b6d4ac484c773132b24ab383af2a1ededf introduced an issue with setting media type for a particular port when
autonegotiation is disabled. In this case $subport ends up being undefined, resulting in an error in ethctl, which
leads to the appropriate media type not being set.

This change is designed to fix the above. Additionally cleaned up the conditionals a bit, so that media type is only
determined once and then reused regardless of whether "oncrossbar" is set or not.

Related to IOP-6415
Related to IOP-5001
---
 .../base-files/lib/network/port.sh            | 24 +++++++++----------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/iopsys-brcm63xx-arm/base-files/lib/network/port.sh b/iopsys-brcm63xx-arm/base-files/lib/network/port.sh
index d531d7b83..0ce40a448 100644
--- a/iopsys-brcm63xx-arm/base-files/lib/network/port.sh
+++ b/iopsys-brcm63xx-arm/base-files/lib/network/port.sh
@@ -43,7 +43,7 @@ set_port_settings() {
 	local autoneg=$5
 	local eee=$6
 	local pause=$7
-	local crossbarports
+	local crossbarports media_type
 
 	[ -d /sys/class/net/$ifname ] || return
 
@@ -56,22 +56,20 @@ set_port_settings() {
 	[ "$duplex" == 0 ] && dplx="HD" || dplx="FD"
 	crossbar="$(echo `ethctl $ifname phy-crossbar` | awk -F' ' '{ print $2 $3 }')"
 
+	if [ "$autoneg" = "on" ]; then
+		media_type="auto"
+	else
+		media_type="$speed$dplx"
+	fi
+
 	if [ "$crossbar" == "oncrossbar" ]; then
 		crossbarports="$(echo `ethctl $ifname phy-crossbar` | awk -F':' '{ print $NF }')"
 
-		if [ "$autoneg" == "on" ]; then
-			for subport in $crossbarports; do
-				ethctl $ifname media-type auto port $subport &>/dev/null
-			done
-		else
-			ethctl $ifname media-type $speed$dplx port $subport &>/dev/null
-		fi
+		for subport in $crossbarports; do
+			ethctl $ifname media-type $media_type port $subport &>/dev/null
+		done
 	else
-		if [ "$autoneg" == "on" ]; then
-			ethctl $ifname media-type auto &>/dev/null
-		else
-			ethctl $ifname media-type $speed$dplx &>/dev/null
-		fi
+		ethctl $ifname media-type $media_type &>/dev/null
 	fi
 
 	[ $eee -eq 1 ] && eee="on" || eee="off"
-- 
GitLab