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