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 | |
| 28 | #include "VmbusApi.h" |
| 29 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 30 | |
| 31 | /* Defines */ |
| 32 | |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 33 | |
| 34 | #define STORVSC_RING_BUFFER_SIZE 10*PAGE_SIZE |
| 35 | #define BLKVSC_RING_BUFFER_SIZE 20*PAGE_SIZE |
| 36 | |
| 37 | #define STORVSC_MAX_IO_REQUESTS 64 |
| 38 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 39 | /* |
| 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 Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 45 | |
| 46 | #define STORVSC_MAX_LUNS_PER_TARGET 64 |
| 47 | #define STORVSC_MAX_TARGETS 1 |
| 48 | #define STORVSC_MAX_CHANNELS 1 |
| 49 | |
| 50 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 51 | /* Fwd decl */ |
| 52 | |
| 53 | /* struct VMBUS_CHANNEL; */ |
Nicolas Palix | 0b3f683 | 2009-07-29 14:10:19 +0200 | [diff] [blame] | 54 | struct hv_storvsc_request; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 55 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 56 | |
| 57 | /* Data types */ |
| 58 | |
Nicolas Palix | 0b3f683 | 2009-07-29 14:10:19 +0200 | [diff] [blame] | 59 | typedef int (*PFN_ON_IO_REQUEST)(struct hv_device *Device, struct hv_storvsc_request *Request); |
| 60 | typedef void (*PFN_ON_IO_REQUEST_COMPLTN)(struct hv_storvsc_request *Request); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 61 | |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 62 | typedef int (*PFN_ON_HOST_RESET)(struct hv_device *Device); |
| 63 | typedef void (*PFN_ON_HOST_RESCAN)(struct hv_device *Device); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 64 | |
| 65 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 66 | /* Matches Windows-end */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 67 | typedef enum _STORVSC_REQUEST_TYPE{ |
| 68 | WRITE_TYPE, |
| 69 | READ_TYPE, |
| 70 | UNKNOWN_TYPE, |
| 71 | } STORVSC_REQUEST_TYPE; |
| 72 | |
| 73 | |
Nicolas Palix | 0b3f683 | 2009-07-29 14:10:19 +0200 | [diff] [blame] | 74 | struct hv_storvsc_request { |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 75 | STORVSC_REQUEST_TYPE Type; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 76 | u32 Host; |
| 77 | u32 Bus; |
| 78 | u32 TargetId; |
| 79 | u32 LunId; |
Greg Kroah-Hartman | 5654e93 | 2009-07-14 15:08:20 -0700 | [diff] [blame] | 80 | u8 * Cdb; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 81 | u32 CdbLen; |
| 82 | u32 Status; |
| 83 | u32 BytesXfer; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 84 | |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 85 | unsigned char* SenseBuffer; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 86 | u32 SenseBufferSize; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 87 | |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 88 | void * Context; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 89 | |
| 90 | PFN_ON_IO_REQUEST_COMPLTN OnIOCompletion; |
| 91 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 92 | /* This points to the memory after DataBuffer */ |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 93 | void * Extension; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 94 | |
| 95 | MULTIPAGE_BUFFER DataBuffer; |
Nicolas Palix | 0b3f683 | 2009-07-29 14:10:19 +0200 | [diff] [blame] | 96 | }; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 97 | |
| 98 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 99 | /* Represents the block vsc driver */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 100 | typedef struct _STORVSC_DRIVER_OBJECT { |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 101 | struct hv_driver Base; /* Must be the first field */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 102 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 103 | /* Set by caller (in bytes) */ |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 104 | u32 RingBufferSize; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 105 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 106 | /* Allocate this much private extension for each I/O request */ |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 107 | u32 RequestExtSize; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 108 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 109 | /* Maximum # of requests in flight per channel/device */ |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 110 | u32 MaxOutstandingRequestsPerChannel; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 111 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 112 | /* Set by the caller to allow us to re-enumerate the bus on the host */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 113 | PFN_ON_HOST_RESCAN OnHostRescan; |
| 114 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 115 | /* Specific to this driver */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 116 | PFN_ON_IO_REQUEST OnIORequest; |
| 117 | PFN_ON_HOST_RESET OnHostReset; |
| 118 | |
| 119 | } STORVSC_DRIVER_OBJECT; |
| 120 | |
| 121 | typedef struct _STORVSC_DEVICE_INFO { |
Greg Kroah-Hartman | 3abcbc4 | 2009-07-14 15:13:46 -0700 | [diff] [blame] | 122 | unsigned int PortNumber; |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 123 | unsigned char PathId; |
| 124 | unsigned char TargetId; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 125 | } STORVSC_DEVICE_INFO; |
| 126 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 127 | |
| 128 | /* Interface */ |
| 129 | |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 130 | int |
| 131 | StorVscInitialize( |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 132 | struct hv_driver *Driver |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 133 | ); |
| 134 | |
| 135 | int |
| 136 | BlkVscInitialize( |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 137 | struct hv_driver *Driver |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 138 | ); |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 139 | #endif /* _STORVSC_API_H_ */ |