<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 28, 2023 at 11:57 PM Padmarao Begari <<a href="mailto:padmarao.begari@microchip.com">padmarao.begari@microchip.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Read the phy address from the device tree and use it to<br>
find the phy device if not found then search in the<br>
range of 0 to 31.<br>
---<br>
freebsd/sys/dev/cadence/if_cgem.c | 41 ++++++++++++++++++++++++++++---<br>
1 file changed, 37 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/freebsd/sys/dev/cadence/if_cgem.c b/freebsd/sys/dev/cadence/if_cgem.c<br>
index 689c3611..2888a085 100644<br>
--- a/freebsd/sys/dev/cadence/if_cgem.c<br>
+++ b/freebsd/sys/dev/cadence/if_cgem.c<br>
@@ -1217,6 +1217,27 @@ cgem_intr(void *arg)<br>
CGEM_UNLOCK(sc);<br>
}<br>
<br>
+static int<br>
+cgem_get_phyaddr(phandle_t node, int *phy_addr)<br>
+{<br>
+ phandle_t phy_node;<br>
+ pcell_t phy_handle, phy_reg;<br>
+<br>
+ if (OF_getencprop(node, "phy-handle", (void *)&phy_handle,<br>
+ sizeof(phy_handle)) <= 0)<br>
+ return (ENXIO);<br>
+<br>
+ phy_node = OF_node_from_xref(phy_handle);<br>
+<br>
+ if (OF_getencprop(phy_node, "reg", (void *)&phy_reg,<br>
+ sizeof(phy_reg)) <= 0)<br>
+ return (ENXIO);<br>
+<br>
+ *phy_addr = phy_reg;<br>
+<br>
+ return (0);<br>
+}<br>
+<br></blockquote><div>All changes should be gated behind #ifdef __rtems__, even if they're backports from upstream.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
/* Reset hardware. */<br>
static void<br>
cgem_reset(struct cgem_softc *sc)<br>
@@ -2003,6 +2024,7 @@ cgem_attach(device_t dev)<br>
pcell_t cell;<br>
int rid, err;<br>
u_char eaddr[ETHER_ADDR_LEN];<br>
+ int phy_addr;<br></blockquote><div>Same here.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
sc->dev = dev;<br>
CGEM_LOCK_INIT(sc);<br>
@@ -2091,10 +2113,21 @@ cgem_attach(device_t dev)<br>
cgem_reset(sc);<br>
CGEM_UNLOCK(sc);<br>
<br>
- /* Attach phy to mii bus. */<br>
- err = mii_attach(dev, &sc->miibus, ifp,<br>
- cgem_ifmedia_upd, cgem_ifmedia_sts,<br>
- BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);<br>
+ err = cgem_get_phyaddr(node, &phy_addr);<br>
+ if (err == 0) {<br>
+ /* Attach phy to mii bus. */<br>
+ err = mii_attach(dev, &sc->miibus, ifp,<br>
+ cgem_ifmedia_upd, cgem_ifmedia_sts,<br>
+ BMSR_DEFCAPMASK, phy_addr, MII_OFFSET_ANY, 0);<br>
+ }<br>
+<br>
+ if (err) {<br>
+ /* Attach phy to mii bus. */<br>
+ err = mii_attach(dev, &sc->miibus, ifp,<br>
+ cgem_ifmedia_upd, cgem_ifmedia_sts,<br>
+ BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);<br>
+ }<br>
+<br></blockquote><div>Same here. Also, a simpler implementation would be to have cgem_get_phyaddr return the PHY address or MII_PHY_ANY on error and fold that all into the declaration. That would leave the declaration as:</div><div>#ifdef __rtems__<br></div><div> int phy_addr = cgem_get_phyaddr(node);</div><div>#endif</div><div><br></div><div>and the change here as:<br></div> /* Attach phy to mii bus. */<div>
err = mii_attach(dev, &sc->miibus, ifp,<br>
cgem_ifmedia_upd, cgem_ifmedia_sts,</div><div>#ifdef __rtems__<br></div><div> BMSR_DEFCAPMASK, phy_addr, MII_OFFSET_ANY, 0);</div><div>#else /* __rtems__ */</div><div> BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);</div><div>#endif /* __rtems__ */<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
if (err) {<br>
device_printf(dev, "attaching PHYs failed\n");<br>
cgem_detach(dev);<br>
-- <br>
2.25.1<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div>