NetBSD Problem Report #58083
From www@netbsd.org Wed Mar 27 01:10:53 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 2597D1A9239
for <gnats-bugs@gnats.NetBSD.org>; Wed, 27 Mar 2024 01:10:53 +0000 (UTC)
Message-Id: <20240327011051.8EECC1A923B@mollari.NetBSD.org>
Date: Wed, 27 Mar 2024 01:10:51 +0000 (UTC)
From: lloyd@must-have-coffee.gen.nz
Reply-To: lloyd@must-have-coffee.gen.nz
To: gnats-bugs@NetBSD.org
Subject: Ethernet not attached correctly on non-Zybo Zynq boards
X-Send-Pr-Version: www-1.0
>Number: 58083
>Category: kern
>Synopsis: Ethernet not attached correctly on non-Zybo Zynq boards
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: thorpej
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Mar 27 01:15:00 +0000 2024
>Last-Modified: Mon Apr 01 00:19:16 +0000 2024
>Originator: Lloyd Parkes
>Release: current @ Sun Mar 24 16:06:37 2024 +0000
>Organization:
Must Have Coffee
>Environment:
NetBSD armv7 10.99.10 NetBSD 10.99.10 (GENERIC) #0: Tue Mar 26 13:22:55 NZDT 2024 lloyd@kudzu.must-have-coffee.gen.nz:/vol/build/zybo/objdir.evbearmv7hf-el/sys/arch/evbarm/compile/GENERIC evbarm
>Description:
The cemac ethernet driver ignores the first PHY it detects because on Zybo boards the Realtek PHY responds at address 0 (incorrectly) as well as address 1 (correctly).
Unfortunately this means that the cemac ethernet driver will ignore any PHY that correctly responds on only one address.
>How-To-Repeat:
Boot NetBSD on an ALINX AX7021B, which is a Zynq 7020 based board with Micrel PHYs instead of Realtek ones.
Type "ifconfig -m cemac0" and note that no PHY appears to be present.
>Fix:
Apply the patch at https://www.must-have-coffee.gen.nz/lloyd/zybo2.diff.
This patch adds support for the appropriate FDT bindings to the PHY code in the cemac driver and then specifies the correct PHY address in the Zynq Zybo device tree files.
Thanks to Jared McNeill for pointing me at example code for this.
>Release-Note:
>Audit-Trail:
From: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58083: Ethernet not attached correctly on non-Zybo Zynq
boards
Date: Wed, 27 Mar 2024 14:17:46 +1300
Here is an inline and probably whitespace mangled copy of the patch
that is on my web site. It'll be easier to read here (hopefully).
diff -r fb03cabe610d sys/arch/arm/dts/zynq-zybo-z7.dts
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/dts/zynq-zybo-z7.dts Wed Mar 27 13:48:52 2024 +1300
@@ -0,0 +1,41 @@
+/* $NetBSD$ */
+
+/*
+ * Copyright (c) 2024 Lloyd Parkes
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
copyright
+ * notice, this list of conditions and the following disclaimer in
the
+ * documentation and/or other materials provided with the
distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "../../../external/gpl2/dts/dist/arch/arm/boot/dts/zynq-zybo-
z7.dts"
+
+/ {
+ chosen {
+ bootargs =3D "root=3Dld0a";
+ };
+};
+
+/* A bug causes this PHY to appear at IDs 0 and 1. */
+/* We only want the official ID of 1. */
+ðernet_phy {
+ reg =3D <1>;
+ device_type =3D "ethernet-phy";
+};
diff -r fb03cabe610d sys/arch/arm/dts/zynq-zybo.dts
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/dts/zynq-zybo.dts Wed Mar 27 13:48:52 2024 +1300
@@ -0,0 +1,41 @@
+/* $NetBSD$ */
+
+/*
+ * Copyright (c) 2024 Lloyd Parkes
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
copyright
+ * notice, this list of conditions and the following disclaimer in
the
+ * documentation and/or other materials provided with the
distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "../../../external/gpl2/dts/dist/arch/arm/boot/dts/zynq-
zybo.dts"
+
+/ {
+ chosen {
+ bootargs =3D "root=3Dld0a";
+ };
+};
+
+/* A bug causes this PHY to appear at IDs 0 and 1. */
+/* We only want the official ID of 1. */
+ðernet_phy {
+ reg =3D <1>;
+ device_type =3D "ethernet-phy";
+};
diff -r fb03cabe610d sys/arch/arm/xilinx/zynq_cemac.c
--- a/sys/arch/arm/xilinx/zynq_cemac.c Sun Mar 24 16:06:37 2024 +0000
+++ b/sys/arch/arm/xilinx/zynq_cemac.c Wed Mar 27 13:48:52 2024 +1300
@@ -41,15 +41,38 @@
#include <dev/cadence/cemacreg.h>
#include <dev/cadence/if_cemacvar.h>
=20
+#include <net/if.h>
+#include <net/if_media.h>
#include <net/if_ether.h>
=20
#include <dev/fdt/fdtvar.h>
=20
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+
static const struct device_compatible_entry compat_data[] =3D {
{ .compat =3D "cdns,zynq-gem" },
DEVICE_COMPAT_EOL
};
=20
+static int
+cemac_get_phyid(const int phandle)
+{
+ bus_addr_t addr;
+ int phy_phandle;
+
+ phy_phandle =3D fdtbus_get_phandle(phandle, "phy");
+ if (phy_phandle =3D=3D -1)
+ phy_phandle =3D fdtbus_get_phandle(phandle, "phy-
handle");
+ if (phy_phandle =3D=3D -1)
+ return MII_PHY_ANY;
+
+ if (fdtbus_get_reg(phy_phandle, 0, &addr, NULL) !=3D 0)
+ return MII_PHY_ANY;
+
+ return (int)addr;
+}
+
int
cemac_match(device_t parent, cfdata_t cfdata, void *aux)
{
@@ -70,6 +93,7 @@
bus_addr_t addr;
bus_size_t size;
int error, len;
+ int phyno;
=20
if (fdtbus_get_reg(phandle, 0, &addr, &size) !=3D 0) {
aprint_error(": couldn't get registers\n");
@@ -99,7 +123,9 @@
prop_dictionary_set_data(prop, "mac-address", macaddr,
len);
}
=20
- cemac_attach_common(self, faa->faa_bst, ioh, faa->faa_dmat,
CEMAC_FLAG_GEM);
+ phyno =3D cemac_get_phyid(phandle);
+
+ cemac_attach_common(self, faa->faa_bst, ioh, faa->faa_dmat,
phyno, CEMAC_FLAG_GEM);
aprint_normal_dev(self, "interrupting on %s\n", intrstr);
}
=20
diff -r fb03cabe610d sys/dev/cadence/if_cemac.c
--- a/sys/dev/cadence/if_cemac.c Sun Mar 24 16:06:37 2024 +0000
+++ b/sys/dev/cadence/if_cemac.c Wed Mar 27 13:48:52 2024 +1300
@@ -109,6 +109,7 @@
uint8_t sc_enaddr[ETHER_ADDR_LEN];
struct ethercom sc_ethercom;
mii_data_t sc_mii;
+ int sc_phyno;
=20
void *rbqpage;
unsigned rbqlen;
@@ -166,7 +167,8 @@
=20
void
cemac_attach_common(device_t self, bus_space_tag_t iot,
- bus_space_handle_t ioh, bus_dma_tag_t dmat, int flags)
+ bus_space_handle_t ioh, bus_dma_tag_t dmat, int
phyno,
+ int flags)
{
struct cemac_softc *sc =3D device_private(self);
prop_data_t enaddr;
@@ -177,6 +179,7 @@
sc->sc_ioh =3D ioh;
sc->sc_iot =3D iot;
sc->sc_dmat =3D dmat;
+ sc->sc_phyno =3D phyno;
sc->cemac_flags =3D flags;
=20
aprint_naive("\n");
@@ -579,7 +582,7 @@
mii->mii_statchg =3D cemac_statchg;
ifmedia_init(&mii->mii_media, IFM_IMASK, cemac_mediachange,
cemac_mediastatus);
- mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY, 1, 0);
+ mii_attach(sc->sc_dev, mii, 0xffffffff, sc->sc_phyno,
MII_OFFSET_ANY, 0);
ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
=20
#if 0
diff -r fb03cabe610d sys/dev/cadence/if_cemacvar.h
--- a/sys/dev/cadence/if_cemacvar.h Sun Mar 24 16:06:37 2024 +0000
+++ b/sys/dev/cadence/if_cemacvar.h Wed Mar 27 13:48:52 2024 +1300
@@ -34,7 +34,7 @@
=20
int cemac_match_common(device_t, cfdata_t, void *);
void cemac_attach_common(device_t, bus_space_tag_t,
bus_space_handle_t,
- bus_dma_tag_t, int);
+ bus_dma_tag_t, int, int);
=20
#define CEMAC_FLAG_GEM 0x0001
=20
Responsible-Changed-From-To: kern-bug-people->thorpej
Responsible-Changed-By: thorpej@NetBSD.org
Responsible-Changed-When: Mon, 01 Apr 2024 00:19:16 +0000
Responsible-Changed-Why:
Grab.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.