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