]> git.karo-electronics.de Git - linux-beck.git/blob - drivers/staging/hv/vmbus_api.h
bd68a07f36cdc827fafda45e60af6d7892ed7394
[linux-beck.git] / drivers / staging / hv / vmbus_api.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 struct hv_dev_port_info {
62         u32 InterruptMask;
63         u32 ReadIndex;
64         u32 WriteIndex;
65         u32 BytesAvailToRead;
66         u32 BytesAvailToWrite;
67 };
68
69 struct hv_device_info {
70         u32 ChannelId;
71         u32 ChannelState;
72         struct hv_guid ChannelType;
73         struct hv_guid ChannelInstance;
74
75         u32 MonitorId;
76         u32 ServerMonitorPending;
77         u32 ServerMonitorLatency;
78         u32 ServerMonitorConnectionId;
79         u32 ClientMonitorPending;
80         u32 ClientMonitorLatency;
81         u32 ClientMonitorConnectionId;
82
83         struct hv_dev_port_info Inbound;
84         struct hv_dev_port_info Outbound;
85 };
86
87 /**
88  * struct vmbus_channel_interface - Contains member functions for vmbus channel
89  * @Open:      Open the channel
90  * @Close:     Close the channel
91  * @SendPacket:        Send a packet over the channel
92  * @SendPacketPageBuffer:      Send a single page buffer over the channel
93  * @SendPacketMultiPageBuffer: Send a multiple page buffers
94  * @RecvPacket:        Receive packet
95  * @RecvPacketRaw:     Receive Raw packet
96  * @EstablishGpadl:    Set up GPADL for ringbuffer
97  *
98  * This structure contains function pointer to control vmbus channel
99  * behavior. None of these functions is externally callable, but they
100  * are used for normal vmbus channel internal behavior.
101  * Only used by Hyper-V drivers.
102  */
103 struct vmbus_channel_interface {
104         int (*Open)(struct hv_device *Device, u32 SendBufferSize,
105                     u32 RecvRingBufferSize, void *UserData, u32 UserDataLen,
106                     void (*ChannelCallback)(void *context),
107                     void *Context);
108         void (*Close)(struct hv_device *device);
109         int (*SendPacket)(struct hv_device *Device, const void *Buffer,
110                           u32 BufferLen, u64 RequestId, u32 Type, u32 Flags);
111         int (*SendPacketPageBuffer)(struct hv_device *dev,
112                                     struct hv_page_buffer PageBuffers[],
113                                     u32 PageCount, void *Buffer, u32 BufferLen,
114                                     u64 RequestId);
115         int (*SendPacketMultiPageBuffer)(struct hv_device *device,
116                                          struct hv_multipage_buffer *mpb,
117                                          void *Buffer,
118                                          u32 BufferLen,
119                                          u64 RequestId);
120         int (*RecvPacket)(struct hv_device *dev, void *buf, u32 buflen,
121                           u32 *BufferActualLen, u64 *RequestId);
122         int (*RecvPacketRaw)(struct hv_device *dev, void *buf, u32 buflen,
123                              u32 *BufferActualLen, u64 *RequestId);
124         int (*EstablishGpadl)(struct hv_device *dev, void *buf, u32 buflen,
125                               u32 *GpadlHandle);
126 };
127
128 extern const struct vmbus_channel_interface vmbus_ops;
129
130
131 /* Base driver object */
132 struct hv_driver {
133         const char *name;
134
135         /* the device type supported by this driver */
136         struct hv_guid deviceType;
137
138         int (*OnDeviceAdd)(struct hv_device *device, void *data);
139         int (*OnDeviceRemove)(struct hv_device *device);
140         void (*OnCleanup)(struct hv_driver *driver);
141
142         struct vmbus_channel_interface VmbusChannelInterface;
143 };
144
145 /* Base device object */
146 struct hv_device {
147         /* the driver for this device */
148         struct hv_driver *Driver;
149
150         char name[64];
151
152         /* the device type id of this device */
153         struct hv_guid deviceType;
154
155         /* the device instance id of this device */
156         struct hv_guid deviceInstance;
157
158         void *context;
159
160         /* Device extension; */
161         void *Extension;
162 };
163
164 /* Vmbus driver object */
165 struct vmbus_driver {
166         /* !! Must be the 1st field !! */
167         /* FIXME if ^, then someone is doing somthing stupid */
168         struct hv_driver Base;
169
170         /* Set by the caller */
171         struct hv_device * (*OnChildDeviceCreate)(struct hv_guid *DeviceType,
172                                                 struct hv_guid *DeviceInstance,
173                                                 void *Context);
174         void (*OnChildDeviceDestroy)(struct hv_device *device);
175         int (*OnChildDeviceAdd)(struct hv_device *RootDevice,
176                                 struct hv_device *ChildDevice);
177         void (*OnChildDeviceRemove)(struct hv_device *device);
178
179         /* Set by the callee */
180         int (*OnIsr)(struct hv_driver *driver);
181         void (*OnMsgDpc)(struct hv_driver *driver);
182         void (*OnEventDpc)(struct hv_driver *driver);
183         void (*GetChannelOffers)(void);
184 };
185
186 int VmbusInitialize(struct hv_driver *drv);
187
188 #endif /* _VMBUS_API_H_ */