[Skiboot] [PATCH 3/3] hw/npu2-hw-procedures.c: Fix running of zcal procedure

Alistair Popple alistair at popple.id.au
Thu Jun 1 13:46:05 AEST 2017


The zcal procedure should only be run once per obus (ie. once per group of 3
links). Clean up the code and fix the potential buffer overflow due to a typo.
Also updates the zcal settings to their proper values.

Fixes coverity 143248.

Signed-off-by: Alistair Popple <alistair at popple.id.au>
---
 hw/npu2-hw-procedures.c | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/hw/npu2-hw-procedures.c b/hw/npu2-hw-procedures.c
index ade898e..ee1ade6 100644
--- a/hw/npu2-hw-procedures.c
+++ b/hw/npu2-hw-procedures.c
@@ -297,9 +297,8 @@ DEFINE_PROCEDURE(phy_reset, phy_reset_wait, phy_reset_complete);
 
 static uint32_t phy_tx_zcal(struct npu2_dev *ndev)
 {
-	if (ndev->npu->tx_zcal_complete[ndev->index % 3])
+	if (ndev->npu->tx_zcal_complete[ndev->index > 2])
 		return PROCEDURE_COMPLETE;
-	ndev->npu->tx_zcal_complete[ndev->index % 3] = 1;
 
 	/* Turn off SW enable and enable zcal state machine */
 	phy_write(ndev, &NPU2_PHY_TX_ZCAL_SWO_EN, 0);
@@ -330,10 +329,9 @@ static uint32_t phy_tx_zcal_wait(struct npu2_dev *ndev)
 	return PROCEDURE_NEXT;
 }
 
-/* FIXME: What are the right values? I just chose the middle ones... */
-#define MARGIN_RATIO		(32)
-#define FFE_PRE_COEFF		(7)
-#define FFE_POST_COEFF		(12)
+#define MARGIN_RATIO		(0)
+#define FFE_PRE_COEFF		(0)
+#define FFE_POST_COEFF		(0)
 
 #define PRE_WIDTH		(5)
 #define POST_WIDTH		(7)
@@ -382,14 +380,6 @@ static uint32_t phy_tx_zcal_calculate(struct npu2_dev *ndev)
 	uint32_t margin_pd_select;
 	uint32_t margin_select;
 
-	if (ndev->index < 3) {
-		if (ndev->npu->tx_zcal_complete[0])
-			return PROCEDURE_COMPLETE;
-	} else {
-		if (ndev->npu->tx_zcal_complete[1])
-			return PROCEDURE_COMPLETE;
-	}
-
 	/* Convert the value from 8R to 2R by / 4 */
 	zcal_n = phy_read(ndev, &NPU2_PHY_TX_ZCAL_N) / 4;
 	zcal_p = phy_read(ndev, &NPU2_PHY_TX_ZCAL_P) / 4;
@@ -470,11 +460,7 @@ static uint32_t phy_tx_zcal_calculate(struct npu2_dev *ndev)
 	phy_write(ndev, &NPU2_PHY_TX_MARGINPU_SELECT, therm(margin_select + 1)/2);
 	phy_write(ndev, &NPU2_PHY_TX_MARGINPD_SELECT, therm(margin_select + 1)/2);
 
-	if (ndev->index < 3)
-		ndev->npu->tx_zcal_complete[0] = true;
-	else
-		ndev->npu->tx_zcal_complete[1] = true;
-
+	ndev->npu->tx_zcal_complete[ndev->index > 2] = 1;
 	return PROCEDURE_COMPLETE;
 }
 DEFINE_PROCEDURE(phy_tx_zcal, phy_tx_zcal_wait, phy_tx_zcal_calculate);
-- 
2.1.4



More information about the Skiboot mailing list