Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/hyperv hvn(4) can be added and deleted dynamically.



details:   https://anonhg.NetBSD.org/src/rev/447bacc70490
branches:  trunk
changeset: 466061:447bacc70490
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Tue Dec 10 12:20:20 2019 +0000

description:
hvn(4) can be added and deleted dynamically.

diffstat:

 sys/dev/hyperv/hyperv_common.c |   13 +-
 sys/dev/hyperv/hypervvar.h     |    6 +-
 sys/dev/hyperv/if_hvn.c        |   57 +++--
 sys/dev/hyperv/vmbus.c         |  378 ++++++++++++++++++++++------------------
 sys/dev/hyperv/vmbusvar.h      |   35 +--
 5 files changed, 271 insertions(+), 218 deletions(-)

diffs (truncated from 948 to 300 lines):

diff -r 3bedbd420af2 -r 447bacc70490 sys/dev/hyperv/hyperv_common.c
--- a/sys/dev/hyperv/hyperv_common.c    Tue Dec 10 12:08:52 2019 +0000
+++ b/sys/dev/hyperv/hyperv_common.c    Tue Dec 10 12:20:20 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hyperv_common.c,v 1.4 2019/12/07 11:45:45 nonaka Exp $ */
+/*     $NetBSD: hyperv_common.c,v 1.5 2019/12/10 12:20:20 nonaka Exp $ */
 
 /*-
  * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hyperv_common.c,v 1.4 2019/12/07 11:45:45 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv_common.c,v 1.5 2019/12/10 12:20:20 nonaka Exp $");
 
 #include "hyperv.h"
 
@@ -111,17 +111,18 @@
  */
 void *
 hyperv_dma_alloc(bus_dma_tag_t dmat, struct hyperv_dma *dma, bus_size_t size,
-    bus_size_t alignment, bus_size_t boundary, int nsegs)
+    bus_size_t alignment, bus_size_t boundary, int nsegs, int flags)
 {
-       const int kmemflags = cold ? KM_NOSLEEP : KM_SLEEP;
-       const int dmaflags = cold ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK;
+       const int waitok = (flags & HYPERV_DMA_NOSLEEP) != HYPERV_DMA_NOSLEEP;
+       const int kmemflags = waitok ? KM_SLEEP: KM_NOSLEEP;
+       const int dmaflags = waitok ? BUS_DMA_WAITOK : BUS_DMA_NOWAIT;
        int rseg, error;
 
        KASSERT(dma != NULL);
        KASSERT(dma->segs == NULL);
        KASSERT(nsegs > 0);
 
-       dma->segs = kmem_zalloc(sizeof(*dma->segs) * nsegs, kmemflags);
+       dma->segs = kmem_intr_zalloc(sizeof(*dma->segs) * nsegs, kmemflags);
        if (dma->segs == NULL)
                return NULL;
 
diff -r 3bedbd420af2 -r 447bacc70490 sys/dev/hyperv/hypervvar.h
--- a/sys/dev/hyperv/hypervvar.h        Tue Dec 10 12:08:52 2019 +0000
+++ b/sys/dev/hyperv/hypervvar.h        Tue Dec 10 12:20:20 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hypervvar.h,v 1.3 2019/12/07 11:45:45 nonaka Exp $     */
+/*     $NetBSD: hypervvar.h,v 1.4 2019/12/10 12:20:20 nonaka Exp $     */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -108,8 +108,10 @@
        return dma->map->dm_segs[0].ds_addr;
 }
 
+#define HYPERV_DMA_SLEEPOK     0
+#define HYPERV_DMA_NOSLEEP     __BIT(0)
 void *hyperv_dma_alloc(bus_dma_tag_t, struct hyperv_dma *, bus_size_t,
-    bus_size_t, bus_size_t, int);
+    bus_size_t, bus_size_t, int, int);
 void hyperv_dma_free(bus_dma_tag_t, struct hyperv_dma *);
 
 #endif /* _KERNEL */
