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>
24 #include <linux/kernel.h>
25 #include <linux/string.h>
27 #include <linux/delay.h>
29 #include "include/logging.h"
30 #include "include/StorVscApi.h"
31 #include "include/VmbusPacketFormat.h"
43 typedef struct _STORVSC_REQUEST_EXTENSION {
44 /* LIST_ENTRY ListEntry; */
46 struct hv_storvsc_request *Request;
47 struct hv_device *Device;
49 /* Synchronize the request/response if needed */
50 struct osd_waitevent *WaitEvent;
52 struct vstor_packet VStorPacket;
53 } STORVSC_REQUEST_EXTENSION;
56 /* A storvsc device is a device object that contains a vmbus channel */
57 typedef struct _STORVSC_DEVICE{
58 struct hv_device *Device;
60 atomic_t RefCount; /* 0 indicates the device is being destroyed */
62 atomic_t NumOutstandingRequests;
65 * Each unique Port/Path/Target represents 1 channel ie scsi
66 * controller. In reality, the pathid, targetid is always 0
67 * and the port is set by us
69 unsigned int PortNumber;
71 unsigned char TargetId;
73 /* LIST_ENTRY OutstandingRequestList; */
74 /* HANDLE OutstandingRequestLock; */
76 /* Used for vsc/vsp channel reset process */
77 STORVSC_REQUEST_EXTENSION InitRequest;
79 STORVSC_REQUEST_EXTENSION ResetRequest;
87 static const char* gDriverName="storvsc";
89 /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
90 static const struct hv_guid gStorVscDeviceType = {
92 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
93 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f
98 /* Internal routines */
102 struct hv_device *Device,
107 StorVscOnDeviceRemove(
108 struct hv_device *Device
113 struct hv_device *Device,
114 struct hv_storvsc_request *Request
119 struct hv_device *Device
124 struct hv_driver *Device
128 StorVscOnChannelCallback(
133 StorVscOnIOCompletion(
134 struct hv_device *Device,
135 struct vstor_packet *VStorPacket,
136 STORVSC_REQUEST_EXTENSION *RequestExt
141 struct hv_device *Device,
142 struct vstor_packet *VStorPacket,
143 STORVSC_REQUEST_EXTENSION *RequestExt
148 struct hv_device *Device
151 static inline STORVSC_DEVICE* AllocStorDevice(struct hv_device *Device)
153 STORVSC_DEVICE *storDevice;
155 storDevice = kzalloc(sizeof(STORVSC_DEVICE), GFP_KERNEL);
159 /* Set to 2 to allow both inbound and outbound traffics */
160 /* (ie GetStorDevice() and MustGetStorDevice()) to proceed. */
161 atomic_cmpxchg(&storDevice->RefCount, 0, 2);
163 storDevice->Device = Device;
164 Device->Extension = storDevice;
169 static inline void FreeStorDevice(STORVSC_DEVICE *Device)
171 ASSERT( atomic_read(&Device->RefCount) == 0);
175 /* Get the stordevice object iff exists and its refcount > 1 */
176 static inline STORVSC_DEVICE* GetStorDevice(struct hv_device *Device)
178 STORVSC_DEVICE *storDevice;
180 storDevice = (STORVSC_DEVICE*)Device->Extension;
181 if (storDevice && atomic_read(&storDevice->RefCount) > 1)
182 atomic_inc(&storDevice->RefCount);
189 /* Get the stordevice object iff exists and its refcount > 0 */
190 static inline STORVSC_DEVICE* MustGetStorDevice(struct hv_device *Device)
192 STORVSC_DEVICE *storDevice;
194 storDevice = (STORVSC_DEVICE*)Device->Extension;
195 if (storDevice && atomic_read(&storDevice->RefCount))
196 atomic_inc(&storDevice->RefCount);
203 static inline void PutStorDevice(struct hv_device *Device)
205 STORVSC_DEVICE *storDevice;
207 storDevice = (STORVSC_DEVICE*)Device->Extension;
210 atomic_dec(&storDevice->RefCount);
211 ASSERT(atomic_read(&storDevice->RefCount));
214 /* Drop ref count to 1 to effectively disable GetStorDevice() */
215 static inline STORVSC_DEVICE* ReleaseStorDevice(struct hv_device *Device)
217 STORVSC_DEVICE *storDevice;
219 storDevice = (STORVSC_DEVICE*)Device->Extension;
222 /* Busy wait until the ref drop to 2, then set it to 1 */
223 while (atomic_cmpxchg(&storDevice->RefCount, 2, 1) != 2)
231 /* Drop ref count to 0. No one can use StorDevice object. */
232 static inline STORVSC_DEVICE* FinalReleaseStorDevice(struct hv_device *Device)
234 STORVSC_DEVICE *storDevice;
236 storDevice = (STORVSC_DEVICE*)Device->Extension;
239 /* Busy wait until the ref drop to 1, then set it to 0 */
240 while (atomic_cmpxchg(&storDevice->RefCount, 1, 0) != 1)
245 Device->Extension = NULL;
261 struct hv_driver *Driver
264 struct storvsc_driver_object *storDriver = (struct storvsc_driver_object *)Driver;
267 DPRINT_ENTER(STORVSC);
269 DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd sizeof(STORVSC_REQUEST_EXTENSION)=%zd sizeof(struct vstor_packet)=%zd, sizeof(struct vmscsi_request)=%zd",
270 sizeof(struct hv_storvsc_request), sizeof(STORVSC_REQUEST_EXTENSION), sizeof(struct vstor_packet), sizeof(struct vmscsi_request));
272 /* Make sure we are at least 2 pages since 1 page is used for control */
273 ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1));
275 Driver->name = gDriverName;
276 memcpy(&Driver->deviceType, &gStorVscDeviceType, sizeof(struct hv_guid));
278 storDriver->RequestExtSize = sizeof(STORVSC_REQUEST_EXTENSION);
281 * Divide the ring buffer data size (which is 1 page less
282 * than the ring buffer size since that page is reserved for
283 * the ring buffer indices) by the max request size (which is
284 * VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + struct vstor_packet + u64)
286 storDriver->MaxOutstandingRequestsPerChannel =
287 ((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(struct vstor_packet) + sizeof(u64),sizeof(u64)));
289 DPRINT_INFO(STORVSC, "max io %u, currently %u\n", storDriver->MaxOutstandingRequestsPerChannel, STORVSC_MAX_IO_REQUESTS);
291 /* Setup the dispatch table */
292 storDriver->Base.OnDeviceAdd = StorVscOnDeviceAdd;
293 storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove;
294 storDriver->Base.OnCleanup = StorVscOnCleanup;
296 storDriver->OnIORequest = StorVscOnIORequest;
297 storDriver->OnHostReset = StorVscOnHostReset;
299 DPRINT_EXIT(STORVSC);
310 Callback when the device belonging to this driver is added
315 struct hv_device *Device,
320 STORVSC_DEVICE *storDevice;
321 /* struct vmstorage_channel_properties *props; */
322 struct storvsc_device_info *deviceInfo = (struct storvsc_device_info *)AdditionalInfo;
324 DPRINT_ENTER(STORVSC);
326 storDevice = AllocStorDevice(Device);
333 /* Save the channel properties to our storvsc channel */
334 /* props = (struct vmstorage_channel_properties *) channel->offerMsg.Offer.u.Standard.UserDefined; */
338 * If we support more than 1 scsi channel, we need to set the
339 * port number here to the scsi channel but how do we get the
340 * scsi channel prior to the bus scan
343 /* storChannel->PortNumber = 0;
344 storChannel->PathId = props->PathId;
345 storChannel->TargetId = props->TargetId; */
347 storDevice->PortNumber = deviceInfo->PortNumber;
348 /* Send it back up */
349 ret = StorVscConnectToVsp(Device);
351 /* deviceInfo->PortNumber = storDevice->PortNumber; */
352 deviceInfo->PathId = storDevice->PathId;
353 deviceInfo->TargetId = storDevice->TargetId;
355 DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n", storDevice->PortNumber, storDevice->PathId, storDevice->TargetId);
358 DPRINT_EXIT(STORVSC);
363 static int StorVscChannelInit(struct hv_device *Device)
366 STORVSC_DEVICE *storDevice;
367 STORVSC_REQUEST_EXTENSION *request;
368 struct vstor_packet *vstorPacket;
370 storDevice = GetStorDevice(Device);
373 DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
374 DPRINT_EXIT(STORVSC);
378 request = &storDevice->InitRequest;
379 vstorPacket = &request->VStorPacket;
381 /* Now, initiate the vsc/vsp initialization protocol on the open channel */
383 memset(request, sizeof(STORVSC_REQUEST_EXTENSION), 0);
384 request->WaitEvent = osd_WaitEventCreate();
386 vstorPacket->Operation = VStorOperationBeginInitialization;
387 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
389 /*SpinlockAcquire(gDriverExt.packetListLock);
390 INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry);
391 SpinlockRelease(gDriverExt.packetListLock);*/
393 DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION...");
395 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
397 sizeof(struct vstor_packet),
398 (unsigned long)request,
399 VmbusPacketTypeDataInBand,
400 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
403 DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION");
407 osd_WaitEventWait(request->WaitEvent);
409 if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
411 DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
415 DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION...");
417 /* reuse the packet for version range supported */
418 memset(vstorPacket, sizeof(struct vstor_packet), 0);
419 vstorPacket->Operation = VStorOperationQueryProtocolVersion;
420 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
422 vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT;
423 FILL_VMSTOR_REVISION(vstorPacket->Version.Revision);
425 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
427 sizeof(struct vstor_packet),
428 (unsigned long)request,
429 VmbusPacketTypeDataInBand,
430 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
433 DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION");
437 osd_WaitEventWait(request->WaitEvent);
439 /* TODO: Check returned version */
440 if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
442 DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
446 /* Query channel properties */
447 DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION...");
449 memset(vstorPacket, sizeof(struct vstor_packet), 0);
450 vstorPacket->Operation = VStorOperationQueryProperties;
451 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
452 vstorPacket->StorageChannelProperties.PortNumber = storDevice->PortNumber;
454 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
456 sizeof(struct vstor_packet),
457 (unsigned long)request,
458 VmbusPacketTypeDataInBand,
459 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
463 DPRINT_ERR(STORVSC, "unable to send QUERY_PROPERTIES_OPERATION");
467 osd_WaitEventWait(request->WaitEvent);
469 /* TODO: Check returned version */
470 if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
472 DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
476 /* storDevice->PortNumber = vstorPacket->StorageChannelProperties.PortNumber; */
477 storDevice->PathId = vstorPacket->StorageChannelProperties.PathId;
478 storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId;
480 DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x", vstorPacket->StorageChannelProperties.Flags, vstorPacket->StorageChannelProperties.MaxTransferBytes);
482 DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION...");
484 memset(vstorPacket, sizeof(struct vstor_packet), 0);
485 vstorPacket->Operation = VStorOperationEndInitialization;
486 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
488 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
490 sizeof(struct vstor_packet),
491 (unsigned long)request,
492 VmbusPacketTypeDataInBand,
493 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
497 DPRINT_ERR(STORVSC, "unable to send END_INITIALIZATION_OPERATION");
501 osd_WaitEventWait(request->WaitEvent);
503 if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0)
505 DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status);
509 DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****");
512 if (request->WaitEvent)
514 kfree(request->WaitEvent);
515 request->WaitEvent = NULL;
518 PutStorDevice(Device);
520 DPRINT_EXIT(STORVSC);
527 struct hv_device *Device
531 struct vmstorage_channel_properties props;
533 struct storvsc_driver_object *storDriver = (struct storvsc_driver_object *)Device->Driver;;
535 memset(&props, sizeof(struct vmstorage_channel_properties), 0);
537 /* Open the channel */
538 ret = Device->Driver->VmbusChannelInterface.Open(Device,
539 storDriver->RingBufferSize,
540 storDriver->RingBufferSize,
542 sizeof(struct vmstorage_channel_properties),
543 StorVscOnChannelCallback,
547 DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", props.PathId, props.TargetId, props.MaxTransferBytes);
551 DPRINT_ERR(STORVSC, "unable to open channel: %d", ret);
555 ret = StorVscChannelInit(Device);
564 StorVscOnDeviceRemove()
567 Callback when the our device is being removed
571 StorVscOnDeviceRemove(
572 struct hv_device *Device
575 STORVSC_DEVICE *storDevice;
578 DPRINT_ENTER(STORVSC);
580 DPRINT_INFO(STORVSC, "disabling storage device (%p)...", Device->Extension);
582 storDevice = ReleaseStorDevice(Device);
585 * At this point, all outbound traffic should be disable. We
586 * only allow inbound traffic (responses) to proceed so that
587 * outstanding requests can be completed.
589 while (atomic_read(&storDevice->NumOutstandingRequests))
591 DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", atomic_read(&storDevice->NumOutstandingRequests));
596 DPRINT_INFO(STORVSC, "removing storage device (%p)...", Device->Extension);
598 storDevice = FinalReleaseStorDevice(Device);
600 DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", storDevice);
602 /* Close the channel */
603 Device->Driver->VmbusChannelInterface.Close(Device);
605 FreeStorDevice(storDevice);
607 DPRINT_EXIT(STORVSC);
613 StorVscOnTargetRescan(
617 struct hv_device *device=(struct hv_device *)Context;
618 struct storvsc_driver_object *storDriver;
620 DPRINT_ENTER(STORVSC);
622 storDriver = (struct storvsc_driver_object*) device->Driver;
623 storDriver->OnHostRescan(device);
625 DPRINT_EXIT(STORVSC);
631 struct hv_device *Device
636 STORVSC_DEVICE *storDevice;
637 STORVSC_REQUEST_EXTENSION *request;
638 struct vstor_packet *vstorPacket;
640 DPRINT_ENTER(STORVSC);
642 DPRINT_INFO(STORVSC, "resetting host adapter...");
644 storDevice = GetStorDevice(Device);
647 DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
648 DPRINT_EXIT(STORVSC);
652 request = &storDevice->ResetRequest;
653 vstorPacket = &request->VStorPacket;
655 request->WaitEvent = osd_WaitEventCreate();
657 vstorPacket->Operation = VStorOperationResetBus;
658 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
659 vstorPacket->VmSrb.PathId = storDevice->PathId;
661 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
663 sizeof(struct vstor_packet),
664 (unsigned long)&storDevice->ResetRequest,
665 VmbusPacketTypeDataInBand,
666 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
669 DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", vstorPacket, ret);
673 /* FIXME: Add a timeout */
674 osd_WaitEventWait(request->WaitEvent);
676 kfree(request->WaitEvent);
677 DPRINT_INFO(STORVSC, "host adapter reset completed");
680 * At this point, all outstanding requests in the adapter
681 * should have been flushed out and return to us
685 PutStorDevice(Device);
686 DPRINT_EXIT(STORVSC);
696 Callback to initiate an I/O request
701 struct hv_device *Device,
702 struct hv_storvsc_request *Request
705 STORVSC_DEVICE *storDevice;
706 STORVSC_REQUEST_EXTENSION* requestExtension = (STORVSC_REQUEST_EXTENSION*) Request->Extension;
707 struct vstor_packet *vstorPacket =&requestExtension->VStorPacket;
710 DPRINT_ENTER(STORVSC);
712 storDevice = GetStorDevice(Device);
714 DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, Extension %p",
715 Device, storDevice, Request, requestExtension);
717 DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d",
718 Request, Request->DataBuffer.Length, Request->Bus, Request->TargetId, Request->LunId, Request->CdbLen);
722 DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
723 DPRINT_EXIT(STORVSC);
727 /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, Request->Cdb, Request->CdbLen); */
729 requestExtension->Request = Request;
730 requestExtension->Device = Device;
732 memset(vstorPacket, 0 , sizeof(struct vstor_packet));
734 vstorPacket->Flags |= REQUEST_COMPLETION_FLAG;
736 vstorPacket->VmSrb.Length = sizeof(struct vmscsi_request);
738 vstorPacket->VmSrb.PortNumber = Request->Host;
739 vstorPacket->VmSrb.PathId = Request->Bus;
740 vstorPacket->VmSrb.TargetId = Request->TargetId;
741 vstorPacket->VmSrb.Lun = Request->LunId;
743 vstorPacket->VmSrb.SenseInfoLength = SENSE_BUFFER_SIZE;
745 /* Copy over the scsi command descriptor block */
746 vstorPacket->VmSrb.CdbLength = Request->CdbLen;
747 memcpy(&vstorPacket->VmSrb.Cdb, Request->Cdb, Request->CdbLen);
749 vstorPacket->VmSrb.DataIn = Request->Type;
750 vstorPacket->VmSrb.DataTransferLength = Request->DataBuffer.Length;
752 vstorPacket->Operation = VStorOperationExecuteSRB;
754 DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, lun %d senselen %d cdblen %d",
755 vstorPacket->VmSrb.Length,
756 vstorPacket->VmSrb.PortNumber,
757 vstorPacket->VmSrb.PathId,
758 vstorPacket->VmSrb.TargetId,
759 vstorPacket->VmSrb.Lun,
760 vstorPacket->VmSrb.SenseInfoLength,
761 vstorPacket->VmSrb.CdbLength);
763 if (requestExtension->Request->DataBuffer.Length)
765 ret = Device->Driver->VmbusChannelInterface.SendPacketMultiPageBuffer(Device,
766 &requestExtension->Request->DataBuffer,
768 sizeof(struct vstor_packet),
769 (unsigned long)requestExtension);
773 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
775 sizeof(struct vstor_packet),
776 (unsigned long)requestExtension,
777 VmbusPacketTypeDataInBand,
778 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
783 DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", vstorPacket, ret);
786 atomic_inc(&storDevice->NumOutstandingRequests);
788 PutStorDevice(Device);
790 DPRINT_EXIT(STORVSC);
800 Perform any cleanup when the driver is removed
805 struct hv_driver *Driver
808 DPRINT_ENTER(STORVSC);
809 DPRINT_EXIT(STORVSC);
814 StorVscOnIOCompletion(
815 struct hv_device *Device,
816 struct vstor_packet *VStorPacket,
817 STORVSC_REQUEST_EXTENSION *RequestExt
820 struct hv_storvsc_request *request;
821 STORVSC_DEVICE *storDevice;
823 DPRINT_ENTER(STORVSC);
825 storDevice = MustGetStorDevice(Device);
828 DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
829 DPRINT_EXIT(STORVSC);
833 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p completed bytes xfer %u",
834 RequestExt, VStorPacket->VmSrb.DataTransferLength);
836 ASSERT(RequestExt != NULL);
837 ASSERT(RequestExt->Request != NULL);
839 request = RequestExt->Request;
841 ASSERT(request->OnIOCompletion != NULL);
843 /* Copy over the status...etc */
844 request->Status = VStorPacket->VmSrb.ScsiStatus;
846 if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1)
848 DPRINT_WARN(STORVSC, "cmd 0x%x scsi status 0x%x srb status 0x%x\n",
850 VStorPacket->VmSrb.ScsiStatus,
851 VStorPacket->VmSrb.SrbStatus);
854 if ((request->Status & 0xFF) == 0x02) /* CHECK_CONDITION */
856 if (VStorPacket->VmSrb.SrbStatus & 0x80) /* autosense data available */
858 DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data valid - len %d\n",
859 RequestExt, VStorPacket->VmSrb.SenseInfoLength);
861 ASSERT(VStorPacket->VmSrb.SenseInfoLength <= request->SenseBufferSize);
862 memcpy(request->SenseBuffer,
863 VStorPacket->VmSrb.SenseData,
864 VStorPacket->VmSrb.SenseInfoLength);
866 request->SenseBufferSize = VStorPacket->VmSrb.SenseInfoLength;
871 request->BytesXfer = VStorPacket->VmSrb.DataTransferLength;
873 request->OnIOCompletion(request);
875 atomic_dec(&storDevice->NumOutstandingRequests);
877 PutStorDevice(Device);
879 DPRINT_EXIT(STORVSC);
885 struct hv_device *Device,
886 struct vstor_packet *VStorPacket,
887 STORVSC_REQUEST_EXTENSION *RequestExt
890 switch(VStorPacket->Operation)
892 case VStorOperationCompleteIo:
894 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION");
895 StorVscOnIOCompletion(Device, VStorPacket, RequestExt);
898 /* case ENUMERATE_DEVICE_OPERATION: */
900 /* DPRINT_INFO(STORVSC, "ENUMERATE_DEVICE_OPERATION"); */
902 /* StorVscOnTargetRescan(Device); */
905 case VStorOperationRemoveDevice:
907 DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION");
912 DPRINT_INFO(STORVSC, "Unknown operation received - %d", VStorPacket->Operation);
918 StorVscOnChannelCallback(
923 struct hv_device *device = (struct hv_device*)Context;
924 STORVSC_DEVICE *storDevice;
927 unsigned char packet[ALIGN_UP(sizeof(struct vstor_packet),8)];
928 STORVSC_REQUEST_EXTENSION *request;
930 DPRINT_ENTER(STORVSC);
934 storDevice = MustGetStorDevice(device);
937 DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?");
938 DPRINT_EXIT(STORVSC);
944 ret = device->Driver->VmbusChannelInterface.RecvPacket(device,
946 ALIGN_UP(sizeof(struct vstor_packet),8),
949 if (ret == 0 && bytesRecvd > 0)
951 DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", bytesRecvd, requestId);
953 /* ASSERT(bytesRecvd == sizeof(struct vstor_packet)); */
955 request = (STORVSC_REQUEST_EXTENSION*)(unsigned long)requestId;
958 /* if (vstorPacket.Flags & SYNTHETIC_FLAG) */
959 if ((request == &storDevice->InitRequest) || (request == &storDevice->ResetRequest))
961 /* DPRINT_INFO(STORVSC, "reset completion - operation %u status %u", vstorPacket.Operation, vstorPacket.Status); */
963 memcpy(&request->VStorPacket, packet, sizeof(struct vstor_packet));
965 osd_WaitEventSet(request->WaitEvent);
969 StorVscOnReceive(device, (struct vstor_packet *)packet, request);
974 /* DPRINT_DBG(STORVSC, "nothing else to read..."); */
979 PutStorDevice(device);
981 DPRINT_EXIT(STORVSC);