Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 1 | /* |
| 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. Srinivasan | ced01b0 | 2011-03-28 09:33:29 -0700 | [diff] [blame] | 28 | #include <linux/kernel.h> |
K. Y. Srinivasan | 604df37 | 2011-05-10 07:54:07 -0700 | [diff] [blame] | 29 | #include <linux/wait.h> |
K. Y. Srinivasan | 036bbed | 2011-03-23 10:50:20 -0700 | [diff] [blame] | 30 | #include "vstorage.h" |
Greg Kroah-Hartman | 447fc67 | 2010-05-05 22:43:02 -0700 | [diff] [blame] | 31 | #include "vmbus_api.h" |
K. Y. Srinivasan | 0724e5f | 2011-04-26 09:20:18 -0700 | [diff] [blame] | 32 | #include "vmbus.h" |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 33 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 34 | /* Defines */ |
Hank Janssen | 15dd1c9 | 2010-08-05 19:30:31 +0000 | [diff] [blame] | 35 | #define STORVSC_RING_BUFFER_SIZE (20*PAGE_SIZE) |
Greg Kroah-Hartman | 9bcd786 | 2009-08-28 16:19:17 -0700 | [diff] [blame] | 36 | #define BLKVSC_RING_BUFFER_SIZE (20*PAGE_SIZE) |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 37 | |
Hank Janssen | 15dd1c9 | 2010-08-05 19:30:31 +0000 | [diff] [blame] | 38 | #define STORVSC_MAX_IO_REQUESTS 128 |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 39 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 40 | /* |
| 41 | * In Hyper-V, each port/path/target maps to 1 scsi host adapter. In |
| 42 | * reality, the path/target is not used (ie always set to 0) so our |
| 43 | * scsi host adapter essentially has 1 bus with 1 target that contains |
| 44 | * up to 256 luns. |
| 45 | */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 46 | #define STORVSC_MAX_LUNS_PER_TARGET 64 |
Greg Kroah-Hartman | 9bcd786 | 2009-08-28 16:19:17 -0700 | [diff] [blame] | 47 | #define STORVSC_MAX_TARGETS 1 |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 48 | #define STORVSC_MAX_CHANNELS 1 |
| 49 | |
Nicolas Palix | 0b3f683 | 2009-07-29 14:10:19 +0200 | [diff] [blame] | 50 | struct hv_storvsc_request; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 51 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 52 | /* Matches Windows-end */ |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 53 | enum storvsc_request_type{ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 54 | WRITE_TYPE, |
| 55 | READ_TYPE, |
| 56 | UNKNOWN_TYPE, |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 57 | }; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 58 | |
K. Y. Srinivasan | bf587a1 | 2011-03-28 09:33:26 -0700 | [diff] [blame] | 59 | |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 60 | struct hv_storvsc_request { |
K. Y. Srinivasan | bf587a1 | 2011-03-28 09:33:26 -0700 | [diff] [blame] | 61 | struct hv_storvsc_request *request; |
| 62 | struct hv_device *device; |
| 63 | |
| 64 | /* Synchronize the request/response if needed */ |
K. Y. Srinivasan | 93958465 | 2011-03-28 09:33:30 -0700 | [diff] [blame] | 65 | struct completion wait_event; |
K. Y. Srinivasan | bf587a1 | 2011-03-28 09:33:26 -0700 | [diff] [blame] | 66 | |
K. Y. Srinivasan | 237ecd6 | 2011-03-28 09:33:39 -0700 | [diff] [blame] | 67 | unsigned char *sense_buffer; |
K. Y. Srinivasan | efb5a66 | 2011-03-28 09:33:40 -0700 | [diff] [blame] | 68 | void *context; |
K. Y. Srinivasan | 0bb7112 | 2011-03-28 09:33:41 -0700 | [diff] [blame] | 69 | void (*on_io_completion)(struct hv_storvsc_request *request); |
K. Y. Srinivasan | e9e936c | 2011-03-28 09:33:43 -0700 | [diff] [blame] | 70 | struct hv_multipage_buffer data_buffer; |
K. Y. Srinivasan | 237ecd6 | 2011-03-28 09:33:39 -0700 | [diff] [blame] | 71 | |
K. Y. Srinivasan | bf587a1 | 2011-03-28 09:33:26 -0700 | [diff] [blame] | 72 | struct vstor_packet vstor_packet; |
| 73 | }; |
| 74 | |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 75 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 76 | /* Represents the block vsc driver */ |
K. Y. Srinivasan | 2e79505 | 2011-05-10 07:53:52 -0700 | [diff] [blame] | 77 | struct storvsc_driver { |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 78 | struct hv_driver base; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 79 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 80 | /* Set by caller (in bytes) */ |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 81 | u32 ring_buffer_size; |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 82 | }; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 83 | |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 84 | struct storvsc_device_info { |
K. Y. Srinivasan | 85cf3a9 | 2011-05-10 07:56:00 -0700 | [diff] [blame^] | 85 | u32 ring_buffer_size; |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 86 | unsigned int port_number; |
| 87 | unsigned char path_id; |
| 88 | unsigned char target_id; |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 89 | }; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 90 | |
K. Y. Srinivasan | 1f91bca | 2011-04-22 14:55:25 -0700 | [diff] [blame] | 91 | struct storvsc_major_info { |
| 92 | int major; |
| 93 | int index; |
| 94 | bool do_register; |
| 95 | char *devname; |
| 96 | char *diskname; |
| 97 | }; |
| 98 | |
K. Y. Srinivasan | f24eeb0 | 2011-03-23 10:50:21 -0700 | [diff] [blame] | 99 | /* A storvsc device is a device object that contains a vmbus channel */ |
| 100 | struct storvsc_device { |
| 101 | struct hv_device *device; |
| 102 | |
| 103 | /* 0 indicates the device is being destroyed */ |
| 104 | atomic_t ref_count; |
| 105 | |
K. Y. Srinivasan | 604df37 | 2011-05-10 07:54:07 -0700 | [diff] [blame] | 106 | bool drain_notify; |
K. Y. Srinivasan | f24eeb0 | 2011-03-23 10:50:21 -0700 | [diff] [blame] | 107 | atomic_t num_outstanding_req; |
| 108 | |
K. Y. Srinivasan | 604df37 | 2011-05-10 07:54:07 -0700 | [diff] [blame] | 109 | wait_queue_head_t waiting_to_drain; |
| 110 | |
K. Y. Srinivasan | f24eeb0 | 2011-03-23 10:50:21 -0700 | [diff] [blame] | 111 | /* |
| 112 | * Each unique Port/Path/Target represents 1 channel ie scsi |
| 113 | * controller. In reality, the pathid, targetid is always 0 |
| 114 | * and the port is set by us |
| 115 | */ |
| 116 | unsigned int port_number; |
| 117 | unsigned char path_id; |
| 118 | unsigned char target_id; |
| 119 | |
K. Y. Srinivasan | f24eeb0 | 2011-03-23 10:50:21 -0700 | [diff] [blame] | 120 | /* Used for vsc/vsp channel reset process */ |
K. Y. Srinivasan | d7a1bdb | 2011-03-28 09:33:44 -0700 | [diff] [blame] | 121 | struct hv_storvsc_request init_request; |
| 122 | struct hv_storvsc_request reset_request; |
K. Y. Srinivasan | f24eeb0 | 2011-03-23 10:50:21 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
K. Y. Srinivasan | 852c16d | 2011-03-23 10:50:31 -0700 | [diff] [blame] | 125 | |
| 126 | /* Get the stordevice object iff exists and its refcount > 1 */ |
| 127 | static inline struct storvsc_device *get_stor_device(struct hv_device *device) |
| 128 | { |
| 129 | struct storvsc_device *stor_device; |
| 130 | |
| 131 | stor_device = (struct storvsc_device *)device->ext; |
| 132 | if (stor_device && atomic_read(&stor_device->ref_count) > 1) |
| 133 | atomic_inc(&stor_device->ref_count); |
| 134 | else |
| 135 | stor_device = NULL; |
| 136 | |
| 137 | return stor_device; |
| 138 | } |
| 139 | |
K. Y. Srinivasan | 1604b1b | 2011-03-23 10:50:32 -0700 | [diff] [blame] | 140 | |
| 141 | static inline void put_stor_device(struct hv_device *device) |
| 142 | { |
| 143 | struct storvsc_device *stor_device; |
| 144 | |
| 145 | stor_device = (struct storvsc_device *)device->ext; |
| 146 | |
| 147 | atomic_dec(&stor_device->ref_count); |
| 148 | } |
| 149 | |
K. Y. Srinivasan | 2e79505 | 2011-05-10 07:53:52 -0700 | [diff] [blame] | 150 | static inline struct storvsc_driver *hvdr_to_stordr(struct hv_driver *d) |
K. Y. Srinivasan | ced01b0 | 2011-03-28 09:33:29 -0700 | [diff] [blame] | 151 | { |
K. Y. Srinivasan | 2e79505 | 2011-05-10 07:53:52 -0700 | [diff] [blame] | 152 | return container_of(d, struct storvsc_driver, base); |
K. Y. Srinivasan | ced01b0 | 2011-03-28 09:33:29 -0700 | [diff] [blame] | 153 | } |
| 154 | |
K. Y. Srinivasan | 0724e5f | 2011-04-26 09:20:18 -0700 | [diff] [blame] | 155 | static inline |
K. Y. Srinivasan | 2e79505 | 2011-05-10 07:53:52 -0700 | [diff] [blame] | 156 | struct storvsc_driver *drv_to_stordrv(struct device_driver *d) |
K. Y. Srinivasan | 0724e5f | 2011-04-26 09:20:18 -0700 | [diff] [blame] | 157 | { |
| 158 | struct hv_driver *hvdrv = drv_to_hv_drv(d); |
| 159 | return hvdr_to_stordr(hvdrv); |
| 160 | } |
| 161 | |
K. Y. Srinivasan | 604df37 | 2011-05-10 07:54:07 -0700 | [diff] [blame] | 162 | static inline void storvsc_wait_to_drain(struct storvsc_device *dev) |
| 163 | { |
| 164 | dev->drain_notify = true; |
| 165 | wait_event(dev->waiting_to_drain, |
| 166 | atomic_read(&dev->num_outstanding_req) == 0); |
| 167 | dev->drain_notify = false; |
| 168 | } |
| 169 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 170 | /* Interface */ |
| 171 | |
K. Y. Srinivasan | 2ac5dad | 2011-05-10 07:53:57 -0700 | [diff] [blame] | 172 | int storvsc_dev_add(struct hv_device *device, |
K. Y. Srinivasan | afa3f3d | 2011-03-23 10:50:23 -0700 | [diff] [blame] | 173 | void *additional_info); |
K. Y. Srinivasan | cb706b04 | 2011-05-10 07:53:58 -0700 | [diff] [blame] | 174 | int storvsc_dev_remove(struct hv_device *device); |
K. Y. Srinivasan | afa3f3d | 2011-03-23 10:50:23 -0700 | [diff] [blame] | 175 | |
K. Y. Srinivasan | bb46592 | 2011-05-10 07:54:02 -0700 | [diff] [blame] | 176 | int storvsc_do_io(struct hv_device *device, |
K. Y. Srinivasan | afa3f3d | 2011-03-23 10:50:23 -0700 | [diff] [blame] | 177 | struct hv_storvsc_request *request); |
K. Y. Srinivasan | afa3f3d | 2011-03-23 10:50:23 -0700 | [diff] [blame] | 178 | |
K. Y. Srinivasan | 43c51f7 | 2011-05-10 07:54:06 -0700 | [diff] [blame] | 179 | int storvsc_get_major_info(struct storvsc_device_info *device_info, |
K. Y. Srinivasan | 1f91bca | 2011-04-22 14:55:25 -0700 | [diff] [blame] | 180 | struct storvsc_major_info *major_info); |
K. Y. Srinivasan | afa3f3d | 2011-03-23 10:50:23 -0700 | [diff] [blame] | 181 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 182 | #endif /* _STORVSC_API_H_ */ |