staging: hv: Remove camel cases of vmbus packet buffer structures
[deliverable/linux.git] / drivers / staging / hv / vmbus.c
CommitLineData
3e7ee490 1/*
3e7ee490
HJ
2 * Copyright (c) 2009, Microsoft Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 *
17 * Authors:
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
20 *
21 */
5654e932 22#include <linux/kernel.h>
0ffa63b0 23#include <linux/mm.h>
5a0e3ad6 24#include <linux/slab.h>
4983b39a 25#include "osd.h"
645954c5 26#include "logging.h"
2d82f6c7 27#include "version_info.h"
72daf320 28#include "vmbus_private.h"
3e7ee490 29
772ec4e2 30static const char *gDriverName = "vmbus";
454f18a9 31
772ec4e2
GKH
32/*
33 * Windows vmbus does not defined this.
454f18a9
BP
34 * We defined this to be consistent with other devices
35 */
36/* {c5295816-f63a-4d5f-8d1a-4daf999ca185} */
caf26a31
GKH
37static const struct hv_guid gVmbusDeviceType = {
38 .data = {
39 0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d,
40 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85
41 }
3e7ee490
HJ
42};
43
454f18a9 44/* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */
caf26a31
GKH
45static const struct hv_guid gVmbusDeviceId = {
46 .data = {
47 0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40,
48 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5
49 }
3e7ee490
HJ
50};
51
775ef25e 52static struct hv_driver *gDriver; /* vmbus driver object */
772ec4e2 53static struct hv_device *gDevice; /* vmbus root device */
3e7ee490 54
3e189519 55/*
772ec4e2
GKH
56 * VmbusGetChannelOffers - Retrieve the channel offers from the parent partition
57 */
58static void VmbusGetChannelOffers(void)
3e7ee490 59{
3e7ee490 60 VmbusChannelRequestOffers();
3e7ee490
HJ
61}
62
3e189519 63/*
772ec4e2
GKH
64 * VmbusGetChannelInfo - Get the device info for the specified device object
65 */
66static void VmbusGetChannelInfo(struct hv_device *DeviceObject,
67 struct hv_device_info *DeviceInfo)
3e7ee490
HJ
68{
69 GetChannelInfo(DeviceObject, DeviceInfo);
70}
71
3e189519 72/*
772ec4e2
GKH
73 * VmbusCreateChildDevice - Creates the child device on the bus that represents the channel offer
74 */
daaa8cc3
GKH
75struct hv_device *VmbusChildDeviceCreate(struct hv_guid *DeviceType,
76 struct hv_guid *DeviceInstance,
f346fdc2 77 void *Context)
3e7ee490 78{
ee3d7ddf 79 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
3e7ee490 80
772ec4e2
GKH
81 return vmbusDriver->OnChildDeviceCreate(DeviceType, DeviceInstance,
82 Context);
3e7ee490
HJ
83}
84
3e189519 85/*
772ec4e2
GKH
86 * VmbusChildDeviceAdd - Registers the child device with the vmbus
87 */
f346fdc2 88int VmbusChildDeviceAdd(struct hv_device *ChildDevice)
3e7ee490 89{
ee3d7ddf 90 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
3e7ee490
HJ
91
92 return vmbusDriver->OnChildDeviceAdd(gDevice, ChildDevice);
93}
94
3e189519 95/*
772ec4e2
GKH
96 * VmbusChildDeviceRemove Unregisters the child device from the vmbus
97 */
f346fdc2 98void VmbusChildDeviceRemove(struct hv_device *ChildDevice)
3e7ee490 99{
ee3d7ddf 100 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
3e7ee490
HJ
101
102 vmbusDriver->OnChildDeviceRemove(ChildDevice);
103}
104
3e189519 105/*
772ec4e2
GKH
106 * VmbusOnDeviceAdd - Callback when the root bus device is added
107 */
108static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo)
3e7ee490 109{
772ec4e2
GKH
110 u32 *irqvector = AdditionalInfo;
111 int ret;
3e7ee490 112
3e7ee490
HJ
113 gDevice = dev;
114
caf26a31 115 memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
772ec4e2
GKH
116 memcpy(&gDevice->deviceInstance, &gVmbusDeviceId,
117 sizeof(struct hv_guid));
3e7ee490 118
454f18a9
BP
119 /* strcpy(dev->name, "vmbus"); */
120 /* SynIC setup... */
7692fd4d 121 on_each_cpu(HvSynicInit, (void *)irqvector, 1);
3e7ee490 122
454f18a9 123 /* Connect to VMBus in the root partition */
3e7ee490
HJ
124 ret = VmbusConnect();
125
454f18a9 126 /* VmbusSendEvent(device->localPortId+1); */
3e7ee490
HJ
127 return ret;
128}
129
3e189519 130/*
772ec4e2
GKH
131 * VmbusOnDeviceRemove - Callback when the root bus device is removed
132 */
133static int VmbusOnDeviceRemove(struct hv_device *dev)
3e7ee490 134{
772ec4e2 135 int ret = 0;
3e7ee490 136
3e7ee490 137 VmbusChannelReleaseUnattachedChannels();
3e7ee490 138 VmbusDisconnect();
7692fd4d 139 on_each_cpu(HvSynicCleanup, NULL, 1);
3e7ee490
HJ
140 return ret;
141}
142
3e189519 143/*
772ec4e2
GKH
144 * VmbusOnCleanup - Perform any cleanup when the driver is removed
145 */
146static void VmbusOnCleanup(struct hv_driver *drv)
3e7ee490 147{
ee3d7ddf 148 /* struct vmbus_driver *driver = (struct vmbus_driver *)drv; */
3e7ee490 149
3e7ee490 150 HvCleanup();
3e7ee490
HJ
151}
152
3e189519 153/*
772ec4e2
GKH
154 * VmbusOnMsgDPC - DPC routine to handle messages from the hypervisior
155 */
156static void VmbusOnMsgDPC(struct hv_driver *drv)
3e7ee490 157{
7692fd4d
GKH
158 int cpu = smp_processor_id();
159 void *page_addr = gHvContext.synICMessagePage[cpu];
772ec4e2
GKH
160 struct hv_message *msg = (struct hv_message *)page_addr +
161 VMBUS_MESSAGE_SINT;
eacb1b4d 162 struct hv_message *copied;
772ec4e2
GKH
163
164 while (1) {
165 if (msg->Header.MessageType == HvMessageTypeNone) {
166 /* no msg */
3e7ee490 167 break;
772ec4e2 168 } else {
94002c07 169 copied = kmemdup(msg, sizeof(*copied), GFP_ATOMIC);
3e7ee490 170 if (copied == NULL)
3e7ee490 171 continue;
3e7ee490 172
de65a384
BP
173 osd_schedule_callback(gVmbusConnection.WorkQueue,
174 VmbusOnChannelMessage,
175 (void *)copied);
3e7ee490
HJ
176 }
177
178 msg->Header.MessageType = HvMessageTypeNone;
179
454f18a9
BP
180 /*
181 * Make sure the write to MessageType (ie set to
182 * HvMessageTypeNone) happens before we read the
183 * MessagePending and EOMing. Otherwise, the EOMing
184 * will not deliver any more messages since there is
185 * no empty slot
186 */
28b6ca9c 187 mb();
3e7ee490 188
772ec4e2 189 if (msg->Header.MessageFlags.MessagePending) {
454f18a9
BP
190 /*
191 * This will cause message queue rescan to
192 * possibly deliver another msg from the
193 * hypervisor
194 */
a51ed7d6 195 wrmsrl(HV_X64_MSR_EOM, 0);
3e7ee490
HJ
196 }
197 }
198}
199
3e189519 200/*
772ec4e2
GKH
201 * VmbusOnEventDPC - DPC routine to handle events from the hypervisior
202 */
203static void VmbusOnEventDPC(struct hv_driver *drv)
3e7ee490 204{
454f18a9 205 /* TODO: Process any events */
3e7ee490
HJ
206 VmbusOnEvents();
207}
208
3e189519 209/*
772ec4e2
GKH
210 * VmbusOnISR - ISR routine
211 */
212static int VmbusOnISR(struct hv_driver *drv)
3e7ee490 213{
772ec4e2 214 int ret = 0;
7692fd4d 215 int cpu = smp_processor_id();
3e7ee490 216 void *page_addr;
eacb1b4d
GKH
217 struct hv_message *msg;
218 union hv_synic_event_flags *event;
3e7ee490 219
7692fd4d 220 page_addr = gHvContext.synICMessagePage[cpu];
eacb1b4d 221 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
3e7ee490 222
454f18a9 223 /* Check if there are actual msgs to be process */
772ec4e2
GKH
224 if (msg->Header.MessageType != HvMessageTypeNone) {
225 DPRINT_DBG(VMBUS, "received msg type %d size %d",
226 msg->Header.MessageType,
227 msg->Header.PayloadSize);
3e7ee490 228 ret |= 0x1;
772ec4e2 229 }
3e7ee490 230
454f18a9 231 /* TODO: Check if there are events to be process */
7692fd4d 232 page_addr = gHvContext.synICEventPage[cpu];
eacb1b4d 233 event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT;
3e7ee490 234
454f18a9 235 /* Since we are a child, we only need to check bit 0 */
772ec4e2 236 if (test_and_clear_bit(0, (unsigned long *) &event->Flags32[0])) {
3e7ee490
HJ
237 DPRINT_DBG(VMBUS, "received event %d", event->Flags32[0]);
238 ret |= 0x2;
239 }
240
3e7ee490
HJ
241 return ret;
242}
b3bfb3ce 243
3e189519 244/*
b3bfb3ce
GKH
245 * VmbusInitialize - Main entry point
246 */
247int VmbusInitialize(struct hv_driver *drv)
248{
249 struct vmbus_driver *driver = (struct vmbus_driver *)drv;
250 int ret;
251
26c14cc1
HJ
252 DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++",
253 HV_DRV_VERSION);
b3bfb3ce
GKH
254 DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++",
255 VMBUS_REVISION_NUMBER);
256 DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++",
257 VMBUS_MESSAGE_SINT);
430a8e9a 258 DPRINT_DBG(VMBUS, "sizeof(vmbus_channel_packet_page_buffer)=%zd, "
b3bfb3ce 259 "sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%zd",
430a8e9a
HZ
260 sizeof(struct vmbus_channel_packet_page_buffer),
261 sizeof(struct vmbus_channel_packet_multipage_buffer));
b3bfb3ce
GKH
262
263 drv->name = gDriverName;
264 memcpy(&drv->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
265
266 /* Setup dispatch table */
267 driver->Base.OnDeviceAdd = VmbusOnDeviceAdd;
268 driver->Base.OnDeviceRemove = VmbusOnDeviceRemove;
269 driver->Base.OnCleanup = VmbusOnCleanup;
270 driver->OnIsr = VmbusOnISR;
271 driver->OnMsgDpc = VmbusOnMsgDPC;
272 driver->OnEventDpc = VmbusOnEventDPC;
273 driver->GetChannelOffers = VmbusGetChannelOffers;
b3bfb3ce
GKH
274 driver->GetChannelInfo = VmbusGetChannelInfo;
275
276 /* Hypervisor initialization...setup hypercall page..etc */
277 ret = HvInit();
278 if (ret != 0)
279 DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x",
280 ret);
281 gDriver = drv;
282
b3bfb3ce
GKH
283 return ret;
284}
This page took 0.140764 seconds and 5 git commands to generate.