• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 
3   Internal definitions for the virtio-net driver, which produces Simple Network
4   Protocol instances for virtio-net devices.
5 
6   Copyright (C) 2013, Red Hat, Inc.
7 
8   This program and the accompanying materials are licensed and made available
9   under the terms and conditions of the BSD License which accompanies this
10   distribution. The full text of the license may be found at
11   http://opensource.org/licenses/bsd-license.php
12 
13   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14   WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 **/
16 
17 #ifndef _VIRTIO_NET_DXE_H_
18 #define _VIRTIO_NET_DXE_H_
19 
20 #include <IndustryStandard/VirtioNet.h>
21 #include <Library/DebugLib.h>
22 #include <Library/VirtioLib.h>
23 #include <Protocol/ComponentName.h>
24 #include <Protocol/ComponentName2.h>
25 #include <Protocol/DevicePath.h>
26 #include <Protocol/DriverBinding.h>
27 #include <Protocol/SimpleNetwork.h>
28 
29 #define VNET_SIG SIGNATURE_32 ('V', 'N', 'E', 'T')
30 
31 //
32 // maximum number of pending packets, separately for each direction
33 //
34 #define VNET_MAX_PENDING 64
35 
36 //
37 // State diagram:
38 //
39 //                  |     ^
40 //                  |     |
41 //        BindingStart  BindingStop
42 //        +SnpPopulate    |
43 //        ++GetFeatures   |
44 //                  |     |
45 //                  v     |
46 //                +---------+    virtio-net device is reset, no resources are
47 //                | stopped |    allocated for traffic, but MAC address has
48 //                +---------+    been retrieved
49 //                  |     ^
50 //                  |     |
51 //            SNP.Start SNP.Stop
52 //                  |     |
53 //                  v     |
54 //                +---------+
55 //                | started |    functionally identical to stopped
56 //                +---------+
57 //                  |     ^
58 //                  |     |
59 //       SNP.Initialize SNP.Shutdown
60 //                  |     |
61 //                  v     |
62 //              +-------------+  Virtio-net setup complete, including DRIVER_OK
63 //              | initialized |  bit. The receive queue is populated with
64 //              +-------------+  requests; McastIpToMac, GetStatus, Transmit,
65 //                               Receive are callable.
66 //
67 
68 typedef struct {
69   //
70   // Parts of this structure are initialized / torn down in various functions
71   // at various call depths. The table to the right should make it easier to
72   // track them.
73   //
74   //                          field              init function
75   //                          ------------------ ------------------------------
76   UINT32                      Signature;         // VirtioNetDriverBindingStart
77   VIRTIO_DEVICE_PROTOCOL      *VirtIo;           // VirtioNetDriverBindingStart
78   EFI_SIMPLE_NETWORK_PROTOCOL Snp;               // VirtioNetSnpPopulate
79   EFI_SIMPLE_NETWORK_MODE     Snm;               // VirtioNetSnpPopulate
80   EFI_EVENT                   ExitBoot;          // VirtioNetSnpPopulate
81   EFI_DEVICE_PATH_PROTOCOL    *MacDevicePath;    // VirtioNetDriverBindingStart
82   EFI_HANDLE                  MacHandle;         // VirtioNetDriverBindingStart
83 
84   VRING                       RxRing;            // VirtioNetInitRing
85   UINT8                       *RxBuf;            // VirtioNetInitRx
86   UINT16                      RxLastUsed;        // VirtioNetInitRx
87 
88   VRING                       TxRing;            // VirtioNetInitRing
89   UINT16                      TxMaxPending;      // VirtioNetInitTx
90   UINT16                      TxCurPending;      // VirtioNetInitTx
91   UINT16                      *TxFreeStack;      // VirtioNetInitTx
92   VIRTIO_1_0_NET_REQ          TxSharedReq;       // VirtioNetInitTx
93   UINT16                      TxLastUsed;        // VirtioNetInitTx
94 } VNET_DEV;
95 
96 
97 //
98 // In order to avoid duplication of interface documentation, please find all
99 // leading comments near the respective function / variable definitions (not
100 // the declarations here), which is where your code editor of choice takes you
101 // anyway when jumping to a function.
102 //
103 
104 //
105 // utility macros
106 //
107 #define VIRTIO_NET_FROM_SNP(SnpPointer) \
108         CR (SnpPointer, VNET_DEV, Snp, VNET_SIG)
109 
110 #define VIRTIO_CFG_WRITE(Dev, Field, Value)  ((Dev)->VirtIo->WriteDevice (  \
111                                                 (Dev)->VirtIo,              \
112                                                 OFFSET_OF_VNET (Field),     \
113                                                 SIZE_OF_VNET (Field),       \
114                                                 (Value)                     \
115                                                 ))
116 
117 #define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice (   \
118                                                 (Dev)->VirtIo,              \
119                                                 OFFSET_OF_VNET (Field),     \
120                                                 SIZE_OF_VNET (Field),       \
121                                                 sizeof *(Pointer),          \
122                                                 (Pointer)                   \
123                                                 ))
124 
125 //
126 // component naming
127 //
128 extern EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName;
129 extern EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2;
130 
131 //
132 // driver binding
133 //
134 extern EFI_DRIVER_BINDING_PROTOCOL gVirtioNetDriverBinding;
135 
136 //
137 // member functions implementing the Simple Network Protocol
138 //
139 EFI_STATUS
140 EFIAPI
141 VirtioNetStart (
142   IN EFI_SIMPLE_NETWORK_PROTOCOL *This
143   );
144 
145 EFI_STATUS
146 EFIAPI
147 VirtioNetStop (
148   IN EFI_SIMPLE_NETWORK_PROTOCOL *This
149   );
150 
151 EFI_STATUS
152 EFIAPI
153 VirtioNetInitialize (
154   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
155   IN UINTN                       ExtraRxBufferSize  OPTIONAL,
156   IN UINTN                       ExtraTxBufferSize  OPTIONAL
157   );
158 
159 EFI_STATUS
160 EFIAPI
161 VirtioNetReset (
162   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
163   IN BOOLEAN                     ExtendedVerification
164   );
165 
166 EFI_STATUS
167 EFIAPI
168 VirtioNetShutdown (
169   IN EFI_SIMPLE_NETWORK_PROTOCOL *This
170   );
171 
172 EFI_STATUS
173 EFIAPI
174 VirtioNetReceiveFilters (
175   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
176   IN UINT32                      Enable,
177   IN UINT32                      Disable,
178   IN BOOLEAN                     ResetMCastFilter,
179   IN UINTN                       MCastFilterCnt    OPTIONAL,
180   IN EFI_MAC_ADDRESS             *MCastFilter      OPTIONAL
181   );
182 
183 EFI_STATUS
184 EFIAPI
185 VirtioNetStationAddress (
186   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
187   IN BOOLEAN                     Reset,
188   IN EFI_MAC_ADDRESS             *New OPTIONAL
189   );
190 
191 EFI_STATUS
192 EFIAPI
193 VirtioNetStatistics (
194   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
195   IN BOOLEAN                     Reset,
196   IN OUT UINTN                   *StatisticsSize   OPTIONAL,
197   OUT EFI_NETWORK_STATISTICS     *StatisticsTable  OPTIONAL
198   );
199 
200 EFI_STATUS
201 EFIAPI
202 VirtioNetMcastIpToMac (
203   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
204   IN BOOLEAN                     IPv6,
205   IN EFI_IP_ADDRESS              *Ip,
206   OUT EFI_MAC_ADDRESS            *Mac
207   );
208 
209 EFI_STATUS
210 EFIAPI
211 VirtioNetNvData (
212   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
213   IN BOOLEAN                     ReadWrite,
214   IN UINTN                       Offset,
215   IN UINTN                       BufferSize,
216   IN OUT VOID                    *Buffer
217   );
218 
219 EFI_STATUS
220 EFIAPI
221 VirtioNetGetStatus (
222   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
223   OUT UINT32                     *InterruptStatus OPTIONAL,
224   OUT VOID                       **TxBuf OPTIONAL
225   );
226 
227 EFI_STATUS
228 EFIAPI
229 VirtioNetTransmit (
230   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
231   IN UINTN                       HeaderSize,
232   IN UINTN                       BufferSize,
233   IN /* +OUT! */ VOID            *Buffer,
234   IN EFI_MAC_ADDRESS             *SrcAddr  OPTIONAL,
235   IN EFI_MAC_ADDRESS             *DestAddr OPTIONAL,
236   IN UINT16                      *Protocol OPTIONAL
237   );
238 
239 EFI_STATUS
240 EFIAPI
241 VirtioNetReceive (
242   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
243   OUT UINTN                      *HeaderSize OPTIONAL,
244   IN OUT UINTN                   *BufferSize,
245   OUT VOID                       *Buffer,
246   OUT EFI_MAC_ADDRESS            *SrcAddr    OPTIONAL,
247   OUT EFI_MAC_ADDRESS            *DestAddr   OPTIONAL,
248   OUT UINT16                     *Protocol   OPTIONAL
249   );
250 
251 //
252 // utility functions shared by various SNP member functions
253 //
254 VOID
255 EFIAPI
256 VirtioNetShutdownRx (
257   IN OUT VNET_DEV *Dev
258   );
259 
260 VOID
261 EFIAPI
262 VirtioNetShutdownTx (
263   IN OUT VNET_DEV *Dev
264   );
265 
266 //
267 // event callbacks
268 //
269 VOID
270 EFIAPI
271 VirtioNetIsPacketAvailable (
272   IN  EFI_EVENT Event,
273   IN  VOID      *Context
274   );
275 
276 VOID
277 EFIAPI
278 VirtioNetExitBoot (
279   IN  EFI_EVENT Event,
280   IN  VOID      *Context
281   );
282 
283 #endif // _VIRTIO_NET_DXE_H_
284