From owner-svn-src-stable-10@freebsd.org Sun Nov 6 13:35:21 2016 Return-Path: Delivered-To: svn-src-stable-10@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 D4B62C33FCF; Sun, 6 Nov 2016 13:35:21 +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 A3D5C16A; Sun, 6 Nov 2016 13:35:21 +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 uA6DZKle071195; Sun, 6 Nov 2016 13:35:20 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA6DZKSB071194; Sun, 6 Nov 2016 13:35:20 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611061335.uA6DZKSB071194@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 6 Nov 2016 13:35:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308364 - stable/10/sys/vm X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Nov 2016 13:35:21 -0000 Author: kib Date: Sun Nov 6 13:35:20 2016 New Revision: 308364 URL: https://svnweb.freebsd.org/changeset/base/308364 Log: MFC r308109: Remove vnode_locked label and goto. Modified: stable/10/sys/vm/vm_fault.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/vm/vm_fault.c ============================================================================== --- stable/10/sys/vm/vm_fault.c Sun Nov 6 12:56:07 2016 (r308363) +++ stable/10/sys/vm/vm_fault.c Sun Nov 6 13:35:20 2016 (r308364) @@ -627,10 +627,8 @@ readrest: */ unlock_map(&fs); - if (fs.object->type == OBJT_VNODE) { - vp = fs.object->handle; - if (vp == fs.vp) - goto vnode_locked; + if (fs.object->type == OBJT_VNODE && + (vp = fs.object->handle) != fs.vp) { unlock_vp(&fs); locked = VOP_ISLOCKED(vp); @@ -653,7 +651,6 @@ readrest: } fs.vp = vp; } -vnode_locked: KASSERT(fs.vp == NULL || !fs.map->system_map, ("vm_fault: vnode-backed object mapped by system map")); From owner-svn-src-stable-10@freebsd.org Sun Nov 6 13:37:34 2016 Return-Path: Delivered-To: svn-src-stable-10@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 C0987C320FE; Sun, 6 Nov 2016 13:37:34 +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 8FC3A324; Sun, 6 Nov 2016 13:37:34 +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 uA6DbXk1071346; Sun, 6 Nov 2016 13:37:33 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA6DbXg4071345; Sun, 6 Nov 2016 13:37:33 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611061337.uA6DbXg4071345@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 6 Nov 2016 13:37:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308365 - stable/10/sys/vm X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Nov 2016 13:37:34 -0000 Author: kib Date: Sun Nov 6 13:37:33 2016 New Revision: 308365 URL: https://svnweb.freebsd.org/changeset/base/308365 Log: MFC r308113: Remove vm_pager_has_page() declaration. Modified: stable/10/sys/vm/vm_pager.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/vm/vm_pager.h ============================================================================== --- stable/10/sys/vm/vm_pager.h Sun Nov 6 13:35:20 2016 (r308364) +++ stable/10/sys/vm/vm_pager.h Sun Nov 6 13:37:33 2016 (r308365) @@ -103,7 +103,6 @@ vm_object_t vm_pager_allocate(objtype_t, void vm_pager_bufferinit(void); void vm_pager_deallocate(vm_object_t); static __inline int vm_pager_get_pages(vm_object_t, vm_page_t *, int, int); -static __inline boolean_t vm_pager_has_page(vm_object_t, vm_pindex_t, int *, int *); void vm_pager_init(void); vm_object_t vm_pager_object_lookup(struct pagerlst *, void *); From owner-svn-src-stable-10@freebsd.org Sun Nov 6 13:40:05 2016 Return-Path: Delivered-To: svn-src-stable-10@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 1ECBEC3223A; Sun, 6 Nov 2016 13:40: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 E2CC76CF; Sun, 6 Nov 2016 13:40:04 +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 uA6De4pR071514; Sun, 6 Nov 2016 13:40:04 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA6De4Vh071513; Sun, 6 Nov 2016 13:40:04 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611061340.uA6De4Vh071513@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 6 Nov 2016 13:40:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308366 - stable/10/sys/vm X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Nov 2016 13:40:05 -0000 Author: kib Date: Sun Nov 6 13:40:03 2016 New Revision: 308366 URL: https://svnweb.freebsd.org/changeset/base/308366 Log: MFC r308114: Change remained internal uses of boolean_t to bool in vm/vm_fault.c. Modified: stable/10/sys/vm/vm_fault.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/vm/vm_fault.c ============================================================================== --- stable/10/sys/vm/vm_fault.c Sun Nov 6 13:37:33 2016 (r308365) +++ stable/10/sys/vm/vm_fault.c Sun Nov 6 13:40:03 2016 (r308366) @@ -184,9 +184,9 @@ unlock_and_deallocate(struct faultstate static void vm_fault_dirty(vm_map_entry_t entry, vm_page_t m, vm_prot_t prot, - vm_prot_t fault_type, int fault_flags, boolean_t set_wd) + vm_prot_t fault_type, int fault_flags, bool set_wd) { - boolean_t need_dirty; + bool need_dirty; if (((prot & VM_PROT_WRITE) == 0 && (fault_flags & VM_FAULT_DIRTY) == 0) || @@ -397,7 +397,7 @@ RetryFault:; vm_page_unlock(m); } vm_fault_dirty(fs.entry, m, prot, fault_type, fault_flags, - FALSE); + false); VM_OBJECT_RUNLOCK(fs.first_object); if (!wired) vm_fault_prefault(&fs, vaddr, 0, 0); @@ -982,7 +982,7 @@ readrest: if (hardfault) fs.entry->next_read = fs.pindex + faultcount - reqpage; - vm_fault_dirty(fs.entry, fs.m, prot, fault_type, fault_flags, TRUE); + vm_fault_dirty(fs.entry, fs.m, prot, fault_type, fault_flags, true); vm_page_assert_xbusied(fs.m); /* From owner-svn-src-stable-10@freebsd.org Sun Nov 6 13:50:55 2016 Return-Path: Delivered-To: svn-src-stable-10@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 545DAC3267E; Sun, 6 Nov 2016 13:50:55 +0000 (UTC) (envelope-from avos@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 0CB6BCE4; Sun, 6 Nov 2016 13:50:54 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uA6DosAh075381; Sun, 6 Nov 2016 13:50:54 GMT (envelope-from avos@FreeBSD.org) Received: (from avos@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA6DosHS075380; Sun, 6 Nov 2016 13:50:54 GMT (envelope-from avos@FreeBSD.org) Message-Id: <201611061350.uA6DosHS075380@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avos set sender to avos@FreeBSD.org using -f From: Andriy Voskoboinyk Date: Sun, 6 Nov 2016 13:50:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308367 - stable/10/sys/dev/bwi X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Nov 2016 13:50:55 -0000 Author: avos Date: Sun Nov 6 13:50:54 2016 New Revision: 308367 URL: https://svnweb.freebsd.org/changeset/base/308367 Log: MFC r283636: - Don't request BUS_DMA_ALLOCNOW for dma tags, that requires enormous amount of memory. - Don't request segsize of BUS_SPACE_MAXSIZE_32BIT, when maxsize is MCLBYTES. With this change bwi_attach() can succeed on i386. PR: 214235 Submitted by: scottl Modified: stable/10/sys/dev/bwi/if_bwi.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/bwi/if_bwi.c ============================================================================== --- stable/10/sys/dev/bwi/if_bwi.c Sun Nov 6 13:40:03 2016 (r308366) +++ stable/10/sys/dev/bwi/if_bwi.c Sun Nov 6 13:50:54 2016 (r308367) @@ -1918,7 +1918,7 @@ bwi_dma_alloc(struct bwi_softc *sc) BUS_SPACE_MAXSIZE, /* maxsize */ BUS_SPACE_UNRESTRICTED, /* nsegments */ BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ - BUS_DMA_ALLOCNOW, /* flags */ + 0, /* flags */ NULL, NULL, /* lockfunc, lockarg */ &sc->sc_parent_dtag); if (error) { @@ -1939,7 +1939,7 @@ bwi_dma_alloc(struct bwi_softc *sc) tx_ring_sz, 1, BUS_SPACE_MAXSIZE_32BIT, - BUS_DMA_ALLOCNOW, + 0, NULL, NULL, &sc->sc_txring_dtag); if (error) { @@ -1969,7 +1969,7 @@ bwi_dma_alloc(struct bwi_softc *sc) rx_ring_sz, 1, BUS_SPACE_MAXSIZE_32BIT, - BUS_DMA_ALLOCNOW, + 0, NULL, NULL, &sc->sc_rxring_dtag); if (error) { @@ -2094,7 +2094,7 @@ bwi_dma_txstats_alloc(struct bwi_softc * dma_size, 1, BUS_SPACE_MAXSIZE_32BIT, - BUS_DMA_ALLOCNOW, + 0, NULL, NULL, &st->stats_ring_dtag); if (error) { @@ -2142,7 +2142,7 @@ bwi_dma_txstats_alloc(struct bwi_softc * dma_size, 1, BUS_SPACE_MAXSIZE_32BIT, - BUS_DMA_ALLOCNOW, + 0, NULL, NULL, &st->stats_dtag); if (error) { @@ -2224,7 +2224,7 @@ bwi_dma_mbuf_create(struct bwi_softc *sc NULL, NULL, MCLBYTES, 1, - BUS_SPACE_MAXSIZE_32BIT, + MCLBYTES, BUS_DMA_ALLOCNOW, NULL, NULL, &sc->sc_buf_dtag); From owner-svn-src-stable-10@freebsd.org Sun Nov 6 13:51:51 2016 Return-Path: Delivered-To: svn-src-stable-10@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 DA554C3288C; Sun, 6 Nov 2016 13:51:51 +0000 (UTC) (envelope-from avg@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 A58D7A1; Sun, 6 Nov 2016 13:51:51 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uA6DpoIe076150; Sun, 6 Nov 2016 13:51:50 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA6DpoOW076149; Sun, 6 Nov 2016 13:51:50 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201611061351.uA6DpoOW076149@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Sun, 6 Nov 2016 13:51:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308369 - stable/10/sys/dev/acpi_support X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Nov 2016 13:51:52 -0000 Author: avg Date: Sun Nov 6 13:51:50 2016 New Revision: 308369 URL: https://svnweb.freebsd.org/changeset/base/308369 Log: MFC r307348: aibs / atk0110: add support for querying sensors via GGRP and GITM Modified: stable/10/sys/dev/acpi_support/atk0110.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/acpi_support/atk0110.c ============================================================================== --- stable/10/sys/dev/acpi_support/atk0110.c Sun Nov 6 13:50:55 2016 (r308368) +++ stable/10/sys/dev/acpi_support/atk0110.c Sun Nov 6 13:51:50 2016 (r308369) @@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -51,18 +52,23 @@ ACPI_SERIAL_DECL(aibs, "aibs"); #define AIBS_MORE_SENSORS #define AIBS_VERBOSE -enum aibs_type { - AIBS_VOLT, - AIBS_TEMP, - AIBS_FAN -}; +#define AIBS_GROUP_SENSORS 0x06 + +#define AIBS_SENS_TYPE(x) (((x) >> 16) & 0xff) +#define AIBS_SENS_TYPE_VOLT 2 +#define AIBS_SENS_TYPE_TEMP 3 +#define AIBS_SENS_TYPE_FAN 4 + +#define AIBS_SENS_TYPE_VOLT_NAME "volt" +#define AIBS_SENS_TYPE_VOLT_TEMP "temp" +#define AIBS_SENS_TYPE_VOLT_FAN "fan" struct aibs_sensor { ACPI_INTEGER v; ACPI_INTEGER i; ACPI_INTEGER l; ACPI_INTEGER h; - enum aibs_type t; + int t; }; struct aibs_softc { @@ -72,14 +78,23 @@ struct aibs_softc { struct aibs_sensor *sc_asens_volt; struct aibs_sensor *sc_asens_temp; struct aibs_sensor *sc_asens_fan; + struct aibs_sensor *sc_asens_all; + + struct sysctl_oid *sc_volt_sysctl; + struct sysctl_oid *sc_temp_sysctl; + struct sysctl_oid *sc_fan_sysctl; + + bool sc_ggrp_method; }; static int aibs_probe(device_t); static int aibs_attach(device_t); static int aibs_detach(device_t); static int aibs_sysctl(SYSCTL_HANDLER_ARGS); +static int aibs_sysctl_ggrp(SYSCTL_HANDLER_ARGS); -static void aibs_attach_sif(struct aibs_softc *, enum aibs_type); +static int aibs_attach_ggrp(struct aibs_softc *); +static int aibs_attach_sif(struct aibs_softc *, int); static device_method_t aibs_methods[] = { DEVMETHOD(device_probe, aibs_probe), @@ -109,54 +124,240 @@ aibs_probe(device_t dev) { if (acpi_disabled("aibs") || ACPI_ID_PROBE(device_get_parent(dev), dev, aibs_hids) == NULL) - return ENXIO; + return (ENXIO); device_set_desc(dev, "ASUSTeK AI Booster (ACPI ASOC ATK0110)"); - return 0; + return (0); } static int aibs_attach(device_t dev) { struct aibs_softc *sc = device_get_softc(dev); + int err; sc->sc_dev = dev; sc->sc_ah = acpi_get_handle(dev); - aibs_attach_sif(sc, AIBS_VOLT); - aibs_attach_sif(sc, AIBS_TEMP); - aibs_attach_sif(sc, AIBS_FAN); + sc->sc_ggrp_method = false; + err = aibs_attach_sif(sc, AIBS_SENS_TYPE_VOLT); + if (err == 0) + err = aibs_attach_sif(sc, AIBS_SENS_TYPE_TEMP); + if (err == 0) + err = aibs_attach_sif(sc, AIBS_SENS_TYPE_FAN); + + if (err == 0) + return (0); + + /* Clean up whatever was allocated earlier. */ + if (sc->sc_volt_sysctl != NULL) + sysctl_remove_oid(sc->sc_volt_sysctl, true, true); + if (sc->sc_temp_sysctl != NULL) + sysctl_remove_oid(sc->sc_temp_sysctl, true, true); + if (sc->sc_fan_sysctl != NULL) + sysctl_remove_oid(sc->sc_fan_sysctl, true, true); + aibs_detach(dev); + + sc->sc_ggrp_method = true; + err = aibs_attach_ggrp(sc); + return (err); +} - return 0; +static int +aibs_add_sensor(struct aibs_softc *sc, ACPI_OBJECT *o, + struct aibs_sensor* sensor, const char ** descr) +{ + int off; + + /* + * Packages for the old and new methods are quite + * similar except that the new package has two + * new (unknown / unused) fields after the name field. + */ + if (sc->sc_ggrp_method) + off = 4; + else + off = 2; + + if (o->Type != ACPI_TYPE_PACKAGE) { + device_printf(sc->sc_dev, + "sensor object is not a package: %i type\n", + o->Type); + return (ENXIO); + } + if (o[0].Package.Count != (off + 3) || + o->Package.Elements[0].Type != ACPI_TYPE_INTEGER || + o->Package.Elements[1].Type != ACPI_TYPE_STRING || + o->Package.Elements[off].Type != ACPI_TYPE_INTEGER || + o->Package.Elements[off + 1].Type != ACPI_TYPE_INTEGER || + o->Package.Elements[off + 2].Type != ACPI_TYPE_INTEGER) { + device_printf(sc->sc_dev, "unexpected package content\n"); + return (ENXIO); + } + + sensor->i = o->Package.Elements[0].Integer.Value; + *descr = o->Package.Elements[1].String.Pointer; + sensor->l = o->Package.Elements[off].Integer.Value; + sensor->h = o->Package.Elements[off + 1].Integer.Value; + /* For the new method the second value is a range size. */ + if (sc->sc_ggrp_method) + sensor->h += sensor->l; + sensor->t = AIBS_SENS_TYPE(sensor->i); + + switch (sensor->t) { + case AIBS_SENS_TYPE_VOLT: + case AIBS_SENS_TYPE_TEMP: + case AIBS_SENS_TYPE_FAN: + return (0); + default: + device_printf(sc->sc_dev, "unknown sensor type 0x%x", + sensor->t); + return (ENXIO); + } } static void -aibs_attach_sif(struct aibs_softc *sc, enum aibs_type st) +aibs_sensor_added(struct aibs_softc *sc, struct sysctl_oid *so, + const char *type_name, int idx, struct aibs_sensor *sensor, + const char *descr) +{ + char sysctl_name[8]; + + snprintf(sysctl_name, sizeof(sysctl_name), "%i", idx); +#ifdef AIBS_VERBOSE + device_printf(sc->sc_dev, "%c%i: 0x%08jx %20s %5jd / %5jd\n", + type_name[0], idx, + (uintmax_t)sensor->i, descr, (intmax_t)sensor->l, + (intmax_t)sensor->h); +#endif + SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->sc_dev), + SYSCTL_CHILDREN(so), idx, sysctl_name, + CTLTYPE_INT | CTLFLAG_RD, sc, (uintptr_t)sensor, + sc->sc_ggrp_method ? aibs_sysctl_ggrp : aibs_sysctl, + sensor->t == AIBS_SENS_TYPE_TEMP ? "IK" : "I", descr); +} + +static int +aibs_attach_ggrp(struct aibs_softc *sc) +{ + ACPI_STATUS s; + ACPI_BUFFER buf; + ACPI_HANDLE h; + ACPI_OBJECT id; + ACPI_OBJECT *bp; + ACPI_OBJECT_LIST arg; + int i; + int t, v, f; + int err; + int *s_idx; + const char *name; + const char *descr; + struct aibs_sensor *sensor; + struct sysctl_oid **so; + + /* First see if GITM is available. */ + s = AcpiGetHandle(sc->sc_ah, "GITM", &h); + if (ACPI_FAILURE(s)) { + if (bootverbose) + device_printf(sc->sc_dev, "GITM not found\n"); + return (ENXIO); + } + + /* + * Now call GGRP with the appropriate argument to list sensors. + * The method lists different groups of entities depending on + * the argument. + */ + id.Integer.Value = AIBS_GROUP_SENSORS; + id.Type = ACPI_TYPE_INTEGER; + arg.Count = 1; + arg.Pointer = &id; + buf.Length = ACPI_ALLOCATE_BUFFER; + buf.Pointer = NULL; + s = AcpiEvaluateObjectTyped(sc->sc_ah, "GGRP", &arg, &buf, + ACPI_TYPE_PACKAGE); + if (ACPI_FAILURE(s)) { + device_printf(sc->sc_dev, "GGRP not found\n"); + return (ENXIO); + } + + bp = buf.Pointer; + sc->sc_asens_all = malloc(sizeof(*sc->sc_asens_all) * bp->Package.Count, + M_DEVBUF, M_WAITOK | M_ZERO); + v = t = f = 0; + for (i = 0; i < bp->Package.Count; i++) { + sensor = &sc->sc_asens_all[i]; + err = aibs_add_sensor(sc, &bp->Package.Elements[i], sensor, + &descr); + if (err != 0) + continue; + + switch (sensor->t) { + case AIBS_SENS_TYPE_VOLT: + name = "volt"; + so = &sc->sc_volt_sysctl; + s_idx = &v; + break; + case AIBS_SENS_TYPE_TEMP: + name = "temp"; + so = &sc->sc_temp_sysctl; + s_idx = &t; + break; + case AIBS_SENS_TYPE_FAN: + name = "fan"; + so = &sc->sc_fan_sysctl; + s_idx = &f; + break; + default: + panic("add_sensor succeeded for unknown sensor type %d", + sensor->t); + } + + if (*so == NULL) { + /* sysctl subtree for sensors of this type */ + *so = SYSCTL_ADD_NODE(device_get_sysctl_ctx(sc->sc_dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(sc->sc_dev)), + sensor->t, name, CTLFLAG_RD, NULL, NULL); + } + aibs_sensor_added(sc, *so, name, *s_idx, sensor, descr); + *s_idx += 1; + } + + AcpiOsFree(buf.Pointer); + return (0); +} + +static int +aibs_attach_sif(struct aibs_softc *sc, int st) { + char name[] = "?SIF"; ACPI_STATUS s; ACPI_BUFFER b; ACPI_OBJECT *bp, *o; - int i, n; const char *node; - char name[] = "?SIF"; struct aibs_sensor *as; - struct sysctl_oid *so; + struct sysctl_oid **so; + int i, n; + int err; switch (st) { - case AIBS_VOLT: + case AIBS_SENS_TYPE_VOLT: node = "volt"; name[0] = 'V'; + so = &sc->sc_volt_sysctl; break; - case AIBS_TEMP: + case AIBS_SENS_TYPE_TEMP: node = "temp"; name[0] = 'T'; + so = &sc->sc_temp_sysctl; break; - case AIBS_FAN: + case AIBS_SENS_TYPE_FAN: node = "fan"; name[0] = 'F'; + so = &sc->sc_fan_sysctl; break; default: - return; + panic("Unsupported sensor type %d", st); } b.Length = ACPI_ALLOCATE_BUFFER; @@ -164,7 +365,7 @@ aibs_attach_sif(struct aibs_softc *sc, e ACPI_TYPE_PACKAGE); if (ACPI_FAILURE(s)) { device_printf(sc->sc_dev, "%s not found\n", name); - return; + return (ENXIO); } bp = b.Pointer; @@ -172,14 +373,14 @@ aibs_attach_sif(struct aibs_softc *sc, e if (o[0].Type != ACPI_TYPE_INTEGER) { device_printf(sc->sc_dev, "%s[0]: invalid type\n", name); AcpiOsFree(b.Pointer); - return; + return (ENXIO); } n = o[0].Integer.Value; if (bp->Package.Count - 1 < n) { device_printf(sc->sc_dev, "%s: invalid package\n", name); AcpiOsFree(b.Pointer); - return; + return (ENXIO); } else if (bp->Package.Count - 1 > n) { int on = n; @@ -193,76 +394,37 @@ aibs_attach_sif(struct aibs_softc *sc, e device_printf(sc->sc_dev, "%s: no members in the package\n", name); AcpiOsFree(b.Pointer); - return; + return (ENXIO); } - as = malloc(sizeof(*as) * n, M_DEVBUF, M_NOWAIT | M_ZERO); - if (as == NULL) { - device_printf(sc->sc_dev, "%s: malloc fail\n", name); - AcpiOsFree(b.Pointer); - return; - } + as = malloc(sizeof(*as) * n, M_DEVBUF, M_WAITOK | M_ZERO); switch (st) { - case AIBS_VOLT: + case AIBS_SENS_TYPE_VOLT: sc->sc_asens_volt = as; break; - case AIBS_TEMP: + case AIBS_SENS_TYPE_TEMP: sc->sc_asens_temp = as; break; - case AIBS_FAN: + case AIBS_SENS_TYPE_FAN: sc->sc_asens_fan = as; break; } /* sysctl subtree for sensors of this type */ - so = SYSCTL_ADD_NODE(device_get_sysctl_ctx(sc->sc_dev), + *so = SYSCTL_ADD_NODE(device_get_sysctl_ctx(sc->sc_dev), SYSCTL_CHILDREN(device_get_sysctl_tree(sc->sc_dev)), st, node, CTLFLAG_RD, NULL, NULL); for (i = 0, o++; i < n; i++, o++) { - ACPI_OBJECT *oi; - char si[3]; - const char *desc; - - /* acpica5 automatically evaluates the referenced package */ - if (o[0].Type != ACPI_TYPE_PACKAGE) { - device_printf(sc->sc_dev, - "%s: %i: not a package: %i type\n", - name, i, o[0].Type); - continue; - } - oi = o[0].Package.Elements; - if (o[0].Package.Count != 5 || - oi[0].Type != ACPI_TYPE_INTEGER || - oi[1].Type != ACPI_TYPE_STRING || - oi[2].Type != ACPI_TYPE_INTEGER || - oi[3].Type != ACPI_TYPE_INTEGER || - oi[4].Type != ACPI_TYPE_INTEGER) { - device_printf(sc->sc_dev, - "%s: %i: invalid package\n", - name, i); - continue; - } - as[i].i = oi[0].Integer.Value; - desc = oi[1].String.Pointer; - as[i].l = oi[2].Integer.Value; - as[i].h = oi[3].Integer.Value; - as[i].t = st; -#ifdef AIBS_VERBOSE - device_printf(sc->sc_dev, "%c%i: " - "0x%08"PRIx64" %20s %5"PRIi64" / %5"PRIi64" " - "0x%"PRIx64"\n", - name[0], i, - (uint64_t)as[i].i, desc, (int64_t)as[i].l, - (int64_t)as[i].h, (uint64_t)oi[4].Integer.Value); -#endif - snprintf(si, sizeof(si), "%i", i); - SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->sc_dev), - SYSCTL_CHILDREN(so), i, si, CTLTYPE_INT | CTLFLAG_RD, - sc, st, aibs_sysctl, st == AIBS_TEMP ? "IK" : "I", desc); + const char *descr; + + err = aibs_add_sensor(sc, o, &as[i], &descr); + if (err == 0) + aibs_sensor_added(sc, *so, node, i, &as[i], descr); } AcpiOsFree(b.Pointer); + return (0); } static int @@ -276,7 +438,9 @@ aibs_detach(device_t dev) free(sc->sc_asens_temp, M_DEVBUF); if (sc->sc_asens_fan != NULL) free(sc->sc_asens_fan, M_DEVBUF); - return 0; + if (sc->sc_asens_all != NULL) + free(sc->sc_asens_all, M_DEVBUF); + return (0); } #ifdef AIBS_VERBOSE @@ -289,39 +453,33 @@ static int aibs_sysctl(SYSCTL_HANDLER_ARGS) { struct aibs_softc *sc = arg1; - enum aibs_type st = arg2; + struct aibs_sensor *sensor = (void *)arg2; int i = oidp->oid_number; ACPI_STATUS rs; ACPI_OBJECT p, *bp; ACPI_OBJECT_LIST mp; ACPI_BUFFER b; char *name; - struct aibs_sensor *as; ACPI_INTEGER v, l, h; int so[3]; - switch (st) { - case AIBS_VOLT: + switch (sensor->t) { + case AIBS_SENS_TYPE_VOLT: name = "RVLT"; - as = sc->sc_asens_volt; break; - case AIBS_TEMP: + case AIBS_SENS_TYPE_TEMP: name = "RTMP"; - as = sc->sc_asens_temp; break; - case AIBS_FAN: + case AIBS_SENS_TYPE_FAN: name = "RFAN"; - as = sc->sc_asens_fan; break; default: - return ENOENT; + return (ENOENT); } - if (as == NULL) - return ENOENT; - l = as[i].l; - h = as[i].h; + l = sensor->l; + h = sensor->h; p.Type = ACPI_TYPE_INTEGER; - p.Integer.Value = as[i].i; + p.Integer.Value = sensor->i; mp.Count = 1; mp.Pointer = &p; b.Length = ACPI_ALLOCATE_BUFFER; @@ -333,26 +491,91 @@ aibs_sysctl(SYSCTL_HANDLER_ARGS) "%s: %i: evaluation failed\n", name, i); ACPI_SERIAL_END(aibs); - return EIO; + return (EIO); } bp = b.Pointer; v = bp->Integer.Value; AcpiOsFree(b.Pointer); ACPI_SERIAL_END(aibs); - switch (st) { - case AIBS_VOLT: + switch (sensor->t) { + case AIBS_SENS_TYPE_VOLT: break; - case AIBS_TEMP: + case AIBS_SENS_TYPE_TEMP: v += 2732; l += 2732; h += 2732; break; - case AIBS_FAN: + case AIBS_SENS_TYPE_FAN: + break; + } + so[0] = v; + so[1] = l; + so[2] = h; + return (sysctl_handle_opaque(oidp, &so, sizeof(so), req)); +} + +static int +aibs_sysctl_ggrp(SYSCTL_HANDLER_ARGS) +{ + struct aibs_softc *sc = arg1; + struct aibs_sensor *sensor = (void *)arg2; + ACPI_STATUS rs; + ACPI_OBJECT p, *bp; + ACPI_OBJECT_LIST arg; + ACPI_BUFFER buf; + ACPI_INTEGER v, l, h; + int so[3]; + uint32_t *ret; + uint32_t cmd[3]; + + cmd[0] = sensor->i; + cmd[1] = 0; + cmd[2] = 0; + p.Type = ACPI_TYPE_BUFFER; + p.Buffer.Pointer = (void *)cmd; + p.Buffer.Length = sizeof(cmd); + arg.Count = 1; + arg.Pointer = &p; + buf.Pointer = NULL; + buf.Length = ACPI_ALLOCATE_BUFFER; + ACPI_SERIAL_BEGIN(aibs); + rs = AcpiEvaluateObjectTyped(sc->sc_ah, "GITM", &arg, &buf, + ACPI_TYPE_BUFFER); + ACPI_SERIAL_END(aibs); + if (ACPI_FAILURE(rs)) { + device_printf(sc->sc_dev, "GITM evaluation failed\n"); + return (EIO); + } + bp = buf.Pointer; + if (bp->Buffer.Length < 8) { + device_printf(sc->sc_dev, "GITM returned short buffer\n"); + return (EIO); + } + ret = (uint32_t *)bp->Buffer.Pointer; + if (ret[0] == 0) { + device_printf(sc->sc_dev, "GITM returned error status\n"); + return (EINVAL); + } + v = ret[1]; + AcpiOsFree(buf.Pointer); + + l = sensor->l; + h = sensor->h; + + switch (sensor->t) { + case AIBS_SENS_TYPE_VOLT: + break; + case AIBS_SENS_TYPE_TEMP: + v += 2731; + l += 2731; + h += 2731; + break; + case AIBS_SENS_TYPE_FAN: break; } so[0] = v; so[1] = l; so[2] = h; - return sysctl_handle_opaque(oidp, &so, sizeof(so), req); + return (sysctl_handle_opaque(oidp, &so, sizeof(so), req)); } From owner-svn-src-stable-10@freebsd.org Sun Nov 6 13:56:36 2016 Return-Path: Delivered-To: svn-src-stable-10@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 F3CE0C32B7B; Sun, 6 Nov 2016 13:56:35 +0000 (UTC) (envelope-from avg@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 CBC8A696; Sun, 6 Nov 2016 13:56:35 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uA6DuZ2n079299; Sun, 6 Nov 2016 13:56:35 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA6DuYcO079294; Sun, 6 Nov 2016 13:56:34 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201611061356.uA6DuYcO079294@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Sun, 6 Nov 2016 13:56:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308371 - in stable/10: share/man/man4 sys/conf sys/dev/jedec_ts sys/modules/i2c sys/modules/i2c/jedec_ts X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Nov 2016 13:56:36 -0000 Author: avg Date: Sun Nov 6 13:56:34 2016 New Revision: 308371 URL: https://svnweb.freebsd.org/changeset/base/308371 Log: MFC r307768: jedec_ts: a driver for thermal sensors on memory modules Added: stable/10/share/man/man4/jedec_ts.4 - copied unchanged from r307768, head/share/man/man4/jedec_ts.4 stable/10/sys/dev/jedec_ts/ - copied from r307768, head/sys/dev/jedec_ts/ stable/10/sys/modules/i2c/jedec_ts/ - copied from r307768, head/sys/modules/i2c/jedec_ts/ Modified: stable/10/sys/conf/NOTES stable/10/sys/conf/files stable/10/sys/modules/i2c/Makefile Directory Properties: stable/10/ (props changed) Copied: stable/10/share/man/man4/jedec_ts.4 (from r307768, head/share/man/man4/jedec_ts.4) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/share/man/man4/jedec_ts.4 Sun Nov 6 13:56:34 2016 (r308371, copy of r307768, head/share/man/man4/jedec_ts.4) @@ -0,0 +1,130 @@ +.\" +.\" Copyright (c) 2016 Andriy Gapon +.\" 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. +.\" +.\" $FreeBSD$ +.\" +.Dd October 13, 2016 +.Dt JEDEC_TS 4 +.Os +.Sh NAME +.Nm jedec_ts +.Nd driver for temperature sensors on memory modules +.Sh SYNOPSIS +.Bd -ragged -offset indent +.Cd "device jedec_ts" +.Cd "device smbus" +.Ed +.Pp +Alternatively, to load the driver as a +module at boot time, place the following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +jedec_ts_load="YES" +.Ed +.Pp +In +.Pa /boot/device.hints : +.Bd -literal -offset indent +.Cd hint.jedec_ts.0.at="smbus0" +.Cd hint.jedec_ts.0.addr="0x30" +.Cd hint.jedec_ts.1.at="smbus0" +.Cd hint.jedec_ts.1.addr="0x32" +.Cd hint.jedec_ts.2.at="smbus0" +.Cd hint.jedec_ts.2.addr="0x34" +.Cd hint.jedec_ts.3.at="smbus0" +.Cd hint.jedec_ts.3.addr="0x36" +.Cd hint.jedec_ts.4.at="smbus0" +.Cd hint.jedec_ts.4.addr="0x38" +.Cd hint.jedec_ts.5.at="smbus0" +.Cd hint.jedec_ts.5.addr="0x3A" +.Cd hint.jedec_ts.6.at="smbus0" +.Cd hint.jedec_ts.6.addr="0x3C" +.Cd hint.jedec_ts.7.at="smbus0" +.Cd hint.jedec_ts.7.addr="0x3E" +.Ed +.Sh DESCRIPTION +The +.Nm +driver provides access to sensor data over the +.Xr smbus 4 . +The driver supports temperature sensors on memory modules that conform +to JEDEC Standard 21-C, TSE2002 Specification. +.Pp +The access to +.Nm +data is made via the +.Xr sysctl 8 +interface: +.Bl -tag -width "dev.jedec_ts.%d.temp" +.It Va dev.jedec_ts.%d.temp +read-only value of the current temperature read by the sensor. +.El +.Pp +On a system using +.Xr device.hints 5 , +these values are configurable for +.Nm : +.Bl -tag -width "hint.jedec_ts.%d.addr" +.It Va hint.jedec_ts.%d.at +target +.Xr smbus 4 . +.It Va hint.jedec_ts.%d.addr +.Nm +SMBus address on the +.Xr smbus 4 . +.El +.Pp +.Nm +temperature sensors can be wired to eight different addresses, +allowing up to eight sensors on the same +.Xr smbus 4 . +.Pp +If the sensors are on an I2C bus behind an +.Xr iicbus 4 +controller, then the +.Xr iicsmb 4 +bridge driver can be used to attach the +.Xr smbus 4 . +.Sh EXAMPLES +.Ss Sensor read out for two memory modules: +.Bd -literal +dev.jedec_ts.0.temp: 40.2500C +dev.jedec_ts.1.temp: 40.7500C +.Ed +.Sh SEE ALSO +.Xr iicbus 4 , +.Xr iicsmb 4 , +.Xr smbus 4 , +.Xr sysctl 8 +.Sh HISTORY +The +.Nm +driver first appeared in +.Fx 12.0 . +.Sh AUTHORS +.An -nosplit +The +.Nm +driver and this manual page were written by +.An Andriy Gapon Aq Mt avg@FreeBSD.org . Modified: stable/10/sys/conf/NOTES ============================================================================== --- stable/10/sys/conf/NOTES Sun Nov 6 13:53:50 2016 (r308370) +++ stable/10/sys/conf/NOTES Sun Nov 6 13:56:34 2016 (r308371) @@ -2515,7 +2515,12 @@ device ismt device smb +# SMBus peripheral devices # +# jedec_ts Temperature Sensor compliant with JEDEC Standard 21-C +# +device jedec_ts + # I2C Bus # # Philips i2c bus support is provided by the `iicbus' device. Modified: stable/10/sys/conf/files ============================================================================== --- stable/10/sys/conf/files Sun Nov 6 13:53:50 2016 (r308370) +++ stable/10/sys/conf/files Sun Nov 6 13:56:34 2016 (r308371) @@ -1782,6 +1782,7 @@ dev/ixl/i40e_nvm.c optional ixl ixlv in compile-with "${NORMAL_C} -I$S/dev/ixl" dev/ixl/i40e_adminq.c optional ixl ixlv inet \ compile-with "${NORMAL_C} -I$S/dev/ixl" +dev/jedec_ts/jedec_ts.c optional jedec_ts smbus dev/jme/if_jme.c optional jme pci dev/joy/joy.c optional joy dev/joy/joy_isa.c optional joy isa Modified: stable/10/sys/modules/i2c/Makefile ============================================================================== --- stable/10/sys/modules/i2c/Makefile Sun Nov 6 13:53:50 2016 (r308370) +++ stable/10/sys/modules/i2c/Makefile Sun Nov 6 13:56:34 2016 (r308371) @@ -1,6 +1,6 @@ # $FreeBSD$ SUBDIR = -SUBDIR += controllers if_ic smbus iicbus iicbb iicsmb iic smb +SUBDIR += controllers if_ic smbus iicbus iicbb iicsmb iic smb jedec_ts .include From owner-svn-src-stable-10@freebsd.org Sun Nov 6 16:44:34 2016 Return-Path: Delivered-To: svn-src-stable-10@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 6F196C3292C; Sun, 6 Nov 2016 16:44:34 +0000 (UTC) (envelope-from avos@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 40C8DA92; Sun, 6 Nov 2016 16:44:34 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uA6GiXig046472; Sun, 6 Nov 2016 16:44:33 GMT (envelope-from avos@FreeBSD.org) Received: (from avos@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA6GiXdP046471; Sun, 6 Nov 2016 16:44:33 GMT (envelope-from avos@FreeBSD.org) Message-Id: <201611061644.uA6GiXdP046471@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avos set sender to avos@FreeBSD.org using -f From: Andriy Voskoboinyk Date: Sun, 6 Nov 2016 16:44:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308376 - stable/10/sys/kern X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Nov 2016 16:44:34 -0000 Author: avos Date: Sun Nov 6 16:44:33 2016 New Revision: 308376 URL: https://svnweb.freebsd.org/changeset/base/308376 Log: MFC r288990: Fix regression from r248371. We need to copy packet header to new mbuf. Unlike in the pre-r248371 code, assert that M_PKTHDR is set only on a first mbuf. PR: 195074 Modified: stable/10/sys/kern/uipc_mbuf.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/uipc_mbuf.c ============================================================================== --- stable/10/sys/kern/uipc_mbuf.c Sun Nov 6 16:27:09 2016 (r308375) +++ stable/10/sys/kern/uipc_mbuf.c Sun Nov 6 16:44:33 2016 (r308376) @@ -1994,6 +1994,11 @@ m_unshare(struct mbuf *m0, int how) m_freem(m0); return (NULL); } + if (m->m_flags & M_PKTHDR) { + KASSERT(mprev == NULL, ("%s: m0 %p, m %p has M_PKTHDR", + __func__, m0, m)); + m_move_pkthdr(n, m); + } len = m->m_len; off = 0; mfirst = n; From owner-svn-src-stable-10@freebsd.org Mon Nov 7 08:15:59 2016 Return-Path: Delivered-To: svn-src-stable-10@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 6AA81C33996; Mon, 7 Nov 2016 08:15:59 +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 3A3731049; Mon, 7 Nov 2016 08:15:59 +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 uA78FwcC023698; Mon, 7 Nov 2016 08:15:58 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA78Fwf4023697; Mon, 7 Nov 2016 08:15:58 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201611070815.uA78Fwf4023697@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 7 Nov 2016 08:15:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308395 - stable/10/sys/dev/usb/input X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Nov 2016 08:15:59 -0000 Author: hselasky Date: Mon Nov 7 08:15:58 2016 New Revision: 308395 URL: https://svnweb.freebsd.org/changeset/base/308395 Log: MFC r308144 and r308165: Fixes for virtual T-axis buttons. Make sure the virtual T-axis buttons gets cleared for USB mice which has less than 6 buttons. Make sure the virtual T-axis buttons generate button release event(s) for continuous tilting. PR: 213919 PR: 213957 Modified: stable/10/sys/dev/usb/input/ums.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/usb/input/ums.c ============================================================================== --- stable/10/sys/dev/usb/input/ums.c Mon Nov 7 08:14:29 2016 (r308394) +++ stable/10/sys/dev/usb/input/ums.c Mon Nov 7 08:15:58 2016 (r308395) @@ -258,8 +258,11 @@ ums_intr_callback(struct usb_xfer *xfer, } if ((info->sc_flags & UMS_FLAG_T_AXIS) && - (id == info->sc_iid_t)) + (id == info->sc_iid_t)) { dt -= hid_get_data(buf, len, &info->sc_loc_t); + /* T-axis is translated into button presses */ + buttons_found |= (1UL << 5) | (1UL << 6); + } for (i = 0; i < info->sc_buttons; i++) { uint32_t mask; @@ -287,10 +290,13 @@ ums_intr_callback(struct usb_xfer *xfer, dx, dy, dz, dt, dw, buttons); /* translate T-axis into button presses until further */ - if (dt > 0) + if (dt > 0) { + ums_put_queue(sc, 0, 0, 0, 0, buttons); buttons |= 1UL << 5; - else if (dt < 0) + } else if (dt < 0) { + ums_put_queue(sc, 0, 0, 0, 0, buttons); buttons |= 1UL << 6; + } sc->sc_status.button = buttons; sc->sc_status.dx += dx; From owner-svn-src-stable-10@freebsd.org Mon Nov 7 08:24:30 2016 Return-Path: Delivered-To: svn-src-stable-10@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 B4CA7C341D4; Mon, 7 Nov 2016 08:24:30 +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 80B7D1BA6; Mon, 7 Nov 2016 08:24:30 +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 uA78OTXR027974; Mon, 7 Nov 2016 08:24:29 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA78OTe6027973; Mon, 7 Nov 2016 08:24:29 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201611070824.uA78OTe6027973@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 7 Nov 2016 08:24:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308399 - stable/10/sys/ofed/drivers/net/mlx4 X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Nov 2016 08:24:30 -0000 Author: hselasky Date: Mon Nov 7 08:24:29 2016 New Revision: 308399 URL: https://svnweb.freebsd.org/changeset/base/308399 Log: MFC r308031: Fix indentation and remove duplicate queue stopped stats increment. Found by: Ryan Stone Sponsored by: Mellanox Technologies Modified: stable/10/sys/ofed/drivers/net/mlx4/en_tx.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/ofed/drivers/net/mlx4/en_tx.c ============================================================================== --- stable/10/sys/ofed/drivers/net/mlx4/en_tx.c Mon Nov 7 08:22:44 2016 (r308398) +++ stable/10/sys/ofed/drivers/net/mlx4/en_tx.c Mon Nov 7 08:24:29 2016 (r308399) @@ -702,20 +702,19 @@ static int mlx4_en_xmit(struct mlx4_en_p /* check if TX ring is full */ if (unlikely(mlx4_en_tx_ring_is_full(ring))) { - /* every full native Tx ring stops queue */ - if (ring->blocked == 0) - atomic_add_int(&priv->blocked, 1); - /* Set HW-queue-is-full flag */ - atomic_set_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); - priv->port_stats.queue_stopped++; - ring->blocked = 1; + /* every full native Tx ring stops queue */ + if (ring->blocked == 0) + atomic_add_int(&priv->blocked, 1); + /* Set HW-queue-is-full flag */ + atomic_set_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); priv->port_stats.queue_stopped++; + ring->blocked = 1; ring->queue_stopped++; /* Use interrupts to find out when queue opened */ mlx4_en_arm_cq(priv, priv->tx_cq[tx_ind]); return (ENOBUFS); - } + } /* sanity check we are not wrapping around */ KASSERT(((~ring->prod) & ring->size_mask) >= From owner-svn-src-stable-10@freebsd.org Mon Nov 7 09:19:08 2016 Return-Path: Delivered-To: svn-src-stable-10@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 221CAC349C9; Mon, 7 Nov 2016 09:19:08 +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 E3B5EFC0; Mon, 7 Nov 2016 09:19:07 +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 uA79J7A7047530; Mon, 7 Nov 2016 09:19:07 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA79J49D047502; Mon, 7 Nov 2016 09:19:04 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201611070919.uA79J49D047502@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 7 Nov 2016 09:19:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308402 - in stable/10/sys: arm/allwinner arm/cavium/cns11xx arm/ti/usb arm/xilinx dev/puc dev/usb dev/usb/controller kern mips/atheros mips/cavium/usb mips/rmi mips/rt305x X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Nov 2016 09:19:08 -0000 Author: hselasky Date: Mon Nov 7 09:19:04 2016 New Revision: 308402 URL: https://svnweb.freebsd.org/changeset/base/308402 Log: MFC r307518: Fix device delete child function. When detaching device trees parent devices must be detached prior to detaching its children. This is because parent devices can have pointers to the child devices in their softcs which are not invalidated by device_delete_child(). This can cause use after free issues and panic(). Device drivers implementing trees, must ensure its detach function detaches or deletes all its children before returning. While at it remove now redundant device_detach() calls before device_delete_child() and device_delete_children(), mostly in the USB controller drivers. Tested by: Jan Henrik Sylvester Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D8070 Modified: stable/10/sys/arm/allwinner/a10_ehci.c stable/10/sys/arm/cavium/cns11xx/ehci_ebus.c stable/10/sys/arm/cavium/cns11xx/ohci_ec.c stable/10/sys/arm/ti/usb/omap_ehci.c stable/10/sys/arm/xilinx/zy7_ehci.c stable/10/sys/dev/puc/puc.c stable/10/sys/dev/usb/controller/at91dci_atmelarm.c stable/10/sys/dev/usb/controller/at91dci_fdt.c stable/10/sys/dev/usb/controller/atmegadci_atmelarm.c stable/10/sys/dev/usb/controller/dwc_otg_fdt.c stable/10/sys/dev/usb/controller/ehci_ixp4xx.c stable/10/sys/dev/usb/controller/ehci_mv.c stable/10/sys/dev/usb/controller/ehci_pci.c stable/10/sys/dev/usb/controller/musb_otg_atmelarm.c stable/10/sys/dev/usb/controller/ohci_pci.c stable/10/sys/dev/usb/controller/ohci_s3c24x0.c stable/10/sys/dev/usb/controller/uhci_pci.c stable/10/sys/dev/usb/controller/uss820dci_atmelarm.c stable/10/sys/dev/usb/controller/xhci_pci.c stable/10/sys/dev/usb/usb_device.c stable/10/sys/kern/subr_bus.c stable/10/sys/mips/atheros/ar71xx_ehci.c stable/10/sys/mips/atheros/ar71xx_ohci.c stable/10/sys/mips/cavium/usb/octusb_octeon.c stable/10/sys/mips/rmi/xls_ehci.c stable/10/sys/mips/rt305x/rt305x_dotg.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/arm/allwinner/a10_ehci.c ============================================================================== --- stable/10/sys/arm/allwinner/a10_ehci.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/arm/allwinner/a10_ehci.c Mon Nov 7 09:19:04 2016 (r308402) @@ -224,15 +224,9 @@ static int a10_ehci_detach(device_t self) { ehci_softc_t *sc = device_get_softc(self); - device_t bdev; int err; uint32_t reg_value = 0; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(self, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(self); Modified: stable/10/sys/arm/cavium/cns11xx/ehci_ebus.c ============================================================================== --- stable/10/sys/arm/cavium/cns11xx/ehci_ebus.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/arm/cavium/cns11xx/ehci_ebus.c Mon Nov 7 09:19:04 2016 (r308402) @@ -184,14 +184,8 @@ static int ehci_ebus_detach(device_t self) { ehci_softc_t *sc = device_get_softc(self); - device_t bdev; int err; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(self, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(self); Modified: stable/10/sys/arm/cavium/cns11xx/ohci_ec.c ============================================================================== --- stable/10/sys/arm/cavium/cns11xx/ohci_ec.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/arm/cavium/cns11xx/ohci_ec.c Mon Nov 7 09:19:04 2016 (r308402) @@ -177,14 +177,8 @@ static int ohci_ec_detach(device_t dev) { struct ec_ohci_softc *sc = device_get_softc(dev); - device_t bdev; int err; - if (sc->sc_ohci.sc_bus.bdev) { - bdev = sc->sc_ohci.sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/arm/ti/usb/omap_ehci.c ============================================================================== --- stable/10/sys/arm/ti/usb/omap_ehci.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/arm/ti/usb/omap_ehci.c Mon Nov 7 09:19:04 2016 (r308402) @@ -939,15 +939,8 @@ omap_ehci_detach(device_t dev) { struct omap_ehci_softc *isc = device_get_softc(dev); ehci_softc_t *sc = &isc->base; - device_t bdev; int err; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } - /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/arm/xilinx/zy7_ehci.c ============================================================================== --- stable/10/sys/arm/xilinx/zy7_ehci.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/arm/xilinx/zy7_ehci.c Mon Nov 7 09:19:04 2016 (r308402) @@ -310,20 +310,17 @@ zy7_ehci_detach(device_t dev) { ehci_softc_t *sc = device_get_softc(dev); + /* during module unload there are lots of children leftover */ + device_delete_children(dev); + sc->sc_flags &= ~EHCI_SCFLG_DONEINIT; - if (device_is_attached(dev)) - bus_generic_detach(dev); - if (sc->sc_irq_res && sc->sc_intr_hdl) /* call ehci_detach() after ehci_init() called after * successful bus_setup_intr(). */ ehci_detach(sc); - if (sc->sc_bus.bdev) { - device_detach(sc->sc_bus.bdev); - device_delete_child(dev, sc->sc_bus.bdev); - } + if (sc->sc_irq_res) { if (sc->sc_intr_hdl != NULL) bus_teardown_intr(dev, sc->sc_irq_res, Modified: stable/10/sys/dev/puc/puc.c ============================================================================== --- stable/10/sys/dev/puc/puc.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/puc/puc.c Mon Nov 7 09:19:04 2016 (r308402) @@ -414,8 +414,7 @@ puc_bfe_detach(device_t dev) port = &sc->sc_port[idx]; if (port->p_dev == NULL) continue; - if (device_detach(port->p_dev) == 0) { - device_delete_child(dev, port->p_dev); + if (device_delete_child(dev, port->p_dev) == 0) { if (port->p_rres != NULL) rman_release_resource(port->p_rres); if (port->p_ires != NULL) Modified: stable/10/sys/dev/usb/controller/at91dci_atmelarm.c ============================================================================== --- stable/10/sys/dev/usb/controller/at91dci_atmelarm.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/at91dci_atmelarm.c Mon Nov 7 09:19:04 2016 (r308402) @@ -243,14 +243,8 @@ static int at91_udp_detach(device_t dev) { struct at91_udp_softc *sc = device_get_softc(dev); - device_t bdev; int err; - if (sc->sc_dci.sc_bus.bdev) { - bdev = sc->sc_dci.sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/dev/usb/controller/at91dci_fdt.c ============================================================================== --- stable/10/sys/dev/usb/controller/at91dci_fdt.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/at91dci_fdt.c Mon Nov 7 09:19:04 2016 (r308402) @@ -249,14 +249,8 @@ static int at91_udp_detach(device_t dev) { struct at91_udp_softc *sc = device_get_softc(dev); - device_t bdev; int err; - if (sc->sc_dci.sc_bus.bdev) { - bdev = sc->sc_dci.sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/dev/usb/controller/atmegadci_atmelarm.c ============================================================================== --- stable/10/sys/dev/usb/controller/atmegadci_atmelarm.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/atmegadci_atmelarm.c Mon Nov 7 09:19:04 2016 (r308402) @@ -155,14 +155,8 @@ static int atmegadci_detach(device_t dev) { struct atmegadci_super_softc *sc = device_get_softc(dev); - device_t bdev; int err; - if (sc->sc_otg.sc_bus.bdev) { - bdev = sc->sc_otg.sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/dev/usb/controller/dwc_otg_fdt.c ============================================================================== --- stable/10/sys/dev/usb/controller/dwc_otg_fdt.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/dwc_otg_fdt.c Mon Nov 7 09:19:04 2016 (r308402) @@ -154,14 +154,8 @@ static int dwc_otg_detach(device_t dev) { struct dwc_otg_super_softc *sc = device_get_softc(dev); - device_t bdev; int err; - if (sc->sc_otg.sc_bus.bdev) { - bdev = sc->sc_otg.sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/dev/usb/controller/ehci_ixp4xx.c ============================================================================== --- stable/10/sys/dev/usb/controller/ehci_ixp4xx.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/ehci_ixp4xx.c Mon Nov 7 09:19:04 2016 (r308402) @@ -207,14 +207,8 @@ ehci_ixp_detach(device_t self) { struct ixp_ehci_softc *isc = device_get_softc(self); ehci_softc_t *sc = &isc->base; - device_t bdev; int err; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(self, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(self); Modified: stable/10/sys/dev/usb/controller/ehci_mv.c ============================================================================== --- stable/10/sys/dev/usb/controller/ehci_mv.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/ehci_mv.c Mon Nov 7 09:19:04 2016 (r308402) @@ -242,14 +242,8 @@ static int mv_ehci_detach(device_t self) { ehci_softc_t *sc = device_get_softc(self); - device_t bdev; int err; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(self, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(self); Modified: stable/10/sys/dev/usb/controller/ehci_pci.c ============================================================================== --- stable/10/sys/dev/usb/controller/ehci_pci.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/ehci_pci.c Mon Nov 7 09:19:04 2016 (r308402) @@ -477,13 +477,7 @@ static int ehci_pci_detach(device_t self) { ehci_softc_t *sc = device_get_softc(self); - device_t bdev; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(self, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(self); Modified: stable/10/sys/dev/usb/controller/musb_otg_atmelarm.c ============================================================================== --- stable/10/sys/dev/usb/controller/musb_otg_atmelarm.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/musb_otg_atmelarm.c Mon Nov 7 09:19:04 2016 (r308402) @@ -204,14 +204,8 @@ static int musbotg_detach(device_t dev) { struct musbotg_super_softc *sc = device_get_softc(dev); - device_t bdev; int err; - if (sc->sc_otg.sc_bus.bdev) { - bdev = sc->sc_otg.sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/dev/usb/controller/ohci_pci.c ============================================================================== --- stable/10/sys/dev/usb/controller/ohci_pci.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/ohci_pci.c Mon Nov 7 09:19:04 2016 (r308402) @@ -333,13 +333,7 @@ static int ohci_pci_detach(device_t self) { ohci_softc_t *sc = device_get_softc(self); - device_t bdev; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(self, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(self); Modified: stable/10/sys/dev/usb/controller/ohci_s3c24x0.c ============================================================================== --- stable/10/sys/dev/usb/controller/ohci_s3c24x0.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/ohci_s3c24x0.c Mon Nov 7 09:19:04 2016 (r308402) @@ -148,14 +148,8 @@ static int ohci_s3c24x0_detach(device_t dev) { struct ohci_softc *sc = device_get_softc(dev); - device_t bdev; int err; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/dev/usb/controller/uhci_pci.c ============================================================================== --- stable/10/sys/dev/usb/controller/uhci_pci.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/uhci_pci.c Mon Nov 7 09:19:04 2016 (r308402) @@ -393,13 +393,7 @@ int uhci_pci_detach(device_t self) { uhci_softc_t *sc = device_get_softc(self); - device_t bdev; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(self, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(self); Modified: stable/10/sys/dev/usb/controller/uss820dci_atmelarm.c ============================================================================== --- stable/10/sys/dev/usb/controller/uss820dci_atmelarm.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/uss820dci_atmelarm.c Mon Nov 7 09:19:04 2016 (r308402) @@ -169,14 +169,8 @@ static int uss820_atmelarm_detach(device_t dev) { struct uss820dci_softc *sc = device_get_softc(dev); - device_t bdev; int err; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/dev/usb/controller/xhci_pci.c ============================================================================== --- stable/10/sys/dev/usb/controller/xhci_pci.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/controller/xhci_pci.c Mon Nov 7 09:19:04 2016 (r308402) @@ -318,13 +318,7 @@ static int xhci_pci_detach(device_t self) { struct xhci_softc *sc = device_get_softc(self); - device_t bdev; - if (sc->sc_bus.bdev != NULL) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(self, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(self); Modified: stable/10/sys/dev/usb/usb_device.c ============================================================================== --- stable/10/sys/dev/usb/usb_device.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/dev/usb/usb_device.c Mon Nov 7 09:19:04 2016 (r308402) @@ -1106,10 +1106,8 @@ usb_detach_device_sub(struct usb_device device_printf(dev, "Resume failed\n"); } } - if (device_detach(dev)) { - goto error; - } } + /* detach and delete child */ if (device_delete_child(udev->parent_dev, dev)) { goto error; } Modified: stable/10/sys/kern/subr_bus.c ============================================================================== --- stable/10/sys/kern/subr_bus.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/kern/subr_bus.c Mon Nov 7 09:19:04 2016 (r308402) @@ -1923,15 +1923,17 @@ device_delete_child(device_t dev, device PDEBUG(("%s from %s", DEVICENAME(child), DEVICENAME(dev))); - /* remove children first */ + /* detach parent before deleting children, if any */ + if ((error = device_detach(child)) != 0) + return (error); + + /* remove children second */ while ((grandchild = TAILQ_FIRST(&child->children)) != NULL) { error = device_delete_child(child, grandchild); if (error) return (error); } - if ((error = device_detach(child)) != 0) - return (error); if (child->devclass) devclass_delete_device(child->devclass, child); if (child->parent) Modified: stable/10/sys/mips/atheros/ar71xx_ehci.c ============================================================================== --- stable/10/sys/mips/atheros/ar71xx_ehci.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/mips/atheros/ar71xx_ehci.c Mon Nov 7 09:19:04 2016 (r308402) @@ -196,14 +196,8 @@ ar71xx_ehci_detach(device_t self) { struct ar71xx_ehci_softc *isc = device_get_softc(self); ehci_softc_t *sc = &isc->base; - device_t bdev; int err; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(self, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(self); Modified: stable/10/sys/mips/atheros/ar71xx_ohci.c ============================================================================== --- stable/10/sys/mips/atheros/ar71xx_ohci.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/mips/atheros/ar71xx_ohci.c Mon Nov 7 09:19:04 2016 (r308402) @@ -143,13 +143,7 @@ static int ar71xx_ohci_detach(device_t dev) { struct ar71xx_ohci_softc *sc = device_get_softc(dev); - device_t bdev; - if (sc->sc_ohci.sc_bus.bdev) { - bdev = sc->sc_ohci.sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/mips/cavium/usb/octusb_octeon.c ============================================================================== --- stable/10/sys/mips/cavium/usb/octusb_octeon.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/mips/cavium/usb/octusb_octeon.c Mon Nov 7 09:19:04 2016 (r308402) @@ -160,16 +160,10 @@ static int octusb_octeon_detach(device_t dev) { struct octusb_octeon_softc *sc = device_get_softc(dev); - device_t bdev; int err; int nports; int i; - if (sc->sc_dci.sc_bus.bdev) { - bdev = sc->sc_dci.sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); Modified: stable/10/sys/mips/rmi/xls_ehci.c ============================================================================== --- stable/10/sys/mips/rmi/xls_ehci.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/mips/rmi/xls_ehci.c Mon Nov 7 09:19:04 2016 (r308402) @@ -164,14 +164,8 @@ static int ehci_xls_detach(device_t self) { ehci_softc_t *sc = device_get_softc(self); - device_t bdev; int err; - if (sc->sc_bus.bdev) { - bdev = sc->sc_bus.bdev; - device_detach(bdev); - device_delete_child(self, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(self); Modified: stable/10/sys/mips/rt305x/rt305x_dotg.c ============================================================================== --- stable/10/sys/mips/rt305x/rt305x_dotg.c Mon Nov 7 08:36:06 2016 (r308401) +++ stable/10/sys/mips/rt305x/rt305x_dotg.c Mon Nov 7 09:19:04 2016 (r308402) @@ -167,14 +167,8 @@ static int dotg_obio_detach(device_t dev) { struct dotg_obio_softc *sc = device_get_softc(dev); - device_t bdev; int err; - if (sc->sc_dci.sc_bus.bdev) { - bdev = sc->sc_dci.sc_bus.bdev; - device_detach(bdev); - device_delete_child(dev, bdev); - } /* during module unload there are lots of children leftover */ device_delete_children(dev); From owner-svn-src-stable-10@freebsd.org Tue Nov 8 07:18:40 2016 Return-Path: Delivered-To: svn-src-stable-10@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 8A5F5C35BBC; Tue, 8 Nov 2016 07:18:40 +0000 (UTC) (envelope-from avg@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 344F32CC; Tue, 8 Nov 2016 07:18:40 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uA87Id41068273; Tue, 8 Nov 2016 07:18:39 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA87IdBm068272; Tue, 8 Nov 2016 07:18:39 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201611080718.uA87IdBm068272@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Tue, 8 Nov 2016 07:18:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308436 - stable/10/sys/amd64/vmm/amd X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Nov 2016 07:18:40 -0000 Author: avg Date: Tue Nov 8 07:18:39 2016 New Revision: 308436 URL: https://svnweb.freebsd.org/changeset/base/308436 Log: MFC r307903,307904,308039,308050: vmm/svm: iopm_bitmap and msr_bitmap must be contiguous in physical memory Modified: stable/10/sys/amd64/vmm/amd/svm.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/amd64/vmm/amd/svm.c ============================================================================== --- stable/10/sys/amd64/vmm/amd/svm.c Tue Nov 8 07:18:33 2016 (r308435) +++ stable/10/sys/amd64/vmm/amd/svm.c Tue Nov 8 07:18:39 2016 (r308436) @@ -515,10 +515,11 @@ svm_vminit(struct vm *vm, pmap_t pmap) { struct svm_softc *svm_sc; struct svm_vcpu *vcpu; - vm_paddr_t msrpm_pa, iopm_pa, pml4_pa; + vm_paddr_t msrpm_pa, iopm_pa, pml4_pa; int i; - svm_sc = malloc(sizeof (struct svm_softc), M_SVM, M_WAITOK | M_ZERO); + svm_sc = contigmalloc(sizeof (*svm_sc), M_SVM, M_WAITOK | M_ZERO, + 0, ~(vm_paddr_t)0, PAGE_SIZE, 0); svm_sc->vm = vm; svm_sc->nptp = (vm_offset_t)vtophys(pmap->pm_pml4); @@ -535,7 +536,7 @@ svm_vminit(struct vm *vm, pmap_t pmap) svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_GSBASE); svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_FSBASE); svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_KGSBASE); - + svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_STAR); svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_LSTAR); svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_CSTAR); @@ -2043,7 +2044,7 @@ svm_vmcleanup(void *arg) { struct svm_softc *sc = arg; - free(sc, M_SVM); + contigfree(sc, sizeof (*sc), M_SVM); } static register_t * From owner-svn-src-stable-10@freebsd.org Tue Nov 8 20:58:26 2016 Return-Path: Delivered-To: svn-src-stable-10@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 7E823C37D5F; Tue, 8 Nov 2016 20:58:26 +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 4901DF1B; Tue, 8 Nov 2016 20:58:26 +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 uA8KwPIc096090; Tue, 8 Nov 2016 20:58:25 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA8KwPMS096089; Tue, 8 Nov 2016 20:58:25 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201611082058.uA8KwPMS096089@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Tue, 8 Nov 2016 20:58:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308448 - stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Nov 2016 20:58:26 -0000 Author: mav Date: Tue Nov 8 20:58:25 2016 New Revision: 308448 URL: https://svnweb.freebsd.org/changeset/base/308448 Log: MFC r307857: Fix panic after ZVOL renamed to name invalid for DEVFS. Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c ============================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Tue Nov 8 20:57:46 2016 (r308447) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Tue Nov 8 20:58:25 2016 (r308448) @@ -780,8 +780,10 @@ zvol_remove_zv(zvol_state_t *zv) g_topology_lock(); zvol_geom_destroy(zv); g_topology_unlock(); - } else if (zv->zv_volmode == ZFS_VOLMODE_DEV) - destroy_dev(zv->zv_dev); + } else if (zv->zv_volmode == ZFS_VOLMODE_DEV) { + if (zv->zv_dev != NULL) + destroy_dev(zv->zv_dev); + } #endif avl_destroy(&zv->zv_znode.z_range_avl); @@ -2952,14 +2954,14 @@ zvol_rename_minor(zvol_state_t *zv, cons } else if (zv->zv_volmode == ZFS_VOLMODE_DEV) { struct make_dev_args args; - dev = zv->zv_dev; - ASSERT(dev != NULL); - zv->zv_dev = NULL; - destroy_dev(dev); - if (zv->zv_total_opens > 0) { - zv->zv_flags &= ~ZVOL_EXCL; - zv->zv_total_opens = 0; - zvol_last_close(zv); + if ((dev = zv->zv_dev) != NULL) { + zv->zv_dev = NULL; + destroy_dev(dev); + if (zv->zv_total_opens > 0) { + zv->zv_flags &= ~ZVOL_EXCL; + zv->zv_total_opens = 0; + zvol_last_close(zv); + } } make_dev_args_init(&args); From owner-svn-src-stable-10@freebsd.org Tue Nov 8 21:39:16 2016 Return-Path: Delivered-To: svn-src-stable-10@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 9AB51C37B85; Tue, 8 Nov 2016 21:39:16 +0000 (UTC) (envelope-from rmacklem@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 63C8CEA1; Tue, 8 Nov 2016 21:39:16 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uA8LdFEQ012364; Tue, 8 Nov 2016 21:39:15 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA8LdFEF012363; Tue, 8 Nov 2016 21:39:15 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201611082139.uA8LdFEF012363@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Tue, 8 Nov 2016 21:39:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308452 - stable/10/usr.sbin/mountd X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Nov 2016 21:39:16 -0000 Author: rmacklem Date: Tue Nov 8 21:39:15 2016 New Revision: 308452 URL: https://svnweb.freebsd.org/changeset/base/308452 Log: MFC: r307890 mountd(8) was erroneously setting the sysctl for the old NFS server when the new/default NFS server was running, for the "-n" option. This patch fixes the problem for stable/10 and stable/9. Since the new NFS server uses vfs.nfsd.nfs_privport == 0 by default, there wouldn't have been many users affected by the code not setting it to 0 when the "-n" option was specified. Modified: stable/10/usr.sbin/mountd/mountd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/mountd/mountd.c ============================================================================== --- stable/10/usr.sbin/mountd/mountd.c Tue Nov 8 21:17:24 2016 (r308451) +++ stable/10/usr.sbin/mountd/mountd.c Tue Nov 8 21:39:15 2016 (r308452) @@ -489,11 +489,20 @@ main(int argc, char **argv) rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec); if (!resvport_only) { - if (sysctlbyname("vfs.nfsrv.nfs_privport", NULL, NULL, - &resvport_only, sizeof(resvport_only)) != 0 && - errno != ENOENT) { - syslog(LOG_ERR, "sysctl: %m"); - exit(1); + if (run_v4server != 0) { + if (sysctlbyname("vfs.nfsd.nfs_privport", NULL, NULL, + &resvport_only, sizeof(resvport_only)) != 0 && + errno != ENOENT) { + syslog(LOG_ERR, "sysctl: %m"); + exit(1); + } + } else { + if (sysctlbyname("vfs.nfsrv.nfs_privport", NULL, NULL, + &resvport_only, sizeof(resvport_only)) != 0 && + errno != ENOENT) { + syslog(LOG_ERR, "sysctl: %m"); + exit(1); + } } } From owner-svn-src-stable-10@freebsd.org Tue Nov 8 21:47:02 2016 Return-Path: Delivered-To: svn-src-stable-10@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 24B5AC37D9A; Tue, 8 Nov 2016 21:47:02 +0000 (UTC) (envelope-from rmacklem@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 E46EB6A8; Tue, 8 Nov 2016 21:47:01 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uA8Ll1WC016342; Tue, 8 Nov 2016 21:47:01 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA8Ll16T016341; Tue, 8 Nov 2016 21:47:01 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201611082147.uA8Ll16T016341@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Tue, 8 Nov 2016 21:47:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308453 - stable/10/usr.sbin/mountd X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Nov 2016 21:47:02 -0000 Author: rmacklem Date: Tue Nov 8 21:47:00 2016 New Revision: 308453 URL: https://svnweb.freebsd.org/changeset/base/308453 Log: MFC: r307891 Fix the man page to reflect the change done by r307890 to mountd.c so that the "-n" option uses the sysctl for the correct NFS server. This is a content change. Modified: stable/10/usr.sbin/mountd/mountd.8 Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/mountd/mountd.8 ============================================================================== --- stable/10/usr.sbin/mountd/mountd.8 Tue Nov 8 21:39:15 2016 (r308452) +++ stable/10/usr.sbin/mountd/mountd.8 Tue Nov 8 21:47:00 2016 (r308453) @@ -28,7 +28,7 @@ .\" @(#)mountd.8 8.4 (Berkeley) 4/28/95 .\" $FreeBSD$ .\" -.Dd October 14, 2012 +.Dd October 24, 2016 .Dt MOUNTD 8 .Os .Sh NAME @@ -96,7 +96,7 @@ requests to be logged. Allow non-root mount requests to be served. This should only be specified if there are clients such as PC's, that require it. -It will automatically clear the vfs.nfsrv.nfs_privport sysctl flag, which +It will automatically clear the vfs.[nfsrv|nfsd].nfs_privport sysctl flag, which controls if the kernel will accept NFS requests from reserved ports only. .It Fl o This flag forces the system to run the old NFS server, which does not From owner-svn-src-stable-10@freebsd.org Wed Nov 9 17:07:47 2016 Return-Path: Delivered-To: svn-src-stable-10@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 23A29C38C4F; Wed, 9 Nov 2016 17:07:47 +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 E6D87FB; Wed, 9 Nov 2016 17:07: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 uA9H7kZg071984; Wed, 9 Nov 2016 17:07:46 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA9H7kNC071983; Wed, 9 Nov 2016 17:07:46 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611091707.uA9H7kNC071983@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 9 Nov 2016 17:07:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308469 - stable/10/sys/kern X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2016 17:07:47 -0000 Author: kib Date: Wed Nov 9 17:07:45 2016 New Revision: 308469 URL: https://svnweb.freebsd.org/changeset/base/308469 Log: MFC r308211: Remove tautological casts. Modified: stable/10/sys/kern/vfs_lookup.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/vfs_lookup.c ============================================================================== --- stable/10/sys/kern/vfs_lookup.c Wed Nov 9 16:46:57 2016 (r308468) +++ stable/10/sys/kern/vfs_lookup.c Wed Nov 9 17:07:45 2016 (r308469) @@ -164,11 +164,11 @@ namei(struct nameidata *ndp) if ((cnp->cn_flags & HASBUF) == 0) cnp->cn_pnbuf = uma_zalloc(namei_zone, M_WAITOK); if (ndp->ni_segflg == UIO_SYSSPACE) - error = copystr(ndp->ni_dirp, cnp->cn_pnbuf, - MAXPATHLEN, (size_t *)&ndp->ni_pathlen); + error = copystr(ndp->ni_dirp, cnp->cn_pnbuf, MAXPATHLEN, + &ndp->ni_pathlen); else - error = copyinstr(ndp->ni_dirp, cnp->cn_pnbuf, - MAXPATHLEN, (size_t *)&ndp->ni_pathlen); + error = copyinstr(ndp->ni_dirp, cnp->cn_pnbuf, MAXPATHLEN, + &ndp->ni_pathlen); /* * Don't allow empty pathnames. From owner-svn-src-stable-10@freebsd.org Wed Nov 9 17:19:51 2016 Return-Path: Delivered-To: svn-src-stable-10@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 8072FC38FB6; Wed, 9 Nov 2016 17:19:51 +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 4FAD6B88; Wed, 9 Nov 2016 17:19:51 +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 uA9HJo2e075937; Wed, 9 Nov 2016 17:19:50 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA9HJoaF075936; Wed, 9 Nov 2016 17:19:50 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611091719.uA9HJoaF075936@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 9 Nov 2016 17:19:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308470 - stable/10/sys/kern X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2016 17:19:51 -0000 Author: kib Date: Wed Nov 9 17:19:50 2016 New Revision: 308470 URL: https://svnweb.freebsd.org/changeset/base/308470 Log: MFC r308228: Remove remnants of the recursive sleep support. Modified: stable/10/sys/kern/kern_synch.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/kern_synch.c ============================================================================== --- stable/10/sys/kern/kern_synch.c Wed Nov 9 17:07:45 2016 (r308469) +++ stable/10/sys/kern/kern_synch.c Wed Nov 9 17:19:50 2016 (r308470) @@ -196,13 +196,7 @@ _sleep(void *ident, struct lock_object * catch = priority & PCATCH; pri = priority & PRIMASK; - /* - * If we are already on a sleep queue, then remove us from that - * sleep queue first. We have to do this to handle recursive - * sleeps. - */ - if (TD_ON_SLEEPQ(td)) - sleepq_remove(td, td->td_wchan); + KASSERT(!TD_ON_SLEEPQ(td), ("recursive sleep")); if ((uint8_t *)ident >= &pause_wchan[0] && (uint8_t *)ident <= &pause_wchan[MAXCPU - 1]) From owner-svn-src-stable-10@freebsd.org Thu Nov 10 11:14:53 2016 Return-Path: Delivered-To: svn-src-stable-10@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 E122AC3A0C8; Thu, 10 Nov 2016 11:14:52 +0000 (UTC) (envelope-from avg@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 A5D39DF3; Thu, 10 Nov 2016 11:14:52 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAABEp1p010457; Thu, 10 Nov 2016 11:14:51 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAABEpfq010456; Thu, 10 Nov 2016 11:14:51 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201611101114.uAABEpfq010456@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Thu, 10 Nov 2016 11:14:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308482 - stable/10/sys/dev/cpuctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Nov 2016 11:14:53 -0000 Author: avg Date: Thu Nov 10 11:14:51 2016 New Revision: 308482 URL: https://svnweb.freebsd.org/changeset/base/308482 Log: MFC r308225: dev/cpuctl: put debug output under CPUCTL_DEBUG rather than DEBUG Modified: stable/10/sys/dev/cpuctl/cpuctl.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/cpuctl/cpuctl.c ============================================================================== --- stable/10/sys/dev/cpuctl/cpuctl.c Thu Nov 10 11:14:46 2016 (r308481) +++ stable/10/sys/dev/cpuctl/cpuctl.c Thu Nov 10 11:14:51 2016 (r308482) @@ -57,7 +57,7 @@ static d_ioctl_t cpuctl_ioctl; #define CPUCTL_VERSION 1 -#ifdef DEBUG +#ifdef CPUCTL_DEBUG # define DPRINTF(format,...) printf(format, __VA_ARGS__); #else # define DPRINTF(...) From owner-svn-src-stable-10@freebsd.org Fri Nov 11 02:40:45 2016 Return-Path: Delivered-To: svn-src-stable-10@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 E9331C3A9D0; Fri, 11 Nov 2016 02:40:45 +0000 (UTC) (envelope-from sephe@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 B797369E; Fri, 11 Nov 2016 02:40:45 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB2ei3h073167; Fri, 11 Nov 2016 02:40:44 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB2eiET073165; Fri, 11 Nov 2016 02:40:44 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110240.uAB2eiET073165@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 02:40:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308492 - in stable/10/sys/dev/hyperv: include vmbus X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 02:40:46 -0000 Author: sephe Date: Fri Nov 11 02:40:44 2016 New Revision: 308492 URL: https://svnweb.freebsd.org/changeset/base/308492 Log: MFC r307624 hyperv/vmbus: Expose channel management taskqueue for driver to use. Sponsored by: Microsoft Modified: stable/10/sys/dev/hyperv/include/vmbus.h stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/include/vmbus.h ============================================================================== --- stable/10/sys/dev/hyperv/include/vmbus.h Thu Nov 10 22:12:19 2016 (r308491) +++ stable/10/sys/dev/hyperv/include/vmbus.h Fri Nov 11 02:40:44 2016 (r308492) @@ -119,6 +119,7 @@ struct vmbus_chan_br { struct vmbus_channel; struct hyperv_guid; struct task; +struct taskqueue; typedef void (*vmbus_chan_callback_t)(struct vmbus_channel *, void *); @@ -180,5 +181,7 @@ int vmbus_chan_prplist_nelem(int br_siz int dlen_max); bool vmbus_chan_rx_empty(const struct vmbus_channel *chan); bool vmbus_chan_tx_empty(const struct vmbus_channel *chan); +struct taskqueue * + vmbus_chan_mgmt_tq(const struct vmbus_channel *chan); #endif /* !_VMBUS_H_ */ Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Thu Nov 10 22:12:19 2016 (r308491) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Fri Nov 11 02:40:44 2016 (r308492) @@ -1721,3 +1721,10 @@ vmbus_chan_run_task(struct vmbus_channel taskqueue_enqueue(chan->ch_tq, task); taskqueue_drain(chan->ch_tq, task); } + +struct taskqueue * +vmbus_chan_mgmt_tq(const struct vmbus_channel *chan) +{ + + return (chan->ch_mgmt_tq); +} From owner-svn-src-stable-10@freebsd.org Fri Nov 11 03:03:56 2016 Return-Path: Delivered-To: svn-src-stable-10@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 F28F6C3823A; Fri, 11 Nov 2016 03:03:55 +0000 (UTC) (envelope-from sephe@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 B4B9799D; Fri, 11 Nov 2016 03:03:55 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB33txM082767; Fri, 11 Nov 2016 03:03:55 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB33sA0082759; Fri, 11 Nov 2016 03:03:54 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110303.uAB33sA0082759@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 03:03:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308494 - in stable/10/sys: dev/hyperv/netvsc net X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 03:03:56 -0000 Author: sephe Date: Fri Nov 11 03:03:54 2016 New Revision: 308494 URL: https://svnweb.freebsd.org/changeset/base/308494 Log: MFC 307710-307712,307714 307710 hyperv/hn: Always query RSS capabilities. - This avoid distributing NDIS version check. - Only NDIS 6.20 required (earlier NDIS uses different indirect table format). Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8291 307711 hyperv/hn: Check NVS version for HASHVAL pktinfo on sending path. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8293 307712 hyperv/hn: Add network change support. Currently the network change is simulated by link status changes. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8295 307714 hyperv/hn: Function renaming; consistent w/ hardware capabilities query. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8296 Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c stable/10/sys/dev/hyperv/netvsc/if_hnreg.h stable/10/sys/dev/hyperv/netvsc/if_hnvar.h stable/10/sys/dev/hyperv/netvsc/ndis.h stable/10/sys/net/rndis.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Fri Nov 11 02:42:53 2016 (r308493) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Fri Nov 11 03:03:54 2016 (r308494) @@ -543,8 +543,9 @@ hn_nvs_init(struct hn_softc *sc) if (error) { if_printf(sc->hn_ifp, "reinit NVS version 0x%x " "failed: %d\n", sc->hn_nvs_ver, error); + return (error); } - return (error); + goto done; } /* @@ -566,11 +567,16 @@ hn_nvs_init(struct hn_softc *sc) HN_NDIS_VERSION_MAJOR(sc->hn_ndis_ver), HN_NDIS_VERSION_MINOR(sc->hn_ndis_ver)); } - return (0); + goto done; } } if_printf(sc->hn_ifp, "no NVS available\n"); return (ENXIO); + +done: + if (sc->hn_nvs_ver >= HN_NVS_VERSION_5) + sc->hn_caps |= HN_CAP_HASHVAL; + return (0); } int Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 02:42:53 2016 (r308493) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 03:03:54 2016 (r308494) @@ -208,7 +208,6 @@ struct hn_softc { struct arpcom arpcom; struct ifmedia hn_media; device_t hn_dev; - int hn_carrier; int hn_if_flags; struct sx hn_lock; struct vmbus_channel *hn_prichan; @@ -237,6 +236,9 @@ struct hn_softc { struct taskqueue *hn_mgmt_taskq; struct taskqueue *hn_mgmt_taskq0; struct task hn_link_task; + struct task hn_netchg_init; + struct timeout_task hn_netchg_status; + uint32_t hn_link_flags; /* HN_LINK_FLAG_ */ uint32_t hn_caps; /* HN_CAP_ */ uint32_t hn_flags; /* HN_FLAG_ */ @@ -270,6 +272,10 @@ struct hn_softc { #define HN_CAP_UDP6CS 0x0040 #define HN_CAP_TSO4 0x0080 #define HN_CAP_TSO6 0x0100 +#define HN_CAP_HASHVAL 0x0200 + +#define HN_LINK_FLAG_LINKUP 0x0001 +#define HN_LINK_FLAG_NETCHG 0x0002 /* * Externs Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 02:42:53 2016 (r308493) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 03:03:54 2016 (r308494) @@ -337,6 +337,8 @@ static void hn_destroy_tx_data(struct hn static void hn_start_taskfunc(void *, int); static void hn_start_txeof_taskfunc(void *, int); static void hn_link_taskfunc(void *, int); +static void hn_netchg_init_taskfunc(void *, int); +static void hn_netchg_status_taskfunc(void *, int); static void hn_suspend_mgmt_taskfunc(void *, int); static int hn_encap(struct hn_tx_ring *, struct hn_txdesc *, struct mbuf **); static int hn_create_rx_data(struct hn_softc *sc, int); @@ -362,6 +364,7 @@ static void hn_rx_drain(struct vmbus_cha static void hn_tx_resume(struct hn_softc *, int); static void hn_tx_ring_qflush(struct hn_tx_ring *); static int netvsc_detach(device_t dev); +static void hn_link_status(struct hn_softc *); static void hn_nvs_handle_notify(struct hn_softc *sc, const struct vmbus_chanpkt_hdr *pkt); @@ -484,7 +487,7 @@ hn_ifmedia_sts(struct ifnet *ifp, struct ifmr->ifm_status = IFM_AVALID; ifmr->ifm_active = IFM_ETHER; - if (!sc->hn_carrier) { + if ((sc->hn_link_flags & HN_LINK_FLAG_LINKUP) == 0) { ifmr->ifm_active |= IFM_NONE; return; } @@ -579,6 +582,9 @@ netvsc_attach(device_t dev) taskqueue_start_threads(&sc->hn_mgmt_taskq0, 1, PI_NET, "%s mgmt", device_get_nameunit(dev)); TASK_INIT(&sc->hn_link_task, 0, hn_link_taskfunc, sc); + TASK_INIT(&sc->hn_netchg_init, 0, hn_netchg_init_taskfunc, sc); + TIMEOUT_TASK_INIT(sc->hn_mgmt_taskq0, &sc->hn_netchg_status, 0, + hn_netchg_status_taskfunc, sc); /* * Allocate ifnet and setup its name earlier, so that if_printf @@ -824,10 +830,8 @@ netvsc_shutdown(device_t dev) } static void -hn_link_taskfunc(void *xsc, int pending __unused) +hn_link_status(struct hn_softc *sc) { - struct hn_softc *sc = xsc; - struct ifnet *ifp = sc->hn_ifp; uint32_t link_status; int error; @@ -838,11 +842,51 @@ hn_link_taskfunc(void *xsc, int pending } if (link_status == NDIS_MEDIA_STATE_CONNECTED) - sc->hn_carrier = 1; + sc->hn_link_flags |= HN_LINK_FLAG_LINKUP; else - sc->hn_carrier = 0; - if_link_state_change(ifp, - sc->hn_carrier ? LINK_STATE_UP : LINK_STATE_DOWN); + sc->hn_link_flags &= ~HN_LINK_FLAG_LINKUP; + if_link_state_change(sc->hn_ifp, + (sc->hn_link_flags & HN_LINK_FLAG_LINKUP) ? + LINK_STATE_UP : LINK_STATE_DOWN); +} + +static void +hn_link_taskfunc(void *xsc, int pending __unused) +{ + struct hn_softc *sc = xsc; + + if (sc->hn_link_flags & HN_LINK_FLAG_NETCHG) + return; + hn_link_status(sc); +} + +static void +hn_netchg_init_taskfunc(void *xsc, int pending __unused) +{ + struct hn_softc *sc = xsc; + + /* Prevent any link status checks from running. */ + sc->hn_link_flags |= HN_LINK_FLAG_NETCHG; + + /* + * Fake up a [link down --> link up] state change; 5 seconds + * delay is used, which closely simulates miibus reaction + * upon link down event. + */ + sc->hn_link_flags &= ~HN_LINK_FLAG_LINKUP; + if_link_state_change(sc->hn_ifp, LINK_STATE_DOWN); + taskqueue_enqueue_timeout(sc->hn_mgmt_taskq0, + &sc->hn_netchg_status, 5 * hz); +} + +static void +hn_netchg_status_taskfunc(void *xsc, int pending __unused) +{ + struct hn_softc *sc = xsc; + + /* Re-allow link status checks. */ + sc->hn_link_flags &= ~HN_LINK_FLAG_NETCHG; + hn_link_status(sc); } void @@ -853,6 +897,14 @@ hn_link_status_update(struct hn_softc *s taskqueue_enqueue(sc->hn_mgmt_taskq, &sc->hn_link_task); } +void +hn_network_change(struct hn_softc *sc) +{ + + if (sc->hn_mgmt_taskq != NULL) + taskqueue_enqueue(sc->hn_mgmt_taskq, &sc->hn_netchg_init); +} + static __inline int hn_txdesc_dmamap_load(struct hn_tx_ring *txr, struct hn_txdesc *txd, struct mbuf **m_head, bus_dma_segment_t *segs, int *nsegs) @@ -2253,7 +2305,8 @@ hn_caps_sysctl(SYSCTL_HANDLER_ARGS) "\006UDP4CS" "\007UDP6CS" "\010TSO4" - "\011TSO6"); + "\011TSO6" + "\012HASHVAL"); return sysctl_handle_string(oidp, caps_str, sizeof(caps_str), req); } @@ -3028,12 +3081,15 @@ hn_fixup_tx_data(struct hn_softc *sc) if (sc->hn_caps & HN_CAP_UDP6CS) csum_assist |= CSUM_IP6_UDP; #endif - for (i = 0; i < sc->hn_tx_ring_cnt; ++i) sc->hn_tx_ring[i].hn_csum_assist = csum_assist; - if (sc->hn_ndis_ver >= HN_NDIS_VERSION_6_30) { - /* Support HASHVAL pktinfo on TX path. */ + if (sc->hn_caps & HN_CAP_HASHVAL) { + /* + * Support HASHVAL pktinfo on TX path. + */ + if (bootverbose) + if_printf(sc->hn_ifp, "support HASHVAL pktinfo\n"); for (i = 0; i < sc->hn_tx_ring_cnt; ++i) sc->hn_tx_ring[i].hn_tx_flags |= HN_TX_FLAG_HASHVAL; } @@ -3428,20 +3484,19 @@ hn_synth_alloc_subchans(struct hn_softc int nchan, rxr_cnt, error; nchan = *nsubch + 1; - if (sc->hn_ndis_ver < HN_NDIS_VERSION_6_30 || nchan == 1) { + if (nchan == 1) { /* - * Either RSS is not supported, or multiple RX/TX rings - * are not requested. + * Multiple RX/TX rings are not requested. */ *nsubch = 0; return (0); } /* - * Get RSS capabilities, e.g. # of RX rings, and # of indirect + * Query RSS capabilities, e.g. # of RX rings, and # of indirect * table entries. */ - error = hn_rndis_get_rsscaps(sc, &rxr_cnt); + error = hn_rndis_query_rsscaps(sc, &rxr_cnt); if (error) { /* No RSS; this is benign. */ *nsubch = 0; @@ -3736,6 +3791,8 @@ hn_suspend_mgmt(struct hn_softc *sc) /* * Make sure that all pending management tasks are completed. */ + taskqueue_drain(sc->hn_mgmt_taskq0, &sc->hn_netchg_init); + taskqueue_drain_timeout(sc->hn_mgmt_taskq0, &sc->hn_netchg_status); taskqueue_drain_all(sc->hn_mgmt_taskq0); } @@ -3813,10 +3870,11 @@ hn_resume_mgmt(struct hn_softc *sc) { /* - * Kick off link status check. + * Kick off network change detection, which will + * do link status check too. */ sc->hn_mgmt_taskq = sc->hn_mgmt_taskq0; - hn_link_status_update(sc); + hn_network_change(sc); } static void Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 02:42:53 2016 (r308493) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 03:03:54 2016 (r308494) @@ -159,6 +159,7 @@ static void hv_rf_receive_indicate_status(struct hn_softc *sc, const void *data, int dlen) { const struct rndis_status_msg *msg; + int ofs; if (dlen < sizeof(*msg)) { if_printf(sc->hn_ifp, "invalid RNDIS status\n"); @@ -177,8 +178,19 @@ hv_rf_receive_indicate_status(struct hn_ break; case RNDIS_STATUS_NETWORK_CHANGE: - /* TODO */ - if_printf(sc->hn_ifp, "network changed\n"); + ofs = RNDIS_STBUFOFFSET_ABS(msg->rm_stbufoffset); + if (dlen < ofs + msg->rm_stbuflen || + msg->rm_stbuflen < sizeof(uint32_t)) { + if_printf(sc->hn_ifp, "network changed\n"); + } else { + uint32_t change; + + memcpy(&change, ((const uint8_t *)msg) + ofs, + sizeof(change)); + if_printf(sc->hn_ifp, "network changed, change %u\n", + change); + } + hn_network_change(sc); break; default: @@ -737,7 +749,7 @@ done: } int -hn_rndis_get_rsscaps(struct hn_softc *sc, int *rxr_cnt) +hn_rndis_query_rsscaps(struct hn_softc *sc, int *rxr_cnt) { struct ndis_rss_caps in, caps; size_t caps_len; @@ -745,15 +757,13 @@ hn_rndis_get_rsscaps(struct hn_softc *sc *rxr_cnt = 0; + if (sc->hn_ndis_ver < HN_NDIS_VERSION_6_20) + return (EOPNOTSUPP); + memset(&in, 0, sizeof(in)); in.ndis_hdr.ndis_type = NDIS_OBJTYPE_RSS_CAPS; - if (sc->hn_ndis_ver < HN_NDIS_VERSION_6_30) { - in.ndis_hdr.ndis_rev = NDIS_RSS_CAPS_REV_1; - in.ndis_hdr.ndis_size = NDIS_RSS_CAPS_SIZE_6_0; - } else { - in.ndis_hdr.ndis_rev = NDIS_RSS_CAPS_REV_2; - in.ndis_hdr.ndis_size = NDIS_RSS_CAPS_SIZE; - } + in.ndis_hdr.ndis_rev = NDIS_RSS_CAPS_REV_2; + in.ndis_hdr.ndis_size = NDIS_RSS_CAPS_SIZE; caps_len = NDIS_RSS_CAPS_SIZE; error = hn_rndis_query2(sc, OID_GEN_RECEIVE_SCALE_CAPABILITIES, @@ -1028,10 +1038,12 @@ hn_rndis_conf_rss(struct hn_softc *sc, u int error; /* - * Only NDIS 6.30+ is supported. + * Only NDIS 6.20+ is supported: + * We only support 4bytes element in indirect table, which has been + * adopted since NDIS 6.20. */ - KASSERT(sc->hn_ndis_ver >= HN_NDIS_VERSION_6_30, - ("NDIS 6.30+ is required, NDIS version 0x%08x", sc->hn_ndis_ver)); + KASSERT(sc->hn_ndis_ver >= HN_NDIS_VERSION_6_20, + ("NDIS 6.20+ is required, NDIS version 0x%08x", sc->hn_ndis_ver)); /* * NOTE: Modified: stable/10/sys/dev/hyperv/netvsc/if_hnreg.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/if_hnreg.h Fri Nov 11 02:42:53 2016 (r308493) +++ stable/10/sys/dev/hyperv/netvsc/if_hnreg.h Fri Nov 11 03:03:54 2016 (r308494) @@ -36,6 +36,7 @@ * NDIS protocol version numbers */ #define HN_NDIS_VERSION_6_1 0x00060001 +#define HN_NDIS_VERSION_6_20 0x00060014 #define HN_NDIS_VERSION_6_30 0x0006001e #define HN_NDIS_VERSION_MAJOR(ver) (((ver) & 0xffff0000) >> 16) #define HN_NDIS_VERSION_MINOR(ver) ((ver) & 0xffff) Modified: stable/10/sys/dev/hyperv/netvsc/if_hnvar.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 02:42:53 2016 (r308493) +++ stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 03:03:54 2016 (r308494) @@ -122,7 +122,7 @@ void hn_rndis_detach(struct hn_softc *s int hn_rndis_conf_rss(struct hn_softc *sc, uint16_t flags); void *hn_rndis_pktinfo_append(struct rndis_packet_msg *, size_t pktsize, size_t pi_dlen, uint32_t pi_type); -int hn_rndis_get_rsscaps(struct hn_softc *sc, int *rxr_cnt); +int hn_rndis_query_rsscaps(struct hn_softc *sc, int *rxr_cnt); int hn_rndis_get_eaddr(struct hn_softc *sc, uint8_t *eaddr); int hn_rndis_get_linkstatus(struct hn_softc *sc, uint32_t *link_status); @@ -139,6 +139,7 @@ int hn_rxpkt(struct hn_rx_ring *rxr, co const struct hn_recvinfo *info); void hn_chan_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr); void hn_link_status_update(struct hn_softc *sc); +void hn_network_change(struct hn_softc *sc); extern struct hn_send_ctx hn_send_ctx_none; Modified: stable/10/sys/dev/hyperv/netvsc/ndis.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/ndis.h Fri Nov 11 02:42:53 2016 (r308493) +++ stable/10/sys/dev/hyperv/netvsc/ndis.h Fri Nov 11 03:03:54 2016 (r308494) @@ -32,6 +32,10 @@ #define NDIS_MEDIA_STATE_CONNECTED 0 #define NDIS_MEDIA_STATE_DISCONNECTED 1 +#define NDIS_NETCHANGE_TYPE_POSSIBLE 1 +#define NDIS_NETCHANGE_TYPE_DEFINITE 2 +#define NDIS_NETCHANGE_TYPE_FROMMEDIA 3 + #define NDIS_OFFLOAD_SET_NOCHG 0 #define NDIS_OFFLOAD_SET_ON 1 #define NDIS_OFFLOAD_SET_OFF 2 Modified: stable/10/sys/net/rndis.h ============================================================================== --- stable/10/sys/net/rndis.h Fri Nov 11 02:42:53 2016 (r308493) +++ stable/10/sys/net/rndis.h Fri Nov 11 03:03:54 2016 (r308494) @@ -320,6 +320,10 @@ struct rndis_status_msg { /* rndis_diag_info */ }; +/* stbuf offset from the beginning of rndis_status_msg. */ +#define RNDIS_STBUFOFFSET_ABS(ofs) \ + ((ofs) + __offsetof(struct rndis_status_msg, rm_status)) + /* * Immediately after rndis_status_msg.rm_stbufoffset, if a control * message is malformatted, or a packet message contains inappropriate From owner-svn-src-stable-10@freebsd.org Fri Nov 11 03:09:17 2016 Return-Path: Delivered-To: svn-src-stable-10@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 63338C38432; Fri, 11 Nov 2016 03:09:17 +0000 (UTC) (envelope-from sephe@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 3234BBD8; Fri, 11 Nov 2016 03:09:17 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB39GBD083009; Fri, 11 Nov 2016 03:09:16 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB39Faq083003; Fri, 11 Nov 2016 03:09:15 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110309.uAB39Faq083003@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 03:09:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308495 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 03:09:17 -0000 Author: sephe Date: Fri Nov 11 03:09:15 2016 New Revision: 308495 URL: https://svnweb.freebsd.org/changeset/base/308495 Log: MFC 307838,307839 307838 hyperv/hn: Move chimney buffer index and size to txdesc. All RNDIS control messages have used SG list for a while. This makes the send context suitable for further refactoring. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8308 307839 hyperv/hn: Fix chimney sending buffer leakage upon NVS sending failure. This will not happen in real world, since TX consumption of the vmbus TX bufring is limitted. Better safe than sorry. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8309 Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Fri Nov 11 03:03:54 2016 (r308494) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Fri Nov 11 03:09:15 2016 (r308495) @@ -116,7 +116,7 @@ hn_nvs_xact_execute(struct hn_softc *sc, /* * Execute the xact setup by the caller. */ - hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact); + hn_send_ctx_init(&sndc, hn_nvs_sent_xact, xact); vmbus_xact_activate(xact); error = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_RC, @@ -668,34 +668,6 @@ hn_chim_free(struct hn_softc *sc, uint32 atomic_clear_long(&sc->hn_chim_bmap[idx], mask); } -/* - * Net VSC on send - * Sends a packet on the specified Hyper-V device. - * Returns 0 on success, non-zero on failure. - */ -int -hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype, - struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt) -{ - struct hn_nvs_rndis rndis; - int ret; - - rndis.nvs_type = HN_NVS_TYPE_RNDIS; - rndis.nvs_rndis_mtype = rndis_mtype; - rndis.nvs_chim_idx = sndc->hn_chim_idx; - rndis.nvs_chim_sz = sndc->hn_chim_sz; - - if (gpa_cnt) { - ret = hn_nvs_send_sglist(chan, gpa, gpa_cnt, - &rndis, sizeof(rndis), sndc); - } else { - ret = hn_nvs_send(chan, VMBUS_CHANPKT_FLAG_RC, - &rndis, sizeof(rndis), sndc); - } - - return (ret); -} - int hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch0) { Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 03:03:54 2016 (r308494) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 03:09:15 2016 (r308495) @@ -104,8 +104,8 @@ struct vmbus_channel; #define HN_XACT_REQ_SIZE (HN_XACT_REQ_PGCNT * PAGE_SIZE) #define HN_XACT_RESP_SIZE (HN_XACT_RESP_PGCNT * PAGE_SIZE) -#ifndef HN_USE_TXDESC_BUFRING struct hn_txdesc; +#ifndef HN_USE_TXDESC_BUFRING SLIST_HEAD(hn_txdesc_list, hn_txdesc); #else struct buf_ring; @@ -179,6 +179,7 @@ struct hn_tx_ring { bus_dma_tag_t hn_tx_data_dtag; uint64_t hn_csum_assist; + int (*hn_sendpkt)(struct hn_tx_ring *, struct hn_txdesc *); int hn_suspended; int hn_gpa_cnt; struct vmbus_gpa hn_gpa[NETVSC_PACKET_MAXPAGE]; @@ -277,13 +278,5 @@ struct hn_softc { #define HN_LINK_FLAG_LINKUP 0x0001 #define HN_LINK_FLAG_NETCHG 0x0002 -/* - * Externs - */ -struct hn_send_ctx; - -int hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype, - struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt); - #endif /* __HV_NET_VSC_H__ */ Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 03:03:54 2016 (r308494) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 03:09:15 2016 (r308495) @@ -171,6 +171,8 @@ struct hn_txdesc { int refs; uint32_t flags; /* HN_TXD_FLAG_ */ struct hn_send_ctx send_ctx; + uint32_t chim_index; + int chim_size; bus_dmamap_t data_dmap; @@ -365,6 +367,8 @@ static void hn_tx_resume(struct hn_softc static void hn_tx_ring_qflush(struct hn_tx_ring *); static int netvsc_detach(device_t dev); static void hn_link_status(struct hn_softc *); +static int hn_sendpkt_rndis_sglist(struct hn_tx_ring *, struct hn_txdesc *); +static int hn_sendpkt_rndis_chim(struct hn_tx_ring *, struct hn_txdesc *); static void hn_nvs_handle_notify(struct hn_softc *sc, const struct vmbus_chanpkt_hdr *pkt); @@ -401,6 +405,57 @@ hn_set_lro_lenlim(struct hn_softc *sc, i } #endif +static __inline int +hn_nvs_send_rndis_sglist1(struct vmbus_channel *chan, uint32_t rndis_mtype, + struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt) +{ + struct hn_nvs_rndis rndis; + + rndis.nvs_type = HN_NVS_TYPE_RNDIS; + rndis.nvs_rndis_mtype = rndis_mtype; + rndis.nvs_chim_idx = HN_NVS_CHIM_IDX_INVALID; + rndis.nvs_chim_sz = 0; + + return (hn_nvs_send_sglist(chan, gpa, gpa_cnt, + &rndis, sizeof(rndis), sndc)); +} + +int +hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan, + struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt) +{ + + return hn_nvs_send_rndis_sglist1(chan, HN_NVS_RNDIS_MTYPE_CTRL, + sndc, gpa, gpa_cnt); +} + +static int +hn_sendpkt_rndis_sglist(struct hn_tx_ring *txr, struct hn_txdesc *txd) +{ + + KASSERT(txd->chim_index == HN_NVS_CHIM_IDX_INVALID && + txd->chim_size == 0, ("invalid rndis sglist txd")); + return (hn_nvs_send_rndis_sglist1(txr->hn_chan, HN_NVS_RNDIS_MTYPE_DATA, + &txd->send_ctx, txr->hn_gpa, txr->hn_gpa_cnt)); +} + +static int +hn_sendpkt_rndis_chim(struct hn_tx_ring *txr, struct hn_txdesc *txd) +{ + struct hn_nvs_rndis rndis; + + KASSERT(txd->chim_index != HN_NVS_CHIM_IDX_INVALID && + txd->chim_size > 0, ("invalid rndis chim txd")); + + rndis.nvs_type = HN_NVS_TYPE_RNDIS; + rndis.nvs_rndis_mtype = HN_NVS_RNDIS_MTYPE_DATA; + rndis.nvs_chim_idx = txd->chim_index; + rndis.nvs_chim_sz = txd->chim_size; + + return (hn_nvs_send(txr->hn_chan, VMBUS_CHANPKT_FLAG_RC, + &rndis, sizeof(rndis), &txd->send_ctx)); +} + static int hn_get_txswq_depth(const struct hn_tx_ring *txr) { @@ -912,6 +967,8 @@ hn_txdesc_dmamap_load(struct hn_tx_ring struct mbuf *m = *m_head; int error; + KASSERT(txd->chim_index == HN_NVS_CHIM_IDX_INVALID, ("txd uses chim")); + error = bus_dmamap_load_mbuf_sg(txr->hn_tx_data_dtag, txd->data_dmap, m, segs, nsegs, BUS_DMA_NOWAIT); if (error == EFBIG) { @@ -935,19 +992,6 @@ hn_txdesc_dmamap_load(struct hn_tx_ring return error; } -static __inline void -hn_txdesc_dmamap_unload(struct hn_tx_ring *txr, struct hn_txdesc *txd) -{ - - if (txd->flags & HN_TXD_FLAG_DMAMAP) { - bus_dmamap_sync(txr->hn_tx_data_dtag, - txd->data_dmap, BUS_DMASYNC_POSTWRITE); - bus_dmamap_unload(txr->hn_tx_data_dtag, - txd->data_dmap); - txd->flags &= ~HN_TXD_FLAG_DMAMAP; - } -} - static __inline int hn_txdesc_put(struct hn_tx_ring *txr, struct hn_txdesc *txd) { @@ -959,14 +1003,25 @@ hn_txdesc_put(struct hn_tx_ring *txr, st if (atomic_fetchadd_int(&txd->refs, -1) != 1) return 0; - hn_txdesc_dmamap_unload(txr, txd); + if (txd->chim_index != HN_NVS_CHIM_IDX_INVALID) { + KASSERT((txd->flags & HN_TXD_FLAG_DMAMAP) == 0, + ("chim txd uses dmamap")); + hn_chim_free(txr->hn_sc, txd->chim_index); + txd->chim_index = HN_NVS_CHIM_IDX_INVALID; + } else if (txd->flags & HN_TXD_FLAG_DMAMAP) { + bus_dmamap_sync(txr->hn_tx_data_dtag, + txd->data_dmap, BUS_DMASYNC_POSTWRITE); + bus_dmamap_unload(txr->hn_tx_data_dtag, + txd->data_dmap); + txd->flags &= ~HN_TXD_FLAG_DMAMAP; + } + if (txd->m != NULL) { m_freem(txd->m); txd->m = NULL; } txd->flags |= HN_TXD_FLAG_ONLIST; - #ifndef HN_USE_TXDESC_BUFRING mtx_lock_spin(&txr->hn_txlist_spin); KASSERT(txr->hn_txdesc_avail >= 0 && @@ -1007,7 +1062,9 @@ hn_txdesc_get(struct hn_tx_ring *txr) atomic_subtract_int(&txr->hn_txdesc_avail, 1); #endif KASSERT(txd->m == NULL && txd->refs == 0 && - (txd->flags & HN_TXD_FLAG_ONLIST), ("invalid txd")); + txd->chim_index == HN_NVS_CHIM_IDX_INVALID && + (txd->flags & HN_TXD_FLAG_ONLIST) && + (txd->flags & HN_TXD_FLAG_DMAMAP) == 0, ("invalid txd")); txd->flags &= ~HN_TXD_FLAG_ONLIST; txd->refs = 1; } @@ -1054,9 +1111,6 @@ hn_tx_done(struct hn_send_ctx *sndc, str struct hn_txdesc *txd = sndc->hn_cbarg; struct hn_tx_ring *txr; - if (sndc->hn_chim_idx != HN_NVS_CHIM_IDX_INVALID) - hn_chim_free(sc, sndc->hn_chim_idx); - txr = txd->txr; KASSERT(txr->hn_chan == chan, ("channel mismatch, on chan%u, should be chan%u", @@ -1118,9 +1172,8 @@ hn_encap(struct hn_tx_ring *txr, struct int error, nsegs, i; struct mbuf *m_head = *m_head0; struct rndis_packet_msg *pkt; - uint32_t send_buf_section_idx; - int send_buf_section_size, pktlen; uint32_t *pi_data; + int pktlen; /* * extension points to the area reserved for the @@ -1233,18 +1286,19 @@ hn_encap(struct hn_tx_ring *txr, struct */ if (pkt->rm_len < txr->hn_chim_size) { txr->hn_tx_chimney_tried++; - send_buf_section_idx = hn_chim_alloc(txr->hn_sc); - if (send_buf_section_idx != HN_NVS_CHIM_IDX_INVALID) { + txd->chim_index = hn_chim_alloc(txr->hn_sc); + if (txd->chim_index != HN_NVS_CHIM_IDX_INVALID) { uint8_t *dest = txr->hn_sc->hn_chim + - (send_buf_section_idx * txr->hn_sc->hn_chim_szmax); + (txd->chim_index * txr->hn_sc->hn_chim_szmax); memcpy(dest, pkt, pktlen); dest += pktlen; m_copydata(m_head, 0, m_head->m_pkthdr.len, dest); - send_buf_section_size = pkt->rm_len; + txd->chim_size = pkt->rm_len; txr->hn_gpa_cnt = 0; txr->hn_tx_chimney++; + txr->hn_sendpkt = hn_sendpkt_rndis_chim; goto done; } } @@ -1289,14 +1343,14 @@ hn_encap(struct hn_tx_ring *txr, struct gpa->gpa_len = segs[i].ds_len; } - send_buf_section_idx = HN_NVS_CHIM_IDX_INVALID; - send_buf_section_size = 0; + txd->chim_index = HN_NVS_CHIM_IDX_INVALID; + txd->chim_size = 0; + txr->hn_sendpkt = hn_sendpkt_rndis_sglist; done: txd->m = m_head; /* Set the completion routine */ - hn_send_ctx_init(&txd->send_ctx, hn_tx_done, txd, - send_buf_section_idx, send_buf_section_size); + hn_send_ctx_init(&txd->send_ctx, hn_tx_done, txd); return 0; } @@ -1316,8 +1370,7 @@ again: * Make sure that txd is not freed before ETHER_BPF_MTAP. */ hn_txdesc_hold(txd); - error = hv_nv_on_send(txr->hn_chan, HN_NVS_RNDIS_MTYPE_DATA, - &txd->send_ctx, txr->hn_gpa, txr->hn_gpa_cnt); + error = txr->hn_sendpkt(txr, txd); if (!error) { ETHER_BPF_MTAP(ifp, txd->m); if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); @@ -2786,6 +2839,7 @@ hn_create_tx_ring(struct hn_softc *sc, i struct hn_txdesc *txd = &txr->hn_txdesc[i]; txd->txr = txr; + txd->chim_index = HN_NVS_CHIM_IDX_INVALID; /* * Allocate and load RNDIS packet message. Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 03:03:54 2016 (r308494) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 03:09:15 2016 (r308495) @@ -586,8 +586,7 @@ hn_rndis_xact_exec1(struct hn_softc *sc, * message. */ vmbus_xact_activate(xact); - error = hv_nv_on_send(sc->hn_prichan, HN_NVS_RNDIS_MTYPE_CTRL, sndc, - gpa, gpa_cnt); + error = hn_nvs_send_rndis_ctrl(sc->hn_prichan, sndc, gpa, gpa_cnt); if (error) { vmbus_xact_deactivate(xact); if_printf(sc->hn_ifp, "RNDIS ctrl send failed: %d\n", error); @@ -1166,7 +1165,7 @@ hn_rndis_halt(struct hn_softc *sc) halt->rm_rid = hn_rndis_rid(sc); /* No RNDIS completion; rely on NVS message send completion */ - hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact); + hn_send_ctx_init(&sndc, hn_nvs_sent_xact, xact); hn_rndis_xact_exec1(sc, xact, sizeof(*halt), &sndc, &comp_len); vmbus_xact_put(xact); Modified: stable/10/sys/dev/hyperv/netvsc/if_hnvar.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 03:03:54 2016 (r308494) +++ stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 03:09:15 2016 (r308495) @@ -46,8 +46,6 @@ typedef void (*hn_sent_callback_t) struct hn_send_ctx { hn_sent_callback_t hn_cb; void *hn_cbarg; - uint32_t hn_chim_idx; - int hn_chim_sz; }; struct rndis_hash_info; @@ -66,31 +64,18 @@ struct hn_recvinfo { uint32_t hash_value; }; -#define HN_SEND_CTX_INITIALIZER(cb, cbarg) \ -{ \ - .hn_cb = cb, \ - .hn_cbarg = cbarg, \ - .hn_chim_idx = HN_NVS_CHIM_IDX_INVALID, \ - .hn_chim_sz = 0 \ +#define HN_SEND_CTX_INITIALIZER(cb, cbarg) \ +{ \ + .hn_cb = cb, \ + .hn_cbarg = cbarg \ } static __inline void -hn_send_ctx_init(struct hn_send_ctx *sndc, hn_sent_callback_t cb, - void *cbarg, uint32_t chim_idx, int chim_sz) +hn_send_ctx_init(struct hn_send_ctx *sndc, hn_sent_callback_t cb, void *cbarg) { sndc->hn_cb = cb; sndc->hn_cbarg = cbarg; - sndc->hn_chim_idx = chim_idx; - sndc->hn_chim_sz = chim_sz; -} - -static __inline void -hn_send_ctx_init_simple(struct hn_send_ctx *sndc, hn_sent_callback_t cb, - void *cbarg) -{ - - hn_send_ctx_init(sndc, cb, cbarg, HN_NVS_CHIM_IDX_INVALID, 0); } static __inline int @@ -134,6 +119,9 @@ void hn_nvs_detach(struct hn_softc *sc) int hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch); void hn_nvs_sent_xact(struct hn_send_ctx *sndc, struct hn_softc *sc, struct vmbus_channel *chan, const void *data, int dlen); +int hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan, + struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, + int gpa_cnt); int hn_rxpkt(struct hn_rx_ring *rxr, const void *data, int dlen, const struct hn_recvinfo *info); From owner-svn-src-stable-10@freebsd.org Fri Nov 11 03:15:53 2016 Return-Path: Delivered-To: svn-src-stable-10@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 5548CC38602; Fri, 11 Nov 2016 03:15:53 +0000 (UTC) (envelope-from sephe@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 172A012; Fri, 11 Nov 2016 03:15:53 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB3FqfH086909; Fri, 11 Nov 2016 03:15:52 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB3Fq6F086908; Fri, 11 Nov 2016 03:15:52 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110315.uAB3Fq6F086908@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 03:15:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308496 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 03:15:53 -0000 Author: sephe Date: Fri Nov 11 03:15:52 2016 New Revision: 308496 URL: https://svnweb.freebsd.org/changeset/base/308496 Log: MFC 307840,307842 307840 hyperv/hn: Properly handle synthetic parts reattach failure. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8310 307842 hyperv/hn: Start link status check, if no network changes were pending. Link status check is much more lightweight than network change detection. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8311 Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 03:09:15 2016 (r308495) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 03:15:52 2016 (r308496) @@ -1803,19 +1803,6 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, break; } - /* Obtain and record requested MTU */ - ifp->if_mtu = ifr->ifr_mtu; - -#if __FreeBSD_version >= 1100099 - /* - * Make sure that LRO aggregation length limit is still - * valid, after the MTU change. - */ - if (sc->hn_rx_ring[0].hn_lro.lro_length_lim < - HN_LRO_LENLIM_MIN(ifp)) - hn_set_lro_lenlim(sc, HN_LRO_LENLIM_MIN(ifp)); -#endif - /* * Suspend this interface before the synthetic parts * are ripped. @@ -1830,13 +1817,31 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, /* * Reattach the synthetic parts, i.e. NVS and RNDIS, * with the new MTU setting. - * XXX check error. */ - hn_synth_attach(sc, ifr->ifr_mtu); + error = hn_synth_attach(sc, ifr->ifr_mtu); + if (error) { + HN_UNLOCK(sc); + break; + } + /* + * Commit the requested MTU, after the synthetic parts + * have been successfully attached. + */ + ifp->if_mtu = ifr->ifr_mtu; + + /* + * Make sure that various parameters based on MTU are + * still valid, after the MTU change. + */ if (sc->hn_tx_ring[0].hn_chim_size > sc->hn_chim_szmax) hn_set_chim_size(sc, sc->hn_chim_szmax); - hn_set_tso_maxsize(sc, hn_tso_maxlen, ifr->ifr_mtu); + hn_set_tso_maxsize(sc, hn_tso_maxlen, ifp->if_mtu); +#if __FreeBSD_version >= 1100099 + if (sc->hn_rx_ring[0].hn_lro.lro_length_lim < + HN_LRO_LENLIM_MIN(ifp)) + hn_set_lro_lenlim(sc, HN_LRO_LENLIM_MIN(ifp)); +#endif /* * All done! Resume the interface now. @@ -3923,12 +3928,18 @@ static void hn_resume_mgmt(struct hn_softc *sc) { + sc->hn_mgmt_taskq = sc->hn_mgmt_taskq0; + /* - * Kick off network change detection, which will - * do link status check too. + * Kick off network change detection, if it was pending. + * If no network change was pending, start link status + * checks, which is more lightweight than network change + * detection. */ - sc->hn_mgmt_taskq = sc->hn_mgmt_taskq0; - hn_network_change(sc); + if (sc->hn_link_flags & HN_LINK_FLAG_NETCHG) + hn_network_change(sc); + else + hn_link_status_update(sc); } static void From owner-svn-src-stable-10@freebsd.org Fri Nov 11 03:22:23 2016 Return-Path: Delivered-To: svn-src-stable-10@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 A8746C38810; Fri, 11 Nov 2016 03:22:23 +0000 (UTC) (envelope-from sephe@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 652B76C9; Fri, 11 Nov 2016 03:22:23 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB3MM8C090668; Fri, 11 Nov 2016 03:22:22 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB3MMFW090362; Fri, 11 Nov 2016 03:22:22 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110322.uAB3MMFW090362@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 03:22:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308497 - in stable/10/sys: dev/hyperv/netvsc net X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 03:22:23 -0000 Author: sephe Date: Fri Nov 11 03:22:22 2016 New Revision: 308497 URL: https://svnweb.freebsd.org/changeset/base/308497 Log: MFC 307843 hyperv/hn: Fix RX filter settings. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8313 Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/net/rndis.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 03:15:52 2016 (r308496) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 03:22:22 2016 (r308497) @@ -233,6 +233,7 @@ struct hn_softc { struct sysctl_oid *hn_rx_sysctl_tree; struct vmbus_xact_ctx *hn_xact; uint32_t hn_nvs_ver; + uint32_t hn_rx_filter; struct taskqueue *hn_mgmt_taskq; struct taskqueue *hn_mgmt_taskq0; Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 03:15:52 2016 (r308496) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 03:22:22 2016 (r308497) @@ -328,6 +328,7 @@ static int hn_tx_conf_int_sysctl(SYSCTL_ static int hn_ndis_version_sysctl(SYSCTL_HANDLER_ARGS); static int hn_caps_sysctl(SYSCTL_HANDLER_ARGS); static int hn_hwassist_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_rxfilter_sysctl(SYSCTL_HANDLER_ARGS); static int hn_rss_key_sysctl(SYSCTL_HANDLER_ARGS); static int hn_rss_ind_sysctl(SYSCTL_HANDLER_ARGS); static int hn_check_iplen(const struct mbuf *, int); @@ -369,6 +370,7 @@ static int netvsc_detach(device_t dev); static void hn_link_status(struct hn_softc *); static int hn_sendpkt_rndis_sglist(struct hn_tx_ring *, struct hn_txdesc *); static int hn_sendpkt_rndis_chim(struct hn_tx_ring *, struct hn_txdesc *); +static int hn_set_rxfilter(struct hn_softc *); static void hn_nvs_handle_notify(struct hn_softc *sc, const struct vmbus_chanpkt_hdr *pkt); @@ -457,6 +459,43 @@ hn_sendpkt_rndis_chim(struct hn_tx_ring } static int +hn_set_rxfilter(struct hn_softc *sc) +{ + struct ifnet *ifp = sc->hn_ifp; + uint32_t filter; + int error = 0; + + HN_LOCK_ASSERT(sc); + + if (ifp->if_flags & IFF_PROMISC) { + filter = NDIS_PACKET_TYPE_PROMISCUOUS; + } else { + filter = NDIS_PACKET_TYPE_DIRECTED; + if (ifp->if_flags & IFF_BROADCAST) + filter |= NDIS_PACKET_TYPE_BROADCAST; +#ifdef notyet + /* + * See the comment in SIOCADDMULTI/SIOCDELMULTI. + */ + /* TODO: support multicast list */ + if ((ifp->if_flags & IFF_ALLMULTI) || + !TAILQ_EMPTY(&ifp->if_multiaddrs)) + filter |= NDIS_PACKET_TYPE_ALL_MULTICAST; +#else + /* Always enable ALLMULTI */ + filter |= NDIS_PACKET_TYPE_ALL_MULTICAST; +#endif + } + + if (sc->hn_rx_filter != filter) { + error = hn_rndis_set_rxfilter(sc, filter); + if (!error) + sc->hn_rx_filter = filter; + } + return (error); +} + +static int hn_get_txswq_depth(const struct hn_tx_ring *txr) { @@ -744,6 +783,9 @@ netvsc_attach(device_t dev) SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "hwassist", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, hn_hwassist_sysctl, "A", "hwassist"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rxfilter", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, + hn_rxfilter_sysctl, "A", "rxfilter"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rss_key", CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, hn_rss_key_sysctl, "IU", "RSS key"); @@ -1860,31 +1902,13 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, } if (ifp->if_flags & IFF_UP) { - /* - * If only the state of the PROMISC flag changed, - * then just use the 'set promisc mode' command - * instead of reinitializing the entire NIC. Doing - * a full re-init means reloading the firmware and - * waiting for it to start up, which may take a - * second or two. - */ -#ifdef notyet - /* Fixme: Promiscuous mode? */ - if (ifp->if_drv_flags & IFF_DRV_RUNNING && - ifp->if_flags & IFF_PROMISC && - !(sc->hn_if_flags & IFF_PROMISC)) { - /* do something here for Hyper-V */ - } else if (ifp->if_drv_flags & IFF_DRV_RUNNING && - !(ifp->if_flags & IFF_PROMISC) && - sc->hn_if_flags & IFF_PROMISC) { - /* do something here for Hyper-V */ - } else -#endif + if (ifp->if_drv_flags & IFF_DRV_RUNNING) + hn_set_rxfilter(sc); + else hn_init_locked(sc); } else { - if (ifp->if_drv_flags & IFF_DRV_RUNNING) { + if (ifp->if_drv_flags & IFF_DRV_RUNNING) hn_stop(sc); - } } sc->hn_if_flags = ifp->if_flags; @@ -1942,12 +1966,27 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, case SIOCADDMULTI: case SIOCDELMULTI: - /* Always all-multi */ +#ifdef notyet /* - * TODO: - * Enable/disable all-multi according to the emptiness of - * the mcast address list. + * XXX + * Multicast uses mutex, while RNDIS RX filter setting + * sleeps. We workaround this by always enabling + * ALLMULTI. ALLMULTI would actually always be on, even + * if we supported the SIOCADDMULTI/SIOCDELMULTI, since + * we don't support multicast address list configuration + * for this driver. */ + HN_LOCK(sc); + + if ((sc->hn_flags & HN_FLAG_SYNTH_ATTACHED) == 0) { + HN_UNLOCK(sc); + break; + } + if (ifp->if_drv_flags & IFF_DRV_RUNNING) + hn_set_rxfilter(sc); + + HN_UNLOCK(sc); +#endif break; case SIOCSIFMEDIA: @@ -2055,8 +2094,8 @@ hn_init_locked(struct hn_softc *sc) if (ifp->if_drv_flags & IFF_DRV_RUNNING) return; - /* TODO: add hn_rx_filter */ - hn_rndis_set_rxfilter(sc, NDIS_PACKET_TYPE_PROMISCUOUS); + /* Configure RX filter */ + hn_set_rxfilter(sc); /* Clear OACTIVE bit. */ atomic_clear_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); @@ -2383,6 +2422,21 @@ hn_hwassist_sysctl(SYSCTL_HANDLER_ARGS) } static int +hn_rxfilter_sysctl(SYSCTL_HANDLER_ARGS) +{ + struct hn_softc *sc = arg1; + char filter_str[128]; + uint32_t filter; + + HN_LOCK(sc); + filter = sc->hn_rx_filter; + HN_UNLOCK(sc); + snprintf(filter_str, sizeof(filter_str), "%b", filter, + NDIS_PACKET_TYPES); + return sysctl_handle_string(oidp, filter_str, sizeof(filter_str), req); +} + +static int hn_rss_key_sysctl(SYSCTL_HANDLER_ARGS) { struct hn_softc *sc = arg1; @@ -3803,6 +3857,7 @@ hn_suspend_data(struct hn_softc *sc) * Disable RX by clearing RX filter. */ hn_rndis_set_rxfilter(sc, 0); + sc->hn_rx_filter = 0; /* * Give RNDIS enough time to flush all pending data packets. @@ -3890,9 +3945,8 @@ hn_resume_data(struct hn_softc *sc) /* * Re-enable RX. - * TODO: add hn_rx_filter. */ - hn_rndis_set_rxfilter(sc, NDIS_PACKET_TYPE_PROMISCUOUS); + hn_set_rxfilter(sc); /* * Make sure to clear suspend status on "all" TX rings, Modified: stable/10/sys/net/rndis.h ============================================================================== --- stable/10/sys/net/rndis.h Fri Nov 11 03:15:52 2016 (r308496) +++ stable/10/sys/net/rndis.h Fri Nov 11 03:22:22 2016 (r308497) @@ -351,7 +351,7 @@ struct rndis_keepalive_comp { uint32_t rm_status; }; -/* packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */ +/* Packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */ #define NDIS_PACKET_TYPE_DIRECTED 0x00000001 #define NDIS_PACKET_TYPE_MULTICAST 0x00000002 #define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004 @@ -365,6 +365,14 @@ struct rndis_keepalive_comp { #define NDIS_PACKET_TYPE_FUNCTIONAL 0x00004000 #define NDIS_PACKET_TYPE_MAC_FRAME 0x00008000 +/* + * Packet filter description for use with printf(9) %b identifier. + */ +#define NDIS_PACKET_TYPES \ + "\20\1DIRECT\2MULTICAST\3ALLMULTI\4BROADCAST" \ + "\5SRCROUTE\6PROMISC\7SMT\10ALLLOCAL" \ + "\11GROUP\12ALLFUNC\13FUNC\14MACFRAME" + /* RNDIS offsets */ #define RNDIS_HEADER_OFFSET ((uint32_t)sizeof(struct rndis_msghdr)) #define RNDIS_DATA_OFFSET \ From owner-svn-src-stable-10@freebsd.org Fri Nov 11 03:41:37 2016 Return-Path: Delivered-To: svn-src-stable-10@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 5506FC38C2A; Fri, 11 Nov 2016 03:41:37 +0000 (UTC) (envelope-from sephe@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 24A9CED4; Fri, 11 Nov 2016 03:41:37 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB3faoY095522; Fri, 11 Nov 2016 03:41:36 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB3faiM095521; Fri, 11 Nov 2016 03:41:36 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110341.uAB3faiM095521@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 03:41:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308498 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 03:41:37 -0000 Author: sephe Date: Fri Nov 11 03:41:36 2016 New Revision: 308498 URL: https://svnweb.freebsd.org/changeset/base/308498 Log: MFC 307844 hyperv/hn: Nuke unused forward declaration. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8314 Modified: stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/if_hnvar.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 03:22:22 2016 (r308497) +++ stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 03:41:36 2016 (r308498) @@ -48,11 +48,6 @@ struct hn_send_ctx { void *hn_cbarg; }; -struct rndis_hash_info; -struct rndix_hash_value; -struct ndis_8021q_info_; -struct rndis_tcp_ip_csum_info_; - #define HN_NDIS_VLAN_INFO_INVALID 0xffffffff #define HN_NDIS_RXCSUM_INFO_INVALID 0 #define HN_NDIS_HASH_INFO_INVALID 0 From owner-svn-src-stable-10@freebsd.org Fri Nov 11 03:43:07 2016 Return-Path: Delivered-To: svn-src-stable-10@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 F2E26C38CE9; Fri, 11 Nov 2016 03:43:07 +0000 (UTC) (envelope-from sephe@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 C20201213; Fri, 11 Nov 2016 03:43:07 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB3h7x4098710; Fri, 11 Nov 2016 03:43:07 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB3h6Y1098700; Fri, 11 Nov 2016 03:43:06 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110343.uAB3h6Y1098700@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 03:43:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308499 - stable/10/sys/dev/hyperv/utilities X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 03:43:08 -0000 Author: sephe Date: Fri Nov 11 03:43:06 2016 New Revision: 308499 URL: https://svnweb.freebsd.org/changeset/base/308499 Log: MFC 307845 hyperv/ic: Rework framework/message version negotiation. Submitted by: Hongjiang Zhang Modified by: sephe Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8280 Modified: stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c stable/10/sys/dev/hyperv/utilities/hv_kvp.c stable/10/sys/dev/hyperv/utilities/hv_kvp.h stable/10/sys/dev/hyperv/utilities/hv_shutdown.c stable/10/sys/dev/hyperv/utilities/hv_timesync.c stable/10/sys/dev/hyperv/utilities/hv_util.c stable/10/sys/dev/hyperv/utilities/hv_util.h stable/10/sys/dev/hyperv/utilities/hv_utilreg.h stable/10/sys/dev/hyperv/utilities/vmbus_icreg.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c Fri Nov 11 03:41:36 2016 (r308498) +++ stable/10/sys/dev/hyperv/utilities/hv_heartbeat.c Fri Nov 11 03:43:06 2016 (r308499) @@ -40,6 +40,14 @@ __FBSDID("$FreeBSD$"); #include "vmbus_if.h" +#define VMBUS_HEARTBEAT_FWVER_MAJOR 3 +#define VMBUS_HEARTBEAT_FWVER \ + VMBUS_IC_VERSION(VMBUS_HEARTBEAT_FWVER_MAJOR, 0) + +#define VMBUS_HEARTBEAT_MSGVER_MAJOR 3 +#define VMBUS_HEARTBEAT_MSGVER \ + VMBUS_IC_VERSION(VMBUS_HEARTBEAT_MSGVER_MAJOR, 0) + static const struct vmbus_ic_desc vmbus_heartbeat_descs[] = { { .ic_guid = { .hv_guid = { @@ -80,7 +88,8 @@ vmbus_heartbeat_cb(struct vmbus_channel */ switch (hdr->ic_type) { case VMBUS_ICMSG_TYPE_NEGOTIATE: - error = vmbus_ic_negomsg(sc, data, &dlen); + error = vmbus_ic_negomsg(sc, data, &dlen, + VMBUS_HEARTBEAT_FWVER, VMBUS_HEARTBEAT_MSGVER); if (error) return; break; Modified: stable/10/sys/dev/hyperv/utilities/hv_kvp.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_kvp.c Fri Nov 11 03:41:36 2016 (r308498) +++ stable/10/sys/dev/hyperv/utilities/hv_kvp.c Fri Nov 11 03:43:06 2016 (r308499) @@ -61,7 +61,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include +#include #include "hv_util.h" #include "unicode.h" @@ -74,6 +76,12 @@ __FBSDID("$FreeBSD$"); #define KVP_ERROR 1 #define kvp_hdr hdr.kvp_hdr +#define KVP_FWVER_MAJOR 3 +#define KVP_FWVER VMBUS_IC_VERSION(KVP_FWVER_MAJOR, 0) + +#define KVP_MSGVER_MAJOR 4 +#define KVP_MSGVER VMBUS_IC_VERSION(KVP_MSGVER_MAJOR, 0) + /* hv_kvp debug control */ static int hv_kvp_log = 0; @@ -208,52 +216,10 @@ hv_kvp_transaction_init(hv_kvp_sc *sc, u sc->host_msg_id = request_id; sc->rcv_buf = rcv_buf; sc->host_kvp_msg = (struct hv_kvp_msg *)&rcv_buf[ - sizeof(struct hv_vmbus_pipe_hdr) + - sizeof(struct hv_vmbus_icmsg_hdr)]; + sizeof(struct hv_vmbus_pipe_hdr) + + sizeof(struct hv_vmbus_icmsg_hdr)]; } - -/* - * hv_kvp - version neogtiation function - */ -static void -hv_kvp_negotiate_version(struct hv_vmbus_icmsg_hdr *icmsghdrp, uint8_t *buf) -{ - struct hv_vmbus_icmsg_negotiate *negop; - int icframe_vercnt; - int icmsg_vercnt; - - icmsghdrp->icmsgsize = 0x10; - - negop = (struct hv_vmbus_icmsg_negotiate *)&buf[ - sizeof(struct hv_vmbus_pipe_hdr) + - sizeof(struct hv_vmbus_icmsg_hdr)]; - icframe_vercnt = negop->icframe_vercnt; - icmsg_vercnt = negop->icmsg_vercnt; - - /* - * Select the framework version number we will support - */ - if ((icframe_vercnt >= 2) && (negop->icversion_data[1].major == 3)) { - icframe_vercnt = 3; - if (icmsg_vercnt > 2) - icmsg_vercnt = 4; - else - icmsg_vercnt = 3; - } else { - icframe_vercnt = 1; - icmsg_vercnt = 1; - } - - negop->icframe_vercnt = 1; - negop->icmsg_vercnt = 1; - negop->icversion_data[0].major = icframe_vercnt; - negop->icversion_data[0].minor = 0; - negop->icversion_data[1].major = icmsg_vercnt; - negop->icversion_data[1].minor = 0; -} - - /* * Convert ip related info in umsg from utf8 to utf16 and store in hmsg */ @@ -578,7 +544,8 @@ hv_kvp_respond_host(hv_kvp_sc *sc, int e error = HV_KVP_E_FAIL; hv_icmsg_hdrp->status = error; - hv_icmsg_hdrp->icflags = HV_ICMSGHDRFLAG_TRANSACTION | HV_ICMSGHDRFLAG_RESPONSE; + hv_icmsg_hdrp->icflags = HV_ICMSGHDRFLAG_TRANSACTION | + HV_ICMSGHDRFLAG_RESPONSE; error = vmbus_chan_send(vmbus_get_channel(sc->dev), VMBUS_CHANPKT_TYPE_INBAND, 0, sc->rcv_buf, sc->host_msg_len, @@ -622,8 +589,8 @@ hv_kvp_process_request(void *context, in uint32_t recvlen = 0; uint64_t requestid; struct hv_vmbus_icmsg_hdr *icmsghdrp; - int ret = 0; - hv_kvp_sc *sc; + int ret = 0, error; + hv_kvp_sc *sc; hv_kvp_log_info("%s: entering hv_kvp_process_request\n", __func__); @@ -637,14 +604,15 @@ hv_kvp_process_request(void *context, in /* XXX check recvlen to make sure that it contains enough data */ while ((ret == 0) && (recvlen > 0)) { - icmsghdrp = (struct hv_vmbus_icmsg_hdr *) - &kvp_buf[sizeof(struct hv_vmbus_pipe_hdr)]; + &kvp_buf[sizeof(struct hv_vmbus_pipe_hdr)]; hv_kvp_transaction_init(sc, recvlen, requestid, kvp_buf); if (icmsghdrp->icmsgtype == HV_ICMSGTYPE_NEGOTIATE) { - hv_kvp_negotiate_version(icmsghdrp, kvp_buf); - hv_kvp_respond_host(sc, ret); + error = vmbus_ic_negomsg(&sc->util_sc, + kvp_buf, &recvlen, KVP_FWVER, KVP_MSGVER); + /* XXX handle vmbus_ic_negomsg failure. */ + hv_kvp_respond_host(sc, error); /* * It is ok to not acquire the mutex before setting Modified: stable/10/sys/dev/hyperv/utilities/hv_kvp.h ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_kvp.h Fri Nov 11 03:41:36 2016 (r308498) +++ stable/10/sys/dev/hyperv/utilities/hv_kvp.h Fri Nov 11 03:43:06 2016 (r308499) @@ -28,7 +28,6 @@ #ifndef _KVP_H #define _KVP_H - /* * An implementation of HyperV key value pair (KVP) functionality for FreeBSD * @@ -178,9 +177,9 @@ struct hv_kvp_ipaddr_value { }__attribute__((packed)); struct hv_kvp_hdr { - uint8_t operation; - uint8_t pool; - uint16_t pad; + uint8_t operation; + uint8_t pool; + uint16_t pad; } __attribute__((packed)); struct hv_kvp_exchg_msg_value { Modified: stable/10/sys/dev/hyperv/utilities/hv_shutdown.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_shutdown.c Fri Nov 11 03:41:36 2016 (r308498) +++ stable/10/sys/dev/hyperv/utilities/hv_shutdown.c Fri Nov 11 03:43:06 2016 (r308499) @@ -41,6 +41,14 @@ __FBSDID("$FreeBSD$"); #include "vmbus_if.h" +#define VMBUS_SHUTDOWN_FWVER_MAJOR 3 +#define VMBUS_SHUTDOWN_FWVER \ + VMBUS_IC_VERSION(VMBUS_SHUTDOWN_FWVER_MAJOR, 0) + +#define VMBUS_SHUTDOWN_MSGVER_MAJOR 3 +#define VMBUS_SHUTDOWN_MSGVER \ + VMBUS_IC_VERSION(VMBUS_SHUTDOWN_MSGVER_MAJOR, 0) + static const struct vmbus_ic_desc vmbus_shutdown_descs[] = { { .ic_guid = { .hv_guid = { @@ -82,7 +90,8 @@ vmbus_shutdown_cb(struct vmbus_channel * */ switch (hdr->ic_type) { case VMBUS_ICMSG_TYPE_NEGOTIATE: - error = vmbus_ic_negomsg(sc, data, &dlen); + error = vmbus_ic_negomsg(sc, data, &dlen, + VMBUS_SHUTDOWN_FWVER, VMBUS_SHUTDOWN_MSGVER); if (error) return; break; Modified: stable/10/sys/dev/hyperv/utilities/hv_timesync.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_timesync.c Fri Nov 11 03:41:36 2016 (r308498) +++ stable/10/sys/dev/hyperv/utilities/hv_timesync.c Fri Nov 11 03:43:06 2016 (r308499) @@ -42,6 +42,14 @@ __FBSDID("$FreeBSD$"); #include "vmbus_if.h" +#define VMBUS_TIMESYNC_FWVER_MAJOR 3 +#define VMBUS_TIMESYNC_FWVER \ + VMBUS_IC_VERSION(VMBUS_TIMESYNC_FWVER_MAJOR, 0) + +#define VMBUS_TIMESYNC_MSGVER_MAJOR 3 +#define VMBUS_TIMESYNC_MSGVER \ + VMBUS_IC_VERSION(VMBUS_TIMESYNC_MSGVER_MAJOR, 0) + static const struct vmbus_ic_desc vmbus_timesync_descs[] = { { .ic_guid = { .hv_guid = { @@ -162,7 +170,8 @@ vmbus_timesync_cb(struct vmbus_channel * */ switch (hdr->ic_type) { case VMBUS_ICMSG_TYPE_NEGOTIATE: - error = vmbus_ic_negomsg(sc, data, &dlen); + error = vmbus_ic_negomsg(sc, data, &dlen, + VMBUS_TIMESYNC_FWVER, VMBUS_TIMESYNC_MSGVER); if (error) return; break; Modified: stable/10/sys/dev/hyperv/utilities/hv_util.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_util.c Fri Nov 11 03:41:36 2016 (r308498) +++ stable/10/sys/dev/hyperv/utilities/hv_util.c Fri Nov 11 03:43:06 2016 (r308499) @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -53,52 +54,145 @@ __offsetof(struct vmbus_icmsg_negotiate, ic_ver[VMBUS_IC_VERCNT]) CTASSERT(VMBUS_IC_NEGOSZ < VMBUS_IC_BRSIZE); +static int vmbus_ic_fwver_sysctl(SYSCTL_HANDLER_ARGS); +static int vmbus_ic_msgver_sysctl(SYSCTL_HANDLER_ARGS); + int -vmbus_ic_negomsg(struct hv_util_sc *sc, void *data, int *dlen0) +vmbus_ic_negomsg(struct hv_util_sc *sc, void *data, int *dlen0, + uint32_t fw_ver, uint32_t msg_ver) { struct vmbus_icmsg_negotiate *nego; - int cnt, major, dlen = *dlen0; + int i, cnt, dlen = *dlen0, error; + uint32_t sel_fw_ver, sel_msg_ver; + bool has_fw_ver, has_msg_ver; /* - * Preliminary message size verification + * Preliminary message verification. */ if (dlen < sizeof(*nego)) { device_printf(sc->ic_dev, "truncated ic negotiate, len %d\n", dlen); - return EINVAL; + return (EINVAL); } nego = data; + if (nego->ic_fwver_cnt == 0) { + device_printf(sc->ic_dev, "ic negotiate does not contain " + "framework version %u\n", nego->ic_fwver_cnt); + return (EINVAL); + } + if (nego->ic_msgver_cnt == 0) { + device_printf(sc->ic_dev, "ic negotiate does not contain " + "message version %u\n", nego->ic_msgver_cnt); + return (EINVAL); + } + cnt = nego->ic_fwver_cnt + nego->ic_msgver_cnt; if (dlen < __offsetof(struct vmbus_icmsg_negotiate, ic_ver[cnt])) { device_printf(sc->ic_dev, "ic negotiate does not contain " "versions %d\n", dlen); - return EINVAL; + return (EINVAL); + } + + error = EOPNOTSUPP; + + /* + * Find the best match framework version. + */ + has_fw_ver = false; + for (i = 0; i < nego->ic_fwver_cnt; ++i) { + if (VMBUS_ICVER_LE(nego->ic_ver[i], fw_ver)) { + if (!has_fw_ver) { + sel_fw_ver = nego->ic_ver[i]; + has_fw_ver = true; + } else if (VMBUS_ICVER_GT(nego->ic_ver[i], + sel_fw_ver)) { + sel_fw_ver = nego->ic_ver[i]; + } + } + } + if (!has_fw_ver) { + device_printf(sc->ic_dev, "failed to select framework " + "version\n"); + goto done; + } + + /* + * Fine the best match message version. + */ + has_msg_ver = false; + for (i = nego->ic_fwver_cnt; + i < nego->ic_fwver_cnt + nego->ic_msgver_cnt; ++i) { + if (VMBUS_ICVER_LE(nego->ic_ver[i], msg_ver)) { + if (!has_msg_ver) { + sel_msg_ver = nego->ic_ver[i]; + has_msg_ver = true; + } else if (VMBUS_ICVER_GT(nego->ic_ver[i], + sel_msg_ver)) { + sel_msg_ver = nego->ic_ver[i]; + } + } + } + if (!has_msg_ver) { + device_printf(sc->ic_dev, "failed to select message " + "version\n"); + goto done; } - /* Select major version; XXX looks wrong. */ - if (nego->ic_fwver_cnt >= 2 && VMBUS_ICVER_MAJOR(nego->ic_ver[1]) == 3) - major = 3; - else - major = 1; + error = 0; +done: + if (bootverbose || !has_fw_ver || !has_msg_ver) { + if (has_fw_ver) { + device_printf(sc->ic_dev, "sel framework version: " + "%u.%u\n", + VMBUS_ICVER_MAJOR(sel_fw_ver), + VMBUS_ICVER_MINOR(sel_fw_ver)); + } + for (i = 0; i < nego->ic_fwver_cnt; i++) { + device_printf(sc->ic_dev, "supp framework version: " + "%u.%u\n", + VMBUS_ICVER_MAJOR(nego->ic_ver[i]), + VMBUS_ICVER_MINOR(nego->ic_ver[i])); + } + + if (has_msg_ver) { + device_printf(sc->ic_dev, "sel message version: " + "%u.%u\n", + VMBUS_ICVER_MAJOR(sel_msg_ver), + VMBUS_ICVER_MINOR(sel_msg_ver)); + } + for (i = nego->ic_fwver_cnt; + i < nego->ic_fwver_cnt + nego->ic_msgver_cnt; i++) { + device_printf(sc->ic_dev, "supp message version: " + "%u.%u\n", + VMBUS_ICVER_MAJOR(nego->ic_ver[i]), + VMBUS_ICVER_MINOR(nego->ic_ver[i])); + } + } + if (error) + return (error); + + /* Record the selected versions. */ + sc->ic_fwver = sel_fw_ver; + sc->ic_msgver = sel_msg_ver; - /* One framework version */ + /* One framework version. */ nego->ic_fwver_cnt = 1; - nego->ic_ver[0] = VMBUS_IC_VERSION(major, 0); + nego->ic_ver[0] = sel_fw_ver; - /* One message version */ + /* One message version. */ nego->ic_msgver_cnt = 1; - nego->ic_ver[1] = VMBUS_IC_VERSION(major, 0); + nego->ic_ver[1] = sel_msg_ver; - /* Update data size */ + /* Update data size. */ nego->ic_hdr.ic_dsize = VMBUS_IC_NEGOSZ - sizeof(struct vmbus_icmsg_hdr); - /* Update total size, if necessary */ + /* Update total size, if necessary. */ if (dlen < VMBUS_IC_NEGOSZ) *dlen0 = VMBUS_IC_NEGOSZ; - return 0; + return (0); } int @@ -124,6 +218,8 @@ hv_util_attach(device_t dev, vmbus_chan_ { struct hv_util_sc *sc = device_get_softc(dev); struct vmbus_channel *chan = vmbus_get_channel(dev); + struct sysctl_oid_list *child; + struct sysctl_ctx_list *ctx; int error; sc->ic_dev = dev; @@ -146,9 +242,41 @@ hv_util_attach(device_t dev, vmbus_chan_ free(sc->receive_buffer, M_DEVBUF); return (error); } + + ctx = device_get_sysctl_ctx(dev); + child = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "fw_version", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, + vmbus_ic_fwver_sysctl, "A", "framework version"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "msg_version", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, + vmbus_ic_msgver_sysctl, "A", "message version"); + return (0); } +static int +vmbus_ic_fwver_sysctl(SYSCTL_HANDLER_ARGS) +{ + struct hv_util_sc *sc = arg1; + char verstr[16]; + + snprintf(verstr, sizeof(verstr), "%u.%u", + VMBUS_ICVER_MAJOR(sc->ic_fwver), VMBUS_ICVER_MINOR(sc->ic_fwver)); + return sysctl_handle_string(oidp, verstr, sizeof(verstr), req); +} + +static int +vmbus_ic_msgver_sysctl(SYSCTL_HANDLER_ARGS) +{ + struct hv_util_sc *sc = arg1; + char verstr[16]; + + snprintf(verstr, sizeof(verstr), "%u.%u", + VMBUS_ICVER_MAJOR(sc->ic_msgver), VMBUS_ICVER_MINOR(sc->ic_msgver)); + return sysctl_handle_string(oidp, verstr, sizeof(verstr), req); +} + int hv_util_detach(device_t dev) { Modified: stable/10/sys/dev/hyperv/utilities/hv_util.h ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_util.h Fri Nov 11 03:41:36 2016 (r308498) +++ stable/10/sys/dev/hyperv/utilities/hv_util.h Fri Nov 11 03:43:06 2016 (r308499) @@ -42,6 +42,8 @@ typedef struct hv_util_sc { device_t ic_dev; uint8_t *receive_buffer; int ic_buflen; + uint32_t ic_fwver; /* framework version */ + uint32_t ic_msgver; /* message version */ } hv_util_sc; struct vmbus_ic_desc { @@ -54,6 +56,7 @@ struct vmbus_ic_desc { int hv_util_attach(device_t dev, vmbus_chan_callback_t cb); int hv_util_detach(device_t dev); int vmbus_ic_probe(device_t dev, const struct vmbus_ic_desc descs[]); -int vmbus_ic_negomsg(struct hv_util_sc *, void *data, int *dlen); +int vmbus_ic_negomsg(struct hv_util_sc *sc, void *data, int *dlen, + uint32_t fw_ver, uint32_t msg_ver); #endif Modified: stable/10/sys/dev/hyperv/utilities/hv_utilreg.h ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_utilreg.h Fri Nov 11 03:41:36 2016 (r308498) +++ stable/10/sys/dev/hyperv/utilities/hv_utilreg.h Fri Nov 11 03:43:06 2016 (r308499) @@ -76,16 +76,4 @@ typedef struct hv_vmbus_icmsg_negotiate hv_vmbus_ic_version icversion_data[1]; /* any size array */ } __packed hv_vmbus_icmsg_negotiate; -typedef struct hv_vmbus_shutdown_msg_data { - uint32_t reason_code; - uint32_t timeout_seconds; - uint32_t flags; - uint8_t display_message[2048]; -} __packed hv_vmbus_shutdown_msg_data; - -typedef struct hv_vmbus_heartbeat_msg_data { - uint64_t seq_num; - uint32_t reserved[8]; -} __packed hv_vmbus_heartbeat_msg_data; - #endif /* !_HV_UTILREG_H_ */ Modified: stable/10/sys/dev/hyperv/utilities/vmbus_icreg.h ============================================================================== --- stable/10/sys/dev/hyperv/utilities/vmbus_icreg.h Fri Nov 11 03:41:36 2016 (r308498) +++ stable/10/sys/dev/hyperv/utilities/vmbus_icreg.h Fri Nov 11 03:43:06 2016 (r308499) @@ -42,6 +42,12 @@ #define VMBUS_IC_VERSION(major, minor) ((major) | (((uint32_t)(minor)) << 16)) #define VMBUS_ICVER_MAJOR(ver) ((ver) & 0xffff) #define VMBUS_ICVER_MINOR(ver) (((ver) & 0xffff0000) >> 16) +#define VMBUS_ICVER_SWAP(ver) \ + ((VMBUS_ICVER_MAJOR((ver)) << 16) | VMBUS_ICVER_MINOR((ver))) +#define VMBUS_ICVER_LE(v1, v2) \ + (VMBUS_ICVER_SWAP((v1)) <= VMBUS_ICVER_SWAP((v2))) +#define VMBUS_ICVER_GT(v1, v2) \ + (VMBUS_ICVER_SWAP((v1)) > VMBUS_ICVER_SWAP((v2))) struct vmbus_pipe_hdr { uint32_t ph_flags; From owner-svn-src-stable-10@freebsd.org Fri Nov 11 04:33:45 2016 Return-Path: Delivered-To: svn-src-stable-10@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 F28C1C398B1; Fri, 11 Nov 2016 04:33:44 +0000 (UTC) (envelope-from sephe@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 B7C136C8; Fri, 11 Nov 2016 04:33:44 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB4XhjH018411; Fri, 11 Nov 2016 04:33:43 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB4Xhlq018410; Fri, 11 Nov 2016 04:33:43 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110433.uAB4Xhlq018410@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 04:33:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308500 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 04:33:45 -0000 Author: sephe Date: Fri Nov 11 04:33:43 2016 New Revision: 308500 URL: https://svnweb.freebsd.org/changeset/base/308500 Log: MFC 307893 hyperv/hn: Set baudrate properly PR: 208931 Submitted by: Eugene Grosbein Reported by: Eugene Grosbein Sponsored by: Microsoft Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 03:43:06 2016 (r308499) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 04:33:43 2016 (r308500) @@ -805,6 +805,7 @@ netvsc_attach(device_t dev) * Setup the ifnet for this interface. */ + ifp->if_baudrate = IF_Gbps(10); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = hn_ioctl; ifp->if_init = hn_init; From owner-svn-src-stable-10@freebsd.org Fri Nov 11 04:39:03 2016 Return-Path: Delivered-To: svn-src-stable-10@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 E1F88C39A1A; Fri, 11 Nov 2016 04:39:03 +0000 (UTC) (envelope-from sephe@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 A503C92E; Fri, 11 Nov 2016 04:39:03 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB4d2bu018669; Fri, 11 Nov 2016 04:39:02 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB4d2su018667; Fri, 11 Nov 2016 04:39:02 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110439.uAB4d2su018667@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 04:39:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308501 - stable/10/sys/dev/hyperv/vmbus X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 04:39:04 -0000 Author: sephe Date: Fri Nov 11 04:39:02 2016 New Revision: 308501 URL: https://svnweb.freebsd.org/changeset/base/308501 Log: MFC 307952,307953,308278 307952 hyperv/vmbus: Add missing white space. Submitted by: QianYue You Sponsored by: Microsoft 307953 hyperv/vmbus: Implement vmbus_chan_printf. And use it for vmbus channel logging, which can log the channel owner's name properly, instead of vmbus0. Submitted by: QianYue You Sponsored by: Microsoft 308278 hyperv/vmbus: Reset ch_dev, once the child is deleted. So it will not be mis-used later on, e.g. in vmbus_chan_printf(). Submitted by: dexuan Reported by: dexuan Sponsored by: Microsoft Modified: stable/10/sys/dev/hyperv/vmbus/vmbus.c stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/vmbus.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus.c Fri Nov 11 04:33:43 2016 (r308500) +++ stable/10/sys/dev/hyperv/vmbus/vmbus.c Fri Nov 11 04:39:02 2016 (r308501) @@ -948,7 +948,7 @@ vmbus_intr_setup(struct vmbus_softc *sc) device_printf(sc->vmbus_dev, "cannot find free IDT vector\n"); return ENXIO; } - if(bootverbose) { + if (bootverbose) { device_printf(sc->vmbus_dev, "vmbus IDT vector %d\n", sc->vmbus_idtvec); } @@ -1036,6 +1036,7 @@ vmbus_delete_child(struct vmbus_channel if (chan->ch_dev != NULL) { error = device_delete_child(chan->ch_vmbus->vmbus_dev, chan->ch_dev); + chan->ch_dev = NULL; } mtx_unlock(&Giant); return (error); Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Fri Nov 11 04:33:43 2016 (r308500) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Fri Nov 11 04:39:02 2016 (r308501) @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -39,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -90,6 +92,9 @@ static void vmbus_chan_msgproc_chresci struct vmbus_softc *, const struct vmbus_message *); +static int vmbus_chan_printf(const struct vmbus_channel *, + const char *, ...) __printflike(2, 3); + /* * Vmbus channel message processing. */ @@ -304,7 +309,7 @@ vmbus_chan_open(struct vmbus_channel *ch PAGE_SIZE, 0, txbr_size + rxbr_size, &chan->ch_bufring_dma, BUS_DMA_WAITOK); if (chan->ch_bufring == NULL) { - device_printf(chan->ch_dev, "bufring allocation failed\n"); + vmbus_chan_printf(chan, "bufring allocation failed\n"); return (ENOMEM); } @@ -336,7 +341,7 @@ vmbus_chan_open_br(struct vmbus_channel uint8_t *br; if (udlen > VMBUS_CHANMSG_CHOPEN_UDATA_SIZE) { - device_printf(sc->vmbus_dev, + vmbus_chan_printf(chan, "invalid udata len %d for chan%u\n", udlen, chan->ch_id); return EINVAL; } @@ -386,7 +391,7 @@ vmbus_chan_open_br(struct vmbus_channel error = vmbus_chan_gpadl_connect(chan, cbr->cbr_paddr, txbr_size + rxbr_size, &chan->ch_bufring_gpadl); if (error) { - device_printf(sc->vmbus_dev, + vmbus_chan_printf(chan, "failed to connect bufring GPADL to chan%u\n", chan->ch_id); goto failed; } @@ -402,7 +407,7 @@ vmbus_chan_open_br(struct vmbus_channel */ mh = vmbus_msghc_get(sc, sizeof(*req)); if (mh == NULL) { - device_printf(sc->vmbus_dev, + vmbus_chan_printf(chan, "can not get msg hypercall for chopen(chan%u)\n", chan->ch_id); error = ENXIO; @@ -421,7 +426,7 @@ vmbus_chan_open_br(struct vmbus_channel error = vmbus_msghc_exec(sc, mh); if (error) { - device_printf(sc->vmbus_dev, + vmbus_chan_printf(chan, "chopen(chan%u) msg hypercall exec failed: %d\n", chan->ch_id, error); vmbus_msghc_put(sc, mh); @@ -436,13 +441,12 @@ vmbus_chan_open_br(struct vmbus_channel if (status == 0) { if (bootverbose) { - device_printf(sc->vmbus_dev, "chan%u opened\n", - chan->ch_id); + vmbus_chan_printf(chan, "chan%u opened\n", chan->ch_id); } return 0; } - device_printf(sc->vmbus_dev, "failed to open chan%u\n", chan->ch_id); + vmbus_chan_printf(chan, "failed to open chan%u\n", chan->ch_id); error = ENXIO; failed: @@ -485,7 +489,7 @@ vmbus_chan_gpadl_connect(struct vmbus_ch * We don't support multiple GPA ranges. */ if (range_len > UINT16_MAX) { - device_printf(sc->vmbus_dev, "GPA too large, %d pages\n", + vmbus_chan_printf(chan, "GPA too large, %d pages\n", page_count); return EOPNOTSUPP; } @@ -514,8 +518,8 @@ vmbus_chan_gpadl_connect(struct vmbus_ch chm_range.gpa_page[cnt]); mh = vmbus_msghc_get(sc, reqsz); if (mh == NULL) { - device_printf(sc->vmbus_dev, - "can not get msg hypercall for gpadl->chan%u\n", + vmbus_chan_printf(chan, + "can not get msg hypercall for gpadl_conn(chan%u)\n", chan->ch_id); return EIO; } @@ -533,8 +537,8 @@ vmbus_chan_gpadl_connect(struct vmbus_ch error = vmbus_msghc_exec(sc, mh); if (error) { - device_printf(sc->vmbus_dev, - "gpadl->chan%u msg hypercall exec failed: %d\n", + vmbus_chan_printf(chan, + "gpadl_conn(chan%u) msg hypercall exec failed: %d\n", chan->ch_id, error); vmbus_msghc_put(sc, mh); return error; @@ -570,13 +574,13 @@ vmbus_chan_gpadl_connect(struct vmbus_ch vmbus_msghc_put(sc, mh); if (status != 0) { - device_printf(sc->vmbus_dev, "gpadl->chan%u failed: " - "status %u\n", chan->ch_id, status); + vmbus_chan_printf(chan, "gpadl_conn(chan%u) failed: %u\n", + chan->ch_id, status); return EIO; } else { if (bootverbose) { - device_printf(sc->vmbus_dev, "gpadl->chan%u " - "succeeded\n", chan->ch_id); + vmbus_chan_printf(chan, + "gpadl_conn(chan%u) succeeded\n", chan->ch_id); } } return 0; @@ -595,8 +599,8 @@ vmbus_chan_gpadl_disconnect(struct vmbus mh = vmbus_msghc_get(sc, sizeof(*req)); if (mh == NULL) { - device_printf(sc->vmbus_dev, - "can not get msg hypercall for gpa x->chan%u\n", + vmbus_chan_printf(chan, + "can not get msg hypercall for gpadl_disconn(chan%u)\n", chan->ch_id); return EBUSY; } @@ -608,8 +612,8 @@ vmbus_chan_gpadl_disconnect(struct vmbus error = vmbus_msghc_exec(sc, mh); if (error) { - device_printf(sc->vmbus_dev, - "gpa x->chan%u msg hypercall exec failed: %d\n", + vmbus_chan_printf(chan, + "gpadl_disconn(chan%u) msg hypercall exec failed: %d\n", chan->ch_id, error); vmbus_msghc_put(sc, mh); return error; @@ -681,7 +685,7 @@ vmbus_chan_close_internal(struct vmbus_c */ mh = vmbus_msghc_get(sc, sizeof(*req)); if (mh == NULL) { - device_printf(sc->vmbus_dev, + vmbus_chan_printf(chan, "can not get msg hypercall for chclose(chan%u)\n", chan->ch_id); return; @@ -695,12 +699,12 @@ vmbus_chan_close_internal(struct vmbus_c vmbus_msghc_put(sc, mh); if (error) { - device_printf(sc->vmbus_dev, + vmbus_chan_printf(chan, "chclose(chan%u) msg hypercall exec failed: %d\n", chan->ch_id, error); return; } else if (bootverbose) { - device_printf(sc->vmbus_dev, "close chan%u\n", chan->ch_id); + vmbus_chan_printf(chan, "close chan%u\n", chan->ch_id); } /* @@ -890,13 +894,12 @@ vmbus_chan_recv(struct vmbus_channel *ch return (error); if (__predict_false(pkt.cph_hlen < VMBUS_CHANPKT_HLEN_MIN)) { - device_printf(chan->ch_dev, "invalid hlen %u\n", - pkt.cph_hlen); + vmbus_chan_printf(chan, "invalid hlen %u\n", pkt.cph_hlen); /* XXX this channel is dead actually. */ return (EIO); } if (__predict_false(pkt.cph_hlen > pkt.cph_tlen)) { - device_printf(chan->ch_dev, "invalid hlen %u and tlen %u\n", + vmbus_chan_printf(chan, "invalid hlen %u and tlen %u\n", pkt.cph_hlen, pkt.cph_tlen); /* XXX this channel is dead actually. */ return (EIO); @@ -933,13 +936,12 @@ vmbus_chan_recv_pkt(struct vmbus_channel return (error); if (__predict_false(pkt.cph_hlen < VMBUS_CHANPKT_HLEN_MIN)) { - device_printf(chan->ch_dev, "invalid hlen %u\n", - pkt.cph_hlen); + vmbus_chan_printf(chan, "invalid hlen %u\n", pkt.cph_hlen); /* XXX this channel is dead actually. */ return (EIO); } if (__predict_false(pkt.cph_hlen > pkt.cph_tlen)) { - device_printf(chan->ch_dev, "invalid hlen %u and tlen %u\n", + vmbus_chan_printf(chan, "invalid hlen %u and tlen %u\n", pkt.cph_hlen, pkt.cph_tlen); /* XXX this channel is dead actually. */ return (EIO); @@ -1082,8 +1084,8 @@ vmbus_chan_update_evtflagcnt(struct vmbu break; if (atomic_cmpset_int(flag_cnt_ptr, old_flag_cnt, flag_cnt)) { if (bootverbose) { - device_printf(sc->vmbus_dev, - "channel%u update cpu%d flag_cnt to %d\n", + vmbus_chan_printf(chan, + "chan%u update cpu%d flag_cnt to %d\n", chan->ch_id, chan->ch_cpuid, flag_cnt); } break; @@ -1154,11 +1156,6 @@ vmbus_chan_add(struct vmbus_channel *new return EINVAL; } - if (bootverbose) { - device_printf(sc->vmbus_dev, "chan%u subidx%u offer\n", - newchan->ch_id, newchan->ch_subidx); - } - mtx_lock(&sc->vmbus_prichan_lock); TAILQ_FOREACH(prichan, &sc->vmbus_prichans, ch_prilink) { /* @@ -1179,15 +1176,15 @@ vmbus_chan_add(struct vmbus_channel *new goto done; } else { mtx_unlock(&sc->vmbus_prichan_lock); - device_printf(sc->vmbus_dev, "duplicated primary " - "chan%u\n", newchan->ch_id); + device_printf(sc->vmbus_dev, + "duplicated primary chan%u\n", newchan->ch_id); return EINVAL; } } else { /* Sub-channel */ if (prichan == NULL) { mtx_unlock(&sc->vmbus_prichan_lock); - device_printf(sc->vmbus_dev, "no primary chan for " - "chan%u\n", newchan->ch_id); + device_printf(sc->vmbus_dev, + "no primary chan for chan%u\n", newchan->ch_id); return EINVAL; } /* @@ -1224,6 +1221,15 @@ done: mtx_lock(&sc->vmbus_chan_lock); vmbus_chan_ins_list(sc, newchan); mtx_unlock(&sc->vmbus_chan_lock); + + if (bootverbose) { + vmbus_chan_printf(newchan, "chan%u subidx%u offer\n", + newchan->ch_id, newchan->ch_subidx); + } + + /* Select default cpu for this channel. */ + vmbus_chan_cpu_default(newchan); + return 0; } @@ -1242,7 +1248,8 @@ vmbus_chan_cpu_set(struct vmbus_channel chan->ch_vcpuid = VMBUS_PCPU_GET(chan->ch_vmbus, vcpuid, cpu); if (bootverbose) { - printf("vmbus_chan%u: assigned to cpu%u [vcpu%u]\n", + vmbus_chan_printf(chan, + "chan%u assigned to cpu%u [vcpu%u]\n", chan->ch_id, chan->ch_cpuid, chan->ch_vcpuid); } } @@ -1338,9 +1345,6 @@ vmbus_chan_msgproc_choffer(struct vmbus_ TASK_INIT(&chan->ch_attach_task, 0, attach_fn, chan); TASK_INIT(&chan->ch_detach_task, 0, detach_fn, chan); - /* Select default cpu for this channel. */ - vmbus_chan_cpu_default(chan); - error = vmbus_chan_add(chan); if (error) { device_printf(sc->vmbus_dev, "add chan%u failed: %d\n", @@ -1365,11 +1369,6 @@ vmbus_chan_msgproc_chrescind(struct vmbu return; } - if (bootverbose) { - device_printf(sc->vmbus_dev, "chan%u rescinded\n", - note->chm_chanid); - } - /* * Find and remove the target channel from the channel list. */ @@ -1400,6 +1399,9 @@ vmbus_chan_msgproc_chrescind(struct vmbu mtx_unlock(&sc->vmbus_prichan_lock); } + if (bootverbose) + vmbus_chan_printf(chan, "chan%u rescinded\n", note->chm_chanid); + /* Detach the target channel. */ taskqueue_enqueue(chan->ch_mgmt_tq, &chan->ch_detach_task); } @@ -1414,8 +1416,9 @@ vmbus_chan_release(struct vmbus_channel mh = vmbus_msghc_get(sc, sizeof(*req)); if (mh == NULL) { - device_printf(sc->vmbus_dev, "can not get msg hypercall for " - "chfree(chan%u)\n", chan->ch_id); + vmbus_chan_printf(chan, + "can not get msg hypercall for chfree(chan%u)\n", + chan->ch_id); return (ENXIO); } @@ -1427,13 +1430,12 @@ vmbus_chan_release(struct vmbus_channel vmbus_msghc_put(sc, mh); if (error) { - device_printf(sc->vmbus_dev, "chfree(chan%u) failed: %d", + vmbus_chan_printf(chan, + "chfree(chan%u) msg hypercall exec failed: %d\n", chan->ch_id, error); } else { - if (bootverbose) { - device_printf(sc->vmbus_dev, "chan%u freed\n", - chan->ch_id); - } + if (bootverbose) + vmbus_chan_printf(chan, "chan%u freed\n", chan->ch_id); } return (error); } @@ -1714,6 +1716,26 @@ vmbus_chan_rx_empty(const struct vmbus_c return (vmbus_rxbr_empty(&chan->ch_rxbr)); } +static int +vmbus_chan_printf(const struct vmbus_channel *chan, const char *fmt, ...) +{ + va_list ap; + device_t dev; + int retval; + + if (chan->ch_dev == NULL || !device_is_alive(chan->ch_dev)) + dev = chan->ch_vmbus->vmbus_dev; + else + dev = chan->ch_dev; + + retval = device_print_prettyname(dev); + va_start(ap, fmt); + retval += vprintf(fmt, ap); + va_end(ap); + + return (retval); +} + void vmbus_chan_run_task(struct vmbus_channel *chan, struct task *task) { From owner-svn-src-stable-10@freebsd.org Fri Nov 11 05:07:26 2016 Return-Path: Delivered-To: svn-src-stable-10@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 E57C3C39FDB; Fri, 11 Nov 2016 05:07:26 +0000 (UTC) (envelope-from sephe@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 BF7D13B1; Fri, 11 Nov 2016 05:07:26 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB57P46030469; Fri, 11 Nov 2016 05:07:25 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB57PAE030465; Fri, 11 Nov 2016 05:07:25 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110507.uAB57PAE030465@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 05:07:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308502 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 05:07:27 -0000 Author: sephe Date: Fri Nov 11 05:07:25 2016 New Revision: 308502 URL: https://svnweb.freebsd.org/changeset/base/308502 Log: MFC 307983 hyperv/hn: Properly configure RSS according to RSS capabilities Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8338 Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c stable/10/sys/dev/hyperv/netvsc/ndis.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 04:39:02 2016 (r308501) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 05:07:25 2016 (r308502) @@ -256,6 +256,8 @@ struct hn_softc { int hn_ndis_tso_szmax; int hn_ndis_tso_sgmin; + int hn_rss_ind_size; + uint32_t hn_rss_hash; /* NDIS_HASH_ */ struct ndis_rssprm_toeplitz hn_rss; }; Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 04:39:02 2016 (r308501) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 05:07:25 2016 (r308502) @@ -331,6 +331,7 @@ static int hn_hwassist_sysctl(SYSCTL_HAN static int hn_rxfilter_sysctl(SYSCTL_HANDLER_ARGS); static int hn_rss_key_sysctl(SYSCTL_HANDLER_ARGS); static int hn_rss_ind_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_rss_hash_sysctl(SYSCTL_HANDLER_ARGS); static int hn_check_iplen(const struct mbuf *, int); static int hn_create_tx_ring(struct hn_softc *, int); static void hn_destroy_tx_ring(struct hn_tx_ring *); @@ -786,6 +787,11 @@ netvsc_attach(device_t dev) SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rxfilter", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, hn_rxfilter_sysctl, "A", "rxfilter"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rss_hash", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, + hn_rss_hash_sysctl, "A", "RSS hash"); + SYSCTL_ADD_INT(ctx, child, OID_AUTO, "rss_ind_size", + CTLFLAG_RD, &sc->hn_rss_ind_size, 0, "RSS indirect entry count"); SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rss_key", CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, hn_rss_key_sysctl, "IU", "RSS key"); @@ -2499,6 +2505,20 @@ back: } static int +hn_rss_hash_sysctl(SYSCTL_HANDLER_ARGS) +{ + struct hn_softc *sc = arg1; + char hash_str[128]; + uint32_t hash; + + HN_LOCK(sc); + hash = sc->hn_rss_hash; + HN_UNLOCK(sc); + snprintf(hash_str, sizeof(hash_str), "%b", hash, NDIS_HASH_BITS); + return sysctl_handle_string(oidp, hash_str, sizeof(hash_str), req); +} + +static int hn_check_iplen(const struct mbuf *m, int hoff) { const struct ip *ip; @@ -3662,6 +3682,10 @@ hn_synth_attach(struct hn_softc *sc, int old_caps = sc->hn_caps; sc->hn_caps = 0; + /* Clear RSS stuffs. */ + sc->hn_rss_ind_size = 0; + sc->hn_rss_hash = 0; + /* * Attach the primary channel _before_ attaching NVS and RNDIS. */ @@ -3736,7 +3760,6 @@ hn_synth_attach(struct hn_softc *sc, int if_printf(sc->hn_ifp, "setup default RSS indirect " "table\n"); } - /* TODO: Take ndis_rss_caps.ndis_nind into account. */ for (i = 0; i < NDIS_HASH_INDCNT; ++i) rss->rss_ind[i] = i % nchan; sc->hn_flags |= HN_FLAG_HAS_RSSIND; Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 04:39:02 2016 (r308501) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 05:07:25 2016 (r308502) @@ -748,13 +748,14 @@ done: } int -hn_rndis_query_rsscaps(struct hn_softc *sc, int *rxr_cnt) +hn_rndis_query_rsscaps(struct hn_softc *sc, int *rxr_cnt0) { struct ndis_rss_caps in, caps; size_t caps_len; - int error; + int error, indsz, rxr_cnt, hash_fnidx; + uint32_t hash_func = 0, hash_types = 0; - *rxr_cnt = 0; + *rxr_cnt0 = 0; if (sc->hn_ndis_ver < HN_NDIS_VERSION_6_20) return (EOPNOTSUPP); @@ -793,18 +794,73 @@ hn_rndis_query_rsscaps(struct hn_softc * return (EINVAL); } + /* + * Save information for later RSS configuration. + */ if (caps.ndis_nrxr == 0) { if_printf(sc->hn_ifp, "0 RX rings!?\n"); return (EINVAL); } - *rxr_cnt = caps.ndis_nrxr; + if (bootverbose) + if_printf(sc->hn_ifp, "%u RX rings\n", caps.ndis_nrxr); + rxr_cnt = caps.ndis_nrxr; + + if (caps.ndis_hdr.ndis_size == NDIS_RSS_CAPS_SIZE && + caps.ndis_hdr.ndis_rev >= NDIS_RSS_CAPS_REV_2) { + if (caps.ndis_nind > NDIS_HASH_INDCNT) { + if_printf(sc->hn_ifp, + "too many RSS indirect table entries %u\n", + caps.ndis_nind); + return (EOPNOTSUPP); + } + if (!powerof2(caps.ndis_nind)) { + if_printf(sc->hn_ifp, "RSS indirect table size is not " + "power-of-2 %u\n", caps.ndis_nind); + } - if (caps.ndis_hdr.ndis_size == NDIS_RSS_CAPS_SIZE) { if (bootverbose) { if_printf(sc->hn_ifp, "RSS indirect table size %u\n", caps.ndis_nind); } + indsz = caps.ndis_nind; + } else { + indsz = NDIS_HASH_INDCNT; + } + if (indsz < rxr_cnt) { + if_printf(sc->hn_ifp, "# of RX rings (%d) > " + "RSS indirect table size %d\n", rxr_cnt, indsz); + rxr_cnt = indsz; } + + /* + * NOTE: + * Toeplitz is at the lowest bit, and it is prefered; so ffs(), + * instead of fls(), is used here. + */ + hash_fnidx = ffs(caps.ndis_caps & NDIS_RSS_CAP_HASHFUNC_MASK); + if (hash_fnidx == 0) { + if_printf(sc->hn_ifp, "no hash functions, caps 0x%08x\n", + caps.ndis_caps); + return (EOPNOTSUPP); + } + hash_func = 1 << (hash_fnidx - 1); /* ffs is 1-based */ + + if (caps.ndis_caps & NDIS_RSS_CAP_IPV4) + hash_types |= NDIS_HASH_IPV4 | NDIS_HASH_TCP_IPV4; + if (caps.ndis_caps & NDIS_RSS_CAP_IPV6) + hash_types |= NDIS_HASH_IPV6 | NDIS_HASH_TCP_IPV6; + if (caps.ndis_caps & NDIS_RSS_CAP_IPV6_EX) + hash_types |= NDIS_HASH_IPV6_EX | NDIS_HASH_TCP_IPV6_EX; + if (hash_types == 0) { + if_printf(sc->hn_ifp, "no hash types, caps 0x%08x\n", + caps.ndis_caps); + return (EOPNOTSUPP); + } + + /* Commit! */ + sc->hn_rss_ind_size = indsz; + sc->hn_rss_hash = hash_func | hash_types; + *rxr_cnt0 = rxr_cnt; return (0); } @@ -1034,7 +1090,7 @@ hn_rndis_conf_rss(struct hn_softc *sc, u { struct ndis_rssprm_toeplitz *rss = &sc->hn_rss; struct ndis_rss_params *prm = &rss->rss_params; - int error; + int error, rss_size; /* * Only NDIS 6.20+ is supported: @@ -1044,21 +1100,29 @@ hn_rndis_conf_rss(struct hn_softc *sc, u KASSERT(sc->hn_ndis_ver >= HN_NDIS_VERSION_6_20, ("NDIS 6.20+ is required, NDIS version 0x%08x", sc->hn_ndis_ver)); + /* XXX only one can be specified through, popcnt? */ + KASSERT((sc->hn_rss_hash & NDIS_HASH_FUNCTION_MASK), ("no hash func")); + KASSERT((sc->hn_rss_hash & NDIS_HASH_TYPE_MASK), ("no hash types")); + KASSERT(sc->hn_rss_ind_size > 0, ("no indirect table size")); + + if (bootverbose) { + if_printf(sc->hn_ifp, "RSS indirect table size %d, " + "hash 0x%08x\n", sc->hn_rss_ind_size, sc->hn_rss_hash); + } + /* * NOTE: * DO NOT whack rss_key and rss_ind, which are setup by the caller. */ memset(prm, 0, sizeof(*prm)); + rss_size = NDIS_RSSPRM_TOEPLITZ_SIZE(sc->hn_rss_ind_size); prm->ndis_hdr.ndis_type = NDIS_OBJTYPE_RSS_PARAMS; prm->ndis_hdr.ndis_rev = NDIS_RSS_PARAMS_REV_2; - prm->ndis_hdr.ndis_size = sizeof(*rss); + prm->ndis_hdr.ndis_size = rss_size; prm->ndis_flags = flags; - prm->ndis_hash = NDIS_HASH_FUNCTION_TOEPLITZ | - NDIS_HASH_IPV4 | NDIS_HASH_TCP_IPV4 | - NDIS_HASH_IPV6 | NDIS_HASH_TCP_IPV6; - /* TODO: Take ndis_rss_caps.ndis_nind into account */ - prm->ndis_indsize = sizeof(rss->rss_ind); + prm->ndis_hash = sc->hn_rss_hash; + prm->ndis_indsize = sizeof(rss->rss_ind[0]) * sc->hn_rss_ind_size; prm->ndis_indoffset = __offsetof(struct ndis_rssprm_toeplitz, rss_ind[0]); prm->ndis_keysize = sizeof(rss->rss_key); @@ -1066,7 +1130,7 @@ hn_rndis_conf_rss(struct hn_softc *sc, u __offsetof(struct ndis_rssprm_toeplitz, rss_key[0]); error = hn_rndis_set(sc, OID_GEN_RECEIVE_SCALE_PARAMETERS, - rss, sizeof(*rss)); + rss, rss_size); if (error) { if_printf(sc->hn_ifp, "RSS config failed: %d\n", error); } else { Modified: stable/10/sys/dev/hyperv/netvsc/ndis.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/ndis.h Fri Nov 11 04:39:02 2016 (r308501) +++ stable/10/sys/dev/hyperv/netvsc/ndis.h Fri Nov 11 05:07:25 2016 (r308502) @@ -57,6 +57,10 @@ #define NDIS_HASH_TCP_IPV6 0x00001000 #define NDIS_HASH_TCP_IPV6_EX 0x00002000 +/* Hash description for use with printf(9) %b identifier. */ +#define NDIS_HASH_BITS \ + "\20\1TOEPLITZ\11IP4\12TCP4\13IP6\14IP6EX\15TCP6\16TCP6EX" + #define NDIS_HASH_KEYSIZE_TOEPLITZ 40 #define NDIS_HASH_INDCNT 128 @@ -142,7 +146,7 @@ struct ndis_offload_params { */ struct ndis_rss_caps { struct ndis_object_hdr ndis_hdr; - uint32_t ndis_flags; /* NDIS_RSS_CAP_ */ + uint32_t ndis_caps; /* NDIS_RSS_CAP_ */ uint32_t ndis_nmsi; /* # of MSIs */ uint32_t ndis_nrxr; /* # of RX rings */ /* NDIS >= 6.30 */ @@ -165,7 +169,8 @@ struct ndis_rss_caps { #define NDIS_RSS_CAP_IPV4 0x00000100 #define NDIS_RSS_CAP_IPV6 0x00000200 #define NDIS_RSS_CAP_IPV6_EX 0x00000400 -#define NDIS_RSS_CAP_HASH_TOEPLITZ 0x00000001 +#define NDIS_RSS_CAP_HASH_TOEPLITZ NDIS_HASH_FUNCTION_TOEPLITZ +#define NDIS_RSS_CAP_HASHFUNC_MASK NDIS_HASH_FUNCTION_MASK /* * OID_GEN_RECEIVE_SCALE_PARAMETERS @@ -209,6 +214,9 @@ struct ndis_rssprm_toeplitz { uint32_t rss_ind[NDIS_HASH_INDCNT]; }; +#define NDIS_RSSPRM_TOEPLITZ_SIZE(nind) \ + __offsetof(struct ndis_rssprm_toeplitz, rss_ind[nind]) + /* * OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES * ndis_type: NDIS_OBJTYPE_OFFLOAD From owner-svn-src-stable-10@freebsd.org Fri Nov 11 05:17:05 2016 Return-Path: Delivered-To: svn-src-stable-10@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 75C04C3A2CC; Fri, 11 Nov 2016 05:17:05 +0000 (UTC) (envelope-from sephe@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 4F044AE1; Fri, 11 Nov 2016 05:17:05 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB5H4ct034385; Fri, 11 Nov 2016 05:17:04 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB5H4IW034380; Fri, 11 Nov 2016 05:17:04 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110517.uAB5H4IW034380@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 05:17:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308503 - in stable/10/sys: dev/hyperv/netvsc net X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 05:17:05 -0000 Author: sephe Date: Fri Nov 11 05:17:03 2016 New Revision: 308503 URL: https://svnweb.freebsd.org/changeset/base/308503 Log: MFC 307985-307988 307985 hyperv/hn: Nuke unnecessary M_NETVSC Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8340 307986 hyperv/hn: Move %b format string for capabilities near their definition. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8341 307987 hyperv/hn: Define empty packet filter. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8342 307988 hyperv/hn: Shuffle chimney sending buffer alloc/free around. This paves way for more chimney sending buffer reorganization. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8343 Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/if_hnvar.h stable/10/sys/net/rndis.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Fri Nov 11 05:07:25 2016 (r308502) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Fri Nov 11 05:17:03 2016 (r308503) @@ -51,8 +51,6 @@ #include #include -MALLOC_DEFINE(M_NETVSC, "netvsc", "Hyper-V netvsc driver"); - /* * Forward declarations */ @@ -74,33 +72,6 @@ static const uint32_t hn_nvs_version[] HN_NVS_VERSION_1 }; -uint32_t -hn_chim_alloc(struct hn_softc *sc) -{ - int i, bmap_cnt = sc->hn_chim_bmap_cnt; - u_long *bmap = sc->hn_chim_bmap; - uint32_t ret = HN_NVS_CHIM_IDX_INVALID; - - for (i = 0; i < bmap_cnt; ++i) { - int idx; - - idx = ffsl(~bmap[i]); - if (idx == 0) - continue; - - --idx; /* ffsl is 1-based */ - KASSERT(i * LONG_BIT + idx < sc->hn_chim_cnt, - ("invalid i %d and idx %d", i, idx)); - - if (atomic_testandset_long(&bmap[i], idx)) - continue; - - ret = i * LONG_BIT + idx; - break; - } - return (ret); -} - static const void * hn_nvs_xact_execute(struct hn_softc *sc, struct vmbus_xact *xact, void *req, int reqlen, size_t *resplen0, uint32_t type) @@ -307,7 +278,7 @@ hn_nvs_conn_chim(struct hn_softc *sc) sc->hn_chim_bmap_cnt = sc->hn_chim_cnt / LONG_BIT; sc->hn_chim_bmap = malloc(sc->hn_chim_bmap_cnt * sizeof(u_long), - M_NETVSC, M_WAITOK | M_ZERO); + M_DEVBUF, M_WAITOK | M_ZERO); /* Done! */ sc->hn_flags |= HN_FLAG_CHIM_CONNECTED; @@ -426,7 +397,7 @@ hn_nvs_disconn_chim(struct hn_softc *sc) } if (sc->hn_chim_bmap != NULL) { - free(sc->hn_chim_bmap, M_NETVSC); + free(sc->hn_chim_bmap, M_DEVBUF); sc->hn_chim_bmap = NULL; } return (0); @@ -649,25 +620,6 @@ hn_nvs_sent_none(struct hn_send_ctx *snd /* EMPTY */ } -void -hn_chim_free(struct hn_softc *sc, uint32_t chim_idx) -{ - u_long mask; - uint32_t idx; - - idx = chim_idx / LONG_BIT; - KASSERT(idx < sc->hn_chim_bmap_cnt, - ("invalid chimney index 0x%x", chim_idx)); - - mask = 1UL << (chim_idx % LONG_BIT); - KASSERT(sc->hn_chim_bmap[idx] & mask, - ("index bitmap 0x%lx, chimney index %u, " - "bitmap idx %d, bitmask 0x%lx", - sc->hn_chim_bmap[idx], chim_idx, idx, mask)); - - atomic_clear_long(&sc->hn_chim_bmap[idx], mask); -} - int hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch0) { Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 05:07:25 2016 (r308502) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 05:17:03 2016 (r308503) @@ -66,8 +66,6 @@ #define HN_USE_TXDESC_BUFRING -MALLOC_DECLARE(M_NETVSC); - /* * The following arguably belongs in a separate header file */ @@ -278,6 +276,11 @@ struct hn_softc { #define HN_CAP_TSO6 0x0100 #define HN_CAP_HASHVAL 0x0200 +/* Capability description for use with printf(9) %b identifier. */ +#define HN_CAP_BITS \ + "\020\1VLAN\2MTU\3IPCS\4TCP4CS\5TCP6CS" \ + "\6UDP4CS\7UDP6CS\10TSO4\11TSO6\12HASHVAL" + #define HN_LINK_FLAG_LINKUP 0x0001 #define HN_LINK_FLAG_NETCHG 0x0002 Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 05:07:25 2016 (r308502) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 05:17:03 2016 (r308503) @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -459,6 +460,52 @@ hn_sendpkt_rndis_chim(struct hn_tx_ring &rndis, sizeof(rndis), &txd->send_ctx)); } +static __inline uint32_t +hn_chim_alloc(struct hn_softc *sc) +{ + int i, bmap_cnt = sc->hn_chim_bmap_cnt; + u_long *bmap = sc->hn_chim_bmap; + uint32_t ret = HN_NVS_CHIM_IDX_INVALID; + + for (i = 0; i < bmap_cnt; ++i) { + int idx; + + idx = ffsl(~bmap[i]); + if (idx == 0) + continue; + + --idx; /* ffsl is 1-based */ + KASSERT(i * LONG_BIT + idx < sc->hn_chim_cnt, + ("invalid i %d and idx %d", i, idx)); + + if (atomic_testandset_long(&bmap[i], idx)) + continue; + + ret = i * LONG_BIT + idx; + break; + } + return (ret); +} + +static __inline void +hn_chim_free(struct hn_softc *sc, uint32_t chim_idx) +{ + u_long mask; + uint32_t idx; + + idx = chim_idx / LONG_BIT; + KASSERT(idx < sc->hn_chim_bmap_cnt, + ("invalid chimney index 0x%x", chim_idx)); + + mask = 1UL << (chim_idx % LONG_BIT); + KASSERT(sc->hn_chim_bmap[idx] & mask, + ("index bitmap 0x%lx, chimney index %u, " + "bitmap idx %d, bitmask 0x%lx", + sc->hn_chim_bmap[idx], chim_idx, idx, mask)); + + atomic_clear_long(&sc->hn_chim_bmap[idx], mask); +} + static int hn_set_rxfilter(struct hn_softc *sc) { @@ -2399,18 +2446,7 @@ hn_caps_sysctl(SYSCTL_HANDLER_ARGS) HN_LOCK(sc); caps = sc->hn_caps; HN_UNLOCK(sc); - snprintf(caps_str, sizeof(caps_str), "%b", caps, - "\020" - "\001VLAN" - "\002MTU" - "\003IPCS" - "\004TCP4CS" - "\005TCP6CS" - "\006UDP4CS" - "\007UDP6CS" - "\010TSO4" - "\011TSO6" - "\012HASHVAL"); + snprintf(caps_str, sizeof(caps_str), "%b", caps, HN_CAP_BITS); return sysctl_handle_string(oidp, caps_str, sizeof(caps_str), req); } @@ -2626,7 +2662,7 @@ hn_create_rx_data(struct hn_softc *sc, i sc->hn_rx_ring_inuse = sc->hn_rx_ring_cnt; sc->hn_rx_ring = malloc(sizeof(struct hn_rx_ring) * sc->hn_rx_ring_cnt, - M_NETVSC, M_WAITOK | M_ZERO); + M_DEVBUF, M_WAITOK | M_ZERO); #if defined(INET) || defined(INET6) #if __FreeBSD_version >= 1100095 @@ -2667,7 +2703,7 @@ hn_create_rx_data(struct hn_softc *sc, i rxr->hn_ifp = sc->hn_ifp; if (i < sc->hn_tx_ring_cnt) rxr->hn_txr = &sc->hn_tx_ring[i]; - rxr->hn_rdbuf = malloc(NETVSC_PACKET_SIZE, M_NETVSC, M_WAITOK); + rxr->hn_rdbuf = malloc(NETVSC_PACKET_SIZE, M_DEVBUF, M_WAITOK); rxr->hn_rx_idx = i; rxr->hn_rxbuf = sc->hn_rxbuf; @@ -2814,9 +2850,9 @@ hn_destroy_rx_data(struct hn_softc *sc) #if defined(INET) || defined(INET6) tcp_lro_free(&rxr->hn_lro); #endif - free(rxr->hn_rdbuf, M_NETVSC); + free(rxr->hn_rdbuf, M_DEVBUF); } - free(sc->hn_rx_ring, M_NETVSC); + free(sc->hn_rx_ring, M_DEVBUF); sc->hn_rx_ring = NULL; sc->hn_rx_ring_cnt = 0; @@ -2841,11 +2877,11 @@ hn_create_tx_ring(struct hn_softc *sc, i txr->hn_txdesc_cnt = HN_TX_DESC_CNT; txr->hn_txdesc = malloc(sizeof(struct hn_txdesc) * txr->hn_txdesc_cnt, - M_NETVSC, M_WAITOK | M_ZERO); + M_DEVBUF, M_WAITOK | M_ZERO); #ifndef HN_USE_TXDESC_BUFRING SLIST_INIT(&txr->hn_txlist); #else - txr->hn_txdesc_br = buf_ring_alloc(txr->hn_txdesc_cnt, M_NETVSC, + txr->hn_txdesc_br = buf_ring_alloc(txr->hn_txdesc_cnt, M_DEVBUF, M_WAITOK, &txr->hn_tx_lock); #endif @@ -2863,7 +2899,7 @@ hn_create_tx_ring(struct hn_softc *sc, i TASK_INIT(&txr->hn_txeof_task, 0, hn_xmit_txeof_taskfunc, txr); br_depth = hn_get_txswq_depth(txr); - txr->hn_mbuf_br = buf_ring_alloc(br_depth, M_NETVSC, + txr->hn_mbuf_br = buf_ring_alloc(br_depth, M_DEVBUF, M_WAITOK, &txr->hn_tx_lock); } @@ -3046,14 +3082,14 @@ hn_destroy_tx_ring(struct hn_tx_ring *tx bus_dma_tag_destroy(txr->hn_tx_rndis_dtag); #ifdef HN_USE_TXDESC_BUFRING - buf_ring_free(txr->hn_txdesc_br, M_NETVSC); + buf_ring_free(txr->hn_txdesc_br, M_DEVBUF); #endif - free(txr->hn_txdesc, M_NETVSC); + free(txr->hn_txdesc, M_DEVBUF); txr->hn_txdesc = NULL; if (txr->hn_mbuf_br != NULL) - buf_ring_free(txr->hn_mbuf_br, M_NETVSC); + buf_ring_free(txr->hn_mbuf_br, M_DEVBUF); #ifndef HN_USE_TXDESC_BUFRING mtx_destroy(&txr->hn_txlist_spin); @@ -3085,7 +3121,7 @@ hn_create_tx_data(struct hn_softc *sc, i sc->hn_tx_ring_inuse = sc->hn_tx_ring_cnt; sc->hn_tx_ring = malloc(sizeof(struct hn_tx_ring) * sc->hn_tx_ring_cnt, - M_NETVSC, M_WAITOK | M_ZERO); + M_DEVBUF, M_WAITOK | M_ZERO); ctx = device_get_sysctl_ctx(sc->hn_dev); child = SYSCTL_CHILDREN(device_get_sysctl_tree(sc->hn_dev)); @@ -3245,7 +3281,7 @@ hn_destroy_tx_data(struct hn_softc *sc) for (i = 0; i < sc->hn_tx_ring_cnt; ++i) hn_destroy_tx_ring(&sc->hn_tx_ring[i]); - free(sc->hn_tx_ring, M_NETVSC); + free(sc->hn_tx_ring, M_DEVBUF); sc->hn_tx_ring = NULL; sc->hn_tx_ring_cnt = 0; @@ -3880,8 +3916,8 @@ hn_suspend_data(struct hn_softc *sc) /* * Disable RX by clearing RX filter. */ - hn_rndis_set_rxfilter(sc, 0); - sc->hn_rx_filter = 0; + sc->hn_rx_filter = NDIS_PACKET_TYPE_NONE; + hn_rndis_set_rxfilter(sc, sc->hn_rx_filter); /* * Give RNDIS enough time to flush all pending data packets. @@ -4195,12 +4231,12 @@ hn_chan_callback(struct vmbus_channel *c } else if (ret == ENOBUFS) { /* Handle large packet */ if (bufferlen > NETVSC_PACKET_SIZE) { - free(buffer, M_NETVSC); + free(buffer, M_DEVBUF); buffer = NULL; } /* alloc new buffer */ - buffer = malloc(bytes_rxed, M_NETVSC, M_NOWAIT); + buffer = malloc(bytes_rxed, M_DEVBUF, M_NOWAIT); if (buffer == NULL) { if_printf(rxr->hn_ifp, "hv_cb malloc buffer failed, len=%u\n", @@ -4216,7 +4252,7 @@ hn_chan_callback(struct vmbus_channel *c } while (1); if (bufferlen > NETVSC_PACKET_SIZE) - free(buffer, M_NETVSC); + free(buffer, M_DEVBUF); hv_rf_channel_rollup(rxr, rxr->hn_txr); } Modified: stable/10/sys/dev/hyperv/netvsc/if_hnvar.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 05:07:25 2016 (r308502) +++ stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 05:17:03 2016 (r308503) @@ -94,9 +94,6 @@ hn_nvs_send_sglist(struct vmbus_channel struct vmbus_xact; struct rndis_packet_msg; -uint32_t hn_chim_alloc(struct hn_softc *sc); -void hn_chim_free(struct hn_softc *sc, uint32_t chim_idx); - int hn_rndis_attach(struct hn_softc *sc, int mtu); void hn_rndis_detach(struct hn_softc *sc); int hn_rndis_conf_rss(struct hn_softc *sc, uint16_t flags); @@ -106,7 +103,7 @@ int hn_rndis_query_rsscaps(struct hn_so int hn_rndis_get_eaddr(struct hn_softc *sc, uint8_t *eaddr); int hn_rndis_get_linkstatus(struct hn_softc *sc, uint32_t *link_status); -/* filter: NDIS_PACKET_TYPE_ or 0. */ +/* filter: NDIS_PACKET_TYPE_. */ int hn_rndis_set_rxfilter(struct hn_softc *sc, uint32_t filter); int hn_nvs_attach(struct hn_softc *sc, int mtu); Modified: stable/10/sys/net/rndis.h ============================================================================== --- stable/10/sys/net/rndis.h Fri Nov 11 05:07:25 2016 (r308502) +++ stable/10/sys/net/rndis.h Fri Nov 11 05:17:03 2016 (r308503) @@ -352,6 +352,7 @@ struct rndis_keepalive_comp { }; /* Packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */ +#define NDIS_PACKET_TYPE_NONE 0x00000000 #define NDIS_PACKET_TYPE_DIRECTED 0x00000001 #define NDIS_PACKET_TYPE_MULTICAST 0x00000002 #define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004 From owner-svn-src-stable-10@freebsd.org Fri Nov 11 05:37:06 2016 Return-Path: Delivered-To: svn-src-stable-10@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 C1A80C3AAF7; Fri, 11 Nov 2016 05:37:06 +0000 (UTC) (envelope-from sephe@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 5FFFE158A; Fri, 11 Nov 2016 05:37:06 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB5b5Pb042701; Fri, 11 Nov 2016 05:37:05 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB5b5x7042696; Fri, 11 Nov 2016 05:37:05 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110537.uAB5b5x7042696@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 05:37:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308504 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 05:37:06 -0000 Author: sephe Date: Fri Nov 11 05:37:04 2016 New Revision: 308504 URL: https://svnweb.freebsd.org/changeset/base/308504 Log: MFC 307989-307991,308010 307989 hyperv/hn: Move hn_softc to if_hnvar.h While I'm here, use consistent macro names. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8345 307990 hyperv/hn: Move send context to NVS domain. Since all sends are encapsulated in NVS messages. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8346 307991 hyperv/hn: NVS inclusion cleanup and forward declare functions. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8347 308010 hyperv/hn: Change header guardian; in preparation for the upcoming rename. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8352 Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Fri Nov 11 05:17:03 2016 (r308503) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Fri Nov 11 05:37:04 2016 (r308504) @@ -24,46 +24,59 @@ * 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$ */ -/** - * HyperV vmbus network VSC (virtual services client) module - * +/* + * Network Virtualization Service. */ +#include +__FBSDID("$FreeBSD$"); + +#include "opt_inet6.h" +#include "opt_inet.h" #include #include -#include #include -#include +#include +#include +#include + #include #include -#include -#include +#include + +#include +#include #include +#include +#include #include -#include -#include + +#include #include #include +#include -/* - * Forward declarations - */ -static int hn_nvs_conn_chim(struct hn_softc *sc); -static int hn_nvs_conn_rxbuf(struct hn_softc *); -static int hn_nvs_disconn_chim(struct hn_softc *sc); -static int hn_nvs_disconn_rxbuf(struct hn_softc *sc); -static void hn_nvs_sent_none(struct hn_send_ctx *sndc, - struct hn_softc *, struct vmbus_channel *chan, - const void *, int); +static int hn_nvs_conn_chim(struct hn_softc *); +static int hn_nvs_conn_rxbuf(struct hn_softc *); +static int hn_nvs_disconn_chim(struct hn_softc *); +static int hn_nvs_disconn_rxbuf(struct hn_softc *); +static int hn_nvs_conf_ndis(struct hn_softc *, int); +static int hn_nvs_init_ndis(struct hn_softc *); +static int hn_nvs_doinit(struct hn_softc *, uint32_t); +static int hn_nvs_init(struct hn_softc *); +static const void *hn_nvs_xact_execute(struct hn_softc *, + struct vmbus_xact *, void *, int, + size_t *, uint32_t); +static void hn_nvs_sent_none(struct hn_nvs_sendctx *, + struct hn_softc *, struct vmbus_channel *, + const void *, int); -struct hn_send_ctx hn_send_ctx_none = - HN_SEND_CTX_INITIALIZER(hn_nvs_sent_none, NULL); +struct hn_nvs_sendctx hn_nvs_sendctx_none = + HN_NVS_SENDCTX_INITIALIZER(hn_nvs_sent_none, NULL); static const uint32_t hn_nvs_version[] = { HN_NVS_VERSION_5, @@ -76,7 +89,7 @@ static const void * hn_nvs_xact_execute(struct hn_softc *sc, struct vmbus_xact *xact, void *req, int reqlen, size_t *resplen0, uint32_t type) { - struct hn_send_ctx sndc; + struct hn_nvs_sendctx sndc; size_t resplen, min_resplen = *resplen0; const struct hn_nvs_hdr *hdr; int error; @@ -87,7 +100,7 @@ hn_nvs_xact_execute(struct hn_softc *sc, /* * Execute the xact setup by the caller. */ - hn_send_ctx_init(&sndc, hn_nvs_sent_xact, xact); + hn_nvs_sendctx_init(&sndc, hn_nvs_sent_xact, xact); vmbus_xact_activate(xact); error = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_RC, @@ -120,7 +133,7 @@ hn_nvs_req_send(struct hn_softc *sc, voi { return (hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_NONE, - req, reqlen, &hn_send_ctx_none)); + req, reqlen, &hn_nvs_sendctx_none)); } static int @@ -137,9 +150,9 @@ hn_nvs_conn_rxbuf(struct hn_softc *sc) * Limit RXBUF size for old NVS. */ if (sc->hn_nvs_ver <= HN_NVS_VERSION_2) - rxbuf_size = NETVSC_RECEIVE_BUFFER_SIZE_LEGACY; + rxbuf_size = HN_RXBUF_SIZE_COMPAT; else - rxbuf_size = NETVSC_RECEIVE_BUFFER_SIZE; + rxbuf_size = HN_RXBUF_SIZE; /* * Connect the RXBUF GPADL to the primary channel. @@ -218,8 +231,7 @@ hn_nvs_conn_chim(struct hn_softc *sc) * Sub-channels just share this chimney sending buffer. */ error = vmbus_chan_gpadl_connect(sc->hn_prichan, - sc->hn_chim_dma.hv_paddr, NETVSC_SEND_BUFFER_SIZE, - &sc->hn_chim_gpadl); + sc->hn_chim_dma.hv_paddr, HN_CHIM_SIZE, &sc->hn_chim_gpadl); if (error) { if_printf(sc->hn_ifp, "chim gpadl conn failed: %d\n", error); goto cleanup; @@ -266,8 +278,8 @@ hn_nvs_conn_chim(struct hn_softc *sc) } sc->hn_chim_szmax = sectsz; - sc->hn_chim_cnt = NETVSC_SEND_BUFFER_SIZE / sc->hn_chim_szmax; - if (NETVSC_SEND_BUFFER_SIZE % sc->hn_chim_szmax != 0) { + sc->hn_chim_cnt = HN_CHIM_SIZE / sc->hn_chim_szmax; + if (HN_CHIM_SIZE % sc->hn_chim_szmax != 0) { if_printf(sc->hn_ifp, "chimney sending sections are " "not properly aligned\n"); } @@ -604,7 +616,7 @@ hn_nvs_detach(struct hn_softc *sc) } void -hn_nvs_sent_xact(struct hn_send_ctx *sndc, +hn_nvs_sent_xact(struct hn_nvs_sendctx *sndc, struct hn_softc *sc __unused, struct vmbus_channel *chan __unused, const void *data, int dlen) { @@ -613,7 +625,7 @@ hn_nvs_sent_xact(struct hn_send_ctx *snd } static void -hn_nvs_sent_none(struct hn_send_ctx *sndc __unused, +hn_nvs_sent_none(struct hn_nvs_sendctx *sndc __unused, struct hn_softc *sc __unused, struct vmbus_channel *chan __unused, const void *data __unused, int dlen __unused) { @@ -670,3 +682,12 @@ done: vmbus_xact_put(xact); return (error); } + +int +hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan, + struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt) +{ + + return hn_nvs_send_rndis_sglist(chan, HN_NVS_RNDIS_MTYPE_CTRL, + sndc, gpa, gpa_cnt); +} Modified: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 05:17:03 2016 (r308503) +++ stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Fri Nov 11 05:37:04 2016 (r308504) @@ -28,261 +28,79 @@ * $FreeBSD$ */ -/* - * HyperV vmbus (virtual machine bus) network VSC (virtual services client) - * header file - * - * (Updated from unencumbered NvspProtocol.h) - */ - -#ifndef __HV_NET_VSC_H__ -#define __HV_NET_VSC_H__ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include - -#define HN_USE_TXDESC_BUFRING - -/* - * The following arguably belongs in a separate header file - */ - -/* - * Defines - */ - -#define NETVSC_SEND_BUFFER_SIZE (1024*1024*15) /* 15M */ - -#define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */ -#define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */ - -/* - * Maximum MTU we permit to be configured for a netvsc interface. - * When the code was developed, a max MTU of 12232 was tested and - * proven to work. 9K is a reasonable maximum for an Ethernet. - */ -#define NETVSC_MAX_CONFIGURABLE_MTU (9 * 1024) - -#define NETVSC_PACKET_SIZE PAGE_SIZE - -/* - * Data types - */ +#ifndef _HN_NVS_H_ +#define _HN_NVS_H_ +struct hn_nvs_sendctx; struct vmbus_channel; +struct hn_softc; -#define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE) -#define NETVSC_PACKET_MAXPAGE 32 - -#define HN_XACT_REQ_PGCNT 2 -#define HN_XACT_RESP_PGCNT 2 -#define HN_XACT_REQ_SIZE (HN_XACT_REQ_PGCNT * PAGE_SIZE) -#define HN_XACT_RESP_SIZE (HN_XACT_RESP_PGCNT * PAGE_SIZE) - -struct hn_txdesc; -#ifndef HN_USE_TXDESC_BUFRING -SLIST_HEAD(hn_txdesc_list, hn_txdesc); -#else -struct buf_ring; -#endif - -struct hn_tx_ring; - -struct hn_rx_ring { - struct ifnet *hn_ifp; - struct hn_tx_ring *hn_txr; - void *hn_rdbuf; - uint8_t *hn_rxbuf; /* shadow sc->hn_rxbuf */ - int hn_rx_idx; - - /* Trust csum verification on host side */ - int hn_trust_hcsum; /* HN_TRUST_HCSUM_ */ - struct lro_ctrl hn_lro; - - u_long hn_csum_ip; - u_long hn_csum_tcp; - u_long hn_csum_udp; - u_long hn_csum_trusted; - u_long hn_lro_tried; - u_long hn_small_pkts; - u_long hn_pkts; - u_long hn_rss_pkts; - - /* Rarely used stuffs */ - struct sysctl_oid *hn_rx_sysctl_tree; - int hn_rx_flags; - - void *hn_br; /* TX/RX bufring */ - struct hyperv_dma hn_br_dma; -} __aligned(CACHE_LINE_SIZE); - -#define HN_TRUST_HCSUM_IP 0x0001 -#define HN_TRUST_HCSUM_TCP 0x0002 -#define HN_TRUST_HCSUM_UDP 0x0004 - -#define HN_RX_FLAG_ATTACHED 0x1 - -struct hn_tx_ring { -#ifndef HN_USE_TXDESC_BUFRING - struct mtx hn_txlist_spin; - struct hn_txdesc_list hn_txlist; -#else - struct buf_ring *hn_txdesc_br; -#endif - int hn_txdesc_cnt; - int hn_txdesc_avail; - u_short hn_has_txeof; - u_short hn_txdone_cnt; - - int hn_sched_tx; - void (*hn_txeof)(struct hn_tx_ring *); - struct taskqueue *hn_tx_taskq; - struct task hn_tx_task; - struct task hn_txeof_task; - - struct buf_ring *hn_mbuf_br; - int hn_oactive; - int hn_tx_idx; - int hn_tx_flags; - - struct mtx hn_tx_lock; - struct hn_softc *hn_sc; - struct vmbus_channel *hn_chan; - - int hn_direct_tx_size; - int hn_chim_size; - bus_dma_tag_t hn_tx_data_dtag; - uint64_t hn_csum_assist; - - int (*hn_sendpkt)(struct hn_tx_ring *, struct hn_txdesc *); - int hn_suspended; - int hn_gpa_cnt; - struct vmbus_gpa hn_gpa[NETVSC_PACKET_MAXPAGE]; - - u_long hn_no_txdescs; - u_long hn_send_failed; - u_long hn_txdma_failed; - u_long hn_tx_collapsed; - u_long hn_tx_chimney_tried; - u_long hn_tx_chimney; - u_long hn_pkts; - - /* Rarely used stuffs */ - struct hn_txdesc *hn_txdesc; - bus_dma_tag_t hn_tx_rndis_dtag; - struct sysctl_oid *hn_tx_sysctl_tree; -} __aligned(CACHE_LINE_SIZE); - -#define HN_TX_FLAG_ATTACHED 0x1 -#define HN_TX_FLAG_HASHVAL 0x2 /* support HASHVAL pktinfo */ - -/* - * Device-specific softc structure - */ -struct hn_softc { - struct ifnet *hn_ifp; - struct arpcom arpcom; - struct ifmedia hn_media; - device_t hn_dev; - int hn_if_flags; - struct sx hn_lock; - struct vmbus_channel *hn_prichan; - - int hn_rx_ring_cnt; - int hn_rx_ring_inuse; - struct hn_rx_ring *hn_rx_ring; - - int hn_tx_ring_cnt; - int hn_tx_ring_inuse; - struct hn_tx_ring *hn_tx_ring; - - uint8_t *hn_chim; - u_long *hn_chim_bmap; - int hn_chim_bmap_cnt; - int hn_chim_cnt; - int hn_chim_szmax; - - int hn_cpu; - struct taskqueue *hn_tx_taskq; - struct sysctl_oid *hn_tx_sysctl_tree; - struct sysctl_oid *hn_rx_sysctl_tree; - struct vmbus_xact_ctx *hn_xact; - uint32_t hn_nvs_ver; - uint32_t hn_rx_filter; - - struct taskqueue *hn_mgmt_taskq; - struct taskqueue *hn_mgmt_taskq0; - struct task hn_link_task; - struct task hn_netchg_init; - struct timeout_task hn_netchg_status; - uint32_t hn_link_flags; /* HN_LINK_FLAG_ */ - - uint32_t hn_caps; /* HN_CAP_ */ - uint32_t hn_flags; /* HN_FLAG_ */ - void *hn_rxbuf; - uint32_t hn_rxbuf_gpadl; - struct hyperv_dma hn_rxbuf_dma; - - uint32_t hn_chim_gpadl; - struct hyperv_dma hn_chim_dma; - - uint32_t hn_rndis_rid; - uint32_t hn_ndis_ver; - int hn_ndis_tso_szmax; - int hn_ndis_tso_sgmin; - - int hn_rss_ind_size; - uint32_t hn_rss_hash; /* NDIS_HASH_ */ - struct ndis_rssprm_toeplitz hn_rss; +typedef void (*hn_nvs_sent_t) + (struct hn_nvs_sendctx *, struct hn_softc *, + struct vmbus_channel *, const void *, int); + +struct hn_nvs_sendctx { + hn_nvs_sent_t hn_cb; + void *hn_cbarg; }; -#define HN_FLAG_RXBUF_CONNECTED 0x0001 -#define HN_FLAG_CHIM_CONNECTED 0x0002 -#define HN_FLAG_HAS_RSSKEY 0x0004 -#define HN_FLAG_HAS_RSSIND 0x0008 -#define HN_FLAG_SYNTH_ATTACHED 0x0010 - -#define HN_CAP_VLAN 0x0001 -#define HN_CAP_MTU 0x0002 -#define HN_CAP_IPCS 0x0004 -#define HN_CAP_TCP4CS 0x0008 -#define HN_CAP_TCP6CS 0x0010 -#define HN_CAP_UDP4CS 0x0020 -#define HN_CAP_UDP6CS 0x0040 -#define HN_CAP_TSO4 0x0080 -#define HN_CAP_TSO6 0x0100 -#define HN_CAP_HASHVAL 0x0200 - -/* Capability description for use with printf(9) %b identifier. */ -#define HN_CAP_BITS \ - "\020\1VLAN\2MTU\3IPCS\4TCP4CS\5TCP6CS" \ - "\6UDP4CS\7UDP6CS\10TSO4\11TSO6\12HASHVAL" - -#define HN_LINK_FLAG_LINKUP 0x0001 -#define HN_LINK_FLAG_NETCHG 0x0002 +#define HN_NVS_SENDCTX_INITIALIZER(cb, cbarg) \ +{ \ + .hn_cb = cb, \ + .hn_cbarg = cbarg \ +} + +static __inline void +hn_nvs_sendctx_init(struct hn_nvs_sendctx *sndc, hn_nvs_sent_t cb, void *cbarg) +{ + + sndc->hn_cb = cb; + sndc->hn_cbarg = cbarg; +} + +static __inline int +hn_nvs_send(struct vmbus_channel *chan, uint16_t flags, + void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc) +{ + + return (vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, flags, + nvs_msg, nvs_msglen, (uint64_t)(uintptr_t)sndc)); +} + +static __inline int +hn_nvs_send_sglist(struct vmbus_channel *chan, struct vmbus_gpa sg[], int sglen, + void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc) +{ + + return (vmbus_chan_send_sglist(chan, sg, sglen, nvs_msg, nvs_msglen, + (uint64_t)(uintptr_t)sndc)); +} + +static __inline int +hn_nvs_send_rndis_sglist(struct vmbus_channel *chan, uint32_t rndis_mtype, + struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt) +{ + struct hn_nvs_rndis rndis; + + rndis.nvs_type = HN_NVS_TYPE_RNDIS; + rndis.nvs_rndis_mtype = rndis_mtype; + rndis.nvs_chim_idx = HN_NVS_CHIM_IDX_INVALID; + rndis.nvs_chim_sz = 0; + + return (hn_nvs_send_sglist(chan, gpa, gpa_cnt, + &rndis, sizeof(rndis), sndc)); +} + +int hn_nvs_attach(struct hn_softc *sc, int mtu); +void hn_nvs_detach(struct hn_softc *sc); +int hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch); +void hn_nvs_sent_xact(struct hn_nvs_sendctx *sndc, + struct hn_softc *sc, struct vmbus_channel *chan, + const void *data, int dlen); +int hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan, + struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, + int gpa_cnt); -#endif /* __HV_NET_VSC_H__ */ +extern struct hn_nvs_sendctx hn_nvs_sendctx_none; +#endif /* !_HN_NVS_H_ */ Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 05:17:03 2016 (r308503) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 05:37:04 2016 (r308504) @@ -74,6 +74,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -92,6 +93,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -118,11 +120,14 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include +#include +#include +#include #include #include -#include #include "vmbus_if.h" @@ -157,7 +162,7 @@ __FBSDID("$FreeBSD$"); #define HN_TX_DATA_MAXSIZE IP_MAXPACKET #define HN_TX_DATA_SEGSIZE PAGE_SIZE /* -1 for RNDIS packet message */ -#define HN_TX_DATA_SEGCNT_MAX (NETVSC_PACKET_MAXPAGE - 1) +#define HN_TX_DATA_SEGCNT_MAX (HN_GPACNT_MAX - 1) #define HN_DIRECT_TX_SIZE_DEF 128 @@ -171,7 +176,7 @@ struct hn_txdesc { struct hn_tx_ring *txr; int refs; uint32_t flags; /* HN_TXD_FLAG_ */ - struct hn_send_ctx send_ctx; + struct hn_nvs_sendctx send_ctx; uint32_t chim_index; int chim_size; @@ -409,37 +414,13 @@ hn_set_lro_lenlim(struct hn_softc *sc, i } #endif -static __inline int -hn_nvs_send_rndis_sglist1(struct vmbus_channel *chan, uint32_t rndis_mtype, - struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt) -{ - struct hn_nvs_rndis rndis; - - rndis.nvs_type = HN_NVS_TYPE_RNDIS; - rndis.nvs_rndis_mtype = rndis_mtype; - rndis.nvs_chim_idx = HN_NVS_CHIM_IDX_INVALID; - rndis.nvs_chim_sz = 0; - - return (hn_nvs_send_sglist(chan, gpa, gpa_cnt, - &rndis, sizeof(rndis), sndc)); -} - -int -hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan, - struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt) -{ - - return hn_nvs_send_rndis_sglist1(chan, HN_NVS_RNDIS_MTYPE_CTRL, - sndc, gpa, gpa_cnt); -} - static int hn_sendpkt_rndis_sglist(struct hn_tx_ring *txr, struct hn_txdesc *txd) { KASSERT(txd->chim_index == HN_NVS_CHIM_IDX_INVALID && txd->chim_size == 0, ("invalid rndis sglist txd")); - return (hn_nvs_send_rndis_sglist1(txr->hn_chan, HN_NVS_RNDIS_MTYPE_DATA, + return (hn_nvs_send_rndis_sglist(txr->hn_chan, HN_NVS_RNDIS_MTYPE_DATA, &txd->send_ctx, txr->hn_gpa, txr->hn_gpa_cnt)); } @@ -1201,7 +1182,7 @@ hn_txeof(struct hn_tx_ring *txr) } static void -hn_tx_done(struct hn_send_ctx *sndc, struct hn_softc *sc, +hn_tx_done(struct hn_nvs_sendctx *sndc, struct hn_softc *sc, struct vmbus_channel *chan, const void *data __unused, int dlen __unused) { struct hn_txdesc *txd = sndc->hn_cbarg; @@ -1446,7 +1427,7 @@ done: txd->m = m_head; /* Set the completion routine */ - hn_send_ctx_init(&txd->send_ctx, hn_tx_done, txd); + hn_nvs_sendctx_init(&txd->send_ctx, hn_tx_done, txd); return 0; } @@ -1875,7 +1856,7 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, switch (cmd) { case SIOCSIFMTU: - if (ifr->ifr_mtu > NETVSC_MAX_CONFIGURABLE_MTU) { + if (ifr->ifr_mtu > HN_MTU_MAX) { error = EINVAL; break; } @@ -2651,7 +2632,7 @@ hn_create_rx_data(struct hn_softc *sc, i * may further limit the usable space. */ sc->hn_rxbuf = hyperv_dmamem_alloc(bus_get_dma_tag(dev), - PAGE_SIZE, 0, NETVSC_RECEIVE_BUFFER_SIZE, &sc->hn_rxbuf_dma, + PAGE_SIZE, 0, HN_RXBUF_SIZE, &sc->hn_rxbuf_dma, BUS_DMA_WAITOK | BUS_DMA_ZERO); if (sc->hn_rxbuf == NULL) { device_printf(sc->hn_dev, "allocate rxbuf failed\n"); @@ -2685,9 +2666,7 @@ hn_create_rx_data(struct hn_softc *sc, i struct hn_rx_ring *rxr = &sc->hn_rx_ring[i]; rxr->hn_br = hyperv_dmamem_alloc(bus_get_dma_tag(dev), - PAGE_SIZE, 0, - NETVSC_DEVICE_RING_BUFFER_SIZE + - NETVSC_DEVICE_RING_BUFFER_SIZE, + PAGE_SIZE, 0, HN_TXBR_SIZE + HN_RXBR_SIZE, &rxr->hn_br_dma, BUS_DMA_WAITOK); if (rxr->hn_br == NULL) { device_printf(dev, "allocate bufring failed\n"); @@ -2703,7 +2682,7 @@ hn_create_rx_data(struct hn_softc *sc, i rxr->hn_ifp = sc->hn_ifp; if (i < sc->hn_tx_ring_cnt) rxr->hn_txr = &sc->hn_tx_ring[i]; - rxr->hn_rdbuf = malloc(NETVSC_PACKET_SIZE, M_DEVBUF, M_WAITOK); + rxr->hn_pktbuf = malloc(HN_PKTBUF_LEN, M_DEVBUF, M_WAITOK); rxr->hn_rx_idx = i; rxr->hn_rxbuf = sc->hn_rxbuf; @@ -2850,7 +2829,7 @@ hn_destroy_rx_data(struct hn_softc *sc) #if defined(INET) || defined(INET6) tcp_lro_free(&rxr->hn_lro); #endif - free(rxr->hn_rdbuf, M_DEVBUF); + free(rxr->hn_pktbuf, M_DEVBUF); } free(sc->hn_rx_ring, M_DEVBUF); sc->hn_rx_ring = NULL; @@ -3110,7 +3089,7 @@ hn_create_tx_data(struct hn_softc *sc, i * NOTE: It is shared by all channels. */ sc->hn_chim = hyperv_dmamem_alloc(bus_get_dma_tag(sc->hn_dev), - PAGE_SIZE, 0, NETVSC_SEND_BUFFER_SIZE, &sc->hn_chim_dma, + PAGE_SIZE, 0, HN_CHIM_SIZE, &sc->hn_chim_dma, BUS_DMA_WAITOK | BUS_DMA_ZERO); if (sc->hn_chim == NULL) { device_printf(sc->hn_dev, "allocate txbuf failed\n"); @@ -3528,8 +3507,8 @@ hn_chan_attach(struct hn_softc *sc, stru */ cbr.cbr = rxr->hn_br; cbr.cbr_paddr = rxr->hn_br_dma.hv_paddr; - cbr.cbr_txsz = NETVSC_DEVICE_RING_BUFFER_SIZE; - cbr.cbr_rxsz = NETVSC_DEVICE_RING_BUFFER_SIZE; + cbr.cbr_txsz = HN_TXBR_SIZE; + cbr.cbr_rxsz = HN_RXBR_SIZE; error = vmbus_chan_open_br(chan, &cbr, NULL, 0, hn_chan_callback, rxr); if (error) { if_printf(sc->hn_ifp, "open chan%u failed: %d\n", @@ -4087,9 +4066,9 @@ static void hn_nvs_handle_comp(struct hn_softc *sc, struct vmbus_channel *chan, const struct vmbus_chanpkt_hdr *pkt) { - struct hn_send_ctx *sndc; + struct hn_nvs_sendctx *sndc; - sndc = (struct hn_send_ctx *)(uintptr_t)pkt->cph_xactid; + sndc = (struct hn_nvs_sendctx *)(uintptr_t)pkt->cph_xactid; sndc->hn_cb(sndc, sc, chan, VMBUS_CHANPKT_CONST_DATA(pkt), VMBUS_CHANPKT_DATALEN(pkt)); /* @@ -4146,7 +4125,7 @@ hn_nvs_handle_rxbuf(struct hn_softc *sc, ofs = pkt->cp_rxbuf[i].rb_ofs; len = pkt->cp_rxbuf[i].rb_len; - if (__predict_false(ofs + len > NETVSC_RECEIVE_BUFFER_SIZE)) { + if (__predict_false(ofs + len > HN_RXBUF_SIZE)) { if_printf(rxr->hn_ifp, "%dth RNDIS msg overflow rxbuf, " "ofs %d, len %d\n", i, ofs, len); continue; @@ -4201,9 +4180,9 @@ hn_chan_callback(struct vmbus_channel *c struct hn_rx_ring *rxr = xrxr; struct hn_softc *sc = rxr->hn_ifp->if_softc; void *buffer; - int bufferlen = NETVSC_PACKET_SIZE; + int bufferlen = HN_PKTBUF_LEN; - buffer = rxr->hn_rdbuf; + buffer = rxr->hn_pktbuf; do { struct vmbus_chanpkt_hdr *pkt = buffer; uint32_t bytes_rxed; @@ -4230,7 +4209,7 @@ hn_chan_callback(struct vmbus_channel *c } } else if (ret == ENOBUFS) { /* Handle large packet */ - if (bufferlen > NETVSC_PACKET_SIZE) { + if (bufferlen > HN_PKTBUF_LEN) { free(buffer, M_DEVBUF); buffer = NULL; } @@ -4251,7 +4230,7 @@ hn_chan_callback(struct vmbus_channel *c } } while (1); - if (bufferlen > NETVSC_PACKET_SIZE) + if (bufferlen > HN_PKTBUF_LEN) free(buffer, M_DEVBUF); hv_rf_channel_rollup(rxr, rxr->hn_txr); Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 05:17:03 2016 (r308503) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 05:37:04 2016 (r308504) @@ -35,26 +35,31 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include + +#include + +#include #include #include #include -#include +#include #include + #include #include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include #include + +#include +#include +#include #include #include -#include -#include #define HV_RF_RECVINFO_VLAN 0x1 #define HV_RF_RECVINFO_CSUM 0x2 @@ -550,7 +555,7 @@ hn_rndis_get_linkstatus(struct hn_softc static const void * hn_rndis_xact_exec1(struct hn_softc *sc, struct vmbus_xact *xact, size_t reqlen, - struct hn_send_ctx *sndc, size_t *comp_len) + struct hn_nvs_sendctx *sndc, size_t *comp_len) { struct vmbus_gpa gpa[HN_XACT_REQ_PGCNT]; int gpa_cnt, error; @@ -609,7 +614,7 @@ hn_rndis_xact_execute(struct hn_softc *s /* * Execute the xact setup by the caller. */ - comp = hn_rndis_xact_exec1(sc, xact, reqlen, &hn_send_ctx_none, + comp = hn_rndis_xact_exec1(sc, xact, reqlen, &hn_nvs_sendctx_none, &comp_len); if (comp == NULL) return (NULL); @@ -1215,7 +1220,7 @@ hn_rndis_halt(struct hn_softc *sc) { struct vmbus_xact *xact; struct rndis_halt_req *halt; - struct hn_send_ctx sndc; + struct hn_nvs_sendctx sndc; size_t comp_len; xact = vmbus_xact_get(sc->hn_xact, sizeof(*halt)); @@ -1229,7 +1234,7 @@ hn_rndis_halt(struct hn_softc *sc) halt->rm_rid = hn_rndis_rid(sc); /* No RNDIS completion; rely on NVS message send completion */ - hn_send_ctx_init(&sndc, hn_nvs_sent_xact, xact); + hn_nvs_sendctx_init(&sndc, hn_nvs_sent_xact, xact); hn_rndis_xact_exec1(sc, xact, sizeof(*halt), &sndc, &comp_len); vmbus_xact_put(xact); Modified: stable/10/sys/dev/hyperv/netvsc/if_hnvar.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 05:17:03 2016 (r308503) +++ stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 05:37:04 2016 (r308504) @@ -29,24 +29,27 @@ #ifndef _IF_HNVAR_H_ #define _IF_HNVAR_H_ -#include +#define HN_USE_TXDESC_BUFRING -#include -#include +#define HN_CHIM_SIZE (15 * 1024 * 1024) -struct hn_softc; +#define HN_RXBUF_SIZE (16 * 1024 * 1024) +#define HN_RXBUF_SIZE_COMPAT (15 * 1024 * 1024) -struct vmbus_channel; -struct hn_send_ctx; +/* Claimed to be 12232B */ +#define HN_MTU_MAX (9 * 1024) -typedef void (*hn_sent_callback_t) - (struct hn_send_ctx *, struct hn_softc *, - struct vmbus_channel *, const void *, int); +#define HN_PKTBUF_LEN 4096 -struct hn_send_ctx { - hn_sent_callback_t hn_cb; - void *hn_cbarg; -}; +#define HN_TXBR_SIZE (128 * PAGE_SIZE) +#define HN_RXBR_SIZE (128 * PAGE_SIZE) + +#define HN_XACT_REQ_PGCNT 2 +#define HN_XACT_RESP_PGCNT 2 +#define HN_XACT_REQ_SIZE (HN_XACT_REQ_PGCNT * PAGE_SIZE) +#define HN_XACT_RESP_SIZE (HN_XACT_RESP_PGCNT * PAGE_SIZE) + +#define HN_GPACNT_MAX 32 #define HN_NDIS_VLAN_INFO_INVALID 0xffffffff #define HN_NDIS_RXCSUM_INFO_INVALID 0 @@ -59,39 +62,187 @@ struct hn_recvinfo { uint32_t hash_value; }; -#define HN_SEND_CTX_INITIALIZER(cb, cbarg) \ -{ \ - .hn_cb = cb, \ - .hn_cbarg = cbarg \ -} - -static __inline void -hn_send_ctx_init(struct hn_send_ctx *sndc, hn_sent_callback_t cb, void *cbarg) -{ - - sndc->hn_cb = cb; - sndc->hn_cbarg = cbarg; -} - -static __inline int -hn_nvs_send(struct vmbus_channel *chan, uint16_t flags, - void *nvs_msg, int nvs_msglen, struct hn_send_ctx *sndc) -{ - - return (vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, flags, - nvs_msg, nvs_msglen, (uint64_t)(uintptr_t)sndc)); -} - -static __inline int -hn_nvs_send_sglist(struct vmbus_channel *chan, struct vmbus_gpa sg[], int sglen, - void *nvs_msg, int nvs_msglen, struct hn_send_ctx *sndc) -{ - - return (vmbus_chan_send_sglist(chan, sg, sglen, nvs_msg, nvs_msglen, - (uint64_t)(uintptr_t)sndc)); -} +struct hn_txdesc; +#ifndef HN_USE_TXDESC_BUFRING +SLIST_HEAD(hn_txdesc_list, hn_txdesc); +#else +struct buf_ring; +#endif +struct hn_tx_ring; + +struct hn_rx_ring { + struct ifnet *hn_ifp; + struct hn_tx_ring *hn_txr; + void *hn_pktbuf; + uint8_t *hn_rxbuf; /* shadow sc->hn_rxbuf */ + int hn_rx_idx; + + /* Trust csum verification on host side */ + int hn_trust_hcsum; /* HN_TRUST_HCSUM_ */ + struct lro_ctrl hn_lro; + + u_long hn_csum_ip; + u_long hn_csum_tcp; + u_long hn_csum_udp; + u_long hn_csum_trusted; + u_long hn_lro_tried; + u_long hn_small_pkts; + u_long hn_pkts; + u_long hn_rss_pkts; + + /* Rarely used stuffs */ + struct sysctl_oid *hn_rx_sysctl_tree; + int hn_rx_flags; + + void *hn_br; /* TX/RX bufring */ + struct hyperv_dma hn_br_dma; +} __aligned(CACHE_LINE_SIZE); + +#define HN_TRUST_HCSUM_IP 0x0001 +#define HN_TRUST_HCSUM_TCP 0x0002 +#define HN_TRUST_HCSUM_UDP 0x0004 + +#define HN_RX_FLAG_ATTACHED 0x1 + +struct hn_tx_ring { +#ifndef HN_USE_TXDESC_BUFRING + struct mtx hn_txlist_spin; + struct hn_txdesc_list hn_txlist; +#else + struct buf_ring *hn_txdesc_br; +#endif + int hn_txdesc_cnt; + int hn_txdesc_avail; + u_short hn_has_txeof; + u_short hn_txdone_cnt; + + int hn_sched_tx; + void (*hn_txeof)(struct hn_tx_ring *); + struct taskqueue *hn_tx_taskq; + struct task hn_tx_task; + struct task hn_txeof_task; + + struct buf_ring *hn_mbuf_br; + int hn_oactive; + int hn_tx_idx; + int hn_tx_flags; + + struct mtx hn_tx_lock; + struct hn_softc *hn_sc; + struct vmbus_channel *hn_chan; + + int hn_direct_tx_size; + int hn_chim_size; + bus_dma_tag_t hn_tx_data_dtag; + uint64_t hn_csum_assist; + + int (*hn_sendpkt)(struct hn_tx_ring *, struct hn_txdesc *); + int hn_suspended; + int hn_gpa_cnt; + struct vmbus_gpa hn_gpa[HN_GPACNT_MAX]; + + u_long hn_no_txdescs; + u_long hn_send_failed; + u_long hn_txdma_failed; + u_long hn_tx_collapsed; + u_long hn_tx_chimney_tried; + u_long hn_tx_chimney; + u_long hn_pkts; + + /* Rarely used stuffs */ + struct hn_txdesc *hn_txdesc; + bus_dma_tag_t hn_tx_rndis_dtag; + struct sysctl_oid *hn_tx_sysctl_tree; +} __aligned(CACHE_LINE_SIZE); + +#define HN_TX_FLAG_ATTACHED 0x1 +#define HN_TX_FLAG_HASHVAL 0x2 /* support HASHVAL pktinfo */ + +/* + * Device-specific softc structure + */ +struct hn_softc { + struct ifnet *hn_ifp; + struct arpcom arpcom; + struct ifmedia hn_media; + device_t hn_dev; + int hn_if_flags; + struct sx hn_lock; + struct vmbus_channel *hn_prichan; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable-10@freebsd.org Fri Nov 11 05:53:59 2016 Return-Path: Delivered-To: svn-src-stable-10@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 ECE9BC3B038; Fri, 11 Nov 2016 05:53:59 +0000 (UTC) (envelope-from sephe@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 C067A1ECF; Fri, 11 Nov 2016 05:53:59 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB5rwQ0050271; Fri, 11 Nov 2016 05:53:58 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB5rwUU050264; Fri, 11 Nov 2016 05:53:58 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110553.uAB5rwUU050264@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 05:53:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308505 - in stable/10/sys: conf dev/hyperv/netvsc modules/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 05:54:00 -0000 Author: sephe Date: Fri Nov 11 05:53:58 2016 New Revision: 308505 URL: https://svnweb.freebsd.org/changeset/base/308505 Log: MFC 308011,308012 308011 hyperv/hn: Rename cleaned up NVS header file. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8353 308012 hyperv/hn: Rename cleaned up NVS source file. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8354 Added: stable/10/sys/dev/hyperv/netvsc/hn_nvs.c - copied, changed from r308504, stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c stable/10/sys/dev/hyperv/netvsc/hn_nvs.h - copied unchanged from r308504, stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Deleted: stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h Modified: stable/10/sys/conf/files.amd64 stable/10/sys/conf/files.i386 stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c stable/10/sys/modules/hyperv/netvsc/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/conf/files.amd64 ============================================================================== --- stable/10/sys/conf/files.amd64 Fri Nov 11 05:37:04 2016 (r308504) +++ stable/10/sys/conf/files.amd64 Fri Nov 11 05:53:58 2016 (r308505) @@ -261,7 +261,7 @@ dev/hwpmc/hwpmc_uncore.c optional hwpmc dev/hwpmc/hwpmc_piv.c optional hwpmc dev/hwpmc/hwpmc_tsc.c optional hwpmc dev/hwpmc/hwpmc_x86.c optional hwpmc -dev/hyperv/netvsc/hv_net_vsc.c optional hyperv +dev/hyperv/netvsc/hn_nvs.c optional hyperv dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c optional hyperv dev/hyperv/netvsc/hv_rndis_filter.c optional hyperv dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c optional hyperv Modified: stable/10/sys/conf/files.i386 ============================================================================== --- stable/10/sys/conf/files.i386 Fri Nov 11 05:37:04 2016 (r308504) +++ stable/10/sys/conf/files.i386 Fri Nov 11 05:53:58 2016 (r308505) @@ -238,7 +238,7 @@ dev/hwpmc/hwpmc_piv.c optional hwpmc dev/hwpmc/hwpmc_ppro.c optional hwpmc dev/hwpmc/hwpmc_tsc.c optional hwpmc dev/hwpmc/hwpmc_x86.c optional hwpmc -dev/hyperv/netvsc/hv_net_vsc.c optional hyperv +dev/hyperv/netvsc/hn_nvs.c optional hyperv dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c optional hyperv dev/hyperv/netvsc/hv_rndis_filter.c optional hyperv dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c optional hyperv Copied and modified: stable/10/sys/dev/hyperv/netvsc/hn_nvs.c (from r308504, stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c) ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.c Fri Nov 11 05:37:04 2016 (r308504, copy source) +++ stable/10/sys/dev/hyperv/netvsc/hn_nvs.c Fri Nov 11 05:53:58 2016 (r308505) @@ -58,7 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include static int hn_nvs_conn_chim(struct hn_softc *); static int hn_nvs_conn_rxbuf(struct hn_softc *); Copied: stable/10/sys/dev/hyperv/netvsc/hn_nvs.h (from r308504, stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/netvsc/hn_nvs.h Fri Nov 11 05:53:58 2016 (r308505, copy of r308504, stable/10/sys/dev/hyperv/netvsc/hv_net_vsc.h) @@ -0,0 +1,106 @@ +/*- + * Copyright (c) 2009-2012,2016 Microsoft Corp. + * Copyright (c) 2010-2012 Citrix Inc. + * Copyright (c) 2012 NetApp Inc. + * 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 unmodified, 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. + * + * $FreeBSD$ + */ + +#ifndef _HN_NVS_H_ +#define _HN_NVS_H_ + +struct hn_nvs_sendctx; +struct vmbus_channel; +struct hn_softc; + +typedef void (*hn_nvs_sent_t) + (struct hn_nvs_sendctx *, struct hn_softc *, + struct vmbus_channel *, const void *, int); + +struct hn_nvs_sendctx { + hn_nvs_sent_t hn_cb; + void *hn_cbarg; +}; + +#define HN_NVS_SENDCTX_INITIALIZER(cb, cbarg) \ +{ \ + .hn_cb = cb, \ + .hn_cbarg = cbarg \ +} + +static __inline void +hn_nvs_sendctx_init(struct hn_nvs_sendctx *sndc, hn_nvs_sent_t cb, void *cbarg) +{ + + sndc->hn_cb = cb; + sndc->hn_cbarg = cbarg; +} + +static __inline int +hn_nvs_send(struct vmbus_channel *chan, uint16_t flags, + void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc) +{ + + return (vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, flags, + nvs_msg, nvs_msglen, (uint64_t)(uintptr_t)sndc)); +} + +static __inline int +hn_nvs_send_sglist(struct vmbus_channel *chan, struct vmbus_gpa sg[], int sglen, + void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc) +{ + + return (vmbus_chan_send_sglist(chan, sg, sglen, nvs_msg, nvs_msglen, + (uint64_t)(uintptr_t)sndc)); +} + +static __inline int +hn_nvs_send_rndis_sglist(struct vmbus_channel *chan, uint32_t rndis_mtype, + struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt) +{ + struct hn_nvs_rndis rndis; + + rndis.nvs_type = HN_NVS_TYPE_RNDIS; + rndis.nvs_rndis_mtype = rndis_mtype; + rndis.nvs_chim_idx = HN_NVS_CHIM_IDX_INVALID; + rndis.nvs_chim_sz = 0; + + return (hn_nvs_send_sglist(chan, gpa, gpa_cnt, + &rndis, sizeof(rndis), sndc)); +} + +int hn_nvs_attach(struct hn_softc *sc, int mtu); +void hn_nvs_detach(struct hn_softc *sc); +int hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch); +void hn_nvs_sent_xact(struct hn_nvs_sendctx *sndc, + struct hn_softc *sc, struct vmbus_channel *chan, + const void *data, int dlen); +int hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan, + struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, + int gpa_cnt); + +extern struct hn_nvs_sendctx hn_nvs_sendctx_none; + +#endif /* !_HN_NVS_H_ */ Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 05:37:04 2016 (r308504) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 05:53:58 2016 (r308505) @@ -126,7 +126,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include #include "vmbus_if.h" Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 05:37:04 2016 (r308504) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 05:53:58 2016 (r308505) @@ -58,7 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include #define HV_RF_RECVINFO_VLAN 0x1 Modified: stable/10/sys/modules/hyperv/netvsc/Makefile ============================================================================== --- stable/10/sys/modules/hyperv/netvsc/Makefile Fri Nov 11 05:37:04 2016 (r308504) +++ stable/10/sys/modules/hyperv/netvsc/Makefile Fri Nov 11 05:53:58 2016 (r308505) @@ -4,7 +4,7 @@ ${.CURDIR}/../../../dev/hyperv/vmbus KMOD= hv_netvsc -SRCS= hv_net_vsc.c \ +SRCS= hn_nvs.c \ hv_netvsc_drv_freebsd.c \ hv_rndis_filter.c SRCS+= bus_if.h device_if.h opt_inet.h opt_inet6.h vmbus_if.h From owner-svn-src-stable-10@freebsd.org Fri Nov 11 06:23:02 2016 Return-Path: Delivered-To: svn-src-stable-10@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 5AD9CC3B861; Fri, 11 Nov 2016 06:23:02 +0000 (UTC) (envelope-from sephe@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 2686D1DEF; Fri, 11 Nov 2016 06:23:02 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB6N15L062432; Fri, 11 Nov 2016 06:23:01 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB6N1aI062429; Fri, 11 Nov 2016 06:23:01 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110623.uAB6N1aI062429@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 06:23:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308506 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 06:23:02 -0000 Author: sephe Date: Fri Nov 11 06:23:01 2016 New Revision: 308506 URL: https://svnweb.freebsd.org/changeset/base/308506 Log: MFC 308013-308017 308013 hyperv/hn: Nuke unnecessary indirection. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8355 308014 hyperv/hn: Reorganize RX path; mainly pull non-control code path up Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8356 308015 hyperv/hn: Pull data path code up. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8357 308016 hyperv/hn: Cleanup RNDIS related files. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8358 308017 hyperv/hn: Change header guardian; in preparation for the upcoming rename. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8359 Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 05:53:58 2016 (r308505) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 06:23:01 2016 (r308506) @@ -168,6 +168,16 @@ __FBSDID("$FreeBSD$"); #define HN_EARLY_TXEOF_THRESH 8 +#define HN_RXINFO_VLAN 0x0001 +#define HN_RXINFO_CSUM 0x0002 +#define HN_RXINFO_HASHINF 0x0004 +#define HN_RXINFO_HASHVAL 0x0008 +#define HN_RXINFO_ALL \ + (HN_RXINFO_VLAN | \ + HN_RXINFO_CSUM | \ + HN_RXINFO_HASHINF | \ + HN_RXINFO_HASHVAL) + struct hn_txdesc { #ifndef HN_USE_TXDESC_BUFRING SLIST_ENTRY(hn_txdesc) link; @@ -190,6 +200,17 @@ struct hn_txdesc { #define HN_TXD_FLAG_ONLIST 0x1 #define HN_TXD_FLAG_DMAMAP 0x2 +#define HN_NDIS_VLAN_INFO_INVALID 0xffffffff +#define HN_NDIS_RXCSUM_INFO_INVALID 0 +#define HN_NDIS_HASH_INFO_INVALID 0 + +struct hn_rxinfo { + uint32_t vlan_info; + uint32_t csum_info; + uint32_t hash_info; + uint32_t hash_value; +}; + #define HN_LRO_LENLIM_MULTIRX_DEF (12 * ETHERMTU) #define HN_LRO_LENLIM_DEF (25 * ETHERMTU) /* YYY 2*MTU is a bit rough, but should be good enough. */ @@ -360,6 +381,7 @@ static void hn_chan_detach(struct hn_sof static int hn_attach_subchans(struct hn_softc *); static void hn_detach_allchans(struct hn_softc *); static void hn_chan_callback(struct vmbus_channel *chan, void *xrxr); +static void hn_chan_rollup(struct hn_rx_ring *, struct hn_tx_ring *); static void hn_set_ring_inuse(struct hn_softc *, int); static int hn_synth_attach(struct hn_softc *, int); static void hn_synth_detach(struct hn_softc *); @@ -378,12 +400,18 @@ static void hn_link_status(struct hn_sof static int hn_sendpkt_rndis_sglist(struct hn_tx_ring *, struct hn_txdesc *); static int hn_sendpkt_rndis_chim(struct hn_tx_ring *, struct hn_txdesc *); static int hn_set_rxfilter(struct hn_softc *); +static void hn_link_status_update(struct hn_softc *); +static void hn_network_change(struct hn_softc *); + +static int hn_rndis_rxinfo(const void *, int, struct hn_rxinfo *); +static void hn_rndis_rx_data(struct hn_rx_ring *, const void *, int); +static void hn_rndis_rx_status(struct hn_softc *, const void *, int); static void hn_nvs_handle_notify(struct hn_softc *sc, const struct vmbus_chanpkt_hdr *pkt); static void hn_nvs_handle_comp(struct hn_softc *sc, struct vmbus_channel *chan, const struct vmbus_chanpkt_hdr *pkt); -static void hn_nvs_handle_rxbuf(struct hn_softc *sc, struct hn_rx_ring *rxr, +static void hn_nvs_handle_rxbuf(struct hn_rx_ring *rxr, struct vmbus_channel *chan, const struct vmbus_chanpkt_hdr *pkthdr); static void hn_nvs_ack_rxbuf(struct vmbus_channel *chan, uint64_t tid); @@ -1021,7 +1049,7 @@ hn_netchg_status_taskfunc(void *xsc, int hn_link_status(sc); } -void +static void hn_link_status_update(struct hn_softc *sc) { @@ -1029,7 +1057,7 @@ hn_link_status_update(struct hn_softc *s taskqueue_enqueue(sc->hn_mgmt_taskq, &sc->hn_link_task); } -void +static void hn_network_change(struct hn_softc *sc) { @@ -1204,7 +1232,7 @@ hn_tx_done(struct hn_nvs_sendctx *sndc, } } -void +static void hn_chan_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr) { #if defined(INET) || defined(INET6) @@ -1238,6 +1266,42 @@ hn_rndis_pktmsg_offset(uint32_t ofs) return (ofs - __offsetof(struct rndis_packet_msg, rm_dataoffset)); } +static __inline void * +hn_rndis_pktinfo_append(struct rndis_packet_msg *pkt, size_t pktsize, + size_t pi_dlen, uint32_t pi_type) +{ + const size_t pi_size = HN_RNDIS_PKTINFO_SIZE(pi_dlen); + struct rndis_pktinfo *pi; + + KASSERT((pi_size & RNDIS_PACKET_MSG_OFFSET_ALIGNMASK) == 0, + ("unaligned pktinfo size %zu, pktinfo dlen %zu", pi_size, pi_dlen)); + + /* + * Per-packet-info does not move; it only grows. + * + * NOTE: + * rm_pktinfooffset in this phase counts from the beginning + * of rndis_packet_msg. + */ + KASSERT(pkt->rm_pktinfooffset + pkt->rm_pktinfolen + pi_size <= pktsize, + ("%u pktinfo overflows RNDIS packet msg", pi_type)); + pi = (struct rndis_pktinfo *)((uint8_t *)pkt + pkt->rm_pktinfooffset + + pkt->rm_pktinfolen); + pkt->rm_pktinfolen += pi_size; + + pi->rm_size = pi_size; + pi->rm_type = pi_type; + pi->rm_pktinfooffset = RNDIS_PKTINFO_OFFSET; + + /* Data immediately follow per-packet-info. */ + pkt->rm_dataoffset += pi_size; + + /* Update RNDIS packet msg length */ + pkt->rm_len += pi_size; + + return (pi->rm_data); +} + /* * NOTE: * If this function fails, then both txd and m_head0 will be freed. @@ -1636,15 +1700,9 @@ hn_lro_rx(struct lro_ctrl *lc, struct mb } #endif -/* - * Called when we receive a data packet from the "wire" on the - * specified device - * - * Note: This is no longer used as a callback - */ -int +static int hn_rxpkt(struct hn_rx_ring *rxr, const void *data, int dlen, - const struct hn_recvinfo *info) + const struct hn_rxinfo *info) { struct ifnet *ifp = rxr->hn_ifp; struct mbuf *m_new; @@ -4044,6 +4102,325 @@ hn_resume(struct hn_softc *sc) hn_resume_mgmt(sc); } +static void +hn_rndis_rx_status(struct hn_softc *sc, const void *data, int dlen) +{ + const struct rndis_status_msg *msg; + int ofs; + + if (dlen < sizeof(*msg)) { + if_printf(sc->hn_ifp, "invalid RNDIS status\n"); + return; + } + msg = data; + + switch (msg->rm_status) { + case RNDIS_STATUS_MEDIA_CONNECT: + case RNDIS_STATUS_MEDIA_DISCONNECT: + hn_link_status_update(sc); + break; + + case RNDIS_STATUS_TASK_OFFLOAD_CURRENT_CONFIG: + /* Not really useful; ignore. */ + break; + + case RNDIS_STATUS_NETWORK_CHANGE: + ofs = RNDIS_STBUFOFFSET_ABS(msg->rm_stbufoffset); + if (dlen < ofs + msg->rm_stbuflen || + msg->rm_stbuflen < sizeof(uint32_t)) { + if_printf(sc->hn_ifp, "network changed\n"); + } else { + uint32_t change; + + memcpy(&change, ((const uint8_t *)msg) + ofs, + sizeof(change)); + if_printf(sc->hn_ifp, "network changed, change %u\n", + change); + } + hn_network_change(sc); + break; + + default: + if_printf(sc->hn_ifp, "unknown RNDIS status 0x%08x\n", + msg->rm_status); + break; + } +} + +static int +hn_rndis_rxinfo(const void *info_data, int info_dlen, struct hn_rxinfo *info) +{ + const struct rndis_pktinfo *pi = info_data; + uint32_t mask = 0; + + while (info_dlen != 0) { + const void *data; + uint32_t dlen; + + if (__predict_false(info_dlen < sizeof(*pi))) + return (EINVAL); + if (__predict_false(info_dlen < pi->rm_size)) + return (EINVAL); + info_dlen -= pi->rm_size; + + if (__predict_false(pi->rm_size & RNDIS_PKTINFO_SIZE_ALIGNMASK)) + return (EINVAL); + if (__predict_false(pi->rm_size < pi->rm_pktinfooffset)) + return (EINVAL); + dlen = pi->rm_size - pi->rm_pktinfooffset; + data = pi->rm_data; + + switch (pi->rm_type) { + case NDIS_PKTINFO_TYPE_VLAN: + if (__predict_false(dlen < NDIS_VLAN_INFO_SIZE)) + return (EINVAL); + info->vlan_info = *((const uint32_t *)data); + mask |= HN_RXINFO_VLAN; + break; + + case NDIS_PKTINFO_TYPE_CSUM: + if (__predict_false(dlen < NDIS_RXCSUM_INFO_SIZE)) + return (EINVAL); + info->csum_info = *((const uint32_t *)data); + mask |= HN_RXINFO_CSUM; + break; + + case HN_NDIS_PKTINFO_TYPE_HASHVAL: + if (__predict_false(dlen < HN_NDIS_HASH_VALUE_SIZE)) + return (EINVAL); + info->hash_value = *((const uint32_t *)data); + mask |= HN_RXINFO_HASHVAL; + break; + + case HN_NDIS_PKTINFO_TYPE_HASHINF: + if (__predict_false(dlen < HN_NDIS_HASH_INFO_SIZE)) + return (EINVAL); + info->hash_info = *((const uint32_t *)data); + mask |= HN_RXINFO_HASHINF; + break; + + default: + goto next; + } + + if (mask == HN_RXINFO_ALL) { + /* All found; done */ + break; + } +next: + pi = (const struct rndis_pktinfo *) + ((const uint8_t *)pi + pi->rm_size); + } + + /* + * Final fixup. + * - If there is no hash value, invalidate the hash info. + */ + if ((mask & HN_RXINFO_HASHVAL) == 0) + info->hash_info = HN_NDIS_HASH_INFO_INVALID; + return (0); +} + +static __inline bool +hn_rndis_check_overlap(int off, int len, int check_off, int check_len) +{ + + if (off < check_off) { + if (__predict_true(off + len <= check_off)) + return (false); + } else if (off > check_off) { + if (__predict_true(check_off + check_len <= off)) + return (false); + } + return (true); +} + +static void +hn_rndis_rx_data(struct hn_rx_ring *rxr, const void *data, int dlen) +{ + const struct rndis_packet_msg *pkt; + struct hn_rxinfo info; + int data_off, pktinfo_off, data_len, pktinfo_len; + + /* + * Check length. + */ + if (__predict_false(dlen < sizeof(*pkt))) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg\n"); + return; + } + pkt = data; + + if (__predict_false(dlen < pkt->rm_len)) { + if_printf(rxr->hn_ifp, "truncated RNDIS packet msg, " + "dlen %d, msglen %u\n", dlen, pkt->rm_len); + return; + } + if (__predict_false(pkt->rm_len < + pkt->rm_datalen + pkt->rm_oobdatalen + pkt->rm_pktinfolen)) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msglen, " + "msglen %u, data %u, oob %u, pktinfo %u\n", + pkt->rm_len, pkt->rm_datalen, pkt->rm_oobdatalen, + pkt->rm_pktinfolen); + return; + } + if (__predict_false(pkt->rm_datalen == 0)) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, no data\n"); + return; + } + + /* + * Check offests. + */ +#define IS_OFFSET_INVALID(ofs) \ + ((ofs) < RNDIS_PACKET_MSG_OFFSET_MIN || \ + ((ofs) & RNDIS_PACKET_MSG_OFFSET_ALIGNMASK)) + + /* XXX Hyper-V does not meet data offset alignment requirement */ + if (__predict_false(pkt->rm_dataoffset < RNDIS_PACKET_MSG_OFFSET_MIN)) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " + "data offset %u\n", pkt->rm_dataoffset); + return; + } + if (__predict_false(pkt->rm_oobdataoffset > 0 && + IS_OFFSET_INVALID(pkt->rm_oobdataoffset))) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " + "oob offset %u\n", pkt->rm_oobdataoffset); + return; + } + if (__predict_true(pkt->rm_pktinfooffset > 0) && + __predict_false(IS_OFFSET_INVALID(pkt->rm_pktinfooffset))) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " + "pktinfo offset %u\n", pkt->rm_pktinfooffset); + return; + } + +#undef IS_OFFSET_INVALID + + data_off = RNDIS_PACKET_MSG_OFFSET_ABS(pkt->rm_dataoffset); + data_len = pkt->rm_datalen; + pktinfo_off = RNDIS_PACKET_MSG_OFFSET_ABS(pkt->rm_pktinfooffset); + pktinfo_len = pkt->rm_pktinfolen; + + /* + * Check OOB coverage. + */ + if (__predict_false(pkt->rm_oobdatalen != 0)) { + int oob_off, oob_len; + + if_printf(rxr->hn_ifp, "got oobdata\n"); + oob_off = RNDIS_PACKET_MSG_OFFSET_ABS(pkt->rm_oobdataoffset); + oob_len = pkt->rm_oobdatalen; + + if (__predict_false(oob_off + oob_len > pkt->rm_len)) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " + "oob overflow, msglen %u, oob abs %d len %d\n", + pkt->rm_len, oob_off, oob_len); + return; + } + + /* + * Check against data. + */ + if (hn_rndis_check_overlap(oob_off, oob_len, + data_off, data_len)) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " + "oob overlaps data, oob abs %d len %d, " + "data abs %d len %d\n", + oob_off, oob_len, data_off, data_len); + return; + } + + /* + * Check against pktinfo. + */ + if (pktinfo_len != 0 && + hn_rndis_check_overlap(oob_off, oob_len, + pktinfo_off, pktinfo_len)) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " + "oob overlaps pktinfo, oob abs %d len %d, " + "pktinfo abs %d len %d\n", + oob_off, oob_len, pktinfo_off, pktinfo_len); + return; + } + } + + /* + * Check per-packet-info coverage and find useful per-packet-info. + */ + info.vlan_info = HN_NDIS_VLAN_INFO_INVALID; + info.csum_info = HN_NDIS_RXCSUM_INFO_INVALID; + info.hash_info = HN_NDIS_HASH_INFO_INVALID; + if (__predict_true(pktinfo_len != 0)) { + bool overlap; + int error; + + if (__predict_false(pktinfo_off + pktinfo_len > pkt->rm_len)) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " + "pktinfo overflow, msglen %u, " + "pktinfo abs %d len %d\n", + pkt->rm_len, pktinfo_off, pktinfo_len); + return; + } + + /* + * Check packet info coverage. + */ + overlap = hn_rndis_check_overlap(pktinfo_off, pktinfo_len, + data_off, data_len); + if (__predict_false(overlap)) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " + "pktinfo overlap data, pktinfo abs %d len %d, " + "data abs %d len %d\n", + pktinfo_off, pktinfo_len, data_off, data_len); + return; + } + + /* + * Find useful per-packet-info. + */ + error = hn_rndis_rxinfo(((const uint8_t *)pkt) + pktinfo_off, + pktinfo_len, &info); + if (__predict_false(error)) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg " + "pktinfo\n"); + return; + } + } + + if (__predict_false(data_off + data_len > pkt->rm_len)) { + if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " + "data overflow, msglen %u, data abs %d len %d\n", + pkt->rm_len, data_off, data_len); + return; + } + hn_rxpkt(rxr, ((const uint8_t *)pkt) + data_off, data_len, &info); +} + +static __inline void +hn_rndis_rxpkt(struct hn_rx_ring *rxr, const void *data, int dlen) +{ + const struct rndis_msghdr *hdr; + + if (__predict_false(dlen < sizeof(*hdr))) { + if_printf(rxr->hn_ifp, "invalid RNDIS msg\n"); + return; + } + hdr = data; + + if (__predict_true(hdr->rm_type == REMOTE_NDIS_PACKET_MSG)) { + /* Hot data path. */ + hn_rndis_rx_data(rxr, data, dlen); + /* Done! */ + return; + } + + if (hdr->rm_type == REMOTE_NDIS_INDICATE_STATUS_MSG) + hn_rndis_rx_status(rxr->hn_ifp->if_softc, data, dlen); + else + hn_rndis_rx_ctrl(rxr->hn_ifp->if_softc, data, dlen); +} + static void hn_nvs_handle_notify(struct hn_softc *sc, const struct vmbus_chanpkt_hdr *pkt) { @@ -4079,8 +4456,8 @@ hn_nvs_handle_comp(struct hn_softc *sc, } static void -hn_nvs_handle_rxbuf(struct hn_softc *sc, struct hn_rx_ring *rxr, - struct vmbus_channel *chan, const struct vmbus_chanpkt_hdr *pkthdr) +hn_nvs_handle_rxbuf(struct hn_rx_ring *rxr, struct vmbus_channel *chan, + const struct vmbus_chanpkt_hdr *pkthdr) { const struct vmbus_chanpkt_rxbuf *pkt; const struct hn_nvs_hdr *nvs_hdr; @@ -4130,9 +4507,9 @@ hn_nvs_handle_rxbuf(struct hn_softc *sc, "ofs %d, len %d\n", i, ofs, len); continue; } - hv_rf_on_receive(sc, rxr, rxr->hn_rxbuf + ofs, len); + hn_rndis_rxpkt(rxr, rxr->hn_rxbuf + ofs, len); } - + /* * Moved completion call back here so that all received * messages (not just data messages) will trigger a response @@ -4196,7 +4573,7 @@ hn_chan_callback(struct vmbus_channel *c hn_nvs_handle_comp(sc, chan, pkt); break; case VMBUS_CHANPKT_TYPE_RXBUF: - hn_nvs_handle_rxbuf(sc, rxr, chan, pkt); + hn_nvs_handle_rxbuf(rxr, chan, pkt); break; case VMBUS_CHANPKT_TYPE_INBAND: hn_nvs_handle_notify(sc, pkt); @@ -4233,7 +4610,7 @@ hn_chan_callback(struct vmbus_channel *c if (bufferlen > HN_PKTBUF_LEN) free(buffer, M_DEVBUF); - hv_rf_channel_rollup(rxr, rxr->hn_txr); + hn_chan_rollup(rxr, rxr->hn_txr); } static void Modified: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 05:53:58 2016 (r308505) +++ stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 06:23:01 2016 (r308506) @@ -29,12 +29,12 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_inet6.h" +#include "opt_inet.h" + #include -#include -#include #include -#include -#include +#include #include #include @@ -61,16 +61,6 @@ __FBSDID("$FreeBSD$"); #include #include -#define HV_RF_RECVINFO_VLAN 0x1 -#define HV_RF_RECVINFO_CSUM 0x2 -#define HV_RF_RECVINFO_HASHINF 0x4 -#define HV_RF_RECVINFO_HASHVAL 0x8 -#define HV_RF_RECVINFO_ALL \ - (HV_RF_RECVINFO_VLAN | \ - HV_RF_RECVINFO_CSUM | \ - HV_RF_RECVINFO_HASHINF | \ - HV_RF_RECVINFO_HASHVAL) - #define HN_RNDIS_RID_COMPAT_MASK 0xffff #define HN_RNDIS_RID_COMPAT_MAX HN_RNDIS_RID_COMPAT_MASK @@ -88,24 +78,23 @@ __FBSDID("$FreeBSD$"); #define HN_NDIS_LSOV2_CAP_IP6 \ (NDIS_LSOV2_CAP_IP6EXT | NDIS_LSOV2_CAP_TCP6OPT) -/* - * Forward declarations - */ -static void hv_rf_receive_indicate_status(struct hn_softc *sc, - const void *data, int dlen); -static void hv_rf_receive_data(struct hn_rx_ring *rxr, - const void *data, int dlen); - -static int hn_rndis_query(struct hn_softc *sc, uint32_t oid, - const void *idata, size_t idlen, void *odata, size_t *odlen0); -static int hn_rndis_query2(struct hn_softc *sc, uint32_t oid, - const void *idata, size_t idlen, void *odata, size_t *odlen0, - size_t min_odlen); -static int hn_rndis_set(struct hn_softc *sc, uint32_t oid, const void *data, - size_t dlen); -static int hn_rndis_conf_offload(struct hn_softc *sc, int mtu); -static int hn_rndis_query_hwcaps(struct hn_softc *sc, - struct ndis_offload *caps); +static const void *hn_rndis_xact_exec1(struct hn_softc *, + struct vmbus_xact *, size_t, + struct hn_nvs_sendctx *, size_t *); +static const void *hn_rndis_xact_execute(struct hn_softc *, + struct vmbus_xact *, uint32_t, size_t, size_t *, + uint32_t); +static int hn_rndis_query(struct hn_softc *, uint32_t, + const void *, size_t, void *, size_t *); +static int hn_rndis_query2(struct hn_softc *, uint32_t, + const void *, size_t, void *, size_t *, size_t); +static int hn_rndis_set(struct hn_softc *, uint32_t, + const void *, size_t); +static int hn_rndis_init(struct hn_softc *); +static int hn_rndis_halt(struct hn_softc *); +static int hn_rndis_conf_offload(struct hn_softc *, int); +static int hn_rndis_query_hwcaps(struct hn_softc *, + struct ndis_offload *); static __inline uint32_t hn_rndis_rid(struct hn_softc *sc) @@ -121,371 +110,22 @@ again: return ((rid & 0xffff) << 16); } -void * -hn_rndis_pktinfo_append(struct rndis_packet_msg *pkt, size_t pktsize, - size_t pi_dlen, uint32_t pi_type) -{ - const size_t pi_size = HN_RNDIS_PKTINFO_SIZE(pi_dlen); - struct rndis_pktinfo *pi; - - KASSERT((pi_size & RNDIS_PACKET_MSG_OFFSET_ALIGNMASK) == 0, - ("unaligned pktinfo size %zu, pktinfo dlen %zu", pi_size, pi_dlen)); - - /* - * Per-packet-info does not move; it only grows. - * - * NOTE: - * rm_pktinfooffset in this phase counts from the beginning - * of rndis_packet_msg. - */ - KASSERT(pkt->rm_pktinfooffset + pkt->rm_pktinfolen + pi_size <= pktsize, - ("%u pktinfo overflows RNDIS packet msg", pi_type)); - pi = (struct rndis_pktinfo *)((uint8_t *)pkt + pkt->rm_pktinfooffset + - pkt->rm_pktinfolen); - pkt->rm_pktinfolen += pi_size; - - pi->rm_size = pi_size; - pi->rm_type = pi_type; - pi->rm_pktinfooffset = RNDIS_PKTINFO_OFFSET; - - /* Data immediately follow per-packet-info. */ - pkt->rm_dataoffset += pi_size; - - /* Update RNDIS packet msg length */ - pkt->rm_len += pi_size; - - return (pi->rm_data); -} - -/* - * RNDIS filter receive indicate status - */ -static void -hv_rf_receive_indicate_status(struct hn_softc *sc, const void *data, int dlen) -{ - const struct rndis_status_msg *msg; - int ofs; - - if (dlen < sizeof(*msg)) { - if_printf(sc->hn_ifp, "invalid RNDIS status\n"); - return; - } - msg = data; - - switch (msg->rm_status) { - case RNDIS_STATUS_MEDIA_CONNECT: - case RNDIS_STATUS_MEDIA_DISCONNECT: - hn_link_status_update(sc); - break; - - case RNDIS_STATUS_TASK_OFFLOAD_CURRENT_CONFIG: - /* Not really useful; ignore. */ - break; - - case RNDIS_STATUS_NETWORK_CHANGE: - ofs = RNDIS_STBUFOFFSET_ABS(msg->rm_stbufoffset); - if (dlen < ofs + msg->rm_stbuflen || - msg->rm_stbuflen < sizeof(uint32_t)) { - if_printf(sc->hn_ifp, "network changed\n"); - } else { - uint32_t change; - - memcpy(&change, ((const uint8_t *)msg) + ofs, - sizeof(change)); - if_printf(sc->hn_ifp, "network changed, change %u\n", - change); - } - hn_network_change(sc); - break; - - default: - /* TODO: */ - if_printf(sc->hn_ifp, "unknown RNDIS status 0x%08x\n", - msg->rm_status); - break; - } -} - -static int -hn_rndis_rxinfo(const void *info_data, int info_dlen, struct hn_recvinfo *info) -{ - const struct rndis_pktinfo *pi = info_data; - uint32_t mask = 0; - - while (info_dlen != 0) { - const void *data; - uint32_t dlen; - - if (__predict_false(info_dlen < sizeof(*pi))) - return (EINVAL); - if (__predict_false(info_dlen < pi->rm_size)) - return (EINVAL); - info_dlen -= pi->rm_size; - - if (__predict_false(pi->rm_size & RNDIS_PKTINFO_SIZE_ALIGNMASK)) - return (EINVAL); - if (__predict_false(pi->rm_size < pi->rm_pktinfooffset)) - return (EINVAL); - dlen = pi->rm_size - pi->rm_pktinfooffset; - data = pi->rm_data; - - switch (pi->rm_type) { - case NDIS_PKTINFO_TYPE_VLAN: - if (__predict_false(dlen < NDIS_VLAN_INFO_SIZE)) - return (EINVAL); - info->vlan_info = *((const uint32_t *)data); - mask |= HV_RF_RECVINFO_VLAN; - break; - - case NDIS_PKTINFO_TYPE_CSUM: - if (__predict_false(dlen < NDIS_RXCSUM_INFO_SIZE)) - return (EINVAL); - info->csum_info = *((const uint32_t *)data); - mask |= HV_RF_RECVINFO_CSUM; - break; - - case HN_NDIS_PKTINFO_TYPE_HASHVAL: - if (__predict_false(dlen < HN_NDIS_HASH_VALUE_SIZE)) - return (EINVAL); - info->hash_value = *((const uint32_t *)data); - mask |= HV_RF_RECVINFO_HASHVAL; - break; - - case HN_NDIS_PKTINFO_TYPE_HASHINF: - if (__predict_false(dlen < HN_NDIS_HASH_INFO_SIZE)) - return (EINVAL); - info->hash_info = *((const uint32_t *)data); - mask |= HV_RF_RECVINFO_HASHINF; - break; - - default: - goto next; - } - - if (mask == HV_RF_RECVINFO_ALL) { - /* All found; done */ - break; - } -next: - pi = (const struct rndis_pktinfo *) - ((const uint8_t *)pi + pi->rm_size); - } - - /* - * Final fixup. - * - If there is no hash value, invalidate the hash info. - */ - if ((mask & HV_RF_RECVINFO_HASHVAL) == 0) - info->hash_info = HN_NDIS_HASH_INFO_INVALID; - return (0); -} - -static __inline bool -hn_rndis_check_overlap(int off, int len, int check_off, int check_len) -{ - - if (off < check_off) { - if (__predict_true(off + len <= check_off)) - return (false); - } else if (off > check_off) { - if (__predict_true(check_off + check_len <= off)) - return (false); - } - return (true); -} - -/* - * RNDIS filter receive data - */ -static void -hv_rf_receive_data(struct hn_rx_ring *rxr, const void *data, int dlen) -{ - const struct rndis_packet_msg *pkt; - struct hn_recvinfo info; - int data_off, pktinfo_off, data_len, pktinfo_len; - - /* - * Check length. - */ - if (__predict_false(dlen < sizeof(*pkt))) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg\n"); - return; - } - pkt = data; - - if (__predict_false(dlen < pkt->rm_len)) { - if_printf(rxr->hn_ifp, "truncated RNDIS packet msg, " - "dlen %d, msglen %u\n", dlen, pkt->rm_len); - return; - } - if (__predict_false(pkt->rm_len < - pkt->rm_datalen + pkt->rm_oobdatalen + pkt->rm_pktinfolen)) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msglen, " - "msglen %u, data %u, oob %u, pktinfo %u\n", - pkt->rm_len, pkt->rm_datalen, pkt->rm_oobdatalen, - pkt->rm_pktinfolen); - return; - } - if (__predict_false(pkt->rm_datalen == 0)) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, no data\n"); - return; - } - - /* - * Check offests. - */ -#define IS_OFFSET_INVALID(ofs) \ - ((ofs) < RNDIS_PACKET_MSG_OFFSET_MIN || \ - ((ofs) & RNDIS_PACKET_MSG_OFFSET_ALIGNMASK)) - - /* XXX Hyper-V does not meet data offset alignment requirement */ - if (__predict_false(pkt->rm_dataoffset < RNDIS_PACKET_MSG_OFFSET_MIN)) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " - "data offset %u\n", pkt->rm_dataoffset); - return; - } - if (__predict_false(pkt->rm_oobdataoffset > 0 && - IS_OFFSET_INVALID(pkt->rm_oobdataoffset))) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " - "oob offset %u\n", pkt->rm_oobdataoffset); - return; - } - if (__predict_true(pkt->rm_pktinfooffset > 0) && - __predict_false(IS_OFFSET_INVALID(pkt->rm_pktinfooffset))) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " - "pktinfo offset %u\n", pkt->rm_pktinfooffset); - return; - } - -#undef IS_OFFSET_INVALID - - data_off = RNDIS_PACKET_MSG_OFFSET_ABS(pkt->rm_dataoffset); - data_len = pkt->rm_datalen; - pktinfo_off = RNDIS_PACKET_MSG_OFFSET_ABS(pkt->rm_pktinfooffset); - pktinfo_len = pkt->rm_pktinfolen; - - /* - * Check OOB coverage. - */ - if (__predict_false(pkt->rm_oobdatalen != 0)) { - int oob_off, oob_len; - - if_printf(rxr->hn_ifp, "got oobdata\n"); - oob_off = RNDIS_PACKET_MSG_OFFSET_ABS(pkt->rm_oobdataoffset); - oob_len = pkt->rm_oobdatalen; - - if (__predict_false(oob_off + oob_len > pkt->rm_len)) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " - "oob overflow, msglen %u, oob abs %d len %d\n", - pkt->rm_len, oob_off, oob_len); - return; - } - - /* - * Check against data. - */ - if (hn_rndis_check_overlap(oob_off, oob_len, - data_off, data_len)) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " - "oob overlaps data, oob abs %d len %d, " - "data abs %d len %d\n", - oob_off, oob_len, data_off, data_len); - return; - } - - /* - * Check against pktinfo. - */ - if (pktinfo_len != 0 && - hn_rndis_check_overlap(oob_off, oob_len, - pktinfo_off, pktinfo_len)) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " - "oob overlaps pktinfo, oob abs %d len %d, " - "pktinfo abs %d len %d\n", - oob_off, oob_len, pktinfo_off, pktinfo_len); - return; - } - } - - /* - * Check per-packet-info coverage and find useful per-packet-info. - */ - info.vlan_info = HN_NDIS_VLAN_INFO_INVALID; - info.csum_info = HN_NDIS_RXCSUM_INFO_INVALID; - info.hash_info = HN_NDIS_HASH_INFO_INVALID; - if (__predict_true(pktinfo_len != 0)) { - bool overlap; - int error; - - if (__predict_false(pktinfo_off + pktinfo_len > pkt->rm_len)) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " - "pktinfo overflow, msglen %u, " - "pktinfo abs %d len %d\n", - pkt->rm_len, pktinfo_off, pktinfo_len); - return; - } - - /* - * Check packet info coverage. - */ - overlap = hn_rndis_check_overlap(pktinfo_off, pktinfo_len, - data_off, data_len); - if (__predict_false(overlap)) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " - "pktinfo overlap data, pktinfo abs %d len %d, " - "data abs %d len %d\n", - pktinfo_off, pktinfo_len, data_off, data_len); - return; - } - - /* - * Find useful per-packet-info. - */ - error = hn_rndis_rxinfo(((const uint8_t *)pkt) + pktinfo_off, - pktinfo_len, &info); - if (__predict_false(error)) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg " - "pktinfo\n"); - return; - } - } - - if (__predict_false(data_off + data_len > pkt->rm_len)) { - if_printf(rxr->hn_ifp, "invalid RNDIS packet msg, " - "data overflow, msglen %u, data abs %d len %d\n", - pkt->rm_len, data_off, data_len); - return; - } - hn_rxpkt(rxr, ((const uint8_t *)pkt) + data_off, data_len, &info); -} - -/* - * RNDIS filter on receive - */ void -hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr, - const void *data, int dlen) +hn_rndis_rx_ctrl(struct hn_softc *sc, const void *data, int dlen) { const struct rndis_comp_hdr *comp; const struct rndis_msghdr *hdr; - if (__predict_false(dlen < sizeof(*hdr))) { - if_printf(rxr->hn_ifp, "invalid RNDIS msg\n"); - return; - } + KASSERT(dlen >= sizeof(*hdr), ("invalid RNDIS msg\n")); hdr = data; switch (hdr->rm_type) { - case REMOTE_NDIS_PACKET_MSG: - hv_rf_receive_data(rxr, data, dlen); - break; - case REMOTE_NDIS_INITIALIZE_CMPLT: case REMOTE_NDIS_QUERY_CMPLT: case REMOTE_NDIS_SET_CMPLT: case REMOTE_NDIS_KEEPALIVE_CMPLT: /* unused */ if (dlen < sizeof(*comp)) { - if_printf(rxr->hn_ifp, "invalid RNDIS cmplt\n"); + if_printf(sc->hn_ifp, "invalid RNDIS cmplt\n"); return; } comp = data; @@ -495,10 +135,6 @@ hv_rf_on_receive(struct hn_softc *sc, st vmbus_xact_ctx_wakeup(sc->hn_xact, comp, dlen); break; - case REMOTE_NDIS_INDICATE_STATUS_MSG: - hv_rf_receive_indicate_status(sc, data, dlen); - break; - case REMOTE_NDIS_RESET_CMPLT: /* * Reset completed, no rid. @@ -507,11 +143,11 @@ hv_rf_on_receive(struct hn_softc *sc, st * RESET is not issued by hn(4), so this message should * _not_ be observed. */ - if_printf(rxr->hn_ifp, "RESET cmplt received\n"); + if_printf(sc->hn_ifp, "RESET cmplt received\n"); break; default: - if_printf(rxr->hn_ifp, "unknown RNDIS msg 0x%x\n", + if_printf(sc->hn_ifp, "unknown RNDIS msg 0x%x\n", hdr->rm_type); break; } @@ -1354,10 +990,3 @@ hn_rndis_detach(struct hn_softc *sc) /* Halt the RNDIS. */ *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable-10@freebsd.org Fri Nov 11 06:26:35 2016 Return-Path: Delivered-To: svn-src-stable-10@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 A05BAC3B92C; Fri, 11 Nov 2016 06:26:35 +0000 (UTC) (envelope-from sephe@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 685C71FA7; Fri, 11 Nov 2016 06:26:35 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB6QYqo062587; Fri, 11 Nov 2016 06:26:34 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB6QYRb062585; Fri, 11 Nov 2016 06:26:34 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110626.uAB6QYRb062585@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 06:26:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308507 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 06:26:35 -0000 Author: sephe Date: Fri Nov 11 06:26:34 2016 New Revision: 308507 URL: https://svnweb.freebsd.org/changeset/base/308507 Log: hyperv/hn: Fix i386 build; if_baudrate is 32bits on i386 on stable/10 This is a direct commit. Sponsored by: Microsoft Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 06:23:01 2016 (r308506) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 06:26:34 2016 (r308507) @@ -867,7 +867,12 @@ netvsc_attach(device_t dev) * Setup the ifnet for this interface. */ +#ifdef __LP64__ ifp->if_baudrate = IF_Gbps(10); +#else + /* if_baudrate is 32bits on 32bit system. */ + ifp->if_baudrate = IF_Gbps(1); +#endif ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = hn_ioctl; ifp->if_init = hn_init; From owner-svn-src-stable-10@freebsd.org Fri Nov 11 06:42:47 2016 Return-Path: Delivered-To: svn-src-stable-10@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 C21B6C3BD6A; Fri, 11 Nov 2016 06:42:47 +0000 (UTC) (envelope-from sephe@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 9B735186A; Fri, 11 Nov 2016 06:42:47 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB6gkxr070532; Fri, 11 Nov 2016 06:42:46 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB6gkZX070526; Fri, 11 Nov 2016 06:42:46 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110642.uAB6gkZX070526@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 06:42:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308508 - in stable/10/sys: conf dev/hyperv/netvsc modules/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 06:42:47 -0000 Author: sephe Date: Fri Nov 11 06:42:46 2016 New Revision: 308508 URL: https://svnweb.freebsd.org/changeset/base/308508 Log: MFC 308018,308116 308018 hyeprv/hn: Rename cleaned up RNDIS header file. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8360 308116 hyperv/hn: Rename cleaned up RNDIS source file. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8361 Added: stable/10/sys/dev/hyperv/netvsc/hn_rndis.c - copied, changed from r308507, stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c stable/10/sys/dev/hyperv/netvsc/hn_rndis.h - copied unchanged from r308507, stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h Deleted: stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h Modified: stable/10/sys/conf/files.amd64 stable/10/sys/conf/files.i386 stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/modules/hyperv/netvsc/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/conf/files.amd64 ============================================================================== --- stable/10/sys/conf/files.amd64 Fri Nov 11 06:26:34 2016 (r308507) +++ stable/10/sys/conf/files.amd64 Fri Nov 11 06:42:46 2016 (r308508) @@ -262,8 +262,8 @@ dev/hwpmc/hwpmc_piv.c optional hwpmc dev/hwpmc/hwpmc_tsc.c optional hwpmc dev/hwpmc/hwpmc_x86.c optional hwpmc dev/hyperv/netvsc/hn_nvs.c optional hyperv +dev/hyperv/netvsc/hn_rndis.c optional hyperv dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c optional hyperv -dev/hyperv/netvsc/hv_rndis_filter.c optional hyperv dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c optional hyperv dev/hyperv/utilities/hv_heartbeat.c optional hyperv dev/hyperv/utilities/hv_kvp.c optional hyperv Modified: stable/10/sys/conf/files.i386 ============================================================================== --- stable/10/sys/conf/files.i386 Fri Nov 11 06:26:34 2016 (r308507) +++ stable/10/sys/conf/files.i386 Fri Nov 11 06:42:46 2016 (r308508) @@ -239,8 +239,8 @@ dev/hwpmc/hwpmc_ppro.c optional hwpmc dev/hwpmc/hwpmc_tsc.c optional hwpmc dev/hwpmc/hwpmc_x86.c optional hwpmc dev/hyperv/netvsc/hn_nvs.c optional hyperv +dev/hyperv/netvsc/hn_rndis.c optional hyperv dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c optional hyperv -dev/hyperv/netvsc/hv_rndis_filter.c optional hyperv dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c optional hyperv dev/hyperv/utilities/hv_heartbeat.c optional hyperv dev/hyperv/utilities/hv_kvp.c optional hyperv Copied and modified: stable/10/sys/dev/hyperv/netvsc/hn_rndis.c (from r308507, stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c) ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.c Fri Nov 11 06:26:34 2016 (r308507, copy source) +++ stable/10/sys/dev/hyperv/netvsc/hn_rndis.c Fri Nov 11 06:42:46 2016 (r308508) @@ -59,7 +59,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #define HN_RNDIS_RID_COMPAT_MASK 0xffff #define HN_RNDIS_RID_COMPAT_MAX HN_RNDIS_RID_COMPAT_MASK Copied: stable/10/sys/dev/hyperv/netvsc/hn_rndis.h (from r308507, stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/netvsc/hn_rndis.h Fri Nov 11 06:42:46 2016 (r308508, copy of r308507, stable/10/sys/dev/hyperv/netvsc/hv_rndis_filter.h) @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 2009-2012,2016 Microsoft Corp. + * Copyright (c) 2010-2012 Citrix Inc. + * Copyright (c) 2012 NetApp Inc. + * 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 unmodified, 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. + * + * $FreeBSD$ + */ + +#ifndef _HN_RNDIS_H_ +#define _HN_RNDIS_H_ + +struct hn_softc; + +int hn_rndis_attach(struct hn_softc *sc, int mtu); +void hn_rndis_detach(struct hn_softc *sc); +int hn_rndis_conf_rss(struct hn_softc *sc, uint16_t flags); +int hn_rndis_query_rsscaps(struct hn_softc *sc, int *rxr_cnt); +int hn_rndis_get_eaddr(struct hn_softc *sc, uint8_t *eaddr); +/* link_status: NDIS_MEDIA_STATE_ */ +int hn_rndis_get_linkstatus(struct hn_softc *sc, + uint32_t *link_status); +/* filter: NDIS_PACKET_TYPE_. */ +int hn_rndis_set_rxfilter(struct hn_softc *sc, uint32_t filter); +void hn_rndis_rx_ctrl(struct hn_softc *sc, const void *data, + int dlen); + +#endif /* !_HN_RNDIS_H_ */ Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 06:26:34 2016 (r308507) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 06:42:46 2016 (r308508) @@ -127,7 +127,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include "vmbus_if.h" Modified: stable/10/sys/modules/hyperv/netvsc/Makefile ============================================================================== --- stable/10/sys/modules/hyperv/netvsc/Makefile Fri Nov 11 06:26:34 2016 (r308507) +++ stable/10/sys/modules/hyperv/netvsc/Makefile Fri Nov 11 06:42:46 2016 (r308508) @@ -4,9 +4,7 @@ ${.CURDIR}/../../../dev/hyperv/vmbus KMOD= hv_netvsc -SRCS= hn_nvs.c \ - hv_netvsc_drv_freebsd.c \ - hv_rndis_filter.c +SRCS= hn_nvs.c hn_rndis.c hv_netvsc_drv_freebsd.c SRCS+= bus_if.h device_if.h opt_inet.h opt_inet6.h vmbus_if.h CFLAGS+= -I${.CURDIR}/../../../dev/hyperv/netvsc From owner-svn-src-stable-10@freebsd.org Fri Nov 11 07:01:52 2016 Return-Path: Delivered-To: svn-src-stable-10@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 34CFDC3A3CA; Fri, 11 Nov 2016 07:01:52 +0000 (UTC) (envelope-from sephe@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 ECF2112F0; Fri, 11 Nov 2016 07:01:51 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB71p0l074901; Fri, 11 Nov 2016 07:01:51 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB71pYk074899; Fri, 11 Nov 2016 07:01:51 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110701.uAB71pYk074899@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 07:01:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308509 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 07:01:52 -0000 Author: sephe Date: Fri Nov 11 07:01:50 2016 New Revision: 308509 URL: https://svnweb.freebsd.org/changeset/base/308509 Log: MFC 308117-308120 308117 hyperv/hn: Rework temporary channel packet buffer expanding. And use large default temporary channel packer buffer; we really don't want it to be expanded at run time. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8367 308118 hyperv/hn: Cleanup RXBUF ack processing. - Increase the # of retries. - Add comment. - Log error, if RXBUF ack fails. - Add stat for RXBUF ack failures. RXBUF ack really should _not_ fail... Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8368 308119 hyperv/hn: Reset do_lro, if the hash types are not TCP related. Mainly because the host side only set TCPCS and IPCS even for UDP datagrams. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8369 308120 hyperv/hn: Don't start shared TX taskq, if the hypervisor is not Hyper-V. - Move the SYSINIT to DRIVER/SECOND, i.e. after the vm_guest becomes determistic. - Minor style changes. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8370 Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 06:42:46 2016 (r308508) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 07:01:50 2016 (r308509) @@ -178,6 +178,8 @@ __FBSDID("$FreeBSD$"); HN_RXINFO_HASHINF | \ HN_RXINFO_HASHVAL) +#define HN_PKTBUF_LEN_DEF (16 * 1024) + struct hn_txdesc { #ifndef HN_USE_TXDESC_BUFRING SLIST_ENTRY(hn_txdesc) link; @@ -414,7 +416,8 @@ static void hn_nvs_handle_comp(struct hn static void hn_nvs_handle_rxbuf(struct hn_rx_ring *rxr, struct vmbus_channel *chan, const struct vmbus_chanpkt_hdr *pkthdr); -static void hn_nvs_ack_rxbuf(struct vmbus_channel *chan, uint64_t tid); +static void hn_nvs_ack_rxbuf(struct hn_rx_ring *, struct vmbus_channel *, + uint64_t); static int hn_transmit(struct ifnet *, struct mbuf *); static void hn_xmit_qflush(struct ifnet *); @@ -1778,6 +1781,13 @@ hn_rxpkt(struct hn_rx_ring *rxr, const v rxr->hn_csum_udp++; } + /* + * XXX + * As of this write (Oct 28th, 2016), host side will turn + * on only TCPCS_OK and IPCS_OK even for UDP datagrams, so + * the do_lro setting here is actually _not_ accurate. We + * depend on the RSS hash type check to reset do_lro. + */ if ((info->csum_info & (NDIS_RXCSUM_INFO_TCPCS_OK | NDIS_RXCSUM_INFO_IPCS_OK)) == (NDIS_RXCSUM_INFO_TCPCS_OK | NDIS_RXCSUM_INFO_IPCS_OK)) @@ -1851,9 +1861,16 @@ skip: NDIS_HASH_FUNCTION_TOEPLITZ) { uint32_t type = (info->hash_info & NDIS_HASH_TYPE_MASK); + /* + * NOTE: + * do_lro is resetted, if the hash types are not TCP + * related. See the comment in the above csum_flags + * setup section. + */ switch (type) { case NDIS_HASH_IPV4: hash_type = M_HASHTYPE_RSS_IPV4; + do_lro = 0; break; case NDIS_HASH_TCP_IPV4: @@ -1862,10 +1879,12 @@ skip: case NDIS_HASH_IPV6: hash_type = M_HASHTYPE_RSS_IPV6; + do_lro = 0; break; case NDIS_HASH_IPV6_EX: hash_type = M_HASHTYPE_RSS_IPV6_EX; + do_lro = 0; break; case NDIS_HASH_TCP_IPV6: @@ -2745,7 +2764,8 @@ hn_create_rx_data(struct hn_softc *sc, i rxr->hn_ifp = sc->hn_ifp; if (i < sc->hn_tx_ring_cnt) rxr->hn_txr = &sc->hn_tx_ring[i]; - rxr->hn_pktbuf = malloc(HN_PKTBUF_LEN, M_DEVBUF, M_WAITOK); + rxr->hn_pktbuf_len = HN_PKTBUF_LEN_DEF; + rxr->hn_pktbuf = malloc(rxr->hn_pktbuf_len, M_DEVBUF, M_WAITOK); rxr->hn_rx_idx = i; rxr->hn_rxbuf = sc->hn_rxbuf; @@ -2788,6 +2808,11 @@ hn_create_rx_data(struct hn_softc *sc, i OID_AUTO, "rss_pkts", CTLFLAG_RW, &rxr->hn_rss_pkts, "# of packets w/ RSS info received"); + SYSCTL_ADD_INT(ctx, + SYSCTL_CHILDREN(rxr->hn_rx_sysctl_tree), + OID_AUTO, "pktbuf_len", CTLFLAG_RD, + &rxr->hn_pktbuf_len, 0, + "Temporary channel packet buffer length"); } } } @@ -2860,6 +2885,10 @@ hn_create_rx_data(struct hn_softc *sc, i CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, __offsetof(struct hn_rx_ring, hn_small_pkts), hn_rx_stat_ulong_sysctl, "LU", "# of small packets received"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rx_ack_failed", + CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, + __offsetof(struct hn_rx_ring, hn_ack_failed), + hn_rx_stat_ulong_sysctl, "LU", "# of RXBUF ack failures"); SYSCTL_ADD_INT(ctx, child, OID_AUTO, "rx_ring_cnt", CTLFLAG_RD, &sc->hn_rx_ring_cnt, 0, "# created RX rings"); SYSCTL_ADD_INT(ctx, child, OID_AUTO, "rx_ring_inuse", @@ -4516,43 +4545,43 @@ hn_nvs_handle_rxbuf(struct hn_rx_ring *r } /* - * Moved completion call back here so that all received - * messages (not just data messages) will trigger a response - * message back to the host. + * Ack the consumed RXBUF associated w/ this channel packet, + * so that this RXBUF can be recycled by the hypervisor. */ - hn_nvs_ack_rxbuf(chan, pkt->cp_hdr.cph_xactid); + hn_nvs_ack_rxbuf(rxr, chan, pkt->cp_hdr.cph_xactid); } -/* - * Net VSC on receive completion - * - * Send a receive completion packet to RNDIS device (ie NetVsp) - */ static void -hn_nvs_ack_rxbuf(struct vmbus_channel *chan, uint64_t tid) +hn_nvs_ack_rxbuf(struct hn_rx_ring *rxr, struct vmbus_channel *chan, + uint64_t tid) { struct hn_nvs_rndis_ack ack; - int retries = 0; - int ret = 0; + int retries, error; ack.nvs_type = HN_NVS_TYPE_RNDIS_ACK; ack.nvs_status = HN_NVS_STATUS_OK; -retry_send_cmplt: - /* Send the completion */ - ret = vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_COMP, + retries = 0; +again: + error = vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_COMP, VMBUS_CHANPKT_FLAG_NONE, &ack, sizeof(ack), tid); - if (ret == 0) { - /* success */ - /* no-op */ - } else if (ret == EAGAIN) { - /* no more room... wait a bit and attempt to retry 3 times */ + if (__predict_false(error == EAGAIN)) { + /* + * NOTE: + * This should _not_ happen in real world, since the + * consumption of the TX bufring from the TX path is + * controlled. + */ + if (rxr->hn_ack_failed == 0) + if_printf(rxr->hn_ifp, "RXBUF ack retry\n"); + rxr->hn_ack_failed++; retries++; - - if (retries < 4) { + if (retries < 10) { DELAY(100); - goto retry_send_cmplt; + goto again; } + /* RXBUF leaks! */ + if_printf(rxr->hn_ifp, "RXBUF ack failed\n"); } } @@ -4561,66 +4590,72 @@ hn_chan_callback(struct vmbus_channel *c { struct hn_rx_ring *rxr = xrxr; struct hn_softc *sc = rxr->hn_ifp->if_softc; - void *buffer; - int bufferlen = HN_PKTBUF_LEN; - buffer = rxr->hn_pktbuf; - do { - struct vmbus_chanpkt_hdr *pkt = buffer; - uint32_t bytes_rxed; - int ret; - - bytes_rxed = bufferlen; - ret = vmbus_chan_recv_pkt(chan, pkt, &bytes_rxed); - if (ret == 0) { - switch (pkt->cph_type) { - case VMBUS_CHANPKT_TYPE_COMP: - hn_nvs_handle_comp(sc, chan, pkt); - break; - case VMBUS_CHANPKT_TYPE_RXBUF: - hn_nvs_handle_rxbuf(rxr, chan, pkt); - break; - case VMBUS_CHANPKT_TYPE_INBAND: - hn_nvs_handle_notify(sc, pkt); - break; - default: - if_printf(rxr->hn_ifp, - "unknown chan pkt %u\n", - pkt->cph_type); - break; - } - } else if (ret == ENOBUFS) { - /* Handle large packet */ - if (bufferlen > HN_PKTBUF_LEN) { - free(buffer, M_DEVBUF); - buffer = NULL; - } + for (;;) { + struct vmbus_chanpkt_hdr *pkt = rxr->hn_pktbuf; + int error, pktlen; + + pktlen = rxr->hn_pktbuf_len; + error = vmbus_chan_recv_pkt(chan, pkt, &pktlen); + if (__predict_false(error == ENOBUFS)) { + void *nbuf; + int nlen; - /* alloc new buffer */ - buffer = malloc(bytes_rxed, M_DEVBUF, M_NOWAIT); - if (buffer == NULL) { - if_printf(rxr->hn_ifp, - "hv_cb malloc buffer failed, len=%u\n", - bytes_rxed); - bufferlen = 0; - break; - } - bufferlen = bytes_rxed; - } else { - /* No more packets */ + /* + * Expand channel packet buffer. + * + * XXX + * Use M_WAITOK here, since allocation failure + * is fatal. + */ + nlen = rxr->hn_pktbuf_len * 2; + while (nlen < pktlen) + nlen *= 2; + nbuf = malloc(nlen, M_DEVBUF, M_WAITOK); + + if_printf(rxr->hn_ifp, "expand pktbuf %d -> %d\n", + rxr->hn_pktbuf_len, nlen); + + free(rxr->hn_pktbuf, M_DEVBUF); + rxr->hn_pktbuf = nbuf; + rxr->hn_pktbuf_len = nlen; + /* Retry! */ + continue; + } else if (__predict_false(error == EAGAIN)) { + /* No more channel packets; done! */ break; } - } while (1); + KASSERT(!error, ("vmbus_chan_recv_pkt failed: %d", error)); - if (bufferlen > HN_PKTBUF_LEN) - free(buffer, M_DEVBUF); + switch (pkt->cph_type) { + case VMBUS_CHANPKT_TYPE_COMP: + hn_nvs_handle_comp(sc, chan, pkt); + break; + + case VMBUS_CHANPKT_TYPE_RXBUF: + hn_nvs_handle_rxbuf(rxr, chan, pkt); + break; + case VMBUS_CHANPKT_TYPE_INBAND: + hn_nvs_handle_notify(sc, pkt); + break; + + default: + if_printf(rxr->hn_ifp, "unknown chan pkt %u\n", + pkt->cph_type); + break; + } + } hn_chan_rollup(rxr, rxr->hn_txr); } static void hn_tx_taskq_create(void *arg __unused) { + + if (vm_guest != VM_GUEST_HV) + return; + if (!hn_share_tx_taskq) return; @@ -4640,16 +4675,17 @@ hn_tx_taskq_create(void *arg __unused) taskqueue_drain(hn_tx_taskq, &cpuset_task); } } -SYSINIT(hn_txtq_create, SI_SUB_DRIVERS, SI_ORDER_FIRST, +SYSINIT(hn_txtq_create, SI_SUB_DRIVERS, SI_ORDER_SECOND, hn_tx_taskq_create, NULL); static void hn_tx_taskq_destroy(void *arg __unused) { + if (hn_tx_taskq != NULL) taskqueue_free(hn_tx_taskq); } -SYSUNINIT(hn_txtq_destroy, SI_SUB_DRIVERS, SI_ORDER_FIRST, +SYSUNINIT(hn_txtq_destroy, SI_SUB_DRIVERS, SI_ORDER_SECOND, hn_tx_taskq_destroy, NULL); static device_method_t netvsc_methods[] = { Modified: stable/10/sys/dev/hyperv/netvsc/if_hnvar.h ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 06:42:46 2016 (r308508) +++ stable/10/sys/dev/hyperv/netvsc/if_hnvar.h Fri Nov 11 07:01:50 2016 (r308509) @@ -39,8 +39,6 @@ /* Claimed to be 12232B */ #define HN_MTU_MAX (9 * 1024) -#define HN_PKTBUF_LEN 4096 - #define HN_TXBR_SIZE (128 * PAGE_SIZE) #define HN_RXBR_SIZE (128 * PAGE_SIZE) @@ -63,6 +61,7 @@ struct hn_rx_ring { struct ifnet *hn_ifp; struct hn_tx_ring *hn_txr; void *hn_pktbuf; + int hn_pktbuf_len; uint8_t *hn_rxbuf; /* shadow sc->hn_rxbuf */ int hn_rx_idx; @@ -78,6 +77,7 @@ struct hn_rx_ring { u_long hn_small_pkts; u_long hn_pkts; u_long hn_rss_pkts; + u_long hn_ack_failed; /* Rarely used stuffs */ struct sysctl_oid *hn_rx_sysctl_tree; From owner-svn-src-stable-10@freebsd.org Fri Nov 11 07:13:19 2016 Return-Path: Delivered-To: svn-src-stable-10@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 00C95C3A7DC; Fri, 11 Nov 2016 07:13:19 +0000 (UTC) (envelope-from sephe@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 C0D3E1C0B; Fri, 11 Nov 2016 07:13:18 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB7DIF0082632; Fri, 11 Nov 2016 07:13:18 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB7DIfv082631; Fri, 11 Nov 2016 07:13:18 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110713.uAB7DIfv082631@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 07:13:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308510 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 07:13:19 -0000 Author: sephe Date: Fri Nov 11 07:13:17 2016 New Revision: 308510 URL: https://svnweb.freebsd.org/changeset/base/308510 Log: MFC 308162 hyperv/hn: Cosmetic cleanup; no functional changes. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8389 Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 07:01:50 2016 (r308509) +++ stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Fri Nov 11 07:13:17 2016 (r308510) @@ -59,64 +59,44 @@ __FBSDID("$FreeBSD$"); #include "opt_inet.h" #include -#include -#include +#include +#include #include -#include #include +#include #include -#include -#include #include #include #include -#include #include +#include +#include +#include #include -#include +#include #include +#include +#include +#include + +#include +#include #include #include -#include -#include #include -#include -#include - #include +#include #include -#include +#include #include #include #include -#include +#include #include #include #include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include #include #include @@ -131,24 +111,11 @@ __FBSDID("$FreeBSD$"); #include "vmbus_if.h" -/* Short for Hyper-V network interface */ -#define NETVSC_DEVNAME "hn" - -/* - * It looks like offset 0 of buf is reserved to hold the softc pointer. - * The sc pointer evidently not needed, and is not presently populated. - * The packet offset is where the netvsc_packet starts in the buffer. - */ -#define HV_NV_SC_PTR_OFFSET_IN_BUF 0 -#define HV_NV_PACKET_OFFSET_IN_BUF 16 +#define HN_RING_CNT_DEF_MAX 8 /* YYY should get it from the underlying channel */ #define HN_TX_DESC_CNT 512 -#define HN_LROENT_CNT_DEF 128 - -#define HN_RING_CNT_DEF_MAX 8 - #define HN_RNDIS_PKT_LEN \ (sizeof(struct rndis_packet_msg) + \ HN_RNDIS_PKTINFO_SIZE(HN_NDIS_HASH_VALUE_SIZE) + \ @@ -168,50 +135,9 @@ __FBSDID("$FreeBSD$"); #define HN_EARLY_TXEOF_THRESH 8 -#define HN_RXINFO_VLAN 0x0001 -#define HN_RXINFO_CSUM 0x0002 -#define HN_RXINFO_HASHINF 0x0004 -#define HN_RXINFO_HASHVAL 0x0008 -#define HN_RXINFO_ALL \ - (HN_RXINFO_VLAN | \ - HN_RXINFO_CSUM | \ - HN_RXINFO_HASHINF | \ - HN_RXINFO_HASHVAL) - #define HN_PKTBUF_LEN_DEF (16 * 1024) -struct hn_txdesc { -#ifndef HN_USE_TXDESC_BUFRING - SLIST_ENTRY(hn_txdesc) link; -#endif - struct mbuf *m; - struct hn_tx_ring *txr; - int refs; - uint32_t flags; /* HN_TXD_FLAG_ */ - struct hn_nvs_sendctx send_ctx; - uint32_t chim_index; - int chim_size; - - bus_dmamap_t data_dmap; - - bus_addr_t rndis_pkt_paddr; - struct rndis_packet_msg *rndis_pkt; - bus_dmamap_t rndis_pkt_dmap; -}; - -#define HN_TXD_FLAG_ONLIST 0x1 -#define HN_TXD_FLAG_DMAMAP 0x2 - -#define HN_NDIS_VLAN_INFO_INVALID 0xffffffff -#define HN_NDIS_RXCSUM_INFO_INVALID 0 -#define HN_NDIS_HASH_INFO_INVALID 0 - -struct hn_rxinfo { - uint32_t vlan_info; - uint32_t csum_info; - uint32_t hash_info; - uint32_t hash_value; -}; +#define HN_LROENT_CNT_DEF 128 #define HN_LRO_LENLIM_MULTIRX_DEF (12 * ETHERMTU) #define HN_LRO_LENLIM_DEF (25 * ETHERMTU) @@ -222,8 +148,8 @@ struct hn_rxinfo { #define HN_LOCK_INIT(sc) \ sx_init(&(sc)->hn_lock, device_get_nameunit((sc)->hn_dev)) -#define HN_LOCK_ASSERT(sc) sx_assert(&(sc)->hn_lock, SA_XLOCKED) #define HN_LOCK_DESTROY(sc) sx_destroy(&(sc)->hn_lock) +#define HN_LOCK_ASSERT(sc) sx_assert(&(sc)->hn_lock, SA_XLOCKED) #define HN_LOCK(sc) sx_xlock(&(sc)->hn_lock) #define HN_UNLOCK(sc) sx_xunlock(&(sc)->hn_lock) @@ -234,199 +160,276 @@ struct hn_rxinfo { #define HN_CSUM_IP6_HWASSIST(sc) \ ((sc)->hn_tx_ring[0].hn_csum_assist & HN_CSUM_IP6_MASK) -/* - * Globals - */ +struct hn_txdesc { +#ifndef HN_USE_TXDESC_BUFRING + SLIST_ENTRY(hn_txdesc) link; +#endif + struct mbuf *m; + struct hn_tx_ring *txr; + int refs; + uint32_t flags; /* HN_TXD_FLAG_ */ + struct hn_nvs_sendctx send_ctx; + uint32_t chim_index; + int chim_size; + + bus_dmamap_t data_dmap; + + bus_addr_t rndis_pkt_paddr; + struct rndis_packet_msg *rndis_pkt; + bus_dmamap_t rndis_pkt_dmap; +}; + +#define HN_TXD_FLAG_ONLIST 0x0001 +#define HN_TXD_FLAG_DMAMAP 0x0002 + +struct hn_rxinfo { + uint32_t vlan_info; + uint32_t csum_info; + uint32_t hash_info; + uint32_t hash_value; +}; + +#define HN_RXINFO_VLAN 0x0001 +#define HN_RXINFO_CSUM 0x0002 +#define HN_RXINFO_HASHINF 0x0004 +#define HN_RXINFO_HASHVAL 0x0008 +#define HN_RXINFO_ALL \ + (HN_RXINFO_VLAN | \ + HN_RXINFO_CSUM | \ + HN_RXINFO_HASHINF | \ + HN_RXINFO_HASHVAL) + +#define HN_NDIS_VLAN_INFO_INVALID 0xffffffff +#define HN_NDIS_RXCSUM_INFO_INVALID 0 +#define HN_NDIS_HASH_INFO_INVALID 0 + +static int hn_probe(device_t); +static int hn_attach(device_t); +static int hn_detach(device_t); +static int hn_shutdown(device_t); +static void hn_chan_callback(struct vmbus_channel *, + void *); + +static void hn_init(void *); +static int hn_ioctl(struct ifnet *, u_long, caddr_t); +static void hn_start(struct ifnet *); +static int hn_transmit(struct ifnet *, struct mbuf *); +static void hn_xmit_qflush(struct ifnet *); +static int hn_ifmedia_upd(struct ifnet *); +static void hn_ifmedia_sts(struct ifnet *, + struct ifmediareq *); + +static int hn_rndis_rxinfo(const void *, int, + struct hn_rxinfo *); +static void hn_rndis_rx_data(struct hn_rx_ring *, + const void *, int); +static void hn_rndis_rx_status(struct hn_softc *, + const void *, int); + +static void hn_nvs_handle_notify(struct hn_softc *, + const struct vmbus_chanpkt_hdr *); +static void hn_nvs_handle_comp(struct hn_softc *, + struct vmbus_channel *, + const struct vmbus_chanpkt_hdr *); +static void hn_nvs_handle_rxbuf(struct hn_rx_ring *, + struct vmbus_channel *, + const struct vmbus_chanpkt_hdr *); +static void hn_nvs_ack_rxbuf(struct hn_rx_ring *, + struct vmbus_channel *, uint64_t); + +#if __FreeBSD_version >= 1100099 +static int hn_lro_lenlim_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_lro_ackcnt_sysctl(SYSCTL_HANDLER_ARGS); +#endif +static int hn_trust_hcsum_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_chim_size_sysctl(SYSCTL_HANDLER_ARGS); +#if __FreeBSD_version < 1100095 +static int hn_rx_stat_int_sysctl(SYSCTL_HANDLER_ARGS); +#else +static int hn_rx_stat_u64_sysctl(SYSCTL_HANDLER_ARGS); +#endif +static int hn_rx_stat_ulong_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_tx_stat_ulong_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_tx_conf_int_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_ndis_version_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_caps_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_hwassist_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_rxfilter_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_rss_key_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_rss_ind_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_rss_hash_sysctl(SYSCTL_HANDLER_ARGS); + +static void hn_stop(struct hn_softc *); +static void hn_init_locked(struct hn_softc *); +static int hn_chan_attach(struct hn_softc *, + struct vmbus_channel *); +static void hn_chan_detach(struct hn_softc *, + struct vmbus_channel *); +static int hn_attach_subchans(struct hn_softc *); +static void hn_detach_allchans(struct hn_softc *); +static void hn_chan_rollup(struct hn_rx_ring *, + struct hn_tx_ring *); +static void hn_set_ring_inuse(struct hn_softc *, int); +static int hn_synth_attach(struct hn_softc *, int); +static void hn_synth_detach(struct hn_softc *); +static int hn_synth_alloc_subchans(struct hn_softc *, + int *); +static void hn_suspend(struct hn_softc *); +static void hn_suspend_data(struct hn_softc *); +static void hn_suspend_mgmt(struct hn_softc *); +static void hn_resume(struct hn_softc *); +static void hn_resume_data(struct hn_softc *); +static void hn_resume_mgmt(struct hn_softc *); +static void hn_suspend_mgmt_taskfunc(void *, int); +static void hn_chan_drain(struct vmbus_channel *); + +static void hn_update_link_status(struct hn_softc *); +static void hn_change_network(struct hn_softc *); +static void hn_link_taskfunc(void *, int); +static void hn_netchg_init_taskfunc(void *, int); +static void hn_netchg_status_taskfunc(void *, int); +static void hn_link_status(struct hn_softc *); + +static int hn_create_rx_data(struct hn_softc *, int); +static void hn_destroy_rx_data(struct hn_softc *); +static int hn_check_iplen(const struct mbuf *, int); +static int hn_set_rxfilter(struct hn_softc *); +static int hn_rss_reconfig(struct hn_softc *); +static void hn_rss_ind_fixup(struct hn_softc *, int); +static int hn_rxpkt(struct hn_rx_ring *, const void *, + int, const struct hn_rxinfo *); + +static int hn_tx_ring_create(struct hn_softc *, int); +static void hn_tx_ring_destroy(struct hn_tx_ring *); +static int hn_create_tx_data(struct hn_softc *, int); +static void hn_fixup_tx_data(struct hn_softc *); +static void hn_destroy_tx_data(struct hn_softc *); +static void hn_txdesc_dmamap_destroy(struct hn_txdesc *); +static int hn_encap(struct hn_tx_ring *, + struct hn_txdesc *, struct mbuf **); +static int hn_txpkt(struct ifnet *, struct hn_tx_ring *, + struct hn_txdesc *); +static void hn_set_chim_size(struct hn_softc *, int); +static void hn_set_tso_maxsize(struct hn_softc *, int, int); +static bool hn_tx_ring_pending(struct hn_tx_ring *); +static void hn_tx_ring_qflush(struct hn_tx_ring *); +static void hn_resume_tx(struct hn_softc *, int); +static int hn_get_txswq_depth(const struct hn_tx_ring *); +static void hn_txpkt_done(struct hn_nvs_sendctx *, + struct hn_softc *, struct vmbus_channel *, + const void *, int); +static int hn_txpkt_sglist(struct hn_tx_ring *, + struct hn_txdesc *); +static int hn_txpkt_chim(struct hn_tx_ring *, + struct hn_txdesc *); +static int hn_xmit(struct hn_tx_ring *, int); +static void hn_xmit_taskfunc(void *, int); +static void hn_xmit_txeof(struct hn_tx_ring *); +static void hn_xmit_txeof_taskfunc(void *, int); +static int hn_start_locked(struct hn_tx_ring *, int); +static void hn_start_taskfunc(void *, int); +static void hn_start_txeof(struct hn_tx_ring *); +static void hn_start_txeof_taskfunc(void *, int); SYSCTL_NODE(_hw, OID_AUTO, hn, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Hyper-V network interface"); /* Trust tcp segements verification on host side. */ -static int hn_trust_hosttcp = 1; +static int hn_trust_hosttcp = 1; SYSCTL_INT(_hw_hn, OID_AUTO, trust_hosttcp, CTLFLAG_RDTUN, &hn_trust_hosttcp, 0, "Trust tcp segement verification on host side, " "when csum info is missing (global setting)"); /* Trust udp datagrams verification on host side. */ -static int hn_trust_hostudp = 1; +static int hn_trust_hostudp = 1; SYSCTL_INT(_hw_hn, OID_AUTO, trust_hostudp, CTLFLAG_RDTUN, &hn_trust_hostudp, 0, "Trust udp datagram verification on host side, " "when csum info is missing (global setting)"); /* Trust ip packets verification on host side. */ -static int hn_trust_hostip = 1; +static int hn_trust_hostip = 1; SYSCTL_INT(_hw_hn, OID_AUTO, trust_hostip, CTLFLAG_RDTUN, &hn_trust_hostip, 0, "Trust ip packet verification on host side, " "when csum info is missing (global setting)"); /* Limit TSO burst size */ -static int hn_tso_maxlen = IP_MAXPACKET; +static int hn_tso_maxlen = IP_MAXPACKET; SYSCTL_INT(_hw_hn, OID_AUTO, tso_maxlen, CTLFLAG_RDTUN, &hn_tso_maxlen, 0, "TSO burst limit"); /* Limit chimney send size */ -static int hn_tx_chimney_size = 0; +static int hn_tx_chimney_size = 0; SYSCTL_INT(_hw_hn, OID_AUTO, tx_chimney_size, CTLFLAG_RDTUN, &hn_tx_chimney_size, 0, "Chimney send packet size limit"); /* Limit the size of packet for direct transmission */ -static int hn_direct_tx_size = HN_DIRECT_TX_SIZE_DEF; +static int hn_direct_tx_size = HN_DIRECT_TX_SIZE_DEF; SYSCTL_INT(_hw_hn, OID_AUTO, direct_tx_size, CTLFLAG_RDTUN, &hn_direct_tx_size, 0, "Size of the packet for direct transmission"); +/* # of LRO entries per RX ring */ #if defined(INET) || defined(INET6) #if __FreeBSD_version >= 1100095 -static int hn_lro_entry_count = HN_LROENT_CNT_DEF; +static int hn_lro_entry_count = HN_LROENT_CNT_DEF; SYSCTL_INT(_hw_hn, OID_AUTO, lro_entry_count, CTLFLAG_RDTUN, &hn_lro_entry_count, 0, "LRO entry count"); #endif #endif -static int hn_share_tx_taskq = 0; +/* Use shared TX taskqueue */ +static int hn_share_tx_taskq = 0; SYSCTL_INT(_hw_hn, OID_AUTO, share_tx_taskq, CTLFLAG_RDTUN, &hn_share_tx_taskq, 0, "Enable shared TX taskqueue"); -static struct taskqueue *hn_tx_taskq; - #ifndef HN_USE_TXDESC_BUFRING -static int hn_use_txdesc_bufring = 0; +static int hn_use_txdesc_bufring = 0; #else -static int hn_use_txdesc_bufring = 1; +static int hn_use_txdesc_bufring = 1; #endif SYSCTL_INT(_hw_hn, OID_AUTO, use_txdesc_bufring, CTLFLAG_RD, &hn_use_txdesc_bufring, 0, "Use buf_ring for TX descriptors"); -static int hn_bind_tx_taskq = -1; +/* Bind TX taskqueue to the target CPU */ +static int hn_bind_tx_taskq = -1; SYSCTL_INT(_hw_hn, OID_AUTO, bind_tx_taskq, CTLFLAG_RDTUN, &hn_bind_tx_taskq, 0, "Bind TX taskqueue to the specified cpu"); -static int hn_use_if_start = 0; +/* Use ifnet.if_start instead of ifnet.if_transmit */ +static int hn_use_if_start = 0; SYSCTL_INT(_hw_hn, OID_AUTO, use_if_start, CTLFLAG_RDTUN, &hn_use_if_start, 0, "Use if_start TX method"); -static int hn_chan_cnt = 0; +/* # of channels to use */ +static int hn_chan_cnt = 0; SYSCTL_INT(_hw_hn, OID_AUTO, chan_cnt, CTLFLAG_RDTUN, &hn_chan_cnt, 0, "# of channels to use; each channel has one RX ring and one TX ring"); -static int hn_tx_ring_cnt = 0; +/* # of transmit rings to use */ +static int hn_tx_ring_cnt = 0; SYSCTL_INT(_hw_hn, OID_AUTO, tx_ring_cnt, CTLFLAG_RDTUN, &hn_tx_ring_cnt, 0, "# of TX rings to use"); -static int hn_tx_swq_depth = 0; +/* Software TX ring deptch */ +static int hn_tx_swq_depth = 0; SYSCTL_INT(_hw_hn, OID_AUTO, tx_swq_depth, CTLFLAG_RDTUN, &hn_tx_swq_depth, 0, "Depth of IFQ or BUFRING"); +/* Enable sorted LRO, and the depth of the per-channel mbuf queue */ #if __FreeBSD_version >= 1100095 -static u_int hn_lro_mbufq_depth = 0; +static u_int hn_lro_mbufq_depth = 0; SYSCTL_UINT(_hw_hn, OID_AUTO, lro_mbufq_depth, CTLFLAG_RDTUN, &hn_lro_mbufq_depth, 0, "Depth of LRO mbuf queue"); #endif -static u_int hn_cpu_index; - -/* - * Forward declarations - */ -static void hn_stop(struct hn_softc *sc); -static void hn_init_locked(struct hn_softc *sc); -static void hn_init(void *xsc); -static int hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data); -static int hn_start_locked(struct hn_tx_ring *txr, int len); -static void hn_start(struct ifnet *ifp); -static void hn_start_txeof(struct hn_tx_ring *); -static int hn_ifmedia_upd(struct ifnet *ifp); -static void hn_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr); -#if __FreeBSD_version >= 1100099 -static int hn_lro_lenlim_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_lro_ackcnt_sysctl(SYSCTL_HANDLER_ARGS); -#endif -static int hn_trust_hcsum_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_chim_size_sysctl(SYSCTL_HANDLER_ARGS); -#if __FreeBSD_version < 1100095 -static int hn_rx_stat_int_sysctl(SYSCTL_HANDLER_ARGS); -#else -static int hn_rx_stat_u64_sysctl(SYSCTL_HANDLER_ARGS); -#endif -static int hn_rx_stat_ulong_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_tx_stat_ulong_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_tx_conf_int_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_ndis_version_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_caps_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_hwassist_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_rxfilter_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_rss_key_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_rss_ind_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_rss_hash_sysctl(SYSCTL_HANDLER_ARGS); -static int hn_check_iplen(const struct mbuf *, int); -static int hn_create_tx_ring(struct hn_softc *, int); -static void hn_destroy_tx_ring(struct hn_tx_ring *); -static int hn_create_tx_data(struct hn_softc *, int); -static void hn_fixup_tx_data(struct hn_softc *); -static void hn_destroy_tx_data(struct hn_softc *); -static void hn_start_taskfunc(void *, int); -static void hn_start_txeof_taskfunc(void *, int); -static void hn_link_taskfunc(void *, int); -static void hn_netchg_init_taskfunc(void *, int); -static void hn_netchg_status_taskfunc(void *, int); -static void hn_suspend_mgmt_taskfunc(void *, int); -static int hn_encap(struct hn_tx_ring *, struct hn_txdesc *, struct mbuf **); -static int hn_create_rx_data(struct hn_softc *sc, int); -static void hn_destroy_rx_data(struct hn_softc *sc); -static void hn_set_chim_size(struct hn_softc *, int); -static void hn_set_tso_maxsize(struct hn_softc *, int, int); -static int hn_chan_attach(struct hn_softc *, struct vmbus_channel *); -static void hn_chan_detach(struct hn_softc *, struct vmbus_channel *); -static int hn_attach_subchans(struct hn_softc *); -static void hn_detach_allchans(struct hn_softc *); -static void hn_chan_callback(struct vmbus_channel *chan, void *xrxr); -static void hn_chan_rollup(struct hn_rx_ring *, struct hn_tx_ring *); -static void hn_set_ring_inuse(struct hn_softc *, int); -static int hn_synth_attach(struct hn_softc *, int); -static void hn_synth_detach(struct hn_softc *); -static bool hn_tx_ring_pending(struct hn_tx_ring *); -static void hn_suspend(struct hn_softc *); -static void hn_suspend_data(struct hn_softc *); -static void hn_suspend_mgmt(struct hn_softc *); -static void hn_resume(struct hn_softc *); -static void hn_resume_data(struct hn_softc *); -static void hn_resume_mgmt(struct hn_softc *); -static void hn_rx_drain(struct vmbus_channel *); -static void hn_tx_resume(struct hn_softc *, int); -static void hn_tx_ring_qflush(struct hn_tx_ring *); -static int netvsc_detach(device_t dev); -static void hn_link_status(struct hn_softc *); -static int hn_sendpkt_rndis_sglist(struct hn_tx_ring *, struct hn_txdesc *); -static int hn_sendpkt_rndis_chim(struct hn_tx_ring *, struct hn_txdesc *); -static int hn_set_rxfilter(struct hn_softc *); -static void hn_link_status_update(struct hn_softc *); -static void hn_network_change(struct hn_softc *); - -static int hn_rndis_rxinfo(const void *, int, struct hn_rxinfo *); -static void hn_rndis_rx_data(struct hn_rx_ring *, const void *, int); -static void hn_rndis_rx_status(struct hn_softc *, const void *, int); - -static void hn_nvs_handle_notify(struct hn_softc *sc, - const struct vmbus_chanpkt_hdr *pkt); -static void hn_nvs_handle_comp(struct hn_softc *sc, struct vmbus_channel *chan, - const struct vmbus_chanpkt_hdr *pkt); -static void hn_nvs_handle_rxbuf(struct hn_rx_ring *rxr, - struct vmbus_channel *chan, - const struct vmbus_chanpkt_hdr *pkthdr); -static void hn_nvs_ack_rxbuf(struct hn_rx_ring *, struct vmbus_channel *, - uint64_t); - -static int hn_transmit(struct ifnet *, struct mbuf *); -static void hn_xmit_qflush(struct ifnet *); -static int hn_xmit(struct hn_tx_ring *, int); -static void hn_xmit_txeof(struct hn_tx_ring *); -static void hn_xmit_taskfunc(void *, int); -static void hn_xmit_txeof_taskfunc(void *, int); +static u_int hn_cpu_index; /* next CPU for channel */ +static struct taskqueue *hn_tx_taskq; /* shared TX taskqueue */ -static const uint8_t hn_rss_key_default[NDIS_HASH_KEYSIZE_TOEPLITZ] = { +static const uint8_t +hn_rss_key_default[NDIS_HASH_KEYSIZE_TOEPLITZ] = { 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, @@ -434,6 +437,27 @@ static const uint8_t hn_rss_key_default[ 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa }; +static device_method_t hn_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, hn_probe), + DEVMETHOD(device_attach, hn_attach), + DEVMETHOD(device_detach, hn_detach), + DEVMETHOD(device_shutdown, hn_shutdown), + DEVMETHOD_END +}; + +static driver_t hn_driver = { + "hn", + hn_methods, + sizeof(struct hn_softc) +}; + +static devclass_t hn_devclass; + +DRIVER_MODULE(hn, vmbus, hn_driver, hn_devclass, 0, 0); +MODULE_VERSION(hn, 1); +MODULE_DEPEND(hn, vmbus, 1, 1, 1); + #if __FreeBSD_version >= 1100099 static void hn_set_lro_lenlim(struct hn_softc *sc, int lenlim) @@ -446,7 +470,7 @@ hn_set_lro_lenlim(struct hn_softc *sc, i #endif static int -hn_sendpkt_rndis_sglist(struct hn_tx_ring *txr, struct hn_txdesc *txd) +hn_txpkt_sglist(struct hn_tx_ring *txr, struct hn_txdesc *txd) { KASSERT(txd->chim_index == HN_NVS_CHIM_IDX_INVALID && @@ -456,7 +480,7 @@ hn_sendpkt_rndis_sglist(struct hn_tx_rin } static int -hn_sendpkt_rndis_chim(struct hn_tx_ring *txr, struct hn_txdesc *txd) +hn_txpkt_chim(struct hn_tx_ring *txr, struct hn_txdesc *txd) { struct hn_nvs_rndis rndis; @@ -655,13 +679,10 @@ static const struct hyperv_guid g_net_vs 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E} }; -/* - * Standard probe entry point. - * - */ static int -netvsc_probe(device_t dev) +hn_probe(device_t dev) { + if (VMBUS_PROBE_GUID(device_get_parent(dev), dev, &g_net_vsc_device_type) == 0) { device_set_desc(dev, "Hyper-V Network Interface"); @@ -683,14 +704,8 @@ hn_cpuset_setthread_task(void *xmask, in } } -/* - * Standard attach entry point. - * - * Called when the driver is loaded. It allocates needed resources, - * and initializes the "hardware" and software. - */ static int -netvsc_attach(device_t dev) +hn_attach(device_t dev) { struct hn_softc *sc = device_get_softc(dev); struct sysctl_oid_list *child; @@ -938,18 +953,18 @@ netvsc_attach(device_t dev) * Kick off link status check. */ sc->hn_mgmt_taskq = sc->hn_mgmt_taskq0; - hn_link_status_update(sc); + hn_update_link_status(sc); return (0); failed: if (sc->hn_flags & HN_FLAG_SYNTH_ATTACHED) hn_synth_detach(sc); - netvsc_detach(dev); + hn_detach(dev); return (error); } static int -netvsc_detach(device_t dev) +hn_detach(device_t dev) { struct hn_softc *sc = device_get_softc(dev); struct ifnet *ifp = sc->hn_ifp; @@ -988,12 +1003,10 @@ netvsc_detach(device_t dev) return (0); } -/* - * Standard shutdown entry point - */ static int -netvsc_shutdown(device_t dev) +hn_shutdown(device_t dev) { + return (0); } @@ -1058,7 +1071,7 @@ hn_netchg_status_taskfunc(void *xsc, int } static void -hn_link_status_update(struct hn_softc *sc) +hn_update_link_status(struct hn_softc *sc) { if (sc->hn_mgmt_taskq != NULL) @@ -1066,7 +1079,7 @@ hn_link_status_update(struct hn_softc *s } static void -hn_network_change(struct hn_softc *sc) +hn_change_network(struct hn_softc *sc) { if (sc->hn_mgmt_taskq != NULL) @@ -1218,7 +1231,7 @@ hn_txeof(struct hn_tx_ring *txr) } static void -hn_tx_done(struct hn_nvs_sendctx *sndc, struct hn_softc *sc, +hn_txpkt_done(struct hn_nvs_sendctx *sndc, struct hn_softc *sc, struct vmbus_channel *chan, const void *data __unused, int dlen __unused) { struct hn_txdesc *txd = sndc->hn_cbarg; @@ -1447,7 +1460,7 @@ hn_encap(struct hn_tx_ring *txr, struct txd->chim_size = pkt->rm_len; txr->hn_gpa_cnt = 0; txr->hn_tx_chimney++; - txr->hn_sendpkt = hn_sendpkt_rndis_chim; + txr->hn_sendpkt = hn_txpkt_chim; goto done; } } @@ -1494,12 +1507,12 @@ hn_encap(struct hn_tx_ring *txr, struct txd->chim_index = HN_NVS_CHIM_IDX_INVALID; txd->chim_size = 0; - txr->hn_sendpkt = hn_sendpkt_rndis_sglist; + txr->hn_sendpkt = hn_txpkt_sglist; done: txd->m = m_head; /* Set the completion routine */ - hn_nvs_sendctx_init(&txd->send_ctx, hn_tx_done, txd); + hn_nvs_sendctx_init(&txd->send_ctx, hn_txpkt_done, txd); return 0; } @@ -1510,7 +1523,7 @@ done: * associated w/ the txd will _not_ be freed. */ static int -hn_send_pkt(struct ifnet *ifp, struct hn_tx_ring *txr, struct hn_txdesc *txd) +hn_txpkt(struct ifnet *ifp, struct hn_tx_ring *txr, struct hn_txdesc *txd) { int error, send_failed = 0; @@ -1626,7 +1639,7 @@ hn_start_locked(struct hn_tx_ring *txr, continue; } - error = hn_send_pkt(ifp, txr, txd); + error = hn_txpkt(ifp, txr, txd); if (__predict_false(error)) { /* txd is freed, but m_head is not */ IFQ_DRV_PREPEND(&ifp->if_snd, m_head); @@ -2139,9 +2152,6 @@ hn_stop(struct hn_softc *sc) sc->hn_tx_ring[i].hn_oactive = 0; } -/* - * FreeBSD transmit entry point - */ static void hn_start(struct ifnet *ifp) { @@ -2220,7 +2230,7 @@ hn_init_locked(struct hn_softc *sc) sc->hn_tx_ring[i].hn_oactive = 0; /* Clear TX 'suspended' bit. */ - hn_tx_resume(sc, sc->hn_tx_ring_inuse); + hn_resume_tx(sc, sc->hn_tx_ring_inuse); /* Everything is ready; unleash! */ atomic_set_int(&ifp->if_drv_flags, IFF_DRV_RUNNING); @@ -2236,20 +2246,6 @@ hn_init(void *xsc) HN_UNLOCK(sc); } -#ifdef LATER -/* - * - */ -static void -hn_watchdog(struct ifnet *ifp) -{ - - if_printf(ifp, "watchdog timeout -- resetting\n"); - hn_init(ifp->if_softc); /* XXX */ - ifp->if_oerrors++; -} -#endif - #if __FreeBSD_version >= 1100099 static int @@ -2931,7 +2927,7 @@ hn_destroy_rx_data(struct hn_softc *sc) } static int -hn_create_tx_ring(struct hn_softc *sc, int id) +hn_tx_ring_create(struct hn_softc *sc, int id) { struct hn_tx_ring *txr = &sc->hn_tx_ring[id]; device_t dev = sc->hn_dev; @@ -3128,7 +3124,7 @@ hn_txdesc_dmamap_destroy(struct hn_txdes } static void -hn_destroy_tx_ring(struct hn_tx_ring *txr) +hn_tx_ring_destroy(struct hn_tx_ring *txr) { struct hn_txdesc *txd; @@ -3204,7 +3200,7 @@ hn_create_tx_data(struct hn_softc *sc, i for (i = 0; i < sc->hn_tx_ring_cnt; ++i) { int error; - error = hn_create_tx_ring(sc, i); + error = hn_tx_ring_create(sc, i); if (error) return error; } @@ -3350,7 +3346,7 @@ hn_destroy_tx_data(struct hn_softc *sc) return; for (i = 0; i < sc->hn_tx_ring_cnt; ++i) - hn_destroy_tx_ring(&sc->hn_tx_ring[i]); + hn_tx_ring_destroy(&sc->hn_tx_ring[i]); free(sc->hn_tx_ring, M_DEVBUF); sc->hn_tx_ring = NULL; @@ -3426,7 +3422,7 @@ hn_xmit(struct hn_tx_ring *txr, int len) continue; } - error = hn_send_pkt(ifp, txr, txd); + error = hn_txpkt(ifp, txr, txd); if (__predict_false(error)) { /* txd is freed, but m_head is not */ drbr_putback(ifp, txr->hn_mbuf_br, m_head); @@ -3949,7 +3945,7 @@ hn_set_ring_inuse(struct hn_softc *sc, i } static void -hn_rx_drain(struct vmbus_channel *chan) +hn_chan_drain(struct vmbus_channel *chan) { while (!vmbus_chan_rx_empty(chan) || !vmbus_chan_tx_empty(chan)) @@ -4004,9 +4000,9 @@ hn_suspend_data(struct hn_softc *sc) if (subch != NULL) { for (i = 0; i < nsubch; ++i) - hn_rx_drain(subch[i]); + hn_chan_drain(subch[i]); } - hn_rx_drain(sc->hn_prichan); + hn_chan_drain(sc->hn_prichan); if (subch != NULL) vmbus_subchan_rel(subch, nsubch); @@ -4051,7 +4047,7 @@ hn_suspend(struct hn_softc *sc) } static void -hn_tx_resume(struct hn_softc *sc, int tx_ring_cnt) +hn_resume_tx(struct hn_softc *sc, int tx_ring_cnt) { int i; @@ -4084,7 +4080,7 @@ hn_resume_data(struct hn_softc *sc) * since hn_tx_ring_inuse can be changed after * hn_suspend_data(). */ - hn_tx_resume(sc, sc->hn_tx_ring_cnt); + hn_resume_tx(sc, sc->hn_tx_ring_cnt); if (!hn_use_if_start) { /* @@ -4122,9 +4118,9 @@ hn_resume_mgmt(struct hn_softc *sc) * detection. */ if (sc->hn_link_flags & HN_LINK_FLAG_NETCHG) - hn_network_change(sc); + hn_change_network(sc); else - hn_link_status_update(sc); + hn_update_link_status(sc); } static void @@ -4151,7 +4147,7 @@ hn_rndis_rx_status(struct hn_softc *sc, switch (msg->rm_status) { case RNDIS_STATUS_MEDIA_CONNECT: case RNDIS_STATUS_MEDIA_DISCONNECT: - hn_link_status_update(sc); + hn_update_link_status(sc); break; case RNDIS_STATUS_TASK_OFFLOAD_CURRENT_CONFIG: @@ -4171,7 +4167,7 @@ hn_rndis_rx_status(struct hn_softc *sc, if_printf(sc->hn_ifp, "network changed, change %u\n", change); } - hn_network_change(sc); + hn_change_network(sc); break; default: @@ -4687,25 +4683,3 @@ hn_tx_taskq_destroy(void *arg __unused) } SYSUNINIT(hn_txtq_destroy, SI_SUB_DRIVERS, SI_ORDER_SECOND, hn_tx_taskq_destroy, NULL); - -static device_method_t netvsc_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, netvsc_probe), - DEVMETHOD(device_attach, netvsc_attach), - DEVMETHOD(device_detach, netvsc_detach), - DEVMETHOD(device_shutdown, netvsc_shutdown), - - { 0, 0 } -}; - -static driver_t netvsc_driver = { - NETVSC_DEVNAME, - netvsc_methods, - sizeof(struct hn_softc) -}; - -static devclass_t netvsc_devclass; - -DRIVER_MODULE(hn, vmbus, netvsc_driver, netvsc_devclass, 0, 0); -MODULE_VERSION(hn, 1); -MODULE_DEPEND(hn, vmbus, 1, 1, 1); From owner-svn-src-stable-10@freebsd.org Fri Nov 11 07:25:15 2016 Return-Path: Delivered-To: svn-src-stable-10@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 9BAE2C3AAFC; Fri, 11 Nov 2016 07:25:15 +0000 (UTC) (envelope-from sephe@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 3C8AA1238; Fri, 11 Nov 2016 07:25:15 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB7PEeb087138; Fri, 11 Nov 2016 07:25:14 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB7PEvt087134; Fri, 11 Nov 2016 07:25:14 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110725.uAB7PEvt087134@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 07:25:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308511 - in stable/10/sys: conf dev/hyperv/netvsc modules/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 07:25:15 -0000 Author: sephe Date: Fri Nov 11 07:25:14 2016 New Revision: 308511 URL: https://svnweb.freebsd.org/changeset/base/308511 Log: MFC 308163 hyperv/hn: Rename cleaned up file. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8390 Added: stable/10/sys/dev/hyperv/netvsc/if_hn.c - copied unchanged from r308510, stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Deleted: stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c Modified: stable/10/sys/conf/files.amd64 stable/10/sys/conf/files.i386 stable/10/sys/modules/hyperv/netvsc/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/conf/files.amd64 ============================================================================== --- stable/10/sys/conf/files.amd64 Fri Nov 11 07:13:17 2016 (r308510) +++ stable/10/sys/conf/files.amd64 Fri Nov 11 07:25:14 2016 (r308511) @@ -263,7 +263,7 @@ dev/hwpmc/hwpmc_tsc.c optional hwpmc dev/hwpmc/hwpmc_x86.c optional hwpmc dev/hyperv/netvsc/hn_nvs.c optional hyperv dev/hyperv/netvsc/hn_rndis.c optional hyperv -dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c optional hyperv +dev/hyperv/netvsc/if_hn.c optional hyperv dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c optional hyperv dev/hyperv/utilities/hv_heartbeat.c optional hyperv dev/hyperv/utilities/hv_kvp.c optional hyperv Modified: stable/10/sys/conf/files.i386 ============================================================================== --- stable/10/sys/conf/files.i386 Fri Nov 11 07:13:17 2016 (r308510) +++ stable/10/sys/conf/files.i386 Fri Nov 11 07:25:14 2016 (r308511) @@ -240,7 +240,7 @@ dev/hwpmc/hwpmc_tsc.c optional hwpmc dev/hwpmc/hwpmc_x86.c optional hwpmc dev/hyperv/netvsc/hn_nvs.c optional hyperv dev/hyperv/netvsc/hn_rndis.c optional hyperv -dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c optional hyperv +dev/hyperv/netvsc/if_hn.c optional hyperv dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c optional hyperv dev/hyperv/utilities/hv_heartbeat.c optional hyperv dev/hyperv/utilities/hv_kvp.c optional hyperv Copied: stable/10/sys/dev/hyperv/netvsc/if_hn.c (from r308510, stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/sys/dev/hyperv/netvsc/if_hn.c Fri Nov 11 07:25:14 2016 (r308511, copy of r308510, stable/10/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c) @@ -0,0 +1,4685 @@ +/*- + * Copyright (c) 2010-2012 Citrix Inc. + * Copyright (c) 2009-2012,2016 Microsoft Corp. + * Copyright (c) 2012 NetApp Inc. + * 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 unmodified, 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. + */ + +/*- + * Copyright (c) 2004-2006 Kip Macy + * 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 "opt_inet6.h" +#include "opt_inet.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "vmbus_if.h" + +#define HN_RING_CNT_DEF_MAX 8 + +/* YYY should get it from the underlying channel */ +#define HN_TX_DESC_CNT 512 + +#define HN_RNDIS_PKT_LEN \ + (sizeof(struct rndis_packet_msg) + \ + HN_RNDIS_PKTINFO_SIZE(HN_NDIS_HASH_VALUE_SIZE) + \ + HN_RNDIS_PKTINFO_SIZE(NDIS_VLAN_INFO_SIZE) + \ + HN_RNDIS_PKTINFO_SIZE(NDIS_LSO2_INFO_SIZE) + \ + HN_RNDIS_PKTINFO_SIZE(NDIS_TXCSUM_INFO_SIZE)) +#define HN_RNDIS_PKT_BOUNDARY PAGE_SIZE +#define HN_RNDIS_PKT_ALIGN CACHE_LINE_SIZE + +#define HN_TX_DATA_BOUNDARY PAGE_SIZE +#define HN_TX_DATA_MAXSIZE IP_MAXPACKET +#define HN_TX_DATA_SEGSIZE PAGE_SIZE +/* -1 for RNDIS packet message */ +#define HN_TX_DATA_SEGCNT_MAX (HN_GPACNT_MAX - 1) + +#define HN_DIRECT_TX_SIZE_DEF 128 + +#define HN_EARLY_TXEOF_THRESH 8 + +#define HN_PKTBUF_LEN_DEF (16 * 1024) + +#define HN_LROENT_CNT_DEF 128 + +#define HN_LRO_LENLIM_MULTIRX_DEF (12 * ETHERMTU) +#define HN_LRO_LENLIM_DEF (25 * ETHERMTU) +/* YYY 2*MTU is a bit rough, but should be good enough. */ +#define HN_LRO_LENLIM_MIN(ifp) (2 * (ifp)->if_mtu) + +#define HN_LRO_ACKCNT_DEF 1 + +#define HN_LOCK_INIT(sc) \ + sx_init(&(sc)->hn_lock, device_get_nameunit((sc)->hn_dev)) +#define HN_LOCK_DESTROY(sc) sx_destroy(&(sc)->hn_lock) +#define HN_LOCK_ASSERT(sc) sx_assert(&(sc)->hn_lock, SA_XLOCKED) +#define HN_LOCK(sc) sx_xlock(&(sc)->hn_lock) +#define HN_UNLOCK(sc) sx_xunlock(&(sc)->hn_lock) + +#define HN_CSUM_IP_MASK (CSUM_IP | CSUM_IP_TCP | CSUM_IP_UDP) +#define HN_CSUM_IP6_MASK (CSUM_IP6_TCP | CSUM_IP6_UDP) +#define HN_CSUM_IP_HWASSIST(sc) \ + ((sc)->hn_tx_ring[0].hn_csum_assist & HN_CSUM_IP_MASK) +#define HN_CSUM_IP6_HWASSIST(sc) \ + ((sc)->hn_tx_ring[0].hn_csum_assist & HN_CSUM_IP6_MASK) + +struct hn_txdesc { +#ifndef HN_USE_TXDESC_BUFRING + SLIST_ENTRY(hn_txdesc) link; +#endif + struct mbuf *m; + struct hn_tx_ring *txr; + int refs; + uint32_t flags; /* HN_TXD_FLAG_ */ + struct hn_nvs_sendctx send_ctx; + uint32_t chim_index; + int chim_size; + + bus_dmamap_t data_dmap; + + bus_addr_t rndis_pkt_paddr; + struct rndis_packet_msg *rndis_pkt; + bus_dmamap_t rndis_pkt_dmap; +}; + +#define HN_TXD_FLAG_ONLIST 0x0001 +#define HN_TXD_FLAG_DMAMAP 0x0002 + +struct hn_rxinfo { + uint32_t vlan_info; + uint32_t csum_info; + uint32_t hash_info; + uint32_t hash_value; +}; + +#define HN_RXINFO_VLAN 0x0001 +#define HN_RXINFO_CSUM 0x0002 +#define HN_RXINFO_HASHINF 0x0004 +#define HN_RXINFO_HASHVAL 0x0008 +#define HN_RXINFO_ALL \ + (HN_RXINFO_VLAN | \ + HN_RXINFO_CSUM | \ + HN_RXINFO_HASHINF | \ + HN_RXINFO_HASHVAL) + +#define HN_NDIS_VLAN_INFO_INVALID 0xffffffff +#define HN_NDIS_RXCSUM_INFO_INVALID 0 +#define HN_NDIS_HASH_INFO_INVALID 0 + +static int hn_probe(device_t); +static int hn_attach(device_t); +static int hn_detach(device_t); +static int hn_shutdown(device_t); +static void hn_chan_callback(struct vmbus_channel *, + void *); + +static void hn_init(void *); +static int hn_ioctl(struct ifnet *, u_long, caddr_t); +static void hn_start(struct ifnet *); +static int hn_transmit(struct ifnet *, struct mbuf *); +static void hn_xmit_qflush(struct ifnet *); +static int hn_ifmedia_upd(struct ifnet *); +static void hn_ifmedia_sts(struct ifnet *, + struct ifmediareq *); + +static int hn_rndis_rxinfo(const void *, int, + struct hn_rxinfo *); +static void hn_rndis_rx_data(struct hn_rx_ring *, + const void *, int); +static void hn_rndis_rx_status(struct hn_softc *, + const void *, int); + +static void hn_nvs_handle_notify(struct hn_softc *, + const struct vmbus_chanpkt_hdr *); +static void hn_nvs_handle_comp(struct hn_softc *, + struct vmbus_channel *, + const struct vmbus_chanpkt_hdr *); +static void hn_nvs_handle_rxbuf(struct hn_rx_ring *, + struct vmbus_channel *, + const struct vmbus_chanpkt_hdr *); +static void hn_nvs_ack_rxbuf(struct hn_rx_ring *, + struct vmbus_channel *, uint64_t); + +#if __FreeBSD_version >= 1100099 +static int hn_lro_lenlim_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_lro_ackcnt_sysctl(SYSCTL_HANDLER_ARGS); +#endif +static int hn_trust_hcsum_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_chim_size_sysctl(SYSCTL_HANDLER_ARGS); +#if __FreeBSD_version < 1100095 +static int hn_rx_stat_int_sysctl(SYSCTL_HANDLER_ARGS); +#else +static int hn_rx_stat_u64_sysctl(SYSCTL_HANDLER_ARGS); +#endif +static int hn_rx_stat_ulong_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_tx_stat_ulong_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_tx_conf_int_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_ndis_version_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_caps_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_hwassist_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_rxfilter_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_rss_key_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_rss_ind_sysctl(SYSCTL_HANDLER_ARGS); +static int hn_rss_hash_sysctl(SYSCTL_HANDLER_ARGS); + +static void hn_stop(struct hn_softc *); +static void hn_init_locked(struct hn_softc *); +static int hn_chan_attach(struct hn_softc *, + struct vmbus_channel *); +static void hn_chan_detach(struct hn_softc *, + struct vmbus_channel *); +static int hn_attach_subchans(struct hn_softc *); +static void hn_detach_allchans(struct hn_softc *); +static void hn_chan_rollup(struct hn_rx_ring *, + struct hn_tx_ring *); +static void hn_set_ring_inuse(struct hn_softc *, int); +static int hn_synth_attach(struct hn_softc *, int); +static void hn_synth_detach(struct hn_softc *); +static int hn_synth_alloc_subchans(struct hn_softc *, + int *); +static void hn_suspend(struct hn_softc *); +static void hn_suspend_data(struct hn_softc *); +static void hn_suspend_mgmt(struct hn_softc *); +static void hn_resume(struct hn_softc *); +static void hn_resume_data(struct hn_softc *); +static void hn_resume_mgmt(struct hn_softc *); +static void hn_suspend_mgmt_taskfunc(void *, int); +static void hn_chan_drain(struct vmbus_channel *); + +static void hn_update_link_status(struct hn_softc *); +static void hn_change_network(struct hn_softc *); +static void hn_link_taskfunc(void *, int); +static void hn_netchg_init_taskfunc(void *, int); +static void hn_netchg_status_taskfunc(void *, int); +static void hn_link_status(struct hn_softc *); + +static int hn_create_rx_data(struct hn_softc *, int); +static void hn_destroy_rx_data(struct hn_softc *); +static int hn_check_iplen(const struct mbuf *, int); +static int hn_set_rxfilter(struct hn_softc *); +static int hn_rss_reconfig(struct hn_softc *); +static void hn_rss_ind_fixup(struct hn_softc *, int); +static int hn_rxpkt(struct hn_rx_ring *, const void *, + int, const struct hn_rxinfo *); + +static int hn_tx_ring_create(struct hn_softc *, int); +static void hn_tx_ring_destroy(struct hn_tx_ring *); +static int hn_create_tx_data(struct hn_softc *, int); +static void hn_fixup_tx_data(struct hn_softc *); +static void hn_destroy_tx_data(struct hn_softc *); +static void hn_txdesc_dmamap_destroy(struct hn_txdesc *); +static int hn_encap(struct hn_tx_ring *, + struct hn_txdesc *, struct mbuf **); +static int hn_txpkt(struct ifnet *, struct hn_tx_ring *, + struct hn_txdesc *); +static void hn_set_chim_size(struct hn_softc *, int); +static void hn_set_tso_maxsize(struct hn_softc *, int, int); +static bool hn_tx_ring_pending(struct hn_tx_ring *); +static void hn_tx_ring_qflush(struct hn_tx_ring *); +static void hn_resume_tx(struct hn_softc *, int); +static int hn_get_txswq_depth(const struct hn_tx_ring *); +static void hn_txpkt_done(struct hn_nvs_sendctx *, + struct hn_softc *, struct vmbus_channel *, + const void *, int); +static int hn_txpkt_sglist(struct hn_tx_ring *, + struct hn_txdesc *); +static int hn_txpkt_chim(struct hn_tx_ring *, + struct hn_txdesc *); +static int hn_xmit(struct hn_tx_ring *, int); +static void hn_xmit_taskfunc(void *, int); +static void hn_xmit_txeof(struct hn_tx_ring *); +static void hn_xmit_txeof_taskfunc(void *, int); +static int hn_start_locked(struct hn_tx_ring *, int); +static void hn_start_taskfunc(void *, int); +static void hn_start_txeof(struct hn_tx_ring *); +static void hn_start_txeof_taskfunc(void *, int); + +SYSCTL_NODE(_hw, OID_AUTO, hn, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, + "Hyper-V network interface"); + +/* Trust tcp segements verification on host side. */ +static int hn_trust_hosttcp = 1; +SYSCTL_INT(_hw_hn, OID_AUTO, trust_hosttcp, CTLFLAG_RDTUN, + &hn_trust_hosttcp, 0, + "Trust tcp segement verification on host side, " + "when csum info is missing (global setting)"); + +/* Trust udp datagrams verification on host side. */ +static int hn_trust_hostudp = 1; +SYSCTL_INT(_hw_hn, OID_AUTO, trust_hostudp, CTLFLAG_RDTUN, + &hn_trust_hostudp, 0, + "Trust udp datagram verification on host side, " + "when csum info is missing (global setting)"); + +/* Trust ip packets verification on host side. */ +static int hn_trust_hostip = 1; +SYSCTL_INT(_hw_hn, OID_AUTO, trust_hostip, CTLFLAG_RDTUN, + &hn_trust_hostip, 0, + "Trust ip packet verification on host side, " + "when csum info is missing (global setting)"); + +/* Limit TSO burst size */ +static int hn_tso_maxlen = IP_MAXPACKET; +SYSCTL_INT(_hw_hn, OID_AUTO, tso_maxlen, CTLFLAG_RDTUN, + &hn_tso_maxlen, 0, "TSO burst limit"); + +/* Limit chimney send size */ +static int hn_tx_chimney_size = 0; +SYSCTL_INT(_hw_hn, OID_AUTO, tx_chimney_size, CTLFLAG_RDTUN, + &hn_tx_chimney_size, 0, "Chimney send packet size limit"); + +/* Limit the size of packet for direct transmission */ +static int hn_direct_tx_size = HN_DIRECT_TX_SIZE_DEF; +SYSCTL_INT(_hw_hn, OID_AUTO, direct_tx_size, CTLFLAG_RDTUN, + &hn_direct_tx_size, 0, "Size of the packet for direct transmission"); + +/* # of LRO entries per RX ring */ +#if defined(INET) || defined(INET6) +#if __FreeBSD_version >= 1100095 +static int hn_lro_entry_count = HN_LROENT_CNT_DEF; +SYSCTL_INT(_hw_hn, OID_AUTO, lro_entry_count, CTLFLAG_RDTUN, + &hn_lro_entry_count, 0, "LRO entry count"); +#endif +#endif + +/* Use shared TX taskqueue */ +static int hn_share_tx_taskq = 0; +SYSCTL_INT(_hw_hn, OID_AUTO, share_tx_taskq, CTLFLAG_RDTUN, + &hn_share_tx_taskq, 0, "Enable shared TX taskqueue"); + +#ifndef HN_USE_TXDESC_BUFRING +static int hn_use_txdesc_bufring = 0; +#else +static int hn_use_txdesc_bufring = 1; +#endif +SYSCTL_INT(_hw_hn, OID_AUTO, use_txdesc_bufring, CTLFLAG_RD, + &hn_use_txdesc_bufring, 0, "Use buf_ring for TX descriptors"); + +/* Bind TX taskqueue to the target CPU */ +static int hn_bind_tx_taskq = -1; +SYSCTL_INT(_hw_hn, OID_AUTO, bind_tx_taskq, CTLFLAG_RDTUN, + &hn_bind_tx_taskq, 0, "Bind TX taskqueue to the specified cpu"); + +/* Use ifnet.if_start instead of ifnet.if_transmit */ +static int hn_use_if_start = 0; +SYSCTL_INT(_hw_hn, OID_AUTO, use_if_start, CTLFLAG_RDTUN, + &hn_use_if_start, 0, "Use if_start TX method"); + +/* # of channels to use */ +static int hn_chan_cnt = 0; +SYSCTL_INT(_hw_hn, OID_AUTO, chan_cnt, CTLFLAG_RDTUN, + &hn_chan_cnt, 0, + "# of channels to use; each channel has one RX ring and one TX ring"); + +/* # of transmit rings to use */ +static int hn_tx_ring_cnt = 0; +SYSCTL_INT(_hw_hn, OID_AUTO, tx_ring_cnt, CTLFLAG_RDTUN, + &hn_tx_ring_cnt, 0, "# of TX rings to use"); + +/* Software TX ring deptch */ +static int hn_tx_swq_depth = 0; +SYSCTL_INT(_hw_hn, OID_AUTO, tx_swq_depth, CTLFLAG_RDTUN, + &hn_tx_swq_depth, 0, "Depth of IFQ or BUFRING"); + +/* Enable sorted LRO, and the depth of the per-channel mbuf queue */ +#if __FreeBSD_version >= 1100095 +static u_int hn_lro_mbufq_depth = 0; +SYSCTL_UINT(_hw_hn, OID_AUTO, lro_mbufq_depth, CTLFLAG_RDTUN, + &hn_lro_mbufq_depth, 0, "Depth of LRO mbuf queue"); +#endif + +static u_int hn_cpu_index; /* next CPU for channel */ +static struct taskqueue *hn_tx_taskq; /* shared TX taskqueue */ + +static const uint8_t +hn_rss_key_default[NDIS_HASH_KEYSIZE_TOEPLITZ] = { + 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, + 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, + 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, + 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, + 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa +}; + +static device_method_t hn_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, hn_probe), + DEVMETHOD(device_attach, hn_attach), + DEVMETHOD(device_detach, hn_detach), + DEVMETHOD(device_shutdown, hn_shutdown), + DEVMETHOD_END +}; + +static driver_t hn_driver = { + "hn", + hn_methods, + sizeof(struct hn_softc) +}; + +static devclass_t hn_devclass; + +DRIVER_MODULE(hn, vmbus, hn_driver, hn_devclass, 0, 0); +MODULE_VERSION(hn, 1); +MODULE_DEPEND(hn, vmbus, 1, 1, 1); + +#if __FreeBSD_version >= 1100099 +static void +hn_set_lro_lenlim(struct hn_softc *sc, int lenlim) +{ + int i; + + for (i = 0; i < sc->hn_rx_ring_inuse; ++i) + sc->hn_rx_ring[i].hn_lro.lro_length_lim = lenlim; +} +#endif + +static int +hn_txpkt_sglist(struct hn_tx_ring *txr, struct hn_txdesc *txd) +{ + + KASSERT(txd->chim_index == HN_NVS_CHIM_IDX_INVALID && + txd->chim_size == 0, ("invalid rndis sglist txd")); + return (hn_nvs_send_rndis_sglist(txr->hn_chan, HN_NVS_RNDIS_MTYPE_DATA, + &txd->send_ctx, txr->hn_gpa, txr->hn_gpa_cnt)); +} + +static int +hn_txpkt_chim(struct hn_tx_ring *txr, struct hn_txdesc *txd) +{ + struct hn_nvs_rndis rndis; + + KASSERT(txd->chim_index != HN_NVS_CHIM_IDX_INVALID && + txd->chim_size > 0, ("invalid rndis chim txd")); + + rndis.nvs_type = HN_NVS_TYPE_RNDIS; + rndis.nvs_rndis_mtype = HN_NVS_RNDIS_MTYPE_DATA; + rndis.nvs_chim_idx = txd->chim_index; + rndis.nvs_chim_sz = txd->chim_size; + + return (hn_nvs_send(txr->hn_chan, VMBUS_CHANPKT_FLAG_RC, + &rndis, sizeof(rndis), &txd->send_ctx)); +} + +static __inline uint32_t +hn_chim_alloc(struct hn_softc *sc) +{ + int i, bmap_cnt = sc->hn_chim_bmap_cnt; + u_long *bmap = sc->hn_chim_bmap; + uint32_t ret = HN_NVS_CHIM_IDX_INVALID; + + for (i = 0; i < bmap_cnt; ++i) { + int idx; + + idx = ffsl(~bmap[i]); + if (idx == 0) + continue; + + --idx; /* ffsl is 1-based */ + KASSERT(i * LONG_BIT + idx < sc->hn_chim_cnt, + ("invalid i %d and idx %d", i, idx)); + + if (atomic_testandset_long(&bmap[i], idx)) + continue; + + ret = i * LONG_BIT + idx; + break; + } + return (ret); +} + +static __inline void +hn_chim_free(struct hn_softc *sc, uint32_t chim_idx) +{ + u_long mask; + uint32_t idx; + + idx = chim_idx / LONG_BIT; + KASSERT(idx < sc->hn_chim_bmap_cnt, + ("invalid chimney index 0x%x", chim_idx)); + + mask = 1UL << (chim_idx % LONG_BIT); + KASSERT(sc->hn_chim_bmap[idx] & mask, + ("index bitmap 0x%lx, chimney index %u, " + "bitmap idx %d, bitmask 0x%lx", + sc->hn_chim_bmap[idx], chim_idx, idx, mask)); + + atomic_clear_long(&sc->hn_chim_bmap[idx], mask); +} + +static int +hn_set_rxfilter(struct hn_softc *sc) +{ + struct ifnet *ifp = sc->hn_ifp; + uint32_t filter; + int error = 0; + + HN_LOCK_ASSERT(sc); + + if (ifp->if_flags & IFF_PROMISC) { + filter = NDIS_PACKET_TYPE_PROMISCUOUS; + } else { + filter = NDIS_PACKET_TYPE_DIRECTED; + if (ifp->if_flags & IFF_BROADCAST) + filter |= NDIS_PACKET_TYPE_BROADCAST; +#ifdef notyet + /* + * See the comment in SIOCADDMULTI/SIOCDELMULTI. + */ + /* TODO: support multicast list */ + if ((ifp->if_flags & IFF_ALLMULTI) || + !TAILQ_EMPTY(&ifp->if_multiaddrs)) + filter |= NDIS_PACKET_TYPE_ALL_MULTICAST; +#else + /* Always enable ALLMULTI */ + filter |= NDIS_PACKET_TYPE_ALL_MULTICAST; +#endif + } + + if (sc->hn_rx_filter != filter) { + error = hn_rndis_set_rxfilter(sc, filter); + if (!error) + sc->hn_rx_filter = filter; + } + return (error); +} + +static int +hn_get_txswq_depth(const struct hn_tx_ring *txr) +{ + + KASSERT(txr->hn_txdesc_cnt > 0, ("tx ring is not setup yet")); + if (hn_tx_swq_depth < txr->hn_txdesc_cnt) + return txr->hn_txdesc_cnt; + return hn_tx_swq_depth; +} + +static int +hn_rss_reconfig(struct hn_softc *sc) +{ + int error; + + HN_LOCK_ASSERT(sc); + + if ((sc->hn_flags & HN_FLAG_SYNTH_ATTACHED) == 0) + return (ENXIO); + + /* + * Disable RSS first. + * + * NOTE: + * Direct reconfiguration by setting the UNCHG flags does + * _not_ work properly. + */ + if (bootverbose) + if_printf(sc->hn_ifp, "disable RSS\n"); + error = hn_rndis_conf_rss(sc, NDIS_RSS_FLAG_DISABLE); + if (error) { + if_printf(sc->hn_ifp, "RSS disable failed\n"); + return (error); + } + + /* + * Reenable the RSS w/ the updated RSS key or indirect + * table. + */ + if (bootverbose) + if_printf(sc->hn_ifp, "reconfig RSS\n"); + error = hn_rndis_conf_rss(sc, NDIS_RSS_FLAG_NONE); + if (error) { + if_printf(sc->hn_ifp, "RSS reconfig failed\n"); + return (error); + } + return (0); +} + +static void +hn_rss_ind_fixup(struct hn_softc *sc, int nchan) +{ + struct ndis_rssprm_toeplitz *rss = &sc->hn_rss; + int i; + + KASSERT(nchan > 1, ("invalid # of channels %d", nchan)); + + /* + * Check indirect table to make sure that all channels in it + * can be used. + */ + for (i = 0; i < NDIS_HASH_INDCNT; ++i) { + if (rss->rss_ind[i] >= nchan) { + if_printf(sc->hn_ifp, + "RSS indirect table %d fixup: %u -> %d\n", + i, rss->rss_ind[i], nchan - 1); + rss->rss_ind[i] = nchan - 1; + } + } +} + +static int +hn_ifmedia_upd(struct ifnet *ifp __unused) +{ + + return EOPNOTSUPP; +} + +static void +hn_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) +{ + struct hn_softc *sc = ifp->if_softc; + + ifmr->ifm_status = IFM_AVALID; + ifmr->ifm_active = IFM_ETHER; + + if ((sc->hn_link_flags & HN_LINK_FLAG_LINKUP) == 0) { + ifmr->ifm_active |= IFM_NONE; + return; + } + ifmr->ifm_status |= IFM_ACTIVE; + ifmr->ifm_active |= IFM_10G_T | IFM_FDX; +} + +/* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */ +static const struct hyperv_guid g_net_vsc_device_type = { + .hv_guid = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, + 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E} +}; + +static int +hn_probe(device_t dev) +{ + + if (VMBUS_PROBE_GUID(device_get_parent(dev), dev, + &g_net_vsc_device_type) == 0) { + device_set_desc(dev, "Hyper-V Network Interface"); + return BUS_PROBE_DEFAULT; + } + return ENXIO; +} + +static void +hn_cpuset_setthread_task(void *xmask, int pending __unused) +{ + cpuset_t *mask = xmask; + int error; + + error = cpuset_setthread(curthread->td_tid, mask); + if (error) { + panic("curthread=%ju: can't pin; error=%d", + (uintmax_t)curthread->td_tid, error); + } +} + +static int +hn_attach(device_t dev) +{ + struct hn_softc *sc = device_get_softc(dev); + struct sysctl_oid_list *child; + struct sysctl_ctx_list *ctx; + uint8_t eaddr[ETHER_ADDR_LEN]; + struct ifnet *ifp = NULL; + int error, ring_cnt, tx_ring_cnt; + + sc->hn_dev = dev; + sc->hn_prichan = vmbus_get_channel(dev); + HN_LOCK_INIT(sc); + + /* + * Setup taskqueue for transmission. + */ + if (hn_tx_taskq == NULL) { + sc->hn_tx_taskq = taskqueue_create("hn_tx", M_WAITOK, + taskqueue_thread_enqueue, &sc->hn_tx_taskq); + taskqueue_start_threads(&sc->hn_tx_taskq, 1, PI_NET, "%s tx", + device_get_nameunit(dev)); + if (hn_bind_tx_taskq >= 0) { + int cpu = hn_bind_tx_taskq; + struct task cpuset_task; + cpuset_t cpu_set; + + if (cpu > mp_ncpus - 1) + cpu = mp_ncpus - 1; + CPU_SETOF(cpu, &cpu_set); + TASK_INIT(&cpuset_task, 0, hn_cpuset_setthread_task, + &cpu_set); + taskqueue_enqueue(sc->hn_tx_taskq, &cpuset_task); + taskqueue_drain(sc->hn_tx_taskq, &cpuset_task); + } + } else { + sc->hn_tx_taskq = hn_tx_taskq; + } + + /* + * Setup taskqueue for mangement tasks, e.g. link status. + */ + sc->hn_mgmt_taskq0 = taskqueue_create("hn_mgmt", M_WAITOK, + taskqueue_thread_enqueue, &sc->hn_mgmt_taskq0); + taskqueue_start_threads(&sc->hn_mgmt_taskq0, 1, PI_NET, "%s mgmt", + device_get_nameunit(dev)); + TASK_INIT(&sc->hn_link_task, 0, hn_link_taskfunc, sc); + TASK_INIT(&sc->hn_netchg_init, 0, hn_netchg_init_taskfunc, sc); + TIMEOUT_TASK_INIT(sc->hn_mgmt_taskq0, &sc->hn_netchg_status, 0, + hn_netchg_status_taskfunc, sc); + + /* + * Allocate ifnet and setup its name earlier, so that if_printf + * can be used by functions, which will be called after + * ether_ifattach(). + */ + ifp = sc->hn_ifp = sc->arpcom.ac_ifp = if_alloc(IFT_ETHER); + ifp->if_softc = sc; + if_initname(ifp, device_get_name(dev), device_get_unit(dev)); + + /* + * Initialize ifmedia earlier so that it can be unconditionally + * destroyed, if error happened later on. + */ + ifmedia_init(&sc->hn_media, 0, hn_ifmedia_upd, hn_ifmedia_sts); + + /* + * Figure out the # of RX rings (ring_cnt) and the # of TX rings + * to use (tx_ring_cnt). + * + * NOTE: + * The # of RX rings to use is same as the # of channels to use. + */ + ring_cnt = hn_chan_cnt; + if (ring_cnt <= 0) { + /* Default */ + ring_cnt = mp_ncpus; + if (ring_cnt > HN_RING_CNT_DEF_MAX) + ring_cnt = HN_RING_CNT_DEF_MAX; + } else if (ring_cnt > mp_ncpus) { + ring_cnt = mp_ncpus; + } + + tx_ring_cnt = hn_tx_ring_cnt; + if (tx_ring_cnt <= 0 || tx_ring_cnt > ring_cnt) + tx_ring_cnt = ring_cnt; + if (hn_use_if_start) { + /* ifnet.if_start only needs one TX ring. */ + tx_ring_cnt = 1; + } + + /* + * Set the leader CPU for channels. + */ + sc->hn_cpu = atomic_fetchadd_int(&hn_cpu_index, ring_cnt) % mp_ncpus; + + /* + * Create enough TX/RX rings, even if only limited number of + * channels can be allocated. + */ + error = hn_create_tx_data(sc, tx_ring_cnt); + if (error) + goto failed; + error = hn_create_rx_data(sc, ring_cnt); + if (error) + goto failed; + + /* + * Create transaction context for NVS and RNDIS transactions. + */ + sc->hn_xact = vmbus_xact_ctx_create(bus_get_dma_tag(dev), + HN_XACT_REQ_SIZE, HN_XACT_RESP_SIZE, 0); + if (sc->hn_xact == NULL) + goto failed; + + /* + * Attach the synthetic parts, i.e. NVS and RNDIS. + */ + error = hn_synth_attach(sc, ETHERMTU); + if (error) + goto failed; + + error = hn_rndis_get_eaddr(sc, eaddr); + if (error) + goto failed; + +#if __FreeBSD_version >= 1100099 + if (sc->hn_rx_ring_inuse > 1) { + /* + * Reduce TCP segment aggregation limit for multiple + * RX rings to increase ACK timeliness. + */ + hn_set_lro_lenlim(sc, HN_LRO_LENLIM_MULTIRX_DEF); + } +#endif + + /* + * Fixup TX stuffs after synthetic parts are attached. + */ + hn_fixup_tx_data(sc); + + ctx = device_get_sysctl_ctx(dev); + child = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); + SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "nvs_version", CTLFLAG_RD, + &sc->hn_nvs_ver, 0, "NVS version"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "ndis_version", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, + hn_ndis_version_sysctl, "A", "NDIS version"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "caps", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, + hn_caps_sysctl, "A", "capabilities"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "hwassist", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, + hn_hwassist_sysctl, "A", "hwassist"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rxfilter", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, + hn_rxfilter_sysctl, "A", "rxfilter"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rss_hash", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, + hn_rss_hash_sysctl, "A", "RSS hash"); + SYSCTL_ADD_INT(ctx, child, OID_AUTO, "rss_ind_size", + CTLFLAG_RD, &sc->hn_rss_ind_size, 0, "RSS indirect entry count"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rss_key", + CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, + hn_rss_key_sysctl, "IU", "RSS key"); + SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rss_ind", + CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, + hn_rss_ind_sysctl, "IU", "RSS indirect table"); + + /* + * Setup the ifmedia, which has been initialized earlier. + */ + ifmedia_add(&sc->hn_media, IFM_ETHER | IFM_AUTO, 0, NULL); + ifmedia_set(&sc->hn_media, IFM_ETHER | IFM_AUTO); + /* XXX ifmedia_set really should do this for us */ + sc->hn_media.ifm_media = sc->hn_media.ifm_cur->ifm_media; + + /* + * Setup the ifnet for this interface. + */ + +#ifdef __LP64__ + ifp->if_baudrate = IF_Gbps(10); +#else + /* if_baudrate is 32bits on 32bit system. */ + ifp->if_baudrate = IF_Gbps(1); +#endif + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_ioctl = hn_ioctl; + ifp->if_init = hn_init; + if (hn_use_if_start) { + int qdepth = hn_get_txswq_depth(&sc->hn_tx_ring[0]); + + ifp->if_start = hn_start; + IFQ_SET_MAXLEN(&ifp->if_snd, qdepth); + ifp->if_snd.ifq_drv_maxlen = qdepth - 1; + IFQ_SET_READY(&ifp->if_snd); + } else { + ifp->if_transmit = hn_transmit; + ifp->if_qflush = hn_xmit_qflush; + } + + ifp->if_capabilities |= IFCAP_RXCSUM | IFCAP_LRO; +#ifdef foo + /* We can't diff IPv6 packets from IPv4 packets on RX path. */ + ifp->if_capabilities |= IFCAP_RXCSUM_IPV6; +#endif + if (sc->hn_caps & HN_CAP_VLAN) { + /* XXX not sure about VLAN_MTU. */ + ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU; + } + + ifp->if_hwassist = sc->hn_tx_ring[0].hn_csum_assist; + if (ifp->if_hwassist & HN_CSUM_IP_MASK) + ifp->if_capabilities |= IFCAP_TXCSUM; + if (ifp->if_hwassist & HN_CSUM_IP6_MASK) + ifp->if_capabilities |= IFCAP_TXCSUM_IPV6; + if (sc->hn_caps & HN_CAP_TSO4) { + ifp->if_capabilities |= IFCAP_TSO4; + ifp->if_hwassist |= CSUM_IP_TSO; + } + if (sc->hn_caps & HN_CAP_TSO6) { + ifp->if_capabilities |= IFCAP_TSO6; + ifp->if_hwassist |= CSUM_IP6_TSO; + } + + /* Enable all available capabilities by default. */ + ifp->if_capenable = ifp->if_capabilities; + + if (ifp->if_capabilities & (IFCAP_TSO6 | IFCAP_TSO4)) { + hn_set_tso_maxsize(sc, hn_tso_maxlen, ETHERMTU); + ifp->if_hw_tsomaxsegcount = HN_TX_DATA_SEGCNT_MAX; + ifp->if_hw_tsomaxsegsize = PAGE_SIZE; + } + + ether_ifattach(ifp, eaddr); + + if ((ifp->if_capabilities & (IFCAP_TSO6 | IFCAP_TSO4)) && bootverbose) { + if_printf(ifp, "TSO segcnt %u segsz %u\n", + ifp->if_hw_tsomaxsegcount, ifp->if_hw_tsomaxsegsize); + } + + /* Inform the upper layer about the long frame support. */ + ifp->if_hdrlen = sizeof(struct ether_vlan_header); + + /* + * Kick off link status check. + */ + sc->hn_mgmt_taskq = sc->hn_mgmt_taskq0; + hn_update_link_status(sc); + + return (0); +failed: + if (sc->hn_flags & HN_FLAG_SYNTH_ATTACHED) + hn_synth_detach(sc); + hn_detach(dev); + return (error); +} + +static int +hn_detach(device_t dev) +{ + struct hn_softc *sc = device_get_softc(dev); + struct ifnet *ifp = sc->hn_ifp; + + if (device_is_attached(dev)) { + HN_LOCK(sc); + if (sc->hn_flags & HN_FLAG_SYNTH_ATTACHED) { + if (ifp->if_drv_flags & IFF_DRV_RUNNING) *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable-10@freebsd.org Fri Nov 11 07:33:45 2016 Return-Path: Delivered-To: svn-src-stable-10@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 3F87BC3ADE2; Fri, 11 Nov 2016 07:33:45 +0000 (UTC) (envelope-from sephe@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 196861703; Fri, 11 Nov 2016 07:33:45 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB7XiSI090875; Fri, 11 Nov 2016 07:33:44 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB7XiD6090874; Fri, 11 Nov 2016 07:33:44 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110733.uAB7XiD6090874@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 07:33:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308512 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 07:33:45 -0000 Author: sephe Date: Fri Nov 11 07:33:44 2016 New Revision: 308512 URL: https://svnweb.freebsd.org/changeset/base/308512 Log: MFC 308164 hyperv/hn: Regroup if_start related functions. And put them under HN_IFSTART_SUPPORT, which is by default on until we whack the if_start related bits from base system. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8392 Modified: stable/10/sys/dev/hyperv/netvsc/if_hn.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/if_hn.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/if_hn.c Fri Nov 11 07:25:14 2016 (r308511) +++ stable/10/sys/dev/hyperv/netvsc/if_hn.c Fri Nov 11 07:33:44 2016 (r308512) @@ -111,6 +111,8 @@ __FBSDID("$FreeBSD$"); #include "vmbus_if.h" +#define HN_IFSTART_SUPPORT + #define HN_RING_CNT_DEF_MAX 8 /* YYY should get it from the underlying channel */ @@ -212,7 +214,9 @@ static void hn_chan_callback(struct vm static void hn_init(void *); static int hn_ioctl(struct ifnet *, u_long, caddr_t); +#ifdef HN_IFSTART_SUPPORT static void hn_start(struct ifnet *); +#endif static int hn_transmit(struct ifnet *, struct mbuf *); static void hn_xmit_qflush(struct ifnet *); static int hn_ifmedia_upd(struct ifnet *); @@ -326,10 +330,12 @@ static int hn_xmit(struct hn_tx_ring * static void hn_xmit_taskfunc(void *, int); static void hn_xmit_txeof(struct hn_tx_ring *); static void hn_xmit_txeof_taskfunc(void *, int); +#ifdef HN_IFSTART_SUPPORT static int hn_start_locked(struct hn_tx_ring *, int); static void hn_start_taskfunc(void *, int); static void hn_start_txeof(struct hn_tx_ring *); static void hn_start_txeof_taskfunc(void *, int); +#endif SYSCTL_NODE(_hw, OID_AUTO, hn, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Hyper-V network interface"); @@ -397,10 +403,12 @@ static int hn_bind_tx_taskq = -1; SYSCTL_INT(_hw_hn, OID_AUTO, bind_tx_taskq, CTLFLAG_RDTUN, &hn_bind_tx_taskq, 0, "Bind TX taskqueue to the specified cpu"); +#ifdef HN_IFSTART_SUPPORT /* Use ifnet.if_start instead of ifnet.if_transmit */ static int hn_use_if_start = 0; SYSCTL_INT(_hw_hn, OID_AUTO, use_if_start, CTLFLAG_RDTUN, &hn_use_if_start, 0, "Use if_start TX method"); +#endif /* # of channels to use */ static int hn_chan_cnt = 0; @@ -790,10 +798,12 @@ hn_attach(device_t dev) tx_ring_cnt = hn_tx_ring_cnt; if (tx_ring_cnt <= 0 || tx_ring_cnt > ring_cnt) tx_ring_cnt = ring_cnt; +#ifdef HN_IFSTART_SUPPORT if (hn_use_if_start) { /* ifnet.if_start only needs one TX ring. */ tx_ring_cnt = 1; } +#endif /* * Set the leader CPU for channels. @@ -894,6 +904,7 @@ hn_attach(device_t dev) ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = hn_ioctl; ifp->if_init = hn_init; +#ifdef HN_IFSTART_SUPPORT if (hn_use_if_start) { int qdepth = hn_get_txswq_depth(&sc->hn_tx_ring[0]); @@ -901,7 +912,9 @@ hn_attach(device_t dev) IFQ_SET_MAXLEN(&ifp->if_snd, qdepth); ifp->if_snd.ifq_drv_maxlen = qdepth - 1; IFQ_SET_READY(&ifp->if_snd); - } else { + } else +#endif + { ifp->if_transmit = hn_transmit; ifp->if_qflush = hn_xmit_qflush; } @@ -1536,7 +1549,10 @@ again: if (!error) { ETHER_BPF_MTAP(ifp, txd->m); if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); - if (!hn_use_if_start) { +#ifdef HN_IFSTART_SUPPORT + if (!hn_use_if_start) +#endif + { if_inc_counter(ifp, IFCOUNTER_OBYTES, txd->m->m_pkthdr.len); if (txd->m->m_flags & M_MCAST) @@ -1586,71 +1602,6 @@ again: } /* - * Start a transmit of one or more packets - */ -static int -hn_start_locked(struct hn_tx_ring *txr, int len) -{ - struct hn_softc *sc = txr->hn_sc; - struct ifnet *ifp = sc->hn_ifp; - - KASSERT(hn_use_if_start, - ("hn_start_locked is called, when if_start is disabled")); - KASSERT(txr == &sc->hn_tx_ring[0], ("not the first TX ring")); - mtx_assert(&txr->hn_tx_lock, MA_OWNED); - - if (__predict_false(txr->hn_suspended)) - return 0; - - if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != - IFF_DRV_RUNNING) - return 0; - - while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) { - struct hn_txdesc *txd; - struct mbuf *m_head; - int error; - - IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head); - if (m_head == NULL) - break; - - if (len > 0 && m_head->m_pkthdr.len > len) { - /* - * This sending could be time consuming; let callers - * dispatch this packet sending (and sending of any - * following up packets) to tx taskqueue. - */ - IFQ_DRV_PREPEND(&ifp->if_snd, m_head); - return 1; - } - - txd = hn_txdesc_get(txr); - if (txd == NULL) { - txr->hn_no_txdescs++; - IFQ_DRV_PREPEND(&ifp->if_snd, m_head); - atomic_set_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); - break; - } - - error = hn_encap(txr, txd, &m_head); - if (error) { - /* Both txd and m_head are freed */ - continue; - } - - error = hn_txpkt(ifp, txr, txd); - if (__predict_false(error)) { - /* txd is freed, but m_head is not */ - IFQ_DRV_PREPEND(&ifp->if_snd, m_head); - atomic_set_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); - break; - } - } - return 0; -} - -/* * Append the specified data to the indicated mbuf chain, * Extend the mbuf chain if the new data does not fit in * existing space. @@ -2153,61 +2104,6 @@ hn_stop(struct hn_softc *sc) } static void -hn_start(struct ifnet *ifp) -{ - struct hn_softc *sc = ifp->if_softc; - struct hn_tx_ring *txr = &sc->hn_tx_ring[0]; - - if (txr->hn_sched_tx) - goto do_sched; - - if (mtx_trylock(&txr->hn_tx_lock)) { - int sched; - - sched = hn_start_locked(txr, txr->hn_direct_tx_size); - mtx_unlock(&txr->hn_tx_lock); - if (!sched) - return; - } -do_sched: - taskqueue_enqueue(txr->hn_tx_taskq, &txr->hn_tx_task); -} - -static void -hn_start_txeof(struct hn_tx_ring *txr) -{ - struct hn_softc *sc = txr->hn_sc; - struct ifnet *ifp = sc->hn_ifp; - - KASSERT(txr == &sc->hn_tx_ring[0], ("not the first TX ring")); - - if (txr->hn_sched_tx) - goto do_sched; - - if (mtx_trylock(&txr->hn_tx_lock)) { - int sched; - - atomic_clear_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); - sched = hn_start_locked(txr, txr->hn_direct_tx_size); - mtx_unlock(&txr->hn_tx_lock); - if (sched) { - taskqueue_enqueue(txr->hn_tx_taskq, - &txr->hn_tx_task); - } - } else { -do_sched: - /* - * Release the OACTIVE earlier, with the hope, that - * others could catch up. The task will clear the - * flag again with the hn_tx_lock to avoid possible - * races. - */ - atomic_clear_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); - taskqueue_enqueue(txr->hn_tx_taskq, &txr->hn_txeof_task); - } -} - -static void hn_init_locked(struct hn_softc *sc) { struct ifnet *ifp = sc->hn_ifp; @@ -2954,11 +2850,14 @@ hn_tx_ring_create(struct hn_softc *sc, i txr->hn_tx_taskq = sc->hn_tx_taskq; +#ifdef HN_IFSTART_SUPPORT if (hn_use_if_start) { txr->hn_txeof = hn_start_txeof; TASK_INIT(&txr->hn_tx_task, 0, hn_start_taskfunc, txr); TASK_INIT(&txr->hn_txeof_task, 0, hn_start_txeof_taskfunc, txr); - } else { + } else +#endif + { int br_depth; txr->hn_txeof = hn_xmit_txeof; @@ -3095,7 +2994,10 @@ hn_tx_ring_create(struct hn_softc *sc, i SYSCTL_ADD_INT(ctx, child, OID_AUTO, "txdesc_avail", CTLFLAG_RD, &txr->hn_txdesc_avail, 0, "# of available TX descs"); - if (!hn_use_if_start) { +#ifdef HN_IFSTART_SUPPORT + if (!hn_use_if_start) +#endif + { SYSCTL_ADD_INT(ctx, child, OID_AUTO, "oactive", CTLFLAG_RD, &txr->hn_oactive, 0, "over active"); @@ -3355,6 +3257,8 @@ hn_destroy_tx_data(struct hn_softc *sc) sc->hn_tx_ring_inuse = 0; } +#ifdef HN_IFSTART_SUPPORT + static void hn_start_taskfunc(void *xtxr, int pending __unused) { @@ -3365,6 +3269,89 @@ hn_start_taskfunc(void *xtxr, int pendin mtx_unlock(&txr->hn_tx_lock); } +static int +hn_start_locked(struct hn_tx_ring *txr, int len) +{ + struct hn_softc *sc = txr->hn_sc; + struct ifnet *ifp = sc->hn_ifp; + + KASSERT(hn_use_if_start, + ("hn_start_locked is called, when if_start is disabled")); + KASSERT(txr == &sc->hn_tx_ring[0], ("not the first TX ring")); + mtx_assert(&txr->hn_tx_lock, MA_OWNED); + + if (__predict_false(txr->hn_suspended)) + return 0; + + if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != + IFF_DRV_RUNNING) + return 0; + + while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) { + struct hn_txdesc *txd; + struct mbuf *m_head; + int error; + + IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head); + if (m_head == NULL) + break; + + if (len > 0 && m_head->m_pkthdr.len > len) { + /* + * This sending could be time consuming; let callers + * dispatch this packet sending (and sending of any + * following up packets) to tx taskqueue. + */ + IFQ_DRV_PREPEND(&ifp->if_snd, m_head); + return 1; + } + + txd = hn_txdesc_get(txr); + if (txd == NULL) { + txr->hn_no_txdescs++; + IFQ_DRV_PREPEND(&ifp->if_snd, m_head); + atomic_set_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); + break; + } + + error = hn_encap(txr, txd, &m_head); + if (error) { + /* Both txd and m_head are freed */ + continue; + } + + error = hn_txpkt(ifp, txr, txd); + if (__predict_false(error)) { + /* txd is freed, but m_head is not */ + IFQ_DRV_PREPEND(&ifp->if_snd, m_head); + atomic_set_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); + break; + } + } + return 0; +} + +static void +hn_start(struct ifnet *ifp) +{ + struct hn_softc *sc = ifp->if_softc; + struct hn_tx_ring *txr = &sc->hn_tx_ring[0]; + + if (txr->hn_sched_tx) + goto do_sched; + + if (mtx_trylock(&txr->hn_tx_lock)) { + int sched; + + sched = hn_start_locked(txr, txr->hn_direct_tx_size); + mtx_unlock(&txr->hn_tx_lock); + if (!sched) + return; + } +do_sched: + taskqueue_enqueue(txr->hn_tx_taskq, &txr->hn_tx_task); +} + static void hn_start_txeof_taskfunc(void *xtxr, int pending __unused) { @@ -3376,6 +3363,42 @@ hn_start_txeof_taskfunc(void *xtxr, int mtx_unlock(&txr->hn_tx_lock); } +static void +hn_start_txeof(struct hn_tx_ring *txr) +{ + struct hn_softc *sc = txr->hn_sc; + struct ifnet *ifp = sc->hn_ifp; + + KASSERT(txr == &sc->hn_tx_ring[0], ("not the first TX ring")); + + if (txr->hn_sched_tx) + goto do_sched; + + if (mtx_trylock(&txr->hn_tx_lock)) { + int sched; + + atomic_clear_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); + sched = hn_start_locked(txr, txr->hn_direct_tx_size); + mtx_unlock(&txr->hn_tx_lock); + if (sched) { + taskqueue_enqueue(txr->hn_tx_taskq, + &txr->hn_tx_task); + } + } else { +do_sched: + /* + * Release the OACTIVE earlier, with the hope, that + * others could catch up. The task will clear the + * flag again with the hn_tx_lock to avoid possible + * races. + */ + atomic_clear_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); + taskqueue_enqueue(txr->hn_tx_taskq, &txr->hn_txeof_task); + } +} + +#endif /* HN_IFSTART_SUPPORT */ + static int hn_xmit(struct hn_tx_ring *txr, int len) { @@ -3384,8 +3407,10 @@ hn_xmit(struct hn_tx_ring *txr, int len) struct mbuf *m_head; mtx_assert(&txr->hn_tx_lock, MA_OWNED); +#ifdef HN_IFSTART_SUPPORT KASSERT(hn_use_if_start == 0, ("hn_xmit is called, when if_start is enabled")); +#endif if (__predict_false(txr->hn_suspended)) return 0; @@ -4082,7 +4107,10 @@ hn_resume_data(struct hn_softc *sc) */ hn_resume_tx(sc, sc->hn_tx_ring_cnt); - if (!hn_use_if_start) { +#ifdef HN_IFSTART_SUPPORT + if (!hn_use_if_start) +#endif + { /* * Flush unused drbrs, since hn_tx_ring_inuse may be * reduced. From owner-svn-src-stable-10@freebsd.org Fri Nov 11 07:41:39 2016 Return-Path: Delivered-To: svn-src-stable-10@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 AC800C3AFD2; Fri, 11 Nov 2016 07:41:39 +0000 (UTC) (envelope-from sephe@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 6EA1B1AC6; Fri, 11 Nov 2016 07:41:39 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB7fcXN092543; Fri, 11 Nov 2016 07:41:38 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB7fcFf092542; Fri, 11 Nov 2016 07:41:38 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110741.uAB7fcFf092542@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 07:41:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308513 - stable/10/sys/dev/hyperv/netvsc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 07:41:39 -0000 Author: sephe Date: Fri Nov 11 07:41:38 2016 New Revision: 308513 URL: https://svnweb.freebsd.org/changeset/base/308513 Log: MFC 308166,308167 308166 hyperv/hn: Move TSO packet fixup to an earlier place for if_transmit. While TSO packet header may be still cache-hot. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8393 308167 hyperv/hn: Directly fill chimney sending buffer for small packets. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8394 Modified: stable/10/sys/dev/hyperv/netvsc/if_hn.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/netvsc/if_hn.c ============================================================================== --- stable/10/sys/dev/hyperv/netvsc/if_hn.c Fri Nov 11 07:33:44 2016 (r308512) +++ stable/10/sys/dev/hyperv/netvsc/if_hn.c Fri Nov 11 07:41:38 2016 (r308513) @@ -550,6 +550,80 @@ hn_chim_free(struct hn_softc *sc, uint32 atomic_clear_long(&sc->hn_chim_bmap[idx], mask); } +#if defined(INET6) || defined(INET) +/* + * NOTE: If this function failed, the m_head would be freed. + */ +static __inline struct mbuf * +hn_tso_fixup(struct mbuf *m_head) +{ + struct ether_vlan_header *evl; + struct tcphdr *th; + int ehlen; + + KASSERT(M_WRITABLE(m_head), ("TSO mbuf not writable")); + +#define PULLUP_HDR(m, len) \ +do { \ + if (__predict_false((m)->m_len < (len))) { \ + (m) = m_pullup((m), (len)); \ + if ((m) == NULL) \ + return (NULL); \ + } \ +} while (0) + + PULLUP_HDR(m_head, sizeof(*evl)); + evl = mtod(m_head, struct ether_vlan_header *); + if (evl->evl_encap_proto == ntohs(ETHERTYPE_VLAN)) + ehlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN; + else + ehlen = ETHER_HDR_LEN; + +#ifdef INET + if (m_head->m_pkthdr.csum_flags & CSUM_IP_TSO) { + struct ip *ip; + int iphlen; + + PULLUP_HDR(m_head, ehlen + sizeof(*ip)); + ip = mtodo(m_head, ehlen); + iphlen = ip->ip_hl << 2; + + PULLUP_HDR(m_head, ehlen + iphlen + sizeof(*th)); + th = mtodo(m_head, ehlen + iphlen); + + ip->ip_len = 0; + ip->ip_sum = 0; + th->th_sum = in_pseudo(ip->ip_src.s_addr, + ip->ip_dst.s_addr, htons(IPPROTO_TCP)); + } +#endif +#if defined(INET6) && defined(INET) + else +#endif +#ifdef INET6 + { + struct ip6_hdr *ip6; + + PULLUP_HDR(m_head, ehlen + sizeof(*ip6)); + ip6 = mtodo(m_head, ehlen); + if (ip6->ip6_nxt != IPPROTO_TCP) { + m_freem(m_head); + return (NULL); + } + + PULLUP_HDR(m_head, ehlen + sizeof(*ip6) + sizeof(*th)); + th = mtodo(m_head, ehlen + sizeof(*ip6)); + + ip6->ip6_plen = 0; + th->th_sum = in6_cksum_pseudo(ip6, 0, IPPROTO_TCP, 0); + } +#endif + return (m_head); + +#undef PULLUP_HDR +} +#endif /* INET6 || INET */ + static int hn_set_rxfilter(struct hn_softc *sc) { @@ -1348,15 +1422,28 @@ hn_encap(struct hn_tx_ring *txr, struct struct mbuf *m_head = *m_head0; struct rndis_packet_msg *pkt; uint32_t *pi_data; + void *chim = NULL; int pktlen; - /* - * extension points to the area reserved for the - * rndis_filter_packet, which is placed just after - * the netvsc_packet (and rppi struct, if present; - * length is updated later). - */ pkt = txd->rndis_pkt; + if (m_head->m_pkthdr.len + HN_RNDIS_PKT_LEN < txr->hn_chim_size) { + /* + * This packet is small enough to fit into a chimney sending + * buffer. Try allocating one chimney sending buffer now. + */ + txr->hn_tx_chimney_tried++; + txd->chim_index = hn_chim_alloc(txr->hn_sc); + if (txd->chim_index != HN_NVS_CHIM_IDX_INVALID) { + chim = txr->hn_sc->hn_chim + + (txd->chim_index * txr->hn_sc->hn_chim_szmax); + /* + * Directly fill the chimney sending buffer w/ the + * RNDIS packet message. + */ + pkt = chim; + } + } + pkt->rm_type = REMOTE_NDIS_PACKET_MSG; pkt->rm_len = sizeof(*pkt) + m_head->m_pkthdr.len; pkt->rm_dataoffset = sizeof(*pkt); @@ -1386,32 +1473,10 @@ hn_encap(struct hn_tx_ring *txr, struct if (m_head->m_pkthdr.csum_flags & CSUM_TSO) { #if defined(INET6) || defined(INET) - struct ether_vlan_header *eh; - int ether_len; - - /* - * XXX need m_pullup and use mtodo - */ - eh = mtod(m_head, struct ether_vlan_header*); - if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) - ether_len = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN; - else - ether_len = ETHER_HDR_LEN; - pi_data = hn_rndis_pktinfo_append(pkt, HN_RNDIS_PKT_LEN, NDIS_LSO2_INFO_SIZE, NDIS_PKTINFO_TYPE_LSO); #ifdef INET if (m_head->m_pkthdr.csum_flags & CSUM_IP_TSO) { - struct ip *ip = - (struct ip *)(m_head->m_data + ether_len); - unsigned long iph_len = ip->ip_hl << 2; - struct tcphdr *th = - (struct tcphdr *)((caddr_t)ip + iph_len); - - ip->ip_len = 0; - ip->ip_sum = 0; - th->th_sum = in_pseudo(ip->ip_src.s_addr, - ip->ip_dst.s_addr, htons(IPPROTO_TCP)); *pi_data = NDIS_LSO2_INFO_MAKEIPV4(0, m_head->m_pkthdr.tso_segsz); } @@ -1421,12 +1486,6 @@ hn_encap(struct hn_tx_ring *txr, struct #endif #ifdef INET6 { - struct ip6_hdr *ip6 = (struct ip6_hdr *) - (m_head->m_data + ether_len); - struct tcphdr *th = (struct tcphdr *)(ip6 + 1); - - ip6->ip6_plen = 0; - th->th_sum = in6_cksum_pseudo(ip6, 0, IPPROTO_TCP, 0); *pi_data = NDIS_LSO2_INFO_MAKEIPV6(0, m_head->m_pkthdr.tso_segsz); } @@ -1457,26 +1516,25 @@ hn_encap(struct hn_tx_ring *txr, struct pkt->rm_pktinfooffset = hn_rndis_pktmsg_offset(pkt->rm_pktinfooffset); /* - * Chimney send, if the packet could fit into one chimney buffer. + * Fast path: Chimney sending. */ - if (pkt->rm_len < txr->hn_chim_size) { - txr->hn_tx_chimney_tried++; - txd->chim_index = hn_chim_alloc(txr->hn_sc); - if (txd->chim_index != HN_NVS_CHIM_IDX_INVALID) { - uint8_t *dest = txr->hn_sc->hn_chim + - (txd->chim_index * txr->hn_sc->hn_chim_szmax); - - memcpy(dest, pkt, pktlen); - dest += pktlen; - m_copydata(m_head, 0, m_head->m_pkthdr.len, dest); - - txd->chim_size = pkt->rm_len; - txr->hn_gpa_cnt = 0; - txr->hn_tx_chimney++; - txr->hn_sendpkt = hn_txpkt_chim; - goto done; - } - } + if (chim != NULL) { + KASSERT(txd->chim_index != HN_NVS_CHIM_IDX_INVALID, + ("chimney buffer is not used")); + KASSERT(pkt == chim, ("RNDIS pkt not in chimney buffer")); + + m_copydata(m_head, 0, m_head->m_pkthdr.len, + ((uint8_t *)chim) + pktlen); + + txd->chim_size = pkt->rm_len; + txr->hn_gpa_cnt = 0; + txr->hn_tx_chimney++; + txr->hn_sendpkt = hn_txpkt_chim; + goto done; + } + KASSERT(txd->chim_index == HN_NVS_CHIM_IDX_INVALID, + ("chimney buffer is used")); + KASSERT(pkt == txd->rndis_pkt, ("RNDIS pkt not in txdesc")); error = hn_txdesc_dmamap_load(txr, txd, &m_head, segs, &nsegs); if (error) { @@ -3306,6 +3364,16 @@ hn_start_locked(struct hn_tx_ring *txr, return 1; } +#if defined(INET6) || defined(INET) + if (m_head->m_pkthdr.csum_flags & CSUM_TSO) { + m_head = hn_tso_fixup(m_head); + if (__predict_false(m_head == NULL)) { + if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); + continue; + } + } +#endif + txd = hn_txdesc_get(txr); if (txd == NULL) { txr->hn_no_txdescs++; @@ -3468,6 +3536,20 @@ hn_transmit(struct ifnet *ifp, struct mb struct hn_tx_ring *txr; int error, idx = 0; +#if defined(INET6) || defined(INET) + /* + * Perform TSO packet header fixup now, since the TSO + * packet header should be cache-hot. + */ + if (m->m_pkthdr.csum_flags & CSUM_TSO) { + m = hn_tso_fixup(m); + if (__predict_false(m == NULL)) { + if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); + return EIO; + } + } +#endif + /* * Select the TX ring based on flowid */ From owner-svn-src-stable-10@freebsd.org Fri Nov 11 07:45:05 2016 Return-Path: Delivered-To: svn-src-stable-10@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 004D7C3B075; Fri, 11 Nov 2016 07:45:05 +0000 (UTC) (envelope-from sephe@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 A7D941D54; Fri, 11 Nov 2016 07:45:04 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB7j3sI094787; Fri, 11 Nov 2016 07:45:03 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB7j3na094786; Fri, 11 Nov 2016 07:45:03 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110745.uAB7j3na094786@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 07:45:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308514 - stable/10/sys/dev/hyperv/vmbus X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 07:45:05 -0000 Author: sephe Date: Fri Nov 11 07:45:03 2016 New Revision: 308514 URL: https://svnweb.freebsd.org/changeset/base/308514 Log: MFC 308168 hyperv/vmbus: Avoid extra header copy. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8395 Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Fri Nov 11 07:41:38 2016 (r308513) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Fri Nov 11 07:45:03 2016 (r308514) @@ -926,28 +926,28 @@ vmbus_chan_recv(struct vmbus_channel *ch int vmbus_chan_recv_pkt(struct vmbus_channel *chan, - struct vmbus_chanpkt_hdr *pkt0, int *pktlen0) + struct vmbus_chanpkt_hdr *pkt, int *pktlen0) { - struct vmbus_chanpkt_hdr pkt; - int error, pktlen; + int error, pktlen, pkt_hlen; - error = vmbus_rxbr_peek(&chan->ch_rxbr, &pkt, sizeof(pkt)); + pkt_hlen = sizeof(*pkt); + error = vmbus_rxbr_peek(&chan->ch_rxbr, pkt, pkt_hlen); if (error) return (error); - if (__predict_false(pkt.cph_hlen < VMBUS_CHANPKT_HLEN_MIN)) { - vmbus_chan_printf(chan, "invalid hlen %u\n", pkt.cph_hlen); + if (__predict_false(pkt->cph_hlen < VMBUS_CHANPKT_HLEN_MIN)) { + vmbus_chan_printf(chan, "invalid hlen %u\n", pkt->cph_hlen); /* XXX this channel is dead actually. */ return (EIO); } - if (__predict_false(pkt.cph_hlen > pkt.cph_tlen)) { + if (__predict_false(pkt->cph_hlen > pkt->cph_tlen)) { vmbus_chan_printf(chan, "invalid hlen %u and tlen %u\n", - pkt.cph_hlen, pkt.cph_tlen); + pkt->cph_hlen, pkt->cph_tlen); /* XXX this channel is dead actually. */ return (EIO); } - pktlen = VMBUS_CHANPKT_GETLEN(pkt.cph_tlen); + pktlen = VMBUS_CHANPKT_GETLEN(pkt->cph_tlen); if (*pktlen0 < pktlen) { /* Return the size of this packet. */ *pktlen0 = pktlen; @@ -955,8 +955,12 @@ vmbus_chan_recv_pkt(struct vmbus_channel } *pktlen0 = pktlen; - /* Include packet header */ - error = vmbus_rxbr_read(&chan->ch_rxbr, pkt0, pktlen, 0); + /* + * Skip the fixed-size packet header, which has been filled + * by the above vmbus_rxbr_peek(). + */ + error = vmbus_rxbr_read(&chan->ch_rxbr, pkt + 1, + pktlen - pkt_hlen, pkt_hlen); KASSERT(!error, ("vmbus_rxbr_read failed")); return (0); From owner-svn-src-stable-10@freebsd.org Fri Nov 11 07:52:30 2016 Return-Path: Delivered-To: svn-src-stable-10@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 C185DC3B2E4; Fri, 11 Nov 2016 07:52:30 +0000 (UTC) (envelope-from sephe@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 9093C1250; Fri, 11 Nov 2016 07:52:30 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB7qTuj098945; Fri, 11 Nov 2016 07:52:29 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB7qTUv098941; Fri, 11 Nov 2016 07:52:29 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110752.uAB7qTUv098941@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 07:52:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308515 - in stable/10/sys/dev/hyperv: include vmbus X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 07:52:30 -0000 Author: sephe Date: Fri Nov 11 07:52:29 2016 New Revision: 308515 URL: https://svnweb.freebsd.org/changeset/base/308515 Log: MFC 308194 hyperv: GC unused functions. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8406 Modified: stable/10/sys/dev/hyperv/include/hyperv.h stable/10/sys/dev/hyperv/include/vmbus.h stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/hyperv/include/hyperv.h ============================================================================== --- stable/10/sys/dev/hyperv/include/hyperv.h Fri Nov 11 07:45:03 2016 (r308514) +++ stable/10/sys/dev/hyperv/include/hyperv.h Fri Nov 11 07:52:29 2016 (r308515) @@ -44,15 +44,4 @@ struct hyperv_guid { int hyperv_guid2str(const struct hyperv_guid *, char *, size_t); -/** - * @brief Get physical address from virtual - */ -static inline unsigned long -hv_get_phys_addr(void *virt) -{ - unsigned long ret; - ret = (vtophys(virt) | ((vm_offset_t) virt & PAGE_MASK)); - return (ret); -} - #endif /* _HYPERV_H_ */ Modified: stable/10/sys/dev/hyperv/include/vmbus.h ============================================================================== --- stable/10/sys/dev/hyperv/include/vmbus.h Fri Nov 11 07:45:03 2016 (r308514) +++ stable/10/sys/dev/hyperv/include/vmbus.h Fri Nov 11 07:52:29 2016 (r308515) @@ -147,8 +147,6 @@ int vmbus_chan_gpadl_disconnect(struct void vmbus_chan_cpu_set(struct vmbus_channel *chan, int cpu); void vmbus_chan_cpu_rr(struct vmbus_channel *chan); -struct vmbus_channel * - vmbus_chan_cpu2chan(struct vmbus_channel *chan, int cpu); void vmbus_chan_set_readbatch(struct vmbus_channel *chan, bool on); struct vmbus_channel ** Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c ============================================================================== --- stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Fri Nov 11 07:45:03 2016 (r308514) +++ stable/10/sys/dev/hyperv/vmbus/vmbus_chan.c Fri Nov 11 07:52:29 2016 (r308515) @@ -1534,65 +1534,6 @@ vmbus_chan_destroy_all(struct vmbus_soft } } -/* - * The channel whose vcpu binding is closest to the currect vcpu will - * be selected. - * If no multi-channel, always select primary channel. - */ -struct vmbus_channel * -vmbus_chan_cpu2chan(struct vmbus_channel *prichan, int cpu) -{ - struct vmbus_channel *sel, *chan; - uint32_t vcpu, sel_dist; - - KASSERT(cpu >= 0 && cpu < mp_ncpus, ("invalid cpuid %d", cpu)); - if (TAILQ_EMPTY(&prichan->ch_subchans)) - return prichan; - - vcpu = VMBUS_PCPU_GET(prichan->ch_vmbus, vcpuid, cpu); - -#define CHAN_VCPU_DIST(ch, vcpu) \ - (((ch)->ch_vcpuid > (vcpu)) ? \ - ((ch)->ch_vcpuid - (vcpu)) : ((vcpu) - (ch)->ch_vcpuid)) - -#define CHAN_SELECT(ch) \ -do { \ - sel = ch; \ - sel_dist = CHAN_VCPU_DIST(ch, vcpu); \ -} while (0) - - CHAN_SELECT(prichan); - - mtx_lock(&prichan->ch_subchan_lock); - TAILQ_FOREACH(chan, &prichan->ch_subchans, ch_sublink) { - uint32_t dist; - - KASSERT(chan->ch_stflags & VMBUS_CHAN_ST_OPENED, - ("chan%u is not opened", chan->ch_id)); - - if (chan->ch_vcpuid == vcpu) { - /* Exact match; done */ - CHAN_SELECT(chan); - break; - } - - dist = CHAN_VCPU_DIST(chan, vcpu); - if (sel_dist <= dist) { - /* Far or same distance; skip */ - continue; - } - - /* Select the closer channel. */ - CHAN_SELECT(chan); - } - mtx_unlock(&prichan->ch_subchan_lock); - -#undef CHAN_SELECT -#undef CHAN_VCPU_DIST - - return sel; -} - struct vmbus_channel ** vmbus_subchan_get(struct vmbus_channel *pri_chan, int subchan_cnt) { From owner-svn-src-stable-10@freebsd.org Fri Nov 11 08:04:26 2016 Return-Path: Delivered-To: svn-src-stable-10@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 26ABAC3B6D7; Fri, 11 Nov 2016 08:04:26 +0000 (UTC) (envelope-from sephe@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 E5EA01738; Fri, 11 Nov 2016 08:04:25 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAB84Pxg003885; Fri, 11 Nov 2016 08:04:25 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAB84O3e003881; Fri, 11 Nov 2016 08:04:24 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201611110804.uAB84O3e003881@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Fri, 11 Nov 2016 08:04:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308516 - in stable/10: contrib/hyperv/tools sys/dev/hyperv/utilities X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 08:04:26 -0000 Author: sephe Date: Fri Nov 11 08:04:24 2016 New Revision: 308516 URL: https://svnweb.freebsd.org/changeset/base/308516 Log: MFC 308201 hyperv/kvp: Don't mix message status codes and function return values. While I'm here, move message status codes to hv_utilreg.h, since they will be used by the upcoming VSS stuffs. Submitted by: Hongjiang Zhang Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8391 Modified: stable/10/contrib/hyperv/tools/hv_kvp_daemon.c stable/10/sys/dev/hyperv/utilities/hv_kvp.c stable/10/sys/dev/hyperv/utilities/hv_kvp.h stable/10/sys/dev/hyperv/utilities/hv_utilreg.h Directory Properties: stable/10/ (props changed) Modified: stable/10/contrib/hyperv/tools/hv_kvp_daemon.c ============================================================================== --- stable/10/contrib/hyperv/tools/hv_kvp_daemon.c Fri Nov 11 07:52:29 2016 (r308515) +++ stable/10/contrib/hyperv/tools/hv_kvp_daemon.c Fri Nov 11 08:04:24 2016 (r308516) @@ -52,9 +52,10 @@ #include #include #include +#include #include "hv_kvp.h" - +#include "hv_utilreg.h" typedef uint8_t __u8; typedef uint16_t __u16; typedef uint32_t __u32; @@ -684,18 +685,16 @@ kvp_get_ipconfig_info(char *if_name, str */ kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way, (MAX_GATEWAY_SIZE * 2), INET_ADDRSTRLEN, 0); - /* * Retrieve the IPV6 address of default gateway. */ - snprintf(cmd, sizeof(cmd), "netstat -rn inet6 | grep %s | awk '/default/ {print $2 }", if_name); + snprintf(cmd, sizeof(cmd), "netstat -rn inet6 | grep %s | awk '/default/ {print $2 }'", if_name); /* * Execute the command to gather gateway IPV6 info. */ kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way, (MAX_GATEWAY_SIZE * 2), INET6_ADDRSTRLEN, 1); - /* * we just invoke an external script to get the DNS info. * @@ -782,11 +781,11 @@ kvp_process_ip_address(void *addrp, } if ((length - *offset) < addr_length + 1) { - return (HV_KVP_E_FAIL); + return (EINVAL); } if (str == NULL) { strlcpy(buffer, "inet_ntop failed\n", length); - return (HV_KVP_E_FAIL); + return (errno); } if (*offset == 0) { strlcpy(buffer, tmp, length); @@ -832,7 +831,7 @@ kvp_get_ip_info(int family, char *if_nam if (getifaddrs(&ifap)) { strlcpy(buffer, "getifaddrs failed\n", buffer_length); - return (HV_KVP_E_FAIL); + return (errno); } curp = ifap; @@ -924,7 +923,6 @@ kvp_get_ip_info(int family, char *if_nam /* * Collect other ip configuration info. */ - kvp_get_ipconfig_info(if_name, ip_buffer); } @@ -954,7 +952,7 @@ kvp_write_file(FILE *f, const char *s1, ret = fprintf(f, "%s%s%s%s\n", s1, s2, "=", s3); if (ret < 0) { - return (HV_KVP_E_FAIL); + return (EIO); } return (0); @@ -979,7 +977,7 @@ kvp_set_ip_info(char *if_name, struct hv if (file == NULL) { KVP_LOG(LOG_ERR, "FreeBSD Failed to open config file\n"); - return (HV_KVP_E_FAIL); + return (errno); } /* @@ -988,7 +986,7 @@ kvp_set_ip_info(char *if_name, struct hv mac_addr = kvp_if_name_to_mac(if_name); if (mac_addr == NULL) { - error = HV_KVP_E_FAIL; + error = EINVAL; goto kvp_set_ip_info_error; } /* MAC Address */ @@ -1091,28 +1089,30 @@ kvp_op_getipinfo(struct hv_kvp_msg *op_m { struct hv_kvp_ipaddr_value *ip_val; char *if_name; + int error = 0; assert(op_msg != NULL); KVP_LOG(LOG_DEBUG, "In kvp_op_getipinfo.\n"); ip_val = &op_msg->body.kvp_ip_val; - op_msg->hdr.error = HV_KVP_S_OK; + op_msg->hdr.error = HV_S_OK; if_name = kvp_mac_to_if_name((char *)ip_val->adapter_id); if (if_name == NULL) { /* No interface found with the mac address. */ - op_msg->hdr.error = HV_KVP_E_FAIL; + op_msg->hdr.error = HV_E_FAIL; goto kvp_op_getipinfo_done; } - op_msg->hdr.error = kvp_get_ip_info(0, if_name, + error = kvp_get_ip_info(0, if_name, HV_KVP_OP_GET_IP_INFO, ip_val, (MAX_IP_ADDR_SIZE * 2)); - + if (error) + op_msg->hdr.error = HV_E_FAIL; free(if_name); kvp_op_getipinfo_done: - return(op_msg->hdr.error); + return (error); } @@ -1121,25 +1121,27 @@ kvp_op_setipinfo(struct hv_kvp_msg *op_m { struct hv_kvp_ipaddr_value *ip_val; char *if_name; + int error = 0; assert(op_msg != NULL); KVP_LOG(LOG_DEBUG, "In kvp_op_setipinfo.\n"); ip_val = &op_msg->body.kvp_ip_val; - op_msg->hdr.error = HV_KVP_S_OK; + op_msg->hdr.error = HV_S_OK; if_name = (char *)ip_val->adapter_id; if (if_name == NULL) { /* No adapter provided. */ - op_msg->hdr.error = HV_KVP_GUID_NOTFOUND; + op_msg->hdr.error = HV_GUID_NOTFOUND; goto kvp_op_setipinfo_done; } - op_msg->hdr.error = kvp_set_ip_info(if_name, ip_val); - + error = kvp_set_ip_info(if_name, ip_val); + if (error) + op_msg->hdr.error = HV_E_FAIL; kvp_op_setipinfo_done: - return(op_msg->hdr.error); + return (error); } @@ -1154,7 +1156,7 @@ kvp_op_setgetdel(struct hv_kvp_msg *op_m assert(op_hdlr != NULL); op_pool = op_msg->hdr.kvp_hdr.pool; - op_msg->hdr.error = HV_KVP_S_OK; + op_msg->hdr.error = HV_S_OK; switch(op_hdlr->kvp_op_key) { case HV_KVP_OP_SET: @@ -1198,8 +1200,7 @@ kvp_op_setgetdel(struct hv_kvp_msg *op_m } if (error != 0) - op_msg->hdr.error = HV_KVP_S_CONT; - + op_msg->hdr.error = HV_S_CONT; return(error); } @@ -1216,7 +1217,7 @@ kvp_op_enumerate(struct hv_kvp_msg *op_m op = op_msg->hdr.kvp_hdr.operation; op_pool = op_msg->hdr.kvp_hdr.pool; - op_msg->hdr.error = HV_KVP_S_OK; + op_msg->hdr.error = HV_S_OK; /* * If the pool is not HV_KVP_POOL_AUTO, read from the appropriate @@ -1229,7 +1230,7 @@ kvp_op_enumerate(struct hv_kvp_msg *op_m HV_KVP_EXCHANGE_MAX_KEY_SIZE, op_msg->body.kvp_enum_data.data.msg_value.value, HV_KVP_EXCHANGE_MAX_VALUE_SIZE)) { - op_msg->hdr.error = HV_KVP_S_CONT; + op_msg->hdr.error = HV_S_CONT; error = -1; } goto kvp_op_enumerate_done; @@ -1298,12 +1299,14 @@ kvp_op_enumerate(struct hv_kvp_msg *op_m KVP_LOG(LOG_ERR, "Auto pool Index %d not found.\n", op_msg->body.kvp_enum_data.index); #endif - op_msg->hdr.error = HV_KVP_S_CONT; + op_msg->hdr.error = HV_S_CONT; error = -1; break; } kvp_op_enumerate_done: + if (error != 0) + op_msg->hdr.error = HV_S_CONT; return(error); } @@ -1496,10 +1499,13 @@ main(int argc, char *argv[]) */ error = kvp_op_hdlrs[op].kvp_op_exec(hv_msg, (void *)&kvp_op_hdlrs[op]); - if (error != 0 && hv_msg->hdr.error != HV_KVP_S_CONT) - KVP_LOG(LOG_WARNING, - "Operation failed OP = %d, error = 0x%x\n", - op, error); + if (error != 0) { + assert(hv_msg->hdr.error != HV_S_OK); + if (hv_msg->hdr.error != HV_S_CONT) + KVP_LOG(LOG_WARNING, + "Operation failed OP = %d, error = 0x%x\n", + op, error); + } } /* Modified: stable/10/sys/dev/hyperv/utilities/hv_kvp.c ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_kvp.c Fri Nov 11 07:52:29 2016 (r308515) +++ stable/10/sys/dev/hyperv/utilities/hv_kvp.c Fri Nov 11 08:04:24 2016 (r308516) @@ -72,8 +72,6 @@ __FBSDID("$FreeBSD$"); /* hv_kvp defines */ #define BUFFERSIZE sizeof(struct hv_kvp_msg) -#define KVP_SUCCESS 0 -#define KVP_ERROR 1 #define kvp_hdr hdr.kvp_hdr #define KVP_FWVER_MAJOR 3 @@ -480,7 +478,7 @@ hv_kvp_convert_usermsg_to_hostmsg(struct case HV_KVP_OP_SET_IP_INFO: case HV_KVP_OP_SET: case HV_KVP_OP_DELETE: - return (KVP_SUCCESS); + return (0); case HV_KVP_OP_ENUMERATE: host_exchg_data = &hmsg->body.kvp_enum_data.data; @@ -501,9 +499,9 @@ hv_kvp_convert_usermsg_to_hostmsg(struct host_exchg_data->value_type = HV_REG_SZ; if ((hkey_len < 0) || (hvalue_len < 0)) - return (HV_KVP_E_FAIL); + return (EINVAL); - return (KVP_SUCCESS); + return (0); case HV_KVP_OP_GET: host_exchg_data = &hmsg->body.kvp_get.data; @@ -519,12 +517,12 @@ hv_kvp_convert_usermsg_to_hostmsg(struct host_exchg_data->value_type = HV_REG_SZ; if ((hkey_len < 0) || (hvalue_len < 0)) - return (HV_KVP_E_FAIL); + return (EINVAL); - return (KVP_SUCCESS); + return (0); default: - return (HV_KVP_E_FAIL); + return (EINVAL); } } @@ -533,16 +531,13 @@ hv_kvp_convert_usermsg_to_hostmsg(struct * Send the response back to the host. */ static void -hv_kvp_respond_host(hv_kvp_sc *sc, int error) +hv_kvp_respond_host(hv_kvp_sc *sc, uint32_t error) { struct hv_vmbus_icmsg_hdr *hv_icmsg_hdrp; hv_icmsg_hdrp = (struct hv_vmbus_icmsg_hdr *) &sc->rcv_buf[sizeof(struct hv_vmbus_pipe_hdr)]; - if (error) - error = HV_KVP_E_FAIL; - hv_icmsg_hdrp->status = error; hv_icmsg_hdrp->icflags = HV_ICMSGHDRFLAG_TRANSACTION | HV_ICMSGHDRFLAG_RESPONSE; @@ -612,8 +607,10 @@ hv_kvp_process_request(void *context, in error = vmbus_ic_negomsg(&sc->util_sc, kvp_buf, &recvlen, KVP_FWVER, KVP_MSGVER); /* XXX handle vmbus_ic_negomsg failure. */ - hv_kvp_respond_host(sc, error); - + if (!error) + hv_kvp_respond_host(sc, HV_S_OK); + else + hv_kvp_respond_host(sc, HV_E_FAIL); /* * It is ok to not acquire the mutex before setting * req_in_progress here because negotiation is the @@ -657,7 +654,7 @@ hv_kvp_process_request(void *context, in */ if (hv_kvp_req_in_progress(sc)) { hv_kvp_log_info("%s: request was still active after wait so failing\n", __func__); - hv_kvp_respond_host(sc, HV_KVP_E_FAIL); + hv_kvp_respond_host(sc, HV_E_FAIL); sc->req_in_progress = false; } @@ -737,9 +734,9 @@ hv_kvp_dev_daemon_read(struct cdev *dev, struct hv_kvp_msg *hv_kvp_dev_buf; hv_kvp_sc *sc = (hv_kvp_sc*)dev->si_drv1; - /* Check hv_kvp daemon registration status*/ + /* Read is not allowed util registering is done. */ if (!sc->register_done) - return (KVP_ERROR); + return (EPERM); sema_wait(&sc->dev_sema); @@ -789,7 +786,7 @@ hv_kvp_dev_daemon_write(struct cdev *dev } else { hv_kvp_log_info("%s, KVP Registration Failed\n", __func__); - return (KVP_ERROR); + return (EINVAL); } } else { @@ -799,10 +796,15 @@ hv_kvp_dev_daemon_write(struct cdev *dev struct hv_kvp_msg *hmsg = sc->host_kvp_msg; struct hv_kvp_msg *umsg = &sc->daemon_kvp_msg; - hv_kvp_convert_usermsg_to_hostmsg(umsg, hmsg); - hv_kvp_respond_host(sc, KVP_SUCCESS); + error = hv_kvp_convert_usermsg_to_hostmsg(umsg, hmsg); + hv_kvp_respond_host(sc, umsg->hdr.error); wakeup(sc); sc->req_in_progress = false; + if (umsg->hdr.error != HV_S_OK) + hv_kvp_log_info("%s, Error 0x%x from daemon\n", + __func__, umsg->hdr.error); + if (error) + hv_kvp_log_info("%s, Error from convert\n", __func__); } sc->daemon_busy = false; @@ -865,7 +867,7 @@ hv_kvp_attach(device_t dev) child = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); SYSCTL_ADD_INT(ctx, child, OID_AUTO, "hv_kvp_log", - CTLFLAG_RW, &hv_kvp_log, 0, "Hyperv KVP service log level"); + CTLFLAG_RWTUN, &hv_kvp_log, 0, "Hyperv KVP service log level"); TASK_INIT(&sc->task, 0, hv_kvp_process_request, sc); Modified: stable/10/sys/dev/hyperv/utilities/hv_kvp.h ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_kvp.h Fri Nov 11 07:52:29 2016 (r308515) +++ stable/10/sys/dev/hyperv/utilities/hv_kvp.h Fri Nov 11 08:04:24 2016 (r308516) @@ -144,19 +144,6 @@ enum hv_kvp_exchg_pool { HV_KVP_POOL_COUNT /* Number of pools, must be last. */ }; - -/* - * Some Hyper-V status codes. - */ -#define HV_KVP_S_OK 0x00000000 -#define HV_KVP_E_FAIL 0x80004005 -#define HV_KVP_S_CONT 0x80070103 -#define HV_ERROR_NOT_SUPPORTED 0x80070032 -#define HV_ERROR_MACHINE_LOCKED 0x800704F7 -#define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F -#define HV_INVALIDARG 0x80070057 -#define HV_KVP_GUID_NOTFOUND 0x80041002 - #define ADDR_FAMILY_NONE 0x00 #define ADDR_FAMILY_IPV4 0x01 #define ADDR_FAMILY_IPV6 0x02 Modified: stable/10/sys/dev/hyperv/utilities/hv_utilreg.h ============================================================================== --- stable/10/sys/dev/hyperv/utilities/hv_utilreg.h Fri Nov 11 07:52:29 2016 (r308515) +++ stable/10/sys/dev/hyperv/utilities/hv_utilreg.h Fri Nov 11 08:04:24 2016 (r308516) @@ -29,10 +29,17 @@ #ifndef _HV_UTILREG_H_ #define _HV_UTILREG_H_ -#define HV_S_OK 0x00000000 -#define HV_E_FAIL 0x80004005 -#define HV_ERROR_NOT_SUPPORTED 0x80070032 -#define HV_ERROR_MACHINE_LOCKED 0x800704F7 +/* + * Some Hyper-V status codes. + */ +#define HV_S_OK 0x00000000 +#define HV_E_FAIL 0x80004005 +#define HV_S_CONT 0x80070103 +#define HV_ERROR_NOT_SUPPORTED 0x80070032 +#define HV_ERROR_MACHINE_LOCKED 0x800704F7 +#define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F +#define HV_INVALIDARG 0x80070057 +#define HV_GUID_NOTFOUND 0x80041002 /* * Common defines for Hyper-V ICs From owner-svn-src-stable-10@freebsd.org Fri Nov 11 19:57:11 2016 Return-Path: Delivered-To: svn-src-stable-10@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 DB967C3C62B; Fri, 11 Nov 2016 19:57:11 +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 A92D313C8; Fri, 11 Nov 2016 19:57:11 +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 uABJvAM9009521; Fri, 11 Nov 2016 19:57:10 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uABJvAi2009520; Fri, 11 Nov 2016 19:57:10 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611111957.uABJvAi2009520@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 11 Nov 2016 19:57:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308546 - stable/10/sys/fs/msdosfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 19:57:12 -0000 Author: kib Date: Fri Nov 11 19:57:10 2016 New Revision: 308546 URL: https://svnweb.freebsd.org/changeset/base/308546 Log: MFC r308019: Remove useless NULL check. Modified: stable/10/sys/fs/msdosfs/msdosfs_vfsops.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/fs/msdosfs/msdosfs_vfsops.c ============================================================================== --- stable/10/sys/fs/msdosfs/msdosfs_vfsops.c Fri Nov 11 19:40:34 2016 (r308545) +++ stable/10/sys/fs/msdosfs/msdosfs_vfsops.c Fri Nov 11 19:57:10 2016 (r308546) @@ -763,8 +763,7 @@ error_exit: } if (pmp) { lockdestroy(&pmp->pm_fatlock); - if (pmp->pm_inusemap) - free(pmp->pm_inusemap, M_MSDOSFSFAT); + free(pmp->pm_inusemap, M_MSDOSFSFAT); free(pmp, M_MSDOSFSMNT); mp->mnt_data = NULL; } From owner-svn-src-stable-10@freebsd.org Fri Nov 11 19:58:27 2016 Return-Path: Delivered-To: svn-src-stable-10@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 282F7C3C694; Fri, 11 Nov 2016 19:58:27 +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 E8C1615C7; Fri, 11 Nov 2016 19:58:26 +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 uABJwQnY009680; Fri, 11 Nov 2016 19:58:26 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uABJwQHd009679; Fri, 11 Nov 2016 19:58:26 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611111958.uABJwQHd009679@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 11 Nov 2016 19:58:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308547 - stable/10/sys/fs/msdosfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 19:58:27 -0000 Author: kib Date: Fri Nov 11 19:58:25 2016 New Revision: 308547 URL: https://svnweb.freebsd.org/changeset/base/308547 Log: MFC r308020: Fix comment formatting. Modified: stable/10/sys/fs/msdosfs/msdosfs_fat.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/fs/msdosfs/msdosfs_fat.c ============================================================================== --- stable/10/sys/fs/msdosfs/msdosfs_fat.c Fri Nov 11 19:57:10 2016 (r308546) +++ stable/10/sys/fs/msdosfs/msdosfs_fat.c Fri Nov 11 19:58:25 2016 (r308547) @@ -1019,12 +1019,14 @@ extendfile(dep, count, bpp, ncp, flags) while (count > 0) { /* * Allocate a new cluster chain and cat onto the end of the - * file. * If the file is empty we make de_StartCluster point - * to the new block. Note that de_StartCluster being 0 is - * sufficient to be sure the file is empty since we exclude - * attempts to extend the root directory above, and the root - * dir is the only file with a startcluster of 0 that has - * blocks allocated (sort of). + * file. + * If the file is empty we make de_StartCluster point + * to the new block. Note that de_StartCluster being + * 0 is sufficient to be sure the file is empty since + * we exclude attempts to extend the root directory + * above, and the root dir is the only file with a + * startcluster of 0 that has blocks allocated (sort + * of). */ if (dep->de_StartCluster == 0) cn = 0; From owner-svn-src-stable-10@freebsd.org Fri Nov 11 19:59:43 2016 Return-Path: Delivered-To: svn-src-stable-10@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 631B3C3C6FD; Fri, 11 Nov 2016 19:59:43 +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 34BC71724; Fri, 11 Nov 2016 19:59:43 +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 uABJxgea009838; Fri, 11 Nov 2016 19:59:42 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uABJxgfX009837; Fri, 11 Nov 2016 19:59:42 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611111959.uABJxgfX009837@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 11 Nov 2016 19:59:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308548 - stable/10/sys/fs/msdosfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 19:59:43 -0000 Author: kib Date: Fri Nov 11 19:59:42 2016 New Revision: 308548 URL: https://svnweb.freebsd.org/changeset/base/308548 Log: MFC r308021: Use symbolic name for the free cluster number. Modified: stable/10/sys/fs/msdosfs/msdosfs_fat.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/fs/msdosfs/msdosfs_fat.c ============================================================================== --- stable/10/sys/fs/msdosfs/msdosfs_fat.c Fri Nov 11 19:58:25 2016 (r308547) +++ stable/10/sys/fs/msdosfs/msdosfs_fat.c Fri Nov 11 19:59:42 2016 (r308548) @@ -951,7 +951,7 @@ fillinusemap(pmp) readcn >>= 4; readcn &= pmp->pm_fatmask; - if (readcn == 0) + if (readcn == CLUST_FREE) usemap_free(pmp, cn); } if (bp != NULL) From owner-svn-src-stable-10@freebsd.org Fri Nov 11 20:01:58 2016 Return-Path: Delivered-To: svn-src-stable-10@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 35177C3C861; Fri, 11 Nov 2016 20:01:58 +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 DE5DC19E7; Fri, 11 Nov 2016 20:01: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 uABK1vhQ013503; Fri, 11 Nov 2016 20:01:57 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uABK1vLe013502; Fri, 11 Nov 2016 20:01:57 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611112001.uABK1vLe013502@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 11 Nov 2016 20:01:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308549 - stable/10/sys/fs/msdosfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 20:01:58 -0000 Author: kib Date: Fri Nov 11 20:01:56 2016 New Revision: 308549 URL: https://svnweb.freebsd.org/changeset/base/308549 Log: MFC r308022: Use symbolic name for the value of fully free word in pm_inusemap. Modified: stable/10/sys/fs/msdosfs/msdosfs_fat.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/fs/msdosfs/msdosfs_fat.c ============================================================================== --- stable/10/sys/fs/msdosfs/msdosfs_fat.c Fri Nov 11 19:59:42 2016 (r308548) +++ stable/10/sys/fs/msdosfs/msdosfs_fat.c Fri Nov 11 20:01:56 2016 (r308549) @@ -60,6 +60,8 @@ #include #include +#define FULL_RUN ((u_int)0xffffffff) + static int chainalloc(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, u_long *got); @@ -792,8 +794,8 @@ clusteralloc1(struct msdosfsmount *pmp, idx = cn / N_INUSEBITS; map = pmp->pm_inusemap[idx]; map |= (1 << (cn % N_INUSEBITS)) - 1; - if (map != (u_int)-1) { - cn = idx * N_INUSEBITS + ffs(map^(u_int)-1) - 1; + if (map != FULL_RUN) { + cn = idx * N_INUSEBITS + ffs(map ^ FULL_RUN) - 1; if ((l = chainlength(pmp, cn, count)) >= count) return (chainalloc(pmp, cn, count, fillwith, retcluster, got)); if (l > foundl) { @@ -809,8 +811,8 @@ clusteralloc1(struct msdosfsmount *pmp, idx = cn / N_INUSEBITS; map = pmp->pm_inusemap[idx]; map |= (1 << (cn % N_INUSEBITS)) - 1; - if (map != (u_int)-1) { - cn = idx * N_INUSEBITS + ffs(map^(u_int)-1) - 1; + if (map != FULL_RUN) { + cn = idx * N_INUSEBITS + ffs(map ^ FULL_RUN) - 1; if ((l = chainlength(pmp, cn, count)) >= count) return (chainalloc(pmp, cn, count, fillwith, retcluster, got)); if (l > foundl) { @@ -921,7 +923,7 @@ fillinusemap(pmp) * loop further down. */ for (cn = 0; cn < (pmp->pm_maxcluster + N_INUSEBITS) / N_INUSEBITS; cn++) - pmp->pm_inusemap[cn] = (u_int)-1; + pmp->pm_inusemap[cn] = FULL_RUN; /* * Figure how many free clusters are in the filesystem by ripping From owner-svn-src-stable-10@freebsd.org Fri Nov 11 20:04:20 2016 Return-Path: Delivered-To: svn-src-stable-10@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 4F1D6C3C8CE; Fri, 11 Nov 2016 20:04:20 +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 130771CE3; Fri, 11 Nov 2016 20:04:20 +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 uABK4J2o013751; Fri, 11 Nov 2016 20:04:19 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uABK4JvP013750; Fri, 11 Nov 2016 20:04:19 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611112004.uABK4JvP013750@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 11 Nov 2016 20:04:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308550 - stable/10/sys/fs/msdosfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 20:04:20 -0000 Author: kib Date: Fri Nov 11 20:04:19 2016 New Revision: 308550 URL: https://svnweb.freebsd.org/changeset/base/308550 Log: MFC r308023: If the fatchain() call in chainalloc() returned an error, revert marking the cluster run as in-use. Modified: stable/10/sys/fs/msdosfs/msdosfs_fat.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/fs/msdosfs/msdosfs_fat.c ============================================================================== --- stable/10/sys/fs/msdosfs/msdosfs_fat.c Fri Nov 11 20:01:56 2016 (r308549) +++ stable/10/sys/fs/msdosfs/msdosfs_fat.c Fri Nov 11 20:04:19 2016 (r308550) @@ -731,8 +731,11 @@ chainalloc(pmp, start, count, fillwith, pmp->pm_nxtfree = CLUST_FIRST; pmp->pm_flags |= MSDOSFS_FSIMOD; error = fatchain(pmp, start, count, fillwith); - if (error != 0) + if (error != 0) { + for (cl = start, n = count; n-- > 0;) + usemap_free(pmp, cl++); return (error); + } #ifdef MSDOSFS_DEBUG printf("clusteralloc(): allocated cluster chain at %lu (%lu clusters)\n", start, count); From owner-svn-src-stable-10@freebsd.org Fri Nov 11 20:06:08 2016 Return-Path: Delivered-To: svn-src-stable-10@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 7A3DFC3C93F; Fri, 11 Nov 2016 20:06:08 +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 326031E76; Fri, 11 Nov 2016 20:06:08 +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 uABK67vO013945; Fri, 11 Nov 2016 20:06:07 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uABK672K013944; Fri, 11 Nov 2016 20:06:07 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611112006.uABK672K013944@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 11 Nov 2016 20:06:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308551 - stable/10/sys/fs/msdosfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 20:06:08 -0000 Author: kib Date: Fri Nov 11 20:06:07 2016 New Revision: 308551 URL: https://svnweb.freebsd.org/changeset/base/308551 Log: MFC r308024: Ensure that cluster allocations never allocate clusters outside the volume limits. Modified: stable/10/sys/fs/msdosfs/msdosfs_fat.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/fs/msdosfs/msdosfs_fat.c ============================================================================== --- stable/10/sys/fs/msdosfs/msdosfs_fat.c Fri Nov 11 20:04:19 2016 (r308550) +++ stable/10/sys/fs/msdosfs/msdosfs_fat.c Fri Nov 11 20:06:07 2016 (r308551) @@ -401,6 +401,8 @@ usemap_alloc(pmp, cn) MSDOSFS_ASSERT_MP_LOCKED(pmp); + KASSERT(cn <= pmp->pm_maxcluster, ("cn too large %lu %lu", cn, + pmp->pm_maxcluster)); KASSERT((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0, ("usemap_alloc on ro msdosfs mount")); KASSERT((pmp->pm_inusemap[cn / N_INUSEBITS] & (1 << (cn % N_INUSEBITS))) @@ -419,6 +421,9 @@ usemap_free(pmp, cn) { MSDOSFS_ASSERT_MP_LOCKED(pmp); + + KASSERT(cn <= pmp->pm_maxcluster, ("cn too large %lu %lu", cn, + pmp->pm_maxcluster)); KASSERT((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0, ("usemap_free on ro msdosfs mount")); pmp->pm_freeclustercount++; @@ -672,6 +677,8 @@ chainlength(pmp, start, count) MSDOSFS_ASSERT_MP_LOCKED(pmp); + if (start > pmp->pm_maxcluster) + return (0); max_idx = pmp->pm_maxcluster / N_INUSEBITS; idx = start / N_INUSEBITS; start %= N_INUSEBITS; @@ -679,11 +686,18 @@ chainlength(pmp, start, count) map &= ~((1 << start) - 1); if (map) { len = ffs(map) - 1 - start; - return (len > count ? count : len); + len = MIN(len, count); + if (start + len > pmp->pm_maxcluster) + len = pmp->pm_maxcluster - start + 1; + return (len); } len = N_INUSEBITS - start; - if (len >= count) - return (count); + if (len >= count) { + len = count; + if (start + len > pmp->pm_maxcluster) + len = pmp->pm_maxcluster - start + 1; + return (len); + } while (++idx <= max_idx) { if (len >= count) break; @@ -694,7 +708,10 @@ chainlength(pmp, start, count) } len += N_INUSEBITS; } - return (len > count ? count : len); + len = MIN(len, count); + if (start + len > pmp->pm_maxcluster) + len = pmp->pm_maxcluster - start + 1; + return (len); } /* @@ -961,6 +978,11 @@ fillinusemap(pmp) } if (bp != NULL) brelse(bp); + + for (cn = pmp->pm_maxcluster + 1; cn < (pmp->pm_maxcluster + + N_INUSEBITS) / N_INUSEBITS; cn++) + pmp->pm_inusemap[cn / N_INUSEBITS] |= 1 << (cn % N_INUSEBITS); + return (0); } From owner-svn-src-stable-10@freebsd.org Fri Nov 11 20:08:47 2016 Return-Path: Delivered-To: svn-src-stable-10@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 4BB22C3C9FA; Fri, 11 Nov 2016 20:08:47 +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 0307510DB; Fri, 11 Nov 2016 20:08: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 uABK8koS014307; Fri, 11 Nov 2016 20:08:46 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uABK8k29014305; Fri, 11 Nov 2016 20:08:46 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611112008.uABK8k29014305@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 11 Nov 2016 20:08:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308552 - stable/10/sys/fs/msdosfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 20:08:47 -0000 Author: kib Date: Fri Nov 11 20:08:45 2016 New Revision: 308552 URL: https://svnweb.freebsd.org/changeset/base/308552 Log: MFC r308025: Enable vn_io_fault() deadlock avoidance for msdosfs. Modified: stable/10/sys/fs/msdosfs/msdosfs_vfsops.c stable/10/sys/fs/msdosfs/msdosfs_vnops.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/fs/msdosfs/msdosfs_vfsops.c ============================================================================== --- stable/10/sys/fs/msdosfs/msdosfs_vfsops.c Fri Nov 11 20:06:07 2016 (r308551) +++ stable/10/sys/fs/msdosfs/msdosfs_vfsops.c Fri Nov 11 20:08:45 2016 (r308552) @@ -743,7 +743,7 @@ mountmsdosfs(struct vnode *devvp, struct mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum; MNT_ILOCK(mp); mp->mnt_flag |= MNT_LOCAL; - mp->mnt_kern_flag |= MNTK_USES_BCACHE; + mp->mnt_kern_flag |= MNTK_USES_BCACHE | MNTK_NO_IOPF; MNT_IUNLOCK(mp); if (pmp->pm_flags & MSDOSFS_LARGEFS) Modified: stable/10/sys/fs/msdosfs/msdosfs_vnops.c ============================================================================== --- stable/10/sys/fs/msdosfs/msdosfs_vnops.c Fri Nov 11 20:06:07 2016 (r308551) +++ stable/10/sys/fs/msdosfs/msdosfs_vnops.c Fri Nov 11 20:08:45 2016 (r308552) @@ -640,7 +640,7 @@ msdosfs_read(ap) diff = blsize - bp->b_resid; if (diff < n) n = diff; - error = uiomove(bp->b_data + on, (int) n, uio); + error = vn_io_fault_uiomove(bp->b_data + on, (int) n, uio); brelse(bp); } while (error == 0 && uio->uio_resid > 0 && n != 0); if (!isadir && (error == 0 || uio->uio_resid != orig_resid) && @@ -776,6 +776,12 @@ msdosfs_write(ap) * then no need to read data from disk. */ bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0, 0); + /* + * This call to vfs_bio_clrbuf() ensures that + * even if vn_io_fault_uiomove() below faults, + * garbage from the newly instantiated buffer + * is not exposed to the userspace via mmap(). + */ vfs_bio_clrbuf(bp); /* * Do the bmap now, since pcbmap needs buffers @@ -813,7 +819,7 @@ msdosfs_write(ap) /* * Copy the data from user space into the buf header. */ - error = uiomove(bp->b_data + croffset, n, uio); + error = vn_io_fault_uiomove(bp->b_data + croffset, n, uio); if (error) { brelse(bp); break; From owner-svn-src-stable-10@freebsd.org Sat Nov 12 17:30:56 2016 Return-Path: Delivered-To: svn-src-stable-10@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 B3919C3D89C; Sat, 12 Nov 2016 17:30:56 +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 815D21FE1; Sat, 12 Nov 2016 17:30:56 +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 uACHUtdr028332; Sat, 12 Nov 2016 17:30:55 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uACHUtu0028331; Sat, 12 Nov 2016 17:30:55 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201611121730.uACHUtu0028331@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Sat, 12 Nov 2016 17:30:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308572 - stable/10/sys/dev/sound/usb X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Nov 2016 17:30:56 -0000 Author: hselasky Date: Sat Nov 12 17:30:55 2016 New Revision: 308572 URL: https://svnweb.freebsd.org/changeset/base/308572 Log: MFC r308437 and r308461: Range check the jitter values to avoid bogus sample rate adjustments. The expected deviation should not be more than 1Hz per second. The USB v2.0 specification also mandates this requirement. Refer to chapter 5.12.4.2 about feedback. Allow higher sample rates to have more jitter than lower ones. PR: 208791 Modified: stable/10/sys/dev/sound/usb/uaudio.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/sound/usb/uaudio.c ============================================================================== --- stable/10/sys/dev/sound/usb/uaudio.c Sat Nov 12 17:27:28 2016 (r308571) +++ stable/10/sys/dev/sound/usb/uaudio.c Sat Nov 12 17:30:55 2016 (r308572) @@ -2084,9 +2084,23 @@ uaudio_chan_play_sync_callback(struct us * Use feedback value as fallback when there is no * recording channel: */ - if (ch->priv_sc->sc_rec_chan.num_alt == 0) - ch->jitter_curr = temp - sample_rate; + if (ch->priv_sc->sc_rec_chan.num_alt == 0) { + int32_t jitter_max = howmany(sample_rate, 16000); + /* + * Range check the jitter values to avoid + * bogus sample rate adjustments. The expected + * deviation should not be more than 1Hz per + * second. The USB v2.0 specification also + * mandates this requirement. Refer to chapter + * 5.12.4.2 about feedback. + */ + ch->jitter_curr = temp - sample_rate; + if (ch->jitter_curr > jitter_max) + ch->jitter_curr = jitter_max; + else if (ch->jitter_curr < -jitter_max) + ch->jitter_curr = -jitter_max; + } ch->feedback_rate = temp; break; From owner-svn-src-stable-10@freebsd.org Sat Nov 12 23:32:01 2016 Return-Path: Delivered-To: svn-src-stable-10@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 87B79C3D6C2; Sat, 12 Nov 2016 23:32:01 +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 62CAE1D32; Sat, 12 Nov 2016 23:32:01 +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 uACNW0QB076640; Sat, 12 Nov 2016 23:32:00 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uACNW0aT076639; Sat, 12 Nov 2016 23:32:00 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201611122332.uACNW0aT076639@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Sat, 12 Nov 2016 23:32:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308586 - stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Nov 2016 23:32:01 -0000 Author: mav Date: Sat Nov 12 23:32:00 2016 New Revision: 308586 URL: https://svnweb.freebsd.org/changeset/base/308586 Log: MFC r307318: MFV r307314: 6988 spa_sync() spends half its time in dmu_objset_do_userquota_updates Using a benchmark which creates 2 million files in one TXG, I observe that the thread running spa_sync() is on CPU almost the entire time we are syncing, and therefore can be a performance bottleneck. About 50% of the time in spa_sync() is in dmu_objset_do_userquota_updates(). The problem is that dmu_objset_do_userquota_updates() calls zap_increment_int(DMU_USERUSED_OBJECT) once for every file that was modified (or created). In this benchmark, all the files are owned by the same user/group, so all 2 million calls to zap_increment_int() are modifying the same entry in the zap. The same issue exists for the DMU_GROUPUSED_OBJECT. We should keep an in-memory map from user to space delta while we are syncing, and when we finish, iterate over the in-memory map and modify the ZAP once per entry. This reduces the number of calls to zap_increment_int() from "number of objects modified" to "number of owners/groups of modified files". This reduced the time spent in spa_sync() in the file create benchmark by ~33%, from 11 seconds to 7 seconds. Closes #107 Reviewed by: George Wilson Reviewed by: Steve Gonczi Reviewed by: Ned Bass Reviewed by: Jinshan Xiong Author: Matthew Ahrens openzfs/openzfs@5fc46359c569369d87728ca09f8705cdff6cc8e2 Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_objset.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_objset.c ============================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_objset.c Sat Nov 12 23:29:09 2016 (r308585) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_objset.c Sat Nov 12 23:32:00 2016 (r308586) @@ -1207,18 +1207,83 @@ dmu_objset_userused_enabled(objset_t *os DMU_USERUSED_DNODE(os) != NULL); } +typedef struct userquota_node { + uint64_t uqn_id; + int64_t uqn_delta; + avl_node_t uqn_node; +} userquota_node_t; + +typedef struct userquota_cache { + avl_tree_t uqc_user_deltas; + avl_tree_t uqc_group_deltas; +} userquota_cache_t; + +static int +userquota_compare(const void *l, const void *r) +{ + const userquota_node_t *luqn = l; + const userquota_node_t *ruqn = r; + + if (luqn->uqn_id < ruqn->uqn_id) + return (-1); + if (luqn->uqn_id > ruqn->uqn_id) + return (1); + return (0); +} + static void -do_userquota_update(objset_t *os, uint64_t used, uint64_t flags, - uint64_t user, uint64_t group, boolean_t subtract, dmu_tx_t *tx) +do_userquota_cacheflush(objset_t *os, userquota_cache_t *cache, dmu_tx_t *tx) +{ + void *cookie; + userquota_node_t *uqn; + + ASSERT(dmu_tx_is_syncing(tx)); + + cookie = NULL; + while ((uqn = avl_destroy_nodes(&cache->uqc_user_deltas, + &cookie)) != NULL) { + VERIFY0(zap_increment_int(os, DMU_USERUSED_OBJECT, + uqn->uqn_id, uqn->uqn_delta, tx)); + kmem_free(uqn, sizeof (*uqn)); + } + avl_destroy(&cache->uqc_user_deltas); + + cookie = NULL; + while ((uqn = avl_destroy_nodes(&cache->uqc_group_deltas, + &cookie)) != NULL) { + VERIFY0(zap_increment_int(os, DMU_GROUPUSED_OBJECT, + uqn->uqn_id, uqn->uqn_delta, tx)); + kmem_free(uqn, sizeof (*uqn)); + } + avl_destroy(&cache->uqc_group_deltas); +} + +static void +userquota_update_cache(avl_tree_t *avl, uint64_t id, int64_t delta) +{ + userquota_node_t search = { .uqn_id = id }; + avl_index_t idx; + + userquota_node_t *uqn = avl_find(avl, &search, &idx); + if (uqn == NULL) { + uqn = kmem_zalloc(sizeof (*uqn), KM_SLEEP); + uqn->uqn_id = id; + avl_insert(avl, uqn, idx); + } + uqn->uqn_delta += delta; +} + +static void +do_userquota_update(userquota_cache_t *cache, uint64_t used, uint64_t flags, + uint64_t user, uint64_t group, boolean_t subtract) { if ((flags & DNODE_FLAG_USERUSED_ACCOUNTED)) { int64_t delta = DNODE_SIZE + used; if (subtract) delta = -delta; - VERIFY3U(0, ==, zap_increment_int(os, DMU_USERUSED_OBJECT, - user, delta, tx)); - VERIFY3U(0, ==, zap_increment_int(os, DMU_GROUPUSED_OBJECT, - group, delta, tx)); + + userquota_update_cache(&cache->uqc_user_deltas, user, delta); + userquota_update_cache(&cache->uqc_group_deltas, group, delta); } } @@ -1227,9 +1292,15 @@ dmu_objset_do_userquota_updates(objset_t { dnode_t *dn; list_t *list = &os->os_synced_dnodes; + userquota_cache_t cache = { 0 }; ASSERT(list_head(list) == NULL || dmu_objset_userused_enabled(os)); + avl_create(&cache.uqc_user_deltas, userquota_compare, + sizeof (userquota_node_t), offsetof(userquota_node_t, uqn_node)); + avl_create(&cache.uqc_group_deltas, userquota_compare, + sizeof (userquota_node_t), offsetof(userquota_node_t, uqn_node)); + while (dn = list_head(list)) { int flags; ASSERT(!DMU_OBJECT_IS_SPECIAL(dn->dn_object)); @@ -1239,32 +1310,26 @@ dmu_objset_do_userquota_updates(objset_t /* Allocate the user/groupused objects if necessary. */ if (DMU_USERUSED_DNODE(os)->dn_type == DMU_OT_NONE) { - VERIFY(0 == zap_create_claim(os, + VERIFY0(zap_create_claim(os, DMU_USERUSED_OBJECT, DMU_OT_USERGROUP_USED, DMU_OT_NONE, 0, tx)); - VERIFY(0 == zap_create_claim(os, + VERIFY0(zap_create_claim(os, DMU_GROUPUSED_OBJECT, DMU_OT_USERGROUP_USED, DMU_OT_NONE, 0, tx)); } - /* - * We intentionally modify the zap object even if the - * net delta is zero. Otherwise - * the block of the zap obj could be shared between - * datasets but need to be different between them after - * a bprewrite. - */ - flags = dn->dn_id_flags; ASSERT(flags); if (flags & DN_ID_OLD_EXIST) { - do_userquota_update(os, dn->dn_oldused, dn->dn_oldflags, - dn->dn_olduid, dn->dn_oldgid, B_TRUE, tx); + do_userquota_update(&cache, + dn->dn_oldused, dn->dn_oldflags, + dn->dn_olduid, dn->dn_oldgid, B_TRUE); } if (flags & DN_ID_NEW_EXIST) { - do_userquota_update(os, DN_USED_BYTES(dn->dn_phys), + do_userquota_update(&cache, + DN_USED_BYTES(dn->dn_phys), dn->dn_phys->dn_flags, dn->dn_newuid, - dn->dn_newgid, B_FALSE, tx); + dn->dn_newgid, B_FALSE); } mutex_enter(&dn->dn_mtx); @@ -1285,6 +1350,7 @@ dmu_objset_do_userquota_updates(objset_t list_remove(list, dn); dnode_rele(dn, list); } + do_userquota_cacheflush(os, &cache, tx); } /* From owner-svn-src-stable-10@freebsd.org Sat Nov 12 23:36:28 2016 Return-Path: Delivered-To: svn-src-stable-10@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 CB94EC3D7FD; Sat, 12 Nov 2016 23:36:28 +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 9B09C1080; Sat, 12 Nov 2016 23:36:28 +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 uACNaR5w079174; Sat, 12 Nov 2016 23:36:27 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uACNaRNm079173; Sat, 12 Nov 2016 23:36:27 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201611122336.uACNaRNm079173@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Sat, 12 Nov 2016 23:36:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308588 - stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Nov 2016 23:36:28 -0000 Author: mav Date: Sat Nov 12 23:36:27 2016 New Revision: 308588 URL: https://svnweb.freebsd.org/changeset/base/308588 Log: MFC r308049: Improve few debugging log messages. Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c ============================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Sat Nov 12 23:35:40 2016 (r308587) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Sat Nov 12 23:36:27 2016 (r308588) @@ -225,7 +225,7 @@ vdev_geom_attach(struct g_provider *pp, } error = g_access(cp, 1, 0, 1); if (error != 0) { - ZFS_LOG(1, "%s(%d): g_access failed: %d\n", __func__, + ZFS_LOG(1, "%s(%d): g_access failed: %d", __func__, __LINE__, error); vdev_geom_detach(cp, B_FALSE); return (NULL); @@ -295,7 +295,7 @@ vdev_geom_detach(struct g_consumer *cp, g_topology_assert(); - ZFS_LOG(1, "Detaching consumer. Provider %s.", + ZFS_LOG(1, "Detaching from %s.", cp->provider && cp->provider->name ? cp->provider->name : "NULL"); vd = cp->private; @@ -309,7 +309,7 @@ vdev_geom_detach(struct g_consumer *cp, if (cp->acw > 0) g_access(cp, 0, -cp->acw, 0); if (cp->provider != NULL) { - ZFS_LOG(1, "Destroying consumer to %s.", + ZFS_LOG(1, "Destroying consumer for %s.", cp->provider->name ? cp->provider->name : "NULL"); g_detach(cp); } From owner-svn-src-stable-10@freebsd.org Sat Nov 12 23:38:05 2016 Return-Path: Delivered-To: svn-src-stable-10@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 88B63C3D919; Sat, 12 Nov 2016 23:38:05 +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 604581373; Sat, 12 Nov 2016 23:38:05 +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 uACNc4cx079341; Sat, 12 Nov 2016 23:38:04 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uACNc4Gs079340; Sat, 12 Nov 2016 23:38:04 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201611122338.uACNc4Gs079340@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Sat, 12 Nov 2016 23:38:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308590 - stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Nov 2016 23:38:05 -0000 Author: mav Date: Sat Nov 12 23:38:04 2016 New Revision: 308590 URL: https://svnweb.freebsd.org/changeset/base/308590 Log: MFC r308051: Matching GUIDs, handle possible race on vdev detach. In case of vdev detach, causing top level mirror vdev destruction, leaf vdev changes its GUID to one of the destroyed mirror, that creates race condition when GUID in vdev label may not match one in the pool config. This change replicates logic nuance of vdev_validate() by adding special exception, matching the vdev GUID against the top level vdev GUID. Since this exception is not completely reliable (may give false positives if we fail to erase label on detached vdev), use it only as last resort. Quick way to reproduce this scenario now is detach vdev from a pool with enabled autoextend. During vdev detach autoextend logic tries to reopen remaining vdev, that always fails now since in-memory configuration is already updated, while on-disk labels are not yet. Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c ============================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Sat Nov 12 23:37:26 2016 (r308589) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Sat Nov 12 23:38:04 2016 (r308590) @@ -340,14 +340,6 @@ vdev_geom_close_locked(vdev_t *vd) vdev_geom_detach(cp, B_TRUE); } -static void -nvlist_get_guids(nvlist_t *list, uint64_t *pguid, uint64_t *vguid) -{ - - (void) nvlist_lookup_uint64(list, ZPOOL_CONFIG_GUID, vguid); - (void) nvlist_lookup_uint64(list, ZPOOL_CONFIG_POOL_GUID, pguid); -} - /* * Issue one or more bios to the vdev in parallel * cmds, datas, offsets, errors, and sizes are arrays of length ncmds. Each IO @@ -608,58 +600,69 @@ vdev_geom_read_pool_label(const char *na return (*count > 0 ? 0 : ENOENT); } -static void -vdev_geom_read_guids(struct g_consumer *cp, uint64_t *pguid, uint64_t *vguid) -{ - nvlist_t *config; - - g_topology_assert_not(); - - *pguid = 0; - *vguid = 0; - if (vdev_geom_read_config(cp, &config) == 0) { - nvlist_get_guids(config, pguid, vguid); - nvlist_free(config); - } -} +enum match { + NO_MATCH, + TOP_MATCH, + FULL_MATCH +}; -static boolean_t +static enum match vdev_attach_ok(vdev_t *vd, struct g_provider *pp) { - uint64_t pool_guid; - uint64_t vdev_guid; - struct g_consumer *zcp; - boolean_t pool_ok; - boolean_t vdev_ok; + nvlist_t *config; + uint64_t pool_guid, top_guid, vdev_guid; + struct g_consumer *cp; - zcp = vdev_geom_attach(pp, NULL); - if (zcp == NULL) { + cp = vdev_geom_attach(pp, NULL); + if (cp == NULL) { ZFS_LOG(1, "Unable to attach tasting instance to %s.", pp->name); - return (B_FALSE); + return (NO_MATCH); } g_topology_unlock(); - vdev_geom_read_guids(zcp, &pool_guid, &vdev_guid); + if (vdev_geom_read_config(cp, &config) != 0) { + g_topology_lock(); + vdev_geom_detach(cp, B_TRUE); + ZFS_LOG(1, "Unable to read config from %s.", pp->name); + return (NO_MATCH); + } g_topology_lock(); - vdev_geom_detach(zcp, B_TRUE); + vdev_geom_detach(cp, B_TRUE); - /* - * Check that the label's vdev guid matches the desired guid. If the - * label has a pool guid, check that it matches too. (Inactive spares - * and L2ARCs do not have any pool guid in the label.) + pool_guid = 0; + (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &pool_guid); + top_guid = 0; + (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_TOP_GUID, &top_guid); + vdev_guid = 0; + (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID, &vdev_guid); + nvlist_free(config); + + /* + * Check that the label's pool guid matches the desired guid. + * Inactive spares and L2ARCs do not have any pool guid in the label. */ - if ((pool_guid == 0 || pool_guid == spa_guid(vd->vdev_spa)) && - vdev_guid == vd->vdev_guid) { - ZFS_LOG(1, "guids match for provider %s.", vd->vdev_path); - return (B_TRUE); - } else { - ZFS_LOG(1, "guid mismatch for provider %s: " - "%ju:%ju != %ju:%ju.", vd->vdev_path, - (uintmax_t)spa_guid(vd->vdev_spa), - (uintmax_t)vd->vdev_guid, - (uintmax_t)pool_guid, (uintmax_t)vdev_guid); - return (B_FALSE); + if (pool_guid != 0 && pool_guid != spa_guid(vd->vdev_spa)) { + ZFS_LOG(1, "pool guid mismatch for provider %s: %ju != %ju.", + pp->name, + (uintmax_t)spa_guid(vd->vdev_spa), (uintmax_t)pool_guid); + return (NO_MATCH); } + + /* + * Check that the label's vdev guid matches the desired guid. + * The second condition handles possible race on vdev detach, when + * remaining vdev receives GUID of destroyed top level mirror vdev. + */ + if (vdev_guid == vd->vdev_guid) { + ZFS_LOG(1, "guids match for provider %s.", pp->name); + return (FULL_MATCH); + } else if (top_guid == vd->vdev_guid && vd == vd->vdev_top) { + ZFS_LOG(1, "top vdev guid match for provider %s.", pp->name); + return (TOP_MATCH); + } + ZFS_LOG(1, "vdev guid mismatch for provider %s: %ju != %ju.", + pp->name, (uintmax_t)vd->vdev_guid, (uintmax_t)vdev_guid); + return (NO_MATCH); } static struct g_consumer * @@ -669,6 +672,7 @@ vdev_geom_attach_by_guids(vdev_t *vd) struct g_geom *gp; struct g_provider *pp; struct g_consumer *cp; + enum match m; g_topology_assert(); @@ -680,23 +684,26 @@ vdev_geom_attach_by_guids(vdev_t *vd) if (gp->flags & G_GEOM_WITHER) continue; LIST_FOREACH(pp, &gp->provider, provider) { - if (!vdev_attach_ok(vd, pp)) + m = vdev_attach_ok(vd, pp); + if (m == NO_MATCH) continue; + if (cp != NULL) { + if (m == FULL_MATCH) + vdev_geom_detach(cp, B_TRUE); + else + continue; + } cp = vdev_geom_attach(pp, vd); if (cp == NULL) { printf("ZFS WARNING: Unable to " "attach to %s.\n", pp->name); continue; } - break; + if (m == FULL_MATCH) + return (cp); } - if (cp != NULL) - break; } - if (cp != NULL) - break; } -end: return (cp); } @@ -744,7 +751,7 @@ vdev_geom_open_by_path(vdev_t *vd, int c pp = g_provider_by_name(vd->vdev_path + sizeof("/dev/") - 1); if (pp != NULL) { ZFS_LOG(1, "Found provider by name %s.", vd->vdev_path); - if (!check_guid || vdev_attach_ok(vd, pp)) + if (!check_guid || vdev_attach_ok(vd, pp) == FULL_MATCH) cp = vdev_geom_attach(pp, vd); } From owner-svn-src-stable-10@freebsd.org Sat Nov 12 23:40:41 2016 Return-Path: Delivered-To: svn-src-stable-10@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 89B7AC3DBC9; Sat, 12 Nov 2016 23:40:41 +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 589A517DC; Sat, 12 Nov 2016 23:40:41 +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 uACNeev3081745; Sat, 12 Nov 2016 23:40:40 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uACNeeWt081744; Sat, 12 Nov 2016 23:40:40 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201611122340.uACNeeWt081744@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Sat, 12 Nov 2016 23:40:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308592 - stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Nov 2016 23:40:41 -0000 Author: mav Date: Sat Nov 12 23:40:40 2016 New Revision: 308592 URL: https://svnweb.freebsd.org/changeset/base/308592 Log: MFC r308055: Add vdev_reopening support to vdev_geom. It allows to avoid extra GEOM providers flapping without significant need. Since GEOM got resize support, we don't need to reopen provider to get new size. If provider was orphaned and no longer valid, ZFS should already know that, and in such case reopen should be done in full as expected. Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c ============================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Sat Nov 12 23:39:08 2016 (r308591) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c Sat Nov 12 23:40:40 2016 (r308592) @@ -778,7 +778,14 @@ vdev_geom_open(vdev_t *vd, uint64_t *psi return (EINVAL); } - vd->vdev_tsd = NULL; + /* + * Reopen the device if it's not currently open. Otherwise, + * just update the physical size of the device. + */ + if ((cp = vd->vdev_tsd) != NULL) { + ASSERT(vd->vdev_reopening); + goto skip_open; + } DROP_GIANT(); g_topology_lock(); @@ -863,6 +870,7 @@ vdev_geom_open(vdev_t *vd, uint64_t *psi vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED; return (error); } +skip_open: pp = cp->provider; /* @@ -898,6 +906,9 @@ static void vdev_geom_close(vdev_t *vd) { + if (vd->vdev_reopening) + return; + DROP_GIANT(); g_topology_lock(); vdev_geom_close_locked(vd); From owner-svn-src-stable-10@freebsd.org Sat Nov 12 23:52:40 2016 Return-Path: Delivered-To: svn-src-stable-10@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 8C7B4C3E022; Sat, 12 Nov 2016 23:52:40 +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 44F2210DA; Sat, 12 Nov 2016 23:52:40 +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 uACNqdfQ087159; Sat, 12 Nov 2016 23:52:39 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uACNqdRu087158; Sat, 12 Nov 2016 23:52:39 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201611122352.uACNqdRu087158@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Sat, 12 Nov 2016 23:52:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308594 - stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Nov 2016 23:52:40 -0000 Author: mav Date: Sat Nov 12 23:52:39 2016 New Revision: 308594 URL: https://svnweb.freebsd.org/changeset/base/308594 Log: MFC r308169: Pass to zvol_log_truncate() same sync values as to zvol_log_write(). Surplus marking of TX_TRUNCATE records as sync could result in putting them into ZIL before previous writes if ones were async. Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c ============================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Sat Nov 12 23:50:48 2016 (r308593) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Sat Nov 12 23:52:39 2016 (r308594) @@ -1649,7 +1649,7 @@ zvol_strategy(struct bio *bp) if (error != 0) { dmu_tx_abort(tx); } else { - zvol_log_truncate(zv, tx, off, resid, B_TRUE); + zvol_log_truncate(zv, tx, off, resid, sync); dmu_tx_commit(tx); error = dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, off, resid); @@ -3093,9 +3093,9 @@ zvol_d_ioctl(struct cdev *dev, u_long cm { zvol_state_t *zv; rl_t *rl; - off_t offset, length, chunk; + off_t offset, length; int i, error; - u_int u; + boolean_t sync; zv = dev->si_drv2; @@ -3133,15 +3133,17 @@ zvol_d_ioctl(struct cdev *dev, u_long cm dmu_tx_t *tx = dmu_tx_create(zv->zv_objset); error = dmu_tx_assign(tx, TXG_WAIT); if (error != 0) { + sync = FALSE; dmu_tx_abort(tx); } else { - zvol_log_truncate(zv, tx, offset, length, B_TRUE); + sync = (zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS); + zvol_log_truncate(zv, tx, offset, length, sync); dmu_tx_commit(tx); error = dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, offset, length); } zfs_range_unlock(rl); - if (zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS) + if (sync) zil_commit(zv->zv_zilog, ZVOL_OBJ); break; case DIOCGSTRIPESIZE: From owner-svn-src-stable-10@freebsd.org Sat Nov 12 23:58:09 2016 Return-Path: Delivered-To: svn-src-stable-10@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 07B63C3E2E0; Sat, 12 Nov 2016 23:58:09 +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 D53DF145B; Sat, 12 Nov 2016 23:58:08 +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 uACNw8pO087472; Sat, 12 Nov 2016 23:58:08 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uACNw7Cd087469; Sat, 12 Nov 2016 23:58:07 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201611122358.uACNw7Cd087469@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Sat, 12 Nov 2016 23:58:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308596 - in stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Nov 2016 23:58:09 -0000 Author: mav Date: Sat Nov 12 23:58:07 2016 New Revision: 308596 URL: https://svnweb.freebsd.org/changeset/base/308596 Log: MFC r308173: Fix ZIL records ordering when ZVOL opened both with and without FSYNC. Before this an earlier writes to a ZVOL opened without FSYNC could get to ZIL after later writes to the same ZVOL opened with FSYNC. Fix this by replicating functionality of ZPL (zv_sync_cnt equivalent to z_sync_cnt), marking all log records sync if anybody opened the ZVOL with FSYNC. Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h ============================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h Sat Nov 12 23:53:37 2016 (r308595) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h Sat Nov 12 23:58:07 2016 (r308596) @@ -405,6 +405,7 @@ extern itx_t *zil_itx_create(uint64_t tx extern void zil_itx_destroy(itx_t *itx); extern void zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx); +extern void zil_async_to_sync(zilog_t *zilog, uint64_t oid); extern void zil_commit(zilog_t *zilog, uint64_t oid); extern int zil_vdev_offline(const char *osname, void *txarg); Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c ============================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c Sat Nov 12 23:53:37 2016 (r308595) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c Sat Nov 12 23:58:07 2016 (r308596) @@ -93,8 +93,6 @@ SYSCTL_INT(_vfs_zfs_trim, OID_AUTO, enab static kmem_cache_t *zil_lwb_cache; -static void zil_async_to_sync(zilog_t *zilog, uint64_t foid); - #define LWB_EMPTY(lwb) ((BP_GET_LSIZE(&lwb->lwb_blk) - \ sizeof (zil_chain_t)) == (lwb->lwb_sz - lwb->lwb_nused)) @@ -1415,7 +1413,7 @@ zil_get_commit_list(zilog_t *zilog) /* * Move the async itxs for a specified object to commit into sync lists. */ -static void +void zil_async_to_sync(zilog_t *zilog, uint64_t foid) { uint64_t otxg, txg; Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c ============================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Sat Nov 12 23:53:37 2016 (r308595) +++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Sat Nov 12 23:58:07 2016 (r308596) @@ -167,6 +167,7 @@ typedef struct zvol_state { uint32_t zv_open_count[OTYPCNT]; /* open counts */ #endif uint32_t zv_total_opens; /* total open count */ + uint32_t zv_sync_cnt; /* synchronous open count */ zilog_t *zv_zilog; /* ZIL handle */ list_t zv_extents; /* List of extents for dump */ znode_t zv_znode; /* for range locking */ @@ -1416,7 +1417,9 @@ zvol_log_write(zvol_state_t *zv, dmu_tx_ BP_ZERO(&lr->lr_blkptr); itx->itx_private = zv; - itx->itx_sync = sync; + + if (!sync && (zv->zv_sync_cnt == 0)) + itx->itx_sync = B_FALSE; zil_itx_assign(zilog, itx, tx); @@ -2058,7 +2061,7 @@ zvol_log_truncate(zvol_state_t *zv, dmu_ lr->lr_offset = off; lr->lr_length = len; - itx->itx_sync = sync; + itx->itx_sync = (sync || zv->zv_sync_cnt != 0); zil_itx_assign(zilog, itx, tx); } @@ -3050,6 +3053,11 @@ zvol_d_open(struct cdev *dev, int flags, #endif zv->zv_total_opens++; + if (flags & (FSYNC | FDSYNC)) { + zv->zv_sync_cnt++; + if (zv->zv_sync_cnt == 1) + zil_async_to_sync(zv->zv_zilog, ZVOL_OBJ); + } mutex_exit(&zfsdev_state_lock); return (err); out: @@ -3080,6 +3088,8 @@ zvol_d_close(struct cdev *dev, int flags * You may get multiple opens, but only one close. */ zv->zv_total_opens--; + if (flags & (FSYNC | FDSYNC)) + zv->zv_sync_cnt--; if (zv->zv_total_opens == 0) zvol_last_close(zv);