c6ddf6cfe423b09f81cadcae7eeb24dfea61d66c
[pandora-kernel.git] / drivers / staging / hv / netvsc.h
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 _NETVSC_H_
26 #define _NETVSC_H_
27
28 #include <linux/list.h>
29 #include "hyperv.h"
30
31
32 #define NVSP_INVALID_PROTOCOL_VERSION   ((u32)0xFFFFFFFF)
33
34 #define NVSP_PROTOCOL_VERSION_1         2
35 #define NVSP_MIN_PROTOCOL_VERSION       NVSP_PROTOCOL_VERSION_1
36 #define NVSP_MAX_PROTOCOL_VERSION       NVSP_PROTOCOL_VERSION_1
37
38 enum {
39         NVSP_MSG_TYPE_NONE = 0,
40
41         /* Init Messages */
42         NVSP_MSG_TYPE_INIT                      = 1,
43         NVSP_MSG_TYPE_INIT_COMPLETE             = 2,
44
45         NVSP_VERSION_MSG_START                  = 100,
46
47         /* Version 1 Messages */
48         NVSP_MSG1_TYPE_SEND_NDIS_VER            = NVSP_VERSION_MSG_START,
49
50         NVSP_MSG1_TYPE_SEND_RECV_BUF,
51         NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE,
52         NVSP_MSG1_TYPE_REVOKE_RECV_BUF,
53
54         NVSP_MSG1_TYPE_SEND_SEND_BUF,
55         NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE,
56         NVSP_MSG1_TYPE_REVOKE_SEND_BUF,
57
58         NVSP_MSG1_TYPE_SEND_RNDIS_PKT,
59         NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE,
60
61         /*
62          * This should be set to the number of messages for the version with
63          * the maximum number of messages.
64          */
65         NVSP_NUM_MSG_PER_VERSION                = 9,
66 };
67
68 enum {
69         NVSP_STAT_NONE = 0,
70         NVSP_STAT_SUCCESS,
71         NVSP_STAT_FAIL,
72         NVSP_STAT_PROTOCOL_TOO_NEW,
73         NVSP_STAT_PROTOCOL_TOO_OLD,
74         NVSP_STAT_INVALID_RNDIS_PKT,
75         NVSP_STAT_BUSY,
76         NVSP_STAT_MAX,
77 };
78
79 struct nvsp_message_header {
80         u32 msg_type;
81 };
82
83 /* Init Messages */
84
85 /*
86  * This message is used by the VSC to initialize the channel after the channels
87  * has been opened. This message should never include anything other then
88  * versioning (i.e. this message will be the same for ever).
89  */
90 struct nvsp_message_init {
91         u32 min_protocol_ver;
92         u32 max_protocol_ver;
93 } __packed;
94
95 /*
96  * This message is used by the VSP to complete the initialization of the
97  * channel. This message should never include anything other then versioning
98  * (i.e. this message will be the same for ever).
99  */
100 struct nvsp_message_init_complete {
101         u32 negotiated_protocol_ver;
102         u32 max_mdl_chain_len;
103         u32 status;
104 } __packed;
105
106 union nvsp_message_init_uber {
107         struct nvsp_message_init init;
108         struct nvsp_message_init_complete init_complete;
109 } __packed;
110
111 /* Version 1 Messages */
112
113 /*
114  * This message is used by the VSC to send the NDIS version to the VSP. The VSP
115  * can use this information when handling OIDs sent by the VSC.
116  */
117 struct nvsp_1_message_send_ndis_version {
118         u32 ndis_major_ver;
119         u32 ndis_minor_ver;
120 } __packed;
121
122 /*
123  * This message is used by the VSC to send a receive buffer to the VSP. The VSP
124  * can then use the receive buffer to send data to the VSC.
125  */
126 struct nvsp_1_message_send_receive_buffer {
127         u32 gpadl_handle;
128         u16 id;
129 } __packed;
130
131 struct nvsp_1_receive_buffer_section {
132         u32 offset;
133         u32 sub_alloc_size;
134         u32 num_sub_allocs;
135         u32 end_offset;
136 } __packed;
137
138 /*
139  * This message is used by the VSP to acknowledge a receive buffer send by the
140  * VSC. This message must be sent by the VSP before the VSP uses the receive
141  * buffer.
142  */
143 struct nvsp_1_message_send_receive_buffer_complete {
144         u32 status;
145         u32 num_sections;
146
147         /*
148          * The receive buffer is split into two parts, a large suballocation
149          * section and a small suballocation section. These sections are then
150          * suballocated by a certain size.
151          */
152
153         /*
154          * For example, the following break up of the receive buffer has 6
155          * large suballocations and 10 small suballocations.
156          */
157
158         /*
159          * |            Large Section          |  |   Small Section   |
160          * ------------------------------------------------------------
161          * |     |     |     |     |     |     |  | | | | | | | | | | |
162          * |                                      |
163          *  LargeOffset                            SmallOffset
164          */
165
166         struct nvsp_1_receive_buffer_section sections[1];
167 } __packed;
168
169 /*
170  * This message is sent by the VSC to revoke the receive buffer.  After the VSP
171  * completes this transaction, the vsp should never use the receive buffer
172  * again.
173  */
174 struct nvsp_1_message_revoke_receive_buffer {
175         u16 id;
176 };
177
178 /*
179  * This message is used by the VSC to send a send buffer to the VSP. The VSC
180  * can then use the send buffer to send data to the VSP.
181  */
182 struct nvsp_1_message_send_send_buffer {
183         u32 gpadl_handle;
184         u16 id;
185 } __packed;
186
187 /*
188  * This message is used by the VSP to acknowledge a send buffer sent by the
189  * VSC. This message must be sent by the VSP before the VSP uses the sent
190  * buffer.
191  */
192 struct nvsp_1_message_send_send_buffer_complete {
193         u32 status;
194
195         /*
196          * The VSC gets to choose the size of the send buffer and the VSP gets
197          * to choose the sections size of the buffer.  This was done to enable
198          * dynamic reconfigurations when the cost of GPA-direct buffers
199          * decreases.
200          */
201         u32 section_size;
202 } __packed;
203
204 /*
205  * This message is sent by the VSC to revoke the send buffer.  After the VSP
206  * completes this transaction, the vsp should never use the send buffer again.
207  */
208 struct nvsp_1_message_revoke_send_buffer {
209         u16 id;
210 };
211
212 /*
213  * This message is used by both the VSP and the VSC to send a RNDIS message to
214  * the opposite channel endpoint.
215  */
216 struct nvsp_1_message_send_rndis_packet {
217         /*
218          * This field is specified by RNIDS. They assume there's two different
219          * channels of communication. However, the Network VSP only has one.
220          * Therefore, the channel travels with the RNDIS packet.
221          */
222         u32 channel_type;
223
224         /*
225          * This field is used to send part or all of the data through a send
226          * buffer. This values specifies an index into the send buffer. If the
227          * index is 0xFFFFFFFF, then the send buffer is not being used and all
228          * of the data was sent through other VMBus mechanisms.
229          */
230         u32 send_buf_section_index;
231         u32 send_buf_section_size;
232 } __packed;
233
234 /*
235  * This message is used by both the VSP and the VSC to complete a RNDIS message
236  * to the opposite channel endpoint. At this point, the initiator of this
237  * message cannot use any resources associated with the original RNDIS packet.
238  */
239 struct nvsp_1_message_send_rndis_packet_complete {
240         u32 status;
241 };
242
243 union nvsp_1_message_uber {
244         struct nvsp_1_message_send_ndis_version send_ndis_ver;
245
246         struct nvsp_1_message_send_receive_buffer send_recv_buf;
247         struct nvsp_1_message_send_receive_buffer_complete
248                                                 send_recv_buf_complete;
249         struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf;
250
251         struct nvsp_1_message_send_send_buffer send_send_buf;
252         struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete;
253         struct nvsp_1_message_revoke_send_buffer revoke_send_buf;
254
255         struct nvsp_1_message_send_rndis_packet send_rndis_pkt;
256         struct nvsp_1_message_send_rndis_packet_complete
257                                                 send_rndis_pkt_complete;
258 } __packed;
259
260 union nvsp_all_messages {
261         union nvsp_message_init_uber init_msg;
262         union nvsp_1_message_uber v1_msg;
263 } __packed;
264
265 /* ALL Messages */
266 struct nvsp_message {
267         struct nvsp_message_header hdr;
268         union nvsp_all_messages msg;
269 } __packed;
270
271
272
273
274 /* #define NVSC_MIN_PROTOCOL_VERSION            1 */
275 /* #define NVSC_MAX_PROTOCOL_VERSION            1 */
276
277 #define NETVSC_SEND_BUFFER_SIZE                 (64*1024)       /* 64K */
278 #define NETVSC_SEND_BUFFER_ID                   0xface
279
280
281 #define NETVSC_RECEIVE_BUFFER_SIZE              (1024*1024)     /* 1MB */
282
283 #define NETVSC_RECEIVE_BUFFER_ID                0xcafe
284
285 #define NETVSC_RECEIVE_SG_COUNT                 1
286
287 /* Preallocated receive packets */
288 #define NETVSC_RECEIVE_PACKETLIST_COUNT         256
289
290 #define NETVSC_PACKET_SIZE                      2048
291
292 /* Per netvsc channel-specific */
293 struct netvsc_device {
294         struct hv_device *dev;
295
296         atomic_t refcnt;
297         atomic_t num_outstanding_sends;
298         /*
299          * List of free preallocated hv_netvsc_packet to represent receive
300          * packet
301          */
302         struct list_head recv_pkt_list;
303         spinlock_t recv_pkt_list_lock;
304
305         /* Send buffer allocated by us but manages by NetVSP */
306         void *send_buf;
307         u32 send_buf_size;
308         u32 send_buf_gpadl_handle;
309         u32 send_section_size;
310
311         /* Receive buffer allocated by us but manages by NetVSP */
312         void *recv_buf;
313         u32 recv_buf_size;
314         u32 recv_buf_gpadl_handle;
315         u32 recv_section_cnt;
316         struct nvsp_1_receive_buffer_section *recv_section;
317
318         /* Used for NetVSP initialization protocol */
319         struct completion channel_init_wait;
320         struct nvsp_message channel_init_pkt;
321
322         struct nvsp_message revoke_packet;
323         /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
324
325         /* Holds rndis device info */
326         void *extension;
327 };
328
329 #endif /* _NETVSC_H_ */