Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -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 | |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/mm.h> |
Greg Kroah-Hartman | 4983b39 | 2009-08-19 16:14:47 -0700 | [diff] [blame] | 26 | #include "osd.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 27 | #include "VmbusPrivate.h" |
| 28 | |
Greg Kroah-Hartman | 2be1301 | 2009-07-14 15:05:36 -0700 | [diff] [blame] | 29 | static int |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 30 | IVmbusChannelOpen( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 31 | struct hv_device *Device, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 32 | u32 SendBufferSize, |
| 33 | u32 RecvRingBufferSize, |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 34 | void * UserData, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 35 | u32 UserDataLen, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 36 | VMBUS_CHANNEL_CALLBACK ChannelCallback, |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 37 | void * Context |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 38 | ) |
| 39 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 40 | return VmbusChannelOpen((struct vmbus_channel *)Device->context, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 41 | SendBufferSize, |
| 42 | RecvRingBufferSize, |
| 43 | UserData, |
| 44 | UserDataLen, |
| 45 | ChannelCallback, |
| 46 | Context); |
| 47 | } |
| 48 | |
| 49 | |
Greg Kroah-Hartman | 2be1301 | 2009-07-14 15:05:36 -0700 | [diff] [blame] | 50 | static void |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 51 | IVmbusChannelClose( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 52 | struct hv_device *Device |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 53 | ) |
| 54 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 55 | VmbusChannelClose((struct vmbus_channel *)Device->context); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | |
Greg Kroah-Hartman | 2be1301 | 2009-07-14 15:05:36 -0700 | [diff] [blame] | 59 | static int |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 60 | IVmbusChannelSendPacket( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 61 | struct hv_device *Device, |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 62 | const void * Buffer, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 63 | u32 BufferLen, |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 64 | u64 RequestId, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 65 | u32 Type, |
| 66 | u32 Flags |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 67 | ) |
| 68 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 69 | return VmbusChannelSendPacket((struct vmbus_channel *)Device->context, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 70 | Buffer, |
| 71 | BufferLen, |
| 72 | RequestId, |
| 73 | Type, |
| 74 | Flags); |
| 75 | } |
| 76 | |
Greg Kroah-Hartman | 2be1301 | 2009-07-14 15:05:36 -0700 | [diff] [blame] | 77 | static int |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 78 | IVmbusChannelSendPacketPageBuffer( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 79 | struct hv_device *Device, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 80 | PAGE_BUFFER PageBuffers[], |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 81 | u32 PageCount, |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 82 | void * Buffer, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 83 | u32 BufferLen, |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 84 | u64 RequestId |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 85 | ) |
| 86 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 87 | return VmbusChannelSendPacketPageBuffer((struct vmbus_channel *)Device->context, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 88 | PageBuffers, |
| 89 | PageCount, |
| 90 | Buffer, |
| 91 | BufferLen, |
| 92 | RequestId); |
| 93 | } |
| 94 | |
Greg Kroah-Hartman | 2be1301 | 2009-07-14 15:05:36 -0700 | [diff] [blame] | 95 | static int |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 96 | IVmbusChannelSendPacketMultiPageBuffer( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 97 | struct hv_device *Device, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 98 | MULTIPAGE_BUFFER *MultiPageBuffer, |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 99 | void * Buffer, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 100 | u32 BufferLen, |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 101 | u64 RequestId |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 102 | ) |
| 103 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 104 | return VmbusChannelSendPacketMultiPageBuffer((struct vmbus_channel *)Device->context, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 105 | MultiPageBuffer, |
| 106 | Buffer, |
| 107 | BufferLen, |
| 108 | RequestId); |
| 109 | } |
| 110 | |
Greg Kroah-Hartman | 2be1301 | 2009-07-14 15:05:36 -0700 | [diff] [blame] | 111 | static int |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 112 | IVmbusChannelRecvPacket ( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 113 | struct hv_device *Device, |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 114 | void * Buffer, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 115 | u32 BufferLen, |
| 116 | u32* BufferActualLen, |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 117 | u64* RequestId |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 118 | ) |
| 119 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 120 | return VmbusChannelRecvPacket((struct vmbus_channel *)Device->context, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 121 | Buffer, |
| 122 | BufferLen, |
| 123 | BufferActualLen, |
| 124 | RequestId); |
| 125 | } |
| 126 | |
Greg Kroah-Hartman | 2be1301 | 2009-07-14 15:05:36 -0700 | [diff] [blame] | 127 | static int |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 128 | IVmbusChannelRecvPacketRaw( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 129 | struct hv_device *Device, |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 130 | void * Buffer, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 131 | u32 BufferLen, |
| 132 | u32* BufferActualLen, |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 133 | u64* RequestId |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 134 | ) |
| 135 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 136 | return VmbusChannelRecvPacketRaw((struct vmbus_channel *)Device->context, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 137 | Buffer, |
| 138 | BufferLen, |
| 139 | BufferActualLen, |
| 140 | RequestId); |
| 141 | } |
| 142 | |
Greg Kroah-Hartman | 2be1301 | 2009-07-14 15:05:36 -0700 | [diff] [blame] | 143 | static int |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 144 | IVmbusChannelEstablishGpadl( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 145 | struct hv_device *Device, |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 146 | void * Buffer, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 147 | u32 BufferLen, |
| 148 | u32* GpadlHandle |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 149 | ) |
| 150 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 151 | return VmbusChannelEstablishGpadl((struct vmbus_channel *)Device->context, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 152 | Buffer, |
| 153 | BufferLen, |
| 154 | GpadlHandle); |
| 155 | } |
| 156 | |
Greg Kroah-Hartman | 2be1301 | 2009-07-14 15:05:36 -0700 | [diff] [blame] | 157 | static int |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 158 | IVmbusChannelTeardownGpadl( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 159 | struct hv_device *Device, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 160 | u32 GpadlHandle |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 161 | ) |
| 162 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 163 | return VmbusChannelTeardownGpadl((struct vmbus_channel *)Device->context, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 164 | GpadlHandle); |
| 165 | |
| 166 | } |
| 167 | |
Greg Kroah-Hartman | e89ce62 | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 168 | void GetChannelInterface(VMBUS_CHANNEL_INTERFACE *ChannelInterface) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | e89ce62 | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 183 | void GetChannelInfo(struct hv_device *Device, DEVICE_INFO *DeviceInfo) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 184 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 185 | struct vmbus_channel_debug_info debugInfo; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 186 | |
| 187 | if (Device->context) |
| 188 | { |
Greg Kroah-Hartman | aded7165 | 2009-08-18 15:21:19 -0700 | [diff] [blame] | 189 | VmbusChannelGetDebugInfo((struct vmbus_channel *)Device->context, &debugInfo); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 190 | |
| 191 | DeviceInfo->ChannelId = debugInfo.RelId; |
| 192 | DeviceInfo->ChannelState = debugInfo.State; |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 193 | memcpy(&DeviceInfo->ChannelType, &debugInfo.InterfaceType, sizeof(struct hv_guid)); |
| 194 | memcpy(&DeviceInfo->ChannelInstance, &debugInfo.InterfaceInstance, sizeof(struct hv_guid)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 195 | |
| 196 | DeviceInfo->MonitorId = debugInfo.MonitorId; |
| 197 | |
| 198 | DeviceInfo->ServerMonitorPending = debugInfo.ServerMonitorPending; |
| 199 | DeviceInfo->ServerMonitorLatency = debugInfo.ServerMonitorLatency; |
| 200 | DeviceInfo->ServerMonitorConnectionId = debugInfo.ServerMonitorConnectionId; |
| 201 | |
| 202 | DeviceInfo->ClientMonitorPending = debugInfo.ClientMonitorPending; |
| 203 | DeviceInfo->ClientMonitorLatency = debugInfo.ClientMonitorLatency; |
| 204 | DeviceInfo->ClientMonitorConnectionId = debugInfo.ClientMonitorConnectionId; |
| 205 | |
| 206 | DeviceInfo->Inbound.InterruptMask = debugInfo.Inbound.CurrentInterruptMask; |
| 207 | DeviceInfo->Inbound.ReadIndex = debugInfo.Inbound.CurrentReadIndex; |
| 208 | DeviceInfo->Inbound.WriteIndex = debugInfo.Inbound.CurrentWriteIndex; |
| 209 | DeviceInfo->Inbound.BytesAvailToRead = debugInfo.Inbound.BytesAvailToRead; |
| 210 | DeviceInfo->Inbound.BytesAvailToWrite = debugInfo.Inbound.BytesAvailToWrite; |
| 211 | |
| 212 | DeviceInfo->Outbound.InterruptMask = debugInfo.Outbound.CurrentInterruptMask; |
| 213 | DeviceInfo->Outbound.ReadIndex = debugInfo.Outbound.CurrentReadIndex; |
| 214 | DeviceInfo->Outbound.WriteIndex = debugInfo.Outbound.CurrentWriteIndex; |
| 215 | DeviceInfo->Outbound.BytesAvailToRead = debugInfo.Outbound.BytesAvailToRead; |
| 216 | DeviceInfo->Outbound.BytesAvailToWrite = debugInfo.Outbound.BytesAvailToWrite; |
| 217 | } |
| 218 | } |