75013bc9e255966a263215c85adbb2c184cd9ae8
[firefly-linux-kernel-4.4.55.git] / drivers / staging / hv / VmbusPrivate.h
1 /*
2  *
3  * Copyright (c) 2009, Microsoft Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * Authors:
19  *   Haiyang Zhang <haiyangz@microsoft.com>
20  *   Hank Janssen  <hjanssen@microsoft.com>
21  *
22  */
23
24
25 #ifndef _VMBUS_PRIVATE_H_
26 #define _VMBUS_PRIVATE_H_
27
28 #include "Hv.h"
29 #include "include/VmbusApi.h"
30 #include "Channel.h"
31 #include "ChannelMgmt.h"
32 #include "ChannelInterface.h"
33 /* #include "ChannelMessages.h" */
34 #include "RingBuffer.h"
35 /* #include "Packet.h" */
36 #include "include/List.h"
37
38
39 /* Defines */
40
41
42 /*
43  * Maximum channels is determined by the size of the interrupt page
44  * which is PAGE_SIZE. 1/2 of PAGE_SIZE is for send endpoint interrupt
45  * and the other is receive endpoint interrupt
46  */
47 #define MAX_NUM_CHANNELS                                (PAGE_SIZE >> 1) << 3  /* 16348 channels */
48
49 /* The value here must be in multiple of 32 */
50 /* TODO: Need to make this configurable */
51 #define MAX_NUM_CHANNELS_SUPPORTED              256
52
53
54 /* Data types */
55
56
57 enum VMBUS_CONNECT_STATE {
58         Disconnected,
59         Connecting,
60         Connected,
61         Disconnecting
62 };
63
64 #define MAX_SIZE_CHANNEL_MESSAGE                        HV_MESSAGE_PAYLOAD_BYTE_COUNT
65
66 struct VMBUS_CONNECTION {
67
68         enum VMBUS_CONNECT_STATE                                        ConnectState;
69
70         u32                                                             NextGpadlHandle;
71
72         /*
73          * Represents channel interrupts. Each bit position represents
74          * a channel.  When a channel sends an interrupt via VMBUS, it
75          * finds its bit in the sendInterruptPage, set it and calls Hv
76          * to generate a port event. The other end receives the port
77          * event and parse the recvInterruptPage to see which bit is
78          * set
79          */
80         void *                                                          InterruptPage;
81         void *                                                          SendInterruptPage;
82         void *                                                          RecvInterruptPage;
83
84         /*
85          * 2 pages - 1st page for parent->child notification and 2nd
86          * is child->parent notification
87          */
88         void *                                                          MonitorPages;
89         LIST_ENTRY                                                      ChannelMsgList;
90         spinlock_t channelmsg_lock;
91
92         /* List of channels */
93         LIST_ENTRY                                                      ChannelList;
94         spinlock_t channel_lock;
95
96         struct workqueue_struct *WorkQueue;
97 };
98
99
100 struct VMBUS_MSGINFO {
101         /* Bookkeeping stuff */
102         LIST_ENTRY                      MsgListEntry;
103
104         /* Synchronize the request/response if needed */
105         HANDLE                          WaitEvent;
106
107         /* The message itself */
108         unsigned char           Msg[0];
109 };
110
111
112
113 /* Externs */
114
115 extern struct VMBUS_CONNECTION gVmbusConnection;
116
117
118 /* General vmbus interface */
119
120 static struct hv_device*
121 VmbusChildDeviceCreate(
122         GUID deviceType,
123         GUID deviceInstance,
124         void *context);
125
126 static int
127 VmbusChildDeviceAdd(
128         struct hv_device *Device);
129
130 static void
131 VmbusChildDeviceRemove(
132    struct hv_device *Device);
133
134 /* static void */
135 /* VmbusChildDeviceDestroy( */
136 /* struct hv_device *); */
137
138 static VMBUS_CHANNEL*
139 GetChannelFromRelId(
140         u32 relId
141         );
142
143
144 /* Connection interface */
145
146 static int
147 VmbusConnect(
148         void
149         );
150
151 static int
152 VmbusDisconnect(
153         void
154         );
155
156 static int
157 VmbusPostMessage(
158         void *                  buffer,
159         size_t                  bufSize
160         );
161
162 static int
163 VmbusSetEvent(
164         u32 childRelId
165         );
166
167 static void
168 VmbusOnEvents(
169   void
170         );
171
172
173 #endif /* _VMBUS_PRIVATE_H_ */