3 * Copyright (c) 2009, Microsoft Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307 USA.
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
26 #include <linux/kernel.h>
27 #include "include/logging.h"
29 #include "include/StorVscApi.h"
30 #include "include/VmbusPacketFormat.h"
31 #include "include/vstorage.h"
42 typedef struct _STORVSC_REQUEST_EXTENSION {
43 //LIST_ENTRY ListEntry;
45 STORVSC_REQUEST *Request;
46 DEVICE_OBJECT *Device;
48 // Synchronize the request/response if needed
51 VSTOR_PACKET VStorPacket;
52 } STORVSC_REQUEST_EXTENSION;
55 // A storvsc device is a device object that contains a vmbus channel
56 typedef struct _STORVSC_DEVICE{
57 DEVICE_OBJECT *Device;
59 int RefCount; // 0 indicates the device is being destroyed
61 int NumOutstandingRequests;
63 // Each unique Port/Path/Target represents 1 channel ie scsi controller. In reality, the pathid, targetid is always 0
64 // and the port is set by us
69 //LIST_ENTRY OutstandingRequestList;
70 //HANDLE OutstandingRequestLock;
72 // Used for vsc/vsp channel reset process
73 STORVSC_REQUEST_EXTENSION InitRequest;
75 STORVSC_REQUEST_EXTENSION ResetRequest;
83 static const char* gDriverName="storvsc";
85 //{ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
86 static const GUID gStorVscDeviceType={
87 .Data = {0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f}
95 DEVICE_OBJECT *Device,
100 StorVscOnDeviceRemove(
101 DEVICE_OBJECT *Device
106 DEVICE_OBJECT *Device,
107 STORVSC_REQUEST *Request
112 DEVICE_OBJECT *Device
117 DRIVER_OBJECT *Device
121 StorVscOnChannelCallback(
126 StorVscOnIOCompletion(
127 DEVICE_OBJECT *Device,
128 VSTOR_PACKET *VStorPacket,
129 STORVSC_REQUEST_EXTENSION *RequestExt
134 DEVICE_OBJECT *Device,
135 VSTOR_PACKET *VStorPacket,
136 STORVSC_REQUEST_EXTENSION *RequestExt
141 DEVICE_OBJECT *Device
144 static inline STORVSC_DEVICE* AllocStorDevice(DEVICE_OBJECT *Device)
146 STORVSC_DEVICE *storDevice;
148 storDevice = MemAllocZeroed(sizeof(STORVSC_DEVICE));
152 // Set to 2 to allow both inbound and outbound traffics
153 // (ie GetStorDevice() and MustGetStorDevice()) to proceed.
154 InterlockedCompareExchange(&storDevice->RefCount, 2, 0);
156 storDevice->Device = Device;
157 Device->Extension = storDevice;
162 static inline void FreeStorDevice(STORVSC_DEVICE *Device)
164 ASSERT(Device->RefCount == 0);
168 // Get the stordevice object iff exists and its refcount > 1
169 static inline STORVSC_DEVICE* GetStorDevice(DEVICE_OBJECT *Device)
171 STORVSC_DEVICE *storDevice;
173 storDevice = (STORVSC_DEVICE*)Device->Extension;
174 if (storDevice && storDevice->RefCount > 1)
176 InterlockedIncrement(&storDevice->RefCount);
186 // Get the stordevice object iff exists and its refcount > 0
187 static inline STORVSC_DEVICE* MustGetStorDevice(DEVICE_OBJECT *Device)
189 STORVSC_DEVICE *storDevice;
191 storDevice = (STORVSC_DEVICE*)Device->Extension;
192 if (storDevice && storDevice->RefCount)
194 InterlockedIncrement(&storDevice->RefCount);
204 static inline void PutStorDevice(DEVICE_OBJECT *Device)
206 STORVSC_DEVICE *storDevice;
208 storDevice = (STORVSC_DEVICE*)Device->Extension;
211 InterlockedDecrement(&storDevice->RefCount);
212 ASSERT(storDevice->RefCount);
215 // Drop ref count to 1 to effectively disable GetStorDevice()
216 static inline STORVSC_DEVICE* ReleaseStorDevice(DEVICE_OBJECT *Device)
218 STORVSC_DEVICE *storDevice;
220 storDevice = (STORVSC_DEVICE*)Device->Extension;
223 // Busy wait until the ref drop to 2, then set it to 1
224 while (InterlockedCompareExchange(&storDevice->RefCount, 1, 2) != 2)
232 // Drop ref count to 0. No one can use StorDevice object.
233 static inline STORVSC_DEVICE* FinalReleaseStorDevice(DEVICE_OBJECT *Device)
235 STORVSC_DEVICE *storDevice;
237 storDevice = (STORVSC_DEVICE*)Device->Extension;
240 // Busy wait until the ref drop to 1, then set it to 0
241 while (InterlockedCompareExchange(&storDevice->RefCount, 0, 1) != 1)
246 Device->Extension = NULL;
262 DRIVER_OBJECT *Driver
265 STORVSC_DRIVER_OBJECT* storDriver = (STORVSC_DRIVER_OBJECT*)Driver;
268 DPRINT_ENTER(STORVSC);
270 DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%d sizeof(STORVSC_REQUEST_EXTENSION)=%d sizeof(VSTOR_PACKET)=%d, sizeof(VMSCSI_REQUEST)=%d",
271 sizeof(STORVSC_REQUEST), sizeof(STORVSC_REQUEST_EXTENSION), sizeof(VSTOR_PACKET), sizeof(VMSCSI_REQUEST));
273 // Make sure we are at least 2 pages since 1 page is used for control
274 ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1));
276 Driver->name = gDriverName;
277 memcpy(&Driver->deviceType, &gStorVscDeviceType, sizeof(GUID));
279 storDriver->RequestExtSize = sizeof(STORVSC_REQUEST_EXTENSION);
281 // Divide the ring buffer data size (which is 1 page less than the ring buffer size since that page is reserved for the ring buffer indices)
282 // by the max request size (which is VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + VSTOR_PACKET + UINT64)
283 storDriver->MaxOutstandingRequestsPerChannel =
284 ((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(VSTOR_PACKET) + sizeof(UINT64),sizeof(UINT64)));
286 DPRINT_INFO(STORVSC, "max io %u, currently %u\n", storDriver->MaxOutstandingRequestsPerChannel, STORVSC_MAX_IO_REQUESTS);
288 // Setup the dispatch table
289 storDriver->Base.OnDeviceAdd = StorVscOnDeviceAdd;
290 storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove;
291 storDriver->Base.OnCleanup = StorVscOnCleanup;
293 storDriver->OnIORequest = StorVscOnIORequest;
294 storDriver->OnHostReset = StorVscOnHostReset;
296 DPRINT_EXIT(STORVSC);
307 Callback when the device belonging to this driver is added
312 DEVICE_OBJECT *Device,
317 STORVSC_DEVICE *storDevice;
318 //VMSTORAGE_CHANNEL_PROPERTIES *props;
319 STORVSC_DEVICE_INFO *deviceInfo = (STORVSC_DEVICE_INFO*)AdditionalInfo;
321 DPRINT_ENTER(STORVSC);
323 storDevice = AllocStorDevice(Device);
330 // Save the channel properties to our storvsc channel
331 //props = (VMSTORAGE_CHANNEL_PROPERTIES*) channel->offerMsg.Offer.u.Standard.UserDefined;
334 // If we support more than 1 scsi channel, we need to set the port number here
335 // to the scsi channel but how do we get the scsi channel prior to the bus scan
336 /*storChannel->PortNumber = 0;
337 storChannel->PathId = props->PathId;
338 storChannel->TargetId = props->TargetId;*/
340 storDevice->PortNumber = deviceInfo->PortNumber;
342 ret = StorVscConnectToVsp(Device);
344 //deviceInfo->PortNumber = storDevice->PortNumber;
345 deviceInfo->PathId = storDevice->PathId;
346 deviceInfo->TargetId = storDevice->TargetId;
348 DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n", storDevice->PortNumber, storDevice->PathId, storDevice->TargetId);
351 DPRINT_EXIT(STORVSC);
356 static int StorVscChannelInit(DEVICE_OBJECT *Device)
359 STORVSC_DEVICE *storDevice;
360 STORVSC_REQUEST_EXTENSION *request;
361 VSTOR_PACKET *vstorPacket;
363 storDevice = GetStorDevice(Device);
366 DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
367 DPRINT_EXIT(STORVSC);
371 request = &storDevice->InitRequest;
372 vstorPacket = &request->VStorPacket;
374 // Now, initiate the vsc/vsp initialization protocol on the open channel
376 memset(request, sizeof(STORVSC_REQUEST_EXTENSION), 0);
377 request->WaitEvent = WaitEventCreate();
379 vstorPacket->Operation = VStorOperationBeginInitialization;
380 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
382 /*SpinlockAcquire(gDriverExt.packetListLock);
383 INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry);
384 SpinlockRelease(gDriverExt.packetListLock);*/
386 DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION...");
388 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
390 sizeof(VSTOR_PACKET),
392 VmbusPacketTypeDataInBand,
393 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
396 DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION");
400 WaitEventWait(request->WaitEvent);
402 if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
404 DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
408 DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION...");
410 // reuse the packet for version range supported
411 memset(vstorPacket, sizeof(VSTOR_PACKET), 0);
412 vstorPacket->Operation = VStorOperationQueryProtocolVersion;
413 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
415 vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT;
416 FILL_VMSTOR_REVISION(vstorPacket->Version.Revision);
418 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
420 sizeof(VSTOR_PACKET),
422 VmbusPacketTypeDataInBand,
423 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
426 DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION");
430 WaitEventWait(request->WaitEvent);
432 // TODO: Check returned version
433 if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
435 DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
439 // Query channel properties
440 DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION...");
442 memset(vstorPacket, sizeof(VSTOR_PACKET), 0);
443 vstorPacket->Operation = VStorOperationQueryProperties;
444 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
445 vstorPacket->StorageChannelProperties.PortNumber = storDevice->PortNumber;
447 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
449 sizeof(VSTOR_PACKET),
451 VmbusPacketTypeDataInBand,
452 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
456 DPRINT_ERR(STORVSC, "unable to send QUERY_PROPERTIES_OPERATION");
460 WaitEventWait(request->WaitEvent);
462 // TODO: Check returned version
463 if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
465 DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
469 //storDevice->PortNumber = vstorPacket->StorageChannelProperties.PortNumber;
470 storDevice->PathId = vstorPacket->StorageChannelProperties.PathId;
471 storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId;
473 DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x", vstorPacket->StorageChannelProperties.Flags, vstorPacket->StorageChannelProperties.MaxTransferBytes);
475 DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION...");
477 memset(vstorPacket, sizeof(VSTOR_PACKET), 0);
478 vstorPacket->Operation = VStorOperationEndInitialization;
479 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
481 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
483 sizeof(VSTOR_PACKET),
485 VmbusPacketTypeDataInBand,
486 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
490 DPRINT_ERR(STORVSC, "unable to send END_INITIALIZATION_OPERATION");
494 WaitEventWait(request->WaitEvent);
496 if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
498 DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
502 DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****");
505 if (request->WaitEvent)
507 WaitEventClose(request->WaitEvent);
508 request->WaitEvent = NULL;
511 PutStorDevice(Device);
513 DPRINT_EXIT(STORVSC);
520 DEVICE_OBJECT *Device
524 VMSTORAGE_CHANNEL_PROPERTIES props;
526 STORVSC_DRIVER_OBJECT *storDriver = (STORVSC_DRIVER_OBJECT*) Device->Driver;;
528 memset(&props, sizeof(VMSTORAGE_CHANNEL_PROPERTIES), 0);
531 ret = Device->Driver->VmbusChannelInterface.Open(Device,
532 storDriver->RingBufferSize,
533 storDriver->RingBufferSize,
535 sizeof(VMSTORAGE_CHANNEL_PROPERTIES),
536 StorVscOnChannelCallback,
540 DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", props.PathId, props.TargetId, props.MaxTransferBytes);
544 DPRINT_ERR(STORVSC, "unable to open channel: %d", ret);
548 ret = StorVscChannelInit(Device);
557 StorVscOnDeviceRemove()
560 Callback when the our device is being removed
564 StorVscOnDeviceRemove(
565 DEVICE_OBJECT *Device
568 STORVSC_DEVICE *storDevice;
571 DPRINT_ENTER(STORVSC);
573 DPRINT_INFO(STORVSC, "disabling storage device (%p)...", Device->Extension);
575 storDevice = ReleaseStorDevice(Device);
577 // At this point, all outbound traffic should be disable. We only allow inbound traffic (responses) to proceed
578 // so that outstanding requests can be completed.
579 while (storDevice->NumOutstandingRequests)
581 DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", storDevice->NumOutstandingRequests);
586 DPRINT_INFO(STORVSC, "removing storage device (%p)...", Device->Extension);
588 storDevice = FinalReleaseStorDevice(Device);
590 DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", storDevice);
593 Device->Driver->VmbusChannelInterface.Close(Device);
595 FreeStorDevice(storDevice);
597 DPRINT_EXIT(STORVSC);
603 //StorVscOnTargetRescan(
607 // DEVICE_OBJECT *device=(DEVICE_OBJECT*)Context;
608 // STORVSC_DRIVER_OBJECT *storDriver;
610 // DPRINT_ENTER(STORVSC);
612 // storDriver = (STORVSC_DRIVER_OBJECT*) device->Driver;
613 // storDriver->OnHostRescan(device);
615 // DPRINT_EXIT(STORVSC);
620 DEVICE_OBJECT *Device
625 STORVSC_DEVICE *storDevice;
626 STORVSC_REQUEST_EXTENSION *request;
627 VSTOR_PACKET *vstorPacket;
629 DPRINT_ENTER(STORVSC);
631 DPRINT_INFO(STORVSC, "resetting host adapter...");
633 storDevice = GetStorDevice(Device);
636 DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
637 DPRINT_EXIT(STORVSC);
641 request = &storDevice->ResetRequest;
642 vstorPacket = &request->VStorPacket;
644 request->WaitEvent = WaitEventCreate();
646 vstorPacket->Operation = VStorOperationResetBus;
647 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
648 vstorPacket->VmSrb.PathId = storDevice->PathId;
650 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
652 sizeof(VSTOR_PACKET),
653 (ULONG_PTR)&storDevice->ResetRequest,
654 VmbusPacketTypeDataInBand,
655 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
658 DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", vstorPacket, ret);
662 // FIXME: Add a timeout
663 WaitEventWait(request->WaitEvent);
665 WaitEventClose(request->WaitEvent);
666 DPRINT_INFO(STORVSC, "host adapter reset completed");
668 // At this point, all outstanding requests in the adapter should have been flushed out and return to us
671 PutStorDevice(Device);
672 DPRINT_EXIT(STORVSC);
682 Callback to initiate an I/O request
687 DEVICE_OBJECT *Device,
688 STORVSC_REQUEST *Request
691 STORVSC_DEVICE *storDevice;
692 STORVSC_REQUEST_EXTENSION* requestExtension = (STORVSC_REQUEST_EXTENSION*) Request->Extension;
693 VSTOR_PACKET* vstorPacket =&requestExtension->VStorPacket;
696 DPRINT_ENTER(STORVSC);
698 storDevice = GetStorDevice(Device);
700 DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, Extension %p",
701 Device, storDevice, Request, requestExtension);
703 DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d",
704 Request, Request->DataBuffer.Length, Request->Bus, Request->TargetId, Request->LunId, Request->CdbLen);
708 DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
709 DPRINT_EXIT(STORVSC);
713 //PrintBytes(Request->Cdb, Request->CdbLen);
715 requestExtension->Request = Request;
716 requestExtension->Device = Device;
718 memset(vstorPacket, 0 , sizeof(VSTOR_PACKET));
720 vstorPacket->Flags |= REQUEST_COMPLETION_FLAG;
722 vstorPacket->VmSrb.Length = sizeof(VMSCSI_REQUEST);
724 vstorPacket->VmSrb.PortNumber = Request->Host;
725 vstorPacket->VmSrb.PathId = Request->Bus;
726 vstorPacket->VmSrb.TargetId = Request->TargetId;
727 vstorPacket->VmSrb.Lun = Request->LunId;
729 vstorPacket->VmSrb.SenseInfoLength = SENSE_BUFFER_SIZE;
731 // Copy over the scsi command descriptor block
732 vstorPacket->VmSrb.CdbLength = Request->CdbLen;
733 memcpy(&vstorPacket->VmSrb.Cdb, Request->Cdb, Request->CdbLen);
735 vstorPacket->VmSrb.DataIn = Request->Type;
736 vstorPacket->VmSrb.DataTransferLength = Request->DataBuffer.Length;
738 vstorPacket->Operation = VStorOperationExecuteSRB;
740 DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, lun %d senselen %d cdblen %d",
741 vstorPacket->VmSrb.Length,
742 vstorPacket->VmSrb.PortNumber,
743 vstorPacket->VmSrb.PathId,
744 vstorPacket->VmSrb.TargetId,
745 vstorPacket->VmSrb.Lun,
746 vstorPacket->VmSrb.SenseInfoLength,
747 vstorPacket->VmSrb.CdbLength);
749 if (requestExtension->Request->DataBuffer.Length)
751 ret = Device->Driver->VmbusChannelInterface.SendPacketMultiPageBuffer(Device,
752 &requestExtension->Request->DataBuffer,
754 sizeof(VSTOR_PACKET),
755 (ULONG_PTR)requestExtension);
759 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
761 sizeof(VSTOR_PACKET),
762 (ULONG_PTR)requestExtension,
763 VmbusPacketTypeDataInBand,
764 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
769 DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", vstorPacket, ret);
772 InterlockedIncrement(&storDevice->NumOutstandingRequests);
774 PutStorDevice(Device);
776 DPRINT_EXIT(STORVSC);
786 Perform any cleanup when the driver is removed
791 DRIVER_OBJECT *Driver
794 DPRINT_ENTER(STORVSC);
795 DPRINT_EXIT(STORVSC);
800 StorVscOnIOCompletion(
801 DEVICE_OBJECT *Device,
802 VSTOR_PACKET *VStorPacket,
803 STORVSC_REQUEST_EXTENSION *RequestExt
806 STORVSC_REQUEST *request;
807 STORVSC_DEVICE *storDevice;
809 DPRINT_ENTER(STORVSC);
811 storDevice = MustGetStorDevice(Device);
814 DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
815 DPRINT_EXIT(STORVSC);
819 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p completed bytes xfer %u",
820 RequestExt, VStorPacket->VmSrb.DataTransferLength);
822 ASSERT(RequestExt != NULL);
823 ASSERT(RequestExt->Request != NULL);
825 request = RequestExt->Request;
827 ASSERT(request->OnIOCompletion != NULL);
829 // Copy over the status...etc
830 request->Status = VStorPacket->VmSrb.ScsiStatus;
832 if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1)
834 DPRINT_WARN(STORVSC, "cmd 0x%x scsi status 0x%x srb status 0x%x\n",
836 VStorPacket->VmSrb.ScsiStatus,
837 VStorPacket->VmSrb.SrbStatus);
840 if ((request->Status & 0xFF) == 0x02) // CHECK_CONDITION
842 if (VStorPacket->VmSrb.SrbStatus & 0x80) // autosense data available
844 DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data valid - len %d\n",
845 RequestExt, VStorPacket->VmSrb.SenseInfoLength);
847 ASSERT(VStorPacket->VmSrb.SenseInfoLength <= request->SenseBufferSize);
848 memcpy(request->SenseBuffer,
849 VStorPacket->VmSrb.SenseData,
850 VStorPacket->VmSrb.SenseInfoLength);
852 request->SenseBufferSize = VStorPacket->VmSrb.SenseInfoLength;
857 request->BytesXfer = VStorPacket->VmSrb.DataTransferLength;
859 request->OnIOCompletion(request);
861 InterlockedDecrement(&storDevice->NumOutstandingRequests);
863 PutStorDevice(Device);
865 DPRINT_EXIT(STORVSC);
871 DEVICE_OBJECT *Device,
872 VSTOR_PACKET *VStorPacket,
873 STORVSC_REQUEST_EXTENSION *RequestExt
876 switch(VStorPacket->Operation)
878 case VStorOperationCompleteIo:
880 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION");
881 StorVscOnIOCompletion(Device, VStorPacket, RequestExt);
884 //case ENUMERATE_DEVICE_OPERATION:
886 // DPRINT_INFO(STORVSC, "ENUMERATE_DEVICE_OPERATION");
888 // StorVscOnTargetRescan(Device);
891 case VStorOperationRemoveDevice:
893 DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION");
898 DPRINT_INFO(STORVSC, "Unknown operation received - %d", VStorPacket->Operation);
904 StorVscOnChannelCallback(
909 DEVICE_OBJECT *device = (DEVICE_OBJECT*)Context;
910 STORVSC_DEVICE *storDevice;
913 UCHAR packet[ALIGN_UP(sizeof(VSTOR_PACKET),8)];
914 STORVSC_REQUEST_EXTENSION *request;
916 DPRINT_ENTER(STORVSC);
920 storDevice = MustGetStorDevice(device);
923 DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
924 DPRINT_EXIT(STORVSC);
930 ret = device->Driver->VmbusChannelInterface.RecvPacket(device,
932 ALIGN_UP(sizeof(VSTOR_PACKET),8),
935 if (ret == 0 && bytesRecvd > 0)
937 DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", bytesRecvd, requestId);
939 //ASSERT(bytesRecvd == sizeof(VSTOR_PACKET));
941 request = (STORVSC_REQUEST_EXTENSION*)(ULONG_PTR)requestId;
944 //if (vstorPacket.Flags & SYNTHETIC_FLAG)
945 if ((request == &storDevice->InitRequest) || (request == &storDevice->ResetRequest))
947 //DPRINT_INFO(STORVSC, "reset completion - operation %u status %u", vstorPacket.Operation, vstorPacket.Status);
949 memcpy(&request->VStorPacket, packet, sizeof(VSTOR_PACKET));
951 WaitEventSet(request->WaitEvent);
955 StorVscOnReceive(device, (VSTOR_PACKET*)packet, request);
960 //DPRINT_DBG(STORVSC, "nothing else to read...");
965 PutStorDevice(device);
967 DPRINT_EXIT(STORVSC);