Staging: hv: netvsc: Move the contents of netvsc.h to hyperv_net.h
[deliverable/linux.git] / drivers / staging / hv / hyperv_net.h
CommitLineData
5ca7252a
S
1/*
2 *
3 * Copyright (c) 2011, 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 * K. Y. Srinivasan <kys@microsoft.com>
22 *
23 */
24
25#ifndef _HYPERV_NET_H
26#define _HYPERV_NET_H
27
41308862
S
28#include "hyperv.h"
29
30/* Fwd declaration */
31struct hv_netvsc_packet;
32
33/* Represent the xfer page packet which contains 1 or more netvsc packet */
34struct xferpage_packet {
35 struct list_head list_ent;
36
37 /* # of netvsc packets this xfer packet contains */
38 u32 count;
39};
40
41/* The number of pages which are enough to cover jumbo frame buffer. */
42#define NETVSC_PACKET_MAXPAGE 4
43
44/*
45 * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
46 * within the RNDIS
47 */
48struct hv_netvsc_packet {
49 /* Bookkeeping stuff */
50 struct list_head list_ent;
51
52 struct hv_device *device;
53 bool is_data_pkt;
54
55 /*
56 * Valid only for receives when we break a xfer page packet
57 * into multiple netvsc packets
58 */
59 struct xferpage_packet *xfer_page_pkt;
60
61 union {
62 struct {
63 u64 recv_completion_tid;
64 void *recv_completion_ctx;
65 void (*recv_completion)(void *context);
66 } recv;
67 struct {
68 u64 send_completion_tid;
69 void *send_completion_ctx;
70 void (*send_completion)(void *context);
71 } send;
72 } completion;
73
74 /* This points to the memory after page_buf */
75 void *extension;
76
77 u32 total_data_buflen;
78 /* Points to the send/receive buffer where the ethernet frame is */
79 u32 page_buf_cnt;
80 struct hv_page_buffer page_buf[NETVSC_PACKET_MAXPAGE];
81};
82
83/* Represents the net vsc driver */
84struct netvsc_driver {
85 /* Must be the first field */
86 /* Which is a bug FIXME! */
87 struct hv_driver base;
88
89 u32 ring_buf_size;
90 u32 req_ext_size;
91
92 /*
93 * This is set by the caller to allow us to callback when we
94 * receive a packet from the "wire"
95 */
96 int (*recv_cb)(struct hv_device *dev,
97 struct hv_netvsc_packet *packet);
98 void (*link_status_change)(struct hv_device *dev, u32 status);
99
100 /* Specific to this driver */
101 int (*send)(struct hv_device *dev, struct hv_netvsc_packet *packet);
102
103 void *ctx;
104};
105
106static inline
107struct netvsc_driver *drv_to_netvscdrv(struct device_driver *d)
108{
109 struct hv_driver *hvdrv = drv_to_hv_drv(d);
110 return container_of(hvdrv, struct netvsc_driver, base);
111}
112
113struct netvsc_device_info {
114 unsigned char mac_adr[6];
115 bool link_state; /* 0 - link up, 1 - link down */
116};
117
118/* Interface */
119int netvsc_device_add(struct hv_device *device, void *additional_info);
120int netvsc_device_remove(struct hv_device *device);
121int netvsc_initialize(struct hv_driver *drv);
122int rndis_filter_open(struct hv_device *dev);
123int rndis_filter_close(struct hv_device *dev);
124int rndis_filte_device_add(struct hv_device *dev,
125 void *additional_info);
126int rndis_filter_device_remove(struct hv_device *dev);
127
128
52584904
S
129
130#include <linux/list.h>
131#include "hyperv.h"
132
133
134#define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
135
136#define NVSP_PROTOCOL_VERSION_1 2
137#define NVSP_MIN_PROTOCOL_VERSION NVSP_PROTOCOL_VERSION_1
138#define NVSP_MAX_PROTOCOL_VERSION NVSP_PROTOCOL_VERSION_1
139
140enum {
141 NVSP_MSG_TYPE_NONE = 0,
142
143 /* Init Messages */
144 NVSP_MSG_TYPE_INIT = 1,
145 NVSP_MSG_TYPE_INIT_COMPLETE = 2,
146
147 NVSP_VERSION_MSG_START = 100,
148
149 /* Version 1 Messages */
150 NVSP_MSG1_TYPE_SEND_NDIS_VER = NVSP_VERSION_MSG_START,
151
152 NVSP_MSG1_TYPE_SEND_RECV_BUF,
153 NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE,
154 NVSP_MSG1_TYPE_REVOKE_RECV_BUF,
155
156 NVSP_MSG1_TYPE_SEND_SEND_BUF,
157 NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE,
158 NVSP_MSG1_TYPE_REVOKE_SEND_BUF,
159
160 NVSP_MSG1_TYPE_SEND_RNDIS_PKT,
161 NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE,
162
163 /*
164 * This should be set to the number of messages for the version with
165 * the maximum number of messages.
166 */
167 NVSP_NUM_MSG_PER_VERSION = 9,
168};
169
170enum {
171 NVSP_STAT_NONE = 0,
172 NVSP_STAT_SUCCESS,
173 NVSP_STAT_FAIL,
174 NVSP_STAT_PROTOCOL_TOO_NEW,
175 NVSP_STAT_PROTOCOL_TOO_OLD,
176 NVSP_STAT_INVALID_RNDIS_PKT,
177 NVSP_STAT_BUSY,
178 NVSP_STAT_MAX,
179};
180
181struct nvsp_message_header {
182 u32 msg_type;
183};
184
185/* Init Messages */
186
187/*
188 * This message is used by the VSC to initialize the channel after the channels
189 * has been opened. This message should never include anything other then
190 * versioning (i.e. this message will be the same for ever).
191 */
192struct nvsp_message_init {
193 u32 min_protocol_ver;
194 u32 max_protocol_ver;
195} __packed;
196
197/*
198 * This message is used by the VSP to complete the initialization of the
199 * channel. This message should never include anything other then versioning
200 * (i.e. this message will be the same for ever).
201 */
202struct nvsp_message_init_complete {
203 u32 negotiated_protocol_ver;
204 u32 max_mdl_chain_len;
205 u32 status;
206} __packed;
207
208union nvsp_message_init_uber {
209 struct nvsp_message_init init;
210 struct nvsp_message_init_complete init_complete;
211} __packed;
212
213/* Version 1 Messages */
214
215/*
216 * This message is used by the VSC to send the NDIS version to the VSP. The VSP
217 * can use this information when handling OIDs sent by the VSC.
218 */
219struct nvsp_1_message_send_ndis_version {
220 u32 ndis_major_ver;
221 u32 ndis_minor_ver;
222} __packed;
223
224/*
225 * This message is used by the VSC to send a receive buffer to the VSP. The VSP
226 * can then use the receive buffer to send data to the VSC.
227 */
228struct nvsp_1_message_send_receive_buffer {
229 u32 gpadl_handle;
230 u16 id;
231} __packed;
232
233struct nvsp_1_receive_buffer_section {
234 u32 offset;
235 u32 sub_alloc_size;
236 u32 num_sub_allocs;
237 u32 end_offset;
238} __packed;
239
240/*
241 * This message is used by the VSP to acknowledge a receive buffer send by the
242 * VSC. This message must be sent by the VSP before the VSP uses the receive
243 * buffer.
244 */
245struct nvsp_1_message_send_receive_buffer_complete {
246 u32 status;
247 u32 num_sections;
248
249 /*
250 * The receive buffer is split into two parts, a large suballocation
251 * section and a small suballocation section. These sections are then
252 * suballocated by a certain size.
253 */
254
255 /*
256 * For example, the following break up of the receive buffer has 6
257 * large suballocations and 10 small suballocations.
258 */
259
260 /*
261 * | Large Section | | Small Section |
262 * ------------------------------------------------------------
263 * | | | | | | | | | | | | | | | | | |
264 * | |
265 * LargeOffset SmallOffset
266 */
267
268 struct nvsp_1_receive_buffer_section sections[1];
269} __packed;
270
271/*
272 * This message is sent by the VSC to revoke the receive buffer. After the VSP
273 * completes this transaction, the vsp should never use the receive buffer
274 * again.
275 */
276struct nvsp_1_message_revoke_receive_buffer {
277 u16 id;
278};
279
280/*
281 * This message is used by the VSC to send a send buffer to the VSP. The VSC
282 * can then use the send buffer to send data to the VSP.
283 */
284struct nvsp_1_message_send_send_buffer {
285 u32 gpadl_handle;
286 u16 id;
287} __packed;
288
289/*
290 * This message is used by the VSP to acknowledge a send buffer sent by the
291 * VSC. This message must be sent by the VSP before the VSP uses the sent
292 * buffer.
293 */
294struct nvsp_1_message_send_send_buffer_complete {
295 u32 status;
296
297 /*
298 * The VSC gets to choose the size of the send buffer and the VSP gets
299 * to choose the sections size of the buffer. This was done to enable
300 * dynamic reconfigurations when the cost of GPA-direct buffers
301 * decreases.
302 */
303 u32 section_size;
304} __packed;
305
306/*
307 * This message is sent by the VSC to revoke the send buffer. After the VSP
308 * completes this transaction, the vsp should never use the send buffer again.
309 */
310struct nvsp_1_message_revoke_send_buffer {
311 u16 id;
312};
313
314/*
315 * This message is used by both the VSP and the VSC to send a RNDIS message to
316 * the opposite channel endpoint.
317 */
318struct nvsp_1_message_send_rndis_packet {
319 /*
320 * This field is specified by RNIDS. They assume there's two different
321 * channels of communication. However, the Network VSP only has one.
322 * Therefore, the channel travels with the RNDIS packet.
323 */
324 u32 channel_type;
325
326 /*
327 * This field is used to send part or all of the data through a send
328 * buffer. This values specifies an index into the send buffer. If the
329 * index is 0xFFFFFFFF, then the send buffer is not being used and all
330 * of the data was sent through other VMBus mechanisms.
331 */
332 u32 send_buf_section_index;
333 u32 send_buf_section_size;
334} __packed;
335
336/*
337 * This message is used by both the VSP and the VSC to complete a RNDIS message
338 * to the opposite channel endpoint. At this point, the initiator of this
339 * message cannot use any resources associated with the original RNDIS packet.
340 */
341struct nvsp_1_message_send_rndis_packet_complete {
342 u32 status;
343};
344
345union nvsp_1_message_uber {
346 struct nvsp_1_message_send_ndis_version send_ndis_ver;
347
348 struct nvsp_1_message_send_receive_buffer send_recv_buf;
349 struct nvsp_1_message_send_receive_buffer_complete
350 send_recv_buf_complete;
351 struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf;
352
353 struct nvsp_1_message_send_send_buffer send_send_buf;
354 struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete;
355 struct nvsp_1_message_revoke_send_buffer revoke_send_buf;
356
357 struct nvsp_1_message_send_rndis_packet send_rndis_pkt;
358 struct nvsp_1_message_send_rndis_packet_complete
359 send_rndis_pkt_complete;
360} __packed;
361
362union nvsp_all_messages {
363 union nvsp_message_init_uber init_msg;
364 union nvsp_1_message_uber v1_msg;
365} __packed;
366
367/* ALL Messages */
368struct nvsp_message {
369 struct nvsp_message_header hdr;
370 union nvsp_all_messages msg;
371} __packed;
372
373
374
375
376/* #define NVSC_MIN_PROTOCOL_VERSION 1 */
377/* #define NVSC_MAX_PROTOCOL_VERSION 1 */
378
379#define NETVSC_SEND_BUFFER_SIZE (64*1024) /* 64K */
380#define NETVSC_SEND_BUFFER_ID 0xface
381
382
383#define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024) /* 1MB */
384
385#define NETVSC_RECEIVE_BUFFER_ID 0xcafe
386
387#define NETVSC_RECEIVE_SG_COUNT 1
388
389/* Preallocated receive packets */
390#define NETVSC_RECEIVE_PACKETLIST_COUNT 256
391
392#define NETVSC_PACKET_SIZE 2048
393
394/* Per netvsc channel-specific */
395struct netvsc_device {
396 struct hv_device *dev;
397
398 atomic_t refcnt;
399 atomic_t num_outstanding_sends;
400 /*
401 * List of free preallocated hv_netvsc_packet to represent receive
402 * packet
403 */
404 struct list_head recv_pkt_list;
405 spinlock_t recv_pkt_list_lock;
406
407 /* Send buffer allocated by us but manages by NetVSP */
408 void *send_buf;
409 u32 send_buf_size;
410 u32 send_buf_gpadl_handle;
411 u32 send_section_size;
412
413 /* Receive buffer allocated by us but manages by NetVSP */
414 void *recv_buf;
415 u32 recv_buf_size;
416 u32 recv_buf_gpadl_handle;
417 u32 recv_section_cnt;
418 struct nvsp_1_receive_buffer_section *recv_section;
419
420 /* Used for NetVSP initialization protocol */
421 struct completion channel_init_wait;
422 struct nvsp_message channel_init_pkt;
423
424 struct nvsp_message revoke_packet;
425 /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
426
427 /* Holds rndis device info */
428 void *extension;
429};
430
5ca7252a 431#endif /* _HYPERV_NET_H */
This page took 0.042348 seconds and 5 git commands to generate.