1 /** @file
2   Virtio Network Device specific type and macro definitions corresponding to
3   the virtio-0.9.5 specification.
4 
5   Copyright (C) 2013, Red Hat, Inc.
6 
7   This program and the accompanying materials are licensed and made available
8   under the terms and conditions of the BSD License which accompanies this
9   distribution. The full text of the license may be found at
10   http://opensource.org/licenses/bsd-license.php
11 
12   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
13   WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 
17 #ifndef _VIRTIO_NET_H_
18 #define _VIRTIO_NET_H_
19 
20 #include <IndustryStandard/Virtio.h>
21 
22 //
23 // virtio-0.9.5, Appendix C: Network Device
24 //
25 #pragma pack(1)
26 typedef struct {
27   UINT8      Mac[6];
28   UINT16     LinkStatus;
29 } VIRTIO_NET_CONFIG;
30 #pragma pack()
31 
32 #define OFFSET_OF_VNET(Field) OFFSET_OF (VIRTIO_NET_CONFIG, Field)
33 #define SIZE_OF_VNET(Field)   (sizeof ((VIRTIO_NET_CONFIG *) 0)->Field)
34 
35 //
36 // Queue Identifiers
37 //
38 #define VIRTIO_NET_Q_RX 0
39 #define VIRTIO_NET_Q_TX 1
40 
41 //
42 // Feature Bits
43 //
44 #define VIRTIO_NET_F_CSUM           BIT0  // host to checksum outgoing packets
45 #define VIRTIO_NET_F_GUEST_CSUM     BIT1  // guest to checksum incoming packets
46 #define VIRTIO_NET_F_MAC            BIT5  // MAC available to guest
47 #define VIRTIO_NET_F_GSO            BIT6  // deprecated
48 #define VIRTIO_NET_F_GUEST_TSO4     BIT7  // guest can receive TSOv4
49 #define VIRTIO_NET_F_GUEST_TSO6     BIT8  // guest can receive TSOv6
50 #define VIRTIO_NET_F_GUEST_ECN      BIT9  // guest can receive TSO with ECN
51 #define VIRTIO_NET_F_GUEST_UFO      BIT10 // guest can receive UFO
52 #define VIRTIO_NET_F_HOST_TSO4      BIT11 // host can receive TSOv4
53 #define VIRTIO_NET_F_HOST_TSO6      BIT12 // host can receive TSOv6
54 #define VIRTIO_NET_F_HOST_ECN       BIT13 // host can receive TSO with ECN
55 #define VIRTIO_NET_F_HOST_UFO       BIT14 // host can receive UFO
56 #define VIRTIO_NET_F_MRG_RXBUF      BIT15 // guest can merge receive buffers
57 #define VIRTIO_NET_F_STATUS         BIT16 // link status available to guest
58 #define VIRTIO_NET_F_CTRL_VQ        BIT17 // control channel available
59 #define VIRTIO_NET_F_CTRL_RX        BIT18 // control channel RX mode support
60 #define VIRTIO_NET_F_CTRL_VLAN      BIT19 // control channel VLAN filtering
61 #define VIRTIO_NET_F_GUEST_ANNOUNCE BIT21 // guest can send gratuitous pkts
62 
63 //
64 // Packet Header
65 //
66 #pragma pack(1)
67 typedef struct {
68   UINT8  Flags;
69   UINT8  GsoType;
70   UINT16 HdrLen;
71   UINT16 GsoSize;
72   UINT16 CsumStart;
73   UINT16 CsumOffset;
74 } VIRTIO_NET_REQ;
75 #pragma pack()
76 
77 //
78 // Bits in VIRTIO_NET_REQ.Flags
79 //
80 #define VIRTIO_NET_HDR_F_NEEDS_CSUM BIT0
81 
82 //
83 // Types/Bits for VIRTIO_NET_REQ.GsoType
84 //
85 #define VIRTIO_NET_HDR_GSO_NONE  0x00
86 #define VIRTIO_NET_HDR_GSO_TCPV4 0x01
87 #define VIRTIO_NET_HDR_GSO_UDP   0x03
88 #define VIRTIO_NET_HDR_GSO_TCPV6 0x04
89 #define VIRTIO_NET_HDR_GSO_ECN   BIT7
90 
91 //
92 // Link Status Bits in VIRTIO_NET_CONFIG.LinkStatus
93 //
94 #define VIRTIO_NET_S_LINK_UP  BIT0
95 #define VIRTIO_NET_S_ANNOUNCE BIT1
96 
97 #endif // _VIRTIO_NET_H_
98