2 * Copyright (c) 2016 Microsoft Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
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.
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.
29 #ifndef _VMBUS_CHANVAR_H_
30 #define _VMBUS_CHANVAR_H_
32 #include <sys/param.h>
33 #include <sys/callout.h>
35 #include <sys/mutex.h>
36 #include <sys/queue.h>
37 #include <sys/sysctl.h>
39 #include <sys/taskqueue.h>
41 #include <dev/hyperv/include/hyperv.h>
42 #include <dev/hyperv/include/hyperv_busdma.h>
43 #include <dev/hyperv/include/vmbus.h>
44 #include <dev/hyperv/vmbus/vmbus_brvar.h>
46 struct vmbus_channel {
49 * Fields before ch_txbr are only accessed on this channel's
52 uint32_t ch_flags; /* VMBUS_CHAN_FLAG_ */
53 int ch_poll_flags; /* callout flags */
56 * RX bufring; immediately following ch_txbr.
58 struct vmbus_rxbr ch_rxbr;
60 struct taskqueue *ch_tq;
62 struct task ch_poll_task;
63 sbintime_t ch_poll_intvl;
64 struct callout ch_poll_timeo;
65 vmbus_chan_callback_t ch_cb;
69 * TX bufring; at the beginning of ch_bufring.
72 * Put TX bufring and the following MNF/evtflag to a new
73 * cacheline, since they will be accessed on all CPUs by
74 * locking ch_txbr first.
77 * TX bufring and following MNF/evtflags do _not_ fit in
80 struct vmbus_txbr ch_txbr __aligned(CACHE_LINE_SIZE);
81 uint32_t ch_txflags; /* VMBUS_CHAN_TXF_ */
84 * These are based on the vmbus_chanmsg_choffer.chm_montrig.
85 * Save it here for easy access.
87 uint32_t ch_montrig_mask;/* MNF trig mask */
88 volatile uint32_t *ch_montrig; /* MNF trigger loc. */
91 * These are based on the vmbus_chanmsg_choffer.chm_chanid.
92 * Save it here for easy access.
94 u_long ch_evtflag_mask;/* event flag */
95 volatile u_long *ch_evtflag; /* event flag loc. */
101 struct hyperv_mon_param *ch_monprm;
102 struct hyperv_dma ch_monprm_dma;
104 uint32_t ch_id; /* channel id */
106 struct vmbus_softc *ch_vmbus;
108 int ch_cpuid; /* owner cpu */
110 * Virtual cpuid for ch_cpuid; it is used to communicate cpuid
111 * related information w/ Hyper-V. If MSR_HV_VP_INDEX does not
112 * exist, ch_vcpuid will always be 0 for compatibility.
117 * If this is a primary channel, ch_subchan* fields
118 * contain sub-channels belonging to this primary
121 struct mtx ch_subchan_lock;
122 TAILQ_HEAD(, vmbus_channel) ch_subchans;
125 /* If this is a sub-channel */
126 TAILQ_ENTRY(vmbus_channel) ch_sublink; /* sub-channel link */
127 struct vmbus_channel *ch_prichan; /* owner primary chan */
129 void *ch_bufring; /* TX+RX bufrings */
130 struct hyperv_dma ch_bufring_dma;
131 uint32_t ch_bufring_gpadl;
133 struct task ch_attach_task; /* run in ch_mgmt_tq */
134 struct task ch_detach_task; /* run in ch_mgmt_tq */
135 struct taskqueue *ch_mgmt_tq;
137 /* If this is a primary channel */
138 TAILQ_ENTRY(vmbus_channel) ch_prilink; /* primary chan link */
140 TAILQ_ENTRY(vmbus_channel) ch_link; /* channel link */
141 uint32_t ch_subidx; /* subchan index */
142 volatile uint32_t ch_stflags; /* atomic-op */
144 struct hyperv_guid ch_guid_type;
145 struct hyperv_guid ch_guid_inst;
147 struct sx ch_orphan_lock;
148 struct vmbus_xact_ctx *ch_orphan_xact;
152 struct sysctl_ctx_list ch_sysctl_ctx;
153 } __aligned(CACHE_LINE_SIZE);
155 #define VMBUS_CHAN_ISPRIMARY(chan) ((chan)->ch_subidx == 0)
158 * If this flag is set, this channel's interrupt will be masked in ISR,
159 * and the RX bufring will be drained before this channel's interrupt is
162 * This flag is turned on by default. Drivers can turn it off according
163 * to their own requirement.
165 #define VMBUS_CHAN_FLAG_BATCHREAD 0x0002
167 #define VMBUS_CHAN_TXF_HASMNF 0x0001
169 #define VMBUS_CHAN_ST_OPENED_SHIFT 0
170 #define VMBUS_CHAN_ST_ONPRIL_SHIFT 1
171 #define VMBUS_CHAN_ST_ONSUBL_SHIFT 2
172 #define VMBUS_CHAN_ST_ONLIST_SHIFT 3
173 #define VMBUS_CHAN_ST_REVOKED_SHIFT 4 /* sticky */
174 #define VMBUS_CHAN_ST_OPENED (1 << VMBUS_CHAN_ST_OPENED_SHIFT)
175 #define VMBUS_CHAN_ST_ONPRIL (1 << VMBUS_CHAN_ST_ONPRIL_SHIFT)
176 #define VMBUS_CHAN_ST_ONSUBL (1 << VMBUS_CHAN_ST_ONSUBL_SHIFT)
177 #define VMBUS_CHAN_ST_ONLIST (1 << VMBUS_CHAN_ST_ONLIST_SHIFT)
178 #define VMBUS_CHAN_ST_REVOKED (1 << VMBUS_CHAN_ST_REVOKED_SHIFT)
181 struct vmbus_message;
183 void vmbus_event_proc(struct vmbus_softc *, int);
184 void vmbus_event_proc_compat(struct vmbus_softc *, int);
185 void vmbus_chan_msgproc(struct vmbus_softc *,
186 const struct vmbus_message *);
187 void vmbus_chan_destroy_all(struct vmbus_softc *);
189 #endif /* !_VMBUS_CHANVAR_H_ */