]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/hyperv/vmbus/hv_vmbus_priv.h
MFC 302733,302737,302801-302806
[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         struct hyperv_guid      interface_type;
60         struct hyperv_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 /*
101  * Private, VM Bus functions
102  */
103 struct sysctl_ctx_list;
104 struct sysctl_oid_list;
105
106 void                    hv_ring_buffer_stat(
107                                 struct sysctl_ctx_list          *ctx,
108                                 struct sysctl_oid_list          *tree_node,
109                                 hv_vmbus_ring_buffer_info       *rbi,
110                                 const char                      *desc);
111
112 int                     hv_vmbus_ring_buffer_init(
113                                 hv_vmbus_ring_buffer_info       *ring_info,
114                                 void                            *buffer,
115                                 uint32_t                        buffer_len);
116
117 void                    hv_ring_buffer_cleanup(
118                                 hv_vmbus_ring_buffer_info       *ring_info);
119
120 int                     hv_ring_buffer_write(
121                                 hv_vmbus_ring_buffer_info       *ring_info,
122                                 hv_vmbus_sg_buffer_list         sg_buffers[],
123                                 uint32_t                        sg_buff_count,
124                                 boolean_t                       *need_sig);
125
126 int                     hv_ring_buffer_peek(
127                                 hv_vmbus_ring_buffer_info       *ring_info,
128                                 void                            *buffer,
129                                 uint32_t                        buffer_len);
130
131 int                     hv_ring_buffer_read(
132                                 hv_vmbus_ring_buffer_info       *ring_info,
133                                 void                            *buffer,
134                                 uint32_t                        buffer_len,
135                                 uint32_t                        offset);
136
137 uint32_t                hv_vmbus_get_ring_buffer_interrupt_mask(
138                                 hv_vmbus_ring_buffer_info       *ring_info);
139
140 void                    hv_vmbus_dump_ring_info(
141                                 hv_vmbus_ring_buffer_info       *ring_info,
142                                 char                            *prefix);
143
144 void                    hv_ring_buffer_read_begin(
145                                 hv_vmbus_ring_buffer_info       *ring_info);
146
147 uint32_t                hv_ring_buffer_read_end(
148                                 hv_vmbus_ring_buffer_info       *ring_info);
149
150 void                    hv_vmbus_free_vmbus_channel(hv_vmbus_channel *channel);
151 void                    hv_vmbus_release_unattached_channels(
152                             struct vmbus_softc *);
153
154 int                     hv_vmbus_child_device_register(
155                                         struct hv_vmbus_channel *chan);
156 int                     hv_vmbus_child_device_unregister(
157                                         struct hv_vmbus_channel *chan);
158
159 #endif  /* __HYPERV_PRIV_H__ */