]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/snp.h
1. Sync the latest network stack. Add NetLibCreateIPv4DPathNode () in netlib library.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / snp.h
1 /** @file
2
3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module name:
13 snp.h
14
15 Abstract:
16
17 Revision history:
18
19
20 **/
21 #ifndef _SNP_H
22 #define _SNP_H
23
24
25 #include <PiDxe.h>
26
27 #include <Protocol/SimpleNetwork.h>
28 #include <Protocol/PciIo.h>
29 #include <Protocol/NetworkInterfaceIdentifier.h>
30 #include <Protocol/DevicePath.h>
31
32 #include <Library/DebugLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/BaseLib.h>
37 #include <Library/UefiLib.h>
38 #include <Library/MemoryAllocationLib.h>
39
40 #include <IndustryStandard/Pci22.h>
41
42 #define FOUR_GIGABYTES (UINT64) 0x100000000ULL
43
44
45 #define SNP_DRIVER_SIGNATURE EFI_SIGNATURE_32 ('s', 'n', 'd', 's')
46 #define MAX_MAP_LENGTH 100
47
48 #define PCI_BAR_IO_MASK 0x00000003
49 #define PCI_BAR_IO_MODE 0x00000001
50
51 #define PCI_BAR_MEM_MASK 0x0000000F
52 #define PCI_BAR_MEM_MODE 0x00000000
53 #define PCI_BAR_MEM_64BIT 0x00000004
54
55 typedef struct {
56 UINT32 Signature;
57 EFI_LOCK lock;
58
59 EFI_SIMPLE_NETWORK_PROTOCOL snp;
60 EFI_SIMPLE_NETWORK_MODE mode;
61
62 EFI_HANDLE device_handle;
63 EFI_DEVICE_PATH_PROTOCOL *device_path;
64
65 //
66 // Local instance data needed by SNP driver
67 //
68 // Pointer to S/W UNDI API entry point
69 // This will be NULL for H/W UNDI
70 //
71 EFI_STATUS (*issue_undi32_command) (UINT64 cdb);
72
73 BOOLEAN is_swundi;
74
75 //
76 // undi interface number, if one undi manages more nics
77 //
78 PXE_IFNUM if_num;
79
80 //
81 // Allocated tx/rx buffer that was passed to UNDI Initialize.
82 //
83 UINT32 tx_rx_bufsize;
84 VOID *tx_rx_buffer;
85 //
86 // mappable buffers for receive and fill header for undi3.0
87 // these will be used if the user buffers are above 4GB limit (instead of
88 // mapping the user buffers)
89 //
90 UINT8 *receive_buf;
91 VOID *ReceiveBufUnmap;
92 UINT8 *fill_hdr_buf;
93 VOID *FillHdrBufUnmap;
94
95 EFI_PCI_IO_PROTOCOL *IoFncs;
96 UINT8 IoBarIndex;
97 UINT8 MemoryBarIndex;
98 BOOLEAN IsOldUndi; // true for EFI1.0 UNDI (3.0) drivers
99 //
100 // Buffers for command descriptor block, command parameter block
101 // and data block.
102 //
103 PXE_CDB cdb;
104 VOID *cpb;
105 VOID *CpbUnmap;
106 VOID *db;
107
108 //
109 // UNDI structure, we need to remember the init info for a long time!
110 //
111 PXE_DB_GET_INIT_INFO init_info;
112
113 VOID *SnpDriverUnmap;
114 //
115 // when ever we map an address, we must remember it's address and the un-map
116 // cookie so that we can unmap later
117 //
118 struct s_map_list {
119 EFI_PHYSICAL_ADDRESS virt;
120 VOID *map_cookie;
121 } map_list[MAX_MAP_LENGTH];
122 }
123 SNP_DRIVER;
124
125 #define EFI_SIMPLE_NETWORK_DEV_FROM_THIS(a) CR (a, SNP_DRIVER, snp, SNP_DRIVER_SIGNATURE)
126
127 //
128 // Global Variables
129 //
130 extern EFI_COMPONENT_NAME_PROTOCOL gSimpleNetworkComponentName;
131
132 //
133 // Virtual to physical mapping for all UNDI 3.0s.
134 //
135 extern struct s_v2p {
136 struct s_v2p *next;
137 VOID *vaddr;
138 UINTN bsize;
139 EFI_PHYSICAL_ADDRESS paddr;
140 VOID *unmap;
141 }
142 *_v2p;
143
144 EFI_STATUS
145 add_v2p (
146 struct s_v2p **v2p,
147 EFI_PCI_IO_PROTOCOL_OPERATION type,
148 VOID *vaddr,
149 UINTN bsize
150 )
151 ;
152
153 EFI_STATUS
154 find_v2p (
155 struct s_v2p **v2p,
156 VOID *vaddr
157 )
158 ;
159
160 EFI_STATUS
161 del_v2p (
162 VOID *vaddr
163 )
164 ;
165
166 extern
167 VOID
168 snp_undi32_callback_block_30 (
169 IN UINT32 Enable
170 )
171 ;
172
173 extern
174 VOID
175 snp_undi32_callback_delay_30 (
176 IN UINT64 MicroSeconds
177 )
178 ;
179
180 extern
181 VOID
182 snp_undi32_callback_memio_30 (
183 IN UINT8 ReadOrWrite,
184 IN UINT8 NumBytes,
185 IN UINT64 MemOrPortAddress,
186 IN OUT UINT64 BufferPtr
187 )
188 ;
189
190 extern
191 VOID
192 snp_undi32_callback_v2p_30 (
193 IN UINT64 CpuAddr,
194 IN OUT UINT64 DeviceAddrPtr
195 )
196 ;
197
198 extern
199 VOID
200 snp_undi32_callback_block (
201 IN UINT64 UniqueId,
202 IN UINT32 Enable
203 )
204 ;
205
206 extern
207 VOID
208 snp_undi32_callback_delay (
209 IN UINT64 UniqueId,
210 IN UINT64 MicroSeconds
211 )
212 ;
213
214 extern
215 VOID
216 snp_undi32_callback_memio (
217 IN UINT64 UniqueId,
218 IN UINT8 ReadOrWrite,
219 IN UINT8 NumBytes,
220 IN UINT64 MemOrPortAddr,
221 IN OUT UINT64 BufferPtr
222 )
223 ;
224
225 extern
226 VOID
227 snp_undi32_callback_map (
228 IN UINT64 UniqueId,
229 IN UINT64 CpuAddr,
230 IN UINT32 NumBytes,
231 IN UINT32 Direction,
232 IN OUT UINT64 DeviceAddrPtr
233 )
234 ;
235
236 extern
237 VOID
238 snp_undi32_callback_unmap (
239 IN UINT64 UniqueId,
240 IN UINT64 CpuAddr,
241 IN UINT32 NumBytes,
242 IN UINT32 Direction,
243 IN UINT64 DeviceAddr // not a pointer to device address
244 )
245 ;
246
247 extern
248 VOID
249 snp_undi32_callback_sync (
250 IN UINT64 UniqueId,
251 IN UINT64 CpuAddr,
252 IN UINT32 NumBytes,
253 IN UINT32 Direction,
254 IN UINT64 DeviceAddr // not a pointer to device address
255 )
256 ;
257
258 extern
259 EFI_STATUS
260 EFIAPI
261 snp_undi32_start (
262 IN EFI_SIMPLE_NETWORK_PROTOCOL *this
263 )
264 ;
265
266 extern
267 EFI_STATUS
268 EFIAPI
269 snp_undi32_stop (
270 IN EFI_SIMPLE_NETWORK_PROTOCOL *this
271 )
272 ;
273
274 extern
275 EFI_STATUS
276 EFIAPI
277 snp_undi32_initialize (
278 IN EFI_SIMPLE_NETWORK_PROTOCOL *this,
279 IN UINTN extra_rx_buffer_size OPTIONAL,
280 IN UINTN extra_tx_buffer_size OPTIONAL
281 )
282 ;
283
284 extern
285 EFI_STATUS
286 EFIAPI
287 snp_undi32_reset (
288 IN EFI_SIMPLE_NETWORK_PROTOCOL *this,
289 IN BOOLEAN ExtendedVerification
290 )
291 ;
292
293 extern
294 EFI_STATUS
295 EFIAPI
296 snp_undi32_shutdown (
297 IN EFI_SIMPLE_NETWORK_PROTOCOL *this
298 )
299 ;
300
301 extern
302 EFI_STATUS
303 EFIAPI
304 snp_undi32_receive_filters (
305 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
306 IN UINT32 enable,
307 IN UINT32 disable,
308 IN BOOLEAN reset_mcast_filter,
309 IN UINTN mcast_filter_count OPTIONAL,
310 IN EFI_MAC_ADDRESS * mcast_filter OPTIONAL
311 )
312 ;
313
314 extern
315 EFI_STATUS
316 EFIAPI
317 snp_undi32_station_address (
318 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
319 IN BOOLEAN reset,
320 IN EFI_MAC_ADDRESS *new OPTIONAL
321 )
322 ;
323
324 extern
325 EFI_STATUS
326 EFIAPI
327 snp_undi32_statistics (
328 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
329 IN BOOLEAN reset,
330 IN OUT UINTN *statistics_size OPTIONAL,
331 IN OUT EFI_NETWORK_STATISTICS * statistics_table OPTIONAL
332 )
333 ;
334
335 extern
336 EFI_STATUS
337 EFIAPI
338 snp_undi32_mcast_ip_to_mac (
339 IN EFI_SIMPLE_NETWORK_PROTOCOL *this,
340 IN BOOLEAN IPv6,
341 IN EFI_IP_ADDRESS *IP,
342 OUT EFI_MAC_ADDRESS *MAC
343 )
344 ;
345
346 extern
347 EFI_STATUS
348 EFIAPI
349 snp_undi32_nvdata (
350 IN EFI_SIMPLE_NETWORK_PROTOCOL *this,
351 IN BOOLEAN read_write,
352 IN UINTN offset,
353 IN UINTN buffer_size,
354 IN OUT VOID *buffer
355 )
356 ;
357
358 extern
359 EFI_STATUS
360 EFIAPI
361 snp_undi32_get_status (
362 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
363 OUT UINT32 *interrupt_status OPTIONAL,
364 OUT VOID **tx_buffer OPTIONAL
365 )
366 ;
367
368 extern
369 EFI_STATUS
370 EFIAPI
371 snp_undi32_transmit (
372 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
373 IN UINTN header_size,
374 IN UINTN buffer_size,
375 IN VOID *buffer,
376 IN EFI_MAC_ADDRESS * src_addr OPTIONAL,
377 IN EFI_MAC_ADDRESS * dest_addr OPTIONAL,
378 IN UINT16 *protocol OPTIONAL
379 )
380 ;
381
382 extern
383 EFI_STATUS
384 EFIAPI
385 snp_undi32_receive (
386 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
387 OUT UINTN *header_size OPTIONAL,
388 IN OUT UINTN *buffer_size,
389 OUT VOID *buffer,
390 OUT EFI_MAC_ADDRESS * src_addr OPTIONAL,
391 OUT EFI_MAC_ADDRESS * dest_addr OPTIONAL,
392 OUT UINT16 *protocol OPTIONAL
393 )
394 ;
395
396 typedef
397 EFI_STATUS
398 (*issue_undi32_command) (
399 UINT64 cdb
400 );
401 typedef
402 VOID
403 (*ptr) (
404 VOID
405 );
406
407
408 /**
409 Install all the driver protocol
410
411 @param ImageHandle Driver image handle
412 @param SystemTable System services table
413
414 @retval EFI_SUCEESS Initialization routine has found UNDI hardware, loaded it's
415 ROM, and installed a notify event for the Network
416 Indentifier Interface Protocol successfully.
417 @retval Other Return value from HandleProtocol for DeviceIoProtocol or
418 LoadedImageProtocol
419
420 **/
421 EFI_STATUS
422 EFIAPI
423 InitializeSnpNiiDriver (
424 IN EFI_HANDLE ImageHandle,
425 IN EFI_SYSTEM_TABLE *SystemTable
426 )
427 ;
428
429 #ifdef EFI_SIZE_REDUCTION_APPLIED
430 #define COMPONENT_NAME_CODE(code)
431 #define COMPONENT_NAME NULL
432 #else
433 #define COMPONENT_NAME_CODE(code) code
434 #define COMPONENT_NAME &gSimpleNetworkComponentName
435 #endif
436
437 #define SNP_MEM_PAGES(x) (((x) - 1) / 4096 + 1)
438
439
440 #endif /* _SNP_H */