Re: [PATCH net-next v4 9/9] net: phy: micrel: ksz886x/ksz8081: add cabletest support

From: Andrew Lunn
Date: Sat Jun 12 2021 - 14:39:19 EST


> +static int ksz886x_cable_test_get_status(struct phy_device *phydev,
> + bool *finished)
> +{
> + unsigned long pair_mask = 0x3;
> + int retries = 20;
> + int pair, ret;
> +
> + *finished = false;
> +
> + /* Try harder if link partner is active */
> + while (pair_mask && retries--) {
> + for_each_set_bit(pair, &pair_mask, 4) {
> + ret = ksz886x_cable_test_one_pair(phydev, pair);
> + if (ret == -EAGAIN)
> + continue;
> + if (ret < 0)
> + return ret;
> + clear_bit(pair, &pair_mask);
> + }
> + /* If link partner is in autonegotiation mode it will send 2ms
> + * of FLPs with at least 6ms of silence.
> + * Add 2ms sleep to have better chances to hit this silence.
> + */
> + if (pair_mask)
> + msleep(2);
> + }
> +
> + *finished = true;
> +
> + return 0;

If ksz886x_cable_test_one_pair() returns -EAGAIN 20x and it gives up,
you end up returning 0. Maybe it would be better to return ret?

Andrew