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 "StorVscApi.h"
29 #include "VmbusPacketFormat.h"
33 struct storvsc_request_extension {
34 /* LIST_ENTRY ListEntry; */
36 struct hv_storvsc_request *Request;
37 struct hv_device *Device;
39 /* Synchronize the request/response if needed */
40 struct osd_waitevent *WaitEvent;
42 struct vstor_packet VStorPacket;
45 /* A storvsc device is a device object that contains a vmbus channel */
46 struct storvsc_device {
47 struct hv_device *Device;
49 /* 0 indicates the device is being destroyed */
52 atomic_t NumOutstandingRequests;
55 * Each unique Port/Path/Target represents 1 channel ie scsi
56 * controller. In reality, the pathid, targetid is always 0
57 * and the port is set by us
59 unsigned int PortNumber;
61 unsigned char TargetId;
63 /* LIST_ENTRY OutstandingRequestList; */
64 /* HANDLE OutstandingRequestLock; */
66 /* Used for vsc/vsp channel reset process */
67 struct storvsc_request_extension InitRequest;
68 struct storvsc_request_extension ResetRequest;
72 static const char *gDriverName = "storvsc";
74 /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
75 static const struct hv_guid gStorVscDeviceType = {
77 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
78 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f
83 static inline struct storvsc_device *AllocStorDevice(struct hv_device *Device)
85 struct storvsc_device *storDevice;
87 storDevice = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
91 /* Set to 2 to allow both inbound and outbound traffics */
92 /* (ie GetStorDevice() and MustGetStorDevice()) to proceed. */
93 atomic_cmpxchg(&storDevice->RefCount, 0, 2);
95 storDevice->Device = Device;
96 Device->Extension = storDevice;
101 static inline void FreeStorDevice(struct storvsc_device *Device)
103 ASSERT(atomic_read(&Device->RefCount) == 0);
107 /* Get the stordevice object iff exists and its refcount > 1 */
108 static inline struct storvsc_device *GetStorDevice(struct hv_device *Device)
110 struct storvsc_device *storDevice;
112 storDevice = (struct storvsc_device *)Device->Extension;
113 if (storDevice && atomic_read(&storDevice->RefCount) > 1)
114 atomic_inc(&storDevice->RefCount);
121 /* Get the stordevice object iff exists and its refcount > 0 */
122 static inline struct storvsc_device *MustGetStorDevice(struct hv_device *Device)
124 struct storvsc_device *storDevice;
126 storDevice = (struct storvsc_device *)Device->Extension;
127 if (storDevice && atomic_read(&storDevice->RefCount))
128 atomic_inc(&storDevice->RefCount);
135 static inline void PutStorDevice(struct hv_device *Device)
137 struct storvsc_device *storDevice;
139 storDevice = (struct storvsc_device *)Device->Extension;
142 atomic_dec(&storDevice->RefCount);
143 ASSERT(atomic_read(&storDevice->RefCount));
146 /* Drop ref count to 1 to effectively disable GetStorDevice() */
147 static inline struct storvsc_device *ReleaseStorDevice(struct hv_device *Device)
149 struct storvsc_device *storDevice;
151 storDevice = (struct storvsc_device *)Device->Extension;
154 /* Busy wait until the ref drop to 2, then set it to 1 */
155 while (atomic_cmpxchg(&storDevice->RefCount, 2, 1) != 2)
161 /* Drop ref count to 0. No one can use StorDevice object. */
162 static inline struct storvsc_device *FinalReleaseStorDevice(
163 struct hv_device *Device)
165 struct storvsc_device *storDevice;
167 storDevice = (struct storvsc_device *)Device->Extension;
170 /* Busy wait until the ref drop to 1, then set it to 0 */
171 while (atomic_cmpxchg(&storDevice->RefCount, 1, 0) != 1)
174 Device->Extension = NULL;
178 static int StorVscChannelInit(struct hv_device *Device)
180 struct storvsc_device *storDevice;
181 struct storvsc_request_extension *request;
182 struct vstor_packet *vstorPacket;
185 storDevice = GetStorDevice(Device);
187 DPRINT_ERR(STORVSC, "unable to get stor device..."
188 "device being destroyed?");
189 DPRINT_EXIT(STORVSC);
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();
203 vstorPacket->Operation = VStorOperationBeginInitialization;
204 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
206 /*SpinlockAcquire(gDriverExt.packetListLock);
207 INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry);
208 SpinlockRelease(gDriverExt.packetListLock);*/
210 DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION...");
212 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
214 sizeof(struct vstor_packet),
215 (unsigned long)request,
216 VmbusPacketTypeDataInBand,
217 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
220 "unable to send BEGIN_INITIALIZATION_OPERATION");
224 osd_WaitEventWait(request->WaitEvent);
226 if (vstorPacket->Operation != VStorOperationCompleteIo ||
227 vstorPacket->Status != 0) {
228 DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed "
229 "(op %d status 0x%x)",
230 vstorPacket->Operation, vstorPacket->Status);
234 DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION...");
236 /* reuse the packet for version range supported */
237 memset(vstorPacket, 0, sizeof(struct vstor_packet));
238 vstorPacket->Operation = VStorOperationQueryProtocolVersion;
239 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
241 vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT;
242 FILL_VMSTOR_REVISION(vstorPacket->Version.Revision);
244 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
246 sizeof(struct vstor_packet),
247 (unsigned long)request,
248 VmbusPacketTypeDataInBand,
249 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
252 "unable to send BEGIN_INITIALIZATION_OPERATION");
256 osd_WaitEventWait(request->WaitEvent);
258 /* TODO: Check returned version */
259 if (vstorPacket->Operation != VStorOperationCompleteIo ||
260 vstorPacket->Status != 0) {
261 DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed "
262 "(op %d status 0x%x)",
263 vstorPacket->Operation, vstorPacket->Status);
267 /* Query channel properties */
268 DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION...");
270 memset(vstorPacket, 0, sizeof(struct vstor_packet));
271 vstorPacket->Operation = VStorOperationQueryProperties;
272 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
273 vstorPacket->StorageChannelProperties.PortNumber =
274 storDevice->PortNumber;
276 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
278 sizeof(struct vstor_packet),
279 (unsigned long)request,
280 VmbusPacketTypeDataInBand,
281 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
285 "unable to send QUERY_PROPERTIES_OPERATION");
289 osd_WaitEventWait(request->WaitEvent);
291 /* TODO: Check returned version */
292 if (vstorPacket->Operation != VStorOperationCompleteIo ||
293 vstorPacket->Status != 0) {
294 DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed "
295 "(op %d status 0x%x)",
296 vstorPacket->Operation, vstorPacket->Status);
300 storDevice->PathId = vstorPacket->StorageChannelProperties.PathId;
301 storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId;
303 DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x",
304 vstorPacket->StorageChannelProperties.Flags,
305 vstorPacket->StorageChannelProperties.MaxTransferBytes);
307 DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION...");
309 memset(vstorPacket, 0, sizeof(struct vstor_packet));
310 vstorPacket->Operation = VStorOperationEndInitialization;
311 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
313 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
315 sizeof(struct vstor_packet),
316 (unsigned long)request,
317 VmbusPacketTypeDataInBand,
318 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
322 "unable to send END_INITIALIZATION_OPERATION");
326 osd_WaitEventWait(request->WaitEvent);
328 if (vstorPacket->Operation != VStorOperationCompleteIo ||
329 vstorPacket->Status != 0) {
330 DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed "
331 "(op %d status 0x%x)",
332 vstorPacket->Operation, vstorPacket->Status);
336 DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****");
339 kfree(request->WaitEvent);
340 request->WaitEvent = NULL;
342 PutStorDevice(Device);
344 DPRINT_EXIT(STORVSC);
348 static void StorVscOnIOCompletion(struct hv_device *Device,
349 struct vstor_packet *VStorPacket,
350 struct storvsc_request_extension *RequestExt)
352 struct hv_storvsc_request *request;
353 struct storvsc_device *storDevice;
355 DPRINT_ENTER(STORVSC);
357 storDevice = MustGetStorDevice(Device);
359 DPRINT_ERR(STORVSC, "unable to get stor device..."
360 "device being destroyed?");
361 DPRINT_EXIT(STORVSC);
365 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p "
366 "completed bytes xfer %u", RequestExt,
367 VStorPacket->VmSrb.DataTransferLength);
369 ASSERT(RequestExt != NULL);
370 ASSERT(RequestExt->Request != NULL);
372 request = RequestExt->Request;
374 ASSERT(request->OnIOCompletion != NULL);
376 /* Copy over the status...etc */
377 request->Status = VStorPacket->VmSrb.ScsiStatus;
379 if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1) {
381 "cmd 0x%x scsi status 0x%x srb status 0x%x\n",
382 request->Cdb[0], VStorPacket->VmSrb.ScsiStatus,
383 VStorPacket->VmSrb.SrbStatus);
386 if ((request->Status & 0xFF) == 0x02) {
387 /* CHECK_CONDITION */
388 if (VStorPacket->VmSrb.SrbStatus & 0x80) {
389 /* autosense data available */
390 DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data "
391 "valid - len %d\n", RequestExt,
392 VStorPacket->VmSrb.SenseInfoLength);
394 ASSERT(VStorPacket->VmSrb.SenseInfoLength <=
395 request->SenseBufferSize);
396 memcpy(request->SenseBuffer,
397 VStorPacket->VmSrb.SenseData,
398 VStorPacket->VmSrb.SenseInfoLength);
400 request->SenseBufferSize =
401 VStorPacket->VmSrb.SenseInfoLength;
406 request->BytesXfer = VStorPacket->VmSrb.DataTransferLength;
408 request->OnIOCompletion(request);
410 atomic_dec(&storDevice->NumOutstandingRequests);
412 PutStorDevice(Device);
414 DPRINT_EXIT(STORVSC);
417 static void StorVscOnReceive(struct hv_device *Device,
418 struct vstor_packet *VStorPacket,
419 struct storvsc_request_extension *RequestExt)
421 switch (VStorPacket->Operation) {
422 case VStorOperationCompleteIo:
423 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION");
424 StorVscOnIOCompletion(Device, VStorPacket, RequestExt);
426 case VStorOperationRemoveDevice:
427 DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION");
432 DPRINT_INFO(STORVSC, "Unknown operation received - %d",
433 VStorPacket->Operation);
438 static void StorVscOnChannelCallback(void *context)
440 struct hv_device *device = (struct hv_device *)context;
441 struct storvsc_device *storDevice;
444 unsigned char packet[ALIGN_UP(sizeof(struct vstor_packet), 8)];
445 struct storvsc_request_extension *request;
448 DPRINT_ENTER(STORVSC);
452 storDevice = MustGetStorDevice(device);
454 DPRINT_ERR(STORVSC, "unable to get stor device..."
455 "device being destroyed?");
456 DPRINT_EXIT(STORVSC);
461 ret = device->Driver->VmbusChannelInterface.RecvPacket(device,
463 ALIGN_UP(sizeof(struct vstor_packet), 8),
464 &bytesRecvd, &requestId);
465 if (ret == 0 && bytesRecvd > 0) {
466 DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx",
467 bytesRecvd, requestId);
469 /* ASSERT(bytesRecvd == sizeof(struct vstor_packet)); */
471 request = (struct storvsc_request_extension *)
472 (unsigned long)requestId;
475 /* if (vstorPacket.Flags & SYNTHETIC_FLAG) */
476 if ((request == &storDevice->InitRequest) ||
477 (request == &storDevice->ResetRequest)) {
478 /* DPRINT_INFO(STORVSC,
479 * "reset completion - operation "
481 * vstorPacket.Operation,
482 * vstorPacket.Status); */
484 memcpy(&request->VStorPacket, packet,
485 sizeof(struct vstor_packet));
487 osd_WaitEventSet(request->WaitEvent);
489 StorVscOnReceive(device,
490 (struct vstor_packet *)packet,
494 /* DPRINT_DBG(STORVSC, "nothing else to read..."); */
499 PutStorDevice(device);
501 DPRINT_EXIT(STORVSC);
505 static int StorVscConnectToVsp(struct hv_device *Device)
507 struct vmstorage_channel_properties props;
508 struct storvsc_driver_object *storDriver;
511 storDriver = (struct storvsc_driver_object *)Device->Driver;
512 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
514 /* Open the channel */
515 ret = Device->Driver->VmbusChannelInterface.Open(Device,
516 storDriver->RingBufferSize,
517 storDriver->RingBufferSize,
519 sizeof(struct vmstorage_channel_properties),
520 StorVscOnChannelCallback,
523 DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d",
524 props.PathId, props.TargetId, props.MaxTransferBytes);
527 DPRINT_ERR(STORVSC, "unable to open channel: %d", ret);
531 ret = StorVscChannelInit(Device);
537 * StorVscOnDeviceAdd - Callback when the device belonging to this driver is added
539 static int StorVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
541 struct storvsc_device *storDevice;
542 /* struct vmstorage_channel_properties *props; */
543 struct storvsc_device_info *deviceInfo;
546 DPRINT_ENTER(STORVSC);
548 deviceInfo = (struct storvsc_device_info *)AdditionalInfo;
549 storDevice = AllocStorDevice(Device);
555 /* Save the channel properties to our storvsc channel */
556 /* props = (struct vmstorage_channel_properties *)
557 * channel->offerMsg.Offer.u.Standard.UserDefined; */
561 * If we support more than 1 scsi channel, we need to set the
562 * port number here to the scsi channel but how do we get the
563 * scsi channel prior to the bus scan
566 /* storChannel->PortNumber = 0;
567 storChannel->PathId = props->PathId;
568 storChannel->TargetId = props->TargetId; */
570 storDevice->PortNumber = deviceInfo->PortNumber;
571 /* Send it back up */
572 ret = StorVscConnectToVsp(Device);
574 /* deviceInfo->PortNumber = storDevice->PortNumber; */
575 deviceInfo->PathId = storDevice->PathId;
576 deviceInfo->TargetId = storDevice->TargetId;
578 DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n",
579 storDevice->PortNumber, storDevice->PathId,
580 storDevice->TargetId);
583 DPRINT_EXIT(STORVSC);
589 * StorVscOnDeviceRemove - Callback when the our device is being removed
591 static int StorVscOnDeviceRemove(struct hv_device *Device)
593 struct storvsc_device *storDevice;
595 DPRINT_ENTER(STORVSC);
597 DPRINT_INFO(STORVSC, "disabling storage device (%p)...",
600 storDevice = ReleaseStorDevice(Device);
603 * At this point, all outbound traffic should be disable. We
604 * only allow inbound traffic (responses) to proceed so that
605 * outstanding requests can be completed.
607 while (atomic_read(&storDevice->NumOutstandingRequests)) {
608 DPRINT_INFO(STORVSC, "waiting for %d requests to complete...",
609 atomic_read(&storDevice->NumOutstandingRequests));
613 DPRINT_INFO(STORVSC, "removing storage device (%p)...",
616 storDevice = FinalReleaseStorDevice(Device);
618 DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", storDevice);
620 /* Close the channel */
621 Device->Driver->VmbusChannelInterface.Close(Device);
623 FreeStorDevice(storDevice);
625 DPRINT_EXIT(STORVSC);
629 int StorVscOnHostReset(struct hv_device *Device)
631 struct storvsc_device *storDevice;
632 struct storvsc_request_extension *request;
633 struct vstor_packet *vstorPacket;
636 DPRINT_ENTER(STORVSC);
638 DPRINT_INFO(STORVSC, "resetting host adapter...");
640 storDevice = GetStorDevice(Device);
642 DPRINT_ERR(STORVSC, "unable to get stor device..."
643 "device being destroyed?");
644 DPRINT_EXIT(STORVSC);
648 request = &storDevice->ResetRequest;
649 vstorPacket = &request->VStorPacket;
651 request->WaitEvent = osd_WaitEventCreate();
653 vstorPacket->Operation = VStorOperationResetBus;
654 vstorPacket->Flags = REQUEST_COMPLETION_FLAG;
655 vstorPacket->VmSrb.PathId = storDevice->PathId;
657 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
659 sizeof(struct vstor_packet),
660 (unsigned long)&storDevice->ResetRequest,
661 VmbusPacketTypeDataInBand,
662 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
664 DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d",
669 /* FIXME: Add a timeout */
670 osd_WaitEventWait(request->WaitEvent);
672 kfree(request->WaitEvent);
673 DPRINT_INFO(STORVSC, "host adapter reset completed");
676 * At this point, all outstanding requests in the adapter
677 * should have been flushed out and return to us
681 PutStorDevice(Device);
682 DPRINT_EXIT(STORVSC);
687 * StorVscOnIORequest - Callback to initiate an I/O request
689 static int StorVscOnIORequest(struct hv_device *Device,
690 struct hv_storvsc_request *Request)
692 struct storvsc_device *storDevice;
693 struct storvsc_request_extension *requestExtension;
694 struct vstor_packet *vstorPacket;
697 DPRINT_ENTER(STORVSC);
700 (struct storvsc_request_extension *)Request->Extension;
701 vstorPacket = &requestExtension->VStorPacket;
702 storDevice = GetStorDevice(Device);
704 DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, "
705 "Extension %p", Device, storDevice, Request,
708 DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d",
709 Request, Request->DataBuffer.Length, Request->Bus,
710 Request->TargetId, Request->LunId, Request->CdbLen);
713 DPRINT_ERR(STORVSC, "unable to get stor device..."
714 "device being destroyed?");
715 DPRINT_EXIT(STORVSC);
719 /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, Request->Cdb,
720 * Request->CdbLen); */
722 requestExtension->Request = Request;
723 requestExtension->Device = Device;
725 memset(vstorPacket, 0 , sizeof(struct vstor_packet));
727 vstorPacket->Flags |= REQUEST_COMPLETION_FLAG;
729 vstorPacket->VmSrb.Length = sizeof(struct vmscsi_request);
731 vstorPacket->VmSrb.PortNumber = Request->Host;
732 vstorPacket->VmSrb.PathId = Request->Bus;
733 vstorPacket->VmSrb.TargetId = Request->TargetId;
734 vstorPacket->VmSrb.Lun = Request->LunId;
736 vstorPacket->VmSrb.SenseInfoLength = SENSE_BUFFER_SIZE;
738 /* Copy over the scsi command descriptor block */
739 vstorPacket->VmSrb.CdbLength = Request->CdbLen;
740 memcpy(&vstorPacket->VmSrb.Cdb, Request->Cdb, Request->CdbLen);
742 vstorPacket->VmSrb.DataIn = Request->Type;
743 vstorPacket->VmSrb.DataTransferLength = Request->DataBuffer.Length;
745 vstorPacket->Operation = VStorOperationExecuteSRB;
747 DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, "
748 "lun %d senselen %d cdblen %d",
749 vstorPacket->VmSrb.Length,
750 vstorPacket->VmSrb.PortNumber,
751 vstorPacket->VmSrb.PathId,
752 vstorPacket->VmSrb.TargetId,
753 vstorPacket->VmSrb.Lun,
754 vstorPacket->VmSrb.SenseInfoLength,
755 vstorPacket->VmSrb.CdbLength);
757 if (requestExtension->Request->DataBuffer.Length) {
758 ret = Device->Driver->VmbusChannelInterface.
759 SendPacketMultiPageBuffer(Device,
760 &requestExtension->Request->DataBuffer,
762 sizeof(struct vstor_packet),
763 (unsigned long)requestExtension);
765 ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
767 sizeof(struct vstor_packet),
768 (unsigned long)requestExtension,
769 VmbusPacketTypeDataInBand,
770 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
774 DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d",
778 atomic_inc(&storDevice->NumOutstandingRequests);
780 PutStorDevice(Device);
782 DPRINT_EXIT(STORVSC);
787 * StorVscOnCleanup - Perform any cleanup when the driver is removed
789 static void StorVscOnCleanup(struct hv_driver *Driver)
791 DPRINT_ENTER(STORVSC);
792 DPRINT_EXIT(STORVSC);
796 * StorVscInitialize - Main entry point
798 int StorVscInitialize(struct hv_driver *Driver)
800 struct storvsc_driver_object *storDriver;
802 DPRINT_ENTER(STORVSC);
804 storDriver = (struct storvsc_driver_object *)Driver;
806 DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd "
807 "sizeof(struct storvsc_request_extension)=%zd "
808 "sizeof(struct vstor_packet)=%zd, "
809 "sizeof(struct vmscsi_request)=%zd",
810 sizeof(struct hv_storvsc_request),
811 sizeof(struct storvsc_request_extension),
812 sizeof(struct vstor_packet),
813 sizeof(struct vmscsi_request));
815 /* Make sure we are at least 2 pages since 1 page is used for control */
816 ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1));
818 Driver->name = gDriverName;
819 memcpy(&Driver->deviceType, &gStorVscDeviceType,
820 sizeof(struct hv_guid));
822 storDriver->RequestExtSize = sizeof(struct storvsc_request_extension);
825 * Divide the ring buffer data size (which is 1 page less
826 * than the ring buffer size since that page is reserved for
827 * the ring buffer indices) by the max request size (which is
828 * VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + struct vstor_packet + u64)
830 storDriver->MaxOutstandingRequestsPerChannel =
831 ((storDriver->RingBufferSize - PAGE_SIZE) /
832 ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET +
833 sizeof(struct vstor_packet) + sizeof(u64),
836 DPRINT_INFO(STORVSC, "max io %u, currently %u\n",
837 storDriver->MaxOutstandingRequestsPerChannel,
838 STORVSC_MAX_IO_REQUESTS);
840 /* Setup the dispatch table */
841 storDriver->Base.OnDeviceAdd = StorVscOnDeviceAdd;
842 storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove;
843 storDriver->Base.OnCleanup = StorVscOnCleanup;
845 storDriver->OnIORequest = StorVscOnIORequest;
847 DPRINT_EXIT(STORVSC);