From nobody Sat Nov 6 08:11:32 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 E1A1E18346F2; Sat, 6 Nov 2021 08:11:33 +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 4HmVT05rQFz3QCC; Sat, 6 Nov 2021 08:11:32 +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 5E85827B99; Sat, 6 Nov 2021 08:11:32 +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 1A68BWV8041143; Sat, 6 Nov 2021 08:11:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A68BWQD041142; Sat, 6 Nov 2021 08:11:32 GMT (envelope-from git) Date: Sat, 6 Nov 2021 08:11:32 GMT Message-Id: <202111060811.1A68BWQD041142@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: 4b843e7f0319 - main - mii_fdt: Add support for switch PHY node lookup 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: 4b843e7f0319867c412070e7752dbb47f195b322 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=4b843e7f0319867c412070e7752dbb47f195b322 commit 4b843e7f0319867c412070e7752dbb47f195b322 Author: Kornel Duleba AuthorDate: 2021-10-27 08:34:17 +0000 Commit: Wojciech Macek CommitDate: 2021-11-06 08:08:45 +0000 mii_fdt: Add support for switch PHY node lookup Previously we would only search for a PHY xref in node of the miibus parent. That didn't work very well with switches. Fix that by searching through "ports" subnode, checking if any of its children have a valid PHY xref. Since switches tend to have multiple ports we also have multiple candidates. Use the PHY address read from mii_attach_args to find the right one. Obtained from: Semihalf Sponsored by: Alstom Group Reviewed by: mw Differential revision: https://reviews.freebsd.org/D32690 --- sys/dev/mii/mii_fdt.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/sys/dev/mii/mii_fdt.c b/sys/dev/mii/mii_fdt.c index 009a523e32ce..18ed9c8e749c 100644 --- a/sys/dev/mii/mii_fdt.c +++ b/sys/dev/mii/mii_fdt.c @@ -99,6 +99,44 @@ mii_fdt_get_phynode(phandle_t macnode) return (-1); } +static phandle_t +mii_fdt_lookup_phy(phandle_t node, int addr) +{ + phandle_t ports, phynode, child; + int reg; + + /* First try to see if we have a direct xref pointing to a PHY. */ + phynode = mii_fdt_get_phynode(node); + if (phynode != -1) + return (phynode); + + /* + * Now handle the "switch" case. + * Search "ports" subnode for nodes that describe a switch port + * including a PHY xref. + * Since we have multiple candidates select one based on PHY address. + */ + ports = ofw_bus_find_child(node, "ports"); + if (ports <= 0) + return (-1); + + for (child = OF_child(ports); child != 0; child = OF_peer(child)) { + if (ofw_bus_node_status_okay(child) == 0) + continue; + + phynode = mii_fdt_get_phynode(child); + if (phynode <= 0) + continue; + + if (OF_getencprop(phynode, "reg", ®, sizeof(reg)) <= 0) + continue; + + if (reg == addr) + return (phynode); + } + return (-1); +} + mii_contype_t mii_fdt_contype_from_name(const char *name) { @@ -145,10 +183,12 @@ mii_fdt_free_config(struct mii_fdt_phy_config *cfg) mii_fdt_phy_config_t * mii_fdt_get_config(device_t phydev) { + struct mii_attach_args *ma; mii_fdt_phy_config_t *cfg; device_t miibus, macdev; pcell_t val; + ma = device_get_ivars(phydev); miibus = device_get_parent(phydev); macdev = device_get_parent(miibus); @@ -167,7 +207,8 @@ mii_fdt_get_config(device_t phydev) * If we can't find our own PHY node, there's nothing more we can fill * in, just return what we've got. */ - if ((cfg->phynode = mii_fdt_get_phynode(cfg->macnode)) == -1) + cfg->phynode = mii_fdt_lookup_phy(cfg->macnode, ma->mii_phyno); + if (cfg->phynode == -1) return (cfg); if (OF_getencprop(cfg->phynode, "max-speed", &val, sizeof(val)) > 0)