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 27 #ifndef _VMBUS_CHANVAR_H_ 28 #define _VMBUS_CHANVAR_H_ 29 30 #include <sys/param.h> 31 #include <sys/callout.h> 32 #include <sys/lock.h> 33 #include <sys/mutex.h> 34 #include <sys/queue.h> 35 #include <sys/sysctl.h> 36 #include <sys/sx.h> 37 #include <sys/taskqueue.h> 38 39 #include <dev/hyperv/include/hyperv.h> 40 #include <dev/hyperv/include/vmbus.h> 41 #include <dev/hyperv/vmbus/vmbus_brvar.h> 42 43 struct vmbus_channel { 44 /* 45 * NOTE: 46 * Fields before ch_txbr are only accessed on this channel's 47 * target CPU. 48 */ 49 uint32_t ch_flags; /* VMBUS_CHAN_FLAG_ */ 50 int ch_poll_flags; /* callout flags */ 51 52 /* 53 * RX bufring; immediately following ch_txbr. 54 */ 55 struct vmbus_rxbr ch_rxbr; 56 57 struct taskqueue *ch_tq; 58 struct task ch_task; 59 struct task ch_poll_task; 60 sbintime_t ch_poll_intvl; 61 struct callout ch_poll_timeo; 62 vmbus_chan_callback_t ch_cb; 63 void *ch_cbarg; 64 vmbus_chan_rescind_callback_t ch_rescind_cb; 65 66 /* 67 * TX bufring; at the beginning of ch_bufring. 68 * 69 * NOTE: 70 * Put TX bufring and the following MNF/evtflag to a new 71 * cacheline, since they will be accessed on all CPUs by 72 * locking ch_txbr first. 73 * 74 * XXX 75 * TX bufring and following MNF/evtflags do _not_ fit in 76 * one 64B cacheline. 77 */ 78 struct vmbus_txbr ch_txbr __aligned(CACHE_LINE_SIZE); 79 uint32_t ch_txflags; /* VMBUS_CHAN_TXF_ */ 80 81 /* 82 * These are based on the vmbus_chanmsg_choffer.chm_montrig. 83 * Save it here for easy access. 84 */ 85 uint8_t ch_monitor_id; 86 uint32_t ch_montrig_mask;/* MNF trig mask */ 87 volatile uint32_t *ch_montrig; /* MNF trigger loc. */ 88 89 /* 90 * These are based on the vmbus_chanmsg_choffer.chm_chanid. 91 * Save it here for easy access. 92 */ 93 u_long ch_evtflag_mask;/* event flag */ 94 volatile u_long *ch_evtflag; /* event flag loc. */ 95 96 /* 97 * Rarely used fields. 98 */ 99 100 struct hyperv_mon_param *ch_monprm; 101 102 uint32_t ch_id; /* channel id */ 103 device_t ch_dev; 104 struct vmbus_softc *ch_vmbus; 105 106 int ch_cpuid; /* owner cpu */ 107 /* 108 * Virtual cpuid for ch_cpuid; it is used to communicate cpuid 109 * related information w/ Hyper-V. If MSR_HV_VP_INDEX does not 110 * exist, ch_vcpuid will always be 0 for compatibility. 111 */ 112 uint32_t ch_vcpuid; 113 114 /* 115 * If this is a primary channel, ch_subchan* fields 116 * contain sub-channels belonging to this primary 117 * channel. 118 */ 119 struct mtx ch_subchan_lock; 120 TAILQ_HEAD(, vmbus_channel) ch_subchans; 121 int ch_subchan_cnt; 122 123 /* If this is a sub-channel */ 124 TAILQ_ENTRY(vmbus_channel) ch_sublink; /* sub-channel link */ 125 struct vmbus_channel *ch_prichan; /* owner primary chan */ 126 127 void *ch_bufring; /* TX+RX bufrings */ 128 uint32_t ch_bufring_gpadl; 129 130 struct task ch_attach_task; /* run in ch_mgmt_tq */ 131 struct task ch_detach_task; /* run in ch_mgmt_tq */ 132 struct taskqueue *ch_mgmt_tq; 133 134 /* If this is a primary channel */ 135 TAILQ_ENTRY(vmbus_channel) ch_prilink; /* primary chan link */ 136 137 TAILQ_ENTRY(vmbus_channel) ch_link; /* channel link */ 138 uint32_t ch_subidx; /* subchan index */ 139 volatile uint32_t ch_stflags; /* atomic-op */ 140 /* VMBUS_CHAN_ST_ */ 141 struct hyperv_guid ch_guid_type; 142 struct hyperv_guid ch_guid_inst; 143 144 struct sx ch_orphan_lock; 145 struct vmbus_xact_ctx *ch_orphan_xact; 146 147 int ch_refs; 148 149 /* 150 * These are for HyperV socket channel only 151 */ 152 bool ch_is_hvs; 153 uint8_t ch_hvs_conn_from_host; 154 155 struct sysctl_ctx_list ch_sysctl_ctx; 156 } __aligned(CACHE_LINE_SIZE); 157 158 #define VMBUS_CHAN_ISPRIMARY(chan) ((chan)->ch_subidx == 0) 159 160 /* 161 * If this flag is set, this channel's interrupt will be masked in ISR, 162 * and the RX bufring will be drained before this channel's interrupt is 163 * unmasked. 164 * 165 * This flag is turned on by default. Drivers can turn it off according 166 * to their own requirement. 167 */ 168 #define VMBUS_CHAN_FLAG_BATCHREAD 0x0002 169 170 #define VMBUS_CHAN_TXF_HASMNF 0x0001 171 172 #define VMBUS_CHAN_ST_OPENED_SHIFT 0 173 #define VMBUS_CHAN_ST_ONPRIL_SHIFT 1 174 #define VMBUS_CHAN_ST_ONSUBL_SHIFT 2 175 #define VMBUS_CHAN_ST_ONLIST_SHIFT 3 176 #define VMBUS_CHAN_ST_REVOKED_SHIFT 4 /* sticky */ 177 #define VMBUS_CHAN_ST_OPENED (1 << VMBUS_CHAN_ST_OPENED_SHIFT) 178 #define VMBUS_CHAN_ST_ONPRIL (1 << VMBUS_CHAN_ST_ONPRIL_SHIFT) 179 #define VMBUS_CHAN_ST_ONSUBL (1 << VMBUS_CHAN_ST_ONSUBL_SHIFT) 180 #define VMBUS_CHAN_ST_ONLIST (1 << VMBUS_CHAN_ST_ONLIST_SHIFT) 181 #define VMBUS_CHAN_ST_REVOKED (1 << VMBUS_CHAN_ST_REVOKED_SHIFT) 182 183 struct vmbus_softc; 184 struct vmbus_message; 185 186 void vmbus_event_proc(struct vmbus_softc *, int); 187 void vmbus_event_proc_compat(struct vmbus_softc *, int); 188 void vmbus_chan_msgproc(struct vmbus_softc *, 189 const struct vmbus_message *); 190 void vmbus_chan_destroy_all(struct vmbus_softc *); 191 struct hyperv_dma *vmbus_get_mem_evtflags(void); 192 struct hyperv_dma *vmbus_get_mem_mnf2(void); 193 #endif /* !_VMBUS_CHANVAR_H_ */ 194