From nobody Tue Mar 29 23:00:00 2022 X-Original-To: dev-commits-src-all@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 76CAA1A34B3A; Tue, 29 Mar 2022 23:00:01 +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 4KSlQ84DChz4TVJ; Tue, 29 Mar 2022 23:00:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648594801; 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=lLBFNNkg3NTGErWSvvGj9+6D/IMkuCQlmxvlPzMh8hs=; b=JgQxca8qXKKBAt4a3gZLE7xcKYfGvozF3GPf9lWdImymDUoblnDFpIjb4zYCJLAZ0mFO/d hL/IBK0iKsBb9HLociCNOsIFlwjCBIUunenfFTgGHxVjci5XFqj2lRxEvugazmMgMUjY4J 8n52zGq2gW454w68bI7VJKAWvDw7T0CaSNJrWTVvOR82bPf86Z2ETVtWFB6+N7huN64zY0 pjLf/V1m4+QhmG1eG8Ybh3l4xSDsEncMtyoTXjfq+D3FocksGo+GpsOboPaEBcd6S+WlKb Kw4mhSBjSMSK1du8W8E0l1r7t8Q08rgAQSuxW+AMlrtSoR+BjLrodLYdT1Dj9Q== 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 4A0462788A; Tue, 29 Mar 2022 23:00:00 +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 22TN00wD050199; Tue, 29 Mar 2022 23:00:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22TN00MV050174; Tue, 29 Mar 2022 23:00:00 GMT (envelope-from git) Date: Tue, 29 Mar 2022 23:00:00 GMT Message-Id: <202203292300.22TN00MV050174@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Marcin Wojtas Subject: git: f0a6f99b2a3a - stable/13 - miibus: Add support for mapping OFW nodes to PHY devices List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mw X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f0a6f99b2a3a449caab404dc5888ceb8ae716c98 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648594801; 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=lLBFNNkg3NTGErWSvvGj9+6D/IMkuCQlmxvlPzMh8hs=; b=sTGIS0jq3NqzbWevwFfLWbidOgdHEp2+41PpBfkXLJvdJ7dNTaB3vPrHD86sTjV2oIG9Ge f0QQdeZK/Q05p9sATeCeNi8U6VP23csVUF8a8ww/l3rpskKo4/a+apsdgK3mSuuoZhJKM+ TSqCSsF7pTW+/apmlhH4YTiRfOITVJit+DbR9WEYHIrpR0gAIfYm43Wt5VOImI8jpsA8Nr ZS988NnMDh84Mj83ju6gWpdunJ329+YeEOfKg71aAVhJ2GPP0Ei3SnF8HKYYBsOy5EseRg swxXlzZMnXDHiznzxgq3jbP7kRkfJMYcYp9KtM79JuOHirjEJ4f3uMKD5djm9Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648594801; a=rsa-sha256; cv=none; b=J5KXX3ogEqm6aa5kk9nsyir8sswWB3dku9qssSDhvomUdFrRM1ncTB5Au9gzy4qgXCuxND EbG3WodyzKHl/lWxfisU0VCMQmD0XZskW0YVjU5kWWmp6yoBGJUN3LdQTdN86TdyMLc8jV YQQQcHycU02VifZC9dYskNInIEDqUVOn6gU/CGb+b210i8Zj/R5vzB5yXvIsPR5V5tWHh2 KPFUdI0BZ07SDJ6rNneuvUi1lSAPjTI4xb+YhOPphv+uCpNH1zT/7omPSTiEVbvoDJXqg5 Y1ibcTiW1macI6f1ZnOsl8dage/CHP4XM04zybwdXeVHEDO4HnENGVOs66uJQw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=f0a6f99b2a3a449caab404dc5888ceb8ae716c98 commit f0a6f99b2a3a449caab404dc5888ceb8ae716c98 Author: Kornel Duleba AuthorDate: 2021-11-15 08:55:33 +0000 Commit: Marcin Wojtas CommitDate: 2022-03-29 22:24:28 +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 (cherry picked from commit 9174eab4142c5ed199b1599c1a3eefd5f0573ab7) --- 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 57294f4c096c..aaae2ec4e5d6 100644 --- a/sys/dev/mii/mii.c +++ b/sys/dev/mii/mii.c @@ -59,7 +59,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_str_t miibus_child_location_str; static bus_child_pnpinfo_str_t miibus_child_pnpinfo_str; @@ -102,12 +101,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; @@ -126,7 +120,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 4658394797e9..0f928dce6efc 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 */ @@ -205,6 +213,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; @@ -250,7 +263,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); @@ -279,6 +298,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);