Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/hyperv Improve Hyper-V support.



details:   https://anonhg.NetBSD.org/src/rev/5d4c001e619c
branches:  trunk
changeset: 366250:5d4c001e619c
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Fri May 20 13:55:16 2022 +0000

description:
Improve Hyper-V support.

vmbus(4):
 - Added support for multichannel.

hvn(4):
 - Added support for multichannel.
 - Added support for change MTU.
 - Added support for TX aggregation.
 - Improve VLAN support.
 - Improve checksum offload support.

diffstat:

 sys/arch/x86/x86/hyperv.c      |     6 +-
 sys/dev/hyperv/files.hyperv    |     7 +-
 sys/dev/hyperv/hyperv_common.c |    25 +-
 sys/dev/hyperv/hypervreg.h     |     3 +-
 sys/dev/hyperv/hypervvar.h     |     7 +-
 sys/dev/hyperv/if_hvn.c        |  4617 ++++++++++++++++++++++++++++++++++-----
 sys/dev/hyperv/if_hvnreg.h     |    19 +-
 sys/dev/hyperv/vmbus.c         |   230 +-
 sys/dev/hyperv/vmbusvar.h      |    16 +-
 9 files changed, 4234 insertions(+), 696 deletions(-)

diffs (truncated from 6346 to 300 lines):

diff -r 098dc957d316 -r 5d4c001e619c sys/arch/x86/x86/hyperv.c
--- a/sys/arch/x86/x86/hyperv.c Fri May 20 07:47:16 2022 +0000
+++ b/sys/arch/x86/x86/hyperv.c Fri May 20 13:55:16 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hyperv.c,v 1.14 2021/12/23 04:06:51 yamaguchi Exp $    */
+/*     $NetBSD: hyperv.c,v 1.15 2022/05/20 13:55:16 nonaka Exp $       */
 
 /*-
  * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
@@ -33,7 +33,7 @@
  */
 #include <sys/cdefs.h>
 #ifdef __KERNEL_RCSID
-__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.14 2021/12/23 04:06:51 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.15 2022/05/20 13:55:16 nonaka Exp $");
 #endif
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/sys/dev/hyperv/vmbus/hyperv.c 331757 2018-03-30 02:25:12Z emaste $");
@@ -106,8 +106,6 @@
 
 static u_int   hyperv_get_timecount(struct timecounter *);
 
-static u_int hyperv_ver_major;
-
 static u_int hyperv_features;          /* CPUID_HV_MSR_ */
 static u_int hyperv_recommends;
 
diff -r 098dc957d316 -r 5d4c001e619c sys/dev/hyperv/files.hyperv
--- a/sys/dev/hyperv/files.hyperv       Fri May 20 07:47:16 2022 +0000
+++ b/sys/dev/hyperv/files.hyperv       Fri May 20 13:55:16 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.hyperv,v 1.2 2019/05/24 14:28:48 nonaka Exp $
+#      $NetBSD: files.hyperv,v 1.3 2022/05/20 13:55:17 nonaka Exp $
 
 define hypervvmbus {}
 device vmbus: hypervvmbus
@@ -14,6 +14,11 @@
 device hvn: ether, ifnet, arp
 attach hvn at hypervvmbus
 file   dev/hyperv/if_hvn.c             hvn
+defparam opt_if_hvn.h  HVN_UDP_CKSUM_FIXUP_MTU_DEFAULT
+                       HVN_CHANNEL_MAX_COUNT_DEFAULT
+                       HVN_CHANNEL_COUNT_DEFAULT
+                       HVN_TX_RING_COUNT_DEFAULT
+                       HVN_LINK_STATE_CHANGE_DELAY
 
 device hvs: scsi
 attach hvs at hypervvmbus
diff -r 098dc957d316 -r 5d4c001e619c sys/dev/hyperv/hyperv_common.c
--- a/sys/dev/hyperv/hyperv_common.c    Fri May 20 07:47:16 2022 +0000
+++ b/sys/dev/hyperv/hyperv_common.c    Fri May 20 13:55:16 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hyperv_common.c,v 1.5 2019/12/10 12:20:20 nonaka Exp $ */
+/*     $NetBSD: hyperv_common.c,v 1.6 2022/05/20 13:55:17 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.5 2019/12/10 12:20:20 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv_common.c,v 1.6 2022/05/20 13:55:17 nonaka Exp $");
 
 #include "hyperv.h"
 
@@ -42,6 +42,7 @@
 #include <dev/hyperv/hypervreg.h>
 #include <dev/hyperv/hypervvar.h>
 
+u_int hyperv_ver_major;
 hyperv_tc64_t hyperv_tc64;
 
 int            hyperv_nullop(void);
@@ -111,46 +112,40 @@
  */
 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, int flags)
