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 *WaitEvent;
43 struct vstor_packet VStorPacket;
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 NumOutstandingRequests;
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 PortNumber;
62 unsigned char TargetId;
64 /* LIST_ENTRY OutstandingRequestList; */
65 /* HANDLE OutstandingRequestLock; */
67 /* Used for vsc/vsp channel reset process */
68 struct storvsc_request_extension InitRequest;
69 struct storvsc_request_extension ResetRequest;
73 static const char *gDriverName = "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 *AllocStorDevice(struct hv_device *Device)
86 struct storvsc_device *storDevice;
88 storDevice = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
92 /* Set to 2 to allow both inbound and outbound traffics */
93 /* (ie GetStorDevice() and MustGetStorDevice()) to proceed. */
94 atomic_cmpxchg(&storDevice->RefCount, 0, 2);
96 storDevice->Device = Device;
97 Device->Extension = storDevice;
102 static inline void FreeStorDevice(struct storvsc_device *Device)
104 /* ASSERT(atomic_read(&Device->RefCount) == 0); */
108 /* Get the stordevice object iff exists and its refcount > 1 */
109 static inline struct storvsc_device *GetStorDevice(struct hv_device *Device)
111 struct storvsc_device *storDevice;
113 storDevice = (struct storvsc_device *)Device->Extension;
114 if (storDevice && atomic_read(&storDevice->RefCount) > 1)
115 atomic_inc(&storDevice->RefCount);
122 /* Get the stordevice object iff exists and its refcount > 0 */
123 static inline struct storvsc_device *MustGetStorDevice(struct hv_device *Device)
125 struct storvsc_device *storDevice;
127 storDevice = (struct storvsc_device *)Device->Extension;
128 if (storDevice && atomic_read(&storDevice->RefCount))
129 atomic_inc(&storDevice->RefCount);
136 static inline void PutStorDevice(struct hv_device *Device)
138 struct storvsc_device *storDevice;
140 storDevice = (struct storvsc_device *)Device->Extension;
141 /* ASSERT(storDevice); */
143 atomic_dec(&storDevice->RefCount);
144 /* ASSERT(atomic_read(&storDevice->RefCount)); */
147 /* Drop ref count to 1 to effectively disable GetStorDevice() */
148 static inline struct storvsc_device *ReleaseStorDevice(struct hv_device *Device)
150 struct storvsc_device *storDevice;
152 storDevice = (struct storvsc_device *)Device->Extension;
153 /* ASSERT(storDevice); */
155 /* Busy wait until the ref drop to 2, then set it to 1 */
156 while (atomic_cmpxchg(&storDevice->RefCount, 2, 1) != 2)
162 /* Drop ref count to 0. No one can use StorDevice object. */
163 static inline struct storvsc_device *FinalReleaseStorDevice(
164 struct hv_device *Device)
166 struct storvsc_device *storDevice;
168 storDevice = (struct storvsc_device *)Device->Extension;
169 /* ASSERT(storDevice); */
171 /* Busy wait until the ref drop to 1, then set it to 0 */
172 while (atomic_cmpxchg(&storDevice->RefCount, 1, 0) != 1)
175 Device->Extension = NULL;
179 static int StorVscChannelInit(struct hv_device *Device)
181 struct storvsc_device *storDevice;
182 struct storvsc_request_extension *request;
183 struct vstor_packet *vstorPacket;
186 storDevice = GetStorDevice(Device);
188 DPRINT_ERR(STORVSC, "unable to get stor device..."
189 "device being destroyed?");
193 request = &storDevice->InitRequest;
194 vstorPacket = &request->VStorPacket;
197 * Now, initiate the vsc/vsp initialization protocol on the open
200 memset(request, 0, sizeof(struct storvsc_request_extension));
201 request->WaitEvent = osd_WaitEventCreate();
202 if (!request->WaitEvent) {
207 vstorPacket->Operation = VStorOperationBeginInitialization;
208 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
210 /*SpinlockAcquire(gDriverExt.packetListLock);
211 INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry);
212 SpinlockRelease(gDriverExt.packetListLock);*/
214 DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION...");
216 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
218 sizeof(struct vstor_packet),
219 (unsigned long)request,
220 VmbusPacketTypeDataInBand,
221 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
224 "unable to send BEGIN_INITIALIZATION_OPERATION");
228 osd_WaitEventWait(request->WaitEvent);
230 if (vstorPacket->Operation != VStorOperationCompleteIo ||
231 vstorPacket->Status != 0) {
232 DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed "
233 "(op %d status 0x%x)",
234 vstorPacket->Operation, vstorPacket->Status);
238 DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION...");
240 /* reuse the packet for version range supported */
241 memset(vstorPacket, 0, sizeof(struct vstor_packet));
242 vstorPacket->Operation = VStorOperationQueryProtocolVersion;
243 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
245 vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT;
246 FILL_VMSTOR_REVISION(vstorPacket->Version.Revision);
248 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
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_WaitEventWait(request->WaitEvent);
262 /* TODO: Check returned version */
263 if (vstorPacket->Operation != VStorOperationCompleteIo ||
264 vstorPacket->Status != 0) {
265 DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed "
266 "(op %d status 0x%x)",
267 vstorPacket->Operation, vstorPacket->Status);
271 /* Query channel properties */
272 DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION...");
274 memset(vstorPacket, 0, sizeof(struct vstor_packet));
275 vstorPacket->Operation = VStorOperationQueryProperties;
276 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
277 vstorPacket->StorageChannelProperties.PortNumber =
278 storDevice->PortNumber;
280 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
282 sizeof(struct vstor_packet),
283 (unsigned long)request,
284 VmbusPacketTypeDataInBand,
285 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
289 "unable to send QUERY_PROPERTIES_OPERATION");
293 osd_WaitEventWait(request->WaitEvent);
295 /* TODO: Check returned version */
296 if (vstorPacket->Operation != VStorOperationCompleteIo ||
297 vstorPacket->Status != 0) {
298 DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed "
299 "(op %d status 0x%x)",
300 vstorPacket->Operation, vstorPacket->Status);
304 storDevice->PathId = vstorPacket->StorageChannelProperties.PathId;
305 storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId;
307 DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x",
308 vstorPacket->StorageChannelProperties.Flags,
309 vstorPacket->StorageChannelProperties.MaxTransferBytes);
311 DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION...");
313 memset(vstorPacket, 0, sizeof(struct vstor_packet));
314 vstorPacket->Operation = VStorOperationEndInitialization;
315 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
317 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
319 sizeof(struct vstor_packet),
320 (unsigned long)request,
321 VmbusPacketTypeDataInBand,
322 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
326 "unable to send END_INITIALIZATION_OPERATION");
330 osd_WaitEventWait(request->WaitEvent);
332 if (vstorPacket->Operation != VStorOperationCompleteIo ||
333 vstorPacket->Status != 0) {
334 DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed "
335 "(op %d status 0x%x)",
336 vstorPacket->Operation, vstorPacket->Status);
340 DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****");
343 kfree(request->WaitEvent);
344 request->WaitEvent = NULL;
346 PutStorDevice(Device);
350 static void StorVscOnIOCompletion(struct hv_device *Device,
351 struct vstor_packet *VStorPacket,
352 struct storvsc_request_extension *RequestExt)
354 struct hv_storvsc_request *request;
355 struct storvsc_device *storDevice;
357 storDevice = MustGetStorDevice(Device);
359 DPRINT_ERR(STORVSC, "unable to get stor device..."
360 "device being destroyed?");
364 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p "
365 "completed bytes xfer %u", RequestExt,
366 VStorPacket->VmSrb.DataTransferLength);
368 /* ASSERT(RequestExt != NULL); */
369 /* ASSERT(RequestExt->Request != NULL); */
371 request = RequestExt->Request;
373 /* ASSERT(request->OnIOCompletion != NULL); */
375 /* Copy over the status...etc */
376 request->Status = VStorPacket->VmSrb.ScsiStatus;
378 if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1) {
380 "cmd 0x%x scsi status 0x%x srb status 0x%x\n",
381 request->Cdb[0], VStorPacket->VmSrb.ScsiStatus,
382 VStorPacket->VmSrb.SrbStatus);
385 if ((request->Status & 0xFF) == 0x02) {
386 /* CHECK_CONDITION */
387 if (VStorPacket->VmSrb.SrbStatus & 0x80) {
388 /* autosense data available */
389 DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data "
390 "valid - len %d\n", RequestExt,
391 VStorPacket->VmSrb.SenseInfoLength);
393 /* ASSERT(VStorPacket->VmSrb.SenseInfoLength <= */
394 /* request->SenseBufferSize); */
395 memcpy(request->SenseBuffer,
396 VStorPacket->VmSrb.SenseData,
397 VStorPacket->VmSrb.SenseInfoLength);
399 request->SenseBufferSize =
400 VStorPacket->VmSrb.SenseInfoLength;
405 request->BytesXfer = VStorPacket->VmSrb.DataTransferLength;
407 request->OnIOCompletion(request);
409 atomic_dec(&storDevice->NumOutstandingRequests);
411 PutStorDevice(Device);
414 static void StorVscOnReceive(struct hv_device *Device,
415 struct vstor_packet *VStorPacket,
416 struct storvsc_request_extension *RequestExt)
418 switch (VStorPacket->Operation) {
419 case VStorOperationCompleteIo:
420 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION");
421 StorVscOnIOCompletion(Device, VStorPacket, RequestExt);
423 case VStorOperationRemoveDevice:
424 DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION");
429 DPRINT_INFO(STORVSC, "Unknown operation received - %d",
430 VStorPacket->Operation);
435 static void StorVscOnChannelCallback(void *context)
437 struct hv_device *device = (struct hv_device *)context;
438 struct storvsc_device *storDevice;
441 unsigned char packet[ALIGN_UP(sizeof(struct vstor_packet), 8)];
442 struct storvsc_request_extension *request;
445 /* ASSERT(device); */
447 storDevice = MustGetStorDevice(device);
449 DPRINT_ERR(STORVSC, "unable to get stor device..."
450 "device being destroyed?");
455 ret = vmbus_recvpacket(device->channel, packet,
456 ALIGN_UP(sizeof(struct vstor_packet), 8),
457 &bytesRecvd, &requestId);
458 if (ret == 0 && bytesRecvd > 0) {
459 DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx",
460 bytesRecvd, requestId);
462 /* ASSERT(bytesRecvd == sizeof(struct vstor_packet)); */
464 request = (struct storvsc_request_extension *)
465 (unsigned long)requestId;
466 /* ASSERT(request);c */
468 /* if (vstorPacket.Flags & SYNTHETIC_FLAG) */
469 if ((request == &storDevice->InitRequest) ||
470 (request == &storDevice->ResetRequest)) {
471 /* DPRINT_INFO(STORVSC,
472 * "reset completion - operation "
474 * vstorPacket.Operation,
475 * vstorPacket.Status); */
477 memcpy(&request->VStorPacket, packet,
478 sizeof(struct vstor_packet));
480 osd_WaitEventSet(request->WaitEvent);
482 StorVscOnReceive(device,
483 (struct vstor_packet *)packet,
487 /* DPRINT_DBG(STORVSC, "nothing else to read..."); */
492 PutStorDevice(device);
496 static int StorVscConnectToVsp(struct hv_device *Device)
498 struct vmstorage_channel_properties props;
499 struct storvsc_driver_object *storDriver;
502 storDriver = (struct storvsc_driver_object *)Device->Driver;
503 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
505 /* Open the channel */
506 ret = Device->Driver->VmbusChannelInterface.Open(Device,
507 storDriver->RingBufferSize,
508 storDriver->RingBufferSize,
510 sizeof(struct vmstorage_channel_properties),
511 StorVscOnChannelCallback,
514 DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d",
515 props.PathId, props.TargetId, props.MaxTransferBytes);
518 DPRINT_ERR(STORVSC, "unable to open channel: %d", ret);
522 ret = StorVscChannelInit(Device);
528 * StorVscOnDeviceAdd - Callback when the device belonging to this driver is added
530 static int StorVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
532 struct storvsc_device *storDevice;
533 /* struct vmstorage_channel_properties *props; */
534 struct storvsc_device_info *deviceInfo;
537 deviceInfo = (struct storvsc_device_info *)AdditionalInfo;
538 storDevice = AllocStorDevice(Device);
544 /* Save the channel properties to our storvsc channel */
545 /* props = (struct vmstorage_channel_properties *)
546 * channel->offerMsg.Offer.u.Standard.UserDefined; */
550 * If we support more than 1 scsi channel, we need to set the
551 * port number here to the scsi channel but how do we get the
552 * scsi channel prior to the bus scan
555 /* storChannel->PortNumber = 0;
556 storChannel->PathId = props->PathId;
557 storChannel->TargetId = props->TargetId; */
559 storDevice->PortNumber = deviceInfo->PortNumber;
560 /* Send it back up */
561 ret = StorVscConnectToVsp(Device);
563 /* deviceInfo->PortNumber = storDevice->PortNumber; */
564 deviceInfo->PathId = storDevice->PathId;
565 deviceInfo->TargetId = storDevice->TargetId;
567 DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n",
568 storDevice->PortNumber, storDevice->PathId,
569 storDevice->TargetId);
576 * StorVscOnDeviceRemove - Callback when the our device is being removed
578 static int StorVscOnDeviceRemove(struct hv_device *Device)
580 struct storvsc_device *storDevice;
582 DPRINT_INFO(STORVSC, "disabling storage device (%p)...",
585 storDevice = ReleaseStorDevice(Device);
588 * At this point, all outbound traffic should be disable. We
589 * only allow inbound traffic (responses) to proceed so that
590 * outstanding requests can be completed.
592 while (atomic_read(&storDevice->NumOutstandingRequests)) {
593 DPRINT_INFO(STORVSC, "waiting for %d requests to complete...",
594 atomic_read(&storDevice->NumOutstandingRequests));
598 DPRINT_INFO(STORVSC, "removing storage device (%p)...",
601 storDevice = FinalReleaseStorDevice(Device);
603 DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", storDevice);
605 /* Close the channel */
606 Device->Driver->VmbusChannelInterface.Close(Device);
608 FreeStorDevice(storDevice);
612 int StorVscOnHostReset(struct hv_device *Device)
614 struct storvsc_device *storDevice;
615 struct storvsc_request_extension *request;
616 struct vstor_packet *vstorPacket;
619 DPRINT_INFO(STORVSC, "resetting host adapter...");
621 storDevice = GetStorDevice(Device);
623 DPRINT_ERR(STORVSC, "unable to get stor device..."
624 "device being destroyed?");
628 request = &storDevice->ResetRequest;
629 vstorPacket = &request->VStorPacket;
631 request->WaitEvent = osd_WaitEventCreate();
632 if (!request->WaitEvent) {
637 vstorPacket->Operation = VStorOperationResetBus;
638 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
639 vstorPacket->VmSrb.PathId = storDevice->PathId;
641 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
643 sizeof(struct vstor_packet),
644 (unsigned long)&storDevice->ResetRequest,
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_WaitEventWait(request->WaitEvent);
656 kfree(request->WaitEvent);
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 PutStorDevice(Device);
670 * StorVscOnIORequest - Callback to initiate an I/O request
672 static int StorVscOnIORequest(struct hv_device *Device,
673 struct hv_storvsc_request *Request)
675 struct storvsc_device *storDevice;
676 struct storvsc_request_extension *requestExtension;
677 struct vstor_packet *vstorPacket;
681 (struct storvsc_request_extension *)Request->Extension;
682 vstorPacket = &requestExtension->VStorPacket;
683 storDevice = GetStorDevice(Device);
685 DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, "
686 "Extension %p", Device, storDevice, Request,
689 DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d",
690 Request, Request->DataBuffer.Length, Request->Bus,
691 Request->TargetId, Request->LunId, Request->CdbLen);
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 requestExtension->Request = Request;
703 requestExtension->Device = Device;
705 memset(vstorPacket, 0 , sizeof(struct vstor_packet));
707 vstorPacket->Flags |= REQUEST_COMPLETION_FLAG;
709 vstorPacket->VmSrb.Length = sizeof(struct vmscsi_request);
711 vstorPacket->VmSrb.PortNumber = Request->Host;
712 vstorPacket->VmSrb.PathId = Request->Bus;
713 vstorPacket->VmSrb.TargetId = Request->TargetId;
714 vstorPacket->VmSrb.Lun = Request->LunId;
716 vstorPacket->VmSrb.SenseInfoLength = SENSE_BUFFER_SIZE;
718 /* Copy over the scsi command descriptor block */
719 vstorPacket->VmSrb.CdbLength = Request->CdbLen;
720 memcpy(&vstorPacket->VmSrb.Cdb, Request->Cdb, Request->CdbLen);
722 vstorPacket->VmSrb.DataIn = Request->Type;
723 vstorPacket->VmSrb.DataTransferLength = Request->DataBuffer.Length;
725 vstorPacket->Operation = VStorOperationExecuteSRB;
727 DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, "
728 "lun %d senselen %d cdblen %d",
729 vstorPacket->VmSrb.Length,
730 vstorPacket->VmSrb.PortNumber,
731 vstorPacket->VmSrb.PathId,
732 vstorPacket->VmSrb.TargetId,
733 vstorPacket->VmSrb.Lun,
734 vstorPacket->VmSrb.SenseInfoLength,
735 vstorPacket->VmSrb.CdbLength);
737 if (requestExtension->Request->DataBuffer.Length) {
738 ret = Device->Driver->VmbusChannelInterface.
739 SendPacketMultiPageBuffer(Device,
740 &requestExtension->Request->DataBuffer,
742 sizeof(struct vstor_packet),
743 (unsigned long)requestExtension);
745 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
747 sizeof(struct vstor_packet),
748 (unsigned long)requestExtension,
749 VmbusPacketTypeDataInBand,
750 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
754 DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d",
758 atomic_inc(&storDevice->NumOutstandingRequests);
760 PutStorDevice(Device);
765 * StorVscOnCleanup - Perform any cleanup when the driver is removed
767 static void StorVscOnCleanup(struct hv_driver *Driver)
772 * StorVscInitialize - Main entry point
774 int StorVscInitialize(struct hv_driver *Driver)
776 struct storvsc_driver_object *storDriver;
778 storDriver = (struct storvsc_driver_object *)Driver;
780 DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd "
781 "sizeof(struct storvsc_request_extension)=%zd "
782 "sizeof(struct vstor_packet)=%zd, "
783 "sizeof(struct vmscsi_request)=%zd",
784 sizeof(struct hv_storvsc_request),
785 sizeof(struct storvsc_request_extension),
786 sizeof(struct vstor_packet),
787 sizeof(struct vmscsi_request));
789 /* Make sure we are at least 2 pages since 1 page is used for control */
790 /* ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1)); */
792 Driver->name = gDriverName;
793 memcpy(&Driver->deviceType, &gStorVscDeviceType,
794 sizeof(struct hv_guid));
796 storDriver->RequestExtSize = sizeof(struct storvsc_request_extension);
799 * Divide the ring buffer data size (which is 1 page less
800 * than the ring buffer size since that page is reserved for
801 * the ring buffer indices) by the max request size (which is
802 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
804 storDriver->MaxOutstandingRequestsPerChannel =
805 ((storDriver->RingBufferSize - PAGE_SIZE) /
806 ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET +
807 sizeof(struct vstor_packet) + sizeof(u64),
810 DPRINT_INFO(STORVSC, "max io %u, currently %u\n",
811 storDriver->MaxOutstandingRequestsPerChannel,
812 STORVSC_MAX_IO_REQUESTS);
814 /* Setup the dispatch table */
815 storDriver->Base.OnDeviceAdd = StorVscOnDeviceAdd;
816 storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove;
817 storDriver->Base.OnCleanup = StorVscOnCleanup;
819 storDriver->OnIORequest = StorVscOnIORequest;