From nobody Tue Mar 29 22:59:59 2022 X-Original-To: dev-commits-src-branches@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 BB2A31A34B1C; Tue, 29 Mar 2022 23:00:00 +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 4KSlQ82CpPz4TdW; Tue, 29 Mar 2022 23:00:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648594800; 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=cr34nL3W5PnAZ6+fsT+i6QeaqTyWBd27/CjibPHoAyA=; b=qQSDFRm6l8KE2fW399xGw+/0e3K3ALPt0nBASXzyadCk9Z39UPB6UGtqW6EcoeD6PJpwpr 1L8u/XMGsESCte1N7mv5A/gKAfRI5Qv10wB/Gk8iTjaNiaMVH+EoiO4dlcrJi71viJNGDr Su17NSq9PT+ziV7eVbLcuWHntnPNTX6S9nxd4fbvZrNAAm3LcrU5HxnJAzbVDb75kCjGaH 7Fe+bB/KLigjCY6edydphJfN+gNJmLoqdvjtj+kyiijmMBgYikRwY6WLJTuknkSkFnUqvN ZcpE9W7JHzqnXKSHlxy/daZfGZySGRFb2/eGOPellpaFZ/gztTVBxsD4yCVlqw== 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 3AD5A27902; Tue, 29 Mar 2022 22:59:59 +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 22TMxxSE049971; Tue, 29 Mar 2022 22:59:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22TMxxYk049970; Tue, 29 Mar 2022 22:59:59 GMT (envelope-from git) Date: Tue, 29 Mar 2022 22:59:59 GMT Message-Id: <202203292259.22TMxxYk049970@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Marcin Wojtas Subject: git: b329bb8fd7b6 - stable/13 - mii_fdt: Add support for switch PHY node lookup List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mw X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b329bb8fd7b64e85243b1a90c388ed5c332ea812 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648594800; 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=cr34nL3W5PnAZ6+fsT+i6QeaqTyWBd27/CjibPHoAyA=; b=m9ckdVyfKwXFOB7QcAttmNPBp5N1KP7Di+tWVrZCqDG0T5klHCtl6T9rHiGF3p3zm4f35B blJfH/16l5zV8L1T44DFGUfAjIlU16n1dCa87Qxy3K0nHm2HWNI+/tAl7yNruPJrD7HO1E 5W+j7QfNA1Tv82QbcUXXiE8jeLVwkoF4A1cwOdWmY4LmpllmsADiZ12NFtAHIa26psqGFV UAXOcg9ddhq6RmqwUaSCgvl0t4taNV0uwKr3fpCDsd71qmT08NxzUxsidkNJuAnoXFvbf7 8unLJbsGx94KSKxVxq1A881GKwmJcPmQIN7TMNS4/rtyfGFERcR/A23d0HFoXQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648594800; a=rsa-sha256; cv=none; b=MMUhCtt5BGPBvk6imGVKHyaxdT0O/uRT5nfJ7Vny4SMBEDqJqfwpzaw/Gjvb4hqCGCk4Or SEZklZlBJ0ChoB/8Lgg68zXPueevMi0r7DWRYfxNoIAR/UOKcL54HuzaD0IPs/TQc6wzQI aztVX5qL2ZTjFrR60AKO/Hp/zlnrRcqkNWWHtIgEsIVdap7V801Yu6L8ZpYbYYO+KSS45k W/67quKJV4bHs7JtxvAf5D/iLAtkqkroo3oXhsWtylFTfneyOWJwpPLNInORebXgxrguFM r15E/SCKbJ2Qw0sdsNMq29DKfq3JHQUU7RVvHUh9BQviZFTRrBTk9lvfkTXrzQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=b329bb8fd7b64e85243b1a90c388ed5c332ea812 commit b329bb8fd7b64e85243b1a90c388ed5c332ea812 Author: Kornel Duleba AuthorDate: 2021-10-27 08:34:17 +0000 Commit: Marcin Wojtas CommitDate: 2022-03-29 22:24:27 +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 (cherry picked from commit 4b843e7f0319867c412070e7752dbb47f195b322) --- 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)