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