From owner-svn-src-stable-9@freebsd.org Tue Mar 14 15:25:51 2017 Return-Path: Delivered-To: svn-src-stable-9@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 A6776D0C3A4; Tue, 14 Mar 2017 15:25:51 +0000 (UTC) (envelope-from hselasky@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 7E4141132; Tue, 14 Mar 2017 15:25:51 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2EFPor8003798; Tue, 14 Mar 2017 15:25:50 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2EFPoiI003793; Tue, 14 Mar 2017 15:25:50 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201703141525.v2EFPoiI003793@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 14 Mar 2017 15:25:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r315250 - in stable/9: share/man/man4 sys/dev/sound/usb sys/dev/usb sys/dev/usb/quirk X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2017 15:25:51 -0000 Author: hselasky Date: Tue Mar 14 15:25:49 2017 New Revision: 315250 URL: https://svnweb.freebsd.org/changeset/base/315250 Log: MFC r312338: Add USB audio support for S/PDIF output with C-Media CM6206 devices. Submitted by: Julien Nadeau PR: 216131 Modified: stable/9/share/man/man4/usb_quirk.4 stable/9/sys/dev/sound/usb/uaudio.c stable/9/sys/dev/usb/quirk/usb_quirk.c stable/9/sys/dev/usb/quirk/usb_quirk.h stable/9/sys/dev/usb/usbdevs Directory Properties: stable/9/share/ (props changed) stable/9/share/man/ (props changed) stable/9/share/man/man4/ (props changed) stable/9/sys/ (props changed) Modified: stable/9/share/man/man4/usb_quirk.4 ============================================================================== --- stable/9/share/man/man4/usb_quirk.4 Tue Mar 14 15:21:41 2017 (r315249) +++ stable/9/share/man/man4/usb_quirk.4 Tue Mar 14 15:25:49 2017 (r315250) @@ -16,7 +16,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 26, 2015 +.Dd January 17, 2017 .Dt USB_QUIRK 4 .Os .Sh NAME @@ -52,6 +52,10 @@ input is async despite claim of adaptive do not adjust for fractional samples .It UQ_AU_NO_XU audio device has broken extension unit +.It UQ_AU_VENDOR_CLASS +audio device uses vendor class to identify itself +.It UQ_AU_SET_SPDIF_CM6206 +audio device needs special programming to enable S/PDIF audio output .It UQ_BAD_ADC bad audio spec version number .It UQ_BAD_AUDIO Modified: stable/9/sys/dev/sound/usb/uaudio.c ============================================================================== --- stable/9/sys/dev/sound/usb/uaudio.c Tue Mar 14 15:21:41 2017 (r315249) +++ stable/9/sys/dev/sound/usb/uaudio.c Tue Mar 14 15:25:49 2017 (r315250) @@ -317,6 +317,11 @@ struct uaudio_hid { uint8_t mute_id; }; +#define UAUDIO_SPDIF_OUT 0x01 /* Enable S/PDIF output */ +#define UAUDIO_SPDIF_OUT_48K 0x02 /* Out sample rate = 48K */ +#define UAUDIO_SPDIF_OUT_96K 0x04 /* Out sample rate = 96K */ +#define UAUDIO_SPDIF_IN_MIX 0x10 /* Input mix enable */ + struct uaudio_softc { struct sbuf sc_sndstat; struct sndcard_func sc_sndcard_func; @@ -334,6 +339,7 @@ struct uaudio_softc { struct usb_xfer *sc_mixer_xfer[1]; struct uaudio_mixer_node *sc_mixer_root; struct uaudio_mixer_node *sc_mixer_curr; + int (*sc_set_spdif_fn) (struct uaudio_softc *, int); uint32_t sc_mix_info; uint32_t sc_recsrc_info; @@ -864,6 +870,46 @@ uaudio_probe(device_t dev) return (ENXIO); } +/* + * Set Cmedia CM6206 S/PDIF settings + * Source: CM6206 Datasheet v2.3. + */ +static int +uaudio_set_spdif_cm6206(struct uaudio_softc *sc, int flags) +{ + uint8_t cmd[2][4] = { + {0x20, 0x20, 0x00, 0}, + {0x20, 0x30, 0x02, 1} + }; + int i; + + if (flags & UAUDIO_SPDIF_OUT) + cmd[1][1] = 0x00; + else + cmd[1][1] = 0x02; + + if (flags & UAUDIO_SPDIF_OUT_96K) + cmd[0][1] = 0x60; /* 96K: 3'b110 */ + + if (flags & UAUDIO_SPDIF_IN_MIX) + cmd[1][1] = 0x03; /* SPDIFMIX */ + + for (i = 0; i < 2; i++) { + if (usbd_req_set_report(sc->sc_udev, NULL, + cmd[i], sizeof(cmd[0]), + sc->sc_mixer_iface_index, UHID_OUTPUT_REPORT, 0) != 0) { + return (ENXIO); + } + } + return (0); +} + +static int +uaudio_set_spdif_dummy(struct uaudio_softc *sc, int flags) +{ + return (0); +} + static int uaudio_attach(device_t dev) { @@ -898,6 +944,12 @@ uaudio_attach(device_t dev) if (usb_test_quirk(uaa, UQ_AU_VENDOR_CLASS)) sc->sc_uq_au_vendor_class = 1; + /* set S/PDIF function */ + if (usb_test_quirk(uaa, UQ_AU_SET_SPDIF_CM6206)) + sc->sc_set_spdif_fn = uaudio_set_spdif_cm6206; + else + sc->sc_set_spdif_fn = uaudio_set_spdif_dummy; + umidi_init(dev); device_set_usb_desc(dev); @@ -1034,6 +1086,11 @@ uaudio_attach(device_t dev) /* reload all mixer settings */ uaudio_mixer_reload_all(sc); + /* enable S/PDIF output, if any */ + if (sc->sc_set_spdif_fn(sc, + UAUDIO_SPDIF_OUT | UAUDIO_SPDIF_OUT_48K) != 0) { + device_printf(dev, "Failed to enable S/PDIF at 48K\n"); + } return (0); /* success */ detach: @@ -1114,6 +1171,9 @@ uaudio_detach_sub(device_t dev) struct uaudio_softc *sc = device_get_softc(device_get_parent(dev)); int error = 0; + /* disable S/PDIF output, if any */ + (void) sc->sc_set_spdif_fn(sc, 0); + repeat: if (sc->sc_pcm_registered) { error = pcm_unregister(dev); Modified: stable/9/sys/dev/usb/quirk/usb_quirk.c ============================================================================== --- stable/9/sys/dev/usb/quirk/usb_quirk.c Tue Mar 14 15:21:41 2017 (r315249) +++ stable/9/sys/dev/usb/quirk/usb_quirk.c Tue Mar 14 15:25:49 2017 (r315250) @@ -517,6 +517,7 @@ static struct usb_quirk_entry usb_quirks /* Non-standard USB AUDIO devices */ USB_QUIRK(MAUDIO, FASTTRACKULTRA, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), USB_QUIRK(MAUDIO, FASTTRACKULTRA8R, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), + USB_QUIRK(CMEDIA, CM6206, 0x0000, 0xffff, UQ_AU_SET_SPDIF_CM6206), /* * Quirks for manufacturers which USB devices does not respond @@ -604,6 +605,7 @@ static const char *usb_quirk_str[USB_QUI [UQ_AU_VENDOR_CLASS] = "UQ_AU_VENDOR_CLASS", [UQ_SINGLE_CMD_MIDI] = "UQ_SINGLE_CMD_MIDI", [UQ_MSC_DYMO_EJECT] = "UQ_MSC_DYMO_EJECT", + [UQ_AU_SET_SPDIF_CM6206] = "UQ_AU_SET_SPDIF_CM6206", }; /*------------------------------------------------------------------------* Modified: stable/9/sys/dev/usb/quirk/usb_quirk.h ============================================================================== --- stable/9/sys/dev/usb/quirk/usb_quirk.h Tue Mar 14 15:21:41 2017 (r315249) +++ stable/9/sys/dev/usb/quirk/usb_quirk.h Tue Mar 14 15:25:49 2017 (r315250) @@ -110,6 +110,7 @@ enum { UQ_AU_VENDOR_CLASS, /* audio device uses vendor and not audio class */ UQ_SINGLE_CMD_MIDI, /* at most one command per USB packet */ UQ_MSC_DYMO_EJECT, /* ejects Dymo MSC device */ + UQ_AU_SET_SPDIF_CM6206, /* enable S/PDIF audio output */ USB_QUIRK_MAX }; Modified: stable/9/sys/dev/usb/usbdevs ============================================================================== --- stable/9/sys/dev/usb/usbdevs Tue Mar 14 15:21:41 2017 (r315249) +++ stable/9/sys/dev/usb/usbdevs Tue Mar 14 15:25:49 2017 (r315250) @@ -1438,6 +1438,9 @@ product CLIPSAL 5000CT2 0x0304 5000CT2 product CLIPSAL C5000CT2 0x0305 C5000CT2 C-Bus Touch Screen product CLIPSAL L51xx 0x0401 L51xx C-Bus Dimmer +/* C-Media products */ +product CMEDIA CM6206 0x0102 CM106 compatible sound device + /* CMOTECH products */ product CMOTECH CNU510 0x5141 CDMA Technologies USB modem product CMOTECH CNU550 0x5543 CDMA 2000 1xRTT/1xEVDO USB modem From owner-svn-src-stable-9@freebsd.org Tue Mar 14 15:30:48 2017 Return-Path: Delivered-To: svn-src-stable-9@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 3D0EED0C66F; Tue, 14 Mar 2017 15:30:48 +0000 (UTC) (envelope-from hselasky@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 17B7917E0; Tue, 14 Mar 2017 15:30:48 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2EFUlpw004214; Tue, 14 Mar 2017 15:30:47 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2EFUkKD004210; Tue, 14 Mar 2017 15:30:46 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201703141530.v2EFUkKD004210@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 14 Mar 2017 15:30:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r315253 - stable/9/sys/dev/usb/controller X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2017 15:30:48 -0000 Author: hselasky Date: Tue Mar 14 15:30:46 2017 New Revision: 315253 URL: https://svnweb.freebsd.org/changeset/base/315253 Log: MFC r312424: Fix problem with suspend and resume when using Skylake chipsets. Make sure the XHCI controller is reset after halting it. The problem is clearly a BIOS bug as the suspend and resume is failing without loading the XHCI driver. The same happens when using Linux and the XHCI driver is not loaded. Submitted by: Yanko Yankulov PR: 216261 Modified: stable/9/sys/dev/usb/controller/xhci.c stable/9/sys/dev/usb/controller/xhci.h stable/9/sys/dev/usb/controller/xhci_pci.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/dev/usb/controller/xhci.c ============================================================================== --- stable/9/sys/dev/usb/controller/xhci.c Tue Mar 14 15:28:59 2017 (r315252) +++ stable/9/sys/dev/usb/controller/xhci.c Tue Mar 14 15:30:46 2017 (r315253) @@ -341,6 +341,7 @@ xhci_start_controller(struct xhci_softc struct usb_page_search buf_res; struct xhci_hw_root *phwr; struct xhci_dev_ctx_addr *pdctxa; + usb_error_t err; uint64_t addr; uint32_t temp; uint16_t i; @@ -352,22 +353,9 @@ xhci_start_controller(struct xhci_softc sc->sc_command_ccs = 1; sc->sc_command_idx = 0; - /* Reset controller */ - XWRITE4(sc, oper, XHCI_USBCMD, XHCI_CMD_HCRST); - - for (i = 0; i != 100; i++) { - usb_pause_mtx(NULL, hz / 100); - temp = (XREAD4(sc, oper, XHCI_USBCMD) & XHCI_CMD_HCRST) | - (XREAD4(sc, oper, XHCI_USBSTS) & XHCI_STS_CNR); - if (!temp) - break; - } - - if (temp) { - device_printf(sc->sc_bus.parent, "Controller " - "reset timeout.\n"); - return (USB_ERR_IOERROR); - } + err = xhci_reset_controller(sc); + if (err) + return (err); /* set up number of device slots */ DPRINTF("CONFIG=0x%08x -> 0x%08x\n", @@ -515,6 +503,33 @@ xhci_halt_controller(struct xhci_softc * } usb_error_t +xhci_reset_controller(struct xhci_softc *sc) +{ + uint32_t temp = 0; + uint16_t i; + + DPRINTF("\n"); + + /* Reset controller */ + XWRITE4(sc, oper, XHCI_USBCMD, XHCI_CMD_HCRST); + + for (i = 0; i != 100; i++) { + usb_pause_mtx(NULL, hz / 100); + temp = (XREAD4(sc, oper, XHCI_USBCMD) & XHCI_CMD_HCRST) | + (XREAD4(sc, oper, XHCI_USBSTS) & XHCI_STS_CNR); + if (!temp) + break; + } + + if (temp) { + device_printf(sc->sc_bus.parent, "Controller " + "reset timeout.\n"); + return (USB_ERR_IOERROR); + } + return (0); +} + +usb_error_t xhci_init(struct xhci_softc *sc, device_t self, uint8_t dma32) { uint32_t temp; @@ -666,10 +681,12 @@ xhci_set_hw_power_sleep(struct usb_bus * case USB_HW_POWER_SUSPEND: DPRINTF("Stopping the XHCI\n"); xhci_halt_controller(sc); + xhci_reset_controller(sc); break; case USB_HW_POWER_SHUTDOWN: DPRINTF("Stopping the XHCI\n"); xhci_halt_controller(sc); + xhci_reset_controller(sc); break; case USB_HW_POWER_RESUME: DPRINTF("Starting the XHCI\n"); Modified: stable/9/sys/dev/usb/controller/xhci.h ============================================================================== --- stable/9/sys/dev/usb/controller/xhci.h Tue Mar 14 15:28:59 2017 (r315252) +++ stable/9/sys/dev/usb/controller/xhci.h Tue Mar 14 15:30:46 2017 (r315253) @@ -515,6 +515,7 @@ struct xhci_softc { uint8_t xhci_use_polling(void); usb_error_t xhci_halt_controller(struct xhci_softc *); +usb_error_t xhci_reset_controller(struct xhci_softc *); usb_error_t xhci_init(struct xhci_softc *, device_t, uint8_t); usb_error_t xhci_start_controller(struct xhci_softc *); void xhci_interrupt(struct xhci_softc *); Modified: stable/9/sys/dev/usb/controller/xhci_pci.c ============================================================================== --- stable/9/sys/dev/usb/controller/xhci_pci.c Tue Mar 14 15:28:59 2017 (r315252) +++ stable/9/sys/dev/usb/controller/xhci_pci.c Tue Mar 14 15:30:46 2017 (r315253) @@ -317,6 +317,7 @@ xhci_pci_detach(device_t self) usb_callout_drain(&sc->sc_callout); xhci_halt_controller(sc); + xhci_reset_controller(sc); pci_disable_busmaster(self); From owner-svn-src-stable-9@freebsd.org Tue Mar 14 15:47:18 2017 Return-Path: Delivered-To: svn-src-stable-9@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 EEC6ED0CEFE; Tue, 14 Mar 2017 15:47:18 +0000 (UTC) (envelope-from hselasky@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 BD7FFD42; Tue, 14 Mar 2017 15:47:18 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2EFlHBG012788; Tue, 14 Mar 2017 15:47:17 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2EFlHFB012787; Tue, 14 Mar 2017 15:47:17 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201703141547.v2EFlHFB012787@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 14 Mar 2017 15:47:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r315258 - stable/9/sys/ofed/drivers/infiniband/hw/mlx4 X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2017 15:47:19 -0000 Author: hselasky Date: Tue Mar 14 15:47:17 2017 New Revision: 315258 URL: https://svnweb.freebsd.org/changeset/base/315258 Log: MFC r313778: Improve code readability and fix compilation error when using clang 4.x. Found by: emaste @ Sponsored by: Mellanox Technologies Modified: stable/9/sys/ofed/drivers/infiniband/hw/mlx4/mad.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/ofed/drivers/infiniband/hw/mlx4/mad.c ============================================================================== --- stable/9/sys/ofed/drivers/infiniband/hw/mlx4/mad.c Tue Mar 14 15:44:39 2017 (r315257) +++ stable/9/sys/ofed/drivers/infiniband/hw/mlx4/mad.c Tue Mar 14 15:47:17 2017 (r315258) @@ -593,7 +593,7 @@ static int mlx4_ib_demux_mad(struct ib_d is_eth = 1; if (is_eth) { - if (!wc->wc_flags & IB_WC_GRH) { + if (!(wc->wc_flags & IB_WC_GRH)) { mlx4_ib_warn(ibdev, "RoCE grh not present.\n"); return -EINVAL; } From owner-svn-src-stable-9@freebsd.org Tue Mar 14 15:52:02 2017 Return-Path: Delivered-To: svn-src-stable-9@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 83DD6D0C4CB; Tue, 14 Mar 2017 15:52:02 +0000 (UTC) (envelope-from hselasky@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 245F41768; Tue, 14 Mar 2017 15:52:02 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2EFq1Rm016775; Tue, 14 Mar 2017 15:52:01 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2EFq1QL016774; Tue, 14 Mar 2017 15:52:01 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201703141552.v2EFq1QL016774@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 14 Mar 2017 15:52:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r315261 - stable/9/sys/kern X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2017 15:52:02 -0000 Author: hselasky Date: Tue Mar 14 15:52:01 2017 New Revision: 315261 URL: https://svnweb.freebsd.org/changeset/base/315261 Log: MFC r313941: Make sure the thread constructor and destructor eventhandlers are called for all threads belonging to a procedure. Currently the first thread in a procedure is kept around as an optimisation step and is never freed. Because the first thread in a procedure is never freed nor allocated, its destructor and constructor callbacks are never called which means per thread structures allocated by dtrace and the Linux emulation layers for example, might be present for threads which don't need these structures. This patch adds a thread construction and destruction call for the first thread in a procedure. Tested: dtrace, linux emulation Reviewed by: kib @ Sponsored by: Mellanox Technologies Modified: stable/9/sys/kern/kern_proc.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/kern_proc.c ============================================================================== --- stable/9/sys/kern/kern_proc.c Tue Mar 14 15:50:36 2017 (r315260) +++ stable/9/sys/kern/kern_proc.c Tue Mar 14 15:52:01 2017 (r315261) @@ -178,11 +178,17 @@ static int proc_ctor(void *mem, int size, void *arg, int flags) { struct proc *p; + struct thread *td; p = (struct proc *)mem; SDT_PROBE4(proc, kernel, ctor , entry, p, size, arg, flags); EVENTHANDLER_INVOKE(process_ctor, p); SDT_PROBE4(proc, kernel, ctor , return, p, size, arg, flags); + td = FIRST_THREAD_IN_PROC(p); + if (td != NULL) { + /* Make sure all thread constructors are executed */ + EVENTHANDLER_INVOKE(thread_ctor, td); + } return (0); } @@ -207,6 +213,9 @@ proc_dtor(void *mem, int size, void *arg #endif /* Free all OSD associated to this thread. */ osd_thread_exit(td); + + /* Make sure all thread destructors are executed */ + EVENTHANDLER_INVOKE(thread_dtor, td); } EVENTHANDLER_INVOKE(process_dtor, p); if (p->p_ksi != NULL) From owner-svn-src-stable-9@freebsd.org Tue Mar 14 15:57:23 2017 Return-Path: Delivered-To: svn-src-stable-9@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 32A34D0C7CB; Tue, 14 Mar 2017 15:57:23 +0000 (UTC) (envelope-from hselasky@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 E801114D; Tue, 14 Mar 2017 15:57:22 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2EFvMbT017711; Tue, 14 Mar 2017 15:57:22 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2EFvMeR017710; Tue, 14 Mar 2017 15:57:22 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201703141557.v2EFvMeR017710@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 14 Mar 2017 15:57:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r315265 - stable/9/sys/dev/acpica X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2017 15:57:23 -0000 Author: hselasky Date: Tue Mar 14 15:57:21 2017 New Revision: 315265 URL: https://svnweb.freebsd.org/changeset/base/315265 Log: MFC r314328: Fix startup race initialising ACPI CM battery structures on MacBookPro. During acpi_cmbat_attach() the acpi_cmbat_init_battery() notification handler is registered. It has been observed this notification handler can be called instantly, before the attach routine has returned. In the notification handler there is a call to device_is_attached() which returns false. Because the softc is set we know an attach is in progress and the fix is simply to wait and try again in this case. Reviewed by: avg @ Modified: stable/9/sys/dev/acpica/acpi_cmbat.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/dev/acpica/acpi_cmbat.c ============================================================================== --- stable/9/sys/dev/acpica/acpi_cmbat.c Tue Mar 14 15:56:19 2017 (r315264) +++ stable/9/sys/dev/acpica/acpi_cmbat.c Tue Mar 14 15:57:21 2017 (r315265) @@ -164,6 +164,16 @@ acpi_cmbat_detach(device_t dev) handle = acpi_get_handle(dev); AcpiRemoveNotifyHandler(handle, ACPI_ALL_NOTIFY, acpi_cmbat_notify_handler); acpi_battery_remove(dev); + + /* + * Force any pending notification handler calls to complete by + * requesting cmbat serialisation while freeing and clearing the + * softc pointer: + */ + ACPI_SERIAL_BEGIN(cmbat); + device_set_softc(dev, NULL); + ACPI_SERIAL_END(cmbat); + return (0); } @@ -436,7 +446,6 @@ acpi_cmbat_init_battery(void *arg) device_t dev; dev = (device_t)arg; - sc = device_get_softc(dev); ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery initialization start\n"); @@ -446,18 +455,33 @@ acpi_cmbat_init_battery(void *arg) * to wait a while. */ for (retry = 0; retry < ACPI_CMBAT_RETRY_MAX; retry++, AcpiOsSleep(10000)) { - /* batteries on DOCK can be ejected w/ DOCK during retrying */ - if (!device_is_attached(dev)) + /* + * Batteries on DOCK can be ejected w/ DOCK during retrying. + * + * If there is a valid softc pointer the device may be in + * attaching, attached or detaching state. If the state is + * different from attached retry getting the device state + * until it becomes stable. This solves a race if the ACPI + * notification handler is called during attach, because + * device_is_attached() doesn't return non-zero until after + * the attach code has been executed. + */ + ACPI_SERIAL_BEGIN(cmbat); + sc = device_get_softc(dev); + if (sc == NULL) { + ACPI_SERIAL_END(cmbat); return; + } - if (!acpi_BatteryIsPresent(dev)) + if (!acpi_BatteryIsPresent(dev) || !device_is_attached(dev)) { + ACPI_SERIAL_END(cmbat); continue; + } /* * Only query the battery if this is the first try or the specific * type of info is still invalid. */ - ACPI_SERIAL_BEGIN(cmbat); if (retry == 0 || !acpi_battery_bst_valid(&sc->bst)) { timespecclear(&sc->bst_lastupdated); acpi_cmbat_get_bst(dev); From owner-svn-src-stable-9@freebsd.org Tue Mar 14 16:01:38 2017 Return-Path: Delivered-To: svn-src-stable-9@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 07D32D0CB90; Tue, 14 Mar 2017 16:01:38 +0000 (UTC) (envelope-from hselasky@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 B03CCCB8; Tue, 14 Mar 2017 16:01:37 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2EG1ac3021944; Tue, 14 Mar 2017 16:01:36 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2EG1ape021942; Tue, 14 Mar 2017 16:01:36 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201703141601.v2EG1ape021942@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 14 Mar 2017 16:01:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r315269 - in stable/9/sys: kern sys X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2017 16:01:38 -0000 Author: hselasky Date: Tue Mar 14 16:01:36 2017 New Revision: 315269 URL: https://svnweb.freebsd.org/changeset/base/315269 Log: MFC r314553: Implement taskqueue_poll_is_busy() for use by the LinuxKPI. Refer to comment above function for a detailed description. Discussed with: kib @ Sponsored by: Mellanox Technologies Modified: stable/9/sys/kern/subr_taskqueue.c stable/9/sys/sys/taskqueue.h Directory Properties: stable/9/sys/ (props changed) stable/9/sys/sys/ (props changed) Modified: stable/9/sys/kern/subr_taskqueue.c ============================================================================== --- stable/9/sys/kern/subr_taskqueue.c Tue Mar 14 16:00:33 2017 (r315268) +++ stable/9/sys/kern/subr_taskqueue.c Tue Mar 14 16:01:36 2017 (r315269) @@ -356,6 +356,23 @@ task_is_running(struct taskqueue *queue, return (0); } +/* + * Only use this function in single threaded contexts. It returns + * non-zero if the given task is either pending or running. Else the + * task is idle and can be queued again or freed. + */ +int +taskqueue_poll_is_busy(struct taskqueue *queue, struct task *task) +{ + int retval; + + TQ_LOCK(queue); + retval = task->ta_pending > 0 || task_is_running(queue, task); + TQ_UNLOCK(queue); + + return (retval); +} + static int taskqueue_cancel_locked(struct taskqueue *queue, struct task *task, u_int *pendp) Modified: stable/9/sys/sys/taskqueue.h ============================================================================== --- stable/9/sys/sys/taskqueue.h Tue Mar 14 16:00:33 2017 (r315268) +++ stable/9/sys/sys/taskqueue.h Tue Mar 14 16:01:36 2017 (r315269) @@ -64,6 +64,7 @@ int taskqueue_start_threads(struct taskq 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_poll_is_busy(struct taskqueue *queue, struct task *task); int taskqueue_cancel(struct taskqueue *queue, struct task *task, u_int *pendp); int taskqueue_cancel_timeout(struct taskqueue *queue,