]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/hv/blkvsc.c
staging: brcm80211: allow both driver are created in single build
[mirror_ubuntu-artful-kernel.git] / 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 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
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 *g_blk_driver_name = "blkvsc";
29
30 /* {32412632-86cb-44a2-9b5c-50d1417354f5} */
31 static const struct hv_guid g_blk_device_type = {
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 int blk_vsc_on_device_add(struct hv_device *device, void *additional_info)
39 {
40 struct storvsc_device_info *device_info;
41 int ret = 0;
42
43 device_info = (struct storvsc_device_info *)additional_info;
44
45 ret = stor_vsc_on_device_add(device, additional_info);
46 if (ret != 0)
47 return ret;
48
49 /*
50 * We need to use the device instance guid to set the path and target
51 * id. For IDE devices, the device instance id is formatted as
52 * <bus id> * - <device id> - 8899 - 000000000000.
53 */
54 device_info->path_id = device->dev_instance.data[3] << 24 |
55 device->dev_instance.data[2] << 16 |
56 device->dev_instance.data[1] << 8 |
57 device->dev_instance.data[0];
58
59 device_info->target_id = device->dev_instance.data[5] << 8 |
60 device->dev_instance.data[4];
61
62 return ret;
63 }
64
65 int blk_vsc_initialize(struct hv_driver *driver)
66 {
67 struct storvsc_driver_object *stor_driver;
68 int ret = 0;
69
70 stor_driver = (struct storvsc_driver_object *)driver;
71
72 /* Make sure we are at least 2 pages since 1 page is used for control */
73 /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */
74
75 driver->name = g_blk_driver_name;
76 memcpy(&driver->dev_type, &g_blk_device_type, sizeof(struct hv_guid));
77
78 stor_driver->request_ext_size = sizeof(struct storvsc_request_extension);
79
80 /*
81 * Divide the ring buffer data size (which is 1 page less than the ring
82 * buffer size since that page is reserved for the ring buffer indices)
83 * by the max request size (which is
84 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
85 */
86 stor_driver->max_outstanding_req_per_channel =
87 ((stor_driver->ring_buffer_size - PAGE_SIZE) /
88 ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
89 sizeof(struct vstor_packet) + sizeof(u64),
90 sizeof(u64)));
91
92 DPRINT_INFO(BLKVSC, "max io outstd %u",
93 stor_driver->max_outstanding_req_per_channel);
94
95 /* Setup the dispatch table */
96 stor_driver->base.dev_add = blk_vsc_on_device_add;
97 stor_driver->base.dev_rm = stor_vsc_on_device_remove;
98 stor_driver->base.cleanup = stor_vsc_on_cleanup;
99 stor_driver->on_io_request = stor_vsc_on_io_request;
100
101 return ret;
102 }