Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
[pandora-kernel.git] / drivers / staging / hv / vmbus_private.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 "vmbus_api.h"
30 #include "channel.h"
31 #include "channel_mgmt.h"
32 #include "ring_buffer.h"
33 #include <linux/list.h>
34
35
36 /*
37  * Maximum channels is determined by the size of the interrupt page
38  * which is PAGE_SIZE. 1/2 of PAGE_SIZE is for send endpoint interrupt
39  * and the other is receive endpoint interrupt
40  */
41 #define MAX_NUM_CHANNELS        ((PAGE_SIZE >> 1) << 3) /* 16348 channels */
42
43 /* The value here must be in multiple of 32 */
44 /* TODO: Need to make this configurable */
45 #define MAX_NUM_CHANNELS_SUPPORTED      256
46
47
48 enum VMBUS_CONNECT_STATE {
49         Disconnected,
50         Connecting,
51         Connected,
52         Disconnecting
53 };
54
55 #define MAX_SIZE_CHANNEL_MESSAGE        HV_MESSAGE_PAYLOAD_BYTE_COUNT
56
57 struct VMBUS_CONNECTION {
58         enum VMBUS_CONNECT_STATE ConnectState;
59
60         atomic_t NextGpadlHandle;
61
62         /*
63          * Represents channel interrupts. Each bit position represents a
64          * channel.  When a channel sends an interrupt via VMBUS, it finds its
65          * bit in the sendInterruptPage, set it and calls Hv to generate a port
66          * event. The other end receives the port event and parse the
67          * recvInterruptPage to see which bit is set
68          */
69         void *InterruptPage;
70         void *SendInterruptPage;
71         void *RecvInterruptPage;
72
73         /*
74          * 2 pages - 1st page for parent->child notification and 2nd
75          * is child->parent notification
76          */
77         void *MonitorPages;
78         struct list_head ChannelMsgList;
79         spinlock_t channelmsg_lock;
80
81         /* List of channels */
82         struct list_head ChannelList;
83         spinlock_t channel_lock;
84
85         struct workqueue_struct *WorkQueue;
86 };
87
88
89 struct VMBUS_MSGINFO {
90         /* Bookkeeping stuff */
91         struct list_head MsgListEntry;
92
93         /* Synchronize the request/response if needed */
94         struct osd_waitevent *WaitEvent;
95
96         /* The message itself */
97         unsigned char Msg[0];
98 };
99
100
101 extern struct VMBUS_CONNECTION gVmbusConnection;
102
103 /* General vmbus interface */
104
105 struct hv_device *VmbusChildDeviceCreate(struct hv_guid *deviceType,
106                                          struct hv_guid *deviceInstance,
107                                          struct vmbus_channel *channel);
108
109 int VmbusChildDeviceAdd(struct hv_device *Device);
110
111 void VmbusChildDeviceRemove(struct hv_device *Device);
112
113 /* static void */
114 /* VmbusChildDeviceDestroy( */
115 /* struct hv_device *); */
116
117 struct vmbus_channel *GetChannelFromRelId(u32 relId);
118
119
120 /* Connection interface */
121
122 int VmbusConnect(void);
123
124 int VmbusDisconnect(void);
125
126 int VmbusPostMessage(void *buffer, size_t bufSize);
127
128 int VmbusSetEvent(u32 childRelId);
129
130 void VmbusOnEvents(void);
131
132
133 #endif /* _VMBUS_PRIVATE_H_ */