From d72b79196fc75a47c40f5e2a862e6a7911c55e3f Mon Sep 17 00:00:00 2001
From: Grygorii Strashko <grygorii.strashko@ti.com>
Date: Mon, 13 Sep 2021 18:19:55 +0300
Subject: [PATCH] net: ethernet: ti: icssg_prueth: simplify icssg_config_ipg()

Pass struct prueth_emac *emac as parameter instead of prueth/speed/slice as
it contains all needed info.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
---
 drivers/net/ethernet/ti/icssg_config.c | 18 +++++++++++-------
 drivers/net/ethernet/ti/icssg_prueth.c |  2 +-
 drivers/net/ethernet/ti/icssg_prueth.h |  2 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/ti/icssg_config.c b/drivers/net/ethernet/ti/icssg_config.c
index 50acf4e31008..7b0a39f6de54 100644
--- a/drivers/net/ethernet/ti/icssg_config.c
+++ b/drivers/net/ethernet/ti/icssg_config.c
@@ -98,8 +98,6 @@ static void icssg_config_mii_init(struct prueth *prueth, int mii)
 	pcnt_reg = (mii == ICSS_MII0) ? PRUSS_MII_RT_RX_PCNT0 :
 				       PRUSS_MII_RT_RX_PCNT1;
 
-	icssg_config_ipg(prueth, SPEED_1000, mii);
-
 	rxcfg = MII_RXCFG_DEFAULT;
 	txcfg = MII_TXCFG_DEFAULT;
 
@@ -177,21 +175,24 @@ static void icssg_config_rgmii_init(struct prueth *prueth, int slice)
 	}
 }
 
-void icssg_config_ipg(struct prueth *prueth, int speed, int mii)
+void icssg_config_ipg(struct prueth_emac *emac)
 {
-	switch (speed) {
+	struct prueth *prueth = emac->prueth;
+	int slice = prueth_emac_slice(emac);
+
+	switch (emac->speed) {
 	case SPEED_1000:
-		icssg_mii_update_ipg(prueth->mii_rt, mii, prueth->is_sr1 ?
+		icssg_mii_update_ipg(prueth->mii_rt, slice, prueth->is_sr1 ?
 				     MII_RT_TX_IPG_1G_SR1 : MII_RT_TX_IPG_1G);
 		break;
 	case SPEED_100:
-		icssg_mii_update_ipg(prueth->mii_rt, mii, prueth->is_sr1 ?
+		icssg_mii_update_ipg(prueth->mii_rt, slice, prueth->is_sr1 ?
 				     MII_RT_TX_IPG_100M_SR1 : MII_RT_TX_IPG_100M);
 		break;
 	case SPEED_10:
 		/* Firmware hardcodes IPG  for PG1. PG2 same as 100M */
 		if (!prueth->is_sr1)
-			icssg_mii_update_ipg(prueth->mii_rt, mii,
+			icssg_mii_update_ipg(prueth->mii_rt, slice,
 					     MII_RT_TX_IPG_100M);
 		break;
 	default:
@@ -293,6 +294,9 @@ int icssg_config_sr2(struct prueth *prueth, struct prueth_emac *emac, int slice)
 	memset_io(config, 0, TAS_GATE_MASK_LIST0);
 	icssg_config_rgmii_init(prueth, slice);
 	icssg_config_mii_init(prueth, slice);
+	emac->speed = SPEED_1000;
+	emac->duplex = DUPLEX_FULL;
+	icssg_config_ipg(emac);
 
 	/* set GPI mode */
 	pruss_cfg_gpimode(prueth->pruss, prueth->pru_id[slice],
diff --git a/drivers/net/ethernet/ti/icssg_prueth.c b/drivers/net/ethernet/ti/icssg_prueth.c
index b9e2b4c0da54..d485930d11ac 100644
--- a/drivers/net/ethernet/ti/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg_prueth.c
@@ -1283,7 +1283,7 @@ static void emac_adjust_link(struct net_device *ndev)
 
 			/* update the Tx IPG based on 100M/1G speed */
 			spin_lock_irqsave(&emac->lock, flags);
-			icssg_config_ipg(prueth, emac->speed, slice);
+			icssg_config_ipg(emac);
 			spin_unlock_irqrestore(&emac->lock, flags);
 			icssg_config_set_speed(emac);
 			if (!emac->is_sr1)
diff --git a/drivers/net/ethernet/ti/icssg_prueth.h b/drivers/net/ethernet/ti/icssg_prueth.h
index 0ff9e9680b57..7da6cb08a49d 100644
--- a/drivers/net/ethernet/ti/icssg_prueth.h
+++ b/drivers/net/ethernet/ti/icssg_prueth.h
@@ -274,7 +274,7 @@ static inline int prueth_emac_slice(struct prueth_emac *emac)
 }
 
 /* config helpers */
-void icssg_config_ipg(struct prueth *prueth, int speed, int mii);
+void icssg_config_ipg(struct prueth_emac *emac);
 void icssg_config_sr1(struct prueth *prueth, struct prueth_emac *emac,
 		      int slice);
 int icssg_config_sr2(struct prueth *prueth, struct prueth_emac *emac,
