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