Port-arm archive

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

Zynq ethernet PHY numbers - revised



Kia ora koutou,
I've finally got back to poking at my Zybo again and I was about to
commit my previous patch for fixing up the attachment of Realtek PHYs
to the cemac driver when I found that the patch would no longer apply
cleanly. The driver was made MPSAFE while I was distracted.

The following is a revised version of my patch. Like my previous patch
it replaces the use of an MII offset with the use of an explicit PHY
number extracted from the FDT. 

Unlike my previous patch I no longer create custom DTBs for the Zybo
boards with a "correct" PHY number of 1. It doesn't seem to be a useful
change, I can only test two of a dozen or so Zynq DTS files like this,
and the "wrong" number works fine.

Once someone has reviewed this, I'll get it committed. 

Ngā mihi,
Lloyd


Index: sys/arch/arm/xilinx/zynq_cemac.c
===================================================================
RCS file: /home/lloyd/NetBSD/cvs/mirror/src/sys/arch/arm/xilinx/zynq_cemac.c,v
retrieving revision 1.9
diff -u -r1.9 zynq_cemac.c
--- sys/arch/arm/xilinx/zynq_cemac.c	25 Aug 2024 07:25:00 -0000	1.9
+++ sys/arch/arm/xilinx/zynq_cemac.c	13 Oct 2024 01:57:18 -0000
@@ -38,16 +38,39 @@
 
 #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 @@
 	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: sys/dev/cadence/if_cemac.c
===================================================================
RCS file: /home/lloyd/NetBSD/cvs/mirror/src/sys/dev/cadence/if_cemac.c,v
retrieving revision 1.44
diff -u -r1.44 if_cemac.c
--- sys/dev/cadence/if_cemac.c	6 Oct 2024 19:18:20 -0000	1.44
+++ sys/dev/cadence/if_cemac.c	13 Oct 2024 01:51:06 -0000
@@ -624,7 +624,7 @@
 	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: sys/dev/cadence/if_cemacvar.h
===================================================================
RCS file: /home/lloyd/NetBSD/cvs/mirror/src/sys/dev/cadence/if_cemacvar.h,v
retrieving revision 1.6
diff -u -r1.6 if_cemacvar.h
--- sys/dev/cadence/if_cemacvar.h	5 Oct 2024 07:37:22 -0000	1.6
+++ sys/dev/cadence/if_cemacvar.h	13 Oct 2024 02:02:15 -0000
@@ -51,6 +51,7 @@
 	uint8_t			sc_enaddr[ETHER_ADDR_LEN];
 	struct ethercom		sc_ethercom;
 	mii_data_t		sc_mii;
+	int			sc_phyno;
 
 	void			*rbqpage;
 	unsigned		rbqlen;


Home | Main Index | Thread Index | Old Index