]> Pileus Git - ~andy/linux/blob - drivers/staging/hv/ChannelInterface.c
Staging: hv: remove UINT32 and INT32 typedefs
[~andy/linux] / drivers / staging / hv / ChannelInterface.c
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 #include "VmbusPrivate.h"
25
26 static int
27 IVmbusChannelOpen(
28         PDEVICE_OBJECT          Device,
29         u32                             SendBufferSize,
30         u32                             RecvRingBufferSize,
31         void *                          UserData,
32         u32                             UserDataLen,
33         VMBUS_CHANNEL_CALLBACK ChannelCallback,
34         void *                          Context
35         )
36 {
37         return VmbusChannelOpen( (VMBUS_CHANNEL*)Device->context,
38                                                                 SendBufferSize,
39                                                                 RecvRingBufferSize,
40                                                                 UserData,
41                                                                 UserDataLen,
42                                                                 ChannelCallback,
43                                                                 Context);
44 }
45
46
47 static void
48 IVmbusChannelClose(
49         PDEVICE_OBJECT          Device
50         )
51 {
52         VmbusChannelClose((VMBUS_CHANNEL*)Device->context);
53 }
54
55
56 static int
57 IVmbusChannelSendPacket(
58         PDEVICE_OBJECT          Device,
59         const void *                    Buffer,
60         u32                             BufferLen,
61         UINT64                          RequestId,
62         u32                             Type,
63         u32                             Flags
64         )
65 {
66         return VmbusChannelSendPacket((VMBUS_CHANNEL*)Device->context,
67                                                                         Buffer,
68                                                                         BufferLen,
69                                                                         RequestId,
70                                                                         Type,
71                                                                         Flags);
72 }
73
74 static int
75 IVmbusChannelSendPacketPageBuffer(
76         PDEVICE_OBJECT          Device,
77         PAGE_BUFFER                     PageBuffers[],
78         u32                             PageCount,
79         void *                          Buffer,
80         u32                             BufferLen,
81         UINT64                          RequestId
82         )
83 {
84         return VmbusChannelSendPacketPageBuffer((VMBUS_CHANNEL*)Device->context,
85                                                                                                 PageBuffers,
86                                                                                                 PageCount,
87                                                                                                 Buffer,
88                                                                                                 BufferLen,
89                                                                                                 RequestId);
90 }
91
92 static int
93 IVmbusChannelSendPacketMultiPageBuffer(
94         PDEVICE_OBJECT          Device,
95         MULTIPAGE_BUFFER        *MultiPageBuffer,
96         void *                          Buffer,
97         u32                             BufferLen,
98         UINT64                          RequestId
99         )
100 {
101         return VmbusChannelSendPacketMultiPageBuffer((VMBUS_CHANNEL*)Device->context,
102                                                                                                         MultiPageBuffer,
103                                                                                                         Buffer,
104                                                                                                         BufferLen,
105                                                                                                         RequestId);
106 }
107
108 static int
109 IVmbusChannelRecvPacket (
110         PDEVICE_OBJECT          Device,
111         void *                          Buffer,
112         u32                             BufferLen,
113         u32*                            BufferActualLen,
114         UINT64*                         RequestId
115         )
116 {
117         return VmbusChannelRecvPacket((VMBUS_CHANNEL*)Device->context,
118                                                                         Buffer,
119                                                                         BufferLen,
120                                                                         BufferActualLen,
121                                                                         RequestId);
122 }
123
124 static int
125 IVmbusChannelRecvPacketRaw(
126         PDEVICE_OBJECT          Device,
127         void *                          Buffer,
128         u32                             BufferLen,
129         u32*                            BufferActualLen,
130         UINT64*                         RequestId
131         )
132 {
133         return VmbusChannelRecvPacketRaw((VMBUS_CHANNEL*)Device->context,
134                                                                                 Buffer,
135                                                                                 BufferLen,
136                                                                                 BufferActualLen,
137                                                                                 RequestId);
138 }
139
140 static int
141 IVmbusChannelEstablishGpadl(
142         PDEVICE_OBJECT          Device,
143         void *                          Buffer,
144         u32                             BufferLen,
145         u32*                            GpadlHandle
146         )
147 {
148         return VmbusChannelEstablishGpadl((VMBUS_CHANNEL*)Device->context,
149                                                                                 Buffer,
150                                                                                 BufferLen,
151                                                                                 GpadlHandle);
152 }
153
154 static int
155 IVmbusChannelTeardownGpadl(
156    PDEVICE_OBJECT               Device,
157    u32                          GpadlHandle
158         )
159 {
160         return VmbusChannelTeardownGpadl((VMBUS_CHANNEL*)Device->context,
161                                                                                 GpadlHandle);
162
163 }
164
165 static void
166 GetChannelInterface(
167         VMBUS_CHANNEL_INTERFACE *ChannelInterface
168         )
169 {
170         ChannelInterface->Open                                          = IVmbusChannelOpen;
171         ChannelInterface->Close                                         = IVmbusChannelClose;
172         ChannelInterface->SendPacket                            = IVmbusChannelSendPacket;
173         ChannelInterface->SendPacketPageBuffer          = IVmbusChannelSendPacketPageBuffer;
174         ChannelInterface->SendPacketMultiPageBuffer = IVmbusChannelSendPacketMultiPageBuffer;
175         ChannelInterface->RecvPacket                            = IVmbusChannelRecvPacket;
176         ChannelInterface->RecvPacketRaw                         = IVmbusChannelRecvPacketRaw;
177         ChannelInterface->EstablishGpadl                        = IVmbusChannelEstablishGpadl;
178         ChannelInterface->TeardownGpadl                         = IVmbusChannelTeardownGpadl;
179         ChannelInterface->GetInfo                                       = GetChannelInfo;
180 }
181
182
183 static void
184 GetChannelInfo(
185         PDEVICE_OBJECT          Device,
186         DEVICE_INFO                     *DeviceInfo
187                            )
188 {
189         VMBUS_CHANNEL_DEBUG_INFO debugInfo;
190
191         if (Device->context)
192         {
193                 VmbusChannelGetDebugInfo((VMBUS_CHANNEL*)Device->context, &debugInfo);
194
195                 DeviceInfo->ChannelId = debugInfo.RelId;
196                 DeviceInfo->ChannelState = debugInfo.State;
197                 memcpy(&DeviceInfo->ChannelType, &debugInfo.InterfaceType, sizeof(GUID));
198                 memcpy(&DeviceInfo->ChannelInstance, &debugInfo.InterfaceInstance, sizeof(GUID));
199
200                 DeviceInfo->MonitorId = debugInfo.MonitorId;
201
202                 DeviceInfo->ServerMonitorPending = debugInfo.ServerMonitorPending;
203                 DeviceInfo->ServerMonitorLatency = debugInfo.ServerMonitorLatency;
204                 DeviceInfo->ServerMonitorConnectionId = debugInfo.ServerMonitorConnectionId;
205
206                 DeviceInfo->ClientMonitorPending = debugInfo.ClientMonitorPending;
207                 DeviceInfo->ClientMonitorLatency = debugInfo.ClientMonitorLatency;
208                 DeviceInfo->ClientMonitorConnectionId = debugInfo.ClientMonitorConnectionId;
209
210                 DeviceInfo->Inbound.InterruptMask = debugInfo.Inbound.CurrentInterruptMask;
211                 DeviceInfo->Inbound.ReadIndex = debugInfo.Inbound.CurrentReadIndex;
212                 DeviceInfo->Inbound.WriteIndex = debugInfo.Inbound.CurrentWriteIndex;
213                 DeviceInfo->Inbound.BytesAvailToRead = debugInfo.Inbound.BytesAvailToRead;
214                 DeviceInfo->Inbound.BytesAvailToWrite = debugInfo.Inbound.BytesAvailToWrite;
215
216                 DeviceInfo->Outbound.InterruptMask = debugInfo.Outbound.CurrentInterruptMask;
217                 DeviceInfo->Outbound.ReadIndex = debugInfo.Outbound.CurrentReadIndex;
218                 DeviceInfo->Outbound.WriteIndex = debugInfo.Outbound.CurrentWriteIndex;
219                 DeviceInfo->Outbound.BytesAvailToRead = debugInfo.Outbound.BytesAvailToRead;
220                 DeviceInfo->Outbound.BytesAvailToWrite = debugInfo.Outbound.BytesAvailToWrite;
221         }
222 }