blob: 32228c0676566d25caf54f8aabb4e9e0cae34cc1 [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"
K. Y. Srinivasan0724e5f2011-04-26 09:20:18 -070031#include "vmbus.h"
Hank Janssenab057782009-07-13 15:19:28 -070032
Bill Pemberton454f18a2009-07-27 16:47:24 -040033/* Defines */
Hank Janssen15dd1c92010-08-05 19:30:31 +000034#define STORVSC_RING_BUFFER_SIZE (20*PAGE_SIZE)
Greg Kroah-Hartman9bcd7862009-08-28 16:19:17 -070035#define BLKVSC_RING_BUFFER_SIZE (20*PAGE_SIZE)
Hank Janssenab057782009-07-13 15:19:28 -070036
Hank Janssen15dd1c92010-08-05 19:30:31 +000037#define STORVSC_MAX_IO_REQUESTS 128
Hank Janssenab057782009-07-13 15:19:28 -070038
Bill Pemberton454f18a2009-07-27 16:47:24 -040039/*
40 * In Hyper-V, each port/path/target maps to 1 scsi host adapter. In
41 * reality, the path/target is not used (ie always set to 0) so our
42 * scsi host adapter essentially has 1 bus with 1 target that contains
43 * up to 256 luns.
44 */
Hank Janssenab057782009-07-13 15:19:28 -070045#define STORVSC_MAX_LUNS_PER_TARGET 64
Greg Kroah-Hartman9bcd7862009-08-28 16:19:17 -070046#define STORVSC_MAX_TARGETS 1
Hank Janssenab057782009-07-13 15:19:28 -070047#define STORVSC_MAX_CHANNELS 1
48
Nicolas Palix0b3f6832009-07-29 14:10:19 +020049struct hv_storvsc_request;
Hank Janssenab057782009-07-13 15:19:28 -070050
Bill Pemberton454f18a2009-07-27 16:47:24 -040051/* Matches Windows-end */
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070052enum storvsc_request_type{
Hank Janssenab057782009-07-13 15:19:28 -070053 WRITE_TYPE,
54 READ_TYPE,
55 UNKNOWN_TYPE,
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070056};
Hank Janssenab057782009-07-13 15:19:28 -070057
K. Y. Srinivasanbf587a12011-03-28 09:33:26 -070058
K. Y. Srinivasand7a1bdb2011-03-28 09:33:44 -070059struct hv_storvsc_request {
K. Y. Srinivasanbf587a12011-03-28 09:33:26 -070060 struct hv_storvsc_request *request;
61 struct hv_device *device;
62
63 /* Synchronize the request/response if needed */
K. Y. Srinivasan939584652011-03-28 09:33:30 -070064 struct completion wait_event;
K. Y. Srinivasanbf587a12011-03-28 09:33:26 -070065
K. Y. Srinivasan237ecd62011-03-28 09:33:39 -070066 unsigned char *sense_buffer;
K. Y. Srinivasanefb5a662011-03-28 09:33:40 -070067 void *context;
K. Y. Srinivasan0bb71122011-03-28 09:33:41 -070068 void (*on_io_completion)(struct hv_storvsc_request *request);
K. Y. Srinivasane9e936c2011-03-28 09:33:43 -070069 struct hv_multipage_buffer data_buffer;
K. Y. Srinivasan237ecd62011-03-28 09:33:39 -070070
K. Y. Srinivasanbf587a12011-03-28 09:33:26 -070071 struct vstor_packet vstor_packet;
72};
73
Hank Janssenab057782009-07-13 15:19:28 -070074
Bill Pemberton454f18a2009-07-27 16:47:24 -040075/* Represents the block vsc driver */
K. Y. Srinivasan2e795052011-05-10 07:53:52 -070076struct storvsc_driver {
Hank Janssen8a046022010-12-06 12:26:45 -080077 struct hv_driver base;
Hank Janssenab057782009-07-13 15:19:28 -070078
Bill Pemberton454f18a2009-07-27 16:47:24 -040079 /* Set by caller (in bytes) */
Hank Janssen8a046022010-12-06 12:26:45 -080080 u32 ring_buffer_size;
Hank Janssenab057782009-07-13 15:19:28 -070081
Bill Pemberton454f18a2009-07-27 16:47:24 -040082 /* Maximum # of requests in flight per channel/device */
Hank Janssen8a046022010-12-06 12:26:45 -080083 u32 max_outstanding_req_per_channel;
Hank Janssenab057782009-07-13 15:19:28 -070084
Bill Pemberton454f18a2009-07-27 16:47:24 -040085 /* Specific to this driver */
Hank Janssen8a046022010-12-06 12:26:45 -080086 int (*on_io_request)(struct hv_device *device,
87 struct hv_storvsc_request *request);
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070088};
Hank Janssenab057782009-07-13 15:19:28 -070089
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070090struct storvsc_device_info {
Hank Janssen8a046022010-12-06 12:26:45 -080091 unsigned int port_number;
92 unsigned char path_id;
93 unsigned char target_id;
Greg Kroah-Hartman9f0c7d22009-08-28 16:20:07 -070094};
Hank Janssenab057782009-07-13 15:19:28 -070095
K. Y. Srinivasan1f91bca2011-04-22 14:55:25 -070096struct storvsc_major_info {
97 int major;
98 int index;
99 bool do_register;
100 char *devname;
101 char *diskname;
102};
103
K. Y. Srinivasanf24eeb02011-03-23 10:50:21 -0700104/* A storvsc device is a device object that contains a vmbus channel */
105struct storvsc_device {
106 struct hv_device *device;
107
108 /* 0 indicates the device is being destroyed */
109 atomic_t ref_count;
110
111 atomic_t num_outstanding_req;
112
113 /*
114 * Each unique Port/Path/Target represents 1 channel ie scsi
115 * controller. In reality, the pathid, targetid is always 0
116 * and the port is set by us
117 */
118 unsigned int port_number;
119 unsigned char path_id;
120 unsigned char target_id;
121
K. Y. Srinivasanf24eeb02011-03-23 10:50:21 -0700122 /* Used for vsc/vsp channel reset process */
K. Y. Srinivasand7a1bdb2011-03-28 09:33:44 -0700123 struct hv_storvsc_request init_request;
124 struct hv_storvsc_request reset_request;
K. Y. Srinivasanf24eeb02011-03-23 10:50:21 -0700125};
126
K. Y. Srinivasan852c16d2011-03-23 10:50:31 -0700127
128/* Get the stordevice object iff exists and its refcount > 1 */
129static inline struct storvsc_device *get_stor_device(struct hv_device *device)
130{
131 struct storvsc_device *stor_device;
132
133 stor_device = (struct storvsc_device *)device->ext;
134 if (stor_device && atomic_read(&stor_device->ref_count) > 1)
135 atomic_inc(&stor_device->ref_count);
136 else
137 stor_device = NULL;
138
139 return stor_device;
140}
141
K. Y. Srinivasan1604b1b2011-03-23 10:50:32 -0700142
143static inline void put_stor_device(struct hv_device *device)
144{
145 struct storvsc_device *stor_device;
146
147 stor_device = (struct storvsc_device *)device->ext;
148
149 atomic_dec(&stor_device->ref_count);
150}
151
K. Y. Srinivasan2e795052011-05-10 07:53:52 -0700152static inline struct storvsc_driver *hvdr_to_stordr(struct hv_driver *d)
K. Y. Srinivasanced01b02011-03-28 09:33:29 -0700153{
K. Y. Srinivasan2e795052011-05-10 07:53:52 -0700154 return container_of(d, struct storvsc_driver, base);
K. Y. Srinivasanced01b02011-03-28 09:33:29 -0700155}
156
K. Y. Srinivasan0724e5f2011-04-26 09:20:18 -0700157static inline
K. Y. Srinivasan2e795052011-05-10 07:53:52 -0700158struct storvsc_driver *drv_to_stordrv(struct device_driver *d)
K. Y. Srinivasan0724e5f2011-04-26 09:20:18 -0700159{
160 struct hv_driver *hvdrv = drv_to_hv_drv(d);
161 return hvdr_to_stordr(hvdrv);
162}
163
Bill Pemberton454f18a2009-07-27 16:47:24 -0400164/* Interface */
165
K. Y. Srinivasan2ac5dad2011-05-10 07:53:57 -0700166int storvsc_dev_add(struct hv_device *device,
K. Y. Srinivasanafa3f3d2011-03-23 10:50:23 -0700167 void *additional_info);
K. Y. Srinivasancb706b042011-05-10 07:53:58 -0700168int storvsc_dev_remove(struct hv_device *device);
K. Y. Srinivasanafa3f3d2011-03-23 10:50:23 -0700169
K. Y. Srinivasanbb465922011-05-10 07:54:02 -0700170int storvsc_do_io(struct hv_device *device,
K. Y. Srinivasanafa3f3d2011-03-23 10:50:23 -0700171 struct hv_storvsc_request *request);
K. Y. Srinivasanafa3f3d2011-03-23 10:50:23 -0700172
K. Y. Srinivasan43c51f72011-05-10 07:54:06 -0700173int storvsc_get_major_info(struct storvsc_device_info *device_info,
K. Y. Srinivasan1f91bca2011-04-22 14:55:25 -0700174 struct storvsc_major_info *major_info);
K. Y. Srinivasanafa3f3d2011-03-23 10:50:23 -0700175
Bill Pemberton454f18a2009-07-27 16:47:24 -0400176#endif /* _STORVSC_API_H_ */