aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging/hv/ChannelInterface.c
blob: 3463ea3640eabaff6a11e0d6aed83c04ccfde9cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 *
 * Copyright (c) 2009, Microsoft Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307 USA.
 *
 * Authors:
 *   Haiyang Zhang <haiyangz@microsoft.com>
 *   Hank Janssen  <hjanssen@microsoft.com>
 *
 */

#include <linux/kernel.h>
#include <linux/mm.h>
#include "osd.h"
#include "VmbusPrivate.h"

static int
IVmbusChannelOpen(
	struct hv_device *Device,
	u32				SendBufferSize,
	u32				RecvRingBufferSize,
	void *				UserData,
	u32				UserDataLen,
	VMBUS_CHANNEL_CALLBACK ChannelCallback,
	void *				Context
	)
{
	return VmbusChannelOpen((struct vmbus_channel *)Device->context,
								SendBufferSize,
								RecvRingBufferSize,
								UserData,
								UserDataLen,
								ChannelCallback,
								Context);
}


static void
IVmbusChannelClose(
	struct hv_device *Device
	)
{
	VmbusChannelClose((struct vmbus_channel *)Device->context);
}


static int
IVmbusChannelSendPacket(
	struct hv_device *Device,
	const void *			Buffer,
	u32				BufferLen,
	u64				RequestId,
	u32				Type,
	u32				Flags
	)
{
	return VmbusChannelSendPacket((struct vmbus_channel *)Device->context,
									Buffer,
									BufferLen,
									RequestId,
									Type,
									Flags);
}

static int
IVmbusChannelSendPacketPageBuffer(
	struct hv_device *Device,
	struct hv_page_buffer PageBuffers[],
	u32				PageCount,
	void *				Buffer,
	u32				BufferLen,
	u64				RequestId
	)
{
	return VmbusChannelSendPacketPageBuffer((struct vmbus_channel *)Device->context,
												PageBuffers,
												PageCount,
												Buffer,
												BufferLen,
												RequestId);
}

static int
IVmbusChannelSendPacketMultiPageBuffer(
	struct hv_device *Device,
	struct hv_multipage_buffer *MultiPageBuffer,
	void *				Buffer,
	u32				BufferLen,
	u64				RequestId
	)
{
	return VmbusChannelSendPacketMultiPageBuffer((struct vmbus_channel *)Device->context,
													MultiPageBuffer,
													Buffer,
													BufferLen,
													RequestId);
}

static int
IVmbusChannelRecvPacket (
	struct hv_device *Device,
	void *				Buffer,
	u32				BufferLen,
	u32*				BufferActualLen,
	u64*				RequestId
	)
{
	return VmbusChannelRecvPacket((struct vmbus_channel *)Device->context,
									Buffer,
									BufferLen,
									BufferActualLen,
									RequestId);
}

static int
IVmbusChannelRecvPacketRaw(
	struct hv_device *Device,
	void *				Buffer,
	u32				BufferLen,
	u32*				BufferActualLen,
	u64*				RequestId
	)
{
	return VmbusChannelRecvPacketRaw((struct vmbus_channel *)Device->context,
										Buffer,
										BufferLen,
										BufferActualLen,
										RequestId);
}

static int
IVmbusChannelEstablishGpadl(
	struct hv_device *Device,
	void *				Buffer,
	u32				BufferLen,
	u32*				GpadlHandle
	)
{
	return VmbusChannelEstablishGpadl((struct vmbus_channel *)Device->context,
										Buffer,
										BufferLen,
										GpadlHandle);
}

static int
IVmbusChannelTeardownGpadl(
   struct hv_device *Device,
   u32				GpadlHandle
	)
{
	return VmbusChannelTeardownGpadl((struct vmbus_channel *)Device->context,
										GpadlHandle);

}

void GetChannelInterface(struct vmbus_channel_interface *ChannelInterface)
{
	ChannelInterface->Open						= IVmbusChannelOpen;
	ChannelInterface->Close						= IVmbusChannelClose;
	ChannelInterface->SendPacket				= IVmbusChannelSendPacket;
	ChannelInterface->SendPacketPageBuffer		= IVmbusChannelSendPacketPageBuffer;
	ChannelInterface->SendPacketMultiPageBuffer = IVmbusChannelSendPacketMultiPageBuffer;
	ChannelInterface->RecvPacket				= IVmbusChannelRecvPacket;
	ChannelInterface->RecvPacketRaw				= IVmbusChannelRecvPacketRaw;
	ChannelInterface->EstablishGpadl			= IVmbusChannelEstablishGpadl;
	ChannelInterface->TeardownGpadl				= IVmbusChannelTeardownGpadl;
	ChannelInterface->GetInfo					= GetChannelInfo;
}


void GetChannelInfo(struct hv_device *Device, struct hv_device_info *DeviceInfo)
{
	struct vmbus_channel_debug_info debugInfo;

	if (Device->context)
	{
		VmbusChannelGetDebugInfo((struct vmbus_channel *)Device->context, &debugInfo);

		DeviceInfo->ChannelId = debugInfo.RelId;
		DeviceInfo->ChannelState = debugInfo.State;
		memcpy(&DeviceInfo->ChannelType, &debugInfo.InterfaceType, sizeof(struct hv_guid));
		memcpy(&DeviceInfo->ChannelInstance, &debugInfo.InterfaceInstance, sizeof(struct hv_guid));

		DeviceInfo->MonitorId = debugInfo.MonitorId;

		DeviceInfo->ServerMonitorPending = debugInfo.ServerMonitorPending;
		DeviceInfo->ServerMonitorLatency = debugInfo.ServerMonitorLatency;
		DeviceInfo->ServerMonitorConnectionId = debugInfo.ServerMonitorConnectionId;

		DeviceInfo->ClientMonitorPending = debugInfo.ClientMonitorPending;
		DeviceInfo->ClientMonitorLatency = debugInfo.ClientMonitorLatency;
		DeviceInfo->ClientMonitorConnectionId = debugInfo.ClientMonitorConnectionId;

		DeviceInfo->Inbound.InterruptMask = debugInfo.Inbound.CurrentInterruptMask;
		DeviceInfo->Inbound.ReadIndex = debugInfo.Inbound.CurrentReadIndex;
		DeviceInfo->Inbound.WriteIndex = debugInfo.Inbound.CurrentWriteIndex;
		DeviceInfo->Inbound.BytesAvailToRead = debugInfo.Inbound.BytesAvailToRead;
		DeviceInfo->Inbound.BytesAvailToWrite = debugInfo.Inbound.BytesAvailToWrite;

		DeviceInfo->Outbound.InterruptMask = debugInfo.Outbound.CurrentInterruptMask;
		DeviceInfo->Outbound.ReadIndex = debugInfo.Outbound.CurrentReadIndex;
		DeviceInfo->Outbound.WriteIndex = debugInfo.Outbound.CurrentWriteIndex;
		DeviceInfo->Outbound.BytesAvailToRead = debugInfo.Outbound.BytesAvailToRead;
		DeviceInfo->Outbound.BytesAvailToWrite = debugInfo.Outbound.BytesAvailToWrite;
	}
}