+    bus_size_t alignment, bus_size_t boundary, int nsegs)
 {
-       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_intr_zalloc(sizeof(*dma->segs) * nsegs, kmemflags);
-       if (dma->segs == NULL)
-               return NULL;
-
+       dma->segs = kmem_zalloc(sizeof(*dma->segs) * nsegs, KM_SLEEP);
        dma->nsegs = nsegs;
 
        error = bus_dmamem_alloc(dmat, size, alignment, boundary, dma->segs,
-           nsegs, &rseg, dmaflags);
+           nsegs, &rseg, BUS_DMA_WAITOK);
        if (error) {
                printf("%s: bus_dmamem_alloc failed: error=%d\n",
                    __func__, error);
                goto fail1;
        }
        error = bus_dmamem_map(dmat, dma->segs, rseg, size, &dma->addr,
-           dmaflags);
+           BUS_DMA_WAITOK);
        if (error) {
                printf("%s: bus_dmamem_map failed: error=%d\n",
                    __func__, error);
                goto fail2;
        }
-       error = bus_dmamap_create(dmat, size, rseg, size, boundary, dmaflags,
-           &dma->map);
+       error = bus_dmamap_create(dmat, size, rseg, size, boundary,
+           BUS_DMA_WAITOK, &dma->map);
        if (error) {
                printf("%s: bus_dmamap_create failed: error=%d\n",
                    __func__, error);
                goto fail3;
        }
        error = bus_dmamap_load(dmat, dma->map, dma->addr, size, NULL,
-           BUS_DMA_READ | BUS_DMA_WRITE | dmaflags);
+           BUS_DMA_READ | BUS_DMA_WRITE | BUS_DMA_WAITOK);
        if (error) {
                printf("%s: bus_dmamap_load failed: error=%d\n",
                    __func__, error);
diff -r 098dc957d316 -r 5d4c001e619c sys/dev/hyperv/hypervreg.h
--- a/sys/dev/hyperv/hypervreg.h        Fri May 20 07:47:16 2022 +0000
+++ b/sys/dev/hyperv/hypervreg.h        Fri May 20 13:55:16 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hypervreg.h,v 1.1 2019/02/15 08:54:01 nonaka Exp $     */
+/*     $NetBSD: hypervreg.h,v 1.2 2022/05/20 13:55:17 nonaka Exp $     */
 /*     $OpenBSD: hypervreg.h,v 1.10 2017/01/05 13:17:22 mikeb Exp $    */
 
 /*-
@@ -258,6 +258,7 @@
        uint8_t                 br_rsvd[4084];
        uint8_t                 br_data[0];
 } __packed;
+__CTASSERT(sizeof(struct vmbus_bufring) == PAGE_SIZE);
 
 /*
  * Channel
diff -r 098dc957d316 -r 5d4c001e619c sys/dev/hyperv/hypervvar.h
--- a/sys/dev/hyperv/hypervvar.h        Fri May 20 07:47:16 2022 +0000
+++ b/sys/dev/hyperv/hypervvar.h        Fri May 20 13:55:16 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hypervvar.h,v 1.5 2021/12/23 04:06:51 yamaguchi Exp $  */
+/*     $NetBSD: hypervvar.h,v 1.6 2022/05/20 13:55:17 nonaka Exp $     */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -59,6 +59,7 @@
 #endif
 
 #if defined(_KERNEL)
+extern u_int hyperv_ver_major;
 
 int    hyperv_hypercall_enabled(void);
 int    hyperv_synic_supported(void);
@@ -108,10 +109,8 @@
        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, int);
+    bus_size_t, bus_size_t, int);
 void hyperv_dma_free(bus_dma_tag_t, struct hyperv_dma *);
 
 #endif /* _KERNEL */
