NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/58083: Ethernet not attached correctly on non-Zybo Zynq boards



The following reply was made to PR kern/58083; it has been noted by GNATS.

From: Lloyd Parkes <lloyd%must-have-coffee.gen.nz@localhost>
To: gnats-bugs%netbsd.org@localhost
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. */
 +&ethernet_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. */
 +&ethernet_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
 


Home | Main Index | Thread Index | Old Index