Skip to content

Commit d35084e

Browse files
apopplestewartsmith
authored andcommitted
hw/npu2-hw-procedures.c: Fix running of zcal procedure
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@popple.id.au> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
1 parent b5d8537 commit d35084e

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

hw/npu2-hw-procedures.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,8 @@ DEFINE_PROCEDURE(phy_reset, phy_reset_wait, phy_reset_complete);
297297

298298
static uint32_t phy_tx_zcal(struct npu2_dev *ndev)
299299
{
300-
if (ndev->npu->tx_zcal_complete[ndev->index % 3])
300+
if (ndev->npu->tx_zcal_complete[ndev->index > 2])
301301
return PROCEDURE_COMPLETE;
302-
ndev->npu->tx_zcal_complete[ndev->index % 3] = 1;
303302

304303
/* Turn off SW enable and enable zcal state machine */
305304
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)
330329
return PROCEDURE_NEXT;
331330
}
332331

333-
/* FIXME: What are the right values? I just chose the middle ones... */
334-
#define MARGIN_RATIO (32)
335-
#define FFE_PRE_COEFF (7)
336-
#define FFE_POST_COEFF (12)
332+
#define MARGIN_RATIO (0)
333+
#define FFE_PRE_COEFF (0)
334+
#define FFE_POST_COEFF (0)
337335

338336
#define PRE_WIDTH (5)
339337
#define POST_WIDTH (7)
@@ -382,14 +380,6 @@ static uint32_t phy_tx_zcal_calculate(struct npu2_dev *ndev)
382380
uint32_t margin_pd_select;
383381
uint32_t margin_select;
384382

385-
if (ndev->index < 3) {
386-
if (ndev->npu->tx_zcal_complete[0])
387-
return PROCEDURE_COMPLETE;
388-
} else {
389-
if (ndev->npu->tx_zcal_complete[1])
390-
return PROCEDURE_COMPLETE;
391-
}
392-
393383
/* Convert the value from 8R to 2R by / 4 */
394384
zcal_n = phy_read(ndev, &NPU2_PHY_TX_ZCAL_N) / 4;
395385
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)
470460
phy_write(ndev, &NPU2_PHY_TX_MARGINPU_SELECT, therm(margin_select + 1)/2);
471461
phy_write(ndev, &NPU2_PHY_TX_MARGINPD_SELECT, therm(margin_select + 1)/2);
472462

473-
if (ndev->index < 3)
474-
ndev->npu->tx_zcal_complete[0] = true;
475-
else
476-
ndev->npu->tx_zcal_complete[1] = true;
477-
463+
ndev->npu->tx_zcal_complete[ndev->index > 2] = 1;
478464
return PROCEDURE_COMPLETE;
479465
}
480466
DEFINE_PROCEDURE(phy_tx_zcal, phy_tx_zcal_wait, phy_tx_zcal_calculate);

0 commit comments

Comments
 (0)