From nobody Wed Nov 24 06:41:50 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 44CA218ABA30; Wed, 24 Nov 2021 06:41:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HzWdC1f9Sz4ktj; Wed, 24 Nov 2021 06:41:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BCB2A2552F; Wed, 24 Nov 2021 06:41:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AO6foE9037054; Wed, 24 Nov 2021 06:41:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AO6fo3t037053; Wed, 24 Nov 2021 06:41:50 GMT (envelope-from git) Date: Wed, 24 Nov 2021 06:41:50 GMT Message-Id: <202111240641.1AO6fo3t037053@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wojciech Macek Subject: git: 9174eab4142c - main - miibus: Add support for mapping OFW nodes to PHY devices List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9174eab4142c5ed199b1599c1a3eefd5f0573ab7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637736111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ThCXGixqvxgXP2jdoWDVspRldSaBjLheW0YATnq2fm0=; b=Sz/+YZbKY3Hhuh+TE+Y6JitJzBCvvRqmWeoxjpDTAQSNN56OfT+ohJ3lbsx/77sBjB2cLa 8+LEj7vj4d1+R07xkzvZVPghuNcBus+iFBB3kLa9djq+mLzu97nbD1Ow086rP8XZHxHo6f UK15tAXmLy1N/jjsQchgdMpn8MNo53iXGIMqgMcP+uJLVrRWhkBfWQzFYqtbEKMeFlhacE +qWi1IKpKha09Lbt881GXb8EUrqJ05B2deAloDx1U2XNXnRuMW1Z9nVi3tyipa9DSWS0bo N0dS7LnpV+r0gw/trsc4F2OTvH2Zk6E6WILYK9bWl8SLnGLpa04nS+sJZNDwbw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637736111; a=rsa-sha256; cv=none; b=UIfwhPaW/96NTBF+xAjxK+DTOhrIrggpuJAzAjj/7G3OVJq44Gq6kv9y7bPSS++VZdjNeC 2bDA4ta9xFiGWbNCseeMzFRvGp4Ji4PJg7TpGa3j5OYcPnFyRaP044By7qk+GAqL5Msf+q hk+57aqlK12llsoHcpQLmkNulcaoYQeHWzQfIFsenAiY3/2C4BU9rlnVB1HzJbiLCc3NJH 8SVfNRTthkW75Q/WTUzsCxG4oRWQ2MTKZh2+E2q02v8VhKpj6rhvOEWjJHfb5RRSBisTsR 7YAvF6gG2yVPU0iVC7jwdd+SXoL28sEukaUexrH6zhlmWIqjxSwCQcXosJavXA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=9174eab4142c5ed199b1599c1a3eefd5f0573ab7 commit 9174eab4142c5ed199b1599c1a3eefd5f0573ab7 Author: Kornel Duleba AuthorDate: 2021-11-15 08:55:33 +0000 Commit: Wojciech Macek CommitDate: 2021-11-24 06:40:36 +0000 miibus: Add support for mapping OFW nodes to PHY devices Create a new miibus OFW specific layer leveraging miibus_fdt.c code. PHY drivers can than read the properties using device_get_property(9) API. Resource(interrupt) allocation is also supported. In order to enable this each NIC/switch driver will have to be modified, because of how miibus is attached to the parent driver. Obtained from: Semihalf Sponsored by: Alstom Group Differential revision: https://reviews.freebsd.org/D32812 --- sys/dev/mii/mii.c | 10 +--- sys/dev/mii/mii_fdt.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++ sys/dev/mii/miivar.h | 23 ++++++++- 3 files changed, 155 insertions(+), 9 deletions(-) diff --git a/sys/dev/mii/mii.c b/sys/dev/mii/mii.c index 5163a7456ed0..f5f791171a53 100644 --- a/sys/dev/mii/mii.c +++ b/sys/dev/mii/mii.c @@ -60,7 +60,6 @@ MODULE_VERSION(miibus, 1); #include "miibus_if.h" -static device_attach_t miibus_attach; static bus_child_detached_t miibus_child_detached; static bus_child_location_t miibus_child_location; static bus_child_pnpinfo_t miibus_child_pnpinfo; @@ -103,12 +102,7 @@ static device_method_t miibus_methods[] = { }; devclass_t miibus_devclass; - -driver_t miibus_driver = { - "miibus", - miibus_methods, - sizeof(struct mii_data) -}; +DEFINE_CLASS_0(miibus, miibus_driver, miibus_methods, sizeof(struct mii_data)); struct miibus_ivars { if_t ifp; @@ -127,7 +121,7 @@ miibus_probe(device_t dev) return (BUS_PROBE_SPECIFIC); } -static int +int miibus_attach(device_t dev) { struct miibus_ivars *ivars; diff --git a/sys/dev/mii/mii_fdt.c b/sys/dev/mii/mii_fdt.c index 18ed9c8e749c..387b02f69504 100644 --- a/sys/dev/mii/mii_fdt.c +++ b/sys/dev/mii/mii_fdt.c @@ -239,3 +239,134 @@ mii_fdt_get_config(device_t phydev) return (cfg); } + +static int +miibus_fdt_probe(device_t dev) +{ + device_t parent; + + parent = device_get_parent(dev); + if (ofw_bus_get_node(parent) == -1) + return (ENXIO); + + device_set_desc(dev, "OFW MII bus"); + return (BUS_PROBE_DEFAULT); +} + +static int +miibus_fdt_attach(device_t dev) +{ + struct mii_attach_args *ma; + struct mii_data *sc; + int i, error, nchildren; + device_t parent, *children; + phandle_t phy_node; + + parent = device_get_parent(dev); + sc = device_get_softc(dev); + + error = device_get_children(dev, &children, &nchildren); + if (error != 0 || nchildren == 0) + return (ENXIO); + + for (i = 0; i < nchildren; i++) { + ma = device_get_ivars(children[i]); + bzero(&ma->obd, sizeof(ma->obd)); + phy_node = mii_fdt_lookup_phy(ofw_bus_get_node(parent), + ma->mii_phyno); + if (phy_node == -1) { + device_printf(dev, + "Warning: failed to find OFW node for PHY%d\n", + ma->mii_phyno); + continue; + } + error = ofw_bus_gen_setup_devinfo(&ma->obd, phy_node); + if (error != 0) { + device_printf(dev, + "Warning: failed to setup OFW devinfo for PHY%d\n", + ma->mii_phyno); + continue; + } + /* + * Setup interrupt resources. + * Only a handful of PHYs support those, + * so it's fine if we fail here. + */ + resource_list_init(&ma->rl); + (void)ofw_bus_intr_to_rl(children[i], phy_node, &ma->rl, NULL); + } + + free(children, M_TEMP); + return (miibus_attach(dev)); +} + +static struct resource_list * +miibus_fdt_get_resource_list(device_t bus, device_t child) +{ + struct mii_attach_args *ma; + + ma = device_get_ivars(child); + + if (ma->obd.obd_node == 0) + return (NULL); + + return (&ma->rl); +} + +static const struct ofw_bus_devinfo* +miibus_fdt_get_devinfo(device_t bus, device_t child) +{ + struct mii_attach_args *ma; + + ma = device_get_ivars(child); + + if (ma->obd.obd_node == 0) + return (NULL); + + return (&ma->obd); +} + +static ssize_t +miibus_fdt_get_property(device_t bus, device_t child, const char *propname, + void *buf, size_t size) +{ + struct mii_attach_args *ma; + + ma = device_get_ivars(child); + + if (ma->obd.obd_node == 0) + return (-1); + + return (OF_getencprop(ma->obd.obd_node, propname, buf, size)); +} + +static device_method_t miibus_fdt_methods[] = { + DEVMETHOD(device_probe, miibus_fdt_probe), + DEVMETHOD(device_attach, miibus_fdt_attach), + + /* ofw_bus interface */ + DEVMETHOD(ofw_bus_get_devinfo, miibus_fdt_get_devinfo), + DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat), + DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model), + DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name), + DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), + DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), + + DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), + DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), + DEVMETHOD(bus_release_resource, bus_generic_release_resource), + DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), + DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), + DEVMETHOD(bus_adjust_resource, bus_generic_adjust_resource), + DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource), + DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), + DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource), + DEVMETHOD(bus_get_resource_list, miibus_fdt_get_resource_list), + DEVMETHOD(bus_get_property, miibus_fdt_get_property), + + DEVMETHOD_END +}; + +devclass_t miibus_fdt_devclass; +DEFINE_CLASS_1(miibus, miibus_fdt_driver, miibus_fdt_methods, + sizeof(struct mii_data), miibus_driver); diff --git a/sys/dev/mii/miivar.h b/sys/dev/mii/miivar.h index cf8032f1eb53..95cfb866b5f7 100644 --- a/sys/dev/mii/miivar.h +++ b/sys/dev/mii/miivar.h @@ -40,6 +40,14 @@ #include #include /* XXX driver API temporary */ +#include "opt_platform.h" + +#ifdef FDT +#include +#include +#include +#endif + /* * Media Independent Interface data structure defintions */ @@ -206,6 +214,11 @@ struct mii_attach_args { uint32_t mii_id1; /* PHY ID register 1 */ uint32_t mii_id2; /* PHY ID register 2 */ u_int mii_capmask; /* capability mask for BMSR */ +#ifdef FDT + struct ofw_bus_devinfo obd; + struct resource_list rl; +#endif + }; typedef struct mii_attach_args mii_attach_args_t; @@ -251,7 +264,13 @@ enum miibus_device_ivars { MIIBUS_ACCESSOR(flags, FLAGS, u_int) extern devclass_t miibus_devclass; -extern driver_t miibus_driver; +DECLARE_CLASS(miibus_driver); + +#ifdef FDT +extern devclass_t miibus_fdt_devclass; +DECLARE_CLASS(miibus_fdt_driver); +#endif + int mii_attach(device_t, device_t *, if_t, ifm_change_cb_t, ifm_stat_cb_t, int, int, int, int); @@ -280,6 +299,8 @@ int mii_phy_dev_probe(device_t dev, const struct mii_phydesc *mpd, int mrv); void mii_phy_dev_attach(device_t dev, u_int flags, const struct mii_phy_funcs *mpf, int add_media); +device_attach_t miibus_attach; + void ukphy_status(struct mii_softc *); u_int mii_oui(u_int, u_int);