blob: 4e6650712ba10d1e5f2a7e6097b774d9c547b754 [file] [log] [blame]
Hank Janssenab057782009-07-13 15:19:28 -07001/*
2 *
3 * Copyright (c) 2009, Microsoft Corporation.
4 *
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.
8 *
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
12 * more details.
13 *
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.
17 *
18 * Authors:
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
21 *
22 */
23
24
25#ifndef _STORVSC_API_H_
26#define _STORVSC_API_H_
27
K. Y. Srinivasan036bbed2011-03-23 10:50:20 -070028#include "vstorage.h"
Greg Kroah-Hartman447fc672010-05-05 22:43:02 -070029#include "vmbus_api.h"
Hank Janssenab057782009-07-13 15:19:28 -070030
Bill Pemberton454f18a2009-07-27 16:47:24 -040031/* Defines */
Hank Janssen15dd1c92010-08-05 19:30:31 +000032#define STORVSC_RING_BUFFER_SIZE (20*PAGE_SIZE)
Greg Kroah-Hartman9bcd7862009-08-28 16:19:17 -070033#define BLKVSC_RING_BUFFER_SIZE (20*PAGE_SIZE)
Hank Janssenab057782009-07-13 15:19:28 -070034
Hank Janssen15dd1c92010-08-05 19:30:31 +000035#define STORVSC_MAX_IO_REQUESTS 128
Hank Janssenab057782009-07-13 15:19:28 -070036
Bill Pemberton454f18a2009-07-27 16:47:24 -040037/*
38 * In Hyper-V, each port/path/target maps to 1 scsi host adapter. In
39 * reality, the path/target is not used (ie always set to 0) so our
40 * scsi host adapter essentially has 1 bus with 1 target that contains
41 * up to 256 luns.
42 */
Hank Janssenab057782009-07-13 15:19:28 -070043#define STORVSC_MAX_LUNS_PER_TARGET 64
Greg Kroah-Hartman9bcd7862009-08-28 16:19:17 -070044#define STORVSC_MAX_TARGETS 1
Hank Janssenab057782009-07-13 15:19:28 -070045#define STORVSC_MAX_CHANNELS 1
46
Nicolas Palix0b3f6832009-07-29 14:10:19 +020047struct hv_storvsc_request;
Hank Janssenab057782009-07-13 15:19:28 -070048
Bill Pemberton454f18a2009-07-27 16:47:24 -040049/* Matches Windows-end */
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070050enum storvsc_request_type{
Hank Janssenab057782009-07-13 15:19:28 -070051 WRITE_TYPE,
52 READ_TYPE,
53 UNKNOWN_TYPE,
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070054};
Hank Janssenab057782009-07-13 15:19:28 -070055
Nicolas Palix0b3f6832009-07-29 14:10:19 +020056struct hv_storvsc_request {
Hank Janssen8a046022010-12-06 12:26:45 -080057 enum storvsc_request_type type;
58 u32 host;
59 u32 bus;
60 u32 target_id;
61 u32 lun_id;
62 u8 *cdb;
63 u32 cdb_len;
64 u32 status;
65 u32 bytes_xfer;
Hank Janssenab057782009-07-13 15:19:28 -070066
Hank Janssen8a046022010-12-06 12:26:45 -080067 unsigned char *sense_buffer;
68 u32 sense_buffer_size;
Hank Janssenab057782009-07-13 15:19:28 -070069
Hank Janssen8a046022010-12-06 12:26:45 -080070 void *context;
Hank Janssenab057782009-07-13 15:19:28 -070071
Hank Janssen8a046022010-12-06 12:26:45 -080072 void (*on_io_completion)(struct hv_storvsc_request *request);
Hank Janssenab057782009-07-13 15:19:28 -070073
Bill Pemberton454f18a2009-07-27 16:47:24 -040074 /* This points to the memory after DataBuffer */
Hank Janssen8a046022010-12-06 12:26:45 -080075 void *extension;
Hank Janssenab057782009-07-13 15:19:28 -070076
Hank Janssen8a046022010-12-06 12:26:45 -080077 struct hv_multipage_buffer data_buffer;
Nicolas Palix0b3f6832009-07-29 14:10:19 +020078};
Hank Janssenab057782009-07-13 15:19:28 -070079
Bill Pemberton454f18a2009-07-27 16:47:24 -040080/* Represents the block vsc driver */
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070081struct storvsc_driver_object {
Greg Kroah-Hartman9bcd7862009-08-28 16:19:17 -070082 /* Must be the first field */
83 /* Which is a bug FIXME! */
Hank Janssen8a046022010-12-06 12:26:45 -080084 struct hv_driver base;
Hank Janssenab057782009-07-13 15:19:28 -070085
Bill Pemberton454f18a2009-07-27 16:47:24 -040086 /* Set by caller (in bytes) */
Hank Janssen8a046022010-12-06 12:26:45 -080087 u32 ring_buffer_size;
Hank Janssenab057782009-07-13 15:19:28 -070088
Bill Pemberton454f18a2009-07-27 16:47:24 -040089 /* Allocate this much private extension for each I/O request */
Hank Janssen8a046022010-12-06 12:26:45 -080090 u32 request_ext_size;
Hank Janssenab057782009-07-13 15:19:28 -070091
Bill Pemberton454f18a2009-07-27 16:47:24 -040092 /* Maximum # of requests in flight per channel/device */
Hank Janssen8a046022010-12-06 12:26:45 -080093 u32 max_outstanding_req_per_channel;
Hank Janssenab057782009-07-13 15:19:28 -070094
Bill Pemberton454f18a2009-07-27 16:47:24 -040095 /* Specific to this driver */
Hank Janssen8a046022010-12-06 12:26:45 -080096 int (*on_io_request)(struct hv_device *device,
97 struct hv_storvsc_request *request);
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070098};
Hank Janssenab057782009-07-13 15:19:28 -070099
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -0700100struct storvsc_device_info {
Hank Janssen8a046022010-12-06 12:26:45 -0800101 unsigned int port_number;
102 unsigned char path_id;
103 unsigned char target_id;
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -0700104};
Hank Janssenab057782009-07-13 15:19:28 -0700105
K. Y. Srinivasan036bbed2011-03-23 10:50:20 -0700106struct storvsc_request_extension {
107 struct hv_storvsc_request *request;
108 struct hv_device *device;
109
110 /* Synchronize the request/response if needed */
111 int wait_condition;
112 wait_queue_head_t wait_event;
113
114 struct vstor_packet vstor_packet;
115};
116
K. Y. Srinivasanf24eeb02011-03-23 10:50:21 -0700117/* A storvsc device is a device object that contains a vmbus channel */
118struct storvsc_device {
119 struct hv_device *device;
120
121 /* 0 indicates the device is being destroyed */
122 atomic_t ref_count;
123
124 atomic_t num_outstanding_req;
125
126 /*
127 * Each unique Port/Path/Target represents 1 channel ie scsi
128 * controller. In reality, the pathid, targetid is always 0
129 * and the port is set by us
130 */
131 unsigned int port_number;
132 unsigned char path_id;
133 unsigned char target_id;
134
K. Y. Srinivasanf24eeb02011-03-23 10:50:21 -0700135 /* Used for vsc/vsp channel reset process */
136 struct storvsc_request_extension init_request;
137 struct storvsc_request_extension reset_request;
138};
139
K. Y. Srinivasan852c16d2011-03-23 10:50:31 -0700140
141/* Get the stordevice object iff exists and its refcount > 1 */
142static inline struct storvsc_device *get_stor_device(struct hv_device *device)
143{
144 struct storvsc_device *stor_device;
145
146 stor_device = (struct storvsc_device *)device->ext;
147 if (stor_device && atomic_read(&stor_device->ref_count) > 1)
148 atomic_inc(&stor_device->ref_count);
149 else
150 stor_device = NULL;
151
152 return stor_device;
153}
154
Bill Pemberton454f18a2009-07-27 16:47:24 -0400155/* Interface */
Hank Jansseneb4f3e02010-12-06 12:26:46 -0800156int stor_vsc_on_host_reset(struct hv_device *device);
Bill Pemberton454f18a2009-07-27 16:47:24 -0400157
K. Y. Srinivasanafa3f3d2011-03-23 10:50:23 -0700158int stor_vsc_on_device_add(struct hv_device *device,
159 void *additional_info);
160int stor_vsc_on_device_remove(struct hv_device *device);
161
162int stor_vsc_on_io_request(struct hv_device *device,
163 struct hv_storvsc_request *request);
164void stor_vsc_on_cleanup(struct hv_driver *driver);
165
166
Bill Pemberton454f18a2009-07-27 16:47:24 -0400167#endif /* _STORVSC_API_H_ */