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