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>
21 #include <linux/kernel.h>
22 #include <linux/string.h>
23 #include <linux/slab.h>
25 #include <linux/delay.h>
28 #include "storvsc_api.h"
29 #include "vmbus_packet_format.h"
34 struct storvsc_request_extension {
35 /* LIST_ENTRY ListEntry; */
37 struct hv_storvsc_request *request;
38 struct hv_device *device;
40 /* Synchronize the request/response if needed */
41 struct osd_waitevent *wait_event;
43 struct vstor_packet vstor_packet;
46 /* A storvsc device is a device object that contains a vmbus channel */
47 struct storvsc_device {
48 struct hv_device *device;
50 /* 0 indicates the device is being destroyed */
53 atomic_t num_outstanding_req;
56 * Each unique Port/Path/Target represents 1 channel ie scsi
57 * controller. In reality, the pathid, targetid is always 0
58 * and the port is set by us
60 unsigned int port_number;
61 unsigned char path_id;
62 unsigned char target_id;
64 /* LIST_ENTRY OutstandingRequestList; */
65 /* HANDLE OutstandingRequestLock; */
67 /* Used for vsc/vsp channel reset process */
68 struct storvsc_request_extension init_request;
69 struct storvsc_request_extension reset_request;
73 static const char *g_driver_name = "storvsc";
75 /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
76 static const struct hv_guid gStorVscDeviceType = {
78 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
79 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f
84 static inline struct storvsc_device *alloc_stor_device(struct hv_device *device)
86 struct storvsc_device *stor_device;
88 stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
92 /* Set to 2 to allow both inbound and outbound traffics */
93 /* (ie get_stor_device() and must_get_stor_device()) to proceed. */
94 atomic_cmpxchg(&stor_device->ref_count, 0, 2);
96 stor_device->device = device;
97 device->Extension = stor_device;
102 static inline void free_stor_device(struct storvsc_device *device)
104 /* ASSERT(atomic_read(&device->ref_count) == 0); */
108 /* Get the stordevice object iff exists and its refcount > 1 */
109 static inline struct storvsc_device *get_stor_device(struct hv_device *device)
111 struct storvsc_device *stor_device;
113 stor_device = (struct storvsc_device *)device->Extension;
114 if (stor_device && atomic_read(&stor_device->ref_count) > 1)
115 atomic_inc(&stor_device->ref_count);
122 /* Get the stordevice object iff exists and its refcount > 0 */
123 static inline struct storvsc_device *must_get_stor_device(
124 struct hv_device *device)
126 struct storvsc_device *stor_device;
128 stor_device = (struct storvsc_device *)device->Extension;
129 if (stor_device && atomic_read(&stor_device->ref_count))
130 atomic_inc(&stor_device->ref_count);
137 static inline void put_stor_device(struct hv_device *device)
139 struct storvsc_device *stor_device;
141 stor_device = (struct storvsc_device *)device->Extension;
142 /* ASSERT(stor_device); */
144 atomic_dec(&stor_device->ref_count);
145 /* ASSERT(atomic_read(&stor_device->ref_count)); */
148 /* Drop ref count to 1 to effectively disable get_stor_device() */
149 static inline struct storvsc_device *release_stor_device(
150 struct hv_device *device)
152 struct storvsc_device *stor_device;
154 stor_device = (struct storvsc_device *)device->Extension;
155 /* ASSERT(stor_device); */
157 /* Busy wait until the ref drop to 2, then set it to 1 */
158 while (atomic_cmpxchg(&stor_device->ref_count, 2, 1) != 2)
164 /* Drop ref count to 0. No one can use stor_device object. */
165 static inline struct storvsc_device *final_release_stor_device(
166 struct hv_device *device)
168 struct storvsc_device *stor_device;
170 stor_device = (struct storvsc_device *)device->Extension;
171 /* ASSERT(stor_device); */
173 /* Busy wait until the ref drop to 1, then set it to 0 */
174 while (atomic_cmpxchg(&stor_device->ref_count, 1, 0) != 1)
177 device->Extension = NULL;
181 static int stor_vsc_channel_init(struct hv_device *device)
183 struct storvsc_device *stor_device;
184 struct storvsc_request_extension *request;
185 struct vstor_packet *vstor_packet;
188 stor_device = get_stor_device(device);
190 DPRINT_ERR(STORVSC, "unable to get stor device..."
191 "device being destroyed?");
195 request = &stor_device->init_request;
196 vstor_packet = &request->vstor_packet;
199 * Now, initiate the vsc/vsp initialization protocol on the open
202 memset(request, 0, sizeof(struct storvsc_request_extension));
203 request->wait_event = osd_waitevent_create();
204 if (!request->wait_event) {
209 vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
210 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
212 /*SpinlockAcquire(gDriverExt.packetListLock);
213 INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry);
214 SpinlockRelease(gDriverExt.packetListLock);*/
216 DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION...");
218 ret = vmbus_sendpacket(device->channel, vstor_packet,
219 sizeof(struct vstor_packet),
220 (unsigned long)request,
221 VmbusPacketTypeDataInBand,
222 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
225 "unable to send BEGIN_INITIALIZATION_OPERATION");
229 osd_waitevent_wait(request->wait_event);
231 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
232 vstor_packet->status != 0) {
233 DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed "
234 "(op %d status 0x%x)",
235 vstor_packet->operation, vstor_packet->status);
239 DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION...");
241 /* reuse the packet for version range supported */
242 memset(vstor_packet, 0, sizeof(struct vstor_packet));
243 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
244 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
246 vstor_packet->version.major_minor = VMSTOR_PROTOCOL_VERSION_CURRENT;
247 FILL_VMSTOR_REVISION(vstor_packet->version.revision);
249 ret = vmbus_sendpacket(device->channel, vstor_packet,
250 sizeof(struct vstor_packet),
251 (unsigned long)request,
252 VmbusPacketTypeDataInBand,
253 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
256 "unable to send BEGIN_INITIALIZATION_OPERATION");
260 osd_waitevent_wait(request->wait_event);
262 /* TODO: Check returned version */
263 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
264 vstor_packet->status != 0) {
265 DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed "
266 "(op %d status 0x%x)",
267 vstor_packet->operation, vstor_packet->status);
271 /* Query channel properties */
272 DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION...");
274 memset(vstor_packet, 0, sizeof(struct vstor_packet));
275 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES;
276 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
277 vstor_packet->storage_channel_properties.port_number =
278 stor_device->port_number;
280 ret = vmbus_sendpacket(device->channel, vstor_packet,
281 sizeof(struct vstor_packet),
282 (unsigned long)request,
283 VmbusPacketTypeDataInBand,
284 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
288 "unable to send QUERY_PROPERTIES_OPERATION");
292 osd_waitevent_wait(request->wait_event);
294 /* TODO: Check returned version */
295 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
296 vstor_packet->status != 0) {
297 DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed "
298 "(op %d status 0x%x)",
299 vstor_packet->operation, vstor_packet->status);
303 stor_device->path_id = vstor_packet->storage_channel_properties.path_id;
304 stor_device->target_id
305 = vstor_packet->storage_channel_properties.target_id;
307 DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x",
308 vstor_packet->storage_channel_properties.flags,
309 vstor_packet->storage_channel_properties.max_transfer_bytes);
311 DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION...");
313 memset(vstor_packet, 0, sizeof(struct vstor_packet));
314 vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION;
315 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
317 ret = vmbus_sendpacket(device->channel, vstor_packet,
318 sizeof(struct vstor_packet),
319 (unsigned long)request,
320 VmbusPacketTypeDataInBand,
321 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
325 "unable to send END_INITIALIZATION_OPERATION");
329 osd_waitevent_wait(request->wait_event);
331 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
332 vstor_packet->status != 0) {
333 DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed "
334 "(op %d status 0x%x)",
335 vstor_packet->operation, vstor_packet->status);
339 DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****");
342 kfree(request->wait_event);
343 request->wait_event = NULL;
345 put_stor_device(device);
349 static void stor_vsc_on_io_completion(struct hv_device *device,
350 struct vstor_packet *vstor_packet,
351 struct storvsc_request_extension *request_ext)
353 struct hv_storvsc_request *request;
354 struct storvsc_device *stor_device;
356 stor_device = must_get_stor_device(device);
358 DPRINT_ERR(STORVSC, "unable to get stor device..."
359 "device being destroyed?");
363 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p "
364 "completed bytes xfer %u", request_ext,
365 vstor_packet->vm_srb.data_transfer_length);
367 /* ASSERT(request_ext != NULL); */
368 /* ASSERT(request_ext->request != NULL); */
370 request = request_ext->request;
372 /* ASSERT(request->OnIOCompletion != NULL); */
374 /* Copy over the status...etc */
375 request->status = vstor_packet->vm_srb.scsi_status;
377 if (request->status != 0 || vstor_packet->vm_srb.srb_status != 1) {
379 "cmd 0x%x scsi status 0x%x srb status 0x%x\n",
380 request->cdb[0], vstor_packet->vm_srb.scsi_status,
381 vstor_packet->vm_srb.srb_status);
384 if ((request->status & 0xFF) == 0x02) {
385 /* CHECK_CONDITION */
386 if (vstor_packet->vm_srb.srb_status & 0x80) {
387 /* autosense data available */
388 DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data "
389 "valid - len %d\n", request_ext,
390 vstor_packet->vm_srb.sense_info_length);
392 /* ASSERT(vstor_packet->vm_srb.sense_info_length <= */
393 /* request->SenseBufferSize); */
394 memcpy(request->sense_buffer,
395 vstor_packet->vm_srb.sense_data,
396 vstor_packet->vm_srb.sense_info_length);
398 request->sense_buffer_size =
399 vstor_packet->vm_srb.sense_info_length;
404 request->bytes_xfer = vstor_packet->vm_srb.data_transfer_length;
406 request->on_io_completion(request);
408 atomic_dec(&stor_device->num_outstanding_req);
410 put_stor_device(device);
413 static void stor_vsc_on_receive(struct hv_device *device,
414 struct vstor_packet *vstor_packet,
415 struct storvsc_request_extension *request_ext)
417 switch (vstor_packet->operation) {
418 case VSTOR_OPERATION_COMPLETE_IO:
419 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION");
420 stor_vsc_on_io_completion(device, vstor_packet, request_ext);
422 case VSTOR_OPERATION_REMOVE_DEVICE:
423 DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION");
428 DPRINT_INFO(STORVSC, "Unknown operation received - %d",
429 vstor_packet->operation);
434 static void stor_vsc_on_channel_callback(void *context)
436 struct hv_device *device = (struct hv_device *)context;
437 struct storvsc_device *stor_device;
440 unsigned char packet[ALIGN_UP(sizeof(struct vstor_packet), 8)];
441 struct storvsc_request_extension *request;
444 /* ASSERT(device); */
446 stor_device = must_get_stor_device(device);
448 DPRINT_ERR(STORVSC, "unable to get stor device..."
449 "device being destroyed?");
454 ret = vmbus_recvpacket(device->channel, packet,
455 ALIGN_UP(sizeof(struct vstor_packet), 8),
456 &bytes_recvd, &request_id);
457 if (ret == 0 && bytes_recvd > 0) {
458 DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx",
459 bytes_recvd, request_id);
461 /* ASSERT(bytes_recvd ==
462 sizeof(struct vstor_packet)); */
464 request = (struct storvsc_request_extension *)
465 (unsigned long)request_id;
466 /* ASSERT(request);c */
468 /* if (vstor_packet.Flags & SYNTHETIC_FLAG) */
469 if ((request == &stor_device->init_request) ||
470 (request == &stor_device->reset_request)) {
471 /* DPRINT_INFO(STORVSC,
472 * "reset completion - operation "
474 * vstor_packet.Operation,
475 * vstor_packet.Status); */
477 memcpy(&request->vstor_packet, packet,
478 sizeof(struct vstor_packet));
480 osd_waitevent_set(request->wait_event);
482 stor_vsc_on_receive(device,
483 (struct vstor_packet *)packet,
487 /* DPRINT_DBG(STORVSC, "nothing else to read..."); */
492 put_stor_device(device);
496 static int stor_vsc_connect_to_vsp(struct hv_device *device)
498 struct vmstorage_channel_properties props;
499 struct storvsc_driver_object *stor_driver;
502 stor_driver = (struct storvsc_driver_object *)device->Driver;
503 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
505 /* Open the channel */
506 ret = vmbus_open(device->channel,
507 stor_driver->ring_buffer_size,
508 stor_driver->ring_buffer_size,
510 sizeof(struct vmstorage_channel_properties),
511 stor_vsc_on_channel_callback, device);
513 DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d",
514 props.path_id, props.target_id, props.max_transfer_bytes);
517 DPRINT_ERR(STORVSC, "unable to open channel: %d", ret);
521 ret = stor_vsc_channel_init(device);
527 * stor_vsc_on_device_add - Callback when the device belonging to this driver
530 static int stor_vsc_on_device_add(struct hv_device *device,
531 void *additional_info)
533 struct storvsc_device *stor_device;
534 /* struct vmstorage_channel_properties *props; */
535 struct storvsc_device_info *device_info;
538 device_info = (struct storvsc_device_info *)additional_info;
539 stor_device = alloc_stor_device(device);
545 /* Save the channel properties to our storvsc channel */
546 /* props = (struct vmstorage_channel_properties *)
547 * channel->offerMsg.Offer.u.Standard.UserDefined; */
551 * If we support more than 1 scsi channel, we need to set the
552 * port number here to the scsi channel but how do we get the
553 * scsi channel prior to the bus scan
556 /* storChannel->PortNumber = 0;
557 storChannel->PathId = props->PathId;
558 storChannel->TargetId = props->TargetId; */
560 stor_device->port_number = device_info->port_number;
561 /* Send it back up */
562 ret = stor_vsc_connect_to_vsp(device);
564 /* device_info->PortNumber = stor_device->PortNumber; */
565 device_info->path_id = stor_device->path_id;
566 device_info->target_id = stor_device->target_id;
568 DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n",
569 stor_device->port_number, stor_device->path_id,
570 stor_device->target_id);
577 * stor_vsc_on_device_remove - Callback when the our device is being removed
579 static int stor_vsc_on_device_remove(struct hv_device *device)
581 struct storvsc_device *stor_device;
583 DPRINT_INFO(STORVSC, "disabling storage device (%p)...",
586 stor_device = release_stor_device(device);
589 * At this point, all outbound traffic should be disable. We
590 * only allow inbound traffic (responses) to proceed so that
591 * outstanding requests can be completed.
593 while (atomic_read(&stor_device->num_outstanding_req)) {
594 DPRINT_INFO(STORVSC, "waiting for %d requests to complete...",
595 atomic_read(&stor_device->num_outstanding_req));
599 DPRINT_INFO(STORVSC, "removing storage device (%p)...",
602 stor_device = final_release_stor_device(device);
604 DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", stor_device);
606 /* Close the channel */
607 vmbus_close(device->channel);
609 free_stor_device(stor_device);
613 int stor_vsc_on_host_reset(struct hv_device *device)
615 struct storvsc_device *stor_device;
616 struct storvsc_request_extension *request;
617 struct vstor_packet *vstor_packet;
620 DPRINT_INFO(STORVSC, "resetting host adapter...");
622 stor_device = get_stor_device(device);
624 DPRINT_ERR(STORVSC, "unable to get stor device..."
625 "device being destroyed?");
629 request = &stor_device->reset_request;
630 vstor_packet = &request->vstor_packet;
632 request->wait_event = osd_waitevent_create();
633 if (!request->wait_event) {
638 vstor_packet->operation = VSTOR_OPERATION_RESET_BUS;
639 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
640 vstor_packet->vm_srb.path_id = stor_device->path_id;
642 ret = vmbus_sendpacket(device->channel, vstor_packet,
643 sizeof(struct vstor_packet),
644 (unsigned long)&stor_device->reset_request,
645 VmbusPacketTypeDataInBand,
646 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
648 DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d",
653 /* FIXME: Add a timeout */
654 osd_waitevent_wait(request->wait_event);
656 kfree(request->wait_event);
657 DPRINT_INFO(STORVSC, "host adapter reset completed");
660 * At this point, all outstanding requests in the adapter
661 * should have been flushed out and return to us
665 put_stor_device(device);
670 * stor_vsc_on_io_request - Callback to initiate an I/O request
672 static int stor_vsc_on_io_request(struct hv_device *device,
673 struct hv_storvsc_request *request)
675 struct storvsc_device *stor_device;
676 struct storvsc_request_extension *request_extension;
677 struct vstor_packet *vstor_packet;
681 (struct storvsc_request_extension *)request->extension;
682 vstor_packet = &request_extension->vstor_packet;
683 stor_device = get_stor_device(device);
685 DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, "
686 "Extension %p", device, stor_device, request,
689 DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d",
690 request, request->data_buffer.Length, request->bus,
691 request->target_id, request->lun_id, request->cdb_len);
694 DPRINT_ERR(STORVSC, "unable to get stor device..."
695 "device being destroyed?");
699 /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, request->Cdb,
700 * request->CdbLen); */
702 request_extension->request = request;
703 request_extension->device = device;
705 memset(vstor_packet, 0 , sizeof(struct vstor_packet));
707 vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
709 vstor_packet->vm_srb.length = sizeof(struct vmscsi_request);
711 vstor_packet->vm_srb.port_number = request->host;
712 vstor_packet->vm_srb.path_id = request->bus;
713 vstor_packet->vm_srb.target_id = request->target_id;
714 vstor_packet->vm_srb.lun = request->lun_id;
716 vstor_packet->vm_srb.sense_info_length = SENSE_BUFFER_SIZE;
718 /* Copy over the scsi command descriptor block */
719 vstor_packet->vm_srb.cdb_length = request->cdb_len;
720 memcpy(&vstor_packet->vm_srb.cdb, request->cdb, request->cdb_len);
722 vstor_packet->vm_srb.data_in = request->type;
723 vstor_packet->vm_srb.data_transfer_length = request->data_buffer.Length;
725 vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB;
727 DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, "
728 "lun %d senselen %d cdblen %d",
729 vstor_packet->vm_srb.length,
730 vstor_packet->vm_srb.port_number,
731 vstor_packet->vm_srb.path_id,
732 vstor_packet->vm_srb.target_id,
733 vstor_packet->vm_srb.lun,
734 vstor_packet->vm_srb.sense_info_length,
735 vstor_packet->vm_srb.cdb_length);
737 if (request_extension->request->data_buffer.Length) {
738 ret = vmbus_sendpacket_multipagebuffer(device->channel,
739 &request_extension->request->data_buffer,
741 sizeof(struct vstor_packet),
742 (unsigned long)request_extension);
744 ret = vmbus_sendpacket(device->channel, vstor_packet,
745 sizeof(struct vstor_packet),
746 (unsigned long)request_extension,
747 VmbusPacketTypeDataInBand,
748 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
752 DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d",
756 atomic_inc(&stor_device->num_outstanding_req);
758 put_stor_device(device);
763 * stor_vsc_on_cleanup - Perform any cleanup when the driver is removed
765 static void stor_vsc_on_cleanup(struct hv_driver *driver)
770 * stor_vsc_initialize - Main entry point
772 int stor_vsc_initialize(struct hv_driver *driver)
774 struct storvsc_driver_object *stor_driver;
776 stor_driver = (struct storvsc_driver_object *)driver;
778 DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd "
779 "sizeof(struct storvsc_request_extension)=%zd "
780 "sizeof(struct vstor_packet)=%zd, "
781 "sizeof(struct vmscsi_request)=%zd",
782 sizeof(struct hv_storvsc_request),
783 sizeof(struct storvsc_request_extension),
784 sizeof(struct vstor_packet),
785 sizeof(struct vmscsi_request));
787 /* Make sure we are at least 2 pages since 1 page is used for control */
788 /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */
790 driver->name = g_driver_name;
791 memcpy(&driver->deviceType, &gStorVscDeviceType,
792 sizeof(struct hv_guid));
794 stor_driver->request_ext_size =
795 sizeof(struct storvsc_request_extension);
798 * Divide the ring buffer data size (which is 1 page less
799 * than the ring buffer size since that page is reserved for
800 * the ring buffer indices) by the max request size (which is
801 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
803 stor_driver->max_outstanding_req_per_channel =
804 ((stor_driver->ring_buffer_size - PAGE_SIZE) /
805 ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET +
806 sizeof(struct vstor_packet) + sizeof(u64),
809 DPRINT_INFO(STORVSC, "max io %u, currently %u\n",
810 stor_driver->max_outstanding_req_per_channel,
811 STORVSC_MAX_IO_REQUESTS);
813 /* Setup the dispatch table */
814 stor_driver->base.OnDeviceAdd = stor_vsc_on_device_add;
815 stor_driver->base.OnDeviceRemove = stor_vsc_on_device_remove;
816 stor_driver->base.OnCleanup = stor_vsc_on_cleanup;
818 stor_driver->on_io_request = stor_vsc_on_io_request;