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
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.
27 #include <Protocol/SimpleNetwork.h>
28 #include <Protocol/PciIo.h>
29 #include <Protocol/NetworkInterfaceIdentifier.h>
30 #include <Protocol/DevicePath.h>
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>
40 #include <IndustryStandard/Pci22.h>
42 #define FOUR_GIGABYTES (UINT64) 0x100000000ULL
45 // Driver Consumed Protocol Prototypes
47 //@MT:#include EFI_PROTOCOL_DEFINITION (DevicePath)
48 //@MT:#include EFI_PROTOCOL_DEFINITION (PciIo)
49 //@MT:#include EFI_PROTOCOL_DEFINITION (EfiNetworkInterfaceIdentifier)
52 // Driver Produced Protocol Prototypes
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)
59 #define SNP_DRIVER_SIGNATURE EFI_SIGNATURE_32 ('s', 'n', 'd', 's')
60 #define MAX_MAP_LENGTH 100
62 #define PCI_BAR_IO_MASK 0x00000003
63 #define PCI_BAR_IO_MODE 0x00000001
65 #define PCI_BAR_MEM_MASK 0x0000000F
66 #define PCI_BAR_MEM_MODE 0x00000000
67 #define PCI_BAR_MEM_64BIT 0x00000004
73 EFI_SIMPLE_NETWORK_PROTOCOL snp
;
74 EFI_SIMPLE_NETWORK_MODE mode
;
76 EFI_HANDLE device_handle
;
77 EFI_DEVICE_PATH_PROTOCOL
*device_path
;
80 // Local instance data needed by SNP driver
82 // Pointer to S/W UNDI API entry point
83 // This will be NULL for H/W UNDI
85 EFI_STATUS (*issue_undi32_command
) (UINT64 cdb
);
90 // undi interface number, if one undi manages more nics
95 // Allocated tx/rx buffer that was passed to UNDI Initialize.
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)
105 VOID
*ReceiveBufUnmap
;
107 VOID
*FillHdrBufUnmap
;
109 EFI_PCI_IO_PROTOCOL
*IoFncs
;
111 UINT8 MemoryBarIndex
;
112 BOOLEAN IsOldUndi
; // true for EFI1.0 UNDI (3.0) drivers
114 // Buffers for command descriptor block, command parameter block
123 // UNDI structure, we need to remember the init info for a long time!
125 PXE_DB_GET_INIT_INFO init_info
;
127 VOID
*SnpDriverUnmap
;
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
133 EFI_PHYSICAL_ADDRESS virt
;
135 } map_list
[MAX_MAP_LENGTH
];
139 #define EFI_SIMPLE_NETWORK_DEV_FROM_THIS(a) CR (a, SNP_DRIVER, snp, SNP_DRIVER_SIGNATURE)
144 extern EFI_COMPONENT_NAME_PROTOCOL gSimpleNetworkComponentName
;
147 // Virtual to physical mapping for all UNDI 3.0s.
149 extern struct s_v2p
{
153 EFI_PHYSICAL_ADDRESS paddr
;
161 EFI_PCI_IO_PROTOCOL_OPERATION type
,
182 snp_undi32_callback_block_30 (
189 snp_undi32_callback_delay_30 (
190 IN UINT64 MicroSeconds
196 snp_undi32_callback_memio_30 (
197 IN UINT8 ReadOrWrite
,
199 IN UINT64 MemOrPortAddress
,
200 IN OUT UINT64 BufferPtr
206 snp_undi32_callback_v2p_30 (
208 IN OUT UINT64 DeviceAddrPtr
214 snp_undi32_callback_block (
222 snp_undi32_callback_delay (
224 IN UINT64 MicroSeconds
230 snp_undi32_callback_memio (
232 IN UINT8 ReadOrWrite
,
234 IN UINT64 MemOrPortAddr
,
235 IN OUT UINT64 BufferPtr
241 snp_undi32_callback_map (
246 IN OUT UINT64 DeviceAddrPtr
252 snp_undi32_callback_unmap (
257 IN UINT64 DeviceAddr
// not a pointer to device address
263 snp_undi32_callback_sync (
268 IN UINT64 DeviceAddr
// not a pointer to device address
276 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this
284 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this
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
302 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
303 IN BOOLEAN ExtendedVerification
310 snp_undi32_shutdown (
311 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this
318 snp_undi32_receive_filters (
319 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
322 IN BOOLEAN reset_mcast_filter
,
323 IN UINTN mcast_filter_count OPTIONAL
,
324 IN EFI_MAC_ADDRESS
* mcast_filter OPTIONAL
331 snp_undi32_station_address (
332 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
334 IN EFI_MAC_ADDRESS
*new OPTIONAL
341 snp_undi32_statistics (
342 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
344 IN OUT UINTN
*statistics_size OPTIONAL
,
345 IN OUT EFI_NETWORK_STATISTICS
* statistics_table OPTIONAL
352 snp_undi32_mcast_ip_to_mac (
353 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
355 IN EFI_IP_ADDRESS
*IP
,
356 OUT EFI_MAC_ADDRESS
*MAC
364 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
365 IN BOOLEAN read_write
,
367 IN UINTN buffer_size
,
375 snp_undi32_get_status (
376 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
377 OUT UINT32
*interrupt_status OPTIONAL
,
378 OUT VOID
**tx_buffer OPTIONAL
385 snp_undi32_transmit (
386 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
387 IN UINTN header_size
,
388 IN UINTN buffer_size
,
390 IN EFI_MAC_ADDRESS
* src_addr OPTIONAL
,
391 IN EFI_MAC_ADDRESS
* dest_addr OPTIONAL
,
392 IN UINT16
*protocol OPTIONAL
400 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
401 OUT UINTN
*header_size OPTIONAL
,
402 IN OUT UINTN
*buffer_size
,
404 OUT EFI_MAC_ADDRESS
* src_addr OPTIONAL
,
405 OUT EFI_MAC_ADDRESS
* dest_addr OPTIONAL
,
406 OUT UINT16
*protocol OPTIONAL
412 (*issue_undi32_command
) (
423 Install all the driver protocol
425 @param ImageHandle Driver image handle
426 @param SystemTable System services table
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
437 InitializeSnpNiiDriver (
438 IN EFI_HANDLE ImageHandle
,
439 IN EFI_SYSTEM_TABLE
*SystemTable
443 #ifdef EFI_SIZE_REDUCTION_APPLIED
444 #define COMPONENT_NAME_CODE(code)
445 #define COMPONENT_NAME NULL
447 #define COMPONENT_NAME_CODE(code) code
448 #define COMPONENT_NAME &gSimpleNetworkComponentName
451 #define SNP_MEM_PAGES(x) (((x) - 1) / 4096 + 1)