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/sched.h>
23 #include <linux/wait.h>
24 #include <linux/string.h>
25 #include <linux/slab.h>
27 #include <linux/delay.h>
30 #include "storvsc_api.h"
31 #include "vmbus_packet_format.h"
36 struct storvsc_request_extension
{
37 /* LIST_ENTRY ListEntry; */
39 struct hv_storvsc_request
*request
;
40 struct hv_device
*device
;
42 /* Synchronize the request/response if needed */
44 wait_queue_head_t wait_event
;
46 struct vstor_packet vstor_packet
;
49 /* A storvsc device is a device object that contains a vmbus channel */
50 struct storvsc_device
{
51 struct hv_device
*device
;
53 /* 0 indicates the device is being destroyed */
56 atomic_t num_outstanding_req
;
59 * Each unique Port/Path/Target represents 1 channel ie scsi
60 * controller. In reality, the pathid, targetid is always 0
61 * and the port is set by us
63 unsigned int port_number
;
64 unsigned char path_id
;
65 unsigned char target_id
;
67 /* LIST_ENTRY OutstandingRequestList; */
68 /* HANDLE OutstandingRequestLock; */
70 /* Used for vsc/vsp channel reset process */
71 struct storvsc_request_extension init_request
;
72 struct storvsc_request_extension reset_request
;
76 static const char *g_driver_name
= "storvsc";
78 /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
79 static const struct hv_guid gStorVscDeviceType
= {
81 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
82 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f
87 static inline struct storvsc_device
*alloc_stor_device(struct hv_device
*device
)
89 struct storvsc_device
*stor_device
;
91 stor_device
= kzalloc(sizeof(struct storvsc_device
), GFP_KERNEL
);
95 /* Set to 2 to allow both inbound and outbound traffics */
96 /* (ie get_stor_device() and must_get_stor_device()) to proceed. */
97 atomic_cmpxchg(&stor_device
->ref_count
, 0, 2);
99 stor_device
->device
= device
;
100 device
->ext
= stor_device
;
105 static inline void free_stor_device(struct storvsc_device
*device
)
107 /* ASSERT(atomic_read(&device->ref_count) == 0); */
111 /* Get the stordevice object iff exists and its refcount > 1 */
112 static inline struct storvsc_device
*get_stor_device(struct hv_device
*device
)
114 struct storvsc_device
*stor_device
;
116 stor_device
= (struct storvsc_device
*)device
->ext
;
117 if (stor_device
&& atomic_read(&stor_device
->ref_count
) > 1)
118 atomic_inc(&stor_device
->ref_count
);
125 /* Get the stordevice object iff exists and its refcount > 0 */
126 static inline struct storvsc_device
*must_get_stor_device(
127 struct hv_device
*device
)
129 struct storvsc_device
*stor_device
;
131 stor_device
= (struct storvsc_device
*)device
->ext
;
132 if (stor_device
&& atomic_read(&stor_device
->ref_count
))
133 atomic_inc(&stor_device
->ref_count
);
140 static inline void put_stor_device(struct hv_device
*device
)
142 struct storvsc_device
*stor_device
;
144 stor_device
= (struct storvsc_device
*)device
->ext
;
145 /* ASSERT(stor_device); */
147 atomic_dec(&stor_device
->ref_count
);
148 /* ASSERT(atomic_read(&stor_device->ref_count)); */
151 /* Drop ref count to 1 to effectively disable get_stor_device() */
152 static inline struct storvsc_device
*release_stor_device(
153 struct hv_device
*device
)
155 struct storvsc_device
*stor_device
;
157 stor_device
= (struct storvsc_device
*)device
->ext
;
158 /* ASSERT(stor_device); */
160 /* Busy wait until the ref drop to 2, then set it to 1 */
161 while (atomic_cmpxchg(&stor_device
->ref_count
, 2, 1) != 2)
167 /* Drop ref count to 0. No one can use stor_device object. */
168 static inline struct storvsc_device
*final_release_stor_device(
169 struct hv_device
*device
)
171 struct storvsc_device
*stor_device
;
173 stor_device
= (struct storvsc_device
*)device
->ext
;
174 /* ASSERT(stor_device); */
176 /* Busy wait until the ref drop to 1, then set it to 0 */
177 while (atomic_cmpxchg(&stor_device
->ref_count
, 1, 0) != 1)
184 static int stor_vsc_channel_init(struct hv_device
*device
)
186 struct storvsc_device
*stor_device
;
187 struct storvsc_request_extension
*request
;
188 struct vstor_packet
*vstor_packet
;
191 stor_device
= get_stor_device(device
);
193 DPRINT_ERR(STORVSC
, "unable to get stor device..."
194 "device being destroyed?");
198 request
= &stor_device
->init_request
;
199 vstor_packet
= &request
->vstor_packet
;
202 * Now, initiate the vsc/vsp initialization protocol on the open
205 memset(request
, 0, sizeof(struct storvsc_request_extension
));
206 init_waitqueue_head(&request
->wait_event
);
207 vstor_packet
->operation
= VSTOR_OPERATION_BEGIN_INITIALIZATION
;
208 vstor_packet
->flags
= REQUEST_COMPLETION_FLAG
;
210 DPRINT_INFO(STORVSC
, "BEGIN_INITIALIZATION_OPERATION...");
212 request
->wait_condition
= 0;
213 ret
= vmbus_sendpacket(device
->channel
, vstor_packet
,
214 sizeof(struct vstor_packet
),
215 (unsigned long)request
,
217 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
220 "unable to send BEGIN_INITIALIZATION_OPERATION");
224 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
225 msecs_to_jiffies(1000));
226 if (request
->wait_condition
== 0) {
232 if (vstor_packet
->operation
!= VSTOR_OPERATION_COMPLETE_IO
||
233 vstor_packet
->status
!= 0) {
234 DPRINT_ERR(STORVSC
, "BEGIN_INITIALIZATION_OPERATION failed "
235 "(op %d status 0x%x)",
236 vstor_packet
->operation
, vstor_packet
->status
);
240 DPRINT_INFO(STORVSC
, "QUERY_PROTOCOL_VERSION_OPERATION...");
242 /* reuse the packet for version range supported */
243 memset(vstor_packet
, 0, sizeof(struct vstor_packet
));
244 vstor_packet
->operation
= VSTOR_OPERATION_QUERY_PROTOCOL_VERSION
;
245 vstor_packet
->flags
= REQUEST_COMPLETION_FLAG
;
247 vstor_packet
->version
.major_minor
= VMSTOR_PROTOCOL_VERSION_CURRENT
;
248 FILL_VMSTOR_REVISION(vstor_packet
->version
.revision
);
250 request
->wait_condition
= 0;
251 ret
= vmbus_sendpacket(device
->channel
, vstor_packet
,
252 sizeof(struct vstor_packet
),
253 (unsigned long)request
,
255 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
258 "unable to send BEGIN_INITIALIZATION_OPERATION");
262 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
263 msecs_to_jiffies(1000));
264 if (request
->wait_condition
== 0) {
269 /* TODO: Check returned version */
270 if (vstor_packet
->operation
!= VSTOR_OPERATION_COMPLETE_IO
||
271 vstor_packet
->status
!= 0) {
272 DPRINT_ERR(STORVSC
, "QUERY_PROTOCOL_VERSION_OPERATION failed "
273 "(op %d status 0x%x)",
274 vstor_packet
->operation
, vstor_packet
->status
);
278 /* Query channel properties */
279 DPRINT_INFO(STORVSC
, "QUERY_PROPERTIES_OPERATION...");
281 memset(vstor_packet
, 0, sizeof(struct vstor_packet
));
282 vstor_packet
->operation
= VSTOR_OPERATION_QUERY_PROPERTIES
;
283 vstor_packet
->flags
= REQUEST_COMPLETION_FLAG
;
284 vstor_packet
->storage_channel_properties
.port_number
=
285 stor_device
->port_number
;
287 request
->wait_condition
= 0;
288 ret
= vmbus_sendpacket(device
->channel
, vstor_packet
,
289 sizeof(struct vstor_packet
),
290 (unsigned long)request
,
292 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
296 "unable to send QUERY_PROPERTIES_OPERATION");
300 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
301 msecs_to_jiffies(1000));
302 if (request
->wait_condition
== 0) {
307 /* TODO: Check returned version */
308 if (vstor_packet
->operation
!= VSTOR_OPERATION_COMPLETE_IO
||
309 vstor_packet
->status
!= 0) {
310 DPRINT_ERR(STORVSC
, "QUERY_PROPERTIES_OPERATION failed "
311 "(op %d status 0x%x)",
312 vstor_packet
->operation
, vstor_packet
->status
);
316 stor_device
->path_id
= vstor_packet
->storage_channel_properties
.path_id
;
317 stor_device
->target_id
318 = vstor_packet
->storage_channel_properties
.target_id
;
320 DPRINT_DBG(STORVSC
, "channel flag 0x%x, max xfer len 0x%x",
321 vstor_packet
->storage_channel_properties
.flags
,
322 vstor_packet
->storage_channel_properties
.max_transfer_bytes
);
324 DPRINT_INFO(STORVSC
, "END_INITIALIZATION_OPERATION...");
326 memset(vstor_packet
, 0, sizeof(struct vstor_packet
));
327 vstor_packet
->operation
= VSTOR_OPERATION_END_INITIALIZATION
;
328 vstor_packet
->flags
= REQUEST_COMPLETION_FLAG
;
330 request
->wait_condition
= 0;
331 ret
= vmbus_sendpacket(device
->channel
, vstor_packet
,
332 sizeof(struct vstor_packet
),
333 (unsigned long)request
,
335 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
339 "unable to send END_INITIALIZATION_OPERATION");
343 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
344 msecs_to_jiffies(1000));
345 if (request
->wait_condition
== 0) {
350 if (vstor_packet
->operation
!= VSTOR_OPERATION_COMPLETE_IO
||
351 vstor_packet
->status
!= 0) {
352 DPRINT_ERR(STORVSC
, "END_INITIALIZATION_OPERATION failed "
353 "(op %d status 0x%x)",
354 vstor_packet
->operation
, vstor_packet
->status
);
358 DPRINT_INFO(STORVSC
, "**** storage channel up and running!! ****");
361 put_stor_device(device
);
365 static void stor_vsc_on_io_completion(struct hv_device
*device
,
366 struct vstor_packet
*vstor_packet
,
367 struct storvsc_request_extension
*request_ext
)
369 struct hv_storvsc_request
*request
;
370 struct storvsc_device
*stor_device
;
372 stor_device
= must_get_stor_device(device
);
374 DPRINT_ERR(STORVSC
, "unable to get stor device..."
375 "device being destroyed?");
379 DPRINT_DBG(STORVSC
, "IO_COMPLETE_OPERATION - request extension %p "
380 "completed bytes xfer %u", request_ext
,
381 vstor_packet
->vm_srb
.data_transfer_length
);
383 /* ASSERT(request_ext != NULL); */
384 /* ASSERT(request_ext->request != NULL); */
386 request
= request_ext
->request
;
388 /* ASSERT(request->OnIOCompletion != NULL); */
390 /* Copy over the status...etc */
391 request
->status
= vstor_packet
->vm_srb
.scsi_status
;
393 if (request
->status
!= 0 || vstor_packet
->vm_srb
.srb_status
!= 1) {
395 "cmd 0x%x scsi status 0x%x srb status 0x%x\n",
396 request
->cdb
[0], vstor_packet
->vm_srb
.scsi_status
,
397 vstor_packet
->vm_srb
.srb_status
);
400 if ((request
->status
& 0xFF) == 0x02) {
401 /* CHECK_CONDITION */
402 if (vstor_packet
->vm_srb
.srb_status
& 0x80) {
403 /* autosense data available */
404 DPRINT_WARN(STORVSC
, "storvsc pkt %p autosense data "
405 "valid - len %d\n", request_ext
,
406 vstor_packet
->vm_srb
.sense_info_length
);
408 /* ASSERT(vstor_packet->vm_srb.sense_info_length <= */
409 /* request->SenseBufferSize); */
410 memcpy(request
->sense_buffer
,
411 vstor_packet
->vm_srb
.sense_data
,
412 vstor_packet
->vm_srb
.sense_info_length
);
414 request
->sense_buffer_size
=
415 vstor_packet
->vm_srb
.sense_info_length
;
420 request
->bytes_xfer
= vstor_packet
->vm_srb
.data_transfer_length
;
422 request
->on_io_completion(request
);
424 atomic_dec(&stor_device
->num_outstanding_req
);
426 put_stor_device(device
);
429 static void stor_vsc_on_receive(struct hv_device
*device
,
430 struct vstor_packet
*vstor_packet
,
431 struct storvsc_request_extension
*request_ext
)
433 switch (vstor_packet
->operation
) {
434 case VSTOR_OPERATION_COMPLETE_IO
:
435 DPRINT_DBG(STORVSC
, "IO_COMPLETE_OPERATION");
436 stor_vsc_on_io_completion(device
, vstor_packet
, request_ext
);
438 case VSTOR_OPERATION_REMOVE_DEVICE
:
439 DPRINT_INFO(STORVSC
, "REMOVE_DEVICE_OPERATION");
444 DPRINT_INFO(STORVSC
, "Unknown operation received - %d",
445 vstor_packet
->operation
);
450 static void stor_vsc_on_channel_callback(void *context
)
452 struct hv_device
*device
= (struct hv_device
*)context
;
453 struct storvsc_device
*stor_device
;
456 unsigned char packet
[ALIGN(sizeof(struct vstor_packet
), 8)];
457 struct storvsc_request_extension
*request
;
460 /* ASSERT(device); */
462 stor_device
= must_get_stor_device(device
);
464 DPRINT_ERR(STORVSC
, "unable to get stor device..."
465 "device being destroyed?");
470 ret
= vmbus_recvpacket(device
->channel
, packet
,
471 ALIGN(sizeof(struct vstor_packet
), 8),
472 &bytes_recvd
, &request_id
);
473 if (ret
== 0 && bytes_recvd
> 0) {
474 DPRINT_DBG(STORVSC
, "receive %d bytes - tid %llx",
475 bytes_recvd
, request_id
);
477 /* ASSERT(bytes_recvd ==
478 sizeof(struct vstor_packet)); */
480 request
= (struct storvsc_request_extension
*)
481 (unsigned long)request_id
;
482 /* ASSERT(request);c */
484 /* if (vstor_packet.Flags & SYNTHETIC_FLAG) */
485 if ((request
== &stor_device
->init_request
) ||
486 (request
== &stor_device
->reset_request
)) {
487 /* DPRINT_INFO(STORVSC,
488 * "reset completion - operation "
490 * vstor_packet.Operation,
491 * vstor_packet.Status); */
493 memcpy(&request
->vstor_packet
, packet
,
494 sizeof(struct vstor_packet
));
495 request
->wait_condition
= 1;
496 wake_up(&request
->wait_event
);
498 stor_vsc_on_receive(device
,
499 (struct vstor_packet
*)packet
,
503 /* DPRINT_DBG(STORVSC, "nothing else to read..."); */
508 put_stor_device(device
);
512 static int stor_vsc_connect_to_vsp(struct hv_device
*device
)
514 struct vmstorage_channel_properties props
;
515 struct storvsc_driver_object
*stor_driver
;
518 stor_driver
= (struct storvsc_driver_object
*)device
->drv
;
519 memset(&props
, 0, sizeof(struct vmstorage_channel_properties
));
521 /* Open the channel */
522 ret
= vmbus_open(device
->channel
,
523 stor_driver
->ring_buffer_size
,
524 stor_driver
->ring_buffer_size
,
526 sizeof(struct vmstorage_channel_properties
),
527 stor_vsc_on_channel_callback
, device
);
529 DPRINT_DBG(STORVSC
, "storage props: path id %d, tgt id %d, max xfer %d",
530 props
.path_id
, props
.target_id
, props
.max_transfer_bytes
);
533 DPRINT_ERR(STORVSC
, "unable to open channel: %d", ret
);
537 ret
= stor_vsc_channel_init(device
);
543 * stor_vsc_on_device_add - Callback when the device belonging to this driver
546 static int stor_vsc_on_device_add(struct hv_device
*device
,
547 void *additional_info
)
549 struct storvsc_device
*stor_device
;
550 /* struct vmstorage_channel_properties *props; */
551 struct storvsc_device_info
*device_info
;
554 device_info
= (struct storvsc_device_info
*)additional_info
;
555 stor_device
= alloc_stor_device(device
);
561 /* Save the channel properties to our storvsc channel */
562 /* props = (struct vmstorage_channel_properties *)
563 * channel->offerMsg.Offer.u.Standard.UserDefined; */
567 * If we support more than 1 scsi channel, we need to set the
568 * port number here to the scsi channel but how do we get the
569 * scsi channel prior to the bus scan
572 /* storChannel->PortNumber = 0;
573 storChannel->PathId = props->PathId;
574 storChannel->TargetId = props->TargetId; */
576 stor_device
->port_number
= device_info
->port_number
;
577 /* Send it back up */
578 ret
= stor_vsc_connect_to_vsp(device
);
580 /* device_info->PortNumber = stor_device->PortNumber; */
581 device_info
->path_id
= stor_device
->path_id
;
582 device_info
->target_id
= stor_device
->target_id
;
584 DPRINT_DBG(STORVSC
, "assigned port %u, path %u target %u\n",
585 stor_device
->port_number
, stor_device
->path_id
,
586 stor_device
->target_id
);
593 * stor_vsc_on_device_remove - Callback when the our device is being removed
595 static int stor_vsc_on_device_remove(struct hv_device
*device
)
597 struct storvsc_device
*stor_device
;
599 DPRINT_INFO(STORVSC
, "disabling storage device (%p)...",
602 stor_device
= release_stor_device(device
);
605 * At this point, all outbound traffic should be disable. We
606 * only allow inbound traffic (responses) to proceed so that
607 * outstanding requests can be completed.
609 while (atomic_read(&stor_device
->num_outstanding_req
)) {
610 DPRINT_INFO(STORVSC
, "waiting for %d requests to complete...",
611 atomic_read(&stor_device
->num_outstanding_req
));
615 DPRINT_INFO(STORVSC
, "removing storage device (%p)...",
618 stor_device
= final_release_stor_device(device
);
620 DPRINT_INFO(STORVSC
, "storage device (%p) safe to remove", stor_device
);
622 /* Close the channel */
623 vmbus_close(device
->channel
);
625 free_stor_device(stor_device
);
629 int stor_vsc_on_host_reset(struct hv_device
*device
)
631 struct storvsc_device
*stor_device
;
632 struct storvsc_request_extension
*request
;
633 struct vstor_packet
*vstor_packet
;
636 DPRINT_INFO(STORVSC
, "resetting host adapter...");
638 stor_device
= get_stor_device(device
);
640 DPRINT_ERR(STORVSC
, "unable to get stor device..."
641 "device being destroyed?");
645 request
= &stor_device
->reset_request
;
646 vstor_packet
= &request
->vstor_packet
;
648 init_waitqueue_head(&request
->wait_event
);
650 vstor_packet
->operation
= VSTOR_OPERATION_RESET_BUS
;
651 vstor_packet
->flags
= REQUEST_COMPLETION_FLAG
;
652 vstor_packet
->vm_srb
.path_id
= stor_device
->path_id
;
654 request
->wait_condition
= 0;
655 ret
= vmbus_sendpacket(device
->channel
, vstor_packet
,
656 sizeof(struct vstor_packet
),
657 (unsigned long)&stor_device
->reset_request
,
659 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
661 DPRINT_ERR(STORVSC
, "Unable to send reset packet %p ret %d",
666 wait_event_timeout(request
->wait_event
, request
->wait_condition
,
667 msecs_to_jiffies(1000));
668 if (request
->wait_condition
== 0) {
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 put_stor_device(device
);
686 * stor_vsc_on_io_request - Callback to initiate an I/O request
688 static int stor_vsc_on_io_request(struct hv_device
*device
,
689 struct hv_storvsc_request
*request
)
691 struct storvsc_device
*stor_device
;
692 struct storvsc_request_extension
*request_extension
;
693 struct vstor_packet
*vstor_packet
;
697 (struct storvsc_request_extension
*)request
->extension
;
698 vstor_packet
= &request_extension
->vstor_packet
;
699 stor_device
= get_stor_device(device
);
701 DPRINT_DBG(STORVSC
, "enter - Device %p, DeviceExt %p, Request %p, "
702 "Extension %p", device
, stor_device
, request
,
705 DPRINT_DBG(STORVSC
, "req %p len %d bus %d, target %d, lun %d cdblen %d",
706 request
, request
->data_buffer
.len
, request
->bus
,
707 request
->target_id
, request
->lun_id
, request
->cdb_len
);
710 DPRINT_ERR(STORVSC
, "unable to get stor device..."
711 "device being destroyed?");
715 /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, request->Cdb,
716 * request->CdbLen); */
718 request_extension
->request
= request
;
719 request_extension
->device
= device
;
721 memset(vstor_packet
, 0 , sizeof(struct vstor_packet
));
723 vstor_packet
->flags
|= REQUEST_COMPLETION_FLAG
;
725 vstor_packet
->vm_srb
.length
= sizeof(struct vmscsi_request
);
727 vstor_packet
->vm_srb
.port_number
= request
->host
;
728 vstor_packet
->vm_srb
.path_id
= request
->bus
;
729 vstor_packet
->vm_srb
.target_id
= request
->target_id
;
730 vstor_packet
->vm_srb
.lun
= request
->lun_id
;
732 vstor_packet
->vm_srb
.sense_info_length
= SENSE_BUFFER_SIZE
;
734 /* Copy over the scsi command descriptor block */
735 vstor_packet
->vm_srb
.cdb_length
= request
->cdb_len
;
736 memcpy(&vstor_packet
->vm_srb
.cdb
, request
->cdb
, request
->cdb_len
);
738 vstor_packet
->vm_srb
.data_in
= request
->type
;
739 vstor_packet
->vm_srb
.data_transfer_length
= request
->data_buffer
.len
;
741 vstor_packet
->operation
= VSTOR_OPERATION_EXECUTE_SRB
;
743 DPRINT_DBG(STORVSC
, "srb - len %d port %d, path %d, target %d, "
744 "lun %d senselen %d cdblen %d",
745 vstor_packet
->vm_srb
.length
,
746 vstor_packet
->vm_srb
.port_number
,
747 vstor_packet
->vm_srb
.path_id
,
748 vstor_packet
->vm_srb
.target_id
,
749 vstor_packet
->vm_srb
.lun
,
750 vstor_packet
->vm_srb
.sense_info_length
,
751 vstor_packet
->vm_srb
.cdb_length
);
753 if (request_extension
->request
->data_buffer
.len
) {
754 ret
= vmbus_sendpacket_multipagebuffer(device
->channel
,
755 &request_extension
->request
->data_buffer
,
757 sizeof(struct vstor_packet
),
758 (unsigned long)request_extension
);
760 ret
= vmbus_sendpacket(device
->channel
, vstor_packet
,
761 sizeof(struct vstor_packet
),
762 (unsigned long)request_extension
,
764 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
768 DPRINT_DBG(STORVSC
, "Unable to send packet %p ret %d",
772 atomic_inc(&stor_device
->num_outstanding_req
);
774 put_stor_device(device
);
779 * stor_vsc_on_cleanup - Perform any cleanup when the driver is removed
781 static void stor_vsc_on_cleanup(struct hv_driver
*driver
)
786 * stor_vsc_initialize - Main entry point
788 int stor_vsc_initialize(struct hv_driver
*driver
)
790 struct storvsc_driver_object
*stor_driver
;
792 stor_driver
= (struct storvsc_driver_object
*)driver
;
794 DPRINT_DBG(STORVSC
, "sizeof(STORVSC_REQUEST)=%zd "
795 "sizeof(struct storvsc_request_extension)=%zd "
796 "sizeof(struct vstor_packet)=%zd, "
797 "sizeof(struct vmscsi_request)=%zd",
798 sizeof(struct hv_storvsc_request
),
799 sizeof(struct storvsc_request_extension
),
800 sizeof(struct vstor_packet
),
801 sizeof(struct vmscsi_request
));
803 /* Make sure we are at least 2 pages since 1 page is used for control */
804 /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */
806 driver
->name
= g_driver_name
;
807 memcpy(&driver
->dev_type
, &gStorVscDeviceType
,
808 sizeof(struct hv_guid
));
810 stor_driver
->request_ext_size
=
811 sizeof(struct storvsc_request_extension
);
814 * Divide the ring buffer data size (which is 1 page less
815 * than the ring buffer size since that page is reserved for
816 * the ring buffer indices) by the max request size (which is
817 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
819 stor_driver
->max_outstanding_req_per_channel
=
820 ((stor_driver
->ring_buffer_size
- PAGE_SIZE
) /
821 ALIGN(MAX_MULTIPAGE_BUFFER_PACKET
+
822 sizeof(struct vstor_packet
) + sizeof(u64
),
825 DPRINT_INFO(STORVSC
, "max io %u, currently %u\n",
826 stor_driver
->max_outstanding_req_per_channel
,
827 STORVSC_MAX_IO_REQUESTS
);
829 /* Setup the dispatch table */
830 stor_driver
->base
.dev_add
= stor_vsc_on_device_add
;
831 stor_driver
->base
.dev_rm
= stor_vsc_on_device_remove
;
832 stor_driver
->base
.cleanup
= stor_vsc_on_cleanup
;
834 stor_driver
->on_io_request
= stor_vsc_on_io_request
;