diff -r 3bedbd420af2 -r 447bacc70490 sys/dev/hyperv/if_hvn.c
--- a/sys/dev/hyperv/if_hvn.c   Tue Dec 10 12:08:52 2019 +0000
+++ b/sys/dev/hyperv/if_hvn.c   Tue Dec 10 12:20:20 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_hvn.c,v 1.12 2019/12/10 11:19:25 nonaka Exp $       */
+/*     $NetBSD: if_hvn.c,v 1.13 2019/12/10 12:20:20 nonaka Exp $       */
 /*     $OpenBSD: if_hvn.c,v 1.39 2018/03/11 14:31:34 mikeb Exp $       */
 
 /*-
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.12 2019/12/10 11:19:25 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.13 2019/12/10 12:20:20 nonaka Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -249,8 +249,6 @@
        aprint_naive("\n");
        aprint_normal(": Hyper-V NetVSC\n");
 
-       strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
-
        if (hvn_nvs_attach(sc)) {
                aprint_error_dev(self, "failed to init NVSP\n");
                return;
@@ -263,9 +261,10 @@
 
        if (hvn_tx_ring_create(sc)) {
                aprint_error_dev(self, "failed to create Tx ring\n");
-               goto fail1;
+               goto fail2;
        }
 
+       strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
        ifp->if_softc = sc;
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
        ifp->if_ioctl = hvn_ioctl;
@@ -300,14 +299,14 @@
        error = if_initialize(ifp);
        if (error) {
                aprint_error_dev(self, "if_initialize failed(%d)\n", error);
-               goto fail2;
+               goto fail3;
        }
        sc->sc_ipq = if_percpuq_create(ifp);
        if_deferred_start_init(ifp, NULL);
 
        if (hvn_rndis_attach(sc)) {
                aprint_error_dev(self, "failed to init RNDIS\n");
-               goto fail1;
+               goto fail3;
        }
 
        aprint_normal_dev(self, "NVS %d.%d NDIS %d.%d\n",
@@ -316,13 +315,13 @@
 
        if (hvn_set_capabilities(sc)) {
                aprint_error_dev(self, "failed to setup offloading\n");
-               goto fail2;
+               goto fail4;
        }
 
        if (hvn_get_lladdr(sc, enaddr)) {
                aprint_error_dev(self,
                    "failed to obtain an ethernet address\n");
-               goto fail2;
+               goto fail4;
        }
        aprint_normal_dev(self, "Ethernet address %s\n", ether_sprintf(enaddr));
 
@@ -337,10 +336,11 @@
        SET(sc->sc_flags, HVN_SCF_ATTACHED);
        return;
 
-fail2: hvn_rndis_detach(sc);
-fail1: hvn_rx_ring_destroy(sc);
-       hvn_tx_ring_destroy(sc);
-       hvn_nvs_detach(sc);
+fail4: hvn_rndis_detach(sc);
+       if_percpuq_destroy(sc->sc_ipq);
+fail3: hvn_tx_ring_destroy(sc);
+fail2: hvn_rx_ring_destroy(sc);
+fail1: hvn_nvs_detach(sc);
 }
 
 static int
@@ -352,7 +352,8 @@
        if (!ISSET(sc->sc_flags, HVN_SCF_ATTACHED))
                return 0;
 
-       hvn_stop(ifp, 1);
+       if (ifp->if_flags & IFF_RUNNING)
+               hvn_stop(ifp, 1);
 
        pmf_device_deregister(self);
 
@@ -693,7 +694,8 @@
        else
                sc->sc_rx_size = 16 * 1024 * 1024;      /* 16MB */
        sc->sc_rx_ring = hyperv_dma_alloc(sc->sc_dmat, &sc->sc_rx_dma,
-           sc->sc_rx_size, PAGE_SIZE, PAGE_SIZE, sc->sc_rx_size / PAGE_SIZE);
+           sc->sc_rx_size, PAGE_SIZE, PAGE_SIZE, sc->sc_rx_size / PAGE_SIZE,
+           HYPERV_DMA_SLEEPOK);
        if (sc->sc_rx_ring == NULL) {
                DPRINTF("%s: failed to allocate Rx ring buffer\n",
                    device_xname(sc->sc_dev));
@@ -735,7 +737,7 @@
                sc->sc_rx_hndl = 0;
        }
        if (sc->sc_rx_ring) {
-               kmem_free(sc->sc_rx_ring, sc->sc_rx_size);
+               hyperv_dma_free(sc->sc_dmat, &sc->sc_rx_dma);
                sc->sc_rx_ring = NULL;
        }
        return -1;
@@ -761,10 +763,9 @@
        delay(100);
 
        vmbus_handle_free(sc->sc_chan, sc->sc_rx_hndl);
-
        sc->sc_rx_hndl = 0;
 
-       kmem_free(sc->sc_rx_ring, sc->sc_rx_size);
+       hyperv_dma_free(sc->sc_dmat, &sc->sc_rx_dma);
        sc->sc_rx_ring = NULL;
 
        return 0;
@@ -854,25 +855,25 @@
                txd->txd_dmap = NULL;
                if (txd->txd_buf == NULL)
                        continue;
-               m_free(txd->txd_buf);
+               m_freem(txd->txd_buf);
                txd->txd_buf = NULL;
        }
