Staging: hv: move StorVscApi.h
[sfrench/cifs-2.6.git] / drivers / staging / hv / include / VmbusApi.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_API_H_
26 #define _VMBUS_API_H_
27
28 #define MAX_PAGE_BUFFER_COUNT                           16
29 #define MAX_MULTIPAGE_BUFFER_COUNT                      32 /* 128K */
30
31 #pragma pack(push, 1)
32
33 /* Single-page buffer */
34 struct hv_page_buffer {
35         u32 Length;
36         u32 Offset;
37         u64 Pfn;
38 };
39
40 /* Multiple-page buffer */
41 struct hv_multipage_buffer {
42         /* Length and Offset determines the # of pfns in the array */
43         u32 Length;
44         u32 Offset;
45         u64 PfnArray[MAX_MULTIPAGE_BUFFER_COUNT];
46 };
47
48 /* 0x18 includes the proprietary packet header */
49 #define MAX_PAGE_BUFFER_PACKET          (0x18 +                 \
50                                         (sizeof(struct hv_page_buffer) * \
51                                          MAX_PAGE_BUFFER_COUNT))
52 #define MAX_MULTIPAGE_BUFFER_PACKET     (0x18 +                 \
53                                          sizeof(struct hv_multipage_buffer))
54
55
56 #pragma pack(pop)
57
58 struct hv_driver;
59 struct hv_device;
60
61 /* All drivers */
62 typedef int (*PFN_ON_DEVICEADD)(struct hv_device *Device,
63                                 void *AdditionalInfo);
64 typedef int (*PFN_ON_DEVICEREMOVE)(struct hv_device *Device);
65 typedef char** (*PFN_ON_GETDEVICEIDS)(void);
66 typedef void (*PFN_ON_CLEANUP)(struct hv_driver *Driver);
67
68 /* Vmbus extensions */
69 typedef int (*PFN_ON_ISR)(struct hv_driver *drv);
70 typedef void (*PFN_ON_DPC)(struct hv_driver *drv);
71 typedef void (*PFN_GET_CHANNEL_OFFERS)(void);
72
73 typedef struct hv_device * (*PFN_ON_CHILDDEVICE_CREATE)
74                                 (struct hv_guid *DeviceType,
75                                  struct hv_guid *DeviceInstance,
76                                  void *Context);
77 typedef void (*PFN_ON_CHILDDEVICE_DESTROY)(struct hv_device *Device);
78 typedef int (*PFN_ON_CHILDDEVICE_ADD)(struct hv_device *RootDevice,
79                                       struct hv_device *ChildDevice);
80 typedef void (*PFN_ON_CHILDDEVICE_REMOVE)(struct hv_device *Device);
81
82 /* Vmbus channel interface */
83 typedef void (*VMBUS_CHANNEL_CALLBACK)(void *context);
84 typedef int (*VMBUS_CHANNEL_OPEN)(struct hv_device *Device, u32 SendBufferSize,
85                                   u32 RecvRingBufferSize,
86                                   void *UserData,
87                                   u32 UserDataLen,
88                                   VMBUS_CHANNEL_CALLBACK ChannelCallback,
89                                   void *Context);
90 typedef void (*VMBUS_CHANNEL_CLOSE)(struct hv_device *Device);
91 typedef int (*VMBUS_CHANNEL_SEND_PACKET)(struct hv_device *Device,
92                                          const void *Buffer,
93                                          u32 BufferLen,
94                                          u64 RequestId,
95                                          u32 Type,
96                                          u32 Flags);
97 typedef int (*VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER)(struct hv_device *Device,
98                                         struct hv_page_buffer PageBuffers[],
99                                         u32 PageCount,
100                                         void *Buffer,
101                                         u32 BufferLen,
102                                         u64 RequestId);
103 typedef int (*VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER)
104                                         (struct hv_device *Device,
105                                          struct hv_multipage_buffer *mpb,
106                                          void *Buffer,
107                                          u32 BufferLen,
108                                          u64 RequestId);
109 typedef int (*VMBUS_CHANNEL_RECV_PACKET)(struct hv_device *Device,
110                                          void *Buffer,
111                                          u32 BufferLen,
112                                          u32 *BufferActualLen,
113                                          u64 *RequestId);
114 typedef int(*VMBUS_CHANNEL_RECV_PACKET_PAW)(struct hv_device *Device,
115                                             void *Buffer,
116                                             u32 BufferLen,
117                                             u32 *BufferActualLen,
118                                             u64 *RequestId);
119 typedef int (*VMBUS_CHANNEL_ESTABLISH_GPADL)(struct hv_device *Device,
120                                              void *Buffer,
121                                              u32 BufferLen,
122                                              u32 *GpadlHandle);
123 typedef int (*VMBUS_CHANNEL_TEARDOWN_GPADL)(struct hv_device *Device,
124                                             u32 GpadlHandle);
125
126
127 struct hv_dev_port_info {
128         u32 InterruptMask;
129         u32 ReadIndex;
130         u32 WriteIndex;
131         u32 BytesAvailToRead;
132         u32 BytesAvailToWrite;
133 };
134
135 struct hv_device_info {
136         u32 ChannelId;
137         u32 ChannelState;
138         struct hv_guid ChannelType;
139         struct hv_guid ChannelInstance;
140
141         u32 MonitorId;
142         u32 ServerMonitorPending;
143         u32 ServerMonitorLatency;
144         u32 ServerMonitorConnectionId;
145         u32 ClientMonitorPending;
146         u32 ClientMonitorLatency;
147         u32 ClientMonitorConnectionId;
148
149         struct hv_dev_port_info Inbound;
150         struct hv_dev_port_info Outbound;
151 };
152
153 typedef void (*VMBUS_GET_CHANNEL_INFO)(struct hv_device *Device,
154                                        struct hv_device_info *DeviceInfo);
155
156 struct vmbus_channel_interface {
157         VMBUS_CHANNEL_OPEN Open;
158         VMBUS_CHANNEL_CLOSE Close;
159         VMBUS_CHANNEL_SEND_PACKET SendPacket;
160         VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER SendPacketPageBuffer;
161         VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER SendPacketMultiPageBuffer;
162         VMBUS_CHANNEL_RECV_PACKET RecvPacket;
163         VMBUS_CHANNEL_RECV_PACKET_PAW RecvPacketRaw;
164         VMBUS_CHANNEL_ESTABLISH_GPADL EstablishGpadl;
165         VMBUS_CHANNEL_TEARDOWN_GPADL TeardownGpadl;
166         VMBUS_GET_CHANNEL_INFO GetInfo;
167 };
168
169 typedef void (*VMBUS_GET_CHANNEL_INTERFACE)(struct vmbus_channel_interface *i);
170
171 /* Base driver object */
172 struct hv_driver {
173         const char *name;
174
175         /* the device type supported by this driver */
176         struct hv_guid deviceType;
177
178         PFN_ON_DEVICEADD OnDeviceAdd;
179         PFN_ON_DEVICEREMOVE OnDeviceRemove;
180
181         /* device ids supported by this driver */
182         PFN_ON_GETDEVICEIDS OnGetDeviceIds;
183         PFN_ON_CLEANUP OnCleanup;
184
185         struct vmbus_channel_interface VmbusChannelInterface;
186 };
187
188 /* Base device object */
189 struct hv_device {
190         /* the driver for this device */
191         struct hv_driver *Driver;
192
193         char name[64];
194
195         /* the device type id of this device */
196         struct hv_guid deviceType;
197
198         /* the device instance id of this device */
199         struct hv_guid deviceInstance;
200
201         void *context;
202
203         /* Device extension; */
204         void *Extension;
205 };
206
207 /* Vmbus driver object */
208 struct vmbus_driver {
209         /* !! Must be the 1st field !! */
210         /* FIXME if ^, then someone is doing somthing stupid */
211         struct hv_driver Base;
212
213         /* Set by the caller */
214         PFN_ON_CHILDDEVICE_CREATE OnChildDeviceCreate;
215         PFN_ON_CHILDDEVICE_DESTROY OnChildDeviceDestroy;
216         PFN_ON_CHILDDEVICE_ADD OnChildDeviceAdd;
217         PFN_ON_CHILDDEVICE_REMOVE OnChildDeviceRemove;
218
219         /* Set by the callee */
220         PFN_ON_ISR OnIsr;
221         PFN_ON_DPC OnMsgDpc;
222         PFN_ON_DPC OnEventDpc;
223         PFN_GET_CHANNEL_OFFERS GetChannelOffers;
224
225         VMBUS_GET_CHANNEL_INTERFACE GetChannelInterface;
226         VMBUS_GET_CHANNEL_INFO GetChannelInfo;
227 };
228
229 int VmbusInitialize(struct hv_driver *drv);
230
231 #endif /* _VMBUS_API_H_ */