Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -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: |
Haiyang Zhang | d0e94d1 | 2009-11-23 17:00:22 +0000 | [diff] [blame] | 19 | * Haiyang Zhang <haiyangz@microsoft.com> |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 20 | * Hank Janssen <hjanssen@microsoft.com> |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #ifndef _NETVSC_H_ |
| 26 | #define _NETVSC_H_ |
| 27 | |
Bill Pemberton | d29274e | 2009-09-11 21:46:43 -0400 | [diff] [blame] | 28 | #include <linux/list.h> |
Greg Kroah-Hartman | 216260d | 2009-08-28 16:24:48 -0700 | [diff] [blame] | 29 | #include "VmbusPacketFormat.h" |
Greg Kroah-Hartman | 0197e34 | 2009-08-28 16:24:34 -0700 | [diff] [blame] | 30 | #include "VmbusChannelInterface.h" |
Greg Kroah-Hartman | cc21181 | 2009-08-28 16:23:17 -0700 | [diff] [blame] | 31 | #include "NetVscApi.h" |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 32 | |
Greg Kroah-Hartman | 64a1403 | 2009-08-28 16:21:33 -0700 | [diff] [blame] | 33 | |
| 34 | #define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF) |
| 35 | |
| 36 | #define NVSP_PROTOCOL_VERSION_1 2 |
| 37 | #define NVSP_MIN_PROTOCOL_VERSION NVSP_PROTOCOL_VERSION_1 |
| 38 | #define NVSP_MAX_PROTOCOL_VERSION NVSP_PROTOCOL_VERSION_1 |
| 39 | |
| 40 | enum { |
| 41 | NvspMessageTypeNone = 0, |
| 42 | |
| 43 | /* Init Messages */ |
| 44 | NvspMessageTypeInit = 1, |
| 45 | NvspMessageTypeInitComplete = 2, |
| 46 | |
| 47 | NvspVersionMessageStart = 100, |
| 48 | |
| 49 | /* Version 1 Messages */ |
| 50 | NvspMessage1TypeSendNdisVersion = NvspVersionMessageStart, |
| 51 | |
| 52 | NvspMessage1TypeSendReceiveBuffer, |
| 53 | NvspMessage1TypeSendReceiveBufferComplete, |
| 54 | NvspMessage1TypeRevokeReceiveBuffer, |
| 55 | |
| 56 | NvspMessage1TypeSendSendBuffer, |
| 57 | NvspMessage1TypeSendSendBufferComplete, |
| 58 | NvspMessage1TypeRevokeSendBuffer, |
| 59 | |
| 60 | NvspMessage1TypeSendRNDISPacket, |
| 61 | NvspMessage1TypeSendRNDISPacketComplete, |
| 62 | |
| 63 | /* |
| 64 | * This should be set to the number of messages for the version with |
| 65 | * the maximum number of messages. |
| 66 | */ |
| 67 | NvspNumMessagePerVersion = 9, |
| 68 | }; |
| 69 | |
| 70 | enum { |
| 71 | NvspStatusNone = 0, |
| 72 | NvspStatusSuccess, |
| 73 | NvspStatusFailure, |
| 74 | NvspStatusProtocolVersionRangeTooNew, |
| 75 | NvspStatusProtocolVersionRangeTooOld, |
| 76 | NvspStatusInvalidRndisPacket, |
| 77 | NvspStatusBusy, |
| 78 | NvspStatusMax, |
| 79 | }; |
| 80 | |
| 81 | struct nvsp_message_header { |
| 82 | u32 MessageType; |
| 83 | }; |
| 84 | |
| 85 | /* Init Messages */ |
| 86 | |
| 87 | /* |
| 88 | * This message is used by the VSC to initialize the channel after the channels |
| 89 | * has been opened. This message should never include anything other then |
| 90 | * versioning (i.e. this message will be the same for ever). |
| 91 | */ |
| 92 | struct nvsp_message_init { |
| 93 | u32 MinProtocolVersion; |
| 94 | u32 MaxProtocolVersion; |
| 95 | } __attribute__((packed)); |
| 96 | |
| 97 | /* |
| 98 | * This message is used by the VSP to complete the initialization of the |
| 99 | * channel. This message should never include anything other then versioning |
| 100 | * (i.e. this message will be the same for ever). |
| 101 | */ |
| 102 | struct nvsp_message_init_complete { |
| 103 | u32 NegotiatedProtocolVersion; |
| 104 | u32 MaximumMdlChainLength; |
| 105 | u32 Status; |
| 106 | } __attribute__((packed)); |
| 107 | |
| 108 | union nvsp_message_init_uber { |
| 109 | struct nvsp_message_init Init; |
| 110 | struct nvsp_message_init_complete InitComplete; |
| 111 | } __attribute__((packed)); |
| 112 | |
| 113 | /* Version 1 Messages */ |
| 114 | |
| 115 | /* |
| 116 | * This message is used by the VSC to send the NDIS version to the VSP. The VSP |
| 117 | * can use this information when handling OIDs sent by the VSC. |
| 118 | */ |
| 119 | struct nvsp_1_message_send_ndis_version { |
| 120 | u32 NdisMajorVersion; |
| 121 | u32 NdisMinorVersion; |
| 122 | } __attribute__((packed)); |
| 123 | |
| 124 | /* |
| 125 | * This message is used by the VSC to send a receive buffer to the VSP. The VSP |
| 126 | * can then use the receive buffer to send data to the VSC. |
| 127 | */ |
| 128 | struct nvsp_1_message_send_receive_buffer { |
| 129 | u32 GpadlHandle; |
| 130 | u16 Id; |
| 131 | } __attribute__((packed)); |
| 132 | |
| 133 | struct nvsp_1_receive_buffer_section { |
| 134 | u32 Offset; |
| 135 | u32 SubAllocationSize; |
| 136 | u32 NumSubAllocations; |
| 137 | u32 EndOffset; |
| 138 | } __attribute__((packed)); |
| 139 | |
| 140 | /* |
| 141 | * This message is used by the VSP to acknowledge a receive buffer send by the |
| 142 | * VSC. This message must be sent by the VSP before the VSP uses the receive |
| 143 | * buffer. |
| 144 | */ |
| 145 | struct nvsp_1_message_send_receive_buffer_complete { |
| 146 | u32 Status; |
| 147 | u32 NumSections; |
| 148 | |
| 149 | /* |
| 150 | * The receive buffer is split into two parts, a large suballocation |
| 151 | * section and a small suballocation section. These sections are then |
| 152 | * suballocated by a certain size. |
| 153 | */ |
| 154 | |
| 155 | /* |
| 156 | * For example, the following break up of the receive buffer has 6 |
| 157 | * large suballocations and 10 small suballocations. |
| 158 | */ |
| 159 | |
| 160 | /* |
| 161 | * | Large Section | | Small Section | |
| 162 | * ------------------------------------------------------------ |
| 163 | * | | | | | | | | | | | | | | | | | | |
| 164 | * | | |
| 165 | * LargeOffset SmallOffset |
| 166 | */ |
| 167 | |
| 168 | struct nvsp_1_receive_buffer_section Sections[1]; |
| 169 | } __attribute__((packed)); |
| 170 | |
| 171 | /* |
| 172 | * This message is sent by the VSC to revoke the receive buffer. After the VSP |
| 173 | * completes this transaction, the vsp should never use the receive buffer |
| 174 | * again. |
| 175 | */ |
| 176 | struct nvsp_1_message_revoke_receive_buffer { |
| 177 | u16 Id; |
| 178 | }; |
| 179 | |
| 180 | /* |
| 181 | * This message is used by the VSC to send a send buffer to the VSP. The VSC |
| 182 | * can then use the send buffer to send data to the VSP. |
| 183 | */ |
| 184 | struct nvsp_1_message_send_send_buffer { |
| 185 | u32 GpadlHandle; |
| 186 | u16 Id; |
| 187 | } __attribute__((packed)); |
| 188 | |
| 189 | /* |
| 190 | * This message is used by the VSP to acknowledge a send buffer sent by the |
| 191 | * VSC. This message must be sent by the VSP before the VSP uses the sent |
| 192 | * buffer. |
| 193 | */ |
| 194 | struct nvsp_1_message_send_send_buffer_complete { |
| 195 | u32 Status; |
| 196 | |
| 197 | /* |
| 198 | * The VSC gets to choose the size of the send buffer and the VSP gets |
| 199 | * to choose the sections size of the buffer. This was done to enable |
| 200 | * dynamic reconfigurations when the cost of GPA-direct buffers |
| 201 | * decreases. |
| 202 | */ |
| 203 | u32 SectionSize; |
| 204 | } __attribute__((packed)); |
| 205 | |
| 206 | /* |
| 207 | * This message is sent by the VSC to revoke the send buffer. After the VSP |
| 208 | * completes this transaction, the vsp should never use the send buffer again. |
| 209 | */ |
| 210 | struct nvsp_1_message_revoke_send_buffer { |
| 211 | u16 Id; |
| 212 | }; |
| 213 | |
| 214 | /* |
| 215 | * This message is used by both the VSP and the VSC to send a RNDIS message to |
| 216 | * the opposite channel endpoint. |
| 217 | */ |
| 218 | struct nvsp_1_message_send_rndis_packet { |
| 219 | /* |
| 220 | * This field is specified by RNIDS. They assume there's two different |
| 221 | * channels of communication. However, the Network VSP only has one. |
| 222 | * Therefore, the channel travels with the RNDIS packet. |
| 223 | */ |
| 224 | u32 ChannelType; |
| 225 | |
| 226 | /* |
| 227 | * This field is used to send part or all of the data through a send |
| 228 | * buffer. This values specifies an index into the send buffer. If the |
| 229 | * index is 0xFFFFFFFF, then the send buffer is not being used and all |
| 230 | * of the data was sent through other VMBus mechanisms. |
| 231 | */ |
| 232 | u32 SendBufferSectionIndex; |
| 233 | u32 SendBufferSectionSize; |
| 234 | } __attribute__((packed)); |
| 235 | |
| 236 | /* |
| 237 | * This message is used by both the VSP and the VSC to complete a RNDIS message |
| 238 | * to the opposite channel endpoint. At this point, the initiator of this |
| 239 | * message cannot use any resources associated with the original RNDIS packet. |
| 240 | */ |
| 241 | struct nvsp_1_message_send_rndis_packet_complete { |
| 242 | u32 Status; |
| 243 | }; |
| 244 | |
| 245 | union nvsp_1_message_uber { |
| 246 | struct nvsp_1_message_send_ndis_version SendNdisVersion; |
| 247 | |
| 248 | struct nvsp_1_message_send_receive_buffer SendReceiveBuffer; |
| 249 | struct nvsp_1_message_send_receive_buffer_complete |
| 250 | SendReceiveBufferComplete; |
| 251 | struct nvsp_1_message_revoke_receive_buffer RevokeReceiveBuffer; |
| 252 | |
| 253 | struct nvsp_1_message_send_send_buffer SendSendBuffer; |
| 254 | struct nvsp_1_message_send_send_buffer_complete SendSendBufferComplete; |
| 255 | struct nvsp_1_message_revoke_send_buffer RevokeSendBuffer; |
| 256 | |
| 257 | struct nvsp_1_message_send_rndis_packet SendRNDISPacket; |
| 258 | struct nvsp_1_message_send_rndis_packet_complete |
| 259 | SendRNDISPacketComplete; |
| 260 | } __attribute__((packed)); |
| 261 | |
| 262 | union nvsp_all_messages { |
| 263 | union nvsp_message_init_uber InitMessages; |
| 264 | union nvsp_1_message_uber Version1Messages; |
| 265 | } __attribute__((packed)); |
| 266 | |
| 267 | /* ALL Messages */ |
| 268 | struct nvsp_message { |
| 269 | struct nvsp_message_header Header; |
| 270 | union nvsp_all_messages Messages; |
| 271 | } __attribute__((packed)); |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
Greg Kroah-Hartman | b010e5a | 2009-08-18 15:18:36 -0700 | [diff] [blame] | 276 | /* #define NVSC_MIN_PROTOCOL_VERSION 1 */ |
| 277 | /* #define NVSC_MAX_PROTOCOL_VERSION 1 */ |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 278 | |
Greg Kroah-Hartman | b010e5a | 2009-08-18 15:18:36 -0700 | [diff] [blame] | 279 | #define NETVSC_SEND_BUFFER_SIZE (64*1024) /* 64K */ |
| 280 | #define NETVSC_SEND_BUFFER_ID 0xface |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 281 | |
| 282 | |
Greg Kroah-Hartman | b010e5a | 2009-08-18 15:18:36 -0700 | [diff] [blame] | 283 | #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024) /* 1MB */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 284 | |
Greg Kroah-Hartman | b010e5a | 2009-08-18 15:18:36 -0700 | [diff] [blame] | 285 | #define NETVSC_RECEIVE_BUFFER_ID 0xcafe |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 286 | |
Greg Kroah-Hartman | b010e5a | 2009-08-18 15:18:36 -0700 | [diff] [blame] | 287 | #define NETVSC_RECEIVE_SG_COUNT 1 |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 288 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 289 | /* Preallocated receive packets */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 290 | #define NETVSC_RECEIVE_PACKETLIST_COUNT 256 |
| 291 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 292 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 293 | /* Per netvsc channel-specific */ |
Greg Kroah-Hartman | ce9ea4c | 2009-09-02 10:35:56 -0700 | [diff] [blame] | 294 | struct netvsc_device { |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 295 | struct hv_device *Device; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 296 | |
Bill Pemberton | f488841 | 2009-07-29 17:00:12 -0400 | [diff] [blame] | 297 | atomic_t RefCount; |
| 298 | atomic_t NumOutstandingSends; |
Greg Kroah-Hartman | b010e5a | 2009-08-18 15:18:36 -0700 | [diff] [blame] | 299 | /* |
| 300 | * List of free preallocated hv_netvsc_packet to represent receive |
| 301 | * packet |
| 302 | */ |
Bill Pemberton | d29274e | 2009-09-11 21:46:43 -0400 | [diff] [blame] | 303 | struct list_head ReceivePacketList; |
Greg Kroah-Hartman | 6436873 | 2009-07-15 14:56:15 -0700 | [diff] [blame] | 304 | spinlock_t receive_packet_list_lock; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 305 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 306 | /* Send buffer allocated by us but manages by NetVSP */ |
Greg Kroah-Hartman | b010e5a | 2009-08-18 15:18:36 -0700 | [diff] [blame] | 307 | void *SendBuffer; |
| 308 | u32 SendBufferSize; |
| 309 | u32 SendBufferGpadlHandle; |
| 310 | u32 SendSectionSize; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 311 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 312 | /* Receive buffer allocated by us but manages by NetVSP */ |
Greg Kroah-Hartman | b010e5a | 2009-08-18 15:18:36 -0700 | [diff] [blame] | 313 | void *ReceiveBuffer; |
| 314 | u32 ReceiveBufferSize; |
| 315 | u32 ReceiveBufferGpadlHandle; |
| 316 | u32 ReceiveSectionCount; |
Greg Kroah-Hartman | 223c1aa | 2009-08-28 16:20:53 -0700 | [diff] [blame] | 317 | struct nvsp_1_receive_buffer_section *ReceiveSections; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 318 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 319 | /* Used for NetVSP initialization protocol */ |
Bill Pemberton | aedb444 | 2009-07-28 13:46:24 -0400 | [diff] [blame] | 320 | struct osd_waitevent *ChannelInitEvent; |
Greg Kroah-Hartman | 223c1aa | 2009-08-28 16:20:53 -0700 | [diff] [blame] | 321 | struct nvsp_message ChannelInitPacket; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 322 | |
Greg Kroah-Hartman | 223c1aa | 2009-08-28 16:20:53 -0700 | [diff] [blame] | 323 | struct nvsp_message RevokePacket; |
Greg Kroah-Hartman | b010e5a | 2009-08-18 15:18:36 -0700 | [diff] [blame] | 324 | /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 325 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 326 | /* Holds rndis device info */ |
Greg Kroah-Hartman | b010e5a | 2009-08-18 15:18:36 -0700 | [diff] [blame] | 327 | void *Extension; |
Bill Pemberton | d1af1db7 | 2009-07-27 16:47:44 -0400 | [diff] [blame] | 328 | }; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 329 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 330 | #endif /* _NETVSC_H_ */ |