3 * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
23 #include <linux/kernel.h>
26 #include "vmbus_private.h"
28 static int IVmbusChannelOpen(struct hv_device
*device
, u32 SendBufferSize
,
29 u32 RecvRingBufferSize
, void *UserData
,
31 void (*ChannelCallback
)(void *context
),
34 return vmbus_open(device
->context
, SendBufferSize
,
35 RecvRingBufferSize
, UserData
, UserDataLen
,
36 ChannelCallback
, Context
);
39 static void IVmbusChannelClose(struct hv_device
*device
)
41 vmbus_close(device
->context
);
44 static int IVmbusChannelSendPacket(struct hv_device
*device
, const void *Buffer
,
45 u32 BufferLen
, u64 RequestId
, u32 Type
,
48 return vmbus_sendpacket(device
->context
, Buffer
, BufferLen
,
49 RequestId
, Type
, Flags
);
52 static int IVmbusChannelSendPacketPageBuffer(struct hv_device
*device
,
53 struct hv_page_buffer PageBuffers
[],
54 u32 PageCount
, void *Buffer
,
55 u32 BufferLen
, u64 RequestId
)
57 return vmbus_sendpacket_pagebuffer(device
->context
, PageBuffers
,
58 PageCount
, Buffer
, BufferLen
,
62 static int IVmbusChannelSendPacketMultiPageBuffer(struct hv_device
*device
,
63 struct hv_multipage_buffer
*MultiPageBuffer
,
64 void *Buffer
, u32 BufferLen
, u64 RequestId
)
66 return vmbus_sendpacket_multipagebuffer(device
->context
,
67 MultiPageBuffer
, Buffer
,
68 BufferLen
, RequestId
);
71 static int IVmbusChannelRecvPacket(struct hv_device
*device
, void *Buffer
,
72 u32 BufferLen
, u32
*BufferActualLen
,
75 return vmbus_recvpacket(device
->context
, Buffer
, BufferLen
,
76 BufferActualLen
, RequestId
);
79 static int IVmbusChannelRecvPacketRaw(struct hv_device
*device
, void *Buffer
,
80 u32 BufferLen
, u32
*BufferActualLen
,
83 return vmbus_recvpacket_raw(device
->context
, Buffer
, BufferLen
,
84 BufferActualLen
, RequestId
);
87 static int IVmbusChannelEstablishGpadl(struct hv_device
*device
, void *Buffer
,
88 u32 BufferLen
, u32
*GpadlHandle
)
90 return vmbus_establish_gpadl(device
->context
, Buffer
, BufferLen
,
94 static int IVmbusChannelTeardownGpadl(struct hv_device
*device
, u32 GpadlHandle
)
96 return vmbus_teardown_gpadl(device
->context
, GpadlHandle
);
101 void GetChannelInfo(struct hv_device
*device
, struct hv_device_info
*info
)
103 struct vmbus_channel_debug_info debugInfo
;
105 if (!device
->context
)
108 vmbus_get_debug_info(device
->context
, &debugInfo
);
110 info
->ChannelId
= debugInfo
.RelId
;
111 info
->ChannelState
= debugInfo
.State
;
112 memcpy(&info
->ChannelType
, &debugInfo
.InterfaceType
,
113 sizeof(struct hv_guid
));
114 memcpy(&info
->ChannelInstance
, &debugInfo
.InterfaceInstance
,
115 sizeof(struct hv_guid
));
117 info
->MonitorId
= debugInfo
.MonitorId
;
119 info
->ServerMonitorPending
= debugInfo
.ServerMonitorPending
;
120 info
->ServerMonitorLatency
= debugInfo
.ServerMonitorLatency
;
121 info
->ServerMonitorConnectionId
= debugInfo
.ServerMonitorConnectionId
;
123 info
->ClientMonitorPending
= debugInfo
.ClientMonitorPending
;
124 info
->ClientMonitorLatency
= debugInfo
.ClientMonitorLatency
;
125 info
->ClientMonitorConnectionId
= debugInfo
.ClientMonitorConnectionId
;
127 info
->Inbound
.InterruptMask
= debugInfo
.Inbound
.CurrentInterruptMask
;
128 info
->Inbound
.ReadIndex
= debugInfo
.Inbound
.CurrentReadIndex
;
129 info
->Inbound
.WriteIndex
= debugInfo
.Inbound
.CurrentWriteIndex
;
130 info
->Inbound
.BytesAvailToRead
= debugInfo
.Inbound
.BytesAvailToRead
;
131 info
->Inbound
.BytesAvailToWrite
= debugInfo
.Inbound
.BytesAvailToWrite
;
133 info
->Outbound
.InterruptMask
= debugInfo
.Outbound
.CurrentInterruptMask
;
134 info
->Outbound
.ReadIndex
= debugInfo
.Outbound
.CurrentReadIndex
;
135 info
->Outbound
.WriteIndex
= debugInfo
.Outbound
.CurrentWriteIndex
;
136 info
->Outbound
.BytesAvailToRead
= debugInfo
.Outbound
.BytesAvailToRead
;
137 info
->Outbound
.BytesAvailToWrite
= debugInfo
.Outbound
.BytesAvailToWrite
;
141 /* vmbus interface function pointer table */
142 const struct vmbus_channel_interface vmbus_ops
= {
143 .Open
= IVmbusChannelOpen
,
144 .Close
= IVmbusChannelClose
,
145 .SendPacket
= IVmbusChannelSendPacket
,
146 .SendPacketPageBuffer
= IVmbusChannelSendPacketPageBuffer
,
147 .SendPacketMultiPageBuffer
= IVmbusChannelSendPacketMultiPageBuffer
,
148 .RecvPacket
= IVmbusChannelRecvPacket
,
149 .RecvPacketRaw
= IVmbusChannelRecvPacketRaw
,
150 .EstablishGpadl
= IVmbusChannelEstablishGpadl
,
151 .TeardownGpadl
= IVmbusChannelTeardownGpadl
,
152 .GetInfo
= GetChannelInfo
,