Commit | Line | Data |
---|---|---|
fceaf24a HJ |
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 | ||
216260d8 | 27 | #include "VmbusPacketFormat.h" |
0197e34c | 28 | #include "VmbusChannelInterface.h" |
0b43c180 | 29 | #include "List.h" |
cc211812 | 30 | #include "NetVscApi.h" |
fceaf24a | 31 | |
64a1403d GKH |
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 | ||
b010e5a7 GKH |
275 | /* #define NVSC_MIN_PROTOCOL_VERSION 1 */ |
276 | /* #define NVSC_MAX_PROTOCOL_VERSION 1 */ | |
454f18a9 | 277 | |
b010e5a7 GKH |
278 | #define NETVSC_SEND_BUFFER_SIZE (64*1024) /* 64K */ |
279 | #define NETVSC_SEND_BUFFER_ID 0xface | |
454f18a9 | 280 | |
fceaf24a | 281 | |
b010e5a7 | 282 | #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024) /* 1MB */ |
fceaf24a | 283 | |
b010e5a7 | 284 | #define NETVSC_RECEIVE_BUFFER_ID 0xcafe |
fceaf24a | 285 | |
b010e5a7 | 286 | #define NETVSC_RECEIVE_SG_COUNT 1 |
fceaf24a | 287 | |
454f18a9 | 288 | /* Preallocated receive packets */ |
fceaf24a HJ |
289 | #define NETVSC_RECEIVE_PACKETLIST_COUNT 256 |
290 | ||
fceaf24a | 291 | |
454f18a9 | 292 | /* Per netvsc channel-specific */ |
ce9ea4cf | 293 | struct netvsc_device { |
3d3b5518 | 294 | struct hv_device *Device; |
fceaf24a | 295 | |
f4888417 BP |
296 | atomic_t RefCount; |
297 | atomic_t NumOutstandingSends; | |
b010e5a7 GKH |
298 | /* |
299 | * List of free preallocated hv_netvsc_packet to represent receive | |
300 | * packet | |
301 | */ | |
302 | LIST_ENTRY ReceivePacketList; | |
6436873a | 303 | spinlock_t receive_packet_list_lock; |
fceaf24a | 304 | |
454f18a9 | 305 | /* Send buffer allocated by us but manages by NetVSP */ |
b010e5a7 GKH |
306 | void *SendBuffer; |
307 | u32 SendBufferSize; | |
308 | u32 SendBufferGpadlHandle; | |
309 | u32 SendSectionSize; | |
fceaf24a | 310 | |
454f18a9 | 311 | /* Receive buffer allocated by us but manages by NetVSP */ |
b010e5a7 GKH |
312 | void *ReceiveBuffer; |
313 | u32 ReceiveBufferSize; | |
314 | u32 ReceiveBufferGpadlHandle; | |
315 | u32 ReceiveSectionCount; | |
223c1aa6 | 316 | struct nvsp_1_receive_buffer_section *ReceiveSections; |
fceaf24a | 317 | |
454f18a9 | 318 | /* Used for NetVSP initialization protocol */ |
aedb444a | 319 | struct osd_waitevent *ChannelInitEvent; |
223c1aa6 | 320 | struct nvsp_message ChannelInitPacket; |
fceaf24a | 321 | |
223c1aa6 | 322 | struct nvsp_message RevokePacket; |
b010e5a7 | 323 | /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */ |
fceaf24a | 324 | |
454f18a9 | 325 | /* Holds rndis device info */ |
b010e5a7 | 326 | void *Extension; |
d1af1db7 | 327 | }; |
fceaf24a | 328 | |
454f18a9 | 329 | #endif /* _NETVSC_H_ */ |