| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: vmbus.c,v 1.5 2019/11/22 12:30:32 nonaka Exp $ */ | | 1 | /* $NetBSD: vmbus.c,v 1.6 2019/12/06 12:46:06 nonaka Exp $ */ |
2 | /* $OpenBSD: hyperv.c,v 1.43 2017/06/27 13:56:15 mikeb Exp $ */ | | 2 | /* $OpenBSD: hyperv.c,v 1.43 2017/06/27 13:56:15 mikeb Exp $ */ |
3 | | | 3 | |
4 | /*- | | 4 | /*- |
5 | * Copyright (c) 2009-2012 Microsoft Corp. | | 5 | * Copyright (c) 2009-2012 Microsoft Corp. |
6 | * Copyright (c) 2012 NetApp Inc. | | 6 | * Copyright (c) 2012 NetApp Inc. |
7 | * Copyright (c) 2012 Citrix Inc. | | 7 | * Copyright (c) 2012 Citrix Inc. |
8 | * Copyright (c) 2016 Mike Belopuhov <mike@esdenera.com> | | 8 | * Copyright (c) 2016 Mike Belopuhov <mike@esdenera.com> |
9 | * All rights reserved. | | 9 | * All rights reserved. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -25,27 +25,27 @@ | | | @@ -25,27 +25,27 @@ |
25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
26 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 26 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
30 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 30 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | /* | | 33 | /* |
34 | * The OpenBSD port was done under funding by Esdenera Networks GmbH. | | 34 | * The OpenBSD port was done under funding by Esdenera Networks GmbH. |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #include <sys/cdefs.h> | | 37 | #include <sys/cdefs.h> |
38 | __KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.5 2019/11/22 12:30:32 nonaka Exp $"); | | 38 | __KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.6 2019/12/06 12:46:06 nonaka Exp $"); |
39 | | | 39 | |
40 | #include <sys/param.h> | | 40 | #include <sys/param.h> |
41 | #include <sys/systm.h> | | 41 | #include <sys/systm.h> |
42 | #include <sys/device.h> | | 42 | #include <sys/device.h> |
43 | #include <sys/atomic.h> | | 43 | #include <sys/atomic.h> |
44 | #include <sys/bitops.h> | | 44 | #include <sys/bitops.h> |
45 | #include <sys/bus.h> | | 45 | #include <sys/bus.h> |
46 | #include <sys/cpu.h> | | 46 | #include <sys/cpu.h> |
47 | #include <sys/intr.h> | | 47 | #include <sys/intr.h> |
48 | #include <sys/kmem.h> | | 48 | #include <sys/kmem.h> |
49 | #include <sys/module.h> | | 49 | #include <sys/module.h> |
50 | #include <sys/mutex.h> | | 50 | #include <sys/mutex.h> |
51 | #include <sys/xcall.h> | | 51 | #include <sys/xcall.h> |
| @@ -975,27 +975,26 @@ static struct vmbus_channel * | | | @@ -975,27 +975,26 @@ static struct vmbus_channel * |
975 | vmbus_channel_alloc(struct vmbus_softc *sc) | | 975 | vmbus_channel_alloc(struct vmbus_softc *sc) |
976 | { | | 976 | { |
977 | struct vmbus_channel *ch; | | 977 | struct vmbus_channel *ch; |
978 | | | 978 | |
979 | ch = kmem_zalloc(sizeof(*ch), cold ? KM_NOSLEEP : KM_SLEEP); | | 979 | ch = kmem_zalloc(sizeof(*ch), cold ? KM_NOSLEEP : KM_SLEEP); |
980 | | | 980 | |
981 | ch->ch_monprm = hyperv_dma_alloc(sc->sc_dmat, &ch->ch_monprm_dma, | | 981 | ch->ch_monprm = hyperv_dma_alloc(sc->sc_dmat, &ch->ch_monprm_dma, |
982 | sizeof(*ch->ch_monprm), 8, 0, 1); | | 982 | sizeof(*ch->ch_monprm), 8, 0, 1); |
983 | if (ch->ch_monprm == NULL) { | | 983 | if (ch->ch_monprm == NULL) { |
984 | device_printf(sc->sc_dev, "monprm alloc failed\n"); | | 984 | device_printf(sc->sc_dev, "monprm alloc failed\n"); |
985 | kmem_free(ch, sizeof(*ch)); | | 985 | kmem_free(ch, sizeof(*ch)); |
986 | return NULL; | | 986 | return NULL; |
987 | } | | 987 | } |
988 | memset(ch->ch_monprm, 0, sizeof(*ch->ch_monprm)); | | | |
989 | | | 988 | |
990 | ch->ch_refs = 1; | | 989 | ch->ch_refs = 1; |
991 | ch->ch_sc = sc; | | 990 | ch->ch_sc = sc; |
992 | mutex_init(&ch->ch_subchannel_lock, MUTEX_DEFAULT, IPL_NET); | | 991 | mutex_init(&ch->ch_subchannel_lock, MUTEX_DEFAULT, IPL_NET); |
993 | TAILQ_INIT(&ch->ch_subchannels); | | 992 | TAILQ_INIT(&ch->ch_subchannels); |
994 | | | 993 | |
995 | ch->ch_state = VMBUS_CHANSTATE_CLOSED; | | 994 | ch->ch_state = VMBUS_CHANSTATE_CLOSED; |
996 | | | 995 | |
997 | return ch; | | 996 | return ch; |
998 | } | | 997 | } |
999 | | | 998 | |
1000 | static void | | 999 | static void |
1001 | vmbus_channel_free(struct vmbus_channel *ch) | | 1000 | vmbus_channel_free(struct vmbus_channel *ch) |
| @@ -1254,27 +1253,26 @@ static int | | | @@ -1254,27 +1253,26 @@ static int |
1254 | vmbus_channel_ring_create(struct vmbus_channel *ch, uint32_t buflen) | | 1253 | vmbus_channel_ring_create(struct vmbus_channel *ch, uint32_t buflen) |
1255 | { | | 1254 | { |
1256 | struct vmbus_softc *sc = ch->ch_sc; | | 1255 | struct vmbus_softc *sc = ch->ch_sc; |
1257 | | | 1256 | |
1258 | buflen = roundup(buflen, PAGE_SIZE) + sizeof(struct vmbus_bufring); | | 1257 | buflen = roundup(buflen, PAGE_SIZE) + sizeof(struct vmbus_bufring); |
1259 | ch->ch_ring_size = 2 * buflen; | | 1258 | ch->ch_ring_size = 2 * buflen; |
1260 | ch->ch_ring = hyperv_dma_alloc(sc->sc_dmat, &ch->ch_ring_dma, | | 1259 | ch->ch_ring = hyperv_dma_alloc(sc->sc_dmat, &ch->ch_ring_dma, |
1261 | ch->ch_ring_size, PAGE_SIZE, 0, 1); /* page aligned memory */ | | 1260 | ch->ch_ring_size, PAGE_SIZE, 0, 1); /* page aligned memory */ |
1262 | if (ch->ch_ring == NULL) { | | 1261 | if (ch->ch_ring == NULL) { |
1263 | device_printf(sc->sc_dev, | | 1262 | device_printf(sc->sc_dev, |
1264 | "failed to allocate channel ring\n"); | | 1263 | "failed to allocate channel ring\n"); |
1265 | return ENOMEM; | | 1264 | return ENOMEM; |
1266 | } | | 1265 | } |
1267 | memset(ch->ch_ring, 0, ch->ch_ring_size); | | | |
1268 | | | 1266 | |
1269 | memset(&ch->ch_wrd, 0, sizeof(ch->ch_wrd)); | | 1267 | memset(&ch->ch_wrd, 0, sizeof(ch->ch_wrd)); |
1270 | ch->ch_wrd.rd_ring = (struct vmbus_bufring *)ch->ch_ring; | | 1268 | ch->ch_wrd.rd_ring = (struct vmbus_bufring *)ch->ch_ring; |
1271 | ch->ch_wrd.rd_size = buflen; | | 1269 | ch->ch_wrd.rd_size = buflen; |
1272 | ch->ch_wrd.rd_dsize = buflen - sizeof(struct vmbus_bufring); | | 1270 | ch->ch_wrd.rd_dsize = buflen - sizeof(struct vmbus_bufring); |
1273 | mutex_init(&ch->ch_wrd.rd_lock, MUTEX_DEFAULT, IPL_NET); | | 1271 | mutex_init(&ch->ch_wrd.rd_lock, MUTEX_DEFAULT, IPL_NET); |
1274 | | | 1272 | |
1275 | memset(&ch->ch_rrd, 0, sizeof(ch->ch_rrd)); | | 1273 | memset(&ch->ch_rrd, 0, sizeof(ch->ch_rrd)); |
1276 | ch->ch_rrd.rd_ring = (struct vmbus_bufring *)((uint8_t *)ch->ch_ring + | | 1274 | ch->ch_rrd.rd_ring = (struct vmbus_bufring *)((uint8_t *)ch->ch_ring + |
1277 | buflen); | | 1275 | buflen); |
1278 | ch->ch_rrd.rd_size = buflen; | | 1276 | ch->ch_rrd.rd_size = buflen; |
1279 | ch->ch_rrd.rd_dsize = buflen - sizeof(struct vmbus_bufring); | | 1277 | ch->ch_rrd.rd_dsize = buflen - sizeof(struct vmbus_bufring); |
1280 | mutex_init(&ch->ch_rrd.rd_lock, MUTEX_DEFAULT, IPL_NET); | | 1278 | mutex_init(&ch->ch_rrd.rd_lock, MUTEX_DEFAULT, IPL_NET); |