Module Name:    src
Committed By:   lloyd
Date:           Tue Oct 15 00:58:15 UTC 2024

Modified Files:
        src/sys/arch/arm/xilinx: zynq_cemac.c
        src/sys/dev/cadence: if_cemac.c if_cemacvar.h

Log Message:
Allow non-Realtek PHYs to be used with Zynq SoCs.

The cemac driver used to skip the first PHY found in order to work
around a bug where Realtek PHYs attached to a cemac Ethernet would
report at PHY numbers 0 and 1. Unfortunately if you don't have this
bug, then your only PHY would get skipped.

The Zynq FDT always has a working PHY number recorded in it, so we now
simply use that number (if present) instead of searching for all
available PHYs.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/xilinx/zynq_cemac.c
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/cadence/if_cemac.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/cadence/if_cemacvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/xilinx/zynq_cemac.c
diff -u src/sys/arch/arm/xilinx/zynq_cemac.c:1.9 src/sys/arch/arm/xilinx/zynq_cemac.c:1.10
--- src/sys/arch/arm/xilinx/zynq_cemac.c:1.9	Sun Aug 25 07:25:00 2024
+++ src/sys/arch/arm/xilinx/zynq_cemac.c	Tue Oct 15 00:58:15 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: zynq_cemac.c,v 1.9 2024/08/25 07:25:00 skrll Exp $	*/
+/*	$NetBSD: zynq_cemac.c,v 1.10 2024/10/15 00:58:15 lloyd Exp $	*/
 /*-
  * Copyright (c) 2015  Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi for Genetec Corporation.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: zynq_cemac.c,v 1.9 2024/08/25 07:25:00 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: zynq_cemac.c,v 1.10 2024/10/15 00:58:15 lloyd Exp $");
 
 #include <sys/param.h>
 
@@ -38,16 +38,39 @@ __KERNEL_RCSID(0, "$NetBSD: zynq_cemac.c
 
 #include <dev/cadence/if_cemacvar.h>
 
+#include <net/if.h>
+#include <net/if_media.h>
 #include <net/if_ether.h>
 
 #include <dev/fdt/fdtvar.h>
 
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+
 static const struct device_compatible_entry compat_data[] = {
 	{ .compat = "cdns,zynq-gem" },
 	DEVICE_COMPAT_EOL
 };
 
 static int
+cemac_get_phyid(const int phandle)
+{
+	bus_addr_t addr;
+	int phy_phandle;
+
+	phy_phandle = fdtbus_get_phandle(phandle, "phy");
+	if (phy_phandle == -1)
+		phy_phandle = fdtbus_get_phandle(phandle, "phy-handle");
+	if (phy_phandle == -1)
+		return MII_PHY_ANY;
+
+	if (fdtbus_get_reg(phy_phandle, 0, &addr, NULL) != 0)
+		return MII_PHY_ANY;
+
+	return (int)addr;
+}
+
+static int
 cemac_match(device_t parent, cfdata_t cfdata, void *aux)
 {
 	struct fdt_attach_args * const faa = aux;
@@ -100,6 +123,7 @@ cemac_attach(device_t parent, device_t s
 	sc->sc_dev = self;
 	sc->sc_iot = faa->faa_bst;
 	sc->sc_dmat = faa->faa_dmat;
+	sc->sc_phyno = cemac_get_phyid(phandle);
 	sc->cemac_flags = CEMAC_FLAG_GEM;
 
 	cemac_attach_common(sc);

Index: src/sys/dev/cadence/if_cemac.c
diff -u src/sys/dev/cadence/if_cemac.c:1.44 src/sys/dev/cadence/if_cemac.c:1.45
--- src/sys/dev/cadence/if_cemac.c:1.44	Sun Oct  6 19:18:20 2024
+++ src/sys/dev/cadence/if_cemac.c	Tue Oct 15 00:58:15 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_cemac.c,v 1.44 2024/10/06 19:18:20 skrll Exp $	*/
+/*	$NetBSD: if_cemac.c,v 1.45 2024/10/15 00:58:15 lloyd Exp $	*/
 
 /*
  * Copyright (c) 2015  Genetec Corporation.  All rights reserved.
@@ -48,7 +48,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cemac.c,v 1.44 2024/10/06 19:18:20 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cemac.c,v 1.45 2024/10/15 00:58:15 lloyd Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -624,7 +624,7 @@ cemac_init(struct cemac_softc *sc)
 	mii->mii_statchg = 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);
 
 #if 0

Index: src/sys/dev/cadence/if_cemacvar.h
diff -u src/sys/dev/cadence/if_cemacvar.h:1.6 src/sys/dev/cadence/if_cemacvar.h:1.7
--- src/sys/dev/cadence/if_cemacvar.h:1.6	Sat Oct  5 07:37:22 2024
+++ src/sys/dev/cadence/if_cemacvar.h	Tue Oct 15 00:58:15 2024
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_cemacvar.h,v 1.6 2024/10/05 07:37:22 skrll Exp $	*/
+/*      $NetBSD: if_cemacvar.h,v 1.7 2024/10/15 00:58:15 lloyd Exp $	*/
 /*-
  * Copyright (c) 2015  Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi for Genetec Corporation.
@@ -51,6 +51,7 @@ struct cemac_softc {
 	uint8_t			sc_enaddr[ETHER_ADDR_LEN];
 	struct ethercom		sc_ethercom;
 	mii_data_t		sc_mii;
+	int			sc_phyno;
 
 	void			*rbqpage;
 	unsigned		rbqlen;

Reply via email to