Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 1 | /* |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 2 | * Copyright (c) 2009, Microsoft Corporation. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 15 | * Place - Suite 330, Boston, MA 02111-1307 USA. |
| 16 | * |
| 17 | * Authors: |
| 18 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 19 | * Hank Janssen <hjanssen@microsoft.com> |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 20 | */ |
Greg Kroah-Hartman | 5654e93 | 2009-07-14 15:08:20 -0700 | [diff] [blame] | 21 | #include <linux/kernel.h> |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 22 | #include <linux/sched.h> |
K. Y. Srinivasan | 93958465 | 2011-03-28 09:33:30 -0700 | [diff] [blame] | 23 | #include <linux/completion.h> |
Greg Kroah-Hartman | 0ffa63b | 2009-07-15 11:06:01 -0700 | [diff] [blame] | 24 | #include <linux/string.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Greg Kroah-Hartman | 0ffa63b | 2009-07-15 11:06:01 -0700 | [diff] [blame] | 26 | #include <linux/mm.h> |
Greg Kroah-Hartman | b4362c9 | 2009-07-16 11:50:41 -0700 | [diff] [blame] | 27 | #include <linux/delay.h> |
K. Y. Srinivasan | e3fe0bb | 2011-02-11 10:00:12 -0800 | [diff] [blame] | 28 | #include "hv_api.h" |
Greg Kroah-Hartman | 645954c | 2009-08-28 16:22:59 -0700 | [diff] [blame] | 29 | #include "logging.h" |
Greg Kroah-Hartman | bb96979 | 2010-05-05 22:40:43 -0700 | [diff] [blame] | 30 | #include "storvsc_api.h" |
Greg Kroah-Hartman | f8e5add | 2010-05-05 22:50:11 -0700 | [diff] [blame] | 31 | #include "vmbus_packet_format.h" |
Greg Kroah-Hartman | 2dd88b5 | 2009-08-27 15:58:52 -0700 | [diff] [blame] | 32 | #include "vstorage.h" |
Greg Kroah-Hartman | 50ea95d | 2010-10-21 09:15:14 -0700 | [diff] [blame] | 33 | #include "channel.h" |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 34 | |
| 35 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 36 | static inline struct storvsc_device *alloc_stor_device(struct hv_device *device) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 37 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 38 | struct storvsc_device *stor_device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 39 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 40 | stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL); |
| 41 | if (!stor_device) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 42 | return NULL; |
| 43 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 44 | /* Set to 2 to allow both inbound and outbound traffics */ |
Hank Janssen | 3d8cdf2 | 2010-12-06 12:26:47 -0800 | [diff] [blame] | 45 | /* (ie get_stor_device() and must_get_stor_device()) to proceed. */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 46 | atomic_cmpxchg(&stor_device->ref_count, 0, 2); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 47 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 48 | stor_device->device = device; |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 49 | device->ext = stor_device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 50 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 51 | return stor_device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 54 | static inline void free_stor_device(struct storvsc_device *device) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 55 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 56 | kfree(device); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 59 | /* Get the stordevice object iff exists and its refcount > 0 */ |
Hank Janssen | 02e37db | 2010-12-06 12:26:48 -0800 | [diff] [blame] | 60 | static inline struct storvsc_device *must_get_stor_device( |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 61 | struct hv_device *device) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 62 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 63 | struct storvsc_device *stor_device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 64 | |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 65 | stor_device = (struct storvsc_device *)device->ext; |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 66 | if (stor_device && atomic_read(&stor_device->ref_count)) |
| 67 | atomic_inc(&stor_device->ref_count); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 68 | else |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 69 | stor_device = NULL; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 70 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 71 | return stor_device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Hank Janssen | 02e37db | 2010-12-06 12:26:48 -0800 | [diff] [blame] | 74 | /* Drop ref count to 1 to effectively disable get_stor_device() */ |
| 75 | static inline struct storvsc_device *release_stor_device( |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 76 | struct hv_device *device) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 77 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 78 | struct storvsc_device *stor_device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 79 | |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 80 | stor_device = (struct storvsc_device *)device->ext; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 81 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 82 | /* Busy wait until the ref drop to 2, then set it to 1 */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 83 | while (atomic_cmpxchg(&stor_device->ref_count, 2, 1) != 2) |
Greg Kroah-Hartman | b4362c9 | 2009-07-16 11:50:41 -0700 | [diff] [blame] | 84 | udelay(100); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 85 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 86 | return stor_device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 89 | /* Drop ref count to 0. No one can use stor_device object. */ |
Hank Janssen | 02e37db | 2010-12-06 12:26:48 -0800 | [diff] [blame] | 90 | static inline struct storvsc_device *final_release_stor_device( |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 91 | struct hv_device *device) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 92 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 93 | struct storvsc_device *stor_device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 94 | |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 95 | stor_device = (struct storvsc_device *)device->ext; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 96 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 97 | /* Busy wait until the ref drop to 1, then set it to 0 */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 98 | while (atomic_cmpxchg(&stor_device->ref_count, 1, 0) != 1) |
Greg Kroah-Hartman | b4362c9 | 2009-07-16 11:50:41 -0700 | [diff] [blame] | 99 | udelay(100); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 100 | |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 101 | device->ext = NULL; |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 102 | return stor_device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 105 | static int stor_vsc_channel_init(struct hv_device *device) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 106 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 107 | struct storvsc_device *stor_device; |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 108 | struct hv_storvsc_request *request; |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 109 | struct vstor_packet *vstor_packet; |
K. Y. Srinivasan | 93958465 | 2011-03-28 09:33:30 -0700 | [diff] [blame] | 110 | int ret, t; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 111 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 112 | stor_device = get_stor_device(device); |
| 113 | if (!stor_device) { |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 114 | DPRINT_ERR(STORVSC, "unable to get stor device..." |
| 115 | "device being destroyed?"); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 116 | return -1; |
| 117 | } |
| 118 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 119 | request = &stor_device->init_request; |
| 120 | vstor_packet = &request->vstor_packet; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 121 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 122 | /* |
| 123 | * Now, initiate the vsc/vsp initialization protocol on the open |
| 124 | * channel |
| 125 | */ |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 126 | memset(request, 0, sizeof(struct hv_storvsc_request)); |
K. Y. Srinivasan | 93958465 | 2011-03-28 09:33:30 -0700 | [diff] [blame] | 127 | init_completion(&request->wait_event); |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 128 | vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION; |
| 129 | vstor_packet->flags = REQUEST_COMPLETION_FLAG; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 130 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 131 | DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION..."); |
| 132 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 133 | ret = vmbus_sendpacket(device->channel, vstor_packet, |
Greg Kroah-Hartman | b60d71e | 2010-10-21 09:43:56 -0700 | [diff] [blame] | 134 | sizeof(struct vstor_packet), |
| 135 | (unsigned long)request, |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 136 | VM_PKT_DATA_INBAND, |
Greg Kroah-Hartman | b60d71e | 2010-10-21 09:43:56 -0700 | [diff] [blame] | 137 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 138 | if (ret != 0) { |
| 139 | DPRINT_ERR(STORVSC, |
| 140 | "unable to send BEGIN_INITIALIZATION_OPERATION"); |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 141 | goto cleanup; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 142 | } |
| 143 | |
K. Y. Srinivasan | 93958465 | 2011-03-28 09:33:30 -0700 | [diff] [blame] | 144 | t = wait_for_completion_timeout(&request->wait_event, HZ); |
| 145 | if (t == 0) { |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 146 | ret = -ETIMEDOUT; |
| 147 | goto cleanup; |
| 148 | } |
| 149 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 150 | if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || |
| 151 | vstor_packet->status != 0) { |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 152 | DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed " |
| 153 | "(op %d status 0x%x)", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 154 | vstor_packet->operation, vstor_packet->status); |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 155 | goto cleanup; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION..."); |
| 159 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 160 | /* reuse the packet for version range supported */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 161 | memset(vstor_packet, 0, sizeof(struct vstor_packet)); |
| 162 | vstor_packet->operation = VSTOR_OPERATION_QUERY_PROTOCOL_VERSION; |
| 163 | vstor_packet->flags = REQUEST_COMPLETION_FLAG; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 164 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 165 | vstor_packet->version.major_minor = VMSTOR_PROTOCOL_VERSION_CURRENT; |
| 166 | FILL_VMSTOR_REVISION(vstor_packet->version.revision); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 167 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 168 | ret = vmbus_sendpacket(device->channel, vstor_packet, |
Greg Kroah-Hartman | b60d71e | 2010-10-21 09:43:56 -0700 | [diff] [blame] | 169 | sizeof(struct vstor_packet), |
| 170 | (unsigned long)request, |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 171 | VM_PKT_DATA_INBAND, |
Greg Kroah-Hartman | b60d71e | 2010-10-21 09:43:56 -0700 | [diff] [blame] | 172 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 173 | if (ret != 0) { |
| 174 | DPRINT_ERR(STORVSC, |
| 175 | "unable to send BEGIN_INITIALIZATION_OPERATION"); |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 176 | goto cleanup; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 177 | } |
| 178 | |
K. Y. Srinivasan | 93958465 | 2011-03-28 09:33:30 -0700 | [diff] [blame] | 179 | t = wait_for_completion_timeout(&request->wait_event, HZ); |
| 180 | if (t == 0) { |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 181 | ret = -ETIMEDOUT; |
| 182 | goto cleanup; |
| 183 | } |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 184 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 185 | /* TODO: Check returned version */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 186 | if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || |
| 187 | vstor_packet->status != 0) { |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 188 | DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed " |
| 189 | "(op %d status 0x%x)", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 190 | vstor_packet->operation, vstor_packet->status); |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 191 | goto cleanup; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 194 | /* Query channel properties */ |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 195 | DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION..."); |
| 196 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 197 | memset(vstor_packet, 0, sizeof(struct vstor_packet)); |
| 198 | vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES; |
| 199 | vstor_packet->flags = REQUEST_COMPLETION_FLAG; |
| 200 | vstor_packet->storage_channel_properties.port_number = |
| 201 | stor_device->port_number; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 202 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 203 | ret = vmbus_sendpacket(device->channel, vstor_packet, |
Greg Kroah-Hartman | b60d71e | 2010-10-21 09:43:56 -0700 | [diff] [blame] | 204 | sizeof(struct vstor_packet), |
| 205 | (unsigned long)request, |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 206 | VM_PKT_DATA_INBAND, |
Greg Kroah-Hartman | b60d71e | 2010-10-21 09:43:56 -0700 | [diff] [blame] | 207 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 208 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 209 | if (ret != 0) { |
| 210 | DPRINT_ERR(STORVSC, |
| 211 | "unable to send QUERY_PROPERTIES_OPERATION"); |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 212 | goto cleanup; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 213 | } |
| 214 | |
K. Y. Srinivasan | 93958465 | 2011-03-28 09:33:30 -0700 | [diff] [blame] | 215 | t = wait_for_completion_timeout(&request->wait_event, HZ); |
| 216 | if (t == 0) { |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 217 | ret = -ETIMEDOUT; |
| 218 | goto cleanup; |
| 219 | } |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 220 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 221 | /* TODO: Check returned version */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 222 | if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || |
| 223 | vstor_packet->status != 0) { |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 224 | DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed " |
| 225 | "(op %d status 0x%x)", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 226 | vstor_packet->operation, vstor_packet->status); |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 227 | goto cleanup; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 230 | stor_device->path_id = vstor_packet->storage_channel_properties.path_id; |
| 231 | stor_device->target_id |
| 232 | = vstor_packet->storage_channel_properties.target_id; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 233 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 234 | DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 235 | vstor_packet->storage_channel_properties.flags, |
| 236 | vstor_packet->storage_channel_properties.max_transfer_bytes); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 237 | |
| 238 | DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION..."); |
| 239 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 240 | memset(vstor_packet, 0, sizeof(struct vstor_packet)); |
| 241 | vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION; |
| 242 | vstor_packet->flags = REQUEST_COMPLETION_FLAG; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 243 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 244 | ret = vmbus_sendpacket(device->channel, vstor_packet, |
Greg Kroah-Hartman | b60d71e | 2010-10-21 09:43:56 -0700 | [diff] [blame] | 245 | sizeof(struct vstor_packet), |
| 246 | (unsigned long)request, |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 247 | VM_PKT_DATA_INBAND, |
Greg Kroah-Hartman | b60d71e | 2010-10-21 09:43:56 -0700 | [diff] [blame] | 248 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 249 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 250 | if (ret != 0) { |
| 251 | DPRINT_ERR(STORVSC, |
| 252 | "unable to send END_INITIALIZATION_OPERATION"); |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 253 | goto cleanup; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 254 | } |
| 255 | |
K. Y. Srinivasan | 93958465 | 2011-03-28 09:33:30 -0700 | [diff] [blame] | 256 | t = wait_for_completion_timeout(&request->wait_event, HZ); |
| 257 | if (t == 0) { |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 258 | ret = -ETIMEDOUT; |
| 259 | goto cleanup; |
| 260 | } |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 261 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 262 | if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || |
| 263 | vstor_packet->status != 0) { |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 264 | DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed " |
| 265 | "(op %d status 0x%x)", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 266 | vstor_packet->operation, vstor_packet->status); |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 267 | goto cleanup; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****"); |
| 271 | |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 272 | cleanup: |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 273 | put_stor_device(device); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 274 | return ret; |
| 275 | } |
| 276 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 277 | static void stor_vsc_on_io_completion(struct hv_device *device, |
| 278 | struct vstor_packet *vstor_packet, |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 279 | struct hv_storvsc_request *request) |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 280 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 281 | struct storvsc_device *stor_device; |
K. Y. Srinivasan | a617e39 | 2011-04-06 11:25:38 -0700 | [diff] [blame] | 282 | struct vstor_packet *stor_pkt; |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 283 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 284 | stor_device = must_get_stor_device(device); |
| 285 | if (!stor_device) { |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 286 | DPRINT_ERR(STORVSC, "unable to get stor device..." |
| 287 | "device being destroyed?"); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 288 | return; |
| 289 | } |
| 290 | |
K. Y. Srinivasan | a617e39 | 2011-04-06 11:25:38 -0700 | [diff] [blame] | 291 | DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request %p " |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 292 | "completed bytes xfer %u", request, |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 293 | vstor_packet->vm_srb.data_transfer_length); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 294 | |
K. Y. Srinivasan | a617e39 | 2011-04-06 11:25:38 -0700 | [diff] [blame] | 295 | stor_pkt = &request->vstor_packet; |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 296 | |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 297 | |
| 298 | /* Copy over the status...etc */ |
K. Y. Srinivasan | a617e39 | 2011-04-06 11:25:38 -0700 | [diff] [blame] | 299 | stor_pkt->vm_srb.scsi_status = vstor_packet->vm_srb.scsi_status; |
| 300 | stor_pkt->vm_srb.srb_status = vstor_packet->vm_srb.srb_status; |
| 301 | stor_pkt->vm_srb.sense_info_length = |
| 302 | vstor_packet->vm_srb.sense_info_length; |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 303 | |
K. Y. Srinivasan | 6dc3f0a | 2011-03-28 09:33:42 -0700 | [diff] [blame] | 304 | if (vstor_packet->vm_srb.scsi_status != 0 || |
| 305 | vstor_packet->vm_srb.srb_status != 1) { |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 306 | DPRINT_WARN(STORVSC, |
| 307 | "cmd 0x%x scsi status 0x%x srb status 0x%x\n", |
K. Y. Srinivasan | a617e39 | 2011-04-06 11:25:38 -0700 | [diff] [blame] | 308 | stor_pkt->vm_srb.cdb[0], |
K. Y. Srinivasan | 373dd8a | 2011-03-28 09:33:37 -0700 | [diff] [blame] | 309 | vstor_packet->vm_srb.scsi_status, |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 310 | vstor_packet->vm_srb.srb_status); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 311 | } |
| 312 | |
K. Y. Srinivasan | 6dc3f0a | 2011-03-28 09:33:42 -0700 | [diff] [blame] | 313 | if ((vstor_packet->vm_srb.scsi_status & 0xFF) == 0x02) { |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 314 | /* CHECK_CONDITION */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 315 | if (vstor_packet->vm_srb.srb_status & 0x80) { |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 316 | /* autosense data available */ |
| 317 | DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data " |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 318 | "valid - len %d\n", request, |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 319 | vstor_packet->vm_srb.sense_info_length); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 320 | |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 321 | memcpy(request->sense_buffer, |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 322 | vstor_packet->vm_srb.sense_data, |
| 323 | vstor_packet->vm_srb.sense_info_length); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 324 | |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
K. Y. Srinivasan | a617e39 | 2011-04-06 11:25:38 -0700 | [diff] [blame] | 328 | stor_pkt->vm_srb.data_transfer_length = |
| 329 | vstor_packet->vm_srb.data_transfer_length; |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 330 | |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 331 | request->on_io_completion(request); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 332 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 333 | atomic_dec(&stor_device->num_outstanding_req); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 334 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 335 | put_stor_device(device); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 338 | static void stor_vsc_on_receive(struct hv_device *device, |
| 339 | struct vstor_packet *vstor_packet, |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 340 | struct hv_storvsc_request *request) |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 341 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 342 | switch (vstor_packet->operation) { |
Hank Janssen | d2aaba4 | 2010-12-06 12:26:44 -0800 | [diff] [blame] | 343 | case VSTOR_OPERATION_COMPLETE_IO: |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 344 | DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION"); |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 345 | stor_vsc_on_io_completion(device, vstor_packet, request); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 346 | break; |
Hank Janssen | d2aaba4 | 2010-12-06 12:26:44 -0800 | [diff] [blame] | 347 | case VSTOR_OPERATION_REMOVE_DEVICE: |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 348 | DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION"); |
| 349 | /* TODO: */ |
| 350 | break; |
| 351 | |
| 352 | default: |
| 353 | DPRINT_INFO(STORVSC, "Unknown operation received - %d", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 354 | vstor_packet->operation); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 355 | break; |
| 356 | } |
| 357 | } |
| 358 | |
Hank Janssen | 02e37db | 2010-12-06 12:26:48 -0800 | [diff] [blame] | 359 | static void stor_vsc_on_channel_callback(void *context) |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 360 | { |
| 361 | struct hv_device *device = (struct hv_device *)context; |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 362 | struct storvsc_device *stor_device; |
| 363 | u32 bytes_recvd; |
| 364 | u64 request_id; |
Uwe Kleine-König | 7350968 | 2011-01-20 09:32:01 +0100 | [diff] [blame] | 365 | unsigned char packet[ALIGN(sizeof(struct vstor_packet), 8)]; |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 366 | struct hv_storvsc_request *request; |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 367 | int ret; |
| 368 | |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 369 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 370 | stor_device = must_get_stor_device(device); |
| 371 | if (!stor_device) { |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 372 | DPRINT_ERR(STORVSC, "unable to get stor device..." |
| 373 | "device being destroyed?"); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 374 | return; |
| 375 | } |
| 376 | |
| 377 | do { |
Greg Kroah-Hartman | 50ea95d | 2010-10-21 09:15:14 -0700 | [diff] [blame] | 378 | ret = vmbus_recvpacket(device->channel, packet, |
Uwe Kleine-König | 7350968 | 2011-01-20 09:32:01 +0100 | [diff] [blame] | 379 | ALIGN(sizeof(struct vstor_packet), 8), |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 380 | &bytes_recvd, &request_id); |
| 381 | if (ret == 0 && bytes_recvd > 0) { |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 382 | DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 383 | bytes_recvd, request_id); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 384 | |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 385 | |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 386 | request = (struct hv_storvsc_request *) |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 387 | (unsigned long)request_id; |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 388 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 389 | if ((request == &stor_device->init_request) || |
| 390 | (request == &stor_device->reset_request)) { |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 391 | |
Hank Janssen | 3d8cdf2 | 2010-12-06 12:26:47 -0800 | [diff] [blame] | 392 | memcpy(&request->vstor_packet, packet, |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 393 | sizeof(struct vstor_packet)); |
K. Y. Srinivasan | 93958465 | 2011-03-28 09:33:30 -0700 | [diff] [blame] | 394 | complete(&request->wait_event); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 395 | } else { |
Hank Janssen | 02e37db | 2010-12-06 12:26:48 -0800 | [diff] [blame] | 396 | stor_vsc_on_receive(device, |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 397 | (struct vstor_packet *)packet, |
| 398 | request); |
| 399 | } |
| 400 | } else { |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 401 | break; |
| 402 | } |
| 403 | } while (1); |
| 404 | |
Hank Janssen | 02e37db | 2010-12-06 12:26:48 -0800 | [diff] [blame] | 405 | put_stor_device(device); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 406 | return; |
| 407 | } |
| 408 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 409 | static int stor_vsc_connect_to_vsp(struct hv_device *device) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 410 | { |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 411 | struct vmstorage_channel_properties props; |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 412 | struct storvsc_driver_object *stor_driver; |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 413 | int ret; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 414 | |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 415 | stor_driver = (struct storvsc_driver_object *)device->drv; |
Dave Jones | 8c960e4 | 2009-11-11 16:57:03 -0500 | [diff] [blame] | 416 | memset(&props, 0, sizeof(struct vmstorage_channel_properties)); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 417 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 418 | /* Open the channel */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 419 | ret = vmbus_open(device->channel, |
| 420 | stor_driver->ring_buffer_size, |
| 421 | stor_driver->ring_buffer_size, |
Greg Kroah-Hartman | 60f841a | 2010-10-21 09:59:06 -0700 | [diff] [blame] | 422 | (void *)&props, |
| 423 | sizeof(struct vmstorage_channel_properties), |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 424 | stor_vsc_on_channel_callback, device); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 425 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 426 | DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", |
Hank Janssen | d2aaba4 | 2010-12-06 12:26:44 -0800 | [diff] [blame] | 427 | props.path_id, props.target_id, props.max_transfer_bytes); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 428 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 429 | if (ret != 0) { |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 430 | DPRINT_ERR(STORVSC, "unable to open channel: %d", ret); |
| 431 | return -1; |
| 432 | } |
| 433 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 434 | ret = stor_vsc_channel_init(device); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 435 | |
| 436 | return ret; |
| 437 | } |
| 438 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 439 | /* |
Hank Janssen | 02e37db | 2010-12-06 12:26:48 -0800 | [diff] [blame] | 440 | * stor_vsc_on_device_add - Callback when the device belonging to this driver |
Hank Janssen | 3d8cdf2 | 2010-12-06 12:26:47 -0800 | [diff] [blame] | 441 | * is added |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 442 | */ |
K. Y. Srinivasan | afa3f3d | 2011-03-23 10:50:23 -0700 | [diff] [blame] | 443 | int stor_vsc_on_device_add(struct hv_device *device, |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 444 | void *additional_info) |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 445 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 446 | struct storvsc_device *stor_device; |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 447 | struct storvsc_device_info *device_info; |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 448 | int ret = 0; |
| 449 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 450 | device_info = (struct storvsc_device_info *)additional_info; |
| 451 | stor_device = alloc_stor_device(device); |
| 452 | if (!stor_device) { |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 453 | ret = -1; |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 454 | goto cleanup; |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /* Save the channel properties to our storvsc channel */ |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 458 | |
| 459 | /* FIXME: */ |
| 460 | /* |
| 461 | * If we support more than 1 scsi channel, we need to set the |
| 462 | * port number here to the scsi channel but how do we get the |
| 463 | * scsi channel prior to the bus scan |
| 464 | */ |
| 465 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 466 | stor_device->port_number = device_info->port_number; |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 467 | /* Send it back up */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 468 | ret = stor_vsc_connect_to_vsp(device); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 469 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 470 | device_info->path_id = stor_device->path_id; |
| 471 | device_info->target_id = stor_device->target_id; |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 472 | |
| 473 | DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 474 | stor_device->port_number, stor_device->path_id, |
| 475 | stor_device->target_id); |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 476 | |
K. Y. Srinivasan | 0c3b7b2 | 2011-02-11 09:59:43 -0800 | [diff] [blame] | 477 | cleanup: |
Greg Kroah-Hartman | 163680b | 2009-08-31 22:31:22 -0700 | [diff] [blame] | 478 | return ret; |
| 479 | } |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 480 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 481 | /* |
Hank Janssen | 02e37db | 2010-12-06 12:26:48 -0800 | [diff] [blame] | 482 | * stor_vsc_on_device_remove - Callback when the our device is being removed |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 483 | */ |
K. Y. Srinivasan | afa3f3d | 2011-03-23 10:50:23 -0700 | [diff] [blame] | 484 | int stor_vsc_on_device_remove(struct hv_device *device) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 485 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 486 | struct storvsc_device *stor_device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 487 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 488 | DPRINT_INFO(STORVSC, "disabling storage device (%p)...", |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 489 | device->ext); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 490 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 491 | stor_device = release_stor_device(device); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 492 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 493 | /* |
| 494 | * At this point, all outbound traffic should be disable. We |
| 495 | * only allow inbound traffic (responses) to proceed so that |
| 496 | * outstanding requests can be completed. |
| 497 | */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 498 | while (atomic_read(&stor_device->num_outstanding_req)) { |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 499 | DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 500 | atomic_read(&stor_device->num_outstanding_req)); |
Greg Kroah-Hartman | b4362c9 | 2009-07-16 11:50:41 -0700 | [diff] [blame] | 501 | udelay(100); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 504 | DPRINT_INFO(STORVSC, "removing storage device (%p)...", |
Haiyang Zhang | ca623ad | 2011-01-26 12:12:11 -0800 | [diff] [blame] | 505 | device->ext); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 506 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 507 | stor_device = final_release_stor_device(device); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 508 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 509 | DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", stor_device); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 510 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 511 | /* Close the channel */ |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 512 | vmbus_close(device->channel); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 513 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 514 | free_stor_device(stor_device); |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 515 | return 0; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 518 | /* |
Hank Janssen | 02e37db | 2010-12-06 12:26:48 -0800 | [diff] [blame] | 519 | * stor_vsc_on_io_request - Callback to initiate an I/O request |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 520 | */ |
K. Y. Srinivasan | afa3f3d | 2011-03-23 10:50:23 -0700 | [diff] [blame] | 521 | int stor_vsc_on_io_request(struct hv_device *device, |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 522 | struct hv_storvsc_request *request) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 523 | { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 524 | struct storvsc_device *stor_device; |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 525 | struct vstor_packet *vstor_packet; |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 526 | int ret = 0; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 527 | |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 528 | vstor_packet = &request->vstor_packet; |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 529 | stor_device = get_stor_device(device); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 530 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 531 | DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, " |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 532 | , device, stor_device, request); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 533 | |
K. Y. Srinivasan | 473f940 | 2011-03-28 09:33:36 -0700 | [diff] [blame] | 534 | DPRINT_DBG(STORVSC, "req %p len %d", |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 535 | request, request->data_buffer.len); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 536 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 537 | if (!stor_device) { |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 538 | DPRINT_ERR(STORVSC, "unable to get stor device..." |
| 539 | "device being destroyed?"); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 540 | return -2; |
| 541 | } |
| 542 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 543 | |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 544 | request->device = device; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 545 | |
K. Y. Srinivasan | a617e39 | 2011-04-06 11:25:38 -0700 | [diff] [blame] | 546 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 547 | vstor_packet->flags |= REQUEST_COMPLETION_FLAG; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 548 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 549 | vstor_packet->vm_srb.length = sizeof(struct vmscsi_request); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 550 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 551 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 552 | vstor_packet->vm_srb.sense_info_length = SENSE_BUFFER_SIZE; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 553 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 554 | |
K. Y. Srinivasan | e9e936c | 2011-03-28 09:33:43 -0700 | [diff] [blame] | 555 | vstor_packet->vm_srb.data_transfer_length = |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 556 | request->data_buffer.len; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 557 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 558 | vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 559 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 560 | DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, " |
| 561 | "lun %d senselen %d cdblen %d", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 562 | vstor_packet->vm_srb.length, |
| 563 | vstor_packet->vm_srb.port_number, |
| 564 | vstor_packet->vm_srb.path_id, |
| 565 | vstor_packet->vm_srb.target_id, |
| 566 | vstor_packet->vm_srb.lun, |
| 567 | vstor_packet->vm_srb.sense_info_length, |
| 568 | vstor_packet->vm_srb.cdb_length); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 569 | |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 570 | if (request->data_buffer.len) { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 571 | ret = vmbus_sendpacket_multipagebuffer(device->channel, |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 572 | &request->data_buffer, |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 573 | vstor_packet, |
Greg Kroah-Hartman | b3715ee | 2009-08-27 16:00:24 -0700 | [diff] [blame] | 574 | sizeof(struct vstor_packet), |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 575 | (unsigned long)request); |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 576 | } else { |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 577 | ret = vmbus_sendpacket(device->channel, vstor_packet, |
Greg Kroah-Hartman | b60d71e | 2010-10-21 09:43:56 -0700 | [diff] [blame] | 578 | sizeof(struct vstor_packet), |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 579 | (unsigned long)request, |
Haiyang Zhang | 415f228 | 2011-01-26 12:12:13 -0800 | [diff] [blame] | 580 | VM_PKT_DATA_INBAND, |
Greg Kroah-Hartman | b60d71e | 2010-10-21 09:43:56 -0700 | [diff] [blame] | 581 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 584 | if (ret != 0) { |
| 585 | DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 586 | vstor_packet, ret); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 589 | atomic_inc(&stor_device->num_outstanding_req); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 590 | |
Hank Janssen | f638859 | 2010-12-06 12:26:49 -0800 | [diff] [blame] | 591 | put_stor_device(device); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 592 | return ret; |
| 593 | } |
| 594 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 595 | /* |
Hank Janssen | 02e37db | 2010-12-06 12:26:48 -0800 | [diff] [blame] | 596 | * stor_vsc_on_cleanup - Perform any cleanup when the driver is removed |
Greg Kroah-Hartman | 068c5df | 2009-08-31 22:25:48 -0700 | [diff] [blame] | 597 | */ |
K. Y. Srinivasan | afa3f3d | 2011-03-23 10:50:23 -0700 | [diff] [blame] | 598 | void stor_vsc_on_cleanup(struct hv_driver *driver) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 599 | { |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 600 | } |
| 601 | |