diff -r 098dc957d316 -r 5d4c001e619c sys/dev/hyperv/if_hvn.c
--- a/sys/dev/hyperv/if_hvn.c   Fri May 20 07:47:16 2022 +0000
+++ b/sys/dev/hyperv/if_hvn.c   Fri May 20 13:55:16 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_hvn.c,v 1.21 2021/06/16 00:21:18 riastradh Exp $    */
+/*     $NetBSD: if_hvn.c,v 1.22 2022/05/20 13:55:17 nonaka Exp $       */
 /*     $OpenBSD: if_hvn.c,v 1.39 2018/03/11 14:31:34 mikeb Exp $       */
 
 /*-
@@ -35,9 +35,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.21 2021/06/16 00:21:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.22 2022/05/20 13:55:17 nonaka Exp $");
 
 #ifdef _KERNEL_OPT
+#include "opt_if_hvn.h"
 #include "opt_inet.h"
 #include "opt_inet6.h"
 #include "opt_net_mpsafe.h"
@@ -47,14 +48,28 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/device.h>
-#include <sys/atomic.h>
+#include <sys/bitops.h>
 #include <sys/bus.h>
+#include <sys/condvar.h>
+#include <sys/cpu.h>
+#include <sys/evcnt.h>
 #include <sys/intr.h>
 #include <sys/kmem.h>
+#include <sys/kthread.h>
+#include <sys/mutex.h>
+#include <sys/pcq.h>
+#include <sys/sysctl.h>
+#include <sys/workqueue.h>
 
 #include <net/if.h>
 #include <net/if_ether.h>
 #include <net/if_media.h>
+#include <net/if_vlanvar.h>
+#include <net/rss_config.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/ip6.h>
+#include <netinet/udp.h>
 
 #include <net/bpf.h>
 
@@ -71,9 +86,24 @@
 #define EVL_CFI_BITS   12
 #endif
 
+#define HVN_CHIM_SIZE                  (15 * 1024 * 1024)
+
 #define HVN_NVS_MSGSIZE                        32
 #define HVN_NVS_BUFSIZE                        PAGE_SIZE
 
+#define HVN_RING_BUFSIZE               (128 * PAGE_SIZE)
+#define HVN_RING_IDX2CPU(sc, idx)      ((idx) % ncpu)
+
+#ifndef HVN_CHANNEL_MAX_COUNT_DEFAULT
+#define HVN_CHANNEL_MAX_COUNT_DEFAULT  8
+#endif
+
+#ifndef HVN_LINK_STATE_CHANGE_DELAY
+#define HVN_LINK_STATE_CHANGE_DELAY    5000
+#endif
+
+#define HVN_WORKQUEUE_PRI              PRI_SOFTNET
+
 /*
  * RNDIS control interface
  */
@@ -93,17 +123,36 @@
        uint8_t                         rc_cmpbuf[HVN_RNDIS_BUFSIZE];
        int                             rc_done;
        TAILQ_ENTRY(rndis_cmd)          rc_entry;
+       kmutex_t                        rc_lock;
+       kcondvar_t                      rc_cv;
 };
 TAILQ_HEAD(rndis_queue, rndis_cmd);
 
-#define HVN_MAXMTU                     (9 * 1024)
+#define HVN_MTU_MIN                    68
+#define HVN_MTU_MAX                    (65535 - ETHER_ADDR_LEN)
 
 #define HVN_RNDIS_XFER_SIZE            2048
 
+#define HVN_NDIS_TXCSUM_CAP_IP4 \
+       (NDIS_TXCSUM_CAP_IP4 | NDIS_TXCSUM_CAP_IP4OPT)
+#define HVN_NDIS_TXCSUM_CAP_TCP4 \
+       (NDIS_TXCSUM_CAP_TCP4 | NDIS_TXCSUM_CAP_TCP4OPT)
+#define HVN_NDIS_TXCSUM_CAP_TCP6 \
+       (NDIS_TXCSUM_CAP_TCP6 | NDIS_TXCSUM_CAP_TCP6OPT | \
+           NDIS_TXCSUM_CAP_IP6EXT)
+#define HVN_NDIS_TXCSUM_CAP_UDP6 \
+       (NDIS_TXCSUM_CAP_UDP6 | NDIS_TXCSUM_CAP_IP6EXT)
+#define HVN_NDIS_LSOV2_CAP_IP6 \
+       (NDIS_LSOV2_CAP_IP6EXT | NDIS_LSOV2_CAP_TCP6OPT)
+
+#define HVN_RNDIS_CMD_NORESP   __BIT(0)
+
+#define HVN_NVS_CMD_NORESP     __BIT(0)
+
 /*
  * Tx ring
  */
-#define HVN_TX_DESC                    256
+#define HVN_TX_DESC                    512
 #define HVN_TX_FRAGS                   15              /* 31 is the max */
 #define HVN_TX_FRAG_SIZE               PAGE_SIZE
 #define HVN_TX_PKT_SIZE                        16384
@@ -113,71 +162,291 @@
         sizeof(struct rndis_pktinfo) + NDIS_VLAN_INFO_SIZE +   \
         sizeof(struct rndis_pktinfo) + NDIS_TXCSUM_INFO_SIZE)
 
+#define HVN_PKTSIZE_MIN(align)                                         \
+       roundup2(ETHER_MIN_LEN + ETHER_VLAN_ENCAP_LEN - ETHER_CRC_LEN + \
+       HVN_RNDIS_PKT_LEN, (align))
+#define HVN_PKTSIZE(m, align)                                          \
+       roundup2((m)->m_pkthdr.len + HVN_RNDIS_PKT_LEN, (align))
+
 struct hvn_tx_desc {



Home | Main Index | Thread Index | Old Index