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 | 036bbed | 2011-03-23 10:50:20 -0700 | [diff] [blame] | 28 | #include "vstorage.h" |
Greg Kroah-Hartman | 447fc67 | 2010-05-05 22:43:02 -0700 | [diff] [blame] | 29 | #include "vmbus_api.h" |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 30 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 31 | /* Defines */ |
Hank Janssen | 15dd1c9 | 2010-08-05 19:30:31 +0000 | [diff] [blame] | 32 | #define STORVSC_RING_BUFFER_SIZE (20*PAGE_SIZE) |
Greg Kroah-Hartman | 9bcd786 | 2009-08-28 16:19:17 -0700 | [diff] [blame] | 33 | #define BLKVSC_RING_BUFFER_SIZE (20*PAGE_SIZE) |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 34 | |
Hank Janssen | 15dd1c9 | 2010-08-05 19:30:31 +0000 | [diff] [blame] | 35 | #define STORVSC_MAX_IO_REQUESTS 128 |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 36 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 37 | /* |
| 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 Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 43 | #define STORVSC_MAX_LUNS_PER_TARGET 64 |
Greg Kroah-Hartman | 9bcd786 | 2009-08-28 16:19:17 -0700 | [diff] [blame] | 44 | #define STORVSC_MAX_TARGETS 1 |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 45 | #define STORVSC_MAX_CHANNELS 1 |
| 46 | |
Nicolas Palix | 0b3f683 | 2009-07-29 14:10:19 +0200 | [diff] [blame] | 47 | struct hv_storvsc_request; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 48 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 49 | /* Matches Windows-end */ |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 50 | enum storvsc_request_type{ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 51 | WRITE_TYPE, |
| 52 | READ_TYPE, |
| 53 | UNKNOWN_TYPE, |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 54 | }; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 55 | |
Nicolas Palix | 0b3f683 | 2009-07-29 14:10:19 +0200 | [diff] [blame] | 56 | struct hv_storvsc_request { |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 57 | 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 Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 66 | |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 67 | unsigned char *sense_buffer; |
| 68 | u32 sense_buffer_size; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 69 | |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 70 | void *context; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 71 | |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 72 | void (*on_io_completion)(struct hv_storvsc_request *request); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 73 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 74 | /* This points to the memory after DataBuffer */ |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 75 | void *extension; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 76 | |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 77 | struct hv_multipage_buffer data_buffer; |
Nicolas Palix | 0b3f683 | 2009-07-29 14:10:19 +0200 | [diff] [blame] | 78 | }; |
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 | /* Represents the block vsc driver */ |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 81 | struct storvsc_driver_object { |
Greg Kroah-Hartman | 9bcd786 | 2009-08-28 16:19:17 -0700 | [diff] [blame] | 82 | /* Must be the first field */ |
| 83 | /* Which is a bug FIXME! */ |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 84 | struct hv_driver base; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 85 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 86 | /* Set by caller (in bytes) */ |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 87 | u32 ring_buffer_size; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 88 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 89 | /* Allocate this much private extension for each I/O request */ |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 90 | u32 request_ext_size; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 91 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 92 | /* Maximum # of requests in flight per channel/device */ |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 93 | u32 max_outstanding_req_per_channel; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 94 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 95 | /* Specific to this driver */ |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 96 | int (*on_io_request)(struct hv_device *device, |
| 97 | struct hv_storvsc_request *request); |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 98 | }; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 99 | |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 100 | struct storvsc_device_info { |
Hank Janssen | 8a04602 | 2010-12-06 12:26:45 -0800 | [diff] [blame] | 101 | unsigned int port_number; |
| 102 | unsigned char path_id; |
| 103 | unsigned char target_id; |
Greg Kroah-Hartman | 9f0c7d2 | 2009-08-28 16:20:07 -0700 | [diff] [blame] | 104 | }; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 105 | |
K. Y. Srinivasan | 036bbed | 2011-03-23 10:50:20 -0700 | [diff] [blame] | 106 | struct 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. Srinivasan | f24eeb0 | 2011-03-23 10:50:21 -0700 | [diff] [blame^] | 117 | /* A storvsc device is a device object that contains a vmbus channel */ |
| 118 | struct 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 | |
| 135 | /* LIST_ENTRY OutstandingRequestList; */ |
| 136 | /* HANDLE OutstandingRequestLock; */ |
| 137 | |
| 138 | /* Used for vsc/vsp channel reset process */ |
| 139 | struct storvsc_request_extension init_request; |
| 140 | struct storvsc_request_extension reset_request; |
| 141 | }; |
| 142 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 143 | /* Interface */ |
Hank Janssen | eb4f3e0 | 2010-12-06 12:26:46 -0800 | [diff] [blame] | 144 | int stor_vsc_initialize(struct hv_driver *driver); |
| 145 | int stor_vsc_on_host_reset(struct hv_device *device); |
| 146 | int blk_vsc_initialize(struct hv_driver *driver); |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 147 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 148 | #endif /* _STORVSC_API_H_ */ |