-       if (sc->sc_tx_rmap) {
+       if (sc->sc_tx_rmap != NULL) {
                bus_dmamap_sync(sc->sc_dmat, sc->sc_tx_rmap,
-                   0, txd->txd_dmap->dm_mapsize,
+                   0, sc->sc_tx_rmap->dm_mapsize,
                    BUS_DMASYNC_POSTWRITE);
                bus_dmamap_unload(sc->sc_dmat, sc->sc_tx_rmap);
                bus_dmamap_destroy(sc->sc_dmat, sc->sc_tx_rmap);
+               sc->sc_tx_rmap = NULL;
        }
-       if (sc->sc_tx_msgs) {
+       if (sc->sc_tx_msgs != NULL) {
                size_t msgsize = roundup(HVN_RNDIS_PKT_LEN, 128);
 
                bus_dmamem_unmap(sc->sc_dmat, sc->sc_tx_msgs,
                    msgsize * HVN_TX_DESC);
                bus_dmamem_free(sc->sc_dmat, &sc->sc_tx_mseg, 1);
+               sc->sc_tx_msgs = NULL;
        }
-       sc->sc_tx_rmap = NULL;
-       sc->sc_tx_msgs = NULL;
 }
 
 static int
@@ -1414,6 +1415,10 @@
                    "RNDIS operation %u send error %d\n", hdr->rm_type, rv);
                return rv;
        }
+       if (vmbus_channel_is_revoked(sc->sc_chan)) {
+               /* No response */
+               return 0;
+       }
 
        bus_dmamap_sync(sc->sc_dmat, rc->rc_dmap, 0, PAGE_SIZE,
            BUS_DMASYNC_POSTWRITE);
@@ -1843,4 +1848,8 @@
                    device_xname(sc->sc_dev), rv);
        }
        hvn_free_cmd(sc, rc);
+
+       mutex_destroy(&sc->sc_cntl_sqlck);
+       mutex_destroy(&sc->sc_cntl_cqlck);
+       mutex_destroy(&sc->sc_cntl_fqlck);
 }
diff -r 3bedbd420af2 -r 447bacc70490 sys/dev/hyperv/vmbus.c
--- a/sys/dev/hyperv/vmbus.c    Tue Dec 10 12:08:52 2019 +0000
+++ b/sys/dev/hyperv/vmbus.c    Tue Dec 10 12:20:20 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmbus.c,v 1.7 2019/12/07 11:45:45 nonaka Exp $ */
+/*     $NetBSD: vmbus.c,v 1.8 2019/12/10 12:20:20 nonaka Exp $ */
 /*     $OpenBSD: hyperv.c,v 1.43 2017/06/27 13:56:15 mikeb Exp $       */
 
 /*-
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.7 2019/12/07 11:45:45 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.8 2019/12/10 12:20:20 nonaka Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -46,6 +46,7 @@
 #include <sys/cpu.h>
 #include <sys/intr.h>
 #include <sys/kmem.h>
+#include <sys/kthread.h>
 #include <sys/module.h>
 #include <sys/mutex.h>
 #include <sys/xcall.h>
@@ -62,6 +63,7 @@
 #define HCF_NOREPLY    0x0004
 
 static void    vmbus_attach_deferred(device_t);
+static int     vmbus_attach_print(void *, const char *);
 static int     vmbus_alloc_dma(struct vmbus_softc *);
 static void    vmbus_free_dma(struct vmbus_softc *);
 static int     vmbus_init_interrupts(struct vmbus_softc *);
@@ -92,16 +94,22 @@
                    struct vmbus_chanmsg_hdr *);
 static int     vmbus_channel_scan(struct vmbus_softc *);
 static void    vmbus_channel_cpu_default(struct vmbus_channel *);
-static void    vmbus_process_offer(struct vmbus_softc *, struct vmbus_offer *);
+static void    vmbus_process_offer(struct vmbus_softc *,
+                   struct vmbus_chanmsg_choffer *);
+static void    vmbus_process_rescind(struct vmbus_softc *,
+                   struct vmbus_chanmsg_chrescind *);
 static struct vmbus_channel *
                vmbus_channel_lookup(struct vmbus_softc *, uint32_t);
 static int     vmbus_channel_ring_create(struct vmbus_channel *, uint32_t);
 static void    vmbus_channel_ring_destroy(struct vmbus_channel *);
+static void    vmbus_channel_detach(struct vmbus_channel *);
 static void    vmbus_channel_pause(struct vmbus_channel *);
 static uint32_t        vmbus_channel_unpause(struct vmbus_channel *);
 static uint32_t        vmbus_channel_ready(struct vmbus_channel *);
-static int     vmbus_attach_icdevs(struct vmbus_softc *);
-static int     vmbus_attach_devices(struct vmbus_softc *);
+static void    vmbus_devq_enqueue(struct vmbus_softc *, int,
+                   struct vmbus_channel *);
+static void    vmbus_process_devq(void *);
+static void    vmbus_devq_thread(void *);



Home | Main Index | Thread Index | Old Index