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> |
K. Y. Srinivasan | 972621c | 2011-05-10 07:54:19 -0700 | [diff] [blame] | 20 | * K. Y. Srinivasan <kys@microsoft.com> |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 21 | */ |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 24 | #include <linux/module.h> |
| 25 | #include <linux/device.h> |
| 26 | #include <linux/blkdev.h> |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 27 | #include <scsi/scsi.h> |
| 28 | #include <scsi/scsi_cmnd.h> |
| 29 | #include <scsi/scsi_host.h> |
| 30 | #include <scsi/scsi_device.h> |
| 31 | #include <scsi/scsi_tcq.h> |
| 32 | #include <scsi/scsi_eh.h> |
| 33 | #include <scsi/scsi_devinfo.h> |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 34 | #include <scsi/scsi_dbg.h> |
K. Y. Srinivasan | e3fe0bb | 2011-02-11 10:00:12 -0800 | [diff] [blame] | 35 | #include "hv_api.h" |
Greg Kroah-Hartman | 645954c | 2009-08-28 16:22:59 -0700 | [diff] [blame] | 36 | #include "logging.h" |
Greg Kroah-Hartman | 2d82f6c | 2010-05-05 22:52:28 -0700 | [diff] [blame] | 37 | #include "version_info.h" |
Greg Kroah-Hartman | 870cde8 | 2009-08-19 16:21:28 -0700 | [diff] [blame] | 38 | #include "vmbus.h" |
Greg Kroah-Hartman | bb96979 | 2010-05-05 22:40:43 -0700 | [diff] [blame] | 39 | #include "storvsc_api.h" |
K. Y. Srinivasan | af3043c | 2011-03-23 10:50:33 -0700 | [diff] [blame] | 40 | #include "vstorage.h" |
| 41 | #include "channel.h" |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 42 | |
K. Y. Srinivasan | 2db2cab | 2011-05-10 07:54:39 -0700 | [diff] [blame] | 43 | static int storvsc_ringbuffer_size = STORVSC_RING_BUFFER_SIZE; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 44 | |
K. Y. Srinivasan | 3d598ce | 2011-05-10 07:54:40 -0700 | [diff] [blame] | 45 | module_param(storvsc_ringbuffer_size, int, S_IRUGO); |
| 46 | MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)"); |
| 47 | |
K. Y. Srinivasan | 0f0cdc6 | 2011-05-10 07:54:18 -0700 | [diff] [blame] | 48 | static const char *driver_name = "storvsc"; |
K. Y. Srinivasan | 6dec244 | 2011-03-23 10:50:25 -0700 | [diff] [blame] | 49 | |
| 50 | /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */ |
| 51 | static const struct hv_guid gStorVscDeviceType = { |
| 52 | .data = { |
| 53 | 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, |
| 54 | 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f |
| 55 | } |
| 56 | }; |
| 57 | |
K. Y. Srinivasan | 972621c | 2011-05-10 07:54:19 -0700 | [diff] [blame] | 58 | struct hv_host_device { |
K. Y. Srinivasan | 97c1529 | 2011-05-10 07:54:21 -0700 | [diff] [blame] | 59 | struct hv_device *dev; |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 60 | struct kmem_cache *request_pool; |
| 61 | unsigned int port; |
| 62 | unsigned char path; |
| 63 | unsigned char target; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | struct storvsc_cmd_request { |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 67 | struct list_head entry; |
| 68 | struct scsi_cmnd *cmd; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 69 | |
| 70 | unsigned int bounce_sgl_count; |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 71 | struct scatterlist *bounce_sgl; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 72 | |
Nicolas Palix | 0b3f683 | 2009-07-29 14:10:19 +0200 | [diff] [blame] | 73 | struct hv_storvsc_request request; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 76 | |
K. Y. Srinivasan | 5b60ace | 2011-05-10 07:54:25 -0700 | [diff] [blame] | 77 | static int storvsc_device_alloc(struct scsi_device *sdevice) |
| 78 | { |
| 79 | /* |
| 80 | * This enables luns to be located sparsely. Otherwise, we may not |
| 81 | * discovered them. |
| 82 | */ |
| 83 | sdevice->sdev_bflags |= BLIST_SPARSELUN | BLIST_LARGELUN; |
| 84 | return 0; |
| 85 | } |
| 86 | |
K. Y. Srinivasan | a1ebfea | 2011-05-10 07:54:26 -0700 | [diff] [blame] | 87 | static int storvsc_merge_bvec(struct request_queue *q, |
| 88 | struct bvec_merge_data *bmd, struct bio_vec *bvec) |
| 89 | { |
| 90 | /* checking done by caller. */ |
| 91 | return bvec->bv_len; |
| 92 | } |
| 93 | |
K. Y. Srinivasan | 419f2d0 | 2011-05-10 07:54:27 -0700 | [diff] [blame] | 94 | static int storvsc_device_configure(struct scsi_device *sdevice) |
| 95 | { |
| 96 | scsi_adjust_queue_depth(sdevice, MSG_SIMPLE_TAG, |
| 97 | STORVSC_MAX_IO_REQUESTS); |
| 98 | |
| 99 | DPRINT_INFO(STORVSC_DRV, "sdev (%p) - setting max segment size to %ld", |
| 100 | sdevice, PAGE_SIZE); |
| 101 | blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE); |
| 102 | |
| 103 | DPRINT_INFO(STORVSC_DRV, "sdev (%p) - adding merge bio vec routine", |
| 104 | sdevice); |
| 105 | blk_queue_merge_bvec(sdevice->request_queue, storvsc_merge_bvec); |
| 106 | |
| 107 | blk_queue_bounce_limit(sdevice->request_queue, BLK_BOUNCE_ANY); |
K. Y. Srinivasan | 419f2d0 | 2011-05-10 07:54:27 -0700 | [diff] [blame] | 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
K. Y. Srinivasan | 49a3c7a | 2011-05-10 07:54:28 -0700 | [diff] [blame] | 112 | static void destroy_bounce_buffer(struct scatterlist *sgl, |
| 113 | unsigned int sg_count) |
| 114 | { |
| 115 | int i; |
| 116 | struct page *page_buf; |
| 117 | |
| 118 | for (i = 0; i < sg_count; i++) { |
| 119 | page_buf = sg_page((&sgl[i])); |
| 120 | if (page_buf != NULL) |
| 121 | __free_page(page_buf); |
| 122 | } |
| 123 | |
| 124 | kfree(sgl); |
| 125 | } |
| 126 | |
K. Y. Srinivasan | 3862ef3 | 2011-05-10 07:54:29 -0700 | [diff] [blame] | 127 | static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count) |
| 128 | { |
| 129 | int i; |
| 130 | |
| 131 | /* No need to check */ |
| 132 | if (sg_count < 2) |
| 133 | return -1; |
| 134 | |
| 135 | /* We have at least 2 sg entries */ |
| 136 | for (i = 0; i < sg_count; i++) { |
| 137 | if (i == 0) { |
| 138 | /* make sure 1st one does not have hole */ |
| 139 | if (sgl[i].offset + sgl[i].length != PAGE_SIZE) |
| 140 | return i; |
| 141 | } else if (i == sg_count - 1) { |
| 142 | /* make sure last one does not have hole */ |
| 143 | if (sgl[i].offset != 0) |
| 144 | return i; |
| 145 | } else { |
| 146 | /* make sure no hole in the middle */ |
| 147 | if (sgl[i].length != PAGE_SIZE || sgl[i].offset != 0) |
| 148 | return i; |
| 149 | } |
| 150 | } |
| 151 | return -1; |
| 152 | } |
| 153 | |
K. Y. Srinivasan | a9753cb | 2011-05-10 07:54:30 -0700 | [diff] [blame] | 154 | static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl, |
| 155 | unsigned int sg_count, |
| 156 | unsigned int len) |
| 157 | { |
| 158 | int i; |
| 159 | int num_pages; |
| 160 | struct scatterlist *bounce_sgl; |
| 161 | struct page *page_buf; |
| 162 | |
| 163 | num_pages = ALIGN(len, PAGE_SIZE) >> PAGE_SHIFT; |
| 164 | |
| 165 | bounce_sgl = kcalloc(num_pages, sizeof(struct scatterlist), GFP_ATOMIC); |
| 166 | if (!bounce_sgl) |
| 167 | return NULL; |
| 168 | |
| 169 | for (i = 0; i < num_pages; i++) { |
| 170 | page_buf = alloc_page(GFP_ATOMIC); |
| 171 | if (!page_buf) |
| 172 | goto cleanup; |
| 173 | sg_set_page(&bounce_sgl[i], page_buf, 0, 0); |
| 174 | } |
| 175 | |
| 176 | return bounce_sgl; |
| 177 | |
| 178 | cleanup: |
| 179 | destroy_bounce_buffer(bounce_sgl, num_pages); |
| 180 | return NULL; |
| 181 | } |
| 182 | |
K. Y. Srinivasan | 29fe2c9 | 2011-05-10 07:54:31 -0700 | [diff] [blame] | 183 | |
| 184 | /* Assume the original sgl has enough room */ |
| 185 | static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl, |
| 186 | struct scatterlist *bounce_sgl, |
| 187 | unsigned int orig_sgl_count) |
| 188 | { |
| 189 | int i; |
| 190 | int j = 0; |
| 191 | unsigned long src, dest; |
| 192 | unsigned int srclen, destlen, copylen; |
| 193 | unsigned int total_copied = 0; |
| 194 | unsigned long bounce_addr = 0; |
| 195 | unsigned long dest_addr = 0; |
| 196 | unsigned long flags; |
| 197 | |
| 198 | local_irq_save(flags); |
| 199 | |
| 200 | for (i = 0; i < orig_sgl_count; i++) { |
| 201 | dest_addr = (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])), |
| 202 | KM_IRQ0) + orig_sgl[i].offset; |
| 203 | dest = dest_addr; |
| 204 | destlen = orig_sgl[i].length; |
| 205 | |
| 206 | if (bounce_addr == 0) |
| 207 | bounce_addr = |
| 208 | (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])), |
| 209 | KM_IRQ0); |
| 210 | |
| 211 | while (destlen) { |
| 212 | src = bounce_addr + bounce_sgl[j].offset; |
| 213 | srclen = bounce_sgl[j].length - bounce_sgl[j].offset; |
| 214 | |
| 215 | copylen = min(srclen, destlen); |
| 216 | memcpy((void *)dest, (void *)src, copylen); |
| 217 | |
| 218 | total_copied += copylen; |
| 219 | bounce_sgl[j].offset += copylen; |
| 220 | destlen -= copylen; |
| 221 | dest += copylen; |
| 222 | |
| 223 | if (bounce_sgl[j].offset == bounce_sgl[j].length) { |
| 224 | /* full */ |
| 225 | kunmap_atomic((void *)bounce_addr, KM_IRQ0); |
| 226 | j++; |
| 227 | |
| 228 | /* if we need to use another bounce buffer */ |
| 229 | if (destlen || i != orig_sgl_count - 1) |
| 230 | bounce_addr = |
| 231 | (unsigned long)kmap_atomic( |
| 232 | sg_page((&bounce_sgl[j])), KM_IRQ0); |
| 233 | } else if (destlen == 0 && i == orig_sgl_count - 1) { |
| 234 | /* unmap the last bounce that is < PAGE_SIZE */ |
| 235 | kunmap_atomic((void *)bounce_addr, KM_IRQ0); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | kunmap_atomic((void *)(dest_addr - orig_sgl[i].offset), |
| 240 | KM_IRQ0); |
| 241 | } |
| 242 | |
| 243 | local_irq_restore(flags); |
| 244 | |
| 245 | return total_copied; |
| 246 | } |
| 247 | |
K. Y. Srinivasan | 6a8ff44 | 2011-05-10 07:54:32 -0700 | [diff] [blame] | 248 | |
| 249 | /* Assume the bounce_sgl has enough room ie using the create_bounce_buffer() */ |
| 250 | static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl, |
| 251 | struct scatterlist *bounce_sgl, |
| 252 | unsigned int orig_sgl_count) |
| 253 | { |
| 254 | int i; |
| 255 | int j = 0; |
| 256 | unsigned long src, dest; |
| 257 | unsigned int srclen, destlen, copylen; |
| 258 | unsigned int total_copied = 0; |
| 259 | unsigned long bounce_addr = 0; |
| 260 | unsigned long src_addr = 0; |
| 261 | unsigned long flags; |
| 262 | |
| 263 | local_irq_save(flags); |
| 264 | |
| 265 | for (i = 0; i < orig_sgl_count; i++) { |
| 266 | src_addr = (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])), |
| 267 | KM_IRQ0) + orig_sgl[i].offset; |
| 268 | src = src_addr; |
| 269 | srclen = orig_sgl[i].length; |
| 270 | |
| 271 | if (bounce_addr == 0) |
| 272 | bounce_addr = |
| 273 | (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])), |
| 274 | KM_IRQ0); |
| 275 | |
| 276 | while (srclen) { |
| 277 | /* assume bounce offset always == 0 */ |
| 278 | dest = bounce_addr + bounce_sgl[j].length; |
| 279 | destlen = PAGE_SIZE - bounce_sgl[j].length; |
| 280 | |
| 281 | copylen = min(srclen, destlen); |
| 282 | memcpy((void *)dest, (void *)src, copylen); |
| 283 | |
| 284 | total_copied += copylen; |
| 285 | bounce_sgl[j].length += copylen; |
| 286 | srclen -= copylen; |
| 287 | src += copylen; |
| 288 | |
| 289 | if (bounce_sgl[j].length == PAGE_SIZE) { |
| 290 | /* full..move to next entry */ |
| 291 | kunmap_atomic((void *)bounce_addr, KM_IRQ0); |
| 292 | j++; |
| 293 | |
| 294 | /* if we need to use another bounce buffer */ |
| 295 | if (srclen || i != orig_sgl_count - 1) |
| 296 | bounce_addr = |
| 297 | (unsigned long)kmap_atomic( |
| 298 | sg_page((&bounce_sgl[j])), KM_IRQ0); |
| 299 | |
| 300 | } else if (srclen == 0 && i == orig_sgl_count - 1) { |
| 301 | /* unmap the last bounce that is < PAGE_SIZE */ |
| 302 | kunmap_atomic((void *)bounce_addr, KM_IRQ0); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | kunmap_atomic((void *)(src_addr - orig_sgl[i].offset), KM_IRQ0); |
| 307 | } |
| 308 | |
| 309 | local_irq_restore(flags); |
| 310 | |
| 311 | return total_copied; |
| 312 | } |
| 313 | |
K. Y. Srinivasan | 5c5c023 | 2011-05-10 07:54:33 -0700 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * storvsc_remove - Callback when our device is removed |
| 317 | */ |
| 318 | static int storvsc_remove(struct hv_device *dev) |
| 319 | { |
K. Y. Srinivasan | 5c5c023 | 2011-05-10 07:54:33 -0700 | [diff] [blame] | 320 | struct Scsi_Host *host = dev_get_drvdata(&dev->device); |
| 321 | struct hv_host_device *host_dev = |
| 322 | (struct hv_host_device *)host->hostdata; |
| 323 | |
| 324 | /* |
| 325 | * Call to the vsc driver to let it know that the device is being |
| 326 | * removed |
| 327 | */ |
K. Y. Srinivasan | 6cdc57c | 2011-05-10 07:54:48 -0700 | [diff] [blame] | 328 | storvsc_dev_remove(dev); |
K. Y. Srinivasan | 5c5c023 | 2011-05-10 07:54:33 -0700 | [diff] [blame] | 329 | |
| 330 | if (host_dev->request_pool) { |
| 331 | kmem_cache_destroy(host_dev->request_pool); |
| 332 | host_dev->request_pool = NULL; |
| 333 | } |
| 334 | |
| 335 | DPRINT_INFO(STORVSC, "removing host adapter (%p)...", host); |
| 336 | scsi_remove_host(host); |
| 337 | |
| 338 | DPRINT_INFO(STORVSC, "releasing host adapter (%p)...", host); |
| 339 | scsi_host_put(host); |
| 340 | return 0; |
| 341 | } |
| 342 | |
K. Y. Srinivasan | 62838ce | 2011-05-10 07:54:34 -0700 | [diff] [blame] | 343 | |
| 344 | static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev, |
| 345 | sector_t capacity, int *info) |
| 346 | { |
K. Y. Srinivasan | 5326fd5 | 2011-05-10 07:54:52 -0700 | [diff] [blame] | 347 | sector_t nsect = capacity; |
| 348 | sector_t cylinders = nsect; |
| 349 | int heads, sectors_pt; |
K. Y. Srinivasan | 62838ce | 2011-05-10 07:54:34 -0700 | [diff] [blame] | 350 | |
K. Y. Srinivasan | 5326fd5 | 2011-05-10 07:54:52 -0700 | [diff] [blame] | 351 | /* |
| 352 | * We are making up these values; let us keep it simple. |
| 353 | */ |
| 354 | heads = 0xff; |
| 355 | sectors_pt = 0x3f; /* Sectors per track */ |
| 356 | sector_div(cylinders, heads * sectors_pt); |
| 357 | if ((sector_t)(cylinders + 1) * heads * sectors_pt < nsect) |
| 358 | cylinders = 0xffff; |
K. Y. Srinivasan | 62838ce | 2011-05-10 07:54:34 -0700 | [diff] [blame] | 359 | |
| 360 | info[0] = heads; |
K. Y. Srinivasan | 5326fd5 | 2011-05-10 07:54:52 -0700 | [diff] [blame] | 361 | info[1] = sectors_pt; |
| 362 | info[2] = (int)cylinders; |
K. Y. Srinivasan | 62838ce | 2011-05-10 07:54:34 -0700 | [diff] [blame] | 363 | |
K. Y. Srinivasan | 5326fd5 | 2011-05-10 07:54:52 -0700 | [diff] [blame] | 364 | DPRINT_INFO(STORVSC_DRV, "CHS (%d, %d, %d)", (int)cylinders, heads, |
| 365 | sectors_pt); |
K. Y. Srinivasan | 62838ce | 2011-05-10 07:54:34 -0700 | [diff] [blame] | 366 | |
| 367 | return 0; |
| 368 | } |
K. Y. Srinivasan | aa3d789 | 2011-05-10 07:54:37 -0700 | [diff] [blame] | 369 | |
| 370 | static int storvsc_host_reset(struct hv_device *device) |
| 371 | { |
| 372 | struct storvsc_device *stor_device; |
| 373 | struct hv_storvsc_request *request; |
| 374 | struct vstor_packet *vstor_packet; |
| 375 | int ret, t; |
| 376 | |
| 377 | DPRINT_INFO(STORVSC, "resetting host adapter..."); |
| 378 | |
| 379 | stor_device = get_stor_device(device); |
| 380 | if (!stor_device) |
| 381 | return -1; |
| 382 | |
| 383 | request = &stor_device->reset_request; |
| 384 | vstor_packet = &request->vstor_packet; |
| 385 | |
| 386 | init_completion(&request->wait_event); |
| 387 | |
| 388 | vstor_packet->operation = VSTOR_OPERATION_RESET_BUS; |
| 389 | vstor_packet->flags = REQUEST_COMPLETION_FLAG; |
| 390 | vstor_packet->vm_srb.path_id = stor_device->path_id; |
| 391 | |
| 392 | ret = vmbus_sendpacket(device->channel, vstor_packet, |
| 393 | sizeof(struct vstor_packet), |
| 394 | (unsigned long)&stor_device->reset_request, |
| 395 | VM_PKT_DATA_INBAND, |
| 396 | VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); |
| 397 | if (ret != 0) |
| 398 | goto cleanup; |
| 399 | |
| 400 | t = wait_for_completion_timeout(&request->wait_event, HZ); |
| 401 | if (t == 0) { |
| 402 | ret = -ETIMEDOUT; |
| 403 | goto cleanup; |
| 404 | } |
| 405 | |
| 406 | DPRINT_INFO(STORVSC, "host adapter reset completed"); |
| 407 | |
| 408 | /* |
| 409 | * At this point, all outstanding requests in the adapter |
| 410 | * should have been flushed out and return to us |
| 411 | */ |
| 412 | |
| 413 | cleanup: |
| 414 | put_stor_device(device); |
| 415 | return ret; |
| 416 | } |
| 417 | |
| 418 | |
K. Y. Srinivasan | 96e690be | 2011-05-10 07:54:38 -0700 | [diff] [blame] | 419 | /* |
| 420 | * storvsc_host_reset_handler - Reset the scsi HBA |
| 421 | */ |
| 422 | static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd) |
| 423 | { |
| 424 | int ret; |
| 425 | struct hv_host_device *host_dev = |
| 426 | (struct hv_host_device *)scmnd->device->host->hostdata; |
| 427 | struct hv_device *dev = host_dev->dev; |
| 428 | |
| 429 | DPRINT_INFO(STORVSC_DRV, "sdev (%p) dev obj (%p) - host resetting...", |
| 430 | scmnd->device, dev); |
| 431 | |
| 432 | /* Invokes the vsc to reset the host/bus */ |
| 433 | ret = storvsc_host_reset(dev); |
| 434 | if (ret != 0) |
| 435 | return ret; |
| 436 | |
| 437 | DPRINT_INFO(STORVSC_DRV, "sdev (%p) dev obj (%p) - host reseted", |
| 438 | scmnd->device, dev); |
| 439 | |
| 440 | return ret; |
| 441 | } |
| 442 | |
K. Y. Srinivasan | 8a411ba | 2011-05-10 07:54:41 -0700 | [diff] [blame] | 443 | |
| 444 | /* |
| 445 | * storvsc_commmand_completion - Command completion processing |
| 446 | */ |
| 447 | static void storvsc_commmand_completion(struct hv_storvsc_request *request) |
| 448 | { |
| 449 | struct storvsc_cmd_request *cmd_request = |
| 450 | (struct storvsc_cmd_request *)request->context; |
| 451 | struct scsi_cmnd *scmnd = cmd_request->cmd; |
| 452 | struct hv_host_device *host_dev = |
| 453 | (struct hv_host_device *)scmnd->device->host->hostdata; |
| 454 | void (*scsi_done_fn)(struct scsi_cmnd *); |
| 455 | struct scsi_sense_hdr sense_hdr; |
| 456 | struct vmscsi_request *vm_srb; |
| 457 | |
K. Y. Srinivasan | 8a411ba | 2011-05-10 07:54:41 -0700 | [diff] [blame] | 458 | if (cmd_request->bounce_sgl_count) { |
K. Y. Srinivasan | 8a411ba | 2011-05-10 07:54:41 -0700 | [diff] [blame] | 459 | |
| 460 | /* FIXME: We can optimize on writes by just skipping this */ |
| 461 | copy_from_bounce_buffer(scsi_sglist(scmnd), |
| 462 | cmd_request->bounce_sgl, |
| 463 | scsi_sg_count(scmnd)); |
| 464 | destroy_bounce_buffer(cmd_request->bounce_sgl, |
| 465 | cmd_request->bounce_sgl_count); |
| 466 | } |
| 467 | |
| 468 | vm_srb = &request->vstor_packet.vm_srb; |
| 469 | scmnd->result = vm_srb->scsi_status; |
| 470 | |
| 471 | if (scmnd->result) { |
| 472 | if (scsi_normalize_sense(scmnd->sense_buffer, |
| 473 | SCSI_SENSE_BUFFERSIZE, &sense_hdr)) |
| 474 | scsi_print_sense_hdr("storvsc", &sense_hdr); |
| 475 | } |
| 476 | |
K. Y. Srinivasan | 8a411ba | 2011-05-10 07:54:41 -0700 | [diff] [blame] | 477 | scsi_set_resid(scmnd, |
| 478 | request->data_buffer.len - |
| 479 | vm_srb->data_transfer_length); |
| 480 | |
| 481 | scsi_done_fn = scmnd->scsi_done; |
| 482 | |
| 483 | scmnd->host_scribble = NULL; |
| 484 | scmnd->scsi_done = NULL; |
| 485 | |
| 486 | /* !!DO NOT MODIFY the scmnd after this call */ |
| 487 | scsi_done_fn(scmnd); |
| 488 | |
| 489 | kmem_cache_free(host_dev->request_pool, cmd_request); |
| 490 | } |
| 491 | |
K. Y. Srinivasan | c5b463a | 2011-05-10 07:54:42 -0700 | [diff] [blame] | 492 | |
| 493 | /* |
| 494 | * storvsc_queuecommand - Initiate command processing |
| 495 | */ |
| 496 | static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, |
| 497 | void (*done)(struct scsi_cmnd *)) |
| 498 | { |
| 499 | int ret; |
| 500 | struct hv_host_device *host_dev = |
| 501 | (struct hv_host_device *)scmnd->device->host->hostdata; |
| 502 | struct hv_device *dev = host_dev->dev; |
K. Y. Srinivasan | c5b463a | 2011-05-10 07:54:42 -0700 | [diff] [blame] | 503 | struct hv_storvsc_request *request; |
| 504 | struct storvsc_cmd_request *cmd_request; |
| 505 | unsigned int request_size = 0; |
| 506 | int i; |
| 507 | struct scatterlist *sgl; |
| 508 | unsigned int sg_count = 0; |
| 509 | struct vmscsi_request *vm_srb; |
| 510 | |
| 511 | |
| 512 | /* If retrying, no need to prep the cmd */ |
| 513 | if (scmnd->host_scribble) { |
K. Y. Srinivasan | c5b463a | 2011-05-10 07:54:42 -0700 | [diff] [blame] | 514 | |
| 515 | cmd_request = |
| 516 | (struct storvsc_cmd_request *)scmnd->host_scribble; |
| 517 | DPRINT_INFO(STORVSC_DRV, "retrying scmnd %p cmd_request %p", |
| 518 | scmnd, cmd_request); |
| 519 | |
| 520 | goto retry_request; |
| 521 | } |
| 522 | |
K. Y. Srinivasan | c5b463a | 2011-05-10 07:54:42 -0700 | [diff] [blame] | 523 | scmnd->scsi_done = done; |
| 524 | |
| 525 | request_size = sizeof(struct storvsc_cmd_request); |
| 526 | |
| 527 | cmd_request = kmem_cache_zalloc(host_dev->request_pool, |
| 528 | GFP_ATOMIC); |
| 529 | if (!cmd_request) { |
| 530 | scmnd->scsi_done = NULL; |
| 531 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 532 | } |
| 533 | |
| 534 | /* Setup the cmd request */ |
| 535 | cmd_request->bounce_sgl_count = 0; |
| 536 | cmd_request->bounce_sgl = NULL; |
| 537 | cmd_request->cmd = scmnd; |
| 538 | |
| 539 | scmnd->host_scribble = (unsigned char *)cmd_request; |
| 540 | |
| 541 | request = &cmd_request->request; |
| 542 | vm_srb = &request->vstor_packet.vm_srb; |
| 543 | |
| 544 | |
| 545 | /* Build the SRB */ |
| 546 | switch (scmnd->sc_data_direction) { |
| 547 | case DMA_TO_DEVICE: |
| 548 | vm_srb->data_in = WRITE_TYPE; |
| 549 | break; |
| 550 | case DMA_FROM_DEVICE: |
| 551 | vm_srb->data_in = READ_TYPE; |
| 552 | break; |
| 553 | default: |
| 554 | vm_srb->data_in = UNKNOWN_TYPE; |
| 555 | break; |
| 556 | } |
| 557 | |
| 558 | request->on_io_completion = storvsc_commmand_completion; |
| 559 | request->context = cmd_request;/* scmnd; */ |
| 560 | |
K. Y. Srinivasan | c5b463a | 2011-05-10 07:54:42 -0700 | [diff] [blame] | 561 | vm_srb->port_number = host_dev->port; |
| 562 | vm_srb->path_id = scmnd->device->channel; |
| 563 | vm_srb->target_id = scmnd->device->id; |
| 564 | vm_srb->lun = scmnd->device->lun; |
| 565 | |
K. Y. Srinivasan | c5b463a | 2011-05-10 07:54:42 -0700 | [diff] [blame] | 566 | vm_srb->cdb_length = scmnd->cmd_len; |
| 567 | |
| 568 | memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length); |
| 569 | |
| 570 | request->sense_buffer = scmnd->sense_buffer; |
| 571 | |
| 572 | |
| 573 | request->data_buffer.len = scsi_bufflen(scmnd); |
| 574 | if (scsi_sg_count(scmnd)) { |
| 575 | sgl = (struct scatterlist *)scsi_sglist(scmnd); |
| 576 | sg_count = scsi_sg_count(scmnd); |
| 577 | |
| 578 | /* check if we need to bounce the sgl */ |
| 579 | if (do_bounce_buffer(sgl, scsi_sg_count(scmnd)) != -1) { |
| 580 | cmd_request->bounce_sgl = |
| 581 | create_bounce_buffer(sgl, scsi_sg_count(scmnd), |
| 582 | scsi_bufflen(scmnd)); |
| 583 | if (!cmd_request->bounce_sgl) { |
| 584 | scmnd->scsi_done = NULL; |
| 585 | scmnd->host_scribble = NULL; |
| 586 | kmem_cache_free(host_dev->request_pool, |
| 587 | cmd_request); |
| 588 | |
| 589 | return SCSI_MLQUEUE_HOST_BUSY; |
| 590 | } |
| 591 | |
| 592 | cmd_request->bounce_sgl_count = |
| 593 | ALIGN(scsi_bufflen(scmnd), PAGE_SIZE) >> |
| 594 | PAGE_SHIFT; |
| 595 | |
| 596 | /* |
| 597 | * FIXME: We can optimize on reads by just skipping |
| 598 | * this |
| 599 | */ |
| 600 | copy_to_bounce_buffer(sgl, cmd_request->bounce_sgl, |
| 601 | scsi_sg_count(scmnd)); |
| 602 | |
| 603 | sgl = cmd_request->bounce_sgl; |
| 604 | sg_count = cmd_request->bounce_sgl_count; |
| 605 | } |
| 606 | |
| 607 | request->data_buffer.offset = sgl[0].offset; |
| 608 | |
| 609 | for (i = 0; i < sg_count; i++) |
| 610 | request->data_buffer.pfn_array[i] = |
| 611 | page_to_pfn(sg_page((&sgl[i]))); |
| 612 | |
| 613 | } else if (scsi_sglist(scmnd)) { |
K. Y. Srinivasan | c5b463a | 2011-05-10 07:54:42 -0700 | [diff] [blame] | 614 | request->data_buffer.offset = |
| 615 | virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1); |
| 616 | request->data_buffer.pfn_array[0] = |
| 617 | virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT; |
| 618 | } |
| 619 | |
| 620 | retry_request: |
| 621 | /* Invokes the vsc to start an IO */ |
K. Y. Srinivasan | 636f0fd | 2011-05-10 07:54:50 -0700 | [diff] [blame] | 622 | ret = storvsc_do_io(dev, &cmd_request->request); |
| 623 | |
K. Y. Srinivasan | c5b463a | 2011-05-10 07:54:42 -0700 | [diff] [blame] | 624 | if (ret == -1) { |
| 625 | /* no more space */ |
| 626 | |
| 627 | if (cmd_request->bounce_sgl_count) { |
| 628 | /* |
| 629 | * FIXME: We can optimize on writes by just skipping |
| 630 | * this |
| 631 | */ |
| 632 | copy_from_bounce_buffer(scsi_sglist(scmnd), |
| 633 | cmd_request->bounce_sgl, |
| 634 | scsi_sg_count(scmnd)); |
| 635 | destroy_bounce_buffer(cmd_request->bounce_sgl, |
| 636 | cmd_request->bounce_sgl_count); |
| 637 | } |
| 638 | |
| 639 | kmem_cache_free(host_dev->request_pool, cmd_request); |
| 640 | |
| 641 | scmnd->scsi_done = NULL; |
| 642 | scmnd->host_scribble = NULL; |
| 643 | |
| 644 | ret = SCSI_MLQUEUE_DEVICE_BUSY; |
| 645 | } |
| 646 | |
| 647 | return ret; |
| 648 | } |
| 649 | |
| 650 | static DEF_SCSI_QCMD(storvsc_queuecommand) |
| 651 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 652 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 653 | /* Scsi driver */ |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 654 | static struct scsi_host_template scsi_driver = { |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 655 | .module = THIS_MODULE, |
| 656 | .name = "storvsc_host_t", |
| 657 | .bios_param = storvsc_get_chs, |
| 658 | .queuecommand = storvsc_queuecommand, |
| 659 | .eh_host_reset_handler = storvsc_host_reset_handler, |
| 660 | .slave_alloc = storvsc_device_alloc, |
| 661 | .slave_configure = storvsc_device_configure, |
| 662 | .cmd_per_lun = 1, |
| 663 | /* 64 max_queue * 1 target */ |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 664 | .can_queue = STORVSC_MAX_IO_REQUESTS*STORVSC_MAX_TARGETS, |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 665 | .this_id = -1, |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 666 | /* no use setting to 0 since ll_blk_rw reset it to 1 */ |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 667 | /* currently 32 */ |
| 668 | .sg_tablesize = MAX_MULTIPAGE_BUFFER_COUNT, |
| 669 | /* |
| 670 | * ENABLE_CLUSTERING allows mutiple physically contig bio_vecs to merge |
| 671 | * into 1 sg element. If set, we must limit the max_segment_size to |
| 672 | * PAGE_SIZE, otherwise we may get 1 sg element that represents |
| 673 | * multiple |
| 674 | */ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 675 | /* physically contig pfns (ie sg[x].length > PAGE_SIZE). */ |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 676 | .use_clustering = ENABLE_CLUSTERING, |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 677 | /* Make sure we dont get a sg segment crosses a page boundary */ |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 678 | .dma_boundary = PAGE_SIZE-1, |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 679 | }; |
| 680 | |
| 681 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 682 | /* |
K. Y. Srinivasan | f5c7887 | 2011-05-10 07:54:43 -0700 | [diff] [blame] | 683 | * storvsc_probe - Add a new device for this driver |
| 684 | */ |
| 685 | |
| 686 | static int storvsc_probe(struct hv_device *device) |
| 687 | { |
| 688 | int ret; |
K. Y. Srinivasan | f5c7887 | 2011-05-10 07:54:43 -0700 | [diff] [blame] | 689 | struct Scsi_Host *host; |
| 690 | struct hv_host_device *host_dev; |
| 691 | struct storvsc_device_info device_info; |
| 692 | |
K. Y. Srinivasan | f5c7887 | 2011-05-10 07:54:43 -0700 | [diff] [blame] | 693 | host = scsi_host_alloc(&scsi_driver, |
| 694 | sizeof(struct hv_host_device)); |
| 695 | if (!host) |
| 696 | return -ENOMEM; |
| 697 | |
| 698 | dev_set_drvdata(&device->device, host); |
| 699 | |
| 700 | host_dev = (struct hv_host_device *)host->hostdata; |
| 701 | memset(host_dev, 0, sizeof(struct hv_host_device)); |
| 702 | |
| 703 | host_dev->port = host->host_no; |
| 704 | host_dev->dev = device; |
| 705 | |
| 706 | host_dev->request_pool = |
| 707 | kmem_cache_create(dev_name(&device->device), |
| 708 | sizeof(struct storvsc_cmd_request), 0, |
| 709 | SLAB_HWCACHE_ALIGN, NULL); |
| 710 | |
| 711 | if (!host_dev->request_pool) { |
| 712 | scsi_host_put(host); |
| 713 | return -ENOMEM; |
| 714 | } |
| 715 | |
| 716 | device_info.port_number = host->host_no; |
K. Y. Srinivasan | fa4d123 | 2011-05-10 07:56:01 -0700 | [diff] [blame] | 717 | device_info.ring_buffer_size = storvsc_ringbuffer_size; |
K. Y. Srinivasan | f5c7887 | 2011-05-10 07:54:43 -0700 | [diff] [blame] | 718 | /* Call to the vsc driver to add the device */ |
K. Y. Srinivasan | 58f1f5c | 2011-05-10 07:54:49 -0700 | [diff] [blame] | 719 | ret = storvsc_dev_add(device, (void *)&device_info); |
K. Y. Srinivasan | f5c7887 | 2011-05-10 07:54:43 -0700 | [diff] [blame] | 720 | |
| 721 | if (ret != 0) { |
| 722 | kmem_cache_destroy(host_dev->request_pool); |
| 723 | scsi_host_put(host); |
| 724 | return -1; |
| 725 | } |
| 726 | |
| 727 | host_dev->path = device_info.path_id; |
| 728 | host_dev->target = device_info.target_id; |
| 729 | |
| 730 | /* max # of devices per target */ |
| 731 | host->max_lun = STORVSC_MAX_LUNS_PER_TARGET; |
| 732 | /* max # of targets per channel */ |
| 733 | host->max_id = STORVSC_MAX_TARGETS; |
| 734 | /* max # of channels */ |
| 735 | host->max_channel = STORVSC_MAX_CHANNELS - 1; |
| 736 | |
| 737 | /* Register the HBA and start the scsi bus scan */ |
| 738 | ret = scsi_add_host(host, &device->device); |
| 739 | if (ret != 0) { |
| 740 | |
K. Y. Srinivasan | 6cdc57c | 2011-05-10 07:54:48 -0700 | [diff] [blame] | 741 | storvsc_dev_remove(device); |
K. Y. Srinivasan | f5c7887 | 2011-05-10 07:54:43 -0700 | [diff] [blame] | 742 | |
| 743 | kmem_cache_destroy(host_dev->request_pool); |
| 744 | scsi_host_put(host); |
| 745 | return -1; |
| 746 | } |
| 747 | |
| 748 | scsi_scan_host(host); |
| 749 | return ret; |
| 750 | } |
| 751 | |
K. Y. Srinivasan | 7bd05b9 | 2011-05-10 07:54:45 -0700 | [diff] [blame] | 752 | /* The one and only one */ |
| 753 | |
K. Y. Srinivasan | 40bf63e | 2011-05-10 07:56:09 -0700 | [diff] [blame^] | 754 | static struct hv_driver storvsc_drv = { |
| 755 | .probe = storvsc_probe, |
| 756 | .remove = storvsc_remove, |
K. Y. Srinivasan | 39ae6fa | 2011-05-10 07:54:46 -0700 | [diff] [blame] | 757 | }; |
K. Y. Srinivasan | 7bd05b9 | 2011-05-10 07:54:45 -0700 | [diff] [blame] | 758 | |
| 759 | |
K. Y. Srinivasan | f5c7887 | 2011-05-10 07:54:43 -0700 | [diff] [blame] | 760 | /* |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 761 | * storvsc_drv_init - StorVsc driver initialization. |
| 762 | */ |
K. Y. Srinivasan | db08577 | 2011-03-23 10:50:27 -0700 | [diff] [blame] | 763 | static int storvsc_drv_init(void) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 764 | { |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 765 | int ret; |
K. Y. Srinivasan | 40bf63e | 2011-05-10 07:56:09 -0700 | [diff] [blame^] | 766 | struct hv_driver *drv = &storvsc_drv; |
K. Y. Srinivasan | 01415ab3 | 2011-05-10 07:55:58 -0700 | [diff] [blame] | 767 | u32 max_outstanding_req_per_channel; |
| 768 | |
| 769 | /* |
| 770 | * Divide the ring buffer data size (which is 1 page less |
| 771 | * than the ring buffer size since that page is reserved for |
| 772 | * the ring buffer indices) by the max request size (which is |
| 773 | * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) |
| 774 | */ |
| 775 | |
| 776 | max_outstanding_req_per_channel = |
| 777 | ((storvsc_ringbuffer_size - PAGE_SIZE) / |
| 778 | ALIGN(MAX_MULTIPAGE_BUFFER_PACKET + |
| 779 | sizeof(struct vstor_packet) + sizeof(u64), |
| 780 | sizeof(u64))); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 781 | |
K. Y. Srinivasan | 1a96d9a | 2011-05-10 07:56:06 -0700 | [diff] [blame] | 782 | memcpy(&drv->dev_type, &gStorVscDeviceType, |
| 783 | sizeof(struct hv_guid)); |
| 784 | |
K. Y. Srinivasan | 01415ab3 | 2011-05-10 07:55:58 -0700 | [diff] [blame] | 785 | if (max_outstanding_req_per_channel < |
K. Y. Srinivasan | f8feed0 | 2011-05-10 07:54:24 -0700 | [diff] [blame] | 786 | STORVSC_MAX_IO_REQUESTS) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 787 | return -1; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 788 | |
K. Y. Srinivasan | 4742e82 | 2011-05-10 07:56:05 -0700 | [diff] [blame] | 789 | drv->name = driver_name; |
K. Y. Srinivasan | 206cf17 | 2011-05-10 07:56:04 -0700 | [diff] [blame] | 790 | drv->driver.name = driver_name; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 791 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 792 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 793 | /* The driver belongs to vmbus */ |
K. Y. Srinivasan | 150f939 | 2011-03-07 13:32:31 -0800 | [diff] [blame] | 794 | ret = vmbus_child_driver_register(&drv->driver); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 795 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 796 | return ret; |
| 797 | } |
| 798 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 799 | static int storvsc_drv_exit_cb(struct device *dev, void *data) |
| 800 | { |
| 801 | struct device **curr = (struct device **)data; |
| 802 | *curr = dev; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 803 | return 1; /* stop iterating */ |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Greg Kroah-Hartman | bd1de70 | 2009-07-29 09:04:51 -0700 | [diff] [blame] | 806 | static void storvsc_drv_exit(void) |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 807 | { |
K. Y. Srinivasan | 40bf63e | 2011-05-10 07:56:09 -0700 | [diff] [blame^] | 808 | struct hv_driver *drv = &storvsc_drv; |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 809 | struct device *current_dev = NULL; |
Bill Pemberton | 2295ba2 | 2009-07-28 13:46:22 -0400 | [diff] [blame] | 810 | int ret; |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 811 | |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 812 | while (1) { |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 813 | current_dev = NULL; |
| 814 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 815 | /* Get the device */ |
K. Y. Srinivasan | 150f939 | 2011-03-07 13:32:31 -0800 | [diff] [blame] | 816 | ret = driver_for_each_device(&drv->driver, NULL, |
Bill Pemberton | 2295ba2 | 2009-07-28 13:46:22 -0400 | [diff] [blame] | 817 | (void *) ¤t_dev, |
| 818 | storvsc_drv_exit_cb); |
| 819 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 820 | |
| 821 | if (current_dev == NULL) |
| 822 | break; |
| 823 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 824 | /* Initiate removal from the top-down */ |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 825 | device_unregister(current_dev); |
| 826 | } |
| 827 | |
K. Y. Srinivasan | 150f939 | 2011-03-07 13:32:31 -0800 | [diff] [blame] | 828 | vmbus_child_driver_unregister(&drv->driver); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 829 | return; |
| 830 | } |
| 831 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 832 | static int __init storvsc_init(void) |
| 833 | { |
| 834 | int ret; |
| 835 | |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 836 | DPRINT_INFO(STORVSC_DRV, "Storvsc initializing...."); |
K. Y. Srinivasan | db08577 | 2011-03-23 10:50:27 -0700 | [diff] [blame] | 837 | ret = storvsc_drv_init(); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 838 | return ret; |
| 839 | } |
| 840 | |
| 841 | static void __exit storvsc_exit(void) |
| 842 | { |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 843 | storvsc_drv_exit(); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Greg Kroah-Hartman | ff568d3 | 2009-09-02 08:37:47 -0700 | [diff] [blame] | 846 | MODULE_LICENSE("GPL"); |
Hank Janssen | 26c14cc | 2010-02-11 23:02:42 +0000 | [diff] [blame] | 847 | MODULE_VERSION(HV_DRV_VERSION); |
Stephen Hemminger | 3afc7cc3 | 2010-05-06 21:44:45 -0700 | [diff] [blame] | 848 | MODULE_DESCRIPTION("Microsoft Hyper-V virtual storage driver"); |
Hank Janssen | bef4a34 | 2009-07-13 16:01:31 -0700 | [diff] [blame] | 849 | module_init(storvsc_init); |
| 850 | module_exit(storvsc_exit); |