Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 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 | |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 28 | #define MAX_PAGE_BUFFER_COUNT 16 |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 29 | #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 30 | |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 31 | #pragma pack(push, 1) |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 32 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 33 | /* Single-page buffer */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 34 | typedef struct _PAGE_BUFFER { |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 35 | u32 Length; |
| 36 | u32 Offset; |
| 37 | u64 Pfn; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 38 | } PAGE_BUFFER; |
| 39 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 40 | /* Multiple-page buffer */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 41 | typedef struct _MULTIPAGE_BUFFER { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 42 | /* Length and Offset determines the # of pfns in the array */ |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 43 | u32 Length; |
| 44 | u32 Offset; |
| 45 | u64 PfnArray[MAX_MULTIPAGE_BUFFER_COUNT]; |
| 46 | } MULTIPAGE_BUFFER; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 47 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 48 | /* 0x18 includes the proprietary packet header */ |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 49 | #define MAX_PAGE_BUFFER_PACKET (0x18 + \ |
| 50 | (sizeof(PAGE_BUFFER) * \ |
| 51 | MAX_PAGE_BUFFER_COUNT)) |
| 52 | #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + sizeof(MULTIPAGE_BUFFER)) |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 53 | |
| 54 | |
| 55 | #pragma pack(pop) |
| 56 | |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 57 | struct hv_driver; |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 58 | struct hv_device; |
| 59 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 60 | /* All drivers */ |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 61 | typedef int (*PFN_ON_DEVICEADD)(struct hv_device *Device, |
| 62 | void *AdditionalInfo); |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 63 | typedef int (*PFN_ON_DEVICEREMOVE)(struct hv_device *Device); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 64 | typedef char** (*PFN_ON_GETDEVICEIDS)(void); |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 65 | typedef void (*PFN_ON_CLEANUP)(struct hv_driver *Driver); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 66 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 67 | /* Vmbus extensions */ |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 68 | typedef int (*PFN_ON_ISR)(struct hv_driver *drv); |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 69 | typedef void (*PFN_ON_DPC)(struct hv_driver *drv); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 70 | typedef void (*PFN_GET_CHANNEL_OFFERS)(void); |
| 71 | |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 72 | typedef struct hv_device *(*PFN_ON_CHILDDEVICE_CREATE) |
| 73 | (struct hv_guid *DeviceType, |
| 74 | struct hv_guid *DeviceInstance, |
| 75 | void *Context); |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 76 | typedef void (*PFN_ON_CHILDDEVICE_DESTROY)(struct hv_device *Device); |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 77 | typedef int (*PFN_ON_CHILDDEVICE_ADD)(struct hv_device *RootDevice, |
| 78 | struct hv_device *ChildDevice); |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 79 | typedef void (*PFN_ON_CHILDDEVICE_REMOVE)(struct hv_device *Device); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 80 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 81 | /* Vmbus channel interface */ |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 82 | typedef void (*VMBUS_CHANNEL_CALLBACK)(void *context); |
| 83 | typedef int (*VMBUS_CHANNEL_OPEN)(struct hv_device *Device, u32 SendBufferSize, |
| 84 | u32 RecvRingBufferSize, |
| 85 | void *UserData, |
| 86 | u32 UserDataLen, |
| 87 | VMBUS_CHANNEL_CALLBACK ChannelCallback, |
| 88 | void *Context); |
| 89 | typedef void (*VMBUS_CHANNEL_CLOSE)(struct hv_device *Device); |
| 90 | typedef int (*VMBUS_CHANNEL_SEND_PACKET)(struct hv_device *Device, |
| 91 | const void *Buffer, |
| 92 | u32 BufferLen, |
| 93 | u64 RequestId, |
| 94 | u32 Type, |
| 95 | u32 Flags); |
| 96 | typedef int (*VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER)(struct hv_device *Device, |
| 97 | PAGE_BUFFER PageBuffers[], |
| 98 | u32 PageCount, |
| 99 | void *Buffer, |
| 100 | u32 BufferLen, |
| 101 | u64 RequestId); |
| 102 | typedef int(*VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER) |
| 103 | (struct hv_device *Device, |
| 104 | MULTIPAGE_BUFFER *MultiPageBuffer, |
| 105 | void *Buffer, |
| 106 | u32 BufferLen, |
| 107 | u64 RequestId); |
| 108 | typedef int (*VMBUS_CHANNEL_RECV_PACKET)(struct hv_device *Device, |
| 109 | void *Buffer, |
| 110 | u32 BufferLen, |
| 111 | u32 *BufferActualLen, |
| 112 | u64 *RequestId); |
| 113 | typedef int(*VMBUS_CHANNEL_RECV_PACKET_PAW)(struct hv_device *Device, |
| 114 | void *Buffer, |
| 115 | u32 BufferLen, |
| 116 | u32 *BufferActualLen, |
| 117 | u64 *RequestId); |
| 118 | typedef int (*VMBUS_CHANNEL_ESTABLISH_GPADL)(struct hv_device *Device, |
| 119 | void *Buffer, |
| 120 | u32 BufferLen, |
| 121 | u32 *GpadlHandle); |
| 122 | typedef int (*VMBUS_CHANNEL_TEARDOWN_GPADL)(struct hv_device *Device, |
| 123 | u32 GpadlHandle); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 124 | |
| 125 | |
| 126 | typedef struct _PORT_INFO { |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 127 | u32 InterruptMask; |
| 128 | u32 ReadIndex; |
| 129 | u32 WriteIndex; |
| 130 | u32 BytesAvailToRead; |
| 131 | u32 BytesAvailToWrite; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 132 | } PORT_INFO; |
| 133 | |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 134 | typedef struct _DEVICE_INFO { |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 135 | u32 ChannelId; |
| 136 | u32 ChannelState; |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 137 | struct hv_guid ChannelType; |
| 138 | struct hv_guid ChannelInstance; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 139 | |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 140 | u32 MonitorId; |
| 141 | u32 ServerMonitorPending; |
| 142 | u32 ServerMonitorLatency; |
| 143 | u32 ServerMonitorConnectionId; |
| 144 | u32 ClientMonitorPending; |
| 145 | u32 ClientMonitorLatency; |
| 146 | u32 ClientMonitorConnectionId; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 147 | |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 148 | PORT_INFO Inbound; |
| 149 | PORT_INFO Outbound; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 150 | } DEVICE_INFO; |
| 151 | |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 152 | typedef void (*VMBUS_GET_CHANNEL_INFO)(struct hv_device *Device, |
| 153 | DEVICE_INFO *DeviceInfo); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 154 | |
| 155 | typedef struct _VMBUS_CHANNEL_INTERFACE { |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 156 | VMBUS_CHANNEL_OPEN Open; |
| 157 | VMBUS_CHANNEL_CLOSE Close; |
| 158 | VMBUS_CHANNEL_SEND_PACKET SendPacket; |
| 159 | VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER SendPacketPageBuffer; |
| 160 | VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER SendPacketMultiPageBuffer; |
| 161 | VMBUS_CHANNEL_RECV_PACKET RecvPacket; |
| 162 | VMBUS_CHANNEL_RECV_PACKET_PAW RecvPacketRaw; |
| 163 | VMBUS_CHANNEL_ESTABLISH_GPADL EstablishGpadl; |
| 164 | VMBUS_CHANNEL_TEARDOWN_GPADL TeardownGpadl; |
| 165 | VMBUS_GET_CHANNEL_INFO GetInfo; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 166 | } VMBUS_CHANNEL_INTERFACE; |
| 167 | |
| 168 | typedef void (*VMBUS_GET_CHANNEL_INTERFACE)(VMBUS_CHANNEL_INTERFACE *Interface); |
| 169 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 170 | /* Base driver object */ |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 171 | struct hv_driver { |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 172 | const char *name; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 173 | |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 174 | /* the device type supported by this driver */ |
| 175 | struct hv_guid deviceType; |
| 176 | |
| 177 | PFN_ON_DEVICEADD OnDeviceAdd; |
| 178 | PFN_ON_DEVICEREMOVE OnDeviceRemove; |
| 179 | |
| 180 | /* device ids supported by this driver */ |
| 181 | PFN_ON_GETDEVICEIDS OnGetDeviceIds; |
| 182 | PFN_ON_CLEANUP OnCleanup; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 183 | |
| 184 | VMBUS_CHANNEL_INTERFACE VmbusChannelInterface; |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 185 | }; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 186 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 187 | /* Base device object */ |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 188 | struct hv_device { |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 189 | /* the driver for this device */ |
| 190 | struct hv_driver *Driver; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 191 | |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 192 | char name[64]; |
| 193 | |
| 194 | /* the device type id of this device */ |
| 195 | struct hv_guid deviceType; |
| 196 | |
| 197 | /* the device instance id of this device */ |
| 198 | struct hv_guid deviceInstance; |
| 199 | |
| 200 | void *context; |
| 201 | |
| 202 | /* Device extension; */ |
| 203 | void *Extension; |
| 204 | }; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 205 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 206 | /* Vmbus driver object */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 207 | typedef struct _VMBUS_DRIVER_OBJECT { |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 208 | /* !! Must be the 1st field !! */ |
| 209 | /* FIXME if ^, then someone is doing somthing stupid */ |
| 210 | struct hv_driver Base; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 211 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 212 | /* Set by the caller */ |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 213 | PFN_ON_CHILDDEVICE_CREATE OnChildDeviceCreate; |
| 214 | PFN_ON_CHILDDEVICE_DESTROY OnChildDeviceDestroy; |
| 215 | PFN_ON_CHILDDEVICE_ADD OnChildDeviceAdd; |
| 216 | PFN_ON_CHILDDEVICE_REMOVE OnChildDeviceRemove; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 217 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 218 | /* Set by the callee */ |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 219 | PFN_ON_ISR OnIsr; |
| 220 | PFN_ON_DPC OnMsgDpc; |
| 221 | PFN_ON_DPC OnEventDpc; |
| 222 | PFN_GET_CHANNEL_OFFERS GetChannelOffers; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 223 | |
| 224 | VMBUS_GET_CHANNEL_INTERFACE GetChannelInterface; |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 225 | VMBUS_GET_CHANNEL_INFO GetChannelInfo; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 226 | } VMBUS_DRIVER_OBJECT; |
| 227 | |
Greg Kroah-Hartman | 54b2b84 | 2009-08-20 12:16:33 -0700 | [diff] [blame^] | 228 | int VmbusInitialize(struct hv_driver *drv); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 229 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 230 | #endif /* _VMBUS_API_H_ */ |