From owner-svn-src-all@freebsd.org Sat Mar 23 02:48:49 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E843A155B1C4; Sat, 23 Mar 2019 02:48:48 +0000 (UTC) (envelope-from mw@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8790371441; Sat, 23 Mar 2019 02:48:48 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6498D1C69; Sat, 23 Mar 2019 02:48:48 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x2N2mmIL047238; Sat, 23 Mar 2019 02:48:48 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x2N2mm7g047236; Sat, 23 Mar 2019 02:48:48 GMT (envelope-from mw@FreeBSD.org) Message-Id: <201903230248.x2N2mm7g047236@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Sat, 23 Mar 2019 02:48:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r345432 - in head/sys/dev: etherswitch/e6000sw neta X-SVN-Group: head X-SVN-Commit-Author: mw X-SVN-Commit-Paths: in head/sys/dev: etherswitch/e6000sw neta X-SVN-Commit-Revision: 345432 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8790371441 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.976,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Mar 2019 02:48:49 -0000 Author: mw Date: Sat Mar 23 02:48:47 2019 New Revision: 345432 URL: https://svnweb.freebsd.org/changeset/base/345432 Log: Update mvneta/e6000sw for new DSA Device Tree Bindings In the latest Linux kernel revisions the DSA (Distributed Switch Architecture) device tree binding was changed. Instead of the top level dsa@ node, the switch and its ports is represented as a child node of the mdio bus. With that other modifications were added, such as relation with the ethernet port of the SoC. Adjust e6000sw etherswitch and mvneta drivers to that. Tested on Armada 3720 EspressoBin and Armada 388 Clearfog Pro boards. Submitted by: Bert JW Regeer Reviewed by: manu Differential Revision: https://reviews.freebsd.org/D19036 Modified: head/sys/dev/etherswitch/e6000sw/e6000sw.c head/sys/dev/neta/if_mvneta.c Modified: head/sys/dev/etherswitch/e6000sw/e6000sw.c ============================================================================== --- head/sys/dev/etherswitch/e6000sw/e6000sw.c Sat Mar 23 02:17:07 2019 (r345431) +++ head/sys/dev/etherswitch/e6000sw/e6000sw.c Sat Mar 23 02:48:47 2019 (r345432) @@ -45,8 +45,8 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include +#include #include "e6000swreg.h" #include "etherswitch_if.h" @@ -92,6 +92,8 @@ static etherswitch_info_t etherswitch_info = { static void e6000sw_identify(driver_t *, device_t); static int e6000sw_probe(device_t); +static int e6000sw_parse_fixed_link(e6000sw_softc_t *, phandle_t, uint32_t); +static int e6000sw_parse_ethernet(e6000sw_softc_t *, phandle_t, uint32_t); static int e6000sw_attach(device_t); static int e6000sw_detach(device_t); static int e6000sw_readphy(device_t, int, int); @@ -197,15 +199,17 @@ e6000sw_probe(device_t dev) { e6000sw_softc_t *sc; const char *description; - phandle_t dsa_node, switch_node; + phandle_t switch_node; - dsa_node = fdt_find_compatible(OF_finddevice("/"), - "marvell,dsa", 0); - switch_node = OF_child(dsa_node); + switch_node = ofw_bus_find_compatible(OF_finddevice("/"), + "marvell,mv88e6085"); if (switch_node == 0) return (ENXIO); + if (bootverbose) + device_printf(dev, "Found switch_node: 0x%x\n", switch_node); + sc = device_get_softc(dev); sc->dev = dev; sc->node = switch_node; @@ -214,8 +218,12 @@ e6000sw_probe(device_t dev) sizeof(sc->sw_addr)) < 0) return (ENXIO); - if (!OF_hasprop(sc->node, "single-chip-addressing") && - (sc->sw_addr != 0 && (sc->sw_addr % 2) == 0)) + /* + * According to the Linux source code, all of the Switch IDs we support + * are multi_chip capable, and should go into multi-chip mode if the + * sw_addr != 0. + */ + if (!OF_hasprop(sc->node, "single-chip-addressing") && sc->sw_addr != 0) sc->multi_chip = true; /* @@ -262,11 +270,58 @@ e6000sw_probe(device_t dev) } static int -e6000sw_parse_child_fdt(e6000sw_softc_t *sc, phandle_t child, int *pport) +e6000sw_parse_fixed_link(e6000sw_softc_t *sc, phandle_t node, uint32_t port) { - char *name, *portlabel; int speed; phandle_t fixed_link; + + fixed_link = ofw_bus_find_child(node, "fixed-link"); + + if (fixed_link != 0) { + sc->fixed_mask |= (1 << port); + + if (OF_getencprop(fixed_link, "speed", &speed, sizeof(speed))> 0) { + if (speed == 2500 && + (MVSWITCH(sc, MV88E6141) || + MVSWITCH(sc, MV88E6341))) + sc->fixed25_mask |= (1 << port); + } else { + device_printf(sc->dev, + "Port %d has a fixed-link node without a speed " + "property\n", port); + + return (ENXIO); + } + } + + return (0); +} + +static int +e6000sw_parse_ethernet(e6000sw_softc_t *sc, phandle_t port_handle, uint32_t port) { + phandle_t switch_eth, switch_eth_handle; + + if (OF_getencprop(port_handle, "ethernet", (void*)&switch_eth_handle, + sizeof(switch_eth_handle)) > 0) { + if (switch_eth_handle > 0) { + switch_eth = OF_node_from_xref(switch_eth_handle); + + device_printf(sc->dev, "CPU port at %d\n", port); + sc->cpuports_mask |= (1 << port); + + return (e6000sw_parse_fixed_link(sc, switch_eth, port)); + } else + device_printf(sc->dev, + "Port %d has ethernet property but it points " + "to an invalid location\n", port); + } + + return (0); +} + +static int +e6000sw_parse_child_fdt(e6000sw_softc_t *sc, phandle_t child, int *pport) +{ uint32_t port; if (pport == NULL) @@ -278,32 +333,12 @@ e6000sw_parse_child_fdt(e6000sw_softc_t *sc, phandle_t return (ENXIO); *pport = port; - if (OF_getprop_alloc(child, "label", (void **)&portlabel) > 0) { - if (strncmp(portlabel, "cpu", 3) == 0) { - device_printf(sc->dev, "CPU port at %d\n", port); - sc->cpuports_mask |= (1 << port); - sc->fixed_mask |= (1 << port); - } - free(portlabel, M_OFWPROP); - } + if (e6000sw_parse_fixed_link(sc, child, port) != 0) + return (ENXIO); - fixed_link = OF_child(child); - if (fixed_link != 0 && - OF_getprop_alloc(fixed_link, "name", (void **)&name) > 0) { - if (strncmp(name, "fixed-link", 10) == 0) { - /* Assume defaults: 1g - full-duplex. */ - sc->fixed_mask |= (1 << port); - if (OF_getencprop(fixed_link, "speed", &speed, - sizeof(speed)) > 0) { - if (speed == 2500 && - (MVSWITCH(sc, MV88E6141) || - MVSWITCH(sc, MV88E6341))) { - sc->fixed25_mask |= (1 << port); - } - } - } - free(name, M_OFWPROP); - } + if (e6000sw_parse_ethernet(sc, child, port) != 0) + return (ENXIO); + if ((sc->fixed_mask & (1 << port)) != 0) device_printf(sc->dev, "fixed port at %d\n", port); else @@ -354,7 +389,7 @@ static int e6000sw_attach(device_t dev) { e6000sw_softc_t *sc; - phandle_t child; + phandle_t child, ports; int err, port; uint32_t reg; @@ -371,7 +406,15 @@ e6000sw_attach(device_t dev) E6000SW_LOCK(sc); e6000sw_setup(dev, sc); - for (child = OF_child(sc->node); child != 0; child = OF_peer(child)) { + ports = ofw_bus_find_child(sc->node, "ports"); + + if (ports == 0) { + device_printf(dev, "failed to parse DTS: no ports found for " + "switch\n"); + return (ENXIO); + } + + for (child = OF_child(ports); child != 0; child = OF_peer(child)) { err = e6000sw_parse_child_fdt(sc, child, &port); if (err != 0) { device_printf(sc->dev, "failed to parse DTS\n"); Modified: head/sys/dev/neta/if_mvneta.c ============================================================================== --- head/sys/dev/neta/if_mvneta.c Sat Mar 23 02:17:07 2019 (r345431) +++ head/sys/dev/neta/if_mvneta.c Sat Mar 23 02:48:47 2019 (r345432) @@ -189,6 +189,7 @@ STATIC void mvneta_clear_mib(struct mvneta_softc *); STATIC void mvneta_update_mib(struct mvneta_softc *); /* Switch */ +STATIC boolean_t mvneta_find_ethernet_prop_switch(phandle_t, phandle_t); STATIC boolean_t mvneta_has_switch(device_t); #define mvneta_sc_lock(sc) mtx_lock(&sc->mtx) @@ -412,25 +413,41 @@ mvneta_get_mac_address(struct mvneta_softc *sc, uint8_ } STATIC boolean_t -mvneta_has_switch(device_t self) +mvneta_find_ethernet_prop_switch(phandle_t ethernet, phandle_t node) { - phandle_t node, switch_node, switch_eth, switch_eth_handle; + boolean_t ret; + phandle_t child, switch_eth_handle, switch_eth; - node = ofw_bus_get_node(self); - switch_node = - ofw_bus_find_compatible(OF_finddevice("/"), "marvell,dsa"); - switch_eth = 0; + for (child = OF_child(node); child != 0; child = OF_peer(child)) { + if (OF_getencprop(child, "ethernet", (void*)&switch_eth_handle, + sizeof(switch_eth_handle)) > 0) { + if (switch_eth_handle > 0) { + switch_eth = OF_node_from_xref( + switch_eth_handle); - OF_getencprop(switch_node, "dsa,ethernet", - (void*)&switch_eth_handle, sizeof(switch_eth_handle)); + if (switch_eth == ethernet) + return (true); + } + } - if (switch_eth_handle > 0) - switch_eth = OF_node_from_xref(switch_eth_handle); + ret = mvneta_find_ethernet_prop_switch(ethernet, child); + if (ret != 0) + return (ret); + } - /* Return true if dsa,ethernet cell points to us */ - return (node == switch_eth); + return (false); } +STATIC boolean_t +mvneta_has_switch(device_t self) +{ + phandle_t node; + + node = ofw_bus_get_node(self); + + return mvneta_find_ethernet_prop_switch(node, OF_finddevice("/")); +} + STATIC int mvneta_dma_create(struct mvneta_softc *sc) { @@ -799,6 +816,8 @@ mvneta_attach(device_t self) if_link_state_change(sc->ifp, LINK_STATE_UP); if (mvneta_has_switch(self)) { + if (bootverbose) + device_printf(self, "This device is attached to a switch\n"); child = device_add_child(sc->dev, "mdio", -1); if (child == NULL) { ether_ifdetach(sc->ifp);