From nobody Wed Nov 24 06:41:48 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id DE28218AB5F1; Wed, 24 Nov 2021 06:41:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HzWd84XxBz4kdD; Wed, 24 Nov 2021 06:41:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7C6D725586; Wed, 24 Nov 2021 06:41:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AO6fmFB036999; Wed, 24 Nov 2021 06:41:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AO6fmuH036998; Wed, 24 Nov 2021 06:41:48 GMT (envelope-from git) Date: Wed, 24 Nov 2021 06:41:48 GMT Message-Id: <202111240641.1AO6fmuH036998@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wojciech Macek Subject: git: b38de28a77f4 - main - mii_physubr: Add support for limiting PHY max speed List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b38de28a77f4d368e0a477e55cb44272359ae9c9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637736108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=D6NZh0IFry+zQ04/ai+pc3F5N0qPjg7jJEwD4DDRfEQ=; b=pegoT7efognxPag6ZE36jS5Oax+rHFbMmZ3DBO7br2H8aClGU3TjHlGfpk7XBvXrf77R9H 0dMRNFKP5/pcPH8nhAwTn/lZN+lHTXCVVar1BOZZuTno8mE+bMu4xUumYHYSVLw/kS5HE9 HL7/dhtqCjZQY9qvJGbAWtaNS8HH77Krweihbkh4nAfujm8jzxdEC/fC0SFsdR+XyWSQVn PLIEEWtAdsWXgBibcTQNfFxw144eePC03PXnkaiVizq8r3lrQAEB7Ir7IzZv7QFso67p5f 40pK8ZV42DoPM1PRiIZ9XJBkunbpBwSkStZxeYeAs4f65P+I+GMvkB8PNclnEw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637736108; a=rsa-sha256; cv=none; b=TAOVQMYm7O+XnE93OQNMEn5lg4ilCJN7oLQZeKasLgOn/rs9X4w5ey2dlIQSpZHtoyE9mV K+ZFxOGqmqbxQfx9VvOiy/gfYYyc+KqYO99AOmT5uDjFgixCa7rsBERTAlPZojPFXaQCAi c/Dk8jMD8R2UmjdO1neVUO4dmsNOoRR/c5sFm+XomDDTYh6qePhAFqKGG8wN1EdBZbf2lU eUPalRvz6Si46TpgVLWlsR0Ccg1c+GAL8HaRcU9I3vmeyQS7Kez7ajuC9FIEa331cZJR0L haM2pAgKrxIh+M1QU14yVHcG2WdQy12GOMlenhxDut0Sblg4TBRU97Lxor5RAg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=b38de28a77f4d368e0a477e55cb44272359ae9c9 commit b38de28a77f4d368e0a477e55cb44272359ae9c9 Author: Kornel Duleba AuthorDate: 2021-11-15 08:49:27 +0000 Commit: Wojciech Macek CommitDate: 2021-11-24 06:40:35 +0000 mii_physubr: Add support for limiting PHY max speed In some cases we might want to limit the max speed advertised below of what the PHY is capable of. This is usually the case when we connect 1G capable PHY to 100M MAC, or when some exotic physical connection is used. Add a new mii_maxspeed field to mii_softc and parse it in mii_phy_dev_attach. Speed limit is normally located in DT. The property is already parsed in mii_fdt.c, but its value still has to be passed by the PHY driver. Obtained from: Semihalf Sponsored by: Alstom Group Differential revision: https://reviews.freebsd.org/D32727 --- sys/dev/mii/mii_physubr.c | 36 ++++++++++++++++++++++++++++++++++++ sys/dev/mii/miivar.h | 1 + 2 files changed, 37 insertions(+) diff --git a/sys/dev/mii/mii_physubr.c b/sys/dev/mii/mii_physubr.c index f56676d4e091..4ddb7d621652 100644 --- a/sys/dev/mii/mii_physubr.c +++ b/sys/dev/mii/mii_physubr.c @@ -618,11 +618,47 @@ mii_phy_dev_attach(device_t dev, u_int flags, const struct mii_phy_funcs *mpf, sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask; if (sc->mii_capabilities & BMSR_EXTSTAT) sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR); + + switch (sc->mii_maxspeed) { + case 100: + /* + * This is a bit tricky. + * If we have a 1G capable PHY, but we don't want to advertise + * 1G capabilities we need to clear the GTCR register before + * doing autonegotiation. + * Clearing the register here is not enough since its value + * can be restored after PHY_RESET is called. + */ + if ((sc->mii_extcapabilities & + (EXTSR_1000THDX | EXTSR_1000TFDX)) != 0) + sc->mii_flags |= MIIF_HAVE_GTCR; + + sc->mii_extcapabilities = 0; + break; + default: + device_printf(dev, + "Ignoring unsupported max speed value of %d\n", + sc->mii_maxspeed); + case 0: + case 1000: + break; + } device_printf(dev, " "); mii_phy_add_media(sc); printf("\n"); MIIBUS_MEDIAINIT(sc->mii_dev); + + /* + * If maxspeed was specified we have to restart autonegotiation. + * PHY might have attempted it and failed due to having mistakenly + * advertising modes that we do not in fact support. + */ + if (sc->mii_maxspeed != 0) { + sc->mii_flags |= MIIF_FORCEANEG; + mii_phy_setmedia(sc); + sc->mii_flags &= ~MIIF_FORCEANEG; + } } /* diff --git a/sys/dev/mii/miivar.h b/sys/dev/mii/miivar.h index 4658394797e9..cf8032f1eb53 100644 --- a/sys/dev/mii/miivar.h +++ b/sys/dev/mii/miivar.h @@ -117,6 +117,7 @@ struct mii_softc { u_int mii_anegticks; /* ticks before retrying aneg */ u_int mii_media_active; /* last active media */ u_int mii_media_status; /* last active status */ + u_int mii_maxspeed; /* Max speed supported by this PHY */ }; typedef struct mii_softc mii_softc_t;