[PATCH v5 1/2] net: brcm: netXtreme driver

Marek Behún kabel at kernel.org
Tue Nov 2 13:07:00 CET 2021


On Mon,  1 Nov 2021 13:21:44 -0700
Roman Bacik <roman.bacik at broadcom.com> wrote:

> +static int set_phy_speed(struct bnxt *bp)
> +{
> +	char name[20];
> +	char name1[30];
> +	u16 flag = PHY_STATUS | PHY_SPEED | DETECT_MEDIA;
> +
> +	/* Query Link Status */
> +	if (bnxt_hwrm_port_phy_qcfg(bp, flag) != STATUS_SUCCESS)
> +		return STATUS_FAILURE;
> +
> +	switch (bp->current_link_speed) {
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_100GB:
> +		sprintf(name, "%s %s", str_100, str_gbps);
> +		break;
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_50GB:
> +		sprintf(name, "%s %s", str_50, str_gbps);
> +		break;
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_40GB:
> +		sprintf(name, "%s %s", str_40, str_gbps);
> +		break;
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_25GB:
> +		sprintf(name, "%s %s", str_25, str_gbps);
> +		break;
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_20GB:
> +		sprintf(name, "%s %s", str_20, str_gbps);
> +		break;
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_10GB:
> +		sprintf(name, "%s %s", str_10, str_gbps);
> +		break;
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_2_5GB:
> +		sprintf(name, "%s %s", str_2_5, str_gbps);
> +		break;
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_2GB:
> +		sprintf(name, "%s %s", str_2, str_gbps);
> +		break;
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_1GB:
> +		sprintf(name, "%s %s", str_1, str_gbps);
> +		break;
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_100MB:
> +		sprintf(name, "%s %s", str_100, str_mbps);
> +		break;
> +	case PORT_PHY_QCFG_RESP_LINK_SPEED_10MB:
> +		sprintf(name, "%s %s", str_10, str_mbps);
> +		break;
> +	default:
> +		sprintf(name, "%s %x", str_unknown, bp->current_link_speed);
> +	}
> +
> +	sprintf(name1, "bnxt_eth%u_phy_speed", bp->cardnum);
> +	env_set(name1, name);
> +	dbg_phy_speed(bp, name);
> +
> +	return STATUS_SUCCESS;
> +}
> +
> +static int set_phy_link(struct bnxt *bp, u32 tmo)
> +{
> +	char name[32];
> +	int ret;
> +
> +	set_phy_speed(bp);
> +	dbg_link_status(bp);
> +	if (bp->link_status == STATUS_LINK_ACTIVE) {
> +		dbg_link_state(bp, tmo);
> +		sprintf(name, "bnxt_eth%u_link", bp->cardnum);
> +		env_set(name, "up");
> +		sprintf(name, "bnxt_eth%u_media", bp->cardnum);
> +		env_set(name, "connected");
> +		ret = STATUS_SUCCESS;
> +	} else {
> +		sprintf(name, "bnxt_eth%u_link", bp->cardnum);
> +		env_set(name, "down");
> +		sprintf(name, "bnxt_eth%u_media", bp->cardnum);
> +		env_set(name, "disconnected");
> +		ret = STATUS_FAILURE;
> +	}
> +
> +	return ret;
> +}

Hi Roman,

your proposal still contains non-standard and unneeded setting of
environment variables. An ethernet driver should never do this. In fact
no driver besides board code or sysinfo driver should do this directly.

There are other mechanisms for reporting PHY connection information in
U-Boot, please use those if you need them (e.g. implement a PHY
driver), but remove all env_set() calls from your ethernet driver.

Rationale: historically, many times things were solved with ad-hoc code
in U-Boot, which did this kind of thing and similar. It got out of hand
pretty fast, and it was horrible. So some people dedided to fix it,
proposing APIs, unifying code, deduplicating code and so on. This is
still, in fact, going on. For your driver to have it's own mechanism
for reporting link status, by setting env variables, is going against
this whole work.

I suggest for now just to remove these calls. When the driver is
merged, we can work on extending support for passing link information
to U-Boot via ethernet PHY API, if you need it.

Marek


More information about the U-Boot mailing list