blob: 5c80cdb5dc1afec3155ef2341fadb953c636abb1 [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. Srinivasanced01b02011-03-28 09:33:29 -070028#include <linux/kernel.h>
K. Y. Srinivasan036bbed2011-03-23 10:50:20 -070029#include "vstorage.h"
Greg Kroah-Hartman447fc672010-05-05 22:43:02 -070030#include "vmbus_api.h"
Hank Janssenab057782009-07-13 15:19:28 -070031
Bill Pemberton454f18a2009-07-27 16:47:24 -040032/* Defines */
Hank Janssen15dd1c92010-08-05 19:30:31 +000033#define STORVSC_RING_BUFFER_SIZE (20*PAGE_SIZE)
Greg Kroah-Hartman9bcd7862009-08-28 16:19:17 -070034#define BLKVSC_RING_BUFFER_SIZE (20*PAGE_SIZE)
Hank Janssenab057782009-07-13 15:19:28 -070035
Hank Janssen15dd1c92010-08-05 19:30:31 +000036#define STORVSC_MAX_IO_REQUESTS 128
Hank Janssenab057782009-07-13 15:19:28 -070037
Bill Pemberton454f18a2009-07-27 16:47:24 -040038/*
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
42 * up to 256 luns.
43 */
Hank Janssenab057782009-07-13 15:19:28 -070044#define STORVSC_MAX_LUNS_PER_TARGET 64
Greg Kroah-Hartman9bcd7862009-08-28 16:19:17 -070045#define STORVSC_MAX_TARGETS 1
Hank Janssenab057782009-07-13 15:19:28 -070046#define STORVSC_MAX_CHANNELS 1
47
Nicolas Palix0b3f6832009-07-29 14:10:19 +020048struct hv_storvsc_request;
Hank Janssenab057782009-07-13 15:19:28 -070049
Bill Pemberton454f18a2009-07-27 16:47:24 -040050/* Matches Windows-end */
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070051enum storvsc_request_type{
Hank Janssenab057782009-07-13 15:19:28 -070052 WRITE_TYPE,
53 READ_TYPE,
54 UNKNOWN_TYPE,
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070055};
Hank Janssenab057782009-07-13 15:19:28 -070056
K. Y. Srinivasanbf587a12011-03-28 09:33:26 -070057
58struct storvsc_request_extension {
59 struct hv_storvsc_request *request;
60 struct hv_device *device;
61
62 /* Synchronize the request/response if needed */
63 int wait_condition;
64 wait_queue_head_t wait_event;
65
66 struct vstor_packet vstor_packet;
67};
68
Nicolas Palix0b3f6832009-07-29 14:10:19 +020069struct hv_storvsc_request {
Hank Janssen8a046022010-12-06 12:26:45 -080070 enum storvsc_request_type type;
71 u32 host;
72 u32 bus;
73 u32 target_id;
74 u32 lun_id;
75 u8 *cdb;
76 u32 cdb_len;
77 u32 status;
78 u32 bytes_xfer;
Hank Janssenab057782009-07-13 15:19:28 -070079
Hank Janssen8a046022010-12-06 12:26:45 -080080 unsigned char *sense_buffer;
81 u32 sense_buffer_size;
Hank Janssenab057782009-07-13 15:19:28 -070082
Hank Janssen8a046022010-12-06 12:26:45 -080083 void *context;
Hank Janssenab057782009-07-13 15:19:28 -070084
Hank Janssen8a046022010-12-06 12:26:45 -080085 void (*on_io_completion)(struct hv_storvsc_request *request);
Hank Janssenab057782009-07-13 15:19:28 -070086
K. Y. Srinivasan2fd0df22011-03-28 09:33:27 -070087 struct storvsc_request_extension extension;
Hank Janssenab057782009-07-13 15:19:28 -070088
Hank Janssen8a046022010-12-06 12:26:45 -080089 struct hv_multipage_buffer data_buffer;
Nicolas Palix0b3f6832009-07-29 14:10:19 +020090};
Hank Janssenab057782009-07-13 15:19:28 -070091
Bill Pemberton454f18a2009-07-27 16:47:24 -040092/* Represents the block vsc driver */
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070093struct storvsc_driver_object {
Hank Janssen8a046022010-12-06 12:26:45 -080094 struct hv_driver base;
Hank Janssenab057782009-07-13 15:19:28 -070095
Bill Pemberton454f18a2009-07-27 16:47:24 -040096 /* Set by caller (in bytes) */
Hank Janssen8a046022010-12-06 12:26:45 -080097 u32 ring_buffer_size;
Hank Janssenab057782009-07-13 15:19:28 -070098
Bill Pemberton454f18a2009-07-27 16:47:24 -040099 /* Maximum # of requests in flight per channel/device */
Hank Janssen8a046022010-12-06 12:26:45 -0800100 u32 max_outstanding_req_per_channel;
Hank Janssenab057782009-07-13 15:19:28 -0700101
Bill Pemberton454f18a2009-07-27 16:47:24 -0400102 /* Specific to this driver */
Hank Janssen8a046022010-12-06 12:26:45 -0800103 int (*on_io_request)(struct hv_device *device,
104 struct hv_storvsc_request *request);
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -0700105};
Hank Janssenab057782009-07-13 15:19:28 -0700106
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -0700107struct storvsc_device_info {
Hank Janssen8a046022010-12-06 12:26:45 -0800108 unsigned int port_number;
109 unsigned char path_id;
110 unsigned char target_id;
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -0700111};
Hank Janssenab057782009-07-13 15:19:28 -0700112
K. Y. Srinivasanf24eeb02011-03-23 10:50:21 -0700113/* A storvsc device is a device object that contains a vmbus channel */
114struct storvsc_device {
115 struct hv_device *device;
116
117 /* 0 indicates the device is being destroyed */
118 atomic_t ref_count;
119
120 atomic_t num_outstanding_req;
121
122 /*
123 * Each unique Port/Path/Target represents 1 channel ie scsi
124 * controller. In reality, the pathid, targetid is always 0
125 * and the port is set by us
126 */
127 unsigned int port_number;
128 unsigned char path_id;
129 unsigned char target_id;
130
K. Y. Srinivasanf24eeb02011-03-23 10:50:21 -0700131 /* Used for vsc/vsp channel reset process */
132 struct storvsc_request_extension init_request;
133 struct storvsc_request_extension reset_request;
134};
135
K. Y. Srinivasan852c16d2011-03-23 10:50:31 -0700136
137/* Get the stordevice object iff exists and its refcount > 1 */
138static inline struct storvsc_device *get_stor_device(struct hv_device *device)
139{
140 struct storvsc_device *stor_device;
141
142 stor_device = (struct storvsc_device *)device->ext;
143 if (stor_device && atomic_read(&stor_device->ref_count) > 1)
144 atomic_inc(&stor_device->ref_count);
145 else
146 stor_device = NULL;
147
148 return stor_device;
149}
150
K. Y. Srinivasan1604b1b2011-03-23 10:50:32 -0700151
152static inline void put_stor_device(struct hv_device *device)
153{
154 struct storvsc_device *stor_device;
155
156 stor_device = (struct storvsc_device *)device->ext;
157
158 atomic_dec(&stor_device->ref_count);
159}
160
K. Y. Srinivasanced01b02011-03-28 09:33:29 -0700161static inline struct storvsc_driver_object *hvdr_to_stordr(struct hv_driver *d)
162{
163 return container_of(d, struct storvsc_driver_object, base);
164}
165
Bill Pemberton454f18a2009-07-27 16:47:24 -0400166/* Interface */
167
K. Y. Srinivasanafa3f3d2011-03-23 10:50:23 -0700168int stor_vsc_on_device_add(struct hv_device *device,
169 void *additional_info);
170int stor_vsc_on_device_remove(struct hv_device *device);
171
172int stor_vsc_on_io_request(struct hv_device *device,
173 struct hv_storvsc_request *request);
174void stor_vsc_on_cleanup(struct hv_driver *driver);
175
176
Bill Pemberton454f18a2009-07-27 16:47:24 -0400177#endif /* _STORVSC_API_H_ */