Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hyperv_net.h
Go to the documentation of this file.
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 <[email protected]>
20  * Hank Janssen <[email protected]>
21  * K. Y. Srinivasan <[email protected]>
22  *
23  */
24 
25 #ifndef _HYPERV_NET_H
26 #define _HYPERV_NET_H
27 
28 #include <linux/list.h>
29 #include <linux/hyperv.h>
30 #include <linux/rndis.h>
31 
32 /* Fwd declaration */
33 struct hv_netvsc_packet;
34 
35 /* Represent the xfer page packet which contains 1 or more netvsc packet */
39 
40  /* # of netvsc packets this xfer packet contains */
42 };
43 
44 /*
45  * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
46  * within the RNDIS
47  */
49  /* Bookkeeping stuff */
52 
53  struct hv_device *device;
56 
57  /*
58  * Valid only for receives when we break a xfer page packet
59  * into multiple netvsc packets
60  */
62 
63  union {
64  struct {
68  } recv;
69  struct {
73  } send;
74  } completion;
75 
76  /* This points to the memory after page_buf */
77  void *extension;
78 
80  /* Points to the send/receive buffer where the ethernet frame is */
81  void *data;
83  struct hv_page_buffer page_buf[0];
84 };
85 
87  unsigned char mac_adr[6];
88  bool link_state; /* 0 - link up, 1 - link down */
89  int ring_size;
90 };
91 
97 };
98 
99 struct rndis_device {
101 
105 
108 
109  unsigned char hw_mac_adr[ETH_ALEN];
110 };
111 
112 
113 /* Interface */
114 int netvsc_device_add(struct hv_device *device, void *additional_info);
115 int netvsc_device_remove(struct hv_device *device);
116 int netvsc_send(struct hv_device *device,
117  struct hv_netvsc_packet *packet);
118 void netvsc_linkstatus_callback(struct hv_device *device_obj,
119  unsigned int status);
120 int netvsc_recv_callback(struct hv_device *device_obj,
121  struct hv_netvsc_packet *packet);
122 int rndis_filter_open(struct hv_device *dev);
123 int rndis_filter_close(struct hv_device *dev);
124 int rndis_filter_device_add(struct hv_device *dev,
125  void *additional_info);
126 void rndis_filter_device_remove(struct hv_device *dev);
127 int rndis_filter_receive(struct hv_device *dev,
128  struct hv_netvsc_packet *pkt);
129 
130 
131 
132 int rndis_filter_send(struct hv_device *dev,
133  struct hv_netvsc_packet *pkt);
134 
135 int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter);
136 int rndis_filter_set_device_mac(struct hv_device *hdev, char *mac);
137 
138 
139 #define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
140 
141 #define NVSP_PROTOCOL_VERSION_1 2
142 #define NVSP_PROTOCOL_VERSION_2 0x30002
143 
144 enum {
146 
147  /* Init Messages */
150 
152 
153  /* Version 1 Messages */
155 
159 
163 
166 
167  /* Version 2 messages */
171 
173 
176 
178 
181 
184 
187 
189 
192 
194 
197 };
198 
199 enum {
209 };
210 
213 };
214 
215 /* Init Messages */
216 
217 /*
218  * This message is used by the VSC to initialize the channel after the channels
219  * has been opened. This message should never include anything other then
220  * versioning (i.e. this message will be the same for ever).
221  */
225 } __packed;
226 
227 /*
228  * This message is used by the VSP to complete the initialization of the
229  * channel. This message should never include anything other then versioning
230  * (i.e. this message will be the same for ever).
231  */
236 } __packed;
237 
241 } __packed;
242 
243 /* Version 1 Messages */
244 
245 /*
246  * This message is used by the VSC to send the NDIS version to the VSP. The VSP
247  * can use this information when handling OIDs sent by the VSC.
248  */
252 } __packed;
253 
254 /*
255  * This message is used by the VSC to send a receive buffer to the VSP. The VSP
256  * can then use the receive buffer to send data to the VSC.
257  */
261 } __packed;
262 
268 } __packed;
269 
270 /*
271  * This message is used by the VSP to acknowledge a receive buffer send by the
272  * VSC. This message must be sent by the VSP before the VSP uses the receive
273  * buffer.
274  */
278 
279  /*
280  * The receive buffer is split into two parts, a large suballocation
281  * section and a small suballocation section. These sections are then
282  * suballocated by a certain size.
283  */
284 
285  /*
286  * For example, the following break up of the receive buffer has 6
287  * large suballocations and 10 small suballocations.
288  */
289 
290  /*
291  * | Large Section | | Small Section |
292  * ------------------------------------------------------------
293  * | | | | | | | | | | | | | | | | | |
294  * | |
295  * LargeOffset SmallOffset
296  */
297 
299 } __packed;
300 
301 /*
302  * This message is sent by the VSC to revoke the receive buffer. After the VSP
303  * completes this transaction, the vsp should never use the receive buffer
304  * again.
305  */
308 };
309 
310 /*
311  * This message is used by the VSC to send a send buffer to the VSP. The VSC
312  * can then use the send buffer to send data to the VSP.
313  */
317 } __packed;
318 
319 /*
320  * This message is used by the VSP to acknowledge a send buffer sent by the
321  * VSC. This message must be sent by the VSP before the VSP uses the sent
322  * buffer.
323  */
326 
327  /*
328  * The VSC gets to choose the size of the send buffer and the VSP gets
329  * to choose the sections size of the buffer. This was done to enable
330  * dynamic reconfigurations when the cost of GPA-direct buffers
331  * decreases.
332  */
334 } __packed;
335 
336 /*
337  * This message is sent by the VSC to revoke the send buffer. After the VSP
338  * completes this transaction, the vsp should never use the send buffer again.
339  */
342 };
343 
344 /*
345  * This message is used by both the VSP and the VSC to send a RNDIS message to
346  * the opposite channel endpoint.
347  */
349  /*
350  * This field is specified by RNIDS. They assume there's two different
351  * channels of communication. However, the Network VSP only has one.
352  * Therefore, the channel travels with the RNDIS packet.
353  */
355 
356  /*
357  * This field is used to send part or all of the data through a send
358  * buffer. This values specifies an index into the send buffer. If the
359  * index is 0xFFFFFFFF, then the send buffer is not being used and all
360  * of the data was sent through other VMBus mechanisms.
361  */
364 } __packed;
365 
366 /*
367  * This message is used by both the VSP and the VSC to complete a RNDIS message
368  * to the opposite channel endpoint. At this point, the initiator of this
369  * message cannot use any resources associated with the original RNDIS packet.
370  */
373 };
374 
377 
382 
386 
390 } __packed;
391 
392 
393 /*
394  * Network VSP protocol version 2 messages:
395  */
397  union {
399  struct {
400  u64 vmq:1;
405  };
406  };
407 } __packed;
408 
413 } __packed;
414 
415 /* Allocate receive buffer */
417  /* Allocation ID to match the allocation request and response */
419 
420  /* Length of the VM shared memory receive buffer that needs to
421  * be allocated
422  */
424 } __packed;
425 
426 /* Allocate receive buffer complete */
428  /* The NDIS_STATUS code for buffer allocation */
430 
432 
433  /* GPADL handle for the allocated receive buffer */
435 
436  /* Receive buffer ID */
438 } __packed;
439 
442 } __packed;
443 
449 } __packed;
450 
455 } __packed;
456 
457 /* ALL Messages */
458 struct nvsp_message {
461 } __packed;
462 
463 
464 #define NETVSC_MTU 65536
465 
466 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*2) /* 2MB */
467 
468 #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
469 
470 /* Preallocated receive packets */
471 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
472 
473 #define NETVSC_PACKET_SIZE 2048
474 
475 /* Per netvsc channel-specific */
477  struct hv_device *dev;
478 
480 
484  bool destroy;
485  /*
486  * List of free preallocated hv_netvsc_packet to represent receive
487  * packet
488  */
491 
492  /* Receive buffer allocated by us but manages by NetVSP */
493  void *recv_buf;
498 
499  /* Used for NetVSP initialization protocol */
502 
504  /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
505 
506  struct net_device *ndev;
507 
508  /* Holds rndis device info */
509  void *extension;
510 };
511 
512 /* NdisInitialize message */
518 };
519 
520 /* Response to NdisInitialize */
533 };
534 
535 /* Call manager devices only: Information about an address family */
536 /* supported by the device is appended to the response to NdisInitialize. */
541 };
542 
543 /* NdisHalt message */
546 };
547 
548 /* NdisQueryRequest message */
555 };
556 
557 /* Response to NdisQueryRequest */
563 };
564 
565 /* NdisSetRequest message */
572 };
573 
574 /* Response to NdisSetRequest */
578 };
579 
580 /* NdisReset message */
583 };
584 
585 /* Response to NdisReset */
589 };
590 
591 /* NdisMIndicateStatus message */
596 };
597 
598 /* Diagnostic information passed as the status buffer in */
599 /* struct rndis_indicate_status messages signifying error conditions. */
603 };
604 
605 /* NdisKeepAlive message */
608 };
609 
610 /* Response to NdisKeepAlive */
614 };
615 
616 /*
617  * Data message. All Offset fields contain byte offsets from the beginning of
618  * struct rndis_packet. All Length fields are in bytes. VcHandle is set
619  * to 0 for connectionless data, otherwise it contains the VC handle.
620  */
621 struct rndis_packet {
631 };
632 
633 /* Optional Out of Band data associated with a Data message. */
634 struct rndis_oobd {
638 };
639 
640 /* Packet extension field contents associated with a Data message. */
645 };
646 
661 };
662 
664  union {
665  struct {
666  u32 pri:3; /* User Priority */
667  u32 cfi:1; /* Canonical Format ID */
668  u32 vlanid:12; /* VLAN ID */
670  };
672  };
673 };
674 
675 #define NDIS_VLAN_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
676  sizeof(struct ndis_pkt_8021q_info))
677 
678 /* Format of Information buffer passed in a SetRequest for the OID */
679 /* OID_GEN_RNDIS_CONFIG_PARAMETER. */
686 };
687 
688 /* Values for ParameterType in struct rndis_config_parameter_info */
689 #define RNDIS_CONFIG_PARAM_TYPE_INTEGER 0
690 #define RNDIS_CONFIG_PARAM_TYPE_STRING 2
691 
692 /* CONDIS Miniport messages for connection oriented devices */
693 /* that do not implement a call manager. */
694 
695 /* CoNdisMiniportCreateVc message */
699 };
700 
701 /* Response to CoNdisMiniportCreateVc */
706 };
707 
708 /* CoNdisMiniportDeleteVc message */
712 };
713 
714 /* Response to CoNdisMiniportDeleteVc */
718 };
719 
720 /* CoNdisMiniportQueryRequest message */
728 };
729 
730 /* CoNdisMiniportSetRequest message */
738 };
739 
740 /* CoNdisIndicateStatus message */
746 };
747 
748 /* CONDIS Call/VC parameters */
753 };
754 
760 };
761 
771 };
772 
777 };
778 
779 /* CoNdisMiniportActivateVc message */
788 };
789 
790 /* Response to CoNdisMiniportActivateVc */
794 };
795 
796 /* CoNdisMiniportDeactivateVc message */
801 };
802 
803 /* Response to CoNdisMiniportDeactivateVc */
807 };
808 
809 
810 /* union with all of the RNDIS messages */
835 };
836 
837 /* Remote NDIS message format */
840 
841  /* Total length of this message, from the beginning */
842  /* of the sruct rndis_message, in bytes. */
844 
845  /* Actual message */
847 };
848 
849 
854 };
855 
856 /* Handy macros */
857 
858 /* get the size of an RNDIS message. Pass in the message type, */
859 /* struct rndis_set_request, struct rndis_packet for example */
860 #define RNDIS_MESSAGE_SIZE(msg) \
861  (sizeof(msg) + (sizeof(struct rndis_message) - \
862  sizeof(union rndis_message_container)))
863 
864 /* get pointer to info buffer with message pointer */
865 #define MESSAGE_TO_INFO_BUFFER(msg) \
866  (((unsigned char *)(msg)) + msg->info_buf_offset)
867 
868 /* get pointer to status buffer with message pointer */
869 #define MESSAGE_TO_STATUS_BUFFER(msg) \
870  (((unsigned char *)(msg)) + msg->status_buf_offset)
871 
872 /* get pointer to OOBD buffer with message pointer */
873 #define MESSAGE_TO_OOBD_BUFFER(msg) \
874  (((unsigned char *)(msg)) + msg->oob_data_offset)
875 
876 /* get pointer to data buffer with message pointer */
877 #define MESSAGE_TO_DATA_BUFFER(msg) \
878  (((unsigned char *)(msg)) + msg->per_pkt_info_offset)
879 
880 /* get pointer to contained message from NDIS_MESSAGE pointer */
881 #define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(rndis_msg) \
882  ((void *) &rndis_msg->msg)
883 
884 /* get pointer to contained message from NDIS_MESSAGE pointer */
885 #define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(rndis_msg) \
886  ((void *) rndis_msg)
887 
888 
889 #define __struct_bcount(x)
890 
891 
892 
893 #define RNDIS_HEADER_SIZE (sizeof(struct rndis_message) - \
894  sizeof(union rndis_message_container))
895 
896 #define NDIS_PACKET_TYPE_DIRECTED 0x00000001
897 #define NDIS_PACKET_TYPE_MULTICAST 0x00000002
898 #define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004
899 #define NDIS_PACKET_TYPE_BROADCAST 0x00000008
900 #define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
901 #define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
902 #define NDIS_PACKET_TYPE_SMT 0x00000040
903 #define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080
904 #define NDIS_PACKET_TYPE_GROUP 0x00000100
905 #define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200
906 #define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400
907 #define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800
908 
909 
910 
911 #endif /* _HYPERV_NET_H */