2 * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
20 * K. Y. Srinivasan <kys@microsoft.com>
23 #include <linux/kernel.h>
24 #include <linux/wait.h>
25 #include <linux/sched.h>
26 #include <linux/completion.h>
27 #include <linux/string.h>
29 #include <linux/delay.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/module.h>
33 #include <linux/device.h>
34 #include <linux/hyperv.h>
35 #include <linux/blkdev.h>
36 #include <scsi/scsi.h>
37 #include <scsi/scsi_cmnd.h>
38 #include <scsi/scsi_host.h>
39 #include <scsi/scsi_device.h>
40 #include <scsi/scsi_tcq.h>
41 #include <scsi/scsi_eh.h>
42 #include <scsi/scsi_devinfo.h>
43 #include <scsi/scsi_dbg.h>
46 * All wire protocol details (storage protocol between the guest and the host)
47 * are consolidated here.
49 * Begin protocol definitions.
55 * V1 RC < 2008/1/31: 1.0
56 * V1 RC > 2008/1/31: 2.0
63 #define VMSTOR_PROTO_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
66 #define VMSTOR_PROTO_VERSION_WIN6 VMSTOR_PROTO_VERSION(2, 0)
67 #define VMSTOR_PROTO_VERSION_WIN7 VMSTOR_PROTO_VERSION(4, 2)
68 #define VMSTOR_PROTO_VERSION_WIN8 VMSTOR_PROTO_VERSION(5, 1)
69 #define VMSTOR_PROTO_VERSION_WIN8_1 VMSTOR_PROTO_VERSION(6, 0)
70 #define VMSTOR_PROTO_VERSION_WIN10 VMSTOR_PROTO_VERSION(6, 2)
72 /* Packet structure describing virtual storage requests. */
73 enum vstor_packet_operation {
74 VSTOR_OPERATION_COMPLETE_IO = 1,
75 VSTOR_OPERATION_REMOVE_DEVICE = 2,
76 VSTOR_OPERATION_EXECUTE_SRB = 3,
77 VSTOR_OPERATION_RESET_LUN = 4,
78 VSTOR_OPERATION_RESET_ADAPTER = 5,
79 VSTOR_OPERATION_RESET_BUS = 6,
80 VSTOR_OPERATION_BEGIN_INITIALIZATION = 7,
81 VSTOR_OPERATION_END_INITIALIZATION = 8,
82 VSTOR_OPERATION_QUERY_PROTOCOL_VERSION = 9,
83 VSTOR_OPERATION_QUERY_PROPERTIES = 10,
84 VSTOR_OPERATION_ENUMERATE_BUS = 11,
85 VSTOR_OPERATION_FCHBA_DATA = 12,
86 VSTOR_OPERATION_CREATE_SUB_CHANNELS = 13,
87 VSTOR_OPERATION_MAXIMUM = 13
91 * WWN packet for Fibre Channel HBA
94 struct hv_fc_wwn_packet {
98 u8 primary_port_wwn[8];
99 u8 primary_node_wwn[8];
100 u8 secondary_port_wwn[8];
101 u8 secondary_node_wwn[8];
110 #define SRB_FLAGS_QUEUE_ACTION_ENABLE 0x00000002
111 #define SRB_FLAGS_DISABLE_DISCONNECT 0x00000004
112 #define SRB_FLAGS_DISABLE_SYNCH_TRANSFER 0x00000008
113 #define SRB_FLAGS_BYPASS_FROZEN_QUEUE 0x00000010
114 #define SRB_FLAGS_DISABLE_AUTOSENSE 0x00000020
115 #define SRB_FLAGS_DATA_IN 0x00000040
116 #define SRB_FLAGS_DATA_OUT 0x00000080
117 #define SRB_FLAGS_NO_DATA_TRANSFER 0x00000000
118 #define SRB_FLAGS_UNSPECIFIED_DIRECTION (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)
119 #define SRB_FLAGS_NO_QUEUE_FREEZE 0x00000100
120 #define SRB_FLAGS_ADAPTER_CACHE_ENABLE 0x00000200
121 #define SRB_FLAGS_FREE_SENSE_BUFFER 0x00000400
124 * This flag indicates the request is part of the workflow for processing a D3.
126 #define SRB_FLAGS_D3_PROCESSING 0x00000800
127 #define SRB_FLAGS_IS_ACTIVE 0x00010000
128 #define SRB_FLAGS_ALLOCATED_FROM_ZONE 0x00020000
129 #define SRB_FLAGS_SGLIST_FROM_POOL 0x00040000
130 #define SRB_FLAGS_BYPASS_LOCKED_QUEUE 0x00080000
131 #define SRB_FLAGS_NO_KEEP_AWAKE 0x00100000
132 #define SRB_FLAGS_PORT_DRIVER_ALLOCSENSE 0x00200000
133 #define SRB_FLAGS_PORT_DRIVER_SENSEHASPORT 0x00400000
134 #define SRB_FLAGS_DONT_START_NEXT_PACKET 0x00800000
135 #define SRB_FLAGS_PORT_DRIVER_RESERVED 0x0F000000
136 #define SRB_FLAGS_CLASS_DRIVER_RESERVED 0xF0000000
138 #define SP_UNTAGGED ((unsigned char) ~0)
139 #define SRB_SIMPLE_TAG_REQUEST 0x20
142 * Platform neutral description of a scsi request -
143 * this remains the same across the write regardless of 32/64 bit
144 * note: it's patterned off the SCSI_PASS_THROUGH structure
146 #define STORVSC_MAX_CMD_LEN 0x10
148 #define POST_WIN7_STORVSC_SENSE_BUFFER_SIZE 0x14
149 #define PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE 0x12
151 #define STORVSC_SENSE_BUFFER_SIZE 0x14
152 #define STORVSC_MAX_BUF_LEN_WITH_PADDING 0x14
155 * Sense buffer size changed in win8; have a run-time
156 * variable to track the size we should use. This value will
157 * likely change during protocol negotiation but it is valid
158 * to start by assuming pre-Win8.
160 static int sense_buffer_size = PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE;
163 * The storage protocol version is determined during the
164 * initial exchange with the host. It will indicate which
165 * storage functionality is available in the host.
167 static int vmstor_proto_version;
169 struct vmscsi_win8_extension {
171 * The following were added in Windows 8
181 struct vmscsi_request {
192 u8 sense_info_length;
196 u32 data_transfer_length;
199 u8 cdb[STORVSC_MAX_CMD_LEN];
200 u8 sense_data[STORVSC_SENSE_BUFFER_SIZE];
201 u8 reserved_array[STORVSC_MAX_BUF_LEN_WITH_PADDING];
204 * The following was added in win8.
206 struct vmscsi_win8_extension win8_extension;
208 } __attribute((packed));
212 * The size of the vmscsi_request has changed in win8. The
213 * additional size is because of new elements added to the
214 * structure. These elements are valid only when we are talking
216 * Track the correction to size we need to apply. This value
217 * will likely change during protocol negotiation but it is
218 * valid to start by assuming pre-Win8.
220 static int vmscsi_size_delta = sizeof(struct vmscsi_win8_extension);
223 * The list of storage protocols in order of preference.
225 struct vmstor_protocol {
226 int protocol_version;
227 int sense_buffer_size;
228 int vmscsi_size_delta;
232 static const struct vmstor_protocol vmstor_protocols[] = {
234 VMSTOR_PROTO_VERSION_WIN10,
235 POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
239 VMSTOR_PROTO_VERSION_WIN8_1,
240 POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
244 VMSTOR_PROTO_VERSION_WIN8,
245 POST_WIN7_STORVSC_SENSE_BUFFER_SIZE,
249 VMSTOR_PROTO_VERSION_WIN7,
250 PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
251 sizeof(struct vmscsi_win8_extension),
254 VMSTOR_PROTO_VERSION_WIN6,
255 PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE,
256 sizeof(struct vmscsi_win8_extension),
262 * This structure is sent during the intialization phase to get the different
263 * properties of the channel.
266 #define STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL 0x1
268 struct vmstorage_channel_properties {
274 u32 max_transfer_bytes;
279 /* This structure is sent during the storage protocol negotiations. */
280 struct vmstorage_protocol_version {
281 /* Major (MSW) and minor (LSW) version numbers. */
285 * Revision number is auto-incremented whenever this file is changed
286 * (See FILL_VMSTOR_REVISION macro above). Mismatch does not
287 * definitely indicate incompatibility--but it does indicate mismatched
289 * This is only used on the windows side. Just set it to 0.
294 /* Channel Property Flags */
295 #define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
296 #define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
298 struct vstor_packet {
299 /* Requested operation type */
300 enum vstor_packet_operation operation;
302 /* Flags - see below for values */
305 /* Status of the request returned from the server side. */
308 /* Data payload area */
311 * Structure used to forward SCSI commands from the
312 * client to the server.
314 struct vmscsi_request vm_srb;
316 /* Structure used to query channel properties. */
317 struct vmstorage_channel_properties storage_channel_properties;
319 /* Used during version negotiations. */
320 struct vmstorage_protocol_version version;
322 /* Fibre channel address packet */
323 struct hv_fc_wwn_packet wwn_packet;
325 /* Number of sub-channels to create */
326 u16 sub_channel_count;
328 /* This will be the maximum of the union members */
336 * This flag indicates that the server should send back a completion for this
340 #define REQUEST_COMPLETION_FLAG 0x1
342 /* Matches Windows-end */
343 enum storvsc_request_type {
350 * SRB status codes and masks; a subset of the codes used here.
353 #define SRB_STATUS_AUTOSENSE_VALID 0x80
354 #define SRB_STATUS_QUEUE_FROZEN 0x40
355 #define SRB_STATUS_INVALID_LUN 0x20
356 #define SRB_STATUS_SUCCESS 0x01
357 #define SRB_STATUS_ABORTED 0x02
358 #define SRB_STATUS_ERROR 0x04
359 #define SRB_STATUS_DATA_OVERRUN 0x12
361 #define SRB_STATUS(status) \
362 (status & ~(SRB_STATUS_AUTOSENSE_VALID | SRB_STATUS_QUEUE_FROZEN))
364 * This is the end of Protocol specific defines.
367 static int storvsc_ringbuffer_size = (256 * PAGE_SIZE);
368 static u32 max_outstanding_req_per_channel;
370 static int storvsc_vcpus_per_sub_channel = 4;
372 module_param(storvsc_ringbuffer_size, int, S_IRUGO);
373 MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)");
375 module_param(storvsc_vcpus_per_sub_channel, int, S_IRUGO);
376 MODULE_PARM_DESC(vcpus_per_sub_channel, "Ratio of VCPUs to subchannels");
378 * Timeout in seconds for all devices managed by this driver.
380 static int storvsc_timeout = 180;
382 static int msft_blist_flags = BLIST_TRY_VPD_PAGES;
385 static void storvsc_on_channel_callback(void *context);
387 #define STORVSC_MAX_LUNS_PER_TARGET 255
388 #define STORVSC_MAX_TARGETS 2
389 #define STORVSC_MAX_CHANNELS 8
391 #define STORVSC_FC_MAX_LUNS_PER_TARGET 255
392 #define STORVSC_FC_MAX_TARGETS 128
393 #define STORVSC_FC_MAX_CHANNELS 8
395 #define STORVSC_IDE_MAX_LUNS_PER_TARGET 64
396 #define STORVSC_IDE_MAX_TARGETS 1
397 #define STORVSC_IDE_MAX_CHANNELS 1
399 struct storvsc_cmd_request {
400 struct scsi_cmnd *cmd;
402 struct hv_device *device;
404 /* Synchronize the request/response if needed */
405 struct completion wait_event;
407 struct vmbus_channel_packet_multipage_buffer mpb;
408 struct vmbus_packet_mpb_array *payload;
411 struct vstor_packet vstor_packet;
415 /* A storvsc device is a device object that contains a vmbus channel */
416 struct storvsc_device {
417 struct hv_device *device;
421 bool open_sub_channel;
422 atomic_t num_outstanding_req;
423 struct Scsi_Host *host;
425 wait_queue_head_t waiting_to_drain;
428 * Each unique Port/Path/Target represents 1 channel ie scsi
429 * controller. In reality, the pathid, targetid is always 0
430 * and the port is set by us
432 unsigned int port_number;
433 unsigned char path_id;
434 unsigned char target_id;
437 * Max I/O, the device can support.
439 u32 max_transfer_bytes;
440 /* Used for vsc/vsp channel reset process */
441 struct storvsc_cmd_request init_request;
442 struct storvsc_cmd_request reset_request;
445 struct hv_host_device {
446 struct hv_device *dev;
449 unsigned char target;
452 struct storvsc_scan_work {
453 struct work_struct work;
454 struct Scsi_Host *host;
458 static void storvsc_device_scan(struct work_struct *work)
460 struct storvsc_scan_work *wrk;
462 struct scsi_device *sdev;
464 wrk = container_of(work, struct storvsc_scan_work, work);
467 sdev = scsi_device_lookup(wrk->host, 0, 0, lun);
470 scsi_rescan_device(&sdev->sdev_gendev);
471 scsi_device_put(sdev);
477 static void storvsc_host_scan(struct work_struct *work)
479 struct storvsc_scan_work *wrk;
480 struct Scsi_Host *host;
481 struct scsi_device *sdev;
483 wrk = container_of(work, struct storvsc_scan_work, work);
487 * Before scanning the host, first check to see if any of the
488 * currrently known devices have been hot removed. We issue a
489 * "unit ready" command against all currently known devices.
490 * This I/O will result in an error for devices that have been
491 * removed. As part of handling the I/O error, we remove the device.
493 * When a LUN is added or removed, the host sends us a signal to
494 * scan the host. Thus we are forced to discover the LUNs that
495 * may have been removed this way.
497 mutex_lock(&host->scan_mutex);
498 shost_for_each_device(sdev, host)
499 scsi_test_unit_ready(sdev, 1, 1, NULL);
500 mutex_unlock(&host->scan_mutex);
502 * Now scan the host to discover LUNs that may have been added.
504 scsi_scan_host(host);
509 static void storvsc_remove_lun(struct work_struct *work)
511 struct storvsc_scan_work *wrk;
512 struct scsi_device *sdev;
514 wrk = container_of(work, struct storvsc_scan_work, work);
515 if (!scsi_host_get(wrk->host))
518 sdev = scsi_device_lookup(wrk->host, 0, 0, wrk->lun);
521 scsi_remove_device(sdev);
522 scsi_device_put(sdev);
524 scsi_host_put(wrk->host);
532 * We can get incoming messages from the host that are not in response to
533 * messages that we have sent out. An example of this would be messages
534 * received by the guest to notify dynamic addition/removal of LUNs. To
535 * deal with potential race conditions where the driver may be in the
536 * midst of being unloaded when we might receive an unsolicited message
537 * from the host, we have implemented a mechanism to gurantee sequential
540 * 1) Once the device is marked as being destroyed, we will fail all
542 * 2) We permit incoming messages when the device is being destroyed,
543 * only to properly account for messages already sent out.
546 static inline struct storvsc_device *get_out_stor_device(
547 struct hv_device *device)
549 struct storvsc_device *stor_device;
551 stor_device = hv_get_drvdata(device);
553 if (stor_device && stor_device->destroy)
560 static inline void storvsc_wait_to_drain(struct storvsc_device *dev)
562 dev->drain_notify = true;
563 wait_event(dev->waiting_to_drain,
564 atomic_read(&dev->num_outstanding_req) == 0);
565 dev->drain_notify = false;
568 static inline struct storvsc_device *get_in_stor_device(
569 struct hv_device *device)
571 struct storvsc_device *stor_device;
573 stor_device = hv_get_drvdata(device);
579 * If the device is being destroyed; allow incoming
580 * traffic only to cleanup outstanding requests.
583 if (stor_device->destroy &&
584 (atomic_read(&stor_device->num_outstanding_req) == 0))
592 static void handle_sc_creation(struct vmbus_channel *new_sc)
594 struct hv_device *device = new_sc->primary_channel->device_obj;
595 struct storvsc_device *stor_device;
596 struct vmstorage_channel_properties props;
598 stor_device = get_out_stor_device(device);
602 if (stor_device->open_sub_channel == false)
605 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
608 storvsc_ringbuffer_size,
609 storvsc_ringbuffer_size,
611 sizeof(struct vmstorage_channel_properties),
612 storvsc_on_channel_callback, new_sc);
615 static void handle_multichannel_storage(struct hv_device *device, int max_chns)
617 struct storvsc_device *stor_device;
618 int num_cpus = num_online_cpus();
620 struct storvsc_cmd_request *request;
621 struct vstor_packet *vstor_packet;
624 num_sc = ((max_chns > num_cpus) ? num_cpus : max_chns);
625 stor_device = get_out_stor_device(device);
629 request = &stor_device->init_request;
630 vstor_packet = &request->vstor_packet;
632 stor_device->open_sub_channel = true;
634 * Establish a handler for dealing with subchannels.
636 vmbus_set_sc_create_callback(device->channel, handle_sc_creation);
639 * Check to see if sub-channels have already been created. This
640 * can happen when this driver is re-loaded after unloading.
643 if (vmbus_are_subchannels_present(device->channel))
646 stor_device->open_sub_channel = false;
648 * Request the host to create sub-channels.
650 memset(request, 0, sizeof(struct storvsc_cmd_request));
651 init_completion(&request->wait_event);
652 vstor_packet->operation = VSTOR_OPERATION_CREATE_SUB_CHANNELS;
653 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
654 vstor_packet->sub_channel_count = num_sc;
656 ret = vmbus_sendpacket(device->channel, vstor_packet,
657 (sizeof(struct vstor_packet) -
659 (unsigned long)request,
661 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
666 t = wait_for_completion_timeout(&request->wait_event, 10*HZ);
670 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
671 vstor_packet->status != 0)
675 * Now that we created the sub-channels, invoke the check; this
676 * may trigger the callback.
678 stor_device->open_sub_channel = true;
679 vmbus_are_subchannels_present(device->channel);
682 static int storvsc_channel_init(struct hv_device *device)
684 struct storvsc_device *stor_device;
685 struct storvsc_cmd_request *request;
686 struct vstor_packet *vstor_packet;
689 bool process_sub_channels = false;
691 stor_device = get_out_stor_device(device);
695 request = &stor_device->init_request;
696 vstor_packet = &request->vstor_packet;
699 * Now, initiate the vsc/vsp initialization protocol on the open
702 memset(request, 0, sizeof(struct storvsc_cmd_request));
703 init_completion(&request->wait_event);
704 vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
705 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
707 ret = vmbus_sendpacket(device->channel, vstor_packet,
708 (sizeof(struct vstor_packet) -
710 (unsigned long)request,
712 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
716 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
722 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
723 vstor_packet->status != 0) {
729 for (i = 0; i < ARRAY_SIZE(vmstor_protocols); i++) {
730 /* reuse the packet for version range supported */
731 memset(vstor_packet, 0, sizeof(struct vstor_packet));
732 vstor_packet->operation =
733 VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
734 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
736 vstor_packet->version.major_minor =
737 vmstor_protocols[i].protocol_version;
740 * The revision number is only used in Windows; set it to 0.
742 vstor_packet->version.revision = 0;
744 ret = vmbus_sendpacket(device->channel, vstor_packet,
745 (sizeof(struct vstor_packet) -
747 (unsigned long)request,
749 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
753 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
759 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO) {
764 if (vstor_packet->status == 0) {
765 vmstor_proto_version =
766 vmstor_protocols[i].protocol_version;
769 vmstor_protocols[i].sense_buffer_size;
772 vmstor_protocols[i].vmscsi_size_delta;
778 if (vstor_packet->status != 0) {
784 memset(vstor_packet, 0, sizeof(struct vstor_packet));
785 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES;
786 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
788 ret = vmbus_sendpacket(device->channel, vstor_packet,
789 (sizeof(struct vstor_packet) -
791 (unsigned long)request,
793 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
798 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
804 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
805 vstor_packet->status != 0) {
811 * Check to see if multi-channel support is there.
812 * Hosts that implement protocol version of 5.1 and above
813 * support multi-channel.
815 max_chns = vstor_packet->storage_channel_properties.max_channel_cnt;
816 if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN8) {
817 if (vstor_packet->storage_channel_properties.flags &
818 STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL)
819 process_sub_channels = true;
821 stor_device->max_transfer_bytes =
822 vstor_packet->storage_channel_properties.max_transfer_bytes;
824 memset(vstor_packet, 0, sizeof(struct vstor_packet));
825 vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION;
826 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
828 ret = vmbus_sendpacket(device->channel, vstor_packet,
829 (sizeof(struct vstor_packet) -
831 (unsigned long)request,
833 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
838 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
844 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
845 vstor_packet->status != 0) {
850 if (process_sub_channels)
851 handle_multichannel_storage(device, max_chns);
858 static void storvsc_handle_error(struct vmscsi_request *vm_srb,
859 struct scsi_cmnd *scmnd,
860 struct Scsi_Host *host,
863 struct storvsc_scan_work *wrk;
864 void (*process_err_fn)(struct work_struct *work);
865 bool do_work = false;
867 switch (SRB_STATUS(vm_srb->srb_status)) {
868 case SRB_STATUS_ERROR:
870 * Let upper layer deal with error when
871 * sense message is present.
874 if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID)
877 * If there is an error; offline the device since all
878 * error recovery strategies would have already been
879 * deployed on the host side. However, if the command
880 * were a pass-through command deal with it appropriately.
882 switch (scmnd->cmnd[0]) {
885 set_host_byte(scmnd, DID_PASSTHROUGH);
888 * On Some Windows hosts TEST_UNIT_READY command can return
889 * SRB_STATUS_ERROR, let the upper level code deal with it
890 * based on the sense information.
892 case TEST_UNIT_READY:
895 set_host_byte(scmnd, DID_TARGET_FAILURE);
898 case SRB_STATUS_INVALID_LUN:
900 process_err_fn = storvsc_remove_lun;
902 case SRB_STATUS_ABORTED:
903 if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID &&
904 (asc == 0x2a) && (ascq == 0x9)) {
906 process_err_fn = storvsc_device_scan;
908 * Retry the I/O that trigerred this.
910 set_host_byte(scmnd, DID_REQUEUE);
919 * We need to schedule work to process this error; schedule it.
921 wrk = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
923 set_host_byte(scmnd, DID_TARGET_FAILURE);
928 wrk->lun = vm_srb->lun;
929 INIT_WORK(&wrk->work, process_err_fn);
930 schedule_work(&wrk->work);
934 static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request)
936 struct scsi_cmnd *scmnd = cmd_request->cmd;
937 struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
938 struct scsi_sense_hdr sense_hdr;
939 struct vmscsi_request *vm_srb;
940 u32 data_transfer_length;
941 struct Scsi_Host *host;
942 struct storvsc_device *stor_dev;
943 struct hv_device *dev = host_dev->dev;
944 u32 payload_sz = cmd_request->payload_sz;
945 void *payload = cmd_request->payload;
947 stor_dev = get_in_stor_device(dev);
948 host = stor_dev->host;
950 vm_srb = &cmd_request->vstor_packet.vm_srb;
951 data_transfer_length = vm_srb->data_transfer_length;
953 scmnd->result = vm_srb->scsi_status;
956 if (scsi_normalize_sense(scmnd->sense_buffer,
957 SCSI_SENSE_BUFFERSIZE, &sense_hdr))
958 scsi_print_sense_hdr(scmnd->device, "storvsc",
962 if (vm_srb->srb_status != SRB_STATUS_SUCCESS) {
963 storvsc_handle_error(vm_srb, scmnd, host, sense_hdr.asc,
966 * The Windows driver set data_transfer_length on
967 * SRB_STATUS_DATA_OVERRUN. On other errors, this value
968 * is untouched. In these cases we set it to 0.
970 if (vm_srb->srb_status != SRB_STATUS_DATA_OVERRUN)
971 data_transfer_length = 0;
974 scsi_set_resid(scmnd,
975 cmd_request->payload->range.len - data_transfer_length);
977 scmnd->scsi_done(scmnd);
980 sizeof(struct vmbus_channel_packet_multipage_buffer))
984 static void storvsc_on_io_completion(struct hv_device *device,
985 struct vstor_packet *vstor_packet,
986 struct storvsc_cmd_request *request)
988 struct storvsc_device *stor_device;
989 struct vstor_packet *stor_pkt;
991 stor_device = hv_get_drvdata(device);
992 stor_pkt = &request->vstor_packet;
995 * The current SCSI handling on the host side does
996 * not correctly handle:
997 * INQUIRY command with page code parameter set to 0x80
998 * MODE_SENSE command with cmd[2] == 0x1c
1000 * Setup srb and scsi status so this won't be fatal.
1001 * We do this so we can distinguish truly fatal failues
1002 * (srb status == 0x4) and off-line the device in that case.
1005 if ((stor_pkt->vm_srb.cdb[0] == INQUIRY) ||
1006 (stor_pkt->vm_srb.cdb[0] == MODE_SENSE)) {
1007 vstor_packet->vm_srb.scsi_status = 0;
1008 vstor_packet->vm_srb.srb_status = SRB_STATUS_SUCCESS;
1012 /* Copy over the status...etc */
1013 stor_pkt->vm_srb.scsi_status = vstor_packet->vm_srb.scsi_status;
1014 stor_pkt->vm_srb.srb_status = vstor_packet->vm_srb.srb_status;
1015 stor_pkt->vm_srb.sense_info_length =
1016 vstor_packet->vm_srb.sense_info_length;
1019 if ((vstor_packet->vm_srb.scsi_status & 0xFF) == 0x02) {
1020 /* CHECK_CONDITION */
1021 if (vstor_packet->vm_srb.srb_status &
1022 SRB_STATUS_AUTOSENSE_VALID) {
1023 /* autosense data available */
1025 memcpy(request->cmd->sense_buffer,
1026 vstor_packet->vm_srb.sense_data,
1027 vstor_packet->vm_srb.sense_info_length);
1032 stor_pkt->vm_srb.data_transfer_length =
1033 vstor_packet->vm_srb.data_transfer_length;
1035 storvsc_command_completion(request);
1037 if (atomic_dec_and_test(&stor_device->num_outstanding_req) &&
1038 stor_device->drain_notify)
1039 wake_up(&stor_device->waiting_to_drain);
1044 static void storvsc_on_receive(struct hv_device *device,
1045 struct vstor_packet *vstor_packet,
1046 struct storvsc_cmd_request *request)
1048 struct storvsc_scan_work *work;
1049 struct storvsc_device *stor_device;
1051 switch (vstor_packet->operation) {
1052 case VSTOR_OPERATION_COMPLETE_IO:
1053 storvsc_on_io_completion(device, vstor_packet, request);
1056 case VSTOR_OPERATION_REMOVE_DEVICE:
1057 case VSTOR_OPERATION_ENUMERATE_BUS:
1058 stor_device = get_in_stor_device(device);
1059 work = kmalloc(sizeof(struct storvsc_scan_work), GFP_ATOMIC);
1063 INIT_WORK(&work->work, storvsc_host_scan);
1064 work->host = stor_device->host;
1065 schedule_work(&work->work);
1073 static void storvsc_on_channel_callback(void *context)
1075 struct vmbus_channel *channel = (struct vmbus_channel *)context;
1076 struct hv_device *device;
1077 struct storvsc_device *stor_device;
1080 unsigned char packet[ALIGN(sizeof(struct vstor_packet), 8)];
1081 struct storvsc_cmd_request *request;
1084 if (channel->primary_channel != NULL)
1085 device = channel->primary_channel->device_obj;
1087 device = channel->device_obj;
1089 stor_device = get_in_stor_device(device);
1094 ret = vmbus_recvpacket(channel, packet,
1095 ALIGN((sizeof(struct vstor_packet) -
1096 vmscsi_size_delta), 8),
1097 &bytes_recvd, &request_id);
1098 if (ret == 0 && bytes_recvd > 0) {
1100 request = (struct storvsc_cmd_request *)
1101 (unsigned long)request_id;
1103 if ((request == &stor_device->init_request) ||
1104 (request == &stor_device->reset_request)) {
1106 memcpy(&request->vstor_packet, packet,
1107 (sizeof(struct vstor_packet) -
1108 vmscsi_size_delta));
1109 complete(&request->wait_event);
1111 storvsc_on_receive(device,
1112 (struct vstor_packet *)packet,
1123 static int storvsc_connect_to_vsp(struct hv_device *device, u32 ring_size)
1125 struct vmstorage_channel_properties props;
1128 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
1130 ret = vmbus_open(device->channel,
1134 sizeof(struct vmstorage_channel_properties),
1135 storvsc_on_channel_callback, device->channel);
1140 ret = storvsc_channel_init(device);
1145 static int storvsc_dev_remove(struct hv_device *device)
1147 struct storvsc_device *stor_device;
1148 unsigned long flags;
1150 stor_device = hv_get_drvdata(device);
1152 spin_lock_irqsave(&device->channel->inbound_lock, flags);
1153 stor_device->destroy = true;
1154 spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
1157 * At this point, all outbound traffic should be disable. We
1158 * only allow inbound traffic (responses) to proceed so that
1159 * outstanding requests can be completed.
1162 storvsc_wait_to_drain(stor_device);
1165 * Since we have already drained, we don't need to busy wait
1166 * as was done in final_release_stor_device()
1167 * Note that we cannot set the ext pointer to NULL until
1168 * we have drained - to drain the outgoing packets, we need to
1169 * allow incoming packets.
1171 spin_lock_irqsave(&device->channel->inbound_lock, flags);
1172 hv_set_drvdata(device, NULL);
1173 spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
1175 /* Close the channel */
1176 vmbus_close(device->channel);
1182 static int storvsc_do_io(struct hv_device *device,
1183 struct storvsc_cmd_request *request)
1185 struct storvsc_device *stor_device;
1186 struct vstor_packet *vstor_packet;
1187 struct vmbus_channel *outgoing_channel;
1190 vstor_packet = &request->vstor_packet;
1191 stor_device = get_out_stor_device(device);
1197 request->device = device;
1199 * Select an an appropriate channel to send the request out.
1202 outgoing_channel = vmbus_get_outgoing_channel(device->channel);
1205 vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
1207 vstor_packet->vm_srb.length = (sizeof(struct vmscsi_request) -
1211 vstor_packet->vm_srb.sense_info_length = sense_buffer_size;
1214 vstor_packet->vm_srb.data_transfer_length =
1215 request->payload->range.len;
1217 vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB;
1219 if (request->payload->range.len) {
1221 ret = vmbus_sendpacket_mpb_desc(outgoing_channel,
1222 request->payload, request->payload_sz,
1224 (sizeof(struct vstor_packet) -
1226 (unsigned long)request);
1228 ret = vmbus_sendpacket(outgoing_channel, vstor_packet,
1229 (sizeof(struct vstor_packet) -
1231 (unsigned long)request,
1233 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
1239 atomic_inc(&stor_device->num_outstanding_req);
1244 static int storvsc_device_configure(struct scsi_device *sdevice)
1247 blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE);
1249 blk_queue_bounce_limit(sdevice->request_queue, BLK_BOUNCE_ANY);
1251 blk_queue_rq_timeout(sdevice->request_queue, (storvsc_timeout * HZ));
1253 /* Ensure there are no gaps in presented sgls */
1254 blk_queue_virt_boundary(sdevice->request_queue, PAGE_SIZE - 1);
1256 sdevice->no_write_same = 1;
1259 * Add blist flags to permit the reading of the VPD pages even when
1260 * the target may claim SPC-2 compliance. MSFT targets currently
1261 * claim SPC-2 compliance while they implement post SPC-2 features.
1262 * With this patch we can correctly handle WRITE_SAME_16 issues.
1264 sdevice->sdev_bflags |= msft_blist_flags;
1267 * If the host is WIN8 or WIN8 R2, claim conformance to SPC-3
1268 * if the device is a MSFT virtual device. If the host is
1269 * WIN10 or newer, allow write_same.
1271 if (!strncmp(sdevice->vendor, "Msft", 4)) {
1272 switch (vmstor_proto_version) {
1273 case VMSTOR_PROTO_VERSION_WIN8:
1274 case VMSTOR_PROTO_VERSION_WIN8_1:
1275 sdevice->scsi_level = SCSI_SPC_3;
1279 if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN10)
1280 sdevice->no_write_same = 0;
1286 static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev,
1287 sector_t capacity, int *info)
1289 sector_t nsect = capacity;
1290 sector_t cylinders = nsect;
1291 int heads, sectors_pt;
1294 * We are making up these values; let us keep it simple.
1297 sectors_pt = 0x3f; /* Sectors per track */
1298 sector_div(cylinders, heads * sectors_pt);
1299 if ((sector_t)(cylinders + 1) * heads * sectors_pt < nsect)
1303 info[1] = sectors_pt;
1304 info[2] = (int)cylinders;
1309 static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd)
1311 struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
1312 struct hv_device *device = host_dev->dev;
1314 struct storvsc_device *stor_device;
1315 struct storvsc_cmd_request *request;
1316 struct vstor_packet *vstor_packet;
1320 stor_device = get_out_stor_device(device);
1324 request = &stor_device->reset_request;
1325 vstor_packet = &request->vstor_packet;
1327 init_completion(&request->wait_event);
1329 vstor_packet->operation = VSTOR_OPERATION_RESET_BUS;
1330 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
1331 vstor_packet->vm_srb.path_id = stor_device->path_id;
1333 ret = vmbus_sendpacket(device->channel, vstor_packet,
1334 (sizeof(struct vstor_packet) -
1336 (unsigned long)&stor_device->reset_request,
1338 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
1342 t = wait_for_completion_timeout(&request->wait_event, 5*HZ);
1344 return TIMEOUT_ERROR;
1348 * At this point, all outstanding requests in the adapter
1349 * should have been flushed out and return to us
1350 * There is a potential race here where the host may be in
1351 * the process of responding when we return from here.
1352 * Just wait for all in-transit packets to be accounted for
1353 * before we return from here.
1355 storvsc_wait_to_drain(stor_device);
1361 * The host guarantees to respond to each command, although I/O latencies might
1362 * be unbounded on Azure. Reset the timer unconditionally to give the host a
1363 * chance to perform EH.
1365 static enum blk_eh_timer_return storvsc_eh_timed_out(struct scsi_cmnd *scmnd)
1367 return BLK_EH_RESET_TIMER;
1370 static bool storvsc_scsi_cmd_ok(struct scsi_cmnd *scmnd)
1372 bool allowed = true;
1373 u8 scsi_op = scmnd->cmnd[0];
1376 /* the host does not handle WRITE_SAME, log accident usage */
1379 * smartd sends this command and the host does not handle
1380 * this. So, don't send it.
1383 scmnd->result = ILLEGAL_REQUEST << 16;
1392 static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
1395 struct hv_host_device *host_dev = shost_priv(host);
1396 struct hv_device *dev = host_dev->dev;
1397 struct storvsc_cmd_request *cmd_request = scsi_cmd_priv(scmnd);
1399 struct scatterlist *sgl;
1400 unsigned int sg_count = 0;
1401 struct vmscsi_request *vm_srb;
1402 struct scatterlist *cur_sgl;
1403 struct vmbus_packet_mpb_array *payload;
1407 if (vmstor_proto_version <= VMSTOR_PROTO_VERSION_WIN8) {
1409 * On legacy hosts filter unimplemented commands.
1410 * Future hosts are expected to correctly handle
1411 * unsupported commands. Furthermore, it is
1412 * possible that some of the currently
1413 * unsupported commands maybe supported in
1414 * future versions of the host.
1416 if (!storvsc_scsi_cmd_ok(scmnd)) {
1417 scmnd->scsi_done(scmnd);
1422 /* Setup the cmd request */
1423 cmd_request->cmd = scmnd;
1425 vm_srb = &cmd_request->vstor_packet.vm_srb;
1426 vm_srb->win8_extension.time_out_value = 60;
1428 vm_srb->win8_extension.srb_flags |=
1429 SRB_FLAGS_DISABLE_SYNCH_TRANSFER;
1431 if (scmnd->device->tagged_supported) {
1432 vm_srb->win8_extension.srb_flags |=
1433 (SRB_FLAGS_QUEUE_ACTION_ENABLE | SRB_FLAGS_NO_QUEUE_FREEZE);
1434 vm_srb->win8_extension.queue_tag = SP_UNTAGGED;
1435 vm_srb->win8_extension.queue_action = SRB_SIMPLE_TAG_REQUEST;
1439 switch (scmnd->sc_data_direction) {
1441 vm_srb->data_in = WRITE_TYPE;
1442 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_OUT;
1444 case DMA_FROM_DEVICE:
1445 vm_srb->data_in = READ_TYPE;
1446 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_DATA_IN;
1449 vm_srb->data_in = UNKNOWN_TYPE;
1450 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_NO_DATA_TRANSFER;
1454 * This is DMA_BIDIRECTIONAL or something else we are never
1455 * supposed to see here.
1457 WARN(1, "Unexpected data direction: %d\n",
1458 scmnd->sc_data_direction);
1463 vm_srb->port_number = host_dev->port;
1464 vm_srb->path_id = scmnd->device->channel;
1465 vm_srb->target_id = scmnd->device->id;
1466 vm_srb->lun = scmnd->device->lun;
1468 vm_srb->cdb_length = scmnd->cmd_len;
1470 memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length);
1472 sgl = (struct scatterlist *)scsi_sglist(scmnd);
1473 sg_count = scsi_sg_count(scmnd);
1475 length = scsi_bufflen(scmnd);
1476 payload = (struct vmbus_packet_mpb_array *)&cmd_request->mpb;
1477 payload_sz = sizeof(cmd_request->mpb);
1480 if (sg_count > MAX_PAGE_BUFFER_COUNT) {
1482 payload_sz = (sg_count * sizeof(void *) +
1483 sizeof(struct vmbus_packet_mpb_array));
1484 payload = kmalloc(payload_sz, GFP_ATOMIC);
1486 return SCSI_MLQUEUE_DEVICE_BUSY;
1489 payload->range.len = length;
1490 payload->range.offset = sgl[0].offset;
1493 for (i = 0; i < sg_count; i++) {
1494 payload->range.pfn_array[i] =
1495 page_to_pfn(sg_page((cur_sgl)));
1496 cur_sgl = sg_next(cur_sgl);
1499 } else if (scsi_sglist(scmnd)) {
1500 payload->range.len = length;
1501 payload->range.offset =
1502 virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1);
1503 payload->range.pfn_array[0] =
1504 virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT;
1507 cmd_request->payload = payload;
1508 cmd_request->payload_sz = payload_sz;
1510 /* Invokes the vsc to start an IO */
1511 ret = storvsc_do_io(dev, cmd_request);
1513 if (ret == -EAGAIN) {
1515 return SCSI_MLQUEUE_DEVICE_BUSY;
1521 static struct scsi_host_template scsi_driver = {
1522 .module = THIS_MODULE,
1523 .name = "storvsc_host_t",
1524 .cmd_size = sizeof(struct storvsc_cmd_request),
1525 .bios_param = storvsc_get_chs,
1526 .queuecommand = storvsc_queuecommand,
1527 .eh_host_reset_handler = storvsc_host_reset_handler,
1528 .proc_name = "storvsc_host",
1529 .eh_timed_out = storvsc_eh_timed_out,
1530 .slave_configure = storvsc_device_configure,
1533 .use_clustering = ENABLE_CLUSTERING,
1534 /* Make sure we dont get a sg segment crosses a page boundary */
1535 .dma_boundary = PAGE_SIZE-1,
1545 static const struct hv_vmbus_device_id id_table[] = {
1548 .driver_data = SCSI_GUID
1552 .driver_data = IDE_GUID
1554 /* Fibre Channel GUID */
1557 .driver_data = SFC_GUID
1562 MODULE_DEVICE_TABLE(vmbus, id_table);
1564 static int storvsc_probe(struct hv_device *device,
1565 const struct hv_vmbus_device_id *dev_id)
1568 int num_cpus = num_online_cpus();
1569 struct Scsi_Host *host;
1570 struct hv_host_device *host_dev;
1571 bool dev_is_ide = ((dev_id->driver_data == IDE_GUID) ? true : false);
1573 struct storvsc_device *stor_device;
1574 int max_luns_per_target;
1577 int max_sub_channels = 0;
1580 * Based on the windows host we are running on,
1581 * set state to properly communicate with the host.
1584 if (vmbus_proto_version < VERSION_WIN8) {
1585 max_luns_per_target = STORVSC_IDE_MAX_LUNS_PER_TARGET;
1586 max_targets = STORVSC_IDE_MAX_TARGETS;
1587 max_channels = STORVSC_IDE_MAX_CHANNELS;
1589 max_luns_per_target = STORVSC_MAX_LUNS_PER_TARGET;
1590 max_targets = STORVSC_MAX_TARGETS;
1591 max_channels = STORVSC_MAX_CHANNELS;
1593 * On Windows8 and above, we support sub-channels for storage.
1594 * The number of sub-channels offerred is based on the number of
1595 * VCPUs in the guest.
1597 max_sub_channels = (num_cpus / storvsc_vcpus_per_sub_channel);
1600 scsi_driver.can_queue = (max_outstanding_req_per_channel *
1601 (max_sub_channels + 1));
1603 host = scsi_host_alloc(&scsi_driver,
1604 sizeof(struct hv_host_device));
1608 host_dev = shost_priv(host);
1609 memset(host_dev, 0, sizeof(struct hv_host_device));
1611 host_dev->port = host->host_no;
1612 host_dev->dev = device;
1615 stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
1621 stor_device->destroy = false;
1622 stor_device->open_sub_channel = false;
1623 init_waitqueue_head(&stor_device->waiting_to_drain);
1624 stor_device->device = device;
1625 stor_device->host = host;
1626 hv_set_drvdata(device, stor_device);
1628 stor_device->port_number = host->host_no;
1629 ret = storvsc_connect_to_vsp(device, storvsc_ringbuffer_size);
1633 host_dev->path = stor_device->path_id;
1634 host_dev->target = stor_device->target_id;
1636 switch (dev_id->driver_data) {
1638 host->max_lun = STORVSC_FC_MAX_LUNS_PER_TARGET;
1639 host->max_id = STORVSC_FC_MAX_TARGETS;
1640 host->max_channel = STORVSC_FC_MAX_CHANNELS - 1;
1644 host->max_lun = max_luns_per_target;
1645 host->max_id = max_targets;
1646 host->max_channel = max_channels - 1;
1650 host->max_lun = STORVSC_IDE_MAX_LUNS_PER_TARGET;
1651 host->max_id = STORVSC_IDE_MAX_TARGETS;
1652 host->max_channel = STORVSC_IDE_MAX_CHANNELS - 1;
1655 /* max cmd length */
1656 host->max_cmd_len = STORVSC_MAX_CMD_LEN;
1659 * set the table size based on the info we got
1662 host->sg_tablesize = (stor_device->max_transfer_bytes >> PAGE_SHIFT);
1664 /* Register the HBA and start the scsi bus scan */
1665 ret = scsi_add_host(host, &device->device);
1670 scsi_scan_host(host);
1672 target = (device->dev_instance.b[5] << 8 |
1673 device->dev_instance.b[4]);
1674 ret = scsi_add_device(host, 0, target, 0);
1676 scsi_remove_host(host);
1684 * Once we have connected with the host, we would need to
1685 * to invoke storvsc_dev_remove() to rollback this state and
1686 * this call also frees up the stor_device; hence the jump around
1689 storvsc_dev_remove(device);
1696 scsi_host_put(host);
1700 static int storvsc_remove(struct hv_device *dev)
1702 struct storvsc_device *stor_device = hv_get_drvdata(dev);
1703 struct Scsi_Host *host = stor_device->host;
1705 scsi_remove_host(host);
1706 storvsc_dev_remove(dev);
1707 scsi_host_put(host);
1712 static struct hv_driver storvsc_drv = {
1713 .name = KBUILD_MODNAME,
1714 .id_table = id_table,
1715 .probe = storvsc_probe,
1716 .remove = storvsc_remove,
1719 static int __init storvsc_drv_init(void)
1723 * Divide the ring buffer data size (which is 1 page less
1724 * than the ring buffer size since that page is reserved for
1725 * the ring buffer indices) by the max request size (which is
1726 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
1728 max_outstanding_req_per_channel =
1729 ((storvsc_ringbuffer_size - PAGE_SIZE) /
1730 ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
1731 sizeof(struct vstor_packet) + sizeof(u64) -
1735 return vmbus_driver_register(&storvsc_drv);
1738 static void __exit storvsc_drv_exit(void)
1740 vmbus_driver_unregister(&storvsc_drv);
1743 MODULE_LICENSE("GPL");
1744 MODULE_DESCRIPTION("Microsoft Hyper-V virtual storage driver");
1745 module_init(storvsc_drv_init);
1746 module_exit(storvsc_drv_exit);