Staging: hv: remove typedefs from RndisFilter.c
[linux-2.6-block.git] / drivers / staging / hv / BlkVsc.c
CommitLineData
f82bd046
HJ
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 * Hank Janssen <hjanssen@microsoft.com>
20 *
21 */
5654e932 22#include <linux/kernel.h>
0ffa63b0 23#include <linux/mm.h>
4983b39a 24#include "osd.h"
0fce4c2f 25#include "StorVsc.c"
f82bd046 26
44c67577 27static const char *gBlkDriverName = "blkvsc";
f82bd046 28
454f18a9 29/* {32412632-86cb-44a2-9b5c-50d1417354f5} */
44c67577 30static const struct hv_guid gBlkVscDeviceType = {
caf26a31
GKH
31 .data = {
32 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44,
33 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5
34 }
f82bd046
HJ
35};
36
44c67577 37static int BlkVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
f82bd046 38{
44c67577
GKH
39 struct storvsc_device_info *deviceInfo;
40 int ret = 0;
f82bd046
HJ
41
42 DPRINT_ENTER(BLKVSC);
43
44c67577 44 deviceInfo = (struct storvsc_device_info *)AdditionalInfo;
f82bd046 45
44c67577
GKH
46 ret = StorVscOnDeviceAdd(Device, AdditionalInfo);
47 if (ret != 0) {
48 DPRINT_EXIT(BLKVSC);
49 return ret;
50 }
f82bd046 51
44c67577
GKH
52 /*
53 * We need to use the device instance guid to set the path and target
54 * id. For IDE devices, the device instance id is formatted as
55 * <bus id> * - <device id> - 8899 - 000000000000.
56 */
57 deviceInfo->PathId = Device->deviceInstance.data[3] << 24 |
58 Device->deviceInstance.data[2] << 16 |
59 Device->deviceInstance.data[1] << 8 |
60 Device->deviceInstance.data[0];
f82bd046 61
44c67577
GKH
62 deviceInfo->TargetId = Device->deviceInstance.data[5] << 8 |
63 Device->deviceInstance.data[4];
f82bd046
HJ
64
65 DPRINT_EXIT(BLKVSC);
66
67 return ret;
68}
69
44c67577 70int BlkVscInitialize(struct hv_driver *Driver)
f82bd046 71{
44c67577
GKH
72 struct storvsc_driver_object *storDriver;
73 int ret = 0;
f82bd046
HJ
74
75 DPRINT_ENTER(BLKVSC);
76
44c67577 77 storDriver = (struct storvsc_driver_object *)Driver;
f82bd046 78
44c67577
GKH
79 /* Make sure we are at least 2 pages since 1 page is used for control */
80 ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1));
f82bd046 81
44c67577
GKH
82 Driver->name = gBlkDriverName;
83 memcpy(&Driver->deviceType, &gBlkVscDeviceType, sizeof(struct hv_guid));
f82bd046 84
44c67577 85 storDriver->RequestExtSize = sizeof(STORVSC_REQUEST_EXTENSION);
f82bd046 86
44c67577
GKH
87 /*
88 * Divide the ring buffer data size (which is 1 page less than the ring
89 * buffer size since that page is reserved for the ring buffer indices)
90 * by the max request size (which is
91 * VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + struct vstor_packet + u64)
92 */
93 storDriver->MaxOutstandingRequestsPerChannel =
94 ((storDriver->RingBufferSize - PAGE_SIZE) /
95 ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET +
96 sizeof(struct vstor_packet) + sizeof(u64),
97 sizeof(u64)));
98
99 DPRINT_INFO(BLKVSC, "max io outstd %u",
100 storDriver->MaxOutstandingRequestsPerChannel);
101
102 /* Setup the dispatch table */
103 storDriver->Base.OnDeviceAdd = BlkVscOnDeviceAdd;
104 storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove;
105 storDriver->Base.OnCleanup = StorVscOnCleanup;
106 storDriver->OnIORequest = StorVscOnIORequest;
f82bd046
HJ
107
108 DPRINT_EXIT(BLKVSC);
109
110 return ret;
111}