From owner-svn-src-stable-11@freebsd.org Sun Sep 10 20:13:21 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F1DB6E00182; Sun, 10 Sep 2017 20:13:21 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id BEC2984DA0; Sun, 10 Sep 2017 20:13:21 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8AKDKq0092364; Sun, 10 Sep 2017 20:13:20 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8AKDKsO092362; Sun, 10 Sep 2017 20:13:20 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709102013.v8AKDKsO092362@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 10 Sep 2017 20:13:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323395 - stable/11/share/man/man9 X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/share/man/man9 X-SVN-Commit-Revision: 323395 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 20:13:22 -0000 Author: ian Date: Sun Sep 10 20:13:20 2017 New Revision: 323395 URL: https://svnweb.freebsd.org/changeset/base/323395 Log: MFC r315089: Document uiomove_frombuf(9). Modified: stable/11/share/man/man9/Makefile stable/11/share/man/man9/uio.9 Directory Properties: stable/11/ (props changed) Modified: stable/11/share/man/man9/Makefile ============================================================================== --- stable/11/share/man/man9/Makefile Sun Sep 10 19:12:01 2017 (r323394) +++ stable/11/share/man/man9/Makefile Sun Sep 10 20:13:20 2017 (r323395) @@ -1791,6 +1791,7 @@ MLINKS+=uidinfo.9 uifind.9 \ uidinfo.9 uihashinit.9 \ uidinfo.9 uihold.9 MLINKS+=uio.9 uiomove.9 \ + uio.9 uiomove_frombuf.9 \ uio.9 uiomove_nofault.9 .if ${MK_USB} != "no" Modified: stable/11/share/man/man9/uio.9 ============================================================================== --- stable/11/share/man/man9/uio.9 Sun Sep 10 19:12:01 2017 (r323394) +++ stable/11/share/man/man9/uio.9 Sun Sep 10 20:13:20 2017 (r323395) @@ -25,12 +25,13 @@ .\" .\" $FreeBSD$ .\" -.Dd January 19, 2012 +.Dd March 11, 2017 .Dt UIO 9 .Os .Sh NAME .Nm uio , .Nm uiomove , +.Nm uiomove_frombuf , .Nm uiomove_nofault .Nd device driver I/O routines .Sh SYNOPSIS @@ -50,10 +51,13 @@ struct uio { .Ft int .Fn uiomove "void *buf" "int howmuch" "struct uio *uiop" .Ft int +.Fn uiomove_frombuf "void *buf" "int howmuch" "struct uio *uiop" +.Ft int .Fn uiomove_nofault "void *buf" "int howmuch" "struct uio *uiop" .Sh DESCRIPTION The functions -.Fn uiomove +.Fn uiomove , +.Fn uiomove_frombuf , and .Fn uiomove_nofault are used to transfer data between buffers and I/O vectors that might @@ -129,9 +133,27 @@ Thus, the function .Fn uiomove_nofault can be called from contexts where acquiring virtual memory system locks or sleeping are prohibited. +.Pp +The +.Fn uiomove_frombuf +function is a convenience wrapper around +.Fn uiomove +for drivers that serve data which is wholly contained within an +existing buffer in memory. +It validates the +.Va uio_offset +and +.Va uio_resid +values against the size of the existing buffer, handling short +transfers when the request partially overlaps the buffer. +When +.Va uio_offset +is greater than or equal to the buffer size, the result is success +with no bytes transfered, effectively signaling EOF. .Sh RETURN VALUES On success -.Fn uiomove +.Fn uiomove , +.Fn uiomove_frombuf , and .Fn uiomove_nofault will return 0; on error they will return an appropriate error code. From owner-svn-src-stable-11@freebsd.org Sun Sep 10 20:16:36 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DD0F7E00449; Sun, 10 Sep 2017 20:16:36 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id A99FF1EE; Sun, 10 Sep 2017 20:16:36 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8AKGZjR092519; Sun, 10 Sep 2017 20:16:35 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8AKGZuG092518; Sun, 10 Sep 2017 20:16:35 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709102016.v8AKGZuG092518@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 10 Sep 2017 20:16:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323396 - stable/11/sys/kern X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/kern X-SVN-Commit-Revision: 323396 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 20:16:37 -0000 Author: ian Date: Sun Sep 10 20:16:35 2017 New Revision: 323396 URL: https://svnweb.freebsd.org/changeset/base/323396 Log: MFC r315165: Correct the abbreviations for microseconds (us, not ms), and for Hz (not HZ). Modified: stable/11/sys/kern/vfs_subr.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/vfs_subr.c ============================================================================== --- stable/11/sys/kern/vfs_subr.c Sun Sep 10 20:13:20 2017 (r323395) +++ stable/11/sys/kern/vfs_subr.c Sun Sep 10 20:16:35 2017 (r323396) @@ -763,7 +763,7 @@ enum { TSP_SEC, TSP_HZ, TSP_USEC, TSP_NSEC }; static int timestamp_precision = TSP_USEC; SYSCTL_INT(_vfs, OID_AUTO, timestamp_precision, CTLFLAG_RW, ×tamp_precision, 0, "File timestamp precision (0: seconds, " - "1: sec + ns accurate to 1/HZ, 2: sec + ns truncated to ms, " + "1: sec + ns accurate to 1/Hz, 2: sec + ns truncated to us, " "3+: sec + ns (max. precision))"); /* From owner-svn-src-stable-11@freebsd.org Sun Sep 10 20:17:32 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BF9B7E004F7; Sun, 10 Sep 2017 20:17:32 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 894583EE; Sun, 10 Sep 2017 20:17:32 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8AKHVFO092591; Sun, 10 Sep 2017 20:17:31 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8AKHVrK092590; Sun, 10 Sep 2017 20:17:31 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709102017.v8AKHVrK092590@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 10 Sep 2017 20:17:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323397 - stable/11/sys/kern X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/kern X-SVN-Commit-Revision: 323397 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 20:17:32 -0000 Author: ian Date: Sun Sep 10 20:17:31 2017 New Revision: 323397 URL: https://svnweb.freebsd.org/changeset/base/323397 Log: MFC r315167: Change 'Hz' back to 'HZ'... it's referring to the kernel config option Modified: stable/11/sys/kern/vfs_subr.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/vfs_subr.c ============================================================================== --- stable/11/sys/kern/vfs_subr.c Sun Sep 10 20:16:35 2017 (r323396) +++ stable/11/sys/kern/vfs_subr.c Sun Sep 10 20:17:31 2017 (r323397) @@ -763,7 +763,7 @@ enum { TSP_SEC, TSP_HZ, TSP_USEC, TSP_NSEC }; static int timestamp_precision = TSP_USEC; SYSCTL_INT(_vfs, OID_AUTO, timestamp_precision, CTLFLAG_RW, ×tamp_precision, 0, "File timestamp precision (0: seconds, " - "1: sec + ns accurate to 1/Hz, 2: sec + ns truncated to us, " + "1: sec + ns accurate to 1/HZ, 2: sec + ns truncated to us, " "3+: sec + ns (max. precision))"); /* From owner-svn-src-stable-11@freebsd.org Sun Sep 10 23:04:56 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8805AE08951; Sun, 10 Sep 2017 23:04:56 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 568BD64A5A; Sun, 10 Sep 2017 23:04:56 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8AN4tN7087272; Sun, 10 Sep 2017 23:04:55 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8AN4t4c087271; Sun, 10 Sep 2017 23:04:55 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709102304.v8AN4t4c087271@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 10 Sep 2017 23:04:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323399 - stable/11/sys/modules/dtb/imx6 X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/modules/dtb/imx6 X-SVN-Commit-Revision: 323399 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 23:04:56 -0000 Author: ian Date: Sun Sep 10 23:04:55 2017 New Revision: 323399 URL: https://svnweb.freebsd.org/changeset/base/323399 Log: MFC r314723: Build the dtb files for the revb1 versions of wandboard. Modified: stable/11/sys/modules/dtb/imx6/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/modules/dtb/imx6/Makefile ============================================================================== --- stable/11/sys/modules/dtb/imx6/Makefile Sun Sep 10 20:33:23 2017 (r323398) +++ stable/11/sys/modules/dtb/imx6/Makefile Sun Sep 10 23:04:55 2017 (r323399) @@ -10,6 +10,8 @@ DTS= \ imx6q-nitrogen6x.dts \ imx6dl-riotboard.dts \ imx6dl-wandboard.dts \ - imx6q-wandboard.dts + imx6dl-wandboard-revb1.dts \ + imx6q-wandboard.dts \ + imx6q-wandboard-revb1.dts \ .include From owner-svn-src-stable-11@freebsd.org Sun Sep 10 23:09:18 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ABE17E08C46; Sun, 10 Sep 2017 23:09:18 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 84EB864BF9; Sun, 10 Sep 2017 23:09:18 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8AN9HZ9087458; Sun, 10 Sep 2017 23:09:17 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8AN9HN5087456; Sun, 10 Sep 2017 23:09:17 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709102309.v8AN9HN5087456@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 10 Sep 2017 23:09:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323400 - stable/11/sys/arm/freescale/imx X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/freescale/imx X-SVN-Commit-Revision: 323400 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 23:09:18 -0000 Author: ian Date: Sun Sep 10 23:09:17 2017 New Revision: 323400 URL: https://svnweb.freebsd.org/changeset/base/323400 Log: MFC r315490, r315508: Make the imx5 clocks driver work with vendor-supplied dts (which does not supply the addresses for the DPLL register blocks) by hard-coding the addresses in the driver source code. Yes, this is just as bad an idea as it sounds, but we have no choice. Remove hardcoded bootverbose=1; imx53 systems boot using loader(8) and users can set verbose if they want to. Modified: stable/11/sys/arm/freescale/imx/imx51_ccm.c stable/11/sys/arm/freescale/imx/imx53_machdep.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/imx51_ccm.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx51_ccm.c Sun Sep 10 23:04:55 2017 (r323399) +++ stable/11/sys/arm/freescale/imx/imx51_ccm.c Sun Sep 10 23:09:17 2017 (r323400) @@ -78,6 +78,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -96,10 +97,34 @@ __FBSDID("$FreeBSD$"); #define IMX51_CKIL_FREQ 32768 #endif +/* + * The fdt data does not provide reg properties describing the DPLL register + * blocks we need to access, presumably because the needed addresses are + * hard-coded within the linux driver. That leaves us with no choice but to do + * the same thing, if we want to run with vendor-supplied fdt data. So here we + * have tables of the physical addresses we need for each soc, and we'll use + * bus_space_map() at attach() time to get access to them. + */ +static uint32_t imx51_dpll_addrs[IMX51_N_DPLLS] = { + 0x83f80000, /* DPLL1 */ + 0x83f84000, /* DPLL2 */ + 0x83f88000, /* DPLL3 */ +}; + +static uint32_t imx53_dpll_addrs[IMX51_N_DPLLS] = { + 0x63f80000, /* DPLL1 */ + 0x63f84000, /* DPLL2 */ + 0x63f88000, /* DPLL3 */ +}; + +#define DPLL_REGS_SZ (16 * 1024) + struct imxccm_softc { device_t sc_dev; - struct resource *res[7]; + struct resource *ccmregs; u_int64_t pll_freq[IMX51_N_DPLLS]; + bus_space_tag_t pllbst; + bus_space_handle_t pllbsh[IMX51_N_DPLLS]; }; struct imxccm_softc *ccm_softc = NULL; @@ -127,16 +152,27 @@ static devclass_t imxccm_devclass; EARLY_DRIVER_MODULE(imxccm, simplebus, imxccm_driver, imxccm_devclass, 0, 0, BUS_PASS_CPU); -static struct resource_spec imxccm_spec[] = { - { SYS_RES_MEMORY, 0, RF_ACTIVE }, /* Global registers */ - { SYS_RES_MEMORY, 1, RF_ACTIVE }, /* DPLLIP1 */ - { SYS_RES_MEMORY, 2, RF_ACTIVE }, /* DPLLIP2 */ - { SYS_RES_MEMORY, 3, RF_ACTIVE }, /* DPLLIP3 */ - { SYS_RES_IRQ, 0, RF_ACTIVE }, /* 71 */ - { SYS_RES_IRQ, 1, RF_ACTIVE }, /* 72 */ - { -1, 0 } -}; +static inline uint32_t +pll_read_4(struct imxccm_softc *sc, int pll, int reg) +{ + return (bus_space_read_4(sc->pllbst, sc->pllbsh[pll - 1], reg)); +} + +static inline uint32_t +ccm_read_4(struct imxccm_softc *sc, int reg) +{ + + return (bus_read_4(sc->ccmregs, reg)); +} + +static inline void +ccm_write_4(struct imxccm_softc *sc, int reg, uint32_t val) +{ + + bus_write_4(sc->ccmregs, reg, val); +} + static int imxccm_match(device_t dev) { @@ -156,15 +192,42 @@ static int imxccm_attach(device_t dev) { struct imxccm_softc *sc; + int idx; + u_int soc; + uint32_t *pll_addrs; sc = device_get_softc(dev); sc->sc_dev = dev; - if (bus_alloc_resources(dev, imxccm_spec, sc->res)) { + switch ((soc = imx_soc_type())) { + case IMXSOC_51: + pll_addrs = imx51_dpll_addrs; + break; + case IMXSOC_53: + pll_addrs = imx53_dpll_addrs; + break; + default: + device_printf(dev, "No support for SoC type 0x%08x\n", soc); + goto noclocks; + } + + idx = 0; + sc->ccmregs = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &idx, + RF_ACTIVE); + if (sc->ccmregs == NULL) { device_printf(dev, "could not allocate resources\n"); - return (ENXIO); + goto noclocks; } + sc->pllbst = fdtbus_bs_tag; + for (idx = 0; idx < IMX51_N_DPLLS; ++idx) { + if (bus_space_map(sc->pllbst, pll_addrs[idx], DPLL_REGS_SZ, 0, + &sc->pllbsh[idx]) != 0) { + device_printf(dev, "Cannot map DPLL registers\n"); + goto noclocks; + } + } + ccm_softc = sc; imx51_get_pll_freq(1); @@ -187,6 +250,10 @@ imxccm_attach(device_t dev) return (0); + +noclocks: + + panic("Cannot continue without clock support"); } u_int @@ -211,13 +278,13 @@ imx51_get_clock(enum imx51_clock clk) case IMX51CLK_PLL3: return ccm_softc->pll_freq[clk-IMX51CLK_PLL1]; case IMX51CLK_PLL1SW: - ccsr = bus_read_4(ccm_softc->res[0], CCMC_CCSR); + ccsr = ccm_read_4(ccm_softc, CCMC_CCSR); if ((ccsr & CCSR_PLL1_SW_CLK_SEL) == 0) return ccm_softc->pll_freq[1-1]; /* step clock */ /* FALLTHROUGH */ case IMX51CLK_PLL1STEP: - ccsr = bus_read_4(ccm_softc->res[0], CCMC_CCSR); + ccsr = ccm_read_4(ccm_softc, CCMC_CCSR); switch ((ccsr & CCSR_STEP_SEL_MASK) >> CCSR_STEP_SEL_SHIFT) { case 0: return imx51_get_clock(IMX51CLK_LP_APM); @@ -234,34 +301,34 @@ imx51_get_clock(enum imx51_clock clk) } /*NOTREACHED*/ case IMX51CLK_PLL2SW: - ccsr = bus_read_4(ccm_softc->res[0], CCMC_CCSR); + ccsr = ccm_read_4(ccm_softc, CCMC_CCSR); if ((ccsr & CCSR_PLL2_SW_CLK_SEL) == 0) return imx51_get_clock(IMX51CLK_PLL2); return 0; /* XXX PLL2 bypass clk */ case IMX51CLK_PLL3SW: - ccsr = bus_read_4(ccm_softc->res[0], CCMC_CCSR); + ccsr = ccm_read_4(ccm_softc, CCMC_CCSR); if ((ccsr & CCSR_PLL3_SW_CLK_SEL) == 0) return imx51_get_clock(IMX51CLK_PLL3); return 0; /* XXX PLL3 bypass clk */ case IMX51CLK_LP_APM: - ccsr = bus_read_4(ccm_softc->res[0], CCMC_CCSR); + ccsr = ccm_read_4(ccm_softc, CCMC_CCSR); return (ccsr & CCSR_LP_APM) ? imx51_get_clock(IMX51CLK_FPM) : IMX51_OSC_FREQ; case IMX51CLK_ARM_ROOT: freq = imx51_get_clock(IMX51CLK_PLL1SW); - cacrr = bus_read_4(ccm_softc->res[0], CCMC_CACRR); + cacrr = ccm_read_4(ccm_softc, CCMC_CACRR); return freq / (cacrr + 1); /* ... */ case IMX51CLK_MAIN_BUS_CLK_SRC: - cbcdr = bus_read_4(ccm_softc->res[0], CCMC_CBCDR); + cbcdr = ccm_read_4(ccm_softc, CCMC_CBCDR); if ((cbcdr & CBCDR_PERIPH_CLK_SEL) == 0) freq = imx51_get_clock(IMX51CLK_PLL2SW); else { freq = 0; - cbcmr = bus_read_4(ccm_softc->res[0], CCMC_CBCMR); + cbcmr = ccm_read_4(ccm_softc, CCMC_CBCMR); switch ((cbcmr & CBCMR_PERIPH_APM_SEL_MASK) >> CBCMR_PERIPH_APM_SEL_SHIFT) { case 0: @@ -281,29 +348,29 @@ imx51_get_clock(enum imx51_clock clk) return freq; case IMX51CLK_MAIN_BUS_CLK: freq = imx51_get_clock(IMX51CLK_MAIN_BUS_CLK_SRC); - cdcr = bus_read_4(ccm_softc->res[0], CCMC_CDCR); + cdcr = ccm_read_4(ccm_softc, CCMC_CDCR); return freq / (1 + ((cdcr & CDCR_PERIPH_CLK_DVFS_PODF_MASK) >> CDCR_PERIPH_CLK_DVFS_PODF_SHIFT)); case IMX51CLK_AHB_CLK_ROOT: freq = imx51_get_clock(IMX51CLK_MAIN_BUS_CLK); - cbcdr = bus_read_4(ccm_softc->res[0], CCMC_CBCDR); + cbcdr = ccm_read_4(ccm_softc, CCMC_CBCDR); return freq / (1 + ((cbcdr & CBCDR_AHB_PODF_MASK) >> CBCDR_AHB_PODF_SHIFT)); case IMX51CLK_IPG_CLK_ROOT: freq = imx51_get_clock(IMX51CLK_AHB_CLK_ROOT); - cbcdr = bus_read_4(ccm_softc->res[0], CCMC_CBCDR); + cbcdr = ccm_read_4(ccm_softc, CCMC_CBCDR); return freq / (1 + ((cbcdr & CBCDR_IPG_PODF_MASK) >> CBCDR_IPG_PODF_SHIFT)); case IMX51CLK_PERCLK_ROOT: - cbcmr = bus_read_4(ccm_softc->res[0], CCMC_CBCMR); + cbcmr = ccm_read_4(ccm_softc, CCMC_CBCMR); if (cbcmr & CBCMR_PERCLK_IPG_SEL) return imx51_get_clock(IMX51CLK_IPG_CLK_ROOT); if (cbcmr & CBCMR_PERCLK_LP_APM_SEL) freq = imx51_get_clock(IMX51CLK_LP_APM); else freq = imx51_get_clock(IMX51CLK_MAIN_BUS_CLK_SRC); - cbcdr = bus_read_4(ccm_softc->res[0], CCMC_CBCDR); + cbcdr = ccm_read_4(ccm_softc, CCMC_CBCDR); #ifdef IMXCCMDEBUG printf("cbcmr=%x cbcdr=%x\n", cbcmr, cbcdr); @@ -317,8 +384,8 @@ imx51_get_clock(enum imx51_clock clk) CBCDR_PERCLK_PODF_SHIFT); return freq; case IMX51CLK_UART_CLK_ROOT: - cscdr1 = bus_read_4(ccm_softc->res[0], CCMC_CSCDR1); - cscmr1 = bus_read_4(ccm_softc->res[0], CCMC_CSCMR1); + cscdr1 = ccm_read_4(ccm_softc, CCMC_CSCDR1); + cscmr1 = ccm_read_4(ccm_softc, CCMC_CSCMR1); #ifdef IMXCCMDEBUG printf("cscdr1=%x cscmr1=%x\n", cscdr1, cscmr1); @@ -345,7 +412,7 @@ imx51_get_clock(enum imx51_clock clk) CSCDR1_UART_CLK_PODF_SHIFT)); case IMX51CLK_IPU_HSP_CLK_ROOT: freq = 0; - cbcmr = bus_read_4(ccm_softc->res[0], CCMC_CBCMR); + cbcmr = ccm_read_4(ccm_softc, CCMC_CBCMR); switch ((cbcmr & CBCMR_IPU_HSP_CLK_SEL_MASK) >> CBCMR_IPU_HSP_CLK_SEL_SHIFT) { case 0: @@ -388,16 +455,16 @@ imx51_get_pll_freq(u_int pll_no) KASSERT(1 <= pll_no && pll_no <= IMX51_N_DPLLS, ("Wrong PLL id")); - dp_ctrl = bus_read_4(ccm_softc->res[pll_no], DPLL_DP_CTL); + dp_ctrl = pll_read_4(ccm_softc, pll_no, DPLL_DP_CTL); if (dp_ctrl & DP_CTL_HFSM) { - dp_op = bus_read_4(ccm_softc->res[pll_no], DPLL_DP_HFS_OP); - dp_mfd = bus_read_4(ccm_softc->res[pll_no], DPLL_DP_HFS_MFD); - dp_mfn = bus_read_4(ccm_softc->res[pll_no], DPLL_DP_HFS_MFN); + dp_op = pll_read_4(ccm_softc, pll_no, DPLL_DP_HFS_OP); + dp_mfd = pll_read_4(ccm_softc, pll_no, DPLL_DP_HFS_MFD); + dp_mfn = pll_read_4(ccm_softc, pll_no, DPLL_DP_HFS_MFN); } else { - dp_op = bus_read_4(ccm_softc->res[pll_no], DPLL_DP_OP); - dp_mfd = bus_read_4(ccm_softc->res[pll_no], DPLL_DP_MFD); - dp_mfn = bus_read_4(ccm_softc->res[pll_no], DPLL_DP_MFN); + dp_op = pll_read_4(ccm_softc, pll_no, DPLL_DP_OP); + dp_mfd = pll_read_4(ccm_softc, pll_no, DPLL_DP_MFD); + dp_mfn = pll_read_4(ccm_softc, pll_no, DPLL_DP_MFN); } pdf = dp_op & DP_OP_PDF_MASK; @@ -416,7 +483,7 @@ imx51_get_pll_freq(u_int pll_no) ref = 24000000; /* IMX51_OSC_FREQ */ break; case DP_CTL_REF_CLK_SEL_FPM: - ccr = bus_read_4(ccm_softc->res[0], CCMC_CCR); + ccr = ccm_read_4(ccm_softc, CCMC_CCR); if (ccr & CCR_FPM_MULT) /* TODO: get from FDT "fsl,imx-ckil" */ ref = 32768 * 1024; @@ -461,10 +528,10 @@ imx51_clk_gating(int clk_src, int mode) group = CCMR_CCGR_MODULE(clk_src); field = clk_src % CCMR_CCGR_NSOURCE; - reg = bus_read_4(ccm_softc->res[0], CCMC_CCGR(group)); + reg = ccm_read_4(ccm_softc, CCMC_CCGR(group)); reg &= ~(0x03 << field * 2); reg |= (mode << field * 2); - bus_write_4(ccm_softc->res[0], CCMC_CCGR(group), reg); + ccm_write_4(ccm_softc, CCMC_CCGR(group), reg); } int @@ -472,7 +539,7 @@ imx51_get_clk_gating(int clk_src) { uint32_t reg; - reg = bus_read_4(ccm_softc->res[0], + reg = ccm_read_4(ccm_softc, CCMC_CCGR(CCMR_CCGR_MODULE(clk_src))); return ((reg >> (clk_src % CCMR_CCGR_NSOURCE) * 2) & 0x03); } @@ -490,20 +557,20 @@ imx_ccm_usb_enable(device_t dev) * Select PLL2 as the source for the USB clock. * The default is PLL3, but U-boot changes it to PLL2. */ - regval = bus_read_4(ccm_softc->res[0], CCMC_CSCMR1); + regval = ccm_read_4(ccm_softc, CCMC_CSCMR1); regval &= ~CSCMR1_USBOH3_CLK_SEL_MASK; regval |= 1 << CSCMR1_USBOH3_CLK_SEL_SHIFT; - bus_write_4(ccm_softc->res[0], CCMC_CSCMR1, regval); + ccm_write_4(ccm_softc, CCMC_CSCMR1, regval); /* * Set the USB clock pre-divider to div-by-5, post-divider to div-by-2. */ - regval = bus_read_4(ccm_softc->res[0], CCMC_CSCDR1); + regval = ccm_read_4(ccm_softc, CCMC_CSCDR1); regval &= ~CSCDR1_USBOH3_CLK_PODF_MASK; regval &= ~CSCDR1_USBOH3_CLK_PRED_MASK; regval |= 4 << CSCDR1_USBOH3_CLK_PRED_SHIFT; regval |= 1 << CSCDR1_USBOH3_CLK_PODF_SHIFT; - bus_write_4(ccm_softc->res[0], CCMC_CSCDR1, regval); + ccm_write_4(ccm_softc, CCMC_CSCDR1, regval); /* * The same two clocks gates are used on imx51 and imx53. @@ -523,9 +590,9 @@ imx_ccm_usbphy_enable(device_t dev) * strange, but we'll go with it until more is known. */ if (imx_soc_type() == IMXSOC_53) { - regval = bus_read_4(ccm_softc->res[0], CCMC_CSCMR1); + regval = ccm_read_4(ccm_softc, CCMC_CSCMR1); regval |= 1 << CSCMR1_USBPHY_CLK_SEL_SHIFT; - bus_write_4(ccm_softc->res[0], CCMC_CSCMR1, regval); + ccm_write_4(ccm_softc, CCMC_CSCMR1, regval); } /* Modified: stable/11/sys/arm/freescale/imx/imx53_machdep.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx53_machdep.c Sun Sep 10 23:04:55 2017 (r323399) +++ stable/11/sys/arm/freescale/imx/imx53_machdep.c Sun Sep 10 23:09:17 2017 (r323400) @@ -56,10 +56,6 @@ static int imx53_attach(platform_t plat) { - /* XXX - Get rid of this stuff soon. */ - boothowto |= RB_VERBOSE|RB_MULTIPLE; - bootverbose = 1; - return (0); } From owner-svn-src-stable-11@freebsd.org Sun Sep 10 23:12:08 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 603B7E08F2F; Sun, 10 Sep 2017 23:12:08 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 2F46D64F46; Sun, 10 Sep 2017 23:12:08 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8ANC7S4090490; Sun, 10 Sep 2017 23:12:07 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8ANC7dG090489; Sun, 10 Sep 2017 23:12:07 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709102312.v8ANC7dG090489@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 10 Sep 2017 23:12:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323401 - stable/11/sys/arm/freescale/imx X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/freescale/imx X-SVN-Commit-Revision: 323401 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 23:12:08 -0000 Author: ian Date: Sun Sep 10 23:12:07 2017 New Revision: 323401 URL: https://svnweb.freebsd.org/changeset/base/323401 Log: MFC r315530: Remove unreferenced global function imx_gpt_get_timerfreq() and do some cleanups enabled by that. Deleted: stable/11/sys/arm/freescale/imx/imx_gptvar.h Modified: stable/11/sys/arm/freescale/imx/imx_gpt.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/imx_gpt.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_gpt.c Sun Sep 10 23:09:17 2017 (r323400) +++ stable/11/sys/arm/freescale/imx/imx_gpt.c Sun Sep 10 23:12:07 2017 (r323401) @@ -35,13 +35,10 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include -#include #include -#include #include #include @@ -49,12 +46,9 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include #include -#include -#include - #define WRITE4(_sc, _r, _v) \ bus_space_write_4((_sc)->sc_iot, (_sc)->sc_ioh, (_r), (_v)) #define READ4(_sc, _r) \ @@ -81,8 +75,20 @@ static struct timecounter imx_gpt_timecounter = { .tc_quality = 1000, }; +struct imx_gpt_softc { + device_t sc_dev; + struct resource * res[2]; + bus_space_tag_t sc_iot; + bus_space_handle_t sc_ioh; + void * sc_ih; /* interrupt handler */ + uint32_t sc_period; + uint32_t sc_clksrc; + uint32_t clkfreq; + struct eventtimer et; +}; + /* Global softc pointer for use in DELAY(). */ -struct imx_gpt_softc *imx_gpt_sc = NULL; +static struct imx_gpt_softc *imx_gpt_sc; /* * Hand-calibrated delay-loop counter. This was calibrated on an i.MX6 running @@ -107,7 +113,7 @@ static struct resource_spec imx_gpt_spec[] = { }; static struct ofw_compat_data compat_data[] = { - {"fsl,imx6dl-gpt", 1}, + {"fsl,imx6dl-gpt", 1}, {"fsl,imx6q-gpt", 1}, {"fsl,imx53-gpt", 1}, {"fsl,imx51-gpt", 1}, @@ -310,13 +316,6 @@ imx_gpt_timer_stop(struct eventtimer *et) sc->sc_period = 0; return (0); -} - -int -imx_gpt_get_timerfreq(struct imx_gpt_softc *sc) -{ - - return (sc->clkfreq); } static int From owner-svn-src-stable-11@freebsd.org Sun Sep 10 23:31:22 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E32B7E09B86; Sun, 10 Sep 2017 23:31:22 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id AD45065786; Sun, 10 Sep 2017 23:31:22 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8ANVLRc098546; Sun, 10 Sep 2017 23:31:21 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8ANVLUb098545; Sun, 10 Sep 2017 23:31:21 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709102331.v8ANVLUb098545@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 10 Sep 2017 23:31:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323402 - in stable/11/sys: arm/conf modules/dtb/imx5 X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: arm/conf modules/dtb/imx5 X-SVN-Commit-Revision: 323402 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 23:31:23 -0000 Author: ian Date: Sun Sep 10 23:31:21 2017 New Revision: 323402 URL: https://svnweb.freebsd.org/changeset/base/323402 Log: MFC r315572, r315573, r315575, r315578: Add a module to build imx5 dtb files. Add dtb/imx5 module build to the IMX53 kernel config. Remove configs for IMX53-QSB and DIGI-CCWMX53. They were just standard IMX53 with static dtb added, and now that imx53 can use vendor- supplied dts files and ubldr, there is no need for a static-dtb variant. Added: stable/11/sys/modules/dtb/imx5/ - copied from r315578, head/sys/modules/dtb/imx5/ Deleted: stable/11/sys/arm/conf/DIGI-CCWMX53 stable/11/sys/arm/conf/IMX53-QSB Modified: stable/11/sys/arm/conf/IMX53 Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/conf/IMX53 ============================================================================== --- stable/11/sys/arm/conf/IMX53 Sun Sep 10 23:12:07 2017 (r323401) +++ stable/11/sys/arm/conf/IMX53 Sun Sep 10 23:31:21 2017 (r323402) @@ -117,3 +117,4 @@ device wlan_amrr # AMRR transmit rate control algori # Flattened Device Tree options FDT # Configure using FDT/DTB data +makeoptions MODULES_EXTRA=dtb/imx5 From owner-svn-src-stable-11@freebsd.org Sun Sep 10 23:41:24 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EA8ADE0A74B; Sun, 10 Sep 2017 23:41:24 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id C4EEF65CC0; Sun, 10 Sep 2017 23:41:24 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8ANfNZc000767; Sun, 10 Sep 2017 23:41:23 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8ANfN56000764; Sun, 10 Sep 2017 23:41:23 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709102341.v8ANfN56000764@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 10 Sep 2017 23:41:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323403 - in stable/11/sys: arm/conf arm/freescale/imx boot/fdt/dts/arm X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: arm/conf arm/freescale/imx boot/fdt/dts/arm X-SVN-Commit-Revision: 323403 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 23:41:25 -0000 Author: ian Date: Sun Sep 10 23:41:23 2017 New Revision: 323403 URL: https://svnweb.freebsd.org/changeset/base/323403 Log: MFC r315574, r315576, r315577: Convert the imx5 interrupt controller driver to INTRNG. Add INTRNG option to EFIKA_MX config, it is an imx5-based platform. Delete our local imx53-qsb.dts file; the code now runs fine using the standard vendor-supplied file in sys/gnu/dts/arm. Deleted: stable/11/sys/boot/fdt/dts/arm/imx53-qsb.dts Modified: stable/11/sys/arm/conf/EFIKA_MX stable/11/sys/arm/conf/IMX53 stable/11/sys/arm/freescale/imx/tzic.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/conf/EFIKA_MX ============================================================================== --- stable/11/sys/arm/conf/EFIKA_MX Sun Sep 10 23:31:21 2017 (r323402) +++ stable/11/sys/arm/conf/EFIKA_MX Sun Sep 10 23:41:23 2017 (r323403) @@ -130,3 +130,5 @@ options SC_DFLT_FONT # compile font in makeoptions SC_DFLT_FONT=cp437 device ukbd # Allow keyboard like HIDs to control console device ums + +options INTRNG Modified: stable/11/sys/arm/conf/IMX53 ============================================================================== --- stable/11/sys/arm/conf/IMX53 Sun Sep 10 23:31:21 2017 (r323402) +++ stable/11/sys/arm/conf/IMX53 Sun Sep 10 23:41:23 2017 (r323403) @@ -118,3 +118,5 @@ device wlan_amrr # AMRR transmit rate control algori # Flattened Device Tree options FDT # Configure using FDT/DTB data makeoptions MODULES_EXTRA=dtb/imx5 + +options INTRNG Modified: stable/11/sys/arm/freescale/imx/tzic.c ============================================================================== --- stable/11/sys/arm/freescale/imx/tzic.c Sun Sep 10 23:31:21 2017 (r323402) +++ stable/11/sys/arm/freescale/imx/tzic.c Sun Sep 10 23:41:23 2017 (r323403) @@ -34,14 +34,12 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include -#include #include -#include #include #include + #include #include @@ -52,28 +50,180 @@ __FBSDID("$FreeBSD$"); #include -struct tzic_softc { - struct resource * tzic_res[3]; - bus_space_tag_t tzic_bst; - bus_space_handle_t tzic_bsh; - uint8_t ver; +#include "pic_if.h" + +#define TZIC_NIRQS 128 + +struct tzic_irqsrc { + struct intr_irqsrc isrc; + u_int irq; }; -static struct resource_spec tzic_spec[] = { - { SYS_RES_MEMORY, 0, RF_ACTIVE }, - { -1, 0 } +struct tzic_softc { + device_t dev; + struct resource *tzicregs; + struct tzic_irqsrc isrcs[TZIC_NIRQS]; }; -static struct tzic_softc *tzic_sc = NULL; +static struct tzic_softc *tzic_sc; -#define tzic_read_4(reg) \ - bus_space_read_4(tzic_sc->tzic_bst, tzic_sc->tzic_bsh, reg) -#define tzic_write_4(reg, val) \ - bus_space_write_4(tzic_sc->tzic_bst, tzic_sc->tzic_bsh, reg, val) +static inline uint32_t +tzic_read_4(struct tzic_softc *sc, int reg) +{ -static void tzic_post_filter(void *); + return (bus_read_4(sc->tzicregs, reg)); +} +static inline void +tzic_write_4(struct tzic_softc *sc, int reg, uint32_t val) +{ + + bus_write_4(sc->tzicregs, reg, val); +} + +static inline void +tzic_irq_eoi(struct tzic_softc *sc) +{ + + tzic_write_4(sc, TZIC_PRIOMASK, 0xff); +} + +static inline void +tzic_irq_mask(struct tzic_softc *sc, u_int irq) +{ + + tzic_write_4(sc, TZIC_ENCLEAR(irq >> 5), (1u << (irq & 0x1f))); +} + +static inline void +tzic_irq_unmask(struct tzic_softc *sc, u_int irq) +{ + + tzic_write_4(sc, TZIC_ENSET(irq >> 5), (1u << (irq & 0x1f))); +} + static int +tzic_intr(void *arg) +{ + struct tzic_softc *sc = arg; + int b, i, irq; + uint32_t pending; + + /* Get active interrupt */ + for (i = 0; i < TZIC_NIRQS / 32; ++i) { + pending = tzic_read_4(sc, TZIC_PND(i)); + if ((b = 31 - __builtin_clz(pending)) < 0) + continue; + irq = i * 32 + b; + tzic_write_4(sc, TZIC_PRIOMASK, 0); + if (intr_isrc_dispatch(&sc->isrcs[irq].isrc, + curthread->td_intr_frame) != 0) { + tzic_irq_mask(sc, irq); + tzic_irq_eoi(sc); + arm_irq_memory_barrier(irq); + if (bootverbose) { + device_printf(sc->dev, + "Stray irq %u disabled\n", irq); + } + } + return (FILTER_HANDLED); + } + + if (bootverbose) + device_printf(sc->dev, "Spurious interrupt detected\n"); + + return (FILTER_HANDLED); +} + +static void +tzic_enable_intr(device_t dev, struct intr_irqsrc *isrc) +{ + u_int irq = ((struct tzic_irqsrc *)isrc)->irq; + struct tzic_softc *sc = device_get_softc(dev); + + arm_irq_memory_barrier(irq); + tzic_irq_unmask(sc, irq); +} + +static void +tzic_disable_intr(device_t dev, struct intr_irqsrc *isrc) +{ + u_int irq = ((struct tzic_irqsrc *)isrc)->irq; + struct tzic_softc *sc = device_get_softc(dev); + + tzic_irq_mask(sc, irq); +} + +static int +tzic_map_intr(device_t dev, struct intr_map_data *data, + struct intr_irqsrc **isrcp) +{ + struct intr_map_data_fdt *daf; + struct tzic_softc *sc; + + if (data->type != INTR_MAP_DATA_FDT) + return (ENOTSUP); + + daf = (struct intr_map_data_fdt *)data; + if (daf->ncells != 1 || daf->cells[0] >= TZIC_NIRQS) + return (EINVAL); + + sc = device_get_softc(dev); + *isrcp = &sc->isrcs[daf->cells[0]].isrc; + + return (0); +} + +static void +tzic_pre_ithread(device_t dev, struct intr_irqsrc *isrc) +{ + struct tzic_softc *sc = device_get_softc(dev); + + tzic_irq_mask(sc, ((struct tzic_irqsrc *)isrc)->irq); + tzic_irq_eoi(sc); +} + +static void +tzic_post_ithread(device_t dev, struct intr_irqsrc *isrc) +{ + + tzic_enable_intr(dev, isrc); +} + +static void +tzic_post_filter(device_t dev, struct intr_irqsrc *isrc) +{ + + tzic_irq_eoi(device_get_softc(dev)); +} + +static int +tzic_pic_attach(struct tzic_softc *sc) +{ + struct intr_pic *pic; + const char *name; + intptr_t xref; + int error; + u_int irq; + + name = device_get_nameunit(sc->dev); + for (irq = 0; irq < TZIC_NIRQS; irq++) { + sc->isrcs[irq].irq = irq; + error = intr_isrc_register(&sc->isrcs[irq].isrc, + sc->dev, 0, "%s,%u", name, irq); + if (error != 0) + return (error); + } + + xref = OF_xref_from_node(ofw_bus_get_node(sc->dev)); + pic = intr_pic_register(sc->dev, xref); + if (pic == NULL) + return (ENXIO); + + return (intr_pic_claim_root(sc->dev, xref, tzic_intr, sc, 0)); +} + +static int tzic_probe(device_t dev) { @@ -90,50 +240,63 @@ tzic_probe(device_t dev) static int tzic_attach(device_t dev) { - struct tzic_softc *sc = device_get_softc(dev); - int i; - uint32_t reg; + struct tzic_softc *sc = device_get_softc(dev); + int i; if (tzic_sc) return (ENXIO); + tzic_sc = sc; + sc->dev = dev; - if (bus_alloc_resources(dev, tzic_spec, sc->tzic_res)) { + i = 0; + sc->tzicregs = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &i, + RF_ACTIVE); + if (sc->tzicregs == NULL) { device_printf(dev, "could not allocate resources\n"); return (ENXIO); } - arm_post_filter = tzic_post_filter; - - /* Distributor Interface */ - sc->tzic_bst = rman_get_bustag(sc->tzic_res[0]); - sc->tzic_bsh = rman_get_bushandle(sc->tzic_res[0]); - - tzic_sc = sc; - - reg = tzic_read_4(TZIC_INTCNTL); - tzic_write_4(TZIC_INTCNTL, INTCNTL_NSEN_MASK|INTCNTL_NSEN|INTCNTL_EN); - reg = tzic_read_4(TZIC_INTCNTL); - tzic_write_4(TZIC_PRIOMASK, 0x1f); - reg = tzic_read_4(TZIC_PRIOMASK); - - tzic_write_4(TZIC_SYNCCTRL, 0x02); - reg = tzic_read_4(TZIC_SYNCCTRL); - /* route all interrupts to IRQ. secure interrupts are for FIQ */ for (i = 0; i < 4; i++) - tzic_write_4(TZIC_INTSEC(i), 0xffffffff); + tzic_write_4(sc, TZIC_INTSEC(i), 0xffffffff); /* disable all interrupts */ for (i = 0; i < 4; i++) - tzic_write_4(TZIC_ENCLEAR(i), 0xffffffff); + tzic_write_4(sc, TZIC_ENCLEAR(i), 0xffffffff); + /* Set all interrupts to priority 0 (max). */ + for (i = 0; i < 128 / 4; ++i) + tzic_write_4(sc, TZIC_PRIORITY(i), 0); + + /* + * Set priority mask to lowest (unmasked) prio, set synchronizer to + * low-latency mode (as opposed to low-power), enable the controller. + */ + tzic_write_4(sc, TZIC_PRIOMASK, 0xff); + tzic_write_4(sc, TZIC_SYNCCTRL, 0); + tzic_write_4(sc, TZIC_INTCNTL, INTCNTL_NSEN_MASK|INTCNTL_NSEN|INTCNTL_EN); + + /* Register as a root pic. */ + if (tzic_pic_attach(sc) != 0) { + device_printf(dev, "could not attach PIC\n"); + return (ENXIO); + } + return (0); } static device_method_t tzic_methods[] = { DEVMETHOD(device_probe, tzic_probe), DEVMETHOD(device_attach, tzic_attach), - { 0, 0 } + + DEVMETHOD(pic_disable_intr, tzic_disable_intr), + DEVMETHOD(pic_enable_intr, tzic_enable_intr), + DEVMETHOD(pic_map_intr, tzic_map_intr), + DEVMETHOD(pic_post_filter, tzic_post_filter), + DEVMETHOD(pic_post_ithread, tzic_post_ithread), + DEVMETHOD(pic_pre_ithread, tzic_pre_ithread), + + DEVMETHOD_END }; static driver_t tzic_driver = { @@ -144,48 +307,5 @@ static driver_t tzic_driver = { static devclass_t tzic_devclass; -/* - * Memory space of controller located outside of device range, so let him to - * attach not only to simplebus, but ofwbus also. - */ EARLY_DRIVER_MODULE(tzic, ofwbus, tzic_driver, tzic_devclass, 0, 0, BUS_PASS_INTERRUPT); -EARLY_DRIVER_MODULE(tzic, simplebus, tzic_driver, tzic_devclass, 0, 0, - BUS_PASS_INTERRUPT); - -static void -tzic_post_filter(void *arg) -{ - -} - -int -arm_get_next_irq(int last_irq) -{ - uint32_t pending; - int i, b; - - for (i = 0; i < 4; i++) { - pending = tzic_read_4(TZIC_PND(i)); - for (b = 0; pending != 0 && b < 32; b++) - if (pending & (1 << b)) { - return (i * 32 + b); - } - } - - return (-1); -} - -void -arm_mask_irq(uintptr_t nb) -{ - - tzic_write_4(TZIC_ENCLEAR(nb / 32), (1UL <<(nb % 32))); -} - -void -arm_unmask_irq(uintptr_t nb) -{ - - tzic_write_4(TZIC_ENSET(nb / 32), (1UL <<(nb % 32))); -} From owner-svn-src-stable-11@freebsd.org Sun Sep 10 23:48:21 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 83053E0ACB1; Sun, 10 Sep 2017 23:48:21 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 5F1446609D; Sun, 10 Sep 2017 23:48:21 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8ANmKBK003866; Sun, 10 Sep 2017 23:48:20 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8ANmKpZ003864; Sun, 10 Sep 2017 23:48:20 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709102348.v8ANmKpZ003864@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 10 Sep 2017 23:48:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323404 - stable/11/sys/arm/freescale/imx X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/freescale/imx X-SVN-Commit-Revision: 323404 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 23:48:21 -0000 Author: ian Date: Sun Sep 10 23:48:20 2017 New Revision: 323404 URL: https://svnweb.freebsd.org/changeset/base/323404 Log: MFC r315589, r315591, r316659, r316661: Eliminate unnecessary read/modify/write sequences during eventtimer setup. Replace the hard-coded way-too-small minimum event timer period with a value calculated at runtime based on how long it takes to set up an event in hardware. This fixes the intermittant 1-minute hang at boot on imx5 systems, and also the occasional oversleeping while running. It doesn't affect imx6 systems, which use different hardware for eventtimers. Remove some old interrupt handling workaround code from the pre-INTRNG days. At this point, INTRNG is not going away (the option may go away, but the code is not), so we no longer need code to support workarounds that handled the lack of INTRNG functionality. Update the code that compensates for the lack of a GPC interrupt controller driver for imx6. Some newer dts source puts the GIC node at the root instead of under /soc, so look in both places. Also, sometimes the GIC node doesn't list itself as its own interrupt-parent, allow that too. Modified: stable/11/sys/arm/freescale/imx/imx6_machdep.c stable/11/sys/arm/freescale/imx/imx_gpt.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/imx6_machdep.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx6_machdep.c Sun Sep 10 23:41:23 2017 (r323403) +++ stable/11/sys/arm/freescale/imx/imx6_machdep.c Sun Sep 10 23:48:20 2017 (r323404) @@ -52,45 +52,7 @@ __FBSDID("$FreeBSD$"); #include "platform_if.h" -static uint32_t gpio1_node; - -#ifndef INTRNG /* - * Work around the linux workaround for imx6 erratum 006687, in which some - * ethernet interrupts don't go to the GPC and thus won't wake the system from - * Wait mode. We don't use Wait mode (which halts the GIC, leaving only GPC - * interrupts able to wake the system), so we don't experience the bug at all. - * The linux workaround is to reconfigure GPIO1_6 as the ENET interrupt by - * writing magic values to an undocumented IOMUX register, then letting the gpio - * interrupt driver notify the ethernet driver. We'll be able to do all that - * (even though we don't need to) once the INTRNG project is committed and the - * imx_gpio driver becomes an interrupt driver. Until then, this crazy little - * workaround watches for requests to map an interrupt 6 with the interrupt - * controller node referring to gpio1, and it substitutes the proper ffec - * interrupt number. - */ -static int -imx6_decode_fdt(uint32_t iparent, uint32_t *intr, int *interrupt, - int *trig, int *pol) -{ - - if (fdt32_to_cpu(intr[0]) == 6 && - OF_node_from_xref(iparent) == gpio1_node) { - *interrupt = 150; - *trig = INTR_TRIGGER_CONFORM; - *pol = INTR_POLARITY_CONFORM; - return (0); - } - return (gic_decode_fdt(iparent, intr, interrupt, trig, pol)); -} - -fdt_pic_decode_t fdt_pic_table[] = { - &imx6_decode_fdt, - NULL -}; -#endif - -/* * Fix FDT data related to interrupts. * * Driven by the needs of linux and its drivers (as always), the published FDT @@ -109,7 +71,7 @@ fdt_pic_decode_t fdt_pic_table[] = { * We validate that we have data that looks like we expect before changing it: * - SOC node exists and has GPC as its interrupt parent. * - GPC node exists and has GIC as its interrupt parent. - * - GIC node exists and is its own interrupt parent. + * - GIC node exists and is its own interrupt parent or has no parent. * * This applies to all models of imx6. Luckily all of them have the devices * involved at the same addresses on the same busses, so we don't need any @@ -133,14 +95,20 @@ fix_fdt_interrupt_data(void) if (result <= 0) return; + /* GIC node may be child of soc node, or appear directly at root. */ gicnode = OF_finddevice("/soc/interrupt-controller@00a01000"); + if (gicnode == -1) { + gicnode = OF_finddevice("/interrupt-controller@00a01000"); if (gicnode == -1) return; + } + gicxref = OF_xref_from_node(gicnode); + + /* If gic node has no parent, pretend it is its own parent. */ result = OF_getencprop(gicnode, "interrupt-parent", &gicipar, sizeof(gicipar)); if (result <= 0) - return; - gicxref = OF_xref_from_node(gicnode); + gicipar = gicxref; gpcnode = OF_finddevice("/soc/aips-bus@02000000/gpc@020dc000"); if (gpcnode == -1) @@ -184,10 +152,6 @@ imx6_late_init(platform_t plat) const uint32_t IMX6_WDOG_SR_PHYS = 0x020bc004; imx_wdog_init_last_reset(IMX6_WDOG_SR_PHYS); - - /* Cache the gpio1 node handle for imx6_decode_fdt() workaround code. */ - gpio1_node = OF_node_from_xref( - OF_finddevice("/soc/aips-bus@02000000/gpio@0209c000")); } /* Modified: stable/11/sys/arm/freescale/imx/imx_gpt.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_gpt.c Sun Sep 10 23:41:23 2017 (r323403) +++ stable/11/sys/arm/freescale/imx/imx_gpt.c Sun Sep 10 23:48:20 2017 (r323404) @@ -84,6 +84,7 @@ struct imx_gpt_softc { uint32_t sc_period; uint32_t sc_clksrc; uint32_t clkfreq; + uint32_t ir_reg; struct eventtimer et; }; @@ -102,10 +103,6 @@ static const int imx_gpt_delay_count = 78; /* Try to divide down an available fast clock to this frequency. */ #define TARGET_FREQUENCY 1000000000 -/* Don't try to set an event timer period smaller than this. */ -#define MIN_ET_PERIOD 10LLU - - static struct resource_spec imx_gpt_spec[] = { { SYS_RES_MEMORY, 0, RF_ACTIVE }, { SYS_RES_IRQ, 0, RF_ACTIVE }, @@ -143,7 +140,7 @@ imx_gpt_attach(device_t dev) { struct imx_gpt_softc *sc; int ctlreg, err; - uint32_t basefreq, prescale; + uint32_t basefreq, prescale, setup_ticks, t1, t2; sc = device_get_softc(dev); @@ -249,13 +246,25 @@ imx_gpt_attach(device_t dev) return (ENXIO); } + /* + * Measure how many clock ticks it takes to setup a one-shot event (it's + * longer than you might think, due to wait states in accessing gpt + * registers). Scale up the result by a factor of 1.5 to be safe, + * and use that to set the minimum eventtimer period we can schedule. In + * the real world, the value works out to about 750ns on imx5 hardware. + */ + t1 = READ4(sc, IMX_GPT_CNT); + WRITE4(sc, IMX_GPT_OCR3, 0); + t2 = READ4(sc, IMX_GPT_CNT); + setup_ticks = ((t2 - t1 + 1) * 3) / 2; + /* Register as an eventtimer. */ sc->et.et_name = "iMXGPT"; sc->et.et_flags = ET_FLAGS_ONESHOT | ET_FLAGS_PERIODIC; sc->et.et_quality = 800; sc->et.et_frequency = sc->clkfreq; - sc->et.et_min_period = (MIN_ET_PERIOD << 32) / sc->et.et_frequency; - sc->et.et_max_period = (0xfffffffeLLU << 32) / sc->et.et_frequency; + sc->et.et_min_period = ((uint64_t)setup_ticks << 32) / sc->clkfreq; + sc->et.et_max_period = ((uint64_t)0xfffffffe << 32) / sc->clkfreq; sc->et.et_start = imx_gpt_timer_start; sc->et.et_stop = imx_gpt_timer_stop; sc->et.et_priv = sc; @@ -285,16 +294,20 @@ imx_gpt_timer_start(struct eventtimer *et, sbintime_t /* Set expected value */ WRITE4(sc, IMX_GPT_OCR2, READ4(sc, IMX_GPT_CNT) + sc->sc_period); /* Enable compare register 2 Interrupt */ - SET4(sc, IMX_GPT_IR, GPT_IR_OF2); + sc->ir_reg |= GPT_IR_OF2; + WRITE4(sc, IMX_GPT_IR, sc->ir_reg); return (0); } else if (first != 0) { + /* Enable compare register 3 interrupt if not already on. */ + if ((sc->ir_reg & GPT_IR_OF3) == 0) { + sc->ir_reg |= GPT_IR_OF3; + WRITE4(sc, IMX_GPT_IR, sc->ir_reg); + } ticks = ((uint32_t)et->et_frequency * first) >> 32; /* Do not disturb, otherwise event will be lost */ spinlock_enter(); /* Set expected value */ WRITE4(sc, IMX_GPT_OCR3, READ4(sc, IMX_GPT_CNT) + ticks); - /* Enable compare register 1 Interrupt */ - SET4(sc, IMX_GPT_IR, GPT_IR_OF3); /* Now everybody can relax */ spinlock_exit(); return (0); @@ -310,9 +323,10 @@ imx_gpt_timer_stop(struct eventtimer *et) sc = (struct imx_gpt_softc *)et->et_priv; - /* Disable OF2 Interrupt */ - CLEAR4(sc, IMX_GPT_IR, GPT_IR_OF2); - WRITE4(sc, IMX_GPT_SR, GPT_IR_OF2); + /* Disable interrupts and clear any pending status. */ + sc->ir_reg &= ~(GPT_IR_OF2 | GPT_IR_OF3); + WRITE4(sc, IMX_GPT_IR, sc->ir_reg); + WRITE4(sc, IMX_GPT_SR, GPT_IR_OF2 | GPT_IR_OF3); sc->sc_period = 0; return (0); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 00:19:11 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 08C8BE0C6C7; Mon, 11 Sep 2017 00:19:11 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id CB7E966DF7; Mon, 11 Sep 2017 00:19:10 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B0J9hj016174; Mon, 11 Sep 2017 00:19:09 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B0J97u016173; Mon, 11 Sep 2017 00:19:09 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110019.v8B0J97u016173@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 00:19:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323406 - stable/11/tools/test/ppsapi X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/tools/test/ppsapi X-SVN-Commit-Revision: 323406 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 00:19:11 -0000 Author: ian Date: Mon Sep 11 00:19:09 2017 New Revision: 323406 URL: https://svnweb.freebsd.org/changeset/base/323406 Log: MFC r315692: Eliminate a "format string is not a string literal" warning. Modified: stable/11/tools/test/ppsapi/ppsapitest.c Directory Properties: stable/11/ (props changed) Modified: stable/11/tools/test/ppsapi/ppsapitest.c ============================================================================== --- stable/11/tools/test/ppsapi/ppsapitest.c Mon Sep 11 00:14:04 2017 (r323405) +++ stable/11/tools/test/ppsapi/ppsapitest.c Mon Sep 11 00:19:09 2017 (r323406) @@ -72,7 +72,7 @@ main(int argc, char **argv) if (argc > 0) { fd = open(argv[0], O_RDONLY); if (fd < 0) - err(1, argv[0]); + err(1, "%s", argv[0]); } else { fd = 0; } From owner-svn-src-stable-11@freebsd.org Mon Sep 11 00:51:48 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6B277E0DFE8; Mon, 11 Sep 2017 00:51:48 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 3002067CC7; Mon, 11 Sep 2017 00:51:48 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B0plI4028364; Mon, 11 Sep 2017 00:51:47 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B0plFa028362; Mon, 11 Sep 2017 00:51:47 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110051.v8B0plFa028362@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 00:51:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323408 - stable/11/sys/dev/mii X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/dev/mii X-SVN-Commit-Revision: 323408 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 00:51:48 -0000 Author: ian Date: Mon Sep 11 00:51:47 2017 New Revision: 323408 URL: https://svnweb.freebsd.org/changeset/base/323408 Log: MFC r316995: Add support for the Micrel KSZ8081 ethernet PHY. Modified: stable/11/sys/dev/mii/micphy.c stable/11/sys/dev/mii/miidevs Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/mii/micphy.c ============================================================================== --- stable/11/sys/dev/mii/micphy.c Mon Sep 11 00:37:00 2017 (r323407) +++ stable/11/sys/dev/mii/micphy.c Mon Sep 11 00:51:47 2017 (r323408) @@ -76,10 +76,13 @@ __FBSDID("$FreeBSD$"); #define MII_KSZ9031_TX_DATA_PAD_SKEW 0x6 #define MII_KSZ9031_CLOCK_PAD_SKEW 0x8 +#define MII_KSZ8081_PHYCTL2 0x1f + #define PS_TO_REG(p) ((p) / 200) static int micphy_probe(device_t); static int micphy_attach(device_t); +static void micphy_reset(struct mii_softc *); static int micphy_service(struct mii_softc *, struct mii_data *, int); static device_method_t micphy_methods[] = { @@ -102,6 +105,7 @@ static driver_t micphy_driver = { DRIVER_MODULE(micphy, miibus, micphy_driver, micphy_devclass, 0, 0); static const struct mii_phydesc micphys[] = { + MII_PHY_DESC(MICREL, KSZ8081), MII_PHY_DESC(MICREL, KSZ9021), MII_PHY_DESC(MICREL, KSZ9031), MII_PHY_END @@ -110,7 +114,7 @@ static const struct mii_phydesc micphys[] = { static const struct mii_phy_funcs micphy_funcs = { micphy_service, ukphy_status, - mii_phy_reset + micphy_reset }; static uint32_t @@ -257,6 +261,10 @@ micphy_attach(device_t dev) mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &micphy_funcs, 1); mii_phy_setmedia(sc); + /* Nothing further to configure for 8081 model. */ + if (sc->mii_mpd_model == MII_MODEL_MICREL_KSZ8081) + return (0); + miibus = device_get_parent(dev); parent = device_get_parent(miibus); @@ -269,6 +277,24 @@ micphy_attach(device_t dev) ksz9021_load_values(sc, node); return (0); +} + +static void +micphy_reset(struct mii_softc *sc) +{ + int reg; + + /* + * The 8081 has no "sticky bits" that survive a soft reset; several bits + * in the Phy Control Register 2 must be preserved across the reset. + * These bits are set up by the bootloader; they control how the phy + * interfaces to the board (such as clock frequency and LED behavior). + */ + if (sc->mii_mpd_model == MII_MODEL_MICREL_KSZ8081) + reg = PHY_READ(sc, MII_KSZ8081_PHYCTL2); + mii_phy_reset(sc); + if (sc->mii_mpd_model == MII_MODEL_MICREL_KSZ8081) + PHY_WRITE(sc, MII_KSZ8081_PHYCTL2, reg); } static int Modified: stable/11/sys/dev/mii/miidevs ============================================================================== --- stable/11/sys/dev/mii/miidevs Mon Sep 11 00:37:00 2017 (r323407) +++ stable/11/sys/dev/mii/miidevs Mon Sep 11 00:51:47 2017 (r323408) @@ -282,6 +282,7 @@ model MARVELL E1000_5 0x0005 Marvell 88E1000 Gigabit model MARVELL E1111 0x000c Marvell 88E1111 Gigabit PHY /* Micrel PHYs */ +model MICREL KSZ8081 0x0016 Micrel KSZ8081 10/100 PHY model MICREL KSZ9021 0x0021 Micrel KSZ9021 10/100/1000 PHY model MICREL KSZ9031 0x0022 Micrel KSZ9031 10/100/1000 PHY From owner-svn-src-stable-11@freebsd.org Mon Sep 11 00:55:20 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2AE71E0E34F; Mon, 11 Sep 2017 00:55:20 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id EB9F967EBA; Mon, 11 Sep 2017 00:55:19 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B0tJnk032178; Mon, 11 Sep 2017 00:55:19 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B0tISa032176; Mon, 11 Sep 2017 00:55:18 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110055.v8B0tISa032176@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 00:55:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323409 - in stable/11/sys/boot: arm/uboot uboot/common X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys/boot: arm/uboot uboot/common X-SVN-Commit-Revision: 323409 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 00:55:20 -0000 Author: ian Date: Mon Sep 11 00:55:18 2017 New Revision: 323409 URL: https://svnweb.freebsd.org/changeset/base/323409 Log: MFC r316374, r316377: Preserve the registers containing argc, argv, and return address values passed in from u-boot across the call to self_reloc and any other early-init code, and restore them before calling main(). Correct a comment... the stack used by ubldr is the same stack u-boot was running on when it jumped to the ubldr entry point. None of the arches that use this code set up a different stack in their start.S routines. Modified: stable/11/sys/boot/arm/uboot/start.S stable/11/sys/boot/uboot/common/main.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/boot/arm/uboot/start.S ============================================================================== --- stable/11/sys/boot/arm/uboot/start.S Mon Sep 11 00:51:47 2017 (r323408) +++ stable/11/sys/boot/arm/uboot/start.S Mon Sep 11 00:55:18 2017 (r323409) @@ -45,6 +45,13 @@ _start: orr ip, ip, #(CPU_CONTROL_AFLT_ENABLE) mcr p15, 0, ip, c1, c0, 0 #endif + + /* + * Save r0 and r1 (argc and argv passed from u-boot), and lr (trashed + * by the call to self_reloc below) until we're ready to call main(). + */ + push {r0, r1, lr} + /* * Do self-relocation when the weak external symbol _DYNAMIC is non-NULL. * When linked as a dynamic relocatable file, the linker automatically @@ -71,9 +78,11 @@ _start: str r9, [ip, #4] /* + * First restore argc, argv, and the u-boot return address, then * Start loader. This is basically a tail-recursion call; if main() * returns, it returns to u-boot (which reports the value returned r0). */ + pop {r0, r1, lr} b main /* Modified: stable/11/sys/boot/uboot/common/main.c ============================================================================== --- stable/11/sys/boot/uboot/common/main.c Mon Sep 11 00:51:47 2017 (r323408) +++ stable/11/sys/boot/uboot/common/main.c Mon Sep 11 00:55:18 2017 (r323409) @@ -416,7 +416,9 @@ main(int argc, char **argv) /* * Initialise the heap as early as possible. Once this is done, - * alloc() is usable. The stack is buried inside us, so this is safe. + * alloc() is usable. We are using the stack u-boot set up near the top + * of physical ram; hopefully there is sufficient space between the end + * of our bss and the bottom of the u-boot stack to avoid overlap. */ uboot_heap_start = round_page((uintptr_t)end); uboot_heap_end = uboot_heap_start + 512 * 1024; From owner-svn-src-stable-11@freebsd.org Mon Sep 11 01:01:02 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BE75EE0E7EE; Mon, 11 Sep 2017 01:01:02 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 99313681FA; Mon, 11 Sep 2017 01:01:02 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B111tx033190; Mon, 11 Sep 2017 01:01:01 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B111bg033184; Mon, 11 Sep 2017 01:01:01 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110101.v8B111bg033184@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 01:01:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323410 - in stable/11/sys: arm/freescale/imx dev/ffec X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: arm/freescale/imx dev/ffec X-SVN-Commit-Revision: 323410 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 01:01:02 -0000 Author: ian Date: Mon Sep 11 01:01:00 2017 New Revision: 323410 URL: https://svnweb.freebsd.org/changeset/base/323410 Log: MFC r316664, r316670, r316972, r316996, r317033: Add imx6ul support (applies to all files). Add code/constants for detecting imx6ul (ultralite) chips, a species of imx6 based on a single cortex-a7 core. Other changes to imx6 drivers and support code are needed to fully support the imx6ul. if_ffec: Add imx6ul SoC support, and get the PHY number from the FDT data. If there is no phy-handle property, fall back to using MII_PHY_ANY. This still doesn't support an mdio bus with multiple PHYs on it, or the possibility that the PHY being used by this instance of ffec is on the mdio bus of some other instance (which is now a possibility with imx6ul). Adding that support will require changes in fdt_get_phyaddr(), which is currently making some assumptions that don't work with modern fdt data. Modified: stable/11/sys/arm/freescale/imx/imx6_machdep.c stable/11/sys/arm/freescale/imx/imx6_usbphy.c stable/11/sys/arm/freescale/imx/imx_gpt.c stable/11/sys/arm/freescale/imx/imx_iomux.c stable/11/sys/arm/freescale/imx/imx_machdep.h stable/11/sys/dev/ffec/if_ffec.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/imx6_machdep.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx6_machdep.c Mon Sep 11 00:55:18 2017 (r323409) +++ stable/11/sys/arm/freescale/imx/imx6_machdep.c Mon Sep 11 01:01:00 2017 (r323410) @@ -99,8 +99,8 @@ fix_fdt_interrupt_data(void) gicnode = OF_finddevice("/soc/interrupt-controller@00a01000"); if (gicnode == -1) { gicnode = OF_finddevice("/interrupt-controller@00a01000"); - if (gicnode == -1) - return; + if (gicnode == -1) + return; } gicxref = OF_xref_from_node(gicnode); @@ -233,6 +233,7 @@ u_int imx_soc_type() #define HWSOC_MX6DL 0x61 #define HWSOC_MX6SOLO 0x62 #define HWSOC_MX6Q 0x63 +#define HWSOC_MX6UL 0x64 if (soctype != 0) return (soctype); @@ -271,6 +272,9 @@ u_int imx_soc_type() case HWSOC_MX6Q : soctype = IMXSOC_6Q; break; + case HWSOC_MX6UL: + soctype = IMXSOC_6UL; + break; default: printf("imx_soc_type: Don't understand hwsoc 0x%02x, " "digprog 0x%08x; assuming IMXSOC_6Q\n", hwsoc, digprog); @@ -317,3 +321,4 @@ static platform_method_t imx6_methods[] = { FDT_PLATFORM_DEF2(imx6, imx6s, "i.MX6 Solo", 0, "fsl,imx6s", 0); FDT_PLATFORM_DEF2(imx6, imx6d, "i.MX6 Dual", 0, "fsl,imx6dl", 0); FDT_PLATFORM_DEF2(imx6, imx6q, "i.MX6 Quad", 0, "fsl,imx6q", 0); +FDT_PLATFORM_DEF2(imx6, imx6ul, "i.MX6 UltraLite", 0, "fsl,imx6ul", 0); Modified: stable/11/sys/arm/freescale/imx/imx6_usbphy.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx6_usbphy.c Mon Sep 11 00:55:18 2017 (r323409) +++ stable/11/sys/arm/freescale/imx/imx6_usbphy.c Mon Sep 11 01:01:00 2017 (r323410) @@ -68,6 +68,12 @@ struct usbphy_softc { u_int phy_num; }; +static struct ofw_compat_data compat_data[] = { + {"fsl,imx6q-usbphy", true}, + {"fsl,imx6ul-usbphy", true}, + {NULL, false} +}; + static int usbphy_detach(device_t dev) { @@ -167,7 +173,7 @@ usbphy_probe(device_t dev) if (!ofw_bus_status_okay(dev)) return (ENXIO); - if (ofw_bus_is_compatible(dev, "fsl,imx6q-usbphy") == 0) + if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) return (ENXIO); device_set_desc(dev, "Freescale i.MX6 USB PHY"); Modified: stable/11/sys/arm/freescale/imx/imx_gpt.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_gpt.c Mon Sep 11 00:55:18 2017 (r323409) +++ stable/11/sys/arm/freescale/imx/imx_gpt.c Mon Sep 11 01:01:00 2017 (r323410) @@ -112,6 +112,7 @@ static struct resource_spec imx_gpt_spec[] = { static struct ofw_compat_data compat_data[] = { {"fsl,imx6dl-gpt", 1}, {"fsl,imx6q-gpt", 1}, + {"fsl,imx6ul-gpt", 1}, {"fsl,imx53-gpt", 1}, {"fsl,imx51-gpt", 1}, {"fsl,imx31-gpt", 1}, @@ -125,6 +126,15 @@ imx_gpt_probe(device_t dev) { if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + /* + * We only support a single unit, because the only thing this driver + * does with the complex timer hardware is supply the system + * timecounter and eventtimer. There is nothing useful we can do with + * the additional device instances that exist in some chips. + */ + if (device_get_unit(dev) > 0) return (ENXIO); if (ofw_bus_search_compatible(dev, compat_data)->ocd_data != 0) { Modified: stable/11/sys/arm/freescale/imx/imx_iomux.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_iomux.c Mon Sep 11 00:55:18 2017 (r323409) +++ stable/11/sys/arm/freescale/imx/imx_iomux.c Mon Sep 11 01:01:00 2017 (r323410) @@ -80,6 +80,7 @@ static struct ofw_compat_data compat_data[] = { {"fsl,imx6dl-iomuxc", true}, {"fsl,imx6q-iomuxc", true}, {"fsl,imx6sl-iomuxc", true}, + {"fsl,imx6ul-iomuxc", true}, {"fsl,imx6sx-iomuxc", true}, {"fsl,imx53-iomuxc", true}, {"fsl,imx51-iomuxc", true}, @@ -223,6 +224,9 @@ iomux_attach(device_t dev) case IMXSOC_6SL: case IMXSOC_6Q: sc->last_gpreg = 13; + break; + case IMXSOC_6UL: + sc->last_gpreg = 14; break; default: device_printf(dev, "Unknown SoC type\n"); Modified: stable/11/sys/arm/freescale/imx/imx_machdep.h ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_machdep.h Mon Sep 11 00:55:18 2017 (r323409) +++ stable/11/sys/arm/freescale/imx/imx_machdep.h Mon Sep 11 01:01:00 2017 (r323410) @@ -55,6 +55,7 @@ void imx_wdog_init_last_reset(vm_offset_t _wdsr_phys); #define IMXSOC_6DL 0x61000000 #define IMXSOC_6S 0x62000000 #define IMXSOC_6Q 0x63000000 +#define IMXSOC_6UL 0x64000000 #define IMXSOC_FAMSHIFT 28 u_int imx_soc_type(void); Modified: stable/11/sys/dev/ffec/if_ffec.c ============================================================================== --- stable/11/sys/dev/ffec/if_ffec.c Mon Sep 11 00:55:18 2017 (r323409) +++ stable/11/sys/dev/ffec/if_ffec.c Mon Sep 11 01:01:00 2017 (r323410) @@ -78,6 +78,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -113,6 +114,7 @@ static struct ofw_compat_data compat_data[] = { {"fsl,imx51-fec", FECTYPE_GENERIC}, {"fsl,imx53-fec", FECTYPE_IMX53}, {"fsl,imx6q-fec", FECTYPE_IMX6 | FECFLAG_GBE}, + {"fsl,imx6ul-fec", FECTYPE_IMX6}, {"fsl,mvf600-fec", FECTYPE_MVF}, {"fsl,mvf-fec", FECTYPE_MVF}, {NULL, FECTYPE_NONE}, @@ -1424,8 +1426,9 @@ ffec_attach(device_t dev) struct ffec_softc *sc; struct ifnet *ifp = NULL; struct mbuf *m; + void *dummy; phandle_t ofw_node; - int error, rid; + int error, phynum, rid; uint8_t eaddr[ETHER_ADDR_LEN]; char phy_conn_name[32]; uint32_t idx, mscr; @@ -1695,8 +1698,11 @@ ffec_attach(device_t dev) ffec_miigasket_setup(sc); /* Attach the mii driver. */ + if (fdt_get_phyaddr(ofw_node, dev, &phynum, &dummy) != 0) { + phynum = MII_PHY_ANY; + } error = mii_attach(dev, &sc->miibus, ifp, ffec_media_change, - ffec_media_status, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, + ffec_media_status, BMSR_DEFCAPMASK, phynum, MII_OFFSET_ANY, (sc->fectype & FECTYPE_MVF) ? MIIF_FORCEANEG : 0); if (error != 0) { device_printf(dev, "PHY attach failed\n"); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 01:26:27 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A3AF1E0FE54; Mon, 11 Sep 2017 01:26:27 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 7F6276933B; Mon, 11 Sep 2017 01:26:27 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B1QQhu044461; Mon, 11 Sep 2017 01:26:26 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B1QQxF044459; Mon, 11 Sep 2017 01:26:26 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110126.v8B1QQxF044459@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 01:26:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323411 - in stable/11/sys: dev/ffec modules modules/ffec X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: dev/ffec modules modules/ffec X-SVN-Commit-Revision: 323411 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 01:26:27 -0000 Author: ian Date: Mon Sep 11 01:26:26 2017 New Revision: 323411 URL: https://svnweb.freebsd.org/changeset/base/323411 Log: MFC r319811, r319813: Allow building if_ffec as a module. if_ffec bugfixes related to harvesting of hardware-maintained statistics... After harvesting the hardware statistics counters and summing them into the interface stats, properly clear the hardware counters back to zero. On imx5 and earlier hardware it is necessary to disable collection of stats while writing zeroes to all the registers. On imx6 and newer it turns out it's not even possible to write zeroes, instead you have to toggle a special "zero everything" control bit in a register. Count incoming packets with a bad start frame delim as input errors, and incoming packets dropped due to no fifo space as input drops. Remove all code related to harvesting the hardware stats less often than once per second. It turns out the 32-bit stats registers are backed by 16-bit counters under the hood, and they can easily roll over if you only harvest them once every 3 seconds like the old code was doing. Now we just read all the regs once a second. The combination of not properly zeroing the stats registers and 16-bit counters sometimes wrapping between harvest calls resulted in basically unusable statistics before these changes. Added: stable/11/sys/modules/ffec/ - copied from r319813, head/sys/modules/ffec/ Modified: stable/11/sys/dev/ffec/if_ffec.c stable/11/sys/modules/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/ffec/if_ffec.c ============================================================================== --- stable/11/sys/dev/ffec/if_ffec.c Mon Sep 11 01:01:00 2017 (r323410) +++ stable/11/sys/dev/ffec/if_ffec.c Mon Sep 11 01:26:26 2017 (r323411) @@ -129,7 +129,6 @@ static struct ofw_compat_data compat_data[] = { #define TX_DESC_SIZE (sizeof(struct ffec_hwdesc) * TX_DESC_COUNT) #define WATCHDOG_TIMEOUT_SECS 5 -#define STATS_HARVEST_INTERVAL 3 struct ffec_bufmap { struct mbuf *mbuf; @@ -160,7 +159,6 @@ struct ffec_softc { boolean_t is_attached; boolean_t is_detaching; int tx_watchdog_count; - int stats_harvest_count; bus_dma_tag_t rxdesc_tag; bus_dmamap_t rxdesc_map; @@ -462,22 +460,41 @@ ffec_media_change(struct ifnet * ifp) static void ffec_clear_stats(struct ffec_softc *sc) { + uint32_t mibc; - WR4(sc, FEC_RMON_R_PACKETS, 0); - WR4(sc, FEC_RMON_R_MC_PKT, 0); - WR4(sc, FEC_RMON_R_CRC_ALIGN, 0); - WR4(sc, FEC_RMON_R_UNDERSIZE, 0); - WR4(sc, FEC_RMON_R_OVERSIZE, 0); - WR4(sc, FEC_RMON_R_FRAG, 0); - WR4(sc, FEC_RMON_R_JAB, 0); - WR4(sc, FEC_RMON_T_PACKETS, 0); - WR4(sc, FEC_RMON_T_MC_PKT, 0); - WR4(sc, FEC_RMON_T_CRC_ALIGN, 0); - WR4(sc, FEC_RMON_T_UNDERSIZE, 0); - WR4(sc, FEC_RMON_T_OVERSIZE , 0); - WR4(sc, FEC_RMON_T_FRAG, 0); - WR4(sc, FEC_RMON_T_JAB, 0); - WR4(sc, FEC_RMON_T_COL, 0); + mibc = RD4(sc, FEC_MIBC_REG); + + /* + * On newer hardware the statistic regs are cleared by toggling a bit in + * the mib control register. On older hardware the clear procedure is + * to disable statistics collection, zero the regs, then re-enable. + */ + if (sc->fectype == FECTYPE_IMX6 || sc->fectype == FECTYPE_MVF) { + WR4(sc, FEC_MIBC_REG, mibc | FEC_MIBC_CLEAR); + WR4(sc, FEC_MIBC_REG, mibc & ~FEC_MIBC_CLEAR); + } else { + WR4(sc, FEC_MIBC_REG, mibc | FEC_MIBC_DIS); + + WR4(sc, FEC_IEEE_R_DROP, 0); + WR4(sc, FEC_IEEE_R_MACERR, 0); + WR4(sc, FEC_RMON_R_CRC_ALIGN, 0); + WR4(sc, FEC_RMON_R_FRAG, 0); + WR4(sc, FEC_RMON_R_JAB, 0); + WR4(sc, FEC_RMON_R_MC_PKT, 0); + WR4(sc, FEC_RMON_R_OVERSIZE, 0); + WR4(sc, FEC_RMON_R_PACKETS, 0); + WR4(sc, FEC_RMON_R_UNDERSIZE, 0); + WR4(sc, FEC_RMON_T_COL, 0); + WR4(sc, FEC_RMON_T_CRC_ALIGN, 0); + WR4(sc, FEC_RMON_T_FRAG, 0); + WR4(sc, FEC_RMON_T_JAB, 0); + WR4(sc, FEC_RMON_T_MC_PKT, 0); + WR4(sc, FEC_RMON_T_OVERSIZE , 0); + WR4(sc, FEC_RMON_T_PACKETS, 0); + WR4(sc, FEC_RMON_T_UNDERSIZE, 0); + + WR4(sc, FEC_MIBC_REG, mibc); + } } static void @@ -485,29 +502,22 @@ ffec_harvest_stats(struct ffec_softc *sc) { struct ifnet *ifp; - /* We don't need to harvest too often. */ - if (++sc->stats_harvest_count < STATS_HARVEST_INTERVAL) - return; + ifp = sc->ifp; /* - * Try to avoid harvesting unless the IDLE flag is on, but if it has - * been too long just go ahead and do it anyway, the worst that'll - * happen is we'll lose a packet count or two as we clear at the end. + * - FEC_IEEE_R_DROP is "dropped due to invalid start frame delimiter" + * so it's really just another type of input error. + * - FEC_IEEE_R_MACERR is "no receive fifo space"; count as input drops. */ - if (sc->stats_harvest_count < (2 * STATS_HARVEST_INTERVAL) && - ((RD4(sc, FEC_MIBC_REG) & FEC_MIBC_IDLE) == 0)) - return; - - sc->stats_harvest_count = 0; - ifp = sc->ifp; - if_inc_counter(ifp, IFCOUNTER_IPACKETS, RD4(sc, FEC_RMON_R_PACKETS)); if_inc_counter(ifp, IFCOUNTER_IMCASTS, RD4(sc, FEC_RMON_R_MC_PKT)); if_inc_counter(ifp, IFCOUNTER_IERRORS, RD4(sc, FEC_RMON_R_CRC_ALIGN) + RD4(sc, FEC_RMON_R_UNDERSIZE) + RD4(sc, FEC_RMON_R_OVERSIZE) + RD4(sc, FEC_RMON_R_FRAG) + - RD4(sc, FEC_RMON_R_JAB)); + RD4(sc, FEC_RMON_R_JAB) + RD4(sc, FEC_IEEE_R_DROP)); + if_inc_counter(ifp, IFCOUNTER_IQDROPS, RD4(sc, FEC_IEEE_R_MACERR)); + if_inc_counter(ifp, IFCOUNTER_OPACKETS, RD4(sc, FEC_RMON_T_PACKETS)); if_inc_counter(ifp, IFCOUNTER_OMCASTS, RD4(sc, FEC_RMON_T_MC_PKT)); if_inc_counter(ifp, IFCOUNTER_OERRORS, @@ -1016,7 +1026,6 @@ ffec_stop_locked(struct ffec_softc *sc) ifp = sc->ifp; ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); sc->tx_watchdog_count = 0; - sc->stats_harvest_count = 0; /* * Stop the hardware, mask all interrupts, and clear all current @@ -1194,7 +1203,8 @@ ffec_init_locked(struct ffec_softc *sc) WR4(sc, FEC_IEM_REG, FEC_IER_TXF | FEC_IER_RXF | FEC_IER_EBERR); /* - * MIBC - MIB control (hardware stats). + * MIBC - MIB control (hardware stats); clear all statistics regs, then + * enable collection of statistics. */ regval = RD4(sc, FEC_MIBC_REG); WR4(sc, FEC_MIBC_REG, regval | FEC_MIBC_DIS); Modified: stable/11/sys/modules/Makefile ============================================================================== --- stable/11/sys/modules/Makefile Mon Sep 11 01:01:00 2017 (r323410) +++ stable/11/sys/modules/Makefile Mon Sep 11 01:26:26 2017 (r323411) @@ -123,6 +123,7 @@ SUBDIR= \ fdc \ fdescfs \ ${_fe} \ + ${_ffec} \ filemon \ firewire \ firmware \ @@ -790,6 +791,7 @@ _cpufreq= cpufreq _drm= drm _exca= exca _nvram= powermac_nvram +_ffec= ffec _pccard= pccard _wi= wi .endif @@ -813,6 +815,10 @@ _cloudabi32= cloudabi32 _cloudabi64= cloudabi64 .endif +.endif + +.if ${MACHINE_ARCH} == "armv6" +_ffec= ffec .endif SUBDIR+=${MODULES_EXTRA} From owner-svn-src-stable-11@freebsd.org Mon Sep 11 01:53:23 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C69A8E1153A; Mon, 11 Sep 2017 01:53:23 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 9363A6A1C3; Mon, 11 Sep 2017 01:53:23 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B1rMXI056378; Mon, 11 Sep 2017 01:53:22 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B1rMe4056377; Mon, 11 Sep 2017 01:53:22 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110153.v8B1rMe4056377@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 01:53:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323413 - stable/11 X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11 X-SVN-Commit-Revision: 323413 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 01:53:23 -0000 Author: ian Date: Mon Sep 11 01:53:22 2017 New Revision: 323413 URL: https://svnweb.freebsd.org/changeset/base/323413 Log: MFC r319859, r319888: Add support for "make universe_kernels -DMAKE_GENERIC_KERNELS" to build just the GENERIC kernels for each arch (including variations such as GENERIC-NODEBUG, GENERIC64, etc). This helps with quickly doing a test build for all[*] arches without building dozens of variant kernels for the arches that have lots of hardware/board/system variations. [*] Not all arches have a generic kernel (but they probably should for test-building purposes, even if it can't boot on any real hardware). By popular demand: change MAKE_GENERIC_KERNELS to MAKE_LINT_KERNELS. It appears that the same arches that lack GENERIC kernel configs also lack LINT. But enough different arches get built to ensure a kernel change should build everywhere (32 and 64 bit, clang and old gcc, little and big endian). Modified: stable/11/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/Makefile ============================================================================== --- stable/11/Makefile Mon Sep 11 01:51:27 2017 (r323412) +++ stable/11/Makefile Mon Sep 11 01:53:22 2017 (r323413) @@ -521,6 +521,8 @@ TARGET!= uname -m .endif .if defined(MAKE_ALL_KERNELS) _THINNER=cat +.elif defined(MAKE_LINT_KERNELS) +_THINNER=grep 'LINT' || true .else _THINNER=xargs grep -L "^.NO_UNIVERSE" || true .endif From owner-svn-src-stable-11@freebsd.org Mon Sep 11 01:59:26 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 62314E119A4; Mon, 11 Sep 2017 01:59:26 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 2FE566A531; Mon, 11 Sep 2017 01:59:26 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B1xP6p056651; Mon, 11 Sep 2017 01:59:25 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B1xP3J056646; Mon, 11 Sep 2017 01:59:25 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110159.v8B1xP3J056646@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 01:59:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323414 - in stable/11/sys: conf dev/ffec dev/mii X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: conf dev/ffec dev/mii X-SVN-Commit-Revision: 323414 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 01:59:26 -0000 Author: ian Date: Mon Sep 11 01:59:24 2017 New Revision: 323414 URL: https://svnweb.freebsd.org/changeset/base/323414 Log: MFC r319814, r319815, r319818: Add a set of constants describing the ways a MAC and PHY can be connected. While the initial need for this is to help support phy drivers which are configured with FDT data, there is nothing devicetree-specific about the concept or the names, so they are available for use even on non-FDT systems. Add some utility functions to help a PHY driver on an FDT-configured system retrieve its config data from the fdt data. Convert if_ffec from local code and constants for mac<->phy connection type to new common fdt helper code. Added: stable/11/sys/dev/mii/mii_fdt.c - copied unchanged from r319815, head/sys/dev/mii/mii_fdt.c stable/11/sys/dev/mii/mii_fdt.h - copied unchanged from r319815, head/sys/dev/mii/mii_fdt.h Modified: stable/11/sys/conf/files stable/11/sys/dev/ffec/if_ffec.c stable/11/sys/dev/mii/miivar.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/conf/files ============================================================================== --- stable/11/sys/conf/files Mon Sep 11 01:53:22 2017 (r323413) +++ stable/11/sys/conf/files Mon Sep 11 01:59:24 2017 (r323414) @@ -2166,6 +2166,7 @@ dev/mii/micphy.c optional miibus fdt | micphy fdt dev/mii/mii.c optional miibus | mii dev/mii/mii_bitbang.c optional miibus | mii_bitbang dev/mii/mii_physubr.c optional miibus | mii +dev/mii/mii_fdt.c optional miibus fdt | mii fdt dev/mii/miibus_if.m optional miibus | mii dev/mii/mlphy.c optional miibus | mlphy dev/mii/nsgphy.c optional miibus | nsgphy Modified: stable/11/sys/dev/ffec/if_ffec.c ============================================================================== --- stable/11/sys/dev/ffec/if_ffec.c Mon Sep 11 01:53:22 2017 (r323413) +++ stable/11/sys/dev/ffec/if_ffec.c Mon Sep 11 01:59:24 2017 (r323414) @@ -84,6 +84,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include "miibus_if.h" /* @@ -135,13 +136,6 @@ struct ffec_bufmap { bus_dmamap_t map; }; -enum { - PHY_CONN_UNKNOWN, - PHY_CONN_MII, - PHY_CONN_RMII, - PHY_CONN_RGMII -}; - struct ffec_softc { device_t dev; device_t miibus; @@ -153,7 +147,7 @@ struct ffec_softc { struct resource *mem_res; void * intr_cookie; struct callout ffec_callout; - uint8_t phy_conn_type; + mii_contype_t phy_conn_type; uint8_t fectype; boolean_t link_is_up; boolean_t is_attached; @@ -262,10 +256,10 @@ ffec_miigasket_setup(struct ffec_softc *sc) switch (sc->phy_conn_type) { - case PHY_CONN_MII: + case MII_CONTYPE_MII: ifmode = 0; break; - case PHY_CONN_RMII: + case MII_CONTYPE_RMII: ifmode = FEC_MIIGSK_CFGR_IF_MODE_RMII; break; default: @@ -377,14 +371,17 @@ ffec_miibus_statchg(device_t dev) rcr |= FEC_RCR_MII_MODE; /* Must always be on even for R[G]MII. */ switch (sc->phy_conn_type) { - case PHY_CONN_MII: - break; - case PHY_CONN_RMII: + case MII_CONTYPE_RMII: rcr |= FEC_RCR_RMII_MODE; break; - case PHY_CONN_RGMII: + case MII_CONTYPE_RGMII: + case MII_CONTYPE_RGMII_ID: + case MII_CONTYPE_RGMII_RXID: + case MII_CONTYPE_RGMII_TXID: rcr |= FEC_RCR_RGMII_EN; break; + default: + break; } switch (IFM_SUBTYPE(mii->mii_media_active)) { @@ -1440,7 +1437,6 @@ ffec_attach(device_t dev) phandle_t ofw_node; int error, phynum, rid; uint8_t eaddr[ETHER_ADDR_LEN]; - char phy_conn_name[32]; uint32_t idx, mscr; sc = device_get_softc(dev); @@ -1463,16 +1459,8 @@ ffec_attach(device_t dev) error = ENXIO; goto out; } - if (OF_searchprop(ofw_node, "phy-mode", - phy_conn_name, sizeof(phy_conn_name)) != -1) { - if (strcasecmp(phy_conn_name, "mii") == 0) - sc->phy_conn_type = PHY_CONN_MII; - else if (strcasecmp(phy_conn_name, "rmii") == 0) - sc->phy_conn_type = PHY_CONN_RMII; - else if (strcasecmp(phy_conn_name, "rgmii") == 0) - sc->phy_conn_type = PHY_CONN_RGMII; - } - if (sc->phy_conn_type == PHY_CONN_UNKNOWN) { + sc->phy_conn_type = mii_fdt_get_contype(ofw_node); + if (sc->phy_conn_type == MII_CONTYPE_UNKNOWN) { device_printf(sc->dev, "No valid 'phy-mode' " "property found in FDT data for device.\n"); error = ENOATTR; Copied: stable/11/sys/dev/mii/mii_fdt.c (from r319815, head/sys/dev/mii/mii_fdt.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/dev/mii/mii_fdt.c Mon Sep 11 01:59:24 2017 (r323414, copy of r319815, head/sys/dev/mii/mii_fdt.c) @@ -0,0 +1,200 @@ +/*- + * Copyright (c) 2017 Ian Lepore + * All rights reserved. + * + * Development sponsored by Microsemi, Inc. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * Utility functions for PHY drivers on systems configured using FDT data. + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include + +/* + * Table to translate MII_CONTYPE_xxxx constants to/from devicetree strings. + * We explicitly associate the enum values with the strings in a table to avoid + * relying on this list being sorted in the same order as the enum in miivar.h, + * and to avoid problems if the enum gains new types that aren't in the FDT + * data. However, the "unknown" entry must be first because it is referenced + * using subscript 0 in mii_fdt_contype_to_name(). + */ +static struct contype_names { + mii_contype_t type; + const char *name; +} fdt_contype_names[] = { + {MII_CONTYPE_UNKNOWN, "unknown"}, + {MII_CONTYPE_MII, "mii"}, + {MII_CONTYPE_GMII, "gmii"}, + {MII_CONTYPE_SGMII, "sgmii"}, + {MII_CONTYPE_QSGMII, "qsgmii"}, + {MII_CONTYPE_TBI, "tbi"}, + {MII_CONTYPE_REVMII, "rev-mii"}, + {MII_CONTYPE_RMII, "rmii"}, + {MII_CONTYPE_RGMII, "rgmii"}, + {MII_CONTYPE_RGMII_ID, "rgmii-id"}, + {MII_CONTYPE_RGMII_RXID, "rgmii-rxid"}, + {MII_CONTYPE_RGMII_TXID, "rgmii-txid"}, + {MII_CONTYPE_RTBI, "rtbi"}, + {MII_CONTYPE_SMII, "smii"}, + {MII_CONTYPE_XGMII, "xgmii"}, + {MII_CONTYPE_TRGMII, "trgmii"}, + {MII_CONTYPE_2000BX, "2000base-x"}, + {MII_CONTYPE_2500BX, "2500base-x"}, + {MII_CONTYPE_RXAUI, "rxaui"}, +}; + +static phandle_t +mii_fdt_get_phynode(phandle_t macnode) +{ + static const char *props[] = { + "phy-handle", "phy", "phy-device" + }; + pcell_t xref; + u_int i; + + for (i = 0; i < nitems(props); ++i) { + if (OF_getencprop(macnode, props[i], &xref, sizeof(xref)) > 0) + return (OF_node_from_xref(xref)); + } + return (-1); +} + +mii_contype_t +mii_fdt_contype_from_name(const char *name) +{ + u_int i; + + for (i = 0; i < nitems(fdt_contype_names); ++i) { + if (strcmp(name, fdt_contype_names[i].name) == 0) + return (fdt_contype_names[i].type); + } + return (MII_CONTYPE_UNKNOWN); +} + +const char * +mii_fdt_contype_to_name(mii_contype_t contype) +{ + u_int i; + + for (i = 0; i < nitems(fdt_contype_names); ++i) { + if (contype == fdt_contype_names[i].type) + return (fdt_contype_names[i].name); + } + return (fdt_contype_names[0].name); +} + +mii_contype_t +mii_fdt_get_contype(phandle_t macnode) +{ + char val[32]; + + if (OF_getprop(macnode, "phy-mode", val, sizeof(val)) <= 0 && + OF_getprop(macnode, "phy-connection-type", val, sizeof(val)) <= 0) { + return (MII_CONTYPE_UNKNOWN); + } + return (mii_fdt_contype_from_name(val)); +} + +void +mii_fdt_free_config(struct mii_fdt_phy_config *cfg) +{ + + free(cfg, M_OFWPROP); +} + +mii_fdt_phy_config_t * +mii_fdt_get_config(device_t phydev) +{ + mii_fdt_phy_config_t *cfg; + device_t miibus, macdev; + pcell_t val; + + miibus = device_get_parent(phydev); + macdev = device_get_parent(miibus); + + cfg = malloc(sizeof(*cfg), M_OFWPROP, M_ZERO | M_WAITOK); + + /* + * If we can't find our parent MAC's node, there's nothing more we can + * fill in; cfg is already full of zero/default values, return it. + */ + if ((cfg->macnode = ofw_bus_get_node(macdev)) == -1) + return (cfg); + + cfg->con_type = mii_fdt_get_contype(cfg->macnode); + + /* + * If we can't find our own PHY node, there's nothing more we can fill + * in, just return what we've got. + */ + if ((cfg->phynode = mii_fdt_get_phynode(cfg->macnode)) == -1) + return (cfg); + + if (OF_getencprop(cfg->phynode, "max-speed", &val, sizeof(val)) > 0) + cfg->max_speed = val; + + if (ofw_bus_node_is_compatible(cfg->phynode, + "ethernet-phy-ieee802.3-c45")) + cfg->flags |= MIIF_FDT_COMPAT_CLAUSE45; + + if (OF_hasprop(cfg->phynode, "broken-turn-around")) + cfg->flags |= MIIF_FDT_BROKEN_TURNAROUND; + if (OF_hasprop(cfg->phynode, "enet-phy-lane-swap")) + cfg->flags |= MIIF_FDT_LANE_SWAP; + if (OF_hasprop(cfg->phynode, "enet-phy-lane-no-swap")) + cfg->flags |= MIIF_FDT_NO_LANE_SWAP; + if (OF_hasprop(cfg->phynode, "eee-broken-100tx")) + cfg->flags |= MIIF_FDT_EEE_BROKEN_100TX; + if (OF_hasprop(cfg->phynode, "eee-broken-1000t")) + cfg->flags |= MIIF_FDT_EEE_BROKEN_1000T; + if (OF_hasprop(cfg->phynode, "eee-broken-10gt")) + cfg->flags |= MIIF_FDT_EEE_BROKEN_10GT; + if (OF_hasprop(cfg->phynode, "eee-broken-1000kx")) + cfg->flags |= MIIF_FDT_EEE_BROKEN_1000KX; + if (OF_hasprop(cfg->phynode, "eee-broken-10gkx4")) + cfg->flags |= MIIF_FDT_EEE_BROKEN_10GKX4; + if (OF_hasprop(cfg->phynode, "eee-broken-10gkr")) + cfg->flags |= MIIF_FDT_EEE_BROKEN_10GKR; + + return (cfg); +} Copied: stable/11/sys/dev/mii/mii_fdt.h (from r319815, head/sys/dev/mii/mii_fdt.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/dev/mii/mii_fdt.h Mon Sep 11 01:59:24 2017 (r323414, copy of r319815, head/sys/dev/mii/mii_fdt.h) @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 2017 Ian Lepore + * All rights reserved. + * + * Development sponsored by Microsemi, Inc. + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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$ + */ + +#ifndef _DEV_MII_FDT_H_ +#define _DEV_MII_FDT_H_ + +/* + * Common FDT config for a PHY, as documented in the devicetree bindings + * documents ethernet.txt and phy.txt. Boolean properties are represented as + * bits in the flags member. + */ +struct mii_fdt_phy_config { + phandle_t macnode; /* Node (not xref) of parent MAC */ + phandle_t phynode; /* Node (not xref) of PHY */ + mii_contype_t con_type; /* MAC<->PHY connection type */ + u_int max_speed; /* Mbits/sec, 0 = not specified */ + uint32_t flags; /* MIIF_FDT_xxx boolean properties */ +}; +typedef struct mii_fdt_phy_config mii_fdt_phy_config_t; + +/* PHY config flags. */ +#define MIIF_FDT_COMPAT_CLAUSE45 0x0001 +#define MIIF_FDT_BROKEN_TURNAROUND 0x0002 +#define MIIF_FDT_LANE_SWAP 0x0004 +#define MIIF_FDT_NO_LANE_SWAP 0x0008 +#define MIIF_FDT_EEE_BROKEN_100TX 0x0010 +#define MIIF_FDT_EEE_BROKEN_1000T 0x0020 +#define MIIF_FDT_EEE_BROKEN_10GT 0x0040 +#define MIIF_FDT_EEE_BROKEN_1000KX 0x0080 +#define MIIF_FDT_EEE_BROKEN_10GKX4 0x0100 +#define MIIF_FDT_EEE_BROKEN_10GKR 0x0200 + +/* + * Convert between mii_contype enums and devicetree property strings. + */ +const char *mii_fdt_contype_to_name(mii_contype_t contype); +mii_contype_t mii_fdt_contype_from_name(const char *name); + +/* Get the connection type from the given MAC node. */ +mii_contype_t mii_fdt_get_contype(phandle_t macnode); + +/* + * Get/free the config for the given PHY device. + */ +void mii_fdt_free_config(struct mii_fdt_phy_config *cfg); +mii_fdt_phy_config_t *mii_fdt_get_config(device_t phydev); + +#endif Modified: stable/11/sys/dev/mii/miivar.h ============================================================================== --- stable/11/sys/dev/mii/miivar.h Mon Sep 11 01:53:22 2017 (r323413) +++ stable/11/sys/dev/mii/miivar.h Mon Sep 11 01:59:24 2017 (r323414) @@ -156,6 +156,42 @@ typedef struct mii_softc mii_softc_t; #define MII_PHY_ANY -1 /* + * Constants used to describe the type of attachment between MAC and PHY. + */ +enum mii_contype { + MII_CONTYPE_UNKNOWN, /* Must be have value 0. */ + + MII_CONTYPE_MII, + MII_CONTYPE_GMII, + MII_CONTYPE_SGMII, + MII_CONTYPE_QSGMII, + MII_CONTYPE_TBI, + MII_CONTYPE_REVMII, /* Reverse MII */ + MII_CONTYPE_RMII, + MII_CONTYPE_RGMII, /* Delays provided by MAC or PCB */ + MII_CONTYPE_RGMII_ID, /* Rx and tx delays provided by PHY */ + MII_CONTYPE_RGMII_RXID, /* Only rx delay provided by PHY */ + MII_CONTYPE_RGMII_TXID, /* Only tx delay provided by PHY */ + MII_CONTYPE_RTBI, + MII_CONTYPE_SMII, + MII_CONTYPE_XGMII, + MII_CONTYPE_TRGMII, + MII_CONTYPE_2000BX, + MII_CONTYPE_2500BX, + MII_CONTYPE_RXAUI, + + MII_CONTYPE_COUNT /* Add new types before this line. */ +}; +typedef enum mii_contype mii_contype_t; + +static inline bool +mii_contype_is_rgmii(mii_contype_t con) +{ + + return (con >= MII_CONTYPE_RGMII && con <= MII_CONTYPE_RGMII_TXID); +} + +/* * Used to attach a PHY to a parent. */ struct mii_attach_args { From owner-svn-src-stable-11@freebsd.org Mon Sep 11 02:13:52 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EFBB9E12452; Mon, 11 Sep 2017 02:13:52 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id CB96C6AC69; Mon, 11 Sep 2017 02:13:52 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B2DpxX064602; Mon, 11 Sep 2017 02:13:51 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B2DpZg064599; Mon, 11 Sep 2017 02:13:51 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110213.v8B2DpZg064599@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 02:13:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323415 - in stable/11/sys: conf dev/mii X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: conf dev/mii X-SVN-Commit-Revision: 323415 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 02:13:53 -0000 Author: ian Date: Mon Sep 11 02:13:51 2017 New Revision: 323415 URL: https://svnweb.freebsd.org/changeset/base/323415 Log: MFC r319817: Add a driver for the Vitesse/Microsemi VSC8501 PHY. Added: stable/11/sys/dev/mii/vscphy.c - copied unchanged from r319817, head/sys/dev/mii/vscphy.c Modified: stable/11/sys/conf/files stable/11/sys/dev/mii/miidevs Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/conf/files ============================================================================== --- stable/11/sys/conf/files Mon Sep 11 01:59:24 2017 (r323414) +++ stable/11/sys/conf/files Mon Sep 11 02:13:51 2017 (r323415) @@ -2185,6 +2185,7 @@ dev/mii/tlphy.c optional miibus | tlphy dev/mii/truephy.c optional miibus | truephy dev/mii/ukphy.c optional miibus | mii dev/mii/ukphy_subr.c optional miibus | mii +dev/mii/vscphy.c optional miibus | vscphy dev/mii/xmphy.c optional miibus | xmphy dev/mk48txx/mk48txx.c optional mk48txx dev/mlx/mlx.c optional mlx Modified: stable/11/sys/dev/mii/miidevs ============================================================================== --- stable/11/sys/dev/mii/miidevs Mon Sep 11 01:59:24 2017 (r323414) +++ stable/11/sys/dev/mii/miidevs Mon Sep 11 02:13:51 2017 (r323415) @@ -337,7 +337,8 @@ model TI TNETE2101 0x0003 TNETE2101 media interface model xxTSC 78Q2120 0x0014 78Q2120 10/100 media interface model xxTSC 78Q2121 0x0015 78Q2121 100BASE-TX media interface -/* Vitesse Semiconductor */ +/* Vitesse Semiconductor (now Microsemi) */ +model xxVITESSE VSC8501 0x0013 Vitesse VSC8501 10/100/1000TX PHY model xxVITESSE VSC8641 0x0003 Vitesse VSC8641 10/100/1000TX PHY /* XaQti Corp. PHYs */ Copied: stable/11/sys/dev/mii/vscphy.c (from r319817, head/sys/dev/mii/vscphy.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/dev/mii/vscphy.c Mon Sep 11 02:13:51 2017 (r323415, copy of r319817, head/sys/dev/mii/vscphy.c) @@ -0,0 +1,272 @@ +/*- + * Copyright (c) 2017 Ian Lepore + * All rights reserved. + * + * Development sponsored by Microsemi, Inc. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * Microsemi / Vitesse VSC8501 (and similar). + */ + +#include "opt_platform.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include "miidevs.h" +#include "miibus_if.h" + +#ifdef FDT +#include +#include +#include +#include +#endif + +/* Vitesse VSC8501 */ +#define VSC8501_EXTPAGE_REG 0x001f + +#define VSC8501_EXTCTL1_REG 0x0017 +#define VSC8501_EXTCTL1_RGMII_MODE (1u << 12) + +#define VSC8501_RGMII_CTRL_PAGE 0x02 +#define VSC8501_RGMII_CTRL_REG 0x14 +#define VSC8501_RGMII_DELAY_MASK 0x07 +#define VSC8501_RGMII_DELAY_TXSHIFT 0 +#define VSC8501_RGMII_DELAY_RXSHIFT 4 +#define VSC8501_RGMII_RXCLOCK_DISABLE (1u << 11) +#define VSC8501_RGMII_RXSWAP (1u << 7) +#define VSC8501_RGMII_TXSWAP (1u << 3) +#define VSC8501_RGMII_LANESWAP (VSC8501_RGMII_RXSWAP | \ + VSC8501_RGMII_TXSWAP) + +struct vscphy_softc { + mii_softc_t mii_sc; + device_t dev; + mii_contype_t contype; + int rxdelay; + int txdelay; + bool laneswap; +}; + +static void vscphy_reset(struct mii_softc *); +static int vscphy_service(struct mii_softc *, struct mii_data *, int); + +static const struct mii_phydesc vscphys[] = { + MII_PHY_DESC(xxVITESSE, VSC8501), + MII_PHY_END +}; + +static const struct mii_phy_funcs vscphy_funcs = { + vscphy_service, + ukphy_status, + vscphy_reset +}; + +#ifdef FDT +static void +vscphy_fdt_get_config(struct vscphy_softc *vsc) +{ + mii_fdt_phy_config_t *cfg; + pcell_t val; + + cfg = mii_fdt_get_config(vsc->dev); + vsc->contype = cfg->con_type; + vsc->laneswap = (cfg->flags & MIIF_FDT_LANE_SWAP) && + !(cfg->flags & MIIF_FDT_NO_LANE_SWAP); + if (OF_getencprop(cfg->phynode, "rx-delay", &val, sizeof(val)) > 0) + vsc->rxdelay = val; + if (OF_getencprop(cfg->phynode, "tx-delay", &val, sizeof(val)) > 0) + vsc->txdelay = val; + mii_fdt_free_config(cfg); +} +#endif + +static inline int +vscphy_read(struct vscphy_softc *sc, u_int reg) +{ + u_int val; + + val = PHY_READ(&sc->mii_sc, reg); + return (val); +} + +static inline void +vscphy_write(struct vscphy_softc *sc, u_int reg, u_int val) +{ + + PHY_WRITE(&sc->mii_sc, reg, val); +} + +static void +vsc8501_setup_rgmii(struct vscphy_softc *vsc) +{ + int reg; + + vscphy_write(vsc, VSC8501_EXTPAGE_REG, VSC8501_RGMII_CTRL_PAGE); + + reg = vscphy_read(vsc, VSC8501_RGMII_CTRL_REG); + reg &= ~VSC8501_RGMII_RXCLOCK_DISABLE; + reg &= ~VSC8501_RGMII_LANESWAP; + reg &= ~(VSC8501_RGMII_DELAY_MASK << VSC8501_RGMII_DELAY_TXSHIFT); + reg &= ~(VSC8501_RGMII_DELAY_MASK << VSC8501_RGMII_DELAY_RXSHIFT); + if (vsc->laneswap) + reg |= VSC8501_RGMII_LANESWAP; + if (vsc->contype == MII_CONTYPE_RGMII_ID || + vsc->contype == MII_CONTYPE_RGMII_TXID) { + reg |= vsc->txdelay << VSC8501_RGMII_DELAY_TXSHIFT; + } + if (vsc->contype == MII_CONTYPE_RGMII_ID || + vsc->contype == MII_CONTYPE_RGMII_RXID) { + reg |= vsc->rxdelay << VSC8501_RGMII_DELAY_RXSHIFT; + } + vscphy_write(vsc, VSC8501_RGMII_CTRL_REG, reg); + + vscphy_write(vsc, VSC8501_EXTPAGE_REG, 0); +} + +static void +vsc8501_reset(struct vscphy_softc *vsc) +{ + int reg; + + /* + * Must set whether the mac<->phy connection is RGMII first; changes to + * that bit take effect only after a softreset. + */ + reg = vscphy_read(vsc, VSC8501_EXTCTL1_REG); + if (mii_contype_is_rgmii(vsc->contype)) + reg |= VSC8501_EXTCTL1_RGMII_MODE; + else + reg &= ~VSC8501_EXTCTL1_RGMII_MODE; + vscphy_write(vsc, VSC8501_EXTCTL1_REG, reg); + + mii_phy_reset(&vsc->mii_sc); + + /* + * Setup rgmii control register if necessary, after softreset. + */ + if (mii_contype_is_rgmii(vsc->contype)) + vsc8501_setup_rgmii(vsc); +} + +static void +vscphy_reset(struct mii_softc *sc) +{ + struct vscphy_softc *vsc = (struct vscphy_softc *)sc; + + switch (sc->mii_mpd_model) { + case MII_MODEL_xxVITESSE_VSC8501: + vsc8501_reset(vsc); + break; + default: + mii_phy_reset(sc); + break; + } +} + +static int +vscphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +{ + + switch (cmd) { + case MII_POLLSTAT: + break; + + case MII_MEDIACHG: + mii_phy_setmedia(sc); + break; + + case MII_TICK: + if (mii_phy_tick(sc) == EJUSTRETURN) + return (0); + break; + } + + /* Update the media status. */ + PHY_STATUS(sc); + + /* Callback if something changed. */ + mii_phy_update(sc, cmd); + return (0); +} + +static int +vscphy_probe(device_t dev) +{ + + return (mii_phy_dev_probe(dev, vscphys, BUS_PROBE_DEFAULT)); +} + +static int +vscphy_attach(device_t dev) +{ + struct vscphy_softc *vsc; + + vsc = device_get_softc(dev); + vsc->dev = dev; + +#ifdef FDT + vscphy_fdt_get_config(vsc); +#endif + + mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &vscphy_funcs, 1); + mii_phy_setmedia(&vsc->mii_sc); + + return (0); +} + +static device_method_t vscphy_methods[] = { + /* device interface */ + DEVMETHOD(device_probe, vscphy_probe), + DEVMETHOD(device_attach, vscphy_attach), + DEVMETHOD(device_detach, mii_phy_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + DEVMETHOD_END +}; + +static devclass_t vscphy_devclass; + +static driver_t vscphy_driver = { + "vscphy", + vscphy_methods, + sizeof(struct vscphy_softc) +}; + +DRIVER_MODULE(vscphy, miibus, vscphy_driver, vscphy_devclass, 0, 0); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 02:14:30 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 59A43E12554; Mon, 11 Sep 2017 02:14:30 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 283E06ADB2; Mon, 11 Sep 2017 02:14:30 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B2ETXk064670; Mon, 11 Sep 2017 02:14:29 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B2ETla064669; Mon, 11 Sep 2017 02:14:29 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110214.v8B2ETla064669@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 02:14:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323416 - stable/11/sys/modules/ffec X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/modules/ffec X-SVN-Commit-Revision: 323416 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 02:14:30 -0000 Author: ian Date: Mon Sep 11 02:14:28 2017 New Revision: 323416 URL: https://svnweb.freebsd.org/changeset/base/323416 Log: MFC r319899: Add missing header dependencies. Modified: stable/11/sys/modules/ffec/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/modules/ffec/Makefile ============================================================================== --- stable/11/sys/modules/ffec/Makefile Mon Sep 11 02:13:51 2017 (r323415) +++ stable/11/sys/modules/ffec/Makefile Mon Sep 11 02:14:28 2017 (r323416) @@ -3,6 +3,6 @@ .PATH: ${SRCTOP}/sys/dev/ffec KMOD= if_ffec -SRCS= if_ffec.c miibus_if.h device_if.h bus_if.h pci_if.h +SRCS= if_ffec.c miibus_if.h device_if.h bus_if.h pci_if.h ofw_bus_if.h opt_global.h .include From owner-svn-src-stable-11@freebsd.org Mon Sep 11 02:26:02 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CB095E12EA8; Mon, 11 Sep 2017 02:26:02 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 99EAA6B2F6; Mon, 11 Sep 2017 02:26:02 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B2Q1X3068631; Mon, 11 Sep 2017 02:26:01 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B2Q12G068630; Mon, 11 Sep 2017 02:26:01 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110226.v8B2Q12G068630@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 02:26:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323417 - stable/11/sys/arm/freescale/imx X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/freescale/imx X-SVN-Commit-Revision: 323417 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 02:26:02 -0000 Author: ian Date: Mon Sep 11 02:26:01 2017 New Revision: 323417 URL: https://svnweb.freebsd.org/changeset/base/323417 Log: MFC r320456: Implement gpio input by reading the pad state register, not the data register. Modified: stable/11/sys/arm/freescale/imx/imx_gpio.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/imx_gpio.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_gpio.c Mon Sep 11 02:14:28 2017 (r323416) +++ stable/11/sys/arm/freescale/imx/imx_gpio.c Mon Sep 11 02:26:01 2017 (r323417) @@ -645,7 +645,7 @@ imx51_gpio_pin_get(device_t dev, uint32_t pin, unsigne if (pin >= sc->gpio_npins) return (EINVAL); - *val = (READ4(sc, IMX_GPIO_DR_REG) >> pin) & 1; + *val = (READ4(sc, IMX_GPIO_PSR_REG) >> pin) & 1; return (0); } From owner-svn-src-stable-11@freebsd.org Mon Sep 11 02:38:59 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 72B3DE139D7; Mon, 11 Sep 2017 02:38:59 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 229FF6B82F; Mon, 11 Sep 2017 02:38:59 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B2cwOU073138; Mon, 11 Sep 2017 02:38:58 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B2cw4M073133; Mon, 11 Sep 2017 02:38:58 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110238.v8B2cw4M073133@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 02:38:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323418 - stable/11/sys/arm/freescale/imx X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/freescale/imx X-SVN-Commit-Revision: 323418 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 02:38:59 -0000 Author: ian Date: Mon Sep 11 02:38:57 2017 New Revision: 323418 URL: https://svnweb.freebsd.org/changeset/base/323418 Log: MFC r320076: Add a driver for the imx6 EPIT timer that can be used as the system timecounter instead of the GPT timer, freeing up the more flexible GPT hardware for other uses. The EPIT driver is a standard (always in the kernel) driver, and the existing GPT driver is now optional and included only if you ask for device imx_gpt. Added: stable/11/sys/arm/freescale/imx/imx_epit.c - copied unchanged from r320076, head/sys/arm/freescale/imx/imx_epit.c Modified: stable/11/sys/arm/freescale/imx/files.imx6 stable/11/sys/arm/freescale/imx/imx6_ccm.c stable/11/sys/arm/freescale/imx/imx6_ccmreg.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/files.imx6 ============================================================================== --- stable/11/sys/arm/freescale/imx/files.imx6 Mon Sep 11 02:26:01 2017 (r323417) +++ stable/11/sys/arm/freescale/imx/files.imx6 Mon Sep 11 02:38:57 2017 (r323418) @@ -15,9 +15,10 @@ arm/freescale/imx/imx6_machdep.c standard arm/freescale/imx/imx6_mp.c optional smp arm/freescale/imx/imx6_pl310.c standard arm/freescale/imx/imx6_src.c standard +arm/freescale/imx/imx_epit.c standard arm/freescale/imx/imx_iomux.c standard arm/freescale/imx/imx_machdep.c standard -arm/freescale/imx/imx_gpt.c standard +arm/freescale/imx/imx_gpt.c optional imx_gpt arm/freescale/imx/imx_gpio.c optional gpio arm/freescale/imx/imx_i2c.c optional fsliic arm/freescale/imx/imx6_sdma.c optional sdma Modified: stable/11/sys/arm/freescale/imx/imx6_ccm.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx6_ccm.c Mon Sep 11 02:26:01 2017 (r323417) +++ stable/11/sys/arm/freescale/imx/imx6_ccm.c Mon Sep 11 02:38:57 2017 (r323418) @@ -94,8 +94,8 @@ ccm_init_gates(struct ccm_softc *sc) reg = CCGR0_AIPS_TZ1 | CCGR0_AIPS_TZ2 | CCGR0_ABPHDMA; WR4(sc, CCM_CCGR0, reg); - /* gpt, enet */ - reg = CCGR1_ENET | CCGR1_GPT; + /* enet, epit, gpt */ + reg = CCGR1_ENET | CCGR1_EPIT1 | CCGR1_GPT; WR4(sc, CCM_CCGR1, reg); /* ipmux & ipsync (bridges), iomux, i2c */ Modified: stable/11/sys/arm/freescale/imx/imx6_ccmreg.h ============================================================================== --- stable/11/sys/arm/freescale/imx/imx6_ccmreg.h Mon Sep 11 02:26:01 2017 (r323417) +++ stable/11/sys/arm/freescale/imx/imx6_ccmreg.h Mon Sep 11 02:38:57 2017 (r323418) @@ -79,7 +79,10 @@ #define CCGR0_ABPHDMA (0x3 << 4) #define CCM_CCGR1 0x06C #define CCGR1_ENET (0x3 << 10) +#define CCGR1_EPIT1 (0x3 << 12) +#define CCGR1_EPIT2 (0x3 << 14) #define CCGR1_GPT (0x3 << 20) +#define CCGR1_GPT_SERIAL (0x3 << 22) #define CCM_CCGR2 0x070 #define CCGR2_HDMI_TX (0x3 << 0) #define CCGR2_HDMI_TX_ISFR (0x3 << 4) Copied: stable/11/sys/arm/freescale/imx/imx_epit.c (from r320076, head/sys/arm/freescale/imx/imx_epit.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/arm/freescale/imx/imx_epit.c Mon Sep 11 02:38:57 2017 (r323418, copy of r320076, head/sys/arm/freescale/imx/imx_epit.c) @@ -0,0 +1,528 @@ +/*- + * Copyright (c) 2017 Ian Lepore + * All rights reserved. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * Driver for imx Enhanced Programmable Interval Timer, a simple free-running + * counter device that can be used as the system timecounter. On imx5 a second + * instance of the device is used as the system eventtimer. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#define EPIT_CR 0x00 /* Control register */ +#define EPIT_CR_CLKSRC_SHIFT 24 +#define EPIT_CR_CLKSRC_OFF 0 +#define EPIT_CR_CLKSRC_IPG 1 +#define EPIT_CR_CLKSRC_HFCLK 2 +#define EPIT_CR_CLKSRC_LFCLK 3 +#define EPIT_CR_STOPEN (1u << 21) +#define EPIT_CR_WAITEN (1u << 19) +#define EPIT_CR_DBGEN (1u << 18) +#define EPIT_CR_IOVW (1u << 17) +#define EPIT_CR_SWR (1u << 16) +#define EPIT_CR_RLD (1u << 3) +#define EPIT_CR_OCIEN (1u << 2) +#define EPIT_CR_ENMOD (1u << 1) +#define EPIT_CR_EN (1u << 0) + +#define EPIT_SR 0x04 /* Status register */ +#define EPIT_SR_OCIF (1u << 0) + +#define EPIT_LR 0x08 /* Load register */ +#define EPIT_CMPR 0x0c /* Compare register */ +#define EPIT_CNR 0x10 /* Counter register */ + +/* + * Define event timer limits. + * + * In theory our minimum period is 1 tick, because to setup a oneshot we don't + * need a read-modify-write sequence to calculate and set a compare register + * value while the counter is running. In practice the waveform diagrams in the + * manual make it appear that a setting of 1 might cause it to miss the event, + * so I'm setting the lower limit to 2 ticks. + */ +#define ET_MIN_TICKS 2 +#define ET_MAX_TICKS 0xfffffffe + +static u_int epit_tc_get_timecount(struct timecounter *tc); + +struct epit_softc { + device_t dev; + struct resource * memres; + struct resource * intres; + void * inthandle; + uint32_t clkfreq; + uint32_t ctlreg; + uint32_t period; + struct timecounter tc; + struct eventtimer et; + bool oneshot; +}; + +#ifndef MULTIDELAY +/* Global softc pointer for use in DELAY(). */ +static struct epit_softc *epit_sc; +#endif + +/* + * Probe data. For some reason, the standard linux dts files don't have + * compatible properties on the epit devices (other properties are missing too, + * like clocks, but we don't care as much about that). So our probe routine + * uses the name of the node (must contain "epit") and the address of the + * registers as identifying marks. + */ +static const uint32_t imx51_epit_ioaddr[2] = {0x73fac000, 0x73fb0000}; +static const uint32_t imx53_epit_ioaddr[2] = {0x53fac000, 0x53fb0000}; +static const uint32_t imx6_epit_ioaddr[2] = {0x020d0000, 0x020d4000}; + +/* ocd_data is number of units to instantiate on the platform */ +static struct ofw_compat_data compat_data[] = { + {"fsl,imx6ul-epit", 1}, + {"fsl,imx6sx-epit", 1}, + {"fsl,imx6q-epit", 1}, + {"fsl,imx6dl-epit", 1}, + {"fsl,imx53-epit", 2}, + {"fsl,imx51-epit", 2}, + {"fsl,imx31-epit", 2}, + {"fsl,imx27-epit", 2}, + {"fsl,imx25-epit", 2}, + {NULL, 0} +}; + +static inline uint32_t +RD4(struct epit_softc *sc, bus_size_t offset) +{ + + return (bus_read_4(sc->memres, offset)); +} + +static inline void +WR4(struct epit_softc *sc, bus_size_t offset, uint32_t value) +{ + + bus_write_4(sc->memres, offset, value); +} + +static inline void +WR4B(struct epit_softc *sc, bus_size_t offset, uint32_t value) +{ + + bus_write_4(sc->memres, offset, value); + bus_barrier(sc->memres, offset, 4, BUS_SPACE_BARRIER_WRITE); +} + +static u_int +epit_read_counter(struct epit_softc *sc) +{ + + /* + * Hardware is a downcounter, adjust to look like it counts up for use + * with timecounter and DELAY. + */ + return (0xffffffff - RD4(sc, EPIT_CNR)); +} + +static void +epit_do_delay(int usec, void *arg) +{ + struct epit_softc *sc = arg; + uint64_t curcnt, endcnt, startcnt, ticks; + + /* + * Calculate the tick count with 64-bit values so that it works for any + * clock frequency. Loop until the hardware count reaches start+ticks. + * If the 32-bit hardware count rolls over while we're looping, just + * manually do a carry into the high bits after each read; don't worry + * that doing this on each loop iteration is inefficient -- we're trying + * to waste time here. + */ + ticks = 1 + ((uint64_t)usec * sc->clkfreq) / 1000000; + curcnt = startcnt = epit_read_counter(sc); + endcnt = startcnt + ticks; + while (curcnt < endcnt) { + curcnt = epit_read_counter(sc); + if (curcnt < startcnt) + curcnt += 1ULL << 32; + } +} + +static u_int +epit_tc_get_timecount(struct timecounter *tc) +{ + + return (epit_read_counter(tc->tc_priv)); +} + +static int +epit_tc_attach(struct epit_softc *sc) +{ + + /* When the counter hits zero, reload with 0xffffffff. Start it. */ + WR4(sc, EPIT_LR, 0xffffffff); + WR4(sc, EPIT_CR, sc->ctlreg | EPIT_CR_EN); + + /* Register as a timecounter. */ + sc->tc.tc_name = "EPIT"; + sc->tc.tc_quality = 1000; + sc->tc.tc_frequency = sc->clkfreq; + sc->tc.tc_counter_mask = 0xffffffff; + sc->tc.tc_get_timecount = epit_tc_get_timecount; + sc->tc.tc_priv = sc; + tc_init(&sc->tc); + + /* We are the DELAY() implementation. */ +#ifdef MULTIDELAY + arm_set_delay(epit_do_delay, sc); +#else + epit_sc = sc; +#endif + return (0); +} + +static int +epit_et_start(struct eventtimer *et, sbintime_t first, sbintime_t period) +{ + struct epit_softc *sc; + uint32_t ticks; + + sc = (struct epit_softc *)et->et_priv; + + /* + * Disable the timer and clear any pending status. The timer may be + * running or may have just expired if we're called to reschedule the + * next event before the previous event time arrives. + */ + WR4(sc, EPIT_CR, sc->ctlreg); + WR4(sc, EPIT_SR, EPIT_SR_OCIF); + if (period != 0) { + sc->oneshot = false; + ticks = ((uint32_t)et->et_frequency * period) >> 32; + } else if (first != 0) { + sc->oneshot = true; + ticks = ((uint32_t)et->et_frequency * first) >> 32; + } else { + return (EINVAL); + } + + /* Set the countdown load register and start the timer. */ + WR4(sc, EPIT_LR, ticks); + WR4B(sc, EPIT_CR, sc->ctlreg | EPIT_CR_EN); + + return (0); +} + +static int +epit_et_stop(struct eventtimer *et) +{ + struct epit_softc *sc; + + sc = (struct epit_softc *)et->et_priv; + + /* Disable the timer and clear any pending status. */ + WR4(sc, EPIT_CR, sc->ctlreg); + WR4B(sc, EPIT_SR, EPIT_SR_OCIF); + + return (0); +} + +static int +epit_intr(void *arg) +{ + struct epit_softc *sc; + uint32_t status; + + sc = arg; + + /* + * Disable a one-shot timer until a new event is scheduled so that the + * counter doesn't wrap and fire again. Do this before clearing the + * status since a short period would make it fire again really soon. + * + * Clear interrupt status before invoking event callbacks. The callback + * often sets up a new one-shot timer event and if the interval is short + * enough it can fire before we get out of this function. If we cleared + * at the bottom we'd miss the interrupt and hang until the clock wraps. + */ + if (sc->oneshot) + WR4(sc, EPIT_CR, sc->ctlreg); + + status = RD4(sc, EPIT_SR); + WR4B(sc, EPIT_SR, status); + + if ((status & EPIT_SR_OCIF) == 0) + return (FILTER_STRAY); + + if (sc->et.et_active) + sc->et.et_event_cb(&sc->et, sc->et.et_arg); + + return (FILTER_HANDLED); +} + +static int +epit_et_attach(struct epit_softc *sc) +{ + int err, rid; + + rid = 0; + sc->intres = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &rid, + RF_ACTIVE); + if (sc->intres == NULL) { + device_printf(sc->dev, "could not allocate interrupt\n"); + return (ENXIO); + } + + err = bus_setup_intr(sc->dev, sc->intres, INTR_TYPE_CLK | INTR_MPSAFE, + epit_intr, NULL, sc, &sc->inthandle); + if (err != 0) { + device_printf(sc->dev, "unable to setup the irq handler\n"); + return (err); + } + + /* To be an eventtimer, we need interrupts enabled. */ + sc->ctlreg |= EPIT_CR_OCIEN; + + /* Register as an eventtimer. */ + sc->et.et_name = "EPIT"; + sc->et.et_flags = ET_FLAGS_ONESHOT | ET_FLAGS_PERIODIC; + sc->et.et_quality = 1000; + sc->et.et_frequency = sc->clkfreq; + sc->et.et_min_period = ((uint64_t)ET_MIN_TICKS << 32) / sc->clkfreq; + sc->et.et_max_period = ((uint64_t)ET_MAX_TICKS << 32) / sc->clkfreq; + sc->et.et_start = epit_et_start; + sc->et.et_stop = epit_et_stop; + sc->et.et_priv = sc; + et_register(&sc->et); + + return (0); +} + +static int +epit_probe(device_t dev) +{ + struct resource *memres; + rman_res_t ioaddr; + int num_units, rid, unit; + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + /* + * The FDT data for imx5 and imx6 EPIT hardware is missing or broken, + * but it may get fixed some day, so first just do a normal check. We + * return success if the compatible string matches and we haven't + * already instantiated the number of units needed on this platform. + */ + unit = device_get_unit(dev); + num_units = ofw_bus_search_compatible(dev, compat_data)->ocd_data; + if (unit < num_units) { + device_set_desc(dev, "i.MX EPIT timer"); + return (BUS_PROBE_DEFAULT); + } + + /* + * No compat string match, but for imx6 all the data we need is in the + * node except the compat string, so do our own compatibility check + * using the device name of the node and the register block address. + */ + if (strstr(ofw_bus_get_name(dev), "epit") == NULL) + return (ENXIO); + + rid = 0; + memres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_UNMAPPED); + if (memres == NULL) + return (ENXIO); + ioaddr = rman_get_start(memres); + bus_free_resource(dev, SYS_RES_MEMORY, memres); + + if (imx_soc_family() == 6) { + if (unit > 0) + return (ENXIO); + if (ioaddr != imx6_epit_ioaddr[unit]) + return (ENXIO); + } else { + if (unit > 1) + return (ENXIO); + switch (imx_soc_type()) { + case IMXSOC_51: + if (ioaddr != imx51_epit_ioaddr[unit]) + return (ENXIO); + break; + case IMXSOC_53: + if (ioaddr != imx53_epit_ioaddr[unit]) + return (ENXIO); + break; + default: + return (ENXIO); + } + /* + * XXX Right now we have no way to handle the fact that the + * entire EPIT node is missing, which means no interrupt data. + */ + return (ENXIO); + } + + device_set_desc(dev, "i.MX EPIT timer"); + return (BUS_PROBE_DEFAULT); +} + +static int +epit_attach(device_t dev) +{ + struct epit_softc *sc; + int err, rid; + uint32_t clksrc; + + sc = device_get_softc(dev); + sc->dev = dev; + + rid = 0; + sc->memres = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY, &rid, + RF_ACTIVE); + if (sc->memres == NULL) { + device_printf(sc->dev, "could not allocate registers\n"); + return (ENXIO); + } + + /* + * For now, use ipg (66 MHz). Some day we should get this from fdt. + */ + clksrc = EPIT_CR_CLKSRC_IPG; + + switch (clksrc) { + default: + device_printf(dev, + "Unsupported clock source '%d', using IPG\n", clksrc); + /* FALLTHROUGH */ + case EPIT_CR_CLKSRC_IPG: + sc->clkfreq = imx_ccm_ipg_hz(); + break; + case EPIT_CR_CLKSRC_HFCLK: + sc->clkfreq = imx_ccm_perclk_hz(); + break; + case EPIT_CR_CLKSRC_LFCLK: + sc->clkfreq = 32768; + break; + } + + /* + * Init: stop operations and clear all options, then set up options and + * clock source, then do a soft-reset and wait for it to complete. + */ + WR4(sc, EPIT_CR, 0); + + sc->ctlreg = + (clksrc << EPIT_CR_CLKSRC_SHIFT) | /* Use selected clock */ + EPIT_CR_ENMOD | /* Reload counter on enable */ + EPIT_CR_RLD | /* Reload counter from LR */ + EPIT_CR_STOPEN | /* Run in STOP mode */ + EPIT_CR_WAITEN | /* Run in WAIT mode */ + EPIT_CR_DBGEN; /* Run in DEBUG mode */ + + WR4B(sc, EPIT_CR, sc->ctlreg | EPIT_CR_SWR); + while (RD4(sc, EPIT_CR) & EPIT_CR_SWR) + continue; + + /* + * Unit 0 is the timecounter, 1 (if instantiated) is the eventtimer. + */ + if (device_get_unit(sc->dev) == 0) + err = epit_tc_attach(sc); + else + err = epit_et_attach(sc); + + return (err); +} + +static device_method_t epit_methods[] = { + DEVMETHOD(device_probe, epit_probe), + DEVMETHOD(device_attach, epit_attach), + + DEVMETHOD_END +}; + +static driver_t epit_driver = { + "imx_epit", + epit_methods, + sizeof(struct epit_softc), +}; + +static devclass_t epit_devclass; + +EARLY_DRIVER_MODULE(imx_epit, simplebus, epit_driver, epit_devclass, 0, + 0, BUS_PASS_TIMER); + +#ifndef MULTIDELAY + +/* + * Hand-calibrated delay-loop counter. This was calibrated on an i.MX6 running + * at 792mhz. It will delay a bit too long on slower processors -- that's + * better than not delaying long enough. In practice this is unlikely to get + * used much since the clock driver is one of the first to start up, and once + * we're attached the delay loop switches to using the timer hardware. + */ +static const int epit_delay_count = 78; + +void +DELAY(int usec) +{ + uint64_t ticks; + + /* If the timer hardware is not accessible, just use a loop. */ + if (epit_sc == NULL) { + while (usec-- > 0) + for (ticks = 0; ticks < epit_delay_count; ++ticks) + cpufunc_nullop(); + return; + } else { + epit_do_delay(usec, epit_sc); + } +} + +#endif From owner-svn-src-stable-11@freebsd.org Mon Sep 11 02:50:25 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CEAC7E143FB; Mon, 11 Sep 2017 02:50:25 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 9C1C96BDE2; Mon, 11 Sep 2017 02:50:25 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B2oO57077157; Mon, 11 Sep 2017 02:50:24 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B2oOX2077152; Mon, 11 Sep 2017 02:50:24 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110250.v8B2oOX2077152@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 02:50:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323419 - in stable/11/sys: arm/freescale/imx conf dev/iicbus X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: arm/freescale/imx conf dev/iicbus X-SVN-Commit-Revision: 323419 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 02:50:25 -0000 Author: ian Date: Mon Sep 11 02:50:24 2017 New Revision: 323419 URL: https://svnweb.freebsd.org/changeset/base/323419 Log: MFC r320460, r320461, r320462, r320463: If an i2c transfer ends due to error, issue a stop on the bus even if the nostop option is set, if a start was issued. Add iic_recover_bus(), a helper function that can be used by any i2c driver which is able to manipulate the clock and data lines directly. When an i2c bus is hung by a slave device stuck in the middle of a transaction that didn't complete properly, this function manipulates the clock and data lines in a sequence known to reliably reset slave devices. The most common cause of a hung i2c bus is a system reboot in the middle of an i2c transfer (so it doesnt' happen often, but now there is a way other than power cycling to recover from it). Add bus recovery handling to the imx5/imx6 i2c driver. Added: stable/11/sys/dev/iicbus/iic_recover_bus.c - copied unchanged from r320461, head/sys/dev/iicbus/iic_recover_bus.c stable/11/sys/dev/iicbus/iic_recover_bus.h - copied unchanged from r320461, head/sys/dev/iicbus/iic_recover_bus.h Modified: stable/11/sys/arm/freescale/imx/imx_i2c.c stable/11/sys/conf/files stable/11/sys/dev/iicbus/iiconf.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/imx_i2c.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_i2c.c Mon Sep 11 02:38:57 2017 (r323418) +++ stable/11/sys/arm/freescale/imx/imx_i2c.c Mon Sep 11 02:50:24 2017 (r323419) @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -61,6 +62,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "iicbus_if.h" #include @@ -68,6 +70,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include + #define I2C_ADDR_REG 0x00 /* I2C slave address register */ #define I2C_FDR_REG 0x04 /* I2C frequency divider register */ #define I2C_CONTROL_REG 0x08 /* I2C control register */ @@ -131,6 +136,9 @@ struct i2c_softc { struct resource *res; int rid; sbintime_t byte_time_sbt; + int rb_pinctl_idx; + gpio_pin_t rb_sclpin; + gpio_pin_t rb_sdapin; }; static phandle_t i2c_get_node(device_t, device_t); @@ -275,6 +283,68 @@ i2c_error_handler(struct i2c_softc *sc, int error) } static int +i2c_recover_getsda(void *ctx) +{ + bool active; + + gpio_pin_is_active(((struct i2c_softc *)ctx)->rb_sdapin, &active); + return (active); +} + +static void +i2c_recover_setsda(void *ctx, int value) +{ + + gpio_pin_set_active(((struct i2c_softc *)ctx)->rb_sdapin, value); +} + +static int +i2c_recover_getscl(void *ctx) +{ + bool active; + + gpio_pin_is_active(((struct i2c_softc *)ctx)->rb_sclpin, &active); + return (active); + +} + +static void +i2c_recover_setscl(void *ctx, int value) +{ + + gpio_pin_set_active(((struct i2c_softc *)ctx)->rb_sclpin, value); +} + +static int +i2c_recover_bus(struct i2c_softc *sc) +{ + struct iicrb_pin_access pins; + int err; + + /* + * If we have gpio pinmux config, reconfigure the pins to gpio mode, + * invoke iic_recover_bus which checks for a hung bus and bitbangs a + * recovery sequence if necessary, then configure the pins back to i2c + * mode (idx 0). + */ + if (sc->rb_pinctl_idx == 0) + return (0); + + fdt_pinctrl_configure(sc->dev, sc->rb_pinctl_idx); + + pins.ctx = sc; + pins.getsda = i2c_recover_getsda; + pins.setsda = i2c_recover_setsda; + pins.getscl = i2c_recover_getscl; + pins.setscl = i2c_recover_setscl; + err = iic_recover_bus(&pins); + + fdt_pinctrl_configure(sc->dev, 0); + + return (err); +} + +static int i2c_probe(device_t dev) { @@ -292,7 +362,10 @@ i2c_probe(device_t dev) static int i2c_attach(device_t dev) { + char wrkstr[16]; struct i2c_softc *sc; + phandle_t node; + int err, cfgidx; sc = device_get_softc(dev); sc->dev = dev; @@ -311,6 +384,49 @@ i2c_attach(device_t dev) return (ENXIO); } + /* + * Set up for bus recovery using gpio pins, if the pinctrl and gpio + * properties are present. This is optional. If all the config data is + * not in place, we just don't do gpio bitbang bus recovery. + */ + node = ofw_bus_get_node(sc->dev); + + err = gpio_pin_get_by_ofw_property(dev, node, "scl-gpios", + &sc->rb_sclpin); + if (err != 0) + goto no_recovery; + err = gpio_pin_get_by_ofw_property(dev, node, "sda-gpios", + &sc->rb_sdapin); + if (err != 0) + goto no_recovery; + + /* + * Preset the gpio pins to output high (idle bus state). The signal + * won't actually appear on the pins until the bus recovery code changes + * the pinmux config from i2c to gpio. + */ + gpio_pin_setflags(sc->rb_sclpin, GPIO_PIN_OUTPUT); + gpio_pin_setflags(sc->rb_sdapin, GPIO_PIN_OUTPUT); + gpio_pin_set_active(sc->rb_sclpin, true); + gpio_pin_set_active(sc->rb_sdapin, true); + + /* + * Obtain the index of pinctrl node for bus recovery using gpio pins, + * then confirm that pinctrl properties exist for that index and for the + * default pinctrl-0. If sc->rb_pinctl_idx is non-zero, the reset code + * will also do a bus recovery, so setting this value must be last. + */ + err = ofw_bus_find_string_index(node, "pinctrl-names", "gpio", &cfgidx); + if (err == 0) { + snprintf(wrkstr, sizeof(wrkstr), "pinctrl-%d", cfgidx); + if (OF_hasprop(node, "pinctrl-0") && OF_hasprop(node, wrkstr)) + sc->rb_pinctl_idx = cfgidx; + } + +no_recovery: + + /* We don't do a hardware reset here because iicbus_attach() does it. */ + bus_generic_attach(dev); return (0); } @@ -340,7 +456,7 @@ i2c_repeated_start(device_t dev, u_char slave, int tim } static int -i2c_start(device_t dev, u_char slave, int timeout) +i2c_start_ll(device_t dev, u_char slave, int timeout) { struct i2c_softc *sc; int error; @@ -362,6 +478,31 @@ i2c_start(device_t dev, u_char slave, int timeout) } static int +i2c_start(device_t dev, u_char slave, int timeout) +{ + struct i2c_softc *sc; + int error; + + sc = device_get_softc(dev); + + /* + * Invoke the low-level code to put the bus into master mode and address + * the given slave. If that fails, idle the controller and attempt a + * bus recovery, and then try again one time. Signaling a start and + * addressing the slave is the only operation that a low-level driver + * can safely retry without any help from the upper layers that know + * more about the slave device. + */ + if ((error = i2c_start_ll(dev, slave, timeout)) != 0) { + i2c_write_reg(sc, I2C_CONTROL_REG, 0x0); + if ((error = i2c_recover_bus(sc)) != 0) + return (error); + error = i2c_start_ll(dev, slave, timeout); + } + return (error); +} + +static int i2c_stop(device_t dev) { struct i2c_softc *sc; @@ -410,7 +551,12 @@ i2c_reset(device_t dev, u_char speed, u_char addr, u_c i2c_write_reg(sc, I2C_STATUS_REG, 0x0); i2c_write_reg(sc, I2C_CONTROL_REG, 0x0); i2c_write_reg(sc, I2C_FDR_REG, (uint8_t)clkdiv_table[i].regcode); - return (IIC_NOERR); + + /* + * Now that the controller is idle, perform bus recovery. If the bus + * isn't hung, this a fairly fast no-op. + */ + return (i2c_recover_bus(sc)); } static int Modified: stable/11/sys/conf/files ============================================================================== --- stable/11/sys/conf/files Mon Sep 11 02:38:57 2017 (r323418) +++ stable/11/sys/conf/files Mon Sep 11 02:50:24 2017 (r323419) @@ -1693,6 +1693,7 @@ dev/iicbus/ds3231.c optional ds3231 dev/iicbus/icee.c optional icee dev/iicbus/if_ic.c optional ic dev/iicbus/iic.c optional iic +dev/iicbus/iic_recover_bus.c optional iicbus dev/iicbus/iicbb.c optional iicbb dev/iicbus/iicbb_if.m optional iicbb dev/iicbus/iicbus.c optional iicbus Copied: stable/11/sys/dev/iicbus/iic_recover_bus.c (from r320461, head/sys/dev/iicbus/iic_recover_bus.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/dev/iicbus/iic_recover_bus.c Mon Sep 11 02:50:24 2017 (r323419, copy of r320461, head/sys/dev/iicbus/iic_recover_bus.c) @@ -0,0 +1,124 @@ +/*- + * Copyright (c) 2017 Ian Lepore + * All rights reserved. + * + * Development sponsored by Microsemi, Inc. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * Helper code to recover a hung i2c bus by bit-banging a recovery sequence. + * + * An i2c bus can be hung by a slave driving the clock (rare) or data lines low. + * The most common cause is a partially-completed transaction such as rebooting + * while a slave is sending a byte of data. Because i2c allows the clock to + * freeze for any amount of time, the slave device will continue driving the + * data line until power is removed, or the clock cycles enough times to + * complete the current byte. After completing any partial byte, a START/STOP + * sequence resets the slave and the bus is recovered. + * + * Any i2c driver which is able to manually set the level of the clock and data + * lines can use this common code for bus recovery. On many SOCs that have + * embedded i2c controllers, the i2c pins can be temporarily reassigned as gpio + * pins to do the bus recovery, then can be assigned back to the i2c hardware. + */ + +#include "opt_platform.h" + +#include +#include +#include + +#include +#include + +int +iic_recover_bus(struct iicrb_pin_access *pins) +{ + const u_int timeout_us = 40000; + const u_int delay_us = 500; + int i; + + /* + * Start with clock and data high. + */ + pins->setsda(pins->ctx, 1); + pins->setscl(pins->ctx, 1); + + /* + * At this point, SCL should be high. If it's not, some slave on the + * bus is doing clock-stretching and we should wait a while. If that + * slave is completely locked up there may be no way to recover at all. + * We wait up to 40 milliseconds, a seriously pessimistic time (even a + * cheap eeprom has a max post-write delay of only 10ms), and also long + * enough to allow SMB slaves to timeout normally after 35ms. + */ + for (i = 0; i < timeout_us; i += delay_us) { + if (pins->getscl(pins->ctx)) + break; + DELAY(delay_us); + } + if (i >= timeout_us) + return (IIC_EBUSERR); + + /* + * At this point we should be able to control the clock line. Some + * slave may be part way through a byte transfer, and could be holding + * the data line low waiting for more clock pulses to finish the byte. + * Cycle the clock until we see the data line go high, but only up to 9 + * times because if it's not free after 9 clocks we're never going to + * win this battle. We do 9 max because that's a byte plus an ack/nack + * bit, after which the slave must not be driving the data line anymore. + */ + for (i = 0; ; ++i) { + if (pins->getsda(pins->ctx)) + break; + if (i == 9) + return (IIC_EBUSERR); + pins->setscl(pins->ctx, 0); + DELAY(5); + pins->setscl(pins->ctx, 1); + DELAY(5); + } + + /* + * At this point we should be in control of both the clock and data + * lines, and both lines should be high. To complete the reset of a + * slave that was part way through a transaction, we need to do a + * START/STOP sequence, which leaves both lines high at the end. + * - START: SDA transitions high->low while SCL remains high. + * - STOP: SDA transitions low->high while SCL remains high. + * Note that even though the clock line remains high, we transition the + * data line no faster than it would change state with a 100khz clock. + */ + pins->setsda(pins->ctx, 0); + DELAY(5); + pins->setsda(pins->ctx, 1); + DELAY(5); + + return (0); +} + Copied: stable/11/sys/dev/iicbus/iic_recover_bus.h (from r320461, head/sys/dev/iicbus/iic_recover_bus.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/dev/iicbus/iic_recover_bus.h Mon Sep 11 02:50:24 2017 (r323419, copy of r320461, head/sys/dev/iicbus/iic_recover_bus.h) @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2017 Ian Lepore + * All rights reserved. + * + * Development sponsored by Microsemi, Inc. + * + * 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$ + */ + +/* + * Helper code to recover a hung i2c bus by bit-banging a recovery sequence. + */ + +#ifndef _IICBUS_IIC_RECOVER_BUS_H_ +#define _IICBUS_IIC_RECOVER_BUS_H_ + +struct iicrb_pin_access { + void *ctx; + int (*getsda)(void *ctx); + void (*setsda)(void *ctx, int value); + int (*getscl)(void *ctx); + void (*setscl)(void *ctx, int value); +}; + +/* + * Drive the bus-recovery logic by manipulating the line states using the + * caller-provided functions. This does not block or sleep or acquire any locks + * (unless the provided pin access functions do so). It uses DELAY() to pace + * bits on the bus. + * + * Returns 0 if the bus is functioning properly or IIC_EBUSERR if the recovery + * attempt failed and some slave device is still driving the bus. + */ +int iic_recover_bus(struct iicrb_pin_access *pins); + +#endif Modified: stable/11/sys/dev/iicbus/iiconf.c ============================================================================== --- stable/11/sys/dev/iicbus/iiconf.c Mon Sep 11 02:38:57 2017 (r323418) +++ stable/11/sys/dev/iicbus/iiconf.c Mon Sep 11 02:50:24 2017 (r323419) @@ -419,7 +419,7 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs { int i, error, lenread, lenwrote, nkid, rpstart, addr; device_t *children, bus; - bool nostop; + bool nostop, started; if ((error = device_get_children(dev, &children, &nkid)) != 0) return (IIC_ERESOURCE); @@ -431,6 +431,7 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs rpstart = 0; free(children, M_TEMP); nostop = iicbus_get_nostop(dev); + started = false; for (i = 0, error = 0; i < nmsgs && error == 0; i++) { addr = msgs[i].slave; if (msgs[i].flags & IIC_M_RD) @@ -443,9 +444,10 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs error = iicbus_repeated_start(bus, addr, 0); else error = iicbus_start(bus, addr, 0); + if (error != 0) + break; + started = true; } - if (error != 0) - break; if (msgs[i].flags & IIC_M_RD) error = iicbus_read(bus, msgs[i].buf, msgs[i].len, @@ -464,7 +466,7 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs iicbus_stop(bus); } } - if (error != 0 && !nostop) + if (error != 0 && started) iicbus_stop(bus); return (error); } From owner-svn-src-stable-11@freebsd.org Mon Sep 11 02:52:42 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C4608E146E5; Mon, 11 Sep 2017 02:52:42 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id A078A6C18B; Mon, 11 Sep 2017 02:52:42 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B2qfFG080795; Mon, 11 Sep 2017 02:52:41 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B2qfvQ080792; Mon, 11 Sep 2017 02:52:41 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110252.v8B2qfvQ080792@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 02:52:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323420 - stable/11/sys/arm/freescale/imx X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/freescale/imx X-SVN-Commit-Revision: 323420 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 02:52:42 -0000 Author: ian Date: Mon Sep 11 02:52:41 2017 New Revision: 323420 URL: https://svnweb.freebsd.org/changeset/base/323420 Log: MFC r320655, r321933: Add a driver for the imx6 on-chip realtime clock (snvs). The imx6_snvs driver is not strictly required for the system to run, so change it from standard to optional and add a device statement for it so that it's included unless someone uses nodevice to eliminate it. Added: stable/11/sys/arm/freescale/imx/imx6_snvs.c - copied unchanged from r320655, head/sys/arm/freescale/imx/imx6_snvs.c Modified: stable/11/sys/arm/freescale/imx/files.imx6 stable/11/sys/arm/freescale/imx/std.imx6 Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/files.imx6 ============================================================================== --- stable/11/sys/arm/freescale/imx/files.imx6 Mon Sep 11 02:50:24 2017 (r323419) +++ stable/11/sys/arm/freescale/imx/files.imx6 Mon Sep 11 02:52:41 2017 (r323420) @@ -14,6 +14,7 @@ arm/freescale/imx/imx6_ccm.c standard arm/freescale/imx/imx6_machdep.c standard arm/freescale/imx/imx6_mp.c optional smp arm/freescale/imx/imx6_pl310.c standard +arm/freescale/imx/imx6_snvs.c optional imx6_snvs arm/freescale/imx/imx6_src.c standard arm/freescale/imx/imx_epit.c standard arm/freescale/imx/imx_iomux.c standard Copied: stable/11/sys/arm/freescale/imx/imx6_snvs.c (from r320655, head/sys/arm/freescale/imx/imx6_snvs.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/arm/freescale/imx/imx6_snvs.c Mon Sep 11 02:52:41 2017 (r323420, copy of r320655, head/sys/arm/freescale/imx/imx6_snvs.c) @@ -0,0 +1,228 @@ +/*- + * Copyright (c) 2017 Ian Lepore + * All rights reserved. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * Driver for imx6 Secure Non-Volatile Storage system, which really means "all + * the stuff that's powered by a battery when main power is off". This includes + * realtime clock, tamper monitor, and power-management functions. Currently + * this driver provides only realtime clock support. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "clock_if.h" + +#define SNVS_LPCR 0x38 /* Control register */ +#define LPCR_LPCALB_VAL_SHIFT 10 /* Calibration shift */ +#define LPCR_LPCALB_VAL_MASK 0x1f /* Calibration mask */ +#define LPCR_LPCALB_EN (1u << 8) /* Calibration enable */ +#define LPCR_SRTC_ENV (1u << 0) /* RTC enabled/valid */ + +#define SNVS_LPSRTCMR 0x50 /* Counter MSB */ +#define SNVS_LPSRTCLR 0x54 /* Counter LSB */ + +#define RTC_RESOLUTION_US (1000000 / 32768) /* 32khz clock */ + +/* + * The RTC is a 47-bit counter clocked at 32KHz and organized as a 32.15 + * fixed-point binary value. Shifting by SBT_LSB bits translates between + * counter and sbintime values. + */ +#define RTC_BITS 47 +#define SBT_BITS 64 +#define SBT_LSB (SBT_BITS - RTC_BITS) + +struct snvs_softc { + device_t dev; + struct resource * memres; + uint32_t lpcr; +}; + +static struct ofw_compat_data compat_data[] = { + {"fsl,sec-v4.0-mon", true}, + {NULL, false} +}; + +static inline uint32_t +RD4(struct snvs_softc *sc, bus_size_t offset) +{ + + return (bus_read_4(sc->memres, offset)); +} + +static inline void +WR4(struct snvs_softc *sc, bus_size_t offset, uint32_t value) +{ + + bus_write_4(sc->memres, offset, value); +} + +static void +snvs_rtc_enable(struct snvs_softc *sc, bool enable) +{ + uint32_t enbit; + + if (enable) + sc->lpcr |= LPCR_SRTC_ENV; + else + sc->lpcr &= ~LPCR_SRTC_ENV; + WR4(sc, SNVS_LPCR, sc->lpcr); + + /* Wait for the hardware to achieve the requested state. */ + enbit = sc->lpcr & LPCR_SRTC_ENV; + while ((RD4(sc, SNVS_LPCR) & LPCR_SRTC_ENV) != enbit) + continue; +} + +static int +snvs_gettime(device_t dev, struct timespec *ts) +{ + struct snvs_softc *sc; + sbintime_t counter1, counter2; + + sc = device_get_softc(dev); + + /* If the clock is not enabled and valid, we can't help. */ + if (!(RD4(sc, SNVS_LPCR) & LPCR_SRTC_ENV)) { + return (EINVAL); + } + + /* + * The counter is clocked asynchronously to cpu accesses; read and + * assemble the pieces of the counter until we get the same value twice. + * The counter is 47 bits, organized as a 32.15 binary fixed-point + * value. If we shift it up to the high order part of a 64-bit word it + * turns into an sbintime. + */ + do { + counter1 = (uint64_t)RD4(sc, SNVS_LPSRTCMR) << (SBT_LSB + 32); + counter1 |= (uint64_t)RD4(sc, SNVS_LPSRTCLR) << (SBT_LSB); + counter2 = (uint64_t)RD4(sc, SNVS_LPSRTCMR) << (SBT_LSB + 32); + counter2 |= (uint64_t)RD4(sc, SNVS_LPSRTCLR) << (SBT_LSB); + } while (counter1 != counter2); + + *ts = sbttots(counter1); + + return (0); +} + +static int +snvs_settime(device_t dev, struct timespec *unused) +{ + struct snvs_softc *sc; + struct bintime bt; + sbintime_t sbt; + + sc = device_get_softc(dev); + + /* + * Ignore the inaccurate time passed in from the common clock code and + * obtain a time worthy of our 30us accuracy. + */ + bintime(&bt); + bt.sec -= utc_offset(); + sbt = bttosbt(bt); + + /* + * It takes two clock cycles for the counter to start after setting the + * enable bit, so add two SBT_LSBs to what we're about to set. + */ + sbt += 2 << SBT_LSB; + snvs_rtc_enable(sc, false); + WR4(sc, SNVS_LPSRTCMR, (uint32_t)(sbt >> (SBT_LSB + 32))); + WR4(sc, SNVS_LPSRTCLR, (uint32_t)(sbt >> (SBT_LSB))); + snvs_rtc_enable(sc, true); + + return (0); +} + +static int +snvs_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) + return (ENXIO); + + device_set_desc(dev, "i.MX6 SNVS RTC"); + return (BUS_PROBE_DEFAULT); +} + +static int +snvs_attach(device_t dev) +{ + struct snvs_softc *sc; + int rid; + + sc = device_get_softc(dev); + sc->dev = dev; + + rid = 0; + sc->memres = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY, &rid, + RF_ACTIVE); + if (sc->memres == NULL) { + device_printf(sc->dev, "could not allocate registers\n"); + return (ENXIO); + } + + clock_register(sc->dev, RTC_RESOLUTION_US); + + return (0); +} + +static device_method_t snvs_methods[] = { + DEVMETHOD(device_probe, snvs_probe), + DEVMETHOD(device_attach, snvs_attach), + + /* clock_if methods */ + DEVMETHOD(clock_gettime, snvs_gettime), + DEVMETHOD(clock_settime, snvs_settime), + + DEVMETHOD_END +}; + +static driver_t snvs_driver = { + "snvs", + snvs_methods, + sizeof(struct snvs_softc), +}; + +static devclass_t snvs_devclass; + +DRIVER_MODULE(snvs, simplebus, snvs_driver, snvs_devclass, 0, 0); Modified: stable/11/sys/arm/freescale/imx/std.imx6 ============================================================================== --- stable/11/sys/arm/freescale/imx/std.imx6 Mon Sep 11 02:50:24 2017 (r323419) +++ stable/11/sys/arm/freescale/imx/std.imx6 Mon Sep 11 02:52:41 2017 (r323420) @@ -9,7 +9,8 @@ makeoptions KERNVIRTADDR = 0xc2000000 options IPI_IRQ_START=0 options IPI_IRQ_END=15 -device fdt_pinctrl +device fdt_pinctrl +device imx6_snvs files "../freescale/imx/files.imx6" From owner-svn-src-stable-11@freebsd.org Mon Sep 11 02:56:47 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 695B7E149F1; Mon, 11 Sep 2017 02:56:47 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 365396C32D; Mon, 11 Sep 2017 02:56:47 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B2ukvJ080986; Mon, 11 Sep 2017 02:56:46 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B2ukFS080983; Mon, 11 Sep 2017 02:56:46 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110256.v8B2ukFS080983@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 02:56:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323421 - in stable/11/sys/dev: bwi iicbus iwi X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys/dev: bwi iicbus iwi X-SVN-Commit-Revision: 323421 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 02:56:47 -0000 Author: ian Date: Mon Sep 11 02:56:45 2017 New Revision: 323421 URL: https://svnweb.freebsd.org/changeset/base/323421 Log: MFC r320743: Fix drivers that assume ticks starts at zero. These drivers all have logic similar to "if (ticks > localvar+interval) {localvar=ticks; ...}" where localvar is initialized to zero. Ticks is initialized to a negative value since r278230, and that leads to these if statements never being true. Modified: stable/11/sys/dev/bwi/if_bwi.c stable/11/sys/dev/iicbus/ad7418.c stable/11/sys/dev/iwi/if_iwi.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/bwi/if_bwi.c ============================================================================== --- stable/11/sys/dev/bwi/if_bwi.c Mon Sep 11 02:52:41 2017 (r323420) +++ stable/11/sys/dev/bwi/if_bwi.c Mon Sep 11 02:56:45 2017 (r323421) @@ -381,6 +381,7 @@ bwi_attach(struct bwi_softc *sc) */ sc->sc_fw_version = BWI_FW_VERSION3; sc->sc_led_idle = (2350 * hz) / 1000; + sc->sc_led_ticks = ticks - sc->sc_led_idle; sc->sc_led_blink = 1; sc->sc_txpwr_calib = 1; #ifdef BWI_DEBUG Modified: stable/11/sys/dev/iicbus/ad7418.c ============================================================================== --- stable/11/sys/dev/iicbus/ad7418.c Mon Sep 11 02:52:41 2017 (r323420) +++ stable/11/sys/dev/iicbus/ad7418.c Mon Sep 11 02:56:45 2017 (r323421) @@ -120,6 +120,8 @@ ad7418_attach(device_t dev) int conf; sc->sc_dev = dev; + sc->sc_lastupdate = ticks - hz; + sx_init(&sc->sc_lock, "ad7418"); SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, Modified: stable/11/sys/dev/iwi/if_iwi.c ============================================================================== --- stable/11/sys/dev/iwi/if_iwi.c Mon Sep 11 02:52:41 2017 (r323420) +++ stable/11/sys/dev/iwi/if_iwi.c Mon Sep 11 02:56:45 2017 (r323421) @@ -286,6 +286,7 @@ iwi_attach(device_t dev) int i, error; sc->sc_dev = dev; + sc->sc_ledevent = ticks; IWI_LOCK_INIT(sc); mbufq_init(&sc->sc_snd, ifqmaxlen); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 02:57:56 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7F660E14B27; Mon, 11 Sep 2017 02:57:56 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 598996C47A; Mon, 11 Sep 2017 02:57:56 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B2vtvd081074; Mon, 11 Sep 2017 02:57:55 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B2vtl0081072; Mon, 11 Sep 2017 02:57:55 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110257.v8B2vtl0081072@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 02:57:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323422 - in stable/11/sys: arm/freescale/imx dev/usb/controller X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: arm/freescale/imx dev/usb/controller X-SVN-Commit-Revision: 323422 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 02:57:56 -0000 Author: ian Date: Mon Sep 11 02:57:55 2017 New Revision: 323422 URL: https://svnweb.freebsd.org/changeset/base/323422 Log: MFC r320928, r320929: Support the "disable-over-current" property for imx ehci controllers. It turns out that this is more than a power optization. The OTG port won't work on boards that have this property unless this setting is honored. Also ensure that the usb phy device attaches before ehci. Put an #ifdef notyet wrapper around a function that's not being used yet, to avoid compile warnings. Modified: stable/11/sys/arm/freescale/imx/imx6_usbphy.c stable/11/sys/dev/usb/controller/ehci_imx.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/imx6_usbphy.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx6_usbphy.c Mon Sep 11 02:56:45 2017 (r323421) +++ stable/11/sys/arm/freescale/imx/imx6_usbphy.c Mon Sep 11 02:57:55 2017 (r323422) @@ -198,5 +198,11 @@ static driver_t usbphy_driver = { static devclass_t usbphy_devclass; -DRIVER_MODULE(usbphy, simplebus, usbphy_driver, usbphy_devclass, 0, 0); +/* + * This driver needs to start before the ehci driver, but later than the usual + * "special" drivers like clocks and cpu. Ehci starts at DEFAULT so + * DEFAULT-1000 seems good. + */ +EARLY_DRIVER_MODULE(usbphy, simplebus, usbphy_driver, usbphy_devclass, 0, 0, + BUS_PASS_DEFAULT - 1000); Modified: stable/11/sys/dev/usb/controller/ehci_imx.c ============================================================================== --- stable/11/sys/dev/usb/controller/ehci_imx.c Mon Sep 11 02:56:45 2017 (r323421) +++ stable/11/sys/dev/usb/controller/ehci_imx.c Mon Sep 11 02:57:55 2017 (r323422) @@ -83,12 +83,11 @@ __FBSDID("$FreeBSD$"); * data, this means that the resources (memory-mapped register range) for the * non-core registers belongs to a device other than the echi devices. * - * At the moment we have no need to access the non-core registers, so all of - * this amounts to documenting what's known. The following compat strings have - * been seen in existing FDT data: - * - "fsl,imx25-usbmisc" - * - "fsl,imx51-usbmisc"; - * - "fsl,imx6q-usbmisc"; + * Because the main ehci device cannot access registers in a range that's + * defined in the fdt data as belonging to another device, we implement a teeny + * little "usbmisc" driver which exists only to provide access to the usbmisc + * control register for each of the 4 usb controller instances. That little + * driver is implemented here in this file, before the main driver. * * In addition to the single usbmisc device, the existing FDT data defines a * separate device for each of the OTG or EHCI cores within the USBOH3. Each of @@ -133,18 +132,129 @@ __FBSDID("$FreeBSD$"); * */ -static struct ofw_compat_data compat_data[] = { - {"fsl,imx6q-usb", 1}, - {"fsl,imx53-usb", 1}, - {"fsl,imx51-usb", 1}, - {"fsl,imx28-usb", 1}, - {"fsl,imx27-usb", 1}, - {"fsl,imx25-usb", 1}, - {"fsl,imx23-usb", 1}, - {NULL, 0}, +/*----------------------------------------------------------------------------- + * imx_usbmisc driver + *---------------------------------------------------------------------------*/ + +#define USBNC_OVER_CUR_POL (1u << 8) +#define USBNC_OVER_CUR_DIS (1u << 7) + +struct imx_usbmisc_softc { + device_t dev; + struct resource *mmio; }; +static struct ofw_compat_data usbmisc_compat_data[] = { + {"fsl,imx6q-usbmisc", true}, + {"fsl,imx51-usbmisc", true}, + {"fsl,imx25-usbmisc", true}, + {NULL, false}, +}; + +static void +imx_usbmisc_set_ctrl(device_t dev, u_int index, uint32_t bits) +{ + struct imx_usbmisc_softc *sc; + uint32_t reg; + + sc = device_get_softc(dev); + reg = bus_read_4(sc->mmio, index * sizeof(uint32_t)); + bus_write_4(sc->mmio, index * sizeof(uint32_t), reg | bits); +} + +#ifdef notyet +static void +imx_usbmisc_clr_ctrl(device_t dev, u_int index, uint32_t bits) +{ + struct imx_usbmisc_softc *sc; + uint32_t reg; + + sc = device_get_softc(dev); + reg = bus_read_4(sc->mmio, index * sizeof(uint32_t)); + bus_write_4(sc->mmio, index * sizeof(uint32_t), reg & ~bits); +} +#endif + +static int +imx_usbmisc_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (ofw_bus_search_compatible(dev, usbmisc_compat_data)->ocd_data) { + device_set_desc(dev, "i.MX USB Misc Control"); + return (BUS_PROBE_DEFAULT); + } + return (ENXIO); +} + +static int +imx_usbmisc_detach(device_t dev) +{ + struct imx_usbmisc_softc *sc; + + sc = device_get_softc(dev); + + if (sc->mmio != NULL) + bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mmio); + + return (0); +} + +static int +imx_usbmisc_attach(device_t dev) +{ + struct imx_usbmisc_softc *sc; + int err, rid; + + sc = device_get_softc(dev); + err = 0; + + /* Allocate bus_space resources. */ + rid = 0; + sc->mmio = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, + RF_ACTIVE); + if (sc->mmio == NULL) { + device_printf(dev, "Cannot allocate memory resources\n"); + return (ENXIO); + } + + OF_device_register_xref(OF_xref_from_node(ofw_bus_get_node(dev)), dev); + + return (0); +} + +static device_method_t imx_usbmisc_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, imx_usbmisc_probe), + DEVMETHOD(device_attach, imx_usbmisc_attach), + DEVMETHOD(device_detach, imx_usbmisc_detach), + + DEVMETHOD_END +}; + +static driver_t imx_usbmisc_driver = { + "imx_usbmisc", + imx_usbmisc_methods, + sizeof(struct imx_usbmisc_softc) +}; + +static devclass_t imx_usbmisc_devclass; + /* + * This driver needs to start before the ehci driver, but later than the usual + * "special" drivers like clocks and cpu. Ehci starts at DEFAULT so + * DEFAULT-1000 seems good. + */ +EARLY_DRIVER_MODULE(imx_usbmisc, simplebus, imx_usbmisc_driver, + imx_usbmisc_devclass, 0, 0, BUS_PASS_DEFAULT - 1000); + +/*----------------------------------------------------------------------------- + * imx_ehci driver... + *---------------------------------------------------------------------------*/ + +/* * Each EHCI device in the SoC has some SoC-specific per-device registers at an * offset of 0, then the standard EHCI registers begin at an offset of 0x100. */ @@ -153,10 +263,22 @@ static struct ofw_compat_data compat_data[] = { struct imx_ehci_softc { ehci_softc_t ehci_softc; + device_t dev; struct resource *ehci_mem_res; /* EHCI core regs. */ struct resource *ehci_irq_res; /* EHCI core IRQ. */ }; +static struct ofw_compat_data compat_data[] = { + {"fsl,imx6q-usb", 1}, + {"fsl,imx53-usb", 1}, + {"fsl,imx51-usb", 1}, + {"fsl,imx28-usb", 1}, + {"fsl,imx27-usb", 1}, + {"fsl,imx25-usb", 1}, + {"fsl,imx23-usb", 1}, + {NULL, 0}, +}; + static void imx_ehci_post_reset(struct ehci_softc *ehci_softc) { @@ -215,6 +337,36 @@ imx_ehci_detach(device_t dev) return (0); } +static void +imx_ehci_disable_oc(struct imx_ehci_softc *sc) +{ + device_t usbmdev; + pcell_t usbmprops[2]; + phandle_t node; + ssize_t size; + int index; + + /* Get the reference to the usbmisc driver from the fdt data */ + node = ofw_bus_get_node(sc->dev); + size = OF_getencprop(node, "fsl,usbmisc", usbmprops, + sizeof(usbmprops)); + if (size < sizeof(usbmprops)) { + device_printf(sc->dev, "failed to retrieve fsl,usbmisc " + "property, cannot disable overcurrent protection"); + return; + } + /* Retrieve the device_t via the xref handle. */ + usbmdev = OF_device_from_xref(usbmprops[0]); + if (usbmdev == NULL) { + device_printf(sc->dev, "usbmisc device not found, " + "cannot disable overcurrent protection"); + return; + } + /* Call the device routine to set the overcurrent disable bit. */ + index = usbmprops[1]; + imx_usbmisc_set_ctrl(usbmdev, index, USBNC_OVER_CUR_DIS); +} + static int imx_ehci_attach(device_t dev) { @@ -223,6 +375,7 @@ imx_ehci_attach(device_t dev) int err, rid; sc = device_get_softc(dev); + sc->dev = dev; esc = &sc->ehci_softc; err = 0; @@ -282,6 +435,10 @@ imx_ehci_attach(device_t dev) /* Turn on clocks. */ imx_ccm_usb_enable(dev); + + /* Disable overcurrent detection, if configured to do so. */ + if (OF_hasprop(ofw_bus_get_node(sc->dev), "disable-over-current")) + imx_ehci_disable_oc(sc); /* Add USB bus device. */ esc->sc_bus.bdev = device_add_child(dev, "usbus", -1); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 03:24:52 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1870EE16176; Mon, 11 Sep 2017 03:24:52 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id DB3186D5B9; Mon, 11 Sep 2017 03:24:51 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B3OoTJ093972; Mon, 11 Sep 2017 03:24:50 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B3Oo1G093971; Mon, 11 Sep 2017 03:24:50 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110324.v8B3Oo1G093971@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 03:24:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323423 - stable/11/sys/arm/include X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/include X-SVN-Commit-Revision: 323423 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 03:24:52 -0000 Author: ian Date: Mon Sep 11 03:24:50 2017 New Revision: 323423 URL: https://svnweb.freebsd.org/changeset/base/323423 Log: MFC r321489: Use the MD __size_t to avoid a dependency on/include of non-MD header files. This should fix the compilation of the lua 5.3.4 port, among others. Modified: stable/11/sys/arm/include/ucontext.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/include/ucontext.h ============================================================================== --- stable/11/sys/arm/include/ucontext.h Mon Sep 11 02:57:55 2017 (r323422) +++ stable/11/sys/arm/include/ucontext.h Mon Sep 11 03:24:50 2017 (r323423) @@ -78,7 +78,7 @@ typedef struct { * Originally, rest of this structure was named __fpu, 35 * 4 bytes * long, never accessed from kernel. */ - size_t mc_vfp_size; + __size_t mc_vfp_size; void *mc_vfp_ptr; unsigned int mc_spare[33]; } mcontext_t; From owner-svn-src-stable-11@freebsd.org Mon Sep 11 04:22:27 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 23FE4E18F0B; Mon, 11 Sep 2017 04:22:27 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id F41C26EFC7; Mon, 11 Sep 2017 04:22:26 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B4MQMK018463; Mon, 11 Sep 2017 04:22:26 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B4MP79018460; Mon, 11 Sep 2017 04:22:25 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709110422.v8B4MP79018460@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 04:22:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323424 - in stable/11/sys: arm/arm dev/ow sys X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: arm/arm dev/ow sys X-SVN-Commit-Revision: 323424 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 04:22:27 -0000 Author: ian Date: Mon Sep 11 04:22:25 2017 New Revision: 323424 URL: https://svnweb.freebsd.org/changeset/base/323424 Log: MFC r321686: Add inline functions to convert between sbintime_t and decimal time units. Use them in some existing code that is vulnerable to roundoff errors. Modified: stable/11/sys/arm/arm/mpcore_timer.c stable/11/sys/dev/ow/owc_gpiobus.c stable/11/sys/sys/time.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/arm/mpcore_timer.c ============================================================================== --- stable/11/sys/arm/arm/mpcore_timer.c Mon Sep 11 03:24:50 2017 (r323423) +++ stable/11/sys/arm/arm/mpcore_timer.c Mon Sep 11 04:22:25 2017 (r323424) @@ -348,7 +348,7 @@ attach_et(struct arm_tmr_softc *sc) sc->et.et_flags = ET_FLAGS_PERIODIC | ET_FLAGS_ONESHOT | ET_FLAGS_PERCPU; sc->et.et_quality = 1000; sc->et.et_frequency = sc->clkfreq; - sc->et.et_min_period = 20 * SBT_1NS; + sc->et.et_min_period = nstosbt(20); sc->et.et_max_period = 2 * SBT_1S; sc->et.et_start = arm_tmr_start; sc->et.et_stop = arm_tmr_stop; Modified: stable/11/sys/dev/ow/owc_gpiobus.c ============================================================================== --- stable/11/sys/dev/ow/owc_gpiobus.c Mon Sep 11 03:24:50 2017 (r323423) +++ stable/11/sys/dev/ow/owc_gpiobus.c Mon Sep 11 04:22:25 2017 (r323424) @@ -295,10 +295,10 @@ owc_gpiobus_read_data(device_t dev, struct ow_timing * do { now = sbinuptime(); GETPIN(sc, &sample); - } while ((now - then) / SBT_1US < t->t_rdv + 2 && sample == 0); + } while (sbttous(now - then) < t->t_rdv + 2 && sample == 0); critical_exit(); - if ((now - then) / SBT_1NS < t->t_rdv * 1000) + if (sbttons(now - then) < t->t_rdv * 1000) *bit = 1; else *bit = 0; Modified: stable/11/sys/sys/time.h ============================================================================== --- stable/11/sys/sys/time.h Mon Sep 11 03:24:50 2017 (r323423) +++ stable/11/sys/sys/time.h Mon Sep 11 04:22:25 2017 (r323424) @@ -128,7 +128,7 @@ bintime_shift(struct bintime *_bt, int _exp) #define SBT_1M (SBT_1S * 60) #define SBT_1MS (SBT_1S / 1000) #define SBT_1US (SBT_1S / 1000000) -#define SBT_1NS (SBT_1S / 1000000000) +#define SBT_1NS (SBT_1S / 1000000000) /* beware rounding, see nstosbt() */ #define SBT_MAX 0x7fffffffffffffffLL static __inline int @@ -155,6 +155,53 @@ sbttobt(sbintime_t _sbt) return (_bt); } +/* + * Decimal<->sbt conversions. Multiplying or dividing by SBT_1NS results in + * large roundoff errors which sbttons() and nstosbt() avoid. Millisecond and + * microsecond functions are also provided for completeness. + */ +static __inline int64_t +sbttons(sbintime_t _sbt) +{ + + return ((1000000000 * _sbt) >> 32); +} + +static __inline sbintime_t +nstosbt(int64_t _ns) +{ + + return ((_ns * (((uint64_t)1 << 63) / 500000000) >> 32)); +} + +static __inline int64_t +sbttous(sbintime_t _sbt) +{ + + return ((1000000 * _sbt) >> 32); +} + +static __inline sbintime_t +ustosbt(int64_t _us) +{ + + return ((_us * (((uint64_t)1 << 63) / 500000) >> 32)); +} + +static __inline int64_t +sbttoms(sbintime_t _sbt) +{ + + return ((1000 * _sbt) >> 32); +} + +static __inline sbintime_t +mstosbt(int64_t _ms) +{ + + return ((_ms * (((uint64_t)1 << 63) / 500) >> 32)); +} + /*- * Background information: * @@ -210,7 +257,7 @@ sbttots(sbintime_t _sbt) struct timespec _ts; _ts.tv_sec = _sbt >> 32; - _ts.tv_nsec = ((uint64_t)1000000000 * (uint32_t)_sbt) >> 32; + _ts.tv_nsec = sbttons((uint32_t)_sbt); return (_ts); } @@ -218,8 +265,7 @@ static __inline sbintime_t tstosbt(struct timespec _ts) { - return (((sbintime_t)_ts.tv_sec << 32) + - (_ts.tv_nsec * (((uint64_t)1 << 63) / 500000000) >> 32)); + return (((sbintime_t)_ts.tv_sec << 32) + nstosbt(_ts.tv_nsec)); } static __inline struct timeval @@ -228,7 +274,7 @@ sbttotv(sbintime_t _sbt) struct timeval _tv; _tv.tv_sec = _sbt >> 32; - _tv.tv_usec = ((uint64_t)1000000 * (uint32_t)_sbt) >> 32; + _tv.tv_usec = sbttous((uint32_t)_sbt); return (_tv); } @@ -236,8 +282,7 @@ static __inline sbintime_t tvtosbt(struct timeval _tv) { - return (((sbintime_t)_tv.tv_sec << 32) + - (_tv.tv_usec * (((uint64_t)1 << 63) / 500000) >> 32)); + return (((sbintime_t)_tv.tv_sec << 32) + ustosbt(_tv.tv_usec)); } #endif /* __BSD_VISIBLE */ From owner-svn-src-stable-11@freebsd.org Mon Sep 11 07:21:36 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 02A81E208A7; Mon, 11 Sep 2017 07:21:36 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id C418074290; Mon, 11 Sep 2017 07:21:35 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B7LYph089080; Mon, 11 Sep 2017 07:21:34 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B7LYCN089079; Mon, 11 Sep 2017 07:21:34 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709110721.v8B7LYCN089079@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Mon, 11 Sep 2017 07:21:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323425 - stable/11/usr.sbin/bhyve X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: stable/11/usr.sbin/bhyve X-SVN-Commit-Revision: 323425 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 07:21:36 -0000 Author: rlibby Date: Mon Sep 11 07:21:34 2017 New Revision: 323425 URL: https://svnweb.freebsd.org/changeset/base/323425 Log: MFC r321668: bhyve/pci_e82545.c: squelch gcc warning for noreturn procedure Modified: stable/11/usr.sbin/bhyve/pci_e82545.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/bhyve/pci_e82545.c ============================================================================== --- stable/11/usr.sbin/bhyve/pci_e82545.c Mon Sep 11 04:22:25 2017 (r323424) +++ stable/11/usr.sbin/bhyve/pci_e82545.c Mon Sep 11 07:21:34 2017 (r323425) @@ -1405,7 +1405,7 @@ e82545_tx_run(struct e82545_softc *sc) sc->esc_TDH, sc->esc_TDHr, sc->esc_TDT); } -static void * +static _Noreturn void * e82545_tx_thread(void *param) { struct e82545_softc *sc = param; From owner-svn-src-stable-11@freebsd.org Mon Sep 11 07:22:54 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5D0FCE20965; Mon, 11 Sep 2017 07:22:54 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id 2A33F74464; Mon, 11 Sep 2017 07:22:54 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B7Mrrg092165; Mon, 11 Sep 2017 07:22:53 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B7MrW0092164; Mon, 11 Sep 2017 07:22:53 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709110722.v8B7MrW0092164@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Mon, 11 Sep 2017 07:22:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323426 - stable/11/usr.sbin/bhyve X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: stable/11/usr.sbin/bhyve X-SVN-Commit-Revision: 323426 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 07:22:54 -0000 Author: rlibby Date: Mon Sep 11 07:22:53 2017 New Revision: 323426 URL: https://svnweb.freebsd.org/changeset/base/323426 Log: MFC r321669: bhyve/vga.c: fix atc_color_select_67 bit shift Modified: stable/11/usr.sbin/bhyve/vga.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/bhyve/vga.c ============================================================================== --- stable/11/usr.sbin/bhyve/vga.c Mon Sep 11 07:21:34 2017 (r323425) +++ stable/11/usr.sbin/bhyve/vga.c Mon Sep 11 07:22:53 2017 (r323426) @@ -1069,7 +1069,7 @@ vga_port_out_handler(struct vmctx *ctx, int in, int po sc->vga_atc.atc_color_select_45 = (val & ATC_CS_C45) << 4; sc->vga_atc.atc_color_select_67 = - (val & ATC_CS_C67) << 6; + ((val & ATC_CS_C67) >> 2) << 6; break; default: //printf("XXX VGA ATC: outb 0x%04x, 0x%02x at index %d\n", port, val, sc->vga_atc.atc_index); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 07:24:58 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1552AE20A61; Mon, 11 Sep 2017 07:24:58 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id D83CC745E3; Mon, 11 Sep 2017 07:24:57 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B7OvTi092279; Mon, 11 Sep 2017 07:24:57 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B7OvWQ092278; Mon, 11 Sep 2017 07:24:57 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709110724.v8B7OvWQ092278@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Mon, 11 Sep 2017 07:24:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323427 - stable/11/usr.sbin/bhyve X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: stable/11/usr.sbin/bhyve X-SVN-Commit-Revision: 323427 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 07:24:58 -0000 Author: rlibby Date: Mon Sep 11 07:24:56 2017 New Revision: 323427 URL: https://svnweb.freebsd.org/changeset/base/323427 Log: bhyve: actually call bhyve_caph_cache_catpages Gcc noticed that bhyve_caph_cache_catpages was defined but unused. It is a stable/11 copy of caph_cache_catpages in head. Direct commit to stable/11. This bug does not apply to head. Reviewed by: grehan Approved by: markj (mentor) Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D12212 Modified: stable/11/usr.sbin/bhyve/bhyverun.c Modified: stable/11/usr.sbin/bhyve/bhyverun.c ============================================================================== --- stable/11/usr.sbin/bhyve/bhyverun.c Mon Sep 11 07:22:53 2017 (r323426) +++ stable/11/usr.sbin/bhyve/bhyverun.c Mon Sep 11 07:24:56 2017 (r323427) @@ -1021,7 +1021,7 @@ main(int argc, char *argv[]) fwctl_init(); #ifndef WITHOUT_CAPSICUM - + bhyve_caph_cache_catpages(); if (bhyve_caph_limit_stdoe() == -1) errx(EX_OSERR, "Unable to apply rights for sandbox"); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 08:16:40 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 26F34E22372; Mon, 11 Sep 2017 08:16:40 +0000 (UTC) (envelope-from kib@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 mx1.freebsd.org (Postfix) with ESMTPS id E6C0875E5A; Mon, 11 Sep 2017 08:16:39 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B8GdVn012613; Mon, 11 Sep 2017 08:16:39 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B8GdaX012612; Mon, 11 Sep 2017 08:16:39 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709110816.v8B8GdaX012612@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 11 Sep 2017 08:16:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323429 - stable/11/sys/fs/msdosfs X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/fs/msdosfs X-SVN-Commit-Revision: 323429 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 08:16:40 -0000 Author: kib Date: Mon Sep 11 08:16:38 2017 New Revision: 323429 URL: https://svnweb.freebsd.org/changeset/base/323429 Log: MFC r322982: Verify that the BPB media descriptor and FAT ID match. Modified: stable/11/sys/fs/msdosfs/msdosfs_fat.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/fs/msdosfs/msdosfs_fat.c ============================================================================== --- stable/11/sys/fs/msdosfs/msdosfs_fat.c Mon Sep 11 07:38:53 2017 (r323428) +++ stable/11/sys/fs/msdosfs/msdosfs_fat.c Mon Sep 11 08:16:38 2017 (r323429) @@ -908,19 +908,17 @@ fillinusemap(struct msdosfsmount *pmp) * zero. These represent free clusters. */ pmp->pm_freeclustercount = 0; - for (cn = CLUST_FIRST; cn <= pmp->pm_maxcluster; cn++) { + for (cn = 0; cn <= pmp->pm_maxcluster; cn++) { byteoffset = FATOFS(pmp, cn); bo = byteoffset % pmp->pm_fatblocksize; - if (!bo || !bp) { + if (bo == 0) { /* Read new FAT block */ - if (bp) + if (bp != NULL) brelse(bp); fatblock(pmp, byteoffset, &bn, &bsize, NULL); error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp); - if (error) { - brelse(bp); + if (error != 0) return (error); - } } if (FAT32(pmp)) readcn = getulong(&bp->b_data[bo]); @@ -930,7 +928,19 @@ fillinusemap(struct msdosfsmount *pmp) readcn >>= 4; readcn &= pmp->pm_fatmask; - if (readcn == CLUST_FREE) + /* + * Check if the FAT ID matches the BPB's media descriptor and + * all other bits are set to 1. + */ + if (cn == 0 && readcn != ((pmp->pm_fatmask & 0xffffff00) | + pmp->pm_bpb.bpbMedia)) { +#ifdef MSDOSFS_DEBUG + printf("mountmsdosfs(): Media descriptor in BPB" + "does not match FAT ID\n"); +#endif + brelse(bp); + return (EINVAL); + } else if (readcn == CLUST_FREE) usemap_free(pmp, cn); } if (bp != NULL) From owner-svn-src-stable-11@freebsd.org Mon Sep 11 08:18:57 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D1490E2246B; Mon, 11 Sep 2017 08:18:57 +0000 (UTC) (envelope-from kib@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 mx1.freebsd.org (Postfix) with ESMTPS id 9E23B75FDD; Mon, 11 Sep 2017 08:18:57 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B8IusU012750; Mon, 11 Sep 2017 08:18:56 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B8IubG012749; Mon, 11 Sep 2017 08:18:56 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709110818.v8B8IubG012749@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 11 Sep 2017 08:18:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323430 - stable/11/sys/fs/msdosfs X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/fs/msdosfs X-SVN-Commit-Revision: 323430 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 08:18:57 -0000 Author: kib Date: Mon Sep 11 08:18:56 2017 New Revision: 323430 URL: https://svnweb.freebsd.org/changeset/base/323430 Log: MFC r322984: Style. Modified: stable/11/sys/fs/msdosfs/msdosfs_fat.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/fs/msdosfs/msdosfs_fat.c ============================================================================== --- stable/11/sys/fs/msdosfs/msdosfs_fat.c Mon Sep 11 08:16:38 2017 (r323429) +++ stable/11/sys/fs/msdosfs/msdosfs_fat.c Mon Sep 11 08:18:56 2017 (r323430) @@ -888,12 +888,12 @@ freeclusterchain(struct msdosfsmount *pmp, u_long clus int fillinusemap(struct msdosfsmount *pmp) { - struct buf *bp = NULL; - u_long cn, readcn; + struct buf *bp; + u_long bn, bo, bsize, byteoffset, cn, readcn; int error; - u_long bn, bo, bsize, byteoffset; MSDOSFS_ASSERT_MP_LOCKED(pmp); + bp = NULL; /* * Mark all clusters in use, we mark the free ones in the fat scan From owner-svn-src-stable-11@freebsd.org Mon Sep 11 08:36:46 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 439ABE231BB for ; Mon, 11 Sep 2017 08:36:46 +0000 (UTC) (envelope-from alonsoschaich@fastmail.fm) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 160C977324 for ; Mon, 11 Sep 2017 08:36:45 +0000 (UTC) (envelope-from alonsoschaich@fastmail.fm) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id D2C8C21107 for ; Mon, 11 Sep 2017 04:36:38 -0400 (EDT) Received: from web5 ([10.202.2.215]) by compute1.internal (MEProxy); Mon, 11 Sep 2017 04:36:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=6Rj69T+NbfwW1CtGMent5HmSt4HO8 McRbRyvYil74YI=; b=RPvzVh8hgdAs29fQ7R9KNRmIvYyHWNOsDdDWYonsXgNff L3QBivAWfT12GacZ/Z49n9tqX4DVwvPC8lXWDUBQmGPR5obo+blTeUIANwjcxG1X xpkz0ajoJZ2zg/sqaX2CoyEE1cnYK9EZ3JHu34jlSc4oYaBAKkwp1QoO4i+DDPFB /WOsdE8QroyKYAnhZgTy25yCJD3kPPCSmhAVi97IZnYDptrNx/ieviwvGwxsx6Vs heB+tB6STKomn3jKQtppfzBs5ftzF4K4GBQpHuknsfA50JN0q8W3yzmHxXuaRMlb QVktHXMVoI5ATqyf5rnla+M6FKXGWtvoX6ksxNl1A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=6Rj69T +NbfwW1CtGMent5HmSt4HO8McRbRyvYil74YI=; b=KC7u/YfvIcefPCagfxN/Ni eELK++LEPTMfidVIVW8AtKJ4bYETY5NL+Tc52lAk8gT6juDRCaTUsHPcFgvukMEk mE5qUXpt0O7qv4uwkE0Dbt+FBkNjaJqqAElYA5GF/xskCnpes70zr4TI37GYhGrg uNOWTp23gxgrtEOy2seSI1cWhr4c/sYyGsN6bkHYnBxIA/UzQRnWZz8DFHOFR0XB Ru+ASELXvNKaANcB5cu8qY4mk9S0ZQJtyn4LdlXYRjc1trUzI+g4uvuI8AOkuwYL jCFJcKzWBV4o9W7byC1oECjZJZPlY0SXaU87qZRPYDQmwzpb93x46pfLE4YjzPOw == X-ME-Sender: Received: by mailuser.nyi.internal (Postfix, from userid 99) id AC1069E2DF; Mon, 11 Sep 2017 04:36:38 -0400 (EDT) Message-Id: <1505118998.43745.1101828864.49A218B7@webmail.messagingengine.com> From: Schaich Alonso To: svn-src-stable-11@freebsd.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-973d3087 References: <201709060708.v8678qIw007343@repo.freebsd.org> In-Reply-To: <201709060708.v8678qIw007343@repo.freebsd.org> Subject: Re: svn commit: r323211 - stable/11/sys/dev/ixl Date: Mon, 11 Sep 2017 10:36:38 +0200 X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 08:36:46 -0000 On Wed, Sep 6, 2017, at 09:08, Ryan Libby wrote: > Author: rlibby > Date: Wed Sep 6 07:08:52 2017 > New Revision: 323211 > URL: https://svnweb.freebsd.org/changeset/base/323211 > > Log: > MFC r320977: > > ixl: gcc build errors > Hi Although seemingly unrelated, starting with this commit, STABLE-11 fails to mountroot on my box (i.e. 323210 works, 323211 does not). It is supposed to boot from zfs, however it fails to mount with "error 5". The 323211 kernel can boot an usb flash installation image though, and once it booted to that flash media, it can import the root pool without issues. The root ZFS pool is a single mirror and one of it's elements faulted and was removed, i.e. the root pool is degraded, however 323210 is able to boot it nevertheless. I don't see how 323211 could break the boot though. Or how to debug further into the issue. Is there a way to get more information about "zfs: trying to mount ${rootpool} failed with error 5"? Yours Alonso From owner-svn-src-stable-11@freebsd.org Mon Sep 11 08:48:38 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9D48BE237DD; Mon, 11 Sep 2017 08:48:38 +0000 (UTC) (envelope-from kib@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 mx1.freebsd.org (Postfix) with ESMTPS id 6A95A779DD; Mon, 11 Sep 2017 08:48:38 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B8mbtY026052; Mon, 11 Sep 2017 08:48:37 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B8maIj026041; Mon, 11 Sep 2017 08:48:36 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709110848.v8B8maIj026041@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 11 Sep 2017 08:48:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323431 - in stable/11/sys: amd64/amd64 amd64/include amd64/vmm/intel sys x86/x86 X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in stable/11/sys: amd64/amd64 amd64/include amd64/vmm/intel sys x86/x86 X-SVN-Commit-Revision: 323431 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 08:48:38 -0000 Author: kib Date: Mon Sep 11 08:48:36 2017 New Revision: 323431 URL: https://svnweb.freebsd.org/changeset/base/323431 Log: MFC r322762, r322799, r322832, r322833: Make WRFSBASE and WRGSBASE instructions functional. Bump stable/11 __FreeBSD_version. Modified: stable/11/sys/amd64/amd64/cpu_switch.S stable/11/sys/amd64/amd64/exception.S stable/11/sys/amd64/amd64/machdep.c stable/11/sys/amd64/amd64/ptrace_machdep.c stable/11/sys/amd64/amd64/sys_machdep.c stable/11/sys/amd64/amd64/vm_machdep.c stable/11/sys/amd64/include/asmacros.h stable/11/sys/amd64/include/pcb.h stable/11/sys/amd64/vmm/intel/vmx_msr.c stable/11/sys/sys/param.h stable/11/sys/x86/x86/identcpu.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/amd64/amd64/cpu_switch.S ============================================================================== --- stable/11/sys/amd64/amd64/cpu_switch.S Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/amd64/amd64/cpu_switch.S Mon Sep 11 08:48:36 2017 (r323431) @@ -87,7 +87,6 @@ END(cpu_throw) ENTRY(cpu_switch) /* Switch to new thread. First, save context. */ movq TD_PCB(%rdi),%r8 - orl $PCB_FULL_IRET,PCB_FLAGS(%r8) movq (%rsp),%rax /* Hardware registers */ movq %r15,PCB_R15(%r8) @@ -99,6 +98,30 @@ ENTRY(cpu_switch) movq %rbx,PCB_RBX(%r8) movq %rax,PCB_RIP(%r8) + testl $PCB_FULL_IRET,PCB_FLAGS(%r8) + jnz 2f + orl $PCB_FULL_IRET,PCB_FLAGS(%r8) + testl $TDP_KTHREAD,TD_PFLAGS(%rdi) + jnz 2f + testb $CPUID_STDEXT_FSGSBASE,cpu_stdext_feature(%rip) + jz 2f + movl %fs,%eax + cmpl $KUF32SEL,%eax + jne 1f + rdfsbaseq %rax + movq %rax,PCB_FSBASE(%r8) +1: movl %gs,%eax + cmpl $KUG32SEL,%eax + jne 2f + movq %rdx,%r12 + movl $MSR_KGSBASE,%ecx /* Read user gs base */ + rdmsr + shlq $32,%rdx + orq %rdx,%rax + movq %rax,PCB_GSBASE(%r8) + movq %r12,%rdx + +2: testl $PCB_DBREGS,PCB_FLAGS(%r8) jnz store_dr /* static predict not taken */ done_store_dr: Modified: stable/11/sys/amd64/amd64/exception.S ============================================================================== --- stable/11/sys/amd64/amd64/exception.S Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/amd64/amd64/exception.S Mon Sep 11 08:48:36 2017 (r323431) @@ -187,12 +187,13 @@ alltraps_testi: jz alltraps_pushregs_no_rdi sti alltraps_pushregs_no_rdi: - movq %rsi,TF_RSI(%rsp) movq %rdx,TF_RDX(%rsp) + movq %rax,TF_RAX(%rsp) +alltraps_pushregs_no_rax: + movq %rsi,TF_RSI(%rsp) movq %rcx,TF_RCX(%rsp) movq %r8,TF_R8(%rsp) movq %r9,TF_R9(%rsp) - movq %rax,TF_RAX(%rsp) movq %rbx,TF_RBX(%rsp) movq %rbp,TF_RBP(%rsp) movq %r10,TF_R10(%rsp) @@ -326,31 +327,53 @@ IDTVEC(prot) prot_addrf: movq $0,TF_ADDR(%rsp) movq %rdi,TF_RDI(%rsp) /* free up a GP register */ + movq %rax,TF_RAX(%rsp) + movq %rdx,TF_RDX(%rsp) + movw %fs,TF_FS(%rsp) + movw %gs,TF_GS(%rsp) leaq doreti_iret(%rip),%rdi cmpq %rdi,TF_RIP(%rsp) - je 1f /* kernel but with user gsbase!! */ + je 5f /* kernel but with user gsbase!! */ testb $SEL_RPL_MASK,TF_CS(%rsp) /* Did we come from kernel? */ - jz 2f /* already running with kernel GS.base */ -1: swapgs -2: movq PCPU(CURPCB),%rdi - orl $PCB_FULL_IRET,PCB_FLAGS(%rdi) /* always full iret from GPF */ - movw %fs,TF_FS(%rsp) - movw %gs,TF_GS(%rsp) + jz 6f /* already running with kernel GS.base */ + testb $CPUID_STDEXT_FSGSBASE,cpu_stdext_feature(%rip) + jz 2f + cmpw $KUF32SEL,TF_FS(%rsp) + jne 1f + rdfsbaseq %rax +1: cmpw $KUG32SEL,TF_GS(%rsp) + jne 2f + rdgsbaseq %rdx +2: swapgs + movq PCPU(CURPCB),%rdi + testb $CPUID_STDEXT_FSGSBASE,cpu_stdext_feature(%rip) + jz 4f + cmpw $KUF32SEL,TF_FS(%rsp) + jne 3f + movq %rax,PCB_FSBASE(%rdi) +3: cmpw $KUG32SEL,TF_GS(%rsp) + jne 4f + movq %rdx,PCB_GSBASE(%rdi) +4: orl $PCB_FULL_IRET,PCB_FLAGS(%rdi) /* always full iret from GPF */ movw %es,TF_ES(%rsp) movw %ds,TF_DS(%rsp) testl $PSL_I,TF_RFLAGS(%rsp) - jz alltraps_pushregs_no_rdi + jz alltraps_pushregs_no_rax sti - jmp alltraps_pushregs_no_rdi + jmp alltraps_pushregs_no_rax +5: swapgs +6: movq PCPU(CURPCB),%rdi + jmp 4b + /* * Fast syscall entry point. We enter here with just our new %cs/%ss set, * and the new privilige level. We are still running on the old user stack * pointer. We have to juggle a few things around to find our stack etc. * swapgs gives us access to our PCPU space only. * - * We do not support invoking this from a custom %cs or %ss (e.g. using - * entries from an LDT). + * We do not support invoking this from a custom segment registers, + * esp. %cs, %ss, %fs, %gs, e.g. using entries from an LDT. */ IDTVEC(fast_syscall) swapgs @@ -503,6 +526,23 @@ IDTVEC(nmi) nmi_fromuserspace: incl %ebx swapgs + testb $CPUID_STDEXT_FSGSBASE,cpu_stdext_feature(%rip) + jz 2f + movq PCPU(CURPCB),%rdi + testq %rdi,%rdi + jz 2f + cmpw $KUF32SEL,TF_FS(%rsp) + jne 1f + rdfsbaseq %rax + movq %rax,PCB_FSBASE(%rdi) +1: cmpw $KUG32SEL,TF_GS(%rsp) + jne 2f + movl $MSR_KGSBASE,%ecx + rdmsr + shlq $32,%rdx + orq %rdx,%rax + movq %rax,PCB_GSBASE(%rdi) +2: /* Note: this label is also used by ddb and gdb: */ nmi_calltrap: FAKE_MCOUNT(TF_RIP(%rsp)) @@ -705,6 +745,7 @@ doreti_exit: jz ld_regs testl $PCB_FULL_IRET,PCB_FLAGS(%r8) jz ld_regs + andl $~PCB_FULL_IRET,PCB_FLAGS(%r8) testl $TF_HASSEGS,TF_FLAGS(%rsp) je set_segs Modified: stable/11/sys/amd64/amd64/machdep.c ============================================================================== --- stable/11/sys/amd64/amd64/machdep.c Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/amd64/amd64/machdep.c Mon Sep 11 08:48:36 2017 (r323431) @@ -379,6 +379,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask sf.sf_uc.uc_mcontext.mc_len = sizeof(sf.sf_uc.uc_mcontext); /* magic */ get_fpcontext(td, &sf.sf_uc.uc_mcontext, xfpusave, xfpusave_len); fpstate_drop(td); + update_pcb_bases(pcb); sf.sf_uc.uc_mcontext.mc_fsbase = pcb->pcb_fsbase; sf.sf_uc.uc_mcontext.mc_gsbase = pcb->pcb_gsbase; bzero(sf.sf_uc.uc_mcontext.mc_spare, @@ -449,7 +450,6 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask regs->tf_fs = _ufssel; regs->tf_gs = _ugssel; regs->tf_flags = TF_HASSEGS; - set_pcb_flags(pcb, PCB_FULL_IRET); PROC_LOCK(p); mtx_lock(&psp->ps_mtx); } @@ -555,6 +555,7 @@ sys_sigreturn(td, uap) return (ret); } bcopy(&ucp->uc_mcontext.mc_rdi, regs, sizeof(*regs)); + update_pcb_bases(pcb); pcb->pcb_fsbase = ucp->uc_mcontext.mc_fsbase; pcb->pcb_gsbase = ucp->uc_mcontext.mc_gsbase; @@ -566,7 +567,6 @@ sys_sigreturn(td, uap) #endif kern_sigprocmask(td, SIG_SETMASK, &ucp->uc_sigmask, NULL, 0); - set_pcb_flags(pcb, PCB_FULL_IRET); return (EJUSTRETURN); } @@ -594,11 +594,11 @@ exec_setregs(struct thread *td, struct image_params *i else mtx_unlock(&dt_lock); + update_pcb_bases(pcb); pcb->pcb_fsbase = 0; pcb->pcb_gsbase = 0; clear_pcb_flags(pcb, PCB_32BIT); pcb->pcb_initial_fpucw = __INITIAL_FPUCW__; - set_pcb_flags(pcb, PCB_FULL_IRET); bzero((char *)regs, sizeof(struct trapframe)); regs->tf_rip = imgp->entry_addr; @@ -2142,6 +2142,7 @@ get_mcontext(struct thread *td, mcontext_t *mcp, int f mcp->mc_flags = tp->tf_flags; mcp->mc_len = sizeof(*mcp); get_fpcontext(td, mcp, NULL, 0); + update_pcb_bases(pcb); mcp->mc_fsbase = pcb->pcb_fsbase; mcp->mc_gsbase = pcb->pcb_gsbase; mcp->mc_xfpustate = 0; @@ -2212,11 +2213,11 @@ set_mcontext(struct thread *td, mcontext_t *mcp) tp->tf_fs = mcp->mc_fs; tp->tf_gs = mcp->mc_gs; } + set_pcb_flags(pcb, PCB_FULL_IRET); if (mcp->mc_flags & _MC_HASBASES) { pcb->pcb_fsbase = mcp->mc_fsbase; pcb->pcb_gsbase = mcp->mc_gsbase; } - set_pcb_flags(pcb, PCB_FULL_IRET); return (0); } @@ -2485,6 +2486,71 @@ user_dbreg_trap(void) * None of the breakpoints are in user space. */ return 0; +} + +/* + * The pcb_flags is only modified by current thread, or by other threads + * when current thread is stopped. However, current thread may change it + * from the interrupt context in cpu_switch(), or in the trap handler. + * When we read-modify-write pcb_flags from C sources, compiler may generate + * code that is not atomic regarding the interrupt handler. If a trap or + * interrupt happens and any flag is modified from the handler, it can be + * clobbered with the cached value later. Therefore, we implement setting + * and clearing flags with single-instruction functions, which do not race + * with possible modification of the flags from the trap or interrupt context, + * because traps and interrupts are executed only on instruction boundary. + */ +void +set_pcb_flags_raw(struct pcb *pcb, const u_int flags) +{ + + __asm __volatile("orl %1,%0" + : "=m" (pcb->pcb_flags) : "ir" (flags), "m" (pcb->pcb_flags) + : "cc", "memory"); + +} + +/* + * The support for RDFSBASE, WRFSBASE and similar instructions for %gs + * base requires that kernel saves MSR_FSBASE and MSR_{K,}GSBASE into + * pcb if user space modified the bases. We must save on the context + * switch or if the return to usermode happens through the doreti. + * + * Tracking of both events is performed by the pcb flag PCB_FULL_IRET, + * which have a consequence that the base MSRs must be saved each time + * the PCB_FULL_IRET flag is set. We disable interrupts to sync with + * context switches. + */ +void +set_pcb_flags(struct pcb *pcb, const u_int flags) +{ + register_t r; + + if (curpcb == pcb && + (flags & PCB_FULL_IRET) != 0 && + (pcb->pcb_flags & PCB_FULL_IRET) == 0 && + (cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) != 0) { + r = intr_disable(); + if ((pcb->pcb_flags & PCB_FULL_IRET) == 0) { + if (rfs() == _ufssel) + pcb->pcb_fsbase = rdfsbase(); + if (rgs() == _ugssel) + pcb->pcb_gsbase = rdmsr(MSR_KGSBASE); + } + set_pcb_flags_raw(pcb, flags); + intr_restore(r); + } else { + set_pcb_flags_raw(pcb, flags); + } +} + +void +clear_pcb_flags(struct pcb *pcb, const u_int flags) +{ + + __asm __volatile("andl %1,%0" + : "=m" (pcb->pcb_flags) : "ir" (~flags), "m" (pcb->pcb_flags) + : "cc", "memory"); } #ifdef KDB Modified: stable/11/sys/amd64/amd64/ptrace_machdep.c ============================================================================== --- stable/11/sys/amd64/amd64/ptrace_machdep.c Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/amd64/amd64/ptrace_machdep.c Mon Sep 11 08:48:36 2017 (r323431) @@ -117,15 +117,17 @@ cpu_ptrace_xstate(struct thread *td, int req, void *ad static void cpu_ptrace_setbase(struct thread *td, int req, register_t r) { + struct pcb *pcb; + pcb = td->td_pcb; + set_pcb_flags(pcb, PCB_FULL_IRET); if (req == PT_SETFSBASE) { - td->td_pcb->pcb_fsbase = r; + pcb->pcb_fsbase = r; td->td_frame->tf_fs = _ufssel; } else { - td->td_pcb->pcb_gsbase = r; + pcb->pcb_gsbase = r; td->td_frame->tf_gs = _ugssel; } - set_pcb_flags(td->td_pcb, PCB_FULL_IRET); } #ifdef COMPAT_FREEBSD32 @@ -136,6 +138,7 @@ static int cpu32_ptrace(struct thread *td, int req, void *addr, int data) { struct savefpu *fpstate; + struct pcb *pcb; uint32_t r; int error; @@ -167,8 +170,10 @@ cpu32_ptrace(struct thread *td, int req, void *addr, i error = EINVAL; break; } - r = req == PT_GETFSBASE ? td->td_pcb->pcb_fsbase : - td->td_pcb->pcb_gsbase; + pcb = td->td_pcb; + if (td == curthread) + update_pcb_bases(pcb); + r = req == PT_GETFSBASE ? pcb->pcb_fsbase : pcb->pcb_gsbase; error = copyout(&r, addr, sizeof(r)); break; @@ -197,6 +202,7 @@ int cpu_ptrace(struct thread *td, int req, void *addr, int data) { register_t *r, rv; + struct pcb *pcb; int error; #ifdef COMPAT_FREEBSD32 @@ -221,8 +227,10 @@ cpu_ptrace(struct thread *td, int req, void *addr, int case PT_GETFSBASE: case PT_GETGSBASE: - r = req == PT_GETFSBASE ? &td->td_pcb->pcb_fsbase : - &td->td_pcb->pcb_gsbase; + pcb = td->td_pcb; + if (td == curthread) + update_pcb_bases(pcb); + r = req == PT_GETFSBASE ? &pcb->pcb_fsbase : &pcb->pcb_gsbase; error = copyout(r, addr, sizeof(*r)); break; Modified: stable/11/sys/amd64/amd64/sys_machdep.c ============================================================================== --- stable/11/sys/amd64/amd64/sys_machdep.c Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/amd64/amd64/sys_machdep.c Mon Sep 11 08:48:36 2017 (r323431) @@ -256,39 +256,45 @@ sysarch(td, uap) error = amd64_set_ioperm(td, &iargs); break; case I386_GET_FSBASE: + update_pcb_bases(pcb); i386base = pcb->pcb_fsbase; error = copyout(&i386base, uap->parms, sizeof(i386base)); break; case I386_SET_FSBASE: error = copyin(uap->parms, &i386base, sizeof(i386base)); if (!error) { + set_pcb_flags(pcb, PCB_FULL_IRET); pcb->pcb_fsbase = i386base; td->td_frame->tf_fs = _ufssel; update_gdt_fsbase(td, i386base); } break; case I386_GET_GSBASE: + update_pcb_bases(pcb); i386base = pcb->pcb_gsbase; error = copyout(&i386base, uap->parms, sizeof(i386base)); break; case I386_SET_GSBASE: error = copyin(uap->parms, &i386base, sizeof(i386base)); if (!error) { + set_pcb_flags(pcb, PCB_FULL_IRET); pcb->pcb_gsbase = i386base; td->td_frame->tf_gs = _ugssel; update_gdt_gsbase(td, i386base); } break; case AMD64_GET_FSBASE: - error = copyout(&pcb->pcb_fsbase, uap->parms, sizeof(pcb->pcb_fsbase)); + update_pcb_bases(pcb); + error = copyout(&pcb->pcb_fsbase, uap->parms, + sizeof(pcb->pcb_fsbase)); break; case AMD64_SET_FSBASE: error = copyin(uap->parms, &a64base, sizeof(a64base)); if (!error) { if (a64base < VM_MAXUSER_ADDRESS) { - pcb->pcb_fsbase = a64base; set_pcb_flags(pcb, PCB_FULL_IRET); + pcb->pcb_fsbase = a64base; td->td_frame->tf_fs = _ufssel; } else error = EINVAL; @@ -296,15 +302,17 @@ sysarch(td, uap) break; case AMD64_GET_GSBASE: - error = copyout(&pcb->pcb_gsbase, uap->parms, sizeof(pcb->pcb_gsbase)); + update_pcb_bases(pcb); + error = copyout(&pcb->pcb_gsbase, uap->parms, + sizeof(pcb->pcb_gsbase)); break; case AMD64_SET_GSBASE: error = copyin(uap->parms, &a64base, sizeof(a64base)); if (!error) { if (a64base < VM_MAXUSER_ADDRESS) { - pcb->pcb_gsbase = a64base; set_pcb_flags(pcb, PCB_FULL_IRET); + pcb->pcb_gsbase = a64base; td->td_frame->tf_gs = _ugssel; } else error = EINVAL; Modified: stable/11/sys/amd64/amd64/vm_machdep.c ============================================================================== --- stable/11/sys/amd64/amd64/vm_machdep.c Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/amd64/amd64/vm_machdep.c Mon Sep 11 08:48:36 2017 (r323431) @@ -176,6 +176,7 @@ cpu_fork(td1, p2, td2, flags) /* Ensure that td1's pcb is up to date. */ fpuexit(td1); + update_pcb_bases(td1->td_pcb); /* Point the pcb to the top of the stack */ pcb2 = get_pcb_td(td2); @@ -242,7 +243,7 @@ cpu_fork(td1, p2, td2, flags) pcb2->pcb_tssp = NULL; /* New segment registers. */ - set_pcb_flags(pcb2, PCB_FULL_IRET); + set_pcb_flags_raw(pcb2, PCB_FULL_IRET); /* Copy the LDT, if necessary. */ mdp1 = &td1->td_proc->p_md; @@ -437,13 +438,14 @@ cpu_copy_thread(struct thread *td, struct thread *td0) * Those not loaded individually below get their default * values here. */ + update_pcb_bases(td0->td_pcb); bcopy(td0->td_pcb, pcb2, sizeof(*pcb2)); clear_pcb_flags(pcb2, PCB_FPUINITDONE | PCB_USERFPUINITDONE | PCB_KERNFPU); pcb2->pcb_save = get_pcb_user_save_pcb(pcb2); bcopy(get_pcb_user_save_td(td0), pcb2->pcb_save, cpu_max_ext_state_size); - set_pcb_flags(pcb2, PCB_FULL_IRET); + set_pcb_flags_raw(pcb2, PCB_FULL_IRET); /* * Create a new fresh stack for the new thread. Modified: stable/11/sys/amd64/include/asmacros.h ============================================================================== --- stable/11/sys/amd64/include/asmacros.h Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/amd64/include/asmacros.h Mon Sep 11 08:48:36 2017 (r323431) @@ -177,7 +177,12 @@ movw %es,TF_ES(%rsp) ; \ movw %ds,TF_DS(%rsp) ; \ movl $TF_HASSEGS,TF_FLAGS(%rsp) ; \ - cld + cld ; \ + testb $SEL_RPL_MASK,TF_CS(%rsp) ; /* come from kernel ? */ \ + jz 2f ; /* yes, leave PCB_FULL_IRET alone */ \ + movq PCPU(CURPCB),%r8 ; \ + andl $~PCB_FULL_IRET,PCB_FLAGS(%r8) ; \ +2: #define POP_FRAME \ movq TF_RDI(%rsp),%rdi ; \ Modified: stable/11/sys/amd64/include/pcb.h ============================================================================== --- stable/11/sys/amd64/include/pcb.h Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/amd64/include/pcb.h Mon Sep 11 08:48:36 2017 (r323431) @@ -119,40 +119,15 @@ struct susppcb { #ifdef _KERNEL struct trapframe; -/* - * The pcb_flags is only modified by current thread, or by other threads - * when current thread is stopped. However, current thread may change it - * from the interrupt context in cpu_switch(), or in the trap handler. - * When we read-modify-write pcb_flags from C sources, compiler may generate - * code that is not atomic regarding the interrupt handler. If a trap or - * interrupt happens and any flag is modified from the handler, it can be - * clobbered with the cached value later. Therefore, we implement setting - * and clearing flags with single-instruction functions, which do not race - * with possible modification of the flags from the trap or interrupt context, - * because traps and interrupts are executed only on instruction boundary. - */ -static __inline void -set_pcb_flags(struct pcb *pcb, const u_int flags) -{ - - __asm __volatile("orl %1,%0" - : "=m" (pcb->pcb_flags) : "ir" (flags), "m" (pcb->pcb_flags) - : "cc"); -} - -static __inline void -clear_pcb_flags(struct pcb *pcb, const u_int flags) -{ - - __asm __volatile("andl %1,%0" - : "=m" (pcb->pcb_flags) : "ir" (~flags), "m" (pcb->pcb_flags) - : "cc"); -} - +void clear_pcb_flags(struct pcb *pcb, const u_int flags); void makectx(struct trapframe *, struct pcb *); +void set_pcb_flags(struct pcb *pcb, const u_int flags); +void set_pcb_flags_raw(struct pcb *pcb, const u_int flags); int savectx(struct pcb *) __returns_twice; void resumectx(struct pcb *); +/* Ensure that pcb_gsbase and pcb_fsbase are up to date */ +#define update_pcb_bases(pcb) set_pcb_flags((pcb), PCB_FULL_IRET) #endif #endif /* _AMD64_PCB_H_ */ Modified: stable/11/sys/amd64/vmm/intel/vmx_msr.c ============================================================================== --- stable/11/sys/amd64/vmm/intel/vmx_msr.c Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/amd64/vmm/intel/vmx_msr.c Mon Sep 11 08:48:36 2017 (r323431) @@ -31,10 +31,12 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include +#include #include #include @@ -356,7 +358,8 @@ vmx_msr_guest_enter(struct vmx *vmx, int vcpuid) { uint64_t *guest_msrs = vmx->guest_msrs[vcpuid]; - /* Save host MSRs (if any) and restore guest MSRs */ + /* Save host MSRs (in particular, KGSBASE) and restore guest MSRs */ + update_pcb_bases(curpcb); wrmsr(MSR_LSTAR, guest_msrs[IDX_MSR_LSTAR]); wrmsr(MSR_CSTAR, guest_msrs[IDX_MSR_CSTAR]); wrmsr(MSR_STAR, guest_msrs[IDX_MSR_STAR]); Modified: stable/11/sys/sys/param.h ============================================================================== --- stable/11/sys/sys/param.h Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/sys/param.h Mon Sep 11 08:48:36 2017 (r323431) @@ -58,7 +58,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1101502 /* Master, propagated to newvers */ +#define __FreeBSD_version 1101503 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, @@ -84,6 +84,8 @@ #define P_OSREL_SHUTDOWN_ENOTCONN 1100077 #define P_OSREL_MAP_GUARD 1200035 #define P_OSREL_MAP_GUARD_11 1101501 +#define P_OSREL_WRFSBASE 1200041 +#define P_OSREL_WRFSBASE_11 1101503 #define P_OSREL_MAJOR(x) ((x) / 100000) #endif Modified: stable/11/sys/x86/x86/identcpu.c ============================================================================== --- stable/11/sys/x86/x86/identcpu.c Mon Sep 11 08:18:56 2017 (r323430) +++ stable/11/sys/x86/x86/identcpu.c Mon Sep 11 08:48:36 2017 (r323431) @@ -1423,18 +1423,15 @@ finishidentcpu(void) cpu_stdext_feature = regs[1]; /* - * Some hypervisors fail to filter out unsupported - * extended features. For now, disable the + * Some hypervisors failed to filter out unsupported + * extended features. Allow to disable the * extensions, activation of which requires setting a * bit in CR4, and which VM monitors do not support. */ - if (cpu_feature2 & CPUID2_HV) { - cpu_stdext_disable = CPUID_STDEXT_FSGSBASE | - CPUID_STDEXT_SMEP; - } else - cpu_stdext_disable = 0; + cpu_stdext_disable = 0; TUNABLE_INT_FETCH("hw.cpu_stdext_disable", &cpu_stdext_disable); cpu_stdext_feature &= ~cpu_stdext_disable; + cpu_stdext_feature2 = regs[2]; } From owner-svn-src-stable-11@freebsd.org Mon Sep 11 15:31:30 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6B737E11FAF; Mon, 11 Sep 2017 15:31:30 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 4494965488; Mon, 11 Sep 2017 15:31:30 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BFVTJK095132; Mon, 11 Sep 2017 15:31:29 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BFVT5N095131; Mon, 11 Sep 2017 15:31:29 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709111531.v8BFVT5N095131@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 15:31:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323440 - stable/11/sys/arm/freescale/imx X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/freescale/imx X-SVN-Commit-Revision: 323440 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 15:31:30 -0000 Author: ian Date: Mon Sep 11 15:31:29 2017 New Revision: 323440 URL: https://svnweb.freebsd.org/changeset/base/323440 Log: MFC r321586: Add a debug sysctl that lets you see i2c bus traffic through this device. Modified: stable/11/sys/arm/freescale/imx/imx_i2c.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/freescale/imx/imx_i2c.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_i2c.c Mon Sep 11 15:18:43 2017 (r323439) +++ stable/11/sys/arm/freescale/imx/imx_i2c.c Mon Sep 11 15:31:29 2017 (r323440) @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -139,8 +140,18 @@ struct i2c_softc { int rb_pinctl_idx; gpio_pin_t rb_sclpin; gpio_pin_t rb_sdapin; + u_int debug; + u_int slave; }; +#define DEVICE_DEBUGF(sc, lvl, fmt, args...) \ + if ((lvl) <= (sc)->debug) \ + device_printf((sc)->dev, fmt, ##args) + +#define DEBUGF(sc, lvl, fmt, args...) \ + if ((lvl) <= (sc)->debug) \ + printf(fmt, ##args) + static phandle_t i2c_get_node(device_t, device_t); static int i2c_probe(device_t); static int i2c_attach(device_t); @@ -384,6 +395,12 @@ i2c_attach(device_t dev) return (ENXIO); } + /* Set up debug-enable sysctl. */ + SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), + OID_AUTO, "debug", CTLFLAG_RWTUN, &sc->debug, 0, + "Enable debug; 1=reads/writes, 2=add starts/stops"); + /* * Set up for bus recovery using gpio pins, if the pinctrl and gpio * properties are present. This is optional. If all the config data is @@ -451,6 +468,8 @@ i2c_repeated_start(device_t dev, u_char slave, int tim DELAY(1); i2c_write_reg(sc, I2C_STATUS_REG, 0x0); i2c_write_reg(sc, I2C_DATA_REG, slave); + sc->slave = slave; + DEVICE_DEBUGF(sc, 2, "rstart 0x%02x\n", sc->slave); error = wait_for_xfer(sc, true); return (i2c_error_handler(sc, error)); } @@ -473,6 +492,8 @@ i2c_start_ll(device_t dev, u_char slave, int timeout) return (i2c_error_handler(sc, error)); i2c_write_reg(sc, I2C_STATUS_REG, 0); i2c_write_reg(sc, I2C_DATA_REG, slave); + sc->slave = slave; + DEVICE_DEBUGF(sc, 2, "start 0x%02x\n", sc->slave); error = wait_for_xfer(sc, true); return (i2c_error_handler(sc, error)); } @@ -512,6 +533,7 @@ i2c_stop(device_t dev) i2c_write_reg(sc, I2C_CONTROL_REG, I2CCR_MEN); wait_for_busbusy(sc, false); i2c_write_reg(sc, I2C_CONTROL_REG, 0); + DEVICE_DEBUGF(sc, 2, "stop 0x%02x\n", sc->slave); return (IIC_NOERR); } @@ -523,6 +545,8 @@ i2c_reset(device_t dev, u_char speed, u_char addr, u_c sc = device_get_softc(dev); + DEVICE_DEBUGF(sc, 1, "reset\n"); + /* * Look up the divisor that gives the nearest speed that doesn't exceed * the configured value for the bus. @@ -568,6 +592,7 @@ i2c_read(device_t dev, char *buf, int len, int *read, sc = device_get_softc(dev); *read = 0; + DEVICE_DEBUGF(sc, 1, "read 0x%02x len %d: ", sc->slave, len); if (len) { if (len == 1) i2c_write_reg(sc, I2C_CONTROL_REG, I2CCR_MEN | @@ -599,9 +624,11 @@ i2c_read(device_t dev, char *buf, int len, int *read, } } reg = i2c_read_reg(sc, I2C_DATA_REG); + DEBUGF(sc, 1, "0x%02x ", reg); *buf++ = reg; (*read)++; } + DEBUGF(sc, 1, "\n"); return (i2c_error_handler(sc, error)); } @@ -616,13 +643,15 @@ i2c_write(device_t dev, const char *buf, int len, int error = 0; *sent = 0; + DEVICE_DEBUGF(sc, 1, "write 0x%02x len %d: ", sc->slave, len); while (*sent < len) { + DEBUGF(sc, 1, "0x%02x ", *buf); i2c_write_reg(sc, I2C_STATUS_REG, 0x0); i2c_write_reg(sc, I2C_DATA_REG, *buf++); if ((error = wait_for_xfer(sc, true)) != IIC_NOERR) break; (*sent)++; } - + DEBUGF(sc, 1, "\n"); return (i2c_error_handler(sc, error)); } From owner-svn-src-stable-11@freebsd.org Mon Sep 11 15:52:25 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8CCE3E1319C; Mon, 11 Sep 2017 15:52:25 +0000 (UTC) (envelope-from kevans@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 mx1.freebsd.org (Postfix) with ESMTPS id 696DE661C1; Mon, 11 Sep 2017 15:52:25 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BFqOSa005609; Mon, 11 Sep 2017 15:52:24 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BFqOAi005604; Mon, 11 Sep 2017 15:52:24 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201709111552.v8BFqOAi005604@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 11 Sep 2017 15:52:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323443 - in stable/11: contrib/netbsd-tests/usr.bin/grep usr.bin/grep X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/11: contrib/netbsd-tests/usr.bin/grep usr.bin/grep X-SVN-Commit-Revision: 323443 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 15:52:25 -0000 Author: kevans Date: Mon Sep 11 15:52:24 2017 New Revision: 323443 URL: https://svnweb.freebsd.org/changeset/base/323443 Log: bsdgrep: add a primitive literal matcher to unbreak fgrep in some scenarios MFC r322825: bsdgrep: add some additional tests for fgrep Previously added tests only check that fgrep is somewhat sane and works. Add some more tests that check that the implementation is basically functional and not producing incorrect results with various flags. MFC r322826: bsdgrep: add a primitive literal matcher fgrep/grep -F will error out at runtime if compiled with a regex(3) that does not define REG_NOSPEC or REG_LITERAL. glibc is one such regex(3) implementation, and as it turns out they don't support literal matching at all. Provide a primitive literal matcher for use with glibc and other implementations that don't support literal matching so that we don't completely lose fgrep/grep -F if compiled against libgnuregex on stable/10, stable/11, or other systems that we don't necessarily support. This is a wholly unoptimized implementation with no plans to optimize it as of now. This is due to both its use-case being primarily on unsupported systems in the near-distant future and that it's reinventing the wheel that we already have available as a feature of regex(3). PR: 222201 Approved by: emaste (mentor, blanket MFC) Modified: stable/11/contrib/netbsd-tests/usr.bin/grep/t_grep.sh stable/11/usr.bin/grep/grep.c stable/11/usr.bin/grep/grep.h stable/11/usr.bin/grep/util.c Directory Properties: stable/11/ (props changed) Modified: stable/11/contrib/netbsd-tests/usr.bin/grep/t_grep.sh ============================================================================== --- stable/11/contrib/netbsd-tests/usr.bin/grep/t_grep.sh Mon Sep 11 15:38:51 2017 (r323442) +++ stable/11/contrib/netbsd-tests/usr.bin/grep/t_grep.sh Mon Sep 11 15:52:24 2017 (r323443) @@ -685,6 +685,59 @@ matchall_body() atf_check -s exit:1 grep "" test1 } + +atf_test_case fgrep_multipattern +fgrep_multipattern_head() +{ + atf_set "descr" "Check proper behavior with multiple patterns supplied to fgrep" +} +fgrep_multipattern_body() +{ + printf "Foo\nBar\nBaz" > test1 + + atf_check -o inline:"Foo\nBaz\n" grep -F -e "Foo" -e "Baz" test1 + atf_check -o inline:"Foo\nBaz\n" grep -F -e "Baz" -e "Foo" test1 + atf_check -o inline:"Bar\nBaz\n" grep -F -e "Bar" -e "Baz" test1 +} + +atf_test_case fgrep_icase +fgrep_icase_head() +{ + atf_set "descr" "Check proper handling of -i supplied to fgrep" +} +fgrep_icase_body() +{ + printf "Foo\nBar\nBaz" > test1 + + atf_check -o inline:"Foo\nBaz\n" grep -Fi -e "foo" -e "baz" test1 + atf_check -o inline:"Foo\nBaz\n" grep -Fi -e "baz" -e "foo" test1 + atf_check -o inline:"Bar\nBaz\n" grep -Fi -e "bar" -e "baz" test1 + atf_check -o inline:"Bar\nBaz\n" grep -Fi -e "BAR" -e "bAz" test1 +} + +atf_test_case fgrep_oflag +fgrep_oflag_head() +{ + atf_set "descr" "Check proper handling of -o supplied to fgrep" +} +fgrep_oflag_body() +{ + printf "abcdefghi\n" > test1 + + atf_check -o inline:"a\n" grep -Fo "a" test1 + atf_check -o inline:"i\n" grep -Fo "i" test1 + atf_check -o inline:"abc\n" grep -Fo "abc" test1 + atf_check -o inline:"fgh\n" grep -Fo "fgh" test1 + atf_check -o inline:"cde\n" grep -Fo "cde" test1 + atf_check -o inline:"bcd\n" grep -Fo -e "bcd" -e "cde" test1 + atf_check -o inline:"bcd\nefg\n" grep -Fo -e "bcd" -e "efg" test1 + + atf_check -s exit:1 grep -Fo "xabc" test1 + atf_check -s exit:1 grep -Fo "abcx" test1 + atf_check -s exit:1 grep -Fo "xghi" test1 + atf_check -s exit:1 grep -Fo "ghix" test1 + atf_check -s exit:1 grep -Fo "abcdefghiklmnopqrstuvwxyz" test1 +} # End FreeBSD atf_init_test_cases() @@ -726,5 +779,8 @@ atf_init_test_cases() atf_add_test_case mmap atf_add_test_case mmap_eof_not_eol atf_add_test_case matchall + atf_add_test_case fgrep_multipattern + atf_add_test_case fgrep_icase + atf_add_test_case fgrep_oflag # End FreeBSD } Modified: stable/11/usr.bin/grep/grep.c ============================================================================== --- stable/11/usr.bin/grep/grep.c Mon Sep 11 15:38:51 2017 (r323442) +++ stable/11/usr.bin/grep/grep.c Mon Sep 11 15:52:24 2017 (r323443) @@ -721,12 +721,19 @@ main(int argc, char *argv[]) case GREP_BASIC: break; case GREP_FIXED: + /* + * regex(3) implementations that support fixed-string searches generally + * define either REG_NOSPEC or REG_LITERAL. Set the appropriate flag + * here. If neither are defined, GREP_FIXED later implies that the + * internal literal matcher should be used. Other cflags that have + * the same interpretation as REG_NOSPEC and REG_LITERAL should be + * similarly added here, and grep.h should be amended to take this into + * consideration when defining WITH_INTERNAL_NOSPEC. + */ #if defined(REG_NOSPEC) cflags |= REG_NOSPEC; #elif defined(REG_LITERAL) cflags |= REG_LITERAL; -#else - errx(2, "literal expressions not supported at compile time"); #endif break; case GREP_EXTENDED: @@ -743,7 +750,11 @@ main(int argc, char *argv[]) r_pattern = grep_calloc(patterns, sizeof(*r_pattern)); /* Don't process any patterns if we have a blank one */ +#ifdef WITH_INTERNAL_NOSPEC + if (!matchall && grepbehave != GREP_FIXED) { +#else if (!matchall) { +#endif /* Check if cheating is allowed (always is for fgrep). */ for (i = 0; i < patterns; ++i) { #ifndef WITHOUT_FASTMATCH Modified: stable/11/usr.bin/grep/grep.h ============================================================================== --- stable/11/usr.bin/grep/grep.h Mon Sep 11 15:38:51 2017 (r323442) +++ stable/11/usr.bin/grep/grep.h Mon Sep 11 15:52:24 2017 (r323443) @@ -57,6 +57,10 @@ extern const char *errstr[]; #define GREP_BASIC 1 #define GREP_EXTENDED 2 +#if !defined(REG_NOSPEC) && !defined(REG_LITERAL) +#define WITH_INTERNAL_NOSPEC +#endif + #define BINFILE_BIN 0 #define BINFILE_SKIP 1 #define BINFILE_TEXT 2 Modified: stable/11/usr.bin/grep/util.c ============================================================================== --- stable/11/usr.bin/grep/util.c Mon Sep 11 15:38:51 2017 (r323442) +++ stable/11/usr.bin/grep/util.c Mon Sep 11 15:52:24 2017 (r323443) @@ -70,7 +70,10 @@ struct parsec { bool binary; /* Binary file? */ }; - +#ifdef WITH_INTERNAL_NOSPEC +static int litexec(const struct pat *pat, const char *string, + size_t nmatch, regmatch_t pmatch[]); +#endif static int procline(struct parsec *pc); static void printline(struct parsec *pc, int sep); static void printline_metadata(struct str *line, int sep); @@ -350,6 +353,67 @@ procfile(const char *fn) return (c); } +#ifdef WITH_INTERNAL_NOSPEC +/* + * Internal implementation of literal string search within a string, modeled + * after regexec(3), for use when the regex(3) implementation doesn't offer + * either REG_NOSPEC or REG_LITERAL. This does not apply in the default FreeBSD + * config, but in other scenarios such as building against libgnuregex or on + * some non-FreeBSD OSes. + */ +static int +litexec(const struct pat *pat, const char *string, size_t nmatch, + regmatch_t pmatch[]) +{ + char *(*strstr_fn)(const char *, const char *); + char *sub, *subject; + const char *search; + size_t idx, n, ofs, stringlen; + + if (cflags & REG_ICASE) + strstr_fn = strcasestr; + else + strstr_fn = strstr; + idx = 0; + ofs = pmatch[0].rm_so; + stringlen = pmatch[0].rm_eo; + if (ofs >= stringlen) + return (REG_NOMATCH); + subject = strndup(string, stringlen); + if (subject == NULL) + return (REG_ESPACE); + for (n = 0; ofs < stringlen;) { + search = (subject + ofs); + if ((unsigned long)pat->len > strlen(search)) + break; + sub = strstr_fn(search, pat->pat); + /* + * Ignoring the empty string possibility due to context: grep optimizes + * for empty patterns and will never reach this point. + */ + if (sub == NULL) + break; + ++n; + /* Fill in pmatch if necessary */ + if (nmatch > 0) { + pmatch[idx].rm_so = ofs + (sub - search); + pmatch[idx].rm_eo = pmatch[idx].rm_so + pat->len; + if (++idx == nmatch) + break; + ofs = pmatch[idx].rm_so + 1; + } else + /* We only needed to know if we match or not */ + break; + } + free(subject); + if (n > 0 && nmatch > 0) + for (n = idx; n < nmatch; ++n) + pmatch[n].rm_so = pmatch[n].rm_eo = -1; + + return (n > 0 ? 0 : REG_NOMATCH); +} +#endif /* WITH_INTERNAL_NOSPEC */ + #define iswword(x) (iswalnum((x)) || (x) == L'_') /* @@ -400,6 +464,11 @@ procline(struct parsec *pc) for (i = 0; i < patterns; i++) { pmatch.rm_so = st; pmatch.rm_eo = pc->ln.len; +#ifdef WITH_INTERNAL_NOSPEC + if (grepbehave == GREP_FIXED) + r = litexec(&pattern[i], pc->ln.dat, 1, &pmatch); + else +#endif #ifndef WITHOUT_FASTMATCH if (fg_pattern[i].pattern) r = fastexec(&fg_pattern[i], From owner-svn-src-stable-11@freebsd.org Mon Sep 11 17:01:28 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 68CAFE168F4; Mon, 11 Sep 2017 17:01:28 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 42B2E68862; Mon, 11 Sep 2017 17:01:28 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BH1Rdl030586; Mon, 11 Sep 2017 17:01:27 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BH1RKP030583; Mon, 11 Sep 2017 17:01:27 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709111701.v8BH1RKP030583@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 17:01:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323446 - stable/11/sys/dev/iicbus X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/dev/iicbus X-SVN-Commit-Revision: 323446 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 17:01:28 -0000 Author: ian Date: Mon Sep 11 17:01:26 2017 New Revision: 323446 URL: https://svnweb.freebsd.org/changeset/base/323446 Log: MFC r321583, r321584: Add a pair of convenience routines for doing simple "register" read/writes on i2c devices, where the "register" can be any length. Add support for tracking nested calls to iicbus_request/release_bus(). Usually it is sufficient to use iicbus_transfer_excl(), or one of the higher-level convenience functions that use it, to reserve the bus for the duration of each register access. Occasionally it is important that a series of accesses or read-modify-write operations must be done without any other intervening access to the device, to prevent corrupting state. Modified: stable/11/sys/dev/iicbus/iicbus.h stable/11/sys/dev/iicbus/iiconf.c stable/11/sys/dev/iicbus/iiconf.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/iicbus/iicbus.h ============================================================================== --- stable/11/sys/dev/iicbus/iicbus.h Mon Sep 11 15:59:20 2017 (r323445) +++ stable/11/sys/dev/iicbus/iicbus.h Mon Sep 11 17:01:26 2017 (r323446) @@ -39,6 +39,7 @@ struct iicbus_softc { device_t dev; /* Myself */ device_t owner; /* iicbus owner device structure */ + u_int owncount; /* iicbus ownership nesting count */ u_char started; /* address of the 'started' slave * 0 if no start condition succeeded */ u_char strict; /* deny operations that violate the Modified: stable/11/sys/dev/iicbus/iiconf.c ============================================================================== --- stable/11/sys/dev/iicbus/iiconf.c Mon Sep 11 15:59:20 2017 (r323445) +++ stable/11/sys/dev/iicbus/iiconf.c Mon Sep 11 17:01:26 2017 (r323446) @@ -113,26 +113,30 @@ iicbus_request_bus(device_t bus, device_t dev, int how IICBUS_LOCK(sc); - while ((error == 0) && (sc->owner != NULL)) + while (error == 0 && sc->owner != NULL && sc->owner != dev) error = iicbus_poll(sc, how); if (error == 0) { - sc->owner = dev; - /* - * Drop the lock around the call to the bus driver. - * This call should be allowed to sleep in the IIC_WAIT case. - * Drivers might also need to grab locks that would cause LOR - * if our lock is held. - */ - IICBUS_UNLOCK(sc); - /* Ask the underlying layers if the request is ok */ - error = IICBUS_CALLBACK(device_get_parent(bus), - IIC_REQUEST_BUS, (caddr_t)&how); - IICBUS_LOCK(sc); - - if (error != 0) { - sc->owner = NULL; - wakeup_one(sc); + ++sc->owncount; + if (sc->owner == NULL) { + sc->owner = dev; + /* + * Drop the lock around the call to the bus driver, it + * should be allowed to sleep in the IIC_WAIT case. + * Drivers might also need to grab locks that would + * cause a LOR if our lock is held. + */ + IICBUS_UNLOCK(sc); + /* Ask the underlying layers if the request is ok */ + error = IICBUS_CALLBACK(device_get_parent(bus), + IIC_REQUEST_BUS, (caddr_t)&how); + IICBUS_LOCK(sc); + + if (error != 0) { + sc->owner = NULL; + sc->owncount = 0; + wakeup_one(sc); + } } } @@ -150,7 +154,6 @@ int iicbus_release_bus(device_t bus, device_t dev) { struct iicbus_softc *sc = (struct iicbus_softc *)device_get_softc(bus); - int error; IICBUS_LOCK(sc); @@ -159,26 +162,16 @@ iicbus_release_bus(device_t bus, device_t dev) return (IIC_EBUSBSY); } - /* - * Drop the lock around the call to the bus driver. - * This call should be allowed to sleep in the IIC_WAIT case. - * Drivers might also need to grab locks that would cause LOR - * if our lock is held. - */ - IICBUS_UNLOCK(sc); - /* Ask the underlying layers if the release is ok */ - error = IICBUS_CALLBACK(device_get_parent(bus), IIC_RELEASE_BUS, NULL); - - if (error == 0) { + if (--sc->owncount == 0) { + /* Drop the lock while informing the low-level driver. */ + IICBUS_UNLOCK(sc); + IICBUS_CALLBACK(device_get_parent(bus), IIC_RELEASE_BUS, NULL); IICBUS_LOCK(sc); sc->owner = NULL; - - /* wakeup a waiting thread */ wakeup_one(sc); - IICBUS_UNLOCK(sc); } - - return (error); + IICBUS_UNLOCK(sc); + return (0); } /* @@ -469,4 +462,56 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs if (error != 0 && started) iicbus_stop(bus); return (error); +} + +int +iicdev_readfrom(device_t slavedev, uint8_t regaddr, void *buffer, + uint16_t buflen, int waithow) +{ + struct iic_msg msgs[2]; + uint8_t slaveaddr; + + /* + * Two transfers back to back with a repeat-start between them; first we + * write the address-within-device, then we read from the device. + */ + slaveaddr = iicbus_get_addr(slavedev); + + msgs[0].slave = slaveaddr; + msgs[0].flags = IIC_M_WR | IIC_M_NOSTOP; + msgs[0].len = 1; + msgs[0].buf = ®addr; + + msgs[1].slave = slaveaddr; + msgs[1].flags = IIC_M_RD; + msgs[1].len = buflen; + msgs[1].buf = buffer; + + return (iicbus_transfer_excl(slavedev, msgs, nitems(msgs), waithow)); +} + +int iicdev_writeto(device_t slavedev, uint8_t regaddr, void *buffer, + uint16_t buflen, int waithow) +{ + struct iic_msg msgs[2]; + uint8_t slaveaddr; + + /* + * Two transfers back to back with no stop or start between them; first + * we write the address then we write the data to that address, all in a + * single transfer from two scattered buffers. + */ + slaveaddr = iicbus_get_addr(slavedev); + + msgs[0].slave = slaveaddr; + msgs[0].flags = IIC_M_WR | IIC_M_NOSTOP; + msgs[0].len = 1; + msgs[0].buf = ®addr; + + msgs[1].slave = slaveaddr; + msgs[1].flags = IIC_M_WR | IIC_M_NOSTART; + msgs[1].len = buflen; + msgs[1].buf = buffer; + + return (iicbus_transfer_excl(slavedev, msgs, nitems(msgs), waithow)); } Modified: stable/11/sys/dev/iicbus/iiconf.h ============================================================================== --- stable/11/sys/dev/iicbus/iiconf.h Mon Sep 11 15:59:20 2017 (r323445) +++ stable/11/sys/dev/iicbus/iiconf.h Mon Sep 11 17:01:26 2017 (r323446) @@ -133,6 +133,16 @@ int iicbus_transfer_excl(device_t bus, struct iic_msg int how); int iicbus_transfer_gen(device_t bus, struct iic_msg *msgs, uint32_t nmsgs); +/* + * Simple register read/write routines, but the "register" can be any size. + * The transfers are done with iicbus_transfer_excl(). Reads use a repeat-start + * between sending the address and reading; writes use a single start/stop. + */ +int iicdev_readfrom(device_t _slavedev, uint8_t _regaddr, void *_buffer, + uint16_t _buflen, int _waithow); +int iicdev_writeto(device_t _slavedev, uint8_t _regaddr, void *_buffer, + uint16_t _buflen, int _waithow); + #define IICBUS_MODVER 1 #define IICBUS_MINVER 1 #define IICBUS_MAXVER 1 From owner-svn-src-stable-11@freebsd.org Mon Sep 11 17:32:29 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0F853E186C4; Mon, 11 Sep 2017 17:32:29 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id B97C66A1CA; Mon, 11 Sep 2017 17:32:28 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BHWRjh046526; Mon, 11 Sep 2017 17:32:27 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BHWRgq046517; Mon, 11 Sep 2017 17:32:27 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709111732.v8BHWRgq046517@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 17:32:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323447 - in stable/11: share/man/man9 sys/amd64/amd64 sys/isa sys/kern sys/sys sys/x86/isa X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11: share/man/man9 sys/amd64/amd64 sys/isa sys/kern sys/sys sys/x86/isa X-SVN-Commit-Revision: 323447 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 17:32:29 -0000 Author: ian Date: Mon Sep 11 17:32:26 2017 New Revision: 323447 URL: https://svnweb.freebsd.org/changeset/base/323447 Log: MFC r320901-r320902, r320996-r320997, r321002, r321048, r321400, r321743, r321745 r320901: Protect access to the AT realtime clock with its own mutex. The mutex protecting access to the registered realtime clock should not be overloaded to protect access to the atrtc hardware, which might not even be the registered rtc. More importantly, the resettodr mutex needs to be eliminated to remove locking/sleeping restrictions on clock drivers, and that can't happen if MD code for amd64 depends on it. This change moves the protection into what's really being protected: access to the atrtc date and time registers. This change also adds protection when the clock is accessed from xentimer_settime(), which bypasses the resettodr locking. Differential Revision: https://reviews.freebsd.org/D11483 r320902: Support multiple realtime clocks, and remove locking/sleeping restrictions on clock drivers. This tracks multiple concurrent realtime clock drivers in a list sorted by clock resolution. When system time changes (and periodically) the clock_settime() methods of all registered clocks are invoked. To initialize system time, each driver is tried in turn from best to worst resolution, until one succesfully returns a valid time. The code no longer holds a mutex while calling the clock_settime() and clock_gettime() methods of the registered clocks. This allows clock drivers to do whatever kind of locking or sleeping is necessary (this is especially important for i2c clock chips since i2c drivers often need to sleep). A new clock_register_flags() function allows the clock driver to pass flags. The flags currently defined help support drivers that use their own techniques to avoid roundoff errors (prevents the 4/5 rounding done by the subr_rtc code). A driver which may need to wait for resources (such as bus ownership) may pass a flag to indicate that it will obtain system time for itself after waiting for resources; this is merely an optimization to avoid the common code retrieving a timespec that will never get used. Relnotes: yes Differential Revision: https://reviews.freebsd.org/D11484 r320996: Allow setting debug.clocktime as a tunable. Print 64-bit time_t correctly on 32-bit systems. r320997: Minor optimization: instead of converting between days and years using loops that start in 1970, assume most conversions are going to be for recent dates and use a precomputed number of days through the end of 2016. r321002: Revert r320997. There are reports of it getting the wrong results, so clearly my testing was insuffficent, and it's best to just revert it until I get it straightened out. r321048: Minor optimization: instead of converting between days and years using loops that start in 1970, assume most conversions are going to be for recent dates and use a precomputed number of days through the end of 2016. This is a do-over of r320997, hopefully this time with 100% more workiness. The first attempt had an off-by-one error, but instead of just adding another mysterious +1 adjustment, this rearranges the relationship between recent_base_year and recent_base_days so that the latter is the number of days that occurred before the start of the associated year (instead of the count thru the end of that year). This makes the recent_base stuff work more like the original loop logic that didn't need any +1 adjustments. r321400: Add common code to support realtime clocks that store year without century. Most realtime clocks store the year as 2 BCD digits. Some add a century bit to extend the range another hundred years. Every clock driver has its own code to determine the century and pass a full year value to clock_ct_to_ts(). Now clock drivers can just convert BCD to bin and store the result in the clocktime struct and let the common code figure out the century. Clocks with a century bit can just add 100 to year if the century bit is on. r321743: Add taskqueue_enqueue_timeout_sbt(), because sometimes you want more control over the scheduling precision than 'ticks' can offer, and because sometimes you're already working with sbintime_t units and it's dumb to convert them to ticks just so they can get converted back to sbintime_t under the hood. r321745: Add clock_schedule(), a feature that allows realtime clock drivers to request that their clock_settime() methods be called at a given offset from top-of-second. This adds a timeout_task to the rtc_instance so that each clock can be separately added to taskqueue_thread with the scheduling it prefers, instead of looping through all the clocks at once with a single task on taskqueue_thread. If a driver doesn't call clock_schedule() the default is the old behavior: clock_settime() is queued immediately. Modified: stable/11/share/man/man9/taskqueue.9 stable/11/sys/amd64/amd64/efirt.c stable/11/sys/isa/rtc.h stable/11/sys/kern/subr_clock.c stable/11/sys/kern/subr_rtc.c stable/11/sys/kern/subr_taskqueue.c stable/11/sys/sys/clock.h stable/11/sys/sys/taskqueue.h stable/11/sys/x86/isa/atrtc.c Directory Properties: stable/11/ (props changed) Modified: stable/11/share/man/man9/taskqueue.9 ============================================================================== --- stable/11/share/man/man9/taskqueue.9 Mon Sep 11 17:01:26 2017 (r323446) +++ stable/11/share/man/man9/taskqueue.9 Mon Sep 11 17:32:26 2017 (r323447) @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 1, 2016 +.Dd July 30, 2017 .Dt TASKQUEUE 9 .Os .Sh NAME @@ -82,6 +82,8 @@ struct timeout_task; .Ft int .Fn taskqueue_enqueue_timeout "struct taskqueue *queue" "struct timeout_task *timeout_task" "int ticks" .Ft int +.Fn taskqueue_enqueue_timeout_sbt "struct taskqueue *queue" "struct timeout_task *timeout_task" "sbintime_t sbt" "sbintime_t pr" "int flags" +.Ft int .Fn taskqueue_cancel "struct taskqueue *queue" "struct task *task" "u_int *pendp" .Ft int .Fn taskqueue_cancel_timeout "struct taskqueue *queue" "struct timeout_task *timeout_task" "u_int *pendp" @@ -211,8 +213,17 @@ is called on the task pointer passed to .Pp The .Fn taskqueue_enqueue_timeout -is used to schedule the enqueue after the specified amount of +function is used to schedule the enqueue after the specified number of .Va ticks . +The +.Fn taskqueue_enqueue_timeout_sbt +function provides finer control over the scheduling based on +.Va sbt , +.Va pr , +and +.Va flags , +as detailed in +.Xr timeout 9 . Only non-fast task queues can be used for .Va timeout_task scheduling. @@ -483,6 +494,7 @@ be created with a dedicated processing thread. .Xr ithread 9 , .Xr kthread 9 , .Xr swi 9 +.Xr timeout 9 .Sh HISTORY This interface first appeared in .Fx 5.0 . Modified: stable/11/sys/amd64/amd64/efirt.c ============================================================================== --- stable/11/sys/amd64/amd64/efirt.c Mon Sep 11 17:01:26 2017 (r323446) +++ stable/11/sys/amd64/amd64/efirt.c Mon Sep 11 17:32:26 2017 (r323447) @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -444,7 +445,7 @@ efi_get_time_locked(struct efi_tm *tm) efi_status status; int error; - mtx_assert(&resettodr_lock, MA_OWNED); + mtx_assert(&atrtc_time_lock, MA_OWNED); error = efi_enter(); if (error != 0) return (error); @@ -461,9 +462,9 @@ efi_get_time(struct efi_tm *tm) if (efi_runtime == NULL) return (ENXIO); - mtx_lock(&resettodr_lock); + mtx_lock(&atrtc_time_lock); error = efi_get_time_locked(tm); - mtx_unlock(&resettodr_lock); + mtx_unlock(&atrtc_time_lock); return (error); } @@ -486,7 +487,7 @@ efi_set_time_locked(struct efi_tm *tm) efi_status status; int error; - mtx_assert(&resettodr_lock, MA_OWNED); + mtx_assert(&atrtc_time_lock, MA_OWNED); error = efi_enter(); if (error != 0) return (error); @@ -503,9 +504,9 @@ efi_set_time(struct efi_tm *tm) if (efi_runtime == NULL) return (ENXIO); - mtx_lock(&resettodr_lock); + mtx_lock(&atrtc_time_lock); error = efi_set_time_locked(tm); - mtx_unlock(&resettodr_lock); + mtx_unlock(&atrtc_time_lock); return (error); } Modified: stable/11/sys/isa/rtc.h ============================================================================== --- stable/11/sys/isa/rtc.h Mon Sep 11 17:01:26 2017 (r323446) +++ stable/11/sys/isa/rtc.h Mon Sep 11 17:32:26 2017 (r323447) @@ -113,6 +113,7 @@ #ifdef _KERNEL extern struct mtx clock_lock; +extern struct mtx atrtc_time_lock; extern int atrtcclock_disable; int rtcin(int reg); void atrtc_restore(void); Modified: stable/11/sys/kern/subr_clock.c ============================================================================== --- stable/11/sys/kern/subr_clock.c Mon Sep 11 17:01:26 2017 (r323446) +++ stable/11/sys/kern/subr_clock.c Mon Sep 11 17:32:26 2017 (r323447) @@ -72,7 +72,7 @@ SYSCTL_PROC(_machdep, OID_AUTO, adjkerntz, CTLTYPE_INT "Local offset from UTC in seconds"); static int ct_debug; -SYSCTL_INT(_debug, OID_AUTO, clocktime, CTLFLAG_RW, +SYSCTL_INT(_debug, OID_AUTO, clocktime, CTLFLAG_RWTUN, &ct_debug, 0, "Enable printing of clocktime debugging"); static int wall_cmos_clock; @@ -97,6 +97,13 @@ static const int month_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; +/* + * Optimization: using a precomputed count of days between POSIX_BASE_YEAR and + * some recent year avoids lots of unnecessary loop iterations in conversion. + * recent_base_days is the number of days before the start of recent_base_year. + */ +static const int recent_base_year = 2017; +static const int recent_base_days = 17167; /* * This inline avoids some unnecessary modulo operations @@ -135,18 +142,27 @@ clock_ct_to_ts(struct clocktime *ct, struct timespec * { int i, year, days; - year = ct->year; - if (ct_debug) { printf("ct_to_ts("); print_ct(ct); printf(")"); } + /* + * Many realtime clocks store the year as 2-digit BCD; pivot on 70 to + * determine century. Some clocks have a "century bit" and drivers do + * year += 100, so interpret values between 70-199 as relative to 1900. + */ + year = ct->year; + if (year < 70) + year += 2000; + else if (year < 200) + year += 1900; + /* Sanity checks. */ if (ct->mon < 1 || ct->mon > 12 || ct->day < 1 || ct->day > days_in_month(year, ct->mon) || - ct->hour > 23 || ct->min > 59 || ct->sec > 59 || + ct->hour > 23 || ct->min > 59 || ct->sec > 59 || year < 1970 || (sizeof(time_t) == 4 && year > 2037)) { /* time_t overflow */ if (ct_debug) printf(" = EINVAL\n"); @@ -157,8 +173,14 @@ clock_ct_to_ts(struct clocktime *ct, struct timespec * * Compute days since start of time * First from years, then from months. */ - days = 0; - for (i = POSIX_BASE_YEAR; i < year; i++) + if (year >= recent_base_year) { + i = recent_base_year; + days = recent_base_days; + } else { + i = POSIX_BASE_YEAR; + days = 0; + } + for (; i < year; i++) days += days_in_year(i); /* Months */ @@ -171,7 +193,7 @@ clock_ct_to_ts(struct clocktime *ct, struct timespec * ts->tv_nsec = ct->nsec; if (ct_debug) - printf(" = %ld.%09ld\n", (long)ts->tv_sec, (long)ts->tv_nsec); + printf(" = %jd.%09ld\n", (intmax_t)ts->tv_sec, ts->tv_nsec); return (0); } @@ -188,8 +210,14 @@ clock_ts_to_ct(struct timespec *ts, struct clocktime * ct->dow = day_of_week(days); - /* Subtract out whole years, counting them in i. */ - for (year = POSIX_BASE_YEAR; days >= days_in_year(year); year++) + /* Subtract out whole years. */ + if (days >= recent_base_days) { + year = recent_base_year; + days -= recent_base_days; + } else { + year = POSIX_BASE_YEAR; + } + for (; days >= days_in_year(year); year++) days -= days_in_year(year); ct->year = year; @@ -209,8 +237,8 @@ clock_ts_to_ct(struct timespec *ts, struct clocktime * ct->sec = rsec; ct->nsec = ts->tv_nsec; if (ct_debug) { - printf("ts_to_ct(%ld.%09ld) = ", - (long)ts->tv_sec, (long)ts->tv_nsec); + printf("ts_to_ct(%jd.%09ld) = ", + (intmax_t)ts->tv_sec, ts->tv_nsec); print_ct(ct); printf("\n"); } Modified: stable/11/sys/kern/subr_rtc.c ============================================================================== --- stable/11/sys/kern/subr_rtc.c Mon Sep 11 17:01:26 2017 (r323446) +++ stable/11/sys/kern/subr_rtc.c Mon Sep 11 17:32:26 2017 (r323447) @@ -63,8 +63,10 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include +#include #include +#include #ifdef FFCLOCK #include #endif @@ -72,116 +74,249 @@ __FBSDID("$FreeBSD$"); #include "clock_if.h" -static device_t clock_dev = NULL; -static long clock_res; -static struct timespec clock_adj; -struct mtx resettodr_lock; -MTX_SYSINIT(resettodr_init, &resettodr_lock, "tod2rl", MTX_DEF); - /* XXX: should be kern. now, it's no longer machdep. */ static int disable_rtc_set; SYSCTL_INT(_machdep, OID_AUTO, disable_rtc_set, CTLFLAG_RW, &disable_rtc_set, 0, "Disallow adjusting time-of-day clock"); +/* + * An instance of a realtime clock. A list of these tracks all the registered + * clocks in the system. + * + * The resadj member is used to apply a "resolution adjustment" equal to half + * the clock's resolution, which is useful mainly on clocks with a whole-second + * resolution. Because the clock truncates the fractional part, adding half the + * resolution performs 4/5 rounding. The same adjustment is applied to the + * times returned from clock_gettime(), because the fraction returned will + * always be zero, but on average the actual fraction at the time of the call + * should be about .5. + */ +struct rtc_instance { + device_t clockdev; + int resolution; + int flags; + u_int schedns; + struct timespec resadj; + struct timeout_task + stask; + LIST_ENTRY(rtc_instance) + rtc_entries; +}; + +/* + * Clocks are updated using a task running on taskqueue_thread. + */ +static void settime_task_func(void *arg, int pending); + +/* + * Registered clocks are kept in a list which is sorted by resolution; the more + * accurate clocks get the first shot at providing the time. + */ +LIST_HEAD(rtc_listhead, rtc_instance); +static struct rtc_listhead rtc_list = LIST_HEAD_INITIALIZER(rtc_list); +static struct sx rtc_list_lock; +SX_SYSINIT(rtc_list_lock_init, &rtc_list_lock, "rtc list"); + +/* + * On the task thread, invoke the clock_settime() method of the clock. Do so + * holding no locks, so that clock drivers are free to do whatever kind of + * locking or sleeping they need to. + */ +static void +settime_task_func(void *arg, int pending) +{ + struct timespec ts; + struct rtc_instance *rtc; + + rtc = arg; + if (!(rtc->flags & CLOCKF_SETTIME_NO_TS)) { + getnanotime(&ts); + if (!(rtc->flags & CLOCKF_SETTIME_NO_ADJ)) { + ts.tv_sec -= utc_offset(); + timespecadd(&ts, &rtc->resadj); + } + } else { + ts.tv_sec = 0; + ts.tv_nsec = 0; + } + CLOCK_SETTIME(rtc->clockdev, &ts); +} + void -clock_register(device_t dev, long res) /* res has units of microseconds */ +clock_register_flags(device_t clockdev, long resolution, int flags) { + struct rtc_instance *rtc, *newrtc; - if (clock_dev != NULL) { - if (clock_res <= res) { - if (bootverbose) - device_printf(dev, "not installed as " - "time-of-day clock: clock %s has higher " - "resolution\n", device_get_name(clock_dev)); - return; + newrtc = malloc(sizeof(*newrtc), M_DEVBUF, M_WAITOK); + newrtc->clockdev = clockdev; + newrtc->resolution = (int)resolution; + newrtc->flags = flags; + newrtc->schedns = 0; + newrtc->resadj.tv_sec = newrtc->resolution / 2 / 1000000; + newrtc->resadj.tv_nsec = newrtc->resolution / 2 % 1000000 * 1000; + TIMEOUT_TASK_INIT(taskqueue_thread, &newrtc->stask, 0, + settime_task_func, newrtc); + + sx_xlock(&rtc_list_lock); + if (LIST_EMPTY(&rtc_list)) { + LIST_INSERT_HEAD(&rtc_list, newrtc, rtc_entries); + } else { + LIST_FOREACH(rtc, &rtc_list, rtc_entries) { + if (rtc->resolution > newrtc->resolution) { + LIST_INSERT_BEFORE(rtc, newrtc, rtc_entries); + break; + } else if (LIST_NEXT(rtc, rtc_entries) == NULL) { + LIST_INSERT_AFTER(rtc, newrtc, rtc_entries); + break; + } } - if (bootverbose) - device_printf(clock_dev, "removed as " - "time-of-day clock: clock %s has higher " - "resolution\n", device_get_name(dev)); } - clock_dev = dev; - clock_res = res; - clock_adj.tv_sec = res / 2 / 1000000; - clock_adj.tv_nsec = res / 2 % 1000000 * 1000; - if (bootverbose) - device_printf(dev, "registered as a time-of-day clock " - "(resolution %ldus, adjustment %jd.%09jds)\n", res, - (intmax_t)clock_adj.tv_sec, (intmax_t)clock_adj.tv_nsec); + sx_xunlock(&rtc_list_lock); + + device_printf(clockdev, + "registered as a time-of-day clock, resolution %d.%6.6ds\n", + newrtc->resolution / 1000000, newrtc->resolution % 1000000); } -/* - * inittodr and settodr derived from the i386 versions written - * by Christoph Robitschko , reintroduced and - * updated by Chris Stenton 8/10/94 - */ +void +clock_register(device_t dev, long res) +{ + clock_register_flags(dev, res, 0); +} + +void +clock_unregister(device_t clockdev) +{ + struct rtc_instance *rtc, *tmp; + + sx_xlock(&rtc_list_lock); + LIST_FOREACH_SAFE(rtc, &rtc_list, rtc_entries, tmp) { + if (rtc->clockdev == clockdev) { + LIST_REMOVE(rtc, rtc_entries); + break; + } + } + sx_xunlock(&rtc_list_lock); + if (rtc != NULL) { + taskqueue_cancel_timeout(taskqueue_thread, &rtc->stask, NULL); + taskqueue_drain_timeout(taskqueue_thread, &rtc->stask); + free(rtc, M_DEVBUF); + } +} + +void +clock_schedule(device_t clockdev, u_int offsetns) +{ + struct rtc_instance *rtc; + + sx_xlock(&rtc_list_lock); + LIST_FOREACH(rtc, &rtc_list, rtc_entries) { + if (rtc->clockdev == clockdev) { + rtc->schedns = offsetns; + break; + } + } + sx_xunlock(&rtc_list_lock); +} + /* - * Initialize the time of day register, based on the time base which is, e.g. - * from a filesystem. + * Initialize the system time. Must be called from a context which does not + * restrict any locking or sleeping that clock drivers may need to do. + * + * First attempt to get the time from a registered realtime clock. The clocks + * are queried in order of resolution until one provides the time. If no clock + * can provide the current time, use the 'base' time provided by the caller, if + * non-zero. The 'base' time is potentially highly inaccurate, such as the last + * known good value of the system clock, or even a filesystem last-updated + * timestamp. It is used to prevent system time from appearing to move + * backwards in logs. */ void inittodr(time_t base) { struct timespec ts; + struct rtc_instance *rtc; int error; - if (clock_dev == NULL) { - printf("warning: no time-of-day clock registered, system time " - "will not be set accurately\n"); - goto wrong_time; + error = ENXIO; + sx_xlock(&rtc_list_lock); + LIST_FOREACH(rtc, &rtc_list, rtc_entries) { + if ((error = CLOCK_GETTIME(rtc->clockdev, &ts)) != 0) + continue; + if (ts.tv_sec < 0 || ts.tv_nsec < 0) { + error = EINVAL; + continue; + } + if (!(rtc->flags & CLOCKF_GETTIME_NO_ADJ)) { + timespecadd(&ts, &rtc->resadj); + ts.tv_sec += utc_offset(); + } + if (bootverbose) + device_printf(rtc->clockdev, + "providing initial system time\n"); + break; } - /* XXX: We should poll all registered RTCs in case of failure */ - mtx_lock(&resettodr_lock); - error = CLOCK_GETTIME(clock_dev, &ts); - mtx_unlock(&resettodr_lock); - if (error != 0 && error != EINVAL) { - printf("warning: clock_gettime failed (%d), the system time " - "will not be set accurately\n", error); - goto wrong_time; + sx_xunlock(&rtc_list_lock); + + /* + * Do not report errors from each clock; it is expected that some clocks + * cannot provide results in some situations. Only report problems when + * no clocks could provide the time. + */ + if (error != 0) { + switch (error) { + case ENXIO: + printf("Warning: no time-of-day clock registered, "); + break; + case EINVAL: + printf("Warning: bad time from time-of-day clock, "); + break; + default: + printf("Error reading time-of-day clock (%d), ", error); + break; + } + printf("system time will not be set accurately\n"); + ts.tv_sec = (base > 0) ? base : -1; + ts.tv_nsec = 0; } - if (error == EINVAL || ts.tv_sec < 0) { - printf("Invalid time in real time clock.\n" - "Check and reset the date immediately!\n"); - goto wrong_time; - } - ts.tv_sec += utc_offset(); - timespecadd(&ts, &clock_adj); - tc_setclock(&ts); + if (ts.tv_sec >= 0) { + tc_setclock(&ts); #ifdef FFCLOCK - ffclock_reset_clock(&ts); + ffclock_reset_clock(&ts); #endif - return; - -wrong_time: - if (base > 0) { - ts.tv_sec = base; - ts.tv_nsec = 0; - tc_setclock(&ts); } } /* - * Write system time back to RTC + * Write system time back to all registered clocks, unless disabled by admin. + * This can be called from a context that restricts locking and/or sleeping; the + * actual updating is done asynchronously on a task thread. */ void resettodr(void) { - struct timespec ts; - int error; + struct timespec now; + struct rtc_instance *rtc; + sbintime_t sbt; + long waitns; - if (disable_rtc_set || clock_dev == NULL) + if (disable_rtc_set) return; - getnanotime(&ts); - timespecadd(&ts, &clock_adj); - ts.tv_sec -= utc_offset(); - /* XXX: We should really set all registered RTCs */ - mtx_lock(&resettodr_lock); - error = CLOCK_SETTIME(clock_dev, &ts); - mtx_unlock(&resettodr_lock); - if (error != 0) - printf("warning: clock_settime failed (%d), time-of-day clock " - "not adjusted to system time\n", error); + sx_xlock(&rtc_list_lock); + LIST_FOREACH(rtc, &rtc_list, rtc_entries) { + if (rtc->schedns != 0) { + getnanotime(&now); + waitns = rtc->schedns - now.tv_nsec; + if (waitns < 0) + waitns += 1000000000; + sbt = nstosbt(waitns); + } else + sbt = 0; + taskqueue_enqueue_timeout_sbt(taskqueue_thread, + &rtc->stask, -sbt, 0, C_PREL(31)); + } + sx_xunlock(&rtc_list_lock); } Modified: stable/11/sys/kern/subr_taskqueue.c ============================================================================== --- stable/11/sys/kern/subr_taskqueue.c Mon Sep 11 17:01:26 2017 (r323446) +++ stable/11/sys/kern/subr_taskqueue.c Mon Sep 11 17:32:26 2017 (r323447) @@ -289,8 +289,8 @@ taskqueue_timeout_func(void *arg) } int -taskqueue_enqueue_timeout(struct taskqueue *queue, - struct timeout_task *timeout_task, int ticks) +taskqueue_enqueue_timeout_sbt(struct taskqueue *queue, + struct timeout_task *timeout_task, sbintime_t sbt, sbintime_t pr, int flags) { int res; @@ -304,7 +304,7 @@ taskqueue_enqueue_timeout(struct taskqueue *queue, /* Do nothing */ TQ_UNLOCK(queue); res = -1; - } else if (ticks == 0) { + } else if (sbt == 0) { taskqueue_enqueue_locked(queue, &timeout_task->t); /* The lock is released inside. */ } else { @@ -313,16 +313,25 @@ taskqueue_enqueue_timeout(struct taskqueue *queue, } else { queue->tq_callouts++; timeout_task->f |= DT_CALLOUT_ARMED; - if (ticks < 0) - ticks = -ticks; /* Ignore overflow. */ + if (sbt < 0) + sbt = -sbt; /* Ignore overflow. */ } - if (ticks > 0) { - callout_reset(&timeout_task->c, ticks, - taskqueue_timeout_func, timeout_task); + if (sbt > 0) { + callout_reset_sbt(&timeout_task->c, sbt, pr, + taskqueue_timeout_func, timeout_task, flags); } TQ_UNLOCK(queue); } return (res); +} + +int +taskqueue_enqueue_timeout(struct taskqueue *queue, + struct timeout_task *ttask, int ticks) +{ + + return (taskqueue_enqueue_timeout_sbt(queue, ttask, ticks * tick_sbt, + 0, 0)); } static void Modified: stable/11/sys/sys/clock.h ============================================================================== --- stable/11/sys/sys/clock.h Mon Sep 11 17:01:26 2017 (r323446) +++ stable/11/sys/sys/clock.h Mon Sep 11 17:32:26 2017 (r323447) @@ -54,7 +54,6 @@ */ extern int tz_minuteswest; extern int tz_dsttime; -extern struct mtx resettodr_lock; int utc_offset(void); @@ -76,7 +75,42 @@ struct clocktime { int clock_ct_to_ts(struct clocktime *, struct timespec *); void clock_ts_to_ct(struct timespec *, struct clocktime *); -void clock_register(device_t, long); + +/* + * Time-of-day clock functions and flags. These functions might sleep. + * + * clock_register and clock_unregister() do what they say. Upon return from + * unregister, the clock's methods are not running and will not be called again. + * + * clock_schedule() requests that a registered clock's clock_settime() calls + * happen at the given offset into the second. The default is 0, meaning no + * specific scheduling. To schedule the call as soon after top-of-second as + * possible, specify 1. Each clock has its own schedule, but taskqueue_thread + * is shared by many tasks; the timing of the call is not guaranteed. + * + * Flags: + * + * CLOCKF_SETTIME_NO_TS + * Do not pass a timespec to clock_settime(), the driver obtains its own time + * and applies its own adjustments (this flag implies CLOCKF_SETTIME_NO_ADJ). + * + * CLOCKF_SETTIME_NO_ADJ + * Do not apply utc offset and resolution/accuracy adjustments to the value + * passed to clock_settime(), the driver applies them itself. + * + * CLOCKF_GETTIME_NO_ADJ + * Do not apply utc offset and resolution/accuracy adjustments to the value + * returned from clock_gettime(), the driver has already applied them. + */ + +#define CLOCKF_SETTIME_NO_TS 0x00000001 +#define CLOCKF_SETTIME_NO_ADJ 0x00000002 +#define CLOCKF_GETTIME_NO_ADJ 0x00000004 + +void clock_register(device_t _clockdev, long _resolution_us); +void clock_register_flags(device_t _clockdev, long _resolution_us, int _flags); +void clock_schedule(device_t clockdev, u_int _offsetns); +void clock_unregister(device_t _clockdev); /* * BCD to decimal and decimal to BCD. Modified: stable/11/sys/sys/taskqueue.h ============================================================================== --- stable/11/sys/sys/taskqueue.h Mon Sep 11 17:01:26 2017 (r323446) +++ stable/11/sys/sys/taskqueue.h Mon Sep 11 17:32:26 2017 (r323447) @@ -79,6 +79,9 @@ int taskqueue_start_threads_cpuset(struct taskqueue ** int taskqueue_enqueue(struct taskqueue *queue, struct task *task); int taskqueue_enqueue_timeout(struct taskqueue *queue, struct timeout_task *timeout_task, int ticks); +int taskqueue_enqueue_timeout_sbt(struct taskqueue *queue, + struct timeout_task *timeout_task, sbintime_t sbt, sbintime_t pr, + int flags); int taskqueue_poll_is_busy(struct taskqueue *queue, struct task *task); int taskqueue_cancel(struct taskqueue *queue, struct task *task, u_int *pendp); Modified: stable/11/sys/x86/isa/atrtc.c ============================================================================== --- stable/11/sys/x86/isa/atrtc.c Mon Sep 11 17:01:26 2017 (r323446) +++ stable/11/sys/x86/isa/atrtc.c Mon Sep 11 17:32:26 2017 (r323447) @@ -53,9 +53,17 @@ __FBSDID("$FreeBSD$"); #include #include "clock_if.h" +/* + * clock_lock protects low-level access to individual hardware registers. + * atrtc_time_lock protects the entire sequence of accessing multiple registers + * to read or write the date and time. + */ #define RTC_LOCK do { if (!kdb_active) mtx_lock_spin(&clock_lock); } while (0) #define RTC_UNLOCK do { if (!kdb_active) mtx_unlock_spin(&clock_lock); } while (0) +struct mtx atrtc_time_lock; +MTX_SYSINIT(atrtc_lock_init, &atrtc_time_lock, "atrtc", MTX_DEF); + int atrtcclock_disable = 0; static int rtc_reg = -1; @@ -158,6 +166,8 @@ atrtc_set(struct timespec *ts) clock_ts_to_ct(ts, &ct); + mtx_lock(&atrtc_time_lock); + /* Disable RTC updates and interrupts. */ writertc(RTC_STATUSB, RTCSB_HALT | RTCSB_24HR); @@ -176,6 +186,8 @@ atrtc_set(struct timespec *ts) /* Re-enable RTC updates and interrupts. */ writertc(RTC_STATUSB, rtc_statusb); rtcin(RTC_INTR); + + mtx_unlock(&atrtc_time_lock); } /********************************************************************** @@ -347,6 +359,7 @@ atrtc_gettime(device_t dev, struct timespec *ts) * to make sure that no more than 240us pass after we start reading, * and try again if so. */ + mtx_lock(&atrtc_time_lock); while (rtcin(RTC_STATUSA) & RTCSA_TUP) continue; critical_enter(); @@ -364,6 +377,7 @@ atrtc_gettime(device_t dev, struct timespec *ts) ct.year += (ct.year < 80 ? 2000 : 1900); #endif critical_exit(); + mtx_unlock(&atrtc_time_lock); /* Set dow = -1 because some clocks don't set it correctly. */ ct.dow = -1; return (clock_ct_to_ts(&ct, ts)); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 18:30:51 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B96DBE1BD50; Mon, 11 Sep 2017 18:30:51 +0000 (UTC) (envelope-from mav@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 mx1.freebsd.org (Postfix) with ESMTPS id 939696C5AB; Mon, 11 Sep 2017 18:30:51 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BIUoNO067540; Mon, 11 Sep 2017 18:30:50 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BIUoYo067539; Mon, 11 Sep 2017 18:30:50 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201709111830.v8BIUoYo067539@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 11 Sep 2017 18:30:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323451 - stable/11/sys/dev/ntb/ntb_hw X-SVN-Group: stable-11 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/11/sys/dev/ntb/ntb_hw X-SVN-Commit-Revision: 323451 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 18:30:51 -0000 Author: mav Date: Mon Sep 11 18:30:50 2017 New Revision: 323451 URL: https://svnweb.freebsd.org/changeset/base/323451 Log: MFC r322980: Fix fake interrupt when set doorbell is unmasked. Since the doorbell bit is already set when interrupt handler is called, the event was not propagated to upper layer. It was working normally because present code was not using masking actively, but that is going to change. Modified: stable/11/sys/dev/ntb/ntb_hw/ntb_hw.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/ntb/ntb_hw/ntb_hw.c ============================================================================== --- stable/11/sys/dev/ntb/ntb_hw/ntb_hw.c Mon Sep 11 18:29:09 2017 (r323450) +++ stable/11/sys/dev/ntb/ntb_hw/ntb_hw.c Mon Sep 11 18:30:50 2017 (r323451) @@ -253,7 +253,8 @@ struct ntb_softc { uint64_t db_valid_mask; uint64_t db_link_mask; uint64_t db_mask; - uint64_t fake_db_bell; /* NTB_SB01BASE_LOCKUP*/ + uint64_t fake_db; /* NTB_SB01BASE_LOCKUP*/ + uint64_t force_db; /* NTB_SB01BASE_LOCKUP*/ int last_ts; /* ticks @ last irq */ @@ -1206,10 +1207,11 @@ intel_ntb_db_clear_mask(device_t dev, uint64_t bits) (uintmax_t)ntb->db_valid_mask)); DB_MASK_LOCK(ntb); - ibits = ntb->fake_db_bell & ntb->db_mask & bits; + ibits = ntb->fake_db & ntb->db_mask & bits; ntb->db_mask &= ~bits; if (HAS_FEATURE(ntb, NTB_SB01BASE_LOCKUP)) { /* Simulate fake interrupts if unmasked DB bits are set. */ + ntb->force_db |= ibits; for (i = 0; i < XEON_NONLINK_DB_MSIX_BITS; i++) { if ((ibits & intel_ntb_db_vector_mask(dev, i)) != 0) swi_sched(ntb->int_info[i].tag, 0); @@ -1226,7 +1228,7 @@ intel_ntb_db_read(device_t dev) struct ntb_softc *ntb = device_get_softc(dev); if (HAS_FEATURE(ntb, NTB_SB01BASE_LOCKUP)) - return (ntb->fake_db_bell); + return (ntb->fake_db); return (db_ioread(ntb, ntb->self_reg->db_bell)); } @@ -1243,7 +1245,7 @@ intel_ntb_db_clear(device_t dev, uint64_t bits) if (HAS_FEATURE(ntb, NTB_SB01BASE_LOCKUP)) { DB_MASK_LOCK(ntb); - ntb->fake_db_bell &= ~bits; + ntb->fake_db &= ~bits; DB_MASK_UNLOCK(ntb); return; } @@ -1291,11 +1293,16 @@ intel_ntb_interrupt(struct ntb_softc *ntb, uint32_t ve (vec_mask & ntb->db_link_mask) == 0) { DB_MASK_LOCK(ntb); - /* Do not report same DB events again if not cleared yet. */ - vec_mask &= ~ntb->fake_db_bell; + /* + * Do not report same DB events again if not cleared yet, + * unless the mask was just cleared for them and this + * interrupt handler call can be the consequence of it. + */ + vec_mask &= ~ntb->fake_db | ntb->force_db; + ntb->force_db &= ~vec_mask; /* Update our internal doorbell register. */ - ntb->fake_db_bell |= vec_mask; + ntb->fake_db |= vec_mask; /* Do not report masked DB events. */ vec_mask &= ~ntb->db_mask; @@ -1512,7 +1519,7 @@ intel_ntb_xeon_init_dev(struct ntb_softc *ntb) ntb->xlat_reg = &xeon_sec_xlat; if (HAS_FEATURE(ntb, NTB_SB01BASE_LOCKUP)) { - ntb->fake_db_bell = 0; + ntb->force_db = ntb->fake_db = 0; ntb->msix_mw_idx = (ntb->mw_count + g_ntb_msix_idx) % ntb->mw_count; intel_ntb_printf(2, "Setting up MSIX mw idx %d means %u\n", From owner-svn-src-stable-11@freebsd.org Mon Sep 11 18:31:52 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5A340E1BE11; Mon, 11 Sep 2017 18:31:52 +0000 (UTC) (envelope-from mav@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 mx1.freebsd.org (Postfix) with ESMTPS id 260586C877; Mon, 11 Sep 2017 18:31:52 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BIVpwj069761; Mon, 11 Sep 2017 18:31:51 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BIVpjq069760; Mon, 11 Sep 2017 18:31:51 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201709111831.v8BIVpjq069760@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 11 Sep 2017 18:31:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323452 - stable/11/sys/dev/ntb X-SVN-Group: stable-11 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/11/sys/dev/ntb X-SVN-Commit-Revision: 323452 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 18:31:52 -0000 Author: mav Date: Mon Sep 11 18:31:51 2017 New Revision: 323452 URL: https://svnweb.freebsd.org/changeset/base/323452 Log: MFC r322981: Mask doorbells while processing them. This fixes interrupt storms on hardware using legacy level-triggered interrupts, since doorbell processing could take time after interrupt handler completion, that triggered extra interrupts in a loop. Modified: stable/11/sys/dev/ntb/ntb_transport.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/ntb/ntb_transport.c ============================================================================== --- stable/11/sys/dev/ntb/ntb_transport.c Mon Sep 11 18:30:50 2017 (r323451) +++ stable/11/sys/dev/ntb/ntb_transport.c Mon Sep 11 18:31:51 2017 (r323452) @@ -835,6 +835,7 @@ static void ntb_transport_rxc_db(void *arg, int pending __unused) { struct ntb_transport_qp *qp = arg; + uint64_t qp_mask = 1ull << qp->qp_num; int rc; CTR0(KTR_NTB, "RX: transport_rx"); @@ -843,11 +844,13 @@ again: ; CTR1(KTR_NTB, "RX: process_rxc returned %d", rc); - if ((ntb_db_read(qp->dev) & (1ull << qp->qp_num)) != 0) { + if ((ntb_db_read(qp->dev) & qp_mask) != 0) { /* If db is set, clear it and check queue once more. */ - ntb_db_clear(qp->dev, 1ull << qp->qp_num); + ntb_db_clear(qp->dev, qp_mask); goto again; } + if (qp->link_is_up) + ntb_db_clear_mask(qp->dev, qp_mask); } static int @@ -1009,6 +1012,8 @@ ntb_transport_doorbell_callback(void *data, uint32_t v vec_mask &= nt->qp_bitmap; if ((vec_mask & (vec_mask - 1)) != 0) vec_mask &= ntb_db_read(nt->dev); + if (vec_mask != 0) + ntb_db_set_mask(nt->dev, vec_mask); while (vec_mask != 0) { qp_num = ffsll(vec_mask) - 1; From owner-svn-src-stable-11@freebsd.org Mon Sep 11 18:48:11 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A330CE1CAFA; Mon, 11 Sep 2017 18:48:11 +0000 (UTC) (envelope-from mav@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 mx1.freebsd.org (Postfix) with ESMTPS id 4C76B6D1E8; Mon, 11 Sep 2017 18:48:11 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BImA5F075705; Mon, 11 Sep 2017 18:48:10 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BIm9xr075694; Mon, 11 Sep 2017 18:48:09 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201709111848.v8BIm9xr075694@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 11 Sep 2017 18:48:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323453 - in stable/11: share/man/man4 sys/amd64/conf sys/conf sys/dev/ntb/ntb_hw sys/i386/conf sys/modules/ntb sys/modules/ntb/ntb_hw sys/modules/ntb/ntb_hw_intel sys/modules/ntb/ntb_h... X-SVN-Group: stable-11 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in stable/11: share/man/man4 sys/amd64/conf sys/conf sys/dev/ntb/ntb_hw sys/i386/conf sys/modules/ntb sys/modules/ntb/ntb_hw sys/modules/ntb/ntb_hw_intel sys/modules/ntb/ntb_hw_plx X-SVN-Commit-Revision: 323453 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 18:48:11 -0000 Author: mav Date: Mon Sep 11 18:48:09 2017 New Revision: 323453 URL: https://svnweb.freebsd.org/changeset/base/323453 Log: MFC r323032, r323053, r323058, r323059, r323084, r323114, r323127: Add NTB driver for PLX/Avago/Broadcom PCIe switches. This driver supports both NTB-to-NTB and NTB-to-Root Port modes (though the second with predictable complications on hot-plug and reboot events). I tested it with PEX 8717 and PEX 8733 chips, but expect it should work with many other compatible ones too. It supports up to two NT bridges per chip, each of which can have up to 2 64-bit or 4 32-bit memory windows, 6 or 12 scratchpad registers and 16 doorbells. There are also 4 DMA engines in those chips, but they are not yet supported. While there, rename Intel NTB driver from generic ntb_hw(4) to more specific ntb_hw_intel(4), so now it is on par with this new ntb_hw_plx(4) driver and alike to Linux naming. Added: stable/11/share/man/man4/ntb.4 - copied, changed from r323032, head/share/man/man4/ntb.4 stable/11/share/man/man4/ntb_hw_intel.4 - copied unchanged from r323032, head/share/man/man4/ntb_hw_intel.4 stable/11/share/man/man4/ntb_hw_plx.4 - copied unchanged from r323032, head/share/man/man4/ntb_hw_plx.4 stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c - copied unchanged from r323032, head/sys/dev/ntb/ntb_hw/ntb_hw_intel.c stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.h - copied unchanged from r323032, head/sys/dev/ntb/ntb_hw/ntb_hw_intel.h stable/11/sys/dev/ntb/ntb_hw/ntb_hw_plx.c - copied, changed from r323032, head/sys/dev/ntb/ntb_hw/ntb_hw_plx.c stable/11/sys/modules/ntb/ntb_hw_intel/ - copied from r323032, head/sys/modules/ntb/ntb_hw_intel/ stable/11/sys/modules/ntb/ntb_hw_plx/ - copied from r323032, head/sys/modules/ntb/ntb_hw_plx/ Deleted: stable/11/share/man/man4/ntb_hw.4 stable/11/sys/dev/ntb/ntb_hw/ntb_hw.c stable/11/sys/dev/ntb/ntb_hw/ntb_regs.h stable/11/sys/modules/ntb/ntb_hw/ Modified: stable/11/share/man/man4/Makefile stable/11/share/man/man4/if_ntb.4 stable/11/share/man/man4/ntb_transport.4 stable/11/sys/amd64/conf/NOTES stable/11/sys/conf/files.amd64 stable/11/sys/conf/files.i386 stable/11/sys/i386/conf/NOTES stable/11/sys/modules/ntb/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/share/man/man4/Makefile ============================================================================== --- stable/11/share/man/man4/Makefile Mon Sep 11 18:31:51 2017 (r323452) +++ stable/11/share/man/man4/Makefile Mon Sep 11 18:48:09 2017 (r323453) @@ -383,7 +383,9 @@ MAN= aac.4 \ ng_vlan.4 \ nmdm.4 \ nsp.4 \ - ${_ntb_hw.4} \ + ${_ntb.4} \ + ${_ntb_hw_intel.4} \ + ${_ntb_hw_plx.4} \ ${_ntb_transport.4} \ ${_if_ntb.4} \ null.4 \ @@ -707,7 +709,6 @@ MLINKS+=netintro.4 net.4 \ netintro.4 networking.4 MLINKS+=${_nfe.4} ${_if_nfe.4} MLINKS+=nge.4 if_nge.4 -MLINKS+=${_ntb_hw.4} ${_ntb.4} MLINKS+=${_nxge.4} ${_if_nxge.4} MLINKS+=ow.4 onewire.4 MLINKS+=patm.4 if_patm.4 @@ -853,7 +854,8 @@ _xnb.4= xnb.4 _if_ntb.4= if_ntb.4 _ioat.4= ioat.4 _ntb.4= ntb.4 -_ntb_hw.4= ntb_hw.4 +_ntb_hw_intel.4= ntb_hw_intel.4 +_ntb_hw_plx.4= ntb_hw_plx.4 _ntb_transport.4=ntb_transport.4 _qlxge.4= qlxge.4 _qlxgb.4= qlxgb.4 Modified: stable/11/share/man/man4/if_ntb.4 ============================================================================== --- stable/11/share/man/man4/if_ntb.4 Mon Sep 11 18:31:51 2017 (r323452) +++ stable/11/share/man/man4/if_ntb.4 Mon Sep 11 18:48:09 2017 (r323453) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 29, 2016 +.Dd September 2, 2017 .Dt IF_NTB 4 .Os .Sh NAME @@ -35,6 +35,8 @@ To compile this driver into your kernel, place the following lines in your kernel configuration file: .Bd -ragged -offset indent +.Cd "device ntb" +.Cd "device ntb_transport" .Cd "device if_ntb" .Ed .Pp @@ -48,7 +50,7 @@ The following tunables are settable from the .Xr loader 8 : .Bl -ohang .It Va hw.if_ntb.num_queues -Number of transport queues to use per interface. +Limits maximal number of queues per interface. Default is unlimited. .El .Sh DESCRIPTION @@ -56,12 +58,10 @@ The .Nm driver attaches on top of the .Xr ntb_transport 4 -driver to utilize its resources to create virtual Ethernet interface between -the systems. -Interface capabilities depend on the underlying transport. -Typical MTU is about 64KB to reduce overhead. -By default one queue is used, but more may be configured. -The MAC address for interface is randomly generated. +driver to utilize one or more of its packet queues to create virtual +Ethernet network interface between the systems. +Typical MTU for the interface is about 64KB to reduce overhead. +Default MAC address for the interface is randomly generated. .Pp The .Nm Copied and modified: stable/11/share/man/man4/ntb.4 (from r323032, head/share/man/man4/ntb.4) ============================================================================== --- head/share/man/man4/ntb.4 Wed Aug 30 21:16:32 2017 (r323032, copy source) +++ stable/11/share/man/man4/ntb.4 Mon Sep 11 18:48:09 2017 (r323453) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 30, 2017 +.Dd September 2, 2017 .Dt NTB 4 .Os .Sh NAME @@ -51,19 +51,19 @@ The following tunables are settable from the Driver debug level. The default value is 0, higher means more verbose. .It Va hint.ntb_hw. Ns Ar X Ns Va .config -Configures NTB resources split between several consumer devices. -Configuration of multiple consumer devices separated by commas. -Each device can be configured as: "[][:[:[:]]]", where: +Configures a set of NTB functions, separated by commas, +and their resource allocation. +Each function can be configured as: "[][:[:[:]]]", where: .Va name -is a name of the driver which should attach the device (empty means any), +is a name of the driver to attach (empty means any), .Va mw is a number of memory windows to allocate (empty means all available), .Va spad is a number of scratchpad registers to allocate (empty means all available), .Va db is a number of doorbells to allocate (empty means all available). -The default configuration is empty string, which means single device -with all available resources allowing any driver attachment. +The default configuration is empty string, which means single function +with all available resources, allowing any driver to attach. .El .Sh DESCRIPTION Non-Transparent Bridges allow to connect two computer systems with PCIe @@ -72,7 +72,7 @@ scratchpad registers and interrupts. The .Nm subsystem uses those resources provided in generic way by hardware drivers -and splits them between multiple consumer drivers, according to specified +and splits them between several functions, according to specified configuration. .Sh SEE ALSO .Xr if_ntb 4 , Copied: stable/11/share/man/man4/ntb_hw_intel.4 (from r323032, head/share/man/man4/ntb_hw_intel.4) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/share/man/man4/ntb_hw_intel.4 Mon Sep 11 18:48:09 2017 (r323453, copy of r323032, head/share/man/man4/ntb_hw_intel.4) @@ -0,0 +1,97 @@ +.\" +.\" Copyright (c) 2016-2017 Alexander Motin +.\" All rights reserved. +.\" +.\" 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 August 30, 2017 +.Dt NTB_HW_INTEL 4 +.Os +.Sh NAME +.Nm ntb_hw_intel +.Nd Intel(R) Non-Transparent Bridge driver +.Sh SYNOPSIS +To compile this driver into your kernel, +place the following lines in your kernel configuration file: +.Bd -ragged -offset indent +.Cd "device ntb" +.Cd "device ntb_hw_intel" +.Ed +.Pp +Or, to load the driver as a module at boot, place the following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +ntb_hw_intel_load="YES" +.Ed +.Sh DESCRIPTION +The +.Nm ntb_hw_intel +driver provides support for the Non-Transparent Bridge (NTB) hardware in +Intel Xeon E3/E5 and S1200 processor families, which allow one of their PCIe +ports to be switched from transparent to non-transparent bridge mode. +In this mode bridge looks not as a PCI bridge, but as PCI endpoint device. +The driver hides hardware details, exposing memory windows, scratchpads +and doorbells of the other side via hardware independent KPI to +.Xr ntb 4 +subsystem. +.Pp +The hardware provides 2 or 3 memory windows to the other system's memory, +16 scratchpad registers and 14 or 34 doorbells to interrupt the other system. +On Xeon processors one of memory windows is typically consumed by the driver +itself to workaround multiple hardware erratas. +.Sh CONFIGURATION +The NTB configuration should be set by BIOS. +It includes enabling NTB, choosing between NTB-to-NTB (back-to-back) or +NTB-to-Root Port mode, +enabling split BAR mode (one of two 64-bit BARs can be split into two 32-bit +ones) and configuring BAR sizes in bits (from 12 to 29/39) for both NTB sides. +.Pp +The recommended configuration is NTB-to-NTB mode, split bar is enabled and +all BAR sizes are set to 20 (1 MiB). +This needs to be done on both systems. +.Sh SEE ALSO +.Xr if_ntb 4 , +.Xr ntb_transport 4 , +.Xr ntb 4 , +.Sh AUTHORS +.An -nosplit +The +.Nm +driver was developed by Intel and originally written by +.An Carl Delsey Aq Mt carl@FreeBSD.org . +Later improvements were done by +.An Conrad E. Meyer Aq Mt cem@FreeBSD.org +and +.An Alexander Motin Aq Mt mav@FreeBSD.org . +.Sh BUGS +NTB-to-Root Port mode is not yet supported, but it doesn't look very useful. +.Pp +On Xeon v2/v3/v4 processors split BAR mode should be enabled to allow +SB01BASE_LOCKUP errata workaround to be applied by the driver. +.Pp +There is no way to protect your system from malicious behavior on the other +system once the link is brought up. +Anyone with root or kernel access on the other system can read or write to +any location on your system. +In other words, only connect two systems that completely trust each other. Copied: stable/11/share/man/man4/ntb_hw_plx.4 (from r323032, head/share/man/man4/ntb_hw_plx.4) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/share/man/man4/ntb_hw_plx.4 Mon Sep 11 18:48:09 2017 (r323453, copy of r323032, head/share/man/man4/ntb_hw_plx.4) @@ -0,0 +1,118 @@ +.\" +.\" Copyright (c) 2017 Alexander Motin +.\" All rights reserved. +.\" +.\" 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 August 30, 2017 +.Dt NTB_HW_PLX 4 +.Os +.Sh NAME +.Nm ntb_hw_plx +.Nd PLX/Avago/Broadcom Non-Transparent Bridge driver +.Sh SYNOPSIS +To compile this driver into your kernel, +place the following lines in your kernel configuration file: +.Bd -ragged -offset indent +.Cd "device ntb" +.Cd "device ntb_hw_plx" +.Ed +.Pp +Or, to load the driver as a module at boot, place the following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +ntb_hw_plx_load="YES" +.Ed +.Pp +The following tunables are settable from the +.Xr loader 8 : +.Bl -ohang +.It Va hint.ntb_hw. Ns Ar X Ns Va .b2b +Being set to 1 (default) tells the driver attached to Virtual Interface of the +NTB that it works in NTB-to-NTB (back-to-back) mode, 0 -- NTB-to-Root Port. +Driver attached to Link Interface (visible from Root Port side) switches to +NTB-to-Root Port mode automatically, but one attached to Virtual Interface +can't detect what is on the other side and require external knowledge. +.El +.Sh DESCRIPTION +The +.Nm +driver provides support for the Non-Transparent Bridge (NTB) hardware in +PLX PCIe bridge chips, which allow up to two of their PCIe ports to be +switched from transparent to non-transparent bridge mode. +In this mode bridge looks not as a PCI bridge, but as PCI endpoint device. +The driver hides hardware details, exposing memory windows, scratchpads +and doorbells of the other side via hardware independent KPI to +.Xr ntb 4 +subsystem. +.Pp +Each PLX NTB provides up to 2 64-bit or 4 32-bit memory windows to the +other system's memory, 6 or 12 scratchpad registers and 16 doorbells to +interrupt the other system. +In NTB-to-NTB mode one of memory windows (or half of it, if bigger then 1MB) +is consumed by the driver itself to access scratchpad and doorbell registers +of the other side. +.Sh HARDWARE +The following PLX/Avago/Broadcom chips are supported by the +.Nm +driver: +.Pp +.Bl -bullet -compact +.It +PEX 8713 +.It +PEX 8717 +.It +PEX 8725 +.It +PEX 8733 +.It +PEX 8749 +.El +.Pp +, but it may also work with other compatible ones. +.Sh CONFIGURATION +The basic chip configuration should be done by serial EEPROM or via i2c. +It includes enabling NTB on one or both sides (choosing between NTB-to-NTB +(back-to-back) and NTB-to-Root Port modes) and configuring BARs sizes. +.Pp +The recommended mode is NTB-to-NTB mode, since while NTB-to-Root Port is +generally supported by the driver, it require PCI hotplug handling on the +Root Port, that may be difficult or cause different kinds of problems. +.Sh SEE ALSO +.Xr if_ntb 4 , +.Xr ntb_transport 4 , +.Xr ntb 4 , +.Sh AUTHORS +.An -nosplit +The +.Nm +driver was written by +.An Alexander Motin Aq Mt mav@FreeBSD.org . +.Sh BUGS +There is no way to protect your system from malicious behavior on the other +system once the link is brought up. +Anyone with root or kernel access on the other system can read or write to +any location on your system. +In other words, only connect two systems that completely trust each other. Modified: stable/11/share/man/man4/ntb_transport.4 ============================================================================== --- stable/11/share/man/man4/ntb_transport.4 Mon Sep 11 18:31:51 2017 (r323452) +++ stable/11/share/man/man4/ntb_transport.4 Mon Sep 11 18:48:09 2017 (r323453) @@ -1,5 +1,5 @@ .\" -.\" Copyright (c) 2016 Alexander Motin +.\" Copyright (c) 2016-2017 Alexander Motin .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -25,14 +25,21 @@ .\" .\" $FreeBSD$ .\" -.Dd July 29, 2016 +.Dd September 2, 2017 .Dt NTB_TRANSPORT 4 .Os .Sh NAME .Nm ntb_transport .Nd Packet-oriented transport for Non-Transparent Bridges .Sh SYNOPSIS -To load the driver as a module at boot, place the following line in +To compile this driver into your kernel, +place the following lines in your kernel configuration file: +.Bd -ragged -offset indent +.Cd "device ntb" +.Cd "device ntb_transport" +.Ed +.Pp +Or, to load the driver as a module at boot, place the following line in .Xr loader.conf 5 : .Bd -literal -offset indent ntb_transport_load="YES" @@ -45,28 +52,44 @@ The following tunables are settable from the Driver debug level. The default value is 0, higher means more verbose. .It Va hint.ntb_transport. Ns Ar X Ns Va .config -Configures queues allocation for consumer devices, separated by commas. -Each device can be configured as: "[:]", where: +Configures a set of the transport consumers, separated by commas. +Each consumer can be configured as: "[][:]", where: .Va name -is a name of the driver which should attach the device (empty means any), +is a name of the driver to attach (empty means any), .Va queues -is a number of queues to allocate (empty means automatic), -The default configuration is empty string, which means single device -with one queue per memory window allowing any driver attachment. +is a number of queues to allocate (empty means automatic). +The default configuration is empty string, which means single consumer +with one queue per memory window, allowing any driver to attach. .El .Sh DESCRIPTION The .Nm driver attaches on top of the .Nm ntb -driver to utilize its resources to create set of bidirectional queues, +driver to utilize its resources to create a set of bidirectional queues, delivering packets between the systems. -The primary purpose of this is to be used by +The primary purpose of this driver is to be used by .Nm if_ntb network interface, but other consumers may also be developed using KPI. +.Pp +Each +.Nm +require from underlying +.Nm ntb +instance: +.Bl -bullet -compact +.It +1 or more memory windows; +.It +6 scratchpads, plus 2 more for each additional memory window; +.It +1 doorbell for each memory window or configured queue. +.El .Sh SEE ALSO .Xr if_ntb 4 , -.Xr ntb_hw 4 +.Xr ntb 4 , +.Xr ntb_hw_intel 4 , +.Xr ntb_hw_plx 4 .Sh AUTHORS .An -nosplit The Modified: stable/11/sys/amd64/conf/NOTES ============================================================================== --- stable/11/sys/amd64/conf/NOTES Mon Sep 11 18:31:51 2017 (r323452) +++ stable/11/sys/amd64/conf/NOTES Mon Sep 11 18:48:09 2017 (r323453) @@ -402,9 +402,14 @@ device iwn6000g2bfw device iwn6050fw device wpifw -# Intel Non-Transparent Bridge (NTB) hardware -device ntb_hw # Hardware Abstraction Layer for the NTB -device if_ntb # Simulated ethernet device using the NTB +# +# Non-Transparent Bridge (NTB) drivers +# +device if_ntb # Virtual NTB network interface +device ntb_transport # NTB packet transport driver +device ntb # NTB hardware interface +device ntb_hw_intel # Intel NTB hardware driver +device ntb_hw_plx # PLX NTB hardware driver # #XXX this stores pointers in a 32bit field that is defined by the hardware Modified: stable/11/sys/conf/files.amd64 ============================================================================== --- stable/11/sys/conf/files.amd64 Mon Sep 11 18:31:51 2017 (r323452) +++ stable/11/sys/conf/files.amd64 Mon Sep 11 18:48:09 2017 (r323453) @@ -324,10 +324,11 @@ dev/hyperv/vmbus/amd64/vmbus_vector.S optional hyper dev/nctgpio/nctgpio.c optional nctgpio dev/nfe/if_nfe.c optional nfe pci dev/ntb/if_ntb/if_ntb.c optional if_ntb -dev/ntb/ntb_transport.c optional if_ntb -dev/ntb/ntb.c optional if_ntb | ntb_hw -dev/ntb/ntb_if.m optional if_ntb | ntb_hw -dev/ntb/ntb_hw/ntb_hw.c optional ntb_hw +dev/ntb/ntb_transport.c optional ntb_transport | if_ntb +dev/ntb/ntb.c optional ntb | ntb_transport | if_ntb | ntb_hw_intel | ntb_hw_plx | ntb_hw +dev/ntb/ntb_if.m optional ntb | ntb_transport | if_ntb | ntb_hw_intel | ntb_hw_plx | ntb_hw +dev/ntb/ntb_hw/ntb_hw_intel.c optional ntb_hw_intel | ntb_hw +dev/ntb/ntb_hw/ntb_hw_plx.c optional ntb_hw_plx | ntb_hw dev/nvd/nvd.c optional nvd nvme dev/nvme/nvme.c optional nvme dev/nvme/nvme_ctrlr.c optional nvme Modified: stable/11/sys/conf/files.i386 ============================================================================== --- stable/11/sys/conf/files.i386 Mon Sep 11 18:31:51 2017 (r323452) +++ stable/11/sys/conf/files.i386 Mon Sep 11 18:48:09 2017 (r323453) @@ -294,10 +294,11 @@ dev/mse/mse_isa.c optional mse isa dev/nctgpio/nctgpio.c optional nctgpio dev/nfe/if_nfe.c optional nfe pci dev/ntb/if_ntb/if_ntb.c optional if_ntb -dev/ntb/ntb_transport.c optional if_ntb -dev/ntb/ntb.c optional if_ntb | ntb_hw -dev/ntb/ntb_if.m optional if_ntb | ntb_hw -dev/ntb/ntb_hw/ntb_hw.c optional ntb_hw +dev/ntb/ntb_transport.c optional ntb_transport | if_ntb +dev/ntb/ntb.c optional ntb | ntb_transport | if_ntb | ntb_hw_intel | ntb_hw_plx | ntb_hw +dev/ntb/ntb_if.m optional ntb | ntb_transport | if_ntb | ntb_hw_intel | ntb_hw_plx | ntb_hw +dev/ntb/ntb_hw/ntb_hw_intel.c optional ntb_hw_intel | ntb_hw +dev/ntb/ntb_hw/ntb_hw_plx.c optional ntb_hw_plx | ntb_hw dev/nvd/nvd.c optional nvd nvme dev/nvme/nvme.c optional nvme dev/nvme/nvme_ctrlr.c optional nvme Copied: stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c (from r323032, head/sys/dev/ntb/ntb_hw/ntb_hw_intel.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c Mon Sep 11 18:48:09 2017 (r323453, copy of r323032, head/sys/dev/ntb/ntb_hw/ntb_hw_intel.c) @@ -0,0 +1,3121 @@ +/*- + * Copyright (c) 2016 Alexander Motin + * Copyright (C) 2013 Intel Corporation + * Copyright (C) 2015 EMC Corporation + * All rights reserved. + * + * 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. + */ + +/* + * The Non-Transparent Bridge (NTB) is a device that allows you to connect + * two or more systems using a PCI-e links, providing remote memory access. + * + * This module contains a driver for NTB hardware in Intel Xeon/Atom CPUs. + * + * NOTE: Much of the code in this module is shared with Linux. Any patches may + * be picked up and redistributed in Linux with a dual GPL/BSD license. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ntb_hw_intel.h" +#include "../ntb.h" + +#define MAX_MSIX_INTERRUPTS MAX(XEON_DB_COUNT, ATOM_DB_COUNT) + +#define NTB_HB_TIMEOUT 1 /* second */ +#define ATOM_LINK_RECOVERY_TIME 500 /* ms */ +#define BAR_HIGH_MASK (~((1ull << 12) - 1)) + +#define NTB_MSIX_VER_GUARD 0xaabbccdd +#define NTB_MSIX_RECEIVED 0xe0f0e0f0 + +/* + * PCI constants could be somewhere more generic, but aren't defined/used in + * pci.c. + */ +#define PCI_MSIX_ENTRY_SIZE 16 +#define PCI_MSIX_ENTRY_LOWER_ADDR 0 +#define PCI_MSIX_ENTRY_UPPER_ADDR 4 +#define PCI_MSIX_ENTRY_DATA 8 + +enum ntb_device_type { + NTB_XEON, + NTB_ATOM +}; + +/* ntb_conn_type are hardware numbers, cannot change. */ +enum ntb_conn_type { + NTB_CONN_TRANSPARENT = 0, + NTB_CONN_B2B = 1, + NTB_CONN_RP = 2, +}; + +enum ntb_b2b_direction { + NTB_DEV_USD = 0, + NTB_DEV_DSD = 1, +}; + +enum ntb_bar { + NTB_CONFIG_BAR = 0, + NTB_B2B_BAR_1, + NTB_B2B_BAR_2, + NTB_B2B_BAR_3, + NTB_MAX_BARS +}; + +enum { + NTB_MSIX_GUARD = 0, + NTB_MSIX_DATA0, + NTB_MSIX_DATA1, + NTB_MSIX_DATA2, + NTB_MSIX_OFS0, + NTB_MSIX_OFS1, + NTB_MSIX_OFS2, + NTB_MSIX_DONE, + NTB_MAX_MSIX_SPAD +}; + +/* Device features and workarounds */ +#define HAS_FEATURE(ntb, feature) \ + (((ntb)->features & (feature)) != 0) + +struct ntb_hw_info { + uint32_t device_id; + const char *desc; + enum ntb_device_type type; + uint32_t features; +}; + +struct ntb_pci_bar_info { + bus_space_tag_t pci_bus_tag; + bus_space_handle_t pci_bus_handle; + int pci_resource_id; + struct resource *pci_resource; + vm_paddr_t pbase; + caddr_t vbase; + vm_size_t size; + vm_memattr_t map_mode; + + /* Configuration register offsets */ + uint32_t psz_off; + uint32_t ssz_off; + uint32_t pbarxlat_off; +}; + +struct ntb_int_info { + struct resource *res; + int rid; + void *tag; +}; + +struct ntb_vec { + struct ntb_softc *ntb; + uint32_t num; + unsigned masked; +}; + +struct ntb_reg { + uint32_t ntb_ctl; + uint32_t lnk_sta; + uint8_t db_size; + unsigned mw_bar[NTB_MAX_BARS]; +}; + +struct ntb_alt_reg { + uint32_t db_bell; + uint32_t db_mask; + uint32_t spad; +}; + +struct ntb_xlat_reg { + uint32_t bar0_base; + uint32_t bar2_base; + uint32_t bar4_base; + uint32_t bar5_base; + + uint32_t bar2_xlat; + uint32_t bar4_xlat; + uint32_t bar5_xlat; + + uint32_t bar2_limit; + uint32_t bar4_limit; + uint32_t bar5_limit; +}; + +struct ntb_b2b_addr { + uint64_t bar0_addr; + uint64_t bar2_addr64; + uint64_t bar4_addr64; + uint64_t bar4_addr32; + uint64_t bar5_addr32; +}; + +struct ntb_msix_data { + uint32_t nmd_ofs; + uint32_t nmd_data; +}; + +struct ntb_softc { + /* ntb.c context. Do not move! Must go first! */ + void *ntb_store; + + device_t device; + enum ntb_device_type type; + uint32_t features; + + struct ntb_pci_bar_info bar_info[NTB_MAX_BARS]; + struct ntb_int_info int_info[MAX_MSIX_INTERRUPTS]; + uint32_t allocated_interrupts; + + struct ntb_msix_data peer_msix_data[XEON_NONLINK_DB_MSIX_BITS]; + struct ntb_msix_data msix_data[XEON_NONLINK_DB_MSIX_BITS]; + bool peer_msix_good; + bool peer_msix_done; + struct ntb_pci_bar_info *peer_lapic_bar; + struct callout peer_msix_work; + + struct callout heartbeat_timer; + struct callout lr_timer; + + struct ntb_vec *msix_vec; + + uint32_t ppd; + enum ntb_conn_type conn_type; + enum ntb_b2b_direction dev_type; + + /* Offset of peer bar0 in B2B BAR */ + uint64_t b2b_off; + /* Memory window used to access peer bar0 */ +#define B2B_MW_DISABLED UINT8_MAX + uint8_t b2b_mw_idx; + uint32_t msix_xlat; + uint8_t msix_mw_idx; + + uint8_t mw_count; + uint8_t spad_count; + uint8_t db_count; + uint8_t db_vec_count; + uint8_t db_vec_shift; + + /* Protects local db_mask. */ +#define DB_MASK_LOCK(sc) mtx_lock_spin(&(sc)->db_mask_lock) +#define DB_MASK_UNLOCK(sc) mtx_unlock_spin(&(sc)->db_mask_lock) +#define DB_MASK_ASSERT(sc,f) mtx_assert(&(sc)->db_mask_lock, (f)) + struct mtx db_mask_lock; + + volatile uint32_t ntb_ctl; + volatile uint32_t lnk_sta; + + uint64_t db_valid_mask; + uint64_t db_link_mask; + uint64_t db_mask; + uint64_t fake_db; /* NTB_SB01BASE_LOCKUP*/ + uint64_t force_db; /* NTB_SB01BASE_LOCKUP*/ + + int last_ts; /* ticks @ last irq */ + + const struct ntb_reg *reg; + const struct ntb_alt_reg *self_reg; + const struct ntb_alt_reg *peer_reg; + const struct ntb_xlat_reg *xlat_reg; +}; + +#ifdef __i386__ +static __inline uint64_t +bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset) +{ + + return (bus_space_read_4(tag, handle, offset) | + ((uint64_t)bus_space_read_4(tag, handle, offset + 4)) << 32); +} + +static __inline void +bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset, uint64_t val) +{ + + bus_space_write_4(tag, handle, offset, val); + bus_space_write_4(tag, handle, offset + 4, val >> 32); +} +#endif + +#define intel_ntb_bar_read(SIZE, bar, offset) \ + bus_space_read_ ## SIZE (ntb->bar_info[(bar)].pci_bus_tag, \ + ntb->bar_info[(bar)].pci_bus_handle, (offset)) +#define intel_ntb_bar_write(SIZE, bar, offset, val) \ + bus_space_write_ ## SIZE (ntb->bar_info[(bar)].pci_bus_tag, \ + ntb->bar_info[(bar)].pci_bus_handle, (offset), (val)) +#define intel_ntb_reg_read(SIZE, offset) \ + intel_ntb_bar_read(SIZE, NTB_CONFIG_BAR, offset) +#define intel_ntb_reg_write(SIZE, offset, val) \ + intel_ntb_bar_write(SIZE, NTB_CONFIG_BAR, offset, val) +#define intel_ntb_mw_read(SIZE, offset) \ + intel_ntb_bar_read(SIZE, intel_ntb_mw_to_bar(ntb, ntb->b2b_mw_idx), \ + offset) +#define intel_ntb_mw_write(SIZE, offset, val) \ + intel_ntb_bar_write(SIZE, intel_ntb_mw_to_bar(ntb, ntb->b2b_mw_idx), \ + offset, val) + +static int intel_ntb_probe(device_t device); +static int intel_ntb_attach(device_t device); +static int intel_ntb_detach(device_t device); +static uint64_t intel_ntb_db_valid_mask(device_t dev); +static void intel_ntb_spad_clear(device_t dev); +static uint64_t intel_ntb_db_vector_mask(device_t dev, uint32_t vector); +static bool intel_ntb_link_is_up(device_t dev, enum ntb_speed *speed, + enum ntb_width *width); +static int intel_ntb_link_enable(device_t dev, enum ntb_speed speed, + enum ntb_width width); +static int intel_ntb_link_disable(device_t dev); +static int intel_ntb_spad_read(device_t dev, unsigned int idx, uint32_t *val); +static int intel_ntb_peer_spad_write(device_t dev, unsigned int idx, uint32_t val); + +static unsigned intel_ntb_user_mw_to_idx(struct ntb_softc *, unsigned uidx); +static inline enum ntb_bar intel_ntb_mw_to_bar(struct ntb_softc *, unsigned mw); +static inline bool bar_is_64bit(struct ntb_softc *, enum ntb_bar); +static inline void bar_get_xlat_params(struct ntb_softc *, enum ntb_bar, + uint32_t *base, uint32_t *xlat, uint32_t *lmt); +static int intel_ntb_map_pci_bars(struct ntb_softc *ntb); +static int intel_ntb_mw_set_wc_internal(struct ntb_softc *, unsigned idx, + vm_memattr_t); +static void print_map_success(struct ntb_softc *, struct ntb_pci_bar_info *, + const char *); +static int map_mmr_bar(struct ntb_softc *ntb, struct ntb_pci_bar_info *bar); +static int map_memory_window_bar(struct ntb_softc *ntb, + struct ntb_pci_bar_info *bar); +static void intel_ntb_unmap_pci_bar(struct ntb_softc *ntb); +static int intel_ntb_remap_msix(device_t, uint32_t desired, uint32_t avail); +static int intel_ntb_init_isr(struct ntb_softc *ntb); +static int intel_ntb_setup_legacy_interrupt(struct ntb_softc *ntb); +static int intel_ntb_setup_msix(struct ntb_softc *ntb, uint32_t num_vectors); +static void intel_ntb_teardown_interrupts(struct ntb_softc *ntb); +static inline uint64_t intel_ntb_vec_mask(struct ntb_softc *, uint64_t db_vector); +static void intel_ntb_interrupt(struct ntb_softc *, uint32_t vec); +static void ndev_vec_isr(void *arg); +static void ndev_irq_isr(void *arg); +static inline uint64_t db_ioread(struct ntb_softc *, uint64_t regoff); +static inline void db_iowrite(struct ntb_softc *, uint64_t regoff, uint64_t); +static inline void db_iowrite_raw(struct ntb_softc *, uint64_t regoff, uint64_t); +static int intel_ntb_create_msix_vec(struct ntb_softc *ntb, uint32_t num_vectors); +static void intel_ntb_free_msix_vec(struct ntb_softc *ntb); +static void intel_ntb_get_msix_info(struct ntb_softc *ntb); +static void intel_ntb_exchange_msix(void *); +static struct ntb_hw_info *intel_ntb_get_device_info(uint32_t device_id); +static void intel_ntb_detect_max_mw(struct ntb_softc *ntb); +static int intel_ntb_detect_xeon(struct ntb_softc *ntb); +static int intel_ntb_detect_atom(struct ntb_softc *ntb); +static int intel_ntb_xeon_init_dev(struct ntb_softc *ntb); +static int intel_ntb_atom_init_dev(struct ntb_softc *ntb); +static void intel_ntb_teardown_xeon(struct ntb_softc *ntb); +static void configure_atom_secondary_side_bars(struct ntb_softc *ntb); +static void xeon_reset_sbar_size(struct ntb_softc *, enum ntb_bar idx, + enum ntb_bar regbar); +static void xeon_set_sbar_base_and_limit(struct ntb_softc *, + uint64_t base_addr, enum ntb_bar idx, enum ntb_bar regbar); +static void xeon_set_pbar_xlat(struct ntb_softc *, uint64_t base_addr, + enum ntb_bar idx); +static int xeon_setup_b2b_mw(struct ntb_softc *, + const struct ntb_b2b_addr *addr, const struct ntb_b2b_addr *peer_addr); +static inline bool link_is_up(struct ntb_softc *ntb); +static inline bool _xeon_link_is_up(struct ntb_softc *ntb); +static inline bool atom_link_is_err(struct ntb_softc *ntb); +static inline enum ntb_speed intel_ntb_link_sta_speed(struct ntb_softc *); +static inline enum ntb_width intel_ntb_link_sta_width(struct ntb_softc *); +static void atom_link_hb(void *arg); +static void recover_atom_link(void *arg); +static bool intel_ntb_poll_link(struct ntb_softc *ntb); +static void save_bar_parameters(struct ntb_pci_bar_info *bar); +static void intel_ntb_sysctl_init(struct ntb_softc *); +static int sysctl_handle_features(SYSCTL_HANDLER_ARGS); +static int sysctl_handle_link_admin(SYSCTL_HANDLER_ARGS); +static int sysctl_handle_link_status_human(SYSCTL_HANDLER_ARGS); +static int sysctl_handle_link_status(SYSCTL_HANDLER_ARGS); +static int sysctl_handle_register(SYSCTL_HANDLER_ARGS); + +static unsigned g_ntb_hw_debug_level; +SYSCTL_UINT(_hw_ntb, OID_AUTO, debug_level, CTLFLAG_RWTUN, + &g_ntb_hw_debug_level, 0, "ntb_hw log level -- higher is more verbose"); +#define intel_ntb_printf(lvl, ...) do { \ + if ((lvl) <= g_ntb_hw_debug_level) { \ + device_printf(ntb->device, __VA_ARGS__); \ + } \ +} while (0) + +#define _NTB_PAT_UC 0 +#define _NTB_PAT_WC 1 +#define _NTB_PAT_WT 4 +#define _NTB_PAT_WP 5 +#define _NTB_PAT_WB 6 +#define _NTB_PAT_UCM 7 +static unsigned g_ntb_mw_pat = _NTB_PAT_UC; +SYSCTL_UINT(_hw_ntb, OID_AUTO, default_mw_pat, CTLFLAG_RDTUN, + &g_ntb_mw_pat, 0, "Configure the default memory window cache flags (PAT): " + "UC: " __XSTRING(_NTB_PAT_UC) ", " + "WC: " __XSTRING(_NTB_PAT_WC) ", " + "WT: " __XSTRING(_NTB_PAT_WT) ", " + "WP: " __XSTRING(_NTB_PAT_WP) ", " + "WB: " __XSTRING(_NTB_PAT_WB) ", " + "UC-: " __XSTRING(_NTB_PAT_UCM)); + +static inline vm_memattr_t +intel_ntb_pat_flags(void) +{ + + switch (g_ntb_mw_pat) { + case _NTB_PAT_WC: + return (VM_MEMATTR_WRITE_COMBINING); + case _NTB_PAT_WT: + return (VM_MEMATTR_WRITE_THROUGH); + case _NTB_PAT_WP: + return (VM_MEMATTR_WRITE_PROTECTED); + case _NTB_PAT_WB: + return (VM_MEMATTR_WRITE_BACK); + case _NTB_PAT_UCM: + return (VM_MEMATTR_WEAK_UNCACHEABLE); + case _NTB_PAT_UC: + /* FALLTHROUGH */ + default: + return (VM_MEMATTR_UNCACHEABLE); + } +} + +/* + * Well, this obviously doesn't belong here, but it doesn't seem to exist + * anywhere better yet. + */ +static inline const char * +intel_ntb_vm_memattr_to_str(vm_memattr_t pat) +{ + + switch (pat) { + case VM_MEMATTR_WRITE_COMBINING: + return ("WRITE_COMBINING"); + case VM_MEMATTR_WRITE_THROUGH: + return ("WRITE_THROUGH"); + case VM_MEMATTR_WRITE_PROTECTED: + return ("WRITE_PROTECTED"); + case VM_MEMATTR_WRITE_BACK: + return ("WRITE_BACK"); + case VM_MEMATTR_WEAK_UNCACHEABLE: + return ("UNCACHED"); + case VM_MEMATTR_UNCACHEABLE: + return ("UNCACHEABLE"); + default: + return ("UNKNOWN"); + } +} + +static int g_ntb_msix_idx = 1; +SYSCTL_INT(_hw_ntb, OID_AUTO, msix_mw_idx, CTLFLAG_RDTUN, &g_ntb_msix_idx, + 0, "Use this memory window to access the peer MSIX message complex on " + "certain Xeon-based NTB systems, as a workaround for a hardware errata. " + "Like b2b_mw_idx, negative values index from the last available memory " + "window. (Applies on Xeon platforms with SB01BASE_LOCKUP errata.)"); + +static int g_ntb_mw_idx = -1; +SYSCTL_INT(_hw_ntb, OID_AUTO, b2b_mw_idx, CTLFLAG_RDTUN, &g_ntb_mw_idx, + 0, "Use this memory window to access the peer NTB registers. A " + "non-negative value starts from the first MW index; a negative value " + "starts from the last MW index. The default is -1, i.e., the last " + "available memory window. Both sides of the NTB MUST set the same " + "value here! (Applies on Xeon platforms with SDOORBELL_LOCKUP errata.)"); + +/* Hardware owns the low 16 bits of features. */ +#define NTB_BAR_SIZE_4K (1 << 0) +#define NTB_SDOORBELL_LOCKUP (1 << 1) +#define NTB_SB01BASE_LOCKUP (1 << 2) +#define NTB_B2BDOORBELL_BIT14 (1 << 3) +/* Software/configuration owns the top 16 bits. */ +#define NTB_SPLIT_BAR (1ull << 16) + +#define NTB_FEATURES_STR \ + "\20\21SPLIT_BAR4\04B2B_DOORBELL_BIT14\03SB01BASE_LOCKUP" \ + "\02SDOORBELL_LOCKUP\01BAR_SIZE_4K" + +static struct ntb_hw_info pci_ids[] = { + /* XXX: PS/SS IDs left out until they are supported. */ + { 0x0C4E8086, "BWD Atom Processor S1200 Non-Transparent Bridge B2B", + NTB_ATOM, 0 }, + + { 0x37258086, "JSF Xeon C35xx/C55xx Non-Transparent Bridge B2B", + NTB_XEON, NTB_SDOORBELL_LOCKUP | NTB_B2BDOORBELL_BIT14 }, + { 0x3C0D8086, "SNB Xeon E5/Core i7 Non-Transparent Bridge B2B", + NTB_XEON, NTB_SDOORBELL_LOCKUP | NTB_B2BDOORBELL_BIT14 }, + { 0x0E0D8086, "IVT Xeon E5 V2 Non-Transparent Bridge B2B", NTB_XEON, + NTB_SDOORBELL_LOCKUP | NTB_B2BDOORBELL_BIT14 | + NTB_SB01BASE_LOCKUP | NTB_BAR_SIZE_4K }, + { 0x2F0D8086, "HSX Xeon E5 V3 Non-Transparent Bridge B2B", NTB_XEON, + NTB_SDOORBELL_LOCKUP | NTB_B2BDOORBELL_BIT14 | + NTB_SB01BASE_LOCKUP }, + { 0x6F0D8086, "BDX Xeon E5 V4 Non-Transparent Bridge B2B", NTB_XEON, + NTB_SDOORBELL_LOCKUP | NTB_B2BDOORBELL_BIT14 | + NTB_SB01BASE_LOCKUP }, + + { 0x00000000, NULL, NTB_ATOM, 0 } +}; + +static const struct ntb_reg atom_reg = { + .ntb_ctl = ATOM_NTBCNTL_OFFSET, + .lnk_sta = ATOM_LINK_STATUS_OFFSET, + .db_size = sizeof(uint64_t), + .mw_bar = { NTB_B2B_BAR_1, NTB_B2B_BAR_2 }, +}; + +static const struct ntb_alt_reg atom_pri_reg = { + .db_bell = ATOM_PDOORBELL_OFFSET, *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable-11@freebsd.org Mon Sep 11 18:50:10 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 71F38E1CE0A; Mon, 11 Sep 2017 18:50:10 +0000 (UTC) (envelope-from mav@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 mx1.freebsd.org (Postfix) with ESMTPS id 3EA916D4BA; Mon, 11 Sep 2017 18:50:10 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BIo97g075870; Mon, 11 Sep 2017 18:50:09 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BIo951075869; Mon, 11 Sep 2017 18:50:09 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201709111850.v8BIo951075869@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 11 Sep 2017 18:50:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323454 - stable/11/sys/dev/ntb X-SVN-Group: stable-11 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/11/sys/dev/ntb X-SVN-Commit-Revision: 323454 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 18:50:10 -0000 Author: mav Date: Mon Sep 11 18:50:09 2017 New Revision: 323454 URL: https://svnweb.freebsd.org/changeset/base/323454 Log: MFC r323074: Clear doorbell bits after masking them before processing. In theory this allows to avoid one more expensive doorbell register read later in some scenarios. But in practice it also significantly increases packet rate on PLX hardware, that I can't explain yet, possibly work- arounding some interrupt delays. Modified: stable/11/sys/dev/ntb/ntb_transport.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/ntb/ntb_transport.c ============================================================================== --- stable/11/sys/dev/ntb/ntb_transport.c Mon Sep 11 18:48:09 2017 (r323453) +++ stable/11/sys/dev/ntb/ntb_transport.c Mon Sep 11 18:50:09 2017 (r323454) @@ -1012,8 +1012,10 @@ ntb_transport_doorbell_callback(void *data, uint32_t v vec_mask &= nt->qp_bitmap; if ((vec_mask & (vec_mask - 1)) != 0) vec_mask &= ntb_db_read(nt->dev); - if (vec_mask != 0) + if (vec_mask != 0) { ntb_db_set_mask(nt->dev, vec_mask); + ntb_db_clear(nt->dev, vec_mask); + } while (vec_mask != 0) { qp_num = ffsll(vec_mask) - 1; From owner-svn-src-stable-11@freebsd.org Mon Sep 11 18:50:38 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 06BFEE1CEC6; Mon, 11 Sep 2017 18:50:38 +0000 (UTC) (envelope-from mav@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 mx1.freebsd.org (Postfix) with ESMTPS id D4ECC6D600; Mon, 11 Sep 2017 18:50:37 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BIob2D075947; Mon, 11 Sep 2017 18:50:37 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BIoagf075942; Mon, 11 Sep 2017 18:50:36 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201709111850.v8BIoagf075942@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 11 Sep 2017 18:50:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323455 - in stable/11/sys/dev/ntb: . ntb_hw X-SVN-Group: stable-11 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in stable/11/sys/dev/ntb: . ntb_hw X-SVN-Commit-Revision: 323455 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 18:50:38 -0000 Author: mav Date: Mon Sep 11 18:50:36 2017 New Revision: 323455 URL: https://svnweb.freebsd.org/changeset/base/323455 Log: MFC r323126: Make NTB drivers report more info via NewBus methods. Modified: stable/11/sys/dev/ntb/ntb.c stable/11/sys/dev/ntb/ntb.h stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c stable/11/sys/dev/ntb/ntb_hw/ntb_hw_plx.c stable/11/sys/dev/ntb/ntb_transport.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/ntb/ntb.c ============================================================================== --- stable/11/sys/dev/ntb/ntb.c Mon Sep 11 18:50:09 2017 (r323454) +++ stable/11/sys/dev/ntb/ntb.c Mon Sep 11 18:50:36 2017 (r323455) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2016 Alexander Motin + * Copyright (c) 2016-2017 Alexander Motin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,13 +43,15 @@ SYSCTL_NODE(_hw, OID_AUTO, ntb, CTLFLAG_RW, 0, "NTB sy struct ntb_child { device_t dev; + int function; int enabled; int mwoff; int mwcnt; int spadoff; int spadcnt; int dboff; - int dbmask; + int dbcnt; + uint64_t dbmask; void *ctx; const struct ntb_ctx_ops *ctx_ops; struct rmlock ctx_lock; @@ -98,11 +100,13 @@ ntb_register_device(device_t dev) } nc = malloc(sizeof(*nc), M_DEVBUF, M_WAITOK | M_ZERO); + nc->function = i; nc->mwoff = mwu; nc->mwcnt = mw; nc->spadoff = spadu; nc->spadcnt = spad; nc->dboff = dbu; + nc->dbcnt = db; nc->dbmask = (db == 0) ? 0 : (0xffffffffffffffff >> (64 - db)); rm_init(&nc->ctx_lock, "ntb ctx"); nc->dev = device_add_child(dev, name, -1); @@ -160,6 +164,45 @@ ntb_unregister_device(device_t dev) free(nc, M_DEVBUF); } return (error); +} + +int +ntb_child_location_str(device_t dev, device_t child, char *buf, + size_t buflen) +{ + struct ntb_child *nc = device_get_ivars(child); + + snprintf(buf, buflen, "function=%d", nc->function); + return (0); +} + +int +ntb_print_child(device_t dev, device_t child) +{ + struct ntb_child *nc = device_get_ivars(child); + int retval; + + retval = bus_print_child_header(dev, child); + if (nc->mwcnt > 0) { + printf(" mw %d", nc->mwoff); + if (nc->mwcnt > 1) + printf("-%d", nc->mwoff + nc->mwcnt - 1); + } + if (nc->spadcnt > 0) { + printf(" spad %d", nc->spadoff); + if (nc->spadcnt > 1) + printf("-%d", nc->spadoff + nc->spadcnt - 1); + } + if (nc->dbcnt > 0) { + printf(" db %d", nc->dboff); + if (nc->dbcnt > 1) + printf("-%d", nc->dboff + nc->dbcnt - 1); + } + retval += printf(" at function %d", nc->function); + retval += bus_print_child_domain(dev, child); + retval += bus_print_child_footer(dev, child); + + return (retval); } void Modified: stable/11/sys/dev/ntb/ntb.h ============================================================================== --- stable/11/sys/dev/ntb/ntb.h Mon Sep 11 18:50:09 2017 (r323454) +++ stable/11/sys/dev/ntb/ntb.h Mon Sep 11 18:50:36 2017 (r323455) @@ -36,6 +36,9 @@ SYSCTL_DECL(_hw_ntb); int ntb_register_device(device_t ntb); int ntb_unregister_device(device_t ntb); +int ntb_child_location_str(device_t dev, device_t child, char *buf, + size_t buflen); +int ntb_print_child(device_t dev, device_t child); /* * ntb_link_event() - notify driver context of a change in link status Modified: stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c ============================================================================== --- stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c Mon Sep 11 18:50:09 2017 (r323454) +++ stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c Mon Sep 11 18:50:36 2017 (r323455) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2016 Alexander Motin + * Copyright (c) 2016-2017 Alexander Motin * Copyright (C) 2013 Intel Corporation * Copyright (C) 2015 EMC Corporation * All rights reserved. @@ -3085,6 +3085,9 @@ static device_method_t ntb_intel_methods[] = { DEVMETHOD(device_probe, intel_ntb_probe), DEVMETHOD(device_attach, intel_ntb_attach), DEVMETHOD(device_detach, intel_ntb_detach), + /* Bus interface */ + DEVMETHOD(bus_child_location_str, ntb_child_location_str), + DEVMETHOD(bus_print_child, ntb_print_child), /* NTB interface */ DEVMETHOD(ntb_link_is_up, intel_ntb_link_is_up), DEVMETHOD(ntb_link_enable, intel_ntb_link_enable), Modified: stable/11/sys/dev/ntb/ntb_hw/ntb_hw_plx.c ============================================================================== --- stable/11/sys/dev/ntb/ntb_hw/ntb_hw_plx.c Mon Sep 11 18:50:09 2017 (r323454) +++ stable/11/sys/dev/ntb/ntb_hw/ntb_hw_plx.c Mon Sep 11 18:50:36 2017 (r323455) @@ -914,6 +914,9 @@ static device_method_t ntb_plx_methods[] = { DEVMETHOD(device_probe, ntb_plx_probe), DEVMETHOD(device_attach, ntb_plx_attach), DEVMETHOD(device_detach, ntb_plx_detach), + /* Bus interface */ + DEVMETHOD(bus_child_location_str, ntb_child_location_str), + DEVMETHOD(bus_print_child, ntb_print_child), /* NTB interface */ DEVMETHOD(ntb_link_is_up, ntb_plx_link_is_up), DEVMETHOD(ntb_link_enable, ntb_plx_link_enable), Modified: stable/11/sys/dev/ntb/ntb_transport.c ============================================================================== --- stable/11/sys/dev/ntb/ntb_transport.c Mon Sep 11 18:50:09 2017 (r323454) +++ stable/11/sys/dev/ntb/ntb_transport.c Mon Sep 11 18:50:36 2017 (r323455) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2016 Alexander Motin + * Copyright (c) 2016-2017 Alexander Motin * Copyright (C) 2013 Intel Corporation * Copyright (C) 2015 EMC Corporation * All rights reserved. @@ -188,6 +188,7 @@ struct ntb_transport_mw { struct ntb_transport_child { device_t dev; + int consumer; int qpoff; int qpcnt; struct ntb_transport_child *next; @@ -343,9 +344,6 @@ ntb_transport_attach(device_t dev) KASSERT(db_bitmap == (1 << db_count) - 1, ("Doorbells are not sequential (%jx).\n", db_bitmap)); - device_printf(dev, "%d memory windows, %d scratchpads, " - "%d doorbells\n", nt->mw_count, spad_count, db_count); - if (nt->mw_count == 0) { device_printf(dev, "At least 1 memory window required.\n"); return (ENXIO); @@ -409,6 +407,7 @@ ntb_transport_attach(device_t dev) } nc = malloc(sizeof(*nc), M_DEVBUF, M_WAITOK | M_ZERO); + nc->consumer = i; nc->qpoff = qpu; nc->qpcnt = qp; nc->dev = device_add_child(dev, name, -1); @@ -496,6 +495,35 @@ ntb_transport_detach(device_t dev) return (0); } +static int +ntb_transport_print_child(device_t dev, device_t child) +{ + struct ntb_transport_child *nc = device_get_ivars(child); + int retval; + + retval = bus_print_child_header(dev, child); + if (nc->qpcnt > 0) { + printf(" queue %d", nc->qpoff); + if (nc->qpcnt > 1) + printf("-%d", nc->qpoff + nc->qpcnt - 1); + } + retval += printf(" at consumer %d", nc->consumer); + retval += bus_print_child_domain(dev, child); + retval += bus_print_child_footer(dev, child); + + return (retval); +} + +static int +ntb_transport_child_location_str(device_t dev, device_t child, char *buf, + size_t buflen) +{ + struct ntb_transport_child *nc = device_get_ivars(child); + + snprintf(buf, buflen, "consumer=%d", nc->consumer); + return (0); +} + int ntb_transport_queue_count(device_t dev) { @@ -1552,6 +1580,9 @@ static device_method_t ntb_transport_methods[] = { DEVMETHOD(device_probe, ntb_transport_probe), DEVMETHOD(device_attach, ntb_transport_attach), DEVMETHOD(device_detach, ntb_transport_detach), + /* Bus interface */ + DEVMETHOD(bus_child_location_str, ntb_transport_child_location_str), + DEVMETHOD(bus_print_child, ntb_transport_print_child), DEVMETHOD_END }; From owner-svn-src-stable-11@freebsd.org Mon Sep 11 18:51:03 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7A9B4E1CF88; Mon, 11 Sep 2017 18:51:03 +0000 (UTC) (envelope-from mav@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 mx1.freebsd.org (Postfix) with ESMTPS id 44C946D86D; Mon, 11 Sep 2017 18:51:03 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BIp2XM078815; Mon, 11 Sep 2017 18:51:02 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BIp2WV078813; Mon, 11 Sep 2017 18:51:02 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201709111851.v8BIp2WV078813@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 11 Sep 2017 18:51:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323456 - in stable/11/sys/dev/ntb: . ntb_hw X-SVN-Group: stable-11 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in stable/11/sys/dev/ntb: . ntb_hw X-SVN-Commit-Revision: 323456 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 18:51:03 -0000 Author: mav Date: Mon Sep 11 18:51:02 2017 New Revision: 323456 URL: https://svnweb.freebsd.org/changeset/base/323456 Log: MFC r323128: Increase negotiation polling period from 10ms to 100ms. There is no big need to burn CPU if other side may be not there yet. For example, the PLX hardware by default enables the NTB link up on reset, not dependig on driver to do it. In case of Intel hardware this also reduces race between MSI-X workaround negotiation and upper layers, using the same scratchpad registers in different time. Modified: stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c stable/11/sys/dev/ntb/ntb_transport.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c ============================================================================== --- stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c Mon Sep 11 18:50:36 2017 (r323455) +++ stable/11/sys/dev/ntb/ntb_hw/ntb_hw_intel.c Mon Sep 11 18:51:02 2017 (r323456) @@ -2689,7 +2689,7 @@ reschedule: ntb->lnk_sta = pci_read_config(ntb->device, ntb->reg->lnk_sta, 2); if (_xeon_link_is_up(ntb)) { callout_reset(&ntb->peer_msix_work, - hz * (ntb->peer_msix_good ? 2 : 1) / 100, + hz * (ntb->peer_msix_good ? 2 : 1) / 10, intel_ntb_exchange_msix, ntb); } else intel_ntb_spad_clear(ntb->device); Modified: stable/11/sys/dev/ntb/ntb_transport.c ============================================================================== --- stable/11/sys/dev/ntb/ntb_transport.c Mon Sep 11 18:50:36 2017 (r323455) +++ stable/11/sys/dev/ntb/ntb_transport.c Mon Sep 11 18:51:02 2017 (r323456) @@ -250,7 +250,7 @@ enum { #define QP_TO_MW(nt, qp) ((qp) % nt->mw_count) #define NTB_QP_DEF_NUM_ENTRIES 100 -#define NTB_LINK_DOWN_TIMEOUT 10 +#define NTB_LINK_DOWN_TIMEOUT 100 static int ntb_transport_probe(device_t dev); static int ntb_transport_attach(device_t dev); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 20:33:22 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1DA10E22D19; Mon, 11 Sep 2017 20:33:22 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id E0E9471899; Mon, 11 Sep 2017 20:33:21 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BKXKdE020466; Mon, 11 Sep 2017 20:33:20 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BKXKOh020465; Mon, 11 Sep 2017 20:33:20 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709112033.v8BKXKOh020465@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 20:33:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323461 - stable/11 X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11 X-SVN-Commit-Revision: 323461 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 20:33:22 -0000 Author: ian Date: Mon Sep 11 20:33:20 2017 New Revision: 323461 URL: https://svnweb.freebsd.org/changeset/base/323461 Log: MFC r321876: In xdev-links, when installing symlinks to the cross-compiler pieces that includes the OS version (armv6-freebsd12.0-cc, etc), use the OS version of the compiler/world source code, not the version of the build host machine. Modified: stable/11/Makefile.inc1 Directory Properties: stable/11/ (props changed) Modified: stable/11/Makefile.inc1 ============================================================================== --- stable/11/Makefile.inc1 Mon Sep 11 19:57:04 2017 (r323460) +++ stable/11/Makefile.inc1 Mon Sep 11 20:33:20 2017 (r323461) @@ -2554,9 +2554,6 @@ CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/u CD2MAKE+= BUILD_TOOLS_META=.NOMETA .endif XDDESTDIR=${DESTDIR}/${XDTP} -.if !defined(OSREL) -OSREL!= uname -r | sed -e 's/[-(].*//' -.endif .ORDER: xdev-build xdev-install xdev-links xdev: xdev-build xdev-install .PHONY @@ -2650,7 +2647,7 @@ xdev-links: .PHONY ln -sf ../../${XDTP}/usr/bin/$$i \ ../../../../usr/bin/${XDDIR}-$$i; \ ln -sf ../../${XDTP}/usr/bin/$$i \ - ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \ + ../../../../usr/bin/${XDDIR}${_REVISION}-$$i; \ done .else xdev xdev-build xdev-install xdev-links: .PHONY From owner-svn-src-stable-11@freebsd.org Mon Sep 11 21:32:37 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2AE35E009B1; Mon, 11 Sep 2017 21:32:37 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 073E373C9A; Mon, 11 Sep 2017 21:32:36 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BLWZ5Q045210; Mon, 11 Sep 2017 21:32:35 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BLWZ7X045206; Mon, 11 Sep 2017 21:32:35 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709112132.v8BLWZ7X045206@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 21:32:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323464 - in stable/11: share/man/man9 sys/kern sys/sys X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11: share/man/man9 sys/kern sys/sys X-SVN-Commit-Revision: 323464 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 21:32:37 -0000 Author: ian Date: Mon Sep 11 21:32:35 2017 New Revision: 323464 URL: https://svnweb.freebsd.org/changeset/base/323464 Log: MFC r322465: Add config_intrhook_oneshot(): schedule an intrhook function and unregister it automatically after it runs. The config_intrhook mechanism allows a driver to stall the boot process until device(s) required for booting are available, by not allowing system inits to proceed until all intrhook functions have been unregistered. Virtually all existing code simply unregisters from within the hook function when it gets called. This new function makes that common usage more convenient. Instead of allocating and filling in a struct, passing it to a function that might (in theory) fail, and checking the return code, now a driver can simply call this cannot-fail routine, passing just the intrhook function and its arg. Differential Revision: https://reviews.freebsd.org/D11963 Modified: stable/11/share/man/man9/Makefile stable/11/share/man/man9/config_intrhook.9 stable/11/sys/kern/subr_autoconf.c stable/11/sys/sys/kernel.h Directory Properties: stable/11/ (props changed) Modified: stable/11/share/man/man9/Makefile ============================================================================== --- stable/11/share/man/man9/Makefile Mon Sep 11 20:42:07 2017 (r323463) +++ stable/11/share/man/man9/Makefile Mon Sep 11 21:32:35 2017 (r323464) @@ -630,7 +630,8 @@ MLINKS+=condvar.9 cv_broadcast.9 \ condvar.9 cv_wait_unlock.9 \ condvar.9 cv_wmesg.9 MLINKS+=config_intrhook.9 config_intrhook_disestablish.9 \ - config_intrhook.9 config_intrhook_establish.9 + config_intrhook.9 config_intrhook_establish.9 \ + config_intrhook.9 config_intrhook_oneshot.9 MLINKS+=contigmalloc.9 contigfree.9 MLINKS+=casuword.9 casueword.9 \ casuword.9 casueword32.9 \ Modified: stable/11/share/man/man9/config_intrhook.9 ============================================================================== --- stable/11/share/man/man9/config_intrhook.9 Mon Sep 11 20:42:07 2017 (r323463) +++ stable/11/share/man/man9/config_intrhook.9 Mon Sep 11 21:32:35 2017 (r323464) @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 24, 2006 +.Dd August 10, 2017 .Dt CONFIG_INTRHOOK 9 .Os .Sh NAME @@ -35,10 +35,13 @@ but before root is mounted .Sh SYNOPSIS .In sys/kernel.h +.Vt typedef void (*ich_func_t)(void *arg); .Ft int .Fn config_intrhook_establish "struct intr_config_hook *hook" .Ft void .Fn config_intrhook_disestablish "struct intr_config_hook *hook" +.Ft void +.Fn config_intrhook_oneshot "ich_func_t func" "void *arg" .Sh DESCRIPTION The .Fn config_intrhook_establish @@ -51,6 +54,18 @@ The .Fn config_intrhook_disestablish function removes the entry from the hook queue. .Pp +The +.Fn config_intrhook_oneshot +function schedules a function to be run as described for +.Fn config_intrhook_establish ; +the entry is automatically removed from the hook queue +after that function runs. +This is appropriate when additional device configuration must be done +after interrupts are enabled, but there is no need to stall the +boot process after that. +This function allocates memory using M_WAITOK; do not call this while +holding any non-sleepable locks. +.Pp Before root is mounted, all the previously established hooks are run. The boot process is then stalled until all handlers remove their hook @@ -71,8 +86,8 @@ This structure is defined as follows: .Bd -literal struct intr_config_hook { TAILQ_ENTRY(intr_config_hook) ich_links;/* Private */ - void (*ich_func)(void *arg); /* function to call */ - void *ich_arg; /* Argument to call */ + ich_func_t ich_func; /* function to call */ + void *ich_arg; /* Argument to call */ }; .Ed .Pp Modified: stable/11/sys/kern/subr_autoconf.c ============================================================================== --- stable/11/sys/kern/subr_autoconf.c Mon Sep 11 20:42:07 2017 (r323463) +++ stable/11/sys/kern/subr_autoconf.c Mon Sep 11 21:32:35 2017 (r323464) @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -63,6 +64,27 @@ MTX_SYSINIT(intr_config_hook, &intr_config_hook_lock, static void run_interrupt_driven_config_hooks(void); /* + * Private data and a shim function for implementing config_interhook_oneshot(). + */ +struct oneshot_config_hook { + struct intr_config_hook + och_hook; /* Must be first */ + ich_func_t och_func; + void *och_arg; +}; + +static void +config_intrhook_oneshot_func(void *arg) +{ + struct oneshot_config_hook *ohook; + + ohook = arg; + ohook->och_func(ohook->och_arg); + config_intrhook_disestablish(&ohook->och_hook); + free(ohook, M_DEVBUF); +} + +/* * If we wait too long for an interrupt-driven config hook to return, print * a diagnostic. */ @@ -181,6 +203,22 @@ config_intrhook_establish(struct intr_config_hook *hoo /* XXX Sufficient for modules loaded after initial config??? */ run_interrupt_driven_config_hooks(); return (0); +} + +/* + * Register a hook function that is automatically unregistered after it runs. + */ +void +config_intrhook_oneshot(ich_func_t func, void *arg) +{ + struct oneshot_config_hook *ohook; + + ohook = malloc(sizeof(*ohook), M_DEVBUF, M_WAITOK); + ohook->och_func = func; + ohook->och_arg = arg; + ohook->och_hook.ich_func = config_intrhook_oneshot_func; + ohook->och_hook.ich_arg = ohook; + config_intrhook_establish(&ohook->och_hook); } void Modified: stable/11/sys/sys/kernel.h ============================================================================== --- stable/11/sys/sys/kernel.h Mon Sep 11 20:42:07 2017 (r323463) +++ stable/11/sys/sys/kernel.h Mon Sep 11 21:32:35 2017 (r323464) @@ -400,13 +400,16 @@ struct tunable_str { #define TUNABLE_STR_FETCH(path, var, size) \ getenv_string((path), (var), (size)) +typedef void (*ich_func_t)(void *_arg); + struct intr_config_hook { TAILQ_ENTRY(intr_config_hook) ich_links; - void (*ich_func)(void *arg); - void *ich_arg; + ich_func_t ich_func; + void *ich_arg; }; int config_intrhook_establish(struct intr_config_hook *hook); void config_intrhook_disestablish(struct intr_config_hook *hook); +void config_intrhook_oneshot(ich_func_t _func, void *_arg); #endif /* !_SYS_KERNEL_H_*/ From owner-svn-src-stable-11@freebsd.org Mon Sep 11 22:21:17 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C634CE03166; Mon, 11 Sep 2017 22:21:17 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 62A7F75511; Mon, 11 Sep 2017 22:21:17 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BMLG0h061592; Mon, 11 Sep 2017 22:21:16 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BMLFoV061582; Mon, 11 Sep 2017 22:21:15 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709112221.v8BMLFoV061582@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 22:21:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323467 - in stable/11/sys: arm/allwinner conf dev/iicbus mips/conf mips/rmi modules/i2c modules/i2c/ds1307 modules/i2c/ds13rtc modules/i2c/ds3231 modules/i2c/isl12xx modules/i2c/nxprtc... X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: arm/allwinner conf dev/iicbus mips/conf mips/rmi modules/i2c modules/i2c/ds1307 modules/i2c/ds13rtc modules/i2c/ds3231 modules/i2c/isl12xx modules/i2c/nxprtc modules/i2c/s35390a X-SVN-Commit-Revision: 323467 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 22:21:17 -0000 Author: ian Date: Mon Sep 11 22:21:15 2017 New Revision: 323467 URL: https://svnweb.freebsd.org/changeset/base/323467 Log: MFC r321708-r321712, r321721, r321726-r321727, r321746, r321751, r321791-r321792, r321795, r321798, r321821, r321823, r321826, r321828, r321841, r321934, r322025-r322026, r322282, r322431, r322473, r322475-r322479 Lots of i2c RTC driver stuff... r321708: Replace the pcf8563 i2c RTC driver with a new nxprtc driver which handles all the chips in the NXP PCA212x and PCA/PCF85xx series. In addition to supporting more chips, this driver uses the countdown timer on the chips as a fractional seconds counter, giving it a resolution of about 15 milliseconds. r321709: Fix building this driver on non-FDT platforms. r321710: Add a few missing i2c devices that build fine on all arches. r321711: Move the device descriptions onto the device lines, so they cut and paste nicely into other config files. r321712: Add the i2c RTC drivers found on various arm systems. r321721: Switch from using iic_transfer() to iicdev_readfrom/writeto(), mostly so that transfers will be done with proper ownership of the bus. No behavioral changes. r321726: Bugfixes and enhancements... Don't enable the oscillator when it is found to be stopped at init time, just let the first setting of valid time start it. But still report a dead battery if it's stopped at init time. Don't force the chip into 24hr mode, just cope with whatever mode it is already in. Align the RTC clock to top of second when setting it. r321727: Fix AM/PM mode handling. The bits to mask off in the hours register changes between 12/24 hour mode. Also fix conversion between 12 and 24 hour mode. It's not as easy as adding/subtracting 12, because the clock doesn't roll over 11->0, it rolls over 12->1; 0 isn't a valid hour in AM/PM mode. r321746: Use the new clock_schedule() to arrange for clock_settime() to be called at the right time to keep the RTC hardware time in sync, instead of using pause_sbt() to sleep until the right time. r321751: Remove now-unused variable. r321791: Switch from using iic_transfer() to iicdev_readfrom/writeto(), mostly so that transfers will be done with proper ownership of the bus. No behavioral changes. Also add a detach() method. r321792: Add a detach() method. r321795: Check the clock-halted flag every time the clock is read, not just once at startup. The flag stays set until the clock is loaded with good time, so we need to keep saying the time is invalid until that happens. r321798: Restore a few rather important lines of code that got fumbled in r321746. r321821: No need to call getnanotime() now that the waiting is done by the central subr_rtc code, switch from CLOCKF_SETTIME_NO_TS to CLOCKF_SETTIME_NO_ADJ so that we get fed a timestamp, but it's not adjusted to compensate for inaccuracy in setting time. r321823: Bugfixes and enhancements... Don't enable the oscillator when it is found to be stopped at init time, just let the first setting of valid time start it. But still report a dead battery if it's stopped at init time. Don't force the chip into 24hr mode, just cope with whatever mode it is already in. Schedule the clock_settime() callbacks to align the RTC clock to top of second when setting it. r321826: Restructure the SUBDIR list as 1-per-line and alphabetize, so it will be easier to add new things (and see what changed) in the future. r321828: Build iicbus/{ds1307,ds3231,nxprtc} as modules. r321841: Add a driver for the Intersil ISL12xx family of i2c RTC chips. Supports ISL1209, ISL1218, ISL1219, ISL1220, ISL1221 (just basic RTC functionality, not all the other fancy stuff the chips can do). r321934: Add missing ofw_bus_if.h src file. r322025: Switch to iicdev_readfrom/writeto() to do xfers with proper bus ownership. Tested by: manu@ r322026: Add missing header file to SRCS. Reported by: manu@ r322282: Remove the ds133x and s35390a i2c RTC drivers for now. They both do i2c transfers in their probe() or attach() routines, and that doesn't work when the low-level controller requires interrupts to be functional. The DS133x family of chips is nearly identical to the DS1307 and support for them should be added to that driver, then the ds133x driver can be deleted. The s35390a driver just needs a non-trivial workover. In both cases that work will be done and committed separately. r322431: Bid for the device with BUS_PROBE_GENERIC, because this is very much a generic driver with minimal feature support for a large number of chips. More featureful per-chip drivers might exist (especially out-of-tree) and those should win the bidding even if they use BUS_PROBE_DEFAULT. r322473: Add a new driver, ds13rtc, that handles all DS13xx series i2c RTC chips. This driver supports only basic timekeeping functionality. It completely replaces the ds133x driver. It can also replace the ds1374 driver, but that will take a few other changes in MIPS code and config, and will be committed separately. It does NOT replace the existing ds1307 driver, which provides access to some of the extended features on the 1307 chip, such as controlling the square wave output signal. If both ds1307 and ds13rtc drivers are present, the ds1307 driver will outbid and win control of the device. This driver can be configured with FDT data, or by using hints on non-FDT systems. In addition to the standard hints for i2c devices, it requires a "chiptype" string of the form "dallas,ds13xx" where 'xx' is the chip id (i.e., the same format as FDT compat strings). r322475: Change "chiptype" to "compatible". Making the hint name the same as the FDT property name should make it easier to document the list of names accepted by both configuration mechanisms. r322476: Remove the old ds1374 driver and use the ds13rtc driver instead. Adjust several mips config files accordingly. r322477: Minor fixes and enhancements for the s35390a i2c RTC driver... - Add FDT probe code. - Do i2c transfers with exclusive bus ownership. - Use config_intrhook_oneshot() to defer chip setup because some i2c busses can't do transfers without interrupts. - Add a detach() routine. - Add to module build. r322478: Add back the drivers for Dallas/Maxim ds13xx and Seiko S35390x now that they've been rewritten/fixed to not cause panics by doing i2c transfers before interrupts are available. PR: 221227 r322479: Add hinted attachment for non-FDT systems. Also, print a message if setting up the timer fails, because on some types of chips that's the first attempt to access the device. If the chip is missing/non-responsive then you'd get a driver that attached and didn't register the rtc, with no clue about why. On other chip types there are inits that come before timer setup, and they already print messages about errors. Added: stable/11/sys/dev/iicbus/ds13rtc.c - copied, changed from r322473, head/sys/dev/iicbus/ds13rtc.c stable/11/sys/dev/iicbus/isl12xx.c - copied unchanged from r321841, head/sys/dev/iicbus/isl12xx.c stable/11/sys/dev/iicbus/nxprtc.c - copied, changed from r321712, head/sys/dev/iicbus/nxprtc.c stable/11/sys/modules/i2c/ds1307/ - copied from r321828, head/sys/modules/i2c/ds1307/ stable/11/sys/modules/i2c/ds13rtc/ - copied from r322473, head/sys/modules/i2c/ds13rtc/ stable/11/sys/modules/i2c/ds3231/ - copied from r321828, head/sys/modules/i2c/ds3231/ stable/11/sys/modules/i2c/isl12xx/ - copied from r321841, head/sys/modules/i2c/isl12xx/ stable/11/sys/modules/i2c/nxprtc/ - copied from r321828, head/sys/modules/i2c/nxprtc/ stable/11/sys/modules/i2c/s35390a/ - copied from r322479, head/sys/modules/i2c/s35390a/ Deleted: stable/11/sys/dev/iicbus/ds133x.c stable/11/sys/dev/iicbus/ds1374.c stable/11/sys/dev/iicbus/pcf8563.c stable/11/sys/dev/iicbus/pcf8563reg.h Modified: stable/11/sys/arm/allwinner/axp209.c stable/11/sys/conf/NOTES stable/11/sys/conf/files stable/11/sys/dev/iicbus/ds1307.c stable/11/sys/dev/iicbus/ds1307reg.h stable/11/sys/dev/iicbus/ds3231.c stable/11/sys/dev/iicbus/ds3231reg.h stable/11/sys/dev/iicbus/s35390a.c stable/11/sys/mips/conf/XLP.hints stable/11/sys/mips/conf/XLR stable/11/sys/mips/conf/XLR64 stable/11/sys/mips/conf/XLRN32 stable/11/sys/mips/conf/std.XLP stable/11/sys/mips/rmi/xlr_i2c.c stable/11/sys/modules/i2c/Makefile stable/11/sys/modules/i2c/ds1307/Makefile stable/11/sys/modules/i2c/ds3231/Makefile stable/11/sys/modules/i2c/isl12xx/Makefile stable/11/sys/modules/i2c/nxprtc/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/allwinner/axp209.c ============================================================================== --- stable/11/sys/arm/allwinner/axp209.c Mon Sep 11 22:18:01 2017 (r323466) +++ stable/11/sys/arm/allwinner/axp209.c Mon Sep 11 22:21:15 2017 (r323467) @@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include @@ -59,7 +58,6 @@ __FBSDID("$FreeBSD$"); #include -#include "iicbus_if.h" #include "gpio_if.h" #include "regdev_if.h" @@ -602,7 +600,6 @@ enum AXP2XX_TYPE { struct axp2xx_softc { device_t dev; - uint32_t addr; struct resource * res[1]; void * intrcookie; struct intr_config_hook intr_hook; @@ -641,57 +638,15 @@ static struct resource_spec axp_res_spec[] = { static int axp2xx_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size) { - struct axp2xx_softc *sc = device_get_softc(dev); - struct iic_msg msg[2]; - msg[0].slave = sc->addr; - msg[0].flags = IIC_M_WR; - msg[0].len = 1; - msg[0].buf = ® - - msg[1].slave = sc->addr; - msg[1].flags = IIC_M_RD; - msg[1].len = size; - msg[1].buf = data; - - return (iicbus_transfer(dev, msg, 2)); + return (iicdev_readfrom(dev, reg, data, size, IIC_INTRWAIT)); } static int axp2xx_write(device_t dev, uint8_t reg, uint8_t data) { - uint8_t buffer[2]; - struct axp2xx_softc *sc = device_get_softc(dev); - struct iic_msg msg[2]; - int nmsgs = 0; - if (sc->type == AXP209) { - buffer[0] = reg; - buffer[1] = data; - - msg[0].slave = sc->addr; - msg[0].flags = IIC_M_WR; - msg[0].len = 2; - msg[0].buf = buffer; - - nmsgs = 1; - } - else if (sc->type == AXP221) { - msg[0].slave = sc->addr; - msg[0].flags = IIC_M_WR; - msg[0].len = 1; - msg[0].buf = ® - - msg[1].slave = sc->addr; - msg[1].flags = IIC_M_WR; - msg[1].len = 1; - msg[1].buf = &data; - nmsgs = 2; - } - else - return (EINVAL); - - return (iicbus_transfer(dev, msg, nmsgs)); + return (iicdev_writeto(dev, reg, &data, sizeof(data), IIC_INTRWAIT)); } static int @@ -1239,7 +1194,6 @@ axp2xx_start(void *pdev) dev = pdev; sc = device_get_softc(dev); - sc->addr = iicbus_get_addr(dev); sc->dev = dev; if (bootverbose) { @@ -1451,4 +1405,4 @@ EARLY_DRIVER_MODULE(ofw_gpiobus, axp2xx_pmu, ofw_gpiob DRIVER_MODULE(gpioc, axp2xx_pmu, gpioc_driver, gpioc_devclass, 0, 0); MODULE_VERSION(axp2xx, 1); -MODULE_DEPEND(axp2xx, iicbus, 1, 1, 1); +MODULE_DEPEND(axp2xx, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER); Modified: stable/11/sys/conf/NOTES ============================================================================== --- stable/11/sys/conf/NOTES Mon Sep 11 22:18:01 2017 (r323466) +++ stable/11/sys/conf/NOTES Mon Sep 11 22:21:15 2017 (r323467) @@ -2567,15 +2567,14 @@ device iicoc # OpenCores I2C controller support # I2C peripheral devices # -# ds133x Dallas Semiconductor DS1337, DS1338 and DS1339 RTC -# ds1374 Dallas Semiconductor DS1374 RTC -# ds1672 Dallas Semiconductor DS1672 RTC -# s35390a Seiko Instruments S-35390A RTC -# -device ds133x -device ds1374 -device ds1672 -device s35390a +device ds1307 # Dallas DS1307 RTC and compatible +device ds13rtc # All Dallas/Maxim ds13xx chips +device ds1672 # Dallas DS1672 RTC +device ds3231 # Dallas DS3231 RTC + temperature +device icee # AT24Cxxx and compatible EEPROMs +device lm75 # LM75 compatible temperature sensor +device nxprtc # NXP RTCs: PCA/PFC212x PCA/PCF85xx +device s35390a # Seiko Instruments S-35390A RTC # Parallel-Port Bus # Modified: stable/11/sys/conf/files ============================================================================== --- stable/11/sys/conf/files Mon Sep 11 22:18:01 2017 (r323466) +++ stable/11/sys/conf/files Mon Sep 11 22:21:15 2017 (r323467) @@ -1686,8 +1686,7 @@ dev/ie/if_ie.c optional ie isa nowerror dev/ie/if_ie_isa.c optional ie isa dev/iicbus/ad7418.c optional ad7418 dev/iicbus/ds1307.c optional ds1307 -dev/iicbus/ds133x.c optional ds133x -dev/iicbus/ds1374.c optional ds1374 +dev/iicbus/ds13rtc.c optional ds13rtc | ds133x | ds1374 dev/iicbus/ds1672.c optional ds1672 dev/iicbus/ds3231.c optional ds3231 dev/iicbus/icee.c optional icee @@ -1702,9 +1701,10 @@ dev/iicbus/iiconf.c optional iicbus dev/iicbus/iicsmb.c optional iicsmb \ dependency "iicbus_if.h" dev/iicbus/iicoc.c optional iicoc +dev/iicbus/isl12xx.c optional isl12xx dev/iicbus/lm75.c optional lm75 +dev/iicbus/nxprtc.c optional nxprtc | pcf8563 dev/iicbus/ofw_iicbus.c optional fdt iicbus -dev/iicbus/pcf8563.c optional pcf8563 dev/iicbus/s35390a.c optional s35390a dev/iir/iir.c optional iir dev/iir/iir_ctrl.c optional iir Modified: stable/11/sys/dev/iicbus/ds1307.c ============================================================================== --- stable/11/sys/dev/iicbus/ds1307.c Mon Sep 11 22:18:01 2017 (r323466) +++ stable/11/sys/dev/iicbus/ds1307.c Mon Sep 11 22:21:15 2017 (r323467) @@ -56,43 +56,36 @@ __FBSDID("$FreeBSD$"); struct ds1307_softc { device_t sc_dev; - int sc_year0; - struct intr_config_hook enum_hook; - uint16_t sc_addr; /* DS1307 slave address. */ + struct intr_config_hook + enum_hook; uint8_t sc_ctrl; - int sc_mcp7941x; + bool sc_mcp7941x; + bool sc_use_ampm; }; static void ds1307_start(void *); #ifdef FDT static const struct ofw_compat_data ds1307_compat_data[] = { - {"dallas,ds1307", (uintptr_t)"Maxim DS1307 RTC"}, - {"maxim,ds1307", (uintptr_t)"Maxim DS1307 RTC"}, - {"microchip,mcp7941x", (uintptr_t)"Microchip MCP7941x RTC"}, + {"dallas,ds1307", (uintptr_t)"Dallas DS1307 RTC"}, + {"maxim,ds1307", (uintptr_t)"Maxim DS1307 RTC"}, + {"microchip,mcp7941x", (uintptr_t)"Microchip MCP7941x RTC"}, { NULL, 0 } }; #endif static int -ds1307_read(device_t dev, uint16_t addr, uint8_t reg, uint8_t *data, size_t len) +ds1307_read1(device_t dev, uint8_t reg, uint8_t *data) { - struct iic_msg msg[2] = { - { addr, IIC_M_WR | IIC_M_NOSTOP, 1, ® }, - { addr, IIC_M_RD, len, data }, - }; - return (iicbus_transfer(dev, msg, nitems(msg))); + return (iicdev_readfrom(dev, reg, data, 1, IIC_INTRWAIT)); } static int -ds1307_write(device_t dev, uint16_t addr, uint8_t *data, size_t len) +ds1307_write1(device_t dev, uint8_t reg, uint8_t data) { - struct iic_msg msg[1] = { - { addr, IIC_M_WR, len, data }, - }; - return (iicbus_transfer(dev, msg, nitems(msg))); + return (iicdev_writeto(dev, reg, &data, 1, IIC_INTRWAIT)); } static int @@ -101,8 +94,7 @@ ds1307_ctrl_read(struct ds1307_softc *sc) int error; sc->sc_ctrl = 0; - error = ds1307_read(sc->sc_dev, sc->sc_addr, DS1307_CONTROL, - &sc->sc_ctrl, sizeof(sc->sc_ctrl)); + error = ds1307_read1(sc->sc_dev, DS1307_CONTROL, &sc->sc_ctrl); if (error) { device_printf(sc->sc_dev, "cannot read from RTC.\n"); return (error); @@ -115,11 +107,10 @@ static int ds1307_ctrl_write(struct ds1307_softc *sc) { int error; - uint8_t data[2]; + uint8_t ctrl; - data[0] = DS1307_CONTROL; - data[1] = sc->sc_ctrl & DS1307_CTRL_MASK; - error = ds1307_write(sc->sc_dev, sc->sc_addr, data, sizeof(data)); + ctrl = sc->sc_ctrl & DS1307_CTRL_MASK; + error = ds1307_write1(sc->sc_dev, DS1307_CONTROL, ctrl); if (error != 0) device_printf(sc->sc_dev, "cannot write to RTC.\n"); @@ -127,54 +118,6 @@ ds1307_ctrl_write(struct ds1307_softc *sc) } static int -ds1307_osc_enable(struct ds1307_softc *sc) -{ - int error; - uint8_t data[2], secs; - - secs = 0; - error = ds1307_read(sc->sc_dev, sc->sc_addr, DS1307_SECS, - &secs, sizeof(secs)); - if (error) { - device_printf(sc->sc_dev, "cannot read from RTC.\n"); - return (error); - } - /* Check if the oscillator is disabled. */ - if ((secs & DS1307_SECS_CH) == 0) - return (0); - device_printf(sc->sc_dev, "clock was halted, check the battery.\n"); - data[0] = DS1307_SECS; - data[1] = secs & DS1307_SECS_MASK; - error = ds1307_write(sc->sc_dev, sc->sc_addr, data, sizeof(data)); - if (error != 0) - device_printf(sc->sc_dev, "cannot write to RTC.\n"); - - return (error); -} - -static int -ds1307_set_24hrs_mode(struct ds1307_softc *sc) -{ - int error; - uint8_t data[2], hour; - - hour = 0; - error = ds1307_read(sc->sc_dev, sc->sc_addr, DS1307_HOUR, - &hour, sizeof(hour)); - if (error) { - device_printf(sc->sc_dev, "cannot read from RTC.\n"); - return (error); - } - data[0] = DS1307_HOUR; - data[1] = hour & DS1307_HOUR_MASK; - error = ds1307_write(sc->sc_dev, sc->sc_addr, data, sizeof(data)); - if (error != 0) - device_printf(sc->sc_dev, "cannot write to RTC.\n"); - - return (error); -} - -static int ds1307_sqwe_sysctl(SYSCTL_HANDLER_ARGS) { int sqwe, error, newv, sqwe_bit; @@ -283,7 +226,7 @@ ds1307_probe(device_t dev) #else device_set_desc(dev, "Maxim DS1307 RTC"); - return (BUS_PROBE_DEFAULT); + return (BUS_PROBE_NOWILDCARD); #endif } @@ -294,13 +237,13 @@ ds1307_attach(device_t dev) sc = device_get_softc(dev); sc->sc_dev = dev; - sc->sc_addr = iicbus_get_addr(dev); - sc->sc_year0 = 1900; sc->enum_hook.ich_func = ds1307_start; sc->enum_hook.ich_arg = dev; +#ifdef FDT if (ofw_bus_is_compatible(dev, "microchip,mcp7941x")) sc->sc_mcp7941x = 1; +#endif /* * We have to wait until interrupts are enabled. Usually I2C read @@ -312,6 +255,14 @@ ds1307_attach(device_t dev) return (0); } +static int +ds1307_detach(device_t dev) +{ + + clock_unregister(dev); + return (0); +} + static void ds1307_start(void *xdev) { @@ -320,6 +271,7 @@ ds1307_start(void *xdev) struct sysctl_ctx_list *ctx; struct sysctl_oid *tree_node; struct sysctl_oid_list *tree; + uint8_t secs; dev = (device_t)xdev; sc = device_get_softc(dev); @@ -328,12 +280,16 @@ ds1307_start(void *xdev) tree = SYSCTL_CHILDREN(tree_node); config_intrhook_disestablish(&sc->enum_hook); - /* Set the 24 hours mode. */ - if (ds1307_set_24hrs_mode(sc) != 0) + + /* Check if the oscillator is disabled. */ + if (ds1307_read1(sc->sc_dev, DS1307_SECS, &secs) != 0) { + device_printf(sc->sc_dev, "cannot read from RTC.\n"); return; - /* Enable the oscillator if halted. */ - if (ds1307_osc_enable(sc) != 0) - return; + } + if ((secs & DS1307_SECS_CH) != 0) { + device_printf(sc->sc_dev, + "WARNING: RTC clock stopped, check the battery.\n"); + } /* Configuration parameters. */ SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "sqwe", @@ -347,8 +303,13 @@ ds1307_start(void *xdev) CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE, sc, 0, ds1307_sqw_out_sysctl, "IU", "DS1307 square-wave output state"); - /* 1 second resolution. */ - clock_register(dev, 1000000); + /* + * Register as a clock with 1 second resolution. Schedule the + * clock_settime() method to be called just after top-of-second; + * resetting the time resets top-of-second in the hardware. + */ + clock_register_flags(dev, 1000000, CLOCKF_SETTIME_NO_ADJ); + clock_schedule(dev, 1); } static int @@ -357,56 +318,85 @@ ds1307_gettime(device_t dev, struct timespec *ts) int error; struct clocktime ct; struct ds1307_softc *sc; - uint8_t data[7]; + uint8_t data[7], hourmask; sc = device_get_softc(dev); - memset(data, 0, sizeof(data)); - error = ds1307_read(sc->sc_dev, sc->sc_addr, DS1307_SECS, - data, sizeof(data)); + error = iicdev_readfrom(sc->sc_dev, DS1307_SECS, data, sizeof(data), + IIC_INTRWAIT); if (error != 0) { device_printf(dev, "cannot read from RTC.\n"); return (error); } + + /* If the clock halted, we don't have good data. */ + if (data[DS1307_SECS] & DS1307_SECS_CH) + return (EINVAL); + + /* If chip is in AM/PM mode remember that. */ + if (data[DS1307_HOUR] & DS1307_HOUR_USE_AMPM) { + sc->sc_use_ampm = true; + hourmask = DS1307_HOUR_MASK_12HR; + } else + hourmask = DS1307_HOUR_MASK_24HR; + ct.nsec = 0; - ct.sec = FROMBCD(data[DS1307_SECS] & DS1307_SECS_MASK); - ct.min = FROMBCD(data[DS1307_MINS] & DS1307_MINS_MASK); - ct.hour = FROMBCD(data[DS1307_HOUR] & DS1307_HOUR_MASK); - ct.day = FROMBCD(data[DS1307_DATE] & DS1307_DATE_MASK); - ct.dow = data[DS1307_WEEKDAY] & DS1307_WEEKDAY_MASK; - ct.mon = FROMBCD(data[DS1307_MONTH] & DS1307_MONTH_MASK); - ct.year = FROMBCD(data[DS1307_YEAR] & DS1307_YEAR_MASK); - ct.year += sc->sc_year0; - if (ct.year < POSIX_BASE_YEAR) - ct.year += 100; /* assume [1970, 2069] */ + ct.sec = FROMBCD(data[DS1307_SECS] & DS1307_SECS_MASK); + ct.min = FROMBCD(data[DS1307_MINS] & DS1307_MINS_MASK); + ct.hour = FROMBCD(data[DS1307_HOUR] & hourmask); + ct.day = FROMBCD(data[DS1307_DATE] & DS1307_DATE_MASK); + ct.mon = FROMBCD(data[DS1307_MONTH] & DS1307_MONTH_MASK); + ct.year = FROMBCD(data[DS1307_YEAR] & DS1307_YEAR_MASK); + if (sc->sc_use_ampm) { + if (ct.hour == 12) + ct.hour = 0; + if (data[DS1307_HOUR] & DS1307_HOUR_IS_PM) + ct.hour += 12; + } + return (clock_ct_to_ts(&ct, ts)); } static int ds1307_settime(device_t dev, struct timespec *ts) { - int error; struct clocktime ct; struct ds1307_softc *sc; - uint8_t data[8]; + int error; + uint8_t data[7]; + uint8_t pmflags; sc = device_get_softc(dev); - /* Accuracy is only one second. */ - if (ts->tv_nsec >= 500000000) - ts->tv_sec++; - ts->tv_nsec = 0; + + /* + * We request a timespec with no resolution-adjustment. That also + * disables utc adjustment, so apply that ourselves. + */ + ts->tv_sec -= utc_offset(); clock_ts_to_ct(ts, &ct); - memset(data, 0, sizeof(data)); - data[0] = DS1307_SECS; - data[DS1307_SECS + 1] = TOBCD(ct.sec); - data[DS1307_MINS + 1] = TOBCD(ct.min); - data[DS1307_HOUR + 1] = TOBCD(ct.hour); - data[DS1307_DATE + 1] = TOBCD(ct.day); - data[DS1307_WEEKDAY + 1] = ct.dow; - data[DS1307_MONTH + 1] = TOBCD(ct.mon); - data[DS1307_YEAR + 1] = TOBCD(ct.year % 100); + + /* If the chip is in AM/PM mode, adjust hour and set flags as needed. */ + if (sc->sc_use_ampm) { + pmflags = DS1307_HOUR_USE_AMPM; + if (ct.hour >= 12) { + ct.hour -= 12; + pmflags |= DS1307_HOUR_IS_PM; + } + if (ct.hour == 0) + ct.hour = 12; + } else + pmflags = 0; + + data[DS1307_SECS] = TOBCD(ct.sec); + data[DS1307_MINS] = TOBCD(ct.min); + data[DS1307_HOUR] = TOBCD(ct.hour) | pmflags; + data[DS1307_DATE] = TOBCD(ct.day); + data[DS1307_WEEKDAY] = ct.dow; + data[DS1307_MONTH] = TOBCD(ct.mon); + data[DS1307_YEAR] = TOBCD(ct.year % 100); /* Write the time back to RTC. */ - error = ds1307_write(dev, sc->sc_addr, data, sizeof(data)); + error = iicdev_writeto(sc->sc_dev, DS1307_SECS, data, sizeof(data), + IIC_INTRWAIT); if (error != 0) device_printf(dev, "cannot write to RTC.\n"); @@ -416,6 +406,7 @@ ds1307_settime(device_t dev, struct timespec *ts) static device_method_t ds1307_methods[] = { DEVMETHOD(device_probe, ds1307_probe), DEVMETHOD(device_attach, ds1307_attach), + DEVMETHOD(device_detach, ds1307_detach), DEVMETHOD(clock_gettime, ds1307_gettime), DEVMETHOD(clock_settime, ds1307_settime), Modified: stable/11/sys/dev/iicbus/ds1307reg.h ============================================================================== --- stable/11/sys/dev/iicbus/ds1307reg.h Mon Sep 11 22:18:01 2017 (r323466) +++ stable/11/sys/dev/iicbus/ds1307reg.h Mon Sep 11 22:21:15 2017 (r323467) @@ -39,7 +39,10 @@ #define DS1307_MINS 0x01 #define DS1307_MINS_MASK 0x7f #define DS1307_HOUR 0x02 -#define DS1307_HOUR_MASK 0x3f +#define DS1307_HOUR_MASK_12HR 0x1f +#define DS1307_HOUR_MASK_24HR 0x3f +#define DS1307_HOUR_IS_PM 0x20 +#define DS1307_HOUR_USE_AMPM 0x40 #define DS1307_WEEKDAY 0x03 #define DS1307_WEEKDAY_MASK 0x07 #define DS1307_DATE 0x04 Copied and modified: stable/11/sys/dev/iicbus/ds13rtc.c (from r322473, head/sys/dev/iicbus/ds13rtc.c) ============================================================================== --- head/sys/dev/iicbus/ds13rtc.c Sun Aug 13 21:02:40 2017 (r322473, copy source) +++ stable/11/sys/dev/iicbus/ds13rtc.c Mon Sep 11 22:21:15 2017 (r323467) @@ -495,7 +495,7 @@ ds13rtc_get_chiptype(device_t dev) * We can only attach if provided a chiptype hint string. */ if (resource_string_value(device_get_name(dev), - device_get_unit(dev), "chiptype", &htype) != 0) + device_get_unit(dev), "compatible", &htype) != 0) return (TYPE_NONE); /* Modified: stable/11/sys/dev/iicbus/ds3231.c ============================================================================== --- stable/11/sys/dev/iicbus/ds3231.c Mon Sep 11 22:18:01 2017 (r323466) +++ stable/11/sys/dev/iicbus/ds3231.c Mon Sep 11 22:21:15 2017 (r323467) @@ -62,29 +62,23 @@ struct ds3231_softc { uint16_t sc_addr; /* DS3231 slave address. */ uint8_t sc_ctrl; uint8_t sc_status; + bool sc_use_ampm; }; static void ds3231_start(void *); static int -ds3231_read(device_t dev, uint16_t addr, uint8_t reg, uint8_t *data, size_t len) +ds3231_read1(device_t dev, uint8_t reg, uint8_t *data) { - struct iic_msg msg[2] = { - { addr, IIC_M_WR | IIC_M_NOSTOP, 1, ® }, - { addr, IIC_M_RD, len, data }, - }; - return (iicbus_transfer(dev, msg, nitems(msg))); + return (iicdev_readfrom(dev, reg, data, 1, IIC_INTRWAIT)); } static int -ds3231_write(device_t dev, uint16_t addr, uint8_t *data, size_t len) +ds3231_write1(device_t dev, uint8_t reg, uint8_t data) { - struct iic_msg msg[1] = { - { addr, IIC_M_WR, len, data }, - }; - return (iicbus_transfer(dev, msg, nitems(msg))); + return (iicdev_writeto(dev, reg, &data, 1, IIC_INTRWAIT)); } static int @@ -92,14 +86,11 @@ ds3231_ctrl_read(struct ds3231_softc *sc) { int error; - sc->sc_ctrl = 0; - error = ds3231_read(sc->sc_dev, sc->sc_addr, DS3231_CONTROL, - &sc->sc_ctrl, sizeof(sc->sc_ctrl)); + error = ds3231_read1(sc->sc_dev, DS3231_CONTROL, &sc->sc_ctrl); if (error) { device_printf(sc->sc_dev, "cannot read from RTC.\n"); return (error); } - return (0); } @@ -107,12 +98,11 @@ static int ds3231_ctrl_write(struct ds3231_softc *sc) { int error; - uint8_t data[2]; + uint8_t data; - data[0] = DS3231_CONTROL; /* Always enable the oscillator. Always disable both alarms. */ - data[1] = sc->sc_ctrl & ~DS3231_CTRL_MASK; - error = ds3231_write(sc->sc_dev, sc->sc_addr, data, sizeof(data)); + data = sc->sc_ctrl & ~DS3231_CTRL_MASK; + error = ds3231_write1(sc->sc_dev, DS3231_CONTROL, data); if (error != 0) device_printf(sc->sc_dev, "cannot write to RTC.\n"); @@ -124,9 +114,7 @@ ds3231_status_read(struct ds3231_softc *sc) { int error; - sc->sc_status = 0; - error = ds3231_read(sc->sc_dev, sc->sc_addr, DS3231_STATUS, - &sc->sc_status, sizeof(sc->sc_status)); + error = ds3231_read1(sc->sc_dev, DS3231_STATUS, &sc->sc_status); if (error) { device_printf(sc->sc_dev, "cannot read from RTC.\n"); return (error); @@ -139,15 +127,14 @@ static int ds3231_status_write(struct ds3231_softc *sc, int clear_a1, int clear_a2) { int error; - uint8_t data[2]; + uint8_t data; - data[0] = DS3231_STATUS; - data[1] = sc->sc_status; + data = sc->sc_status; if (clear_a1 == 0) - data[1] |= DS3231_STATUS_A1F; + data |= DS3231_STATUS_A1F; if (clear_a2 == 0) - data[1] |= DS3231_STATUS_A2F; - error = ds3231_write(sc->sc_dev, sc->sc_addr, data, sizeof(data)); + data |= DS3231_STATUS_A2F; + error = ds3231_write1(sc->sc_dev, DS3231_STATUS, data); if (error != 0) device_printf(sc->sc_dev, "cannot write to RTC.\n"); @@ -155,36 +142,14 @@ ds3231_status_write(struct ds3231_softc *sc, int clear } static int -ds3231_set_24hrs_mode(struct ds3231_softc *sc) -{ - int error; - uint8_t data[2], hour; - - hour = 0; - error = ds3231_read(sc->sc_dev, sc->sc_addr, DS3231_HOUR, - &hour, sizeof(hour)); - if (error) { - device_printf(sc->sc_dev, "cannot read from RTC.\n"); - return (error); - } - data[0] = DS3231_HOUR; - data[1] = hour & ~DS3231_C_MASK; - error = ds3231_write(sc->sc_dev, sc->sc_addr, data, sizeof(data)); - if (error != 0) - device_printf(sc->sc_dev, "cannot write to RTC.\n"); - - return (error); -} - -static int ds3231_temp_read(struct ds3231_softc *sc, int *temp) { int error, neg, t; uint8_t buf8[2]; uint16_t buf; - error = ds3231_read(sc->sc_dev, sc->sc_addr, DS3231_TEMP, - buf8, sizeof(buf8)); + error = iicdev_readfrom(sc->sc_dev, DS3231_TEMP, buf8, sizeof(buf8), + IIC_INTRWAIT); if (error != 0) return (error); buf = (buf8[0] << 8) | (buf8[1] & 0xff); @@ -426,6 +391,14 @@ ds3231_attach(device_t dev) return (0); } +static int +ds3231_detach(device_t dev) +{ + + clock_unregister(dev); + return (0); +} + static void ds3231_start(void *xdev) { @@ -446,20 +419,20 @@ ds3231_start(void *xdev) return; if (ds3231_status_read(sc) != 0) return; - /* Clear the OSF bit and ack any pending alarm interrupt. */ + /* + * Warn if the clock stopped, but don't restart it until the first + * clock_settime() call. + */ if (sc->sc_status & DS3231_STATUS_OSF) { device_printf(sc->sc_dev, - "oscillator has stopped, check the battery.\n"); - sc->sc_status &= ~DS3231_STATUS_OSF; + "WARNING: RTC clock stopped, check the battery.\n"); } + /* Ack any pending alarm interrupt. */ if (ds3231_status_write(sc, 1, 1) != 0) return; /* Always enable the oscillator. */ if (ds3231_ctrl_write(sc) != 0) return; - /* Set the 24 hours mode. */ - if (ds3231_set_24hrs_mode(sc) != 0) - return; /* Temperature. */ SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "temperature", @@ -485,8 +458,13 @@ ds3231_start(void *xdev) CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE, sc, 0, ds3231_en32khz_sysctl, "IU", "DS3231 enable the 32kHz output"); - /* 1 second resolution. */ - clock_register(dev, 1000000); + /* + * Register as a clock with 1 second resolution. Schedule the + * clock_settime() method to be called just after top-of-second; + * resetting the time resets top-of-second in the hardware. + */ + clock_register_flags(dev, 1000000, CLOCKF_SETTIME_NO_ADJ); + clock_schedule(dev, 1); } static int @@ -495,24 +473,45 @@ ds3231_gettime(device_t dev, struct timespec *ts) int c, error; struct clocktime ct; struct ds3231_softc *sc; - uint8_t data[7]; + uint8_t data[7], hourmask; sc = device_get_softc(dev); - memset(data, 0, sizeof(data)); - error = ds3231_read(sc->sc_dev, sc->sc_addr, DS3231_SECS, - data, sizeof(data)); + + /* If the clock halted, we don't have good data. */ + if ((error = ds3231_status_read(sc)) != 0) { + device_printf(dev, "cannot read from RTC.\n"); + return (error); + } + if (sc->sc_status & DS3231_STATUS_OSF) + return (EINVAL); + + error = iicdev_readfrom(sc->sc_dev, DS3231_SECS, data, sizeof(data), + IIC_INTRWAIT); if (error != 0) { device_printf(dev, "cannot read from RTC.\n"); return (error); } + + /* If chip is in AM/PM mode remember that. */ + if (data[DS3231_HOUR] & DS3231_HOUR_USE_AMPM) { + sc->sc_use_ampm = true; + hourmask = DS3231_HOUR_MASK_12HR; + } else + hourmask = DS3231_HOUR_MASK_24HR; + ct.nsec = 0; - ct.sec = FROMBCD(data[DS3231_SECS] & DS3231_SECS_MASK); - ct.min = FROMBCD(data[DS3231_MINS] & DS3231_MINS_MASK); - ct.hour = FROMBCD(data[DS3231_HOUR] & DS3231_HOUR_MASK); - ct.day = FROMBCD(data[DS3231_DATE] & DS3231_DATE_MASK); - ct.dow = data[DS3231_WEEKDAY] & DS3231_WEEKDAY_MASK; - ct.mon = FROMBCD(data[DS3231_MONTH] & DS3231_MONTH_MASK); - ct.year = FROMBCD(data[DS3231_YEAR] & DS3231_YEAR_MASK); + ct.sec = FROMBCD(data[DS3231_SECS] & DS3231_SECS_MASK); + ct.min = FROMBCD(data[DS3231_MINS] & DS3231_MINS_MASK); + ct.hour = FROMBCD(data[DS3231_HOUR] & hourmask); + ct.day = FROMBCD(data[DS3231_DATE] & DS3231_DATE_MASK); + ct.mon = FROMBCD(data[DS3231_MONTH] & DS3231_MONTH_MASK); + ct.year = FROMBCD(data[DS3231_YEAR] & DS3231_YEAR_MASK); + + /* + * If the century flag has toggled since we last saw it, there has been + * a century rollover. If this is the first time we're seeing it, + * remember the state so we can preserve its polarity on writes. + */ c = (data[DS3231_MONTH] & DS3231_C_MASK) ? 1 : 0; if (sc->sc_last_c == -1) sc->sc_last_c = c; @@ -524,6 +523,14 @@ ds3231_gettime(device_t dev, struct timespec *ts) if (ct.year < POSIX_BASE_YEAR) ct.year += 100; /* assume [1970, 2069] */ + /* If running in AM/PM mode, deal with it. */ + if (sc->sc_use_ampm) { + if (ct.hour == 12) + ct.hour = 0; + if (data[DS3231_HOUR] & DS3231_HOUR_IS_PM) + ct.hour += 12; + } + return (clock_ct_to_ts(&ct, ts)); } @@ -533,36 +540,71 @@ ds3231_settime(device_t dev, struct timespec *ts) int error; struct clocktime ct; struct ds3231_softc *sc; - uint8_t data[8]; + uint8_t data[7]; + uint8_t pmflags; sc = device_get_softc(dev); - /* Accuracy is only one second. */ - if (ts->tv_nsec >= 500000000) - ts->tv_sec++; - ts->tv_nsec = 0; + + /* + * We request a timespec with no resolution-adjustment. That also + * disables utc adjustment, so apply that ourselves. + */ + ts->tv_sec -= utc_offset(); clock_ts_to_ct(ts, &ct); - memset(data, 0, sizeof(data)); - data[0] = DS3231_SECS; - data[DS3231_SECS + 1] = TOBCD(ct.sec); - data[DS3231_MINS + 1] = TOBCD(ct.min); - data[DS3231_HOUR + 1] = TOBCD(ct.hour); - data[DS3231_DATE + 1] = TOBCD(ct.day); - data[DS3231_WEEKDAY + 1] = ct.dow; - data[DS3231_MONTH + 1] = TOBCD(ct.mon); - data[DS3231_YEAR + 1] = TOBCD(ct.year % 100); + + /* If the chip is in AM/PM mode, adjust hour and set flags as needed. */ + if (sc->sc_use_ampm) { + pmflags = DS3231_HOUR_USE_AMPM; + if (ct.hour >= 12) { + ct.hour -= 12; + pmflags |= DS3231_HOUR_IS_PM; + } + if (ct.hour == 0) + ct.hour = 12; + } else + pmflags = 0; + + data[DS3231_SECS] = TOBCD(ct.sec); + data[DS3231_MINS] = TOBCD(ct.min); + data[DS3231_HOUR] = TOBCD(ct.hour) | pmflags; + data[DS3231_DATE] = TOBCD(ct.day); + data[DS3231_WEEKDAY] = ct.dow; + data[DS3231_MONTH] = TOBCD(ct.mon); + data[DS3231_YEAR] = TOBCD(ct.year % 100); if (sc->sc_last_c) data[DS3231_MONTH] |= DS3231_C_MASK; + /* Write the time back to RTC. */ - error = ds3231_write(dev, sc->sc_addr, data, sizeof(data)); - if (error != 0) + error = iicdev_writeto(dev, DS3231_SECS, data, sizeof(data), + IIC_INTRWAIT); + if (error != 0) { device_printf(dev, "cannot write to RTC.\n"); + return (error); + } + /* + * Unlike most hardware, the osc-was-stopped bit does not clear itself + * after setting the time, it has to be manually written to zero. + */ + if (sc->sc_status & DS3231_STATUS_OSF) { + if ((error = ds3231_status_read(sc)) != 0) { + device_printf(dev, "cannot read from RTC.\n"); + return (error); + } + sc->sc_status &= ~DS3231_STATUS_OSF; + if ((error = ds3231_status_write(sc, 0, 0)) != 0) { + device_printf(dev, "cannot write to RTC.\n"); + return (error); + } + } + return (error); } static device_method_t ds3231_methods[] = { DEVMETHOD(device_probe, ds3231_probe), DEVMETHOD(device_attach, ds3231_attach), + DEVMETHOD(device_detach, ds3231_detach), DEVMETHOD(clock_gettime, ds3231_gettime), DEVMETHOD(clock_settime, ds3231_settime), Modified: stable/11/sys/dev/iicbus/ds3231reg.h ============================================================================== --- stable/11/sys/dev/iicbus/ds3231reg.h Mon Sep 11 22:18:01 2017 (r323466) +++ stable/11/sys/dev/iicbus/ds3231reg.h Mon Sep 11 22:21:15 2017 (r323467) @@ -38,7 +38,10 @@ #define DS3231_MINS 0x01 #define DS3231_MINS_MASK 0x7f #define DS3231_HOUR 0x02 -#define DS3231_HOUR_MASK 0x3f +#define DS3231_HOUR_MASK_12HR 0x3f +#define DS3231_HOUR_MASK_24HR 0x1f +#define DS3231_HOUR_IS_PM 0x20 +#define DS3231_HOUR_USE_AMPM 0x40 #define DS3231_WEEKDAY 0x03 #define DS3231_WEEKDAY_MASK 0x07 #define DS3231_DATE 0x04 Copied: stable/11/sys/dev/iicbus/isl12xx.c (from r321841, head/sys/dev/iicbus/isl12xx.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/dev/iicbus/isl12xx.c Mon Sep 11 22:21:15 2017 (r323467, copy of r321841, head/sys/dev/iicbus/isl12xx.c) @@ -0,0 +1,354 @@ +/*- + * Copyright (c) 2017 Ian Lepore. All rights reserved. + * + * 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 ``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 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * Driver for ISL12xx family i2c realtime clocks: + * - ISL1209 = 2B sram, tamper/event timestamp + * - ISL1218 = 8B sram, DS13xx pin compatible (but not software compatible) + * - ISL1219 = 2B sram, tamper/event timestamp + * - ISL1220 = 8B sram, separate Fout + * - ISL1221 = 2B sram, separate Fout, tamper/event timestamp + * + * This driver supports only the basic RTC functionality in all these chips. + */ + +#include "opt_platform.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef FDT +#include +#include +#endif + +#include +#include + +#include "clock_if.h" +#include "iicbus_if.h" + +/* + * All register and bit names as found in the datasheet. When a bit name ends + * in 'B' that stands for "bar" and it is an active-low signal; something named + * "EVENB" implies 1=event-disable, 0=event-enable. + */ + +#define ISL12XX_SC_REG 0x00 /* RTC Seconds */ + +#define ISL12XX_SR_REG 0x07 /* Status */ +#define ISL12XX_SR_ARST (1u << 7) /* Auto-reset on status read */ +#define ISL12XX_SR_XTOSCB (1u << 5) /* Osc disable (use ext osc) */ +#define ISL12XX_SR_WRTC (1u << 4) /* Write RTC enable */ +#define ISL12XX_SR_EVT (1u << 3) /* Event occurred (w0c) */ +#define ISL12XX_SR_ALM (1u << 2) /* Alarm occurred (w0c) */ +#define ISL12XX_SR_BAT (1u << 1) /* Running on battery (w0c) */ +#define ISL12XX_SR_RTCF (1u << 0) /* RTC fail (power loss) */ +#define ISL12XX_SR_W0C_BITS (ISL12XX_SR_BAT | ISL12XX_SR_ALM | ISL12XX_SR_EVT) + +#define ISL12XX_INT_REG 0x08 /* Interrupts */ +#define ISL12XX_INT_IM (1u << 7) /* Alarm interrupt mode */ +#define ISL12XX_INT_ALME (1u << 6) /* Alarm enable */ +#define ISL12XX_INT_LPMODE (1u << 5) /* Low Power mode */ +#define ISL12XX_INT_FOBATB (1u << 4) /* Fout/IRQ disabled on bat */ +#define ISL12XX_INT_FO_SHIFT 0 /* Frequency output select */ +#define ISL12XX_INT_FO_MASK 0x0f /* shift and mask. */ + +#define ISL12XX_EV_REG 0x09 /* Event */ +#define ISL12XX_EV_EVIENB (1u << 7) /* Disable internal pullup */ +#define ISL12XX_EV_EVBATB (1u << 6) /* Disable ev detect on bat */ +#define ISL12XX_EV_RTCHLT (1u << 5) /* Halt RTC on event */ +#define ISL12XX_EV_EVEN (1u << 4) /* Event detect enable */ +#define ISL12XX_EV_EHYS_SHIFT 2 /* Event input hysteresis */ +#define ISL12XX_EV_EHYS_MASK 0x03 /* selection; see datasheet */ +#define ISL12XX_EV_ESMP_SHIFT 0 /* Event input sample rate */ +#define ISL12XX_EV_ESMP_MASK 0x03 /* selection; see datasheet */ + +#define ISL12XX_ATR_REG 0x0a /* Analog trim (osc adjust) */ + +#define ISL12XX_DTR_REG 0x0b /* Digital trim (osc adjust) */ + +#define ISL12XX_SCA_REG 0x0c /* Alarm seconds */ + +#define ISL12XX_USR1_REG 0x12 /* User byte 1 */ *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable-11@freebsd.org Mon Sep 11 22:28:40 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 05AB7E03826; Mon, 11 Sep 2017 22:28:40 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id C5232759B5; Mon, 11 Sep 2017 22:28:39 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BMSdg3065616; Mon, 11 Sep 2017 22:28:39 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BMScMV065607; Mon, 11 Sep 2017 22:28:38 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709112228.v8BMScMV065607@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 22:28:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323468 - in stable/11/sys/arm: conf freescale/imx X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys/arm: conf freescale/imx X-SVN-Commit-Revision: 323468 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 22:28:40 -0000 Author: ian Date: Mon Sep 11 22:28:38 2017 New Revision: 323468 URL: https://svnweb.freebsd.org/changeset/base/323468 Log: MFC r321938, r322015 r321938: Fix the interface to imx_iomux_gpr_get/set(). The functions were defined as taking a register number, and that would get multiplied by 4 to make a register address. But the header file that consumers have to reference this stuff publishes register addresses, not numbers. So now everything works in terms of register addresses. Note that the HDMI init code was writing into the wrong register before this change. Apparently whatever it wrote to was harmless, and apparently HDMI was working because uboot had set up the right bits. r322015: Add an ahci driver for imx6. This was submitted by Rogiel Sulzbach (thank you!) but has a few last-minute changes by me, mostly where the code interfaces to my still-utterly-deficient imx6_ccm clocks implementation. So blame me for any mistakes. Submitted by: Rogiel Sulzbach Differential Revision: https://reviews.freebsd.org/D11177 Added: stable/11/sys/arm/freescale/imx/imx6_ahci.c - copied unchanged from r322015, head/sys/arm/freescale/imx/imx6_ahci.c Modified: stable/11/sys/arm/conf/IMX6 stable/11/sys/arm/freescale/imx/files.imx6 stable/11/sys/arm/freescale/imx/imx6_ccm.c stable/11/sys/arm/freescale/imx/imx6_ccmreg.h stable/11/sys/arm/freescale/imx/imx_ccmvar.h stable/11/sys/arm/freescale/imx/imx_iomux.c stable/11/sys/arm/freescale/imx/imx_iomuxreg.h stable/11/sys/arm/freescale/imx/imx_iomuxvar.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/conf/IMX6 ============================================================================== --- stable/11/sys/arm/conf/IMX6 Mon Sep 11 22:21:15 2017 (r323467) +++ stable/11/sys/arm/conf/IMX6 Mon Sep 11 22:28:38 2017 (r323468) @@ -78,6 +78,9 @@ device da # Direct Access (disks) device cd # CD device pass # Passthrough device (direct ATA/SCSI access) +# ATA controllers +device ahci # AHCI-compatible SATA controllers + # USB support device ehci # OHCI USB interface device usb # USB Bus (required) Modified: stable/11/sys/arm/freescale/imx/files.imx6 ============================================================================== --- stable/11/sys/arm/freescale/imx/files.imx6 Mon Sep 11 22:21:15 2017 (r323467) +++ stable/11/sys/arm/freescale/imx/files.imx6 Mon Sep 11 22:28:38 2017 (r323468) @@ -25,6 +25,7 @@ arm/freescale/imx/imx_i2c.c optional fsliic arm/freescale/imx/imx6_sdma.c optional sdma arm/freescale/imx/imx6_audmux.c optional sound arm/freescale/imx/imx6_ssi.c optional sound +arm/freescale/imx/imx6_ahci.c optional ahci arm/arm/hdmi_if.m optional hdmi arm/freescale/imx/imx6_hdmi.c optional hdmi Copied: stable/11/sys/arm/freescale/imx/imx6_ahci.c (from r322015, head/sys/arm/freescale/imx/imx6_ahci.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/arm/freescale/imx/imx6_ahci.c Mon Sep 11 22:28:38 2017 (r323468, copy of r322015, head/sys/arm/freescale/imx/imx6_ahci.c) @@ -0,0 +1,358 @@ +/*- + * Copyright (c) 2017 Rogiel Sulzbach + * All rights reserved. + * + * 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. + */ + +#include + +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#define SATA_TIMER1MS 0x000000e0 + +#define SATA_P0PHYCR 0x00000178 +#define SATA_P0PHYCR_CR_READ (1 << 19) +#define SATA_P0PHYCR_CR_WRITE (1 << 18) +#define SATA_P0PHYCR_CR_CAP_DATA (1 << 17) +#define SATA_P0PHYCR_CR_CAP_ADDR (1 << 16) +#define SATA_P0PHYCR_CR_DATA_IN(v) ((v) & 0xffff) + +#define SATA_P0PHYSR 0x0000017c +#define SATA_P0PHYSR_CR_ACK (1 << 18) +#define SATA_P0PHYSR_CR_DATA_OUT(v) ((v) & 0xffff) + +/* phy registers */ +#define SATA_PHY_CLOCK_RESET 0x7f3f +#define SATA_PHY_CLOCK_RESET_RST (1 << 0) + +#define SATA_PHY_LANE0_OUT_STAT 0x2003 +#define SATA_PHY_LANE0_OUT_STAT_RX_PLL_STATE (1 << 1) + +static int +imx6_ahci_phy_ctrl(struct ahci_controller* sc, uint32_t bitmask, bool on) +{ + uint32_t v; + int timeout; + bool state; + + v = ATA_INL(sc->r_mem, SATA_P0PHYCR); + if (on) { + v |= bitmask; + } else { + v &= ~bitmask; + } + ATA_OUTL(sc->r_mem, SATA_P0PHYCR, v); + + for (timeout = 5000; timeout > 0; --timeout) { + v = ATA_INL(sc->r_mem, SATA_P0PHYSR); + state = (v & SATA_P0PHYSR_CR_ACK) == SATA_P0PHYSR_CR_ACK; + if(state == on) { + break; + } + DELAY(100); + } + + if (timeout > 0) { + return (0); + } + + return (ETIMEDOUT); +} + +static int +imx6_ahci_phy_addr(struct ahci_controller* sc, uint32_t addr) +{ + int error; + + DELAY(100); + + ATA_OUTL(sc->r_mem, SATA_P0PHYCR, addr); + + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_ADDR, true); + if (error != 0) { + device_printf(sc->dev, + "%s: timeout on SATA_P0PHYCR_CR_CAP_ADDR=1\n", + __FUNCTION__); + return (error); + } + + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_ADDR, false); + if (error != 0) { + device_printf(sc->dev, + "%s: timeout on SATA_P0PHYCR_CR_CAP_ADDR=0\n", + __FUNCTION__); + return (error); + } + + return (0); +} + +static int +imx6_ahci_phy_write(struct ahci_controller* sc, uint32_t addr, + uint16_t data) +{ + int error; + + error = imx6_ahci_phy_addr(sc, addr); + if (error != 0) { + device_printf(sc->dev, "%s: error on imx6_ahci_phy_addr\n", + __FUNCTION__); + return (error); + } + + ATA_OUTL(sc->r_mem, SATA_P0PHYCR, data); + + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_DATA, true); + if (error != 0) { + device_printf(sc->dev, + "%s: error on SATA_P0PHYCR_CR_CAP_DATA=1\n", __FUNCTION__); + return (error); + } + if (imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_CAP_DATA, false) != 0) { + device_printf(sc->dev, + "%s: error on SATA_P0PHYCR_CR_CAP_DATA=0\n", __FUNCTION__); + return (error); + } + + if ((addr == SATA_PHY_CLOCK_RESET) && data) { + /* we can't check ACK after RESET */ + ATA_OUTL(sc->r_mem, SATA_P0PHYCR, + SATA_P0PHYCR_CR_DATA_IN(data) | SATA_P0PHYCR_CR_WRITE); + return (0); + } + + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_WRITE, true); + if (error != 0) { + device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_WRITE=1\n", + __FUNCTION__); + return (error); + } + + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_WRITE, false); + if (error != 0) { + device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_WRITE=0\n", + __FUNCTION__); + return (error); + } + + return (0); +} + +static int +imx6_ahci_phy_read(struct ahci_controller* sc, uint32_t addr, uint16_t* val) +{ + int error; + uint32_t v; + + error = imx6_ahci_phy_addr(sc, addr); + if (error != 0) { + device_printf(sc->dev, "%s: error on imx6_ahci_phy_addr\n", + __FUNCTION__); + return (error); + } + + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_READ, true); + if (error != 0) { + device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_READ=1\n", + __FUNCTION__); + return (error); + } + + v = ATA_INL(sc->r_mem, SATA_P0PHYSR); + + error = imx6_ahci_phy_ctrl(sc, SATA_P0PHYCR_CR_READ, false); + if (error != 0) { + device_printf(sc->dev, "%s: error on SATA_P0PHYCR_CR_READ=0\n", + __FUNCTION__); + return (error); + } + + *val = SATA_P0PHYSR_CR_DATA_OUT(v); + return (0); +} + +static int +imx6_ahci_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) { + return (ENXIO); + } + + if (!ofw_bus_is_compatible(dev, "fsl,imx6q-ahci")) { + return (ENXIO); + } + device_set_desc(dev, "i.MX6 Integrated AHCI controller"); + + return (BUS_PROBE_DEFAULT); +} + +static int +imx6_ahci_attach(device_t dev) +{ + struct ahci_controller* ctlr; + uint16_t pllstat; + uint32_t v; + int error, timeout; + + ctlr = device_get_softc(dev); + + /* Power up the controller and phy. */ + error = imx6_ccm_sata_enable(); + if (error != 0) { + device_printf(dev, "error enabling controller and phy\n"); + return (error); + } + + ctlr->vendorid = 0; + ctlr->deviceid = 0; + ctlr->subvendorid = 0; + ctlr->subdeviceid = 0; + ctlr->numirqs = 1; + ctlr->r_rid = 0; + if ((ctlr->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + &ctlr->r_rid, RF_ACTIVE)) == NULL) { + return (ENXIO); + } + + v = imx_iomux_gpr_get(IOMUX_GPR13); + /* Clear out existing values; these numbers are bitmasks. */ + v &= ~(IOMUX_GPR13_SATA_PHY_8(7) | + IOMUX_GPR13_SATA_PHY_7(0x1f) | + IOMUX_GPR13_SATA_PHY_6(7) | + IOMUX_GPR13_SATA_SPEED(1) | + IOMUX_GPR13_SATA_PHY_5(1) | + IOMUX_GPR13_SATA_PHY_4(7) | + IOMUX_GPR13_SATA_PHY_3(0xf) | + IOMUX_GPR13_SATA_PHY_2(0x1f) | + IOMUX_GPR13_SATA_PHY_1(1) | + IOMUX_GPR13_SATA_PHY_0(1)); + /* setting */ + v |= IOMUX_GPR13_SATA_PHY_8(5) | /* Rx 3.0db */ + IOMUX_GPR13_SATA_PHY_7(0x12) | /* Rx SATA2m */ + IOMUX_GPR13_SATA_PHY_6(3) | /* Rx DPLL mode */ + IOMUX_GPR13_SATA_SPEED(1) | /* 3.0GHz */ + IOMUX_GPR13_SATA_PHY_5(0) | /* SpreadSpectram */ + IOMUX_GPR13_SATA_PHY_4(4) | /* Tx Attenuation 9/16 */ + IOMUX_GPR13_SATA_PHY_3(0) | /* Tx Boost 0db */ + IOMUX_GPR13_SATA_PHY_2(0x11) | /* Tx Level 1.104V */ + IOMUX_GPR13_SATA_PHY_1(1); /* PLL clock enable */ + imx_iomux_gpr_set(IOMUX_GPR13, v); + + /* phy reset */ + error = imx6_ahci_phy_write(ctlr, SATA_PHY_CLOCK_RESET, + SATA_PHY_CLOCK_RESET_RST); + if (error != 0) { + device_printf(dev, "cannot reset PHY\n"); + goto fail; + } + + for (timeout = 50; timeout > 0; --timeout) { + DELAY(100); + error = imx6_ahci_phy_read(ctlr, SATA_PHY_LANE0_OUT_STAT, + &pllstat); + if (error != 0) { + device_printf(dev, "cannot read LANE0 status\n"); + goto fail; + } + if (pllstat & SATA_PHY_LANE0_OUT_STAT_RX_PLL_STATE) { + break; + } + } + if (timeout <= 0) { + device_printf(dev, "time out reading LANE0 status\n"); + error = ETIMEDOUT; + goto fail; + } + + /* Support Staggered Spin-up */ + v = ATA_INL(ctlr->r_mem, AHCI_CAP); + ATA_OUTL(ctlr->r_mem, AHCI_CAP, v | AHCI_CAP_SSS); + + /* Ports Implemented. must set 1 */ + v = ATA_INL(ctlr->r_mem, AHCI_PI); + ATA_OUTL(ctlr->r_mem, AHCI_PI, v | (1 << 0)); + + /* set 1ms-timer = AHB clock / 1000 */ + ATA_OUTL(ctlr->r_mem, SATA_TIMER1MS, + imx_ccm_ahb_hz() / 1000); + + /* + * Note: ahci_attach will release ctlr->r_mem on errors automatically + */ + return (ahci_attach(dev)); + +fail: + bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_rid, ctlr->r_mem); + return (error); +} + +static int +imx6_ahci_detach(device_t dev) +{ + + return (ahci_detach(dev)); +} + +devclass_t ahci_devclass; + +static device_method_t imx6_ahci_ata_methods[] = { + /* device probe, attach and detach methods */ + DEVMETHOD(device_probe, imx6_ahci_probe), + DEVMETHOD(device_attach, imx6_ahci_attach), + DEVMETHOD(device_detach, imx6_ahci_detach), + + /* ahci bus methods */ + DEVMETHOD(bus_print_child, ahci_print_child), + DEVMETHOD(bus_alloc_resource, ahci_alloc_resource), + DEVMETHOD(bus_release_resource, ahci_release_resource), + DEVMETHOD(bus_setup_intr, ahci_setup_intr), + DEVMETHOD(bus_teardown_intr, ahci_teardown_intr), + DEVMETHOD(bus_child_location_str, ahci_child_location_str), + + DEVMETHOD_END +}; + +static driver_t ahci_ata_driver = { + "ahci", + imx6_ahci_ata_methods, + sizeof(struct ahci_controller) +}; + +DRIVER_MODULE(ahci, simplebus, ahci_ata_driver, ahci_devclass, 0, 0); Modified: stable/11/sys/arm/freescale/imx/imx6_ccm.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx6_ccm.c Mon Sep 11 22:21:15 2017 (r323467) +++ stable/11/sys/arm/freescale/imx/imx6_ccm.c Mon Sep 11 22:28:38 2017 (r323468) @@ -314,6 +314,41 @@ imx_ccm_usbphy_enable(device_t _phydev) #endif } +int +imx6_ccm_sata_enable(void) +{ + uint32_t v; + int timeout; + + /* Un-gate the sata controller. */ + WR4(ccm_sc, CCM_CCGR5, RD4(ccm_sc, CCM_CCGR5) | CCGR5_SATA); + + /* Power up the PLL that feeds ENET/SATA/PCI phys, wait for lock. */ + v = RD4(ccm_sc, CCM_ANALOG_PLL_ENET); + v &= ~CCM_ANALOG_PLL_ENET_POWERDOWN; + WR4(ccm_sc, CCM_ANALOG_PLL_ENET, v); + + for (timeout = 100000; timeout > 0; timeout--) { + if (RD4(ccm_sc, CCM_ANALOG_PLL_ENET) & + CCM_ANALOG_PLL_ENET_LOCK) { + break; + } + } + if (timeout <= 0) { + return ETIMEDOUT; + } + + /* Enable the PLL, and enable its 100mhz output. */ + v |= CCM_ANALOG_PLL_ENET_ENABLE; + v &= ~CCM_ANALOG_PLL_ENET_BYPASS; + WR4(ccm_sc, CCM_ANALOG_PLL_ENET, v); + + v |= CCM_ANALOG_PLL_ENET_ENABLE_100M; + WR4(ccm_sc, CCM_ANALOG_PLL_ENET, v); + + return 0; +} + uint32_t imx_ccm_ipg_hz(void) { Modified: stable/11/sys/arm/freescale/imx/imx6_ccmreg.h ============================================================================== --- stable/11/sys/arm/freescale/imx/imx6_ccmreg.h Mon Sep 11 22:21:15 2017 (r323467) +++ stable/11/sys/arm/freescale/imx/imx6_ccmreg.h Mon Sep 11 22:28:38 2017 (r323468) @@ -116,6 +116,7 @@ #define CCGR4_PL301_MX6QPER1_BCH (0x3 << 12) #define CCGR4_PL301_MX6QPER2_MAIN (0x3 << 14) #define CCM_CCGR5 0x07C +#define CCGR5_SATA (0x3 << 4) #define CCGR5_SDMA (0x3 << 6) #define CCGR5_SSI1 (0x3 << 18) #define CCGR5_SSI2 (0x3 << 20) @@ -129,5 +130,12 @@ #define CCGR6_USDHC3 (0x3 << 6) #define CCGR6_USDHC4 (0x3 << 8) #define CCM_CMEOR 0x088 + +#define CCM_ANALOG_PLL_ENET 0x000040e0 +#define CCM_ANALOG_PLL_ENET_LOCK (1u << 31) +#define CCM_ANALOG_PLL_ENET_ENABLE_100M (1u << 20) /* SATA */ +#define CCM_ANALOG_PLL_ENET_BYPASS (1u << 16) +#define CCM_ANALOG_PLL_ENET_ENABLE (1u << 13) /* Ether */ +#define CCM_ANALOG_PLL_ENET_POWERDOWN (1u << 12) #endif Modified: stable/11/sys/arm/freescale/imx/imx_ccmvar.h ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_ccmvar.h Mon Sep 11 22:21:15 2017 (r323467) +++ stable/11/sys/arm/freescale/imx/imx_ccmvar.h Mon Sep 11 22:28:38 2017 (r323468) @@ -54,6 +54,7 @@ void imx_ccm_usbphy_enable(device_t _phydev); void imx_ccm_ssi_configure(device_t _ssidev); void imx_ccm_hdmi_enable(void); void imx_ccm_ipu_enable(int ipu); +int imx6_ccm_sata_enable(void); /* Routines to get and set the arm clock root divisor register. */ uint32_t imx_ccm_get_cacrr(void); Modified: stable/11/sys/arm/freescale/imx/imx_iomux.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_iomux.c Mon Sep 11 22:21:15 2017 (r323467) +++ stable/11/sys/arm/freescale/imx/imx_iomux.c Mon Sep 11 22:28:38 2017 (r323468) @@ -71,7 +71,7 @@ struct iomux_softc { device_t dev; struct resource *mem_res; - u_int last_gpreg; + u_int last_gpregaddr; }; static struct iomux_softc *iomux_sc; @@ -214,19 +214,19 @@ iomux_attach(device_t dev) switch (imx_soc_type()) { case IMXSOC_51: - sc->last_gpreg = 1; + sc->last_gpregaddr = 1 * sizeof(uint32_t); break; case IMXSOC_53: - sc->last_gpreg = 2; + sc->last_gpregaddr = 2 * sizeof(uint32_t); break; case IMXSOC_6DL: case IMXSOC_6S: case IMXSOC_6SL: case IMXSOC_6Q: - sc->last_gpreg = 13; + sc->last_gpregaddr = 13 * sizeof(uint32_t); break; case IMXSOC_6UL: - sc->last_gpreg = 14; + sc->last_gpregaddr = 14 * sizeof(uint32_t); break; default: device_printf(dev, "Unknown SoC type\n"); @@ -262,45 +262,48 @@ iomux_attach(device_t dev) } uint32_t -imx_iomux_gpr_get(u_int regnum) +imx_iomux_gpr_get(u_int regaddr) { struct iomux_softc * sc; sc = iomux_sc; KASSERT(sc != NULL, ("%s called before attach", __FUNCTION__)); - KASSERT(regnum >= 0 && regnum <= sc->last_gpreg, - ("%s bad regnum %u, max %u", __FUNCTION__, regnum, sc->last_gpreg)); + KASSERT(regaddr >= 0 && regaddr <= sc->last_gpregaddr, + ("%s bad regaddr %u, max %u", __FUNCTION__, regaddr, + sc->last_gpregaddr)); - return (RD4(iomux_sc, regnum * 4)); + return (RD4(iomux_sc, regaddr)); } void -imx_iomux_gpr_set(u_int regnum, uint32_t val) +imx_iomux_gpr_set(u_int regaddr, uint32_t val) { struct iomux_softc * sc; sc = iomux_sc; KASSERT(sc != NULL, ("%s called before attach", __FUNCTION__)); - KASSERT(regnum >= 0 && regnum <= sc->last_gpreg, - ("%s bad regnum %u, max %u", __FUNCTION__, regnum, sc->last_gpreg)); + KASSERT(regaddr >= 0 && regaddr <= sc->last_gpregaddr, + ("%s bad regaddr %u, max %u", __FUNCTION__, regaddr, + sc->last_gpregaddr)); - WR4(iomux_sc, regnum * 4, val); + WR4(iomux_sc, regaddr, val); } void -imx_iomux_gpr_set_masked(u_int regnum, uint32_t clrbits, uint32_t setbits) +imx_iomux_gpr_set_masked(u_int regaddr, uint32_t clrbits, uint32_t setbits) { struct iomux_softc * sc; uint32_t val; sc = iomux_sc; KASSERT(sc != NULL, ("%s called before attach", __FUNCTION__)); - KASSERT(regnum >= 0 && regnum <= sc->last_gpreg, - ("%s bad regnum %u, max %u", __FUNCTION__, regnum, sc->last_gpreg)); + KASSERT(regaddr >= 0 && regaddr <= sc->last_gpregaddr, + ("%s bad regaddr %u, max %u", __FUNCTION__, regaddr, + sc->last_gpregaddr)); - val = RD4(iomux_sc, regnum * 4); + val = RD4(iomux_sc, regaddr * 4); val = (val & ~clrbits) | setbits; - WR4(iomux_sc, regnum * 4, val); + WR4(iomux_sc, regaddr, val); } static device_method_t imx_iomux_methods[] = { Modified: stable/11/sys/arm/freescale/imx/imx_iomuxreg.h ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_iomuxreg.h Mon Sep 11 22:21:15 2017 (r323467) +++ stable/11/sys/arm/freescale/imx/imx_iomuxreg.h Mon Sep 11 22:28:38 2017 (r323468) @@ -29,14 +29,33 @@ #ifndef IMX_IOMUXREG_H #define IMX_IOMUXREG_H -#define IOMUXC_GPR0 0x00 -#define IOMUXC_GPR1 0x04 -#define IOMUXC_GPR2 0x08 -#define IOMUXC_GPR3 0x0C -#define IOMUXC_GPR3_HDMI_MASK (3 << 2) -#define IOMUXC_GPR3_HDMI_IPU1_DI0 (0 << 2) -#define IOMUXC_GPR3_HDMI_IPU1_DI1 (1 << 2) -#define IOMUXC_GPR3_HDMI_IPU2_DI0 (2 << 2) -#define IOMUXC_GPR3_HDMI_IPU2_DI1 (3 << 2) +#define IMX_IOMUXREG_LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) +#define IMX_IOMUXREG_SHIFTIN(__x, __mask) ((__x) * IMX_IOMUXREG_LOWEST_SET_BIT(__mask)) + +#define IMX_IOMUXREG_BIT(n) (1 << (n)) +#define IMX_IOMUXREG_BITS(__m, __n) \ + ((IMX_IOMUXREG_BIT(MAX((__m), (__n)) + 1) - 1) ^ (IMX_IOMUXREG_BIT(MIN((__m), (__n))) - 1)) + +#define IOMUXC_GPR0 0x00 +#define IOMUXC_GPR1 0x04 +#define IOMUXC_GPR2 0x08 +#define IOMUXC_GPR3 0x0C +#define IOMUXC_GPR3_HDMI_MASK (3 << 2) +#define IOMUXC_GPR3_HDMI_IPU1_DI0 (0 << 2) +#define IOMUXC_GPR3_HDMI_IPU1_DI1 (1 << 2) +#define IOMUXC_GPR3_HDMI_IPU2_DI0 (2 << 2) +#define IOMUXC_GPR3_HDMI_IPU2_DI1 (3 << 2) + +#define IOMUX_GPR13 0x34 +#define IOMUX_GPR13_SATA_PHY_8(n) IMX_IOMUXREG_SHIFTIN(n, IMX_IOMUXREG_BITS(26, 24)) +#define IOMUX_GPR13_SATA_PHY_7(n) IMX_IOMUXREG_SHIFTIN(n, IMX_IOMUXREG_BITS(23, 19)) +#define IOMUX_GPR13_SATA_PHY_6(n) IMX_IOMUXREG_SHIFTIN(n, IMX_IOMUXREG_BITS(18, 16)) +#define IOMUX_GPR13_SATA_SPEED(n) IMX_IOMUXREG_SHIFTIN(n, (1 << 15)) +#define IOMUX_GPR13_SATA_PHY_5(n) IMX_IOMUXREG_SHIFTIN(n, (1 << 14)) +#define IOMUX_GPR13_SATA_PHY_4(n) IMX_IOMUXREG_SHIFTIN(n, IMX_IOMUXREG_BITS(13, 11)) +#define IOMUX_GPR13_SATA_PHY_3(n) IMX_IOMUXREG_SHIFTIN(n, IMX_IOMUXREG_BITS(10, 7)) +#define IOMUX_GPR13_SATA_PHY_2(n) IMX_IOMUXREG_SHIFTIN(n, IMX_IOMUXREG_BITS(6, 2)) +#define IOMUX_GPR13_SATA_PHY_1(n) IMX_IOMUXREG_SHIFTIN(n, (1 << 1)) +#define IOMUX_GPR13_SATA_PHY_0(n) IMX_IOMUXREG_SHIFTIN(n, (1 << 0)) #endif Modified: stable/11/sys/arm/freescale/imx/imx_iomuxvar.h ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_iomuxvar.h Mon Sep 11 22:21:15 2017 (r323467) +++ stable/11/sys/arm/freescale/imx/imx_iomuxvar.h Mon Sep 11 22:28:38 2017 (r323468) @@ -42,8 +42,8 @@ u_int iomux_get_pad_config(u_int pin); * with IO pin assignments or pad control. These functions let other soc level * code manipulate these values. */ -uint32_t imx_iomux_gpr_get(u_int regnum); -void imx_iomux_gpr_set(u_int regnum, uint32_t val); -void imx_iomux_gpr_set_masked(u_int regnum, uint32_t clrbits, uint32_t setbits); +uint32_t imx_iomux_gpr_get(u_int regaddr); +void imx_iomux_gpr_set(u_int regaddr, uint32_t val); +void imx_iomux_gpr_set_masked(u_int regaddr, uint32_t clrbits, uint32_t setbits); #endif From owner-svn-src-stable-11@freebsd.org Mon Sep 11 22:32:39 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5B907E03C71; Mon, 11 Sep 2017 22:32:39 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 28B2175DB1; Mon, 11 Sep 2017 22:32:39 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BMWcnc069433; Mon, 11 Sep 2017 22:32:38 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BMWcM6069432; Mon, 11 Sep 2017 22:32:38 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709112232.v8BMWcM6069432@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 22:32:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323469 - stable/11/sys/kern X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/kern X-SVN-Commit-Revision: 323469 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 22:32:39 -0000 Author: ian Date: Mon Sep 11 22:32:38 2017 New Revision: 323469 URL: https://svnweb.freebsd.org/changeset/base/323469 Log: MFC r322580: Fix compile error with option DEBUG. This is fallout from some long-ago INTRNG refactoring that didn't get caught at the time because code in a debugf() statement isn't compiled unless DEBUG is defined. PR: 221557 Modified: stable/11/sys/kern/subr_intr.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/subr_intr.c ============================================================================== --- stable/11/sys/kern/subr_intr.c Mon Sep 11 22:28:38 2017 (r323468) +++ stable/11/sys/kern/subr_intr.c Mon Sep 11 22:32:38 2017 (r323469) @@ -1023,14 +1023,14 @@ intr_setup_irq(device_t dev, struct resource *res, dri if (flags & INTR_SOLO) { error = iscr_setup_filter(isrc, name, (intr_irq_filter_t *)filt, arg, cookiep); - debugf("irq %u setup filter error %d on %s\n", irq, error, + debugf("irq %u setup filter error %d on %s\n", isrc->isrc_irq, error, name); } else #endif { error = isrc_add_handler(isrc, name, filt, hand, arg, flags, cookiep); - debugf("irq %u add handler error %d on %s\n", irq, error, name); + debugf("irq %u add handler error %d on %s\n", isrc->isrc_irq, error, name); } if (error != 0) return (error); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 22:33:30 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E3C4EE03DA6; Mon, 11 Sep 2017 22:33:30 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id B2B5275F66; Mon, 11 Sep 2017 22:33:30 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BMXTuh069539; Mon, 11 Sep 2017 22:33:29 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BMXTm6069538; Mon, 11 Sep 2017 22:33:29 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709112233.v8BMXTm6069538@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 22:33:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323470 - stable/11/sys/arm/ti/am335x X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/ti/am335x X-SVN-Commit-Revision: 323470 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 22:33:31 -0000 Author: ian Date: Mon Sep 11 22:33:29 2017 New Revision: 323470 URL: https://svnweb.freebsd.org/changeset/base/323470 Log: MFC r322373: Ensure the clocks driver is attached before any drivers that need to enable clocks in their attach(). Modified: stable/11/sys/arm/ti/am335x/am335x_prcm.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/ti/am335x/am335x_prcm.c ============================================================================== --- stable/11/sys/arm/ti/am335x/am335x_prcm.c Mon Sep 11 22:32:38 2017 (r323469) +++ stable/11/sys/arm/ti/am335x/am335x_prcm.c Mon Sep 11 22:33:29 2017 (r323470) @@ -466,8 +466,8 @@ static driver_t am335x_prcm_driver = { static devclass_t am335x_prcm_devclass; -DRIVER_MODULE(am335x_prcm, simplebus, am335x_prcm_driver, - am335x_prcm_devclass, 0, 0); +EARLY_DRIVER_MODULE(am335x_prcm, simplebus, am335x_prcm_driver, + am335x_prcm_devclass, 0, 0, BUS_PASS_TIMER + BUS_PASS_ORDER_EARLY); MODULE_VERSION(am335x_prcm, 1); MODULE_DEPEND(am335x_prcm, ti_scm, 1, 1, 1); From owner-svn-src-stable-11@freebsd.org Mon Sep 11 22:35:21 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D2988E03F20; Mon, 11 Sep 2017 22:35:21 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 9FD64760E4; Mon, 11 Sep 2017 22:35:21 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BMZKhx069654; Mon, 11 Sep 2017 22:35:20 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BMZKfV069653; Mon, 11 Sep 2017 22:35:20 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709112235.v8BMZKfV069653@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 22:35:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323471 - stable/11/sys/arm/broadcom/bcm2835 X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/sys/arm/broadcom/bcm2835 X-SVN-Commit-Revision: 323471 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 22:35:21 -0000 Author: ian Date: Mon Sep 11 22:35:20 2017 New Revision: 323471 URL: https://svnweb.freebsd.org/changeset/base/323471 Log: MFC r323132-r323133 r323132: The latest RPi firmware leaves secondary cores in a wait-for-event (WFE) state to save power, so after writing the entry point address for a core to the mailbox, use a dsb() to synchronize the execution pipeline to the data written, then use an sev() to wake up the core. Submitted by: Sylvain Garrigues r323133: Change leading spaces to tabs, no functional change. Modified: stable/11/sys/arm/broadcom/bcm2835/bcm2836_mp.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/broadcom/bcm2835/bcm2836_mp.c ============================================================================== --- stable/11/sys/arm/broadcom/bcm2835/bcm2836_mp.c Mon Sep 11 22:33:29 2017 (r323470) +++ stable/11/sys/arm/broadcom/bcm2835/bcm2836_mp.c Mon Sep 11 22:35:20 2017 (r323471) @@ -114,7 +114,9 @@ platform_mp_start_ap(void) /* set entry point to mailbox 3 */ BSWR4(MBOX3SET_CORE(i), (uint32_t)pmap_kextract((vm_offset_t)mpentry)); - wmb(); + /* Firmware put cores in WFE state, need SEV to wake up. */ + dsb(); + sev(); /* wait for bootup */ retry = 1000; From owner-svn-src-stable-11@freebsd.org Mon Sep 11 22:40:01 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 540E0E04227; Mon, 11 Sep 2017 22:40:01 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id 22D23762B6; Mon, 11 Sep 2017 22:40:01 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BMe095069858; Mon, 11 Sep 2017 22:40:00 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BMe0gP069855; Mon, 11 Sep 2017 22:40:00 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709112240.v8BMe0gP069855@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 22:40:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323472 - in stable/11/sys: dev/xen/timer isa x86/isa X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: dev/xen/timer isa x86/isa X-SVN-Commit-Revision: 323472 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 22:40:01 -0000 Author: ian Date: Mon Sep 11 22:39:59 2017 New Revision: 323472 URL: https://svnweb.freebsd.org/changeset/base/323472 Log: MFC r322411: Stop calling atrtc_set() from the xen timer clock_settime() method. That removes the only reference to atrtc_set() from outside of atrtc.c, so make it static. The xen timer driver registers as a realtime clock with 1us resolution. In the past that resulted in only the xen timer's clock_settime() getting called, so it would call atrtc_set() to set the hardware clock as well. As of r32090, the clock_settime() method of all registered realtime clocks gets called, so the xen driver no longer needs to chain-call the lower-resolution driver. Thanks to royger@ for talking me through the xen stuff, and for testing. Modified: stable/11/sys/dev/xen/timer/timer.c stable/11/sys/isa/rtc.h stable/11/sys/x86/isa/atrtc.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/xen/timer/timer.c ============================================================================== --- stable/11/sys/dev/xen/timer/timer.c Mon Sep 11 22:35:20 2017 (r323471) +++ stable/11/sys/dev/xen/timer/timer.c Mon Sep 11 22:39:59 2017 (r323472) @@ -64,8 +64,6 @@ __FBSDID("$FreeBSD$"); #include -#include - #include "clock_if.h" static devclass_t xentimer_devclass; @@ -228,9 +226,6 @@ xentimer_settime(device_t dev __unused, struct timespe */ if (!xen_initial_domain()) return (0); - - /* Set the native RTC. */ - atrtc_set(ts); settime.cmd = XENPF_settime64; settime.u.settime64.mbz = 0; Modified: stable/11/sys/isa/rtc.h ============================================================================== --- stable/11/sys/isa/rtc.h Mon Sep 11 22:35:20 2017 (r323471) +++ stable/11/sys/isa/rtc.h Mon Sep 11 22:39:59 2017 (r323472) @@ -118,7 +118,6 @@ extern int atrtcclock_disable; int rtcin(int reg); void atrtc_restore(void); void writertc(int reg, u_char val); -void atrtc_set(struct timespec *ts); #endif #endif /* _I386_ISA_RTC_H_ */ Modified: stable/11/sys/x86/isa/atrtc.c ============================================================================== --- stable/11/sys/x86/isa/atrtc.c Mon Sep 11 22:35:20 2017 (r323471) +++ stable/11/sys/x86/isa/atrtc.c Mon Sep 11 22:39:59 2017 (r323472) @@ -159,7 +159,7 @@ atrtc_restore(void) rtcin(RTC_INTR); } -void +static void atrtc_set(struct timespec *ts) { struct clocktime ct; From owner-svn-src-stable-11@freebsd.org Mon Sep 11 22:43:03 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 225AAE046B6; Mon, 11 Sep 2017 22:43:03 +0000 (UTC) (envelope-from ian@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 mx1.freebsd.org (Postfix) with ESMTPS id E3F3F766F0; Mon, 11 Sep 2017 22:43:02 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8BMh22X073732; Mon, 11 Sep 2017 22:43:02 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8BMh2gL073731; Mon, 11 Sep 2017 22:43:02 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709112243.v8BMh2gL073731@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 11 Sep 2017 22:43:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323473 - stable/11/share/man/man5 X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/11/share/man/man5 X-SVN-Commit-Revision: 323473 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 22:43:03 -0000 Author: ian Date: Mon Sep 11 22:43:01 2017 New Revision: 323473 URL: https://svnweb.freebsd.org/changeset/base/323473 Log: MFC r323341: Clarify that the size option is in bytes by default, but also accepts the usual SI suffixes. Modified: stable/11/share/man/man5/tmpfs.5 Directory Properties: stable/11/ (props changed) Modified: stable/11/share/man/man5/tmpfs.5 ============================================================================== --- stable/11/share/man/man5/tmpfs.5 Mon Sep 11 22:39:59 2017 (r323472) +++ stable/11/share/man/man5/tmpfs.5 Mon Sep 11 22:43:01 2017 (r323473) @@ -54,7 +54,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 20, 2017 +.Dd September 8, 2017 .Dt TMPFS 5 .Os .Sh NAME @@ -131,7 +131,9 @@ the file system size, which can be limited with the .Cm size option. .It Cm size -Specifies the total file system size in bytes. +Specifies the total file system size in bytes, unless suffixed +with one of k, m, g, t, or p, which denote byte, kilobyte, +megabyte, gigabyte, terabyte and petabyte respectively. If zero (the default) or a value larger than SIZE_MAX - PAGE_SIZE is given, the available amount of memory (including main memory and swap space) will be used. From owner-svn-src-stable-11@freebsd.org Tue Sep 12 00:26:58 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2478AE0A509; Tue, 12 Sep 2017 00:26:58 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id 0023A7DBA6; Tue, 12 Sep 2017 00:26:57 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8C0QvoD014068; Tue, 12 Sep 2017 00:26:57 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8C0Qvii014065; Tue, 12 Sep 2017 00:26:57 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709120026.v8C0Qvii014065@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Tue, 12 Sep 2017 00:26:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323475 - in stable/11/lib/msun: src tests X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: in stable/11/lib/msun: src tests X-SVN-Commit-Revision: 323475 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 00:26:58 -0000 Author: rlibby Date: Tue Sep 12 00:26:56 2017 New Revision: 323475 URL: https://svnweb.freebsd.org/changeset/base/323475 Log: MFC r323003,r323004: r323003: lib/msun: avoid referring to broken LDBL_MAX r323004: lib/msun: add more csqrt unit tests for precision and overflow Modified: stable/11/lib/msun/src/catrig.c stable/11/lib/msun/src/s_csqrtl.c stable/11/lib/msun/tests/csqrt_test.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/msun/src/catrig.c ============================================================================== --- stable/11/lib/msun/src/catrig.c Mon Sep 11 23:47:49 2017 (r323474) +++ stable/11/lib/msun/src/catrig.c Tue Sep 12 00:26:56 2017 (r323475) @@ -469,8 +469,13 @@ clog_for_large_values(double complex z) /* * Avoid overflow in hypot() when x and y are both very large. - * Divide x and y by E, and then add 1 to the logarithm. This depends - * on E being larger than sqrt(2). + * Divide x and y by E, and then add 1 to the logarithm. This + * depends on E being larger than sqrt(2), since the return value of + * hypot cannot overflow if neither argument is greater in magnitude + * than 1/sqrt(2) of the maximum value of the return type. Likewise + * this determines the necessary threshold for using this method + * (however, actually use 1/2 instead as it is simpler). + * * Dividing by E causes an insignificant loss of accuracy; however * this method is still poor since it is uneccessarily slow. */ Modified: stable/11/lib/msun/src/s_csqrtl.c ============================================================================== --- stable/11/lib/msun/src/s_csqrtl.c Mon Sep 11 23:47:49 2017 (r323474) +++ stable/11/lib/msun/src/s_csqrtl.c Tue Sep 12 00:26:56 2017 (r323475) @@ -42,8 +42,16 @@ __FBSDID("$FreeBSD$"); */ #pragma STDC CX_LIMITED_RANGE ON -/* We risk spurious overflow for components >= LDBL_MAX / (1 + sqrt(2)). */ -#define THRESH (LDBL_MAX / 2.414213562373095048801688724209698L) +/* + * We risk spurious overflow for components >= LDBL_MAX / (1 + sqrt(2)). + * Rather than determining the fully precise value at which we might + * overflow, just use a threshold of approximately LDBL_MAX / 4. + */ +#if LDBL_MAX_EXP != 0x4000 +#error "Unsupported long double format" +#else +#define THRESH 0x1p16382L +#endif long double complex csqrtl(long double complex z) Modified: stable/11/lib/msun/tests/csqrt_test.c ============================================================================== --- stable/11/lib/msun/tests/csqrt_test.c Mon Sep 11 23:47:49 2017 (r323474) +++ stable/11/lib/msun/tests/csqrt_test.c Tue Sep 12 00:26:56 2017 (r323475) @@ -214,28 +214,94 @@ test_nans(void) /* * Test whether csqrt(a + bi) works for inputs that are large enough to - * cause overflow in hypot(a, b) + a. In this case we are using - * csqrt(115 + 252*I) == 14 + 9*I - * scaled up to near MAX_EXP. + * cause overflow in hypot(a, b) + a. Each of the tests is scaled up to + * near MAX_EXP. */ static void test_overflow(int maxexp) { long double a, b; long double complex result; + int exp, i; - a = ldexpl(115 * 0x1p-8, maxexp); - b = ldexpl(252 * 0x1p-8, maxexp); - result = t_csqrt(CMPLXL(a, b)); - assert(creall(result) == ldexpl(14 * 0x1p-4, maxexp / 2)); - assert(cimagl(result) == ldexpl(9 * 0x1p-4, maxexp / 2)); + assert(maxexp > 0 && maxexp % 2 == 0); + + for (i = 0; i < 4; i++) { + exp = maxexp - 2 * i; + + /* csqrt(115 + 252*I) == 14 + 9*I */ + a = ldexpl(115 * 0x1p-8, exp); + b = ldexpl(252 * 0x1p-8, exp); + result = t_csqrt(CMPLXL(a, b)); + assert(creall(result) == ldexpl(14 * 0x1p-4, exp / 2)); + assert(cimagl(result) == ldexpl(9 * 0x1p-4, exp / 2)); + + /* csqrt(-11 + 60*I) = 5 + 6*I */ + a = ldexpl(-11 * 0x1p-6, exp); + b = ldexpl(60 * 0x1p-6, exp); + result = t_csqrt(CMPLXL(a, b)); + assert(creall(result) == ldexpl(5 * 0x1p-3, exp / 2)); + assert(cimagl(result) == ldexpl(6 * 0x1p-3, exp / 2)); + + /* csqrt(225 + 0*I) == 15 + 0*I */ + a = ldexpl(225 * 0x1p-8, exp); + b = 0; + result = t_csqrt(CMPLXL(a, b)); + assert(creall(result) == ldexpl(15 * 0x1p-4, exp / 2)); + assert(cimagl(result) == 0); + } } +/* + * Test that precision is maintained for some large squares. Set all or + * some bits in the lower mantdig/2 bits, square the number, and try to + * recover the sqrt. Note: + * (x + xI)**2 = 2xxI + */ +static void +test_precision(int maxexp, int mantdig) +{ + long double b, x; + long double complex result; + uint64_t mantbits, sq_mantbits; + int exp, i; + + assert(maxexp > 0 && maxexp % 2 == 0); + assert(mantdig <= 64); + mantdig = rounddown(mantdig, 2); + + for (exp = 0; exp <= maxexp; exp += 2) { + mantbits = ((uint64_t)1 << (mantdig / 2 )) - 1; + for (i = 0; + i < 100 && mantbits > ((uint64_t)1 << (mantdig / 2 - 1)); + i++, mantbits--) { + sq_mantbits = mantbits * mantbits; + /* + * sq_mantibts is a mantdig-bit number. Divide by + * 2**mantdig to normalize it to [0.5, 1), where, + * note, the binary power will be -1. Raise it by + * 2**exp for the test. exp is even. Lower it by + * one to reach a final binary power which is also + * even. The result should be exactly + * representable, given that mantdig is less than or + * equal to the available precision. + */ + b = ldexpl((long double)sq_mantbits, + exp - 1 - mantdig); + x = ldexpl(mantbits, (exp - 2 - mantdig) / 2); + assert(b == x * x * 2); + result = t_csqrt(CMPLXL(0, b)); + assert(creall(result) == x); + assert(cimagl(result) == x); + } + } +} + int main(void) { - printf("1..15\n"); + printf("1..18\n"); /* Test csqrt() */ t_csqrt = _csqrt; @@ -255,41 +321,56 @@ main(void) test_overflow(DBL_MAX_EXP); printf("ok 5 - csqrt\n"); + test_precision(DBL_MAX_EXP, DBL_MANT_DIG); + printf("ok 6 - csqrt\n"); + /* Now test csqrtf() */ t_csqrt = _csqrtf; test_finite(); - printf("ok 6 - csqrt\n"); + printf("ok 7 - csqrt\n"); test_zeros(); - printf("ok 7 - csqrt\n"); + printf("ok 8 - csqrt\n"); test_infinities(); - printf("ok 8 - csqrt\n"); + printf("ok 9 - csqrt\n"); test_nans(); - printf("ok 9 - csqrt\n"); + printf("ok 10 - csqrt\n"); test_overflow(FLT_MAX_EXP); - printf("ok 10 - csqrt\n"); + printf("ok 11 - csqrt\n"); + test_precision(FLT_MAX_EXP, FLT_MANT_DIG); + printf("ok 12 - csqrt\n"); + /* Now test csqrtl() */ t_csqrt = csqrtl; test_finite(); - printf("ok 11 - csqrt\n"); + printf("ok 13 - csqrt\n"); test_zeros(); - printf("ok 12 - csqrt\n"); + printf("ok 14 - csqrt\n"); test_infinities(); - printf("ok 13 - csqrt\n"); + printf("ok 15 - csqrt\n"); test_nans(); - printf("ok 14 - csqrt\n"); + printf("ok 16 - csqrt\n"); test_overflow(LDBL_MAX_EXP); - printf("ok 15 - csqrt\n"); + printf("ok 17 - csqrt\n"); + + test_precision(LDBL_MAX_EXP, +#ifndef __i386__ + LDBL_MANT_DIG +#else + DBL_MANT_DIG +#endif + ); + printf("ok 18 - csqrt\n"); return (0); } From owner-svn-src-stable-11@freebsd.org Tue Sep 12 00:44:18 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 800AEE0B38B; Tue, 12 Sep 2017 00:44:18 +0000 (UTC) (envelope-from emaste@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 mx1.freebsd.org (Postfix) with ESMTPS id 5A5437E530; Tue, 12 Sep 2017 00:44:18 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8C0iHOi022118; Tue, 12 Sep 2017 00:44:17 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8C0iGVL022114; Tue, 12 Sep 2017 00:44:16 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201709120044.v8C0iGVL022114@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Tue, 12 Sep 2017 00:44:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323476 - in stable/11/release: amd64 arm64 i386 powerpc X-SVN-Group: stable-11 X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: in stable/11/release: amd64 arm64 i386 powerpc X-SVN-Commit-Revision: 323476 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 00:44:18 -0000 Author: emaste Date: Tue Sep 12 00:44:16 2017 New Revision: 323476 URL: https://svnweb.freebsd.org/changeset/base/323476 Log: make-memstick.sh: use 'set -e' to abort if any step fails Also remove the now-redundant error handling that was only for makefs. This script was run on an older FreeBSD host that lacked efi-on-mbr support in makefs. A warning was emitted on the console (from makefs) but the script continued running and exited with 0. MFC of r308171 (arm64) and r323178 (other architectures). Modified: stable/11/release/amd64/make-memstick.sh stable/11/release/arm64/make-memstick.sh stable/11/release/i386/make-memstick.sh stable/11/release/powerpc/make-memstick.sh Directory Properties: stable/11/ (props changed) Modified: stable/11/release/amd64/make-memstick.sh ============================================================================== --- stable/11/release/amd64/make-memstick.sh Tue Sep 12 00:26:56 2017 (r323475) +++ stable/11/release/amd64/make-memstick.sh Tue Sep 12 00:44:16 2017 (r323476) @@ -10,6 +10,8 @@ # $FreeBSD$ # +set -e + PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH @@ -31,10 +33,6 @@ fi echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${1}/etc/fstab echo 'root_rw_mount="NO"' > ${1}/etc/rc.conf.local makefs -B little -o label=FreeBSD_Install ${2}.part ${1} -if [ $? -ne 0 ]; then - echo "makefs failed" - exit 1 -fi rm ${1}/etc/fstab rm ${1}/etc/rc.conf.local Modified: stable/11/release/arm64/make-memstick.sh ============================================================================== --- stable/11/release/arm64/make-memstick.sh Tue Sep 12 00:26:56 2017 (r323475) +++ stable/11/release/arm64/make-memstick.sh Tue Sep 12 00:44:16 2017 (r323476) @@ -10,6 +10,8 @@ # $FreeBSD$ # +set -e + PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH @@ -31,10 +33,6 @@ fi echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${1}/etc/fstab echo 'root_rw_mount="NO"' > ${1}/etc/rc.conf.local makefs -B little -o label=FreeBSD_Install ${2}.part ${1} -if [ $? -ne 0 ]; then - echo "makefs failed" - exit 1 -fi rm ${1}/etc/fstab rm ${1}/etc/rc.conf.local Modified: stable/11/release/i386/make-memstick.sh ============================================================================== --- stable/11/release/i386/make-memstick.sh Tue Sep 12 00:26:56 2017 (r323475) +++ stable/11/release/i386/make-memstick.sh Tue Sep 12 00:44:16 2017 (r323476) @@ -10,6 +10,8 @@ # $FreeBSD$ # +set -e + PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH @@ -31,10 +33,6 @@ fi echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${1}/etc/fstab echo 'root_rw_mount="NO"' > ${1}/etc/rc.conf.local makefs -B little -o label=FreeBSD_Install ${2}.part ${1} -if [ $? -ne 0 ]; then - echo "makefs failed" - exit 1 -fi rm ${1}/etc/fstab rm ${1}/etc/rc.conf.local Modified: stable/11/release/powerpc/make-memstick.sh ============================================================================== --- stable/11/release/powerpc/make-memstick.sh Tue Sep 12 00:26:56 2017 (r323475) +++ stable/11/release/powerpc/make-memstick.sh Tue Sep 12 00:44:16 2017 (r323476) @@ -10,6 +10,8 @@ # $FreeBSD$ # +set -e + PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH @@ -36,10 +38,6 @@ echo '/dev/da0s3 / ufs ro,noatime 1 1' > ${1}/etc/fsta echo 'root_rw_mount="NO"' > ${1}/etc/rc.conf.local rm -f ${tempfile} makefs -B big ${tempfile} ${1} -if [ $? -ne 0 ]; then - echo "makefs failed" - exit 1 -fi rm ${1}/etc/fstab rm ${1}/etc/rc.conf.local From owner-svn-src-stable-11@freebsd.org Tue Sep 12 03:54:06 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 254F1E14CFA; Tue, 12 Sep 2017 03:54:06 +0000 (UTC) (envelope-from mjoras@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 mx1.freebsd.org (Postfix) with ESMTPS id C89248398C; Tue, 12 Sep 2017 03:54:05 +0000 (UTC) (envelope-from mjoras@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8C3s5pl099326; Tue, 12 Sep 2017 03:54:05 GMT (envelope-from mjoras@FreeBSD.org) Received: (from mjoras@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8C3s5fa099325; Tue, 12 Sep 2017 03:54:05 GMT (envelope-from mjoras@FreeBSD.org) Message-Id: <201709120354.v8C3s5fa099325@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjoras set sender to mjoras@FreeBSD.org using -f From: Matt Joras Date: Tue, 12 Sep 2017 03:54:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323477 - stable/11/sys/net X-SVN-Group: stable-11 X-SVN-Commit-Author: mjoras X-SVN-Commit-Paths: stable/11/sys/net X-SVN-Commit-Revision: 323477 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 03:54:06 -0000 Author: mjoras Date: Tue Sep 12 03:54:04 2017 New Revision: 323477 URL: https://svnweb.freebsd.org/changeset/base/323477 Log: MFC r322548: Rework vlan(4) locking. Previously the locking of vlan(4) interfaces was not very comprehensive. Particularly there was very little protection against the destruction of active vlan(4) interfaces or concurrent modification of a vlan(4) interface. The former readily produced several different panics. The changes can be summarized as using two global vlan locks (an rmlock(9) and an sx(9)) to protect accesses to the if_vlantrunk field of struct ifnet, in addition to other places where global exclusive access is required. vlan(4) should now be much more resilient to the destruction of active interfaces and concurrent calls into the configuration path. Modified: stable/11/sys/net/if_vlan.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/net/if_vlan.c ============================================================================== --- stable/11/sys/net/if_vlan.c Tue Sep 12 00:44:16 2017 (r323476) +++ stable/11/sys/net/if_vlan.c Tue Sep 12 03:54:04 2017 (r323477) @@ -1,6 +1,7 @@ /*- * Copyright 1998 Massachusetts Institute of Technology * Copyright 2012 ADARA Networks, Inc. + * Copyright 2017 Dell EMC Isilon * * Portions of this software were developed by Robert N. M. Watson under * contract to ADARA Networks, Inc. @@ -62,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -100,6 +102,53 @@ struct ifvlantrunk { int refcnt; }; +/* + * This macro provides a facility to iterate over every vlan on a trunk with + * the assumption that none will be added/removed during iteration. + */ +#ifdef VLAN_ARRAY +#define VLAN_FOREACH(_ifv, _trunk) \ + size_t _i; \ + for (_i = 0; _i < VLAN_ARRAY_SIZE; _i++) \ + if (((_ifv) = (_trunk)->vlans[_i]) != NULL) +#else /* VLAN_ARRAY */ +#define VLAN_FOREACH(_ifv, _trunk) \ + struct ifvlan *_next; \ + size_t _i; \ + for (_i = 0; _i < (1 << (_trunk)->hwidth); _i++) \ + LIST_FOREACH_SAFE((_ifv), &(_trunk)->hash[_i], ifv_list, _next) +#endif /* VLAN_ARRAY */ + +/* + * This macro provides a facility to iterate over every vlan on a trunk while + * also modifying the number of vlans on the trunk. The iteration continues + * until some condition is met or there are no more vlans on the trunk. + */ +#ifdef VLAN_ARRAY +/* The VLAN_ARRAY case is simple -- just a for loop using the condition. */ +#define VLAN_FOREACH_UNTIL_SAFE(_ifv, _trunk, _cond) \ + size_t _i; \ + for (_i = 0; !(_cond) && _i < VLAN_ARRAY_SIZE; _i++) \ + if (((_ifv) = (_trunk)->vlans[_i])) +#else /* VLAN_ARRAY */ +/* + * The hash table case is more complicated. We allow for the hash table to be + * modified (i.e. vlans removed) while we are iterating over it. To allow for + * this we must restart the iteration every time we "touch" something during + * the iteration, since removal will resize the hash table and invalidate our + * current position. If acting on the touched element causes the trunk to be + * emptied, then iteration also stops. + */ +#define VLAN_FOREACH_UNTIL_SAFE(_ifv, _trunk, _cond) \ + size_t _i; \ + bool _touch = false; \ + for (_i = 0; \ + !(_cond) && _i < (1 << (_trunk)->hwidth); \ + _i = (_touch && ((_trunk) != NULL) ? 0 : _i + 1), _touch = false) \ + if (((_ifv) = LIST_FIRST(&(_trunk)->hash[_i])) != NULL && \ + (_touch = true)) +#endif /* VLAN_ARRAY */ + struct vlan_mc_entry { struct sockaddr_dl mc_addr; SLIST_ENTRY(vlan_mc_entry) mc_entries; @@ -122,6 +171,7 @@ struct ifvlan { uint16_t ifvm_vid; /* VLAN ID */ uint8_t ifvm_pcp; /* Priority Code Point (PCP). */ } ifv_mib; + struct task lladdr_task; SLIST_HEAD(, vlan_mc_entry) vlan_mc_listhead; #ifndef VLAN_ARRAY LIST_ENTRY(ifvlan) ifv_list; @@ -172,33 +222,92 @@ static eventhandler_tag ifdetach_tag; static eventhandler_tag iflladdr_tag; /* - * We have a global mutex, that is used to serialize configuration - * changes and isn't used in normal packet delivery. + * if_vlan uses two module-level locks to allow concurrent modification of vlan + * interfaces and (mostly) allow for vlans to be destroyed while they are being + * used for tx/rx. To accomplish this in a way that has acceptable performance + * and cooperation with other parts of the network stack there is a + * non-sleepable rmlock(9) and an sx(9). Both locks are exclusively acquired + * when destroying a vlan interface, i.e. when the if_vlantrunk field of struct + * ifnet is de-allocated and NULL'd. Thus a reader holding either lock has a + * guarantee that the struct ifvlantrunk references a valid vlan trunk. * - * We also have a per-trunk rmlock(9), that is locked shared on packet - * processing and exclusive when configuration is changed. + * The performance-sensitive paths that warrant using the rmlock(9) are + * vlan_transmit and vlan_input. Both have to check for the vlan interface's + * existence using if_vlantrunk, and being in the network tx/rx paths the use + * of an rmlock(9) gives a measureable improvement in performance. * + * The reason for having an sx(9) is mostly because there are still areas that + * must be sleepable and also have safe concurrent access to a vlan interface. + * Since the sx(9) exists, it is used by default in most paths unless sleeping + * is not permitted, or if it is not clear whether sleeping is permitted. + * + * Note that despite these protections, there is still an inherent race in the + * destruction of vlans since there's no guarantee that the ifnet hasn't been + * freed/reused when the tx/rx functions are called by the stack. This can only + * be fixed by addressing ifnet's lifetime issues. + */ +#define _VLAN_RM_ID ifv_rm_lock +#define _VLAN_SX_ID ifv_sx + +static struct rmlock _VLAN_RM_ID; +static struct sx _VLAN_SX_ID; + +#define VLAN_LOCKING_INIT() \ + rm_init(&_VLAN_RM_ID, "vlan_rm"); \ + sx_init(&_VLAN_SX_ID, "vlan_sx") + +#define VLAN_LOCKING_DESTROY() \ + rm_destroy(&_VLAN_RM_ID); \ + sx_destroy(&_VLAN_SX_ID) + +#define _VLAN_RM_TRACKER _vlan_rm_tracker +#define VLAN_RLOCK() rm_rlock(&_VLAN_RM_ID, \ + &_VLAN_RM_TRACKER) +#define VLAN_RUNLOCK() rm_runlock(&_VLAN_RM_ID, \ + &_VLAN_RM_TRACKER) +#define VLAN_WLOCK() rm_wlock(&_VLAN_RM_ID) +#define VLAN_WUNLOCK() rm_wunlock(&_VLAN_RM_ID) +#define VLAN_RLOCK_ASSERT() rm_assert(&_VLAN_RM_ID, RA_RLOCKED) +#define VLAN_WLOCK_ASSERT() rm_assert(&_VLAN_RM_ID, RA_WLOCKED) +#define VLAN_RWLOCK_ASSERT() rm_assert(&_VLAN_RM_ID, RA_LOCKED) +#define VLAN_LOCK_READER struct rm_priotracker _VLAN_RM_TRACKER + +#define VLAN_SLOCK() sx_slock(&_VLAN_SX_ID) +#define VLAN_SUNLOCK() sx_sunlock(&_VLAN_SX_ID) +#define VLAN_XLOCK() sx_xlock(&_VLAN_SX_ID) +#define VLAN_XUNLOCK() sx_xunlock(&_VLAN_SX_ID) +#define VLAN_SLOCK_ASSERT() sx_assert(&_VLAN_SX_ID, SA_SLOCKED) +#define VLAN_XLOCK_ASSERT() sx_assert(&_VLAN_SX_ID, SA_XLOCKED) +#define VLAN_SXLOCK_ASSERT() sx_assert(&_VLAN_SX_ID, SA_LOCKED) + + +/* + * We also have a per-trunk rmlock(9), that is locked shared on packet + * processing and exclusive when configuration is changed. Note: This should + * only be acquired while there is a shared lock on either of the global locks + * via VLAN_SLOCK or VLAN_RLOCK. Thus, an exclusive lock on the global locks + * makes a call to TRUNK_RLOCK/TRUNK_WLOCK technically superfluous. + */ +#define _TRUNK_RM_TRACKER _trunk_rm_tracker +#define TRUNK_LOCK_INIT(trunk) rm_init(&(trunk)->lock, vlanname) +#define TRUNK_LOCK_DESTROY(trunk) rm_destroy(&(trunk)->lock) +#define TRUNK_RLOCK(trunk) rm_rlock(&(trunk)->lock, \ + &_TRUNK_RM_TRACKER) +#define TRUNK_WLOCK(trunk) rm_wlock(&(trunk)->lock) +#define TRUNK_RUNLOCK(trunk) rm_runlock(&(trunk)->lock, \ + &_TRUNK_RM_TRACKER) +#define TRUNK_WUNLOCK(trunk) rm_wunlock(&(trunk)->lock) +#define TRUNK_RLOCK_ASSERT(trunk) rm_assert(&(trunk)->lock, RA_RLOCKED) +#define TRUNK_LOCK_ASSERT(trunk) rm_assert(&(trunk)->lock, RA_LOCKED) +#define TRUNK_WLOCK_ASSERT(trunk) rm_assert(&(trunk)->lock, RA_WLOCKED) +#define TRUNK_LOCK_READER struct rm_priotracker _TRUNK_RM_TRACKER + +/* * The VLAN_ARRAY substitutes the dynamic hash with a static array * with 4096 entries. In theory this can give a boost in processing, - * however on practice it does not. Probably this is because array + * however in practice it does not. Probably this is because the array * is too big to fit into CPU cache. */ -static struct sx ifv_lock; -#define VLAN_LOCK_INIT() sx_init(&ifv_lock, "vlan_global") -#define VLAN_LOCK_DESTROY() sx_destroy(&ifv_lock) -#define VLAN_LOCK_ASSERT() sx_assert(&ifv_lock, SA_LOCKED) -#define VLAN_LOCK() sx_xlock(&ifv_lock) -#define VLAN_UNLOCK() sx_xunlock(&ifv_lock) -#define TRUNK_LOCK_INIT(trunk) rm_init(&(trunk)->lock, vlanname) -#define TRUNK_LOCK_DESTROY(trunk) rm_destroy(&(trunk)->lock) -#define TRUNK_LOCK(trunk) rm_wlock(&(trunk)->lock) -#define TRUNK_UNLOCK(trunk) rm_wunlock(&(trunk)->lock) -#define TRUNK_LOCK_ASSERT(trunk) rm_assert(&(trunk)->lock, RA_WLOCKED) -#define TRUNK_RLOCK(trunk) rm_rlock(&(trunk)->lock, &tracker) -#define TRUNK_RUNLOCK(trunk) rm_runlock(&(trunk)->lock, &tracker) -#define TRUNK_LOCK_RASSERT(trunk) rm_assert(&(trunk)->lock, RA_RLOCKED) -#define TRUNK_LOCK_READER struct rm_priotracker tracker - #ifndef VLAN_ARRAY static void vlan_inithash(struct ifvlantrunk *trunk); static void vlan_freehash(struct ifvlantrunk *trunk); @@ -234,6 +343,8 @@ static int vlan_clone_destroy(struct if_clone *, struc static void vlan_ifdetach(void *arg, struct ifnet *ifp); static void vlan_iflladdr(void *arg, struct ifnet *ifp); +static void vlan_lladdr_fn(void *arg, int pending); + static struct if_clone *vlan_cloner; #ifdef VIMAGE @@ -288,7 +399,7 @@ vlan_inshash(struct ifvlantrunk *trunk, struct ifvlan int i, b; struct ifvlan *ifv2; - TRUNK_LOCK_ASSERT(trunk); + TRUNK_WLOCK_ASSERT(trunk); KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__)); b = 1 << trunk->hwidth; @@ -318,7 +429,7 @@ vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan int i, b; struct ifvlan *ifv2; - TRUNK_LOCK_ASSERT(trunk); + TRUNK_WLOCK_ASSERT(trunk); KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__)); b = 1 << trunk->hwidth; @@ -346,7 +457,7 @@ vlan_growhash(struct ifvlantrunk *trunk, int howmuch) struct ifvlanhead *hash2; int hwidth2, i, j, n, n2; - TRUNK_LOCK_ASSERT(trunk); + TRUNK_WLOCK_ASSERT(trunk); KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__)); if (howmuch == 0) { @@ -392,7 +503,7 @@ vlan_gethash(struct ifvlantrunk *trunk, uint16_t vid) { struct ifvlan *ifv; - TRUNK_LOCK_RASSERT(trunk); + TRUNK_RLOCK_ASSERT(trunk); LIST_FOREACH(ifv, &trunk->hash[HASH(vid, trunk->hmask)], ifv_list) if (ifv->ifv_vid == vid) @@ -462,12 +573,11 @@ vlan_inithash(struct ifvlantrunk *trunk) static void trunk_destroy(struct ifvlantrunk *trunk) { - VLAN_LOCK_ASSERT(); + VLAN_XLOCK_ASSERT(); + VLAN_WLOCK_ASSERT(); - TRUNK_LOCK(trunk); vlan_freehash(trunk); trunk->parent->if_vlantrunk = NULL; - TRUNK_UNLOCK(trunk); TRUNK_LOCK_DESTROY(trunk); if_rele(trunk->parent); free(trunk, M_VLAN); @@ -490,9 +600,15 @@ vlan_setmulti(struct ifnet *ifp) struct vlan_mc_entry *mc; int error; + /* + * XXX This stupidly needs the rmlock to avoid sleeping while holding + * the in6_multi_mtx (see in6_mc_join_locked). + */ + VLAN_RWLOCK_ASSERT(); + /* Find the parent. */ sc = ifp->if_softc; - TRUNK_LOCK_ASSERT(TRUNK(sc)); + TRUNK_WLOCK_ASSERT(TRUNK(sc)); ifp_p = PARENT(sc); CURVNET_SET_QUIET(ifp_p->if_vnet); @@ -539,36 +655,42 @@ static void vlan_iflladdr(void *arg __unused, struct ifnet *ifp) { struct ifvlan *ifv; -#ifndef VLAN_ARRAY - struct ifvlan *next; -#endif - int i; + struct ifnet *ifv_ifp; + struct ifvlantrunk *trunk; + struct sockaddr_dl *sdl; + VLAN_LOCK_READER; - /* - * Check if it's a trunk interface first of all - * to avoid needless locking. - */ - if (ifp->if_vlantrunk == NULL) + /* Need the rmlock since this is run on taskqueue_swi. */ + VLAN_RLOCK(); + trunk = ifp->if_vlantrunk; + if (trunk == NULL) { + VLAN_RUNLOCK(); return; + } - VLAN_LOCK(); /* * OK, it's a trunk. Loop over and change all vlan's lladdrs on it. + * We need an exclusive lock here to prevent concurrent SIOCSIFLLADDR + * ioctl calls on the parent garbling the lladdr of the child vlan. */ -#ifdef VLAN_ARRAY - for (i = 0; i < VLAN_ARRAY_SIZE; i++) - if ((ifv = ifp->if_vlantrunk->vlans[i])) { -#else /* VLAN_ARRAY */ - for (i = 0; i < (1 << ifp->if_vlantrunk->hwidth); i++) - LIST_FOREACH_SAFE(ifv, &ifp->if_vlantrunk->hash[i], ifv_list, next) { -#endif /* VLAN_ARRAY */ - VLAN_UNLOCK(); - if_setlladdr(ifv->ifv_ifp, IF_LLADDR(ifp), - ifp->if_addrlen); - VLAN_LOCK(); - } - VLAN_UNLOCK(); - + TRUNK_WLOCK(trunk); + VLAN_FOREACH(ifv, trunk) { + /* + * Copy new new lladdr into the ifv_ifp, enqueue a task + * to actually call if_setlladdr. if_setlladdr needs to + * be deferred to a taskqueue because it will call into + * the if_vlan ioctl path and try to acquire the global + * lock. + */ + ifv_ifp = ifv->ifv_ifp; + bcopy(IF_LLADDR(ifp), IF_LLADDR(ifv_ifp), + ifp->if_addrlen); + sdl = (struct sockaddr_dl *)ifv_ifp->if_addr->ifa_addr; + sdl->sdl_alen = ifp->if_addrlen; + taskqueue_enqueue(taskqueue_thread, &ifv->lladdr_task); + } + TRUNK_WUNLOCK(trunk); + VLAN_RUNLOCK(); } /* @@ -582,46 +704,30 @@ static void vlan_ifdetach(void *arg __unused, struct ifnet *ifp) { struct ifvlan *ifv; - int i; + struct ifvlantrunk *trunk; - /* - * Check if it's a trunk interface first of all - * to avoid needless locking. - */ - if (ifp->if_vlantrunk == NULL) - return; - /* If the ifnet is just being renamed, don't do anything. */ if (ifp->if_flags & IFF_RENAMING) return; + VLAN_XLOCK(); + trunk = ifp->if_vlantrunk; + if (trunk == NULL) { + VLAN_XUNLOCK(); + return; + } - VLAN_LOCK(); /* * OK, it's a trunk. Loop over and detach all vlan's on it. * Check trunk pointer after each vlan_unconfig() as it will * free it and set to NULL after the last vlan was detached. */ -#ifdef VLAN_ARRAY - for (i = 0; i < VLAN_ARRAY_SIZE; i++) - if ((ifv = ifp->if_vlantrunk->vlans[i])) { - vlan_unconfig_locked(ifv->ifv_ifp, 1); - if (ifp->if_vlantrunk == NULL) - break; - } -#else /* VLAN_ARRAY */ -restart: - for (i = 0; i < (1 << ifp->if_vlantrunk->hwidth); i++) - if ((ifv = LIST_FIRST(&ifp->if_vlantrunk->hash[i]))) { - vlan_unconfig_locked(ifv->ifv_ifp, 1); - if (ifp->if_vlantrunk) - goto restart; /* trunk->hwidth can change */ - else - break; - } -#endif /* VLAN_ARRAY */ + VLAN_FOREACH_UNTIL_SAFE(ifv, ifp->if_vlantrunk, + ifp->if_vlantrunk == NULL) + vlan_unconfig_locked(ifv->ifv_ifp, 1); + /* Trunk should have been destroyed in vlan_unconfig(). */ KASSERT(ifp->if_vlantrunk == NULL, ("%s: purge failed", __func__)); - VLAN_UNLOCK(); + VLAN_XUNLOCK(); } /* @@ -631,15 +737,18 @@ static struct ifnet * vlan_trunkdev(struct ifnet *ifp) { struct ifvlan *ifv; + VLAN_LOCK_READER; if (ifp->if_type != IFT_L2VLAN) return (NULL); + + /* Not clear if callers are sleepable, so acquire the rmlock. */ + VLAN_RLOCK(); ifv = ifp->if_softc; ifp = NULL; - VLAN_LOCK(); if (ifv->ifv_trunk) ifp = PARENT(ifv); - VLAN_UNLOCK(); + VLAN_RUNLOCK(); return (ifp); } @@ -701,17 +810,23 @@ vlan_devat(struct ifnet *ifp, uint16_t vid) { struct ifvlantrunk *trunk; struct ifvlan *ifv; + VLAN_LOCK_READER; TRUNK_LOCK_READER; + /* Not clear if callers are sleepable, so acquire the rmlock. */ + VLAN_RLOCK(); trunk = ifp->if_vlantrunk; - if (trunk == NULL) + if (trunk == NULL) { + VLAN_RUNLOCK(); return (NULL); + } ifp = NULL; TRUNK_RLOCK(trunk); ifv = vlan_gethash(trunk, vid); if (ifv) ifp = ifv->ifv_ifp; TRUNK_RUNLOCK(trunk); + VLAN_RUNLOCK(); return (ifp); } @@ -751,7 +866,7 @@ vlan_modevent(module_t mod, int type, void *data) vlan_iflladdr, NULL, EVENTHANDLER_PRI_ANY); if (iflladdr_tag == NULL) return (ENOMEM); - VLAN_LOCK_INIT(); + VLAN_LOCKING_INIT(); vlan_input_p = vlan_input; vlan_link_state_p = vlan_link_state; vlan_trunk_cap_p = vlan_trunk_capabilities; @@ -788,7 +903,7 @@ vlan_modevent(module_t mod, int type, void *data) vlan_cookie_p = NULL; vlan_setcookie_p = NULL; vlan_devat_p = NULL; - VLAN_LOCK_DESTROY(); + VLAN_LOCKING_DESTROY(); if (bootverbose) printf("vlan: unloaded\n"); break; @@ -1006,9 +1121,6 @@ vlan_clone_create(struct if_clone *ifc, char *name, si return (error); } - - /* Update flags on the parent, if necessary. */ - vlan_setflags(ifp, 1); } return (0); @@ -1022,6 +1134,12 @@ vlan_clone_destroy(struct if_clone *ifc, struct ifnet ether_ifdetach(ifp); /* first, remove it from system-wide lists */ vlan_unconfig(ifp); /* now it can be unconfigured and freed */ + /* + * We should have the only reference to the ifv now, so we can now + * drain any remaining lladdr task before freeing the ifnet and the + * ifvlan. + */ + taskqueue_drain(taskqueue_thread, &ifv->lladdr_task); if_free(ifp); free(ifv, M_VLAN); ifc_free_unit(ifc, unit); @@ -1048,8 +1166,16 @@ vlan_transmit(struct ifnet *ifp, struct mbuf *m) struct m_tag *mtag; uint16_t tag; int error, len, mcast; + VLAN_LOCK_READER; + VLAN_RLOCK(); ifv = ifp->if_softc; + if (TRUNK(ifv) == NULL) { + if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); + VLAN_RUNLOCK(); + m_freem(m); + return (ENETDOWN); + } p = PARENT(ifv); len = m->m_pkthdr.len; mcast = (m->m_flags & (M_MCAST | M_BCAST)) ? 1 : 0; @@ -1061,8 +1187,9 @@ vlan_transmit(struct ifnet *ifp, struct mbuf *m) * or parent's driver will cause a system crash. */ if (!UP_AND_RUNNING(p)) { - m_freem(m); if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); + VLAN_RUNLOCK(); + m_freem(m); return (ENETDOWN); } @@ -1090,6 +1217,7 @@ vlan_transmit(struct ifnet *ifp, struct mbuf *m) if (n > 0) { if_printf(ifp, "cannot pad short frame\n"); if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); + VLAN_RUNLOCK(); m_freem(m); return (0); } @@ -1115,6 +1243,7 @@ vlan_transmit(struct ifnet *ifp, struct mbuf *m) if (m == NULL) { if_printf(ifp, "unable to prepend VLAN header\n"); if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); + VLAN_RUNLOCK(); return (0); } } @@ -1129,6 +1258,7 @@ vlan_transmit(struct ifnet *ifp, struct mbuf *m) if_inc_counter(ifp, IFCOUNTER_OMCASTS, mcast); } else if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); + VLAN_RUNLOCK(); return (error); } @@ -1143,13 +1273,20 @@ vlan_qflush(struct ifnet *ifp __unused) static void vlan_input(struct ifnet *ifp, struct mbuf *m) { - struct ifvlantrunk *trunk = ifp->if_vlantrunk; + struct ifvlantrunk *trunk; struct ifvlan *ifv; + VLAN_LOCK_READER; TRUNK_LOCK_READER; struct m_tag *mtag; uint16_t vid, tag; - KASSERT(trunk != NULL, ("%s: no trunk", __func__)); + VLAN_RLOCK(); + trunk = ifp->if_vlantrunk; + if (trunk == NULL) { + VLAN_RUNLOCK(); + m_freem(m); + return; + } if (m->m_flags & M_VLANTAG) { /* @@ -1169,6 +1306,7 @@ vlan_input(struct ifnet *ifp, struct mbuf *m) if (m->m_len < sizeof(*evl) && (m = m_pullup(m, sizeof(*evl))) == NULL) { if_printf(ifp, "cannot pullup VLAN header\n"); + VLAN_RUNLOCK(); return; } evl = mtod(m, struct ether_vlan_header *); @@ -1190,8 +1328,9 @@ vlan_input(struct ifnet *ifp, struct mbuf *m) panic("%s: %s has unsupported if_type %u", __func__, ifp->if_xname, ifp->if_type); #endif - m_freem(m); if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1); + VLAN_RUNLOCK(); + m_freem(m); return; } } @@ -1202,8 +1341,9 @@ vlan_input(struct ifnet *ifp, struct mbuf *m) ifv = vlan_gethash(trunk, vid); if (ifv == NULL || !UP_AND_RUNNING(ifv->ifv_ifp)) { TRUNK_RUNLOCK(trunk); - m_freem(m); if_inc_counter(ifp, IFCOUNTER_NOPROTO, 1); + VLAN_RUNLOCK(); + m_freem(m); return; } TRUNK_RUNLOCK(trunk); @@ -1221,8 +1361,9 @@ vlan_input(struct ifnet *ifp, struct mbuf *m) mtag = m_tag_alloc(MTAG_8021Q, MTAG_8021Q_PCP_IN, sizeof(uint8_t), M_NOWAIT); if (mtag == NULL) { - m_freem(m); if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); + VLAN_RUNLOCK(); + m_freem(m); return; } m_tag_prepend(m, mtag); @@ -1232,11 +1373,24 @@ vlan_input(struct ifnet *ifp, struct mbuf *m) m->m_pkthdr.rcvif = ifv->ifv_ifp; if_inc_counter(ifv->ifv_ifp, IFCOUNTER_IPACKETS, 1); + VLAN_RUNLOCK(); /* Pass it back through the parent's input routine. */ (*ifp->if_input)(ifv->ifv_ifp, m); } +static void +vlan_lladdr_fn(void *arg, int pending __unused) +{ + struct ifvlan *ifv; + struct ifnet *ifp; + + ifv = (struct ifvlan *)arg; + ifp = ifv->ifv_ifp; + /* The ifv_ifp already has the lladdr copied in. */ + if_setlladdr(ifp, IF_LLADDR(ifp), ifp->if_addrlen); +} + static int vlan_config(struct ifvlan *ifv, struct ifnet *p, uint16_t vid) { @@ -1263,27 +1417,22 @@ vlan_config(struct ifvlan *ifv, struct ifnet *p, uint1 if (ifv->ifv_trunk) return (EBUSY); + /* Acquire rmlock after the branch so we can M_WAITOK. */ + VLAN_XLOCK(); if (p->if_vlantrunk == NULL) { trunk = malloc(sizeof(struct ifvlantrunk), M_VLAN, M_WAITOK | M_ZERO); vlan_inithash(trunk); - VLAN_LOCK(); - if (p->if_vlantrunk != NULL) { - /* A race that is very unlikely to be hit. */ - vlan_freehash(trunk); - free(trunk, M_VLAN); - goto exists; - } TRUNK_LOCK_INIT(trunk); - TRUNK_LOCK(trunk); + VLAN_WLOCK(); + TRUNK_WLOCK(trunk); p->if_vlantrunk = trunk; trunk->parent = p; if_ref(trunk->parent); } else { - VLAN_LOCK(); -exists: + VLAN_WLOCK(); trunk = p->if_vlantrunk; - TRUNK_LOCK(trunk); + TRUNK_WLOCK(trunk); } ifv->ifv_vid = vid; /* must set this before vlan_inshash() */ @@ -1360,15 +1509,25 @@ exists: * Configure multicast addresses that may already be * joined on the vlan device. */ - (void)vlan_setmulti(ifp); /* XXX: VLAN lock held */ + (void)vlan_setmulti(ifp); + TASK_INIT(&ifv->lladdr_task, 0, vlan_lladdr_fn, ifv); + /* We are ready for operation now. */ ifp->if_drv_flags |= IFF_DRV_RUNNING; + + /* Update flags on the parent, if necessary. */ + vlan_setflags(ifp, 1); done: - TRUNK_UNLOCK(trunk); + /* + * We need to drop the non-sleepable rmlock so that the underlying + * devices can sleep in their vlan_config hooks. + */ + TRUNK_WUNLOCK(trunk); + VLAN_WUNLOCK(); if (error == 0) EVENTHANDLER_INVOKE(vlan_config, p, ifv->ifv_vid); - VLAN_UNLOCK(); + VLAN_XUNLOCK(); return (error); } @@ -1377,9 +1536,9 @@ static void vlan_unconfig(struct ifnet *ifp) { - VLAN_LOCK(); + VLAN_XLOCK(); vlan_unconfig_locked(ifp, 0); - VLAN_UNLOCK(); + VLAN_XUNLOCK(); } static void @@ -1391,15 +1550,20 @@ vlan_unconfig_locked(struct ifnet *ifp, int departing) struct ifnet *parent; int error; - VLAN_LOCK_ASSERT(); + VLAN_XLOCK_ASSERT(); ifv = ifp->if_softc; trunk = ifv->ifv_trunk; parent = NULL; if (trunk != NULL) { - - TRUNK_LOCK(trunk); + /* + * Both vlan_transmit and vlan_input rely on the trunk fields + * being NULL to determine whether to bail, so we need to get + * an exclusive lock here to prevent them from using bad + * ifvlans. + */ + VLAN_WLOCK(); parent = trunk->parent; /* @@ -1429,7 +1593,14 @@ vlan_unconfig_locked(struct ifnet *ifp, int departing) } vlan_setflags(ifp, 0); /* clear special flags on parent */ + + /* + * The trunk lock isn't actually required here, but + * vlan_remhash expects it. + */ + TRUNK_WLOCK(trunk); vlan_remhash(trunk, ifv); + TRUNK_WUNLOCK(trunk); ifv->ifv_trunk = NULL; /* @@ -1437,17 +1608,9 @@ vlan_unconfig_locked(struct ifnet *ifp, int departing) */ if (trunk->refcnt == 0) { parent->if_vlantrunk = NULL; - /* - * XXXGL: If some ithread has already entered - * vlan_input() and is now blocked on the trunk - * lock, then it should preempt us right after - * unlock and finish its work. Then we will acquire - * lock again in trunk_destroy(). - */ - TRUNK_UNLOCK(trunk); trunk_destroy(trunk); - } else - TRUNK_UNLOCK(trunk); + } + VLAN_WUNLOCK(); } /* Disconnect from parent. */ @@ -1474,7 +1637,7 @@ vlan_setflag(struct ifnet *ifp, int flag, int status, struct ifvlan *ifv; int error; - /* XXX VLAN_LOCK_ASSERT(); */ + VLAN_SXLOCK_ASSERT(); ifv = ifp->if_softc; status = status ? (ifp->if_flags & flag) : 0; @@ -1522,36 +1685,41 @@ vlan_setflags(struct ifnet *ifp, int status) static void vlan_link_state(struct ifnet *ifp) { - struct ifvlantrunk *trunk = ifp->if_vlantrunk; + struct ifvlantrunk *trunk; struct ifvlan *ifv; - int i; + VLAN_LOCK_READER; - TRUNK_LOCK(trunk); -#ifdef VLAN_ARRAY - for (i = 0; i < VLAN_ARRAY_SIZE; i++) - if (trunk->vlans[i] != NULL) { - ifv = trunk->vlans[i]; -#else - for (i = 0; i < (1 << trunk->hwidth); i++) - LIST_FOREACH(ifv, &trunk->hash[i], ifv_list) { -#endif - ifv->ifv_ifp->if_baudrate = trunk->parent->if_baudrate; - if_link_state_change(ifv->ifv_ifp, - trunk->parent->if_link_state); - } - TRUNK_UNLOCK(trunk); + /* Called from a taskqueue_swi task, so we cannot sleep. */ + VLAN_RLOCK(); + trunk = ifp->if_vlantrunk; + if (trunk == NULL) { + VLAN_RUNLOCK(); + return; + } + + TRUNK_WLOCK(trunk); + VLAN_FOREACH(ifv, trunk) { + ifv->ifv_ifp->if_baudrate = trunk->parent->if_baudrate; + if_link_state_change(ifv->ifv_ifp, + trunk->parent->if_link_state); + } + TRUNK_WUNLOCK(trunk); + VLAN_RUNLOCK(); } static void vlan_capabilities(struct ifvlan *ifv) { - struct ifnet *p = PARENT(ifv); - struct ifnet *ifp = ifv->ifv_ifp; + struct ifnet *p; + struct ifnet *ifp; struct ifnet_hw_tsomax hw_tsomax; int cap = 0, ena = 0, mena; u_long hwa = 0; - TRUNK_LOCK_ASSERT(TRUNK(ifv)); + VLAN_SXLOCK_ASSERT(); + TRUNK_WLOCK_ASSERT(TRUNK(ifv)); + p = PARENT(ifv); + ifp = ifv->ifv_ifp; /* Mask parent interface enabled capabilities disabled by user. */ mena = p->if_capenable & ifv->ifv_capenable; @@ -1632,22 +1800,21 @@ vlan_capabilities(struct ifvlan *ifv) static void vlan_trunk_capabilities(struct ifnet *ifp) { - struct ifvlantrunk *trunk = ifp->if_vlantrunk; + struct ifvlantrunk *trunk; struct ifvlan *ifv; - int i; - TRUNK_LOCK(trunk); -#ifdef VLAN_ARRAY - for (i = 0; i < VLAN_ARRAY_SIZE; i++) - if (trunk->vlans[i] != NULL) { - ifv = trunk->vlans[i]; -#else - for (i = 0; i < (1 << trunk->hwidth); i++) { - LIST_FOREACH(ifv, &trunk->hash[i], ifv_list) -#endif - vlan_capabilities(ifv); + VLAN_SLOCK(); + trunk = ifp->if_vlantrunk; + if (trunk == NULL) { + VLAN_SUNLOCK(); + return; } - TRUNK_UNLOCK(trunk); + TRUNK_WLOCK(trunk); + VLAN_FOREACH(ifv, trunk) { + vlan_capabilities(ifv); + } + TRUNK_WUNLOCK(trunk); + VLAN_SUNLOCK(); } static int @@ -1660,6 +1827,7 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data struct ifvlantrunk *trunk; struct vlanreq vlr; int error = 0; + VLAN_LOCK_READER; ifr = (struct ifreq *)data; ifa = (struct ifaddr *) data; @@ -1682,11 +1850,10 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data } break; case SIOCGIFMEDIA: - VLAN_LOCK(); + VLAN_SLOCK(); if (TRUNK(ifv) != NULL) { p = PARENT(ifv); if_ref(p); - VLAN_UNLOCK(); error = (*p->if_ioctl)(p, SIOCGIFMEDIA, data); if_rele(p); /* Limit the result to the parent's current config. */ @@ -1702,9 +1869,9 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data } } } else { - VLAN_UNLOCK(); error = EINVAL; } + VLAN_SUNLOCK(); break; case SIOCSIFMEDIA: @@ -1715,8 +1882,10 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data /* * Set the interface MTU. */ - VLAN_LOCK(); - if (TRUNK(ifv) != NULL) { + VLAN_SLOCK(); + trunk = TRUNK(ifv); + if (trunk != NULL) { + TRUNK_WLOCK(trunk); if (ifr->ifr_mtu > (PARENT(ifv)->if_mtu - ifv->ifv_mtufudge) || ifr->ifr_mtu < @@ -1724,9 +1893,10 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data error = EINVAL; else ifp->if_mtu = ifr->ifr_mtu; + TRUNK_WUNLOCK(trunk); } else error = EINVAL; - VLAN_UNLOCK(); + VLAN_SUNLOCK(); break; case SIOCSETVLAN: @@ -1757,11 +1927,6 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data } error = vlan_config(ifv, p, vlr.vlr_tag); if_rele(p); - if (error) - break; - - /* Update flags on the parent, if necessary. */ - vlan_setflags(ifp, 1); break; case SIOCGETVLAN: @@ -1772,13 +1937,13 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data } #endif bzero(&vlr, sizeof(vlr)); - VLAN_LOCK(); + VLAN_SLOCK(); if (TRUNK(ifv) != NULL) { strlcpy(vlr.vlr_parent, PARENT(ifv)->if_xname, sizeof(vlr.vlr_parent)); vlr.vlr_tag = ifv->ifv_vid; } - VLAN_UNLOCK(); + VLAN_SUNLOCK(); error = copyout(&vlr, ifr->ifr_data, sizeof(vlr)); break; @@ -1787,8 +1952,10 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data * We should propagate selected flags to the parent, * e.g., promiscuous mode. */ + VLAN_XLOCK(); if (TRUNK(ifv) != NULL) error = vlan_setflags(ifp, 1); + VLAN_XUNLOCK(); break; case SIOCADDMULTI: @@ -1796,13 +1963,18 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data /* * If we don't have a parent, just remember the membership for * when we do. + * + * XXX We need the rmlock here to avoid sleeping while + * holding in6_multi_mtx. */ + VLAN_RLOCK(); trunk = TRUNK(ifv); if (trunk != NULL) { - TRUNK_LOCK(trunk); + TRUNK_WLOCK(trunk); error = vlan_setmulti(ifp); - TRUNK_UNLOCK(trunk); + TRUNK_WUNLOCK(trunk); } + VLAN_RUNLOCK(); break; case SIOCGVLANPCP: @@ -1834,15 +2006,15 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data break; case SIOCSIFCAP: - VLAN_LOCK(); + VLAN_SLOCK(); ifv->ifv_capenable = ifr->ifr_reqcap; trunk = TRUNK(ifv); if (trunk != NULL) { - TRUNK_LOCK(trunk); + TRUNK_WLOCK(trunk); vlan_capabilities(ifv); - TRUNK_UNLOCK(trunk); + TRUNK_WUNLOCK(trunk); } - VLAN_UNLOCK(); + VLAN_SUNLOCK(); break; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable-11@freebsd.org Tue Sep 12 06:19:21 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 34218E1B6AF; Tue, 12 Sep 2017 06:19:21 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id 0C6396369D; Tue, 12 Sep 2017 06:19:20 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8C6JK8T056805; Tue, 12 Sep 2017 06:19:20 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8C6JJ51056802; Tue, 12 Sep 2017 06:19:19 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709120619.v8C6JJ51056802@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Tue, 12 Sep 2017 06:19:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323484 - stable/11/sys/boot/efi/boot1 X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: stable/11/sys/boot/efi/boot1 X-SVN-Commit-Revision: 323484 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 06:19:21 -0000 Author: rlibby Date: Tue Sep 12 06:19:19 2017 New Revision: 323484 URL: https://svnweb.freebsd.org/changeset/base/323484 Log: MFC r303723 (by markj): Fix a few cosmetic issues in boot1.efi. Modified: stable/11/sys/boot/efi/boot1/boot1.c stable/11/sys/boot/efi/boot1/ufs_module.c stable/11/sys/boot/efi/boot1/zfs_module.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/boot/efi/boot1/boot1.c ============================================================================== --- stable/11/sys/boot/efi/boot1/boot1.c Tue Sep 12 06:06:58 2017 (r323483) +++ stable/11/sys/boot/efi/boot1/boot1.c Tue Sep 12 06:19:19 2017 (r323484) @@ -43,7 +43,7 @@ static const boot_module_t *boot_modules[] = #endif }; -#define NUM_BOOT_MODULES (sizeof(boot_modules) / sizeof(boot_module_t*)) +#define NUM_BOOT_MODULES nitems(boot_modules) /* The initial number of handles used to query EFI for partitions. */ #define NUM_HANDLES_INIT 24 @@ -330,8 +330,6 @@ load_loader(const boot_module_t **modp, dev_info_t **d const boot_module_t *mod; for (i = 0; i < NUM_BOOT_MODULES; i++) { - if (boot_modules[i] == NULL) - continue; mod = boot_modules[i]; for (dev = mod->devices(); dev != NULL; dev = dev->next) { if (dev->preferred != preferred) @@ -354,7 +352,7 @@ load_loader(const boot_module_t **modp, dev_info_t **d * it simply boots, otherwise it returns the status of last EFI call. */ static EFI_STATUS -try_boot() +try_boot(void) { size_t bufsize, loadersize, cmdsize; void *buf, *loaderbuf; @@ -497,9 +495,6 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, B /* Run through each module, see if it can load this partition */ for (i = 0; i < NUM_BOOT_MODULES; i++) { - if (boot_modules[i] == NULL) - continue; - if ((status = bs->AllocatePool(EfiLoaderData, sizeof(*devinfo), (void **)&devinfo)) != EFI_SUCCESS) { @@ -604,9 +599,6 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab) printf(" Loader path: %s\n\n", PATH_LOADER_EFI); printf(" Initializing modules:"); for (i = 0; i < NUM_BOOT_MODULES; i++) { - if (boot_modules[i] == NULL) - continue; - printf(" %s", boot_modules[i]->name); if (boot_modules[i]->init != NULL) boot_modules[i]->init(); @@ -666,10 +658,8 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab) /* Status summary. */ for (i = 0; i < NUM_BOOT_MODULES; i++) { - if (boot_modules[i] != NULL) { - printf(" "); - boot_modules[i]->status(); - } + printf(" "); + boot_modules[i]->status(); } try_boot(); Modified: stable/11/sys/boot/efi/boot1/ufs_module.c ============================================================================== --- stable/11/sys/boot/efi/boot1/ufs_module.c Tue Sep 12 06:06:58 2017 (r323483) +++ stable/11/sys/boot/efi/boot1/ufs_module.c Tue Sep 12 06:19:19 2017 (r323484) @@ -142,7 +142,7 @@ load(const char *filepath, dev_info_t *dev, void **buf } static void -status() +status(void) { int i; dev_info_t *dev; @@ -164,7 +164,7 @@ status() } static dev_info_t * -_devices() +_devices(void) { return (devices); Modified: stable/11/sys/boot/efi/boot1/zfs_module.c ============================================================================== --- stable/11/sys/boot/efi/boot1/zfs_module.c Tue Sep 12 06:06:58 2017 (r323483) +++ stable/11/sys/boot/efi/boot1/zfs_module.c Tue Sep 12 06:19:19 2017 (r323484) @@ -192,7 +192,7 @@ load(const char *filepath, dev_info_t *devinfo, void * } static void -status() +status(void) { spa_t *spa; @@ -210,14 +210,14 @@ status() } static void -init() +init(void) { zfs_init(); } static dev_info_t * -_devices() +_devices(void) { return (devices); From owner-svn-src-stable-11@freebsd.org Tue Sep 12 06:21:44 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AC74FE1B82E; Tue, 12 Sep 2017 06:21:44 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id 79DF8639E2; Tue, 12 Sep 2017 06:21:44 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8C6LhFZ060775; Tue, 12 Sep 2017 06:21:43 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8C6LhQp060772; Tue, 12 Sep 2017 06:21:43 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709120621.v8C6LhQp060772@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Tue, 12 Sep 2017 06:21:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323485 - in stable/11/sys/boot: arm/uboot efi/boot1 efi/loader X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: in stable/11/sys/boot: arm/uboot efi/boot1 efi/loader X-SVN-Commit-Revision: 323485 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 06:21:44 -0000 Author: rlibby Date: Tue Sep 12 06:21:43 2017 New Revision: 323485 URL: https://svnweb.freebsd.org/changeset/base/323485 Log: MFC r316119 (by ngie): self_reloc.c: Pass -Wno-error=maybe-uninitialized to gcc versions greater than 4.2.1 Modified: stable/11/sys/boot/arm/uboot/Makefile stable/11/sys/boot/efi/boot1/Makefile stable/11/sys/boot/efi/loader/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/boot/arm/uboot/Makefile ============================================================================== --- stable/11/sys/boot/arm/uboot/Makefile Tue Sep 12 06:19:19 2017 (r323484) +++ stable/11/sys/boot/arm/uboot/Makefile Tue Sep 12 06:21:43 2017 (r323485) @@ -15,6 +15,10 @@ UBLDR_LOADADDR?= 0x1000000 # Architecture-specific loader code SRCS= start.S conf.c self_reloc.c vers.c +.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} > 40201 +CWARNFLAGS.self_reloc.c+= -Wno-error=maybe-uninitialized +.endif + .if !defined(LOADER_NO_DISK_SUPPORT) LOADER_DISK_SUPPORT?= yes .else Modified: stable/11/sys/boot/efi/boot1/Makefile ============================================================================== --- stable/11/sys/boot/efi/boot1/Makefile Tue Sep 12 06:19:19 2017 (r323484) +++ stable/11/sys/boot/efi/boot1/Makefile Tue Sep 12 06:21:43 2017 (r323485) @@ -27,6 +27,10 @@ SRCS= boot1.c self_reloc.c start.S ufs_module.c SRCS+= zfs_module.c .endif +.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} > 40201 +CWARNFLAGS.self_reloc.c+= -Wno-error=maybe-uninitialized +.endif + CFLAGS+= -I. CFLAGS+= -I${.CURDIR}/../include CFLAGS+= -I${.CURDIR}/../include/${MACHINE} Modified: stable/11/sys/boot/efi/loader/Makefile ============================================================================== --- stable/11/sys/boot/efi/loader/Makefile Tue Sep 12 06:19:19 2017 (r323484) +++ stable/11/sys/boot/efi/loader/Makefile Tue Sep 12 06:21:43 2017 (r323485) @@ -31,6 +31,10 @@ CWARNFLAGS.zfs.c+= -Wno-array-bounds CWARNFLAGS.zfs.c+= -Wno-missing-prototypes .endif +.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} > 40201 +CWARNFLAGS.self_reloc.c+= -Wno-error=maybe-uninitialized +.endif + # We implement a slightly non-standard %S in that it always takes a # CHAR16 that's common in UEFI-land instead of a wchar_t. This only # seems to matter on arm64 where wchar_t defaults to an int instead From owner-svn-src-stable-11@freebsd.org Tue Sep 12 06:24:45 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 90F38E1BB47; Tue, 12 Sep 2017 06:24:45 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id 5A2C263BCA; Tue, 12 Sep 2017 06:24:45 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8C6OivW060940; Tue, 12 Sep 2017 06:24:44 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8C6Oip4060938; Tue, 12 Sep 2017 06:24:44 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709120624.v8C6Oip4060938@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Tue, 12 Sep 2017 06:24:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323486 - in stable/11/sys: amd64/include sys X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: in stable/11/sys: amd64/include sys X-SVN-Commit-Revision: 323486 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 06:24:45 -0000 Author: rlibby Date: Tue Sep 12 06:24:44 2017 New Revision: 323486 URL: https://svnweb.freebsd.org/changeset/base/323486 Log: MFC r321284: efi: restrict visibility of EFIABI_ATTR-declared functions Modified: stable/11/sys/amd64/include/efi.h stable/11/sys/sys/efi.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/amd64/include/efi.h ============================================================================== --- stable/11/sys/amd64/include/efi.h Tue Sep 12 06:21:43 2017 (r323485) +++ stable/11/sys/amd64/include/efi.h Tue Sep 12 06:24:44 2017 (r323486) @@ -36,8 +36,14 @@ * XXX: from gcc 6.2 manual: * Note, the ms_abi attribute for Microsoft Windows 64-bit targets * currently requires the -maccumulate-outgoing-args option. + * + * Avoid EFIABI_ATTR declarations for compilers that don't support it. + * GCC support began in version 4.4. */ +#if defined(__clang__) || defined(__GNUC__) && \ + (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4) #define EFIABI_ATTR __attribute__((ms_abi)) +#endif #ifdef _KERNEL struct uuid; Modified: stable/11/sys/sys/efi.h ============================================================================== --- stable/11/sys/sys/efi.h Tue Sep 12 06:21:43 2017 (r323485) +++ stable/11/sys/sys/efi.h Tue Sep 12 06:24:44 2017 (r323486) @@ -122,6 +122,9 @@ struct efi_tblhdr { uint32_t __res; }; +#ifdef _KERNEL + +#ifdef EFIABI_ATTR struct efi_rt { struct efi_tblhdr rt_hdr; efi_status (*rt_gettime)(struct efi_tm *, struct efi_tmcap *) @@ -144,6 +147,7 @@ struct efi_rt { efi_status (*rt_reset)(enum efi_reset, efi_status, u_long, efi_char *) EFIABI_ATTR; }; +#endif struct efi_systbl { struct efi_tblhdr st_hdr; @@ -163,7 +167,6 @@ struct efi_systbl { uint64_t st_cfgtbl; }; -#ifdef _KERNEL extern vm_paddr_t efi_systbl_phys; #endif /* _KERNEL */ From owner-svn-src-stable-11@freebsd.org Tue Sep 12 06:27:20 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A2369E1BCE4; Tue, 12 Sep 2017 06:27:20 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id 6B8AE63D34; Tue, 12 Sep 2017 06:27:20 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8C6RJCv061088; Tue, 12 Sep 2017 06:27:19 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8C6RJVK061087; Tue, 12 Sep 2017 06:27:19 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709120627.v8C6RJVK061087@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Tue, 12 Sep 2017 06:27:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323487 - stable/11/lib/libefivar X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: stable/11/lib/libefivar X-SVN-Commit-Revision: 323487 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 06:27:20 -0000 Author: rlibby Date: Tue Sep 12 06:27:19 2017 New Revision: 323487 URL: https://svnweb.freebsd.org/changeset/base/323487 Log: MFC r323155: libefivar: -fno-strict-aliasing Modified: stable/11/lib/libefivar/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libefivar/Makefile ============================================================================== --- stable/11/lib/libefivar/Makefile Tue Sep 12 06:24:44 2017 (r323486) +++ stable/11/lib/libefivar/Makefile Tue Sep 12 06:27:19 2017 (r323487) @@ -64,4 +64,4 @@ WARNS?= 9 .include -CFLAGS+= -Wno-cast-align -Wno-unused-parameter +CFLAGS+= -fno-strict-aliasing -Wno-cast-align -Wno-unused-parameter From owner-svn-src-stable-11@freebsd.org Tue Sep 12 06:31:54 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E93A7E1C13B; Tue, 12 Sep 2017 06:31:54 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id B614A64227; Tue, 12 Sep 2017 06:31:54 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8C6Vr9B062032; Tue, 12 Sep 2017 06:31:53 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8C6VrmM062030; Tue, 12 Sep 2017 06:31:53 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709120631.v8C6VrmM062030@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Tue, 12 Sep 2017 06:31:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323488 - stable/11/sys/amd64/amd64 X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: stable/11/sys/amd64/amd64 X-SVN-Commit-Revision: 323488 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 06:31:55 -0000 Author: rlibby Date: Tue Sep 12 06:31:53 2017 New Revision: 323488 URL: https://svnweb.freebsd.org/changeset/base/323488 Log: MFC r322940: amd64: drop q suffix from rd[fg]sbase for gas compatibility Modified: stable/11/sys/amd64/amd64/cpu_switch.S stable/11/sys/amd64/amd64/exception.S Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/amd64/amd64/cpu_switch.S ============================================================================== --- stable/11/sys/amd64/amd64/cpu_switch.S Tue Sep 12 06:27:19 2017 (r323487) +++ stable/11/sys/amd64/amd64/cpu_switch.S Tue Sep 12 06:31:53 2017 (r323488) @@ -108,7 +108,7 @@ ENTRY(cpu_switch) movl %fs,%eax cmpl $KUF32SEL,%eax jne 1f - rdfsbaseq %rax + rdfsbase %rax movq %rax,PCB_FSBASE(%r8) 1: movl %gs,%eax cmpl $KUG32SEL,%eax Modified: stable/11/sys/amd64/amd64/exception.S ============================================================================== --- stable/11/sys/amd64/amd64/exception.S Tue Sep 12 06:27:19 2017 (r323487) +++ stable/11/sys/amd64/amd64/exception.S Tue Sep 12 06:31:53 2017 (r323488) @@ -340,10 +340,10 @@ prot_addrf: jz 2f cmpw $KUF32SEL,TF_FS(%rsp) jne 1f - rdfsbaseq %rax + rdfsbase %rax 1: cmpw $KUG32SEL,TF_GS(%rsp) jne 2f - rdgsbaseq %rdx + rdgsbase %rdx 2: swapgs movq PCPU(CURPCB),%rdi testb $CPUID_STDEXT_FSGSBASE,cpu_stdext_feature(%rip) @@ -533,7 +533,7 @@ nmi_fromuserspace: jz 2f cmpw $KUF32SEL,TF_FS(%rsp) jne 1f - rdfsbaseq %rax + rdfsbase %rax movq %rax,PCB_FSBASE(%rdi) 1: cmpw $KUG32SEL,TF_GS(%rsp) jne 2f From owner-svn-src-stable-11@freebsd.org Tue Sep 12 06:34:04 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7D205E1C377; Tue, 12 Sep 2017 06:34:04 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id 572F3643DD; Tue, 12 Sep 2017 06:34:04 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8C6Y38i065190; Tue, 12 Sep 2017 06:34:03 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8C6Y3Ug065185; Tue, 12 Sep 2017 06:34:03 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709120634.v8C6Y3Ug065185@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Tue, 12 Sep 2017 06:34:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323489 - stable/11/contrib/binutils/opcodes X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: stable/11/contrib/binutils/opcodes X-SVN-Commit-Revision: 323489 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 06:34:04 -0000 Author: rlibby Date: Tue Sep 12 06:34:02 2017 New Revision: 323489 URL: https://svnweb.freebsd.org/changeset/base/323489 Log: MFC r323192: gnu binutils: FSGSBASE assembly/disassembly Modified: stable/11/contrib/binutils/opcodes/i386-dis.c stable/11/contrib/binutils/opcodes/i386-opc.h stable/11/contrib/binutils/opcodes/i386-opc.tbl stable/11/contrib/binutils/opcodes/i386-tbl.h Directory Properties: stable/11/ (props changed) Modified: stable/11/contrib/binutils/opcodes/i386-dis.c ============================================================================== --- stable/11/contrib/binutils/opcodes/i386-dis.c Tue Sep 12 06:31:53 2017 (r323488) +++ stable/11/contrib/binutils/opcodes/i386-dis.c Tue Sep 12 06:34:02 2017 (r323489) @@ -1302,7 +1302,7 @@ static const unsigned char twobyte_uses_REPZ_prefix[25 /* 70 */ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1, /* 7f */ /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */ /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */ - /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */ + /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, /* af */ /* b0 */ 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0, /* bf */ /* c0 */ 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */ /* d0 */ 0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* df */ @@ -1793,10 +1793,10 @@ static const struct dis386 grps[][8] = { }, /* GRP15 */ { - { "fxsave", { Ev } }, - { "fxrstor", { Ev } }, - { "ldmxcsr", { Ev } }, - { "stmxcsr", { Ev } }, + { "fxsave", { { OP_0fae, v_mode } } }, + { "fxrstor", { { OP_0fae, v_mode } } }, + { "ldmxcsr", { { OP_0fae, v_mode } } }, + { "stmxcsr", { { OP_0fae, v_mode } } }, { "xsave", { Ev } }, { "xrstor", { { OP_0fae, v_mode } } }, { "xsaveopt", { { OP_0fae, v_mode } } }, @@ -5997,19 +5997,34 @@ OP_0fae (int bytemode, int sizeflag) { if (modrm.mod == 3) { - if (modrm.reg == 7) - strcpy (obuf + strlen (obuf) - sizeof ("clflush") + 1, "sfence"); - else if (modrm.reg == 6) - strcpy (obuf + strlen (obuf) - sizeof ("xsaveopt") + 1, "mfence"); - else if (modrm.reg == 5) - strcpy (obuf + strlen (obuf) - sizeof ("xrstor") + 1, "lfence"); - - if (modrm.reg < 5 || modrm.rm != 0) + if (modrm.reg >= 5 && modrm.reg <= 7 && modrm.rm == 0) { - BadOp (); /* bad sfence, mfence, or lfence */ + if (modrm.reg == 7) + strcpy (obuf + strlen (obuf) - sizeof ("clflush") + 1, "sfence"); + else if (modrm.reg == 6) + strcpy (obuf + strlen (obuf) - sizeof ("xsaveopt") + 1, "mfence"); + else if (modrm.reg == 5) + strcpy (obuf + strlen (obuf) - sizeof ("xrstor") + 1, "lfence"); + bytemode = 0; + } + else if (modrm.reg <= 3 && (prefixes & PREFIX_REPZ) != 0) + { + if (modrm.reg == 0) + strcpy (obuf + strlen (obuf) - sizeof ("fxsave") + 1, "rdfsbase"); + else if (modrm.reg == 1) + strcpy (obuf + strlen (obuf) - sizeof ("fxrstor") + 1, "rdgsbase"); + else if (modrm.reg == 2) + strcpy (obuf + strlen (obuf) - sizeof ("ldmxcsr") + 1, "wrfsbase"); + else if (modrm.reg == 3) + strcpy (obuf + strlen (obuf) - sizeof ("stmxcsr") + 1, "wrgsbase"); + used_prefixes |= PREFIX_REPZ; + bytemode = dq_mode; + } + else + { + BadOp (); return; } - bytemode = 0; } OP_E (bytemode, sizeflag); Modified: stable/11/contrib/binutils/opcodes/i386-opc.h ============================================================================== --- stable/11/contrib/binutils/opcodes/i386-opc.h Tue Sep 12 06:31:53 2017 (r323488) +++ stable/11/contrib/binutils/opcodes/i386-opc.h Tue Sep 12 06:34:02 2017 (r323489) @@ -81,6 +81,7 @@ typedef struct template #define CpuPCLMUL 0x10000000 /* Carry-less Multiplication extensions */ #define CpuRdRnd 0x20000000 /* Intel Random Number Generator extensions */ #define CpuSMAP 0x40000000 /* Intel Supervisor Mode Access Prevention */ +#define CpuFSGSBase 0x80000000 /* Read/write fs/gs segment base registers */ /* SSE4.1/4.2 Instructions required */ #define CpuSSE4 (CpuSSE4_1|CpuSSE4_2) @@ -89,7 +90,8 @@ typedef struct template #define CpuUnknownFlags (Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686 \ |CpuP4|CpuSledgehammer|CpuMMX|CpuMMX2|CpuSSE|CpuSSE2|CpuSSE3|CpuVMX \ |Cpu3dnow|Cpu3dnowA|CpuK6|CpuPadLock|CpuSVME|CpuSSSE3|CpuSSE4_1 \ - |CpuSSE4_2|CpuABM|CpuSSE4a|CpuXSAVE|CpuAES|CpuPCLMUL|CpuRdRnd|CpuSMAP) + |CpuSSE4_2|CpuABM|CpuSSE4a|CpuXSAVE|CpuAES|CpuPCLMUL|CpuRdRnd|CpuSMAP \ + |CpuFSGSBase) /* the bits in opcode_modifier are used to generate the final opcode from the base_opcode. These bits also are used to detect alternate forms of Modified: stable/11/contrib/binutils/opcodes/i386-opc.tbl ============================================================================== --- stable/11/contrib/binutils/opcodes/i386-opc.tbl Tue Sep 12 06:31:53 2017 (r323488) +++ stable/11/contrib/binutils/opcodes/i386-opc.tbl Tue Sep 12 06:34:02 2017 (r323489) @@ -1525,3 +1525,13 @@ pclmulhqhqdq, 2, 0x660f3a44, 0x11, CpuPCLMUL, Modrm|Ig // Intel Random Number Generator extensions rdrand, 1, 0x0fc7, 0x6, CpuRdRnd, Modrm|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf, { Reg16|Reg32|Reg64 } rdseed, 1, 0x0fc7, 0x7, CpuRdRnd, Modrm|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_xSuf, { Reg16|Reg32|Reg64 } + +// Intel Supervisor Mode Access Prevention extensions +clac, 0, 0x0f01, 0xca, CpuSMAP, NoSuf|ImmExt, { 0 } +stac, 0, 0x0f01, 0xcb, CpuSMAP, NoSuf|ImmExt, { 0 } + +// Read/write fs/gs segment base registers +rdfsbase, 1, 0xf30fae, 0x0, CpuFSGSBase|Cpu64, Modrm|No_bSuf|No_wSuf|No_sSuf|No_xSuf, { Reg32|Reg64 } +rdgsbase, 1, 0xf30fae, 0x1, CpuFSGSBase|Cpu64, Modrm|No_bSuf|No_wSuf|No_sSuf|No_xSuf, { Reg32|Reg64 } +wrfsbase, 1, 0xf30fae, 0x2, CpuFSGSBase|Cpu64, Modrm|No_bSuf|No_wSuf|No_sSuf|No_xSuf, { Reg32|Reg64 } +wrgsbase, 1, 0xf30fae, 0x3, CpuFSGSBase|Cpu64, Modrm|No_bSuf|No_wSuf|No_sSuf|No_xSuf, { Reg32|Reg64 } Modified: stable/11/contrib/binutils/opcodes/i386-tbl.h ============================================================================== --- stable/11/contrib/binutils/opcodes/i386-tbl.h Tue Sep 12 06:31:53 2017 (r323488) +++ stable/11/contrib/binutils/opcodes/i386-tbl.h Tue Sep 12 06:34:02 2017 (r323489) @@ -4400,6 +4400,20 @@ const template i386_optab[] = NoSuf|ImmExt, { 0, 0, 0 } }, {"stac", 0, 0x0f01, 0xcb, CpuSMAP, NoSuf|ImmExt, { 0, 0, 0 } }, + + /* Read/write fs/gs segment base registers */ + {"rdfsbase", 1, 0xf30fae, 0x0, CpuFSGSBase|Cpu64, + Modrm|No_bSuf|No_wSuf|No_sSuf|No_xSuf, + { Reg32|Reg64 } }, + {"rdgsbase", 1, 0xf30fae, 0x1, CpuFSGSBase|Cpu64, + Modrm|No_bSuf|No_wSuf|No_sSuf|No_xSuf, + { Reg32|Reg64 } }, + {"wrfsbase", 1, 0xf30fae, 0x2, CpuFSGSBase|Cpu64, + Modrm|No_bSuf|No_wSuf|No_sSuf|No_xSuf, + { Reg32|Reg64 } }, + {"wrgsbase", 1, 0xf30fae, 0x3, CpuFSGSBase|Cpu64, + Modrm|No_bSuf|No_wSuf|No_sSuf|No_xSuf, + { Reg32|Reg64 } }, { NULL, 0, 0, 0, 0, 0, { 0 } } }; From owner-svn-src-stable-11@freebsd.org Tue Sep 12 09:45:42 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E7EBAE24F4C; Tue, 12 Sep 2017 09:45:42 +0000 (UTC) (envelope-from rlibby@gmail.com) Received: from mail-pg0-f45.google.com (mail-pg0-f45.google.com [74.125.83.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BBA526AB9B; Tue, 12 Sep 2017 09:45:42 +0000 (UTC) (envelope-from rlibby@gmail.com) Received: by mail-pg0-f45.google.com with SMTP id u18so3783542pgo.0; Tue, 12 Sep 2017 02:45:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=VfIwAVG4oJx2B9tWvUCz380x57VBG8Kdyr2ZDQlvfz0=; b=o8TO52kzrqze1MQHKhat1dyqSRtUCWhmQCvUZFU+mVUJU0JMQpdI6TGS0bNWVCvFTm 4//+84YpTlD5vpNur6IHyseMbZHBePhxw3ka8Vo3I3gvgwD5z0toL5ggIewQ9VKV3Wrq AwrYXxpg5HMLCzOukv58NKZTz30nPTd5023bemu1PDVCP1qAPNuYmIOio8EgvWYQFEGn KMp3RhN6bUV9ct6Yeuvq3h6eh1DS0LxhPTB3Do1BJcuiDDzxD0NHx5xlm1cR/cygITSu LRL37SmUMn2V94VOjEB8Jr2Zt33Lp7epQcXdAx3j45383piEcX2gpRpJKFQt2sM2iyZg dwqQ== X-Gm-Message-State: AHPjjUhTP0dK6ZE/TZKN0SkYwGqgUpb6AkkC7GFZMCix+Q+/sMVj5EeR sysgXQRJQ5hr/ILXLBas9g== X-Received: by 10.84.133.99 with SMTP id 90mr8998178plf.148.1505209536547; Tue, 12 Sep 2017 02:45:36 -0700 (PDT) Received: from mail-pg0-f47.google.com (mail-pg0-f47.google.com. [74.125.83.47]) by smtp.gmail.com with ESMTPSA id r90sm19130695pfb.183.2017.09.12.02.45.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Sep 2017 02:45:36 -0700 (PDT) Received: by mail-pg0-f47.google.com with SMTP id j16so10093481pga.1; Tue, 12 Sep 2017 02:45:35 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5Zj0FyQtVx0M5ZAfO0E5A/7SL9YkFU3vNwmyiNffyzLoUO1sHfWJAkq6EbbPMWjdVSGVsFVXlDnZYqs9JolKE= X-Received: by 10.98.149.207 with SMTP id c76mr14605472pfk.198.1505209535484; Tue, 12 Sep 2017 02:45:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.207.193 with HTTP; Tue, 12 Sep 2017 02:45:35 -0700 (PDT) In-Reply-To: <201709080437.v884bnIh029199@repo.freebsd.org> References: <201709080437.v884bnIh029199@repo.freebsd.org> From: Ryan Libby Date: Tue, 12 Sep 2017 02:45:35 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r323299 - stable/11/lib/msun/tests To: Ngie Cooper Cc: src-committers , svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 09:45:43 -0000 On Thu, Sep 7, 2017 at 9:37 PM, Ngie Cooper wrote: > Author: ngie > Date: Fri Sep 8 04:37:49 2017 > New Revision: 323299 > URL: https://svnweb.freebsd.org/changeset/base/323299 > > Log: > MFC r321455: > > Raise WARNS to 1 > > This will enable warnings with the msun tests. > > Modified: > stable/11/lib/msun/tests/Makefile > Directory Properties: > stable/11/ (props changed) > > Modified: stable/11/lib/msun/tests/Makefile > ============================================================================== > --- stable/11/lib/msun/tests/Makefile Fri Sep 8 04:35:44 2017 (r323298) > +++ stable/11/lib/msun/tests/Makefile Fri Sep 8 04:37:49 2017 (r323299) > @@ -4,8 +4,6 @@ > > TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libm > > -WARNS?= 0 > - > # All architectures on FreeBSD have fenv.h > CFLAGS+= -DHAVE_FENV_H > > @@ -85,6 +83,8 @@ IGNORE_PRAGMA= > SRCS.ilogb2_test= ilogb_test.c > > LIBADD+= m > + > +WARNS?= 1 > > # Copied from lib/msun/Makefile > .if ${MACHINE_CPUARCH} == "i386" This seems to have broken the i386 build [1]. Did you mean to MFC it with r321483? [1] https://ci.freebsd.org/job/FreeBSD-stable-11-i386-build/1521/ From owner-svn-src-stable-11@freebsd.org Tue Sep 12 13:47:55 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B0E93E0A73A; Tue, 12 Sep 2017 13:47:55 +0000 (UTC) (envelope-from markj@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 mx1.freebsd.org (Postfix) with ESMTPS id 7D6AE72775; Tue, 12 Sep 2017 13:47:55 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8CDlsxU041111; Tue, 12 Sep 2017 13:47:54 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8CDlsjb041110; Tue, 12 Sep 2017 13:47:54 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201709121347.v8CDlsjb041110@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Tue, 12 Sep 2017 13:47:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323495 - stable/11/cddl/contrib/opensolaris/lib/libdtrace/common X-SVN-Group: stable-11 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: stable/11/cddl/contrib/opensolaris/lib/libdtrace/common X-SVN-Commit-Revision: 323495 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Sep 2017 13:47:55 -0000 Author: markj Date: Tue Sep 12 13:47:54 2017 New Revision: 323495 URL: https://svnweb.freebsd.org/changeset/base/323495 Log: MFC r323166: Use O_CLOEXEC when opening persistent handles in libdtrace. Modified: stable/11/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c Directory Properties: stable/11/ (props changed) Modified: stable/11/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c ============================================================================== --- stable/11/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c Tue Sep 12 13:45:04 2017 (r323494) +++ stable/11/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c Tue Sep 12 13:47:54 2017 (r323495) @@ -965,7 +965,7 @@ dt_provmod_open(dt_provmod_t **provmod, dt_fdlist_t *d (void) snprintf(path, sizeof (path), "/dev/dtrace/%s", p1); - if ((fd = open(path, O_RDONLY)) == -1) + if ((fd = open(path, O_RDONLY | O_CLOEXEC)) == -1) continue; /* failed to open driver; just skip it */ if (((prov = malloc(sizeof (dt_provmod_t))) == NULL) || @@ -1102,7 +1102,7 @@ dt_vopen(int version, int flags, int *errp, */ dt_provmod_open(&provmod, &df); - dtfd = open("/dev/dtrace/dtrace", O_RDWR); + dtfd = open("/dev/dtrace/dtrace", O_RDWR | O_CLOEXEC); err = errno; /* save errno from opening dtfd */ #if defined(__FreeBSD__) /* @@ -1118,7 +1118,7 @@ dt_vopen(int version, int flags, int *errp, #ifdef illumos ftfd = open("/dev/dtrace/provider/fasttrap", O_RDWR); #else - ftfd = open("/dev/dtrace/fasttrap", O_RDWR); + ftfd = open("/dev/dtrace/fasttrap", O_RDWR | O_CLOEXEC); #endif fterr = ftfd == -1 ? errno : 0; /* save errno from open ftfd */ @@ -1147,9 +1147,6 @@ dt_vopen(int version, int flags, int *errp, } return (set_open_errno(dtp, errp, err)); } - - (void) fcntl(dtfd, F_SETFD, FD_CLOEXEC); - (void) fcntl(ftfd, F_SETFD, FD_CLOEXEC); alloc: if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL) { From owner-svn-src-stable-11@freebsd.org Wed Sep 13 00:51:37 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 600D6E024AE; Wed, 13 Sep 2017 00:51:37 +0000 (UTC) (envelope-from rlibby@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 mx1.freebsd.org (Postfix) with ESMTPS id 29AB66B91B; Wed, 13 Sep 2017 00:51:37 +0000 (UTC) (envelope-from rlibby@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8D0pa9J020155; Wed, 13 Sep 2017 00:51:36 GMT (envelope-from rlibby@FreeBSD.org) Received: (from rlibby@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8D0paSx020154; Wed, 13 Sep 2017 00:51:36 GMT (envelope-from rlibby@FreeBSD.org) Message-Id: <201709130051.v8D0paSx020154@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rlibby set sender to rlibby@FreeBSD.org using -f From: Ryan Libby Date: Wed, 13 Sep 2017 00:51:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323515 - stable/11/lib/msun/tests X-SVN-Group: stable-11 X-SVN-Commit-Author: rlibby X-SVN-Commit-Paths: stable/11/lib/msun/tests X-SVN-Commit-Revision: 323515 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Sep 2017 00:51:37 -0000 Author: rlibby Date: Wed Sep 13 00:51:36 2017 New Revision: 323515 URL: https://svnweb.freebsd.org/changeset/base/323515 Log: MFC r321483 (by ngie): Mask issues with duplicate definitions for __fnstcw, __fldenv, and __fldcw on i386 by ignoring -Wmacro-redefined. This is a bandaid until the code is fixed and will be reverted before MFC. This unbreaks the tinderbox build for i386. Although the head commit log suggests this would not be MFC'd, it nevertheless is being MFC'd as the commit that enabled the warnings that this silences was MFC'd without any proper fix for the warnings (head r321455, stable/11 r323299). Modified: stable/11/lib/msun/tests/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/msun/tests/Makefile ============================================================================== --- stable/11/lib/msun/tests/Makefile Wed Sep 13 00:37:42 2017 (r323514) +++ stable/11/lib/msun/tests/Makefile Wed Sep 13 00:51:36 2017 (r323515) @@ -84,6 +84,10 @@ SRCS.ilogb2_test= ilogb_test.c LIBADD+= m +.if ${MACHINE_CPUARCH} == "i386" +# XXX: __fldcw macro mismatch between fenv.h and ieeefp.h . +CWARNFLAGS.clang+= -Wno-error=macro-redefined +.endif WARNS?= 1 # Copied from lib/msun/Makefile From owner-svn-src-stable-11@freebsd.org Wed Sep 13 02:32:20 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DCB30E066AA; Wed, 13 Sep 2017 02:32:20 +0000 (UTC) (envelope-from rlibby@gmail.com) Received: from mail-pf0-f174.google.com (mail-pf0-f174.google.com [209.85.192.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B364A6E918; Wed, 13 Sep 2017 02:32:20 +0000 (UTC) (envelope-from rlibby@gmail.com) Received: by mail-pf0-f174.google.com with SMTP id q76so7863648pfq.2; Tue, 12 Sep 2017 19:32:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vkygJu6QHKkQ8wTNgFsIpmR2uDMfcVm414nG7njIlPo=; b=XyExWHEP/ZmXaeMjdcP5L+wHwy0JdfSAaNSTtKGTTCNNAhUDC271gDizRdy5/dFr5y 2fWnQK4XgnmFxtsLnn/4hr0z11ley9KNHCfxRrK66IXY7FIm1RNCjE6OG32YlfjGw6NL 3/FpGkQ+pedn+WV+5FIwR/AjtKBndGOGH+kbzavL5/8ceSz/sFAGnMisiASjWfh3IkEm t4uKR6CI8ksPkRX20lx8Auqx6W2nljRkont9un7paBI4RyEnpptCyer1VTXQQ/XXAekK Yb9P8vVF0M0872NjAGOEipgOzv847to1Lt9KPRXFmHLRjKv8BRmLfXMDsxEclVJsKNbf Kv8w== X-Gm-Message-State: AHPjjUhLxyh3oysyTsCfe6vApNF1dBonT+tUVIw7jYrb9LGy9D9aS3/Q gnbAKL/FqzpU3jAMC5iJeQ== X-Received: by 10.84.210.69 with SMTP id z63mr19294377plh.431.1505269933486; Tue, 12 Sep 2017 19:32:13 -0700 (PDT) Received: from mail-pg0-f46.google.com (mail-pg0-f46.google.com. [74.125.83.46]) by smtp.gmail.com with ESMTPSA id h88sm23532204pfa.24.2017.09.12.19.32.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Sep 2017 19:32:13 -0700 (PDT) Received: by mail-pg0-f46.google.com with SMTP id j16so14518094pga.1; Tue, 12 Sep 2017 19:32:13 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7NkD8zpuESEd+7E18J2GMEgp8VFMV2l5iPbnGzHZ+53Z0poq4tlL+mq1I6bKsk800r8KHBTCPXgprG57LzHQ4= X-Received: by 10.99.186.81 with SMTP id l17mr16278724pgu.170.1505269932942; Tue, 12 Sep 2017 19:32:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.207.193 with HTTP; Tue, 12 Sep 2017 19:32:12 -0700 (PDT) In-Reply-To: References: <201709080437.v884bnIh029199@repo.freebsd.org> From: Ryan Libby Date: Tue, 12 Sep 2017 19:32:12 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r323299 - stable/11/lib/msun/tests To: Ngie Cooper Cc: src-committers , svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Sep 2017 02:32:21 -0000 On Tue, Sep 12, 2017 at 2:45 AM, Ryan Libby wrote: > On Thu, Sep 7, 2017 at 9:37 PM, Ngie Cooper wrote: >> Author: ngie >> Date: Fri Sep 8 04:37:49 2017 >> New Revision: 323299 >> URL: https://svnweb.freebsd.org/changeset/base/323299 >> >> Log: >> MFC r321455: >> >> Raise WARNS to 1 >> >> This will enable warnings with the msun tests. >> >> Modified: >> stable/11/lib/msun/tests/Makefile >> Directory Properties: >> stable/11/ (props changed) >> >> Modified: stable/11/lib/msun/tests/Makefile >> ============================================================================== >> --- stable/11/lib/msun/tests/Makefile Fri Sep 8 04:35:44 2017 (r323298) >> +++ stable/11/lib/msun/tests/Makefile Fri Sep 8 04:37:49 2017 (r323299) >> @@ -4,8 +4,6 @@ >> >> TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libm >> >> -WARNS?= 0 >> - >> # All architectures on FreeBSD have fenv.h >> CFLAGS+= -DHAVE_FENV_H >> >> @@ -85,6 +83,8 @@ IGNORE_PRAGMA= >> SRCS.ilogb2_test= ilogb_test.c >> >> LIBADD+= m >> + >> +WARNS?= 1 >> >> # Copied from lib/msun/Makefile >> .if ${MACHINE_CPUARCH} == "i386" > > This seems to have broken the i386 build [1]. Did you mean to MFC it > with r321483? > > [1] https://ci.freebsd.org/job/FreeBSD-stable-11-i386-build/1521/ I MFC'd head r321483 to stable/11 in r323515 in order to unbreak the build for i386. I realize this may not have been the plan, so, Ngie, you may like to follow up on that further. From owner-svn-src-stable-11@freebsd.org Wed Sep 13 05:56:08 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1516EE0E139; Wed, 13 Sep 2017 05:56:08 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7352A741EC; Wed, 13 Sep 2017 05:56:07 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: by mail-pf0-x244.google.com with SMTP id f84so7134715pfj.3; Tue, 12 Sep 2017 22:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=UIBahuhI1v7yEwLdvlrdneQkF20woYUP8YJ7NsGsqKk=; b=VfDosKyXtOjlJ2gk93eJRGQtDeQ2YkQgNzk30AroLOiXBRFaJgNyWjfnITRHwbFqTI juRoZoXQ/bpYI5zSZyFQVocSHg4ifYEd0cDT120VP5rWdOIqAybzeMZV5SlviG5ig03D VO5xNuHkXIhkOFuKVHHqgJ9hb/JK8yEeIhBPopV32joWNl56hrYh8NnQnB9R3mcohnD0 6b86Vif3/ut5faQEWRZfdeQKGclVsklKzyJwyc3S61SXUNekFSfLO2TiEairm6Bth/6I TUthukS3sYKFPqf+PFdzIqOFdTckcVtzJ7x2vj84snr0khBQgRPd3kHl8A4fSHj3/U0t gGKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=UIBahuhI1v7yEwLdvlrdneQkF20woYUP8YJ7NsGsqKk=; b=KciastsIBSppFZbS8ZpH/XPoAB2+lOU2ZZnKjhMtrW9xZZZrxpPuTgMV7H8hi9POwh Qti8Ds2j25S7vzb6PBky9yQgiYpsHpnQCMy+BjKlN7e6KIH3Lt57qs7N3SG340gmW4Mh Z+ZK3gZxJuOvvbniV3YhHM/2Xf+yTIJ88070qFwLlHuNLyRSUWDPW0WyI0qa6OhVYlFv A/plW5nbjzc1qZJ2gcKtnkJMraKDSRx2ATIU5S4inMKFHezNGgR0XgfT9KwS4+4owORb 58xO6yEfybU62PXnn4mhm3C5o1ar6tiSxJuyTGJVpFDNNDFo21X5VIdrOXjbjF71NdYd AqSg== X-Gm-Message-State: AHPjjUj6rM3WoGd5DEfc64YEhEZXnNiuG+Ts5nDX2V4LVbElg981Z3Zr S240KL07hYV75x8HHYKfIg== X-Google-Smtp-Source: ADKCNb4e1Ju5M0pzN8Z7cFT02Ycydad+YqpPeffDQNZi/EA8C23x/I522fzhUshJ5x84gAepHW74nQ== X-Received: by 10.99.105.130 with SMTP id e124mr16917927pgc.420.1505282166753; Tue, 12 Sep 2017 22:56:06 -0700 (PDT) Received: from ?IPv6:2607:fb90:9dce:72a3:4135:819b:49e7:7507? ([2607:fb90:9dce:72a3:4135:819b:49e7:7507]) by smtp.gmail.com with ESMTPSA id b1sm20403258pgn.55.2017.09.12.22.56.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Sep 2017 22:56:05 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (1.0) Subject: Re: svn commit: r323515 - stable/11/lib/msun/tests From: Ngie Cooper X-Mailer: iPhone Mail (14G60) In-Reply-To: <201709130051.v8D0paSx020154@repo.freebsd.org> Date: Tue, 12 Sep 2017 22:56:04 -0700 Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <4BC08295-1228-4EBE-80D5-3FB2BFDDD4E9@gmail.com> References: <201709130051.v8D0paSx020154@repo.freebsd.org> To: Ryan Libby X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Sep 2017 05:56:08 -0000 > On Sep 12, 2017, at 17:51, Ryan Libby wrote: >=20 > Author: rlibby > Date: Wed Sep 13 00:51:36 2017 > New Revision: 323515 > URL: https://svnweb.freebsd.org/changeset/base/323515 >=20 > Log: > MFC r321483 (by ngie): >=20 > Mask issues with duplicate definitions for __fnstcw, __fldenv, and > __fldcw on i386 by ignoring -Wmacro-redefined. >=20 > This is a bandaid until the code is fixed and will be reverted before > MFC. >=20 > This unbreaks the tinderbox build for i386. Although the head commit > log suggests this would not be MFC'd, it nevertheless is being MFC'd as > the commit that enabled the warnings that this silences was MFC'd > without any proper fix for the warnings (head r321455, stable/11 > r323299). Sorry for the breakage and for fixing this mistake. I forgot to MFC this= (I usually set the MFC timers properly, but apparently I didn't this time) := /.. Cheers, -Ngie= From owner-svn-src-stable-11@freebsd.org Wed Sep 13 11:07:13 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6272AE1ABFA; Wed, 13 Sep 2017 11:07:13 +0000 (UTC) (envelope-from kib@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 mx1.freebsd.org (Postfix) with ESMTPS id 2EE0B83491; Wed, 13 Sep 2017 11:07:13 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8DB7CtU072228; Wed, 13 Sep 2017 11:07:12 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8DB7COV072227; Wed, 13 Sep 2017 11:07:12 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709131107.v8DB7COV072227@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 13 Sep 2017 11:07:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323536 - stable/11/sys/x86/pci X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/x86/pci X-SVN-Commit-Revision: 323536 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Sep 2017 11:07:13 -0000 Author: kib Date: Wed Sep 13 11:07:12 2017 New Revision: 323536 URL: https://svnweb.freebsd.org/changeset/base/323536 Log: MFC r323217: Fix typos. Stop claiming that two children are created. MFC r323310: Consistently use tabs for indent. Modified: stable/11/sys/x86/pci/qpi.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/x86/pci/qpi.c ============================================================================== --- stable/11/sys/x86/pci/qpi.c Wed Sep 13 10:59:36 2017 (r323535) +++ stable/11/sys/x86/pci/qpi.c Wed Sep 13 11:07:12 2017 (r323536) @@ -26,9 +26,9 @@ */ /* - * This driver provides a psuedo-bus to enumerate the PCI buses - * present on a sytem using a QPI chipset. It creates a qpi0 bus that - * is a child of nexus0 and then creates two Host-PCI bridges as a + * This driver provides a pseudo-bus to enumerate the PCI buses + * present on a system using a QPI chipset. It creates a qpi0 bus that + * is a child of nexus0 and then creates Host-PCI bridges as a * child of that. */ @@ -64,15 +64,15 @@ static void qpi_identify(driver_t *driver, device_t parent) { - /* Check CPUID to ensure this is an i7 CPU of some sort. */ - if (!(cpu_vendor_id == CPU_VENDOR_INTEL && + /* Check CPUID to ensure this is an i7 CPU of some sort. */ + if (!(cpu_vendor_id == CPU_VENDOR_INTEL && CPUID_TO_FAMILY(cpu_id) == 0x6 && (CPUID_TO_MODEL(cpu_id) == 0x1a || CPUID_TO_MODEL(cpu_id) == 0x2c))) - return; + return; - /* PCI config register access is required. */ - if (pci_cfgregopen() == 0) - return; + /* PCI config register access is required. */ + if (pci_cfgregopen() == 0) + return; /* Add a qpi bus device. */ if (BUS_ADD_CHILD(parent, 20, "qpi", -1) == NULL) @@ -219,7 +219,7 @@ qpi_pcib_attach(device_t dev) { device_add_child(dev, "pci", -1); - return (bus_generic_attach(dev)); + return (bus_generic_attach(dev)); } static int From owner-svn-src-stable-11@freebsd.org Wed Sep 13 11:19:05 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A9DEAE1B47B; Wed, 13 Sep 2017 11:19:05 +0000 (UTC) (envelope-from kib@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 mx1.freebsd.org (Postfix) with ESMTPS id 6C96A839D9; Wed, 13 Sep 2017 11:19:05 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8DBJ45L076508; Wed, 13 Sep 2017 11:19:04 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8DBJ4HW076504; Wed, 13 Sep 2017 11:19:04 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709131119.v8DBJ4HW076504@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 13 Sep 2017 11:19:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323537 - stable/11/sys/vm X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/vm X-SVN-Commit-Revision: 323537 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Sep 2017 11:19:05 -0000 Author: kib Date: Wed Sep 13 11:19:04 2017 New Revision: 323537 URL: https://svnweb.freebsd.org/changeset/base/323537 Log: MFC r322913: Replace global swhash in swap pager with per-object trie to track swap blocks assigned to the object pages. MFC r322970 (by alc): Do not call vm_pager_page_unswapped() on the fast fault path. MFC r322971 (by alc): Update a couple vm_object lock assertions in the swap pager. MFC r323224: In swp_pager_meta_build(), handle a race with other thread allocating swapblk for our index while we dropped the object lock. MFC r323226: Do not leak empty swblk. Modified: stable/11/sys/vm/swap_pager.c stable/11/sys/vm/vm_fault.c stable/11/sys/vm/vm_object.c stable/11/sys/vm/vm_object.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/vm/swap_pager.c ============================================================================== --- stable/11/sys/vm/swap_pager.c Wed Sep 13 11:07:12 2017 (r323536) +++ stable/11/sys/vm/swap_pager.c Wed Sep 13 11:19:04 2017 (r323537) @@ -86,6 +86,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -126,22 +127,17 @@ __FBSDID("$FreeBSD$"); #define SWB_NPAGES MAX_PAGEOUT_CLUSTER #endif +#define SWAP_META_PAGES PCTRIE_COUNT + /* - * The swblock structure maps an object and a small, fixed-size range - * of page indices to disk addresses within a swap area. - * The collection of these mappings is implemented as a hash table. - * Unused disk addresses within a swap area are allocated and managed - * using a blist. + * A swblk structure maps each page index within a + * SWAP_META_PAGES-aligned and sized range to the address of an + * on-disk swap block (or SWAPBLK_NONE). The collection of these + * mappings for an entire vm object is implemented as a pc-trie. */ -#define SWAP_META_PAGES 32 -#define SWAP_META_MASK (SWAP_META_PAGES - 1) - -struct swblock { - struct swblock *swb_hnext; - vm_object_t swb_object; - vm_pindex_t swb_index; - int swb_count; - daddr_t swb_pages[SWAP_META_PAGES]; +struct swblk { + vm_pindex_t p; + daddr_t d[SWAP_META_PAGES]; }; static MALLOC_DEFINE(M_VMPGDATA, "vm_pgdata", "swap pager private data"); @@ -327,10 +323,6 @@ SYSCTL_PROC(_vm, OID_AUTO, swap_async_max, CTLTYPE_INT CTLFLAG_MPSAFE, NULL, 0, sysctl_swap_async_max, "I", "Maximum running async swap ops"); -static struct swblock **swhash; -static int swhash_mask; -static struct mtx swhash_mtx; - static struct sx sw_alloc_sx; /* @@ -344,7 +336,8 @@ static struct sx sw_alloc_sx; (&swap_pager_object_list[((int)(intptr_t)handle >> 4) & (NOBJLISTS-1)]) static struct pagerlst swap_pager_object_list[NOBJLISTS]; -static uma_zone_t swap_zone; +static uma_zone_t swblk_zone; +static uma_zone_t swpctrie_zone; /* * pagerops for OBJT_SWAP - "swap pager". Some ops are also global procedure @@ -402,12 +395,28 @@ static daddr_t swp_pager_getswapspace(int npages); /* * Metadata functions */ -static struct swblock **swp_pager_hash(vm_object_t object, vm_pindex_t index); static void swp_pager_meta_build(vm_object_t, vm_pindex_t, daddr_t); static void swp_pager_meta_free(vm_object_t, vm_pindex_t, vm_pindex_t); static void swp_pager_meta_free_all(vm_object_t); static daddr_t swp_pager_meta_ctl(vm_object_t, vm_pindex_t, int); +static void * +swblk_trie_alloc(struct pctrie *ptree) +{ + + return (uma_zalloc(swpctrie_zone, M_NOWAIT | (curproc == pageproc ? + M_USE_RESERVE : 0))); +} + +static void +swblk_trie_free(struct pctrie *ptree, void *node) +{ + + uma_zfree(swpctrie_zone, node); +} + +PCTRIE_DEFINE(SWAP, swblk, p, swblk_trie_alloc, swblk_trie_free); + /* * SWP_SIZECHECK() - update swap_pager_full indication * @@ -436,33 +445,6 @@ swp_sizecheck(void) } /* - * SWP_PAGER_HASH() - hash swap meta data - * - * This is an helper function which hashes the swapblk given - * the object and page index. It returns a pointer to a pointer - * to the object, or a pointer to a NULL pointer if it could not - * find a swapblk. - */ -static struct swblock ** -swp_pager_hash(vm_object_t object, vm_pindex_t index) -{ - struct swblock **pswap; - struct swblock *swap; - - index &= ~(vm_pindex_t)SWAP_META_MASK; - pswap = &swhash[(index ^ (int)(intptr_t)object) & swhash_mask]; - while ((swap = *pswap) != NULL) { - if (swap->swb_object == object && - swap->swb_index == index - ) { - break; - } - pswap = &swap->swb_hnext; - } - return (pswap); -} - -/* * SWAP_PAGER_INIT() - initialize the swap pager! * * Expected to be started from system init. NOTE: This code is run @@ -527,21 +509,25 @@ swap_pager_swap_init(void) mtx_unlock(&pbuf_mtx); /* - * Initialize our zone. Right now I'm just guessing on the number - * we need based on the number of pages in the system. Each swblock - * can hold 32 pages, so this is probably overkill. This reservation - * is typically limited to around 32MB by default. + * Initialize our zone, guessing on the number we need based + * on the number of pages in the system. */ n = vm_cnt.v_page_count / 2; - if (maxswzone && n > maxswzone / sizeof(struct swblock)) - n = maxswzone / sizeof(struct swblock); + if (maxswzone && n > maxswzone / sizeof(struct swblk)) + n = maxswzone / sizeof(struct swblk); + swpctrie_zone = uma_zcreate("swpctrie", pctrie_node_size(), NULL, NULL, + pctrie_zone_init, NULL, UMA_ALIGN_PTR, + UMA_ZONE_NOFREE | UMA_ZONE_VM); + if (swpctrie_zone == NULL) + panic("failed to create swap pctrie zone."); + swblk_zone = uma_zcreate("swblk", sizeof(struct swblk), NULL, NULL, + NULL, NULL, _Alignof(struct swblk) - 1, + UMA_ZONE_NOFREE | UMA_ZONE_VM); + if (swblk_zone == NULL) + panic("failed to create swap blk zone."); n2 = n; - swap_zone = uma_zcreate("SWAPMETA", sizeof(struct swblock), NULL, NULL, - NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE | UMA_ZONE_VM); - if (swap_zone == NULL) - panic("failed to create swap_zone."); do { - if (uma_zone_reserve_kva(swap_zone, n)) + if (uma_zone_reserve_kva(swblk_zone, n)) break; /* * if the allocation failed, try a zone two thirds the @@ -550,24 +536,13 @@ swap_pager_swap_init(void) n -= ((n + 2) / 3); } while (n > 0); if (n2 != n) - printf("Swap zone entries reduced from %lu to %lu.\n", n2, n); + printf("Swap blk zone entries reduced from %lu to %lu.\n", + n2, n); swap_maxpages = n * SWAP_META_PAGES; - swzone = n * sizeof(struct swblock); - n2 = n; - - /* - * Initialize our meta-data hash table. The swapper does not need to - * be quite as efficient as the VM system, so we do not use an - * oversized hash table. - * - * n: size of hash table, must be power of 2 - * swhash_mask: hash table index mask - */ - for (n = 1; n < n2 / 8; n *= 2) - ; - swhash = malloc(sizeof(struct swblock *) * n, M_VMPGDATA, M_WAITOK | M_ZERO); - swhash_mask = n - 1; - mtx_init(&swhash_mtx, "swap_pager swhash", NULL, MTX_DEF); + swzone = n * sizeof(struct swblk); + if (!uma_zone_reserve_kva(swpctrie_zone, n)) + printf("Cannot reserve swap pctrie zone, " + "reduce kern.maxswzone.\n"); } static vm_object_t @@ -581,14 +556,20 @@ swap_pager_alloc_init(void *handle, struct ucred *cred return (NULL); crhold(cred); } + + /* + * The un_pager.swp.swp_blks trie is initialized by + * vm_object_allocate() to ensure the correct order of + * visibility to other threads. + */ object = vm_object_allocate(OBJT_SWAP, OFF_TO_IDX(offset + PAGE_MASK + size)); + object->handle = handle; if (cred != NULL) { object->cred = cred; object->charge = size; } - object->un_pager.swp.swp_bcount = 0; return (object); } @@ -1643,50 +1624,56 @@ swp_pager_force_pagein(vm_object_t object, vm_pindex_t static void swap_pager_swapoff(struct swdevt *sp) { - struct swblock *swap; - vm_object_t locked_obj, object; - vm_pindex_t pindex; - int i, j, retries; + struct swblk *sb; + vm_object_t object; + vm_pindex_t pi; + int i, retries; sx_assert(&swdev_syscall_lock, SA_XLOCKED); retries = 0; - locked_obj = NULL; full_rescan: - mtx_lock(&swhash_mtx); - for (i = 0; i <= swhash_mask; i++) { /* '<=' is correct here */ -restart: - for (swap = swhash[i]; swap != NULL; swap = swap->swb_hnext) { - object = swap->swb_object; - pindex = swap->swb_index; - for (j = 0; j < SWAP_META_PAGES; ++j) { - if (!swp_pager_isondev(swap->swb_pages[j], sp)) + mtx_lock(&vm_object_list_mtx); + TAILQ_FOREACH(object, &vm_object_list, object_list) { + if (object->type != OBJT_SWAP) + continue; + mtx_unlock(&vm_object_list_mtx); + /* Depends on type-stability. */ + VM_OBJECT_WLOCK(object); + + /* + * Dead objects are eventually terminated on their own. + */ + if ((object->flags & OBJ_DEAD) != 0) + goto next_obj; + + /* + * Sync with fences placed after pctrie + * initialization. We must not access pctrie below + * unless we checked that our object is swap and not + * dead. + */ + atomic_thread_fence_acq(); + if (object->type != OBJT_SWAP) + goto next_obj; + + for (pi = 0; (sb = SWAP_PCTRIE_LOOKUP_GE( + &object->un_pager.swp.swp_blks, pi)) != NULL; ) { + pi = sb->p + SWAP_META_PAGES; + for (i = 0; i < SWAP_META_PAGES; i++) { + if (sb->d[i] == SWAPBLK_NONE) continue; - if (locked_obj != object) { - if (locked_obj != NULL) - VM_OBJECT_WUNLOCK(locked_obj); - locked_obj = object; - if (!VM_OBJECT_TRYWLOCK(object)) { - mtx_unlock(&swhash_mtx); - /* Depends on type-stability. */ - VM_OBJECT_WLOCK(object); - mtx_lock(&swhash_mtx); - goto restart; - } - } - MPASS(locked_obj == object); - mtx_unlock(&swhash_mtx); - swp_pager_force_pagein(object, pindex + j); - mtx_lock(&swhash_mtx); - goto restart; + if (swp_pager_isondev(sb->d[i], sp)) + swp_pager_force_pagein(object, + sb->p + i); } } +next_obj: + VM_OBJECT_WUNLOCK(object); + mtx_lock(&vm_object_list_mtx); } - mtx_unlock(&swhash_mtx); - if (locked_obj != NULL) { - VM_OBJECT_WUNLOCK(locked_obj); - locked_obj = NULL; - } + mtx_unlock(&vm_object_list_mtx); + if (sp->sw_used) { /* * Objects may be locked or paging to the device being @@ -1729,85 +1716,120 @@ restart: static void swp_pager_meta_build(vm_object_t object, vm_pindex_t pindex, daddr_t swapblk) { - static volatile int exhausted; - struct swblock *swap; - struct swblock **pswap; - int idx; + static volatile int swblk_zone_exhausted, swpctrie_zone_exhausted; + struct swblk *sb, *sb1; + vm_pindex_t modpi, rdpi; + int error, i; VM_OBJECT_ASSERT_WLOCKED(object); + /* * Convert default object to swap object if necessary */ if (object->type != OBJT_SWAP) { + pctrie_init(&object->un_pager.swp.swp_blks); + + /* + * Ensure that swap_pager_swapoff()'s iteration over + * object_list does not see a garbage pctrie. + */ + atomic_thread_fence_rel(); + object->type = OBJT_SWAP; - object->un_pager.swp.swp_bcount = 0; KASSERT(object->handle == NULL, ("default pager with handle")); } - /* - * Locate hash entry. If not found create, but if we aren't adding - * anything just return. If we run out of space in the map we wait - * and, since the hash table may have changed, retry. - */ -retry: - mtx_lock(&swhash_mtx); - pswap = swp_pager_hash(object, pindex); - - if ((swap = *pswap) == NULL) { - int i; - + rdpi = rounddown(pindex, SWAP_META_PAGES); + sb = SWAP_PCTRIE_LOOKUP(&object->un_pager.swp.swp_blks, rdpi); + if (sb == NULL) { if (swapblk == SWAPBLK_NONE) - goto done; - - swap = *pswap = uma_zalloc(swap_zone, M_NOWAIT | - (curproc == pageproc ? M_USE_RESERVE : 0)); - if (swap == NULL) { - mtx_unlock(&swhash_mtx); + return; + for (;;) { + sb = uma_zalloc(swblk_zone, M_NOWAIT | (curproc == + pageproc ? M_USE_RESERVE : 0)); + if (sb != NULL) { + sb->p = rdpi; + for (i = 0; i < SWAP_META_PAGES; i++) + sb->d[i] = SWAPBLK_NONE; + if (atomic_cmpset_int(&swblk_zone_exhausted, + 1, 0)) + printf("swblk zone ok\n"); + break; + } VM_OBJECT_WUNLOCK(object); - if (uma_zone_exhausted(swap_zone)) { - if (atomic_cmpset_int(&exhausted, 0, 1)) - printf("swap zone exhausted, " + if (uma_zone_exhausted(swblk_zone)) { + if (atomic_cmpset_int(&swblk_zone_exhausted, + 0, 1)) + printf("swap blk zone exhausted, " "increase kern.maxswzone\n"); vm_pageout_oom(VM_OOM_SWAPZ); - pause("swzonex", 10); + pause("swzonxb", 10); } else VM_WAIT; VM_OBJECT_WLOCK(object); - goto retry; + sb = SWAP_PCTRIE_LOOKUP(&object->un_pager.swp.swp_blks, + rdpi); + if (sb != NULL) + /* + * Somebody swapped out a nearby page, + * allocating swblk at the rdpi index, + * while we dropped the object lock. + */ + goto allocated; } - - if (atomic_cmpset_int(&exhausted, 1, 0)) - printf("swap zone ok\n"); - - swap->swb_hnext = NULL; - swap->swb_object = object; - swap->swb_index = pindex & ~(vm_pindex_t)SWAP_META_MASK; - swap->swb_count = 0; - - ++object->un_pager.swp.swp_bcount; - - for (i = 0; i < SWAP_META_PAGES; ++i) - swap->swb_pages[i] = SWAPBLK_NONE; + for (;;) { + error = SWAP_PCTRIE_INSERT( + &object->un_pager.swp.swp_blks, sb); + if (error == 0) { + if (atomic_cmpset_int(&swpctrie_zone_exhausted, + 1, 0)) + printf("swpctrie zone ok\n"); + break; + } + VM_OBJECT_WUNLOCK(object); + if (uma_zone_exhausted(swpctrie_zone)) { + if (atomic_cmpset_int(&swpctrie_zone_exhausted, + 0, 1)) + printf("swap pctrie zone exhausted, " + "increase kern.maxswzone\n"); + vm_pageout_oom(VM_OOM_SWAPZ); + pause("swzonxp", 10); + } else + VM_WAIT; + VM_OBJECT_WLOCK(object); + sb1 = SWAP_PCTRIE_LOOKUP(&object->un_pager.swp.swp_blks, + rdpi); + if (sb1 != NULL) { + uma_zfree(swblk_zone, sb); + sb = sb1; + goto allocated; + } + } } +allocated: + MPASS(sb->p == rdpi); - /* - * Delete prior contents of metadata - */ - idx = pindex & SWAP_META_MASK; + modpi = pindex % SWAP_META_PAGES; + /* Delete prior contents of metadata. */ + if (sb->d[modpi] != SWAPBLK_NONE) + swp_pager_freeswapspace(sb->d[modpi], 1); + /* Enter block into metadata. */ + sb->d[modpi] = swapblk; - if (swap->swb_pages[idx] != SWAPBLK_NONE) { - swp_pager_freeswapspace(swap->swb_pages[idx], 1); - --swap->swb_count; - } - /* - * Enter block into metadata + * Free the swblk if we end up with the empty page run. */ - swap->swb_pages[idx] = swapblk; - if (swapblk != SWAPBLK_NONE) - ++swap->swb_count; -done: - mtx_unlock(&swhash_mtx); + if (swapblk == SWAPBLK_NONE) { + for (i = 0; i < SWAP_META_PAGES; i++) { + if (sb->d[i] != SWAPBLK_NONE) + break; + } + if (i == SWAP_META_PAGES) { + SWAP_PCTRIE_REMOVE(&object->un_pager.swp.swp_blks, + rdpi); + uma_zfree(swblk_zone, sb); + } + } } /* @@ -1821,42 +1843,40 @@ done: * with resident pages. */ static void -swp_pager_meta_free(vm_object_t object, vm_pindex_t index, vm_pindex_t count) +swp_pager_meta_free(vm_object_t object, vm_pindex_t pindex, vm_pindex_t count) { - struct swblock **pswap, *swap; - vm_pindex_t c; - daddr_t v; - int n, sidx; + struct swblk *sb; + vm_pindex_t last; + int i; + bool empty; - VM_OBJECT_ASSERT_LOCKED(object); + VM_OBJECT_ASSERT_WLOCKED(object); if (object->type != OBJT_SWAP || count == 0) return; - mtx_lock(&swhash_mtx); - for (c = 0; c < count;) { - pswap = swp_pager_hash(object, index); - sidx = index & SWAP_META_MASK; - n = SWAP_META_PAGES - sidx; - index += n; - if ((swap = *pswap) == NULL) { - c += n; - continue; - } - for (; c < count && sidx < SWAP_META_PAGES; ++c, ++sidx) { - if ((v = swap->swb_pages[sidx]) == SWAPBLK_NONE) + last = pindex + count - 1; + for (;;) { + sb = SWAP_PCTRIE_LOOKUP_GE(&object->un_pager.swp.swp_blks, + rounddown(pindex, SWAP_META_PAGES)); + if (sb == NULL || sb->p > last) + break; + empty = true; + for (i = 0; i < SWAP_META_PAGES; i++) { + if (sb->d[i] == SWAPBLK_NONE) continue; - swp_pager_freeswapspace(v, 1); - swap->swb_pages[sidx] = SWAPBLK_NONE; - if (--swap->swb_count == 0) { - *pswap = swap->swb_hnext; - uma_zfree(swap_zone, swap); - --object->un_pager.swp.swp_bcount; - c += SWAP_META_PAGES - sidx; - break; - } + if (pindex <= sb->p + i && sb->p + i <= last) { + swp_pager_freeswapspace(sb->d[i], 1); + sb->d[i] = SWAPBLK_NONE; + } else + empty = false; } + pindex = sb->p + SWAP_META_PAGES; + if (empty) { + SWAP_PCTRIE_REMOVE(&object->un_pager.swp.swp_blks, + sb->p); + uma_zfree(swblk_zone, sb); + } } - mtx_unlock(&swhash_mtx); } /* @@ -1868,36 +1888,23 @@ swp_pager_meta_free(vm_object_t object, vm_pindex_t in static void swp_pager_meta_free_all(vm_object_t object) { - struct swblock **pswap, *swap; - vm_pindex_t index; - daddr_t v; + struct swblk *sb; + vm_pindex_t pindex; int i; VM_OBJECT_ASSERT_WLOCKED(object); if (object->type != OBJT_SWAP) return; - index = 0; - while (object->un_pager.swp.swp_bcount != 0) { - mtx_lock(&swhash_mtx); - pswap = swp_pager_hash(object, index); - if ((swap = *pswap) != NULL) { - for (i = 0; i < SWAP_META_PAGES; ++i) { - v = swap->swb_pages[i]; - if (v != SWAPBLK_NONE) { - --swap->swb_count; - swp_pager_freeswapspace(v, 1); - } - } - if (swap->swb_count != 0) - panic( - "swap_pager_meta_free_all: swb_count != 0"); - *pswap = swap->swb_hnext; - uma_zfree(swap_zone, swap); - --object->un_pager.swp.swp_bcount; + for (pindex = 0; (sb = SWAP_PCTRIE_LOOKUP_GE( + &object->un_pager.swp.swp_blks, pindex)) != NULL;) { + pindex = sb->p + SWAP_META_PAGES; + for (i = 0; i < SWAP_META_PAGES; i++) { + if (sb->d[i] != SWAPBLK_NONE) + swp_pager_freeswapspace(sb->d[i], 1); } - mtx_unlock(&swhash_mtx); - index += SWAP_META_PAGES; + SWAP_PCTRIE_REMOVE(&object->un_pager.swp.swp_blks, sb->p); + uma_zfree(swblk_zone, sb); } } @@ -1911,9 +1918,6 @@ swp_pager_meta_free_all(vm_object_t object) * was invalid. This routine will automatically free any invalid * meta-data swapblks. * - * It is not possible to store invalid swapblks in the swap meta data - * (other then a literal 'SWAPBLK_NONE'), so we don't bother checking. - * * When acting on a busy resident page and paging is in progress, we * have to wait until paging is complete but otherwise can act on the * busy page. @@ -1924,43 +1928,45 @@ swp_pager_meta_free_all(vm_object_t object) static daddr_t swp_pager_meta_ctl(vm_object_t object, vm_pindex_t pindex, int flags) { - struct swblock **pswap; - struct swblock *swap; + struct swblk *sb; daddr_t r1; - int idx; + int i; - VM_OBJECT_ASSERT_LOCKED(object); + if ((flags & (SWM_FREE | SWM_POP)) != 0) + VM_OBJECT_ASSERT_WLOCKED(object); + else + VM_OBJECT_ASSERT_LOCKED(object); + /* - * The meta data only exists of the object is OBJT_SWAP + * The meta data only exists if the object is OBJT_SWAP * and even then might not be allocated yet. */ if (object->type != OBJT_SWAP) return (SWAPBLK_NONE); - r1 = SWAPBLK_NONE; - mtx_lock(&swhash_mtx); - pswap = swp_pager_hash(object, pindex); - - if ((swap = *pswap) != NULL) { - idx = pindex & SWAP_META_MASK; - r1 = swap->swb_pages[idx]; - - if (r1 != SWAPBLK_NONE) { - if (flags & SWM_FREE) { - swp_pager_freeswapspace(r1, 1); - r1 = SWAPBLK_NONE; - } - if (flags & (SWM_FREE|SWM_POP)) { - swap->swb_pages[idx] = SWAPBLK_NONE; - if (--swap->swb_count == 0) { - *pswap = swap->swb_hnext; - uma_zfree(swap_zone, swap); - --object->un_pager.swp.swp_bcount; - } - } + sb = SWAP_PCTRIE_LOOKUP(&object->un_pager.swp.swp_blks, + rounddown(pindex, SWAP_META_PAGES)); + if (sb == NULL) + return (SWAPBLK_NONE); + r1 = sb->d[pindex % SWAP_META_PAGES]; + if (r1 == SWAPBLK_NONE) + return (SWAPBLK_NONE); + if ((flags & (SWM_FREE | SWM_POP)) != 0) { + sb->d[pindex % SWAP_META_PAGES] = SWAPBLK_NONE; + for (i = 0; i < SWAP_META_PAGES; i++) { + if (sb->d[i] != SWAPBLK_NONE) + break; } + if (i == SWAP_META_PAGES) { + SWAP_PCTRIE_REMOVE(&object->un_pager.swp.swp_blks, + rounddown(pindex, SWAP_META_PAGES)); + uma_zfree(swblk_zone, sb); + } } - mtx_unlock(&swhash_mtx); + if ((flags & SWM_FREE) != 0) { + swp_pager_freeswapspace(r1, 1); + r1 = SWAPBLK_NONE; + } return (r1); } @@ -1974,32 +1980,38 @@ swp_pager_meta_ctl(vm_object_t object, vm_pindex_t pin vm_pindex_t swap_pager_find_least(vm_object_t object, vm_pindex_t pindex) { - struct swblock **pswap, *swap; - vm_pindex_t i, j, lim; - int idx; + struct swblk *sb; + int i; VM_OBJECT_ASSERT_LOCKED(object); - if (object->type != OBJT_SWAP || object->un_pager.swp.swp_bcount == 0) + if (object->type != OBJT_SWAP) return (object->size); - mtx_lock(&swhash_mtx); - for (j = pindex; j < object->size; j = lim) { - pswap = swp_pager_hash(object, j); - lim = rounddown2(j + SWAP_META_PAGES, SWAP_META_PAGES); - if (lim > object->size) - lim = object->size; - if ((swap = *pswap) != NULL) { - for (idx = j & SWAP_META_MASK, i = j; i < lim; - i++, idx++) { - if (swap->swb_pages[idx] != SWAPBLK_NONE) - goto found; - } + sb = SWAP_PCTRIE_LOOKUP_GE(&object->un_pager.swp.swp_blks, + rounddown(pindex, SWAP_META_PAGES)); + if (sb == NULL) + return (object->size); + if (sb->p < pindex) { + for (i = pindex % SWAP_META_PAGES; i < SWAP_META_PAGES; i++) { + if (sb->d[i] != SWAPBLK_NONE) + return (sb->p + i); } + sb = SWAP_PCTRIE_LOOKUP_GE(&object->un_pager.swp.swp_blks, + roundup(pindex, SWAP_META_PAGES)); + if (sb == NULL) + return (object->size); } - i = object->size; -found: - mtx_unlock(&swhash_mtx); - return (i); + for (i = 0; i < SWAP_META_PAGES; i++) { + if (sb->d[i] != SWAPBLK_NONE) + return (sb->p + i); + } + + /* + * We get here if a swblk is present in the trie but it + * doesn't map any blocks. + */ + MPASS(0); + return (object->size); } /* @@ -2035,7 +2047,7 @@ sys_swapon(struct thread *td, struct swapon_args *uap) * Swap metadata may not fit in the KVM if we have physical * memory of >1GB. */ - if (swap_zone == NULL) { + if (swblk_zone == NULL) { error = ENOMEM; goto done; } @@ -2080,7 +2092,7 @@ swapon_check_swzone(void) npages = swap_total / PAGE_SIZE; /* absolute maximum we can handle assuming 100% efficiency */ - maxpages = uma_zone_get_max(swap_zone) * SWAP_META_PAGES; + maxpages = uma_zone_get_max(swblk_zone) * SWAP_META_PAGES; /* recommend using no more than half that amount */ if (npages > maxpages / 2) { @@ -2378,15 +2390,9 @@ SYSCTL_NODE(_vm, OID_AUTO, swap_info, CTLFLAG_RD | CTL "Swap statistics by device"); /* - * vmspace_swap_count() - count the approximate swap usage in pages for a - * vmspace. - * - * The map must be locked. - * - * Swap usage is determined by taking the proportional swap used by - * VM objects backing the VM map. To make up for fractional losses, - * if the VM object has any swap use at all the associated map entries - * count for at least 1 swap page. + * Count the approximate swap usage in pages for a vmspace. The + * shadowed or not yet copied on write swap blocks are not accounted. + * The map must be locked. */ long vmspace_swap_count(struct vmspace *vmspace) @@ -2394,23 +2400,38 @@ vmspace_swap_count(struct vmspace *vmspace) vm_map_t map; vm_map_entry_t cur; vm_object_t object; - long count, n; + struct swblk *sb; + vm_pindex_t e, pi; + long count; + int i; map = &vmspace->vm_map; count = 0; for (cur = map->header.next; cur != &map->header; cur = cur->next) { - if ((cur->eflags & MAP_ENTRY_IS_SUB_MAP) == 0 && - (object = cur->object.vm_object) != NULL) { - VM_OBJECT_WLOCK(object); - if (object->type == OBJT_SWAP && - object->un_pager.swp.swp_bcount != 0) { - n = (cur->end - cur->start) / PAGE_SIZE; - count += object->un_pager.swp.swp_bcount * - SWAP_META_PAGES * n / object->size + 1; + if ((cur->eflags & MAP_ENTRY_IS_SUB_MAP) != 0) + continue; + object = cur->object.vm_object; + if (object == NULL || object->type != OBJT_SWAP) + continue; + VM_OBJECT_RLOCK(object); + if (object->type != OBJT_SWAP) + goto unlock; + pi = OFF_TO_IDX(cur->offset); + e = pi + OFF_TO_IDX(cur->end - cur->start); + for (;; pi = sb->p + SWAP_META_PAGES) { + sb = SWAP_PCTRIE_LOOKUP_GE( + &object->un_pager.swp.swp_blks, pi); + if (sb == NULL || sb->p >= e) + break; + for (i = 0; i < SWAP_META_PAGES; i++) { + if (sb->p + i < e && + sb->d[i] != SWAPBLK_NONE) + count++; } - VM_OBJECT_WUNLOCK(object); } +unlock: + VM_OBJECT_RUNLOCK(object); } return (count); } Modified: stable/11/sys/vm/vm_fault.c ============================================================================== --- stable/11/sys/vm/vm_fault.c Wed Sep 13 11:07:12 2017 (r323536) +++ stable/11/sys/vm/vm_fault.c Wed Sep 13 11:19:04 2017 (r323537) @@ -236,14 +236,15 @@ vm_fault_dirty(vm_map_entry_t entry, vm_page_t m, vm_p * written NOW so dirty it explicitly to save on * pmap_is_modified() calls later. * - * Also tell the backing pager, if any, that it should remove - * any swap backing since the page is now dirty. + * Also, since the page is now dirty, we can possibly tell + * the pager to release any swap backing the page. Calling + * the pager requires a write lock on the object. */ if (need_dirty) vm_page_dirty(m); if (!set_wd) vm_page_unlock(m); - if (need_dirty) + else if (need_dirty) vm_pager_page_unswapped(m); } Modified: stable/11/sys/vm/vm_object.c ============================================================================== --- stable/11/sys/vm/vm_object.c Wed Sep 13 11:07:12 2017 (r323536) +++ stable/11/sys/vm/vm_object.c Wed Sep 13 11:19:04 2017 (r323537) @@ -73,6 +73,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include /* for curproc, pageproc */ @@ -208,6 +209,7 @@ vm_object_zinit(void *mem, int size, int flags) object->paging_in_progress = 0; object->resident_page_count = 0; object->shadow_count = 0; + object->flags = OBJ_DEAD; mtx_lock(&vm_object_list_mtx); TAILQ_INSERT_TAIL(&vm_object_list, object, object_list); @@ -223,6 +225,16 @@ _vm_object_allocate(objtype_t type, vm_pindex_t size, LIST_INIT(&object->shadow_head); object->type = type; + if (type == OBJT_SWAP) + pctrie_init(&object->un_pager.swp.swp_blks); + + /* + * Ensure that swap_pager_swapoff() iteration over object_list + * sees up to date type and pctrie head if it observed + * non-dead object. + */ + atomic_thread_fence_rel(); + switch (type) { case OBJT_DEAD: panic("_vm_object_allocate: can't create OBJT_DEAD"); Modified: stable/11/sys/vm/vm_object.h ============================================================================== --- stable/11/sys/vm/vm_object.h Wed Sep 13 11:07:12 2017 (r323536) +++ stable/11/sys/vm/vm_object.h Wed Sep 13 11:19:04 2017 (r323537) @@ -70,6 +70,7 @@ #include #include #include +#include #include #include @@ -151,13 +152,12 @@ struct vm_object { * the handle changed and hash-chain * invalid. * - * swp_bcount - number of swap 'swblock' metablocks, each - * contains up to 16 swapblk assignments. - * see vm/swap_pager.h + * swp_blks - pc-trie of the allocated swap blocks. + * */ struct { void *swp_tmpfs; - int swp_bcount; + struct pctrie swp_blks; } swp; } un_pager; struct ucred *cred; From owner-svn-src-stable-11@freebsd.org Wed Sep 13 11:29:50 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1CDAEE1BD88; Wed, 13 Sep 2017 11:29:50 +0000 (UTC) (envelope-from kib@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 mx1.freebsd.org (Postfix) with ESMTPS id EADC78C; Wed, 13 Sep 2017 11:29:49 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8DBTnvR080447; Wed, 13 Sep 2017 11:29:49 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8DBTmD8080440; Wed, 13 Sep 2017 11:29:48 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709131129.v8DBTmD8080440@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 13 Sep 2017 11:29:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323538 - stable/11/lib/libc/amd64/sys X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/lib/libc/amd64/sys X-SVN-Commit-Revision: 323538 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Sep 2017 11:29:50 -0000 Author: kib Date: Wed Sep 13 11:29:48 2017 New Revision: 323538 URL: https://svnweb.freebsd.org/changeset/base/323538 Log: MFC 322763: Optimize libc to get and set TLS using the RDFSBASE and RDGSBASE instructions, if supported both by CPU and kernel. Added: stable/11/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.c - copied, changed from r322763, head/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.c stable/11/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.h - copied unchanged from r322763, head/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.h Modified: stable/11/lib/libc/amd64/sys/Makefile.inc stable/11/lib/libc/amd64/sys/amd64_get_fsbase.c stable/11/lib/libc/amd64/sys/amd64_get_gsbase.c stable/11/lib/libc/amd64/sys/amd64_set_fsbase.c stable/11/lib/libc/amd64/sys/amd64_set_gsbase.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libc/amd64/sys/Makefile.inc ============================================================================== --- stable/11/lib/libc/amd64/sys/Makefile.inc Wed Sep 13 11:19:04 2017 (r323537) +++ stable/11/lib/libc/amd64/sys/Makefile.inc Wed Sep 13 11:29:48 2017 (r323538) @@ -1,7 +1,11 @@ # from: Makefile.inc,v 1.1 1993/09/03 19:04:23 jtc Exp # $FreeBSD$ -SRCS+= amd64_get_fsbase.c amd64_get_gsbase.c amd64_set_fsbase.c \ +SRCS+= \ + amd64_detect_rdfsgsbase.c \ + amd64_get_fsbase.c \ + amd64_get_gsbase.c \ + amd64_set_fsbase.c \ amd64_set_gsbase.c MDASM= vfork.S brk.S cerror.S exect.S getcontext.S \ Copied and modified: stable/11/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.c (from r322763, head/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.c) ============================================================================== --- head/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.c Mon Aug 21 17:39:12 2017 (r322763, copy source) +++ stable/11/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.c Wed Sep 13 11:29:48 2017 (r323538) @@ -48,7 +48,9 @@ amd64_detect_rdfsgsbase(void) if (__predict_true(state != RDFSGS_UNKNOWN)) return (state); - if (__getosreldate() >= P_OSREL_WRFSBASE) { + if (__getosreldate() >= P_OSREL_WRFSBASE || + (P_OSREL_MAJOR(__getosreldate()) == 11 && __getosreldate() >= + P_OSREL_WRFSBASE_11)) { do_cpuid(0x0, p); if (p[0] >= 0x7) { cpuid_count(0x7, 0x0, p); Copied: stable/11/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.h (from r322763, head/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.h Wed Sep 13 11:29:48 2017 (r323538, copy of r322763, head/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.h) @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2017 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * 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$ + */ + +#ifndef _AMD64_DETECT_RDFSGSBASE_H_ +#define _AMD64_DETECT_RDFSGSBASE_H_ + +enum { + RDFSGS_UNKNOWN, + RDFSGS_SUPPORTED, + RDFSGS_UNSUPPORTED, +}; + +int amd64_detect_rdfsgsbase(void); + +#endif Modified: stable/11/lib/libc/amd64/sys/amd64_get_fsbase.c ============================================================================== --- stable/11/lib/libc/amd64/sys/amd64_get_fsbase.c Wed Sep 13 11:19:04 2017 (r323537) +++ stable/11/lib/libc/amd64/sys/amd64_get_fsbase.c Wed Sep 13 11:29:48 2017 (r323538) @@ -1,7 +1,11 @@ /*- * Copyright (c) 2003 Peter Wemm + * Copyright (c) 2017 The FreeBSD Foundation * All rights reserved. * + * Portions of this software were developed by Konstantin Belousov + * 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: @@ -27,11 +31,18 @@ #include __FBSDID("$FreeBSD$"); +#include +#include #include +#include "amd64_detect_rdfsgsbase.h" int amd64_get_fsbase(void **addr) { + if (amd64_detect_rdfsgsbase() == RDFSGS_SUPPORTED) { + *addr = (void *)rdfsbase(); + return (0); + } return (sysarch(AMD64_GET_FSBASE, addr)); } Modified: stable/11/lib/libc/amd64/sys/amd64_get_gsbase.c ============================================================================== --- stable/11/lib/libc/amd64/sys/amd64_get_gsbase.c Wed Sep 13 11:19:04 2017 (r323537) +++ stable/11/lib/libc/amd64/sys/amd64_get_gsbase.c Wed Sep 13 11:29:48 2017 (r323538) @@ -1,7 +1,11 @@ /*- * Copyright (c) 2003 Peter Wemm + * Copyright (c) 2017 The FreeBSD Foundation * All rights reserved. * + * Portions of this software were developed by Konstantin Belousov + * 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: @@ -27,11 +31,18 @@ #include __FBSDID("$FreeBSD$"); +#include +#include #include +#include "amd64_detect_rdfsgsbase.h" int amd64_get_gsbase(void **addr) { + if (amd64_detect_rdfsgsbase() == RDFSGS_SUPPORTED) { + *addr = (void *)rdgsbase(); + return (0); + } return (sysarch(AMD64_GET_GSBASE, addr)); } Modified: stable/11/lib/libc/amd64/sys/amd64_set_fsbase.c ============================================================================== --- stable/11/lib/libc/amd64/sys/amd64_set_fsbase.c Wed Sep 13 11:19:04 2017 (r323537) +++ stable/11/lib/libc/amd64/sys/amd64_set_fsbase.c Wed Sep 13 11:29:48 2017 (r323538) @@ -1,7 +1,11 @@ /*- * Copyright (c) 2003 Peter Wemm + * Copyright (c) 2017 The FreeBSD Foundation * All rights reserved. * + * Portions of this software were developed by Konstantin Belousov + * 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: @@ -27,11 +31,18 @@ #include __FBSDID("$FreeBSD$"); +#include +#include #include +#include "amd64_detect_rdfsgsbase.h" int amd64_set_fsbase(void *addr) { + if (amd64_detect_rdfsgsbase() == RDFSGS_SUPPORTED) { + wrfsbase((uintptr_t)addr); + return (0); + } return (sysarch(AMD64_SET_FSBASE, &addr)); } Modified: stable/11/lib/libc/amd64/sys/amd64_set_gsbase.c ============================================================================== --- stable/11/lib/libc/amd64/sys/amd64_set_gsbase.c Wed Sep 13 11:19:04 2017 (r323537) +++ stable/11/lib/libc/amd64/sys/amd64_set_gsbase.c Wed Sep 13 11:29:48 2017 (r323538) @@ -1,7 +1,11 @@ /*- * Copyright (c) 2003 Peter Wemm + * Copyright (c) 2017 The FreeBSD Foundation * All rights reserved. * + * Portions of this software were developed by Konstantin Belousov + * 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: @@ -27,11 +31,18 @@ #include __FBSDID("$FreeBSD$"); +#include +#include #include +#include "amd64_detect_rdfsgsbase.h" int amd64_set_gsbase(void *addr) { + if (amd64_detect_rdfsgsbase() == RDFSGS_SUPPORTED) { + wrgsbase((uintptr_t)addr); + return (0); + } return (sysarch(AMD64_SET_GSBASE, &addr)); } From owner-svn-src-stable-11@freebsd.org Wed Sep 13 16:21:12 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 60374E03E6B; Wed, 13 Sep 2017 16:21:12 +0000 (UTC) (envelope-from pfg@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 mx1.freebsd.org (Postfix) with ESMTPS id 3C5956C466; Wed, 13 Sep 2017 16:21:12 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8DGLBhL003650; Wed, 13 Sep 2017 16:21:11 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8DGLBfi003647; Wed, 13 Sep 2017 16:21:11 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201709131621.v8DGLBfi003647@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Wed, 13 Sep 2017 16:21:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323548 - in stable/11/lib/libc: gen locale X-SVN-Group: stable-11 X-SVN-Commit-Author: pfg X-SVN-Commit-Paths: in stable/11/lib/libc: gen locale X-SVN-Commit-Revision: 323548 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Sep 2017 16:21:12 -0000 Author: pfg Date: Wed Sep 13 16:21:11 2017 New Revision: 323548 URL: https://svnweb.freebsd.org/changeset/base/323548 Log: MFC r322925: libc: minor indent(1) cleanups. Illumos and Schillix are adopting some of the locale code and our style(9) sometimes matches the Solaris cstyle, so the changes are also useful as a way to reduce diffs. No functional change. Modified: stable/11/lib/libc/gen/fnmatch.c stable/11/lib/libc/locale/setlocale.c stable/11/lib/libc/locale/setrunelocale.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libc/gen/fnmatch.c ============================================================================== --- stable/11/lib/libc/gen/fnmatch.c Wed Sep 13 16:13:14 2017 (r323547) +++ stable/11/lib/libc/gen/fnmatch.c Wed Sep 13 16:21:11 2017 (r323548) @@ -249,7 +249,7 @@ rangematch(const char *pattern, wchar_t test, int flag * consistency with the regular expression syntax. * J.T. Conklin (conklin@ngai.kaleida.com) */ - if ( (negate = (*pattern == '!' || *pattern == '^')) ) + if ((negate = (*pattern == '!' || *pattern == '^'))) ++pattern; if (flags & FNM_CASEFOLD) Modified: stable/11/lib/libc/locale/setlocale.c ============================================================================== --- stable/11/lib/libc/locale/setlocale.c Wed Sep 13 16:13:14 2017 (r323547) +++ stable/11/lib/libc/locale/setlocale.c Wed Sep 13 16:21:11 2017 (r323548) @@ -42,48 +42,48 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include /* for _PATH_LOCALE */ +#include /* for _PATH_LOCALE */ #include #include #include #include "collate.h" -#include "lmonetary.h" /* for __monetary_load_locale() */ -#include "lnumeric.h" /* for __numeric_load_locale() */ -#include "lmessages.h" /* for __messages_load_locale() */ +#include "lmonetary.h" /* for __monetary_load_locale() */ +#include "lnumeric.h" /* for __numeric_load_locale() */ +#include "lmessages.h" /* for __messages_load_locale() */ #include "setlocale.h" #include "ldpart.h" -#include "../stdtime/timelocal.h" /* for __time_load_locale() */ +#include "../stdtime/timelocal.h" /* for __time_load_locale() */ /* * Category names for getenv() */ static const char categories[_LC_LAST][12] = { - "LC_ALL", - "LC_COLLATE", - "LC_CTYPE", - "LC_MONETARY", - "LC_NUMERIC", - "LC_TIME", - "LC_MESSAGES", + "LC_ALL", + "LC_COLLATE", + "LC_CTYPE", + "LC_MONETARY", + "LC_NUMERIC", + "LC_TIME", + "LC_MESSAGES", }; /* * Current locales for each category */ static char current_categories[_LC_LAST][ENCODING_LEN + 1] = { - "C", - "C", - "C", - "C", - "C", - "C", - "C", + "C", + "C", + "C", + "C", + "C", + "C", + "C", }; /* * Path to locale storage directory */ -char *_PathLocale; +char *_PathLocale; /* * The locales we are going to try and load @@ -93,21 +93,20 @@ static char saved_categories[_LC_LAST][ENCODING_LEN + static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)]; -static char *currentlocale(void); -static char *loadlocale(int); +static char *currentlocale(void); +static char *loadlocale(int); const char *__get_locale_env(int); char * setlocale(int category, const char *locale) { int i, j, len, saverr; - const char *env, *r; + const char *env, *r; if (category < LC_ALL || category >= _LC_LAST) { errno = EINVAL; return (NULL); } - if (locale == NULL) return (category != LC_ALL ? current_categories[category] : currentlocale()); @@ -162,13 +161,13 @@ setlocale(int category, const char *locale) } do { if (i == _LC_LAST) - break; /* Too many slashes... */ + break; /* Too many slashes... */ if ((len = r - locale) > ENCODING_LEN) { errno = EINVAL; return (NULL); } (void)strlcpy(new_categories[i], locale, - len + 1); + len + 1); i++; while (*r == '/') r++; @@ -178,7 +177,7 @@ setlocale(int category, const char *locale) } while (*locale); while (i < _LC_LAST) { (void)strcpy(new_categories[i], - new_categories[i-1]); + new_categories[i - 1]); i++; } } @@ -193,7 +192,7 @@ setlocale(int category, const char *locale) saverr = errno; for (j = 1; j < i; j++) { (void)strcpy(new_categories[j], - saved_categories[j]); + saved_categories[j]); if (loadlocale(j) == NULL) { (void)strcpy(new_categories[j], "C"); (void)loadlocale(j); @@ -218,7 +217,7 @@ currentlocale(void) for (i = 2; i < _LC_LAST; ++i) { (void)strcat(current_locale_string, "/"); (void)strcat(current_locale_string, - current_categories[i]); + current_categories[i]); } break; } @@ -230,16 +229,15 @@ loadlocale(int category) { char *new = new_categories[category]; char *old = current_categories[category]; - int (*func)(const char *); + int (*func) (const char *); int saved_errno; if ((new[0] == '.' && - (new[1] == '\0' || (new[1] == '.' && new[2] == '\0'))) || + (new[1] == '\0' || (new[1] == '.' && new[2] == '\0'))) || strchr(new, '/') != NULL) { errno = EINVAL; return (NULL); } - saved_errno = errno; errno = __detect_path_locale(); if (errno != 0) @@ -285,22 +283,22 @@ loadlocale(int category) const char * __get_locale_env(int category) { - const char *env; + const char *env; - /* 1. check LC_ALL. */ - env = getenv(categories[0]); + /* 1. check LC_ALL. */ + env = getenv(categories[0]); - /* 2. check LC_* */ + /* 2. check LC_* */ if (env == NULL || !*env) - env = getenv(categories[category]); + env = getenv(categories[category]); - /* 3. check LANG */ + /* 3. check LANG */ if (env == NULL || !*env) - env = getenv("LANG"); + env = getenv("LANG"); - /* 4. if none is set, fall to "C" */ + /* 4. if none is set, fall to "C" */ if (env == NULL || !*env) - env = "C"; + env = "C"; return (env); } @@ -326,4 +324,3 @@ __detect_path_locale(void) } return (0); } - Modified: stable/11/lib/libc/locale/setrunelocale.c ============================================================================== --- stable/11/lib/libc/locale/setrunelocale.c Wed Sep 13 16:13:14 2017 (r323547) +++ stable/11/lib/libc/locale/setrunelocale.c Wed Sep 13 16:21:11 2017 (r323548) @@ -38,7 +38,7 @@ #include __FBSDID("$FreeBSD$"); -#define __RUNETYPE_INTERNAL 1 +#define __RUNETYPE_INTERNAL 1 #include #include @@ -72,7 +72,7 @@ destruct_ctype(void *v) { struct xlocale_ctype *l = v; - if (&_DefaultRuneLocale != l->runes) + if (&_DefaultRuneLocale != l->runes) free(l->runes); free(l); } @@ -81,7 +81,7 @@ const _RuneLocale * __getCurrentRuneLocale(void) { - return XLOCALE_CTYPE(__get_locale())->runes; + return (XLOCALE_CTYPE(__get_locale())->runes); } static void @@ -144,7 +144,7 @@ __setrunelocale(struct xlocale_ctype *l, const char *e else if (strcmp(rl->__encoding, "EUC-TW") == 0) ret = _EUC_TW_init(l, rl); else if (strcmp(rl->__encoding, "GB18030") == 0) - ret = _GB18030_init(l, rl); + ret = _GB18030_init(l, rl); else if (strcmp(rl->__encoding, "GB2312") == 0) ret = _GB2312_init(l, rl); else if (strcmp(rl->__encoding, "GBK") == 0) @@ -204,10 +204,9 @@ __ctype_load(const char *locale, locale_t unused __unu struct xlocale_ctype *l = calloc(sizeof(struct xlocale_ctype), 1); l->header.header.destructor = destruct_ctype; - if (__setrunelocale(l, locale)) - { + if (__setrunelocale(l, locale)) { free(l); - return NULL; + return (NULL); } - return l; + return (l); } From owner-svn-src-stable-11@freebsd.org Wed Sep 13 21:21:34 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A89FFE10341; Wed, 13 Sep 2017 21:21:34 +0000 (UTC) (envelope-from marius@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 mx1.freebsd.org (Postfix) with ESMTPS id 83E2277270; Wed, 13 Sep 2017 21:21:34 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8DLLXm4026215; Wed, 13 Sep 2017 21:21:33 GMT (envelope-from marius@FreeBSD.org) Received: (from marius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8DLLXs7026213; Wed, 13 Sep 2017 21:21:33 GMT (envelope-from marius@FreeBSD.org) Message-Id: <201709132121.v8DLLXs7026213@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: marius set sender to marius@FreeBSD.org using -f From: Marius Strobl Date: Wed, 13 Sep 2017 21:21:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323563 - stable/11/contrib/zlib X-SVN-Group: stable-11 X-SVN-Commit-Author: marius X-SVN-Commit-Paths: stable/11/contrib/zlib X-SVN-Commit-Revision: 323563 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Sep 2017 21:21:34 -0000 Author: marius Date: Wed Sep 13 21:21:33 2017 New Revision: 323563 URL: https://svnweb.freebsd.org/changeset/base/323563 Log: MFC: 323382, MFV: r323381 Permit a deflateParams() parameter change as soon as possible. This change fixes compression errors seen when the embedded Tomcat web server of a UniFi Controller zlib compresses responses. Given that Tomcat just uses Java/OpenJDK which in turn employs zlib for its compression/decompression support, this bug might very well affect other applications, too. PR: 222136 Modified: stable/11/contrib/zlib/deflate.c stable/11/contrib/zlib/zlib.h Directory Properties: stable/11/ (props changed) Modified: stable/11/contrib/zlib/deflate.c ============================================================================== --- stable/11/contrib/zlib/deflate.c Wed Sep 13 19:30:09 2017 (r323562) +++ stable/11/contrib/zlib/deflate.c Wed Sep 13 21:21:33 2017 (r323563) @@ -494,7 +494,7 @@ int ZEXPORT deflateResetKeep (strm) s->wrap == 2 ? crc32(0L, Z_NULL, 0) : #endif adler32(0L, Z_NULL, 0); - s->last_flush = Z_NO_FLUSH; + s->last_flush = -2; _tr_init(s); @@ -587,12 +587,12 @@ int ZEXPORT deflateParams(strm, level, strategy) func = configuration_table[s->level].func; if ((strategy != s->strategy || func != configuration_table[level].func) && - s->high_water) { + s->last_flush != -2) { /* Flush the last buffer: */ int err = deflate(strm, Z_BLOCK); if (err == Z_STREAM_ERROR) return err; - if (strm->avail_out == 0) + if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead) return Z_BUF_ERROR; } if (s->level != level) { Modified: stable/11/contrib/zlib/zlib.h ============================================================================== --- stable/11/contrib/zlib/zlib.h Wed Sep 13 19:30:09 2017 (r323562) +++ stable/11/contrib/zlib/zlib.h Wed Sep 13 21:21:33 2017 (r323563) @@ -712,11 +712,12 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, used to switch between compression and straight copy of the input data, or to switch to a different kind of input data requiring a different strategy. If the compression approach (which is a function of the level) or the - strategy is changed, and if any input has been consumed in a previous - deflate() call, then the input available so far is compressed with the old - level and strategy using deflate(strm, Z_BLOCK). There are three approaches - for the compression levels 0, 1..3, and 4..9 respectively. The new level - and strategy will take effect at the next call of deflate(). + strategy is changed, and if there have been any deflate() calls since the + state was initialized or reset, then the input available so far is + compressed with the old level and strategy using deflate(strm, Z_BLOCK). + There are three approaches for the compression levels 0, 1..3, and 4..9 + respectively. The new level and strategy will take effect at the next call + of deflate(). If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does not have enough output space to complete, then the parameter change will not From owner-svn-src-stable-11@freebsd.org Thu Sep 14 00:33:29 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 435AAE17DB9; Thu, 14 Sep 2017 00:33:29 +0000 (UTC) (envelope-from markj@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 mx1.freebsd.org (Postfix) with ESMTPS id 0FBA181153; Thu, 14 Sep 2017 00:33:28 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8E0XSxj006614; Thu, 14 Sep 2017 00:33:28 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8E0XSkY006613; Thu, 14 Sep 2017 00:33:28 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201709140033.v8E0XSkY006613@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 14 Sep 2017 00:33:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323567 - stable/11/sys/ofed/drivers/infiniband/core X-SVN-Group: stable-11 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: stable/11/sys/ofed/drivers/infiniband/core X-SVN-Commit-Revision: 323567 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Sep 2017 00:33:29 -0000 Author: markj Date: Thu Sep 14 00:33:27 2017 New Revision: 323567 URL: https://svnweb.freebsd.org/changeset/base/323567 Log: MFC r323280: Fix indentation. Modified: stable/11/sys/ofed/drivers/infiniband/core/cma.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/ofed/drivers/infiniband/core/cma.c ============================================================================== --- stable/11/sys/ofed/drivers/infiniband/core/cma.c Wed Sep 13 22:11:05 2017 (r323566) +++ stable/11/sys/ofed/drivers/infiniband/core/cma.c Thu Sep 14 00:33:27 2017 (r323567) @@ -3203,9 +3203,9 @@ int rdma_accept(struct rdma_cm_id *id, struct rdma_con NULL, 0); } else { if (conn_param) - ret = cma_accept_ib(id_priv, conn_param); - else - ret = cma_rep_recv(id_priv); + ret = cma_accept_ib(id_priv, conn_param); + else + ret = cma_rep_recv(id_priv); } break; case RDMA_TRANSPORT_IWARP: From owner-svn-src-stable-11@freebsd.org Thu Sep 14 00:35:28 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C212CE17FCD; Thu, 14 Sep 2017 00:35:28 +0000 (UTC) (envelope-from emaste@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 mx1.freebsd.org (Postfix) with ESMTPS id 8D95C812DC; Thu, 14 Sep 2017 00:35:28 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8E0ZRXv006748; Thu, 14 Sep 2017 00:35:27 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8E0ZRMv006747; Thu, 14 Sep 2017 00:35:27 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201709140035.v8E0ZRMv006747@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Thu, 14 Sep 2017 00:35:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323568 - stable/11/usr.sbin/bsdinstall/scripts X-SVN-Group: stable-11 X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: stable/11/usr.sbin/bsdinstall/scripts X-SVN-Commit-Revision: 323568 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Sep 2017 00:35:28 -0000 Author: emaste Date: Thu Sep 14 00:35:27 2017 New Revision: 323568 URL: https://svnweb.freebsd.org/changeset/base/323568 Log: MFC r323448: bsdinstall: Ignore error return from newaliases(1) This was originally added as "exit $SUCCESS" but with nothing to set the SUCCESS variable. Thus it became an exit with no argument, which just exits with the status of the preceding command. Sponsored by: The FreeBSD Foundation Modified: stable/11/usr.sbin/bsdinstall/scripts/config Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/bsdinstall/scripts/config ============================================================================== --- stable/11/usr.sbin/bsdinstall/scripts/config Thu Sep 14 00:33:27 2017 (r323567) +++ stable/11/usr.sbin/bsdinstall/scripts/config Thu Sep 14 00:35:27 2017 (r323568) @@ -48,7 +48,7 @@ cp $BSDINSTALL_TMPBOOT/* $BSDINSTALL_CHROOT/boot # Set up other things from installed config chroot $BSDINSTALL_CHROOT /usr/bin/newaliases > /dev/null 2>&1 -exit $SUCCESS +exit 0 ################################################################################ # END From owner-svn-src-stable-11@freebsd.org Thu Sep 14 00:39:09 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7751AE18266; Thu, 14 Sep 2017 00:39:09 +0000 (UTC) (envelope-from emaste@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 mx1.freebsd.org (Postfix) with ESMTPS id 45EE681560; Thu, 14 Sep 2017 00:39:09 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8E0d8Lh007043; Thu, 14 Sep 2017 00:39:08 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8E0d8US007042; Thu, 14 Sep 2017 00:39:08 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201709140039.v8E0d8US007042@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Thu, 14 Sep 2017 00:39:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323569 - stable/11/usr.sbin/bsdinstall/partedit X-SVN-Group: stable-11 X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: stable/11/usr.sbin/bsdinstall/partedit X-SVN-Commit-Revision: 323569 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Sep 2017 00:39:09 -0000 Author: emaste Date: Thu Sep 14 00:39:08 2017 New Revision: 323569 URL: https://svnweb.freebsd.org/changeset/base/323569 Log: MFC r316802 (cem): bsdinstall(8): Sprinkle a snprintf to fixed size buffer Use a snprintf to write an environment variable to a fixed-size buffer to avoid stack overflow. Reported by: Coverity (CWE-120) CID: 1238926 Sponsored by: The FreeBSD Foundation Modified: stable/11/usr.sbin/bsdinstall/partedit/gpart_ops.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/bsdinstall/partedit/gpart_ops.c ============================================================================== --- stable/11/usr.sbin/bsdinstall/partedit/gpart_ops.c Thu Sep 14 00:35:27 2017 (r323568) +++ stable/11/usr.sbin/bsdinstall/partedit/gpart_ops.c Thu Sep 14 00:39:08 2017 (r323569) @@ -148,7 +148,7 @@ newfs_command(const char *fstype, char *command, int u strcpy(command, "zpool create -f -m none "); if (getenv("BSDINSTALL_TMPBOOT") != NULL) { char zfsboot_path[MAXPATHLEN]; - sprintf(zfsboot_path, "%s/zfs", + snprintf(zfsboot_path, sizeof(zfsboot_path), "%s/zfs", getenv("BSDINSTALL_TMPBOOT")); mkdir(zfsboot_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); From owner-svn-src-stable-11@freebsd.org Thu Sep 14 00:41:28 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AA8CBE18523; Thu, 14 Sep 2017 00:41:28 +0000 (UTC) (envelope-from emaste@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 mx1.freebsd.org (Postfix) with ESMTPS id 780A18185E; Thu, 14 Sep 2017 00:41:28 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8E0fR2q007863; Thu, 14 Sep 2017 00:41:27 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8E0fR2q007862; Thu, 14 Sep 2017 00:41:27 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201709140041.v8E0fR2q007862@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Thu, 14 Sep 2017 00:41:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323570 - stable/11/usr.sbin/bsdinstall/scripts X-SVN-Group: stable-11 X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: stable/11/usr.sbin/bsdinstall/scripts X-SVN-Commit-Revision: 323570 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Sep 2017 00:41:28 -0000 Author: emaste Date: Thu Sep 14 00:41:27 2017 New Revision: 323570 URL: https://svnweb.freebsd.org/changeset/base/323570 Log: MFC r321226: bsdinstall: improve checksum mismatch error for snapshots The usual case of a mismatched checksum for installer snapshots (e.g., -CURRENT, -ALPHA*) is that a newer snapshot has been built and the old install sets have been replaced. Provide a specific error message for checksum mismatches there that suggests looking for a newer snapshot. Submitted by: Guangyuan Yang Sponsored by: The FreeBSD Foundation Modified: stable/11/usr.sbin/bsdinstall/scripts/checksum Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/bsdinstall/scripts/checksum ============================================================================== --- stable/11/usr.sbin/bsdinstall/scripts/checksum Thu Sep 14 00:39:08 2017 (r323569) +++ stable/11/usr.sbin/bsdinstall/scripts/checksum Thu Sep 14 00:41:27 2017 (r323570) @@ -62,8 +62,16 @@ for dist in $DISTRIBUTIONS; do percentage=$(echo $percentage + 100/`echo $DISTRIBUTIONS | wc -w` | bc) else eval "status_$distname=1" - dialog --backtitle "FreeBSD Installer" --title "Error" \ - --msgbox "The checksum for $dist does not match. It may have become corrupted, and should be redownloaded." 0 0 + case $(/bin/freebsd-version -u) in + *-ALPHA*|*-CURRENT|*-STABLE|*-PRERELEASE) + dialog --backtitle "FreeBSD Installer" --title "Error" \ + --msgbox "The checksum for $dist does not match. It may have become corrupted, or it may be from a newer version of FreeBSD. Please check for a newer snapshot." 0 0 + ;; + *) + dialog --backtitle "FreeBSD Installer" --title "Error" \ + --msgbox "The checksum for $dist does not match. It may have become corrupted, and should be redownloaded." 0 0 + ;; + esac exit 1 fi done From owner-svn-src-stable-11@freebsd.org Fri Sep 15 00:35:01 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 02196E17AC8; Fri, 15 Sep 2017 00:35:01 +0000 (UTC) (envelope-from markj@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 mx1.freebsd.org (Postfix) with ESMTPS id C4C1070A1E; Fri, 15 Sep 2017 00:35:00 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8F0Yxrn098812; Fri, 15 Sep 2017 00:34:59 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8F0Yx1S098811; Fri, 15 Sep 2017 00:34:59 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201709150034.v8F0Yx1S098811@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Fri, 15 Sep 2017 00:34:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323606 - stable/11/cddl/contrib/opensolaris/lib/libdtrace/common X-SVN-Group: stable-11 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: stable/11/cddl/contrib/opensolaris/lib/libdtrace/common X-SVN-Commit-Revision: 323606 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Sep 2017 00:35:01 -0000 Author: markj Date: Fri Sep 15 00:34:59 2017 New Revision: 323606 URL: https://svnweb.freebsd.org/changeset/base/323606 Log: MFC r323498: Add a O_CLOEXEC use missed in r323166. Modified: stable/11/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c Directory Properties: stable/11/ (props changed) Modified: stable/11/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c ============================================================================== --- stable/11/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c Fri Sep 15 00:32:22 2017 (r323605) +++ stable/11/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c Fri Sep 15 00:34:59 2017 (r323606) @@ -1111,7 +1111,7 @@ dt_vopen(int version, int flags, int *errp, */ if (err == ENOENT && modfind("dtraceall") < 0) { kldload("dtraceall"); /* ignore the error */ - dtfd = open("/dev/dtrace/dtrace", O_RDWR); + dtfd = open("/dev/dtrace/dtrace", O_RDWR | O_CLOEXEC); err = errno; } #endif From owner-svn-src-stable-11@freebsd.org Fri Sep 15 09:00:46 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7CB81E086B5; Fri, 15 Sep 2017 09:00:46 +0000 (UTC) (envelope-from kib@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 mx1.freebsd.org (Postfix) with ESMTPS id 4B9AC82C72; Fri, 15 Sep 2017 09:00:46 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8F90jnC070165; Fri, 15 Sep 2017 09:00:45 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8F90jmB070164; Fri, 15 Sep 2017 09:00:45 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709150900.v8F90jmB070164@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 15 Sep 2017 09:00:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323608 - stable/11/sys/x86/include X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/x86/include X-SVN-Commit-Revision: 323608 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Sep 2017 09:00:46 -0000 Author: kib Date: Fri Sep 15 09:00:45 2017 New Revision: 323608 URL: https://svnweb.freebsd.org/changeset/base/323608 Log: MFC r323324: Add a constant specifying the min size of the IOAPIC registers window. Modified: stable/11/sys/x86/include/apicreg.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/x86/include/apicreg.h ============================================================================== --- stable/11/sys/x86/include/apicreg.h Fri Sep 15 00:54:37 2017 (r323607) +++ stable/11/sys/x86/include/apicreg.h Fri Sep 15 09:00:45 2017 (r323608) @@ -469,6 +469,8 @@ typedef struct IOAPIC ioapic_t; #define IOAPIC_WINDOW 0x10 #define IOAPIC_EOIR 0x40 +#define IOAPIC_WND_SIZE 0x50 + /* indexes into IO APIC */ #define IOAPIC_ID 0x00 #define IOAPIC_VER 0x01 From owner-svn-src-stable-11@freebsd.org Fri Sep 15 09:03:03 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0B084E08934; Fri, 15 Sep 2017 09:03:03 +0000 (UTC) (envelope-from kib@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 mx1.freebsd.org (Postfix) with ESMTPS id DA959831DA; Fri, 15 Sep 2017 09:03:02 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8F932e8074186; Fri, 15 Sep 2017 09:03:02 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8F932Ai074185; Fri, 15 Sep 2017 09:03:02 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709150903.v8F932Ai074185@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 15 Sep 2017 09:03:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323609 - stable/11/sys/x86/pci X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/x86/pci X-SVN-Commit-Revision: 323609 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Sep 2017 09:03:03 -0000 Author: kib Date: Fri Sep 15 09:03:01 2017 New Revision: 323609 URL: https://svnweb.freebsd.org/changeset/base/323609 Log: MFC r323327: Enhance qpi.c to make it usable on all Core-microarchitecture Xeons. Modified: stable/11/sys/x86/pci/qpi.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/x86/pci/qpi.c ============================================================================== --- stable/11/sys/x86/pci/qpi.c Fri Sep 15 09:00:45 2017 (r323608) +++ stable/11/sys/x86/pci/qpi.c Fri Sep 15 09:03:01 2017 (r323609) @@ -63,13 +63,19 @@ static MALLOC_DEFINE(M_QPI, "qpidrv", "qpi system devi static void qpi_identify(driver_t *driver, device_t parent) { + int do_qpi; /* Check CPUID to ensure this is an i7 CPU of some sort. */ - if (!(cpu_vendor_id == CPU_VENDOR_INTEL && - CPUID_TO_FAMILY(cpu_id) == 0x6 && - (CPUID_TO_MODEL(cpu_id) == 0x1a || CPUID_TO_MODEL(cpu_id) == 0x2c))) + if (cpu_vendor_id != CPU_VENDOR_INTEL || + CPUID_TO_FAMILY(cpu_id) != 0x6) return; + /* Only discover buses with configuration devices if allowed by user */ + do_qpi = 0; + TUNABLE_INT_FETCH("hw.attach_intel_csr_pci", &do_qpi); + if (!do_qpi) + return; + /* PCI config register access is required. */ if (pci_cfgregopen() == 0) return; @@ -97,6 +103,7 @@ qpi_probe_pcib(device_t dev, int bus) struct qpi_device *qdev; device_t child; uint32_t devid; + int s; /* * If a PCI bus already exists for this bus number, then @@ -106,18 +113,23 @@ qpi_probe_pcib(device_t dev, int bus) return (EEXIST); /* - * Attempt to read the device id for device 0, function 0 on - * the bus. A value of 0xffffffff means that the bus is not - * present. + * Attempt to read the device id for every slot, function 0 on + * the bus. If all read values are 0xffffffff this means that + * the bus is not present. */ - devid = pci_cfgregread(bus, 0, 0, PCIR_DEVVENDOR, 4); + for (s = 0; s <= PCI_SLOTMAX; s++) { + devid = pci_cfgregread(bus, s, 0, PCIR_DEVVENDOR, 4); + if (devid != 0xffffffff) + break; + } if (devid == 0xffffffff) return (ENOENT); if ((devid & 0xffff) != 0x8086) { - device_printf(dev, - "Device at pci%d.0.0 has non-Intel vendor 0x%x\n", bus, - devid & 0xffff); + if (bootverbose) + device_printf(dev, + "Device at pci%d.%d.0 has non-Intel vendor 0x%x\n", + bus, s, devid & 0xffff); return (ENXIO); } @@ -137,12 +149,12 @@ qpi_attach(device_t dev) int bus; /* - * Each processor socket has a dedicated PCI bus counting down from - * 255. We keep probing buses until one fails. + * Each processor socket has a dedicated PCI bus, sometimes + * not enumerated by ACPI. Probe all unattached buses from 0 + * to 255. */ - for (bus = 255;; bus--) - if (qpi_probe_pcib(dev, bus) != 0) - break; + for (bus = PCI_BUSMAX; bus >= 0; bus--) + qpi_probe_pcib(dev, bus); return (bus_generic_attach(dev)); } From owner-svn-src-stable-11@freebsd.org Sat Sep 16 02:10:37 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E168CE1BA8E; Sat, 16 Sep 2017 02:10:37 +0000 (UTC) (envelope-from mjoras@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 mx1.freebsd.org (Postfix) with ESMTPS id B09522024; Sat, 16 Sep 2017 02:10:37 +0000 (UTC) (envelope-from mjoras@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8G2AaFu094062; Sat, 16 Sep 2017 02:10:36 GMT (envelope-from mjoras@FreeBSD.org) Received: (from mjoras@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8G2Aagv094061; Sat, 16 Sep 2017 02:10:36 GMT (envelope-from mjoras@FreeBSD.org) Message-Id: <201709160210.v8G2Aagv094061@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjoras set sender to mjoras@FreeBSD.org using -f From: Matt Joras Date: Sat, 16 Sep 2017 02:10:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323633 - stable/11/sys/net X-SVN-Group: stable-11 X-SVN-Commit-Author: mjoras X-SVN-Commit-Paths: stable/11/sys/net X-SVN-Commit-Revision: 323633 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Sep 2017 02:10:38 -0000 Author: mjoras Date: Sat Sep 16 02:10:36 2017 New Revision: 323633 URL: https://svnweb.freebsd.org/changeset/base/323633 Log: MFC r323513: Allow vlan interfaces to rx through netmap(4). Modified: stable/11/sys/net/if_vlan.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/net/if_vlan.c ============================================================================== --- stable/11/sys/net/if_vlan.c Fri Sep 15 22:56:39 2017 (r323632) +++ stable/11/sys/net/if_vlan.c Sat Sep 16 02:10:36 2017 (r323633) @@ -1376,7 +1376,7 @@ vlan_input(struct ifnet *ifp, struct mbuf *m) VLAN_RUNLOCK(); /* Pass it back through the parent's input routine. */ - (*ifp->if_input)(ifv->ifv_ifp, m); + (*ifv->ifv_ifp->if_input)(ifv->ifv_ifp, m); } static void From owner-svn-src-stable-11@freebsd.org Sat Sep 16 02:32:01 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C4B60E1D9C4; Sat, 16 Sep 2017 02:32:01 +0000 (UTC) (envelope-from glebius@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 mx1.freebsd.org (Postfix) with ESMTPS id 93FDF3382; Sat, 16 Sep 2017 02:32:01 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8G2W0O8006038; Sat, 16 Sep 2017 02:32:00 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8G2W0PW006037; Sat, 16 Sep 2017 02:32:00 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201709160232.v8G2W0PW006037@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Sat, 16 Sep 2017 02:32:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323634 - stable/11/sys/kern X-SVN-Group: stable-11 X-SVN-Commit-Author: glebius X-SVN-Commit-Paths: stable/11/sys/kern X-SVN-Commit-Revision: 323634 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Sep 2017 02:32:01 -0000 Author: glebius Date: Sat Sep 16 02:32:00 2017 New Revision: 323634 URL: https://svnweb.freebsd.org/changeset/base/323634 Log: Merge r323552: Fix two issues with not ready data in sockets (read: sendfile) in UNIX sockets. o Check that socket is still connected in uipc_ready(). If not we are responsible to free mbufs. o In uipc_send() if socket appears to be disconnected, but we are sending data with pending I/Os, don't free mbufs. PR: 222259 Modified: stable/11/sys/kern/uipc_usrreq.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/uipc_usrreq.c ============================================================================== --- stable/11/sys/kern/uipc_usrreq.c Sat Sep 16 02:10:36 2017 (r323633) +++ stable/11/sys/kern/uipc_usrreq.c Sat Sep 16 02:32:00 2017 (r323634) @@ -1056,7 +1056,11 @@ uipc_send(struct socket *so, int flags, struct mbuf *m release: if (control != NULL) m_freem(control); - if (m != NULL) + /* + * In case of PRUS_NOTREADY, uipc_ready() is responsible + * for freeing memory. + */ + if (m != NULL && (flags & PRUS_NOTREADY) == 0) m_freem(m); return (error); } @@ -1071,7 +1075,12 @@ uipc_ready(struct socket *so, struct mbuf *m, int coun unp = sotounpcb(so); UNP_LINK_RLOCK(); - unp2 = unp->unp_conn; + if ((unp2 = unp->unp_conn) == NULL) { + UNP_LINK_RUNLOCK(); + for (int i = 0; i < count; i++) + m = m_free(m); + return (ECONNRESET); + } UNP_PCB_LOCK(unp2); so2 = unp2->unp_socket; From owner-svn-src-stable-11@freebsd.org Sat Sep 16 13:49:28 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 20E61E17A82; Sat, 16 Sep 2017 13:49:28 +0000 (UTC) (envelope-from kib@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 mx1.freebsd.org (Postfix) with ESMTPS id EECBA76A06; Sat, 16 Sep 2017 13:49:27 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8GDnRCR081625; Sat, 16 Sep 2017 13:49:27 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8GDnQo1081622; Sat, 16 Sep 2017 13:49:26 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709161349.v8GDnQo1081622@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 16 Sep 2017 13:49:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323638 - stable/11/sys/vm X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/vm X-SVN-Commit-Revision: 323638 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Sep 2017 13:49:28 -0000 Author: kib Date: Sat Sep 16 13:49:26 2017 New Revision: 323638 URL: https://svnweb.freebsd.org/changeset/base/323638 Log: MFC r323368: Add a vm_page_change_lock() helper. Modified: stable/11/sys/vm/vm_object.c stable/11/sys/vm/vm_page.c stable/11/sys/vm/vm_page.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/vm/vm_object.c ============================================================================== --- stable/11/sys/vm/vm_object.c Sat Sep 16 05:42:27 2017 (r323637) +++ stable/11/sys/vm/vm_object.c Sat Sep 16 13:49:26 2017 (r323638) @@ -1910,6 +1910,7 @@ vm_object_page_remove(vm_object_t object, vm_pindex_t int options) { vm_page_t p, next; + struct mtx *mtx; VM_OBJECT_ASSERT_WLOCKED(object); KASSERT((object->flags & OBJ_UNMANAGED) == 0 || @@ -1920,6 +1921,7 @@ vm_object_page_remove(vm_object_t object, vm_pindex_t vm_object_pip_add(object, 1); again: p = vm_page_find_least(object, start); + mtx = NULL; /* * Here, the variable "p" is either (1) the page with the least pindex @@ -1936,7 +1938,7 @@ again: * however, be invalidated if the option OBJPR_CLEANONLY is * not specified. */ - vm_page_lock(p); + vm_page_change_lock(p, &mtx); if (vm_page_xbusied(p)) { VM_OBJECT_WUNLOCK(object); vm_page_busy_sleep(p, "vmopax", true); @@ -1950,7 +1952,7 @@ again: p->valid = 0; vm_page_undirty(p); } - goto next; + continue; } if (vm_page_busied(p)) { VM_OBJECT_WUNLOCK(object); @@ -1964,14 +1966,14 @@ again: if ((options & OBJPR_NOTMAPPED) == 0) pmap_remove_write(p); if (p->dirty) - goto next; + continue; } if ((options & OBJPR_NOTMAPPED) == 0) pmap_remove_all(p); vm_page_free(p); -next: - vm_page_unlock(p); } + if (mtx != NULL) + mtx_unlock(mtx); vm_object_pip_wakeup(object); } @@ -1994,7 +1996,7 @@ next: void vm_object_page_noreuse(vm_object_t object, vm_pindex_t start, vm_pindex_t end) { - struct mtx *mtx, *new_mtx; + struct mtx *mtx; vm_page_t p, next; VM_OBJECT_ASSERT_LOCKED(object); @@ -2011,17 +2013,7 @@ vm_object_page_noreuse(vm_object_t object, vm_pindex_t mtx = NULL; for (; p != NULL && (p->pindex < end || end == 0); p = next) { next = TAILQ_NEXT(p, listq); - - /* - * Avoid releasing and reacquiring the same page lock. - */ - new_mtx = vm_page_lockptr(p); - if (mtx != new_mtx) { - if (mtx != NULL) - mtx_unlock(mtx); - mtx = new_mtx; - mtx_lock(mtx); - } + vm_page_change_lock(p, &mtx); vm_page_deactivate_noreuse(p); } if (mtx != NULL) Modified: stable/11/sys/vm/vm_page.c ============================================================================== --- stable/11/sys/vm/vm_page.c Sat Sep 16 05:42:27 2017 (r323637) +++ stable/11/sys/vm/vm_page.c Sat Sep 16 13:49:26 2017 (r323638) @@ -905,6 +905,23 @@ vm_page_flash(vm_page_t m) } /* + * Avoid releasing and reacquiring the same page lock. + */ +void +vm_page_change_lock(vm_page_t m, struct mtx **mtx) +{ + struct mtx *mtx1; + + mtx1 = vm_page_lockptr(m); + if (*mtx == mtx1) + return; + if (*mtx != NULL) + mtx_unlock(*mtx); + *mtx = mtx1; + mtx_lock(mtx1); +} + +/* * Keep page from being freed by the page daemon * much of the same effect as wiring, except much lower * overhead and should be used only for *very* temporary @@ -937,20 +954,11 @@ vm_page_unhold(vm_page_t mem) void vm_page_unhold_pages(vm_page_t *ma, int count) { - struct mtx *mtx, *new_mtx; + struct mtx *mtx; mtx = NULL; for (; count != 0; count--) { - /* - * Avoid releasing and reacquiring the same page lock. - */ - new_mtx = vm_page_lockptr(*ma); - if (mtx != new_mtx) { - if (mtx != NULL) - mtx_unlock(mtx); - mtx = new_mtx; - mtx_lock(mtx); - } + vm_page_change_lock(*ma, &mtx); vm_page_unhold(*ma); ma++; } @@ -1989,7 +1997,7 @@ vm_page_t vm_page_scan_contig(u_long npages, vm_page_t m_start, vm_page_t m_end, u_long alignment, vm_paddr_t boundary, int options) { - struct mtx *m_mtx, *new_mtx; + struct mtx *m_mtx; vm_object_t object; vm_paddr_t pa; vm_page_t m, m_run; @@ -2032,16 +2040,7 @@ vm_page_scan_contig(u_long npages, vm_page_t m_start, } else KASSERT(m_run != NULL, ("m_run == NULL")); - /* - * Avoid releasing and reacquiring the same page lock. - */ - new_mtx = vm_page_lockptr(m); - if (m_mtx != new_mtx) { - if (m_mtx != NULL) - mtx_unlock(m_mtx); - m_mtx = new_mtx; - mtx_lock(m_mtx); - } + vm_page_change_lock(m, &m_mtx); m_inc = 1; retry: if (m->wire_count != 0 || m->hold_count != 0) @@ -2191,7 +2190,7 @@ static int vm_page_reclaim_run(int req_class, u_long npages, vm_page_t m_run, vm_paddr_t high) { - struct mtx *m_mtx, *new_mtx; + struct mtx *m_mtx; struct spglist free; vm_object_t object; vm_paddr_t pa; @@ -2212,13 +2211,7 @@ vm_page_reclaim_run(int req_class, u_long npages, vm_p /* * Avoid releasing and reacquiring the same page lock. */ - new_mtx = vm_page_lockptr(m); - if (m_mtx != new_mtx) { - if (m_mtx != NULL) - mtx_unlock(m_mtx); - m_mtx = new_mtx; - mtx_lock(m_mtx); - } + vm_page_change_lock(m, &m_mtx); retry: if (m->wire_count != 0 || m->hold_count != 0) error = EBUSY; @@ -2331,12 +2324,7 @@ retry: * The new page must be deactivated * before the object is unlocked. */ - new_mtx = vm_page_lockptr(m_new); - if (m_mtx != new_mtx) { - mtx_unlock(m_mtx); - m_mtx = new_mtx; - mtx_lock(m_mtx); - } + vm_page_change_lock(m_new, &m_mtx); vm_page_deactivate(m_new); } else { m->flags &= ~PG_ZERO; Modified: stable/11/sys/vm/vm_page.h ============================================================================== --- stable/11/sys/vm/vm_page.h Sat Sep 16 05:42:27 2017 (r323637) +++ stable/11/sys/vm/vm_page.h Sat Sep 16 13:49:26 2017 (r323638) @@ -448,6 +448,7 @@ vm_page_t vm_page_alloc_contig(vm_object_t object, vm_ u_long npages, vm_paddr_t low, vm_paddr_t high, u_long alignment, vm_paddr_t boundary, vm_memattr_t memattr); vm_page_t vm_page_alloc_freelist(int, int); +void vm_page_change_lock(vm_page_t m, struct mtx **mtx); vm_page_t vm_page_grab (vm_object_t, vm_pindex_t, int); int vm_page_try_to_free (vm_page_t); void vm_page_deactivate (vm_page_t);