From owner-svn-src-user@freebsd.org Tue May 21 00:07:59 2019 Return-Path: Delivered-To: svn-src-user@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 90D651596DDE for ; Tue, 21 May 2019 00:07:59 +0000 (UTC) (envelope-from ngie@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 3493A6A68D; Tue, 21 May 2019 00:07:59 +0000 (UTC) (envelope-from ngie@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 DC98F25B76; Tue, 21 May 2019 00:07:58 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x4L07wgT068355; Tue, 21 May 2019 00:07:58 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x4L07sFm068330; Tue, 21 May 2019 00:07:54 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201905210007.x4L07sFm068330@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Enji Cooper Date: Tue, 21 May 2019 00:07:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r348023 - in user/ngie/bug-237403: cddl/contrib/opensolaris/lib/libzfs/common lib/csu/mips lib/libarchive/tests share/man/man9 stand/common stand/ofw/libofw stand/powerpc/boot1.chrp sta... X-SVN-Group: user X-SVN-Commit-Author: ngie X-SVN-Commit-Paths: in user/ngie/bug-237403: cddl/contrib/opensolaris/lib/libzfs/common lib/csu/mips lib/libarchive/tests share/man/man9 stand/common stand/ofw/libofw stand/powerpc/boot1.chrp stand/powerpc/kboot stand/po... X-SVN-Commit-Revision: 348023 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 3493A6A68D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.98)[-0.982,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 May 2019 00:08:00 -0000 Author: ngie Date: Tue May 21 00:07:53 2019 New Revision: 348023 URL: https://svnweb.freebsd.org/changeset/base/348023 Log: MFhead@r348022 Added: user/ngie/bug-237403/share/man/man9/DEFINE_IFUNC.9 - copied unchanged from r348022, head/share/man/man9/DEFINE_IFUNC.9 Modified: user/ngie/bug-237403/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_diff.c user/ngie/bug-237403/lib/csu/mips/crtn.S user/ngie/bug-237403/lib/libarchive/tests/Makefile user/ngie/bug-237403/share/man/man9/DRIVER_MODULE.9 user/ngie/bug-237403/share/man/man9/Makefile user/ngie/bug-237403/stand/common/load_elf.c user/ngie/bug-237403/stand/ofw/libofw/ofw_net.c user/ngie/bug-237403/stand/ofw/libofw/openfirm.c user/ngie/bug-237403/stand/powerpc/boot1.chrp/boot1.c user/ngie/bug-237403/stand/powerpc/kboot/Makefile user/ngie/bug-237403/stand/powerpc/kboot/main.c user/ngie/bug-237403/stand/powerpc/ofw/elf_freebsd.c user/ngie/bug-237403/stand/powerpc/ofw/ppc64_elf_freebsd.c user/ngie/bug-237403/sys/dev/netmap/netmap_freebsd.c user/ngie/bug-237403/sys/dev/usb/net/if_muge.c user/ngie/bug-237403/sys/dev/usb/net/if_mugereg.h user/ngie/bug-237403/sys/kern/kern_kcov.c user/ngie/bug-237403/sys/mips/mediatek/mtk_spi_v1.c user/ngie/bug-237403/sys/netinet/netdump/netdump_client.c user/ngie/bug-237403/tests/sys/opencrypto/runtests.sh user/ngie/bug-237403/tests/sys/sys/rb_test.c user/ngie/bug-237403/tests/sys/sys/splay_test.c Directory Properties: user/ngie/bug-237403/ (props changed) user/ngie/bug-237403/cddl/ (props changed) user/ngie/bug-237403/cddl/contrib/opensolaris/ (props changed) user/ngie/bug-237403/cddl/contrib/opensolaris/lib/libzfs/ (props changed) Modified: user/ngie/bug-237403/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_diff.c ============================================================================== --- user/ngie/bug-237403/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_diff.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_diff.c Tue May 21 00:07:53 2019 (r348023) @@ -114,7 +114,7 @@ get_stats_for_obj(differ_info_t *di, const char *dsnam (void) snprintf(di->errbuf, sizeof (di->errbuf), dgettext(TEXT_DOMAIN, "Unable to determine path or stats for " - "object %lld in %s"), obj, dsname); + "object %jd in %s"), (uintmax_t)obj, dsname); return (-1); } } @@ -406,8 +406,8 @@ write_free_diffs(FILE *fp, differ_info_t *di, dmu_diff } else { (void) snprintf(di->errbuf, sizeof (di->errbuf), dgettext(TEXT_DOMAIN, - "next allocated object (> %lld) find failure"), - zc.zc_obj); + "next allocated object (> %jd) find failure"), + (uintmax_t)zc.zc_obj); di->zerr = errno; break; } Modified: user/ngie/bug-237403/lib/csu/mips/crtn.S ============================================================================== --- user/ngie/bug-237403/lib/csu/mips/crtn.S Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/lib/csu/mips/crtn.S Tue May 21 00:07:53 2019 (r348023) @@ -5,7 +5,6 @@ __FBSDID("$FreeBSD$"); .gnu_attribute 4, 0 #endif .section .init,"ax",%progbits - .align 4 .set noreorder #if defined(__ABICALLS__) && (defined(__mips_n32) || defined(__mips_n64)) REG_L gp, CALLFRAME_GP(sp) @@ -16,7 +15,6 @@ __FBSDID("$FreeBSD$"); .set reorder .section .fini,"ax",%progbits - .align 4 .set noreorder #if defined(__ABICALLS__) && (defined(__mips_n32) || defined(__mips_n64)) REG_L gp, CALLFRAME_GP(sp) Modified: user/ngie/bug-237403/lib/libarchive/tests/Makefile ============================================================================== --- user/ngie/bug-237403/lib/libarchive/tests/Makefile Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/lib/libarchive/tests/Makefile Tue May 21 00:07:53 2019 (r348023) @@ -557,6 +557,7 @@ ${PACKAGE}FILES+= test_read_format_ustar_filename_eucj ${PACKAGE}FILES+= test_read_format_ustar_filename_koi8r.tar.Z.uu ${PACKAGE}FILES+= test_read_format_warc.warc.uu ${PACKAGE}FILES+= test_read_format_zip.zip.uu +${PACKAGE}FILES+= test_read_format_zip_7075_utf8_paths.zip.uu ${PACKAGE}FILES+= test_read_format_zip_bz2_hang.zip.uu ${PACKAGE}FILES+= test_read_format_zip_bzip2.zipx.uu ${PACKAGE}FILES+= test_read_format_zip_bzip2_multi.zipx.uu Copied: user/ngie/bug-237403/share/man/man9/DEFINE_IFUNC.9 (from r348022, head/share/man/man9/DEFINE_IFUNC.9) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/ngie/bug-237403/share/man/man9/DEFINE_IFUNC.9 Tue May 21 00:07:53 2019 (r348023, copy of r348022, head/share/man/man9/DEFINE_IFUNC.9) @@ -0,0 +1,143 @@ +.\" Copyright (c) 2019 The FreeBSD Foundation +.\" +.\" This documentation was written by Mark Johnston +.\" under sponsorship from the FreeBSD Foundation. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd May 18, 2019 +.Dt DEFINE_IFUNC 9 +.Os +.Sh NAME +.Nm DEFINE_IFUNC +.Nd define a kernel function with an implementation selected at run-time +.Sh SYNOPSIS +.In machine/ifunc.h +.Fn DEFINE_IFUNC qual ret_type name args +.Sh DESCRIPTION +ifuncs are a linker feature which allows the programmer to define functions +whose implementation is selected at boot-time or module load-time. +The +.Nm +macro can be used to define an ifunc. +The selection is performed by a resolver function, which returns a pointer +to the selected function. +ifunc resolvers are invoked very early during the machine-dependent +initialization routine, or at load time for dynamically loaded modules. +Resolution must occur before the first call to an ifunc. +ifunc resolution is performed after CPU features are enumerated and after the +kernel's environment is initialized. +The typical use-case for an ifunc is a routine whose behavior depends on +optional CPU features. +For example, newer generations of a given CPU architecture may provide an +instruction to optimize a common operation. +To avoid the overhead of testing for the CPU feature each time the operation +is performed, an ifunc can be used to provide two implementations for the +operation: one targeting platforms with the extra instruction, and one +for older platforms. +.Pp +Because +.Nm +is a macro that defines a dynamically typed function, its usage looks somewhat +unusual. +The +.Ar qual +parameter is a list of zero or more C function qualifiers to be applied to the +ifunc. +This parameter is typically empty or the +.Dv static +qualifier. +.Ar ret_type +is the return type of the ifunc. +.Ar name +is the name of the ifunc. +.Ar args +is a parenthesized, comma-separated list of the parameter types of the function, +as they would appear in a C function declaration. +.Pp +The +.Nm +usage must be followed by the resolver function body. +The resolver must return a function with return type +.Ar ret_type +and parameter types +.Ar args . +The resolver function is defined with the +.Ql resolver +gcc-style function attribute, causing the corresponding +.Xr elf 5 +function symbol to be of type +.Dv STT_GNU_IFUNC +instead of +.Dv STT_FUNC . +The kernel linker invokes the resolver to process relocations targeting ifunc +calls and PLT entries referencing such symbols. +.Sh EXAMPLES +ifunc resolvers are executed early during boot, before most kernel facilities +are available. +They are effectively limited to checking CPU feature flags and tunables. +.Bd -literal +static size_t +fast_strlen(const char *s __unused) +{ + size_t len; + + /* Fast, but may not be correct in all cases. */ + __asm("movq $42,%0\\n" : "=r" (len)); + return (len); +} + +static size_t +slow_strlen(const char *s) +{ + const char *t; + + for (t = s; *t != '\\0'; t++); + return (t - s); +} + +DEFINE_IFUNC(, size_t, strlen, (const char *)) +{ + int enabled; + + enabled = 1; + TUNABLE_INT_FETCH("debug.use_fast_strlen", &enabled); + if (enabled && (cpu_features & CPUID_FAST_STRLEN) != 0) + return (fast_strlen); + else + return (slow_strlen); +} +.Ed +.Pp +This defines a +.Fn strlen +function with an optimized implementation for CPUs that advertise support. +.Sh SEE ALSO +.Xr elf 5 +.Sh NOTES +ifuncs are not supported on all architectures. +They require both toolchain support, to emit function symbols of type +.Dv STT_GNU_IFUNC , +and kernel linker support to invoke ifunc resolvers during boot or +during module load. Modified: user/ngie/bug-237403/share/man/man9/DRIVER_MODULE.9 ============================================================================== --- user/ngie/bug-237403/share/man/man9/DRIVER_MODULE.9 Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/share/man/man9/DRIVER_MODULE.9 Tue May 21 00:07:53 2019 (r348023) @@ -125,7 +125,7 @@ macro allows a driver to be registered for a specific The boot time probe and attach process makes multiple passes over the device tree. Certain critical drivers that provide basic services needed by other -devices are attach during earlier passes. +devices are attached during earlier passes. Most drivers are attached in a final general pass. A driver that attaches during an early pass must register for a specific pass level Modified: user/ngie/bug-237403/share/man/man9/Makefile ============================================================================== --- user/ngie/bug-237403/share/man/man9/Makefile Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/share/man/man9/Makefile Tue May 21 00:07:53 2019 (r348023) @@ -75,6 +75,7 @@ MAN= accept_filter.9 \ DB_COMMAND.9 \ DECLARE_GEOM_CLASS.9 \ DECLARE_MODULE.9 \ + DEFINE_IFUNC.9 \ DELAY.9 \ devclass.9 \ devclass_find.9 \ Modified: user/ngie/bug-237403/stand/common/load_elf.c ============================================================================== --- user/ngie/bug-237403/stand/common/load_elf.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/stand/common/load_elf.c Tue May 21 00:07:53 2019 (r348023) @@ -483,7 +483,7 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_ off += 0x01000000; ehdr->e_entry += off; #ifdef ELF_VERBOSE - printf("Converted entry 0x%08x\n", ehdr->e_entry); + printf("Converted entry 0x%jx\n", (uintmax_t)ehdr->e_entry); #endif } else off = 0; @@ -509,8 +509,8 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_ off -= ehdr->e_entry & ~PAGE_MASK; ehdr->e_entry += off; #ifdef ELF_VERBOSE - printf("ehdr->e_entry 0x%08x, va<->pa off %llx\n", - ehdr->e_entry, off); + printf("ehdr->e_entry 0x%jx", va<->pa off %llx\n", + (uintmax_t)ehdr->e_entry, off); #endif #else off = 0; /* other archs use direct mapped kernels */ Modified: user/ngie/bug-237403/stand/ofw/libofw/ofw_net.c ============================================================================== --- user/ngie/bug-237403/stand/ofw/libofw/ofw_net.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/stand/ofw/libofw/ofw_net.c Tue May 21 00:07:53 2019 (r348023) @@ -225,12 +225,12 @@ ofwn_init(struct iodesc *desc, void *machdep_hint) dmabuf = NULL; if (OF_call_method("dma-alloc", netinstance, 1, 1, (64 * 1024), &dmabuf) < 0) { - printf("Failed to allocate DMA buffer (got %08x).\n", dmabuf); + printf("Failed to allocate DMA buffer (got %p).\n", dmabuf); goto punt; } #if defined(NETIF_DEBUG) - printf("ofwn_init: allocated DMA buffer: %08x\n", dmabuf); + printf("ofwn_init: allocated DMA buffer: %p\n", dmabuf); #endif #endif Modified: user/ngie/bug-237403/stand/ofw/libofw/openfirm.c ============================================================================== --- user/ngie/bug-237403/stand/ofw/libofw/openfirm.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/stand/ofw/libofw/openfirm.c Tue May 21 00:07:53 2019 (r348023) @@ -669,7 +669,6 @@ OF_block_size(ihandle_t instance) } /* -/* * Memory functions */ Modified: user/ngie/bug-237403/stand/powerpc/boot1.chrp/boot1.c ============================================================================== --- user/ngie/bug-237403/stand/powerpc/boot1.chrp/boot1.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/stand/powerpc/boot1.chrp/boot1.c Tue May 21 00:07:53 2019 (r348023) @@ -23,6 +23,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include "paths.h" Modified: user/ngie/bug-237403/stand/powerpc/kboot/Makefile ============================================================================== --- user/ngie/bug-237403/stand/powerpc/kboot/Makefile Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/stand/powerpc/kboot/Makefile Tue May 21 00:07:53 2019 (r348023) @@ -36,9 +36,6 @@ CFLAGS+= -DRELOC=${RELOC} LDFLAGS= -nostdlib -static -T ${.CURDIR}/ldscript.powerpc -# 64-bit bridge extensions -CFLAGS+= -Wa,-mppc64bridge - DPADD= ${LDR_INTERP} ${LIBOFW} ${LIBFDT} ${LIBSA} LDADD= ${LDR_INTERP} ${LIBOFW} ${LIBFDT} ${LIBSA} Modified: user/ngie/bug-237403/stand/powerpc/kboot/main.c ============================================================================== --- user/ngie/bug-237403/stand/powerpc/kboot/main.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/stand/powerpc/kboot/main.c Tue May 21 00:07:53 2019 (r348023) @@ -484,8 +484,18 @@ kboot_kseg_get(int *nseg, void **ptr) void _start(int argc, const char **argv, char **env) { +// This makes error "variable 'sp' is uninitialized" be just a warning on clang. +// Initializing 'sp' is not desired here as it would overwrite "r1" original value +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic warning "-Wuninitialized" +#endif register volatile void **sp asm("r1"); main((int)sp[0], (const char **)&sp[1]); +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + } /* Modified: user/ngie/bug-237403/stand/powerpc/ofw/elf_freebsd.c ============================================================================== --- user/ngie/bug-237403/stand/powerpc/ofw/elf_freebsd.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/stand/powerpc/ofw/elf_freebsd.c Tue May 21 00:07:53 2019 (r348023) @@ -84,7 +84,7 @@ __elfN(ofw_exec)(struct preloaded_file *fp) if ((error = md_load(fp->f_args, &mdp, &dtbp)) != 0) return (error); - printf("Kernel entry at 0x%lx ...\n", e->e_entry); + printf("Kernel entry at 0x%x ...\n", entry); dev_cleanup(); if (dtbp != 0) { Modified: user/ngie/bug-237403/stand/powerpc/ofw/ppc64_elf_freebsd.c ============================================================================== --- user/ngie/bug-237403/stand/powerpc/ofw/ppc64_elf_freebsd.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/stand/powerpc/ofw/ppc64_elf_freebsd.c Tue May 21 00:07:53 2019 (r348023) @@ -87,7 +87,7 @@ ppc64_ofw_elf_exec(struct preloaded_file *fp) if ((error = md_load64(fp->f_args, &mdp, &dtbp)) != 0) return (error); - printf("Kernel entry at 0x%lx ...\n", entry); + printf("Kernel entry at 0x%x ...\n", entry); dev_cleanup(); Modified: user/ngie/bug-237403/sys/dev/netmap/netmap_freebsd.c ============================================================================== --- user/ngie/bug-237403/sys/dev/netmap/netmap_freebsd.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/sys/dev/netmap/netmap_freebsd.c Tue May 21 00:07:53 2019 (r348023) @@ -32,6 +32,7 @@ #include #include #include +#include #include #include /* POLLIN, POLLOUT */ #include /* types used in module initialization */ Modified: user/ngie/bug-237403/sys/dev/usb/net/if_muge.c ============================================================================== --- user/ngie/bug-237403/sys/dev/usb/net/if_muge.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/sys/dev/usb/net/if_muge.c Tue May 21 00:07:53 2019 (r348023) @@ -97,6 +97,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #endif #include @@ -173,6 +174,9 @@ struct muge_softc { struct mtx sc_mtx; struct usb_xfer *sc_xfer[MUGE_N_TRANSFER]; int sc_phyno; + uint32_t sc_leds; + uint16_t sc_led_modes; + uint16_t sc_led_modes_mask; /* Settings for the mac control (MAC_CSR) register. */ uint32_t sc_rfe_ctl; @@ -889,8 +893,9 @@ static int lan78xx_phy_init(struct muge_softc *sc) { muge_dbg_printf(sc, "Initializing PHY.\n"); - uint16_t bmcr; + uint16_t bmcr, lmsr; usb_ticks_t start_ticks; + uint32_t hw_reg; const usb_ticks_t max_ticks = USB_MS_TO_TICKS(1000); MUGE_LOCK_ASSERT(sc, MA_OWNED); @@ -931,6 +936,25 @@ lan78xx_phy_init(struct muge_softc *sc) bmcr |= BMCR_AUTOEN; lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR, bmcr); bmcr = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, MII_BMCR); + + /* Configure LED Modes. */ + if (sc->sc_led_modes_mask != 0) { + lmsr = lan78xx_miibus_readreg(sc->sc_ue.ue_dev, sc->sc_phyno, + MUGE_PHY_LED_MODE); + lmsr &= ~sc->sc_led_modes_mask; + lmsr |= sc->sc_led_modes; + lan78xx_miibus_writereg(sc->sc_ue.ue_dev, sc->sc_phyno, + MUGE_PHY_LED_MODE, lmsr); + } + + /* Enable appropriate LEDs. */ + if (sc->sc_leds != 0 && + lan78xx_read_reg(sc, ETH_HW_CFG, &hw_reg) == 0) { + hw_reg &= ~(ETH_HW_CFG_LEDO_EN_ | ETH_HW_CFG_LED1_EN_ | + ETH_HW_CFG_LED2_EN_ | ETH_HW_CFG_LED3_EN_ ); + hw_reg |= sc->sc_leds; + lan78xx_write_reg(sc, ETH_HW_CFG, hw_reg); + } return (0); } @@ -1431,101 +1455,7 @@ tr_setup: } } -#ifdef FDT /** - * muge_fdt_find_eth_node - find descendant node with required compatibility - * @start: start node - * @compatible: compatible string used to identify the node - * - * Loop through all descendant nodes and return first match with required - * compatibility. - * - * RETURNS: - * Returns node's phandle on success -1 otherwise - */ -static phandle_t -muge_fdt_find_eth_node(phandle_t start, const char *compatible) -{ - phandle_t child, node; - - /* Traverse through entire tree to find usb ethernet nodes. */ - for (node = OF_child(start); node != 0; node = OF_peer(node)) { - if (ofw_bus_node_is_compatible(node, compatible)) - return (node); - child = muge_fdt_find_eth_node(node, compatible); - if (child != -1) - return (child); - } - - return (-1); -} - -/** - * muge_fdt_read_mac_property - read MAC address from node - * @node: USB device node - * @mac: memory to store MAC address to - * - * Check for common properties that might contain MAC address - * passed by boot loader. - * - * RETURNS: - * Returns 0 on success, error code otherwise - */ -static int -muge_fdt_read_mac_property(phandle_t node, unsigned char *mac) -{ - int len; - - /* Check if there is property */ - if ((len = OF_getproplen(node, "local-mac-address")) > 0) { - if (len != ETHER_ADDR_LEN) - return (EINVAL); - - OF_getprop(node, "local-mac-address", mac, - ETHER_ADDR_LEN); - return (0); - } - - if ((len = OF_getproplen(node, "mac-address")) > 0) { - if (len != ETHER_ADDR_LEN) - return (EINVAL); - - OF_getprop(node, "mac-address", mac, - ETHER_ADDR_LEN); - return (0); - } - - return (ENXIO); -} - -/** - * muge_fdt_find_mac - read MAC address from node - * @compatible: compatible string for DTB node in the form "usb[N]NNN,[M]MMM" - * where NNN is vendor id and MMM is product id - * @mac: memory to store MAC address to - * - * Tries to find matching node in DTS and obtain MAC address info from it - * - * RETURNS: - * Returns 0 on success, error code otherwise - */ -static int -muge_fdt_find_mac(const char *compatible, unsigned char *mac) -{ - phandle_t node, root; - - root = OF_finddevice("/"); - node = muge_fdt_find_eth_node(root, compatible); - if (node != -1) { - if (muge_fdt_read_mac_property(node, mac) == 0) - return (0); - } - - return (ENXIO); -} -#endif - -/** * muge_set_mac_addr - Initiailizes NIC MAC address * @ue: the USB ethernet device * @@ -1537,12 +1467,8 @@ muge_set_mac_addr(struct usb_ether *ue) { struct muge_softc *sc = uether_getsc(ue); uint32_t mac_h, mac_l; -#ifdef FDT - char compatible[16]; - struct usb_attach_arg *uaa = device_get_ivars(ue->ue_dev); -#endif - memset(sc->sc_ue.ue_eaddr, 0xff, ETHER_ADDR_LEN); + memset(ue->ue_eaddr, 0xff, ETHER_ADDR_LEN); uint32_t val; lan78xx_read_reg(sc, 0, &val); @@ -1550,44 +1476,78 @@ muge_set_mac_addr(struct usb_ether *ue) /* Read current MAC address from RX_ADDRx registers. */ if ((lan78xx_read_reg(sc, ETH_RX_ADDRL, &mac_l) == 0) && (lan78xx_read_reg(sc, ETH_RX_ADDRH, &mac_h) == 0)) { - sc->sc_ue.ue_eaddr[5] = (uint8_t)((mac_h >> 8) & 0xff); - sc->sc_ue.ue_eaddr[4] = (uint8_t)((mac_h) & 0xff); - sc->sc_ue.ue_eaddr[3] = (uint8_t)((mac_l >> 24) & 0xff); - sc->sc_ue.ue_eaddr[2] = (uint8_t)((mac_l >> 16) & 0xff); - sc->sc_ue.ue_eaddr[1] = (uint8_t)((mac_l >> 8) & 0xff); - sc->sc_ue.ue_eaddr[0] = (uint8_t)((mac_l) & 0xff); + ue->ue_eaddr[5] = (uint8_t)((mac_h >> 8) & 0xff); + ue->ue_eaddr[4] = (uint8_t)((mac_h) & 0xff); + ue->ue_eaddr[3] = (uint8_t)((mac_l >> 24) & 0xff); + ue->ue_eaddr[2] = (uint8_t)((mac_l >> 16) & 0xff); + ue->ue_eaddr[1] = (uint8_t)((mac_l >> 8) & 0xff); + ue->ue_eaddr[0] = (uint8_t)((mac_l) & 0xff); } - /* If RX_ADDRx did not provide a valid MAC address, try EEPROM. */ - if (ETHER_IS_VALID(sc->sc_ue.ue_eaddr)) { + /* + * If RX_ADDRx did not provide a valid MAC address, try EEPROM. If that + * doesn't work, try OTP. Whether any of these methods work or not, try + * FDT data, because it is allowed to override the EEPROM/OTP values. + */ + if (ETHER_IS_VALID(ue->ue_eaddr)) { muge_dbg_printf(sc, "MAC assigned from registers\n"); - return; + } else if (lan78xx_eeprom_present(sc) && lan78xx_eeprom_read_raw(sc, + ETH_E2P_MAC_OFFSET, ue->ue_eaddr, ETHER_ADDR_LEN) == 0 && + ETHER_IS_VALID(ue->ue_eaddr)) { + muge_dbg_printf(sc, "MAC assigned from EEPROM\n"); + } else if (lan78xx_otp_read(sc, OTP_MAC_OFFSET, ue->ue_eaddr, + ETHER_ADDR_LEN) == 0 && ETHER_IS_VALID(ue->ue_eaddr)) { + muge_dbg_printf(sc, "MAC assigned from OTP\n"); } - if ((lan78xx_eeprom_present(sc) && - lan78xx_eeprom_read_raw(sc, ETH_E2P_MAC_OFFSET, - sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN) == 0) || - (lan78xx_otp_read(sc, OTP_MAC_OFFSET, - sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN) == 0)) { - if (ETHER_IS_VALID(sc->sc_ue.ue_eaddr)) { - muge_dbg_printf(sc, "MAC read from EEPROM\n"); - return; - } +#ifdef FDT + /* ue->ue_eaddr modified only if config exists for this dev instance. */ + usb_fdt_get_mac_addr(ue->ue_dev, ue); + if (ETHER_IS_VALID(ue->ue_eaddr)) { + muge_dbg_printf(sc, "MAC assigned from FDT data\n"); } +#endif + if (!ETHER_IS_VALID(ue->ue_eaddr)) { + muge_dbg_printf(sc, "MAC assigned randomly\n"); + arc4rand(ue->ue_eaddr, ETHER_ADDR_LEN, 0); + ue->ue_eaddr[0] &= ~0x01; /* unicast */ + ue->ue_eaddr[0] |= 0x02; /* locally administered */ + } +} + +/** + * muge_set_leds - Initializes NIC LEDs pattern + * @ue: the USB ethernet device + * + * Tries to store the LED modes. + * Supports only DTB blob like the Linux driver does. + */ +static void +muge_set_leds(struct usb_ether *ue) +{ #ifdef FDT - snprintf(compatible, sizeof(compatible), "usb%x,%x", - uaa->info.idVendor, uaa->info.idProduct); - if (muge_fdt_find_mac(compatible, sc->sc_ue.ue_eaddr) == 0) { - muge_dbg_printf(sc, "MAC assigned from FDT blob\n"); - return; + struct muge_softc *sc = uether_getsc(ue); + phandle_t node; + pcell_t modes[4]; /* 4 LEDs are possible */ + ssize_t proplen; + uint32_t count; + + if ((node = usb_fdt_get_node(ue->ue_dev, ue->ue_udev)) != -1 && + (proplen = OF_getencprop(node, "microchip,led-modes", modes, + sizeof(modes))) > 0) { + count = proplen / sizeof( uint32_t ); + sc->sc_leds = (count > 0) * ETH_HW_CFG_LEDO_EN_ | + (count > 1) * ETH_HW_CFG_LED1_EN_ | + (count > 2) * ETH_HW_CFG_LED2_EN_ | + (count > 3) * ETH_HW_CFG_LED3_EN_; + while (count-- > 0) { + sc->sc_led_modes |= (modes[count] & 0xf) << (4 * count); + sc->sc_led_modes_mask |= 0xf << (4 * count); + } + muge_dbg_printf(sc, "LED modes set from FDT data\n"); } #endif - - muge_dbg_printf(sc, "MAC assigned randomly\n"); - arc4rand(sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN, 0); - sc->sc_ue.ue_eaddr[0] &= ~0x01; /* unicast */ - sc->sc_ue.ue_eaddr[0] |= 0x02; /* locally administered */ } /** @@ -1610,6 +1570,7 @@ muge_attach_post(struct usb_ether *ue) sc->sc_phyno = 1; muge_set_mac_addr(ue); + muge_set_leds(ue); /* Initialise the chip for the first time */ lan78xx_chip_init(sc); Modified: user/ngie/bug-237403/sys/dev/usb/net/if_mugereg.h ============================================================================== --- user/ngie/bug-237403/sys/dev/usb/net/if_mugereg.h Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/sys/dev/usb/net/if_mugereg.h Tue May 21 00:07:53 2019 (r348023) @@ -190,6 +190,8 @@ #define MUGE_EXT_PAGE_SPACE_1 0x0001 #define MUGE_EXT_PAGE_SPACE_2 0x0002 +#define MUGE_PHY_LED_MODE 29 + /* Extended Register Page 1 Space */ #define MUGE_EXT_MODE_CTRL 0x0013 #define MUGE_EXT_MODE_CTRL_MDIX_MASK_ 0x000C Modified: user/ngie/bug-237403/sys/kern/kern_kcov.c ============================================================================== --- user/ngie/bug-237403/sys/kern/kern_kcov.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/sys/kern/kern_kcov.c Tue May 21 00:07:53 2019 (r348023) @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include Modified: user/ngie/bug-237403/sys/mips/mediatek/mtk_spi_v1.c ============================================================================== --- user/ngie/bug-237403/sys/mips/mediatek/mtk_spi_v1.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/sys/mips/mediatek/mtk_spi_v1.c Tue May 21 00:07:53 2019 (r348023) @@ -43,6 +43,11 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include "gpiobus_if.h" + +#include + #include #include #include "spibus_if.h" @@ -53,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -81,6 +87,8 @@ __FBSDID("$FreeBSD$"); struct mtk_spi_softc { device_t sc_dev; struct resource *sc_mem_res; + struct gpiobus_pin *gpio_cs; + int nonflash; }; static int mtk_spi_probe(device_t); @@ -127,7 +135,7 @@ mtk_spi_attach(device_t dev) sc->sc_dev = dev; rid = 0; sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, - RF_ACTIVE); + RF_SHAREABLE | RF_ACTIVE); if (!sc->sc_mem_res) { device_printf(dev, "Could not map memory\n"); return (ENXIO); @@ -138,14 +146,20 @@ mtk_spi_attach(device_t dev) return (EBUSY); } - SPI_WRITE(sc, MTK_SPICFG, MSBFIRST | SPICLKPOL | TX_ON_CLK_FALL | - SPI_CLK_DIV8); /* XXX: make it configurable */ - /* - * W25Q64CV max 104MHz, bus 120-192 MHz, so divide by 2. - * Update: divide by 4, DEV2 to fast for flash. - */ + if (ofw_bus_has_prop(dev, "non-flash")) + sc->nonflash = 1; + else + sc->nonflash = 0; - device_add_child(dev, "spibus", 0); + ofw_gpiobus_parse_gpios(dev, "cs-gpios", &sc->gpio_cs); + + if (sc->gpio_cs != NULL) { + GPIO_PIN_SETFLAGS(sc->gpio_cs->dev, sc->gpio_cs->pin, + GPIO_PIN_OUTPUT); + GPIO_PIN_SET(sc->gpio_cs->dev, sc->gpio_cs->pin, 1); + } + + device_add_child(dev, "spibus", -1); return (bus_generic_attach(dev)); } @@ -169,7 +183,12 @@ mtk_spi_chip_activate(struct mtk_spi_softc *sc) /* * Put all CSx to low */ - SPI_CLEAR_BITS(sc, MTK_SPICTL, CS_HIGH | HIZSMOSI); + if (sc->gpio_cs != NULL) { + GPIO_PIN_SET(sc->gpio_cs->dev, sc->gpio_cs->pin, 0); + SPI_CLEAR_BITS(sc, MTK_SPICTL, HIZSMOSI); + } else { + SPI_CLEAR_BITS(sc, MTK_SPICTL, CS_HIGH | HIZSMOSI); + } } static void @@ -179,7 +198,12 @@ mtk_spi_chip_deactivate(struct mtk_spi_softc *sc) /* * Put all CSx to high */ - SPI_SET_BITS(sc, MTK_SPICTL, CS_HIGH | HIZSMOSI); + if (sc->gpio_cs != NULL) { + GPIO_PIN_SET(sc->gpio_cs->dev, sc->gpio_cs->pin, 1); + SPI_SET_BITS(sc, MTK_SPICTL, HIZSMOSI); + } else { + SPI_SET_BITS(sc, MTK_SPICTL, CS_HIGH | HIZSMOSI); + } } static int @@ -224,12 +248,15 @@ mtk_spi_transfer(device_t dev, device_t child, struct { struct mtk_spi_softc *sc; uint8_t *buf, byte, *tx_buf; - uint32_t cs; + uint32_t cs, clock, mode; int i, sz, error = 0, write = 0; + int div, clk, cfgreg; sc = device_get_softc(dev); spibus_get_cs(child, &cs); + spibus_get_clock(child, &clock); + spibus_get_mode(child, &mode); cs &= ~SPIBUS_CS_HIGH; @@ -237,44 +264,80 @@ mtk_spi_transfer(device_t dev, device_t child, struct /* Only 1 CS */ return (ENXIO); - /* There is always a command to transfer. */ - tx_buf = (uint8_t *)(cmd->tx_cmd); - - /* Perform some fixup because MTK dont support duplex SPI */ - switch(tx_buf[0]) { - case CMD_READ_IDENT: - cmd->tx_cmd_sz = 1; - cmd->rx_cmd_sz = 3; + cfgreg = MSBFIRST; + switch(mode) { + case 0: /* This is workadound because of + mode 0 not work this soc. */ + case 3: + cfgreg |= SPICLKPOL | TX_ON_CLK_FALL; break; - case CMD_ENTER_4B_MODE: - case CMD_EXIT_4B_MODE: - case CMD_WRITE_ENABLE: - case CMD_WRITE_DISABLE: - cmd->tx_cmd_sz = 1; - cmd->rx_cmd_sz = 0; + case 1: + cfgreg |= TX_ON_CLK_FALL; break; - case CMD_READ_STATUS: - cmd->tx_cmd_sz = 1; - cmd->rx_cmd_sz = 1; + case 2: + cfgreg |= CAPT_ON_CLK_FALL; break; - case CMD_READ: - case CMD_FAST_READ: - cmd->rx_cmd_sz = cmd->tx_data_sz = 0; - break; - case CMD_SECTOR_ERASE: - cmd->rx_cmd_sz = 0; - break; - case CMD_PAGE_PROGRAM: - cmd->rx_cmd_sz = cmd->rx_data_sz = 0; - break; - } + } + + /* + * W25Q64CV max 104MHz, bus 120-192 MHz, so divide by 2. + * Update: divide by 4, DEV2 to fast for flash. + */ + if (clock != 0) { + div = (mtk_soc_get_cpuclk() + (clock - 1)) / clock; + clk = fls(div) - 2; + if (clk < 0) + clk = 0; + else if (clk > 6) + clk = 6; + } else { + clk = 6; + } + + SPI_WRITE(sc, MTK_SPICFG, cfgreg | clk); + + if (sc->nonflash == 0) { + /* There is always a command to transfer. */ + tx_buf = (uint8_t *)(cmd->tx_cmd); + + /* Perform some fixup because MTK dont support duplex SPI */ + switch(tx_buf[0]) { + case CMD_READ_IDENT: + cmd->tx_cmd_sz = 1; + cmd->rx_cmd_sz = 3; + break; + case CMD_ENTER_4B_MODE: + case CMD_EXIT_4B_MODE: + case CMD_WRITE_ENABLE: + case CMD_WRITE_DISABLE: + cmd->tx_cmd_sz = 1; + cmd->rx_cmd_sz = 0; + break; + case CMD_READ_STATUS: + cmd->tx_cmd_sz = 1; + cmd->rx_cmd_sz = 1; + break; + case CMD_READ: + case CMD_FAST_READ: + cmd->rx_cmd_sz = cmd->tx_data_sz = 0; + break; + case CMD_SECTOR_ERASE: + cmd->rx_cmd_sz = 0; + break; + case CMD_PAGE_PROGRAM: + cmd->rx_cmd_sz = cmd->rx_data_sz = 0; + break; + } + } mtk_spi_chip_activate(sc); if (cmd->tx_cmd_sz + cmd->rx_cmd_sz) { buf = (uint8_t *)(cmd->rx_cmd); tx_buf = (uint8_t *)(cmd->tx_cmd); - sz = cmd->tx_cmd_sz + cmd->rx_cmd_sz; + sz = cmd->tx_cmd_sz; + if (sc->nonflash == 0) + sz += cmd->rx_cmd_sz; for (i = 0; i < sz; i++) { if(i < cmd->tx_cmd_sz) { Modified: user/ngie/bug-237403/sys/netinet/netdump/netdump_client.c ============================================================================== --- user/ngie/bug-237403/sys/netinet/netdump/netdump_client.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/sys/netinet/netdump/netdump_client.c Tue May 21 00:07:53 2019 (r348023) @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include Modified: user/ngie/bug-237403/tests/sys/opencrypto/runtests.sh ============================================================================== --- user/ngie/bug-237403/tests/sys/opencrypto/runtests.sh Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/tests/sys/opencrypto/runtests.sh Tue May 21 00:07:53 2019 (r348023) @@ -81,7 +81,7 @@ if ! sysctl $cdas_sysctl=1; then fi echo "1..1" -if "$PYTHON" $(dirname $0)/cryptotest.py; then +if "$PYTHON" $(dirname $0)/cryptotest.py $CRYPTOTEST_ARGS; then echo "ok 1" else echo "not ok 1" Modified: user/ngie/bug-237403/tests/sys/sys/rb_test.c ============================================================================== --- user/ngie/bug-237403/tests/sys/sys/rb_test.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/tests/sys/sys/rb_test.c Tue May 21 00:07:53 2019 (r348023) @@ -69,7 +69,7 @@ ATF_TC_BODY(rb_test, tc) for (i = 0; i < ITER; i++) { tmp = malloc(sizeof(struct node)); - ATF_CHECK_MSG(tmp != NULL, "malloc failed"); + ATF_REQUIRE_MSG(tmp != NULL, "malloc failed"); do { tmp->key = arc4random_uniform(MAX-MIN); tmp->key += MIN; @@ -82,20 +82,22 @@ ATF_TC_BODY(rb_test, tc) if (tmp->key < min) min = tmp->key; } - ATF_CHECK_EQ(NULL, RB_INSERT(tree, &root, tmp)); + ATF_REQUIRE_EQ(NULL, RB_INSERT(tree, &root, tmp)); } ins = RB_MIN(tree, &root); + ATF_REQUIRE_MSG(ins != NULL, "RB_MIN error"); ATF_CHECK_EQ(min, ins->key); tmp = ins; ins = RB_MAX(tree, &root); + ATF_REQUIRE_MSG(ins != NULL, "RB_MAX error"); ATF_CHECK_EQ(max, ins->key); ATF_CHECK_EQ(tmp, RB_REMOVE(tree, &root, tmp)); for (i = 0; i < ITER - 1; i++) { tmp = RB_ROOT(&root); - ATF_CHECK_MSG(tmp != NULL, "RB_ROOT error"); + ATF_REQUIRE_MSG(tmp != NULL, "RB_ROOT error"); ATF_CHECK_EQ(tmp, RB_REMOVE(tree, &root, tmp)); free(tmp); } Modified: user/ngie/bug-237403/tests/sys/sys/splay_test.c ============================================================================== --- user/ngie/bug-237403/tests/sys/sys/splay_test.c Tue May 21 00:04:19 2019 (r348022) +++ user/ngie/bug-237403/tests/sys/sys/splay_test.c Tue May 21 00:07:53 2019 (r348023) @@ -69,7 +69,7 @@ ATF_TC_BODY(splay_test, tc) for (i = 0; i < ITER; i++) { tmp = malloc(sizeof(struct node)); - ATF_CHECK_MSG(tmp != NULL, "malloc failed"); + ATF_REQUIRE_MSG(tmp != NULL, "malloc failed"); do { tmp->key = arc4random_uniform(MAX-MIN); tmp->key += MIN; @@ -82,20 +82,22 @@ ATF_TC_BODY(splay_test, tc) if (tmp->key < min) min = tmp->key; } - ATF_CHECK_EQ(NULL, SPLAY_INSERT(tree, &root, tmp)); + ATF_REQUIRE_EQ(NULL, SPLAY_INSERT(tree, &root, tmp)); } ins = SPLAY_MIN(tree, &root); + ATF_REQUIRE_MSG(ins != NULL, "SPLAY_MIN error"); ATF_CHECK_EQ(min, ins->key); tmp = ins; ins = SPLAY_MAX(tree, &root); + ATF_REQUIRE_MSG(ins != NULL, "SPLAY_MAX error"); ATF_CHECK_EQ(max, ins->key); ATF_CHECK_EQ(tmp, SPLAY_REMOVE(tree, &root, tmp)); for (i = 0; i < ITER - 1; i++) { tmp = SPLAY_ROOT(&root); - ATF_CHECK_MSG(tmp != NULL, "SPLAY_ROOT error"); + ATF_REQUIRE_MSG(tmp != NULL, "SPLAY_ROOT error"); ATF_CHECK_EQ(tmp, SPLAY_REMOVE(tree, &root, tmp)); free(tmp); }