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>
25 #ifndef _STORVSC_API_H_
26 #define _STORVSC_API_H_
28 #include <linux/kernel.h>
30 #include "vmbus_api.h"
33 #define STORVSC_RING_BUFFER_SIZE (20*PAGE_SIZE)
34 #define BLKVSC_RING_BUFFER_SIZE (20*PAGE_SIZE)
36 #define STORVSC_MAX_IO_REQUESTS 128
39 * In Hyper-V, each port/path/target maps to 1 scsi host adapter. In
40 * reality, the path/target is not used (ie always set to 0) so our
41 * scsi host adapter essentially has 1 bus with 1 target that contains
44 #define STORVSC_MAX_LUNS_PER_TARGET 64
45 #define STORVSC_MAX_TARGETS 1
46 #define STORVSC_MAX_CHANNELS 1
48 struct hv_storvsc_request
;
50 /* Matches Windows-end */
51 enum storvsc_request_type
{
58 struct storvsc_request_extension
{
59 struct hv_storvsc_request
*request
;
60 struct hv_device
*device
;
62 /* Synchronize the request/response if needed */
63 struct completion wait_event
;
65 struct vstor_packet vstor_packet
;
68 struct hv_storvsc_request
{
77 unsigned char *sense_buffer
;
78 u32 sense_buffer_size
;
82 void (*on_io_completion
)(struct hv_storvsc_request
*request
);
84 struct storvsc_request_extension extension
;
86 struct hv_multipage_buffer data_buffer
;
89 /* Represents the block vsc driver */
90 struct storvsc_driver_object
{
91 struct hv_driver base
;
93 /* Set by caller (in bytes) */
96 /* Maximum # of requests in flight per channel/device */
97 u32 max_outstanding_req_per_channel
;
99 /* Specific to this driver */
100 int (*on_io_request
)(struct hv_device
*device
,
101 struct hv_storvsc_request
*request
);
104 struct storvsc_device_info
{
105 unsigned int port_number
;
106 unsigned char path_id
;
107 unsigned char target_id
;
110 /* A storvsc device is a device object that contains a vmbus channel */
111 struct storvsc_device
{
112 struct hv_device
*device
;
114 /* 0 indicates the device is being destroyed */
117 atomic_t num_outstanding_req
;
120 * Each unique Port/Path/Target represents 1 channel ie scsi
121 * controller. In reality, the pathid, targetid is always 0
122 * and the port is set by us
124 unsigned int port_number
;
125 unsigned char path_id
;
126 unsigned char target_id
;
128 /* Used for vsc/vsp channel reset process */
129 struct storvsc_request_extension init_request
;
130 struct storvsc_request_extension reset_request
;
134 /* Get the stordevice object iff exists and its refcount > 1 */
135 static inline struct storvsc_device
*get_stor_device(struct hv_device
*device
)
137 struct storvsc_device
*stor_device
;
139 stor_device
= (struct storvsc_device
*)device
->ext
;
140 if (stor_device
&& atomic_read(&stor_device
->ref_count
) > 1)
141 atomic_inc(&stor_device
->ref_count
);
149 static inline void put_stor_device(struct hv_device
*device
)
151 struct storvsc_device
*stor_device
;
153 stor_device
= (struct storvsc_device
*)device
->ext
;
155 atomic_dec(&stor_device
->ref_count
);
158 static inline struct storvsc_driver_object
*hvdr_to_stordr(struct hv_driver
*d
)
160 return container_of(d
, struct storvsc_driver_object
, base
);
165 int stor_vsc_on_device_add(struct hv_device
*device
,
166 void *additional_info
);
167 int stor_vsc_on_device_remove(struct hv_device
*device
);
169 int stor_vsc_on_io_request(struct hv_device
*device
,
170 struct hv_storvsc_request
*request
);
171 void stor_vsc_on_cleanup(struct hv_driver
*driver
);
174 #endif /* _STORVSC_API_H_ */