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 #define SNP_DRIVER_SIGNATURE EFI_SIGNATURE_32 ('s', 'n', 'd', 's')
46 #define MAX_MAP_LENGTH 100
48 #define PCI_BAR_IO_MASK 0x00000003
49 #define PCI_BAR_IO_MODE 0x00000001
51 #define PCI_BAR_MEM_MASK 0x0000000F
52 #define PCI_BAR_MEM_MODE 0x00000000
53 #define PCI_BAR_MEM_64BIT 0x00000004
59 EFI_SIMPLE_NETWORK_PROTOCOL snp
;
60 EFI_SIMPLE_NETWORK_MODE mode
;
62 EFI_HANDLE device_handle
;
63 EFI_DEVICE_PATH_PROTOCOL
*device_path
;
66 // Local instance data needed by SNP driver
68 // Pointer to S/W UNDI API entry point
69 // This will be NULL for H/W UNDI
71 EFI_STATUS (*issue_undi32_command
) (UINT64 cdb
);
76 // undi interface number, if one undi manages more nics
81 // Allocated tx/rx buffer that was passed to UNDI Initialize.
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)
91 VOID
*ReceiveBufUnmap
;
93 VOID
*FillHdrBufUnmap
;
95 EFI_PCI_IO_PROTOCOL
*IoFncs
;
100 // Buffers for command descriptor block, command parameter block
109 // UNDI structure, we need to remember the init info for a long time!
111 PXE_DB_GET_INIT_INFO init_info
;
113 VOID
*SnpDriverUnmap
;
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
119 EFI_PHYSICAL_ADDRESS virt
;
121 } map_list
[MAX_MAP_LENGTH
];
125 #define EFI_SIMPLE_NETWORK_DEV_FROM_THIS(a) CR (a, SNP_DRIVER, snp, SNP_DRIVER_SIGNATURE)
130 extern EFI_COMPONENT_NAME_PROTOCOL gSimpleNetworkComponentName
;
131 extern EFI_COMPONENT_NAME2_PROTOCOL gSimpleNetworkComponentName2
;
134 // Virtual to physical mapping for all UNDI 3.0s.
136 extern struct s_v2p
{
140 EFI_PHYSICAL_ADDRESS paddr
;
148 EFI_PCI_IO_PROTOCOL_OPERATION type
,
166 snp_undi32_callback_block_30 (
172 snp_undi32_callback_delay_30 (
173 IN UINT64 MicroSeconds
178 snp_undi32_callback_memio_30 (
179 IN UINT8 ReadOrWrite
,
181 IN UINT64 MemOrPortAddress
,
182 IN OUT UINT64 BufferPtr
187 snp_undi32_callback_v2p_30 (
189 IN OUT UINT64 DeviceAddrPtr
194 snp_undi32_callback_block (
201 snp_undi32_callback_delay (
203 IN UINT64 MicroSeconds
208 snp_undi32_callback_memio (
210 IN UINT8 ReadOrWrite
,
212 IN UINT64 MemOrPortAddr
,
213 IN OUT UINT64 BufferPtr
218 snp_undi32_callback_map (
223 IN OUT UINT64 DeviceAddrPtr
228 snp_undi32_callback_unmap (
233 IN UINT64 DeviceAddr
// not a pointer to device address
238 snp_undi32_callback_sync (
243 IN UINT64 DeviceAddr
// not a pointer to device address
250 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this
257 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this
263 snp_undi32_initialize (
264 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
265 IN UINTN extra_rx_buffer_size OPTIONAL
,
266 IN UINTN extra_tx_buffer_size OPTIONAL
273 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
274 IN BOOLEAN ExtendedVerification
280 snp_undi32_shutdown (
281 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this
287 snp_undi32_receive_filters (
288 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
291 IN BOOLEAN reset_mcast_filter
,
292 IN UINTN mcast_filter_count OPTIONAL
,
293 IN EFI_MAC_ADDRESS
* mcast_filter OPTIONAL
299 snp_undi32_station_address (
300 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
302 IN EFI_MAC_ADDRESS
*new OPTIONAL
308 snp_undi32_statistics (
309 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
311 IN OUT UINTN
*statistics_size OPTIONAL
,
312 IN OUT EFI_NETWORK_STATISTICS
* statistics_table OPTIONAL
318 snp_undi32_mcast_ip_to_mac (
319 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
321 IN EFI_IP_ADDRESS
*IP
,
322 OUT EFI_MAC_ADDRESS
*MAC
329 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
330 IN BOOLEAN read_write
,
332 IN UINTN buffer_size
,
339 snp_undi32_get_status (
340 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
341 OUT UINT32
*interrupt_status OPTIONAL
,
342 OUT VOID
**tx_buffer OPTIONAL
348 snp_undi32_transmit (
349 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
350 IN UINTN header_size
,
351 IN UINTN buffer_size
,
353 IN EFI_MAC_ADDRESS
* src_addr OPTIONAL
,
354 IN EFI_MAC_ADDRESS
* dest_addr OPTIONAL
,
355 IN UINT16
*protocol OPTIONAL
362 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
363 OUT UINTN
*header_size OPTIONAL
,
364 IN OUT UINTN
*buffer_size
,
366 OUT EFI_MAC_ADDRESS
* src_addr OPTIONAL
,
367 OUT EFI_MAC_ADDRESS
* dest_addr OPTIONAL
,
368 OUT UINT16
*protocol OPTIONAL
373 (*issue_undi32_command
) (
384 Install all the driver protocol
386 @param ImageHandle Driver image handle
387 @param SystemTable System services table
389 @retval EFI_SUCEESS Initialization routine has found UNDI hardware, loaded it's
390 ROM, and installed a notify event for the Network
391 Indentifier Interface Protocol successfully.
392 @retval Other Return value from HandleProtocol for DeviceIoProtocol or
398 InitializeSnpNiiDriver (
399 IN EFI_HANDLE ImageHandle
,
400 IN EFI_SYSTEM_TABLE
*SystemTable
403 #define SNP_MEM_PAGES(x) (((x) - 1) / 4096 + 1)