]> Pileus Git - ~andy/linux/blob - drivers/staging/hv/BlkVsc.c
Staging: hv: remove UINT8 and INT8 typedefs
[~andy/linux] / drivers / staging / hv / BlkVsc.c
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
23 #include <linux/kernel.h>
24 #include "StorVsc.c"
25
26 static const char* gBlkDriverName="blkvsc";
27
28 //{32412632-86cb-44a2-9b5c-50d1417354f5}
29 static const GUID gBlkVscDeviceType={
30         .Data = {0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5}
31 };
32
33 // Static routines
34 static int
35 BlkVscOnDeviceAdd(
36         DEVICE_OBJECT   *Device,
37         void                    *AdditionalInfo
38         );
39
40
41 int
42 BlkVscInitialize(
43         DRIVER_OBJECT *Driver
44         )
45 {
46         STORVSC_DRIVER_OBJECT* storDriver = (STORVSC_DRIVER_OBJECT*)Driver;
47         int ret=0;
48
49         DPRINT_ENTER(BLKVSC);
50
51         // Make sure we are at least 2 pages since 1 page is used for control
52         ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1));
53
54         Driver->name = gBlkDriverName;
55         memcpy(&Driver->deviceType, &gBlkVscDeviceType, sizeof(GUID));
56
57         storDriver->RequestExtSize                      = sizeof(STORVSC_REQUEST_EXTENSION);
58         // 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)
59         // by the max request size (which is VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + VSTOR_PACKET + UINT64)
60         storDriver->MaxOutstandingRequestsPerChannel =
61                 ((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(VSTOR_PACKET) + sizeof(UINT64),sizeof(UINT64)));
62
63         DPRINT_INFO(BLKVSC, "max io outstd %u", storDriver->MaxOutstandingRequestsPerChannel);
64
65         // Setup the dispatch table
66         storDriver->Base.OnDeviceAdd            = BlkVscOnDeviceAdd;
67         storDriver->Base.OnDeviceRemove         = StorVscOnDeviceRemove;
68         storDriver->Base.OnCleanup                      = StorVscOnCleanup;
69
70         storDriver->OnIORequest                         = StorVscOnIORequest;
71
72         DPRINT_EXIT(BLKVSC);
73
74         return ret;
75 }
76
77 int
78 BlkVscOnDeviceAdd(
79         DEVICE_OBJECT   *Device,
80         void                    *AdditionalInfo
81         )
82 {
83         int ret=0;
84         STORVSC_DEVICE_INFO *deviceInfo = (STORVSC_DEVICE_INFO*)AdditionalInfo;
85
86         DPRINT_ENTER(BLKVSC);
87
88         ret = StorVscOnDeviceAdd(Device, AdditionalInfo);
89
90         if (ret != 0)
91         {
92                 DPRINT_EXIT(BLKVSC);
93
94                 return ret;
95         }
96
97         // We need to use the device instance guid to set the path and target id. For IDE devices, the
98         // device instance id is formatted as <bus id> - <device id> - 8899 - 000000000000.
99         deviceInfo->PathId = Device->deviceInstance.Data[3] << 24 | Device->deviceInstance.Data[2] << 16 |
100                 Device->deviceInstance.Data[1] << 8 |Device->deviceInstance.Data[0];
101
102         deviceInfo->TargetId = Device->deviceInstance.Data[5] << 8 | Device->deviceInstance.Data[4];
103
104         DPRINT_EXIT(BLKVSC);
105
106         return ret;
107 }