summaryrefslogtreecommitdiff
path: root/drivers/staging/hv/include/VmbusApi.h
blob: 0a870855028e2da8cf418c344702d790e7d10eca (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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
 *
 * 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>
 *
 */


#ifndef _VMBUS_API_H_
#define _VMBUS_API_H_

#include "osd.h"


/* Defines */


#define MAX_PAGE_BUFFER_COUNT				16
#define MAX_MULTIPAGE_BUFFER_COUNT			32 /* 128K */

/* Data types */


#pragma pack(push,1)

/* Single-page buffer */
typedef struct _PAGE_BUFFER {
	u32	Length;
	u32	Offset;
	u64	Pfn;
} PAGE_BUFFER;

/* Multiple-page buffer */
typedef struct _MULTIPAGE_BUFFER {
	/* Length and Offset determines the # of pfns in the array */
	u32	Length;
	u32	Offset;
	u64	PfnArray[MAX_MULTIPAGE_BUFFER_COUNT];
}MULTIPAGE_BUFFER;

/* 0x18 includes the proprietary packet header */
#define MAX_PAGE_BUFFER_PACKET			(0x18 + (sizeof(PAGE_BUFFER) * MAX_PAGE_BUFFER_COUNT))
#define MAX_MULTIPAGE_BUFFER_PACKET		(0x18 + sizeof(MULTIPAGE_BUFFER))


#pragma pack(pop)

struct hv_driver;
struct hv_device;

/* All drivers */
typedef int (*PFN_ON_DEVICEADD)(struct hv_device *Device, void* AdditionalInfo);
typedef int (*PFN_ON_DEVICEREMOVE)(struct hv_device *Device);
typedef char** (*PFN_ON_GETDEVICEIDS)(void);
typedef void (*PFN_ON_CLEANUP)(struct hv_driver *Driver);

/* Vmbus extensions */
/* typedef int (*PFN_ON_MATCH)(struct hv_device *dev, struct hv_driver *drv); */
/* typedef int (*PFN_ON_PROBE)(struct hv_device *dev); */
typedef int	(*PFN_ON_ISR)(struct hv_driver *drv);
typedef void (*PFN_ON_DPC)(struct hv_driver *drv);
typedef void (*PFN_GET_CHANNEL_OFFERS)(void);

typedef struct hv_device *(*PFN_ON_CHILDDEVICE_CREATE)(GUID DeviceType, GUID DeviceInstance, void *Context);
typedef void (*PFN_ON_CHILDDEVICE_DESTROY)(struct hv_device *Device);
typedef int (*PFN_ON_CHILDDEVICE_ADD)(struct hv_device *RootDevice, struct hv_device *ChildDevice);
typedef void (*PFN_ON_CHILDDEVICE_REMOVE)(struct hv_device *Device);

/* Vmbus channel interface */
typedef void (*VMBUS_CHANNEL_CALLBACK)(void * context);

typedef int	(*VMBUS_CHANNEL_OPEN)(
	struct hv_device *Device,
	u32				SendBufferSize,
	u32				RecvRingBufferSize,
	void *				UserData,
	u32				UserDataLen,
	VMBUS_CHANNEL_CALLBACK ChannelCallback,
	void *				Context
	);

typedef void (*VMBUS_CHANNEL_CLOSE)(
	struct hv_device *Device
	);

typedef int	(*VMBUS_CHANNEL_SEND_PACKET)(
	struct hv_device *Device,
	const void *			Buffer,
	u32				BufferLen,
	u64				RequestId,
	u32				Type,
	u32				Flags
);

typedef int	(*VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER)(
	struct hv_device *Device,
	PAGE_BUFFER			PageBuffers[],
	u32				PageCount,
	void *				Buffer,
	u32				BufferLen,
	u64				RequestId
	);

typedef int	(*VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER)(
	struct hv_device *Device,
	MULTIPAGE_BUFFER	*MultiPageBuffer,
	void *				Buffer,
	u32				BufferLen,
	u64				RequestId
);

typedef int	(*VMBUS_CHANNEL_RECV_PACKET)(
	struct hv_device *Device,
	void *				Buffer,
	u32				BufferLen,
	u32*				BufferActualLen,
	u64*				RequestId
	);

typedef int	(*VMBUS_CHANNEL_RECV_PACKET_PAW)(
	struct hv_device *Device,
	void *				Buffer,
	u32				BufferLen,
	u32*				BufferActualLen,
	u64*				RequestId
	);

typedef int	(*VMBUS_CHANNEL_ESTABLISH_GPADL)(
	struct hv_device *Device,
	void *				Buffer,	/* from kmalloc() */
	u32				BufferLen,		/* page-size multiple */
	u32*				GpadlHandle
	);

typedef int	(*VMBUS_CHANNEL_TEARDOWN_GPADL)(
	struct hv_device *Device,
	u32				GpadlHandle
	);


typedef struct _PORT_INFO {
	u32		InterruptMask;
	u32		ReadIndex;
	u32		WriteIndex;
	u32		BytesAvailToRead;
	u32		BytesAvailToWrite;
} PORT_INFO;


typedef struct _DEVICE_INFO {
	u32		ChannelId;
	u32		ChannelState;
	GUID		ChannelType;
	GUID		ChannelInstance;

	u32						MonitorId;
	u32						ServerMonitorPending;
	u32						ServerMonitorLatency;
	u32						ServerMonitorConnectionId;
	u32						ClientMonitorPending;
	u32						ClientMonitorLatency;
	u32						ClientMonitorConnectionId;

	PORT_INFO	Inbound;
	PORT_INFO	Outbound;
} DEVICE_INFO;

typedef void (*VMBUS_GET_CHANNEL_INFO)(struct hv_device *Device, DEVICE_INFO* DeviceInfo);

typedef struct _VMBUS_CHANNEL_INTERFACE {
	VMBUS_CHANNEL_OPEN							Open;
	VMBUS_CHANNEL_CLOSE							Close;
	VMBUS_CHANNEL_SEND_PACKET					SendPacket;
	VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER		SendPacketPageBuffer;
	VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER	SendPacketMultiPageBuffer;
	VMBUS_CHANNEL_RECV_PACKET					RecvPacket;
	VMBUS_CHANNEL_RECV_PACKET_PAW				RecvPacketRaw;
	VMBUS_CHANNEL_ESTABLISH_GPADL				EstablishGpadl;
	VMBUS_CHANNEL_TEARDOWN_GPADL				TeardownGpadl;
	VMBUS_GET_CHANNEL_INFO						GetInfo;
} VMBUS_CHANNEL_INTERFACE;

typedef void (*VMBUS_GET_CHANNEL_INTERFACE)(VMBUS_CHANNEL_INTERFACE *Interface);

/* Base driver object */
struct hv_driver {
	const char*				name;
	GUID					deviceType; /* the device type supported by this driver */

	PFN_ON_DEVICEADD		OnDeviceAdd;
	PFN_ON_DEVICEREMOVE		OnDeviceRemove;
	PFN_ON_GETDEVICEIDS		OnGetDeviceIds; /* device ids supported by this driver */
	PFN_ON_CLEANUP			OnCleanup;

	VMBUS_CHANNEL_INTERFACE VmbusChannelInterface;
};


/* Base device object */
struct hv_device {
	struct hv_driver *Driver;		/* the driver for this device */
	char				name[64];
	GUID				deviceType; /* the device type id of this device */
	GUID				deviceInstance; /* the device instance id of this device */
	void*				context;
	void*				Extension;		/* Device extension; */
};


/* Vmbus driver object */
typedef struct _VMBUS_DRIVER_OBJECT {
	struct hv_driver Base; /* !! Must be the 1st field !! */

	/* Set by the caller */
	PFN_ON_CHILDDEVICE_CREATE	OnChildDeviceCreate;
	PFN_ON_CHILDDEVICE_DESTROY	OnChildDeviceDestroy;
	PFN_ON_CHILDDEVICE_ADD		OnChildDeviceAdd;
	PFN_ON_CHILDDEVICE_REMOVE	OnChildDeviceRemove;

	/* Set by the callee */
	/* PFN_ON_MATCH		OnMatch; */
	/* PFN_ON_PROBE		OnProbe; */
	PFN_ON_ISR				OnIsr;
	PFN_ON_DPC				OnMsgDpc;
	PFN_ON_DPC				OnEventDpc;
	PFN_GET_CHANNEL_OFFERS	GetChannelOffers;

	VMBUS_GET_CHANNEL_INTERFACE GetChannelInterface;
	VMBUS_GET_CHANNEL_INFO		GetChannelInfo;
} VMBUS_DRIVER_OBJECT;



/* Interface */

int
VmbusInitialize(
	struct hv_driver *drv
	);

#endif /* _VMBUS_API_H_ */