1 /*- 2 * Copyright (c) 2016 Microsoft Corp. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #ifndef _VMBUS_CHANVAR_H_ 30 #define _VMBUS_CHANVAR_H_ 31 32 #include <sys/param.h> 33 #include <sys/lock.h> 34 #include <sys/mutex.h> 35 #include <sys/queue.h> 36 #include <sys/sysctl.h> 37 #include <sys/sx.h> 38 #include <sys/taskqueue.h> 39 40 #include <dev/hyperv/include/hyperv.h> 41 #include <dev/hyperv/include/hyperv_busdma.h> 42 #include <dev/hyperv/include/vmbus.h> 43 #include <dev/hyperv/vmbus/vmbus_brvar.h> 44 45 struct vmbus_channel { 46 /* 47 * NOTE: 48 * Fields before ch_txbr are only accessed on this channel's 49 * target CPU. 50 */ 51 uint32_t ch_flags; /* VMBUS_CHAN_FLAG_ */ 52 53 /* 54 * RX bufring; immediately following ch_txbr. 55 */ 56 struct vmbus_rxbr ch_rxbr; 57 58 struct taskqueue *ch_tq; 59 struct task ch_task; 60 vmbus_chan_callback_t ch_cb; 61 void *ch_cbarg; 62 63 /* 64 * TX bufring; at the beginning of ch_bufring. 65 * 66 * NOTE: 67 * Put TX bufring and the following MNF/evtflag to a new 68 * cacheline, since they will be accessed on all CPUs by 69 * locking ch_txbr first. 70 * 71 * XXX 72 * TX bufring and following MNF/evtflags do _not_ fit in 73 * one 64B cacheline. 74 */ 75 struct vmbus_txbr ch_txbr __aligned(CACHE_LINE_SIZE); 76 uint32_t ch_txflags; /* VMBUS_CHAN_TXF_ */ 77 78 /* 79 * These are based on the vmbus_chanmsg_choffer.chm_montrig. 80 * Save it here for easy access. 81 */ 82 uint32_t ch_montrig_mask;/* MNF trig mask */ 83 volatile uint32_t *ch_montrig; /* MNF trigger loc. */ 84 85 /* 86 * These are based on the vmbus_chanmsg_choffer.chm_chanid. 87 * Save it here for easy access. 88 */ 89 u_long ch_evtflag_mask;/* event flag */ 90 volatile u_long *ch_evtflag; /* event flag loc. */ 91 92 /* 93 * Rarely used fields. 94 */ 95 96 struct hyperv_mon_param *ch_monprm; 97 struct hyperv_dma ch_monprm_dma; 98 99 uint32_t ch_id; /* channel id */ 100 device_t ch_dev; 101 struct vmbus_softc *ch_vmbus; 102 103 int ch_cpuid; /* owner cpu */ 104 /* 105 * Virtual cpuid for ch_cpuid; it is used to communicate cpuid 106 * related information w/ Hyper-V. If MSR_HV_VP_INDEX does not 107 * exist, ch_vcpuid will always be 0 for compatibility. 108 */ 109 uint32_t ch_vcpuid; 110 111 /* 112 * If this is a primary channel, ch_subchan* fields 113 * contain sub-channels belonging to this primary 114 * channel. 115 */ 116 struct mtx ch_subchan_lock; 117 TAILQ_HEAD(, vmbus_channel) ch_subchans; 118 int ch_subchan_cnt; 119 120 /* If this is a sub-channel */ 121 TAILQ_ENTRY(vmbus_channel) ch_sublink; /* sub-channel link */ 122 struct vmbus_channel *ch_prichan; /* owner primary chan */ 123 124 void *ch_bufring; /* TX+RX bufrings */ 125 struct hyperv_dma ch_bufring_dma; 126 uint32_t ch_bufring_gpadl; 127 128 struct task ch_attach_task; /* run in ch_mgmt_tq */ 129 struct task ch_detach_task; /* run in ch_mgmt_tq */ 130 struct taskqueue *ch_mgmt_tq; 131 132 /* If this is a primary channel */ 133 TAILQ_ENTRY(vmbus_channel) ch_prilink; /* primary chan link */ 134 135 TAILQ_ENTRY(vmbus_channel) ch_link; /* channel link */ 136 uint32_t ch_subidx; /* subchan index */ 137 volatile uint32_t ch_stflags; /* atomic-op */ 138 /* VMBUS_CHAN_ST_ */ 139 struct hyperv_guid ch_guid_type; 140 struct hyperv_guid ch_guid_inst; 141 142 struct sx ch_orphan_lock; 143 struct vmbus_xact_ctx *ch_orphan_xact; 144 145 int ch_refs; 146 147 struct sysctl_ctx_list ch_sysctl_ctx; 148 } __aligned(CACHE_LINE_SIZE); 149 150 #define VMBUS_CHAN_ISPRIMARY(chan) ((chan)->ch_subidx == 0) 151 152 /* 153 * If this flag is set, this channel's interrupt will be masked in ISR, 154 * and the RX bufring will be drained before this channel's interrupt is 155 * unmasked. 156 * 157 * This flag is turned on by default. Drivers can turn it off according 158 * to their own requirement. 159 */ 160 #define VMBUS_CHAN_FLAG_BATCHREAD 0x0002 161 162 #define VMBUS_CHAN_TXF_HASMNF 0x0001 163 164 #define VMBUS_CHAN_ST_OPENED_SHIFT 0 165 #define VMBUS_CHAN_ST_ONPRIL_SHIFT 1 166 #define VMBUS_CHAN_ST_ONSUBL_SHIFT 2 167 #define VMBUS_CHAN_ST_ONLIST_SHIFT 3 168 #define VMBUS_CHAN_ST_REVOKED_SHIFT 4 /* sticky */ 169 #define VMBUS_CHAN_ST_OPENED (1 << VMBUS_CHAN_ST_OPENED_SHIFT) 170 #define VMBUS_CHAN_ST_ONPRIL (1 << VMBUS_CHAN_ST_ONPRIL_SHIFT) 171 #define VMBUS_CHAN_ST_ONSUBL (1 << VMBUS_CHAN_ST_ONSUBL_SHIFT) 172 #define VMBUS_CHAN_ST_ONLIST (1 << VMBUS_CHAN_ST_ONLIST_SHIFT) 173 #define VMBUS_CHAN_ST_REVOKED (1 << VMBUS_CHAN_ST_REVOKED_SHIFT) 174 175 struct vmbus_softc; 176 struct vmbus_message; 177 178 void vmbus_event_proc(struct vmbus_softc *, int); 179 void vmbus_event_proc_compat(struct vmbus_softc *, int); 180 void vmbus_chan_msgproc(struct vmbus_softc *, 181 const struct vmbus_message *); 182 void vmbus_chan_destroy_all(struct vmbus_softc *); 183 184 #endif /* !_VMBUS_CHANVAR_H_ */ 185