]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/hyperv/vmbus/hv_vmbus_priv.h
MFC 302636-302638,302692
[FreeBSD/stable/10.git] / sys / dev / hyperv / vmbus / hv_vmbus_priv.h
1 /*-
2  * Copyright (c) 2009-2012,2016 Microsoft Corp.
3  * Copyright (c) 2012 NetApp Inc.
4  * Copyright (c) 2012 Citrix Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30
31 #ifndef __HYPERV_PRIV_H__
32 #define __HYPERV_PRIV_H__
33
34 #include <sys/param.h>
35 #include <sys/lock.h>
36 #include <sys/mutex.h>
37 #include <sys/sema.h>
38
39 #include <dev/hyperv/include/hyperv.h>
40
41 struct vmbus_softc;
42
43 typedef struct {
44         void*           data;
45         uint32_t        length;
46 } hv_vmbus_sg_buffer_list;
47
48 typedef struct {
49         uint32_t        current_interrupt_mask;
50         uint32_t        current_read_index;
51         uint32_t        current_write_index;
52         uint32_t        bytes_avail_to_read;
53         uint32_t        bytes_avail_to_write;
54 } hv_vmbus_ring_buffer_debug_info;
55
56 typedef struct {
57         uint32_t                rel_id;
58         hv_vmbus_channel_state  state;
59         hv_guid                 interface_type;
60         hv_guid                 interface_instance;
61         uint32_t                monitor_id;
62         uint32_t                server_monitor_pending;
63         uint32_t                server_monitor_latency;
64         uint32_t                server_monitor_connection_id;
65         uint32_t                client_monitor_pending;
66         uint32_t                client_monitor_latency;
67         uint32_t                client_monitor_connection_id;
68         hv_vmbus_ring_buffer_debug_info inbound;
69         hv_vmbus_ring_buffer_debug_info outbound;
70 } hv_vmbus_channel_debug_info;
71
72 /*
73  * The format must be the same as hv_vm_data_gpa_direct
74  */
75 typedef struct hv_vmbus_channel_packet_page_buffer {
76         uint16_t                type;
77         uint16_t                data_offset8;
78         uint16_t                length8;
79         uint16_t                flags;
80         uint64_t                transaction_id;
81         uint32_t                reserved;
82         uint32_t                range_count;
83         hv_vmbus_page_buffer    range[HV_MAX_PAGE_BUFFER_COUNT];
84 } __packed hv_vmbus_channel_packet_page_buffer;
85
86 /*
87  * The format must be the same as hv_vm_data_gpa_direct
88  */
89 typedef struct hv_vmbus_channel_packet_multipage_buffer {
90         uint16_t                        type;
91         uint16_t                        data_offset8;
92         uint16_t                        length8;
93         uint16_t                        flags;
94         uint64_t                        transaction_id;
95         uint32_t                        reserved;
96         uint32_t                        range_count; /* Always 1 in this case */
97         hv_vmbus_multipage_buffer       range;
98 } __packed hv_vmbus_channel_packet_multipage_buffer;
99
100 typedef union {
101         uint32_t as_uint32_t;
102         struct {
103                 uint32_t group_enable :4;
104                 uint32_t rsvd_z :28;
105         } u;
106 } hv_vmbus_monitor_trigger_state;
107
108 typedef union {
109         uint64_t as_uint64_t;
110         struct {
111                 uint32_t pending;
112                 uint32_t armed;
113         } u;
114 } hv_vmbus_monitor_trigger_group;
115
116 typedef struct {
117         hv_vmbus_connection_id  connection_id;
118         uint16_t                flag_number;
119         uint16_t                rsvd_z;
120 } hv_vmbus_monitor_parameter;
121
122 /*
123  * hv_vmbus_monitor_page Layout
124  * ------------------------------------------------------
125  * | 0   | trigger_state (4 bytes) | Rsvd1 (4 bytes)     |
126  * | 8   | trigger_group[0]                              |
127  * | 10  | trigger_group[1]                              |
128  * | 18  | trigger_group[2]                              |
129  * | 20  | trigger_group[3]                              |
130  * | 28  | Rsvd2[0]                                      |
131  * | 30  | Rsvd2[1]                                      |
132  * | 38  | Rsvd2[2]                                      |
133  * | 40  | next_check_time[0][0] | next_check_time[0][1] |
134  * | ...                                                 |
135  * | 240 | latency[0][0..3]                              |
136  * | 340 | Rsvz3[0]                                      |
137  * | 440 | parameter[0][0]                               |
138  * | 448 | parameter[0][1]                               |
139  * | ...                                                 |
140  * | 840 | Rsvd4[0]                                      |
141  * ------------------------------------------------------
142  */
143
144 typedef struct {
145         hv_vmbus_monitor_trigger_state  trigger_state;
146         uint32_t                        rsvd_z1;
147
148         hv_vmbus_monitor_trigger_group  trigger_group[4];
149         uint64_t                        rsvd_z2[3];
150
151         int32_t                         next_check_time[4][32];
152
153         uint16_t                        latency[4][32];
154         uint64_t                        rsvd_z3[32];
155
156         hv_vmbus_monitor_parameter      parameter[4][32];
157
158         uint8_t                         rsvd_z4[1984];
159 } hv_vmbus_monitor_page;
160
161 /*
162  * Private, VM Bus functions
163  */
164 struct sysctl_ctx_list;
165 struct sysctl_oid_list;
166
167 void                    hv_ring_buffer_stat(
168                                 struct sysctl_ctx_list          *ctx,
169                                 struct sysctl_oid_list          *tree_node,
170                                 hv_vmbus_ring_buffer_info       *rbi,
171                                 const char                      *desc);
172
173 int                     hv_vmbus_ring_buffer_init(
174                                 hv_vmbus_ring_buffer_info       *ring_info,
175                                 void                            *buffer,
176                                 uint32_t                        buffer_len);
177
178 void                    hv_ring_buffer_cleanup(
179                                 hv_vmbus_ring_buffer_info       *ring_info);
180
181 int                     hv_ring_buffer_write(
182                                 hv_vmbus_ring_buffer_info       *ring_info,
183                                 hv_vmbus_sg_buffer_list         sg_buffers[],
184                                 uint32_t                        sg_buff_count,
185                                 boolean_t                       *need_sig);
186
187 int                     hv_ring_buffer_peek(
188                                 hv_vmbus_ring_buffer_info       *ring_info,
189                                 void                            *buffer,
190                                 uint32_t                        buffer_len);
191
192 int                     hv_ring_buffer_read(
193                                 hv_vmbus_ring_buffer_info       *ring_info,
194                                 void                            *buffer,
195                                 uint32_t                        buffer_len,
196                                 uint32_t                        offset);
197
198 uint32_t                hv_vmbus_get_ring_buffer_interrupt_mask(
199                                 hv_vmbus_ring_buffer_info       *ring_info);
200
201 void                    hv_vmbus_dump_ring_info(
202                                 hv_vmbus_ring_buffer_info       *ring_info,
203                                 char                            *prefix);
204
205 void                    hv_ring_buffer_read_begin(
206                                 hv_vmbus_ring_buffer_info       *ring_info);
207
208 uint32_t                hv_ring_buffer_read_end(
209                                 hv_vmbus_ring_buffer_info       *ring_info);
210
211 void                    hv_vmbus_free_vmbus_channel(hv_vmbus_channel *channel);
212 void                    hv_vmbus_release_unattached_channels(
213                             struct vmbus_softc *);
214
215 struct hv_device*       hv_vmbus_child_device_create(
216                                 hv_guid                 device_type,
217                                 hv_guid                 device_instance,
218                                 hv_vmbus_channel        *channel);
219
220 void                    hv_vmbus_child_device_register(struct vmbus_softc *,
221                                         struct hv_device *child_dev);
222 int                     hv_vmbus_child_device_unregister(
223                                         struct hv_device *child_dev);
224
225 #endif  /* __HYPERV_PRIV_H__ */