blob: 019b064f7cb3d7130269a4445716f3389bc90373 [file] [log] [blame]
Hank Janssen3e7ee492009-07-13 16:02:34 -07001/*
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 */
Greg Kroah-Hartmana0086dc2009-08-17 17:22:08 -070023#include <linux/kernel.h>
24#include <linux/mm.h>
Greg Kroah-Hartman4983b392009-08-19 16:14:47 -070025#include "osd.h"
Hank Janssen3e7ee492009-07-13 16:02:34 -070026#include "VmbusPrivate.h"
27
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070028static int IVmbusChannelOpen(struct hv_device *device, u32 SendBufferSize,
29 u32 RecvRingBufferSize, void *UserData,
30 u32 UserDataLen,
Greg Kroah-Hartman74982612009-09-02 11:18:10 -070031 void (*ChannelCallback)(void *context),
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070032 void *Context)
Hank Janssen3e7ee492009-07-13 16:02:34 -070033{
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070034 return VmbusChannelOpen(device->context, SendBufferSize,
35 RecvRingBufferSize, UserData, UserDataLen,
36 ChannelCallback, Context);
Hank Janssen3e7ee492009-07-13 16:02:34 -070037}
38
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070039static void IVmbusChannelClose(struct hv_device *device)
Hank Janssen3e7ee492009-07-13 16:02:34 -070040{
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070041 VmbusChannelClose(device->context);
Hank Janssen3e7ee492009-07-13 16:02:34 -070042}
43
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070044static int IVmbusChannelSendPacket(struct hv_device *device, const void *Buffer,
45 u32 BufferLen, u64 RequestId, u32 Type,
46 u32 Flags)
Hank Janssen3e7ee492009-07-13 16:02:34 -070047{
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070048 return VmbusChannelSendPacket(device->context, Buffer, BufferLen,
49 RequestId, Type, Flags);
Hank Janssen3e7ee492009-07-13 16:02:34 -070050}
51
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070052static int IVmbusChannelSendPacketPageBuffer(struct hv_device *device,
53 struct hv_page_buffer PageBuffers[],
54 u32 PageCount, void *Buffer,
55 u32 BufferLen, u64 RequestId)
Hank Janssen3e7ee492009-07-13 16:02:34 -070056{
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070057 return VmbusChannelSendPacketPageBuffer(device->context, PageBuffers,
58 PageCount, Buffer, BufferLen,
59 RequestId);
Hank Janssen3e7ee492009-07-13 16:02:34 -070060}
61
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070062static int IVmbusChannelSendPacketMultiPageBuffer(struct hv_device *device,
63 struct hv_multipage_buffer *MultiPageBuffer,
64 void *Buffer, u32 BufferLen, u64 RequestId)
Hank Janssen3e7ee492009-07-13 16:02:34 -070065{
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070066 return VmbusChannelSendPacketMultiPageBuffer(device->context,
67 MultiPageBuffer, Buffer,
68 BufferLen, RequestId);
Hank Janssen3e7ee492009-07-13 16:02:34 -070069}
70
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070071static int IVmbusChannelRecvPacket(struct hv_device *device, void *Buffer,
72 u32 BufferLen, u32 *BufferActualLen,
73 u64 *RequestId)
Hank Janssen3e7ee492009-07-13 16:02:34 -070074{
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070075 return VmbusChannelRecvPacket(device->context, Buffer, BufferLen,
76 BufferActualLen, RequestId);
Hank Janssen3e7ee492009-07-13 16:02:34 -070077}
78
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070079static int IVmbusChannelRecvPacketRaw(struct hv_device *device, void *Buffer,
80 u32 BufferLen, u32 *BufferActualLen,
81 u64 *RequestId)
Hank Janssen3e7ee492009-07-13 16:02:34 -070082{
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070083 return VmbusChannelRecvPacketRaw(device->context, Buffer, BufferLen,
84 BufferActualLen, RequestId);
Hank Janssen3e7ee492009-07-13 16:02:34 -070085}
86
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070087static int IVmbusChannelEstablishGpadl(struct hv_device *device, void *Buffer,
88 u32 BufferLen, u32 *GpadlHandle)
Hank Janssen3e7ee492009-07-13 16:02:34 -070089{
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070090 return VmbusChannelEstablishGpadl(device->context, Buffer, BufferLen,
91 GpadlHandle);
Hank Janssen3e7ee492009-07-13 16:02:34 -070092}
93
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070094static int IVmbusChannelTeardownGpadl(struct hv_device *device, u32 GpadlHandle)
Hank Janssen3e7ee492009-07-13 16:02:34 -070095{
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -070096 return VmbusChannelTeardownGpadl(device->context, GpadlHandle);
Hank Janssen3e7ee492009-07-13 16:02:34 -070097
98}
99
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -0700100void GetChannelInterface(struct vmbus_channel_interface *iface)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700101{
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -0700102 iface->Open = IVmbusChannelOpen;
103 iface->Close = IVmbusChannelClose;
104 iface->SendPacket = IVmbusChannelSendPacket;
105 iface->SendPacketPageBuffer = IVmbusChannelSendPacketPageBuffer;
106 iface->SendPacketMultiPageBuffer =
107 IVmbusChannelSendPacketMultiPageBuffer;
108 iface->RecvPacket = IVmbusChannelRecvPacket;
109 iface->RecvPacketRaw = IVmbusChannelRecvPacketRaw;
110 iface->EstablishGpadl = IVmbusChannelEstablishGpadl;
111 iface->TeardownGpadl = IVmbusChannelTeardownGpadl;
112 iface->GetInfo = GetChannelInfo;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700113}
114
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -0700115void GetChannelInfo(struct hv_device *device, struct hv_device_info *info)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700116{
Greg Kroah-Hartmanaded71652009-08-18 15:21:19 -0700117 struct vmbus_channel_debug_info debugInfo;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700118
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -0700119 if (!device->context)
120 return;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700121
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -0700122 VmbusChannelGetDebugInfo(device->context, &debugInfo);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700123
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -0700124 info->ChannelId = debugInfo.RelId;
125 info->ChannelState = debugInfo.State;
126 memcpy(&info->ChannelType, &debugInfo.InterfaceType,
127 sizeof(struct hv_guid));
128 memcpy(&info->ChannelInstance, &debugInfo.InterfaceInstance,
129 sizeof(struct hv_guid));
Hank Janssen3e7ee492009-07-13 16:02:34 -0700130
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -0700131 info->MonitorId = debugInfo.MonitorId;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700132
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -0700133 info->ServerMonitorPending = debugInfo.ServerMonitorPending;
134 info->ServerMonitorLatency = debugInfo.ServerMonitorLatency;
135 info->ServerMonitorConnectionId = debugInfo.ServerMonitorConnectionId;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700136
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -0700137 info->ClientMonitorPending = debugInfo.ClientMonitorPending;
138 info->ClientMonitorLatency = debugInfo.ClientMonitorLatency;
139 info->ClientMonitorConnectionId = debugInfo.ClientMonitorConnectionId;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700140
Greg Kroah-Hartman490707d2009-08-28 16:25:39 -0700141 info->Inbound.InterruptMask = debugInfo.Inbound.CurrentInterruptMask;
142 info->Inbound.ReadIndex = debugInfo.Inbound.CurrentReadIndex;
143 info->Inbound.WriteIndex = debugInfo.Inbound.CurrentWriteIndex;
144 info->Inbound.BytesAvailToRead = debugInfo.Inbound.BytesAvailToRead;
145 info->Inbound.BytesAvailToWrite = debugInfo.Inbound.BytesAvailToWrite;
146
147 info->Outbound.InterruptMask = debugInfo.Outbound.CurrentInterruptMask;
148 info->Outbound.ReadIndex = debugInfo.Outbound.CurrentReadIndex;
149 info->Outbound.WriteIndex = debugInfo.Outbound.CurrentWriteIndex;
150 info->Outbound.BytesAvailToRead = debugInfo.Outbound.BytesAvailToRead;
151 info->Outbound.BytesAvailToWrite = debugInfo.Outbound.BytesAvailToWrite;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700152}