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