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: | |
d0e94d17 | 19 | * Haiyang Zhang <haiyangz@microsoft.com> |
fceaf24a HJ |
20 | * Hank Janssen <hjanssen@microsoft.com> |
21 | * | |
22 | */ | |
23 | ||
24 | ||
25 | #ifndef _NETVSC_H_ | |
26 | #define _NETVSC_H_ | |
27 | ||
d29274ef | 28 | #include <linux/list.h> |
f8e5add2 | 29 | #include "vmbus_packet_format.h" |
0e0ab5f5 | 30 | #include "vmbus_channel_interface.h" |
a82c7a2a | 31 | #include "netvsc_api.h" |
fceaf24a | 32 | |
64a1403d GKH |
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 { | |
53d21fdb | 41 | NVSP_MSG_TYPE_NONE = 0, |
64a1403d GKH |
42 | |
43 | /* Init Messages */ | |
53d21fdb HZ |
44 | NVSP_MSG_TYPE_INIT = 1, |
45 | NVSP_MSG_TYPE_INIT_COMPLETE = 2, | |
64a1403d | 46 | |
53d21fdb | 47 | NVSP_VERSION_MSG_START = 100, |
64a1403d GKH |
48 | |
49 | /* Version 1 Messages */ | |
53d21fdb | 50 | NVSP_MSG1_TYPE_SEND_NDIS_VER = NVSP_VERSION_MSG_START, |
64a1403d | 51 | |
53d21fdb HZ |
52 | NVSP_MSG1_TYPE_SEND_RECV_BUF, |
53 | NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE, | |
54 | NVSP_MSG1_TYPE_REVOKE_RECV_BUF, | |
64a1403d | 55 | |
53d21fdb HZ |
56 | NVSP_MSG1_TYPE_SEND_SEND_BUF, |
57 | NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE, | |
58 | NVSP_MSG1_TYPE_REVOKE_SEND_BUF, | |
64a1403d | 59 | |
53d21fdb HZ |
60 | NVSP_MSG1_TYPE_SEND_RNDIS_PKT, |
61 | NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE, | |
64a1403d GKH |
62 | |
63 | /* | |
64 | * This should be set to the number of messages for the version with | |
65 | * the maximum number of messages. | |
66 | */ | |
53d21fdb | 67 | NVSP_NUM_MSG_PER_VERSION = 9, |
64a1403d GKH |
68 | }; |
69 | ||
70 | enum { | |
53d21fdb HZ |
71 | NVSP_STAT_NONE = 0, |
72 | NVSP_STAT_SUCCESS, | |
73 | NVSP_STAT_FAIL, | |
74 | NVSP_STAT_PROTOCOL_TOO_NEW, | |
75 | NVSP_STAT_PROTOCOL_TOO_OLD, | |
76 | NVSP_STAT_INVALID_RNDIS_PKT, | |
77 | NVSP_STAT_BUSY, | |
78 | NVSP_STAT_MAX, | |
64a1403d GKH |
79 | }; |
80 | ||
81 | struct nvsp_message_header { | |
53d21fdb | 82 | u32 msg_type; |
64a1403d GKH |
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 { | |
53d21fdb HZ |
93 | u32 min_protocol_ver; |
94 | u32 max_protocol_ver; | |
3c4a9413 | 95 | } __packed; |
64a1403d GKH |
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 { | |
53d21fdb HZ |
103 | u32 negotiated_protocol_ver; |
104 | u32 max_mdl_chain_len; | |
105 | u32 status; | |
3c4a9413 | 106 | } __packed; |
64a1403d GKH |
107 | |
108 | union nvsp_message_init_uber { | |
53d21fdb HZ |
109 | struct nvsp_message_init init; |
110 | struct nvsp_message_init_complete init_complete; | |
3c4a9413 | 111 | } __packed; |
64a1403d GKH |
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 { | |
53d21fdb HZ |
120 | u32 ndis_major_ver; |
121 | u32 ndis_minor_ver; | |
3c4a9413 | 122 | } __packed; |
64a1403d GKH |
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 { | |
53d21fdb HZ |
129 | u32 gpadl_handle; |
130 | u16 id; | |
3c4a9413 | 131 | } __packed; |
64a1403d GKH |
132 | |
133 | struct nvsp_1_receive_buffer_section { | |
53d21fdb HZ |
134 | u32 offset; |
135 | u32 sub_alloc_size; | |
136 | u32 num_sub_allocs; | |
137 | u32 end_offset; | |
3c4a9413 | 138 | } __packed; |
64a1403d GKH |
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 { | |
53d21fdb HZ |
146 | u32 status; |
147 | u32 num_sections; | |
64a1403d GKH |
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 | ||
53d21fdb | 168 | struct nvsp_1_receive_buffer_section sections[1]; |
3c4a9413 | 169 | } __packed; |
64a1403d GKH |
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 { | |
53d21fdb | 177 | u16 id; |
64a1403d GKH |
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 { | |
53d21fdb HZ |
185 | u32 gpadl_handle; |
186 | u16 id; | |
3c4a9413 | 187 | } __packed; |
64a1403d GKH |
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 { | |
53d21fdb | 195 | u32 status; |
64a1403d GKH |
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 | */ | |
53d21fdb | 203 | u32 section_size; |
3c4a9413 | 204 | } __packed; |
64a1403d GKH |
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 { | |
53d21fdb | 211 | u16 id; |
64a1403d GKH |
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 | */ | |
53d21fdb | 224 | u32 channel_type; |
64a1403d GKH |
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 | */ | |
53d21fdb HZ |
232 | u32 send_buf_section_index; |
233 | u32 send_buf_section_size; | |
3c4a9413 | 234 | } __packed; |
64a1403d GKH |
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 { | |
53d21fdb | 242 | u32 status; |
64a1403d GKH |
243 | }; |
244 | ||
245 | union nvsp_1_message_uber { | |
53d21fdb | 246 | struct nvsp_1_message_send_ndis_version send_ndis_ver; |
64a1403d | 247 | |
53d21fdb | 248 | struct nvsp_1_message_send_receive_buffer send_recv_buf; |
64a1403d | 249 | struct nvsp_1_message_send_receive_buffer_complete |
53d21fdb HZ |
250 | send_recv_buf_complete; |
251 | struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf; | |
64a1403d | 252 | |
53d21fdb HZ |
253 | struct nvsp_1_message_send_send_buffer send_send_buf; |
254 | struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete; | |
255 | struct nvsp_1_message_revoke_send_buffer revoke_send_buf; | |
64a1403d | 256 | |
53d21fdb | 257 | struct nvsp_1_message_send_rndis_packet send_rndis_pkt; |
64a1403d | 258 | struct nvsp_1_message_send_rndis_packet_complete |
53d21fdb | 259 | send_rndis_pkt_complete; |
3c4a9413 | 260 | } __packed; |
64a1403d GKH |
261 | |
262 | union nvsp_all_messages { | |
53d21fdb HZ |
263 | union nvsp_message_init_uber init_msg; |
264 | union nvsp_1_message_uber v1_msg; | |
3c4a9413 | 265 | } __packed; |
64a1403d GKH |
266 | |
267 | /* ALL Messages */ | |
268 | struct nvsp_message { | |
53d21fdb HZ |
269 | struct nvsp_message_header hdr; |
270 | union nvsp_all_messages msg; | |
3c4a9413 | 271 | } __packed; |
64a1403d GKH |
272 | |
273 | ||
274 | ||
275 | ||
b010e5a7 GKH |
276 | /* #define NVSC_MIN_PROTOCOL_VERSION 1 */ |
277 | /* #define NVSC_MAX_PROTOCOL_VERSION 1 */ | |
454f18a9 | 278 | |
b010e5a7 GKH |
279 | #define NETVSC_SEND_BUFFER_SIZE (64*1024) /* 64K */ |
280 | #define NETVSC_SEND_BUFFER_ID 0xface | |
454f18a9 | 281 | |
fceaf24a | 282 | |
b010e5a7 | 283 | #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024) /* 1MB */ |
fceaf24a | 284 | |
b010e5a7 | 285 | #define NETVSC_RECEIVE_BUFFER_ID 0xcafe |
fceaf24a | 286 | |
b010e5a7 | 287 | #define NETVSC_RECEIVE_SG_COUNT 1 |
fceaf24a | 288 | |
454f18a9 | 289 | /* Preallocated receive packets */ |
fceaf24a HJ |
290 | #define NETVSC_RECEIVE_PACKETLIST_COUNT 256 |
291 | ||
c6fcf0ba | 292 | #define NETVSC_PACKET_SIZE 2048 |
fceaf24a | 293 | |
454f18a9 | 294 | /* Per netvsc channel-specific */ |
ce9ea4cf | 295 | struct netvsc_device { |
53d21fdb | 296 | struct hv_device *dev; |
fceaf24a | 297 | |
53d21fdb HZ |
298 | atomic_t refcnt; |
299 | atomic_t num_outstanding_sends; | |
b010e5a7 GKH |
300 | /* |
301 | * List of free preallocated hv_netvsc_packet to represent receive | |
302 | * packet | |
303 | */ | |
53d21fdb HZ |
304 | struct list_head recv_pkt_list; |
305 | spinlock_t recv_pkt_list_lock; | |
fceaf24a | 306 | |
454f18a9 | 307 | /* Send buffer allocated by us but manages by NetVSP */ |
53d21fdb HZ |
308 | void *send_buf; |
309 | u32 send_buf_size; | |
310 | u32 send_buf_gpadl_handle; | |
311 | u32 send_section_size; | |
fceaf24a | 312 | |
454f18a9 | 313 | /* Receive buffer allocated by us but manages by NetVSP */ |
53d21fdb HZ |
314 | void *recv_buf; |
315 | u32 recv_buf_size; | |
316 | u32 recv_buf_gpadl_handle; | |
317 | u32 recv_section_cnt; | |
318 | struct nvsp_1_receive_buffer_section *recv_section; | |
fceaf24a | 319 | |
454f18a9 | 320 | /* Used for NetVSP initialization protocol */ |
0c3b7b2f S |
321 | int wait_condition; |
322 | wait_queue_head_t channel_init_wait; | |
53d21fdb | 323 | struct nvsp_message channel_init_pkt; |
fceaf24a | 324 | |
53d21fdb | 325 | struct nvsp_message revoke_packet; |
b010e5a7 | 326 | /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */ |
fceaf24a | 327 | |
454f18a9 | 328 | /* Holds rndis device info */ |
53d21fdb | 329 | void *extension; |
d1af1db7 | 330 | }; |
fceaf24a | 331 | |
454f18a9 | 332 | #endif /* _NETVSC_H_ */ |