First Support on Ginger and OMAP TI
[linux-ginger.git] / drivers / staging / hv / NetVsc.h
blob3e7112f7c75536bb9c0b990c39da6180aaf10d97
1 /*
3 * Copyright (c) 2009, Microsoft Corporation.
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.
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.
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.
18 * Authors:
19 * Hank Janssen <hjanssen@microsoft.com>
24 #ifndef _NETVSC_H_
25 #define _NETVSC_H_
27 #include <linux/list.h>
28 #include "VmbusPacketFormat.h"
29 #include "VmbusChannelInterface.h"
30 #include "NetVscApi.h"
33 #define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
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
39 enum {
40 NvspMessageTypeNone = 0,
42 /* Init Messages */
43 NvspMessageTypeInit = 1,
44 NvspMessageTypeInitComplete = 2,
46 NvspVersionMessageStart = 100,
48 /* Version 1 Messages */
49 NvspMessage1TypeSendNdisVersion = NvspVersionMessageStart,
51 NvspMessage1TypeSendReceiveBuffer,
52 NvspMessage1TypeSendReceiveBufferComplete,
53 NvspMessage1TypeRevokeReceiveBuffer,
55 NvspMessage1TypeSendSendBuffer,
56 NvspMessage1TypeSendSendBufferComplete,
57 NvspMessage1TypeRevokeSendBuffer,
59 NvspMessage1TypeSendRNDISPacket,
60 NvspMessage1TypeSendRNDISPacketComplete,
63 * This should be set to the number of messages for the version with
64 * the maximum number of messages.
66 NvspNumMessagePerVersion = 9,
69 enum {
70 NvspStatusNone = 0,
71 NvspStatusSuccess,
72 NvspStatusFailure,
73 NvspStatusProtocolVersionRangeTooNew,
74 NvspStatusProtocolVersionRangeTooOld,
75 NvspStatusInvalidRndisPacket,
76 NvspStatusBusy,
77 NvspStatusMax,
80 struct nvsp_message_header {
81 u32 MessageType;
84 /* Init Messages */
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).
91 struct nvsp_message_init {
92 u32 MinProtocolVersion;
93 u32 MaxProtocolVersion;
94 } __attribute__((packed));
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).
101 struct nvsp_message_init_complete {
102 u32 NegotiatedProtocolVersion;
103 u32 MaximumMdlChainLength;
104 u32 Status;
105 } __attribute__((packed));
107 union nvsp_message_init_uber {
108 struct nvsp_message_init Init;
109 struct nvsp_message_init_complete InitComplete;
110 } __attribute__((packed));
112 /* Version 1 Messages */
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.
118 struct nvsp_1_message_send_ndis_version {
119 u32 NdisMajorVersion;
120 u32 NdisMinorVersion;
121 } __attribute__((packed));
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.
127 struct nvsp_1_message_send_receive_buffer {
128 u32 GpadlHandle;
129 u16 Id;
130 } __attribute__((packed));
132 struct nvsp_1_receive_buffer_section {
133 u32 Offset;
134 u32 SubAllocationSize;
135 u32 NumSubAllocations;
136 u32 EndOffset;
137 } __attribute__((packed));
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.
144 struct nvsp_1_message_send_receive_buffer_complete {
145 u32 Status;
146 u32 NumSections;
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.
155 * For example, the following break up of the receive buffer has 6
156 * large suballocations and 10 small suballocations.
160 * | Large Section | | Small Section |
161 * ------------------------------------------------------------
162 * | | | | | | | | | | | | | | | | | |
163 * | |
164 * LargeOffset SmallOffset
167 struct nvsp_1_receive_buffer_section Sections[1];
168 } __attribute__((packed));
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.
175 struct nvsp_1_message_revoke_receive_buffer {
176 u16 Id;
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.
183 struct nvsp_1_message_send_send_buffer {
184 u32 GpadlHandle;
185 u16 Id;
186 } __attribute__((packed));
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.
193 struct nvsp_1_message_send_send_buffer_complete {
194 u32 Status;
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.
202 u32 SectionSize;
203 } __attribute__((packed));
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.
209 struct nvsp_1_message_revoke_send_buffer {
210 u16 Id;
214 * This message is used by both the VSP and the VSC to send a RNDIS message to
215 * the opposite channel endpoint.
217 struct nvsp_1_message_send_rndis_packet {
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.
223 u32 ChannelType;
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.
231 u32 SendBufferSectionIndex;
232 u32 SendBufferSectionSize;
233 } __attribute__((packed));
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.
240 struct nvsp_1_message_send_rndis_packet_complete {
241 u32 Status;
244 union nvsp_1_message_uber {
245 struct nvsp_1_message_send_ndis_version SendNdisVersion;
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;
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;
256 struct nvsp_1_message_send_rndis_packet SendRNDISPacket;
257 struct nvsp_1_message_send_rndis_packet_complete
258 SendRNDISPacketComplete;
259 } __attribute__((packed));
261 union nvsp_all_messages {
262 union nvsp_message_init_uber InitMessages;
263 union nvsp_1_message_uber Version1Messages;
264 } __attribute__((packed));
266 /* ALL Messages */
267 struct nvsp_message {
268 struct nvsp_message_header Header;
269 union nvsp_all_messages Messages;
270 } __attribute__((packed));
275 /* #define NVSC_MIN_PROTOCOL_VERSION 1 */
276 /* #define NVSC_MAX_PROTOCOL_VERSION 1 */
278 #define NETVSC_SEND_BUFFER_SIZE (64*1024) /* 64K */
279 #define NETVSC_SEND_BUFFER_ID 0xface
282 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024) /* 1MB */
284 #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
286 #define NETVSC_RECEIVE_SG_COUNT 1
288 /* Preallocated receive packets */
289 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
292 /* Per netvsc channel-specific */
293 struct netvsc_device {
294 struct hv_device *Device;
296 atomic_t RefCount;
297 atomic_t NumOutstandingSends;
299 * List of free preallocated hv_netvsc_packet to represent receive
300 * packet
302 struct list_head ReceivePacketList;
303 spinlock_t receive_packet_list_lock;
305 /* Send buffer allocated by us but manages by NetVSP */
306 void *SendBuffer;
307 u32 SendBufferSize;
308 u32 SendBufferGpadlHandle;
309 u32 SendSectionSize;
311 /* Receive buffer allocated by us but manages by NetVSP */
312 void *ReceiveBuffer;
313 u32 ReceiveBufferSize;
314 u32 ReceiveBufferGpadlHandle;
315 u32 ReceiveSectionCount;
316 struct nvsp_1_receive_buffer_section *ReceiveSections;
318 /* Used for NetVSP initialization protocol */
319 struct osd_waitevent *ChannelInitEvent;
320 struct nvsp_message ChannelInitPacket;
322 struct nvsp_message RevokePacket;
323 /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
325 /* Holds rndis device info */
326 void *Extension;
329 #endif /* _NETVSC_H_ */